@opencloudcms/codegen 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +4 -2
- package/dist/blocks.d.ts +58 -0
- package/dist/blocks.js +408 -0
- package/dist/blocks.js.map +1 -0
- package/dist/codegen.d.ts +10 -0
- package/dist/codegen.js +236 -0
- package/dist/codegen.js.map +1 -0
- package/dist/ddl.d.ts +67 -0
- package/dist/ddl.js +185 -0
- package/dist/ddl.js.map +1 -0
- package/dist/diff.d.ts +52 -0
- package/dist/diff.js +158 -0
- package/dist/diff.js.map +1 -0
- package/dist/eject.d.ts +20 -0
- package/dist/eject.js +773 -0
- package/dist/eject.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/loader.d.ts +17 -0
- package/dist/loader.js +134 -0
- package/dist/loader.js.map +1 -0
- package/dist/migration-file.d.ts +9 -0
- package/dist/migration-file.js +52 -0
- package/dist/migration-file.js.map +1 -0
- package/dist/pipeline.d.ts +78 -0
- package/dist/pipeline.js +227 -0
- package/dist/pipeline.js.map +1 -0
- package/dist/plan.d.ts +11 -0
- package/dist/plan.js +217 -0
- package/dist/plan.js.map +1 -0
- package/dist/printer.d.ts +11 -0
- package/dist/printer.js +127 -0
- package/dist/printer.js.map +1 -0
- package/dist/snapshot.d.ts +11 -0
- package/dist/snapshot.js +60 -0
- package/dist/snapshot.js.map +1 -0
- package/package.json +33 -3
package/dist/codegen.js
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.pascal = void 0;
|
|
37
|
+
exports.generateCode = generateCode;
|
|
38
|
+
exports.writeGeneratedFiles = writeGeneratedFiles;
|
|
39
|
+
exports.staleGeneratedFiles = staleGeneratedFiles;
|
|
40
|
+
/**
|
|
41
|
+
* Code generator: writes `src/generated/*` from content type definitions.
|
|
42
|
+
* Everything in that folder is overwritten on each run; custom code lives in `src/extensions`.
|
|
43
|
+
*/
|
|
44
|
+
const fs = __importStar(require("node:fs"));
|
|
45
|
+
const path = __importStar(require("node:path"));
|
|
46
|
+
const schema_1 = require("@opencloudcms/schema");
|
|
47
|
+
const HEADER = `// ------------------------------------------------------------------
|
|
48
|
+
// Generated by opencloudcms. DO NOT EDIT: changes are overwritten.
|
|
49
|
+
// Edit src/content-types/**/*.schema.ts and run \`opencloudcms generate\`.
|
|
50
|
+
// ------------------------------------------------------------------
|
|
51
|
+
`;
|
|
52
|
+
const pascal = (s) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
53
|
+
exports.pascal = pascal;
|
|
54
|
+
function tsFieldType(field) {
|
|
55
|
+
switch (field.kind) {
|
|
56
|
+
case 'number':
|
|
57
|
+
return 'number';
|
|
58
|
+
case 'boolean':
|
|
59
|
+
return 'boolean';
|
|
60
|
+
case 'richText':
|
|
61
|
+
return 'RichTextDocument';
|
|
62
|
+
case 'json':
|
|
63
|
+
return 'unknown';
|
|
64
|
+
case 'money':
|
|
65
|
+
return 'Money';
|
|
66
|
+
case 'asset':
|
|
67
|
+
case 'reference':
|
|
68
|
+
case 'taxonomy':
|
|
69
|
+
return (0, schema_1.isMultiRelation)(field) ? 'string[]' : 'string';
|
|
70
|
+
default:
|
|
71
|
+
return 'string';
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function fieldDoc(field) {
|
|
75
|
+
const bits = [field.kind];
|
|
76
|
+
if (field.required)
|
|
77
|
+
bits.push('required');
|
|
78
|
+
if (field.localizable)
|
|
79
|
+
bits.push('localizable');
|
|
80
|
+
if (field.unique)
|
|
81
|
+
bits.push('unique');
|
|
82
|
+
else if (field.indexed)
|
|
83
|
+
bits.push('indexed');
|
|
84
|
+
const o = field.options;
|
|
85
|
+
if (o.target)
|
|
86
|
+
bits.push(`-> ${o.target}`);
|
|
87
|
+
const label = field.label ? `${field.label}. ` : '';
|
|
88
|
+
return ` /** ${label}${bits.join(', ')} */`;
|
|
89
|
+
}
|
|
90
|
+
function renderTypes(defs) {
|
|
91
|
+
const out = [
|
|
92
|
+
HEADER,
|
|
93
|
+
'export type RichTextDocument = Record<string, unknown> | unknown[];',
|
|
94
|
+
'export interface Money { amount: number; currency: string }',
|
|
95
|
+
'',
|
|
96
|
+
'export interface EntryMeta {',
|
|
97
|
+
' documentId: string;',
|
|
98
|
+
" status: 'draft' | 'published';",
|
|
99
|
+
' locale: string | null;',
|
|
100
|
+
' createdAt: string;',
|
|
101
|
+
' updatedAt: string;',
|
|
102
|
+
' publishedAt: string | null;',
|
|
103
|
+
'}',
|
|
104
|
+
'',
|
|
105
|
+
];
|
|
106
|
+
for (const def of defs) {
|
|
107
|
+
const name = (0, exports.pascal)(def.apiId);
|
|
108
|
+
out.push(`/** ${(0, schema_1.localizedText)(def.displayName, 'en-US', def.apiId)} (${def.apiId}) */`);
|
|
109
|
+
out.push(`export interface ${name} extends EntryMeta {`);
|
|
110
|
+
for (const field of def.fields) {
|
|
111
|
+
out.push(fieldDoc(field));
|
|
112
|
+
const t = tsFieldType(field);
|
|
113
|
+
out.push((0, schema_1.isMultiRelation)(field) ? ` ${field.name}: ${t};` : ` ${field.name}: ${t} | null;`);
|
|
114
|
+
}
|
|
115
|
+
out.push('}', '');
|
|
116
|
+
out.push(`export interface ${name}Input {`);
|
|
117
|
+
for (const field of def.fields)
|
|
118
|
+
out.push(` ${field.name}?: ${tsFieldType(field)} | null;`);
|
|
119
|
+
out.push('}', '');
|
|
120
|
+
}
|
|
121
|
+
out.push('export interface ContentTypeMap {');
|
|
122
|
+
for (const def of defs)
|
|
123
|
+
out.push(` ${def.apiId}: ${(0, exports.pascal)(def.apiId)};`);
|
|
124
|
+
out.push('}', '');
|
|
125
|
+
out.push('export interface ContentTypeInputMap {');
|
|
126
|
+
for (const def of defs)
|
|
127
|
+
out.push(` ${def.apiId}: ${(0, exports.pascal)(def.apiId)}Input;`);
|
|
128
|
+
out.push('}', '');
|
|
129
|
+
return out.join('\n');
|
|
130
|
+
}
|
|
131
|
+
function pgToTs(col) {
|
|
132
|
+
const t = col.type;
|
|
133
|
+
let ts = 'string';
|
|
134
|
+
if (t === 'integer')
|
|
135
|
+
ts = 'number';
|
|
136
|
+
else if (t === 'boolean')
|
|
137
|
+
ts = 'boolean';
|
|
138
|
+
else if (t === 'timestamptz' || t === 'date')
|
|
139
|
+
ts = 'Date';
|
|
140
|
+
else if (t === 'jsonb')
|
|
141
|
+
ts = 'unknown';
|
|
142
|
+
else if (t.startsWith('numeric'))
|
|
143
|
+
ts = 'string';
|
|
144
|
+
return col.notNull ? ts : `${ts} | null`;
|
|
145
|
+
}
|
|
146
|
+
function tableInterface(name, columns) {
|
|
147
|
+
return [`export interface ${name} {`, ...columns.map((c) => ` ${c.name}: ${pgToTs(c)};`), '}', ''].join('\n');
|
|
148
|
+
}
|
|
149
|
+
function renderTables(defs) {
|
|
150
|
+
const out = [HEADER, '/** Kysely table types for the generated ct_* tables. */', ''];
|
|
151
|
+
const dbEntries = [];
|
|
152
|
+
for (const def of defs) {
|
|
153
|
+
const base = (0, exports.pascal)(def.apiId);
|
|
154
|
+
const mainCols = [...(0, schema_1.mainBaseColumns)()];
|
|
155
|
+
const l10nCols = [...(0, schema_1.l10nBaseColumns)(def)];
|
|
156
|
+
for (const field of def.fields) {
|
|
157
|
+
const s = (0, schema_1.fieldStorage)(def, field);
|
|
158
|
+
if (s.mode === 'columns')
|
|
159
|
+
(s.location === 'main' ? mainCols : l10nCols).push(...s.columns);
|
|
160
|
+
else {
|
|
161
|
+
const iface = `${base}${(0, exports.pascal)(field.name)}RelTable`;
|
|
162
|
+
out.push(tableInterface(iface, (0, schema_1.relBaseColumns)(def, field)));
|
|
163
|
+
dbEntries.push(` ${s.table}: ${iface};`);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
out.push(tableInterface(`${base}Table`, mainCols));
|
|
167
|
+
out.push(tableInterface(`${base}L10nTable`, l10nCols));
|
|
168
|
+
dbEntries.unshift(` ${(0, schema_1.mainTable)(def)}: ${base}Table;`, ` ${(0, schema_1.l10nTable)(def)}: ${base}L10nTable;`);
|
|
169
|
+
}
|
|
170
|
+
out.push('export interface ContentDatabase {', ...dbEntries, '}', '');
|
|
171
|
+
return out.join('\n');
|
|
172
|
+
}
|
|
173
|
+
function renderRegistry(defs) {
|
|
174
|
+
const out = [HEADER, "import type { ContentTypeDefinition } from '@opencloudcms/schema';", ''];
|
|
175
|
+
for (const def of defs) {
|
|
176
|
+
out.push(`export const ${def.apiId}Definition: ContentTypeDefinition = ${JSON.stringify(def, null, 2)};`, '');
|
|
177
|
+
}
|
|
178
|
+
out.push(`export const contentTypes: ContentTypeDefinition[] = [${defs.map((d) => `${d.apiId}Definition`).join(', ')}];`, '');
|
|
179
|
+
return out.join('\n');
|
|
180
|
+
}
|
|
181
|
+
function renderValidators(defs) {
|
|
182
|
+
const out = [
|
|
183
|
+
HEADER,
|
|
184
|
+
"import { buildEntryValidator } from '@opencloudcms/schema';",
|
|
185
|
+
`import { ${defs.map((d) => `${d.apiId}Definition`).join(', ')} } from './registry';`,
|
|
186
|
+
'',
|
|
187
|
+
];
|
|
188
|
+
if (!defs.length)
|
|
189
|
+
out.splice(2, 1);
|
|
190
|
+
for (const def of defs) {
|
|
191
|
+
out.push(`export const ${def.apiId}DraftSchema = buildEntryValidator(${def.apiId}Definition, 'draft');`);
|
|
192
|
+
out.push(`export const ${def.apiId}PublishSchema = buildEntryValidator(${def.apiId}Definition, 'publish');`);
|
|
193
|
+
}
|
|
194
|
+
out.push('');
|
|
195
|
+
return out.join('\n');
|
|
196
|
+
}
|
|
197
|
+
function renderClient(defs) {
|
|
198
|
+
const pub = defs.filter((d) => !d.private);
|
|
199
|
+
const names = pub.map((d) => (0, exports.pascal)(d.apiId));
|
|
200
|
+
const imp = names.length ? `import type { ${names.join(', ')} } from './types';\n` : '';
|
|
201
|
+
const map = pub.map((d) => `${d.apiId}: ${(0, exports.pascal)(d.apiId)}`).join('; ');
|
|
202
|
+
return `${HEADER}import { createContentApi } from '@opencloudcms/client';\n${imp}\n/** Typed storefront content client (public content types only). */\nexport const cms = createContentApi<{ ${map} }>();\n`;
|
|
203
|
+
}
|
|
204
|
+
function renderIndex() {
|
|
205
|
+
return `${HEADER}export * from './types';\nexport * from './tables';\nexport * from './registry';\nexport * from './validators';\n`;
|
|
206
|
+
}
|
|
207
|
+
function generateCode(defs, generatedDir) {
|
|
208
|
+
const sorted = [...defs].sort((a, b) => a.apiId.localeCompare(b.apiId));
|
|
209
|
+
return [
|
|
210
|
+
{ path: path.join(generatedDir, 'types.ts'), content: renderTypes(sorted) },
|
|
211
|
+
{ path: path.join(generatedDir, 'tables.ts'), content: renderTables(sorted) },
|
|
212
|
+
{ path: path.join(generatedDir, 'registry.ts'), content: renderRegistry(sorted) },
|
|
213
|
+
{ path: path.join(generatedDir, 'validators.ts'), content: renderValidators(sorted) },
|
|
214
|
+
{ path: path.join(generatedDir, 'client.ts'), content: renderClient(sorted) },
|
|
215
|
+
{ path: path.join(generatedDir, 'index.ts'), content: renderIndex() },
|
|
216
|
+
];
|
|
217
|
+
}
|
|
218
|
+
/** Writes files; returns the ones whose content changed. */
|
|
219
|
+
function writeGeneratedFiles(files) {
|
|
220
|
+
const changed = [];
|
|
221
|
+
for (const file of files) {
|
|
222
|
+
const current = fs.existsSync(file.path) ? fs.readFileSync(file.path, 'utf8') : null;
|
|
223
|
+
if (current === file.content)
|
|
224
|
+
continue;
|
|
225
|
+
fs.mkdirSync(path.dirname(file.path), { recursive: true });
|
|
226
|
+
fs.writeFileSync(file.path, file.content);
|
|
227
|
+
changed.push(file.path);
|
|
228
|
+
}
|
|
229
|
+
return changed;
|
|
230
|
+
}
|
|
231
|
+
function staleGeneratedFiles(files) {
|
|
232
|
+
return files
|
|
233
|
+
.filter((f) => !fs.existsSync(f.path) || fs.readFileSync(f.path, 'utf8') !== f.content)
|
|
234
|
+
.map((f) => f.path);
|
|
235
|
+
}
|
|
236
|
+
//# sourceMappingURL=codegen.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codegen.js","sourceRoot":"","sources":["../src/codegen.ts"],"names":[],"mappings":";;;;;;;;;;;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,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;SACtF,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;AACxB,CAAC"}
|
package/dist/ddl.d.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A tiny DDL model. The diff engine produces statements; three consumers use them:
|
|
3
|
+
* - printStatement() -> Kysely code written into migration files
|
|
4
|
+
* - compileStatement() -> SQL shown in the admin UI / `opencloudcms plan`
|
|
5
|
+
* - executeStatement() -> run directly (tests, tooling)
|
|
6
|
+
*/
|
|
7
|
+
import { Kysely } from 'kysely';
|
|
8
|
+
import type { IndexSpec, PhysicalColumn } from '@opencloudcms/schema';
|
|
9
|
+
export type Statement = {
|
|
10
|
+
type: 'createTable';
|
|
11
|
+
table: string;
|
|
12
|
+
columns: PhysicalColumn[];
|
|
13
|
+
primaryKey: {
|
|
14
|
+
name: string;
|
|
15
|
+
columns: string[];
|
|
16
|
+
};
|
|
17
|
+
} | {
|
|
18
|
+
type: 'dropTable';
|
|
19
|
+
table: string;
|
|
20
|
+
} | {
|
|
21
|
+
type: 'renameTable';
|
|
22
|
+
from: string;
|
|
23
|
+
to: string;
|
|
24
|
+
} | {
|
|
25
|
+
type: 'addColumn';
|
|
26
|
+
table: string;
|
|
27
|
+
column: PhysicalColumn;
|
|
28
|
+
} | {
|
|
29
|
+
type: 'dropColumn';
|
|
30
|
+
table: string;
|
|
31
|
+
column: string;
|
|
32
|
+
} | {
|
|
33
|
+
type: 'renameColumn';
|
|
34
|
+
table: string;
|
|
35
|
+
from: string;
|
|
36
|
+
to: string;
|
|
37
|
+
} | {
|
|
38
|
+
type: 'alterColumnType';
|
|
39
|
+
table: string;
|
|
40
|
+
column: string;
|
|
41
|
+
toType: string;
|
|
42
|
+
} | {
|
|
43
|
+
type: 'createIndex';
|
|
44
|
+
index: IndexSpec;
|
|
45
|
+
} | {
|
|
46
|
+
type: 'dropIndex';
|
|
47
|
+
name: string;
|
|
48
|
+
} | {
|
|
49
|
+
type: 'renameIndex';
|
|
50
|
+
from: string;
|
|
51
|
+
to: string;
|
|
52
|
+
}
|
|
53
|
+
/** Throws when the table has any row (guards switching `private` on a type). */
|
|
54
|
+
| {
|
|
55
|
+
type: 'assertTableEmpty';
|
|
56
|
+
table: string;
|
|
57
|
+
apiId: string;
|
|
58
|
+
option: string;
|
|
59
|
+
};
|
|
60
|
+
/** SQL text for previews. */
|
|
61
|
+
export declare function compileStatement(stmt: Statement): string;
|
|
62
|
+
export declare function emptyTableMessage(stmt: {
|
|
63
|
+
apiId: string;
|
|
64
|
+
option: string;
|
|
65
|
+
}): string;
|
|
66
|
+
export declare function executeStatement(db: Kysely<any>, stmt: Statement): Promise<void>;
|
|
67
|
+
export declare function printStatement(stmt: Statement, indent?: string): string;
|
package/dist/ddl.js
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.compileStatement = compileStatement;
|
|
4
|
+
exports.emptyTableMessage = emptyTableMessage;
|
|
5
|
+
exports.executeStatement = executeStatement;
|
|
6
|
+
exports.printStatement = printStatement;
|
|
7
|
+
/**
|
|
8
|
+
* A tiny DDL model. The diff engine produces statements; three consumers use them:
|
|
9
|
+
* - printStatement() -> Kysely code written into migration files
|
|
10
|
+
* - compileStatement() -> SQL shown in the admin UI / `opencloudcms plan`
|
|
11
|
+
* - executeStatement() -> run directly (tests, tooling)
|
|
12
|
+
*/
|
|
13
|
+
const kysely_1 = require("kysely");
|
|
14
|
+
const IDENT_RE = /^[a-z_][a-z0-9_]*$/;
|
|
15
|
+
const TYPE_RE = /^[a-z ]+(\(\d+(, ?\d+)?\))?$/;
|
|
16
|
+
function ident(name) {
|
|
17
|
+
if (!IDENT_RE.test(name))
|
|
18
|
+
throw new Error(`Unsafe SQL identifier: ${name}`);
|
|
19
|
+
return `"${name}"`;
|
|
20
|
+
}
|
|
21
|
+
function pgType(type) {
|
|
22
|
+
if (!TYPE_RE.test(type))
|
|
23
|
+
throw new Error(`Unsafe SQL type: ${type}`);
|
|
24
|
+
return type;
|
|
25
|
+
}
|
|
26
|
+
function defaultSql(value) {
|
|
27
|
+
if (!/^(now\(\)|-?\d+|true|false)$/.test(value))
|
|
28
|
+
throw new Error(`Unsupported default: ${value}`);
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
function rawSql(stmt) {
|
|
32
|
+
switch (stmt.type) {
|
|
33
|
+
case 'assertTableEmpty':
|
|
34
|
+
return `select 1 from ${ident(stmt.table)} limit 1`;
|
|
35
|
+
case 'renameIndex':
|
|
36
|
+
return `alter index ${ident(stmt.from)} rename to ${ident(stmt.to)}`;
|
|
37
|
+
case 'alterColumnType':
|
|
38
|
+
return `alter table ${ident(stmt.table)} alter column ${ident(stmt.column)} type ${pgType(stmt.toType)} using ${ident(stmt.column)}::${pgType(stmt.toType)}`;
|
|
39
|
+
default:
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function build(db, stmt) {
|
|
44
|
+
const raw = rawSql(stmt);
|
|
45
|
+
if (raw !== null) {
|
|
46
|
+
const q = kysely_1.sql.raw(raw);
|
|
47
|
+
return { sql: q.compile(db).sql, run: () => q.execute(db) };
|
|
48
|
+
}
|
|
49
|
+
let b;
|
|
50
|
+
switch (stmt.type) {
|
|
51
|
+
case 'createTable': {
|
|
52
|
+
let t = db.schema.createTable(stmt.table);
|
|
53
|
+
for (const col of stmt.columns) {
|
|
54
|
+
t = t.addColumn(col.name, kysely_1.sql.raw(pgType(col.type)), (c) => {
|
|
55
|
+
let cc = c;
|
|
56
|
+
if (col.notNull)
|
|
57
|
+
cc = cc.notNull();
|
|
58
|
+
if (col.defaultSql)
|
|
59
|
+
cc = cc.defaultTo(kysely_1.sql.raw(defaultSql(col.defaultSql)));
|
|
60
|
+
if (col.references)
|
|
61
|
+
cc = cc.references(`${col.references.table}.${col.references.column}`).onDelete(col.references.onDelete);
|
|
62
|
+
return cc;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
b = t.addPrimaryKeyConstraint(stmt.primaryKey.name, stmt.primaryKey.columns);
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
case 'dropTable':
|
|
69
|
+
b = db.schema.dropTable(stmt.table);
|
|
70
|
+
break;
|
|
71
|
+
case 'renameTable':
|
|
72
|
+
b = db.schema.alterTable(stmt.from).renameTo(stmt.to);
|
|
73
|
+
break;
|
|
74
|
+
case 'addColumn': {
|
|
75
|
+
const col = stmt.column;
|
|
76
|
+
b = db.schema.alterTable(stmt.table).addColumn(col.name, kysely_1.sql.raw(pgType(col.type)), (c) => {
|
|
77
|
+
let cc = c;
|
|
78
|
+
if (col.notNull)
|
|
79
|
+
cc = cc.notNull();
|
|
80
|
+
if (col.defaultSql)
|
|
81
|
+
cc = cc.defaultTo(kysely_1.sql.raw(defaultSql(col.defaultSql)));
|
|
82
|
+
if (col.references)
|
|
83
|
+
cc = cc.references(`${col.references.table}.${col.references.column}`).onDelete(col.references.onDelete);
|
|
84
|
+
return cc;
|
|
85
|
+
});
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
case 'dropColumn':
|
|
89
|
+
b = db.schema.alterTable(stmt.table).dropColumn(stmt.column);
|
|
90
|
+
break;
|
|
91
|
+
case 'renameColumn':
|
|
92
|
+
b = db.schema.alterTable(stmt.table).renameColumn(stmt.from, stmt.to);
|
|
93
|
+
break;
|
|
94
|
+
case 'createIndex': {
|
|
95
|
+
let i = db.schema.createIndex(stmt.index.name).on(stmt.index.table).columns(stmt.index.columns);
|
|
96
|
+
if (stmt.index.unique)
|
|
97
|
+
i = i.unique();
|
|
98
|
+
b = i;
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
case 'dropIndex':
|
|
102
|
+
b = db.schema.dropIndex(stmt.name);
|
|
103
|
+
break;
|
|
104
|
+
default:
|
|
105
|
+
throw new Error(`Unhandled statement ${stmt.type}`);
|
|
106
|
+
}
|
|
107
|
+
return { sql: b.compile().sql, run: () => b.execute() };
|
|
108
|
+
}
|
|
109
|
+
let compilerDb;
|
|
110
|
+
function getCompilerDb() {
|
|
111
|
+
compilerDb ??= new kysely_1.Kysely({
|
|
112
|
+
dialect: {
|
|
113
|
+
createAdapter: () => new kysely_1.PostgresAdapter(),
|
|
114
|
+
createDriver: () => new kysely_1.DummyDriver(),
|
|
115
|
+
createIntrospector: (db) => new kysely_1.PostgresIntrospector(db),
|
|
116
|
+
createQueryCompiler: () => new kysely_1.PostgresQueryCompiler(),
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
return compilerDb;
|
|
120
|
+
}
|
|
121
|
+
/** SQL text for previews. */
|
|
122
|
+
function compileStatement(stmt) {
|
|
123
|
+
return build(getCompilerDb(), stmt).sql;
|
|
124
|
+
}
|
|
125
|
+
function emptyTableMessage(stmt) {
|
|
126
|
+
return `Cannot change "${stmt.option}" on ${stmt.apiId}: the type has entries`;
|
|
127
|
+
}
|
|
128
|
+
async function executeStatement(db, stmt) {
|
|
129
|
+
if (stmt.type === 'assertTableEmpty') {
|
|
130
|
+
const res = await kysely_1.sql.raw(rawSql(stmt)).execute(db);
|
|
131
|
+
if (res.rows.length)
|
|
132
|
+
throw new Error(emptyTableMessage(stmt));
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
await build(db, stmt).run();
|
|
136
|
+
}
|
|
137
|
+
/* ------------------------------------------------------------------ */
|
|
138
|
+
/* Code printer: Kysely code for migration files */
|
|
139
|
+
/* ------------------------------------------------------------------ */
|
|
140
|
+
const q = (s) => `'${s.replace(/\\/g, '\\\\').replace(/'/g, "\\'")}'`;
|
|
141
|
+
function columnCallback(col) {
|
|
142
|
+
const parts = [];
|
|
143
|
+
if (col.notNull)
|
|
144
|
+
parts.push('.notNull()');
|
|
145
|
+
if (col.defaultSql)
|
|
146
|
+
parts.push(`.defaultTo(sql\`${defaultSql(col.defaultSql)}\`)`);
|
|
147
|
+
if (col.references) {
|
|
148
|
+
parts.push(`.references(${q(`${col.references.table}.${col.references.column}`)}).onDelete(${q(col.references.onDelete)})`);
|
|
149
|
+
}
|
|
150
|
+
return parts.length ? `, (col) => col${parts.join('')}` : '';
|
|
151
|
+
}
|
|
152
|
+
function printStatement(stmt, indent = ' ') {
|
|
153
|
+
const i2 = indent + ' ';
|
|
154
|
+
switch (stmt.type) {
|
|
155
|
+
case 'createTable': {
|
|
156
|
+
const lines = [`${indent}await db.schema`, `${i2}.createTable(${q(stmt.table)})`];
|
|
157
|
+
for (const col of stmt.columns) {
|
|
158
|
+
lines.push(`${i2}.addColumn(${q(col.name)}, sql\`${pgType(col.type)}\`${columnCallback(col)})`);
|
|
159
|
+
}
|
|
160
|
+
lines.push(`${i2}.addPrimaryKeyConstraint(${q(stmt.primaryKey.name)}, [${stmt.primaryKey.columns.map(q).join(', ')}])`);
|
|
161
|
+
lines.push(`${i2}.execute();`);
|
|
162
|
+
return lines.join('\n');
|
|
163
|
+
}
|
|
164
|
+
case 'dropTable':
|
|
165
|
+
return `${indent}await db.schema.dropTable(${q(stmt.table)}).execute();`;
|
|
166
|
+
case 'renameTable':
|
|
167
|
+
return `${indent}await db.schema.alterTable(${q(stmt.from)}).renameTo(${q(stmt.to)}).execute();`;
|
|
168
|
+
case 'addColumn':
|
|
169
|
+
return `${indent}await db.schema\n${i2}.alterTable(${q(stmt.table)})\n${i2}.addColumn(${q(stmt.column.name)}, sql\`${pgType(stmt.column.type)}\`${columnCallback(stmt.column)})\n${i2}.execute();`;
|
|
170
|
+
case 'dropColumn':
|
|
171
|
+
return `${indent}await db.schema.alterTable(${q(stmt.table)}).dropColumn(${q(stmt.column)}).execute();`;
|
|
172
|
+
case 'renameColumn':
|
|
173
|
+
return `${indent}await db.schema.alterTable(${q(stmt.table)}).renameColumn(${q(stmt.from)}, ${q(stmt.to)}).execute();`;
|
|
174
|
+
case 'createIndex':
|
|
175
|
+
return `${indent}await db.schema\n${i2}.createIndex(${q(stmt.index.name)})\n${i2}.on(${q(stmt.index.table)})\n${i2}.columns([${stmt.index.columns.map(q).join(', ')}])${stmt.index.unique ? `\n${i2}.unique()` : ''}\n${i2}.execute();`;
|
|
176
|
+
case 'dropIndex':
|
|
177
|
+
return `${indent}await db.schema.dropIndex(${q(stmt.name)}).execute();`;
|
|
178
|
+
case 'assertTableEmpty':
|
|
179
|
+
return `${indent}{\n${i2}const { rows } = await sql.raw(${q(rawSql(stmt))}).execute(db);\n${i2}if (rows.length) throw new Error(${q(emptyTableMessage(stmt))});\n${indent}}`;
|
|
180
|
+
case 'renameIndex':
|
|
181
|
+
case 'alterColumnType':
|
|
182
|
+
return `${indent}await sql.raw(${q(rawSql(stmt))}).execute(db);`;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
//# sourceMappingURL=ddl.js.map
|
package/dist/ddl.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ddl.js","sourceRoot":"","sources":["../src/ddl.ts"],"names":[],"mappings":";;AA0IA,4CAEC;AAED,8CAEC;AAED,4CAOC;AAkBD,wCAgCC;AA3MD;;;;;GAKG;AACH,mCAOgB;AAiBhB,MAAM,QAAQ,GAAG,oBAAoB,CAAC;AACtC,MAAM,OAAO,GAAG,8BAA8B,CAAC;AAE/C,SAAS,KAAK,CAAC,IAAY;IACzB,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,0BAA0B,IAAI,EAAE,CAAC,CAAC;IAC5E,OAAO,IAAI,IAAI,GAAG,CAAC;AACrB,CAAC;AACD,SAAS,MAAM,CAAC,IAAY;IAC1B,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,MAAM,IAAI,KAAK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,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,aAAa,CAAC;QAC1O,KAAK,WAAW;YACd,OAAO,GAAG,MAAM,6BAA6B,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC;QAC1E,KAAK,kBAAkB;YACrB,OAAO,GAAG,MAAM,MAAM,EAAE,kCAAkC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAE,CAAC,mBAAmB,EAAE,oCAAoC,CAAC,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,OAAO,MAAM,GAAG,CAAC;QAChL,KAAK,aAAa,CAAC;QACnB,KAAK,iBAAiB;YACpB,OAAO,GAAG,MAAM,iBAAiB,CAAC,CAAC,MAAM,CAAC,IAAI,CAAE,CAAC,gBAAgB,CAAC;IACtE,CAAC;AACH,CAAC"}
|
package/dist/diff.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Diff engine: compares the previous snapshot with the current definitions
|
|
3
|
+
* (matching content types and fields by their stable `id`) and produces a
|
|
4
|
+
* list of schema operations.
|
|
5
|
+
*/
|
|
6
|
+
import type { ContentTypeDefinition, FieldDefinition } from '@opencloudcms/schema';
|
|
7
|
+
export type Operation = {
|
|
8
|
+
op: 'createType';
|
|
9
|
+
def: ContentTypeDefinition;
|
|
10
|
+
} | {
|
|
11
|
+
op: 'dropType';
|
|
12
|
+
def: ContentTypeDefinition;
|
|
13
|
+
} | {
|
|
14
|
+
op: 'setPrivate';
|
|
15
|
+
def: ContentTypeDefinition;
|
|
16
|
+
to: boolean;
|
|
17
|
+
} | {
|
|
18
|
+
op: 'renameType';
|
|
19
|
+
def: ContentTypeDefinition;
|
|
20
|
+
toApiId: string;
|
|
21
|
+
} | {
|
|
22
|
+
op: 'addField';
|
|
23
|
+
ctx: ContentTypeDefinition;
|
|
24
|
+
field: FieldDefinition;
|
|
25
|
+
} | {
|
|
26
|
+
op: 'dropField';
|
|
27
|
+
ctx: ContentTypeDefinition;
|
|
28
|
+
field: FieldDefinition;
|
|
29
|
+
} | {
|
|
30
|
+
op: 'renameField';
|
|
31
|
+
ctx: ContentTypeDefinition;
|
|
32
|
+
from: FieldDefinition;
|
|
33
|
+
to: FieldDefinition;
|
|
34
|
+
} | {
|
|
35
|
+
op: 'alterField';
|
|
36
|
+
ctx: ContentTypeDefinition;
|
|
37
|
+
from: FieldDefinition;
|
|
38
|
+
to: FieldDefinition;
|
|
39
|
+
};
|
|
40
|
+
export declare class DiffError extends Error {
|
|
41
|
+
readonly issues: string[];
|
|
42
|
+
constructor(issues: string[]);
|
|
43
|
+
}
|
|
44
|
+
export interface DiffResult {
|
|
45
|
+
operations: Operation[];
|
|
46
|
+
/** True when anything at all changed, including labels and other metadata. */
|
|
47
|
+
changed: boolean;
|
|
48
|
+
}
|
|
49
|
+
export declare const definitionsEqual: (a: unknown, b: unknown) => boolean;
|
|
50
|
+
/** Column type changes that never lose data. */
|
|
51
|
+
export declare function isSafeCast(from: string, to: string): boolean;
|
|
52
|
+
export declare function diffSchemas(prev: ContentTypeDefinition[], next: ContentTypeDefinition[]): DiffResult;
|