@gaganref/confect-alchemy 10.3.1-fork.96 → 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
@@ -35,14 +35,14 @@ const selection = (target: PushTarget) =>
35
35
  ? `CONVEX_DEPLOY_KEY=${Redacted.value(target.deployKey)}\n`
36
36
  : `CONVEX_SELF_HOSTED_URL=${target.url}\nCONVEX_SELF_HOSTED_ADMIN_KEY=${Redacted.value(target.adminKey)}\n`;
37
37
 
38
- export class CommandError extends Schema.TaggedError<CommandError>()(
39
- "CommandError",
40
- {
41
- operation: Schema.Literals(["prepare", "deploy"]),
42
- reason: Schema.Literals(["configuration", "spawn", "exit"]),
43
- exitCode: Schema.optionalKey(Schema.Finite),
44
- },
45
- ) {}
38
+ export class CommandError extends Schema.TaggedError<
39
+ CommandError,
40
+ { readonly brand: unique symbol }
41
+ >()("CommandError", {
42
+ operation: Schema.Literals(["prepare", "deploy"]),
43
+ reason: Schema.Literals(["configuration", "spawn", "exit"]),
44
+ exitCode: Schema.optionalKey(Schema.Finite),
45
+ }) {}
46
46
 
47
47
  export class CommandRunner extends Context.Service<
48
48
  CommandRunner,
@@ -85,7 +85,7 @@ const packageBin = Effect.fn("CommandRunner.packageBin")(function* (
85
85
  binName: string,
86
86
  ) {
87
87
  const invalid = () =>
88
- new CommandError({
88
+ CommandError.make({
89
89
  operation: packageName === "convex" ? "deploy" : "prepare",
90
90
  reason: "configuration",
91
91
  });
@@ -115,7 +115,7 @@ const packageBin = Effect.fn("CommandRunner.packageBin")(function* (
115
115
  );
116
116
  const relative =
117
117
  typeof manifest.bin === "string" ? manifest.bin : manifest.bin[binName];
118
- if (!relative) return yield* invalid();
118
+ if (relative === undefined || relative === "") return yield* invalid();
119
119
  return path.resolve(path.dirname(manifestPath), relative);
120
120
  }
121
121
  const parent = path.dirname(directory);
@@ -124,6 +124,9 @@ const packageBin = Effect.fn("CommandRunner.packageBin")(function* (
124
124
  }
125
125
  });
126
126
 
127
+ /**
128
+ * @internal
129
+ */
127
130
  export const layer = Layer.effect(
128
131
  CommandRunner,
129
132
  Effect.gen(function* () {
@@ -149,12 +152,12 @@ export const layer = Layer.effect(
149
152
  }),
150
153
  )
151
154
  .pipe(
152
- Effect.mapError(
153
- () => new CommandError({ operation, reason: "spawn" }),
155
+ Effect.mapError(() =>
156
+ CommandError.make({ operation, reason: "spawn" }),
154
157
  ),
155
158
  );
156
159
  if (code !== 0)
157
- return yield* new CommandError({
160
+ return yield* CommandError.make({
158
161
  operation,
159
162
  reason: "exit",
160
163
  exitCode: Number(code),
@@ -170,12 +173,11 @@ export const layer = Layer.effect(
170
173
  ) {
171
174
  const directory = path.resolve(cwd);
172
175
  const env = yield* environment.pipe(
173
- Effect.mapError(
174
- () =>
175
- new CommandError({
176
- operation: "prepare",
177
- reason: "configuration",
178
- }),
176
+ Effect.mapError(() =>
177
+ CommandError.make({
178
+ operation: "prepare",
179
+ reason: "configuration",
180
+ }),
179
181
  ),
180
182
  );
181
183
  if (command.command === "confect") {
@@ -204,12 +206,11 @@ export const layer = Layer.effect(
204
206
  const directory = path.resolve(cwd);
205
207
  const bin = yield* packageBin(fs, path, directory, "convex", "convex");
206
208
  const env = yield* environment.pipe(
207
- Effect.mapError(
208
- () =>
209
- new CommandError({
210
- operation: "deploy",
211
- reason: "configuration",
212
- }),
209
+ Effect.mapError(() =>
210
+ CommandError.make({
211
+ operation: "deploy",
212
+ reason: "configuration",
213
+ }),
213
214
  ),
214
215
  );
215
216
  yield* Effect.scoped(
@@ -238,7 +239,7 @@ export const layer = Layer.effect(
238
239
  Effect.mapError((error) =>
239
240
  Schema.is(CommandError)(error)
240
241
  ? error
241
- : new CommandError({
242
+ : CommandError.make({
242
243
  operation: "deploy",
243
244
  reason: "configuration",
244
245
  }),
@@ -1,4 +1,4 @@
1
- import * as Crypto from "effect/Crypto";
1
+ import * as SecureRandom from "effect/crypto/SecureRandom";
2
2
  import type * as Duration from "effect/Duration";
3
3
  import * as Effect from "effect/Effect";
4
4
  import * as FileSystem from "effect/FileSystem";
@@ -8,10 +8,12 @@ import * as Predicate from "effect/Predicate";
8
8
  import * as Schedule from "effect/Schedule";
9
9
  import * as Schema from "effect/Schema";
10
10
 
11
- export class FileLockError extends Schema.TaggedError<FileLockError>()(
12
- "FileLockError",
13
- { reason: Schema.Literals(["held", "timeout", "filesystem"]) },
14
- ) {}
11
+ export class FileLockError extends Schema.TaggedError<
12
+ FileLockError,
13
+ { readonly brand: unique symbol }
14
+ >()("FileLockError", {
15
+ reason: Schema.Literals(["held", "timeout", "filesystem"]),
16
+ }) {}
15
17
 
16
18
  const Holder = Schema.fromJsonString(
17
19
  Schema.Struct({ pid: Schema.Finite, token: Schema.String }),
@@ -42,6 +44,8 @@ const isAlive = (pid: number) => {
42
44
  * leaves waiters timing out rather than overlapping. A timeout that lands while
43
45
  * an attempt succeeds still fails, and the published lock is removed only when
44
46
  * the ambient scope closes.
47
+ *
48
+ * @internal
45
49
  */
46
50
  export const acquire = Effect.fn("FileLock.acquire")(function* (
47
51
  file: string,
@@ -49,11 +53,10 @@ export const acquire = Effect.fn("FileLock.acquire")(function* (
49
53
  ) {
50
54
  const fs = yield* FileSystem.FileSystem;
51
55
  const path = yield* Path.Path;
52
- const crypto = yield* Crypto.Crypto;
53
- const failed = () => new FileLockError({ reason: "filesystem" });
54
- const token = Buffer.from(
55
- yield* crypto.randomBytes(16).pipe(Effect.mapError(failed)),
56
- ).toString("hex");
56
+ const random = yield* SecureRandom.SecureRandom;
57
+ const failed = () => FileLockError.make({ reason: "filesystem" });
58
+ const randomBytes2 = yield* random.randomBytes(16);
59
+ const token = Buffer.from(randomBytes2).toString("hex");
57
60
  const holder = yield* Schema.encodeEffect(Holder)({
58
61
  pid: process.pid,
59
62
  token,
@@ -119,7 +122,7 @@ export const acquire = Effect.fn("FileLock.acquire")(function* (
119
122
  );
120
123
 
121
124
  if (wait === undefined) {
122
- if (!(yield* attempt)) return yield* new FileLockError({ reason: "held" });
125
+ if (!(yield* attempt)) return yield* FileLockError.make({ reason: "held" });
123
126
  } else {
124
127
  yield* attempt.pipe(
125
128
  Effect.repeat({
@@ -128,7 +131,7 @@ export const acquire = Effect.fn("FileLock.acquire")(function* (
128
131
  }),
129
132
  Effect.timeoutOrElse({
130
133
  duration: wait,
131
- orElse: () => Effect.fail(new FileLockError({ reason: "timeout" })),
134
+ orElse: () => Effect.fail(FileLockError.make({ reason: "timeout" })),
132
135
  }),
133
136
  );
134
137
  }
@@ -6,22 +6,26 @@ import * as Effect from "effect/Effect";
6
6
  import * as Option from "effect/Option";
7
7
  import * as Schema from "effect/Schema";
8
8
 
9
- export class LifecycleStateError extends Schema.TaggedError<LifecycleStateError>()(
10
- "LifecycleStateError",
11
- { fqn: Schema.String },
12
- ) {}
9
+ export class LifecycleStateError extends Schema.TaggedError<
10
+ LifecycleStateError,
11
+ { readonly brand: unique symbol }
12
+ >()("LifecycleStateError", { fqn: Schema.String }) {}
13
13
 
14
14
  export const checkpointCreate = Effect.fn("Lifecycle.checkpointCreate")(
15
15
  function* (fqn: string, instanceId: string, props: object, output?: object) {
16
16
  const stack = yield* Effect.serviceOption(Stack);
17
17
  if (Option.isNone(stack)) return;
18
18
  const state = yield* Effect.serviceOption(State);
19
- if (Option.isNone(state)) return yield* new LifecycleStateError({ fqn });
19
+ if (Option.isNone(state)) return yield* LifecycleStateError.make({ fqn });
20
20
  const store = yield* state.value;
21
21
  const key = { stack: stack.value.name, stage: stack.value.stage, fqn };
22
22
  const row = yield* store.get(key);
23
- if (!row || row.kind === "action" || row.instanceId !== instanceId)
24
- return yield* new LifecycleStateError({ fqn });
23
+ if (
24
+ row === undefined ||
25
+ row.kind === "action" ||
26
+ row.instanceId !== instanceId
27
+ )
28
+ return yield* LifecycleStateError.make({ fqn });
25
29
  if (row.status !== "creating") return;
26
30
  yield* store.set({
27
31
  ...key,
@@ -2,7 +2,7 @@ import { createServer, type Server } from "node:net";
2
2
  import { dotAlchemyDirectory } from "alchemy/AlchemyContext";
3
3
  import { Stack } from "alchemy/Stack";
4
4
  import * as Config from "effect/Config";
5
- import * as Crypto from "effect/Crypto";
5
+ import * as SecureRandom from "effect/crypto/SecureRandom";
6
6
  import * as Deferred from "effect/Deferred";
7
7
  import * as Effect from "effect/Effect";
8
8
  import * as Exit from "effect/Exit";
@@ -22,6 +22,9 @@ import * as FileLock from "./FileLock.js";
22
22
  import * as Loopback from "./Loopback.js";
23
23
  import { userCache } from "./UserCache.js";
24
24
  import { extract } from "./Zip.js";
25
+ import * as Str from "effect/String";
26
+ import { pipe } from "effect/Function";
27
+ import * as Array from "effect/Array";
25
28
 
26
29
  /**
27
30
  * The backend release a new local deployment runs. An existing data directory
@@ -30,24 +33,24 @@ import { extract } from "./Zip.js";
30
33
  */
31
34
  export const backendVersion = "precompiled-2026-10-28-cccbade";
32
35
 
33
- export class LocalBackendError extends Schema.TaggedError<LocalBackendError>()(
34
- "LocalBackendError",
35
- {
36
- deploymentName: Schema.String,
37
- reason: Schema.Literals([
38
- "configuration",
39
- "filesystem",
40
- "install",
41
- "identity",
42
- "ports",
43
- "running",
44
- "spawn",
45
- "exit",
46
- "timeout",
47
- ]),
48
- exitCode: Schema.optionalKey(Schema.Finite),
49
- },
50
- ) {
36
+ export class LocalBackendError extends Schema.TaggedError<
37
+ LocalBackendError,
38
+ { readonly brand: unique symbol }
39
+ >()("LocalBackendError", {
40
+ deploymentName: Schema.String,
41
+ reason: Schema.Literals([
42
+ "configuration",
43
+ "filesystem",
44
+ "install",
45
+ "identity",
46
+ "ports",
47
+ "running",
48
+ "spawn",
49
+ "exit",
50
+ "timeout",
51
+ ]),
52
+ exitCode: Schema.optionalKey(Schema.Finite),
53
+ }) {
51
54
  override get message() {
52
55
  const subject = `Local backend for ${this.deploymentName}`;
53
56
  switch (this.reason) {
@@ -129,7 +132,7 @@ const listen = (port: number) =>
129
132
  server.once("error", () => resume(Effect.undefined));
130
133
  server.listen(port, "127.0.0.1", () => resume(Effect.succeed(server)));
131
134
  }),
132
- (server) => (server ? close(server) : Effect.void),
135
+ (server) => (server !== undefined ? close(server) : Effect.void),
133
136
  );
134
137
 
135
138
  const isFree = (port: number) =>
@@ -153,12 +156,15 @@ const startup = Semaphore.makeUnsafe(1);
153
156
  * Resolves the directory that holds one local deployment's identity, database,
154
157
  * and file storage: `.alchemy/convex/<stack>/<stage>/<deployment>`. Keyed by
155
158
  * the deployment name because a deploy key resource only knows that name.
159
+ *
160
+ * @internal
156
161
  */
157
162
  export const dataDirectories = Effect.gen(function* () {
158
163
  const path = yield* Path.Path;
159
164
  const stack = yield* Stack;
165
+ const dotAlchemyDirectoryValue = yield* dotAlchemyDirectory;
160
166
  const root = path.resolve(
161
- yield* dotAlchemyDirectory,
167
+ dotAlchemyDirectoryValue,
162
168
  "convex",
163
169
  stack.name,
164
170
  stack.stage,
@@ -174,7 +180,7 @@ const readIdentity = Effect.fn("LocalBackend.readIdentity")(function* (
174
180
  const path = yield* Path.Path;
175
181
  const file = path.join(directory, "identity.json");
176
182
  const invalid = () =>
177
- new LocalBackendError({ deploymentName, reason: "identity" });
183
+ LocalBackendError.make({ deploymentName, reason: "identity" });
178
184
  if (!(yield* fs.exists(file).pipe(Effect.mapError(invalid))))
179
185
  return Option.none<Identity>();
180
186
  const identity = yield* fs
@@ -196,7 +202,10 @@ export const adminKey = Effect.fn("LocalBackend.adminKey")(function* (
196
202
  ) {
197
203
  const identity = yield* readIdentity(deploymentName, directory);
198
204
  if (Option.isNone(identity))
199
- return yield* new LocalBackendError({ deploymentName, reason: "identity" });
205
+ return yield* LocalBackendError.make({
206
+ deploymentName,
207
+ reason: "identity",
208
+ });
200
209
  return Redacted.make(identity.value.adminKey);
201
210
  });
202
211
 
@@ -208,8 +217,8 @@ export const remove = Effect.fn("LocalBackend.remove")(function* (
208
217
  yield* fs
209
218
  .remove(directory, { recursive: true, force: true })
210
219
  .pipe(
211
- Effect.mapError(
212
- () => new LocalBackendError({ deploymentName, reason: "filesystem" }),
220
+ Effect.mapError(() =>
221
+ LocalBackendError.make({ deploymentName, reason: "filesystem" }),
213
222
  ),
214
223
  );
215
224
  });
@@ -227,7 +236,7 @@ const install = Effect.fn("LocalBackend.install")(function* (
227
236
  const path = yield* Path.Path;
228
237
  const http = yield* HttpClient.HttpClient;
229
238
  const failed = () =>
230
- new LocalBackendError({ deploymentName, reason: "install" });
239
+ LocalBackendError.make({ deploymentName, reason: "install" });
231
240
  const binaries = path.join(cache, "convex", "binaries");
232
241
  const binary = path.join(binaries, version, executable);
233
242
  const artifact = artifacts[`${process.platform}-${process.arch}`];
@@ -272,9 +281,9 @@ export const boot = Effect.fn("LocalBackend.boot")(function* (
272
281
  const fs = yield* FileSystem.FileSystem;
273
282
  const http = yield* HttpClient.HttpClient;
274
283
  const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
275
- const crypto = yield* Crypto.Crypto;
284
+ const random = yield* SecureRandom.SecureRandom;
276
285
  const fail = (reason: LocalBackendError["reason"], exitCode?: number) =>
277
- new LocalBackendError({
286
+ LocalBackendError.make({
278
287
  deploymentName,
279
288
  reason,
280
289
  ...(exitCode === undefined ? {} : { exitCode }),
@@ -308,7 +317,7 @@ export const boot = Effect.fn("LocalBackend.boot")(function* (
308
317
  if (Option.isNone(range) || Option.isNone(range.value)) {
309
318
  // A closed server no longer has an address.
310
319
  const [port, sitePort] = yield* Effect.all([listen(0), listen(0)]).pipe(
311
- Effect.map((servers) => servers.map(portOf)),
320
+ Effect.map((servers) => Array.map(servers, portOf)),
312
321
  Effect.scoped,
313
322
  );
314
323
  if (port === undefined || sitePort === undefined)
@@ -328,9 +337,8 @@ export const boot = Effect.fn("LocalBackend.boot")(function* (
328
337
 
329
338
  const generate = (binary: string) =>
330
339
  Effect.gen(function* () {
331
- const instanceSecret = Buffer.from(
332
- yield* crypto.randomBytes(32),
333
- ).toString("hex");
340
+ const randomBytes2 = yield* random.randomBytes(32);
341
+ const instanceSecret = Buffer.from(randomBytes2).toString("hex");
334
342
  const output = yield* spawner.string(
335
343
  ChildProcess.make(
336
344
  binary,
@@ -345,8 +353,9 @@ export const boot = Effect.fn("LocalBackend.boot")(function* (
345
353
  { env, extendEnv: false, stdin: "ignore", stderr: "ignore" },
346
354
  ),
347
355
  );
348
- const key = output.trim();
349
- if (!key.startsWith(`${deploymentName}|`)) return yield* fail("identity");
356
+ const key = pipe(output, Str.trim);
357
+ if (!pipe(key, Str.startsWith(`${deploymentName}|`)))
358
+ return yield* fail("identity");
350
359
  return { instanceSecret, adminKey: key };
351
360
  }).pipe(
352
361
  Effect.catchTag("PlatformError", () => Effect.fail(fail("identity"))),
@@ -356,11 +365,8 @@ export const boot = Effect.fn("LocalBackend.boot")(function* (
356
365
  Effect.gen(function* () {
357
366
  const file = path.join(directory, "identity.json");
358
367
  const temp = `${file}.${process.pid}.tmp`;
359
- yield* fs.writeFileString(
360
- temp,
361
- yield* Schema.encodeEffect(Identity)(identity),
362
- { mode: 0o600 },
363
- );
368
+ const encoded = yield* Schema.encodeEffect(Identity)(identity);
369
+ yield* fs.writeFileString(temp, encoded, { mode: 0o600 });
364
370
  yield* fs.rename(temp, file);
365
371
  }).pipe(
366
372
  // Node cannot cancel a write or rename it has started; finishing it
@@ -6,4 +6,7 @@
6
6
  import type * as RpcServer from "alchemy/Local/RpcServer";
7
7
  import { localLayer } from "../Deployment.js";
8
8
 
9
+ /**
10
+ * @internal
11
+ */
9
12
  export default localLayer satisfies RpcServer.ProviderLayer;
@@ -5,10 +5,10 @@ import type * as Redacted from "effect/Redacted";
5
5
  import * as Schema from "effect/Schema";
6
6
  import { ConvexClient, ConvexFunctionError } from "../ConvexClient.js";
7
7
 
8
- export class MountInitFailed extends Schema.TaggedError<MountInitFailed>()(
9
- "MountInitFailed",
10
- { mount: Schema.String, detail: Schema.String },
11
- ) {
8
+ export class MountInitFailed extends Schema.TaggedError<
9
+ MountInitFailed,
10
+ { readonly brand: unique symbol }
11
+ >()("MountInitFailed", { mount: Schema.String, detail: Schema.String }) {
12
12
  override get message() {
13
13
  return `${this.mount}: init failed; earlier mounts are applied, and the next push retries`;
14
14
  }
@@ -58,6 +58,8 @@ const hasDeployModule = Effect.fn("MountInit.hasDeployModule")(function* (
58
58
  * path, one at a time, and visit a nested component's own steps after its
59
59
  * `init`. The first failing mount stops the run. Each `init` is its own
60
60
  * transaction, so earlier mounts stay applied and a rerun converges.
61
+ *
62
+ * @internal
61
63
  */
62
64
  export const run = Effect.fn("MountInit.run")(function* (
63
65
  url: string,
@@ -67,7 +69,7 @@ export const run = Effect.fn("MountInit.run")(function* (
67
69
  const failed =
68
70
  (mount: string) =>
69
71
  (error: { readonly _tag: string }): MountInitFailed =>
70
- new MountInitFailed({
72
+ MountInitFailed.make({
71
73
  mount,
72
74
  detail: Schema.is(ConvexFunctionError)(error)
73
75
  ? error.errorMessage
@@ -92,7 +94,7 @@ export const run = Effect.fn("MountInit.run")(function* (
92
94
  ? step.componentPath
93
95
  : `${prefix}/${step.componentPath}`;
94
96
  if ("failure" in step)
95
- return yield* new MountInitFailed({ mount, detail: step.failure });
97
+ return yield* MountInitFailed.make({ mount, detail: step.failure });
96
98
  if (step.init !== null)
97
99
  yield* client
98
100
  .runFunction(
@@ -1,5 +1,5 @@
1
1
  import * as Context from "effect/Context";
2
- import * as Crypto from "effect/Crypto";
2
+ import * as SecureRandom from "effect/crypto/SecureRandom";
3
3
  import * as Duration from "effect/Duration";
4
4
  import * as Effect from "effect/Effect";
5
5
  import * as FileSystem from "effect/FileSystem";
@@ -11,13 +11,13 @@ import * as Scope from "effect/Scope";
11
11
  import * as FileLock from "./FileLock.js";
12
12
  import { userCache } from "./UserCache.js";
13
13
 
14
- export class PushLockError extends Schema.TaggedError<PushLockError>()(
15
- "PushLockError",
16
- {
17
- deploymentName: Schema.String,
18
- reason: Schema.Literals(["configuration", "timeout", "filesystem"]),
19
- },
20
- ) {
14
+ export class PushLockError extends Schema.TaggedError<
15
+ PushLockError,
16
+ { readonly brand: unique symbol }
17
+ >()("PushLockError", {
18
+ deploymentName: Schema.String,
19
+ reason: Schema.Literals(["configuration", "timeout", "filesystem"]),
20
+ }) {
21
21
  override get message() {
22
22
  switch (this.reason) {
23
23
  case "configuration":
@@ -50,6 +50,8 @@ export class PushLock extends Context.Service<
50
50
  * `confect/alchemy/locks/<deployment>.lock`, so every checkout on the machine
51
51
  * shares it. A lock left by a process that exited is taken over; a holder that
52
52
  * never releases ends in a typed timeout.
53
+ *
54
+ * @internal
53
55
  */
54
56
  export const layer = (options?: { readonly timeout?: Duration.Input }) =>
55
57
  Layer.effect(
@@ -57,12 +59,12 @@ export const layer = (options?: { readonly timeout?: Duration.Input }) =>
57
59
  Effect.gen(function* () {
58
60
  const fs = yield* FileSystem.FileSystem;
59
61
  const path = yield* Path.Path;
60
- const crypto = yield* Crypto.Crypto;
62
+ const random = yield* SecureRandom.SecureRandom;
61
63
  const timeout = options?.timeout ?? Duration.minutes(10);
62
64
  const lock = Effect.fn("PushLock.lock")(
63
65
  function* (deploymentName: string, scope: Scope.Scope) {
64
66
  const failed = (reason: PushLockError["reason"]) =>
65
- new PushLockError({ deploymentName, reason });
67
+ PushLockError.make({ deploymentName, reason });
66
68
  const cache = yield* userCache.pipe(
67
69
  Effect.mapError(() => failed("configuration")),
68
70
  );
@@ -85,7 +87,7 @@ export const layer = (options?: { readonly timeout?: Duration.Input }) =>
85
87
  },
86
88
  Effect.provideService(FileSystem.FileSystem, fs),
87
89
  Effect.provideService(Path.Path, path),
88
- Effect.provideService(Crypto.Crypto, crypto),
90
+ Effect.provideService(SecureRandom.SecureRandom, random),
89
91
  );
90
92
  return PushLock.of({
91
93
  withLock: (deploymentName, effect) =>
@@ -1,4 +1,7 @@
1
1
  import * as Effect from "effect/Effect";
2
+ import * as String from "effect/String";
3
+ import { pipe } from "effect/Function";
4
+ import * as Arr from "effect/Array";
2
5
 
3
6
  export const resourceName = Effect.fn("ResourceIdentity.name")(function* (
4
7
  kind: string,
@@ -11,10 +14,14 @@ export const resourceName = Effect.fn("ResourceIdentity.name")(function* (
11
14
  new TextEncoder().encode(`${fqn}:${instanceId}`),
12
15
  ),
13
16
  );
14
- const suffix = Array.from(new Uint8Array(hash), (byte) =>
15
- byte.toString(16).padStart(2, "0"),
16
- )
17
- .join("")
18
- .slice(0, 24);
17
+ const suffix = pipe(
18
+ Arr.join(
19
+ Array.from(new Uint8Array(hash), (byte) =>
20
+ pipe(byte.toString(16), String.padStart(2, "0")),
21
+ ),
22
+ "",
23
+ ),
24
+ String.slice(0, 24),
25
+ );
19
26
  return `confect-${kind}-${suffix}`;
20
27
  });
@@ -8,6 +8,8 @@ import * as Path from "effect/Path";
8
8
  * POSIX and `%LOCALAPPDATA%` on Windows. Shared by every checkout on the
9
9
  * machine, so binaries are downloaded once and push locks are seen by every
10
10
  * stack. None when no absolute directory can be derived.
11
+ *
12
+ * @internal
11
13
  */
12
14
  export const userCache = Effect.gen(function* () {
13
15
  const path = yield* Path.Path;
@@ -18,8 +20,15 @@ export const userCache = Effect.gen(function* () {
18
20
  });
19
21
  const root =
20
22
  process.platform === "win32"
21
- ? LOCALAPPDATA ||
22
- (USERPROFILE && path.join(USERPROFILE, "AppData", "Local"))
23
- : HOME && path.join(HOME, ".cache");
24
- return root && path.isAbsolute(root) ? Option.some(root) : Option.none();
23
+ ? LOCALAPPDATA !== ""
24
+ ? LOCALAPPDATA
25
+ : USERPROFILE === ""
26
+ ? ""
27
+ : path.join(USERPROFILE, "AppData", "Local")
28
+ : HOME === ""
29
+ ? ""
30
+ : path.join(HOME, ".cache");
31
+ return root !== "" && path.isAbsolute(root)
32
+ ? Option.some(root)
33
+ : Option.none();
25
34
  });
@@ -4,7 +4,10 @@ import * as FileSystem from "effect/FileSystem";
4
4
  import * as Result from "effect/Result";
5
5
  import * as Schema from "effect/Schema";
6
6
 
7
- export class ZipError extends Schema.TaggedError<ZipError>()("ZipError", {
7
+ export class ZipError extends Schema.TaggedError<
8
+ ZipError,
9
+ { readonly brand: unique symbol }
10
+ >()("ZipError", {
8
11
  reason: Schema.Literals(["format", "entry", "io"]),
9
12
  }) {}
10
13
 
@@ -14,7 +17,7 @@ interface Entry {
14
17
  readonly end: number;
15
18
  }
16
19
 
17
- const format = () => Result.fail(new ZipError({ reason: "format" }));
20
+ const format = () => Result.fail(ZipError.make({ reason: "format" }));
18
21
 
19
22
  /**
20
23
  * Locate one entry's compressed bytes through the archive's central directory.
@@ -67,15 +70,15 @@ const locate = (
67
70
  bytes.readUInt16LE(offset + 30) +
68
71
  bytes.readUInt16LE(offset + 32);
69
72
  }
70
- return Result.fail(new ZipError({ reason: "entry" }));
73
+ return Result.fail(ZipError.make({ reason: "entry" }));
71
74
  };
72
75
 
73
76
  const inflate = (data: Uint8Array) =>
74
77
  Effect.callback<Uint8Array, ZipError>((resume) => {
75
78
  inflateRaw(data, (error, output) =>
76
79
  resume(
77
- error
78
- ? Effect.fail(new ZipError({ reason: "format" }))
80
+ error !== null
81
+ ? Effect.fail(ZipError.make({ reason: "format" }))
79
82
  : Effect.succeed(output),
80
83
  ),
81
84
  );
@@ -84,6 +87,8 @@ const inflate = (data: Uint8Array) =>
84
87
  /**
85
88
  * Extract one entry of a zip archive. Convex publishes the local backend as a
86
89
  * single-file zip, stored or deflated.
90
+ *
91
+ * @internal
87
92
  */
88
93
  export const extract = Effect.fn("Zip.extract")(function* (
89
94
  archive: string,
@@ -93,7 +98,7 @@ export const extract = Effect.fn("Zip.extract")(function* (
93
98
  const fs = yield* FileSystem.FileSystem;
94
99
  const bytes = yield* fs
95
100
  .readFile(archive)
96
- .pipe(Effect.mapError(() => new ZipError({ reason: "io" })));
101
+ .pipe(Effect.mapError(() => ZipError.make({ reason: "io" })));
97
102
  const entry = yield* Effect.fromResult(locate(bytes, name));
98
103
  const data = bytes.subarray(entry.start, entry.end);
99
104
  const content =
@@ -101,8 +106,8 @@ export const extract = Effect.fn("Zip.extract")(function* (
101
106
  ? yield* inflate(data)
102
107
  : entry.method === 0
103
108
  ? data
104
- : yield* new ZipError({ reason: "format" });
109
+ : yield* ZipError.make({ reason: "format" });
105
110
  yield* fs
106
111
  .writeFile(destination, content, { mode: 0o755 })
107
- .pipe(Effect.mapError(() => new ZipError({ reason: "io" })));
112
+ .pipe(Effect.mapError(() => ZipError.make({ reason: "io" })));
108
113
  });