prisma-next 0.4.0-dev.9 → 0.4.2
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/dist/agent-skill-mongo.md +63 -31
- package/dist/agent-skill-postgres.md +1 -1
- package/dist/cli-errors-BFYgBH3L.d.mts +4 -0
- package/dist/cli-errors-Cd79vmTH.mjs +5 -0
- package/dist/cli.mjs +127 -25
- package/dist/cli.mjs.map +1 -1
- package/dist/{client-CJxHfhze.mjs → client-CrsnY58k.mjs} +9 -8
- package/dist/{client-CJxHfhze.mjs.map → client-CrsnY58k.mjs.map} +1 -1
- package/dist/commands/contract-emit.d.mts.map +1 -1
- package/dist/commands/contract-emit.mjs +7 -7
- package/dist/commands/contract-infer.mjs +8 -8
- package/dist/commands/db-init.mjs +8 -8
- package/dist/commands/db-schema.mjs +8 -8
- package/dist/commands/db-sign.mjs +8 -8
- package/dist/commands/db-update.mjs +8 -8
- package/dist/commands/db-verify.mjs +9 -9
- package/dist/commands/migration-apply.d.mts +1 -1
- package/dist/commands/migration-apply.d.mts.map +1 -1
- package/dist/commands/migration-apply.mjs +37 -28
- package/dist/commands/migration-apply.mjs.map +1 -1
- package/dist/commands/migration-new.d.mts.map +1 -1
- package/dist/commands/migration-new.mjs +48 -23
- package/dist/commands/migration-new.mjs.map +1 -1
- package/dist/commands/migration-plan.d.mts +6 -1
- package/dist/commands/migration-plan.d.mts.map +1 -1
- package/dist/commands/migration-plan.mjs +94 -71
- package/dist/commands/migration-plan.mjs.map +1 -1
- package/dist/commands/migration-ref.d.mts +6 -4
- package/dist/commands/migration-ref.d.mts.map +1 -1
- package/dist/commands/migration-ref.mjs +29 -34
- package/dist/commands/migration-ref.mjs.map +1 -1
- package/dist/commands/migration-show.d.mts +2 -2
- package/dist/commands/migration-show.d.mts.map +1 -1
- package/dist/commands/migration-show.mjs +11 -16
- package/dist/commands/migration-show.mjs.map +1 -1
- package/dist/commands/migration-status.d.mts +4 -5
- package/dist/commands/migration-status.d.mts.map +1 -1
- package/dist/commands/migration-status.mjs +7 -7
- package/dist/config-loader-C25b63rJ.mjs +90 -0
- package/dist/config-loader-C25b63rJ.mjs.map +1 -0
- package/dist/config-loader.d.mts.map +1 -1
- package/dist/config-loader.mjs +1 -1
- package/dist/contract-emit-DxgyXrqV.mjs +6 -0
- package/dist/{contract-emit-gpJNLGs7.mjs → contract-emit-NJ01hiiv.mjs} +20 -16
- package/dist/contract-emit-NJ01hiiv.mjs.map +1 -0
- package/dist/{contract-emit-CKig_Lra.mjs → contract-emit-V5SSitUT.mjs} +25 -21
- package/dist/contract-emit-V5SSitUT.mjs.map +1 -0
- package/dist/{contract-enrichment-CGW6mm-E.mjs → contract-enrichment-CAOELa-H.mjs} +1 -1
- package/dist/{contract-enrichment-CGW6mm-E.mjs.map → contract-enrichment-CAOELa-H.mjs.map} +1 -1
- package/dist/{contract-infer-BDJgg7Xb.mjs → contract-infer-D9cC3rJm.mjs} +4 -4
- package/dist/{contract-infer-BDJgg7Xb.mjs.map → contract-infer-D9cC3rJm.mjs.map} +1 -1
- package/dist/exports/control-api.d.mts +2 -2
- package/dist/exports/control-api.d.mts.map +1 -1
- package/dist/exports/control-api.mjs +6 -6
- package/dist/exports/index.mjs +7 -7
- package/dist/exports/init-output.d.mts +39 -0
- package/dist/exports/init-output.d.mts.map +1 -0
- package/dist/exports/init-output.mjs +3 -0
- package/dist/{extract-operation-statements-DZUJNmL3.mjs → extract-operation-statements-DsFfxXVZ.mjs} +2 -2
- package/dist/{extract-operation-statements-DZUJNmL3.mjs.map → extract-operation-statements-DsFfxXVZ.mjs.map} +1 -1
- package/dist/{extract-sql-ddl-DDMX-9mz.mjs → extract-sql-ddl-D9UbZDyz.mjs} +1 -1
- package/dist/{extract-sql-ddl-DDMX-9mz.mjs.map → extract-sql-ddl-D9UbZDyz.mjs.map} +1 -1
- package/dist/{framework-components-Bsr1GaIj.mjs → framework-components-Cr--XBKy.mjs} +2 -2
- package/dist/{framework-components-Bsr1GaIj.mjs.map → framework-components-Cr--XBKy.mjs.map} +1 -1
- package/dist/init-m8x0UoPY.mjs +2062 -0
- package/dist/init-m8x0UoPY.mjs.map +1 -0
- package/dist/{inspect-live-schema-ChqrALmw.mjs → inspect-live-schema-yrHAvG71.mjs} +6 -6
- package/dist/{inspect-live-schema-ChqrALmw.mjs.map → inspect-live-schema-yrHAvG71.mjs.map} +1 -1
- package/dist/migration-cli.d.mts +50 -0
- package/dist/migration-cli.d.mts.map +1 -0
- package/dist/migration-cli.mjs +184 -0
- package/dist/migration-cli.mjs.map +1 -0
- package/dist/{migration-command-scaffold-B0oH_hyB.mjs → migration-command-scaffold-B3B09et6.mjs} +7 -7
- package/dist/{migration-command-scaffold-B0oH_hyB.mjs.map → migration-command-scaffold-B3B09et6.mjs.map} +1 -1
- package/dist/{migration-status-CPamfEPj.mjs → migration-status-DUMiH8_G.mjs} +25 -43
- package/dist/migration-status-DUMiH8_G.mjs.map +1 -0
- package/dist/{migrations-BIsjFjSV.mjs → migrations-Bo5WtTla.mjs} +4 -15
- package/dist/migrations-Bo5WtTla.mjs.map +1 -0
- package/dist/output-BpcQrnnq.mjs +103 -0
- package/dist/output-BpcQrnnq.mjs.map +1 -0
- package/dist/{progress-adapter-B-YvmcDu.mjs → progress-adapter-DvQWB1nK.mjs} +1 -1
- package/dist/{progress-adapter-B-YvmcDu.mjs.map → progress-adapter-DvQWB1nK.mjs.map} +1 -1
- package/dist/quick-reference-mongo.md +34 -13
- package/dist/quick-reference-postgres.md +11 -9
- package/dist/{result-handler-AFK4hxyX.mjs → result-handler-Ba3zWQsI.mjs} +26 -88
- package/dist/result-handler-Ba3zWQsI.mjs.map +1 -0
- package/dist/{terminal-ui-C5k88MmW.mjs → terminal-ui-C3ZLwQxK.mjs} +76 -2
- package/dist/terminal-ui-C3ZLwQxK.mjs.map +1 -0
- package/dist/{validate-contract-deps-DBH6iTAD.mjs → validate-contract-deps-B_Cs29TL.mjs} +1 -1
- package/dist/{validate-contract-deps-DBH6iTAD.mjs.map → validate-contract-deps-B_Cs29TL.mjs.map} +1 -1
- package/dist/{verify-C56CuQc7.mjs → verify-Bkycc-Tf.mjs} +2 -2
- package/dist/{verify-C56CuQc7.mjs.map → verify-Bkycc-Tf.mjs.map} +1 -1
- package/package.json +11 -10
- package/dist/cli-errors-BUuJr6py.mjs +0 -5
- package/dist/cli-errors-Dic2eADK.d.mts +0 -4
- package/dist/commands/migration-emit.d.mts +0 -38
- package/dist/commands/migration-emit.d.mts.map +0 -1
- package/dist/commands/migration-emit.mjs +0 -81
- package/dist/commands/migration-emit.mjs.map +0 -1
- package/dist/config-loader-C4VXKl8f.mjs +0 -43
- package/dist/config-loader-C4VXKl8f.mjs.map +0 -1
- package/dist/contract-emit-CKig_Lra.mjs.map +0 -1
- package/dist/contract-emit-CU-SYNe4.mjs +0 -6
- package/dist/contract-emit-gpJNLGs7.mjs.map +0 -1
- package/dist/init-DZWvhEP0.mjs +0 -430
- package/dist/init-DZWvhEP0.mjs.map +0 -1
- package/dist/migration-emit-Du4DBMqz.mjs +0 -125
- package/dist/migration-emit-Du4DBMqz.mjs.map +0 -1
- package/dist/migration-status-CPamfEPj.mjs.map +0 -1
- package/dist/migrations-BIsjFjSV.mjs.map +0 -1
- package/dist/result-handler-AFK4hxyX.mjs.map +0 -1
- package/dist/terminal-ui-C5k88MmW.mjs.map +0 -1
package/dist/init-DZWvhEP0.mjs
DELETED
|
@@ -1,430 +0,0 @@
|
|
|
1
|
-
import { t as TerminalUI } from "./terminal-ui-C5k88MmW.mjs";
|
|
2
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
|
-
import { dirname, extname, isAbsolute, join, normalize } from "pathe";
|
|
4
|
-
import * as clack from "@clack/prompts";
|
|
5
|
-
import { execFile } from "node:child_process";
|
|
6
|
-
import { promisify } from "node:util";
|
|
7
|
-
import { detect } from "package-manager-detector/detect";
|
|
8
|
-
|
|
9
|
-
//#region src/commands/init/detect-package-manager.ts
|
|
10
|
-
const KNOWN = new Set([
|
|
11
|
-
"pnpm",
|
|
12
|
-
"npm",
|
|
13
|
-
"yarn",
|
|
14
|
-
"bun",
|
|
15
|
-
"deno"
|
|
16
|
-
]);
|
|
17
|
-
async function detectPackageManager(cwd) {
|
|
18
|
-
const result = await detect({ cwd });
|
|
19
|
-
if (result && KNOWN.has(result.name)) return result.name;
|
|
20
|
-
return "npm";
|
|
21
|
-
}
|
|
22
|
-
function hasProjectManifest(cwd) {
|
|
23
|
-
return existsSync(join(cwd, "package.json")) || existsSync(join(cwd, "deno.json")) || existsSync(join(cwd, "deno.jsonc"));
|
|
24
|
-
}
|
|
25
|
-
function formatRunCommand(pm, bin, args) {
|
|
26
|
-
if (pm === "npm") return `npx ${bin} ${args}`;
|
|
27
|
-
if (pm === "deno") return `deno run npm:${bin} ${args}`;
|
|
28
|
-
return `${pm} ${bin} ${args}`;
|
|
29
|
-
}
|
|
30
|
-
function formatAddArgs(pm, packages) {
|
|
31
|
-
if (pm === "deno") return ["add", ...packages.map((p) => `npm:${p}`)];
|
|
32
|
-
return ["add", ...packages];
|
|
33
|
-
}
|
|
34
|
-
function formatAddDevArgs(pm, packages) {
|
|
35
|
-
if (pm === "deno") return [
|
|
36
|
-
"add",
|
|
37
|
-
"--dev",
|
|
38
|
-
...packages.map((p) => `npm:${p}`)
|
|
39
|
-
];
|
|
40
|
-
return [
|
|
41
|
-
"add",
|
|
42
|
-
"-D",
|
|
43
|
-
...packages
|
|
44
|
-
];
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
//#endregion
|
|
48
|
-
//#region src/commands/init/templates/render.ts
|
|
49
|
-
function renderTemplate(templateFile, variableNames, vars) {
|
|
50
|
-
let result = readFileSync(join(import.meta.dirname, templateFile), "utf-8");
|
|
51
|
-
for (const key of variableNames) {
|
|
52
|
-
const value = vars[key];
|
|
53
|
-
if (value === void 0) throw new Error(`Template variable '${key}' is not defined`);
|
|
54
|
-
result = result.replaceAll(`{{${key}}}`, value);
|
|
55
|
-
}
|
|
56
|
-
return result;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
//#endregion
|
|
60
|
-
//#region src/commands/init/templates/agent-skill.ts
|
|
61
|
-
const variables$1 = [
|
|
62
|
-
"schemaPath",
|
|
63
|
-
"schemaDir",
|
|
64
|
-
"dbImportPath",
|
|
65
|
-
"pkgRun"
|
|
66
|
-
];
|
|
67
|
-
function agentSkillMd(target, schemaPath, pkgRun) {
|
|
68
|
-
const schemaDir = dirname(schemaPath);
|
|
69
|
-
const vars = {
|
|
70
|
-
schemaPath,
|
|
71
|
-
schemaDir,
|
|
72
|
-
dbImportPath: `./${schemaDir}/db`,
|
|
73
|
-
pkgRun
|
|
74
|
-
};
|
|
75
|
-
return renderTemplate(`agent-skill-${target}.md`, variables$1, vars);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
//#endregion
|
|
79
|
-
//#region src/commands/init/templates/code-templates.ts
|
|
80
|
-
function targetPackageName(target) {
|
|
81
|
-
return target === "postgres" ? "@prisma-next/postgres" : "@prisma-next/mongo";
|
|
82
|
-
}
|
|
83
|
-
function defaultSchemaPath(authoring) {
|
|
84
|
-
if (authoring === "typescript") return "prisma/contract.ts";
|
|
85
|
-
return "prisma/contract.prisma";
|
|
86
|
-
}
|
|
87
|
-
function starterSchema(target, authoring) {
|
|
88
|
-
if (authoring === "typescript") return target === "mongo" ? starterSchemaTsMongo() : starterSchemaTsPostgres();
|
|
89
|
-
return target === "mongo" ? starterSchemaPslMongo() : starterSchemaPslPostgres();
|
|
90
|
-
}
|
|
91
|
-
function starterSchemaPslPostgres() {
|
|
92
|
-
return `model User {
|
|
93
|
-
id Int @id @default(autoincrement())
|
|
94
|
-
email String @unique
|
|
95
|
-
name String?
|
|
96
|
-
posts Post[]
|
|
97
|
-
createdAt DateTime @default(now())
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
model Post {
|
|
101
|
-
id Int @id @default(autoincrement())
|
|
102
|
-
title String
|
|
103
|
-
content String?
|
|
104
|
-
author User @relation(fields: [authorId], references: [id])
|
|
105
|
-
authorId Int
|
|
106
|
-
createdAt DateTime @default(now())
|
|
107
|
-
}
|
|
108
|
-
`;
|
|
109
|
-
}
|
|
110
|
-
function starterSchemaPslMongo() {
|
|
111
|
-
return `model User {
|
|
112
|
-
id ObjectId @id @map("_id")
|
|
113
|
-
email String @unique
|
|
114
|
-
name String?
|
|
115
|
-
posts Post[]
|
|
116
|
-
@@map("users")
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
model Post {
|
|
120
|
-
id ObjectId @id @map("_id")
|
|
121
|
-
title String
|
|
122
|
-
content String?
|
|
123
|
-
author User @relation(fields: [authorId], references: [id])
|
|
124
|
-
authorId ObjectId
|
|
125
|
-
@@map("posts")
|
|
126
|
-
}
|
|
127
|
-
`;
|
|
128
|
-
}
|
|
129
|
-
function starterSchemaTsPostgres() {
|
|
130
|
-
return `import sqlFamily from '@prisma-next/family-sql/pack';
|
|
131
|
-
import { defineContract } from '@prisma-next/sql-contract-ts/contract-builder';
|
|
132
|
-
import postgresPack from '@prisma-next/target-postgres/pack';
|
|
133
|
-
|
|
134
|
-
export const contract = defineContract(
|
|
135
|
-
{ family: sqlFamily, target: postgresPack },
|
|
136
|
-
({ field, model, rel }) => ({
|
|
137
|
-
models: {
|
|
138
|
-
User: model('User', {
|
|
139
|
-
fields: {
|
|
140
|
-
id: field.id.uuidv7(),
|
|
141
|
-
email: field.text().unique(),
|
|
142
|
-
name: field.text().optional(),
|
|
143
|
-
createdAt: field.createdAt(),
|
|
144
|
-
},
|
|
145
|
-
}).relations({
|
|
146
|
-
posts: rel.hasMany('Post', { by: 'authorId' }),
|
|
147
|
-
}),
|
|
148
|
-
|
|
149
|
-
Post: model('Post', {
|
|
150
|
-
fields: {
|
|
151
|
-
id: field.id.uuidv7(),
|
|
152
|
-
title: field.text(),
|
|
153
|
-
content: field.text().optional(),
|
|
154
|
-
authorId: field.uuid(),
|
|
155
|
-
createdAt: field.createdAt(),
|
|
156
|
-
},
|
|
157
|
-
}).relations({
|
|
158
|
-
author: rel.belongsTo('User', { from: 'authorId', to: 'id' }),
|
|
159
|
-
}),
|
|
160
|
-
},
|
|
161
|
-
}),
|
|
162
|
-
);
|
|
163
|
-
`;
|
|
164
|
-
}
|
|
165
|
-
function starterSchemaTsMongo() {
|
|
166
|
-
return `import mongoFamily from '@prisma-next/family-mongo/pack';
|
|
167
|
-
import { defineContract, field, model, rel } from '@prisma-next/mongo-contract-ts/contract-builder';
|
|
168
|
-
import mongoTarget from '@prisma-next/target-mongo/pack';
|
|
169
|
-
|
|
170
|
-
const User = model('User', {
|
|
171
|
-
collection: 'users',
|
|
172
|
-
fields: {
|
|
173
|
-
_id: field.objectId(),
|
|
174
|
-
email: field.string(),
|
|
175
|
-
name: field.string().optional(),
|
|
176
|
-
},
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
const Post = model('Post', {
|
|
180
|
-
collection: 'posts',
|
|
181
|
-
fields: {
|
|
182
|
-
_id: field.objectId(),
|
|
183
|
-
title: field.string(),
|
|
184
|
-
content: field.string().optional(),
|
|
185
|
-
authorId: field.objectId(),
|
|
186
|
-
},
|
|
187
|
-
relations: {
|
|
188
|
-
author: rel.belongsTo(User, { from: 'authorId', to: User.ref('_id') }),
|
|
189
|
-
},
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
export const contract = defineContract({
|
|
193
|
-
family: mongoFamily,
|
|
194
|
-
target: mongoTarget,
|
|
195
|
-
models: { User, Post },
|
|
196
|
-
});
|
|
197
|
-
`;
|
|
198
|
-
}
|
|
199
|
-
function configFile(target, contractPath) {
|
|
200
|
-
return `import 'dotenv/config';
|
|
201
|
-
import { defineConfig } from '${targetPackageName(target)}/config';
|
|
202
|
-
|
|
203
|
-
export default defineConfig({
|
|
204
|
-
contract: ${JSON.stringify(contractPath)},
|
|
205
|
-
db: {
|
|
206
|
-
connection: process.env['DATABASE_URL']!,
|
|
207
|
-
},
|
|
208
|
-
});
|
|
209
|
-
`;
|
|
210
|
-
}
|
|
211
|
-
function dbFile(target) {
|
|
212
|
-
if (target === "postgres") return `import postgres from '@prisma-next/postgres/runtime';
|
|
213
|
-
import type { Contract } from './contract.d';
|
|
214
|
-
import contractJson from './contract.json' with { type: 'json' };
|
|
215
|
-
|
|
216
|
-
export const db = postgres<Contract>({ contractJson });
|
|
217
|
-
`;
|
|
218
|
-
return `import mongo from '@prisma-next/mongo/runtime';
|
|
219
|
-
import type { Contract } from './contract.d';
|
|
220
|
-
import contractJson from './contract.json' with { type: 'json' };
|
|
221
|
-
|
|
222
|
-
export const db = mongo<Contract>({ contractJson });
|
|
223
|
-
`;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
//#endregion
|
|
227
|
-
//#region src/commands/init/templates/quick-reference.ts
|
|
228
|
-
const variables = [
|
|
229
|
-
"schemaPath",
|
|
230
|
-
"schemaDir",
|
|
231
|
-
"dbImportPath",
|
|
232
|
-
"pkgRun"
|
|
233
|
-
];
|
|
234
|
-
function quickReferenceMd(target, schemaPath, pkgRun) {
|
|
235
|
-
const schemaDir = dirname(schemaPath);
|
|
236
|
-
const vars = {
|
|
237
|
-
schemaPath,
|
|
238
|
-
schemaDir,
|
|
239
|
-
dbImportPath: `./${schemaDir}/db`,
|
|
240
|
-
pkgRun
|
|
241
|
-
};
|
|
242
|
-
return renderTemplate(`quick-reference-${target}.md`, variables, vars);
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
//#endregion
|
|
246
|
-
//#region src/commands/init/templates/tsconfig.ts
|
|
247
|
-
const REQUIRED_COMPILER_OPTIONS = {
|
|
248
|
-
module: "preserve",
|
|
249
|
-
moduleResolution: "bundler",
|
|
250
|
-
resolveJsonModule: true
|
|
251
|
-
};
|
|
252
|
-
function defaultTsConfig() {
|
|
253
|
-
return JSON.stringify({
|
|
254
|
-
compilerOptions: {
|
|
255
|
-
target: "ES2022",
|
|
256
|
-
...REQUIRED_COMPILER_OPTIONS,
|
|
257
|
-
strict: true,
|
|
258
|
-
skipLibCheck: true,
|
|
259
|
-
esModuleInterop: true,
|
|
260
|
-
outDir: "dist"
|
|
261
|
-
},
|
|
262
|
-
include: ["**/*.ts"]
|
|
263
|
-
}, null, 2);
|
|
264
|
-
}
|
|
265
|
-
function mergeTsConfig(existing) {
|
|
266
|
-
const config = JSON.parse(existing);
|
|
267
|
-
const compilerOptions = config["compilerOptions"] ?? {};
|
|
268
|
-
for (const [key, value] of Object.entries(REQUIRED_COMPILER_OPTIONS)) compilerOptions[key] = value;
|
|
269
|
-
config["compilerOptions"] = compilerOptions;
|
|
270
|
-
return JSON.stringify(config, null, 2);
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
//#endregion
|
|
274
|
-
//#region src/commands/init/init.ts
|
|
275
|
-
async function runInit(baseDir, options) {
|
|
276
|
-
const ui = new TerminalUI();
|
|
277
|
-
clack.intro("prisma-next init", { output: process.stderr });
|
|
278
|
-
if (!hasProjectManifest(baseDir)) {
|
|
279
|
-
ui.error("No package.json or deno.json found. Initialize your project first (e.g. npm init or deno init), then re-run prisma-next init.");
|
|
280
|
-
process.exit(1);
|
|
281
|
-
}
|
|
282
|
-
const pm = await detectPackageManager(baseDir);
|
|
283
|
-
const pkgRun = formatRunCommand(pm, "prisma-next", "").trimEnd();
|
|
284
|
-
if (existsSync(join(baseDir, "prisma-next.config.ts"))) {
|
|
285
|
-
const reinit = await clack.confirm({
|
|
286
|
-
message: "This project is already initialized. Re-initialize? This will overwrite all generated files.",
|
|
287
|
-
initialValue: false,
|
|
288
|
-
output: process.stderr
|
|
289
|
-
});
|
|
290
|
-
if (clack.isCancel(reinit) || !reinit) {
|
|
291
|
-
clack.cancel("Init cancelled.", { output: process.stderr });
|
|
292
|
-
process.exit(0);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
const targetResult = await clack.select({
|
|
296
|
-
message: "What database are you using?",
|
|
297
|
-
options: [{
|
|
298
|
-
value: "postgres",
|
|
299
|
-
label: "PostgreSQL"
|
|
300
|
-
}, {
|
|
301
|
-
value: "mongo",
|
|
302
|
-
label: "MongoDB"
|
|
303
|
-
}],
|
|
304
|
-
output: process.stderr
|
|
305
|
-
});
|
|
306
|
-
if (clack.isCancel(targetResult)) {
|
|
307
|
-
clack.cancel("Init cancelled.", { output: process.stderr });
|
|
308
|
-
process.exit(0);
|
|
309
|
-
}
|
|
310
|
-
const target = targetResult;
|
|
311
|
-
const authoringResult = await clack.select({
|
|
312
|
-
message: "How do you want to write your schema?",
|
|
313
|
-
options: [{
|
|
314
|
-
value: "psl",
|
|
315
|
-
label: "Prisma Schema Language (.prisma)"
|
|
316
|
-
}, {
|
|
317
|
-
value: "typescript",
|
|
318
|
-
label: "TypeScript (.ts)"
|
|
319
|
-
}],
|
|
320
|
-
output: process.stderr
|
|
321
|
-
});
|
|
322
|
-
if (clack.isCancel(authoringResult)) {
|
|
323
|
-
clack.cancel("Init cancelled.", { output: process.stderr });
|
|
324
|
-
process.exit(0);
|
|
325
|
-
}
|
|
326
|
-
const authoring = authoringResult;
|
|
327
|
-
const schemaPathResult = await clack.text({
|
|
328
|
-
message: "Where should the schema file go?",
|
|
329
|
-
initialValue: defaultSchemaPath(authoring),
|
|
330
|
-
validate(value = "") {
|
|
331
|
-
const trimmed = value.trim();
|
|
332
|
-
if (trimmed.length === 0) return "Path cannot be empty";
|
|
333
|
-
if (trimmed.endsWith("/") || trimmed.endsWith("\\")) return "Path must be a file, not a directory";
|
|
334
|
-
if (!extname(trimmed)) return "Path must include a file extension (e.g. .prisma or .ts)";
|
|
335
|
-
},
|
|
336
|
-
output: process.stderr
|
|
337
|
-
});
|
|
338
|
-
if (clack.isCancel(schemaPathResult)) {
|
|
339
|
-
clack.cancel("Init cancelled.", { output: process.stderr });
|
|
340
|
-
process.exit(0);
|
|
341
|
-
}
|
|
342
|
-
const schemaPath = normalize(schemaPathResult.trim());
|
|
343
|
-
const schemaDir = dirname(schemaPath);
|
|
344
|
-
const configPath = isAbsolute(schemaPath) ? schemaPath : `./${schemaPath}`;
|
|
345
|
-
const files = [
|
|
346
|
-
{
|
|
347
|
-
path: schemaPath,
|
|
348
|
-
content: starterSchema(target, authoring)
|
|
349
|
-
},
|
|
350
|
-
{
|
|
351
|
-
path: "prisma-next.config.ts",
|
|
352
|
-
content: configFile(target, configPath)
|
|
353
|
-
},
|
|
354
|
-
{
|
|
355
|
-
path: join(schemaDir, "db.ts"),
|
|
356
|
-
content: dbFile(target)
|
|
357
|
-
},
|
|
358
|
-
{
|
|
359
|
-
path: "prisma-next.md",
|
|
360
|
-
content: quickReferenceMd(target, schemaPath, pkgRun)
|
|
361
|
-
},
|
|
362
|
-
{
|
|
363
|
-
path: ".agents/skills/prisma-next/SKILL.md",
|
|
364
|
-
content: agentSkillMd(target, schemaPath, pkgRun)
|
|
365
|
-
}
|
|
366
|
-
];
|
|
367
|
-
for (const file of files) {
|
|
368
|
-
const fullPath = join(baseDir, file.path);
|
|
369
|
-
mkdirSync(dirname(fullPath), { recursive: true });
|
|
370
|
-
writeFileSync(fullPath, file.content, "utf-8");
|
|
371
|
-
}
|
|
372
|
-
const tsconfigPath = join(baseDir, "tsconfig.json");
|
|
373
|
-
if (existsSync(tsconfigPath)) {
|
|
374
|
-
writeFileSync(tsconfigPath, mergeTsConfig(readFileSync(tsconfigPath, "utf-8")), "utf-8");
|
|
375
|
-
ui.log("Updated tsconfig.json with required compiler options.");
|
|
376
|
-
} else writeFileSync(tsconfigPath, defaultTsConfig(), "utf-8");
|
|
377
|
-
const emitCommand = formatRunCommand(pm, "prisma-next", "contract emit");
|
|
378
|
-
if (options.noInstall) {
|
|
379
|
-
const pkg = targetPackageName(target);
|
|
380
|
-
ui.note([
|
|
381
|
-
"Run the following commands to complete setup:",
|
|
382
|
-
"",
|
|
383
|
-
" 1. Install dependencies:",
|
|
384
|
-
` ${pm} ${formatAddArgs(pm, [pkg, "dotenv"]).join(" ")}`,
|
|
385
|
-
` ${pm} ${formatAddDevArgs(pm, ["prisma-next"]).join(" ")}`,
|
|
386
|
-
"",
|
|
387
|
-
" 2. Emit the contract:",
|
|
388
|
-
` ${emitCommand}`
|
|
389
|
-
].join("\n"), "Manual steps");
|
|
390
|
-
} else {
|
|
391
|
-
const pkg = targetPackageName(target);
|
|
392
|
-
const spinner = ui.spinner();
|
|
393
|
-
let installSucceeded = false;
|
|
394
|
-
const exec = promisify(execFile);
|
|
395
|
-
spinner.start(`Installing ${pkg}, dotenv, and prisma-next...`);
|
|
396
|
-
try {
|
|
397
|
-
await exec(pm, formatAddArgs(pm, [pkg, "dotenv"]), { cwd: baseDir });
|
|
398
|
-
await exec(pm, formatAddDevArgs(pm, ["prisma-next"]), { cwd: baseDir });
|
|
399
|
-
spinner.stop(`Installed ${pkg}, dotenv, and prisma-next`);
|
|
400
|
-
installSucceeded = true;
|
|
401
|
-
} catch (err) {
|
|
402
|
-
spinner.stop("Installation failed");
|
|
403
|
-
const stderr = err instanceof Error && "stderr" in err ? err.stderr : "";
|
|
404
|
-
ui.warn([
|
|
405
|
-
"Could not install dependencies automatically.",
|
|
406
|
-
...stderr ? [` ${stderr.trim()}`] : [],
|
|
407
|
-
"",
|
|
408
|
-
"Run manually:",
|
|
409
|
-
` ${pm} ${formatAddArgs(pm, [pkg, "dotenv"]).join(" ")}`,
|
|
410
|
-
` ${pm} ${formatAddDevArgs(pm, ["prisma-next"]).join(" ")}`
|
|
411
|
-
].join("\n"));
|
|
412
|
-
}
|
|
413
|
-
if (installSucceeded) {
|
|
414
|
-
spinner.start("Emitting contract...");
|
|
415
|
-
try {
|
|
416
|
-
const { executeContractEmit } = await import("./contract-emit-CU-SYNe4.mjs");
|
|
417
|
-
await executeContractEmit({ configPath: join(baseDir, "prisma-next.config.ts") });
|
|
418
|
-
spinner.stop("Contract emitted");
|
|
419
|
-
} catch {
|
|
420
|
-
spinner.stop("Contract emission failed");
|
|
421
|
-
ui.warn(["Could not emit contract automatically. Run manually:", ` ${emitCommand}`].join("\n"));
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
clack.outro("Done! Open prisma-next.md to get started.", { output: process.stderr });
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
//#endregion
|
|
429
|
-
export { runInit };
|
|
430
|
-
//# sourceMappingURL=init-DZWvhEP0.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"init-DZWvhEP0.mjs","names":["KNOWN: ReadonlySet<string>","variables","vars: TemplateVars","vars: TemplateVars","REQUIRED_COMPILER_OPTIONS: Record<string, string | boolean>","files: FileEntry[]"],"sources":["../src/commands/init/detect-package-manager.ts","../src/commands/init/templates/render.ts","../src/commands/init/templates/agent-skill.ts","../src/commands/init/templates/code-templates.ts","../src/commands/init/templates/quick-reference.ts","../src/commands/init/templates/tsconfig.ts","../src/commands/init/init.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { detect } from 'package-manager-detector/detect';\nimport { join } from 'pathe';\n\nexport type PackageManager = 'pnpm' | 'npm' | 'yarn' | 'bun' | 'deno';\n\nconst KNOWN: ReadonlySet<string> = new Set<PackageManager>(['pnpm', 'npm', 'yarn', 'bun', 'deno']);\n\nexport async function detectPackageManager(cwd: string): Promise<PackageManager> {\n const result = await detect({ cwd });\n if (result && KNOWN.has(result.name)) {\n return result.name as PackageManager;\n }\n return 'npm';\n}\n\nexport function hasProjectManifest(cwd: string): boolean {\n return (\n existsSync(join(cwd, 'package.json')) ||\n existsSync(join(cwd, 'deno.json')) ||\n existsSync(join(cwd, 'deno.jsonc'))\n );\n}\n\nexport function formatRunCommand(pm: PackageManager, bin: string, args: string): string {\n if (pm === 'npm') {\n return `npx ${bin} ${args}`;\n }\n if (pm === 'deno') {\n return `deno run npm:${bin} ${args}`;\n }\n return `${pm} ${bin} ${args}`;\n}\n\nexport function formatAddArgs(pm: PackageManager, packages: string[]): string[] {\n if (pm === 'deno') {\n return ['add', ...packages.map((p) => `npm:${p}`)];\n }\n return ['add', ...packages];\n}\n\nexport function formatAddDevArgs(pm: PackageManager, packages: string[]): string[] {\n if (pm === 'deno') {\n return ['add', '--dev', ...packages.map((p) => `npm:${p}`)];\n }\n return ['add', '-D', ...packages];\n}\n","import { readFileSync } from 'node:fs';\nimport { join } from 'pathe';\n\nexport function renderTemplate(\n templateFile: string,\n variableNames: readonly string[],\n vars: Record<string, string>,\n): string {\n const templatePath = join(import.meta.dirname, templateFile);\n const raw = readFileSync(templatePath, 'utf-8');\n let result = raw;\n for (const key of variableNames) {\n const value = vars[key];\n if (value === undefined) {\n throw new Error(`Template variable '${key}' is not defined`);\n }\n result = result.replaceAll(`{{${key}}}`, value);\n }\n return result;\n}\n","import { dirname } from 'pathe';\nimport type { TargetId } from './code-templates';\nimport { renderTemplate } from './render';\n\nexport const variables = ['schemaPath', 'schemaDir', 'dbImportPath', 'pkgRun'] as const;\n\ntype TemplateVars = Record<(typeof variables)[number], string>;\n\nexport function agentSkillMd(target: TargetId, schemaPath: string, pkgRun: string): string {\n const schemaDir = dirname(schemaPath);\n const vars: TemplateVars = {\n schemaPath,\n schemaDir,\n dbImportPath: `./${schemaDir}/db`,\n pkgRun,\n };\n const templateFile = `agent-skill-${target}.md`;\n return renderTemplate(templateFile, variables, vars);\n}\n","export type TargetId = 'postgres' | 'mongo';\nexport type AuthoringId = 'psl' | 'typescript';\n\nexport function targetPackageName(target: TargetId): string {\n return target === 'postgres' ? '@prisma-next/postgres' : '@prisma-next/mongo';\n}\n\nexport function targetLabel(target: TargetId): string {\n return target === 'postgres' ? 'PostgreSQL' : 'MongoDB';\n}\n\nexport function defaultSchemaPath(authoring: AuthoringId): string {\n if (authoring === 'typescript') {\n return 'prisma/contract.ts';\n }\n return 'prisma/contract.prisma';\n}\n\nexport function starterSchema(target: TargetId, authoring: AuthoringId): string {\n if (authoring === 'typescript') {\n return target === 'mongo' ? starterSchemaTsMongo() : starterSchemaTsPostgres();\n }\n return target === 'mongo' ? starterSchemaPslMongo() : starterSchemaPslPostgres();\n}\n\nfunction starterSchemaPslPostgres(): string {\n return `model User {\n id Int @id @default(autoincrement())\n email String @unique\n name String?\n posts Post[]\n createdAt DateTime @default(now())\n}\n\nmodel Post {\n id Int @id @default(autoincrement())\n title String\n content String?\n author User @relation(fields: [authorId], references: [id])\n authorId Int\n createdAt DateTime @default(now())\n}\n`;\n}\n\nfunction starterSchemaPslMongo(): string {\n return `model User {\n id ObjectId @id @map(\"_id\")\n email String @unique\n name String?\n posts Post[]\n @@map(\"users\")\n}\n\nmodel Post {\n id ObjectId @id @map(\"_id\")\n title String\n content String?\n author User @relation(fields: [authorId], references: [id])\n authorId ObjectId\n @@map(\"posts\")\n}\n`;\n}\n\nfunction starterSchemaTsPostgres(): string {\n return `import sqlFamily from '@prisma-next/family-sql/pack';\nimport { defineContract } from '@prisma-next/sql-contract-ts/contract-builder';\nimport postgresPack from '@prisma-next/target-postgres/pack';\n\nexport const contract = defineContract(\n { family: sqlFamily, target: postgresPack },\n ({ field, model, rel }) => ({\n models: {\n User: model('User', {\n fields: {\n id: field.id.uuidv7(),\n email: field.text().unique(),\n name: field.text().optional(),\n createdAt: field.createdAt(),\n },\n }).relations({\n posts: rel.hasMany('Post', { by: 'authorId' }),\n }),\n\n Post: model('Post', {\n fields: {\n id: field.id.uuidv7(),\n title: field.text(),\n content: field.text().optional(),\n authorId: field.uuid(),\n createdAt: field.createdAt(),\n },\n }).relations({\n author: rel.belongsTo('User', { from: 'authorId', to: 'id' }),\n }),\n },\n }),\n);\n`;\n}\n\nfunction starterSchemaTsMongo(): string {\n return `import mongoFamily from '@prisma-next/family-mongo/pack';\nimport { defineContract, field, model, rel } from '@prisma-next/mongo-contract-ts/contract-builder';\nimport mongoTarget from '@prisma-next/target-mongo/pack';\n\nconst User = model('User', {\n collection: 'users',\n fields: {\n _id: field.objectId(),\n email: field.string(),\n name: field.string().optional(),\n },\n});\n\nconst Post = model('Post', {\n collection: 'posts',\n fields: {\n _id: field.objectId(),\n title: field.string(),\n content: field.string().optional(),\n authorId: field.objectId(),\n },\n relations: {\n author: rel.belongsTo(User, { from: 'authorId', to: User.ref('_id') }),\n },\n});\n\nexport const contract = defineContract({\n family: mongoFamily,\n target: mongoTarget,\n models: { User, Post },\n});\n`;\n}\n\nexport function configFile(target: TargetId, contractPath: string): string {\n const pkg = targetPackageName(target);\n return `import 'dotenv/config';\nimport { defineConfig } from '${pkg}/config';\n\nexport default defineConfig({\n contract: ${JSON.stringify(contractPath)},\n db: {\n connection: process.env['DATABASE_URL']!,\n },\n});\n`;\n}\n\nexport function dbFile(target: TargetId): string {\n if (target === 'postgres') {\n return `import postgres from '@prisma-next/postgres/runtime';\nimport type { Contract } from './contract.d';\nimport contractJson from './contract.json' with { type: 'json' };\n\nexport const db = postgres<Contract>({ contractJson });\n`;\n }\n\n return `import mongo from '@prisma-next/mongo/runtime';\nimport type { Contract } from './contract.d';\nimport contractJson from './contract.json' with { type: 'json' };\n\nexport const db = mongo<Contract>({ contractJson });\n`;\n}\n","import { dirname } from 'pathe';\nimport type { TargetId } from './code-templates';\nimport { renderTemplate } from './render';\n\nexport const variables = ['schemaPath', 'schemaDir', 'dbImportPath', 'pkgRun'] as const;\n\ntype TemplateVars = Record<(typeof variables)[number], string>;\n\nexport function quickReferenceMd(target: TargetId, schemaPath: string, pkgRun: string): string {\n const schemaDir = dirname(schemaPath);\n const vars: TemplateVars = {\n schemaPath,\n schemaDir,\n dbImportPath: `./${schemaDir}/db`,\n pkgRun,\n };\n const templateFile = `quick-reference-${target}.md`;\n return renderTemplate(templateFile, variables, vars);\n}\n","export const REQUIRED_COMPILER_OPTIONS: Record<string, string | boolean> = {\n module: 'preserve',\n moduleResolution: 'bundler',\n resolveJsonModule: true,\n};\n\nexport function defaultTsConfig(): string {\n return JSON.stringify(\n {\n compilerOptions: {\n target: 'ES2022',\n ...REQUIRED_COMPILER_OPTIONS,\n strict: true,\n skipLibCheck: true,\n esModuleInterop: true,\n outDir: 'dist',\n },\n include: ['**/*.ts'],\n },\n null,\n 2,\n );\n}\n\nexport function mergeTsConfig(existing: string): string {\n const config = JSON.parse(existing) as Record<string, unknown>;\n const compilerOptions = (config['compilerOptions'] ?? {}) as Record<string, unknown>;\n\n for (const [key, value] of Object.entries(REQUIRED_COMPILER_OPTIONS)) {\n compilerOptions[key] = value;\n }\n\n config['compilerOptions'] = compilerOptions;\n return JSON.stringify(config, null, 2);\n}\n","import { execFile } from 'node:child_process';\nimport { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';\nimport { promisify } from 'node:util';\nimport * as clack from '@clack/prompts';\nimport { dirname, extname, isAbsolute, join, normalize } from 'pathe';\nimport { TerminalUI } from '../../utils/terminal-ui';\nimport {\n detectPackageManager,\n formatAddArgs,\n formatAddDevArgs,\n formatRunCommand,\n hasProjectManifest,\n} from './detect-package-manager';\nimport { agentSkillMd } from './templates/agent-skill';\nimport {\n type AuthoringId,\n configFile,\n dbFile,\n defaultSchemaPath,\n starterSchema,\n type TargetId,\n targetPackageName,\n} from './templates/code-templates';\nimport { quickReferenceMd } from './templates/quick-reference';\nimport { defaultTsConfig, mergeTsConfig } from './templates/tsconfig';\n\nexport interface InitOptions {\n readonly noInstall?: boolean;\n}\n\ninterface FileEntry {\n readonly path: string;\n readonly content: string;\n}\n\nexport async function runInit(baseDir: string, options: InitOptions): Promise<void> {\n const ui = new TerminalUI();\n\n clack.intro('prisma-next init', { output: process.stderr });\n\n if (!hasProjectManifest(baseDir)) {\n ui.error(\n 'No package.json or deno.json found. Initialize your project first (e.g. npm init or deno init), then re-run prisma-next init.',\n );\n process.exit(1);\n }\n\n const pm = await detectPackageManager(baseDir);\n const pkgRun = formatRunCommand(pm, 'prisma-next', '').trimEnd();\n\n if (existsSync(join(baseDir, 'prisma-next.config.ts'))) {\n const reinit = await clack.confirm({\n message:\n 'This project is already initialized. Re-initialize? This will overwrite all generated files.',\n initialValue: false,\n output: process.stderr,\n });\n if (clack.isCancel(reinit) || !reinit) {\n clack.cancel('Init cancelled.', { output: process.stderr });\n process.exit(0);\n }\n }\n\n const targetResult = await clack.select({\n message: 'What database are you using?',\n options: [\n { value: 'postgres' as TargetId, label: 'PostgreSQL' },\n { value: 'mongo' as TargetId, label: 'MongoDB' },\n ],\n output: process.stderr,\n });\n if (clack.isCancel(targetResult)) {\n clack.cancel('Init cancelled.', { output: process.stderr });\n process.exit(0);\n }\n const target = targetResult as TargetId;\n\n const authoringResult = await clack.select({\n message: 'How do you want to write your schema?',\n options: [\n { value: 'psl' as AuthoringId, label: 'Prisma Schema Language (.prisma)' },\n { value: 'typescript' as AuthoringId, label: 'TypeScript (.ts)' },\n ],\n output: process.stderr,\n });\n if (clack.isCancel(authoringResult)) {\n clack.cancel('Init cancelled.', { output: process.stderr });\n process.exit(0);\n }\n const authoring = authoringResult as AuthoringId;\n\n const schemaPathResult = await clack.text({\n message: 'Where should the schema file go?',\n initialValue: defaultSchemaPath(authoring),\n validate(value = '') {\n const trimmed = value.trim();\n if (trimmed.length === 0) return 'Path cannot be empty';\n if (trimmed.endsWith('/') || trimmed.endsWith('\\\\'))\n return 'Path must be a file, not a directory';\n if (!extname(trimmed)) return 'Path must include a file extension (e.g. .prisma or .ts)';\n return undefined;\n },\n output: process.stderr,\n });\n if (clack.isCancel(schemaPathResult)) {\n clack.cancel('Init cancelled.', { output: process.stderr });\n process.exit(0);\n }\n const schemaPath = normalize((schemaPathResult as string).trim());\n\n const schemaDir = dirname(schemaPath);\n const configPath = isAbsolute(schemaPath) ? schemaPath : `./${schemaPath}`;\n\n const files: FileEntry[] = [\n { path: schemaPath, content: starterSchema(target, authoring) },\n { path: 'prisma-next.config.ts', content: configFile(target, configPath) },\n { path: join(schemaDir, 'db.ts'), content: dbFile(target) },\n { path: 'prisma-next.md', content: quickReferenceMd(target, schemaPath, pkgRun) },\n {\n path: '.agents/skills/prisma-next/SKILL.md',\n content: agentSkillMd(target, schemaPath, pkgRun),\n },\n ];\n\n for (const file of files) {\n const fullPath = join(baseDir, file.path);\n mkdirSync(dirname(fullPath), { recursive: true });\n writeFileSync(fullPath, file.content, 'utf-8');\n }\n\n const tsconfigPath = join(baseDir, 'tsconfig.json');\n if (existsSync(tsconfigPath)) {\n const existing = readFileSync(tsconfigPath, 'utf-8');\n writeFileSync(tsconfigPath, mergeTsConfig(existing), 'utf-8');\n ui.log('Updated tsconfig.json with required compiler options.');\n } else {\n writeFileSync(tsconfigPath, defaultTsConfig(), 'utf-8');\n }\n\n const emitCommand = formatRunCommand(pm, 'prisma-next', 'contract emit');\n\n if (options.noInstall) {\n const pkg = targetPackageName(target);\n ui.note(\n [\n 'Run the following commands to complete setup:',\n '',\n ' 1. Install dependencies:',\n ` ${pm} ${formatAddArgs(pm, [pkg, 'dotenv']).join(' ')}`,\n ` ${pm} ${formatAddDevArgs(pm, ['prisma-next']).join(' ')}`,\n '',\n ' 2. Emit the contract:',\n ` ${emitCommand}`,\n ].join('\\n'),\n 'Manual steps',\n );\n } else {\n const pkg = targetPackageName(target);\n const spinner = ui.spinner();\n let installSucceeded = false;\n\n const exec = promisify(execFile);\n\n spinner.start(`Installing ${pkg}, dotenv, and prisma-next...`);\n try {\n await exec(pm, formatAddArgs(pm, [pkg, 'dotenv']), { cwd: baseDir });\n await exec(pm, formatAddDevArgs(pm, ['prisma-next']), { cwd: baseDir });\n spinner.stop(`Installed ${pkg}, dotenv, and prisma-next`);\n installSucceeded = true;\n } catch (err) {\n spinner.stop('Installation failed');\n const stderr =\n err instanceof Error && 'stderr' in err ? (err as { stderr: string }).stderr : '';\n ui.warn(\n [\n 'Could not install dependencies automatically.',\n ...(stderr ? [` ${stderr.trim()}`] : []),\n '',\n 'Run manually:',\n ` ${pm} ${formatAddArgs(pm, [pkg, 'dotenv']).join(' ')}`,\n ` ${pm} ${formatAddDevArgs(pm, ['prisma-next']).join(' ')}`,\n ].join('\\n'),\n );\n }\n\n if (installSucceeded) {\n spinner.start('Emitting contract...');\n try {\n const { executeContractEmit } = await import('../../control-api/operations/contract-emit');\n const configFilePath = join(baseDir, 'prisma-next.config.ts');\n await executeContractEmit({ configPath: configFilePath });\n spinner.stop('Contract emitted');\n } catch {\n spinner.stop('Contract emission failed');\n ui.warn(\n ['Could not emit contract automatically. Run manually:', ` ${emitCommand}`].join('\\n'),\n );\n }\n }\n }\n\n clack.outro('Done! Open prisma-next.md to get started.', { output: process.stderr });\n}\n"],"mappings":";;;;;;;;;AAMA,MAAMA,QAA6B,IAAI,IAAoB;CAAC;CAAQ;CAAO;CAAQ;CAAO;CAAO,CAAC;AAElG,eAAsB,qBAAqB,KAAsC;CAC/E,MAAM,SAAS,MAAM,OAAO,EAAE,KAAK,CAAC;AACpC,KAAI,UAAU,MAAM,IAAI,OAAO,KAAK,CAClC,QAAO,OAAO;AAEhB,QAAO;;AAGT,SAAgB,mBAAmB,KAAsB;AACvD,QACE,WAAW,KAAK,KAAK,eAAe,CAAC,IACrC,WAAW,KAAK,KAAK,YAAY,CAAC,IAClC,WAAW,KAAK,KAAK,aAAa,CAAC;;AAIvC,SAAgB,iBAAiB,IAAoB,KAAa,MAAsB;AACtF,KAAI,OAAO,MACT,QAAO,OAAO,IAAI,GAAG;AAEvB,KAAI,OAAO,OACT,QAAO,gBAAgB,IAAI,GAAG;AAEhC,QAAO,GAAG,GAAG,GAAG,IAAI,GAAG;;AAGzB,SAAgB,cAAc,IAAoB,UAA8B;AAC9E,KAAI,OAAO,OACT,QAAO,CAAC,OAAO,GAAG,SAAS,KAAK,MAAM,OAAO,IAAI,CAAC;AAEpD,QAAO,CAAC,OAAO,GAAG,SAAS;;AAG7B,SAAgB,iBAAiB,IAAoB,UAA8B;AACjF,KAAI,OAAO,OACT,QAAO;EAAC;EAAO;EAAS,GAAG,SAAS,KAAK,MAAM,OAAO,IAAI;EAAC;AAE7D,QAAO;EAAC;EAAO;EAAM,GAAG;EAAS;;;;;AC1CnC,SAAgB,eACd,cACA,eACA,MACQ;CAGR,IAAI,SADQ,aADS,KAAK,OAAO,KAAK,SAAS,aAAa,EACrB,QAAQ;AAE/C,MAAK,MAAM,OAAO,eAAe;EAC/B,MAAM,QAAQ,KAAK;AACnB,MAA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CAAC,EAAE,EAAE,KAAK,SAAS,CAAC;AACpE,SAAM,KAAK,IAAI,iBAAiB,IAAI,CAAC,cAAc,CAAC,EAAE,EAAE,KAAK,SAAS,CAAC;AACvE,WAAQ,KAAK,aAAa,IAAI,2BAA2B;AACzD,sBAAmB;WACZ,KAAK;AACZ,WAAQ,KAAK,sBAAsB;GACnC,MAAM,SACJ,eAAe,SAAS,YAAY,MAAO,IAA2B,SAAS;AACjF,MAAG,KACD;IACE;IACA,GAAI,SAAS,CAAC,KAAK,OAAO,MAAM,GAAG,GAAG,EAAE;IACxC;IACA;IACA,KAAK,GAAG,GAAG,cAAc,IAAI,CAAC,KAAK,SAAS,CAAC,CAAC,KAAK,IAAI;IACvD,KAAK,GAAG,GAAG,iBAAiB,IAAI,CAAC,cAAc,CAAC,CAAC,KAAK,IAAI;IAC3D,CAAC,KAAK,KAAK,CACb;;AAGH,MAAI,kBAAkB;AACpB,WAAQ,MAAM,uBAAuB;AACrC,OAAI;IACF,MAAM,EAAE,wBAAwB,MAAM,OAAO;AAE7C,UAAM,oBAAoB,EAAE,YADL,KAAK,SAAS,wBAAwB,EACL,CAAC;AACzD,YAAQ,KAAK,mBAAmB;WAC1B;AACN,YAAQ,KAAK,2BAA2B;AACxC,OAAG,KACD,CAAC,wDAAwD,KAAK,cAAc,CAAC,KAAK,KAAK,CACxF;;;;AAKP,OAAM,MAAM,6CAA6C,EAAE,QAAQ,QAAQ,QAAQ,CAAC"}
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { f as errorMigrationFileMissing, g as errorTargetMigrationNotSupported } from "./cli-errors-BUuJr6py.mjs";
|
|
2
|
-
import { errorTargetHasIncompleteMigrationCapabilities } from "@prisma-next/errors/migration";
|
|
3
|
-
import { readMigrationPackage, writeMigrationOps } from "@prisma-next/migration-tools/io";
|
|
4
|
-
import assert from "node:assert/strict";
|
|
5
|
-
import { attestMigration } from "@prisma-next/migration-tools/attestation";
|
|
6
|
-
import { evaluateMigrationTs, hasMigrationTs } from "@prisma-next/migration-tools/migration-ts";
|
|
7
|
-
|
|
8
|
-
//#region src/lib/migration-strategy.ts
|
|
9
|
-
/**
|
|
10
|
-
* Migration authoring strategy selector.
|
|
11
|
-
*
|
|
12
|
-
* Targets currently use one of two strategies to author `migration.ts`:
|
|
13
|
-
*
|
|
14
|
-
* - **Descriptor flow** — the planner produces an `OperationDescriptor[]`
|
|
15
|
-
* and `migration.ts` is a `export default () => [...]` file that the CLI
|
|
16
|
-
* later replays through `resolveDescriptors` at emit time. Postgres uses
|
|
17
|
-
* this today.
|
|
18
|
-
* - **Class flow** — the planner produces a `MigrationPlanWithAuthoringSurface`
|
|
19
|
-
* that renders itself as a `class M extends Migration { ... }` file. The
|
|
20
|
-
* CLI dispatches to the target's `emit` capability at emit time. Mongo
|
|
21
|
-
* uses this today.
|
|
22
|
-
*
|
|
23
|
-
* The two are mutually exclusive at the target level: a migrations capability
|
|
24
|
-
* either implements the descriptor-flow trio (`planWithDescriptors`,
|
|
25
|
-
* `resolveDescriptors`, `renderDescriptorTypeScript`) or the class-flow
|
|
26
|
-
* `emit` hook. `migrationStrategy` discriminates between them by observing
|
|
27
|
-
* which hooks are present, and is consumed by `migration new`, `migration
|
|
28
|
-
* plan`, and `migration emit` to keep strategy-specific branching in one
|
|
29
|
-
* place.
|
|
30
|
-
*/
|
|
31
|
-
/**
|
|
32
|
-
* Determine which authoring strategy a target uses, based on the shape of
|
|
33
|
-
* its `TargetMigrationsCapability`. Callers that need strategy-specific
|
|
34
|
-
* guarantees (e.g. that `resolveDescriptors` is present) should narrow on
|
|
35
|
-
* the returned tag and trust the capability fields directly rather than
|
|
36
|
-
* re-probing.
|
|
37
|
-
*
|
|
38
|
-
* Throws `errorTargetHasIncompleteMigrationCapabilities` (PN-MIG-2011) when
|
|
39
|
-
* the capability registers neither flow. We diagnose this here rather than
|
|
40
|
-
* deferring to the dispatch site so a misconfigured target gets an honest
|
|
41
|
-
* "incomplete capability" error instead of being silently routed to one
|
|
42
|
-
* flow and reported as missing the *other* flow's hook.
|
|
43
|
-
*/
|
|
44
|
-
function migrationStrategy(migrations, targetId) {
|
|
45
|
-
if (migrations.resolveDescriptors) return "descriptor";
|
|
46
|
-
if (migrations.emit) return "class-based";
|
|
47
|
-
throw errorTargetHasIncompleteMigrationCapabilities({ targetId });
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
//#endregion
|
|
51
|
-
//#region src/lib/migration-emit.ts
|
|
52
|
-
/**
|
|
53
|
-
* Shared helper for emitting `ops.json` and attesting `migration.json` for a
|
|
54
|
-
* migration package's `migration.ts`.
|
|
55
|
-
*
|
|
56
|
-
* Two flows are dispatched here:
|
|
57
|
-
* - Descriptor flow (Postgres): the framework evaluates `migration.ts`
|
|
58
|
-
* (which re-exports the planner's descriptor list), calls the target's
|
|
59
|
-
* `resolveDescriptors` to produce display-oriented operations, writes
|
|
60
|
-
* `ops.json`, and attests `migration.json`.
|
|
61
|
-
* - Class flow (Mongo): the target's `emit` capability dynamic-imports
|
|
62
|
-
* `migration.ts`, instantiates the default-exported `Migration` subclass
|
|
63
|
-
* (or invokes the default-exported factory function), reads `operations`,
|
|
64
|
-
* and writes `ops.json`. This helper then attests `migration.json` once
|
|
65
|
-
* the capability returns.
|
|
66
|
-
*
|
|
67
|
-
* In both cases attestation is owned by this helper so the on-disk artifacts
|
|
68
|
-
* are guaranteed to be fully attested when emit returns.
|
|
69
|
-
*
|
|
70
|
-
* Note that this helper is the CLI-driven emit path. Class-flow `migration.ts`
|
|
71
|
-
* files are also self-emitting via `Migration.run(...)` when run directly;
|
|
72
|
-
* that path attests inside `Migration.run` and produces byte-identical
|
|
73
|
-
* artifacts. This helper exists primarily to bridge descriptor-flow targets
|
|
74
|
-
* and to give `migration plan` a single in-process emit dispatch.
|
|
75
|
-
*
|
|
76
|
-
* Used by `migration emit` (always) and `migration plan` (always, after
|
|
77
|
-
* scaffolding `migration.ts`). Both flows run in-process so that structured
|
|
78
|
-
* errors thrown during evaluation (notably `errorUnfilledPlaceholder` with
|
|
79
|
-
* code `PN-MIG-2001`) propagate as real exceptions and the CLI's error
|
|
80
|
-
* envelope renders them with full structured metadata.
|
|
81
|
-
*/
|
|
82
|
-
/**
|
|
83
|
-
* Emit `ops.json` and attest `migrationId` for the migration package at `dir`.
|
|
84
|
-
*
|
|
85
|
-
* Dispatches to descriptor flow when the target implements `resolveDescriptors`,
|
|
86
|
-
* otherwise to the target's `emit` capability. Throws a structured error if
|
|
87
|
-
* `migration.ts` is missing or the target supports neither flow. Other
|
|
88
|
-
* structured errors thrown during evaluation propagate unchanged.
|
|
89
|
-
*/
|
|
90
|
-
async function emitMigration(dir, ctx) {
|
|
91
|
-
if (!await hasMigrationTs(dir)) throw errorMigrationFileMissing(dir);
|
|
92
|
-
if (migrationStrategy(ctx.migrations, ctx.targetId) === "descriptor") return emitDescriptorFlow(dir, ctx.migrations, ctx);
|
|
93
|
-
if (!ctx.migrations.emit) throw errorTargetMigrationNotSupported({ why: `Target "${ctx.targetId}" does not implement the class-flow \`emit\` capability; cannot emit a migration package` });
|
|
94
|
-
return {
|
|
95
|
-
operations: await ctx.migrations.emit({
|
|
96
|
-
dir,
|
|
97
|
-
frameworkComponents: ctx.frameworkComponents
|
|
98
|
-
}),
|
|
99
|
-
migrationId: await attestMigration(dir)
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Descriptor flow: evaluate `migration.ts` to obtain a list of operation
|
|
104
|
-
* descriptors, hand them to the target's `resolveDescriptors` along with the
|
|
105
|
-
* manifest's contract bookends, then persist `ops.json` and attest the package.
|
|
106
|
-
*/
|
|
107
|
-
async function emitDescriptorFlow(dir, migrations, ctx) {
|
|
108
|
-
assert(migrations.resolveDescriptors, "emitDescriptorFlow requires resolveDescriptors; gated by caller");
|
|
109
|
-
const pkg = await readMigrationPackage(dir);
|
|
110
|
-
const descriptors = await evaluateMigrationTs(dir);
|
|
111
|
-
const operations = migrations.resolveDescriptors(descriptors, {
|
|
112
|
-
fromContract: pkg.manifest.fromContract,
|
|
113
|
-
toContract: pkg.manifest.toContract,
|
|
114
|
-
frameworkComponents: ctx.frameworkComponents
|
|
115
|
-
});
|
|
116
|
-
await writeMigrationOps(dir, operations);
|
|
117
|
-
return {
|
|
118
|
-
operations,
|
|
119
|
-
migrationId: await attestMigration(dir)
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
//#endregion
|
|
124
|
-
export { migrationStrategy as n, emitMigration as t };
|
|
125
|
-
//# sourceMappingURL=migration-emit-Du4DBMqz.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"migration-emit-Du4DBMqz.mjs","names":[],"sources":["../src/lib/migration-strategy.ts","../src/lib/migration-emit.ts"],"sourcesContent":["/**\n * Migration authoring strategy selector.\n *\n * Targets currently use one of two strategies to author `migration.ts`:\n *\n * - **Descriptor flow** — the planner produces an `OperationDescriptor[]`\n * and `migration.ts` is a `export default () => [...]` file that the CLI\n * later replays through `resolveDescriptors` at emit time. Postgres uses\n * this today.\n * - **Class flow** — the planner produces a `MigrationPlanWithAuthoringSurface`\n * that renders itself as a `class M extends Migration { ... }` file. The\n * CLI dispatches to the target's `emit` capability at emit time. Mongo\n * uses this today.\n *\n * The two are mutually exclusive at the target level: a migrations capability\n * either implements the descriptor-flow trio (`planWithDescriptors`,\n * `resolveDescriptors`, `renderDescriptorTypeScript`) or the class-flow\n * `emit` hook. `migrationStrategy` discriminates between them by observing\n * which hooks are present, and is consumed by `migration new`, `migration\n * plan`, and `migration emit` to keep strategy-specific branching in one\n * place.\n */\n\nimport { errorTargetHasIncompleteMigrationCapabilities } from '@prisma-next/errors/migration';\nimport type { TargetMigrationsCapability } from '@prisma-next/framework-components/control';\n\nexport type MigrationStrategy = 'descriptor' | 'class-based';\n\n/**\n * Determine which authoring strategy a target uses, based on the shape of\n * its `TargetMigrationsCapability`. Callers that need strategy-specific\n * guarantees (e.g. that `resolveDescriptors` is present) should narrow on\n * the returned tag and trust the capability fields directly rather than\n * re-probing.\n *\n * Throws `errorTargetHasIncompleteMigrationCapabilities` (PN-MIG-2011) when\n * the capability registers neither flow. We diagnose this here rather than\n * deferring to the dispatch site so a misconfigured target gets an honest\n * \"incomplete capability\" error instead of being silently routed to one\n * flow and reported as missing the *other* flow's hook.\n */\nexport function migrationStrategy(\n migrations: TargetMigrationsCapability,\n targetId: string,\n): MigrationStrategy {\n if (migrations.resolveDescriptors) return 'descriptor';\n if (migrations.emit) return 'class-based';\n throw errorTargetHasIncompleteMigrationCapabilities({ targetId });\n}\n","/**\n * Shared helper for emitting `ops.json` and attesting `migration.json` for a\n * migration package's `migration.ts`.\n *\n * Two flows are dispatched here:\n * - Descriptor flow (Postgres): the framework evaluates `migration.ts`\n * (which re-exports the planner's descriptor list), calls the target's\n * `resolveDescriptors` to produce display-oriented operations, writes\n * `ops.json`, and attests `migration.json`.\n * - Class flow (Mongo): the target's `emit` capability dynamic-imports\n * `migration.ts`, instantiates the default-exported `Migration` subclass\n * (or invokes the default-exported factory function), reads `operations`,\n * and writes `ops.json`. This helper then attests `migration.json` once\n * the capability returns.\n *\n * In both cases attestation is owned by this helper so the on-disk artifacts\n * are guaranteed to be fully attested when emit returns.\n *\n * Note that this helper is the CLI-driven emit path. Class-flow `migration.ts`\n * files are also self-emitting via `Migration.run(...)` when run directly;\n * that path attests inside `Migration.run` and produces byte-identical\n * artifacts. This helper exists primarily to bridge descriptor-flow targets\n * and to give `migration plan` a single in-process emit dispatch.\n *\n * Used by `migration emit` (always) and `migration plan` (always, after\n * scaffolding `migration.ts`). Both flows run in-process so that structured\n * errors thrown during evaluation (notably `errorUnfilledPlaceholder` with\n * code `PN-MIG-2001`) propagate as real exceptions and the CLI's error\n * envelope renders them with full structured metadata.\n */\n\nimport assert from 'node:assert/strict';\nimport type { TargetBoundComponentDescriptor } from '@prisma-next/framework-components/components';\nimport type {\n MigrationPlanOperation,\n OperationDescriptor,\n TargetMigrationsCapability,\n} from '@prisma-next/framework-components/control';\nimport { attestMigration } from '@prisma-next/migration-tools/attestation';\nimport { readMigrationPackage, writeMigrationOps } from '@prisma-next/migration-tools/io';\nimport { evaluateMigrationTs, hasMigrationTs } from '@prisma-next/migration-tools/migration-ts';\nimport { errorMigrationFileMissing, errorTargetMigrationNotSupported } from '../utils/cli-errors';\nimport { migrationStrategy } from './migration-strategy';\n\n/**\n * Context passed to `emitMigration`. Captures everything the helper needs to\n * dispatch to the right flow without re-loading the config.\n */\nexport interface EmitMigrationContext {\n readonly targetId: string;\n readonly migrations: TargetMigrationsCapability;\n readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<string, string>>;\n}\n\n/**\n * Result of a successful emit: the operations that were written to `ops.json`\n * (display-oriented shape) and the content-addressed migrationId persisted to\n * `migration.json`.\n */\nexport interface EmitMigrationResult {\n readonly operations: readonly MigrationPlanOperation[];\n readonly migrationId: string;\n}\n\n/**\n * Emit `ops.json` and attest `migrationId` for the migration package at `dir`.\n *\n * Dispatches to descriptor flow when the target implements `resolveDescriptors`,\n * otherwise to the target's `emit` capability. Throws a structured error if\n * `migration.ts` is missing or the target supports neither flow. Other\n * structured errors thrown during evaluation propagate unchanged.\n */\nexport async function emitMigration(\n dir: string,\n ctx: EmitMigrationContext,\n): Promise<EmitMigrationResult> {\n if (!(await hasMigrationTs(dir))) {\n throw errorMigrationFileMissing(dir);\n }\n\n const strategy = migrationStrategy(ctx.migrations, ctx.targetId);\n\n if (strategy === 'descriptor') {\n return emitDescriptorFlow(dir, ctx.migrations, ctx);\n }\n\n if (!ctx.migrations.emit) {\n throw errorTargetMigrationNotSupported({\n why: `Target \"${ctx.targetId}\" does not implement the class-flow \\`emit\\` capability; cannot emit a migration package`,\n });\n }\n\n const operations = await ctx.migrations.emit({\n dir,\n frameworkComponents: ctx.frameworkComponents,\n });\n const migrationId = await attestMigration(dir);\n return { operations, migrationId };\n}\n\n/**\n * Descriptor flow: evaluate `migration.ts` to obtain a list of operation\n * descriptors, hand them to the target's `resolveDescriptors` along with the\n * manifest's contract bookends, then persist `ops.json` and attest the package.\n */\nasync function emitDescriptorFlow(\n dir: string,\n migrations: TargetMigrationsCapability,\n ctx: EmitMigrationContext,\n): Promise<EmitMigrationResult> {\n assert(\n migrations.resolveDescriptors,\n 'emitDescriptorFlow requires resolveDescriptors; gated by caller',\n );\n const pkg = await readMigrationPackage(dir);\n const descriptors = await evaluateMigrationTs(dir);\n const operations = migrations.resolveDescriptors(descriptors as OperationDescriptor[], {\n fromContract: pkg.manifest.fromContract,\n toContract: pkg.manifest.toContract,\n frameworkComponents: ctx.frameworkComponents,\n });\n await writeMigrationOps(dir, operations);\n const migrationId = await attestMigration(dir);\n return { operations, migrationId };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,SAAgB,kBACd,YACA,UACmB;AACnB,KAAI,WAAW,mBAAoB,QAAO;AAC1C,KAAI,WAAW,KAAM,QAAO;AAC5B,OAAM,8CAA8C,EAAE,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACyBnE,eAAsB,cACpB,KACA,KAC8B;AAC9B,KAAI,CAAE,MAAM,eAAe,IAAI,CAC7B,OAAM,0BAA0B,IAAI;AAKtC,KAFiB,kBAAkB,IAAI,YAAY,IAAI,SAAS,KAE/C,aACf,QAAO,mBAAmB,KAAK,IAAI,YAAY,IAAI;AAGrD,KAAI,CAAC,IAAI,WAAW,KAClB,OAAM,iCAAiC,EACrC,KAAK,WAAW,IAAI,SAAS,2FAC9B,CAAC;AAQJ,QAAO;EAAE,YALU,MAAM,IAAI,WAAW,KAAK;GAC3C;GACA,qBAAqB,IAAI;GAC1B,CAAC;EAEmB,aADD,MAAM,gBAAgB,IAAI;EACZ;;;;;;;AAQpC,eAAe,mBACb,KACA,YACA,KAC8B;AAC9B,QACE,WAAW,oBACX,kEACD;CACD,MAAM,MAAM,MAAM,qBAAqB,IAAI;CAC3C,MAAM,cAAc,MAAM,oBAAoB,IAAI;CAClD,MAAM,aAAa,WAAW,mBAAmB,aAAsC;EACrF,cAAc,IAAI,SAAS;EAC3B,YAAY,IAAI,SAAS;EACzB,qBAAqB,IAAI;EAC1B,CAAC;AACF,OAAM,kBAAkB,KAAK,WAAW;AAExC,QAAO;EAAE;EAAY,aADD,MAAM,gBAAgB,IAAI;EACZ"}
|