@effect-agent/platform-cloudflare 0.1.0-beta.50 → 0.1.0-beta.52

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.
@@ -1,13 +1,13 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
2
2
  import { CloudflareThreadClient } from "./CloudflareThreadClient.mjs";
3
- import { t as cloudflarePreparedInputAdmissionLayer } from "./prepared-admission-DRBhl2Sp.mjs";
3
+ import { t as cloudflarePreparedInputAdmissionLayer } from "./prepared-admission-9rvlHI0y.mjs";
4
4
  import { Principal } from "@effect-agent/thread/SubmissionLedger";
5
5
  import { Cause, Clock, Context, DateTime, Effect, Layer, Schema } from "effect";
6
6
  import { PersistedJson } from "@effect-agent/thread/Records";
7
7
  import { DurableObject, DurableObjectAlarm, DurableObjectState } from "effect-cf";
8
8
  import { BrowserCrypto } from "@effect/platform-browser";
9
9
  import { SqliteClient } from "@effect/sql-sqlite-do";
10
- import { EventAcknowledgement, EventSourceVersion, SourcePartition, SubscriptionConfiguration, SubscriptionDeliverySnapshot, SubscriptionError, SubscriptionFailpointError, SubscriptionKey, SubscriptionScope, SubscriptionSnapshot, SubscriptionSourceError, defaultSubscriptionLimits } from "@effect-agent/thread/Subscription";
10
+ import { EventAcknowledgement, EventSourceVersion, SourcePartition, SubscriptionConfiguration, SubscriptionDeliveryKey, SubscriptionDeliverySnapshot, SubscriptionError, SubscriptionFailpointError, SubscriptionKey, SubscriptionScope, SubscriptionSnapshot, SubscriptionSourceError, defaultSubscriptionLimits } from "@effect-agent/thread/Subscription";
11
11
  import { DoSubscriptionAlarmControl, DoSubscriptionTransaction, doSubscriptionStoreLayer } from "@effect-agent/storage-cloudflare/DoSubscriptionStore";
12
12
  import "@effect-agent/thread/EventSource";
13
13
  import "@effect-agent/thread/SubscriptionInput";
@@ -16,10 +16,13 @@ import { SubscriptionDriver, SubscriptionIntake, Subscriptions } from "@effect-a
16
16
  var CloudflareSubscriptions_exports = /* @__PURE__ */ __exportAll({
17
17
  CloudflareSubscriptionConfigError: () => CloudflareSubscriptionConfigError,
18
18
  CloudflareSubscriptionsClient: () => CloudflareSubscriptionsClient,
19
+ SubscriptionAlarmExtensionError: () => SubscriptionAlarmExtensionError,
19
20
  SubscriptionAlarmProtocolError: () => SubscriptionAlarmProtocolError,
21
+ SubscriptionPartitionAlarmExtension: () => SubscriptionPartitionAlarmExtension,
20
22
  SubscriptionPartitionIdentity: () => SubscriptionPartitionIdentity,
21
23
  SubscriptionPartitionNamespace: () => SubscriptionPartitionNamespace,
22
24
  SubscriptionPartitionProtocolError: () => SubscriptionPartitionProtocolError,
25
+ makeSubscriptionPartitionAlarmHandler: () => makeSubscriptionPartitionAlarmHandler,
23
26
  makeSubscriptionPartitionObjectClass: () => makeSubscriptionPartitionObjectClass,
24
27
  sourcePartitionName: () => sourcePartitionName,
25
28
  validateCloudflareSubscriptionLimits: () => validateCloudflareSubscriptionLimits
@@ -27,16 +30,42 @@ var CloudflareSubscriptions_exports = /* @__PURE__ */ __exportAll({
27
30
  const SUBSCRIPTION_ALARM_TAG = "effect-agent/SubscriptionPartitionWake";
28
31
  const SUBSCRIPTION_ALARM_ID = "driver";
29
32
  const MAX_ALARM_WALL_MILLIS = 72e4;
33
+ const MAX_ALARMS_PER_INVOCATION = 16;
34
+ const MAX_ANCILLARY_ALARM_MILLIS = 3e4;
30
35
  const SubscriptionAlarmPayload = Schema.Struct({
31
36
  schemaVersion: Schema.Literal(1),
32
37
  generation: Schema.Int.check(Schema.isGreaterThan(0))
33
38
  });
34
39
  var SubscriptionAlarmProtocolError = class extends Schema.TaggedError()("SubscriptionAlarmProtocolError", { message: Schema.String }) {};
40
+ /** Bounded host diagnostic; credentials and provider responses do not belong in alarm failures. */
41
+ var SubscriptionAlarmExtensionError = class extends Schema.TaggedError()("SubscriptionAlarmExtensionError", { code: Schema.NonEmptyString.check(Schema.isMaxLength(128)) }) {};
42
+ /** Host-only handlers; the framework reserves its namespace and rejects every unknown tag. */
43
+ const SubscriptionPartitionAlarmExtension = Context.Reference("@effect-agent/platform-cloudflare/SubscriptionPartitionAlarmExtension", { defaultValue: () => ({ handlers: [] }) });
44
+ /** Capture host services once, deferring native partition services to invocation.
45
+ * Each invocation owns its codec/handler Scope and timeout.
46
+ * Callback failures stay typed. Defects and interruption reach the native alarm multiplexer.
47
+ * The host owns durable idempotency, prearming and external-effect uncertainty.
48
+ */
49
+ const makeSubscriptionPartitionAlarmHandler = Effect.fn("makeSubscriptionPartitionAlarmHandler")(function* (options) {
50
+ if (options.tag.length === 0 || options.tag.length > 128 || options.tag.startsWith("effect-agent/") || !Number.isSafeInteger(options.timeoutMillis) || options.timeoutMillis < 1 || options.timeoutMillis > MAX_ANCILLARY_ALARM_MILLIS) return yield* SubscriptionAlarmProtocolError.make({ message: "Invalid ancillary alarm tag or timeout" });
51
+ const services = (yield* Effect.context()).pipe(Context.omit(Subscriptions, SubscriptionIntake, SubscriptionDriver));
52
+ return {
53
+ tag: options.tag,
54
+ handle: (event) => Effect.gen(function* () {
55
+ if (event.tag !== options.tag) return yield* SubscriptionAlarmProtocolError.make({ message: "Ancillary alarm tag mismatch" });
56
+ const payload = yield* Schema.decodeUnknownEffect(options.payload)(event.payload).pipe(Effect.mapError(() => SubscriptionAlarmProtocolError.make({ message: "Invalid ancillary alarm payload" })));
57
+ yield* options.handle({
58
+ ...event,
59
+ payload
60
+ });
61
+ }).pipe(Effect.scoped, Effect.timeout(options.timeoutMillis), Effect.catchTag("TimeoutError", () => SubscriptionAlarmExtensionError.make({ code: "timeout" })), Effect.provideContext(services))
62
+ };
63
+ });
35
64
  var SubscriptionPartitionProtocolError = class extends Schema.TaggedError()("SubscriptionPartitionProtocolError", { message: Schema.String.check(Schema.isMaxLength(4096)) }) {};
36
65
  var CloudflareSubscriptionConfigError = class extends Schema.TaggedError()("CloudflareSubscriptionConfigError", { message: Schema.String }) {};
37
66
  /** Reject limits whose four bounded phases could exceed the safe Durable Object alarm budget. */
38
- const validateCloudflareSubscriptionLimits = (limits) => {
39
- return 4 * Math.ceil(limits.batchSize / limits.concurrency) * limits.operationTimeoutMillis <= MAX_ALARM_WALL_MILLIS ? Effect.void : Effect.fail(CloudflareSubscriptionConfigError.make({ message: "Subscription limits can exceed the bounded Durable Object alarm wall budget" }));
67
+ const validateCloudflareSubscriptionLimits = (limits, options = {}) => {
68
+ return 4 * Math.ceil(limits.batchSize / limits.concurrency) * limits.operationTimeoutMillis + (options.ancillaryAlarms === true ? MAX_ALARMS_PER_INVOCATION * MAX_ANCILLARY_ALARM_MILLIS : 0) <= MAX_ALARM_WALL_MILLIS ? Effect.void : Effect.fail(CloudflareSubscriptionConfigError.make({ message: "Subscription limits can exceed the bounded Durable Object alarm wall budget" }));
40
69
  };
41
70
  const protocolMessage = (message) => message.length <= 4096 ? message : `${message.slice(0, 4093)}...`;
42
71
  const SubscribeRequest = Schema.TaggedStruct("Subscribe", {
@@ -48,13 +77,33 @@ const SubscribeRequest = Schema.TaggedStruct("Subscribe", {
48
77
  parameters: PersistedJson,
49
78
  context: PersistedJson,
50
79
  mode: Schema.Literals(["once", "continuous"]),
51
- expiresAtMillis: Schema.Number,
80
+ expiresAtMillis: Schema.NullOr(Schema.Number),
52
81
  destination: SubscriptionConfiguration.fields.destination,
53
82
  deliveryPrincipal: SubscriptionConfiguration.fields.deliveryPrincipal,
83
+ admissionGroup: SubscriptionConfiguration.fields.admissionGroup,
84
+ admissionFence: SubscriptionConfiguration.fields.admissionFence,
54
85
  agentId: SubscriptionConfiguration.fields.agentId,
55
86
  definitions: SubscriptionConfiguration.fields.definitions
56
87
  })
57
88
  });
89
+ const UpdateSubscriptionRequest = Schema.TaggedStruct("UpdateSubscription", {
90
+ schemaVersion: Schema.Literal(1),
91
+ scope: SubscribeRequest.fields.scope,
92
+ key: SubscriptionKey,
93
+ expectedRevision: Schema.Int.check(Schema.isGreaterThan(0)),
94
+ options: SubscribeRequest.fields.options.mapFields(({ subscriptionId: _, ...fields }) => fields)
95
+ });
96
+ const SubscriptionStateRequest = Schema.Struct({
97
+ _tag: Schema.Literals([
98
+ "PauseSubscription",
99
+ "ResumeSubscription",
100
+ "RecoverSubscription"
101
+ ]),
102
+ schemaVersion: Schema.Literal(1),
103
+ scope: SubscribeRequest.fields.scope,
104
+ key: SubscriptionKey,
105
+ expectedRevision: Schema.Int.check(Schema.isGreaterThan(0))
106
+ });
58
107
  const ListSubscriptionsRequest = Schema.TaggedStruct("ListSubscriptions", {
59
108
  schemaVersion: Schema.Literal(1),
60
109
  scope: SubscribeRequest.fields.scope,
@@ -62,10 +111,22 @@ const ListSubscriptionsRequest = Schema.TaggedStruct("ListSubscriptions", {
62
111
  limit: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThan(0)))
63
112
  });
64
113
  const CancelSubscriptionRequest = Schema.TaggedStruct("CancelSubscription", {
114
+ expectedRevision: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThan(0))),
65
115
  schemaVersion: Schema.Literal(1),
66
116
  scope: SubscribeRequest.fields.scope,
67
117
  key: SubscriptionKey
68
118
  });
119
+ const GetSubscriptionRequest = Schema.TaggedStruct("GetSubscription", {
120
+ schemaVersion: Schema.Literal(1),
121
+ scope: SubscriptionScope,
122
+ key: SubscriptionKey
123
+ });
124
+ const RecoverDeliveryRequest = Schema.TaggedStruct("RecoverDelivery", {
125
+ expectedGeneration: Schema.Natural,
126
+ schemaVersion: Schema.Literal(1),
127
+ scope: SubscribeRequest.fields.scope,
128
+ key: SubscriptionDeliveryKey
129
+ });
69
130
  const ListDeliveriesRequest = Schema.TaggedStruct("ListDeliveries", {
70
131
  schemaVersion: Schema.Literal(1),
71
132
  scope: SubscribeRequest.fields.scope,
@@ -89,9 +150,13 @@ const StatusRequest = Schema.TaggedStruct("Status", {
89
150
  });
90
151
  const SubscriptionPartitionRequest = Schema.Union([
91
152
  SubscribeRequest,
153
+ GetSubscriptionRequest,
154
+ UpdateSubscriptionRequest,
155
+ SubscriptionStateRequest,
92
156
  ListSubscriptionsRequest,
93
157
  CancelSubscriptionRequest,
94
158
  ListDeliveriesRequest,
159
+ RecoverDeliveryRequest,
95
160
  AcceptRequest,
96
161
  StatusRequest
97
162
  ]);
@@ -119,6 +184,7 @@ const SubscriptionPartitionResponse = Schema.Union([
119
184
  Schema.TaggedStruct("Snapshot", { value: SubscriptionSnapshot }),
120
185
  Schema.TaggedStruct("SubscriptionPage", { value: SubscriptionPage }),
121
186
  Schema.TaggedStruct("DeliveryPage", { value: DeliveryPage }),
187
+ Schema.TaggedStruct("DeliverySnapshot", { value: SubscriptionDeliverySnapshot }),
122
188
  Schema.TaggedStruct("Acknowledgement", { value: EventAcknowledgement }),
123
189
  Schema.TaggedStruct("Status", { value: IntakeStatus }),
124
190
  Schema.TaggedStruct("Failed", { failure: SubscriptionPartitionFailure })
@@ -160,7 +226,58 @@ var CloudflareSubscriptionsClient = class {
160
226
  });
161
227
  const failed = (response) => response._tag === "Failed" ? response.failure : SubscriptionPartitionProtocolError.make({ message: "Unexpected subscription response" });
162
228
  const asProtocolError = () => corruptFailure("subscription-partition-protocol");
229
+ const changeState = Effect.fn("CloudflareSubscriptions.changeState")(function* (scope, key, expectedRevision, _tag) {
230
+ const response = yield* call(scope.partition, {
231
+ _tag,
232
+ schemaVersion: 1,
233
+ scope,
234
+ key,
235
+ expectedRevision
236
+ });
237
+ if (response._tag === "Snapshot") return response.value;
238
+ const failure = failed(response);
239
+ return yield* failure._tag === "SubscriptionError" || failure._tag === "SubscriptionFailpointError" ? failure : asProtocolError();
240
+ });
163
241
  const subscriptions = Subscriptions.of({
242
+ recoverSubscription: (scope, key, revision) => changeState(scope, key, revision, "RecoverSubscription"),
243
+ getSubscription: (scope, key) => Effect.gen(function* () {
244
+ const response = yield* call(scope.partition, {
245
+ _tag: "GetSubscription",
246
+ schemaVersion: 1,
247
+ scope,
248
+ key
249
+ });
250
+ if (response._tag === "Snapshot") return response.value;
251
+ const failure = failed(response);
252
+ return yield* failure._tag === "SubscriptionError" ? failure : asProtocolError();
253
+ }),
254
+ recoverDelivery: (scope, key, expectedGeneration) => Effect.gen(function* () {
255
+ const response = yield* call(scope.partition, {
256
+ _tag: "RecoverDelivery",
257
+ expectedGeneration,
258
+ schemaVersion: 1,
259
+ scope,
260
+ key
261
+ });
262
+ if (response._tag === "DeliverySnapshot") return response.value;
263
+ const failure = failed(response);
264
+ return yield* failure._tag === "SubscriptionError" || failure._tag === "SubscriptionFailpointError" ? failure : asProtocolError();
265
+ }),
266
+ updateSubscription: (scope, key, expectedRevision, options) => Effect.gen(function* () {
267
+ const response = yield* call(scope.partition, {
268
+ _tag: "UpdateSubscription",
269
+ schemaVersion: 1,
270
+ scope,
271
+ key,
272
+ expectedRevision,
273
+ options
274
+ });
275
+ if (response._tag === "Snapshot") return response.value;
276
+ const failure = failed(response);
277
+ return yield* failure._tag === "SubscriptionError" || failure._tag === "SubscriptionFailpointError" || failure._tag === "SubscriptionSourceError" ? failure : asProtocolError();
278
+ }),
279
+ pauseSubscription: (scope, key, revision) => changeState(scope, key, revision, "PauseSubscription"),
280
+ resumeSubscription: (scope, key, revision) => changeState(scope, key, revision, "ResumeSubscription"),
164
281
  subscribe: (scope, options) => Effect.gen(function* () {
165
282
  const response = yield* call(scope.partition, {
166
283
  _tag: "Subscribe",
@@ -185,9 +302,10 @@ var CloudflareSubscriptionsClient = class {
185
302
  const failure = failed(response);
186
303
  return yield* failure._tag === "SubscriptionError" ? failure : asProtocolError();
187
304
  }),
188
- cancelSubscription: (scope, key) => Effect.gen(function* () {
305
+ cancelSubscription: (scope, key, expectedRevision) => Effect.gen(function* () {
189
306
  const response = yield* call(scope.partition, {
190
307
  _tag: "CancelSubscription",
308
+ ...expectedRevision === void 0 ? {} : { expectedRevision },
191
309
  schemaVersion: 1,
192
310
  scope,
193
311
  key
@@ -269,17 +387,41 @@ const handleRequest = Effect.fn("SubscriptionPartition.handleRequest")(function*
269
387
  const intake = yield* SubscriptionIntake;
270
388
  const response = yield* Effect.gen(function* () {
271
389
  switch (request._tag) {
390
+ case "GetSubscription": return {
391
+ _tag: "Snapshot",
392
+ value: yield* subscriptions.getSubscription(request.scope, request.key)
393
+ };
272
394
  case "Subscribe": return {
273
395
  _tag: "Snapshot",
274
396
  value: yield* subscriptions.subscribe(request.scope, request.options)
275
397
  };
398
+ case "UpdateSubscription": return {
399
+ _tag: "Snapshot",
400
+ value: yield* subscriptions.updateSubscription(request.scope, request.key, request.expectedRevision, request.options)
401
+ };
402
+ case "RecoverSubscription": return {
403
+ _tag: "Snapshot",
404
+ value: yield* subscriptions.recoverSubscription(request.scope, request.key, request.expectedRevision)
405
+ };
406
+ case "PauseSubscription": return {
407
+ _tag: "Snapshot",
408
+ value: yield* subscriptions.pauseSubscription(request.scope, request.key, request.expectedRevision)
409
+ };
410
+ case "ResumeSubscription": return {
411
+ _tag: "Snapshot",
412
+ value: yield* subscriptions.resumeSubscription(request.scope, request.key, request.expectedRevision)
413
+ };
276
414
  case "ListSubscriptions": return {
277
415
  _tag: "SubscriptionPage",
278
416
  value: yield* subscriptions.listSubscriptions(request.scope, request.after, request.limit)
279
417
  };
280
418
  case "CancelSubscription": return {
281
419
  _tag: "Snapshot",
282
- value: yield* subscriptions.cancelSubscription(request.scope, request.key)
420
+ value: yield* subscriptions.cancelSubscription(request.scope, request.key, request.expectedRevision)
421
+ };
422
+ case "RecoverDelivery": return {
423
+ _tag: "DeliverySnapshot",
424
+ value: yield* subscriptions.recoverDelivery(request.scope, request.key, request.expectedGeneration)
283
425
  };
284
426
  case "ListDeliveries": return {
285
427
  _tag: "DeliveryPage",
@@ -320,14 +462,26 @@ const transactionLayer = Layer.effect(DoSubscriptionTransaction, Effect.gen(func
320
462
  }) });
321
463
  }));
322
464
  const alarmHandler = (limits) => DurableObjectAlarm.processDue((event) => Effect.gen(function* () {
323
- if (event.tag !== SUBSCRIPTION_ALARM_TAG || event.id !== SUBSCRIPTION_ALARM_ID) return yield* SubscriptionAlarmProtocolError.make({ message: `Unsupported Subscription Partition alarm ${event.tag}/${event.id}` });
465
+ if (event.tag !== SUBSCRIPTION_ALARM_TAG) {
466
+ const { handlers } = yield* SubscriptionPartitionAlarmExtension;
467
+ const matches = handlers.filter((handler) => handler.tag === event.tag);
468
+ const handler = matches[0];
469
+ if (event.tag.startsWith("effect-agent/") || matches.length !== 1 || handler === void 0) return yield* SubscriptionAlarmProtocolError.make({ message: "Unknown or ambiguous ancillary alarm tag" });
470
+ return yield* handler.handle(event).pipe(Effect.scoped, Effect.timeout(MAX_ANCILLARY_ALARM_MILLIS), Effect.catchTag("TimeoutError", () => SubscriptionAlarmExtensionError.make({ code: "timeout" })));
471
+ }
472
+ if (event.id !== SUBSCRIPTION_ALARM_ID) return yield* SubscriptionAlarmProtocolError.make({ message: `Unsupported Subscription Partition alarm ${event.tag}/${event.id}` });
324
473
  yield* Schema.decodeUnknownEffect(SubscriptionAlarmPayload)(event.payload).pipe(Effect.mapError(() => SubscriptionAlarmProtocolError.make({ message: "Unsupported subscription alarm payload" })));
325
474
  const driver = yield* SubscriptionDriver;
326
475
  const alarmControl = yield* DoSubscriptionAlarmControl;
327
476
  yield* alarmControl.prearm((yield* Clock.currentTimeMillis) + limits.retryMillis);
328
477
  if ((yield* driver.runDue.pipe(Effect.catchCause((cause) => Cause.hasInterrupts(cause) ? Effect.failCause(cause) : Clock.currentTimeMillis.pipe(Effect.flatMap((time) => alarmControl.prearm(time + limits.retryMillis)), Effect.andThen(Effect.failCause(cause)))))).failed > 0) yield* alarmControl.prearm((yield* Clock.currentTimeMillis) + limits.retryMillis);
329
478
  else yield* alarmControl.reconcile;
330
- }), { mode: "ordered" }).pipe(Effect.asVoid);
479
+ }), {
480
+ mode: "isolated",
481
+ limit: MAX_ALARMS_PER_INVOCATION,
482
+ retryFailedAfter: limits.retryMillis,
483
+ onFailure: () => Effect.logWarning("Subscription partition alarm retained for retry")
484
+ }).pipe(Effect.asVoid);
331
485
  /**
332
486
  * Build one source-addressed SQLite Durable Object. The host Layer binds the permitted source
333
487
  * catalog and authority. It must not retain cleanup-scoped resources across RPC events.
@@ -340,7 +494,13 @@ const makeSubscriptionPartitionObjectClass = (host, limits = defaultSubscription
340
494
  }));
341
495
  const sqlLayer = Layer.unwrap(Effect.map(DurableObjectState.DurableObjectState, (state) => SqliteClient.layer({ storage: state.raw.storage })));
342
496
  const partitionStore = Layer.unwrap(Effect.map(SubscriptionPartitionIdentity, ({ partition }) => doSubscriptionStoreLayer(partition).pipe(Layer.provide(transactionLayer), Layer.provide(sqlLayer))));
343
- const application = Layer.mergeAll(Subscriptions.layer(limits), SubscriptionIntake.layer(limits), SubscriptionDriver.layer(limits), cloudflareLimitsLayer).pipe(Layer.provideMerge(partitionStore), Layer.provide(cloudflarePreparedInputAdmissionLayer.pipe(Layer.provide(CloudflareThreadClient.layer))), Layer.provide(BrowserCrypto.layer), Layer.provideMerge(DurableObjectAlarm.DurableObjectAlarm.layer), Layer.provide(host), Layer.provideMerge(identityLayer));
497
+ const application = Layer.mergeAll(Subscriptions.layer(limits), SubscriptionIntake.layer(limits), SubscriptionDriver.layer(limits), cloudflareLimitsLayer, Layer.effect(SubscriptionPartitionAlarmExtension, Effect.gen(function* () {
498
+ const extension = yield* SubscriptionPartitionAlarmExtension;
499
+ const tags = extension.handlers.map((handler) => handler.tag);
500
+ if (tags.length > MAX_ALARMS_PER_INVOCATION || new Set(tags).size !== tags.length || tags.some((tag) => tag.length === 0 || tag.length > 128 || tag.startsWith("effect-agent/"))) return yield* SubscriptionAlarmProtocolError.make({ message: "Invalid ancillary alarm handler registry" });
501
+ yield* validateCloudflareSubscriptionLimits(limits, { ancillaryAlarms: tags.length > 0 });
502
+ return extension;
503
+ }))).pipe(Layer.provideMerge(partitionStore), Layer.provide(cloudflarePreparedInputAdmissionLayer.pipe(Layer.provide(CloudflareThreadClient.layer))), Layer.provide(BrowserCrypto.layer), Layer.provideMerge(DurableObjectAlarm.DurableObjectAlarm.layer), Layer.provide(host), Layer.provideMerge(identityLayer));
344
504
  const runtime = Layer.effectContext(Effect.gen(function* () {
345
505
  const state = yield* DurableObjectState.DurableObjectState;
346
506
  const scope = yield* Effect.scope;
@@ -359,6 +519,6 @@ const makeSubscriptionPartitionObjectClass = (host, limits = defaultSubscription
359
519
  return SubscriptionPartitionObject;
360
520
  };
361
521
  //#endregion
362
- export { CloudflareSubscriptionConfigError, CloudflareSubscriptionsClient, SubscriptionAlarmProtocolError, SubscriptionPartitionIdentity, SubscriptionPartitionNamespace, SubscriptionPartitionProtocolError, makeSubscriptionPartitionObjectClass, sourcePartitionName, CloudflareSubscriptions_exports as t, validateCloudflareSubscriptionLimits };
522
+ export { CloudflareSubscriptionConfigError, CloudflareSubscriptionsClient, SubscriptionAlarmExtensionError, SubscriptionAlarmProtocolError, SubscriptionPartitionAlarmExtension, SubscriptionPartitionIdentity, SubscriptionPartitionNamespace, SubscriptionPartitionProtocolError, makeSubscriptionPartitionAlarmHandler, makeSubscriptionPartitionObjectClass, sourcePartitionName, CloudflareSubscriptions_exports as t, validateCloudflareSubscriptionLimits };
363
523
 
364
524
  //# sourceMappingURL=CloudflareSubscriptions.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"CloudflareSubscriptions.mjs","names":["EffectCfDurableObjectState","EffectCfDurableObject"],"sources":["../src/CloudflareSubscriptions.ts"],"sourcesContent":["import {\n DoSubscriptionAlarmControl,\n DoSubscriptionTransaction,\n doSubscriptionStoreLayer,\n} from \"@effect-agent/storage-cloudflare/DoSubscriptionStore\";\nimport { type EventSources } from \"@effect-agent/thread/EventSource\";\nimport { PersistedJson } from \"@effect-agent/thread/Records\";\nimport { Principal } from \"@effect-agent/thread/SubmissionLedger\";\nimport {\n EventAcknowledgement,\n EventSourceVersion,\n SourcePartition,\n type SubscriptionAuthorizer,\n SubscriptionConfiguration,\n SubscriptionDeliverySnapshot,\n SubscriptionError,\n SubscriptionFailpointError,\n SubscriptionKey,\n SubscriptionScope,\n type SubscriptionLimits,\n SubscriptionSnapshot,\n SubscriptionSourceError,\n defaultSubscriptionLimits,\n} from \"@effect-agent/thread/Subscription\";\nimport { type SubscriptionInputBindings } from \"@effect-agent/thread/SubscriptionInput\";\nimport {\n SubscriptionDriver,\n SubscriptionIntake,\n Subscriptions,\n} from \"@effect-agent/thread/Subscriptions\";\nimport { BrowserCrypto } from \"@effect/platform-browser\";\nimport { SqliteClient } from \"@effect/sql-sqlite-do\";\nimport { Cause, Clock, Context, DateTime, Effect, Layer, Schema } from \"effect\";\nimport {\n DurableObject as EffectCfDurableObject,\n DurableObjectAlarm,\n DurableObjectState as EffectCfDurableObjectState,\n type WorkerEnvironment,\n} from \"effect-cf\";\n\nimport { type ThreadObjectNamespace } from \"./CloudflareBindings.ts\";\nimport { CloudflareThreadClient } from \"./CloudflareThreadClient.ts\";\nimport { cloudflarePreparedInputAdmissionLayer } from \"./internal/prepared-admission.ts\";\n\nconst SUBSCRIPTION_ALARM_TAG = \"effect-agent/SubscriptionPartitionWake\";\nconst SUBSCRIPTION_ALARM_ID = \"driver\";\nconst MAX_ALARM_WALL_MILLIS = 12 * 60_000;\n\nconst SubscriptionAlarmPayload = Schema.Struct({\n schemaVersion: Schema.Literal(1),\n generation: Schema.Int.check(Schema.isGreaterThan(0)),\n});\n\nexport class SubscriptionAlarmProtocolError extends Schema.TaggedError<SubscriptionAlarmProtocolError>()(\n \"SubscriptionAlarmProtocolError\",\n { message: Schema.String },\n) {}\n\nexport class SubscriptionPartitionProtocolError extends Schema.TaggedError<SubscriptionPartitionProtocolError>()(\n \"SubscriptionPartitionProtocolError\",\n { message: Schema.String.check(Schema.isMaxLength(4_096)) },\n) {}\n\nexport class CloudflareSubscriptionConfigError extends Schema.TaggedError<CloudflareSubscriptionConfigError>()(\n \"CloudflareSubscriptionConfigError\",\n { message: Schema.String },\n) {}\n\n/** Reject limits whose four bounded phases could exceed the safe Durable Object alarm budget. */\nexport const validateCloudflareSubscriptionLimits = (\n limits: SubscriptionLimits,\n): Effect.Effect<void, CloudflareSubscriptionConfigError> => {\n const worstCaseMillis =\n 4 * Math.ceil(limits.batchSize / limits.concurrency) * limits.operationTimeoutMillis;\n\n return worstCaseMillis <= MAX_ALARM_WALL_MILLIS\n ? Effect.void\n : Effect.fail(\n CloudflareSubscriptionConfigError.make({\n message: \"Subscription limits can exceed the bounded Durable Object alarm wall budget\",\n }),\n );\n};\n\nconst protocolMessage = (message: string): string =>\n message.length <= 4_096 ? message : `${message.slice(0, 4_093)}...`;\n\nconst SubscribeRequest = Schema.TaggedStruct(\"Subscribe\", {\n schemaVersion: Schema.Literal(1),\n scope: Schema.Struct({\n ...SubscriptionScope.fields,\n }),\n options: Schema.Struct({\n subscriptionId: SubscriptionKey.fields.subscriptionId,\n source: EventSourceVersion,\n parameters: PersistedJson,\n context: PersistedJson,\n mode: Schema.Literals([\"once\", \"continuous\"]),\n expiresAtMillis: Schema.Number,\n destination: SubscriptionConfiguration.fields.destination,\n deliveryPrincipal: SubscriptionConfiguration.fields.deliveryPrincipal,\n agentId: SubscriptionConfiguration.fields.agentId,\n definitions: SubscriptionConfiguration.fields.definitions,\n }),\n});\n\nconst ListSubscriptionsRequest = Schema.TaggedStruct(\"ListSubscriptions\", {\n schemaVersion: Schema.Literal(1),\n scope: SubscribeRequest.fields.scope,\n after: Schema.optionalKey(Schema.Natural),\n limit: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThan(0))),\n});\n\nconst CancelSubscriptionRequest = Schema.TaggedStruct(\"CancelSubscription\", {\n schemaVersion: Schema.Literal(1),\n scope: SubscribeRequest.fields.scope,\n key: SubscriptionKey,\n});\n\nconst ListDeliveriesRequest = Schema.TaggedStruct(\"ListDeliveries\", {\n schemaVersion: Schema.Literal(1),\n scope: SubscribeRequest.fields.scope,\n key: SubscriptionKey,\n after: Schema.optionalKey(Schema.String),\n limit: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThan(0))),\n});\n\nconst AcceptRequest = Schema.TaggedStruct(\"Accept\", {\n schemaVersion: Schema.Literal(1),\n partition: SourcePartition,\n principal: Principal,\n source: EventSourceVersion,\n payload: PersistedJson,\n});\n\nconst StatusRequest = Schema.TaggedStruct(\"Status\", {\n schemaVersion: Schema.Literal(1),\n partition: SourcePartition,\n principal: Principal,\n source: EventSourceVersion,\n eventId: Schema.String,\n});\n\nconst SubscriptionPartitionRequest = Schema.Union([\n SubscribeRequest,\n ListSubscriptionsRequest,\n CancelSubscriptionRequest,\n ListDeliveriesRequest,\n AcceptRequest,\n StatusRequest,\n]);\n\ntype SubscriptionPartitionRequest = typeof SubscriptionPartitionRequest.Type;\n\nconst SubscriptionPage = Schema.Struct({\n items: Schema.Array(SubscriptionSnapshot),\n next: Schema.NullOr(Schema.Natural),\n});\n\nconst DeliveryPage = Schema.Struct({\n items: Schema.Array(SubscriptionDeliverySnapshot),\n next: Schema.NullOr(Schema.String),\n});\n\nconst IntakeStatus = Schema.Struct({\n ...EventAcknowledgement.fields,\n routingComplete: Schema.Boolean,\n routingFailure: Schema.NullOr(Schema.String),\n nextAttemptAtMillis: Schema.Number,\n});\n\nconst SubscriptionPartitionFailure = Schema.Union([\n SubscriptionError,\n SubscriptionSourceError,\n SubscriptionFailpointError,\n SubscriptionPartitionProtocolError,\n]);\n\ntype SubscriptionPartitionFailure = typeof SubscriptionPartitionFailure.Type;\n\nconst SubscriptionPartitionResponse = Schema.Union([\n Schema.TaggedStruct(\"Snapshot\", { value: SubscriptionSnapshot }),\n Schema.TaggedStruct(\"SubscriptionPage\", { value: SubscriptionPage }),\n Schema.TaggedStruct(\"DeliveryPage\", { value: DeliveryPage }),\n Schema.TaggedStruct(\"Acknowledgement\", { value: EventAcknowledgement }),\n Schema.TaggedStruct(\"Status\", { value: IntakeStatus }),\n Schema.TaggedStruct(\"Failed\", { failure: SubscriptionPartitionFailure }),\n]);\n\ntype SubscriptionPartitionResponse = typeof SubscriptionPartitionResponse.Type;\n\nconst decodeRequest = Schema.decodeUnknownEffect(SubscriptionPartitionRequest);\nconst encodeRequest = Schema.encodeEffect(SubscriptionPartitionRequest);\nconst decodeResponse = Schema.decodeUnknownEffect(SubscriptionPartitionResponse);\nconst encodeResponse = Schema.encodeEffect(SubscriptionPartitionResponse);\n\nconst protocolFailure = (message: string): SubscriptionPartitionResponse => ({\n _tag: \"Failed\",\n failure: SubscriptionPartitionProtocolError.make({ message: protocolMessage(message) }),\n});\n\nexport const sourcePartitionName = (partition: SourcePartition): string =>\n JSON.stringify([partition.tenantId, partition.address]);\n\nexport interface SubscriptionPartitionObjectRpc extends Rpc.DurableObjectBranded {\n subscription(encoded: unknown): Promise<unknown>;\n}\n\nexport class SubscriptionPartitionNamespace extends Context.Service<\n SubscriptionPartitionNamespace,\n { readonly namespace: DurableObjectNamespace<SubscriptionPartitionObjectRpc> }\n>()(\"@effect-agent/platform-cloudflare/SubscriptionPartitionNamespace\") {}\n\nconst storageFailure = (code: string): SubscriptionError =>\n SubscriptionError.make({ reason: \"storage\", code });\n\nconst corruptFailure = (code: string): SubscriptionError =>\n SubscriptionError.make({ reason: \"corrupt\", code });\n\n/** Worker-side management and trusted intake, routed to one fresh partition stub per call. */\nexport class CloudflareSubscriptionsClient {\n static layer(\n partition: SourcePartition,\n ): Layer.Layer<Subscriptions | SubscriptionIntake, never, SubscriptionPartitionNamespace> {\n return Layer.effectContext(\n Effect.gen(function* () {\n const { namespace } = yield* SubscriptionPartitionNamespace;\n\n const call = Effect.fn(\"CloudflareSubscriptionsClient.call\")(function* (\n addressedPartition: SourcePartition,\n request: SubscriptionPartitionRequest,\n ) {\n if (!samePartition(partition, addressedPartition)) {\n return yield* SubscriptionError.make({ reason: \"unauthorized\", code: \"partition\" });\n }\n\n const encoded = yield* encodeRequest(request).pipe(\n Effect.mapError(() => corruptFailure(\"subscription-partition-protocol\")),\n );\n\n const raw = yield* Effect.tryPromise({\n try: () =>\n namespace\n .get(namespace.idFromName(sourcePartitionName(partition)))\n .subscription(encoded),\n catch: () => storageFailure(\"call-subscription-partition\"),\n });\n\n return yield* decodeResponse(raw).pipe(\n Effect.mapError(() => corruptFailure(\"subscription-partition-protocol\")),\n );\n });\n\n const failed = (response: SubscriptionPartitionResponse): SubscriptionPartitionFailure =>\n response._tag === \"Failed\"\n ? response.failure\n : SubscriptionPartitionProtocolError.make({\n message: \"Unexpected subscription response\",\n });\n\n const asProtocolError = (): SubscriptionError =>\n corruptFailure(\"subscription-partition-protocol\");\n\n const subscriptions = Subscriptions.of({\n subscribe: (scope, options) =>\n Effect.gen(function* () {\n const response = yield* call(scope.partition, {\n _tag: \"Subscribe\",\n schemaVersion: 1,\n scope,\n options,\n });\n\n if (response._tag === \"Snapshot\") return response.value;\n const failure = failed(response);\n\n if (\n failure._tag === \"SubscriptionError\" ||\n failure._tag === \"SubscriptionSourceError\" ||\n failure._tag === \"SubscriptionFailpointError\"\n )\n return yield* failure;\n\n return yield* asProtocolError();\n }),\n listSubscriptions: (scope, after, limit) =>\n Effect.gen(function* () {\n const response = yield* call(scope.partition, {\n _tag: \"ListSubscriptions\",\n schemaVersion: 1,\n scope,\n ...(after === undefined ? {} : { after }),\n ...(limit === undefined ? {} : { limit }),\n });\n\n if (response._tag === \"SubscriptionPage\") return response.value;\n const failure = failed(response);\n\n return yield* failure._tag === \"SubscriptionError\" ? failure : asProtocolError();\n }),\n cancelSubscription: (scope, key) =>\n Effect.gen(function* () {\n const response = yield* call(scope.partition, {\n _tag: \"CancelSubscription\",\n schemaVersion: 1,\n scope,\n key,\n });\n\n if (response._tag === \"Snapshot\") return response.value;\n const failure = failed(response);\n\n if (\n failure._tag === \"SubscriptionError\" ||\n failure._tag === \"SubscriptionFailpointError\"\n )\n return yield* failure;\n\n return yield* asProtocolError();\n }),\n listDeliveries: (scope, key, after, limit) =>\n Effect.gen(function* () {\n const response = yield* call(scope.partition, {\n _tag: \"ListDeliveries\",\n schemaVersion: 1,\n scope,\n key,\n ...(after === undefined ? {} : { after }),\n ...(limit === undefined ? {} : { limit }),\n });\n\n if (response._tag === \"DeliveryPage\") return response.value;\n const failure = failed(response);\n\n return yield* failure._tag === \"SubscriptionError\" ? failure : asProtocolError();\n }),\n });\n\n const intake = SubscriptionIntake.of({\n accept: (principal, source, payload) =>\n Effect.gen(function* () {\n const request = yield* Schema.decodeUnknownEffect(AcceptRequest)({\n _tag: \"Accept\",\n schemaVersion: 1,\n partition,\n principal,\n source,\n payload,\n }).pipe(\n Effect.mapError(() =>\n SubscriptionError.make({ reason: \"validation\", code: \"event-payload\" }),\n ),\n );\n\n const response = yield* call(request.partition, request);\n\n if (response._tag === \"Acknowledgement\") return response.value;\n const failure = failed(response);\n\n if (\n failure._tag === \"SubscriptionError\" ||\n failure._tag === \"SubscriptionSourceError\" ||\n failure._tag === \"SubscriptionFailpointError\"\n )\n return yield* failure;\n\n return yield* asProtocolError();\n }),\n status: (principal, source, eventId) =>\n Effect.gen(function* () {\n const response = yield* call(partition, {\n _tag: \"Status\",\n schemaVersion: 1,\n partition,\n principal,\n source,\n eventId,\n });\n\n if (response._tag === \"Status\") return response.value;\n const failure = failed(response);\n\n return yield* failure._tag === \"SubscriptionError\" ? failure : asProtocolError();\n }),\n });\n\n return Context.make(Subscriptions, subscriptions).pipe(\n Context.add(SubscriptionIntake, intake),\n );\n }),\n );\n }\n}\n\nexport class SubscriptionPartitionIdentity extends Context.Service<\n SubscriptionPartitionIdentity,\n { readonly partition: SourcePartition }\n>()(\"@effect-agent/platform-cloudflare/SubscriptionPartitionIdentity\") {}\n\nconst decodePartitionName = Effect.fn(\"decodeSubscriptionPartitionName\")(function* (\n name: string | null | undefined,\n) {\n if (name === null || name === undefined) {\n return yield* SubscriptionPartitionProtocolError.make({\n message: \"Subscription Partition objects require an idFromName identity\",\n });\n }\n\n const tuple = yield* Schema.decodeUnknownEffect(\n Schema.fromJsonString(Schema.Tuple([Schema.String, Schema.String])),\n )(name).pipe(\n Effect.mapError(() =>\n SubscriptionPartitionProtocolError.make({\n message: \"Subscription Partition name is malformed\",\n }),\n ),\n );\n\n return yield* Schema.decodeUnknownEffect(SourcePartition)({\n tenantId: tuple[0],\n address: tuple[1],\n }).pipe(\n Effect.mapError(() =>\n SubscriptionPartitionProtocolError.make({\n message: \"Subscription Partition identity is invalid\",\n }),\n ),\n );\n});\n\nconst samePartition = Schema.toEquivalence(SourcePartition);\n\nconst requestPartition = (request: SubscriptionPartitionRequest): SourcePartition =>\n request._tag === \"Accept\" || request._tag === \"Status\"\n ? request.partition\n : request.scope.partition;\n\nconst handleRequest = Effect.fn(\"SubscriptionPartition.handleRequest\")(function* (\n encoded: unknown,\n) {\n const decoded = yield* decodeRequest(encoded).pipe(Effect.result);\n\n if (decoded._tag === \"Failure\") {\n return yield* encodeResponse(\n protocolFailure(\"The subscription request could not be decoded\"),\n ).pipe(Effect.orDie);\n }\n const request = decoded.success;\n const { partition } = yield* SubscriptionPartitionIdentity;\n\n if (!samePartition(partition, requestPartition(request))) {\n return yield* encodeResponse(\n protocolFailure(\"The request partition does not match the addressed object\"),\n ).pipe(Effect.orDie);\n }\n const subscriptions = yield* Subscriptions;\n const intake = yield* SubscriptionIntake;\n\n const response = yield* Effect.gen(function* (): Effect.fn.Return<\n SubscriptionPartitionResponse,\n SubscriptionPartitionFailure\n > {\n switch (request._tag) {\n case \"Subscribe\":\n return {\n _tag: \"Snapshot\",\n value: yield* subscriptions.subscribe(request.scope, request.options),\n };\n case \"ListSubscriptions\":\n return {\n _tag: \"SubscriptionPage\",\n value: yield* subscriptions.listSubscriptions(\n request.scope,\n request.after,\n request.limit,\n ),\n };\n case \"CancelSubscription\":\n return {\n _tag: \"Snapshot\",\n value: yield* subscriptions.cancelSubscription(request.scope, request.key),\n };\n case \"ListDeliveries\":\n return {\n _tag: \"DeliveryPage\",\n value: yield* subscriptions.listDeliveries(\n request.scope,\n request.key,\n request.after,\n request.limit,\n ),\n };\n case \"Accept\":\n return {\n _tag: \"Acknowledgement\",\n value: yield* intake.accept(request.principal, request.source, request.payload),\n };\n case \"Status\":\n return {\n _tag: \"Status\",\n value: yield* intake.status(request.principal, request.source, request.eventId),\n };\n }\n }).pipe(\n Effect.catch((failure) =>\n Schema.is(SubscriptionPartitionFailure)(failure)\n ? Effect.succeed({ _tag: \"Failed\" as const, failure })\n : Effect.succeed(protocolFailure(\"The subscription operation failed outside its contract\")),\n ),\n );\n\n return yield* encodeResponse(response).pipe(Effect.orDie);\n});\n\nconst alarmStorageError = (code: string) => () => storageFailure(code);\n\nconst transactionLayer: Layer.Layer<\n DoSubscriptionTransaction,\n never,\n DurableObjectAlarm.DurableObjectAlarm\n> = Layer.effect(\n DoSubscriptionTransaction,\n Effect.gen(function* () {\n const alarms = yield* DurableObjectAlarm.DurableObjectAlarm;\n\n return DoSubscriptionTransaction.of({\n run: (body) =>\n Effect.gen(function* () {\n const nowMillis = yield* Clock.currentTimeMillis;\n\n return yield* alarms\n .transaction((transaction) =>\n body((replacement) =>\n replacement.deadlineAtMillis === null\n ? transaction\n .cancelAlarm({ id: SUBSCRIPTION_ALARM_ID, tag: SUBSCRIPTION_ALARM_TAG })\n .pipe(Effect.mapError(alarmStorageError(\"cancel-subscription-alarm\")))\n : Effect.fromOption(\n DateTime.make(Math.max(replacement.deadlineAtMillis, nowMillis + 1)),\n ).pipe(\n Effect.mapError(() => corruptFailure(\"subscription-alarm-deadline\")),\n Effect.flatMap((runAt) =>\n transaction\n .scheduleAlarm({\n id: SUBSCRIPTION_ALARM_ID,\n tag: SUBSCRIPTION_ALARM_TAG,\n runAt,\n payload: { schemaVersion: 1, generation: replacement.generation },\n })\n .pipe(Effect.mapError(alarmStorageError(\"schedule-subscription-alarm\"))),\n ),\n ),\n ),\n )\n .pipe(\n Effect.catchTag(\"StorageOperationError\", () =>\n storageFailure(\"commit-subscription-transaction\"),\n ),\n );\n }),\n });\n }),\n);\n\nconst alarmHandler = (limits: SubscriptionLimits) =>\n DurableObjectAlarm.processDue(\n (event) =>\n Effect.gen(function* () {\n if (event.tag !== SUBSCRIPTION_ALARM_TAG || event.id !== SUBSCRIPTION_ALARM_ID) {\n return yield* SubscriptionAlarmProtocolError.make({\n message: `Unsupported Subscription Partition alarm ${event.tag}/${event.id}`,\n });\n }\n yield* Schema.decodeUnknownEffect(SubscriptionAlarmPayload)(event.payload).pipe(\n Effect.mapError(() =>\n SubscriptionAlarmProtocolError.make({\n message: \"Unsupported subscription alarm payload\",\n }),\n ),\n );\n const driver = yield* SubscriptionDriver;\n const alarmControl = yield* DoSubscriptionAlarmControl;\n\n yield* alarmControl.prearm((yield* Clock.currentTimeMillis) + limits.retryMillis);\n\n const pass = yield* driver.runDue.pipe(\n Effect.catchCause((cause) =>\n Cause.hasInterrupts(cause)\n ? Effect.failCause(cause)\n : Clock.currentTimeMillis.pipe(\n Effect.flatMap((time) => alarmControl.prearm(time + limits.retryMillis)),\n Effect.andThen(Effect.failCause(cause)),\n ),\n ),\n );\n\n if (pass.failed > 0) {\n yield* alarmControl.prearm((yield* Clock.currentTimeMillis) + limits.retryMillis);\n } else {\n yield* alarmControl.reconcile;\n }\n }),\n { mode: \"ordered\" },\n ).pipe(Effect.asVoid);\n\ntype SubscriptionRuntimeServices =\n | Subscriptions\n | SubscriptionIntake\n | SubscriptionDriver\n | DoSubscriptionAlarmControl\n | SubscriptionPartitionIdentity\n | DurableObjectAlarm.DurableObjectAlarm;\n\nexport interface SubscriptionPartitionObjectInstance extends InstanceType<\n EffectCfDurableObject.DurableObjectClass<Record<never, never>, SubscriptionRuntimeServices>\n> {\n subscription(encoded: unknown): Promise<unknown>;\n alarm(alarmInfo?: AlarmInvocationInfo): Promise<void> | void;\n}\n\nexport interface SubscriptionPartitionObjectClass {\n new (ctx: DurableObjectState, env: Cloudflare.Env): SubscriptionPartitionObjectInstance;\n}\n\n/**\n * Build one source-addressed SQLite Durable Object. The host Layer binds the permitted source\n * catalog and authority. It must not retain cleanup-scoped resources across RPC events.\n */\nexport const makeSubscriptionPartitionObjectClass = <E>(\n host: Layer.Layer<\n SubscriptionAuthorizer | EventSources | SubscriptionInputBindings | ThreadObjectNamespace,\n E,\n | EffectCfDurableObjectState.DurableObjectState\n | WorkerEnvironment\n | SubscriptionPartitionIdentity\n >,\n limits: SubscriptionLimits = defaultSubscriptionLimits,\n): SubscriptionPartitionObjectClass => {\n const cloudflareLimitsLayer = Layer.effectDiscard(validateCloudflareSubscriptionLimits(limits));\n\n const identityLayer = Layer.effect(\n SubscriptionPartitionIdentity,\n Effect.gen(function* () {\n const state = yield* EffectCfDurableObjectState.DurableObjectState;\n\n return SubscriptionPartitionIdentity.of({\n partition: yield* decodePartitionName(state.raw.id.name),\n });\n }),\n );\n\n const sqlLayer = Layer.unwrap(\n Effect.map(EffectCfDurableObjectState.DurableObjectState, (state) =>\n SqliteClient.layer({ storage: state.raw.storage }),\n ),\n );\n\n const partitionStore = Layer.unwrap(\n Effect.map(SubscriptionPartitionIdentity, ({ partition }) =>\n doSubscriptionStoreLayer(partition).pipe(\n Layer.provide(transactionLayer),\n Layer.provide(sqlLayer),\n ),\n ),\n );\n\n const application = Layer.mergeAll(\n Subscriptions.layer(limits),\n SubscriptionIntake.layer(limits),\n SubscriptionDriver.layer(limits),\n cloudflareLimitsLayer,\n ).pipe(\n Layer.provideMerge(partitionStore),\n Layer.provide(\n cloudflarePreparedInputAdmissionLayer.pipe(Layer.provide(CloudflareThreadClient.layer)),\n ),\n Layer.provide(BrowserCrypto.layer),\n Layer.provideMerge(DurableObjectAlarm.DurableObjectAlarm.layer),\n Layer.provide(host),\n Layer.provideMerge(identityLayer),\n );\n\n const runtime: Layer.Layer<\n SubscriptionRuntimeServices,\n E | SubscriptionError | SubscriptionPartitionProtocolError | CloudflareSubscriptionConfigError,\n EffectCfDurableObjectState.DurableObjectState | WorkerEnvironment\n > = Layer.effectContext(\n Effect.gen(function* () {\n const state = yield* EffectCfDurableObjectState.DurableObjectState;\n const scope = yield* Effect.scope;\n\n return yield* state.blockConcurrencyWhile(Layer.buildWithScope(application, scope));\n }),\n );\n\n const rpc = {\n subscription: (encoded: unknown) => handleRequest(encoded),\n } satisfies EffectCfDurableObject.DurableObjectRpc<SubscriptionRuntimeServices>;\n\n const Base = EffectCfDurableObject.make(runtime, {\n initialize: Effect.void,\n rpc,\n alarms: alarmHandler(limits),\n });\n\n class SubscriptionPartitionObject extends Base {\n override alarm(alarmInfo?: AlarmInvocationInfo): Promise<void> | void {\n return super.alarm?.(alarmInfo);\n }\n }\n\n return SubscriptionPartitionObject;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,MAAM,yBAAyB;AAC/B,MAAM,wBAAwB;AAC9B,MAAM,wBAAwB;AAE9B,MAAM,2BAA2B,OAAO,OAAO;CAC7C,eAAe,OAAO,QAAQ,CAAC;CAC/B,YAAY,OAAO,IAAI,MAAM,OAAO,cAAc,CAAC,CAAC;AACtD,CAAC;AAED,IAAa,iCAAb,cAAoD,OAAO,YAA4C,CAAC,CACtG,kCACA,EAAE,SAAS,OAAO,OAAO,CAC3B,CAAC,CAAC,CAAC;AAEH,IAAa,qCAAb,cAAwD,OAAO,YAAgD,CAAC,CAC9G,sCACA,EAAE,SAAS,OAAO,OAAO,MAAM,OAAO,YAAY,IAAK,CAAC,EAAE,CAC5D,CAAC,CAAC,CAAC;AAEH,IAAa,oCAAb,cAAuD,OAAO,YAA+C,CAAC,CAC5G,qCACA,EAAE,SAAS,OAAO,OAAO,CAC3B,CAAC,CAAC,CAAC;;AAGH,MAAa,wCACX,WAC2D;CAI3D,OAFE,IAAI,KAAK,KAAK,OAAO,YAAY,OAAO,WAAW,IAAI,OAAO,0BAEtC,wBACtB,OAAO,OACP,OAAO,KACL,kCAAkC,KAAK,EACrC,SAAS,8EACX,CAAC,CACH;AACN;AAEA,MAAM,mBAAmB,YACvB,QAAQ,UAAU,OAAQ,UAAU,GAAG,QAAQ,MAAM,GAAG,IAAK,EAAE;AAEjE,MAAM,mBAAmB,OAAO,aAAa,aAAa;CACxD,eAAe,OAAO,QAAQ,CAAC;CAC/B,OAAO,OAAO,OAAO,EACnB,GAAG,kBAAkB,OACvB,CAAC;CACD,SAAS,OAAO,OAAO;EACrB,gBAAgB,gBAAgB,OAAO;EACvC,QAAQ;EACR,YAAY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AAO,IAAIA,mBAA2B,qBAAqB,UACzD,aAAa,MAAM,EAAE,SAAS,MAAM,IAAI,QAAQ,CAAC,CACnD,CACF;CAEA,MAAM,iBAAiB,MAAM,OAC3B,OAAO,IAAI,gCAAgC,EAAE,gBAC3C,yBAAyB,SAAS,CAAC,CAAC,KAClC,MAAM,QAAQ,gBAAgB,GAC9B,MAAM,QAAQ,QAAQ,CACxB,CACF,CACF;CAEA,MAAM,cAAc,MAAM,SACxB,cAAc,MAAM,MAAM,GAC1B,mBAAmB,MAAM,MAAM,GAC/B,mBAAmB,MAAM,MAAM,GAC/B,qBACF,CAAC,CAAC,KACA,MAAM,aAAa,cAAc,GACjC,MAAM,QACJ,sCAAsC,KAAK,MAAM,QAAQ,uBAAuB,KAAK,CAAC,CACxF,GACA,MAAM,QAAQ,cAAc,KAAK,GACjC,MAAM,aAAa,mBAAmB,mBAAmB,KAAK,GAC9D,MAAM,QAAQ,IAAI,GAClB,MAAM,aAAa,aAAa,CAClC;CAEA,MAAM,UAIF,MAAM,cACR,OAAO,IAAI,aAAa;EACtB,MAAM,QAAQ,OAAOA,mBAA2B;EAChD,MAAM,QAAQ,OAAO,OAAO;EAE5B,OAAO,OAAO,MAAM,sBAAsB,MAAM,eAAe,aAAa,KAAK,CAAC;CACpF,CAAC,CACH;CAMA,MAAM,OAAOC,cAAsB,KAAK,SAAS;EAC/C,YAAY,OAAO;EACnB,KAAA,EALA,eAAe,YAAqB,cAAc,OAAO,EAKvD;EACF,QAAQ,aAAa,MAAM;CAC7B,CAAC;CAED,MAAM,oCAAoC,KAAK;EAC7C,MAAe,WAAuD;GACpE,OAAO,MAAM,QAAQ,SAAS;EAChC;CACF;CAEA,OAAO;AACT"}
1
+ {"version":3,"file":"CloudflareSubscriptions.mjs","names":["EffectCfDurableObjectState","EffectCfDurableObject"],"sources":["../src/CloudflareSubscriptions.ts"],"sourcesContent":["import {\n DoSubscriptionAlarmControl,\n DoSubscriptionTransaction,\n doSubscriptionStoreLayer,\n} from \"@effect-agent/storage-cloudflare/DoSubscriptionStore\";\nimport { type EventSources } from \"@effect-agent/thread/EventSource\";\nimport { PersistedJson } from \"@effect-agent/thread/Records\";\nimport { Principal } from \"@effect-agent/thread/SubmissionLedger\";\nimport {\n EventAcknowledgement,\n EventSourceVersion,\n SourcePartition,\n type SubscriptionAuthorizer,\n SubscriptionConfiguration,\n SubscriptionDeliverySnapshot,\n SubscriptionDeliveryKey,\n SubscriptionError,\n SubscriptionFailpointError,\n SubscriptionKey,\n SubscriptionScope,\n type SubscriptionLimits,\n SubscriptionSnapshot,\n SubscriptionSourceError,\n defaultSubscriptionLimits,\n} from \"@effect-agent/thread/Subscription\";\nimport { type SubscriptionInputBindings } from \"@effect-agent/thread/SubscriptionInput\";\nimport {\n SubscriptionDriver,\n SubscriptionIntake,\n Subscriptions,\n} from \"@effect-agent/thread/Subscriptions\";\nimport { BrowserCrypto } from \"@effect/platform-browser\";\nimport { SqliteClient } from \"@effect/sql-sqlite-do\";\nimport { Cause, Clock, Context, DateTime, Effect, Layer, Schema, type Scope } from \"effect\";\nimport {\n DurableObject as EffectCfDurableObject,\n DurableObjectAlarm,\n DurableObjectState as EffectCfDurableObjectState,\n type WorkerEnvironment,\n} from \"effect-cf\";\n\nimport { type ThreadObjectNamespace } from \"./CloudflareBindings.ts\";\nimport { CloudflareThreadClient } from \"./CloudflareThreadClient.ts\";\nimport { cloudflarePreparedInputAdmissionLayer } from \"./internal/prepared-admission.ts\";\n\nconst SUBSCRIPTION_ALARM_TAG = \"effect-agent/SubscriptionPartitionWake\";\nconst SUBSCRIPTION_ALARM_ID = \"driver\";\nconst MAX_ALARM_WALL_MILLIS = 12 * 60_000;\nconst MAX_ALARMS_PER_INVOCATION = 16;\nconst MAX_ANCILLARY_ALARM_MILLIS = 30_000;\n\nconst SubscriptionAlarmPayload = Schema.Struct({\n schemaVersion: Schema.Literal(1),\n generation: Schema.Int.check(Schema.isGreaterThan(0)),\n});\n\nexport class SubscriptionAlarmProtocolError extends Schema.TaggedError<SubscriptionAlarmProtocolError>()(\n \"SubscriptionAlarmProtocolError\",\n { message: Schema.String },\n) {}\n\n/** Bounded host diagnostic; credentials and provider responses do not belong in alarm failures. */\nexport class SubscriptionAlarmExtensionError extends Schema.TaggedError<SubscriptionAlarmExtensionError>()(\n \"SubscriptionAlarmExtensionError\",\n { code: Schema.NonEmptyString.check(Schema.isMaxLength(128)) },\n) {}\n\n/** Native partition services supplied at alarm invocation, after the host Layer is built. */\nexport type SubscriptionPartitionAlarmServices =\n | Subscriptions\n | SubscriptionIntake\n | SubscriptionDriver;\n\nexport interface SubscriptionPartitionAlarmHandler<R = SubscriptionPartitionAlarmServices> {\n readonly tag: string;\n readonly handle: (\n event: DurableObjectAlarm.DurableObjectAlarmEvent,\n ) => Effect.Effect<void, SubscriptionAlarmProtocolError | SubscriptionAlarmExtensionError, R>;\n}\n\n/** Host-only handlers; the framework reserves its namespace and rejects every unknown tag. */\nexport const SubscriptionPartitionAlarmExtension = Context.Reference<{\n readonly handlers: ReadonlyArray<SubscriptionPartitionAlarmHandler>;\n}>(\"@effect-agent/platform-cloudflare/SubscriptionPartitionAlarmExtension\", {\n defaultValue: () => ({ handlers: [] }),\n});\n\n/** Capture host services once, deferring native partition services to invocation.\n * Each invocation owns its codec/handler Scope and timeout.\n * Callback failures stay typed. Defects and interruption reach the native alarm multiplexer.\n * The host owns durable idempotency, prearming and external-effect uncertainty.\n */\nexport const makeSubscriptionPartitionAlarmHandler = Effect.fn(\n \"makeSubscriptionPartitionAlarmHandler\",\n)(function* <Payload extends Schema.Top, R>(options: {\n readonly tag: string;\n readonly payload: Payload;\n readonly timeoutMillis: number;\n readonly handle: (\n event: Omit<DurableObjectAlarm.DurableObjectAlarmEvent, \"payload\"> & {\n readonly payload: Payload[\"Type\"];\n },\n ) => Effect.Effect<void, SubscriptionAlarmExtensionError, R>;\n}): Effect.fn.Return<\n SubscriptionPartitionAlarmHandler<\n Exclude<\n Exclude<R | Payload[\"DecodingServices\"], Scope.Scope>,\n Exclude<\n Exclude<R | Payload[\"DecodingServices\"], Scope.Scope | SubscriptionPartitionAlarmServices>,\n SubscriptionPartitionAlarmServices\n >\n >\n >,\n SubscriptionAlarmProtocolError,\n Exclude<R | Payload[\"DecodingServices\"], Scope.Scope | SubscriptionPartitionAlarmServices>\n> {\n if (\n options.tag.length === 0 ||\n options.tag.length > 128 ||\n options.tag.startsWith(\"effect-agent/\") ||\n !Number.isSafeInteger(options.timeoutMillis) ||\n options.timeoutMillis < 1 ||\n options.timeoutMillis > MAX_ANCILLARY_ALARM_MILLIS\n )\n return yield* SubscriptionAlarmProtocolError.make({\n message: \"Invalid ancillary alarm tag or timeout\",\n });\n\n // Context capture includes unrequested services too; never retain a host override of native work.\n const services = (yield* Effect.context<\n Exclude<R | Payload[\"DecodingServices\"], Scope.Scope | SubscriptionPartitionAlarmServices>\n >()).pipe(Context.omit(Subscriptions, SubscriptionIntake, SubscriptionDriver));\n\n return {\n tag: options.tag,\n handle: (event) =>\n Effect.gen(function* () {\n if (event.tag !== options.tag)\n return yield* SubscriptionAlarmProtocolError.make({\n message: \"Ancillary alarm tag mismatch\",\n });\n\n const payload = yield* Schema.decodeUnknownEffect(options.payload)(event.payload).pipe(\n Effect.mapError(() =>\n SubscriptionAlarmProtocolError.make({ message: \"Invalid ancillary alarm payload\" }),\n ),\n );\n\n yield* options.handle({ ...event, payload });\n }).pipe(\n Effect.scoped,\n Effect.timeout(options.timeoutMillis),\n Effect.catchTag(\"TimeoutError\", () =>\n SubscriptionAlarmExtensionError.make({ code: \"timeout\" }),\n ),\n Effect.provideContext(services),\n ),\n };\n});\n\nexport class SubscriptionPartitionProtocolError extends Schema.TaggedError<SubscriptionPartitionProtocolError>()(\n \"SubscriptionPartitionProtocolError\",\n { message: Schema.String.check(Schema.isMaxLength(4_096)) },\n) {}\n\nexport class CloudflareSubscriptionConfigError extends Schema.TaggedError<CloudflareSubscriptionConfigError>()(\n \"CloudflareSubscriptionConfigError\",\n { message: Schema.String },\n) {}\n\n/** Reject limits whose four bounded phases could exceed the safe Durable Object alarm budget. */\nexport const validateCloudflareSubscriptionLimits = (\n limits: SubscriptionLimits,\n options: { readonly ancillaryAlarms?: boolean } = {},\n): Effect.Effect<void, CloudflareSubscriptionConfigError> => {\n const worstCaseMillis =\n 4 * Math.ceil(limits.batchSize / limits.concurrency) * limits.operationTimeoutMillis +\n (options.ancillaryAlarms === true ? MAX_ALARMS_PER_INVOCATION * MAX_ANCILLARY_ALARM_MILLIS : 0);\n\n return worstCaseMillis <= MAX_ALARM_WALL_MILLIS\n ? Effect.void\n : Effect.fail(\n CloudflareSubscriptionConfigError.make({\n message: \"Subscription limits can exceed the bounded Durable Object alarm wall budget\",\n }),\n );\n};\n\nconst protocolMessage = (message: string): string =>\n message.length <= 4_096 ? message : `${message.slice(0, 4_093)}...`;\n\nconst SubscribeRequest = Schema.TaggedStruct(\"Subscribe\", {\n schemaVersion: Schema.Literal(1),\n scope: Schema.Struct({\n ...SubscriptionScope.fields,\n }),\n options: Schema.Struct({\n subscriptionId: SubscriptionKey.fields.subscriptionId,\n source: EventSourceVersion,\n parameters: PersistedJson,\n context: PersistedJson,\n mode: Schema.Literals([\"once\", \"continuous\"]),\n expiresAtMillis: Schema.NullOr(Schema.Number),\n destination: SubscriptionConfiguration.fields.destination,\n deliveryPrincipal: SubscriptionConfiguration.fields.deliveryPrincipal,\n admissionGroup: SubscriptionConfiguration.fields.admissionGroup,\n admissionFence: SubscriptionConfiguration.fields.admissionFence,\n agentId: SubscriptionConfiguration.fields.agentId,\n definitions: SubscriptionConfiguration.fields.definitions,\n }),\n});\n\nconst UpdateSubscriptionRequest = Schema.TaggedStruct(\"UpdateSubscription\", {\n schemaVersion: Schema.Literal(1),\n scope: SubscribeRequest.fields.scope,\n key: SubscriptionKey,\n expectedRevision: Schema.Int.check(Schema.isGreaterThan(0)),\n options: SubscribeRequest.fields.options.mapFields(({ subscriptionId: _, ...fields }) => fields),\n});\n\nconst SubscriptionStateRequest = Schema.Struct({\n _tag: Schema.Literals([\"PauseSubscription\", \"ResumeSubscription\", \"RecoverSubscription\"]),\n schemaVersion: Schema.Literal(1),\n scope: SubscribeRequest.fields.scope,\n key: SubscriptionKey,\n expectedRevision: Schema.Int.check(Schema.isGreaterThan(0)),\n});\n\nconst ListSubscriptionsRequest = Schema.TaggedStruct(\"ListSubscriptions\", {\n schemaVersion: Schema.Literal(1),\n scope: SubscribeRequest.fields.scope,\n after: Schema.optionalKey(Schema.Natural),\n limit: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThan(0))),\n});\n\nconst CancelSubscriptionRequest = Schema.TaggedStruct(\"CancelSubscription\", {\n expectedRevision: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThan(0))),\n schemaVersion: Schema.Literal(1),\n scope: SubscribeRequest.fields.scope,\n key: SubscriptionKey,\n});\n\nconst GetSubscriptionRequest = Schema.TaggedStruct(\"GetSubscription\", {\n schemaVersion: Schema.Literal(1),\n scope: SubscriptionScope,\n key: SubscriptionKey,\n});\n\nconst RecoverDeliveryRequest = Schema.TaggedStruct(\"RecoverDelivery\", {\n expectedGeneration: Schema.Natural,\n schemaVersion: Schema.Literal(1),\n scope: SubscribeRequest.fields.scope,\n key: SubscriptionDeliveryKey,\n});\n\nconst ListDeliveriesRequest = Schema.TaggedStruct(\"ListDeliveries\", {\n schemaVersion: Schema.Literal(1),\n scope: SubscribeRequest.fields.scope,\n key: SubscriptionKey,\n after: Schema.optionalKey(Schema.String),\n limit: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThan(0))),\n});\n\nconst AcceptRequest = Schema.TaggedStruct(\"Accept\", {\n schemaVersion: Schema.Literal(1),\n partition: SourcePartition,\n principal: Principal,\n source: EventSourceVersion,\n payload: PersistedJson,\n});\n\nconst StatusRequest = Schema.TaggedStruct(\"Status\", {\n schemaVersion: Schema.Literal(1),\n partition: SourcePartition,\n principal: Principal,\n source: EventSourceVersion,\n eventId: Schema.String,\n});\n\nconst SubscriptionPartitionRequest = Schema.Union([\n SubscribeRequest,\n GetSubscriptionRequest,\n UpdateSubscriptionRequest,\n SubscriptionStateRequest,\n ListSubscriptionsRequest,\n CancelSubscriptionRequest,\n ListDeliveriesRequest,\n RecoverDeliveryRequest,\n AcceptRequest,\n StatusRequest,\n]);\n\ntype SubscriptionPartitionRequest = typeof SubscriptionPartitionRequest.Type;\n\nconst SubscriptionPage = Schema.Struct({\n items: Schema.Array(SubscriptionSnapshot),\n next: Schema.NullOr(Schema.Natural),\n});\n\nconst DeliveryPage = Schema.Struct({\n items: Schema.Array(SubscriptionDeliverySnapshot),\n next: Schema.NullOr(Schema.String),\n});\n\nconst IntakeStatus = Schema.Struct({\n ...EventAcknowledgement.fields,\n routingComplete: Schema.Boolean,\n routingFailure: Schema.NullOr(Schema.String),\n nextAttemptAtMillis: Schema.Number,\n});\n\nconst SubscriptionPartitionFailure = Schema.Union([\n SubscriptionError,\n SubscriptionSourceError,\n SubscriptionFailpointError,\n SubscriptionPartitionProtocolError,\n]);\n\ntype SubscriptionPartitionFailure = typeof SubscriptionPartitionFailure.Type;\n\nconst SubscriptionPartitionResponse = Schema.Union([\n Schema.TaggedStruct(\"Snapshot\", { value: SubscriptionSnapshot }),\n Schema.TaggedStruct(\"SubscriptionPage\", { value: SubscriptionPage }),\n Schema.TaggedStruct(\"DeliveryPage\", { value: DeliveryPage }),\n Schema.TaggedStruct(\"DeliverySnapshot\", { value: SubscriptionDeliverySnapshot }),\n Schema.TaggedStruct(\"Acknowledgement\", { value: EventAcknowledgement }),\n Schema.TaggedStruct(\"Status\", { value: IntakeStatus }),\n Schema.TaggedStruct(\"Failed\", { failure: SubscriptionPartitionFailure }),\n]);\n\ntype SubscriptionPartitionResponse = typeof SubscriptionPartitionResponse.Type;\n\nconst decodeRequest = Schema.decodeUnknownEffect(SubscriptionPartitionRequest);\nconst encodeRequest = Schema.encodeEffect(SubscriptionPartitionRequest);\nconst decodeResponse = Schema.decodeUnknownEffect(SubscriptionPartitionResponse);\nconst encodeResponse = Schema.encodeEffect(SubscriptionPartitionResponse);\n\nconst protocolFailure = (message: string): SubscriptionPartitionResponse => ({\n _tag: \"Failed\",\n failure: SubscriptionPartitionProtocolError.make({ message: protocolMessage(message) }),\n});\n\nexport const sourcePartitionName = (partition: SourcePartition): string =>\n JSON.stringify([partition.tenantId, partition.address]);\n\nexport interface SubscriptionPartitionObjectRpc extends Rpc.DurableObjectBranded {\n subscription(encoded: unknown): Promise<unknown>;\n}\n\nexport class SubscriptionPartitionNamespace extends Context.Service<\n SubscriptionPartitionNamespace,\n { readonly namespace: DurableObjectNamespace<SubscriptionPartitionObjectRpc> }\n>()(\"@effect-agent/platform-cloudflare/SubscriptionPartitionNamespace\") {}\n\nconst storageFailure = (code: string): SubscriptionError =>\n SubscriptionError.make({ reason: \"storage\", code });\n\nconst corruptFailure = (code: string): SubscriptionError =>\n SubscriptionError.make({ reason: \"corrupt\", code });\n\n/** Worker-side management and trusted intake, routed to one fresh partition stub per call. */\nexport class CloudflareSubscriptionsClient {\n static layer(\n partition: SourcePartition,\n ): Layer.Layer<Subscriptions | SubscriptionIntake, never, SubscriptionPartitionNamespace> {\n return Layer.effectContext(\n Effect.gen(function* () {\n const { namespace } = yield* SubscriptionPartitionNamespace;\n\n const call = Effect.fn(\"CloudflareSubscriptionsClient.call\")(function* (\n addressedPartition: SourcePartition,\n request: SubscriptionPartitionRequest,\n ) {\n if (!samePartition(partition, addressedPartition)) {\n return yield* SubscriptionError.make({ reason: \"unauthorized\", code: \"partition\" });\n }\n\n const encoded = yield* encodeRequest(request).pipe(\n Effect.mapError(() => corruptFailure(\"subscription-partition-protocol\")),\n );\n\n const raw = yield* Effect.tryPromise({\n try: () =>\n namespace\n .get(namespace.idFromName(sourcePartitionName(partition)))\n .subscription(encoded),\n catch: () => storageFailure(\"call-subscription-partition\"),\n });\n\n return yield* decodeResponse(raw).pipe(\n Effect.mapError(() => corruptFailure(\"subscription-partition-protocol\")),\n );\n });\n\n const failed = (response: SubscriptionPartitionResponse): SubscriptionPartitionFailure =>\n response._tag === \"Failed\"\n ? response.failure\n : SubscriptionPartitionProtocolError.make({\n message: \"Unexpected subscription response\",\n });\n\n const asProtocolError = (): SubscriptionError =>\n corruptFailure(\"subscription-partition-protocol\");\n\n const changeState = Effect.fn(\"CloudflareSubscriptions.changeState\")(function* (\n scope: typeof SubscriptionScope.Type,\n key: typeof SubscriptionKey.Type,\n expectedRevision: number,\n _tag: \"PauseSubscription\" | \"ResumeSubscription\" | \"RecoverSubscription\",\n ) {\n const response = yield* call(scope.partition, {\n _tag,\n schemaVersion: 1,\n scope,\n key,\n expectedRevision,\n });\n\n if (response._tag === \"Snapshot\") return response.value;\n const failure = failed(response);\n\n return yield* failure._tag === \"SubscriptionError\" ||\n failure._tag === \"SubscriptionFailpointError\"\n ? failure\n : asProtocolError();\n });\n\n const subscriptions = Subscriptions.of({\n recoverSubscription: (scope, key, revision) =>\n changeState(scope, key, revision, \"RecoverSubscription\"),\n getSubscription: (scope, key) =>\n Effect.gen(function* () {\n const response = yield* call(scope.partition, {\n _tag: \"GetSubscription\",\n schemaVersion: 1,\n scope,\n key,\n });\n\n if (response._tag === \"Snapshot\") return response.value;\n const failure = failed(response);\n\n return yield* failure._tag === \"SubscriptionError\" ? failure : asProtocolError();\n }),\n recoverDelivery: (scope, key, expectedGeneration) =>\n Effect.gen(function* () {\n const response = yield* call(scope.partition, {\n _tag: \"RecoverDelivery\",\n expectedGeneration,\n schemaVersion: 1,\n scope,\n key,\n });\n\n if (response._tag === \"DeliverySnapshot\") return response.value;\n const failure = failed(response);\n\n return yield* failure._tag === \"SubscriptionError\" ||\n failure._tag === \"SubscriptionFailpointError\"\n ? failure\n : asProtocolError();\n }),\n updateSubscription: (scope, key, expectedRevision, options) =>\n Effect.gen(function* () {\n const response = yield* call(scope.partition, {\n _tag: \"UpdateSubscription\",\n schemaVersion: 1,\n scope,\n key,\n expectedRevision,\n options,\n });\n\n if (response._tag === \"Snapshot\") return response.value;\n const failure = failed(response);\n\n return yield* failure._tag === \"SubscriptionError\" ||\n failure._tag === \"SubscriptionFailpointError\" ||\n failure._tag === \"SubscriptionSourceError\"\n ? failure\n : asProtocolError();\n }),\n pauseSubscription: (scope, key, revision) =>\n changeState(scope, key, revision, \"PauseSubscription\"),\n resumeSubscription: (scope, key, revision) =>\n changeState(scope, key, revision, \"ResumeSubscription\"),\n subscribe: (scope, options) =>\n Effect.gen(function* () {\n const response = yield* call(scope.partition, {\n _tag: \"Subscribe\",\n schemaVersion: 1,\n scope,\n options,\n });\n\n if (response._tag === \"Snapshot\") return response.value;\n const failure = failed(response);\n\n if (\n failure._tag === \"SubscriptionError\" ||\n failure._tag === \"SubscriptionSourceError\" ||\n failure._tag === \"SubscriptionFailpointError\"\n )\n return yield* failure;\n\n return yield* asProtocolError();\n }),\n listSubscriptions: (scope, after, limit) =>\n Effect.gen(function* () {\n const response = yield* call(scope.partition, {\n _tag: \"ListSubscriptions\",\n schemaVersion: 1,\n scope,\n ...(after === undefined ? {} : { after }),\n ...(limit === undefined ? {} : { limit }),\n });\n\n if (response._tag === \"SubscriptionPage\") return response.value;\n const failure = failed(response);\n\n return yield* failure._tag === \"SubscriptionError\" ? failure : asProtocolError();\n }),\n cancelSubscription: (scope, key, expectedRevision) =>\n Effect.gen(function* () {\n const response = yield* call(scope.partition, {\n _tag: \"CancelSubscription\",\n ...(expectedRevision === undefined ? {} : { expectedRevision }),\n schemaVersion: 1,\n scope,\n key,\n });\n\n if (response._tag === \"Snapshot\") return response.value;\n const failure = failed(response);\n\n if (\n failure._tag === \"SubscriptionError\" ||\n failure._tag === \"SubscriptionFailpointError\"\n )\n return yield* failure;\n\n return yield* asProtocolError();\n }),\n listDeliveries: (scope, key, after, limit) =>\n Effect.gen(function* () {\n const response = yield* call(scope.partition, {\n _tag: \"ListDeliveries\",\n schemaVersion: 1,\n scope,\n key,\n ...(after === undefined ? {} : { after }),\n ...(limit === undefined ? {} : { limit }),\n });\n\n if (response._tag === \"DeliveryPage\") return response.value;\n const failure = failed(response);\n\n return yield* failure._tag === \"SubscriptionError\" ? failure : asProtocolError();\n }),\n });\n\n const intake = SubscriptionIntake.of({\n accept: (principal, source, payload) =>\n Effect.gen(function* () {\n const request = yield* Schema.decodeUnknownEffect(AcceptRequest)({\n _tag: \"Accept\",\n schemaVersion: 1,\n partition,\n principal,\n source,\n payload,\n }).pipe(\n Effect.mapError(() =>\n SubscriptionError.make({ reason: \"validation\", code: \"event-payload\" }),\n ),\n );\n\n const response = yield* call(request.partition, request);\n\n if (response._tag === \"Acknowledgement\") return response.value;\n const failure = failed(response);\n\n if (\n failure._tag === \"SubscriptionError\" ||\n failure._tag === \"SubscriptionSourceError\" ||\n failure._tag === \"SubscriptionFailpointError\"\n )\n return yield* failure;\n\n return yield* asProtocolError();\n }),\n status: (principal, source, eventId) =>\n Effect.gen(function* () {\n const response = yield* call(partition, {\n _tag: \"Status\",\n schemaVersion: 1,\n partition,\n principal,\n source,\n eventId,\n });\n\n if (response._tag === \"Status\") return response.value;\n const failure = failed(response);\n\n return yield* failure._tag === \"SubscriptionError\" ? failure : asProtocolError();\n }),\n });\n\n return Context.make(Subscriptions, subscriptions).pipe(\n Context.add(SubscriptionIntake, intake),\n );\n }),\n );\n }\n}\n\nexport class SubscriptionPartitionIdentity extends Context.Service<\n SubscriptionPartitionIdentity,\n { readonly partition: SourcePartition }\n>()(\"@effect-agent/platform-cloudflare/SubscriptionPartitionIdentity\") {}\n\nconst decodePartitionName = Effect.fn(\"decodeSubscriptionPartitionName\")(function* (\n name: string | null | undefined,\n) {\n if (name === null || name === undefined) {\n return yield* SubscriptionPartitionProtocolError.make({\n message: \"Subscription Partition objects require an idFromName identity\",\n });\n }\n\n const tuple = yield* Schema.decodeUnknownEffect(\n Schema.fromJsonString(Schema.Tuple([Schema.String, Schema.String])),\n )(name).pipe(\n Effect.mapError(() =>\n SubscriptionPartitionProtocolError.make({\n message: \"Subscription Partition name is malformed\",\n }),\n ),\n );\n\n return yield* Schema.decodeUnknownEffect(SourcePartition)({\n tenantId: tuple[0],\n address: tuple[1],\n }).pipe(\n Effect.mapError(() =>\n SubscriptionPartitionProtocolError.make({\n message: \"Subscription Partition identity is invalid\",\n }),\n ),\n );\n});\n\nconst samePartition = Schema.toEquivalence(SourcePartition);\n\nconst requestPartition = (request: SubscriptionPartitionRequest): SourcePartition =>\n request._tag === \"Accept\" || request._tag === \"Status\"\n ? request.partition\n : request.scope.partition;\n\nconst handleRequest = Effect.fn(\"SubscriptionPartition.handleRequest\")(function* (\n encoded: unknown,\n) {\n const decoded = yield* decodeRequest(encoded).pipe(Effect.result);\n\n if (decoded._tag === \"Failure\") {\n return yield* encodeResponse(\n protocolFailure(\"The subscription request could not be decoded\"),\n ).pipe(Effect.orDie);\n }\n const request = decoded.success;\n const { partition } = yield* SubscriptionPartitionIdentity;\n\n if (!samePartition(partition, requestPartition(request))) {\n return yield* encodeResponse(\n protocolFailure(\"The request partition does not match the addressed object\"),\n ).pipe(Effect.orDie);\n }\n const subscriptions = yield* Subscriptions;\n const intake = yield* SubscriptionIntake;\n\n const response = yield* Effect.gen(function* (): Effect.fn.Return<\n SubscriptionPartitionResponse,\n SubscriptionPartitionFailure\n > {\n switch (request._tag) {\n case \"GetSubscription\":\n return {\n _tag: \"Snapshot\",\n value: yield* subscriptions.getSubscription(request.scope, request.key),\n };\n case \"Subscribe\":\n return {\n _tag: \"Snapshot\",\n value: yield* subscriptions.subscribe(request.scope, request.options),\n };\n case \"UpdateSubscription\":\n return {\n _tag: \"Snapshot\",\n value: yield* subscriptions.updateSubscription(\n request.scope,\n request.key,\n request.expectedRevision,\n request.options,\n ),\n };\n case \"RecoverSubscription\":\n return {\n _tag: \"Snapshot\",\n value: yield* subscriptions.recoverSubscription(\n request.scope,\n request.key,\n request.expectedRevision,\n ),\n };\n case \"PauseSubscription\":\n return {\n _tag: \"Snapshot\",\n value: yield* subscriptions.pauseSubscription(\n request.scope,\n request.key,\n request.expectedRevision,\n ),\n };\n case \"ResumeSubscription\":\n return {\n _tag: \"Snapshot\",\n value: yield* subscriptions.resumeSubscription(\n request.scope,\n request.key,\n request.expectedRevision,\n ),\n };\n case \"ListSubscriptions\":\n return {\n _tag: \"SubscriptionPage\",\n value: yield* subscriptions.listSubscriptions(\n request.scope,\n request.after,\n request.limit,\n ),\n };\n case \"CancelSubscription\":\n return {\n _tag: \"Snapshot\",\n value: yield* subscriptions.cancelSubscription(\n request.scope,\n request.key,\n request.expectedRevision,\n ),\n };\n case \"RecoverDelivery\":\n return {\n _tag: \"DeliverySnapshot\",\n value: yield* subscriptions.recoverDelivery(\n request.scope,\n request.key,\n request.expectedGeneration,\n ),\n };\n case \"ListDeliveries\":\n return {\n _tag: \"DeliveryPage\",\n value: yield* subscriptions.listDeliveries(\n request.scope,\n request.key,\n request.after,\n request.limit,\n ),\n };\n case \"Accept\":\n return {\n _tag: \"Acknowledgement\",\n value: yield* intake.accept(request.principal, request.source, request.payload),\n };\n case \"Status\":\n return {\n _tag: \"Status\",\n value: yield* intake.status(request.principal, request.source, request.eventId),\n };\n }\n }).pipe(\n Effect.catch((failure) =>\n Schema.is(SubscriptionPartitionFailure)(failure)\n ? Effect.succeed({ _tag: \"Failed\" as const, failure })\n : Effect.succeed(protocolFailure(\"The subscription operation failed outside its contract\")),\n ),\n );\n\n return yield* encodeResponse(response).pipe(Effect.orDie);\n});\n\nconst alarmStorageError = (code: string) => () => storageFailure(code);\n\nconst transactionLayer: Layer.Layer<\n DoSubscriptionTransaction,\n never,\n DurableObjectAlarm.DurableObjectAlarm\n> = Layer.effect(\n DoSubscriptionTransaction,\n Effect.gen(function* () {\n const alarms = yield* DurableObjectAlarm.DurableObjectAlarm;\n\n return DoSubscriptionTransaction.of({\n run: (body) =>\n Effect.gen(function* () {\n const nowMillis = yield* Clock.currentTimeMillis;\n\n return yield* alarms\n .transaction((transaction) =>\n body((replacement) =>\n replacement.deadlineAtMillis === null\n ? transaction\n .cancelAlarm({ id: SUBSCRIPTION_ALARM_ID, tag: SUBSCRIPTION_ALARM_TAG })\n .pipe(Effect.mapError(alarmStorageError(\"cancel-subscription-alarm\")))\n : Effect.fromOption(\n DateTime.make(Math.max(replacement.deadlineAtMillis, nowMillis + 1)),\n ).pipe(\n Effect.mapError(() => corruptFailure(\"subscription-alarm-deadline\")),\n Effect.flatMap((runAt) =>\n transaction\n .scheduleAlarm({\n id: SUBSCRIPTION_ALARM_ID,\n tag: SUBSCRIPTION_ALARM_TAG,\n runAt,\n payload: { schemaVersion: 1, generation: replacement.generation },\n })\n .pipe(Effect.mapError(alarmStorageError(\"schedule-subscription-alarm\"))),\n ),\n ),\n ),\n )\n .pipe(\n Effect.catchTag(\"StorageOperationError\", () =>\n storageFailure(\"commit-subscription-transaction\"),\n ),\n );\n }),\n });\n }),\n);\n\nconst alarmHandler = (limits: SubscriptionLimits) =>\n DurableObjectAlarm.processDue(\n (event) =>\n Effect.gen(function* () {\n if (event.tag !== SUBSCRIPTION_ALARM_TAG) {\n const { handlers } = yield* SubscriptionPartitionAlarmExtension;\n const matches = handlers.filter((handler) => handler.tag === event.tag);\n const handler = matches[0];\n\n if (\n event.tag.startsWith(\"effect-agent/\") ||\n matches.length !== 1 ||\n handler === undefined\n )\n return yield* SubscriptionAlarmProtocolError.make({\n message: \"Unknown or ambiguous ancillary alarm tag\",\n });\n\n return yield* handler.handle(event).pipe(\n Effect.scoped,\n Effect.timeout(MAX_ANCILLARY_ALARM_MILLIS),\n Effect.catchTag(\"TimeoutError\", () =>\n SubscriptionAlarmExtensionError.make({ code: \"timeout\" }),\n ),\n );\n }\n if (event.id !== SUBSCRIPTION_ALARM_ID) {\n return yield* SubscriptionAlarmProtocolError.make({\n message: `Unsupported Subscription Partition alarm ${event.tag}/${event.id}`,\n });\n }\n yield* Schema.decodeUnknownEffect(SubscriptionAlarmPayload)(event.payload).pipe(\n Effect.mapError(() =>\n SubscriptionAlarmProtocolError.make({\n message: \"Unsupported subscription alarm payload\",\n }),\n ),\n );\n const driver = yield* SubscriptionDriver;\n const alarmControl = yield* DoSubscriptionAlarmControl;\n\n yield* alarmControl.prearm((yield* Clock.currentTimeMillis) + limits.retryMillis);\n\n const pass = yield* driver.runDue.pipe(\n Effect.catchCause((cause) =>\n Cause.hasInterrupts(cause)\n ? Effect.failCause(cause)\n : Clock.currentTimeMillis.pipe(\n Effect.flatMap((time) => alarmControl.prearm(time + limits.retryMillis)),\n Effect.andThen(Effect.failCause(cause)),\n ),\n ),\n );\n\n if (pass.failed > 0) {\n yield* alarmControl.prearm((yield* Clock.currentTimeMillis) + limits.retryMillis);\n } else {\n yield* alarmControl.reconcile;\n }\n }),\n {\n mode: \"isolated\",\n limit: MAX_ALARMS_PER_INVOCATION,\n retryFailedAfter: limits.retryMillis,\n onFailure: () => Effect.logWarning(\"Subscription partition alarm retained for retry\"),\n },\n ).pipe(Effect.asVoid);\n\ntype SubscriptionRuntimeServices =\n | Subscriptions\n | SubscriptionIntake\n | SubscriptionDriver\n | DoSubscriptionAlarmControl\n | SubscriptionPartitionIdentity\n | DurableObjectAlarm.DurableObjectAlarm;\n\nexport interface SubscriptionPartitionObjectInstance extends InstanceType<\n EffectCfDurableObject.DurableObjectClass<Record<never, never>, SubscriptionRuntimeServices>\n> {\n subscription(encoded: unknown): Promise<unknown>;\n alarm(alarmInfo?: AlarmInvocationInfo): Promise<void> | void;\n}\n\nexport interface SubscriptionPartitionObjectClass {\n new (ctx: DurableObjectState, env: Cloudflare.Env): SubscriptionPartitionObjectInstance;\n}\n\n/**\n * Build one source-addressed SQLite Durable Object. The host Layer binds the permitted source\n * catalog and authority. It must not retain cleanup-scoped resources across RPC events.\n */\nexport const makeSubscriptionPartitionObjectClass = <E>(\n host: Layer.Layer<\n SubscriptionAuthorizer | EventSources | SubscriptionInputBindings | ThreadObjectNamespace,\n E,\n | EffectCfDurableObjectState.DurableObjectState\n | WorkerEnvironment\n | SubscriptionPartitionIdentity\n >,\n limits: SubscriptionLimits = defaultSubscriptionLimits,\n): SubscriptionPartitionObjectClass => {\n const cloudflareLimitsLayer = Layer.effectDiscard(validateCloudflareSubscriptionLimits(limits));\n\n const identityLayer = Layer.effect(\n SubscriptionPartitionIdentity,\n Effect.gen(function* () {\n const state = yield* EffectCfDurableObjectState.DurableObjectState;\n\n return SubscriptionPartitionIdentity.of({\n partition: yield* decodePartitionName(state.raw.id.name),\n });\n }),\n );\n\n const sqlLayer = Layer.unwrap(\n Effect.map(EffectCfDurableObjectState.DurableObjectState, (state) =>\n SqliteClient.layer({ storage: state.raw.storage }),\n ),\n );\n\n const partitionStore = Layer.unwrap(\n Effect.map(SubscriptionPartitionIdentity, ({ partition }) =>\n doSubscriptionStoreLayer(partition).pipe(\n Layer.provide(transactionLayer),\n Layer.provide(sqlLayer),\n ),\n ),\n );\n\n const application = Layer.mergeAll(\n Subscriptions.layer(limits),\n SubscriptionIntake.layer(limits),\n SubscriptionDriver.layer(limits),\n cloudflareLimitsLayer,\n // Capture the host reference before its scoped input Layer is hidden from the runtime.\n Layer.effect(\n SubscriptionPartitionAlarmExtension,\n Effect.gen(function* () {\n const extension = yield* SubscriptionPartitionAlarmExtension;\n const tags = extension.handlers.map((handler) => handler.tag);\n\n if (\n tags.length > MAX_ALARMS_PER_INVOCATION ||\n new Set(tags).size !== tags.length ||\n tags.some(\n (tag) => tag.length === 0 || tag.length > 128 || tag.startsWith(\"effect-agent/\"),\n )\n )\n return yield* SubscriptionAlarmProtocolError.make({\n message: \"Invalid ancillary alarm handler registry\",\n });\n\n yield* validateCloudflareSubscriptionLimits(limits, { ancillaryAlarms: tags.length > 0 });\n\n return extension;\n }),\n ),\n ).pipe(\n Layer.provideMerge(partitionStore),\n Layer.provide(\n cloudflarePreparedInputAdmissionLayer.pipe(Layer.provide(CloudflareThreadClient.layer)),\n ),\n Layer.provide(BrowserCrypto.layer),\n Layer.provideMerge(DurableObjectAlarm.DurableObjectAlarm.layer),\n Layer.provide(host),\n Layer.provideMerge(identityLayer),\n );\n\n const runtime: Layer.Layer<\n SubscriptionRuntimeServices,\n | E\n | SubscriptionError\n | SubscriptionPartitionProtocolError\n | CloudflareSubscriptionConfigError\n | SubscriptionAlarmProtocolError,\n EffectCfDurableObjectState.DurableObjectState | WorkerEnvironment\n > = Layer.effectContext(\n Effect.gen(function* () {\n const state = yield* EffectCfDurableObjectState.DurableObjectState;\n const scope = yield* Effect.scope;\n\n return yield* state.blockConcurrencyWhile(Layer.buildWithScope(application, scope));\n }),\n );\n\n const rpc = {\n subscription: (encoded: unknown) => handleRequest(encoded),\n } satisfies EffectCfDurableObject.DurableObjectRpc<SubscriptionRuntimeServices>;\n\n const Base = EffectCfDurableObject.make(runtime, {\n initialize: Effect.void,\n rpc,\n alarms: alarmHandler(limits),\n });\n\n class SubscriptionPartitionObject extends Base {\n override alarm(alarmInfo?: AlarmInvocationInfo): Promise<void> | void {\n return super.alarm?.(alarmInfo);\n }\n }\n\n return SubscriptionPartitionObject;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,MAAM,yBAAyB;AAC/B,MAAM,wBAAwB;AAC9B,MAAM,wBAAwB;AAC9B,MAAM,4BAA4B;AAClC,MAAM,6BAA6B;AAEnC,MAAM,2BAA2B,OAAO,OAAO;CAC7C,eAAe,OAAO,QAAQ,CAAC;CAC/B,YAAY,OAAO,IAAI,MAAM,OAAO,cAAc,CAAC,CAAC;AACtD,CAAC;AAED,IAAa,iCAAb,cAAoD,OAAO,YAA4C,CAAC,CACtG,kCACA,EAAE,SAAS,OAAO,OAAO,CAC3B,CAAC,CAAC,CAAC;;AAGH,IAAa,kCAAb,cAAqD,OAAO,YAA6C,CAAC,CACxG,mCACA,EAAE,MAAM,OAAO,eAAe,MAAM,OAAO,YAAY,GAAG,CAAC,EAAE,CAC/D,CAAC,CAAC,CAAC;;AAgBH,MAAa,sCAAsC,QAAQ,UAExD,yEAAyE,EAC1E,qBAAqB,EAAE,UAAU,CAAC,EAAE,GACtC,CAAC;;;;;;AAOD,MAAa,wCAAwC,OAAO,GAC1D,uCACF,CAAC,CAAC,WAA0C,SAq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