@ewhauser/world-celld 0.1.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/CHANGELOG.md +11 -0
- package/LICENSE +201 -0
- package/NOTICE +24 -0
- package/README.md +292 -0
- package/celld-worker/README.md +34 -0
- package/celld-worker/worker.ts +5 -0
- package/celld-worker/wrangler.jsonc +32 -0
- package/dist/index.d.ts +250 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +949 -0
- package/dist/index.js.map +1 -0
- package/dist/testing.d.ts +134 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +1808 -0
- package/dist/testing.js.map +1 -0
- package/dist/util-BvWlkqgV.js +122 -0
- package/dist/util-BvWlkqgV.js.map +1 -0
- package/dist/worker.d.ts +406 -0
- package/dist/worker.d.ts.map +1 -0
- package/dist/worker.js +1582 -0
- package/dist/worker.js.map +1 -0
- package/package.json +90 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { CreateEventRequest, Event, Hook, RunCreatedEventRequest, Step, ValidQueueName, WorkflowRun, World } from "@workflow/world";
|
|
2
|
+
//#region src/apply-event.d.ts
|
|
3
|
+
interface ApplyEventRequest {
|
|
4
|
+
/** The effective run id (already resolved / generated by the caller). */
|
|
5
|
+
runId: string;
|
|
6
|
+
data: CreateEventRequest | RunCreatedEventRequest;
|
|
7
|
+
/**
|
|
8
|
+
* Current holder of the hook token per the global KV token index
|
|
9
|
+
* (hook_created only). `null` means the token is unclaimed.
|
|
10
|
+
*/
|
|
11
|
+
tokenHolder?: {
|
|
12
|
+
runId: string;
|
|
13
|
+
hookId: string;
|
|
14
|
+
} | null;
|
|
15
|
+
}
|
|
16
|
+
type ApplyEventErrorCode = 'RUN_NOT_FOUND' | 'STEP_NOT_FOUND' | 'HOOK_NOT_FOUND' | 'ENTITY_CONFLICT' | 'RUN_EXPIRED' | 'TOO_EARLY' | 'RUN_NOT_SUPPORTED' | 'LEGACY_RUN_NOT_SUPPORTED';
|
|
17
|
+
interface ApplyEventFailure {
|
|
18
|
+
ok: false;
|
|
19
|
+
code: ApplyEventErrorCode;
|
|
20
|
+
message: string;
|
|
21
|
+
/** Seconds until retry is allowed (TOO_EARLY only). */
|
|
22
|
+
retryAfterSeconds?: number;
|
|
23
|
+
/** The run's spec version (RUN_NOT_SUPPORTED only). */
|
|
24
|
+
runSpecVersion?: number;
|
|
25
|
+
}
|
|
26
|
+
interface ApplyEventSuccess {
|
|
27
|
+
ok: true;
|
|
28
|
+
/** Absent for idempotent replays that record no new event. */
|
|
29
|
+
event?: Event;
|
|
30
|
+
run?: WorkflowRun;
|
|
31
|
+
step?: Step;
|
|
32
|
+
hook?: Hook;
|
|
33
|
+
/** Hooks whose tokens must be released from the global KV index. */
|
|
34
|
+
releasedHooks: Array<{
|
|
35
|
+
hookId: string;
|
|
36
|
+
token: string;
|
|
37
|
+
}>;
|
|
38
|
+
/** Set when a run entity was created (run_created or resilient bootstrap). */
|
|
39
|
+
runCreated?: {
|
|
40
|
+
workflowName: string;
|
|
41
|
+
createdAt: Date;
|
|
42
|
+
};
|
|
43
|
+
/** Set when the global KV hook index must be (re)written. */
|
|
44
|
+
hookToIndex?: Hook;
|
|
45
|
+
/** All events (ascending), preloaded for run_started responses. */
|
|
46
|
+
events?: Event[];
|
|
47
|
+
}
|
|
48
|
+
type ApplyEventOutcome = ApplyEventSuccess | ApplyEventFailure;
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/storage.d.ts
|
|
51
|
+
/**
|
|
52
|
+
* RPC surface of WorkflowRunDO used by the storage layer. Declared
|
|
53
|
+
* structurally to avoid a circular type reference on the DO class.
|
|
54
|
+
*/
|
|
55
|
+
interface WorkflowRunDOStub {
|
|
56
|
+
applyEvent(request: ApplyEventRequest): Promise<ApplyEventOutcome>;
|
|
57
|
+
getRun(): Promise<WorkflowRun | null>;
|
|
58
|
+
getStep(stepId: string): Promise<Step | null>;
|
|
59
|
+
getEvent(eventId: string): Promise<Event | null>;
|
|
60
|
+
listEvents(params?: {
|
|
61
|
+
limit?: number;
|
|
62
|
+
cursor?: string;
|
|
63
|
+
sortOrder?: 'asc' | 'desc';
|
|
64
|
+
}): Promise<{
|
|
65
|
+
data: Event[];
|
|
66
|
+
cursor: string | null;
|
|
67
|
+
hasMore: boolean;
|
|
68
|
+
}>;
|
|
69
|
+
listSteps(params?: {
|
|
70
|
+
limit?: number;
|
|
71
|
+
cursor?: string;
|
|
72
|
+
sortOrder?: 'asc' | 'desc';
|
|
73
|
+
}): Promise<{
|
|
74
|
+
data: Step[];
|
|
75
|
+
cursor: string | null;
|
|
76
|
+
hasMore: boolean;
|
|
77
|
+
}>;
|
|
78
|
+
listHooks(params?: {
|
|
79
|
+
limit?: number;
|
|
80
|
+
cursor?: string;
|
|
81
|
+
sortOrder?: 'asc' | 'desc';
|
|
82
|
+
}): Promise<{
|
|
83
|
+
data: Hook[];
|
|
84
|
+
cursor: string | null;
|
|
85
|
+
hasMore: boolean;
|
|
86
|
+
}>;
|
|
87
|
+
}
|
|
88
|
+
interface WorkflowRunDONamespace {
|
|
89
|
+
idFromName(name: string): DurableObjectIdLike;
|
|
90
|
+
get(id: DurableObjectIdLike): WorkflowRunDOStub;
|
|
91
|
+
}
|
|
92
|
+
interface DurableObjectIdLike {
|
|
93
|
+
toString(): string;
|
|
94
|
+
}
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region src/streamer.d.ts
|
|
97
|
+
/**
|
|
98
|
+
* RPC surface of StreamDO (see durable-objects/StreamDO.ts). The streamer
|
|
99
|
+
* talks to the DO exclusively via these methods — there is no fetch()
|
|
100
|
+
* protocol.
|
|
101
|
+
*/
|
|
102
|
+
interface StreamDOStub {
|
|
103
|
+
writeChunk(data: Uint8Array): Promise<number>;
|
|
104
|
+
closeStream(): Promise<void>;
|
|
105
|
+
getChunks(params: {
|
|
106
|
+
startIndex: number;
|
|
107
|
+
limit: number;
|
|
108
|
+
}): Promise<{
|
|
109
|
+
chunks: Uint8Array[];
|
|
110
|
+
done: boolean;
|
|
111
|
+
tailIndex: number;
|
|
112
|
+
}>;
|
|
113
|
+
getInfo(): Promise<{
|
|
114
|
+
tailIndex: number;
|
|
115
|
+
done: boolean;
|
|
116
|
+
}>;
|
|
117
|
+
registerStream(name: string): Promise<void>;
|
|
118
|
+
listStreams(): Promise<string[]>;
|
|
119
|
+
}
|
|
120
|
+
interface StreamDONamespace {
|
|
121
|
+
idFromName(name: string): StreamDOId;
|
|
122
|
+
get(id: StreamDOId): StreamDOStub;
|
|
123
|
+
}
|
|
124
|
+
interface StreamDOId {
|
|
125
|
+
toString(): string;
|
|
126
|
+
}
|
|
127
|
+
//#endregion
|
|
128
|
+
//#region src/queue.d.ts
|
|
129
|
+
type Pathname = 'flow' | 'step';
|
|
130
|
+
/**
|
|
131
|
+
* Enqueue request accepted by a QueueDO cell. The message payload travels
|
|
132
|
+
* pre-encoded with the shared tagged-JSON codec (`body`), so the cell can
|
|
133
|
+
* forward it byte-identical to the app's queue handler without re-encoding.
|
|
134
|
+
*/
|
|
135
|
+
interface EnqueueRequest {
|
|
136
|
+
messageId: string;
|
|
137
|
+
queueName: ValidQueueName;
|
|
138
|
+
pathname: Pathname;
|
|
139
|
+
/** `stringify(message)` — the exact bytes POSTed to the app on delivery. */
|
|
140
|
+
body: string;
|
|
141
|
+
idempotencyKey?: string;
|
|
142
|
+
delaySeconds?: number;
|
|
143
|
+
/**
|
|
144
|
+
* Delivery configuration. The cell pins this from its first enqueue (the
|
|
145
|
+
* eve-ambient pattern); a later mismatch is rejected as CONFIG_MISMATCH.
|
|
146
|
+
*/
|
|
147
|
+
config: QueueCellConfig;
|
|
148
|
+
}
|
|
149
|
+
interface QueueCellConfig {
|
|
150
|
+
/** Base URL of the app; deliveries POST to `${baseUrl}/.well-known/workflow/v1/{flow|step}`. */
|
|
151
|
+
targetBaseUrl: string;
|
|
152
|
+
queueShards: number;
|
|
153
|
+
}
|
|
154
|
+
type EnqueueOutcome = {
|
|
155
|
+
ok: true;
|
|
156
|
+
messageId: string;
|
|
157
|
+
deduped: boolean;
|
|
158
|
+
} | {
|
|
159
|
+
ok: false;
|
|
160
|
+
code: 'CONFIG_MISMATCH';
|
|
161
|
+
message: string;
|
|
162
|
+
};
|
|
163
|
+
/** RPC surface of QueueDO used by the queue producer. */
|
|
164
|
+
interface QueueCellStub {
|
|
165
|
+
enqueue(request: EnqueueRequest): Promise<EnqueueOutcome>;
|
|
166
|
+
}
|
|
167
|
+
interface QueueCellNamespace {
|
|
168
|
+
idFromName(name: string): {
|
|
169
|
+
toString(): string;
|
|
170
|
+
};
|
|
171
|
+
get(id: {
|
|
172
|
+
toString(): string;
|
|
173
|
+
}): QueueCellStub;
|
|
174
|
+
}
|
|
175
|
+
//#endregion
|
|
176
|
+
//#region src/config.d.ts
|
|
177
|
+
/** Storage-layer KV interface (satisfied by IndexDO over HTTP, or a mock). */
|
|
178
|
+
interface IndexNamespace {
|
|
179
|
+
get(key: string): Promise<string | null>;
|
|
180
|
+
put(key: string, value: string): Promise<void>;
|
|
181
|
+
delete(key: string): Promise<void>;
|
|
182
|
+
list(options?: {
|
|
183
|
+
prefix?: string;
|
|
184
|
+
cursor?: string;
|
|
185
|
+
limit?: number;
|
|
186
|
+
reverse?: boolean;
|
|
187
|
+
}): Promise<{
|
|
188
|
+
keys: Array<{
|
|
189
|
+
name: string;
|
|
190
|
+
}>;
|
|
191
|
+
list_complete: boolean;
|
|
192
|
+
cursor?: string;
|
|
193
|
+
}>;
|
|
194
|
+
reserveHookToken(token: string, owner: HookTokenOwner): Promise<{
|
|
195
|
+
claimed: boolean;
|
|
196
|
+
holder?: HookTokenOwner;
|
|
197
|
+
}>;
|
|
198
|
+
finalizeHookIndexes(token: string, hookId: string, serializedHook: string, owner: HookTokenOwner): Promise<void>;
|
|
199
|
+
releaseHookToken(token: string, owner: HookTokenOwner): Promise<void>;
|
|
200
|
+
deleteHookIndexes(token: string, hookId: string, owner: HookTokenOwner): Promise<void>;
|
|
201
|
+
}
|
|
202
|
+
interface HookTokenOwner {
|
|
203
|
+
runId: string;
|
|
204
|
+
hookId: string;
|
|
205
|
+
}
|
|
206
|
+
interface CelldWorldEnv {
|
|
207
|
+
WORKFLOW_DB: WorkflowRunDONamespace;
|
|
208
|
+
WORKFLOW_INDEX: IndexNamespace;
|
|
209
|
+
WORKFLOW_QUEUE: QueueCellNamespace;
|
|
210
|
+
WORKFLOW_STREAMS: StreamDONamespace;
|
|
211
|
+
}
|
|
212
|
+
interface CelldWorldConfig {
|
|
213
|
+
/**
|
|
214
|
+
* Base URL of any celld fleet node's public listener (e.g.
|
|
215
|
+
* `http://fleet.internal:8080`). Requests are routed to the deployed
|
|
216
|
+
* world-celld worker, which forwards them to the owning cells.
|
|
217
|
+
* Default: process.env.CELLD_FLEET_URL
|
|
218
|
+
*/
|
|
219
|
+
fleetUrl?: string;
|
|
220
|
+
/**
|
|
221
|
+
* Bearer secret shared with the worker (its WORLD_SECRET var).
|
|
222
|
+
* Default: process.env.CELLD_WORLD_SECRET
|
|
223
|
+
*/
|
|
224
|
+
secret?: string;
|
|
225
|
+
/**
|
|
226
|
+
* Pre-built namespaces (used by tests and the in-process harness). When
|
|
227
|
+
* provided, fleetUrl/secret are not used.
|
|
228
|
+
*/
|
|
229
|
+
env?: CelldWorldEnv;
|
|
230
|
+
/** Default: process.env.CELLD_DEPLOYMENT_ID || 'celld-default' */
|
|
231
|
+
deploymentId?: string;
|
|
232
|
+
/**
|
|
233
|
+
* Base URL the app's workflow endpoints are mounted on; QueueDO cells
|
|
234
|
+
* deliver to `${baseUrl}/.well-known/workflow/v1/{flow|step}`.
|
|
235
|
+
* Default: process.env.WORKFLOW_BASE_URL || `http://localhost:${PORT ?? 3000}`
|
|
236
|
+
*/
|
|
237
|
+
baseUrl?: string;
|
|
238
|
+
/** Number of queue cells to spread enqueues over. Default: 1 */
|
|
239
|
+
queueShards?: number;
|
|
240
|
+
/** Poll interval (ms) while waiting for new chunks on a live stream. Default: 250 */
|
|
241
|
+
readPollMs?: number;
|
|
242
|
+
/** Per-attempt fleet RPC deadline in milliseconds. Default: 30000 */
|
|
243
|
+
rpcTimeoutMs?: number;
|
|
244
|
+
}
|
|
245
|
+
//#endregion
|
|
246
|
+
//#region src/index.d.ts
|
|
247
|
+
declare function createCelldWorld(config?: CelldWorldConfig): World;
|
|
248
|
+
//#endregion
|
|
249
|
+
export { type CelldWorldConfig, type CelldWorldEnv, type EnqueueOutcome, type EnqueueRequest, type IndexNamespace, type QueueCellConfig, type QueueCellNamespace, type QueueCellStub, type StreamDONamespace, type StreamDOStub, type WorkflowRunDONamespace, type WorkflowRunDOStub, createCelldWorld, createCelldWorld as createWorld };
|
|
250
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/apply-event.ts","../src/storage.ts","../src/streamer.ts","../src/queue.ts","../src/config.ts","../src/index.ts"],"mappings":";;UAsFiB;;EAEf;EACA,MAAM,qBAAqB;;;;;EAK3B;IAAgB;IAAe;;;KAGrB;UAUK;EACf;EACA,MAAM;EACN;;EAEA;;EAEA;;UAGe;EACf;;EAEA,QAAQ;EACR,MAAM;EACN,OAAO;EACP,OAAO;;EAEP,eAAe;IAAQ;IAAgB;;;EAEvC;IAAe;IAAsB,WAAW;;;EAEhD,cAAc;;EAEd,SAAS;;KAGC,oBAAoB,oBAAoB;;;;;;;UCrFnC;EACf,WAAW,SAAS,oBAAoB,QAAQ;EAChD,UAAU,QAAQ;EAClB,QAAQ,iBAAiB,QAAQ;EACjC,SAAS,kBAAkB,QAAQ;EACnC,WAAW;IACT;IACA;IACA;MACE;IAAU,MAAM;IAAS;IAAuB;;EACpD,UAAU;IACR;IACA;IACA;MACE;IAAU,MAAM;IAAQ;IAAuB;;EACnD,UAAU;IACR;IACA;IACA;MACE;IAAU,MAAM;IAAQ;IAAuB;;;UAGpC;EACf,WAAW,eAAe;EAC1B,IAAI,IAAI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