@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.
- package/README.md +116 -135
- package/dist/.build-hash +1 -0
- package/dist/commands/db.d.ts +23 -0
- package/dist/commands/db.d.ts.map +1 -0
- package/dist/commands/db.js +43 -0
- package/dist/commands/db.js.map +1 -0
- package/dist/commands/dev.d.ts +12 -1
- package/dist/commands/dev.d.ts.map +1 -1
- package/dist/commands/dev.js +519 -22
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/fk-renames.d.ts +14 -0
- package/dist/commands/fk-renames.d.ts.map +1 -0
- package/dist/commands/fk-renames.js +90 -0
- package/dist/commands/fk-renames.js.map +1 -0
- package/dist/commands/generate.d.ts +61 -4
- package/dist/commands/generate.d.ts.map +1 -1
- package/dist/commands/generate.js +225 -138
- package/dist/commands/generate.js.map +1 -1
- package/dist/commands/init.d.ts +6 -0
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +13 -2
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/junction-ids.d.ts +11 -0
- package/dist/commands/junction-ids.d.ts.map +1 -0
- package/dist/commands/junction-ids.js +81 -0
- package/dist/commands/junction-ids.js.map +1 -0
- package/dist/commands/migrate.d.ts +2 -0
- package/dist/commands/migrate.d.ts.map +1 -1
- package/dist/commands/migrate.js +47 -25
- package/dist/commands/migrate.js.map +1 -1
- package/dist/dev/app-runner.d.ts +70 -0
- package/dist/dev/app-runner.d.ts.map +1 -0
- package/dist/dev/app-runner.js +116 -0
- package/dist/dev/app-runner.js.map +1 -0
- package/dist/dev/control.d.ts +73 -0
- package/dist/dev/control.d.ts.map +1 -0
- package/dist/dev/control.js +251 -0
- package/dist/dev/control.js.map +1 -0
- package/dist/dev/staged-reconcile.d.ts +126 -0
- package/dist/dev/staged-reconcile.d.ts.map +1 -0
- package/dist/dev/staged-reconcile.js +289 -0
- package/dist/dev/staged-reconcile.js.map +1 -0
- package/dist/generator/config-load.d.ts +34 -0
- package/dist/generator/config-load.d.ts.map +1 -0
- package/dist/generator/config-load.js +64 -0
- package/dist/generator/config-load.js.map +1 -0
- package/dist/generator/context.d.ts +39 -3
- package/dist/generator/context.d.ts.map +1 -1
- package/dist/generator/context.js +245 -107
- package/dist/generator/context.js.map +1 -1
- package/dist/generator/contract-emit.d.ts +24 -0
- package/dist/generator/contract-emit.d.ts.map +1 -0
- package/dist/generator/contract-emit.js +34 -0
- package/dist/generator/contract-emit.js.map +1 -0
- package/dist/generator/contract-module.d.ts +39 -0
- package/dist/generator/contract-module.d.ts.map +1 -0
- package/dist/generator/contract-module.js +440 -0
- package/dist/generator/contract-module.js.map +1 -0
- package/dist/generator/extension-spaces.d.ts +142 -0
- package/dist/generator/extension-spaces.d.ts.map +1 -0
- package/dist/generator/extension-spaces.js +358 -0
- package/dist/generator/extension-spaces.js.map +1 -0
- package/dist/generator/index.d.ts +12 -4
- package/dist/generator/index.d.ts.map +1 -1
- package/dist/generator/index.js +7 -3
- package/dist/generator/index.js.map +1 -1
- package/dist/generator/lists.d.ts +6 -7
- package/dist/generator/lists.d.ts.map +1 -1
- package/dist/generator/lists.js +33 -13
- package/dist/generator/lists.js.map +1 -1
- package/dist/generator/output-paths.d.ts +62 -19
- package/dist/generator/output-paths.d.ts.map +1 -1
- package/dist/generator/output-paths.js +68 -30
- package/dist/generator/output-paths.js.map +1 -1
- package/dist/generator/prisma-cli.d.ts +61 -0
- package/dist/generator/prisma-cli.d.ts.map +1 -0
- package/dist/generator/prisma-cli.js +92 -0
- package/dist/generator/prisma-cli.js.map +1 -0
- package/dist/generator/prisma-config.d.ts +50 -31
- package/dist/generator/prisma-config.d.ts.map +1 -1
- package/dist/generator/prisma-config.js +72 -65
- package/dist/generator/prisma-config.js.map +1 -1
- package/dist/generator/source-text.d.ts +16 -0
- package/dist/generator/source-text.d.ts.map +1 -0
- package/dist/generator/source-text.js +35 -0
- package/dist/generator/source-text.js.map +1 -0
- package/dist/generator/tables.d.ts +5 -0
- package/dist/generator/tables.d.ts.map +1 -0
- package/dist/generator/tables.js +84 -0
- package/dist/generator/tables.js.map +1 -0
- package/dist/generator/types.d.ts +23 -3
- package/dist/generator/types.d.ts.map +1 -1
- package/dist/generator/types.js +291 -1171
- package/dist/generator/types.js.map +1 -1
- package/dist/index.js +20 -7
- package/dist/index.js.map +1 -1
- package/dist/mcp/lib/documentation-provider.d.ts.map +1 -1
- package/dist/mcp/lib/documentation-provider.js +44 -42
- package/dist/mcp/lib/documentation-provider.js.map +1 -1
- package/dist/mcp/lib/generators/feature-generator.d.ts.map +1 -1
- package/dist/mcp/lib/generators/feature-generator.js +124 -73
- package/dist/mcp/lib/generators/feature-generator.js.map +1 -1
- package/dist/mcp/lib/wizards/migration-wizard.js +6 -6
- package/dist/mcp/lib/wizards/migration-wizard.js.map +1 -1
- package/dist/mcp/lib/wizards/wizard-engine.d.ts.map +1 -1
- package/dist/mcp/lib/wizards/wizard-engine.js +3 -2
- package/dist/mcp/lib/wizards/wizard-engine.js.map +1 -1
- package/dist/mcp/server/stack-mcp-server.js +1 -1
- package/dist/migration/fk-renames.d.ts +39 -0
- package/dist/migration/fk-renames.d.ts.map +1 -0
- package/dist/migration/fk-renames.js +79 -0
- package/dist/migration/fk-renames.js.map +1 -0
- package/dist/migration/generators/migration-generator.d.ts +11 -0
- package/dist/migration/generators/migration-generator.d.ts.map +1 -1
- package/dist/migration/generators/migration-generator.js +83 -150
- package/dist/migration/generators/migration-generator.js.map +1 -1
- package/dist/migration/introspectors/prisma-introspector.d.ts.map +1 -1
- package/dist/migration/introspectors/prisma-introspector.js +1 -0
- package/dist/migration/introspectors/prisma-introspector.js.map +1 -1
- package/dist/migration/junction-ids.d.ts +15 -0
- package/dist/migration/junction-ids.d.ts.map +1 -0
- package/dist/migration/junction-ids.js +58 -0
- package/dist/migration/junction-ids.js.map +1 -0
- package/dist/migration/types.d.ts +2 -0
- package/dist/migration/types.d.ts.map +1 -1
- package/package.json +27 -15
- package/dist/generator/node-build.d.ts +0 -53
- package/dist/generator/node-build.d.ts.map +0 -1
- package/dist/generator/node-build.js +0 -280
- package/dist/generator/node-build.js.map +0 -1
- package/dist/generator/prisma.d.ts +0 -30
- package/dist/generator/prisma.d.ts.map +0 -1
- package/dist/generator/prisma.js +0 -422
- package/dist/generator/prisma.js.map +0 -1
|
@@ -1,85 +1,92 @@
|
|
|
1
1
|
import * as fs from 'fs';
|
|
2
2
|
import * as path from 'path';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
|
|
4
|
+
* The pack's `/control` subpath — the descriptor flavour `defineConfig` takes,
|
|
5
|
+
* as distinct from the `/pack` flavour the Contract module imports (ADR-0049).
|
|
6
|
+
*/
|
|
7
|
+
function controlSubpath(from) {
|
|
8
|
+
return `${from}/control`;
|
|
9
|
+
}
|
|
10
|
+
/** A single-quoted TypeScript string literal — Windows path separators included. */
|
|
11
|
+
function quote(value) {
|
|
12
|
+
return `'${value.replaceAll('\\', '\\\\').replaceAll("'", "\\'")}'`;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Render the project-root `prisma.config.ts` the Prisma 8 CLI reads.
|
|
16
|
+
*
|
|
17
|
+
* The file wires four things and nothing else: the Contract module's path, the
|
|
18
|
+
* directory the emitted artifacts land in beside it, each declared extension
|
|
19
|
+
* pack's control façade, and the database connection. It never imports
|
|
20
|
+
* `opensaas.config.ts` — the CLI evaluates this file for every command, and a
|
|
21
|
+
* config import would drag the app's plugins, hooks and environment reads onto
|
|
22
|
+
* that path (ADR-0040).
|
|
7
23
|
*
|
|
8
|
-
* The
|
|
9
|
-
*
|
|
10
|
-
*
|
|
24
|
+
* The connection is resolved here, so this is also where the project's `.env`
|
|
25
|
+
* is loaded: Prisma's config evaluation loads no dotenv of its own, and
|
|
26
|
+
* ADR-0040's ban on environment reads covers the Contract module, not this
|
|
27
|
+
* file.
|
|
11
28
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
29
|
+
* `definePrismaConfig` stamps the version marker the rc.12 CLI requires; the
|
|
30
|
+
* ORM's own options live under its `orm` section.
|
|
31
|
+
*
|
|
32
|
+
* @param data - The derived contract, read only for its declared extensions.
|
|
33
|
+
* @param contractModule - The Contract module's path relative to the project
|
|
34
|
+
* root, POSIX-separated (e.g. `./prisma/contract.ts`).
|
|
35
|
+
* @param outputDir - Where `contract.json` and `contract.d.ts` are written —
|
|
36
|
+
* the Contract module's own directory.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* writePrismaConfig(deriveContract(config), '/app/prisma.config.ts', {
|
|
41
|
+
* contractModule: './prisma/contract.ts',
|
|
42
|
+
* outputDir: './prisma',
|
|
43
|
+
* })
|
|
44
|
+
* ```
|
|
16
45
|
*/
|
|
17
|
-
export function generatePrismaConfig(
|
|
46
|
+
export function generatePrismaConfig(data, contractModule, outputDir, overrides = {}) {
|
|
18
47
|
const lines = [];
|
|
19
|
-
//
|
|
20
|
-
//
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
lines.push("import '
|
|
25
|
-
lines.push("import { defineConfig } from 'prisma/config'");
|
|
48
|
+
lines.push('// ⚠️ GENERATED FILE - DO NOT EDIT');
|
|
49
|
+
lines.push("// Generated by 'opensaas generate' from opensaas.config.ts.");
|
|
50
|
+
lines.push('');
|
|
51
|
+
lines.push("import { existsSync } from 'node:fs'");
|
|
52
|
+
lines.push("import { join } from 'node:path'");
|
|
53
|
+
lines.push("import { definePrismaConfig } from 'prisma/config'");
|
|
54
|
+
lines.push("import { defineConfig } from '@prisma/orm-postgres/config'");
|
|
55
|
+
lines.push("import { findDatabaseUrl } from '@opensaas/stack-core'");
|
|
56
|
+
for (const extension of data.extensions) {
|
|
57
|
+
lines.push(`import ${extension.name} from ${quote(controlSubpath(extension.from))}`);
|
|
58
|
+
}
|
|
26
59
|
lines.push('');
|
|
27
|
-
lines.push('//
|
|
28
|
-
lines.push('//
|
|
29
|
-
|
|
30
|
-
lines.push('
|
|
31
|
-
lines.push('
|
|
60
|
+
lines.push('// The Prisma CLI evaluates this file without loading a .env of its own, and');
|
|
61
|
+
lines.push('// `process.loadEnvFile` throws when the file is absent.');
|
|
62
|
+
const envDir = overrides.envDir === undefined ? 'import.meta.dirname' : quote(overrides.envDir);
|
|
63
|
+
lines.push(`const envFile = join(${envDir}, '.env')`);
|
|
64
|
+
lines.push('if (existsSync(envFile)) process.loadEnvFile(envFile)');
|
|
32
65
|
lines.push('');
|
|
33
|
-
lines.push('export default
|
|
34
|
-
lines.push(
|
|
35
|
-
lines.push(
|
|
36
|
-
lines.push(
|
|
37
|
-
|
|
38
|
-
|
|
66
|
+
lines.push('export default definePrismaConfig({');
|
|
67
|
+
lines.push(' orm: defineConfig({');
|
|
68
|
+
lines.push(` contract: ${quote(contractModule)},`);
|
|
69
|
+
lines.push(` output: ${quote(outputDir)},`);
|
|
70
|
+
const packs = data.extensions.map((extension) => extension.name).join(', ');
|
|
71
|
+
lines.push(` extensions: [${packs}],`);
|
|
72
|
+
if (overrides.migrationsDir !== undefined) {
|
|
73
|
+
lines.push(` migrations: { dir: ${quote(overrides.migrationsDir)} },`);
|
|
39
74
|
}
|
|
40
|
-
lines.push('
|
|
75
|
+
lines.push(' db: { connection: findDatabaseUrl() },');
|
|
76
|
+
lines.push(' }),');
|
|
41
77
|
lines.push('})');
|
|
42
78
|
lines.push('');
|
|
43
79
|
return lines.join('\n');
|
|
44
80
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
* Only the `url` key is generator-managed; every other entry in the block
|
|
51
|
-
* (e.g. `shadowDatabaseUrl`) is treated as host-owned and returned verbatim
|
|
52
|
-
* for re-emission by {@link generatePrismaConfig}.
|
|
53
|
-
*
|
|
54
|
-
* This is a lightweight line-based extraction, not a TypeScript parser: it
|
|
55
|
-
* assumes the `datasource` block contains flat, single-line `key: value,`
|
|
56
|
-
* entries with no nested braces, which matches every entry this generator or
|
|
57
|
-
* documented host customization emits.
|
|
58
|
-
*/
|
|
59
|
-
export function extractExtraDatasourceLines(existingContent) {
|
|
60
|
-
const match = existingContent.match(/datasource:\s*\{([^}]*)\}/);
|
|
61
|
-
if (!match) {
|
|
62
|
-
return [];
|
|
63
|
-
}
|
|
64
|
-
return match[1]
|
|
65
|
-
.split('\n')
|
|
66
|
-
.map((line) => line.trim())
|
|
67
|
-
.filter((line) => line.length > 0 && !line.startsWith('url:'));
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* If a `prisma.config.ts` already exists at `outputPath`, its `datasource`
|
|
71
|
-
* block is read first so host-added keys the generator does not manage (e.g.
|
|
72
|
-
* `shadowDatabaseUrl`) survive the rewrite — see {@link extractExtraDatasourceLines}.
|
|
73
|
-
*/
|
|
74
|
-
export function writePrismaConfig(config, outputPath, schemaPath) {
|
|
75
|
-
const extraDatasourceLines = fs.existsSync(outputPath)
|
|
76
|
-
? extractExtraDatasourceLines(fs.readFileSync(outputPath, 'utf-8'))
|
|
77
|
-
: [];
|
|
78
|
-
const prismaConfig = generatePrismaConfig(config, schemaPath, extraDatasourceLines);
|
|
81
|
+
export function writePrismaConfig(data, outputPath, references) {
|
|
82
|
+
const content = generatePrismaConfig(data, references.contractModule, references.outputDir, {
|
|
83
|
+
migrationsDir: references.migrationsDir,
|
|
84
|
+
envDir: references.envDir,
|
|
85
|
+
});
|
|
79
86
|
const dir = path.dirname(outputPath);
|
|
80
87
|
if (!fs.existsSync(dir)) {
|
|
81
88
|
fs.mkdirSync(dir, { recursive: true });
|
|
82
89
|
}
|
|
83
|
-
fs.writeFileSync(outputPath,
|
|
90
|
+
fs.writeFileSync(outputPath, content, 'utf-8');
|
|
84
91
|
}
|
|
85
92
|
//# sourceMappingURL=prisma-config.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prisma-config.js","sourceRoot":"","sources":["../../src/generator/prisma-config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"prisma-config.js","sourceRoot":"","sources":["../../src/generator/prisma-config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AACxB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAG5B;;;GAGG;AACH,SAAS,cAAc,CAAC,IAAY;IAClC,OAAO,GAAG,IAAI,UAAU,CAAA;AAC1B,CAAC;AAED,oFAAoF;AACpF,SAAS,KAAK,CAAC,KAAa;IAC1B,OAAO,IAAI,KAAK,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,CAAA;AACrE,CAAC;AAqBD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,UAAU,oBAAoB,CAClC,IAAkB,EAClB,cAAsB,EACtB,SAAiB,EACjB,SAAS,GAAkC,EAAE;IAE7C,MAAM,KAAK,GAAa,EAAE,CAAA;IAE1B,KAAK,CAAC,IAAI,CAAC,qCAAqC,CAAC,CAAA;IACjD,KAAK,CAAC,IAAI,CAAC,8DAA8D,CAAC,CAAA;IAC1E,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IACd,KAAK,CAAC,IAAI,CAAC,sCAAsC,CAAC,CAAA;IAClD,KAAK,CAAC,IAAI,CAAC,kCAAkC,CAAC,CAAA;IAC9C,KAAK,CAAC,IAAI,CAAC,oDAAoD,CAAC,CAAA;IAChE,KAAK,CAAC,IAAI,CAAC,4DAA4D,CAAC,CAAA;IACxE,KAAK,CAAC,IAAI,CAAC,wDAAwD,CAAC,CAAA;IACpE,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;QACxC,KAAK,CAAC,IAAI,CAAC,UAAU,SAAS,CAAC,IAAI,SAAS,KAAK,CAAC,cAAc,CAAC,SAAS,CAAC,IAAI,CAAC,C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AAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAChB,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IAEd,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACzB,CAAC;AAED,MAAM,UAAU,iBAAiB,CAC/B,IAAkB,EAClB,UAAkB,EAClB,UAAyF;IAEzF,MAAM,OAAO,GAAG,oBAAoB,CAAC,IAAI,EAAE,UAAU,CAAC,cAAc,EAAE,UAAU,CAAC,SAAS,EAAE;QAC1F,aAAa,EAAE,UAAU,CAAC,aAAa;QACvC,MAAM,EAAE,UAAU,CAAC,MAAM;KAC1B,CAAC,CAAA;IAEF,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;IACpC,IAAI,CAAC,EAAE,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,16 @@
|
|
|
1
|
+
import type { OpenSaasConfig } from '@opensaas/stack-core';
|
|
2
|
+
export declare const IDENTIFIER: RegExp;
|
|
3
|
+
/**
|
|
4
|
+
* A single-quoted TypeScript string, matching the repo's own source style.
|
|
5
|
+
*
|
|
6
|
+
* All four ECMAScript LineTerminators are escaped: an unescaped one inside a
|
|
7
|
+
* single-quoted literal ends it, so a `\r` or a U+2028/U+2029 in a user's
|
|
8
|
+
* value would otherwise write a module that will not parse. This is not
|
|
9
|
+
* `JSON.stringify`, which leaves U+2028 and U+2029 raw — legal in JSON,
|
|
10
|
+
* fatal in a JavaScript string literal.
|
|
11
|
+
*/
|
|
12
|
+
export declare function quote(value: string): string;
|
|
13
|
+
/** A TypeScript object key, quoted only when it is not a plain identifier. */
|
|
14
|
+
export declare function key(name: string): string;
|
|
15
|
+
export declare function assertFieldKeysAreIdentifiers(config: OpenSaasConfig): void;
|
|
16
|
+
//# sourceMappingURL=source-text.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source-text.d.ts","sourceRoot":"","sources":["../../src/generator/source-text.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAE1D,eAAO,MAAM,UAAU,QAA+B,CAAA;AAEtD;;;;;;;;GAQG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAS3C;AAED,8EAA8E;AAC9E,wBAAgB,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAExC;AAED,wBAAgB,6BAA6B,CAAC,MAAM,EAAE,cAAc,GAAG,IAAI,CAW1E"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export const IDENTIFIER = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
|
|
2
|
+
/**
|
|
3
|
+
* A single-quoted TypeScript string, matching the repo's own source style.
|
|
4
|
+
*
|
|
5
|
+
* All four ECMAScript LineTerminators are escaped: an unescaped one inside a
|
|
6
|
+
* single-quoted literal ends it, so a `\r` or a U+2028/U+2029 in a user's
|
|
7
|
+
* value would otherwise write a module that will not parse. This is not
|
|
8
|
+
* `JSON.stringify`, which leaves U+2028 and U+2029 raw — legal in JSON,
|
|
9
|
+
* fatal in a JavaScript string literal.
|
|
10
|
+
*/
|
|
11
|
+
export function quote(value) {
|
|
12
|
+
const escaped = value
|
|
13
|
+
.replace(/\\/g, '\\\\')
|
|
14
|
+
.replace(/'/g, "\\'")
|
|
15
|
+
.replace(/\n/g, '\\n')
|
|
16
|
+
.replace(/\r/g, '\\r')
|
|
17
|
+
.replace(/\u2028/g, '\\u2028')
|
|
18
|
+
.replace(/\u2029/g, '\\u2029');
|
|
19
|
+
return `'${escaped}'`;
|
|
20
|
+
}
|
|
21
|
+
/** A TypeScript object key, quoted only when it is not a plain identifier. */
|
|
22
|
+
export function key(name) {
|
|
23
|
+
return IDENTIFIER.test(name) ? name : quote(name);
|
|
24
|
+
}
|
|
25
|
+
export function assertFieldKeysAreIdentifiers(config) {
|
|
26
|
+
for (const [listName, listConfig] of Object.entries(config.lists)) {
|
|
27
|
+
for (const fieldName of Object.keys(listConfig.fields)) {
|
|
28
|
+
if (!IDENTIFIER.test(fieldName)) {
|
|
29
|
+
throw new Error(`List "${listName}", field "${fieldName}": a field key must be a valid ` +
|
|
30
|
+
'JavaScript identifier (letters, digits, "_" and "$", not starting with a digit).');
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=source-text.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source-text.js","sourceRoot":"","sources":["../../src/generator/source-text.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,UAAU,GAAG,4BAA4B,CAAA;AAEtD;;;;;;;;GAQG;AACH,MAAM,UAAU,KAAK,CAAC,KAAa;IACjC,MAAM,OAAO,GAAG,KAAK;SAClB,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC;SACtB,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC;SACpB,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC;SACrB,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC;SACrB,OAAO,CAAC,SAAS,EAAE,SAAS,CAAC;SAC7B,OAAO,CAAC,SAAS,EAAE,SAAS,CAAC,CAAA;IAChC,OAAO,IAAI,OAAO,GAAG,CAAA;AACvB,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,GAAG,CAAC,IAAY;IAC9B,OAAO,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;AACnD,CAAC;AAED,MAAM,UAAU,6BAA6B,CAAC,MAAsB;IAClE,KAAK,MAAM,CAAC,QAAQ,EAAE,UAAU,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QAClE,KAAK,MAAM,SAAS,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;YACvD,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;gBAChC,MAAM,IAAI,KAAK,CACb,SAAS,QAAQ,aAAa,SAAS,iCAAiC;oBACtE,kFAAkF,CACrF,CAAA;YACH,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { GeneratedTables } from '@opensaas/stack-core';
|
|
2
|
+
/** The bundle's `tables.ts`: both emitted tables as literal, erasable TypeScript. */
|
|
3
|
+
export declare function generateTables(tables: GeneratedTables): string;
|
|
4
|
+
export declare function writeTables(tables: GeneratedTables, outputPath: string): void;
|
|
5
|
+
//# sourceMappingURL=tables.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tables.d.ts","sourceRoot":"","sources":["../../src/generator/tables.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAGV,eAAe,EAGhB,MAAM,sBAAsB,CAAA;AA+D7B,qFAAqF;AACrF,wBAAgB,cAAc,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM,CAkB9D;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,CAO7E"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
/**
|
|
4
|
+
* Render `<opensaasDir>/tables.ts` — the emitted dependency-set table
|
|
5
|
+
* (ADR-0051) and unique-constraint map (ADR-0042).
|
|
6
|
+
*
|
|
7
|
+
* They sit in the bundle rather than in the Contract module: ADR-0040 makes
|
|
8
|
+
* that artifact standalone, fully literal and Prisma's, and neither table is
|
|
9
|
+
* Prisma's data. The generated context imports this module and hands both to
|
|
10
|
+
* the runtime, which is the door ADR-0051 names — the engine widens a read
|
|
11
|
+
* from an emitted fact instead of walking the config, and a unique violation
|
|
12
|
+
* resolves to per-field messages without parsing prose.
|
|
13
|
+
*
|
|
14
|
+
* Every key is emitted in sorted order so a regenerate over an unchanged
|
|
15
|
+
* config is byte-identical.
|
|
16
|
+
*/
|
|
17
|
+
function renderStringArray(values) {
|
|
18
|
+
return `[${values.map((value) => JSON.stringify(value)).join(', ')}]`;
|
|
19
|
+
}
|
|
20
|
+
function renderListDependencies(listKey, entry) {
|
|
21
|
+
const fieldKeys = Object.keys(entry.fields).sort();
|
|
22
|
+
const lines = [
|
|
23
|
+
` ${JSON.stringify(listKey)}: {`,
|
|
24
|
+
` systemFields: ${renderStringArray(entry.systemFields)},`,
|
|
25
|
+
];
|
|
26
|
+
if (fieldKeys.length === 0) {
|
|
27
|
+
lines.push(' fields: {},', ' },');
|
|
28
|
+
return lines.join('\n');
|
|
29
|
+
}
|
|
30
|
+
lines.push(' fields: {');
|
|
31
|
+
for (const fieldKey of fieldKeys) {
|
|
32
|
+
const set = entry.fields[fieldKey];
|
|
33
|
+
lines.push(` ${JSON.stringify(fieldKey)}: { columns: ${renderStringArray(set.columns)}, relations: ${renderStringArray(set.relations)} },`);
|
|
34
|
+
}
|
|
35
|
+
lines.push(' },', ' },');
|
|
36
|
+
return lines.join('\n');
|
|
37
|
+
}
|
|
38
|
+
function renderDependencyTable(table) {
|
|
39
|
+
const lines = ['export const dependencyTable: DependencyTable = {'];
|
|
40
|
+
for (const listKey of Object.keys(table).sort()) {
|
|
41
|
+
lines.push(renderListDependencies(listKey, table[listKey]));
|
|
42
|
+
}
|
|
43
|
+
lines.push('}');
|
|
44
|
+
return lines.join('\n');
|
|
45
|
+
}
|
|
46
|
+
function renderConstraint(name, entry) {
|
|
47
|
+
return ` ${JSON.stringify(name)}: { list: ${JSON.stringify(entry.list)}, fields: ${renderStringArray(entry.fields)} },`;
|
|
48
|
+
}
|
|
49
|
+
function renderConstraintMap(map) {
|
|
50
|
+
const lines = ['export const constraintMap: ConstraintMap = {'];
|
|
51
|
+
for (const name of Object.keys(map).sort()) {
|
|
52
|
+
lines.push(renderConstraint(name, map[name]));
|
|
53
|
+
}
|
|
54
|
+
lines.push('}');
|
|
55
|
+
return lines.join('\n');
|
|
56
|
+
}
|
|
57
|
+
/** The bundle's `tables.ts`: both emitted tables as literal, erasable TypeScript. */
|
|
58
|
+
export function generateTables(tables) {
|
|
59
|
+
return `/**
|
|
60
|
+
* Auto-generated dependency-set table and unique-constraint map
|
|
61
|
+
*
|
|
62
|
+
* DO NOT EDIT - This file is automatically generated by 'pnpm generate'
|
|
63
|
+
*
|
|
64
|
+
* \`dependencyTable\` is each computed field's one-hop \`needs\` set plus each
|
|
65
|
+
* list's actual system fields (ADR-0051). \`constraintMap\` names every unique
|
|
66
|
+
* constraint the generator emitted, so a unique violation resolves to
|
|
67
|
+
* per-field messages without parsing prose (ADR-0042).
|
|
68
|
+
*/
|
|
69
|
+
|
|
70
|
+
import type { ConstraintMap, DependencyTable } from '@opensaas/stack-core'
|
|
71
|
+
|
|
72
|
+
${renderDependencyTable(tables.dependencies)}
|
|
73
|
+
|
|
74
|
+
${renderConstraintMap(tables.constraints)}
|
|
75
|
+
`;
|
|
76
|
+
}
|
|
77
|
+
export function writeTables(tables, outputPath) {
|
|
78
|
+
const dir = path.dirname(outputPath);
|
|
79
|
+
if (!fs.existsSync(dir)) {
|
|
80
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
81
|
+
}
|
|
82
|
+
fs.writeFileSync(outputPath, generateTables(tables), 'utf-8');
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=tables.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tables.js","sourceRoot":"","sources":["../../src/generator/tables.ts"],"names":[],"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CAAC,WAAW,CAAC;CACxC,CAAA;AACD,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,MAAuB,EAAE,UAAkB;IACrE,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;IACpC,IAAI,CAAC,EAAE,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,cAAc,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,CAAA;AAC/D,CAAC"}
|
|
@@ -1,4 +1,24 @@
|
|
|
1
|
-
import type { OpenSaasConfig } from '@opensaas/stack-core';
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import type { DependencyTable, FieldConfig, OpenSaasConfig } from '@opensaas/stack-core';
|
|
2
|
+
/**
|
|
3
|
+
* Each computed field's declared dependency set, read off the one table
|
|
4
|
+
* `deriveDependencyTable` produced (ADR-0051). The runtime widens a read from
|
|
5
|
+
* that table and the `Remainder` renders the same rows as types, so the two
|
|
6
|
+
* cannot disagree about which columns a hook is handed — including the
|
|
7
|
+
* foreign-key column a declared relation implies on the owning side.
|
|
8
|
+
*
|
|
9
|
+
* Only a COMPUTED field's row becomes a type — by `isComputedField`, the same
|
|
10
|
+
* flag-or-descriptor rule `generateRemainderEntry` sorts a field into
|
|
11
|
+
* `computed` by (issue #1531). `field-visibility.ts` builds the narrowed
|
|
12
|
+
* `computedFieldItem` for a computed field's `resolveOutput` and hands a
|
|
13
|
+
* stored field's the whole `workingItem`, which carries the field's own
|
|
14
|
+
* column — a column `NeedsRow`'s `Pick` does not name. So a `NeedsItem` for a
|
|
15
|
+
* stored field would reject a read that always succeeds. The table keeps those
|
|
16
|
+
* rows because the widening still pays for their declarations.
|
|
17
|
+
*
|
|
18
|
+
* `never` for a field whose hook declares nothing: `NeedsRow` still adds the
|
|
19
|
+
* list's system fields, which is exactly what such a hook receives.
|
|
20
|
+
*/
|
|
21
|
+
export declare function needsEntries(listName: string, fields: Record<string, FieldConfig>, dependencies: DependencyTable, config: OpenSaasConfig): Array<[string, string]>;
|
|
22
|
+
export declare function generateTypes(config: OpenSaasConfig, dependencies: DependencyTable): string;
|
|
23
|
+
export declare function writeTypes(config: OpenSaasConfig, outputPath: string, dependencies: DependencyTable): void;
|
|
4
24
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/generator/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/generator/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,eAAe,EACf,WAAW,EACX,cAAc,EACf,MAAM,sBAAsB,CAAA;AAgI7B;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,EACnC,YAAY,EAAE,eAAe,EAC7B,MAAM,EAAE,cAAc,GACrB,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAazB;AAwJD,wBAAgB,aAAa,CAAC,MAAM,EAAE,cAAc,EAAE,YAAY,EAAE,eAAe,GAAG,MAAM,CAoG3F;AAMD,wBAAgB,UAAU,CACxB,MAAM,EAAE,cAAc,EACtB,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,eAAe,GAC5B,IAAI,CASN"}
|