effect-cf 0.20.1 → 0.23.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 +52 -0
- package/README.md +27 -3
- package/dist/{Hyperdrive-RTjgirMV.d.mts → Hyperdrive-COyg7R26.d.mts} +40 -13
- package/dist/HyperdrivePg.d.mts +13 -5
- package/dist/HyperdrivePg.mjs +12 -7
- package/dist/index.d.mts +1113 -922
- package/dist/index.mjs +980 -604
- package/package.json +10 -5
- package/src/AiGateway.ts +82 -47
- package/src/AnalyticsEngine.ts +74 -58
- package/src/Binding.ts +66 -13
- package/src/BrowserRendering.ts +30 -7
- package/src/Cache.ts +32 -8
- package/src/CloudflareOtlp.ts +32 -9
- package/src/ContainerNamespace.ts +251 -80
- package/src/D1.ts +13 -3
- package/src/DurableObject.ts +27 -164
- package/src/DurableObjectAlarm.ts +30 -9
- package/src/DurableObjectDefinition.ts +58 -54
- package/src/DurableObjectNamespace.ts +99 -96
- package/src/DurableObjectRpcWebSocket.ts +14 -6
- package/src/DurableObjectSqlite.ts +6 -3
- package/src/DurableObjectState.ts +63 -39
- package/src/DurableObjectStorage.ts +7 -1
- package/src/DurableObjectWebSocket.ts +51 -41
- package/src/Email.ts +40 -13
- package/src/Environment.ts +26 -6
- package/src/Hyperdrive.ts +2 -2
- package/src/HyperdrivePg.ts +25 -13
- package/src/Images.ts +77 -82
- package/src/Kv.ts +37 -27
- package/src/Queue.ts +6 -1
- package/src/QueueBinding.ts +18 -21
- package/src/QueueDefinition.ts +15 -14
- package/src/R2.ts +107 -29
- package/src/Rpc.ts +3 -1
- package/src/RpcDefinition.ts +177 -133
- package/src/ServiceBinding.ts +112 -108
- package/src/Vectorize.ts +59 -14
- package/src/Worker.ts +172 -192
- package/src/WorkerDefinition.ts +5 -10
- package/src/WorkersAi.ts +27 -17
- package/src/Workflow.ts +54 -49
- package/src/WorkflowBinding.ts +19 -11
- package/src/WorkflowDefinition.ts +24 -27
- package/src/index.ts +4 -3
- package/src/internal/Entrypoint.ts +3 -1
- package/src/internal/ErrorMessage.ts +24 -0
- package/src/internal/RpcInvocation.ts +11 -8
- package/src/internal/Runtime.ts +52 -0
- package/src/internal/WorkerContext.ts +39 -17
- package/src/Entry.ts +0 -259
- package/src/internal/Clock.ts +0 -37
package/src/DurableObject.ts
CHANGED
|
@@ -1,24 +1,12 @@
|
|
|
1
1
|
import { DurableObject as CloudflareDurableObject } from "cloudflare:workers";
|
|
2
|
-
import {
|
|
3
|
-
ConfigProvider,
|
|
4
|
-
Effect,
|
|
5
|
-
Layer,
|
|
6
|
-
ManagedRuntime,
|
|
7
|
-
type Context,
|
|
8
|
-
type Scope,
|
|
9
|
-
type Schema as S,
|
|
10
|
-
} from "effect";
|
|
2
|
+
import { Effect, Layer, type ManagedRuntime, type Scope } from "effect";
|
|
11
3
|
|
|
12
4
|
import { NativeRequest } from "./Worker";
|
|
13
|
-
import {
|
|
5
|
+
import { WorkerEnvironment, type WorkerEnv } from "./Environment";
|
|
14
6
|
import { DurableObjectState, fromDurableObjectState } from "./DurableObjectState";
|
|
15
7
|
import { fromWebSocket, type DurableWebSocket } from "./DurableObjectWebSocket";
|
|
16
|
-
import type * as Binding from "./Binding";
|
|
17
|
-
import * as DurableObjectDefinition from "./DurableObjectDefinition";
|
|
18
|
-
import type * as DurableObjectNamespace from "./DurableObjectNamespace";
|
|
19
|
-
import type * as Rpc from "./Rpc";
|
|
20
|
-
import * as CloudflareClock from "./internal/Clock";
|
|
21
8
|
import * as Entrypoint from "./internal/Entrypoint";
|
|
9
|
+
import * as Runtime from "./internal/Runtime";
|
|
22
10
|
|
|
23
11
|
const reservedMethodNames = new Set<string>([
|
|
24
12
|
"constructor",
|
|
@@ -168,17 +156,12 @@ export const make = <
|
|
|
168
156
|
constructor(state: globalThis.DurableObjectState, env: WorkerEnv) {
|
|
169
157
|
super(state, env);
|
|
170
158
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
159
|
+
this.runtime = Runtime.makeEntrypointRuntime<ROut, LayerError, DurableObjectState>(
|
|
160
|
+
layer,
|
|
161
|
+
env,
|
|
174
162
|
Layer.succeed(DurableObjectState, fromDurableObjectState(state)),
|
|
175
|
-
Layer.succeed(WorkerEnvironment, env),
|
|
176
163
|
);
|
|
177
164
|
|
|
178
|
-
const runtimeLayer = Entrypoint.provideEntrypointServices(layer, services);
|
|
179
|
-
|
|
180
|
-
this.runtime = ManagedRuntime.make(runtimeLayer);
|
|
181
|
-
|
|
182
165
|
const initialize = options.initialize;
|
|
183
166
|
|
|
184
167
|
if (initialize !== undefined) {
|
|
@@ -190,15 +173,10 @@ export const make = <
|
|
|
190
173
|
effect: Effect.Effect<A, E, HandlerContext<ROut | REvent>>,
|
|
191
174
|
runOptions: RunOptions = {},
|
|
192
175
|
): Promise<A> {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
return this.runtime.runPromise(
|
|
199
|
-
Effect.scoped(
|
|
200
|
-
effectWithEventLayer as Effect.Effect<A, E | EventLayerError, HandlerContext<ROut>>,
|
|
201
|
-
),
|
|
176
|
+
return Runtime.runEventPromise(
|
|
177
|
+
this.runtime,
|
|
178
|
+
effect,
|
|
179
|
+
runOptions.eventLayer === false ? undefined : options.eventLayer,
|
|
202
180
|
);
|
|
203
181
|
}
|
|
204
182
|
|
|
@@ -273,135 +251,20 @@ export const make = <
|
|
|
273
251
|
);
|
|
274
252
|
};
|
|
275
253
|
|
|
276
|
-
export type
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
...infer Tail extends ReadonlyArray<ServiceFreeSchema>,
|
|
294
|
-
]
|
|
295
|
-
? [S.Schema.Type<Head>, ...ArgsFromSchemas<Tail>]
|
|
296
|
-
: Array<S.Schema.Type<Args[number]>>;
|
|
297
|
-
|
|
298
|
-
export type Args<Self extends Any> = ArgsFromSchemas<Self["args"]>;
|
|
299
|
-
|
|
300
|
-
export type Success<Self extends Any> = S.Schema.Type<Self["success"]>;
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
export type Methods = Record<string, Method.Any>;
|
|
304
|
-
|
|
305
|
-
export type ReservedMethodName = DurableObjectDefinition.ReservedMethodName;
|
|
306
|
-
|
|
307
|
-
export type NoReservedMethods<MethodsShape extends Methods> =
|
|
308
|
-
Extract<keyof MethodsShape, ReservedMethodName> extends never ? MethodsShape : never;
|
|
309
|
-
|
|
310
|
-
export interface Definition<Id extends string = string, MethodsShape extends Methods = Methods> {
|
|
311
|
-
readonly id: Id;
|
|
312
|
-
readonly methods: MethodsShape;
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
export namespace Definition {
|
|
316
|
-
export type Any = Definition<string, Methods>;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
export type LayerOptions = DurableObjectDefinition.LayerOptions;
|
|
320
|
-
|
|
321
|
-
export type ServerApi<Self extends Definition.Any> = {
|
|
322
|
-
readonly [Key in keyof Self["methods"]]: (
|
|
323
|
-
...args: Method.Args<Self["methods"][Key]>
|
|
324
|
-
) => Promise<Method.Success<Self["methods"][Key]>>;
|
|
325
|
-
};
|
|
326
|
-
|
|
327
|
-
export type Api<Self extends Definition.Any> = Rpc.Provider<ServerApi<Self>, ReservedMethodName>;
|
|
328
|
-
|
|
329
|
-
export type Handlers<ROut, Self extends Definition.Any> = {
|
|
330
|
-
readonly [Key in keyof Self["methods"]]: (
|
|
331
|
-
...args: Method.Args<Self["methods"][Key]>
|
|
332
|
-
) => DurableObjectHandler<ROut, Method.Success<Self["methods"][Key]>>;
|
|
333
|
-
};
|
|
334
|
-
|
|
335
|
-
export interface Options<
|
|
336
|
-
ROut,
|
|
337
|
-
Self extends Definition.Any,
|
|
338
|
-
REvent = never,
|
|
339
|
-
EventLayerError = never,
|
|
340
|
-
> extends Omit<
|
|
341
|
-
DurableObjectOptions<ROut, REvent, EventLayerError, Handlers<ROut | REvent, Self>>,
|
|
342
|
-
"rpc"
|
|
343
|
-
> {
|
|
344
|
-
readonly rpc: Handlers<ROut | REvent, Self>;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
export type TagClass<Self, Id extends string, MethodsShape extends Methods> = Context.ServiceClass<
|
|
348
|
-
Self,
|
|
349
|
-
Id,
|
|
350
|
-
DurableObjectNamespace.DurableObjectNamespaceEffectClient<
|
|
351
|
-
Api<Definition<Id, MethodsShape>>,
|
|
352
|
-
Definition<Id, MethodsShape>
|
|
353
|
-
>
|
|
354
|
-
> &
|
|
355
|
-
DurableObjectNamespace.DurableObjectNamespaceStaticClient<
|
|
356
|
-
Self,
|
|
357
|
-
Api<Definition<Id, MethodsShape>>,
|
|
358
|
-
Definition<Id, MethodsShape>
|
|
359
|
-
> & {
|
|
360
|
-
readonly id: Id;
|
|
361
|
-
readonly methods: MethodsShape;
|
|
362
|
-
readonly make: <ROut, LayerError, REvent = never, EventLayerError = never>(
|
|
363
|
-
layer: Layer.Layer<ROut, LayerError, DurableObjectState | WorkerEnvironment>,
|
|
364
|
-
options: Options<ROut, Definition<Id, MethodsShape>, REvent, EventLayerError>,
|
|
365
|
-
) => DurableObjectClass<Handlers<ROut | REvent, Definition<Id, MethodsShape>>, ROut | REvent>;
|
|
366
|
-
readonly layer: (
|
|
367
|
-
options: LayerOptions,
|
|
368
|
-
) => Layer.Layer<
|
|
369
|
-
Self,
|
|
370
|
-
Binding.BindingNotFoundError | Binding.BindingValidationError,
|
|
371
|
-
WorkerEnvironment
|
|
372
|
-
>;
|
|
373
|
-
};
|
|
374
|
-
|
|
375
|
-
export type TagFactory = <Self>() => <Id extends string, const MethodsShape extends Methods>(
|
|
376
|
-
id: Id,
|
|
377
|
-
methods: MethodsShape & NoReservedMethods<MethodsShape>,
|
|
378
|
-
) => TagClass<Self, Id, MethodsShape>;
|
|
379
|
-
|
|
380
|
-
export const Tag = DurableObjectDefinition.Tag as unknown as TagFactory;
|
|
381
|
-
|
|
382
|
-
export const method = DurableObjectDefinition.method as {
|
|
383
|
-
<Success extends ServiceFreeSchema>(definition: {
|
|
384
|
-
readonly success: Success;
|
|
385
|
-
}): Method<readonly [], Success>;
|
|
386
|
-
<
|
|
387
|
-
const Args extends ReadonlyArray<ServiceFreeSchema>,
|
|
388
|
-
Success extends ServiceFreeSchema,
|
|
389
|
-
>(definition: {
|
|
390
|
-
readonly args: Args;
|
|
391
|
-
readonly success: Success;
|
|
392
|
-
}): Method<Args, Success>;
|
|
393
|
-
};
|
|
394
|
-
|
|
395
|
-
export const implement = DurableObjectDefinition.implement as unknown as <
|
|
396
|
-
ROut,
|
|
397
|
-
const Self extends Definition.Any,
|
|
398
|
-
>(
|
|
399
|
-
_definition: Self,
|
|
400
|
-
handlers: Handlers<ROut, Self>,
|
|
401
|
-
) => Handlers<ROut, Self>;
|
|
402
|
-
|
|
403
|
-
export type HandlerEffect<
|
|
404
|
-
ROut,
|
|
405
|
-
Self extends Definition.Any,
|
|
406
|
-
Key extends keyof Self["methods"],
|
|
407
|
-
> = DurableObjectHandler<ROut, Method.Success<Self["methods"][Key]>>;
|
|
254
|
+
export type {
|
|
255
|
+
Api,
|
|
256
|
+
Definition,
|
|
257
|
+
HandlerEffect,
|
|
258
|
+
Handlers,
|
|
259
|
+
LayerOptions,
|
|
260
|
+
Method,
|
|
261
|
+
Methods,
|
|
262
|
+
NoReservedMethods,
|
|
263
|
+
Options,
|
|
264
|
+
ReservedMethodName,
|
|
265
|
+
ServerApi,
|
|
266
|
+
ServiceFreeSchema,
|
|
267
|
+
TagClass,
|
|
268
|
+
} from "./DurableObjectDefinition";
|
|
269
|
+
|
|
270
|
+
export { implement, method, Tag } from "./DurableObjectDefinition";
|
|
@@ -2,6 +2,7 @@ import { Clock, Context, Data, DateTime, Duration, Effect, Exit, Layer, Schema a
|
|
|
2
2
|
|
|
3
3
|
import { DurableObjectState } from "./DurableObjectState";
|
|
4
4
|
import type { SqlStorageValue, StorageOperationError } from "./DurableObjectStorage";
|
|
5
|
+
import * as ErrorMessage from "./internal/ErrorMessage";
|
|
5
6
|
|
|
6
7
|
const INIT_TABLE_SQL = `
|
|
7
8
|
CREATE TABLE IF NOT EXISTS effect_cf_scheduled_alarms (
|
|
@@ -46,26 +47,46 @@ interface NextAlarmRow extends Record<string, SqlStorageValue> {
|
|
|
46
47
|
|
|
47
48
|
export class InvalidAlarmRefError extends Data.TaggedError("InvalidAlarmRefError")<{
|
|
48
49
|
readonly cause: unknown;
|
|
49
|
-
}> {
|
|
50
|
+
}> {
|
|
51
|
+
override get message(): string {
|
|
52
|
+
return `Invalid Durable Object alarm ref: ${ErrorMessage.causeMessage(this.cause)}`;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
50
55
|
|
|
51
56
|
export class InvalidAlarmPayloadError extends Data.TaggedError("InvalidAlarmPayloadError")<{
|
|
52
57
|
readonly cause: unknown;
|
|
53
|
-
}> {
|
|
58
|
+
}> {
|
|
59
|
+
override get message(): string {
|
|
60
|
+
return `Invalid Durable Object alarm payload: ${ErrorMessage.causeMessage(this.cause)}`;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
54
63
|
|
|
55
64
|
export class InvalidRepeatEveryError extends Data.TaggedError("InvalidRepeatEveryError")<{
|
|
56
65
|
readonly cause: unknown;
|
|
57
|
-
}> {
|
|
66
|
+
}> {
|
|
67
|
+
override get message(): string {
|
|
68
|
+
return `Invalid Durable Object alarm repeatEvery: ${ErrorMessage.causeMessage(this.cause)}`;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
58
71
|
|
|
59
72
|
export class InvalidProcessDueAlarmsOptionsError extends Data.TaggedError(
|
|
60
73
|
"InvalidProcessDueAlarmsOptionsError",
|
|
61
74
|
)<{
|
|
62
75
|
readonly cause: unknown;
|
|
63
|
-
}> {
|
|
76
|
+
}> {
|
|
77
|
+
override get message(): string {
|
|
78
|
+
return `Invalid processDueAlarms options: ${ErrorMessage.causeMessage(this.cause)}`;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
64
81
|
|
|
65
82
|
export class StoredAlarmDecodeError extends Data.TaggedError("StoredAlarmDecodeError")<{
|
|
66
83
|
readonly cause: unknown;
|
|
67
84
|
readonly storageId: string;
|
|
68
|
-
}> {
|
|
85
|
+
}> {
|
|
86
|
+
override get message(): string {
|
|
87
|
+
return `Failed to decode stored alarm "${this.storageId}": ${ErrorMessage.causeMessage(this.cause)}`;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
69
90
|
|
|
70
91
|
export type DurableObjectAlarmError =
|
|
71
92
|
| InvalidAlarmPayloadError
|
|
@@ -355,7 +376,7 @@ const toRepeatEveryMillis = (input: Duration.Input | undefined) => {
|
|
|
355
376
|
|
|
356
377
|
return Effect.try({
|
|
357
378
|
try: () => {
|
|
358
|
-
const millis = Duration.toMillis(
|
|
379
|
+
const millis = Duration.toMillis(input);
|
|
359
380
|
|
|
360
381
|
if (!Number.isFinite(millis) || millis <= 0) {
|
|
361
382
|
throw new Error("Alarm repeatEvery must be a positive finite duration");
|
|
@@ -382,7 +403,7 @@ const toAlarmDue = (row: AlarmRow) =>
|
|
|
382
403
|
_tag: "AlarmDue",
|
|
383
404
|
id: row.alarm_id,
|
|
384
405
|
payload: yield* decodeStoredPayload(row),
|
|
385
|
-
scheduledAt: DateTime.
|
|
406
|
+
scheduledAt: DateTime.makeUnsafe(row.run_at),
|
|
386
407
|
tag: row.tag,
|
|
387
408
|
});
|
|
388
409
|
});
|
|
@@ -404,7 +425,7 @@ const getProcessLimit = (options: ProcessDueAlarmsOptions<unknown, unknown> | un
|
|
|
404
425
|
const toFailureRescheduleMillis = (input: Duration.Input) =>
|
|
405
426
|
Effect.try({
|
|
406
427
|
try: () => {
|
|
407
|
-
const millis = Duration.toMillis(
|
|
428
|
+
const millis = Duration.toMillis(input);
|
|
408
429
|
|
|
409
430
|
if (!Number.isFinite(millis) || millis <= 0) {
|
|
410
431
|
throw new Error("Alarm failure rescheduleAfter must be a positive finite duration");
|
|
@@ -594,7 +615,7 @@ export const define = <const Definitions extends AlarmDefinitions>(definitions:
|
|
|
594
615
|
export class DurableObjectAlarm extends Context.Service<DurableObjectAlarm, AlarmScheduler>()(
|
|
595
616
|
"effect-cf/DurableObjectAlarm",
|
|
596
617
|
) {
|
|
597
|
-
static readonly layer = Layer.effect(
|
|
618
|
+
static readonly layer: Layer.Layer<DurableObjectAlarm, never, DurableObjectState> = Layer.effect(
|
|
598
619
|
DurableObjectAlarm,
|
|
599
620
|
Effect.gen(function* () {
|
|
600
621
|
const state = yield* DurableObjectState;
|
|
@@ -38,15 +38,10 @@ export namespace Method {
|
|
|
38
38
|
? [S.Schema.Type<Head>, ...ArgsFromSchemas<Tail>]
|
|
39
39
|
: Array<S.Schema.Type<Args[number]>>;
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
infer Head extends ServiceFreeSchema,
|
|
46
|
-
...infer Tail extends ReadonlyArray<ServiceFreeSchema>,
|
|
47
|
-
]
|
|
48
|
-
? [S.Codec.Encoded<Head>, ...EncodedArgsFromSchemas<Tail>]
|
|
49
|
-
: Array<S.Codec.Encoded<Args[number]>>;
|
|
41
|
+
/** Method schemas cross the wire through their canonical JSON codec. */
|
|
42
|
+
type EncodedArgsFromSchemas<Args extends ReadonlyArray<ServiceFreeSchema>> = {
|
|
43
|
+
[Index in keyof Args]: S.Json;
|
|
44
|
+
};
|
|
50
45
|
|
|
51
46
|
export type Args<Self extends Any> = ArgsFromSchemas<Self["args"]>;
|
|
52
47
|
|
|
@@ -54,7 +49,7 @@ export namespace Method {
|
|
|
54
49
|
|
|
55
50
|
export type Success<Self extends Any> = S.Schema.Type<Self["success"]>;
|
|
56
51
|
|
|
57
|
-
export type EncodedSuccess<Self extends Any> = S.
|
|
52
|
+
export type EncodedSuccess<Self extends Any> = S.Json;
|
|
58
53
|
}
|
|
59
54
|
|
|
60
55
|
export type Methods = Record<string, Method.Any>;
|
|
@@ -144,7 +139,7 @@ export type LayerOptions = {
|
|
|
144
139
|
|
|
145
140
|
export type TagClass<Self, Id extends string, MethodsShape extends Methods> = Context.ServiceClass<
|
|
146
141
|
Self,
|
|
147
|
-
Id
|
|
142
|
+
`effect-cf/DurableObject/${Id}`,
|
|
148
143
|
DurableObjectNamespace.DurableObjectNamespaceEffectClient<
|
|
149
144
|
Api<Definition<Id, MethodsShape>>,
|
|
150
145
|
Definition<Id, MethodsShape>
|
|
@@ -241,23 +236,30 @@ export const Tag =
|
|
|
241
236
|
|
|
242
237
|
type SelfDefinition = Definition<Id, MethodsShape>;
|
|
243
238
|
type ClientApi = Api<SelfDefinition>;
|
|
239
|
+
const serviceKey: `effect-cf/DurableObject/${Id}` = `effect-cf/DurableObject/${id}`;
|
|
244
240
|
const tag = Context.Service<
|
|
245
241
|
Self,
|
|
246
242
|
DurableObjectNamespace.DurableObjectNamespaceEffectClient<ClientApi, SelfDefinition>
|
|
247
|
-
>()(
|
|
243
|
+
>()(serviceKey);
|
|
248
244
|
|
|
249
245
|
const bindingDefinition = (binding: LayerOptions) => ({
|
|
250
246
|
...binding,
|
|
251
247
|
definition,
|
|
252
248
|
});
|
|
253
249
|
|
|
254
|
-
const layer = (
|
|
250
|
+
const layer = (
|
|
251
|
+
binding: LayerOptions,
|
|
252
|
+
): Layer.Layer<
|
|
253
|
+
Self,
|
|
254
|
+
Binding.BindingNotFoundError | Binding.BindingValidationError,
|
|
255
|
+
WorkerEnvironment
|
|
256
|
+
> =>
|
|
255
257
|
DurableObjectNamespace.layer<Self, ClientApi, SelfDefinition>(
|
|
256
258
|
tag,
|
|
257
259
|
bindingDefinition(binding),
|
|
258
260
|
);
|
|
259
261
|
|
|
260
|
-
const newUniqueId = Effect.
|
|
262
|
+
const newUniqueId = Effect.fn("DurableObject.newUniqueId")(function* (
|
|
261
263
|
options?: globalThis.DurableObjectNamespaceNewUniqueIdOptions,
|
|
262
264
|
) {
|
|
263
265
|
const namespace = yield* tag;
|
|
@@ -265,19 +267,19 @@ export const Tag =
|
|
|
265
267
|
return yield* namespace.newUniqueId(options);
|
|
266
268
|
});
|
|
267
269
|
|
|
268
|
-
const idFromName = Effect.
|
|
270
|
+
const idFromName = Effect.fn("DurableObject.idFromName")(function* (name: string) {
|
|
269
271
|
const namespace = yield* tag;
|
|
270
272
|
|
|
271
273
|
return yield* namespace.idFromName(name);
|
|
272
274
|
});
|
|
273
275
|
|
|
274
|
-
const idFromString = Effect.
|
|
276
|
+
const idFromString = Effect.fn("DurableObject.idFromString")(function* (value: string) {
|
|
275
277
|
const namespace = yield* tag;
|
|
276
278
|
|
|
277
279
|
return yield* namespace.idFromString(value);
|
|
278
280
|
});
|
|
279
281
|
|
|
280
|
-
const get = Effect.
|
|
282
|
+
const get = Effect.fn("DurableObject.get")(function* (
|
|
281
283
|
objectId: globalThis.DurableObjectId,
|
|
282
284
|
options?: globalThis.DurableObjectNamespaceGetDurableObjectOptions,
|
|
283
285
|
) {
|
|
@@ -286,7 +288,7 @@ export const Tag =
|
|
|
286
288
|
return yield* namespace.get(objectId, options);
|
|
287
289
|
});
|
|
288
290
|
|
|
289
|
-
const getByName = Effect.
|
|
291
|
+
const getByName = Effect.fn("DurableObject.getByName")(function* (
|
|
290
292
|
name: string,
|
|
291
293
|
options?: globalThis.DurableObjectNamespaceGetDurableObjectOptions,
|
|
292
294
|
) {
|
|
@@ -295,68 +297,70 @@ export const Tag =
|
|
|
295
297
|
return yield* namespace.getByName(name, options);
|
|
296
298
|
});
|
|
297
299
|
|
|
298
|
-
const jurisdiction = Effect.
|
|
300
|
+
const jurisdiction = Effect.fn("DurableObject.jurisdiction")(function* (
|
|
301
|
+
value: globalThis.DurableObjectJurisdiction,
|
|
302
|
+
) {
|
|
299
303
|
const namespace = yield* tag;
|
|
300
304
|
|
|
301
305
|
return yield* namespace.jurisdiction(value);
|
|
302
306
|
});
|
|
303
307
|
|
|
304
|
-
const fetch = (
|
|
308
|
+
const fetch = Effect.fn("DurableObject.fetch")(function* (
|
|
305
309
|
stub: DurableObjectNamespace.DurableObjectStubClient<ClientApi>,
|
|
306
310
|
input: RequestInfo | URL,
|
|
307
311
|
init?: RequestInit,
|
|
308
|
-
)
|
|
309
|
-
|
|
310
|
-
const namespace = yield* tag;
|
|
312
|
+
) {
|
|
313
|
+
const namespace = yield* tag;
|
|
311
314
|
|
|
312
|
-
|
|
313
|
-
|
|
315
|
+
return yield* namespace.fetch(stub, input, init);
|
|
316
|
+
});
|
|
314
317
|
|
|
315
|
-
const rpc = <Method extends keyof ClientApi>(
|
|
318
|
+
const rpc = Effect.fn("DurableObject.rpc")(function* <Method extends keyof ClientApi>(
|
|
316
319
|
stub: DurableObjectNamespace.DurableObjectStubClient<ClientApi>,
|
|
317
320
|
method: Method,
|
|
318
321
|
...args: ClientApi[Method] extends (...args: infer Args) => unknown ? Args : never
|
|
319
|
-
)
|
|
320
|
-
|
|
321
|
-
const namespace = yield* tag;
|
|
322
|
+
) {
|
|
323
|
+
const namespace = yield* tag;
|
|
322
324
|
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
325
|
+
return yield* (namespace.rpc as UnsafeInvoke<DurableObjectNamespace.DurableObjectRpcError>)(
|
|
326
|
+
stub,
|
|
327
|
+
method,
|
|
328
|
+
...args,
|
|
329
|
+
);
|
|
330
|
+
});
|
|
329
331
|
|
|
330
|
-
const call = <Method extends keyof ClientApi>(
|
|
332
|
+
const call = Effect.fn("DurableObject.call")(function* <Method extends keyof ClientApi>(
|
|
331
333
|
stub: DurableObjectNamespace.DurableObjectStubClient<ClientApi>,
|
|
332
334
|
method: Method,
|
|
333
335
|
...args: ClientApi[Method] extends (...args: infer Args) => unknown ? Args : never
|
|
334
|
-
)
|
|
335
|
-
|
|
336
|
-
const namespace = yield* tag;
|
|
336
|
+
) {
|
|
337
|
+
const namespace = yield* tag;
|
|
337
338
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
339
|
+
return yield* (namespace.call as UnsafeInvoke<DurableObjectNamespace.DurableObjectRpcError>)(
|
|
340
|
+
stub,
|
|
341
|
+
method,
|
|
342
|
+
...args,
|
|
343
|
+
);
|
|
344
|
+
});
|
|
342
345
|
|
|
343
|
-
const scopedCall = <
|
|
346
|
+
const scopedCall = Effect.fn("DurableObject.scopedCall")(function* <
|
|
347
|
+
Method extends keyof ClientApi,
|
|
348
|
+
>(
|
|
344
349
|
stub: DurableObjectNamespace.DurableObjectStubClient<ClientApi>,
|
|
345
350
|
method: Method,
|
|
346
351
|
...args: ClientApi[Method] extends (...args: infer Args) => unknown ? Args : never
|
|
347
|
-
)
|
|
348
|
-
|
|
349
|
-
const namespace = yield* tag;
|
|
352
|
+
) {
|
|
353
|
+
const namespace = yield* tag;
|
|
350
354
|
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
+
return yield* (
|
|
356
|
+
namespace.scopedCall as UnsafeInvoke<DurableObjectNamespace.DurableObjectRpcError>
|
|
357
|
+
)(stub, method, ...args);
|
|
358
|
+
});
|
|
355
359
|
|
|
356
|
-
const
|
|
360
|
+
const rawUnsafe = Effect.fnUntraced(function* () {
|
|
357
361
|
const namespace = yield* tag;
|
|
358
362
|
|
|
359
|
-
return yield* namespace.
|
|
363
|
+
return yield* namespace.rawUnsafe;
|
|
360
364
|
});
|
|
361
365
|
|
|
362
366
|
const directMethods = DurableObjectNamespace.makeDirectMethods<Self, ClientApi, SelfDefinition>(
|
|
@@ -384,7 +388,7 @@ export const Tag =
|
|
|
384
388
|
rpc,
|
|
385
389
|
call,
|
|
386
390
|
scopedCall,
|
|
387
|
-
|
|
391
|
+
rawUnsafe,
|
|
388
392
|
}) as unknown as TagClass<Self, Id, MethodsShape>;
|
|
389
393
|
};
|
|
390
394
|
|