@prisma/orm-toolchain 8.0.0-rc.24-dev.32 → 8.0.0-rc.24-dev.34

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.mjs CHANGED
@@ -11,7 +11,7 @@ import { i as readRef, n as advanceRef } from "./refs-t_JbIjGo-BVCqKpXd.mjs";
11
11
  import { a as contractHashAtMarker } from "./aggregate-7sB4u_aJ.mjs";
12
12
  import { o as isLiveMarkerRef } from "./ref-resolution-C0xsiRig.mjs";
13
13
  import { $ as planEverySpace, A as executeMigrationNewCommand, B as labelsText, C as errorPermitPolicyChangeNeedsRef, Ct as statusForMigrationHash, Et as withWarningFindings, F as executeRefSetCommand, G as loadContractSource, H as liveMarkerUse, I as findPackageByDirPath, J as looksLikePath, K as loadContractSourceWithStack, L as formatSourceDiagnostic, N as executeRefDeleteCommand, P as executeRefListCommand, Q as migrationSpaceListEntriesFromAggregate, R as hasMigrationPath, S as enumerateCheckSpaces, St as sourceWarningDiagnostic, Tt as validateLoadedContract, U as loadAggregateIntegrityViolations, V as listRefsByContractHash, W as loadContractRawSafely, Y as mapContractAtError, Z as matchConsents, _ as databasePoliciesInForce, a as advanceRefSafely, at as refusePackageCorruptionOnAggregate, bt as skippedOperationsText, ct as requireDatabaseForLiveMarkerUse, d as buildRefAdvancementFields, dt as resolveContractRefToSnapshot, et as preflightRefAdvancement, f as checkSingleTarget, g as createControlClient, gt as retryCommandFor, h as convertAndDelete, i as RECORDED_OR_EMPTY_CONTRACT_REF_FORMS, it as refuseMissingInvariantPath, j as executeMigrationPlanCommand, k as executeMigrateShowPlan, l as buildMigrationSpaceGraphEntries, lt as resolveAppTargetPath, m as contractValidationMeta, n as NO_REF_ADVANCEMENT, nt as refuseContractSpaceIntegrity, ot as refuseUnknownInvariants, p as computeRefAdvancementName, pt as resolveMigrationRef, q as loadContractSpaceAggregateForCli, r as RECORDED_CONTRACT_REF_FORMS, s as appliedHashesFromLedger, st as renamedAndDeleted, t as ALL_CONTRACT_REF_FORMS, tt as readMigrationRefs, u as buildReadAggregate, ut as resolveContractRef$1, v as declaredSettingsText, vt as runMigrationCheck, w as executeContractEmit, wt as toDeclaredExtensionsFromRaw, xt as snapshotVerifierFor, y as deriveStatusEdgeAnnotations, yt as runMigrationList, z as isStatementVerb } from "./ref-Cdgyujqe-KrdBPcA7.mjs";
14
- import { a as PRISMA7_LOOP_STEP, c as buildNextSteps, d as findTargetByProvider, i as NEXT_STEPS_BEFORE_SCAFFOLD, l as findPrisma6OnlyTarget, n as InitOutputSchema, o as PRISMA7_QUICK_REFERENCE_STEP, r as KNOWN_TARGET_PACKAGES, s as TARGET_SHORT_NAMES, t as DB_SIGN_STEP, u as findTargetByName } from "./output-E6F4-EMc-CqlzGlv-.mjs";
14
+ import { a as PRISMA7_QUICK_REFERENCE_STEP, i as PRISMA7_LOOP_STEP, n as InitOutputSchema, o as buildNextSteps, r as NEXT_STEPS_BEFORE_SCAFFOLD, t as DB_SIGN_STEP } from "./output-BV7p64ql-nFpstc7l.mjs";
15
15
  import { a as resolveGating, i as readUserConfig, r as ensureInstallationId, s as runTelemetry, u as userConfigPath } from "./exports-DwuO4y2c.mjs";
16
16
  import { createRequire } from "node:module";
17
17
  import { ifDefined } from "@prisma/orm-framework/utils/defined";
@@ -35,14 +35,15 @@ import { DEFAULT_CONTRACT_SOURCE_DIR, defaultContractOutputPath } from "@prisma/
35
35
  import { EOL, tmpdir } from "node:os";
36
36
  import { format } from "@prisma/orm-framework/psl-parser/format";
37
37
  import { spawn, spawnSync } from "node:child_process";
38
+ import validatePackageName from "validate-npm-package-name";
38
39
  import { detect } from "package-manager-detector/detect";
39
40
  import { applyEdits, modify, parse, printParseErrorCode } from "jsonc-parser";
40
41
  import stringWidth from "string-width";
41
42
  import { bold, createColors, cyan, cyanBright, dim, green, yellow } from "colorette";
42
43
  import { isCI } from "ci-info";
43
44
  import { build } from "esbuild";
44
- //#region ../../../1-framework/3-tooling/cli/dist/cli-DHiHzWlW.mjs
45
- var version = "8.0.0-rc.24-dev.32";
45
+ //#region ../../../1-framework/3-tooling/cli/dist/cli-Bo71C7T4.mjs
46
+ var version = "8.0.0-rc.24-dev.34";
46
47
  const ESCAPES = {
47
48
  "\\": "\\\\",
48
49
  " ": "\\t",
@@ -161,6 +162,8 @@ function normalizeError(error) {
161
162
  * to catch it outside the outermost boundary: it means an invariant broke, which is a bug in
162
163
  * Prisma ORM rather than something the user did. Re-throwing lets the engine settle it as a bug
163
164
  * at exit 1, where converting it would report the same number as a bad connection string.
165
+ *
166
+ * The reason of a cancelled run is not converted either, so the engine settles the run as cancelled.
164
167
  */
165
168
  function defineOrmCommand(def) {
166
169
  return defineCommand({
@@ -169,7 +172,7 @@ function defineOrmCommand(def) {
169
172
  try {
170
173
  return await def.handler(args, ctx);
171
174
  } catch (error) {
172
- if (isInternalError(error)) throw error;
175
+ if (isInternalError(error) || ctx.signal.aborted && error === ctx.signal.reason) throw error;
173
176
  return notOk$1(normalizeError(error));
174
177
  }
175
178
  }
@@ -3462,6 +3465,79 @@ function buildCatalogWarnings(baseDir, packages) {
3462
3465
  if (result === null || result.entries.length === 0) return [];
3463
3466
  return [formatCatalogWarning(result.workspaceFile, result.entries)];
3464
3467
  }
3468
+ const KNOWN_TARGET_PACKAGES = [{
3469
+ shortName: "postgres",
3470
+ aliases: ["postgresql"],
3471
+ packageName: "@prisma/orm-postgres",
3472
+ workspacePackageName: "@internal/postgres",
3473
+ label: "PostgreSQL",
3474
+ provider: {
3475
+ name: "postgresql",
3476
+ writtenBy: 7
3477
+ },
3478
+ peerPackages: ["pg"]
3479
+ }, {
3480
+ shortName: "mongodb",
3481
+ aliases: ["mongo"],
3482
+ packageName: "@prisma/orm-mongo",
3483
+ workspacePackageName: "@internal/mongo",
3484
+ label: "MongoDB",
3485
+ provider: {
3486
+ name: "mongodb",
3487
+ writtenBy: 6
3488
+ },
3489
+ peerPackages: ["mongodb"]
3490
+ }];
3491
+ const TARGET_SHORT_NAMES = KNOWN_TARGET_PACKAGES.map((entry) => entry.shortName);
3492
+ /** The flag's placeholder word; the usage line puts it in angle brackets itself. */
3493
+ const TARGET_FLAG_PLACEHOLDER = "package";
3494
+ /** Stands for a target package's name wherever `init` shows what `--target` takes. */
3495
+ const PACKAGE_NAME_PLACEHOLDER = `<${TARGET_FLAG_PLACEHOLDER}>`;
3496
+ /** What init requires in the `keywords` of a target package's `package.json` before it installs or uses one. */
3497
+ const PRISMA_ORM_PACKAGE_KEYWORD = "prisma-orm-extension";
3498
+ /**
3499
+ * The entry `--target` names by its short name or an alias, in any case, or by its package name
3500
+ * exactly.
3501
+ */
3502
+ function findTargetByName(value) {
3503
+ const name = value.toLowerCase();
3504
+ return KNOWN_TARGET_PACKAGES.find((entry) => entry.shortName === name || entry.aliases.some((alias) => alias === name) || entry.packageName === value);
3505
+ }
3506
+ function listedTargetPackage(entry) {
3507
+ return {
3508
+ packageName: entry.packageName,
3509
+ listed: entry
3510
+ };
3511
+ }
3512
+ function unlistedTargetPackage(packageName) {
3513
+ return {
3514
+ packageName,
3515
+ listed: void 0
3516
+ };
3517
+ }
3518
+ /** What `--json` reports as `target`: the short name of a listed package, otherwise the package name. */
3519
+ function reportedTargetName(target) {
3520
+ return target.listed?.shortName ?? target.packageName;
3521
+ }
3522
+ /**
3523
+ * The drivers installed with the package, before its contribution is loaded. Only the list knows
3524
+ * them before the install, so an unlisted package has none, and its contribution's `peerPackages`
3525
+ * go into the later install.
3526
+ */
3527
+ function firstInstallDrivers(target) {
3528
+ return target.listed?.peerPackages ?? [];
3529
+ }
3530
+ /**
3531
+ * The entry a `datasource` provider names, matched exactly: the provider itself, or the short
3532
+ * name or an alias.
3533
+ */
3534
+ function findTargetByProvider(provider) {
3535
+ return KNOWN_TARGET_PACKAGES.find((entry) => entry.provider.name === provider || entry.shortName === provider || entry.aliases.some((alias) => alias === provider));
3536
+ }
3537
+ /** The entry whose provider only Prisma 6 and earlier wrote; such a schema is a Prisma 6 schema. */
3538
+ function findPrisma6OnlyTarget(provider) {
3539
+ return KNOWN_TARGET_PACKAGES.find((entry) => entry.provider.writtenBy === 6 && entry.provider.name === provider);
3540
+ }
3465
3541
  /**
3466
3542
  * Non-interactive mode is missing one or more required inputs. Lists every
3467
3543
  * missing flag in the error so an agent / CI script can react without
@@ -3475,7 +3551,7 @@ function errorInitMissingFlags(options) {
3475
3551
  const flagList = options.missing.map((flag) => `--${flag}`).join(", ");
3476
3552
  const fixList = options.missing.map((flag) => {
3477
3553
  switch (flag) {
3478
- case "target": return `--target ${TARGET_SHORT_NAMES.join("|")}`;
3554
+ case "target": return `--target ${[...TARGET_SHORT_NAMES, PACKAGE_NAME_PLACEHOLDER].join("|")}`;
3479
3555
  case "authoring": return "--authoring psl|typescript";
3480
3556
  case "schema-path": return "--schema-path <path>";
3481
3557
  default: return `--${flag} <value>`;
@@ -3508,6 +3584,44 @@ function errorInitInvalidFlagValue(options) {
3508
3584
  }
3509
3585
  });
3510
3586
  }
3587
+ const SHORT_NAME_LIST = TARGET_SHORT_NAMES.join(", ");
3588
+ const SHORT_NAME_FLAGS = TARGET_SHORT_NAMES.map((name) => `--target ${name}`).join(", ");
3589
+ /**
3590
+ * The target is neither a short name nor a valid package name. `answeredIn` says whether it came
3591
+ * from `--target` or from the name typed into the picker, whose wording names the answer instead.
3592
+ */
3593
+ function errorInitInvalidTarget(options) {
3594
+ const problems = options.problems.join("; ");
3595
+ const wording = options.answeredIn === "flag" ? {
3596
+ summary: "Invalid value for --target",
3597
+ why: `\`--target ${options.value}\` is not one of the short names (${SHORT_NAME_LIST}), and init does not take it as a package name: ${problems}.`,
3598
+ fix: `Pass a short name (${SHORT_NAME_FLAGS}) or the full name of a target package (\`--target ${PACKAGE_NAME_PLACEHOLDER}\`).`
3599
+ } : {
3600
+ summary: "Invalid target package name",
3601
+ why: `\`${options.value}\`, typed as the name of the target package, is not taken as a package name: ${problems}. Nothing was changed.`,
3602
+ fix: `Run \`prisma orm init\` again and type the target package's name as it is published, or pass it as \`--target ${PACKAGE_NAME_PLACEHOLDER}\`.`
3603
+ };
3604
+ return new CliStructuredError$1$1("CLI.INIT_INVALID_FLAG_VALUE", wording.summary, {
3605
+ why: wording.why,
3606
+ fix: wording.fix,
3607
+ docsUrl: docsUrlFor("CLI.INIT_INVALID_FLAG_VALUE"),
3608
+ meta: {
3609
+ flag: "target",
3610
+ value: options.value,
3611
+ allowed: [...TARGET_SHORT_NAMES],
3612
+ acceptsPackageName: true,
3613
+ problems: options.problems
3614
+ }
3615
+ });
3616
+ }
3617
+ /**
3618
+ * Said first when a value in no list turns out not to be a usable target package, so the user
3619
+ * sees why init looked for a package of that name.
3620
+ */
3621
+ function takenAsPackageName(packageName) {
3622
+ return `\`${packageName}\` is not one of the short names (${SHORT_NAME_LIST}), so init took it as a package name.`;
3623
+ }
3624
+ const LISTED_INSTEAD = `To use a target package from the list instead, pass its short name (${SHORT_NAME_FLAGS}); for any other, pass its full package name.`;
3511
3625
  /**
3512
3626
  * `--authoring` and `--schema-path` disagree on file extension (e.g. PSL
3513
3627
  * authoring with a `.ts` path). Surfaces before any scaffold files are
@@ -3751,13 +3865,81 @@ function errorInitPrisma7ConfigUnreadable(options) {
3751
3865
  */
3752
3866
  function errorInitTargetPackageNotInstalled(options) {
3753
3867
  const { packageName, ranCommand } = options;
3868
+ const why = ranCommand !== void 0 ? `\`${ranCommand}\` succeeded, but ${packageName} cannot be found from the project, so init cannot read its init contribution. No scaffold file was written.` : `init writes the project from ${packageName}, and \`--skip-install\` forbids installing it. Nothing was changed.`;
3869
+ const fix = ranCommand !== void 0 ? `Check that \`${options.installCommand}\` makes ${packageName} resolvable from this directory (Yarn Plug'n'Play hides packages from Node), then run \`prisma orm init\` again.` : options.unlisted ? `Run \`prisma orm init\` again without \`--skip-install\`: it checks that ${packageName} lists the keyword \`${PRISMA_ORM_PACKAGE_KEYWORD}\` before installing it.` : `Install it with \`${options.installCommand}\`, then run \`prisma orm init\` again, or run it without \`--skip-install\`.`;
3754
3870
  return new CliStructuredError$1$1("CLI.INIT_TARGET_PACKAGE_NOT_INSTALLED", ranCommand !== void 0 ? `${packageName} cannot be found from the project` : `${packageName} is not installed`, {
3755
- why: ranCommand !== void 0 ? `\`${ranCommand}\` succeeded, but ${packageName} cannot be found from the project, so init cannot read its init contribution. No scaffold file was written.` : `init writes the project from ${packageName}, and \`--skip-install\` forbids installing it. Nothing was changed.`,
3756
- fix: ranCommand !== void 0 ? `Check that \`${options.installCommand}\` makes ${packageName} resolvable from this directory (Yarn Plug'n'Play hides packages from Node), then run \`prisma orm init\` again.` : `Install it with \`${options.installCommand}\`, then run \`prisma orm init\` again, or run it without \`--skip-install\`.`,
3871
+ ...explainUnlisted(options.unlisted, packageName, {
3872
+ why,
3873
+ fix
3874
+ }),
3757
3875
  docsUrl: docsUrlFor("CLI.INIT_TARGET_PACKAGE_NOT_INSTALLED"),
3758
3876
  meta: {
3759
3877
  packageName: options.packageName,
3760
- installCommand: options.installCommand
3878
+ ...options.unlisted && ranCommand === void 0 ? {} : { installCommand: options.installCommand },
3879
+ ...takenAsPackageNameMeta(options.unlisted)
3880
+ }
3881
+ });
3882
+ }
3883
+ /**
3884
+ * For a package in no list, says first that the value was taken as a package name, and last how
3885
+ * to name a listed one instead.
3886
+ */
3887
+ function explainUnlisted(unlisted, packageName, wording) {
3888
+ return unlisted ? {
3889
+ why: `${takenAsPackageName(packageName)} ${wording.why}`,
3890
+ fix: `${wording.fix} ${LISTED_INSTEAD}`
3891
+ } : wording;
3892
+ }
3893
+ function takenAsPackageNameMeta(unlisted) {
3894
+ return unlisted ? { takenAsPackageName: true } : {};
3895
+ }
3896
+ /**
3897
+ * A package in no list does not list the keyword init requires of a target package, or init could
3898
+ * not read its keywords. Init checks before installing or loading it, so nothing was changed.
3899
+ * `registry` is set when the keywords were to come from the registry rather than the installed
3900
+ * package.
3901
+ */
3902
+ function errorInitTargetPackageNotVerified(options) {
3903
+ const { packageName, installCommand } = options;
3904
+ const keyword = `\`${PRISMA_ORM_PACKAGE_KEYWORD}\``;
3905
+ const required = "init requires that keyword of a target package before it installs or uses one";
3906
+ const runAgain = "run `prisma orm init` again";
3907
+ const maintainer = `If you maintain ${packageName}, add ${keyword} to the keywords in its package.json and publish a new version.`;
3908
+ const wording = (() => {
3909
+ switch (options.reason) {
3910
+ case "keyword-missing": return options.registry === void 0 ? {
3911
+ summary: `${packageName} does not list the keyword ${keyword}`,
3912
+ why: `The installed ${packageName} does not list the keyword ${keyword} in its package.json. ${required}, so it did not use ${packageName}. Nothing was changed.`,
3913
+ fix: `Check the package name. If a newer version of ${packageName} lists the keyword, update it with \`${options.updateCommand}\` and ${runAgain}. ${maintainer}`
3914
+ } : {
3915
+ summary: `${packageName} does not list the keyword ${keyword}`,
3916
+ why: `The latest version of ${packageName} on ${options.registry} does not list the keyword ${keyword} in its package.json. ${required}, so it did not install ${packageName}. Nothing was changed.`,
3917
+ fix: `Check the package name. ${maintainer}`
3918
+ };
3919
+ case "not-found": return {
3920
+ summary: `${packageName} was not found`,
3921
+ why: `No package named ${packageName} was found on ${options.registry}. Nothing was changed.`,
3922
+ fix: `Check the package name. init asks only ${options.registry} and sends no credentials, so a package on another registry, or one that needs credentials, is not found there: install it yourself with \`${installCommand}\` and ${runAgain}, and init reads it from disk.`
3923
+ };
3924
+ case "lookup-failed": {
3925
+ const from = options.registry === void 0 ? "" : ` from ${options.registry}`;
3926
+ return {
3927
+ summary: `Could not read the keywords of ${packageName}`,
3928
+ why: `init requires the keyword ${keyword} of a target package before it installs or uses one, and it could not read the keywords of ${packageName}${from}: ${options.cause}. Nothing was changed.`,
3929
+ fix: options.registry === void 0 ? `Check the package name. If it is right, reinstall ${packageName} with \`${installCommand}\` and ${runAgain}.` : `Check the package name. If it is right and ${packageName} lists ${keyword}, install it yourself with \`${installCommand}\` and ${runAgain}: init reads the keywords of an installed package from disk.`
3930
+ };
3931
+ }
3932
+ }
3933
+ })();
3934
+ return new CliStructuredError$1$1("CLI.INIT_TARGET_PACKAGE_NOT_VERIFIED", wording.summary, {
3935
+ ...explainUnlisted(true, packageName, wording),
3936
+ docsUrl: docsUrlFor("CLI.INIT_TARGET_PACKAGE_NOT_VERIFIED"),
3937
+ meta: {
3938
+ reason: options.reason,
3939
+ packageName,
3940
+ keyword: PRISMA_ORM_PACKAGE_KEYWORD,
3941
+ ...options.registry === void 0 ? {} : { registry: options.registry },
3942
+ ...takenAsPackageNameMeta(true)
3761
3943
  }
3762
3944
  });
3763
3945
  }
@@ -3775,13 +3957,16 @@ function errorInitContributionUnavailable(options) {
3775
3957
  }[options.reason];
3776
3958
  const byHand = `Write prisma.config.ts by hand, with the defineConfig import the README of ${options.packageName} shows.`;
3777
3959
  return new CliStructuredError$1$1("CLI.INIT_CONTRIBUTION_UNAVAILABLE", options.reason === "unloadable" ? `Could not load ${module}` : `${options.packageName} does not support init`, {
3778
- why: `${why} ${options.packageName} is installed; no scaffold file was written.`,
3779
- fix: options.reason === "unloadable" ? `Reinstall ${options.packageName} with your package manager and run \`prisma orm init\` again, or ${byHand.charAt(0).toLowerCase()}${byHand.slice(1)}` : byHand,
3960
+ ...explainUnlisted(options.unlisted, options.packageName, {
3961
+ why: `${why} ${options.packageName} is installed; no scaffold file was written.`,
3962
+ fix: options.reason === "unloadable" ? `Reinstall ${options.packageName} with your package manager and run \`prisma orm init\` again, or ${byHand.charAt(0).toLowerCase()}${byHand.slice(1)}` : byHand
3963
+ }),
3780
3964
  docsUrl: docsUrlFor("CLI.INIT_CONTRIBUTION_UNAVAILABLE"),
3781
3965
  meta: {
3782
3966
  packageName: options.packageName,
3783
3967
  module,
3784
- reason: options.reason
3968
+ reason: options.reason,
3969
+ ...takenAsPackageNameMeta(options.unlisted)
3785
3970
  }
3786
3971
  });
3787
3972
  }
@@ -3816,8 +4001,9 @@ function packagesAddedAction(added, reason) {
3816
4001
  }
3817
4002
  /**
3818
4003
  * The target package init loads to read the Prisma 7 schema cannot be loaded
3819
- * from the project, or it has no Prisma 7 contract source while
3820
- * `--from-prisma7-schema` asked for one.
4004
+ * from the project, it has no Prisma 7 contract source while
4005
+ * `--from-prisma7-schema` asked for one, or it is in no list, and only a
4006
+ * listed package can keep a Prisma 7 schema.
3821
4007
  */
3822
4008
  function errorInitPrisma7SourceUnavailable(options) {
3823
4009
  const { packageName, schemaPath } = options;
@@ -3829,6 +4015,10 @@ function errorInitPrisma7SourceUnavailable(options) {
3829
4015
  summary: `Could not load ${options.module} from the project`,
3830
4016
  why: `${packageName} was installed, but the project cannot find \`${options.module}\`, the config module its init contribution names, so init cannot check that Prisma 8 reads ${schemaPath}.`,
3831
4017
  fix: `Check that ${packageName} is installed and exports ${options.module}, resolvable from this directory (Yarn Plug'n'Play hides packages from Node), then run \`prisma orm init\` again.`
4018
+ } : options.reason === "unlisted" ? {
4019
+ summary: `${packageName} cannot keep a Prisma 7 schema`,
4020
+ why: `${packageName} is not one of the target packages in Prisma's list (${SHORT_NAME_LIST}), and only a package in that list can keep ${schemaPath} as the contract source. Nothing was changed.`,
4021
+ fix: `Run \`prisma orm init\` without \`--from-prisma7-schema\` to start a fresh contract on ${packageName}. To keep ${schemaPath}, name a target package from the list instead.`
3832
4022
  } : {
3833
4023
  summary: "No Prisma 7 contract source for this database",
3834
4024
  why: `${packageName} does not provide a Prisma 7 contract source, so it cannot read ${schemaPath}.`,
@@ -3842,7 +4032,7 @@ function errorInitPrisma7SourceUnavailable(options) {
3842
4032
  schemaPath: options.schemaPath,
3843
4033
  packageName: options.packageName,
3844
4034
  reason: options.reason,
3845
- ...options.reason === "no-prisma7-source" ? {} : { module: options.module }
4035
+ ...options.reason === "no-prisma7-source" || options.reason === "unlisted" ? {} : { module: options.module }
3846
4036
  }
3847
4037
  });
3848
4038
  }
@@ -4585,14 +4775,22 @@ const AUTHORING_VALUES = /* @__PURE__ */ new Map([
4585
4775
  ["ts", "typescript"]
4586
4776
  ]);
4587
4777
  function resolveTarget(value) {
4588
- if (value === void 0) return void 0;
4589
- const mapped = findTargetByName(value);
4590
- if (mapped === void 0) throw errorInitInvalidFlagValue({
4591
- flag: "target",
4778
+ return value === void 0 ? void 0 : resolveTargetName(value, "flag");
4779
+ }
4780
+ /**
4781
+ * A short name or alias from the list, or the name of a target package that is in no list.
4782
+ * `answeredIn` says where the value came from, for the wording of a refusal.
4783
+ */
4784
+ function resolveTargetName(value, answeredIn) {
4785
+ const listed = findTargetByName(value);
4786
+ if (listed !== void 0) return listedTargetPackage(listed);
4787
+ const validation = validatePackageName(value);
4788
+ if (!validation.validForNewPackages) throw errorInitInvalidTarget({
4592
4789
  value,
4593
- allowed: TARGET_SHORT_NAMES
4790
+ problems: [...validation.errors ?? [], ...validation.warnings ?? []],
4791
+ answeredIn
4594
4792
  });
4595
- return mapped;
4793
+ return unlistedTargetPackage(value);
4596
4794
  }
4597
4795
  function resolveAuthoring(value) {
4598
4796
  if (value === void 0) return void 0;
@@ -5917,6 +6115,11 @@ async function installProjectDependencies(ctx) {
5917
6115
  if (!installed.ok) return installed.failure;
5918
6116
  }
5919
6117
  }
6118
+ /** The string entries of a `package.json`'s `keywords`; none when it has no list there. */
6119
+ function keywordsOf(manifest) {
6120
+ const keywords = typeof manifest === "object" && manifest !== null ? Reflect.get(manifest, "keywords") : void 0;
6121
+ return Array.isArray(keywords) ? keywords.filter((keyword) => typeof keyword === "string") : [];
6122
+ }
5920
6123
  /** The command that evaluates `script` as an ES module with `argument` last in `process.argv`. */
5921
6124
  function resolverChildCommand(versions, execPath, script, argument) {
5922
6125
  if (versions["deno"] !== void 0) return {
@@ -6045,10 +6248,6 @@ function resolveFromProject(cwd, specifier) {
6045
6248
  cause: Object.assign(new Error(resolved.message), { code: resolved.code })
6046
6249
  };
6047
6250
  }
6048
- /** Whether the project at `cwd` has the package `name` where Node would find it. */
6049
- function isInstalledInProject(cwd, name) {
6050
- return installedManifest(cwd, name) !== void 0;
6051
- }
6052
6251
  /**
6053
6252
  * Resolves with the import conditions, so a package that exports a module only under `import`
6054
6253
  * loads. A package the project does not have is `not-installed`; one that does not export the
@@ -6159,21 +6358,30 @@ var TargetPackageInstallFailed = class extends Error {
6159
6358
  };
6160
6359
  /**
6161
6360
  * Installs the target package with `dotenv`, the package every init installs, and the driver
6162
- * packages the caller names, leaving out those the project already declares, then loads the
6163
- * package's init contribution from the project. Under `--skip-install` the package must already be
6164
- * installed. Each refusal happens before any file is written.
6361
+ * packages its list entry names, leaving out those the project already declares, then loads the
6362
+ * package's init contribution from the project. A package in no list must first list the Prisma 8
6363
+ * keyword. Under `--skip-install` the package must already be installed. Each refusal happens
6364
+ * before any file is written.
6165
6365
  */
6166
6366
  function createTargetPackagePreparation(ctx) {
6167
- return async (packageName, peerPackages) => {
6367
+ return async (target) => {
6368
+ const { packageName } = target;
6369
+ const drivers = firstInstallDrivers(target);
6168
6370
  rejectUnparseableManifest(ctx.cwd);
6371
+ const declaredBefore = declaredPackages(ctx.cwd);
6372
+ const manifestPath = installedManifest(ctx.cwd, packageName);
6373
+ const targetInPlace = manifestPath !== void 0 && declaredBefore.has(packageName);
6374
+ const installsTarget = ctx.install && !targetInPlace;
6375
+ if (target.listed === void 0) await checkTargetPackageKeyword(ctx, packageName, {
6376
+ manifestPath,
6377
+ installsTarget
6378
+ });
6169
6379
  const warnings = [];
6170
6380
  let installed = [];
6171
6381
  let added;
6172
6382
  let ranCommand;
6173
6383
  if (ctx.install) {
6174
- const declaredBefore = declaredPackages(ctx.cwd);
6175
- const targetInPlace = declaredBefore.has(packageName) && isInstalledInProject(ctx.cwd, packageName);
6176
- const deps = [...targetInPlace ? [] : [packageName], ...["dotenv", ...peerPackages].filter((dep) => !declaredBefore.has(dep))];
6384
+ const deps = [...installsTarget ? [packageName] : [], ...["dotenv", ...drivers].filter((dep) => !declaredBefore.has(dep))];
6177
6385
  const installFailure = await installProjectDependencies({
6178
6386
  packages: ctx.packages,
6179
6387
  cwd: ctx.cwd,
@@ -6182,13 +6390,13 @@ function createTargetPackagePreparation(ctx) {
6182
6390
  });
6183
6391
  if (installFailure !== void 0) throw new TargetPackageInstallFailed(installFailure);
6184
6392
  if (ctx.packageManager === "pnpm") warnings.push(...buildCatalogWarnings(ctx.cwd, deps));
6185
- installed = targetInPlace ? [packageName, ...deps] : deps;
6393
+ installed = installsTarget ? deps : [packageName, ...deps];
6186
6394
  ranCommand = deps.length === 0 ? void 0 : installCommand(ctx.packageManager, deps);
6187
6395
  added = manifestChanges(ctx.packageManager, declaredBefore, declaredPackages(ctx.cwd));
6188
6396
  }
6189
6397
  try {
6190
6398
  return {
6191
- contribution: await loadContribution(ctx, packageName, peerPackages, ranCommand),
6399
+ contribution: await loadContribution(ctx, target, ranCommand),
6192
6400
  installed,
6193
6401
  added,
6194
6402
  warnings
@@ -6198,23 +6406,83 @@ function createTargetPackagePreparation(ctx) {
6198
6406
  }
6199
6407
  };
6200
6408
  }
6201
- async function loadContribution(ctx, packageName, peerPackages, ranCommand) {
6409
+ /**
6410
+ * Installing a package runs its install scripts, so a name that is not meant for Prisma 8, such as
6411
+ * a mistyped short name, is refused before anything is installed. The copy checked is the one init
6412
+ * will use: the installed one when init will not install the package, otherwise the registry's.
6413
+ * Under `--skip-install` a package that is not installed is left to the "not installed" refusal.
6414
+ */
6415
+ async function checkTargetPackageKeyword(ctx, packageName, copy) {
6416
+ const { manifestPath } = copy;
6417
+ if (!ctx.install && manifestPath === void 0) return;
6418
+ const lookup = manifestPath === void 0 || copy.installsTarget ? await ctx.lookUpRegistryKeywords(packageName, {
6419
+ env: ctx.env,
6420
+ signal: ctx.signal
6421
+ }) : installedKeywords(ctx.cwd, manifestPath);
6422
+ const refusal = {
6423
+ packageName,
6424
+ installCommand: installCommand(ctx.packageManager, [packageName]),
6425
+ updateCommand: installCommand(ctx.packageManager, [`${packageName}@latest`])
6426
+ };
6427
+ switch (lookup.kind) {
6428
+ case "read":
6429
+ if (!lookup.keywords.includes("prisma-orm-extension")) throw errorInitTargetPackageNotVerified({
6430
+ ...refusal,
6431
+ reason: "keyword-missing",
6432
+ registry: lookup.registry
6433
+ });
6434
+ return;
6435
+ case "not-found": throw errorInitTargetPackageNotVerified({
6436
+ ...refusal,
6437
+ reason: "not-found",
6438
+ registry: lookup.registry
6439
+ });
6440
+ case "lookup-failed": throw errorInitTargetPackageNotVerified({
6441
+ ...refusal,
6442
+ reason: "lookup-failed",
6443
+ registry: lookup.registry,
6444
+ cause: lookup.cause
6445
+ });
6446
+ }
6447
+ }
6448
+ function installedKeywords(cwd, manifestPath) {
6449
+ try {
6450
+ return {
6451
+ kind: "read",
6452
+ registry: void 0,
6453
+ keywords: keywordsOf(JSON.parse(readFileSync(manifestPath, "utf-8")))
6454
+ };
6455
+ } catch (error) {
6456
+ const reason = error instanceof Error ? error.message : String(error);
6457
+ return {
6458
+ kind: "lookup-failed",
6459
+ registry: void 0,
6460
+ cause: `${relative(cwd, manifestPath)} cannot be read as JSON: ${reason}`
6461
+ };
6462
+ }
6463
+ }
6464
+ async function loadContribution(ctx, target, ranCommand) {
6465
+ const { packageName } = target;
6466
+ const unlisted = target.listed === void 0;
6202
6467
  const entrypoint = await ctx.importFromProject(ctx.cwd, `${packageName}/init`);
6203
6468
  switch (entrypoint.kind) {
6204
6469
  case "not-installed": throw errorInitTargetPackageNotInstalled({
6205
6470
  packageName,
6206
- installCommand: installCommand(ctx.packageManager, [packageName, ...peerPackages]),
6207
- ranCommand
6471
+ installCommand: installCommand(ctx.packageManager, [packageName, ...firstInstallDrivers(target)]),
6472
+ ranCommand,
6473
+ unlisted
6208
6474
  });
6209
6475
  case "not-exported": throw errorInitContributionUnavailable({
6210
6476
  packageName,
6211
6477
  reason: "no-entrypoint",
6212
- detail: void 0
6478
+ detail: void 0,
6479
+ unlisted
6213
6480
  });
6214
6481
  case "unloadable": throw errorInitContributionUnavailable({
6215
6482
  packageName,
6216
6483
  reason: "unloadable",
6217
- detail: causeMessage$1(entrypoint.cause)
6484
+ detail: causeMessage$1(entrypoint.cause),
6485
+ unlisted
6218
6486
  });
6219
6487
  case "loaded": break;
6220
6488
  }
@@ -6222,7 +6490,8 @@ async function loadContribution(ctx, packageName, peerPackages, ranCommand) {
6222
6490
  if (!isInitContribution(contribution)) throw errorInitContributionUnavailable({
6223
6491
  packageName,
6224
6492
  reason: "invalid-shape",
6225
- detail: contributionProblems(contribution)
6493
+ detail: contributionProblems(contribution),
6494
+ unlisted
6226
6495
  });
6227
6496
  return contribution;
6228
6497
  }
@@ -6307,7 +6576,7 @@ var InitInstallFailedBeforeWriting = class extends Error {
6307
6576
  };
6308
6577
  async function prepareTarget(prepareTargetPackage, target, report, installReason) {
6309
6578
  try {
6310
- return await prepareTargetPackage(target.packageName, target.peerPackages);
6579
+ return await prepareTargetPackage(target);
6311
6580
  } catch (error) {
6312
6581
  if (error instanceof TargetPackageRefusedAfterInstall) throw withPackagesAddedAction(error.cause, error.added, installReason);
6313
6582
  if (error instanceof TargetPackageInstallFailed) throw new InitInstallFailedBeforeWriting(error.failure, target, report.authoring, report.schemaPath);
@@ -6346,14 +6615,23 @@ function consentToken(cwd) {
6346
6615
  const name = basename(cwd).trim();
6347
6616
  return name.length > 0 ? name : cwd.trim();
6348
6617
  }
6618
+ const ANOTHER_PACKAGE = "another-package";
6619
+ /**
6620
+ * The known target packages, and a way to type another package's name, which then resolves as
6621
+ * `--target <name>` does.
6622
+ */
6349
6623
  async function askTarget(prompt) {
6350
- const shortName = await prompt.select("What database are you using?", KNOWN_TARGET_PACKAGES.map((entry) => ({
6624
+ const answer = await prompt.select("What database are you using?", [...KNOWN_TARGET_PACKAGES.map((entry) => ({
6351
6625
  value: entry.shortName,
6352
6626
  label: entry.label
6353
- })));
6354
- const chosen = KNOWN_TARGET_PACKAGES.find((entry) => entry.shortName === shortName);
6627
+ })), {
6628
+ value: ANOTHER_PACKAGE,
6629
+ label: "Another target package"
6630
+ }]);
6631
+ if (answer === ANOTHER_PACKAGE) return resolveTargetName((await prompt.text("Which target package?", { placeholder: PACKAGE_NAME_PLACEHOLDER })).trim(), "prompt");
6632
+ const chosen = KNOWN_TARGET_PACKAGES.find((entry) => entry.shortName === answer);
6355
6633
  if (chosen === void 0) throw errorInitUserAborted();
6356
- return chosen;
6634
+ return listedTargetPackage(chosen);
6357
6635
  }
6358
6636
  const AUTHORING_CHOICES = [{
6359
6637
  value: "psl",
@@ -6389,7 +6667,7 @@ async function askSchemaPath(prompt, authoring) {
6389
6667
  function previousFacade(cwd, target) {
6390
6668
  const manifestPath = join(cwd, "package.json");
6391
6669
  if (!existsSync(manifestPath)) return;
6392
- const candidates = KNOWN_TARGET_PACKAGES.filter((entry) => entry.shortName !== target.shortName).flatMap((entry) => [entry.packageName, entry.workspacePackageName].map((packageName) => ({
6670
+ const candidates = KNOWN_TARGET_PACKAGES.filter((entry) => entry.packageName !== target.packageName).flatMap((entry) => [entry.packageName, entry.workspacePackageName].map((packageName) => ({
6393
6671
  target: entry,
6394
6672
  packageName
6395
6673
  })));
@@ -6408,7 +6686,7 @@ async function resolveRemovePreviousFacade(ctx) {
6408
6686
  if (!ctx.reinit || ctx.keepPreviousFacade) return null;
6409
6687
  const facade = previousFacade(ctx.cwd, ctx.target);
6410
6688
  if (facade === void 0) return null;
6411
- return await ctx.prompt.confirm(`Switching from ${facade.target.label} to ${ctx.target.label} — remove ${facade.packageName} from package.json dependencies?`, { default: true }) ? facade.packageName : null;
6689
+ return await ctx.prompt.confirm(`Switching from ${facade.target.label} to ${ctx.label} — remove ${facade.packageName} from package.json dependencies?`, { default: true }) ? facade.packageName : null;
6412
6690
  }
6413
6691
  const PRISMA7_SCHEMA_FLAG = "from-prisma7-schema";
6414
6692
  const PRISMA7_CONFIG_STEM = "prisma.config.";
@@ -6441,11 +6719,16 @@ function prisma7Question(detection) {
6441
6719
  * The Prisma 7 path is entered by the flag or by an explicit yes. The question
6442
6720
  * declares no default on purpose: a session that cannot ask (`--yes`, no
6443
6721
  * terminal) must run init as today rather than have the engine answer for the
6444
- * user, so the engine's "cannot ask" is read as a no.
6722
+ * user, so the engine's "cannot ask" is read as a no. An unlisted package
6723
+ * cannot keep the schema, so it is not asked about, and the user is told why.
6445
6724
  */
6446
6725
  async function choosePrisma7Path(ctx) {
6447
6726
  if (ctx.flags.fromPrisma7Schema !== void 0) return true;
6448
6727
  if (!looksLikePrisma7(ctx.detection)) return false;
6728
+ if (ctx.flagTarget !== void 0 && ctx.flagTarget.listed === void 0) {
6729
+ ctx.warn(freshInitWarning(`${ctx.flagTarget.packageName} is not in the list of target packages that can keep a Prisma 7 schema`, ctx.detection));
6730
+ return false;
6731
+ }
6449
6732
  const { schema } = ctx.detection;
6450
6733
  if (schema.kind === "datasource" && !prisma7Target(schema, ctx.flagTarget, ctx.flags.target).ok) return false;
6451
6734
  try {
@@ -6456,10 +6739,17 @@ async function choosePrisma7Path(ctx) {
6456
6739
  }
6457
6740
  }
6458
6741
  /**
6459
- * The schema's provider names the target; `--target` may only agree with it,
6460
- * or name the database when the provider is not a string literal.
6742
+ * The schema's provider names the target through the list; `--target` may only agree with it,
6743
+ * or name a listed database when the provider is not a string literal. An unlisted package takes
6744
+ * no Prisma 7 schema.
6461
6745
  */
6462
- function prisma7Target(schema, flagTarget, rawFlagTarget) {
6746
+ function prisma7Target(schema, flagTargetPackage, rawFlagTarget) {
6747
+ const flagTarget = flagTargetPackage?.listed;
6748
+ if (flagTargetPackage !== void 0 && flagTarget === void 0) return notOk(errorInitPrisma7SourceUnavailable({
6749
+ schemaPath: schema.path,
6750
+ packageName: flagTargetPackage.packageName,
6751
+ reason: "unlisted"
6752
+ }));
6463
6753
  const providerTarget = schema.provider === void 0 ? void 0 : findTargetByProvider(schema.provider);
6464
6754
  if (schema.provider !== void 0 && providerTarget === void 0) return notOk(errorInitPrisma7ProviderUnsupported({
6465
6755
  schemaPath: schema.path,
@@ -6474,17 +6764,17 @@ function prisma7Target(schema, flagTarget, rawFlagTarget) {
6474
6764
  return target === void 0 ? notOk(errorInitPrisma7ProviderUnsupported({
6475
6765
  schemaPath: schema.path,
6476
6766
  provider: void 0
6477
- })) : ok(target);
6767
+ })) : ok(listedTargetPackage(target));
6478
6768
  }
6479
6769
  /**
6480
6770
  * What a fresh init does to a Prisma 7 project, said before its questions: the user answered yes
6481
6771
  * to adopting the schema and is about to be asked something else.
6482
6772
  */
6483
- function freshInitWarning(packageName, detection) {
6773
+ function freshInitWarning(cause, detection) {
6484
6774
  const { config, schema, cli } = detection;
6485
6775
  const effects = [...config.kind === "prisma7" && config.path === "prisma.config.ts" ? [`asks before replacing the Prisma 7 ${CONFIG_FILE}`] : [], ...cli.kind === "earlier" ? ["installs prisma@latest, which replaces the Prisma 7 CLI"] : []];
6486
6776
  const consequences = effects.length === 0 ? "" : ` It ${effects.join(", and it ")}.`;
6487
- return `${packageName} cannot read Prisma 7 schemas, so init sets up a fresh Prisma 8 project instead and leaves ${schema.path} alone.${consequences}`;
6777
+ return `${cause}, so init sets up a fresh Prisma 8 project instead and leaves ${schema.path} alone.${consequences}`;
6488
6778
  }
6489
6779
  function sideBySidePlan(detection) {
6490
6780
  const { config, cli } = detection;
@@ -6554,7 +6844,7 @@ async function resolvePrisma7Inputs(ctx) {
6554
6844
  reason: "no-prisma7-source"
6555
6845
  });
6556
6846
  if (check.outcome === "no-source") {
6557
- ctx.warn(freshInitWarning(target.packageName, detection));
6847
+ ctx.warn(freshInitWarning(`${target.packageName} cannot read Prisma 7 schemas`, detection));
6558
6848
  return await resolveStarterInputs({
6559
6849
  cwd,
6560
6850
  flags,
@@ -6605,6 +6895,7 @@ async function confirmPrisma7Inputs(ctx) {
6605
6895
  const removePreviousFacade = await resolveRemovePreviousFacade({
6606
6896
  cwd,
6607
6897
  target,
6898
+ label: prepared.contribution.label,
6608
6899
  reinit,
6609
6900
  keepPreviousFacade: flags.keepPreviousFacade,
6610
6901
  prompt
@@ -6702,6 +6993,7 @@ async function confirmStarterInputs(ctx) {
6702
6993
  const removePreviousFacade = await resolveRemovePreviousFacade({
6703
6994
  cwd,
6704
6995
  target,
6996
+ label: prepared.contribution.label,
6705
6997
  reinit,
6706
6998
  keepPreviousFacade: flags.keepPreviousFacade,
6707
6999
  prompt
@@ -6796,7 +7088,8 @@ async function resolveInitInputs(ctx) {
6796
7088
  flags,
6797
7089
  prompt,
6798
7090
  detection,
6799
- flagTarget
7091
+ flagTarget,
7092
+ warn: ctx.warn
6800
7093
  })) return resolvePrisma7Inputs({
6801
7094
  cwd,
6802
7095
  flags,
@@ -6849,13 +7142,15 @@ function createPrisma7SourceCheck(ctx) {
6849
7142
  if (typeof defineConfig !== "function") throw errorInitContributionUnavailable({
6850
7143
  packageName,
6851
7144
  reason: "invalid-shape",
6852
- detail: `${contribution.configModule} exports prisma7Schema, but not a defineConfig function`
7145
+ detail: `${contribution.configModule} exports prisma7Schema, but not a defineConfig function`,
7146
+ unlisted: false
6853
7147
  });
6854
7148
  const quickReference = contribution.prisma7QuickReference;
6855
7149
  if (quickReference === void 0) throw errorInitContributionUnavailable({
6856
7150
  packageName,
6857
7151
  reason: "invalid-shape",
6858
- detail: `${contribution.configModule} exports prisma7Schema, but the contribution has no prisma7QuickReference`
7152
+ detail: `${contribution.configModule} exports prisma7Schema, but the contribution has no prisma7QuickReference`,
7153
+ unlisted: false
6859
7154
  });
6860
7155
  const section = defineConfig({
6861
7156
  contract: prisma7Schema(schemaPath),
@@ -6884,6 +7179,131 @@ function createPrisma7SourceCheck(ctx) {
6884
7179
  function isRecord(value) {
6885
7180
  return typeof value === "object" && value !== null && !Array.isArray(value);
6886
7181
  }
7182
+ const DEFAULT_REGISTRY = "https://registry.npmjs.org";
7183
+ const REGISTRY_LOOKUP_TIMEOUT_MILLIS = 1e4;
7184
+ const REGISTRY_MANIFEST_LIMIT_BYTES = 1024 * 1024;
7185
+ const REGISTRY_VARIABLE = "npm_config_registry";
7186
+ const LatestManifest = type({
7187
+ name: "string",
7188
+ version: "string"
7189
+ });
7190
+ var ManifestTooLarge = class extends Error {};
7191
+ /** Package managers read their environment settings in any letter case; the lower-case one wins. */
7192
+ function configuredRegistry(env) {
7193
+ const lower = env[REGISTRY_VARIABLE];
7194
+ if (lower !== void 0) return lower;
7195
+ const other = Object.keys(env).find((key) => key.toLowerCase() === REGISTRY_VARIABLE);
7196
+ return other === void 0 ? void 0 : env[other];
7197
+ }
7198
+ function registryOf(env) {
7199
+ const configured = configuredRegistry(env)?.trim();
7200
+ return (configured === void 0 || configured === "" ? DEFAULT_REGISTRY : configured).replace(/\/+$/, "");
7201
+ }
7202
+ /** The registry URL without its userinfo, since init sends no credentials. */
7203
+ function withoutCredentials(registry) {
7204
+ try {
7205
+ const url = new URL(registry);
7206
+ url.username = "";
7207
+ url.password = "";
7208
+ return url.href.replace(/\/+$/, "");
7209
+ } catch {
7210
+ return redactUrlCredentials(registry);
7211
+ }
7212
+ }
7213
+ function describeError(error) {
7214
+ if (!(error instanceof Error)) return String(error);
7215
+ const code = Reflect.get(error, "code");
7216
+ return error.message !== "" ? error.message : typeof code === "string" ? code : error.name;
7217
+ }
7218
+ function failureMessage(error) {
7219
+ const message = describeError(error);
7220
+ if (!(error instanceof Error) || error.cause === void 0) return message;
7221
+ const cause = describeError(error.cause);
7222
+ return cause === "" ? message : `${message} (${cause})`;
7223
+ }
7224
+ function abortedWith(signal) {
7225
+ return new Promise((_, reject) => {
7226
+ if (signal.aborted) {
7227
+ reject(signal.reason);
7228
+ return;
7229
+ }
7230
+ signal.addEventListener("abort", () => reject(signal.reason), { once: true });
7231
+ });
7232
+ }
7233
+ async function readBody(response, signal) {
7234
+ if (response.body === null) return "";
7235
+ const reader = response.body.getReader();
7236
+ const aborted = abortedWith(signal);
7237
+ const chunks = [];
7238
+ let size = 0;
7239
+ try {
7240
+ for (;;) {
7241
+ const { done, value } = await Promise.race([reader.read(), aborted]);
7242
+ if (done) break;
7243
+ size += value.byteLength;
7244
+ if (size > 1048576) throw new ManifestTooLarge();
7245
+ chunks.push(value);
7246
+ }
7247
+ } catch (error) {
7248
+ reader.cancel().catch(() => void 0);
7249
+ throw error;
7250
+ } finally {
7251
+ aborted.catch(() => void 0);
7252
+ }
7253
+ return new TextDecoder().decode(Buffer.concat(chunks));
7254
+ }
7255
+ async function readLatest(url, signal) {
7256
+ const response = await Promise.race([fetch(url, {
7257
+ signal,
7258
+ headers: { accept: "application/json" }
7259
+ }), abortedWith(signal)]);
7260
+ return {
7261
+ status: response.status,
7262
+ ok: response.ok,
7263
+ text: await readBody(response, signal)
7264
+ };
7265
+ }
7266
+ const lookUpRegistryKeywords = async (packageName, options) => {
7267
+ const registry = withoutCredentials(registryOf(options.env));
7268
+ const url = `${registry}/${packageName.replace("/", "%2F")}/latest`;
7269
+ const failed = (cause) => ({
7270
+ kind: "lookup-failed",
7271
+ registry,
7272
+ cause: redactUrlCredentials(cause)
7273
+ });
7274
+ const timeout = new AbortController();
7275
+ const timer = setTimeout(() => timeout.abort(), REGISTRY_LOOKUP_TIMEOUT_MILLIS);
7276
+ const signal = AbortSignal.any([options.signal, timeout.signal]);
7277
+ let answer;
7278
+ try {
7279
+ answer = await readLatest(url, signal);
7280
+ } catch (error) {
7281
+ if (options.signal.aborted) throw options.signal.reason;
7282
+ if (timeout.signal.aborted) return failed(`the registry did not answer within ${REGISTRY_LOOKUP_TIMEOUT_MILLIS / 1e3} seconds`);
7283
+ if (error instanceof ManifestTooLarge) return failed(`the registry's answer is larger than ${REGISTRY_MANIFEST_LIMIT_BYTES / 1024 / 1024} MiB`);
7284
+ return failed(failureMessage(error));
7285
+ } finally {
7286
+ clearTimeout(timer);
7287
+ }
7288
+ if (answer.status === 404) return {
7289
+ kind: "not-found",
7290
+ registry
7291
+ };
7292
+ if (!answer.ok) return failed(`the registry answered with status ${answer.status}`);
7293
+ let body;
7294
+ try {
7295
+ body = JSON.parse(answer.text);
7296
+ } catch (error) {
7297
+ return failed(`the registry's answer is not a package manifest: ${failureMessage(error)}`);
7298
+ }
7299
+ const manifest = LatestManifest(body);
7300
+ if (manifest instanceof type.errors) return failed(`the registry's answer is not a package manifest: ${manifest.summary}`);
7301
+ return {
7302
+ kind: "read",
7303
+ registry,
7304
+ keywords: keywordsOf(manifest)
7305
+ };
7306
+ };
6887
7307
  /** Each of these is a finding on a completed run, not an error. */
6888
7308
  const INIT_EXIT_CODES = {
6889
7309
  4: "dependency install failed",
@@ -6947,8 +7367,8 @@ which breaks the Prisma 6 CLI.`,
6947
7367
  },
6948
7368
  args: { flags: {
6949
7369
  target: flag.string({
6950
- brief: `Database target: ${TARGET_SHORT_NAMES.join(" or ")}`,
6951
- placeholder: "db"
7370
+ brief: `Database target: ${TARGET_SHORT_NAMES.join(" or ")}, or the name of a target package`,
7371
+ placeholder: TARGET_FLAG_PLACEHOLDER
6952
7372
  }),
6953
7373
  authoring: flag.string({
6954
7374
  brief: "Schema authoring style: psl or typescript",
@@ -6992,10 +7412,13 @@ which breaks the Prisma 6 CLI.`,
6992
7412
  prompt: ctx.prompt,
6993
7413
  prepareTargetPackage: createTargetPackagePreparation({
6994
7414
  cwd: ctx.cwd,
7415
+ env: ctx.env,
6995
7416
  packages: ctx.packages,
6996
7417
  packageManager,
6997
7418
  install: !args.flags.skipInstall,
6998
- importFromProject: injected.importFromProject
7419
+ importFromProject: injected.importFromProject,
7420
+ lookUpRegistryKeywords: injected.lookUpRegistryKeywords,
7421
+ signal: ctx.signal
6999
7422
  }),
7000
7423
  checkPrisma7Source: createPrisma7SourceCheck({
7001
7424
  cwd: ctx.cwd,
@@ -7008,7 +7431,8 @@ which breaks the Prisma 6 CLI.`,
7008
7431
  if (!(error instanceof InitInstallFailedBeforeWriting)) throw error;
7009
7432
  const document = {
7010
7433
  ok: true,
7011
- target: error.target.shortName,
7434
+ target: reportedTargetName(error.target),
7435
+ package: error.target.packageName,
7012
7436
  authoring: error.authoring,
7013
7437
  schemaPath: error.schemaPath,
7014
7438
  filesWritten: [],
@@ -7077,7 +7501,8 @@ which breaks the Prisma 6 CLI.`,
7077
7501
  const installed = packagesInstalled === "installed";
7078
7502
  const document = {
7079
7503
  ok: true,
7080
- target: inputs.target.shortName,
7504
+ target: reportedTargetName(inputs.target),
7505
+ package: inputs.target.packageName,
7081
7506
  authoring: adoptsPrisma7 ? "prisma7" : inputs.authoring,
7082
7507
  schemaPath: inputs.schemaPath,
7083
7508
  filesWritten: scaffold.filesWritten,
@@ -7096,7 +7521,7 @@ which breaks the Prisma 6 CLI.`,
7096
7521
  packagesMoved
7097
7522
  } : null,
7098
7523
  nextSteps: buildNextSteps({
7099
- target: inputs.target.shortName,
7524
+ target: reportedTargetName(inputs.target),
7100
7525
  packagesInstalled,
7101
7526
  contractEmitted,
7102
7527
  emitCommand: EMIT_COMMAND,
@@ -7191,7 +7616,8 @@ which breaks the Prisma 6 CLI.`,
7191
7616
  });
7192
7617
  const initCommand = createInitCommand({
7193
7618
  emitScaffoldedContract,
7194
- importFromProject
7619
+ importFromProject,
7620
+ lookUpRegistryKeywords
7195
7621
  });
7196
7622
  /**
7197
7623
  * R-S5-12 asks every command to end at 143 for SIGTERM and 130 otherwise, and