@prisma/cli-engine 0.0.2 → 0.0.5
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 +57 -19
- package/dist/index.js +118 -121
- package/dist/{run-summary-CZITSYO_.d.ts → run-summary-CLpl1gmC.d.ts} +186 -15
- package/dist/testing.d.ts +42 -3
- package/dist/testing.js +92 -48
- package/dist/{engine-vF4FiZqo.js → token-claims-Bpb1vA2N.js} +1253 -380
- package/package.json +3 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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 FlagSpec, a as defineCommandFamily, at as Session, b as defineServerCommand, bt as positional, c as CommandHandler, ct as ManagementApiClientConfig, d as CompletedEnvelope, dt as SectionValidation, et as Credential, f as ErroredEnvelope, ft as defineConfigSection, g as ServerCommandDefinition, gt as CommandArgs, h as NeedsSpec, ht as Char, i as MountedTree, it as SERVICE_TOKEN_ENV_VAR, j as OpenUrlRequest, k as CommandContext, l as CommandHelp, lt as TokenStorage, m as HelpSpec, mt as ArgsSpec, n as RunSummary, nt as CredentialManager, o as AnyCommand, ot as StoredSessions, p as Handler, pt as Args, q as TreeNode, r as CommandFamily, rt as CredentialOrigin, s as CommandDefinition, st as ManagementApiClient, t as EngineCommandSnapshot, tt as CredentialIdentity, u as CommandNeeds, ut as ConfigSection, v as SpawnDeclarations, vt as PositionalSpec, w as LoadedConfig, x as defineSessionCommand, y as defineCommand, yt as flag, z as SpawnedChild } from "./run-summary-CLpl1gmC.js";
|
|
2
2
|
import { n as CliStructuredError } from "./protocol-CpZLdxML.js";
|
|
3
3
|
|
|
4
4
|
//#region src/cli.d.ts
|
|
@@ -41,26 +41,27 @@ declare function createCli(spec: {
|
|
|
41
41
|
//#endregion
|
|
42
42
|
//#region src/config-loader.d.ts
|
|
43
43
|
/**
|
|
44
|
-
* Attaches the version marker to a prisma.config.ts export.
|
|
45
|
-
*
|
|
46
|
-
* the
|
|
44
|
+
* Attaches the version marker to a prisma.config.ts export. Each
|
|
45
|
+
* top-level key names a config section, and the recognised section
|
|
46
|
+
* names are exactly the ones the CLI's command families declare. Never
|
|
47
|
+
* throws — bad section values are the section validator's problem, not
|
|
48
|
+
* defineConfig's.
|
|
47
49
|
*/
|
|
48
50
|
declare function defineConfig<T extends Record<string, unknown>>(config: T): T & {
|
|
49
51
|
readonly $prismaConfig: number;
|
|
50
52
|
};
|
|
51
53
|
/**
|
|
52
|
-
* The real-disk loader behind Runtime.
|
|
53
|
-
*
|
|
54
|
-
* bin builds Runtime.config with this; tests hand in fixtures.
|
|
54
|
+
* The real-disk loader behind Runtime.loadConfig. The bin binds it to
|
|
55
|
+
* the process cwd; tests hand in fixtures.
|
|
55
56
|
*/
|
|
56
|
-
declare function loadConfig(cwd: string): Promise<LoadedConfig>;
|
|
57
|
+
declare function loadConfig(cwd: string, configPath?: string): Promise<LoadedConfig>;
|
|
57
58
|
//#endregion
|
|
58
59
|
//#region src/credential-errors.d.ts
|
|
59
|
-
type CredentialsRequiredReason = "unauthenticated" | "expired" | "session-ended" | "sessions-held-none-selected";
|
|
60
|
+
type CredentialsRequiredReason = "unauthenticated" | "expired" | "expiring-soon" | "session-ended" | "sessions-held-none-selected";
|
|
60
61
|
/**
|
|
61
62
|
* The single constructor of CLI.CREDENTIALS_REQUIRED. Raised
|
|
62
|
-
* identically by the needs check, ctx.
|
|
63
|
-
* request path.
|
|
63
|
+
* identically by the needs check, ctx.activeCredential, and the
|
|
64
|
+
* engine's request path.
|
|
64
65
|
*/
|
|
65
66
|
declare function credentialsRequiredError(reason?: CredentialsRequiredReason): CliStructuredError;
|
|
66
67
|
/**
|
|
@@ -75,10 +76,17 @@ declare function authServiceError(): CliStructuredError;
|
|
|
75
76
|
* nothing else compares against `origin.source`.
|
|
76
77
|
*/
|
|
77
78
|
declare function credentialRejectedError(origin: CredentialOrigin, envVar: string): CliStructuredError;
|
|
79
|
+
/**
|
|
80
|
+
* A credential's workspace_id claim disagrees with the workspace it is
|
|
81
|
+
* being stored under, or a rotated token would re-scope a session.
|
|
82
|
+
* Raised by every CredentialManager, so a test sees what production
|
|
83
|
+
* raises.
|
|
84
|
+
*/
|
|
85
|
+
declare function credentialWorkspaceMismatchError(workspaceId: string): CliStructuredError;
|
|
78
86
|
/**
|
|
79
87
|
* The env var that supplies a session is set to a blank value. The one
|
|
80
|
-
* structured error for it, raised identically by
|
|
81
|
-
* needs check, and the engine's request path.
|
|
88
|
+
* structured error for it, raised identically by activeCredential(),
|
|
89
|
+
* the needs check, and the engine's request path.
|
|
82
90
|
*/
|
|
83
91
|
declare function emptyServiceTokenError(spec: {
|
|
84
92
|
readonly envVar: string;
|
|
@@ -89,12 +97,42 @@ declare function emptyServiceTokenError(spec: {
|
|
|
89
97
|
* you have.
|
|
90
98
|
*/
|
|
91
99
|
declare function noSessionForWorkspaceError(workspaceRef: string): CliStructuredError;
|
|
100
|
+
//#endregion
|
|
101
|
+
//#region src/environment-credential-manager.d.ts
|
|
102
|
+
declare class EnvironmentCredentialManager implements CredentialManager {
|
|
103
|
+
#private;
|
|
104
|
+
constructor(spec: {
|
|
105
|
+
readonly env: Readonly<Record<string, string | undefined>>;
|
|
106
|
+
});
|
|
107
|
+
activeCredential(): Promise<ActiveCredential | null>;
|
|
108
|
+
sessions(): Promise<StoredSessions>;
|
|
109
|
+
createSession(_credential: Credential, _workspaceId: string): Promise<Session>;
|
|
110
|
+
selectSession(_workspaceId: string): Promise<Session>;
|
|
111
|
+
endSession(_workspaceId: string): Promise<void>;
|
|
112
|
+
endAllSessions(): Promise<void>;
|
|
113
|
+
activeCredentialStorage(): Promise<TokenStorage>;
|
|
114
|
+
/** The spawn path's read: the env token passes through directly. It
|
|
115
|
+
* is already a snapshot with no refresh token behind it. */
|
|
116
|
+
activeAccessToken(): Promise<string | null>;
|
|
117
|
+
}
|
|
118
|
+
//#endregion
|
|
119
|
+
//#region src/token-claims.d.ts
|
|
92
120
|
/**
|
|
93
|
-
* The
|
|
94
|
-
*
|
|
121
|
+
* The workspace a credential names. One derivation, because a token
|
|
122
|
+
* says it one of two ways and every caller wants the same answer: an
|
|
123
|
+
* OAuth token carries `workspace_id`, while a service token names its
|
|
124
|
+
* workspace through `sub` and carries no `workspace_id` at all. Reading
|
|
125
|
+
* only the claim was a second path that happened to work because
|
|
126
|
+
* service tokens reached it by a different route — a split nothing
|
|
127
|
+
* enforced.
|
|
95
128
|
*/
|
|
96
|
-
declare function
|
|
97
|
-
|
|
98
|
-
|
|
129
|
+
declare function credentialWorkspaceId(token: string): string | undefined;
|
|
130
|
+
declare function claimedExpiresAt(token: string): Date | undefined;
|
|
131
|
+
/**
|
|
132
|
+
* Who a credential belongs to, from its own claims. A service token's
|
|
133
|
+
* subject names a workspace rather than a person, so it yields no user
|
|
134
|
+
* — reporting `workspace:ws_1` as a user id was a real defect.
|
|
135
|
+
*/
|
|
136
|
+
declare function claimedIdentity(token: string): CredentialIdentity | undefined;
|
|
99
137
|
//#endregion
|
|
100
|
-
export { type ActiveCredential, type AnyCommand, type Args, type ArgsSpec, type Block, type BrowserWaitRequest, type Char, 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, type ErroredEnvelope, 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 StoredSessions, type StreamEvent, type StreamMeta, type TokenStorage, type TreeNode, type Ui, authServiceError, createCli, credentialRejectedError, credentialsRequiredError, defineCommand, defineCommandFamily, defineConfig, defineConfigSection, defineServerCommand, defineSessionCommand, emptyServiceTokenError, flag, loadConfig, noSessionForWorkspaceError, positional
|
|
138
|
+
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, SERVICE_TOKEN_ENV_VAR, 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, createCli, credentialRejectedError, credentialWorkspaceId, credentialWorkspaceMismatchError, credentialsRequiredError, defineCommand, defineCommandFamily, defineConfig, defineConfigSection, defineServerCommand, defineSessionCommand, emptyServiceTokenError, exitWithChildStatus, flag, loadConfig, noSessionForWorkspaceError, positional };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { existsSync } from "node:fs";
|
|
4
|
-
import { pathToFileURL } from "node:url";
|
|
1
|
+
import { _ as PRESENTED, b as positional, c as PRISMA_CONFIG_VERSION, d as authServiceError, f as credentialRejectedError, g as noSessionForWorkspaceError, h as emptyServiceTokenError, i as buildEngine, l as SERVICE_TOKEN_ENV_VAR, m as credentialsRequiredError, n as claimedIdentity, o as defineConfig, p as credentialWorkspaceMismatchError, r as credentialWorkspaceId, s as loadConfig, t as claimedExpiresAt, u as WORKSPACE_ID_ENV_VAR, v as exitWithChildStatus, y as flag } from "./token-claims-Bpb1vA2N.js";
|
|
2
|
+
import { t as CliStructuredError } from "./protocol-C1JQcGl9.js";
|
|
5
3
|
//#region src/cli.ts
|
|
6
4
|
/**
|
|
7
5
|
* Shell-side construction. Group help is declared with the mount.
|
|
@@ -40,7 +38,7 @@ function normalizeArgs(spec) {
|
|
|
40
38
|
function normalizeNeeds(spec) {
|
|
41
39
|
return Object.freeze({
|
|
42
40
|
config: spec?.config,
|
|
43
|
-
credentials: spec?.credentials
|
|
41
|
+
credentials: spec?.credentials ?? false,
|
|
44
42
|
dependencies: spec?.dependencies ?? [],
|
|
45
43
|
interaction: spec?.interaction === true
|
|
46
44
|
});
|
|
@@ -53,6 +51,7 @@ function defineCommand(def) {
|
|
|
53
51
|
needs: normalizeNeeds(def.needs),
|
|
54
52
|
exitCodes: def.exitCodes ?? {},
|
|
55
53
|
managesCredentials: def.managesCredentials ?? false,
|
|
54
|
+
maySpawn: def.maySpawn ?? false,
|
|
56
55
|
handler: def.handler
|
|
57
56
|
});
|
|
58
57
|
}
|
|
@@ -62,6 +61,7 @@ function defineSessionCommand(def) {
|
|
|
62
61
|
help: normalizeHelp(def.help),
|
|
63
62
|
args: normalizeArgs(def.args),
|
|
64
63
|
needs: normalizeNeeds(def.needs),
|
|
64
|
+
maySpawn: def.maySpawn ?? false,
|
|
65
65
|
handler: def.handler
|
|
66
66
|
});
|
|
67
67
|
}
|
|
@@ -71,125 +71,11 @@ function defineServerCommand(def) {
|
|
|
71
71
|
help: normalizeHelp(def.help),
|
|
72
72
|
args: normalizeArgs(def.args),
|
|
73
73
|
needs: normalizeNeeds(def.needs),
|
|
74
|
+
maySpawn: false,
|
|
74
75
|
handler: def.handler
|
|
75
76
|
});
|
|
76
77
|
}
|
|
77
78
|
//#endregion
|
|
78
|
-
//#region src/runtime.ts
|
|
79
|
-
/**
|
|
80
|
-
* The config contract version defineConfig writes as the structural
|
|
81
|
-
* `$prismaConfig` marker; the loader checks it before interpreting
|
|
82
|
-
* anything.
|
|
83
|
-
*/
|
|
84
|
-
const PRISMA_CONFIG_VERSION = 1;
|
|
85
|
-
//#endregion
|
|
86
|
-
//#region src/config-loader.ts
|
|
87
|
-
/**
|
|
88
|
-
* The minimal prisma.config.ts loader behind Runtime.config:
|
|
89
|
-
* discover the file in cwd (cwd only — no walking up), evaluate it,
|
|
90
|
-
* check the defineConfig version marker, and produce LoadedConfig.
|
|
91
|
-
*
|
|
92
|
-
* Absence is not an error: section validators own absence, so a missing
|
|
93
|
-
* file is an empty LoadedConfig. An evaluated file WITHOUT the marker (a
|
|
94
|
-
* classic Prisma 7 config, which uses the same filename) fails early
|
|
95
|
-
* with one typed diagnostic — the loader never partially interprets an
|
|
96
|
-
* unmarked file, and never guesses.
|
|
97
|
-
*/
|
|
98
|
-
const CONFIG_FILE_NAME = "prisma.config.ts";
|
|
99
|
-
const MARKER_KEY = "$prismaConfig";
|
|
100
|
-
/**
|
|
101
|
-
* Attaches the version marker to a prisma.config.ts export. Top-level
|
|
102
|
-
* keys are the config sections. Never throws — bad section values are
|
|
103
|
-
* the section validator's problem, not defineConfig's.
|
|
104
|
-
*/
|
|
105
|
-
function defineConfig(config) {
|
|
106
|
-
return Object.freeze({
|
|
107
|
-
...config,
|
|
108
|
-
$prismaConfig: 1
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
function hasVersionMarker(value) {
|
|
112
|
-
return typeof value === "object" && value !== null && typeof value[MARKER_KEY] === "number";
|
|
113
|
-
}
|
|
114
|
-
function fileLevelConfig(diagnostic) {
|
|
115
|
-
return {
|
|
116
|
-
sections: {},
|
|
117
|
-
diagnostics: [{
|
|
118
|
-
section: null,
|
|
119
|
-
diagnostic
|
|
120
|
-
}]
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
function missingMarkerDiagnostic(path) {
|
|
124
|
-
return {
|
|
125
|
-
code: "CLI.CONFIG_MISSING_MARKER",
|
|
126
|
-
severity: "error",
|
|
127
|
-
summary: "This prisma.config.ts was not written for this version of the Prisma CLI, so it cannot be used.",
|
|
128
|
-
why: "Configs for this CLI are created with defineConfig, which records a version marker on the exported object. This file's default export has no marker — it is most likely a Prisma 7 config, which uses the same filename — and the CLI stops rather than misread it.",
|
|
129
|
-
nextActions: [{
|
|
130
|
-
kind: "user-choice",
|
|
131
|
-
label: "Migrate the file: wrap the exported object in defineConfig from @prisma/cli-engine and export the result as the default export."
|
|
132
|
-
}],
|
|
133
|
-
where: { path }
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
function firstLine(text) {
|
|
137
|
-
const newline = text.indexOf("\n");
|
|
138
|
-
return (newline === -1 ? text : text.slice(0, newline)).trim();
|
|
139
|
-
}
|
|
140
|
-
function unsupportedVersionDiagnostic(path, found) {
|
|
141
|
-
return {
|
|
142
|
-
code: "CLI.CONFIG_INVALID",
|
|
143
|
-
severity: "error",
|
|
144
|
-
summary: `prisma.config.ts declares config version ${found}, but this CLI supports only version 1.`,
|
|
145
|
-
nextActions: [{
|
|
146
|
-
kind: "user-choice",
|
|
147
|
-
label: "Regenerate the config with a defineConfig matching this CLI, or update the CLI to a version that supports the declared config version."
|
|
148
|
-
}],
|
|
149
|
-
where: { path }
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
function unreadableDiagnostic(path, cause) {
|
|
153
|
-
return {
|
|
154
|
-
code: "CLI.CONFIG_UNREADABLE",
|
|
155
|
-
severity: "error",
|
|
156
|
-
summary: `prisma.config.ts could not be evaluated: ${firstLine(cause instanceof Error ? cause.message : String(cause))}`,
|
|
157
|
-
nextActions: [{
|
|
158
|
-
kind: "user-choice",
|
|
159
|
-
label: "Fix the error in the file, then run the command again."
|
|
160
|
-
}],
|
|
161
|
-
where: { path }
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* The real-disk loader behind Runtime.config: reads prisma.config.ts
|
|
166
|
-
* from cwd (cwd only — no walking up) and produces LoadedConfig. The
|
|
167
|
-
* bin builds Runtime.config with this; tests hand in fixtures.
|
|
168
|
-
*/
|
|
169
|
-
async function loadConfig(cwd) {
|
|
170
|
-
const path = join(cwd, CONFIG_FILE_NAME);
|
|
171
|
-
if (!existsSync(path)) return {
|
|
172
|
-
sections: {},
|
|
173
|
-
diagnostics: []
|
|
174
|
-
};
|
|
175
|
-
let loaded;
|
|
176
|
-
try {
|
|
177
|
-
loaded = await import(pathToFileURL(path).href);
|
|
178
|
-
} catch (cause) {
|
|
179
|
-
return fileLevelConfig(unreadableDiagnostic(path, cause));
|
|
180
|
-
}
|
|
181
|
-
const exported = loaded.default;
|
|
182
|
-
if (!hasVersionMarker(exported)) return fileLevelConfig(missingMarkerDiagnostic(path));
|
|
183
|
-
const version = exported[MARKER_KEY];
|
|
184
|
-
if (version !== 1) return fileLevelConfig(unsupportedVersionDiagnostic(path, version));
|
|
185
|
-
const sections = {};
|
|
186
|
-
for (const [key, value] of Object.entries(exported)) if (key !== MARKER_KEY) sections[key] = value;
|
|
187
|
-
return {
|
|
188
|
-
sections,
|
|
189
|
-
diagnostics: []
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
//#endregion
|
|
193
79
|
//#region src/config-section.ts
|
|
194
80
|
function defineConfigSection(spec) {
|
|
195
81
|
return Object.freeze({
|
|
@@ -198,4 +84,115 @@ function defineConfigSection(spec) {
|
|
|
198
84
|
});
|
|
199
85
|
}
|
|
200
86
|
//#endregion
|
|
201
|
-
|
|
87
|
+
//#region src/environment-credential-manager.ts
|
|
88
|
+
/**
|
|
89
|
+
* The production, environment-only CredentialManager (S3, R-S3-1): for
|
|
90
|
+
* hosts whose sole credential source is the inter-process protocol —
|
|
91
|
+
* PRISMA_SERVICE_TOKEN plus PRISMA_WORKSPACE_ID — such as composer's
|
|
92
|
+
* rebuilt CLI. It holds no stored sessions and cannot: every mutation
|
|
93
|
+
* refuses with a structured error. Env is a construction input; nothing
|
|
94
|
+
* here reads process.env.
|
|
95
|
+
*/
|
|
96
|
+
/** The SDK's Tokens requires a workspace id; an environment credential
|
|
97
|
+
* that names none is given this instead. It never leaves the manager
|
|
98
|
+
* and is never the empty string. */
|
|
99
|
+
const NO_WORKSPACE_NAMED = "(no workspace)";
|
|
100
|
+
function sessionsUnsupportedError() {
|
|
101
|
+
return new CliStructuredError("AUTH.SESSIONS_UNSUPPORTED", "This host manages no stored workspace sessions.", {
|
|
102
|
+
why: `Its credentials come only from ${SERVICE_TOKEN_ENV_VAR} (and ${WORKSPACE_ID_ENV_VAR}); there is nothing to create, select, or end.`,
|
|
103
|
+
nextActions: [{
|
|
104
|
+
kind: "user-choice",
|
|
105
|
+
label: `Set or change ${SERVICE_TOKEN_ENV_VAR} in the environment instead.`
|
|
106
|
+
}]
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
var EnvironmentCredentialManager = class {
|
|
110
|
+
#env;
|
|
111
|
+
#refreshLock = Promise.resolve();
|
|
112
|
+
#activeStorage;
|
|
113
|
+
constructor(spec) {
|
|
114
|
+
this.#env = spec.env;
|
|
115
|
+
}
|
|
116
|
+
async activeCredential() {
|
|
117
|
+
const token = this.#token();
|
|
118
|
+
if (token === void 0) return null;
|
|
119
|
+
return {
|
|
120
|
+
workspaceId: this.#workspaceId(token),
|
|
121
|
+
workspaceName: void 0,
|
|
122
|
+
expiresAt: claimedExpiresAt(token),
|
|
123
|
+
identity: claimedIdentity(token),
|
|
124
|
+
origin: { source: "environment" }
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
async sessions() {
|
|
128
|
+
return {
|
|
129
|
+
sessions: [],
|
|
130
|
+
selectedWorkspaceId: void 0
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
async createSession(_credential, _workspaceId) {
|
|
134
|
+
throw sessionsUnsupportedError();
|
|
135
|
+
}
|
|
136
|
+
async selectSession(_workspaceId) {
|
|
137
|
+
throw sessionsUnsupportedError();
|
|
138
|
+
}
|
|
139
|
+
async endSession(_workspaceId) {
|
|
140
|
+
throw sessionsUnsupportedError();
|
|
141
|
+
}
|
|
142
|
+
async endAllSessions() {
|
|
143
|
+
throw sessionsUnsupportedError();
|
|
144
|
+
}
|
|
145
|
+
async activeCredentialStorage() {
|
|
146
|
+
this.#activeStorage ??= this.#buildActiveStorage();
|
|
147
|
+
return this.#activeStorage;
|
|
148
|
+
}
|
|
149
|
+
/** The spawn path's read: the env token passes through directly. It
|
|
150
|
+
* is already a snapshot with no refresh token behind it. */
|
|
151
|
+
async activeAccessToken() {
|
|
152
|
+
return this.#token() ?? null;
|
|
153
|
+
}
|
|
154
|
+
#buildActiveStorage() {
|
|
155
|
+
const token = this.#token();
|
|
156
|
+
if (token === void 0) throw new Error("@prisma/cli-engine: activeCredentialStorage() is only valid once activeCredential() has returned non-null");
|
|
157
|
+
let tokens = {
|
|
158
|
+
workspaceId: this.#workspaceId(token) ?? NO_WORKSPACE_NAMED,
|
|
159
|
+
accessToken: token,
|
|
160
|
+
refreshToken: void 0
|
|
161
|
+
};
|
|
162
|
+
const singleFlight = (fn) => {
|
|
163
|
+
const queued = this.#refreshLock.then(fn, fn);
|
|
164
|
+
this.#refreshLock = queued.then(() => void 0, () => void 0);
|
|
165
|
+
return queued;
|
|
166
|
+
};
|
|
167
|
+
return {
|
|
168
|
+
getTokens: async () => tokens,
|
|
169
|
+
setTokens: async (rotated) => {
|
|
170
|
+
tokens = rotated;
|
|
171
|
+
},
|
|
172
|
+
clearTokens: async () => {
|
|
173
|
+
tokens = null;
|
|
174
|
+
},
|
|
175
|
+
withRefreshLock: (fn) => singleFlight(fn)
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
/** The raw variable, resolved fresh on every read. Unset or missing
|
|
179
|
+
* means no credential; set-but-blank is the structured error state
|
|
180
|
+
* (a blank token authenticates nothing and would silently shadow
|
|
181
|
+
* nothing here — surface it). */
|
|
182
|
+
#token() {
|
|
183
|
+
const raw = this.#env[SERVICE_TOKEN_ENV_VAR];
|
|
184
|
+
if (raw === void 0) return;
|
|
185
|
+
if (raw.trim() === "") throw emptyServiceTokenError({ envVar: SERVICE_TOKEN_ENV_VAR });
|
|
186
|
+
return raw;
|
|
187
|
+
}
|
|
188
|
+
/** The credential's workspace: its own claims first (the token is
|
|
189
|
+
* authoritative about itself), the companion variable otherwise. */
|
|
190
|
+
#workspaceId(token) {
|
|
191
|
+
const claimed = credentialWorkspaceId(token);
|
|
192
|
+
if (claimed !== void 0) return claimed;
|
|
193
|
+
const fromEnv = this.#env[WORKSPACE_ID_ENV_VAR]?.trim();
|
|
194
|
+
return fromEnv === void 0 || fromEnv === "" ? void 0 : fromEnv;
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
//#endregion
|
|
198
|
+
export { EnvironmentCredentialManager, PRESENTED, PRISMA_CONFIG_VERSION, SERVICE_TOKEN_ENV_VAR, authServiceError, claimedExpiresAt, claimedIdentity, createCli, credentialRejectedError, credentialWorkspaceId, credentialWorkspaceMismatchError, credentialsRequiredError, defineCommand, defineCommandFamily, defineConfig, defineConfigSection, defineServerCommand, defineSessionCommand, emptyServiceTokenError, exitWithChildStatus, flag, loadConfig, noSessionForWorkspaceError, positional };
|