@gaganref/confect-alchemy 10.3.1-fork.95 → 10.6.0-fork.1

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.
Files changed (106) hide show
  1. package/README.md +1 -1
  2. package/dist/Backend.d.ts.map +1 -1
  3. package/dist/Backend.js +2 -3
  4. package/dist/Backend.js.map +1 -1
  5. package/dist/Code.d.ts +16 -3
  6. package/dist/Code.d.ts.map +1 -1
  7. package/dist/Code.js +13 -3
  8. package/dist/Code.js.map +1 -1
  9. package/dist/Confect.d.ts.map +1 -1
  10. package/dist/Confect.js +1 -2
  11. package/dist/Convex.d.ts.map +1 -1
  12. package/dist/Convex.js +3 -4
  13. package/dist/ConvexClient.d.ts +14 -4
  14. package/dist/ConvexClient.d.ts.map +1 -1
  15. package/dist/ConvexClient.js +44 -36
  16. package/dist/ConvexClient.js.map +1 -1
  17. package/dist/DeployKey.d.ts +22 -12
  18. package/dist/DeployKey.d.ts.map +1 -1
  19. package/dist/DeployKey.js +41 -29
  20. package/dist/DeployKey.js.map +1 -1
  21. package/dist/Deployment.d.ts +19 -10
  22. package/dist/Deployment.d.ts.map +1 -1
  23. package/dist/Deployment.js +22 -19
  24. package/dist/Deployment.js.map +1 -1
  25. package/dist/EnvironmentVariables.d.ts +23 -31
  26. package/dist/EnvironmentVariables.d.ts.map +1 -1
  27. package/dist/EnvironmentVariables.js +21 -20
  28. package/dist/EnvironmentVariables.js.map +1 -1
  29. package/dist/Project.d.ts +15 -10
  30. package/dist/Project.d.ts.map +1 -1
  31. package/dist/Project.js +23 -22
  32. package/dist/Project.js.map +1 -1
  33. package/dist/Providers.d.ts +3 -1
  34. package/dist/Providers.d.ts.map +1 -1
  35. package/dist/Providers.js +19 -18
  36. package/dist/Providers.js.map +1 -1
  37. package/dist/_virtual/_rolldown/runtime.js +5 -6
  38. package/dist/index.d.ts +3 -0
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +1 -1
  41. package/dist/internal/CodeDeployment.d.ts +6 -1
  42. package/dist/internal/CodeDeployment.d.ts.map +1 -1
  43. package/dist/internal/CodeDeployment.js +10 -8
  44. package/dist/internal/CodeDeployment.js.map +1 -1
  45. package/dist/internal/CommandRunner.d.ts +6 -1
  46. package/dist/internal/CommandRunner.d.ts.map +1 -1
  47. package/dist/internal/CommandRunner.js +11 -9
  48. package/dist/internal/CommandRunner.js.map +1 -1
  49. package/dist/internal/FileLock.d.ts +7 -3
  50. package/dist/internal/FileLock.d.ts.map +1 -1
  51. package/dist/internal/FileLock.js +10 -8
  52. package/dist/internal/FileLock.js.map +1 -1
  53. package/dist/internal/Lifecycle.d.ts +3 -1
  54. package/dist/internal/Lifecycle.d.ts.map +1 -1
  55. package/dist/internal/Lifecycle.js +3 -4
  56. package/dist/internal/Lifecycle.js.map +1 -1
  57. package/dist/internal/LocalBackend.d.ts +7 -3
  58. package/dist/internal/LocalBackend.d.ts.map +1 -1
  59. package/dist/internal/LocalBackend.js +26 -18
  60. package/dist/internal/LocalBackend.js.map +1 -1
  61. package/dist/internal/LocalSidecar.d.ts +4 -1
  62. package/dist/internal/LocalSidecar.d.ts.map +1 -1
  63. package/dist/internal/LocalSidecar.js +4 -2
  64. package/dist/internal/LocalSidecar.js.map +1 -1
  65. package/dist/internal/Loopback.d.ts.map +1 -1
  66. package/dist/internal/Loopback.js +1 -2
  67. package/dist/internal/MountInit.d.ts +5 -1
  68. package/dist/internal/MountInit.d.ts.map +1 -1
  69. package/dist/internal/MountInit.js +5 -4
  70. package/dist/internal/MountInit.js.map +1 -1
  71. package/dist/internal/PushLock.d.ts +7 -3
  72. package/dist/internal/PushLock.d.ts.map +1 -1
  73. package/dist/internal/PushLock.js +7 -6
  74. package/dist/internal/PushLock.js.map +1 -1
  75. package/dist/internal/ResourceIdentity.d.ts.map +1 -1
  76. package/dist/internal/ResourceIdentity.js +5 -3
  77. package/dist/internal/ResourceIdentity.js.map +1 -1
  78. package/dist/internal/UserCache.d.ts +2 -0
  79. package/dist/internal/UserCache.d.ts.map +1 -1
  80. package/dist/internal/UserCache.js +5 -4
  81. package/dist/internal/UserCache.js.map +1 -1
  82. package/dist/internal/Zip.d.ts +5 -1
  83. package/dist/internal/Zip.d.ts.map +1 -1
  84. package/dist/internal/Zip.js +9 -8
  85. package/dist/internal/Zip.js.map +1 -1
  86. package/package.json +5 -5
  87. package/src/Backend.ts +7 -6
  88. package/src/Code.ts +11 -0
  89. package/src/ConvexClient.ts +87 -74
  90. package/src/DeployKey.ts +73 -44
  91. package/src/Deployment.ts +50 -37
  92. package/src/EnvironmentVariables.ts +30 -27
  93. package/src/Project.ts +42 -41
  94. package/src/Providers.ts +2 -0
  95. package/src/index.ts +3 -0
  96. package/src/internal/CodeDeployment.ts +17 -11
  97. package/src/internal/CommandRunner.ts +27 -26
  98. package/src/internal/FileLock.ts +15 -12
  99. package/src/internal/Lifecycle.ts +11 -7
  100. package/src/internal/LocalBackend.ts +45 -39
  101. package/src/internal/LocalSidecar.ts +3 -0
  102. package/src/internal/MountInit.ts +8 -6
  103. package/src/internal/PushLock.ts +13 -11
  104. package/src/internal/ResourceIdentity.ts +12 -5
  105. package/src/internal/UserCache.ts +13 -4
  106. package/src/internal/Zip.ts +13 -8
@@ -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<ConvexApiError>()(
78
- "ConvexApiError",
79
- errorFields,
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<ConvexNotFound>()(
83
- "ConvexNotFound",
84
- errorFields,
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<ConvexConflict>()(
88
- "ConvexConflict",
89
- errorFields,
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<ConvexFunctionError>()(
96
- "ConvexFunctionError",
97
- { functionPath: Schema.String, errorMessage: Schema.String },
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.optionalKey(Schema.NullOr(Schema.String)),
121
- devDeploymentName: Schema.optionalKey(Schema.NullOr(Schema.String)),
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.optionalKey(Schema.NullOr(Schema.String)),
129
- deploymentUrl: Schema.optionalKey(Schema.NullOr(Schema.String)),
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.optionalKey(Schema.NullOr(Schema.String)),
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.optionalKey(Schema.NullOr(Schema.Finite)),
146
- creator: Schema.optionalKey(Schema.NullOr(Schema.Finite)),
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.optionalKey(
156
- Schema.NullOr(Schema.Boolean),
162
+ dashboardEditConfirmation: Schema.Boolean.pipe(
163
+ Schema.NullOr,
164
+ Schema.optionalKey,
157
165
  ),
158
166
  deploymentUrl: Schema.String,
159
- expiresAt: Schema.optionalKey(Schema.NullOr(Schema.Finite)),
167
+ expiresAt: Schema.Finite.pipe(Schema.NullOr, Schema.optionalKey),
160
168
  class: Schema.String,
161
- sendLogsToClient: Schema.optionalKey(Schema.NullOr(Schema.Boolean)),
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.optionalKey(Schema.NullOr(Schema.Finite)),
178
- expiresAt: Schema.optionalKey(Schema.NullOr(Schema.Finite)),
179
- creator: Schema.optionalKey(Schema.NullOr(Schema.Finite)),
180
- managedBy: Schema.optionalKey(
181
- Schema.NullOr(
182
- Schema.Union([
183
- Schema.Literal("vercel"),
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.optionalKey(Schema.NullOr(Schema.String)),
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
- new ConvexApiError({
211
- operation: "configure",
212
- code: "InvalidConfiguration",
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
- () => new ConvexApiError({ operation, code: "InvalidRequest" }),
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
- () => new ConvexApiError({ operation, code: "TransportError" }),
248
+ Effect.mapError(() =>
249
+ ConvexApiError.make({ operation, code: "TransportError" }),
247
250
  ),
248
251
  );
249
252
  if (response.status === 404) {
250
- return yield* new ConvexNotFound({
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* new ConvexConflict({
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* new ConvexApiError({
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
- new ConvexApiError({
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
- yield* managementAuthorization,
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
- yield* managementAuthorization,
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
- new ConvexApiError({ operation, code: "InvalidRequest" });
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 origin = (yield* deploymentUrl(operation, url)).replace(
368
- /\/api\/v1$/,
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
- () => new ConvexApiError({ operation, code: "InvalidRequest" }),
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
- () => new ConvexApiError({ operation, code: "TransportError" }),
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* new ConvexApiError({
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* new ConvexFunctionError({
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 (!nextCursor || seenCursors.has(nextCursor)) {
429
- return yield* new ConvexApiError({
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 Object.fromEntries(
565
- Object.entries(result.environmentVariables).map(([name, value]) => [
566
- name,
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: changes.map(({ name, value }) => ({
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<DeployKeyRecoveryRequired>()(
43
- "DeployKeyRecoveryRequired",
44
- {
45
- deploymentName: Schema.String,
46
- name: Schema.String,
47
- keyIds: Schema.Array(Schema.Finite),
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<DeployKeyChangeRequiresNewResource>()(
52
- "DeployKeyChangeRequiresNewResource",
53
- { deploymentName: Schema.String, keyId: Schema.Finite, field: Schema.String },
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
- ) => new DeployKeyRecoveryRequired({ deploymentName, name, keyIds });
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) || !output) return;
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* new DeployKeyChangeRequiresNewResource({
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 = keys.find((candidate) => candidate.id === output.keyId);
80
- if (!key || !Redacted.isRedacted(output.deployKey))
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* new DeployKeyChangeRequiresNewResource({
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
- allowedActions.some((action) => !key.allowedActions.includes(action))
104
+ Array.some(
105
+ allowedActions,
106
+ (action) => !key.allowedActions.includes(action),
107
+ )
94
108
  )
95
- return yield* new DeployKeyChangeRequiresNewResource({
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 = keys.find((candidate) => candidate.id === output.keyId);
116
- if (!key) return yield* recover(deploymentName, name, [output.keyId]);
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 = keys.filter((key) => hasName(key.name, name));
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
- matches.map((candidate) => candidate.id),
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 (!output) yield* checkpointCreate(fqn, instanceId, news);
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* new DeployKeyChangeRequiresNewResource({
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 = keys.find((candidate) => candidate.id === output.keyId);
155
- if (!key || !Redacted.isRedacted(output.deployKey))
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* new DeployKeyChangeRequiresNewResource({
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
- allowedActions.some((action) => !key.allowedActions.includes(action))
185
+ Array.some(
186
+ allowedActions,
187
+ (action) => !key.allowedActions.includes(action),
188
+ )
167
189
  )
168
- return yield* new DeployKeyChangeRequiresNewResource({
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 existing = (yield* client.listDeployKeys(
179
- news.deploymentName,
180
- )).filter((key) => hasName(key.name, name));
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
- existing.map((key) => key.id),
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 matches = (yield* client.listDeployKeys(
194
- news.deploymentName,
195
- )).filter((key) => hasName(key.name, name));
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 || !key)
221
+ if (matches.length !== 1 || key === undefined)
198
222
  return yield* recover(
199
223
  news.deploymentName,
200
224
  name,
201
- matches.map((candidate) => candidate.id),
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);