effect-cf 0.6.0 → 0.7.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 +8 -0
- package/README.md +30 -29
- package/dist/index.d.mts +837 -1027
- package/dist/index.mjs +328 -407
- package/package.json +1 -1
- package/src/Binding.ts +17 -10
- package/src/DurableObject.ts +117 -23
- package/src/DurableObjectDefinition.ts +251 -72
- package/src/DurableObjectNamespace.ts +239 -287
- package/src/Kv.ts +173 -199
- package/src/Queue.ts +18 -4
- package/src/QueueBinding.ts +45 -97
- package/src/QueueDefinition.ts +87 -41
- package/src/ServiceBinding.ts +260 -116
- package/src/Worker.ts +114 -20
- package/src/WorkerDefinition.ts +187 -63
- package/src/Workflow.ts +23 -4
- package/src/WorkflowBinding.ts +100 -109
- package/src/WorkflowDefinition.ts +116 -51
package/dist/index.mjs
CHANGED
|
@@ -29,11 +29,12 @@ let WorkerConfig;
|
|
|
29
29
|
var Binding_exports = /* @__PURE__ */ __exportAll({
|
|
30
30
|
BindingNotFoundError: () => BindingNotFoundError,
|
|
31
31
|
BindingValidationError: () => BindingValidationError,
|
|
32
|
-
Service: () => Service$
|
|
33
|
-
TypeId: () => TypeId$
|
|
32
|
+
Service: () => Service$2,
|
|
33
|
+
TypeId: () => TypeId$2,
|
|
34
|
+
layer: () => layer$6
|
|
34
35
|
});
|
|
35
36
|
/** Internal type id marker used by binding helper services. */
|
|
36
|
-
const TypeId$
|
|
37
|
+
const TypeId$2 = "effect-cf/Binding";
|
|
37
38
|
/** Error raised when a configured binding does not exist on `env`. */
|
|
38
39
|
var BindingNotFoundError = class extends Data.TaggedError("BindingNotFoundError") {};
|
|
39
40
|
/** Error raised when a binding exists but does not match the expected shape. */
|
|
@@ -46,26 +47,27 @@ const getBinding = (env, binding, isResource) => Effect.gen(function* () {
|
|
|
46
47
|
if (!isResource(resource)) return yield* Effect.fail(new BindingValidationError({ binding }));
|
|
47
48
|
return resource;
|
|
48
49
|
});
|
|
49
|
-
const
|
|
50
|
+
const layer$6 = (tag, binding, isResource, wrap) => Layer.effect(tag, Effect.gen(function* () {
|
|
51
|
+
const resource = yield* getBinding(yield* WorkerEnvironment, binding, isResource);
|
|
52
|
+
return wrap === void 0 ? resource : wrap(resource);
|
|
53
|
+
}));
|
|
54
|
+
const Service$2 = () => (id, binding, isResource, wrap) => {
|
|
50
55
|
const tag = Context.Service()(id);
|
|
51
|
-
const
|
|
52
|
-
const resource = yield* getBinding(yield* WorkerEnvironment, binding, isResource);
|
|
53
|
-
return wrap === void 0 ? resource : wrap(resource);
|
|
54
|
-
}));
|
|
56
|
+
const serviceLayer = layer$6(tag, binding, isResource, wrap);
|
|
55
57
|
return Object.assign(tag, {
|
|
56
|
-
[TypeId$
|
|
58
|
+
[TypeId$2]: TypeId$2,
|
|
57
59
|
binding,
|
|
58
|
-
layer
|
|
60
|
+
layer: serviceLayer
|
|
59
61
|
});
|
|
60
62
|
};
|
|
61
63
|
//#endregion
|
|
62
64
|
//#region src/D1.ts
|
|
63
65
|
var D1_exports = /* @__PURE__ */ __exportAll({
|
|
64
66
|
D1OperationError: () => D1OperationError,
|
|
65
|
-
Service: () => Service$
|
|
66
|
-
make: () => make$
|
|
67
|
+
Service: () => Service$1,
|
|
68
|
+
make: () => make$8
|
|
67
69
|
});
|
|
68
|
-
const TypeId$
|
|
70
|
+
const TypeId$1 = "effect-cf/D1";
|
|
69
71
|
/** Error raised when a D1 operation fails. */
|
|
70
72
|
var D1OperationError = class extends Data.TaggedError("D1OperationError") {};
|
|
71
73
|
const isD1Database = (value) => {
|
|
@@ -89,7 +91,7 @@ const tryD1Sync = (binding, operation, evaluate) => Effect.try({
|
|
|
89
91
|
/**
|
|
90
92
|
* Creates a typed D1 service tag plus Effect helpers.
|
|
91
93
|
*/
|
|
92
|
-
const make$
|
|
94
|
+
const make$8 = (id, definition) => Service$1()(id, definition);
|
|
93
95
|
/**
|
|
94
96
|
* Builds a D1 service around a Cloudflare D1 database binding.
|
|
95
97
|
*
|
|
@@ -106,8 +108,8 @@ const make$11 = (id, definition) => Service$5()(id, definition);
|
|
|
106
108
|
* const SqlLive = TodoDatabase.sqlLayer();
|
|
107
109
|
* ```
|
|
108
110
|
*/
|
|
109
|
-
const Service$
|
|
110
|
-
const tag = Service$
|
|
111
|
+
const Service$1 = () => (id, definition) => {
|
|
112
|
+
const tag = Service$2()(id, definition.binding, isD1Database);
|
|
111
113
|
const sqlLayer = (options) => Layer.unwrap(Effect.gen(function* () {
|
|
112
114
|
const db = yield* tag;
|
|
113
115
|
return D1Client.layer({
|
|
@@ -131,7 +133,7 @@ const Service$5 = () => (id, definition) => {
|
|
|
131
133
|
return yield* tag;
|
|
132
134
|
});
|
|
133
135
|
return Object.assign(tag, {
|
|
134
|
-
[TypeId$
|
|
136
|
+
[TypeId$1]: TypeId$1,
|
|
135
137
|
definition,
|
|
136
138
|
sqlLayer,
|
|
137
139
|
prepare,
|
|
@@ -144,10 +146,10 @@ const Service$5 = () => (id, definition) => {
|
|
|
144
146
|
//#region src/QueueBinding.ts
|
|
145
147
|
var QueueBinding_exports = /* @__PURE__ */ __exportAll({
|
|
146
148
|
QueueOperationError: () => QueueOperationError,
|
|
147
|
-
|
|
148
|
-
|
|
149
|
+
isQueue: () => isQueue,
|
|
150
|
+
layer: () => layer$5,
|
|
151
|
+
makeClient: () => makeClient$4
|
|
149
152
|
});
|
|
150
|
-
const TypeId$4 = "effect-cf/QueueBinding";
|
|
151
153
|
var QueueOperationError = class extends Data.TaggedError("QueueOperationError") {};
|
|
152
154
|
const queueError = (binding, operation, cause) => new QueueOperationError({
|
|
153
155
|
binding,
|
|
@@ -163,14 +165,9 @@ const isQueue = (value) => {
|
|
|
163
165
|
const resource = value;
|
|
164
166
|
return typeof resource.send === "function" && typeof resource.sendBatch === "function" && typeof resource.metrics === "function";
|
|
165
167
|
};
|
|
166
|
-
|
|
167
|
-
const make$10 = (id, definition) => Service$4()(id, definition);
|
|
168
|
-
/**
|
|
169
|
-
* Builds an Effect service around a Cloudflare Queue producer binding.
|
|
170
|
-
*/
|
|
171
|
-
const Service$4 = () => (id, definition) => {
|
|
168
|
+
const makeClient$4 = (definition) => {
|
|
172
169
|
const encodeMessage = Schema.encodeEffect(definition.message);
|
|
173
|
-
|
|
170
|
+
return (queue) => ({
|
|
174
171
|
send: Effect.fnUntraced(function* (message, options) {
|
|
175
172
|
const encoded = yield* encodeMessage(message);
|
|
176
173
|
yield* tryQueuePromise(definition.binding, "send", () => queue.send(encoded, options));
|
|
@@ -186,7 +183,34 @@ const Service$4 = () => (id, definition) => {
|
|
|
186
183
|
metrics: () => tryQueuePromise(definition.binding, "metrics", () => queue.metrics()),
|
|
187
184
|
unsafeRaw: Effect.succeed(queue)
|
|
188
185
|
});
|
|
189
|
-
|
|
186
|
+
};
|
|
187
|
+
const layer$5 = (tag, definition) => layer$6(tag, definition.binding, (value) => isQueue(value), makeClient$4(definition));
|
|
188
|
+
//#endregion
|
|
189
|
+
//#region src/QueueDefinition.ts
|
|
190
|
+
var QueueDefinition_exports = /* @__PURE__ */ __exportAll({
|
|
191
|
+
Queue: () => Queue$1,
|
|
192
|
+
Tag: () => Tag$8,
|
|
193
|
+
implement: () => implement$7,
|
|
194
|
+
make: () => make$7
|
|
195
|
+
});
|
|
196
|
+
const makeDefinition$4 = (id, definition) => {
|
|
197
|
+
const queueDefinition = {
|
|
198
|
+
id,
|
|
199
|
+
message: definition.message
|
|
200
|
+
};
|
|
201
|
+
return Object.assign(queueDefinition, { make: (layer, options) => make$4(layer, {
|
|
202
|
+
...options,
|
|
203
|
+
queue: wrapHandler$1(queueDefinition, options.queue)
|
|
204
|
+
}) });
|
|
205
|
+
};
|
|
206
|
+
const make$7 = (id, definition) => Tag$8()(id, definition);
|
|
207
|
+
const Tag$8 = () => (id, definition) => {
|
|
208
|
+
const queueDefinition = makeDefinition$4(id, definition);
|
|
209
|
+
const tag = Context.Service()(id);
|
|
210
|
+
const layer = (binding) => layer$5(tag, {
|
|
211
|
+
...binding,
|
|
212
|
+
message: definition.message
|
|
213
|
+
});
|
|
190
214
|
const send = Effect.fnUntraced(function* (message, options) {
|
|
191
215
|
yield* (yield* tag).send(message, options);
|
|
192
216
|
});
|
|
@@ -200,54 +224,16 @@ const Service$4 = () => (id, definition) => {
|
|
|
200
224
|
return yield* (yield* tag).unsafeRaw;
|
|
201
225
|
});
|
|
202
226
|
return Object.assign(tag, {
|
|
203
|
-
|
|
204
|
-
|
|
227
|
+
id: queueDefinition.id,
|
|
228
|
+
message: queueDefinition.message,
|
|
229
|
+
make: queueDefinition.make,
|
|
230
|
+
layer,
|
|
205
231
|
send,
|
|
206
232
|
sendBatch,
|
|
207
233
|
metrics,
|
|
208
234
|
unsafeRaw
|
|
209
235
|
});
|
|
210
236
|
};
|
|
211
|
-
//#endregion
|
|
212
|
-
//#region src/QueueDefinition.ts
|
|
213
|
-
var QueueDefinition_exports = /* @__PURE__ */ __exportAll({
|
|
214
|
-
Queue: () => Queue$1,
|
|
215
|
-
Tag: () => Tag$8,
|
|
216
|
-
implement: () => implement$7,
|
|
217
|
-
make: () => make$9
|
|
218
|
-
});
|
|
219
|
-
const makeDefinition$4 = (id, definition) => {
|
|
220
|
-
const queueDefinition = {
|
|
221
|
-
id,
|
|
222
|
-
message: definition.message
|
|
223
|
-
};
|
|
224
|
-
return Object.assign(queueDefinition, {
|
|
225
|
-
make: (layer, options) => make$6(layer, {
|
|
226
|
-
...options,
|
|
227
|
-
queue: wrapHandler$1(queueDefinition, options.queue)
|
|
228
|
-
}),
|
|
229
|
-
Binding: () => (bindingId, binding) => Service$4()(bindingId, {
|
|
230
|
-
...binding,
|
|
231
|
-
message: definition.message
|
|
232
|
-
}),
|
|
233
|
-
binding: (bindingId, binding) => Service$4()(bindingId, {
|
|
234
|
-
...binding,
|
|
235
|
-
message: definition.message
|
|
236
|
-
})
|
|
237
|
-
});
|
|
238
|
-
};
|
|
239
|
-
const make$9 = makeDefinition$4;
|
|
240
|
-
const Tag$8 = () => (id, definition) => {
|
|
241
|
-
const queueDefinition = makeDefinition$4(id, definition);
|
|
242
|
-
class QueueDefinitionClass {
|
|
243
|
-
static id = queueDefinition.id;
|
|
244
|
-
static message = queueDefinition.message;
|
|
245
|
-
static make = queueDefinition.make;
|
|
246
|
-
static Binding = queueDefinition.Binding;
|
|
247
|
-
static binding = queueDefinition.binding;
|
|
248
|
-
}
|
|
249
|
-
return QueueDefinitionClass;
|
|
250
|
-
};
|
|
251
237
|
const Queue$1 = Tag$8;
|
|
252
238
|
const wrapHandler$1 = (definition, handler) => {
|
|
253
239
|
const decodeBody = Schema.decodeUnknownEffect(definition.message);
|
|
@@ -316,7 +302,7 @@ var RpcDefinition_exports = /* @__PURE__ */ __exportAll({
|
|
|
316
302
|
decodeSuccess: () => decodeSuccess,
|
|
317
303
|
encodeArgs: () => encodeArgs,
|
|
318
304
|
encodeSuccess: () => encodeSuccess,
|
|
319
|
-
make: () => make$
|
|
305
|
+
make: () => make$6,
|
|
320
306
|
method: () => method$4,
|
|
321
307
|
reservedMethodNames: () => reservedMethodNames$4
|
|
322
308
|
});
|
|
@@ -419,7 +405,7 @@ const decodeSuccess = (definition, methodName, value) => {
|
|
|
419
405
|
cause
|
|
420
406
|
})));
|
|
421
407
|
};
|
|
422
|
-
const make$
|
|
408
|
+
const make$6 = (id, methods) => {
|
|
423
409
|
const definition = {
|
|
424
410
|
id,
|
|
425
411
|
methods
|
|
@@ -473,11 +459,15 @@ const invokeRpcMethod = (target, method, args, makeError) => Effect.gen(function
|
|
|
473
459
|
//#endregion
|
|
474
460
|
//#region src/ServiceBinding.ts
|
|
475
461
|
var ServiceBinding_exports = /* @__PURE__ */ __exportAll({
|
|
476
|
-
Service: () => Service
|
|
462
|
+
Service: () => Service,
|
|
477
463
|
ServiceBindingFetchError: () => ServiceBindingFetchError,
|
|
478
|
-
ServiceBindingRpcError: () => ServiceBindingRpcError
|
|
464
|
+
ServiceBindingRpcError: () => ServiceBindingRpcError,
|
|
465
|
+
isServiceBindingClient: () => isServiceBindingClient,
|
|
466
|
+
layer: () => layer$4,
|
|
467
|
+
makeClient: () => makeClient$3,
|
|
468
|
+
makeDirectMethods: () => makeDirectMethods$1
|
|
479
469
|
});
|
|
480
|
-
const TypeId
|
|
470
|
+
const TypeId = "effect-cf/ServiceBinding";
|
|
481
471
|
/**
|
|
482
472
|
* Failure raised when calling `fetch` on a service binding.
|
|
483
473
|
*/
|
|
@@ -486,34 +476,9 @@ var ServiceBindingFetchError = class extends Data.TaggedError("ServiceBindingFet
|
|
|
486
476
|
* Failure raised when invoking an RPC method on a service binding.
|
|
487
477
|
*/
|
|
488
478
|
var ServiceBindingRpcError = class extends Data.TaggedError("ServiceBindingRpcError") {};
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
* Returned value includes:
|
|
493
|
-
* - a Context tag for dependency injection
|
|
494
|
-
* - `fetch(...)` for raw HTTP forwarding
|
|
495
|
-
* - `call(...)` for generic RPC invocation
|
|
496
|
-
* - direct RPC methods when `definition` is provided
|
|
497
|
-
*
|
|
498
|
-
* @example
|
|
499
|
-
* ```ts
|
|
500
|
-
* const Counter = WorkerDefinition.make("Counter", {
|
|
501
|
-
* increment: WorkerDefinition.method({
|
|
502
|
-
* args: [Schema.Number],
|
|
503
|
-
* success: Schema.Number,
|
|
504
|
-
* }),
|
|
505
|
-
* });
|
|
506
|
-
*
|
|
507
|
-
* const CounterService = Counter.binding("COUNTER", { binding: "COUNTER" });
|
|
508
|
-
*
|
|
509
|
-
* const program = Effect.gen(function* () {
|
|
510
|
-
* const next = yield* CounterService.increment(1);
|
|
511
|
-
* return next;
|
|
512
|
-
* });
|
|
513
|
-
* ```
|
|
514
|
-
*/
|
|
515
|
-
const Service$3 = () => (id, definition) => {
|
|
516
|
-
const makeClient = (service) => {
|
|
479
|
+
const isServiceBindingClient = (value) => typeof value === "object" && value !== null && typeof Reflect.get(value, "fetch") === "function";
|
|
480
|
+
const makeClient$3 = (definition) => {
|
|
481
|
+
return (service) => {
|
|
517
482
|
const fetch = (input, init) => Effect.tryPromise({
|
|
518
483
|
try: () => service.fetch(input, init),
|
|
519
484
|
catch: (cause) => new ServiceBindingFetchError({
|
|
@@ -533,22 +498,24 @@ const Service$3 = () => (id, definition) => {
|
|
|
533
498
|
cause
|
|
534
499
|
}));
|
|
535
500
|
});
|
|
536
|
-
const
|
|
537
|
-
|
|
538
|
-
|
|
501
|
+
const decodeSuccess$2 = (methodName, value) => Effect.gen(function* () {
|
|
502
|
+
if (definition.definition === void 0) return value;
|
|
503
|
+
return yield* decodeSuccess(definition.definition, methodName, value).pipe(Effect.mapError((cause) => new ServiceBindingRpcError({
|
|
539
504
|
binding: definition.binding,
|
|
540
505
|
method: methodName,
|
|
541
506
|
cause
|
|
542
507
|
})));
|
|
543
|
-
|
|
544
|
-
|
|
508
|
+
});
|
|
509
|
+
const call = (method, ...args) => Effect.gen(function* () {
|
|
510
|
+
const methodName = String(method);
|
|
511
|
+
return yield* decodeSuccess$2(methodName, yield* resolve(yield* rpc(method, ...args)).pipe(Effect.mapError((cause) => new ServiceBindingRpcError({
|
|
545
512
|
binding: definition.binding,
|
|
546
513
|
method: methodName,
|
|
547
514
|
cause
|
|
548
|
-
})));
|
|
515
|
+
}))));
|
|
549
516
|
});
|
|
550
517
|
const scopedCall = (method, ...args) => Effect.gen(function* () {
|
|
551
|
-
return yield* scoped(yield* rpc(method, ...args));
|
|
518
|
+
return yield* decodeSuccess$2(String(method), yield* scoped(yield* rpc(method, ...args)));
|
|
552
519
|
});
|
|
553
520
|
const directMethods = makeDirectMethods$1(definition.definition, call);
|
|
554
521
|
return Object.assign(directMethods, {
|
|
@@ -558,7 +525,39 @@ const Service$3 = () => (id, definition) => {
|
|
|
558
525
|
scopedCall
|
|
559
526
|
});
|
|
560
527
|
};
|
|
561
|
-
|
|
528
|
+
};
|
|
529
|
+
const layer$4 = (tag, definition) => layer$6(tag, definition.binding, (value) => isServiceBindingClient(value), makeClient$3(definition));
|
|
530
|
+
/**
|
|
531
|
+
* Creates a typed Effect service for a Worker service binding.
|
|
532
|
+
*
|
|
533
|
+
* Returned value includes:
|
|
534
|
+
* - a Context tag for dependency injection
|
|
535
|
+
* - `fetch(...)` for raw HTTP forwarding
|
|
536
|
+
* - `rpc(...)` for raw Cloudflare RPC results
|
|
537
|
+
* - `call(...)` for resolved and decoded RPC results
|
|
538
|
+
* - `scopedCall(...)` for scoped and decoded disposable RPC results
|
|
539
|
+
* - direct RPC methods when `definition` is provided
|
|
540
|
+
*
|
|
541
|
+
* @example
|
|
542
|
+
* ```ts
|
|
543
|
+
* const Counter = WorkerDefinition.make("Counter", {
|
|
544
|
+
* increment: WorkerDefinition.method({
|
|
545
|
+
* args: [Schema.Number],
|
|
546
|
+
* success: Schema.Number,
|
|
547
|
+
* }),
|
|
548
|
+
* });
|
|
549
|
+
*
|
|
550
|
+
* const CounterLive = Counter.layer({ binding: "COUNTER" });
|
|
551
|
+
*
|
|
552
|
+
* const program = Effect.gen(function* () {
|
|
553
|
+
* const counter = yield* Counter;
|
|
554
|
+
* const next = yield* counter.increment(1);
|
|
555
|
+
* return next;
|
|
556
|
+
* });
|
|
557
|
+
* ```
|
|
558
|
+
*/
|
|
559
|
+
const Service = () => (id, definition) => {
|
|
560
|
+
const tag = Service$2()(id, definition.binding, (value) => isServiceBindingClient(value), makeClient$3(definition));
|
|
562
561
|
const fetch = (input, init) => Effect.gen(function* () {
|
|
563
562
|
return yield* (yield* tag).fetch(input, init);
|
|
564
563
|
});
|
|
@@ -573,7 +572,7 @@ const Service$3 = () => (id, definition) => {
|
|
|
573
572
|
});
|
|
574
573
|
const directMethods = makeDirectMethods$1(definition.definition, call);
|
|
575
574
|
return Object.assign(tag, directMethods, {
|
|
576
|
-
[TypeId
|
|
575
|
+
[TypeId]: TypeId,
|
|
577
576
|
definition,
|
|
578
577
|
fetch,
|
|
579
578
|
rpc,
|
|
@@ -592,7 +591,7 @@ var WorkerDefinition_exports = /* @__PURE__ */ __exportAll({
|
|
|
592
591
|
Tag: () => Tag$6,
|
|
593
592
|
Worker: () => Worker,
|
|
594
593
|
implement: () => implement$5,
|
|
595
|
-
make: () => make$
|
|
594
|
+
make: () => make$5,
|
|
596
595
|
method: () => method$3
|
|
597
596
|
});
|
|
598
597
|
const reservedMethodNames$3 = new Set([
|
|
@@ -630,33 +629,44 @@ const method$3 = method$4;
|
|
|
630
629
|
*/
|
|
631
630
|
const makeDefinition$3 = (id, methods) => {
|
|
632
631
|
assertNoReservedMethods("Worker", methods, reservedMethodNames$3);
|
|
633
|
-
const definition = make$
|
|
634
|
-
return Object.assign(definition, {
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
}),
|
|
639
|
-
Binding: () => (bindingId, binding) => Service$3()(bindingId, {
|
|
640
|
-
...binding,
|
|
641
|
-
definition
|
|
642
|
-
}),
|
|
643
|
-
binding: (bindingId, binding) => Service$3()(bindingId, {
|
|
644
|
-
...binding,
|
|
645
|
-
definition
|
|
646
|
-
})
|
|
647
|
-
});
|
|
632
|
+
const definition = make$6(id, methods);
|
|
633
|
+
return Object.assign(definition, { make: (layer, options) => make$4(layer, {
|
|
634
|
+
...options,
|
|
635
|
+
rpc: wrapHandlers$1(definition, options.rpc)
|
|
636
|
+
}) });
|
|
648
637
|
};
|
|
649
|
-
const make$
|
|
638
|
+
const make$5 = (id, methods) => Tag$6()(id, methods);
|
|
650
639
|
const Tag$6 = () => (id, methods) => {
|
|
651
640
|
const definition = makeDefinition$3(id, methods);
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
641
|
+
const tag = Context.Service()(id);
|
|
642
|
+
const bindingDefinition = (binding) => ({
|
|
643
|
+
...binding,
|
|
644
|
+
definition
|
|
645
|
+
});
|
|
646
|
+
const layer = (binding) => layer$4(tag, bindingDefinition(binding));
|
|
647
|
+
const fetch = (input, init) => Effect.gen(function* () {
|
|
648
|
+
return yield* (yield* tag).fetch(input, init);
|
|
649
|
+
});
|
|
650
|
+
const rpc = (method, ...args) => Effect.gen(function* () {
|
|
651
|
+
return yield* (yield* tag).rpc(method, ...args);
|
|
652
|
+
});
|
|
653
|
+
const call = (method, ...args) => Effect.gen(function* () {
|
|
654
|
+
return yield* (yield* tag).call(method, ...args);
|
|
655
|
+
});
|
|
656
|
+
const scopedCall = (method, ...args) => Effect.gen(function* () {
|
|
657
|
+
return yield* (yield* tag).scopedCall(method, ...args);
|
|
658
|
+
});
|
|
659
|
+
const directMethods = makeDirectMethods$1(definition, call);
|
|
660
|
+
return Object.assign(tag, directMethods, {
|
|
661
|
+
id: definition.id,
|
|
662
|
+
methods: definition.methods,
|
|
663
|
+
make: definition.make,
|
|
664
|
+
layer,
|
|
665
|
+
fetch,
|
|
666
|
+
rpc,
|
|
667
|
+
call,
|
|
668
|
+
scopedCall
|
|
669
|
+
});
|
|
660
670
|
};
|
|
661
671
|
const Worker = Tag$6;
|
|
662
672
|
const wrapHandlers$1 = (definition, handlers) => {
|
|
@@ -718,7 +728,7 @@ var Worker_exports = /* @__PURE__ */ __exportAll({
|
|
|
718
728
|
WorkerContext: () => WorkerContext,
|
|
719
729
|
implement: () => implement$4,
|
|
720
730
|
isWebSocketUpgrade: () => isWebSocketUpgrade,
|
|
721
|
-
make: () => make$
|
|
731
|
+
make: () => make$4,
|
|
722
732
|
makeFetchHandler: () => makeFetchHandler,
|
|
723
733
|
method: () => method$2,
|
|
724
734
|
renderHttpResponse: () => renderHttpResponse
|
|
@@ -747,7 +757,7 @@ const RunSymbol$1 = Symbol.for("effect-cf/Worker/run");
|
|
|
747
757
|
const renderHttpResponse = (effect) => Effect.flatMap(effect, (response) => Effect.map(Effect.context(), (context) => HttpServerResponse.toWeb(response, { context })));
|
|
748
758
|
const renderFetchSuccess = (effect) => Effect.flatMap(effect, (response) => response instanceof Response ? Effect.succeed(response) : Effect.map(Effect.context(), (context) => HttpServerResponse.toWeb(response, { context })));
|
|
749
759
|
const isWorkerOptions = (options) => typeof options === "object" && options !== null && ("fetch" in options || "queue" in options || "rpc" in options);
|
|
750
|
-
function make$
|
|
760
|
+
function make$4(layer, optionsOrFetch) {
|
|
751
761
|
const options = isWorkerOptions(optionsOrFetch) ? optionsOrFetch : { fetch: optionsOrFetch };
|
|
752
762
|
class EffectWorker extends WorkerEntrypoint {
|
|
753
763
|
runtime;
|
|
@@ -778,7 +788,7 @@ function make$6(layer, optionsOrFetch) {
|
|
|
778
788
|
return assumeEntrypointClass(EffectWorker);
|
|
779
789
|
}
|
|
780
790
|
const makeFetchHandler = (layer, options) => {
|
|
781
|
-
const WorkerClass = make$
|
|
791
|
+
const WorkerClass = make$4(layer, options);
|
|
782
792
|
return { fetch: (request, env, ctx) => Promise.resolve(new WorkerClass(ctx, env).fetch(request)) };
|
|
783
793
|
};
|
|
784
794
|
const Tag$5 = Tag$6;
|
|
@@ -1078,9 +1088,11 @@ const runPromiseExitPreservingTypedFailures = async (effect) => {
|
|
|
1078
1088
|
var DurableObjectNamespace_exports = /* @__PURE__ */ __exportAll({
|
|
1079
1089
|
DurableObjectFetchError: () => DurableObjectFetchError,
|
|
1080
1090
|
DurableObjectRpcError: () => DurableObjectRpcError,
|
|
1081
|
-
|
|
1091
|
+
isDurableObjectNamespaceClient: () => isDurableObjectNamespaceClient,
|
|
1092
|
+
layer: () => layer$3,
|
|
1093
|
+
makeClient: () => makeClient$2,
|
|
1094
|
+
makeDirectMethods: () => makeDirectMethods
|
|
1082
1095
|
});
|
|
1083
|
-
const TypeId$2 = "effect-cf/DurableObjectNamespace";
|
|
1084
1096
|
/**
|
|
1085
1097
|
* Failure raised when invoking an RPC method on a Durable Object stub.
|
|
1086
1098
|
*/
|
|
@@ -1089,33 +1101,10 @@ var DurableObjectRpcError = class extends Data.TaggedError("DurableObjectRpcErro
|
|
|
1089
1101
|
* Failure raised when forwarding a request to a Durable Object stub.
|
|
1090
1102
|
*/
|
|
1091
1103
|
var DurableObjectFetchError = class extends Data.TaggedError("DurableObjectFetchError") {};
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
* raw `fetch` / `call` helpers, and direct RPC helpers when `definition` is provided.
|
|
1097
|
-
*
|
|
1098
|
-
* @example
|
|
1099
|
-
* ```ts
|
|
1100
|
-
* const ChatRoom = DurableObjectDefinition.make("ChatRoom", {
|
|
1101
|
-
* postMessage: DurableObjectDefinition.method({
|
|
1102
|
-
* args: [Schema.String],
|
|
1103
|
-
* success: Schema.Void,
|
|
1104
|
-
* }),
|
|
1105
|
-
* });
|
|
1106
|
-
*
|
|
1107
|
-
* const ChatRooms = ChatRoom.namespace("CHAT_ROOMS", { binding: "CHAT_ROOMS" });
|
|
1108
|
-
*
|
|
1109
|
-
* const program = Effect.gen(function* () {
|
|
1110
|
-
* const room = ChatRooms.byName("general");
|
|
1111
|
-
* yield* room.postMessage("hello");
|
|
1112
|
-
* });
|
|
1113
|
-
* ```
|
|
1114
|
-
*/
|
|
1115
|
-
const Service$2 = () => (id, definition) => {
|
|
1116
|
-
const hasFunction = (value, key) => typeof Reflect.get(value, key) === "function";
|
|
1117
|
-
const isDurableObjectNamespaceClient = (value) => typeof value === "object" && value !== null && hasFunction(value, "getByName") && hasFunction(value, "get") && hasFunction(value, "idFromName") && hasFunction(value, "idFromString") && hasFunction(value, "newUniqueId") && hasFunction(value, "jurisdiction");
|
|
1118
|
-
const makeClient = (namespace) => {
|
|
1104
|
+
const hasFunction = (value, key) => typeof Reflect.get(value, key) === "function";
|
|
1105
|
+
const isDurableObjectNamespaceClient = (value) => typeof value === "object" && value !== null && hasFunction(value, "getByName") && hasFunction(value, "get") && hasFunction(value, "idFromName") && hasFunction(value, "idFromString") && hasFunction(value, "newUniqueId") && hasFunction(value, "jurisdiction");
|
|
1106
|
+
const makeClient$2 = (definition) => {
|
|
1107
|
+
return (namespace) => {
|
|
1119
1108
|
const newUniqueId = (options) => Effect.sync(() => namespace.newUniqueId(options));
|
|
1120
1109
|
const idFromName = (name) => Effect.sync(() => namespace.idFromName(name));
|
|
1121
1110
|
const idFromString = (id) => Effect.sync(() => namespace.idFromString(id));
|
|
@@ -1141,22 +1130,24 @@ const Service$2 = () => (id, definition) => {
|
|
|
1141
1130
|
cause
|
|
1142
1131
|
}));
|
|
1143
1132
|
});
|
|
1144
|
-
const
|
|
1145
|
-
|
|
1146
|
-
|
|
1133
|
+
const decodeSuccess$1 = (methodName, value) => Effect.gen(function* () {
|
|
1134
|
+
if (definition.definition === void 0) return value;
|
|
1135
|
+
return yield* decodeSuccess(definition.definition, methodName, value).pipe(Effect.mapError((cause) => new DurableObjectRpcError({
|
|
1147
1136
|
binding: definition.binding,
|
|
1148
1137
|
method: methodName,
|
|
1149
1138
|
cause
|
|
1150
1139
|
})));
|
|
1151
|
-
|
|
1152
|
-
|
|
1140
|
+
});
|
|
1141
|
+
const call = (stub, method, ...args) => Effect.gen(function* () {
|
|
1142
|
+
const methodName = String(method);
|
|
1143
|
+
return yield* decodeSuccess$1(methodName, yield* resolve(yield* rpc(stub, method, ...args)).pipe(Effect.mapError((cause) => new DurableObjectRpcError({
|
|
1153
1144
|
binding: definition.binding,
|
|
1154
1145
|
method: methodName,
|
|
1155
1146
|
cause
|
|
1156
|
-
})));
|
|
1147
|
+
}))));
|
|
1157
1148
|
});
|
|
1158
1149
|
const scopedCall = (stub, method, ...args) => Effect.gen(function* () {
|
|
1159
|
-
return yield* scoped(yield* rpc(stub, method, ...args));
|
|
1150
|
+
return yield* decodeSuccess$1(String(method), yield* scoped(yield* rpc(stub, method, ...args)));
|
|
1160
1151
|
});
|
|
1161
1152
|
const directMethods = makeDirectMethods(definition.definition, {
|
|
1162
1153
|
call,
|
|
@@ -1178,86 +1169,8 @@ const Service$2 = () => (id, definition) => {
|
|
|
1178
1169
|
unsafeRaw: Effect.succeed(namespace)
|
|
1179
1170
|
});
|
|
1180
1171
|
};
|
|
1181
|
-
const tag = Service$6()(id, definition.binding, (value) => isDurableObjectNamespaceClient(value), makeClient);
|
|
1182
|
-
const newUniqueId = Effect.fnUntraced(function* (options) {
|
|
1183
|
-
return yield* (yield* tag).newUniqueId(options);
|
|
1184
|
-
});
|
|
1185
|
-
const idFromName = Effect.fnUntraced(function* (name) {
|
|
1186
|
-
return yield* (yield* tag).idFromName(name);
|
|
1187
|
-
});
|
|
1188
|
-
const idFromString = Effect.fnUntraced(function* (id) {
|
|
1189
|
-
return yield* (yield* tag).idFromString(id);
|
|
1190
|
-
});
|
|
1191
|
-
const get = Effect.fnUntraced(function* (id, options) {
|
|
1192
|
-
return yield* (yield* tag).get(id, options);
|
|
1193
|
-
});
|
|
1194
|
-
const getByName = Effect.fnUntraced(function* (name, options) {
|
|
1195
|
-
return yield* (yield* tag).getByName(name, options);
|
|
1196
|
-
});
|
|
1197
|
-
const jurisdiction = Effect.fnUntraced(function* (value) {
|
|
1198
|
-
return yield* (yield* tag).jurisdiction(value);
|
|
1199
|
-
});
|
|
1200
|
-
const fetch = (stub, input, init) => Effect.tryPromise({
|
|
1201
|
-
try: () => stub.fetch(input, init),
|
|
1202
|
-
catch: (cause) => new DurableObjectFetchError({
|
|
1203
|
-
binding: definition.binding,
|
|
1204
|
-
cause
|
|
1205
|
-
})
|
|
1206
|
-
});
|
|
1207
|
-
const rpc = (stub, method, ...args) => Effect.gen(function* () {
|
|
1208
|
-
const methodName = String(method);
|
|
1209
|
-
return yield* invokeRpcMethod(stub, method, definition.definition === void 0 ? args : yield* encodeArgs(definition.definition, methodName, args).pipe(Effect.mapError((cause) => new DurableObjectRpcError({
|
|
1210
|
-
binding: definition.binding,
|
|
1211
|
-
method: methodName,
|
|
1212
|
-
cause
|
|
1213
|
-
}))), (cause) => new DurableObjectRpcError({
|
|
1214
|
-
binding: definition.binding,
|
|
1215
|
-
method: methodName,
|
|
1216
|
-
cause
|
|
1217
|
-
}));
|
|
1218
|
-
});
|
|
1219
|
-
const call = (stub, method, ...args) => Effect.gen(function* () {
|
|
1220
|
-
const methodName = String(method);
|
|
1221
|
-
const value = yield* resolve(yield* rpc(stub, method, ...args)).pipe(Effect.mapError((cause) => new DurableObjectRpcError({
|
|
1222
|
-
binding: definition.binding,
|
|
1223
|
-
method: methodName,
|
|
1224
|
-
cause
|
|
1225
|
-
})));
|
|
1226
|
-
if (definition.definition === void 0) return value;
|
|
1227
|
-
return yield* decodeSuccess(definition.definition, methodName, value).pipe(Effect.mapError((cause) => new DurableObjectRpcError({
|
|
1228
|
-
binding: definition.binding,
|
|
1229
|
-
method: methodName,
|
|
1230
|
-
cause
|
|
1231
|
-
})));
|
|
1232
|
-
});
|
|
1233
|
-
const scopedCall = (stub, method, ...args) => Effect.gen(function* () {
|
|
1234
|
-
return yield* scoped(yield* rpc(stub, method, ...args));
|
|
1235
|
-
});
|
|
1236
|
-
const unsafeRaw = Effect.fnUntraced(function* () {
|
|
1237
|
-
return yield* (yield* tag).unsafeRaw;
|
|
1238
|
-
});
|
|
1239
|
-
const directMethods = makeDirectMethods(definition.definition, {
|
|
1240
|
-
call,
|
|
1241
|
-
fetch,
|
|
1242
|
-
get,
|
|
1243
|
-
getByName
|
|
1244
|
-
});
|
|
1245
|
-
return Object.assign(tag, directMethods, {
|
|
1246
|
-
[TypeId$2]: TypeId$2,
|
|
1247
|
-
definition,
|
|
1248
|
-
newUniqueId,
|
|
1249
|
-
idFromName,
|
|
1250
|
-
idFromString,
|
|
1251
|
-
get,
|
|
1252
|
-
getByName,
|
|
1253
|
-
jurisdiction,
|
|
1254
|
-
fetch,
|
|
1255
|
-
rpc,
|
|
1256
|
-
call,
|
|
1257
|
-
scopedCall,
|
|
1258
|
-
unsafeRaw
|
|
1259
|
-
});
|
|
1260
1172
|
};
|
|
1173
|
+
const layer$3 = (tag, definition) => layer$6(tag, definition.binding, (value) => isDurableObjectNamespaceClient(value), makeClient$2(definition));
|
|
1261
1174
|
const makeDirectMethods = (rpcDefinition, helpers) => {
|
|
1262
1175
|
const methods = {};
|
|
1263
1176
|
if (rpcDefinition !== void 0) {
|
|
@@ -1284,7 +1197,7 @@ var DurableObjectDefinition_exports = /* @__PURE__ */ __exportAll({
|
|
|
1284
1197
|
DurableObject: () => DurableObject$1,
|
|
1285
1198
|
Tag: () => Tag$4,
|
|
1286
1199
|
implement: () => implement$3,
|
|
1287
|
-
make: () => make$
|
|
1200
|
+
make: () => make$3,
|
|
1288
1201
|
method: () => method$1
|
|
1289
1202
|
});
|
|
1290
1203
|
const reservedMethodNames$1 = new Set([
|
|
@@ -1315,33 +1228,77 @@ const method$1 = method$4;
|
|
|
1315
1228
|
*/
|
|
1316
1229
|
const makeDefinition$2 = (id, methods) => {
|
|
1317
1230
|
assertNoReservedMethods("Durable Object", methods, reservedMethodNames$1);
|
|
1318
|
-
const definition = make$
|
|
1319
|
-
return Object.assign(definition, {
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
}),
|
|
1324
|
-
Namespace: () => (bindingId, binding) => Service$2()(bindingId, {
|
|
1325
|
-
...binding,
|
|
1326
|
-
definition
|
|
1327
|
-
}),
|
|
1328
|
-
namespace: (bindingId, binding) => Service$2()(bindingId, {
|
|
1329
|
-
...binding,
|
|
1330
|
-
definition
|
|
1331
|
-
})
|
|
1332
|
-
});
|
|
1231
|
+
const definition = make$6(id, methods);
|
|
1232
|
+
return Object.assign(definition, { make: (layer, options) => make$2(layer, {
|
|
1233
|
+
...options,
|
|
1234
|
+
rpc: wrapHandlers(definition, options.rpc)
|
|
1235
|
+
}) });
|
|
1333
1236
|
};
|
|
1334
|
-
const make$
|
|
1237
|
+
const make$3 = (id, methods) => Tag$4()(id, methods);
|
|
1335
1238
|
const Tag$4 = () => (id, methods) => {
|
|
1336
1239
|
const definition = makeDefinition$2(id, methods);
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1240
|
+
const tag = Context.Service()(id);
|
|
1241
|
+
const bindingDefinition = (binding) => ({
|
|
1242
|
+
...binding,
|
|
1243
|
+
definition
|
|
1244
|
+
});
|
|
1245
|
+
const layer = (binding) => layer$3(tag, bindingDefinition(binding));
|
|
1246
|
+
const newUniqueId = Effect.fnUntraced(function* (options) {
|
|
1247
|
+
return yield* (yield* tag).newUniqueId(options);
|
|
1248
|
+
});
|
|
1249
|
+
const idFromName = Effect.fnUntraced(function* (name) {
|
|
1250
|
+
return yield* (yield* tag).idFromName(name);
|
|
1251
|
+
});
|
|
1252
|
+
const idFromString = Effect.fnUntraced(function* (value) {
|
|
1253
|
+
return yield* (yield* tag).idFromString(value);
|
|
1254
|
+
});
|
|
1255
|
+
const get = Effect.fnUntraced(function* (objectId, options) {
|
|
1256
|
+
return yield* (yield* tag).get(objectId, options);
|
|
1257
|
+
});
|
|
1258
|
+
const getByName = Effect.fnUntraced(function* (name, options) {
|
|
1259
|
+
return yield* (yield* tag).getByName(name, options);
|
|
1260
|
+
});
|
|
1261
|
+
const jurisdiction = Effect.fnUntraced(function* (value) {
|
|
1262
|
+
return yield* (yield* tag).jurisdiction(value);
|
|
1263
|
+
});
|
|
1264
|
+
const fetch = (stub, input, init) => Effect.gen(function* () {
|
|
1265
|
+
return yield* (yield* tag).fetch(stub, input, init);
|
|
1266
|
+
});
|
|
1267
|
+
const rpc = (stub, method, ...args) => Effect.gen(function* () {
|
|
1268
|
+
return yield* (yield* tag).rpc(stub, method, ...args);
|
|
1269
|
+
});
|
|
1270
|
+
const call = (stub, method, ...args) => Effect.gen(function* () {
|
|
1271
|
+
return yield* (yield* tag).call(stub, method, ...args);
|
|
1272
|
+
});
|
|
1273
|
+
const scopedCall = (stub, method, ...args) => Effect.gen(function* () {
|
|
1274
|
+
return yield* (yield* tag).scopedCall(stub, method, ...args);
|
|
1275
|
+
});
|
|
1276
|
+
const unsafeRaw = Effect.fnUntraced(function* () {
|
|
1277
|
+
return yield* (yield* tag).unsafeRaw;
|
|
1278
|
+
});
|
|
1279
|
+
const directMethods = makeDirectMethods(definition, {
|
|
1280
|
+
call,
|
|
1281
|
+
fetch,
|
|
1282
|
+
get,
|
|
1283
|
+
getByName
|
|
1284
|
+
});
|
|
1285
|
+
return Object.assign(tag, directMethods, {
|
|
1286
|
+
id: definition.id,
|
|
1287
|
+
methods: definition.methods,
|
|
1288
|
+
make: definition.make,
|
|
1289
|
+
layer,
|
|
1290
|
+
newUniqueId,
|
|
1291
|
+
idFromName,
|
|
1292
|
+
idFromString,
|
|
1293
|
+
get,
|
|
1294
|
+
getByName,
|
|
1295
|
+
jurisdiction,
|
|
1296
|
+
fetch,
|
|
1297
|
+
rpc,
|
|
1298
|
+
call,
|
|
1299
|
+
scopedCall,
|
|
1300
|
+
unsafeRaw
|
|
1301
|
+
});
|
|
1345
1302
|
};
|
|
1346
1303
|
const DurableObject$1 = Tag$4;
|
|
1347
1304
|
const wrapHandlers = (definition, handlers) => {
|
|
@@ -1363,7 +1320,7 @@ const implement$3 = (_definition, handlers) => handlers;
|
|
|
1363
1320
|
var DurableObject_exports = /* @__PURE__ */ __exportAll({
|
|
1364
1321
|
Tag: () => Tag$3,
|
|
1365
1322
|
implement: () => implement$2,
|
|
1366
|
-
make: () => make$
|
|
1323
|
+
make: () => make$2,
|
|
1367
1324
|
method: () => method
|
|
1368
1325
|
});
|
|
1369
1326
|
const reservedMethodNames = new Set([
|
|
@@ -1379,7 +1336,7 @@ const RunSymbol = Symbol.for("effect-cf/DurableObject/run");
|
|
|
1379
1336
|
/**
|
|
1380
1337
|
* Creates a Durable Object class backed by a single managed Effect runtime.
|
|
1381
1338
|
*/
|
|
1382
|
-
const make$
|
|
1339
|
+
const make$2 = (layer, options = {}) => {
|
|
1383
1340
|
class EffectDurableObject extends DurableObject {
|
|
1384
1341
|
runtime;
|
|
1385
1342
|
constructor(state, env) {
|
|
@@ -1747,7 +1704,7 @@ var DurableObjectAlarm = class DurableObjectAlarm extends Context.Service()("eff
|
|
|
1747
1704
|
//#region src/DurableObjectRpcWebSocket.ts
|
|
1748
1705
|
var DurableObjectRpcWebSocket_exports = /* @__PURE__ */ __exportAll({
|
|
1749
1706
|
DurableObjectRpcWebSocket: () => DurableObjectRpcWebSocket,
|
|
1750
|
-
layer: () => layer
|
|
1707
|
+
layer: () => layer$2
|
|
1751
1708
|
});
|
|
1752
1709
|
const defaultAttachmentKey = "effectCloudflareRpcClientId";
|
|
1753
1710
|
const defaultTag = "effect-cf-rpc";
|
|
@@ -1758,7 +1715,7 @@ var DurableObjectRpcWebSocket = class extends Context.Service()("effect-cf/Durab
|
|
|
1758
1715
|
/**
|
|
1759
1716
|
* Builds a layer that bridges Durable Object websocket events to `RpcServer.Protocol`.
|
|
1760
1717
|
*/
|
|
1761
|
-
const layer = (options = {}) => Layer.effectContext(Effect.gen(function* () {
|
|
1718
|
+
const layer$2 = (options = {}) => Layer.effectContext(Effect.gen(function* () {
|
|
1762
1719
|
const tag = options.tag ?? defaultTag;
|
|
1763
1720
|
const attachmentKey = options.attachmentKey ?? defaultAttachmentKey;
|
|
1764
1721
|
const durableObjectState = yield* DurableObjectState;
|
|
@@ -1873,11 +1830,11 @@ const writeAttachment = (socket, key, clientId) => {
|
|
|
1873
1830
|
//#region src/Kv.ts
|
|
1874
1831
|
var Kv_exports = /* @__PURE__ */ __exportAll({
|
|
1875
1832
|
KvOperationError: () => KvOperationError,
|
|
1876
|
-
Service: () => Service$1,
|
|
1877
1833
|
Tag: () => Tag$2,
|
|
1878
|
-
|
|
1834
|
+
isKvNamespace: () => isKvNamespace,
|
|
1835
|
+
layer: () => layer$1,
|
|
1836
|
+
makeClient: () => makeClient$1
|
|
1879
1837
|
});
|
|
1880
|
-
const TypeId$1 = "effect-cf/Kv";
|
|
1881
1838
|
/** Error raised when a KV operation fails. */
|
|
1882
1839
|
var KvOperationError = class extends Data.TaggedError("KvOperationError") {};
|
|
1883
1840
|
const maybeString = (value) => value == null ? Option.none() : Option.some(value);
|
|
@@ -1891,66 +1848,17 @@ const tryKvPromise = (binding, operation, evaluate) => Effect.tryPromise({
|
|
|
1891
1848
|
try: evaluate,
|
|
1892
1849
|
catch: (cause) => kvError(binding, operation, cause)
|
|
1893
1850
|
});
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
const makeDefinition$1 = (id, definition) => {
|
|
1899
|
-
const kvDefinition = {
|
|
1900
|
-
id,
|
|
1901
|
-
key: definition.key,
|
|
1902
|
-
value: definition.value
|
|
1903
|
-
};
|
|
1904
|
-
return Object.assign(kvDefinition, {
|
|
1905
|
-
Binding: () => (bindingId, binding) => Service$1()(bindingId, {
|
|
1906
|
-
...binding,
|
|
1907
|
-
key: definition.key,
|
|
1908
|
-
value: definition.value
|
|
1909
|
-
}),
|
|
1910
|
-
binding: (bindingId, binding) => Service$1()(bindingId, {
|
|
1911
|
-
...binding,
|
|
1912
|
-
key: definition.key,
|
|
1913
|
-
value: definition.value
|
|
1914
|
-
})
|
|
1915
|
-
});
|
|
1916
|
-
};
|
|
1917
|
-
const Tag$2 = () => (id, definition) => {
|
|
1918
|
-
const kvDefinition = makeDefinition$1(id, definition);
|
|
1919
|
-
class KvDefinitionClass {
|
|
1920
|
-
static id = kvDefinition.id;
|
|
1921
|
-
static key = kvDefinition.key;
|
|
1922
|
-
static value = kvDefinition.value;
|
|
1923
|
-
static Binding = kvDefinition.Binding;
|
|
1924
|
-
static binding = kvDefinition.binding;
|
|
1925
|
-
}
|
|
1926
|
-
return KvDefinitionClass;
|
|
1851
|
+
const isKvNamespace = (value) => {
|
|
1852
|
+
if (typeof value !== "object" || value === null) return false;
|
|
1853
|
+
const resource = value;
|
|
1854
|
+
return typeof resource.get === "function" && typeof resource.put === "function" && typeof resource.delete === "function" && typeof resource.getWithMetadata === "function" && typeof resource.list === "function";
|
|
1927
1855
|
};
|
|
1928
|
-
|
|
1929
|
-
* Builds a KV service around a Cloudflare KV namespace binding.
|
|
1930
|
-
*
|
|
1931
|
-
* Returned service includes schema-aware `put`, `get`, `getWithMetadata`,
|
|
1932
|
-
* `list`, and `remove` helpers.
|
|
1933
|
-
*
|
|
1934
|
-
* @example
|
|
1935
|
-
* ```ts
|
|
1936
|
-
* const Sessions = Kv.make("Sessions", {
|
|
1937
|
-
* binding: "SESSIONS",
|
|
1938
|
-
* key: Schema.String,
|
|
1939
|
-
* value: Schema.Struct({ userId: Schema.String }),
|
|
1940
|
-
* });
|
|
1941
|
-
*
|
|
1942
|
-
* const program = Effect.gen(function* () {
|
|
1943
|
-
* yield* Sessions.put("abc", { userId: "u_1" });
|
|
1944
|
-
* return yield* Sessions.get("abc");
|
|
1945
|
-
* });
|
|
1946
|
-
* ```
|
|
1947
|
-
*/
|
|
1948
|
-
const Service$1 = () => (id, definition) => {
|
|
1856
|
+
const makeClient$1 = (definition) => {
|
|
1949
1857
|
const encodeKey = Schema.encodeEffect(definition.key);
|
|
1950
1858
|
const decodeKey = Schema.decodeUnknownEffect(definition.key);
|
|
1951
1859
|
const encodeValue = Schema.encodeEffect(Schema.fromJsonString(Schema.toCodecJson(definition.value)));
|
|
1952
1860
|
const decodeValue = Schema.decodeUnknownEffect(Schema.fromJsonString(Schema.toCodecJson(definition.value)));
|
|
1953
|
-
|
|
1861
|
+
return (kv) => ({
|
|
1954
1862
|
definition,
|
|
1955
1863
|
put: Effect.fnUntraced(function* (key, value, options) {
|
|
1956
1864
|
const keyEncoded = yield* encodeKey(key);
|
|
@@ -2001,11 +1909,24 @@ const Service$1 = () => (id, definition) => {
|
|
|
2001
1909
|
}),
|
|
2002
1910
|
unsafeRaw: Effect.succeed(kv)
|
|
2003
1911
|
});
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
1912
|
+
};
|
|
1913
|
+
const layer$1 = (tag, definition) => layer$6(tag, definition.binding, isKvNamespace, makeClient$1(definition));
|
|
1914
|
+
const makeDefinition$1 = (id, definition) => {
|
|
1915
|
+
const kvDefinition = {
|
|
1916
|
+
id,
|
|
1917
|
+
key: definition.key,
|
|
1918
|
+
value: definition.value
|
|
1919
|
+
};
|
|
1920
|
+
return Object.assign(kvDefinition, { layer: (tag, binding) => layer$1(tag, {
|
|
1921
|
+
...binding,
|
|
1922
|
+
key: definition.key,
|
|
1923
|
+
value: definition.value
|
|
1924
|
+
}) });
|
|
1925
|
+
};
|
|
1926
|
+
const Tag$2 = () => (id, definition) => {
|
|
1927
|
+
const kvDefinition = makeDefinition$1(id, definition);
|
|
1928
|
+
const tag = Context.Service()(id);
|
|
1929
|
+
const makeLayer = (binding) => kvDefinition.layer(tag, binding);
|
|
2009
1930
|
const put = Effect.fnUntraced(function* (key, value, options) {
|
|
2010
1931
|
yield* (yield* tag).put(key, value, options);
|
|
2011
1932
|
});
|
|
@@ -2025,8 +1946,10 @@ const Service$1 = () => (id, definition) => {
|
|
|
2025
1946
|
return yield* (yield* tag).unsafeRaw;
|
|
2026
1947
|
});
|
|
2027
1948
|
return Object.assign(tag, {
|
|
2028
|
-
|
|
2029
|
-
|
|
1949
|
+
id: kvDefinition.id,
|
|
1950
|
+
keySchema: kvDefinition.key,
|
|
1951
|
+
valueSchema: kvDefinition.value,
|
|
1952
|
+
layer: makeLayer,
|
|
2030
1953
|
put,
|
|
2031
1954
|
get,
|
|
2032
1955
|
getWithMetadata,
|
|
@@ -2038,12 +1961,12 @@ const Service$1 = () => (id, definition) => {
|
|
|
2038
1961
|
//#endregion
|
|
2039
1962
|
//#region src/WorkflowBinding.ts
|
|
2040
1963
|
var WorkflowBinding_exports = /* @__PURE__ */ __exportAll({
|
|
2041
|
-
Service: () => Service,
|
|
2042
1964
|
WorkflowOperationError: () => WorkflowOperationError,
|
|
2043
1965
|
WorkflowResultDecodeError: () => WorkflowResultDecodeError,
|
|
2044
|
-
|
|
1966
|
+
isWorkflow: () => isWorkflow,
|
|
1967
|
+
layer: () => layer,
|
|
1968
|
+
makeClient: () => makeClient
|
|
2045
1969
|
});
|
|
2046
|
-
const TypeId = "effect-cf/WorkflowBinding";
|
|
2047
1970
|
var WorkflowOperationError = class extends Data.TaggedError("WorkflowOperationError") {};
|
|
2048
1971
|
var WorkflowResultDecodeError = class extends Data.TaggedError("WorkflowResultDecodeError") {};
|
|
2049
1972
|
const workflowError = (binding, operation, cause) => new WorkflowOperationError({
|
|
@@ -2060,9 +1983,7 @@ const isWorkflow = (value) => {
|
|
|
2060
1983
|
const resource = value;
|
|
2061
1984
|
return typeof resource.create === "function" && typeof resource.createBatch === "function" && typeof resource.get === "function";
|
|
2062
1985
|
};
|
|
2063
|
-
const
|
|
2064
|
-
const Service = () => (id, definition) => {
|
|
2065
|
-
const tag = Service$6()(id, definition.binding, (value) => isWorkflow(value));
|
|
1986
|
+
const makeClient = (definition) => {
|
|
2066
1987
|
const encodePayload = Schema.encodeEffect(definition.payload);
|
|
2067
1988
|
const decodeResult = Schema.decodeUnknownEffect(definition.result);
|
|
2068
1989
|
const wrapInstance = (raw) => {
|
|
@@ -2089,38 +2010,30 @@ const Service = () => (id, definition) => {
|
|
|
2089
2010
|
sendEvent: (event) => operation("sendEvent", () => raw.sendEvent(event))
|
|
2090
2011
|
};
|
|
2091
2012
|
};
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
...options,
|
|
2097
|
-
params: encoded
|
|
2098
|
-
})));
|
|
2099
|
-
});
|
|
2100
|
-
const createBatch = Effect.fnUntraced(function* (batch) {
|
|
2101
|
-
const workflow = yield* tag;
|
|
2102
|
-
const encodedBatch = [];
|
|
2103
|
-
for (const item of batch) {
|
|
2104
|
-
const { payload, ...options } = item;
|
|
2105
|
-
encodedBatch.push({
|
|
2013
|
+
return (workflow) => ({
|
|
2014
|
+
create: Effect.fnUntraced(function* (payload, options) {
|
|
2015
|
+
const encoded = yield* encodePayload(payload);
|
|
2016
|
+
return wrapInstance(yield* tryWorkflowPromise(definition.binding, "create", () => workflow.create({
|
|
2106
2017
|
...options,
|
|
2107
|
-
params:
|
|
2108
|
-
});
|
|
2109
|
-
}
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
get
|
|
2018
|
+
params: encoded
|
|
2019
|
+
})));
|
|
2020
|
+
}),
|
|
2021
|
+
createBatch: Effect.fnUntraced(function* (batch) {
|
|
2022
|
+
const encodedBatch = [];
|
|
2023
|
+
for (const item of batch) {
|
|
2024
|
+
const { payload, ...options } = item;
|
|
2025
|
+
encodedBatch.push({
|
|
2026
|
+
...options,
|
|
2027
|
+
params: yield* encodePayload(payload)
|
|
2028
|
+
});
|
|
2029
|
+
}
|
|
2030
|
+
return (yield* tryWorkflowPromise(definition.binding, "createBatch", () => workflow.createBatch(encodedBatch))).map(wrapInstance);
|
|
2031
|
+
}),
|
|
2032
|
+
get: (instanceId) => tryWorkflowPromise(definition.binding, "get", () => workflow.get(instanceId)).pipe(Effect.map(wrapInstance)),
|
|
2033
|
+
unsafeRaw: Effect.succeed(workflow)
|
|
2122
2034
|
});
|
|
2123
2035
|
};
|
|
2036
|
+
const layer = (tag, definition) => layer$6(tag, definition.binding, (value) => isWorkflow(value), makeClient(definition));
|
|
2124
2037
|
//#endregion
|
|
2125
2038
|
//#region src/WorkflowDefinition.ts
|
|
2126
2039
|
var WorkflowDefinition_exports = /* @__PURE__ */ __exportAll({
|
|
@@ -2135,32 +2048,40 @@ const makeDefinition = (id, definition) => {
|
|
|
2135
2048
|
payload: definition.payload,
|
|
2136
2049
|
result: definition.result
|
|
2137
2050
|
};
|
|
2138
|
-
return Object.assign(workflowDefinition, {
|
|
2139
|
-
make: (layer, options) => make(layer, { run: wrapHandler(workflowDefinition, options.run) }),
|
|
2140
|
-
Binding: () => (bindingId, binding) => Service()(bindingId, {
|
|
2141
|
-
...binding,
|
|
2142
|
-
payload: definition.payload,
|
|
2143
|
-
result: definition.result
|
|
2144
|
-
}),
|
|
2145
|
-
binding: (bindingId, binding) => Service()(bindingId, {
|
|
2146
|
-
...binding,
|
|
2147
|
-
payload: definition.payload,
|
|
2148
|
-
result: definition.result
|
|
2149
|
-
})
|
|
2150
|
-
});
|
|
2051
|
+
return Object.assign(workflowDefinition, { make: (layer, options) => make(layer, { run: wrapHandler(workflowDefinition, options.run) }) });
|
|
2151
2052
|
};
|
|
2152
|
-
const make$1 =
|
|
2053
|
+
const make$1 = (id, definition) => Tag$1()(id, definition);
|
|
2153
2054
|
const Tag$1 = () => (id, definition) => {
|
|
2154
2055
|
const workflowDefinition = makeDefinition(id, definition);
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2056
|
+
const tag = Context.Service()(id);
|
|
2057
|
+
const layer$7 = (binding) => layer(tag, {
|
|
2058
|
+
...binding,
|
|
2059
|
+
payload: definition.payload,
|
|
2060
|
+
result: definition.result
|
|
2061
|
+
});
|
|
2062
|
+
const create = Effect.fnUntraced(function* (payload, options) {
|
|
2063
|
+
return yield* (yield* tag).create(payload, options);
|
|
2064
|
+
});
|
|
2065
|
+
const createBatch = Effect.fnUntraced(function* (batch) {
|
|
2066
|
+
return yield* (yield* tag).createBatch(batch);
|
|
2067
|
+
});
|
|
2068
|
+
const get = Effect.fnUntraced(function* (instanceId) {
|
|
2069
|
+
return yield* (yield* tag).get(instanceId);
|
|
2070
|
+
});
|
|
2071
|
+
const unsafeRaw = Effect.fnUntraced(function* () {
|
|
2072
|
+
return yield* (yield* tag).unsafeRaw;
|
|
2073
|
+
});
|
|
2074
|
+
return Object.assign(tag, {
|
|
2075
|
+
id: workflowDefinition.id,
|
|
2076
|
+
payload: workflowDefinition.payload,
|
|
2077
|
+
result: workflowDefinition.result,
|
|
2078
|
+
make: workflowDefinition.make,
|
|
2079
|
+
layer: layer$7,
|
|
2080
|
+
create,
|
|
2081
|
+
createBatch,
|
|
2082
|
+
get,
|
|
2083
|
+
unsafeRaw
|
|
2084
|
+
});
|
|
2164
2085
|
};
|
|
2165
2086
|
const Workflow = Tag$1;
|
|
2166
2087
|
const wrapHandler = (definition, handler) => {
|