@prisma/compute-sdk 0.22.0 → 0.24.0

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.
@@ -0,0 +1,91 @@
1
+ import { readFile, stat } from "node:fs/promises";
2
+ import path from "node:path";
3
+
4
+ /**
5
+ * Resolves the directories from `startPath` up to its source root, nearest
6
+ * first. The source root is the closest ancestor that looks like a repository
7
+ * or workspace root; a standalone directory is its own source root, so
8
+ * discovery never escapes into unrelated parent directories.
9
+ */
10
+ export async function resolveSourceRoot(
11
+ startPath: string,
12
+ signal?: AbortSignal,
13
+ ): Promise<string> {
14
+ let current = path.resolve(startPath);
15
+
16
+ while (true) {
17
+ if (
18
+ (await pathExists(path.join(current, ".git"), signal)) ||
19
+ (await pathExists(path.join(current, "pnpm-workspace.yaml"), signal)) ||
20
+ (await pathExists(path.join(current, "bun.lock"), signal)) ||
21
+ (await pathExists(path.join(current, "bun.lockb"), signal)) ||
22
+ (await packageJsonDeclaresWorkspaces(current, signal))
23
+ ) {
24
+ return current;
25
+ }
26
+
27
+ const parent = path.dirname(current);
28
+ if (parent === current) {
29
+ return path.resolve(startPath);
30
+ }
31
+
32
+ current = parent;
33
+ }
34
+ }
35
+
36
+ /** Directories from `startPath` up to its source root, nearest first. */
37
+ export async function sourceRootLineage(
38
+ startPath: string,
39
+ signal?: AbortSignal,
40
+ ): Promise<string[]> {
41
+ const sourceRoot = await resolveSourceRoot(startPath, signal);
42
+ const lineage: string[] = [];
43
+ let current = path.resolve(startPath);
44
+
45
+ while (true) {
46
+ lineage.push(current);
47
+ if (current === sourceRoot) {
48
+ return lineage;
49
+ }
50
+
51
+ const parent = path.dirname(current);
52
+ if (parent === current) {
53
+ return lineage;
54
+ }
55
+
56
+ current = parent;
57
+ }
58
+ }
59
+
60
+ async function packageJsonDeclaresWorkspaces(
61
+ directory: string,
62
+ signal?: AbortSignal,
63
+ ): Promise<boolean> {
64
+ signal?.throwIfAborted();
65
+ try {
66
+ const content = await readFile(path.join(directory, "package.json"), {
67
+ encoding: "utf8",
68
+ signal,
69
+ });
70
+ const parsed = JSON.parse(content) as { workspaces?: unknown };
71
+ return Boolean(parsed.workspaces);
72
+ } catch (error) {
73
+ if (signal?.aborted) throw error;
74
+ return false;
75
+ }
76
+ }
77
+
78
+ async function pathExists(
79
+ targetPath: string,
80
+ signal?: AbortSignal,
81
+ ): Promise<boolean> {
82
+ try {
83
+ signal?.throwIfAborted();
84
+ await stat(targetPath);
85
+ signal?.throwIfAborted();
86
+ return true;
87
+ } catch (error) {
88
+ if (signal?.aborted) throw error;
89
+ return false;
90
+ }
91
+ }
@@ -0,0 +1,78 @@
1
+ /**
2
+ * The compute config contract: the shape of `prisma.compute.ts`.
3
+ *
4
+ * This module is the shared source of truth for every consumer of the
5
+ * deploy graph (CLI, build-runner, scaffolding). It must stay free of
6
+ * runtime dependencies so user config files can import it cheaply.
7
+ */
8
+
9
+ export const COMPUTE_FRAMEWORKS = [
10
+ "nextjs",
11
+ "nuxt",
12
+ "astro",
13
+ "hono",
14
+ "tanstack-start",
15
+ "bun",
16
+ ] as const;
17
+
18
+ export type ComputeFramework = (typeof COMPUTE_FRAMEWORKS)[number];
19
+
20
+ export interface ComputeEnvConfig {
21
+ /** Dotenv file path(s) resolved relative to the config file directory. */
22
+ file?: string | string[];
23
+ /**
24
+ * Inline environment variable assignments. Values must be non-empty and
25
+ * are deployed as-is. This file is committed — keep secrets in platform
26
+ * branch config; consumers may ignore inline vars on git-push deploys.
27
+ */
28
+ vars?: Record<string, string>;
29
+ }
30
+
31
+ export interface ComputeBuildConfig {
32
+ /** Build command run in the app root. `null` skips the build step. */
33
+ command?: string | null;
34
+ /** Framework output path relative to the app root, e.g. ".next/standalone". */
35
+ outputDirectory?: string;
36
+ }
37
+
38
+ export interface ComputeAppConfig {
39
+ /** Deployed app name. Defaults to the `apps` key, then consumer-side inference. */
40
+ name?: string;
41
+ /** App directory relative to the config file. Defaults to the config file directory. */
42
+ root?: string;
43
+ /** Framework to deploy. Defaults to detection from the app directory. */
44
+ framework?: ComputeFramework;
45
+ /** Entrypoint path for Bun (and Hono) deploys, relative to the app root. */
46
+ entry?: string;
47
+ /** HTTP port the deployed app listens on. Defaults to the framework default. */
48
+ httpPort?: number;
49
+ /** Environment variables for the deploy. A string is shorthand for `{ file }`. */
50
+ env?: string | ComputeEnvConfig;
51
+ /** Build settings. When present, these own the app's build configuration. */
52
+ build?: ComputeBuildConfig;
53
+ }
54
+
55
+ /**
56
+ * `prisma.compute.ts` accepts exactly one of:
57
+ *
58
+ * - `app` — a repository that deploys a single app
59
+ * - `apps` — a monorepo or multi-app repository, keyed by deploy target
60
+ */
61
+ export type ComputeConfig =
62
+ | { app: ComputeAppConfig; apps?: never }
63
+ | { apps: Record<string, ComputeAppConfig>; app?: never };
64
+
65
+ /**
66
+ * Identity helper that gives `prisma.compute.ts` full type checking:
67
+ *
68
+ * ```ts
69
+ * import { defineComputeConfig } from "@prisma/compute-sdk/config";
70
+ *
71
+ * export default defineComputeConfig({
72
+ * app: { framework: "hono", httpPort: 8080 },
73
+ * });
74
+ * ```
75
+ */
76
+ export function defineComputeConfig(config: ComputeConfig): ComputeConfig {
77
+ return config;
78
+ }