@prisma/compute-sdk 0.1.0 → 0.3.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/README.md CHANGED
@@ -83,11 +83,11 @@ import { ComputeClient } from "@prisma/compute-sdk";
83
83
  const compute = new ComputeClient(apiClient);
84
84
  ```
85
85
 
86
- All methods return `Promise<Result<T, ComputeError>>` — a discriminated union that is either `Ok` with a value or `Err` with a typed error. See [Error handling](#error-handling) for details.
86
+ All methods return `Promise<Result<T, E>>` — a discriminated union that is either `Ok` with a value or `Err` with a typed error. Each method declares only the error variants it can actually produce. See [Error handling](#error-handling) for details.
87
87
 
88
88
  ---
89
89
 
90
- #### `deploy(options): Promise<Result<DeployResult, ComputeError>>`
90
+ #### `deploy(options): Promise<Result<DeployResult, DeployError>>`
91
91
 
92
92
  Builds, uploads, and deploys an application version.
93
93
 
@@ -132,7 +132,7 @@ if (result.isOk()) {
132
132
 
133
133
  ---
134
134
 
135
- #### `updateEnv(options): Promise<Result<UpdateEnvResult, ComputeError>>`
135
+ #### `updateEnv(options): Promise<Result<UpdateEnvResult, UpdateEnvError>>`
136
136
 
137
137
  Creates a new version with updated environment variables and/or port mapping, reusing the code from the most recent deployment.
138
138
 
@@ -148,7 +148,7 @@ The service must have at least one existing version. If not, this returns a `NoE
148
148
 
149
149
  ---
150
150
 
151
- #### `destroyVersion(options): Promise<Result<DestroyVersionResult, ComputeError>>`
151
+ #### `destroyVersion(options): Promise<Result<DestroyVersionResult, DestroyVersionError>>`
152
152
 
153
153
  Stops (if running) and deletes a single version.
154
154
 
@@ -170,7 +170,7 @@ const result = await compute.destroyVersion({
170
170
 
171
171
  ---
172
172
 
173
- #### `destroyService(options): Promise<Result<DestroyServiceResult, ComputeError>>`
173
+ #### `destroyService(options): Promise<Result<DestroyServiceResult, DestroyServiceError>>`
174
174
 
175
175
  Stops all running versions, deletes all versions, and optionally deletes the service itself.
176
176
 
@@ -185,7 +185,7 @@ If some versions fail to stop or delete, returns a `DestroyAggregateError` with
185
185
 
186
186
  ---
187
187
 
188
- #### `listProjects(options?): Promise<Result<ProjectInfo[], ComputeError>>`
188
+ #### `listProjects(options?): Promise<Result<ProjectInfo[], ApiRequestError>>`
189
189
 
190
190
  ```ts
191
191
  const result = await compute.listProjects();
@@ -198,7 +198,7 @@ if (result.isOk()) {
198
198
 
199
199
  ---
200
200
 
201
- #### `listServices(options): Promise<Result<ServiceInfo[], ComputeError>>`
201
+ #### `listServices(options): Promise<Result<ServiceInfo[], ApiRequestError>>`
202
202
 
203
203
  ```ts
204
204
  const result = await compute.listServices({ projectId: "proj_abc" });
@@ -206,7 +206,7 @@ const result = await compute.listServices({ projectId: "proj_abc" });
206
206
 
207
207
  ---
208
208
 
209
- #### `createService(options): Promise<Result<ServiceInfo, ComputeError>>`
209
+ #### `createService(options): Promise<Result<ServiceInfo, ApiRequestError>>`
210
210
 
211
211
  ```ts
212
212
  const result = await compute.createService({
@@ -218,7 +218,7 @@ const result = await compute.createService({
218
218
 
219
219
  ---
220
220
 
221
- #### `showService(options): Promise<Result<ServiceDetail, ComputeError>>`
221
+ #### `showService(options): Promise<Result<ServiceDetail, ApiRequestError>>`
222
222
 
223
223
  ```ts
224
224
  const result = await compute.showService({ serviceId: "svc_xyz" });
@@ -229,7 +229,7 @@ if (result.isOk()) {
229
229
 
230
230
  ---
231
231
 
232
- #### `deleteService(options): Promise<Result<void, ComputeError>>`
232
+ #### `deleteService(options): Promise<Result<void, ApiRequestError>>`
233
233
 
234
234
  Deletes a service record. The service should have no versions (use `destroyService` to clean up versions first).
235
235
 
@@ -239,7 +239,7 @@ await compute.deleteService({ serviceId: "svc_xyz" });
239
239
 
240
240
  ---
241
241
 
242
- #### `listVersions(options): Promise<Result<VersionInfo[], ComputeError>>`
242
+ #### `listVersions(options): Promise<Result<VersionInfo[], ApiRequestError>>`
243
243
 
244
244
  ```ts
245
245
  const result = await compute.listVersions({ serviceId: "svc_xyz" });
@@ -247,7 +247,7 @@ const result = await compute.listVersions({ serviceId: "svc_xyz" });
247
247
 
248
248
  ---
249
249
 
250
- #### `showVersion(options): Promise<Result<VersionDetail, ComputeError>>`
250
+ #### `showVersion(options): Promise<Result<VersionDetail, ApiRequestError>>`
251
251
 
252
252
  ```ts
253
253
  const result = await compute.showVersion({ versionId: "ver_abc" });
@@ -259,7 +259,7 @@ if (result.isOk()) {
259
259
 
260
260
  ---
261
261
 
262
- #### `startVersion(options): Promise<Result<void, ComputeError>>`
262
+ #### `startVersion(options): Promise<Result<void, ApiRequestError>>`
263
263
 
264
264
  ```ts
265
265
  await compute.startVersion({ versionId: "ver_abc" });
@@ -267,7 +267,7 @@ await compute.startVersion({ versionId: "ver_abc" });
267
267
 
268
268
  ---
269
269
 
270
- #### `stopVersion(options): Promise<Result<void, ComputeError>>`
270
+ #### `stopVersion(options): Promise<Result<void, ApiRequestError>>`
271
271
 
272
272
  ```ts
273
273
  await compute.stopVersion({ versionId: "ver_abc" });
@@ -275,7 +275,7 @@ await compute.stopVersion({ versionId: "ver_abc" });
275
275
 
276
276
  ---
277
277
 
278
- #### `deleteVersion(options): Promise<Result<void, ComputeError>>`
278
+ #### `deleteVersion(options): Promise<Result<void, ApiRequestError>>`
279
279
 
280
280
  ```ts
281
281
  await compute.deleteVersion({ versionId: "ver_abc" });
@@ -409,10 +409,11 @@ if (result.isErr()) {
409
409
 
410
410
  The SDK exports narrowed error unions for each operation:
411
411
 
412
- - **`DeployError`** — errors from `deploy()`: `AuthenticationError | ApiError | MissingArgumentError | BuildError | ArtifactError | TimeoutError | VersionFailedError | CancelledError`
413
- - **`UpdateEnvError`** — errors from `updateEnv()`: `AuthenticationError | ApiError | MissingArgumentError | NoExistingVersionError | TimeoutError | VersionFailedError | CancelledError`
414
- - **`DestroyError`** — errors from `destroyVersion()` / `destroyService()`: `AuthenticationError | ApiError | MissingArgumentError | CancelledError | DestroyAggregateError`
415
- - **`ComputeError`** — union of all error types
412
+ - **`DeployError`** — errors from `deploy()`: `CancelledError | MissingArgumentError | AuthenticationError | ApiError | BuildError | ArtifactError | TimeoutError | VersionFailedError`
413
+ - **`UpdateEnvError`** — errors from `updateEnv()`: `CancelledError | MissingArgumentError | AuthenticationError | ApiError | NoExistingVersionError | TimeoutError | VersionFailedError`
414
+ - **`DestroyVersionError`** — errors from `destroyVersion()`: `CancelledError | MissingArgumentError | AuthenticationError | ApiError | TimeoutError | VersionFailedError`
415
+ - **`DestroyServiceError`** — errors from `destroyService()`: `CancelledError | AuthenticationError | ApiError | DestroyAggregateError`
416
+ - **`ApiRequestError`** — errors from simple CRUD methods (`listProjects`, `listServices`, `createService`, etc.): `CancelledError | AuthenticationError | ApiError`
416
417
 
417
418
  ## Progress and interaction callbacks
418
419
 
@@ -1,7 +1,7 @@
1
1
  import type { ManagementApiClient, paths } from "@prisma/management-api-sdk";
2
2
  import { Result } from "better-result";
3
- import { ApiError, AuthenticationError } from "./errors.ts";
4
- export type ApiClientError = AuthenticationError | ApiError;
3
+ import { ApiError, AuthenticationError, CancelledError } from "./errors.ts";
4
+ export type ApiClientError = CancelledError | AuthenticationError | ApiError;
5
5
  /**
6
6
  * Lean internal wrapper around ManagementApiClient.
7
7
  *
@@ -25,7 +25,7 @@ export declare class InternalApiClient {
25
25
  name: string;
26
26
  };
27
27
  }[], ApiClientError>>;
28
- getProject(id: string, signal?: AbortSignal): Promise<import("better-result").Ok<{
28
+ createProject(body: CreateProjectBody, signal?: AbortSignal): Promise<import("better-result").Ok<{
29
29
  id: string;
30
30
  type: "project";
31
31
  url: string;
@@ -37,6 +37,99 @@ export declare class InternalApiClient {
37
37
  url: string;
38
38
  name: string;
39
39
  };
40
+ database: {
41
+ id: string;
42
+ type: "database";
43
+ url: string;
44
+ name: string;
45
+ status: "provisioning" | "ready";
46
+ createdAt: string;
47
+ isDefault: boolean;
48
+ defaultConnectionId: string | null;
49
+ connections: {
50
+ id: string;
51
+ type: "connection";
52
+ url: string;
53
+ name: string;
54
+ createdAt: string;
55
+ kind: "postgres" | "accelerate";
56
+ endpoints: {
57
+ direct?: {
58
+ host: string;
59
+ port: number;
60
+ connectionString?: string;
61
+ };
62
+ pooled?: {
63
+ host: string;
64
+ port: number;
65
+ connectionString?: string;
66
+ };
67
+ accelerate?: {
68
+ host: string;
69
+ port: number;
70
+ connectionString?: string;
71
+ };
72
+ };
73
+ directConnection?: {
74
+ host: string;
75
+ pass: string;
76
+ user: string;
77
+ } | null;
78
+ database: {
79
+ id: string;
80
+ url: string;
81
+ name: string;
82
+ };
83
+ }[];
84
+ region: {
85
+ id: string;
86
+ name: string;
87
+ };
88
+ source: {
89
+ type: "empty";
90
+ } | {
91
+ type: "backup";
92
+ databaseId: string;
93
+ backupId: string;
94
+ } | {
95
+ type: "database";
96
+ databaseId: string;
97
+ } | null;
98
+ apiKeys: {
99
+ id: string;
100
+ type: "connection";
101
+ url: string;
102
+ name: string;
103
+ createdAt: string;
104
+ kind: "postgres" | "accelerate";
105
+ endpoints: {
106
+ direct?: {
107
+ host: string;
108
+ port: number;
109
+ };
110
+ pooled?: {
111
+ host: string;
112
+ port: number;
113
+ };
114
+ accelerate?: {
115
+ host: string;
116
+ port: number;
117
+ };
118
+ };
119
+ connectionString: string;
120
+ directConnection?: {
121
+ host: string;
122
+ pass: string;
123
+ user: string;
124
+ } | null;
125
+ }[];
126
+ connectionString: string | null;
127
+ directConnection: {
128
+ host: string;
129
+ pass: string;
130
+ user: string;
131
+ } | null;
132
+ } | null;
40
133
  }, ApiClientError> | import("better-result").Err<{
41
134
  id: string;
42
135
  type: "project";
@@ -49,6 +142,124 @@ export declare class InternalApiClient {
49
142
  url: string;
50
143
  name: string;
51
144
  };
145
+ database: {
146
+ id: string;
147
+ type: "database";
148
+ url: string;
149
+ name: string;
150
+ status: "provisioning" | "ready";
151
+ createdAt: string;
152
+ isDefault: boolean;
153
+ defaultConnectionId: string | null;
154
+ connections: {
155
+ id: string;
156
+ type: "connection";
157
+ url: string;
158
+ name: string;
159
+ createdAt: string;
160
+ kind: "postgres" | "accelerate";
161
+ endpoints: {
162
+ direct?: {
163
+ host: string;
164
+ port: number;
165
+ connectionString?: string;
166
+ };
167
+ pooled?: {
168
+ host: string;
169
+ port: number;
170
+ connectionString?: string;
171
+ };
172
+ accelerate?: {
173
+ host: string;
174
+ port: number;
175
+ connectionString?: string;
176
+ };
177
+ };
178
+ directConnection?: {
179
+ host: string;
180
+ pass: string;
181
+ user: string;
182
+ } | null;
183
+ database: {
184
+ id: string;
185
+ url: string;
186
+ name: string;
187
+ };
188
+ }[];
189
+ region: {
190
+ id: string;
191
+ name: string;
192
+ };
193
+ source: {
194
+ type: "empty";
195
+ } | {
196
+ type: "backup";
197
+ databaseId: string;
198
+ backupId: string;
199
+ } | {
200
+ type: "database";
201
+ databaseId: string;
202
+ } | null;
203
+ apiKeys: {
204
+ id: string;
205
+ type: "connection";
206
+ url: string;
207
+ name: string;
208
+ createdAt: string;
209
+ kind: "postgres" | "accelerate";
210
+ endpoints: {
211
+ direct?: {
212
+ host: string;
213
+ port: number;
214
+ };
215
+ pooled?: {
216
+ host: string;
217
+ port: number;
218
+ };
219
+ accelerate?: {
220
+ host: string;
221
+ port: number;
222
+ };
223
+ };
224
+ connectionString: string;
225
+ directConnection?: {
226
+ host: string;
227
+ pass: string;
228
+ user: string;
229
+ } | null;
230
+ }[];
231
+ connectionString: string | null;
232
+ directConnection: {
233
+ host: string;
234
+ pass: string;
235
+ user: string;
236
+ } | null;
237
+ } | null;
238
+ }, ApiClientError>>;
239
+ getProject(id: string, signal?: AbortSignal): Promise<import("better-result").Err<{
240
+ id: string;
241
+ type: "project";
242
+ url: string;
243
+ name: string;
244
+ createdAt: string;
245
+ defaultRegion: string | null;
246
+ workspace: {
247
+ id: string;
248
+ url: string;
249
+ name: string;
250
+ };
251
+ }, ApiClientError> | import("better-result").Ok<{
252
+ id: string;
253
+ type: "project";
254
+ url: string;
255
+ name: string;
256
+ createdAt: string;
257
+ defaultRegion: string | null;
258
+ workspace: {
259
+ id: string;
260
+ url: string;
261
+ name: string;
262
+ };
52
263
  }, ApiClientError>>;
53
264
  listProjectServices(projectId: string, signal?: AbortSignal): Promise<Result<{
54
265
  id: string;
@@ -61,6 +272,7 @@ export declare class InternalApiClient {
61
272
  };
62
273
  projectId: string;
63
274
  latestVersionId: string | null;
275
+ serviceEndpointDomain: string;
64
276
  createdAt: string;
65
277
  }[], ApiClientError>>;
66
278
  createProjectService(projectId: string, body: CreateProjectServiceBody, signal?: AbortSignal): Promise<import("better-result").Err<{
@@ -74,6 +286,7 @@ export declare class InternalApiClient {
74
286
  };
75
287
  projectId: string;
76
288
  latestVersionId: string | null;
289
+ serviceEndpointDomain: string;
77
290
  createdAt: string;
78
291
  }, ApiClientError> | import("better-result").Ok<{
79
292
  id: string;
@@ -86,6 +299,7 @@ export declare class InternalApiClient {
86
299
  };
87
300
  projectId: string;
88
301
  latestVersionId: string | null;
302
+ serviceEndpointDomain: string;
89
303
  createdAt: string;
90
304
  }, ApiClientError>>;
91
305
  getService(computeServiceId: string, signal?: AbortSignal): Promise<import("better-result").Err<{
@@ -99,6 +313,7 @@ export declare class InternalApiClient {
99
313
  };
100
314
  projectId: string;
101
315
  latestVersionId: string | null;
316
+ serviceEndpointDomain: string;
102
317
  createdAt: string;
103
318
  }, ApiClientError> | import("better-result").Ok<{
104
319
  id: string;
@@ -111,6 +326,7 @@ export declare class InternalApiClient {
111
326
  };
112
327
  projectId: string;
113
328
  latestVersionId: string | null;
329
+ serviceEndpointDomain: string;
114
330
  createdAt: string;
115
331
  }, ApiClientError>>;
116
332
  deleteService(computeServiceId: string, signal?: AbortSignal): Promise<Result<void, ApiClientError>>;
@@ -144,6 +360,9 @@ export declare class InternalApiClient {
144
360
  envVars?: {
145
361
  [key: string]: string;
146
362
  };
363
+ portMapping?: {
364
+ http?: number;
365
+ };
147
366
  createdAt: string;
148
367
  }, ApiClientError> | import("better-result").Ok<{
149
368
  id: string;
@@ -155,6 +374,9 @@ export declare class InternalApiClient {
155
374
  envVars?: {
156
375
  [key: string]: string;
157
376
  };
377
+ portMapping?: {
378
+ http?: number;
379
+ };
158
380
  createdAt: string;
159
381
  }, ApiClientError>>;
160
382
  startVersion(versionId: string, signal?: AbortSignal): Promise<import("better-result").Err<{
@@ -165,6 +387,10 @@ export declare class InternalApiClient {
165
387
  stopVersion(versionId: string, signal?: AbortSignal): Promise<Result<void, ApiClientError>>;
166
388
  deleteVersion(versionId: string, signal?: AbortSignal): Promise<Result<void, ApiClientError>>;
167
389
  }
390
+ type SdkCreateProjectBody = NonNullable<paths["/v1/projects"]["post"]["requestBody"]>["content"]["application/json"];
391
+ type CreateProjectBody = Omit<SdkCreateProjectBody, "region"> & {
392
+ region?: string;
393
+ };
168
394
  type SdkCreateProjectServiceBody = NonNullable<paths["/v1/projects/{projectId}/compute-services"]["post"]["requestBody"]>["content"]["application/json"];
169
395
  type CreateProjectServiceBody = Omit<SdkCreateProjectServiceBody, "regionId"> & {
170
396
  regionId?: string;
@@ -173,7 +399,6 @@ export type CreateServiceVersionBody = NonNullable<paths["/v1/compute-services/{
173
399
  /** Extract the upload URL from a version creation response. */
174
400
  export declare function readUploadUrl(data: {
175
401
  uploadUrl?: string | null;
176
- artifactUploadUrl?: string | null;
177
402
  }): string | null;
178
403
  /** Normalize a preview domain to a clickable https URL. */
179
404
  export declare function toDeploymentUrl(value: string): string;
@@ -1 +1 @@
1
- {"version":3,"file":"api-client.d.ts","sourceRoot":"","sources":["../src/api-client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AAC7E,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAE5D,MAAM,MAAM,cAAc,GAAG,mBAAmB,GAAG,QAAQ,CAAC;AAE5D;;;;;;GAMG;AACH,qBAAa,iBAAiB;;gBAGhB,MAAM,EAAE,mBAAmB;IAIjC,YAAY,CAAC,M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,aAAa,CAAC,IAAI,EAAE;IAClC,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B,GAAG,MAAM,GAAG,IAAI,CAKhB;AAED,2DAA2D;AAC3D,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAMrD"}
@@ -1,5 +1,5 @@
1
1
  import { Result } from "better-result";
2
- import { ApiError, AuthenticationError } from "./errors.js";
2
+ import { ApiError, AuthenticationError, CancelledError } from "./errors.js";
3
3
  /**
4
4
  * Lean internal wrapper around ManagementApiClient.
5
5
  *
@@ -16,38 +16,44 @@ export class InternalApiClient {
16
16
  return this.#requestPaginated((cursor) => this.#client.GET("/v1/projects", {
17
17
  params: { query: cursor ? { cursor } : {} },
18
18
  signal,
19
- }), "/v1/projects");
19
+ }), "/v1/projects", signal);
20
+ }
21
+ async createProject(body, signal) {
22
+ return this.#request(this.#client.POST("/v1/projects", {
23
+ body: body,
24
+ signal,
25
+ }), "/v1/projects", signal).then((r) => r.map((body) => body.data));
20
26
  }
21
27
  async getProject(id, signal) {
22
28
  return this.#request(this.#client.GET("/v1/projects/{id}", {
23
29
  params: { path: { id } },
24
30
  signal,
25
- }), "/v1/projects/{id}").then((r) => r.map((body) => body.data));
31
+ }), "/v1/projects/{id}", signal).then((r) => r.map((body) => body.data));
26
32
  }
27
33
  async listProjectServices(projectId, signal) {
28
34
  return this.#requestPaginated((cursor) => this.#client.GET("/v1/projects/{projectId}/compute-services", {
29
35
  params: { path: { projectId }, query: cursor ? { cursor } : {} },
30
36
  signal,
31
- }), "/v1/projects/{projectId}/compute-services");
37
+ }), "/v1/projects/{projectId}/compute-services", signal);
32
38
  }
33
39
  async createProjectService(projectId, body, signal) {
34
40
  return this.#request(this.#client.POST("/v1/projects/{projectId}/compute-services", {
35
41
  params: { path: { projectId } },
36
42
  body: body,
37
43
  signal,
38
- }), "/v1/projects/{projectId}/compute-services").then((r) => r.map((body) => body.data));
44
+ }), "/v1/projects/{projectId}/compute-services", signal).then((r) => r.map((body) => body.data));
39
45
  }
40
46
  async getService(computeServiceId, signal) {
41
47
  return this.#request(this.#client.GET("/v1/compute-services/{computeServiceId}", {
42
48
  params: { path: { computeServiceId } },
43
49
  signal,
44
- }), "/v1/compute-services/{computeServiceId}").then((r) => r.map((body) => body.data));
50
+ }), "/v1/compute-services/{computeServiceId}", signal).then((r) => r.map((body) => body.data));
45
51
  }
46
52
  async deleteService(computeServiceId, signal) {
47
53
  return this.#unwrapVoid(this.#client.DELETE("/v1/compute-services/{computeServiceId}", {
48
54
  params: { path: { computeServiceId } },
49
55
  signal,
50
- }));
56
+ }), signal);
51
57
  }
52
58
  async listServiceVersions(computeServiceId, signal) {
53
59
  return this.#requestPaginated((cursor) => this.#client.GET("/v1/compute-services/{computeServiceId}/versions", {
@@ -56,55 +62,61 @@ export class InternalApiClient {
56
62
  query: cursor ? { cursor } : {},
57
63
  },
58
64
  signal,
59
- }), "/v1/compute-services/{computeServiceId}/versions");
65
+ }), "/v1/compute-services/{computeServiceId}/versions", signal);
60
66
  }
61
67
  async createServiceVersion(computeServiceId, body, signal) {
62
68
  return this.#request(this.#client.POST("/v1/compute-services/{computeServiceId}/versions", {
63
69
  params: { path: { computeServiceId } },
64
70
  body,
65
71
  signal,
66
- }), "/v1/compute-services/{computeServiceId}/versions").then((r) => r.map((body) => body.data));
72
+ }), "/v1/compute-services/{computeServiceId}/versions", signal).then((r) => r.map((body) => body.data));
67
73
  }
68
74
  async getVersion(versionId, signal) {
69
75
  return this.#request(this.#client.GET("/v1/compute-services/versions/{versionId}", {
70
76
  params: { path: { versionId } },
71
77
  signal,
72
- }), "/v1/compute-services/versions/{versionId}").then((r) => r.map((body) => body.data));
78
+ }), "/v1/compute-services/versions/{versionId}", signal).then((r) => r.map((body) => body.data));
73
79
  }
74
80
  async startVersion(versionId, signal) {
75
81
  return this.#request(this.#client.POST("/v1/compute-services/versions/{versionId}/start", {
76
82
  params: { path: { versionId } },
77
83
  signal,
78
- }), "/v1/compute-services/versions/{versionId}/start").then((r) => r.map((body) => body.data));
84
+ }), "/v1/compute-services/versions/{versionId}/start", signal).then((r) => r.map((body) => body.data));
79
85
  }
80
86
  async stopVersion(versionId, signal) {
81
87
  return this.#unwrapVoid(this.#client.POST("/v1/compute-services/versions/{versionId}/stop", {
82
88
  params: { path: { versionId } },
83
89
  signal,
84
- }));
90
+ }), signal);
85
91
  }
86
92
  async deleteVersion(versionId, signal) {
87
93
  return this.#unwrapVoid(this.#client.DELETE("/v1/compute-services/versions/{versionId}", {
88
94
  params: { path: { versionId } },
89
95
  signal,
90
- }));
96
+ }), signal);
91
97
  }
92
- async #request(request, endpoint) {
93
- const result = await request;
98
+ async #request(request, endpoint, signal) {
99
+ let result;
100
+ try {
101
+ result = await request;
102
+ }
103
+ catch (error) {
104
+ return Result.err(parseRequestError(error, undefined, signal));
105
+ }
94
106
  if (result.error) {
95
- return Result.err(parseApiError(result.error, result.response));
107
+ return Result.err(parseRequestError(result.error, result.response, signal));
96
108
  }
97
109
  const body = result.data;
98
110
  if (body == null) {
99
- return Result.err(parseApiError(undefined, undefined, `Management API returned an empty response body for ${endpoint}`));
111
+ return Result.err(parseRequestError(undefined, undefined, signal, `Management API returned an empty response body for ${endpoint}`));
100
112
  }
101
113
  return Result.ok(body);
102
114
  }
103
- async #requestPaginated(makeRequest, endpoint) {
115
+ async #requestPaginated(makeRequest, endpoint, signal) {
104
116
  const allItems = [];
105
117
  let cursor;
106
118
  for (;;) {
107
- const result = await this.#request(makeRequest(cursor), endpoint);
119
+ const result = await this.#request(makeRequest(cursor), endpoint, signal);
108
120
  if (result.isErr())
109
121
  return result;
110
122
  allItems.push(...result.value.data);
@@ -115,10 +127,16 @@ export class InternalApiClient {
115
127
  }
116
128
  return Result.ok(allItems);
117
129
  }
118
- async #unwrapVoid(request) {
119
- const result = await request;
130
+ async #unwrapVoid(request, signal) {
131
+ let result;
132
+ try {
133
+ result = await request;
134
+ }
135
+ catch (error) {
136
+ return Result.err(parseRequestError(error, undefined, signal));
137
+ }
120
138
  if (result.error) {
121
- return Result.err(parseApiError(result.error, result.response));
139
+ return Result.err(parseRequestError(result.error, result.response, signal));
122
140
  }
123
141
  return Result.ok(undefined);
124
142
  }
@@ -168,15 +186,17 @@ function parseApiError(error, response, fallbackMessage) {
168
186
  traceHeaders,
169
187
  });
170
188
  }
189
+ function parseRequestError(error, response, signal, fallbackMessage) {
190
+ if (signal?.aborted) {
191
+ return new CancelledError();
192
+ }
193
+ return parseApiError(error, response, fallbackMessage);
194
+ }
171
195
  /** Extract the upload URL from a version creation response. */
172
196
  export function readUploadUrl(data) {
173
197
  if (typeof data.uploadUrl === "string" && data.uploadUrl.length > 0) {
174
198
  return data.uploadUrl;
175
199
  }
176
- if (typeof data.artifactUploadUrl === "string" &&
177
- data.artifactUploadUrl.length > 0) {
178
- return data.artifactUploadUrl;
179
- }
180
200
  return null;
181
201
  }
182
202
  /** Normalize a preview domain to a clickable https URL. */