@voltro/testing 0.70.0 → 0.71.1
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 +1341 -111
- package/dist/dialect.js +642 -363
- package/dist/index.js +171 -158
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -1,47 +1,47 @@
|
|
|
1
1
|
import { AUTO_FILLED_COLUMNS as e, allRegisteredTables as t, changeDelete as n, changeInsert as r, changeSoftDelete as i, changeUpdate as a, clearRelationsRegistry as o, missingRequiredColumns as s, registerRelations as c } from "@voltro/database";
|
|
2
2
|
import { Cause as l, Effect as u, Exit as d, Layer as f, Schema as p } from "effect";
|
|
3
3
|
import { SubjectService as m, anonymousSubject as h, checkGuardsEffect as g, composeAuthStrategies as _, composeRpcInterceptors as v, eventRoute as y, systemSubject as b, tenantScopedSubject as ee } from "@voltro/protocol";
|
|
4
|
-
import { EventBus as x, InMemoryDataStore as
|
|
5
|
-
import { installEnvSnapshot as
|
|
6
|
-
import
|
|
7
|
-
import { describe as
|
|
8
|
-
import { collectPublicApiRoutes as
|
|
9
|
-
import { createLogger as
|
|
10
|
-
import { CurrentWorkflowRunId as
|
|
4
|
+
import { EventBus as x, InMemoryDataStore as S, NO_ROW_FILTER as C, appValidation as te, applyRowFilterToDescriptor as ne, clearSystemStoreHandle as re, getRowFilter as w, getSystemStoreHandle as ie, makeAppAccess as ae, makeConnectionState as oe, makeDataLoader as se, makeEffectStoreLayer as ce, makeEventPublisher as le, makeFieldCipher as ue, makeOutboxFacade as de, makeSchemaRegistry as fe, publishEvent as pe, resolveRowFilterScopeFor as me, resolveTransactionSubject as he, runProvidedEffect as T, runWithDeadlockRetry as ge, setFieldCipher as _e, setSystemStoreHandle as E, wrapStoreWithMixinBehaviour as D } from "@voltro/runtime";
|
|
5
|
+
import { installEnvSnapshot as ve } from "@voltro/env";
|
|
6
|
+
import ye from "node:net";
|
|
7
|
+
import { describe as be } from "vitest";
|
|
8
|
+
import { collectPublicApiRoutes as xe, dispatchSharedPath as Se, restRoutesToHttpRoutes as Ce } from "@voltro/protocol/rest";
|
|
9
|
+
import { createLogger as we } from "@voltro/logger";
|
|
10
|
+
import { CurrentWorkflowRunId as Te, inMemoryWorkflowEngineLayer as Ee, makeInMemoryRecorder as De } from "@voltro/workflow";
|
|
11
11
|
//#region src/fixtureRow.ts
|
|
12
|
-
var
|
|
12
|
+
var Oe = new Set(e), O = 0, k = () => ++O, ke = (e, t) => {
|
|
13
13
|
if (t.oneOf && t.oneOf.length > 0) return t.oneOf[0];
|
|
14
14
|
if (t.enumValues && t.enumValues.length > 0) return t.enumValues[0];
|
|
15
15
|
let n = t.unique === !0;
|
|
16
16
|
switch (t.type) {
|
|
17
17
|
case "text":
|
|
18
18
|
case "id":
|
|
19
|
-
case "enum": return n ? `${e}-${++
|
|
20
|
-
case "reference": return t.referenceStorage === "numeric" ? n ? ++
|
|
19
|
+
case "enum": return n ? `${e}-${++O}` : e;
|
|
20
|
+
case "reference": return t.referenceStorage === "numeric" ? n ? ++O : 0 : n ? `${e}-${++O}` : e;
|
|
21
21
|
case "integer":
|
|
22
|
-
case "real": return n ? ++
|
|
22
|
+
case "real": return n ? ++O : 0;
|
|
23
23
|
case "decimal":
|
|
24
|
-
case "bigint": return n ? String(++
|
|
24
|
+
case "bigint": return n ? String(++O) : "0";
|
|
25
25
|
case "boolean": return !1;
|
|
26
26
|
case "timestamp":
|
|
27
27
|
case "date": return /* @__PURE__ */ new Date(0);
|
|
28
28
|
default: throw Error(`fixtureRow: column '${e}' is a required '${t.type}' with no default, and fixtureRow can't synthesize a safe placeholder for that type. Pass it explicitly: fixtureRow(table, { ${e}: … }).`);
|
|
29
29
|
}
|
|
30
|
-
},
|
|
30
|
+
}, A = (e, t = {}) => {
|
|
31
31
|
let n = {};
|
|
32
|
-
for (let r of s(e, t))
|
|
32
|
+
for (let r of s(e, t)) Oe.has(r) || (n[r] = ke(r, e.fields[r]));
|
|
33
33
|
return {
|
|
34
34
|
...n,
|
|
35
35
|
...t
|
|
36
36
|
};
|
|
37
|
-
},
|
|
37
|
+
}, Ae = (e) => {
|
|
38
38
|
let t = {};
|
|
39
|
-
for (let [n, r] of Object.entries(e)) t[n] = typeof r == "function" ? r(
|
|
39
|
+
for (let [n, r] of Object.entries(e)) t[n] = typeof r == "function" ? r(k()) : r;
|
|
40
40
|
return t;
|
|
41
|
-
},
|
|
41
|
+
}, je = (e) => {
|
|
42
42
|
for (let [t, n] of Object.entries(e.fields)) if (n.type === "id") return t;
|
|
43
43
|
return "id";
|
|
44
|
-
},
|
|
44
|
+
}, Me = async (e, t, n, r, i) => {
|
|
45
45
|
let a = {};
|
|
46
46
|
for (let o of s(t, n)) {
|
|
47
47
|
let n = t.fields[o];
|
|
@@ -49,29 +49,29 @@ var Ae = new Set(e), T = 0, E = () => ++T, je = (e, t) => {
|
|
|
49
49
|
let s = n.references();
|
|
50
50
|
if (i.includes(s.tableName)) throw Error(`defineFactory: creating '${t.tableName}' requires '${s.tableName}' via '${o}', and that reference is cyclic (${[...i, s.tableName].join(" → ")}). Insert one side first and pass the id: create(store, { ${o}: existing.id }).`);
|
|
51
51
|
let c = r[o];
|
|
52
|
-
a[o] = (c === void 0 ? await
|
|
52
|
+
a[o] = (c === void 0 ? await j(e, s, {}, {}, [...i, s.tableName]) : await c.create(e, {}))[n.referenceColumn ?? je(s)];
|
|
53
53
|
}
|
|
54
54
|
return a;
|
|
55
|
-
},
|
|
55
|
+
}, j = async (e, t, n, r, i) => {
|
|
56
56
|
let a = {
|
|
57
|
-
...await
|
|
57
|
+
...await Me(e, t, n, r, i),
|
|
58
58
|
...n
|
|
59
59
|
};
|
|
60
|
-
return e.insert(t.tableName,
|
|
61
|
-
},
|
|
60
|
+
return e.insert(t.tableName, A(t, a));
|
|
61
|
+
}, M = (e, t) => typeof e == "function" ? e(t) : e ?? {}, Ne = (e, t = {}) => {
|
|
62
62
|
let n = t.traits ?? {}, r = t.associations ?? {}, i = (t) => {
|
|
63
63
|
let a = (e = {}) => ({
|
|
64
|
-
...
|
|
64
|
+
...Ae(t),
|
|
65
65
|
...e
|
|
66
|
-
}), o = (t = {}) =>
|
|
66
|
+
}), o = (t = {}) => A(e, a(t));
|
|
67
67
|
return {
|
|
68
68
|
table: e,
|
|
69
69
|
build: o,
|
|
70
|
-
buildList: (e, t) => Array.from({ length: e }, (e, n) => o(
|
|
71
|
-
create: (t, n = {}) =>
|
|
70
|
+
buildList: (e, t) => Array.from({ length: e }, (e, n) => o(M(t, n))),
|
|
71
|
+
create: (t, n = {}) => j(t, e, a(n), r, [e.tableName]),
|
|
72
72
|
createList: async (t, n, i) => {
|
|
73
73
|
let o = [];
|
|
74
|
-
for (let s = 0; s < n; s++) o.push(await
|
|
74
|
+
for (let s = 0; s < n; s++) o.push(await j(t, e, a(M(i, s)), r, [e.tableName]));
|
|
75
75
|
return o;
|
|
76
76
|
},
|
|
77
77
|
with: (...r) => {
|
|
@@ -93,19 +93,19 @@ var Ae = new Set(e), T = 0, E = () => ++T, je = (e, t) => {
|
|
|
93
93
|
};
|
|
94
94
|
};
|
|
95
95
|
return i(t.defaults ?? {});
|
|
96
|
-
},
|
|
96
|
+
}, N = Symbol.for("voltro/testing/mockClock.installed"), P = () => globalThis, Pe = (e, t) => new Proxy(e, {
|
|
97
97
|
construct: (e, n, r) => Reflect.construct(e, n.length === 0 ? [t()] : n, r),
|
|
98
98
|
apply: () => new e(t()).toString(),
|
|
99
99
|
get: (e, n, r) => n === "now" ? () => t() : Reflect.get(e, n, r)
|
|
100
|
-
}),
|
|
100
|
+
}), F = (e) => {
|
|
101
101
|
if (typeof e == "number") return e;
|
|
102
102
|
let t = e instanceof Date ? e.getTime() : Date.parse(e);
|
|
103
103
|
if (Number.isNaN(t)) throw Error(`mockClock: cannot read an instant from '${String(e)}'`);
|
|
104
104
|
return t;
|
|
105
|
-
},
|
|
105
|
+
}, I = class {
|
|
106
106
|
currentMs;
|
|
107
107
|
constructor(e = "2026-01-01T00:00:00Z") {
|
|
108
|
-
this.currentMs =
|
|
108
|
+
this.currentMs = F(e);
|
|
109
109
|
}
|
|
110
110
|
now() {
|
|
111
111
|
return this.currentMs;
|
|
@@ -114,47 +114,47 @@ var Ae = new Set(e), T = 0, E = () => ++T, je = (e, t) => {
|
|
|
114
114
|
return new Date(this.currentMs);
|
|
115
115
|
}
|
|
116
116
|
advance(e) {
|
|
117
|
-
this.currentMs += typeof e == "number" ? e :
|
|
117
|
+
this.currentMs += typeof e == "number" ? e : Re(e);
|
|
118
118
|
}
|
|
119
119
|
set(e) {
|
|
120
|
-
this.currentMs =
|
|
120
|
+
this.currentMs = F(e);
|
|
121
121
|
}
|
|
122
122
|
get installed() {
|
|
123
|
-
return
|
|
123
|
+
return P()[N]?.clock === this;
|
|
124
124
|
}
|
|
125
125
|
install() {
|
|
126
|
-
let e =
|
|
126
|
+
let e = P(), t = e[N];
|
|
127
127
|
if (t !== void 0) throw Error("mockClock: global time is already faked" + (t.clock === this ? " by this same clock" : " by another MockClock") + ". Uninstall it before installing again — a nested install restores the outer fake on the way out, which leaves the realm frozen with nothing pointing at why. `withFrozenTime` always restores, including on a throw.");
|
|
128
128
|
let n = globalThis.Date;
|
|
129
|
-
return e[
|
|
129
|
+
return e[N] = {
|
|
130
130
|
realDate: n,
|
|
131
131
|
clock: this
|
|
132
|
-
}, globalThis.Date =
|
|
132
|
+
}, globalThis.Date = Pe(n, () => this.currentMs), () => {
|
|
133
133
|
this.uninstall();
|
|
134
134
|
};
|
|
135
135
|
}
|
|
136
136
|
uninstall() {
|
|
137
|
-
let e =
|
|
138
|
-
t !== void 0 && t.clock === this && (globalThis.Date = t.realDate, delete e[
|
|
137
|
+
let e = P(), t = e[N];
|
|
138
|
+
t !== void 0 && t.clock === this && (globalThis.Date = t.realDate, delete e[N]);
|
|
139
139
|
}
|
|
140
|
-
},
|
|
141
|
-
let n = e instanceof
|
|
140
|
+
}, Fe = (e) => typeof e == "object" && !!e && typeof e.then == "function", Ie = (e, t) => {
|
|
141
|
+
let n = e instanceof I ? e : new I(e);
|
|
142
142
|
n.install();
|
|
143
143
|
let r = !1;
|
|
144
144
|
try {
|
|
145
145
|
let e = t(n);
|
|
146
|
-
return
|
|
146
|
+
return Fe(e) ? (r = !0, e.then((e) => (n.uninstall(), e), (e) => {
|
|
147
147
|
throw n.uninstall(), e;
|
|
148
148
|
})) : e;
|
|
149
149
|
} finally {
|
|
150
150
|
r || n.uninstall();
|
|
151
151
|
}
|
|
152
|
-
},
|
|
153
|
-
let t = e instanceof
|
|
152
|
+
}, Le = (e) => u.acquireRelease(u.sync(() => {
|
|
153
|
+
let t = e instanceof I ? e : new I(e);
|
|
154
154
|
return t.install(), t;
|
|
155
155
|
}), (e) => u.sync(() => {
|
|
156
156
|
e.uninstall();
|
|
157
|
-
})),
|
|
157
|
+
})), Re = (e) => {
|
|
158
158
|
let t = /^\s*(\d+(?:\.\d+)?)\s*(ms|s|m|h|d)\s*$/.exec(e);
|
|
159
159
|
if (!t) throw Error(`mockClock: cannot parse duration '${e}'`);
|
|
160
160
|
let n = Number(t[1]), r = t[2];
|
|
@@ -166,7 +166,7 @@ var Ae = new Set(e), T = 0, E = () => ++T, je = (e, t) => {
|
|
|
166
166
|
case "d": return n * 864e5;
|
|
167
167
|
default: throw Error(`mockClock: unknown unit '${r}'`);
|
|
168
168
|
}
|
|
169
|
-
},
|
|
169
|
+
}, L = class {
|
|
170
170
|
emitted = [];
|
|
171
171
|
async emit(e, t) {
|
|
172
172
|
let n = typeof e == "string" ? e : e.id ?? e.event ?? "(unnamed event)";
|
|
@@ -185,14 +185,14 @@ var Ae = new Set(e), T = 0, E = () => ++T, je = (e, t) => {
|
|
|
185
185
|
clear() {
|
|
186
186
|
this.emitted.length = 0;
|
|
187
187
|
}
|
|
188
|
-
},
|
|
188
|
+
}, R = (e = {}) => {
|
|
189
189
|
let t = e.tenantId ?? null, n = new x({
|
|
190
190
|
origin: e.origin ?? "test",
|
|
191
191
|
...e.ringSize === void 0 ? {} : { ringSize: e.ringSize }
|
|
192
192
|
});
|
|
193
193
|
return {
|
|
194
194
|
publish: async (e, r, i) => {
|
|
195
|
-
let a = await u.runPromise(u.either(
|
|
195
|
+
let a = await u.runPromise(u.either(pe({
|
|
196
196
|
bus: n,
|
|
197
197
|
tenantId: t
|
|
198
198
|
}, e, r, i)));
|
|
@@ -255,7 +255,7 @@ var Ae = new Set(e), T = 0, E = () => ++T, je = (e, t) => {
|
|
|
255
255
|
n.clear();
|
|
256
256
|
}
|
|
257
257
|
};
|
|
258
|
-
},
|
|
258
|
+
}, z = class {
|
|
259
259
|
queue;
|
|
260
260
|
calls = [];
|
|
261
261
|
constructor(e) {
|
|
@@ -270,38 +270,38 @@ var Ae = new Set(e), T = 0, E = () => ++T, je = (e, t) => {
|
|
|
270
270
|
remaining() {
|
|
271
271
|
return this.queue.length;
|
|
272
272
|
}
|
|
273
|
-
},
|
|
274
|
-
let n =
|
|
273
|
+
}, ze = (e) => e, B = "00000000000000000000000000000000", V = /* @__PURE__ */ new WeakMap(), H = /* @__PURE__ */ new WeakMap(), Be = (e, t) => {
|
|
274
|
+
let n = H.get(e);
|
|
275
275
|
if (n === void 0) throw Error("withRpcConnection requires a context created by makeTestContext");
|
|
276
276
|
return n(t);
|
|
277
|
-
},
|
|
278
|
-
|
|
279
|
-
},
|
|
280
|
-
let n =
|
|
277
|
+
}, U = /* @__PURE__ */ new WeakMap(), W = /* @__PURE__ */ new WeakMap(), G = /* @__PURE__ */ new WeakMap(), K = (e) => G.get(e) ?? [], q = /* @__PURE__ */ new WeakMap(), J = (e, t) => {
|
|
278
|
+
q.set(e, { publicApi: t });
|
|
279
|
+
}, Y = (e) => q.get(e), X = /* @__PURE__ */ new WeakMap(), Ve = (e, t) => {
|
|
280
|
+
let n = G.get(e) ?? [], r = t === "mutation" ? "interceptMutation" : t === "query" ? "interceptQuery" : "interceptAction", i = [];
|
|
281
281
|
for (let e of n) {
|
|
282
282
|
let t = e[r];
|
|
283
283
|
typeof t == "function" && i.push(t);
|
|
284
284
|
}
|
|
285
285
|
return v(i);
|
|
286
|
-
},
|
|
287
|
-
let t = (
|
|
286
|
+
}, He = (e) => {
|
|
287
|
+
let t = (G.get(e) ?? []).map((e) => e.services).filter((e) => e !== void 0), n = X.get(e) ?? [], r = [...t, ...n];
|
|
288
288
|
if (r.length !== 0) return f.mergeAll(...r);
|
|
289
|
-
},
|
|
290
|
-
let t =
|
|
289
|
+
}, Ue = (e) => {
|
|
290
|
+
let t = U.get(e);
|
|
291
291
|
t !== void 0 && (t.length = 0);
|
|
292
|
-
},
|
|
293
|
-
let t =
|
|
292
|
+
}, Z = async (e) => {
|
|
293
|
+
let t = U.get(e);
|
|
294
294
|
if (t === void 0 || t.length === 0) return;
|
|
295
295
|
let n = [...t];
|
|
296
296
|
t.length = 0;
|
|
297
297
|
for (let e of n) await e();
|
|
298
|
-
}, We = (e) =>
|
|
299
|
-
let n =
|
|
298
|
+
}, We = (e) => W.get(e) ?? [], Ge = async (e, t) => {
|
|
299
|
+
let n = V.get(e);
|
|
300
300
|
return n === void 0 ? e.store.transactional(async (n) => t({
|
|
301
301
|
...e,
|
|
302
302
|
store: n
|
|
303
303
|
})) : n(t);
|
|
304
|
-
},
|
|
304
|
+
}, Ke = (e) => {
|
|
305
305
|
let t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(), r = (n) => {
|
|
306
306
|
let r = t.get(n);
|
|
307
307
|
return r === void 0 ? !1 : r.expiresAt !== null && r.expiresAt <= e() ? (t.delete(n), !1) : !0;
|
|
@@ -340,7 +340,7 @@ var Ae = new Set(e), T = 0, E = () => ++T, je = (e, t) => {
|
|
|
340
340
|
return i(e, o, n.ttlMs, n.tags), o;
|
|
341
341
|
}
|
|
342
342
|
};
|
|
343
|
-
},
|
|
343
|
+
}, qe = (e) => {
|
|
344
344
|
let t = /* @__PURE__ */ new Map(), n = (n) => {
|
|
345
345
|
let r = t.get(n);
|
|
346
346
|
return r === void 0 ? !1 : r.expiresAt !== null && r.expiresAt <= e() ? (t.delete(n), !1) : !0;
|
|
@@ -368,131 +368,144 @@ var Ae = new Set(e), T = 0, E = () => ++T, je = (e, t) => {
|
|
|
368
368
|
t.clear();
|
|
369
369
|
}
|
|
370
370
|
};
|
|
371
|
-
},
|
|
372
|
-
let n =
|
|
373
|
-
|
|
371
|
+
}, Je = async (e, t) => {
|
|
372
|
+
let n = ie();
|
|
373
|
+
E(e);
|
|
374
374
|
try {
|
|
375
375
|
return await t();
|
|
376
376
|
} finally {
|
|
377
|
-
n === void 0 ?
|
|
377
|
+
n === void 0 ? re() : E(n);
|
|
378
378
|
}
|
|
379
|
-
},
|
|
380
|
-
|
|
381
|
-
},
|
|
382
|
-
let r =
|
|
379
|
+
}, Ye = /* @__PURE__ */ new Set(), Xe = (e) => {
|
|
380
|
+
Ye.has(e) || (Ye.add(e), console.warn(e));
|
|
381
|
+
}, Ze = (e, t, n) => {
|
|
382
|
+
let r = Qe, i;
|
|
383
383
|
return () => {
|
|
384
|
-
let a = t ??
|
|
385
|
-
return t !== void 0 &&
|
|
384
|
+
let a = t ?? w();
|
|
385
|
+
return t !== void 0 && w() !== void 0 && t !== w() && Xe("[voltro:testing] this test passes `rowFilter:` while a DIFFERENT filter is registered via `setRowFilter`. The option wins, so this test does not exercise your app's registration. Drop `rowFilter:` to run the real process-global one."), (i === void 0 || a !== r) && (r = a, i = Je(n, () => T(me(a, e, (e) => {
|
|
386
386
|
console.error("[voltro:testing] row filter failed to load — reads refused for this subject", e);
|
|
387
387
|
})))), i;
|
|
388
388
|
};
|
|
389
|
-
},
|
|
390
|
-
if (n === "query") return async (n) => e.query(
|
|
389
|
+
}, Qe = Symbol("unresolved"), $e = (e, t) => new Proxy(e, { get: (e, n) => {
|
|
390
|
+
if (n === "query") return async (n) => e.query(ne(await t(), n));
|
|
391
391
|
let r = Reflect.get(e, n, e);
|
|
392
392
|
return typeof r == "function" ? r.bind(e) : r;
|
|
393
|
-
} }),
|
|
394
|
-
if (
|
|
393
|
+
} }), et = (e = {}) => {
|
|
394
|
+
if (ve({
|
|
395
395
|
...process.env,
|
|
396
396
|
...e.env ?? {}
|
|
397
|
-
}), e.fieldEncryptionKey !== void 0 &&
|
|
397
|
+
}), e.fieldEncryptionKey !== void 0 && _e(ue(e.fieldEncryptionKey)), e.relations !== void 0) {
|
|
398
398
|
o();
|
|
399
399
|
for (let t of e.relations) c(t);
|
|
400
400
|
}
|
|
401
|
-
let n = e.tables ?? t(), r =
|
|
401
|
+
let n = e.tables ?? t(), r = fe(n), i = new S(e.store ?? {}), a = {
|
|
402
402
|
dataStore: i,
|
|
403
403
|
schemaRegistry: r
|
|
404
404
|
};
|
|
405
|
-
|
|
406
|
-
let s = new
|
|
407
|
-
let
|
|
405
|
+
E(a);
|
|
406
|
+
let s = new I(e.clockStart), l = new L(), u = R(), d = new z(e.llmResponses ?? []), f = Ke(() => s.now()), p = qe(() => s.now()), m = (t, n, o = i, c, h = !1) => {
|
|
407
|
+
let g = {
|
|
408
408
|
subject: t,
|
|
409
|
-
traceId:
|
|
409
|
+
traceId: B,
|
|
410
410
|
...n === void 0 ? {} : { connection: n }
|
|
411
|
-
},
|
|
411
|
+
}, _ = c?.queued ?? [], v = c?.nudges ?? [], y = le({
|
|
412
412
|
bus: u.bus,
|
|
413
413
|
tenantId: t.tenantId ?? null,
|
|
414
414
|
...o === i ? {} : { deferToCommit: (e) => {
|
|
415
|
-
|
|
415
|
+
_.push(async () => {
|
|
416
416
|
e();
|
|
417
417
|
});
|
|
418
418
|
} }
|
|
419
|
-
}),
|
|
419
|
+
}), b = se({ store: o }), x = h ? async () => C : Ze(t, e.rowFilter, a), S = {
|
|
420
|
+
transaction: async (e, r) => {
|
|
421
|
+
let a = he(t, r?.tenantId, o !== i);
|
|
422
|
+
if (a !== t) return m(a, n, i, void 0, !0).transaction(e);
|
|
423
|
+
if (o !== i) return e(S);
|
|
424
|
+
let s, c = await o.transactional(async (r) => {
|
|
425
|
+
let i = m(t, n, r, {
|
|
426
|
+
queued: [],
|
|
427
|
+
nudges: []
|
|
428
|
+
}, h), a = await e(i);
|
|
429
|
+
return s = i, a;
|
|
430
|
+
});
|
|
431
|
+
return s !== void 0 && (await Z(s), v.push(...We(s))), c;
|
|
432
|
+
},
|
|
420
433
|
clock: s,
|
|
421
434
|
webhooks: l,
|
|
422
|
-
events:
|
|
435
|
+
events: y,
|
|
423
436
|
eventBus: u,
|
|
424
437
|
llm: d,
|
|
425
438
|
...e.ai === void 0 ? {} : { ai: e.ai },
|
|
426
|
-
request:
|
|
427
|
-
...n === void 0 ? {} : { connectionState:
|
|
428
|
-
|
|
439
|
+
request: g,
|
|
440
|
+
...n === void 0 ? {} : { connectionState: oe(n, o === i ? void 0 : (e) => {
|
|
441
|
+
_.push(e);
|
|
429
442
|
}) },
|
|
430
|
-
validation:
|
|
431
|
-
access:
|
|
443
|
+
validation: te,
|
|
444
|
+
access: ae(t),
|
|
432
445
|
cache: f,
|
|
433
446
|
kv: p,
|
|
434
|
-
store:
|
|
447
|
+
store: D($e(o, x), {
|
|
435
448
|
subject: t,
|
|
436
449
|
schemaRegistry: r,
|
|
437
|
-
rowFilter:
|
|
450
|
+
rowFilter: C
|
|
438
451
|
}),
|
|
439
|
-
storeForTenant: (e) =>
|
|
452
|
+
storeForTenant: (e) => D($e(o, x), {
|
|
440
453
|
subject: ee(t, e),
|
|
441
454
|
schemaRegistry: r,
|
|
442
|
-
rowFilter:
|
|
455
|
+
rowFilter: C
|
|
443
456
|
}),
|
|
444
|
-
outbox:
|
|
457
|
+
outbox: de({
|
|
445
458
|
store: o,
|
|
446
459
|
subject: t,
|
|
447
|
-
traceId:
|
|
460
|
+
traceId: B,
|
|
448
461
|
nudge: () => {
|
|
449
|
-
|
|
462
|
+
v.push(B);
|
|
450
463
|
},
|
|
451
464
|
afterCommit: (e) => {
|
|
452
|
-
|
|
465
|
+
_.push(e);
|
|
453
466
|
}
|
|
454
467
|
}),
|
|
455
|
-
load:
|
|
456
|
-
loadMany:
|
|
468
|
+
load: b.load,
|
|
469
|
+
loadMany: b.loadMany,
|
|
457
470
|
withSubject: (e, t) => Promise.resolve(t(m(e, n, o, {
|
|
458
|
-
queued:
|
|
459
|
-
nudges:
|
|
471
|
+
queued: _,
|
|
472
|
+
nudges: v
|
|
460
473
|
}))),
|
|
461
474
|
withTenant: (e, r) => Promise.resolve(r(m({
|
|
462
475
|
...t,
|
|
463
476
|
tenantId: e
|
|
464
477
|
}, n, o, {
|
|
465
|
-
queued:
|
|
466
|
-
nudges:
|
|
478
|
+
queued: _,
|
|
479
|
+
nudges: v
|
|
467
480
|
}))),
|
|
468
481
|
asSubject: (e) => m(e, n, o, {
|
|
469
|
-
queued:
|
|
470
|
-
nudges:
|
|
482
|
+
queued: _,
|
|
483
|
+
nudges: v
|
|
471
484
|
}),
|
|
472
485
|
asTenant: (e) => m({
|
|
473
486
|
...t,
|
|
474
487
|
tenantId: e
|
|
475
488
|
}, n, o, {
|
|
476
|
-
queued:
|
|
477
|
-
nudges:
|
|
489
|
+
queued: _,
|
|
490
|
+
nudges: v
|
|
478
491
|
})
|
|
479
492
|
};
|
|
480
|
-
return
|
|
481
|
-
queued:
|
|
482
|
-
nudges:
|
|
483
|
-
})),
|
|
484
|
-
queued:
|
|
485
|
-
nudges:
|
|
486
|
-
})))),
|
|
493
|
+
return U.set(S, _), H.set(S, (e) => m(t, e, o, {
|
|
494
|
+
queued: _,
|
|
495
|
+
nudges: v
|
|
496
|
+
})), W.set(S, v), G.set(S, e.plugins ?? []), X.set(S, e.layers ?? []), V.set(S, (e) => o.transactional((r) => e(m(t, n, r, {
|
|
497
|
+
queued: _,
|
|
498
|
+
nudges: v
|
|
499
|
+
})))), S;
|
|
487
500
|
};
|
|
488
501
|
return m(e.subject ?? h(null), e.connection);
|
|
489
|
-
},
|
|
490
|
-
let n =
|
|
491
|
-
return (n === void 0 ? e : u.provide(e, n)).pipe(u.provide(
|
|
492
|
-
},
|
|
502
|
+
}, tt = (e, t) => {
|
|
503
|
+
let n = He(t);
|
|
504
|
+
return (n === void 0 ? e : u.provide(e, n)).pipe(u.provide(ce(t.store)), u.provideService(m, t.request.subject));
|
|
505
|
+
}, nt = async (e, t, n, r) => {
|
|
493
506
|
let i = e.input, a = await p.decodeUnknownPromise(i)(n), o = e.kind, s = async (e) => {
|
|
494
507
|
let n = t(a, e);
|
|
495
|
-
return u.isEffect(n) ?
|
|
508
|
+
return u.isEffect(n) ? T(tt(n, e)) : n;
|
|
496
509
|
}, c = async () => {
|
|
497
510
|
let t = e.guards;
|
|
498
511
|
if (t !== void 0 && t.length > 0) {
|
|
@@ -500,14 +513,14 @@ var Ae = new Set(e), T = 0, E = () => ++T, je = (e, t) => {
|
|
|
500
513
|
if (e !== null) throw e;
|
|
501
514
|
}
|
|
502
515
|
if (o !== "mutation") return s(r);
|
|
503
|
-
let n = await
|
|
504
|
-
return await
|
|
505
|
-
}, f = o === "mutation" || o === "query" || o === "action" ? o : void 0, m = f === void 0 ? void 0 :
|
|
516
|
+
let n = await ge(async () => Ge(r, async (e) => (Ue(r), s(e))), { delay: () => Promise.resolve() });
|
|
517
|
+
return await Z(r), n;
|
|
518
|
+
}, f = o === "mutation" || o === "query" || o === "action" ? o : void 0, m = f === void 0 ? void 0 : Ve(r, f);
|
|
506
519
|
if (m === void 0 || f === void 0) return await c();
|
|
507
520
|
let h = u.tryPromise({
|
|
508
521
|
try: () => c(),
|
|
509
522
|
catch: (e) => e
|
|
510
|
-
}), _ =
|
|
523
|
+
}), _ = Y(r), v = m(h, {
|
|
511
524
|
tag: e.name ?? "",
|
|
512
525
|
kind: f,
|
|
513
526
|
input: a,
|
|
@@ -521,12 +534,12 @@ var Ae = new Set(e), T = 0, E = () => ++T, je = (e, t) => {
|
|
|
521
534
|
}), y = await u.runPromiseExit(v);
|
|
522
535
|
if (d.isSuccess(y)) return y.value;
|
|
523
536
|
throw l.squash(y.cause);
|
|
524
|
-
},
|
|
525
|
-
let n = new
|
|
537
|
+
}, rt = (e) => new Promise((t) => {
|
|
538
|
+
let n = new ye.Socket(), r = (e) => {
|
|
526
539
|
clearTimeout(i), n.destroy(), t(e);
|
|
527
540
|
}, i = setTimeout(() => r(!1), e.timeoutMs ?? 750);
|
|
528
541
|
n.once("connect", () => r(!0)), n.once("error", () => r(!1)), n.connect(e.port, e.host);
|
|
529
|
-
}),
|
|
542
|
+
}), it = async (e, t, n, r) => {
|
|
530
543
|
if (typeof t != "string" || typeof n != "function" || typeof r != "function") throw TypeError(`describeIfAvailable('${e}', ...): expected (label, dependency, probe, suite) — got dependency: ${typeof t}, probe: ${typeof n}, suite: ${typeof r}. Three arguments means the suite body is being used as the probe: it would run at file scope, unconditionally, and the skip would silently do nothing.`);
|
|
531
544
|
let i = !1;
|
|
532
545
|
try {
|
|
@@ -534,21 +547,21 @@ var Ae = new Set(e), T = 0, E = () => ++T, je = (e, t) => {
|
|
|
534
547
|
} catch {
|
|
535
548
|
i = !1;
|
|
536
549
|
}
|
|
537
|
-
|
|
538
|
-
},
|
|
539
|
-
await
|
|
540
|
-
},
|
|
550
|
+
be.skipIf(!i)(i ? e : `${e} [SKIPPED: needs ${t}]`, r);
|
|
551
|
+
}, at = async (e, t, n) => {
|
|
552
|
+
await it(e, `${t.name} at ${t.host}:${t.port}`, () => rt(t), n);
|
|
553
|
+
}, ot = async (e, t) => {
|
|
541
554
|
try {
|
|
542
555
|
let n = await t();
|
|
543
556
|
n !== void 0 && n !== "" && console.log(`[engine] ${e}: ${n}`);
|
|
544
557
|
} catch {}
|
|
545
|
-
},
|
|
558
|
+
}, st = "test-tenant", Q = (e, t, n) => ({
|
|
546
559
|
type: e,
|
|
547
560
|
id: t,
|
|
548
561
|
tenantId: n.tenantId ?? "test-tenant",
|
|
549
562
|
scopes: n.scopes ?? [],
|
|
550
563
|
...n.metadata === void 0 ? {} : { metadata: n.metadata }
|
|
551
|
-
}),
|
|
564
|
+
}), ct = (e, t = {}) => Q("user", e, t), lt = (e, t = {}) => Q("apiKey", e, t), ut = (e, t = {}) => Q("serviceAccount", e, t), dt = (e = null) => h(e), ft = (e = "job:test", t) => t === void 0 ? b(e) : b(e, t), pt = (e) => {
|
|
552
565
|
let t = e.indexOf("?");
|
|
553
566
|
return t === -1 ? {
|
|
554
567
|
path: e,
|
|
@@ -557,19 +570,19 @@ var Ae = new Set(e), T = 0, E = () => ++T, je = (e, t) => {
|
|
|
557
570
|
path: e.slice(0, t),
|
|
558
571
|
query: e.slice(t + 1)
|
|
559
572
|
};
|
|
560
|
-
},
|
|
573
|
+
}, mt = (e, t) => {
|
|
561
574
|
let n = e.split("/").filter((e) => e.length > 0), r = t.split("/").filter((e) => e.length > 0);
|
|
562
575
|
return n.length === r.length && n.every((e, t) => e.startsWith(":") || e === r[t]);
|
|
563
|
-
},
|
|
576
|
+
}, $ = (e) => {
|
|
564
577
|
let t = {};
|
|
565
578
|
for (let [n, r] of Object.entries(e)) t[n.toLowerCase()] = r;
|
|
566
579
|
return t;
|
|
567
|
-
},
|
|
568
|
-
let { ctx: t } = e, n =
|
|
580
|
+
}, ht = (e) => e === void 0 ? /* @__PURE__ */ new Uint8Array() : new TextEncoder().encode(JSON.stringify(e)), gt = (e) => e === void 0 ? "" : typeof e == "string" ? e : new TextDecoder().decode(e), _t = (e) => {
|
|
581
|
+
let { ctx: t } = e, n = xe((e.publicApi ?? []).map((e) => ({
|
|
569
582
|
descriptor: e.descriptor,
|
|
570
|
-
invoke: (n, r) => t.withSubject(r.subject, (t) => (e.descriptor.publicApi !== void 0 &&
|
|
583
|
+
invoke: (n, r) => t.withSubject(r.subject, (t) => (e.descriptor.publicApi !== void 0 && J(t, e.descriptor.publicApi), nt(e.descriptor, e.handler, n, t)))
|
|
571
584
|
})), {
|
|
572
|
-
pluginErrors:
|
|
585
|
+
pluginErrors: K(t).flatMap((e) => e.errorSchemas ?? []),
|
|
573
586
|
...e.publicApiProfile === void 0 ? {} : { profile: e.publicApiProfile }
|
|
574
587
|
}), r = [...e.restRoutes ?? [], ...n], i = _(e.strategies ?? [], {
|
|
575
588
|
...e.anonymousTenantRequired === void 0 ? {} : { anonymousTenantRequired: e.anonymousTenantRequired },
|
|
@@ -583,11 +596,11 @@ var Ae = new Set(e), T = 0, E = () => ++T, je = (e, t) => {
|
|
|
583
596
|
clientId: -1
|
|
584
597
|
})).subject : () => n,
|
|
585
598
|
...e.idempotency === void 0 ? {} : { idempotency: e.idempotency }
|
|
586
|
-
}, c =
|
|
599
|
+
}, c = Ce(r, s).map((e, t) => ({
|
|
587
600
|
pattern: r[t].path,
|
|
588
601
|
route: e
|
|
589
602
|
})), l = async (e, n, i = {}) => {
|
|
590
|
-
let { path: a, query: s } =
|
|
603
|
+
let { path: a, query: s } = pt(n), l = c.filter((e) => mt(e.pattern, a)).map((e) => e.route);
|
|
591
604
|
if (l.length === 0) return {
|
|
592
605
|
status: 404,
|
|
593
606
|
headers: {},
|
|
@@ -603,15 +616,15 @@ var Ae = new Set(e), T = 0, E = () => ++T, je = (e, t) => {
|
|
|
603
616
|
path: a,
|
|
604
617
|
query: s,
|
|
605
618
|
headers: {
|
|
606
|
-
|
|
607
|
-
|
|
619
|
+
...$(o),
|
|
620
|
+
...$(i.headers ?? {})
|
|
608
621
|
},
|
|
609
|
-
rawBody:
|
|
622
|
+
rawBody: ht(i.body),
|
|
610
623
|
store: t.store
|
|
611
|
-
}, d = await
|
|
624
|
+
}, d = await Se(l, u), f = {};
|
|
612
625
|
for (let [e, t] of Object.entries(d.headers ?? {})) f[e.toLowerCase()] = t;
|
|
613
626
|
d.contentType !== void 0 && (f["content-type"] = d.contentType);
|
|
614
|
-
let p =
|
|
627
|
+
let p = gt(d.body), m = (d.contentType ?? "").includes("json");
|
|
615
628
|
return {
|
|
616
629
|
status: d.status,
|
|
617
630
|
headers: f,
|
|
@@ -645,17 +658,17 @@ var Ae = new Set(e), T = 0, E = () => ++T, je = (e, t) => {
|
|
|
645
658
|
};
|
|
646
659
|
};
|
|
647
660
|
return a(void 0, {});
|
|
648
|
-
},
|
|
661
|
+
}, vt = (e = {}) => {
|
|
649
662
|
let t = e.id ?? "test", n = e.store ?? new Proxy({}, { get: (e, t) => {
|
|
650
663
|
throw Error(`makeSubscribeContext: this subscriber reached ctx.store.${String(t)} and the test passed no store. Pass \`{ store: makeTestContext().store }\` so the subscriber and the code under test share one — an empty stand-in would let a read of the wrong table pass.`);
|
|
651
664
|
} });
|
|
652
665
|
return {
|
|
653
666
|
id: t,
|
|
654
|
-
log: e.log ??
|
|
667
|
+
log: e.log ?? we({ scope: `subscribe:${t}` }),
|
|
655
668
|
store: n,
|
|
656
669
|
...e.publish === void 0 ? {} : { publish: e.publish }
|
|
657
670
|
};
|
|
658
|
-
},
|
|
671
|
+
}, yt = (e) => {
|
|
659
672
|
let t = /* @__PURE__ */ new Map();
|
|
660
673
|
for (let n of e) {
|
|
661
674
|
let e = t.get(n.stepName);
|
|
@@ -681,13 +694,13 @@ var Ae = new Set(e), T = 0, E = () => ++T, je = (e, t) => {
|
|
|
681
694
|
});
|
|
682
695
|
}
|
|
683
696
|
return n.sort((e, t) => e._startedAt - t._startedAt), n.map(({ _startedAt: e, ...t }) => t);
|
|
684
|
-
},
|
|
697
|
+
}, bt = (e) => {
|
|
685
698
|
let t = e.workflows ?? [], n = /* @__PURE__ */ new Map(), r = 0;
|
|
686
699
|
return {
|
|
687
700
|
start: async (i, a) => {
|
|
688
701
|
let o = t.find((e) => e.workflow.name === i);
|
|
689
702
|
if (o === void 0) throw Error(`makeWorkflowRunner: no workflow named '${i}' — pass it in makeWorkflowRunner({ ctx, workflows: [{ workflow, execute }] }).`);
|
|
690
|
-
let s = `wfrun_test_${++r}`, c =
|
|
703
|
+
let s = `wfrun_test_${++r}`, c = De(), l = o.workflow.toLayer(o.execute).pipe(f.provideMerge(Ee)), d = /* @__PURE__ */ new Date(), p = o.workflow.execute(a).pipe(u.locally(Te, s), u.provide(c.layer), u.provide(l), u.either), m = await u.runPromise(p), h = yt(c.readSteps()), g = /* @__PURE__ */ new Date(), _;
|
|
691
704
|
if (m._tag === "Right") _ = {
|
|
692
705
|
status: "succeeded",
|
|
693
706
|
output: m.right,
|
|
@@ -727,6 +740,6 @@ var Ae = new Set(e), T = 0, E = () => ++T, je = (e, t) => {
|
|
|
727
740
|
},
|
|
728
741
|
inspect: async (e) => n.get(e) ?? null
|
|
729
742
|
};
|
|
730
|
-
},
|
|
743
|
+
}, xt = 1;
|
|
731
744
|
//#endregion
|
|
732
|
-
export {
|
|
745
|
+
export { I as MockClock, z as MockLLM, L as MockWebhooks, xt as TESTING_PRESET_VERSION, st as TEST_TENANT_ID, dt as anonymous, lt as apiKey, n as changeDelete, r as changeInsert, i as changeSoftDelete, a as changeUpdate, Ne as defineFactory, it as describeIfAvailable, at as describeIfReachable, A as fixtureRow, Le as frozenTime, nt as invoke, rt as isTcpReachable, vt as makeSubscribeContext, _t as makeTestApp, et as makeTestContext, bt as makeWorkflowRunner, J as markRestInvocation, ze as mockStore, k as nextSequence, We as outboxNudgesOf, K as pluginsOf, ot as reportEngineVersion, Ue as resetAfterCommit, Y as restInvocationOf, Ve as rpcInterceptorFor, Z as runAfterCommit, Ge as runInStoreTransaction, ut as serviceAccount, He as serviceLayerFor, ft as system, R as testEventBus, ct as user, Ie as withFrozenTime, Be as withRpcConnection };
|