@gaganref/confect-alchemy 10.6.0-fork.29 → 10.6.0-fork.30
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/dist/Backend.d.ts +64 -5
- package/dist/Backend.d.ts.map +1 -1
- package/dist/Backend.js +187 -3
- package/dist/Backend.js.map +1 -1
- package/dist/Code.d.ts +14 -2
- package/dist/Code.d.ts.map +1 -1
- package/dist/Code.js +2 -2
- package/dist/Code.js.map +1 -1
- package/dist/Confect.d.ts +1 -1
- package/dist/Confect.d.ts.map +1 -1
- package/dist/Confect.js +8 -3
- package/dist/Confect.js.map +1 -1
- package/dist/Convex.d.ts +1 -1
- package/dist/Convex.d.ts.map +1 -1
- package/dist/Convex.js +4 -1
- package/dist/Convex.js.map +1 -1
- package/dist/ConvexClient.js +4 -4
- package/dist/CustomDomain.js +3 -3
- package/dist/DeployKey.js +3 -3
- package/dist/Deployment.js +2 -2
- package/dist/EnvironmentVariables.d.ts.map +1 -1
- package/dist/EnvironmentVariables.js +20 -13
- package/dist/EnvironmentVariables.js.map +1 -1
- package/dist/LogStream.js +5 -5
- package/dist/Project.js +2 -2
- package/dist/UsageLimit.js +2 -2
- package/dist/internal/CodeDeployment.d.ts +28 -1
- package/dist/internal/CodeDeployment.d.ts.map +1 -1
- package/dist/internal/CodeDeployment.js +85 -2
- package/dist/internal/CodeDeployment.js.map +1 -1
- package/dist/internal/CommandRunner.js +4 -4
- package/dist/internal/FileLock.js +1 -1
- package/dist/internal/FunctionsDirectory.d.ts +12 -0
- package/dist/internal/FunctionsDirectory.d.ts.map +1 -0
- package/dist/internal/FunctionsDirectory.js +22 -0
- package/dist/internal/FunctionsDirectory.js.map +1 -0
- package/dist/internal/LocalBackend.d.ts +7 -0
- package/dist/internal/LocalBackend.d.ts.map +1 -1
- package/dist/internal/LocalBackend.js +10 -3
- package/dist/internal/LocalBackend.js.map +1 -1
- package/dist/internal/MountInit.d.ts.map +1 -1
- package/dist/internal/MountInit.js +4 -6
- package/dist/internal/MountInit.js.map +1 -1
- package/dist/internal/PushLock.js +1 -1
- package/dist/internal/ResourceIdentity.js +1 -1
- package/dist/internal/Zip.js +1 -1
- package/package.json +3 -3
- package/src/Backend.ts +422 -12
- package/src/Code.ts +13 -0
- package/src/Confect.ts +7 -1
- package/src/Convex.ts +7 -1
- package/src/EnvironmentVariables.ts +27 -12
- package/src/internal/CodeDeployment.ts +115 -0
- package/src/internal/FunctionsDirectory.ts +27 -0
- package/src/internal/LocalBackend.ts +7 -0
- package/src/internal/MountInit.ts +3 -13
|
@@ -1,15 +1,15 @@
|
|
|
1
|
+
import * as Arr from "effect/Array";
|
|
1
2
|
import * as Effect from "effect/Effect";
|
|
3
|
+
import * as Redacted from "effect/Redacted";
|
|
4
|
+
import * as Schema from "effect/Schema";
|
|
5
|
+
import * as Result from "effect/Result";
|
|
2
6
|
import * as FileSystem from "effect/FileSystem";
|
|
3
7
|
import * as Layer from "effect/Layer";
|
|
4
8
|
import * as Path from "effect/Path";
|
|
5
9
|
import * as Config from "effect/Config";
|
|
6
10
|
import * as Context from "effect/Context";
|
|
7
|
-
import * as Redacted from "effect/Redacted";
|
|
8
|
-
import * as Schema from "effect/Schema";
|
|
9
11
|
import * as Stream from "effect/Stream";
|
|
10
12
|
import * as Str from "effect/String";
|
|
11
|
-
import * as Arr from "effect/Array";
|
|
12
|
-
import * as Result from "effect/Result";
|
|
13
13
|
import * as Deferred from "effect/Deferred";
|
|
14
14
|
import { ChildProcess, ChildProcessSpawner } from "effect/process";
|
|
15
15
|
import { Buffer } from "node:buffer";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as Effect from "effect/Effect";
|
|
2
|
+
import * as Schema from "effect/Schema";
|
|
2
3
|
import * as FileSystem from "effect/FileSystem";
|
|
3
4
|
import * as Path from "effect/Path";
|
|
4
|
-
import * as Schema from "effect/Schema";
|
|
5
5
|
import * as Option from "effect/Option";
|
|
6
6
|
import * as SecureRandom from "effect/crypto/SecureRandom";
|
|
7
7
|
import * as Predicate from "effect/Predicate";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import * as FileSystem from "effect/FileSystem";
|
|
3
|
+
import * as Path from "effect/Path";
|
|
4
|
+
import * as Schema from "effect/Schema";
|
|
5
|
+
/**
|
|
6
|
+
* The backend's Convex directory relative to `cwd`, which `convex.json` may
|
|
7
|
+
* move from `convex`.
|
|
8
|
+
*
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export declare const functionsDirectory: (cwd: string) => Effect.Effect<string, import("effect/PlatformError").PlatformError | Schema.SchemaError, FileSystem.FileSystem | Path.Path>;
|
|
12
|
+
//# sourceMappingURL=FunctionsDirectory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FunctionsDirectory.d.ts","sources":["../../src/internal/FunctionsDirectory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,IAAI,MAAM,aAAa,CAAC;AACpC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAMxC;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,8IAW9B,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import * as Schema from "effect/Schema";
|
|
3
|
+
import * as FileSystem from "effect/FileSystem";
|
|
4
|
+
import * as Path from "effect/Path";
|
|
5
|
+
// src/internal/FunctionsDirectory.ts
|
|
6
|
+
const ConvexJson = Schema.fromJsonString(Schema.Struct({ functions: Schema.optional(Schema.String) }));
|
|
7
|
+
/**
|
|
8
|
+
* The backend's Convex directory relative to `cwd`, which `convex.json` may
|
|
9
|
+
* move from `convex`.
|
|
10
|
+
*
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
const functionsDirectory = Effect.fn("FunctionsDirectory.resolve")(function* (cwd) {
|
|
14
|
+
const fs = yield* FileSystem.FileSystem;
|
|
15
|
+
const config = (yield* Path.Path).join(cwd, "convex.json");
|
|
16
|
+
if (!(yield* fs.exists(config))) return "convex";
|
|
17
|
+
const { functions } = yield* fs.readFileString(config).pipe(Effect.flatMap(Schema.decodeEffect(ConvexJson)));
|
|
18
|
+
return functions ?? "convex";
|
|
19
|
+
});
|
|
20
|
+
export { functionsDirectory };
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=FunctionsDirectory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FunctionsDirectory.js","names":[],"sources":["../../src/internal/FunctionsDirectory.ts"],"sourcesContent":["import * as Effect from \"effect/Effect\";\nimport * as FileSystem from \"effect/FileSystem\";\nimport * as Path from \"effect/Path\";\nimport * as Schema from \"effect/Schema\";\n\nconst ConvexJson = Schema.fromJsonString(\n Schema.Struct({ functions: Schema.optional(Schema.String) }),\n);\n\n/**\n * The backend's Convex directory relative to `cwd`, which `convex.json` may\n * move from `convex`.\n *\n * @internal\n */\nexport const functionsDirectory = Effect.fn(\"FunctionsDirectory.resolve\")(\n function* (cwd: string) {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const config = path.join(cwd, \"convex.json\");\n if (!(yield* fs.exists(config))) return \"convex\";\n const { functions } = yield* fs\n .readFileString(config)\n .pipe(Effect.flatMap(Schema.decodeEffect(ConvexJson)));\n return functions ?? \"convex\";\n },\n);\n"],"mappings":";;;;;AAKA,MAAM,aAAa,OAAO,eACxB,OAAO,OAAO,EAAE,WAAW,OAAO,SAAS,OAAO,MAAM,EAAE,CAAC,CAC7D;;;;;;;AAQA,MAAa,qBAAqB,OAAO,GAAG,4BAA4B,CAAC,CACvE,WAAW,KAAa;CACtB,MAAM,KAAK,OAAO,WAAW;CAE7B,MAAM,UAAS,OADK,KAAK,KAAA,CACL,KAAK,KAAK,aAAa;CAC3C,IAAI,EAAE,OAAO,GAAG,OAAO,MAAM,IAAI,OAAO;CACxC,MAAM,EAAE,cAAc,OAAO,GAC1B,eAAe,MAAM,CAAC,CACtB,KAAK,OAAO,QAAQ,OAAO,aAAa,UAAU,CAAC,CAAC;CACvD,OAAO,aAAa;AACtB,CACF"}
|
|
@@ -48,6 +48,11 @@ export declare const dataDirectories: Effect.Effect<(deploymentName: string) =>
|
|
|
48
48
|
* @stability unstable
|
|
49
49
|
*/
|
|
50
50
|
export declare const adminKey: (deploymentName: string, directory: string) => Effect.Effect<Redacted.Redacted<string>, LocalBackendError, FileSystem.FileSystem | Path.Path>;
|
|
51
|
+
/**
|
|
52
|
+
* Remove a local deployment's retained data.
|
|
53
|
+
*
|
|
54
|
+
* @stability unstable
|
|
55
|
+
*/
|
|
51
56
|
export declare const remove: (deploymentName: string, directory: string) => Effect.Effect<void, LocalBackendError, FileSystem.FileSystem>;
|
|
52
57
|
/**
|
|
53
58
|
* Boot the local backend for one deployment and keep it running for the ambient
|
|
@@ -58,6 +63,8 @@ export declare const remove: (deploymentName: string, directory: string) => Effe
|
|
|
58
63
|
* picks two free loopback ports; later boots reuse all of them, so stored
|
|
59
64
|
* credentials and URLs stay valid. A saved port that something else now holds
|
|
60
65
|
* is an error rather than a move, because resources keep the URL.
|
|
66
|
+
*
|
|
67
|
+
* @stability unstable
|
|
61
68
|
*/
|
|
62
69
|
export declare const boot: (deploymentName: string, directory: string) => Effect.Effect<{
|
|
63
70
|
url: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LocalBackend.d.ts","sources":["../../src/internal/LocalBackend.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtC,OAAO,KAAK,YAAY,MAAM,4BAA4B,CAAC;AAE3D,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAC;AAEhD,OAAO,KAAK,IAAI,MAAM,aAAa,CA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xC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAGtC,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAgB,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAUnE;;;;GAIG;AACH,eAAO,MAAM,cAAc,mCAAmC,CAAC;;;;;;oBAI3C,OAAO,MAAM;;AAFjC,qBAAa,iBAAkB,SAAQ,sBAiBrC;IACA,IAAa,OAAO,WAsBnB;CACF;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC7C;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;CACtC;AAmED;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,iCAUF,MAAM,sCAC9B,CAAC;AAuBH;;;;GAIG;AACH,eAAO,MAAM,QAAQ,+IAWnB,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,MAAM,8GAYjB,CAAC;AA0CH;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,IAAI;;;;;oKA8Nf,CAAC"}
|
|
@@ -3,18 +3,18 @@ import { acquire } from "./FileLock.js";
|
|
|
3
3
|
import { origin, parsePortRange } from "./Loopback.js";
|
|
4
4
|
import { userCache } from "./UserCache.js";
|
|
5
5
|
import { extract } from "./Zip.js";
|
|
6
|
+
import * as Array from "effect/Array";
|
|
6
7
|
import * as Effect from "effect/Effect";
|
|
8
|
+
import * as Redacted from "effect/Redacted";
|
|
9
|
+
import * as Schema from "effect/Schema";
|
|
7
10
|
import * as FileSystem from "effect/FileSystem";
|
|
8
11
|
import * as Path from "effect/Path";
|
|
9
12
|
import * as Config from "effect/Config";
|
|
10
|
-
import * as Redacted from "effect/Redacted";
|
|
11
|
-
import * as Schema from "effect/Schema";
|
|
12
13
|
import * as Stream from "effect/Stream";
|
|
13
14
|
import * as HttpClient from "effect/http/HttpClient";
|
|
14
15
|
import * as Option from "effect/Option";
|
|
15
16
|
import * as Str from "effect/String";
|
|
16
17
|
import { pipe } from "effect/Function";
|
|
17
|
-
import * as Array from "effect/Array";
|
|
18
18
|
import * as Deferred from "effect/Deferred";
|
|
19
19
|
import { ChildProcess, ChildProcessSpawner } from "effect/process";
|
|
20
20
|
import * as SecureRandom from "effect/crypto/SecureRandom";
|
|
@@ -134,6 +134,11 @@ const adminKey = Effect.fn("LocalBackend.adminKey")(function* (deploymentName, d
|
|
|
134
134
|
});
|
|
135
135
|
return Redacted.make(identity.value.adminKey);
|
|
136
136
|
});
|
|
137
|
+
/**
|
|
138
|
+
* Remove a local deployment's retained data.
|
|
139
|
+
*
|
|
140
|
+
* @stability unstable
|
|
141
|
+
*/
|
|
137
142
|
const remove = Effect.fn("LocalBackend.remove")(function* (deploymentName, directory) {
|
|
138
143
|
yield* (yield* FileSystem.FileSystem).remove(directory, {
|
|
139
144
|
recursive: true,
|
|
@@ -187,6 +192,8 @@ const install = Effect.fn("LocalBackend.install")(function* (deploymentName, ver
|
|
|
187
192
|
* picks two free loopback ports; later boots reuse all of them, so stored
|
|
188
193
|
* credentials and URLs stay valid. A saved port that something else now holds
|
|
189
194
|
* is an error rather than a move, because resources keep the URL.
|
|
195
|
+
*
|
|
196
|
+
* @stability unstable
|
|
190
197
|
*/
|
|
191
198
|
const boot = Effect.fn("LocalBackend.boot")(function* (deploymentName, directory) {
|
|
192
199
|
const path = yield* Path.Path;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LocalBackend.js","names":["Loopback.parsePortRange","FileLock.acquire","Loopback.origin"],"sources":["../../src/internal/LocalBackend.ts"],"sourcesContent":["import { createServer, type Server } from \"node:net\";\nimport { dotAlchemyDirectory } from \"alchemy/AlchemyContext\";\nimport { Stack } from \"alchemy/Stack\";\nimport * as Config from \"effect/Config\";\nimport * as SecureRandom from \"effect/crypto/SecureRandom\";\nimport * as Deferred from \"effect/Deferred\";\nimport * as Effect from \"effect/Effect\";\nimport * as Exit from \"effect/Exit\";\nimport * as FileSystem from \"effect/FileSystem\";\nimport * as Option from \"effect/Option\";\nimport * as Path from \"effect/Path\";\nimport * as Redacted from \"effect/Redacted\";\nimport * as Schedule from \"effect/Schedule\";\nimport * as Schema from \"effect/Schema\";\nimport * as Scope from \"effect/Scope\";\nimport * as Semaphore from \"effect/Semaphore\";\nimport * as Stream from \"effect/Stream\";\nimport * as HttpClient from \"effect/http/HttpClient\";\nimport { ChildProcess, ChildProcessSpawner } from \"effect/process\";\nimport { processEnvironment } from \"./CommandRunner.js\";\nimport * as FileLock from \"./FileLock.js\";\nimport * as Loopback from \"./Loopback.js\";\nimport { userCache } from \"./UserCache.js\";\nimport { extract } from \"./Zip.js\";\nimport * as Str from \"effect/String\";\nimport { pipe } from \"effect/Function\";\nimport * as Array from \"effect/Array\";\n\n/**\n * The backend release a new local deployment runs. An existing data directory\n * keeps running the release that created it, so upgrading this package never\n * opens a database with a different release.\n */\nexport const backendVersion = \"precompiled-2026-10-28-cccbade\";\n\nexport class LocalBackendError extends Schema.TaggedError<\n LocalBackendError,\n { readonly brand: unique symbol }\n>()(\"LocalBackendError\", {\n deploymentName: Schema.String,\n reason: Schema.Literals([\n \"configuration\",\n \"filesystem\",\n \"install\",\n \"identity\",\n \"ports\",\n \"running\",\n \"spawn\",\n \"exit\",\n \"timeout\",\n ]),\n exitCode: Schema.optionalKey(Schema.Finite),\n}) {\n override get message() {\n const subject = `Local backend for ${this.deploymentName}`;\n switch (this.reason) {\n case \"configuration\":\n return `${subject} needs a home directory and, when set, CONFECT_LOCAL_BACKEND_PORTS as a range such as 3300-3399`;\n case \"filesystem\":\n return `${subject} could not read or write its data directory`;\n case \"install\":\n return `${subject} could not download or install the backend binary`;\n case \"identity\":\n return `${subject} could not read, create, or save its identity`;\n case \"ports\":\n return `${subject} could not get its ports; another process is using them`;\n case \"running\":\n return `${subject} is already running: stop the other alchemy dev session, or the backend process left over from one, that serves its data directory`;\n case \"spawn\":\n return `${subject} could not be started`;\n case \"exit\":\n return `${subject} exited${this.exitCode === undefined ? \"\" : ` with code ${this.exitCode}`} before it was ready`;\n case \"timeout\":\n return `${subject} did not become ready in time`;\n }\n }\n}\n\nexport interface LocalBackend {\n readonly url: string;\n readonly siteUrl: string;\n readonly adminKey: Redacted.Redacted<string>;\n /**\n * Completes when the backend process has exited and released its data\n * directory, so the deployment can be booted again.\n */\n readonly exited: Effect.Effect<void>;\n}\n\n// Ports are saved once a backend has answered on them, so a first start that\n// fails picks fresh ports next time instead of keeping ones that never worked.\nconst Identity = Schema.fromJsonString(\n Schema.Struct({\n name: Schema.String,\n version: Schema.String,\n instanceSecret: Schema.String,\n adminKey: Schema.String,\n ports: Schema.optionalKey(\n Schema.Struct({ port: Schema.Int, sitePort: Schema.Int }),\n ),\n }),\n);\ntype Identity = typeof Identity.Type;\n\n// The release archive per platform, as the Convex CLI maps it\n// (convex-js src/cli/lib/localDeployment/download.ts getDownloadPath).\nconst artifacts: Readonly<Record<string, string>> = {\n \"darwin-arm64\": \"convex-local-backend-aarch64-apple-darwin.zip\",\n \"darwin-x64\": \"convex-local-backend-x86_64-apple-darwin.zip\",\n \"linux-arm64\": \"convex-local-backend-aarch64-unknown-linux-gnu.zip\",\n \"linux-x64\": \"convex-local-backend-x86_64-unknown-linux-gnu.zip\",\n \"win32-arm64\": \"convex-local-backend-x86_64-pc-windows-msvc.zip\",\n \"win32-x64\": \"convex-local-backend-x86_64-pc-windows-msvc.zip\",\n};\nconst executable =\n process.platform === \"win32\"\n ? \"convex-local-backend.exe\"\n : \"convex-local-backend\";\n\nconst close = (server: Server) =>\n Effect.callback<void>((resume) => {\n server.close(() => resume(Effect.void));\n });\n\n// A server listening on `port`, or undefined when the port is taken, closed\n// with the scope. Listening is uninterruptible, so an interrupted probe never\n// leaves a server bound to the port.\nconst listen = (port: number) =>\n Effect.acquireRelease(\n Effect.callback<Server | undefined>((resume) => {\n const server = createServer();\n server.once(\"error\", () => resume(Effect.undefined));\n server.listen(port, \"127.0.0.1\", () => resume(Effect.succeed(server)));\n }),\n (server) => (server !== undefined ? close(server) : Effect.void),\n );\n\nconst isFree = (port: number) =>\n listen(port).pipe(\n Effect.map((server) => server !== undefined),\n Effect.scoped,\n );\n\nconst portOf = (server: Server | undefined) => {\n const address = server?.address();\n return typeof address === \"object\" && address !== null\n ? address.port\n : undefined;\n};\n\n// Backends in one process start one at a time, so two deployments starting\n// together never probe and claim the same ports.\nconst startup = Semaphore.makeUnsafe(1);\n\n/**\n * Resolves the directory that holds one local deployment's identity, database,\n * and file storage: `.alchemy/convex/<stack>/<stage>/<deployment>`. Keyed by\n * the deployment name because a deploy key resource only knows that name.\n *\n * @internal\n */\nexport const dataDirectories = Effect.gen(function* () {\n const path = yield* Path.Path;\n const stack = yield* Stack;\n const dotAlchemyDirectoryValue = yield* dotAlchemyDirectory;\n const root = path.resolve(\n dotAlchemyDirectoryValue,\n \"convex\",\n stack.name,\n stack.stage,\n );\n return (deploymentName: string) => path.join(root, deploymentName);\n});\n\nconst readIdentity = Effect.fn(\"LocalBackend.readIdentity\")(function* (\n deploymentName: string,\n directory: string,\n) {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const file = path.join(directory, \"identity.json\");\n const invalid = () =>\n LocalBackendError.make({ deploymentName, reason: \"identity\" });\n if (!(yield* fs.exists(file).pipe(Effect.mapError(invalid))))\n return Option.none<Identity>();\n const identity = yield* fs\n .readFileString(file)\n .pipe(\n Effect.flatMap(Schema.decodeEffect(Identity)),\n Effect.mapError(invalid),\n );\n if (identity.name !== deploymentName) return yield* invalid();\n return Option.some(identity);\n});\n\n/**\n * The admin key of a local deployment, for its deploy key resource.\n *\n * @stability unstable\n */\nexport const adminKey = Effect.fn(\"LocalBackend.adminKey\")(function* (\n deploymentName: string,\n directory: string,\n) {\n const identity = yield* readIdentity(deploymentName, directory);\n if (Option.isNone(identity))\n return yield* LocalBackendError.make({\n deploymentName,\n reason: \"identity\",\n });\n return Redacted.make(identity.value.adminKey);\n});\n\nexport const remove = Effect.fn(\"LocalBackend.remove\")(function* (\n deploymentName: string,\n directory: string,\n) {\n const fs = yield* FileSystem.FileSystem;\n yield* fs\n .remove(directory, { recursive: true, force: true })\n .pipe(\n Effect.mapError(() =>\n LocalBackendError.make({ deploymentName, reason: \"filesystem\" }),\n ),\n );\n});\n\n/**\n * Install a backend release into the Convex CLI's binary cache,\n * `<cache>/convex/binaries/<version>/`, unless it is already there.\n */\nconst install = Effect.fn(\"LocalBackend.install\")(function* (\n deploymentName: string,\n version: string,\n cache: string,\n) {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const http = yield* HttpClient.HttpClient;\n const failed = () =>\n LocalBackendError.make({ deploymentName, reason: \"install\" });\n const binaries = path.join(cache, \"convex\", \"binaries\");\n const binary = path.join(binaries, version, executable);\n const artifact = artifacts[`${process.platform}-${process.arch}`];\n return yield* Effect.gen(function* () {\n if (yield* fs.exists(binary)) return binary;\n if (artifact === undefined) return yield* failed();\n yield* fs.makeDirectory(binaries, { recursive: true });\n const temp = yield* fs.makeTempDirectoryScoped({\n directory: binaries,\n prefix: \".download-\",\n });\n const archive = path.join(temp, artifact);\n const response = yield* http.get(\n `https://github.com/get-convex/convex-backend/releases/download/${version}/${artifact}`,\n );\n if (response.status !== 200) return yield* failed();\n yield* response.stream.pipe(Stream.run(fs.sink(archive)));\n const extracted = path.join(temp, executable);\n yield* extract(archive, executable, extracted);\n yield* fs.chmod(extracted, 0o755);\n yield* fs.makeDirectory(path.dirname(binary), { recursive: true });\n yield* fs.rename(extracted, binary);\n return binary;\n }).pipe(Effect.scoped, Effect.mapError(failed));\n});\n\n/**\n * Boot the local backend for one deployment and keep it running for the ambient\n * scope. The process and the data directory's `owner.lock` share a child scope\n * that closes when the boot fails or is interrupted and when the process exits,\n * so a deployment can be booted again in the same session. The first boot\n * installs the pinned release, generates an instance secret and admin key, and\n * picks two free loopback ports; later boots reuse all of them, so stored\n * credentials and URLs stay valid. A saved port that something else now holds\n * is an error rather than a move, because resources keep the URL.\n */\nexport const boot = Effect.fn(\"LocalBackend.boot\")(function* (\n deploymentName: string,\n directory: string,\n) {\n const path = yield* Path.Path;\n const fs = yield* FileSystem.FileSystem;\n const http = yield* HttpClient.HttpClient;\n const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;\n const random = yield* SecureRandom.SecureRandom;\n const fail = (reason: LocalBackendError[\"reason\"], exitCode?: number) =>\n LocalBackendError.make({\n deploymentName,\n reason,\n ...(exitCode === undefined ? {} : { exitCode }),\n });\n const settings = yield* Config.all({\n environment: processEnvironment,\n ports: Config.String(\"CONFECT_LOCAL_BACKEND_PORTS\").pipe(Config.option),\n }).pipe(Effect.mapError(() => fail(\"configuration\")));\n const cache = yield* userCache.pipe(\n Effect.mapError(() => fail(\"configuration\")),\n );\n if (Option.isNone(cache)) return yield* fail(\"configuration\");\n const range = Option.map(settings.ports, Loopback.parsePortRange);\n if (Option.isSome(range) && Option.isNone(range.value))\n return yield* fail(\"configuration\");\n const env = {\n ...settings.environment,\n DISABLE_BEACON: \"1\",\n DO_NOT_TRACK: \"1\",\n };\n\n const answer = (url: string) =>\n http.get(`${url}/instance_name`).pipe(\n Effect.flatMap((response) =>\n response.status === 200 ? response.text : Effect.undefined,\n ),\n Effect.orElseSucceed(() => undefined),\n );\n\n const allocate = Effect.gen(function* () {\n if (Option.isNone(range) || Option.isNone(range.value)) {\n // A closed server no longer has an address.\n const [port, sitePort] = yield* Effect.all([listen(0), listen(0)]).pipe(\n Effect.map((servers) => Array.map(servers, portOf)),\n Effect.scoped,\n );\n if (port === undefined || sitePort === undefined)\n return yield* fail(\"ports\");\n return { port, sitePort };\n }\n const free: number[] = [];\n const { from, to } = range.value.value;\n for (let port = from; port <= to && free.length < 2; port++) {\n if (yield* isFree(port)) free.push(port);\n }\n const [port, sitePort] = free;\n if (port === undefined || sitePort === undefined)\n return yield* fail(\"ports\");\n return { port, sitePort };\n });\n\n const generate = (binary: string) =>\n Effect.gen(function* () {\n const randomBytes2 = yield* random.randomBytes(32);\n const instanceSecret = Buffer.from(randomBytes2).toString(\"hex\");\n const output = yield* spawner.string(\n ChildProcess.make(\n binary,\n [\n \"keygen\",\n \"admin-key\",\n \"--instance-name\",\n deploymentName,\n \"--instance-secret\",\n instanceSecret,\n ],\n { env, extendEnv: false, stdin: \"ignore\", stderr: \"ignore\" },\n ),\n );\n const key = pipe(output, Str.trim);\n if (!pipe(key, Str.startsWith(`${deploymentName}|`)))\n return yield* fail(\"identity\");\n return { instanceSecret, adminKey: key };\n }).pipe(\n Effect.catchTag(\"PlatformError\", () => Effect.fail(fail(\"identity\"))),\n );\n\n const save = (identity: Identity) =>\n Effect.gen(function* () {\n const file = path.join(directory, \"identity.json\");\n const temp = `${file}.${process.pid}.tmp`;\n const encoded = yield* Schema.encodeEffect(Identity)(identity);\n yield* fs.writeFileString(temp, encoded, { mode: 0o600 });\n yield* fs.rename(temp, file);\n }).pipe(\n // Node cannot cancel a write or rename it has started; finishing it\n // keeps a pending rename from landing after owner.lock is released.\n Effect.uninterruptible,\n Effect.mapError(() => fail(\"identity\")),\n );\n\n const session = yield* Scope.Scope;\n const owned = yield* Scope.fork(session);\n const stopped = yield* Deferred.make<void>();\n // Registered first, so it runs after the process and owner.lock finalizers\n // however the scope closes.\n yield* Scope.addFinalizer(owned, Deferred.succeed(stopped, undefined));\n const start = Effect.gen(function* () {\n yield* FileLock.acquire(path.join(directory, \"owner.lock\")).pipe(\n Effect.mapError((error) =>\n fail(error.reason === \"held\" ? \"running\" : \"filesystem\"),\n ),\n );\n const saved = yield* readIdentity(deploymentName, directory);\n const version = Option.isSome(saved) ? saved.value.version : backendVersion;\n const binary = yield* install(deploymentName, version, cache.value);\n let identity: Identity;\n if (Option.isSome(saved)) {\n identity = saved.value;\n } else {\n identity = {\n name: deploymentName,\n version,\n ...(yield* generate(binary)),\n };\n yield* save(identity);\n }\n const ports = identity.ports ?? (yield* allocate);\n if (identity.ports !== undefined) {\n if (!(yield* isFree(ports.port)) || !(yield* isFree(ports.sitePort)))\n return yield* fail(\n (yield* answer(Loopback.origin(ports.port))) === deploymentName\n ? \"running\"\n : \"ports\",\n );\n }\n\n const url = Loopback.origin(ports.port);\n const siteUrl = Loopback.origin(ports.sitePort);\n const handle = yield* spawner\n .spawn(\n ChildProcess.make(\n binary,\n [\n \"--interface\",\n \"127.0.0.1\",\n \"--port\",\n String(ports.port),\n \"--site-proxy-port\",\n String(ports.sitePort),\n \"--instance-name\",\n deploymentName,\n \"--instance-secret\",\n identity.instanceSecret,\n \"--convex-origin\",\n url,\n \"--convex-site\",\n siteUrl,\n \"--local-storage\",\n path.join(directory, \"convex_local_storage\"),\n \"--disable-beacon\",\n path.join(directory, \"convex_local_backend.sqlite3\"),\n ],\n {\n cwd: directory,\n env,\n extendEnv: false,\n stdin: \"ignore\",\n stdout: \"ignore\",\n stderr: \"ignore\",\n forceKillAfter: \"3 seconds\",\n },\n ),\n )\n .pipe(Effect.mapError(() => fail(\"spawn\")));\n\n const ready = answer(url).pipe(\n Effect.flatMap((name) =>\n name === undefined || name === deploymentName\n ? Effect.succeed(name === deploymentName)\n : Effect.fail(fail(\"ports\")),\n ),\n Effect.repeat({\n until: (isReady) => isReady,\n schedule: Schedule.spaced(\"100 millis\"),\n }),\n );\n const exit = handle.exitCode.pipe(\n Effect.mapError(() => fail(\"exit\")),\n Effect.flatMap((code) => Effect.fail(fail(\"exit\", Number(code)))),\n );\n yield* Effect.raceFirst(ready, exit).pipe(\n Effect.timeoutOrElse({\n duration: \"60 seconds\",\n orElse: () => Effect.fail(fail(\"timeout\")),\n }),\n );\n if (identity.ports === undefined) yield* save({ ...identity, ports });\n // An exited backend releases the data directory before `exited`\n // completes, so the deployment can be booted again in this session.\n yield* handle.exitCode.pipe(\n Effect.ignore,\n Effect.andThen(Scope.close(owned, Exit.void)),\n Effect.forkIn(session),\n );\n return {\n url,\n siteUrl,\n adminKey: Redacted.make(identity.adminKey),\n exited: Deferred.await(stopped),\n } satisfies LocalBackend;\n });\n\n return yield* startup\n .withPermits(1)(start)\n .pipe(\n Scope.provide(owned),\n Effect.onExit((exit) =>\n Exit.isSuccess(exit) ? Effect.void : Scope.close(owned, exit),\n ),\n );\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,MAAa,iBAAiB;AAE9B,IAAa,oBAAb,cAAuC,OAAO,YAG5C,CAAC,CAAC,qBAAqB;CACvB,gBAAgB,OAAO;CACvB,QAAQ,OAAO,SAAS;EACtB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CACD,UAAU,OAAO,YAAY,OAAO,MAAM;AAC5C,CAAC,CAAC,CAAC;CACD,IAAa,UAAU;EACrB,MAAM,UAAU,qBAAqB,KAAK;EAC1C,QAAQ,KAAK,QAAb;GACE,KAAK,iBACH,OAAO,GAAG,QAAQ;GACpB,KAAK,cACH,OAAO,GAAG,QAAQ;GACpB,KAAK,WACH,OAAO,GAAG,QAAQ;GACpB,KAAK,YACH,OAAO,GAAG,QAAQ;GACpB,KAAK,SACH,OAAO,GAAG,QAAQ;GACpB,KAAK,WACH,OAAO,GAAG,QAAQ;GACpB,KAAK,SACH,OAAO,GAAG,QAAQ;GACpB,KAAK,QACH,OAAO,GAAG,QAAQ,SAAS,KAAK,aAAa,KAAA,IAAY,KAAK,cAAc,KAAK,WAAW;GAC9F,KAAK,WACH,OAAO,GAAG,QAAQ;EACtB;CACF;AACF;AAeA,MAAM,WAAW,OAAO,eACtB,OAAO,OAAO;CACZ,MAAM,OAAO;CACb,SAAS,OAAO;CAChB,gBAAgB,OAAO;CACvB,UAAU,OAAO;CACjB,OAAO,OAAO,YACZ,OAAO,OAAO;EAAE,MAAM,OAAO;EAAK,UAAU,OAAO;CAAI,CAAC,CAC1D;AACF,CAAC,CACH;AAKA,MAAM,YAA8C;CA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AAC,CAAC,KACxB,OAAO,SAAS,SACd,SAAS,KAAA,KAAa,SAAS,iBAC3B,OAAO,QAAQ,SAAS,cAAc,IACtC,OAAO,KAAK,KAAK,OAAO,CAAC,CAC/B,GACA,OAAO,OAAO;GACZ,QAAQ,YAAY;GACpB,UAAU,SAAS,OAAO,YAAY;EACxC,CAAC,CACH;EACA,MAAM,OAAO,OAAO,SAAS,KAC3B,OAAO,eAAe,KAAK,MAAM,CAAC,GAClC,OAAO,SAAS,SAAS,OAAO,KAAK,KAAK,QAAQ,OAAO,IAAI,CAAC,CAAC,CAAC,CAClE;EACA,OAAO,OAAO,UAAU,OAAO,IAAI,CAAC,CAAC,KACnC,OAAO,cAAc;GACnB,UAAU;GACV,cAAc,OAAO,KAAK,KAAK,SAAS,CAAC;EAC3C,CAAC,CACH;EACA,IAAI,SAAS,UAAU,KAAA,GAAW,OAAO,KAAK;GAAE,GAAG;GAAU;EAAM,CAAC;EAGpE,OAAO,OAAO,SAAS,KACrB,OAAO,QACP,OAAO,QAAQ,MAAM,MAAM,OAAO,KAAK,IAAI,CAAC,GAC5C,OAAO,OAAO,OAAO,CACvB;EACA,OAAO;GACL;GACA;GACA,UAAU,SAAS,KAAK,SAAS,QAAQ;GACzC,QAAQ,SAAS,MAAM,OAAO;EAChC;CACF,CAAC;CAED,OAAO,OAAO,QACX,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CACrB,KACC,MAAM,QAAQ,KAAK,GACnB,OAAO,QAAQ,SACb,KAAK,UAAU,IAAI,IAAI,OAAO,OAAO,MAAM,MAAM,OAAO,IAAI,CAC9D,CACF;AACJ,CAAC"}
|
|
1
|
+
{"version":3,"file":"LocalBackend.js","names":["Loopback.parsePortRange","FileLock.acquire","Loopback.origin"],"sources":["../../src/internal/LocalBackend.ts"],"sourcesContent":["import { createServer, type Server } from \"node:net\";\nimport { dotAlchemyDirectory } from \"alchemy/AlchemyContext\";\nimport { Stack } from \"alchemy/Stack\";\nimport * as Config from \"effect/Config\";\nimport * as SecureRandom from \"effect/crypto/SecureRandom\";\nimport * as Deferred from \"effect/Deferred\";\nimport * as Effect from \"effect/Effect\";\nimport * as Exit from \"effect/Exit\";\nimport * as FileSystem from \"effect/FileSystem\";\nimport * as Option from \"effect/Option\";\nimport * as Path from \"effect/Path\";\nimport * as Redacted from \"effect/Redacted\";\nimport * as Schedule from \"effect/Schedule\";\nimport * as Schema from \"effect/Schema\";\nimport * as Scope from \"effect/Scope\";\nimport * as Semaphore from \"effect/Semaphore\";\nimport * as Stream from \"effect/Stream\";\nimport * as HttpClient from \"effect/http/HttpClient\";\nimport { ChildProcess, ChildProcessSpawner } from \"effect/process\";\nimport { processEnvironment } from \"./CommandRunner.js\";\nimport * as FileLock from \"./FileLock.js\";\nimport * as Loopback from \"./Loopback.js\";\nimport { userCache } from \"./UserCache.js\";\nimport { extract } from \"./Zip.js\";\nimport * as Str from \"effect/String\";\nimport { pipe } from \"effect/Function\";\nimport * as Array from \"effect/Array\";\n\n/**\n * The backend release a new local deployment runs. An existing data directory\n * keeps running the release that created it, so upgrading this package never\n * opens a database with a different release.\n */\nexport const backendVersion = \"precompiled-2026-10-28-cccbade\";\n\nexport class LocalBackendError extends Schema.TaggedError<\n LocalBackendError,\n { readonly brand: unique symbol }\n>()(\"LocalBackendError\", {\n deploymentName: Schema.String,\n reason: Schema.Literals([\n \"configuration\",\n \"filesystem\",\n \"install\",\n \"identity\",\n \"ports\",\n \"running\",\n \"spawn\",\n \"exit\",\n \"timeout\",\n ]),\n exitCode: Schema.optionalKey(Schema.Finite),\n}) {\n override get message() {\n const subject = `Local backend for ${this.deploymentName}`;\n switch (this.reason) {\n case \"configuration\":\n return `${subject} needs a home directory and, when set, CONFECT_LOCAL_BACKEND_PORTS as a range such as 3300-3399`;\n case \"filesystem\":\n return `${subject} could not read or write its data directory`;\n case \"install\":\n return `${subject} could not download or install the backend binary`;\n case \"identity\":\n return `${subject} could not read, create, or save its identity`;\n case \"ports\":\n return `${subject} could not get its ports; another process is using them`;\n case \"running\":\n return `${subject} is already running: stop the other alchemy dev session, or the backend process left over from one, that serves its data directory`;\n case \"spawn\":\n return `${subject} could not be started`;\n case \"exit\":\n return `${subject} exited${this.exitCode === undefined ? \"\" : ` with code ${this.exitCode}`} before it was ready`;\n case \"timeout\":\n return `${subject} did not become ready in time`;\n }\n }\n}\n\nexport interface LocalBackend {\n readonly url: string;\n readonly siteUrl: string;\n readonly adminKey: Redacted.Redacted<string>;\n /**\n * Completes when the backend process has exited and released its data\n * directory, so the deployment can be booted again.\n */\n readonly exited: Effect.Effect<void>;\n}\n\n// Ports are saved once a backend has answered on them, so a first start that\n// fails picks fresh ports next time instead of keeping ones that never worked.\nconst Identity = Schema.fromJsonString(\n Schema.Struct({\n name: Schema.String,\n version: Schema.String,\n instanceSecret: Schema.String,\n adminKey: Schema.String,\n ports: Schema.optionalKey(\n Schema.Struct({ port: Schema.Int, sitePort: Schema.Int }),\n ),\n }),\n);\ntype Identity = typeof Identity.Type;\n\n// The release archive per platform, as the Convex CLI maps it\n// (convex-js src/cli/lib/localDeployment/download.ts getDownloadPath).\nconst artifacts: Readonly<Record<string, string>> = {\n \"darwin-arm64\": \"convex-local-backend-aarch64-apple-darwin.zip\",\n \"darwin-x64\": \"convex-local-backend-x86_64-apple-darwin.zip\",\n \"linux-arm64\": \"convex-local-backend-aarch64-unknown-linux-gnu.zip\",\n \"linux-x64\": \"convex-local-backend-x86_64-unknown-linux-gnu.zip\",\n \"win32-arm64\": \"convex-local-backend-x86_64-pc-windows-msvc.zip\",\n \"win32-x64\": \"convex-local-backend-x86_64-pc-windows-msvc.zip\",\n};\nconst executable =\n process.platform === \"win32\"\n ? \"convex-local-backend.exe\"\n : \"convex-local-backend\";\n\nconst close = (server: Server) =>\n Effect.callback<void>((resume) => {\n server.close(() => resume(Effect.void));\n });\n\n// A server listening on `port`, or undefined when the port is taken, closed\n// with the scope. Listening is uninterruptible, so an interrupted probe never\n// leaves a server bound to the port.\nconst listen = (port: number) =>\n Effect.acquireRelease(\n Effect.callback<Server | undefined>((resume) => {\n const server = createServer();\n server.once(\"error\", () => resume(Effect.undefined));\n server.listen(port, \"127.0.0.1\", () => resume(Effect.succeed(server)));\n }),\n (server) => (server !== undefined ? close(server) : Effect.void),\n );\n\nconst isFree = (port: number) =>\n listen(port).pipe(\n Effect.map((server) => server !== undefined),\n Effect.scoped,\n );\n\nconst portOf = (server: Server | undefined) => {\n const address = server?.address();\n return typeof address === \"object\" && address !== null\n ? address.port\n : undefined;\n};\n\n// Backends in one process start one at a time, so two deployments starting\n// together never probe and claim the same ports.\nconst startup = Semaphore.makeUnsafe(1);\n\n/**\n * Resolves the directory that holds one local deployment's identity, database,\n * and file storage: `.alchemy/convex/<stack>/<stage>/<deployment>`. Keyed by\n * the deployment name because a deploy key resource only knows that name.\n *\n * @internal\n */\nexport const dataDirectories = Effect.gen(function* () {\n const path = yield* Path.Path;\n const stack = yield* Stack;\n const dotAlchemyDirectoryValue = yield* dotAlchemyDirectory;\n const root = path.resolve(\n dotAlchemyDirectoryValue,\n \"convex\",\n stack.name,\n stack.stage,\n );\n return (deploymentName: string) => path.join(root, deploymentName);\n});\n\nconst readIdentity = Effect.fn(\"LocalBackend.readIdentity\")(function* (\n deploymentName: string,\n directory: string,\n) {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const file = path.join(directory, \"identity.json\");\n const invalid = () =>\n LocalBackendError.make({ deploymentName, reason: \"identity\" });\n if (!(yield* fs.exists(file).pipe(Effect.mapError(invalid))))\n return Option.none<Identity>();\n const identity = yield* fs\n .readFileString(file)\n .pipe(\n Effect.flatMap(Schema.decodeEffect(Identity)),\n Effect.mapError(invalid),\n );\n if (identity.name !== deploymentName) return yield* invalid();\n return Option.some(identity);\n});\n\n/**\n * The admin key of a local deployment, for its deploy key resource.\n *\n * @stability unstable\n */\nexport const adminKey = Effect.fn(\"LocalBackend.adminKey\")(function* (\n deploymentName: string,\n directory: string,\n) {\n const identity = yield* readIdentity(deploymentName, directory);\n if (Option.isNone(identity))\n return yield* LocalBackendError.make({\n deploymentName,\n reason: \"identity\",\n });\n return Redacted.make(identity.value.adminKey);\n});\n\n/**\n * Remove a local deployment's retained data.\n *\n * @stability unstable\n */\nexport const remove = Effect.fn(\"LocalBackend.remove\")(function* (\n deploymentName: string,\n directory: string,\n) {\n const fs = yield* FileSystem.FileSystem;\n yield* fs\n .remove(directory, { recursive: true, force: true })\n .pipe(\n Effect.mapError(() =>\n LocalBackendError.make({ deploymentName, reason: \"filesystem\" }),\n ),\n );\n});\n\n/**\n * Install a backend release into the Convex CLI's binary cache,\n * `<cache>/convex/binaries/<version>/`, unless it is already there.\n */\nconst install = Effect.fn(\"LocalBackend.install\")(function* (\n deploymentName: string,\n version: string,\n cache: string,\n) {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const http = yield* HttpClient.HttpClient;\n const failed = () =>\n LocalBackendError.make({ deploymentName, reason: \"install\" });\n const binaries = path.join(cache, \"convex\", \"binaries\");\n const binary = path.join(binaries, version, executable);\n const artifact = artifacts[`${process.platform}-${process.arch}`];\n return yield* Effect.gen(function* () {\n if (yield* fs.exists(binary)) return binary;\n if (artifact === undefined) return yield* failed();\n yield* fs.makeDirectory(binaries, { recursive: true });\n const temp = yield* fs.makeTempDirectoryScoped({\n directory: binaries,\n prefix: \".download-\",\n });\n const archive = path.join(temp, artifact);\n const response = yield* http.get(\n `https://github.com/get-convex/convex-backend/releases/download/${version}/${artifact}`,\n );\n if (response.status !== 200) return yield* failed();\n yield* response.stream.pipe(Stream.run(fs.sink(archive)));\n const extracted = path.join(temp, executable);\n yield* extract(archive, executable, extracted);\n yield* fs.chmod(extracted, 0o755);\n yield* fs.makeDirectory(path.dirname(binary), { recursive: true });\n yield* fs.rename(extracted, binary);\n return binary;\n }).pipe(Effect.scoped, Effect.mapError(failed));\n});\n\n/**\n * Boot the local backend for one deployment and keep it running for the ambient\n * scope. The process and the data directory's `owner.lock` share a child scope\n * that closes when the boot fails or is interrupted and when the process exits,\n * so a deployment can be booted again in the same session. The first boot\n * installs the pinned release, generates an instance secret and admin key, and\n * picks two free loopback ports; later boots reuse all of them, so stored\n * credentials and URLs stay valid. A saved port that something else now holds\n * is an error rather than a move, because resources keep the URL.\n *\n * @stability unstable\n */\nexport const boot = Effect.fn(\"LocalBackend.boot\")(function* (\n deploymentName: string,\n directory: string,\n) {\n const path = yield* Path.Path;\n const fs = yield* FileSystem.FileSystem;\n const http = yield* HttpClient.HttpClient;\n const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;\n const random = yield* SecureRandom.SecureRandom;\n const fail = (reason: LocalBackendError[\"reason\"], exitCode?: number) =>\n LocalBackendError.make({\n deploymentName,\n reason,\n ...(exitCode === undefined ? {} : { exitCode }),\n });\n const settings = yield* Config.all({\n environment: processEnvironment,\n ports: Config.String(\"CONFECT_LOCAL_BACKEND_PORTS\").pipe(Config.option),\n }).pipe(Effect.mapError(() => fail(\"configuration\")));\n const cache = yield* userCache.pipe(\n Effect.mapError(() => fail(\"configuration\")),\n );\n if (Option.isNone(cache)) return yield* fail(\"configuration\");\n const range = Option.map(settings.ports, Loopback.parsePortRange);\n if (Option.isSome(range) && Option.isNone(range.value))\n return yield* fail(\"configuration\");\n const env = {\n ...settings.environment,\n DISABLE_BEACON: \"1\",\n DO_NOT_TRACK: \"1\",\n };\n\n const answer = (url: string) =>\n http.get(`${url}/instance_name`).pipe(\n Effect.flatMap((response) =>\n response.status === 200 ? response.text : Effect.undefined,\n ),\n Effect.orElseSucceed(() => undefined),\n );\n\n const allocate = Effect.gen(function* () {\n if (Option.isNone(range) || Option.isNone(range.value)) {\n // A closed server no longer has an address.\n const [port, sitePort] = yield* Effect.all([listen(0), listen(0)]).pipe(\n Effect.map((servers) => Array.map(servers, portOf)),\n Effect.scoped,\n );\n if (port === undefined || sitePort === undefined)\n return yield* fail(\"ports\");\n return { port, sitePort };\n }\n const free: number[] = [];\n const { from, to } = range.value.value;\n for (let port = from; port <= to && free.length < 2; port++) {\n if (yield* isFree(port)) free.push(port);\n }\n const [port, sitePort] = free;\n if (port === undefined || sitePort === undefined)\n return yield* fail(\"ports\");\n return { port, sitePort };\n });\n\n const generate = (binary: string) =>\n Effect.gen(function* () {\n const randomBytes2 = yield* random.randomBytes(32);\n const instanceSecret = Buffer.from(randomBytes2).toString(\"hex\");\n const output = yield* spawner.string(\n ChildProcess.make(\n binary,\n [\n \"keygen\",\n \"admin-key\",\n \"--instance-name\",\n deploymentName,\n \"--instance-secret\",\n instanceSecret,\n ],\n { env, extendEnv: false, stdin: \"ignore\", stderr: \"ignore\" },\n ),\n );\n const key = pipe(output, Str.trim);\n if (!pipe(key, Str.startsWith(`${deploymentName}|`)))\n return yield* fail(\"identity\");\n return { instanceSecret, adminKey: key };\n }).pipe(\n Effect.catchTag(\"PlatformError\", () => Effect.fail(fail(\"identity\"))),\n );\n\n const save = (identity: Identity) =>\n Effect.gen(function* () {\n const file = path.join(directory, \"identity.json\");\n const temp = `${file}.${process.pid}.tmp`;\n const encoded = yield* Schema.encodeEffect(Identity)(identity);\n yield* fs.writeFileString(temp, encoded, { mode: 0o600 });\n yield* fs.rename(temp, file);\n }).pipe(\n // Node cannot cancel a write or rename it has started; finishing it\n // keeps a pending rename from landing after owner.lock is released.\n Effect.uninterruptible,\n Effect.mapError(() => fail(\"identity\")),\n );\n\n const session = yield* Scope.Scope;\n const owned = yield* Scope.fork(session);\n const stopped = yield* Deferred.make<void>();\n // Registered first, so it runs after the process and owner.lock finalizers\n // however the scope closes.\n yield* Scope.addFinalizer(owned, Deferred.succeed(stopped, undefined));\n const start = Effect.gen(function* () {\n yield* FileLock.acquire(path.join(directory, \"owner.lock\")).pipe(\n Effect.mapError((error) =>\n fail(error.reason === \"held\" ? \"running\" : \"filesystem\"),\n ),\n );\n const saved = yield* readIdentity(deploymentName, directory);\n const version = Option.isSome(saved) ? saved.value.version : backendVersion;\n const binary = yield* install(deploymentName, version, cache.value);\n let identity: Identity;\n if (Option.isSome(saved)) {\n identity = saved.value;\n } else {\n identity = {\n name: deploymentName,\n version,\n ...(yield* generate(binary)),\n };\n yield* save(identity);\n }\n const ports = identity.ports ?? (yield* allocate);\n if (identity.ports !== undefined) {\n if (!(yield* isFree(ports.port)) || !(yield* isFree(ports.sitePort)))\n return yield* fail(\n (yield* answer(Loopback.origin(ports.port))) === deploymentName\n ? \"running\"\n : \"ports\",\n );\n }\n\n const url = Loopback.origin(ports.port);\n const siteUrl = Loopback.origin(ports.sitePort);\n const handle = yield* spawner\n .spawn(\n ChildProcess.make(\n binary,\n [\n \"--interface\",\n \"127.0.0.1\",\n \"--port\",\n String(ports.port),\n \"--site-proxy-port\",\n String(ports.sitePort),\n \"--instance-name\",\n deploymentName,\n \"--instance-secret\",\n identity.instanceSecret,\n \"--convex-origin\",\n url,\n \"--convex-site\",\n siteUrl,\n \"--local-storage\",\n path.join(directory, \"convex_local_storage\"),\n \"--disable-beacon\",\n path.join(directory, \"convex_local_backend.sqlite3\"),\n ],\n {\n cwd: directory,\n env,\n extendEnv: false,\n stdin: \"ignore\",\n stdout: \"ignore\",\n stderr: \"ignore\",\n forceKillAfter: \"3 seconds\",\n },\n ),\n )\n .pipe(Effect.mapError(() => fail(\"spawn\")));\n\n const ready = answer(url).pipe(\n Effect.flatMap((name) =>\n name === undefined || name === deploymentName\n ? Effect.succeed(name === deploymentName)\n : Effect.fail(fail(\"ports\")),\n ),\n Effect.repeat({\n until: (isReady) => isReady,\n schedule: Schedule.spaced(\"100 millis\"),\n }),\n );\n const exit = handle.exitCode.pipe(\n Effect.mapError(() => fail(\"exit\")),\n Effect.flatMap((code) => Effect.fail(fail(\"exit\", Number(code)))),\n );\n yield* Effect.raceFirst(ready, exit).pipe(\n Effect.timeoutOrElse({\n duration: \"60 seconds\",\n orElse: () => Effect.fail(fail(\"timeout\")),\n }),\n );\n if (identity.ports === undefined) yield* save({ ...identity, ports });\n // An exited backend releases the data directory before `exited`\n // completes, so the deployment can be booted again in this session.\n yield* handle.exitCode.pipe(\n Effect.ignore,\n Effect.andThen(Scope.close(owned, Exit.void)),\n Effect.forkIn(session),\n );\n return {\n url,\n siteUrl,\n adminKey: Redacted.make(identity.adminKey),\n exited: Deferred.await(stopped),\n } satisfies LocalBackend;\n });\n\n return yield* startup\n .withPermits(1)(start)\n .pipe(\n Scope.provide(owned),\n Effect.onExit((exit) =>\n Exit.isSuccess(exit) ? Effect.void : Scope.close(owned, exit),\n ),\n );\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,MAAa,iBAAiB;AAE9B,IAAa,oBAAb,cAAuC,OAAO,YAG5C,CAAC,CAAC,qBAAqB;CACvB,gBAAgB,OAAO;CACvB,QAAQ,OAAO,SAAS;EACtB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CACD,UAAU,OAAO,YAAY,OAAO,MAAM;AAC5C,CAAC,CAAC,CAAC;CACD,IAAa,UAAU;EACrB,MAAM,UAAU,qBAAqB,KAAK;EAC1C,QAAQ,KAAK,QAAb;GACE,KAAK,iBACH,OAAO,GAAG,QAAQ;GACpB,KAAK,cACH,OAAO,GAAG,QAAQ;GACpB,KAAK,WACH,OAAO,GAAG,QAAQ;GACpB,KAAK,YACH,OAAO,GAAG,QAAQ;GACpB,KAAK,SACH,OAAO,GAAG,QAAQ;GACpB,KAAK,WACH,OAAO,GAAG,QAAQ;GACpB,KAAK,SACH,OAAO,GAAG,QAAQ;GACpB,KAAK,QACH,OAAO,GAAG,QAAQ,SAAS,KAAK,aAAa,KAAA,IAAY,KAAK,cAAc,KAAK,WAAW;GAC9F,KAAK,WACH,OAAO,GAAG,QAAQ;EACtB;CACF;AACF;AAeA,MAAM,WAAW,OAAO,eACtB,OAAO,OAAO;CACZ,MAAM,OAAO;CACb,SAAS,OAAO;CAChB,gBAAgB,OAAO;CACvB,UAAU,OAAO;CACjB,OAAO,OAAO,YACZ,OAAO,OAAO;EAAE,MAAM,OAAO;EAAK,UAAU,OAAO;CAAI,CAAC,CA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mB,CAAC;AAChD,OAAO,KAAK,IAAI,MAAM,aAAa,CAAC;AACpC,OAAO,KAAK,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,YAAY,EAAuB,MAAM,oBAAoB,CAAC;;;;;
|
|
1
|
+
{"version":3,"file":"MountInit.d.ts","sources":["../../src/internal/MountInit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,IAAI,MAAM,aAAa,CAAC;AACpC,OAAO,KAAK,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,YAAY,EAAuB,MAAM,oBAAoB,CAAC;;;;;oBAKnD,OAAO,MAAM;;AAFjC,qBAAa,eAAgB,SAAQ,oBAGkC;IACrE,IAAa,OAAO,WAEnB;CACF;AA6BD;;;;;;;;GAQG;AACH,eAAO,MAAM,GAAG,sJAgDd,CAAC"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { ConvexClient, ConvexFunctionError } from "../ConvexClient.js";
|
|
2
|
+
import { functionsDirectory } from "./FunctionsDirectory.js";
|
|
2
3
|
import * as Effect from "effect/Effect";
|
|
4
|
+
import * as Schema from "effect/Schema";
|
|
3
5
|
import * as FileSystem from "effect/FileSystem";
|
|
4
6
|
import * as Path from "effect/Path";
|
|
5
|
-
import * as Schema from "effect/Schema";
|
|
6
7
|
// src/internal/MountInit.ts
|
|
7
8
|
var MountInitFailed = class extends Schema.TaggedError()("MountInitFailed", {
|
|
8
9
|
mount: Schema.String,
|
|
@@ -24,16 +25,13 @@ const Steps = Schema.Array(Schema.Union([Schema.Struct({
|
|
|
24
25
|
failure: Schema.String
|
|
25
26
|
})]));
|
|
26
27
|
const STEPS = "confectDeploy:steps";
|
|
27
|
-
const ConvexJson = Schema.fromJsonString(Schema.Struct({ functions: Schema.optional(Schema.String) }));
|
|
28
28
|
/**
|
|
29
|
-
* Whether codegen wrote `confectDeploy.ts` into the backend's Convex directory
|
|
30
|
-
* which `convex.json` may move.
|
|
29
|
+
* Whether codegen wrote `confectDeploy.ts` into the backend's Convex directory.
|
|
31
30
|
*/
|
|
32
31
|
const hasDeployModule = Effect.fn("MountInit.hasDeployModule")(function* (cwd) {
|
|
33
32
|
const fs = yield* FileSystem.FileSystem;
|
|
34
33
|
const path = yield* Path.Path;
|
|
35
|
-
const
|
|
36
|
-
const functions = (yield* fs.exists(config)) ? (yield* fs.readFileString(config).pipe(Effect.flatMap(Schema.decodeEffect(ConvexJson)))).functions ?? "convex" : "convex";
|
|
34
|
+
const functions = yield* functionsDirectory(cwd);
|
|
37
35
|
return yield* fs.exists(path.join(cwd, functions, "confectDeploy.ts"));
|
|
38
36
|
});
|
|
39
37
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MountInit.js","names":[],"sources":["../../src/internal/MountInit.ts"],"sourcesContent":["import * as Effect from \"effect/Effect\";\nimport * as FileSystem from \"effect/FileSystem\";\nimport * as Path from \"effect/Path\";\nimport type * as Redacted from \"effect/Redacted\";\nimport * as Schema from \"effect/Schema\";\nimport { ConvexClient, ConvexFunctionError } from \"../ConvexClient.js\";\n\nexport class MountInitFailed extends Schema.TaggedError<\n MountInitFailed,\n { readonly brand: unique symbol }\n>()(\"MountInitFailed\", { mount: Schema.String, detail: Schema.String }) {\n override get message() {\n return `${this.mount}: init failed; earlier mounts are applied, and the next push retries`;\n }\n}\n\nconst Steps = Schema.Array(\n Schema.Union([\n Schema.Struct({\n componentPath: Schema.String,\n nested: Schema.Boolean,\n init: Schema.NullOr(\n Schema.Struct({ functionName: Schema.String, args: Schema.Unknown }),\n ),\n }),\n Schema.Struct({ componentPath: Schema.String, failure: Schema.String }),\n ]),\n);\n\nconst STEPS = \"confectDeploy:steps\";\n\
|
|
1
|
+
{"version":3,"file":"MountInit.js","names":[],"sources":["../../src/internal/MountInit.ts"],"sourcesContent":["import * as Effect from \"effect/Effect\";\nimport * as FileSystem from \"effect/FileSystem\";\nimport * as Path from \"effect/Path\";\nimport type * as Redacted from \"effect/Redacted\";\nimport * as Schema from \"effect/Schema\";\nimport { ConvexClient, ConvexFunctionError } from \"../ConvexClient.js\";\nimport { functionsDirectory } from \"./FunctionsDirectory.js\";\n\nexport class MountInitFailed extends Schema.TaggedError<\n MountInitFailed,\n { readonly brand: unique symbol }\n>()(\"MountInitFailed\", { mount: Schema.String, detail: Schema.String }) {\n override get message() {\n return `${this.mount}: init failed; earlier mounts are applied, and the next push retries`;\n }\n}\n\nconst Steps = Schema.Array(\n Schema.Union([\n Schema.Struct({\n componentPath: Schema.String,\n nested: Schema.Boolean,\n init: Schema.NullOr(\n Schema.Struct({ functionName: Schema.String, args: Schema.Unknown }),\n ),\n }),\n Schema.Struct({ componentPath: Schema.String, failure: Schema.String }),\n ]),\n);\n\nconst STEPS = \"confectDeploy:steps\";\n\n/**\n * Whether codegen wrote `confectDeploy.ts` into the backend's Convex directory.\n */\nconst hasDeployModule = Effect.fn(\"MountInit.hasDeployModule\")(function* (\n cwd: string,\n) {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const functions = yield* functionsDirectory(cwd);\n return yield* fs.exists(path.join(cwd, functions, \"confectDeploy.ts\"));\n});\n\n/**\n * Run every mount's `init` against a pushed deployment: ask the backend's\n * deploy module for its steps, then run each mount's `init` at its component\n * path, one at a time, and visit a nested component's own steps after its\n * `init`. The first failing mount stops the run. Each `init` is its own\n * transaction, so earlier mounts stay applied and a rerun converges.\n *\n * @internal\n */\nexport const run = Effect.fn(\"MountInit.run\")(function* (\n url: string,\n key: Redacted.Redacted<string>,\n cwd: string,\n) {\n const failed =\n (mount: string) =>\n (error: { readonly _tag: string }): MountInitFailed =>\n MountInitFailed.make({\n mount,\n detail: Schema.is(ConvexFunctionError)(error)\n ? error.errorMessage\n : error._tag,\n });\n if (!(yield* hasDeployModule(cwd).pipe(Effect.mapError(failed(STEPS)))))\n return;\n const client = yield* ConvexClient;\n const visit = (\n prefix: string | undefined,\n ): Effect.Effect<void, MountInitFailed> =>\n Effect.gen(function* () {\n const steps = yield* client\n .runFunction(url, key, STEPS, {}, prefix)\n .pipe(\n Effect.flatMap(Schema.decodeUnknownEffect(Steps)),\n Effect.mapError(failed(prefix ?? STEPS)),\n );\n for (const step of steps) {\n const mount =\n prefix === undefined\n ? step.componentPath\n : `${prefix}/${step.componentPath}`;\n if (\"failure\" in step)\n return yield* MountInitFailed.make({ mount, detail: step.failure });\n if (step.init !== null)\n yield* client\n .runFunction(\n url,\n key,\n step.init.functionName,\n step.init.args,\n mount,\n )\n .pipe(Effect.mapError(failed(mount)));\n if (step.nested) yield* visit(mount);\n }\n });\n yield* visit(undefined);\n});\n"],"mappings":";;;;;;;AAQA,IAAa,kBAAb,cAAqC,OAAO,YAG1C,CAAC,CAAC,mBAAmB;CAAE,OAAO,OAAO;CAAQ,QAAQ,OAAO;AAAO,CAAC,CAAC,CAAC;CACtE,IAAa,UAAU;EACrB,OAAO,GAAG,KAAK,MAAM;CACvB;AACF;AAEA,MAAM,QAAQ,OAAO,MACnB,OAAO,MAAM,CACX,OAAO,OAAO;CACZ,eAAe,OAAO;CACtB,QAAQ,OAAO;CACf,MAAM,OAAO,OACX,OAAO,OAAO;EAAE,cAAc,OAAO;EAAQ,MAAM,OAAO;CAAQ,CAAC,CACrE;AACF,CAAC,GACD,OAAO,OAAO;CAAE,eAAe,OAAO;CAAQ,SAAS,OAAO;AAAO,CAAC,CACxE,CAAC,CACH;AAEA,MAAM,QAAQ;;;;AAKd,MAAM,kBAAkB,OAAO,GAAG,2BAA2B,CAAC,CAAC,WAC7D,KACA;CACA,MAAM,KAAK,OAAO,WAAW;CAC7B,MAAM,OAAO,OAAO,KAAK;CACzB,MAAM,YAAY,OAAO,mBAAmB,GAAG;CAC/C,OAAO,OAAO,GAAG,OAAO,KAAK,KAAK,KAAK,WAAW,kBAAkB,CAAC;AACvE,CAAC;;;;;;;;;;AAWD,MAAa,MAAM,OAAO,GAAG,eAAe,CAAC,CAAC,WAC5C,KACA,KACA,KACA;CACA,MAAM,UACH,WACA,UACC,gBAAgB,KAAK;EACnB;EACA,QAAQ,OAAO,GAAG,mBAAmB,CAAC,CAAC,KAAK,IACxC,MAAM,eACN,MAAM;CACZ,CAAC;CACL,IAAI,EAAE,OAAO,gBAAgB,GAAG,CAAC,CAAC,KAAK,OAAO,SAAS,OAAO,KAAK,CAAC,CAAC,IACnE;CACF,MAAM,SAAS,OAAO;CACtB,MAAM,SACJ,WAEA,OAAO,IAAI,aAAa;EACtB,MAAM,QAAQ,OAAO,OAClB,YAAY,KAAK,KAAK,OAAO,CAAC,GAAG,MAAM,CAAC,CACxC,KACC,OAAO,QAAQ,OAAO,oBAAoB,KAAK,CAAC,GAChD,OAAO,SAAS,OAAO,UAAU,KAAK,CAAC,CACzC;EACF,KAAK,MAAM,QAAQ,OAAO;GACxB,MAAM,QACJ,WAAW,KAAA,IACP,KAAK,gBACL,GAAG,OAAO,GAAG,KAAK;GACxB,IAAI,aAAa,MACf,OAAO,OAAO,gBAAgB,KAAK;IAAE;IAAO,QAAQ,KAAK;GAAQ,CAAC;GACpE,IAAI,KAAK,SAAS,MAChB,OAAO,OACJ,YACC,KACA,KACA,KAAK,KAAK,cACV,KAAK,KAAK,MACV,KACF,CAAC,CACA,KAAK,OAAO,SAAS,OAAO,KAAK,CAAC,CAAC;GACxC,IAAI,KAAK,QAAQ,OAAO,MAAM,KAAK;EACrC;CACF,CAAC;CACH,OAAO,MAAM,KAAA,CAAS;AACxB,CAAC"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { acquire } from "./FileLock.js";
|
|
2
2
|
import { userCache } from "./UserCache.js";
|
|
3
3
|
import * as Effect from "effect/Effect";
|
|
4
|
+
import * as Schema from "effect/Schema";
|
|
4
5
|
import * as FileSystem from "effect/FileSystem";
|
|
5
6
|
import * as Layer from "effect/Layer";
|
|
6
7
|
import * as Path from "effect/Path";
|
|
7
8
|
import * as Context from "effect/Context";
|
|
8
|
-
import * as Schema from "effect/Schema";
|
|
9
9
|
import * as Option from "effect/Option";
|
|
10
10
|
import * as SecureRandom from "effect/crypto/SecureRandom";
|
|
11
11
|
import * as Duration from "effect/Duration";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import * as Arr from "effect/Array";
|
|
1
2
|
import * as Effect from "effect/Effect";
|
|
2
3
|
import * as String from "effect/String";
|
|
3
4
|
import { pipe } from "effect/Function";
|
|
4
|
-
import * as Arr from "effect/Array";
|
|
5
5
|
// src/internal/ResourceIdentity.ts
|
|
6
6
|
const resourceName = Effect.fn("ResourceIdentity.name")(function* (kind, fqn, instanceId) {
|
|
7
7
|
const hash = yield* Effect.promise(() => crypto.subtle.digest("SHA-256", new TextEncoder().encode(`${fqn}:${instanceId}`)));
|
package/dist/internal/Zip.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as Effect from "effect/Effect";
|
|
2
|
-
import * as FileSystem from "effect/FileSystem";
|
|
3
2
|
import * as Schema from "effect/Schema";
|
|
4
3
|
import * as Result from "effect/Result";
|
|
4
|
+
import * as FileSystem from "effect/FileSystem";
|
|
5
5
|
import { inflateRaw } from "node:zlib";
|
|
6
6
|
// src/internal/Zip.ts
|
|
7
7
|
var ZipError = class extends Schema.TaggedError()("ZipError", { reason: Schema.Literals([
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gaganref/confect-alchemy",
|
|
3
|
-
"version": "10.6.0-fork.
|
|
3
|
+
"version": "10.6.0-fork.30",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"@convex-dev/platform": "^0.1.10"
|
|
6
6
|
},
|
|
7
7
|
"peerDependencies": {
|
|
8
|
-
"@confect/cli": "npm:@gaganref/confect-cli@10.6.0-fork.
|
|
9
|
-
"@confect/core": "npm:@gaganref/confect-core@10.6.0-fork.
|
|
8
|
+
"@confect/cli": "npm:@gaganref/confect-cli@10.6.0-fork.30",
|
|
9
|
+
"@confect/core": "npm:@gaganref/confect-core@10.6.0-fork.30",
|
|
10
10
|
"alchemy": ">=2.0.0-beta.85 <2.0.0",
|
|
11
11
|
"convex": "^1.32.0",
|
|
12
12
|
"effect": "~4.1.4"
|