effect-cf 0.34.0 → 0.35.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 +10 -0
- package/dist/ComputerWorkspace.d.mts +11 -3
- package/dist/ComputerWorkspace.mjs +31 -9
- package/dist/{DurableObjectState-De4ZojhY.mjs → DurableObjectState-DcqElJ4e.mjs} +81 -50
- package/dist/{DurableObjectState-CrEunfQ-.d.mts → DurableObjectState-DpYdNZgT.d.mts} +35 -29
- package/dist/Vitest.d.mts +2 -2
- package/dist/Vitest.mjs +7 -10
- package/dist/{WorkflowBinding-BumVQTuW.d.mts → WorkflowBinding-Cn3AuUyP.d.mts} +1 -1
- package/dist/index.d.mts +12 -4
- package/dist/index.mjs +102 -77
- package/package.json +1 -1
- package/src/AnalyticsEngine.ts +8 -1
- package/src/CloudflareOtlp.ts +6 -3
- package/src/ComputerWorkspace.ts +53 -26
- package/src/DurableObject.ts +8 -9
- package/src/DurableObjectNamespace.ts +33 -5
- package/src/DurableObjectRpcWebSocket.ts +2 -27
- package/src/DurableObjectState.ts +18 -20
- package/src/DurableObjectStorage.ts +53 -35
- package/src/DurableObjectWebSocket.ts +23 -41
- package/src/RpcDefinition.ts +5 -15
- package/src/ServiceBinding.ts +37 -5
- package/src/Vitest.ts +18 -15
- package/src/Worker.ts +107 -54
- package/src/WorkersAi.ts +21 -14
- package/src/Workflow.ts +45 -49
- package/src/internal/NativeCallback.ts +55 -0
- package/src/internal/WorkerContext.ts +5 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# effect-cf
|
|
2
2
|
|
|
3
|
+
## 0.35.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#130](https://github.com/danieljvdm/effect-cf/pull/130) [`6139dc2`](https://github.com/danieljvdm/effect-cf/commit/6139dc2507043abfd81b6abeeff87bfd5b8bb31a) Thanks [@danieljvdm](https://github.com/danieljvdm)! - Keep Worker event-layer resources alive through Effect HTTP response streams, give background work and Workflow steps their own resource scopes, and join interrupted native callbacks before returning. Durable Object transactions now await rollback and cleanup on interruption, including accidental asynchronous work in synchronous transactions. Queue handlers also schedule telemetry flushes after success or failure.
|
|
8
|
+
|
|
9
|
+
Propagate fetch cancellation to service bindings and Durable Objects. Report scoped RPC failures, malformed embedding responses, and invalid Analytics Engine URLs through tagged errors. Computer workspace acquisition now exposes `WorkspaceAcquireError` in its layer error channel. Typed WebSocket attachments enforce their declared shape, and fresh RPC connections replace reserved metadata without losing application fields.
|
|
10
|
+
|
|
11
|
+
Support modern WebTransport datagram writers and buffered-datagram options while retaining legacy compatibility. Release stream locks after cleanup and datagram writer locks when either peer closes. Failed or interrupted fallback candidates release their resources before selection continues.
|
|
12
|
+
|
|
3
13
|
## 0.34.0
|
|
4
14
|
|
|
5
15
|
### Minor Changes
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ComputerArtifactsClient } from "./ComputerArtifacts.mjs";
|
|
2
|
-
import { t as DurableObjectState } from "./DurableObjectState-
|
|
2
|
+
import { t as DurableObjectState } from "./DurableObjectState-DpYdNZgT.mjs";
|
|
3
3
|
import { Context, Effect, Layer, Schema, Scope, Stream } from "effect";
|
|
4
4
|
import { CommitView, GitClient, GitCloneOptions, GitCommitOptions, GitDiffOptions, GitFetchOptions, GitLogOptions, GitUpdateRefOptions } from "@cloudflare/computer/git";
|
|
5
5
|
import { ExecSyncResult, RuntimeExecOptions, RuntimeGetOptions, RuntimeKillOptions, ShellValue, SkippedEntry, ThinkWorkspaceCompatibility, WorkspaceClient, WorkspaceRuntimeResult, WorkspaceRuntimeValue as WorkspaceRuntimeValue$1 } from "@cloudflare/computer";
|
|
@@ -56,6 +56,14 @@ declare const WorkspaceAssetsError_base: Schema.Class<WorkspaceAssetsError, Sche
|
|
|
56
56
|
}>, import("effect/Cause").YieldableError>;
|
|
57
57
|
/** Schema-serializable error for a workspace Assets operation. */
|
|
58
58
|
declare class WorkspaceAssetsError extends WorkspaceAssetsError_base {}
|
|
59
|
+
declare const WorkspaceAcquireError_base: Schema.Class<WorkspaceAcquireError, Schema.TaggedStruct<"WorkspaceAcquireError", {
|
|
60
|
+
readonly operation: Schema.String;
|
|
61
|
+
readonly message: Schema.String;
|
|
62
|
+
readonly code: Schema.optionalKey<Schema.String>;
|
|
63
|
+
readonly cause: Schema.optionalKey<Schema.Defect>;
|
|
64
|
+
}>, import("effect/Cause").YieldableError>;
|
|
65
|
+
/** Schema-serializable error while acquiring the Computer workspace client. */
|
|
66
|
+
declare class WorkspaceAcquireError extends WorkspaceAcquireError_base {}
|
|
59
67
|
type WorkspaceReadFileOptions = Omit<CloudflareReadFileOptions, "encoding">;
|
|
60
68
|
type ReadTextFileOptions = WorkspaceReadFileOptions;
|
|
61
69
|
type ListDirectoryOptions = CloudflareReaddirOptions;
|
|
@@ -264,7 +272,7 @@ declare class ComputerWorkspace extends ComputerWorkspace_base {
|
|
|
264
272
|
* Acquires the single workspace registered by `withComputerWorkspace` and
|
|
265
273
|
* releases its RPC client when the layer scope closes.
|
|
266
274
|
*/
|
|
267
|
-
static readonly layer: Layer.Layer<ComputerWorkspace,
|
|
275
|
+
static readonly layer: Layer.Layer<ComputerWorkspace, WorkspaceAcquireError, DurableObjectState>;
|
|
268
276
|
}
|
|
269
277
|
//#endregion
|
|
270
|
-
export { ComputerWorkspace, ComputerWorkspaceAssets, ComputerWorkspaceFilesystem, ComputerWorkspaceGit, ComputerWorkspaceRuntime, ComputerWorkspaceService, type ComputerWorkspaceService as ComputerWorkspaceShape, ComputerWorkspaceThink, ListDirectoryOptions, ReadTextFileOptions, RemovePathOptions, WorkspaceAssetsError, WorkspaceDirectoryEntry, WorkspaceEntryStat, WorkspaceExec, WorkspaceExecChunk, WorkspaceExecCollect, WorkspaceExecEncoding, WorkspaceExecError, WorkspaceExecEvent, WorkspaceExecOptions, WorkspaceExecResult, WorkspaceExecRun, WorkspaceExecSignal, WorkspaceExecSkippedEntry, WorkspaceExecSyncResult, WorkspaceFindOptions, WorkspaceFoundEntry, WorkspaceFsError, WorkspaceGetExec, WorkspaceGetExecOptions, WorkspaceGitCheckoutOptions, WorkspaceGitCloneOptions, WorkspaceGitCommit, WorkspaceGitCommitOptions, WorkspaceGitDiffOptions, WorkspaceGitError, WorkspaceGitFetchOptions, WorkspaceGitFetchResult, WorkspaceGitLogOptions, WorkspaceGitPerson, WorkspaceGitUpdateRefOptions, WorkspaceGrepMatch, WorkspaceGrepOptions, WorkspaceMkdirOptions, WorkspaceReadEncoding, WorkspaceReadFile, WorkspaceReadFileOptions, WorkspaceRuntimeValue, WorkspaceWriteFileContent, WorkspaceWriteFileOptions, fromWorkspaceClient };
|
|
278
|
+
export { ComputerWorkspace, ComputerWorkspaceAssets, ComputerWorkspaceFilesystem, ComputerWorkspaceGit, ComputerWorkspaceRuntime, ComputerWorkspaceService, type ComputerWorkspaceService as ComputerWorkspaceShape, ComputerWorkspaceThink, ListDirectoryOptions, ReadTextFileOptions, RemovePathOptions, WorkspaceAcquireError, WorkspaceAssetsError, WorkspaceDirectoryEntry, WorkspaceEntryStat, WorkspaceExec, WorkspaceExecChunk, WorkspaceExecCollect, WorkspaceExecEncoding, WorkspaceExecError, WorkspaceExecEvent, WorkspaceExecOptions, WorkspaceExecResult, WorkspaceExecRun, WorkspaceExecSignal, WorkspaceExecSkippedEntry, WorkspaceExecSyncResult, WorkspaceFindOptions, WorkspaceFoundEntry, WorkspaceFsError, WorkspaceGetExec, WorkspaceGetExecOptions, WorkspaceGitCheckoutOptions, WorkspaceGitCloneOptions, WorkspaceGitCommit, WorkspaceGitCommitOptions, WorkspaceGitDiffOptions, WorkspaceGitError, WorkspaceGitFetchOptions, WorkspaceGitFetchResult, WorkspaceGitLogOptions, WorkspaceGitPerson, WorkspaceGitUpdateRefOptions, WorkspaceGrepMatch, WorkspaceGrepOptions, WorkspaceMkdirOptions, WorkspaceReadEncoding, WorkspaceReadFile, WorkspaceReadFileOptions, WorkspaceRuntimeValue, WorkspaceWriteFileContent, WorkspaceWriteFileOptions, fromWorkspaceClient };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as DurableObjectState } from "./DurableObjectState-
|
|
1
|
+
import { t as DurableObjectState } from "./DurableObjectState-DcqElJ4e.mjs";
|
|
2
2
|
import { fromClient } from "./ComputerArtifacts.mjs";
|
|
3
3
|
import { t as lookup } from "./ComputerWorkspaceHostRegistry-CY5Fv4Ng.mjs";
|
|
4
4
|
import { Context, Effect, Layer, Predicate, Schema, Stream } from "effect";
|
|
@@ -37,6 +37,13 @@ var WorkspaceAssetsError = class extends Schema.TaggedError()("WorkspaceAssetsEr
|
|
|
37
37
|
code: Schema.optionalKey(Schema.String),
|
|
38
38
|
cause: Schema.optionalKey(Schema.Defect({ includeStack: true }))
|
|
39
39
|
}) {};
|
|
40
|
+
/** Schema-serializable error while acquiring the Computer workspace client. */
|
|
41
|
+
var WorkspaceAcquireError = class extends Schema.TaggedError()("WorkspaceAcquireError", {
|
|
42
|
+
operation: Schema.String,
|
|
43
|
+
message: Schema.String,
|
|
44
|
+
code: Schema.optionalKey(Schema.String),
|
|
45
|
+
cause: Schema.optionalKey(Schema.Defect({ includeStack: true }))
|
|
46
|
+
}) {};
|
|
40
47
|
const errorMessage = (cause) => cause instanceof Error ? cause.message : String(cause);
|
|
41
48
|
const errorCode = (cause) => {
|
|
42
49
|
if (Predicate.hasProperty(cause, "code") && Predicate.isString(cause.code)) return cause.code;
|
|
@@ -72,6 +79,16 @@ const execError = (operation, cause) => {
|
|
|
72
79
|
if (code !== void 0) properties.code = code;
|
|
73
80
|
return WorkspaceExecError.make(properties);
|
|
74
81
|
};
|
|
82
|
+
const acquireError = (operation, cause) => {
|
|
83
|
+
const properties = {
|
|
84
|
+
operation,
|
|
85
|
+
message: errorMessage(cause),
|
|
86
|
+
cause
|
|
87
|
+
};
|
|
88
|
+
const code = errorCode(cause);
|
|
89
|
+
if (code !== void 0) properties.code = code;
|
|
90
|
+
return WorkspaceAcquireError.make(properties);
|
|
91
|
+
};
|
|
75
92
|
const assetsError = (operation, path, cause) => {
|
|
76
93
|
const properties = {
|
|
77
94
|
operation,
|
|
@@ -404,7 +421,6 @@ const wrapRun = (handle) => {
|
|
|
404
421
|
kill
|
|
405
422
|
};
|
|
406
423
|
};
|
|
407
|
-
const releaseRun = (handle) => Effect.sync(() => handle[Symbol.dispose]());
|
|
408
424
|
const makeRuntime = (client) => {
|
|
409
425
|
const execImplementation = Effect.fn("ComputerWorkspace.runtime.exec", { attributes: {
|
|
410
426
|
family: "runtime",
|
|
@@ -415,14 +431,14 @@ const makeRuntime = (client) => {
|
|
|
415
431
|
backend: options?.backend,
|
|
416
432
|
runId: options?.id
|
|
417
433
|
});
|
|
418
|
-
const handle = yield* Effect.
|
|
434
|
+
const handle = yield* Effect.acquireDisposable(Effect.tryPromise({
|
|
419
435
|
try: () => {
|
|
420
436
|
if (Predicate.isString(source)) return client.runtime.exec(source, runtimeExecOptions(options));
|
|
421
437
|
const values = optionsOrValue === void 0 ? remainingValues : [optionsOrValue, ...remainingValues];
|
|
422
438
|
return client.runtime.exec(source, ...values);
|
|
423
439
|
},
|
|
424
440
|
catch: (cause) => execError("exec", cause)
|
|
425
|
-
})
|
|
441
|
+
}));
|
|
426
442
|
return wrapRun(handle);
|
|
427
443
|
});
|
|
428
444
|
const exec = execImplementation;
|
|
@@ -434,10 +450,10 @@ const makeRuntime = (client) => {
|
|
|
434
450
|
backend: options?.backend,
|
|
435
451
|
runId: id
|
|
436
452
|
});
|
|
437
|
-
const handle = yield* Effect.
|
|
453
|
+
const handle = yield* Effect.acquireDisposable(Effect.tryPromise({
|
|
438
454
|
try: () => client.runtime.getExec(id, runtimeGetOptions(options)),
|
|
439
455
|
catch: (cause) => execError("getExec", cause)
|
|
440
|
-
})
|
|
456
|
+
}));
|
|
441
457
|
return wrapRun(handle);
|
|
442
458
|
});
|
|
443
459
|
const killExec = Effect.fn("ComputerWorkspace.runtime.killExec", { attributes: {
|
|
@@ -567,10 +583,16 @@ var ComputerWorkspace = class ComputerWorkspace extends Context.Service()("effec
|
|
|
567
583
|
static layer = Layer.effect(ComputerWorkspace, Effect.gen(function* () {
|
|
568
584
|
const host = lookup((yield* DurableObjectState).raw);
|
|
569
585
|
if (host === void 0) return yield* Effect.die("ComputerWorkspace.layer requires a Durable Object class built with withComputerWorkspace");
|
|
570
|
-
const computer = yield* Effect.
|
|
571
|
-
|
|
586
|
+
const computer = yield* Effect.tryPromise({
|
|
587
|
+
try: () => import("@cloudflare/computer"),
|
|
588
|
+
catch: (cause) => acquireError("import", cause)
|
|
589
|
+
});
|
|
590
|
+
const client = yield* Effect.acquireDisposable(Effect.tryPromise({
|
|
591
|
+
try: () => computer.getWorkspace(host),
|
|
592
|
+
catch: (cause) => acquireError("getWorkspace", cause)
|
|
593
|
+
}));
|
|
572
594
|
return ComputerWorkspace.of(fromWorkspaceClient(client));
|
|
573
595
|
}));
|
|
574
596
|
};
|
|
575
597
|
//#endregion
|
|
576
|
-
export { ComputerWorkspace, WorkspaceAssetsError, WorkspaceExecError, WorkspaceFsError, WorkspaceGitError, fromWorkspaceClient };
|
|
598
|
+
export { ComputerWorkspace, WorkspaceAcquireError, WorkspaceAssetsError, WorkspaceExecError, WorkspaceFsError, WorkspaceGitError, fromWorkspaceClient };
|
|
@@ -1,6 +1,35 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
2
|
import { t as causeMessage } from "./ErrorMessage-Byx2OgNd.mjs";
|
|
3
|
-
import { Cause, Clock, Context, Data, Duration, Effect, Exit, Option, Predicate, Result, Schema } from "effect";
|
|
3
|
+
import { Cause, Clock, Context, Data, Duration, Effect, Exit, Fiber, FiberSet, Option, Predicate, Result, Schema } from "effect";
|
|
4
|
+
//#region src/internal/NativeCallback.ts
|
|
5
|
+
/**
|
|
6
|
+
* Runs an Effect callback owned by a native Promise operation.
|
|
7
|
+
*
|
|
8
|
+
* The callback keeps the caller's context, while a private scope owns its
|
|
9
|
+
* fiber. Closing that scope interrupts and joins the callback before awaiting
|
|
10
|
+
* the native operation's settlement.
|
|
11
|
+
*/
|
|
12
|
+
const runNativeCallback = Effect.fnUntraced(function* (operation) {
|
|
13
|
+
const callerContext = yield* Effect.context();
|
|
14
|
+
return yield* Effect.scoped(Effect.gen(function* () {
|
|
15
|
+
let nativePromise;
|
|
16
|
+
yield* Effect.addFinalizer(() => {
|
|
17
|
+
const promise = nativePromise;
|
|
18
|
+
return promise === void 0 ? Effect.void : Effect.promise(() => promise.then(() => void 0, () => void 0));
|
|
19
|
+
});
|
|
20
|
+
const runPromise = yield* FiberSet.makeRuntimePromise();
|
|
21
|
+
return yield* Effect.callback((resume) => {
|
|
22
|
+
try {
|
|
23
|
+
nativePromise = operation((effect) => runPromise(Effect.provideContext(Effect.exit(effect), callerContext)));
|
|
24
|
+
} catch (cause) {
|
|
25
|
+
resume(Effect.fail(cause));
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
nativePromise.then((value) => resume(Effect.succeed(value)), (cause) => resume(Effect.fail(cause)));
|
|
29
|
+
});
|
|
30
|
+
}));
|
|
31
|
+
});
|
|
32
|
+
//#endregion
|
|
4
33
|
//#region src/DurableObjectStorage.ts
|
|
5
34
|
var DurableObjectStorage_exports = /* @__PURE__ */ __exportAll({
|
|
6
35
|
StorageOperationError: () => StorageOperationError,
|
|
@@ -103,30 +132,35 @@ const fromDurableObjectStorage = (storage) => ({
|
|
|
103
132
|
deleteAlarm: (options) => tryStoragePromise("deleteAlarm", () => storage.deleteAlarm(options)),
|
|
104
133
|
transactionSync: (closure) => Effect.context().pipe(Effect.flatMap((context) => Effect.suspend(() => {
|
|
105
134
|
let aborted;
|
|
135
|
+
let escapedFiber;
|
|
106
136
|
try {
|
|
107
137
|
return Effect.succeed(storage.transactionSync(() => {
|
|
108
138
|
const exit = Effect.runSyncExitWith(context)(closure());
|
|
109
139
|
if (Exit.isSuccess(exit)) return exit.value;
|
|
140
|
+
const defect = Cause.findDefect(exit.cause);
|
|
141
|
+
if (Result.isSuccess(defect) && Cause.isAsyncFiberError(defect.success)) {
|
|
142
|
+
escapedFiber = defect.success.fiber;
|
|
143
|
+
escapedFiber.interruptUnsafe();
|
|
144
|
+
}
|
|
110
145
|
aborted = exit;
|
|
111
146
|
throw exit;
|
|
112
147
|
}));
|
|
113
148
|
} catch (cause) {
|
|
114
|
-
|
|
115
|
-
|
|
149
|
+
const failure = aborted !== void 0 && cause === aborted && Exit.isFailure(aborted) ? Effect.failCause(aborted.cause) : Effect.fail(storageError("transactionSync", cause));
|
|
150
|
+
const fiber = escapedFiber;
|
|
151
|
+
if (fiber !== void 0) return Fiber.interrupt(fiber).pipe(Effect.andThen(failure));
|
|
152
|
+
return failure;
|
|
116
153
|
}
|
|
117
154
|
}))),
|
|
118
|
-
transaction: (closure) => Effect.
|
|
155
|
+
transaction: (closure) => Effect.suspend(() => {
|
|
119
156
|
let aborted;
|
|
120
|
-
storage.transaction(async (txn) => {
|
|
121
|
-
const exit = await Effect.
|
|
157
|
+
return runNativeCallback((run) => storage.transaction(async (txn) => {
|
|
158
|
+
const exit = await run(Effect.suspend(() => closure(fromDurableObjectTransaction(txn))));
|
|
122
159
|
if (Exit.isSuccess(exit)) return exit.value;
|
|
123
160
|
aborted = exit;
|
|
124
161
|
throw exit;
|
|
125
|
-
}).
|
|
126
|
-
|
|
127
|
-
else resume(Effect.fail(storageError("transaction", cause)));
|
|
128
|
-
});
|
|
129
|
-
}))),
|
|
162
|
+
})).pipe(Effect.catch((cause) => aborted !== void 0 && cause === aborted && Exit.isFailure(aborted) ? Effect.failCause(aborted.cause) : Effect.fail(storageError("transaction", cause))));
|
|
163
|
+
}),
|
|
130
164
|
sync: () => tryStoragePromise("sync", () => storage.sync()),
|
|
131
165
|
getCurrentBookmark: () => tryStoragePromise("getCurrentBookmark", () => storage.getCurrentBookmark()),
|
|
132
166
|
onNextSessionRestoreBookmark: (bookmark) => tryStoragePromise("onNextSessionRestoreBookmark", () => storage.onNextSessionRestoreBookmark(bookmark)),
|
|
@@ -160,38 +194,31 @@ var DurableWebSocketAttachmentError = class extends Data.TaggedError("DurableWeb
|
|
|
160
194
|
return `Durable Object websocket attachment ${this.operation} failed: ${causeMessage(this.cause)}`;
|
|
161
195
|
}
|
|
162
196
|
};
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
try: () => raw.serializeAttachment(value),
|
|
179
|
-
catch: (cause) => new DurableWebSocketAttachmentError({
|
|
180
|
-
operation: "serialize",
|
|
181
|
-
cause
|
|
182
|
-
})
|
|
183
|
-
}),
|
|
184
|
-
deserializeAttachment: Effect.try({
|
|
185
|
-
try: () => raw.deserializeAttachment(),
|
|
186
|
-
catch: (cause) => new DurableWebSocketAttachmentError({
|
|
187
|
-
operation: "deserialize",
|
|
188
|
-
cause
|
|
189
|
-
})
|
|
197
|
+
const fromWebSocket = (raw) => ({
|
|
198
|
+
raw,
|
|
199
|
+
send: (data) => Effect.try({
|
|
200
|
+
try: () => raw.send(data),
|
|
201
|
+
catch: (cause) => new DurableWebSocketSendError({ cause })
|
|
202
|
+
}),
|
|
203
|
+
close: (code, reason) => Effect.try({
|
|
204
|
+
try: () => raw.close(code, reason),
|
|
205
|
+
catch: (cause) => new DurableWebSocketCloseError({ cause })
|
|
206
|
+
}),
|
|
207
|
+
serializeAttachment: (value) => Effect.try({
|
|
208
|
+
try: () => raw.serializeAttachment(value),
|
|
209
|
+
catch: (cause) => new DurableWebSocketAttachmentError({
|
|
210
|
+
operation: "serialize",
|
|
211
|
+
cause
|
|
190
212
|
})
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
213
|
+
}),
|
|
214
|
+
deserializeAttachment: Effect.try({
|
|
215
|
+
try: () => raw.deserializeAttachment(),
|
|
216
|
+
catch: (cause) => new DurableWebSocketAttachmentError({
|
|
217
|
+
operation: "deserialize",
|
|
218
|
+
cause
|
|
219
|
+
})
|
|
220
|
+
})
|
|
221
|
+
});
|
|
195
222
|
const acceptUpgrade = Effect.fn("DurableObjectWebSocket.acceptUpgrade")(function* (options = {}) {
|
|
196
223
|
const state = yield* DurableObjectState;
|
|
197
224
|
const pair = new WebSocketPair();
|
|
@@ -257,13 +284,13 @@ const causeError = (cause) => {
|
|
|
257
284
|
const squashed = Cause.squash(cause);
|
|
258
285
|
return squashed instanceof Error ? squashed : new Error(Cause.pretty(cause), { cause: squashed });
|
|
259
286
|
};
|
|
260
|
-
const failureHandler = (label, cause, options) => (options?.onFailure?.(cause) ?? Effect.logError(`${label} failed`, Cause.pretty(cause))).pipe(Effect.catchCause((handlerCause) => Effect.logError(`${label} failure handler failed`, Cause.pretty(cause), Cause.pretty(handlerCause))));
|
|
287
|
+
const failureHandler = (label, cause, options) => Effect.suspend(() => options?.onFailure?.(cause) ?? Effect.logError(`${label} failed`, Cause.pretty(cause))).pipe(Effect.catchCause((handlerCause) => Effect.logError(`${label} failure handler failed`, Cause.pretty(cause), Cause.pretty(handlerCause))));
|
|
261
288
|
const makeWaitUntilScheduler = (label, register, runPromiseExit = (effect) => Effect.runPromiseExit(effect)) => {
|
|
262
289
|
return (effect, options, mode) => Effect.context().pipe(Effect.flatMap((context) => Effect.sync(() => {
|
|
263
|
-
const runHandler = (cause) => runPromiseExit(Effect.
|
|
290
|
+
const runHandler = (cause) => runPromiseExit(Effect.provideContext(Effect.scoped(failureHandler(label, cause, options)), context)).then((exit) => {
|
|
264
291
|
if (Exit.isFailure(exit)) console.error(`${label} failure handler failed`, Cause.pretty(exit.cause));
|
|
265
292
|
});
|
|
266
|
-
register(runPromiseExit(Effect.
|
|
293
|
+
register(runPromiseExit(Effect.provideContext(Effect.scoped(effect), context)).then(async (exit) => {
|
|
267
294
|
if (Exit.isSuccess(exit)) return;
|
|
268
295
|
await runHandler(exit.cause);
|
|
269
296
|
if (mode === "propagate") throw causeError(exit.cause);
|
|
@@ -295,8 +322,12 @@ const fromDurableObjectState = (state) => {
|
|
|
295
322
|
id: state.id,
|
|
296
323
|
storage: fromDurableObjectStorage(state.storage),
|
|
297
324
|
waitUntil,
|
|
298
|
-
blockConcurrencyWhile: (effect) =>
|
|
299
|
-
blockConcurrencyWhileOrReset: (effect) =>
|
|
325
|
+
blockConcurrencyWhile: (effect) => runNativeCallback((run) => state.blockConcurrencyWhile(() => runExitPreservingTypedFailures(run, effect))).pipe(Effect.orDie, Effect.flatten),
|
|
326
|
+
blockConcurrencyWhileOrReset: (effect) => runNativeCallback((run) => state.blockConcurrencyWhile(async () => {
|
|
327
|
+
const exit = await run(effect);
|
|
328
|
+
if (Exit.isFailure(exit)) throw Cause.squash(exit.cause);
|
|
329
|
+
return exit.value;
|
|
330
|
+
})).pipe(Effect.orDie),
|
|
300
331
|
acceptWebSocket: (ws, tags) => Effect.sync(() => state.acceptWebSocket(ws.raw, tags)),
|
|
301
332
|
getWebSockets: (tag) => Effect.sync(() => state.getWebSockets(tag).map((socket) => fromWebSocket(socket))),
|
|
302
333
|
setWebSocketAutoResponse: (pair) => Effect.sync(() => state.setWebSocketAutoResponse(pair)),
|
|
@@ -308,10 +339,10 @@ const fromDurableObjectState = (state) => {
|
|
|
308
339
|
abort: (reason, options) => Effect.sync(() => state.abort(reason, options))
|
|
309
340
|
};
|
|
310
341
|
};
|
|
311
|
-
const
|
|
312
|
-
const exit = await
|
|
342
|
+
const runExitPreservingTypedFailures = async (run, effect) => {
|
|
343
|
+
const exit = await run(effect);
|
|
313
344
|
if (Exit.isFailure(exit) && (Cause.hasDies(exit.cause) || Cause.hasInterrupts(exit.cause))) throw Cause.squash(exit.cause);
|
|
314
345
|
return exit;
|
|
315
346
|
};
|
|
316
347
|
//#endregion
|
|
317
|
-
export { DurableObjectWebSocket_exports as a, DurableObjectStorage_exports as c, fromExecutionContext as i, DurableObjectState_exports as n, DurableWebSocketAttachmentError as o, fromDurableObjectState as r, fromWebSocket as s, DurableObjectState as t };
|
|
348
|
+
export { DurableObjectWebSocket_exports as a, DurableObjectStorage_exports as c, fromExecutionContext as i, runNativeCallback as l, DurableObjectState_exports as n, DurableWebSocketAttachmentError as o, fromDurableObjectState as r, fromWebSocket as s, DurableObjectState as t };
|
|
@@ -6,7 +6,7 @@ declare namespace DurableObjectStorage_d_exports {
|
|
|
6
6
|
export { DurableObjectStorage, DurableObjectTransaction, SchemaBackedSyncKvStorage, SqlCursor, SqlStorage, SqlStorageValue, StorageOperationError, SyncKvDefinition, SyncKvStorage, fromDurableObjectStorage };
|
|
7
7
|
}
|
|
8
8
|
type SqlStorageValue = globalThis.SqlStorageValue;
|
|
9
|
-
declare const StorageOperationError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) =>
|
|
9
|
+
declare const StorageOperationError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => Cause.YieldableError & {
|
|
10
10
|
readonly _tag: "StorageOperationError";
|
|
11
11
|
} & Readonly<A>;
|
|
12
12
|
declare class StorageOperationError extends StorageOperationError_base<{
|
|
@@ -142,7 +142,7 @@ interface DurableWebSocket<Attachment = unknown> {
|
|
|
142
142
|
send(data: DurableWebSocketSendData): Effect.Effect<void, DurableWebSocketSendError>;
|
|
143
143
|
close(code?: number, reason?: string): Effect.Effect<void, DurableWebSocketCloseError>;
|
|
144
144
|
/** Serializes hibernation attachment metadata onto the socket. */
|
|
145
|
-
serializeAttachment<A = Attachment>(value: A): Effect.Effect<void, DurableWebSocketAttachmentError>;
|
|
145
|
+
serializeAttachment<A extends Attachment = Attachment>(value: A): Effect.Effect<void, DurableWebSocketAttachmentError>;
|
|
146
146
|
/** Deserializes hibernation attachment metadata from the socket. */
|
|
147
147
|
readonly deserializeAttachment: Effect.Effect<unknown, DurableWebSocketAttachmentError>;
|
|
148
148
|
}
|
|
@@ -274,8 +274,9 @@ declare const isWireError: (error: WireValue) => error is WireError;
|
|
|
274
274
|
*/
|
|
275
275
|
declare const encodeWireError: (error: WireValue) => WireValue;
|
|
276
276
|
declare const decodeWireError: (cause: WireValue) => WireValue;
|
|
277
|
+
declare const reservedMethodNameValues: readonly ["constructor", "fetch", "connect", "alarm", "webSocketMessage", "webSocketClose", "webSocketError", "then", "dup", "dispose", "serialize", "deserialize"];
|
|
277
278
|
declare const reservedMethodNames: Set<string>;
|
|
278
|
-
type ReservedMethodName$3 =
|
|
279
|
+
type ReservedMethodName$3 = (typeof reservedMethodNameValues)[number];
|
|
279
280
|
type ServiceFreeSchema$1 = Schema.Codec<any, any, never, never>;
|
|
280
281
|
interface Method$2<Args extends ReadonlyArray<ServiceFreeSchema$1> = ReadonlyArray<ServiceFreeSchema$1>, Success extends ServiceFreeSchema$1 = ServiceFreeSchema$1> {
|
|
281
282
|
readonly args: Args;
|
|
@@ -516,9 +517,9 @@ type ApiOrDefinition<Api extends object, Definition> = [Api] extends [never] ? A
|
|
|
516
517
|
/**
|
|
517
518
|
* Binding metadata used to create an Effect service from a Worker binding.
|
|
518
519
|
*/
|
|
519
|
-
interface ServiceBindingDefinition<Definition$
|
|
520
|
+
interface ServiceBindingDefinition<Definition$7 extends Definition.Any | undefined = undefined> {
|
|
520
521
|
readonly binding: string;
|
|
521
|
-
readonly definition?: Definition$
|
|
522
|
+
readonly definition?: Definition$7;
|
|
522
523
|
/** Append live trace context only when the receiver also enables rpcTracing. */
|
|
523
524
|
readonly rpcTracing?: boolean;
|
|
524
525
|
}
|
|
@@ -554,7 +555,7 @@ type ServiceMethodCloudflareReturn<Api, Method extends keyof Api> = AsyncMethodC
|
|
|
554
555
|
type ServiceCall<R, Api> = <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<ServiceMethodSuccess<Api, Method>, ServiceBindingRpcError, R>;
|
|
555
556
|
type DefinitionDirectMethods<R, Definition$4 extends Definition.Any> = { readonly [Method in Definition$3.MethodNames<Definition$4>]: (...args: Method$2.Args<Definition$4["methods"][Method]>) => Effect.Effect<Method$2.Success<Definition$4["methods"][Method]>, ServiceBindingRpcError, R>; };
|
|
556
557
|
type DirectMethods<R, Definition$13> = Definition$13 extends Definition.Any ? DefinitionDirectMethods<R, Definition$13> : {};
|
|
557
|
-
type ServiceBindingEffectClient<Api extends object, Definition$
|
|
558
|
+
type ServiceBindingEffectClient<Api extends object, Definition$8 extends Definition.Any | undefined = undefined> = DirectMethods<never, Definition$8> & {
|
|
558
559
|
readonly fetch: (input: RequestInfo | URL, init?: RequestInit) => Effect.Effect<globalThis.Response, ServiceBindingFetchError>;
|
|
559
560
|
/**
|
|
560
561
|
* Invokes a Worker RPC method and returns Cloudflare's raw RPC result.
|
|
@@ -581,27 +582,27 @@ type ServiceBindingEffectClient<Api extends object, Definition$7 extends Definit
|
|
|
581
582
|
* Use this for RPC methods that return Cloudflare RPC resources or other
|
|
582
583
|
* disposable objects whose lifetime should be tied to an Effect scope.
|
|
583
584
|
*/
|
|
584
|
-
readonly scopedCall: <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<Awaited<ServiceMethodSuccess<Api, Method>>,
|
|
585
|
+
readonly scopedCall: <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<Awaited<ServiceMethodSuccess<Api, Method>>, ServiceBindingRpcError, Scope.Scope>;
|
|
585
586
|
};
|
|
586
|
-
type ServiceBindingStaticClient<R, Api extends object, Definition$
|
|
587
|
+
type ServiceBindingStaticClient<R, Api extends object, Definition$5 extends Definition.Any | undefined = undefined> = DirectMethods<R, Definition$5> & {
|
|
587
588
|
readonly fetch: (input: RequestInfo | URL, init?: RequestInit) => Effect.Effect<globalThis.Response, ServiceBindingFetchError, R>;
|
|
588
589
|
readonly rpc: <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<ServiceMethodCloudflareReturn<Api, Method>, ServiceBindingRpcError, R>;
|
|
589
590
|
readonly call: <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<ServiceMethodSuccess<Api, Method>, ServiceBindingRpcError, R>;
|
|
590
|
-
readonly scopedCall: <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<Awaited<ServiceMethodSuccess<Api, Method>>,
|
|
591
|
+
readonly scopedCall: <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<Awaited<ServiceMethodSuccess<Api, Method>>, ServiceBindingRpcError, Scope.Scope | R>;
|
|
591
592
|
};
|
|
592
593
|
type ServiceBindingValue = Schema.Schema.Type<typeof Schema.Unknown>;
|
|
593
594
|
declare const isServiceBindingClient: <Api extends object>(value: ServiceBindingValue) => value is ServiceBindingClient<Api>;
|
|
594
|
-
declare const makeClient: <Api extends object, const Definition$
|
|
595
|
-
declare const layer: <Self, Api extends object, const Definition$
|
|
596
|
-
declare const Service: <Self, Api extends object = never>() => <Id extends string, const Definition$
|
|
595
|
+
declare const makeClient: <Api extends object, const Definition$10 extends Definition.Any | undefined = undefined>(definition: ServiceBindingDefinition<Definition$10>) => ((service: ServiceBindingClient<Api>) => ServiceBindingEffectClient<Api, Definition$10>);
|
|
596
|
+
declare const layer: <Self, Api extends object, const Definition$11 extends Definition.Any | undefined = undefined>(tag: Context.Service<Self, ServiceBindingEffectClient<Api, Definition$11>>, definition: ServiceBindingDefinition<Definition$11>) => import("effect/Layer").Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
|
|
597
|
+
declare const Service: <Self, Api extends object = never>() => <Id extends string, const Definition$6 extends Definition.Any | undefined = undefined>(id: Id, definition: ServiceBindingDefinition<Definition$6>) => BindingService<Self, Id, ServiceBindingEffectClient<ApiOrDefinition<Api, Definition$6>, Definition$6>> & DirectMethods<Self, Definition$6> & {
|
|
597
598
|
readonly [TypeId]: typeof TypeId;
|
|
598
|
-
readonly definition: ServiceBindingDefinition<Definition$
|
|
599
|
+
readonly definition: ServiceBindingDefinition<Definition$6>;
|
|
599
600
|
readonly fetch: (input: URL | RequestInfo<unknown, CfProperties<unknown>>, init?: RequestInit<CfProperties<unknown>> | undefined) => Effect.Effect<Response, ServiceBindingFetchError, Self>;
|
|
600
|
-
readonly rpc: <Method extends ServiceMethodKey<ApiOrDefinition<Api, Definition$
|
|
601
|
-
readonly call: <Method extends ServiceMethodKey<ApiOrDefinition<Api, Definition$
|
|
602
|
-
readonly scopedCall: <Method extends ServiceMethodKey<ApiOrDefinition<Api, Definition$
|
|
601
|
+
readonly rpc: <Method extends ServiceMethodKey<ApiOrDefinition<Api, Definition$6>>>(method: Method, ...args: AsyncMethodArgs<ApiOrDefinition<Api, Definition$6>, Method>) => Effect.Effect<Result$1<AsyncMethodSuccess<ApiOrDefinition<Api, Definition$6>, Method>>, ServiceBindingRpcError, Self>;
|
|
602
|
+
readonly call: <Method extends ServiceMethodKey<ApiOrDefinition<Api, Definition$6>>>(method: Method, ...args: AsyncMethodArgs<ApiOrDefinition<Api, Definition$6>, Method>) => Effect.Effect<AsyncMethodSuccess<ApiOrDefinition<Api, Definition$6>, Method>, ServiceBindingRpcError, Self>;
|
|
603
|
+
readonly scopedCall: <Method extends ServiceMethodKey<ApiOrDefinition<Api, Definition$6>>>(method: Method, ...args: AsyncMethodArgs<ApiOrDefinition<Api, Definition$6>, Method>) => Effect.Effect<Awaited<AsyncMethodSuccess<ApiOrDefinition<Api, Definition$6>, Method>>, ServiceBindingRpcError, Self | Scope.Scope>;
|
|
603
604
|
};
|
|
604
|
-
declare const makeDirectMethods: <R, Api, Definition$
|
|
605
|
+
declare const makeDirectMethods: <R, Api, Definition$9 extends Definition.Any | undefined>(rpcDefinition: Definition$9 | undefined, call: ServiceCall<R, Api>) => DirectMethods<R, Definition$9>;
|
|
605
606
|
declare namespace WorkerDefinition_d_exports {
|
|
606
607
|
export { Api, Definition, HandlerEffect, Handlers, LayerOptions, Method$1 as Method, Methods, NoReservedMethods, Options, ReservedMethodName$1 as ReservedMethodName, ServerApi$1 as ServerApi, ServiceFreeSchema, Tag, TagClass, Worker, implement, make$1 as make, method };
|
|
607
608
|
}
|
|
@@ -750,10 +751,12 @@ interface WorkerOptions<RRuntime, REvent = never, EventLayerError = never, Rpc e
|
|
|
750
751
|
/**
|
|
751
752
|
* Layer provided around each Cloudflare event handled by this Worker.
|
|
752
753
|
*
|
|
753
|
-
* The layer is built inside the event's Effect scope
|
|
754
|
-
*
|
|
755
|
-
*
|
|
756
|
-
*
|
|
754
|
+
* The layer is built inside the event's Effect scope. For fetch handlers that
|
|
755
|
+
* return an Effect `HttpServerResponse` stream, its scope remains open until
|
|
756
|
+
* the response body finishes or is canceled. Native `Response` values pass
|
|
757
|
+
* through unchanged, so their body streams do not carry this scoped-lifetime
|
|
758
|
+
* guarantee. Fetch, queue, and RPC handlers schedule a best-effort telemetry
|
|
759
|
+
* flush capped at two seconds.
|
|
757
760
|
*/
|
|
758
761
|
readonly eventLayer?: Layer.Layer<REvent, EventLayerError, WorkerBaseContext<RRuntime>>;
|
|
759
762
|
readonly fetch?: Effect.Effect<WorkerFetchSuccess, unknown, WorkerFetchContext<RRuntime | REvent>>;
|
|
@@ -794,8 +797,10 @@ interface FetchHandler<Env extends WorkerEnv = WorkerEnv> {
|
|
|
794
797
|
readonly fetch: (request: Request, env: Env, ctx: globalThis.ExecutionContext) => Promise<Response>;
|
|
795
798
|
}
|
|
796
799
|
/**
|
|
797
|
-
*
|
|
798
|
-
*
|
|
800
|
+
* Cloudflare creates a new `WorkerEntrypoint` instance for each native
|
|
801
|
+
* invocation, so this base layer is not shared across invocations. Its managed
|
|
802
|
+
* runtime has no deterministic disposal point in this adapter; use
|
|
803
|
+
* `eventLayer` for resources whose finalizers must run with an event.
|
|
799
804
|
*/
|
|
800
805
|
declare function make<ROut, LayerError>(layer: Layer.Layer<ROut, LayerError, ExecutionContext | WorkerContext | WorkerEnvironment>, fetch: WorkerHandler<ROut>): WorkerClass<Record<never, never>, ROut>;
|
|
801
806
|
declare function make<ROut, LayerError, REvent, EventLayerError = never, const Rpc extends WorkerRpc<ROut | REvent> = Record<never, never>>(layer: Layer.Layer<ROut, LayerError, ExecutionContext | WorkerContext | WorkerEnvironment>, options: WorkerOptionsWithEventLayer<ROut, REvent, EventLayerError, Rpc>): WorkerClass<Rpc, ROut | REvent>;
|
|
@@ -804,12 +809,13 @@ declare function make<ROut, LayerError, REvent extends never = never, EventLayer
|
|
|
804
809
|
* Creates an `ExportedHandler`-compatible `{ fetch }` object backed by
|
|
805
810
|
* {@link make}.
|
|
806
811
|
*
|
|
807
|
-
* The Effect runtime is cached per `env` identity, so the
|
|
808
|
-
* once
|
|
809
|
-
*
|
|
810
|
-
*
|
|
811
|
-
*
|
|
812
|
-
*
|
|
812
|
+
* The Effect runtime is cached per `env` identity, so the base layer builds
|
|
813
|
+
* once for that cached handler. Request handlers and `eventLayer` receive fresh
|
|
814
|
+
* `ExecutionContext` and `WorkerContext` services. A service constructed by the
|
|
815
|
+
* cached base layer from either context instead captures the first request's
|
|
816
|
+
* value, so construct invocation-bound services in `eventLayer`. Cloudflare
|
|
817
|
+
* provides no isolate shutdown hook, so cached base-layer finalizers are not
|
|
818
|
+
* guaranteed to run.
|
|
813
819
|
*/
|
|
814
820
|
declare function makeFetchHandler<ROut, LayerError, REvent, EventLayerError = never, Env extends WorkerEnv = WorkerEnv>(layer: Layer.Layer<ROut, LayerError, ExecutionContext | WorkerContext | WorkerEnvironment>, options: FetchWorkerOptionsWithEventLayer<ROut, REvent, EventLayerError>): FetchHandler<Env>;
|
|
815
821
|
declare function makeFetchHandler<ROut, LayerError, REvent extends never = never, EventLayerError = never, Env extends WorkerEnv = WorkerEnv>(layer: Layer.Layer<ROut, LayerError, ExecutionContext | WorkerContext | WorkerEnvironment>, options: FetchWorkerOptions<ROut, REvent, EventLayerError>): FetchHandler<Env>;
|
package/dist/Vitest.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { c as WorkerEnvironment, s as WorkerEnv } from "./Binding-DKcLrQCM.mjs";
|
|
2
|
-
import { n as DurableObjectStateService, t as DurableObjectState } from "./DurableObjectState-
|
|
3
|
-
import { o as WorkflowInstanceStatusName } from "./WorkflowBinding-
|
|
2
|
+
import { n as DurableObjectStateService, t as DurableObjectState } from "./DurableObjectState-DpYdNZgT.mjs";
|
|
3
|
+
import { o as WorkflowInstanceStatusName } from "./WorkflowBinding-Cn3AuUyP.mjs";
|
|
4
4
|
import { Effect, Layer, Schema } from "effect";
|
|
5
5
|
import { DurableObject } from "cloudflare:workers";
|
|
6
6
|
import { adminSecretsStore as adminSecretsStore$1, getQueueResult, introspectWorkflow as introspectWorkflow$1, introspectWorkflowInstance as introspectWorkflowInstance$1 } from "cloudflare:test";
|
package/dist/Vitest.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as WorkerEnvironment, i as WorkerConfig } from "./ErrorMessage-Byx2OgNd.mjs";
|
|
2
|
-
import { r as fromDurableObjectState, t as DurableObjectState } from "./DurableObjectState-
|
|
2
|
+
import { l as runNativeCallback, r as fromDurableObjectState, t as DurableObjectState } from "./DurableObjectState-DcqElJ4e.mjs";
|
|
3
3
|
import { ConfigProvider, Effect, Exit, Layer } from "effect";
|
|
4
4
|
import { env } from "cloudflare:workers";
|
|
5
5
|
import { abortAllDurableObjects as abortAllDurableObjects$1, adminSecretsStore as adminSecretsStore$1, applyD1Migrations as applyD1Migrations$1, createExecutionContext, createMessageBatch, createPagesEventContext, createScheduledController, evictAllDurableObjects as evictAllDurableObjects$1, evictDurableObject as evictDurableObject$1, getQueueResult, introspectWorkflow as introspectWorkflow$1, introspectWorkflowInstance as introspectWorkflowInstance$1, listDurableObjectIds as listDurableObjectIds$1, reset as reset$1, runDurableObjectAlarm as runDurableObjectAlarm$1, runInDurableObject as runInDurableObject$1, waitOnExecutionContext } from "cloudflare:test";
|
|
@@ -63,12 +63,10 @@ const queue = Effect.fn("effect-cf/vitest/queue")(function* (Worker, queueName,
|
|
|
63
63
|
* passed to `use` for direct access.
|
|
64
64
|
*/
|
|
65
65
|
const runInDurableObject = Effect.fn("effect-cf/vitest/runInDurableObject")(function* (stub, use) {
|
|
66
|
-
|
|
67
|
-
return yield* yield* Effect.promise(() => runInDurableObject$1(stub, (instance, nativeState) => {
|
|
66
|
+
return yield* yield* runNativeCallback((run) => runInDurableObject$1(stub, (instance, nativeState) => {
|
|
68
67
|
const state = fromDurableObjectState(nativeState);
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}));
|
|
68
|
+
return run(Effect.provideService(Effect.suspend(() => use(instance, state)), DurableObjectState, state));
|
|
69
|
+
})).pipe(Effect.orDie);
|
|
72
70
|
});
|
|
73
71
|
const runDurableObjectAlarm = Effect.fn("effect-cf/vitest/runDurableObjectAlarm")(function* (stub) {
|
|
74
72
|
return yield* Effect.promise(() => runDurableObjectAlarm$1(stub));
|
|
@@ -119,12 +117,11 @@ const wrapWorkflowModifier = (modifier) => ({
|
|
|
119
117
|
forceEventTimeout: (step) => Effect.promise(() => modifier.forceEventTimeout(step))
|
|
120
118
|
});
|
|
121
119
|
const runWorkflowModifier = Effect.fnUntraced(function* (register, use) {
|
|
122
|
-
|
|
123
|
-
return yield* yield* Effect.promise(async () => {
|
|
120
|
+
return yield* yield* runNativeCallback(async (run) => {
|
|
124
121
|
let callbackExit;
|
|
125
122
|
try {
|
|
126
123
|
await register(async (modifier) => {
|
|
127
|
-
callbackExit = await Effect.
|
|
124
|
+
callbackExit = await run(Effect.suspend(() => use(wrapWorkflowModifier(modifier))));
|
|
128
125
|
if (Exit.isFailure(callbackExit)) throw callbackExit;
|
|
129
126
|
});
|
|
130
127
|
} catch (cause) {
|
|
@@ -133,7 +130,7 @@ const runWorkflowModifier = Effect.fnUntraced(function* (register, use) {
|
|
|
133
130
|
}
|
|
134
131
|
if (callbackExit === void 0) throw new Error("The Workers Vitest plugin did not invoke the Workflow modifier callback");
|
|
135
132
|
return callbackExit;
|
|
136
|
-
});
|
|
133
|
+
}).pipe(Effect.orDie);
|
|
137
134
|
});
|
|
138
135
|
const wrapWorkflowInstanceIntrospector = (introspector) => ({
|
|
139
136
|
raw: introspector,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { c as WorkerEnvironment, r as BindingValidationError, t as BindingNotFoundError } from "./Binding-DKcLrQCM.mjs";
|
|
2
|
-
import { w as ServiceFreeSchema } from "./DurableObjectState-
|
|
2
|
+
import { w as ServiceFreeSchema } from "./DurableObjectState-DpYdNZgT.mjs";
|
|
3
3
|
import { Context, Effect, Option, Schema } from "effect";
|
|
4
4
|
declare namespace WorkflowBinding_d_exports {
|
|
5
5
|
export { WorkflowBindingClient, WorkflowBindingDefinition, WorkflowInstance, WorkflowInstanceCreateBatchOptions, WorkflowInstanceCreateOptions, WorkflowInstanceEvent, WorkflowInstanceLocationHint, WorkflowInstanceRestartOptions, WorkflowInstanceStatus, WorkflowInstanceStatusName, WorkflowInstanceTerminateOptions, WorkflowOperationError, WorkflowResultDecodeError, isWorkflow, layer, makeClient };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { a as Environment_d_exports, c as WorkerEnvironment, i as Binding_d_exports, n as BindingService, o as WorkerConfig, r as BindingValidationError, s as WorkerEnv, t as BindingNotFoundError } from "./Binding-DKcLrQCM.mjs";
|
|
2
2
|
import { l as Artifacts_d_exports } from "./Artifacts-B3r3RuTB.mjs";
|
|
3
|
-
import { A as DurableWebSocket, C as RpcDefinition_d_exports, D as AcceptUpgradeOptions, E as Rpc_d_exports, M as DurableObjectStorage_d_exports, N as StorageOperationError, O as AcceptedUpgrade, S as ReservedMethodName$2, T as Provider, _ as Queue_d_exports, a as NativeRequest, b as Definition$4, c as WorkerDefinition_d_exports, d as AsyncMethodCloudflareReturn, f as AsyncMethodKey, g as RpcTracing_d_exports, h as RpcInvocationInfo, i as ExecutionContext, j as DurableWebSocketAttachmentError, k as DurableObjectWebSocket_d_exports, l as ServiceBinding_d_exports, m as ReceiverOptions, o as WorkerContext, p as AsyncMethodSuccess, r as DurableObjectState_d_exports, s as Worker_d_exports, t as DurableObjectState, u as AsyncMethodArgs, v as QueueDefinition_d_exports, w as ServiceFreeSchema$1, x as Method$2, y as QueueBinding_d_exports } from "./DurableObjectState-
|
|
3
|
+
import { A as DurableWebSocket, C as RpcDefinition_d_exports, D as AcceptUpgradeOptions, E as Rpc_d_exports, M as DurableObjectStorage_d_exports, N as StorageOperationError, O as AcceptedUpgrade, S as ReservedMethodName$2, T as Provider, _ as Queue_d_exports, a as NativeRequest, b as Definition$4, c as WorkerDefinition_d_exports, d as AsyncMethodCloudflareReturn, f as AsyncMethodKey, g as RpcTracing_d_exports, h as RpcInvocationInfo, i as ExecutionContext, j as DurableWebSocketAttachmentError, k as DurableObjectWebSocket_d_exports, l as ServiceBinding_d_exports, m as ReceiverOptions, o as WorkerContext, p as AsyncMethodSuccess, r as DurableObjectState_d_exports, s as Worker_d_exports, t as DurableObjectState, u as AsyncMethodArgs, v as QueueDefinition_d_exports, w as ServiceFreeSchema$1, x as Method$2, y as QueueBinding_d_exports } from "./DurableObjectState-DpYdNZgT.mjs";
|
|
4
4
|
import { t as Hyperdrive_d_exports } from "./Hyperdrive-HrwFlZ6x.mjs";
|
|
5
5
|
import { t as ContainerNamespace_d_exports } from "./ContainerNamespace-DbLaeFhN.mjs";
|
|
6
|
-
import { a as WorkflowInstanceCreateOptions, i as WorkflowInstanceCreateBatchOptions, n as WorkflowBinding_d_exports, r as WorkflowInstance, s as WorkflowOperationError, t as WorkflowBindingClient } from "./WorkflowBinding-
|
|
6
|
+
import { a as WorkflowInstanceCreateOptions, i as WorkflowInstanceCreateBatchOptions, n as WorkflowBinding_d_exports, r as WorkflowInstance, s as WorkflowOperationError, t as WorkflowBindingClient } from "./WorkflowBinding-Cn3AuUyP.mjs";
|
|
7
7
|
import { Cause, Config, Context, Data, DateTime, Duration, Effect, Layer, Option, Predicate, Redacted, Schema, Scope } from "effect";
|
|
8
8
|
import { Headers as Headers$1, HttpClient, HttpClientResponse } from "effect/unstable/http";
|
|
9
9
|
import { OtlpExporter, OtlpResource } from "effect/unstable/observability";
|
|
@@ -513,6 +513,8 @@ declare const layerProtobuf: (options?: Omit<LayerOptions$9, "serialization">) =
|
|
|
513
513
|
*
|
|
514
514
|
* Provide this layer at runtime scope for long-lived metrics aggregation, or at
|
|
515
515
|
* handler scope when traces/logs should flush as the Cloudflare event finishes.
|
|
516
|
+
* A handler-scoped exporter can delay scope closure while its own finalizer
|
|
517
|
+
* flushes; the two-second background flush limit does not bound layer shutdown.
|
|
516
518
|
*/
|
|
517
519
|
declare const layerWorker: (options?: WorkerLayerOptions) => Layer.Layer<OtlpExporter.Flusher>;
|
|
518
520
|
/**
|
|
@@ -660,7 +662,7 @@ type DurableObjectNamespaceEffectClient<Api extends object, Definition extends D
|
|
|
660
662
|
* Use this for RPC methods that return Cloudflare RPC resources or other
|
|
661
663
|
* disposable objects whose lifetime should be tied to an Effect scope.
|
|
662
664
|
*/
|
|
663
|
-
readonly scopedCall: <Method extends StubMethodKey<Api>>(stub: DurableObjectStubClient<Api>, method: Method, ...args: StubMethodArgs<Api, Method>) => Effect.Effect<Awaited<StubMethodSuccess<Api, Method>>,
|
|
665
|
+
readonly scopedCall: <Method extends StubMethodKey<Api>>(stub: DurableObjectStubClient<Api>, method: Method, ...args: StubMethodArgs<Api, Method>) => Effect.Effect<Awaited<StubMethodSuccess<Api, Method>>, DurableObjectRpcError, Scope.Scope>;
|
|
664
666
|
/**
|
|
665
667
|
* Exposes the underlying native Durable Object namespace binding.
|
|
666
668
|
*
|
|
@@ -679,7 +681,7 @@ type DurableObjectNamespaceStaticClient<R, Api extends object, Definition extend
|
|
|
679
681
|
readonly fetch: (stub: DurableObjectStubClient<Api>, input: RequestInfo | URL, init?: RequestInit) => Effect.Effect<globalThis.Response, DurableObjectFetchError, R>;
|
|
680
682
|
readonly rpc: <Method extends StubMethodKey<Api>>(stub: DurableObjectStubClient<Api>, method: Method, ...args: StubMethodArgs<Api, Method>) => Effect.Effect<StubMethodCloudflareReturn<Api, Method>, DurableObjectRpcError, R>;
|
|
681
683
|
readonly call: <Method extends StubMethodKey<Api>>(stub: DurableObjectStubClient<Api>, method: Method, ...args: StubMethodArgs<Api, Method>) => Effect.Effect<StubMethodSuccess<Api, Method>, DurableObjectRpcError, R>;
|
|
682
|
-
readonly scopedCall: <Method extends StubMethodKey<Api>>(stub: DurableObjectStubClient<Api>, method: Method, ...args: StubMethodArgs<Api, Method>) => Effect.Effect<Awaited<StubMethodSuccess<Api, Method>>,
|
|
684
|
+
readonly scopedCall: <Method extends StubMethodKey<Api>>(stub: DurableObjectStubClient<Api>, method: Method, ...args: StubMethodArgs<Api, Method>) => Effect.Effect<Awaited<StubMethodSuccess<Api, Method>>, DurableObjectRpcError, Scope.Scope | R>;
|
|
683
685
|
readonly rawUnsafe: () => Effect.Effect<DurableObjectNamespaceClient<Api>, never, R>;
|
|
684
686
|
};
|
|
685
687
|
declare const isDurableObjectNamespaceClient: <Api extends object>(value: NamespaceCandidate) => value is DurableObjectNamespaceClient<Api>;
|
|
@@ -842,6 +844,12 @@ interface DurableObjectOptions<RRuntime, REvent = never, EventLayerError = never
|
|
|
842
844
|
type DurableObjectClass<Rpc extends DurableObjectRpc<ROut>, ROut> = new (state: globalThis.DurableObjectState, env: WorkerEnv) => DurableObject<WorkerEnv> & DurableObjectRpcApi<Rpc, ROut> & {
|
|
843
845
|
[RunSymbol]<A, E>(effect: Effect.Effect<A, E, HandlerContext<ROut>>, options?: RunOptions): Promise<A>;
|
|
844
846
|
};
|
|
847
|
+
/**
|
|
848
|
+
* Builds a Durable Object whose base `layer` lives for the in-memory instance.
|
|
849
|
+
* Cloudflare does not expose an eviction or shutdown hook, so finalizers in
|
|
850
|
+
* that layer are not guaranteed to run. Put resources that require timely
|
|
851
|
+
* release in `eventLayer`, whose scope closes after each handled event.
|
|
852
|
+
*/
|
|
845
853
|
declare const make$6: <ROut, LayerError, REvent = never, EventLayerError = never, const Rpc extends DurableObjectRpc<ROut | REvent> = Record<never, never>>(layer: Layer.Layer<ROut, LayerError, DurableObjectState | WorkerEnvironment>, options?: DurableObjectOptions<ROut, REvent, EventLayerError, Rpc>) => DurableObjectClass<Rpc, ROut | REvent>;
|
|
846
854
|
declare namespace DurableObjectAlarm_d_exports {
|
|
847
855
|
export { AlarmDefinitionConfig, AlarmDefinitionEntry, AlarmDefinitionPayload, AlarmDefinitions, AlarmFailurePolicy, AlarmPayload, AlarmPayloadSchema, AlarmRef, AlarmRetryPolicy, AlarmScheduler, DefinedAlarmEvent, DefinedAlarmHandlers, DurableObjectAlarm, DurableObjectAlarmError, DurableObjectAlarmEvent, InvalidAlarmPayloadError, InvalidAlarmRefError, InvalidProcessDueAlarmsOptionsError, InvalidRepeatEveryError, ProcessDueAlarmsFailure, ProcessDueAlarmsFailureAction, ProcessDueAlarmsHandler, ProcessDueAlarmsMode, ProcessDueAlarmsOptions, ProcessDueAlarmsResult, ScheduleAlarmInput, StoredAlarmDecodeError, define, processDue };
|