@danceroutine/tango-migrations 0.1.0 → 1.0.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 (106) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +114 -0
  3. package/dist/{CollectingBuilder-C6qnwyrb.js → CollectingBuilder--4fqDQdE.js} +17 -2
  4. package/dist/CollectingBuilder--4fqDQdE.js.map +1 -0
  5. package/dist/{CompilerStrategy-Cv1woBmO.js → CompilerStrategy-yKw-Egxv.js} +19 -8
  6. package/dist/CompilerStrategy-yKw-Egxv.js.map +1 -0
  7. package/dist/InternalColumnType-G9zV9StN.js +16 -0
  8. package/dist/InternalColumnType-G9zV9StN.js.map +1 -0
  9. package/dist/InternalOperationKind-Bt6Weuon.js +19 -0
  10. package/dist/InternalOperationKind-Bt6Weuon.js.map +1 -0
  11. package/dist/{IntrospectorStrategy-BM1Eizfc.js → IntrospectorStrategy-blvwSU3_.js} +13 -4
  12. package/dist/IntrospectorStrategy-blvwSU3_.js.map +1 -0
  13. package/dist/Migration-DYQ0hUG7.js +30 -0
  14. package/dist/Migration-DYQ0hUG7.js.map +1 -0
  15. package/dist/{MigrationGenerator-Z39LTKmC.js → MigrationGenerator-B1p0jHnx.js} +20 -12
  16. package/dist/MigrationGenerator-B1p0jHnx.js.map +1 -0
  17. package/dist/{MigrationRunner-CCFuPUlr.js → MigrationRunner-D1ZfbbS-.js} +52 -9
  18. package/dist/MigrationRunner-D1ZfbbS-.js.map +1 -0
  19. package/dist/MigrationSqlSafetyAdapter-CGRbB2k2.js +62 -0
  20. package/dist/MigrationSqlSafetyAdapter-CGRbB2k2.js.map +1 -0
  21. package/dist/{SqliteCompilerFactory-DwMwO7xY.js → SqliteCompilerFactory-BAodJW9n.js} +73 -51
  22. package/dist/SqliteCompilerFactory-BAodJW9n.js.map +1 -0
  23. package/dist/{SqliteIntrospector-BRdNt6KG.js → SqliteIntrospector-CWwPWhmA.js} +49 -5
  24. package/dist/SqliteIntrospector-CWwPWhmA.js.map +1 -0
  25. package/dist/builder/contracts/ColumnSpec.d.ts +2 -1
  26. package/dist/builder/contracts/UpdateReferentialAction.d.ts +1 -1
  27. package/dist/builder/index.js +4 -4
  28. package/dist/builder/ops/OpBuilder.d.ts +48 -7
  29. package/dist/builder/runtime/CollectingBuilder.d.ts +19 -1
  30. package/dist/{builder-Dtk8oP_Y.js → builder-xJ-Bq2pk.js} +51 -21
  31. package/dist/builder-xJ-Bq2pk.js.map +1 -0
  32. package/dist/cli-DhCn8xiS.js +313 -0
  33. package/dist/cli-DhCn8xiS.js.map +1 -0
  34. package/dist/cli.js +17 -169
  35. package/dist/cli.js.map +1 -1
  36. package/dist/commands/cli.d.ts +5 -0
  37. package/dist/commands/index.d.ts +4 -0
  38. package/dist/commands/index.js +17 -0
  39. package/dist/commands-DIJepqNg.js +10 -0
  40. package/dist/commands-DIJepqNg.js.map +1 -0
  41. package/dist/compilers/contracts/CompilerFactory.d.ts +4 -0
  42. package/dist/compilers/contracts/SQLCompiler.d.ts +4 -0
  43. package/dist/compilers/dialects/PostgresCompiler.d.ts +10 -1
  44. package/dist/compilers/dialects/SqliteCompiler.d.ts +10 -0
  45. package/dist/compilers/factories/PostgresCompilerFactory.d.ts +9 -0
  46. package/dist/compilers/factories/SqliteCompilerFactory.d.ts +9 -0
  47. package/dist/compilers/index.js +5 -4
  48. package/dist/{compilers-D8DJuTnQ.js → compilers-dRN0Hzev.js} +2 -2
  49. package/dist/{compilers-D8DJuTnQ.js.map → compilers-dRN0Hzev.js.map} +1 -1
  50. package/dist/diff/diffSchema.d.ts +6 -1
  51. package/dist/diff/index.js +6 -6
  52. package/dist/{diff-Cs0TPEGR.js → diff-CZZbXAPN.js} +2 -2
  53. package/dist/{diff-Cs0TPEGR.js.map → diff-CZZbXAPN.js.map} +1 -1
  54. package/dist/{diffSchema-KgGHP-s3.js → diffSchema-D4oemTWS.js} +5 -4
  55. package/dist/diffSchema-D4oemTWS.js.map +1 -0
  56. package/dist/domain/Migration.d.ts +17 -0
  57. package/dist/domain/MigrationOperation.d.ts +14 -13
  58. package/dist/domain/index.js +2 -2
  59. package/dist/domain/internal/InternalColumnType.d.ts +11 -10
  60. package/dist/domain/internal/InternalDialect.d.ts +5 -4
  61. package/dist/domain/internal/InternalMigrationMode.d.ts +5 -4
  62. package/dist/domain/internal/InternalOperationKind.d.ts +14 -13
  63. package/dist/domain/internal/InternalReferentialAction.d.ts +7 -6
  64. package/dist/{domain-BXVlG0C0.js → domain-CwR-kUNS.js} +2 -2
  65. package/dist/{domain-BXVlG0C0.js.map → domain-CwR-kUNS.js.map} +1 -1
  66. package/dist/generator/MigrationGenerator.d.ts +13 -0
  67. package/dist/generator/index.js +3 -3
  68. package/dist/{generator-3yC60b1u.js → generator-DK-_f-PF.js} +2 -2
  69. package/dist/{generator-3yC60b1u.js.map → generator-DK-_f-PF.js.map} +1 -1
  70. package/dist/index.d.ts +4 -0
  71. package/dist/index.js +24 -20
  72. package/dist/internal/MigrationSqlSafetyAdapter.d.ts +24 -0
  73. package/dist/introspect/DatabaseIntrospector.d.ts +8 -0
  74. package/dist/introspect/PostgresIntrospector.d.ts +14 -0
  75. package/dist/introspect/SqliteIntrospector.d.ts +13 -0
  76. package/dist/introspect/index.js +3 -2
  77. package/dist/{introspect-ks-QSodq.js → introspect-TPv_jeD6.js} +2 -2
  78. package/dist/{introspect-ks-QSodq.js.map → introspect-TPv_jeD6.js.map} +1 -1
  79. package/dist/runner/MigrationRunner.d.ts +7 -1
  80. package/dist/runner/index.js +9 -8
  81. package/dist/{runner-BOs-tItW.js → runner-C97xT8_W.js} +2 -2
  82. package/dist/{runner-BOs-tItW.js.map → runner-C97xT8_W.js.map} +1 -1
  83. package/dist/runtime/loadModule.d.ts +15 -0
  84. package/dist/strategies/CompilerStrategy.d.ts +19 -1
  85. package/dist/strategies/IntrospectorStrategy.d.ts +16 -1
  86. package/dist/strategies/index.js +8 -7
  87. package/dist/{strategies-BvHwf4as.js → strategies-D9ymSvbG.js} +3 -3
  88. package/dist/{strategies-BvHwf4as.js.map → strategies-D9ymSvbG.js.map} +1 -1
  89. package/package.json +98 -92
  90. package/dist/CollectingBuilder-C6qnwyrb.js.map +0 -1
  91. package/dist/CompilerStrategy-Cv1woBmO.js.map +0 -1
  92. package/dist/InternalColumnType-_YAz7RqI.js +0 -17
  93. package/dist/InternalColumnType-_YAz7RqI.js.map +0 -1
  94. package/dist/InternalOperationKind-BPVoOQwD.js +0 -20
  95. package/dist/InternalOperationKind-BPVoOQwD.js.map +0 -1
  96. package/dist/IntrospectorStrategy-BM1Eizfc.js.map +0 -1
  97. package/dist/Migration-D9J6ZbLP.js +0 -25
  98. package/dist/Migration-D9J6ZbLP.js.map +0 -1
  99. package/dist/MigrationGenerator-Z39LTKmC.js.map +0 -1
  100. package/dist/MigrationRunner-CCFuPUlr.js.map +0 -1
  101. package/dist/SqliteCompilerFactory-DwMwO7xY.js.map +0 -1
  102. package/dist/SqliteIntrospector-BRdNt6KG.js.map +0 -1
  103. package/dist/builder/ops/OpBuilder.js +0 -173
  104. package/dist/builder-Dtk8oP_Y.js.map +0 -1
  105. package/dist/diffSchema-KgGHP-s3.js.map +0 -1
  106. package/dist/domain/MigrationOperation.js +0 -1
@@ -1,3 +1,4 @@
1
+ import type { TrustedSqlFragment } from '@danceroutine/tango-core';
1
2
  import type { ColumnType } from './ColumnType';
2
3
  import type { DeleteReferentialAction } from './DeleteReferentialAction';
3
4
  import type { UpdateReferentialAction } from './UpdateReferentialAction';
@@ -5,7 +6,7 @@ export interface ColumnSpec {
5
6
  name: string;
6
7
  type: ColumnType;
7
8
  notNull?: boolean;
8
- default?: string | {
9
+ default?: TrustedSqlFragment | {
9
10
  now: true;
10
11
  } | null;
11
12
  primaryKey?: boolean;
@@ -1,2 +1,2 @@
1
1
  import type { InternalReferentialAction } from '../../domain/internal/InternalReferentialAction';
2
- export type UpdateReferentialAction = InternalReferentialAction.CASCADE | InternalReferentialAction.RESTRICT | InternalReferentialAction.NO_ACTION;
2
+ export type UpdateReferentialAction = Extract<InternalReferentialAction, 'CASCADE' | 'RESTRICT' | 'NO_ACTION'>;
@@ -1,6 +1,6 @@
1
- import { CollectingBuilder } from "../CollectingBuilder-C6qnwyrb.js";
2
- import "../InternalOperationKind-BPVoOQwD.js";
3
- import "../InternalColumnType-_YAz7RqI.js";
4
- import { OpBuilder, applyFieldType, contracts_exports, ops_exports, runtime_exports } from "../builder-Dtk8oP_Y.js";
1
+ import { CollectingBuilder } from "../CollectingBuilder--4fqDQdE.js";
2
+ import "../InternalOperationKind-Bt6Weuon.js";
3
+ import "../InternalColumnType-G9zV9StN.js";
4
+ import { OpBuilder, applyFieldType, contracts_exports, ops_exports, runtime_exports } from "../builder-xJ-Bq2pk.js";
5
5
 
6
6
  export { CollectingBuilder, OpBuilder, applyFieldType, contracts_exports as contracts, OpBuilder as op, ops_exports as ops, runtime_exports as runtime };
@@ -1,27 +1,45 @@
1
+ import type { TrustedSqlFragment } from '@danceroutine/tango-core';
1
2
  import type { CustomMigrationOperation, ForeignKeyCreate, ForeignKeyDrop, ForeignKeyValidate, IndexCreate, IndexDrop, TableCreate, TableDrop, ColumnAdd, ColumnDrop, ColumnAlter, ColumnRename } from '../../domain/MigrationOperation';
2
3
  import type { ColumnSpec } from '../contracts/ColumnSpec';
3
4
  import type { ColumnType } from '../contracts/ColumnType';
4
5
  import type { DeleteReferentialAction } from '../contracts/DeleteReferentialAction';
5
6
  import type { UpdateReferentialAction } from '../contracts/UpdateReferentialAction';
7
+ /**
8
+ * Fluent builder for column specifications used by table operations.
9
+ */
6
10
  declare class ColumnBuilder {
7
11
  static readonly BRAND: "tango.migrations.column_builder";
8
- private spec;
9
12
  readonly __tangoBrand: typeof ColumnBuilder.BRAND;
13
+ private spec;
10
14
  constructor(name: string);
11
15
  static isColumnBuilder(value: unknown): value is ColumnBuilder;
16
+ /** Set column type to serial/auto-increment. */
12
17
  serial(): ColumnBuilder;
18
+ /** Set column type to integer. */
13
19
  int(): ColumnBuilder;
20
+ /** Set column type to bigint. */
14
21
  bigint(): ColumnBuilder;
22
+ /** Set column type to text. */
15
23
  text(): ColumnBuilder;
24
+ /** Set column type to boolean. */
16
25
  bool(): ColumnBuilder;
26
+ /** Set column type to timestamptz. */
17
27
  timestamptz(): ColumnBuilder;
28
+ /** Set column type to JSONB. */
18
29
  jsonb(): ColumnBuilder;
30
+ /** Set column type to UUID. */
19
31
  uuid(): ColumnBuilder;
32
+ /** Mark column as NOT NULL. */
20
33
  notNull(): ColumnBuilder;
34
+ /** Set default to current timestamp. */
21
35
  defaultNow(): ColumnBuilder;
22
- default(v: string | null): ColumnBuilder;
36
+ /** Set reviewed raw SQL default expression. */
37
+ default(v: TrustedSqlFragment | null): ColumnBuilder;
38
+ /** Mark column as part of primary key. */
23
39
  primaryKey(): ColumnBuilder;
40
+ /** Mark column as unique. */
24
41
  unique(): ColumnBuilder;
42
+ /** Configure foreign key reference metadata. */
25
43
  references(table: string, column: string, opts?: {
26
44
  onDelete?: DeleteReferentialAction;
27
45
  onUpdate?: UpdateReferentialAction;
@@ -40,27 +58,39 @@ type TableOperationBuilder = {
40
58
  alterColumn(name: string, to: Partial<ColumnSpec>): ColumnAlter;
41
59
  renameColumn(from: string, to: string): ColumnRename;
42
60
  };
61
+ /**
62
+ * Static factory for migration operations.
63
+ */
43
64
  export declare class OpBuilder {
44
65
  static readonly BRAND: "tango.migrations.op_builder";
45
- readonly __tangoBrand: typeof OpBuilder.BRAND;
46
- private static customOperations;
47
- static isOpBuilder(value: unknown): value is OpBuilder;
48
- static table(table: string): TableOperationBuilder;
49
66
  static index: {
67
+ /** Build an index create operation. */
50
68
  create(p: {
51
69
  name: string;
52
70
  table: string;
53
71
  on: string[];
54
72
  unique?: boolean;
55
- where?: string;
73
+ where?: TrustedSqlFragment;
56
74
  concurrently?: boolean;
57
75
  }): IndexCreate;
76
+ /** Build an index drop operation. */
58
77
  drop(p: {
59
78
  name: string;
60
79
  table: string;
61
80
  concurrently?: boolean;
62
81
  }): IndexDrop;
63
82
  };
83
+ private static customOperations;
84
+ readonly __tangoBrand: typeof OpBuilder.BRAND;
85
+ /**
86
+ * Narrow an unknown value to the shared migration operation builder type.
87
+ */
88
+ static isOpBuilder(value: unknown): value is OpBuilder;
89
+ /**
90
+ * Build table-scoped migration operations.
91
+ */
92
+ static table(table: string): TableOperationBuilder;
93
+ /** Build a foreign key create operation. */
64
94
  static foreignKey(p: {
65
95
  table: string;
66
96
  name?: string;
@@ -73,16 +103,27 @@ export declare class OpBuilder {
73
103
  onUpdate?: string;
74
104
  notValid?: boolean;
75
105
  }): ForeignKeyCreate;
106
+ /** Build a foreign key validation operation. */
76
107
  static foreignKeyValidate(p: {
77
108
  table: string;
78
109
  name: string;
79
110
  }): ForeignKeyValidate;
111
+ /** Build a foreign key drop operation. */
80
112
  static foreignKeyDrop(p: {
81
113
  table: string;
82
114
  name: string;
83
115
  }): ForeignKeyDrop;
116
+ /**
117
+ * Register a custom migration operation builder.
118
+ */
84
119
  static registerCustomOperation<TName extends string, TArgs extends object>(name: TName, builder: (args: TArgs) => CustomMigrationOperation<TName, TArgs>): void;
120
+ /**
121
+ * Resolve a previously registered custom operation builder.
122
+ */
85
123
  static getCustomOperation<TName extends string, TArgs extends object>(name: TName): ((args: TArgs) => CustomMigrationOperation<TName, TArgs>) | undefined;
86
124
  }
125
+ /**
126
+ * Apply a domain field type to a column builder.
127
+ */
87
128
  export declare function applyFieldType(builder: ColumnBuilder, fieldType: ColumnType): ColumnBuilder;
88
129
  export {};
@@ -1,21 +1,39 @@
1
1
  import type { Builder } from '../contracts/Builder';
2
2
  import type { MigrationOperation } from '../../domain/MigrationOperation';
3
3
  import type { MigrationMode } from '../../domain/MigrationMode';
4
+ /**
5
+ * In-memory builder that collects migration operations and data callbacks.
6
+ */
4
7
  export declare class CollectingBuilder implements Builder {
5
8
  static readonly BRAND: "tango.migrations.collecting_builder";
6
- private mode?;
7
9
  readonly __tangoBrand: typeof CollectingBuilder.BRAND;
8
10
  ops: MigrationOperation[];
9
11
  dataFns: Array<(ctx: {
10
12
  query(sql: string, params?: readonly unknown[]): Promise<void>;
11
13
  }) => Promise<void>>;
14
+ private mode?;
15
+ /**
16
+ * Narrow an unknown value to the in-memory builder used during migration collection.
17
+ */
12
18
  static isCollectingBuilder(value: unknown): value is CollectingBuilder;
19
+ /**
20
+ * Append schema operations to the collection.
21
+ */
13
22
  run(...ops: MigrationOperation[]): void;
23
+ /**
24
+ * Register a data migration callback.
25
+ */
14
26
  data(fn: (ctx: {
15
27
  query(sql: string, params?: readonly unknown[]): Promise<void>;
16
28
  }) => Promise<void>): void;
29
+ /**
30
+ * Set execution options for the migration.
31
+ */
17
32
  options(o: {
18
33
  mode?: MigrationMode;
19
34
  }): void;
35
+ /**
36
+ * Get the currently configured migration mode.
37
+ */
20
38
  getMode(): MigrationMode | undefined;
21
39
  }
@@ -1,7 +1,7 @@
1
1
  import { __export } from "./chunk-BkvOhyD0.js";
2
- import { CollectingBuilder } from "./CollectingBuilder-C6qnwyrb.js";
3
- import { InternalOperationKind } from "./InternalOperationKind-BPVoOQwD.js";
4
- import { InternalColumnType } from "./InternalColumnType-_YAz7RqI.js";
2
+ import { CollectingBuilder } from "./CollectingBuilder--4fqDQdE.js";
3
+ import { InternalOperationKind } from "./InternalOperationKind-Bt6Weuon.js";
4
+ import { InternalColumnType } from "./InternalColumnType-G9zV9StN.js";
5
5
 
6
6
  //#region src/builder/contracts/index.ts
7
7
  var contracts_exports = {};
@@ -10,66 +10,80 @@ var contracts_exports = {};
10
10
  //#region src/builder/ops/OpBuilder.ts
11
11
  var ColumnBuilder = class ColumnBuilder {
12
12
  static BRAND = "tango.migrations.column_builder";
13
- spec = {};
14
13
  __tangoBrand = ColumnBuilder.BRAND;
14
+ spec = {};
15
15
  constructor(name) {
16
16
  this.spec.name = name;
17
17
  }
18
18
  static isColumnBuilder(value) {
19
19
  return typeof value === "object" && value !== null && value.__tangoBrand === ColumnBuilder.BRAND;
20
20
  }
21
+ /** Set column type to serial/auto-increment. */
21
22
  serial() {
22
23
  this.spec.type = InternalColumnType.SERIAL;
23
24
  return this;
24
25
  }
26
+ /** Set column type to integer. */
25
27
  int() {
26
28
  this.spec.type = InternalColumnType.INT;
27
29
  return this;
28
30
  }
31
+ /** Set column type to bigint. */
29
32
  bigint() {
30
33
  this.spec.type = InternalColumnType.BIGINT;
31
34
  return this;
32
35
  }
36
+ /** Set column type to text. */
33
37
  text() {
34
38
  this.spec.type = InternalColumnType.TEXT;
35
39
  return this;
36
40
  }
41
+ /** Set column type to boolean. */
37
42
  bool() {
38
43
  this.spec.type = InternalColumnType.BOOL;
39
44
  return this;
40
45
  }
46
+ /** Set column type to timestamptz. */
41
47
  timestamptz() {
42
48
  this.spec.type = InternalColumnType.TIMESTAMPTZ;
43
49
  return this;
44
50
  }
51
+ /** Set column type to JSONB. */
45
52
  jsonb() {
46
53
  this.spec.type = InternalColumnType.JSONB;
47
54
  return this;
48
55
  }
56
+ /** Set column type to UUID. */
49
57
  uuid() {
50
58
  this.spec.type = InternalColumnType.UUID;
51
59
  return this;
52
60
  }
61
+ /** Mark column as NOT NULL. */
53
62
  notNull() {
54
63
  this.spec.notNull = true;
55
64
  return this;
56
65
  }
66
+ /** Set default to current timestamp. */
57
67
  defaultNow() {
58
68
  this.spec.default = { now: true };
59
69
  return this;
60
70
  }
71
+ /** Set reviewed raw SQL default expression. */
61
72
  default(v) {
62
73
  this.spec.default = v;
63
74
  return this;
64
75
  }
76
+ /** Mark column as part of primary key. */
65
77
  primaryKey() {
66
78
  this.spec.primaryKey = true;
67
79
  return this;
68
80
  }
81
+ /** Mark column as unique. */
69
82
  unique() {
70
83
  this.spec.unique = true;
71
84
  return this;
72
85
  }
86
+ /** Configure foreign key reference metadata. */
73
87
  references(table, column, opts) {
74
88
  this.spec.references = {
75
89
  table,
@@ -85,11 +99,31 @@ var ColumnBuilder = class ColumnBuilder {
85
99
  };
86
100
  var OpBuilder = class OpBuilder {
87
101
  static BRAND = "tango.migrations.op_builder";
88
- __tangoBrand = OpBuilder.BRAND;
102
+ static index = {
103
+ create(p) {
104
+ return {
105
+ kind: InternalOperationKind.INDEX_CREATE,
106
+ ...p
107
+ };
108
+ },
109
+ drop(p) {
110
+ return {
111
+ kind: InternalOperationKind.INDEX_DROP,
112
+ ...p
113
+ };
114
+ }
115
+ };
89
116
  static customOperations = new Map();
117
+ __tangoBrand = OpBuilder.BRAND;
118
+ /**
119
+ * Narrow an unknown value to the shared migration operation builder type.
120
+ */
90
121
  static isOpBuilder(value) {
91
122
  return typeof value === "object" && value !== null && value.__tangoBrand === OpBuilder.BRAND;
92
123
  }
124
+ /**
125
+ * Build table-scoped migration operations.
126
+ */
93
127
  static table(table) {
94
128
  return {
95
129
  create(def) {
@@ -142,20 +176,7 @@ var OpBuilder = class OpBuilder {
142
176
  }
143
177
  };
144
178
  }
145
- static index = {
146
- create(p) {
147
- return {
148
- kind: InternalOperationKind.INDEX_CREATE,
149
- ...p
150
- };
151
- },
152
- drop(p) {
153
- return {
154
- kind: InternalOperationKind.INDEX_DROP,
155
- ...p
156
- };
157
- }
158
- };
179
+ /** Build a foreign key create operation. */
159
180
  static foreignKey(p) {
160
181
  return {
161
182
  kind: InternalOperationKind.FK_CREATE,
@@ -169,21 +190,29 @@ var OpBuilder = class OpBuilder {
169
190
  notValid: p.notValid
170
191
  };
171
192
  }
193
+ /** Build a foreign key validation operation. */
172
194
  static foreignKeyValidate(p) {
173
195
  return {
174
196
  kind: InternalOperationKind.FK_VALIDATE,
175
197
  ...p
176
198
  };
177
199
  }
200
+ /** Build a foreign key drop operation. */
178
201
  static foreignKeyDrop(p) {
179
202
  return {
180
203
  kind: InternalOperationKind.FK_DROP,
181
204
  ...p
182
205
  };
183
206
  }
207
+ /**
208
+ * Register a custom migration operation builder.
209
+ */
184
210
  static registerCustomOperation(name, builder) {
185
211
  this.customOperations.set(name, builder);
186
212
  }
213
+ /**
214
+ * Resolve a previously registered custom operation builder.
215
+ */
187
216
  static getCustomOperation(name) {
188
217
  return this.customOperations.get(name);
189
218
  }
@@ -198,9 +227,10 @@ function applyFieldType(builder, fieldType) {
198
227
  case InternalColumnType.TIMESTAMPTZ: return builder.timestamptz();
199
228
  case InternalColumnType.JSONB: return builder.jsonb();
200
229
  case InternalColumnType.UUID: return builder.uuid();
201
- default:
230
+ default: {
202
231
  const exhaustive = fieldType;
203
232
  throw new Error(`Unsupported field type: ${exhaustive}`);
233
+ }
204
234
  }
205
235
  }
206
236
 
@@ -233,4 +263,4 @@ __export(builder_exports, {
233
263
 
234
264
  //#endregion
235
265
  export { OpBuilder, applyFieldType, builder_exports, contracts_exports, ops_exports, runtime_exports };
236
- //# sourceMappingURL=builder-Dtk8oP_Y.js.map
266
+ //# sourceMappingURL=builder-xJ-Bq2pk.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builder-xJ-Bq2pk.js","names":["name: string","value: unknown","v: TrustedSqlFragment | null","table: string","column: string","opts?: {\n onDelete?: DeleteReferentialAction;\n onUpdate?: UpdateReferentialAction;\n }","p: {\n name: string;\n table: string;\n on: string[];\n unique?: boolean;\n where?: TrustedSqlFragment;\n concurrently?: boolean;\n }","p: { name: string; table: string; concurrently?: boolean }","def: (cols: { add: (name: string, cb: (b: ColumnBuilder) => ColumnBuilder) => void }) => void","columns: ColumnSpec[]","opts?: { cascade?: boolean }","cb: (b: ColumnBuilder) => ColumnBuilder","to: Partial<ColumnSpec>","from: string","to: string","p: {\n table: string;\n name?: string;\n columns: string[];\n references: { table: string; columns: string[] };\n onDelete?: string;\n onUpdate?: string;\n notValid?: boolean;\n }","p: { table: string; name: string }","name: TName","builder: (args: TArgs) => CustomMigrationOperation<TName, TArgs>","builder: ColumnBuilder","fieldType: ColumnType","exhaustive: never"],"sources":["../src/builder/contracts/index.ts","../src/builder/ops/OpBuilder.ts","../src/builder/ops/index.ts","../src/builder/runtime/index.ts","../src/builder/index.ts"],"sourcesContent":["/**\n * Domain boundary barrel: centralizes this subdomain's public contract.\n */\n\nexport type { Builder } from './Builder';\nexport type { ColumnSpec } from './ColumnSpec';\nexport type { ColumnType } from './ColumnType';\nexport type { DeleteReferentialAction } from './DeleteReferentialAction';\nexport type { UpdateReferentialAction } from './UpdateReferentialAction';\n","import type { TrustedSqlFragment } from '@danceroutine/tango-core';\nimport type {\n CustomMigrationOperation,\n ForeignKeyCreate,\n ForeignKeyDrop,\n ForeignKeyValidate,\n IndexCreate,\n IndexDrop,\n TableCreate,\n TableDrop,\n ColumnAdd,\n ColumnDrop,\n ColumnAlter,\n ColumnRename,\n} from '../../domain/MigrationOperation';\nimport type { ColumnSpec } from '../contracts/ColumnSpec';\nimport type { ColumnType } from '../contracts/ColumnType';\nimport { InternalColumnType } from '../../domain/internal/InternalColumnType';\nimport type { DeleteReferentialAction } from '../contracts/DeleteReferentialAction';\nimport type { UpdateReferentialAction } from '../contracts/UpdateReferentialAction';\nimport { InternalOperationKind } from '../../domain/internal/InternalOperationKind';\n\n/**\n * Fluent builder for column specifications used by table operations.\n */\nclass ColumnBuilder {\n static readonly BRAND = 'tango.migrations.column_builder' as const;\n readonly __tangoBrand: typeof ColumnBuilder.BRAND = ColumnBuilder.BRAND;\n private spec: Partial<ColumnSpec> = {};\n\n constructor(name: string) {\n this.spec.name = name;\n }\n\n static isColumnBuilder(value: unknown): value is ColumnBuilder {\n return (\n typeof value === 'object' &&\n value !== null &&\n (value as { __tangoBrand?: unknown }).__tangoBrand === ColumnBuilder.BRAND\n );\n }\n\n /** Set column type to serial/auto-increment. */\n serial(): ColumnBuilder {\n this.spec.type = InternalColumnType.SERIAL;\n return this;\n }\n /** Set column type to integer. */\n int(): ColumnBuilder {\n this.spec.type = InternalColumnType.INT;\n return this;\n }\n /** Set column type to bigint. */\n bigint(): ColumnBuilder {\n this.spec.type = InternalColumnType.BIGINT;\n return this;\n }\n /** Set column type to text. */\n text(): ColumnBuilder {\n this.spec.type = InternalColumnType.TEXT;\n return this;\n }\n /** Set column type to boolean. */\n bool(): ColumnBuilder {\n this.spec.type = InternalColumnType.BOOL;\n return this;\n }\n /** Set column type to timestamptz. */\n timestamptz(): ColumnBuilder {\n this.spec.type = InternalColumnType.TIMESTAMPTZ;\n return this;\n }\n /** Set column type to JSONB. */\n jsonb(): ColumnBuilder {\n this.spec.type = InternalColumnType.JSONB;\n return this;\n }\n /** Set column type to UUID. */\n uuid(): ColumnBuilder {\n this.spec.type = InternalColumnType.UUID;\n return this;\n }\n\n /** Mark column as NOT NULL. */\n notNull(): ColumnBuilder {\n this.spec.notNull = true;\n return this;\n }\n /** Set default to current timestamp. */\n defaultNow(): ColumnBuilder {\n this.spec.default = { now: true };\n return this;\n }\n /** Set reviewed raw SQL default expression. */\n default(v: TrustedSqlFragment | null): ColumnBuilder {\n this.spec.default = v;\n return this;\n }\n /** Mark column as part of primary key. */\n primaryKey(): ColumnBuilder {\n this.spec.primaryKey = true;\n return this;\n }\n /** Mark column as unique. */\n unique(): ColumnBuilder {\n this.spec.unique = true;\n return this;\n }\n /** Configure foreign key reference metadata. */\n references(\n table: string,\n column: string,\n opts?: {\n onDelete?: DeleteReferentialAction;\n onUpdate?: UpdateReferentialAction;\n }\n ): ColumnBuilder {\n this.spec.references = {\n table,\n column,\n onDelete: opts?.onDelete,\n onUpdate: opts?.onUpdate,\n };\n return this;\n }\n\n _done(): ColumnSpec {\n return this.spec as ColumnSpec;\n }\n}\n\ntype TableOperationBuilder = {\n create(def: (cols: { add: (name: string, cb: (b: ColumnBuilder) => ColumnBuilder) => void }) => void): TableCreate;\n drop(opts?: { cascade?: boolean }): TableDrop;\n addColumn(name: string, cb: (b: ColumnBuilder) => ColumnBuilder): ColumnAdd;\n dropColumn(name: string): ColumnDrop;\n alterColumn(name: string, to: Partial<ColumnSpec>): ColumnAlter;\n renameColumn(from: string, to: string): ColumnRename;\n};\n\n/**\n * Static factory for migration operations.\n */\nexport class OpBuilder {\n static readonly BRAND = 'tango.migrations.op_builder' as const;\n static index = {\n /** Build an index create operation. */\n create(p: {\n name: string;\n table: string;\n on: string[];\n unique?: boolean;\n where?: TrustedSqlFragment;\n concurrently?: boolean;\n }): IndexCreate {\n return { kind: InternalOperationKind.INDEX_CREATE, ...p };\n },\n /** Build an index drop operation. */\n drop(p: { name: string; table: string; concurrently?: boolean }): IndexDrop {\n return { kind: InternalOperationKind.INDEX_DROP, ...p };\n },\n };\n private static customOperations = new Map<string, (args: Record<string, unknown>) => CustomMigrationOperation>();\n readonly __tangoBrand: typeof OpBuilder.BRAND = OpBuilder.BRAND;\n\n /**\n * Narrow an unknown value to the shared migration operation builder type.\n */\n static isOpBuilder(value: unknown): value is OpBuilder {\n return (\n typeof value === 'object' &&\n value !== null &&\n (value as { __tangoBrand?: unknown }).__tangoBrand === OpBuilder.BRAND\n );\n }\n\n /**\n * Build table-scoped migration operations.\n */\n static table(table: string): TableOperationBuilder {\n return {\n create(\n def: (cols: { add: (name: string, cb: (b: ColumnBuilder) => ColumnBuilder) => void }) => void\n ): TableCreate {\n const columns: ColumnSpec[] = [];\n def({\n add(name, cb) {\n columns.push(cb(new ColumnBuilder(name))._done());\n },\n });\n return { kind: InternalOperationKind.TABLE_CREATE, table, columns };\n },\n drop(opts?: { cascade?: boolean }): TableDrop {\n return { kind: InternalOperationKind.TABLE_DROP, table, cascade: opts?.cascade };\n },\n addColumn(name: string, cb: (b: ColumnBuilder) => ColumnBuilder): ColumnAdd {\n return { kind: InternalOperationKind.COLUMN_ADD, table, column: cb(new ColumnBuilder(name))._done() };\n },\n dropColumn(name: string): ColumnDrop {\n return { kind: InternalOperationKind.COLUMN_DROP, table, column: name };\n },\n alterColumn(name: string, to: Partial<ColumnSpec>): ColumnAlter {\n return { kind: InternalOperationKind.COLUMN_ALTER, table, column: name, to };\n },\n renameColumn(from: string, to: string): ColumnRename {\n return { kind: InternalOperationKind.COLUMN_RENAME, table, from, to };\n },\n };\n }\n\n /** Build a foreign key create operation. */\n static foreignKey(p: {\n table: string;\n name?: string;\n columns: string[];\n references: { table: string; columns: string[] };\n onDelete?: string;\n onUpdate?: string;\n notValid?: boolean;\n }): ForeignKeyCreate {\n return {\n kind: InternalOperationKind.FK_CREATE,\n table: p.table,\n name: p.name,\n columns: p.columns,\n refTable: p.references.table,\n refColumns: p.references.columns,\n onDelete: p.onDelete,\n onUpdate: p.onUpdate,\n notValid: p.notValid,\n };\n }\n\n /** Build a foreign key validation operation. */\n static foreignKeyValidate(p: { table: string; name: string }): ForeignKeyValidate {\n return { kind: InternalOperationKind.FK_VALIDATE, ...p };\n }\n\n /** Build a foreign key drop operation. */\n static foreignKeyDrop(p: { table: string; name: string }): ForeignKeyDrop {\n return { kind: InternalOperationKind.FK_DROP, ...p };\n }\n\n /**\n * Register a custom migration operation builder.\n */\n static registerCustomOperation<TName extends string, TArgs extends object>(\n name: TName,\n builder: (args: TArgs) => CustomMigrationOperation<TName, TArgs>\n ): void {\n this.customOperations.set(name, builder as (args: Record<string, unknown>) => CustomMigrationOperation);\n }\n\n /**\n * Resolve a previously registered custom operation builder.\n */\n static getCustomOperation<TName extends string, TArgs extends object>(\n name: TName\n ): ((args: TArgs) => CustomMigrationOperation<TName, TArgs>) | undefined {\n return this.customOperations.get(name) as ((args: TArgs) => CustomMigrationOperation<TName, TArgs>) | undefined;\n }\n}\n\n/**\n * Apply a domain field type to a column builder.\n */\nexport function applyFieldType(builder: ColumnBuilder, fieldType: ColumnType): ColumnBuilder {\n switch (fieldType) {\n case InternalColumnType.SERIAL:\n return builder.serial();\n case InternalColumnType.INT:\n return builder.int();\n case InternalColumnType.BIGINT:\n return builder.bigint();\n case InternalColumnType.TEXT:\n return builder.text();\n case InternalColumnType.BOOL:\n return builder.bool();\n case InternalColumnType.TIMESTAMPTZ:\n return builder.timestamptz();\n case InternalColumnType.JSONB:\n return builder.jsonb();\n case InternalColumnType.UUID:\n return builder.uuid();\n default: {\n const exhaustive: never = fieldType;\n throw new Error(`Unsupported field type: ${exhaustive}`);\n }\n }\n}\n","/**\n * Domain boundary barrel: centralizes this subdomain's public contract.\n */\n\nexport { OpBuilder, OpBuilder as op, applyFieldType } from './OpBuilder';\n","/**\n * Domain boundary barrel: centralizes this subdomain's public contract.\n */\n\nexport { CollectingBuilder } from './CollectingBuilder';\n","/**\n * Domain boundary barrel: exposes namespaced exports for Django-style drill-down\n * imports and curated flat exports for TS-native ergonomics.\n */\n\nexport * as contracts from './contracts/index';\nexport * as ops from './ops/index';\nexport * as runtime from './runtime/index';\n\nexport type {\n Builder,\n ColumnSpec,\n ColumnType,\n DeleteReferentialAction,\n UpdateReferentialAction,\n} from './contracts/index';\nexport { OpBuilder, op, applyFieldType } from './ops/index';\nexport { CollectingBuilder } from './runtime/index';\n"],"mappings":";;;;;;;;;;ICyBM,gBAAN,MAAM,cAAc;CAChB,OAAgB,QAAQ;CACxB,eAAoD,cAAc;CAClE,OAAoC,CAAE;CAEtC,YAAYA,MAAc;AACtB,OAAK,KAAK,OAAO;CACpB;CAED,OAAO,gBAAgBC,OAAwC;AAC3D,gBACW,UAAU,YACjB,UAAU,QACT,MAAqC,iBAAiB,cAAc;CAE5E;;CAGD,SAAwB;AACpB,OAAK,KAAK,OAAO,mBAAmB;AACpC,SAAO;CACV;;CAED,MAAqB;AACjB,OAAK,KAAK,OAAO,mBAAmB;AACpC,SAAO;CACV;;CAED,SAAwB;AACpB,OAAK,KAAK,OAAO,mBAAmB;AACpC,SAAO;CACV;;CAED,OAAsB;AAClB,OAAK,KAAK,OAAO,mBAAmB;AACpC,SAAO;CACV;;CAED,OAAsB;AAClB,OAAK,KAAK,OAAO,mBAAmB;AACpC,SAAO;CACV;;CAED,cAA6B;AACzB,OAAK,KAAK,OAAO,mBAAmB;AACpC,SAAO;CACV;;CAED,QAAuB;AACnB,OAAK,KAAK,OAAO,mBAAmB;AACpC,SAAO;CACV;;CAED,OAAsB;AAClB,OAAK,KAAK,OAAO,mBAAmB;AACpC,SAAO;CACV;;CAGD,UAAyB;AACrB,OAAK,KAAK,UAAU;AACpB,SAAO;CACV;;CAED,aAA4B;AACxB,OAAK,KAAK,UAAU,EAAE,KAA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