@tailor-platform/sdk 1.74.0 → 1.74.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 +20 -0
- package/dist/{application-DwmoI6ZQ.mjs → application-BsH6tkZC.mjs} +43 -5
- package/dist/application-BsH6tkZC.mjs.map +1 -0
- package/dist/application-CSUhZMb5.mjs +3 -0
- package/dist/cli/commands/tailordb/migrate/snapshot.d.mts +1 -16
- package/dist/cli/index.mjs +22 -33
- package/dist/cli/index.mjs.map +1 -1
- package/dist/cli/lib.d.mts +2 -2
- package/dist/cli/lib.mjs +3 -3
- package/dist/cli/lib.mjs.map +1 -1
- package/dist/completion/zsh-worker.zsh +1 -1
- package/dist/configure/index.mjs +2 -2
- package/dist/configure/services/tailordb/schema.d.mts +5 -19
- package/dist/configure/types/field-runtime.d.mts +17 -0
- package/dist/configure/types/type.d.mts +1 -18
- package/dist/field-runtime-9bfXBAOK.mjs +183 -0
- package/dist/field-runtime-9bfXBAOK.mjs.map +1 -0
- package/dist/plugin/builtin/seed/index.mjs +1 -1
- package/dist/{runtime-Zkg3SUwi.mjs → runtime-DV1EnfMs.mjs} +229 -394
- package/dist/runtime-DV1EnfMs.mjs.map +1 -0
- package/dist/{schema-DAdZSFOd.mjs → schema-Dl_y0m9e.mjs} +8 -167
- package/dist/schema-Dl_y0m9e.mjs.map +1 -0
- package/dist/secretmanager-Bd45j7an.mjs +98 -0
- package/dist/secretmanager-Bd45j7an.mjs.map +1 -0
- package/dist/{seed-DoMTMLcm.mjs → seed-fm0LeYP2.mjs} +14 -3
- package/dist/seed-fm0LeYP2.mjs.map +1 -0
- package/dist/types-BwzB2okW.mjs +199 -0
- package/dist/types-BwzB2okW.mjs.map +1 -0
- package/dist/types-KlawuVKa.mjs +4 -0
- package/dist/vitest/index.d.mts +8 -1
- package/dist/vitest/index.mjs +776 -1
- package/dist/vitest/index.mjs.map +1 -1
- package/dist/vitest/mock.d.mts +8 -363
- package/dist/vitest/mocks/aigateway.d.mts +30 -0
- package/dist/vitest/mocks/authconnection.d.mts +28 -0
- package/dist/vitest/mocks/file.d.mts +41 -0
- package/dist/vitest/mocks/iconv.d.mts +27 -0
- package/dist/vitest/mocks/idp.d.mts +44 -0
- package/dist/vitest/mocks/secretmanager.d.mts +33 -0
- package/dist/vitest/mocks/tailordb.d.mts +71 -0
- package/dist/vitest/mocks/workflow.d.mts +115 -0
- package/dist/vitest/setup.mjs +1 -1
- package/package.json +8 -8
- package/dist/application-BndtMTFY.mjs +0 -3
- package/dist/application-DwmoI6ZQ.mjs.map +0 -1
- package/dist/field-DOsJCPFa.mjs +0 -22
- package/dist/field-DOsJCPFa.mjs.map +0 -1
- package/dist/mock-Ce1GCi4-.mjs +0 -871
- package/dist/mock-Ce1GCi4-.mjs.map +0 -1
- package/dist/runtime-Zkg3SUwi.mjs.map +0 -1
- package/dist/schema-DAdZSFOd.mjs.map +0 -1
- package/dist/seed-DoMTMLcm.mjs.map +0 -1
- package/dist/types-qhFZ8y9B.mjs +0 -4
- package/dist/types-ywCGpzDZ.mjs +0 -360
- package/dist/types-ywCGpzDZ.mjs.map +0 -1
package/dist/vitest/mock.d.mts
CHANGED
|
@@ -1,364 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
type FileResolver = (method: string, call: FileCall) => unknown;
|
|
10
|
-
type IconvResolver = (method: string, args: unknown[]) => unknown;
|
|
11
|
-
type TriggerWorkflowOptions = {
|
|
12
|
-
authInvoker?: {
|
|
13
|
-
namespace: string;
|
|
14
|
-
machineUserName: string;
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
type TriggerHandlerFn = (workflowName: string, args: unknown, options?: TriggerWorkflowOptions) => string;
|
|
18
|
-
type ResumeHandlerFn = (executionId: string) => string;
|
|
19
|
-
type WaitHandlerFn = (key: string, payload: unknown) => unknown;
|
|
20
|
-
type ResolveHandler = (executionId: string, key: string, callback: (payload: unknown) => unknown) => unknown | Promise<unknown>;
|
|
21
|
-
type SetWaitHandler = {
|
|
22
|
-
(handler: WaitHandlerFn): void;
|
|
23
|
-
(handler: unknown): void;
|
|
24
|
-
};
|
|
25
|
-
interface ExecutedQuery {
|
|
26
|
-
query: string;
|
|
27
|
-
params: unknown[];
|
|
28
|
-
}
|
|
29
|
-
interface CreatedClient {
|
|
30
|
-
namespace: string | undefined;
|
|
31
|
-
ended: boolean;
|
|
32
|
-
}
|
|
33
|
-
interface TriggeredJob {
|
|
34
|
-
jobName: string;
|
|
35
|
-
args: unknown;
|
|
36
|
-
}
|
|
37
|
-
interface SecretCall {
|
|
38
|
-
method: "getSecret" | "getSecrets";
|
|
39
|
-
vault: string;
|
|
40
|
-
name?: string;
|
|
41
|
-
names?: readonly string[];
|
|
42
|
-
}
|
|
43
|
-
interface AuthConnectionCall {
|
|
44
|
-
connectionName: ConnectionName;
|
|
45
|
-
}
|
|
46
|
-
interface AigatewayCall {
|
|
47
|
-
name: AIGatewayName;
|
|
48
|
-
}
|
|
49
|
-
interface IdpCall {
|
|
50
|
-
method: string;
|
|
51
|
-
args: unknown[];
|
|
52
|
-
namespace: string;
|
|
53
|
-
}
|
|
54
|
-
interface FileCall {
|
|
55
|
-
method: string;
|
|
56
|
-
namespace: string;
|
|
57
|
-
typeName: string;
|
|
58
|
-
fieldName: string;
|
|
59
|
-
recordId: string;
|
|
60
|
-
}
|
|
61
|
-
interface IconvCall {
|
|
62
|
-
method: string;
|
|
63
|
-
args: unknown[];
|
|
64
|
-
}
|
|
65
|
-
declare class MockQueryResult {
|
|
66
|
-
command: string;
|
|
67
|
-
rowCount: number;
|
|
68
|
-
rows: unknown[];
|
|
69
|
-
constructor(rows: unknown[]);
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Acquire a disposable mock for TailorDB operations. Installs a mock
|
|
73
|
-
* `tailordb.Client` whose `queryObject` is a shared `vi.fn()` (so query
|
|
74
|
-
* responses can be staged before the client is constructed). Restored on
|
|
75
|
-
* dispose.
|
|
76
|
-
* @returns Disposable TailorDB mock control object
|
|
77
|
-
* @example
|
|
78
|
-
* ```typescript
|
|
79
|
-
* import { mockTailordb } from "@tailor-platform/sdk/vitest";
|
|
80
|
-
*
|
|
81
|
-
* test("order-based", async () => {
|
|
82
|
-
* using db = mockTailordb();
|
|
83
|
-
* db.enqueueResults([], [{ age: 30 }], []); // BEGIN / SELECT / COMMIT
|
|
84
|
-
* // …
|
|
85
|
-
* expect(db.queryObject).toHaveBeenCalledTimes(3);
|
|
86
|
-
* expect(db.Client).toHaveBeenCalledWith({ namespace: "tailordb" });
|
|
87
|
-
* });
|
|
88
|
-
* ```
|
|
89
|
-
*/
|
|
90
|
-
declare function mockTailordb(): {
|
|
91
|
-
/** The mock `tailordb.Client` constructor (`vi.fn`). */Client: Mock<(this: any, config?: {
|
|
92
|
-
namespace?: string;
|
|
93
|
-
}) => void>; /** The shared `queryObject` `vi.fn` used by every client and transaction. */
|
|
94
|
-
queryObject: Mock<(_query: string, _params?: unknown[]) => Promise<MockQueryResult>>;
|
|
95
|
-
/**
|
|
96
|
-
* Set a fallback query resolver. Called when the enqueue queue is empty.
|
|
97
|
-
* @param resolver - Function that returns rows for a given query and params
|
|
98
|
-
*/
|
|
99
|
-
setQueryResolver(resolver: QueryResolver): void;
|
|
100
|
-
/**
|
|
101
|
-
* Enqueue rows for the next `queryObject` call (FIFO; takes priority over
|
|
102
|
-
* `setQueryResolver`). Call with no arguments for an empty result.
|
|
103
|
-
* @param rows - Row objects to return from the next `queryObject` call
|
|
104
|
-
*/
|
|
105
|
-
enqueueResult(...rows: unknown[]): void;
|
|
106
|
-
/**
|
|
107
|
-
* Enqueue rows for multiple subsequent `queryObject` calls (FIFO).
|
|
108
|
-
* @param rowsList - Rows arrays, one per upcoming query
|
|
109
|
-
*/
|
|
110
|
-
enqueueResults(...rowsList: unknown[][]): void;
|
|
111
|
-
/**
|
|
112
|
-
* All queries executed via `queryObject`, in order, derived from the vi.fn
|
|
113
|
-
* call records.
|
|
114
|
-
* @returns Executed queries array
|
|
115
|
-
*/
|
|
116
|
-
readonly executedQueries: ExecutedQuery[];
|
|
117
|
-
/**
|
|
118
|
-
* All TailorDB clients created, with their namespace and end state.
|
|
119
|
-
* @returns Created clients array
|
|
120
|
-
*/
|
|
121
|
-
readonly createdClients: CreatedClient[]; /** Reset query responses and recorded calls (keeps the mock installed). */
|
|
122
|
-
reset(): void;
|
|
123
|
-
} & Disposable;
|
|
124
|
-
/**
|
|
125
|
-
* Acquire a disposable mock for workflow operations (`tailor.workflow`).
|
|
126
|
-
* Restored on dispose.
|
|
127
|
-
* @returns Disposable workflow mock control object
|
|
128
|
-
* @example
|
|
129
|
-
* ```typescript
|
|
130
|
-
* import { mockWorkflow } from "@tailor-platform/sdk/vitest";
|
|
131
|
-
*
|
|
132
|
-
* test("job handler", async () => {
|
|
133
|
-
* using wf = mockWorkflow();
|
|
134
|
-
* wf.setJobHandler((name) => (name === "validate" ? { valid: true } : null));
|
|
135
|
-
* await runWorkflowUnderTest(); // calls tailor.workflow.triggerJobFunction("validate", {})
|
|
136
|
-
* expect(wf.triggerJobFunction).toHaveBeenCalledWith("validate", {});
|
|
137
|
-
* });
|
|
138
|
-
* ```
|
|
139
|
-
*/
|
|
140
|
-
declare function mockWorkflow(): {
|
|
141
|
-
/** The `triggerJobFunction` `vi.fn`. */triggerJobFunction: Mock<(jobName: string, args?: unknown) => unknown>; /** The `triggerWorkflow` `vi.fn`. */
|
|
142
|
-
triggerWorkflow: Mock<(workflowName: string, args?: unknown, _options?: TriggerWorkflowOptions) => Promise<string>>; /** The `resumeWorkflow` `vi.fn`. */
|
|
143
|
-
resumeWorkflow: Mock<(executionId: string) => Promise<string>>; /** The `wait` `vi.fn`. */
|
|
144
|
-
wait: Mock<(_key: string, _payload?: unknown) => unknown>; /** The `resolve` `vi.fn`. */
|
|
145
|
-
resolve: Mock<(_executionId: string, _key: string, _callback: (payload: unknown) => unknown) => Promise<void>>;
|
|
146
|
-
/**
|
|
147
|
-
* Set a fallback job handler. Called when the enqueue queue is empty.
|
|
148
|
-
* @param handler - Function returning a result for a job name and args
|
|
149
|
-
*/
|
|
150
|
-
setJobHandler(handler: JobHandler): void;
|
|
151
|
-
/**
|
|
152
|
-
* Enqueue a single result for the next `triggerJobFunction` call (FIFO;
|
|
153
|
-
* takes priority over `setJobHandler`).
|
|
154
|
-
* @param result - Result to return from the next call
|
|
155
|
-
*/
|
|
156
|
-
enqueueResult(result: unknown): void;
|
|
157
|
-
/**
|
|
158
|
-
* Enqueue results for multiple subsequent `triggerJobFunction` calls (FIFO).
|
|
159
|
-
* @param results - Results to enqueue, one per upcoming call
|
|
160
|
-
*/
|
|
161
|
-
enqueueResults(...results: unknown[]): void;
|
|
162
|
-
/**
|
|
163
|
-
* All jobs triggered via `triggerJobFunction`, in order.
|
|
164
|
-
* @returns Triggered jobs array
|
|
165
|
-
*/
|
|
166
|
-
readonly triggeredJobs: TriggeredJob[];
|
|
167
|
-
/**
|
|
168
|
-
* Configure what `triggerWorkflow` returns. Pass a string (same id every
|
|
169
|
-
* call) or `(name, args, options) => string`. Default: a placeholder UUID.
|
|
170
|
-
* @param handler - Static execution ID or a function returning one
|
|
171
|
-
*/
|
|
172
|
-
setTriggerHandler(handler: string | TriggerHandlerFn): void;
|
|
173
|
-
/**
|
|
174
|
-
* Configure what `resumeWorkflow` returns. Pass a string (same id every
|
|
175
|
-
* call) or `(executionId) => string`. Default: echoes the input executionId.
|
|
176
|
-
* @param handler - Static execution ID or a function returning one
|
|
177
|
-
*/
|
|
178
|
-
setResumeHandler(handler: string | ResumeHandlerFn): void;
|
|
179
|
-
/**
|
|
180
|
-
* Configure what `wait` returns. Pass `(key, payload) => unknown` or any
|
|
181
|
-
* other value to return it for every call. Default: `null`.
|
|
182
|
-
* @param handler - Static value or a function returning one
|
|
183
|
-
*/
|
|
184
|
-
setWaitHandler: SetWaitHandler;
|
|
185
|
-
/**
|
|
186
|
-
* Set the `env` passed to job bodies invoked via `createWorkflowJob().trigger()`.
|
|
187
|
-
* Cleared on dispose / reset.
|
|
188
|
-
* @param env - Env passed to job bodies.
|
|
189
|
-
*/
|
|
190
|
-
setEnv(env: TailorEnv): void;
|
|
191
|
-
/**
|
|
192
|
-
* Configure how `resolve` runs the user-supplied callback. Default: callback
|
|
193
|
-
* is not invoked (records the call only).
|
|
194
|
-
* @param handler - Function invoked per `resolve` call
|
|
195
|
-
*/
|
|
196
|
-
setResolveHandler(handler: ResolveHandler): void;
|
|
197
|
-
/**
|
|
198
|
-
* `wait` calls reshaped as `{ key, payload }` for assertions.
|
|
199
|
-
* @returns Wait call records
|
|
200
|
-
*/
|
|
201
|
-
readonly waitCalls: {
|
|
202
|
-
key: string;
|
|
203
|
-
payload: unknown;
|
|
204
|
-
}[];
|
|
205
|
-
/**
|
|
206
|
-
* `resolve` calls reshaped as `{ executionId, key }` for assertions.
|
|
207
|
-
* @returns Resolve call records
|
|
208
|
-
*/
|
|
209
|
-
readonly resolveCalls: {
|
|
210
|
-
executionId: string;
|
|
211
|
-
key: string;
|
|
212
|
-
}[]; /** Reset all workflow responses and recorded calls (keeps the mock installed). */
|
|
213
|
-
reset(): void;
|
|
214
|
-
} & Disposable;
|
|
215
|
-
/**
|
|
216
|
-
* Acquire a disposable mock for `tailor.secretmanager`. The secret store is
|
|
217
|
-
* inherited (cloned) from the currently-installed mock on acquisition and
|
|
218
|
-
* restored on dispose, so secrets seeded outside the test survive across
|
|
219
|
-
* `using` scopes while per-test `setSecrets()` overrides stay isolated.
|
|
220
|
-
* @returns Disposable SecretManager mock control object
|
|
221
|
-
* @example
|
|
222
|
-
* ```typescript
|
|
223
|
-
* import { mockSecretmanager } from "@tailor-platform/sdk/vitest";
|
|
224
|
-
*
|
|
225
|
-
* test("reads secrets from vault", async () => {
|
|
226
|
-
* using sm = mockSecretmanager();
|
|
227
|
-
* sm.setSecrets({ "my-vault": { API_KEY: "sk-123" } });
|
|
228
|
-
* // …
|
|
229
|
-
* });
|
|
230
|
-
* ```
|
|
231
|
-
*/
|
|
232
|
-
declare function mockSecretmanager(): {
|
|
233
|
-
/** The `getSecret` `vi.fn`. */getSecret: Mock<(vault: string, name: string) => Promise<string | undefined>>; /** The `getSecrets` `vi.fn`. */
|
|
234
|
-
getSecrets: Mock<(<const T extends readonly string[]>(vault: string, names: T) => Promise<Partial<Record<T[number], string>>>)>;
|
|
235
|
-
setSecrets(secrets: Record<string, Record<string, string>>): void;
|
|
236
|
-
readonly calls: SecretCall[];
|
|
237
|
-
reset(): void;
|
|
238
|
-
} & Disposable;
|
|
239
|
-
/**
|
|
240
|
-
* Acquire a disposable mock for `tailor.authconnection`. Restored on dispose.
|
|
241
|
-
* @returns Disposable AuthConnection mock control object
|
|
242
|
-
* @example
|
|
243
|
-
* ```typescript
|
|
244
|
-
* import { mockAuthconnection } from "@tailor-platform/sdk/vitest";
|
|
245
|
-
*
|
|
246
|
-
* test("returns configured token", async () => {
|
|
247
|
-
* using ac = mockAuthconnection();
|
|
248
|
-
* ac.setTokens({ google: { access_token: "ya29.xxx" } });
|
|
249
|
-
* // …
|
|
250
|
-
* });
|
|
251
|
-
* ```
|
|
252
|
-
*/
|
|
253
|
-
declare function mockAuthconnection(): {
|
|
254
|
-
/** The `getConnectionToken` `vi.fn`. */getConnectionToken: Mock<(connectionName: ConnectionName) => Promise<AuthConnectionTokenResult>>;
|
|
255
|
-
setTokens(value: Partial<Record<ConnectionName, AuthConnectionTokenResult>>): void;
|
|
256
|
-
readonly calls: AuthConnectionCall[];
|
|
257
|
-
reset(): void;
|
|
258
|
-
} & Disposable;
|
|
259
|
-
/**
|
|
260
|
-
* Acquire a disposable mock for `tailor.idp`. Restored on dispose.
|
|
261
|
-
* @returns Disposable IDP mock control object
|
|
262
|
-
* @example
|
|
263
|
-
* ```typescript
|
|
264
|
-
* import { mockIdp } from "@tailor-platform/sdk/vitest";
|
|
265
|
-
*
|
|
266
|
-
* test("resolver-based", async () => {
|
|
267
|
-
* using idp = mockIdp();
|
|
268
|
-
* idp.setResolver((method) =>
|
|
269
|
-
* method === "user" ? { id: "u-1", name: "alice", disabled: false } : null,
|
|
270
|
-
* );
|
|
271
|
-
* // …
|
|
272
|
-
* });
|
|
273
|
-
* ```
|
|
274
|
-
*/
|
|
275
|
-
declare function mockIdp(): {
|
|
276
|
-
/** The mock IDP `Client` constructor (`vi.fn`). */Client: Mock;
|
|
277
|
-
setResolver(value: IdpResolver): void;
|
|
278
|
-
/**
|
|
279
|
-
* Enqueue a single result for the next IDP call (FIFO; falls back to
|
|
280
|
-
* `setResolver` when exhausted).
|
|
281
|
-
* @param result - Result to return from the next IDP call
|
|
282
|
-
*/
|
|
283
|
-
enqueueResult(result: unknown): void;
|
|
284
|
-
/**
|
|
285
|
-
* Enqueue results for multiple subsequent IDP calls.
|
|
286
|
-
* @param results - Results to enqueue, one per upcoming call
|
|
287
|
-
*/
|
|
288
|
-
enqueueResults(...results: unknown[]): void;
|
|
289
|
-
readonly calls: IdpCall[];
|
|
290
|
-
reset(): void;
|
|
291
|
-
} & Disposable;
|
|
292
|
-
/**
|
|
293
|
-
* Acquire a disposable mock for `tailor.iconv`. Restored on dispose.
|
|
294
|
-
* @returns Disposable Iconv mock control object
|
|
295
|
-
* @example
|
|
296
|
-
* ```typescript
|
|
297
|
-
* import { mockIconv } from "@tailor-platform/sdk/vitest";
|
|
298
|
-
*
|
|
299
|
-
* test("mock encoding conversion", () => {
|
|
300
|
-
* using iconv = mockIconv();
|
|
301
|
-
* iconv.setResolver((method) => (method === "decode" ? "decoded-text" : null));
|
|
302
|
-
* // …
|
|
303
|
-
* });
|
|
304
|
-
* ```
|
|
305
|
-
*/
|
|
306
|
-
declare function mockIconv(): {
|
|
307
|
-
setResolver(value: IconvResolver): void;
|
|
308
|
-
readonly calls: IconvCall[];
|
|
309
|
-
reset(): void;
|
|
310
|
-
} & Disposable;
|
|
311
|
-
/**
|
|
312
|
-
* Acquire a disposable mock for `tailordb.file`. Restored on dispose.
|
|
313
|
-
* @returns Disposable File mock control object
|
|
314
|
-
* @example
|
|
315
|
-
* ```typescript
|
|
316
|
-
* import { mockFile } from "@tailor-platform/sdk/vitest";
|
|
317
|
-
*
|
|
318
|
-
* test("mock file download", async () => {
|
|
319
|
-
* using file = mockFile();
|
|
320
|
-
* file.enqueueResult({ data: new Uint8Array([1, 2, 3]), metadata: { ... } });
|
|
321
|
-
* // …
|
|
322
|
-
* });
|
|
323
|
-
* ```
|
|
324
|
-
*/
|
|
325
|
-
declare function mockFile(): {
|
|
326
|
-
setResolver(value: FileResolver): void;
|
|
327
|
-
/**
|
|
328
|
-
* Enqueue a single result for the next `tailordb.file` call (FIFO; falls
|
|
329
|
-
* back to `setResolver` when exhausted).
|
|
330
|
-
* @param result - Result to return from the next file call
|
|
331
|
-
*/
|
|
332
|
-
enqueueResult(result: unknown): void;
|
|
333
|
-
/**
|
|
334
|
-
* Enqueue results for multiple subsequent `tailordb.file` calls.
|
|
335
|
-
* @param results - Results to enqueue, one per upcoming call
|
|
336
|
-
*/
|
|
337
|
-
enqueueResults(...results: unknown[]): void;
|
|
338
|
-
readonly calls: FileCall[];
|
|
339
|
-
reset(): void;
|
|
340
|
-
} & Disposable;
|
|
341
|
-
/**
|
|
342
|
-
* Acquire a disposable mock for `tailor.aigateway`. Restored on dispose.
|
|
343
|
-
* @returns Disposable AI Gateway mock control object
|
|
344
|
-
* @example
|
|
345
|
-
* ```typescript
|
|
346
|
-
* import { mockAigateway } from "@tailor-platform/sdk/vitest";
|
|
347
|
-
*
|
|
348
|
-
* test("resolves an AI Gateway URL", async () => {
|
|
349
|
-
* using aigateway = mockAigateway();
|
|
350
|
-
* aigateway.setUrls({ "my-aigateway": "https://my-aigateway.example.com" });
|
|
351
|
-
* // …
|
|
352
|
-
* });
|
|
353
|
-
* ```
|
|
354
|
-
*/
|
|
355
|
-
declare function mockAigateway(): {
|
|
356
|
-
/** The `get` `vi.fn`. */get: Mock<(name: AIGatewayName) => Promise<{
|
|
357
|
-
url: string;
|
|
358
|
-
}>>;
|
|
359
|
-
setUrls(value: Partial<Record<AIGatewayName, string>>): void;
|
|
360
|
-
readonly calls: AigatewayCall[];
|
|
361
|
-
reset(): void;
|
|
362
|
-
} & Disposable;
|
|
363
|
-
//#endregion
|
|
1
|
+
import { mockAigateway } from "./mocks/aigateway.mjs";
|
|
2
|
+
import { mockAuthconnection } from "./mocks/authconnection.mjs";
|
|
3
|
+
import { mockFile } from "./mocks/file.mjs";
|
|
4
|
+
import { mockIconv } from "./mocks/iconv.mjs";
|
|
5
|
+
import { mockIdp } from "./mocks/idp.mjs";
|
|
6
|
+
import { mockSecretmanager } from "./mocks/secretmanager.mjs";
|
|
7
|
+
import { mockTailordb } from "./mocks/tailordb.mjs";
|
|
8
|
+
import { mockWorkflow } from "./mocks/workflow.mjs";
|
|
364
9
|
export { mockAigateway, mockAuthconnection, mockFile, mockIconv, mockIdp, mockSecretmanager, mockTailordb, mockWorkflow };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { AIGatewayName } from "@tailor-platform/sdk";
|
|
2
|
+
|
|
3
|
+
//#region src/vitest/mocks/aigateway.d.ts
|
|
4
|
+
interface AigatewayCall {
|
|
5
|
+
name: AIGatewayName;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Acquire a disposable mock for `tailor.aigateway`. Restored on dispose.
|
|
9
|
+
* @returns Disposable AI Gateway mock control object
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { mockAigateway } from "@tailor-platform/sdk/vitest";
|
|
13
|
+
*
|
|
14
|
+
* test("resolves an AI Gateway URL", async () => {
|
|
15
|
+
* using aigateway = mockAigateway();
|
|
16
|
+
* aigateway.setUrls({ "my-aigateway": "https://my-aigateway.example.com" });
|
|
17
|
+
* // …
|
|
18
|
+
* });
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
declare function mockAigateway(): {
|
|
22
|
+
/** The `get` `vi.fn`. */get: import("vitest").Mock<(name: AIGatewayName) => Promise<{
|
|
23
|
+
url: string;
|
|
24
|
+
}>>;
|
|
25
|
+
setUrls(value: Partial<Record<AIGatewayName, string>>): void;
|
|
26
|
+
readonly calls: AigatewayCall[];
|
|
27
|
+
reset(): void;
|
|
28
|
+
} & Disposable;
|
|
29
|
+
//#endregion
|
|
30
|
+
export { mockAigateway };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { AuthConnectionTokenResult, ConnectionName } from "@tailor-platform/sdk";
|
|
2
|
+
|
|
3
|
+
//#region src/vitest/mocks/authconnection.d.ts
|
|
4
|
+
interface AuthConnectionCall {
|
|
5
|
+
connectionName: ConnectionName;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Acquire a disposable mock for `tailor.authconnection`. Restored on dispose.
|
|
9
|
+
* @returns Disposable AuthConnection mock control object
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { mockAuthconnection } from "@tailor-platform/sdk/vitest";
|
|
13
|
+
*
|
|
14
|
+
* test("returns configured token", async () => {
|
|
15
|
+
* using ac = mockAuthconnection();
|
|
16
|
+
* ac.setTokens({ google: { access_token: "ya29.xxx" } });
|
|
17
|
+
* // …
|
|
18
|
+
* });
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
declare function mockAuthconnection(): {
|
|
22
|
+
/** The `getConnectionToken` `vi.fn`. */getConnectionToken: import("vitest").Mock<(connectionName: ConnectionName) => Promise<AuthConnectionTokenResult>>;
|
|
23
|
+
setTokens(value: Partial<Record<ConnectionName, AuthConnectionTokenResult>>): void;
|
|
24
|
+
readonly calls: AuthConnectionCall[];
|
|
25
|
+
reset(): void;
|
|
26
|
+
} & Disposable;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { mockAuthconnection };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
//#region src/vitest/mocks/file.d.ts
|
|
2
|
+
type FileResolver = (method: string, call: FileCall) => unknown;
|
|
3
|
+
interface FileCall {
|
|
4
|
+
method: string;
|
|
5
|
+
namespace: string;
|
|
6
|
+
typeName: string;
|
|
7
|
+
fieldName: string;
|
|
8
|
+
recordId: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Acquire a disposable mock for `tailordb.file`. Restored on dispose.
|
|
12
|
+
* @returns Disposable File mock control object
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import { mockFile } from "@tailor-platform/sdk/vitest";
|
|
16
|
+
*
|
|
17
|
+
* test("mock file download", async () => {
|
|
18
|
+
* using file = mockFile();
|
|
19
|
+
* file.enqueueResult({ data: new Uint8Array([1, 2, 3]), metadata: { ... } });
|
|
20
|
+
* // …
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
declare function mockFile(): {
|
|
25
|
+
setResolver(value: FileResolver): void;
|
|
26
|
+
/**
|
|
27
|
+
* Enqueue a single result for the next `tailordb.file` call (FIFO; falls
|
|
28
|
+
* back to `setResolver` when exhausted).
|
|
29
|
+
* @param result - Result to return from the next file call
|
|
30
|
+
*/
|
|
31
|
+
enqueueResult(result: unknown): void;
|
|
32
|
+
/**
|
|
33
|
+
* Enqueue results for multiple subsequent `tailordb.file` calls.
|
|
34
|
+
* @param results - Results to enqueue, one per upcoming call
|
|
35
|
+
*/
|
|
36
|
+
enqueueResults(...results: unknown[]): void;
|
|
37
|
+
readonly calls: FileCall[];
|
|
38
|
+
reset(): void;
|
|
39
|
+
} & Disposable;
|
|
40
|
+
//#endregion
|
|
41
|
+
export { mockFile };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
//#region src/vitest/mocks/iconv.d.ts
|
|
2
|
+
type IconvResolver = (method: string, args: unknown[]) => unknown;
|
|
3
|
+
interface IconvCall {
|
|
4
|
+
method: string;
|
|
5
|
+
args: unknown[];
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Acquire a disposable mock for `tailor.iconv`. Restored on dispose.
|
|
9
|
+
* @returns Disposable Iconv mock control object
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { mockIconv } from "@tailor-platform/sdk/vitest";
|
|
13
|
+
*
|
|
14
|
+
* test("mock encoding conversion", () => {
|
|
15
|
+
* using iconv = mockIconv();
|
|
16
|
+
* iconv.setResolver((method) => (method === "decode" ? "decoded-text" : null));
|
|
17
|
+
* // …
|
|
18
|
+
* });
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
declare function mockIconv(): {
|
|
22
|
+
setResolver(value: IconvResolver): void;
|
|
23
|
+
readonly calls: IconvCall[];
|
|
24
|
+
reset(): void;
|
|
25
|
+
} & Disposable;
|
|
26
|
+
//#endregion
|
|
27
|
+
export { mockIconv };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Mock } from "vitest";
|
|
2
|
+
|
|
3
|
+
//#region src/vitest/mocks/idp.d.ts
|
|
4
|
+
type IdpResolver = (method: string, args: unknown[], namespace: string) => unknown;
|
|
5
|
+
interface IdpCall {
|
|
6
|
+
method: string;
|
|
7
|
+
args: unknown[];
|
|
8
|
+
namespace: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Acquire a disposable mock for `tailor.idp`. Restored on dispose.
|
|
12
|
+
* @returns Disposable IDP mock control object
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import { mockIdp } from "@tailor-platform/sdk/vitest";
|
|
16
|
+
*
|
|
17
|
+
* test("resolver-based", async () => {
|
|
18
|
+
* using idp = mockIdp();
|
|
19
|
+
* idp.setResolver((method) =>
|
|
20
|
+
* method === "user" ? { id: "u-1", name: "alice", disabled: false } : null,
|
|
21
|
+
* );
|
|
22
|
+
* // …
|
|
23
|
+
* });
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
declare function mockIdp(): {
|
|
27
|
+
/** The mock IDP `Client` constructor (`vi.fn`). */Client: Mock;
|
|
28
|
+
setResolver(value: IdpResolver): void;
|
|
29
|
+
/**
|
|
30
|
+
* Enqueue a single result for the next IDP call (FIFO; falls back to
|
|
31
|
+
* `setResolver` when exhausted).
|
|
32
|
+
* @param result - Result to return from the next IDP call
|
|
33
|
+
*/
|
|
34
|
+
enqueueResult(result: unknown): void;
|
|
35
|
+
/**
|
|
36
|
+
* Enqueue results for multiple subsequent IDP calls.
|
|
37
|
+
* @param results - Results to enqueue, one per upcoming call
|
|
38
|
+
*/
|
|
39
|
+
enqueueResults(...results: unknown[]): void;
|
|
40
|
+
readonly calls: IdpCall[];
|
|
41
|
+
reset(): void;
|
|
42
|
+
} & Disposable;
|
|
43
|
+
//#endregion
|
|
44
|
+
export { mockIdp };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
//#region src/vitest/mocks/secretmanager.d.ts
|
|
2
|
+
interface SecretCall {
|
|
3
|
+
method: "getSecret" | "getSecrets";
|
|
4
|
+
vault: string;
|
|
5
|
+
name?: string;
|
|
6
|
+
names?: readonly string[];
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Acquire a disposable mock for `tailor.secretmanager`. The secret store is
|
|
10
|
+
* inherited (cloned) from the currently-installed mock on acquisition and
|
|
11
|
+
* restored on dispose, so secrets seeded outside the test survive across
|
|
12
|
+
* `using` scopes while per-test `setSecrets()` overrides stay isolated.
|
|
13
|
+
* @returns Disposable SecretManager mock control object
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* import { mockSecretmanager } from "@tailor-platform/sdk/vitest";
|
|
17
|
+
*
|
|
18
|
+
* test("reads secrets from vault", async () => {
|
|
19
|
+
* using sm = mockSecretmanager();
|
|
20
|
+
* sm.setSecrets({ "my-vault": { API_KEY: "sk-123" } });
|
|
21
|
+
* // …
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
declare function mockSecretmanager(): {
|
|
26
|
+
/** The `getSecret` `vi.fn`. */getSecret: import("vitest").Mock<(vault: string, name: string) => Promise<string | undefined>>; /** The `getSecrets` `vi.fn`. */
|
|
27
|
+
getSecrets: import("vitest").Mock<(<const T extends readonly string[]>(vault: string, names: T) => Promise<Partial<Record<T[number], string>>>)>;
|
|
28
|
+
setSecrets(secrets: Record<string, Record<string, string>>): void;
|
|
29
|
+
readonly calls: SecretCall[];
|
|
30
|
+
reset(): void;
|
|
31
|
+
} & Disposable;
|
|
32
|
+
//#endregion
|
|
33
|
+
export { mockSecretmanager };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
//#region src/vitest/mocks/tailordb.d.ts
|
|
2
|
+
type QueryResolver = (query: string, params: unknown[]) => unknown[];
|
|
3
|
+
interface ExecutedQuery {
|
|
4
|
+
query: string;
|
|
5
|
+
params: unknown[];
|
|
6
|
+
}
|
|
7
|
+
interface CreatedClient {
|
|
8
|
+
namespace: string | undefined;
|
|
9
|
+
ended: boolean;
|
|
10
|
+
}
|
|
11
|
+
declare class MockQueryResult {
|
|
12
|
+
command: string;
|
|
13
|
+
rowCount: number;
|
|
14
|
+
rows: unknown[];
|
|
15
|
+
constructor(rows: unknown[]);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Acquire a disposable mock for TailorDB operations. Installs a mock
|
|
19
|
+
* `tailordb.Client` whose `queryObject` is a shared `vi.fn()` (so query
|
|
20
|
+
* responses can be staged before the client is constructed). Restored on
|
|
21
|
+
* dispose.
|
|
22
|
+
* @returns Disposable TailorDB mock control object
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* import { mockTailordb } from "@tailor-platform/sdk/vitest";
|
|
26
|
+
*
|
|
27
|
+
* test("order-based", async () => {
|
|
28
|
+
* using db = mockTailordb();
|
|
29
|
+
* db.enqueueResults([], [{ age: 30 }], []); // BEGIN / SELECT / COMMIT
|
|
30
|
+
* // …
|
|
31
|
+
* expect(db.queryObject).toHaveBeenCalledTimes(3);
|
|
32
|
+
* expect(db.Client).toHaveBeenCalledWith({ namespace: "tailordb" });
|
|
33
|
+
* });
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
declare function mockTailordb(): {
|
|
37
|
+
/** The mock `tailordb.Client` constructor (`vi.fn`). */Client: import("vitest").Mock<(this: any, config?: {
|
|
38
|
+
namespace?: string;
|
|
39
|
+
}) => void>; /** The shared `queryObject` `vi.fn` used by every client and transaction. */
|
|
40
|
+
queryObject: import("vitest").Mock<(_query: string, _params?: unknown[]) => Promise<MockQueryResult>>;
|
|
41
|
+
/**
|
|
42
|
+
* Set a fallback query resolver. Called when the enqueue queue is empty.
|
|
43
|
+
* @param resolver - Function that returns rows for a given query and params
|
|
44
|
+
*/
|
|
45
|
+
setQueryResolver(resolver: QueryResolver): void;
|
|
46
|
+
/**
|
|
47
|
+
* Enqueue rows for the next `queryObject` call (FIFO; takes priority over
|
|
48
|
+
* `setQueryResolver`). Call with no arguments for an empty result.
|
|
49
|
+
* @param rows - Row objects to return from the next `queryObject` call
|
|
50
|
+
*/
|
|
51
|
+
enqueueResult(...rows: unknown[]): void;
|
|
52
|
+
/**
|
|
53
|
+
* Enqueue rows for multiple subsequent `queryObject` calls (FIFO).
|
|
54
|
+
* @param rowsList - Rows arrays, one per upcoming query
|
|
55
|
+
*/
|
|
56
|
+
enqueueResults(...rowsList: unknown[][]): void;
|
|
57
|
+
/**
|
|
58
|
+
* All queries executed via `queryObject`, in order, derived from the vi.fn
|
|
59
|
+
* call records.
|
|
60
|
+
* @returns Executed queries array
|
|
61
|
+
*/
|
|
62
|
+
readonly executedQueries: ExecutedQuery[];
|
|
63
|
+
/**
|
|
64
|
+
* All TailorDB clients created, with their namespace and end state.
|
|
65
|
+
* @returns Created clients array
|
|
66
|
+
*/
|
|
67
|
+
readonly createdClients: CreatedClient[]; /** Reset query responses and recorded calls (keeps the mock installed). */
|
|
68
|
+
reset(): void;
|
|
69
|
+
} & Disposable;
|
|
70
|
+
//#endregion
|
|
71
|
+
export { mockTailordb };
|