@syncular/typegen 0.58.0 → 0.60.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 +96 -43
- package/dist/cli.js +8 -3
- package/dist/emit-dart.d.ts +4 -3
- package/dist/emit-dart.js +40 -100
- package/dist/emit-kotlin.d.ts +4 -4
- package/dist/emit-kotlin.js +41 -99
- package/dist/emit-queries-dart.d.ts +1 -1
- package/dist/emit-queries-dart.js +17 -26
- package/dist/emit-queries-kotlin.d.ts +1 -1
- package/dist/emit-queries-kotlin.js +15 -24
- package/dist/emit-queries-rust.d.ts +1 -1
- package/dist/emit-queries-rust.js +18 -19
- package/dist/emit-queries-swift.d.ts +1 -1
- package/dist/emit-queries-swift.js +22 -26
- package/dist/emit-queries.d.ts +1 -1
- package/dist/emit-queries.js +18 -27
- package/dist/emit-swift.d.ts +4 -4
- package/dist/emit-swift.js +43 -102
- package/dist/emit.d.ts +3 -3
- package/dist/emit.js +37 -113
- package/dist/errors.d.ts +6 -2
- package/dist/errors.js +10 -2
- package/dist/fmt.js +11 -2
- package/dist/generate.d.ts +4 -3
- package/dist/generate.js +61 -73
- package/dist/init.js +5 -6
- package/dist/ir.d.ts +14 -2
- package/dist/ir.js +67 -49
- package/dist/lower.d.ts +0 -7
- package/dist/lower.js +0 -62
- package/dist/lsp.js +6 -1
- package/dist/manifest.d.ts +1 -2
- package/dist/manifest.js +13 -12
- package/dist/migration-lock.d.ts +32 -23
- package/dist/migration-lock.js +115 -92
- package/dist/naming.d.ts +25 -0
- package/dist/naming.js +92 -0
- package/dist/query.d.ts +94 -14
- package/dist/query.js +642 -461
- package/dist/sql.js +18 -3
- package/dist/syql-ast.d.ts +2 -0
- package/dist/syql-ast.js +7 -1
- package/dist/syql-browser.js +7 -6
- package/dist/syql-diagnostics.d.ts +1 -0
- package/dist/syql-diagnostics.js +1 -0
- package/dist/syql-lowering.js +11 -1
- package/dist/syql-parser.d.ts +4 -1
- package/dist/syql-parser.js +42 -5
- package/dist/syql-validator.js +13 -220
- package/package.json +3 -3
- package/src/cli.ts +9 -3
- package/src/emit-dart.ts +44 -116
- package/src/emit-kotlin.ts +41 -118
- package/src/emit-queries-dart.ts +23 -32
- package/src/emit-queries-kotlin.ts +20 -30
- package/src/emit-queries-rust.ts +29 -31
- package/src/emit-queries-swift.ts +26 -32
- package/src/emit-queries.ts +26 -47
- package/src/emit-swift.ts +49 -120
- package/src/emit.ts +45 -135
- package/src/errors.ts +13 -2
- package/src/fmt.ts +10 -2
- package/src/generate.ts +113 -107
- package/src/init.ts +8 -6
- package/src/ir.ts +91 -54
- package/src/lower.ts +0 -53
- package/src/lsp.ts +11 -4
- package/src/manifest.ts +22 -18
- package/src/migration-lock.ts +192 -137
- package/src/naming.ts +154 -0
- package/src/query.ts +864 -502
- package/src/sql.ts +30 -3
- package/src/syql-ast.ts +9 -0
- package/src/syql-browser.ts +8 -7
- package/src/syql-diagnostics.ts +2 -0
- package/src/syql-lowering.ts +16 -1
- package/src/syql-parser.ts +73 -8
- package/src/syql-validator.ts +21 -279
package/dist/ir.js
CHANGED
|
@@ -12,6 +12,14 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import { createHash } from 'node:crypto';
|
|
14
14
|
export const IR_VERSION = 1;
|
|
15
|
+
/** §5.11: the app-side type of a column. An encrypted column rides the wire
|
|
16
|
+
* as `bytes`; generated rows expose its declared type (the local mirror is
|
|
17
|
+
* plaintext). */
|
|
18
|
+
export function appColumnType(column) {
|
|
19
|
+
return column.encrypted === true && column.declaredType !== undefined
|
|
20
|
+
? column.declaredType
|
|
21
|
+
: column.type;
|
|
22
|
+
}
|
|
15
23
|
/** Recursively sort object keys so extension payloads serialize stably. */
|
|
16
24
|
export function canonicalizeExtensions(value) {
|
|
17
25
|
if (Array.isArray(value))
|
|
@@ -31,6 +39,47 @@ function canonicalScopeValue(value) {
|
|
|
31
39
|
? { kind: 'literal', value: value.value }
|
|
32
40
|
: { kind: 'parameter', name: value.name };
|
|
33
41
|
}
|
|
42
|
+
/** Column, reference, and index entries shared by the IR document and the
|
|
43
|
+
* schema object, in their fixed key order. Optional members (crdtType,
|
|
44
|
+
* encrypted/declaredType, references, indexes, ftsIndexes) are emitted only
|
|
45
|
+
* when present so documents without them stay byte-identical. */
|
|
46
|
+
function serializeTableShape(table, scopes) {
|
|
47
|
+
return {
|
|
48
|
+
name: table.name,
|
|
49
|
+
primaryKey: table.primaryKey,
|
|
50
|
+
columns: table.columns.map((column) => ({
|
|
51
|
+
name: column.name,
|
|
52
|
+
type: column.type,
|
|
53
|
+
nullable: column.nullable,
|
|
54
|
+
...(column.crdtType !== undefined ? { crdtType: column.crdtType } : {}),
|
|
55
|
+
...(column.encrypted === true
|
|
56
|
+
? { encrypted: true, declaredType: column.declaredType }
|
|
57
|
+
: {}),
|
|
58
|
+
})),
|
|
59
|
+
scopes,
|
|
60
|
+
...(table.references.length > 0
|
|
61
|
+
? { references: table.references.map((reference) => ({ ...reference })) }
|
|
62
|
+
: {}),
|
|
63
|
+
...(table.indexes.length > 0
|
|
64
|
+
? {
|
|
65
|
+
indexes: table.indexes.map((index) => ({
|
|
66
|
+
name: index.name,
|
|
67
|
+
columns: index.columns,
|
|
68
|
+
unique: index.unique,
|
|
69
|
+
})),
|
|
70
|
+
}
|
|
71
|
+
: {}),
|
|
72
|
+
...(table.ftsIndexes.length > 0
|
|
73
|
+
? {
|
|
74
|
+
ftsIndexes: table.ftsIndexes.map((index) => ({
|
|
75
|
+
name: index.name,
|
|
76
|
+
columns: index.columns,
|
|
77
|
+
tokenize: index.tokenize,
|
|
78
|
+
})),
|
|
79
|
+
}
|
|
80
|
+
: {}),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
34
83
|
/** Serialize with a fixed key order — byte-deterministic for equal IRs. */
|
|
35
84
|
export function serializeIr(ir) {
|
|
36
85
|
const doc = {
|
|
@@ -41,70 +90,39 @@ export function serializeIr(ir) {
|
|
|
41
90
|
migrations: v.migrations,
|
|
42
91
|
})),
|
|
43
92
|
tables: ir.tables.map((table) => ({
|
|
44
|
-
|
|
45
|
-
primaryKey: table.primaryKey,
|
|
46
|
-
columns: table.columns.map((column) => ({
|
|
47
|
-
name: column.name,
|
|
48
|
-
type: column.type,
|
|
49
|
-
nullable: column.nullable,
|
|
50
|
-
// §5.10.1: crdtType is IR metadata (never on the wire); emitted only
|
|
51
|
-
// for crdt columns so non-crdt column diffs stay byte-identical.
|
|
52
|
-
...(column.crdtType !== undefined ? { crdtType: column.crdtType } : {}),
|
|
53
|
-
// §5.11: encrypted/declaredType are IR metadata (never on the wire);
|
|
54
|
-
// emitted only for encrypted columns so non-encrypted diffs stay
|
|
55
|
-
// byte-identical.
|
|
56
|
-
...(column.encrypted === true
|
|
57
|
-
? { encrypted: true, declaredType: column.declaredType }
|
|
58
|
-
: {}),
|
|
59
|
-
})),
|
|
60
|
-
scopes: table.scopes.map((scope) => ({
|
|
93
|
+
...serializeTableShape(table, table.scopes.map((scope) => ({
|
|
61
94
|
pattern: scope.pattern,
|
|
62
95
|
variable: scope.variable,
|
|
63
96
|
column: scope.column,
|
|
64
|
-
})),
|
|
65
|
-
// Declared references (§6.11) are additive under irVersion 1: emitted
|
|
66
|
-
// only when the table declares at least one, so reference-free tables
|
|
67
|
-
// stay byte-identical.
|
|
68
|
-
...(table.references.length > 0
|
|
69
|
-
? {
|
|
70
|
-
references: table.references.map((reference) => ({ ...reference })),
|
|
71
|
-
}
|
|
72
|
-
: {}),
|
|
73
|
-
// Indexes are additive under irVersion 1: emitted only when the table
|
|
74
|
-
// declares at least one, so index-free tables (every pre-index manifest)
|
|
75
|
-
// stay byte-identical and --check fresh. Declaration order preserved.
|
|
76
|
-
...(table.indexes.length > 0
|
|
77
|
-
? {
|
|
78
|
-
indexes: table.indexes.map((index) => ({
|
|
79
|
-
name: index.name,
|
|
80
|
-
columns: index.columns,
|
|
81
|
-
unique: index.unique,
|
|
82
|
-
})),
|
|
83
|
-
}
|
|
84
|
-
: {}),
|
|
85
|
-
...(table.ftsIndexes.length > 0
|
|
86
|
-
? {
|
|
87
|
-
ftsIndexes: table.ftsIndexes.map((index) => ({
|
|
88
|
-
name: index.name,
|
|
89
|
-
columns: index.columns,
|
|
90
|
-
tokenize: index.tokenize,
|
|
91
|
-
})),
|
|
92
|
-
}
|
|
93
|
-
: {}),
|
|
97
|
+
}))),
|
|
94
98
|
extensions: canonicalizeExtensions(table.extensions),
|
|
95
99
|
})),
|
|
96
100
|
subscriptions: ir.subscriptions.map((sub) => ({
|
|
97
101
|
name: sub.name,
|
|
98
|
-
table: sub.table,
|
|
99
102
|
scopes: sub.scopes.map((scope) => ({
|
|
100
103
|
variable: scope.variable,
|
|
101
|
-
|
|
104
|
+
value: canonicalScopeValue(scope.value),
|
|
102
105
|
})),
|
|
103
106
|
})),
|
|
104
107
|
extensions: canonicalizeExtensions(ir.extensions),
|
|
105
108
|
};
|
|
106
109
|
return `${JSON.stringify(doc, null, 2)}\n`;
|
|
107
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* The ServerSchema-compatible schema object (§2.4, §3.1) as 2-space JSON.
|
|
113
|
+
* Every emitter embeds these exact bytes: TS as an object literal, Swift,
|
|
114
|
+
* Kotlin, and Dart as a string literal they parse, so every platform hands
|
|
115
|
+
* its client the same tables, scopes, references, and indexes.
|
|
116
|
+
*/
|
|
117
|
+
export function serializeSchema(ir) {
|
|
118
|
+
return JSON.stringify({
|
|
119
|
+
version: ir.schemaVersion,
|
|
120
|
+
tables: ir.tables.map((table) => serializeTableShape(table, table.scopes.map((scope) => ({
|
|
121
|
+
pattern: scope.pattern,
|
|
122
|
+
column: scope.column,
|
|
123
|
+
})))),
|
|
124
|
+
}, null, 2);
|
|
125
|
+
}
|
|
108
126
|
/** Hash of the exact IR file bytes; stamped into generated modules. */
|
|
109
127
|
export function irHash(irJson) {
|
|
110
128
|
return `sha256:${createHash('sha256').update(irJson, 'utf8').digest('hex')}`;
|
package/dist/lower.d.ts
CHANGED
|
@@ -19,13 +19,6 @@ interface ProjectionSpan {
|
|
|
19
19
|
* when there is no depth-0 SELECT…FROM shape (e.g. `SELECT 1`).
|
|
20
20
|
*/
|
|
21
21
|
export declare function findProjection(sql: string): ProjectionSpan | null;
|
|
22
|
-
/**
|
|
23
|
-
* The main verb of a `WITH …` statement (uppercased): SQLite allows a
|
|
24
|
-
* with-clause before SELECT and before INSERT/UPDATE/DELETE. CTE bodies live
|
|
25
|
-
* inside parentheses and a bare keyword cannot be a CTE name, so the first
|
|
26
|
-
* paren-depth-0 keyword after `WITH` is the main verb.
|
|
27
|
-
*/
|
|
28
|
-
export declare function mainVerbAfterWith(sql: string): string | undefined;
|
|
29
22
|
/** A `FROM`/`JOIN` base-table reference the caller already resolved. */
|
|
30
23
|
export interface LowerTableRef {
|
|
31
24
|
readonly table: string;
|
package/dist/lower.js
CHANGED
|
@@ -115,68 +115,6 @@ export function findProjection(sql) {
|
|
|
115
115
|
}
|
|
116
116
|
return null;
|
|
117
117
|
}
|
|
118
|
-
/**
|
|
119
|
-
* The main verb of a `WITH …` statement (uppercased): SQLite allows a
|
|
120
|
-
* with-clause before SELECT and before INSERT/UPDATE/DELETE. CTE bodies live
|
|
121
|
-
* inside parentheses and a bare keyword cannot be a CTE name, so the first
|
|
122
|
-
* paren-depth-0 keyword after `WITH` is the main verb.
|
|
123
|
-
*/
|
|
124
|
-
export function mainVerbAfterWith(sql) {
|
|
125
|
-
const MAIN_VERBS = new Set([
|
|
126
|
-
'SELECT',
|
|
127
|
-
'VALUES',
|
|
128
|
-
'INSERT',
|
|
129
|
-
'UPDATE',
|
|
130
|
-
'DELETE',
|
|
131
|
-
'REPLACE',
|
|
132
|
-
]);
|
|
133
|
-
let depth = 0;
|
|
134
|
-
let i = 0;
|
|
135
|
-
let sawWith = false;
|
|
136
|
-
while (i < sql.length) {
|
|
137
|
-
const ch = sql[i];
|
|
138
|
-
const next = sql[i + 1];
|
|
139
|
-
if (ch === '-' && next === '-') {
|
|
140
|
-
const end = sql.indexOf('\n', i);
|
|
141
|
-
i = end === -1 ? sql.length : end + 1;
|
|
142
|
-
}
|
|
143
|
-
else if (ch === '/' && next === '*') {
|
|
144
|
-
const end = sql.indexOf('*/', i + 2);
|
|
145
|
-
i = end === -1 ? sql.length : end + 2;
|
|
146
|
-
}
|
|
147
|
-
else if (ch === "'" || ch === '"' || ch === '`') {
|
|
148
|
-
let j = i + 1;
|
|
149
|
-
while (j < sql.length && sql[j] !== ch)
|
|
150
|
-
j += 1;
|
|
151
|
-
i = j + 1;
|
|
152
|
-
}
|
|
153
|
-
else if (ch === '(') {
|
|
154
|
-
depth += 1;
|
|
155
|
-
i += 1;
|
|
156
|
-
}
|
|
157
|
-
else if (ch === ')') {
|
|
158
|
-
depth -= 1;
|
|
159
|
-
i += 1;
|
|
160
|
-
}
|
|
161
|
-
else if (WORD_RE.test(ch)) {
|
|
162
|
-
let j = i + 1;
|
|
163
|
-
while (j < sql.length && /[A-Za-z0-9_]/.test(sql[j]))
|
|
164
|
-
j += 1;
|
|
165
|
-
const word = sql.slice(i, j).toUpperCase();
|
|
166
|
-
if (depth === 0) {
|
|
167
|
-
if (!sawWith && word === 'WITH')
|
|
168
|
-
sawWith = true;
|
|
169
|
-
else if (sawWith && MAIN_VERBS.has(word))
|
|
170
|
-
return word;
|
|
171
|
-
}
|
|
172
|
-
i = j;
|
|
173
|
-
}
|
|
174
|
-
else {
|
|
175
|
-
i += 1;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
return undefined;
|
|
179
|
-
}
|
|
180
118
|
const IDENT = '[A-Za-z_][A-Za-z0-9_]*';
|
|
181
119
|
const EXPLICIT_ALIAS_RE = new RegExp(`^([\\s\\S]*?)\\s+AS\\s+(${IDENT})$`, 'i');
|
|
182
120
|
const TRAILING_IDENT_RE = new RegExp(`^([\\s\\S]*?)\\s+(${IDENT})$`);
|
package/dist/lsp.js
CHANGED
|
@@ -7,6 +7,7 @@ import { formatSyql } from './fmt.js';
|
|
|
7
7
|
import { buildIr, loadMigrations, loadQueries, makeQueryDb } from './generate.js';
|
|
8
8
|
import { MANIFEST_FILENAME, parseManifest } from './manifest.js';
|
|
9
9
|
import { lockedMigrationNames, readMigrationLock } from './migration-lock.js';
|
|
10
|
+
import { checkQueryPlan } from './query.js';
|
|
10
11
|
import { syqlDiagnosticRemedy } from './syql-diagnostics.js';
|
|
11
12
|
import { SyqlFrontendError } from './syql-lexer.js';
|
|
12
13
|
import { lowerSyqlQuery } from './syql-lowering.js';
|
|
@@ -271,7 +272,11 @@ export class SyqlLanguageServer {
|
|
|
271
272
|
throw new TypegenError(file, 'current SYQL module missing');
|
|
272
273
|
const lowered = project === undefined
|
|
273
274
|
? []
|
|
274
|
-
: validateSyqlProgram(semantic, project.ir, project.db, project.naming).queries.map((query) =>
|
|
275
|
+
: validateSyqlProgram(semantic, project.ir, project.db, project.naming).queries.map((query) => {
|
|
276
|
+
const result = lowerSyqlQuery(query, project.ir, project.db, project.naming);
|
|
277
|
+
checkQueryPlan(result.analysis, project.ir, project.db);
|
|
278
|
+
return result;
|
|
279
|
+
});
|
|
275
280
|
return { root, file, module, semantic, lowered };
|
|
276
281
|
}
|
|
277
282
|
#publishDiagnostics(uri) {
|
package/dist/manifest.d.ts
CHANGED
|
@@ -22,8 +22,7 @@ export interface ManifestTable {
|
|
|
22
22
|
}
|
|
23
23
|
export interface ManifestSubscription {
|
|
24
24
|
readonly name: string;
|
|
25
|
-
readonly
|
|
26
|
-
readonly scopes: Readonly<Record<string, readonly string[]>>;
|
|
25
|
+
readonly scopes: Readonly<Record<string, string>>;
|
|
27
26
|
}
|
|
28
27
|
export interface ManifestSchemaVersion {
|
|
29
28
|
readonly version: number;
|
package/dist/manifest.js
CHANGED
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
* "dart": "./lib/syncular.generated.dart" },
|
|
15
15
|
* "schemaVersions": [{ "version": 1, "through": "0001_initial" }],
|
|
16
16
|
* "tables": [{ "name": "tasks", "scopes": ["project:{project_id}"] }],
|
|
17
|
-
* "subscriptions": [{ "name": "projectTasks",
|
|
18
|
-
* "scopes": { "project_id":
|
|
17
|
+
* "subscriptions": [{ "name": "projectTasks",
|
|
18
|
+
* "scopes": { "project_id": "{projectId}" } }],
|
|
19
19
|
* "extensions": {}
|
|
20
20
|
* }
|
|
21
21
|
* ```
|
|
@@ -24,8 +24,10 @@
|
|
|
24
24
|
* - `schemaVersions` is the §1.5 version history: strictly increasing
|
|
25
25
|
* versions, each naming the last migration it includes (`through`); the
|
|
26
26
|
* final entry must cover the final migration.
|
|
27
|
-
* -
|
|
28
|
-
*
|
|
27
|
+
* - A subscription is a unit template (SPEC §4.1): one literal or
|
|
28
|
+
* whole-value `{param}` placeholder per scope variable (partial templates
|
|
29
|
+
* are unsupported), no table. The unit covers every table declaring all of
|
|
30
|
+
* its variables; a template that covers no table is an error.
|
|
29
31
|
* - `output.ir` / `output.module` are the always-emitted TS defaults;
|
|
30
32
|
* `output.queryIr` opts into the deterministic analyzed-query document.
|
|
31
33
|
* `output.swift` / `output.kotlin` / `output.dart` are OPT-IN native schema
|
|
@@ -187,24 +189,23 @@ const IDENTIFIER_RE = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
|
|
|
187
189
|
function parseSubscription(value, index) {
|
|
188
190
|
const context = `subscriptions[${index}]`;
|
|
189
191
|
const obj = asObject(value, context);
|
|
190
|
-
rejectUnknownKeys(obj, ['name', 'table', 'scopes'], context);
|
|
191
192
|
const name = asString(obj.name, `${context}.name`);
|
|
192
193
|
if (!IDENTIFIER_RE.test(name)) {
|
|
193
194
|
fail(`subscription ${JSON.stringify(name)}: name must be a valid identifier`);
|
|
194
195
|
}
|
|
195
|
-
const table = asString(obj.table, `subscription ${name}: table`);
|
|
196
196
|
const scopesObj = asObject(obj.scopes, `subscription ${name}: scopes`);
|
|
197
|
+
if ('table' in obj || Object.values(scopesObj).some(Array.isArray)) {
|
|
198
|
+
throw new TypegenError(SOURCE, 'a subscription is a unit template { "name", "scopes": { "<variable>": "<value or {param}>" } } with one value per scope variable and no table (SPEC §4.1); several values are several templates', 'typegen.subscription_legacy_shape', { subscription: name });
|
|
199
|
+
}
|
|
200
|
+
rejectUnknownKeys(obj, ['name', 'scopes'], context);
|
|
197
201
|
const scopes = {};
|
|
198
|
-
for (const [variable,
|
|
199
|
-
|
|
200
|
-
fail(`subscription ${name}: scopes.${variable} must be a non-empty array`);
|
|
201
|
-
}
|
|
202
|
-
scopes[variable] = values.map((v, i) => asString(v, `subscription ${name}: scopes.${variable}[${i}]`));
|
|
202
|
+
for (const [variable, scope] of Object.entries(scopesObj)) {
|
|
203
|
+
scopes[variable] = asString(scope, `subscription ${name}: scopes.${variable}`);
|
|
203
204
|
}
|
|
204
205
|
if (Object.keys(scopes).length === 0) {
|
|
205
206
|
fail(`subscription ${name}: scopes must not be empty`);
|
|
206
207
|
}
|
|
207
|
-
return { name,
|
|
208
|
+
return { name, scopes };
|
|
208
209
|
}
|
|
209
210
|
function parseSchemaVersion(value, index) {
|
|
210
211
|
const context = `schemaVersions[${index}]`;
|
package/dist/migration-lock.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { MigrationInput } from './generate.js';
|
|
2
|
-
import type { IrColumnType } from './ir.js';
|
|
2
|
+
import type { IrColumnType, IrSchemaVersion } from './ir.js';
|
|
3
|
+
import { type ManifestSchemaVersion } from './manifest.js';
|
|
3
4
|
export declare const MIGRATION_LOCK_FILENAME = "syncular.migrations.lock.json";
|
|
4
|
-
export declare const MIGRATION_LOCK_FORMAT_VERSION =
|
|
5
|
-
export declare const LEGACY_MIGRATION_LOCK_FORMAT_VERSION = 1;
|
|
5
|
+
export declare const MIGRATION_LOCK_FORMAT_VERSION = 3;
|
|
6
6
|
export interface MigrationLockColumn {
|
|
7
7
|
readonly name: string;
|
|
8
8
|
readonly type: IrColumnType;
|
|
@@ -17,37 +17,46 @@ export interface MigrationLockTable {
|
|
|
17
17
|
export interface MigrationLockEntry {
|
|
18
18
|
readonly name: string;
|
|
19
19
|
readonly sha256: string;
|
|
20
|
+
/** The schema version this migration belongs to (§1.5, §7.4). */
|
|
21
|
+
readonly schemaVersion: number;
|
|
20
22
|
}
|
|
21
|
-
export interface
|
|
22
|
-
readonly tables: readonly MigrationLockTable[];
|
|
23
|
-
}
|
|
24
|
-
export interface LegacyMigrationLock {
|
|
25
|
-
readonly formatVersion: typeof LEGACY_MIGRATION_LOCK_FORMAT_VERSION;
|
|
26
|
-
readonly migrations: readonly LegacyMigrationLockEntry[];
|
|
27
|
-
}
|
|
28
|
-
export interface MigrationLockV2 {
|
|
23
|
+
export interface MigrationLock {
|
|
29
24
|
readonly formatVersion: typeof MIGRATION_LOCK_FORMAT_VERSION;
|
|
30
25
|
readonly migrations: readonly MigrationLockEntry[];
|
|
31
26
|
readonly head: {
|
|
32
27
|
readonly tables: readonly MigrationLockTable[];
|
|
33
28
|
};
|
|
34
29
|
}
|
|
35
|
-
|
|
30
|
+
/** A format-1 or format-2 lock: names and checksums without schema versions,
|
|
31
|
+
* read only to upgrade it to the current format. */
|
|
32
|
+
export interface LegacyMigrationLock {
|
|
33
|
+
readonly formatVersion: 1 | 2;
|
|
34
|
+
readonly migrations: readonly Omit<MigrationLockEntry, 'schemaVersion'>[];
|
|
35
|
+
}
|
|
36
36
|
/** The names of every migration a committed lock has made immutable. */
|
|
37
|
-
export declare function lockedMigrationNames(lock: MigrationLock): ReadonlySet<string>;
|
|
38
|
-
/**
|
|
39
|
-
|
|
37
|
+
export declare function lockedMigrationNames(lock: MigrationLock | LegacyMigrationLock): ReadonlySet<string>;
|
|
38
|
+
/** Resolve the manifest's `schemaVersions` (each naming the last migration
|
|
39
|
+
* it includes) into the migrations every version adds (§1.5). */
|
|
40
|
+
export declare function buildSchemaVersions(declared: readonly ManifestSchemaVersion[], migrations: readonly MigrationInput[]): IrSchemaVersion[];
|
|
41
|
+
/** Build a deterministic lock document for a complete migration sequence;
|
|
42
|
+
* `declared` is the manifest's `schemaVersions`. */
|
|
43
|
+
export declare function buildMigrationLock(migrations: readonly MigrationInput[], declared: readonly ManifestSchemaVersion[]): MigrationLock;
|
|
40
44
|
/** Fixed-order, byte-deterministic serialization for clean code review. */
|
|
41
45
|
export declare function serializeMigrationLock(lock: MigrationLock): string;
|
|
42
46
|
/** Parse and structurally validate a committed lock document. */
|
|
43
|
-
export declare function parseMigrationLock(source: string): MigrationLock;
|
|
47
|
+
export declare function parseMigrationLock(source: string): MigrationLock | LegacyMigrationLock;
|
|
44
48
|
/** Read the version-controlled baseline without exposing its absolute path. */
|
|
45
|
-
export declare function readMigrationLock(manifestDir: string): MigrationLock;
|
|
49
|
+
export declare function readMigrationLock(manifestDir: string): MigrationLock | LegacyMigrationLock;
|
|
50
|
+
/**
|
|
51
|
+
* Validate a committed lock against the migration inputs and their schema
|
|
52
|
+
* versions, and build its exact next document. A locked migration keeps its
|
|
53
|
+
* schema version; an appended migration belongs to a version above the
|
|
54
|
+
* highest locked one, because a deployed version never changes (§7.4).
|
|
55
|
+
*/
|
|
56
|
+
export declare function updateMigrationLock(locked: MigrationLock | LegacyMigrationLock, migrations: readonly MigrationInput[], declared: readonly ManifestSchemaVersion[]): MigrationLock;
|
|
46
57
|
/**
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
58
|
+
* Convert a format-1 or format-2 lock to the current format: validate its
|
|
59
|
+
* locked prefix and record the schema version the manifest's `declared`
|
|
60
|
+
* versions assign each locked migration. Appended migrations stay unlocked for generation.
|
|
50
61
|
*/
|
|
51
|
-
export declare function
|
|
52
|
-
/** Validate without changing the committed lock format. */
|
|
53
|
-
export declare function validateMigrationLock(locked: MigrationLock, migrations: readonly MigrationInput[]): void;
|
|
62
|
+
export declare function upgradeMigrationLock(locked: LegacyMigrationLock, migrations: readonly MigrationInput[], declared: readonly ManifestSchemaVersion[]): MigrationLock;
|