@tailor-platform/sdk 1.49.0 → 1.50.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 CHANGED
@@ -1,5 +1,40 @@
1
1
  # @tailor-platform/sdk
2
2
 
3
+ ## 1.50.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#1226](https://github.com/tailor-platform/sdk/pull/1226) [`d900ddc`](https://github.com/tailor-platform/sdk/commit/d900ddcba170a5effe2119fb37e3e038d5cd5935) Thanks [@remiposo](https://github.com/remiposo)! - Fix `deploy` to no longer delete the application when its `id` is regenerated
8
+ (e.g. CI working tree without a committed `id` in `tailor.config.ts`).
9
+
10
+ ## 1.50.0
11
+
12
+ ### Minor Changes
13
+
14
+ - [#1223](https://github.com/tailor-platform/sdk/pull/1223) [`c2f078d`](https://github.com/tailor-platform/sdk/commit/c2f078d6fb82d42bcc8c040e020b34072a2d2eb6) Thanks [@toiroakr](https://github.com/toiroakr)! - Improve `tailordb migration` handling of data-loss-possible changes:
15
+
16
+ - Removed fields (`field_removed`) and removed types (`type_removed`) are now reported as **warnings** during `tailordb migration generate`, not silent changes. They are no longer dropped before `migrate.ts` runs: the field/type stays available during the Pre-migration phase so that scripts can read it (e.g. `innerJoin` through a foreign key that is being dropped in the same migration), then the physical drop happens in the Post-migration phase.
17
+ - Add `tailordb migration script <number>` subcommand to add a `migrate.ts` (and `db.ts`) template to an existing migration directory. Useful for warning-tier changes where you want a custom data migration even though one was not generated automatically.
18
+ - `migrate.ts` is now executed whenever the file exists on disk for a pending migration, regardless of whether the diff originally required a script. Breaking changes still hard-require a script as before.
19
+
20
+ ### Patch Changes
21
+
22
+ - [#1194](https://github.com/tailor-platform/sdk/pull/1194) [`4c227cc`](https://github.com/tailor-platform/sdk/commit/4c227cc404e51331c0514b0aaa07d96d8940c347) Thanks [@toiroakr](https://github.com/toiroakr)! - Colocate `src/vitest/` tests next to their sources (drop the
23
+ `src/vitest/__tests__/` directory). Vitest discovers the test files
24
+ via the existing `**/?(*.)+(spec|test).ts` include pattern, so the
25
+ `**/__tests__/**/*.ts` entry has been removed from `vitest.config.ts`.
26
+ The nested integration runner moves from
27
+ `src/vitest/__tests__/integration/` to `src/vitest/integration/`. Pure
28
+ refactor: no public API or behavior changes.
29
+
30
+ - [#1207](https://github.com/tailor-platform/sdk/pull/1207) [`c0b392d`](https://github.com/tailor-platform/sdk/commit/c0b392d95f81bcb2a4bfd9e856183222da87ef06) Thanks [@toiroakr](https://github.com/toiroakr)! - Fix `tailor deploy` so an intermediate migration's data script can still read fields that a later migration removes. Each migration's pre/post phase now submits the schema state reconstructed up to that migration (initial baseline + diffs through N), instead of the FINAL post-all-migrations schema. Previously, removals declared in later migrations leaked into earlier migrations' pre-phase and caused `field 'X' not found` failures at script execution time.
31
+
32
+ - [#1208](https://github.com/tailor-platform/sdk/pull/1208) [`59d7e0e`](https://github.com/tailor-platform/sdk/commit/59d7e0e7c1b42dcd1571365780114d596e44350c) Thanks [@toiroakr](https://github.com/toiroakr)! - fix(skills): rename bundled skill directory to `agent-skills/` so `gh skill install tailor-platform/sdk` resolves a single skill. `gh skill` uses a recursive `**/skills/*/SKILL.md` match and was picking up both `skills/tailor-sdk/` (the public mirror) and `packages/sdk/skills/tailor-sdk/` (the npm bundle), erroring with conflicting names. The bundled copy is now under `packages/sdk/agent-skills/` (excluded from gh's match), while the repo-root `skills/` mirror remains the single discovery target for `gh skill install` and `npx skills add <repo>`. `npx tailor-sdk skills install` continues to work via the bundled `agent-skills/` path inside the published package.
33
+
34
+ - [#1217](https://github.com/tailor-platform/sdk/pull/1217) [`b827cf9`](https://github.com/tailor-platform/sdk/commit/b827cf95c0c048959c269f7ed9a31fdc81a5eb13) Thanks [@renovate](https://github.com/apps/renovate)! - fix(deps): update dependency @toiroakr/read-multiline to v0.4.1
35
+
36
+ - [#1184](https://github.com/tailor-platform/sdk/pull/1184) [`dee2ad7`](https://github.com/tailor-platform/sdk/commit/dee2ad7199b2da238b7e9edea2d9bb9605033456) Thanks [@toiroakr](https://github.com/toiroakr)! - Fix `tailor deploy` so decimal fields without an explicit `scale` no longer show spurious drift against the platform (which materializes the default `6`). Deploy now plans and applies through the same snapshot pipeline as `tailordb migrate`.
37
+
3
38
  ## 1.49.0
4
39
 
5
40
  ### Minor Changes
package/README.md CHANGED
@@ -60,7 +60,7 @@ npx tailor-sdk skills install -a codex -y
60
60
  ```
61
61
 
62
62
  This uses the `skills` CLI under the hood, sourcing the skill from
63
- `node_modules/@tailor-platform/sdk/skills` so the skill version always matches
63
+ `node_modules/@tailor-platform/sdk/agent-skills` so the skill version always matches
64
64
  the installed SDK version. Files are copied (not symlinked) so they survive
65
65
  `pnpm install` wiping `node_modules`.
66
66
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  import { G as PATScope, R as AuthInvokerSchema, c as fetchUserInfo, d as initOperatorClient, h as userAgent, i as fetchAll, j as FunctionExecution_Type, n as closeConnectionPool, o as fetchPaged, s as fetchPlatformMachineUserToken, u as initOAuth2Client } from "../client-_kHh0Pip.mjs";
4
4
  import { n as logger, r as styles } from "../logger-DTNAMYGy.mjs";
5
- import { $ as deleteCommand$3, At as executionsCommand, C as listCommand$13, Cn as paginationArgs, Ct as jobsCommand, E as resumeCommand, Et as startCommand, F as showCommand, Ft as getCommand$1, G as getCommand$5, H as treeCommand, I as logBetaWarning, Lt as deploy, N as generateCommand$1, Nt as functionExecutionStatusToString, O as listCommand$12, Ot as getCommand$6, Pt as formatKeyValueTable, R as removeCommand$1, Rt as executeScript, Sn as pagedLogArgs, T as healthCommand, Tn as workspaceArgs, U as listCommand$11, Vt as parseMigrationLabelNumber, Y as listCommand$10, Z as getCommand$4, Zt as formatMigrationNumber, _n as defineAppCommand, _t as webhookCommand, at as getCommand$3, b as createCommand$4, bn as deploymentArgs, bt as listCommand$6, c as listCommand$14, ct as tokenCommand, dn as trnPrefix, dt as generate, en as getMigrationFilePath, f as restoreCommand, ft as listCommand$7, g as getCommand$7, gn as assertWritable, i as updateCommand$4, in as loadDiff, j as truncateCommand, ln as getNamespacesWithMigrations, lt as listCommand$8, m as listCommand$15, mn as apiCommand, mt as getCommand$2, o as removeCommand, pn as prompt, q as updateCommand$2, r as queryCommand, rn as isValidMigrationNumber, rt as listCommand$9, t as isNativeTypeScriptRuntime, tn as getMigrationFiles, tt as createCommand$3, u as inviteCommand, un as sdkNameLabelKey, v as deleteCommand$4, vn as commonArgs, vt as triggerCommand, wn as toPageDirection, xn as isVerbose, yn as confirmationArgs, z as updateCommand$3 } from "../runtime-oZgK353r.mjs";
5
+ import { $ as listCommand$10, An as workspaceArgs, At as startCommand, B as logBetaWarning, C as listCommand$13, Cn as configArg, Dn as pagedLogArgs, Dt as jobsCommand, E as resumeCommand, En as isVerbose, F as writeDbTypesFile, Gt as parseMigrationLabelNumber, H as removeCommand$1, Ht as executeScript, I as getConfiguredEditorCommand, K as treeCommand, L as openInConfiguredEditor, Lt as functionExecutionStatusToString, Mt as getCommand$6, N as generateCommand$1, O as listCommand$12, On as paginationArgs, P as generateMigrationScript, Pt as executionsCommand, Rt as formatKeyValueTable, Sn as commonArgs, St as triggerCommand, T as healthCommand, Tn as deploymentArgs, U as updateCommand$3, Vt as deploy, Y as getCommand$5, Yt as INITIAL_SCHEMA_NUMBER, Z as updateCommand$2, _n as prompt, an as getMigrationFiles, at as createCommand$3, b as createCommand$4, bn as assertWritable, c as listCommand$14, cn as loadDiff, f as restoreCommand, ft as tokenCommand, g as getCommand$7, gt as listCommand$7, hn as trnPrefix, ht as generate, i as updateCommand$4, in as getMigrationFilePath, j as truncateCommand, kn as toPageDirection, ln as reconstructSnapshotFromMigrations, lt as getCommand$3, m as listCommand$15, mn as sdkNameLabelKey, o as removeCommand, pn as getNamespacesWithMigrations, pt as listCommand$8, q as listCommand$11, r as queryCommand, rt as deleteCommand$3, sn as isValidMigrationNumber, st as listCommand$9, t as isNativeTypeScriptRuntime, tn as formatMigrationNumber, tt as getCommand$4, u as inviteCommand, v as deleteCommand$4, vn as apiCommand, vt as getCommand$2, wn as confirmationArgs, wt as listCommand$6, xn as defineAppCommand, xt as webhookCommand, z as showCommand, zt as getCommand$1 } from "../runtime-DgsMnMrO.mjs";
6
6
  import { D as saveUserTokens, E as resolveTokens, O as writePlatformConfig, S as loadAccessToken, T as readPlatformConfig, _ as getDistDir, a as WorkflowJobSchema, b as deleteUserTokens, c as ExecutorSchema, i as resolveInlineSourcemap, l as INVOKER_EXPR, o as ResolverSchema, w as loadWorkspaceId, x as fetchLatestToken, y as loadConfig } from "../application-CZMzt9jL.mjs";
7
7
  import { t as multiline } from "../multiline-e3IpANmS.mjs";
8
8
  import { t as readPackageJson } from "../package-json-6Px8bDpG.mjs";
@@ -25,6 +25,7 @@ import * as crypto from "node:crypto";
25
25
  import * as http from "node:http";
26
26
  import open from "open";
27
27
  import * as rolldown from "rolldown";
28
+ import * as fsPromises from "node:fs/promises";
28
29
  import { TraceMap, generatedPositionFor, originalPositionFor } from "@jridgewell/trace-mapping";
29
30
  import { spawn, spawnSync } from "node:child_process";
30
31
  import * as fs from "fs";
@@ -2716,7 +2717,7 @@ async function runSkillsInstaller(options) {
2716
2717
  //#endregion
2717
2718
  //#region src/cli/commands/skills/install.ts
2718
2719
  async function resolveBundledSkillsDir() {
2719
- return resolve(dirname(await resolvePackageJSON(import.meta.url)), "skills");
2720
+ return resolve(dirname(await resolvePackageJSON(import.meta.url)), "agent-skills");
2720
2721
  }
2721
2722
  const DEFAULT_AGENT = "claude-code";
2722
2723
  const installCommand = defineAppCommand({
@@ -3571,6 +3572,91 @@ const erdCommand = defineCommand({
3571
3572
  }
3572
3573
  });
3573
3574
 
3575
+ //#endregion
3576
+ //#region src/cli/commands/tailordb/migrate/script.ts
3577
+ /**
3578
+ * Script command for TailorDB migrations
3579
+ *
3580
+ * Adds a `migrate.ts` (and supporting `db.ts`) template to an existing
3581
+ * migration directory. Useful for warning-tier changes where users may
3582
+ * want to write a custom data migration even though the change does not
3583
+ * automatically require one.
3584
+ */
3585
+ /**
3586
+ * Add a migrate.ts template to an existing migration directory.
3587
+ * @param {ScriptOptions} options - Command options
3588
+ */
3589
+ async function script(options) {
3590
+ logBetaWarning("tailordb migration");
3591
+ let migrationNumber;
3592
+ if (isValidMigrationNumber(options.number)) migrationNumber = parseInt(options.number, 10);
3593
+ else if (/^[1-9]\d*$/.test(options.number)) {
3594
+ migrationNumber = parseInt(options.number, 10);
3595
+ if (migrationNumber > 9999) throw new Error(`Migration number ${options.number} is out of range. Expected 1-9999.`);
3596
+ } else throw new Error(`Invalid migration number format: ${options.number}. Expected 4-digit format (e.g., 0001) or integer 1-9999 (e.g., 1).`);
3597
+ if (migrationNumber === 0) throw new Error(`Migration ${options.number} is the initial schema snapshot and cannot have a migration script.`);
3598
+ const { config } = await loadConfig(options.configPath);
3599
+ const namespacesWithMigrations = getNamespacesWithMigrations(config, path.dirname(config.path));
3600
+ if (namespacesWithMigrations.length === 0) throw new Error("No TailorDB services with migrations configuration found");
3601
+ const targetNamespace = resolveTargetNamespace(namespacesWithMigrations, options.namespace);
3602
+ const { migrationsDir } = namespacesWithMigrations.find((ns) => ns.namespace === targetNamespace);
3603
+ const diffPath = getMigrationFilePath(migrationsDir, migrationNumber, "diff");
3604
+ if (!fs$1.existsSync(diffPath)) throw new Error(`Migration ${options.number} not found in ${migrationsDir}. Expected ${diffPath}.`);
3605
+ const migratePath = getMigrationFilePath(migrationsDir, migrationNumber, "migrate");
3606
+ if (fs$1.existsSync(migratePath)) throw new Error(`Migration script already exists at ${migratePath}.`);
3607
+ const diff = loadDiff(diffPath);
3608
+ const previousSnapshot = reconstructSnapshotFromMigrations(migrationsDir, migrationNumber - 1);
3609
+ if (!previousSnapshot) throw new Error(`Could not reconstruct previous schema for migration ${options.number}. Make sure migration ${0} exists.`);
3610
+ const scriptContent = generateMigrationScript(diff);
3611
+ await fsPromises.writeFile(migratePath, scriptContent);
3612
+ await writeDbTypesFile(previousSnapshot, migrationsDir, migrationNumber, diff);
3613
+ logger.success(`Added migration script for migration ${styles.bold(options.number)} in namespace ${styles.bold(targetNamespace)}`);
3614
+ logger.info(` Migration script: ${migratePath}`);
3615
+ logger.info(` DB types: ${getMigrationFilePath(migrationsDir, migrationNumber, "db")}`);
3616
+ logger.newline();
3617
+ logger.log("Edit the script to implement your data migration logic.");
3618
+ logger.log("It will be executed by 'tailor-sdk deploy' between Pre and Post phases.");
3619
+ const editor = getConfiguredEditorCommand();
3620
+ if (!editor) return;
3621
+ logger.newline();
3622
+ logger.info(`Opening ${path.basename(migratePath)} in ${editor}...`);
3623
+ try {
3624
+ await openInConfiguredEditor(migratePath);
3625
+ } catch {
3626
+ return;
3627
+ }
3628
+ }
3629
+ function resolveTargetNamespace(namespacesWithMigrations, requested) {
3630
+ if (requested) {
3631
+ if (!namespacesWithMigrations.some((ns) => ns.namespace === requested)) throw new Error(`Namespace "${requested}" not found or does not have migrations configured`);
3632
+ return requested;
3633
+ }
3634
+ if (namespacesWithMigrations.length === 1) return namespacesWithMigrations[0].namespace;
3635
+ throw new Error(`Multiple TailorDB services found. Please specify namespace with --namespace flag: ${namespacesWithMigrations.map((ns) => ns.namespace).join(", ")}`);
3636
+ }
3637
+ const scriptCommand = defineAppCommand({
3638
+ name: "script",
3639
+ description: "Add a migration script (migrate.ts) template to an existing migration directory.",
3640
+ args: z.object({
3641
+ ...configArg,
3642
+ number: arg(z.string(), {
3643
+ positional: true,
3644
+ description: "Migration number to add a script to (e.g., 0001 or 1)"
3645
+ }),
3646
+ namespace: arg(z.string().optional(), {
3647
+ alias: "n",
3648
+ description: "Target TailorDB namespace (required if multiple namespaces exist)"
3649
+ })
3650
+ }).strict(),
3651
+ run: async (args) => {
3652
+ await script({
3653
+ configPath: args.config,
3654
+ number: args.number,
3655
+ namespace: args.namespace
3656
+ });
3657
+ }
3658
+ });
3659
+
3574
3660
  //#endregion
3575
3661
  //#region src/cli/commands/tailordb/migrate/set.ts
3576
3662
  /**
@@ -3750,14 +3836,16 @@ const statusCommand = defineAppCommand({
3750
3836
  *
3751
3837
  * Subcommands:
3752
3838
  * - generate: Generate migration files from schema differences
3753
- * - set: Set migration checkpoint to a specific number
3754
- * - status: Show migration status for TailorDB namespaces
3839
+ * - script: Add a migrate.ts template to an existing migration
3840
+ * - set: Set migration checkpoint to a specific number
3841
+ * - status: Show migration status for TailorDB namespaces
3755
3842
  */
3756
3843
  const migrationCommand = defineCommand({
3757
3844
  name: "migration",
3758
3845
  description: "Manage TailorDB schema migrations.",
3759
3846
  subCommands: {
3760
3847
  generate: generateCommand$1,
3848
+ script: scriptCommand,
3761
3849
  set: setCommand,
3762
3850
  status: statusCommand
3763
3851
  }