@tailor-platform/sdk 1.46.0 → 1.47.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 (64) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/dist/{actor-BmxQeMFP.d.mts → actor-DhXSqWTW.d.mts} +2 -2
  3. package/dist/application-CN9Htzup.mjs +4 -0
  4. package/dist/{application-B4zVVNRS.mjs → application-TasSqBTD.mjs} +22 -41
  5. package/dist/application-TasSqBTD.mjs.map +1 -0
  6. package/dist/cli/index.mjs +33 -15
  7. package/dist/cli/index.mjs.map +1 -1
  8. package/dist/cli/lib.d.mts +6 -6
  9. package/dist/cli/lib.mjs +3 -3
  10. package/dist/{client-BwXkoiMq.mjs → client-COfsXV69.mjs} +31 -120
  11. package/dist/client-COfsXV69.mjs.map +1 -0
  12. package/dist/{client-DTaArWQr.mjs → client-DYSkSLRr.mjs} +1 -1
  13. package/dist/configure/index.d.mts +4 -4
  14. package/dist/configure/index.mjs +4 -43
  15. package/dist/configure/index.mjs.map +1 -1
  16. package/dist/{crashreport-6mcMyWu4.mjs → crashreport-B8lVOx0U.mjs} +1 -1
  17. package/dist/{crashreport-DGeGj9BF.mjs → crashreport-CKJwnWsX.mjs} +2 -2
  18. package/dist/{crashreport-DGeGj9BF.mjs.map → crashreport-CKJwnWsX.mjs.map} +1 -1
  19. package/dist/{index-DV-5OIEv.d.mts → index-BRvNi5q9.d.mts} +2 -2
  20. package/dist/{index-BBvPd9Uv.d.mts → index-BXyS7xKC.d.mts} +2 -2
  21. package/dist/{index-Dxe6alSZ.d.mts → index-BbOTbZFf.d.mts} +2 -2
  22. package/dist/{index-PB0otrDj.d.mts → index-BoU_52Du.d.mts} +4 -4
  23. package/dist/{index-B5_4Tzm2.d.mts → index-iy-hNfGp.d.mts} +2 -2
  24. package/dist/{interceptor-CrcDfLPq.mjs → interceptor-CBsqEWDK.mjs} +1 -1
  25. package/dist/{interceptor-CrcDfLPq.mjs.map → interceptor-CBsqEWDK.mjs.map} +1 -1
  26. package/dist/mock-BP-9O5On.mjs +796 -0
  27. package/dist/mock-BP-9O5On.mjs.map +1 -0
  28. package/dist/plugin/builtin/enum-constants/index.d.mts +1 -1
  29. package/dist/plugin/builtin/file-utils/index.d.mts +1 -1
  30. package/dist/plugin/builtin/kysely-type/index.d.mts +1 -1
  31. package/dist/plugin/builtin/seed/index.d.mts +1 -1
  32. package/dist/plugin/index.d.mts +2 -2
  33. package/dist/{repl-editor-BlT2dFtm.mjs → repl-editor-CZpLlOBj.mjs} +1 -1
  34. package/dist/{repl-editor-BlT2dFtm.mjs.map → repl-editor-CZpLlOBj.mjs.map} +1 -1
  35. package/dist/{runtime-B67skpW-.mjs → runtime-DDYL2Zf1.mjs} +86 -8
  36. package/dist/runtime-DDYL2Zf1.mjs.map +1 -0
  37. package/dist/{service-CCgw66c6.mjs → service-obEU5gSM.mjs} +1 -1
  38. package/dist/{service-CCgw66c6.mjs.map → service-obEU5gSM.mjs.map} +1 -1
  39. package/dist/{tailor-db-field-Hx9OqPWY.d.mts → tailor-db-field-Bn8ZC5lK.d.mts} +1 -1
  40. package/dist/{schema-DBq6hr6h.mjs → tailordb-Bg9-TZj1.mjs} +42 -2
  41. package/dist/tailordb-Bg9-TZj1.mjs.map +1 -0
  42. package/dist/utils/test/index.d.mts +13 -4
  43. package/dist/utils/test/index.mjs +12 -3
  44. package/dist/utils/test/index.mjs.map +1 -1
  45. package/dist/vitest/environment.d.mts +12 -0
  46. package/dist/vitest/environment.mjs +44 -0
  47. package/dist/vitest/environment.mjs.map +1 -0
  48. package/dist/vitest/index.d.mts +345 -0
  49. package/dist/vitest/index.mjs +350 -0
  50. package/dist/vitest/index.mjs.map +1 -0
  51. package/dist/vitest/setup.d.mts +64 -0
  52. package/dist/vitest/setup.mjs +141 -0
  53. package/dist/vitest/setup.mjs.map +1 -0
  54. package/dist/{workflow.generated-DFljpJh7.d.mts → workflow.generated-i7PK4fg-.d.mts} +2 -2
  55. package/docs/cli/setup.md +1 -0
  56. package/docs/services/tailordb.md +43 -12
  57. package/docs/services/workflow.md +1 -1
  58. package/docs/testing.md +530 -243
  59. package/package.json +32 -6
  60. package/dist/application-B4zVVNRS.mjs.map +0 -1
  61. package/dist/application-Boa_11Nv.mjs +0 -4
  62. package/dist/client-BwXkoiMq.mjs.map +0 -1
  63. package/dist/runtime-B67skpW-.mjs.map +0 -1
  64. package/dist/schema-DBq6hr6h.mjs.map +0 -1
@@ -0,0 +1,796 @@
1
+
2
+ //#region src/vitest/mock.ts
3
+ const STATE_KEY = "__tailorMockState";
4
+ const RUNTIME_FLAG_KEY = "__tailorRuntimeActive";
5
+ function getState() {
6
+ const g = globalThis;
7
+ if (!g["__tailorMockState"]) g[STATE_KEY] = createDefaultState();
8
+ return g[STATE_KEY];
9
+ }
10
+ function createDefaultState() {
11
+ return {
12
+ queryResolver: () => [],
13
+ queryResultQueue: [],
14
+ executedQueries: [],
15
+ createdClients: [],
16
+ jobHandler: () => null,
17
+ jobResultQueue: [],
18
+ triggeredJobs: [],
19
+ triggerHandler: "mock-execution-id",
20
+ waitHandler: null,
21
+ resolveHandler: null,
22
+ workflowCalls: [],
23
+ secretStore: {},
24
+ secretCalls: [],
25
+ authTokens: {},
26
+ authCalls: [],
27
+ idpResolver: () => null,
28
+ idpResultQueue: [],
29
+ idpCalls: [],
30
+ fileResolver: () => null,
31
+ fileResultQueue: [],
32
+ fileCalls: [],
33
+ iconvResolver: null,
34
+ iconvCalls: []
35
+ };
36
+ }
37
+ /**
38
+ * Mock control object for TailorDB operations.
39
+ *
40
+ * Automatically injected into `globalThis.tailordb` by the tailor-runtime environment.
41
+ * Use this object to configure query responses and assert on executed queries.
42
+ * @example
43
+ * ```typescript
44
+ * import { tailordbMock } from "@tailor-platform/sdk/vitest";
45
+ *
46
+ * beforeEach(() => tailordbMock.reset());
47
+ *
48
+ * test("content-based", () => {
49
+ * tailordbMock.setQueryResolver((query) => {
50
+ * if (query.includes("SELECT")) return [{ id: "1" }];
51
+ * return [];
52
+ * });
53
+ * });
54
+ *
55
+ * test("order-based", () => {
56
+ * tailordbMock.enqueueResults(
57
+ * [], // BEGIN (empty result)
58
+ * [{ age: 30 }], // SELECT (one row)
59
+ * [], // COMMIT (empty result)
60
+ * );
61
+ * });
62
+ * ```
63
+ */
64
+ const tailordbMock = {
65
+ /**
66
+ * Set a fallback query resolver. Called when the result queue is empty.
67
+ * @param resolver - Function that returns rows for a given query and params
68
+ */
69
+ setQueryResolver(resolver) {
70
+ getState().queryResolver = resolver;
71
+ },
72
+ /**
73
+ * Enqueue rows for the next `queryObject` call. Arguments are the row objects returned
74
+ * by that single query. Call with no arguments for an empty result. Consumed in FIFO
75
+ * order; when the queue is exhausted, subsequent calls fall back to `setQueryResolver`
76
+ * (default: empty rows). Use `enqueueResults` to stage rows for multiple queries in one
77
+ * call.
78
+ * @param rows - Row objects to return from the next `queryObject` call
79
+ */
80
+ enqueueResult(...rows) {
81
+ getState().queryResultQueue.push(rows);
82
+ },
83
+ /**
84
+ * Enqueue rows for multiple subsequent `queryObject` calls. Each argument is a rows
85
+ * array for one query, consumed in FIFO order.
86
+ * @param rowsList - Rows arrays, one per upcoming query
87
+ */
88
+ enqueueResults(...rowsList) {
89
+ getState().queryResultQueue.push(...rowsList);
90
+ },
91
+ /**
92
+ * All queries executed via `queryObject`, in order.
93
+ * @returns Executed queries array
94
+ */
95
+ get executedQueries() {
96
+ return getState().executedQueries;
97
+ },
98
+ /**
99
+ * All TailorDB clients created, with their namespace and end state.
100
+ * @returns Created clients array
101
+ */
102
+ get createdClients() {
103
+ return getState().createdClients;
104
+ },
105
+ /** Reset all TailorDB mock state. Call in `beforeEach`. */
106
+ reset() {
107
+ const state = getState();
108
+ state.queryResolver = () => [];
109
+ state.queryResultQueue.length = 0;
110
+ state.executedQueries.length = 0;
111
+ state.createdClients.length = 0;
112
+ }
113
+ };
114
+ /**
115
+ * Mock control object for workflow operations.
116
+ *
117
+ * Automatically injected into `globalThis.tailor.workflow` by the tailor-runtime environment.
118
+ * @example
119
+ * ```typescript
120
+ * import { workflowMock } from "@tailor-platform/sdk/vitest";
121
+ *
122
+ * beforeEach(() => workflowMock.reset());
123
+ *
124
+ * test("job handler", () => {
125
+ * workflowMock.setJobHandler((jobName, args) => {
126
+ * if (jobName === "validate") return { valid: true };
127
+ * return null;
128
+ * });
129
+ * });
130
+ *
131
+ * test("wait point", () => {
132
+ * workflowMock.setWaitHandler(() => ({ approved: true }));
133
+ * // …
134
+ * expect(workflowMock.waitCalls).toEqual([{ key: "approval", payload: undefined }]);
135
+ * });
136
+ *
137
+ * test("resolve point", () => {
138
+ * workflowMock.setResolveHandler((_executionId, _key, callback) =>
139
+ * callback({ approved: true }),
140
+ * );
141
+ * // …
142
+ * expect(workflowMock.resolveCalls).toEqual([
143
+ * { executionId: "mock-execution-id", key: "approval" },
144
+ * ]);
145
+ * });
146
+ * ```
147
+ */
148
+ const workflowMock = {
149
+ /**
150
+ * Set a fallback job handler. Called when the result queue is empty.
151
+ * @param handler - Function that returns a result for a given job name and args
152
+ */
153
+ setJobHandler(handler) {
154
+ getState().jobHandler = handler;
155
+ },
156
+ /**
157
+ * Enqueue a single result for the next `triggerJobFunction` call. Consumed in FIFO
158
+ * order; when the queue is exhausted, subsequent calls fall back to `setJobHandler`
159
+ * (default: null). Use `enqueueResults` to stage multiple results in one call.
160
+ * @param result - Result to return from the next `triggerJobFunction` call
161
+ */
162
+ enqueueResult(result) {
163
+ getState().jobResultQueue.push(result);
164
+ },
165
+ /**
166
+ * Enqueue results for multiple subsequent `triggerJobFunction` calls.
167
+ * @param results - Results to enqueue, one per upcoming call
168
+ */
169
+ enqueueResults(...results) {
170
+ const queue = getState().jobResultQueue;
171
+ for (const result of results) queue.push(result);
172
+ },
173
+ /**
174
+ * All jobs triggered via `triggerJobFunction`, in order.
175
+ * @returns Triggered jobs array
176
+ */
177
+ get triggeredJobs() {
178
+ return getState().triggeredJobs;
179
+ },
180
+ /**
181
+ * Configure what `tailor.workflow.triggerWorkflow` returns. Pass a string to return
182
+ * the same execution ID for every call, or a function `(name, args, options) => string`
183
+ * to compute one per call. Default: `"mock-execution-id"`.
184
+ * @param handler - Static execution ID or a function that returns one
185
+ */
186
+ setTriggerHandler(handler) {
187
+ getState().triggerHandler = handler;
188
+ },
189
+ /**
190
+ * Configure what `tailor.workflow.wait` returns. Pass a function `(key, payload) => unknown`
191
+ * to compute one per call, or any other value to return it for every call. Default: `null`.
192
+ * @param handler - Static value or a function that returns one
193
+ */
194
+ setWaitHandler: ((handler) => {
195
+ getState().waitHandler = handler;
196
+ }),
197
+ /**
198
+ * Configure how `tailor.workflow.resolve` runs the user-supplied callback. The handler
199
+ * receives `(executionId, key, callback)` — invoke `callback(payload)` to drive
200
+ * resolve→wait wiring in tests. Default: callback is not invoked (records the call only).
201
+ * @param handler - Function invoked per `resolve` call
202
+ */
203
+ setResolveHandler(handler) {
204
+ getState().resolveHandler = handler;
205
+ },
206
+ /**
207
+ * Calls to triggerWorkflow, wait, resolve (not triggerJobFunction — use triggeredJobs).
208
+ * @returns Workflow calls array
209
+ */
210
+ get calls() {
211
+ return getState().workflowCalls;
212
+ },
213
+ /**
214
+ * `tailor.workflow.wait` calls reshaped as `{ key, payload }` for assertions.
215
+ * @returns Wait call records
216
+ */
217
+ get waitCalls() {
218
+ return getState().workflowCalls.filter((c) => c.method === "wait").map((c) => ({
219
+ key: c.args[0],
220
+ payload: c.args[1]
221
+ }));
222
+ },
223
+ /**
224
+ * `tailor.workflow.resolve` calls reshaped as `{ executionId, key }` for assertions.
225
+ * @returns Resolve call records
226
+ */
227
+ get resolveCalls() {
228
+ return getState().workflowCalls.filter((c) => c.method === "resolve").map((c) => ({
229
+ executionId: c.args[0],
230
+ key: c.args[1]
231
+ }));
232
+ },
233
+ /** Reset all workflow mock state. Call in `beforeEach`. */
234
+ reset() {
235
+ const state = getState();
236
+ state.jobHandler = () => null;
237
+ state.jobResultQueue.length = 0;
238
+ state.triggeredJobs.length = 0;
239
+ state.triggerHandler = "mock-execution-id";
240
+ state.waitHandler = null;
241
+ state.resolveHandler = null;
242
+ state.workflowCalls.length = 0;
243
+ }
244
+ };
245
+ /** Mock control for `tailor.secretmanager` — secret store and call recording. */
246
+ const secretmanagerMock = {
247
+ setSecrets(secrets) {
248
+ getState().secretStore = secrets;
249
+ },
250
+ get calls() {
251
+ return getState().secretCalls;
252
+ },
253
+ reset() {
254
+ const state = getState();
255
+ state.secretStore = {};
256
+ state.secretCalls.length = 0;
257
+ }
258
+ };
259
+ /** Mock control for `tailor.authconnection` — token store and call recording. */
260
+ const authconnectionMock = {
261
+ setTokens(tokens) {
262
+ getState().authTokens = tokens;
263
+ },
264
+ get calls() {
265
+ return getState().authCalls;
266
+ },
267
+ reset() {
268
+ const state = getState();
269
+ state.authTokens = {};
270
+ state.authCalls.length = 0;
271
+ }
272
+ };
273
+ /** Mock control for `tailor.idp` — IDP client responses and call recording. */
274
+ const idpMock = {
275
+ setResolver(resolver) {
276
+ getState().idpResolver = resolver;
277
+ },
278
+ /**
279
+ * Enqueue a single result for the next IDP call. Consumed in FIFO order; falls back
280
+ * to `setResolver` when exhausted. Use `enqueueResults` to stage multiple in one call.
281
+ * @param result - Result to return from the next IDP call
282
+ */
283
+ enqueueResult(result) {
284
+ getState().idpResultQueue.push(result);
285
+ },
286
+ /**
287
+ * Enqueue results for multiple subsequent IDP calls.
288
+ * @param results - Results to enqueue, one per upcoming call
289
+ */
290
+ enqueueResults(...results) {
291
+ const queue = getState().idpResultQueue;
292
+ for (const result of results) queue.push(result);
293
+ },
294
+ get calls() {
295
+ return getState().idpCalls;
296
+ },
297
+ reset() {
298
+ const state = getState();
299
+ state.idpResolver = () => null;
300
+ state.idpResultQueue.length = 0;
301
+ state.idpCalls.length = 0;
302
+ }
303
+ };
304
+ /** Mock control for `tailordb.file` — file operation responses and call recording. */
305
+ const fileMock = {
306
+ setResolver(resolver) {
307
+ getState().fileResolver = resolver;
308
+ },
309
+ /**
310
+ * Enqueue a single result for the next `tailordb.file` call. Consumed in FIFO order;
311
+ * falls back to `setResolver` when exhausted. Use `enqueueResults` to stage multiple
312
+ * in one call.
313
+ * @param result - Result to return from the next file call
314
+ */
315
+ enqueueResult(result) {
316
+ getState().fileResultQueue.push(result);
317
+ },
318
+ /**
319
+ * Enqueue results for multiple subsequent `tailordb.file` calls.
320
+ * @param results - Results to enqueue, one per upcoming call
321
+ */
322
+ enqueueResults(...results) {
323
+ const queue = getState().fileResultQueue;
324
+ for (const result of results) queue.push(result);
325
+ },
326
+ get calls() {
327
+ return getState().fileCalls;
328
+ },
329
+ reset() {
330
+ const state = getState();
331
+ state.fileResolver = () => null;
332
+ state.fileResultQueue.length = 0;
333
+ state.fileCalls.length = 0;
334
+ }
335
+ };
336
+ /** Mock control for `tailor.iconv` — encoding call recording. */
337
+ const iconvMock = {
338
+ setResolver(resolver) {
339
+ getState().iconvResolver = resolver;
340
+ },
341
+ get calls() {
342
+ return getState().iconvCalls;
343
+ },
344
+ reset() {
345
+ const state = getState();
346
+ state.iconvResolver = null;
347
+ state.iconvCalls.length = 0;
348
+ }
349
+ };
350
+ var MockQueryResult = class {
351
+ command;
352
+ rowCount;
353
+ rows;
354
+ constructor(rows) {
355
+ this.command = "";
356
+ this.rowCount = rows.length;
357
+ this.rows = rows;
358
+ }
359
+ };
360
+ var MockTransaction = class {
361
+ async begin() {}
362
+ async commit() {}
363
+ async rollback() {}
364
+ async queryObject(query, params = []) {
365
+ return resolveQuery(query, params);
366
+ }
367
+ };
368
+ var MockTailordbClient = class {
369
+ #record;
370
+ constructor(config) {
371
+ this.#record = {
372
+ namespace: config?.namespace,
373
+ ended: false
374
+ };
375
+ getState().createdClients.push(this.#record);
376
+ }
377
+ async connect() {}
378
+ async end() {
379
+ this.#record.ended = true;
380
+ }
381
+ async queryObject(query, params = []) {
382
+ return resolveQuery(query, params);
383
+ }
384
+ createTransaction(name) {
385
+ if (!name) throw new Error("Transaction name must be a non-empty string");
386
+ return new MockTransaction();
387
+ }
388
+ };
389
+ function resolveQuery(query, params) {
390
+ const state = getState();
391
+ state.executedQueries.push({
392
+ query,
393
+ params
394
+ });
395
+ if (state.queryResultQueue.length > 0) return new MockQueryResult(state.queryResultQueue.shift());
396
+ return new MockQueryResult(state.queryResolver(query, params) ?? []);
397
+ }
398
+ function mockTriggerJobFunction(jobName, args) {
399
+ const state = getState();
400
+ state.triggeredJobs.push({
401
+ jobName,
402
+ args
403
+ });
404
+ if (state.jobResultQueue.length > 0) return state.jobResultQueue.shift();
405
+ return state.jobHandler(jobName, args);
406
+ }
407
+ async function mockTriggerWorkflow(workflowName, args, options) {
408
+ const state = getState();
409
+ state.workflowCalls.push({
410
+ method: "triggerWorkflow",
411
+ args: [
412
+ workflowName,
413
+ args,
414
+ options
415
+ ]
416
+ });
417
+ const handler = state.triggerHandler;
418
+ return typeof handler === "function" ? handler(workflowName, args, options) : handler;
419
+ }
420
+ function mockWait(key, payload) {
421
+ const state = getState();
422
+ state.workflowCalls.push({
423
+ method: "wait",
424
+ args: [key, payload]
425
+ });
426
+ const handler = state.waitHandler;
427
+ return typeof handler === "function" ? handler(key, payload) : handler;
428
+ }
429
+ async function mockResolve(executionId, key, callback) {
430
+ const state = getState();
431
+ state.workflowCalls.push({
432
+ method: "resolve",
433
+ args: [
434
+ executionId,
435
+ key,
436
+ callback
437
+ ]
438
+ });
439
+ if (state.resolveHandler) await state.resolveHandler(executionId, key, callback);
440
+ }
441
+ function mockGetInvoker() {
442
+ return null;
443
+ }
444
+ async function mockGetSecrets(vault, names) {
445
+ const state = getState();
446
+ state.secretCalls.push({
447
+ method: "getSecrets",
448
+ vault,
449
+ names
450
+ });
451
+ const vaultData = state.secretStore[vault] ?? {};
452
+ const result = {};
453
+ for (const name of names) if (name in vaultData) result[name] = vaultData[name];
454
+ return result;
455
+ }
456
+ async function mockGetSecret(vault, name) {
457
+ const state = getState();
458
+ state.secretCalls.push({
459
+ method: "getSecret",
460
+ vault,
461
+ name
462
+ });
463
+ return state.secretStore[vault]?.[name];
464
+ }
465
+ async function mockGetConnectionToken(connectionName) {
466
+ const state = getState();
467
+ state.authCalls.push({ connectionName });
468
+ return state.authTokens[connectionName] ?? { access_token: "mock-token" };
469
+ }
470
+ const IDP_DEFAULTS = {
471
+ users: {
472
+ users: [],
473
+ nextPageToken: null,
474
+ totalCount: 0
475
+ },
476
+ user: {
477
+ id: "mock-id",
478
+ name: "mock-user",
479
+ disabled: false
480
+ },
481
+ userByName: {
482
+ id: "mock-id",
483
+ name: "mock-user",
484
+ disabled: false
485
+ },
486
+ createUser: {
487
+ id: "mock-id",
488
+ name: "mock-user",
489
+ disabled: false
490
+ },
491
+ updateUser: {
492
+ id: "mock-id",
493
+ name: "mock-user",
494
+ disabled: false
495
+ },
496
+ deleteUser: true,
497
+ sendPasswordResetEmail: true
498
+ };
499
+ function resolveIdpCall(method, args, namespace) {
500
+ const state = getState();
501
+ state.idpCalls.push({
502
+ method,
503
+ args,
504
+ namespace
505
+ });
506
+ if (state.idpResultQueue.length > 0) return state.idpResultQueue.shift();
507
+ const resolved = state.idpResolver(method, args, namespace);
508
+ if (resolved != null) return resolved;
509
+ const fallback = IDP_DEFAULTS[method];
510
+ return fallback === void 0 ? void 0 : structuredClone(fallback);
511
+ }
512
+ var MockIdpClient = class {
513
+ #namespace;
514
+ constructor(config) {
515
+ this.#namespace = config.namespace;
516
+ }
517
+ async users(options) {
518
+ return resolveIdpCall("users", [options], this.#namespace);
519
+ }
520
+ async user(userId) {
521
+ return resolveIdpCall("user", [userId], this.#namespace);
522
+ }
523
+ async userByName(name) {
524
+ return resolveIdpCall("userByName", [name], this.#namespace);
525
+ }
526
+ async createUser(input) {
527
+ return resolveIdpCall("createUser", [input], this.#namespace);
528
+ }
529
+ async updateUser(input) {
530
+ return resolveIdpCall("updateUser", [input], this.#namespace);
531
+ }
532
+ async deleteUser(userId) {
533
+ return resolveIdpCall("deleteUser", [userId], this.#namespace);
534
+ }
535
+ async sendPasswordResetEmail(input) {
536
+ return resolveIdpCall("sendPasswordResetEmail", [input], this.#namespace);
537
+ }
538
+ };
539
+ function isUtf8(encoding) {
540
+ return encoding === "UTF8" || encoding === "UTF-8";
541
+ }
542
+ function defaultIconvResult(method, args) {
543
+ switch (method) {
544
+ case "convert":
545
+ case "convertBuffer": return isUtf8(args[2]) ? "" : new Uint8Array();
546
+ case "decode": return "";
547
+ case "encode": return isUtf8(args[1]) ? "" : new Uint8Array();
548
+ case "encodings": return [];
549
+ default: return;
550
+ }
551
+ }
552
+ function resolveIconvCall(method, args) {
553
+ const state = getState();
554
+ state.iconvCalls.push({
555
+ method,
556
+ args: [...args]
557
+ });
558
+ if (state.iconvResolver) {
559
+ const result = state.iconvResolver(method, args);
560
+ if (result != null) return result;
561
+ }
562
+ return defaultIconvResult(method, args);
563
+ }
564
+ function mockConvert(str, fromEncoding, toEncoding) {
565
+ return resolveIconvCall("convert", [
566
+ str,
567
+ fromEncoding,
568
+ toEncoding
569
+ ]);
570
+ }
571
+ function mockConvertBuffer(buffer, fromEncoding, toEncoding) {
572
+ return resolveIconvCall("convertBuffer", [
573
+ buffer,
574
+ fromEncoding,
575
+ toEncoding
576
+ ]);
577
+ }
578
+ function mockDecode(buffer, encoding) {
579
+ return resolveIconvCall("decode", [buffer, encoding]);
580
+ }
581
+ function mockEncode(str, encoding) {
582
+ return resolveIconvCall("encode", [str, encoding]);
583
+ }
584
+ function mockEncodings() {
585
+ return resolveIconvCall("encodings", []);
586
+ }
587
+ var MockIconv = class {
588
+ #fromEncoding;
589
+ #toEncoding;
590
+ constructor(fromEncoding, toEncoding) {
591
+ this.#fromEncoding = fromEncoding;
592
+ this.#toEncoding = toEncoding;
593
+ }
594
+ convert(input) {
595
+ return resolveIconvCall("convert", [
596
+ input,
597
+ this.#fromEncoding,
598
+ this.#toEncoding
599
+ ]);
600
+ }
601
+ };
602
+ const FILE_DEFAULTS = {
603
+ upload: { metadata: {
604
+ fileSize: 0,
605
+ sha256sum: ""
606
+ } },
607
+ download: {
608
+ data: new Uint8Array(),
609
+ metadata: {
610
+ contentType: "",
611
+ fileSize: 0,
612
+ sha256sum: "",
613
+ lastUploadedAt: ""
614
+ }
615
+ },
616
+ downloadAsBase64: {
617
+ data: "",
618
+ metadata: {
619
+ contentType: "",
620
+ fileSize: 0,
621
+ sha256sum: "",
622
+ lastUploadedAt: ""
623
+ }
624
+ },
625
+ delete: void 0,
626
+ getMetadata: {
627
+ contentType: "",
628
+ fileSize: 0,
629
+ sha256sum: "",
630
+ urlPath: ""
631
+ }
632
+ };
633
+ function resolveFileCall(method, namespace, typeName, fieldName, recordId) {
634
+ const state = getState();
635
+ const call = {
636
+ method,
637
+ namespace,
638
+ typeName,
639
+ fieldName,
640
+ recordId
641
+ };
642
+ state.fileCalls.push(call);
643
+ if (state.fileResultQueue.length > 0) return state.fileResultQueue.shift();
644
+ const resolved = state.fileResolver(method, call);
645
+ if (resolved != null) return resolved;
646
+ const fallback = FILE_DEFAULTS[method];
647
+ return fallback === void 0 ? void 0 : structuredClone(fallback);
648
+ }
649
+ const mockTailordbFile = {
650
+ async upload(namespace, typeName, fieldName, recordId, _data, _options) {
651
+ return resolveFileCall("upload", namespace, typeName, fieldName, recordId);
652
+ },
653
+ async download(namespace, typeName, fieldName, recordId) {
654
+ return resolveFileCall("download", namespace, typeName, fieldName, recordId);
655
+ },
656
+ async downloadAsBase64(namespace, typeName, fieldName, recordId) {
657
+ return resolveFileCall("downloadAsBase64", namespace, typeName, fieldName, recordId);
658
+ },
659
+ async delete(namespace, typeName, fieldName, recordId) {
660
+ resolveFileCall("delete", namespace, typeName, fieldName, recordId);
661
+ },
662
+ async getMetadata(namespace, typeName, fieldName, recordId) {
663
+ return resolveFileCall("getMetadata", namespace, typeName, fieldName, recordId);
664
+ },
665
+ openDownloadStream(namespace, typeName, fieldName, recordId) {
666
+ const resolved = resolveFileCall("openDownloadStream", namespace, typeName, fieldName, recordId);
667
+ return Promise.resolve(toFileStream(resolved));
668
+ }
669
+ };
670
+ function toFileStream(value) {
671
+ if (value !== null && typeof value === "object" && Symbol.asyncIterator in value && typeof value.close === "function") return value;
672
+ if (value instanceof ArrayBuffer || ArrayBuffer.isView(value)) return toFileStream([value]);
673
+ if (value !== null && typeof value === "object" && (Symbol.iterator in value || Symbol.asyncIterator in value)) {
674
+ const source = value;
675
+ const inner = Symbol.asyncIterator in source ? source[Symbol.asyncIterator]() : source[Symbol.iterator]();
676
+ const stream = {
677
+ async next() {
678
+ const r = await inner.next();
679
+ return r.done ? {
680
+ done: true,
681
+ value: void 0
682
+ } : r;
683
+ },
684
+ async close() {},
685
+ [Symbol.asyncIterator]() {
686
+ return stream;
687
+ }
688
+ };
689
+ return stream;
690
+ }
691
+ const empty = {
692
+ async next() {
693
+ return {
694
+ done: true,
695
+ value: void 0
696
+ };
697
+ },
698
+ async close() {},
699
+ [Symbol.asyncIterator]() {
700
+ return empty;
701
+ }
702
+ };
703
+ return empty;
704
+ }
705
+ var TailorErrorsMock = class extends Error {
706
+ errors;
707
+ constructor(errors) {
708
+ if (!Array.isArray(errors)) throw new TypeError("TailorErrors: errors must be an array");
709
+ const validated = errors.map((e, i) => {
710
+ if (typeof e.message !== "string") throw new TypeError(`TailorErrors: errors[${i}].message must be a string`);
711
+ if (!Array.isArray(e.path)) throw new TypeError(`TailorErrors: errors[${i}].path must be an array`);
712
+ return {
713
+ message: e.message,
714
+ path: e.path
715
+ };
716
+ });
717
+ super(`TailorErrors: ${JSON.stringify({ errors: validated })}`);
718
+ this.name = "TailorErrors";
719
+ this.errors = validated;
720
+ }
721
+ };
722
+ var TailorErrorMessageMock = class extends Error {
723
+ constructor(message) {
724
+ super(message);
725
+ this.name = "TailorErrorMessage";
726
+ }
727
+ };
728
+ var TailorDBFileErrorMock = class extends Error {
729
+ code;
730
+ cause;
731
+ constructor(message, code, cause) {
732
+ super(message);
733
+ this.name = "TailorDBFileError";
734
+ this.code = code;
735
+ this.cause = cause;
736
+ }
737
+ };
738
+ /**
739
+ * Inject all platform API mocks into globalThis.
740
+ * Called by the tailor-runtime Vitest environment during setup.
741
+ * @param global - The global object to inject mocks into
742
+ */
743
+ function injectMocks(global) {
744
+ const g = global;
745
+ g[STATE_KEY] = createDefaultState();
746
+ g[RUNTIME_FLAG_KEY] = true;
747
+ g.tailordb = {
748
+ Client: MockTailordbClient,
749
+ file: mockTailordbFile
750
+ };
751
+ g.tailor = {
752
+ secretmanager: {
753
+ getSecrets: mockGetSecrets,
754
+ getSecret: mockGetSecret
755
+ },
756
+ authconnection: { getConnectionToken: mockGetConnectionToken },
757
+ workflow: {
758
+ triggerJobFunction: mockTriggerJobFunction,
759
+ triggerWorkflow: mockTriggerWorkflow,
760
+ wait: mockWait,
761
+ resolve: mockResolve
762
+ },
763
+ context: { getInvoker: mockGetInvoker },
764
+ idp: { Client: MockIdpClient },
765
+ iconv: {
766
+ convert: mockConvert,
767
+ convertBuffer: mockConvertBuffer,
768
+ decode: mockDecode,
769
+ encode: mockEncode,
770
+ encodings: mockEncodings,
771
+ Iconv: MockIconv
772
+ }
773
+ };
774
+ g.TailorErrors = TailorErrorsMock;
775
+ g.TailorErrorMessage = TailorErrorMessageMock;
776
+ g.TailorDBFileError = TailorDBFileErrorMock;
777
+ }
778
+ /**
779
+ * Remove all injected mocks from globalThis.
780
+ * Called by the tailor-runtime Vitest environment during teardown.
781
+ * @param global - The global object to clean up mocks from
782
+ */
783
+ function cleanupMocks(global) {
784
+ const g = global;
785
+ delete g.tailordb;
786
+ delete g.tailor;
787
+ delete g.TailorErrors;
788
+ delete g.TailorErrorMessage;
789
+ delete g.TailorDBFileError;
790
+ delete g[STATE_KEY];
791
+ delete g[RUNTIME_FLAG_KEY];
792
+ }
793
+
794
+ //#endregion
795
+ export { fileMock as a, injectMocks as c, workflowMock as d, cleanupMocks as i, secretmanagerMock as l, STATE_KEY as n, iconvMock as o, authconnectionMock as r, idpMock as s, RUNTIME_FLAG_KEY as t, tailordbMock as u };
796
+ //# sourceMappingURL=mock-BP-9O5On.mjs.map