@prisma/cli-engine 0.0.1 → 0.0.3
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/dist/index.d.ts +77 -2
- package/dist/index.js +121 -3
- package/dist/{protocol-DGUfR-Ni.d.ts → protocol-CpZLdxML.d.ts} +5 -1
- package/dist/protocol.d.ts +1 -1
- package/dist/{run-summary-CPpYAYtS.d.ts → run-summary-DMFNIvjx.d.ts} +420 -40
- package/dist/testing.d.ts +137 -5
- package/dist/testing.js +432 -79
- package/dist/{engine-DXE014TZ.js → token-claims-DXO0q52l.js} +1234 -407
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { $ as
|
|
1
|
+
import { $ as ActiveCredential, A as OpenUrlOutcome, B as exitWithChildStatus, C as InputStream, D as Runtime, E as PRISMA_CONFIG_VERSION, F as ExitWithChildStatusOptions, G as Presentations, H as Format, I as SpawnChild, J as Ui, K as PresentedResult, L as SpawnOptions, M as PromptSurface, N as ChildResult, O as BrowserWaitRequest, P as ChildStatusSettlement, Q as StreamMeta, R as SpawnRequest, S as HostProcess, T as OutputStream, U as Outcome, V as Block, W as PRESENTED, X as Severity, Y as EngineEvent, Z as StreamEvent, _ as SessionCommandDefinition, _t as PositionalSpec, a as defineCommandFamily, at as StoredSessions, b as defineServerCommand, c as CommandHandler, ct as TokenStorage, d as CompletedEnvelope, dt as defineConfigSection, et as Credential, f as ErroredEnvelope, ft as Args, g as ServerCommandDefinition, gt as FlagSpec, h as NeedsSpec, ht as CommandArgs, i as MountedTree, it as Session, j as OpenUrlRequest, k as CommandContext, l as CommandHelp, lt as ConfigSection, m as HelpSpec, mt as Char, n as RunSummary, nt as CredentialManager, o as AnyCommand, ot as ManagementApiClient, p as Handler, pt as ArgsSpec, q as TreeNode, r as CommandFamily, rt as CredentialOrigin, s as CommandDefinition, st as ManagementApiClientConfig, t as EngineCommandSnapshot, tt as CredentialIdentity, u as CommandNeeds, ut as SectionValidation, v as SpawnDeclarations, vt as flag, w as LoadedConfig, x as defineSessionCommand, y as defineCommand, yt as positional, z as SpawnedChild } from "./run-summary-DMFNIvjx.js";
|
|
2
|
+
import { n as CliStructuredError } from "./protocol-CpZLdxML.js";
|
|
2
3
|
|
|
3
4
|
//#region src/cli.d.ts
|
|
4
5
|
/**
|
|
@@ -54,4 +55,78 @@ declare function defineConfig<T extends Record<string, unknown>>(config: T): T &
|
|
|
54
55
|
*/
|
|
55
56
|
declare function loadConfig(cwd: string): Promise<LoadedConfig>;
|
|
56
57
|
//#endregion
|
|
57
|
-
|
|
58
|
+
//#region src/credential-errors.d.ts
|
|
59
|
+
type CredentialsRequiredReason = "unauthenticated" | "expired" | "expiring-soon" | "session-ended" | "sessions-held-none-selected";
|
|
60
|
+
/**
|
|
61
|
+
* The single constructor of CLI.CREDENTIALS_REQUIRED. Raised
|
|
62
|
+
* identically by the needs check, ctx.activeCredential, and the
|
|
63
|
+
* engine's request path.
|
|
64
|
+
*/
|
|
65
|
+
declare function credentialsRequiredError(reason?: CredentialsRequiredReason): CliStructuredError;
|
|
66
|
+
/**
|
|
67
|
+
* A refresh attempt failed transiently (the auth service, not the
|
|
68
|
+
* credentials): nothing was cleared, and signing in again is not the
|
|
69
|
+
* fix.
|
|
70
|
+
*/
|
|
71
|
+
declare function authServiceError(): CliStructuredError;
|
|
72
|
+
/**
|
|
73
|
+
* The credential in force was rejected and could never be renewed — it
|
|
74
|
+
* carries no refresh token. The ONE place wording differs by origin;
|
|
75
|
+
* nothing else compares against `origin.source`.
|
|
76
|
+
*/
|
|
77
|
+
declare function credentialRejectedError(origin: CredentialOrigin, envVar: string): CliStructuredError;
|
|
78
|
+
/**
|
|
79
|
+
* A credential's workspace_id claim disagrees with the workspace it is
|
|
80
|
+
* being stored under, or a rotated token would re-scope a session.
|
|
81
|
+
* Raised by every CredentialManager, so a test sees what production
|
|
82
|
+
* raises.
|
|
83
|
+
*/
|
|
84
|
+
declare function credentialWorkspaceMismatchError(workspaceId: string): CliStructuredError;
|
|
85
|
+
/**
|
|
86
|
+
* The env var that supplies a session is set to a blank value. The one
|
|
87
|
+
* structured error for it, raised identically by activeCredential(),
|
|
88
|
+
* the needs check, and the engine's request path.
|
|
89
|
+
*/
|
|
90
|
+
declare function emptyServiceTokenError(spec: {
|
|
91
|
+
readonly envVar: string;
|
|
92
|
+
}): CliStructuredError;
|
|
93
|
+
/**
|
|
94
|
+
* No session exists for the named workspace. Sessions are created by
|
|
95
|
+
* `prisma auth login` alone — `workspace use` selects among the ones
|
|
96
|
+
* you have.
|
|
97
|
+
*/
|
|
98
|
+
declare function noSessionForWorkspaceError(workspaceRef: string): CliStructuredError;
|
|
99
|
+
//#endregion
|
|
100
|
+
//#region src/environment-credential-manager.d.ts
|
|
101
|
+
declare class EnvironmentCredentialManager implements CredentialManager {
|
|
102
|
+
#private;
|
|
103
|
+
constructor(spec: {
|
|
104
|
+
readonly env: Readonly<Record<string, string | undefined>>;
|
|
105
|
+
});
|
|
106
|
+
activeCredential(): Promise<ActiveCredential | null>;
|
|
107
|
+
sessions(): Promise<StoredSessions>;
|
|
108
|
+
createSession(_credential: Credential, _workspaceId: string): Promise<Session>;
|
|
109
|
+
selectSession(_workspaceId: string): Promise<Session>;
|
|
110
|
+
endSession(_workspaceId: string): Promise<void>;
|
|
111
|
+
endAllSessions(): Promise<void>;
|
|
112
|
+
activeCredentialStorage(): Promise<TokenStorage>;
|
|
113
|
+
/** The spawn path's read: the env token passes through directly. It
|
|
114
|
+
* is already a snapshot with no refresh token behind it. */
|
|
115
|
+
activeAccessToken(): Promise<string | null>;
|
|
116
|
+
}
|
|
117
|
+
//#endregion
|
|
118
|
+
//#region src/token-claims.d.ts
|
|
119
|
+
/** The `workspace_id` claim, which is what sessions are keyed by. */
|
|
120
|
+
declare function claimedWorkspaceId(token: string): string | undefined;
|
|
121
|
+
/** The workspace a credential names: its `workspace_id` claim, or the
|
|
122
|
+
* workspace its subject names when it is a service token. */
|
|
123
|
+
declare function credentialWorkspaceId(token: string): string | undefined;
|
|
124
|
+
declare function claimedExpiresAt(token: string): Date | undefined;
|
|
125
|
+
/**
|
|
126
|
+
* Who a credential belongs to, from its own claims. A service token's
|
|
127
|
+
* subject names a workspace rather than a person, so it yields no user
|
|
128
|
+
* — reporting `workspace:ws_1` as a user id was a real defect.
|
|
129
|
+
*/
|
|
130
|
+
declare function claimedIdentity(token: string): CredentialIdentity | undefined;
|
|
131
|
+
//#endregion
|
|
132
|
+
export { type ActiveCredential, type AnyCommand, type Args, type ArgsSpec, type Block, type BrowserWaitRequest, type Char, type ChildResult, type ChildStatusSettlement, type Cli, type CliRunHooks, type CommandArgs, type CommandContext, type CommandDefinition, type CommandFamily, type CommandHandler, type CommandHelp, type CommandNeeds, type CompletedEnvelope, type ConfigSection, type Credential, type CredentialIdentity, type CredentialManager, type CredentialOrigin, type CredentialsRequiredReason, type EngineCommandSnapshot, type EngineEvent, EnvironmentCredentialManager, type ErroredEnvelope, type ExitWithChildStatusOptions, type FlagSpec, type Format, type Handler, type HelpSpec, type HostProcess, type InputStream, type LoadedConfig, type ManagementApiClient, type ManagementApiClientConfig, type MountedTree, type NeedsSpec, type OpenUrlOutcome, type OpenUrlRequest, type Outcome, type OutputStream, PRESENTED, PRISMA_CONFIG_VERSION, type PositionalSpec, type Presentations, type PresentedResult, type PromptSurface, type RunSummary, type Runtime, type SectionValidation, type ServerCommandDefinition, type Session, type SessionCommandDefinition, type Severity, type SpawnChild, type SpawnDeclarations, type SpawnOptions, type SpawnRequest, type SpawnedChild, type StoredSessions, type StreamEvent, type StreamMeta, type TokenStorage, type TreeNode, type Ui, authServiceError, claimedExpiresAt, claimedIdentity, claimedWorkspaceId, createCli, credentialRejectedError, credentialWorkspaceId, credentialWorkspaceMismatchError, credentialsRequiredError, defineCommand, defineCommandFamily, defineConfig, defineConfigSection, defineServerCommand, defineSessionCommand, emptyServiceTokenError, exitWithChildStatus, flag, loadConfig, noSessionForWorkspaceError, positional };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as buildEngine, c as credentialWorkspaceMismatchError, d as noSessionForWorkspaceError, f as PRESENTED, h as positional, i as credentialWorkspaceId, l as credentialsRequiredError, m as flag, n as claimedIdentity, o as authServiceError, p as exitWithChildStatus, r as claimedWorkspaceId, s as credentialRejectedError, t as claimedExpiresAt, u as emptyServiceTokenError } from "./token-claims-DXO0q52l.js";
|
|
2
|
+
import { t as CliStructuredError } from "./protocol-C1JQcGl9.js";
|
|
2
3
|
import { join } from "node:path";
|
|
3
4
|
import { existsSync } from "node:fs";
|
|
4
5
|
import { pathToFileURL } from "node:url";
|
|
@@ -40,7 +41,7 @@ function normalizeArgs(spec) {
|
|
|
40
41
|
function normalizeNeeds(spec) {
|
|
41
42
|
return Object.freeze({
|
|
42
43
|
config: spec?.config,
|
|
43
|
-
credentials: spec?.credentials
|
|
44
|
+
credentials: spec?.credentials ?? false,
|
|
44
45
|
dependencies: spec?.dependencies ?? [],
|
|
45
46
|
interaction: spec?.interaction === true
|
|
46
47
|
});
|
|
@@ -52,6 +53,8 @@ function defineCommand(def) {
|
|
|
52
53
|
args: normalizeArgs(def.args),
|
|
53
54
|
needs: normalizeNeeds(def.needs),
|
|
54
55
|
exitCodes: def.exitCodes ?? {},
|
|
56
|
+
managesCredentials: def.managesCredentials ?? false,
|
|
57
|
+
maySpawn: def.maySpawn ?? false,
|
|
55
58
|
handler: def.handler
|
|
56
59
|
});
|
|
57
60
|
}
|
|
@@ -61,6 +64,7 @@ function defineSessionCommand(def) {
|
|
|
61
64
|
help: normalizeHelp(def.help),
|
|
62
65
|
args: normalizeArgs(def.args),
|
|
63
66
|
needs: normalizeNeeds(def.needs),
|
|
67
|
+
maySpawn: def.maySpawn ?? false,
|
|
64
68
|
handler: def.handler
|
|
65
69
|
});
|
|
66
70
|
}
|
|
@@ -70,6 +74,7 @@ function defineServerCommand(def) {
|
|
|
70
74
|
help: normalizeHelp(def.help),
|
|
71
75
|
args: normalizeArgs(def.args),
|
|
72
76
|
needs: normalizeNeeds(def.needs),
|
|
77
|
+
maySpawn: false,
|
|
73
78
|
handler: def.handler
|
|
74
79
|
});
|
|
75
80
|
}
|
|
@@ -197,4 +202,117 @@ function defineConfigSection(spec) {
|
|
|
197
202
|
});
|
|
198
203
|
}
|
|
199
204
|
//#endregion
|
|
200
|
-
|
|
205
|
+
//#region src/environment-credential-manager.ts
|
|
206
|
+
/**
|
|
207
|
+
* The production, environment-only CredentialManager (S3, R-S3-1): for
|
|
208
|
+
* hosts whose sole credential source is the inter-process protocol —
|
|
209
|
+
* PRISMA_SERVICE_TOKEN plus PRISMA_WORKSPACE_ID — such as composer's
|
|
210
|
+
* rebuilt CLI. It holds no stored sessions and cannot: every mutation
|
|
211
|
+
* refuses with a structured error. Env is a construction input; nothing
|
|
212
|
+
* here reads process.env.
|
|
213
|
+
*/
|
|
214
|
+
const SERVICE_TOKEN_ENV_VAR = "PRISMA_SERVICE_TOKEN";
|
|
215
|
+
const WORKSPACE_ID_ENV_VAR = "PRISMA_WORKSPACE_ID";
|
|
216
|
+
/** The SDK's Tokens requires a workspace id; an environment credential
|
|
217
|
+
* that names none is given this instead. It never leaves the manager
|
|
218
|
+
* and is never the empty string. */
|
|
219
|
+
const NO_WORKSPACE_NAMED = "(no workspace)";
|
|
220
|
+
function sessionsUnsupportedError() {
|
|
221
|
+
return new CliStructuredError("AUTH.SESSIONS_UNSUPPORTED", "This host manages no stored workspace sessions.", {
|
|
222
|
+
why: `Its credentials come only from ${SERVICE_TOKEN_ENV_VAR} (and ${WORKSPACE_ID_ENV_VAR}); there is nothing to create, select, or end.`,
|
|
223
|
+
nextActions: [{
|
|
224
|
+
kind: "user-choice",
|
|
225
|
+
label: `Set or change ${SERVICE_TOKEN_ENV_VAR} in the environment instead.`
|
|
226
|
+
}]
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
var EnvironmentCredentialManager = class {
|
|
230
|
+
#env;
|
|
231
|
+
#refreshLock = Promise.resolve();
|
|
232
|
+
#activeStorage;
|
|
233
|
+
constructor(spec) {
|
|
234
|
+
this.#env = spec.env;
|
|
235
|
+
}
|
|
236
|
+
async activeCredential() {
|
|
237
|
+
const token = this.#token();
|
|
238
|
+
if (token === void 0) return null;
|
|
239
|
+
return {
|
|
240
|
+
workspaceId: this.#workspaceId(token),
|
|
241
|
+
workspaceName: void 0,
|
|
242
|
+
expiresAt: claimedExpiresAt(token),
|
|
243
|
+
identity: claimedIdentity(token),
|
|
244
|
+
origin: { source: "environment" }
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
async sessions() {
|
|
248
|
+
return {
|
|
249
|
+
sessions: [],
|
|
250
|
+
selectedWorkspaceId: void 0
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
async createSession(_credential, _workspaceId) {
|
|
254
|
+
throw sessionsUnsupportedError();
|
|
255
|
+
}
|
|
256
|
+
async selectSession(_workspaceId) {
|
|
257
|
+
throw sessionsUnsupportedError();
|
|
258
|
+
}
|
|
259
|
+
async endSession(_workspaceId) {
|
|
260
|
+
throw sessionsUnsupportedError();
|
|
261
|
+
}
|
|
262
|
+
async endAllSessions() {
|
|
263
|
+
throw sessionsUnsupportedError();
|
|
264
|
+
}
|
|
265
|
+
async activeCredentialStorage() {
|
|
266
|
+
this.#activeStorage ??= this.#buildActiveStorage();
|
|
267
|
+
return this.#activeStorage;
|
|
268
|
+
}
|
|
269
|
+
/** The spawn path's read: the env token passes through directly. It
|
|
270
|
+
* is already a snapshot with no refresh token behind it. */
|
|
271
|
+
async activeAccessToken() {
|
|
272
|
+
return this.#token() ?? null;
|
|
273
|
+
}
|
|
274
|
+
#buildActiveStorage() {
|
|
275
|
+
const token = this.#token();
|
|
276
|
+
if (token === void 0) throw new Error("@prisma/cli-engine: activeCredentialStorage() is only valid once activeCredential() has returned non-null");
|
|
277
|
+
let tokens = {
|
|
278
|
+
workspaceId: this.#workspaceId(token) ?? NO_WORKSPACE_NAMED,
|
|
279
|
+
accessToken: token,
|
|
280
|
+
refreshToken: void 0
|
|
281
|
+
};
|
|
282
|
+
const singleFlight = (fn) => {
|
|
283
|
+
const queued = this.#refreshLock.then(fn, fn);
|
|
284
|
+
this.#refreshLock = queued.then(() => void 0, () => void 0);
|
|
285
|
+
return queued;
|
|
286
|
+
};
|
|
287
|
+
return {
|
|
288
|
+
getTokens: async () => tokens,
|
|
289
|
+
setTokens: async (rotated) => {
|
|
290
|
+
tokens = rotated;
|
|
291
|
+
},
|
|
292
|
+
clearTokens: async () => {
|
|
293
|
+
tokens = null;
|
|
294
|
+
},
|
|
295
|
+
withRefreshLock: (fn) => singleFlight(fn)
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
/** The raw variable, resolved fresh on every read. Unset or missing
|
|
299
|
+
* means no credential; set-but-blank is the structured error state
|
|
300
|
+
* (a blank token authenticates nothing and would silently shadow
|
|
301
|
+
* nothing here — surface it). */
|
|
302
|
+
#token() {
|
|
303
|
+
const raw = this.#env[SERVICE_TOKEN_ENV_VAR];
|
|
304
|
+
if (raw === void 0) return;
|
|
305
|
+
if (raw.trim() === "") throw emptyServiceTokenError({ envVar: SERVICE_TOKEN_ENV_VAR });
|
|
306
|
+
return raw;
|
|
307
|
+
}
|
|
308
|
+
/** The credential's workspace: its own claims first (the token is
|
|
309
|
+
* authoritative about itself), the companion variable otherwise. */
|
|
310
|
+
#workspaceId(token) {
|
|
311
|
+
const claimed = credentialWorkspaceId(token);
|
|
312
|
+
if (claimed !== void 0) return claimed;
|
|
313
|
+
const fromEnv = this.#env[WORKSPACE_ID_ENV_VAR]?.trim();
|
|
314
|
+
return fromEnv === void 0 || fromEnv === "" ? void 0 : fromEnv;
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
//#endregion
|
|
318
|
+
export { EnvironmentCredentialManager, PRESENTED, PRISMA_CONFIG_VERSION, authServiceError, claimedExpiresAt, claimedIdentity, claimedWorkspaceId, createCli, credentialRejectedError, credentialWorkspaceId, credentialWorkspaceMismatchError, credentialsRequiredError, defineCommand, defineCommandFamily, defineConfig, defineConfigSection, defineServerCommand, defineSessionCommand, emptyServiceTokenError, exitWithChildStatus, flag, loadConfig, noSessionForWorkspaceError, positional };
|
|
@@ -27,10 +27,14 @@ interface Diagnostic {
|
|
|
27
27
|
* The typed agent-facing follow-up action.
|
|
28
28
|
*/
|
|
29
29
|
interface NextAction {
|
|
30
|
-
readonly kind: "run-command" | "user-choice" | "edit-file" | "done";
|
|
30
|
+
readonly kind: "run-command" | "open-url" | "user-choice" | "edit-file" | "done";
|
|
31
31
|
readonly label: string;
|
|
32
32
|
readonly command?: string;
|
|
33
33
|
readonly commands?: readonly string[];
|
|
34
|
+
/** The address an `open-url` action sends the user to. A URL is not
|
|
35
|
+
* a command: putting one in `command` tells a consumer to execute
|
|
36
|
+
* it. */
|
|
37
|
+
readonly url?: string;
|
|
34
38
|
readonly reason?: string;
|
|
35
39
|
}
|
|
36
40
|
/**
|
package/dist/protocol.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as NotOk, c as notOk, i as NextAction, l as ok, n as CliStructuredError, o as Ok, r as Diagnostic, s as Result, t as CliErrorEnvelope, u as okVoid } from "./protocol-
|
|
1
|
+
import { a as NotOk, c as notOk, i as NextAction, l as ok, n as CliStructuredError, o as Ok, r as Diagnostic, s as Result, t as CliErrorEnvelope, u as okVoid } from "./protocol-CpZLdxML.js";
|
|
2
2
|
export { type CliErrorEnvelope, CliStructuredError, type Diagnostic, type NextAction, type NotOk, type Ok, type Result, notOk, ok, okVoid };
|