@fragno-dev/db 0.2.0 → 0.2.2
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/.turbo/turbo-build.log +34 -30
- package/CHANGELOG.md +49 -0
- package/dist/adapters/generic-sql/query/where-builder.js +1 -1
- package/dist/db-fragment-definition-builder.d.ts +31 -39
- package/dist/db-fragment-definition-builder.d.ts.map +1 -1
- package/dist/db-fragment-definition-builder.js +20 -16
- package/dist/db-fragment-definition-builder.js.map +1 -1
- package/dist/fragments/internal-fragment.d.ts +94 -8
- package/dist/fragments/internal-fragment.d.ts.map +1 -1
- package/dist/fragments/internal-fragment.js +56 -55
- package/dist/fragments/internal-fragment.js.map +1 -1
- package/dist/hooks/hooks.d.ts +5 -3
- package/dist/hooks/hooks.d.ts.map +1 -1
- package/dist/hooks/hooks.js +38 -37
- package/dist/hooks/hooks.js.map +1 -1
- package/dist/mod.d.ts +3 -3
- package/dist/mod.d.ts.map +1 -1
- package/dist/mod.js +4 -4
- package/dist/mod.js.map +1 -1
- package/dist/query/unit-of-work/execute-unit-of-work.d.ts +367 -80
- package/dist/query/unit-of-work/execute-unit-of-work.d.ts.map +1 -1
- package/dist/query/unit-of-work/execute-unit-of-work.js +448 -148
- package/dist/query/unit-of-work/execute-unit-of-work.js.map +1 -1
- package/dist/query/unit-of-work/unit-of-work.d.ts +35 -11
- package/dist/query/unit-of-work/unit-of-work.d.ts.map +1 -1
- package/dist/query/unit-of-work/unit-of-work.js +49 -19
- package/dist/query/unit-of-work/unit-of-work.js.map +1 -1
- package/dist/query/value-decoding.js +1 -1
- package/dist/schema/create.d.ts +2 -3
- package/dist/schema/create.d.ts.map +1 -1
- package/dist/schema/create.js +2 -5
- package/dist/schema/create.js.map +1 -1
- package/dist/schema/generate-id.d.ts +20 -0
- package/dist/schema/generate-id.d.ts.map +1 -0
- package/dist/schema/generate-id.js +28 -0
- package/dist/schema/generate-id.js.map +1 -0
- package/dist/sql-driver/dialects/durable-object-dialect.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/adapters/drizzle/drizzle-adapter-pglite.test.ts +1 -0
- package/src/adapters/drizzle/drizzle-adapter-sqlite3.test.ts +41 -25
- package/src/adapters/generic-sql/test/generic-drizzle-adapter-sqlite3.test.ts +39 -25
- package/src/db-fragment-definition-builder.test.ts +58 -42
- package/src/db-fragment-definition-builder.ts +78 -88
- package/src/db-fragment-instantiator.test.ts +64 -88
- package/src/db-fragment-integration.test.ts +292 -142
- package/src/fragments/internal-fragment.test.ts +272 -266
- package/src/fragments/internal-fragment.ts +155 -122
- package/src/hooks/hooks.test.ts +268 -264
- package/src/hooks/hooks.ts +74 -63
- package/src/mod.ts +14 -4
- package/src/query/unit-of-work/execute-unit-of-work.test.ts +1582 -998
- package/src/query/unit-of-work/execute-unit-of-work.ts +1746 -343
- package/src/query/unit-of-work/tx-builder.test.ts +1041 -0
- package/src/query/unit-of-work/unit-of-work-coordinator.test.ts +269 -21
- package/src/query/unit-of-work/unit-of-work.test.ts +64 -0
- package/src/query/unit-of-work/unit-of-work.ts +65 -30
- package/src/schema/create.ts +2 -5
- package/src/schema/generate-id.test.ts +57 -0
- package/src/schema/generate-id.ts +38 -0
- package/src/shared/config.ts +0 -10
- package/src/shared/connection-pool.ts +0 -24
- package/src/shared/prisma.ts +0 -45
package/src/hooks/hooks.test.ts
CHANGED
|
@@ -53,33 +53,43 @@ describe("Hook System", () => {
|
|
|
53
53
|
const hooks: HooksMap = {
|
|
54
54
|
onTest: vi.fn(),
|
|
55
55
|
};
|
|
56
|
+
const onSuccess = vi.fn();
|
|
57
|
+
const onBeforeMutate = vi.fn();
|
|
56
58
|
|
|
57
59
|
await internalFragment.inContext(async function () {
|
|
58
|
-
await this.
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
60
|
+
await this.handlerTx({
|
|
61
|
+
onAfterMutate: onSuccess,
|
|
62
|
+
onBeforeMutate,
|
|
63
|
+
})
|
|
64
|
+
.mutate(({ forSchema }) => {
|
|
65
|
+
const uow = forSchema(internalSchema, hooks);
|
|
66
|
+
|
|
67
|
+
// Trigger a hook
|
|
68
|
+
uow.triggerHook("onTest", { data: "test" });
|
|
69
|
+
|
|
70
|
+
// Prepare hook mutations
|
|
71
|
+
prepareHookMutations(uow, {
|
|
72
|
+
hooks,
|
|
73
|
+
namespace,
|
|
74
|
+
internalFragment,
|
|
75
|
+
defaultRetryPolicy: new ExponentialBackoffRetryPolicy({ maxRetries: 5 }),
|
|
76
|
+
});
|
|
77
|
+
})
|
|
78
|
+
.execute();
|
|
74
79
|
});
|
|
75
80
|
|
|
81
|
+
// Verify callbacks were executed
|
|
82
|
+
expect(onSuccess).toHaveBeenCalledOnce();
|
|
83
|
+
expect(onBeforeMutate).toHaveBeenCalledOnce();
|
|
84
|
+
|
|
76
85
|
// Verify hook was created
|
|
77
86
|
const events = await internalFragment.inContext(async function () {
|
|
78
|
-
return await this.
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
87
|
+
return await this.handlerTx()
|
|
88
|
+
.withServiceCalls(
|
|
89
|
+
() => [internalFragment.services.hookService.getPendingHookEvents(namespace)] as const,
|
|
90
|
+
)
|
|
91
|
+
.transform(({ serviceResult: [result] }) => result)
|
|
92
|
+
.execute();
|
|
83
93
|
});
|
|
84
94
|
|
|
85
95
|
expect(events).toHaveLength(1);
|
|
@@ -98,28 +108,29 @@ describe("Hook System", () => {
|
|
|
98
108
|
};
|
|
99
109
|
|
|
100
110
|
await internalFragment.inContext(async function () {
|
|
101
|
-
await this.
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
111
|
+
await this.handlerTx()
|
|
112
|
+
.mutate(({ forSchema }) => {
|
|
113
|
+
const uow = forSchema(internalSchema, hooks);
|
|
114
|
+
|
|
115
|
+
uow.triggerHook("onNoRetry", { data: "test" });
|
|
116
|
+
|
|
117
|
+
prepareHookMutations(uow, {
|
|
118
|
+
hooks,
|
|
119
|
+
namespace,
|
|
120
|
+
internalFragment,
|
|
121
|
+
defaultRetryPolicy: new NoRetryPolicy(),
|
|
122
|
+
});
|
|
123
|
+
})
|
|
124
|
+
.execute();
|
|
115
125
|
});
|
|
116
126
|
|
|
117
127
|
const events = await internalFragment.inContext(async function () {
|
|
118
|
-
return await this.
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
128
|
+
return await this.handlerTx()
|
|
129
|
+
.withServiceCalls(
|
|
130
|
+
() => [internalFragment.services.hookService.getPendingHookEvents(namespace)] as const,
|
|
131
|
+
)
|
|
132
|
+
.transform(({ serviceResult: [result] }) => result)
|
|
133
|
+
.execute();
|
|
123
134
|
});
|
|
124
135
|
|
|
125
136
|
expect(events).toHaveLength(1);
|
|
@@ -133,34 +144,35 @@ describe("Hook System", () => {
|
|
|
133
144
|
};
|
|
134
145
|
|
|
135
146
|
await internalFragment.inContext(async function () {
|
|
136
|
-
await this.
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
147
|
+
await this.handlerTx()
|
|
148
|
+
.mutate(({ forSchema }) => {
|
|
149
|
+
const uow = forSchema(internalSchema, hooks);
|
|
150
|
+
|
|
151
|
+
uow.triggerHook(
|
|
152
|
+
"onCustomRetry",
|
|
153
|
+
{ data: "test" },
|
|
154
|
+
{
|
|
155
|
+
retryPolicy: new NoRetryPolicy(),
|
|
156
|
+
},
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
prepareHookMutations(uow, {
|
|
160
|
+
hooks,
|
|
161
|
+
namespace,
|
|
162
|
+
internalFragment,
|
|
163
|
+
defaultRetryPolicy: new ExponentialBackoffRetryPolicy({ maxRetries: 10 }),
|
|
164
|
+
});
|
|
165
|
+
})
|
|
166
|
+
.execute();
|
|
156
167
|
});
|
|
157
168
|
|
|
158
169
|
const events = await internalFragment.inContext(async function () {
|
|
159
|
-
return await this.
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
170
|
+
return await this.handlerTx()
|
|
171
|
+
.withServiceCalls(
|
|
172
|
+
() => [internalFragment.services.hookService.getPendingHookEvents(namespace)] as const,
|
|
173
|
+
)
|
|
174
|
+
.transform(({ serviceResult: [result] }) => result)
|
|
175
|
+
.execute();
|
|
164
176
|
});
|
|
165
177
|
|
|
166
178
|
expect(events[0]?.maxAttempts).toBe(1);
|
|
@@ -179,22 +191,24 @@ describe("Hook System", () => {
|
|
|
179
191
|
|
|
180
192
|
// Create a pending hook event
|
|
181
193
|
await internalFragment.inContext(async function () {
|
|
182
|
-
await this.
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
194
|
+
const createdId = await this.handlerTx()
|
|
195
|
+
.mutate(({ forSchema }) => {
|
|
196
|
+
const uow = forSchema(internalSchema);
|
|
197
|
+
return uow.create("fragno_hooks", {
|
|
198
|
+
namespace,
|
|
199
|
+
hookName: "onSuccess",
|
|
200
|
+
payload: { email: "test@example.com" },
|
|
201
|
+
status: "pending",
|
|
202
|
+
attempts: 0,
|
|
203
|
+
maxAttempts: 5,
|
|
204
|
+
lastAttemptAt: null,
|
|
205
|
+
nextRetryAt: null,
|
|
206
|
+
error: null,
|
|
207
|
+
nonce: "test-nonce",
|
|
208
|
+
});
|
|
209
|
+
})
|
|
210
|
+
.execute();
|
|
211
|
+
eventId = createdId;
|
|
198
212
|
});
|
|
199
213
|
|
|
200
214
|
// Process hooks
|
|
@@ -211,19 +225,16 @@ describe("Hook System", () => {
|
|
|
211
225
|
|
|
212
226
|
// Verify hook context (this)
|
|
213
227
|
const hookContext = hookFn.mock.contexts[0] as HookContext;
|
|
214
|
-
expect(hookContext.
|
|
228
|
+
expect(hookContext.idempotencyKey).toBe("test-nonce");
|
|
215
229
|
|
|
216
230
|
// Verify event was marked as completed
|
|
217
231
|
const result = await internalFragment.inContext(async function () {
|
|
218
|
-
return await this.
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
)
|
|
223
|
-
|
|
224
|
-
const [events] = await findUow.retrievalPhase;
|
|
225
|
-
return events?.[0];
|
|
226
|
-
});
|
|
232
|
+
return await this.handlerTx()
|
|
233
|
+
.withServiceCalls(
|
|
234
|
+
() => [internalFragment.services.hookService.getHookById(eventId)] as const,
|
|
235
|
+
)
|
|
236
|
+
.transform(({ serviceResult: [event] }) => event)
|
|
237
|
+
.execute();
|
|
227
238
|
});
|
|
228
239
|
|
|
229
240
|
expect(result?.status).toBe("completed");
|
|
@@ -240,22 +251,24 @@ describe("Hook System", () => {
|
|
|
240
251
|
let eventId: FragnoId;
|
|
241
252
|
|
|
242
253
|
await internalFragment.inContext(async function () {
|
|
243
|
-
await this.
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
254
|
+
const createdId = await this.handlerTx()
|
|
255
|
+
.mutate(({ forSchema }) => {
|
|
256
|
+
const uow = forSchema(internalSchema);
|
|
257
|
+
return uow.create("fragno_hooks", {
|
|
258
|
+
namespace,
|
|
259
|
+
hookName: "onFailure",
|
|
260
|
+
payload: { data: "test" },
|
|
261
|
+
status: "pending",
|
|
262
|
+
attempts: 0,
|
|
263
|
+
maxAttempts: 5,
|
|
264
|
+
lastAttemptAt: null,
|
|
265
|
+
nextRetryAt: null,
|
|
266
|
+
error: null,
|
|
267
|
+
nonce: "test-nonce",
|
|
268
|
+
});
|
|
269
|
+
})
|
|
270
|
+
.execute();
|
|
271
|
+
eventId = createdId;
|
|
259
272
|
});
|
|
260
273
|
|
|
261
274
|
await processHooks({
|
|
@@ -268,15 +281,12 @@ describe("Hook System", () => {
|
|
|
268
281
|
expect(hookFn).toHaveBeenCalledOnce();
|
|
269
282
|
|
|
270
283
|
const result = await internalFragment.inContext(async function () {
|
|
271
|
-
return await this.
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
)
|
|
276
|
-
|
|
277
|
-
const [events] = await findUow.retrievalPhase;
|
|
278
|
-
return events?.[0];
|
|
279
|
-
});
|
|
284
|
+
return await this.handlerTx()
|
|
285
|
+
.withServiceCalls(
|
|
286
|
+
() => [internalFragment.services.hookService.getHookById(eventId)] as const,
|
|
287
|
+
)
|
|
288
|
+
.transform(({ serviceResult: [event] }) => event)
|
|
289
|
+
.execute();
|
|
280
290
|
});
|
|
281
291
|
|
|
282
292
|
expect(result?.status).toBe("pending");
|
|
@@ -295,22 +305,24 @@ describe("Hook System", () => {
|
|
|
295
305
|
let eventId: FragnoId;
|
|
296
306
|
|
|
297
307
|
await internalFragment.inContext(async function () {
|
|
298
|
-
await this.
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
308
|
+
const createdId = await this.handlerTx()
|
|
309
|
+
.mutate(({ forSchema }) => {
|
|
310
|
+
const uow = forSchema(internalSchema);
|
|
311
|
+
return uow.create("fragno_hooks", {
|
|
312
|
+
namespace,
|
|
313
|
+
hookName: "onMaxRetries",
|
|
314
|
+
payload: { data: "test" },
|
|
315
|
+
status: "pending",
|
|
316
|
+
attempts: 0,
|
|
317
|
+
maxAttempts: 1,
|
|
318
|
+
lastAttemptAt: null,
|
|
319
|
+
nextRetryAt: null,
|
|
320
|
+
error: null,
|
|
321
|
+
nonce: "test-nonce",
|
|
322
|
+
});
|
|
323
|
+
})
|
|
324
|
+
.execute();
|
|
325
|
+
eventId = createdId;
|
|
314
326
|
});
|
|
315
327
|
|
|
316
328
|
await processHooks({
|
|
@@ -321,15 +333,12 @@ describe("Hook System", () => {
|
|
|
321
333
|
});
|
|
322
334
|
|
|
323
335
|
const result = await internalFragment.inContext(async function () {
|
|
324
|
-
return await this.
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
)
|
|
329
|
-
|
|
330
|
-
const [events] = await findUow.retrievalPhase;
|
|
331
|
-
return events?.[0];
|
|
332
|
-
});
|
|
336
|
+
return await this.handlerTx()
|
|
337
|
+
.withServiceCalls(
|
|
338
|
+
() => [internalFragment.services.hookService.getHookById(eventId)] as const,
|
|
339
|
+
)
|
|
340
|
+
.transform(({ serviceResult: [event] }) => event)
|
|
341
|
+
.execute();
|
|
333
342
|
});
|
|
334
343
|
|
|
335
344
|
expect(result?.status).toBe("failed");
|
|
@@ -346,22 +355,24 @@ describe("Hook System", () => {
|
|
|
346
355
|
let eventId: FragnoId;
|
|
347
356
|
|
|
348
357
|
await internalFragment.inContext(async function () {
|
|
349
|
-
await this.
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
358
|
+
const createdId = await this.handlerTx()
|
|
359
|
+
.mutate(({ forSchema }) => {
|
|
360
|
+
const uow = forSchema(internalSchema);
|
|
361
|
+
return uow.create("fragno_hooks", {
|
|
362
|
+
namespace,
|
|
363
|
+
hookName: "onMissing",
|
|
364
|
+
payload: { data: "test" },
|
|
365
|
+
status: "pending",
|
|
366
|
+
attempts: 0,
|
|
367
|
+
maxAttempts: 1,
|
|
368
|
+
lastAttemptAt: null,
|
|
369
|
+
nextRetryAt: null,
|
|
370
|
+
error: null,
|
|
371
|
+
nonce: "test-nonce",
|
|
372
|
+
});
|
|
373
|
+
})
|
|
374
|
+
.execute();
|
|
375
|
+
eventId = createdId;
|
|
365
376
|
});
|
|
366
377
|
|
|
367
378
|
await processHooks({
|
|
@@ -372,15 +383,12 @@ describe("Hook System", () => {
|
|
|
372
383
|
});
|
|
373
384
|
|
|
374
385
|
const result = await internalFragment.inContext(async function () {
|
|
375
|
-
return await this.
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
)
|
|
380
|
-
|
|
381
|
-
const [events] = await findUow.retrievalPhase;
|
|
382
|
-
return events?.[0];
|
|
383
|
-
});
|
|
386
|
+
return await this.handlerTx()
|
|
387
|
+
.withServiceCalls(
|
|
388
|
+
() => [internalFragment.services.hookService.getHookById(eventId)] as const,
|
|
389
|
+
)
|
|
390
|
+
.transform(({ serviceResult: [event] }) => event)
|
|
391
|
+
.execute();
|
|
384
392
|
});
|
|
385
393
|
|
|
386
394
|
expect(result?.status).toBe("failed");
|
|
@@ -399,46 +407,47 @@ describe("Hook System", () => {
|
|
|
399
407
|
};
|
|
400
408
|
|
|
401
409
|
await internalFragment.inContext(async function () {
|
|
402
|
-
await this.
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
410
|
+
await this.handlerTx()
|
|
411
|
+
.mutate(({ forSchema }) => {
|
|
412
|
+
const uow = forSchema(internalSchema);
|
|
413
|
+
uow.create("fragno_hooks", {
|
|
414
|
+
namespace,
|
|
415
|
+
hookName: "onHook1",
|
|
416
|
+
payload: { id: 1 },
|
|
417
|
+
status: "pending",
|
|
418
|
+
attempts: 0,
|
|
419
|
+
maxAttempts: 5,
|
|
420
|
+
lastAttemptAt: null,
|
|
421
|
+
nextRetryAt: null,
|
|
422
|
+
error: null,
|
|
423
|
+
nonce: "nonce-1",
|
|
424
|
+
});
|
|
425
|
+
uow.create("fragno_hooks", {
|
|
426
|
+
namespace,
|
|
427
|
+
hookName: "onHook2",
|
|
428
|
+
payload: { id: 2 },
|
|
429
|
+
status: "pending",
|
|
430
|
+
attempts: 0,
|
|
431
|
+
maxAttempts: 5,
|
|
432
|
+
lastAttemptAt: null,
|
|
433
|
+
nextRetryAt: null,
|
|
434
|
+
error: null,
|
|
435
|
+
nonce: "nonce-2",
|
|
436
|
+
});
|
|
437
|
+
uow.create("fragno_hooks", {
|
|
438
|
+
namespace,
|
|
439
|
+
hookName: "onHook3",
|
|
440
|
+
payload: { id: 3 },
|
|
441
|
+
status: "pending",
|
|
442
|
+
attempts: 0,
|
|
443
|
+
maxAttempts: 5,
|
|
444
|
+
lastAttemptAt: null,
|
|
445
|
+
nextRetryAt: null,
|
|
446
|
+
error: null,
|
|
447
|
+
nonce: "nonce-3",
|
|
448
|
+
});
|
|
449
|
+
})
|
|
450
|
+
.execute();
|
|
442
451
|
});
|
|
443
452
|
|
|
444
453
|
await processHooks({
|
|
@@ -454,15 +463,12 @@ describe("Hook System", () => {
|
|
|
454
463
|
|
|
455
464
|
// Verify all were marked as completed
|
|
456
465
|
const events = await internalFragment.inContext(async function () {
|
|
457
|
-
return await this.
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
)
|
|
462
|
-
|
|
463
|
-
const [results] = await findUow.retrievalPhase;
|
|
464
|
-
return results;
|
|
465
|
-
});
|
|
466
|
+
return await this.handlerTx()
|
|
467
|
+
.withServiceCalls(
|
|
468
|
+
() => [internalFragment.services.hookService.getHooksByNamespace(namespace)] as const,
|
|
469
|
+
)
|
|
470
|
+
.transform(({ serviceResult: [result] }) => result)
|
|
471
|
+
.execute();
|
|
466
472
|
});
|
|
467
473
|
|
|
468
474
|
const completed = events.filter((e) => e.status === "completed");
|
|
@@ -481,46 +487,47 @@ describe("Hook System", () => {
|
|
|
481
487
|
};
|
|
482
488
|
|
|
483
489
|
await internalFragment.inContext(async function () {
|
|
484
|
-
await this.
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
490
|
+
await this.handlerTx()
|
|
491
|
+
.mutate(({ forSchema }) => {
|
|
492
|
+
const uow = forSchema(internalSchema);
|
|
493
|
+
uow.create("fragno_hooks", {
|
|
494
|
+
namespace,
|
|
495
|
+
hookName: "onHook1",
|
|
496
|
+
payload: { id: 1 },
|
|
497
|
+
status: "pending",
|
|
498
|
+
attempts: 0,
|
|
499
|
+
maxAttempts: 5,
|
|
500
|
+
lastAttemptAt: null,
|
|
501
|
+
nextRetryAt: null,
|
|
502
|
+
error: null,
|
|
503
|
+
nonce: "nonce-1",
|
|
504
|
+
});
|
|
505
|
+
uow.create("fragno_hooks", {
|
|
506
|
+
namespace,
|
|
507
|
+
hookName: "onHook2",
|
|
508
|
+
payload: { id: 2 },
|
|
509
|
+
status: "pending",
|
|
510
|
+
attempts: 0,
|
|
511
|
+
maxAttempts: 5,
|
|
512
|
+
lastAttemptAt: null,
|
|
513
|
+
nextRetryAt: null,
|
|
514
|
+
error: null,
|
|
515
|
+
nonce: "nonce-2",
|
|
516
|
+
});
|
|
517
|
+
uow.create("fragno_hooks", {
|
|
518
|
+
namespace,
|
|
519
|
+
hookName: "onHook3",
|
|
520
|
+
payload: { id: 3 },
|
|
521
|
+
status: "pending",
|
|
522
|
+
attempts: 0,
|
|
523
|
+
maxAttempts: 5,
|
|
524
|
+
lastAttemptAt: null,
|
|
525
|
+
nextRetryAt: null,
|
|
526
|
+
error: null,
|
|
527
|
+
nonce: "nonce-3",
|
|
528
|
+
});
|
|
529
|
+
})
|
|
530
|
+
.execute();
|
|
524
531
|
});
|
|
525
532
|
|
|
526
533
|
await processHooks({
|
|
@@ -536,15 +543,12 @@ describe("Hook System", () => {
|
|
|
536
543
|
|
|
537
544
|
// Verify hook1 and hook3 were completed, hook2 was marked for retry
|
|
538
545
|
const events = await internalFragment.inContext(async function () {
|
|
539
|
-
return await this.
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
)
|
|
544
|
-
|
|
545
|
-
const [results] = await findUow.retrievalPhase;
|
|
546
|
-
return results;
|
|
547
|
-
});
|
|
546
|
+
return await this.handlerTx()
|
|
547
|
+
.withServiceCalls(
|
|
548
|
+
() => [internalFragment.services.hookService.getHooksByNamespace(namespace)] as const,
|
|
549
|
+
)
|
|
550
|
+
.transform(({ serviceResult: [result] }) => result)
|
|
551
|
+
.execute();
|
|
548
552
|
});
|
|
549
553
|
|
|
550
554
|
const completed = events.filter((e) => e.status === "completed");
|