@prisma/composer-prisma-cloud 0.6.0-dev.14 → 0.6.0-dev.16

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.
@@ -849,7 +849,7 @@ function mintKeyPair() {
849
849
  };
850
850
  }
851
851
  //#endregion
852
- //#region ../../1-prisma-cloud/1-extensions/target/dist/s3-credentials-resource-CqOODiAr.mjs
852
+ //#region ../../1-prisma-cloud/1-extensions/target/dist/s3-credentials-resource-BltGd-gG.mjs
853
853
  const PRISMA_CLOUD_EXTENSION_ID = "@prisma/composer-prisma-cloud";
854
854
  /** 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. */
855
855
  const ALCHEMY_STAGE_PATTERN = /^[a-z0-9][-_a-z0-9]*$/i;
@@ -929,18 +929,31 @@ function deserialize(serialized) {
929
929
  }
930
930
  const workspaceRequiredError = () => /* @__PURE__ */ new Error("environment variable PRISMA_WORKSPACE_ID is required.");
931
931
  const tokenRequiredError = () => /* @__PURE__ */ new Error("environment variable PRISMA_SERVICE_TOKEN is required.");
932
- function requireWorkspaceId() {
933
- const workspaceId = process.env["PRISMA_WORKSPACE_ID"];
932
+ /**
933
+ * The caller's workspace id, or — only when the caller passed no credentials
934
+ * at all — the env protocol, which is what the alchemy child process and
935
+ * existing programmatic hosts have set.
936
+ */
937
+ function requireWorkspaceId(credentials) {
938
+ const workspaceId = credentials === void 0 ? process.env["PRISMA_WORKSPACE_ID"] : credentials.workspaceId;
934
939
  if (workspaceId === void 0 || workspaceId.length === 0) throw workspaceRequiredError();
935
940
  return workspaceId;
936
941
  }
937
- function requireTokenUnlessInjected(deps) {
938
- if (deps?.client === void 0 && (process.env["PRISMA_SERVICE_TOKEN"] ?? "").length === 0) throw tokenRequiredError();
942
+ function requireTokenUnlessInjected(client) {
943
+ if (client === void 0 && (process.env["PRISMA_SERVICE_TOKEN"] ?? "").length === 0) throw tokenRequiredError();
944
+ }
945
+ function clientFor(credentials, deps) {
946
+ return credentials?.client ?? deps?.client;
947
+ }
948
+ /** Runs against the injected client when there is one, and against an env-built one otherwise. */
949
+ function runWithClient(program, client) {
950
+ return Effect.runPromise(client !== void 0 ? program.pipe(Effect.provideService(ManagementClient, client)) : program.pipe(Effect.provide(layer().pipe(Layer.provide(fromEnv())))));
939
951
  }
940
- async function ensureContainer(input, deps) {
941
- const workspaceId = requireWorkspaceId();
942
- requireTokenUnlessInjected(deps);
943
- const program = resolveContainer({
952
+ async function ensureContainer(input, credentials, deps) {
953
+ const workspaceId = requireWorkspaceId(credentials);
954
+ const client = clientFor(credentials, deps);
955
+ requireTokenUnlessInjected(client);
956
+ const outcome = await runWithClient(resolveContainer({
944
957
  workspaceId,
945
958
  appName: input.appName,
946
959
  ...input.stage !== void 0 ? { stage: input.stage } : {},
@@ -951,16 +964,15 @@ async function ensureContainer(input, deps) {
951
964
  })), Effect.catchTag("PrismaApiError", (e) => Effect.succeed({
952
965
  ok: false,
953
966
  message: `Prisma Management API error resolving containers: ${e.message}.`
954
- })));
955
- const provided = deps?.client !== void 0 ? program.pipe(Effect.provideService(ManagementClient, deps.client)) : program.pipe(Effect.provide(layer().pipe(Layer.provide(fromEnv()))));
956
- const outcome = await Effect.runPromise(provided);
967
+ }))), client);
957
968
  if (!outcome.ok) throw new Error(outcome.message);
958
969
  return new PrismaCloudContainer(input, outcome.container.projectId, outcome.container.branchId, outcome.container.defaultBranchId);
959
970
  }
960
- async function locateContainer(input, deps) {
961
- const workspaceId = requireWorkspaceId();
962
- requireTokenUnlessInjected(deps);
963
- const program = resolveContainer({
971
+ async function locateContainer(input, credentials, deps) {
972
+ const workspaceId = requireWorkspaceId(credentials);
973
+ const client = clientFor(credentials, deps);
974
+ requireTokenUnlessInjected(client);
975
+ const outcome = await runWithClient(resolveContainer({
964
976
  workspaceId,
965
977
  appName: input.appName,
966
978
  ...input.stage !== void 0 ? { stage: input.stage } : {},
@@ -968,9 +980,7 @@ async function locateContainer(input, deps) {
968
980
  }).pipe(Effect.map((c) => ({
969
981
  ok: true,
970
982
  container: c
971
- })), Effect.catchTag("ContainerNotFoundError", () => Effect.succeed({ ok: false })), Effect.catchTag("PrismaApiError", (e) => Effect.fail(/* @__PURE__ */ new Error(`Prisma Management API error resolving containers: ${e.message}.`))));
972
- const provided = deps?.client !== void 0 ? program.pipe(Effect.provideService(ManagementClient, deps.client)) : program.pipe(Effect.provide(layer().pipe(Layer.provide(fromEnv()))));
973
- const outcome = await Effect.runPromise(provided);
983
+ })), Effect.catchTag("ContainerNotFoundError", () => Effect.succeed({ ok: false })), Effect.catchTag("PrismaApiError", (e) => Effect.fail(/* @__PURE__ */ new Error(`Prisma Management API error resolving containers: ${e.message}.`)))), client);
974
984
  if (!outcome.ok) return void 0;
975
985
  return new PrismaCloudContainer(input, outcome.container.projectId, outcome.container.branchId, outcome.container.defaultBranchId);
976
986
  }
@@ -979,14 +989,13 @@ async function locateContainer(input, deps) {
979
989
  * has removed its members — the Management API refuses to delete a Branch
980
990
  * that still has live members.
981
991
  */
982
- async function removeStageBranch(branchId, deps) {
983
- requireTokenUnlessInjected(deps);
984
- const program = deleteBranch(branchId).pipe(Effect.map(() => ({ ok: true })), Effect.catchTag("PrismaApiError", (e) => Effect.succeed({
992
+ async function removeStageBranch(branchId, credentials, deps) {
993
+ const client = clientFor(credentials, deps);
994
+ requireTokenUnlessInjected(client);
995
+ const outcome = await runWithClient(deleteBranch(branchId).pipe(Effect.map(() => ({ ok: true })), Effect.catchTag("PrismaApiError", (e) => Effect.succeed({
985
996
  ok: false,
986
997
  message: `Failed to delete the stage Branch: ${e.message}.`
987
- })));
988
- const provided = deps?.client !== void 0 ? program.pipe(Effect.provideService(ManagementClient, deps.client)) : program.pipe(Effect.provide(layer().pipe(Layer.provide(fromEnv()))));
989
- const outcome = await Effect.runPromise(provided);
998
+ }))), client);
990
999
  if (!outcome.ok) throw new Error(outcome.message);
991
1000
  }
992
1001
  /**
@@ -997,17 +1006,16 @@ async function removeStageBranch(branchId, deps) {
997
1006
  * 400 ("still has dependencies") is the only check that matters — failing
998
1007
  * the command over a cleanup step would be worse than leaving a Project shell.
999
1008
  */
1000
- async function removeAppProject(projectId, deps) {
1001
- if (deps?.client === void 0 && (process.env["PRISMA_SERVICE_TOKEN"] ?? "").length === 0) {
1009
+ async function removeAppProject(projectId, credentials, deps) {
1010
+ const client = clientFor(credentials, deps);
1011
+ if (client === void 0 && (process.env["PRISMA_SERVICE_TOKEN"] ?? "").length === 0) {
1002
1012
  console.warn(`Skipped removing the Project (${projectId}): PRISMA_SERVICE_TOKEN is not set.`);
1003
1013
  return;
1004
1014
  }
1005
- const program = deleteProject(projectId).pipe(Effect.map(() => ({ ok: true })), Effect.catchTag("PrismaApiError", (e) => Effect.succeed({
1015
+ const outcome = await runWithClient(deleteProject(projectId).pipe(Effect.map(() => ({ ok: true })), Effect.catchTag("PrismaApiError", (e) => Effect.succeed({
1006
1016
  ok: false,
1007
1017
  error: e
1008
- })));
1009
- const provided = deps?.client !== void 0 ? program.pipe(Effect.provideService(ManagementClient, deps.client)) : program.pipe(Effect.provide(layer().pipe(Layer.provide(fromEnv()))));
1010
- const outcome = await Effect.runPromise(provided);
1018
+ }))), client);
1011
1019
  if (outcome.ok) {
1012
1020
  console.log(`Removed the Project (${projectId}) — nothing was left in it.`);
1013
1021
  return;
@@ -1020,9 +1028,9 @@ async function removeAppProject(projectId, deps) {
1020
1028
  }
1021
1029
  function containerDescriptor(deps) {
1022
1030
  return {
1023
- ensure: (input) => ensureContainer(input, deps),
1024
- locate: (input) => locateContainer(input, deps),
1025
- remove: (instance) => instance.input.stage !== void 0 ? removeStageBranch(instance.branchId ?? missingBranchId(instance), deps) : removeAppProject(instance.projectId, deps),
1031
+ ensure: (input, credentials) => ensureContainer(input, credentials, deps),
1032
+ locate: (input, credentials) => locateContainer(input, credentials, deps),
1033
+ remove: (instance, credentials) => instance.input.stage !== void 0 ? removeStageBranch(instance.branchId ?? missingBranchId(instance), credentials, deps) : removeAppProject(instance.projectId, credentials, deps),
1026
1034
  deserialize
1027
1035
  };
1028
1036
  }
@@ -1458,4 +1466,4 @@ const S3CredentialsProvider = () => Provider.effect(S3Credentials, Effect.succee
1458
1466
  //#endregion
1459
1467
  export { packageComputeArtifact as A, call as B, Project as C, EnvironmentVariable as D, Deployment as E, resolveDefaultBranchId as F, layer as H, MANAGEMENT_API_ORIGIN as I, ManagementClient as L, BucketKey as M, collectPages as N, ServiceKey as O, drivePagesAsync as P, PrismaApiError as R, Database as S, ComputeService as T, fromEnv as V, resolveTargetRef as _, PgWarmProvider as a, providers as b, PrismaCloudContainer as c, collectPreflightNames as d, containerDescriptor as f, resolvePrismaNextConfig as g, prismaCloudContainerOf as h, PgWarm as i, Bucket as j, ServiceKeyProvider as k, S3Credentials as l, packHeadRefHashes as m, GeneratedParamProvider as n, PnMigration as o, deserialize as p, PRISMA_CLOUD_EXTENSION_ID as r, PnMigrationProvider as s, GeneratedParam as t, S3CredentialsProvider as u, mintKeyPair as v, COMPUTE_REGIONS as w, Connection as x, Providers as y, PrismaCredentials as z };
1460
1468
 
1461
- //# sourceMappingURL=s3-credentials-resource-CqOODiAr-C3jW4ft6.mjs.map
1469
+ //# sourceMappingURL=s3-credentials-resource-BltGd-gG-CKs9XXiR.mjs.map