effect-cf 0.5.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 +14 -0
- package/README.md +36 -29
- package/dist/index.d.mts +854 -1216
- package/dist/index.mjs +469 -441
- package/package.json +1 -1
- package/src/Binding.ts +36 -13
- package/src/DurableObject.ts +117 -23
- package/src/DurableObjectDefinition.ts +251 -72
- package/src/DurableObjectNamespace.ts +305 -158
- package/src/Kv.ts +181 -154
- package/src/Queue.ts +18 -4
- package/src/QueueBinding.ts +43 -62
- package/src/QueueDefinition.ts +87 -41
- package/src/ServiceBinding.ts +288 -81
- 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,28 +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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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) => {
|
|
53
55
|
const tag = Context.Service()(id);
|
|
54
|
-
const
|
|
55
|
-
return yield* getBinding(yield* WorkerEnvironment, binding, isResource);
|
|
56
|
-
}));
|
|
56
|
+
const serviceLayer = layer$6(tag, binding, isResource, wrap);
|
|
57
57
|
return Object.assign(tag, {
|
|
58
|
-
[TypeId$
|
|
58
|
+
[TypeId$2]: TypeId$2,
|
|
59
59
|
binding,
|
|
60
|
-
layer
|
|
60
|
+
layer: serviceLayer
|
|
61
61
|
});
|
|
62
62
|
};
|
|
63
63
|
//#endregion
|
|
64
64
|
//#region src/D1.ts
|
|
65
65
|
var D1_exports = /* @__PURE__ */ __exportAll({
|
|
66
66
|
D1OperationError: () => D1OperationError,
|
|
67
|
-
Service: () => Service$
|
|
68
|
-
make: () => make$
|
|
67
|
+
Service: () => Service$1,
|
|
68
|
+
make: () => make$8
|
|
69
69
|
});
|
|
70
|
-
const TypeId$
|
|
70
|
+
const TypeId$1 = "effect-cf/D1";
|
|
71
71
|
/** Error raised when a D1 operation fails. */
|
|
72
72
|
var D1OperationError = class extends Data.TaggedError("D1OperationError") {};
|
|
73
73
|
const isD1Database = (value) => {
|
|
@@ -91,7 +91,7 @@ const tryD1Sync = (binding, operation, evaluate) => Effect.try({
|
|
|
91
91
|
/**
|
|
92
92
|
* Creates a typed D1 service tag plus Effect helpers.
|
|
93
93
|
*/
|
|
94
|
-
const make$
|
|
94
|
+
const make$8 = (id, definition) => Service$1()(id, definition);
|
|
95
95
|
/**
|
|
96
96
|
* Builds a D1 service around a Cloudflare D1 database binding.
|
|
97
97
|
*
|
|
@@ -108,8 +108,8 @@ const make$11 = (id, definition) => Service$5()(id, definition);
|
|
|
108
108
|
* const SqlLive = TodoDatabase.sqlLayer();
|
|
109
109
|
* ```
|
|
110
110
|
*/
|
|
111
|
-
const Service$
|
|
112
|
-
const tag = Service$
|
|
111
|
+
const Service$1 = () => (id, definition) => {
|
|
112
|
+
const tag = Service$2()(id, definition.binding, isD1Database);
|
|
113
113
|
const sqlLayer = (options) => Layer.unwrap(Effect.gen(function* () {
|
|
114
114
|
const db = yield* tag;
|
|
115
115
|
return D1Client.layer({
|
|
@@ -133,7 +133,7 @@ const Service$5 = () => (id, definition) => {
|
|
|
133
133
|
return yield* tag;
|
|
134
134
|
});
|
|
135
135
|
return Object.assign(tag, {
|
|
136
|
-
[TypeId$
|
|
136
|
+
[TypeId$1]: TypeId$1,
|
|
137
137
|
definition,
|
|
138
138
|
sqlLayer,
|
|
139
139
|
prepare,
|
|
@@ -146,10 +146,10 @@ const Service$5 = () => (id, definition) => {
|
|
|
146
146
|
//#region src/QueueBinding.ts
|
|
147
147
|
var QueueBinding_exports = /* @__PURE__ */ __exportAll({
|
|
148
148
|
QueueOperationError: () => QueueOperationError,
|
|
149
|
-
|
|
150
|
-
|
|
149
|
+
isQueue: () => isQueue,
|
|
150
|
+
layer: () => layer$5,
|
|
151
|
+
makeClient: () => makeClient$4
|
|
151
152
|
});
|
|
152
|
-
const TypeId$4 = "effect-cf/QueueBinding";
|
|
153
153
|
var QueueOperationError = class extends Data.TaggedError("QueueOperationError") {};
|
|
154
154
|
const queueError = (binding, operation, cause) => new QueueOperationError({
|
|
155
155
|
binding,
|
|
@@ -165,79 +165,74 @@ const isQueue = (value) => {
|
|
|
165
165
|
const resource = value;
|
|
166
166
|
return typeof resource.send === "function" && typeof resource.sendBatch === "function" && typeof resource.metrics === "function";
|
|
167
167
|
};
|
|
168
|
-
|
|
169
|
-
const make$10 = (id, definition) => Service$4()(id, definition);
|
|
170
|
-
/**
|
|
171
|
-
* Builds an Effect service around a Cloudflare Queue producer binding.
|
|
172
|
-
*/
|
|
173
|
-
const Service$4 = () => (id, definition) => {
|
|
174
|
-
const tag = Service$6()(id, definition.binding, (value) => isQueue(value));
|
|
168
|
+
const makeClient$4 = (definition) => {
|
|
175
169
|
const encodeMessage = Schema.encodeEffect(definition.message);
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
const queue = yield* tag;
|
|
192
|
-
return yield* tryQueuePromise(definition.binding, "metrics", () => queue.metrics());
|
|
193
|
-
});
|
|
194
|
-
return Object.assign(tag, {
|
|
195
|
-
[TypeId$4]: TypeId$4,
|
|
196
|
-
binding: definition.binding,
|
|
197
|
-
send,
|
|
198
|
-
sendBatch,
|
|
199
|
-
metrics
|
|
170
|
+
return (queue) => ({
|
|
171
|
+
send: Effect.fnUntraced(function* (message, options) {
|
|
172
|
+
const encoded = yield* encodeMessage(message);
|
|
173
|
+
yield* tryQueuePromise(definition.binding, "send", () => queue.send(encoded, options));
|
|
174
|
+
}),
|
|
175
|
+
sendBatch: Effect.fnUntraced(function* (messages, options) {
|
|
176
|
+
const encodedMessages = [];
|
|
177
|
+
for (const message of messages) encodedMessages.push({
|
|
178
|
+
...message,
|
|
179
|
+
body: yield* encodeMessage(message.body)
|
|
180
|
+
});
|
|
181
|
+
yield* tryQueuePromise(definition.binding, "sendBatch", () => queue.sendBatch(encodedMessages, options));
|
|
182
|
+
}),
|
|
183
|
+
metrics: () => tryQueuePromise(definition.binding, "metrics", () => queue.metrics()),
|
|
184
|
+
unsafeRaw: Effect.succeed(queue)
|
|
200
185
|
});
|
|
201
186
|
};
|
|
187
|
+
const layer$5 = (tag, definition) => layer$6(tag, definition.binding, (value) => isQueue(value), makeClient$4(definition));
|
|
202
188
|
//#endregion
|
|
203
189
|
//#region src/QueueDefinition.ts
|
|
204
190
|
var QueueDefinition_exports = /* @__PURE__ */ __exportAll({
|
|
205
191
|
Queue: () => Queue$1,
|
|
206
192
|
Tag: () => Tag$8,
|
|
207
193
|
implement: () => implement$7,
|
|
208
|
-
make: () => make$
|
|
194
|
+
make: () => make$7
|
|
209
195
|
});
|
|
210
196
|
const makeDefinition$4 = (id, definition) => {
|
|
211
197
|
const queueDefinition = {
|
|
212
198
|
id,
|
|
213
199
|
message: definition.message
|
|
214
200
|
};
|
|
215
|
-
return Object.assign(queueDefinition, {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
}),
|
|
220
|
-
Binding: () => (bindingId, binding) => Service$4()(bindingId, {
|
|
221
|
-
...binding,
|
|
222
|
-
message: definition.message
|
|
223
|
-
}),
|
|
224
|
-
binding: (bindingId, binding) => Service$4()(bindingId, {
|
|
225
|
-
...binding,
|
|
226
|
-
message: definition.message
|
|
227
|
-
})
|
|
228
|
-
});
|
|
201
|
+
return Object.assign(queueDefinition, { make: (layer, options) => make$4(layer, {
|
|
202
|
+
...options,
|
|
203
|
+
queue: wrapHandler$1(queueDefinition, options.queue)
|
|
204
|
+
}) });
|
|
229
205
|
};
|
|
230
|
-
const make$
|
|
206
|
+
const make$7 = (id, definition) => Tag$8()(id, definition);
|
|
231
207
|
const Tag$8 = () => (id, definition) => {
|
|
232
208
|
const queueDefinition = makeDefinition$4(id, definition);
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
209
|
+
const tag = Context.Service()(id);
|
|
210
|
+
const layer = (binding) => layer$5(tag, {
|
|
211
|
+
...binding,
|
|
212
|
+
message: definition.message
|
|
213
|
+
});
|
|
214
|
+
const send = Effect.fnUntraced(function* (message, options) {
|
|
215
|
+
yield* (yield* tag).send(message, options);
|
|
216
|
+
});
|
|
217
|
+
const sendBatch = Effect.fnUntraced(function* (messages, options) {
|
|
218
|
+
yield* (yield* tag).sendBatch(messages, options);
|
|
219
|
+
});
|
|
220
|
+
const metrics = Effect.fnUntraced(function* () {
|
|
221
|
+
return yield* (yield* tag).metrics();
|
|
222
|
+
});
|
|
223
|
+
const unsafeRaw = Effect.fnUntraced(function* () {
|
|
224
|
+
return yield* (yield* tag).unsafeRaw;
|
|
225
|
+
});
|
|
226
|
+
return Object.assign(tag, {
|
|
227
|
+
id: queueDefinition.id,
|
|
228
|
+
message: queueDefinition.message,
|
|
229
|
+
make: queueDefinition.make,
|
|
230
|
+
layer,
|
|
231
|
+
send,
|
|
232
|
+
sendBatch,
|
|
233
|
+
metrics,
|
|
234
|
+
unsafeRaw
|
|
235
|
+
});
|
|
241
236
|
};
|
|
242
237
|
const Queue$1 = Tag$8;
|
|
243
238
|
const wrapHandler$1 = (definition, handler) => {
|
|
@@ -307,7 +302,7 @@ var RpcDefinition_exports = /* @__PURE__ */ __exportAll({
|
|
|
307
302
|
decodeSuccess: () => decodeSuccess,
|
|
308
303
|
encodeArgs: () => encodeArgs,
|
|
309
304
|
encodeSuccess: () => encodeSuccess,
|
|
310
|
-
make: () => make$
|
|
305
|
+
make: () => make$6,
|
|
311
306
|
method: () => method$4,
|
|
312
307
|
reservedMethodNames: () => reservedMethodNames$4
|
|
313
308
|
});
|
|
@@ -410,7 +405,7 @@ const decodeSuccess = (definition, methodName, value) => {
|
|
|
410
405
|
cause
|
|
411
406
|
})));
|
|
412
407
|
};
|
|
413
|
-
const make$
|
|
408
|
+
const make$6 = (id, methods) => {
|
|
414
409
|
const definition = {
|
|
415
410
|
id,
|
|
416
411
|
methods
|
|
@@ -464,11 +459,15 @@ const invokeRpcMethod = (target, method, args, makeError) => Effect.gen(function
|
|
|
464
459
|
//#endregion
|
|
465
460
|
//#region src/ServiceBinding.ts
|
|
466
461
|
var ServiceBinding_exports = /* @__PURE__ */ __exportAll({
|
|
467
|
-
Service: () => Service
|
|
462
|
+
Service: () => Service,
|
|
468
463
|
ServiceBindingFetchError: () => ServiceBindingFetchError,
|
|
469
|
-
ServiceBindingRpcError: () => ServiceBindingRpcError
|
|
464
|
+
ServiceBindingRpcError: () => ServiceBindingRpcError,
|
|
465
|
+
isServiceBindingClient: () => isServiceBindingClient,
|
|
466
|
+
layer: () => layer$4,
|
|
467
|
+
makeClient: () => makeClient$3,
|
|
468
|
+
makeDirectMethods: () => makeDirectMethods$1
|
|
470
469
|
});
|
|
471
|
-
const TypeId
|
|
470
|
+
const TypeId = "effect-cf/ServiceBinding";
|
|
472
471
|
/**
|
|
473
472
|
* Failure raised when calling `fetch` on a service binding.
|
|
474
473
|
*/
|
|
@@ -477,13 +476,66 @@ var ServiceBindingFetchError = class extends Data.TaggedError("ServiceBindingFet
|
|
|
477
476
|
* Failure raised when invoking an RPC method on a service binding.
|
|
478
477
|
*/
|
|
479
478
|
var ServiceBindingRpcError = class extends Data.TaggedError("ServiceBindingRpcError") {};
|
|
479
|
+
const isServiceBindingClient = (value) => typeof value === "object" && value !== null && typeof Reflect.get(value, "fetch") === "function";
|
|
480
|
+
const makeClient$3 = (definition) => {
|
|
481
|
+
return (service) => {
|
|
482
|
+
const fetch = (input, init) => Effect.tryPromise({
|
|
483
|
+
try: () => service.fetch(input, init),
|
|
484
|
+
catch: (cause) => new ServiceBindingFetchError({
|
|
485
|
+
binding: definition.binding,
|
|
486
|
+
cause
|
|
487
|
+
})
|
|
488
|
+
});
|
|
489
|
+
const rpc = (method, ...args) => Effect.gen(function* () {
|
|
490
|
+
const methodName = String(method);
|
|
491
|
+
return yield* invokeRpcMethod(service, method, definition.definition === void 0 ? args : yield* encodeArgs(definition.definition, methodName, args).pipe(Effect.mapError((cause) => new ServiceBindingRpcError({
|
|
492
|
+
binding: definition.binding,
|
|
493
|
+
method: methodName,
|
|
494
|
+
cause
|
|
495
|
+
}))), (cause) => new ServiceBindingRpcError({
|
|
496
|
+
binding: definition.binding,
|
|
497
|
+
method: methodName,
|
|
498
|
+
cause
|
|
499
|
+
}));
|
|
500
|
+
});
|
|
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({
|
|
504
|
+
binding: definition.binding,
|
|
505
|
+
method: methodName,
|
|
506
|
+
cause
|
|
507
|
+
})));
|
|
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({
|
|
512
|
+
binding: definition.binding,
|
|
513
|
+
method: methodName,
|
|
514
|
+
cause
|
|
515
|
+
}))));
|
|
516
|
+
});
|
|
517
|
+
const scopedCall = (method, ...args) => Effect.gen(function* () {
|
|
518
|
+
return yield* decodeSuccess$2(String(method), yield* scoped(yield* rpc(method, ...args)));
|
|
519
|
+
});
|
|
520
|
+
const directMethods = makeDirectMethods$1(definition.definition, call);
|
|
521
|
+
return Object.assign(directMethods, {
|
|
522
|
+
fetch,
|
|
523
|
+
rpc,
|
|
524
|
+
call,
|
|
525
|
+
scopedCall
|
|
526
|
+
});
|
|
527
|
+
};
|
|
528
|
+
};
|
|
529
|
+
const layer$4 = (tag, definition) => layer$6(tag, definition.binding, (value) => isServiceBindingClient(value), makeClient$3(definition));
|
|
480
530
|
/**
|
|
481
531
|
* Creates a typed Effect service for a Worker service binding.
|
|
482
532
|
*
|
|
483
533
|
* Returned value includes:
|
|
484
534
|
* - a Context tag for dependency injection
|
|
485
535
|
* - `fetch(...)` for raw HTTP forwarding
|
|
486
|
-
* - `
|
|
536
|
+
* - `rpc(...)` for raw Cloudflare RPC results
|
|
537
|
+
* - `call(...)` for resolved and decoded RPC results
|
|
538
|
+
* - `scopedCall(...)` for scoped and decoded disposable RPC results
|
|
487
539
|
* - direct RPC methods when `definition` is provided
|
|
488
540
|
*
|
|
489
541
|
* @example
|
|
@@ -495,59 +547,32 @@ var ServiceBindingRpcError = class extends Data.TaggedError("ServiceBindingRpcEr
|
|
|
495
547
|
* }),
|
|
496
548
|
* });
|
|
497
549
|
*
|
|
498
|
-
* const
|
|
550
|
+
* const CounterLive = Counter.layer({ binding: "COUNTER" });
|
|
499
551
|
*
|
|
500
552
|
* const program = Effect.gen(function* () {
|
|
501
|
-
* const
|
|
553
|
+
* const counter = yield* Counter;
|
|
554
|
+
* const next = yield* counter.increment(1);
|
|
502
555
|
* return next;
|
|
503
556
|
* });
|
|
504
557
|
* ```
|
|
505
558
|
*/
|
|
506
|
-
const Service
|
|
507
|
-
const tag = Service$
|
|
559
|
+
const Service = () => (id, definition) => {
|
|
560
|
+
const tag = Service$2()(id, definition.binding, (value) => isServiceBindingClient(value), makeClient$3(definition));
|
|
508
561
|
const fetch = (input, init) => Effect.gen(function* () {
|
|
509
|
-
|
|
510
|
-
return yield* Effect.tryPromise({
|
|
511
|
-
try: () => service.fetch(input, init),
|
|
512
|
-
catch: (cause) => new ServiceBindingFetchError({
|
|
513
|
-
binding: definition.binding,
|
|
514
|
-
cause
|
|
515
|
-
})
|
|
516
|
-
});
|
|
562
|
+
return yield* (yield* tag).fetch(input, init);
|
|
517
563
|
});
|
|
518
564
|
const rpc = (method, ...args) => Effect.gen(function* () {
|
|
519
|
-
|
|
520
|
-
const methodName = String(method);
|
|
521
|
-
return yield* invokeRpcMethod(service, method, definition.definition === void 0 ? args : yield* encodeArgs(definition.definition, methodName, args).pipe(Effect.mapError((cause) => new ServiceBindingRpcError({
|
|
522
|
-
binding: definition.binding,
|
|
523
|
-
method: methodName,
|
|
524
|
-
cause
|
|
525
|
-
}))), (cause) => new ServiceBindingRpcError({
|
|
526
|
-
binding: definition.binding,
|
|
527
|
-
method: methodName,
|
|
528
|
-
cause
|
|
529
|
-
}));
|
|
565
|
+
return yield* (yield* tag).rpc(method, ...args);
|
|
530
566
|
});
|
|
531
567
|
const call = (method, ...args) => Effect.gen(function* () {
|
|
532
|
-
|
|
533
|
-
const value = yield* resolve(yield* rpc(method, ...args)).pipe(Effect.mapError((cause) => new ServiceBindingRpcError({
|
|
534
|
-
binding: definition.binding,
|
|
535
|
-
method: methodName,
|
|
536
|
-
cause
|
|
537
|
-
})));
|
|
538
|
-
if (definition.definition === void 0) return value;
|
|
539
|
-
return yield* decodeSuccess(definition.definition, methodName, value).pipe(Effect.mapError((cause) => new ServiceBindingRpcError({
|
|
540
|
-
binding: definition.binding,
|
|
541
|
-
method: methodName,
|
|
542
|
-
cause
|
|
543
|
-
})));
|
|
568
|
+
return yield* (yield* tag).call(method, ...args);
|
|
544
569
|
});
|
|
545
570
|
const scopedCall = (method, ...args) => Effect.gen(function* () {
|
|
546
|
-
return yield*
|
|
571
|
+
return yield* (yield* tag).scopedCall(method, ...args);
|
|
547
572
|
});
|
|
548
573
|
const directMethods = makeDirectMethods$1(definition.definition, call);
|
|
549
574
|
return Object.assign(tag, directMethods, {
|
|
550
|
-
[TypeId
|
|
575
|
+
[TypeId]: TypeId,
|
|
551
576
|
definition,
|
|
552
577
|
fetch,
|
|
553
578
|
rpc,
|
|
@@ -566,7 +591,7 @@ var WorkerDefinition_exports = /* @__PURE__ */ __exportAll({
|
|
|
566
591
|
Tag: () => Tag$6,
|
|
567
592
|
Worker: () => Worker,
|
|
568
593
|
implement: () => implement$5,
|
|
569
|
-
make: () => make$
|
|
594
|
+
make: () => make$5,
|
|
570
595
|
method: () => method$3
|
|
571
596
|
});
|
|
572
597
|
const reservedMethodNames$3 = new Set([
|
|
@@ -604,33 +629,44 @@ const method$3 = method$4;
|
|
|
604
629
|
*/
|
|
605
630
|
const makeDefinition$3 = (id, methods) => {
|
|
606
631
|
assertNoReservedMethods("Worker", methods, reservedMethodNames$3);
|
|
607
|
-
const definition = make$
|
|
608
|
-
return Object.assign(definition, {
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
}),
|
|
613
|
-
Binding: () => (bindingId, binding) => Service$3()(bindingId, {
|
|
614
|
-
...binding,
|
|
615
|
-
definition
|
|
616
|
-
}),
|
|
617
|
-
binding: (bindingId, binding) => Service$3()(bindingId, {
|
|
618
|
-
...binding,
|
|
619
|
-
definition
|
|
620
|
-
})
|
|
621
|
-
});
|
|
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
|
+
}) });
|
|
622
637
|
};
|
|
623
|
-
const make$
|
|
638
|
+
const make$5 = (id, methods) => Tag$6()(id, methods);
|
|
624
639
|
const Tag$6 = () => (id, methods) => {
|
|
625
640
|
const definition = makeDefinition$3(id, methods);
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
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
|
+
});
|
|
634
670
|
};
|
|
635
671
|
const Worker = Tag$6;
|
|
636
672
|
const wrapHandlers$1 = (definition, handlers) => {
|
|
@@ -692,7 +728,7 @@ var Worker_exports = /* @__PURE__ */ __exportAll({
|
|
|
692
728
|
WorkerContext: () => WorkerContext,
|
|
693
729
|
implement: () => implement$4,
|
|
694
730
|
isWebSocketUpgrade: () => isWebSocketUpgrade,
|
|
695
|
-
make: () => make$
|
|
731
|
+
make: () => make$4,
|
|
696
732
|
makeFetchHandler: () => makeFetchHandler,
|
|
697
733
|
method: () => method$2,
|
|
698
734
|
renderHttpResponse: () => renderHttpResponse
|
|
@@ -721,7 +757,7 @@ const RunSymbol$1 = Symbol.for("effect-cf/Worker/run");
|
|
|
721
757
|
const renderHttpResponse = (effect) => Effect.flatMap(effect, (response) => Effect.map(Effect.context(), (context) => HttpServerResponse.toWeb(response, { context })));
|
|
722
758
|
const renderFetchSuccess = (effect) => Effect.flatMap(effect, (response) => response instanceof Response ? Effect.succeed(response) : Effect.map(Effect.context(), (context) => HttpServerResponse.toWeb(response, { context })));
|
|
723
759
|
const isWorkerOptions = (options) => typeof options === "object" && options !== null && ("fetch" in options || "queue" in options || "rpc" in options);
|
|
724
|
-
function make$
|
|
760
|
+
function make$4(layer, optionsOrFetch) {
|
|
725
761
|
const options = isWorkerOptions(optionsOrFetch) ? optionsOrFetch : { fetch: optionsOrFetch };
|
|
726
762
|
class EffectWorker extends WorkerEntrypoint {
|
|
727
763
|
runtime;
|
|
@@ -752,7 +788,7 @@ function make$6(layer, optionsOrFetch) {
|
|
|
752
788
|
return assumeEntrypointClass(EffectWorker);
|
|
753
789
|
}
|
|
754
790
|
const makeFetchHandler = (layer, options) => {
|
|
755
|
-
const WorkerClass = make$
|
|
791
|
+
const WorkerClass = make$4(layer, options);
|
|
756
792
|
return { fetch: (request, env, ctx) => Promise.resolve(new WorkerClass(ctx, env).fetch(request)) };
|
|
757
793
|
};
|
|
758
794
|
const Tag$5 = Tag$6;
|
|
@@ -1052,9 +1088,11 @@ const runPromiseExitPreservingTypedFailures = async (effect) => {
|
|
|
1052
1088
|
var DurableObjectNamespace_exports = /* @__PURE__ */ __exportAll({
|
|
1053
1089
|
DurableObjectFetchError: () => DurableObjectFetchError,
|
|
1054
1090
|
DurableObjectRpcError: () => DurableObjectRpcError,
|
|
1055
|
-
|
|
1091
|
+
isDurableObjectNamespaceClient: () => isDurableObjectNamespaceClient,
|
|
1092
|
+
layer: () => layer$3,
|
|
1093
|
+
makeClient: () => makeClient$2,
|
|
1094
|
+
makeDirectMethods: () => makeDirectMethods
|
|
1056
1095
|
});
|
|
1057
|
-
const TypeId$2 = "effect-cf/DurableObjectNamespace";
|
|
1058
1096
|
/**
|
|
1059
1097
|
* Failure raised when invoking an RPC method on a Durable Object stub.
|
|
1060
1098
|
*/
|
|
@@ -1063,108 +1101,76 @@ var DurableObjectRpcError = class extends Data.TaggedError("DurableObjectRpcErro
|
|
|
1063
1101
|
* Failure raised when forwarding a request to a Durable Object stub.
|
|
1064
1102
|
*/
|
|
1065
1103
|
var DurableObjectFetchError = class extends Data.TaggedError("DurableObjectFetchError") {};
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
*
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
return
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
method: methodName,
|
|
1135
|
-
cause
|
|
1136
|
-
})));
|
|
1137
|
-
if (definition.definition === void 0) return value;
|
|
1138
|
-
return yield* decodeSuccess(definition.definition, methodName, value).pipe(Effect.mapError((cause) => new DurableObjectRpcError({
|
|
1139
|
-
binding: definition.binding,
|
|
1140
|
-
method: methodName,
|
|
1141
|
-
cause
|
|
1142
|
-
})));
|
|
1143
|
-
});
|
|
1144
|
-
const scopedCall = (stub, method, ...args) => Effect.gen(function* () {
|
|
1145
|
-
return yield* scoped(yield* rpc(stub, method, ...args));
|
|
1146
|
-
});
|
|
1147
|
-
const directMethods = makeDirectMethods(definition.definition, {
|
|
1148
|
-
call,
|
|
1149
|
-
fetch,
|
|
1150
|
-
get,
|
|
1151
|
-
getByName
|
|
1152
|
-
});
|
|
1153
|
-
return Object.assign(tag, directMethods, {
|
|
1154
|
-
[TypeId$2]: TypeId$2,
|
|
1155
|
-
definition,
|
|
1156
|
-
newUniqueId,
|
|
1157
|
-
idFromName,
|
|
1158
|
-
idFromString,
|
|
1159
|
-
get,
|
|
1160
|
-
getByName,
|
|
1161
|
-
jurisdiction,
|
|
1162
|
-
fetch,
|
|
1163
|
-
rpc,
|
|
1164
|
-
call,
|
|
1165
|
-
scopedCall
|
|
1166
|
-
});
|
|
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) => {
|
|
1108
|
+
const newUniqueId = (options) => Effect.sync(() => namespace.newUniqueId(options));
|
|
1109
|
+
const idFromName = (name) => Effect.sync(() => namespace.idFromName(name));
|
|
1110
|
+
const idFromString = (id) => Effect.sync(() => namespace.idFromString(id));
|
|
1111
|
+
const get = (id, options) => Effect.sync(() => namespace.get(id, options));
|
|
1112
|
+
const getByName = (name, options) => Effect.sync(() => namespace.getByName(name, options));
|
|
1113
|
+
const jurisdiction = (value) => Effect.sync(() => namespace.jurisdiction(value));
|
|
1114
|
+
const fetch = (stub, input, init) => Effect.tryPromise({
|
|
1115
|
+
try: () => stub.fetch(input, init),
|
|
1116
|
+
catch: (cause) => new DurableObjectFetchError({
|
|
1117
|
+
binding: definition.binding,
|
|
1118
|
+
cause
|
|
1119
|
+
})
|
|
1120
|
+
});
|
|
1121
|
+
const rpc = (stub, method, ...args) => Effect.gen(function* () {
|
|
1122
|
+
const methodName = String(method);
|
|
1123
|
+
return yield* invokeRpcMethod(stub, method, definition.definition === void 0 ? args : yield* encodeArgs(definition.definition, methodName, args).pipe(Effect.mapError((cause) => new DurableObjectRpcError({
|
|
1124
|
+
binding: definition.binding,
|
|
1125
|
+
method: methodName,
|
|
1126
|
+
cause
|
|
1127
|
+
}))), (cause) => new DurableObjectRpcError({
|
|
1128
|
+
binding: definition.binding,
|
|
1129
|
+
method: methodName,
|
|
1130
|
+
cause
|
|
1131
|
+
}));
|
|
1132
|
+
});
|
|
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({
|
|
1136
|
+
binding: definition.binding,
|
|
1137
|
+
method: methodName,
|
|
1138
|
+
cause
|
|
1139
|
+
})));
|
|
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({
|
|
1144
|
+
binding: definition.binding,
|
|
1145
|
+
method: methodName,
|
|
1146
|
+
cause
|
|
1147
|
+
}))));
|
|
1148
|
+
});
|
|
1149
|
+
const scopedCall = (stub, method, ...args) => Effect.gen(function* () {
|
|
1150
|
+
return yield* decodeSuccess$1(String(method), yield* scoped(yield* rpc(stub, method, ...args)));
|
|
1151
|
+
});
|
|
1152
|
+
const directMethods = makeDirectMethods(definition.definition, {
|
|
1153
|
+
call,
|
|
1154
|
+
fetch,
|
|
1155
|
+
get,
|
|
1156
|
+
getByName
|
|
1157
|
+
});
|
|
1158
|
+
return Object.assign(directMethods, {
|
|
1159
|
+
newUniqueId,
|
|
1160
|
+
idFromName,
|
|
1161
|
+
idFromString,
|
|
1162
|
+
get,
|
|
1163
|
+
getByName,
|
|
1164
|
+
jurisdiction,
|
|
1165
|
+
fetch,
|
|
1166
|
+
rpc,
|
|
1167
|
+
call,
|
|
1168
|
+
scopedCall,
|
|
1169
|
+
unsafeRaw: Effect.succeed(namespace)
|
|
1170
|
+
});
|
|
1171
|
+
};
|
|
1167
1172
|
};
|
|
1173
|
+
const layer$3 = (tag, definition) => layer$6(tag, definition.binding, (value) => isDurableObjectNamespaceClient(value), makeClient$2(definition));
|
|
1168
1174
|
const makeDirectMethods = (rpcDefinition, helpers) => {
|
|
1169
1175
|
const methods = {};
|
|
1170
1176
|
if (rpcDefinition !== void 0) {
|
|
@@ -1191,7 +1197,7 @@ var DurableObjectDefinition_exports = /* @__PURE__ */ __exportAll({
|
|
|
1191
1197
|
DurableObject: () => DurableObject$1,
|
|
1192
1198
|
Tag: () => Tag$4,
|
|
1193
1199
|
implement: () => implement$3,
|
|
1194
|
-
make: () => make$
|
|
1200
|
+
make: () => make$3,
|
|
1195
1201
|
method: () => method$1
|
|
1196
1202
|
});
|
|
1197
1203
|
const reservedMethodNames$1 = new Set([
|
|
@@ -1222,33 +1228,77 @@ const method$1 = method$4;
|
|
|
1222
1228
|
*/
|
|
1223
1229
|
const makeDefinition$2 = (id, methods) => {
|
|
1224
1230
|
assertNoReservedMethods("Durable Object", methods, reservedMethodNames$1);
|
|
1225
|
-
const definition = make$
|
|
1226
|
-
return Object.assign(definition, {
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
}),
|
|
1231
|
-
Namespace: () => (bindingId, binding) => Service$2()(bindingId, {
|
|
1232
|
-
...binding,
|
|
1233
|
-
definition
|
|
1234
|
-
}),
|
|
1235
|
-
namespace: (bindingId, binding) => Service$2()(bindingId, {
|
|
1236
|
-
...binding,
|
|
1237
|
-
definition
|
|
1238
|
-
})
|
|
1239
|
-
});
|
|
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
|
+
}) });
|
|
1240
1236
|
};
|
|
1241
|
-
const make$
|
|
1237
|
+
const make$3 = (id, methods) => Tag$4()(id, methods);
|
|
1242
1238
|
const Tag$4 = () => (id, methods) => {
|
|
1243
1239
|
const definition = makeDefinition$2(id, methods);
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
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
|
+
});
|
|
1252
1302
|
};
|
|
1253
1303
|
const DurableObject$1 = Tag$4;
|
|
1254
1304
|
const wrapHandlers = (definition, handlers) => {
|
|
@@ -1270,7 +1320,7 @@ const implement$3 = (_definition, handlers) => handlers;
|
|
|
1270
1320
|
var DurableObject_exports = /* @__PURE__ */ __exportAll({
|
|
1271
1321
|
Tag: () => Tag$3,
|
|
1272
1322
|
implement: () => implement$2,
|
|
1273
|
-
make: () => make$
|
|
1323
|
+
make: () => make$2,
|
|
1274
1324
|
method: () => method
|
|
1275
1325
|
});
|
|
1276
1326
|
const reservedMethodNames = new Set([
|
|
@@ -1286,7 +1336,7 @@ const RunSymbol = Symbol.for("effect-cf/DurableObject/run");
|
|
|
1286
1336
|
/**
|
|
1287
1337
|
* Creates a Durable Object class backed by a single managed Effect runtime.
|
|
1288
1338
|
*/
|
|
1289
|
-
const make$
|
|
1339
|
+
const make$2 = (layer, options = {}) => {
|
|
1290
1340
|
class EffectDurableObject extends DurableObject {
|
|
1291
1341
|
runtime;
|
|
1292
1342
|
constructor(state, env) {
|
|
@@ -1654,7 +1704,7 @@ var DurableObjectAlarm = class DurableObjectAlarm extends Context.Service()("eff
|
|
|
1654
1704
|
//#region src/DurableObjectRpcWebSocket.ts
|
|
1655
1705
|
var DurableObjectRpcWebSocket_exports = /* @__PURE__ */ __exportAll({
|
|
1656
1706
|
DurableObjectRpcWebSocket: () => DurableObjectRpcWebSocket,
|
|
1657
|
-
layer: () => layer
|
|
1707
|
+
layer: () => layer$2
|
|
1658
1708
|
});
|
|
1659
1709
|
const defaultAttachmentKey = "effectCloudflareRpcClientId";
|
|
1660
1710
|
const defaultTag = "effect-cf-rpc";
|
|
@@ -1665,7 +1715,7 @@ var DurableObjectRpcWebSocket = class extends Context.Service()("effect-cf/Durab
|
|
|
1665
1715
|
/**
|
|
1666
1716
|
* Builds a layer that bridges Durable Object websocket events to `RpcServer.Protocol`.
|
|
1667
1717
|
*/
|
|
1668
|
-
const layer = (options = {}) => Layer.effectContext(Effect.gen(function* () {
|
|
1718
|
+
const layer$2 = (options = {}) => Layer.effectContext(Effect.gen(function* () {
|
|
1669
1719
|
const tag = options.tag ?? defaultTag;
|
|
1670
1720
|
const attachmentKey = options.attachmentKey ?? defaultAttachmentKey;
|
|
1671
1721
|
const durableObjectState = yield* DurableObjectState;
|
|
@@ -1780,11 +1830,11 @@ const writeAttachment = (socket, key, clientId) => {
|
|
|
1780
1830
|
//#region src/Kv.ts
|
|
1781
1831
|
var Kv_exports = /* @__PURE__ */ __exportAll({
|
|
1782
1832
|
KvOperationError: () => KvOperationError,
|
|
1783
|
-
Service: () => Service$1,
|
|
1784
1833
|
Tag: () => Tag$2,
|
|
1785
|
-
|
|
1834
|
+
isKvNamespace: () => isKvNamespace,
|
|
1835
|
+
layer: () => layer$1,
|
|
1836
|
+
makeClient: () => makeClient$1
|
|
1786
1837
|
});
|
|
1787
|
-
const TypeId$1 = "effect-cf/Kv";
|
|
1788
1838
|
/** Error raised when a KV operation fails. */
|
|
1789
1839
|
var KvOperationError = class extends Data.TaggedError("KvOperationError") {};
|
|
1790
1840
|
const maybeString = (value) => value == null ? Option.none() : Option.some(value);
|
|
@@ -1798,128 +1848,108 @@ const tryKvPromise = (binding, operation, evaluate) => Effect.tryPromise({
|
|
|
1798
1848
|
try: evaluate,
|
|
1799
1849
|
catch: (cause) => kvError(binding, operation, cause)
|
|
1800
1850
|
});
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
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";
|
|
1855
|
+
};
|
|
1856
|
+
const makeClient$1 = (definition) => {
|
|
1857
|
+
const encodeKey = Schema.encodeEffect(definition.key);
|
|
1858
|
+
const decodeKey = Schema.decodeUnknownEffect(definition.key);
|
|
1859
|
+
const encodeValue = Schema.encodeEffect(Schema.fromJsonString(Schema.toCodecJson(definition.value)));
|
|
1860
|
+
const decodeValue = Schema.decodeUnknownEffect(Schema.fromJsonString(Schema.toCodecJson(definition.value)));
|
|
1861
|
+
return (kv) => ({
|
|
1862
|
+
definition,
|
|
1863
|
+
put: Effect.fnUntraced(function* (key, value, options) {
|
|
1864
|
+
const keyEncoded = yield* encodeKey(key);
|
|
1865
|
+
const valueEncoded = yield* encodeValue(value);
|
|
1866
|
+
yield* tryKvPromise(definition.binding, "put", () => kv.put(keyEncoded, valueEncoded, options));
|
|
1867
|
+
}),
|
|
1868
|
+
get: Effect.fnUntraced(function* (key) {
|
|
1869
|
+
const keyEncoded = yield* encodeKey(key);
|
|
1870
|
+
const valueEncoded = yield* tryKvPromise(definition.binding, "get", () => kv.get(keyEncoded));
|
|
1871
|
+
if (valueEncoded === null) return Option.none();
|
|
1872
|
+
return yield* decodeValue(valueEncoded).pipe(Effect.map(Option.some));
|
|
1873
|
+
}),
|
|
1874
|
+
getWithMetadata: Effect.fnUntraced(function* (key, metadataSchema) {
|
|
1875
|
+
const keyEncoded = yield* encodeKey(key);
|
|
1876
|
+
const result = yield* tryKvPromise(definition.binding, "getWithMetadata", () => kv.getWithMetadata(keyEncoded));
|
|
1877
|
+
if (result.value === null) return Option.none();
|
|
1878
|
+
const value = yield* decodeValue(result.value);
|
|
1879
|
+
const metadata = result.metadata === null ? Option.none() : Option.some(yield* Schema.decodeUnknownEffect(metadataSchema)(result.metadata));
|
|
1880
|
+
return Option.some({
|
|
1881
|
+
value,
|
|
1882
|
+
metadata,
|
|
1883
|
+
cacheStatus: maybeString(result.cacheStatus)
|
|
1884
|
+
});
|
|
1885
|
+
}),
|
|
1886
|
+
list: Effect.fnUntraced(function* (options) {
|
|
1887
|
+
const { metadataSchema, ...kvOptions } = options ?? {};
|
|
1888
|
+
const result = yield* tryKvPromise(definition.binding, "list", () => kv.list(kvOptions));
|
|
1889
|
+
const keys = [];
|
|
1890
|
+
for (const key of result.keys) {
|
|
1891
|
+
const decodedName = yield* decodeKey(key.name);
|
|
1892
|
+
const decodedMetadata = key.metadata === void 0 ? Option.none() : metadataSchema === void 0 ? Option.some(key.metadata) : Option.some(yield* Schema.decodeUnknownEffect(metadataSchema)(key.metadata));
|
|
1893
|
+
keys.push({
|
|
1894
|
+
name: decodedName,
|
|
1895
|
+
expiration: maybeNumber(key.expiration),
|
|
1896
|
+
metadata: decodedMetadata
|
|
1897
|
+
});
|
|
1898
|
+
}
|
|
1899
|
+
return {
|
|
1900
|
+
keys,
|
|
1901
|
+
listComplete: result.list_complete,
|
|
1902
|
+
cursor: maybeString("cursor" in result ? result.cursor : void 0),
|
|
1903
|
+
cacheStatus: maybeString(result.cacheStatus)
|
|
1904
|
+
};
|
|
1905
|
+
}),
|
|
1906
|
+
remove: Effect.fnUntraced(function* (key) {
|
|
1907
|
+
const keyEncoded = yield* encodeKey(key);
|
|
1908
|
+
yield* tryKvPromise(definition.binding, "delete", () => kv.delete(keyEncoded));
|
|
1909
|
+
}),
|
|
1910
|
+
unsafeRaw: Effect.succeed(kv)
|
|
1911
|
+
});
|
|
1912
|
+
};
|
|
1913
|
+
const layer$1 = (tag, definition) => layer$6(tag, definition.binding, isKvNamespace, makeClient$1(definition));
|
|
1805
1914
|
const makeDefinition$1 = (id, definition) => {
|
|
1806
1915
|
const kvDefinition = {
|
|
1807
1916
|
id,
|
|
1808
1917
|
key: definition.key,
|
|
1809
1918
|
value: definition.value
|
|
1810
1919
|
};
|
|
1811
|
-
return Object.assign(kvDefinition, {
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
}),
|
|
1817
|
-
binding: (bindingId, binding) => Service$1()(bindingId, {
|
|
1818
|
-
...binding,
|
|
1819
|
-
key: definition.key,
|
|
1820
|
-
value: definition.value
|
|
1821
|
-
})
|
|
1822
|
-
});
|
|
1920
|
+
return Object.assign(kvDefinition, { layer: (tag, binding) => layer$1(tag, {
|
|
1921
|
+
...binding,
|
|
1922
|
+
key: definition.key,
|
|
1923
|
+
value: definition.value
|
|
1924
|
+
}) });
|
|
1823
1925
|
};
|
|
1824
1926
|
const Tag$2 = () => (id, definition) => {
|
|
1825
1927
|
const kvDefinition = makeDefinition$1(id, definition);
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
static key = kvDefinition.key;
|
|
1829
|
-
static value = kvDefinition.value;
|
|
1830
|
-
static Binding = kvDefinition.Binding;
|
|
1831
|
-
static binding = kvDefinition.binding;
|
|
1832
|
-
}
|
|
1833
|
-
return KvDefinitionClass;
|
|
1834
|
-
};
|
|
1835
|
-
/**
|
|
1836
|
-
* Builds a KV service around a Cloudflare KV namespace binding.
|
|
1837
|
-
*
|
|
1838
|
-
* Returned service includes schema-aware `put`, `get`, `getWithMetadata`,
|
|
1839
|
-
* `list`, and `remove` helpers.
|
|
1840
|
-
*
|
|
1841
|
-
* @example
|
|
1842
|
-
* ```ts
|
|
1843
|
-
* const Sessions = Kv.make("Sessions", {
|
|
1844
|
-
* binding: "SESSIONS",
|
|
1845
|
-
* key: Schema.String,
|
|
1846
|
-
* value: Schema.Struct({ userId: Schema.String }),
|
|
1847
|
-
* });
|
|
1848
|
-
*
|
|
1849
|
-
* const program = Effect.gen(function* () {
|
|
1850
|
-
* yield* Sessions.put("abc", { userId: "u_1" });
|
|
1851
|
-
* return yield* Sessions.get("abc");
|
|
1852
|
-
* });
|
|
1853
|
-
* ```
|
|
1854
|
-
*/
|
|
1855
|
-
const Service$1 = () => (id, definition) => {
|
|
1856
|
-
const tag = Service$6()(id, definition.binding, (value) => {
|
|
1857
|
-
if (typeof value !== "object" || value === null) return false;
|
|
1858
|
-
const resource = value;
|
|
1859
|
-
return typeof resource.get === "function" && typeof resource.put === "function" && typeof resource.delete === "function" && typeof resource.getWithMetadata === "function" && typeof resource.list === "function";
|
|
1860
|
-
});
|
|
1861
|
-
const encodeKey = Schema.encodeEffect(definition.key);
|
|
1862
|
-
const decodeKey = Schema.decodeUnknownEffect(definition.key);
|
|
1863
|
-
const encodeValue = Schema.encodeEffect(Schema.fromJsonString(Schema.toCodecJson(definition.value)));
|
|
1864
|
-
const decodeValue = Schema.decodeUnknownEffect(Schema.fromJsonString(Schema.toCodecJson(definition.value)));
|
|
1928
|
+
const tag = Context.Service()(id);
|
|
1929
|
+
const makeLayer = (binding) => kvDefinition.layer(tag, binding);
|
|
1865
1930
|
const put = Effect.fnUntraced(function* (key, value, options) {
|
|
1866
|
-
|
|
1867
|
-
const keyEncoded = yield* encodeKey(key);
|
|
1868
|
-
const valueEncoded = yield* encodeValue(value);
|
|
1869
|
-
yield* tryKvPromise(definition.binding, "put", () => kv.put(keyEncoded, valueEncoded, options));
|
|
1931
|
+
yield* (yield* tag).put(key, value, options);
|
|
1870
1932
|
});
|
|
1871
1933
|
const get = Effect.fnUntraced(function* (key) {
|
|
1872
|
-
|
|
1873
|
-
const keyEncoded = yield* encodeKey(key);
|
|
1874
|
-
const valueEncoded = yield* tryKvPromise(definition.binding, "get", () => kv.get(keyEncoded));
|
|
1875
|
-
if (valueEncoded === null) return Option.none();
|
|
1876
|
-
return yield* decodeValue(valueEncoded).pipe(Effect.map(Option.some));
|
|
1934
|
+
return yield* (yield* tag).get(key);
|
|
1877
1935
|
});
|
|
1878
1936
|
const getWithMetadata = Effect.fnUntraced(function* (key, metadataSchema) {
|
|
1879
|
-
|
|
1880
|
-
const keyEncoded = yield* encodeKey(key);
|
|
1881
|
-
const result = yield* tryKvPromise(definition.binding, "getWithMetadata", () => kv.getWithMetadata(keyEncoded));
|
|
1882
|
-
if (result.value === null) return Option.none();
|
|
1883
|
-
const value = yield* decodeValue(result.value);
|
|
1884
|
-
const metadata = result.metadata === null ? Option.none() : Option.some(yield* Schema.decodeUnknownEffect(metadataSchema)(result.metadata));
|
|
1885
|
-
return Option.some({
|
|
1886
|
-
value,
|
|
1887
|
-
metadata,
|
|
1888
|
-
cacheStatus: maybeString(result.cacheStatus)
|
|
1889
|
-
});
|
|
1937
|
+
return yield* (yield* tag).getWithMetadata(key, metadataSchema);
|
|
1890
1938
|
});
|
|
1891
1939
|
const list = Effect.fnUntraced(function* (options) {
|
|
1892
|
-
|
|
1893
|
-
const { metadataSchema, ...kvOptions } = options ?? {};
|
|
1894
|
-
const result = yield* tryKvPromise(definition.binding, "list", () => kv.list(kvOptions));
|
|
1895
|
-
const keys = [];
|
|
1896
|
-
for (const key of result.keys) {
|
|
1897
|
-
const decodedName = yield* decodeKey(key.name);
|
|
1898
|
-
const decodedMetadata = key.metadata === void 0 ? Option.none() : metadataSchema === void 0 ? Option.some(key.metadata) : Option.some(yield* Schema.decodeUnknownEffect(metadataSchema)(key.metadata));
|
|
1899
|
-
keys.push({
|
|
1900
|
-
name: decodedName,
|
|
1901
|
-
expiration: maybeNumber(key.expiration),
|
|
1902
|
-
metadata: decodedMetadata
|
|
1903
|
-
});
|
|
1904
|
-
}
|
|
1905
|
-
return {
|
|
1906
|
-
keys,
|
|
1907
|
-
listComplete: result.list_complete,
|
|
1908
|
-
cursor: maybeString("cursor" in result ? result.cursor : void 0),
|
|
1909
|
-
cacheStatus: maybeString(result.cacheStatus)
|
|
1910
|
-
};
|
|
1940
|
+
return yield* (yield* tag).list(options);
|
|
1911
1941
|
});
|
|
1912
1942
|
const remove = Effect.fnUntraced(function* (key) {
|
|
1913
|
-
|
|
1914
|
-
const keyEncoded = yield* encodeKey(key);
|
|
1915
|
-
yield* tryKvPromise(definition.binding, "delete", () => kv.delete(keyEncoded));
|
|
1943
|
+
yield* (yield* tag).remove(key);
|
|
1916
1944
|
});
|
|
1917
1945
|
const unsafeRaw = Effect.fnUntraced(function* () {
|
|
1918
|
-
return yield* tag;
|
|
1946
|
+
return yield* (yield* tag).unsafeRaw;
|
|
1919
1947
|
});
|
|
1920
1948
|
return Object.assign(tag, {
|
|
1921
|
-
|
|
1922
|
-
|
|
1949
|
+
id: kvDefinition.id,
|
|
1950
|
+
keySchema: kvDefinition.key,
|
|
1951
|
+
valueSchema: kvDefinition.value,
|
|
1952
|
+
layer: makeLayer,
|
|
1923
1953
|
put,
|
|
1924
1954
|
get,
|
|
1925
1955
|
getWithMetadata,
|
|
@@ -1931,12 +1961,12 @@ const Service$1 = () => (id, definition) => {
|
|
|
1931
1961
|
//#endregion
|
|
1932
1962
|
//#region src/WorkflowBinding.ts
|
|
1933
1963
|
var WorkflowBinding_exports = /* @__PURE__ */ __exportAll({
|
|
1934
|
-
Service: () => Service,
|
|
1935
1964
|
WorkflowOperationError: () => WorkflowOperationError,
|
|
1936
1965
|
WorkflowResultDecodeError: () => WorkflowResultDecodeError,
|
|
1937
|
-
|
|
1966
|
+
isWorkflow: () => isWorkflow,
|
|
1967
|
+
layer: () => layer,
|
|
1968
|
+
makeClient: () => makeClient
|
|
1938
1969
|
});
|
|
1939
|
-
const TypeId = "effect-cf/WorkflowBinding";
|
|
1940
1970
|
var WorkflowOperationError = class extends Data.TaggedError("WorkflowOperationError") {};
|
|
1941
1971
|
var WorkflowResultDecodeError = class extends Data.TaggedError("WorkflowResultDecodeError") {};
|
|
1942
1972
|
const workflowError = (binding, operation, cause) => new WorkflowOperationError({
|
|
@@ -1953,9 +1983,7 @@ const isWorkflow = (value) => {
|
|
|
1953
1983
|
const resource = value;
|
|
1954
1984
|
return typeof resource.create === "function" && typeof resource.createBatch === "function" && typeof resource.get === "function";
|
|
1955
1985
|
};
|
|
1956
|
-
const
|
|
1957
|
-
const Service = () => (id, definition) => {
|
|
1958
|
-
const tag = Service$6()(id, definition.binding, (value) => isWorkflow(value));
|
|
1986
|
+
const makeClient = (definition) => {
|
|
1959
1987
|
const encodePayload = Schema.encodeEffect(definition.payload);
|
|
1960
1988
|
const decodeResult = Schema.decodeUnknownEffect(definition.result);
|
|
1961
1989
|
const wrapInstance = (raw) => {
|
|
@@ -1982,38 +2010,30 @@ const Service = () => (id, definition) => {
|
|
|
1982
2010
|
sendEvent: (event) => operation("sendEvent", () => raw.sendEvent(event))
|
|
1983
2011
|
};
|
|
1984
2012
|
};
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
...options,
|
|
1990
|
-
params: encoded
|
|
1991
|
-
})));
|
|
1992
|
-
});
|
|
1993
|
-
const createBatch = Effect.fnUntraced(function* (batch) {
|
|
1994
|
-
const workflow = yield* tag;
|
|
1995
|
-
const encodedBatch = [];
|
|
1996
|
-
for (const item of batch) {
|
|
1997
|
-
const { payload, ...options } = item;
|
|
1998
|
-
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({
|
|
1999
2017
|
...options,
|
|
2000
|
-
params:
|
|
2001
|
-
});
|
|
2002
|
-
}
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
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)
|
|
2015
2034
|
});
|
|
2016
2035
|
};
|
|
2036
|
+
const layer = (tag, definition) => layer$6(tag, definition.binding, (value) => isWorkflow(value), makeClient(definition));
|
|
2017
2037
|
//#endregion
|
|
2018
2038
|
//#region src/WorkflowDefinition.ts
|
|
2019
2039
|
var WorkflowDefinition_exports = /* @__PURE__ */ __exportAll({
|
|
@@ -2028,32 +2048,40 @@ const makeDefinition = (id, definition) => {
|
|
|
2028
2048
|
payload: definition.payload,
|
|
2029
2049
|
result: definition.result
|
|
2030
2050
|
};
|
|
2031
|
-
return Object.assign(workflowDefinition, {
|
|
2032
|
-
make: (layer, options) => make(layer, { run: wrapHandler(workflowDefinition, options.run) }),
|
|
2033
|
-
Binding: () => (bindingId, binding) => Service()(bindingId, {
|
|
2034
|
-
...binding,
|
|
2035
|
-
payload: definition.payload,
|
|
2036
|
-
result: definition.result
|
|
2037
|
-
}),
|
|
2038
|
-
binding: (bindingId, binding) => Service()(bindingId, {
|
|
2039
|
-
...binding,
|
|
2040
|
-
payload: definition.payload,
|
|
2041
|
-
result: definition.result
|
|
2042
|
-
})
|
|
2043
|
-
});
|
|
2051
|
+
return Object.assign(workflowDefinition, { make: (layer, options) => make(layer, { run: wrapHandler(workflowDefinition, options.run) }) });
|
|
2044
2052
|
};
|
|
2045
|
-
const make$1 =
|
|
2053
|
+
const make$1 = (id, definition) => Tag$1()(id, definition);
|
|
2046
2054
|
const Tag$1 = () => (id, definition) => {
|
|
2047
2055
|
const workflowDefinition = makeDefinition(id, definition);
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
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
|
+
});
|
|
2057
2085
|
};
|
|
2058
2086
|
const Workflow = Tag$1;
|
|
2059
2087
|
const wrapHandler = (definition, handler) => {
|