tempest-db-js 0.1.0 → 0.2.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.
@@ -353,6 +353,56 @@ declare function applyOperation(schema: SchemaIR, op: Operation): SchemaIR;
353
353
  */
354
354
  declare function replaySchema(migrations: readonly Migration[]): SchemaIR;
355
355
 
356
+ /**
357
+ * tempest-db-js — Phase 6: rename detection.
358
+ *
359
+ * The differ ({@link diffSchema}) is deliberately conservative: a renamed column
360
+ * looks like a drop + add, and a renamed table like a drop + create. That is the
361
+ * *safe* default (never guesses), but it loses data. This module turns those
362
+ * add/drop pairs into rename *candidates* the CLI can confirm — interactively at
363
+ * a TTY, or explicitly via flags — and folds confirmed ones back into a single
364
+ * `rename_table` / `rename_column` operation.
365
+ *
366
+ * Everything here is pure and structural (no SQL, no DB, no I/O), so the
367
+ * detection and folding are fully testable; the actual prompting lives in the
368
+ * `tempest-db` bin.
369
+ */
370
+
371
+ /** A possible rename the differ emitted as a drop + add/create pair. */
372
+ type RenameCandidate = {
373
+ readonly kind: "table";
374
+ readonly from: string;
375
+ readonly to: string;
376
+ } | {
377
+ readonly kind: "column";
378
+ readonly table: string;
379
+ readonly from: string;
380
+ readonly to: string;
381
+ };
382
+ /**
383
+ * Detect rename candidates in a forward operation list.
384
+ *
385
+ * A table rename is a `create_table` + `drop_table` whose column shapes match
386
+ * exactly. A column rename is an `add_column` + `drop_column` on the same table
387
+ * whose column shapes match exactly. Only unambiguous 1:1 shape matches are
388
+ * reported — if two dropped columns share a shape, neither is offered (the
389
+ * mapping would be a guess).
390
+ *
391
+ * @param ops The forward operations from {@link diffSchema}.
392
+ * @returns The rename candidates found (never mutates `ops`).
393
+ */
394
+ declare function detectRenames(ops: readonly Operation[]): RenameCandidate[];
395
+ /**
396
+ * Fold confirmed renames into an operation list: each confirmed candidate's
397
+ * drop + add/create pair is removed and replaced by a single rename operation,
398
+ * inserted at the position of the first op it replaces (preserving order).
399
+ *
400
+ * @param ops The forward operations from {@link diffSchema}.
401
+ * @param confirmed The rename candidates the user accepted.
402
+ * @returns A new operation list with renames applied.
403
+ */
404
+ declare function applyRenames(ops: readonly Operation[], confirmed: readonly RenameCandidate[]): Operation[];
405
+
356
406
  /**
357
407
  * tempest-db-js — migration CLI (programmatic core).
358
408
  *
@@ -376,6 +426,30 @@ interface CliResult {
376
426
  readonly code: number;
377
427
  readonly lines: string[];
378
428
  }
429
+ /**
430
+ * Identity helper for authoring a typed migration config file. Gives editor
431
+ * autocompletion and type-checking on the object the `tempest-db` bin loads.
432
+ *
433
+ * @example
434
+ * ```ts
435
+ * // tempest-db.config.mjs
436
+ * import { defineMigrationConfig } from "tempest-db-js/migrations";
437
+ * import { NodeSqliteDriver } from "tempest-db-js";
438
+ * import { migrations } from "./migrations/index.js";
439
+ * import { User } from "./models.js";
440
+ *
441
+ * export default defineMigrationConfig({
442
+ * driver: NodeSqliteDriver.open("app.db"),
443
+ * dialect: "sqlite",
444
+ * migrations,
445
+ * models: [User],
446
+ * });
447
+ * ```
448
+ *
449
+ * @param config The migration config to pass through unchanged.
450
+ * @returns The same config, typed as `CliConfig`.
451
+ */
452
+ declare function defineMigrationConfig(config: CliConfig): CliConfig;
379
453
  /**
380
454
  * Run one CLI command.
381
455
  *
@@ -388,4 +462,4 @@ interface CliResult {
388
462
  */
389
463
  declare function runMigrationCli(argv: readonly string[], config: CliConfig): CliResult;
390
464
 
391
- export { type CliConfig, type CliResult, type ColumnIR, CyclicMigrationGraph, type DefaultIR, IrreversibleMigration, type Migration, type MigrationDraft, MigrationRunner, Op, type Operation, type RevisionNode, type SchemaIR, type SqliteAffinity, type TableIR, UnknownRevision, applyOperation, checkDrift, checkDriftPostgres, diffSchema, emptySchema, generateMigration, heads, introspectPostgres, introspectSqlite, invert, invertAll, makeRevisionId, reflectSchema, reflectTable, renderColumnDef, renderColumnType, renderDefault, renderOperation, replaySchema, runMigrationCli, sqliteAffinity, topoOrder };
465
+ export { type CliConfig, type CliResult, type ColumnIR, CyclicMigrationGraph, type DefaultIR, IrreversibleMigration, type Migration, type MigrationDraft, MigrationRunner, Op, type Operation, type RenameCandidate, type RevisionNode, type SchemaIR, type SqliteAffinity, type TableIR, UnknownRevision, applyOperation, applyRenames, checkDrift, checkDriftPostgres, defineMigrationConfig, detectRenames, diffSchema, emptySchema, generateMigration, heads, introspectPostgres, introspectSqlite, invert, invertAll, makeRevisionId, reflectSchema, reflectTable, renderColumnDef, renderColumnType, renderDefault, renderOperation, replaySchema, runMigrationCli, sqliteAffinity, topoOrder };
@@ -353,6 +353,56 @@ declare function applyOperation(schema: SchemaIR, op: Operation): SchemaIR;
353
353
  */
354
354
  declare function replaySchema(migrations: readonly Migration[]): SchemaIR;
355
355
 
356
+ /**
357
+ * tempest-db-js — Phase 6: rename detection.
358
+ *
359
+ * The differ ({@link diffSchema}) is deliberately conservative: a renamed column
360
+ * looks like a drop + add, and a renamed table like a drop + create. That is the
361
+ * *safe* default (never guesses), but it loses data. This module turns those
362
+ * add/drop pairs into rename *candidates* the CLI can confirm — interactively at
363
+ * a TTY, or explicitly via flags — and folds confirmed ones back into a single
364
+ * `rename_table` / `rename_column` operation.
365
+ *
366
+ * Everything here is pure and structural (no SQL, no DB, no I/O), so the
367
+ * detection and folding are fully testable; the actual prompting lives in the
368
+ * `tempest-db` bin.
369
+ */
370
+
371
+ /** A possible rename the differ emitted as a drop + add/create pair. */
372
+ type RenameCandidate = {
373
+ readonly kind: "table";
374
+ readonly from: string;
375
+ readonly to: string;
376
+ } | {
377
+ readonly kind: "column";
378
+ readonly table: string;
379
+ readonly from: string;
380
+ readonly to: string;
381
+ };
382
+ /**
383
+ * Detect rename candidates in a forward operation list.
384
+ *
385
+ * A table rename is a `create_table` + `drop_table` whose column shapes match
386
+ * exactly. A column rename is an `add_column` + `drop_column` on the same table
387
+ * whose column shapes match exactly. Only unambiguous 1:1 shape matches are
388
+ * reported — if two dropped columns share a shape, neither is offered (the
389
+ * mapping would be a guess).
390
+ *
391
+ * @param ops The forward operations from {@link diffSchema}.
392
+ * @returns The rename candidates found (never mutates `ops`).
393
+ */
394
+ declare function detectRenames(ops: readonly Operation[]): RenameCandidate[];
395
+ /**
396
+ * Fold confirmed renames into an operation list: each confirmed candidate's
397
+ * drop + add/create pair is removed and replaced by a single rename operation,
398
+ * inserted at the position of the first op it replaces (preserving order).
399
+ *
400
+ * @param ops The forward operations from {@link diffSchema}.
401
+ * @param confirmed The rename candidates the user accepted.
402
+ * @returns A new operation list with renames applied.
403
+ */
404
+ declare function applyRenames(ops: readonly Operation[], confirmed: readonly RenameCandidate[]): Operation[];
405
+
356
406
  /**
357
407
  * tempest-db-js — migration CLI (programmatic core).
358
408
  *
@@ -376,6 +426,30 @@ interface CliResult {
376
426
  readonly code: number;
377
427
  readonly lines: string[];
378
428
  }
429
+ /**
430
+ * Identity helper for authoring a typed migration config file. Gives editor
431
+ * autocompletion and type-checking on the object the `tempest-db` bin loads.
432
+ *
433
+ * @example
434
+ * ```ts
435
+ * // tempest-db.config.mjs
436
+ * import { defineMigrationConfig } from "tempest-db-js/migrations";
437
+ * import { NodeSqliteDriver } from "tempest-db-js";
438
+ * import { migrations } from "./migrations/index.js";
439
+ * import { User } from "./models.js";
440
+ *
441
+ * export default defineMigrationConfig({
442
+ * driver: NodeSqliteDriver.open("app.db"),
443
+ * dialect: "sqlite",
444
+ * migrations,
445
+ * models: [User],
446
+ * });
447
+ * ```
448
+ *
449
+ * @param config The migration config to pass through unchanged.
450
+ * @returns The same config, typed as `CliConfig`.
451
+ */
452
+ declare function defineMigrationConfig(config: CliConfig): CliConfig;
379
453
  /**
380
454
  * Run one CLI command.
381
455
  *
@@ -388,4 +462,4 @@ interface CliResult {
388
462
  */
389
463
  declare function runMigrationCli(argv: readonly string[], config: CliConfig): CliResult;
390
464
 
391
- export { type CliConfig, type CliResult, type ColumnIR, CyclicMigrationGraph, type DefaultIR, IrreversibleMigration, type Migration, type MigrationDraft, MigrationRunner, Op, type Operation, type RevisionNode, type SchemaIR, type SqliteAffinity, type TableIR, UnknownRevision, applyOperation, checkDrift, checkDriftPostgres, diffSchema, emptySchema, generateMigration, heads, introspectPostgres, introspectSqlite, invert, invertAll, makeRevisionId, reflectSchema, reflectTable, renderColumnDef, renderColumnType, renderDefault, renderOperation, replaySchema, runMigrationCli, sqliteAffinity, topoOrder };
465
+ export { type CliConfig, type CliResult, type ColumnIR, CyclicMigrationGraph, type DefaultIR, IrreversibleMigration, type Migration, type MigrationDraft, MigrationRunner, Op, type Operation, type RenameCandidate, type RevisionNode, type SchemaIR, type SqliteAffinity, type TableIR, UnknownRevision, applyOperation, applyRenames, checkDrift, checkDriftPostgres, defineMigrationConfig, detectRenames, diffSchema, emptySchema, generateMigration, heads, introspectPostgres, introspectSqlite, invert, invertAll, makeRevisionId, reflectSchema, reflectTable, renderColumnDef, renderColumnType, renderDefault, renderOperation, replaySchema, runMigrationCli, sqliteAffinity, topoOrder };