Skip to content

Commit

Permalink
refactor: Move runner types to runner package (#11552)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomi authored Nov 5, 2024
1 parent 6854f94 commit 3edecff
Show file tree
Hide file tree
Showing 16 changed files with 378 additions and 568 deletions.
14 changes: 13 additions & 1 deletion packages/@n8n/task-runner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,22 @@
},
"main": "dist/start.js",
"module": "src/start.ts",
"types": "dist/start.d.ts",
"types": "dist/index.d.ts",
"files": [
"dist/**/*"
],
"exports": {
"./start": {
"require": "./dist/start.js",
"import": "./src/start.ts",
"types": "./dist/start.d.ts"
},
".": {
"require": "./dist/index.js",
"import": "./src/index.ts",
"types": "./dist/index.d.ts"
}
},
"dependencies": {
"@n8n/config": "workspace:*",
"acorn": "8.14.0",
Expand Down
1 change: 1 addition & 0 deletions packages/@n8n/task-runner/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './task-runner';
export * from './runner-types';
export * from './message-types';
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { N8nMessage } from '../../runner-types';
import type { BrokerMessage } from '@/message-types';

/**
* Class to keep track of which built-in variables are accessed in the code
Expand Down Expand Up @@ -53,7 +53,7 @@ export class BuiltInsParserState {
this.needs$prevNode = true;
}

toDataRequestParams(): N8nMessage.ToRequester.TaskDataRequest['requestParams'] {
toDataRequestParams(): BrokerMessage.ToRequester.TaskDataRequest['requestParams'] {
return {
dataOfNodes: this.needsAllNodes ? 'all' : Array.from(this.neededNodeNames),
env: this.needs$env,
Expand Down
204 changes: 204 additions & 0 deletions packages/@n8n/task-runner/src/message-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
import type { INodeTypeBaseDescription } from 'n8n-workflow';

import type { RPC_ALLOW_LIST, TaskDataRequestParams, TaskResultData } from './runner-types';

export namespace BrokerMessage {
export namespace ToRunner {
export interface InfoRequest {
type: 'broker:inforequest';
}

export interface RunnerRegistered {
type: 'broker:runnerregistered';
}

export interface TaskOfferAccept {
type: 'broker:taskofferaccept';
taskId: string;
offerId: string;
}

export interface TaskCancel {
type: 'broker:taskcancel';
taskId: string;
reason: string;
}

export interface TaskSettings {
type: 'broker:tasksettings';
taskId: string;
settings: unknown;
}

export interface RPCResponse {
type: 'broker:rpcresponse';
callId: string;
taskId: string;
status: 'success' | 'error';
data: unknown;
}

export interface TaskDataResponse {
type: 'broker:taskdataresponse';
taskId: string;
requestId: string;
data: unknown;
}

export interface NodeTypes {
type: 'broker:nodetypes';
nodeTypes: INodeTypeBaseDescription[];
}

export type All =
| InfoRequest
| TaskOfferAccept
| TaskCancel
| TaskSettings
| RunnerRegistered
| RPCResponse
| TaskDataResponse
| NodeTypes;
}

export namespace ToRequester {
export interface TaskReady {
type: 'broker:taskready';
requestId: string;
taskId: string;
}

export interface TaskDone {
type: 'broker:taskdone';
taskId: string;
data: TaskResultData;
}

export interface TaskError {
type: 'broker:taskerror';
taskId: string;
error: unknown;
}

export interface TaskDataRequest {
type: 'broker:taskdatarequest';
taskId: string;
requestId: string;
requestParams: TaskDataRequestParams;
}

export interface RPC {
type: 'broker:rpc';
callId: string;
taskId: string;
name: (typeof RPC_ALLOW_LIST)[number];
params: unknown[];
}

export type All = TaskReady | TaskDone | TaskError | TaskDataRequest | RPC;
}
}

export namespace RequesterMessage {
export namespace ToBroker {
export interface TaskSettings {
type: 'requester:tasksettings';
taskId: string;
settings: unknown;
}

export interface TaskCancel {
type: 'requester:taskcancel';
taskId: string;
reason: string;
}

export interface TaskDataResponse {
type: 'requester:taskdataresponse';
taskId: string;
requestId: string;
data: unknown;
}

export interface RPCResponse {
type: 'requester:rpcresponse';
taskId: string;
callId: string;
status: 'success' | 'error';
data: unknown;
}

export interface TaskRequest {
type: 'requester:taskrequest';
requestId: string;
taskType: string;
}

export type All = TaskSettings | TaskCancel | RPCResponse | TaskDataResponse | TaskRequest;
}
}

export namespace RunnerMessage {
export namespace ToBroker {
export interface Info {
type: 'runner:info';
name: string;
types: string[];
}

export interface TaskAccepted {
type: 'runner:taskaccepted';
taskId: string;
}

export interface TaskRejected {
type: 'runner:taskrejected';
taskId: string;
reason: string;
}

export interface TaskDone {
type: 'runner:taskdone';
taskId: string;
data: TaskResultData;
}

export interface TaskError {
type: 'runner:taskerror';
taskId: string;
error: unknown;
}

export interface TaskOffer {
type: 'runner:taskoffer';
offerId: string;
taskType: string;
validFor: number;
}

export interface TaskDataRequest {
type: 'runner:taskdatarequest';
taskId: string;
requestId: string;
requestParams: TaskDataRequestParams;
}

export interface RPC {
type: 'runner:rpc';
callId: string;
taskId: string;
name: (typeof RPC_ALLOW_LIST)[number];
params: unknown[];
}

export type All =
| Info
| TaskDone
| TaskError
| TaskAccepted
| TaskRejected
| TaskOffer
| RPC
| TaskDataRequest;
}
}
Loading

0 comments on commit 3edecff

Please sign in to comment.