@fantastic.dev/better-stripe 0.97.1 → 0.99.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.
Files changed (111) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +1 -1
  3. package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.d.ts +11 -0
  4. package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.d.ts.map +1 -1
  5. package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.js +39 -1
  6. package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.js.map +1 -1
  7. package/dist/client/billing/renewalAttach/internal/c10/attachEvents.d.ts +22 -0
  8. package/dist/client/billing/renewalAttach/internal/c10/attachEvents.d.ts.map +1 -1
  9. package/dist/client/billing/renewalAttach/internal/c10/attachEvents.js +13 -5
  10. package/dist/client/billing/renewalAttach/internal/c10/attachEvents.js.map +1 -1
  11. package/dist/client/billing/renewalAttach/internal/operations/actorFailureControl.d.ts +17 -0
  12. package/dist/client/billing/renewalAttach/internal/operations/actorFailureControl.d.ts.map +1 -0
  13. package/dist/client/billing/renewalAttach/internal/operations/actorFailureControl.js +140 -0
  14. package/dist/client/billing/renewalAttach/internal/operations/actorFailureControl.js.map +1 -0
  15. package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.d.ts +61 -9
  16. package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.d.ts.map +1 -1
  17. package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.js +41 -411
  18. package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.js.map +1 -1
  19. package/dist/client/billing/renewalAttach/internal/operations/initialActorData.d.ts +21 -0
  20. package/dist/client/billing/renewalAttach/internal/operations/initialActorData.d.ts.map +1 -0
  21. package/dist/client/billing/renewalAttach/internal/operations/initialActorData.js +36 -0
  22. package/dist/client/billing/renewalAttach/internal/operations/initialActorData.js.map +1 -0
  23. package/dist/client/billing/renewalAttach/internal/operations/initialAttach.d.ts +141 -0
  24. package/dist/client/billing/renewalAttach/internal/operations/initialAttach.d.ts.map +1 -1
  25. package/dist/client/billing/renewalAttach/internal/operations/initialAttach.js +132 -182
  26. package/dist/client/billing/renewalAttach/internal/operations/initialAttach.js.map +1 -1
  27. package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.d.ts +1 -0
  28. package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.d.ts.map +1 -1
  29. package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.js +17 -5
  30. package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.js.map +1 -1
  31. package/dist/client/billing/renewalAttach/internal/operations/transportCapture.d.ts +35 -0
  32. package/dist/client/billing/renewalAttach/internal/operations/transportCapture.d.ts.map +1 -0
  33. package/dist/client/billing/renewalAttach/internal/operations/transportCapture.js +46 -0
  34. package/dist/client/billing/renewalAttach/internal/operations/transportCapture.js.map +1 -0
  35. package/dist/client/billing/renewalAttach/internal/operations/transportKernel.d.ts +63 -0
  36. package/dist/client/billing/renewalAttach/internal/operations/transportKernel.d.ts.map +1 -0
  37. package/dist/client/billing/renewalAttach/internal/operations/transportKernel.js +380 -0
  38. package/dist/client/billing/renewalAttach/internal/operations/transportKernel.js.map +1 -0
  39. package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.d.ts +8 -0
  40. package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.d.ts.map +1 -1
  41. package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.js +25 -0
  42. package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.js.map +1 -1
  43. package/dist/client/billing/renewalAttach/internal/producer/journalWorkFactory.d.ts +56 -0
  44. package/dist/client/billing/renewalAttach/internal/producer/journalWorkFactory.d.ts.map +1 -0
  45. package/dist/client/billing/renewalAttach/internal/producer/journalWorkFactory.js +49 -0
  46. package/dist/client/billing/renewalAttach/internal/producer/journalWorkFactory.js.map +1 -0
  47. package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.d.ts +1 -0
  48. package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.d.ts.map +1 -1
  49. package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.js +3 -0
  50. package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.js.map +1 -1
  51. package/dist/client/billing/renewalAttach/internal/producer/operationFactory.d.ts +65 -0
  52. package/dist/client/billing/renewalAttach/internal/producer/operationFactory.d.ts.map +1 -0
  53. package/dist/client/billing/renewalAttach/internal/producer/operationFactory.js +162 -0
  54. package/dist/client/billing/renewalAttach/internal/producer/operationFactory.js.map +1 -0
  55. package/dist/client/billing/renewalAttach/internal/producer/recoveryEntry.d.ts +4 -0
  56. package/dist/client/billing/renewalAttach/internal/producer/recoveryEntry.d.ts.map +1 -0
  57. package/dist/client/billing/renewalAttach/internal/producer/recoveryEntry.js +87 -0
  58. package/dist/client/billing/renewalAttach/internal/producer/recoveryEntry.js.map +1 -0
  59. package/dist/client/billing/renewalAttach/internal/producer/recoveryFactory.d.ts +368 -0
  60. package/dist/client/billing/renewalAttach/internal/producer/recoveryFactory.d.ts.map +1 -0
  61. package/dist/client/billing/renewalAttach/internal/producer/recoveryFactory.js +106 -0
  62. package/dist/client/billing/renewalAttach/internal/producer/recoveryFactory.js.map +1 -0
  63. package/dist/client/billing/renewalAttach/internal/producer/stockDelegateFactory.d.ts +4 -0
  64. package/dist/client/billing/renewalAttach/internal/producer/stockDelegateFactory.d.ts.map +1 -1
  65. package/dist/client/billing/renewalAttach/internal/producer/stockDelegateFactory.js +24 -3
  66. package/dist/client/billing/renewalAttach/internal/producer/stockDelegateFactory.js.map +1 -1
  67. package/dist/client/billing/renewalAttach/internal/recovery/output.d.ts +1 -0
  68. package/dist/client/billing/renewalAttach/internal/recovery/output.d.ts.map +1 -1
  69. package/dist/client/billing/renewalAttach/internal/recovery/output.js +22 -8
  70. package/dist/client/billing/renewalAttach/internal/recovery/output.js.map +1 -1
  71. package/dist/client/billing/renewalAttach/internal/recovery/record.d.ts +1 -0
  72. package/dist/client/billing/renewalAttach/internal/recovery/record.d.ts.map +1 -1
  73. package/dist/client/billing/renewalAttach/internal/recovery/record.js +10 -2
  74. package/dist/client/billing/renewalAttach/internal/recovery/record.js.map +1 -1
  75. package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.d.ts +3 -0
  76. package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.d.ts.map +1 -1
  77. package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.js +69 -156
  78. package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.js.map +1 -1
  79. package/dist/client/billing/renewalAttach/internal/recovery/relation.d.ts +18 -0
  80. package/dist/client/billing/renewalAttach/internal/recovery/relation.d.ts.map +1 -1
  81. package/dist/client/billing/renewalAttach/internal/recovery/relation.js +15 -1
  82. package/dist/client/billing/renewalAttach/internal/recovery/relation.js.map +1 -1
  83. package/docs/renewal-context-reads.md +69 -8
  84. package/package.json +1 -1
  85. package/src/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.ts +45 -3
  86. package/src/client/billing/renewalAttach/internal/c10/attachEvents.ts +17 -5
  87. package/src/client/billing/renewalAttach/internal/operations/actorFailureControl.ts +165 -0
  88. package/src/client/billing/renewalAttach/internal/operations/fixedTransport.ts +48 -535
  89. package/src/client/billing/renewalAttach/internal/operations/initialActorData.ts +41 -0
  90. package/src/client/billing/renewalAttach/internal/operations/initialAttach.ts +168 -209
  91. package/src/client/billing/renewalAttach/internal/operations/ownedAwait.ts +23 -5
  92. package/src/client/billing/renewalAttach/internal/operations/transportCapture.ts +60 -0
  93. package/src/client/billing/renewalAttach/internal/operations/transportKernel.ts +500 -0
  94. package/src/client/billing/renewalAttach/internal/producer/invocationProducer.ts +28 -0
  95. package/src/client/billing/renewalAttach/internal/producer/journalWorkFactory.ts +54 -0
  96. package/src/client/billing/renewalAttach/internal/producer/lineageAuthority.ts +3 -0
  97. package/src/client/billing/renewalAttach/internal/producer/operationFactory.ts +176 -0
  98. package/src/client/billing/renewalAttach/internal/producer/producerAcquisition.integration.test.ts +240 -0
  99. package/src/client/billing/renewalAttach/internal/producer/producerActor.integration.test.ts +526 -0
  100. package/src/client/billing/renewalAttach/internal/producer/producerRecovery.integration.test.ts +394 -0
  101. package/src/client/billing/renewalAttach/internal/producer/producerRecoveryControls.integration.test.ts +437 -0
  102. package/src/client/billing/renewalAttach/internal/producer/producerRecoveryIsolation.integration.test.ts +332 -0
  103. package/src/client/billing/renewalAttach/internal/producer/producerTransport.integration.test.ts +440 -0
  104. package/src/client/billing/renewalAttach/internal/producer/recoveryEntry.ts +109 -0
  105. package/src/client/billing/renewalAttach/internal/producer/recoveryFactory.ts +135 -0
  106. package/src/client/billing/renewalAttach/internal/producer/stockDelegateFactory.ts +29 -5
  107. package/src/client/billing/renewalAttach/internal/recovery/output.ts +34 -8
  108. package/src/client/billing/renewalAttach/internal/recovery/record.ts +16 -2
  109. package/src/client/billing/renewalAttach/internal/recovery/recoveryActor.ts +107 -188
  110. package/src/client/billing/renewalAttach/internal/recovery/relation.ts +17 -1
  111. package/src/client/billing/renewalAttach/internal/test-fixtures/producerInitialOperation.ts +82 -11
@@ -0,0 +1,500 @@
1
+ import { types } from "node:util";
2
+ import { requiredJSONSnapshot } from "../material/requiredJson.js";
3
+ import { rejectProxyJSON } from "../acquisition/rawWireSource.js";
4
+ import {
5
+ closed,
6
+ captureRequestAndReads,
7
+ need,
8
+ stop,
9
+ freezeJSON,
10
+ type AttachRequest,
11
+ type ReadRow,
12
+ } from "./types.js";
13
+ import {
14
+ safeDiagnostics,
15
+ opaqueRecord,
16
+ type Diagnostics,
17
+ } from "./providerFailure.js";
18
+ import { equal } from "../../../renewalAggregate/shared.js";
19
+ import {
20
+ captureLegacyTransportSource,
21
+ captureInitialTransportSource,
22
+ checkTransportOwnerResult as checkOwnerResult,
23
+ } from "./transportCapture.js";
24
+
25
+ function validRead(
26
+ row: ReadRow,
27
+ method: unknown,
28
+ path: unknown,
29
+ body: unknown,
30
+ options: unknown,
31
+ ) {
32
+ need(row && method === row.method && path === row.path && body === undefined);
33
+ const value = closed(options, ["apiVersion", "maxNetworkRetries"]);
34
+ need(
35
+ value.apiVersion === row.options.apiVersion &&
36
+ value.maxNetworkRetries === 0,
37
+ );
38
+ }
39
+
40
+ export type PostDisposition =
41
+ | "NOT_STARTED"
42
+ | "PENDING"
43
+ | "REJECTED"
44
+ | "FULFILLED_UNVERIFIED"
45
+ | "FULFILLED_SAFE";
46
+ type Attempt = Readonly<{
47
+ generation: object;
48
+ ordinal: number;
49
+ kind: "read" | "post";
50
+ resource: string;
51
+ method: string;
52
+ path: string;
53
+ id: string;
54
+ }>;
55
+ export type Quarantine = Readonly<object>;
56
+ type Rejection = Readonly<{
57
+ phase: "read";
58
+ ordinal: number;
59
+ diagnostics: Diagnostics;
60
+ }>;
61
+ const notStarted = (reason: string) =>
62
+ Object.freeze({ outcome: "not_started" as const, reason });
63
+ const nativeResponsePrototype = Response.prototype,
64
+ nativeStatusGetter = Object.getOwnPropertyDescriptor(
65
+ nativeResponsePrototype,
66
+ "status",
67
+ )!.get!,
68
+ apply = Reflect.apply;
69
+
70
+ function capturePostReply(reply: unknown) {
71
+ rejectProxyJSON(reply, true);
72
+ need(reply !== null && typeof reply === "object" && !Array.isArray(reply));
73
+ const proto = Object.getPrototypeOf(reply);
74
+ need(proto === Object.prototype || proto === null);
75
+ const meta = Object.getOwnPropertyDescriptor(reply, "lastResponse");
76
+ need(
77
+ meta &&
78
+ !meta.enumerable &&
79
+ "value" in meta &&
80
+ meta.value !== null &&
81
+ typeof meta.value === "object",
82
+ );
83
+ const metadata: object = meta.value;
84
+ need(!types.isProxy(metadata));
85
+ const codes: unknown[] = [];
86
+ for (const key of ["status", "statusCode"]) {
87
+ const d = Object.getOwnPropertyDescriptor(metadata, key);
88
+ if (!d) continue;
89
+ need("value" in d);
90
+ if (d.value !== undefined) codes.push(d.value);
91
+ }
92
+ if (Object.getPrototypeOf(metadata) === nativeResponsePrototype)
93
+ codes.push(apply(nativeStatusGetter, metadata, []));
94
+ need(
95
+ codes.length > 0 &&
96
+ codes.every(
97
+ (x) =>
98
+ typeof x === "number" &&
99
+ Number.isInteger(x) &&
100
+ x >= 200 &&
101
+ x < 300 &&
102
+ x === codes[0],
103
+ ),
104
+ );
105
+ const statusCode = codes[0];
106
+ need(typeof statusCode === "number");
107
+ const entries: [string, unknown][] = [];
108
+ for (const key of Reflect.ownKeys(reply)) {
109
+ need(typeof key === "string");
110
+ if (key === "lastResponse") continue;
111
+ const d = Object.getOwnPropertyDescriptor(reply, key);
112
+ need(d && d.enumerable && "value" in d);
113
+ entries.push([key, d.value]);
114
+ }
115
+ return Object.freeze({
116
+ body: requiredJSONSnapshot(Object.fromEntries(entries)),
117
+ statusCode,
118
+ });
119
+ }
120
+
121
+ type Association = Readonly<{
122
+ operation: unknown;
123
+ readPlan: unknown;
124
+ delegate: unknown;
125
+ }>;
126
+ export function build(
127
+ source: unknown,
128
+ association?: Association,
129
+ token?: object,
130
+ ) {
131
+ const b =
132
+ token === undefined
133
+ ? captureLegacyTransportSource(source)
134
+ : captureInitialTransportSource(token, source);
135
+ const generation = Object.freeze({});
136
+ let ordinal = 0,
137
+ index = 0,
138
+ pending: Attempt | null = null,
139
+ failedRead = false,
140
+ consumedPost = false;
141
+ let postState: PostDisposition = "NOT_STARTED",
142
+ postAttempt: Attempt | null = null,
143
+ rejectionSlot: { attempt: Attempt; record: Rejection } | null = null,
144
+ lastFailedRead: Attempt | null = null,
145
+ closedOwner = false,
146
+ checking = false;
147
+ function ownerGate() {
148
+ if (closedOwner || checking) {
149
+ closedOwner = true;
150
+ stop();
151
+ }
152
+ checking = true;
153
+ try {
154
+ checkOwnerResult(Reflect.apply(b.check, b.owner, []));
155
+ if (closedOwner) stop();
156
+ } catch {
157
+ closedOwner = true;
158
+ stop();
159
+ } finally {
160
+ checking = false;
161
+ }
162
+ }
163
+ function attempt(
164
+ kind: "read" | "post",
165
+ row: ReadRow | AttachRequest,
166
+ ): Attempt {
167
+ need(!pending && ordinal < 44);
168
+ const value = Object.freeze({
169
+ generation,
170
+ ordinal: ++ordinal,
171
+ kind,
172
+ resource: kind === "read" && "resource" in row ? row.resource : "post",
173
+ method: row.method,
174
+ path: row.path,
175
+ id: "id" in row ? row.id : b.request.payload.from_subscription,
176
+ });
177
+ pending = value;
178
+ return value;
179
+ }
180
+ const own = (a: Attempt) => pending === a && a.generation === generation;
181
+ const postCatchRecords = new WeakMap<
182
+ object,
183
+ Readonly<{ attempt: Attempt; diagnostics: Diagnostics }>
184
+ >();
185
+ let reservation = "unused",
186
+ fulfilledSlot: Readonly<{
187
+ attempt: Attempt;
188
+ generation: object;
189
+ quarantine: Quarantine;
190
+ }> | null = null;
191
+ async function rawRequest(
192
+ method: unknown,
193
+ path: unknown,
194
+ body: unknown,
195
+ options: unknown,
196
+ ): Promise<unknown> {
197
+ need(!failedRead && !consumedPost && !pending && index < b.plan.length);
198
+ ownerGate();
199
+ const row = b.plan[index];
200
+ validRead(row, method, path, body, options);
201
+ const a = attempt("read", row);
202
+ let reply: unknown;
203
+ try {
204
+ reply = await Reflect.apply(b.send, b.delegate, [
205
+ method,
206
+ path,
207
+ body,
208
+ row.options,
209
+ ]);
210
+ } catch (error) {
211
+ need(own(a));
212
+ failedRead = true;
213
+ lastFailedRead = a;
214
+ let live = false;
215
+ try {
216
+ ownerGate();
217
+ live = true;
218
+ } catch {
219
+ /* Retired errors are opaque. */
220
+ }
221
+ if (live && own(a))
222
+ rejectionSlot = {
223
+ attempt: a,
224
+ record: opaqueRecord(
225
+ {
226
+ phase: "read",
227
+ ordinal: a.ordinal,
228
+ diagnostics: safeDiagnostics(error),
229
+ } as const,
230
+ "rawError",
231
+ error,
232
+ ),
233
+ };
234
+ pending = null;
235
+ if (live) throw error;
236
+ stop();
237
+ }
238
+ try {
239
+ ownerGate();
240
+ need(own(a));
241
+ } catch {
242
+ failedRead = true;
243
+ pending = null;
244
+ stop();
245
+ }
246
+ pending = null;
247
+ index++;
248
+ return reply;
249
+ }
250
+ async function postAttach(...args: unknown[]) {
251
+ if (
252
+ args.length ||
253
+ consumedPost ||
254
+ pending ||
255
+ failedRead ||
256
+ index !== b.plan.length
257
+ )
258
+ return notStarted("not_ready");
259
+ try {
260
+ ownerGate();
261
+ } catch {
262
+ return notStarted("owner_closed");
263
+ }
264
+ consumedPost = true;
265
+ const request = b.request,
266
+ a = attempt("post", request);
267
+ postAttempt = a;
268
+ postState = "PENDING";
269
+ let reply: unknown;
270
+ try {
271
+ reply = await Reflect.apply(b.send, b.delegate, [
272
+ request.method,
273
+ request.path,
274
+ request.payload,
275
+ {
276
+ apiVersion: request.apiVersion,
277
+ idempotencyKey: request.key,
278
+ maxNetworkRetries: 0,
279
+ },
280
+ ]);
281
+ } catch (error) {
282
+ postState = "REJECTED";
283
+ let live = false;
284
+ try {
285
+ ownerGate();
286
+ live = true;
287
+ } catch {
288
+ /* No late error reflection. */
289
+ }
290
+ const valid = own(a) && postAttempt === a,
291
+ diagnostics =
292
+ live && valid ? safeDiagnostics(error) : Object.freeze({});
293
+ const record = opaqueRecord(
294
+ {
295
+ outcome: "provider_rejected",
296
+ phase: "post",
297
+ ordinal: a.ordinal,
298
+ diagnostics,
299
+ } as const,
300
+ "rawError",
301
+ error,
302
+ );
303
+ if (valid)
304
+ postCatchRecords.set(
305
+ record,
306
+ Object.freeze({ attempt: a, diagnostics }),
307
+ );
308
+ pending = null;
309
+ return record;
310
+ }
311
+ if (own(a) && postAttempt === a && a.generation === generation) {
312
+ const q: object = Object.create(null);
313
+ Object.defineProperty(q, "raw", {
314
+ value: reply,
315
+ enumerable: false,
316
+ writable: false,
317
+ configurable: false,
318
+ });
319
+ Object.freeze(q);
320
+ fulfilledSlot = Object.freeze({ attempt: a, generation, quarantine: q });
321
+ }
322
+ postState = "FULFILLED_UNVERIFIED";
323
+ try {
324
+ ownerGate();
325
+ need(own(a) && postAttempt === a);
326
+ const admitted = capturePostReply(reply);
327
+ ownerGate();
328
+ pending = null;
329
+ postState = "FULFILLED_SAFE";
330
+ return Object.freeze({
331
+ outcome: "fulfilled_safe" as const,
332
+ body: freezeJSON(admitted.body),
333
+ statusCode: admitted.statusCode,
334
+ });
335
+ } catch {
336
+ pending = null;
337
+ return opaqueRecord(
338
+ { outcome: "fulfilled_unverified" as const },
339
+ "rawResponse",
340
+ reply,
341
+ );
342
+ }
343
+ }
344
+ const transport = Object.freeze({
345
+ readTransport: Object.freeze({ rawRequest }),
346
+ postAttach,
347
+ takeReadRejection(...args: unknown[]) {
348
+ need(args.length === 0);
349
+ const slot = rejectionSlot;
350
+ rejectionSlot = null;
351
+ if (
352
+ !slot ||
353
+ slot.attempt !== lastFailedRead ||
354
+ slot.attempt.generation !== generation ||
355
+ slot.attempt.kind !== "read"
356
+ )
357
+ return null;
358
+ return slot.record;
359
+ },
360
+ postDisposition(...args: unknown[]): PostDisposition {
361
+ need(args.length === 0);
362
+ return postState;
363
+ },
364
+ });
365
+ const capability = Object.freeze({
366
+ assertSourceOperationBinding(
367
+ operation: unknown,
368
+ request: unknown,
369
+ readPlan: unknown,
370
+ delegate: unknown,
371
+ ) {
372
+ ownerGate();
373
+ if (
374
+ !association ||
375
+ association.operation !== operation ||
376
+ association.readPlan !== readPlan ||
377
+ association.delegate !== delegate
378
+ )
379
+ return false;
380
+ const current = captureRequestAndReads(request, readPlan);
381
+ const matches =
382
+ equal(current.request, b.request) &&
383
+ current.plan.length === b.plan.length &&
384
+ current.plan.every((row, index) => {
385
+ const captured = b.plan[index];
386
+ return (
387
+ row.resource === captured.resource &&
388
+ row.ordinal === captured.ordinal &&
389
+ row.method === captured.method &&
390
+ row.path === captured.path &&
391
+ row.body === captured.body &&
392
+ row.id === captured.id &&
393
+ row.options.apiVersion === captured.options.apiVersion &&
394
+ row.options.maxNetworkRetries === captured.options.maxNetworkRetries
395
+ );
396
+ });
397
+ ownerGate();
398
+ return matches;
399
+ },
400
+ takeFulfilledQuarantine(...args: unknown[]) {
401
+ if (
402
+ args.length !== 0 ||
403
+ pending !== null ||
404
+ fulfilledSlot === null ||
405
+ fulfilledSlot.attempt !== postAttempt ||
406
+ fulfilledSlot.generation !== generation ||
407
+ postAttempt === null ||
408
+ postAttempt.generation !== generation ||
409
+ postAttempt.kind !== "post" ||
410
+ (postState !== "FULFILLED_SAFE" && postState !== "FULFILLED_UNVERIFIED")
411
+ )
412
+ return null;
413
+ const q = fulfilledSlot.quarantine;
414
+ fulfilledSlot = null;
415
+ return q;
416
+ },
417
+ assertVirginAcquisition(...args: unknown[]) {
418
+ need(args.length === 0);
419
+ try {
420
+ ownerGate();
421
+ } catch {
422
+ return false;
423
+ }
424
+ if (
425
+ reservation !== "unused" ||
426
+ ordinal !== 0 ||
427
+ index !== 0 ||
428
+ pending ||
429
+ failedRead ||
430
+ lastFailedRead ||
431
+ rejectionSlot ||
432
+ consumedPost ||
433
+ postAttempt ||
434
+ postState !== "NOT_STARTED"
435
+ ) {
436
+ reservation = "invalid";
437
+ return false;
438
+ }
439
+ reservation = "reserved";
440
+ return true;
441
+ },
442
+ consumeReadCatch(...args: unknown[]) {
443
+ need(args.length === 0);
444
+ try {
445
+ ownerGate();
446
+ } catch {
447
+ return null;
448
+ }
449
+ const slot = rejectionSlot;
450
+ if (
451
+ reservation !== "reserved" ||
452
+ !failedRead ||
453
+ pending ||
454
+ !slot ||
455
+ slot.attempt !== lastFailedRead ||
456
+ slot.attempt.generation !== generation ||
457
+ slot.attempt.kind !== "read" ||
458
+ slot.attempt.ordinal > 43
459
+ )
460
+ return null;
461
+ rejectionSlot = null;
462
+ return Object.freeze({
463
+ phase: "read" as const,
464
+ ordinal: slot.attempt.ordinal,
465
+ diagnostics: slot.record.diagnostics,
466
+ });
467
+ },
468
+ consumePostCatch(actualReply: unknown) {
469
+ need(arguments.length === 1);
470
+ try {
471
+ ownerGate();
472
+ } catch {
473
+ return null;
474
+ }
475
+ const stored =
476
+ actualReply !== null &&
477
+ (typeof actualReply === "object" || typeof actualReply === "function")
478
+ ? postCatchRecords.get(actualReply)
479
+ : undefined;
480
+ if (
481
+ reservation !== "reserved" ||
482
+ !stored ||
483
+ stored.attempt !== postAttempt ||
484
+ stored.attempt.generation !== generation ||
485
+ stored.attempt.kind !== "post" ||
486
+ postState !== "REJECTED" ||
487
+ pending ||
488
+ stored.attempt.ordinal > 44
489
+ )
490
+ return null;
491
+ postCatchRecords.delete(actualReply as object);
492
+ return Object.freeze({
493
+ phase: "post" as const,
494
+ ordinal: stored.attempt.ordinal,
495
+ diagnostics: stored.diagnostics,
496
+ });
497
+ },
498
+ });
499
+ return Object.freeze({ transport, capability });
500
+ }
@@ -1,10 +1,17 @@
1
1
  import { mintInitialLineage, readInitialLineage } from "./lineageAuthority.js";
2
+ import { captureLiveAttachRecovery } from "./recoveryEntry.js";
2
3
  import { ownerForInitialLineage, type InitialOwner } from "./ownerFactory.js";
3
4
  import { ownedAwaitForInitialLineage } from "./ownedAwaitFactory.js";
4
5
  import { stockDelegateForInitialLineage } from "./stockDelegateFactory.js";
5
6
  import type { createClassActionOperationJournal } from "../operationJournal.js";
6
7
  import { createInitialAttachEventCompiler } from "../c10/attachEvents.js";
7
8
  import { createInitialMaterialClassifiers } from "../material/classifiers.js";
9
+ import { createInitialTransportForLineage } from "../operations/fixedTransport.js";
10
+ import {
11
+ acquisitionForInitialLineage,
12
+ type RawAcquisitionResult,
13
+ } from "../acquisition/ownedAcquisition.js";
14
+ import { captureInitialAttachForLineage } from "../operations/initialAttach.js";
8
15
 
9
16
  export type InitialInvocationCore = Readonly<{
10
17
  owner: InitialOwner;
@@ -13,6 +20,10 @@ export type InitialInvocationCore = Readonly<{
13
20
  owned<T>(work: () => T | PromiseLike<T>): Promise<T>;
14
21
  attachEvents(): ReturnType<typeof createInitialAttachEventCompiler>;
15
22
  material: ReturnType<typeof createInitialMaterialClassifiers>;
23
+ transport(): ReturnType<typeof createInitialTransportForLineage>;
24
+ acquire(): Promise<RawAcquisitionResult>;
25
+ initialAttach(): ReturnType<typeof captureInitialAttachForLineage>;
26
+ recoverAttach(): ReturnType<typeof captureLiveAttachRecovery>;
16
27
  operationalAuthority: false;
17
28
  }>;
18
29
 
@@ -62,6 +73,23 @@ export async function captureInitialInvocationCore(
62
73
  return createInitialAttachEventCompiler(token);
63
74
  },
64
75
  material: createInitialMaterialClassifiers(token),
76
+ async transport() {
77
+ if (arguments.length !== 0) throw Error("INITIAL_OPERATION_UNBOUND");
78
+ return owned(() => createInitialTransportForLineage(token));
79
+ },
80
+ async acquire() {
81
+ if (arguments.length !== 0) throw Error("INITIAL_OPERATION_UNBOUND");
82
+ const reader = await owned(() => acquisitionForInitialLineage(token));
83
+ return owned(() => reader.acquire());
84
+ },
85
+ initialAttach() {
86
+ if (arguments.length !== 0) throw Error("INITIAL_OPERATION_UNBOUND");
87
+ return captureInitialAttachForLineage(token);
88
+ },
89
+ recoverAttach() {
90
+ if (arguments.length !== 0) throw Error("INITIAL_OPERATION_UNBOUND");
91
+ return captureLiveAttachRecovery(token);
92
+ },
65
93
  operationalAuthority: false,
66
94
  });
67
95
  } catch (error) {
@@ -0,0 +1,54 @@
1
+ import { readInitialLineage } from "./lineageAuthority.js";
2
+ import { ownerForInitialLineage } from "./ownerFactory.js";
3
+
4
+ const journals = new WeakMap<object, ReturnType<typeof construct>>();
5
+ function construct(token: object) {
6
+ const lineage = readInitialLineage(token);
7
+ const owner = ownerForInitialLineage(token);
8
+
9
+ let pending = 0;
10
+ async function track<T>(work: () => Promise<T>): Promise<T> {
11
+ owner.check();
12
+ pending++;
13
+ try {
14
+ // Track the actual journal promise, independently of a channel's timeout.
15
+ return await work();
16
+ } finally {
17
+ pending--;
18
+ }
19
+ }
20
+ return Object.freeze({
21
+ captureSend() {
22
+ if (arguments.length !== 0) throw Error("INITIAL_OPERATION_UNBOUND");
23
+ owner.check();
24
+ const send = lineage.journal.createC10Send(lineage.reservation);
25
+ return (
26
+ record: Parameters<typeof send>[0],
27
+ ack: Parameters<typeof send>[1],
28
+ ) => track(() => send(record, ack));
29
+ },
30
+ retain(
31
+ input: Parameters<
32
+ typeof lineage.journal.retainProviderAcknowledgement
33
+ >[0],
34
+ ) {
35
+ return track(() => lineage.journal.retainProviderAcknowledgement(input));
36
+ },
37
+ idle() {
38
+ owner.check();
39
+ return pending === 0;
40
+ },
41
+ });
42
+ }
43
+ /** Original journal work only; channel closure cannot hide a pending mutation. */
44
+ export function journalWorkForInitialLineage(token: object) {
45
+ if (arguments.length !== 1) throw Error("INITIAL_OPERATION_UNBOUND");
46
+ const owner = ownerForInitialLineage(token);
47
+ owner.check();
48
+ let work = journals.get(token);
49
+ if (!work) {
50
+ work = construct(token);
51
+ journals.set(token, work);
52
+ }
53
+ return work;
54
+ }
@@ -16,7 +16,9 @@ const ms = (value: number) => Number.isSafeInteger(value) && value >= 0;
16
16
 
17
17
  // Only this module mints identities. Retained journal DATA cannot construct one.
18
18
  class InitialLineage {}
19
+ class InitialOrigin {}
19
20
  type Lineage = Readonly<{
21
+ originAssociation: object;
20
22
  journal: ReturnType<typeof consumeInitialClassReservation>["journal"];
21
23
  reservation: ReturnType<typeof consumeInitialClassReservation>["reservation"];
22
24
  selection: ReturnType<typeof captureInitialJournalSelection>;
@@ -125,6 +127,7 @@ export function mintInitialLineage(
125
127
  lineages.set(
126
128
  token,
127
129
  Object.freeze({
130
+ originAssociation: Object.freeze(new InitialOrigin()),
128
131
  journal: originalJournal,
129
132
  reservation,
130
133
  selection,