depa-actor 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/ActorSystem.d.ts +1 -1
- package/dist/core/ActorSystem.d.ts.map +1 -1
- package/dist/dispatch/ActorDispatchAdapter.d.ts +1 -1
- package/dist/dispatch/ActorDispatchAdapter.d.ts.map +1 -1
- package/dist/execution/commandDeque.d.ts +121 -0
- package/dist/execution/commandDeque.d.ts.map +1 -0
- package/dist/execution/commandDeque.js +415 -0
- package/dist/execution/commandDeque.js.map +1 -0
- package/dist/execution/dispatcher.d.ts +72 -0
- package/dist/execution/dispatcher.d.ts.map +1 -0
- package/dist/execution/dispatcher.js +77 -0
- package/dist/execution/dispatcher.js.map +1 -0
- package/dist/execution/index.d.ts +7 -0
- package/dist/execution/index.d.ts.map +1 -0
- package/dist/execution/index.js +4 -0
- package/dist/execution/index.js.map +1 -0
- package/dist/execution/stack.d.ts +24 -0
- package/dist/execution/stack.d.ts.map +1 -0
- package/dist/execution/stack.js +84 -0
- package/dist/execution/stack.js.map +1 -0
- package/dist/index.d.ts +17 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -8
- package/dist/index.js.map +1 -1
- package/dist/orchestration/index.d.ts +8 -8
- package/dist/orchestration/index.d.ts.map +1 -1
- package/dist/orchestration/index.js +6 -6
- package/dist/orchestration/index.js.map +1 -1
- package/dist/orchestration/presets/aiAgent.d.ts +2 -2
- package/dist/orchestration/presets/aiAgent.d.ts.map +1 -1
- package/dist/orchestration/recovery.d.ts +2 -2
- package/dist/orchestration/recovery.d.ts.map +1 -1
- package/dist/orchestration/reducer.d.ts +2 -2
- package/dist/orchestration/reducer.d.ts.map +1 -1
- package/dist/orchestration/reducer.js +2 -2
- package/dist/orchestration/reducer.js.map +1 -1
- package/dist/orchestration/runtimeAdapter.d.ts +3 -3
- package/dist/orchestration/runtimeAdapter.d.ts.map +1 -1
- package/dist/orchestration/scheduler.d.ts +2 -2
- package/dist/orchestration/scheduler.d.ts.map +1 -1
- package/dist/orchestration/types.d.ts +1 -1
- package/dist/orchestration/types.d.ts.map +1 -1
- package/dist/pipeline/ActorPipeline.d.ts +1 -1
- package/dist/pipeline/ActorPipeline.d.ts.map +1 -1
- package/dist/runtime/ActorRuntime.d.ts +2 -2
- package/dist/runtime/ActorRuntime.d.ts.map +1 -1
- package/dist/runtime/ActorRuntime.js +1 -1
- package/dist/runtime/ActorRuntime.js.map +1 -1
- package/dist-cjs/core/ActorSystem.cjs +172 -0
- package/dist-cjs/core/types.cjs +10 -0
- package/dist-cjs/dispatch/ActorDispatchAdapter.cjs +40 -0
- package/dist-cjs/execution/commandDeque.cjs +430 -0
- package/dist-cjs/execution/dispatcher.cjs +79 -0
- package/dist-cjs/execution/index.cjs +24 -0
- package/dist-cjs/execution/stack.cjs +88 -0
- package/dist-cjs/index.cjs +52 -0
- package/dist-cjs/orchestration/index.cjs +19 -0
- package/dist-cjs/orchestration/presets/aiAgent.cjs +40 -0
- package/dist-cjs/orchestration/recovery.cjs +112 -0
- package/dist-cjs/orchestration/reducer.cjs +276 -0
- package/dist-cjs/orchestration/runtimeAdapter.cjs +14 -0
- package/dist-cjs/orchestration/scheduler.cjs +86 -0
- package/dist-cjs/orchestration/types.cjs +14 -0
- package/dist-cjs/package.json +3 -0
- package/dist-cjs/pipeline/ActorPipeline.cjs +34 -0
- package/dist-cjs/runtime/ActorRuntime.cjs +77 -0
- package/dist-cjs/runtime/completion.cjs +75 -0
- package/dist-cjs/runtime/indexing.cjs +34 -0
- package/dist-cjs/runtime/snapshot.cjs +14 -0
- package/package.json +6 -4
- package/src/core/ActorSystem.ts +1 -1
- package/src/dispatch/ActorDispatchAdapter.ts +1 -1
- package/src/execution/commandDeque.ts +656 -0
- package/src/execution/dispatcher.ts +188 -0
- package/src/execution/index.ts +58 -0
- package/src/execution/stack.ts +130 -0
- package/src/index.ts +67 -15
- package/src/orchestration/index.ts +8 -8
- package/src/orchestration/presets/aiAgent.ts +2 -2
- package/src/orchestration/recovery.ts +2 -2
- package/src/orchestration/reducer.ts +3 -3
- package/src/orchestration/runtimeAdapter.ts +3 -3
- package/src/orchestration/scheduler.ts +2 -2
- package/src/orchestration/types.ts +1 -1
- package/src/pipeline/ActorPipeline.ts +1 -1
- package/src/runtime/ActorRuntime.ts +2 -2
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
*
|
|
11
11
|
* createPipelineHandler() wraps a pipeline definition into an ActorHandler.
|
|
12
12
|
*/
|
|
13
|
-
import type { MailboxSchema, ActorSelf, ActorHandler } from '../core/types';
|
|
13
|
+
import type { MailboxSchema, ActorSelf, ActorHandler } from '../core/types.js';
|
|
14
14
|
export type PipelineDerivedAdapter<TRuntime, TSchema extends MailboxSchema, TState, TDerived> = (self: ActorSelf<TRuntime, TSchema, TState>, payload: TSchema[keyof TSchema & string], state: TState) => TDerived;
|
|
15
15
|
export type PipelineInnerRuntimeAdapter<TRuntime, TSchema extends MailboxSchema, TState, TDerived, TInnerRuntime> = (self: ActorSelf<TRuntime, TSchema, TState>, payload: TSchema[keyof TSchema & string], state: TState, derived: TDerived) => TInnerRuntime;
|
|
16
16
|
export type PipelineInnerInputAdapter<TRuntime, TSchema extends MailboxSchema, TState, TDerived, TInnerInput> = (self: ActorSelf<TRuntime, TSchema, TState>, payload: TSchema[keyof TSchema & string], state: TState, derived: TDerived) => TInnerInput;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActorPipeline.d.ts","sourceRoot":"","sources":["../../src/pipeline/ActorPipeline.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EACV,aAAa,EACb,SAAS,EACT,YAAY,EACb,MAAM,
|
|
1
|
+
{"version":3,"file":"ActorPipeline.d.ts","sourceRoot":"","sources":["../../src/pipeline/ActorPipeline.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EACV,aAAa,EACb,SAAS,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AAY,CAAC,CAAC;CAClF;AAID,wBAAgB,qBAAqB,CACnC,QAAQ,EACR,OAAO,SAAS,aAAa,EAC7B,MAAM,EACN,QAAQ,EACR,aAAa,EACb,WAAW,EACX,YAAY,EACZ,YAAY,EAEZ,QAAQ,EAAE,gBAAgB,CACxB,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EACnC,aAAa,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,CACvD,GACA,YAAY,CAAC,QAAQ,EAAE,OAAO,EAAE,MAAM,CAAC,CAuBzC"}
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
*
|
|
7
7
|
* Future AiAgentVm will hold an ActorRuntime instance.
|
|
8
8
|
*/
|
|
9
|
-
import type { MailboxSchema, ActorDef, ActorRef, ActorLogEntry } from '../core/types';
|
|
10
|
-
import { ActorSystem } from '../core/ActorSystem';
|
|
9
|
+
import type { MailboxSchema, ActorDef, ActorRef, ActorLogEntry } from '../core/types.js';
|
|
10
|
+
import { ActorSystem } from '../core/ActorSystem.js';
|
|
11
11
|
export interface ActorPlugin<TRuntime, TSchema extends MailboxSchema> {
|
|
12
12
|
name: string;
|
|
13
13
|
onRegister?: (id: string, def: ActorDef<TRuntime, TSchema, unknown>) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActorRuntime.d.ts","sourceRoot":"","sources":["../../src/runtime/ActorRuntime.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACV,aAAa,EACb,QAAQ,EACR,QAAQ,EACR,aAAa,EACd,MAAM,
|
|
1
|
+
{"version":3,"file":"ActorRuntime.d.ts","sourceRoot":"","sources":["../../src/runtime/ActorRuntime.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACV,aAAa,EACb,QAAQ,EACR,QAAQ,EACR,aAAa,EACd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAw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C,EAAE,EAAE,MAAM,GAAG,IAAI;IAO5B,QAAQ,CAAC,IAAI,SAAS,MAAM,OAAO,GAAG,MAAM,EAC1C,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,EACV,GAAG,EAAE,IAAI,EACT,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,GACrB,IAAI;IAIP,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,SAAS;IAIhE,GAAG,IAAI,MAAM,EAAE;IAIf,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAMxB,OAAO,CAAC,SAAS;CAKlB"}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* Future AiAgentVm will hold an ActorRuntime instance.
|
|
8
8
|
*/
|
|
9
|
-
import { ActorSystem } from '../core/ActorSystem';
|
|
9
|
+
import { ActorSystem } from '../core/ActorSystem.js';
|
|
10
10
|
// ─── ActorRuntime ────────────────────────────────────────────────────
|
|
11
11
|
export class ActorRuntime {
|
|
12
12
|
system;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActorRuntime.js","sourceRoot":"","sources":["../../src/runtime/ActorRuntime.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAQH,OAAO,EAAE,WAAW,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"ActorRuntime.js","sourceRoot":"","sources":["../../src/runtime/ActorRuntime.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAQH,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAWrD,wEAAwE;AAExE,MAAM,OAAO,YAAY;IACd,MAAM,CAAiC;IACxC,OAAO,GAAqC,EAAE,CAAC;IAC/C,MAAM,GAAG,IAAI,GAAG,EAAmB,CAAC;IAE5C,YACE,UAA0B,EAC1B,OAA0C;QAE1C,IAAI,CAAC,OAAO,GAAG,OAAO,IAAI,E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,CAAC;QAClE,CAAC;IACH,CAAC;IAED,UAAU,CAAC,EAAU;QACnB,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;QAC3B,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YAC7B,CAAC,CAAC,YAAY,EAAE,CAAC,EAAE,CAAC,CAAC;QACvB,CAAC;IACH,CAAC;IAED,QAAQ,CACN,IAAY,EACZ,EAAU,EACV,GAAS,EACT,OAAsB;QAEtB,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;IAC/C,CAAC;IAED,OAAO,CAAC,IAAY,EAAE,EAAU;QAC9B,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IACvC,CAAC;IAED,GAAG;QACD,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC;IAC3B,CAAC;IAED,GAAG,CAAC,EAAU;QACZ,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC7B,CAAC;IAED,iBAAiB;IAET,SAAS,CAAC,KAA6B;QAC7C,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YAC7B,CAAC,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC;QACnB,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* depa-actor — ActorSystem
|
|
4
|
+
*
|
|
5
|
+
* Multi-mailbox actor system with priority-based drain.
|
|
6
|
+
* Evolved from depa-data-graph ActorSystem with MailboxSchema support.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.ActorSystem = void 0;
|
|
10
|
+
// ─── ActorSystem ─────────────────────────────────────────────────────
|
|
11
|
+
class ActorSystem {
|
|
12
|
+
getRuntime;
|
|
13
|
+
onLog;
|
|
14
|
+
seq = 0;
|
|
15
|
+
cells = new Map();
|
|
16
|
+
constructor(getRuntime, onLog) {
|
|
17
|
+
this.getRuntime = getRuntime;
|
|
18
|
+
this.onLog = onLog;
|
|
19
|
+
}
|
|
20
|
+
// ── Query ──
|
|
21
|
+
ids() {
|
|
22
|
+
return Array.from(this.cells.keys()).sort();
|
|
23
|
+
}
|
|
24
|
+
has(id) {
|
|
25
|
+
return this.cells.has(id);
|
|
26
|
+
}
|
|
27
|
+
// ── Registration ──
|
|
28
|
+
register(id, def) {
|
|
29
|
+
if (this.cells.has(id)) {
|
|
30
|
+
throw new Error(`Actor already registered: ${id}`);
|
|
31
|
+
}
|
|
32
|
+
if (!def.handler && !def.handlers) {
|
|
33
|
+
throw new Error(`Actor "${id}" must have at least handler or handlers`);
|
|
34
|
+
}
|
|
35
|
+
this.cells.set(id, {
|
|
36
|
+
id,
|
|
37
|
+
def: def,
|
|
38
|
+
state: def.initialState,
|
|
39
|
+
queue: [],
|
|
40
|
+
processing: false,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
unregister(id) {
|
|
44
|
+
this.cells.delete(id);
|
|
45
|
+
}
|
|
46
|
+
// ── Messaging ──
|
|
47
|
+
refFrom(from, to) {
|
|
48
|
+
if (!this.cells.has(to))
|
|
49
|
+
return undefined;
|
|
50
|
+
return {
|
|
51
|
+
id: to,
|
|
52
|
+
send: (tag, payload) => this.sendFrom(from, to, tag, payload),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
sendFrom(from, to, tag, payload) {
|
|
56
|
+
const target = this.cells.get(to);
|
|
57
|
+
const envelope = {
|
|
58
|
+
id: ++this.seq,
|
|
59
|
+
ts: Date.now(),
|
|
60
|
+
from,
|
|
61
|
+
to,
|
|
62
|
+
tag,
|
|
63
|
+
payload,
|
|
64
|
+
};
|
|
65
|
+
if (!target) {
|
|
66
|
+
this.onLog?.({ kind: 'error', ...envelope, error: `Unknown actor: ${to}` });
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
this.onLog?.({ kind: 'send', ...envelope });
|
|
70
|
+
target.queue.push(envelope);
|
|
71
|
+
this.scheduleDrain(target);
|
|
72
|
+
}
|
|
73
|
+
broadcastFrom(from, tag, payload, opts) {
|
|
74
|
+
for (const id of this.cells.keys()) {
|
|
75
|
+
if (opts?.excludeSelf && id === from)
|
|
76
|
+
continue;
|
|
77
|
+
this.sendFrom(from, id, tag, payload);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// ── Drain ──
|
|
81
|
+
scheduleDrain(cell) {
|
|
82
|
+
if (cell.processing)
|
|
83
|
+
return;
|
|
84
|
+
cell.processing = true;
|
|
85
|
+
queueMicrotask(() => {
|
|
86
|
+
void this.drain(cell);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Priority-based drain: sorts pending messages by tag priority,
|
|
91
|
+
* then processes sequentially. Per-tag handlers take precedence.
|
|
92
|
+
*/
|
|
93
|
+
async drain(cell) {
|
|
94
|
+
try {
|
|
95
|
+
while (cell.queue.length > 0) {
|
|
96
|
+
// Sort by priority (lower = higher priority, default 100)
|
|
97
|
+
const priorities = cell.def.priority ?? {};
|
|
98
|
+
cell.queue.sort((a, b) => {
|
|
99
|
+
const pa = priorities[a.tag] ?? 100;
|
|
100
|
+
const pb = priorities[b.tag] ?? 100;
|
|
101
|
+
return pa - pb;
|
|
102
|
+
});
|
|
103
|
+
const envelope = cell.queue.shift();
|
|
104
|
+
const self = this.makeSelf(cell);
|
|
105
|
+
try {
|
|
106
|
+
await this.dispatch(cell, self, envelope);
|
|
107
|
+
this.onLog?.({ kind: 'deliver', ...envelope });
|
|
108
|
+
}
|
|
109
|
+
catch (err) {
|
|
110
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
111
|
+
this.onLog?.({ kind: 'error', ...envelope, error: message });
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
finally {
|
|
116
|
+
cell.processing = false;
|
|
117
|
+
if (cell.queue.length > 0) {
|
|
118
|
+
this.scheduleDrain(cell);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/** Route envelope to per-tag handler or unified handler */
|
|
123
|
+
async dispatch(cell, self, envelope) {
|
|
124
|
+
const tagHandler = cell.def.handlers?.[envelope.tag];
|
|
125
|
+
if (tagHandler) {
|
|
126
|
+
await tagHandler(self, envelope);
|
|
127
|
+
}
|
|
128
|
+
else if (cell.def.handler) {
|
|
129
|
+
await cell.def.handler(self, envelope);
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
// No handler for this tag — log and skip
|
|
133
|
+
this.onLog?.({
|
|
134
|
+
kind: 'error',
|
|
135
|
+
...envelope,
|
|
136
|
+
error: `No handler for tag "${envelope.tag}" on actor "${cell.id}"`,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/** Construct ActorSelf with selective receive capabilities */
|
|
141
|
+
makeSelf(cell) {
|
|
142
|
+
return {
|
|
143
|
+
id: cell.id,
|
|
144
|
+
ref: {
|
|
145
|
+
id: cell.id,
|
|
146
|
+
send: (tag, payload) => this.sendFrom(cell.id, cell.id, tag, payload),
|
|
147
|
+
},
|
|
148
|
+
runtime: this.getRuntime(),
|
|
149
|
+
state: cell.state,
|
|
150
|
+
send: (to, tag, payload) => this.sendFrom(cell.id, to, tag, payload),
|
|
151
|
+
broadcast: (tag, payload, opts) => this.broadcastFrom(cell.id, tag, payload, opts),
|
|
152
|
+
// Selective receive
|
|
153
|
+
hasPending: (tag) => cell.queue.some((e) => e.tag === tag),
|
|
154
|
+
drainMailbox: (tag) => {
|
|
155
|
+
const matching = [];
|
|
156
|
+
const remaining = [];
|
|
157
|
+
for (const e of cell.queue) {
|
|
158
|
+
if (e.tag === tag) {
|
|
159
|
+
matching.push(e);
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
remaining.push(e);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
cell.queue.length = 0;
|
|
166
|
+
cell.queue.push(...remaining);
|
|
167
|
+
return matching;
|
|
168
|
+
},
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
exports.ActorSystem = ActorSystem;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* depa-actor — Core Type Definitions
|
|
4
|
+
*
|
|
5
|
+
* Synthesizes:
|
|
6
|
+
* - depa-data-graph ActorSystem (true actor model, mailbox queue, microtask drain)
|
|
7
|
+
* - depa-processor (dispatch routing, DOP pipeline)
|
|
8
|
+
* - OneAgentActor domain needs (multi-mailbox, typed tags)
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* depa-actor — Dispatch Bridge
|
|
4
|
+
*
|
|
5
|
+
* Optional bridge to depa-processor DispatchEngine.
|
|
6
|
+
* Only this file imports from depa-processor concepts.
|
|
7
|
+
* No hard dependency — uses structural typing.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.createDispatchHandler = createDispatchHandler;
|
|
11
|
+
// ─── createDispatchHandler ───────────────────────────────────────────
|
|
12
|
+
/**
|
|
13
|
+
* Creates an ActorHandler that routes envelopes through dispatch routes.
|
|
14
|
+
* Falls back to `defaultHandler` for tags not covered by any route.
|
|
15
|
+
*/
|
|
16
|
+
function createDispatchHandler(routes, defaultHandler) {
|
|
17
|
+
// Build tag → route index for O(1) lookup
|
|
18
|
+
const tagIndex = new Map();
|
|
19
|
+
for (const route of routes) {
|
|
20
|
+
for (const tag of route.tags) {
|
|
21
|
+
tagIndex.set(tag, route);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return async (self, envelope) => {
|
|
25
|
+
const route = tagIndex.get(envelope.tag);
|
|
26
|
+
if (route) {
|
|
27
|
+
const key = route.resolveKey(envelope);
|
|
28
|
+
const handler = route.routes[key];
|
|
29
|
+
if (handler) {
|
|
30
|
+
await handler(self, envelope);
|
|
31
|
+
}
|
|
32
|
+
else if (route.fallback) {
|
|
33
|
+
await route.fallback(self, envelope, key);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else if (defaultHandler) {
|
|
37
|
+
await defaultHandler(self, envelope);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|