@danceroutine/tango-migrations 0.1.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 (100) hide show
  1. package/dist/CollectingBuilder-C6qnwyrb.js +28 -0
  2. package/dist/CollectingBuilder-C6qnwyrb.js.map +1 -0
  3. package/dist/CompilerStrategy-Cv1woBmO.js +55 -0
  4. package/dist/CompilerStrategy-Cv1woBmO.js.map +1 -0
  5. package/dist/InternalColumnType-_YAz7RqI.js +17 -0
  6. package/dist/InternalColumnType-_YAz7RqI.js.map +1 -0
  7. package/dist/InternalOperationKind-BPVoOQwD.js +20 -0
  8. package/dist/InternalOperationKind-BPVoOQwD.js.map +1 -0
  9. package/dist/IntrospectorStrategy-BM1Eizfc.js +38 -0
  10. package/dist/IntrospectorStrategy-BM1Eizfc.js.map +1 -0
  11. package/dist/Migration-D9J6ZbLP.js +25 -0
  12. package/dist/Migration-D9J6ZbLP.js.map +1 -0
  13. package/dist/MigrationGenerator-Z39LTKmC.js +199 -0
  14. package/dist/MigrationGenerator-Z39LTKmC.js.map +1 -0
  15. package/dist/MigrationRunner-CCFuPUlr.js +144 -0
  16. package/dist/MigrationRunner-CCFuPUlr.js.map +1 -0
  17. package/dist/SqliteCompilerFactory-DwMwO7xY.js +303 -0
  18. package/dist/SqliteCompilerFactory-DwMwO7xY.js.map +1 -0
  19. package/dist/SqliteIntrospector-BRdNt6KG.js +121 -0
  20. package/dist/SqliteIntrospector-BRdNt6KG.js.map +1 -0
  21. package/dist/builder/contracts/Builder.d.ts +11 -0
  22. package/dist/builder/contracts/ColumnSpec.d.ts +19 -0
  23. package/dist/builder/contracts/ColumnType.d.ts +2 -0
  24. package/dist/builder/contracts/DeleteReferentialAction.d.ts +2 -0
  25. package/dist/builder/contracts/UpdateReferentialAction.d.ts +2 -0
  26. package/dist/builder/contracts/index.d.ts +8 -0
  27. package/dist/builder/index.d.ts +10 -0
  28. package/dist/builder/index.js +6 -0
  29. package/dist/builder/ops/OpBuilder.d.ts +88 -0
  30. package/dist/builder/ops/OpBuilder.js +173 -0
  31. package/dist/builder/ops/index.d.ts +4 -0
  32. package/dist/builder/runtime/CollectingBuilder.d.ts +21 -0
  33. package/dist/builder/runtime/index.d.ts +4 -0
  34. package/dist/builder-Dtk8oP_Y.js +236 -0
  35. package/dist/builder-Dtk8oP_Y.js.map +1 -0
  36. package/dist/chunk-BkvOhyD0.js +12 -0
  37. package/dist/cli.d.ts +2 -0
  38. package/dist/cli.js +178 -0
  39. package/dist/cli.js.map +1 -0
  40. package/dist/compilers/contracts/CompilerFactory.d.ts +4 -0
  41. package/dist/compilers/contracts/SQL.d.ts +4 -0
  42. package/dist/compilers/contracts/SQLCompiler.d.ts +5 -0
  43. package/dist/compilers/contracts/index.d.ts +6 -0
  44. package/dist/compilers/dialects/PostgresCompiler.d.ts +17 -0
  45. package/dist/compilers/dialects/SqliteCompiler.d.ts +10 -0
  46. package/dist/compilers/dialects/index.d.ts +5 -0
  47. package/dist/compilers/factories/PostgresCompilerFactory.d.ts +8 -0
  48. package/dist/compilers/factories/SqliteCompilerFactory.d.ts +8 -0
  49. package/dist/compilers/factories/index.d.ts +5 -0
  50. package/dist/compilers/index.d.ts +10 -0
  51. package/dist/compilers/index.js +6 -0
  52. package/dist/compilers-D8DJuTnQ.js +38 -0
  53. package/dist/compilers-D8DJuTnQ.js.map +1 -0
  54. package/dist/diff/diffSchema.d.ts +33 -0
  55. package/dist/diff/index.d.ts +4 -0
  56. package/dist/diff/index.js +8 -0
  57. package/dist/diff-Cs0TPEGR.js +10 -0
  58. package/dist/diff-Cs0TPEGR.js.map +1 -0
  59. package/dist/diffSchema-KgGHP-s3.js +86 -0
  60. package/dist/diffSchema-KgGHP-s3.js.map +1 -0
  61. package/dist/domain/Dialect.d.ts +2 -0
  62. package/dist/domain/Migration.d.ts +12 -0
  63. package/dist/domain/MigrationMode.d.ts +2 -0
  64. package/dist/domain/MigrationOperation.d.ts +76 -0
  65. package/dist/domain/MigrationOperation.js +1 -0
  66. package/dist/domain/index.d.ts +7 -0
  67. package/dist/domain/index.js +4 -0
  68. package/dist/domain/internal/InternalColumnType.d.ts +10 -0
  69. package/dist/domain/internal/InternalDialect.d.ts +4 -0
  70. package/dist/domain/internal/InternalMigrationMode.d.ts +4 -0
  71. package/dist/domain/internal/InternalOperationKind.d.ts +13 -0
  72. package/dist/domain/internal/InternalReferentialAction.d.ts +6 -0
  73. package/dist/domain-BXVlG0C0.js +10 -0
  74. package/dist/domain-BXVlG0C0.js.map +1 -0
  75. package/dist/generator/MigrationGenerator.d.ts +35 -0
  76. package/dist/generator/index.d.ts +4 -0
  77. package/dist/generator/index.js +5 -0
  78. package/dist/generator-3yC60b1u.js +10 -0
  79. package/dist/generator-3yC60b1u.js.map +1 -0
  80. package/dist/index.d.ts +23 -0
  81. package/dist/index.js +21 -0
  82. package/dist/introspect/DatabaseIntrospector.d.ts +9 -0
  83. package/dist/introspect/PostgresIntrospector.d.ts +42 -0
  84. package/dist/introspect/SqliteIntrospector.d.ts +40 -0
  85. package/dist/introspect/index.d.ts +6 -0
  86. package/dist/introspect/index.js +4 -0
  87. package/dist/introspect-ks-QSodq.js +13 -0
  88. package/dist/introspect-ks-QSodq.js.map +1 -0
  89. package/dist/runner/MigrationRunner.d.ts +73 -0
  90. package/dist/runner/index.d.ts +4 -0
  91. package/dist/runner/index.js +10 -0
  92. package/dist/runner-BOs-tItW.js +10 -0
  93. package/dist/runner-BOs-tItW.js.map +1 -0
  94. package/dist/strategies/CompilerStrategy.d.ts +20 -0
  95. package/dist/strategies/IntrospectorStrategy.d.ts +19 -0
  96. package/dist/strategies/index.d.ts +5 -0
  97. package/dist/strategies/index.js +9 -0
  98. package/dist/strategies-BvHwf4as.js +16 -0
  99. package/dist/strategies-BvHwf4as.js.map +1 -0
  100. package/package.json +101 -0
@@ -0,0 +1,88 @@
1
+ import type { CustomMigrationOperation, ForeignKeyCreate, ForeignKeyDrop, ForeignKeyValidate, IndexCreate, IndexDrop, TableCreate, TableDrop, ColumnAdd, ColumnDrop, ColumnAlter, ColumnRename } from '../../domain/MigrationOperation';
2
+ import type { ColumnSpec } from '../contracts/ColumnSpec';
3
+ import type { ColumnType } from '../contracts/ColumnType';
4
+ import type { DeleteReferentialAction } from '../contracts/DeleteReferentialAction';
5
+ import type { UpdateReferentialAction } from '../contracts/UpdateReferentialAction';
6
+ declare class ColumnBuilder {
7
+ static readonly BRAND: "tango.migrations.column_builder";
8
+ private spec;
9
+ readonly __tangoBrand: typeof ColumnBuilder.BRAND;
10
+ constructor(name: string);
11
+ static isColumnBuilder(value: unknown): value is ColumnBuilder;
12
+ serial(): ColumnBuilder;
13
+ int(): ColumnBuilder;
14
+ bigint(): ColumnBuilder;
15
+ text(): ColumnBuilder;
16
+ bool(): ColumnBuilder;
17
+ timestamptz(): ColumnBuilder;
18
+ jsonb(): ColumnBuilder;
19
+ uuid(): ColumnBuilder;
20
+ notNull(): ColumnBuilder;
21
+ defaultNow(): ColumnBuilder;
22
+ default(v: string | null): ColumnBuilder;
23
+ primaryKey(): ColumnBuilder;
24
+ unique(): ColumnBuilder;
25
+ references(table: string, column: string, opts?: {
26
+ onDelete?: DeleteReferentialAction;
27
+ onUpdate?: UpdateReferentialAction;
28
+ }): ColumnBuilder;
29
+ _done(): ColumnSpec;
30
+ }
31
+ type TableOperationBuilder = {
32
+ create(def: (cols: {
33
+ add: (name: string, cb: (b: ColumnBuilder) => ColumnBuilder) => void;
34
+ }) => void): TableCreate;
35
+ drop(opts?: {
36
+ cascade?: boolean;
37
+ }): TableDrop;
38
+ addColumn(name: string, cb: (b: ColumnBuilder) => ColumnBuilder): ColumnAdd;
39
+ dropColumn(name: string): ColumnDrop;
40
+ alterColumn(name: string, to: Partial<ColumnSpec>): ColumnAlter;
41
+ renameColumn(from: string, to: string): ColumnRename;
42
+ };
43
+ export declare class OpBuilder {
44
+ 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
+ static index: {
50
+ create(p: {
51
+ name: string;
52
+ table: string;
53
+ on: string[];
54
+ unique?: boolean;
55
+ where?: string;
56
+ concurrently?: boolean;
57
+ }): IndexCreate;
58
+ drop(p: {
59
+ name: string;
60
+ table: string;
61
+ concurrently?: boolean;
62
+ }): IndexDrop;
63
+ };
64
+ static foreignKey(p: {
65
+ table: string;
66
+ name?: string;
67
+ columns: string[];
68
+ references: {
69
+ table: string;
70
+ columns: string[];
71
+ };
72
+ onDelete?: string;
73
+ onUpdate?: string;
74
+ notValid?: boolean;
75
+ }): ForeignKeyCreate;
76
+ static foreignKeyValidate(p: {
77
+ table: string;
78
+ name: string;
79
+ }): ForeignKeyValidate;
80
+ static foreignKeyDrop(p: {
81
+ table: string;
82
+ name: string;
83
+ }): ForeignKeyDrop;
84
+ static registerCustomOperation<TName extends string, TArgs extends object>(name: TName, builder: (args: TArgs) => CustomMigrationOperation<TName, TArgs>): void;
85
+ static getCustomOperation<TName extends string, TArgs extends object>(name: TName): ((args: TArgs) => CustomMigrationOperation<TName, TArgs>) | undefined;
86
+ }
87
+ export declare function applyFieldType(builder: ColumnBuilder, fieldType: ColumnType): ColumnBuilder;
88
+ export {};
@@ -0,0 +1,173 @@
1
+ import { InternalColumnType } from '../../domain/internal/InternalColumnType';
2
+ import { InternalOperationKind } from '../../domain/internal/InternalOperationKind';
3
+ class ColumnBuilder {
4
+ static BRAND = 'tango.migrations.column_builder';
5
+ spec = {};
6
+ __tangoBrand = ColumnBuilder.BRAND;
7
+ constructor(name) {
8
+ this.spec.name = name;
9
+ }
10
+ static isColumnBuilder(value) {
11
+ return (typeof value === 'object' &&
12
+ value !== null &&
13
+ value.__tangoBrand === ColumnBuilder.BRAND);
14
+ }
15
+ serial() {
16
+ this.spec.type = InternalColumnType.SERIAL;
17
+ return this;
18
+ }
19
+ int() {
20
+ this.spec.type = InternalColumnType.INT;
21
+ return this;
22
+ }
23
+ bigint() {
24
+ this.spec.type = InternalColumnType.BIGINT;
25
+ return this;
26
+ }
27
+ text() {
28
+ this.spec.type = InternalColumnType.TEXT;
29
+ return this;
30
+ }
31
+ bool() {
32
+ this.spec.type = InternalColumnType.BOOL;
33
+ return this;
34
+ }
35
+ timestamptz() {
36
+ this.spec.type = InternalColumnType.TIMESTAMPTZ;
37
+ return this;
38
+ }
39
+ jsonb() {
40
+ this.spec.type = InternalColumnType.JSONB;
41
+ return this;
42
+ }
43
+ uuid() {
44
+ this.spec.type = InternalColumnType.UUID;
45
+ return this;
46
+ }
47
+ notNull() {
48
+ this.spec.notNull = true;
49
+ return this;
50
+ }
51
+ defaultNow() {
52
+ this.spec.default = { now: true };
53
+ return this;
54
+ }
55
+ default(v) {
56
+ this.spec.default = v;
57
+ return this;
58
+ }
59
+ primaryKey() {
60
+ this.spec.primaryKey = true;
61
+ return this;
62
+ }
63
+ unique() {
64
+ this.spec.unique = true;
65
+ return this;
66
+ }
67
+ references(table, column, opts) {
68
+ this.spec.references = {
69
+ table,
70
+ column,
71
+ onDelete: opts?.onDelete,
72
+ onUpdate: opts?.onUpdate,
73
+ };
74
+ return this;
75
+ }
76
+ _done() {
77
+ return this.spec;
78
+ }
79
+ }
80
+ export class OpBuilder {
81
+ static BRAND = 'tango.migrations.op_builder';
82
+ __tangoBrand = OpBuilder.BRAND;
83
+ static customOperations = new Map();
84
+ static isOpBuilder(value) {
85
+ return (typeof value === 'object' &&
86
+ value !== null &&
87
+ value.__tangoBrand === OpBuilder.BRAND);
88
+ }
89
+ static table(table) {
90
+ return {
91
+ create(def) {
92
+ const columns = [];
93
+ def({
94
+ add(name, cb) {
95
+ columns.push(cb(new ColumnBuilder(name))._done());
96
+ },
97
+ });
98
+ return { kind: InternalOperationKind.TABLE_CREATE, table, columns };
99
+ },
100
+ drop(opts) {
101
+ return { kind: InternalOperationKind.TABLE_DROP, table, cascade: opts?.cascade };
102
+ },
103
+ addColumn(name, cb) {
104
+ return { kind: InternalOperationKind.COLUMN_ADD, table, column: cb(new ColumnBuilder(name))._done() };
105
+ },
106
+ dropColumn(name) {
107
+ return { kind: InternalOperationKind.COLUMN_DROP, table, column: name };
108
+ },
109
+ alterColumn(name, to) {
110
+ return { kind: InternalOperationKind.COLUMN_ALTER, table, column: name, to };
111
+ },
112
+ renameColumn(from, to) {
113
+ return { kind: InternalOperationKind.COLUMN_RENAME, table, from, to };
114
+ },
115
+ };
116
+ }
117
+ static index = {
118
+ create(p) {
119
+ return { kind: InternalOperationKind.INDEX_CREATE, ...p };
120
+ },
121
+ drop(p) {
122
+ return { kind: InternalOperationKind.INDEX_DROP, ...p };
123
+ },
124
+ };
125
+ static foreignKey(p) {
126
+ return {
127
+ kind: InternalOperationKind.FK_CREATE,
128
+ table: p.table,
129
+ name: p.name,
130
+ columns: p.columns,
131
+ refTable: p.references.table,
132
+ refColumns: p.references.columns,
133
+ onDelete: p.onDelete,
134
+ onUpdate: p.onUpdate,
135
+ notValid: p.notValid,
136
+ };
137
+ }
138
+ static foreignKeyValidate(p) {
139
+ return { kind: InternalOperationKind.FK_VALIDATE, ...p };
140
+ }
141
+ static foreignKeyDrop(p) {
142
+ return { kind: InternalOperationKind.FK_DROP, ...p };
143
+ }
144
+ static registerCustomOperation(name, builder) {
145
+ this.customOperations.set(name, builder);
146
+ }
147
+ static getCustomOperation(name) {
148
+ return this.customOperations.get(name);
149
+ }
150
+ }
151
+ export function applyFieldType(builder, fieldType) {
152
+ switch (fieldType) {
153
+ case InternalColumnType.SERIAL:
154
+ return builder.serial();
155
+ case InternalColumnType.INT:
156
+ return builder.int();
157
+ case InternalColumnType.BIGINT:
158
+ return builder.bigint();
159
+ case InternalColumnType.TEXT:
160
+ return builder.text();
161
+ case InternalColumnType.BOOL:
162
+ return builder.bool();
163
+ case InternalColumnType.TIMESTAMPTZ:
164
+ return builder.timestamptz();
165
+ case InternalColumnType.JSONB:
166
+ return builder.jsonb();
167
+ case InternalColumnType.UUID:
168
+ return builder.uuid();
169
+ default:
170
+ const exhaustive = fieldType;
171
+ throw new Error(`Unsupported field type: ${exhaustive}`);
172
+ }
173
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Domain boundary barrel: centralizes this subdomain's public contract.
3
+ */
4
+ export { OpBuilder, OpBuilder as op, applyFieldType } from './OpBuilder';
@@ -0,0 +1,21 @@
1
+ import type { Builder } from '../contracts/Builder';
2
+ import type { MigrationOperation } from '../../domain/MigrationOperation';
3
+ import type { MigrationMode } from '../../domain/MigrationMode';
4
+ export declare class CollectingBuilder implements Builder {
5
+ static readonly BRAND: "tango.migrations.collecting_builder";
6
+ private mode?;
7
+ readonly __tangoBrand: typeof CollectingBuilder.BRAND;
8
+ ops: MigrationOperation[];
9
+ dataFns: Array<(ctx: {
10
+ query(sql: string, params?: readonly unknown[]): Promise<void>;
11
+ }) => Promise<void>>;
12
+ static isCollectingBuilder(value: unknown): value is CollectingBuilder;
13
+ run(...ops: MigrationOperation[]): void;
14
+ data(fn: (ctx: {
15
+ query(sql: string, params?: readonly unknown[]): Promise<void>;
16
+ }) => Promise<void>): void;
17
+ options(o: {
18
+ mode?: MigrationMode;
19
+ }): void;
20
+ getMode(): MigrationMode | undefined;
21
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Domain boundary barrel: centralizes this subdomain's public contract.
3
+ */
4
+ export { CollectingBuilder } from './CollectingBuilder';
@@ -0,0 +1,236 @@
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";
5
+
6
+ //#region src/builder/contracts/index.ts
7
+ var contracts_exports = {};
8
+
9
+ //#endregion
10
+ //#region src/builder/ops/OpBuilder.ts
11
+ var ColumnBuilder = class ColumnBuilder {
12
+ static BRAND = "tango.migrations.column_builder";
13
+ spec = {};
14
+ __tangoBrand = ColumnBuilder.BRAND;
15
+ constructor(name) {
16
+ this.spec.name = name;
17
+ }
18
+ static isColumnBuilder(value) {
19
+ return typeof value === "object" && value !== null && value.__tangoBrand === ColumnBuilder.BRAND;
20
+ }
21
+ serial() {
22
+ this.spec.type = InternalColumnType.SERIAL;
23
+ return this;
24
+ }
25
+ int() {
26
+ this.spec.type = InternalColumnType.INT;
27
+ return this;
28
+ }
29
+ bigint() {
30
+ this.spec.type = InternalColumnType.BIGINT;
31
+ return this;
32
+ }
33
+ text() {
34
+ this.spec.type = InternalColumnType.TEXT;
35
+ return this;
36
+ }
37
+ bool() {
38
+ this.spec.type = InternalColumnType.BOOL;
39
+ return this;
40
+ }
41
+ timestamptz() {
42
+ this.spec.type = InternalColumnType.TIMESTAMPTZ;
43
+ return this;
44
+ }
45
+ jsonb() {
46
+ this.spec.type = InternalColumnType.JSONB;
47
+ return this;
48
+ }
49
+ uuid() {
50
+ this.spec.type = InternalColumnType.UUID;
51
+ return this;
52
+ }
53
+ notNull() {
54
+ this.spec.notNull = true;
55
+ return this;
56
+ }
57
+ defaultNow() {
58
+ this.spec.default = { now: true };
59
+ return this;
60
+ }
61
+ default(v) {
62
+ this.spec.default = v;
63
+ return this;
64
+ }
65
+ primaryKey() {
66
+ this.spec.primaryKey = true;
67
+ return this;
68
+ }
69
+ unique() {
70
+ this.spec.unique = true;
71
+ return this;
72
+ }
73
+ references(table, column, opts) {
74
+ this.spec.references = {
75
+ table,
76
+ column,
77
+ onDelete: opts?.onDelete,
78
+ onUpdate: opts?.onUpdate
79
+ };
80
+ return this;
81
+ }
82
+ _done() {
83
+ return this.spec;
84
+ }
85
+ };
86
+ var OpBuilder = class OpBuilder {
87
+ static BRAND = "tango.migrations.op_builder";
88
+ __tangoBrand = OpBuilder.BRAND;
89
+ static customOperations = new Map();
90
+ static isOpBuilder(value) {
91
+ return typeof value === "object" && value !== null && value.__tangoBrand === OpBuilder.BRAND;
92
+ }
93
+ static table(table) {
94
+ return {
95
+ create(def) {
96
+ const columns = [];
97
+ def({ add(name, cb) {
98
+ columns.push(cb(new ColumnBuilder(name))._done());
99
+ } });
100
+ return {
101
+ kind: InternalOperationKind.TABLE_CREATE,
102
+ table,
103
+ columns
104
+ };
105
+ },
106
+ drop(opts) {
107
+ return {
108
+ kind: InternalOperationKind.TABLE_DROP,
109
+ table,
110
+ cascade: opts?.cascade
111
+ };
112
+ },
113
+ addColumn(name, cb) {
114
+ return {
115
+ kind: InternalOperationKind.COLUMN_ADD,
116
+ table,
117
+ column: cb(new ColumnBuilder(name))._done()
118
+ };
119
+ },
120
+ dropColumn(name) {
121
+ return {
122
+ kind: InternalOperationKind.COLUMN_DROP,
123
+ table,
124
+ column: name
125
+ };
126
+ },
127
+ alterColumn(name, to) {
128
+ return {
129
+ kind: InternalOperationKind.COLUMN_ALTER,
130
+ table,
131
+ column: name,
132
+ to
133
+ };
134
+ },
135
+ renameColumn(from, to) {
136
+ return {
137
+ kind: InternalOperationKind.COLUMN_RENAME,
138
+ table,
139
+ from,
140
+ to
141
+ };
142
+ }
143
+ };
144
+ }
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
+ };
159
+ static foreignKey(p) {
160
+ return {
161
+ kind: InternalOperationKind.FK_CREATE,
162
+ table: p.table,
163
+ name: p.name,
164
+ columns: p.columns,
165
+ refTable: p.references.table,
166
+ refColumns: p.references.columns,
167
+ onDelete: p.onDelete,
168
+ onUpdate: p.onUpdate,
169
+ notValid: p.notValid
170
+ };
171
+ }
172
+ static foreignKeyValidate(p) {
173
+ return {
174
+ kind: InternalOperationKind.FK_VALIDATE,
175
+ ...p
176
+ };
177
+ }
178
+ static foreignKeyDrop(p) {
179
+ return {
180
+ kind: InternalOperationKind.FK_DROP,
181
+ ...p
182
+ };
183
+ }
184
+ static registerCustomOperation(name, builder) {
185
+ this.customOperations.set(name, builder);
186
+ }
187
+ static getCustomOperation(name) {
188
+ return this.customOperations.get(name);
189
+ }
190
+ };
191
+ function applyFieldType(builder, fieldType) {
192
+ switch (fieldType) {
193
+ case InternalColumnType.SERIAL: return builder.serial();
194
+ case InternalColumnType.INT: return builder.int();
195
+ case InternalColumnType.BIGINT: return builder.bigint();
196
+ case InternalColumnType.TEXT: return builder.text();
197
+ case InternalColumnType.BOOL: return builder.bool();
198
+ case InternalColumnType.TIMESTAMPTZ: return builder.timestamptz();
199
+ case InternalColumnType.JSONB: return builder.jsonb();
200
+ case InternalColumnType.UUID: return builder.uuid();
201
+ default:
202
+ const exhaustive = fieldType;
203
+ throw new Error(`Unsupported field type: ${exhaustive}`);
204
+ }
205
+ }
206
+
207
+ //#endregion
208
+ //#region src/builder/ops/index.ts
209
+ var ops_exports = {};
210
+ __export(ops_exports, {
211
+ OpBuilder: () => OpBuilder,
212
+ applyFieldType: () => applyFieldType,
213
+ op: () => OpBuilder
214
+ });
215
+
216
+ //#endregion
217
+ //#region src/builder/runtime/index.ts
218
+ var runtime_exports = {};
219
+ __export(runtime_exports, { CollectingBuilder: () => CollectingBuilder });
220
+
221
+ //#endregion
222
+ //#region src/builder/index.ts
223
+ var builder_exports = {};
224
+ __export(builder_exports, {
225
+ CollectingBuilder: () => CollectingBuilder,
226
+ OpBuilder: () => OpBuilder,
227
+ applyFieldType: () => applyFieldType,
228
+ contracts: () => contracts_exports,
229
+ op: () => OpBuilder,
230
+ ops: () => ops_exports,
231
+ runtime: () => runtime_exports
232
+ });
233
+
234
+ //#endregion
235
+ export { OpBuilder, applyFieldType, builder_exports, contracts_exports, ops_exports, runtime_exports };
236
+ //# sourceMappingURL=builder-Dtk8oP_Y.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builder-Dtk8oP_Y.js","names":["name: string","value: unknown","v: string | null","table: string","column: string","opts?: {\n onDelete?: DeleteReferentialAction;\n onUpdate?: UpdateReferentialAction;\n }","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 name: string;\n table: string;\n on: string[];\n unique?: boolean;\n where?: string;\n concurrently?: boolean;\n }","p: { name: string; table: string; concurrently?: boolean }","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 {\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\nclass ColumnBuilder {\n static readonly BRAND = 'tango.migrations.column_builder' as const;\n private spec: Partial<ColumnSpec> = {};\n readonly __tangoBrand: typeof ColumnBuilder.BRAND = ColumnBuilder.BRAND;\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 serial(): ColumnBuilder {\n this.spec.type = InternalColumnType.SERIAL;\n return this;\n }\n int(): ColumnBuilder {\n this.spec.type = InternalColumnType.INT;\n return this;\n }\n bigint(): ColumnBuilder {\n this.spec.type = InternalColumnType.BIGINT;\n return this;\n }\n text(): ColumnBuilder {\n this.spec.type = InternalColumnType.TEXT;\n return this;\n }\n bool(): ColumnBuilder {\n this.spec.type = InternalColumnType.BOOL;\n return this;\n }\n timestamptz(): ColumnBuilder {\n this.spec.type = InternalColumnType.TIMESTAMPTZ;\n return this;\n }\n jsonb(): ColumnBuilder {\n this.spec.type = InternalColumnType.JSONB;\n return this;\n }\n uuid(): ColumnBuilder {\n this.spec.type = InternalColumnType.UUID;\n return this;\n }\n\n notNull(): ColumnBuilder {\n this.spec.notNull = true;\n return this;\n }\n defaultNow(): ColumnBuilder {\n this.spec.default = { now: true };\n return this;\n }\n default(v: string | null): ColumnBuilder {\n this.spec.default = v;\n return this;\n }\n primaryKey(): ColumnBuilder {\n this.spec.primaryKey = true;\n return this;\n }\n unique(): ColumnBuilder {\n this.spec.unique = true;\n return this;\n }\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\nexport class OpBuilder {\n static readonly BRAND = 'tango.migrations.op_builder' as const;\n readonly __tangoBrand: typeof OpBuilder.BRAND = OpBuilder.BRAND;\n private static customOperations = new Map<\n string,\n (args: Record<string, unknown>) => CustomMigrationOperation\n >();\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 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 static index = {\n create(p: {\n name: string;\n table: string;\n on: string[];\n unique?: boolean;\n where?: string;\n concurrently?: boolean;\n }): IndexCreate {\n return { kind: InternalOperationKind.INDEX_CREATE, ...p };\n },\n drop(p: { name: string; table: string; concurrently?: boolean }): IndexDrop {\n return { kind: InternalOperationKind.INDEX_DROP, ...p };\n },\n };\n\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 static foreignKeyValidate(p: { table: string; name: string }): ForeignKeyValidate {\n return { kind: InternalOperationKind.FK_VALIDATE, ...p };\n }\n\n static foreignKeyDrop(p: { table: string; name: string }): ForeignKeyDrop {\n return { kind: InternalOperationKind.FK_DROP, ...p };\n }\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 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\n | ((args: TArgs) => CustomMigrationOperation<TName, TArgs>)\n | undefined;\n }\n}\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 * 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":";;;;;;;;;;ICqBM,gBAAN,MAAM,cAAc;CAChB,OAAgB,QAAQ;CACxB,OAAoC,CAAE;CACtC,eAAoD,cAAc;CAElE,YAAYA,MAAc;AACtB,OAAK,KAAK,OAAO;CACpB;CAED,OAAO,gBAAgBC,OAAwC;AAC3D,gBACW,UAAU,YACjB,UAAU,QACT,MAAqC,iBAAiB,cAAc;CAE5E;CAED,SAAwB;AACpB,OAAK,KAAK,OAAO,mBAAmB;AACpC,SAAO;CACV;CACD,MAAqB;AACjB,OAAK,KAAK,OAAO,mBAAmB;AACpC,SAAO;CACV;CACD,SAAwB;AACpB,OAAK,KAAK,OAAO,mBAAmB;AACpC,SAAO;CACV;CACD,OAAsB;AAClB,OAAK,KAAK,OAAO,mBAAmB;AACpC,SAAO;CACV;CACD,OAAsB;AAClB,OAAK,KAAK,OAAO,mBAAmB;AACpC,SAAO;CACV;CACD,cAA6B;AACzB,OAAK,KAAK,OAAO,mBAAmB;AACpC,SAAO;CACV;CACD,QAAuB;AACnB,OAAK,KAAK,OAAO,mBAAmB;AACpC,SAAO;CACV;CACD,OAAsB;AAClB,OAAK,KAAK,OAAO,mBAAmB;AACpC,SAAO;CACV;CAED,UAAyB;AACrB,OAAK,KAAK,UAAU;AACpB,SAAO;CACV;CACD,aAA4B;AACxB,OAAK,KAAK,UAAU,EAAE,KAAK,KAAM;AACjC,SAAO;CACV;CACD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;AACJ"}
@@ -0,0 +1,12 @@
1
+
2
+ //#region rolldown:runtime
3
+ var __defProp = Object.defineProperty;
4
+ var __export = (target, all) => {
5
+ for (var name in all) __defProp(target, name, {
6
+ get: all[name],
7
+ enumerable: true
8
+ });
9
+ };
10
+
11
+ //#endregion
12
+ export { __export };
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};