@prisma/composer-prisma-cloud 0.30.0-dev.4 → 0.30.0-dev.6

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 +1 @@
1
- {"version":3,"file":"local-target.d.mts","names":[],"sources":["../../../1-prisma-cloud/0-lowering/dev-emulators/dist/index.d.mts","../../../1-prisma-cloud/1-extensions/target/dist/local-target.d.mts"],"mappings":";;;cAac;;iBAEG;;;;;;;;;iBCPA,yBAAyB"}
1
+ {"version":3,"file":"local-target.d.mts","names":[],"sources":["../../../1-prisma-cloud/0-lowering/dev-emulators/dist/index.d.mts","../../../1-prisma-cloud/1-extensions/target/dist/local-target.d.mts"],"mappings":";;;cAec;;iBAEG;;;;;;;;;iBCTA,yBAAyB"}
@@ -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-6qCQY8BD.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-X6h7aZcG.mjs";
3
3
  import { createRequire } from "node:module";
4
4
  import { blindCast } from "@prisma/composer/casts";
5
5
  import * as Effect from "effect/Effect";
@@ -58,6 +58,21 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
58
58
  }) : target, mod));
59
59
  var __require = /* #__PURE__ */ (() => createRequire(import.meta.url))();
60
60
  //#endregion
61
+ //#region ../../0-framework/0-foundation/foundation/dist/internal-error-Dfur7Zqt.mjs
62
+ /**
63
+ * A bug in Prisma ORM, not a user error. Never catch this except at the
64
+ * outermost boundary for crash reporting — an InternalError means an invariant
65
+ * broke and the process cannot reliably continue. User-facing failures use
66
+ * `structuredError` with a dotted code instead.
67
+ */
68
+ var InternalError = class extends Error {
69
+ isPrismaInternalError = true;
70
+ constructor(message, options) {
71
+ super(message, options?.cause !== void 0 ? { cause: options.cause } : void 0);
72
+ this.name = "InternalError";
73
+ }
74
+ };
75
+ //#endregion
61
76
  //#region ../../0-framework/0-foundation/foundation/dist/errors.mjs
62
77
  /**
63
78
  * Returns an object with the key/value if value is defined, otherwise an empty object.
@@ -1780,6 +1795,9 @@ function isPidAlive(pid) {
1780
1795
  return false;
1781
1796
  }
1782
1797
  }
1798
+ async function readRegistryEntry(registryRoot, name) {
1799
+ return readJsonFile(registryFilePath(registryRoot, name), isRegistryEntry$1);
1800
+ }
1783
1801
  async function probeHealth(port, healthPath, timeoutMs) {
1784
1802
  try {
1785
1803
  const res = await fetch(`http://127.0.0.1:${port}${healthPath}`, { signal: AbortSignal.timeout(timeoutMs) });
@@ -2050,6 +2068,53 @@ async function ensureDaemon(name, entry, opts = {}) {
2050
2068
  await release();
2051
2069
  }
2052
2070
  }
2071
+ (class ResultImpl {
2072
+ ok;
2073
+ _value;
2074
+ _failure;
2075
+ constructor(ok, valueOrFailure) {
2076
+ this.ok = ok;
2077
+ if (ok) this._value = blindCast$1(valueOrFailure);
2078
+ else this._failure = blindCast$1(valueOrFailure);
2079
+ Object.freeze(this);
2080
+ }
2081
+ get value() {
2082
+ if (!this.ok) throw new InternalError("Cannot access value on NotOk result");
2083
+ return this._value;
2084
+ }
2085
+ get failure() {
2086
+ if (this.ok) throw new InternalError("Cannot access failure on Ok result");
2087
+ return this._failure;
2088
+ }
2089
+ /**
2090
+ * Creates a successful result.
2091
+ */
2092
+ static ok(value) {
2093
+ return blindCast$1(new ResultImpl(true, value));
2094
+ }
2095
+ /**
2096
+ * Creates an unsuccessful result.
2097
+ */
2098
+ static notOk(failure) {
2099
+ return blindCast$1(new ResultImpl(false, failure));
2100
+ }
2101
+ /**
2102
+ * Asserts that this result is Ok and returns the value.
2103
+ * Throws if the result is NotOk.
2104
+ */
2105
+ assertOk() {
2106
+ if (!this.ok) throw new InternalError("Expected Ok result but got NotOk");
2107
+ return this.value;
2108
+ }
2109
+ /**
2110
+ * Asserts that this result is NotOk and returns the failure.
2111
+ * Throws if the result is Ok.
2112
+ */
2113
+ assertNotOk() {
2114
+ if (this.ok) throw new InternalError("Expected NotOk result but got Ok");
2115
+ return this.failure;
2116
+ }
2117
+ }).ok(void 0);
2053
2118
  //#endregion
2054
2119
  //#region ../../1-prisma-cloud/0-lowering/dev-emulators/dist/index.mjs
2055
2120
  /**
@@ -2307,6 +2372,16 @@ function postgresClient(opts = {}) {
2307
2372
  }
2308
2373
  };
2309
2374
  }
2375
+ const DAEMON_OF$1 = {
2376
+ service: "compute",
2377
+ database: "postgres",
2378
+ bucket: "buckets"
2379
+ };
2380
+ /** Whether the emulator for `kind` is registered with a live process. */
2381
+ async function isEmulatorRunning(kind, opts = {}) {
2382
+ const entry = await readRegistryEntry(opts.registryRoot ?? defaultRegistryRoot(), DAEMON_OF$1[kind]);
2383
+ return entry !== void 0 && isPidAlive(entry.pid);
2384
+ }
2310
2385
  //#endregion
2311
2386
  //#region ../../../node_modules/tar/dist/esm/index.min.js
2312
2387
  var zr = Object.defineProperty;
@@ -5777,6 +5852,10 @@ async function readRecord(devDir) {
5777
5852
  async function updateRecord(devDir, mutate) {
5778
5853
  await store(devDir).update((stored) => mutate(normalized(stored)));
5779
5854
  }
5855
+ /** The record `prisma dev` left in `directory`; undefined when it has not run there. */
5856
+ function readEmulatorInstances(directory) {
5857
+ return readRecord(path$1.join(directory, DEV_DIR));
5858
+ }
5780
5859
  async function appNodes$1(scope) {
5781
5860
  return (await readRecord(scope.devDir))?.apps[scope.app]?.nodes ?? {};
5782
5861
  }
@@ -5805,24 +5884,28 @@ function idsOf(nodes, kind) {
5805
5884
  }
5806
5885
  /**
5807
5886
  * Stops the service processes and database servers of `nodes`, keeping
5808
- * their data and ports. A kind whose emulator is not running has nothing
5809
- * running to stop.
5887
+ * their data and ports, and returns the nodes it stopped. A kind whose
5888
+ * emulator is not running has nothing running to stop.
5810
5889
  */
5811
5890
  async function stopNodes(nodes) {
5812
5891
  const services = idsOf(nodes, "service");
5813
5892
  const databases = idsOf(nodes, "database");
5814
- const failure = (await Promise.allSettled([services.length > 0 ? whenRunning(() => computeClient().stopInstances(services)) : void 0, databases.length > 0 ? whenRunning(() => postgresClient().stopInstances(databases)) : void 0])).find((result) => result.status === "rejected");
5893
+ const results = await Promise.allSettled([services.length > 0 && whenRunning("service", () => computeClient().stopInstances(services)), databases.length > 0 && whenRunning("database", () => postgresClient().stopInstances(databases))]);
5894
+ const failure = results.find((result) => result.status === "rejected");
5815
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) ? [{
5900
+ address,
5901
+ kind: node.kind
5902
+ }] : []);
5816
5903
  }
5817
- /** Runs `action` against an emulator, treating "the emulator is not running" as nothing to do. */
5818
- async function whenRunning(action) {
5819
- let run;
5820
- try {
5821
- run = action();
5822
- } catch {
5823
- return;
5824
- }
5825
- await run;
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;
5826
5909
  }
5827
5910
  /**
5828
5911
  * Makes `scope.app` the directory's current app. When another app ran here
@@ -5990,7 +6073,7 @@ async function deleteAppInstances(scope) {
5990
6073
  }
5991
6074
  /** When `prisma dev` ends: stops the app's service processes and database servers, keeping their data and ports. */
5992
6075
  async function stopAppInstances(scope) {
5993
- await stopNodes(await appNodes$1(scope));
6076
+ return stopNodes(await appNodes$1(scope));
5994
6077
  }
5995
6078
  /**
5996
6079
  * The emulators' failure messages name instances by id; `prisma dev` names
@@ -6490,6 +6573,84 @@ function LocalProjectProvider(_input) {
6490
6573
  delete: () => Effect.void
6491
6574
  }));
6492
6575
  }
6576
+ const CONDITION_OF = {
6577
+ running: "running",
6578
+ stopped: "stopped",
6579
+ backoff: "crashing",
6580
+ held: "crashing"
6581
+ };
6582
+ /** A node whose emulator no longer has the instance the record names. */
6583
+ function missing(address, kind) {
6584
+ return {
6585
+ address,
6586
+ kind,
6587
+ emulator: "running",
6588
+ state: "missing",
6589
+ condition: "missing"
6590
+ };
6591
+ }
6592
+ async function locate(address, node) {
6593
+ const kind = node.kind;
6594
+ if (!await isEmulatorRunning(kind)) return {
6595
+ address,
6596
+ kind,
6597
+ emulator: "not-running"
6598
+ };
6599
+ if (node.kind === "service") {
6600
+ const instance = await computeClient().getInstance(node.id);
6601
+ if (instance === void 0) return missing(address, kind);
6602
+ return {
6603
+ address,
6604
+ kind,
6605
+ emulator: "running",
6606
+ url: instance.url,
6607
+ state: instance.status,
6608
+ condition: CONDITION_OF[instance.status],
6609
+ logPath: instance.logPath
6610
+ };
6611
+ }
6612
+ if (node.kind === "database") {
6613
+ const instance = await postgresClient().getInstance(node.id);
6614
+ if (instance === void 0) return missing(address, kind);
6615
+ return {
6616
+ address,
6617
+ kind,
6618
+ emulator: "running",
6619
+ url: instance.url,
6620
+ state: instance.status,
6621
+ condition: instance.status
6622
+ };
6623
+ }
6624
+ const client = bucketsClient();
6625
+ if (await client.getInstance(node.id) === void 0) return missing(address, kind);
6626
+ return {
6627
+ address,
6628
+ kind,
6629
+ emulator: "running",
6630
+ url: `${client.baseUrl}/${node.id}`,
6631
+ state: "running",
6632
+ condition: "running"
6633
+ };
6634
+ }
6635
+ /** The directory's current app; undefined when `prisma dev` never ran there. */
6636
+ async function currentApp(devDir) {
6637
+ const record = await readEmulatorInstances(directoryOf(devDir));
6638
+ if (record === void 0) return void 0;
6639
+ const app = record.current;
6640
+ const nodes = record.apps[app]?.nodes ?? {};
6641
+ return {
6642
+ app,
6643
+ addresses: Object.keys(nodes),
6644
+ locate: async (address) => {
6645
+ const node = nodes[address];
6646
+ return node === void 0 ? void 0 : locate(address, node);
6647
+ },
6648
+ stop: () => stopAppInstances({
6649
+ devDir,
6650
+ app
6651
+ })
6652
+ };
6653
+ }
6493
6654
  /** Reads a database id from upstream's `database` input: a plain string or a resolved `Prisma.Database` attributes record. */
6494
6655
  function databaseIdOfInput(value) {
6495
6656
  if (typeof value === "string") return value;
@@ -6728,7 +6889,9 @@ async function devAttach(input) {
6728
6889
  }));
6729
6890
  },
6730
6891
  logs: (signal, opts) => mergedLogs(scope, signal, opts?.tail ?? 0),
6731
- stopApp: () => stopAppInstances(scope)
6892
+ stopApp: async () => {
6893
+ await stopAppInstances(scope);
6894
+ }
6732
6895
  };
6733
6896
  }
6734
6897
  const LOCAL_PROJECT_ID = "local";
@@ -6875,7 +7038,8 @@ function localTargetDescriptor() {
6875
7038
  preflight: (input) => runDevPreflight(input),
6876
7039
  emulators: (input) => runDevEmulators(input),
6877
7040
  attach: (input) => devAttach(input),
6878
- teardown: (input) => runDevTeardown(input)
7041
+ teardown: (input) => runDevTeardown(input),
7042
+ current: (input) => currentApp(input.devDir)
6879
7043
  };
6880
7044
  }
6881
7045
  //#endregion