@prisma/composer-prisma-cloud 0.17.0-dev.3 → 0.17.0-dev.5

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.
@@ -470,7 +470,7 @@ function mintKeyPair() {
470
470
  };
471
471
  }
472
472
  //#endregion
473
- //#region ../../1-prisma-cloud/1-extensions/target/dist/s3-credentials-resource-CDab6Xhp.mjs
473
+ //#region ../../1-prisma-cloud/1-extensions/target/dist/s3-credentials-resource-CLB5qGGZ.mjs
474
474
  const PRISMA_CLOUD_EXTENSION_ID = "@prisma/composer-prisma-cloud";
475
475
  /** Accepts exactly what Alchemy's own `--stage` validation accepts (pinned 2.0.0-beta.59, `Cli/commands/_shared.ts`), rewritten without overlapping quantifiers so it cannot backtrack catastrophically. Asserted before a Branch id is exposed as a stage. */
476
476
  const ALCHEMY_STAGE_PATTERN = /^[a-z0-9][-_a-z0-9]*$/i;
@@ -709,9 +709,10 @@ const generatedParamProviderService = {
709
709
  const GeneratedParamProvider = () => Provider.effect(GeneratedParam, Effect.succeed(generatedParamProviderService));
710
710
  /**
711
711
  * Resolves a `postgres` resource's `prisma.config.ts` path to the
712
- * project facts the deploy needs (ADR-0022, slice 2): the on-disk migrations
713
- * directory the control client's `migrate` reads, and the declared
714
- * extension packs. Deploy-time only: loads PN's config (via c12) and applies
712
+ * project facts the deploy needs (ADR-0022, slice 2): the emitted
713
+ * `contract.json` artifact path, the on-disk migrations directory the control
714
+ * client's `migrate` reads, and the declared extension packs. Deploy-time
715
+ * only: loads PN's config (via c12) and applies
715
716
  * PN's own convention — `migrations.dir`, or the default `migrations/`,
716
717
  * relative to the config file's directory (mirrors the CLI's
717
718
  * `resolveMigrationPaths`). Imported by `control.ts` + tests, never by
@@ -726,11 +727,18 @@ async function resolveOrmConfig(configPath) {
726
727
  const loaded = await loadConfig(configPath);
727
728
  if (!loaded.ok) throw loaded.failure;
728
729
  const config = loaded.value.config;
730
+ if (config.contract === void 0) throw new Error(`Prisma ORM config at "${configPath}" did not declare orm.contract.`);
731
+ if (config.contract.output === void 0) throw new Error(`Prisma ORM config at "${configPath}" did not resolve orm.contract.output.`);
729
732
  return {
730
733
  migrationsDir: resolve(configPath, "..", config.migrations?.dir ?? "migrations"),
734
+ contractArtifactPath: resolve(configPath, "..", config.contract.output),
731
735
  extensionPacks: blindCast(config.extensions ?? [])
732
736
  };
733
737
  }
738
+ /** Loads the emitted `contract.json` at the resolved artifact path. */
739
+ async function loadContractJson(contractArtifactPath) {
740
+ return (await import(`${contractArtifactPath}?t=${Date.now()}`, { with: { type: "json" } })).default;
741
+ }
734
742
  /**
735
743
  * The pack-head identity entries the `OrmMigration` resource folds into its
736
744
  * diff key: `"<packId>:<headRefHash>"` — each pack's contract-space head ref,
@@ -951,10 +959,19 @@ const ormMigrationProviderService = {
951
959
  list: () => Effect.succeed([]),
952
960
  reconcile: ({ news }) => Effect.tryPromise({
953
961
  try: async () => {
954
- const extensionPacks = news.packHeadRefHashes.length > 0 ? (await resolveOrmConfig(news.configPath)).extensionPacks : [];
962
+ const { contractArtifactPath, extensionPacks } = await resolveOrmConfig(news.configPath);
963
+ let contractJson;
964
+ try {
965
+ contractJson = await loadContractJson(contractArtifactPath);
966
+ } catch (error) {
967
+ const summary = error instanceof Error ? error.message : String(error);
968
+ throw new OrmMigrationError("CONTRACT_ARTIFACT_UNREADABLE", `could not load the emitted contract identified by "${news.configPath}" at "${contractArtifactPath}": ${summary}`);
969
+ }
970
+ const loadedContractHash = targetStorageHash(contractJson);
971
+ if (loadedContractHash !== news.currentContractHash) throw new OrmMigrationError("CONTRACT_IDENTITY_MISMATCH", `the emitted contract identified by "${news.configPath}" has storage hash "${loadedContractHash}", but the database resource declared "${news.currentContractHash}"`);
955
972
  return applyOrmMigration({
956
973
  url: news.url,
957
- contractJson: news.contractJson,
974
+ contractJson,
958
975
  migrationsDir: news.migrationsDir,
959
976
  ref: {
960
977
  hash: news.targetHash,
@@ -1093,6 +1110,6 @@ const s3CredentialsProviderService = {
1093
1110
  /** The `S3Credentials` provider layer — merged into the extension descriptor's `providers()`. */
1094
1111
  const S3CredentialsProvider = () => Provider.effect(S3Credentials, Effect.succeed(s3CredentialsProviderService));
1095
1112
  //#endregion
1096
- export { collectPages as A, appAfterEnvironment as C, RESERVED_DATABASE_URL_KEYS as D, PrismaApiError as E, fromEnv as F, managementApiBaseUrl as I, layer as M, resolveDefaultBranchId as N, call as O, PrismaCredentials as P, ServiceKeyProvider as S, ManagementClient as T, resolveTargetRef as _, PRISMA_CLOUD_EXTENSION_ID as a, providers as b, PrismaCloudContainer as c, collectPreflightNames as d, containerDescriptor as f, resolveOrmConfig as g, prismaCloudContainerOf as h, OrmMigrationProvider as i, drivePagesAsync as j, claimDatabaseUrlKeys as k, S3Credentials as l, packHeadRefHashes as m, GeneratedParamProvider as n, PgWarm as o, deserialize as p, OrmMigration as r, PgWarmProvider as s, GeneratedParam as t, S3CredentialsProvider as u, mintKeyPair as v, isWithin as w, ServiceKey as x, Providers as y };
1113
+ export { claimDatabaseUrlKeys as A, ServiceKeyProvider as C, PrismaApiError as D, ManagementClient as E, PrismaCredentials as F, fromEnv as I, managementApiBaseUrl as L, drivePagesAsync as M, layer as N, RESERVED_DATABASE_URL_KEYS as O, resolveDefaultBranchId as P, ServiceKey as S, isWithin as T, resolveTargetRef as _, PRISMA_CLOUD_EXTENSION_ID as a, Providers as b, PrismaCloudContainer as c, collectPreflightNames as d, containerDescriptor as f, resolveOrmConfig as g, prismaCloudContainerOf as h, OrmMigrationProvider as i, collectPages as j, call as k, S3Credentials as l, packHeadRefHashes as m, GeneratedParamProvider as n, PgWarm as o, deserialize as p, OrmMigration as r, PgWarmProvider as s, GeneratedParam as t, S3CredentialsProvider as u, targetStorageHash as v, appAfterEnvironment as w, providers as x, mintKeyPair as y };
1097
1114
 
1098
- //# sourceMappingURL=s3-credentials-resource-CDab6Xhp-DhYo1-tR.mjs.map
1115
+ //# sourceMappingURL=s3-credentials-resource-CLB5qGGZ-BA7MT-Tb.mjs.map