duronto 0.0.0 → 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.
- package/README.md +23 -0
- package/dist/cli/commands/check.d.ts +2 -0
- package/dist/cli/commands/check.d.ts.map +1 -0
- package/dist/cli/commands/check.js +22 -0
- package/dist/cli/commands/check.js.map +1 -0
- package/dist/cli/commands/diff.d.ts +2 -0
- package/dist/cli/commands/diff.d.ts.map +1 -0
- package/dist/cli/commands/diff.js +26 -0
- package/dist/cli/commands/diff.js.map +1 -0
- package/dist/cli/commands/generate.d.ts +6 -0
- package/dist/cli/commands/generate.d.ts.map +1 -0
- package/dist/cli/commands/generate.js +51 -0
- package/dist/cli/commands/generate.js.map +1 -0
- package/dist/cli/commands/init.d.ts +2 -0
- package/dist/cli/commands/init.d.ts.map +1 -0
- package/dist/cli/commands/init.js +36 -0
- package/dist/cli/commands/init.js.map +1 -0
- package/dist/cli/commands/sql.d.ts +2 -0
- package/dist/cli/commands/sql.d.ts.map +1 -0
- package/dist/cli/commands/sql.js +24 -0
- package/dist/cli/commands/sql.js.map +1 -0
- package/dist/cli/commands/types.d.ts +2 -0
- package/dist/cli/commands/types.d.ts.map +1 -0
- package/dist/cli/commands/types.js +32 -0
- package/dist/cli/commands/types.js.map +1 -0
- package/dist/cli/config.d.ts +9 -0
- package/dist/cli/config.d.ts.map +1 -0
- package/dist/cli/config.js +29 -0
- package/dist/cli/config.js.map +1 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +61 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/compiler/compile.d.ts +5 -0
- package/dist/compiler/compile.d.ts.map +1 -0
- package/dist/compiler/compile.js +221 -0
- package/dist/compiler/compile.js.map +1 -0
- package/dist/compiler/validate.d.ts +23 -0
- package/dist/compiler/validate.d.ts.map +1 -0
- package/dist/compiler/validate.js +68 -0
- package/dist/compiler/validate.js.map +1 -0
- package/dist/core/column.d.ts +55 -0
- package/dist/core/column.d.ts.map +1 -0
- package/dist/core/column.js +122 -0
- package/dist/core/column.js.map +1 -0
- package/dist/core/errors.d.ts +7 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +15 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/ir.d.ts +57 -0
- package/dist/core/ir.d.ts.map +1 -0
- package/dist/core/ir.js +2 -0
- package/dist/core/ir.js.map +1 -0
- package/dist/core/naming.d.ts +2 -0
- package/dist/core/naming.d.ts.map +1 -0
- package/dist/core/naming.js +8 -0
- package/dist/core/naming.js.map +1 -0
- package/dist/core/table.d.ts +40 -0
- package/dist/core/table.d.ts.map +1 -0
- package/dist/core/table.js +75 -0
- package/dist/core/table.js.map +1 -0
- package/dist/core/types.d.ts +16 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +2 -0
- package/dist/core/types.js.map +1 -0
- package/dist/dialects/postgres/index.d.ts +3 -0
- package/dist/dialects/postgres/index.d.ts.map +1 -0
- package/dist/dialects/postgres/index.js +156 -0
- package/dist/dialects/postgres/index.js.map +1 -0
- package/dist/dialects/sqlite/index.d.ts +13 -0
- package/dist/dialects/sqlite/index.d.ts.map +1 -0
- package/dist/dialects/sqlite/index.js +218 -0
- package/dist/dialects/sqlite/index.js.map +1 -0
- package/dist/dialects/types.d.ts +10 -0
- package/dist/dialects/types.d.ts.map +1 -0
- package/dist/dialects/types.js +2 -0
- package/dist/dialects/types.js.map +1 -0
- package/dist/diff/diff.d.ts +4 -0
- package/dist/diff/diff.d.ts.map +1 -0
- package/dist/diff/diff.js +102 -0
- package/dist/diff/diff.js.map +1 -0
- package/dist/diff/index.d.ts +3 -0
- package/dist/diff/index.d.ts.map +1 -0
- package/dist/diff/index.js +3 -0
- package/dist/diff/index.js.map +1 -0
- package/dist/diff/types.d.ts +60 -0
- package/dist/diff/types.d.ts.map +1 -0
- package/dist/diff/types.js +2 -0
- package/dist/diff/types.js.map +1 -0
- package/dist/index.d.ts +20 -3
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -6
- package/dist/index.js.map +1 -1
- package/dist/snapshot.d.ts +6 -0
- package/dist/snapshot.d.ts.map +1 -0
- package/dist/snapshot.js +29 -0
- package/dist/snapshot.js.map +1 -0
- package/package.json +29 -34
- package/dist/index.cjs +0 -10
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diff.d.ts","sourceRoot":"","sources":["../../src/diff/diff.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,EAAU,UAAU,EAAE,MAAM,YAAY,CAAC;AAMrD,wBAAgB,IAAI,CAAC,KAAK,EAAE,EAAE,GAAG,IAAI,EAAE,KAAK,EAAE,EAAE,GAAG,UAAU,CA8F5D"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
function colEqual(a, b) {
|
|
2
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
3
|
+
}
|
|
4
|
+
export function diff(oldIR, newIR) {
|
|
5
|
+
const ops = [];
|
|
6
|
+
let destructive = false;
|
|
7
|
+
const oldTables = oldIR?.tables ?? {};
|
|
8
|
+
const newTables = newIR.tables;
|
|
9
|
+
// dropped tables
|
|
10
|
+
for (const name of Object.keys(oldTables)) {
|
|
11
|
+
if (!(name in newTables)) {
|
|
12
|
+
ops.push({ kind: "dropTable", table: name, destructive: true });
|
|
13
|
+
destructive = true;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
// created tables
|
|
17
|
+
for (const name of Object.keys(newTables)) {
|
|
18
|
+
if (!(name in oldTables)) {
|
|
19
|
+
ops.push({ kind: "createTable", table: name });
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
// modified tables
|
|
23
|
+
for (const name of Object.keys(newTables)) {
|
|
24
|
+
if (!(name in oldTables))
|
|
25
|
+
continue;
|
|
26
|
+
const oldT = oldTables[name];
|
|
27
|
+
const newT = newTables[name];
|
|
28
|
+
// renamed columns detection
|
|
29
|
+
const renamedOld = new Set();
|
|
30
|
+
const renamedNew = new Set();
|
|
31
|
+
// columns added
|
|
32
|
+
for (const [newCol, newColDef] of Object.entries(newT.columns)) {
|
|
33
|
+
if (newCol in oldT.columns)
|
|
34
|
+
continue;
|
|
35
|
+
const hint = newColDef.renamedFrom;
|
|
36
|
+
if (hint && hint in oldT.columns) {
|
|
37
|
+
ops.push({ kind: "renameColumn", table: name, from: hint, to: newCol });
|
|
38
|
+
renamedOld.add(hint);
|
|
39
|
+
renamedNew.add(newCol);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
ops.push({ kind: "addColumn", table: name, column: newCol, col: newColDef });
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// columns dropped
|
|
46
|
+
for (const oldCol of Object.keys(oldT.columns)) {
|
|
47
|
+
if (oldCol in newT.columns)
|
|
48
|
+
continue;
|
|
49
|
+
if (renamedOld.has(oldCol))
|
|
50
|
+
continue;
|
|
51
|
+
ops.push({ kind: "dropColumn", table: name, column: oldCol, destructive: true });
|
|
52
|
+
destructive = true;
|
|
53
|
+
}
|
|
54
|
+
// columns altered
|
|
55
|
+
for (const col of Object.keys(newT.columns)) {
|
|
56
|
+
if (!(col in oldT.columns))
|
|
57
|
+
continue;
|
|
58
|
+
if (renamedNew.has(col))
|
|
59
|
+
continue;
|
|
60
|
+
const oldCol = oldT.columns[col];
|
|
61
|
+
const newCol = newT.columns[col];
|
|
62
|
+
if (!colEqual(oldCol, newCol)) {
|
|
63
|
+
const isDestructive = oldCol.type !== newCol.type ||
|
|
64
|
+
(!oldCol.notNull && newCol.notNull) ||
|
|
65
|
+
(oldCol.unique && !newCol.unique);
|
|
66
|
+
ops.push({ kind: "alterColumn", table: name, column: col, oldCol: oldCol, newCol: newCol, destructive: isDestructive, tableIR: newT, oldTableIR: oldT });
|
|
67
|
+
if (isDestructive)
|
|
68
|
+
destructive = true;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
// indexes
|
|
72
|
+
const oldIdx = new Map(oldT.indexes.map((i) => [i.name, i]));
|
|
73
|
+
const newIdx = new Map(newT.indexes.map((i) => [i.name, i]));
|
|
74
|
+
for (const idxName of newIdx.keys()) {
|
|
75
|
+
if (!oldIdx.has(idxName))
|
|
76
|
+
ops.push({ kind: "addIndex", table: name, index: idxName, idx: newIdx.get(idxName) });
|
|
77
|
+
}
|
|
78
|
+
for (const idxName of oldIdx.keys()) {
|
|
79
|
+
if (!newIdx.has(idxName))
|
|
80
|
+
ops.push({ kind: "dropIndex", table: name, index: idxName, idx: oldIdx.get(idxName) });
|
|
81
|
+
}
|
|
82
|
+
// foreign keys (count-based)
|
|
83
|
+
if (newT.foreignKeys.length > oldT.foreignKeys.length) {
|
|
84
|
+
const fk = newT.foreignKeys[newT.foreignKeys.length - 1];
|
|
85
|
+
ops.push(fk ? { kind: "addForeignKey", table: name, fk } : { kind: "addForeignKey", table: name });
|
|
86
|
+
}
|
|
87
|
+
else if (newT.foreignKeys.length < oldT.foreignKeys.length) {
|
|
88
|
+
const fk = oldT.foreignKeys[oldT.foreignKeys.length - 1];
|
|
89
|
+
ops.push(fk ? { kind: "dropForeignKey", table: name, fk } : { kind: "dropForeignKey", table: name });
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
// sort for determinism
|
|
93
|
+
ops.sort((a, b) => {
|
|
94
|
+
const ta = a.table ?? "";
|
|
95
|
+
const tb = b.table ?? "";
|
|
96
|
+
if (ta !== tb)
|
|
97
|
+
return ta.localeCompare(tb);
|
|
98
|
+
return a.kind.localeCompare(b.kind);
|
|
99
|
+
});
|
|
100
|
+
return { ops, destructive };
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=diff.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diff.js","sourceRoot":"","sources":["../../src/diff/diff.ts"],"names":[],"mapp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AAC,MAAM,EAAE,CAAC;YAC7D,MAAM,EAAE,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;YACzD,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,gBAAgB,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,gBAAgB,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QACvG,CAAC;IACH,CAAC;IAED,uBAAuB;IACvB,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QAChB,MAAM,EAAE,GAAI,CAAwB,CAAC,KAAK,IAAI,EAAE,CAAC;QACjD,MAAM,EAAE,GAAI,CAAwB,CAAC,KAAK,IAAI,EAAE,CAAC;QACjD,IAAI,EAAE,KAAK,EAAE;YAAE,OAAO,EAAE,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;QAC3C,OAAO,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;IAEH,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,CAAC;AAC9B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/diff/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/diff/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { IRColumn, IRTable, IRIndex, IRForeignKey } from "../core/ir.js";
|
|
2
|
+
export type DiffOp = {
|
|
3
|
+
kind: "createTable";
|
|
4
|
+
table: string;
|
|
5
|
+
} | {
|
|
6
|
+
kind: "dropTable";
|
|
7
|
+
table: string;
|
|
8
|
+
destructive: true;
|
|
9
|
+
} | {
|
|
10
|
+
kind: "addColumn";
|
|
11
|
+
table: string;
|
|
12
|
+
column: string;
|
|
13
|
+
col: IRColumn;
|
|
14
|
+
} | {
|
|
15
|
+
kind: "dropColumn";
|
|
16
|
+
table: string;
|
|
17
|
+
column: string;
|
|
18
|
+
destructive: true;
|
|
19
|
+
} | {
|
|
20
|
+
kind: "alterColumn";
|
|
21
|
+
table: string;
|
|
22
|
+
column: string;
|
|
23
|
+
oldCol: IRColumn;
|
|
24
|
+
newCol: IRColumn;
|
|
25
|
+
destructive?: boolean;
|
|
26
|
+
tableIR: IRTable;
|
|
27
|
+
oldTableIR: IRTable;
|
|
28
|
+
} | {
|
|
29
|
+
kind: "renameColumn";
|
|
30
|
+
table: string;
|
|
31
|
+
from: string;
|
|
32
|
+
to: string;
|
|
33
|
+
} | {
|
|
34
|
+
kind: "renameTable";
|
|
35
|
+
from: string;
|
|
36
|
+
to: string;
|
|
37
|
+
} | {
|
|
38
|
+
kind: "addIndex";
|
|
39
|
+
table: string;
|
|
40
|
+
index: string;
|
|
41
|
+
idx: IRIndex;
|
|
42
|
+
} | {
|
|
43
|
+
kind: "dropIndex";
|
|
44
|
+
table: string;
|
|
45
|
+
index: string;
|
|
46
|
+
idx: IRIndex;
|
|
47
|
+
} | {
|
|
48
|
+
kind: "addForeignKey";
|
|
49
|
+
table: string;
|
|
50
|
+
fk?: IRForeignKey;
|
|
51
|
+
} | {
|
|
52
|
+
kind: "dropForeignKey";
|
|
53
|
+
table: string;
|
|
54
|
+
fk?: IRForeignKey;
|
|
55
|
+
};
|
|
56
|
+
export interface DiffResult {
|
|
57
|
+
ops: DiffOp[];
|
|
58
|
+
destructive: boolean;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
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,GAAG,EAAE,OAAO,CAAA;CAAE,GAChE;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,OAAO,CAAA;CAAE,GACjE;IAAE,IAAI,EAAE,eAAe,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,EAAE,CAAC,EAAE,YAAY,CAAA;CAAE,GAC3D;IAAE,IAAI,EAAE,gBAAgB,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,EAAE,CAAC,EAAE,YAAY,CAAA;CAAE,CAAC;AAEjE,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,EAAE,CAAC;IACd,WAAW,EAAE,OAAO,CAAC;CACtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/diff/types.ts"],"names":[],"mappings":""}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export
|
|
1
|
+
export * from "./core/column.js";
|
|
2
|
+
export * from "./core/table.js";
|
|
3
|
+
export * from "./core/types.js";
|
|
4
|
+
export * from "./core/ir.js";
|
|
5
|
+
export * from "./core/naming.js";
|
|
6
|
+
export * from "./core/errors.js";
|
|
7
|
+
export { compileSchema, collectTables } from "./compiler/compile.js";
|
|
8
|
+
export { sqliteDialect } from "./dialects/sqlite/index.js";
|
|
9
|
+
export { postgresDialect } from "./dialects/postgres/index.js";
|
|
10
|
+
export type { Dialect } from "./dialects/types.js";
|
|
11
|
+
import type { Dialect } from "./dialects/types.js";
|
|
12
|
+
export interface TinySchemaConfig {
|
|
13
|
+
schema: string;
|
|
14
|
+
out: string;
|
|
15
|
+
dialect: "sqlite" | "postgres";
|
|
16
|
+
naming?: "snake_case" | "camelCase";
|
|
17
|
+
}
|
|
18
|
+
export declare function defineConfig(config: TinySchemaConfig): TinySchemaConfig;
|
|
19
|
+
export declare function getDialect(name: string): Dialect;
|
|
20
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE3D,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAE/D,YAAY,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAEnD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAEnD,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,QAAQ,GAAG,UAAU,CAAC;IAC/B,MAAM,CAAC,EAAE,YAAY,GAAG,WAAW,CAAC;CACrC;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,gBAAgB,GAAG,gBAAgB,CAEvE;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAIhD"}
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export * from "./core/column.js";
|
|
2
|
+
export * from "./core/table.js";
|
|
3
|
+
export * from "./core/types.js";
|
|
4
|
+
export * from "./core/ir.js";
|
|
5
|
+
export * from "./core/naming.js";
|
|
6
|
+
export * from "./core/errors.js";
|
|
7
|
+
export { compileSchema, collectTables } from "./compiler/compile.js";
|
|
8
|
+
export { sqliteDialect } from "./dialects/sqlite/index.js";
|
|
9
|
+
import { sqliteDialect } from "./dialects/sqlite/index.js";
|
|
10
|
+
export { postgresDialect } from "./dialects/postgres/index.js";
|
|
11
|
+
import { postgresDialect } from "./dialects/postgres/index.js";
|
|
12
|
+
export function defineConfig(config) {
|
|
13
|
+
return config;
|
|
14
|
+
}
|
|
15
|
+
export function getDialect(name) {
|
|
16
|
+
if (name === "sqlite")
|
|
17
|
+
return sqliteDialect;
|
|
18
|
+
if (name === "postgres")
|
|
19
|
+
return postgresDialect;
|
|
20
|
+
throw new Error(`Unknown dialect: ${name}`);
|
|
4
21
|
}
|
|
5
|
-
|
|
6
|
-
export { sayHello };
|
|
7
|
-
//# sourceMappingURL=index.js.map
|
|
8
22
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAY/D,MAAM,UAAU,YAAY,CAAC,MAAwB;IACnD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,IAAI,IAAI,KAAK,QAAQ;QAAE,OAAO,aAAmC,CAAC;IAClE,IAAI,IAAI,KAAK,UAAU;QAAE,OAAO,eAAqC,CAAC;IACtE,MAAM,IAAI,KAAK,CAAC,oBAAoB,IAAI,EAAE,CAAC,CAAC;AAC9C,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { IR } from "./core/ir.js";
|
|
2
|
+
export declare function snapshotPath(dir: string, name?: string): string;
|
|
3
|
+
export declare function loadSnapshot(dir: string): IR | null;
|
|
4
|
+
export declare function saveSnapshot(dir: string, ir: IR, fileName?: string): string;
|
|
5
|
+
export declare function nextMigrationNumber(dir: string): number;
|
|
6
|
+
//# sourceMappingURL=snapshot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot.d.ts","sourceRoot":"","sources":["../src/snapshot.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,cAAc,CAAC;AAEvC,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,SAAgB,GAAG,MAAM,CAEtE;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,EAAE,GAAG,IAAI,CAKnD;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,QAAQ,SAAgB,GAAG,MAAM,CAMlF;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAMvD"}
|
package/dist/snapshot.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { mkdirSync, readFileSync, writeFileSync, existsSync, readdirSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
export function snapshotPath(dir, name = "latest.json") {
|
|
4
|
+
return path.join(dir, "meta", name);
|
|
5
|
+
}
|
|
6
|
+
export function loadSnapshot(dir) {
|
|
7
|
+
const p = snapshotPath(dir, "latest.json");
|
|
8
|
+
if (!existsSync(p))
|
|
9
|
+
return null;
|
|
10
|
+
const raw = readFileSync(p, "utf8");
|
|
11
|
+
return JSON.parse(raw);
|
|
12
|
+
}
|
|
13
|
+
export function saveSnapshot(dir, ir, fileName = "latest.json") {
|
|
14
|
+
const metaDir = path.join(dir, "meta");
|
|
15
|
+
mkdirSync(metaDir, { recursive: true });
|
|
16
|
+
const p = path.join(metaDir, fileName);
|
|
17
|
+
writeFileSync(p, JSON.stringify(ir, null, 2) + "\n");
|
|
18
|
+
return p;
|
|
19
|
+
}
|
|
20
|
+
export function nextMigrationNumber(dir) {
|
|
21
|
+
if (!existsSync(dir))
|
|
22
|
+
return 1;
|
|
23
|
+
const files = readdirSync(dir).filter((f) => /^\d{4}_.*\.sql$/.test(f));
|
|
24
|
+
if (files.length === 0)
|
|
25
|
+
return 1;
|
|
26
|
+
const nums = files.map((f) => parseInt(f.slice(0, 4), 10));
|
|
27
|
+
return Math.max(...nums) + 1;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=snapshot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot.js","sourceRoot":"","sources":["../src/snapshot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC1F,OAAO,IAAI,MAAM,WAAW,CAAC;AAG7B,MAAM,UAAU,YAAY,CAAC,GAAW,EAAE,IAAI,GAAG,aAAa;IAC5D,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;AACtC,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,GAAW;IACtC,MAAM,CAAC,GAAG,YAAY,CAAC,GAAG,EAAE,aAAa,CAAC,CAAC;IAC3C,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;QAAE,OAAO,IAAI,CAAC;IAChC,MAAM,GAAG,GAAG,YAAY,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;IACpC,OAAO,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
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Development-time-only tool for designing database schemas in TypeScript and converting them to SQL.",
|
|
6
5
|
"type": "module",
|
|
7
|
-
"
|
|
8
|
-
"main": "./dist/index.cjs",
|
|
9
|
-
"module": "./dist/index.js",
|
|
6
|
+
"main": "./dist/index.js",
|
|
10
7
|
"types": "./dist/index.d.ts",
|
|
8
|
+
"bin": {
|
|
9
|
+
"duronto": "./dist/cli/index.js"
|
|
10
|
+
},
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
},
|
|
17
|
-
"require": {
|
|
18
|
-
"types": "./dist/index.d.cts",
|
|
19
|
-
"default": "./dist/index.cjs"
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
"./package.json": "./package.json"
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js"
|
|
15
|
+
}
|
|
23
16
|
},
|
|
24
17
|
"files": [
|
|
25
|
-
"dist"
|
|
26
|
-
"README.md",
|
|
27
|
-
"LICENSE"
|
|
18
|
+
"dist"
|
|
28
19
|
],
|
|
29
|
-
"engines": {
|
|
30
|
-
"node": ">=18"
|
|
31
|
-
},
|
|
32
|
-
"publishConfig": {
|
|
33
|
-
"access": "public"
|
|
34
|
-
},
|
|
35
|
-
"repository": {
|
|
36
|
-
"type": "git",
|
|
37
|
-
"url": "git+https://github.com/you/uni-com-sdk.git"
|
|
38
|
-
},
|
|
39
20
|
"scripts": {
|
|
40
|
-
"build": "
|
|
41
|
-
"
|
|
42
|
-
"
|
|
21
|
+
"build": "tsc -p tsconfig.json",
|
|
22
|
+
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
23
|
+
"test": "vitest run",
|
|
24
|
+
"test:watch": "vitest",
|
|
25
|
+
"lint": "tsc --noEmit -p tsconfig.json",
|
|
26
|
+
"release:check": "npm run typecheck && npm run build && npm test"
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"schema",
|
|
30
|
+
"sql",
|
|
31
|
+
"typescript",
|
|
32
|
+
"dev"
|
|
33
|
+
],
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"jiti": "^2.4.2"
|
|
43
37
|
},
|
|
44
38
|
"devDependencies": {
|
|
45
|
-
"
|
|
46
|
-
"typescript": "
|
|
39
|
+
"@types/node": "^22.0.0",
|
|
40
|
+
"typescript": "^5.6.0",
|
|
41
|
+
"vitest": "^2.1.0"
|
|
47
42
|
}
|
|
48
43
|
}
|
package/dist/index.cjs
DELETED
package/dist/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,SAAS,SAAS,IAAA,EAAc;AAC5B,EAAA,OAAO,SAAS,IAAI,CAAA,CAAA;AACxB","file":"index.cjs","sourcesContent":["function sayHello(name: string) {\r\n return `Hello ${name}`\r\n}\r\n\r\nexport { sayHello }"]}
|
package/dist/index.d.cts
DELETED