@fantastic.dev/better-stripe 0.93.0 → 0.95.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/operationJournal.d.ts +47 -0
- package/dist/client/billing/renewalAttach/internal/operationJournal.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operationJournal.js +388 -0
- package/dist/client/billing/renewalAttach/internal/operationJournal.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.d.ts +24 -5
- package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.js +182 -4
- package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.d.ts +13 -0
- package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.js +43 -0
- package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.d.ts +32 -0
- package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.js +105 -0
- package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/ownedAwaitFactory.d.ts +3 -0
- package/dist/client/billing/renewalAttach/internal/producer/ownedAwaitFactory.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/ownedAwaitFactory.js +59 -0
- package/dist/client/billing/renewalAttach/internal/producer/ownedAwaitFactory.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/ownerFactory.d.ts +11 -0
- package/dist/client/billing/renewalAttach/internal/producer/ownerFactory.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/ownerFactory.js +121 -0
- package/dist/client/billing/renewalAttach/internal/producer/ownerFactory.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/stockDelegateFactory.d.ts +6 -0
- package/dist/client/billing/renewalAttach/internal/producer/stockDelegateFactory.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/stockDelegateFactory.js +16 -0
- package/dist/client/billing/renewalAttach/internal/producer/stockDelegateFactory.js.map +1 -0
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +32 -32
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts +16 -16
- package/dist/component/balanceFunding/internal/actions.d.ts +11 -11
- package/dist/component/balanceFunding/mutations.d.ts +43 -43
- package/dist/component/balanceFunding/preparationHandlers.d.ts +8 -8
- package/dist/component/financialObservations/settlementHelpers.d.ts +3 -3
- package/dist/component/usageCredits/accounting.fixtures.d.ts +16 -16
- package/docs/renewal-context-reads.md +57 -5
- package/package.json +1 -1
- package/src/client/billing/renewalAttach/internal/operationJournal.acknowledgement.integration.test.ts +500 -0
- package/src/client/billing/renewalAttach/internal/operationJournal.c10.integration.test.ts +560 -0
- package/src/client/billing/renewalAttach/internal/operationJournal.controls.integration.test.ts +356 -0
- package/src/client/billing/renewalAttach/internal/operationJournal.integration.test.ts +181 -1
- package/src/client/billing/renewalAttach/internal/operationJournal.methods.integration.test.ts +534 -0
- package/src/client/billing/renewalAttach/internal/operationJournal.ts +573 -0
- package/src/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.ts +246 -8
- package/src/client/billing/renewalAttach/internal/producer/invocationProducer.ts +58 -0
- package/src/client/billing/renewalAttach/internal/producer/lineageAuthority.ts +161 -0
- package/src/client/billing/renewalAttach/internal/producer/ownedAwaitFactory.ts +54 -0
- package/src/client/billing/renewalAttach/internal/producer/ownerFactory.ts +124 -0
- package/src/client/billing/renewalAttach/internal/producer/producerGuards.integration.test.ts +323 -0
- package/src/client/billing/renewalAttach/internal/producer/producerInitial.integration.test.ts +301 -0
- package/src/client/billing/renewalAttach/internal/producer/producerIsolation.integration.test.ts +531 -0
- package/src/client/billing/renewalAttach/internal/producer/producerOwner.integration.test.ts +457 -0
- package/src/client/billing/renewalAttach/internal/producer/stockDelegateFactory.ts +23 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/producerInitialDeclarations.ts +5 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/producerInitialOperation.ts +80 -0
|
@@ -0,0 +1,573 @@
|
|
|
1
|
+
import {
|
|
2
|
+
captureMaintainedJournalBinding,
|
|
3
|
+
readCheckedJournalActionRPC,
|
|
4
|
+
type ClassActionInput,
|
|
5
|
+
} from "./producer/classOwnedActionRoot.js";
|
|
6
|
+
import type {
|
|
7
|
+
GenericActionCtx,
|
|
8
|
+
GenericDataModel,
|
|
9
|
+
FunctionReturnType,
|
|
10
|
+
FunctionArgs,
|
|
11
|
+
} from "convex/server";
|
|
12
|
+
import type { ComponentApi } from "../../../../component/_generated/component.js";
|
|
13
|
+
import { closed, type EventRecord } from "./c10/ownData.js";
|
|
14
|
+
import { renewalSnapshot } from "../../renewalReplacementSnapshot.js";
|
|
15
|
+
import {
|
|
16
|
+
admitJournalValue,
|
|
17
|
+
canonicalJournalEvent,
|
|
18
|
+
canonicalJournalRecord,
|
|
19
|
+
journalReservationMaterial,
|
|
20
|
+
} from "../../../../shared/renewalOperationJournal.js";
|
|
21
|
+
|
|
22
|
+
const classJournalBindings = new WeakMap<object, object>();
|
|
23
|
+
type Journal = ComponentApi["renewalOperations"];
|
|
24
|
+
type Reservation = FunctionArgs<
|
|
25
|
+
Journal["mutations"]["appendStageEvent"]
|
|
26
|
+
>["reservation"];
|
|
27
|
+
type FreshReserveArgs = Omit<
|
|
28
|
+
FunctionArgs<Journal["mutations"]["reserveAttempt"]>,
|
|
29
|
+
"operationId"
|
|
30
|
+
>;
|
|
31
|
+
type FreshReserveResult = Readonly<{
|
|
32
|
+
result: FunctionReturnType<Journal["mutations"]["reserveAttempt"]>;
|
|
33
|
+
call: object | null;
|
|
34
|
+
}>;
|
|
35
|
+
type ConsumedReservation = Readonly<{
|
|
36
|
+
reservation: Readonly<Reservation>;
|
|
37
|
+
tag: object;
|
|
38
|
+
}>;
|
|
39
|
+
type ClassJournal = Awaited<ReturnType<typeof createActionOperationJournal>> &
|
|
40
|
+
Readonly<{
|
|
41
|
+
reserveFreshAttempt(args: FreshReserveArgs): Promise<FreshReserveResult>;
|
|
42
|
+
}>;
|
|
43
|
+
type ReserveReply = FunctionReturnType<Journal["mutations"]["reserveAttempt"]>;
|
|
44
|
+
type WinningCallState = {
|
|
45
|
+
spent: boolean;
|
|
46
|
+
readonly journal: object;
|
|
47
|
+
readonly binding: object;
|
|
48
|
+
readonly rpc: ReturnType<typeof readCheckedJournalActionRPC>;
|
|
49
|
+
readonly source: Awaited<ReturnType<typeof createActionOperationJournal>>;
|
|
50
|
+
readonly reserve: Awaited<
|
|
51
|
+
ReturnType<typeof createActionOperationJournal>
|
|
52
|
+
>["reserveAttempt"];
|
|
53
|
+
readonly request: Readonly<FreshReserveArgs>;
|
|
54
|
+
readonly promise: Promise<ReserveReply>;
|
|
55
|
+
readonly result: Extract<ReserveReply, { disposition: "acquired" }>;
|
|
56
|
+
readonly reservation: Readonly<Reservation>;
|
|
57
|
+
};
|
|
58
|
+
const winningCalls = new WeakMap<object, WinningCallState>();
|
|
59
|
+
function callUnbound(): never {
|
|
60
|
+
throw Error("CLASS_JOURNAL_CALL_UNBOUND");
|
|
61
|
+
}
|
|
62
|
+
type ActionContext = GenericActionCtx<GenericDataModel>;
|
|
63
|
+
type LoadedOperation = FunctionReturnType<
|
|
64
|
+
ComponentApi["renewalOperations"]["queries"]["loadAuthorizedOperation"]
|
|
65
|
+
>;
|
|
66
|
+
function unbound(): never {
|
|
67
|
+
throw Error("OPERATION_JOURNAL_ACTION_UNBOUND");
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Private trusted-host capture only; metadata is not hostile-host attestation.
|
|
71
|
+
* Fixed eight-reference DATA adapter; no class admission or fresh handle.
|
|
72
|
+
* Component mutation replies are not runtime dispatch or Owner capabilities.
|
|
73
|
+
*/
|
|
74
|
+
export async function createActionOperationJournal(
|
|
75
|
+
actualActionCtx: ActionContext,
|
|
76
|
+
component: ComponentApi,
|
|
77
|
+
operationId: string,
|
|
78
|
+
) {
|
|
79
|
+
const metaReceiver = actualActionCtx.meta;
|
|
80
|
+
const runQuery = actualActionCtx.runQuery;
|
|
81
|
+
const runMutation = actualActionCtx.runMutation;
|
|
82
|
+
if (
|
|
83
|
+
!metaReceiver ||
|
|
84
|
+
typeof metaReceiver.getFunctionMetadata !== "function" ||
|
|
85
|
+
typeof runQuery !== "function" ||
|
|
86
|
+
typeof runMutation !== "function" ||
|
|
87
|
+
typeof operationId !== "string" ||
|
|
88
|
+
operationId.length === 0
|
|
89
|
+
)
|
|
90
|
+
unbound();
|
|
91
|
+
const getMetadata = metaReceiver.getFunctionMetadata;
|
|
92
|
+
const references = Object.freeze({
|
|
93
|
+
loadAuthorizedOperation:
|
|
94
|
+
component.renewalOperations.queries.loadAuthorizedOperation,
|
|
95
|
+
reserveAttempt: component.renewalOperations.mutations.reserveAttempt,
|
|
96
|
+
bindInitialBasis: component.renewalOperations.mutations.bindInitialBasis,
|
|
97
|
+
appendStageEvent: component.renewalOperations.mutations.appendStageEvent,
|
|
98
|
+
readAttempt: component.renewalOperations.queries.readAttempt,
|
|
99
|
+
readStageEvent: component.renewalOperations.queries.readStageEvent,
|
|
100
|
+
retainProviderAcknowledgement:
|
|
101
|
+
component.renewalOperations.mutations.retainProviderAcknowledgement,
|
|
102
|
+
readProviderAcknowledgement:
|
|
103
|
+
component.renewalOperations.queries.readProviderAcknowledgement,
|
|
104
|
+
});
|
|
105
|
+
const metadata = await getMetadata.call(metaReceiver);
|
|
106
|
+
if (
|
|
107
|
+
metadata.type !== "action" ||
|
|
108
|
+
typeof metadata.name !== "string" ||
|
|
109
|
+
metadata.name.length === 0 ||
|
|
110
|
+
typeof metadata.componentPath !== "string"
|
|
111
|
+
)
|
|
112
|
+
unbound();
|
|
113
|
+
const captured = Object.freeze({
|
|
114
|
+
receiver: actualActionCtx,
|
|
115
|
+
metaReceiver,
|
|
116
|
+
getMetadata,
|
|
117
|
+
runQuery,
|
|
118
|
+
runMutation,
|
|
119
|
+
references,
|
|
120
|
+
operationId,
|
|
121
|
+
metadata,
|
|
122
|
+
});
|
|
123
|
+
function checkCapture(): void {
|
|
124
|
+
const binding = classJournalBindings.get(journal);
|
|
125
|
+
if (binding) {
|
|
126
|
+
const rpc = readCheckedJournalActionRPC(binding);
|
|
127
|
+
if (
|
|
128
|
+
rpc.receiver !== captured.receiver ||
|
|
129
|
+
rpc.component !== component ||
|
|
130
|
+
rpc.operationId !== captured.operationId ||
|
|
131
|
+
rpc.runQuery !== captured.runQuery ||
|
|
132
|
+
rpc.runMutation !== captured.runMutation ||
|
|
133
|
+
rpc.metaReceiver !== captured.metaReceiver ||
|
|
134
|
+
rpc.getMetadata !== captured.getMetadata
|
|
135
|
+
)
|
|
136
|
+
unbound();
|
|
137
|
+
}
|
|
138
|
+
if (
|
|
139
|
+
captured.receiver.meta !== captured.metaReceiver ||
|
|
140
|
+
captured.metaReceiver.getFunctionMetadata !== captured.getMetadata ||
|
|
141
|
+
captured.receiver.runQuery !== captured.runQuery ||
|
|
142
|
+
captured.receiver.runMutation !== captured.runMutation
|
|
143
|
+
)
|
|
144
|
+
unbound();
|
|
145
|
+
}
|
|
146
|
+
function checkArguments(args: object) {
|
|
147
|
+
checkCapture();
|
|
148
|
+
if (
|
|
149
|
+
typeof args !== "object" ||
|
|
150
|
+
args === null ||
|
|
151
|
+
Array.isArray(args) ||
|
|
152
|
+
"operationId" in args
|
|
153
|
+
)
|
|
154
|
+
unbound();
|
|
155
|
+
}
|
|
156
|
+
// Local DATA object custody only, not a fresh execution or provider permit.
|
|
157
|
+
const reservations = new WeakMap<
|
|
158
|
+
object,
|
|
159
|
+
Readonly<{ reservation: Readonly<Reservation>; json: string }>
|
|
160
|
+
>();
|
|
161
|
+
function reservationJSON(value: unknown): string {
|
|
162
|
+
try {
|
|
163
|
+
const common = [
|
|
164
|
+
"operationId",
|
|
165
|
+
"attemptId",
|
|
166
|
+
"payloadId",
|
|
167
|
+
"authorizationScope",
|
|
168
|
+
"authorizationId",
|
|
169
|
+
"authorizationRevision",
|
|
170
|
+
"logicalOperationId",
|
|
171
|
+
"requestBinding",
|
|
172
|
+
"key",
|
|
173
|
+
"apiVersion",
|
|
174
|
+
"accountJSON",
|
|
175
|
+
"firstDispatchedAt",
|
|
176
|
+
"ordinal",
|
|
177
|
+
"preparedRevision",
|
|
178
|
+
"committedRevision",
|
|
179
|
+
"recordJSON",
|
|
180
|
+
"stage",
|
|
181
|
+
];
|
|
182
|
+
const operational =
|
|
183
|
+
value !== null &&
|
|
184
|
+
typeof value === "object" &&
|
|
185
|
+
Object.prototype.hasOwnProperty.call(value, "recordVersion");
|
|
186
|
+
const own = closed(value, [
|
|
187
|
+
...common,
|
|
188
|
+
...(operational
|
|
189
|
+
? ["recordVersion", "timingPolicyJSON"]
|
|
190
|
+
: ["basisJSON"]),
|
|
191
|
+
]);
|
|
192
|
+
if (
|
|
193
|
+
typeof own.recordJSON !== "string" ||
|
|
194
|
+
typeof own.attemptId !== "string" ||
|
|
195
|
+
own.attemptId.length === 0 ||
|
|
196
|
+
typeof own.payloadId !== "string" ||
|
|
197
|
+
own.payloadId.length === 0
|
|
198
|
+
)
|
|
199
|
+
unbound();
|
|
200
|
+
const full = canonicalJournalRecord(own.recordJSON);
|
|
201
|
+
const expected = {
|
|
202
|
+
operationId: captured.operationId,
|
|
203
|
+
attemptId: own.attemptId,
|
|
204
|
+
payloadId: own.payloadId,
|
|
205
|
+
authorizationScope: full.authorizationScope,
|
|
206
|
+
authorizationId: full.authorizationId,
|
|
207
|
+
authorizationRevision: full.authorizationRevision,
|
|
208
|
+
logicalOperationId: full.logicalOperationId,
|
|
209
|
+
requestBinding: full.requestBinding,
|
|
210
|
+
ordinal: 1,
|
|
211
|
+
preparedRevision: 0,
|
|
212
|
+
committedRevision: 1,
|
|
213
|
+
recordJSON: full.json,
|
|
214
|
+
...journalReservationMaterial(full),
|
|
215
|
+
};
|
|
216
|
+
if (
|
|
217
|
+
Object.keys(expected).length !== Object.keys(own).length ||
|
|
218
|
+
!Object.entries(expected).every(([key, value]) => own[key] === value)
|
|
219
|
+
)
|
|
220
|
+
unbound();
|
|
221
|
+
return JSON.stringify(
|
|
222
|
+
Object.fromEntries(
|
|
223
|
+
Object.entries(own).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)),
|
|
224
|
+
),
|
|
225
|
+
);
|
|
226
|
+
} catch {
|
|
227
|
+
unbound();
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
const journal = Object.freeze({
|
|
231
|
+
createC10Send(
|
|
232
|
+
actualReservation: Reservation,
|
|
233
|
+
): (
|
|
234
|
+
record: Readonly<EventRecord>,
|
|
235
|
+
ack: (value: unknown) => void,
|
|
236
|
+
) => Promise<void> {
|
|
237
|
+
checkCapture();
|
|
238
|
+
const found = reservations.get(actualReservation);
|
|
239
|
+
if (!found || reservationJSON(actualReservation) !== found.json)
|
|
240
|
+
unbound();
|
|
241
|
+
const saved = found;
|
|
242
|
+
let busy = false;
|
|
243
|
+
let stopped = false;
|
|
244
|
+
function gate() {
|
|
245
|
+
checkCapture();
|
|
246
|
+
if (stopped || reservationJSON(actualReservation) !== saved.json)
|
|
247
|
+
unbound();
|
|
248
|
+
}
|
|
249
|
+
return async (record, ack) => {
|
|
250
|
+
if (busy || stopped) {
|
|
251
|
+
stopped = true;
|
|
252
|
+
unbound();
|
|
253
|
+
}
|
|
254
|
+
busy = true;
|
|
255
|
+
try {
|
|
256
|
+
gate();
|
|
257
|
+
if (typeof ack !== "function") unbound();
|
|
258
|
+
const own = closed(record, ["sequence", "binding", "data"]);
|
|
259
|
+
const sequence = own.sequence;
|
|
260
|
+
const binding = own.binding;
|
|
261
|
+
if (
|
|
262
|
+
(sequence !== 1 && sequence !== 2 && sequence !== 3) ||
|
|
263
|
+
typeof binding !== "string"
|
|
264
|
+
)
|
|
265
|
+
unbound();
|
|
266
|
+
const event = await canonicalJournalEvent(
|
|
267
|
+
sequence,
|
|
268
|
+
JSON.stringify(renewalSnapshot(own.data)),
|
|
269
|
+
);
|
|
270
|
+
gate();
|
|
271
|
+
if (event.binding !== binding) unbound();
|
|
272
|
+
const args: FunctionArgs<Journal["mutations"]["appendStageEvent"]> = {
|
|
273
|
+
reservation: saved.reservation,
|
|
274
|
+
expectedSequence: sequence - 1,
|
|
275
|
+
event: { sequence, binding, dataJSON: event.json },
|
|
276
|
+
};
|
|
277
|
+
admitJournalValue(args);
|
|
278
|
+
const reply: FunctionReturnType<
|
|
279
|
+
Journal["mutations"]["appendStageEvent"]
|
|
280
|
+
> = await captured.runMutation.call(
|
|
281
|
+
captured.receiver,
|
|
282
|
+
captured.references.appendStageEvent,
|
|
283
|
+
args,
|
|
284
|
+
);
|
|
285
|
+
gate();
|
|
286
|
+
const result = closed(reply, [
|
|
287
|
+
"operationId",
|
|
288
|
+
"attemptId",
|
|
289
|
+
"stage",
|
|
290
|
+
"sourcePayloadId",
|
|
291
|
+
"sequence",
|
|
292
|
+
"binding",
|
|
293
|
+
"payloadId",
|
|
294
|
+
"eventId",
|
|
295
|
+
"reservation",
|
|
296
|
+
]);
|
|
297
|
+
if (
|
|
298
|
+
result.operationId !== captured.operationId ||
|
|
299
|
+
result.attemptId !== saved.reservation.attemptId ||
|
|
300
|
+
result.stage !== saved.reservation.stage ||
|
|
301
|
+
result.sourcePayloadId !== saved.reservation.payloadId ||
|
|
302
|
+
result.sequence !== sequence ||
|
|
303
|
+
result.binding !== binding ||
|
|
304
|
+
typeof result.payloadId !== "string" ||
|
|
305
|
+
result.payloadId.length === 0 ||
|
|
306
|
+
result.payloadId === saved.reservation.payloadId ||
|
|
307
|
+
typeof result.eventId !== "string" ||
|
|
308
|
+
result.eventId.length === 0 ||
|
|
309
|
+
reservationJSON(result.reservation) !== saved.json
|
|
310
|
+
)
|
|
311
|
+
unbound();
|
|
312
|
+
gate();
|
|
313
|
+
ack(Object.freeze({ sequence, binding }));
|
|
314
|
+
} catch (error) {
|
|
315
|
+
stopped = true;
|
|
316
|
+
throw error;
|
|
317
|
+
} finally {
|
|
318
|
+
busy = false;
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
},
|
|
322
|
+
async loadAuthorizedOperation(): Promise<LoadedOperation> {
|
|
323
|
+
checkCapture();
|
|
324
|
+
return captured.runQuery.call(
|
|
325
|
+
captured.receiver,
|
|
326
|
+
captured.references.loadAuthorizedOperation,
|
|
327
|
+
{ operationId: captured.operationId },
|
|
328
|
+
);
|
|
329
|
+
},
|
|
330
|
+
async reserveAttempt(
|
|
331
|
+
args: Omit<
|
|
332
|
+
FunctionArgs<Journal["mutations"]["reserveAttempt"]>,
|
|
333
|
+
"operationId"
|
|
334
|
+
>,
|
|
335
|
+
): Promise<FunctionReturnType<Journal["mutations"]["reserveAttempt"]>> {
|
|
336
|
+
checkArguments(args);
|
|
337
|
+
const reply: FunctionReturnType<Journal["mutations"]["reserveAttempt"]> =
|
|
338
|
+
await captured.runMutation.call(
|
|
339
|
+
captured.receiver,
|
|
340
|
+
captured.references.reserveAttempt,
|
|
341
|
+
{ ...args, operationId: captured.operationId },
|
|
342
|
+
);
|
|
343
|
+
checkCapture();
|
|
344
|
+
if (reply.disposition !== "conflict") {
|
|
345
|
+
const json = reservationJSON(reply.reservation);
|
|
346
|
+
reservations.set(
|
|
347
|
+
reply.reservation,
|
|
348
|
+
Object.freeze({
|
|
349
|
+
reservation: Object.freeze({ ...reply.reservation }),
|
|
350
|
+
json,
|
|
351
|
+
}),
|
|
352
|
+
);
|
|
353
|
+
}
|
|
354
|
+
return reply;
|
|
355
|
+
},
|
|
356
|
+
async bindInitialBasis(
|
|
357
|
+
args: Omit<
|
|
358
|
+
FunctionArgs<Journal["mutations"]["bindInitialBasis"]>,
|
|
359
|
+
"operationId"
|
|
360
|
+
>,
|
|
361
|
+
): Promise<FunctionReturnType<Journal["mutations"]["bindInitialBasis"]>> {
|
|
362
|
+
checkArguments(args);
|
|
363
|
+
return captured.runMutation.call(
|
|
364
|
+
captured.receiver,
|
|
365
|
+
captured.references.bindInitialBasis,
|
|
366
|
+
{ ...args, operationId: captured.operationId },
|
|
367
|
+
);
|
|
368
|
+
},
|
|
369
|
+
async appendStageEvent(
|
|
370
|
+
args: FunctionArgs<Journal["mutations"]["appendStageEvent"]>,
|
|
371
|
+
): Promise<FunctionReturnType<Journal["mutations"]["appendStageEvent"]>> {
|
|
372
|
+
checkArguments(args);
|
|
373
|
+
if (
|
|
374
|
+
!args.reservation ||
|
|
375
|
+
args.reservation.operationId !== captured.operationId
|
|
376
|
+
)
|
|
377
|
+
unbound();
|
|
378
|
+
return captured.runMutation.call(
|
|
379
|
+
captured.receiver,
|
|
380
|
+
captured.references.appendStageEvent,
|
|
381
|
+
args,
|
|
382
|
+
);
|
|
383
|
+
},
|
|
384
|
+
async readAttempt(
|
|
385
|
+
args: Omit<
|
|
386
|
+
FunctionArgs<Journal["queries"]["readAttempt"]>,
|
|
387
|
+
"operationId"
|
|
388
|
+
>,
|
|
389
|
+
): Promise<FunctionReturnType<Journal["queries"]["readAttempt"]>> {
|
|
390
|
+
checkArguments(args);
|
|
391
|
+
return captured.runQuery.call(
|
|
392
|
+
captured.receiver,
|
|
393
|
+
captured.references.readAttempt,
|
|
394
|
+
{ ...args, operationId: captured.operationId },
|
|
395
|
+
);
|
|
396
|
+
},
|
|
397
|
+
async readStageEvent(
|
|
398
|
+
args: Omit<
|
|
399
|
+
FunctionArgs<Journal["queries"]["readStageEvent"]>,
|
|
400
|
+
"operationId"
|
|
401
|
+
>,
|
|
402
|
+
): Promise<FunctionReturnType<Journal["queries"]["readStageEvent"]>> {
|
|
403
|
+
checkArguments(args);
|
|
404
|
+
return captured.runQuery.call(
|
|
405
|
+
captured.receiver,
|
|
406
|
+
captured.references.readStageEvent,
|
|
407
|
+
{ ...args, operationId: captured.operationId },
|
|
408
|
+
);
|
|
409
|
+
},
|
|
410
|
+
async retainProviderAcknowledgement(
|
|
411
|
+
args: Omit<
|
|
412
|
+
FunctionArgs<Journal["mutations"]["retainProviderAcknowledgement"]>,
|
|
413
|
+
"operationId"
|
|
414
|
+
>,
|
|
415
|
+
): Promise<
|
|
416
|
+
FunctionReturnType<Journal["mutations"]["retainProviderAcknowledgement"]>
|
|
417
|
+
> {
|
|
418
|
+
checkArguments(args);
|
|
419
|
+
return captured.runMutation.call(
|
|
420
|
+
captured.receiver,
|
|
421
|
+
captured.references.retainProviderAcknowledgement,
|
|
422
|
+
{ ...args, operationId: captured.operationId },
|
|
423
|
+
);
|
|
424
|
+
},
|
|
425
|
+
async readProviderAcknowledgement(): Promise<
|
|
426
|
+
FunctionReturnType<Journal["queries"]["readProviderAcknowledgement"]>
|
|
427
|
+
> {
|
|
428
|
+
checkCapture();
|
|
429
|
+
return captured.runQuery.call(
|
|
430
|
+
captured.receiver,
|
|
431
|
+
captured.references.readProviderAcknowledgement,
|
|
432
|
+
{ operationId: captured.operationId },
|
|
433
|
+
);
|
|
434
|
+
},
|
|
435
|
+
});
|
|
436
|
+
return journal;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/** Maintained class/Action journal DATA and local call identity, not execution authority. */
|
|
440
|
+
export async function createClassActionOperationJournal(
|
|
441
|
+
actualRoot: object,
|
|
442
|
+
input: ClassActionInput,
|
|
443
|
+
): Promise<ClassJournal> {
|
|
444
|
+
const binding = await captureMaintainedJournalBinding(actualRoot, input);
|
|
445
|
+
const rpc = readCheckedJournalActionRPC(binding);
|
|
446
|
+
const journal = await createActionOperationJournal(
|
|
447
|
+
rpc.receiver,
|
|
448
|
+
rpc.component,
|
|
449
|
+
rpc.operationId,
|
|
450
|
+
);
|
|
451
|
+
if (readCheckedJournalActionRPC(binding) !== rpc) unbound();
|
|
452
|
+
classJournalBindings.set(journal, binding);
|
|
453
|
+
const reserve = journal.reserveAttempt;
|
|
454
|
+
const classJournal: ClassJournal = Object.freeze({
|
|
455
|
+
...journal,
|
|
456
|
+
async reserveFreshAttempt(
|
|
457
|
+
args: FreshReserveArgs,
|
|
458
|
+
): Promise<FreshReserveResult> {
|
|
459
|
+
const before = readCheckedJournalActionRPC(binding);
|
|
460
|
+
if (before !== rpc) unbound();
|
|
461
|
+
if (
|
|
462
|
+
typeof args !== "object" ||
|
|
463
|
+
args === null ||
|
|
464
|
+
Array.isArray(args) ||
|
|
465
|
+
"operationId" in args
|
|
466
|
+
)
|
|
467
|
+
unbound();
|
|
468
|
+
const own = closed(args, [
|
|
469
|
+
"expectedRevision",
|
|
470
|
+
"stage",
|
|
471
|
+
"expectedRequestBinding",
|
|
472
|
+
"recordJSON",
|
|
473
|
+
]);
|
|
474
|
+
if (
|
|
475
|
+
typeof own.expectedRevision !== "number" ||
|
|
476
|
+
(own.stage !== "attach" && own.stage !== "configure") ||
|
|
477
|
+
typeof own.expectedRequestBinding !== "string" ||
|
|
478
|
+
typeof own.recordJSON !== "string"
|
|
479
|
+
)
|
|
480
|
+
unbound();
|
|
481
|
+
const request: FreshReserveArgs = Object.freeze({
|
|
482
|
+
expectedRevision: own.expectedRevision,
|
|
483
|
+
stage: own.stage,
|
|
484
|
+
expectedRequestBinding: own.expectedRequestBinding,
|
|
485
|
+
recordJSON: own.recordJSON,
|
|
486
|
+
});
|
|
487
|
+
const promise = reserve.call(journal, request);
|
|
488
|
+
const result = await promise;
|
|
489
|
+
if (readCheckedJournalActionRPC(binding) !== before) unbound();
|
|
490
|
+
if (result.disposition !== "acquired")
|
|
491
|
+
return Object.freeze({ result, call: null });
|
|
492
|
+
const top = closed(result, [
|
|
493
|
+
"disposition",
|
|
494
|
+
"previousRevision",
|
|
495
|
+
"committedRevision",
|
|
496
|
+
"reservation",
|
|
497
|
+
]);
|
|
498
|
+
const full = canonicalJournalRecord(request.recordJSON);
|
|
499
|
+
if (
|
|
500
|
+
top.disposition !== "acquired" ||
|
|
501
|
+
top.previousRevision !== 0 ||
|
|
502
|
+
top.committedRevision !== 1 ||
|
|
503
|
+
top.reservation !== result.reservation ||
|
|
504
|
+
request.expectedRevision !== 0 ||
|
|
505
|
+
full.requestBinding !== request.expectedRequestBinding ||
|
|
506
|
+
result.reservation.operationId !== before.operationId ||
|
|
507
|
+
result.reservation.recordJSON !== full.json ||
|
|
508
|
+
result.reservation.requestBinding !== full.requestBinding ||
|
|
509
|
+
result.reservation.stage !== request.stage
|
|
510
|
+
)
|
|
511
|
+
unbound();
|
|
512
|
+
Object.freeze(result.reservation);
|
|
513
|
+
Object.freeze(result);
|
|
514
|
+
const call = Object.freeze({});
|
|
515
|
+
winningCalls.set(call, {
|
|
516
|
+
spent: false,
|
|
517
|
+
journal: classJournal,
|
|
518
|
+
binding,
|
|
519
|
+
rpc: before,
|
|
520
|
+
source: journal,
|
|
521
|
+
reserve,
|
|
522
|
+
request,
|
|
523
|
+
promise,
|
|
524
|
+
result,
|
|
525
|
+
reservation: result.reservation,
|
|
526
|
+
});
|
|
527
|
+
return Object.freeze({ result, call });
|
|
528
|
+
},
|
|
529
|
+
});
|
|
530
|
+
classJournalBindings.set(classJournal, binding);
|
|
531
|
+
return classJournal;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
/** Spend the original local call before inspecting its expected journal. */
|
|
535
|
+
export function consumeClassReservation(
|
|
536
|
+
call: unknown,
|
|
537
|
+
expectedClassJournal: unknown,
|
|
538
|
+
): ConsumedReservation {
|
|
539
|
+
if (typeof call !== "object" || call === null) callUnbound();
|
|
540
|
+
const state = winningCalls.get(call);
|
|
541
|
+
if (!state || state.spent) callUnbound();
|
|
542
|
+
state.spent = true;
|
|
543
|
+
try {
|
|
544
|
+
if (
|
|
545
|
+
arguments.length !== 2 ||
|
|
546
|
+
typeof expectedClassJournal !== "object" ||
|
|
547
|
+
expectedClassJournal === null ||
|
|
548
|
+
classJournalBindings.get(expectedClassJournal) !== state.binding ||
|
|
549
|
+
expectedClassJournal !== state.journal ||
|
|
550
|
+
state.source.reserveAttempt !== state.reserve ||
|
|
551
|
+
readCheckedJournalActionRPC(state.binding) !== state.rpc
|
|
552
|
+
)
|
|
553
|
+
callUnbound();
|
|
554
|
+
return Object.freeze({
|
|
555
|
+
reservation: state.reservation,
|
|
556
|
+
tag: state.rpc.tag,
|
|
557
|
+
});
|
|
558
|
+
} catch {
|
|
559
|
+
return callUnbound();
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
/** Fixed Node producer entry, still distinct from operational profile admission. */
|
|
564
|
+
export function consumeInitialClassReservation(
|
|
565
|
+
call: unknown,
|
|
566
|
+
journal: unknown,
|
|
567
|
+
) {
|
|
568
|
+
const consumed = consumeClassReservation(call, journal);
|
|
569
|
+
if (typeof call !== "object" || call === null) callUnbound();
|
|
570
|
+
const state = winningCalls.get(call);
|
|
571
|
+
if (!state) callUnbound();
|
|
572
|
+
return Object.freeze({ ...consumed, binding: state.binding });
|
|
573
|
+
}
|