@prisma/composer-prisma-cloud 0.31.0-dev.1 → 0.31.0-dev.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  import { t as blindCast$1 } from "./casts-DpaahrlC-Ykus3kCE.mjs";
2
- import { C as Providers, E as ServiceKeyProvider, O as isWithin, S as mintKeyPair, b as serviceAppName, c as PgWarmProvider, d as S3CredentialsProvider, f as collectPreflightNames, g as prismaCloudContainerOf, l as PrismaCloudContainer, m as deserialize, n as GeneratedParamProvider, r as LocalOrmMigrationProvider, y as resourceName } from "./s3-credentials-resource-D4jcpAZp-5IHVSv4P.mjs";
2
+ import { C as Providers, E as ServiceKeyProvider, O as isWithin, S as mintKeyPair, b as serviceAppName, c as PgWarmProvider, d as S3CredentialsProvider, f as collectPreflightNames, g as prismaCloudContainerOf, l as PrismaCloudContainer, m as deserialize, n as GeneratedParamProvider, r as LocalOrmMigrationProvider, y as resourceName } from "./s3-credentials-resource-D4jcpAZp-BaOuPNI5.mjs";
3
3
  import { createRequire } from "node:module";
4
4
  import { blindCast } from "@prisma/composer/casts";
5
5
  import * as Effect from "effect/Effect";
@@ -5884,28 +5884,42 @@ function idsOf(nodes, kind) {
5884
5884
  }
5885
5885
  /**
5886
5886
  * Stops the service processes and database servers of `nodes`, keeping
5887
- * their data and ports, and returns the nodes it stopped. A kind whose
5888
- * emulator is not running has nothing running to stop.
5887
+ * their data and ports, and returns the nodes that were running. A kind
5888
+ * whose emulator is not running has nothing running to stop.
5889
5889
  */
5890
5890
  async function stopNodes(nodes) {
5891
5891
  const services = idsOf(nodes, "service");
5892
5892
  const databases = idsOf(nodes, "database");
5893
- const results = await Promise.allSettled([services.length > 0 && whenRunning("service", () => computeClient().stopInstances(services)), databases.length > 0 && whenRunning("database", () => postgresClient().stopInstances(databases))]);
5893
+ const results = await Promise.allSettled([stopRunning("service", services), stopRunning("database", databases)]);
5894
5894
  const failure = results.find((result) => result.status === "rejected");
5895
5895
  if (failure) throw failure.reason;
5896
- const stoppedKinds = /* @__PURE__ */ new Set();
5897
- if (results[0].status === "fulfilled" && results[0].value === true) stoppedKinds.add("service");
5898
- if (results[1].status === "fulfilled" && results[1].value === true) stoppedKinds.add("database");
5899
- return Object.entries(nodes).flatMap(([address, node]) => node.kind !== "bucket" && stoppedKinds.has(node.kind) ? [{
5896
+ const stoppedIds = new Set(results.flatMap((result) => result.status === "fulfilled" ? result.value : []));
5897
+ return Object.entries(nodes).flatMap(([address, node]) => node.kind !== "bucket" && stoppedIds.has(node.id) ? [{
5900
5898
  address,
5901
5899
  kind: node.kind
5902
5900
  }] : []);
5903
5901
  }
5904
- /** Runs `action` when the emulator for `kind` is running; returns whether it ran. */
5905
- async function whenRunning(kind, action) {
5906
- if (!await isEmulatorRunning(kind)) return false;
5907
- await action();
5908
- return true;
5902
+ /**
5903
+ * Sends a stop for every one of `ids` on the emulator for `kind`, since an
5904
+ * instance whose start is in flight can still be listed as `stopped`, and
5905
+ * returns those that were running. A `held` service with no process is
5906
+ * left `held`.
5907
+ */
5908
+ async function stopRunning(kind, ids) {
5909
+ if (ids.length === 0 || !await isEmulatorRunning(kind)) return [];
5910
+ const wanted = new Set(ids);
5911
+ if (kind === "service") {
5912
+ const client = computeClient();
5913
+ const listed = (await client.listInstances()).filter((i) => wanted.has(i.id));
5914
+ const settledHeld = new Set(listed.filter((i) => i.status === "held" && i.pid === void 0).map((i) => i.id));
5915
+ const toStop = ids.filter((id) => !settledHeld.has(id));
5916
+ if (toStop.length > 0) await client.stopInstances(toStop);
5917
+ return listed.filter((i) => i.pid !== void 0 || i.status === "running" || i.status === "backoff").map((i) => i.id);
5918
+ }
5919
+ const client = postgresClient();
5920
+ const listed = (await client.listInstances()).filter((i) => wanted.has(i.id));
5921
+ await client.stopInstances(ids);
5922
+ return listed.filter((i) => i.status === "running").map((i) => i.id);
5909
5923
  }
5910
5924
  /**
5911
5925
  * Makes `scope.app` the directory's current app. When another app ran here