@prisma/cli-engine 0.0.1
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.
- package/LICENSE +158 -0
- package/README.md +11 -0
- package/dist/engine-DXE014TZ.js +1703 -0
- package/dist/index.d.ts +57 -0
- package/dist/index.js +200 -0
- package/dist/protocol-C1JQcGl9.js +106 -0
- package/dist/protocol-DGUfR-Ni.d.ts +117 -0
- package/dist/protocol.d.ts +2 -0
- package/dist/protocol.js +2 -0
- package/dist/run-summary-CPpYAYtS.d.ts +787 -0
- package/dist/testing.d.ts +67 -0
- package/dist/testing.js +96 -0
- package/package.json +60 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { F as PresentedResult, O as Credentials, R as ManagementApiClient, V as StreamEvent, i as MountedTree, n as RunSummary, r as CommandFamily, z as EngineEvent } from "./run-summary-CPpYAYtS.js";
|
|
2
|
+
|
|
3
|
+
//#region src/testing.d.ts
|
|
4
|
+
interface TestCli {
|
|
5
|
+
run(argv: readonly string[], opts?: {
|
|
6
|
+
readonly stdin?: string;
|
|
7
|
+
/**
|
|
8
|
+
* Scripted prompt answers, consumed in order; a run that prompts
|
|
9
|
+
* past the script fails the test.
|
|
10
|
+
*/
|
|
11
|
+
readonly answers?: ReadonlyArray<string | boolean>;
|
|
12
|
+
/**
|
|
13
|
+
* Abort the run (session tests): its firing is delivered to the
|
|
14
|
+
* engine as a signal (SIGTERM when the reason is 'SIGTERM',
|
|
15
|
+
* SIGINT otherwise).
|
|
16
|
+
*/
|
|
17
|
+
readonly abort?: AbortSignal; /** Live event tap, for asserting mid-session behavior. */
|
|
18
|
+
readonly onEvent?: (event: EngineEvent) => void;
|
|
19
|
+
/** Settlement tap: receives the RunSummary the engine fires
|
|
20
|
+
* after settlement (once, mounted runs only). */
|
|
21
|
+
readonly onSettled?: (summary: RunSummary) => void;
|
|
22
|
+
readonly cwd?: string;
|
|
23
|
+
readonly isTty?: {
|
|
24
|
+
stdin?: boolean;
|
|
25
|
+
stdout?: boolean;
|
|
26
|
+
stderr?: boolean;
|
|
27
|
+
};
|
|
28
|
+
readonly env?: Readonly<Record<string, string | undefined>>;
|
|
29
|
+
}): Promise<{
|
|
30
|
+
readonly exitCode: number;
|
|
31
|
+
readonly stdout: string;
|
|
32
|
+
readonly stderr: string; /** Parsed stream (events + the terminal result) when json mode. */
|
|
33
|
+
readonly json: readonly StreamEvent[]; /** Every EngineEvent the handler emitted, for semantic assertions. */
|
|
34
|
+
readonly events: readonly EngineEvent[];
|
|
35
|
+
/**
|
|
36
|
+
* The PresentedResult the handler returned, for semantic assertions
|
|
37
|
+
* without byte-scraping; undefined when the run never presented.
|
|
38
|
+
*/
|
|
39
|
+
readonly presented: PresentedResult<unknown> | undefined;
|
|
40
|
+
}>;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The test harness: the same engine over in-memory streams. The
|
|
44
|
+
* harness hands the engine no real process access at all — its exit
|
|
45
|
+
* proxy throws and its streams are in-memory — which is how "the engine
|
|
46
|
+
* never touches process globals and writes only to provided streams" is
|
|
47
|
+
* proven by construction.
|
|
48
|
+
*/
|
|
49
|
+
declare function createTestCli(spec: {
|
|
50
|
+
readonly commandFamilies?: readonly CommandFamily[];
|
|
51
|
+
readonly commands: MountedTree;
|
|
52
|
+
readonly groups?: Readonly<Record<string, {
|
|
53
|
+
readonly brief: string;
|
|
54
|
+
}>>;
|
|
55
|
+
readonly config?: Readonly<Record<string, unknown>>;
|
|
56
|
+
readonly credentials?: Credentials;
|
|
57
|
+
/** baseUrl defaults to "https://test.invalid"; when `client` is
|
|
58
|
+
* supplied, ctx.api IS that object. */
|
|
59
|
+
readonly managementApi?: {
|
|
60
|
+
readonly baseUrl?: string;
|
|
61
|
+
readonly client?: ManagementApiClient;
|
|
62
|
+
};
|
|
63
|
+
readonly packageManager?: "npm" | "pnpm" | "yarn" | "bun" | "unknown"; /** Fixed clock for deterministic stream timestamps. */
|
|
64
|
+
readonly now?: () => Date;
|
|
65
|
+
}): TestCli;
|
|
66
|
+
//#endregion
|
|
67
|
+
export { type TestCli, createTestCli };
|
package/dist/testing.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { t as buildEngine } from "./engine-DXE014TZ.js";
|
|
2
|
+
//#region src/testing.ts
|
|
3
|
+
function inputStreamFromString(text) {
|
|
4
|
+
const bytes = new TextEncoder().encode(text);
|
|
5
|
+
return { async *[Symbol.asyncIterator]() {
|
|
6
|
+
if (bytes.length > 0) yield bytes;
|
|
7
|
+
} };
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The test harness: the same engine over in-memory streams. The
|
|
11
|
+
* harness hands the engine no real process access at all — its exit
|
|
12
|
+
* proxy throws and its streams are in-memory — which is how "the engine
|
|
13
|
+
* never touches process globals and writes only to provided streams" is
|
|
14
|
+
* proven by construction.
|
|
15
|
+
*/
|
|
16
|
+
function createTestCli(spec) {
|
|
17
|
+
const engine = buildEngine({
|
|
18
|
+
name: "prisma-test",
|
|
19
|
+
version: "0.0.0",
|
|
20
|
+
commandFamilies: spec.commandFamilies ?? [],
|
|
21
|
+
groups: spec.groups ?? {},
|
|
22
|
+
commands: spec.commands
|
|
23
|
+
}, { now: spec.now });
|
|
24
|
+
return { async run(argv, opts) {
|
|
25
|
+
let stdoutText = "";
|
|
26
|
+
let stderrText = "";
|
|
27
|
+
const frames = [];
|
|
28
|
+
const events = [];
|
|
29
|
+
let presented;
|
|
30
|
+
const signalListeners = /* @__PURE__ */ new Set();
|
|
31
|
+
const deliverSignal = (reason) => {
|
|
32
|
+
const signal = reason === "SIGTERM" ? "SIGTERM" : "SIGINT";
|
|
33
|
+
for (const listener of [...signalListeners]) listener(signal);
|
|
34
|
+
};
|
|
35
|
+
const runtime = {
|
|
36
|
+
stdout: { write: (text) => {
|
|
37
|
+
stdoutText += text;
|
|
38
|
+
} },
|
|
39
|
+
stderr: { write: (text) => {
|
|
40
|
+
stderrText += text;
|
|
41
|
+
} },
|
|
42
|
+
stdin: inputStreamFromString(opts?.stdin ?? ""),
|
|
43
|
+
cwd: opts?.cwd ?? "/",
|
|
44
|
+
env: opts?.env ?? {},
|
|
45
|
+
isTty: {
|
|
46
|
+
stdin: opts?.isTty?.stdin ?? false,
|
|
47
|
+
stdout: opts?.isTty?.stdout ?? false,
|
|
48
|
+
stderr: opts?.isTty?.stderr ?? false
|
|
49
|
+
},
|
|
50
|
+
exit: (code) => {
|
|
51
|
+
throw new Error(`@prisma/cli-engine: runtime.exit(${code}) reached the test harness`);
|
|
52
|
+
},
|
|
53
|
+
onSignal: (cb) => {
|
|
54
|
+
signalListeners.add(cb);
|
|
55
|
+
return () => {
|
|
56
|
+
signalListeners.delete(cb);
|
|
57
|
+
};
|
|
58
|
+
},
|
|
59
|
+
config: {
|
|
60
|
+
sections: spec.config ?? {},
|
|
61
|
+
diagnostics: []
|
|
62
|
+
},
|
|
63
|
+
getCredentials: async () => spec.credentials,
|
|
64
|
+
managementApi: { baseUrl: spec.managementApi?.baseUrl ?? "https://test.invalid" },
|
|
65
|
+
packageManager: spec.packageManager ?? "unknown"
|
|
66
|
+
};
|
|
67
|
+
const running = engine.execute(argv, runtime, {
|
|
68
|
+
onEvent: (event) => {
|
|
69
|
+
events.push(event);
|
|
70
|
+
opts?.onEvent?.(event);
|
|
71
|
+
},
|
|
72
|
+
onPresented: (value) => {
|
|
73
|
+
presented = value;
|
|
74
|
+
},
|
|
75
|
+
onStreamEvent: (frame) => {
|
|
76
|
+
frames.push(frame);
|
|
77
|
+
},
|
|
78
|
+
onSettled: opts?.onSettled,
|
|
79
|
+
answers: opts?.answers,
|
|
80
|
+
managementApi: spec.managementApi?.client === void 0 ? void 0 : { client: spec.managementApi.client }
|
|
81
|
+
});
|
|
82
|
+
const abort = opts?.abort;
|
|
83
|
+
if (abort !== void 0) if (abort.aborted) deliverSignal(abort.reason);
|
|
84
|
+
else abort.addEventListener("abort", () => deliverSignal(abort.reason), { once: true });
|
|
85
|
+
return {
|
|
86
|
+
exitCode: await running,
|
|
87
|
+
stdout: stdoutText,
|
|
88
|
+
stderr: stderrText,
|
|
89
|
+
json: frames,
|
|
90
|
+
events,
|
|
91
|
+
presented
|
|
92
|
+
};
|
|
93
|
+
} };
|
|
94
|
+
}
|
|
95
|
+
//#endregion
|
|
96
|
+
export { createTestCli };
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@prisma/cli-engine",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "The execution engine of the unified Prisma CLI.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"import": "./dist/index.js"
|
|
10
|
+
},
|
|
11
|
+
"./package.json": "./package.json",
|
|
12
|
+
"./protocol": {
|
|
13
|
+
"types": "./dist/protocol.d.ts",
|
|
14
|
+
"import": "./dist/protocol.js"
|
|
15
|
+
},
|
|
16
|
+
"./testing": {
|
|
17
|
+
"types": "./dist/testing.d.ts",
|
|
18
|
+
"import": "./dist/testing.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"README.md",
|
|
24
|
+
"LICENSE"
|
|
25
|
+
],
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=22.12.0"
|
|
31
|
+
},
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "https://github.com/prisma/prisma-cli.git",
|
|
35
|
+
"directory": "packages/cli-engine"
|
|
36
|
+
},
|
|
37
|
+
"homepage": "https://github.com/prisma/prisma-cli#readme",
|
|
38
|
+
"bugs": {
|
|
39
|
+
"url": "https://github.com/prisma/prisma-cli/issues"
|
|
40
|
+
},
|
|
41
|
+
"license": "Apache-2.0",
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "tsdown",
|
|
44
|
+
"prepack": "pnpm run build",
|
|
45
|
+
"typecheck": "tsc --noEmit",
|
|
46
|
+
"test": "pnpm run build && pnpm run typecheck && vitest run"
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"@clack/prompts": "1.5.0",
|
|
50
|
+
"@prisma/management-api-sdk": "1.55.0",
|
|
51
|
+
"@stricli/core": "1.3.0"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@repo/tsconfig": "workspace:8.0.0-rc.1",
|
|
55
|
+
"@types/node": "^22.19.19",
|
|
56
|
+
"tsdown": "^0.21.10",
|
|
57
|
+
"typescript": "^6.0.3",
|
|
58
|
+
"vitest": "^4.1.8"
|
|
59
|
+
}
|
|
60
|
+
}
|