@prisma/compute-sdk 0.13.0 → 0.14.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.
- package/dist/errors.d.ts +6 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +2 -0
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -3
- package/dist/index.js.map +1 -1
- package/dist/log-stream.d.ts +40 -0
- package/dist/log-stream.d.ts.map +1 -0
- package/dist/log-stream.js +151 -0
- package/dist/log-stream.js.map +1 -0
- package/package.json +4 -2
- package/src/errors.ts +5 -0
- package/src/index.ts +10 -5
- package/src/log-stream.ts +218 -0
package/dist/errors.d.ts
CHANGED
|
@@ -107,6 +107,12 @@ declare const InvalidOptionsError_base: import("better-result").TaggedErrorClass
|
|
|
107
107
|
}>;
|
|
108
108
|
export declare class InvalidOptionsError extends InvalidOptionsError_base {
|
|
109
109
|
}
|
|
110
|
+
declare const LogStreamError_base: import("better-result").TaggedErrorClass<"LogStreamError", {
|
|
111
|
+
statusCode: number;
|
|
112
|
+
message: string;
|
|
113
|
+
}>;
|
|
114
|
+
export declare class LogStreamError extends LogStreamError_base {
|
|
115
|
+
}
|
|
110
116
|
export type DeployError = AuthenticationError | ApiError | MissingArgumentError | InvalidOptionsError | BuildError | ArtifactError | TimeoutError | VersionFailedError | CancelledError;
|
|
111
117
|
export type UpdateEnvError = AuthenticationError | ApiError | MissingArgumentError | NoExistingVersionError | TimeoutError | VersionFailedError | CancelledError;
|
|
112
118
|
export type DestroyVersionError = CancelledError | MissingArgumentError | NoVersionsFoundError | AuthenticationError | ApiError | TimeoutError | VersionFailedError;
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";gBAGc,GAAG;aACN,MAAM;;AAFjB,qBAAa,m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.js
CHANGED
|
@@ -63,4 +63,6 @@ export class DestroyAggregateError extends TaggedError("DestroyAggregateError")(
|
|
|
63
63
|
}
|
|
64
64
|
export class InvalidOptionsError extends TaggedError("InvalidOptionsError")() {
|
|
65
65
|
}
|
|
66
|
+
export class LogStreamError extends TaggedError("LogStreamError")() {
|
|
67
|
+
}
|
|
66
68
|
//# sourceMappingURL=errors.js.map
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,MAAM,OAAO,mBAAoB,SAAQ,WAAW,CAAC,qBAAqB,CAAC,EAGvE;CAAG;AAEP,MAAM,OAAO,QAAS,SAAQ,WAAW,CAAC,UAAU,CAAC,EAOjD;CAAG;AAEP,MAAM,OAAO,oBAAqB,SAAQ,WAAW,CAAC,sBAAsB,CAAC,EAGzE;IACF,YAAY,IAAuB;QACjC,KAAK,CAAC;YACJ,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,OAAO,EAAE,8BAA8B,IAAI,CAAC,KAAK,EAAE;SACpD,CAAC,CAAC;IACL,CAAC;CACF;AAED,MAAM,OAAO,UAAW,SAAQ,WAAW,CAAC,YAAY,CAAC,EAGrD;CAAG;AAEP,MAAM,OAAO,aAAc,SAAQ,WAAW,CAAC,eAAe,CAAC,EAG3D;CAAG;AAEP,MAAM,OAAO,YAAa,SAAQ,WAAW,CAAC,cAAc,CAAC,EAKzD;IACF,YAAY,IAIX;QACC,KAAK,CAAC;YACJ,GAAG,IAAI;YACP,OAAO,EAAE,iCAAiC,IAAI,CAAC,SAAS,wCAAwC,IAAI,CAAC,UAAU,cAAc,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,IAAI;SACnK,CAAC,CAAC;IACL,CAAC;CACF;AAED,MAAM,OAAO,kBAAmB,SAAQ,W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ACzB,EAGG;IACF,YAAY,IAA2B;QACrC,KAAK,CAAC;YACJ,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,OAAO,EAAE,WAAW,IAAI,CAAC,SAAS,4FAA4F;SAC/H,CAAC,CAAC;IACL,CAAC;CACF;AAED,MAAM,OAAO,oBAAqB,SAAQ,WAAW,CAAC,sBAAsB,CAAC,EAGzE;IACF,YAAY,IAA2B;QACrC,KAAK,CAAC;YACJ,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,OAAO,EAAE,WAAW,IAAI,CAAC,SAAS,kBAAkB;SACrD,CAAC,CAAC;IACL,CAAC;CACF;AAED,MAAM,OAAO,cAAe,SAAQ,WAAW,CAAC,gBAAgB,CAAC,EAE7D;IACF,YAAY,IAA2B;QACrC,KAAK,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,IAAI,qBAAqB,EAAE,CAAC,CAAC;IAC7D,CAAC;CACF;AAED,MAAM,OAAO,qBAAsB,SAAQ,WAAW,CACpD,uBAAuB,CACxB,EAKG;IACF,YAAY,IAIX;QACC,MAAM,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACnE,KAAK,CAAC;YACJ,GAAG,IAAI;YACP,OAAO,EAAE,qBAAqB,IAAI,CAAC,QAAQ,CAAC,MAAM,gBAAgB,SAAS,EAAE;SAC9E,CAAC,CAAC;IACL,CAAC;CACF;AAED,MAAM,OAAO,mBAAoB,SAAQ,WAAW,CAAC,qBAAqB,CAAC,EAEvE;CAAG;AAEP,MAAM,OAAO,cAAe,SAAQ,WAAW,CAAC,gBAAgB,CAAC,EAG7D;CAAG"}
|
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,9 @@ export type { DeployInteraction, DeployProgress, DestroyServiceProgress, Destroy
|
|
|
7
7
|
export type { CreateProjectOptions, CreateServiceOptions, DeleteServiceOptions, DeleteVersionOptions, DeployOptions, DeployResult, DestroyServiceOptions, DestroyServiceResult, DestroyVersionOptions, DestroyVersionResult, ListProjectsOptions, ListServicesOptions, ListVersionsOptions, PromoteOptions, PromoteResult, ShowServiceOptions, ShowVersionOptions, StartVersionOptions, StopVersionOptions, UpdateEnvOptions, UpdateEnvResult, } from "./compute-client.ts";
|
|
8
8
|
export { ComputeClient } from "./compute-client.ts";
|
|
9
9
|
export type { ApiRequestError, DeployError, DestroyServiceError, DestroyVersionError, PromoteError, UpdateEnvError, VersionOperationError, } from "./errors.ts";
|
|
10
|
-
export { ApiError, ArtifactError, AuthenticationError, BuildError, CancelledError, DestroyAggregateError, InvalidOptionsError, MissingArgumentError, NoExistingVersionError, NoVersionsFoundError, TimeoutError, VersionFailedError, } from "./errors.ts";
|
|
10
|
+
export { ApiError, ArtifactError, AuthenticationError, BuildError, CancelledError, DestroyAggregateError, InvalidOptionsError, LogStreamError, MissingArgumentError, NoExistingVersionError, NoVersionsFoundError, TimeoutError, VersionFailedError, } from "./errors.ts";
|
|
11
|
+
export type { LogRecord, LogStreamOptions, StreamLogsError, StreamRecord, StreamResult, TerminalRecord, } from "./log-stream.ts";
|
|
12
|
+
export { streamLogs } from "./log-stream.ts";
|
|
11
13
|
export { NextjsBuild } from "./nextjs-build.ts";
|
|
12
14
|
export type { CreateProjectResult, DatabaseInfo, PortMapping, ProjectInfo, RegionInfo, ResolvedConfig, ServiceDetail, ServiceInfo, VersionDetail, VersionInfo, } from "./types.ts";
|
|
13
15
|
export { KNOWN_REGION_IDS, REGIONS } from "./types.ts";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,GAAG,EACH,UAAU,EACV,iBAAiB,EACjB,EAAE,EACF,KAAK,MAAM,EACX,WAAW,GACZ,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,GAAG,EACH,UAAU,EACV,iBAAiB,EACjB,EAAE,EACF,KAAK,MAAM,EACX,WAAW,GACZ,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,YAAY,EACV,iBAAiB,EACjB,cAAc,EACd,sBAAsB,EACtB,yBAAyB,EACzB,sBAAsB,EACtB,eAAe,EACf,iBAAiB,GAClB,MAAM,gBAAgB,CAAC;AACxB,YAAY,EACV,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,EACpB,aAAa,EACb,YAAY,EACZ,qBAAqB,EACrB,oBAAoB,EACpB,qBAAqB,EACrB,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,cAAc,EACd,aAAa,EACb,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,EAClB,gBAAgB,EAChB,eAAe,GAChB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,YAAY,EACV,eAAe,EACf,WAAW,EACX,mBAAmB,EACnB,mBAAmB,EACnB,YAAY,EACZ,cAAc,EACd,qBAAqB,GACtB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,QAAQ,EACR,aAAa,EACb,mBAAmB,EACnB,UAAU,EACV,cAAc,EACd,qBAAqB,EACrB,mBAAmB,EACnB,cAAc,EACd,oBAAoB,EACpB,sBAAsB,EACtB,oBAAoB,EACpB,YAAY,EACZ,kBAAkB,GACnB,MAAM,aAAa,CAAC;AACrB,YAAY,EACV,SAAS,EACT,gBAAgB,EAChB,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,cAAc,GACf,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,YAAY,EACV,mBAAmB,EACnB,YAAY,EACZ,WAAW,EACX,WAAW,EACX,UAAU,EACV,cAAc,EACd,aAAa,EACb,WAAW,EACX,aAAa,EACb,WAAW,GACZ,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -3,10 +3,9 @@ export { Err, matchError, matchErrorPartial, Ok, TaggedError, } from "better-res
|
|
|
3
3
|
export { AutoBuild } from "./auto-build.js";
|
|
4
4
|
export { PreBuilt } from "./build-strategy.js";
|
|
5
5
|
export { BunBuild } from "./bun-build.js";
|
|
6
|
-
// Core client
|
|
7
6
|
export { ComputeClient } from "./compute-client.js";
|
|
8
|
-
|
|
9
|
-
export {
|
|
7
|
+
export { ApiError, ArtifactError, AuthenticationError, BuildError, CancelledError, DestroyAggregateError, InvalidOptionsError, LogStreamError, MissingArgumentError, NoExistingVersionError, NoVersionsFoundError, TimeoutError, VersionFailedError, } from "./errors.js";
|
|
8
|
+
export { streamLogs } from "./log-stream.js";
|
|
10
9
|
export { NextjsBuild } from "./nextjs-build.js";
|
|
11
10
|
export { KNOWN_REGION_IDS, REGIONS } from "./types.js";
|
|
12
11
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,uFAAuF;AACvF,OAAO,EACL,GAAG,EACH,UAAU,EACV,iBAAiB,EACjB,EAAE,EAEF,WAAW,GACZ,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,uFAAuF;AACvF,OAAO,EACL,GAAG,EACH,UAAU,EACV,iBAAiB,EACjB,EAAE,EAEF,WAAW,GACZ,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAiC1C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAUpD,OAAO,EACL,QAAQ,EACR,aAAa,EACb,mBAAmB,EACnB,UAAU,EACV,cAAc,EACd,qBAAqB,EACrB,mBAAmB,EACnB,cAAc,EACd,oBAAoB,EACpB,sBAAsB,EACtB,oBAAoB,EACpB,YAAY,EACZ,kBAAkB,GACnB,MAAM,aAAa,CAAC;AASrB,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAahD,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Result } from "better-result";
|
|
2
|
+
import { CancelledError, LogStreamError } from "./errors.ts";
|
|
3
|
+
export type LogRecord = {
|
|
4
|
+
type: "log";
|
|
5
|
+
text: string;
|
|
6
|
+
byteStart: number;
|
|
7
|
+
byteEnd: number;
|
|
8
|
+
};
|
|
9
|
+
export type TerminalRecord = {
|
|
10
|
+
type: "terminal";
|
|
11
|
+
kind: "end" | "error";
|
|
12
|
+
code: string;
|
|
13
|
+
message: string;
|
|
14
|
+
retryable: boolean;
|
|
15
|
+
cursor: string | null;
|
|
16
|
+
details?: Record<string, unknown>;
|
|
17
|
+
};
|
|
18
|
+
export type StreamRecord = LogRecord | TerminalRecord;
|
|
19
|
+
export type LogStreamOptions = {
|
|
20
|
+
baseUrl: string;
|
|
21
|
+
token: string;
|
|
22
|
+
versionId: string;
|
|
23
|
+
tail?: number;
|
|
24
|
+
fromStart?: boolean;
|
|
25
|
+
cursor?: string;
|
|
26
|
+
signal?: AbortSignal;
|
|
27
|
+
};
|
|
28
|
+
export type StreamResult = {
|
|
29
|
+
terminal: TerminalRecord | null;
|
|
30
|
+
lastByteEnd: number | null;
|
|
31
|
+
};
|
|
32
|
+
export type StreamLogsError = LogStreamError | CancelledError;
|
|
33
|
+
/**
|
|
34
|
+
* Open a WebSocket to the log-streaming endpoint and deliver records via callback.
|
|
35
|
+
*
|
|
36
|
+
* Returns `Ok` with the stream result on graceful close, or `Err` with a
|
|
37
|
+
* `LogStreamError` (connection/HTTP errors) or `CancelledError` (abort signal).
|
|
38
|
+
*/
|
|
39
|
+
export declare function streamLogs(options: LogStreamOptions, onRecord: (record: StreamRecord) => void): Promise<Result<StreamResult, StreamLogsError>>;
|
|
40
|
+
//# sourceMappingURL=log-stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log-stream.d.ts","sourceRoot":"","sources":["../src/log-stream.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAI7D,MAAM,MAAM,SAAS,GAAG;IACtB,IAAI,EAAE,KAAK,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,UAAU,CAAC;IACjB,IAAI,EAAE,KAAK,GAAG,OAAO,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,OAAO,CAAC;IACnB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,cAAc,CAAC;AAEtD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,EAAE,cAAc,GAAG,IAAI,CAAC;IAChC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,cAAc,GAAG,cAAc,CAAC;AA6J9D;;;;;GAKG;AACH,wBAAsB,UAAU,CAC9B,OAAO,EAAE,gBAAgB,EACzB,QAAQ,EAAE,CAAC,MAAM,EAAE,YAAY,KAAK,IAAI,GACvC,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,CAAC,CAUhD"}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { Result } from "better-result";
|
|
2
|
+
import WebSocket from "ws";
|
|
3
|
+
import { CancelledError, LogStreamError } from "./errors.js";
|
|
4
|
+
const isBun = "Bun" in globalThis;
|
|
5
|
+
function parseErrorBody(body, statusCode) {
|
|
6
|
+
try {
|
|
7
|
+
const parsed = JSON.parse(body);
|
|
8
|
+
return parsed.error?.message ?? parsed.message ?? `HTTP ${statusCode}`;
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return body || `HTTP ${statusCode}`;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function toError(value) {
|
|
15
|
+
if (value instanceof Error)
|
|
16
|
+
return value;
|
|
17
|
+
// Bun emits ErrorEvent instead of Error on WebSocket failures
|
|
18
|
+
if (typeof value === "object" &&
|
|
19
|
+
value !== null &&
|
|
20
|
+
"message" in value &&
|
|
21
|
+
typeof value.message === "string") {
|
|
22
|
+
return new Error(value.message);
|
|
23
|
+
}
|
|
24
|
+
return new Error(String(value));
|
|
25
|
+
}
|
|
26
|
+
function buildWebSocketUrl(options) {
|
|
27
|
+
const httpUrl = new URL(`/v1/compute-services/versions/${encodeURIComponent(options.versionId)}/logs`, options.baseUrl);
|
|
28
|
+
httpUrl.protocol = httpUrl.protocol === "https:" ? "wss:" : "ws:";
|
|
29
|
+
if (options.tail != null)
|
|
30
|
+
httpUrl.searchParams.set("tail", String(options.tail));
|
|
31
|
+
if (options.fromStart)
|
|
32
|
+
httpUrl.searchParams.set("from_start", "true");
|
|
33
|
+
if (options.cursor)
|
|
34
|
+
httpUrl.searchParams.set("cursor", options.cursor);
|
|
35
|
+
return httpUrl.toString();
|
|
36
|
+
}
|
|
37
|
+
function connectOnce(options, onRecord) {
|
|
38
|
+
return new Promise((resolve, reject) => {
|
|
39
|
+
if (options.signal?.aborted) {
|
|
40
|
+
reject(new CancelledError());
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const url = buildWebSocketUrl(options);
|
|
44
|
+
const ws = new WebSocket(url, {
|
|
45
|
+
headers: { Authorization: `Bearer ${options.token}` },
|
|
46
|
+
});
|
|
47
|
+
let terminal = null;
|
|
48
|
+
let lastByteEnd = null;
|
|
49
|
+
let settled = false;
|
|
50
|
+
const cleanup = () => {
|
|
51
|
+
options.signal?.removeEventListener("abort", onAbort);
|
|
52
|
+
};
|
|
53
|
+
const onAbort = () => {
|
|
54
|
+
cleanup();
|
|
55
|
+
if (!settled) {
|
|
56
|
+
settled = true;
|
|
57
|
+
ws.close();
|
|
58
|
+
reject(new CancelledError());
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
options.signal?.addEventListener("abort", onAbort, { once: true });
|
|
62
|
+
if (options.signal?.aborted) {
|
|
63
|
+
onAbort();
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
// Node.js ws: fires when the server responds with a non-101 status,
|
|
67
|
+
// giving us access to the HTTP response for structured error messages.
|
|
68
|
+
// Bun doesn't implement this event — errors go to the "error" handler.
|
|
69
|
+
if (!isBun) {
|
|
70
|
+
ws.on("unexpected-response", (_req, res) => {
|
|
71
|
+
const chunks = [];
|
|
72
|
+
res.on("data", (chunk) => {
|
|
73
|
+
chunks.push(chunk);
|
|
74
|
+
});
|
|
75
|
+
res.on("end", () => {
|
|
76
|
+
cleanup();
|
|
77
|
+
if (!settled) {
|
|
78
|
+
settled = true;
|
|
79
|
+
const statusCode = res.statusCode ?? 0;
|
|
80
|
+
const body = Buffer.concat(chunks).toString();
|
|
81
|
+
reject(new LogStreamError({
|
|
82
|
+
statusCode,
|
|
83
|
+
message: parseErrorBody(body, statusCode),
|
|
84
|
+
}));
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
ws.on("message", (data) => {
|
|
90
|
+
let record;
|
|
91
|
+
try {
|
|
92
|
+
record = JSON.parse(data.toString());
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (record.type === "log") {
|
|
98
|
+
lastByteEnd = record.byteEnd;
|
|
99
|
+
}
|
|
100
|
+
else if (record.type === "terminal") {
|
|
101
|
+
terminal = record;
|
|
102
|
+
}
|
|
103
|
+
try {
|
|
104
|
+
onRecord(record);
|
|
105
|
+
}
|
|
106
|
+
catch (err) {
|
|
107
|
+
cleanup();
|
|
108
|
+
if (!settled) {
|
|
109
|
+
settled = true;
|
|
110
|
+
ws.close();
|
|
111
|
+
reject(toError(err));
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
ws.on("close", () => {
|
|
116
|
+
cleanup();
|
|
117
|
+
if (!settled) {
|
|
118
|
+
settled = true;
|
|
119
|
+
resolve({ terminal, lastByteEnd });
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
ws.on("error", (err) => {
|
|
123
|
+
cleanup();
|
|
124
|
+
if (!settled) {
|
|
125
|
+
settled = true;
|
|
126
|
+
const error = toError(err);
|
|
127
|
+
reject(new LogStreamError({ statusCode: 0, message: error.message }));
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Open a WebSocket to the log-streaming endpoint and deliver records via callback.
|
|
134
|
+
*
|
|
135
|
+
* Returns `Ok` with the stream result on graceful close, or `Err` with a
|
|
136
|
+
* `LogStreamError` (connection/HTTP errors) or `CancelledError` (abort signal).
|
|
137
|
+
*/
|
|
138
|
+
export async function streamLogs(options, onRecord) {
|
|
139
|
+
return Result.tryPromise({
|
|
140
|
+
try: () => connectOnce(options, onRecord),
|
|
141
|
+
catch: (e) => {
|
|
142
|
+
if (CancelledError.is(e))
|
|
143
|
+
return e;
|
|
144
|
+
if (LogStreamError.is(e))
|
|
145
|
+
return e;
|
|
146
|
+
const error = toError(e);
|
|
147
|
+
return new LogStreamError({ statusCode: 0, message: error.message });
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=log-stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log-stream.js","sourceRoot":"","sources":["../src/log-stream.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,SAAS,MAAM,IAAI,CAAC;AAC3B,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7D,MAAM,KAAK,GAAG,KAAK,IAAI,UAAU,CAAC;AAsClC,SAAS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E,GAAG,EAAE,CAAC,WAAW,CAAC,OAAO,EAAE,QAAQ,CAAC;QACzC,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE;YACX,IAAI,cAAc,CAAC,EAAE,CAAC,CAAC,CAAC;gBAAE,OAAO,CAAC,CAAC;YACnC,IAAI,cAAc,CAAC,EAAE,CAAC,CAAC,CAAC;gBAAE,OAAO,CAAC,CAAC;YACnC,MAAM,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;YACzB,OAAO,IAAI,cAAc,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QACvE,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma/compute-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "TypeScript SDK for deploying and managing applications on Prisma Compute",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": "prisma/project-compute",
|
|
@@ -31,8 +31,9 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"better-result": "^2.7.0",
|
|
34
|
+
"tar-stream": "^3.1.8",
|
|
34
35
|
"tiny-invariant": "1.3.3",
|
|
35
|
-
"
|
|
36
|
+
"ws": "^8.20.0"
|
|
36
37
|
},
|
|
37
38
|
"peerDependencies": {
|
|
38
39
|
"@prisma/management-api-sdk": ">=1.23.0"
|
|
@@ -40,6 +41,7 @@
|
|
|
40
41
|
"devDependencies": {
|
|
41
42
|
"@types/bun": "latest",
|
|
42
43
|
"@types/tar-stream": "^3.1.4",
|
|
44
|
+
"@types/ws": "^8.18.1",
|
|
43
45
|
"typescript": "^6.0.2"
|
|
44
46
|
}
|
|
45
47
|
}
|
package/src/errors.ts
CHANGED
|
@@ -125,6 +125,11 @@ export class InvalidOptionsError extends TaggedError("InvalidOptionsError")<{
|
|
|
125
125
|
message: string;
|
|
126
126
|
}>() {}
|
|
127
127
|
|
|
128
|
+
export class LogStreamError extends TaggedError("LogStreamError")<{
|
|
129
|
+
statusCode: number;
|
|
130
|
+
message: string;
|
|
131
|
+
}>() {}
|
|
132
|
+
|
|
128
133
|
export type DeployError =
|
|
129
134
|
| AuthenticationError
|
|
130
135
|
| ApiError
|
package/src/index.ts
CHANGED
|
@@ -8,11 +8,9 @@ export {
|
|
|
8
8
|
TaggedError,
|
|
9
9
|
} from "better-result";
|
|
10
10
|
export { AutoBuild } from "./auto-build.ts";
|
|
11
|
-
// Build strategy
|
|
12
11
|
export type { BuildArtifact, BuildStrategy } from "./build-strategy.ts";
|
|
13
12
|
export { PreBuilt } from "./build-strategy.ts";
|
|
14
13
|
export { BunBuild } from "./bun-build.ts";
|
|
15
|
-
// Callbacks
|
|
16
14
|
export type {
|
|
17
15
|
DeployInteraction,
|
|
18
16
|
DeployProgress,
|
|
@@ -45,7 +43,6 @@ export type {
|
|
|
45
43
|
UpdateEnvOptions,
|
|
46
44
|
UpdateEnvResult,
|
|
47
45
|
} from "./compute-client.ts";
|
|
48
|
-
// Core client
|
|
49
46
|
export { ComputeClient } from "./compute-client.ts";
|
|
50
47
|
export type {
|
|
51
48
|
ApiRequestError,
|
|
@@ -56,7 +53,6 @@ export type {
|
|
|
56
53
|
UpdateEnvError,
|
|
57
54
|
VersionOperationError,
|
|
58
55
|
} from "./errors.ts";
|
|
59
|
-
// Errors
|
|
60
56
|
export {
|
|
61
57
|
ApiError,
|
|
62
58
|
ArtifactError,
|
|
@@ -65,14 +61,23 @@ export {
|
|
|
65
61
|
CancelledError,
|
|
66
62
|
DestroyAggregateError,
|
|
67
63
|
InvalidOptionsError,
|
|
64
|
+
LogStreamError,
|
|
68
65
|
MissingArgumentError,
|
|
69
66
|
NoExistingVersionError,
|
|
70
67
|
NoVersionsFoundError,
|
|
71
68
|
TimeoutError,
|
|
72
69
|
VersionFailedError,
|
|
73
70
|
} from "./errors.ts";
|
|
71
|
+
export type {
|
|
72
|
+
LogRecord,
|
|
73
|
+
LogStreamOptions,
|
|
74
|
+
StreamLogsError,
|
|
75
|
+
StreamRecord,
|
|
76
|
+
StreamResult,
|
|
77
|
+
TerminalRecord,
|
|
78
|
+
} from "./log-stream.ts";
|
|
79
|
+
export { streamLogs } from "./log-stream.ts";
|
|
74
80
|
export { NextjsBuild } from "./nextjs-build.ts";
|
|
75
|
-
// Domain types
|
|
76
81
|
export type {
|
|
77
82
|
CreateProjectResult,
|
|
78
83
|
DatabaseInfo,
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import type { IncomingMessage } from "node:http";
|
|
2
|
+
import { Result } from "better-result";
|
|
3
|
+
import WebSocket from "ws";
|
|
4
|
+
import { CancelledError, LogStreamError } from "./errors.ts";
|
|
5
|
+
|
|
6
|
+
const isBun = "Bun" in globalThis;
|
|
7
|
+
|
|
8
|
+
export type LogRecord = {
|
|
9
|
+
type: "log";
|
|
10
|
+
text: string;
|
|
11
|
+
byteStart: number;
|
|
12
|
+
byteEnd: number;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type TerminalRecord = {
|
|
16
|
+
type: "terminal";
|
|
17
|
+
kind: "end" | "error";
|
|
18
|
+
code: string;
|
|
19
|
+
message: string;
|
|
20
|
+
retryable: boolean;
|
|
21
|
+
cursor: string | null;
|
|
22
|
+
details?: Record<string, unknown>;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export type StreamRecord = LogRecord | TerminalRecord;
|
|
26
|
+
|
|
27
|
+
export type LogStreamOptions = {
|
|
28
|
+
baseUrl: string;
|
|
29
|
+
token: string;
|
|
30
|
+
versionId: string;
|
|
31
|
+
tail?: number;
|
|
32
|
+
fromStart?: boolean;
|
|
33
|
+
cursor?: string;
|
|
34
|
+
signal?: AbortSignal;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export type StreamResult = {
|
|
38
|
+
terminal: TerminalRecord | null;
|
|
39
|
+
lastByteEnd: number | null;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export type StreamLogsError = LogStreamError | CancelledError;
|
|
43
|
+
|
|
44
|
+
function parseErrorBody(body: string, statusCode: number): string {
|
|
45
|
+
try {
|
|
46
|
+
const parsed = JSON.parse(body) as {
|
|
47
|
+
message?: string;
|
|
48
|
+
error?: { message?: string };
|
|
49
|
+
};
|
|
50
|
+
return parsed.error?.message ?? parsed.message ?? `HTTP ${statusCode}`;
|
|
51
|
+
} catch {
|
|
52
|
+
return body || `HTTP ${statusCode}`;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function toError(value: unknown): Error {
|
|
57
|
+
if (value instanceof Error) return value;
|
|
58
|
+
|
|
59
|
+
// Bun emits ErrorEvent instead of Error on WebSocket failures
|
|
60
|
+
if (
|
|
61
|
+
typeof value === "object" &&
|
|
62
|
+
value !== null &&
|
|
63
|
+
"message" in value &&
|
|
64
|
+
typeof (value as { message: unknown }).message === "string"
|
|
65
|
+
) {
|
|
66
|
+
return new Error((value as { message: string }).message);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return new Error(String(value));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function buildWebSocketUrl(options: LogStreamOptions): string {
|
|
73
|
+
const httpUrl = new URL(
|
|
74
|
+
`/v1/compute-services/versions/${encodeURIComponent(options.versionId)}/logs`,
|
|
75
|
+
options.baseUrl,
|
|
76
|
+
);
|
|
77
|
+
httpUrl.protocol = httpUrl.protocol === "https:" ? "wss:" : "ws:";
|
|
78
|
+
|
|
79
|
+
if (options.tail != null)
|
|
80
|
+
httpUrl.searchParams.set("tail", String(options.tail));
|
|
81
|
+
if (options.fromStart) httpUrl.searchParams.set("from_start", "true");
|
|
82
|
+
if (options.cursor) httpUrl.searchParams.set("cursor", options.cursor);
|
|
83
|
+
|
|
84
|
+
return httpUrl.toString();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
type ConnectResult = {
|
|
88
|
+
terminal: TerminalRecord | null;
|
|
89
|
+
lastByteEnd: number | null;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
function connectOnce(
|
|
93
|
+
options: LogStreamOptions,
|
|
94
|
+
onRecord: (record: StreamRecord) => void,
|
|
95
|
+
): Promise<ConnectResult> {
|
|
96
|
+
return new Promise<ConnectResult>((resolve, reject) => {
|
|
97
|
+
if (options.signal?.aborted) {
|
|
98
|
+
reject(new CancelledError());
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const url = buildWebSocketUrl(options);
|
|
103
|
+
const ws = new WebSocket(url, {
|
|
104
|
+
headers: { Authorization: `Bearer ${options.token}` },
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
let terminal: TerminalRecord | null = null;
|
|
108
|
+
let lastByteEnd: number | null = null;
|
|
109
|
+
let settled = false;
|
|
110
|
+
|
|
111
|
+
const cleanup = () => {
|
|
112
|
+
options.signal?.removeEventListener("abort", onAbort);
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const onAbort = () => {
|
|
116
|
+
cleanup();
|
|
117
|
+
if (!settled) {
|
|
118
|
+
settled = true;
|
|
119
|
+
ws.close();
|
|
120
|
+
reject(new CancelledError());
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
options.signal?.addEventListener("abort", onAbort, { once: true });
|
|
124
|
+
|
|
125
|
+
if (options.signal?.aborted) {
|
|
126
|
+
onAbort();
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Node.js ws: fires when the server responds with a non-101 status,
|
|
131
|
+
// giving us access to the HTTP response for structured error messages.
|
|
132
|
+
// Bun doesn't implement this event — errors go to the "error" handler.
|
|
133
|
+
if (!isBun) {
|
|
134
|
+
ws.on("unexpected-response", (_req: unknown, res: IncomingMessage) => {
|
|
135
|
+
const chunks: Buffer[] = [];
|
|
136
|
+
res.on("data", (chunk: Buffer) => {
|
|
137
|
+
chunks.push(chunk);
|
|
138
|
+
});
|
|
139
|
+
res.on("end", () => {
|
|
140
|
+
cleanup();
|
|
141
|
+
if (!settled) {
|
|
142
|
+
settled = true;
|
|
143
|
+
const statusCode = res.statusCode ?? 0;
|
|
144
|
+
const body = Buffer.concat(chunks).toString();
|
|
145
|
+
reject(
|
|
146
|
+
new LogStreamError({
|
|
147
|
+
statusCode,
|
|
148
|
+
message: parseErrorBody(body, statusCode),
|
|
149
|
+
}),
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
ws.on("message", (data: WebSocket.RawData) => {
|
|
157
|
+
let record: StreamRecord;
|
|
158
|
+
try {
|
|
159
|
+
record = JSON.parse(data.toString()) as StreamRecord;
|
|
160
|
+
} catch {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
if (record.type === "log") {
|
|
164
|
+
lastByteEnd = record.byteEnd;
|
|
165
|
+
} else if (record.type === "terminal") {
|
|
166
|
+
terminal = record;
|
|
167
|
+
}
|
|
168
|
+
try {
|
|
169
|
+
onRecord(record);
|
|
170
|
+
} catch (err) {
|
|
171
|
+
cleanup();
|
|
172
|
+
if (!settled) {
|
|
173
|
+
settled = true;
|
|
174
|
+
ws.close();
|
|
175
|
+
reject(toError(err));
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
ws.on("close", () => {
|
|
181
|
+
cleanup();
|
|
182
|
+
if (!settled) {
|
|
183
|
+
settled = true;
|
|
184
|
+
resolve({ terminal, lastByteEnd });
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
ws.on("error", (err: unknown) => {
|
|
189
|
+
cleanup();
|
|
190
|
+
if (!settled) {
|
|
191
|
+
settled = true;
|
|
192
|
+
const error = toError(err);
|
|
193
|
+
reject(new LogStreamError({ statusCode: 0, message: error.message }));
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Open a WebSocket to the log-streaming endpoint and deliver records via callback.
|
|
201
|
+
*
|
|
202
|
+
* Returns `Ok` with the stream result on graceful close, or `Err` with a
|
|
203
|
+
* `LogStreamError` (connection/HTTP errors) or `CancelledError` (abort signal).
|
|
204
|
+
*/
|
|
205
|
+
export async function streamLogs(
|
|
206
|
+
options: LogStreamOptions,
|
|
207
|
+
onRecord: (record: StreamRecord) => void,
|
|
208
|
+
): Promise<Result<StreamResult, StreamLogsError>> {
|
|
209
|
+
return Result.tryPromise({
|
|
210
|
+
try: () => connectOnce(options, onRecord),
|
|
211
|
+
catch: (e) => {
|
|
212
|
+
if (CancelledError.is(e)) return e;
|
|
213
|
+
if (LogStreamError.is(e)) return e;
|
|
214
|
+
const error = toError(e);
|
|
215
|
+
return new LogStreamError({ statusCode: 0, message: error.message });
|
|
216
|
+
},
|
|
217
|
+
});
|
|
218
|
+
}
|