@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.
Files changed (57) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +1 -1
  3. package/dist/client/billing/renewalAttach/internal/operationJournal.d.ts +47 -0
  4. package/dist/client/billing/renewalAttach/internal/operationJournal.d.ts.map +1 -0
  5. package/dist/client/billing/renewalAttach/internal/operationJournal.js +388 -0
  6. package/dist/client/billing/renewalAttach/internal/operationJournal.js.map +1 -0
  7. package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.d.ts +24 -5
  8. package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.d.ts.map +1 -1
  9. package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.js +182 -4
  10. package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.js.map +1 -1
  11. package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.d.ts +13 -0
  12. package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.d.ts.map +1 -0
  13. package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.js +43 -0
  14. package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.js.map +1 -0
  15. package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.d.ts +32 -0
  16. package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.d.ts.map +1 -0
  17. package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.js +105 -0
  18. package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.js.map +1 -0
  19. package/dist/client/billing/renewalAttach/internal/producer/ownedAwaitFactory.d.ts +3 -0
  20. package/dist/client/billing/renewalAttach/internal/producer/ownedAwaitFactory.d.ts.map +1 -0
  21. package/dist/client/billing/renewalAttach/internal/producer/ownedAwaitFactory.js +59 -0
  22. package/dist/client/billing/renewalAttach/internal/producer/ownedAwaitFactory.js.map +1 -0
  23. package/dist/client/billing/renewalAttach/internal/producer/ownerFactory.d.ts +11 -0
  24. package/dist/client/billing/renewalAttach/internal/producer/ownerFactory.d.ts.map +1 -0
  25. package/dist/client/billing/renewalAttach/internal/producer/ownerFactory.js +121 -0
  26. package/dist/client/billing/renewalAttach/internal/producer/ownerFactory.js.map +1 -0
  27. package/dist/client/billing/renewalAttach/internal/producer/stockDelegateFactory.d.ts +6 -0
  28. package/dist/client/billing/renewalAttach/internal/producer/stockDelegateFactory.d.ts.map +1 -0
  29. package/dist/client/billing/renewalAttach/internal/producer/stockDelegateFactory.js +16 -0
  30. package/dist/client/billing/renewalAttach/internal/producer/stockDelegateFactory.js.map +1 -0
  31. package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +32 -32
  32. package/dist/client/connect/payoutExecutionTestHelpers.d.ts +16 -16
  33. package/dist/component/balanceFunding/internal/actions.d.ts +11 -11
  34. package/dist/component/balanceFunding/mutations.d.ts +43 -43
  35. package/dist/component/balanceFunding/preparationHandlers.d.ts +8 -8
  36. package/dist/component/financialObservations/settlementHelpers.d.ts +3 -3
  37. package/dist/component/usageCredits/accounting.fixtures.d.ts +16 -16
  38. package/docs/renewal-context-reads.md +57 -5
  39. package/package.json +1 -1
  40. package/src/client/billing/renewalAttach/internal/operationJournal.acknowledgement.integration.test.ts +500 -0
  41. package/src/client/billing/renewalAttach/internal/operationJournal.c10.integration.test.ts +560 -0
  42. package/src/client/billing/renewalAttach/internal/operationJournal.controls.integration.test.ts +356 -0
  43. package/src/client/billing/renewalAttach/internal/operationJournal.integration.test.ts +181 -1
  44. package/src/client/billing/renewalAttach/internal/operationJournal.methods.integration.test.ts +534 -0
  45. package/src/client/billing/renewalAttach/internal/operationJournal.ts +573 -0
  46. package/src/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.ts +246 -8
  47. package/src/client/billing/renewalAttach/internal/producer/invocationProducer.ts +58 -0
  48. package/src/client/billing/renewalAttach/internal/producer/lineageAuthority.ts +161 -0
  49. package/src/client/billing/renewalAttach/internal/producer/ownedAwaitFactory.ts +54 -0
  50. package/src/client/billing/renewalAttach/internal/producer/ownerFactory.ts +124 -0
  51. package/src/client/billing/renewalAttach/internal/producer/producerGuards.integration.test.ts +323 -0
  52. package/src/client/billing/renewalAttach/internal/producer/producerInitial.integration.test.ts +301 -0
  53. package/src/client/billing/renewalAttach/internal/producer/producerIsolation.integration.test.ts +531 -0
  54. package/src/client/billing/renewalAttach/internal/producer/producerOwner.integration.test.ts +457 -0
  55. package/src/client/billing/renewalAttach/internal/producer/stockDelegateFactory.ts +23 -0
  56. package/src/client/billing/renewalAttach/internal/test-fixtures/producerInitialDeclarations.ts +5 -0
  57. package/src/client/billing/renewalAttach/internal/test-fixtures/producerInitialOperation.ts +80 -0
@@ -0,0 +1,356 @@
1
+ import assert from "node:assert/strict";
2
+ import { components } from "../../../../../example/convex/_generated/api.js";
3
+ import { createActionOperationJournal } from "./operationJournal.js";
4
+ import { convexTest } from "convex-test";
5
+ import {
6
+ actionGeneric,
7
+ mutationGeneric,
8
+ componentsGeneric,
9
+ defineSchema,
10
+ makeFunctionReference,
11
+ type FunctionReturnType,
12
+ } from "convex/server";
13
+ import { getConvexSize, getDocumentSize, v } from "convex/values";
14
+ import { afterEach, expect, it, vi } from "vitest";
15
+ import { modules, schema } from "../../../../test.js";
16
+ import { query } from "../../../../component/_generated/server.js";
17
+ import type { Doc } from "../../../../component/_generated/dataModel.js";
18
+ import {
19
+ canonical,
20
+ codecFixture,
21
+ VALUE_LIMIT,
22
+ } from "../../../../component/renewalOperations/timingPolicy.fixtures.js";
23
+
24
+ const refs = components.betterStripe.renewalOperations;
25
+ const nested = componentsGeneric();
26
+ type Loaded = FunctionReturnType<typeof refs.queries.loadAuthorizedOperation>;
27
+ type Reserved = FunctionReturnType<typeof refs.mutations.reserveAttempt>;
28
+ type Physical = {
29
+ operations: Doc<"renewalOperations">[];
30
+ attempts: Doc<"renewalOperationAttempts">[];
31
+ events: Doc<"renewalOperationEvents">[];
32
+ payloads: Doc<"renewalOperationPayloads">[];
33
+ };
34
+ const inspection = {
35
+ physical: query({
36
+ args: {},
37
+ handler: async (ctx): Promise<Physical> => ({
38
+ operations: await ctx.db.query("renewalOperations").take(4),
39
+ attempts: await ctx.db.query("renewalOperationAttempts").take(4),
40
+ events: await ctx.db.query("renewalOperationEvents").take(4),
41
+ payloads: await ctx.db.query("renewalOperationPayloads").take(6),
42
+ }),
43
+ }),
44
+ };
45
+ const mutationTarget = makeFunctionReference<
46
+ "mutation",
47
+ { operationId: string },
48
+ null
49
+ >("adapterControls:mutationContext");
50
+ const concurrentTarget = makeFunctionReference<
51
+ "action",
52
+ { operationId: string },
53
+ { before: Loaded; acquired: Reserved; after: Loaded }
54
+ >("adapterControls:concurrent");
55
+
56
+ afterEach(() => vi.unstubAllGlobals());
57
+
58
+ it("ADAPTER-CONTEXT refuses a genuine registered Mutation context", async () => {
59
+ const h = await codecFixture();
60
+ const progress = { entered: 0, direct: 0, refused: 0 };
61
+ const host = {
62
+ mutationContext: mutationGeneric({
63
+ args: { operationId: v.string() },
64
+ handler: async (ctx, args): Promise<null> => {
65
+ progress.entered++;
66
+ expect(await ctx.meta.getFunctionMetadata()).toEqual({
67
+ name: "adapterControls:mutationContext",
68
+ componentPath: "",
69
+ type: "mutation",
70
+ visibility: "public",
71
+ });
72
+ expect(
73
+ await ctx.runQuery(refs.queries.loadAuthorizedOperation, args),
74
+ ).toEqual({
75
+ recordVersion: 2,
76
+ ...args,
77
+ recordJSON: h.recordJSON,
78
+ revision: 0,
79
+ activeAttempt: null,
80
+ initialBasis: null,
81
+ });
82
+ progress.direct++;
83
+ // Deliberate runtime bad-context call using the actual registered ctx.
84
+ // No context/metadata/reference cast or replacement is introduced.
85
+ await expect(
86
+ Reflect.apply(createActionOperationJournal, undefined, [
87
+ ctx,
88
+ components.betterStripe,
89
+ args.operationId,
90
+ ]),
91
+ ).rejects.toThrow(/^OPERATION_JOURNAL_ACTION_UNBOUND$/);
92
+ progress.refused++;
93
+ return null;
94
+ },
95
+ }),
96
+ };
97
+ const t = convexTest(defineSchema({}), {
98
+ "./_generated/api.ts": async () => ({}),
99
+ "./adapterControls.ts": async () => host,
100
+ });
101
+ t.registerComponent("betterStripe", schema, {
102
+ ...modules,
103
+ "./component/adapterControlsInspection.ts": async () => inspection,
104
+ });
105
+ const physical = async (): Promise<Physical> =>
106
+ t.query(nested.betterStripe.adapterControlsInspection.physical, {});
107
+ expect(await physical()).toEqual({
108
+ operations: [],
109
+ attempts: [],
110
+ events: [],
111
+ payloads: [],
112
+ });
113
+ const created = await t.mutation(refs.mutations.createAuthorizedOperation, {
114
+ authorizationScope: h.record.authorization.scope,
115
+ authorizationRevision: h.record.authorization.revision,
116
+ logicalOperationId: h.record.logicalOperationId,
117
+ recordJSON: h.recordJSON,
118
+ });
119
+ assert(created.status === "created");
120
+ const before = await physical();
121
+ expect(before.operations).toHaveLength(1);
122
+ expect(before.attempts).toEqual([]);
123
+ expect(before.events).toEqual([]);
124
+ expect(before.payloads).toHaveLength(1);
125
+ expect(before.operations[0]).toMatchObject({
126
+ _id: created.operationId,
127
+ recordVersion: 2,
128
+ state: "PREPARED",
129
+ revision: 0,
130
+ payloadId: before.payloads[0]._id,
131
+ });
132
+ expect(before.payloads[0]).toMatchObject({
133
+ codecVersion: 1,
134
+ json: h.recordJSON,
135
+ owner: { kind: "operation", operationId: created.operationId },
136
+ });
137
+ for (const rows of Object.values(before))
138
+ for (const row of rows)
139
+ expect(getDocumentSize(row)).toBeLessThanOrEqual(VALUE_LIMIT);
140
+ let failed = false;
141
+ try {
142
+ expect(
143
+ await t.mutation(mutationTarget, { operationId: created.operationId }),
144
+ ).toBeNull();
145
+ expect(progress).toEqual({ entered: 1, direct: 1, refused: 1 });
146
+ } catch (error) {
147
+ failed = true;
148
+ throw error;
149
+ } finally {
150
+ try {
151
+ expect(await physical()).toEqual(before);
152
+ expect(h.fetchCalls()).toBe(0);
153
+ console.info(
154
+ "ADAPTER_CONTEXT_SETTLEMENT",
155
+ JSON.stringify({ ...progress, physicalEqual: true, fetchCalls: 0 }),
156
+ );
157
+ } catch (error) {
158
+ if (!failed) throw error;
159
+ console.info("ADAPTER_CONTEXT_INSPECTION_FAILED");
160
+ }
161
+ }
162
+ });
163
+
164
+ it("ADAPTER-CONCURRENT keeps two genuine Action facades operation-bound", async () => {
165
+ const h = await codecFixture();
166
+ const records = [
167
+ h.recordJSON,
168
+ canonical({
169
+ ...h.record,
170
+ logicalOperationId: h.record.logicalOperationId + "-concurrent",
171
+ }),
172
+ ];
173
+ const logicalOperationIds = [
174
+ h.record.logicalOperationId,
175
+ h.record.logicalOperationId + "-concurrent",
176
+ ];
177
+ const expectedRecords = new Map<string, string>();
178
+ let captured = 0;
179
+ let releaseBoth = () => {};
180
+ const bothCaptured = new Promise<void>((resolve) => {
181
+ releaseBoth = resolve;
182
+ });
183
+ let deadline: ReturnType<typeof setTimeout> | undefined;
184
+ const host = {
185
+ concurrent: actionGeneric({
186
+ args: { operationId: v.string() },
187
+ handler: async (
188
+ ctx,
189
+ args,
190
+ ): Promise<FunctionReturnType<typeof concurrentTarget>> => {
191
+ expect(await ctx.meta.getFunctionMetadata()).toEqual({
192
+ name: "adapterControls:concurrent",
193
+ componentPath: "",
194
+ type: "action",
195
+ visibility: "public",
196
+ });
197
+ const recordJSON = expectedRecords.get(args.operationId);
198
+ assert(recordJSON);
199
+ const journal = await createActionOperationJournal(
200
+ ctx,
201
+ components.betterStripe,
202
+ args.operationId,
203
+ );
204
+ captured++;
205
+ if (captured === 2) releaseBoth();
206
+ await Promise.race([bothCaptured, barrierTimeout]);
207
+ const before = await journal.loadAuthorizedOperation();
208
+ expect(before).toEqual({
209
+ recordVersion: 2,
210
+ ...args,
211
+ recordJSON,
212
+ revision: 0,
213
+ activeAttempt: null,
214
+ initialBasis: null,
215
+ });
216
+ const acquired = await journal.reserveAttempt({
217
+ expectedRevision: 0,
218
+ stage: "attach",
219
+ expectedRequestBinding: h.record.requestBinding,
220
+ recordJSON,
221
+ });
222
+ assert(acquired.disposition === "acquired");
223
+ expect(acquired.reservation.operationId).toBe(args.operationId);
224
+ expect(acquired.reservation.recordJSON).toBe(recordJSON);
225
+ const { recordJSON: _recordJSON, ...summary } = acquired.reservation;
226
+ const after = await journal.loadAuthorizedOperation();
227
+ expect(after).toEqual({
228
+ recordVersion: 2,
229
+ ...args,
230
+ recordJSON,
231
+ revision: 1,
232
+ activeAttempt: summary,
233
+ initialBasis: null,
234
+ });
235
+ expect(getConvexSize({ before, acquired, after })).toBeLessThanOrEqual(
236
+ VALUE_LIMIT,
237
+ );
238
+ return { before, acquired, after };
239
+ },
240
+ }),
241
+ };
242
+ const t = convexTest(defineSchema({}), {
243
+ "./_generated/api.ts": async () => ({}),
244
+ "./adapterControls.ts": async () => host,
245
+ });
246
+ t.registerComponent("betterStripe", schema, {
247
+ ...modules,
248
+ "./component/adapterControlsInspection.ts": async () => inspection,
249
+ });
250
+ const physical = async (): Promise<Physical> =>
251
+ t.query(nested.betterStripe.adapterControlsInspection.physical, {});
252
+ expect(await physical()).toEqual({
253
+ operations: [],
254
+ attempts: [],
255
+ events: [],
256
+ payloads: [],
257
+ });
258
+ const operationIds: string[] = [];
259
+ for (const [index, recordJSON] of records.entries()) {
260
+ const created = await t.mutation(refs.mutations.createAuthorizedOperation, {
261
+ authorizationScope: h.record.authorization.scope,
262
+ authorizationRevision: h.record.authorization.revision,
263
+ logicalOperationId: logicalOperationIds[index],
264
+ recordJSON,
265
+ });
266
+ assert(created.status === "created");
267
+ operationIds.push(created.operationId);
268
+ expectedRecords.set(created.operationId, recordJSON);
269
+ }
270
+ expect(new Set(operationIds).size).toBe(2);
271
+ const before = await physical();
272
+ expect(before.operations).toHaveLength(2);
273
+ expect(before.attempts).toEqual([]);
274
+ expect(before.events).toEqual([]);
275
+ expect(before.payloads).toHaveLength(2);
276
+ let stable = before;
277
+ let failed = false;
278
+ const barrierTimeout = new Promise<never>((_, reject) => {
279
+ deadline = setTimeout(
280
+ () => reject(Error("ADAPTER_CONCURRENT_CAPTURE_PREREQUISITE_STOP")),
281
+ 1000,
282
+ );
283
+ });
284
+ try {
285
+ const settled = await Promise.allSettled(
286
+ operationIds.map((operationId) =>
287
+ t.action(concurrentTarget, { operationId }),
288
+ ),
289
+ );
290
+ const results = settled.map((result) => {
291
+ if (result.status === "rejected") throw result.reason;
292
+ return result.value;
293
+ });
294
+ expect(settled.map((result) => result.status)).toEqual([
295
+ "fulfilled",
296
+ "fulfilled",
297
+ ]);
298
+ expect(captured).toBe(2);
299
+ const attempts = new Set<string>();
300
+ for (let index = 0; index < results.length; index++) {
301
+ const result = results[index];
302
+ assert(result.acquired.disposition === "acquired");
303
+ expect(result.before?.operationId).toBe(operationIds[index]);
304
+ expect(result.before?.recordJSON).toBe(records[index]);
305
+ expect(result.after?.operationId).toBe(operationIds[index]);
306
+ expect(result.after?.recordJSON).toBe(records[index]);
307
+ attempts.add(result.acquired.reservation.attemptId);
308
+ }
309
+ expect(attempts.size).toBe(2);
310
+ const after = await physical();
311
+ expect(after.operations).toHaveLength(2);
312
+ expect(after.attempts).toHaveLength(2);
313
+ expect(after.events).toEqual([]);
314
+ expect(after.payloads).toEqual(before.payloads);
315
+ for (const original of before.operations) {
316
+ const result = results.find(
317
+ (value) => value.after?.operationId === original._id,
318
+ );
319
+ assert(result && result.acquired.disposition === "acquired");
320
+ const reservation = result.acquired.reservation;
321
+ expect(after.operations.find((row) => row._id === original._id)).toEqual({
322
+ ...original,
323
+ revision: 1,
324
+ state: "RESERVED",
325
+ activeAttemptId: reservation.attemptId,
326
+ });
327
+ expect(
328
+ after.attempts.find((row) => row._id === reservation.attemptId),
329
+ ).toMatchObject({
330
+ operationId: original._id,
331
+ payloadId: reservation.payloadId,
332
+ lastSequence: 0,
333
+ });
334
+ }
335
+ for (const rows of Object.values(after))
336
+ for (const row of rows)
337
+ expect(getDocumentSize(row)).toBeLessThanOrEqual(VALUE_LIMIT);
338
+ stable = after;
339
+ } catch (error) {
340
+ failed = true;
341
+ throw error;
342
+ } finally {
343
+ if (deadline !== undefined) clearTimeout(deadline);
344
+ try {
345
+ expect(await physical()).toEqual(stable);
346
+ expect(h.fetchCalls()).toBe(0);
347
+ console.info(
348
+ "ADAPTER_CONCURRENT_SETTLEMENT",
349
+ JSON.stringify({ captured, physicalEqual: true, fetchCalls: 0 }),
350
+ );
351
+ } catch (error) {
352
+ if (!failed) throw error;
353
+ console.info("ADAPTER_CONCURRENT_INSPECTION_FAILED");
354
+ }
355
+ }
356
+ });
@@ -1,3 +1,5 @@
1
+ import { components as generatedComponents } from "../../../../../example/convex/_generated/api.js";
2
+ import { createActionOperationJournal } from "./operationJournal.js";
1
3
  import { convexTest } from "convex-test";
2
4
  import {
3
5
  actionGeneric,
@@ -5,8 +7,14 @@ import {
5
7
  componentsGeneric,
6
8
  defineSchema,
7
9
  makeFunctionReference,
10
+ type FunctionReturnType,
8
11
  } from "convex/server";
9
- import { getConvexSize, getDocumentSize, type ObjectType } from "convex/values";
12
+ import {
13
+ getConvexSize,
14
+ getDocumentSize,
15
+ v,
16
+ type ObjectType,
17
+ } from "convex/values";
10
18
  import { afterEach, expect, it, vi } from "vitest";
11
19
  import { modules, schema } from "../../../../test.js";
12
20
  import { query as componentQuery } from "../../../../component/_generated/server.js";
@@ -378,3 +386,175 @@ it.each(cases)(
378
386
  }
379
387
  },
380
388
  );
389
+
390
+ type GeneratedLoad = FunctionReturnType<
391
+ typeof generatedComponents.betterStripe.renewalOperations.queries.loadAuthorizedOperation
392
+ >;
393
+ const adapterRead = makeFunctionReference<
394
+ "action",
395
+ { operationId: string },
396
+ { direct: GeneratedLoad; adapter: GeneratedLoad }
397
+ >("adapterHost:readExisting");
398
+
399
+ it("ADAPTER01 loads the actual existing operation through the private Action adapter", async () => {
400
+ const h = await codecFixture();
401
+ const progress = { entries: 0, directLoads: 0, captures: 0, adapterCalls: 0 };
402
+ const inspection = {
403
+ physical: componentQuery({
404
+ args: {},
405
+ handler: async (ctx): Promise<Physical> => ({
406
+ operations: await ctx.db.query("renewalOperations").take(3),
407
+ attempts: await ctx.db.query("renewalOperationAttempts").take(3),
408
+ events: await ctx.db.query("renewalOperationEvents").take(4),
409
+ payloads: await ctx.db.query("renewalOperationPayloads").take(6),
410
+ }),
411
+ }),
412
+ };
413
+ const host = {
414
+ readExisting: actionGeneric({
415
+ args: { operationId: v.string() },
416
+ handler: async (ctx, args) => {
417
+ progress.entries++;
418
+ expect(await ctx.meta.getFunctionMetadata()).toEqual({
419
+ name: "adapterHost:readExisting",
420
+ componentPath: "",
421
+ type: "action",
422
+ visibility: "public",
423
+ });
424
+ const direct = await ctx.runQuery(
425
+ generatedComponents.betterStripe.renewalOperations.queries
426
+ .loadAuthorizedOperation,
427
+ args,
428
+ );
429
+ expect(direct).toEqual({
430
+ recordVersion: 2,
431
+ operationId: args.operationId,
432
+ recordJSON: h.recordJSON,
433
+ revision: 0,
434
+ activeAttempt: null,
435
+ initialBasis: null,
436
+ });
437
+ expect(getConvexSize(direct)).toBeLessThanOrEqual(VALUE_LIMIT);
438
+ progress.directLoads++;
439
+ // Actual read-only component query, not a caller-provided physical DTO.
440
+ expect(
441
+ await ctx.runQuery(
442
+ nested.betterStripe.adapterInspection.physical,
443
+ {},
444
+ ),
445
+ ).toEqual(before);
446
+ const journal = await createActionOperationJournal(
447
+ ctx,
448
+ generatedComponents.betterStripe,
449
+ args.operationId,
450
+ );
451
+ progress.captures++;
452
+ const adapter = await journal.loadAuthorizedOperation();
453
+ progress.adapterCalls++;
454
+ return { direct, adapter };
455
+ },
456
+ }),
457
+ };
458
+ const t = convexTest(defineSchema({}), {
459
+ "./_generated/api.ts": async () => ({}),
460
+ "./adapterHost.ts": async () => host,
461
+ });
462
+ expect(
463
+ Object.prototype.hasOwnProperty.call(
464
+ modules,
465
+ "./component/adapterInspection.ts",
466
+ ),
467
+ ).toBe(false);
468
+ t.registerComponent("betterStripe", schema, {
469
+ ...modules,
470
+ "./component/adapterInspection.ts": async () => inspection,
471
+ });
472
+ const physical = async (): Promise<Physical> =>
473
+ t.query(nested.betterStripe.adapterInspection.physical, {});
474
+ expect(await physical()).toEqual({
475
+ operations: [],
476
+ attempts: [],
477
+ events: [],
478
+ payloads: [],
479
+ });
480
+ const createArgs = {
481
+ authorizationScope: h.record.authorization.scope,
482
+ logicalOperationId: h.record.logicalOperationId,
483
+ authorizationRevision: h.record.authorization.revision,
484
+ recordJSON: h.recordJSON,
485
+ };
486
+ expect(getConvexSize(createArgs)).toBeLessThanOrEqual(VALUE_LIMIT);
487
+ const created = await t.mutation(
488
+ generatedComponents.betterStripe.renewalOperations.mutations
489
+ .createAuthorizedOperation,
490
+ createArgs,
491
+ );
492
+ if (created.status !== "created")
493
+ throw Error("ADAPTER_CREATE_PREREQUISITE_STOP");
494
+ const before = await physical();
495
+ expect({
496
+ operations: before.operations.length,
497
+ attempts: before.attempts.length,
498
+ events: before.events.length,
499
+ payloads: before.payloads.length,
500
+ }).toEqual({ operations: 1, attempts: 0, events: 0, payloads: 1 });
501
+ const operation = before.operations[0];
502
+ const payload = before.payloads[0];
503
+ expect(operation).toMatchObject({
504
+ _id: created.operationId,
505
+ recordVersion: 2,
506
+ payloadId: payload._id,
507
+ revision: 0,
508
+ state: "PREPARED",
509
+ });
510
+ expect(payload).toMatchObject({
511
+ codecVersion: 1,
512
+ json: h.recordJSON,
513
+ owner: { kind: "operation", operationId: created.operationId },
514
+ });
515
+ for (const rows of Object.values(before))
516
+ for (const row of rows)
517
+ expect(getDocumentSize(row)).toBeLessThanOrEqual(VALUE_LIMIT);
518
+ const args = { operationId: created.operationId };
519
+ expect(getConvexSize(args)).toBeLessThanOrEqual(VALUE_LIMIT);
520
+ let targetFailed = false;
521
+ try {
522
+ const result = await t.action(adapterRead, args);
523
+ expect(progress).toEqual({
524
+ entries: 1,
525
+ directLoads: 1,
526
+ captures: 1,
527
+ adapterCalls: 1,
528
+ });
529
+ expect(result.direct).toEqual({
530
+ recordVersion: 2,
531
+ ...args,
532
+ recordJSON: h.recordJSON,
533
+ revision: 0,
534
+ activeAttempt: null,
535
+ initialBasis: null,
536
+ });
537
+ expect(getConvexSize(result)).toBeLessThanOrEqual(VALUE_LIMIT);
538
+ // Intended adapter-specific null-vs-complete-operation RED, after all prerequisites.
539
+ expect(result.adapter).toEqual(result.direct);
540
+ } catch (error) {
541
+ targetFailed = true;
542
+ throw error;
543
+ } finally {
544
+ try {
545
+ expect(await physical()).toEqual(before);
546
+ expect(h.fetchCalls()).toBe(0);
547
+ console.info(
548
+ "ADAPTER01_SETTLEMENT",
549
+ JSON.stringify({
550
+ ...progress,
551
+ physicalEqual: true,
552
+ fetchCalls: h.fetchCalls(),
553
+ }),
554
+ );
555
+ } catch (inspectionError) {
556
+ if (!targetFailed) throw inspectionError;
557
+ console.info("ADAPTER01_INSPECTION_FAILED");
558
+ }
559
+ }
560
+ });