@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.
- package/CHANGELOG.md +12 -0
- package/README.md +1 -1
- package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.d.ts +11 -0
- package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.js +39 -1
- package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/c10/attachEvents.d.ts +22 -0
- package/dist/client/billing/renewalAttach/internal/c10/attachEvents.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/c10/attachEvents.js +13 -5
- package/dist/client/billing/renewalAttach/internal/c10/attachEvents.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/operations/actorFailureControl.d.ts +17 -0
- package/dist/client/billing/renewalAttach/internal/operations/actorFailureControl.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/actorFailureControl.js +140 -0
- package/dist/client/billing/renewalAttach/internal/operations/actorFailureControl.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.d.ts +61 -9
- package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.js +41 -411
- package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/operations/initialActorData.d.ts +21 -0
- package/dist/client/billing/renewalAttach/internal/operations/initialActorData.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/initialActorData.js +36 -0
- package/dist/client/billing/renewalAttach/internal/operations/initialActorData.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/initialAttach.d.ts +141 -0
- package/dist/client/billing/renewalAttach/internal/operations/initialAttach.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/operations/initialAttach.js +132 -182
- package/dist/client/billing/renewalAttach/internal/operations/initialAttach.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.d.ts +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.js +17 -5
- package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/operations/transportCapture.d.ts +35 -0
- package/dist/client/billing/renewalAttach/internal/operations/transportCapture.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/transportCapture.js +46 -0
- package/dist/client/billing/renewalAttach/internal/operations/transportCapture.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/transportKernel.d.ts +63 -0
- package/dist/client/billing/renewalAttach/internal/operations/transportKernel.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/transportKernel.js +380 -0
- package/dist/client/billing/renewalAttach/internal/operations/transportKernel.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.d.ts +8 -0
- package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.js +25 -0
- package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/journalWorkFactory.d.ts +56 -0
- package/dist/client/billing/renewalAttach/internal/producer/journalWorkFactory.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/journalWorkFactory.js +49 -0
- package/dist/client/billing/renewalAttach/internal/producer/journalWorkFactory.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.d.ts +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.js +3 -0
- package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/operationFactory.d.ts +65 -0
- package/dist/client/billing/renewalAttach/internal/producer/operationFactory.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/operationFactory.js +162 -0
- package/dist/client/billing/renewalAttach/internal/producer/operationFactory.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/recoveryEntry.d.ts +4 -0
- package/dist/client/billing/renewalAttach/internal/producer/recoveryEntry.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/recoveryEntry.js +87 -0
- package/dist/client/billing/renewalAttach/internal/producer/recoveryEntry.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/recoveryFactory.d.ts +368 -0
- package/dist/client/billing/renewalAttach/internal/producer/recoveryFactory.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/recoveryFactory.js +106 -0
- package/dist/client/billing/renewalAttach/internal/producer/recoveryFactory.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/stockDelegateFactory.d.ts +4 -0
- package/dist/client/billing/renewalAttach/internal/producer/stockDelegateFactory.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/stockDelegateFactory.js +24 -3
- package/dist/client/billing/renewalAttach/internal/producer/stockDelegateFactory.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/recovery/output.d.ts +1 -0
- package/dist/client/billing/renewalAttach/internal/recovery/output.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/recovery/output.js +22 -8
- package/dist/client/billing/renewalAttach/internal/recovery/output.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/recovery/record.d.ts +1 -0
- package/dist/client/billing/renewalAttach/internal/recovery/record.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/recovery/record.js +10 -2
- package/dist/client/billing/renewalAttach/internal/recovery/record.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.d.ts +3 -0
- package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.js +69 -156
- package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/recovery/relation.d.ts +18 -0
- package/dist/client/billing/renewalAttach/internal/recovery/relation.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/recovery/relation.js +15 -1
- package/dist/client/billing/renewalAttach/internal/recovery/relation.js.map +1 -1
- package/docs/renewal-context-reads.md +69 -8
- package/package.json +1 -1
- package/src/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.ts +45 -3
- package/src/client/billing/renewalAttach/internal/c10/attachEvents.ts +17 -5
- package/src/client/billing/renewalAttach/internal/operations/actorFailureControl.ts +165 -0
- package/src/client/billing/renewalAttach/internal/operations/fixedTransport.ts +48 -535
- package/src/client/billing/renewalAttach/internal/operations/initialActorData.ts +41 -0
- package/src/client/billing/renewalAttach/internal/operations/initialAttach.ts +168 -209
- package/src/client/billing/renewalAttach/internal/operations/ownedAwait.ts +23 -5
- package/src/client/billing/renewalAttach/internal/operations/transportCapture.ts +60 -0
- package/src/client/billing/renewalAttach/internal/operations/transportKernel.ts +500 -0
- package/src/client/billing/renewalAttach/internal/producer/invocationProducer.ts +28 -0
- package/src/client/billing/renewalAttach/internal/producer/journalWorkFactory.ts +54 -0
- package/src/client/billing/renewalAttach/internal/producer/lineageAuthority.ts +3 -0
- package/src/client/billing/renewalAttach/internal/producer/operationFactory.ts +176 -0
- package/src/client/billing/renewalAttach/internal/producer/producerAcquisition.integration.test.ts +240 -0
- package/src/client/billing/renewalAttach/internal/producer/producerActor.integration.test.ts +526 -0
- package/src/client/billing/renewalAttach/internal/producer/producerRecovery.integration.test.ts +394 -0
- package/src/client/billing/renewalAttach/internal/producer/producerRecoveryControls.integration.test.ts +437 -0
- package/src/client/billing/renewalAttach/internal/producer/producerRecoveryIsolation.integration.test.ts +332 -0
- package/src/client/billing/renewalAttach/internal/producer/producerTransport.integration.test.ts +440 -0
- package/src/client/billing/renewalAttach/internal/producer/recoveryEntry.ts +109 -0
- package/src/client/billing/renewalAttach/internal/producer/recoveryFactory.ts +135 -0
- package/src/client/billing/renewalAttach/internal/producer/stockDelegateFactory.ts +29 -5
- package/src/client/billing/renewalAttach/internal/recovery/output.ts +34 -8
- package/src/client/billing/renewalAttach/internal/recovery/record.ts +16 -2
- package/src/client/billing/renewalAttach/internal/recovery/recoveryActor.ts +107 -188
- package/src/client/billing/renewalAttach/internal/recovery/relation.ts +17 -1
- package/src/client/billing/renewalAttach/internal/test-fixtures/producerInitialOperation.ts +82 -11
|
@@ -43,8 +43,8 @@ not migrate its old binding or authorize a retry.
|
|
|
43
43
|
|
|
44
44
|
## Internal ownership and transport groundwork
|
|
45
45
|
|
|
46
|
-
The
|
|
47
|
-
and adapt the stock Stripe client's inherited `rawRequest` method without
|
|
46
|
+
The legacy `renewalAttach/internal` facades keep one dormant original Owner
|
|
47
|
+
identity and adapt the stock Stripe client's inherited `rawRequest` method without
|
|
48
48
|
changing its receiver, arguments, result or thrown value. The owner checks the
|
|
49
49
|
same original wall and monotonic time bounds and closes permanently on expiry,
|
|
50
50
|
regression or retirement. These modules do not read a clock at import time.
|
|
@@ -113,8 +113,7 @@ Each callback rechecks both clocks and the original policy before rearming. The
|
|
|
113
113
|
later final deadline is not a timer span limit. Event-loop suspension can delay
|
|
114
114
|
callbacks. Every continuation therefore checks both clocks before
|
|
115
115
|
returning a value. Retirement is irreversible and never extends either original
|
|
116
|
-
cutoff. Legacy actors
|
|
117
|
-
wiring their per-invocation kernels remains required before runtime activation.
|
|
116
|
+
cutoff. Legacy actors retain their separate dormant identity and behavior.
|
|
118
117
|
|
|
119
118
|
The private initial core can capture one attach-stage C10 compiler for its own
|
|
120
119
|
lineage. This compiler takes the original raw source and actual acquired
|
|
@@ -127,8 +126,7 @@ Retiring one invocation rejects its pending channel without retiring another
|
|
|
127
126
|
invocation's channel or removing already committed DATA. Stored events and C10
|
|
128
127
|
append acknowledgements do not establish provider custody or a returned public
|
|
129
128
|
operation acknowledgement. Legacy stage-channel facades retain their existing
|
|
130
|
-
lazy Owner and behavior.
|
|
131
|
-
remains required.
|
|
129
|
+
lazy Owner and behavior.
|
|
132
130
|
|
|
133
131
|
The core's private material classifiers also retain the original journal source
|
|
134
132
|
and canonical Owner. Retained classification accepts no replacement source.
|
|
@@ -138,8 +136,71 @@ original source. Both paths keep the existing DATA-consistency-only result and
|
|
|
138
136
|
bounded snapshots. They do not qualify acquisition or provider custody. Pending
|
|
139
137
|
reconstruction is owned by that invocation; retirement rejects its continuation
|
|
140
138
|
without closing another invocation's classifier. Legacy classifier exports keep
|
|
141
|
-
their lazy Owner and existing refusal behavior.
|
|
142
|
-
|
|
139
|
+
their lazy Owner and existing refusal behavior.
|
|
140
|
+
|
|
141
|
+
The private initial actor now uses those classifiers, the canonical transport and
|
|
142
|
+
one acquisition reader for its lineage. Its operation retains one private origin
|
|
143
|
+
association and a single-use source slot. The transport captures the selected
|
|
144
|
+
SDK's original raw-request method and receiver, and receives the actual SDK
|
|
145
|
+
promise. Its fixed read plan permits the original subscription, target price,
|
|
146
|
+
billing customer and at most 40 original Coupon reads. It permits one attachment
|
|
147
|
+
POST. Callers cannot supply a replacement client, source, plan, Owner or journal
|
|
148
|
+
sink through the invocation core.
|
|
149
|
+
|
|
150
|
+
The actor retains the complete captured C3 receipt in the component journal at
|
|
151
|
+
sequence 2 before appending receipt event 3 or returning an acknowledgement.
|
|
152
|
+
Receipt retention alone is DATA. If the Owner retires while a committed retention
|
|
153
|
+
reply is pending, that DATA remains, but the actor refuses its acknowledgement.
|
|
154
|
+
Another invocation keeps its own client, Owner, journal and continuation.
|
|
155
|
+
|
|
156
|
+
Production Source class arrays remain empty. Empty admission returns before
|
|
157
|
+
constructing an Owner, loading Source data, invoking a client method or sampling
|
|
158
|
+
a clock, including when the
|
|
159
|
+
private actor is captured from a lineage that has no Owner yet. Tests admit
|
|
160
|
+
synthetic profiles in ordinary Node and Convex-test with controlled HTTP. They
|
|
161
|
+
do not qualify native execution or provider custody. Public scheduling, native
|
|
162
|
+
profile qualification, cross-process recovery and later operation stages remain
|
|
163
|
+
separate work.
|
|
164
|
+
|
|
165
|
+
The private core also captures one single-use explicit recovery actor. It keeps
|
|
166
|
+
actual initial attempt custody beside the initial actor, including its original
|
|
167
|
+
selected entry and predicates, reconstructed request and safely captured SDK
|
|
168
|
+
response when available. A stored or copied journal record cannot create this
|
|
169
|
+
custody. Recovery consumes its reservation before awaiting construction and
|
|
170
|
+
uses the same live Owner and original absolute deadlines.
|
|
171
|
+
|
|
172
|
+
A settled unknown POST without a safe response can use one explicitly invoked
|
|
173
|
+
same-request, same-key replay. It requires the committed dispatch event at head
|
|
174
|
+
1, no known acknowledgement and no pending journal writes. The new transport
|
|
175
|
+
pair retains the original selected SDK and bounded read plan. Complete fresh
|
|
176
|
+
reads must preserve the original residual subscription, target, customer and
|
|
177
|
+
Coupon material. The observed schedule association may remain null or become a
|
|
178
|
+
validated non-null reference. That pre-POST observation remains unowned DATA;
|
|
179
|
+
it never substitutes for the original creation acknowledgement. Recovery checks
|
|
180
|
+
the complete journal frontier again after dispatch acknowledgement and before
|
|
181
|
+
its POST. This read fence cannot atomically lock journal state and a provider
|
|
182
|
+
request; another authorized writer may race the final read-to-call interval.
|
|
183
|
+
Immutable conflicting history still refuses acknowledgement. The legacy
|
|
184
|
+
recovery facade retains its existing association rules.
|
|
185
|
+
|
|
186
|
+
When the original live invocation already holds a safe response, recovery
|
|
187
|
+
resumes acknowledgement without another provider read or POST. It rebuilds C3
|
|
188
|
+
from that response and the original request, idempotently completes matching C10
|
|
189
|
+
events and receipt retention, and checks the original Owner before returning the
|
|
190
|
+
fully admitted receipt. Existing event 2 or 3 must match complete immutable
|
|
191
|
+
history. Conflicting DATA refuses.
|
|
192
|
+
|
|
193
|
+
Each initial or recovery channel captures its own original-journal sender and
|
|
194
|
+
keeps that sender's irreversible stop latch. Journal work tracking follows all
|
|
195
|
+
actual send and retention promises for the lineage. A C10
|
|
196
|
+
channel timeout can close its caller while the underlying mutation remains
|
|
197
|
+
pending and may later commit. Recovery refuses while that work is pending. It
|
|
198
|
+
also refuses an unattempted operation, a returned acknowledgement, changed
|
|
199
|
+
entry predicates, missing class relation or a retired Owner. Retiring one
|
|
200
|
+
invocation cannot retire another SDK root or return its receipt. These are
|
|
201
|
+
ordinary Node and Convex-test mechanics with controlled HTTP, not native or
|
|
202
|
+
provider qualification. Cross-process recovery cannot revive this Owner or
|
|
203
|
+
reconstruct actual live response custody from stored DATA.
|
|
143
204
|
|
|
144
205
|
## Component operation journal
|
|
145
206
|
|
package/package.json
CHANGED
|
@@ -22,6 +22,10 @@ import {
|
|
|
22
22
|
type RawReadTransport,
|
|
23
23
|
} from "./rawWireSource.js";
|
|
24
24
|
import { acquireCouponJoins } from "./rawCouponJoins.js";
|
|
25
|
+
import { ownerForInitialLineage } from "../producer/ownerFactory.js";
|
|
26
|
+
import { ownedAwaitForInitialLineage } from "../producer/ownedAwaitFactory.js";
|
|
27
|
+
import { operationForInitialLineage } from "../producer/operationFactory.js";
|
|
28
|
+
import { createInitialTransportForLineage } from "../operations/fixedTransport.js";
|
|
25
29
|
const need: (x: unknown) => asserts x = (x) => {
|
|
26
30
|
if (!x) throw Error("RAW_ACQUISITION_STOP");
|
|
27
31
|
};
|
|
@@ -47,6 +51,44 @@ type RawSuccess = Readonly<{
|
|
|
47
51
|
export type RawAcquisitionResult = typeof STOP | RawSuccess;
|
|
48
52
|
export type RawConfigureAcquisitionResult =
|
|
49
53
|
typeof STOP | (RawSuccess & Readonly<{ schedule: Record<string, unknown> }>);
|
|
54
|
+
type InitialReader = Readonly<{ acquire(): Promise<RawAcquisitionResult> }>;
|
|
55
|
+
const initialReaders = new WeakMap<object, Promise<InitialReader>>();
|
|
56
|
+
|
|
57
|
+
/** Fixed source, transport and expected material; no replacement inputs. */
|
|
58
|
+
export function acquisitionForInitialLineage(
|
|
59
|
+
token: object,
|
|
60
|
+
): Promise<InitialReader> {
|
|
61
|
+
if (arguments.length !== 1) throw Error("RAW_ACQUISITION_STOP");
|
|
62
|
+
const owner = ownerForInitialLineage(token);
|
|
63
|
+
owner.check();
|
|
64
|
+
const owned = ownedAwaitForInitialLineage(token);
|
|
65
|
+
let pending = initialReaders.get(token);
|
|
66
|
+
if (!pending) {
|
|
67
|
+
pending = owned(async () => {
|
|
68
|
+
try {
|
|
69
|
+
const frame = await operationForInitialLineage(token);
|
|
70
|
+
const pair = await createInitialTransportForLineage(token);
|
|
71
|
+
owner.check();
|
|
72
|
+
const reader = createSelectedRawAcquisition(
|
|
73
|
+
owner,
|
|
74
|
+
captureTransport(pair.transport.readTransport),
|
|
75
|
+
);
|
|
76
|
+
return Object.freeze({
|
|
77
|
+
acquire() {
|
|
78
|
+
if (arguments.length !== 0) throw Error("RAW_ACQUISITION_STOP");
|
|
79
|
+
return owned(() => reader.acquire(frame.expected));
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
} catch (error) {
|
|
83
|
+
owner.retire();
|
|
84
|
+
throw error;
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
initialReaders.set(token, pending);
|
|
88
|
+
}
|
|
89
|
+
const captured = pending;
|
|
90
|
+
return owned(() => captured);
|
|
91
|
+
}
|
|
50
92
|
const observed = z.union([
|
|
51
93
|
z.null(),
|
|
52
94
|
resourceId("sub_sched"),
|
|
@@ -167,18 +209,18 @@ function captureTransport(sourceTransport: RawReadTransport): RawReadTransport {
|
|
|
167
209
|
return capturedTransport;
|
|
168
210
|
}
|
|
169
211
|
|
|
170
|
-
function createSelectedRawAcquisition(
|
|
212
|
+
export function createSelectedRawAcquisition(
|
|
171
213
|
sourceOwner: typeof OWNER,
|
|
172
214
|
sourceTransport: RawReadTransport,
|
|
173
215
|
): Readonly<{ acquire(rawExpected: unknown): Promise<RawAcquisitionResult> }>;
|
|
174
|
-
function createSelectedRawAcquisition(
|
|
216
|
+
export function createSelectedRawAcquisition(
|
|
175
217
|
sourceOwner: typeof OWNER,
|
|
176
218
|
sourceTransport: RawReadTransport,
|
|
177
219
|
fixedScheduleId: string,
|
|
178
220
|
): Readonly<{
|
|
179
221
|
acquire(rawExpected: unknown): Promise<RawConfigureAcquisitionResult>;
|
|
180
222
|
}>;
|
|
181
|
-
function createSelectedRawAcquisition(
|
|
223
|
+
export function createSelectedRawAcquisition(
|
|
182
224
|
sourceOwner: typeof OWNER,
|
|
183
225
|
sourceTransport: RawReadTransport,
|
|
184
226
|
fixedScheduleId: string | null = null,
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
import { materialize } from "./eventCodec.js";
|
|
12
12
|
import { createStageChannel, createInitialStageChannel } from "./appendAck.js";
|
|
13
13
|
import { readInitialLineage } from "../producer/lineageAuthority.js";
|
|
14
|
+
import { journalWorkForInitialLineage } from "../producer/journalWorkFactory.js";
|
|
14
15
|
import { ownerForInitialLineage } from "../producer/ownerFactory.js";
|
|
15
16
|
import { ownedAwaitForInitialLineage } from "../producer/ownedAwaitFactory.js";
|
|
16
17
|
import {
|
|
@@ -22,16 +23,27 @@ export function createAttachEventCompiler(raw: unknown, options: unknown) {
|
|
|
22
23
|
return attachEventCompiler(raw, createStageChannel(options));
|
|
23
24
|
}
|
|
24
25
|
const initialChannels = new WeakSet<object>();
|
|
26
|
+
const recoveryChannels = new WeakSet<object>();
|
|
27
|
+
export function createRecoveryAttachEventCompiler(token: object) {
|
|
28
|
+
return lineageAttachEventCompiler(token, recoveryChannels, arguments.length);
|
|
29
|
+
}
|
|
25
30
|
/** Exact original call, source and journal; no replacement sink or Owner input. */
|
|
26
31
|
export function createInitialAttachEventCompiler(token: object) {
|
|
32
|
+
return lineageAttachEventCompiler(token, initialChannels, arguments.length);
|
|
33
|
+
}
|
|
34
|
+
function lineageAttachEventCompiler(
|
|
35
|
+
token: object,
|
|
36
|
+
channels: WeakSet<object>,
|
|
37
|
+
arity: number,
|
|
38
|
+
) {
|
|
27
39
|
const owner = ownerForInitialLineage(token);
|
|
28
40
|
owner.check();
|
|
29
|
-
if (
|
|
30
|
-
|
|
31
|
-
if (
|
|
32
|
-
const { reservation
|
|
41
|
+
if (channels.has(token)) throw Error("INITIAL_CHANNEL_CONSUMED");
|
|
42
|
+
channels.add(token);
|
|
43
|
+
if (arity !== 1) throw Error("INITIAL_CHANNEL_UNBOUND");
|
|
44
|
+
const { reservation } = readInitialLineage(token);
|
|
33
45
|
const source = JSON.parse(reservation.recordJSON);
|
|
34
|
-
const send =
|
|
46
|
+
const send = journalWorkForInitialLineage(token).captureSend();
|
|
35
47
|
const owned = ownedAwaitForInitialLineage(token);
|
|
36
48
|
owner.check();
|
|
37
49
|
const channel = createInitialStageChannel(token, {
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import type { AttachRequest } from "./types.js";
|
|
2
|
+
import type { Diagnostics } from "./providerFailure.js";
|
|
3
|
+
import type { createOwnedTransportWithAttemptCapability } from "./fixedTransport.js";
|
|
4
|
+
import { need, stop } from "./initialActorData.js";
|
|
5
|
+
|
|
6
|
+
/** Invocation-local failure projection; no transport, Owner or Source mint. */
|
|
7
|
+
export function captureActorFailureControl(
|
|
8
|
+
OWNER: { check(): unknown },
|
|
9
|
+
activePair: ReturnType<typeof createOwnedTransportWithAttemptCapability>,
|
|
10
|
+
request: AttachRequest,
|
|
11
|
+
) {
|
|
12
|
+
const capability = activePair.capability,
|
|
13
|
+
takeQuarantine = capability.takeFulfilledQuarantine;
|
|
14
|
+
Object.freeze(request.payload);
|
|
15
|
+
Object.freeze(request.requestIdentity);
|
|
16
|
+
Object.freeze(request);
|
|
17
|
+
OWNER.check();
|
|
18
|
+
type Token = {
|
|
19
|
+
invocation: object;
|
|
20
|
+
phase: "read" | "post";
|
|
21
|
+
ordinal: number;
|
|
22
|
+
request: AttachRequest;
|
|
23
|
+
diagnostics: Diagnostics;
|
|
24
|
+
};
|
|
25
|
+
const tokens = new WeakMap<object, Token>(),
|
|
26
|
+
invocation = Object.freeze({});
|
|
27
|
+
let phase = "unused";
|
|
28
|
+
const tokenValue = (error: unknown) =>
|
|
29
|
+
error !== null && (typeof error === "object" || typeof error === "function")
|
|
30
|
+
? tokens.get(error)
|
|
31
|
+
: undefined;
|
|
32
|
+
function consume(error: unknown, kind: "read" | "post") {
|
|
33
|
+
OWNER.check();
|
|
34
|
+
const value = tokenValue(error);
|
|
35
|
+
if (
|
|
36
|
+
error !== null &&
|
|
37
|
+
(typeof error === "object" || typeof error === "function")
|
|
38
|
+
)
|
|
39
|
+
tokens.delete(error);
|
|
40
|
+
if (
|
|
41
|
+
!value ||
|
|
42
|
+
value.invocation !== invocation ||
|
|
43
|
+
value.phase !== kind ||
|
|
44
|
+
phase !== (kind === "read" ? "failed" : "failed_post")
|
|
45
|
+
)
|
|
46
|
+
return null;
|
|
47
|
+
phase = kind === "read" ? "consumed" : "consumed_post";
|
|
48
|
+
const failure = Object.freeze({
|
|
49
|
+
category: "provider_rejected",
|
|
50
|
+
phase: kind,
|
|
51
|
+
ordinal: value.ordinal,
|
|
52
|
+
request: value.request,
|
|
53
|
+
diagnostics: value.diagnostics,
|
|
54
|
+
outcome: "unknown",
|
|
55
|
+
operationalAuthority: false,
|
|
56
|
+
});
|
|
57
|
+
const out = Error("INITIAL_PROVIDER_REJECTED");
|
|
58
|
+
Object.defineProperty(out, "failure", {
|
|
59
|
+
value: failure,
|
|
60
|
+
enumerable: false,
|
|
61
|
+
writable: false,
|
|
62
|
+
configurable: false,
|
|
63
|
+
});
|
|
64
|
+
return out;
|
|
65
|
+
}
|
|
66
|
+
return Object.freeze({
|
|
67
|
+
takePostQuarantine(...args: unknown[]) {
|
|
68
|
+
if (args.length !== 0) return null;
|
|
69
|
+
return Reflect.apply(takeQuarantine, capability, []) as object | null;
|
|
70
|
+
},
|
|
71
|
+
begin() {
|
|
72
|
+
OWNER.check();
|
|
73
|
+
if (phase !== "unused") stop();
|
|
74
|
+
if (capability.assertVirginAcquisition() !== true) {
|
|
75
|
+
phase = "closed";
|
|
76
|
+
stop();
|
|
77
|
+
}
|
|
78
|
+
OWNER.check();
|
|
79
|
+
phase = "acquiring";
|
|
80
|
+
},
|
|
81
|
+
complete() {
|
|
82
|
+
OWNER.check();
|
|
83
|
+
if (phase !== "acquiring") stop();
|
|
84
|
+
phase = "complete";
|
|
85
|
+
},
|
|
86
|
+
takeReadFailure() {
|
|
87
|
+
OWNER.check();
|
|
88
|
+
if (phase !== "acquiring") stop();
|
|
89
|
+
const record = capability.consumeReadCatch();
|
|
90
|
+
OWNER.check();
|
|
91
|
+
if (record === null) {
|
|
92
|
+
phase = "unsupported";
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
need(
|
|
96
|
+
record.phase === "read" &&
|
|
97
|
+
Number.isSafeInteger(record.ordinal) &&
|
|
98
|
+
record.ordinal >= 1 &&
|
|
99
|
+
record.ordinal <= 43,
|
|
100
|
+
);
|
|
101
|
+
const token = Object.freeze(Object.create(null)) as object;
|
|
102
|
+
tokens.set(
|
|
103
|
+
token,
|
|
104
|
+
Object.freeze({
|
|
105
|
+
invocation,
|
|
106
|
+
phase: "read",
|
|
107
|
+
ordinal: record.ordinal,
|
|
108
|
+
request,
|
|
109
|
+
diagnostics: record.diagnostics,
|
|
110
|
+
}),
|
|
111
|
+
);
|
|
112
|
+
phase = "failed";
|
|
113
|
+
return token;
|
|
114
|
+
},
|
|
115
|
+
beginPost() {
|
|
116
|
+
OWNER.check();
|
|
117
|
+
if (phase !== "complete") stop();
|
|
118
|
+
phase = "posting";
|
|
119
|
+
},
|
|
120
|
+
takePostFailure(actualReply: unknown) {
|
|
121
|
+
OWNER.check();
|
|
122
|
+
if (phase !== "posting") stop();
|
|
123
|
+
const record = capability.consumePostCatch(actualReply);
|
|
124
|
+
OWNER.check();
|
|
125
|
+
if (record === null) {
|
|
126
|
+
phase = "post_without_token";
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
need(
|
|
130
|
+
record.phase === "post" &&
|
|
131
|
+
Number.isSafeInteger(record.ordinal) &&
|
|
132
|
+
record.ordinal >= 1 &&
|
|
133
|
+
record.ordinal <= 44,
|
|
134
|
+
);
|
|
135
|
+
const token = Object.freeze(Object.create(null)) as object;
|
|
136
|
+
tokens.set(
|
|
137
|
+
token,
|
|
138
|
+
Object.freeze({
|
|
139
|
+
invocation,
|
|
140
|
+
phase: "post",
|
|
141
|
+
ordinal: record.ordinal,
|
|
142
|
+
request,
|
|
143
|
+
diagnostics: record.diagnostics,
|
|
144
|
+
}),
|
|
145
|
+
);
|
|
146
|
+
phase = "failed_post";
|
|
147
|
+
return token;
|
|
148
|
+
},
|
|
149
|
+
forward(error: unknown) {
|
|
150
|
+
OWNER.check();
|
|
151
|
+
const value = tokenValue(error);
|
|
152
|
+
return value &&
|
|
153
|
+
value.invocation === invocation &&
|
|
154
|
+
(phase === "failed" || phase === "failed_post")
|
|
155
|
+
? (error as object)
|
|
156
|
+
: null;
|
|
157
|
+
},
|
|
158
|
+
consume(error: unknown) {
|
|
159
|
+
return consume(error, "read");
|
|
160
|
+
},
|
|
161
|
+
consumePost(error: unknown) {
|
|
162
|
+
return consume(error, "post");
|
|
163
|
+
},
|
|
164
|
+
});
|
|
165
|
+
}
|