@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.
Files changed (56) hide show
  1. package/dist/Backend.d.ts +64 -5
  2. package/dist/Backend.d.ts.map +1 -1
  3. package/dist/Backend.js +187 -3
  4. package/dist/Backend.js.map +1 -1
  5. package/dist/Code.d.ts +14 -2
  6. package/dist/Code.d.ts.map +1 -1
  7. package/dist/Code.js +2 -2
  8. package/dist/Code.js.map +1 -1
  9. package/dist/Confect.d.ts +1 -1
  10. package/dist/Confect.d.ts.map +1 -1
  11. package/dist/Confect.js +8 -3
  12. package/dist/Confect.js.map +1 -1
  13. package/dist/Convex.d.ts +1 -1
  14. package/dist/Convex.d.ts.map +1 -1
  15. package/dist/Convex.js +4 -1
  16. package/dist/Convex.js.map +1 -1
  17. package/dist/ConvexClient.js +4 -4
  18. package/dist/CustomDomain.js +3 -3
  19. package/dist/DeployKey.js +3 -3
  20. package/dist/Deployment.js +2 -2
  21. package/dist/EnvironmentVariables.d.ts.map +1 -1
  22. package/dist/EnvironmentVariables.js +20 -13
  23. package/dist/EnvironmentVariables.js.map +1 -1
  24. package/dist/LogStream.js +5 -5
  25. package/dist/Project.js +2 -2
  26. package/dist/UsageLimit.js +2 -2
  27. package/dist/internal/CodeDeployment.d.ts +28 -1
  28. package/dist/internal/CodeDeployment.d.ts.map +1 -1
  29. package/dist/internal/CodeDeployment.js +85 -2
  30. package/dist/internal/CodeDeployment.js.map +1 -1
  31. package/dist/internal/CommandRunner.js +4 -4
  32. package/dist/internal/FileLock.js +1 -1
  33. package/dist/internal/FunctionsDirectory.d.ts +12 -0
  34. package/dist/internal/FunctionsDirectory.d.ts.map +1 -0
  35. package/dist/internal/FunctionsDirectory.js +22 -0
  36. package/dist/internal/FunctionsDirectory.js.map +1 -0
  37. package/dist/internal/LocalBackend.d.ts +7 -0
  38. package/dist/internal/LocalBackend.d.ts.map +1 -1
  39. package/dist/internal/LocalBackend.js +10 -3
  40. package/dist/internal/LocalBackend.js.map +1 -1
  41. package/dist/internal/MountInit.d.ts.map +1 -1
  42. package/dist/internal/MountInit.js +4 -6
  43. package/dist/internal/MountInit.js.map +1 -1
  44. package/dist/internal/PushLock.js +1 -1
  45. package/dist/internal/ResourceIdentity.js +1 -1
  46. package/dist/internal/Zip.js +1 -1
  47. package/package.json +3 -3
  48. package/src/Backend.ts +422 -12
  49. package/src/Code.ts +13 -0
  50. package/src/Confect.ts +7 -1
  51. package/src/Convex.ts +7 -1
  52. package/src/EnvironmentVariables.ts +27 -12
  53. package/src/internal/CodeDeployment.ts +115 -0
  54. package/src/internal/FunctionsDirectory.ts +27 -0
  55. package/src/internal/LocalBackend.ts +7 -0
  56. package/src/internal/MountInit.ts +3 -13
@@ -1,13 +1,13 @@
1
1
  import { ConvexClient } from "./ConvexClient.js";
2
2
  import { checkpointCreate, checkpointUpdate, shouldAdopt } from "./internal/Lifecycle.js";
3
+ import * as Array from "effect/Array";
3
4
  import * as Output from "alchemy/Output";
4
5
  import * as Effect from "effect/Effect";
6
+ import * as Record from "effect/Record";
7
+ import * as Schema from "effect/Schema";
5
8
  import * as Provider from "alchemy/Provider";
6
9
  import { Resource } from "alchemy/Resource";
7
- import * as Schema from "effect/Schema";
8
10
  import * as Option from "effect/Option";
9
- import * as Array from "effect/Array";
10
- import * as Record from "effect/Record";
11
11
  import { OwnedBySomeoneElse, Unowned } from "alchemy/AdoptPolicy";
12
12
  import { isResolved } from "alchemy/Diff";
13
13
  import { Stack } from "alchemy/Stack";
package/dist/DeployKey.js CHANGED
@@ -2,17 +2,17 @@ import { ConvexClient } from "./ConvexClient.js";
2
2
  import { resourceName } from "./internal/ResourceIdentity.js";
3
3
  import { checkpointCreate } from "./internal/Lifecycle.js";
4
4
  import { adminKey, dataDirectories } from "./internal/LocalBackend.js";
5
+ import * as Array from "effect/Array";
5
6
  import * as Effect from "effect/Effect";
7
+ import * as Redacted from "effect/Redacted";
8
+ import * as Schema from "effect/Schema";
6
9
  import * as Provider from "alchemy/Provider";
7
10
  import { Resource } from "alchemy/Resource";
8
11
  import * as FileSystem from "effect/FileSystem";
9
12
  import * as Path from "effect/Path";
10
- import * as Redacted from "effect/Redacted";
11
- import * as Schema from "effect/Schema";
12
13
  import * as Option from "effect/Option";
13
14
  import * as String from "effect/String";
14
15
  import { pipe } from "effect/Function";
15
- import * as Array from "effect/Array";
16
16
  import { isResolved } from "alchemy/Diff";
17
17
  // src/DeployKey.ts
18
18
  const DeployKey = Resource("Convex.DeployKey");
@@ -2,12 +2,12 @@ import { ConvexClient } from "./ConvexClient.js";
2
2
  import { resourceName } from "./internal/ResourceIdentity.js";
3
3
  import { checkpointCreate, shouldAdopt } from "./internal/Lifecycle.js";
4
4
  import { boot, dataDirectories, remove } from "./internal/LocalBackend.js";
5
+ import * as Array from "effect/Array";
5
6
  import * as Effect from "effect/Effect";
7
+ import * as Schema from "effect/Schema";
6
8
  import * as Provider from "alchemy/Provider";
7
9
  import { Resource } from "alchemy/Resource";
8
10
  import * as FileSystem from "effect/FileSystem";
9
- import * as Schema from "effect/Schema";
10
- import * as Array from "effect/Array";
11
11
  import { OwnedBySomeoneElse, Unowned } from "alchemy/AdoptPolicy";
12
12
  import { isResolved } from "alchemy/Diff";
13
13
  import * as LocalProvider from "alchemy/Local/LocalProvider";
@@ -1 +1 @@
1
- {"version":3,"file":"EnvironmentVariables.d.ts","sources":["../src/EnvironmentVariables.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAW,MAAM,qBAAqB,CAAC;AAElE,OAAO,KAAK,EAAE,KAAK,EAAc,MAAM,eAAe,CAAC;AAEvD,OAAO,KAAK,QAAQ,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EACL,QAAQ,EACR,KAAK,aAAa,EAEnB,MAAM,kBAAkB,CAAC;AAI1B,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAI5C,OAAO,EAAY,aAAa,EAAE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FjC,qBAAa,0BAA2B,SAAQ,+BAGkB;IAChE,IAAa,OAAO,WAEnB;CACF;;;;oBAImB,OAAO,MAAM;;AAFjC,qBAAa,iCAAkC,SAAQ,sCAKrD;IACA,IAAa,OAAO,8OASnB;CACF;AAkJD,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;aA/PL,MAAM;oBAEC,aAAa,CAAC,MAAM,CAAC;mBAEtB,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oCA+nBvE,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;aA1oBV,MAAM;oBAEC,aAAa,CAAC,MAAM,CAAC;mBAEtB,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oCAqpBxE,CAAC;AAEF,eAAO,MAAM,KAAK,wFAAkD,CAAC;AACrE,eAAO,MAAM,UAAU,oEAStB,CAAC"}
@@ -1,19 +1,19 @@
1
1
  import { PushLock, PushLockError } from "./internal/PushLock.js";
2
2
  import { ConvexApiError, ConvexClient, layer as layer$1 } from "./ConvexClient.js";
3
3
  import { checkpointCreate, shouldAdopt } from "./internal/Lifecycle.js";
4
+ import * as Arr from "effect/Array";
4
5
  import * as Output from "alchemy/Output";
5
6
  import * as Effect from "effect/Effect";
7
+ import * as Rec from "effect/Record";
8
+ import * as Redacted from "effect/Redacted";
9
+ import * as Schema from "effect/Schema";
10
+ import * as Result from "effect/Result";
6
11
  import * as Provider from "alchemy/Provider";
7
12
  import { Resource } from "alchemy/Resource";
8
13
  import * as Layer from "effect/Layer";
9
14
  import * as FetchHttpClient from "effect/http/FetchHttpClient";
10
15
  import * as Config from "effect/Config";
11
- import * as Redacted from "effect/Redacted";
12
- import * as Schema from "effect/Schema";
13
16
  import * as Option from "effect/Option";
14
- import * as Arr from "effect/Array";
15
- import * as Rec from "effect/Record";
16
- import * as Result from "effect/Result";
17
17
  import * as Duration from "effect/Duration";
18
18
  import * as Predicate from "effect/Predicate";
19
19
  import * as Schedule from "effect/Schedule";
@@ -98,20 +98,22 @@ const ownershipConflict = (variableName) => new OwnedBySomeoneElse({
98
98
  resourceType: EnvironmentVariables.Type,
99
99
  physicalName: variableName
100
100
  });
101
+ const definedVariables = (variables) => Rec.filter(variables, (value) => value !== null && value !== void 0);
101
102
  const optionsForDiff = (olds, news) => {
102
103
  if (!("variables" in news)) return {
103
104
  ...olds,
104
105
  desiredNames: void 0,
105
106
  desiredVariables: void 0
106
107
  };
108
+ const desiredVariables = !Output.isExpr(news.variables) && !Effect.isEffect(news.variables) && Predicate.isReadonlyObject(news.variables) ? definedVariables(news.variables) : void 0;
107
109
  return {
108
110
  driftPolicy: isResolved(news.driftPolicy) ? news.driftPolicy : olds.driftPolicy,
109
111
  adoptMatching: isResolved(news.adoptMatching) ? news.adoptMatching : olds.adoptMatching,
110
112
  unownedPolicy: isResolved(news.unownedPolicy) ? news.unownedPolicy : olds.unownedPolicy,
111
113
  lock: isResolved(news.lock) ? news.lock : olds.lock,
112
114
  retry: isResolved(news.retry) ? news.retry : olds.retry,
113
- desiredVariables: news.variables,
114
- desiredNames: !Output.isExpr(news.variables) && !Effect.isEffect(news.variables) && Predicate.isReadonlyObject(news.variables) ? Rec.keys(news.variables) : void 0
115
+ desiredVariables,
116
+ desiredNames: desiredVariables === void 0 ? void 0 : Rec.keys(desiredVariables)
115
117
  };
116
118
  };
117
119
  const provider = Effect.gen(function* () {
@@ -173,10 +175,11 @@ const provider = Effect.gen(function* () {
173
175
  }
174
176
  if (!isResolved(news) || output === void 0) return;
175
177
  if (news.url !== output.url) return yield* EnvironmentTargetChange.make({ url: output.url });
176
- const names = Rec.keys(news.variables);
178
+ const desired = definedVariables(news.variables);
179
+ const names = Rec.keys(desired);
177
180
  if (names.length !== output.ownedNames.length || Arr.some(names, (name) => !output.ownedNames.includes(name))) return { action: "update" };
178
181
  const variables = yield* client.listEnvironmentVariables(news.url, news.deployKey);
179
- for (const [name, value] of Rec.toEntries(news.variables)) {
182
+ for (const [name, value] of Rec.toEntries(desired)) {
180
183
  const observed = valueAt(variables, name);
181
184
  if (observed === void 0 || Redacted.value(observed) !== Redacted.value(redacted(value))) return { action: "update" };
182
185
  }
@@ -185,9 +188,9 @@ const provider = Effect.gen(function* () {
185
188
  const url = output?.url ?? olds.url;
186
189
  if (url === void 0 || olds.deployKey === void 0) return;
187
190
  const observed = yield* client.listEnvironmentVariables(url, olds.deployKey);
188
- yield* checkDrift(olds.driftPolicy, output, observed, olds.variables);
189
- yield* checkUnowned(olds.unownedPolicy, output, Rec.keys(olds.variables), observed);
190
- const ownedNames = output?.ownedNames ?? Rec.keys(olds.variables);
191
+ yield* checkDrift(olds.driftPolicy, output, observed, definedVariables(olds.variables));
192
+ yield* checkUnowned(olds.unownedPolicy, output, Rec.keys(definedVariables(olds.variables)), observed);
193
+ const ownedNames = output?.ownedNames ?? Rec.keys(definedVariables(olds.variables));
191
194
  const variables = select(observed, ownedNames);
192
195
  if (output !== void 0) return {
193
196
  ...output,
@@ -208,6 +211,10 @@ const provider = Effect.gen(function* () {
208
211
  });
209
212
  }),
210
213
  reconcile: Effect.fn("EnvironmentVariables.reconcile")(function* ({ fqn, instanceId, news, output }) {
214
+ news = {
215
+ ...news,
216
+ variables: definedVariables(news.variables)
217
+ };
211
218
  if (output === void 0) yield* checkpointCreate(fqn, instanceId, news);
212
219
  if (output !== void 0 && output.url !== news.url) return yield* EnvironmentTargetChange.make({ url: output.url });
213
220
  const observed = yield* client.listEnvironmentVariables(news.url, news.deployKey);
@@ -275,7 +282,7 @@ const provider = Effect.gen(function* () {
275
282
  const observed = yield* client.listEnvironmentVariables(output.url, output.deployKey).pipe(Effect.catchTag("ConvexNotFound", () => Effect.void));
276
283
  if (observed === void 0) return;
277
284
  yield* checkDrift(olds.driftPolicy, output, observed, {});
278
- yield* checkUnowned(olds.unownedPolicy, output, Rec.keys(olds.variables), observed);
285
+ yield* checkUnowned(olds.unownedPolicy, output, Rec.keys(definedVariables(olds.variables)), observed);
279
286
  const changes = [];
280
287
  for (const name of output.ownedNames) {
281
288
  const original = valueAt(output.originals, name);
@@ -1 +1 @@
1
- {"version":3,"file":"EnvironmentVariables.js","names":["ConvexClient.ConvexClient","ConvexClient.ConvexApiError","ConvexClient.layer"],"sources":["../src/EnvironmentVariables.ts"],"sourcesContent":["import { OwnedBySomeoneElse, Unowned } from \"alchemy/AdoptPolicy\";\nimport { isResolved } from \"alchemy/Diff\";\nimport type { Input, InputProps } from \"alchemy/Input\";\nimport * as Output from \"alchemy/Output\";\nimport * as Provider from \"alchemy/Provider\";\nimport {\n Resource,\n type ResourceClass,\n type ResourceConstructor,\n} from \"alchemy/Resource\";\nimport * as Effectable from \"effect/Effectable\";\nimport * as Config from \"effect/Config\";\nimport * as Result from \"effect/Result\";\nimport * as Duration from \"effect/Duration\";\nimport * as Option from \"effect/Option\";\nimport * as Predicate from \"effect/Predicate\";\nimport * as Schedule from \"effect/Schedule\";\nimport { PushLock, PushLockError } from \"./internal/PushLock.js\";\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 /**\n * Refuse live owned values that differ from both the last write and the\n * desired value. Defaults to `overwrite`.\n */\n readonly driftPolicy?: \"overwrite\" | \"error\";\n /**\n * Adopt unowned desired names only when their live values match. Defaults to\n * false.\n */\n readonly adoptMatching?: boolean;\n /**\n * Refuse live names that are neither owned nor desired. Defaults to `ignore`.\n */\n readonly unownedPolicy?: \"ignore\" | \"error\";\n /**\n * Share the deployment push lock for checks and writes. Absent by default.\n */\n readonly lock?: { readonly deploymentName: string };\n /**\n * Retry write conflicts only, with 1 to 10 attempts and a delay of 1 to 10000\n * ms. Absent means one attempt.\n */\n readonly retry?: {\n readonly maxAttempts: number;\n readonly delay: Duration.Input;\n };\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>;\nconst environmentVariables = Resource<EnvironmentVariables>(\n \"Convex.EnvironmentVariables\",\n);\n\n// Alchemy skips provider reads for fresh resources with unresolved inputs.\nexport const EnvironmentVariables: ResourceClass<EnvironmentVariables> =\n Object.assign(\n new Proxy(environmentVariables, {\n apply: <PropsReq>(\n target: ResourceClass<EnvironmentVariables>,\n _this: unknown,\n args:\n | [methods: object]\n | [\n id: string,\n props:\n | InputProps<EnvironmentVariablesProps>\n | Effect.Effect<\n InputProps<EnvironmentVariablesProps>,\n never,\n PropsReq\n >,\n ],\n ) => {\n if (args.length === 1)\n return Object.assign(EnvironmentVariables, args[0]);\n const [id, props] = args;\n return target(\n id,\n (Effect.isEffect(props) ? props : Effect.succeed(props)).pipe(\n Effect.flatMap((options) =>\n Effect.fromResult(validateSafety(options)).pipe(\n Effect.orDie,\n Effect.as({\n ...options,\n ...(options.retry === undefined\n ? {}\n : { retry: checkedRetry(options.retry) }),\n ...(options.lock === undefined\n ? {}\n : { lock: checkedLock(options.lock) }),\n }),\n ),\n ),\n ),\n );\n },\n }),\n Effectable.Prototype<\n Effect.Effect<ResourceConstructor<EnvironmentVariables>>\n >({\n label: \"Resource<Convex.EnvironmentVariables>\",\n evaluate: () => Effect.succeed(EnvironmentVariables),\n }),\n );\n\nexport class EnvironmentTargetChange extends Schema.TaggedError<\n EnvironmentTargetChange,\n { readonly brand: unique symbol }\n>()(\"EnvironmentTargetChange\", { url: Schema.String }) {}\n\nexport class EnvironmentVariableDrift extends Schema.TaggedError<\n EnvironmentVariableDrift,\n { readonly brand: unique symbol }\n>()(\"EnvironmentVariableDrift\", { variableName: Schema.String }) {\n override get message() {\n return `Environment variable ${this.variableName} differs from its last managed value`;\n }\n}\n\nexport class EnvironmentVariableUnowned extends Schema.TaggedError<\n EnvironmentVariableUnowned,\n { readonly brand: unique symbol }\n>()(\"EnvironmentVariableUnowned\", { variableName: Schema.String }) {\n override get message() {\n return `Environment variable ${this.variableName} is neither owned nor desired`;\n }\n}\n\nexport class EnvironmentVariablesInvalidOption extends Schema.TaggedError<\n EnvironmentVariablesInvalidOption,\n { readonly brand: unique symbol }\n>()(\"EnvironmentVariablesInvalidOption\", {\n option: Schema.Literals([\"maxAttempts\", \"delay\", \"deploymentName\"]),\n}) {\n override get message() {\n switch (this.option) {\n case \"maxAttempts\":\n return \"Environment retry maxAttempts must be an integer from 1 to 10\";\n case \"delay\":\n return \"Environment retry delay must be from 1 to 10000 milliseconds\";\n case \"deploymentName\":\n return \"Environment lock deploymentName must contain lowercase letters or digits separated by single hyphens\";\n }\n }\n}\n\ntype SafetyOptions = {\n readonly retry?: EnvironmentVariablesProps[\"retry\"];\n readonly lock?: EnvironmentVariablesProps[\"lock\"];\n};\n\nconst validateMaxAttempts = (\n maxAttempts: number,\n): Result.Result<void, EnvironmentVariablesInvalidOption> =>\n Number.isInteger(maxAttempts) && maxAttempts >= 1 && maxAttempts <= 10\n ? Result.succeed(undefined)\n : Result.fail(\n EnvironmentVariablesInvalidOption.make({ option: \"maxAttempts\" }),\n );\n\nconst validateDelay = (\n delay: Duration.Input,\n): Result.Result<Duration.Duration, EnvironmentVariablesInvalidOption> => {\n const parsed = Duration.fromInput(delay);\n return Option.isSome(parsed) &&\n Duration.toMillis(parsed.value) >= 1 &&\n Duration.toMillis(parsed.value) <= 10000\n ? Result.succeed(parsed.value)\n : Result.fail(EnvironmentVariablesInvalidOption.make({ option: \"delay\" }));\n};\n\nconst validateDeploymentName = (\n deploymentName: string,\n): Result.Result<void, EnvironmentVariablesInvalidOption> =>\n /^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(deploymentName)\n ? Result.succeed(undefined)\n : Result.fail(\n EnvironmentVariablesInvalidOption.make({ option: \"deploymentName\" }),\n );\n\nconst validateSafety = (\n options: Input<SafetyOptions>,\n): Result.Result<\n Duration.Duration | undefined,\n EnvironmentVariablesInvalidOption\n> =>\n Result.gen(function* () {\n let duration: Duration.Duration | undefined;\n if (\n \"retry\" in options &&\n options.retry !== undefined &&\n \"maxAttempts\" in options.retry &&\n \"delay\" in options.retry\n ) {\n if (isResolved(options.retry.maxAttempts))\n yield* validateMaxAttempts(options.retry.maxAttempts);\n if (isResolved(options.retry.delay))\n duration = yield* validateDelay(options.retry.delay);\n }\n if (\n \"lock\" in options &&\n options.lock !== undefined &&\n \"deploymentName\" in options.lock &&\n isResolved(options.lock.deploymentName)\n )\n yield* validateDeploymentName(options.lock.deploymentName);\n return duration;\n });\n\nconst checkedInput = <A>(\n input: Exclude<Input<A>, undefined>,\n validate: (\n value: A,\n ) => Result.Result<unknown, EnvironmentVariablesInvalidOption>,\n): Exclude<Input<A>, undefined> => {\n const check = (value: A) =>\n Effect.fromResult(validate(value)).pipe(Effect.orDie, Effect.as(value));\n if (Config.isConfig(input)) return input.pipe(Config.mapEffect(check));\n return input;\n};\n\nconst checkedRetry = (\n input: Exclude<Input<SafetyOptions[\"retry\"]>, undefined>,\n): Exclude<Input<SafetyOptions[\"retry\"]>, undefined> => {\n if (\"maxAttempts\" in input && \"delay\" in input)\n return {\n ...input,\n maxAttempts: checkedInput(input.maxAttempts, validateMaxAttempts),\n delay: checkedInput(input.delay, validateDelay),\n };\n return checkedInput(input, (retry) => validateSafety({ retry }));\n};\n\nconst checkedLock = (\n input: Exclude<Input<SafetyOptions[\"lock\"]>, undefined>,\n): Exclude<Input<SafetyOptions[\"lock\"]>, undefined> => {\n if (\"deploymentName\" in input)\n return {\n ...input,\n deploymentName: checkedInput(\n input.deploymentName,\n validateDeploymentName,\n ),\n };\n return checkedInput(input, (lock) => validateSafety({ lock }));\n};\n\nconst ownershipConflict = (variableName: string) =>\n new OwnedBySomeoneElse({\n message:\n \"An existing environment variable requires explicit adoption in a separate resource.\",\n resourceType: EnvironmentVariables.Type,\n physicalName: variableName,\n });\n\nconst optionsForDiff = (\n olds: EnvironmentVariablesProps,\n news: Input<EnvironmentVariablesProps>,\n) => {\n if (!(\"variables\" in news))\n return { ...olds, desiredNames: undefined, desiredVariables: undefined };\n return {\n driftPolicy: isResolved(news.driftPolicy)\n ? news.driftPolicy\n : olds.driftPolicy,\n adoptMatching: isResolved(news.adoptMatching)\n ? news.adoptMatching\n : olds.adoptMatching,\n unownedPolicy: isResolved(news.unownedPolicy)\n ? news.unownedPolicy\n : olds.unownedPolicy,\n lock: isResolved(news.lock) ? news.lock : olds.lock,\n retry: isResolved(news.retry) ? news.retry : olds.retry,\n desiredVariables: news.variables,\n desiredNames:\n !Output.isExpr(news.variables) &&\n !Effect.isEffect(news.variables) &&\n Predicate.isReadonlyObject(news.variables)\n ? Rec.keys<string, unknown>(news.variables)\n : undefined,\n };\n};\n\nexport const provider = Effect.gen(function* () {\n const client = yield* ConvexClient.ConvexClient;\n const lock = yield* Effect.serviceOption(PushLock);\n const withSafety = Effect.fn(\"EnvironmentVariables.withSafety\")(function* <\n A,\n E,\n R,\n >(\n options: {\n readonly lock?: EnvironmentVariablesProps[\"lock\"];\n readonly retry?: EnvironmentVariablesProps[\"retry\"];\n },\n effect: Effect.Effect<A, E, R>,\n ) {\n const duration = yield* Effect.fromResult(validateSafety(options));\n let attempt = effect;\n if (options.retry !== undefined && duration !== undefined) {\n const { maxAttempts } = options.retry;\n attempt = effect.pipe(\n Effect.retry({\n times: maxAttempts - 1,\n schedule: Schedule.spaced(duration),\n while: (error) =>\n Schema.is(ConvexClient.ConvexApiError)(error) &&\n error.serverCode === \"OptimisticConcurrencyControlFailure\",\n }),\n );\n }\n if (options.lock === undefined) return yield* attempt;\n if (Option.isNone(lock))\n return yield* PushLockError.make({\n deploymentName: options.lock.deploymentName,\n reason: \"configuration\",\n missing: \"PushLock\",\n });\n return yield* lock.value.withLock(options.lock.deploymentName, attempt);\n });\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 const checkDrift = (\n policy: EnvironmentVariablesProps[\"driftPolicy\"],\n output: EnvironmentVariablesAttributes | undefined,\n observed: ConvexClient.EnvironmentVariables,\n desired: Input<EnvironmentVariablesProps[\"variables\"]> | undefined,\n ) => {\n if (policy !== \"error\" || output === undefined) return Effect.void;\n const desiredVariables =\n Predicate.isReadonlyObject(desired) &&\n !Output.isExpr(desired) &&\n !Effect.isEffect(desired)\n ? desired\n : undefined;\n for (const name of output.ownedNames) {\n const previous = valueAt(output.variables, name);\n const current = valueAt(observed, name);\n const wanted = desiredVariables?.[name];\n if (\n current === undefined &&\n desiredVariables !== undefined &&\n !Rec.has(desiredVariables, name)\n )\n continue;\n if (\n current !== undefined &&\n (desiredVariables === undefined ||\n (wanted !== undefined && !isResolved(wanted)))\n )\n continue;\n if (\n current !== undefined &&\n (typeof wanted === \"string\" || Redacted.isRedacted(wanted)) &&\n Redacted.value(current) ===\n (typeof wanted === \"string\" ? wanted : Redacted.value(wanted))\n )\n continue;\n if (previous === undefined && current === undefined) continue;\n if (\n previous === undefined ||\n current === undefined ||\n Redacted.value(previous) !== Redacted.value(current)\n )\n return Effect.fail(\n EnvironmentVariableDrift.make({ variableName: name }),\n );\n }\n return Effect.void;\n };\n const checkUnowned = (\n policy: EnvironmentVariablesProps[\"unownedPolicy\"],\n output: EnvironmentVariablesAttributes | undefined,\n desiredNames: ReadonlyArray<string> | undefined,\n observed: ConvexClient.EnvironmentVariables,\n ) => {\n if (policy !== \"error\" || desiredNames === undefined) return Effect.void;\n for (const name of Rec.keys(observed)) {\n if (\n output?.ownedNames.includes(name) !== true &&\n !desiredNames.includes(name)\n )\n return Effect.fail(\n EnvironmentVariableUnowned.make({ variableName: name }),\n );\n }\n return Effect.void;\n };\n const service = {\n diff: Effect.fn(\"EnvironmentVariables.diff\")(function* ({\n olds,\n news,\n output,\n }) {\n const options = optionsForDiff(olds, news);\n if (\n output !== undefined &&\n (options.driftPolicy === \"error\" ||\n options.unownedPolicy === \"error\" ||\n options.adoptMatching === true)\n ) {\n const observed = yield* client.listEnvironmentVariables(\n output.url,\n output.deployKey,\n );\n yield* checkDrift(\n options.driftPolicy,\n output,\n observed,\n options.desiredVariables,\n );\n if (\n options.adoptMatching === true &&\n Predicate.isReadonlyObject(options.desiredVariables) &&\n !Output.isExpr(options.desiredVariables) &&\n !Effect.isEffect(options.desiredVariables)\n ) {\n for (const [name, wanted] of Rec.toEntries(\n options.desiredVariables,\n )) {\n const current = valueAt(observed, name);\n if (\n !output.ownedNames.includes(name) &&\n current !== undefined &&\n (typeof wanted === \"string\" || Redacted.isRedacted(wanted)) &&\n Redacted.value(current) !==\n (typeof wanted === \"string\" ? wanted : Redacted.value(wanted))\n )\n return yield* ownershipConflict(name);\n }\n }\n yield* checkUnowned(\n options.unownedPolicy,\n output,\n options.desiredNames,\n observed,\n );\n }\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 yield* checkDrift(olds.driftPolicy, output, observed, olds.variables);\n yield* checkUnowned(\n olds.unownedPolicy,\n output,\n Rec.keys(olds.variables),\n observed,\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 if (olds.adoptMatching === true) {\n for (const [name, value] of Rec.toEntries(variables)) {\n if (\n Redacted.value(value) !==\n Redacted.value(redacted(olds.variables[name]))\n )\n return yield* ownershipConflict(name);\n }\n return undefined;\n }\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 yield* checkDrift(news.driftPolicy, output, observed, news.variables);\n yield* checkUnowned(\n news.unownedPolicy,\n output,\n Rec.keys(news.variables),\n observed,\n );\n const ownedNames = Rec.keys(news.variables);\n if (\n output === undefined &&\n news.adoptMatching !== true &&\n (yield* shouldAdopt(fqn))\n ) {\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 let originals = output?.originals ?? {};\n for (const name of ownedNames) {\n const current = valueAt(observed, name);\n if (previousNames.includes(name) || current === undefined) continue;\n if (\n news.adoptMatching === true &&\n Redacted.value(current) ===\n Redacted.value(redacted(news.variables[name]))\n ) {\n originals = Rec.set(originals, name, current);\n yield* Effect.logInfo(`Adopted environment variable ${name}`);\n } else {\n return yield* ownershipConflict(name);\n }\n }\n if (output === undefined && news.adoptMatching === true) {\n yield* checkpointCreate(fqn, instanceId, news, {\n url: news.url,\n deployKey: news.deployKey,\n ownedNames,\n variables: select(observed, ownedNames),\n originals,\n } satisfies EnvironmentVariablesAttributes);\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(originals, ownedNames),\n };\n }),\n delete: Effect.fn(\"EnvironmentVariables.delete\")(function* ({\n olds,\n output,\n }) {\n const observed = yield* client\n .listEnvironmentVariables(output.url, output.deployKey)\n .pipe(Effect.catchTag(\"ConvexNotFound\", () => Effect.void));\n if (observed === undefined) return;\n yield* checkDrift(olds.driftPolicy, output, observed, {});\n yield* checkUnowned(\n olds.unownedPolicy,\n output,\n Rec.keys(olds.variables),\n observed,\n );\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 return {\n diff: (input) =>\n withSafety(optionsForDiff(input.olds, input.news), service.diff(input)),\n read: (input) => withSafety(input.olds, service.read(input)),\n reconcile: (input) => withSafety(input.news, service.reconcile(input)),\n delete: (input) => withSafety(input.olds, service.delete(input)),\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\" }).p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ConvexApiError","ConvexClient.layer"],"sources":["../src/EnvironmentVariables.ts"],"sourcesContent":["import { OwnedBySomeoneElse, Unowned } from \"alchemy/AdoptPolicy\";\nimport { isResolved } from \"alchemy/Diff\";\nimport type { Input, InputProps } from \"alchemy/Input\";\nimport * as Output from \"alchemy/Output\";\nimport * as Provider from \"alchemy/Provider\";\nimport {\n Resource,\n type ResourceClass,\n type ResourceConstructor,\n} from \"alchemy/Resource\";\nimport * as Effectable from \"effect/Effectable\";\nimport * as Config from \"effect/Config\";\nimport * as Result from \"effect/Result\";\nimport * as Duration from \"effect/Duration\";\nimport * as Option from \"effect/Option\";\nimport * as Predicate from \"effect/Predicate\";\nimport * as Schedule from \"effect/Schedule\";\nimport { PushLock, PushLockError } from \"./internal/PushLock.js\";\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 /**\n * Refuse live owned values that differ from both the last write and the\n * desired value. Defaults to `overwrite`.\n */\n readonly driftPolicy?: \"overwrite\" | \"error\";\n /**\n * Adopt unowned desired names only when their live values match. Defaults to\n * false.\n */\n readonly adoptMatching?: boolean;\n /**\n * Refuse live names that are neither owned nor desired. Defaults to `ignore`.\n */\n readonly unownedPolicy?: \"ignore\" | \"error\";\n /**\n * Share the deployment push lock for checks and writes. Absent by default.\n */\n readonly lock?: { readonly deploymentName: string };\n /**\n * Retry write conflicts only, with 1 to 10 attempts and a delay of 1 to 10000\n * ms. Absent means one attempt.\n */\n readonly retry?: {\n readonly maxAttempts: number;\n readonly delay: Duration.Input;\n };\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>;\nconst environmentVariables = Resource<EnvironmentVariables>(\n \"Convex.EnvironmentVariables\",\n);\n\n// Alchemy skips provider reads for fresh resources with unresolved inputs.\nexport const EnvironmentVariables: ResourceClass<EnvironmentVariables> =\n Object.assign(\n new Proxy(environmentVariables, {\n apply: <PropsReq>(\n target: ResourceClass<EnvironmentVariables>,\n _this: unknown,\n args:\n | [methods: object]\n | [\n id: string,\n props:\n | InputProps<EnvironmentVariablesProps>\n | Effect.Effect<\n InputProps<EnvironmentVariablesProps>,\n never,\n PropsReq\n >,\n ],\n ) => {\n if (args.length === 1)\n return Object.assign(EnvironmentVariables, args[0]);\n const [id, props] = args;\n return target(\n id,\n (Effect.isEffect(props) ? props : Effect.succeed(props)).pipe(\n Effect.flatMap((options) =>\n Effect.fromResult(validateSafety(options)).pipe(\n Effect.orDie,\n Effect.as({\n ...options,\n ...(options.retry === undefined\n ? {}\n : { retry: checkedRetry(options.retry) }),\n ...(options.lock === undefined\n ? {}\n : { lock: checkedLock(options.lock) }),\n }),\n ),\n ),\n ),\n );\n },\n }),\n Effectable.Prototype<\n Effect.Effect<ResourceConstructor<EnvironmentVariables>>\n >({\n label: \"Resource<Convex.EnvironmentVariables>\",\n evaluate: () => Effect.succeed(EnvironmentVariables),\n }),\n );\n\nexport class EnvironmentTargetChange extends Schema.TaggedError<\n EnvironmentTargetChange,\n { readonly brand: unique symbol }\n>()(\"EnvironmentTargetChange\", { url: Schema.String }) {}\n\nexport class EnvironmentVariableDrift extends Schema.TaggedError<\n EnvironmentVariableDrift,\n { readonly brand: unique symbol }\n>()(\"EnvironmentVariableDrift\", { variableName: Schema.String }) {\n override get message() {\n return `Environment variable ${this.variableName} differs from its last managed value`;\n }\n}\n\nexport class EnvironmentVariableUnowned extends Schema.TaggedError<\n EnvironmentVariableUnowned,\n { readonly brand: unique symbol }\n>()(\"EnvironmentVariableUnowned\", { variableName: Schema.String }) {\n override get message() {\n return `Environment variable ${this.variableName} is neither owned nor desired`;\n }\n}\n\nexport class EnvironmentVariablesInvalidOption extends Schema.TaggedError<\n EnvironmentVariablesInvalidOption,\n { readonly brand: unique symbol }\n>()(\"EnvironmentVariablesInvalidOption\", {\n option: Schema.Literals([\"maxAttempts\", \"delay\", \"deploymentName\"]),\n}) {\n override get message() {\n switch (this.option) {\n case \"maxAttempts\":\n return \"Environment retry maxAttempts must be an integer from 1 to 10\";\n case \"delay\":\n return \"Environment retry delay must be from 1 to 10000 milliseconds\";\n case \"deploymentName\":\n return \"Environment lock deploymentName must contain lowercase letters or digits separated by single hyphens\";\n }\n }\n}\n\ntype SafetyOptions = {\n readonly retry?: EnvironmentVariablesProps[\"retry\"];\n readonly lock?: EnvironmentVariablesProps[\"lock\"];\n};\n\nconst validateMaxAttempts = (\n maxAttempts: number,\n): Result.Result<void, EnvironmentVariablesInvalidOption> =>\n Number.isInteger(maxAttempts) && maxAttempts >= 1 && maxAttempts <= 10\n ? Result.succeed(undefined)\n : Result.fail(\n EnvironmentVariablesInvalidOption.make({ option: \"maxAttempts\" }),\n );\n\nconst validateDelay = (\n delay: Duration.Input,\n): Result.Result<Duration.Duration, EnvironmentVariablesInvalidOption> => {\n const parsed = Duration.fromInput(delay);\n return Option.isSome(parsed) &&\n Duration.toMillis(parsed.value) >= 1 &&\n Duration.toMillis(parsed.value) <= 10000\n ? Result.succeed(parsed.value)\n : Result.fail(EnvironmentVariablesInvalidOption.make({ option: \"delay\" }));\n};\n\nconst validateDeploymentName = (\n deploymentName: string,\n): Result.Result<void, EnvironmentVariablesInvalidOption> =>\n /^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(deploymentName)\n ? Result.succeed(undefined)\n : Result.fail(\n EnvironmentVariablesInvalidOption.make({ option: \"deploymentName\" }),\n );\n\nconst validateSafety = (\n options: Input<SafetyOptions>,\n): Result.Result<\n Duration.Duration | undefined,\n EnvironmentVariablesInvalidOption\n> =>\n Result.gen(function* () {\n let duration: Duration.Duration | undefined;\n if (\n \"retry\" in options &&\n options.retry !== undefined &&\n \"maxAttempts\" in options.retry &&\n \"delay\" in options.retry\n ) {\n if (isResolved(options.retry.maxAttempts))\n yield* validateMaxAttempts(options.retry.maxAttempts);\n if (isResolved(options.retry.delay))\n duration = yield* validateDelay(options.retry.delay);\n }\n if (\n \"lock\" in options &&\n options.lock !== undefined &&\n \"deploymentName\" in options.lock &&\n isResolved(options.lock.deploymentName)\n )\n yield* validateDeploymentName(options.lock.deploymentName);\n return duration;\n });\n\nconst checkedInput = <A>(\n input: Exclude<Input<A>, undefined>,\n validate: (\n value: A,\n ) => Result.Result<unknown, EnvironmentVariablesInvalidOption>,\n): Exclude<Input<A>, undefined> => {\n const check = (value: A) =>\n Effect.fromResult(validate(value)).pipe(Effect.orDie, Effect.as(value));\n if (Config.isConfig(input)) return input.pipe(Config.mapEffect(check));\n return input;\n};\n\nconst checkedRetry = (\n input: Exclude<Input<SafetyOptions[\"retry\"]>, undefined>,\n): Exclude<Input<SafetyOptions[\"retry\"]>, undefined> => {\n if (\"maxAttempts\" in input && \"delay\" in input)\n return {\n ...input,\n maxAttempts: checkedInput(input.maxAttempts, validateMaxAttempts),\n delay: checkedInput(input.delay, validateDelay),\n };\n return checkedInput(input, (retry) => validateSafety({ retry }));\n};\n\nconst checkedLock = (\n input: Exclude<Input<SafetyOptions[\"lock\"]>, undefined>,\n): Exclude<Input<SafetyOptions[\"lock\"]>, undefined> => {\n if (\"deploymentName\" in input)\n return {\n ...input,\n deploymentName: checkedInput(\n input.deploymentName,\n validateDeploymentName,\n ),\n };\n return checkedInput(input, (lock) => validateSafety({ lock }));\n};\n\nconst ownershipConflict = (variableName: string) =>\n new OwnedBySomeoneElse({\n message:\n \"An existing environment variable requires explicit adoption in a separate resource.\",\n resourceType: EnvironmentVariables.Type,\n physicalName: variableName,\n });\n\nconst definedVariables = <A>(variables: Readonly<Record<string, A>>) =>\n Rec.filter(variables, (value) => value !== null && value !== undefined);\n\nconst optionsForDiff = (\n olds: EnvironmentVariablesProps,\n news: Input<EnvironmentVariablesProps>,\n) => {\n if (!(\"variables\" in news))\n return { ...olds, desiredNames: undefined, desiredVariables: undefined };\n const desiredVariables =\n !Output.isExpr(news.variables) &&\n !Effect.isEffect(news.variables) &&\n Predicate.isReadonlyObject(news.variables)\n ? definedVariables<Input<string | Redacted.Redacted<string>>>(\n news.variables,\n )\n : undefined;\n return {\n driftPolicy: isResolved(news.driftPolicy)\n ? news.driftPolicy\n : olds.driftPolicy,\n adoptMatching: isResolved(news.adoptMatching)\n ? news.adoptMatching\n : olds.adoptMatching,\n unownedPolicy: isResolved(news.unownedPolicy)\n ? news.unownedPolicy\n : olds.unownedPolicy,\n lock: isResolved(news.lock) ? news.lock : olds.lock,\n retry: isResolved(news.retry) ? news.retry : olds.retry,\n desiredVariables,\n desiredNames:\n desiredVariables === undefined ? undefined : Rec.keys(desiredVariables),\n };\n};\n\nexport const provider = Effect.gen(function* () {\n const client = yield* ConvexClient.ConvexClient;\n const lock = yield* Effect.serviceOption(PushLock);\n const withSafety = Effect.fn(\"EnvironmentVariables.withSafety\")(function* <\n A,\n E,\n R,\n >(\n options: {\n readonly lock?: EnvironmentVariablesProps[\"lock\"];\n readonly retry?: EnvironmentVariablesProps[\"retry\"];\n },\n effect: Effect.Effect<A, E, R>,\n ) {\n const duration = yield* Effect.fromResult(validateSafety(options));\n let attempt = effect;\n if (options.retry !== undefined && duration !== undefined) {\n const { maxAttempts } = options.retry;\n attempt = effect.pipe(\n Effect.retry({\n times: maxAttempts - 1,\n schedule: Schedule.spaced(duration),\n while: (error) =>\n Schema.is(ConvexClient.ConvexApiError)(error) &&\n error.serverCode === \"OptimisticConcurrencyControlFailure\",\n }),\n );\n }\n if (options.lock === undefined) return yield* attempt;\n if (Option.isNone(lock))\n return yield* PushLockError.make({\n deploymentName: options.lock.deploymentName,\n reason: \"configuration\",\n missing: \"PushLock\",\n });\n return yield* lock.value.withLock(options.lock.deploymentName, attempt);\n });\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 const checkDrift = (\n policy: EnvironmentVariablesProps[\"driftPolicy\"],\n output: EnvironmentVariablesAttributes | undefined,\n observed: ConvexClient.EnvironmentVariables,\n desired: Input<EnvironmentVariablesProps[\"variables\"]> | undefined,\n ) => {\n if (policy !== \"error\" || output === undefined) return Effect.void;\n const desiredVariables =\n Predicate.isReadonlyObject(desired) &&\n !Output.isExpr(desired) &&\n !Effect.isEffect(desired)\n ? desired\n : undefined;\n for (const name of output.ownedNames) {\n const previous = valueAt(output.variables, name);\n const current = valueAt(observed, name);\n const wanted = desiredVariables?.[name];\n if (\n current === undefined &&\n desiredVariables !== undefined &&\n !Rec.has(desiredVariables, name)\n )\n continue;\n if (\n current !== undefined &&\n (desiredVariables === undefined ||\n (wanted !== undefined && !isResolved(wanted)))\n )\n continue;\n if (\n current !== undefined &&\n (typeof wanted === \"string\" || Redacted.isRedacted(wanted)) &&\n Redacted.value(current) ===\n (typeof wanted === \"string\" ? wanted : Redacted.value(wanted))\n )\n continue;\n if (previous === undefined && current === undefined) continue;\n if (\n previous === undefined ||\n current === undefined ||\n Redacted.value(previous) !== Redacted.value(current)\n )\n return Effect.fail(\n EnvironmentVariableDrift.make({ variableName: name }),\n );\n }\n return Effect.void;\n };\n const checkUnowned = (\n policy: EnvironmentVariablesProps[\"unownedPolicy\"],\n output: EnvironmentVariablesAttributes | undefined,\n desiredNames: ReadonlyArray<string> | undefined,\n observed: ConvexClient.EnvironmentVariables,\n ) => {\n if (policy !== \"error\" || desiredNames === undefined) return Effect.void;\n for (const name of Rec.keys(observed)) {\n if (\n output?.ownedNames.includes(name) !== true &&\n !desiredNames.includes(name)\n )\n return Effect.fail(\n EnvironmentVariableUnowned.make({ variableName: name }),\n );\n }\n return Effect.void;\n };\n const service = {\n diff: Effect.fn(\"EnvironmentVariables.diff\")(function* ({\n olds,\n news,\n output,\n }) {\n const options = optionsForDiff(olds, news);\n if (\n output !== undefined &&\n (options.driftPolicy === \"error\" ||\n options.unownedPolicy === \"error\" ||\n options.adoptMatching === true)\n ) {\n const observed = yield* client.listEnvironmentVariables(\n output.url,\n output.deployKey,\n );\n yield* checkDrift(\n options.driftPolicy,\n output,\n observed,\n options.desiredVariables,\n );\n if (\n options.adoptMatching === true &&\n Predicate.isReadonlyObject(options.desiredVariables) &&\n !Output.isExpr(options.desiredVariables) &&\n !Effect.isEffect(options.desiredVariables)\n ) {\n for (const [name, wanted] of Rec.toEntries(\n options.desiredVariables,\n )) {\n const current = valueAt(observed, name);\n if (\n !output.ownedNames.includes(name) &&\n current !== undefined &&\n (typeof wanted === \"string\" || Redacted.isRedacted(wanted)) &&\n Redacted.value(current) !==\n (typeof wanted === \"string\" ? wanted : Redacted.value(wanted))\n )\n return yield* ownershipConflict(name);\n }\n }\n yield* checkUnowned(\n options.unownedPolicy,\n output,\n options.desiredNames,\n observed,\n );\n }\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 desired = definedVariables(news.variables);\n const names = Rec.keys(desired);\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(desired)) {\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 yield* checkDrift(\n olds.driftPolicy,\n output,\n observed,\n definedVariables(olds.variables),\n );\n yield* checkUnowned(\n olds.unownedPolicy,\n output,\n Rec.keys(definedVariables(olds.variables)),\n observed,\n );\n const ownedNames =\n output?.ownedNames ?? Rec.keys(definedVariables(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 if (olds.adoptMatching === true) {\n for (const [name, value] of Rec.toEntries(variables)) {\n if (\n Redacted.value(value) !==\n Redacted.value(redacted(olds.variables[name]))\n )\n return yield* ownershipConflict(name);\n }\n return undefined;\n }\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 news = { ...news, variables: definedVariables(news.variables) };\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 yield* checkDrift(news.driftPolicy, output, observed, news.variables);\n yield* checkUnowned(\n news.unownedPolicy,\n output,\n Rec.keys(news.variables),\n observed,\n );\n const ownedNames = Rec.keys(news.variables);\n if (\n output === undefined &&\n news.adoptMatching !== true &&\n (yield* shouldAdopt(fqn))\n ) {\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 let originals = output?.originals ?? {};\n for (const name of ownedNames) {\n const current = valueAt(observed, name);\n if (previousNames.includes(name) || current === undefined) continue;\n if (\n news.adoptMatching === true &&\n Redacted.value(current) ===\n Redacted.value(redacted(news.variables[name]))\n ) {\n originals = Rec.set(originals, name, current);\n yield* Effect.logInfo(`Adopted environment variable ${name}`);\n } else {\n return yield* ownershipConflict(name);\n }\n }\n if (output === undefined && news.adoptMatching === true) {\n yield* checkpointCreate(fqn, instanceId, news, {\n url: news.url,\n deployKey: news.deployKey,\n ownedNames,\n variables: select(observed, ownedNames),\n originals,\n } satisfies EnvironmentVariablesAttributes);\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(originals, ownedNames),\n };\n }),\n delete: Effect.fn(\"EnvironmentVariables.delete\")(function* ({\n olds,\n output,\n }) {\n const observed = yield* client\n .listEnvironmentVariables(output.url, output.deployKey)\n .pipe(Effect.catchTag(\"ConvexNotFound\", () => Effect.void));\n if (observed === undefined) return;\n yield* checkDrift(olds.driftPolicy, output, observed, {});\n yield* checkUnowned(\n olds.unownedPolicy,\n output,\n Rec.keys(definedVariables(olds.variables)),\n observed,\n );\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 return {\n diff: (input) =>\n withSafety(optionsForDiff(input.olds, input.news), service.diff(input)),\n read: (input) => withSafety(input.olds, service.read(input)),\n reconcile: (input) => withSafety(input.news, service.reconcile(input)),\n delete: (input) => withSafety(input.olds, service.delete(input)),\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":";;;;;;;;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Aa,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/LogStream.js CHANGED
@@ -1,18 +1,18 @@
1
1
  import { ConvexClient, layer as layer$1 } from "./ConvexClient.js";
2
2
  import { checkpointCreate } from "./internal/Lifecycle.js";
3
3
  import { Topics } from "./internal/LogStream.js";
4
+ import * as Array from "effect/Array";
4
5
  import * as Output from "alchemy/Output";
5
6
  import * as Effect from "effect/Effect";
7
+ import * as Record from "effect/Record";
8
+ import * as Redacted from "effect/Redacted";
9
+ import * as Schema from "effect/Schema";
10
+ import * as Result from "effect/Result";
6
11
  import * as Provider from "alchemy/Provider";
7
12
  import { Resource } from "alchemy/Resource";
8
13
  import * as Layer from "effect/Layer";
9
14
  import * as FetchHttpClient from "effect/http/FetchHttpClient";
10
- import * as Redacted from "effect/Redacted";
11
- import * as Schema from "effect/Schema";
12
15
  import * as Option from "effect/Option";
13
- import * as Array from "effect/Array";
14
- import * as Record from "effect/Record";
15
- import * as Result from "effect/Result";
16
16
  import { deepEqual, isResolved } from "alchemy/Diff";
17
17
  import * as Effectable from "effect/Effectable";
18
18
  import { Stack } from "alchemy/Stack";
package/dist/Project.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import { ConvexClient } from "./ConvexClient.js";
2
2
  import { resourceName } from "./internal/ResourceIdentity.js";
3
3
  import { checkpointCreate, shouldAdopt } from "./internal/Lifecycle.js";
4
+ import * as Array from "effect/Array";
4
5
  import * as Effect from "effect/Effect";
6
+ import * as Schema from "effect/Schema";
5
7
  import * as Provider from "alchemy/Provider";
6
8
  import { Resource } from "alchemy/Resource";
7
- import * as Schema from "effect/Schema";
8
- import * as Array from "effect/Array";
9
9
  import { OwnedBySomeoneElse, Unowned } from "alchemy/AdoptPolicy";
10
10
  import { isResolved } from "alchemy/Diff";
11
11
  // src/Project.ts
@@ -1,11 +1,11 @@
1
1
  import { ConvexClient } from "./ConvexClient.js";
2
2
  import { checkpointCreate, shouldAdopt } from "./internal/Lifecycle.js";
3
+ import * as Array from "effect/Array";
3
4
  import * as Effect from "effect/Effect";
5
+ import * as Schema from "effect/Schema";
4
6
  import * as Provider from "alchemy/Provider";
5
7
  import { Resource } from "alchemy/Resource";
6
- import * as Schema from "effect/Schema";
7
8
  import * as Option from "effect/Option";
8
- import * as Array from "effect/Array";
9
9
  import { OwnedBySomeoneElse, Unowned } from "alchemy/AdoptPolicy";
10
10
  import { isResolved } from "alchemy/Diff";
11
11
  // src/UsageLimit.ts
@@ -1,8 +1,10 @@
1
1
  import type { ProviderMode } from "alchemy/ProviderMode";
2
2
  import * as Effect from "effect/Effect";
3
+ import * as FileSystem from "effect/FileSystem";
3
4
  import * as Path from "effect/Path";
4
5
  import * as Schema from "effect/Schema";
5
6
  import type { CodeProps } from "../Code.js";
7
+ import { ConvexClient } from "../ConvexClient.js";
6
8
  import { CommandRunner } from "./CommandRunner.js";
7
9
  import * as MountInit from "./MountInit.js";
8
10
  import { PushLock } from "./PushLock.js";
@@ -13,12 +15,37 @@ declare const InvalidDeploymentTarget_base: Schema.Class<InvalidDeploymentTarget
13
15
  }>;
14
16
  export declare class InvalidDeploymentTarget extends InvalidDeploymentTarget_base {
15
17
  }
18
+ declare const HealthCheckFailed_base: Schema.Class<HealthCheckFailed, Schema.TaggedStruct<"HealthCheckFailed", {
19
+ readonly expected: Schema.String;
20
+ readonly answered: Schema.optional<Schema.String>;
21
+ readonly detail: Schema.optional<Schema.String>;
22
+ }>, import("effect/Cause").YieldableError & {
23
+ readonly brand: unique symbol;
24
+ }>;
25
+ export declare class HealthCheckFailed extends HealthCheckFailed_base {
26
+ get message(): string;
27
+ }
28
+ declare const StaleManifest_base: Schema.Class<StaleManifest, Schema.TaggedStruct<"StaleManifest", {
29
+ readonly expected: Schema.String;
30
+ readonly reason: Schema.Literals<readonly ["DifferentDigest", "NotGenerated"]>;
31
+ readonly generated: Schema.optionalKey<Schema.String>;
32
+ readonly healthModulePath: Schema.optionalKey<Schema.String>;
33
+ }>, import("effect/Cause").YieldableError & {
34
+ readonly brand: unique symbol;
35
+ }>;
36
+ /**
37
+ * Prepare's health module is edited, missing, or generated for another
38
+ * manifest. Nothing was pushed.
39
+ */
40
+ export declare class StaleManifest extends StaleManifest_base {
41
+ get message(): string;
42
+ }
16
43
  /**
17
44
  * @internal
18
45
  */
19
46
  export declare const deploy: (props: CodeProps, mode?: ProviderMode | undefined) => Effect.Effect<{
20
47
  name: string;
21
48
  url: string;
22
- }, import("./CommandRunner.js").CommandError | InvalidDeploymentTarget | MountInit.MountInitFailed | import("./PushLock.js").PushLockError, CommandRunner | import("../ConvexClient.js").ConvexClient | import("effect/FileSystem").FileSystem | Path.Path | PushLock>;
49
+ }, import("./CommandRunner.js").CommandError | HealthCheckFailed | InvalidDeploymentTarget | MountInit.MountInitFailed | import("./PushLock.js").PushLockError | StaleManifest, CommandRunner | ConvexClient | FileSystem.FileSystem | Path.Path | PushLock>;
23
50
  export {};
24
51
  //# sourceMappingURL=CodeDeployment.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"CodeDeployment.d.ts","sources":["../../src/internal/CodeDeployment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,IAAI,MAAM,aAAa,CAAC;AAGpC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAmB,MAAM,oBAAoB,CAAC;AAEpE,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;;;;oBAIrB,OAAO,MAAM;;AAFjC,qBAAa,uBAAwB,SAAQ,4BAK3C;CAAG;AAoDL;;GAEG;AACH,eAAO,MAAM,MAAM;;;sQA4BjB,CAAC"}
1
+ {"version":3,"file":"CodeDeployment.d.ts","sources":["../../src/internal/CodeDeployment.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAC;AAEhD,OAAO,KAAK,IAAI,MAAM,aAAa,CAAC;AAGpC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAmB,MAAM,oBAAoB,CAAC;AAGpE,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;;;;oBAIrB,OAAO,MAAM;;AAFjC,qBAAa,uBAAwB,SAAQ,4BAK3C;CAAG;;;;;;oBAIe,OAAO,MAAM;;AAFjC,qBAAa,iBAAkB,SAAQ,sBAOrC;IACA,IAAa,OAAO,WAInB;CACF;;;;;;;oBAQmB,OAAO,MAAM;;AANjC;;;GAGG;AACH,qBAAa,aAAc,SAAQ,kBAQjC;IACA,IAAa,OAAO,WAInB;CACF;AAwGD;;GAEG;AACH,eAAO,MAAM,MAAM;;;4PAmDjB,CAAC"}
@@ -1,14 +1,84 @@
1
+ import { ConvexClient } from "../ConvexClient.js";
1
2
  import { CommandRunner } from "./CommandRunner.js";
2
3
  import { isOrigin } from "./Loopback.js";
4
+ import { functionsDirectory } from "./FunctionsDirectory.js";
3
5
  import { run } from "./MountInit.js";
4
6
  import { PushLock } from "./PushLock.js";
5
7
  import * as Effect from "effect/Effect";
6
- import * as Path from "effect/Path";
7
8
  import * as Redacted from "effect/Redacted";
8
9
  import * as Schema from "effect/Schema";
9
10
  import * as Result from "effect/Result";
11
+ import * as FileSystem from "effect/FileSystem";
12
+ import * as Path from "effect/Path";
13
+ import * as Option from "effect/Option";
14
+ import * as HealthModule from "@confect/core/HealthModule";
10
15
  // src/internal/CodeDeployment.ts
11
16
  var InvalidDeploymentTarget = class extends Schema.TaggedError()("InvalidDeploymentTarget", { reason: Schema.Literals(["deployment", "deployKey"]) }) {};
17
+ var HealthCheckFailed = class extends Schema.TaggedError()("HealthCheckFailed", {
18
+ expected: Schema.String,
19
+ answered: Schema.optional(Schema.String),
20
+ detail: Schema.optional(Schema.String)
21
+ }) {
22
+ get message() {
23
+ return this.answered === void 0 ? `health: the pushed code gave no manifest digest (${this.detail ?? "no answer"}); expected ${this.expected}` : `health: the pushed code was generated with ${this.answered}, not ${this.expected}`;
24
+ }
25
+ };
26
+ /**
27
+ * Prepare's health module is edited, missing, or generated for another
28
+ * manifest. Nothing was pushed.
29
+ */
30
+ var StaleManifest = class extends Schema.TaggedError()("StaleManifest", {
31
+ expected: Schema.String,
32
+ reason: Schema.Literals(["DifferentDigest", "NotGenerated"]),
33
+ generated: Schema.optionalKey(Schema.String),
34
+ healthModulePath: Schema.optionalKey(Schema.String)
35
+ }) {
36
+ get message() {
37
+ return this.reason === "NotGenerated" ? `The health module ${this.healthModulePath ?? "at the configured functions directory"} is not as codegen writes it, so nothing was pushed. Do not edit or format the file; regenerate it with confect codegen. The CLI that generates it and the Alchemy package that reads it must be on the same Confect release.` : `prepare generated manifest ${this.generated}, but the stack imported manifest ${this.expected}, so nothing was pushed. Run confect codegen, commit the generated files and deploy again.`;
38
+ }
39
+ };
40
+ const HEALTH = "confectHealth:digest";
41
+ /**
42
+ * The digest prepare wrote into the health module, which is what the push would
43
+ * deploy; none when the module is missing or unreadable.
44
+ */
45
+ const generatedDigest = Effect.fn("Code.generatedDigest")(function* (cwd) {
46
+ const fs = yield* FileSystem.FileSystem;
47
+ const path = yield* Path.Path;
48
+ const functions = yield* functionsDirectory(cwd);
49
+ const file = path.join(cwd, functions, "confectHealth.ts");
50
+ return {
51
+ path: file,
52
+ digest: yield* fs.readFileString(file).pipe(Effect.map(HealthModule.read), Effect.orElseSucceed(Option.none))
53
+ };
54
+ }, Effect.orElseSucceed(() => ({
55
+ path: void 0,
56
+ digest: Option.none()
57
+ })));
58
+ /**
59
+ * Ask the pushed code which manifest digest codegen wrote into it, and fail
60
+ * unless it is `expected`.
61
+ */
62
+ const checkHealth = Effect.fn("Code.checkHealth")(function* (url, key, expected) {
63
+ const answer = yield* (yield* ConvexClient).runFunction(url, key, HEALTH, {}).pipe(Effect.mapError((error) => HealthCheckFailed.make({
64
+ expected,
65
+ detail: error._tag
66
+ })), Effect.timeoutOrElse({
67
+ duration: "30 seconds",
68
+ orElse: () => Effect.fail(HealthCheckFailed.make({
69
+ expected,
70
+ detail: "timeout"
71
+ }))
72
+ }));
73
+ if (typeof answer !== "string") return yield* HealthCheckFailed.make({
74
+ expected,
75
+ detail: "not a string"
76
+ });
77
+ if (answer !== expected) return yield* HealthCheckFailed.make({
78
+ expected,
79
+ answered: answer
80
+ });
81
+ });
12
82
  const deploymentName = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
13
83
  const cloudTarget = (props) => {
14
84
  const { name, url } = props.deployment;
@@ -47,14 +117,27 @@ const deploy = Effect.fn("Code.deploy")(function* (props, mode = "live") {
47
117
  const path = yield* Path.Path;
48
118
  yield* lock.withLock(target.deploymentName, Effect.gen(function* () {
49
119
  if (props.prepare !== void 0) yield* runner.prepare(props.prepare, props.cwd);
120
+ if (props.manifestDigest !== void 0) {
121
+ const { path: file, digest: generated } = yield* generatedDigest(path.resolve(props.cwd ?? "."));
122
+ if (Option.getOrUndefined(generated) !== props.manifestDigest) return yield* StaleManifest.make({
123
+ expected: props.manifestDigest,
124
+ ...file === void 0 ? {} : { healthModulePath: file },
125
+ reason: Option.isNone(generated) ? "NotGenerated" : "DifferentDigest",
126
+ ...Option.match(generated, {
127
+ onNone: () => ({}),
128
+ onSome: (digest) => ({ generated: digest })
129
+ })
130
+ });
131
+ }
50
132
  yield* runner.deploy(target, props.cwd);
51
133
  yield* run(props.deployment.url, props.deployKey, path.resolve(props.cwd ?? "."));
134
+ if (props.manifestDigest !== void 0) yield* checkHealth(props.deployment.url, props.deployKey, props.manifestDigest);
52
135
  }));
53
136
  return {
54
137
  name: props.deployment.name,
55
138
  url: props.deployment.url
56
139
  };
57
140
  });
58
- export { InvalidDeploymentTarget, deploy };
141
+ export { HealthCheckFailed, InvalidDeploymentTarget, StaleManifest, deploy };
59
142
 
60
143
  //# sourceMappingURL=CodeDeployment.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"CodeDeployment.js","names":["Loopback.isOrigin","MountInit.run"],"sources":["../../src/internal/CodeDeployment.ts"],"sourcesContent":["import type { ProviderMode } from \"alchemy/ProviderMode\";\nimport * as Effect from \"effect/Effect\";\nimport * as Path from \"effect/Path\";\nimport * as Redacted from \"effect/Redacted\";\nimport * as Result from \"effect/Result\";\nimport * as Schema from \"effect/Schema\";\nimport type { CodeProps } from \"../Code.js\";\nimport { CommandRunner, type PushTarget } from \"./CommandRunner.js\";\nimport * as Loopback from \"./Loopback.js\";\nimport * as MountInit from \"./MountInit.js\";\nimport { PushLock } from \"./PushLock.js\";\n\nexport class InvalidDeploymentTarget extends Schema.TaggedError<\n InvalidDeploymentTarget,\n { readonly brand: unique symbol }\n>()(\"InvalidDeploymentTarget\", {\n reason: Schema.Literals([\"deployment\", \"deployKey\"]),\n}) {}\n\nconst deploymentName = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;\n\nconst cloudTarget = (\n props: CodeProps,\n): Result.Result<PushTarget, InvalidDeploymentTarget> => {\n const { name, url } = props.deployment;\n if (\n !deploymentName.test(name) ||\n !new RegExp(\n `^https://${name}(?:\\\\.[a-z]{2}-[a-z]+-[0-9]+)?\\\\.convex\\\\.cloud$`,\n ).test(url)\n )\n return Result.fail(InvalidDeploymentTarget.make({ reason: \"deployment\" }));\n const key =\n /^(?:dev|prod|preview|custom):([a-z0-9]+(?:-[a-z0-9]+)*)\\|[a-zA-Z0-9+/=_-]+$/.exec(\n Redacted.value(props.deployKey),\n );\n if (key === null || key[1] !== name)\n return Result.fail(InvalidDeploymentTarget.make({ reason: \"deployKey\" }));\n return Result.succeed({\n _tag: \"Cloud\",\n deploymentName: name,\n deployKey: props.deployKey,\n });\n};\n\nconst localTarget = (\n props: CodeProps,\n): Result.Result<PushTarget, InvalidDeploymentTarget> => {\n const { name, url } = props.deployment;\n if (!deploymentName.test(name) || !Loopback.isOrigin(url))\n return Result.fail(InvalidDeploymentTarget.make({ reason: \"deployment\" }));\n const key = /^([a-z0-9]+(?:-[a-z0-9]+)*)\\|[0-9a-f]+$/.exec(\n Redacted.value(props.deployKey),\n );\n if (key === null || key[1] !== name)\n return Result.fail(InvalidDeploymentTarget.make({ reason: \"deployKey\" }));\n return Result.succeed({\n _tag: \"SelfHosted\",\n deploymentName: name,\n url,\n adminKey: props.deployKey,\n });\n};\n\nconst targets = { live: cloudTarget, local: localTarget } satisfies Record<\n ProviderMode,\n (props: CodeProps) => Result.Result<PushTarget, InvalidDeploymentTarget>\n>;\n\n/**\n * @internal\n */\nexport const deploy = Effect.fn(\"Code.deploy\")(function* (\n props: CodeProps,\n mode: ProviderMode = \"live\",\n) {\n const target = yield* Effect.fromResult(targets[mode](props));\n const runner = yield* CommandRunner;\n const lock = yield* PushLock;\n const path = yield* Path.Path;\n yield* lock.withLock(\n target.deploymentName,\n Effect.gen(function* () {\n if (props.prepare !== undefined)\n yield* runner.prepare(props.prepare, props.cwd);\n yield* runner.deploy(target, props.cwd);\n // WORKAROUND: Convex has no component `init` or install `args` in a\n // stable release, so each push runs every mount's `init` itself, inside\n // the lock so no other push lands between this code and its `init`.\n // Delete this step at gaganref/confect#18's trigger: a stable `convex`\n // release with `init` and `args`, and an open-source backend that\n // accepts them. CHANGES.md lists what else goes with it.\n yield* MountInit.run(\n props.deployment.url,\n props.deployKey,\n path.res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AAa,OAAO;AAAY;;;;AAQxD,MAAa,SAAS,OAAO,GAAG,aAAa,CAAC,CAAC,WAC7C,OACA,OAAqB,QACrB;CACA,MAAM,SAAS,OAAO,OAAO,WAAW,QAAQ,KAAK,CAAC,KAAK,CAAC;CAC5D,MAAM,SAAS,OAAO;CACtB,MAAM,OAAO,OAAO;CACpB,MAAM,OAAO,OAAO,KAAK;CACzB,OAAO,KAAK,SACV,OAAO,gBACP,OAAO,IAAI,aAAa;EACtB,IAAI,MAAM,YAAY,KAAA,GACpB,OAAO,OAAO,QAAQ,MAAM,SAAS,MAAM,GAAG;EAChD,OAAO,OAAO,OAAO,QAAQ,MAAM,GAAG;EAOtC,OAAOC,IACL,MAAM,WAAW,KACjB,MAAM,WACN,KAAK,QAAQ,MAAM,OAAO,GAAG,CAC/B;CACF,CAAC,CACH;CACA,OAAO;EAAE,MAAM,MAAM,WAAW;EAAM,KAAK,MAAM,WAAW;CAAI;AAClE,CAAC"}
1
+ {"version":3,"file":"CodeDeployment.js","names":["Loopback.isOrigin","MountInit.run"],"sources":["../../src/internal/CodeDeployment.ts"],"sourcesContent":["import * as HealthModule from \"@confect/core/HealthModule\";\nimport type { ProviderMode } from \"alchemy/ProviderMode\";\nimport * as Effect from \"effect/Effect\";\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 Result from \"effect/Result\";\nimport * as Schema from \"effect/Schema\";\nimport type { CodeProps } from \"../Code.js\";\nimport { ConvexClient } from \"../ConvexClient.js\";\nimport { CommandRunner, type PushTarget } from \"./CommandRunner.js\";\nimport * as Loopback from \"./Loopback.js\";\nimport { functionsDirectory } from \"./FunctionsDirectory.js\";\nimport * as MountInit from \"./MountInit.js\";\nimport { PushLock } from \"./PushLock.js\";\n\nexport class InvalidDeploymentTarget extends Schema.TaggedError<\n InvalidDeploymentTarget,\n { readonly brand: unique symbol }\n>()(\"InvalidDeploymentTarget\", {\n reason: Schema.Literals([\"deployment\", \"deployKey\"]),\n}) {}\n\nexport class HealthCheckFailed extends Schema.TaggedError<\n HealthCheckFailed,\n { readonly brand: unique symbol }\n>()(\"HealthCheckFailed\", {\n expected: Schema.String,\n answered: Schema.optional(Schema.String),\n detail: Schema.optional(Schema.String),\n}) {\n override get message() {\n return this.answered === undefined\n ? `health: the pushed code gave no manifest digest (${this.detail ?? \"no answer\"}); expected ${this.expected}`\n : `health: the pushed code was generated with ${this.answered}, not ${this.expected}`;\n }\n}\n\n/**\n * Prepare's health module is edited, missing, or generated for another\n * manifest. Nothing was pushed.\n */\nexport class StaleManifest extends Schema.TaggedError<\n StaleManifest,\n { readonly brand: unique symbol }\n>()(\"StaleManifest\", {\n expected: Schema.String,\n reason: Schema.Literals([\"DifferentDigest\", \"NotGenerated\"]),\n generated: Schema.optionalKey(Schema.String),\n healthModulePath: Schema.optionalKey(Schema.String),\n}) {\n override get message() {\n return this.reason === \"NotGenerated\"\n ? `The health module ${this.healthModulePath ?? \"at the configured functions directory\"} is not as codegen writes it, so nothing was pushed. Do not edit or format the file; regenerate it with confect codegen. The CLI that generates it and the Alchemy package that reads it must be on the same Confect release.`\n : `prepare generated manifest ${this.generated}, but the stack imported manifest ${this.expected}, so nothing was pushed. Run confect codegen, commit the generated files and deploy again.`;\n }\n}\n\nconst HEALTH = \"confectHealth:digest\";\n\n/**\n * The digest prepare wrote into the health module, which is what the push would\n * deploy; none when the module is missing or unreadable.\n */\nconst generatedDigest = Effect.fn(\"Code.generatedDigest\")(\n function* (cwd: string) {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const functions = yield* functionsDirectory(cwd);\n const file = path.join(cwd, functions, \"confectHealth.ts\");\n const digest = yield* fs\n .readFileString(file)\n .pipe(\n Effect.map(HealthModule.read),\n Effect.orElseSucceed(Option.none<string>),\n );\n return { path: file, digest };\n },\n Effect.orElseSucceed(() => ({\n path: undefined,\n digest: Option.none<string>(),\n })),\n);\n\n/**\n * Ask the pushed code which manifest digest codegen wrote into it, and fail\n * unless it is `expected`.\n */\nconst checkHealth = Effect.fn(\"Code.checkHealth\")(function* (\n url: string,\n key: Redacted.Redacted<string>,\n expected: string,\n) {\n const client = yield* ConvexClient;\n const answer = yield* client.runFunction(url, key, HEALTH, {}).pipe(\n Effect.mapError((error) =>\n HealthCheckFailed.make({ expected, detail: error._tag }),\n ),\n Effect.timeoutOrElse({\n duration: \"30 seconds\",\n orElse: () =>\n Effect.fail(HealthCheckFailed.make({ expected, detail: \"timeout\" })),\n }),\n );\n if (typeof answer !== \"string\")\n return yield* HealthCheckFailed.make({ expected, detail: \"not a string\" });\n if (answer !== expected)\n return yield* HealthCheckFailed.make({ expected, answered: answer });\n});\n\nconst deploymentName = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;\n\nconst cloudTarget = (\n props: CodeProps,\n): Result.Result<PushTarget, InvalidDeploymentTarget> => {\n const { name, url } = props.deployment;\n if (\n !deploymentName.test(name) ||\n !new RegExp(\n `^https://${name}(?:\\\\.[a-z]{2}-[a-z]+-[0-9]+)?\\\\.convex\\\\.cloud$`,\n ).test(url)\n )\n return Result.fail(InvalidDeploymentTarget.make({ reason: \"deployment\" }));\n const key =\n /^(?:dev|prod|preview|custom):([a-z0-9]+(?:-[a-z0-9]+)*)\\|[a-zA-Z0-9+/=_-]+$/.exec(\n Redacted.value(props.deployKey),\n );\n if (key === null || key[1] !== name)\n return Result.fail(InvalidDeploymentTarget.make({ reason: \"deployKey\" }));\n return Result.succeed({\n _tag: \"Cloud\",\n deploymentName: name,\n deployKey: props.deployKey,\n });\n};\n\nconst localTarget = (\n props: CodeProps,\n): Result.Result<PushTarget, InvalidDeploymentTarget> => {\n const { name, url } = props.deployment;\n if (!deploymentName.test(name) || !Loopback.isOrigin(url))\n return Result.fail(InvalidDeploymentTarget.make({ reason: \"deployment\" }));\n const key = /^([a-z0-9]+(?:-[a-z0-9]+)*)\\|[0-9a-f]+$/.exec(\n Redacted.value(props.deployKey),\n );\n if (key === null || key[1] !== name)\n return Result.fail(InvalidDeploymentTarget.make({ reason: \"deployKey\" }));\n return Result.succeed({\n _tag: \"SelfHosted\",\n deploymentName: name,\n url,\n adminKey: props.deployKey,\n });\n};\n\nconst targets = { live: cloudTarget, local: localTarget } satisfies Record<\n ProviderMode,\n (props: CodeProps) => Result.Result<PushTarget, InvalidDeploymentTarget>\n>;\n\n/**\n * @internal\n */\nexport const deploy = Effect.fn(\"Code.deploy\")(function* (\n props: CodeProps,\n mode: ProviderMode = \"live\",\n) {\n const target = yield* Effect.fromResult(targets[mode](props));\n const runner = yield* CommandRunner;\n const lock = yield* PushLock;\n const path = yield* Path.Path;\n yield* lock.withLock(\n target.deploymentName,\n Effect.gen(function* () {\n if (props.prepare !== undefined)\n yield* runner.prepare(props.prepare, props.cwd);\n if (props.manifestDigest !== undefined) {\n const { path: file, digest: generated } = yield* generatedDigest(\n path.resolve(props.cwd ?? \".\"),\n );\n if (Option.getOrUndefined(generated) !== props.manifestDigest)\n return yield* StaleManifest.make({\n expected: props.manifestDigest,\n ...(file === undefined ? {} : { healthModulePath: file }),\n reason: Option.isNone(generated)\n ? \"NotGenerated\"\n : \"DifferentDigest\",\n ...Option.match(generated, {\n onNone: () => ({}),\n onSome: (digest) => ({ generated: digest }),\n }),\n });\n }\n yield* runner.deploy(target, props.cwd);\n // WORKAROUND: Convex has no component `init` or install `args` in a\n // stable release, so each push runs every mount's `init` itself, inside\n // the lock so no other push lands between this code and its `init`.\n // Delete this step at gaganref/confect#18's trigger: a stable `convex`\n // release with `init` and `args`, and an open-source backend that\n // accepts them. CHANGES.md lists what else goes with it.\n yield* MountInit.run(\n props.deployment.url,\n props.deployKey,\n path.resolve(props.cwd ?? \".\"),\n );\n if (props.manifestDigest !== undefined)\n yield* checkHealth(\n props.deployment.url,\n props.deployKey,\n props.manifestDigest,\n );\n }),\n );\n return { name: props.deployment.name, url: props.deployment.url };\n});\n"],"mappings":";;;;;;;;;;;;;;;AAiBA,IAAa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