@fantastic.dev/better-stripe 0.92.0 → 0.94.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 +41 -0
- package/dist/client/billing/renewalAttach/internal/operationJournal.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operationJournal.js +378 -0
- package/dist/client/billing/renewalAttach/internal/operationJournal.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.d.ts +44 -0
- package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.js +251 -0
- package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.js.map +1 -0
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +562 -0
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts +281 -0
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts +562 -0
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutSyncTestHelpers.d.ts +281 -0
- package/dist/client/connect/payoutSyncTestHelpers.d.ts.map +1 -1
- package/dist/client/index.d.ts +3 -2
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +16 -3
- package/dist/client/index.js.map +1 -1
- package/dist/component/_generated/api.d.ts +6 -0
- package/dist/component/_generated/api.d.ts.map +1 -1
- package/dist/component/_generated/api.js.map +1 -1
- package/dist/component/_generated/component.d.ts +406 -0
- package/dist/component/_generated/component.d.ts.map +1 -1
- package/dist/component/balanceFunding/mutations.d.ts +27 -27
- package/dist/component/balanceFunding/queries.d.ts +1 -1
- package/dist/component/balanceFunding/workflowValidators.d.ts +16 -16
- package/dist/component/earnings/triggers.d.ts +294 -0
- package/dist/component/earnings/triggers.d.ts.map +1 -1
- package/dist/component/financialObservations/settlementHelpers.d.ts +3 -3
- package/dist/component/renewalOperations/helpers.d.ts +236 -0
- package/dist/component/renewalOperations/helpers.d.ts.map +1 -0
- package/dist/component/renewalOperations/helpers.js +457 -0
- package/dist/component/renewalOperations/helpers.js.map +1 -0
- package/dist/component/renewalOperations/mutations.d.ts +252 -0
- package/dist/component/renewalOperations/mutations.d.ts.map +1 -0
- package/dist/component/renewalOperations/mutations.js +340 -0
- package/dist/component/renewalOperations/mutations.js.map +1 -0
- package/dist/component/renewalOperations/queries.d.ts +163 -0
- package/dist/component/renewalOperations/queries.d.ts.map +1 -0
- package/dist/component/renewalOperations/queries.js +167 -0
- package/dist/component/renewalOperations/queries.js.map +1 -0
- package/dist/component/renewalOperations/schema.d.ts +1988 -0
- package/dist/component/renewalOperations/schema.d.ts.map +1 -0
- package/dist/component/renewalOperations/schema.js +227 -0
- package/dist/component/renewalOperations/schema.js.map +1 -0
- package/dist/component/schema.d.ts +281 -0
- package/dist/component/schema.js +5 -0
- package/dist/component/schema.js.map +1 -1
- package/dist/component/usage/allowance.fixtures.d.ts +281 -0
- package/dist/component/usage/allowance.fixtures.d.ts.map +1 -1
- package/dist/component/usageCredits/accounting.fixtures.d.ts +297 -16
- package/dist/component/usageCredits/accounting.fixtures.d.ts.map +1 -1
- package/dist/shared/renewalOperationJournal.d.ts +43 -0
- package/dist/shared/renewalOperationJournal.d.ts.map +1 -0
- package/dist/shared/renewalOperationJournal.js +294 -0
- package/dist/shared/renewalOperationJournal.js.map +1 -0
- package/docs/renewal-context-reads.md +180 -0
- 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 +560 -0
- package/src/client/billing/renewalAttach/internal/operationJournal.methods.integration.test.ts +534 -0
- package/src/client/billing/renewalAttach/internal/operationJournal.ts +561 -0
- package/src/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.ts +334 -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/index.ts +24 -3
- package/src/component/_generated/api.ts +6 -0
- package/src/component/_generated/component.ts +450 -0
- package/src/component/renewalOperations/acknowledgement.fixtures.ts +552 -0
- package/src/component/renewalOperations/acknowledgement.test.ts +573 -0
- package/src/component/renewalOperations/acknowledgementReads.test.ts +442 -0
- package/src/component/renewalOperations/acknowledgementV2.test.ts +493 -0
- package/src/component/renewalOperations/acknowledgementV2Publication.test.ts +373 -0
- package/src/component/renewalOperations/basisBinding.test.ts +567 -0
- package/src/component/renewalOperations/basisLifecycle.test.ts +569 -0
- package/src/component/renewalOperations/boundHistory.test.ts +474 -0
- package/src/component/renewalOperations/helpers.ts +592 -0
- package/src/component/renewalOperations/historyReads.test.ts +595 -0
- package/src/component/renewalOperations/initialBasis.test.ts +578 -0
- package/src/component/renewalOperations/journal.test.ts +567 -0
- package/src/component/renewalOperations/mutations.ts +456 -0
- package/src/component/renewalOperations/payload.test.ts +589 -0
- package/src/component/renewalOperations/payloadEncoding.test.ts +592 -0
- package/src/component/renewalOperations/queries.ts +204 -0
- package/src/component/renewalOperations/schema.ts +268 -0
- package/src/component/renewalOperations/timingPolicy.fixtures.ts +193 -0
- package/src/component/renewalOperations/timingPolicy.test.ts +523 -0
- package/src/component/schema.ts +11 -0
- package/src/shared/renewalOperationJournal.ts +333 -0
|
@@ -0,0 +1,560 @@
|
|
|
1
|
+
import { components as generatedComponents } from "../../../../../example/convex/_generated/api.js";
|
|
2
|
+
import { createActionOperationJournal } from "./operationJournal.js";
|
|
3
|
+
import { convexTest } from "convex-test";
|
|
4
|
+
import {
|
|
5
|
+
actionGeneric,
|
|
6
|
+
mutationGeneric,
|
|
7
|
+
componentsGeneric,
|
|
8
|
+
defineSchema,
|
|
9
|
+
makeFunctionReference,
|
|
10
|
+
type FunctionReturnType,
|
|
11
|
+
} from "convex/server";
|
|
12
|
+
import {
|
|
13
|
+
getConvexSize,
|
|
14
|
+
getDocumentSize,
|
|
15
|
+
v,
|
|
16
|
+
type ObjectType,
|
|
17
|
+
} from "convex/values";
|
|
18
|
+
import { afterEach, expect, it, vi } from "vitest";
|
|
19
|
+
import { modules, schema } from "../../../../test.js";
|
|
20
|
+
import { query as componentQuery } from "../../../../component/_generated/server.js";
|
|
21
|
+
import type { Doc } from "../../../../component/_generated/dataModel.js";
|
|
22
|
+
import {
|
|
23
|
+
creationArgs,
|
|
24
|
+
reserveArgs,
|
|
25
|
+
} from "../../../../component/renewalOperations/schema.js";
|
|
26
|
+
import {
|
|
27
|
+
canonical,
|
|
28
|
+
codecFixture,
|
|
29
|
+
VALUE_LIMIT,
|
|
30
|
+
} from "../../../../component/renewalOperations/timingPolicy.fixtures.js";
|
|
31
|
+
|
|
32
|
+
// TEST-only mounted references; never a production ComponentApi substitute.
|
|
33
|
+
const nested = componentsGeneric();
|
|
34
|
+
const createAction = makeFunctionReference<
|
|
35
|
+
"action",
|
|
36
|
+
ObjectType<typeof creationArgs>,
|
|
37
|
+
null
|
|
38
|
+
>("host:createAction");
|
|
39
|
+
const createMutation = makeFunctionReference<
|
|
40
|
+
"mutation",
|
|
41
|
+
ObjectType<typeof creationArgs>,
|
|
42
|
+
null
|
|
43
|
+
>("host:createMutation");
|
|
44
|
+
const reserveAction = makeFunctionReference<
|
|
45
|
+
"action",
|
|
46
|
+
ObjectType<typeof reserveArgs>,
|
|
47
|
+
null
|
|
48
|
+
>("host:reserveAction");
|
|
49
|
+
const reserveMutation = makeFunctionReference<
|
|
50
|
+
"mutation",
|
|
51
|
+
ObjectType<typeof reserveArgs>,
|
|
52
|
+
null
|
|
53
|
+
>("host:reserveMutation");
|
|
54
|
+
const cases = [
|
|
55
|
+
{ phase: "create", parent: "action", route: "host:createAction" },
|
|
56
|
+
{ phase: "create", parent: "mutation", route: "host:createMutation" },
|
|
57
|
+
{ phase: "reserve", parent: "action", route: "host:reserveAction" },
|
|
58
|
+
{ phase: "reserve", parent: "mutation", route: "host:reserveMutation" },
|
|
59
|
+
] as const;
|
|
60
|
+
type Physical = {
|
|
61
|
+
operations: Doc<"renewalOperations">[];
|
|
62
|
+
attempts: Doc<"renewalOperationAttempts">[];
|
|
63
|
+
events: Doc<"renewalOperationEvents">[];
|
|
64
|
+
payloads: Doc<"renewalOperationPayloads">[];
|
|
65
|
+
};
|
|
66
|
+
type Trace = { route: string; metadata: unknown; reply: unknown };
|
|
67
|
+
const parentStop = "JOURNAL_MECHANICAL_PARENT_STOP";
|
|
68
|
+
afterEach(() => vi.unstubAllGlobals());
|
|
69
|
+
|
|
70
|
+
it.each(cases)(
|
|
71
|
+
"ACTION-MECHANICAL $phase under $parent has the declared transaction boundary",
|
|
72
|
+
async (scenario) => {
|
|
73
|
+
const h = await codecFixture();
|
|
74
|
+
const trace: Trace[] = [];
|
|
75
|
+
const host = {
|
|
76
|
+
createAction: actionGeneric({
|
|
77
|
+
args: creationArgs,
|
|
78
|
+
handler: async (ctx, args) => {
|
|
79
|
+
const metadata = await ctx.meta.getFunctionMetadata();
|
|
80
|
+
expect(metadata).toEqual({
|
|
81
|
+
name: "host:createAction",
|
|
82
|
+
componentPath: "",
|
|
83
|
+
type: "action",
|
|
84
|
+
visibility: "public",
|
|
85
|
+
});
|
|
86
|
+
const reply: unknown = await ctx.runMutation(
|
|
87
|
+
nested.betterStripe.renewalOperations.mutations
|
|
88
|
+
.createAuthorizedOperation,
|
|
89
|
+
args,
|
|
90
|
+
);
|
|
91
|
+
expect(reply).toMatchObject({ status: "created" });
|
|
92
|
+
trace.push({ route: "host:createAction", metadata, reply });
|
|
93
|
+
throw Error(parentStop);
|
|
94
|
+
},
|
|
95
|
+
}),
|
|
96
|
+
createMutation: mutationGeneric({
|
|
97
|
+
args: creationArgs,
|
|
98
|
+
handler: async (ctx, args) => {
|
|
99
|
+
const metadata = await ctx.meta.getFunctionMetadata();
|
|
100
|
+
expect(metadata).toEqual({
|
|
101
|
+
name: "host:createMutation",
|
|
102
|
+
componentPath: "",
|
|
103
|
+
type: "mutation",
|
|
104
|
+
visibility: "public",
|
|
105
|
+
});
|
|
106
|
+
const reply: unknown = await ctx.runMutation(
|
|
107
|
+
nested.betterStripe.renewalOperations.mutations
|
|
108
|
+
.createAuthorizedOperation,
|
|
109
|
+
args,
|
|
110
|
+
);
|
|
111
|
+
expect(reply).toMatchObject({ status: "created" });
|
|
112
|
+
trace.push({ route: "host:createMutation", metadata, reply });
|
|
113
|
+
throw Error(parentStop);
|
|
114
|
+
},
|
|
115
|
+
}),
|
|
116
|
+
reserveAction: actionGeneric({
|
|
117
|
+
args: reserveArgs,
|
|
118
|
+
handler: async (ctx, args) => {
|
|
119
|
+
const metadata = await ctx.meta.getFunctionMetadata();
|
|
120
|
+
expect(metadata).toEqual({
|
|
121
|
+
name: "host:reserveAction",
|
|
122
|
+
componentPath: "",
|
|
123
|
+
type: "action",
|
|
124
|
+
visibility: "public",
|
|
125
|
+
});
|
|
126
|
+
const reply: unknown = await ctx.runMutation(
|
|
127
|
+
nested.betterStripe.renewalOperations.mutations.reserveAttempt,
|
|
128
|
+
args,
|
|
129
|
+
);
|
|
130
|
+
expect(reply).toMatchObject({
|
|
131
|
+
disposition: "acquired",
|
|
132
|
+
previousRevision: 0,
|
|
133
|
+
committedRevision: 1,
|
|
134
|
+
});
|
|
135
|
+
trace.push({ route: "host:reserveAction", metadata, reply });
|
|
136
|
+
throw Error(parentStop);
|
|
137
|
+
},
|
|
138
|
+
}),
|
|
139
|
+
reserveMutation: mutationGeneric({
|
|
140
|
+
args: reserveArgs,
|
|
141
|
+
handler: async (ctx, args) => {
|
|
142
|
+
const metadata = await ctx.meta.getFunctionMetadata();
|
|
143
|
+
expect(metadata).toEqual({
|
|
144
|
+
name: "host:reserveMutation",
|
|
145
|
+
componentPath: "",
|
|
146
|
+
type: "mutation",
|
|
147
|
+
visibility: "public",
|
|
148
|
+
});
|
|
149
|
+
const reply: unknown = await ctx.runMutation(
|
|
150
|
+
nested.betterStripe.renewalOperations.mutations.reserveAttempt,
|
|
151
|
+
args,
|
|
152
|
+
);
|
|
153
|
+
expect(reply).toMatchObject({
|
|
154
|
+
disposition: "acquired",
|
|
155
|
+
previousRevision: 0,
|
|
156
|
+
committedRevision: 1,
|
|
157
|
+
});
|
|
158
|
+
trace.push({ route: "host:reserveMutation", metadata, reply });
|
|
159
|
+
throw Error(parentStop);
|
|
160
|
+
},
|
|
161
|
+
}),
|
|
162
|
+
};
|
|
163
|
+
const inspection = {
|
|
164
|
+
physical: componentQuery({
|
|
165
|
+
args: {},
|
|
166
|
+
handler: async (ctx): Promise<Physical> => ({
|
|
167
|
+
operations: await ctx.db.query("renewalOperations").take(3),
|
|
168
|
+
attempts: await ctx.db.query("renewalOperationAttempts").take(3),
|
|
169
|
+
events: await ctx.db.query("renewalOperationEvents").take(4),
|
|
170
|
+
payloads: await ctx.db.query("renewalOperationPayloads").take(6),
|
|
171
|
+
}),
|
|
172
|
+
}),
|
|
173
|
+
};
|
|
174
|
+
// The empty host API module is only convex-test's module-root sentinel.
|
|
175
|
+
// No generated file or journal function reference is fabricated by it.
|
|
176
|
+
const t = convexTest(defineSchema({}), {
|
|
177
|
+
"./_generated/api.ts": async () => ({}),
|
|
178
|
+
"./host.ts": async () => host,
|
|
179
|
+
});
|
|
180
|
+
expect(
|
|
181
|
+
Object.prototype.hasOwnProperty.call(
|
|
182
|
+
modules,
|
|
183
|
+
"./component/journalMechanical.ts",
|
|
184
|
+
),
|
|
185
|
+
).toBe(false);
|
|
186
|
+
t.registerComponent("betterStripe", schema, {
|
|
187
|
+
...modules,
|
|
188
|
+
"./component/journalMechanical.ts": async () => inspection,
|
|
189
|
+
});
|
|
190
|
+
const physical = async (): Promise<Physical> =>
|
|
191
|
+
t.query(nested.betterStripe.journalMechanical.physical, {});
|
|
192
|
+
expect(await physical()).toEqual({
|
|
193
|
+
operations: [],
|
|
194
|
+
attempts: [],
|
|
195
|
+
events: [],
|
|
196
|
+
payloads: [],
|
|
197
|
+
});
|
|
198
|
+
const createArgs: ObjectType<typeof creationArgs> = {
|
|
199
|
+
authorizationScope: h.record.authorization.scope,
|
|
200
|
+
logicalOperationId: h.record.logicalOperationId,
|
|
201
|
+
authorizationRevision: h.record.authorization.revision,
|
|
202
|
+
recordJSON: h.recordJSON,
|
|
203
|
+
};
|
|
204
|
+
expect(getConvexSize(createArgs)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
205
|
+
if (scenario.phase === "reserve") {
|
|
206
|
+
const created: unknown = await t.mutation(
|
|
207
|
+
nested.betterStripe.renewalOperations.mutations
|
|
208
|
+
.createAuthorizedOperation,
|
|
209
|
+
createArgs,
|
|
210
|
+
);
|
|
211
|
+
const prepared = await physical();
|
|
212
|
+
expect(prepared.operations).toHaveLength(1);
|
|
213
|
+
expect(prepared.payloads).toHaveLength(1);
|
|
214
|
+
expect(prepared.attempts).toHaveLength(0);
|
|
215
|
+
expect(prepared.events).toHaveLength(0);
|
|
216
|
+
const operationId = prepared.operations[0]._id;
|
|
217
|
+
expect(created).toEqual({ status: "created", operationId });
|
|
218
|
+
expect(
|
|
219
|
+
await t.query(
|
|
220
|
+
nested.betterStripe.renewalOperations.queries.loadAuthorizedOperation,
|
|
221
|
+
{ operationId },
|
|
222
|
+
),
|
|
223
|
+
).toEqual({
|
|
224
|
+
recordVersion: 2,
|
|
225
|
+
operationId,
|
|
226
|
+
recordJSON: h.recordJSON,
|
|
227
|
+
revision: 0,
|
|
228
|
+
activeAttempt: null,
|
|
229
|
+
initialBasis: null,
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
const before = await physical();
|
|
233
|
+
const operation = before.operations[0];
|
|
234
|
+
let targetFailed = false;
|
|
235
|
+
let stable = before;
|
|
236
|
+
try {
|
|
237
|
+
if (scenario.phase === "create") {
|
|
238
|
+
const operationPromise =
|
|
239
|
+
scenario.parent === "action"
|
|
240
|
+
? t.action(createAction, createArgs)
|
|
241
|
+
: t.mutation(createMutation, createArgs);
|
|
242
|
+
await expect(operationPromise).rejects.toThrow(
|
|
243
|
+
new RegExp("^" + parentStop + "$"),
|
|
244
|
+
);
|
|
245
|
+
} else {
|
|
246
|
+
const args: ObjectType<typeof reserveArgs> = {
|
|
247
|
+
operationId: operation._id,
|
|
248
|
+
expectedRevision: 0,
|
|
249
|
+
stage: "attach",
|
|
250
|
+
expectedRequestBinding: h.record.requestBinding,
|
|
251
|
+
recordJSON: h.recordJSON,
|
|
252
|
+
};
|
|
253
|
+
expect(getConvexSize(args)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
254
|
+
const operationPromise =
|
|
255
|
+
scenario.parent === "action"
|
|
256
|
+
? t.action(reserveAction, args)
|
|
257
|
+
: t.mutation(reserveMutation, args);
|
|
258
|
+
await expect(operationPromise).rejects.toThrow(
|
|
259
|
+
new RegExp("^" + parentStop + "$"),
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
expect(trace).toHaveLength(1);
|
|
263
|
+
expect(trace[0].route).toBe(scenario.route);
|
|
264
|
+
const after = await physical();
|
|
265
|
+
stable = after;
|
|
266
|
+
if (scenario.parent === "mutation") {
|
|
267
|
+
expect(after).toEqual(before);
|
|
268
|
+
} else if (scenario.phase === "create") {
|
|
269
|
+
expect({
|
|
270
|
+
operations: after.operations.length,
|
|
271
|
+
attempts: after.attempts.length,
|
|
272
|
+
events: after.events.length,
|
|
273
|
+
payloads: after.payloads.length,
|
|
274
|
+
}).toEqual({ operations: 1, attempts: 0, events: 0, payloads: 1 });
|
|
275
|
+
const row = after.operations[0];
|
|
276
|
+
const payload = after.payloads[0];
|
|
277
|
+
expect(row).toEqual({
|
|
278
|
+
_id: row._id,
|
|
279
|
+
_creationTime: row._creationTime,
|
|
280
|
+
recordVersion: 2,
|
|
281
|
+
authorizationScope: h.record.authorization.scope,
|
|
282
|
+
authorizationId: h.record.authorization.id,
|
|
283
|
+
authorizationRevision: h.record.authorization.revision,
|
|
284
|
+
logicalOperationId: h.record.logicalOperationId,
|
|
285
|
+
requestBinding: h.record.requestBinding,
|
|
286
|
+
payloadId: payload._id,
|
|
287
|
+
revision: 0,
|
|
288
|
+
state: "PREPARED",
|
|
289
|
+
});
|
|
290
|
+
expect(payload).toEqual({
|
|
291
|
+
_id: payload._id,
|
|
292
|
+
_creationTime: payload._creationTime,
|
|
293
|
+
codecVersion: 1,
|
|
294
|
+
json: h.recordJSON,
|
|
295
|
+
owner: { kind: "operation", operationId: row._id },
|
|
296
|
+
});
|
|
297
|
+
expect(trace[0].reply).toEqual({
|
|
298
|
+
status: "created",
|
|
299
|
+
operationId: row._id,
|
|
300
|
+
});
|
|
301
|
+
} else {
|
|
302
|
+
expect({
|
|
303
|
+
operations: after.operations.length,
|
|
304
|
+
attempts: after.attempts.length,
|
|
305
|
+
events: after.events.length,
|
|
306
|
+
payloads: after.payloads.length,
|
|
307
|
+
}).toEqual({ operations: 1, attempts: 1, events: 0, payloads: 1 });
|
|
308
|
+
const attempt = after.attempts[0];
|
|
309
|
+
expect(after.operations).toEqual([
|
|
310
|
+
{
|
|
311
|
+
...operation,
|
|
312
|
+
revision: 1,
|
|
313
|
+
state: "RESERVED",
|
|
314
|
+
activeAttemptId: attempt._id,
|
|
315
|
+
},
|
|
316
|
+
]);
|
|
317
|
+
expect(after.payloads).toEqual(before.payloads);
|
|
318
|
+
expect(after.events).toEqual(before.events);
|
|
319
|
+
expect(attempt).toEqual({
|
|
320
|
+
_id: attempt._id,
|
|
321
|
+
_creationTime: attempt._creationTime,
|
|
322
|
+
operationId: operation._id,
|
|
323
|
+
payloadId: operation.payloadId,
|
|
324
|
+
recordVersion: 2,
|
|
325
|
+
stage: "attach",
|
|
326
|
+
authorizationScope: h.record.authorization.scope,
|
|
327
|
+
authorizationId: h.record.authorization.id,
|
|
328
|
+
authorizationRevision: h.record.authorization.revision,
|
|
329
|
+
logicalOperationId: h.record.logicalOperationId,
|
|
330
|
+
requestBinding: h.record.requestBinding,
|
|
331
|
+
key: h.request.key,
|
|
332
|
+
apiVersion: h.request.apiVersion,
|
|
333
|
+
accountJSON: canonical(h.record.account),
|
|
334
|
+
timingPolicyJSON: canonical(h.record.timingPolicy),
|
|
335
|
+
firstDispatchedAt: h.request.firstDispatchedAt,
|
|
336
|
+
ordinal: 1,
|
|
337
|
+
preparedRevision: 0,
|
|
338
|
+
committedRevision: 1,
|
|
339
|
+
lastSequence: 0,
|
|
340
|
+
});
|
|
341
|
+
const { _id, _creationTime, lastSequence, ...fields } = attempt;
|
|
342
|
+
void _creationTime;
|
|
343
|
+
void lastSequence;
|
|
344
|
+
expect(trace[0].reply).toEqual({
|
|
345
|
+
disposition: "acquired",
|
|
346
|
+
previousRevision: 0,
|
|
347
|
+
committedRevision: 1,
|
|
348
|
+
reservation: { ...fields, attemptId: _id, recordJSON: h.recordJSON },
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
for (const rows of Object.values(after))
|
|
352
|
+
for (const row of rows) {
|
|
353
|
+
expect(Number.isFinite(row._creationTime)).toBe(true);
|
|
354
|
+
expect(getDocumentSize(row)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
355
|
+
}
|
|
356
|
+
expect(getConvexSize(after)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
357
|
+
expect(canonical(h.record)).toBe(h.recordJSON);
|
|
358
|
+
} catch (error) {
|
|
359
|
+
targetFailed = true;
|
|
360
|
+
throw error;
|
|
361
|
+
} finally {
|
|
362
|
+
try {
|
|
363
|
+
const after = await physical();
|
|
364
|
+
console.info(
|
|
365
|
+
"JOURNAL_ACTION_MECHANICAL_SETTLEMENT",
|
|
366
|
+
JSON.stringify({
|
|
367
|
+
phase: scenario.phase,
|
|
368
|
+
parent: scenario.parent,
|
|
369
|
+
childFulfillments: trace.length,
|
|
370
|
+
physicalEqual: JSON.stringify(after) === JSON.stringify(stable),
|
|
371
|
+
counts: {
|
|
372
|
+
operations: after.operations.length,
|
|
373
|
+
attempts: after.attempts.length,
|
|
374
|
+
events: after.events.length,
|
|
375
|
+
payloads: after.payloads.length,
|
|
376
|
+
},
|
|
377
|
+
fetchCalls: h.fetchCalls(),
|
|
378
|
+
}),
|
|
379
|
+
);
|
|
380
|
+
expect(after).toEqual(stable);
|
|
381
|
+
expect(h.fetchCalls()).toBe(0);
|
|
382
|
+
} catch (inspectionError) {
|
|
383
|
+
if (!targetFailed) throw inspectionError;
|
|
384
|
+
console.info("JOURNAL_ACTION_MECHANICAL_INSPECTION_FAILED");
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
},
|
|
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
|
+
});
|