@tailor-platform/sdk 2.3.0 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +68 -0
- package/README.md +1 -1
- package/dist/{application-F-nl107y.mjs → application-C8a0UJ-z.mjs} +201 -149
- package/dist/application-C8a0UJ-z.mjs.map +1 -0
- package/dist/application-D4zOiLLa.mjs +3 -0
- package/dist/cli/commands/tailordb/migrate/diff-calculator.d.mts +4 -4
- package/dist/cli/commands/tailordb/migrate/generate.d.mts +3 -3
- package/dist/cli/commands/tailordb/migrate/snapshot.d.mts +5 -5
- package/dist/cli/commands/tailordb/truncate.d.mts +2 -2
- package/dist/cli/lib.mjs +2 -2
- package/dist/cli/lib.mjs.map +1 -1
- package/dist/cli/main.mjs +174 -106
- package/dist/cli/main.mjs.map +1 -1
- package/dist/cli/ts-hook.mjs +3 -1
- package/dist/completion/zsh-worker.zsh +19 -11
- package/dist/configure/config/index.d.mts +1 -1
- package/dist/configure/index.d.mts +2 -1
- package/dist/configure/index.mjs +2 -2
- package/dist/configure/index.mjs.map +1 -1
- package/dist/configure/services/aigateway/index.d.mts +5 -4
- package/dist/configure/services/aigateway/types.d.mts +6 -1
- package/dist/configure/services/auth/types.d.mts +2 -2
- package/dist/configure/services/tailordb/permission.d.mts +1 -1
- package/dist/configure/services/tailordb/schema.d.mts +1 -1
- package/dist/configure/services/tailordb/types.d.mts +7 -4
- package/dist/configure/types/auth-namespace-name.d.mts +18 -0
- package/dist/{crashreport-CINZ5dVN.mjs → crashreport-Cd4TqfZq.mjs} +1 -1
- package/dist/{crashreport-CIIfLnoO.mjs → crashreport-Q0pDAlrj.mjs} +8 -4
- package/dist/{crashreport-CIIfLnoO.mjs.map → crashreport-Q0pDAlrj.mjs.map} +1 -1
- package/dist/{errors-BVb6vYGy.mjs → errors-Bxut5_Sy.mjs} +2 -2
- package/dist/{errors-BVb6vYGy.mjs.map → errors-Bxut5_Sy.mjs.map} +1 -1
- package/dist/file-BUcmVIH2.mjs.map +1 -1
- package/dist/kysely/index.mjs +2 -1
- package/dist/kysely/index.mjs.map +1 -1
- package/dist/{logger-DSdExfor.mjs → logger-D0bEznPv.mjs} +9 -5
- package/dist/{logger-DSdExfor.mjs.map → logger-D0bEznPv.mjs.map} +1 -1
- package/dist/package-json-8b0O9TlX.mjs.map +1 -1
- package/dist/plugin/builtin/enum-constants/index.d.mts +1 -1
- package/dist/plugin/builtin/enum-constants/index.mjs +5 -5
- package/dist/plugin/builtin/enum-constants/index.mjs.map +1 -1
- package/dist/plugin/builtin/file-utils/index.d.mts +1 -1
- package/dist/plugin/builtin/file-utils/index.mjs +14 -11
- package/dist/plugin/builtin/file-utils/index.mjs.map +1 -1
- package/dist/plugin/builtin/kysely-type/index.d.mts +1 -1
- package/dist/plugin/builtin/kysely-type/index.mjs +9 -9
- package/dist/plugin/builtin/kysely-type/index.mjs.map +1 -1
- package/dist/plugin/builtin/seed/index.mjs +1 -1
- package/dist/plugin/builtin/seed/seed-type-processor.d.mts +4 -4
- package/dist/plugin/get-generated-type.d.mts +4 -4
- package/dist/plugin/index.mjs +13 -13
- package/dist/plugin/index.mjs.map +1 -1
- package/dist/plugin/types.d.mts +2 -2
- package/dist/plugin/with-context.d.mts +1 -1
- package/dist/{register-ts-hook-ClI226n2.mjs → register-ts-hook-Vqjza10T.mjs} +552 -416
- package/dist/register-ts-hook-Vqjza10T.mjs.map +1 -0
- package/dist/{repl-editor-BCozyiNq.mjs → repl-editor-F9LotMNx.mjs} +3 -2
- package/dist/{repl-editor-BCozyiNq.mjs.map → repl-editor-F9LotMNx.mjs.map} +1 -1
- package/dist/runtime/file.d.mts +14 -14
- package/dist/{schema--xYWRGfe.mjs → schema-D4TC4BC3.mjs} +4 -3
- package/dist/schema-D4TC4BC3.mjs.map +1 -0
- package/dist/seed/index.d.mts +4 -4
- package/dist/seed/index.mjs +3 -3
- package/dist/seed/index.mjs.map +1 -1
- package/dist/{seed-xqM9WIHP.mjs → seed-Cibjmtry.mjs} +46 -40
- package/dist/seed-Cibjmtry.mjs.map +1 -0
- package/dist/{service-C_WpbKHu.mjs → service-2grcAOCJ.mjs} +24 -24
- package/dist/service-2grcAOCJ.mjs.map +1 -0
- package/dist/service-CaBPNDIZ.mjs +3 -0
- package/dist/{service-hZskxZmg.mjs → service-LTfp03ZZ.mjs} +7 -5
- package/dist/{service-hZskxZmg.mjs.map → service-LTfp03ZZ.mjs.map} +1 -1
- package/dist/types/aigateway.generated.d.mts +2 -2
- package/dist/types/auth.generated.d.mts +3 -3
- package/dist/types/executor.generated.d.mts +1 -1
- package/dist/types/tailordb.generated.d.mts +12 -12
- package/dist/utils/test/index.d.mts +4 -4
- package/dist/utils/test/index.mjs +4 -4
- package/dist/utils/test/index.mjs.map +1 -1
- package/dist/vitest/index.mjs +13 -7
- package/dist/vitest/index.mjs.map +1 -1
- package/dist/vitest/mocks/file.d.mts +1 -1
- package/docs/cli/application.md +3 -1
- package/docs/cli/function.md +17 -13
- package/docs/cli/tailordb.md +30 -30
- package/docs/cli/workspace.md +2 -2
- package/docs/cli-reference.md +21 -21
- package/docs/configuration.md +2 -2
- package/docs/migration/v2.md +4 -4
- package/docs/migration/v3.md +41 -0
- package/docs/quickstart.md +1 -1
- package/docs/services/aigateway.md +33 -9
- package/docs/services/executor.md +5 -1
- package/docs/services/tailordb-migration.md +47 -47
- package/docs/services/tailordb.md +7 -7
- package/docs/testing.md +1 -1
- package/package.json +6 -6
- package/dist/application-BZfk4HKm.mjs +0 -3
- package/dist/application-F-nl107y.mjs.map +0 -1
- package/dist/register-ts-hook-ClI226n2.mjs.map +0 -1
- package/dist/schema--xYWRGfe.mjs.map +0 -1
- package/dist/seed-xqM9WIHP.mjs.map +0 -1
- package/dist/service-C_WpbKHu.mjs.map +0 -1
- package/dist/service-D1RCdzIL.mjs +0 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service-
|
|
1
|
+
{"version":3,"file":"service-LTfp03ZZ.mjs","names":["CLIError"],"sources":["../src/cli/commands/upgrade/version-detector.ts","../src/cli/commands/upgrade/service.ts"],"sourcesContent":["import * as path from \"pathe\";\nimport { readPackageJSON } from \"pkg-types\";\n\nconst SDK_PACKAGE_NAME = \"@tailor-platform/sdk\";\n\n/**\n * Detect the installed SDK version from the user's project.\n * Walks up from projectRoot to find the SDK package in node_modules,\n * matching Node's module resolution for workspace setups with hoisted deps.\n * @param projectRoot - The project root directory to search from\n * @returns The installed SDK version string, or null if not found\n */\nexport async function detectInstalledVersion(projectRoot: string): Promise<string | null> {\n let dir = path.resolve(projectRoot);\n // loop exits when a package.json is found or the root is reached\n // oxlint-disable-next-line typescript/no-unnecessary-condition\n while (true) {\n try {\n const sdkPath = path.join(dir, \"node_modules\", SDK_PACKAGE_NAME);\n const pkg = await readPackageJSON(sdkPath);\n if (pkg.version) return pkg.version;\n } catch {\n // Not found at this level, try parent\n }\n const parent = path.dirname(dir);\n if (parent === dir) break;\n dir = parent;\n }\n return null;\n}\n","import { spawnSync } from \"node:child_process\";\nimport { CLIError } from \"#/cli/shared/errors\";\nimport { logger, styles } from \"#/cli/shared/logger\";\nimport { detectInstalledVersion } from \"./version-detector\";\nimport type { RunOutput } from \"./types\";\n\ninterface UpgradeOptions {\n from: string;\n dryRun: boolean;\n path: string;\n}\n\n/**\n * Print the upgrade summary to the terminal.\n * @param output - The parsed JSON output from sdk-codemod\n * @param dryRun - Whether this was a dry-run\n */\nfunction printUpgradeSummary(output: RunOutput, dryRun: boolean): void {\n if (dryRun) {\n logger.info(`${styles.bold(\"[Dry Run]\")} No files were modified.`);\n logger.log(\"\");\n }\n\n const total = output.codemodsApplied + output.codemodsSkipped + output.errors.length;\n logger.info(\n `Upgrade complete: ${styles.success(`${output.codemodsApplied} applied`)}, ${styles.dim(`${output.codemodsSkipped} skipped`)} (${total} total codemods)`,\n );\n\n if (output.filesModified.length > 0) {\n logger.log(\"\");\n logger.info(\n `${dryRun ? \"Files that would be modified\" : \"Modified files\"} (${output.filesModified.length}):`,\n );\n for (const file of output.filesModified) {\n logger.log(` ${styles.path(file)}`);\n }\n }\n\n if (output.warnings.length > 0) {\n logger.log(\"\");\n logger.warn(`Manual attention needed (${output.warnings.length}):`);\n for (const warning of output.warnings) {\n logger.log(` ${styles.warning(\"!\")} ${warning}`);\n }\n }\n\n if (output.errors.length > 0) {\n logger.log(\"\");\n logger.error(`Failed codemods (${output.errors.length}):`);\n for (const { codemodId, message } of output.errors) {\n logger.log(` ${styles.error(codemodId)}: ${message}`);\n }\n }\n}\n\n/**\n * Run the upgrade pipeline:\n * 1. Detect target SDK version from node_modules\n * 2. Invoke @tailor-platform/sdk-codemod CLI\n * 3. Parse JSON output and display results\n * @param options - Upgrade options\n */\nexport async function upgrade(options: UpgradeOptions): Promise<void> {\n const projectRoot = options.path;\n\n // Step 1: Detect target SDK version (the newly installed version)\n const targetVersion = await detectInstalledVersion(projectRoot);\n if (!targetVersion) {\n throw CLIError({\n message: `Could not detect installed @tailor-platform/sdk version in ${projectRoot}`,\n suggestion:\n \"Ensure @tailor-platform/sdk is installed. Run 'pnpm install' or 'npm install' first.\",\n command: \"upgrade\",\n });\n }\n\n logger.info(\n `Upgrading from ${styles.highlight(options.from)} → ${styles.highlight(targetVersion)}`,\n );\n\n if (options.dryRun) {\n logger.info(`${styles.bold(\"[Dry Run]\")} Changes will be previewed but not applied.`);\n }\n\n logger.log(\"\");\n\n // Step 2: Invoke sdk-codemod CLI\n // Use \"latest\" because sdk-codemod may not be published at the exact same\n // version as @tailor-platform/sdk. Version filtering is handled internally\n // by sdk-codemod's registry via the --from / --to arguments.\n const npxCommand = process.platform === \"win32\" ? \"npx.cmd\" : \"npx\";\n\n const result = spawnSync(\n npxCommand,\n [\n \"@tailor-platform/sdk-codemod@latest\",\n \"--from\",\n options.from,\n \"--to\",\n targetVersion,\n \"--target\",\n projectRoot,\n ...(options.dryRun ? [\"--dry-run\"] : []),\n ],\n {\n cwd: projectRoot,\n stdio: [\"ignore\", \"pipe\", \"pipe\"],\n encoding: \"utf-8\",\n timeout: 300_000,\n },\n );\n\n if (result.error) {\n throw CLIError({\n message: `Failed to run @tailor-platform/sdk-codemod: ${result.error.message}`,\n suggestion: \"Ensure npx is available and the network is accessible.\",\n command: \"upgrade\",\n });\n }\n\n // Check for non-zero exit without a launch error (e.g. registry/auth/network failures)\n if (result.status !== 0 && !result.stdout.trim()) {\n throw CLIError({\n message: `@tailor-platform/sdk-codemod exited with code ${result.status}`,\n details: result.stderr.trim() || \"(no stderr output)\",\n suggestion:\n \"Review the error above. Common causes: invalid version arguments, network issues, or missing package registry access.\",\n command: \"upgrade\",\n });\n }\n\n // Forward captured stderr so users see dry-run diffs and progress messages\n // written by sdk-codemod. stderr is piped (not inherited) so that the error\n // path above can surface it via CLIError, but on success we still need to\n // replay it verbatim to keep the colorized unified diff output visible.\n if (result.stderr) {\n process.stderr.write(result.stderr);\n }\n\n // Step 3: Parse JSON output\n let output: RunOutput;\n try {\n output = JSON.parse(result.stdout);\n } catch {\n throw CLIError({\n message: \"Failed to parse output from @tailor-platform/sdk-codemod\",\n details: result.stdout || \"(empty stdout)\",\n suggestion: \"This is likely a bug. Please report it.\",\n command: \"upgrade\",\n });\n }\n\n // Step 4: Display results\n // Emit structured data on stdout (honors --json via logger.out) and\n // human-readable summary on stderr (via printUpgradeSummary).\n logger.out(output);\n printUpgradeSummary(output, options.dryRun);\n\n if (output.errors.length > 0) {\n throw CLIError({\n message: `Upgrade completed with ${output.errors.length} error(s)`,\n suggestion: \"Review the errors above and re-run the upgrade after fixing the issues.\",\n command: \"upgrade\",\n });\n }\n}\n"],"mappings":";;;;;;;AAGA,MAAM,mBAAmB;;;;;;;;AASzB,eAAsB,uBAAuB,aAA6C;CACxF,IAAI,MAAM,KAAK,QAAQ,WAAW;CAGlC,OAAO,MAAM;EACX,IAAI;GACF,MAAM,UAAU,KAAK,KAAK,KAAK,gBAAgB,gBAAgB;GAC/D,MAAM,MAAM,MAAM,gBAAgB,OAAO;GACzC,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
@@ -2,8 +2,8 @@
|
|
|
2
2
|
type AIGateway = {
|
|
3
3
|
/** AI Gateway name */
|
|
4
4
|
name: string;
|
|
5
|
-
/** Auth namespace used to resolve request tokens against the workspace's auth */
|
|
6
|
-
authNamespace
|
|
5
|
+
/** Auth namespace used to resolve request tokens against the workspace's auth. Defaults to the application's own auth service when omitted; omitting it without an Auth service configured is rejected. */
|
|
6
|
+
authNamespace?: string | undefined;
|
|
7
7
|
/** Allowed CORS origins for browser-based clients. Each entry is `*`, `http(s)://*`, `http(s)://*.example.com`, or `http(s)://app.example.com`, optionally with `:port`. Empty list disables cross-origin access. */
|
|
8
8
|
cors?: string[] | undefined;
|
|
9
9
|
};
|
|
@@ -138,7 +138,7 @@ type SCIMResource = {
|
|
|
138
138
|
name: string;
|
|
139
139
|
/** TailorDB namespace for the resource */
|
|
140
140
|
tailorDBNamespace: string;
|
|
141
|
-
/** TailorDB
|
|
141
|
+
/** TailorDB table name for the resource */
|
|
142
142
|
tailorDBType: string;
|
|
143
143
|
/** Core SCIM schema definition */
|
|
144
144
|
coreSchema: {
|
|
@@ -177,9 +177,9 @@ type SCIMConfig = {
|
|
|
177
177
|
resources: SCIMResource[];
|
|
178
178
|
};
|
|
179
179
|
type TenantProvider = {
|
|
180
|
-
/** TailorDB namespace for the tenant
|
|
180
|
+
/** TailorDB namespace for the tenant table */
|
|
181
181
|
namespace: string;
|
|
182
|
-
/** TailorDB
|
|
182
|
+
/** TailorDB table name for tenants */
|
|
183
183
|
type: string;
|
|
184
184
|
/** Field used as the tenant signature */
|
|
185
185
|
signatureField: string;
|
|
@@ -4,7 +4,7 @@ type TailorDBTrigger = {
|
|
|
4
4
|
kind: "tailordb";
|
|
5
5
|
/** TailorDB event types to trigger on */
|
|
6
6
|
events: ("tailordb.type_record.created" | "tailordb.type_record.updated" | "tailordb.type_record.deleted")[];
|
|
7
|
-
/** TailorDB
|
|
7
|
+
/** TailorDB table name to watch for events */
|
|
8
8
|
typeName: string;
|
|
9
9
|
/** Condition function to filter events */
|
|
10
10
|
condition?: Function | undefined;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
//#region src/types/tailordb.generated.d.ts
|
|
2
2
|
/**
|
|
3
|
-
* Configuration for GraphQL operations on a TailorDB
|
|
3
|
+
* Configuration for GraphQL operations on a TailorDB table.
|
|
4
4
|
* All operations are enabled by default (undefined or true = enabled, false = disabled).
|
|
5
5
|
*/
|
|
6
6
|
type GqlOperationsInput = "query" | {
|
|
@@ -41,7 +41,7 @@ type DBFieldMetadata = {
|
|
|
41
41
|
vector?: boolean | undefined;
|
|
42
42
|
/** Whether the field is a foreign key */
|
|
43
43
|
foreignKey?: boolean | undefined;
|
|
44
|
-
/** Target
|
|
44
|
+
/** Target table name for foreign key relations */
|
|
45
45
|
foreignKeyType?: string | undefined;
|
|
46
46
|
/** Target field name for foreign key relations */
|
|
47
47
|
foreignKeyField?: string | undefined;
|
|
@@ -69,20 +69,20 @@ type DBFieldMetadata = {
|
|
|
69
69
|
default?: unknown;
|
|
70
70
|
};
|
|
71
71
|
type TailorDBTypeParsedSettings = {
|
|
72
|
-
/** Custom plural form of the
|
|
72
|
+
/** Custom plural form of the table name for GraphQL */
|
|
73
73
|
pluralForm?: string | undefined;
|
|
74
|
-
/** Enable aggregation queries for this
|
|
74
|
+
/** Enable aggregation queries for this table */
|
|
75
75
|
aggregation?: boolean | undefined;
|
|
76
|
-
/** Enable bulk upsert mutation for this
|
|
76
|
+
/** Enable bulk upsert mutation for this table */
|
|
77
77
|
bulkUpsert?: boolean | undefined;
|
|
78
|
-
/** Configure GraphQL operations for this
|
|
78
|
+
/** Configure GraphQL operations for this table. Use "query" for read-only mode, or an object for granular control. */
|
|
79
79
|
gqlOperations?: GqlOperations;
|
|
80
80
|
/**
|
|
81
|
-
* Enable publishing events for this
|
|
81
|
+
* Enable publishing events for this table.
|
|
82
82
|
* When enabled, record creation/update/deletion events are published.
|
|
83
|
-
* If not specified, this is automatically set to true when an executor uses this
|
|
83
|
+
* If not specified, this is automatically set to true when an executor uses this table
|
|
84
84
|
* with recordCreated/recordUpdated/recordDeleted triggers. If explicitly set to false
|
|
85
|
-
* while an executor uses this
|
|
85
|
+
* while an executor uses this table, an error will be thrown during apply.
|
|
86
86
|
*/
|
|
87
87
|
publishEvents?: boolean | undefined;
|
|
88
88
|
};
|
|
@@ -441,9 +441,9 @@ type RawPermissions = {
|
|
|
441
441
|
}[] | undefined;
|
|
442
442
|
};
|
|
443
443
|
type TailorDBServiceConfigInput = {
|
|
444
|
-
/** Glob patterns for TailorDB
|
|
444
|
+
/** Glob patterns for TailorDB table definition files */
|
|
445
445
|
files: string[];
|
|
446
|
-
/** Glob patterns to exclude from
|
|
446
|
+
/** Glob patterns to exclude from table discovery */
|
|
447
447
|
ignores?: string[] | undefined;
|
|
448
448
|
/** Migration configuration */
|
|
449
449
|
migration?: {
|
|
@@ -452,7 +452,7 @@ type TailorDBServiceConfigInput = {
|
|
|
452
452
|
/** Machine user name for migration execution */
|
|
453
453
|
machineUser?: string | undefined;
|
|
454
454
|
} | undefined;
|
|
455
|
-
/** Default GraphQL operations for all
|
|
455
|
+
/** Default GraphQL operations for all tables in this service */
|
|
456
456
|
gqlOperations?: "query" | {
|
|
457
457
|
/** Enable create mutation (default: true) */
|
|
458
458
|
create?: boolean | undefined;
|
|
@@ -4,7 +4,7 @@ import { output } from "../../configure/index.mjs";
|
|
|
4
4
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
5
5
|
//#region src/utils/test/index.d.ts
|
|
6
6
|
/**
|
|
7
|
-
* Creates a hook function that processes TailorDB
|
|
7
|
+
* Creates a hook function that processes TailorDB table fields
|
|
8
8
|
* - Uses existing id from data if provided, otherwise generates UUID for id fields
|
|
9
9
|
* - Recursively processes nested types
|
|
10
10
|
* - Executes hooks.create for fields with create hooks
|
|
@@ -12,19 +12,19 @@ import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
|
12
12
|
* member of `Object` such as `toString` is read from the record rather than
|
|
13
13
|
* from the prototype
|
|
14
14
|
* @template T - The output type of the hook function
|
|
15
|
-
* @param type - TailorDB
|
|
15
|
+
* @param type - TailorDB table definition
|
|
16
16
|
* @returns A function that transforms input data according to field hooks
|
|
17
17
|
*/
|
|
18
18
|
declare function createTailorDBHook<T extends TailorDBType<any, any>>(type: T): (data: unknown, now?: Date) => Partial<output<T>>;
|
|
19
19
|
/**
|
|
20
20
|
* Creates the standard schema definition used to validate seed rows.
|
|
21
|
-
* Runs the hook, then the
|
|
21
|
+
* Runs the hook, then the table's own `validate`, and the field schema only when
|
|
22
22
|
* that reported nothing, so both levels of validation report as issues rather
|
|
23
23
|
* than by throwing.
|
|
24
24
|
* @template T - The output type after validation
|
|
25
25
|
* @param schemaType - TailorDB field schema for validation
|
|
26
26
|
* @param hook - Hook function to transform data before validation
|
|
27
|
-
* @param type - TailorDB
|
|
27
|
+
* @param type - TailorDB table definition, when it carries a table-level `validate`
|
|
28
28
|
* @returns Schema object with ~standard section for defineSchema
|
|
29
29
|
*/
|
|
30
30
|
declare function createStandardSchema<T = Record<string, unknown>>(schemaType: TailorField<any, T>, hook: (data: unknown) => Partial<T>, type?: TailorDBType<any, any>): {
|
|
@@ -8,7 +8,7 @@ function setField(record, key, value) {
|
|
|
8
8
|
});
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
|
-
* Creates a hook function that processes TailorDB
|
|
11
|
+
* Creates a hook function that processes TailorDB table fields
|
|
12
12
|
* - Uses existing id from data if provided, otherwise generates UUID for id fields
|
|
13
13
|
* - Recursively processes nested types
|
|
14
14
|
* - Executes hooks.create for fields with create hooks
|
|
@@ -16,7 +16,7 @@ function setField(record, key, value) {
|
|
|
16
16
|
* member of `Object` such as `toString` is read from the record rather than
|
|
17
17
|
* from the prototype
|
|
18
18
|
* @template T - The output type of the hook function
|
|
19
|
-
* @param type - TailorDB
|
|
19
|
+
* @param type - TailorDB table definition
|
|
20
20
|
* @returns A function that transforms input data according to field hooks
|
|
21
21
|
*/
|
|
22
22
|
function createTailorDBHook(type) {
|
|
@@ -77,13 +77,13 @@ function typeLevelIssues(type, hooked) {
|
|
|
77
77
|
}
|
|
78
78
|
/**
|
|
79
79
|
* Creates the standard schema definition used to validate seed rows.
|
|
80
|
-
* Runs the hook, then the
|
|
80
|
+
* Runs the hook, then the table's own `validate`, and the field schema only when
|
|
81
81
|
* that reported nothing, so both levels of validation report as issues rather
|
|
82
82
|
* than by throwing.
|
|
83
83
|
* @template T - The output type after validation
|
|
84
84
|
* @param schemaType - TailorDB field schema for validation
|
|
85
85
|
* @param hook - Hook function to transform data before validation
|
|
86
|
-
* @param type - TailorDB
|
|
86
|
+
* @param type - TailorDB table definition, when it carries a table-level `validate`
|
|
87
87
|
* @returns Schema object with ~standard section for defineSchema
|
|
88
88
|
*/
|
|
89
89
|
function createStandardSchema(schemaType, hook, type) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/utils/test/index.ts"],"sourcesContent":["import type { output } from \"#/configure/index\";\nimport type { TailorDBType } from \"#/configure/services/tailordb/schema\";\nimport type { TailorField } from \"#/configure/types/type\";\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\n\n// Not `record[key] = value`: assigning to `__proto__` goes through the inherited\n// setter, which mutates the prototype instead of recording the field and leaves\n// no own property behind for the value to be read from.\nfunction setField(record: Record<string, unknown>, key: string, value: unknown): void {\n Object.defineProperty(record, key, {\n value,\n enumerable: true,\n writable: true,\n configurable: true,\n });\n}\n\n/**\n * Creates a hook function that processes TailorDB
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/utils/test/index.ts"],"sourcesContent":["import type { output } from \"#/configure/index\";\nimport type { TailorDBType } from \"#/configure/services/tailordb/schema\";\nimport type { TailorField } from \"#/configure/types/type\";\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\n\n// Not `record[key] = value`: assigning to `__proto__` goes through the inherited\n// setter, which mutates the prototype instead of recording the field and leaves\n// no own property behind for the value to be read from.\nfunction setField(record: Record<string, unknown>, key: string, value: unknown): void {\n Object.defineProperty(record, key, {\n value,\n enumerable: true,\n writable: true,\n configurable: true,\n });\n}\n\n/**\n * Creates a hook function that processes TailorDB table fields\n * - Uses existing id from data if provided, otherwise generates UUID for id fields\n * - Recursively processes nested types\n * - Executes hooks.create for fields with create hooks\n * - Takes each field from the data's own properties, so a field named after a\n * member of `Object` such as `toString` is read from the record rather than\n * from the prototype\n * @template T - The output type of the hook function\n * @param type - TailorDB table definition\n * @returns A function that transforms input data according to field hooks\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function createTailorDBHook<T extends TailorDBType<any, any>>(type: T) {\n return (data: unknown, now: Date = new Date()) => {\n const obj = data && typeof data === \"object\" ? (data as Record<string, unknown>) : undefined;\n const hooked = Object.entries(type.fields).reduce(\n (hooked, [key, value]) => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const field = value as TailorField<any, any, any>;\n // `Object.hasOwn`, not `obj?.[key]`: a field named after an Object member\n // such as `toString` would otherwise read the inherited value.\n const input = obj && Object.hasOwn(obj, key) ? obj[key] : undefined;\n let hookedValue: unknown;\n if (key === \"id\") {\n hookedValue = input ?? crypto.randomUUID();\n } else if (field.type === \"nested\") {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const nestedHook = createTailorDBHook({ fields: field.fields } as any);\n if (field.metadata.array) {\n hookedValue = Array.isArray(input) ? input.map((item) => nestedHook(item, now)) : input;\n } else {\n hookedValue = nestedHook(input, now);\n }\n } else if (field.metadata.hooks?.create) {\n hookedValue = field.metadata.hooks.create({ input, invoker: null, now });\n if (hookedValue instanceof Date) {\n hookedValue = hookedValue.toISOString();\n }\n } else {\n hookedValue = input;\n }\n if (hookedValue == null && field.metadata.default !== undefined) {\n const isTimeType =\n field.type === \"datetime\" || field.type === \"date\" || field.type === \"time\";\n hookedValue =\n field.metadata.default === \"now\" && isTimeType\n ? now.toISOString()\n : field.metadata.default;\n }\n // Set even when there is no value: the key carrying `undefined` is what\n // tells a schema inferred from the record that the column is nullable,\n // and it shadows a same-named member of `Object.prototype`.\n setField(hooked, key, hookedValue);\n return hooked;\n },\n {} as Record<string, unknown>,\n );\n\n // oxlint-disable-next-line typescript/no-unnecessary-condition -- metadata absent in recursive nested calls\n if (type.metadata?.typeHook?.create) {\n const { id: _id, ...typeHookInput } = hooked;\n // oxlint-disable-next-line typescript/no-unsafe-function-type\n const overrides = (type.metadata.typeHook.create as Function)({\n input: typeHookInput,\n invoker: null,\n now,\n });\n if (overrides && typeof overrides === \"object\") {\n for (const [key, value] of Object.entries(overrides as Record<string, unknown>)) {\n setField(hooked, key, value instanceof Date ? value.toISOString() : value);\n }\n }\n }\n\n return hooked as Partial<output<T>>;\n };\n}\n\n// Collect the issues the table's own `validate` reports for a record, so they\n// surface the same way a field's do instead of ending the run.\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction typeLevelIssues(type: TailorDBType<any, any> | undefined, hooked: unknown) {\n // oxlint-disable-next-line typescript/no-unnecessary-condition -- absent on a nested type\n const typeValidate = type?.metadata?.typeValidate;\n if (!typeValidate) {\n return [];\n }\n const { id: _id, ...newRecord } = hooked as Record<string, unknown>;\n const issues: StandardSchemaV1.Issue[] = [];\n // oxlint-disable-next-line typescript/no-unsafe-function-type\n (typeValidate as Function)(\n { newRecord, oldRecord: null, invoker: null },\n (field: string, message: string) => {\n issues.push({ message, path: [field] });\n },\n );\n return issues;\n}\n\n/**\n * Creates the standard schema definition used to validate seed rows.\n * Runs the hook, then the table's own `validate`, and the field schema only when\n * that reported nothing, so both levels of validation report as issues rather\n * than by throwing.\n * @template T - The output type after validation\n * @param schemaType - TailorDB field schema for validation\n * @param hook - Hook function to transform data before validation\n * @param type - TailorDB table definition, when it carries a table-level `validate`\n * @returns Schema object with ~standard section for defineSchema\n */\nexport function createStandardSchema<T = Record<string, unknown>>(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n schemaType: TailorField<any, T>,\n hook: (data: unknown) => Partial<T>,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n type?: TailorDBType<any, any>,\n) {\n return {\n \"~standard\": {\n version: 1,\n vendor: \"@tailor-platform/sdk\",\n validate: (value: unknown) => {\n const hooked = hook(value);\n const issues = typeLevelIssues(type, hooked);\n if (issues.length > 0) {\n return { issues };\n }\n const result = schemaType.parse({\n value: hooked,\n data: hooked,\n invoker: null,\n });\n if (result.issues) {\n return result;\n }\n return { value: hooked as T };\n },\n },\n } as const satisfies StandardSchemaV1<T>;\n}\n"],"mappings":";AAQA,SAAS,SAAS,QAAiC,KAAa,OAAsB;CACpF,OAAO,eAAe,QAAQ,KAAK;EACjC;EACA,YAAY;EACZ,UAAU;EACV,cAAc;CAChB,CAAC;AACH;;;;;;;;;;;;;AAeA,SAAgB,mBAAqD,MAAS;CAC5E,QAAQ,MAAe,sBAAY,IAAI,KAAK,MAAM;EAChD,MAAM,MAAM,QAAQ,OAAO,SAAS,WAAY,OAAmC;EACnF,MAAM,SAAS,OAAO,QAAQ,KAAK,MAAM,CAAC,CAAC,QACxC,QAAQ,CAAC,KAAK,WAAW;GAExB,MAAM,QAAQ;GAGd,MAAM,QAAQ,OAAO,OAAO,OAAO,KAAK,GAAG,IAAI,IAAI,OAAO;GAC1D,IAAI;GACJ,IAAI,QAAQ,MACV,cAAc,SAAS,OAAO,WAAW;QACpC,IAAI,MAAM,SAAS,UAAU;IAElC,MAAM,aAAa,mBAAmB,EAAE,QAAQ,MAAM,OAAO,CAAQ;IACrE,IAAI,MAAM,SAAS,OACjB,cAAc,MAAM,QAAQ,KAAK,IAAI,MAAM,KAAK,SAAS,WAAW,MAAM,GAAG,CAAC,IAAI;SAElF,cAAc,WAAW,OAAO,GAAG;GAEvC,OAAO,IAAI,MAAM,SAAS,OAAO,QAAQ;IACvC,cAAc,MAAM,SAAS,MAAM,OAAO;KAAE;KAAO,SAAS;KAAM;IAAI,CAAC;IACvE,IAAI,uBAAuB,MACzB,cAAc,YAAY,YAAY;GAE1C,OAC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AAS;GACX,CAAC;GACD,IAAI,OAAO,QACT,OAAO;GAET,OAAO,EAAE,OAAO,OAAY;EAC9B;CACF,EACF;AACF"}
|
package/dist/vitest/index.mjs
CHANGED
|
@@ -253,7 +253,8 @@ function createEnvironmentPlugin(options) {
|
|
|
253
253
|
}
|
|
254
254
|
delete process.env.__TAILOR_RUNTIME_CONFIG;
|
|
255
255
|
if (options?.config && usesTailorRuntime) {
|
|
256
|
-
const
|
|
256
|
+
const configRoot = config.root ?? process.cwd();
|
|
257
|
+
const configAbsPath = resolve(configRoot, options.config);
|
|
257
258
|
process.env.__TAILOR_RUNTIME_CONFIG = configAbsPath;
|
|
258
259
|
}
|
|
259
260
|
if (testConfig && typeof testConfig.setupFiles === "string") testConfig.setupFiles = [testConfig.setupFiles];
|
|
@@ -521,7 +522,7 @@ function mockFile(options = {}) {
|
|
|
521
522
|
function allMocks() {
|
|
522
523
|
return FILE_METHODS.map((method) => mocks[method]);
|
|
523
524
|
}
|
|
524
|
-
|
|
525
|
+
const facade = {
|
|
525
526
|
...mocks,
|
|
526
527
|
setResolver(value) {
|
|
527
528
|
resolver = value;
|
|
@@ -555,7 +556,8 @@ function mockFile(options = {}) {
|
|
|
555
556
|
resolver = () => null;
|
|
556
557
|
for (const mock of allMocks()) mock.mockReset();
|
|
557
558
|
}
|
|
558
|
-
}
|
|
559
|
+
};
|
|
560
|
+
return withDispose(facade, () => {
|
|
559
561
|
root.file = prev;
|
|
560
562
|
});
|
|
561
563
|
}
|
|
@@ -1368,7 +1370,8 @@ function mockWorkflow() {
|
|
|
1368
1370
|
*/
|
|
1369
1371
|
setResolvePayload(payload) {
|
|
1370
1372
|
resolveSpy.mockImplementation(async (_executionId, callback) => {
|
|
1371
|
-
|
|
1373
|
+
const result = await callback(platformSerialize(payload));
|
|
1374
|
+
platformSerialize(result);
|
|
1372
1375
|
});
|
|
1373
1376
|
}
|
|
1374
1377
|
};
|
|
@@ -1399,7 +1402,8 @@ function mockWorkflow() {
|
|
|
1399
1402
|
*/
|
|
1400
1403
|
setResolvePayload(payload) {
|
|
1401
1404
|
resolveSpy.mockImplementation(async (_executionId, callback) => {
|
|
1402
|
-
|
|
1405
|
+
const result = await callback(platformSerialize(payload));
|
|
1406
|
+
platformSerialize(result);
|
|
1403
1407
|
});
|
|
1404
1408
|
}
|
|
1405
1409
|
};
|
|
@@ -1559,8 +1563,10 @@ async function runWorkflowLocally(workflow, args, options) {
|
|
|
1559
1563
|
} finally {
|
|
1560
1564
|
if (previousTailor) root.tailor = previousTailor;
|
|
1561
1565
|
else delete root.tailor;
|
|
1562
|
-
if (options?.env !== void 0)
|
|
1563
|
-
|
|
1566
|
+
if (options?.env !== void 0) {
|
|
1567
|
+
if (hasPreviousEnv) writeWorkflowTestEnv(previousEnv);
|
|
1568
|
+
else clearWorkflowTestEnv();
|
|
1569
|
+
}
|
|
1564
1570
|
}
|
|
1565
1571
|
}
|
|
1566
1572
|
function createLocalJobRunner() {
|