@gaganref/confect-alchemy 10.6.0-fork.30 → 10.6.0-fork.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/Backend.d.ts CHANGED
@@ -1,18 +1,23 @@
1
1
  import * as Env from "@confect/core/Env";
2
2
  import * as Manifest from "@confect/core/Manifest";
3
- import type { Input } from "alchemy/Input";
3
+ import type { Input, InputProps } from "alchemy/Input";
4
4
  import * as Output from "alchemy/Output";
5
5
  import * as Effect from "effect/Effect";
6
6
  import * as Redacted from "effect/Redacted";
7
7
  import * as Schema from "effect/Schema";
8
8
  import { Code } from "./Code.js";
9
- import { EnvironmentVariables } from "./EnvironmentVariables.js";
9
+ import { EnvironmentVariables, type EnvironmentVariablesProps } from "./EnvironmentVariables.js";
10
10
  interface CommonProps {
11
11
  readonly deployment: {
12
12
  readonly name: Input<string>;
13
13
  readonly url: Input<string>;
14
14
  };
15
15
  readonly deployKey: Input<Redacted.Redacted<string>>;
16
+ /**
17
+ * Safety options for managed environment values. Defaults to the resource
18
+ * defaults.
19
+ */
20
+ readonly environment?: InputProps<Omit<EnvironmentVariablesProps, "url" | "deployKey" | "variables">>;
16
21
  readonly cwd?: string;
17
22
  }
18
23
  type Environment<M extends Manifest.Manifest> = {
@@ -1 +1 @@
1
- {"version":3,"file":"Backend.d.ts","sources":["../src/Backend.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,GAAG,MAAM,mBAAmB,CAAC;AACzC,OAAO,KAAK,QAAQ,MAAM,wBAAwB,CAAC;AACnD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,KAAK,MAAM,MAAM,gBAAgB,CAAC;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,EAAE,IAAI,EAAE,MAAM,WA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AAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;CACtD;;;;;6CAgFA,CAAC"}
package/dist/Backend.js CHANGED
@@ -192,6 +192,7 @@ const backend = (id, props) => Namespace.push(id, Effect.gen(function* () {
192
192
  ...promoted
193
193
  };
194
194
  const environment = variables === void 0 || props.env === void 0 && props.automatic === void 0 && Rec.keys(variables).length === 0 ? void 0 : yield* EnvironmentVariables("Environment", {
195
+ ...props.environment,
195
196
  url: props.deployment.url,
196
197
  deployKey: props.deployKey,
197
198
  variables
@@ -1 +1 @@
1
- {"version":3,"file":"Backend.js","names":[],"sources":["../src/Backend.ts"],"sourcesContent":["import * as Arr from \"effect/Array\";\nimport * as Env from \"@confect/core/Env\";\nimport * as Manifest from \"@confect/core/Manifest\";\nimport type { Input } from \"alchemy/Input\";\nimport * as Namespace from \"alchemy/Namespace\";\nimport * as Output from \"alchemy/Output\";\nimport * as Effect from \"effect/Effect\";\nimport * as Rec from \"effect/Record\";\nimport * as Redacted from \"effect/Redacted\";\nimport * as Schema from \"effect/Schema\";\nimport * as Result from \"effect/Result\";\nimport { Code } from \"./Code.js\";\nimport { EnvironmentVariables } from \"./EnvironmentVariables.js\";\n\ninterface CommonProps {\n readonly deployment: {\n readonly name: Input<string>;\n readonly url: Input<string>;\n };\n readonly deployKey: Input<Redacted.Redacted<string>>;\n readonly cwd?: string;\n}\n\ntype Environment<M extends Manifest.Manifest> = {\n readonly [K in keyof Manifest.Values<M>]: Input<\n Exclude<Manifest.Values<M>[K], undefined>\n >;\n};\n\ntype MountSettings<M extends Manifest.Manifest> = {\n readonly [K in keyof Manifest.Mounts<M>]: {\n readonly [S in keyof NonNullable<Manifest.Mounts<M>[K]>]: Input<\n Exclude<NonNullable<Manifest.Mounts<M>[K]>[S], undefined>\n >;\n };\n};\n\ntype AutomaticValues<M extends Manifest.Manifest> = {\n readonly [K in keyof Manifest.Automatic<M>]: Input<Manifest.Automatic<M>[K]>;\n};\n\n/**\n * Inputs for a backend deployment. An input Effect or Config may be evaluated\n * several times in plan and again in apply, more often for a provider selector\n * and its settings. It must be free of side effects and return the same value\n * every time. Otherwise, a choice can be written without a setting it\n * requires.\n */\nexport type BackendProps<M extends Manifest.Manifest | undefined = undefined> =\n CommonProps &\n (M extends Manifest.Manifest\n ? { readonly manifest: M } & ({} extends Manifest.Values<M>\n ? { readonly env?: Environment<NoInfer<M>> }\n : { readonly env: Environment<NoInfer<M>> }) &\n ({} extends Manifest.Mounts<M>\n ? { readonly mounts?: MountSettings<NoInfer<M>> }\n : { readonly mounts: MountSettings<NoInfer<M>> }) &\n ({} extends Manifest.Automatic<M>\n ? { readonly automatic?: AutomaticValues<NoInfer<M>> }\n : { readonly automatic: AutomaticValues<NoInfer<M>> })\n : {\n readonly manifest?: never;\n readonly mounts?: never;\n readonly automatic?: never;\n readonly env?: Readonly<\n Record<string, Input<string | Redacted.Redacted<string>>>\n >;\n });\n\n/**\n * Deploy a declared backend with env typed by its generated manifest.\n */\nexport function Backend<\n const M extends Manifest.Manifest,\n const E extends Environment<NoInfer<M>> = Environment<NoInfer<M>>,\n const S extends MountSettings<NoInfer<M>> = MountSettings<NoInfer<M>>,\n>(\n id: string,\n props: BackendProps<M> & {\n readonly env?: E &\n Readonly<Record<Exclude<keyof E, keyof Environment<M>>, never>>;\n readonly mounts?: S &\n Readonly<Record<Exclude<keyof S, keyof M[\"mounts\"]>, never>>;\n },\n): ReturnType<typeof backend>;\nexport function Backend(\n id: string,\n props: BackendProps,\n): ReturnType<typeof backend>;\nexport function Backend(\n id: string,\n props: CommonProps & {\n readonly manifest?: Manifest.Manifest;\n readonly env?: Settings;\n readonly automatic?: Variables;\n readonly mounts?: Readonly<Record<string, Settings>>;\n },\n): ReturnType<typeof backend> {\n return backend(id, props);\n}\n\ntype Settings = Readonly<\n Record<string, Input<string | Redacted.Redacted<string> | Env.ProviderChoice>>\n>;\n\ntype Variables = Readonly<\n Record<string, Input<string | Redacted.Redacted<string>>>\n>;\n\nexport class InvalidAutomaticSetting extends Schema.TaggedError<\n InvalidAutomaticSetting,\n { readonly brand: unique symbol }\n>()(\"InvalidAutomaticSetting\", {\n slot: Schema.String,\n reason: Schema.Literals([\n \"NotAutomatic\",\n \"Missing\",\n \"InvalidValue\",\n \"PlainSecret\",\n ]),\n}) {\n override get message(): string {\n if (this.reason === \"PlainSecret\")\n return `${this.slot} is a plain string. Wrap this secret with Redacted.make before passing it in Backend.automatic.`;\n if (this.reason === \"InvalidValue\")\n return `${this.slot} has a value that does not match its manifest slot. Supply a string of the declared kind in Backend.automatic; secret slots require a Redacted string and literals slots require one of their values.`;\n return this.reason === \"NotAutomatic\"\n ? `${this.slot} is not declared automatic in manifest.env. Supply only automatic slots in Backend.automatic; put application values in Backend.env.`\n : `${this.slot} is declared automatic in manifest.env but has no value. Supply it in Backend.automatic.`;\n }\n}\n\nconst automaticVariables = (\n manifest: Manifest.Manifest,\n supplied: Variables,\n): Result.Result<Variables, InvalidAutomaticSetting> =>\n Result.gen(function* () {\n for (const slot of Rec.keys(supplied)) {\n if (\n !Rec.has(manifest.env, slot) ||\n manifest.env[slot]?.automatic !== true\n )\n return yield* Result.fail(\n InvalidAutomaticSetting.make({ slot, reason: \"NotAutomatic\" }),\n );\n }\n for (const [slot, descriptor] of Rec.toEntries(manifest.env)) {\n if (\n descriptor.automatic === true &&\n missing(Rec.has(supplied, slot) ? supplied[slot] : undefined)\n )\n return yield* Result.fail(\n InvalidAutomaticSetting.make({ slot, reason: \"Missing\" }),\n );\n }\n return supplied;\n });\n\nconst missing = (value: unknown): boolean =>\n value === undefined ||\n value === null ||\n value === \"\" ||\n (Redacted.isRedacted(value) && Redacted.value(value) === \"\");\n\n/**\n * A provider choice validated and encoded with the schema the handler decodes\n * it with, after refusing a choice that names a provider whose required setting\n * is unset. A setting belongs to the selector its tag names.\n */\nconst settleChoice = (\n at: string,\n key: string,\n selector: Env.Descriptor & { readonly kind: \"providers\" },\n slots: Readonly<Record<string, Env.Descriptor>>,\n supplied: Readonly<Record<string, unknown>>,\n value: unknown,\n) =>\n Effect.gen(function* () {\n if (selector.optional && missing(value)) return undefined;\n const invalid = InvalidMountSetting.make({\n mount: at,\n slot: key,\n reason: \"InvalidChoice\",\n });\n const schema = Env.providerChoice(selector.values);\n const choice = yield* Schema.decodeUnknownEffect(Schema.toType(schema))(\n value,\n ).pipe(Effect.mapError(() => invalid));\n const named = Env.chosen(choice);\n for (const [slot, other] of Rec.toEntries(slots)) {\n if (\n other.provider?.selector === key &&\n other.provider.required &&\n named.includes(other.provider.name) &&\n missing(Rec.has(supplied, slot) ? supplied[slot] : undefined)\n )\n return yield* InvalidMountSetting.make({\n mount: at,\n slot,\n reason: \"Missing\",\n });\n }\n return yield* Schema.encodeUnknownEffect(schema)(choice).pipe(\n Effect.mapError(() => invalid),\n );\n });\n\n/**\n * Normalize all accepted Input forms without resolving resource dependencies.\n * Redacted values remain opaque; arrays and choice records retain their shape.\n */\nconst normalize = (value: unknown): unknown => {\n if (Output.isOutput(value)) return value;\n if (Effect.isEffect(value)) {\n // oxlint-disable-next-line effecttsgo/any-unknown-in-error-context -- Input admits Effects with arbitrary errors and requirements; this boundary preserves requirements on the Output and converts failures to defects.\n return value.pipe(Effect.orDie, Output.fromEffect);\n }\n if (value === null || typeof value !== \"object\" || Redacted.isRedacted(value))\n return value;\n if (Arr.isArray(value)) {\n const inputs = Arr.map(value, normalize);\n return Arr.some(inputs, Output.isOutput)\n ? Output.all(...Arr.map(inputs, (input) => Output.asOutput(input)))\n : inputs;\n }\n const entries = Arr.map(\n Rec.toEntries(value),\n ([key, input]) => [key, normalize(input)] as const,\n );\n const assemble = (resolved: ReadonlyArray<unknown>) =>\n Rec.fromEntries(Arr.map(entries, ([key], index) => [key, resolved[index]]));\n const inputs = Arr.map(entries, ([, input]) => input);\n return Arr.some(inputs, Output.isOutput)\n ? Output.map(\n Output.all(...Arr.map(inputs, (input) => Output.asOutput(input))),\n assemble,\n )\n : assemble(inputs);\n};\n\n/**\n * Each supplied slot keeps its input edges. A tagged setting also reads its\n * selector's input, and a selector reads only its own tagged settings.\n */\nconst supplySettings = <E>(\n at: string,\n slots: Readonly<Record<string, Env.Descriptor>>,\n supplied: Readonly<Record<string, unknown>>,\n invalid: (\n slot: string,\n reason: \"Missing\" | \"InvalidValue\" | \"PlainSecret\",\n ) => E,\n) =>\n Effect.gen(function* () {\n const normalized = Rec.map(supplied, normalize);\n const entries: Array<[string, unknown]> = [];\n const settle = (\n key: string,\n descriptor: Env.Descriptor,\n value: unknown,\n choice?: unknown,\n ) =>\n Effect.gen(function* () {\n if (missing(value)) {\n const provider = descriptor.provider;\n const selector =\n provider === undefined ? undefined : slots[provider.selector];\n if (\n provider?.required === true &&\n selector?.kind === \"providers\" &&\n !missing(choice)\n )\n yield* settleChoice(\n at,\n provider.selector,\n selector,\n { [key]: descriptor },\n { [key]: value },\n choice,\n );\n if (!descriptor.optional)\n return yield* Effect.fail(invalid(key, \"Missing\"));\n return undefined;\n }\n if (descriptor.kind === \"secret\" && typeof value === \"string\")\n return yield* Effect.fail(invalid(key, \"PlainSecret\"));\n const valid =\n descriptor.kind === \"secret\"\n ? Redacted.isRedacted(value) &&\n typeof Redacted.value(value) === \"string\"\n : descriptor.kind === \"providers\" ||\n (typeof value === \"string\" &&\n (descriptor.kind !== \"literals\" ||\n descriptor.values.includes(value)));\n if (!valid) return yield* Effect.fail(invalid(key, \"InvalidValue\"));\n return value;\n });\n for (const [key, descriptor] of Rec.toEntries(slots)) {\n const value = Rec.has(normalized, key) ? normalized[key] : undefined;\n const choice =\n descriptor.provider === undefined ||\n !Rec.has(normalized, descriptor.provider.selector)\n ? undefined\n : normalized[descriptor.provider.selector];\n const checked =\n Output.isOutput(value) || Output.isOutput(choice)\n ? Output.all(Output.asOutput(value), Output.asOutput(choice)).pipe(\n Output.mapEffect(([resolved, selected]) =>\n settle(key, descriptor, resolved, selected).pipe(Effect.orDie),\n ),\n )\n : yield* settle(key, descriptor, value, choice);\n if (checked !== undefined) entries.push([key, checked]);\n }\n const settings = Rec.fromEntries(entries);\n for (const [key, descriptor] of Rec.toEntries(slots)) {\n if (descriptor.kind !== \"providers\" || !Rec.has(settings, key)) continue;\n const value = settings[key];\n const tagged = Rec.filter(\n settings,\n (_, slot) => slots[slot]?.provider?.selector === key,\n );\n const check = (\n choice: unknown,\n resolved: Readonly<Record<string, unknown>>,\n ) => settleChoice(at, key, descriptor, slots, resolved, choice);\n const inputs = normalize({ value, tagged });\n settings[key] = Output.isOutput(inputs)\n ? inputs.pipe(\n Output.mapEffect(\n (resolved: {\n readonly value: unknown;\n readonly tagged: Readonly<Record<string, unknown>>;\n }) => check(resolved.value, resolved.tagged).pipe(Effect.orDie),\n ),\n )\n : yield* check(value, tagged);\n }\n return settings as Record<string, Variables[string]>;\n });\n\nexport class InvalidMountSetting extends Schema.TaggedError<\n InvalidMountSetting,\n { readonly brand: unique symbol }\n>()(\"InvalidMountSetting\", {\n mount: Schema.String,\n slot: Schema.optional(Schema.String),\n reason: Schema.Literals([\n \"UnknownMount\",\n \"NotOpen\",\n \"Missing\",\n \"PlainSecret\",\n \"InvalidChoice\",\n \"InvalidValue\",\n ]),\n}) {\n override get message() {\n const at =\n this.slot === undefined ? this.mount : `${this.mount}.${this.slot}`;\n const location = this.mount === \"app\" ? \"Backend.env\" : \"Backend.mounts\";\n const remedy = {\n UnknownMount:\n \"This mount is not listed. Use a mount name from manifest.mounts.\",\n NotOpen:\n \"This slot is not open. Supply only slots listed in this mount's manifest env.\",\n Missing: `This required slot is missing. Supply this required slot in ${location}.`,\n PlainSecret: `This secret is a plain string. Wrap this secret with Redacted.make before passing it in ${location}.`,\n InvalidValue:\n \"This value does not match its manifest slot. Supply a string of the declared kind; secret slots require a Redacted string and literals slots require one of their values.\",\n InvalidChoice:\n \"This provider choice is one the component would refuse. Name one of the providers this selector offers, or a failover or pool of them.\",\n };\n return `${at}: ${remedy[this.reason]}`;\n }\n}\n\n/**\n * Each mount's settings under the deployment variable the manifest names for\n * it, refusing a manifest that does not decode, a mount or slot the manifest\n * does not list as open, a missing required slot, a plain string for a secret\n * and a provider choice the component would refuse.\n */\nexport const mountVariables = (\n input: Manifest.Manifest,\n mounts: Readonly<Record<string, Settings>>,\n): Effect.Effect<\n Record<string, Variables[string]>,\n InvalidMountSetting | Manifest.UnsupportedManifestFormat\n> =>\n Effect.gen(function* () {\n const manifest = yield* Effect.fromResult(\n Manifest.decode(input, \"confect/_generated/manifest.ts\"),\n );\n const variables: Record<string, Variables[string]> = {};\n for (const mount of Rec.keys(mounts)) {\n if (!Rec.has(manifest.mounts, mount))\n return yield* InvalidMountSetting.make({\n mount,\n reason: \"UnknownMount\",\n });\n }\n for (const [mount, entry] of Rec.toEntries(manifest.mounts)) {\n const supplied =\n (Rec.has(mounts, mount) ? mounts[mount] : undefined) ?? {};\n for (const slot of Rec.keys(supplied)) {\n if (!Rec.has(entry.env, slot))\n return yield* InvalidMountSetting.make({\n mount,\n slot,\n reason: \"NotOpen\",\n });\n }\n const settings = yield* supplySettings(\n mount,\n entry.env,\n supplied,\n (slot, reason) => InvalidMountSetting.make({ mount, slot, reason }),\n );\n for (const [slot, value] of Rec.toEntries(settings)) {\n variables[entry.env[slot]!.variable] = value;\n }\n }\n return variables;\n });\n\nconst backend = (\n id: string,\n props: CommonProps & {\n readonly manifest?: Manifest.Manifest;\n readonly env?: Settings;\n readonly automatic?: Variables;\n readonly mounts?: Readonly<Record<string, Settings>>;\n },\n) =>\n Namespace.push(\n id,\n Effect.gen(function* () {\n const manifest =\n props.manifest === undefined\n ? undefined\n : yield* Effect.fromResult(\n Manifest.decode(props.manifest, \"confect/_generated/manifest.ts\"),\n ).pipe(Effect.orDie);\n const promoted =\n manifest === undefined\n ? {}\n : yield* mountVariables(manifest, props.mounts ?? {}).pipe(\n Effect.orDie,\n );\n const automaticInput =\n manifest === undefined\n ? undefined\n : yield* Effect.fromResult(\n automaticVariables(manifest, props.automatic ?? {}),\n ).pipe(Effect.orDie);\n const automatic =\n manifest === undefined || automaticInput === undefined\n ? undefined\n : yield* supplySettings(\n \"app\",\n Rec.filter(manifest.env, (slot) => slot.automatic === true),\n automaticInput,\n (slot, reason) => InvalidAutomaticSetting.make({ slot, reason }),\n ).pipe(Effect.orDie);\n const env =\n manifest === undefined\n ? props.env\n : yield* supplySettings(\n \"app\",\n Rec.filter(manifest.env, (slot) => slot.automatic !== true),\n props.env ?? {},\n (slot, reason) =>\n InvalidMountSetting.make({\n mount: \"app\",\n slot,\n reason,\n }),\n ).pipe(Effect.orDie);\n const variables =\n Rec.keys(promoted).length === 0 && props.automatic === undefined\n ? env\n : { ...env, ...automatic, ...promoted };\n const environment =\n variables === undefined ||\n (props.env === undefined &&\n props.automatic === undefined &&\n Rec.keys(variables).length === 0)\n ? undefined\n : yield* EnvironmentVariables(\"Environment\", {\n url: props.deployment.url,\n deployKey: props.deployKey,\n variables: variables as Variables,\n });\n const code = yield* Code(\"Code\", {\n deployment: {\n name: props.deployment.name,\n url:\n environment !== undefined\n ? Output.map(\n Output.all(environment.variables, environment.url),\n ([, url]) => url,\n )\n : props.deployment.url,\n },\n deployKey: props.deployKey,\n ...(props.cwd === undefined ? {} : { cwd: props.cwd }),\n ...(manifest === undefined ? {} : { manifestDigest: manifest.digest }),\n prepare: { command: \"confect\", args: [\"codegen\"] },\n });\n return { code, environment, name: code.name, url: code.url };\n }),\n );\n"],"mappings":";;;;;;;;;;;;;AAyFA,SAAgB,QACd,IACA,OAM4B;CAC5B,OAAO,QAAQ,IAAI,KAAK;AAC1B;AAUA,IAAa,0BAAb,cAA6C,OAAO,YAGlD,CAAC,CAAC,2BAA2B;CAC7B,MAAM,OAAO;CACb,QAAQ,OAAO,SAAS;EACtB;EACA;EACA;EACA;CACF,CAAC;AACH,CAAC,CAAC,CAAC;CACD,IAAa,UAAkB;EAC7B,IAAI,KAAK,WAAW,eAClB,OAAO,GAAG,KAAK,KAAK;EACtB,IAAI,KAAK,WAAW,gBAClB,OAAO,GAAG,KAAK,KAAK;EACtB,OAAO,KAAK,WAAW,iBACnB,GAAG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,CAAC,IAAI,EAAE,gBAAgB,SAAS,OAAO;EACpE,SAAS;GAAE,SAAS;GAAW,MAAM,CAAC,SAAS;EAAE;CACnD,CAAC;CACD,OAAO;EAAE;EAAM;EAAa,MAAM,KAAK;EAAM,KAAK,KAAK;CAAI;AAC7D,CAAC,CACH"}
1
+ {"version":3,"file":"Backend.js","names":[],"sources":["../src/Backend.ts"],"sourcesContent":["import * as Arr from \"effect/Array\";\nimport * as Env from \"@confect/core/Env\";\nimport * as Manifest from \"@confect/core/Manifest\";\nimport type { Input, InputProps } from \"alchemy/Input\";\nimport * as Namespace from \"alchemy/Namespace\";\nimport * as Output from \"alchemy/Output\";\nimport * as Effect from \"effect/Effect\";\nimport * as Rec from \"effect/Record\";\nimport * as Redacted from \"effect/Redacted\";\nimport * as Schema from \"effect/Schema\";\nimport * as Result from \"effect/Result\";\nimport { Code } from \"./Code.js\";\nimport {\n EnvironmentVariables,\n type EnvironmentVariablesProps,\n} from \"./EnvironmentVariables.js\";\n\ninterface CommonProps {\n readonly deployment: {\n readonly name: Input<string>;\n readonly url: Input<string>;\n };\n readonly deployKey: Input<Redacted.Redacted<string>>;\n /**\n * Safety options for managed environment values. Defaults to the resource\n * defaults.\n */\n readonly environment?: InputProps<\n Omit<EnvironmentVariablesProps, \"url\" | \"deployKey\" | \"variables\">\n >;\n readonly cwd?: string;\n}\n\ntype Environment<M extends Manifest.Manifest> = {\n readonly [K in keyof Manifest.Values<M>]: Input<\n Exclude<Manifest.Values<M>[K], undefined>\n >;\n};\n\ntype MountSettings<M extends Manifest.Manifest> = {\n readonly [K in keyof Manifest.Mounts<M>]: {\n readonly [S in keyof NonNullable<Manifest.Mounts<M>[K]>]: Input<\n Exclude<NonNullable<Manifest.Mounts<M>[K]>[S], undefined>\n >;\n };\n};\n\ntype AutomaticValues<M extends Manifest.Manifest> = {\n readonly [K in keyof Manifest.Automatic<M>]: Input<Manifest.Automatic<M>[K]>;\n};\n\n/**\n * Inputs for a backend deployment. An input Effect or Config may be evaluated\n * several times in plan and again in apply, more often for a provider selector\n * and its settings. It must be free of side effects and return the same value\n * every time. Otherwise, a choice can be written without a setting it\n * requires.\n */\nexport type BackendProps<M extends Manifest.Manifest | undefined = undefined> =\n CommonProps &\n (M extends Manifest.Manifest\n ? { readonly manifest: M } & ({} extends Manifest.Values<M>\n ? { readonly env?: Environment<NoInfer<M>> }\n : { readonly env: Environment<NoInfer<M>> }) &\n ({} extends Manifest.Mounts<M>\n ? { readonly mounts?: MountSettings<NoInfer<M>> }\n : { readonly mounts: MountSettings<NoInfer<M>> }) &\n ({} extends Manifest.Automatic<M>\n ? { readonly automatic?: AutomaticValues<NoInfer<M>> }\n : { readonly automatic: AutomaticValues<NoInfer<M>> })\n : {\n readonly manifest?: never;\n readonly mounts?: never;\n readonly automatic?: never;\n readonly env?: Readonly<\n Record<string, Input<string | Redacted.Redacted<string>>>\n >;\n });\n\n/**\n * Deploy a declared backend with env typed by its generated manifest.\n */\nexport function Backend<\n const M extends Manifest.Manifest,\n const E extends Environment<NoInfer<M>> = Environment<NoInfer<M>>,\n const S extends MountSettings<NoInfer<M>> = MountSettings<NoInfer<M>>,\n>(\n id: string,\n props: BackendProps<M> & {\n readonly env?: E &\n Readonly<Record<Exclude<keyof E, keyof Environment<M>>, never>>;\n readonly mounts?: S &\n Readonly<Record<Exclude<keyof S, keyof M[\"mounts\"]>, never>>;\n },\n): ReturnType<typeof backend>;\nexport function Backend(\n id: string,\n props: BackendProps,\n): ReturnType<typeof backend>;\nexport function Backend(\n id: string,\n props: CommonProps & {\n readonly manifest?: Manifest.Manifest;\n readonly env?: Settings;\n readonly automatic?: Variables;\n readonly mounts?: Readonly<Record<string, Settings>>;\n },\n): ReturnType<typeof backend> {\n return backend(id, props);\n}\n\ntype Settings = Readonly<\n Record<string, Input<string | Redacted.Redacted<string> | Env.ProviderChoice>>\n>;\n\ntype Variables = Readonly<\n Record<string, Input<string | Redacted.Redacted<string>>>\n>;\n\nexport class InvalidAutomaticSetting extends Schema.TaggedError<\n InvalidAutomaticSetting,\n { readonly brand: unique symbol }\n>()(\"InvalidAutomaticSetting\", {\n slot: Schema.String,\n reason: Schema.Literals([\n \"NotAutomatic\",\n \"Missing\",\n \"InvalidValue\",\n \"PlainSecret\",\n ]),\n}) {\n override get message(): string {\n if (this.reason === \"PlainSecret\")\n return `${this.slot} is a plain string. Wrap this secret with Redacted.make before passing it in Backend.automatic.`;\n if (this.reason === \"InvalidValue\")\n return `${this.slot} has a value that does not match its manifest slot. Supply a string of the declared kind in Backend.automatic; secret slots require a Redacted string and literals slots require one of their values.`;\n return this.reason === \"NotAutomatic\"\n ? `${this.slot} is not declared automatic in manifest.env. Supply only automatic slots in Backend.automatic; put application values in Backend.env.`\n : `${this.slot} is declared automatic in manifest.env but has no value. Supply it in Backend.automatic.`;\n }\n}\n\nconst automaticVariables = (\n manifest: Manifest.Manifest,\n supplied: Variables,\n): Result.Result<Variables, InvalidAutomaticSetting> =>\n Result.gen(function* () {\n for (const slot of Rec.keys(supplied)) {\n if (\n !Rec.has(manifest.env, slot) ||\n manifest.env[slot]?.automatic !== true\n )\n return yield* Result.fail(\n InvalidAutomaticSetting.make({ slot, reason: \"NotAutomatic\" }),\n );\n }\n for (const [slot, descriptor] of Rec.toEntries(manifest.env)) {\n if (\n descriptor.automatic === true &&\n missing(Rec.has(supplied, slot) ? supplied[slot] : undefined)\n )\n return yield* Result.fail(\n InvalidAutomaticSetting.make({ slot, reason: \"Missing\" }),\n );\n }\n return supplied;\n });\n\nconst missing = (value: unknown): boolean =>\n value === undefined ||\n value === null ||\n value === \"\" ||\n (Redacted.isRedacted(value) && Redacted.value(value) === \"\");\n\n/**\n * A provider choice validated and encoded with the schema the handler decodes\n * it with, after refusing a choice that names a provider whose required setting\n * is unset. A setting belongs to the selector its tag names.\n */\nconst settleChoice = (\n at: string,\n key: string,\n selector: Env.Descriptor & { readonly kind: \"providers\" },\n slots: Readonly<Record<string, Env.Descriptor>>,\n supplied: Readonly<Record<string, unknown>>,\n value: unknown,\n) =>\n Effect.gen(function* () {\n if (selector.optional && missing(value)) return undefined;\n const invalid = InvalidMountSetting.make({\n mount: at,\n slot: key,\n reason: \"InvalidChoice\",\n });\n const schema = Env.providerChoice(selector.values);\n const choice = yield* Schema.decodeUnknownEffect(Schema.toType(schema))(\n value,\n ).pipe(Effect.mapError(() => invalid));\n const named = Env.chosen(choice);\n for (const [slot, other] of Rec.toEntries(slots)) {\n if (\n other.provider?.selector === key &&\n other.provider.required &&\n named.includes(other.provider.name) &&\n missing(Rec.has(supplied, slot) ? supplied[slot] : undefined)\n )\n return yield* InvalidMountSetting.make({\n mount: at,\n slot,\n reason: \"Missing\",\n });\n }\n return yield* Schema.encodeUnknownEffect(schema)(choice).pipe(\n Effect.mapError(() => invalid),\n );\n });\n\n/**\n * Normalize all accepted Input forms without resolving resource dependencies.\n * Redacted values remain opaque; arrays and choice records retain their shape.\n */\nconst normalize = (value: unknown): unknown => {\n if (Output.isOutput(value)) return value;\n if (Effect.isEffect(value)) {\n // oxlint-disable-next-line effecttsgo/any-unknown-in-error-context -- Input admits Effects with arbitrary errors and requirements; this boundary preserves requirements on the Output and converts failures to defects.\n return value.pipe(Effect.orDie, Output.fromEffect);\n }\n if (value === null || typeof value !== \"object\" || Redacted.isRedacted(value))\n return value;\n if (Arr.isArray(value)) {\n const inputs = Arr.map(value, normalize);\n return Arr.some(inputs, Output.isOutput)\n ? Output.all(...Arr.map(inputs, (input) => Output.asOutput(input)))\n : inputs;\n }\n const entries = Arr.map(\n Rec.toEntries(value),\n ([key, input]) => [key, normalize(input)] as const,\n );\n const assemble = (resolved: ReadonlyArray<unknown>) =>\n Rec.fromEntries(Arr.map(entries, ([key], index) => [key, resolved[index]]));\n const inputs = Arr.map(entries, ([, input]) => input);\n return Arr.some(inputs, Output.isOutput)\n ? Output.map(\n Output.all(...Arr.map(inputs, (input) => Output.asOutput(input))),\n assemble,\n )\n : assemble(inputs);\n};\n\n/**\n * Each supplied slot keeps its input edges. A tagged setting also reads its\n * selector's input, and a selector reads only its own tagged settings.\n */\nconst supplySettings = <E>(\n at: string,\n slots: Readonly<Record<string, Env.Descriptor>>,\n supplied: Readonly<Record<string, unknown>>,\n invalid: (\n slot: string,\n reason: \"Missing\" | \"InvalidValue\" | \"PlainSecret\",\n ) => E,\n) =>\n Effect.gen(function* () {\n const normalized = Rec.map(supplied, normalize);\n const entries: Array<[string, unknown]> = [];\n const settle = (\n key: string,\n descriptor: Env.Descriptor,\n value: unknown,\n choice?: unknown,\n ) =>\n Effect.gen(function* () {\n if (missing(value)) {\n const provider = descriptor.provider;\n const selector =\n provider === undefined ? undefined : slots[provider.selector];\n if (\n provider?.required === true &&\n selector?.kind === \"providers\" &&\n !missing(choice)\n )\n yield* settleChoice(\n at,\n provider.selector,\n selector,\n { [key]: descriptor },\n { [key]: value },\n choice,\n );\n if (!descriptor.optional)\n return yield* Effect.fail(invalid(key, \"Missing\"));\n return undefined;\n }\n if (descriptor.kind === \"secret\" && typeof value === \"string\")\n return yield* Effect.fail(invalid(key, \"PlainSecret\"));\n const valid =\n descriptor.kind === \"secret\"\n ? Redacted.isRedacted(value) &&\n typeof Redacted.value(value) === \"string\"\n : descriptor.kind === \"providers\" ||\n (typeof value === \"string\" &&\n (descriptor.kind !== \"literals\" ||\n descriptor.values.includes(value)));\n if (!valid) return yield* Effect.fail(invalid(key, \"InvalidValue\"));\n return value;\n });\n for (const [key, descriptor] of Rec.toEntries(slots)) {\n const value = Rec.has(normalized, key) ? normalized[key] : undefined;\n const choice =\n descriptor.provider === undefined ||\n !Rec.has(normalized, descriptor.provider.selector)\n ? undefined\n : normalized[descriptor.provider.selector];\n const checked =\n Output.isOutput(value) || Output.isOutput(choice)\n ? Output.all(Output.asOutput(value), Output.asOutput(choice)).pipe(\n Output.mapEffect(([resolved, selected]) =>\n settle(key, descriptor, resolved, selected).pipe(Effect.orDie),\n ),\n )\n : yield* settle(key, descriptor, value, choice);\n if (checked !== undefined) entries.push([key, checked]);\n }\n const settings = Rec.fromEntries(entries);\n for (const [key, descriptor] of Rec.toEntries(slots)) {\n if (descriptor.kind !== \"providers\" || !Rec.has(settings, key)) continue;\n const value = settings[key];\n const tagged = Rec.filter(\n settings,\n (_, slot) => slots[slot]?.provider?.selector === key,\n );\n const check = (\n choice: unknown,\n resolved: Readonly<Record<string, unknown>>,\n ) => settleChoice(at, key, descriptor, slots, resolved, choice);\n const inputs = normalize({ value, tagged });\n settings[key] = Output.isOutput(inputs)\n ? inputs.pipe(\n Output.mapEffect(\n (resolved: {\n readonly value: unknown;\n readonly tagged: Readonly<Record<string, unknown>>;\n }) => check(resolved.value, resolved.tagged).pipe(Effect.orDie),\n ),\n )\n : yield* check(value, tagged);\n }\n return settings as Record<string, Variables[string]>;\n });\n\nexport class InvalidMountSetting extends Schema.TaggedError<\n InvalidMountSetting,\n { readonly brand: unique symbol }\n>()(\"InvalidMountSetting\", {\n mount: Schema.String,\n slot: Schema.optional(Schema.String),\n reason: Schema.Literals([\n \"UnknownMount\",\n \"NotOpen\",\n \"Missing\",\n \"PlainSecret\",\n \"InvalidChoice\",\n \"InvalidValue\",\n ]),\n}) {\n override get message() {\n const at =\n this.slot === undefined ? this.mount : `${this.mount}.${this.slot}`;\n const location = this.mount === \"app\" ? \"Backend.env\" : \"Backend.mounts\";\n const remedy = {\n UnknownMount:\n \"This mount is not listed. Use a mount name from manifest.mounts.\",\n NotOpen:\n \"This slot is not open. Supply only slots listed in this mount's manifest env.\",\n Missing: `This required slot is missing. Supply this required slot in ${location}.`,\n PlainSecret: `This secret is a plain string. Wrap this secret with Redacted.make before passing it in ${location}.`,\n InvalidValue:\n \"This value does not match its manifest slot. Supply a string of the declared kind; secret slots require a Redacted string and literals slots require one of their values.\",\n InvalidChoice:\n \"This provider choice is one the component would refuse. Name one of the providers this selector offers, or a failover or pool of them.\",\n };\n return `${at}: ${remedy[this.reason]}`;\n }\n}\n\n/**\n * Each mount's settings under the deployment variable the manifest names for\n * it, refusing a manifest that does not decode, a mount or slot the manifest\n * does not list as open, a missing required slot, a plain string for a secret\n * and a provider choice the component would refuse.\n */\nexport const mountVariables = (\n input: Manifest.Manifest,\n mounts: Readonly<Record<string, Settings>>,\n): Effect.Effect<\n Record<string, Variables[string]>,\n InvalidMountSetting | Manifest.UnsupportedManifestFormat\n> =>\n Effect.gen(function* () {\n const manifest = yield* Effect.fromResult(\n Manifest.decode(input, \"confect/_generated/manifest.ts\"),\n );\n const variables: Record<string, Variables[string]> = {};\n for (const mount of Rec.keys(mounts)) {\n if (!Rec.has(manifest.mounts, mount))\n return yield* InvalidMountSetting.make({\n mount,\n reason: \"UnknownMount\",\n });\n }\n for (const [mount, entry] of Rec.toEntries(manifest.mounts)) {\n const supplied =\n (Rec.has(mounts, mount) ? mounts[mount] : undefined) ?? {};\n for (const slot of Rec.keys(supplied)) {\n if (!Rec.has(entry.env, slot))\n return yield* InvalidMountSetting.make({\n mount,\n slot,\n reason: \"NotOpen\",\n });\n }\n const settings = yield* supplySettings(\n mount,\n entry.env,\n supplied,\n (slot, reason) => InvalidMountSetting.make({ mount, slot, reason }),\n );\n for (const [slot, value] of Rec.toEntries(settings)) {\n variables[entry.env[slot]!.variable] = value;\n }\n }\n return variables;\n });\n\nconst backend = (\n id: string,\n props: CommonProps & {\n readonly manifest?: Manifest.Manifest;\n readonly env?: Settings;\n readonly automatic?: Variables;\n readonly mounts?: Readonly<Record<string, Settings>>;\n },\n) =>\n Namespace.push(\n id,\n Effect.gen(function* () {\n const manifest =\n props.manifest === undefined\n ? undefined\n : yield* Effect.fromResult(\n Manifest.decode(props.manifest, \"confect/_generated/manifest.ts\"),\n ).pipe(Effect.orDie);\n const promoted =\n manifest === undefined\n ? {}\n : yield* mountVariables(manifest, props.mounts ?? {}).pipe(\n Effect.orDie,\n );\n const automaticInput =\n manifest === undefined\n ? undefined\n : yield* Effect.fromResult(\n automaticVariables(manifest, props.automatic ?? {}),\n ).pipe(Effect.orDie);\n const automatic =\n manifest === undefined || automaticInput === undefined\n ? undefined\n : yield* supplySettings(\n \"app\",\n Rec.filter(manifest.env, (slot) => slot.automatic === true),\n automaticInput,\n (slot, reason) => InvalidAutomaticSetting.make({ slot, reason }),\n ).pipe(Effect.orDie);\n const env =\n manifest === undefined\n ? props.env\n : yield* supplySettings(\n \"app\",\n Rec.filter(manifest.env, (slot) => slot.automatic !== true),\n props.env ?? {},\n (slot, reason) =>\n InvalidMountSetting.make({\n mount: \"app\",\n slot,\n reason,\n }),\n ).pipe(Effect.orDie);\n const variables =\n Rec.keys(promoted).length === 0 && props.automatic === undefined\n ? env\n : { ...env, ...automatic, ...promoted };\n const environment =\n variables === undefined ||\n (props.env === undefined &&\n props.automatic === undefined &&\n Rec.keys(variables).length === 0)\n ? undefined\n : yield* EnvironmentVariables(\"Environment\", {\n ...props.environment,\n url: props.deployment.url,\n deployKey: props.deployKey,\n variables: variables as Variables,\n });\n const code = yield* Code(\"Code\", {\n deployment: {\n name: props.deployment.name,\n url:\n environment !== undefined\n ? Output.map(\n Output.all(environment.variables, environment.url),\n ([, url]) => url,\n )\n : props.deployment.url,\n },\n deployKey: props.deployKey,\n ...(props.cwd === undefined ? {} : { cwd: props.cwd }),\n ...(manifest === undefined ? {} : { manifestDigest: manifest.digest }),\n prepare: { command: \"confect\", args: [\"codegen\"] },\n });\n return { code, environment, name: code.name, url: code.url };\n }),\n );\n"],"mappings":";;;;;;;;;;;;;AAmGA,SAAgB,QACd,IACA,OAM4B;CAC5B,OAAO,QAAQ,IAAI,KAAK;AAC1B;AAUA,IAAa,0BAAb,cAA6C,OAAO,YAGlD,CAAC,CAAC,2BAA2B;CAC7B,MAAM,OAAO;CACb,QAAQ,OAAO,SAAS;EACtB;EACA;EACA;EACA;CACF,CAAC;AACH,CAAC,CAAC,CAAC;CACD,IAAa,UAAkB;EAC7B,IAAI,KAAK,WAAW,eAClB,OAAO,GAAG,KAAK,KAAK;EACtB,IAAI,KAAK,WAAW,gBAClB,OAAO,GAAG,KAAK,KAAK;EACtB,OAAO,KAAK,WAAW,iBACn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,GAAI,aAAa,KAAA,IAAY,CAAC,IAAI,EAAE,gBAAgB,SAAS,OAAO;EACpE,SAAS;GAAE,SAAS;GAAW,MAAM,CAAC,SAAS;EAAE;CACnD,CAAC;CACD,OAAO;EAAE;EAAM;EAAa,MAAM,KAAK;EAAM,KAAK,KAAK;CAAI;AAC7D,CAAC,CACH"}
@@ -14,11 +14,10 @@ export declare class MountInitFailed extends MountInitFailed_base {
14
14
  get message(): string;
15
15
  }
16
16
  /**
17
- * Run every mount's `init` against a pushed deployment: ask the backend's
18
- * deploy module for its steps, then run each mount's `init` at its component
19
- * path, one at a time, and visit a nested component's own steps after its
20
- * `init`. The first failing mount stops the run. Each `init` is its own
21
- * transaction, so earlier mounts stay applied and a rerun converges.
17
+ * Run every mount's `init` against a pushed deployment, in the order
18
+ * `MountSteps.run` walks them, the order the test backend uses too. The first
19
+ * failing mount stops the run. Each `init` is its own transaction, so earlier
20
+ * mounts stay applied and a rerun converges.
22
21
  *
23
22
  * @internal
24
23
  */
@@ -1 +1 @@
1
- {"version":3,"file":"MountInit.d.ts","sources":["../../src/internal/MountInit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,IAAI,MAAM,aAAa,CAAC;AACpC,OAAO,KAAK,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,YAAY,EAAuB,MAAM,oBAAoB,CAAC;;;;;oBAKnD,OAAO,MAAM;;AAFjC,qBAAa,eAAgB,SAAQ,oBAGkC;IACrE,IAAa,OAAO,WAEnB;CACF;AA6BD;;;;;;;;GAQG;AACH,eAAO,MAAM,GAAG,sJAgDd,CAAC"}
1
+ {"version":3,"file":"MountInit.d.ts","sources":["../../src/internal/MountInit.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,IAAI,MAAM,aAAa,CAAC;AACpC,OAAO,KAAK,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,YAAY,EAAuB,MAAM,oBAAoB,CAAC;;;;;oBAKnD,OAAO,MAAM;;AAFjC,qBAAa,eAAgB,SAAQ,oBAGkC;IACrE,IAAa,OAAO,WAEnB;CACF;AAcD;;;;;;;GAOG;AACH,eAAO,MAAM,GAAG,sJAgCd,CAAC"}
@@ -4,6 +4,7 @@ import * as Effect from "effect/Effect";
4
4
  import * as Schema from "effect/Schema";
5
5
  import * as FileSystem from "effect/FileSystem";
6
6
  import * as Path from "effect/Path";
7
+ import * as MountSteps from "@confect/core/MountSteps";
7
8
  // src/internal/MountInit.ts
8
9
  var MountInitFailed = class extends Schema.TaggedError()("MountInitFailed", {
9
10
  mount: Schema.String,
@@ -13,18 +14,6 @@ var MountInitFailed = class extends Schema.TaggedError()("MountInitFailed", {
13
14
  return `${this.mount}: init failed; earlier mounts are applied, and the next push retries`;
14
15
  }
15
16
  };
16
- const Steps = Schema.Array(Schema.Union([Schema.Struct({
17
- componentPath: Schema.String,
18
- nested: Schema.Boolean,
19
- init: Schema.NullOr(Schema.Struct({
20
- functionName: Schema.String,
21
- args: Schema.Unknown
22
- }))
23
- }), Schema.Struct({
24
- componentPath: Schema.String,
25
- failure: Schema.String
26
- })]));
27
- const STEPS = "confectDeploy:steps";
28
17
  /**
29
18
  * Whether codegen wrote `confectDeploy.ts` into the backend's Convex directory.
30
19
  */
@@ -35,11 +24,10 @@ const hasDeployModule = Effect.fn("MountInit.hasDeployModule")(function* (cwd) {
35
24
  return yield* fs.exists(path.join(cwd, functions, "confectDeploy.ts"));
36
25
  });
37
26
  /**
38
- * Run every mount's `init` against a pushed deployment: ask the backend's
39
- * deploy module for its steps, then run each mount's `init` at its component
40
- * path, one at a time, and visit a nested component's own steps after its
41
- * `init`. The first failing mount stops the run. Each `init` is its own
42
- * transaction, so earlier mounts stay applied and a rerun converges.
27
+ * Run every mount's `init` against a pushed deployment, in the order
28
+ * `MountSteps.run` walks them, the order the test backend uses too. The first
29
+ * failing mount stops the run. Each `init` is its own transaction, so earlier
30
+ * mounts stay applied and a rerun converges.
43
31
  *
44
32
  * @internal
45
33
  */
@@ -48,21 +36,16 @@ const run = Effect.fn("MountInit.run")(function* (url, key, cwd) {
48
36
  mount,
49
37
  detail: Schema.is(ConvexFunctionError)(error) ? error.errorMessage : error._tag
50
38
  });
51
- if (!(yield* hasDeployModule(cwd).pipe(Effect.mapError(failed(STEPS))))) return;
39
+ if (!(yield* hasDeployModule(cwd).pipe(Effect.mapError(failed(MountSteps.STEPS))))) return;
52
40
  const client = yield* ConvexClient;
53
- const visit = (prefix) => Effect.gen(function* () {
54
- const steps = yield* client.runFunction(url, key, STEPS, {}, prefix).pipe(Effect.flatMap(Schema.decodeUnknownEffect(Steps)), Effect.mapError(failed(prefix ?? STEPS)));
55
- for (const step of steps) {
56
- const mount = prefix === void 0 ? step.componentPath : `${prefix}/${step.componentPath}`;
57
- if ("failure" in step) return yield* MountInitFailed.make({
58
- mount,
59
- detail: step.failure
60
- });
61
- if (step.init !== null) yield* client.runFunction(url, key, step.init.functionName, step.init.args, mount).pipe(Effect.mapError(failed(mount)));
62
- if (step.nested) yield* visit(mount);
63
- }
41
+ yield* MountSteps.run({
42
+ steps: (prefix) => client.runFunction(url, key, MountSteps.STEPS, {}, prefix).pipe(Effect.mapError(failed(prefix ?? MountSteps.STEPS))),
43
+ init: (mount, functionName, args) => client.runFunction(url, key, functionName, args, mount).pipe(Effect.mapError(failed(mount))),
44
+ failed: (mount, detail) => MountInitFailed.make({
45
+ mount,
46
+ detail
47
+ })
64
48
  });
65
- yield* visit(void 0);
66
49
  });
67
50
  export { MountInitFailed, run };
68
51
 
@@ -1 +1 @@
1
- {"version":3,"file":"MountInit.js","names":[],"sources":["../../src/internal/MountInit.ts"],"sourcesContent":["import * as Effect from \"effect/Effect\";\nimport * as FileSystem from \"effect/FileSystem\";\nimport * as Path from \"effect/Path\";\nimport type * as Redacted from \"effect/Redacted\";\nimport * as Schema from \"effect/Schema\";\nimport { ConvexClient, ConvexFunctionError } from \"../ConvexClient.js\";\nimport { functionsDirectory } from \"./FunctionsDirectory.js\";\n\nexport class MountInitFailed extends Schema.TaggedError<\n MountInitFailed,\n { readonly brand: unique symbol }\n>()(\"MountInitFailed\", { mount: Schema.String, detail: Schema.String }) {\n override get message() {\n return `${this.mount}: init failed; earlier mounts are applied, and the next push retries`;\n }\n}\n\nconst Steps = Schema.Array(\n Schema.Union([\n Schema.Struct({\n componentPath: Schema.String,\n nested: Schema.Boolean,\n init: Schema.NullOr(\n Schema.Struct({ functionName: Schema.String, args: Schema.Unknown }),\n ),\n }),\n Schema.Struct({ componentPath: Schema.String, failure: Schema.String }),\n ]),\n);\n\nconst STEPS = \"confectDeploy:steps\";\n\n/**\n * Whether codegen wrote `confectDeploy.ts` into the backend's Convex directory.\n */\nconst hasDeployModule = Effect.fn(\"MountInit.hasDeployModule\")(function* (\n cwd: string,\n) {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const functions = yield* functionsDirectory(cwd);\n return yield* fs.exists(path.join(cwd, functions, \"confectDeploy.ts\"));\n});\n\n/**\n * Run every mount's `init` against a pushed deployment: ask the backend's\n * deploy module for its steps, then run each mount's `init` at its component\n * path, one at a time, and visit a nested component's own steps after its\n * `init`. The first failing mount stops the run. Each `init` is its own\n * transaction, so earlier mounts stay applied and a rerun converges.\n *\n * @internal\n */\nexport const run = Effect.fn(\"MountInit.run\")(function* (\n url: string,\n key: Redacted.Redacted<string>,\n cwd: string,\n) {\n const failed =\n (mount: string) =>\n (error: { readonly _tag: string }): MountInitFailed =>\n MountInitFailed.make({\n mount,\n detail: Schema.is(ConvexFunctionError)(error)\n ? error.errorMessage\n : error._tag,\n });\n if (!(yield* hasDeployModule(cwd).pipe(Effect.mapError(failed(STEPS)))))\n return;\n const client = yield* ConvexClient;\n const visit = (\n prefix: string | undefined,\n ): Effect.Effect<void, MountInitFailed> =>\n Effect.gen(function* () {\n const steps = yield* client\n .runFunction(url, key, STEPS, {}, prefix)\n .pipe(\n Effect.flatMap(Schema.decodeUnknownEffect(Steps)),\n Effect.mapError(failed(prefix ?? STEPS)),\n );\n for (const step of steps) {\n const mount =\n prefix === undefined\n ? step.componentPath\n : `${prefix}/${step.componentPath}`;\n if (\"failure\" in step)\n return yield* MountInitFailed.make({ mount, detail: step.failure });\n if (step.init !== null)\n yield* client\n .runFunction(\n url,\n key,\n step.init.functionName,\n step.init.args,\n mount,\n )\n .pipe(Effect.mapError(failed(mount)));\n if (step.nested) yield* visit(mount);\n }\n });\n yield* visit(undefined);\n});\n"],"mappings":";;;;;;;AAQA,IAAa,kBAAb,cAAqC,OAAO,YAG1C,CAAC,CAAC,mBAAmB;CAAE,OAAO,OAAO;CAAQ,QAAQ,OAAO;AAAO,CAAC,CAAC,CAAC;CACtE,IAAa,UAAU;EACrB,OAAO,GAAG,KAAK,MAAM;CACvB;AACF;AAEA,MAAM,QAAQ,OAAO,MACnB,OAAO,MAAM,CACX,OAAO,OAAO;CACZ,eAAe,OAAO;CACtB,QAAQ,OAAO;CACf,MAAM,OAAO,OACX,OAAO,OAAO;EAAE,cAAc,OAAO;EAAQ,MAAM,OAAO;CAAQ,CAAC,CACrE;AACF,CAAC,GACD,OAAO,OAAO;CAAE,eAAe,OAAO;CAAQ,SAAS,OAAO;AAAO,CAAC,CACxE,CAAC,CACH;AAEA,MAAM,QAAQ;;;;AAKd,MAAM,kBAAkB,OAAO,GAAG,2BAA2B,CAAC,CAAC,WAC7D,KACA;CACA,MAAM,KAAK,OAAO,WAAW;CAC7B,MAAM,OAAO,OAAO,KAAK;CACzB,MAAM,YAAY,OAAO,mBAAmB,GAAG;CAC/C,OAAO,OAAO,GAAG,OAAO,KAAK,KAAK,KAAK,WAAW,kBAAkB,CAAC;AACvE,CAAC;;;;;;;;;;AAWD,MAAa,MAAM,OAAO,GAAG,eAAe,CAAC,CAAC,WAC5C,KACA,KACA,KACA;CACA,MAAM,UACH,WACA,UACC,gBAAgB,KAAK;EACnB;EACA,QAAQ,OAAO,GAAG,mBAAmB,CAAC,CAAC,KAAK,IACxC,MAAM,eACN,MAAM;CACZ,CAAC;CACL,IAAI,EAAE,OAAO,gBAAgB,GAAG,CAAC,CAAC,KAAK,OAAO,SAAS,OAAO,KAAK,CAAC,CAAC,IACnE;CACF,MAAM,SAAS,OAAO;CACtB,MAAM,SACJ,WAEA,OAAO,IAAI,aAAa;EACtB,MAAM,QAAQ,OAAO,OAClB,YAAY,KAAK,KAAK,OAAO,CAAC,GAAG,MAAM,CAAC,CACxC,KACC,OAAO,QAAQ,OAAO,oBAAoB,KAAK,CAAC,GAChD,OAAO,SAAS,OAAO,UAAU,KAAK,CAAC,CACzC;EACF,KAAK,MAAM,QAAQ,OAAO;GACxB,MAAM,QACJ,WAAW,KAAA,IACP,KAAK,gBACL,GAAG,OAAO,GAAG,KAAK;GACxB,IAAI,aAAa,MACf,OAAO,OAAO,gBAAgB,KAAK;IAAE;IAAO,QAAQ,KAAK;GAAQ,CAAC;GACpE,IAAI,KAAK,SAAS,MAChB,OAAO,OACJ,YACC,KACA,KACA,KAAK,KAAK,cACV,KAAK,KAAK,MACV,KACF,CAAC,CACA,KAAK,OAAO,SAAS,OAAO,KAAK,CAAC,CAAC;GACxC,IAAI,KAAK,QAAQ,OAAO,MAAM,KAAK;EACrC;CACF,CAAC;CACH,OAAO,MAAM,KAAA,CAAS;AACxB,CAAC"}
1
+ {"version":3,"file":"MountInit.js","names":[],"sources":["../../src/internal/MountInit.ts"],"sourcesContent":["import * as MountSteps from \"@confect/core/MountSteps\";\nimport * as Effect from \"effect/Effect\";\nimport * as FileSystem from \"effect/FileSystem\";\nimport * as Path from \"effect/Path\";\nimport type * as Redacted from \"effect/Redacted\";\nimport * as Schema from \"effect/Schema\";\nimport { ConvexClient, ConvexFunctionError } from \"../ConvexClient.js\";\nimport { functionsDirectory } from \"./FunctionsDirectory.js\";\n\nexport class MountInitFailed extends Schema.TaggedError<\n MountInitFailed,\n { readonly brand: unique symbol }\n>()(\"MountInitFailed\", { mount: Schema.String, detail: Schema.String }) {\n override get message() {\n return `${this.mount}: init failed; earlier mounts are applied, and the next push retries`;\n }\n}\n\n/**\n * Whether codegen wrote `confectDeploy.ts` into the backend's Convex directory.\n */\nconst hasDeployModule = Effect.fn(\"MountInit.hasDeployModule\")(function* (\n cwd: string,\n) {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const functions = yield* functionsDirectory(cwd);\n return yield* fs.exists(path.join(cwd, functions, \"confectDeploy.ts\"));\n});\n\n/**\n * Run every mount's `init` against a pushed deployment, in the order\n * `MountSteps.run` walks them, the order the test backend uses too. The first\n * failing mount stops the run. Each `init` is its own transaction, so earlier\n * mounts stay applied and a rerun converges.\n *\n * @internal\n */\nexport const run = Effect.fn(\"MountInit.run\")(function* (\n url: string,\n key: Redacted.Redacted<string>,\n cwd: string,\n) {\n const failed =\n (mount: string) =>\n (error: { readonly _tag: string }): MountInitFailed =>\n MountInitFailed.make({\n mount,\n detail: Schema.is(ConvexFunctionError)(error)\n ? error.errorMessage\n : error._tag,\n });\n if (\n !(yield* hasDeployModule(cwd).pipe(\n Effect.mapError(failed(MountSteps.STEPS)),\n ))\n )\n return;\n const client = yield* ConvexClient;\n yield* MountSteps.run({\n steps: (prefix) =>\n client\n .runFunction(url, key, MountSteps.STEPS, {}, prefix)\n .pipe(Effect.mapError(failed(prefix ?? MountSteps.STEPS))),\n init: (mount, functionName, args) =>\n client\n .runFunction(url, key, functionName, args, mount)\n .pipe(Effect.mapError(failed(mount))),\n failed: (mount, detail) => MountInitFailed.make({ mount, detail }),\n });\n});\n"],"mappings":";;;;;;;;AASA,IAAa,kBAAb,cAAqC,OAAO,YAG1C,CAAC,CAAC,mBAAmB;CAAE,OAAO,OAAO;CAAQ,QAAQ,OAAO;AAAO,CAAC,CAAC,CAAC;CACtE,IAAa,UAAU;EACrB,OAAO,GAAG,KAAK,MAAM;CACvB;AACF;;;;AAKA,MAAM,kBAAkB,OAAO,GAAG,2BAA2B,CAAC,CAAC,WAC7D,KACA;CACA,MAAM,KAAK,OAAO,WAAW;CAC7B,MAAM,OAAO,OAAO,KAAK;CACzB,MAAM,YAAY,OAAO,mBAAmB,GAAG;CAC/C,OAAO,OAAO,GAAG,OAAO,KAAK,KAAK,KAAK,WAAW,kBAAkB,CAAC;AACvE,CAAC;;;;;;;;;AAUD,MAAa,MAAM,OAAO,GAAG,eAAe,CAAC,CAAC,WAC5C,KACA,KACA,KACA;CACA,MAAM,UACH,WACA,UACC,gBAAgB,KAAK;EACnB;EACA,QAAQ,OAAO,GAAG,mBAAmB,CAAC,CAAC,KAAK,IACxC,MAAM,eACN,MAAM;CACZ,CAAC;CACL,IACE,EAAE,OAAO,gBAAgB,GAAG,CAAC,CAAC,KAC5B,OAAO,SAAS,OAAO,WAAW,KAAK,CAAC,CAC1C,IAEA;CACF,MAAM,SAAS,OAAO;CACtB,OAAO,WAAW,IAAI;EACpB,QAAQ,WACN,OACG,YAAY,KAAK,KAAK,WAAW,OAAO,CAAC,GAAG,MAAM,CAAC,CACnD,KAAK,OAAO,SAAS,OAAO,UAAU,WAAW,KAAK,CAAC,CAAC;EAC7D,OAAO,OAAO,cAAc,SAC1B,OACG,YAAY,KAAK,KAAK,cAAc,MAAM,KAAK,CAAC,CAChD,KAAK,OAAO,SAAS,OAAO,KAAK,CAAC,CAAC;EACxC,SAAS,OAAO,WAAW,gBAAgB,KAAK;GAAE;GAAO;EAAO,CAAC;CACnE,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@gaganref/confect-alchemy",
3
- "version": "10.6.0-fork.30",
3
+ "version": "10.6.0-fork.32",
4
4
  "dependencies": {
5
5
  "@convex-dev/platform": "^0.1.10"
6
6
  },
7
7
  "peerDependencies": {
8
- "@confect/cli": "npm:@gaganref/confect-cli@10.6.0-fork.30",
9
- "@confect/core": "npm:@gaganref/confect-core@10.6.0-fork.30",
8
+ "@confect/cli": "npm:@gaganref/confect-cli@10.6.0-fork.32",
9
+ "@confect/core": "npm:@gaganref/confect-core@10.6.0-fork.32",
10
10
  "alchemy": ">=2.0.0-beta.85 <2.0.0",
11
11
  "convex": "^1.32.0",
12
12
  "effect": "~4.1.4"
package/src/Backend.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as Arr from "effect/Array";
2
2
  import * as Env from "@confect/core/Env";
3
3
  import * as Manifest from "@confect/core/Manifest";
4
- import type { Input } from "alchemy/Input";
4
+ import type { Input, InputProps } from "alchemy/Input";
5
5
  import * as Namespace from "alchemy/Namespace";
6
6
  import * as Output from "alchemy/Output";
7
7
  import * as Effect from "effect/Effect";
@@ -10,7 +10,10 @@ import * as Redacted from "effect/Redacted";
10
10
  import * as Schema from "effect/Schema";
11
11
  import * as Result from "effect/Result";
12
12
  import { Code } from "./Code.js";
13
- import { EnvironmentVariables } from "./EnvironmentVariables.js";
13
+ import {
14
+ EnvironmentVariables,
15
+ type EnvironmentVariablesProps,
16
+ } from "./EnvironmentVariables.js";
14
17
 
15
18
  interface CommonProps {
16
19
  readonly deployment: {
@@ -18,6 +21,13 @@ interface CommonProps {
18
21
  readonly url: Input<string>;
19
22
  };
20
23
  readonly deployKey: Input<Redacted.Redacted<string>>;
24
+ /**
25
+ * Safety options for managed environment values. Defaults to the resource
26
+ * defaults.
27
+ */
28
+ readonly environment?: InputProps<
29
+ Omit<EnvironmentVariablesProps, "url" | "deployKey" | "variables">
30
+ >;
21
31
  readonly cwd?: string;
22
32
  }
23
33
 
@@ -487,6 +497,7 @@ const backend = (
487
497
  Rec.keys(variables).length === 0)
488
498
  ? undefined
489
499
  : yield* EnvironmentVariables("Environment", {
500
+ ...props.environment,
490
501
  url: props.deployment.url,
491
502
  deployKey: props.deployKey,
492
503
  variables: variables as Variables,
@@ -1,3 +1,4 @@
1
+ import * as MountSteps from "@confect/core/MountSteps";
1
2
  import * as Effect from "effect/Effect";
2
3
  import * as FileSystem from "effect/FileSystem";
3
4
  import * as Path from "effect/Path";
@@ -15,21 +16,6 @@ export class MountInitFailed extends Schema.TaggedError<
15
16
  }
16
17
  }
17
18
 
18
- const Steps = Schema.Array(
19
- Schema.Union([
20
- Schema.Struct({
21
- componentPath: Schema.String,
22
- nested: Schema.Boolean,
23
- init: Schema.NullOr(
24
- Schema.Struct({ functionName: Schema.String, args: Schema.Unknown }),
25
- ),
26
- }),
27
- Schema.Struct({ componentPath: Schema.String, failure: Schema.String }),
28
- ]),
29
- );
30
-
31
- const STEPS = "confectDeploy:steps";
32
-
33
19
  /**
34
20
  * Whether codegen wrote `confectDeploy.ts` into the backend's Convex directory.
35
21
  */
@@ -43,11 +29,10 @@ const hasDeployModule = Effect.fn("MountInit.hasDeployModule")(function* (
43
29
  });
44
30
 
45
31
  /**
46
- * Run every mount's `init` against a pushed deployment: ask the backend's
47
- * deploy module for its steps, then run each mount's `init` at its component
48
- * path, one at a time, and visit a nested component's own steps after its
49
- * `init`. The first failing mount stops the run. Each `init` is its own
50
- * transaction, so earlier mounts stay applied and a rerun converges.
32
+ * Run every mount's `init` against a pushed deployment, in the order
33
+ * `MountSteps.run` walks them, the order the test backend uses too. The first
34
+ * failing mount stops the run. Each `init` is its own transaction, so earlier
35
+ * mounts stay applied and a rerun converges.
51
36
  *
52
37
  * @internal
53
38
  */
@@ -65,38 +50,22 @@ export const run = Effect.fn("MountInit.run")(function* (
65
50
  ? error.errorMessage
66
51
  : error._tag,
67
52
  });
68
- if (!(yield* hasDeployModule(cwd).pipe(Effect.mapError(failed(STEPS)))))
53
+ if (
54
+ !(yield* hasDeployModule(cwd).pipe(
55
+ Effect.mapError(failed(MountSteps.STEPS)),
56
+ ))
57
+ )
69
58
  return;
70
59
  const client = yield* ConvexClient;
71
- const visit = (
72
- prefix: string | undefined,
73
- ): Effect.Effect<void, MountInitFailed> =>
74
- Effect.gen(function* () {
75
- const steps = yield* client
76
- .runFunction(url, key, STEPS, {}, prefix)
77
- .pipe(
78
- Effect.flatMap(Schema.decodeUnknownEffect(Steps)),
79
- Effect.mapError(failed(prefix ?? STEPS)),
80
- );
81
- for (const step of steps) {
82
- const mount =
83
- prefix === undefined
84
- ? step.componentPath
85
- : `${prefix}/${step.componentPath}`;
86
- if ("failure" in step)
87
- return yield* MountInitFailed.make({ mount, detail: step.failure });
88
- if (step.init !== null)
89
- yield* client
90
- .runFunction(
91
- url,
92
- key,
93
- step.init.functionName,
94
- step.init.args,
95
- mount,
96
- )
97
- .pipe(Effect.mapError(failed(mount)));
98
- if (step.nested) yield* visit(mount);
99
- }
100
- });
101
- yield* visit(undefined);
60
+ yield* MountSteps.run({
61
+ steps: (prefix) =>
62
+ client
63
+ .runFunction(url, key, MountSteps.STEPS, {}, prefix)
64
+ .pipe(Effect.mapError(failed(prefix ?? MountSteps.STEPS))),
65
+ init: (mount, functionName, args) =>
66
+ client
67
+ .runFunction(url, key, functionName, args, mount)
68
+ .pipe(Effect.mapError(failed(mount))),
69
+ failed: (mount, detail) => MountInitFailed.make({ mount, detail }),
70
+ });
102
71
  });