@gaganref/confect-alchemy 10.3.1-fork.96 → 10.6.0-fork.2
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 +1 -1
- package/dist/Backend.d.ts.map +1 -1
- package/dist/Backend.js +2 -3
- package/dist/Backend.js.map +1 -1
- package/dist/Code.d.ts +16 -3
- package/dist/Code.d.ts.map +1 -1
- package/dist/Code.js +13 -3
- package/dist/Code.js.map +1 -1
- package/dist/Confect.d.ts.map +1 -1
- package/dist/Confect.js +1 -2
- package/dist/Convex.d.ts.map +1 -1
- package/dist/Convex.js +3 -4
- package/dist/ConvexClient.d.ts +14 -4
- package/dist/ConvexClient.d.ts.map +1 -1
- package/dist/ConvexClient.js +44 -36
- package/dist/ConvexClient.js.map +1 -1
- package/dist/DeployKey.d.ts +22 -12
- package/dist/DeployKey.d.ts.map +1 -1
- package/dist/DeployKey.js +41 -29
- package/dist/DeployKey.js.map +1 -1
- package/dist/Deployment.d.ts +19 -10
- package/dist/Deployment.d.ts.map +1 -1
- package/dist/Deployment.js +22 -19
- package/dist/Deployment.js.map +1 -1
- package/dist/EnvironmentVariables.d.ts +23 -31
- package/dist/EnvironmentVariables.d.ts.map +1 -1
- package/dist/EnvironmentVariables.js +21 -20
- package/dist/EnvironmentVariables.js.map +1 -1
- package/dist/Project.d.ts +15 -10
- package/dist/Project.d.ts.map +1 -1
- package/dist/Project.js +23 -22
- package/dist/Project.js.map +1 -1
- package/dist/Providers.d.ts +3 -1
- package/dist/Providers.d.ts.map +1 -1
- package/dist/Providers.js +19 -18
- package/dist/Providers.js.map +1 -1
- package/dist/_virtual/_rolldown/runtime.js +5 -6
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/internal/CodeDeployment.d.ts +6 -1
- package/dist/internal/CodeDeployment.d.ts.map +1 -1
- package/dist/internal/CodeDeployment.js +10 -8
- package/dist/internal/CodeDeployment.js.map +1 -1
- package/dist/internal/CommandRunner.d.ts +6 -1
- package/dist/internal/CommandRunner.d.ts.map +1 -1
- package/dist/internal/CommandRunner.js +11 -9
- package/dist/internal/CommandRunner.js.map +1 -1
- package/dist/internal/FileLock.d.ts +7 -3
- package/dist/internal/FileLock.d.ts.map +1 -1
- package/dist/internal/FileLock.js +10 -8
- package/dist/internal/FileLock.js.map +1 -1
- package/dist/internal/Lifecycle.d.ts +3 -1
- package/dist/internal/Lifecycle.d.ts.map +1 -1
- package/dist/internal/Lifecycle.js +3 -4
- package/dist/internal/Lifecycle.js.map +1 -1
- package/dist/internal/LocalBackend.d.ts +7 -3
- package/dist/internal/LocalBackend.d.ts.map +1 -1
- package/dist/internal/LocalBackend.js +26 -18
- package/dist/internal/LocalBackend.js.map +1 -1
- package/dist/internal/LocalSidecar.d.ts +4 -1
- package/dist/internal/LocalSidecar.d.ts.map +1 -1
- package/dist/internal/LocalSidecar.js +4 -2
- package/dist/internal/LocalSidecar.js.map +1 -1
- package/dist/internal/Loopback.d.ts.map +1 -1
- package/dist/internal/Loopback.js +1 -2
- package/dist/internal/MountInit.d.ts +5 -1
- package/dist/internal/MountInit.d.ts.map +1 -1
- package/dist/internal/MountInit.js +5 -4
- package/dist/internal/MountInit.js.map +1 -1
- package/dist/internal/PushLock.d.ts +7 -3
- package/dist/internal/PushLock.d.ts.map +1 -1
- package/dist/internal/PushLock.js +7 -6
- package/dist/internal/PushLock.js.map +1 -1
- package/dist/internal/ResourceIdentity.d.ts.map +1 -1
- package/dist/internal/ResourceIdentity.js +5 -3
- package/dist/internal/ResourceIdentity.js.map +1 -1
- package/dist/internal/UserCache.d.ts +2 -0
- package/dist/internal/UserCache.d.ts.map +1 -1
- package/dist/internal/UserCache.js +5 -4
- package/dist/internal/UserCache.js.map +1 -1
- package/dist/internal/Zip.d.ts +5 -1
- package/dist/internal/Zip.d.ts.map +1 -1
- package/dist/internal/Zip.js +9 -8
- package/dist/internal/Zip.js.map +1 -1
- package/package.json +5 -5
- package/src/Backend.ts +7 -6
- package/src/Code.ts +11 -0
- package/src/ConvexClient.ts +87 -74
- package/src/DeployKey.ts +73 -44
- package/src/Deployment.ts +50 -37
- package/src/EnvironmentVariables.ts +30 -27
- package/src/Project.ts +42 -41
- package/src/Providers.ts +2 -0
- package/src/index.ts +3 -0
- package/src/internal/CodeDeployment.ts +17 -11
- package/src/internal/CommandRunner.ts +27 -26
- package/src/internal/FileLock.ts +15 -12
- package/src/internal/Lifecycle.ts +11 -7
- package/src/internal/LocalBackend.ts +45 -39
- package/src/internal/LocalSidecar.ts +3 -0
- package/src/internal/MountInit.ts +8 -6
- package/src/internal/PushLock.ts +13 -11
- package/src/internal/ResourceIdentity.ts +12 -5
- package/src/internal/UserCache.ts +13 -4
- package/src/internal/Zip.ts +13 -8
package/src/ConvexClient.ts
CHANGED
|
@@ -12,6 +12,10 @@ import * as HttpClient from "effect/http/HttpClient";
|
|
|
12
12
|
import * as HttpClientRequest from "effect/http/HttpClientRequest";
|
|
13
13
|
import type * as HttpClientResponse from "effect/http/HttpClientResponse";
|
|
14
14
|
import * as Loopback from "./internal/Loopback.js";
|
|
15
|
+
import * as String from "effect/String";
|
|
16
|
+
import { pipe } from "effect/Function";
|
|
17
|
+
import * as Array from "effect/Array";
|
|
18
|
+
import * as Rec from "effect/Record";
|
|
15
19
|
|
|
16
20
|
export type Project = ManagementApi.ProjectResponse;
|
|
17
21
|
export type CreatedProject = ManagementApi.PlatformCreateProjectResponse;
|
|
@@ -74,28 +78,31 @@ const errorFields = {
|
|
|
74
78
|
]),
|
|
75
79
|
};
|
|
76
80
|
|
|
77
|
-
export class ConvexApiError extends Schema.TaggedError<
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
) {}
|
|
81
|
+
export class ConvexApiError extends Schema.TaggedError<
|
|
82
|
+
ConvexApiError,
|
|
83
|
+
{ readonly brand: unique symbol }
|
|
84
|
+
>()("ConvexApiError", errorFields) {}
|
|
81
85
|
|
|
82
|
-
export class ConvexNotFound extends Schema.TaggedError<
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
) {}
|
|
86
|
+
export class ConvexNotFound extends Schema.TaggedError<
|
|
87
|
+
ConvexNotFound,
|
|
88
|
+
{ readonly brand: unique symbol }
|
|
89
|
+
>()("ConvexNotFound", errorFields) {}
|
|
86
90
|
|
|
87
|
-
export class ConvexConflict extends Schema.TaggedError<
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
) {}
|
|
91
|
+
export class ConvexConflict extends Schema.TaggedError<
|
|
92
|
+
ConvexConflict,
|
|
93
|
+
{ readonly brand: unique symbol }
|
|
94
|
+
>()("ConvexConflict", errorFields) {}
|
|
91
95
|
|
|
92
96
|
/**
|
|
93
97
|
* A function the deployment ran failed, with the message Convex reports.
|
|
94
98
|
*/
|
|
95
|
-
export class ConvexFunctionError extends Schema.TaggedError<
|
|
96
|
-
|
|
97
|
-
{
|
|
98
|
-
) {
|
|
99
|
+
export class ConvexFunctionError extends Schema.TaggedError<
|
|
100
|
+
ConvexFunctionError,
|
|
101
|
+
{ readonly brand: unique symbol }
|
|
102
|
+
>()("ConvexFunctionError", {
|
|
103
|
+
functionPath: Schema.String,
|
|
104
|
+
errorMessage: Schema.String,
|
|
105
|
+
}) {}
|
|
99
106
|
|
|
100
107
|
const FunctionResponse = Schema.Union([
|
|
101
108
|
Schema.Struct({ status: Schema.Literal("success"), value: Schema.Unknown }),
|
|
@@ -117,16 +124,16 @@ const ProjectSchema = Schema.Struct({
|
|
|
117
124
|
teamId: Schema.Finite,
|
|
118
125
|
teamSlug: Schema.String,
|
|
119
126
|
createTime: Schema.Finite,
|
|
120
|
-
prodDeploymentName: Schema.
|
|
121
|
-
devDeploymentName: Schema.
|
|
127
|
+
prodDeploymentName: Schema.String.pipe(Schema.NullOr, Schema.optionalKey),
|
|
128
|
+
devDeploymentName: Schema.String.pipe(Schema.NullOr, Schema.optionalKey),
|
|
122
129
|
}) satisfies Schema.Schema<Project>;
|
|
123
130
|
|
|
124
131
|
const CreatedProjectSchema = Schema.Struct({
|
|
125
132
|
id: Schema.Finite,
|
|
126
133
|
projectId: Schema.Finite,
|
|
127
134
|
slug: Schema.String,
|
|
128
|
-
deploymentName: Schema.
|
|
129
|
-
deploymentUrl: Schema.
|
|
135
|
+
deploymentName: Schema.String.pipe(Schema.NullOr, Schema.optionalKey),
|
|
136
|
+
deploymentUrl: Schema.String.pipe(Schema.NullOr, Schema.optionalKey),
|
|
130
137
|
}) satisfies Schema.Schema<CreatedProject>;
|
|
131
138
|
|
|
132
139
|
const deploymentFields = {
|
|
@@ -134,7 +141,7 @@ const deploymentFields = {
|
|
|
134
141
|
createTime: Schema.Finite,
|
|
135
142
|
deploymentType: Schema.Literals(["dev", "prod", "preview", "custom"]),
|
|
136
143
|
projectId: Schema.Finite,
|
|
137
|
-
previewIdentifier: Schema.
|
|
144
|
+
previewIdentifier: Schema.String.pipe(Schema.NullOr, Schema.optionalKey),
|
|
138
145
|
};
|
|
139
146
|
|
|
140
147
|
const DeploymentSchema = Schema.Union([
|
|
@@ -142,8 +149,8 @@ const DeploymentSchema = Schema.Union([
|
|
|
142
149
|
...deploymentFields,
|
|
143
150
|
kind: Schema.Literal("cloud"),
|
|
144
151
|
id: Schema.Finite,
|
|
145
|
-
lastDeployTime: Schema.
|
|
146
|
-
creator: Schema.
|
|
152
|
+
lastDeployTime: Schema.Finite.pipe(Schema.NullOr, Schema.optionalKey),
|
|
153
|
+
creator: Schema.Finite.pipe(Schema.NullOr, Schema.optionalKey),
|
|
147
154
|
region: Schema.Literals([
|
|
148
155
|
"aws-us-east-1",
|
|
149
156
|
"aws-eu-west-1",
|
|
@@ -152,13 +159,14 @@ const DeploymentSchema = Schema.Union([
|
|
|
152
159
|
]),
|
|
153
160
|
isDefault: Schema.Boolean,
|
|
154
161
|
reference: Schema.String,
|
|
155
|
-
dashboardEditConfirmation: Schema.
|
|
156
|
-
Schema.NullOr
|
|
162
|
+
dashboardEditConfirmation: Schema.Boolean.pipe(
|
|
163
|
+
Schema.NullOr,
|
|
164
|
+
Schema.optionalKey,
|
|
157
165
|
),
|
|
158
166
|
deploymentUrl: Schema.String,
|
|
159
|
-
expiresAt: Schema.
|
|
167
|
+
expiresAt: Schema.Finite.pipe(Schema.NullOr, Schema.optionalKey),
|
|
160
168
|
class: Schema.String,
|
|
161
|
-
sendLogsToClient: Schema.
|
|
169
|
+
sendLogsToClient: Schema.Boolean.pipe(Schema.NullOr, Schema.optionalKey),
|
|
162
170
|
}),
|
|
163
171
|
Schema.Struct({
|
|
164
172
|
...deploymentFields,
|
|
@@ -174,17 +182,13 @@ const DeployKeySchema = Schema.Struct({
|
|
|
174
182
|
id: Schema.Finite,
|
|
175
183
|
name: Schema.String,
|
|
176
184
|
creationTime: Schema.Finite,
|
|
177
|
-
lastUsedTime: Schema.
|
|
178
|
-
expiresAt: Schema.
|
|
179
|
-
creator: Schema.
|
|
180
|
-
managedBy: Schema.
|
|
181
|
-
Schema.
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
Schema.Struct({ oauthApp: Schema.String }),
|
|
185
|
-
]),
|
|
186
|
-
),
|
|
187
|
-
),
|
|
185
|
+
lastUsedTime: Schema.Finite.pipe(Schema.NullOr, Schema.optionalKey),
|
|
186
|
+
expiresAt: Schema.Finite.pipe(Schema.NullOr, Schema.optionalKey),
|
|
187
|
+
creator: Schema.Finite.pipe(Schema.NullOr, Schema.optionalKey),
|
|
188
|
+
managedBy: Schema.Union([
|
|
189
|
+
Schema.Literal("vercel"),
|
|
190
|
+
Schema.Struct({ oauthApp: Schema.String }),
|
|
191
|
+
]).pipe(Schema.NullOr, Schema.optionalKey),
|
|
188
192
|
allowedActions: Schema.Array(Schema.String),
|
|
189
193
|
}) satisfies Schema.Schema<DeployKey>;
|
|
190
194
|
|
|
@@ -192,7 +196,7 @@ const ProjectsPageSchema = Schema.Struct({
|
|
|
192
196
|
items: Schema.Array(ProjectSchema),
|
|
193
197
|
pagination: Schema.Struct({
|
|
194
198
|
hasMore: Schema.Boolean,
|
|
195
|
-
nextCursor: Schema.
|
|
199
|
+
nextCursor: Schema.String.pipe(Schema.NullOr, Schema.optionalKey),
|
|
196
200
|
}),
|
|
197
201
|
});
|
|
198
202
|
|
|
@@ -205,12 +209,11 @@ const make = Effect.fn("ConvexClient.make")(function* (options?: {
|
|
|
205
209
|
const token =
|
|
206
210
|
options?.token ??
|
|
207
211
|
(yield* Config.Redacted("CONVEX_ACCESS_TOKEN").pipe(
|
|
208
|
-
Effect.mapError(
|
|
209
|
-
(
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
}),
|
|
212
|
+
Effect.mapError(() =>
|
|
213
|
+
ConvexApiError.make({
|
|
214
|
+
operation: "configure",
|
|
215
|
+
code: "InvalidConfiguration",
|
|
216
|
+
}),
|
|
214
217
|
),
|
|
215
218
|
));
|
|
216
219
|
return Redacted.make(`Bearer ${Redacted.value(token)}`);
|
|
@@ -233,8 +236,8 @@ const make = Effect.fn("ConvexClient.make")(function* (options?: {
|
|
|
233
236
|
);
|
|
234
237
|
if (body !== undefined) {
|
|
235
238
|
request = yield* HttpClientRequest.bodyJson(request, body).pipe(
|
|
236
|
-
Effect.mapError(
|
|
237
|
-
|
|
239
|
+
Effect.mapError(() =>
|
|
240
|
+
ConvexApiError.make({ operation, code: "InvalidRequest" }),
|
|
238
241
|
),
|
|
239
242
|
);
|
|
240
243
|
}
|
|
@@ -242,26 +245,26 @@ const make = Effect.fn("ConvexClient.make")(function* (options?: {
|
|
|
242
245
|
Effect.provideService(FetchHttpClient.RequestInit, {
|
|
243
246
|
redirect: "manual",
|
|
244
247
|
}),
|
|
245
|
-
Effect.mapError(
|
|
246
|
-
|
|
248
|
+
Effect.mapError(() =>
|
|
249
|
+
ConvexApiError.make({ operation, code: "TransportError" }),
|
|
247
250
|
),
|
|
248
251
|
);
|
|
249
252
|
if (response.status === 404) {
|
|
250
|
-
return yield*
|
|
253
|
+
return yield* ConvexNotFound.make({
|
|
251
254
|
operation,
|
|
252
255
|
status: 404,
|
|
253
256
|
code: "HttpError",
|
|
254
257
|
});
|
|
255
258
|
}
|
|
256
259
|
if (response.status === 409) {
|
|
257
|
-
return yield*
|
|
260
|
+
return yield* ConvexConflict.make({
|
|
258
261
|
operation,
|
|
259
262
|
status: 409,
|
|
260
263
|
code: "HttpError",
|
|
261
264
|
});
|
|
262
265
|
}
|
|
263
266
|
if (response.status < 200 || response.status >= 300) {
|
|
264
|
-
return yield*
|
|
267
|
+
return yield* ConvexApiError.make({
|
|
265
268
|
operation,
|
|
266
269
|
status: response.status,
|
|
267
270
|
code: "HttpError",
|
|
@@ -276,7 +279,7 @@ const make = Effect.fn("ConvexClient.make")(function* (options?: {
|
|
|
276
279
|
schema: Schema.Decoder<A>,
|
|
277
280
|
) {
|
|
278
281
|
const invalidResponse = () =>
|
|
279
|
-
|
|
282
|
+
ConvexApiError.make({
|
|
280
283
|
operation,
|
|
281
284
|
status: response.status,
|
|
282
285
|
code: "InvalidResponse",
|
|
@@ -294,11 +297,12 @@ const make = Effect.fn("ConvexClient.make")(function* (options?: {
|
|
|
294
297
|
schema: Schema.Decoder<A>,
|
|
295
298
|
body?: unknown,
|
|
296
299
|
) {
|
|
300
|
+
const managementAuthorizationValue = yield* managementAuthorization;
|
|
297
301
|
const response = yield* send(
|
|
298
302
|
operation,
|
|
299
303
|
method,
|
|
300
304
|
`${baseUrl}${path}`,
|
|
301
|
-
|
|
305
|
+
managementAuthorizationValue,
|
|
302
306
|
body,
|
|
303
307
|
);
|
|
304
308
|
return yield* decode(operation, response, schema);
|
|
@@ -310,11 +314,12 @@ const make = Effect.fn("ConvexClient.make")(function* (options?: {
|
|
|
310
314
|
path: string,
|
|
311
315
|
body?: unknown,
|
|
312
316
|
) {
|
|
317
|
+
const managementAuthorizationValue = yield* managementAuthorization;
|
|
313
318
|
yield* send(
|
|
314
319
|
operation,
|
|
315
320
|
method,
|
|
316
321
|
`${baseUrl}${path}`,
|
|
317
|
-
|
|
322
|
+
managementAuthorizationValue,
|
|
318
323
|
body,
|
|
319
324
|
);
|
|
320
325
|
});
|
|
@@ -324,7 +329,7 @@ const make = Effect.fn("ConvexClient.make")(function* (options?: {
|
|
|
324
329
|
url: string,
|
|
325
330
|
) {
|
|
326
331
|
const invalidUrl = () =>
|
|
327
|
-
|
|
332
|
+
ConvexApiError.make({ operation, code: "InvalidRequest" });
|
|
328
333
|
if (options?.mode === "local") {
|
|
329
334
|
if (!Loopback.isOrigin(url)) return yield* invalidUrl();
|
|
330
335
|
return `${url}/api/v1`;
|
|
@@ -344,7 +349,7 @@ const make = Effect.fn("ConvexClient.make")(function* (options?: {
|
|
|
344
349
|
!/^[a-z0-9-]+(?:\.(?:eu-west-1|ap-southeast-2|ca-central-1))?\.convex\.cloud$/.test(
|
|
345
350
|
parsed.hostname,
|
|
346
351
|
) ||
|
|
347
|
-
url.replace(/\/$/, "") !== parsed.origin
|
|
352
|
+
pipe(url, String.replace(/\/$/, "")) !== parsed.origin
|
|
348
353
|
) {
|
|
349
354
|
return yield* invalidUrl();
|
|
350
355
|
}
|
|
@@ -364,9 +369,10 @@ const make = Effect.fn("ConvexClient.make")(function* (options?: {
|
|
|
364
369
|
componentPath?: string,
|
|
365
370
|
) {
|
|
366
371
|
const operation = "runFunction";
|
|
367
|
-
const
|
|
368
|
-
|
|
369
|
-
|
|
372
|
+
const deploymentUrlResult = yield* deploymentUrl(operation, url);
|
|
373
|
+
const origin = pipe(
|
|
374
|
+
deploymentUrlResult,
|
|
375
|
+
String.replace(/\/api\/v1$/, ""),
|
|
370
376
|
);
|
|
371
377
|
const request = yield* HttpClientRequest.post(
|
|
372
378
|
`${origin}/api/function`,
|
|
@@ -382,28 +388,28 @@ const make = Effect.fn("ConvexClient.make")(function* (options?: {
|
|
|
382
388
|
format: "json",
|
|
383
389
|
...(componentPath === undefined ? {} : { componentPath }),
|
|
384
390
|
}),
|
|
385
|
-
Effect.mapError(
|
|
386
|
-
|
|
391
|
+
Effect.mapError(() =>
|
|
392
|
+
ConvexApiError.make({ operation, code: "InvalidRequest" }),
|
|
387
393
|
),
|
|
388
394
|
);
|
|
389
395
|
const response = yield* http.execute(request).pipe(
|
|
390
396
|
Effect.provideService(FetchHttpClient.RequestInit, {
|
|
391
397
|
redirect: "manual",
|
|
392
398
|
}),
|
|
393
|
-
Effect.mapError(
|
|
394
|
-
|
|
399
|
+
Effect.mapError(() =>
|
|
400
|
+
ConvexApiError.make({ operation, code: "TransportError" }),
|
|
395
401
|
),
|
|
396
402
|
);
|
|
397
403
|
// Convex answers a function that threw with 560 and its message.
|
|
398
404
|
if (response.status !== 200 && response.status !== 560)
|
|
399
|
-
return yield*
|
|
405
|
+
return yield* ConvexApiError.make({
|
|
400
406
|
operation,
|
|
401
407
|
status: response.status,
|
|
402
408
|
code: "HttpError",
|
|
403
409
|
});
|
|
404
410
|
const result = yield* decode(operation, response, FunctionResponse);
|
|
405
411
|
if (result.status === "error")
|
|
406
|
-
return yield*
|
|
412
|
+
return yield* ConvexFunctionError.make({
|
|
407
413
|
functionPath,
|
|
408
414
|
errorMessage: result.errorMessage,
|
|
409
415
|
});
|
|
@@ -425,8 +431,13 @@ const make = Effect.fn("ConvexClient.make")(function* (options?: {
|
|
|
425
431
|
projects.push(...page.items);
|
|
426
432
|
if (!page.pagination.hasMore) return projects;
|
|
427
433
|
const nextCursor = page.pagination.nextCursor;
|
|
428
|
-
if (
|
|
429
|
-
|
|
434
|
+
if (
|
|
435
|
+
nextCursor === undefined ||
|
|
436
|
+
nextCursor === null ||
|
|
437
|
+
nextCursor === "" ||
|
|
438
|
+
seenCursors.has(nextCursor)
|
|
439
|
+
) {
|
|
440
|
+
return yield* ConvexApiError.make({
|
|
430
441
|
operation: "listProjects",
|
|
431
442
|
code: "InvalidPagination",
|
|
432
443
|
});
|
|
@@ -561,11 +572,11 @@ const make = Effect.fn("ConvexClient.make")(function* (options?: {
|
|
|
561
572
|
environmentVariables: Schema.Record(Schema.String, Schema.String),
|
|
562
573
|
}),
|
|
563
574
|
);
|
|
564
|
-
return
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
Redacted.make(value),
|
|
568
|
-
|
|
575
|
+
return Rec.fromEntries(
|
|
576
|
+
Array.map(
|
|
577
|
+
Rec.toEntries(result.environmentVariables),
|
|
578
|
+
([name, value]) => [name, Redacted.make(value)],
|
|
579
|
+
),
|
|
569
580
|
);
|
|
570
581
|
}),
|
|
571
582
|
updateEnvironmentVariables: Effect.fn(
|
|
@@ -581,7 +592,7 @@ const make = Effect.fn("ConvexClient.make")(function* (options?: {
|
|
|
581
592
|
`${yield* deploymentUrl("updateEnvironmentVariables", url)}/update_environment_variables`,
|
|
582
593
|
Redacted.make(`Convex ${Redacted.value(key)}`),
|
|
583
594
|
{
|
|
584
|
-
changes:
|
|
595
|
+
changes: Array.map(changes, ({ name, value }) => ({
|
|
585
596
|
name,
|
|
586
597
|
...(value === undefined
|
|
587
598
|
? {}
|
|
@@ -609,6 +620,8 @@ export class ConvexClient extends Context.Service<
|
|
|
609
620
|
/**
|
|
610
621
|
* `mode: "local"` sends deployment requests only to a loopback backend over
|
|
611
622
|
* HTTP; the default accepts only Convex cloud HTTPS origins.
|
|
623
|
+
*
|
|
624
|
+
* @stability unstable
|
|
612
625
|
*/
|
|
613
626
|
export const layer = (options?: {
|
|
614
627
|
readonly token?: Redacted.Redacted<string>;
|
package/src/DeployKey.ts
CHANGED
|
@@ -13,6 +13,10 @@ import type { Providers } from "./Providers.js";
|
|
|
13
13
|
import { resourceName } from "./internal/ResourceIdentity.js";
|
|
14
14
|
import { checkpointCreate } from "./internal/Lifecycle.js";
|
|
15
15
|
import { adminKey, dataDirectories } from "./internal/LocalBackend.js";
|
|
16
|
+
import * as String from "effect/String";
|
|
17
|
+
import { pipe } from "effect/Function";
|
|
18
|
+
import * as Option from "effect/Option";
|
|
19
|
+
import * as Array from "effect/Array";
|
|
16
20
|
|
|
17
21
|
export interface DeployKeyProps {
|
|
18
22
|
readonly deploymentName: string;
|
|
@@ -39,50 +43,57 @@ export type DeployKey = Resource<
|
|
|
39
43
|
>;
|
|
40
44
|
export const DeployKey = Resource<DeployKey>("Convex.DeployKey");
|
|
41
45
|
|
|
42
|
-
export class DeployKeyRecoveryRequired extends Schema.TaggedError<
|
|
43
|
-
|
|
44
|
-
{
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
) {}
|
|
46
|
+
export class DeployKeyRecoveryRequired extends Schema.TaggedError<
|
|
47
|
+
DeployKeyRecoveryRequired,
|
|
48
|
+
{ readonly brand: unique symbol }
|
|
49
|
+
>()("DeployKeyRecoveryRequired", {
|
|
50
|
+
deploymentName: Schema.String,
|
|
51
|
+
keyName: Schema.String,
|
|
52
|
+
keyIds: Schema.Array(Schema.Finite),
|
|
53
|
+
}) {}
|
|
50
54
|
|
|
51
|
-
export class DeployKeyChangeRequiresNewResource extends Schema.TaggedError<
|
|
52
|
-
|
|
53
|
-
{
|
|
54
|
-
) {
|
|
55
|
+
export class DeployKeyChangeRequiresNewResource extends Schema.TaggedError<
|
|
56
|
+
DeployKeyChangeRequiresNewResource,
|
|
57
|
+
{ readonly brand: unique symbol }
|
|
58
|
+
>()("DeployKeyChangeRequiresNewResource", {
|
|
59
|
+
deploymentName: Schema.String,
|
|
60
|
+
keyId: Schema.Finite,
|
|
61
|
+
field: Schema.String,
|
|
62
|
+
}) {}
|
|
55
63
|
|
|
56
64
|
export const provider = Effect.gen(function* () {
|
|
57
65
|
const client = yield* ConvexClient;
|
|
58
66
|
const hasName = (keyName: string, name: string) =>
|
|
59
67
|
keyName === name ||
|
|
60
|
-
(keyName.startsWith(`${name} (`) &&
|
|
61
|
-
/^[0-9a-f]{8}\)$/.test(keyName.slice(name.length + 2)));
|
|
68
|
+
(pipe(keyName, String.startsWith(`${name} (`)) &&
|
|
69
|
+
/^[0-9a-f]{8}\)$/.test(pipe(keyName, String.slice(name.length + 2))));
|
|
62
70
|
const recover = (
|
|
63
71
|
deploymentName: string,
|
|
64
72
|
name: string,
|
|
65
73
|
keyIds: ReadonlyArray<number>,
|
|
66
|
-
) =>
|
|
74
|
+
) =>
|
|
75
|
+
DeployKeyRecoveryRequired.make({ deploymentName, keyName: name, keyIds });
|
|
67
76
|
return {
|
|
68
77
|
diff: Effect.fn("DeployKey.diff")(function* ({ news, output }) {
|
|
69
|
-
if (!isResolved(news) ||
|
|
78
|
+
if (!isResolved(news) || output === undefined) return;
|
|
70
79
|
for (const field of ["deploymentName", "name"] as const) {
|
|
71
80
|
if (news[field] !== undefined && news[field] !== output[field])
|
|
72
|
-
return yield*
|
|
81
|
+
return yield* DeployKeyChangeRequiresNewResource.make({
|
|
73
82
|
deploymentName: output.deploymentName,
|
|
74
83
|
keyId: output.keyId,
|
|
75
84
|
field,
|
|
76
85
|
});
|
|
77
86
|
}
|
|
78
87
|
const keys = yield* client.listDeployKeys(output.deploymentName);
|
|
79
|
-
const key =
|
|
80
|
-
|
|
88
|
+
const key = Option.getOrUndefined(
|
|
89
|
+
Array.findFirst(keys, (candidate) => candidate.id === output.keyId),
|
|
90
|
+
);
|
|
91
|
+
if (key === undefined || !Redacted.isRedacted(output.deployKey))
|
|
81
92
|
return yield* recover(output.deploymentName, output.name, [
|
|
82
93
|
output.keyId,
|
|
83
94
|
]);
|
|
84
95
|
if (!hasName(key.name, news.name ?? output.name))
|
|
85
|
-
return yield*
|
|
96
|
+
return yield* DeployKeyChangeRequiresNewResource.make({
|
|
86
97
|
deploymentName: output.deploymentName,
|
|
87
98
|
keyId: output.keyId,
|
|
88
99
|
field: "name",
|
|
@@ -90,9 +101,12 @@ export const provider = Effect.gen(function* () {
|
|
|
90
101
|
const allowedActions = news.allowedActions ?? output.allowedActions;
|
|
91
102
|
if (
|
|
92
103
|
new Set(allowedActions).size !== new Set(key.allowedActions).size ||
|
|
93
|
-
|
|
104
|
+
Array.some(
|
|
105
|
+
allowedActions,
|
|
106
|
+
(action) => !key.allowedActions.includes(action),
|
|
107
|
+
)
|
|
94
108
|
)
|
|
95
|
-
return yield*
|
|
109
|
+
return yield* DeployKeyChangeRequiresNewResource.make({
|
|
96
110
|
deploymentName: output.deploymentName,
|
|
97
111
|
keyId: output.keyId,
|
|
98
112
|
field: "allowedActions",
|
|
@@ -111,9 +125,12 @@ export const provider = Effect.gen(function* () {
|
|
|
111
125
|
olds.name ??
|
|
112
126
|
(yield* resourceName("key", fqn, instanceId));
|
|
113
127
|
const keys = yield* client.listDeployKeys(deploymentName);
|
|
114
|
-
if (output) {
|
|
115
|
-
const key =
|
|
116
|
-
|
|
128
|
+
if (output !== undefined) {
|
|
129
|
+
const key = Option.getOrUndefined(
|
|
130
|
+
Array.findFirst(keys, (candidate) => candidate.id === output.keyId),
|
|
131
|
+
);
|
|
132
|
+
if (key === undefined)
|
|
133
|
+
return yield* recover(deploymentName, name, [output.keyId]);
|
|
117
134
|
if (!Redacted.isRedacted(output.deployKey))
|
|
118
135
|
return yield* recover(deploymentName, name, [key.id]);
|
|
119
136
|
return {
|
|
@@ -121,12 +138,12 @@ export const provider = Effect.gen(function* () {
|
|
|
121
138
|
allowedActions: key.allowedActions,
|
|
122
139
|
};
|
|
123
140
|
}
|
|
124
|
-
const matches =
|
|
141
|
+
const matches = Array.filter(keys, (key) => hasName(key.name, name));
|
|
125
142
|
if (matches.length > 0)
|
|
126
143
|
return yield* recover(
|
|
127
144
|
deploymentName,
|
|
128
145
|
name,
|
|
129
|
-
|
|
146
|
+
Array.map(matches, (candidate) => candidate.id),
|
|
130
147
|
);
|
|
131
148
|
return undefined;
|
|
132
149
|
}),
|
|
@@ -136,26 +153,28 @@ export const provider = Effect.gen(function* () {
|
|
|
136
153
|
news,
|
|
137
154
|
output,
|
|
138
155
|
}) {
|
|
139
|
-
if (
|
|
156
|
+
if (output === undefined) yield* checkpointCreate(fqn, instanceId, news);
|
|
140
157
|
const name =
|
|
141
158
|
news.name ??
|
|
142
159
|
output?.name ??
|
|
143
160
|
(yield* resourceName("key", fqn, instanceId));
|
|
144
|
-
if (output) {
|
|
161
|
+
if (output !== undefined) {
|
|
145
162
|
for (const field of ["deploymentName", "name"] as const) {
|
|
146
163
|
if (news[field] !== undefined && news[field] !== output[field])
|
|
147
|
-
return yield*
|
|
164
|
+
return yield* DeployKeyChangeRequiresNewResource.make({
|
|
148
165
|
deploymentName: output.deploymentName,
|
|
149
166
|
keyId: output.keyId,
|
|
150
167
|
field,
|
|
151
168
|
});
|
|
152
169
|
}
|
|
153
170
|
const keys = yield* client.listDeployKeys(output.deploymentName);
|
|
154
|
-
const key =
|
|
155
|
-
|
|
171
|
+
const key = Option.getOrUndefined(
|
|
172
|
+
Array.findFirst(keys, (candidate) => candidate.id === output.keyId),
|
|
173
|
+
);
|
|
174
|
+
if (key === undefined || !Redacted.isRedacted(output.deployKey))
|
|
156
175
|
return yield* recover(output.deploymentName, name, [output.keyId]);
|
|
157
176
|
if (!hasName(key.name, name))
|
|
158
|
-
return yield*
|
|
177
|
+
return yield* DeployKeyChangeRequiresNewResource.make({
|
|
159
178
|
deploymentName: output.deploymentName,
|
|
160
179
|
keyId: output.keyId,
|
|
161
180
|
field: "name",
|
|
@@ -163,9 +182,12 @@ export const provider = Effect.gen(function* () {
|
|
|
163
182
|
const allowedActions = news.allowedActions ?? output.allowedActions;
|
|
164
183
|
if (
|
|
165
184
|
new Set(allowedActions).size !== new Set(key.allowedActions).size ||
|
|
166
|
-
|
|
185
|
+
Array.some(
|
|
186
|
+
allowedActions,
|
|
187
|
+
(action) => !key.allowedActions.includes(action),
|
|
188
|
+
)
|
|
167
189
|
)
|
|
168
|
-
return yield*
|
|
190
|
+
return yield* DeployKeyChangeRequiresNewResource.make({
|
|
169
191
|
deploymentName: output.deploymentName,
|
|
170
192
|
keyId: output.keyId,
|
|
171
193
|
field: "allowedActions",
|
|
@@ -175,14 +197,15 @@ export const provider = Effect.gen(function* () {
|
|
|
175
197
|
allowedActions: key.allowedActions,
|
|
176
198
|
};
|
|
177
199
|
}
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
|
|
200
|
+
const deployKeys = yield* client.listDeployKeys(news.deploymentName);
|
|
201
|
+
const existing = Array.filter(deployKeys, (key) =>
|
|
202
|
+
hasName(key.name, name),
|
|
203
|
+
);
|
|
181
204
|
if (existing.length > 0)
|
|
182
205
|
return yield* recover(
|
|
183
206
|
news.deploymentName,
|
|
184
207
|
name,
|
|
185
|
-
|
|
208
|
+
Array.map(existing, (key) => key.id),
|
|
186
209
|
);
|
|
187
210
|
const created = yield* client.createDeployKey(news.deploymentName, {
|
|
188
211
|
name,
|
|
@@ -190,15 +213,16 @@ export const provider = Effect.gen(function* () {
|
|
|
190
213
|
? {}
|
|
191
214
|
: { allowedActions: [...news.allowedActions] }),
|
|
192
215
|
});
|
|
193
|
-
const
|
|
194
|
-
|
|
195
|
-
|
|
216
|
+
const deployKeys2 = yield* client.listDeployKeys(news.deploymentName);
|
|
217
|
+
const matches = Array.filter(deployKeys2, (key) =>
|
|
218
|
+
hasName(key.name, name),
|
|
219
|
+
);
|
|
196
220
|
const key = matches[0];
|
|
197
|
-
if (matches.length !== 1 ||
|
|
221
|
+
if (matches.length !== 1 || key === undefined)
|
|
198
222
|
return yield* recover(
|
|
199
223
|
news.deploymentName,
|
|
200
224
|
name,
|
|
201
|
-
|
|
225
|
+
Array.map(matches, (candidate) => candidate.id),
|
|
202
226
|
);
|
|
203
227
|
return {
|
|
204
228
|
deploymentName: news.deploymentName,
|
|
@@ -220,6 +244,8 @@ export const provider = Effect.gen(function* () {
|
|
|
220
244
|
* Under `alchemy dev` the deploy key is the admin key the local deployment
|
|
221
245
|
* generated. It is read on every apply, so a recreated backend's new key
|
|
222
246
|
* replaces the old one.
|
|
247
|
+
*
|
|
248
|
+
* @stability unstable
|
|
223
249
|
*/
|
|
224
250
|
export const localProvider = Effect.gen(function* () {
|
|
225
251
|
const fs = yield* FileSystem.FileSystem;
|
|
@@ -253,4 +279,7 @@ export const localProvider = Effect.gen(function* () {
|
|
|
253
279
|
});
|
|
254
280
|
|
|
255
281
|
export const layer = Provider.effect(DeployKey, provider);
|
|
282
|
+
/**
|
|
283
|
+
* @stability unstable
|
|
284
|
+
*/
|
|
256
285
|
export const localLayer = Provider.effect(DeployKey, localProvider);
|