@opensaas/stack-cli 0.43.0 → 0.44.0-alpha.1

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 (134) hide show
  1. package/README.md +116 -135
  2. package/dist/.build-hash +1 -0
  3. package/dist/commands/db.d.ts +23 -0
  4. package/dist/commands/db.d.ts.map +1 -0
  5. package/dist/commands/db.js +43 -0
  6. package/dist/commands/db.js.map +1 -0
  7. package/dist/commands/dev.d.ts +12 -1
  8. package/dist/commands/dev.d.ts.map +1 -1
  9. package/dist/commands/dev.js +519 -22
  10. package/dist/commands/dev.js.map +1 -1
  11. package/dist/commands/fk-renames.d.ts +14 -0
  12. package/dist/commands/fk-renames.d.ts.map +1 -0
  13. package/dist/commands/fk-renames.js +90 -0
  14. package/dist/commands/fk-renames.js.map +1 -0
  15. package/dist/commands/generate.d.ts +61 -4
  16. package/dist/commands/generate.d.ts.map +1 -1
  17. package/dist/commands/generate.js +225 -138
  18. package/dist/commands/generate.js.map +1 -1
  19. package/dist/commands/init.d.ts +6 -0
  20. package/dist/commands/init.d.ts.map +1 -1
  21. package/dist/commands/init.js +13 -2
  22. package/dist/commands/init.js.map +1 -1
  23. package/dist/commands/junction-ids.d.ts +11 -0
  24. package/dist/commands/junction-ids.d.ts.map +1 -0
  25. package/dist/commands/junction-ids.js +81 -0
  26. package/dist/commands/junction-ids.js.map +1 -0
  27. package/dist/commands/migrate.d.ts +2 -0
  28. package/dist/commands/migrate.d.ts.map +1 -1
  29. package/dist/commands/migrate.js +47 -25
  30. package/dist/commands/migrate.js.map +1 -1
  31. package/dist/dev/app-runner.d.ts +70 -0
  32. package/dist/dev/app-runner.d.ts.map +1 -0
  33. package/dist/dev/app-runner.js +116 -0
  34. package/dist/dev/app-runner.js.map +1 -0
  35. package/dist/dev/control.d.ts +73 -0
  36. package/dist/dev/control.d.ts.map +1 -0
  37. package/dist/dev/control.js +251 -0
  38. package/dist/dev/control.js.map +1 -0
  39. package/dist/dev/staged-reconcile.d.ts +126 -0
  40. package/dist/dev/staged-reconcile.d.ts.map +1 -0
  41. package/dist/dev/staged-reconcile.js +289 -0
  42. package/dist/dev/staged-reconcile.js.map +1 -0
  43. package/dist/generator/config-load.d.ts +34 -0
  44. package/dist/generator/config-load.d.ts.map +1 -0
  45. package/dist/generator/config-load.js +64 -0
  46. package/dist/generator/config-load.js.map +1 -0
  47. package/dist/generator/context.d.ts +39 -3
  48. package/dist/generator/context.d.ts.map +1 -1
  49. package/dist/generator/context.js +245 -107
  50. package/dist/generator/context.js.map +1 -1
  51. package/dist/generator/contract-emit.d.ts +24 -0
  52. package/dist/generator/contract-emit.d.ts.map +1 -0
  53. package/dist/generator/contract-emit.js +34 -0
  54. package/dist/generator/contract-emit.js.map +1 -0
  55. package/dist/generator/contract-module.d.ts +39 -0
  56. package/dist/generator/contract-module.d.ts.map +1 -0
  57. package/dist/generator/contract-module.js +440 -0
  58. package/dist/generator/contract-module.js.map +1 -0
  59. package/dist/generator/extension-spaces.d.ts +142 -0
  60. package/dist/generator/extension-spaces.d.ts.map +1 -0
  61. package/dist/generator/extension-spaces.js +358 -0
  62. package/dist/generator/extension-spaces.js.map +1 -0
  63. package/dist/generator/index.d.ts +12 -4
  64. package/dist/generator/index.d.ts.map +1 -1
  65. package/dist/generator/index.js +7 -3
  66. package/dist/generator/index.js.map +1 -1
  67. package/dist/generator/lists.d.ts +6 -7
  68. package/dist/generator/lists.d.ts.map +1 -1
  69. package/dist/generator/lists.js +33 -13
  70. package/dist/generator/lists.js.map +1 -1
  71. package/dist/generator/output-paths.d.ts +62 -19
  72. package/dist/generator/output-paths.d.ts.map +1 -1
  73. package/dist/generator/output-paths.js +68 -30
  74. package/dist/generator/output-paths.js.map +1 -1
  75. package/dist/generator/prisma-cli.d.ts +61 -0
  76. package/dist/generator/prisma-cli.d.ts.map +1 -0
  77. package/dist/generator/prisma-cli.js +92 -0
  78. package/dist/generator/prisma-cli.js.map +1 -0
  79. package/dist/generator/prisma-config.d.ts +50 -31
  80. package/dist/generator/prisma-config.d.ts.map +1 -1
  81. package/dist/generator/prisma-config.js +72 -65
  82. package/dist/generator/prisma-config.js.map +1 -1
  83. package/dist/generator/source-text.d.ts +16 -0
  84. package/dist/generator/source-text.d.ts.map +1 -0
  85. package/dist/generator/source-text.js +35 -0
  86. package/dist/generator/source-text.js.map +1 -0
  87. package/dist/generator/tables.d.ts +5 -0
  88. package/dist/generator/tables.d.ts.map +1 -0
  89. package/dist/generator/tables.js +84 -0
  90. package/dist/generator/tables.js.map +1 -0
  91. package/dist/generator/types.d.ts +23 -3
  92. package/dist/generator/types.d.ts.map +1 -1
  93. package/dist/generator/types.js +291 -1171
  94. package/dist/generator/types.js.map +1 -1
  95. package/dist/index.js +20 -7
  96. package/dist/index.js.map +1 -1
  97. package/dist/mcp/lib/documentation-provider.d.ts.map +1 -1
  98. package/dist/mcp/lib/documentation-provider.js +44 -42
  99. package/dist/mcp/lib/documentation-provider.js.map +1 -1
  100. package/dist/mcp/lib/generators/feature-generator.d.ts.map +1 -1
  101. package/dist/mcp/lib/generators/feature-generator.js +124 -73
  102. package/dist/mcp/lib/generators/feature-generator.js.map +1 -1
  103. package/dist/mcp/lib/wizards/migration-wizard.js +6 -6
  104. package/dist/mcp/lib/wizards/migration-wizard.js.map +1 -1
  105. package/dist/mcp/lib/wizards/wizard-engine.d.ts.map +1 -1
  106. package/dist/mcp/lib/wizards/wizard-engine.js +3 -2
  107. package/dist/mcp/lib/wizards/wizard-engine.js.map +1 -1
  108. package/dist/mcp/server/stack-mcp-server.js +1 -1
  109. package/dist/migration/fk-renames.d.ts +39 -0
  110. package/dist/migration/fk-renames.d.ts.map +1 -0
  111. package/dist/migration/fk-renames.js +79 -0
  112. package/dist/migration/fk-renames.js.map +1 -0
  113. package/dist/migration/generators/migration-generator.d.ts +11 -0
  114. package/dist/migration/generators/migration-generator.d.ts.map +1 -1
  115. package/dist/migration/generators/migration-generator.js +83 -150
  116. package/dist/migration/generators/migration-generator.js.map +1 -1
  117. package/dist/migration/introspectors/prisma-introspector.d.ts.map +1 -1
  118. package/dist/migration/introspectors/prisma-introspector.js +1 -0
  119. package/dist/migration/introspectors/prisma-introspector.js.map +1 -1
  120. package/dist/migration/junction-ids.d.ts +15 -0
  121. package/dist/migration/junction-ids.d.ts.map +1 -0
  122. package/dist/migration/junction-ids.js +58 -0
  123. package/dist/migration/junction-ids.js.map +1 -0
  124. package/dist/migration/types.d.ts +2 -0
  125. package/dist/migration/types.d.ts.map +1 -1
  126. package/package.json +27 -15
  127. package/dist/generator/node-build.d.ts +0 -53
  128. package/dist/generator/node-build.d.ts.map +0 -1
  129. package/dist/generator/node-build.js +0 -280
  130. package/dist/generator/node-build.js.map +0 -1
  131. package/dist/generator/prisma.d.ts +0 -30
  132. package/dist/generator/prisma.d.ts.map +0 -1
  133. package/dist/generator/prisma.js +0 -422
  134. package/dist/generator/prisma.js.map +0 -1
@@ -0,0 +1,440 @@
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+ import { IDENTIFIER, key, quote } from './source-text.js';
4
+ /**
5
+ * The column-type helpers the rendered module imports from
6
+ * `@prisma/orm-postgres/adapter/column-types`, in the order they are emitted.
7
+ * Only the ones a given contract actually reaches are imported.
8
+ */
9
+ const COLUMN_TYPE_HELPERS = [
10
+ 'charColumn',
11
+ 'dateStringColumn',
12
+ 'float4Column',
13
+ 'int2Column',
14
+ 'jsonColumn',
15
+ 'numericColumn',
16
+ 'timeStringColumn',
17
+ 'timestampStringColumn',
18
+ 'timestamptzStringColumn',
19
+ 'varcharColumn',
20
+ ];
21
+ /**
22
+ * JSON literals are the whole vocabulary a contract carries (ADR-0040).
23
+ *
24
+ * An object member whose value is `undefined` is omitted, as `JSON.stringify`
25
+ * omits it. Anything else with no JSON form — `undefined` as an array element
26
+ * or a bare argument, a function, a symbol — is refused rather than rendered
27
+ * as the bare identifier `undefined`: omitting it there would silently shift
28
+ * the positions around it.
29
+ */
30
+ function literal(value) {
31
+ if (typeof value === 'string')
32
+ return quote(value);
33
+ if (Array.isArray(value))
34
+ return `[${value.map((entry) => literal(entry)).join(', ')}]`;
35
+ if (typeof value === 'object' && value !== null) {
36
+ const entries = Object.entries(value)
37
+ .filter(([, entry]) => entry !== undefined)
38
+ .map(([name, entry]) => `${key(name)}: ${literal(entry)}`);
39
+ return entries.length === 0 ? '{}' : `{ ${entries.join(', ')} }`;
40
+ }
41
+ const rendered = JSON.stringify(value);
42
+ if (rendered === undefined) {
43
+ throw new Error(`A contract descriptor carries a ${typeof value} where a JSON literal is required. ` +
44
+ 'Contract values are JSON (ADR-0040).');
45
+ }
46
+ return rendered;
47
+ }
48
+ /** A member access on the builder's `cols`/`fields` helper record. */
49
+ function member(record, name) {
50
+ return IDENTIFIER.test(name) ? `${record}.${name}` : `${record}[${quote(name)}]`;
51
+ }
52
+ function numberArg(args, index) {
53
+ const value = args?.[index];
54
+ return typeof value === 'number' ? value : undefined;
55
+ }
56
+ function argList(args) {
57
+ return (args ?? []).map((arg) => literal(arg)).join(', ');
58
+ }
59
+ /**
60
+ * The identifiers a model and a native enum are bound to in the rendered
61
+ * module.
62
+ *
63
+ * Both names come from the config surface, which enforces no casing and no
64
+ * reserved words: a list may be called `models` or `field`, and an enum name
65
+ * (`db.enumName`) may equal a list's. A bare `<Name>` binding would then shadow
66
+ * the callback's own `field`/`model`/`rel`/`type` parameters or the internal
67
+ * `models` record, and a bare `<Name>Enum` would collide with a list literally
68
+ * called `<Name>Enum`. Prefixing puts both in their own namespace, and the
69
+ * prefixes are injective, so two distinct names can never land on one binding.
70
+ */
71
+ function modelBinding(name) {
72
+ return `model_${name}`;
73
+ }
74
+ function enumBinding(name) {
75
+ return `enum_${name}`;
76
+ }
77
+ /**
78
+ * The `field.*` call for one `pg`-pack column type — the rendered twin of
79
+ * `buildPrismaContract`'s `pgColumn`.
80
+ */
81
+ function pgColumnExpression(model, column) {
82
+ const { type } = column;
83
+ switch (type.type) {
84
+ case 'text':
85
+ return { expression: 'field.column(type.String())', helpers: [] };
86
+ case 'varchar': {
87
+ const length = numberArg(type.args, 0);
88
+ if (length === undefined) {
89
+ throw new Error(`Model "${model}", column "${column.name}": a varchar column needs a length`);
90
+ }
91
+ return { expression: `field.column(varcharColumn(${length}))`, helpers: ['varcharColumn'] };
92
+ }
93
+ case 'char': {
94
+ const length = numberArg(type.args, 0);
95
+ if (length === undefined) {
96
+ throw new Error(`Model "${model}", column "${column.name}": a char column needs a length`);
97
+ }
98
+ return { expression: `field.column(charColumn(${length}))`, helpers: ['charColumn'] };
99
+ }
100
+ case 'int':
101
+ return { expression: 'field.column(type.Int())', helpers: [] };
102
+ case 'smallint':
103
+ return { expression: 'field.column(int2Column)', helpers: ['int2Column'] };
104
+ case 'bigint':
105
+ return { expression: 'field.column(type.BigInt())', helpers: [] };
106
+ case 'decimal': {
107
+ const precision = numberArg(type.args, 0);
108
+ if (precision === undefined)
109
+ return { expression: 'field.column(type.Decimal())', helpers: [] };
110
+ const scale = numberArg(type.args, 1);
111
+ const args = scale === undefined ? `${precision}` : `${precision}, ${scale}`;
112
+ return { expression: `field.column(numericColumn(${args}))`, helpers: ['numericColumn'] };
113
+ }
114
+ case 'float':
115
+ return { expression: 'field.column(type.Float())', helpers: [] };
116
+ case 'real':
117
+ return { expression: 'field.column(float4Column)', helpers: ['float4Column'] };
118
+ case 'boolean':
119
+ return { expression: 'field.column(type.Boolean())', helpers: [] };
120
+ case 'dateTime':
121
+ case 'timestamptz':
122
+ return withPrecision('timestamptzStringColumn', numberArg(type.args, 0));
123
+ case 'timestamp':
124
+ return withPrecision('timestampStringColumn', numberArg(type.args, 0));
125
+ case 'time': {
126
+ const precision = numberArg(type.args, 0);
127
+ const args = precision === undefined ? '' : `${precision}`;
128
+ return {
129
+ expression: `field.column(timeStringColumn(${args}))`,
130
+ helpers: ['timeStringColumn'],
131
+ };
132
+ }
133
+ case 'date':
134
+ return { expression: 'field.column(dateStringColumn)', helpers: ['dateStringColumn'] };
135
+ case 'uuid':
136
+ return { expression: 'field.column(type.Uuid())', helpers: [] };
137
+ case 'json':
138
+ return { expression: 'field.column(jsonColumn)', helpers: ['jsonColumn'] };
139
+ case 'jsonb':
140
+ return { expression: 'field.column(type.Jsonb())', helpers: [] };
141
+ case 'bytes':
142
+ return { expression: 'field.column(type.Bytes())', helpers: [] };
143
+ case 'enum': {
144
+ const name = column.enum?.name;
145
+ if (name === undefined) {
146
+ throw new Error(`Model "${model}", column "${column.name}": enum column names no declared enum`);
147
+ }
148
+ return { expression: `field.column(pg.enum(${enumBinding(name)}))`, helpers: [] };
149
+ }
150
+ default:
151
+ throw new Error(`Model "${model}", column "${column.name}": the Postgres pack has no type "${type.type}"`);
152
+ }
153
+ }
154
+ /**
155
+ * rc.8's `timestamp`/`timestamptz` descriptors are constants with no
156
+ * precision parameter; the codec behind each takes `typeParams.precision`, so
157
+ * a precision is spread onto the constant.
158
+ */
159
+ function withPrecision(helper, precision) {
160
+ const expression = precision === undefined
161
+ ? `field.column(${helper})`
162
+ : `field.column({ ...${helper}, typeParams: { precision: ${precision} } })`;
163
+ return { expression, helpers: [helper] };
164
+ }
165
+ function columnExpression(model, column) {
166
+ const base = column.type.pack === 'pg'
167
+ ? pgColumnExpression(model, column)
168
+ : {
169
+ expression: `field.column(type.${column.type.pack}.${column.type.type}(${argList(column.type.args)}))`,
170
+ helpers: [],
171
+ };
172
+ let expression = base.expression;
173
+ if (column.nullable)
174
+ expression += '.optional()';
175
+ if (column.map !== undefined)
176
+ expression += `.column(${literal(column.map)})`;
177
+ if (column.unique)
178
+ expression += '.unique()';
179
+ if (column.default?.kind === 'literal')
180
+ expression += `.default(${codecLiteral(column, column.default.value)})`;
181
+ if (column.default?.kind === 'now')
182
+ expression += `.defaultSql('now()')`;
183
+ if (column.default?.kind === 'sql')
184
+ expression += `.defaultSql(${literal(column.default.expression)})`;
185
+ return { expression, helpers: base.helpers };
186
+ }
187
+ function codecLiteral(column, value) {
188
+ return column.type.pack === 'pg' && column.type.type === 'bigint' && typeof value === 'string'
189
+ ? `${BigInt(value)}n`
190
+ : literal(value);
191
+ }
192
+ function idExpression(id) {
193
+ switch (id.strategy) {
194
+ case 'uuid7':
195
+ return 'field.column(type.Uuid()).id().onCreate(gen.uuid(7))';
196
+ case 'cuid2':
197
+ return 'field.column(type.Cuid2()).id().onCreate(gen.cuid(2))';
198
+ case 'cuid':
199
+ return 'field.column(type.String()).id().onCreate(gen.cuid(2))';
200
+ case 'int autoincrement':
201
+ return `field.column(type.Int()).defaultSql('autoincrement()').id()`;
202
+ case 'singleton':
203
+ return 'field.column(type.Int()).default(1).id()';
204
+ }
205
+ }
206
+ function relationExpression(relation) {
207
+ const target = `() => ${member('models', relation.target)}`;
208
+ return relation.kind === 'belongsTo'
209
+ ? `rel.belongsTo(${target}, { from: ${literal(relation.column)}, to: 'id' })`
210
+ : `rel.${relation.kind}(${target}, { by: ${literal(relation.column)} })`;
211
+ }
212
+ /** The `const <Model> = model(...)` declaration, relations included. */
213
+ function renderModelDeclaration(model, helpers) {
214
+ const fields = [` id: ${idExpression(model.id)},`];
215
+ for (const column of model.columns) {
216
+ const rendered = columnExpression(model.name, column);
217
+ for (const helper of rendered.helpers)
218
+ helpers.add(helper);
219
+ fields.push(` ${key(column.name)}: ${rendered.expression},`);
220
+ }
221
+ // Known limits: createdAt is not .onCreate(gen.now()) alone, which drops the database
222
+ // now() default that inserts outside the ORM rely on. See #1693 and ADR-0048.
223
+ if (model.timestamps.createdAt) {
224
+ helpers.add('timestamptzStringColumn');
225
+ fields.push(" createdAt: field.column(timestamptzStringColumn).defaultSql('now()'),");
226
+ }
227
+ if (model.timestamps.updatedAt) {
228
+ fields.push(' updatedAt: field.column(type.TimestamptzString()).onCreate(gen.now()).onUpdate(gen.now()),');
229
+ }
230
+ const lines = [
231
+ ` const ${modelBinding(model.name)} = (${member('models', model.name)} = model(${literal(model.name)}, {`,
232
+ ];
233
+ lines.push(' fields: {', ...fields, ' },');
234
+ if (model.relations.length === 0) {
235
+ lines.push(' relations: {},');
236
+ }
237
+ else {
238
+ lines.push(' relations: {');
239
+ for (const relation of model.relations) {
240
+ lines.push(` ${key(relation.name)}: ${relationExpression(relation)},`);
241
+ }
242
+ lines.push(' },');
243
+ }
244
+ if (model.namespace !== undefined) {
245
+ lines.push(` namespace: ${literal(model.namespace)},`);
246
+ }
247
+ lines.push(' }))');
248
+ return lines.join('\n');
249
+ }
250
+ /**
251
+ * The `.attributes(...).sql(...)` tail, rendered for the `models:` record the
252
+ * `defineContract` callback returns. Both calls are always emitted so the
253
+ * rendered module and `buildPrismaContract` reach the builder identically.
254
+ */
255
+ function renderModelAttributes(model) {
256
+ const uniques = model.indexes.filter((index) => index.unique && index.where === undefined);
257
+ const plainIndexes = model.indexes.filter((index) => !index.unique || index.where !== undefined);
258
+ const indexedColumns = model.columns.filter((column) => column.index);
259
+ const uniqueEntries = uniques.map((index) => {
260
+ const columns = index.columns.map((column) => member('fields', column)).join(', ');
261
+ const options = index.name !== undefined ? `, { name: ${literal(index.name)} }` : ', {}';
262
+ return `constraints.unique([${columns}]${options}),`;
263
+ });
264
+ const indexEntries = [
265
+ ...indexedColumns.map((column) => `constraints.index([${member('cols', column.name)}]),`),
266
+ ...plainIndexes.map((index) => {
267
+ const columns = index.columns.map((column) => member('cols', column)).join(', ');
268
+ const options = [];
269
+ if (index.name !== undefined)
270
+ options.push(`map: ${literal(index.name)}`);
271
+ if (index.unique)
272
+ options.push('unique: true');
273
+ if (index.where !== undefined)
274
+ options.push(`where: sql(Object.assign([${literal(index.where)}], { raw: [${literal(index.where)}] }))`);
275
+ return `constraints.index([${columns}]${options.length > 0 ? `, { ${options.join(', ')} }` : ''}),`;
276
+ }),
277
+ ];
278
+ const foreignKeyEntries = model.foreignKeys.map((fk) => {
279
+ const options = ['index: false'];
280
+ if (fk.name !== undefined)
281
+ options.push(`name: ${literal(fk.name)}`);
282
+ if (fk.onDelete !== undefined)
283
+ options.push(`onDelete: ${literal(fk.onDelete)}`);
284
+ if (fk.onUpdate !== undefined)
285
+ options.push(`onUpdate: ${literal(fk.onUpdate)}`);
286
+ return `constraints.foreignKey(${member('cols', fk.column)}, ${modelBinding(fk.references.model)}.refs.id, { ${options.join(', ')} }),`;
287
+ });
288
+ /** `key: []`, or the entries one per line under it. */
289
+ function block(name, entries) {
290
+ if (entries.length === 0)
291
+ return [` ${name}: [],`];
292
+ return [
293
+ ` ${name}: [`,
294
+ ...entries.map((entry) => ` ${entry}`),
295
+ ' ],',
296
+ ];
297
+ }
298
+ const lines = [];
299
+ const uniqueParams = uniqueEntries.length > 0 ? '({ fields, constraints })' : '()';
300
+ lines.push(` ${key(model.name)}: ${modelBinding(model.name)}.attributes(${uniqueParams} => ({`);
301
+ lines.push(...block('uniques', uniqueEntries));
302
+ const usesSqlHelpers = indexEntries.length > 0 || foreignKeyEntries.length > 0;
303
+ const sqlParams = usesSqlHelpers ? '({ cols, constraints })' : '()';
304
+ lines.push(` })).sql(${sqlParams} => ({`);
305
+ if (model.table !== undefined) {
306
+ lines.push(` table: ${literal(model.table)},`);
307
+ }
308
+ lines.push(...block('indexes', indexEntries));
309
+ lines.push(...block('foreignKeys', foreignKeyEntries));
310
+ lines.push(' })),');
311
+ return lines.join('\n');
312
+ }
313
+ /**
314
+ * The pack's `/pack` subpath, re-emitted from the descriptor's `from` package
315
+ * name (ADR-0049). The module imports the pack value; nothing is serialised
316
+ * out of the config.
317
+ */
318
+ function packSubpath(extension) {
319
+ return `${extension.from}/pack`;
320
+ }
321
+ /**
322
+ * Render the standalone Contract module — `prisma/contract.ts` — from core's
323
+ * derivation (ADR-0040, ADR-0057).
324
+ *
325
+ * The module imports only from `@prisma/orm-postgres/contract-builder`,
326
+ * `@prisma/orm-postgres/adapter/column-types` and each declared extension
327
+ * pack's `/pack` subpath. It imports nothing from `opensaas.config.ts`, reads
328
+ * no environment variable and contains no non-literal expression, so it
329
+ * satisfies Prisma's purity rules by construction and `prisma contract emit`
330
+ * can evaluate it on its own.
331
+ *
332
+ * Every builder call is the one {@link buildPrismaContract} makes for the same
333
+ * data, so the rendered module and the in-process derivation emit identical
334
+ * contract JSON — the equivalence test that keeps the two from drifting.
335
+ *
336
+ * @example
337
+ * ```typescript
338
+ * import { deriveContract } from '@opensaas/stack-core'
339
+ * fs.writeFileSync('prisma/contract.ts', renderContractModule(deriveContract(config)))
340
+ * ```
341
+ *
342
+ * Known limits:
343
+ * - A model or enum name must be a valid TypeScript identifier: each becomes a
344
+ * `const` declaration (`model_<Name>` / `enum_<Name>`), and this renderer
345
+ * does not re-check the name. Relation, column and index names have no such
346
+ * limit — they are rendered through `key()`/`member()`, which quote whatever
347
+ * is not an identifier.
348
+ * - The emitted relation targets are thunks (`() => Target`), so a model may
349
+ * reference one declared later, but every target must be a model in the
350
+ * same contract — cross-space references are not rendered.
351
+ * - An extension pack's type constructor is emitted as
352
+ * `type.<pack>.<type>(...)` with the descriptor's literal arguments; the
353
+ * renderer does not know the pack's constructor list, so a misspelled type
354
+ * surfaces at `contract emit` rather than here.
355
+ */
356
+ export function renderContractModule(data) {
357
+ const helpers = new Set();
358
+ const declarations = data.models.map((model) => renderModelDeclaration(model, helpers));
359
+ const attributes = data.models.map((model) => renderModelAttributes(model));
360
+ const usesEnums = data.enums.length > 0;
361
+ const builderImports = ['defineContract'];
362
+ if (data.models.some((model) => model.indexes.some((index) => index.where !== undefined)))
363
+ builderImports.push('sql');
364
+ if (usesEnums)
365
+ builderImports.push('nativeEnum', 'pg');
366
+ const lines = [];
367
+ lines.push('// ⚠️ GENERATED FILE - DO NOT EDIT');
368
+ lines.push("// Generated by 'opensaas generate' from opensaas.config.ts.");
369
+ lines.push('');
370
+ lines.push(`import { ${builderImports.join(', ')} } from '@prisma/orm-postgres/contract-builder'`);
371
+ lines.push("import type { ScalarFieldBuilder } from '@prisma/orm-postgres/contract-builder'");
372
+ const usedHelpers = COLUMN_TYPE_HELPERS.filter((helper) => helpers.has(helper));
373
+ if (usedHelpers.length > 0) {
374
+ lines.push(`import { ${usedHelpers.join(', ')} } from '@prisma/orm-postgres/adapter/column-types'`);
375
+ }
376
+ for (const extension of data.extensions) {
377
+ lines.push(`import ${extension.name} from ${quote(packSubpath(extension))}`);
378
+ }
379
+ lines.push('');
380
+ // A relation target is resolved when the contract is lowered, not when the
381
+ // model is declared, so every target is routed through a record rather than
382
+ // named directly — `rel.belongsTo` reads its target eagerly, which a `const`
383
+ // declared later (or the model itself) cannot satisfy. This is the shape the
384
+ // relation builders accept; the per-model `const` keeps the precise type
385
+ // where a foreign key needs it.
386
+ lines.push('type ModelToken = {');
387
+ lines.push(' readonly stageOne: {');
388
+ lines.push(' readonly modelName?: string');
389
+ lines.push(' readonly fields: Record<string, ScalarFieldBuilder>');
390
+ lines.push(' }');
391
+ lines.push('}');
392
+ lines.push('');
393
+ for (const declared of data.enums) {
394
+ const values = declared.values.map((value) => literal(value)).join(', ');
395
+ lines.push(`const ${enumBinding(declared.name)} = nativeEnum(${literal(declared.name)}, ${values})`);
396
+ }
397
+ if (usesEnums)
398
+ lines.push('');
399
+ const scaffold = [];
400
+ const packNames = data.extensions.map((extension) => extension.name);
401
+ if (packNames.length > 0)
402
+ scaffold.push(`extensions: { ${packNames.join(', ')} }`);
403
+ if (data.namespaces.length > 0) {
404
+ scaffold.push(`namespaces: [${data.namespaces.map((ns) => literal(ns)).join(', ')}]`);
405
+ }
406
+ const usesGenHelper = data.models.some((model) => model.id.strategy === 'uuid7' || model.id.strategy === 'cuid2' || model.timestamps.updatedAt);
407
+ const usesRelHelper = data.models.some((model) => model.relations.length > 0);
408
+ const callbackParams = ['field', 'model'];
409
+ if (usesRelHelper)
410
+ callbackParams.push('rel');
411
+ callbackParams.push('type');
412
+ if (usesGenHelper)
413
+ callbackParams.push('gen');
414
+ lines.push('export const contract = defineContract(');
415
+ lines.push(scaffold.length === 0 ? ' {},' : ` { ${scaffold.join(', ')} },`);
416
+ lines.push(` ({ ${callbackParams.join(', ')} }) => {`);
417
+ lines.push(' const models: Record<string, ModelToken> = {}');
418
+ lines.push('');
419
+ for (const declaration of declarations) {
420
+ lines.push(declaration, '');
421
+ }
422
+ lines.push(' return {');
423
+ lines.push(' models: {');
424
+ lines.push(...attributes);
425
+ lines.push(' },');
426
+ lines.push(' }');
427
+ lines.push(' },');
428
+ lines.push(')');
429
+ lines.push('');
430
+ return lines.join('\n');
431
+ }
432
+ export function writeContractModule(data, outputPath) {
433
+ const content = renderContractModule(data);
434
+ const dir = path.dirname(outputPath);
435
+ if (!fs.existsSync(dir)) {
436
+ fs.mkdirSync(dir, { recursive: true });
437
+ }
438
+ fs.writeFileSync(outputPath, content, 'utf-8');
439
+ }
440
+ //# sourceMappingURL=contract-module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract-module.js","sourceRoot":"","sources":["../../src/generator/contract-module.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AACxB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAQ5B,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AAEzD;;;;GAIG;AACH,MAAM,mBAAmB,GAAG;IAC1B,YAAY;IACZ,kBAAkB;IAClB,cAAc;IACd,YAAY;IACZ,YAAY;IACZ,eAAe;IACf,kBAAkB;IAClB,uBAAuB;IACvB,yBAAyB;IACzB,eAAe;CACP,CAAA;AAUV;;;;;;;;GAQG;AACH,SAAS,OAAO,CAAC,KAAc;IAC7B,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC,KAAK,CAAC,CAAA;IAClD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAA;IACvF,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAChD,MAAM,OAAO,G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AAE,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QACxB,EAAE,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;IACxC,CAAC;IAED,EAAE,CAAC,aAAa,CAAC,UAAU,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;AAChD,CAAC"}
@@ -0,0 +1,142 @@
1
+ import type { ContractData } from '@opensaas/stack-core';
2
+ /**
3
+ * Thrown when a declared extension pack does not publish one of the three
4
+ * subpaths the emissions need. Names the pack and the exact missing subpath —
5
+ * Supabase's pack has no `/control` and is precisely this error.
6
+ */
7
+ export declare class ExtensionSubpathError extends Error {
8
+ /** The pack's binding name, as `db.extensions` spells it. */
9
+ readonly pack: string;
10
+ /** The subpath that did not resolve, e.g. `@prisma/orm-extension-x/control`. */
11
+ readonly subpath: string;
12
+ constructor(
13
+ /** The pack's binding name, as `db.extensions` spells it. */
14
+ pack: string,
15
+ /** The subpath that did not resolve, e.g. `@prisma/orm-extension-x/control`. */
16
+ subpath: string);
17
+ }
18
+ /**
19
+ * Thrown when a declared pack's `/control` subpath resolves and loads but does
20
+ * not default-export a control descriptor. Names the pack and the subpath, so
21
+ * a pack built against a different toolchain generation is reported as such
22
+ * rather than as a `TypeError` from inside the seed phase.
23
+ */
24
+ export declare class ExtensionDescriptorError extends Error {
25
+ /** The pack's binding name, as `db.extensions` spells it. */
26
+ readonly pack: string;
27
+ /** The subpath that loaded without a usable descriptor. */
28
+ readonly subpath: string;
29
+ constructor(
30
+ /** The pack's binding name, as `db.extensions` spells it. */
31
+ pack: string,
32
+ /** The subpath that loaded without a usable descriptor. */
33
+ subpath: string);
34
+ }
35
+ /**
36
+ * Thrown when `migrations/` carries a contract-space directory that no
37
+ * longer corresponds to any pack in `db.extensions` — the pack was
38
+ * dropped from the config, or its space id changed, and the seeded
39
+ * directory was left behind. Each entry's message is the toolchain's own
40
+ * `orphanSpaceDir` remediation, byte-identical to what a later `db init`/
41
+ * `db update` would otherwise refuse with (ADR-0065).
42
+ */
43
+ export declare class OrphanExtensionSpaceError extends Error {
44
+ /** One entry per orphaned space directory, keyed by the directory's own name. */
45
+ readonly spaceIds: readonly string[];
46
+ constructor(
47
+ /** One entry per orphaned space directory, keyed by the directory's own name. */
48
+ spaceIds: readonly string[], remediations: readonly string[]);
49
+ }
50
+ /** One pack's seeded contract space, as the toolchain reported it. */
51
+ export interface SeededExtensionSpace {
52
+ /** The pack's binding name from `db.extensions`. */
53
+ pack: string;
54
+ /** The toolchain's space id — the directory under `migrations/`. */
55
+ spaceId: string;
56
+ /** `updated` when the head ref moved or a package was materialised. */
57
+ action: 'updated' | 'unchanged';
58
+ /** Migration packages written by this call; empty when nothing was missing. */
59
+ migrationDirs: readonly string[];
60
+ }
61
+ /** What {@link seedExtensionContractSpaces} did, for the generator to report. */
62
+ export interface SeededExtensionSpaces {
63
+ /** One record per declared pack, ordered by the toolchain's own space sort. */
64
+ seeded: SeededExtensionSpace[];
65
+ }
66
+ /**
67
+ * Refuse a declared pack that does not publish every required subpath.
68
+ *
69
+ * Runs before the generator writes `prisma.config.ts` and the Contract module,
70
+ * both of which import `<from>/control` and `<from>/pack`: refusing after the
71
+ * writes would leave the project carrying an unresolvable import.
72
+ *
73
+ * @throws {ExtensionSubpathError} when a declared pack lacks a required subpath.
74
+ */
75
+ export declare function verifyExtensionSubpaths(cwd: string, data: ContractData): void;
76
+ /**
77
+ * Materialise each declared extension pack's **Extension contract space**
78
+ * under the project's `migrations/` directory, between writing the Contract
79
+ * module and shelling to `prisma contract emit` (ADR-0065).
80
+ *
81
+ * For every entry in `data.extensions` this derives the `/pack`, `/control`
82
+ * and `/runtime` subpaths from the package name, refuses when one is absent,
83
+ * then hands the `/control` descriptors to the toolchain's public seed phase.
84
+ * That writes five files per pack — the migration package's `migration.json`
85
+ * and `ops.json`, `refs/head.json`, and the space's `contract.json` +
86
+ * `contract.d.ts` in the content-addressed snapshot store.
87
+ *
88
+ * The space's content is a function of the installed pack version alone, so
89
+ * the files are committed and regenerated on every `generate`: a pack upgrade
90
+ * shipping a new package shows up as a generate diff, and `db update` never
91
+ * meets a declared-but-unmigrated space.
92
+ *
93
+ * Seeding opens no database connection — it is a file copy out of the pack's
94
+ * own descriptor.
95
+ *
96
+ * Once the currently declared packs are seeded, every contract-space
97
+ * directory under `migrations/` is checked against them via the toolchain's
98
+ * own `verifyContractSpaces` — the same structural check a later `db init`/
99
+ * `db update` runs. A directory that is not the app space and does not
100
+ * belong to a currently declared pack is an **orphan**: most often a pack
101
+ * that was removed from `db.extensions` without removing its seeded space.
102
+ * This refuses with {@link OrphanExtensionSpaceError} naming every such
103
+ * directory, rather than leaving `generate` to exit 0 and the failure to
104
+ * surface later, out of the toolchain, as `db init`/`db update`'s own
105
+ * `orphanSpaceDir` refusal. Nothing under `migrations/` is ever deleted by
106
+ * this check — including the orphan's own migration packages and the
107
+ * content-addressed snapshot entries they reference — so a hand-authored
108
+ * migration directory this check does not recognise as a pack space (it
109
+ * carries its own `migration.json`, per the toolchain's own space/package
110
+ * distinction) is never at risk (#1192).
111
+ *
112
+ * Known limits:
113
+ * - The migrations directory is the toolchain's default, `<cwd>/migrations`.
114
+ * A project that overrides `migrations.dir` in a hand-edited
115
+ * `prisma.config.ts` would be seeded in the wrong place; the generated
116
+ * config never sets that key.
117
+ * - Only the `/control` subpath is loaded. `/pack` and `/runtime` are checked
118
+ * for resolvability and are otherwise the Contract module's and the
119
+ * generated client's business.
120
+ * - A pack whose `/control` descriptor ships no `contractSpace` is resolved
121
+ * and passed through; the toolchain reports nothing seeded for it.
122
+ * - Orphan detection is refuse-and-report only. Removing the directory (or
123
+ * re-adding the extension) is left to the user; there is no `--prune` flag.
124
+ * - Subpaths are resolved by reading the pack's `exports` under the `import`
125
+ * condition, which is how the generated artifacts reach them. Exotic maps
126
+ * (nested patterns, `imports`-style self-reference) are not covered.
127
+ *
128
+ * @param cwd - The project root, which is also the migrations directory's parent.
129
+ * @param data - The derived contract, read only for its declared extensions.
130
+ * @throws {ExtensionSubpathError} when a declared pack lacks a required subpath.
131
+ * @throws {ExtensionDescriptorError} when `/control` has no default descriptor.
132
+ * @throws {OrphanExtensionSpaceError} when a seeded space directory no longer
133
+ * matches any currently declared pack.
134
+ *
135
+ * @example
136
+ * ```typescript
137
+ * const { seeded } = await seedExtensionContractSpaces(cwd, deriveContract(config))
138
+ * // → [{ pack: 'pgvector', spaceId: 'pgvector', action: 'unchanged', migrationDirs: [] }]
139
+ * ```
140
+ */
141
+ export declare function seedExtensionContractSpaces(cwd: string, data: ContractData): Promise<SeededExtensionSpaces>;
142
+ //# sourceMappingURL=extension-spaces.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extension-spaces.d.ts","sourceRoot":"","sources":["../../src/generator/extension-spaces.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AASxD;;;;GAIG;AACH,qBAAa,qBAAsB,SAAQ,KAAK;IAE5C,6DAA6D;IAC7D,QAAQ,CAAC,IAAI,EAAE,MAAM;IACrB,gFAAgF;IAChF,QAAQ,CAAC,OAAO,EAAE,MAAM;IAJ1B;IACE,6DAA6D;IACpD,IAAI,EAAE,MAAM;IACrB,gFAAgF;IACvE,OAAO,EAAE,MAAM,EASzB;CACF;AAED;;;;;GAKG;AACH,qBAAa,wBAAyB,SAAQ,KAAK;IAE/C,6DAA6D;IAC7D,QAAQ,CAAC,IAAI,EAAE,MAAM;IACrB,2DAA2D;IAC3D,QAAQ,CAAC,OAAO,EAAE,MAAM;IAJ1B;IACE,6DAA6D;IACpD,IAAI,EAAE,MAAM;IACrB,2DAA2D;IAClD,OAAO,EAAE,MAAM,EASzB;CACF;AAED;;;;;;;GAOG;AACH,qBAAa,yBAA0B,SAAQ,KAAK;IAEhD,iFAAiF;IACjF,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE;IAFtC;IACE,iFAAiF;IACxE,QAAQ,EAAE,SAAS,MAA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