@prisma/compute-sdk 0.35.0 → 0.36.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 +199 -120
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -60,12 +60,12 @@ const result = await compute.deploy({
|
|
|
60
60
|
entrypoint: "index.js",
|
|
61
61
|
}),
|
|
62
62
|
projectId: "your-project-id",
|
|
63
|
-
|
|
63
|
+
appName: "my-app",
|
|
64
64
|
region: "us-east-1",
|
|
65
65
|
});
|
|
66
66
|
|
|
67
67
|
if (result.isOk()) {
|
|
68
|
-
console.log(`Deployed to ${result.value.
|
|
68
|
+
console.log(`Deployed to ${result.value.deploymentEndpointDomain}`);
|
|
69
69
|
} else {
|
|
70
70
|
console.error(`Deploy failed: ${result.error.message}`);
|
|
71
71
|
}
|
|
@@ -89,27 +89,29 @@ All methods return `Promise<Result<T, E>>` — a discriminated union that is eit
|
|
|
89
89
|
|
|
90
90
|
#### `deploy(options): Promise<Result<DeployResult, DeployError>>`
|
|
91
91
|
|
|
92
|
-
Builds, uploads, and deploys an application
|
|
92
|
+
Builds, uploads, and deploys an application, then promotes it to the app's live endpoint.
|
|
93
93
|
|
|
94
94
|
```ts
|
|
95
95
|
const result = await compute.deploy({
|
|
96
96
|
// Required: how to produce the deployable artifact
|
|
97
97
|
strategy: new PreBuilt({ appPath: "./dist", entrypoint: "index.js" }),
|
|
98
98
|
|
|
99
|
-
// Target (provide
|
|
99
|
+
// Target (provide appId OR projectId + appName + region)
|
|
100
100
|
projectId: "proj_abc",
|
|
101
|
-
|
|
101
|
+
appName: "my-app",
|
|
102
102
|
region: "us-east-1",
|
|
103
103
|
// OR:
|
|
104
|
-
|
|
104
|
+
appId: "app_xyz",
|
|
105
105
|
|
|
106
106
|
// Optional
|
|
107
|
-
// Stored through the environment-variable API before the
|
|
108
|
-
// Production
|
|
107
|
+
// Stored through the environment-variable API before the deployment is created.
|
|
108
|
+
// Production apps use project vars; preview-branch apps use branch overrides.
|
|
109
109
|
envVars: { DATABASE_URL: "postgresql://..." },
|
|
110
110
|
portMapping: { http: 3000 },
|
|
111
111
|
timeoutSeconds: 120, // max time to wait for "running" status
|
|
112
112
|
pollIntervalMs: 1000, // how often to check status
|
|
113
|
+
skipPromote: false, // deploy without promoting to the app's live endpoint
|
|
114
|
+
destroyOldDeployment: false, // destroy (rather than just stop) the previously promoted deployment
|
|
113
115
|
signal: abortController.signal,
|
|
114
116
|
progress: {
|
|
115
117
|
/* DeployProgress callbacks */
|
|
@@ -120,31 +122,38 @@ const result = await compute.deploy({
|
|
|
120
122
|
});
|
|
121
123
|
|
|
122
124
|
if (result.isOk()) {
|
|
123
|
-
const {
|
|
125
|
+
const { deploymentEndpointDomain, deploymentId, appId, resolvedConfig } =
|
|
126
|
+
result.value;
|
|
124
127
|
}
|
|
125
128
|
```
|
|
126
129
|
|
|
130
|
+
`skipPromote` and `destroyOldDeployment` are mutually exclusive — combining them returns an `InvalidOptionsError`, since there is no previously-active deployment to destroy when promotion is skipped.
|
|
131
|
+
|
|
127
132
|
**Returns** `DeployResult`:
|
|
128
133
|
|
|
129
|
-
| Field
|
|
130
|
-
|
|
|
131
|
-
| `projectId`
|
|
132
|
-
| `
|
|
133
|
-
| `
|
|
134
|
-
| `region`
|
|
135
|
-
| `
|
|
136
|
-
| `
|
|
137
|
-
| `
|
|
134
|
+
| Field | Type | Description |
|
|
135
|
+
| -------------------------- | ---------------------------------------------------- | -------------------------------------------------------- |
|
|
136
|
+
| `projectId` | `string` | Project ID |
|
|
137
|
+
| `appId` | `string` | App ID |
|
|
138
|
+
| `appName` | `string` | App display name |
|
|
139
|
+
| `region` | `string` | Region identifier |
|
|
140
|
+
| `deploymentId` | `string` | Created deployment ID |
|
|
141
|
+
| `deploymentEndpointDomain` | `string` | Live URL of the new deployment |
|
|
142
|
+
| `appEndpointDomain` | `string \| null` | The app's live URL, or `null` when `skipPromote` was set |
|
|
143
|
+
| `promoted` | `boolean` | Whether the new deployment was promoted |
|
|
144
|
+
| `previousDeploymentId` | `string \| null` | The previously active deployment, if any |
|
|
145
|
+
| `previousDeploymentAction` | `"stopped" \| "destroyed" \| "still-active" \| null` | What happened to the previous deployment |
|
|
146
|
+
| `resolvedConfig` | `ResolvedConfig` | Final resolved configuration |
|
|
138
147
|
|
|
139
148
|
---
|
|
140
149
|
|
|
141
150
|
#### `updateEnv(options): Promise<Result<UpdateEnvResult, UpdateEnvError>>`
|
|
142
151
|
|
|
143
|
-
Updates project environment variables and/or port mapping, then creates a new
|
|
152
|
+
Updates project environment variables and/or port mapping, then creates a new deployment that reuses the code from the most recent deployment. Preview-branch apps update preview branch overrides.
|
|
144
153
|
|
|
145
154
|
```ts
|
|
146
155
|
const result = await compute.updateEnv({
|
|
147
|
-
|
|
156
|
+
appId: "app_xyz",
|
|
148
157
|
envVars: { DATABASE_URL: "postgresql://new-url..." },
|
|
149
158
|
portMapping: { http: 8080 },
|
|
150
159
|
});
|
|
@@ -154,7 +163,7 @@ To remove an environment variable, set its value to `null`:
|
|
|
154
163
|
|
|
155
164
|
```ts
|
|
156
165
|
const result = await compute.updateEnv({
|
|
157
|
-
|
|
166
|
+
appId: "app_xyz",
|
|
158
167
|
envVars: {
|
|
159
168
|
DATABASE_URL: "postgresql://new-url...", // set or update
|
|
160
169
|
OLD_SECRET: null, // remove
|
|
@@ -162,44 +171,97 @@ const result = await compute.updateEnv({
|
|
|
162
171
|
});
|
|
163
172
|
```
|
|
164
173
|
|
|
165
|
-
The
|
|
174
|
+
The app must have at least one existing deployment. If not, this returns a `NoExistingDeploymentError`.
|
|
166
175
|
|
|
167
176
|
---
|
|
168
177
|
|
|
169
|
-
#### `
|
|
178
|
+
#### `destroyDeployment(options): Promise<Result<DestroyDeploymentResult, DestroyDeploymentError>>`
|
|
170
179
|
|
|
171
|
-
Stops (if running) and deletes a single
|
|
180
|
+
Stops (if running) and deletes a single deployment.
|
|
172
181
|
|
|
173
182
|
```ts
|
|
174
|
-
const result = await compute.
|
|
175
|
-
|
|
176
|
-
// OR provide
|
|
183
|
+
const result = await compute.destroyDeployment({
|
|
184
|
+
deploymentId: "dep_abc",
|
|
185
|
+
// OR provide appId + interaction.selectDeployment for interactive selection
|
|
177
186
|
});
|
|
178
187
|
```
|
|
179
188
|
|
|
180
|
-
**Returns** `
|
|
189
|
+
**Returns** `DestroyDeploymentResult`:
|
|
190
|
+
|
|
191
|
+
| Field | Type | Description |
|
|
192
|
+
| ---------------- | --------- | ----------------------------- |
|
|
193
|
+
| `deploymentId` | `string` | The destroyed deployment ID |
|
|
194
|
+
| `previousStatus` | `string` | Status before destruction |
|
|
195
|
+
| `stopped` | `boolean` | Whether a stop was required |
|
|
196
|
+
| `deleted` | `boolean` | Whether deletion succeeded |
|
|
197
|
+
|
|
198
|
+
---
|
|
199
|
+
|
|
200
|
+
#### `destroyApp(options): Promise<Result<DestroyAppResult, DestroyAppError>>`
|
|
201
|
+
|
|
202
|
+
Stops all running deployments, deletes all deployments, and optionally deletes the app itself.
|
|
203
|
+
|
|
204
|
+
```ts
|
|
205
|
+
const result = await compute.destroyApp({
|
|
206
|
+
appId: "app_xyz",
|
|
207
|
+
keepApp: false, // set to true to keep the app record
|
|
208
|
+
});
|
|
209
|
+
```
|
|
181
210
|
|
|
182
|
-
|
|
183
|
-
| ---------------- | --------- | --------------------------- |
|
|
184
|
-
| `versionId` | `string` | The destroyed version ID |
|
|
185
|
-
| `previousStatus` | `string` | Status before destruction |
|
|
186
|
-
| `stopped` | `boolean` | Whether a stop was required |
|
|
187
|
-
| `deleted` | `boolean` | Whether deletion succeeded |
|
|
211
|
+
If some deployments fail to stop or delete, returns a `DestroyAggregateError` with details on which succeeded and which failed.
|
|
188
212
|
|
|
189
213
|
---
|
|
190
214
|
|
|
191
|
-
#### `
|
|
215
|
+
#### `promote(options): Promise<Result<PromoteResult, PromoteError>>`
|
|
192
216
|
|
|
193
|
-
|
|
217
|
+
Promotes an existing deployment to the app's live endpoint, starting it first if it isn't already running. Unlike `deploy`, this does not build, upload, or create a new deployment — it operates on one that already exists.
|
|
194
218
|
|
|
195
219
|
```ts
|
|
196
|
-
const result = await compute.
|
|
197
|
-
|
|
198
|
-
|
|
220
|
+
const result = await compute.promote({
|
|
221
|
+
appId: "app_xyz",
|
|
222
|
+
deploymentId: "dep_abc",
|
|
223
|
+
// OR provide interaction.selectDeployment for interactive selection
|
|
199
224
|
});
|
|
200
225
|
```
|
|
201
226
|
|
|
202
|
-
|
|
227
|
+
**Returns** `PromoteResult`:
|
|
228
|
+
|
|
229
|
+
| Field | Type | Description |
|
|
230
|
+
| -------------------- | --------- | ------------------------------------------------ |
|
|
231
|
+
| `appId` | `string` | App ID |
|
|
232
|
+
| `deploymentId` | `string` | The promoted deployment ID |
|
|
233
|
+
| `appEndpointDomain` | `string` | The app's live URL after promotion |
|
|
234
|
+
| `deploymentStarted` | `boolean` | Whether the deployment had to be started first |
|
|
235
|
+
|
|
236
|
+
---
|
|
237
|
+
|
|
238
|
+
#### `createProject(options): Promise<Result<CreateProjectResult, ApiRequestError>>`
|
|
239
|
+
|
|
240
|
+
Creates a new project, optionally provisioning a database alongside it.
|
|
241
|
+
|
|
242
|
+
```ts
|
|
243
|
+
const result = await compute.createProject({
|
|
244
|
+
name: "my-project",
|
|
245
|
+
createDatabase: true,
|
|
246
|
+
region: "us-east-1",
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
if (result.isOk()) {
|
|
250
|
+
console.log(`Project: ${result.value.id}`);
|
|
251
|
+
if (result.value.database) {
|
|
252
|
+
console.log(`Database: ${result.value.database.connectionString}`);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
**Returns** `CreateProjectResult` (`ProjectInfo & { database?: DatabaseInfo }`):
|
|
258
|
+
|
|
259
|
+
| Field | Type | Description |
|
|
260
|
+
| --------------- | -------------- | ------------------------------------------------------ |
|
|
261
|
+
| `id` | `string` | Project ID |
|
|
262
|
+
| `name` | `string` | Project name |
|
|
263
|
+
| `defaultRegion` | `string \| undefined` | Default region, if set |
|
|
264
|
+
| `database` | `DatabaseInfo \| undefined` | Provisioned database, present when `createDatabase` is true |
|
|
203
265
|
|
|
204
266
|
---
|
|
205
267
|
|
|
@@ -216,59 +278,59 @@ if (result.isOk()) {
|
|
|
216
278
|
|
|
217
279
|
---
|
|
218
280
|
|
|
219
|
-
#### `
|
|
281
|
+
#### `listApps(options): Promise<Result<AppInfo[], ApiRequestError>>`
|
|
220
282
|
|
|
221
283
|
```ts
|
|
222
|
-
const result = await compute.
|
|
284
|
+
const result = await compute.listApps({ projectId: "proj_abc" });
|
|
223
285
|
```
|
|
224
286
|
|
|
225
287
|
---
|
|
226
288
|
|
|
227
|
-
#### `
|
|
289
|
+
#### `createApp(options): Promise<Result<AppInfo, ApiRequestError>>`
|
|
228
290
|
|
|
229
291
|
```ts
|
|
230
|
-
const result = await compute.
|
|
292
|
+
const result = await compute.createApp({
|
|
231
293
|
projectId: "proj_abc",
|
|
232
|
-
|
|
294
|
+
appName: "my-new-app",
|
|
233
295
|
region: "eu-west-3",
|
|
234
296
|
});
|
|
235
297
|
```
|
|
236
298
|
|
|
237
299
|
---
|
|
238
300
|
|
|
239
|
-
#### `
|
|
301
|
+
#### `showApp(options): Promise<Result<AppDetail, ApiRequestError>>`
|
|
240
302
|
|
|
241
303
|
```ts
|
|
242
|
-
const result = await compute.
|
|
304
|
+
const result = await compute.showApp({ appId: "app_xyz" });
|
|
243
305
|
if (result.isOk()) {
|
|
244
|
-
console.log(`Latest
|
|
306
|
+
console.log(`Latest deployment: ${result.value.latestDeploymentId}`);
|
|
245
307
|
}
|
|
246
308
|
```
|
|
247
309
|
|
|
248
310
|
---
|
|
249
311
|
|
|
250
|
-
#### `
|
|
312
|
+
#### `deleteApp(options): Promise<Result<void, ApiRequestError>>`
|
|
251
313
|
|
|
252
|
-
Deletes
|
|
314
|
+
Deletes an app record. The app should have no deployments (use `destroyApp` to clean up deployments first).
|
|
253
315
|
|
|
254
316
|
```ts
|
|
255
|
-
await compute.
|
|
317
|
+
await compute.deleteApp({ appId: "app_xyz" });
|
|
256
318
|
```
|
|
257
319
|
|
|
258
320
|
---
|
|
259
321
|
|
|
260
|
-
#### `
|
|
322
|
+
#### `listDeployments(options): Promise<Result<DeploymentInfo[], ApiRequestError>>`
|
|
261
323
|
|
|
262
324
|
```ts
|
|
263
|
-
const result = await compute.
|
|
325
|
+
const result = await compute.listDeployments({ appId: "app_xyz" });
|
|
264
326
|
```
|
|
265
327
|
|
|
266
328
|
---
|
|
267
329
|
|
|
268
|
-
#### `
|
|
330
|
+
#### `showDeployment(options): Promise<Result<DeploymentDetail, ApiRequestError>>`
|
|
269
331
|
|
|
270
332
|
```ts
|
|
271
|
-
const result = await compute.
|
|
333
|
+
const result = await compute.showDeployment({ deploymentId: "dep_abc" });
|
|
272
334
|
if (result.isOk()) {
|
|
273
335
|
console.log(`Status: ${result.value.status}`);
|
|
274
336
|
console.log(`URL: https://${result.value.previewDomain}`);
|
|
@@ -277,31 +339,31 @@ if (result.isOk()) {
|
|
|
277
339
|
|
|
278
340
|
---
|
|
279
341
|
|
|
280
|
-
#### `
|
|
342
|
+
#### `startDeployment(options): Promise<Result<void, ApiRequestError>>`
|
|
281
343
|
|
|
282
344
|
```ts
|
|
283
|
-
await compute.
|
|
345
|
+
await compute.startDeployment({ deploymentId: "dep_abc" });
|
|
284
346
|
```
|
|
285
347
|
|
|
286
348
|
---
|
|
287
349
|
|
|
288
|
-
#### `
|
|
350
|
+
#### `stopDeployment(options): Promise<Result<void, ApiRequestError>>`
|
|
289
351
|
|
|
290
352
|
```ts
|
|
291
|
-
await compute.
|
|
353
|
+
await compute.stopDeployment({ deploymentId: "dep_abc" });
|
|
292
354
|
```
|
|
293
355
|
|
|
294
356
|
---
|
|
295
357
|
|
|
296
|
-
#### `
|
|
358
|
+
#### `deleteDeployment(options): Promise<Result<void, ApiRequestError>>`
|
|
297
359
|
|
|
298
360
|
```ts
|
|
299
|
-
await compute.
|
|
361
|
+
await compute.deleteDeployment({ deploymentId: "dep_abc" });
|
|
300
362
|
```
|
|
301
363
|
|
|
302
364
|
## Build strategies
|
|
303
365
|
|
|
304
|
-
A build strategy produces a deployable artifact (a directory with an entrypoint file). The SDK ships with two built-in strategies:
|
|
366
|
+
A build strategy produces a deployable artifact (a directory with an entrypoint file). The SDK ships with two built-in general-purpose strategies (plus framework-specific ones used internally by `AutoBuild`):
|
|
305
367
|
|
|
306
368
|
### `PreBuilt`
|
|
307
369
|
|
|
@@ -368,14 +430,14 @@ const result = await compute.deploy({
|
|
|
368
430
|
|
|
369
431
|
// Pattern 1: isOk / isErr
|
|
370
432
|
if (result.isOk()) {
|
|
371
|
-
console.log(result.value.
|
|
433
|
+
console.log(result.value.deploymentEndpointDomain);
|
|
372
434
|
} else {
|
|
373
435
|
console.error(result.error.message);
|
|
374
436
|
}
|
|
375
437
|
|
|
376
438
|
// Pattern 2: match
|
|
377
439
|
result.match({
|
|
378
|
-
Ok: (value) => console.log(value.
|
|
440
|
+
Ok: (value) => console.log(value.deploymentEndpointDomain),
|
|
379
441
|
Err: (error) => console.error(error.message),
|
|
380
442
|
});
|
|
381
443
|
```
|
|
@@ -384,18 +446,20 @@ result.match({
|
|
|
384
446
|
|
|
385
447
|
Every error extends `TaggedError` and has a `_tag` discriminant for pattern matching:
|
|
386
448
|
|
|
387
|
-
| Error class
|
|
388
|
-
|
|
|
389
|
-
| `AuthenticationError`
|
|
390
|
-
| `ApiError`
|
|
391
|
-
| `MissingArgumentError`
|
|
392
|
-
| `
|
|
393
|
-
| `
|
|
394
|
-
| `
|
|
395
|
-
| `
|
|
396
|
-
| `
|
|
397
|
-
| `
|
|
398
|
-
| `
|
|
449
|
+
| Error class | `_tag` | Description |
|
|
450
|
+
| --------------------------- | ----------------------------- | ----------------------------------------------------------- |
|
|
451
|
+
| `AuthenticationError` | `"AuthenticationError"` | API returned HTTP 401 |
|
|
452
|
+
| `ApiError` | `"ApiError"` | API returned a non-401 error |
|
|
453
|
+
| `MissingArgumentError` | `"MissingArgumentError"` | A required argument was not provided |
|
|
454
|
+
| `InvalidOptionsError` | `"InvalidOptionsError"` | A conflicting or invalid combination of options was provided |
|
|
455
|
+
| `BuildError` | `"BuildError"` | Build strategy failed |
|
|
456
|
+
| `ArtifactError` | `"ArtifactError"` | Archive creation or upload failed |
|
|
457
|
+
| `TimeoutError` | `"TimeoutError"` | Deployment didn't reach target status in time |
|
|
458
|
+
| `DeploymentFailedError` | `"DeploymentFailedError"` | Deployment transitioned to `"failed"` status |
|
|
459
|
+
| `NoExistingDeploymentError` | `"NoExistingDeploymentError"` | `updateEnv` called on an app with no prior deployments |
|
|
460
|
+
| `NoDeploymentsFoundError` | `"NoDeploymentsFoundError"` | App has no deployments to select from |
|
|
461
|
+
| `CancelledError` | `"CancelledError"` | Operation cancelled via `AbortSignal` |
|
|
462
|
+
| `DestroyAggregateError` | `"DestroyAggregateError"` | Some deployments failed during `destroyApp` |
|
|
399
463
|
|
|
400
464
|
### Matching specific errors
|
|
401
465
|
|
|
@@ -432,11 +496,12 @@ if (result.isErr()) {
|
|
|
432
496
|
|
|
433
497
|
The SDK exports narrowed error unions for each operation:
|
|
434
498
|
|
|
435
|
-
- **`DeployError`** — errors from `deploy()`: `CancelledError | MissingArgumentError | AuthenticationError | ApiError | BuildError | ArtifactError | TimeoutError |
|
|
436
|
-
- **`UpdateEnvError`** — errors from `updateEnv()`: `CancelledError | MissingArgumentError | AuthenticationError | ApiError |
|
|
437
|
-
- **`
|
|
438
|
-
- **`
|
|
439
|
-
- **`
|
|
499
|
+
- **`DeployError`** — errors from `deploy()`: `CancelledError | MissingArgumentError | InvalidOptionsError | AuthenticationError | ApiError | BuildError | ArtifactError | TimeoutError | DeploymentFailedError`
|
|
500
|
+
- **`UpdateEnvError`** — errors from `updateEnv()`: `CancelledError | MissingArgumentError | InvalidOptionsError | AuthenticationError | ApiError | NoExistingDeploymentError | TimeoutError | DeploymentFailedError`
|
|
501
|
+
- **`DestroyDeploymentError`** — errors from `destroyDeployment()`: `CancelledError | MissingArgumentError | NoDeploymentsFoundError | AuthenticationError | ApiError | TimeoutError | DeploymentFailedError`
|
|
502
|
+
- **`DestroyAppError`** — errors from `destroyApp()`: `CancelledError | AuthenticationError | ApiError | DestroyAggregateError`
|
|
503
|
+
- **`PromoteError`** — errors from `promote()`: `AuthenticationError | ApiError | MissingArgumentError | NoDeploymentsFoundError | TimeoutError | DeploymentFailedError | CancelledError`
|
|
504
|
+
- **`ApiRequestError`** — errors from single-request methods (`createProject`, `listProjects`, `listApps`, `createApp`, `startDeployment`, `stopDeployment`, `deleteDeployment`, etc.): `CancelledError | AuthenticationError | ApiError`
|
|
440
505
|
|
|
441
506
|
## Progress and interaction callbacks
|
|
442
507
|
|
|
@@ -444,11 +509,13 @@ Long-running operations accept `progress` and `interaction` callbacks for UI int
|
|
|
444
509
|
|
|
445
510
|
### Deploy progress
|
|
446
511
|
|
|
512
|
+
`deploy()` promotes the new deployment and stops (optionally destroys) the previous one by default, so `DeployProgress` also reports promotion and old-deployment cleanup progress alongside the build/upload/start steps:
|
|
513
|
+
|
|
447
514
|
```ts
|
|
448
515
|
await compute.deploy({
|
|
449
516
|
strategy,
|
|
450
517
|
projectId: "proj_abc",
|
|
451
|
-
|
|
518
|
+
appName: "my-app",
|
|
452
519
|
region: "us-east-1",
|
|
453
520
|
progress: {
|
|
454
521
|
onBuildStart() {
|
|
@@ -463,8 +530,8 @@ await compute.deploy({
|
|
|
463
530
|
onArchiveReady(sizeBytes) {
|
|
464
531
|
console.log(`Archive: ${(sizeBytes / 1024).toFixed(1)} KB`);
|
|
465
532
|
},
|
|
466
|
-
|
|
467
|
-
console.log(`
|
|
533
|
+
onDeploymentCreated(deploymentId) {
|
|
534
|
+
console.log(`Deployment: ${deploymentId}`);
|
|
468
535
|
},
|
|
469
536
|
onUploadStart() {
|
|
470
537
|
console.log("Uploading...");
|
|
@@ -481,13 +548,25 @@ await compute.deploy({
|
|
|
481
548
|
onRunning(deploymentUrl) {
|
|
482
549
|
console.log(`Live at ${deploymentUrl}`);
|
|
483
550
|
},
|
|
551
|
+
onPromoteStart() {
|
|
552
|
+
console.log("Promoting...");
|
|
553
|
+
},
|
|
554
|
+
onPromoted(appEndpointDomain) {
|
|
555
|
+
console.log(`Promoted: ${appEndpointDomain}`);
|
|
556
|
+
},
|
|
557
|
+
onOldDeploymentStopping(deploymentId) {
|
|
558
|
+
console.log(`Stopping previous deployment ${deploymentId}...`);
|
|
559
|
+
},
|
|
560
|
+
onOldDeploymentStopped(deploymentId) {
|
|
561
|
+
console.log(`Stopped previous deployment ${deploymentId}.`);
|
|
562
|
+
},
|
|
484
563
|
},
|
|
485
564
|
});
|
|
486
565
|
```
|
|
487
566
|
|
|
488
567
|
### Deploy interaction
|
|
489
568
|
|
|
490
|
-
When `projectId`, `
|
|
569
|
+
When `projectId`, `appId`/`appName`, or `region` aren't provided, the SDK calls interaction callbacks so the caller can resolve them (e.g., by prompting the user):
|
|
491
570
|
|
|
492
571
|
```ts
|
|
493
572
|
await compute.deploy({
|
|
@@ -497,16 +576,16 @@ await compute.deploy({
|
|
|
497
576
|
// projects: ProjectInfo[] — return the chosen project ID
|
|
498
577
|
return projects[0].id;
|
|
499
578
|
},
|
|
500
|
-
async
|
|
501
|
-
//
|
|
579
|
+
async selectApp(apps) {
|
|
580
|
+
// apps: AppInfo[] — return an app ID, or null to create a new one
|
|
502
581
|
return null;
|
|
503
582
|
},
|
|
504
|
-
async
|
|
505
|
-
// return a name for the new
|
|
506
|
-
return "my-new-
|
|
583
|
+
async provideAppName() {
|
|
584
|
+
// return a name for the new app
|
|
585
|
+
return "my-new-app";
|
|
507
586
|
},
|
|
508
587
|
async selectRegion(regions) {
|
|
509
|
-
// regions: RegionInfo[] —
|
|
588
|
+
// regions: RegionInfo[] — used to resolve a region when one wasn't supplied
|
|
510
589
|
return "us-east-1";
|
|
511
590
|
},
|
|
512
591
|
},
|
|
@@ -516,28 +595,28 @@ await compute.deploy({
|
|
|
516
595
|
### Destroy progress
|
|
517
596
|
|
|
518
597
|
```ts
|
|
519
|
-
await compute.
|
|
520
|
-
|
|
598
|
+
await compute.destroyApp({
|
|
599
|
+
appId: "app_xyz",
|
|
521
600
|
progress: {
|
|
522
|
-
|
|
601
|
+
onStoppingDeployments(deploymentIds) {
|
|
523
602
|
/* ... */
|
|
524
603
|
},
|
|
525
|
-
|
|
604
|
+
onDeploymentStopped(deploymentId) {
|
|
526
605
|
/* ... */
|
|
527
606
|
},
|
|
528
|
-
|
|
607
|
+
onAllDeploymentsStopped() {
|
|
529
608
|
/* ... */
|
|
530
609
|
},
|
|
531
|
-
|
|
610
|
+
onDeletingDeployments(deploymentIds) {
|
|
532
611
|
/* ... */
|
|
533
612
|
},
|
|
534
|
-
|
|
613
|
+
onDeploymentDeleted(deploymentId) {
|
|
535
614
|
/* ... */
|
|
536
615
|
},
|
|
537
|
-
|
|
616
|
+
onAllDeploymentsDeleted() {
|
|
538
617
|
/* ... */
|
|
539
618
|
},
|
|
540
|
-
|
|
619
|
+
onAppDeleted(appId) {
|
|
541
620
|
/* ... */
|
|
542
621
|
},
|
|
543
622
|
},
|
|
@@ -556,7 +635,7 @@ setTimeout(() => controller.abort(), 30_000);
|
|
|
556
635
|
|
|
557
636
|
const result = await compute.deploy({
|
|
558
637
|
strategy,
|
|
559
|
-
|
|
638
|
+
appId: "app_xyz",
|
|
560
639
|
signal: controller.signal,
|
|
561
640
|
});
|
|
562
641
|
|
|
@@ -570,12 +649,12 @@ if (result.isErr() && result.error._tag === "CancelledError") {
|
|
|
570
649
|
```ts
|
|
571
650
|
import type {
|
|
572
651
|
ProjectInfo, // { id, name, defaultRegion? }
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
652
|
+
AppInfo, // { id, name, region, projectId, createdAt? }
|
|
653
|
+
AppDetail, // AppInfo & { latestDeploymentId?, appEndpointDomain? }
|
|
654
|
+
DeploymentInfo, // { id, status, createdAt, previewDomain? }
|
|
655
|
+
DeploymentDetail, // DeploymentInfo & { envVars?, foundryVersionId? }
|
|
577
656
|
RegionInfo, // { id, displayName }
|
|
578
|
-
ResolvedConfig, // { projectId,
|
|
657
|
+
ResolvedConfig, // { projectId, appId, appName, region, portMapping? }
|
|
579
658
|
PortMapping, // { http?: number | null }
|
|
580
659
|
} from "@prisma/compute-sdk";
|
|
581
660
|
```
|
|
@@ -609,7 +688,7 @@ async function main() {
|
|
|
609
688
|
entrypoint: "server.js",
|
|
610
689
|
}),
|
|
611
690
|
projectId: process.env.PROJECT_ID!,
|
|
612
|
-
|
|
691
|
+
appName: "my-api",
|
|
613
692
|
region: "us-east-1",
|
|
614
693
|
envVars: {
|
|
615
694
|
DATABASE_URL: process.env.DATABASE_URL!,
|
|
@@ -637,7 +716,7 @@ async function main() {
|
|
|
637
716
|
},
|
|
638
717
|
TimeoutError: (e) => {
|
|
639
718
|
console.error(`Deploy timed out (${Math.round(e.elapsedMs / 1000)}s).`);
|
|
640
|
-
console.error(`
|
|
719
|
+
console.error(`Deployment ${e.deploymentId} may still be starting.`);
|
|
641
720
|
process.exit(1);
|
|
642
721
|
},
|
|
643
722
|
_: (e) => {
|
|
@@ -648,17 +727,17 @@ async function main() {
|
|
|
648
727
|
return;
|
|
649
728
|
}
|
|
650
729
|
|
|
651
|
-
const {
|
|
652
|
-
console.log(`\
|
|
653
|
-
console.log(`
|
|
654
|
-
console.log(`URL:
|
|
655
|
-
|
|
656
|
-
// List
|
|
657
|
-
const
|
|
658
|
-
if (
|
|
659
|
-
console.log(`\
|
|
660
|
-
for (const
|
|
661
|
-
console.log(` ${
|
|
730
|
+
const { appId, deploymentId, deploymentEndpointDomain } = deployResult.value;
|
|
731
|
+
console.log(`\nApp: ${appId}`);
|
|
732
|
+
console.log(`Deployment: ${deploymentId}`);
|
|
733
|
+
console.log(`URL: ${deploymentEndpointDomain}`);
|
|
734
|
+
|
|
735
|
+
// List deployments
|
|
736
|
+
const deploymentsResult = await compute.listDeployments({ appId });
|
|
737
|
+
if (deploymentsResult.isOk()) {
|
|
738
|
+
console.log(`\nDeployments (${deploymentsResult.value.length}):`);
|
|
739
|
+
for (const d of deploymentsResult.value) {
|
|
740
|
+
console.log(` ${d.id} — ${d.status} (${d.createdAt})`);
|
|
662
741
|
}
|
|
663
742
|
}
|
|
664
743
|
}
|
|
@@ -669,7 +748,7 @@ main();
|
|
|
669
748
|
## Requirements
|
|
670
749
|
|
|
671
750
|
- Node.js >= 18.0.0
|
|
672
|
-
- `@prisma/management-api-sdk`
|
|
751
|
+
- `@prisma/management-api-sdk` ^1.44.0
|
|
673
752
|
|
|
674
753
|
## License
|
|
675
754
|
|
package/package.json
CHANGED