@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.
- package/README.md +1 -1
- package/dist/Backend.d.ts.map +1 -1
- package/dist/Backend.js +2 -3
- package/dist/Backend.js.map +1 -1
- package/dist/Code.d.ts +16 -3
- package/dist/Code.d.ts.map +1 -1
- package/dist/Code.js +13 -3
- package/dist/Code.js.map +1 -1
- package/dist/Confect.d.ts.map +1 -1
- package/dist/Confect.js +1 -2
- package/dist/Convex.d.ts.map +1 -1
- package/dist/Convex.js +3 -4
- package/dist/ConvexClient.d.ts +14 -4
- package/dist/ConvexClient.d.ts.map +1 -1
- package/dist/ConvexClient.js +44 -36
- package/dist/ConvexClient.js.map +1 -1
- package/dist/DeployKey.d.ts +22 -12
- package/dist/DeployKey.d.ts.map +1 -1
- package/dist/DeployKey.js +41 -29
- package/dist/DeployKey.js.map +1 -1
- package/dist/Deployment.d.ts +19 -10
- package/dist/Deployment.d.ts.map +1 -1
- package/dist/Deployment.js +22 -19
- package/dist/Deployment.js.map +1 -1
- package/dist/EnvironmentVariables.d.ts +23 -31
- package/dist/EnvironmentVariables.d.ts.map +1 -1
- package/dist/EnvironmentVariables.js +21 -20
- package/dist/EnvironmentVariables.js.map +1 -1
- package/dist/Project.d.ts +15 -10
- package/dist/Project.d.ts.map +1 -1
- package/dist/Project.js +23 -22
- package/dist/Project.js.map +1 -1
- package/dist/Providers.d.ts +3 -1
- package/dist/Providers.d.ts.map +1 -1
- package/dist/Providers.js +19 -18
- package/dist/Providers.js.map +1 -1
- package/dist/_virtual/_rolldown/runtime.js +5 -6
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/internal/CodeDeployment.d.ts +6 -1
- package/dist/internal/CodeDeployment.d.ts.map +1 -1
- package/dist/internal/CodeDeployment.js +10 -8
- package/dist/internal/CodeDeployment.js.map +1 -1
- package/dist/internal/CommandRunner.d.ts +6 -1
- package/dist/internal/CommandRunner.d.ts.map +1 -1
- package/dist/internal/CommandRunner.js +11 -9
- package/dist/internal/CommandRunner.js.map +1 -1
- package/dist/internal/FileLock.d.ts +7 -3
- package/dist/internal/FileLock.d.ts.map +1 -1
- package/dist/internal/FileLock.js +10 -8
- package/dist/internal/FileLock.js.map +1 -1
- package/dist/internal/Lifecycle.d.ts +3 -1
- package/dist/internal/Lifecycle.d.ts.map +1 -1
- package/dist/internal/Lifecycle.js +3 -4
- package/dist/internal/Lifecycle.js.map +1 -1
- package/dist/internal/LocalBackend.d.ts +7 -3
- package/dist/internal/LocalBackend.d.ts.map +1 -1
- package/dist/internal/LocalBackend.js +26 -18
- package/dist/internal/LocalBackend.js.map +1 -1
- package/dist/internal/LocalSidecar.d.ts +4 -1
- package/dist/internal/LocalSidecar.d.ts.map +1 -1
- package/dist/internal/LocalSidecar.js +4 -2
- package/dist/internal/LocalSidecar.js.map +1 -1
- package/dist/internal/Loopback.d.ts.map +1 -1
- package/dist/internal/Loopback.js +1 -2
- package/dist/internal/MountInit.d.ts +5 -1
- package/dist/internal/MountInit.d.ts.map +1 -1
- package/dist/internal/MountInit.js +5 -4
- package/dist/internal/MountInit.js.map +1 -1
- package/dist/internal/PushLock.d.ts +7 -3
- package/dist/internal/PushLock.d.ts.map +1 -1
- package/dist/internal/PushLock.js +7 -6
- package/dist/internal/PushLock.js.map +1 -1
- package/dist/internal/ResourceIdentity.d.ts.map +1 -1
- package/dist/internal/ResourceIdentity.js +5 -3
- package/dist/internal/ResourceIdentity.js.map +1 -1
- package/dist/internal/UserCache.d.ts +2 -0
- package/dist/internal/UserCache.d.ts.map +1 -1
- package/dist/internal/UserCache.js +5 -4
- package/dist/internal/UserCache.js.map +1 -1
- package/dist/internal/Zip.d.ts +5 -1
- package/dist/internal/Zip.d.ts.map +1 -1
- package/dist/internal/Zip.js +9 -8
- package/dist/internal/Zip.js.map +1 -1
- package/package.json +5 -5
- package/src/Backend.ts +7 -6
- package/src/Code.ts +11 -0
- package/src/ConvexClient.ts +87 -74
- package/src/DeployKey.ts +73 -44
- package/src/Deployment.ts +50 -37
- package/src/EnvironmentVariables.ts +30 -27
- package/src/Project.ts +42 -41
- package/src/Providers.ts +2 -0
- package/src/index.ts +3 -0
- package/src/internal/CodeDeployment.ts +17 -11
- package/src/internal/CommandRunner.ts +27 -26
- package/src/internal/FileLock.ts +15 -12
- package/src/internal/Lifecycle.ts +11 -7
- package/src/internal/LocalBackend.ts +45 -39
- package/src/internal/LocalSidecar.ts +3 -0
- package/src/internal/MountInit.ts +8 -6
- package/src/internal/PushLock.ts +13 -11
- package/src/internal/ResourceIdentity.ts +12 -5
- package/src/internal/UserCache.ts +13 -4
- package/src/internal/Zip.ts +13 -8
package/dist/Deployment.js
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { ConvexClient } from "./ConvexClient.js";
|
|
2
|
-
import { checkpointCreate, shouldAdopt } from "./internal/Lifecycle.js";
|
|
3
2
|
import { resourceName } from "./internal/ResourceIdentity.js";
|
|
3
|
+
import { checkpointCreate, shouldAdopt } from "./internal/Lifecycle.js";
|
|
4
4
|
import { boot, dataDirectories, remove } from "./internal/LocalBackend.js";
|
|
5
5
|
import * as Effect from "effect/Effect";
|
|
6
6
|
import * as Provider from "alchemy/Provider";
|
|
7
7
|
import { Resource } from "alchemy/Resource";
|
|
8
8
|
import * as FileSystem from "effect/FileSystem";
|
|
9
9
|
import * as Schema from "effect/Schema";
|
|
10
|
+
import * as Array from "effect/Array";
|
|
10
11
|
import { OwnedBySomeoneElse, Unowned } from "alchemy/AdoptPolicy";
|
|
11
12
|
import { isResolved } from "alchemy/Diff";
|
|
12
13
|
import * as LocalProvider from "alchemy/Local/LocalProvider";
|
|
13
14
|
import { moduleExtension } from "alchemy/Util/Node";
|
|
14
|
-
|
|
15
|
+
// src/Deployment.ts
|
|
15
16
|
const Deployment = Resource("Convex.Deployment", { defaultRemovalPolicy: "retain" });
|
|
16
17
|
var DeploymentIdentityChange = class extends Schema.TaggedError()("DeploymentIdentityChange", {
|
|
17
18
|
deploymentName: Schema.String,
|
|
@@ -27,7 +28,7 @@ var AmbiguousDeployment = class extends Schema.TaggedError()("AmbiguousDeploymen
|
|
|
27
28
|
const provider = Effect.gen(function* () {
|
|
28
29
|
const client = yield* ConvexClient;
|
|
29
30
|
const attributes = Effect.fn("Deployment.attributes")(function* (deployment) {
|
|
30
|
-
if (deployment.kind !== "cloud") return yield*
|
|
31
|
+
if (deployment.kind !== "cloud") return yield* UnsupportedLocalDeployment.make({ deploymentName: deployment.name });
|
|
31
32
|
return {
|
|
32
33
|
projectId: deployment.projectId,
|
|
33
34
|
name: deployment.name,
|
|
@@ -38,8 +39,9 @@ const provider = Effect.gen(function* () {
|
|
|
38
39
|
};
|
|
39
40
|
});
|
|
40
41
|
const find = Effect.fn("Deployment.find")(function* (projectId, reference) {
|
|
41
|
-
const
|
|
42
|
-
|
|
42
|
+
const deployments = yield* client.listDeployments(projectId);
|
|
43
|
+
const matches = Array.filter(deployments, (deployment) => deployment.kind === "cloud" && deployment.reference === reference);
|
|
44
|
+
if (matches.length > 1) return yield* AmbiguousDeployment.make({
|
|
43
45
|
projectId,
|
|
44
46
|
reference
|
|
45
47
|
});
|
|
@@ -50,7 +52,7 @@ const provider = Effect.gen(function* () {
|
|
|
50
52
|
"projectId",
|
|
51
53
|
"type",
|
|
52
54
|
"region"
|
|
53
|
-
]) if (news[field] !== void 0 && current[field] !== news[field]) return yield*
|
|
55
|
+
]) if (news[field] !== void 0 && current[field] !== news[field]) return yield* DeploymentIdentityChange.make({
|
|
54
56
|
deploymentName: current.name,
|
|
55
57
|
field,
|
|
56
58
|
current: String(current[field]),
|
|
@@ -59,36 +61,36 @@ const provider = Effect.gen(function* () {
|
|
|
59
61
|
});
|
|
60
62
|
return {
|
|
61
63
|
diff: Effect.fn("Deployment.diff")(function* ({ news, output }) {
|
|
62
|
-
if (!isResolved(news) ||
|
|
64
|
+
if (!isResolved(news) || output === void 0) return;
|
|
63
65
|
yield* validate(output, news);
|
|
64
66
|
const deployment = yield* client.getDeployment(output.name).pipe(Effect.catchTag("ConvexNotFound", () => Effect.void));
|
|
65
|
-
if (
|
|
67
|
+
if (deployment === void 0) return { action: "update" };
|
|
66
68
|
const current = yield* attributes(deployment);
|
|
67
69
|
yield* validate(current, news);
|
|
68
70
|
if ((news.reference ?? output.reference) !== current.reference) return { action: "update" };
|
|
69
71
|
}),
|
|
70
72
|
read: Effect.fn("Deployment.read")(function* ({ fqn, instanceId, olds, output }) {
|
|
71
|
-
if (output) {
|
|
73
|
+
if (output !== void 0) {
|
|
72
74
|
const deployment = yield* client.getDeployment(output.name).pipe(Effect.catchTag("ConvexNotFound", () => Effect.void));
|
|
73
|
-
return deployment ? yield* attributes(deployment) : void 0;
|
|
75
|
+
return deployment !== void 0 ? yield* attributes(deployment) : void 0;
|
|
74
76
|
}
|
|
75
77
|
if (olds.projectId === void 0) return;
|
|
76
78
|
const deployment = yield* find(olds.projectId, olds.reference ?? (yield* resourceName("deployment", fqn, instanceId)));
|
|
77
|
-
return deployment ?
|
|
79
|
+
return deployment !== void 0 ? yield* Effect.map(attributes(deployment), Unowned) : void 0;
|
|
78
80
|
}),
|
|
79
81
|
reconcile: Effect.fn("Deployment.reconcile")(function* ({ fqn, instanceId, news, output }) {
|
|
80
|
-
if (
|
|
81
|
-
if (output) yield* validate(output, news);
|
|
82
|
-
let deployment = output ? yield* client.getDeployment(output.name).pipe(Effect.catchTag("ConvexNotFound", () => Effect.void)) : void 0;
|
|
82
|
+
if (output === void 0) yield* checkpointCreate(fqn, instanceId, news);
|
|
83
|
+
if (output !== void 0) yield* validate(output, news);
|
|
84
|
+
let deployment = output !== void 0 ? yield* client.getDeployment(output.name).pipe(Effect.catchTag("ConvexNotFound", () => Effect.void)) : void 0;
|
|
83
85
|
const reference = news.reference ?? output?.reference ?? (yield* resourceName("deployment", fqn, instanceId));
|
|
84
|
-
if (
|
|
86
|
+
if (deployment === void 0) {
|
|
85
87
|
const existing = yield* find(news.projectId, reference);
|
|
86
|
-
if (existing && !(yield* shouldAdopt(fqn))) return yield* new OwnedBySomeoneElse({
|
|
88
|
+
if (existing !== void 0 && !(yield* shouldAdopt(fqn))) return yield* new OwnedBySomeoneElse({
|
|
87
89
|
message: "An existing deployment requires explicit adoption.",
|
|
88
90
|
resourceType: Deployment.Type,
|
|
89
91
|
physicalName: reference
|
|
90
92
|
});
|
|
91
|
-
if (existing) {
|
|
93
|
+
if (existing !== void 0) {
|
|
92
94
|
const adopted = yield* attributes(existing);
|
|
93
95
|
yield* validate(adopted, news);
|
|
94
96
|
yield* checkpointCreate(fqn, instanceId, news, adopted);
|
|
@@ -103,7 +105,7 @@ const provider = Effect.gen(function* () {
|
|
|
103
105
|
yield* validate(current, news);
|
|
104
106
|
if (current.reference !== reference) {
|
|
105
107
|
const existing = yield* find(news.projectId, reference);
|
|
106
|
-
if (existing && existing.name !== current.name) return yield* new OwnedBySomeoneElse({
|
|
108
|
+
if (existing !== void 0 && existing.name !== current.name) return yield* new OwnedBySomeoneElse({
|
|
107
109
|
message: "The requested deployment reference is already in use.",
|
|
108
110
|
resourceType: Deployment.Type,
|
|
109
111
|
physicalName: reference
|
|
@@ -124,6 +126,8 @@ const provider = Effect.gen(function* () {
|
|
|
124
126
|
* reloads of the stack and stops when the dev session ends. Its data lives in
|
|
125
127
|
* `.alchemy/convex/<stack>/<stage>/<name>` and is removed only when the
|
|
126
128
|
* deployment is destroyed.
|
|
129
|
+
*
|
|
130
|
+
* @stability unstable
|
|
127
131
|
*/
|
|
128
132
|
const localLayer = LocalProvider.make(Deployment, new URL(`./internal/LocalSidecar${moduleExtension(import.meta.url)}`, import.meta.url).href, Effect.gen(function* () {
|
|
129
133
|
const fs = yield* FileSystem.FileSystem;
|
|
@@ -154,7 +158,6 @@ const localLayer = LocalProvider.make(Deployment, new URL(`./internal/LocalSidec
|
|
|
154
158
|
};
|
|
155
159
|
}));
|
|
156
160
|
const layer = Provider.effect(Deployment, provider);
|
|
157
|
-
//#endregion
|
|
158
161
|
export { AmbiguousDeployment, Deployment, DeploymentIdentityChange, UnsupportedLocalDeployment, layer, localLayer, provider };
|
|
159
162
|
|
|
160
163
|
//# sourceMappingURL=Deployment.js.map
|
package/dist/Deployment.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Deployment.js","names":[],"sources":["../src/Deployment.ts"],"sourcesContent":["import type {\n CreateDeploymentType,\n PlatformDeploymentResponse,\n RegionName,\n} from \"@convex-dev/platform/managementApi\";\nimport { OwnedBySomeoneElse, Unowned } from \"alchemy/AdoptPolicy\";\nimport { isResolved } from \"alchemy/Diff\";\nimport * as LocalProvider from \"alchemy/Local/LocalProvider\";\nimport * as Provider from \"alchemy/Provider\";\nimport { Resource } from \"alchemy/Resource\";\nimport { moduleExtension } from \"alchemy/Util/Node\";\nimport * as Effect from \"effect/Effect\";\nimport * as FileSystem from \"effect/FileSystem\";\nimport * as Schema from \"effect/Schema\";\n\nimport { ConvexClient } from \"./ConvexClient.js\";\nimport type { Providers } from \"./Providers.js\";\nimport { resourceName } from \"./internal/ResourceIdentity.js\";\nimport { checkpointCreate, shouldAdopt } from \"./internal/Lifecycle.js\";\nimport { boot, dataDirectories, remove } from \"./internal/LocalBackend.js\";\n\nexport interface DeploymentProps {\n readonly projectId: number;\n readonly type: CreateDeploymentType;\n readonly reference?: string;\n readonly region?: RegionName;\n}\n\nexport interface DeploymentAttributes {\n readonly projectId: number;\n readonly name: string;\n readonly reference: string;\n readonly type: CreateDeploymentType;\n readonly url: string;\n /**\n * Always set in the cloud; a local deployment echoes the requested region.\n */\n readonly region?: RegionName;\n}\n\nexport type Deployment = Resource<\n \"Convex.Deployment\",\n DeploymentProps,\n DeploymentAttributes,\n never,\n Providers\n>;\nexport const Deployment = Resource<Deployment>(\"Convex.Deployment\", {\n defaultRemovalPolicy: \"retain\",\n});\n\nexport class DeploymentIdentityChange extends Schema.TaggedError<DeploymentIdentityChange>()(\n \"DeploymentIdentityChange\",\n {\n deploymentName: Schema.String,\n field: Schema.String,\n current: Schema.String,\n requested: Schema.String,\n },\n) {}\n\nexport class UnsupportedLocalDeployment extends Schema.TaggedError<UnsupportedLocalDeployment>()(\n \"UnsupportedLocalDeployment\",\n { deploymentName: Schema.String },\n) {}\n\nexport class AmbiguousDeployment extends Schema.TaggedError<AmbiguousDeployment>()(\n \"AmbiguousDeployment\",\n { projectId: Schema.Finite, reference: Schema.String },\n) {}\n\nexport const provider = Effect.gen(function* () {\n const client = yield* ConvexClient;\n const attributes = Effect.fn(\"Deployment.attributes\")(function* (\n deployment: PlatformDeploymentResponse,\n ) {\n if (deployment.kind !== \"cloud\")\n return yield* new UnsupportedLocalDeployment({\n deploymentName: deployment.name,\n });\n return {\n projectId: deployment.projectId,\n name: deployment.name,\n reference: deployment.reference,\n type: deployment.deploymentType,\n url: deployment.deploymentUrl,\n region: deployment.region,\n } satisfies DeploymentAttributes;\n });\n const find = Effect.fn(\"Deployment.find\")(function* (\n projectId: number,\n reference: string,\n ) {\n const matches = (yield* client.listDeployments(projectId)).filter(\n (deployment) =>\n deployment.kind === \"cloud\" && deployment.reference === reference,\n );\n if (matches.length > 1)\n return yield* new AmbiguousDeployment({ projectId, reference });\n return matches[0];\n });\n const validate = Effect.fn(\"Deployment.validate\")(function* (\n current: DeploymentAttributes,\n news: DeploymentProps,\n ) {\n for (const field of [\"projectId\", \"type\", \"region\"] as const) {\n if (news[field] !== undefined && current[field] !== news[field])\n return yield* new DeploymentIdentityChange({\n deploymentName: current.name,\n field,\n current: String(current[field]),\n requested: String(news[field]),\n });\n }\n });\n return {\n diff: Effect.fn(\"Deployment.diff\")(function* ({ news, output }) {\n if (!isResolved(news) || !output) return;\n yield* validate(output, news);\n const deployment = yield* client\n .getDeployment(output.name)\n .pipe(Effect.catchTag(\"ConvexNotFound\", () => Effect.void));\n if (!deployment) return { action: \"update\" };\n const current = yield* attributes(deployment);\n yield* validate(current, news);\n if ((news.reference ?? output.reference) !== current.reference)\n return { action: \"update\" };\n }),\n read: Effect.fn(\"Deployment.read\")(function* ({\n fqn,\n instanceId,\n olds,\n output,\n }) {\n if (output) {\n const deployment = yield* client\n .getDeployment(output.name)\n .pipe(Effect.catchTag(\"ConvexNotFound\", () => Effect.void));\n return deployment ? yield* attributes(deployment) : undefined;\n }\n if (olds.projectId === undefined) return;\n const deployment = yield* find(\n olds.projectId,\n olds.reference ?? (yield* resourceName(\"deployment\", fqn, instanceId)),\n );\n return deployment ? Unowned(yield* attributes(deployment)) : undefined;\n }),\n reconcile: Effect.fn(\"Deployment.reconcile\")(function* ({\n fqn,\n instanceId,\n news,\n output,\n }) {\n if (!output) yield* checkpointCreate(fqn, instanceId, news);\n if (output) yield* validate(output, news);\n let deployment = output\n ? yield* client\n .getDeployment(output.name)\n .pipe(Effect.catchTag(\"ConvexNotFound\", () => Effect.void))\n : undefined;\n const reference =\n news.reference ??\n output?.reference ??\n (yield* resourceName(\"deployment\", fqn, instanceId));\n if (!deployment) {\n const existing = yield* find(news.projectId, reference);\n if (existing && !(yield* shouldAdopt(fqn)))\n return yield* new OwnedBySomeoneElse({\n message: \"An existing deployment requires explicit adoption.\",\n resourceType: Deployment.Type,\n physicalName: reference,\n });\n if (existing) {\n const adopted = yield* attributes(existing);\n yield* validate(adopted, news);\n yield* checkpointCreate(fqn, instanceId, news, adopted);\n deployment = existing;\n } else {\n deployment = yield* client.createDeployment(news.projectId, {\n type: news.type,\n reference,\n ...(news.region === undefined ? {} : { region: news.region }),\n });\n }\n }\n const current = yield* attributes(deployment);\n yield* validate(current, news);\n if (current.reference !== reference) {\n const existing = yield* find(news.projectId, reference);\n if (existing && existing.name !== current.name)\n return yield* new OwnedBySomeoneElse({\n message: \"The requested deployment reference is already in use.\",\n resourceType: Deployment.Type,\n physicalName: reference,\n });\n yield* client.updateDeployment(current.name, {\n reference,\n });\n deployment = yield* client.getDeployment(current.name);\n }\n return yield* attributes(deployment);\n }),\n delete: Effect.fn(\"Deployment.delete\")(function* ({ output }) {\n yield* client\n .deleteDeployment(output.name)\n .pipe(Effect.catchTag(\"ConvexNotFound\", () => Effect.void));\n }),\n } satisfies Provider.ProviderServiceInput<Deployment>;\n});\n\ninterface LocalConfig {\n readonly name: string;\n readonly props: DeploymentProps;\n}\n\n/**\n * Under `alchemy dev` a deployment is a local Convex backend this provider\n * owns. Alchemy's dev sidecar hosts it, so the backend keeps running across\n * reloads of the stack and stops when the dev session ends. Its data lives in\n * `.alchemy/convex/<stack>/<stage>/<name>` and is removed only when the\n * deployment is destroyed.\n */\nexport const localLayer = LocalProvider.make(\n Deployment,\n new URL(\n `./internal/LocalSidecar${moduleExtension(import.meta.url)}`,\n import.meta.url,\n ).href,\n Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const directory = yield* dataDirectories;\n return {\n resolveConfig: Effect.fn(\"Deployment.localConfig\")(function* ({\n fqn,\n instanceId,\n news,\n }) {\n return {\n name: yield* resourceName(\"deployment\", fqn, instanceId),\n props: news,\n } satisfies LocalConfig;\n }),\n start: Effect.fn(\"Deployment.localStart\")(function* ({\n config,\n invalidate,\n }) {\n const backend = yield* boot(config.name, directory(config.name));\n yield* backend.exited.pipe(\n Effect.andThen(invalidate),\n Effect.forkScoped,\n );\n return {\n projectId: config.props.projectId,\n name: config.name,\n reference: config.props.reference ?? config.name,\n type: config.props.type,\n url: backend.url,\n ...(config.props.region === undefined\n ? {}\n : { region: config.props.region }),\n } satisfies DeploymentAttributes;\n }),\n stop: Effect.fn(\"Deployment.localStop\")(function* ({ fqn, instanceId }) {\n const name = yield* resourceName(\"deployment\", fqn, instanceId);\n yield* remove(name, directory(name)).pipe(\n Effect.provideService(FileSystem.FileSystem, fs),\n );\n }),\n } satisfies LocalProvider.LocalProviderSpec<\n Deployment,\n LocalConfig,\n Effect.Services<ReturnType<typeof boot>>\n >;\n }),\n);\n\nexport const layer = Provider.effect(Deployment, provider);\n"],"mappings":";;;;;;;;;;;;;;AA+CA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.ts"],"sourcesContent":["import type {\n CreateDeploymentType,\n PlatformDeploymentResponse,\n RegionName,\n} from \"@convex-dev/platform/managementApi\";\nimport { OwnedBySomeoneElse, Unowned } from \"alchemy/AdoptPolicy\";\nimport { isResolved } from \"alchemy/Diff\";\nimport * as LocalProvider from \"alchemy/Local/LocalProvider\";\nimport * as Provider from \"alchemy/Provider\";\nimport { Resource } from \"alchemy/Resource\";\nimport { moduleExtension } from \"alchemy/Util/Node\";\nimport * as Effect from \"effect/Effect\";\nimport * as FileSystem from \"effect/FileSystem\";\nimport * as Schema from \"effect/Schema\";\n\nimport { ConvexClient } from \"./ConvexClient.js\";\nimport type { Providers } from \"./Providers.js\";\nimport { resourceName } from \"./internal/ResourceIdentity.js\";\nimport { checkpointCreate, shouldAdopt } from \"./internal/Lifecycle.js\";\nimport { boot, dataDirectories, remove } from \"./internal/LocalBackend.js\";\nimport * as Array from \"effect/Array\";\n\nexport interface DeploymentProps {\n readonly projectId: number;\n readonly type: CreateDeploymentType;\n readonly reference?: string;\n readonly region?: RegionName;\n}\n\nexport interface DeploymentAttributes {\n readonly projectId: number;\n readonly name: string;\n readonly reference: string;\n readonly type: CreateDeploymentType;\n readonly url: string;\n /**\n * Always set in the cloud; a local deployment echoes the requested region.\n */\n readonly region?: RegionName;\n}\n\nexport type Deployment = Resource<\n \"Convex.Deployment\",\n DeploymentProps,\n DeploymentAttributes,\n never,\n Providers\n>;\nexport const Deployment = Resource<Deployment>(\"Convex.Deployment\", {\n defaultRemovalPolicy: \"retain\",\n});\n\nexport class DeploymentIdentityChange extends Schema.TaggedError<\n DeploymentIdentityChange,\n { readonly brand: unique symbol }\n>()(\"DeploymentIdentityChange\", {\n deploymentName: Schema.String,\n field: Schema.String,\n current: Schema.String,\n requested: Schema.String,\n}) {}\n\nexport class UnsupportedLocalDeployment extends Schema.TaggedError<\n UnsupportedLocalDeployment,\n { readonly brand: unique symbol }\n>()(\"UnsupportedLocalDeployment\", { deploymentName: Schema.String }) {}\n\nexport class AmbiguousDeployment extends Schema.TaggedError<\n AmbiguousDeployment,\n { readonly brand: unique symbol }\n>()(\"AmbiguousDeployment\", {\n projectId: Schema.Finite,\n reference: Schema.String,\n}) {}\n\nexport const provider = Effect.gen(function* () {\n const client = yield* ConvexClient;\n const attributes = Effect.fn(\"Deployment.attributes\")(function* (\n deployment: PlatformDeploymentResponse,\n ) {\n if (deployment.kind !== \"cloud\")\n return yield* UnsupportedLocalDeployment.make({\n deploymentName: deployment.name,\n });\n return {\n projectId: deployment.projectId,\n name: deployment.name,\n reference: deployment.reference,\n type: deployment.deploymentType,\n url: deployment.deploymentUrl,\n region: deployment.region,\n } satisfies DeploymentAttributes;\n });\n const find = Effect.fn(\"Deployment.find\")(function* (\n projectId: number,\n reference: string,\n ) {\n const deployments = yield* client.listDeployments(projectId);\n const matches = Array.filter(\n deployments,\n (deployment) =>\n deployment.kind === \"cloud\" && deployment.reference === reference,\n );\n if (matches.length > 1)\n return yield* AmbiguousDeployment.make({ projectId, reference });\n return matches[0];\n });\n const validate = Effect.fn(\"Deployment.validate\")(function* (\n current: DeploymentAttributes,\n news: DeploymentProps,\n ) {\n for (const field of [\"projectId\", \"type\", \"region\"] as const) {\n if (news[field] !== undefined && current[field] !== news[field])\n return yield* DeploymentIdentityChange.make({\n deploymentName: current.name,\n field,\n current: String(current[field]),\n requested: String(news[field]),\n });\n }\n });\n return {\n diff: Effect.fn(\"Deployment.diff\")(function* ({ news, output }) {\n if (!isResolved(news) || output === undefined) return;\n yield* validate(output, news);\n const deployment = yield* client\n .getDeployment(output.name)\n .pipe(Effect.catchTag(\"ConvexNotFound\", () => Effect.void));\n if (deployment === undefined) return { action: \"update\" };\n const current = yield* attributes(deployment);\n yield* validate(current, news);\n if ((news.reference ?? output.reference) !== current.reference)\n return { action: \"update\" };\n }),\n read: Effect.fn(\"Deployment.read\")(function* ({\n fqn,\n instanceId,\n olds,\n output,\n }) {\n if (output !== undefined) {\n const deployment = yield* client\n .getDeployment(output.name)\n .pipe(Effect.catchTag(\"ConvexNotFound\", () => Effect.void));\n return deployment !== undefined\n ? yield* attributes(deployment)\n : undefined;\n }\n if (olds.projectId === undefined) return;\n const deployment = yield* find(\n olds.projectId,\n olds.reference ?? (yield* resourceName(\"deployment\", fqn, instanceId)),\n );\n return deployment !== undefined\n ? yield* Effect.map(attributes(deployment), Unowned)\n : undefined;\n }),\n reconcile: Effect.fn(\"Deployment.reconcile\")(function* ({\n fqn,\n instanceId,\n news,\n output,\n }) {\n if (output === undefined) yield* checkpointCreate(fqn, instanceId, news);\n if (output !== undefined) yield* validate(output, news);\n let deployment =\n output !== undefined\n ? yield* client\n .getDeployment(output.name)\n .pipe(Effect.catchTag(\"ConvexNotFound\", () => Effect.void))\n : undefined;\n const reference =\n news.reference ??\n output?.reference ??\n (yield* resourceName(\"deployment\", fqn, instanceId));\n if (deployment === undefined) {\n const existing = yield* find(news.projectId, reference);\n if (existing !== undefined && !(yield* shouldAdopt(fqn)))\n return yield* new OwnedBySomeoneElse({\n message: \"An existing deployment requires explicit adoption.\",\n resourceType: Deployment.Type,\n physicalName: reference,\n });\n if (existing !== undefined) {\n const adopted = yield* attributes(existing);\n yield* validate(adopted, news);\n yield* checkpointCreate(fqn, instanceId, news, adopted);\n deployment = existing;\n } else {\n deployment = yield* client.createDeployment(news.projectId, {\n type: news.type,\n reference,\n ...(news.region === undefined ? {} : { region: news.region }),\n });\n }\n }\n const current = yield* attributes(deployment);\n yield* validate(current, news);\n if (current.reference !== reference) {\n const existing = yield* find(news.projectId, reference);\n if (existing !== undefined && existing.name !== current.name)\n return yield* new OwnedBySomeoneElse({\n message: \"The requested deployment reference is already in use.\",\n resourceType: Deployment.Type,\n physicalName: reference,\n });\n yield* client.updateDeployment(current.name, {\n reference,\n });\n deployment = yield* client.getDeployment(current.name);\n }\n return yield* attributes(deployment);\n }),\n delete: Effect.fn(\"Deployment.delete\")(function* ({ output }) {\n yield* client\n .deleteDeployment(output.name)\n .pipe(Effect.catchTag(\"ConvexNotFound\", () => Effect.void));\n }),\n } satisfies Provider.ProviderServiceInput<Deployment>;\n});\n\ninterface LocalConfig {\n readonly name: string;\n readonly props: DeploymentProps;\n}\n\n/**\n * Under `alchemy dev` a deployment is a local Convex backend this provider\n * owns. Alchemy's dev sidecar hosts it, so the backend keeps running across\n * reloads of the stack and stops when the dev session ends. Its data lives in\n * `.alchemy/convex/<stack>/<stage>/<name>` and is removed only when the\n * deployment is destroyed.\n *\n * @stability unstable\n */\nexport const localLayer = LocalProvider.make(\n Deployment,\n new URL(\n `./internal/LocalSidecar${moduleExtension(import.meta.url)}`,\n import.meta.url,\n ).href,\n Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const directory = yield* dataDirectories;\n return {\n resolveConfig: Effect.fn(\"Deployment.localConfig\")(function* ({\n fqn,\n instanceId,\n news,\n }) {\n return {\n name: yield* resourceName(\"deployment\", fqn, instanceId),\n props: news,\n } satisfies LocalConfig;\n }),\n start: Effect.fn(\"Deployment.localStart\")(function* ({\n config,\n invalidate,\n }) {\n const backend = yield* boot(config.name, directory(config.name));\n yield* backend.exited.pipe(\n Effect.andThen(invalidate),\n Effect.forkScoped,\n );\n return {\n projectId: config.props.projectId,\n name: config.name,\n reference: config.props.reference ?? config.name,\n type: config.props.type,\n url: backend.url,\n ...(config.props.region === undefined\n ? {}\n : { region: config.props.region }),\n } satisfies DeploymentAttributes;\n }),\n stop: Effect.fn(\"Deployment.localStop\")(function* ({ fqn, instanceId }) {\n const name = yield* resourceName(\"deployment\", fqn, instanceId);\n yield* remove(name, directory(name)).pipe(\n Effect.provideService(FileSystem.FileSystem, fs),\n );\n }),\n } satisfies LocalProvider.LocalProviderSpec<\n Deployment,\n LocalConfig,\n Effect.Services<ReturnType<typeof boot>>\n >;\n }),\n);\n\nexport const layer = Provider.effect(Deployment, provider);\n"],"mappings":";;;;;;;;;;;;;;;AAgDA,MAAa,aAAa,SAAqB,qBAAqB,EAClE,sBAAsB,SACxB,CAAC;AAED,IAAa,2BAAb,cA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Q,SAAS,OAAO,YAAY,QAAQ"}
|
|
@@ -20,10 +20,12 @@ export interface EnvironmentVariablesAttributes {
|
|
|
20
20
|
readonly originals: Readonly<Record<string, Redacted.Redacted<string>>>;
|
|
21
21
|
}
|
|
22
22
|
export type EnvironmentVariables = Resource<"Convex.EnvironmentVariables", EnvironmentVariablesProps, EnvironmentVariablesAttributes, never, Providers>;
|
|
23
|
-
export declare const EnvironmentVariables: import("alchemy
|
|
23
|
+
export declare const EnvironmentVariables: import("alchemy").ResourceClass<EnvironmentVariables>;
|
|
24
24
|
declare const EnvironmentTargetChange_base: Schema.Class<EnvironmentTargetChange, Schema.TaggedStruct<"EnvironmentTargetChange", {
|
|
25
25
|
readonly url: Schema.String;
|
|
26
|
-
}>, import("effect/Cause").YieldableError
|
|
26
|
+
}>, import("effect/Cause").YieldableError & {
|
|
27
|
+
readonly brand: unique symbol;
|
|
28
|
+
}>;
|
|
27
29
|
export declare class EnvironmentTargetChange extends EnvironmentTargetChange_base {
|
|
28
30
|
}
|
|
29
31
|
export declare const provider: Effect.Effect<{
|
|
@@ -32,9 +34,9 @@ export declare const provider: Effect.Effect<{
|
|
|
32
34
|
fqn: string;
|
|
33
35
|
instanceId: string;
|
|
34
36
|
olds: EnvironmentVariablesProps;
|
|
35
|
-
news: import("alchemy
|
|
36
|
-
oldBindings: import("alchemy
|
|
37
|
-
newBindings: import("alchemy
|
|
37
|
+
news: import("alchemy").Input<EnvironmentVariablesProps>;
|
|
38
|
+
oldBindings: import("alchemy").ResourceBinding<never>[];
|
|
39
|
+
newBindings: import("alchemy").Input<import("alchemy").ResourceBinding<never>[]>;
|
|
38
40
|
output: EnvironmentVariablesAttributes | undefined;
|
|
39
41
|
}) => Effect.Effect<{
|
|
40
42
|
action: "update";
|
|
@@ -45,14 +47,13 @@ export declare const provider: Effect.Effect<{
|
|
|
45
47
|
instanceId: string;
|
|
46
48
|
olds: EnvironmentVariablesProps;
|
|
47
49
|
output: EnvironmentVariablesAttributes | undefined;
|
|
50
|
+
previous?: EnvironmentVariablesAttributes;
|
|
48
51
|
}) => Effect.Effect<{
|
|
49
52
|
url: string;
|
|
50
53
|
ownedNames: ReadonlyArray<string>;
|
|
51
54
|
originals: Readonly<Record<string, Redacted.Redacted<string>>>;
|
|
52
55
|
deployKey: Redacted.Redacted<string>;
|
|
53
|
-
variables:
|
|
54
|
-
[k: string]: Redacted.Redacted<string>;
|
|
55
|
-
};
|
|
56
|
+
variables: Record<string, Redacted.Redacted<string>>;
|
|
56
57
|
} | undefined, ConvexClient.ConvexClientError, never>;
|
|
57
58
|
reconcile: (args_0: {
|
|
58
59
|
id: string;
|
|
@@ -62,17 +63,13 @@ export declare const provider: Effect.Effect<{
|
|
|
62
63
|
olds: EnvironmentVariablesProps | undefined;
|
|
63
64
|
output: EnvironmentVariablesAttributes | undefined;
|
|
64
65
|
session: import("alchemy/Report").ScopedPlanStatusSession;
|
|
65
|
-
bindings: import("alchemy
|
|
66
|
+
bindings: import("alchemy").ResourceBinding<never>[];
|
|
66
67
|
}) => Effect.Effect<{
|
|
67
68
|
url: string;
|
|
68
69
|
deployKey: Redacted.Redacted<string>;
|
|
69
70
|
ownedNames: string[];
|
|
70
|
-
variables:
|
|
71
|
-
|
|
72
|
-
};
|
|
73
|
-
originals: {
|
|
74
|
-
[k: string]: Redacted.Redacted<string>;
|
|
75
|
-
};
|
|
71
|
+
variables: Record<string, Redacted.Redacted<string>>;
|
|
72
|
+
originals: Record<string, Redacted.Redacted<string>>;
|
|
76
73
|
}, ConvexClient.ConvexApiError | ConvexClient.ConvexConflict | ConvexClient.ConvexNotFound | EnvironmentTargetChange | import("./internal/Lifecycle.js").LifecycleStateError | OwnedBySomeoneElse | import("alchemy/State/State").StateStoreError, never>;
|
|
77
74
|
delete: (args_0: {
|
|
78
75
|
id: string;
|
|
@@ -81,7 +78,7 @@ export declare const provider: Effect.Effect<{
|
|
|
81
78
|
olds: EnvironmentVariablesProps;
|
|
82
79
|
output: EnvironmentVariablesAttributes;
|
|
83
80
|
session: import("alchemy/Report").ScopedPlanStatusSession;
|
|
84
|
-
bindings: import("alchemy
|
|
81
|
+
bindings: import("alchemy").ResourceBinding<never>[];
|
|
85
82
|
force?: boolean;
|
|
86
83
|
}) => Effect.Effect<void, ConvexClient.ConvexApiError | ConvexClient.ConvexConflict, never>;
|
|
87
84
|
}, never, ConvexClient.ConvexClient>;
|
|
@@ -96,9 +93,9 @@ export declare const localProvider: Effect.Effect<{
|
|
|
96
93
|
fqn: string;
|
|
97
94
|
instanceId: string;
|
|
98
95
|
olds: EnvironmentVariablesProps;
|
|
99
|
-
news: import("alchemy
|
|
100
|
-
oldBindings: import("alchemy
|
|
101
|
-
newBindings: import("alchemy
|
|
96
|
+
news: import("alchemy").Input<EnvironmentVariablesProps>;
|
|
97
|
+
oldBindings: import("alchemy").ResourceBinding<never>[];
|
|
98
|
+
newBindings: import("alchemy").Input<import("alchemy").ResourceBinding<never>[]>;
|
|
102
99
|
output: EnvironmentVariablesAttributes | undefined;
|
|
103
100
|
}) => Effect.Effect<{
|
|
104
101
|
action: "update";
|
|
@@ -109,14 +106,13 @@ export declare const localProvider: Effect.Effect<{
|
|
|
109
106
|
instanceId: string;
|
|
110
107
|
olds: EnvironmentVariablesProps;
|
|
111
108
|
output: EnvironmentVariablesAttributes | undefined;
|
|
109
|
+
previous?: EnvironmentVariablesAttributes;
|
|
112
110
|
}) => Effect.Effect<{
|
|
113
111
|
url: string;
|
|
114
112
|
ownedNames: ReadonlyArray<string>;
|
|
115
113
|
originals: Readonly<Record<string, Redacted.Redacted<string>>>;
|
|
116
114
|
deployKey: Redacted.Redacted<string>;
|
|
117
|
-
variables:
|
|
118
|
-
[k: string]: Redacted.Redacted<string>;
|
|
119
|
-
};
|
|
115
|
+
variables: Record<string, Redacted.Redacted<string>>;
|
|
120
116
|
} | undefined, ConvexClient.ConvexClientError, never>;
|
|
121
117
|
reconcile: (args_0: {
|
|
122
118
|
id: string;
|
|
@@ -126,17 +122,13 @@ export declare const localProvider: Effect.Effect<{
|
|
|
126
122
|
olds: EnvironmentVariablesProps | undefined;
|
|
127
123
|
output: EnvironmentVariablesAttributes | undefined;
|
|
128
124
|
session: import("alchemy/Report").ScopedPlanStatusSession;
|
|
129
|
-
bindings: import("alchemy
|
|
125
|
+
bindings: import("alchemy").ResourceBinding<never>[];
|
|
130
126
|
}) => Effect.Effect<{
|
|
131
127
|
url: string;
|
|
132
128
|
deployKey: Redacted.Redacted<string>;
|
|
133
129
|
ownedNames: string[];
|
|
134
|
-
variables:
|
|
135
|
-
|
|
136
|
-
};
|
|
137
|
-
originals: {
|
|
138
|
-
[k: string]: Redacted.Redacted<string>;
|
|
139
|
-
};
|
|
130
|
+
variables: Record<string, Redacted.Redacted<string>>;
|
|
131
|
+
originals: Record<string, Redacted.Redacted<string>>;
|
|
140
132
|
}, ConvexClient.ConvexApiError | ConvexClient.ConvexConflict | ConvexClient.ConvexNotFound | EnvironmentTargetChange | import("./internal/Lifecycle.js").LifecycleStateError | OwnedBySomeoneElse | import("alchemy/State/State").StateStoreError, never>;
|
|
141
133
|
delete: (input: {
|
|
142
134
|
id: string;
|
|
@@ -145,9 +137,9 @@ export declare const localProvider: Effect.Effect<{
|
|
|
145
137
|
olds: EnvironmentVariablesProps;
|
|
146
138
|
output: EnvironmentVariablesAttributes;
|
|
147
139
|
session: import("alchemy/Report").ScopedPlanStatusSession;
|
|
148
|
-
bindings: import("alchemy
|
|
140
|
+
bindings: import("alchemy").ResourceBinding<never>[];
|
|
149
141
|
force?: boolean;
|
|
150
|
-
}) => Effect.Effect<void,
|
|
142
|
+
}) => Effect.Effect<void, ConvexClient.ConvexApiError | ConvexClient.ConvexConflict | Provider.ProviderError, never>;
|
|
151
143
|
}, never, ConvexClient.ConvexClient>;
|
|
152
144
|
export declare const layer: Layer.Layer<Provider.Provider<EnvironmentVariables>, never, ConvexClient.ConvexClient>;
|
|
153
145
|
export declare const localLayer: Layer.Layer<Provider.Provider<EnvironmentVariables>, never, never>;
|
|
@@ -1 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MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;CACzE;AAED,MAAM,MAAM,oBAAoB,GAAG,QAAQ,CACzC,6BAA6B,EAC7B,yBAAyB,EACzB,8BAA8B,EAC9B,KAAK,EACL,SAAS,CACV,CAAC;AACF,eAAO,MAAM,oBAAoB,uDAEhC,CAAC;;;;oBAIkB,OAAO,MAAM;;AAFjC,qBAAa,uBAAwB,SAAQ,4BAGS;CAAG;AAEzD,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;aAvBL,MAAM;oBAEC,aAAa,CAAC,MAAM,CAAC;mBAEtB,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oCAiMvE,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;aA5MV,MAAM;oBAEC,aAAa,CAAC,MAAM,CAAC;mBAEtB,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oCAuNxE,CAAC;AAEF,eAAO,MAAM,KAAK,wFAAkD,CAAC;AACrE,eAAO,MAAM,UAAU,oEAStB,CAAC"}
|
|
@@ -7,24 +7,26 @@ import * as Layer from "effect/Layer";
|
|
|
7
7
|
import * as FetchHttpClient from "effect/http/FetchHttpClient";
|
|
8
8
|
import * as Redacted from "effect/Redacted";
|
|
9
9
|
import * as Schema from "effect/Schema";
|
|
10
|
+
import * as Arr from "effect/Array";
|
|
11
|
+
import * as Rec from "effect/Record";
|
|
10
12
|
import { OwnedBySomeoneElse, Unowned } from "alchemy/AdoptPolicy";
|
|
11
13
|
import { isResolved } from "alchemy/Diff";
|
|
12
|
-
|
|
14
|
+
// src/EnvironmentVariables.ts
|
|
13
15
|
const EnvironmentVariables = Resource("Convex.EnvironmentVariables");
|
|
14
16
|
var EnvironmentTargetChange = class extends Schema.TaggedError()("EnvironmentTargetChange", { url: Schema.String }) {};
|
|
15
17
|
const provider = Effect.gen(function* () {
|
|
16
18
|
const client = yield* ConvexClient;
|
|
17
19
|
const redacted = (value) => typeof value === "string" ? Redacted.make(value) : value;
|
|
18
|
-
const valueAt = (variables, name) =>
|
|
19
|
-
const select = (variables, names) =>
|
|
20
|
+
const valueAt = (variables, name) => Rec.has(variables, name) ? variables[name] : void 0;
|
|
21
|
+
const select = (variables, names) => Rec.fromEntries(Arr.flatMap(names, (name) => !Rec.has(variables, name) ? [] : [[name, variables[name]]]));
|
|
20
22
|
return {
|
|
21
23
|
diff: Effect.fn("EnvironmentVariables.diff")(function* ({ news, output }) {
|
|
22
|
-
if (!isResolved(news) ||
|
|
23
|
-
if (news.url !== output.url) return yield*
|
|
24
|
-
const names =
|
|
25
|
-
if (names.length !== output.ownedNames.length ||
|
|
24
|
+
if (!isResolved(news) || output === void 0) return;
|
|
25
|
+
if (news.url !== output.url) return yield* EnvironmentTargetChange.make({ url: output.url });
|
|
26
|
+
const names = Rec.keys(news.variables);
|
|
27
|
+
if (names.length !== output.ownedNames.length || Arr.some(names, (name) => !output.ownedNames.includes(name))) return { action: "update" };
|
|
26
28
|
const variables = yield* client.listEnvironmentVariables(news.url, news.deployKey);
|
|
27
|
-
for (const [name, value] of
|
|
29
|
+
for (const [name, value] of Rec.toEntries(news.variables)) {
|
|
28
30
|
const observed = valueAt(variables, name);
|
|
29
31
|
if (observed === void 0 || Redacted.value(observed) !== Redacted.value(redacted(value))) return { action: "update" };
|
|
30
32
|
}
|
|
@@ -33,14 +35,14 @@ const provider = Effect.gen(function* () {
|
|
|
33
35
|
const url = output?.url ?? olds.url;
|
|
34
36
|
if (url === void 0 || olds.deployKey === void 0) return;
|
|
35
37
|
const observed = yield* client.listEnvironmentVariables(url, olds.deployKey);
|
|
36
|
-
const ownedNames = output?.ownedNames ??
|
|
38
|
+
const ownedNames = output?.ownedNames ?? Rec.keys(olds.variables);
|
|
37
39
|
const variables = select(observed, ownedNames);
|
|
38
|
-
if (output) return {
|
|
40
|
+
if (output !== void 0) return {
|
|
39
41
|
...output,
|
|
40
42
|
deployKey: olds.deployKey,
|
|
41
43
|
variables
|
|
42
44
|
};
|
|
43
|
-
if (
|
|
45
|
+
if (Rec.keys(variables).length === 0) return void 0;
|
|
44
46
|
return Unowned({
|
|
45
47
|
url,
|
|
46
48
|
deployKey: olds.deployKey,
|
|
@@ -50,11 +52,11 @@ const provider = Effect.gen(function* () {
|
|
|
50
52
|
});
|
|
51
53
|
}),
|
|
52
54
|
reconcile: Effect.fn("EnvironmentVariables.reconcile")(function* ({ fqn, instanceId, news, output }) {
|
|
53
|
-
if (
|
|
54
|
-
if (output && output.url !== news.url) return yield*
|
|
55
|
+
if (output === void 0) yield* checkpointCreate(fqn, instanceId, news);
|
|
56
|
+
if (output !== void 0 && output.url !== news.url) return yield* EnvironmentTargetChange.make({ url: output.url });
|
|
55
57
|
const observed = yield* client.listEnvironmentVariables(news.url, news.deployKey);
|
|
56
|
-
const ownedNames =
|
|
57
|
-
if (
|
|
58
|
+
const ownedNames = Rec.keys(news.variables);
|
|
59
|
+
if (output === void 0 && (yield* shouldAdopt(fqn))) {
|
|
58
60
|
const variables = select(observed, ownedNames);
|
|
59
61
|
output = {
|
|
60
62
|
url: news.url,
|
|
@@ -71,9 +73,9 @@ const provider = Effect.gen(function* () {
|
|
|
71
73
|
resourceType: EnvironmentVariables.Type,
|
|
72
74
|
physicalName: name
|
|
73
75
|
});
|
|
74
|
-
const desired =
|
|
76
|
+
const desired = Rec.fromEntries(Arr.map(Rec.toEntries(news.variables), ([name, value]) => [name, redacted(value)]));
|
|
75
77
|
const changes = [];
|
|
76
|
-
for (const [name, value] of
|
|
78
|
+
for (const [name, value] of Rec.toEntries(desired)) {
|
|
77
79
|
const current = valueAt(observed, name);
|
|
78
80
|
if (current === void 0 || Redacted.value(current) !== Redacted.value(value)) changes.push({
|
|
79
81
|
name,
|
|
@@ -81,8 +83,8 @@ const provider = Effect.gen(function* () {
|
|
|
81
83
|
});
|
|
82
84
|
}
|
|
83
85
|
for (const name of previousNames) {
|
|
84
|
-
if (
|
|
85
|
-
const original = output ? valueAt(output.originals, name) : void 0;
|
|
86
|
+
if (Rec.has(desired, name)) continue;
|
|
87
|
+
const original = output !== void 0 ? valueAt(output.originals, name) : void 0;
|
|
86
88
|
const current = valueAt(observed, name);
|
|
87
89
|
if (original !== void 0) {
|
|
88
90
|
if (current === void 0 || Redacted.value(current) !== Redacted.value(original)) changes.push({
|
|
@@ -129,7 +131,6 @@ const localProvider = Effect.map(provider, (service) => ({
|
|
|
129
131
|
}));
|
|
130
132
|
const layer = Provider.effect(EnvironmentVariables, provider);
|
|
131
133
|
const localLayer = Provider.effect(EnvironmentVariables, localProvider).pipe(Layer.provide(layer$1({ mode: "local" }).pipe(Layer.provide(FetchHttpClient.layer))));
|
|
132
|
-
//#endregion
|
|
133
134
|
export { EnvironmentTargetChange, EnvironmentVariables, layer, localLayer, localProvider, provider };
|
|
134
135
|
|
|
135
136
|
//# sourceMappingURL=EnvironmentVariables.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EnvironmentVariables.js","names":["ConvexClient.ConvexClient","ConvexClient.layer"],"sources":["../src/EnvironmentVariables.ts"],"sourcesContent":["import { OwnedBySomeoneElse, Unowned } from \"alchemy/AdoptPolicy\";\nimport { isResolved } from \"alchemy/Diff\";\nimport * as Provider from \"alchemy/Provider\";\nimport { Resource } from \"alchemy/Resource\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\nimport * as FetchHttpClient from \"effect/http/FetchHttpClient\";\nimport * as Redacted from \"effect/Redacted\";\nimport * as Schema from \"effect/Schema\";\n\nimport * as ConvexClient from \"./ConvexClient.js\";\nimport type { Providers } from \"./Providers.js\";\nimport { checkpointCreate, shouldAdopt } from \"./internal/Lifecycle.js\";\n\nexport interface EnvironmentVariablesProps {\n readonly url: string;\n readonly deployKey: Redacted.Redacted<string>;\n readonly variables: Readonly<\n Record<string, string | Redacted.Redacted<string>>\n >;\n}\n\nexport interface EnvironmentVariablesAttributes {\n readonly url: string;\n readonly deployKey: Redacted.Redacted<string>;\n readonly ownedNames: ReadonlyArray<string>;\n readonly variables: Readonly<Record<string, Redacted.Redacted<string>>>;\n readonly originals: Readonly<Record<string, Redacted.Redacted<string>>>;\n}\n\nexport type EnvironmentVariables = Resource<\n \"Convex.EnvironmentVariables\",\n EnvironmentVariablesProps,\n EnvironmentVariablesAttributes,\n never,\n Providers\n>;\nexport const EnvironmentVariables = Resource<EnvironmentVariables>(\n \"Convex.EnvironmentVariables\",\n);\n\nexport class EnvironmentTargetChange extends Schema.TaggedError<EnvironmentTargetChange>()(\n \"EnvironmentTargetChange\",\n { url: Schema.String },\n) {}\n\nexport const provider = Effect.gen(function* () {\n const client = yield* ConvexClient.ConvexClient;\n const redacted = (value: string | Redacted.Redacted<string>) =>\n typeof value === \"string\" ? Redacted.make(value) : value;\n const valueAt = (\n variables: Readonly<Record<string, Redacted.Redacted<string>>>,\n name: string,\n ) => (Object.hasOwn(variables, name) ? variables[name] : undefined);\n const select = (\n variables: Readonly<Record<string, Redacted.Redacted<string>>>,\n names: ReadonlyArray<string>,\n ) =>\n Object.fromEntries(\n names.flatMap((name) =>\n !Object.hasOwn(variables, name) ? [] : [[name, variables[name]]],\n ),\n );\n return {\n diff: Effect.fn(\"EnvironmentVariables.diff\")(function* ({ news, output }) {\n if (!isResolved(news) || !output) return;\n if (news.url !== output.url)\n return yield* new EnvironmentTargetChange({\n url: output.url,\n });\n const names = Object.keys(news.variables);\n if (\n names.length !== output.ownedNames.length ||\n names.some((name) => !output.ownedNames.includes(name))\n )\n return { action: \"update\" };\n const variables = yield* client.listEnvironmentVariables(\n news.url,\n news.deployKey,\n );\n for (const [name, value] of Object.entries(news.variables)) {\n const observed = valueAt(variables, name);\n if (\n observed === undefined ||\n Redacted.value(observed) !== Redacted.value(redacted(value))\n )\n return { action: \"update\" };\n }\n }),\n read: Effect.fn(\"EnvironmentVariables.read\")(function* ({ olds, output }) {\n const url = output?.url ?? olds.url;\n if (url === undefined || olds.deployKey === undefined) return;\n const observed = yield* client.listEnvironmentVariables(\n url,\n olds.deployKey,\n );\n const ownedNames = output?.ownedNames ?? Object.keys(olds.variables);\n const variables = select(observed, ownedNames);\n if (output) return { ...output, deployKey: olds.deployKey, variables };\n if (Object.keys(variables).length === 0) return undefined;\n return Unowned({\n url,\n deployKey: olds.deployKey,\n ownedNames,\n variables,\n originals: variables,\n });\n }),\n reconcile: Effect.fn(\"EnvironmentVariables.reconcile\")(function* ({\n fqn,\n instanceId,\n news,\n output,\n }) {\n if (!output) yield* checkpointCreate(fqn, instanceId, news);\n if (output && output.url !== news.url)\n return yield* new EnvironmentTargetChange({\n url: output.url,\n });\n const observed = yield* client.listEnvironmentVariables(\n news.url,\n news.deployKey,\n );\n const ownedNames = Object.keys(news.variables);\n if (!output && (yield* shouldAdopt(fqn))) {\n const variables = select(observed, ownedNames);\n output = {\n url: news.url,\n deployKey: news.deployKey,\n ownedNames,\n variables,\n originals: variables,\n };\n yield* checkpointCreate(fqn, instanceId, news, output);\n }\n const previousNames = output?.ownedNames ?? [];\n for (const name of ownedNames) {\n if (\n !previousNames.includes(name) &&\n valueAt(observed, name) !== undefined\n )\n return yield* new OwnedBySomeoneElse({\n message:\n \"An existing environment variable requires explicit adoption in a separate resource.\",\n resourceType: EnvironmentVariables.Type,\n physicalName: name,\n });\n }\n const desired = Object.fromEntries(\n Object.entries(news.variables).map(([name, value]) => [\n name,\n redacted(value),\n ]),\n );\n const changes: Array<{\n name: string;\n value?: Redacted.Redacted<string>;\n }> = [];\n for (const [name, value] of Object.entries(desired)) {\n const current = valueAt(observed, name);\n if (\n current === undefined ||\n Redacted.value(current) !== Redacted.value(value)\n )\n changes.push({ name, value });\n }\n for (const name of previousNames) {\n if (Object.hasOwn(desired, name)) continue;\n const original = output ? valueAt(output.originals, name) : undefined;\n const current = valueAt(observed, name);\n if (original !== undefined) {\n if (\n current === undefined ||\n Redacted.value(current) !== Redacted.value(original)\n )\n changes.push({ name, value: original });\n } else if (current !== undefined) changes.push({ name });\n }\n if (changes.length > 0)\n yield* client.updateEnvironmentVariables(\n news.url,\n news.deployKey,\n changes,\n );\n return {\n url: news.url,\n deployKey: news.deployKey,\n ownedNames,\n variables: desired,\n originals: select(output?.originals ?? {}, ownedNames),\n };\n }),\n delete: Effect.fn(\"EnvironmentVariables.delete\")(function* ({ output }) {\n const observed = yield* client\n .listEnvironmentVariables(output.url, output.deployKey)\n .pipe(Effect.catchTag(\"ConvexNotFound\", () => Effect.void));\n if (observed === undefined) return;\n const changes: Array<{\n name: string;\n value?: Redacted.Redacted<string>;\n }> = [];\n for (const name of output.ownedNames) {\n const original = valueAt(output.originals, name);\n const current = valueAt(observed, name);\n if (original !== undefined) {\n if (\n current === undefined ||\n Redacted.value(current) !== Redacted.value(original)\n )\n changes.push({ name, value: original });\n } else if (current !== undefined) changes.push({ name });\n }\n if (changes.length > 0)\n yield* client\n .updateEnvironmentVariables(output.url, output.deployKey, changes)\n .pipe(Effect.catchTag(\"ConvexNotFound\", () => Effect.void));\n }),\n } satisfies Provider.ProviderServiceInput<EnvironmentVariables>;\n});\n\n/**\n * Under `alchemy dev` variables are managed on the local backend. A backend\n * that is not running keeps its variables in its retained data, so removing\n * them is skipped rather than failing the apply.\n */\nexport const localProvider = Effect.map(\n provider,\n (service) =>\n ({\n ...service,\n delete: (input) =>\n // oxlint-disable-next-line effecttsgo/any-unknown-in-error-context -- Alchemy's provider input type erases the delete error channel.\n service.delete(input).pipe(\n Effect.catchIf(\n (error) =>\n error._tag === \"ConvexApiError\" &&\n error.code === \"TransportError\",\n () => Effect.void,\n ),\n ),\n }) satisfies Provider.ProviderServiceInput<EnvironmentVariables>,\n);\n\nexport const layer = Provider.effect(EnvironmentVariables, provider);\nexport const localLayer = Provider.effect(\n EnvironmentVariables,\n localProvider,\n).pipe(\n Layer.provide(\n ConvexClient.layer({ mode: \"local\" }).pipe(\n Layer.provide(FetchHttpClient.layer),\n ),\n ),\n);\n"],"mappings":";;;;;;;;;;;;AAqCA,MAAa,uBAAuB,SAClC,6BACF;AAEA,IAAa,0BAAb,cAA6C,OAAO,YAAqC,CAAC,CACxF,2BACA,EAAE,KAAK,OAAO,OAAO,CACvB,CAAC,CAAC,CAAC;AAEH,MAAa,WAAW,OAAO,IAAI,aAAa;CAC9C,MAAM,SAAS,OAAOA;CACtB,MAAM,YAAY,UAChB,OAAO,UAAU,WAAW,SAAS,KAAK,KAAK,IAAI;CACrD,MAAM,WACJ,WACA,SACI,OAAO,OAAO,WAAW,IAAI,IAAI,UAAU,QAAQ,KAAA;CACzD,MAAM,UACJ,WACA,UAEA,OAAO,YACL,MAAM,SAAS,SACb,CAAC,OAAO,OAAO,WAAW,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,UAAU,KAAK,CAAC,CACjE,CACF;CACF,OAAO;EACL,MAAM,OAAO,GAAG,2BAA2B,CAAC,CAAC,WAAW,EAAE,MAAM,UAAU;GACxE,IAAI,CAAC,WAAW,IAAI,KAAK,CAAC,QAAQ;GAClC,IAAI,KAAK,QAAQ,OAAO,KACtB,OAAO,OAAO,IAAI,wBAAwB,EACxC,KAAK,OAAO,IACd,CAAC;GACH,MAAM,QAAQ,OAAO,KAAK,KAAK,SAAS;GACxC,IACE,MAAM,WAAW,OAAO,WAAW,UACnC,MAAM,MAAM,SAAS,CAAC,OAAO,WAAW,SAAS,IAAI,CAAC,GAEtD,OAAO,EAAE,QAAQ,SAAS;GAC5B,MAAM,YAAY,OAAO,OAAO,yBAC9B,KAAK,KACL,KAAK,SACP;GACA,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,KAAK,SAAS,GAAG;IAC1D,MAAM,WAAW,QAAQ,WAAW,IAAI;IACxC,IACE,aAA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OACrB,yBAAyB,OAAO,KAAK,OAAO,SAAS,CAAC,CACtD,KAAK,OAAO,SAAS,wBAAwB,OAAO,IAAI,CAAC;GAC5D,IAAI,aAAa,KAAA,GAAW;GAC5B,MAAM,UAGD,CAAC;GACN,KAAK,MAAM,QAAQ,OAAO,YAAY;IACpC,MAAM,WAAW,QAAQ,OAAO,WAAW,IAAI;IAC/C,MAAM,UAAU,QAAQ,UAAU,IAAI;IACtC,IAAI,aAAa,KAAA,GAEb;SAAA,YAAY,KAAA,KACZ,SAAS,MAAM,OAAO,MAAM,SAAS,MAAM,QAAQ,GAEnD,QAAQ,KAAK;MAAE;MAAM,OAAO;KAAS,CAAC;IAAA,OACnC,IAAI,YAAY,KAAA,GAAW,QAAQ,KAAK,EAAE,KAAK,CAAC;GACzD;GACA,IAAI,QAAQ,SAAS,GACnB,OAAO,OACJ,2BAA2B,OAAO,KAAK,OAAO,WAAW,OAAO,CAAC,CACjE,KAAK,OAAO,SAAS,wBAAwB,OAAO,IAAI,CAAC;EAChE,CAAC;CACH;AACF,CAAC;;;;;;AAOD,MAAa,gBAAgB,OAAO,IAClC,WACC,aACE;CACC,GAAG;CACH,SAAS,UAEP,QAAQ,OAAO,KAAK,CAAC,CAAC,KACpB,OAAO,SACJ,UACC,MAAM,SAAS,oBACf,MAAM,SAAS,wBACX,OAAO,IACf,CACF;AACJ,EACJ;AAEA,MAAa,QAAQ,SAAS,OAAO,sBAAsB,QAAQ;AACnE,MAAa,aAAa,SAAS,OACjC,sBACA,aACF,CAAC,CAAC,KACA,MAAM,QACJC,QAAmB,EAAE,MAAM,QAAQ,CAAC,CAAC,CAAC,KACpC,MAAM,QAAQ,gBAAgB,KAAK,CACrC,CACF,CACF"}
|
|
1
|
+
{"version":3,"file":"EnvironmentVariables.js","names":["ConvexClient.ConvexClient","ConvexClient.layer"],"sources":["../src/EnvironmentVariables.ts"],"sourcesContent":["import { OwnedBySomeoneElse, Unowned } from \"alchemy/AdoptPolicy\";\nimport { isResolved } from \"alchemy/Diff\";\nimport * as Provider from \"alchemy/Provider\";\nimport { Resource } from \"alchemy/Resource\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\nimport * as FetchHttpClient from \"effect/http/FetchHttpClient\";\nimport * as Redacted from \"effect/Redacted\";\nimport * as Schema from \"effect/Schema\";\n\nimport * as ConvexClient from \"./ConvexClient.js\";\nimport type { Providers } from \"./Providers.js\";\nimport { checkpointCreate, shouldAdopt } from \"./internal/Lifecycle.js\";\nimport * as Arr from \"effect/Array\";\nimport * as Rec from \"effect/Record\";\n\nexport interface EnvironmentVariablesProps {\n readonly url: string;\n readonly deployKey: Redacted.Redacted<string>;\n readonly variables: Readonly<\n Record<string, string | Redacted.Redacted<string>>\n >;\n}\n\nexport interface EnvironmentVariablesAttributes {\n readonly url: string;\n readonly deployKey: Redacted.Redacted<string>;\n readonly ownedNames: ReadonlyArray<string>;\n readonly variables: Readonly<Record<string, Redacted.Redacted<string>>>;\n readonly originals: Readonly<Record<string, Redacted.Redacted<string>>>;\n}\n\nexport type EnvironmentVariables = Resource<\n \"Convex.EnvironmentVariables\",\n EnvironmentVariablesProps,\n EnvironmentVariablesAttributes,\n never,\n Providers\n>;\nexport const EnvironmentVariables = Resource<EnvironmentVariables>(\n \"Convex.EnvironmentVariables\",\n);\n\nexport class EnvironmentTargetChange extends Schema.TaggedError<\n EnvironmentTargetChange,\n { readonly brand: unique symbol }\n>()(\"EnvironmentTargetChange\", { url: Schema.String }) {}\n\nexport const provider = Effect.gen(function* () {\n const client = yield* ConvexClient.ConvexClient;\n const redacted = (value: string | Redacted.Redacted<string>) =>\n typeof value === \"string\" ? Redacted.make(value) : value;\n const valueAt = (\n variables: Readonly<Record<string, Redacted.Redacted<string>>>,\n name: string,\n ) => (Rec.has(variables, name) ? variables[name] : undefined);\n const select = (\n variables: Readonly<Record<string, Redacted.Redacted<string>>>,\n names: ReadonlyArray<string>,\n ) =>\n Rec.fromEntries(\n Arr.flatMap(names, (name) =>\n !Rec.has(variables, name) ? [] : [[name, variables[name]]],\n ),\n );\n return {\n diff: Effect.fn(\"EnvironmentVariables.diff\")(function* ({ news, output }) {\n if (!isResolved(news) || output === undefined) return;\n if (news.url !== output.url)\n return yield* EnvironmentTargetChange.make({\n url: output.url,\n });\n const names = Rec.keys(news.variables);\n if (\n names.length !== output.ownedNames.length ||\n Arr.some(names, (name) => !output.ownedNames.includes(name))\n )\n return { action: \"update\" };\n const variables = yield* client.listEnvironmentVariables(\n news.url,\n news.deployKey,\n );\n for (const [name, value] of Rec.toEntries(news.variables)) {\n const observed = valueAt(variables, name);\n if (\n observed === undefined ||\n Redacted.value(observed) !== Redacted.value(redacted(value))\n )\n return { action: \"update\" };\n }\n }),\n read: Effect.fn(\"EnvironmentVariables.read\")(function* ({ olds, output }) {\n const url = output?.url ?? olds.url;\n if (url === undefined || olds.deployKey === undefined) return;\n const observed = yield* client.listEnvironmentVariables(\n url,\n olds.deployKey,\n );\n const ownedNames = output?.ownedNames ?? Rec.keys(olds.variables);\n const variables = select(observed, ownedNames);\n if (output !== undefined)\n return { ...output, deployKey: olds.deployKey, variables };\n if (Rec.keys(variables).length === 0) return undefined;\n return Unowned({\n url,\n deployKey: olds.deployKey,\n ownedNames,\n variables,\n originals: variables,\n });\n }),\n reconcile: Effect.fn(\"EnvironmentVariables.reconcile\")(function* ({\n fqn,\n instanceId,\n news,\n output,\n }) {\n if (output === undefined) yield* checkpointCreate(fqn, instanceId, news);\n if (output !== undefined && output.url !== news.url)\n return yield* EnvironmentTargetChange.make({\n url: output.url,\n });\n const observed = yield* client.listEnvironmentVariables(\n news.url,\n news.deployKey,\n );\n const ownedNames = Rec.keys(news.variables);\n if (output === undefined && (yield* shouldAdopt(fqn))) {\n const variables = select(observed, ownedNames);\n output = {\n url: news.url,\n deployKey: news.deployKey,\n ownedNames,\n variables,\n originals: variables,\n };\n yield* checkpointCreate(fqn, instanceId, news, output);\n }\n const previousNames = output?.ownedNames ?? [];\n for (const name of ownedNames) {\n if (\n !previousNames.includes(name) &&\n valueAt(observed, name) !== undefined\n )\n return yield* new OwnedBySomeoneElse({\n message:\n \"An existing environment variable requires explicit adoption in a separate resource.\",\n resourceType: EnvironmentVariables.Type,\n physicalName: name,\n });\n }\n const desired = Rec.fromEntries(\n Arr.map(Rec.toEntries(news.variables), ([name, value]) => [\n name,\n redacted(value),\n ]),\n );\n const changes: Array<{\n name: string;\n value?: Redacted.Redacted<string>;\n }> = [];\n for (const [name, value] of Rec.toEntries(desired)) {\n const current = valueAt(observed, name);\n if (\n current === undefined ||\n Redacted.value(current) !== Redacted.value(value)\n )\n changes.push({ name, value });\n }\n for (const name of previousNames) {\n if (Rec.has(desired, name)) continue;\n const original =\n output !== undefined ? valueAt(output.originals, name) : undefined;\n const current = valueAt(observed, name);\n if (original !== undefined) {\n if (\n current === undefined ||\n Redacted.value(current) !== Redacted.value(original)\n )\n changes.push({ name, value: original });\n } else if (current !== undefined) changes.push({ name });\n }\n if (changes.length > 0)\n yield* client.updateEnvironmentVariables(\n news.url,\n news.deployKey,\n changes,\n );\n return {\n url: news.url,\n deployKey: news.deployKey,\n ownedNames,\n variables: desired,\n originals: select(output?.originals ?? {}, ownedNames),\n };\n }),\n delete: Effect.fn(\"EnvironmentVariables.delete\")(function* ({ output }) {\n const observed = yield* client\n .listEnvironmentVariables(output.url, output.deployKey)\n .pipe(Effect.catchTag(\"ConvexNotFound\", () => Effect.void));\n if (observed === undefined) return;\n const changes: Array<{\n name: string;\n value?: Redacted.Redacted<string>;\n }> = [];\n for (const name of output.ownedNames) {\n const original = valueAt(output.originals, name);\n const current = valueAt(observed, name);\n if (original !== undefined) {\n if (\n current === undefined ||\n Redacted.value(current) !== Redacted.value(original)\n )\n changes.push({ name, value: original });\n } else if (current !== undefined) changes.push({ name });\n }\n if (changes.length > 0)\n yield* client\n .updateEnvironmentVariables(output.url, output.deployKey, changes)\n .pipe(Effect.catchTag(\"ConvexNotFound\", () => Effect.void));\n }),\n } satisfies Provider.ProviderServiceInput<EnvironmentVariables>;\n});\n\n/**\n * Under `alchemy dev` variables are managed on the local backend. A backend\n * that is not running keeps its variables in its retained data, so removing\n * them is skipped rather than failing the apply.\n */\nexport const localProvider = Effect.map(\n provider,\n (service) =>\n ({\n ...service,\n delete: (input) =>\n service.delete(input).pipe(\n Effect.catchIf(\n (error) =>\n error._tag === \"ConvexApiError\" &&\n error.code === \"TransportError\",\n () => Effect.void,\n ),\n ),\n }) satisfies Provider.ProviderServiceInput<EnvironmentVariables>,\n);\n\nexport const layer = Provider.effect(EnvironmentVariables, provider);\nexport const localLayer = Provider.effect(\n EnvironmentVariables,\n localProvider,\n).pipe(\n Layer.provide(\n ConvexClient.layer({ mode: \"local\" }).pipe(\n Layer.provide(FetchHttpClient.layer),\n ),\n ),\n);\n"],"mappings":";;;;;;;;;;;;;;AAuCA,MAAa,uBAAuB,SAClC,6BACF;AAEA,IAAa,0BAAb,cAA6C,OAAO,YAGlD,CAAC,CAAC,2BAA2B,EAAE,KAAK,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC;AAExD,MAAa,WAAW,OAAO,IAAI,aAAa;CAC9C,MAAM,SAAS,OAAOA;CACtB,MAAM,YAAY,UAChB,OAAO,UAAU,WAAW,SAAS,KAAK,KAAK,IAAI;CACrD,MAAM,WACJ,WACA,SACI,IAAI,IAAI,WAAW,IAAI,IAAI,UAAU,QAAQ,KAAA;CACnD,MAAM,UACJ,WACA,UAEA,IAAI,YACF,IAAI,QAAQ,QAAQ,SAClB,CAAC,IAAI,IAAI,WAAW,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,UAAU,KAAK,CAAC,CAC3D,CACF;CACF,OAAO;EACL,MAAM,OAAO,GAAG,2BAA2B,CAAC,CAAC,WAAW,EAAE,MAAM,UAAU;GACxE,IAAI,CAAC,WAAW,IAAI,KAAK,WAAW,KAAA,GAAW;GAC/C,IAAI,KAAK,QAAQ,OAAO,KACtB,OAAO,OAAO,wBAAwB,KAAK,EACzC,KAAK,OAAO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,OAAO,IACf,CACF;AACJ,EACJ;AAEA,MAAa,QAAQ,SAAS,OAAO,sBAAsB,QAAQ;AACnE,MAAa,aAAa,SAAS,OACjC,sBACA,aACF,CAAC,CAAC,KACA,MAAM,QACJC,QAAmB,EAAE,MAAM,QAAQ,CAAC,CAAC,CAAC,KACpC,MAAM,QAAQ,gBAAgB,KAAK,CACrC,CACF,CACF"}
|
package/dist/Project.d.ts
CHANGED
|
@@ -16,19 +16,23 @@ export interface ProjectAttributes {
|
|
|
16
16
|
readonly slug: string;
|
|
17
17
|
}
|
|
18
18
|
export type Project = Resource<"Convex.Project", ProjectProps, ProjectAttributes, never, Providers>;
|
|
19
|
-
export declare const Project: import("alchemy
|
|
19
|
+
export declare const Project: import("alchemy").ResourceClass<Project>;
|
|
20
20
|
declare const ProjectTeamChange_base: Schema.Class<ProjectTeamChange, Schema.TaggedStruct<"ProjectTeamChange", {
|
|
21
21
|
readonly projectId: Schema.Finite;
|
|
22
22
|
readonly teamId: Schema.Finite;
|
|
23
23
|
readonly requestedTeamId: Schema.Finite;
|
|
24
|
-
}>, import("effect/Cause").YieldableError
|
|
24
|
+
}>, import("effect/Cause").YieldableError & {
|
|
25
|
+
readonly brand: unique symbol;
|
|
26
|
+
}>;
|
|
25
27
|
export declare class ProjectTeamChange extends ProjectTeamChange_base {
|
|
26
28
|
}
|
|
27
29
|
declare const AmbiguousProject_base: Schema.Class<AmbiguousProject, Schema.TaggedStruct<"AmbiguousProject", {
|
|
28
30
|
readonly teamId: Schema.Finite;
|
|
29
|
-
readonly
|
|
31
|
+
readonly projectName: Schema.String;
|
|
30
32
|
readonly projectIds: Schema.$Array<Schema.Finite>;
|
|
31
|
-
}>, import("effect/Cause").YieldableError
|
|
33
|
+
}>, import("effect/Cause").YieldableError & {
|
|
34
|
+
readonly brand: unique symbol;
|
|
35
|
+
}>;
|
|
32
36
|
export declare class AmbiguousProject extends AmbiguousProject_base {
|
|
33
37
|
}
|
|
34
38
|
export declare const provider: Effect.Effect<{
|
|
@@ -37,9 +41,9 @@ export declare const provider: Effect.Effect<{
|
|
|
37
41
|
fqn: string;
|
|
38
42
|
instanceId: string;
|
|
39
43
|
olds: ProjectProps;
|
|
40
|
-
news: import("alchemy
|
|
41
|
-
oldBindings: import("alchemy
|
|
42
|
-
newBindings: import("alchemy
|
|
44
|
+
news: import("alchemy").Input<ProjectProps>;
|
|
45
|
+
oldBindings: import("alchemy").ResourceBinding<never>[];
|
|
46
|
+
newBindings: import("alchemy").Input<import("alchemy").ResourceBinding<never>[]>;
|
|
43
47
|
output: ProjectAttributes | undefined;
|
|
44
48
|
}) => Effect.Effect<{
|
|
45
49
|
action: "update";
|
|
@@ -50,6 +54,7 @@ export declare const provider: Effect.Effect<{
|
|
|
50
54
|
instanceId: string;
|
|
51
55
|
olds: ProjectProps;
|
|
52
56
|
output: ProjectAttributes | undefined;
|
|
57
|
+
previous?: ProjectAttributes;
|
|
53
58
|
}) => Effect.Effect<ProjectAttributes | undefined, AmbiguousProject | import("./ConvexClient.js").ConvexApiError | import("./ConvexClient.js").ConvexConflict | import("./ConvexClient.js").ConvexNotFound, never>;
|
|
54
59
|
reconcile: (args_0: {
|
|
55
60
|
id: string;
|
|
@@ -59,7 +64,7 @@ export declare const provider: Effect.Effect<{
|
|
|
59
64
|
olds: ProjectProps | undefined;
|
|
60
65
|
output: ProjectAttributes | undefined;
|
|
61
66
|
session: import("alchemy/Report").ScopedPlanStatusSession;
|
|
62
|
-
bindings: import("alchemy
|
|
67
|
+
bindings: import("alchemy").ResourceBinding<never>[];
|
|
63
68
|
}) => Effect.Effect<ProjectAttributes, AmbiguousProject | import("./ConvexClient.js").ConvexApiError | import("./ConvexClient.js").ConvexConflict | import("./ConvexClient.js").ConvexNotFound | import("./internal/Lifecycle.js").LifecycleStateError | OwnedBySomeoneElse | ProjectTeamChange | import("alchemy/State/State").StateStoreError, never>;
|
|
64
69
|
delete: (args_0: {
|
|
65
70
|
id: string;
|
|
@@ -68,7 +73,7 @@ export declare const provider: Effect.Effect<{
|
|
|
68
73
|
olds: ProjectProps;
|
|
69
74
|
output: ProjectAttributes;
|
|
70
75
|
session: import("alchemy/Report").ScopedPlanStatusSession;
|
|
71
|
-
bindings: import("alchemy
|
|
76
|
+
bindings: import("alchemy").ResourceBinding<never>[];
|
|
72
77
|
force?: boolean;
|
|
73
78
|
}) => Effect.Effect<void, import("./ConvexClient.js").ConvexApiError | import("./ConvexClient.js").ConvexConflict, never>;
|
|
74
79
|
}, never, ConvexClient>;
|
|
@@ -85,7 +90,7 @@ export declare const localProvider: Effect.Effect<{
|
|
|
85
90
|
olds: ProjectProps | undefined;
|
|
86
91
|
output: ProjectAttributes | undefined;
|
|
87
92
|
session: import("alchemy/Report").ScopedPlanStatusSession;
|
|
88
|
-
bindings: import("alchemy
|
|
93
|
+
bindings: import("alchemy").ResourceBinding<never>[];
|
|
89
94
|
}) => Effect.Effect<{
|
|
90
95
|
projectId: number;
|
|
91
96
|
teamId: number;
|
package/dist/Project.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Project.d.ts","
|
|
1
|
+
{"version":3,"file":"Project.d.ts","sources":["../src/Project.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAW,MAAM,qBAAqB,CAAC;AAElE,OAAO,KAAK,QAAQ,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAKhD,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,iBAAi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