prisma-next 0.10.0 → 0.11.0-dev.10
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/cli-errors-Bw2GlweY.mjs +175 -0
- package/dist/cli-errors-Bw2GlweY.mjs.map +1 -0
- package/dist/cli.mjs +400 -13
- package/dist/cli.mjs.map +1 -1
- package/dist/{client-Brv4qlfB.mjs → client-UnIveZxZ.mjs} +6 -5
- package/dist/client-UnIveZxZ.mjs.map +1 -0
- package/dist/{command-helpers-D3vL5yi8.mjs → command-helpers-CRfjbZRz.mjs} +109 -12
- package/dist/command-helpers-CRfjbZRz.mjs.map +1 -0
- package/dist/commands/contract-emit.d.mts.map +1 -1
- package/dist/commands/contract-emit.mjs +1 -1
- package/dist/commands/contract-infer.mjs +1 -1
- package/dist/commands/db-init.d.mts.map +1 -1
- package/dist/commands/db-init.mjs +47 -21
- package/dist/commands/db-init.mjs.map +1 -1
- package/dist/commands/db-schema.mjs +6 -10
- package/dist/commands/db-schema.mjs.map +1 -1
- package/dist/commands/db-sign.mjs +8 -12
- package/dist/commands/db-sign.mjs.map +1 -1
- package/dist/commands/db-update.d.mts.map +1 -1
- package/dist/commands/db-update.mjs +47 -19
- package/dist/commands/db-update.mjs.map +1 -1
- package/dist/commands/db-verify.mjs +1 -1
- package/dist/commands/migrate.d.mts +5 -1
- package/dist/commands/migrate.d.mts.map +1 -1
- package/dist/commands/migrate.mjs +47 -15
- package/dist/commands/migrate.mjs.map +1 -1
- package/dist/commands/migration-check.mjs +5 -8
- package/dist/commands/migration-check.mjs.map +1 -1
- package/dist/commands/migration-graph.d.mts +1 -1
- package/dist/commands/migration-graph.mjs +6 -10
- package/dist/commands/migration-graph.mjs.map +1 -1
- package/dist/commands/migration-list.mjs +5 -9
- package/dist/commands/migration-list.mjs.map +1 -1
- package/dist/commands/migration-log.d.mts.map +1 -1
- package/dist/commands/migration-log.mjs +7 -10
- package/dist/commands/migration-log.mjs.map +1 -1
- package/dist/commands/migration-new.mjs +6 -10
- package/dist/commands/migration-new.mjs.map +1 -1
- package/dist/commands/migration-plan.d.mts +2 -1
- package/dist/commands/migration-plan.d.mts.map +1 -1
- package/dist/commands/migration-plan.mjs +1 -1
- package/dist/commands/migration-show.d.mts +1 -1
- package/dist/commands/migration-show.mjs +9 -13
- package/dist/commands/migration-show.mjs.map +1 -1
- package/dist/commands/migration-status.d.mts +1 -1
- package/dist/commands/migration-status.d.mts.map +1 -1
- package/dist/commands/migration-status.mjs +37 -15
- package/dist/commands/migration-status.mjs.map +1 -1
- package/dist/commands/ref.d.mts +1 -1
- package/dist/commands/ref.d.mts.map +1 -1
- package/dist/commands/ref.mjs +41 -25
- package/dist/commands/ref.mjs.map +1 -1
- package/dist/{contract-emit-iynA3BCA.mjs → contract-emit-C6rlsljO.mjs} +7 -6
- package/dist/contract-emit-C6rlsljO.mjs.map +1 -0
- package/dist/{contract-emit-C3STUIBg.mjs → contract-emit-mqXmapxB.mjs} +22 -20
- package/dist/contract-emit-mqXmapxB.mjs.map +1 -0
- package/dist/{contract-infer-Cnj8G1E2.mjs → contract-infer-C4jxc1aZ.mjs} +9 -14
- package/dist/contract-infer-C4jxc1aZ.mjs.map +1 -0
- package/dist/{contract-space-aggregate-loader-pAc8CDfY.mjs → contract-space-aggregate-loader-CGakRlKM.mjs} +2 -2
- package/dist/{contract-space-aggregate-loader-pAc8CDfY.mjs.map → contract-space-aggregate-loader-CGakRlKM.mjs.map} +1 -1
- package/dist/{db-verify-D7cyH_zz.mjs → db-verify-1d8tDoFN.mjs} +9 -13
- package/dist/db-verify-1d8tDoFN.mjs.map +1 -0
- package/dist/exports/control-api.d.mts +1 -1
- package/dist/exports/control-api.mjs +2 -2
- package/dist/exports/index.mjs +2 -2
- package/dist/exports/init-output.mjs +1 -1
- package/dist/{framework-components-xFLFpZUO.mjs → framework-components-Bexd0f4E.mjs} +2 -2
- package/dist/{framework-components-xFLFpZUO.mjs.map → framework-components-Bexd0f4E.mjs.map} +1 -1
- package/dist/{global-flags-DGmw6Kqg.d.mts → global-flags-CdE7M0d9.d.mts} +4 -1
- package/dist/global-flags-CdE7M0d9.d.mts.map +1 -0
- package/dist/{graph-render-eJDcLWny.mjs → graph-render-BE8vmJ_7.mjs} +1 -1
- package/dist/{graph-render-eJDcLWny.mjs.map → graph-render-BE8vmJ_7.mjs.map} +1 -1
- package/dist/{init-eh2z5Tl6.mjs → init-ByoeQphC.mjs} +528 -627
- package/dist/init-ByoeQphC.mjs.map +1 -0
- package/dist/{inspect-live-schema-CWLK_lgs.mjs → inspect-live-schema-B1Q49RF0.mjs} +4 -4
- package/dist/{inspect-live-schema-CWLK_lgs.mjs.map → inspect-live-schema-B1Q49RF0.mjs.map} +1 -1
- package/dist/{migration-command-scaffold-CmXXC1UZ.mjs → migration-command-scaffold-oY4P1Qto.mjs} +4 -4
- package/dist/{migration-command-scaffold-CmXXC1UZ.mjs.map → migration-command-scaffold-oY4P1Qto.mjs.map} +1 -1
- package/dist/{migration-plan-CHyUlBV0.mjs → migration-plan-jdAHg_gK.mjs} +349 -94
- package/dist/migration-plan-jdAHg_gK.mjs.map +1 -0
- package/dist/{migration-types-D2FW63pr.d.mts → migration-types-BXWvz12q.d.mts} +1 -1
- package/dist/{migration-types-D2FW63pr.d.mts.map → migration-types-BXWvz12q.d.mts.map} +1 -1
- package/dist/{migrations-DyUf5lTt.mjs → migrations-B7n518mT.mjs} +11 -2
- package/dist/migrations-B7n518mT.mjs.map +1 -0
- package/dist/{output-B60Gw5fu.mjs → output-CUIdfYo5.mjs} +1 -1
- package/dist/{output-B60Gw5fu.mjs.map → output-CUIdfYo5.mjs.map} +1 -1
- package/dist/quick-reference-mongo.md +1 -1
- package/dist/quick-reference-postgres.md +1 -1
- package/dist/readme-mongo.md +35 -0
- package/dist/readme-postgres.md +34 -0
- package/dist/ref-advancement-DRh5Nquq.mjs +50 -0
- package/dist/ref-advancement-DRh5Nquq.mjs.map +1 -0
- package/dist/{terminal-ui-XtOQsqe9.mjs → terminal-ui-BiB_8KNo.mjs} +131 -24
- package/dist/terminal-ui-BiB_8KNo.mjs.map +1 -0
- package/dist/{types-0aS865QN.d.mts → types-UWB2-rrw.d.mts} +12 -4
- package/dist/types-UWB2-rrw.d.mts.map +1 -0
- package/dist/{verify-D7ypCCe6.mjs → verify-C5UvbrF1.mjs} +2 -2
- package/dist/{verify-D7ypCCe6.mjs.map → verify-C5UvbrF1.mjs.map} +1 -1
- package/package.json +13 -11
- package/dist/cli-errors-CF60g2cG.mjs +0 -71
- package/dist/cli-errors-CF60g2cG.mjs.map +0 -1
- package/dist/cli-errors-DdcjVLJV.d.mts +0 -3
- package/dist/client-Brv4qlfB.mjs.map +0 -1
- package/dist/command-helpers-D3vL5yi8.mjs.map +0 -1
- package/dist/contract-emit-C3STUIBg.mjs.map +0 -1
- package/dist/contract-emit-iynA3BCA.mjs.map +0 -1
- package/dist/contract-infer-Cnj8G1E2.mjs.map +0 -1
- package/dist/db-verify-D7cyH_zz.mjs.map +0 -1
- package/dist/errors-Cw6kyTyV.mjs +0 -56
- package/dist/errors-Cw6kyTyV.mjs.map +0 -1
- package/dist/global-flags-DGmw6Kqg.d.mts.map +0 -1
- package/dist/helpers-eqdN8tH6.mjs +0 -25
- package/dist/helpers-eqdN8tH6.mjs.map +0 -1
- package/dist/init-eh2z5Tl6.mjs.map +0 -1
- package/dist/migration-plan-CHyUlBV0.mjs.map +0 -1
- package/dist/migrations-DyUf5lTt.mjs.map +0 -1
- package/dist/result-handler-Bm_6dDYg.mjs +0 -25
- package/dist/result-handler-Bm_6dDYg.mjs.map +0 -1
- package/dist/terminal-ui-XtOQsqe9.mjs.map +0 -1
- package/dist/types-0aS865QN.d.mts.map +0 -1
package/dist/cli.mjs
CHANGED
|
@@ -1,27 +1,397 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import { t as
|
|
4
|
-
import {
|
|
5
|
-
import { t as createContractInferCommand } from "./contract-infer-
|
|
2
|
+
import { a as isCI, n as installShutdownHandlers } from "./terminal-ui-BiB_8KNo.mjs";
|
|
3
|
+
import { _ as parseGlobalFlags, b as formatCommandHelp, d as setCommandDescriptions, f as setCommandExamples, t as addGlobalOptions, v as parseGlobalFlagsOrExit, x as formatRootHelp } from "./command-helpers-CRfjbZRz.mjs";
|
|
4
|
+
import { t as createContractEmitCommand } from "./contract-emit-mqXmapxB.mjs";
|
|
5
|
+
import { t as createContractInferCommand } from "./contract-infer-C4jxc1aZ.mjs";
|
|
6
6
|
import { createDbInitCommand } from "./commands/db-init.mjs";
|
|
7
7
|
import { createDbSchemaCommand } from "./commands/db-schema.mjs";
|
|
8
8
|
import { createDbSignCommand } from "./commands/db-sign.mjs";
|
|
9
9
|
import { createDbUpdateCommand } from "./commands/db-update.mjs";
|
|
10
|
-
import { t as createDbVerifyCommand } from "./db-verify-
|
|
10
|
+
import { t as createDbVerifyCommand } from "./db-verify-1d8tDoFN.mjs";
|
|
11
11
|
import { createMigrateCommand } from "./commands/migrate.mjs";
|
|
12
12
|
import { createMigrationCheckCommand } from "./commands/migration-check.mjs";
|
|
13
13
|
import { createMigrationGraphCommand } from "./commands/migration-graph.mjs";
|
|
14
14
|
import { createMigrationListCommand } from "./commands/migration-list.mjs";
|
|
15
15
|
import { createMigrationLogCommand } from "./commands/migration-log.mjs";
|
|
16
16
|
import { createMigrationNewCommand } from "./commands/migration-new.mjs";
|
|
17
|
-
import { t as createMigrationPlanCommand } from "./migration-plan-
|
|
17
|
+
import { t as createMigrationPlanCommand } from "./migration-plan-jdAHg_gK.mjs";
|
|
18
18
|
import { createMigrationShowCommand } from "./commands/migration-show.mjs";
|
|
19
19
|
import { createMigrationStatusCommand } from "./commands/migration-status.mjs";
|
|
20
20
|
import { createRefCommand } from "./commands/ref.mjs";
|
|
21
21
|
import { Command } from "commander";
|
|
22
|
+
import { ifDefined } from "@prisma-next/utils/defined";
|
|
23
|
+
import { DEFAULT_CONTRACT_SOURCE_DIR } from "@prisma-next/config/config-types";
|
|
24
|
+
import { fileURLToPath } from "node:url";
|
|
25
|
+
import { readUserConfig, resolveGating, runTelemetry } from "@prisma-next/cli-telemetry";
|
|
22
26
|
import { distance } from "closest-match";
|
|
23
27
|
//#region package.json
|
|
24
|
-
var version = "0.
|
|
28
|
+
var version = "0.11.0-dev.10";
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region src/utils/telemetry.ts
|
|
31
|
+
/**
|
|
32
|
+
* Resolve the commander command path from a leaf `Command`, walking up
|
|
33
|
+
* the parent chain. Result is rooted at the program name and ends at
|
|
34
|
+
* the leaf — `['prisma-next', 'migration', 'new']` for
|
|
35
|
+
* `prisma-next migration new …`.
|
|
36
|
+
*/
|
|
37
|
+
function commandPathFor(actionCommand) {
|
|
38
|
+
const path = [];
|
|
39
|
+
let cursor = actionCommand;
|
|
40
|
+
while (cursor !== null) {
|
|
41
|
+
path.unshift(cursor.name());
|
|
42
|
+
cursor = cursor.parent;
|
|
43
|
+
}
|
|
44
|
+
return path;
|
|
45
|
+
}
|
|
46
|
+
function commanderOptionSnapshots(actionCommand) {
|
|
47
|
+
return actionCommand.options.map((option) => {
|
|
48
|
+
const attributeName = option.attributeName();
|
|
49
|
+
return {
|
|
50
|
+
attributeName,
|
|
51
|
+
longName: option.long ?? null,
|
|
52
|
+
source: actionCommand.getOptionValueSource(attributeName) ?? null
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Project commander's leaf `Command` into the wire-shape snapshot the
|
|
58
|
+
* telemetry sanitiser consumes. Pure projection — no env, no I/O.
|
|
59
|
+
*/
|
|
60
|
+
function commanderSnapshotForTelemetry(actionCommand) {
|
|
61
|
+
return {
|
|
62
|
+
commandPath: commandPathFor(actionCommand),
|
|
63
|
+
positionalArgs: actionCommand.args,
|
|
64
|
+
options: commanderOptionSnapshots(actionCommand)
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function resolveTelemetryGate() {
|
|
68
|
+
if (isCI()) return {
|
|
69
|
+
enabled: false,
|
|
70
|
+
outcome: {
|
|
71
|
+
spawned: false,
|
|
72
|
+
reason: "ci"
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
const userConfig = readUserConfig();
|
|
76
|
+
if (!resolveGating({
|
|
77
|
+
env: process.env,
|
|
78
|
+
config: userConfig
|
|
79
|
+
}).enabled) return {
|
|
80
|
+
enabled: false,
|
|
81
|
+
outcome: {
|
|
82
|
+
spawned: false,
|
|
83
|
+
reason: "gated-off"
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
return {
|
|
87
|
+
enabled: true,
|
|
88
|
+
userConfig
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Path to the compiled sender script inside `@prisma-next/cli-telemetry`'s
|
|
93
|
+
* `dist/`. Resolved off this module's `import.meta.url` via the package
|
|
94
|
+
* specifier `@prisma-next/cli-telemetry/sender`, so the consumer pays
|
|
95
|
+
* no attention to internal package layout.
|
|
96
|
+
*/
|
|
97
|
+
function senderPath() {
|
|
98
|
+
return fileURLToPath(new URL(import.meta.resolve("@prisma-next/cli-telemetry/sender")));
|
|
99
|
+
}
|
|
100
|
+
function fireTelemetry(actionCommand, userConfig, overrides = {}) {
|
|
101
|
+
return runTelemetry({
|
|
102
|
+
command: commanderSnapshotForTelemetry(actionCommand),
|
|
103
|
+
version,
|
|
104
|
+
projectRoot: process.cwd(),
|
|
105
|
+
senderPath: senderPath(),
|
|
106
|
+
isCI: isCI(),
|
|
107
|
+
env: process.env,
|
|
108
|
+
userConfig,
|
|
109
|
+
...ifDefined("databaseTarget", overrides.databaseTarget)
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* preAction-stage entry point. Synchronous by construction: resolve
|
|
114
|
+
* env/CI/user-consent gates (cheap, all in-memory and a single tiny
|
|
115
|
+
* user-config read), then — only when enabled — `fork()` the detached
|
|
116
|
+
* sender script. The forked child loads `prisma-next.config.*` via
|
|
117
|
+
* c12 on its own (see `loadProjectConfig` in cli-telemetry); the
|
|
118
|
+
* parent does no project-config I/O on the command's hot path.
|
|
119
|
+
*
|
|
120
|
+
* Privacy invariant: gate resolution always happens before any project
|
|
121
|
+
* config touches disk. The child loading user TS code is acceptable
|
|
122
|
+
* only because it's gated behind the same resolved-enabled signal.
|
|
123
|
+
*/
|
|
124
|
+
function fireTelemetryFromPreAction(actionCommand) {
|
|
125
|
+
const gate = resolveTelemetryGate();
|
|
126
|
+
if (!gate.enabled) return gate.outcome;
|
|
127
|
+
return fireTelemetry(actionCommand, gate.userConfig);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Manual one-shot telemetry path for the first `init` run where the user
|
|
131
|
+
* explicitly answers Yes to the consent prompt. The preAction hook for
|
|
132
|
+
* that same run has already resolved before consent existed, so it is
|
|
133
|
+
* default-off. After consent is persisted, `runInit` calls this helper
|
|
134
|
+
* exactly for that first affirmative answer; subsequent init runs skip
|
|
135
|
+
* it because the prompt is not shown again.
|
|
136
|
+
*
|
|
137
|
+
* The child's c12 load would return `databaseTarget: null` for this
|
|
138
|
+
* specific invocation because `prisma-next.config.*` is not yet on
|
|
139
|
+
* disk (init writes it later in the same run). To preserve the
|
|
140
|
+
* prompt-chosen target in the first-init telemetry event, this
|
|
141
|
+
* helper forwards the value as a parent-side IPC override on
|
|
142
|
+
* `ParentToSenderPayload.databaseTarget` — the child consults the
|
|
143
|
+
* override first and falls back to its c12 result when absent.
|
|
144
|
+
*/
|
|
145
|
+
function fireTelemetryAfterInitConsent(actionCommand, inputs) {
|
|
146
|
+
return fireTelemetry(actionCommand, readUserConfig(), { databaseTarget: inputs.databaseTarget });
|
|
147
|
+
}
|
|
148
|
+
//#endregion
|
|
149
|
+
//#region src/commands/init/templates/code-templates.ts
|
|
150
|
+
function targetPackageName(target) {
|
|
151
|
+
return target === "postgres" ? "@prisma-next/postgres" : "@prisma-next/mongo";
|
|
152
|
+
}
|
|
153
|
+
function targetLabel(target) {
|
|
154
|
+
return target === "postgres" ? "PostgreSQL" : "MongoDB";
|
|
155
|
+
}
|
|
156
|
+
function defaultSchemaPath(authoring) {
|
|
157
|
+
if (authoring === "typescript") return `${DEFAULT_CONTRACT_SOURCE_DIR}/contract.ts`;
|
|
158
|
+
return `${DEFAULT_CONTRACT_SOURCE_DIR}/contract.prisma`;
|
|
159
|
+
}
|
|
160
|
+
function starterSchema(target, authoring) {
|
|
161
|
+
if (authoring === "typescript") return target === "mongo" ? starterSchemaTsMongo() : starterSchemaTsPostgres();
|
|
162
|
+
return target === "mongo" ? starterSchemaPslMongo() : starterSchemaPslPostgres();
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Renders a short authoring-appropriate schema sample (FR5.1) for embedding
|
|
166
|
+
* in `prisma-next.md`. Returns a complete fenced markdown code block.
|
|
167
|
+
*
|
|
168
|
+
* The sample intentionally shows just one model: it's illustrative, not
|
|
169
|
+
* a substitute for the full scaffolded contract file. The TS samples use
|
|
170
|
+
* the same outer shape as `starterSchemaTs*` (FR5.3) so a user reading
|
|
171
|
+
* the doc and the file side-by-side sees the same structure.
|
|
172
|
+
*/
|
|
173
|
+
function schemaSample(target, authoring) {
|
|
174
|
+
if (authoring === "typescript") return target === "mongo" ? schemaSampleTsMongo() : schemaSampleTsPostgres();
|
|
175
|
+
return target === "mongo" ? schemaSamplePslMongo() : schemaSamplePslPostgres();
|
|
176
|
+
}
|
|
177
|
+
function schemaSamplePslPostgres() {
|
|
178
|
+
return `\`\`\`prisma
|
|
179
|
+
model User {
|
|
180
|
+
id Int @id @default(autoincrement())
|
|
181
|
+
email String @unique
|
|
182
|
+
username String?
|
|
183
|
+
name String?
|
|
184
|
+
}
|
|
185
|
+
\`\`\``;
|
|
186
|
+
}
|
|
187
|
+
function schemaSamplePslMongo() {
|
|
188
|
+
return `\`\`\`prisma
|
|
189
|
+
model User {
|
|
190
|
+
id ObjectId @id @map("_id")
|
|
191
|
+
email String @unique
|
|
192
|
+
username String?
|
|
193
|
+
name String?
|
|
194
|
+
@@map("users")
|
|
195
|
+
}
|
|
196
|
+
\`\`\``;
|
|
197
|
+
}
|
|
198
|
+
function schemaSampleTsPostgres() {
|
|
199
|
+
return `\`\`\`typescript
|
|
200
|
+
import { defineContract } from '@prisma-next/postgres/contract-builder';
|
|
201
|
+
|
|
202
|
+
export const contract = defineContract(
|
|
203
|
+
{},
|
|
204
|
+
({ field, model }) => ({
|
|
205
|
+
models: {
|
|
206
|
+
User: model('User', {
|
|
207
|
+
fields: {
|
|
208
|
+
id: field.id.uuidv7(),
|
|
209
|
+
email: field.text().unique(),
|
|
210
|
+
username: field.text().optional(),
|
|
211
|
+
name: field.text().optional(),
|
|
212
|
+
},
|
|
213
|
+
}),
|
|
214
|
+
},
|
|
215
|
+
}),
|
|
216
|
+
);
|
|
217
|
+
\`\`\``;
|
|
218
|
+
}
|
|
219
|
+
function schemaSampleTsMongo() {
|
|
220
|
+
return `\`\`\`typescript
|
|
221
|
+
import { defineContract } from '@prisma-next/mongo/contract-builder';
|
|
222
|
+
|
|
223
|
+
export const contract = defineContract(
|
|
224
|
+
{},
|
|
225
|
+
({ field, model }) => ({
|
|
226
|
+
models: {
|
|
227
|
+
User: model('User', {
|
|
228
|
+
collection: 'users',
|
|
229
|
+
fields: {
|
|
230
|
+
_id: field.objectId(),
|
|
231
|
+
email: field.string(),
|
|
232
|
+
username: field.string().optional(),
|
|
233
|
+
name: field.string().optional(),
|
|
234
|
+
},
|
|
235
|
+
}),
|
|
236
|
+
},
|
|
237
|
+
}),
|
|
238
|
+
);
|
|
239
|
+
\`\`\``;
|
|
240
|
+
}
|
|
241
|
+
function starterSchemaPslPostgres() {
|
|
242
|
+
return `// use prisma-next
|
|
243
|
+
|
|
244
|
+
model User {
|
|
245
|
+
id Int @id @default(autoincrement())
|
|
246
|
+
email String @unique
|
|
247
|
+
username String?
|
|
248
|
+
name String?
|
|
249
|
+
posts Post[]
|
|
250
|
+
createdAt DateTime @default(now())
|
|
251
|
+
updatedAt temporal.updatedAt()
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
model Post {
|
|
255
|
+
id Int @id @default(autoincrement())
|
|
256
|
+
title String
|
|
257
|
+
content String?
|
|
258
|
+
author User @relation(fields: [authorId], references: [id])
|
|
259
|
+
authorId Int
|
|
260
|
+
createdAt DateTime @default(now())
|
|
261
|
+
updatedAt temporal.updatedAt()
|
|
262
|
+
}
|
|
263
|
+
`;
|
|
264
|
+
}
|
|
265
|
+
function starterSchemaPslMongo() {
|
|
266
|
+
return `// use prisma-next
|
|
267
|
+
|
|
268
|
+
model User {
|
|
269
|
+
id ObjectId @id @map("_id")
|
|
270
|
+
email String @unique
|
|
271
|
+
username String?
|
|
272
|
+
name String?
|
|
273
|
+
posts Post[]
|
|
274
|
+
@@map("users")
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
model Post {
|
|
278
|
+
id ObjectId @id @map("_id")
|
|
279
|
+
title String
|
|
280
|
+
content String?
|
|
281
|
+
author User @relation(fields: [authorId], references: [id])
|
|
282
|
+
authorId ObjectId
|
|
283
|
+
@@map("posts")
|
|
284
|
+
}
|
|
285
|
+
`;
|
|
286
|
+
}
|
|
287
|
+
function starterSchemaTsPostgres() {
|
|
288
|
+
return `import { defineContract } from '@prisma-next/postgres/contract-builder';
|
|
289
|
+
|
|
290
|
+
export const contract = defineContract(
|
|
291
|
+
{},
|
|
292
|
+
({ field, model, rel }) => ({
|
|
293
|
+
models: {
|
|
294
|
+
User: model('User', {
|
|
295
|
+
fields: {
|
|
296
|
+
id: field.id.uuidv7(),
|
|
297
|
+
email: field.text().unique(),
|
|
298
|
+
username: field.text().optional(),
|
|
299
|
+
name: field.text().optional(),
|
|
300
|
+
createdAt: field.temporal.createdAt(),
|
|
301
|
+
updatedAt: field.temporal.updatedAt(),
|
|
302
|
+
},
|
|
303
|
+
relations: {
|
|
304
|
+
posts: rel.hasMany('Post', { by: 'authorId' }),
|
|
305
|
+
},
|
|
306
|
+
}),
|
|
307
|
+
|
|
308
|
+
Post: model('Post', {
|
|
309
|
+
fields: {
|
|
310
|
+
id: field.id.uuidv7(),
|
|
311
|
+
title: field.text(),
|
|
312
|
+
content: field.text().optional(),
|
|
313
|
+
authorId: field.uuid(),
|
|
314
|
+
createdAt: field.temporal.createdAt(),
|
|
315
|
+
updatedAt: field.temporal.updatedAt(),
|
|
316
|
+
},
|
|
317
|
+
relations: {
|
|
318
|
+
author: rel.belongsTo('User', { from: 'authorId', to: 'id' }),
|
|
319
|
+
},
|
|
320
|
+
}),
|
|
321
|
+
},
|
|
322
|
+
}),
|
|
323
|
+
);
|
|
324
|
+
`;
|
|
325
|
+
}
|
|
326
|
+
function starterSchemaTsMongo() {
|
|
327
|
+
return `import { defineContract } from '@prisma-next/mongo/contract-builder';
|
|
328
|
+
|
|
329
|
+
export const contract = defineContract(
|
|
330
|
+
{},
|
|
331
|
+
({ field, model, rel }) => ({
|
|
332
|
+
models: {
|
|
333
|
+
User: model('User', {
|
|
334
|
+
collection: 'users',
|
|
335
|
+
fields: {
|
|
336
|
+
_id: field.objectId(),
|
|
337
|
+
email: field.string(),
|
|
338
|
+
username: field.string().optional(),
|
|
339
|
+
name: field.string().optional(),
|
|
340
|
+
},
|
|
341
|
+
relations: {
|
|
342
|
+
posts: rel.hasMany('Post', { from: '_id', to: 'authorId' }),
|
|
343
|
+
},
|
|
344
|
+
}),
|
|
345
|
+
|
|
346
|
+
Post: model('Post', {
|
|
347
|
+
collection: 'posts',
|
|
348
|
+
fields: {
|
|
349
|
+
_id: field.objectId(),
|
|
350
|
+
title: field.string(),
|
|
351
|
+
content: field.string().optional(),
|
|
352
|
+
authorId: field.objectId(),
|
|
353
|
+
},
|
|
354
|
+
relations: {
|
|
355
|
+
author: rel.belongsTo('User', { from: 'authorId', to: '_id' }),
|
|
356
|
+
},
|
|
357
|
+
}),
|
|
358
|
+
},
|
|
359
|
+
}),
|
|
360
|
+
);
|
|
361
|
+
`;
|
|
362
|
+
}
|
|
363
|
+
function configFile(target, contractPath) {
|
|
364
|
+
return `import 'dotenv/config';
|
|
365
|
+
import { defineConfig } from '${targetPackageName(target)}/config';
|
|
366
|
+
|
|
367
|
+
export default defineConfig({
|
|
368
|
+
contract: ${JSON.stringify(contractPath)},
|
|
369
|
+
db: {
|
|
370
|
+
connection: process.env['DATABASE_URL']!,
|
|
371
|
+
},
|
|
372
|
+
});
|
|
373
|
+
`;
|
|
374
|
+
}
|
|
375
|
+
function dbFile(target) {
|
|
376
|
+
if (target === "postgres") return `import postgres from '@prisma-next/postgres/runtime';
|
|
377
|
+
import type { Contract } from './contract.d';
|
|
378
|
+
import contractJson from './contract.json' with { type: 'json' };
|
|
379
|
+
|
|
380
|
+
export const db = postgres<Contract>({
|
|
381
|
+
contractJson,
|
|
382
|
+
url: process.env['DATABASE_URL']!,
|
|
383
|
+
});
|
|
384
|
+
`;
|
|
385
|
+
return `import mongo from '@prisma-next/mongo/runtime';
|
|
386
|
+
import type { Contract } from './contract.d';
|
|
387
|
+
import contractJson from './contract.json' with { type: 'json' };
|
|
388
|
+
|
|
389
|
+
export const db = mongo<Contract>({
|
|
390
|
+
contractJson,
|
|
391
|
+
url: process.env['DATABASE_URL']!,
|
|
392
|
+
});
|
|
393
|
+
`;
|
|
394
|
+
}
|
|
25
395
|
//#endregion
|
|
26
396
|
//#region src/commands/init/index.ts
|
|
27
397
|
function createInitCommand() {
|
|
@@ -40,11 +410,11 @@ Exit codes (see CLI Style Guide § Exit Codes):
|
|
|
40
410
|
"prisma-next init --yes --target mongodb --authoring typescript --json",
|
|
41
411
|
"prisma-next init --yes --force --target postgres --authoring psl # overwrite an existing scaffold",
|
|
42
412
|
"prisma-next init --no-install # skip pnpm/npm install + emit",
|
|
43
|
-
"prisma-next init --no-skill # skip the
|
|
413
|
+
"prisma-next init --no-skill # skip the skills install (air-gapped / restricted env)"
|
|
44
414
|
]);
|
|
45
|
-
return addGlobalOptions(command).option("--target <db>", "Database target: postgres or mongodb").option("--authoring <style>", "Schema authoring style: psl or typescript").option("--schema-path <path>",
|
|
46
|
-
const { runInit } = await import("./init-
|
|
47
|
-
const flags =
|
|
415
|
+
return addGlobalOptions(command).option("--target <db>", "Database target: postgres or mongodb").option("--authoring <style>", "Schema authoring style: psl or typescript").option("--schema-path <path>", `Where to write the starter schema (default: ${defaultSchemaPath("psl")})`).option("--force", "Overwrite an existing scaffold without prompting").option("--write-env", "Write a .env file from .env.example (gitignored; default: only .env.example)").option("--probe-db", "Connect to DATABASE_URL once and check the server version against the target minimum (opt-in; off by default)").option("--strict-probe", "Treat a failed --probe-db as fatal (no-op without --probe-db; init is offline-by-default)").option("--no-install", "Skip dependency installation and contract emission").option("--no-skill", "Skip Prisma Next skills install (air-gapped CI, restricted registries, etc.)").action(async (options, actionCommand) => {
|
|
416
|
+
const { runInit } = await import("./init-ByoeQphC.mjs");
|
|
417
|
+
const flags = parseGlobalFlagsOrExit(options);
|
|
48
418
|
const canPrompt = deriveCanPrompt({
|
|
49
419
|
flagsInteractive: flags.interactive,
|
|
50
420
|
optionInteractive: options.interactive,
|
|
@@ -53,7 +423,10 @@ Exit codes (see CLI Style Guide § Exit Codes):
|
|
|
53
423
|
const exitCode = await runInit(process.cwd(), {
|
|
54
424
|
options,
|
|
55
425
|
flags,
|
|
56
|
-
canPrompt
|
|
426
|
+
canPrompt,
|
|
427
|
+
afterFirstTelemetryConsent: (inputs) => {
|
|
428
|
+
fireTelemetryAfterInitConsent(actionCommand, { databaseTarget: inputs.target });
|
|
429
|
+
}
|
|
57
430
|
});
|
|
58
431
|
process.exit(exitCode);
|
|
59
432
|
});
|
|
@@ -137,6 +510,11 @@ function formatSuggestion(input, candidates) {
|
|
|
137
510
|
}
|
|
138
511
|
const program = new Command();
|
|
139
512
|
program.name("prisma-next").description("Prisma Next CLI").version(version);
|
|
513
|
+
program.hook("preAction", (_thisCommand, actionCommand) => {
|
|
514
|
+
try {
|
|
515
|
+
fireTelemetryFromPreAction(actionCommand);
|
|
516
|
+
} catch {}
|
|
517
|
+
});
|
|
140
518
|
const versionOption = program.options.find((opt) => opt.flags.includes("--version"));
|
|
141
519
|
if (versionOption) versionOption.description = "Output the version number";
|
|
142
520
|
program.configureOutput({
|
|
@@ -272,6 +650,15 @@ program.addCommand(contractCommand);
|
|
|
272
650
|
program.addCommand(dbCommand);
|
|
273
651
|
program.addCommand(migrationCommand);
|
|
274
652
|
program.addCommand(refCommand);
|
|
653
|
+
const TELEMETRY_CRASH_TEST_SLEEP_MS = 200;
|
|
654
|
+
if (process.env["PRISMA_NEXT_ENABLE_TEST_COMMANDS"] === "1") {
|
|
655
|
+
const telemetryCrashTestCommand = new Command("__telemetry-crash-test").description("Internal: deliberately throw for the telemetry e2e suite.").action(async () => {
|
|
656
|
+
await new Promise((settle) => setTimeout(settle, TELEMETRY_CRASH_TEST_SLEEP_MS));
|
|
657
|
+
throw new Error("__telemetry-crash-test: intentional crash for e2e coverage");
|
|
658
|
+
});
|
|
659
|
+
telemetryCrashTestCommand.configureHelp({ visibleCommands: () => [] });
|
|
660
|
+
program.addCommand(telemetryCrashTestCommand, { hidden: true });
|
|
661
|
+
}
|
|
275
662
|
const helpCommand = new Command("help").description("Show usage instructions").configureHelp({ formatHelp: (cmd) => {
|
|
276
663
|
return formatCommandHelp({
|
|
277
664
|
command: cmd,
|
|
@@ -342,6 +729,6 @@ if (args.length > 0) {
|
|
|
342
729
|
}
|
|
343
730
|
program.parse();
|
|
344
731
|
//#endregion
|
|
345
|
-
export { version as t };
|
|
732
|
+
export { starterSchema as a, version as c, schemaSample as i, dbFile as n, targetLabel as o, defaultSchemaPath as r, targetPackageName as s, configFile as t };
|
|
346
733
|
|
|
347
734
|
//# sourceMappingURL=cli.mjs.map
|