@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
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
import { createHash } from 'crypto';
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
import * as path from 'path';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { OPENSAAS_FILES, runPrismaCli, STAGED_ROOT_PRISMA_CONFIG } from '../generator/index.js';
|
|
6
|
+
/** Where a staged generation lives, inside the Generated bundle. */
|
|
7
|
+
export const STAGING_DIR = path.join('.opensaas', 'staged');
|
|
8
|
+
const operationSchema = z.object({
|
|
9
|
+
label: z.string(),
|
|
10
|
+
operationClass: z.string(),
|
|
11
|
+
});
|
|
12
|
+
const askedSubjectSchema = z.object({ text: z.string() });
|
|
13
|
+
const resultEnvelopeSchema = z.object({
|
|
14
|
+
kind: z.literal('result'),
|
|
15
|
+
envelope: z.object({
|
|
16
|
+
result: z.object({
|
|
17
|
+
dataLoss: z.array(askedSubjectSchema).optional(),
|
|
18
|
+
accessWidening: z.array(askedSubjectSchema).optional(),
|
|
19
|
+
plan: z
|
|
20
|
+
.object({
|
|
21
|
+
operations: z.array(operationSchema).optional(),
|
|
22
|
+
preview: z
|
|
23
|
+
.object({ statements: z.array(z.object({ text: z.string() })).optional() })
|
|
24
|
+
.optional(),
|
|
25
|
+
})
|
|
26
|
+
.optional(),
|
|
27
|
+
}),
|
|
28
|
+
}),
|
|
29
|
+
});
|
|
30
|
+
/**
|
|
31
|
+
* The plan out of a `--json` run. The CLI streams newline-delimited progress
|
|
32
|
+
* envelopes and closes with the result one, so the last parseable `result`
|
|
33
|
+
* line is the answer; anything the CLI wrote to stderr is not searched, which
|
|
34
|
+
* is why only stdout is read here.
|
|
35
|
+
*/
|
|
36
|
+
function readPlan(stdout) {
|
|
37
|
+
let plan;
|
|
38
|
+
for (const line of stdout.split('\n')) {
|
|
39
|
+
const trimmed = line.trim();
|
|
40
|
+
if (trimmed.length === 0 || !trimmed.startsWith('{'))
|
|
41
|
+
continue;
|
|
42
|
+
let parsed;
|
|
43
|
+
try {
|
|
44
|
+
parsed = JSON.parse(trimmed);
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
const envelope = resultEnvelopeSchema.safeParse(parsed);
|
|
50
|
+
if (!envelope.success)
|
|
51
|
+
continue;
|
|
52
|
+
const { result } = envelope.data.envelope;
|
|
53
|
+
const operations = result.plan?.operations ?? [];
|
|
54
|
+
const dataLoss = (result.dataLoss ?? []).map((subject) => subject.text);
|
|
55
|
+
const accessWidening = (result.accessWidening ?? []).map((subject) => subject.text);
|
|
56
|
+
plan = {
|
|
57
|
+
operations,
|
|
58
|
+
statements: (result.plan?.preview?.statements ?? []).map((statement) => statement.text),
|
|
59
|
+
dataLoss,
|
|
60
|
+
accessWidening,
|
|
61
|
+
destructive: dataLoss.length > 0 ||
|
|
62
|
+
accessWidening.length > 0 ||
|
|
63
|
+
operations.some((operation) => operation.operationClass === 'destructive'),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
return plan;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Run `prisma db update` against a staged generation and report what it
|
|
70
|
+
* planned.
|
|
71
|
+
*
|
|
72
|
+
* @param configPath - The staged Prisma config, which names the staged
|
|
73
|
+
* Contract module and the project's own migrations directory.
|
|
74
|
+
* @param options.dryRun - Plan without applying, which is how a destructive
|
|
75
|
+
* change is discovered before anything is promoted.
|
|
76
|
+
* @param options.consent - A dry run's plan whose data loss and access
|
|
77
|
+
* widening this run may carry out, passed to Prisma as `--delete` and
|
|
78
|
+
* `--allow`. A question the plan did not list stays unanswered, so a plan
|
|
79
|
+
* that changed since the dry run fails rather than applying unasked.
|
|
80
|
+
*/
|
|
81
|
+
export async function planDatabaseUpdate(cwd, configPath, options = {}) {
|
|
82
|
+
const args = ['db', 'update', '--config', configPath, '--json', '--no-interactive'];
|
|
83
|
+
if (options.dryRun === true)
|
|
84
|
+
args.push('--dry-run');
|
|
85
|
+
for (const subject of options.consent?.dataLoss ?? [])
|
|
86
|
+
args.push('--delete', subject);
|
|
87
|
+
for (const subject of options.consent?.accessWidening ?? [])
|
|
88
|
+
args.push('--allow', subject);
|
|
89
|
+
const run = await runPrismaCli(cwd, args);
|
|
90
|
+
if (run.exitCode !== 0)
|
|
91
|
+
return { ok: false, failure: { exitCode: run.exitCode, output: run.output } };
|
|
92
|
+
const plan = readPlan(run.stdout);
|
|
93
|
+
if (plan === undefined) {
|
|
94
|
+
return { ok: false, failure: { exitCode: run.exitCode, output: run.output } };
|
|
95
|
+
}
|
|
96
|
+
return { ok: true, plan };
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* The migrations graph's named refs, as they stand.
|
|
100
|
+
*
|
|
101
|
+
* The loop owns these: `db update` advances the `db` ref to the contract it
|
|
102
|
+
* just reached, so a plan the loop discards has to leave the refs where it
|
|
103
|
+
* found them — otherwise the discarded schema's ref shadows the source
|
|
104
|
+
* contract on the next plan (ADR-0063).
|
|
105
|
+
*/
|
|
106
|
+
export function snapshotMigrationRefs(cwd) {
|
|
107
|
+
const migrationsDir = path.join(cwd, 'migrations');
|
|
108
|
+
if (!fs.existsSync(migrationsDir))
|
|
109
|
+
return [];
|
|
110
|
+
const snapshots = [];
|
|
111
|
+
for (const space of fs.readdirSync(migrationsDir, { withFileTypes: true })) {
|
|
112
|
+
if (!space.isDirectory())
|
|
113
|
+
continue;
|
|
114
|
+
const refsDir = path.join(migrationsDir, space.name, 'refs');
|
|
115
|
+
if (!fs.existsSync(refsDir))
|
|
116
|
+
continue;
|
|
117
|
+
for (const entry of fs.readdirSync(refsDir)) {
|
|
118
|
+
const file = path.join(refsDir, entry);
|
|
119
|
+
snapshots.push({ file, contents: fs.readFileSync(file, 'utf-8') });
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return snapshots;
|
|
123
|
+
}
|
|
124
|
+
/** The space directory a `refs/*.json` path belongs to. */
|
|
125
|
+
function spaceOf(file) {
|
|
126
|
+
return path.basename(path.dirname(path.dirname(file)));
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Puts every snapshotted ref back, and removes any extra ref the run
|
|
130
|
+
* introduced into a space the snapshot already knew about.
|
|
131
|
+
*
|
|
132
|
+
* A space with no snapshotted ref at all was seeded by this run's own
|
|
133
|
+
* `generate` — a newly declared pack reaching `migrations/` for the first
|
|
134
|
+
* time — and is left untouched. That ref is not a discarded run's leftover;
|
|
135
|
+
* it is the new space's only record of itself, and deleting it strands the
|
|
136
|
+
* migration package `seedExtensionContractSpaces` just wrote refless (#1226).
|
|
137
|
+
*
|
|
138
|
+
* "No snapshotted ref" is a proxy for "space didn't exist yet," not a
|
|
139
|
+
* directly-checked fact: a space that existed before this run but already had
|
|
140
|
+
* no ref (already broken, by some other cause) reads the same way, and this
|
|
141
|
+
* run's own ref for it survives the prune too. That is no worse than the
|
|
142
|
+
* space already being broken.
|
|
143
|
+
*/
|
|
144
|
+
export function restoreMigrationRefs(cwd, snapshots) {
|
|
145
|
+
const known = new Set(snapshots.map((snapshot) => snapshot.file));
|
|
146
|
+
const knownSpaces = new Set(snapshots.map((snapshot) => spaceOf(snapshot.file)));
|
|
147
|
+
for (const snapshot of snapshotMigrationRefs(cwd)) {
|
|
148
|
+
if (known.has(snapshot.file))
|
|
149
|
+
continue;
|
|
150
|
+
if (!knownSpaces.has(spaceOf(snapshot.file)))
|
|
151
|
+
continue;
|
|
152
|
+
fs.rmSync(snapshot.file, { force: true });
|
|
153
|
+
}
|
|
154
|
+
for (const snapshot of snapshots) {
|
|
155
|
+
fs.mkdirSync(path.dirname(snapshot.file), { recursive: true });
|
|
156
|
+
fs.writeFileSync(snapshot.file, snapshot.contents, 'utf-8');
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
function hasAppMigrationPackage(cwd) {
|
|
160
|
+
const appDir = path.join(cwd, 'migrations', 'app');
|
|
161
|
+
if (!fs.existsSync(appDir))
|
|
162
|
+
return false;
|
|
163
|
+
return fs
|
|
164
|
+
.readdirSync(appDir, { withFileTypes: true })
|
|
165
|
+
.some((entry) => entry.isDirectory() && fs.existsSync(path.join(appDir, entry.name, 'migration.json')));
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Restores the refs after an applied reconcile, unless the app space has no
|
|
169
|
+
* migration package yet: then Prisma's `db` ref write stays, because
|
|
170
|
+
* `migration plan --name init` derives its baseline from it (ADR-0065).
|
|
171
|
+
*/
|
|
172
|
+
export function restoreRefsAfterReconcile(cwd, snapshots) {
|
|
173
|
+
if (!hasAppMigrationPackage(cwd))
|
|
174
|
+
return;
|
|
175
|
+
restoreMigrationRefs(cwd, snapshots.filter((snapshot) => spaceOf(snapshot.file) === 'app'));
|
|
176
|
+
}
|
|
177
|
+
/** Thrown when promotion stopped part-way, leaving the live bundle split. */
|
|
178
|
+
export class PartialPromotionError extends Error {
|
|
179
|
+
/** The live files that already carry the staged generation. */
|
|
180
|
+
promoted;
|
|
181
|
+
/** The live file the failure stopped on, still carrying the previous generation. */
|
|
182
|
+
failedOn;
|
|
183
|
+
constructor(promoted, failedOn, cause) {
|
|
184
|
+
super(`The database was updated, but promoting the staged generation stopped at ${failedOn}. ` +
|
|
185
|
+
`${promoted.length} file(s) already carry the new contract, so the project is split ` +
|
|
186
|
+
'across two contracts. Re-run `opensaas generate` to rewrite the whole bundle from ' +
|
|
187
|
+
`the current config. Underlying failure: ${cause instanceof Error ? cause.message : String(cause)}`);
|
|
188
|
+
this.name = 'PartialPromotionError';
|
|
189
|
+
this.promoted = promoted;
|
|
190
|
+
this.failedOn = failedOn;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Copies through a sibling temp name and renames into place, so the app's dev
|
|
195
|
+
* server never reads a half-written file: a rename within one filesystem is
|
|
196
|
+
* atomic, a `copyFileSync` onto a watched path is not.
|
|
197
|
+
*/
|
|
198
|
+
function swapIntoPlace(from, to) {
|
|
199
|
+
fs.mkdirSync(path.dirname(to), { recursive: true });
|
|
200
|
+
const staging = `${to}.promoting-${process.pid}`;
|
|
201
|
+
try {
|
|
202
|
+
fs.copyFileSync(from, staging);
|
|
203
|
+
fs.renameSync(staging, to);
|
|
204
|
+
}
|
|
205
|
+
catch (error) {
|
|
206
|
+
fs.rmSync(staging, { force: true });
|
|
207
|
+
throw error;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Move a staged generation into the places the app reads: the Contract module
|
|
212
|
+
* and its emitted artifacts, then the whole bundle directory — enumerating the
|
|
213
|
+
* bundle would strand the extra files a plugin's `afterGenerate` writes there.
|
|
214
|
+
* Called only once the database carries the schema they describe.
|
|
215
|
+
*
|
|
216
|
+
* Each file lands atomically. The set of them does not: the filesystem offers
|
|
217
|
+
* no multi-file commit, and a mid-promotion reader from another process can
|
|
218
|
+
* observe a mix of old and new artifacts (ADR-0072). This order is a stated,
|
|
219
|
+
* not incidental, response to that:
|
|
220
|
+
*
|
|
221
|
+
* - `tables.ts` is derived from the same computation as the Contract module
|
|
222
|
+
* (ADR-0051), so it lands immediately after the contract artifacts rather
|
|
223
|
+
* than wherever the bundle directory's unordered `readdirSync` happens to
|
|
224
|
+
* place it — narrowing, not closing, the window in which the two could
|
|
225
|
+
* disagree.
|
|
226
|
+
* - `prisma.config.ts` lands **last**, so its landing is the one signal that
|
|
227
|
+
* the whole set is in place — the ordering an outside observer's own
|
|
228
|
+
* end-of-promotion signal (a log line printed after this function returns,
|
|
229
|
+
* for instance) can rely on without inspecting anything else.
|
|
230
|
+
*
|
|
231
|
+
* A failure part-way through throws {@link PartialPromotionError} naming the
|
|
232
|
+
* split rather than a bare copy error.
|
|
233
|
+
*
|
|
234
|
+
* @throws {PartialPromotionError} when promotion stops after the first file.
|
|
235
|
+
*/
|
|
236
|
+
export function promoteStagedGeneration(staged, live, stagingDir) {
|
|
237
|
+
const moves = [
|
|
238
|
+
[staged.contractModule, live.contractModule],
|
|
239
|
+
[staged.contractJson, live.contractJson],
|
|
240
|
+
[staged.contractTypes, live.contractTypes],
|
|
241
|
+
[staged.tables, live.tables],
|
|
242
|
+
];
|
|
243
|
+
if (fs.existsSync(staged.opensaasDir)) {
|
|
244
|
+
for (const entry of fs.readdirSync(staged.opensaasDir, { withFileTypes: true })) {
|
|
245
|
+
if (!entry.isFile() || entry.name === OPENSAAS_FILES.tables)
|
|
246
|
+
continue;
|
|
247
|
+
moves.push([
|
|
248
|
+
path.join(staged.opensaasDir, entry.name),
|
|
249
|
+
path.join(live.opensaasDir, entry.name),
|
|
250
|
+
]);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
const rootPrismaConfig = path.join(stagingDir, STAGED_ROOT_PRISMA_CONFIG);
|
|
254
|
+
if (fs.existsSync(rootPrismaConfig))
|
|
255
|
+
moves.push([rootPrismaConfig, live.prismaConfig]);
|
|
256
|
+
const promoted = [];
|
|
257
|
+
for (const [from, to] of moves) {
|
|
258
|
+
if (!fs.existsSync(from))
|
|
259
|
+
continue;
|
|
260
|
+
try {
|
|
261
|
+
swapIntoPlace(from, to);
|
|
262
|
+
}
|
|
263
|
+
catch (error) {
|
|
264
|
+
if (promoted.length === 0)
|
|
265
|
+
throw error;
|
|
266
|
+
throw new PartialPromotionError(promoted, to, error);
|
|
267
|
+
}
|
|
268
|
+
promoted.push(to);
|
|
269
|
+
}
|
|
270
|
+
fs.rmSync(stagingDir, { recursive: true, force: true });
|
|
271
|
+
}
|
|
272
|
+
/** Formats a plan the way the loop reports one that it is not applying. */
|
|
273
|
+
export function describePlan(plan) {
|
|
274
|
+
const lines = plan.operations.map((operation) => ` • ${operation.label} (${operation.operationClass})`);
|
|
275
|
+
for (const statement of plan.statements)
|
|
276
|
+
lines.push(` ${statement}`);
|
|
277
|
+
return lines;
|
|
278
|
+
}
|
|
279
|
+
/** A short, stable id for a plan, derived from its operations. */
|
|
280
|
+
export function planId(plan) {
|
|
281
|
+
const content = [
|
|
282
|
+
...plan.operations.map((operation) => `${operation.operationClass}:${operation.label}`),
|
|
283
|
+
...plan.statements,
|
|
284
|
+
...plan.dataLoss.map((subject) => `delete:${subject}`),
|
|
285
|
+
...plan.accessWidening.map((subject) => `allow:${subject}`),
|
|
286
|
+
];
|
|
287
|
+
return createHash('sha256').update(JSON.stringify(content)).digest('hex').slice(0, 12);
|
|
288
|
+
}
|
|
289
|
+
//# sourceMappingURL=staged-reconcile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"staged-reconcile.js","sourceRoot":"","sources":["../../src/dev/staged-reconcile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AACnC,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AACxB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAC5B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAA;AAG/F,oEAAoE;AACpE,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAA;AA8B3D,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/B,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;IACjB,cAAc,EAAE,CAAC,CAAC,MAAM,EAAE;CAC3B,CAAC,CAAA;AAEF,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;AAEzD,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,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,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,SAAS,OAAO,EAAE,CAAC;KAC5D,CAAA;IACD,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;AACxF,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { OpenSaasConfig } from '@opensaas/stack-core';
|
|
2
|
+
/**
|
|
3
|
+
* Loads the project's env files before `opensaas.config.ts` is read, in the
|
|
4
|
+
* precedence Next applies under `next dev`. A variable already in the
|
|
5
|
+
* environment is never overwritten, so a shell value wins.
|
|
6
|
+
*
|
|
7
|
+
* Returns the file each newly set variable came from.
|
|
8
|
+
*/
|
|
9
|
+
export declare function loadProjectEnvFile(cwd: string): Map<string, string>;
|
|
10
|
+
/** A loaded `opensaas.config.ts`, with whatever the alias resolution wants to say. */
|
|
11
|
+
export interface LoadedOpenSaasConfig {
|
|
12
|
+
config: OpenSaasConfig;
|
|
13
|
+
/** Messages from resolving the project's tsconfig path aliases, for the caller to print. */
|
|
14
|
+
aliasWarnings: string[];
|
|
15
|
+
/**
|
|
16
|
+
* Absolute paths of every project-local module the config imported, direct
|
|
17
|
+
* or transitive, besides the config file itself. A dependency resolved into
|
|
18
|
+
* `node_modules` is never included — a config split across its own modules
|
|
19
|
+
* is what this reports, not the packages it depends on (#1414).
|
|
20
|
+
*/
|
|
21
|
+
resolvedModules: string[];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Load a project's `opensaas.config.ts` the way every command that reads it
|
|
25
|
+
* must: through jiti, under the project's own tsconfig path aliases, awaiting
|
|
26
|
+
* a default export that is a `Promise` whenever the config declares plugins.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* const { config, aliasWarnings, resolvedModules } = await loadOpenSaasConfig(cwd, configPath)
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare function loadOpenSaasConfig(cwd: string, configPath: string): Promise<LoadedOpenSaasConfig>;
|
|
34
|
+
//# sourceMappingURL=config-load.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-load.d.ts","sourceRoot":"","sources":["../../src/generator/config-load.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAK1D;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAYnE;AAED,sFAAsF;AACtF,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,cAAc,CAAA;IACtB,4FAA4F;IAC5F,aAAa,EAAE,MAAM,EAAE,CAAA;IACvB;;;;;OAKG;IACH,eAAe,EAAE,MAAM,EAAE,CAAA;CAC1B;AAED;;;;;;;;;GASG;AACH,wBAAsB,kBAAkB,CACtC,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,oBAAoB,CAAC,CAmC/B"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import { createJiti } from 'jiti';
|
|
4
|
+
import { resolveTsconfigAlias } from './tsconfig-alias.js';
|
|
5
|
+
const DEV_ENV_FILES = ['.env.development.local', '.env.local', '.env.development', '.env'];
|
|
6
|
+
/**
|
|
7
|
+
* Loads the project's env files before `opensaas.config.ts` is read, in the
|
|
8
|
+
* precedence Next applies under `next dev`. A variable already in the
|
|
9
|
+
* environment is never overwritten, so a shell value wins.
|
|
10
|
+
*
|
|
11
|
+
* Returns the file each newly set variable came from.
|
|
12
|
+
*/
|
|
13
|
+
export function loadProjectEnvFile(cwd) {
|
|
14
|
+
const sources = new Map();
|
|
15
|
+
for (const name of DEV_ENV_FILES) {
|
|
16
|
+
const file = path.join(cwd, name);
|
|
17
|
+
if (!fs.existsSync(file))
|
|
18
|
+
continue;
|
|
19
|
+
const before = new Set(Object.keys(process.env));
|
|
20
|
+
process.loadEnvFile(file);
|
|
21
|
+
for (const key of Object.keys(process.env)) {
|
|
22
|
+
if (!before.has(key))
|
|
23
|
+
sources.set(key, name);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return sources;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Load a project's `opensaas.config.ts` the way every command that reads it
|
|
30
|
+
* must: through jiti, under the project's own tsconfig path aliases, awaiting
|
|
31
|
+
* a default export that is a `Promise` whenever the config declares plugins.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const { config, aliasWarnings, resolvedModules } = await loadOpenSaasConfig(cwd, configPath)
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export async function loadOpenSaasConfig(cwd, configPath) {
|
|
39
|
+
const { alias, warnings } = resolveTsconfigAlias(cwd);
|
|
40
|
+
// Module caching is enabled only long enough to read back the resolved
|
|
41
|
+
// import graph off jiti's own cache (the `NodeRequire.cache` shape its
|
|
42
|
+
// public API already documents), then cleared below — so a second load of
|
|
43
|
+
// this exact path in the same process still sees fresh bytes. That cache is
|
|
44
|
+
// Node's own process-wide `require.cache`, not an object private to this
|
|
45
|
+
// jiti instance, which is why only the entries this load actually added are
|
|
46
|
+
// deleted, never the ones already there before it ran.
|
|
47
|
+
const jiti = createJiti(cwd, { interopDefault: true, alias, moduleCache: true });
|
|
48
|
+
const cachedBeforeLoad = new Set(Object.keys(jiti.cache));
|
|
49
|
+
// jiti's `interopDefault` doesn't unwrap an async `default` export, so the
|
|
50
|
+
// module's own default is awaited here.
|
|
51
|
+
const module = await jiti.import(configPath);
|
|
52
|
+
// Every entry this load newly added, freshness demands cleared regardless of
|
|
53
|
+
// where it resolved to — a `node_modules` package still on its source form
|
|
54
|
+
// (a workspace link, a git dependency) goes through the same transform and
|
|
55
|
+
// caches exactly like a project file, and staleness in that cache is the
|
|
56
|
+
// bug `moduleCache: false` used to prevent outright. `resolvedModules`,
|
|
57
|
+
// reported for the caller to watch, is the stricter, project-local subset.
|
|
58
|
+
const newlyCached = Object.keys(jiti.cache).filter((modulePath) => !cachedBeforeLoad.has(modulePath));
|
|
59
|
+
const resolvedModules = newlyCached.filter((modulePath) => modulePath !== configPath && !modulePath.split(path.sep).includes('node_modules'));
|
|
60
|
+
for (const modulePath of newlyCached)
|
|
61
|
+
delete jiti.cache[modulePath];
|
|
62
|
+
return { config: await module.default, aliasWarnings: warnings, resolvedModules };
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=config-load.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-load.js","sourceRoot":"","sources":["../../src/generator/config-load.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AACxB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAA;AAEjC,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AAE1D,MAAM,aAAa,GAAG,CAAC,wBAAwB,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,CAAU,CAAA;AAEnG;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAC,GAAW;IAC5C,MAAM,OAAO,GAAG,IAAI,GAAG,EAAkB,CAAA;IACzC,KAAK,MAAM,IAAI,IAAI,aAAa,EAAE,CAAC;QACjC,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;QACjC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC;YAAE,SAAQ;QAClC,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC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,eAAe,GAAG,WAAW,CAAC,MAAM,CACxC,CAAC,UAAU,EAAE,EAAE,CACb,UAAU,KAAK,UAAU,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,cAAc,CAAC,CACpF,CAAA;IACD,KAAK,MAAM,UAAU,IAAI,WAAW;QAAE,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAA;IAEnE,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,eAAe,EAAE,CAAA;AACnF,CAAC"}
|
|
@@ -1,4 +1,40 @@
|
|
|
1
|
-
import type { OpenSaasConfig } from '@opensaas/stack-core';
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import type { ContractData, OpenSaasConfig } from '@opensaas/stack-core';
|
|
2
|
+
/**
|
|
3
|
+
* The relative specifiers the generated context embeds, resolved by
|
|
4
|
+
* {@link resolveOutputPaths} so the bundle and the Contract module can each be
|
|
5
|
+
* relocated.
|
|
6
|
+
*/
|
|
7
|
+
export interface ContextReferences {
|
|
8
|
+
/** Specifier for `opensaas.config`, relative to the bundle directory. */
|
|
9
|
+
configImport: string;
|
|
10
|
+
/** Specifier for the emitted `contract.json`, relative to the bundle directory. */
|
|
11
|
+
contractJsonImport: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Render `<opensaasDir>/context.ts` — the generated context factory.
|
|
15
|
+
*
|
|
16
|
+
* The client is constructed from the committed `contract.json`, so the runtime
|
|
17
|
+
* executes the same bytes the emitted artifacts were signed over (PRD user
|
|
18
|
+
* story 6), with the stack-owned tripwire in `middleware` and each declared
|
|
19
|
+
* pack's runtime façade in `extensions`. Its connection is
|
|
20
|
+
* `resolveRuntimeConnection`'s: `db.client.pg` when the config supplies a pool
|
|
21
|
+
* factory, otherwise the stack's URL lookup, whose provenance decides the
|
|
22
|
+
* Dev database's single-connection binding (ADR-0049, ADR-0063).
|
|
23
|
+
*
|
|
24
|
+
* The resolved config carries the emitted dependency-set table and
|
|
25
|
+
* unique-constraint map from `tables.ts` on `_tables`, which is how the
|
|
26
|
+
* engine reaches them (ADR-0051, ADR-0042).
|
|
27
|
+
*
|
|
28
|
+
* Known limits:
|
|
29
|
+
* - `Context` is still the bundle's own type; #1136 rewrites `types.ts` to
|
|
30
|
+
* instantiate core's contract-keyed generics, and the client's own typed
|
|
31
|
+
* surface is spec 2's.
|
|
32
|
+
* - Pool lifecycle beyond the module-level singleton — `close()`, the dev
|
|
33
|
+
* loop's ephemeral database, the pooled/direct split — is still unowned. The
|
|
34
|
+
* pool `resolveRuntimeConnection` builds for that database is bound as `pg`,
|
|
35
|
+
* which rc.8 gives no `ownedDispose`, so nothing ends it; it carries a
|
|
36
|
+
* connection timeout instead of relying on one.
|
|
37
|
+
*/
|
|
38
|
+
export declare function generateContext(config: OpenSaasConfig, data: ContractData, references?: Partial<ContextReferences>): string;
|
|
39
|
+
export declare function writeContext(config: OpenSaasConfig, data: ContractData, outputPath: string, references?: Partial<ContextReferences>): void;
|
|
4
40
|
//# sourceMappingURL=context.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/generator/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/generator/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAKxE;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,yEAAyE;IACzE,YAAY,EAAE,MAAM,CAAA;IACpB,mFAAmF;IACnF,kBAAkB,EAAE,MAAM,CAAA;CAC3B;AAyFD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,cAAc,EACtB,IAAI,EAAE,YAAY,EAClB,UAAU,GAAE,OAAO,CAAC,iBAAiB,CAAM,GAC1C,MAAM,CAqOR;AAED,wBAAgB,YAAY,CAC1B,MAAM,EAAE,cAAc,EACtB,IAAI,EAAE,YAAY,EAClB,UAAU,EAAE,MAAM,EAClB,UAAU,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,GACtC,IAAI,CASN"}
|