@gaganref/confect-alchemy 10.6.0-fork.29 → 10.6.0-fork.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Backend.d.ts +64 -5
- package/dist/Backend.d.ts.map +1 -1
- package/dist/Backend.js +187 -3
- package/dist/Backend.js.map +1 -1
- package/dist/Code.d.ts +14 -2
- package/dist/Code.d.ts.map +1 -1
- package/dist/Code.js +2 -2
- package/dist/Code.js.map +1 -1
- package/dist/Confect.d.ts +1 -1
- package/dist/Confect.d.ts.map +1 -1
- package/dist/Confect.js +8 -3
- package/dist/Confect.js.map +1 -1
- package/dist/Convex.d.ts +1 -1
- package/dist/Convex.d.ts.map +1 -1
- package/dist/Convex.js +4 -1
- package/dist/Convex.js.map +1 -1
- package/dist/ConvexClient.js +4 -4
- package/dist/CustomDomain.js +3 -3
- package/dist/DeployKey.js +3 -3
- package/dist/Deployment.js +2 -2
- package/dist/EnvironmentVariables.d.ts.map +1 -1
- package/dist/EnvironmentVariables.js +20 -13
- package/dist/EnvironmentVariables.js.map +1 -1
- package/dist/LogStream.js +5 -5
- package/dist/Project.js +2 -2
- package/dist/UsageLimit.js +2 -2
- package/dist/internal/CodeDeployment.d.ts +28 -1
- package/dist/internal/CodeDeployment.d.ts.map +1 -1
- package/dist/internal/CodeDeployment.js +85 -2
- package/dist/internal/CodeDeployment.js.map +1 -1
- package/dist/internal/CommandRunner.js +4 -4
- package/dist/internal/FileLock.js +1 -1
- package/dist/internal/FunctionsDirectory.d.ts +12 -0
- package/dist/internal/FunctionsDirectory.d.ts.map +1 -0
- package/dist/internal/FunctionsDirectory.js +22 -0
- package/dist/internal/FunctionsDirectory.js.map +1 -0
- package/dist/internal/LocalBackend.d.ts +7 -0
- package/dist/internal/LocalBackend.d.ts.map +1 -1
- package/dist/internal/LocalBackend.js +10 -3
- package/dist/internal/LocalBackend.js.map +1 -1
- package/dist/internal/MountInit.d.ts.map +1 -1
- package/dist/internal/MountInit.js +4 -6
- package/dist/internal/MountInit.js.map +1 -1
- package/dist/internal/PushLock.js +1 -1
- package/dist/internal/ResourceIdentity.js +1 -1
- package/dist/internal/Zip.js +1 -1
- package/package.json +3 -3
- package/src/Backend.ts +422 -12
- package/src/Code.ts +13 -0
- package/src/Confect.ts +7 -1
- package/src/Convex.ts +7 -1
- package/src/EnvironmentVariables.ts +27 -12
- package/src/internal/CodeDeployment.ts +115 -0
- package/src/internal/FunctionsDirectory.ts +27 -0
- package/src/internal/LocalBackend.ts +7 -0
- package/src/internal/MountInit.ts +3 -13
package/src/Backend.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as Arr from "effect/Array";
|
|
2
|
+
import * as Env from "@confect/core/Env";
|
|
3
|
+
import * as Manifest from "@confect/core/Manifest";
|
|
2
4
|
import type { Input } from "alchemy/Input";
|
|
3
5
|
import * as Namespace from "alchemy/Namespace";
|
|
4
6
|
import * as Output from "alchemy/Output";
|
|
5
7
|
import * as Effect from "effect/Effect";
|
|
6
|
-
import
|
|
8
|
+
import * as Rec from "effect/Record";
|
|
9
|
+
import * as Redacted from "effect/Redacted";
|
|
10
|
+
import * as Schema from "effect/Schema";
|
|
11
|
+
import * as Result from "effect/Result";
|
|
7
12
|
import { Code } from "./Code.js";
|
|
8
13
|
import { EnvironmentVariables } from "./EnvironmentVariables.js";
|
|
9
14
|
|
|
@@ -22,14 +27,41 @@ type Environment<M extends Manifest.Manifest> = {
|
|
|
22
27
|
>;
|
|
23
28
|
};
|
|
24
29
|
|
|
30
|
+
type MountSettings<M extends Manifest.Manifest> = {
|
|
31
|
+
readonly [K in keyof Manifest.Mounts<M>]: {
|
|
32
|
+
readonly [S in keyof NonNullable<Manifest.Mounts<M>[K]>]: Input<
|
|
33
|
+
Exclude<NonNullable<Manifest.Mounts<M>[K]>[S], undefined>
|
|
34
|
+
>;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
type AutomaticValues<M extends Manifest.Manifest> = {
|
|
39
|
+
readonly [K in keyof Manifest.Automatic<M>]: Input<Manifest.Automatic<M>[K]>;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Inputs for a backend deployment. An input Effect or Config may be evaluated
|
|
44
|
+
* several times in plan and again in apply, more often for a provider selector
|
|
45
|
+
* and its settings. It must be free of side effects and return the same value
|
|
46
|
+
* every time. Otherwise, a choice can be written without a setting it
|
|
47
|
+
* requires.
|
|
48
|
+
*/
|
|
25
49
|
export type BackendProps<M extends Manifest.Manifest | undefined = undefined> =
|
|
26
50
|
CommonProps &
|
|
27
51
|
(M extends Manifest.Manifest
|
|
28
52
|
? { readonly manifest: M } & ({} extends Manifest.Values<M>
|
|
29
53
|
? { readonly env?: Environment<NoInfer<M>> }
|
|
30
|
-
: { readonly env: Environment<NoInfer<M>> })
|
|
54
|
+
: { readonly env: Environment<NoInfer<M>> }) &
|
|
55
|
+
({} extends Manifest.Mounts<M>
|
|
56
|
+
? { readonly mounts?: MountSettings<NoInfer<M>> }
|
|
57
|
+
: { readonly mounts: MountSettings<NoInfer<M>> }) &
|
|
58
|
+
({} extends Manifest.Automatic<M>
|
|
59
|
+
? { readonly automatic?: AutomaticValues<NoInfer<M>> }
|
|
60
|
+
: { readonly automatic: AutomaticValues<NoInfer<M>> })
|
|
31
61
|
: {
|
|
32
62
|
readonly manifest?: never;
|
|
63
|
+
readonly mounts?: never;
|
|
64
|
+
readonly automatic?: never;
|
|
33
65
|
readonly env?: Readonly<
|
|
34
66
|
Record<string, Input<string | Redacted.Redacted<string>>>
|
|
35
67
|
>;
|
|
@@ -41,11 +73,14 @@ export type BackendProps<M extends Manifest.Manifest | undefined = undefined> =
|
|
|
41
73
|
export function Backend<
|
|
42
74
|
const M extends Manifest.Manifest,
|
|
43
75
|
const E extends Environment<NoInfer<M>> = Environment<NoInfer<M>>,
|
|
76
|
+
const S extends MountSettings<NoInfer<M>> = MountSettings<NoInfer<M>>,
|
|
44
77
|
>(
|
|
45
78
|
id: string,
|
|
46
79
|
props: BackendProps<M> & {
|
|
47
80
|
readonly env?: E &
|
|
48
|
-
Readonly<Record<Exclude<keyof E, keyof M
|
|
81
|
+
Readonly<Record<Exclude<keyof E, keyof Environment<M>>, never>>;
|
|
82
|
+
readonly mounts?: S &
|
|
83
|
+
Readonly<Record<Exclude<keyof S, keyof M["mounts"]>, never>>;
|
|
49
84
|
},
|
|
50
85
|
): ReturnType<typeof backend>;
|
|
51
86
|
export function Backend(
|
|
@@ -55,32 +90,406 @@ export function Backend(
|
|
|
55
90
|
export function Backend(
|
|
56
91
|
id: string,
|
|
57
92
|
props: CommonProps & {
|
|
58
|
-
readonly
|
|
59
|
-
|
|
60
|
-
|
|
93
|
+
readonly manifest?: Manifest.Manifest;
|
|
94
|
+
readonly env?: Settings;
|
|
95
|
+
readonly automatic?: Variables;
|
|
96
|
+
readonly mounts?: Readonly<Record<string, Settings>>;
|
|
61
97
|
},
|
|
62
98
|
): ReturnType<typeof backend> {
|
|
63
99
|
return backend(id, props);
|
|
64
100
|
}
|
|
65
101
|
|
|
102
|
+
type Settings = Readonly<
|
|
103
|
+
Record<string, Input<string | Redacted.Redacted<string> | Env.ProviderChoice>>
|
|
104
|
+
>;
|
|
105
|
+
|
|
106
|
+
type Variables = Readonly<
|
|
107
|
+
Record<string, Input<string | Redacted.Redacted<string>>>
|
|
108
|
+
>;
|
|
109
|
+
|
|
110
|
+
export class InvalidAutomaticSetting extends Schema.TaggedError<
|
|
111
|
+
InvalidAutomaticSetting,
|
|
112
|
+
{ readonly brand: unique symbol }
|
|
113
|
+
>()("InvalidAutomaticSetting", {
|
|
114
|
+
slot: Schema.String,
|
|
115
|
+
reason: Schema.Literals([
|
|
116
|
+
"NotAutomatic",
|
|
117
|
+
"Missing",
|
|
118
|
+
"InvalidValue",
|
|
119
|
+
"PlainSecret",
|
|
120
|
+
]),
|
|
121
|
+
}) {
|
|
122
|
+
override get message(): string {
|
|
123
|
+
if (this.reason === "PlainSecret")
|
|
124
|
+
return `${this.slot} is a plain string. Wrap this secret with Redacted.make before passing it in Backend.automatic.`;
|
|
125
|
+
if (this.reason === "InvalidValue")
|
|
126
|
+
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.`;
|
|
127
|
+
return this.reason === "NotAutomatic"
|
|
128
|
+
? `${this.slot} is not declared automatic in manifest.env. Supply only automatic slots in Backend.automatic; put application values in Backend.env.`
|
|
129
|
+
: `${this.slot} is declared automatic in manifest.env but has no value. Supply it in Backend.automatic.`;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const automaticVariables = (
|
|
134
|
+
manifest: Manifest.Manifest,
|
|
135
|
+
supplied: Variables,
|
|
136
|
+
): Result.Result<Variables, InvalidAutomaticSetting> =>
|
|
137
|
+
Result.gen(function* () {
|
|
138
|
+
for (const slot of Rec.keys(supplied)) {
|
|
139
|
+
if (
|
|
140
|
+
!Rec.has(manifest.env, slot) ||
|
|
141
|
+
manifest.env[slot]?.automatic !== true
|
|
142
|
+
)
|
|
143
|
+
return yield* Result.fail(
|
|
144
|
+
InvalidAutomaticSetting.make({ slot, reason: "NotAutomatic" }),
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
for (const [slot, descriptor] of Rec.toEntries(manifest.env)) {
|
|
148
|
+
if (
|
|
149
|
+
descriptor.automatic === true &&
|
|
150
|
+
missing(Rec.has(supplied, slot) ? supplied[slot] : undefined)
|
|
151
|
+
)
|
|
152
|
+
return yield* Result.fail(
|
|
153
|
+
InvalidAutomaticSetting.make({ slot, reason: "Missing" }),
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
return supplied;
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
const missing = (value: unknown): boolean =>
|
|
160
|
+
value === undefined ||
|
|
161
|
+
value === null ||
|
|
162
|
+
value === "" ||
|
|
163
|
+
(Redacted.isRedacted(value) && Redacted.value(value) === "");
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* A provider choice validated and encoded with the schema the handler decodes
|
|
167
|
+
* it with, after refusing a choice that names a provider whose required setting
|
|
168
|
+
* is unset. A setting belongs to the selector its tag names.
|
|
169
|
+
*/
|
|
170
|
+
const settleChoice = (
|
|
171
|
+
at: string,
|
|
172
|
+
key: string,
|
|
173
|
+
selector: Env.Descriptor & { readonly kind: "providers" },
|
|
174
|
+
slots: Readonly<Record<string, Env.Descriptor>>,
|
|
175
|
+
supplied: Readonly<Record<string, unknown>>,
|
|
176
|
+
value: unknown,
|
|
177
|
+
) =>
|
|
178
|
+
Effect.gen(function* () {
|
|
179
|
+
if (selector.optional && missing(value)) return undefined;
|
|
180
|
+
const invalid = InvalidMountSetting.make({
|
|
181
|
+
mount: at,
|
|
182
|
+
slot: key,
|
|
183
|
+
reason: "InvalidChoice",
|
|
184
|
+
});
|
|
185
|
+
const schema = Env.providerChoice(selector.values);
|
|
186
|
+
const choice = yield* Schema.decodeUnknownEffect(Schema.toType(schema))(
|
|
187
|
+
value,
|
|
188
|
+
).pipe(Effect.mapError(() => invalid));
|
|
189
|
+
const named = Env.chosen(choice);
|
|
190
|
+
for (const [slot, other] of Rec.toEntries(slots)) {
|
|
191
|
+
if (
|
|
192
|
+
other.provider?.selector === key &&
|
|
193
|
+
other.provider.required &&
|
|
194
|
+
named.includes(other.provider.name) &&
|
|
195
|
+
missing(Rec.has(supplied, slot) ? supplied[slot] : undefined)
|
|
196
|
+
)
|
|
197
|
+
return yield* InvalidMountSetting.make({
|
|
198
|
+
mount: at,
|
|
199
|
+
slot,
|
|
200
|
+
reason: "Missing",
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
return yield* Schema.encodeUnknownEffect(schema)(choice).pipe(
|
|
204
|
+
Effect.mapError(() => invalid),
|
|
205
|
+
);
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Normalize all accepted Input forms without resolving resource dependencies.
|
|
210
|
+
* Redacted values remain opaque; arrays and choice records retain their shape.
|
|
211
|
+
*/
|
|
212
|
+
const normalize = (value: unknown): unknown => {
|
|
213
|
+
if (Output.isOutput(value)) return value;
|
|
214
|
+
if (Effect.isEffect(value)) {
|
|
215
|
+
// 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.
|
|
216
|
+
return value.pipe(Effect.orDie, Output.fromEffect);
|
|
217
|
+
}
|
|
218
|
+
if (value === null || typeof value !== "object" || Redacted.isRedacted(value))
|
|
219
|
+
return value;
|
|
220
|
+
if (Arr.isArray(value)) {
|
|
221
|
+
const inputs = Arr.map(value, normalize);
|
|
222
|
+
return Arr.some(inputs, Output.isOutput)
|
|
223
|
+
? Output.all(...Arr.map(inputs, (input) => Output.asOutput(input)))
|
|
224
|
+
: inputs;
|
|
225
|
+
}
|
|
226
|
+
const entries = Arr.map(
|
|
227
|
+
Rec.toEntries(value),
|
|
228
|
+
([key, input]) => [key, normalize(input)] as const,
|
|
229
|
+
);
|
|
230
|
+
const assemble = (resolved: ReadonlyArray<unknown>) =>
|
|
231
|
+
Rec.fromEntries(Arr.map(entries, ([key], index) => [key, resolved[index]]));
|
|
232
|
+
const inputs = Arr.map(entries, ([, input]) => input);
|
|
233
|
+
return Arr.some(inputs, Output.isOutput)
|
|
234
|
+
? Output.map(
|
|
235
|
+
Output.all(...Arr.map(inputs, (input) => Output.asOutput(input))),
|
|
236
|
+
assemble,
|
|
237
|
+
)
|
|
238
|
+
: assemble(inputs);
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Each supplied slot keeps its input edges. A tagged setting also reads its
|
|
243
|
+
* selector's input, and a selector reads only its own tagged settings.
|
|
244
|
+
*/
|
|
245
|
+
const supplySettings = <E>(
|
|
246
|
+
at: string,
|
|
247
|
+
slots: Readonly<Record<string, Env.Descriptor>>,
|
|
248
|
+
supplied: Readonly<Record<string, unknown>>,
|
|
249
|
+
invalid: (
|
|
250
|
+
slot: string,
|
|
251
|
+
reason: "Missing" | "InvalidValue" | "PlainSecret",
|
|
252
|
+
) => E,
|
|
253
|
+
) =>
|
|
254
|
+
Effect.gen(function* () {
|
|
255
|
+
const normalized = Rec.map(supplied, normalize);
|
|
256
|
+
const entries: Array<[string, unknown]> = [];
|
|
257
|
+
const settle = (
|
|
258
|
+
key: string,
|
|
259
|
+
descriptor: Env.Descriptor,
|
|
260
|
+
value: unknown,
|
|
261
|
+
choice?: unknown,
|
|
262
|
+
) =>
|
|
263
|
+
Effect.gen(function* () {
|
|
264
|
+
if (missing(value)) {
|
|
265
|
+
const provider = descriptor.provider;
|
|
266
|
+
const selector =
|
|
267
|
+
provider === undefined ? undefined : slots[provider.selector];
|
|
268
|
+
if (
|
|
269
|
+
provider?.required === true &&
|
|
270
|
+
selector?.kind === "providers" &&
|
|
271
|
+
!missing(choice)
|
|
272
|
+
)
|
|
273
|
+
yield* settleChoice(
|
|
274
|
+
at,
|
|
275
|
+
provider.selector,
|
|
276
|
+
selector,
|
|
277
|
+
{ [key]: descriptor },
|
|
278
|
+
{ [key]: value },
|
|
279
|
+
choice,
|
|
280
|
+
);
|
|
281
|
+
if (!descriptor.optional)
|
|
282
|
+
return yield* Effect.fail(invalid(key, "Missing"));
|
|
283
|
+
return undefined;
|
|
284
|
+
}
|
|
285
|
+
if (descriptor.kind === "secret" && typeof value === "string")
|
|
286
|
+
return yield* Effect.fail(invalid(key, "PlainSecret"));
|
|
287
|
+
const valid =
|
|
288
|
+
descriptor.kind === "secret"
|
|
289
|
+
? Redacted.isRedacted(value) &&
|
|
290
|
+
typeof Redacted.value(value) === "string"
|
|
291
|
+
: descriptor.kind === "providers" ||
|
|
292
|
+
(typeof value === "string" &&
|
|
293
|
+
(descriptor.kind !== "literals" ||
|
|
294
|
+
descriptor.values.includes(value)));
|
|
295
|
+
if (!valid) return yield* Effect.fail(invalid(key, "InvalidValue"));
|
|
296
|
+
return value;
|
|
297
|
+
});
|
|
298
|
+
for (const [key, descriptor] of Rec.toEntries(slots)) {
|
|
299
|
+
const value = Rec.has(normalized, key) ? normalized[key] : undefined;
|
|
300
|
+
const choice =
|
|
301
|
+
descriptor.provider === undefined ||
|
|
302
|
+
!Rec.has(normalized, descriptor.provider.selector)
|
|
303
|
+
? undefined
|
|
304
|
+
: normalized[descriptor.provider.selector];
|
|
305
|
+
const checked =
|
|
306
|
+
Output.isOutput(value) || Output.isOutput(choice)
|
|
307
|
+
? Output.all(Output.asOutput(value), Output.asOutput(choice)).pipe(
|
|
308
|
+
Output.mapEffect(([resolved, selected]) =>
|
|
309
|
+
settle(key, descriptor, resolved, selected).pipe(Effect.orDie),
|
|
310
|
+
),
|
|
311
|
+
)
|
|
312
|
+
: yield* settle(key, descriptor, value, choice);
|
|
313
|
+
if (checked !== undefined) entries.push([key, checked]);
|
|
314
|
+
}
|
|
315
|
+
const settings = Rec.fromEntries(entries);
|
|
316
|
+
for (const [key, descriptor] of Rec.toEntries(slots)) {
|
|
317
|
+
if (descriptor.kind !== "providers" || !Rec.has(settings, key)) continue;
|
|
318
|
+
const value = settings[key];
|
|
319
|
+
const tagged = Rec.filter(
|
|
320
|
+
settings,
|
|
321
|
+
(_, slot) => slots[slot]?.provider?.selector === key,
|
|
322
|
+
);
|
|
323
|
+
const check = (
|
|
324
|
+
choice: unknown,
|
|
325
|
+
resolved: Readonly<Record<string, unknown>>,
|
|
326
|
+
) => settleChoice(at, key, descriptor, slots, resolved, choice);
|
|
327
|
+
const inputs = normalize({ value, tagged });
|
|
328
|
+
settings[key] = Output.isOutput(inputs)
|
|
329
|
+
? inputs.pipe(
|
|
330
|
+
Output.mapEffect(
|
|
331
|
+
(resolved: {
|
|
332
|
+
readonly value: unknown;
|
|
333
|
+
readonly tagged: Readonly<Record<string, unknown>>;
|
|
334
|
+
}) => check(resolved.value, resolved.tagged).pipe(Effect.orDie),
|
|
335
|
+
),
|
|
336
|
+
)
|
|
337
|
+
: yield* check(value, tagged);
|
|
338
|
+
}
|
|
339
|
+
return settings as Record<string, Variables[string]>;
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
export class InvalidMountSetting extends Schema.TaggedError<
|
|
343
|
+
InvalidMountSetting,
|
|
344
|
+
{ readonly brand: unique symbol }
|
|
345
|
+
>()("InvalidMountSetting", {
|
|
346
|
+
mount: Schema.String,
|
|
347
|
+
slot: Schema.optional(Schema.String),
|
|
348
|
+
reason: Schema.Literals([
|
|
349
|
+
"UnknownMount",
|
|
350
|
+
"NotOpen",
|
|
351
|
+
"Missing",
|
|
352
|
+
"PlainSecret",
|
|
353
|
+
"InvalidChoice",
|
|
354
|
+
"InvalidValue",
|
|
355
|
+
]),
|
|
356
|
+
}) {
|
|
357
|
+
override get message() {
|
|
358
|
+
const at =
|
|
359
|
+
this.slot === undefined ? this.mount : `${this.mount}.${this.slot}`;
|
|
360
|
+
const location = this.mount === "app" ? "Backend.env" : "Backend.mounts";
|
|
361
|
+
const remedy = {
|
|
362
|
+
UnknownMount:
|
|
363
|
+
"This mount is not listed. Use a mount name from manifest.mounts.",
|
|
364
|
+
NotOpen:
|
|
365
|
+
"This slot is not open. Supply only slots listed in this mount's manifest env.",
|
|
366
|
+
Missing: `This required slot is missing. Supply this required slot in ${location}.`,
|
|
367
|
+
PlainSecret: `This secret is a plain string. Wrap this secret with Redacted.make before passing it in ${location}.`,
|
|
368
|
+
InvalidValue:
|
|
369
|
+
"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.",
|
|
370
|
+
InvalidChoice:
|
|
371
|
+
"This provider choice is one the component would refuse. Name one of the providers this selector offers, or a failover or pool of them.",
|
|
372
|
+
};
|
|
373
|
+
return `${at}: ${remedy[this.reason]}`;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* Each mount's settings under the deployment variable the manifest names for
|
|
379
|
+
* it, refusing a manifest that does not decode, a mount or slot the manifest
|
|
380
|
+
* does not list as open, a missing required slot, a plain string for a secret
|
|
381
|
+
* and a provider choice the component would refuse.
|
|
382
|
+
*/
|
|
383
|
+
export const mountVariables = (
|
|
384
|
+
input: Manifest.Manifest,
|
|
385
|
+
mounts: Readonly<Record<string, Settings>>,
|
|
386
|
+
): Effect.Effect<
|
|
387
|
+
Record<string, Variables[string]>,
|
|
388
|
+
InvalidMountSetting | Manifest.UnsupportedManifestFormat
|
|
389
|
+
> =>
|
|
390
|
+
Effect.gen(function* () {
|
|
391
|
+
const manifest = yield* Effect.fromResult(
|
|
392
|
+
Manifest.decode(input, "confect/_generated/manifest.ts"),
|
|
393
|
+
);
|
|
394
|
+
const variables: Record<string, Variables[string]> = {};
|
|
395
|
+
for (const mount of Rec.keys(mounts)) {
|
|
396
|
+
if (!Rec.has(manifest.mounts, mount))
|
|
397
|
+
return yield* InvalidMountSetting.make({
|
|
398
|
+
mount,
|
|
399
|
+
reason: "UnknownMount",
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
for (const [mount, entry] of Rec.toEntries(manifest.mounts)) {
|
|
403
|
+
const supplied =
|
|
404
|
+
(Rec.has(mounts, mount) ? mounts[mount] : undefined) ?? {};
|
|
405
|
+
for (const slot of Rec.keys(supplied)) {
|
|
406
|
+
if (!Rec.has(entry.env, slot))
|
|
407
|
+
return yield* InvalidMountSetting.make({
|
|
408
|
+
mount,
|
|
409
|
+
slot,
|
|
410
|
+
reason: "NotOpen",
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
const settings = yield* supplySettings(
|
|
414
|
+
mount,
|
|
415
|
+
entry.env,
|
|
416
|
+
supplied,
|
|
417
|
+
(slot, reason) => InvalidMountSetting.make({ mount, slot, reason }),
|
|
418
|
+
);
|
|
419
|
+
for (const [slot, value] of Rec.toEntries(settings)) {
|
|
420
|
+
variables[entry.env[slot]!.variable] = value;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
return variables;
|
|
424
|
+
});
|
|
425
|
+
|
|
66
426
|
const backend = (
|
|
67
427
|
id: string,
|
|
68
428
|
props: CommonProps & {
|
|
69
|
-
readonly
|
|
70
|
-
|
|
71
|
-
|
|
429
|
+
readonly manifest?: Manifest.Manifest;
|
|
430
|
+
readonly env?: Settings;
|
|
431
|
+
readonly automatic?: Variables;
|
|
432
|
+
readonly mounts?: Readonly<Record<string, Settings>>;
|
|
72
433
|
},
|
|
73
434
|
) =>
|
|
74
435
|
Namespace.push(
|
|
75
436
|
id,
|
|
76
437
|
Effect.gen(function* () {
|
|
438
|
+
const manifest =
|
|
439
|
+
props.manifest === undefined
|
|
440
|
+
? undefined
|
|
441
|
+
: yield* Effect.fromResult(
|
|
442
|
+
Manifest.decode(props.manifest, "confect/_generated/manifest.ts"),
|
|
443
|
+
).pipe(Effect.orDie);
|
|
444
|
+
const promoted =
|
|
445
|
+
manifest === undefined
|
|
446
|
+
? {}
|
|
447
|
+
: yield* mountVariables(manifest, props.mounts ?? {}).pipe(
|
|
448
|
+
Effect.orDie,
|
|
449
|
+
);
|
|
450
|
+
const automaticInput =
|
|
451
|
+
manifest === undefined
|
|
452
|
+
? undefined
|
|
453
|
+
: yield* Effect.fromResult(
|
|
454
|
+
automaticVariables(manifest, props.automatic ?? {}),
|
|
455
|
+
).pipe(Effect.orDie);
|
|
456
|
+
const automatic =
|
|
457
|
+
manifest === undefined || automaticInput === undefined
|
|
458
|
+
? undefined
|
|
459
|
+
: yield* supplySettings(
|
|
460
|
+
"app",
|
|
461
|
+
Rec.filter(manifest.env, (slot) => slot.automatic === true),
|
|
462
|
+
automaticInput,
|
|
463
|
+
(slot, reason) => InvalidAutomaticSetting.make({ slot, reason }),
|
|
464
|
+
).pipe(Effect.orDie);
|
|
465
|
+
const env =
|
|
466
|
+
manifest === undefined
|
|
467
|
+
? props.env
|
|
468
|
+
: yield* supplySettings(
|
|
469
|
+
"app",
|
|
470
|
+
Rec.filter(manifest.env, (slot) => slot.automatic !== true),
|
|
471
|
+
props.env ?? {},
|
|
472
|
+
(slot, reason) =>
|
|
473
|
+
InvalidMountSetting.make({
|
|
474
|
+
mount: "app",
|
|
475
|
+
slot,
|
|
476
|
+
reason,
|
|
477
|
+
}),
|
|
478
|
+
).pipe(Effect.orDie);
|
|
479
|
+
const variables =
|
|
480
|
+
Rec.keys(promoted).length === 0 && props.automatic === undefined
|
|
481
|
+
? env
|
|
482
|
+
: { ...env, ...automatic, ...promoted };
|
|
77
483
|
const environment =
|
|
78
|
-
|
|
484
|
+
variables === undefined ||
|
|
485
|
+
(props.env === undefined &&
|
|
486
|
+
props.automatic === undefined &&
|
|
487
|
+
Rec.keys(variables).length === 0)
|
|
79
488
|
? undefined
|
|
80
489
|
: yield* EnvironmentVariables("Environment", {
|
|
81
490
|
url: props.deployment.url,
|
|
82
491
|
deployKey: props.deployKey,
|
|
83
|
-
variables:
|
|
492
|
+
variables: variables as Variables,
|
|
84
493
|
});
|
|
85
494
|
const code = yield* Code("Code", {
|
|
86
495
|
deployment: {
|
|
@@ -95,6 +504,7 @@ const backend = (
|
|
|
95
504
|
},
|
|
96
505
|
deployKey: props.deployKey,
|
|
97
506
|
...(props.cwd === undefined ? {} : { cwd: props.cwd }),
|
|
507
|
+
...(manifest === undefined ? {} : { manifestDigest: manifest.digest }),
|
|
98
508
|
prepare: { command: "confect", args: ["codegen"] },
|
|
99
509
|
});
|
|
100
510
|
return { code, environment, name: code.name, url: code.url };
|
package/src/Code.ts
CHANGED
|
@@ -10,6 +10,8 @@ import type * as Redacted from "effect/Redacted";
|
|
|
10
10
|
import { ConvexClient, layer as ConvexClientLayer } from "./ConvexClient.js";
|
|
11
11
|
import type { Providers } from "./Providers.js";
|
|
12
12
|
import { deploy } from "./internal/CodeDeployment.js";
|
|
13
|
+
|
|
14
|
+
export { HealthCheckFailed, StaleManifest } from "./internal/CodeDeployment.js";
|
|
13
15
|
import {
|
|
14
16
|
CommandRunner,
|
|
15
17
|
type PrepareCommand,
|
|
@@ -21,6 +23,17 @@ export interface CodeProps {
|
|
|
21
23
|
readonly deployKey: Redacted.Redacted<string>;
|
|
22
24
|
readonly cwd?: string;
|
|
23
25
|
readonly prepare?: PrepareCommand;
|
|
26
|
+
/**
|
|
27
|
+
* The digest of the manifest this push deploys. After `prepare` and before
|
|
28
|
+
* the push, the deploy verifies the complete generated `confectHealth.ts`
|
|
29
|
+
* with LF or CRLF line endings. Edited or missing files fail with
|
|
30
|
+
* `StaleManifest` reason `NotGenerated`; another digest uses
|
|
31
|
+
* `DifferentDigest`. Both push nothing. Do not edit or format the generated
|
|
32
|
+
* file. After every mount's `init`, still inside the push lock, it asks the
|
|
33
|
+
* pushed code which digest it was generated with and fails when it answers
|
|
34
|
+
* nothing or another one.
|
|
35
|
+
*/
|
|
36
|
+
readonly manifestDigest?: string;
|
|
24
37
|
}
|
|
25
38
|
|
|
26
39
|
export interface CodeAttributes {
|
package/src/Confect.ts
CHANGED
package/src/Convex.ts
CHANGED
|
@@ -18,7 +18,13 @@ export {
|
|
|
18
18
|
type EnvironmentVariablesProps,
|
|
19
19
|
type EnvironmentVariablesAttributes,
|
|
20
20
|
} from "./EnvironmentVariables.js";
|
|
21
|
-
export {
|
|
21
|
+
export {
|
|
22
|
+
Code,
|
|
23
|
+
type CodeProps,
|
|
24
|
+
type CodeAttributes,
|
|
25
|
+
HealthCheckFailed,
|
|
26
|
+
StaleManifest,
|
|
27
|
+
} from "./Code.js";
|
|
22
28
|
export { providers, Providers } from "./Providers.js";
|
|
23
29
|
export {
|
|
24
30
|
LogStream,
|
|
@@ -283,12 +283,23 @@ const ownershipConflict = (variableName: string) =>
|
|
|
283
283
|
physicalName: variableName,
|
|
284
284
|
});
|
|
285
285
|
|
|
286
|
+
const definedVariables = <A>(variables: Readonly<Record<string, A>>) =>
|
|
287
|
+
Rec.filter(variables, (value) => value !== null && value !== undefined);
|
|
288
|
+
|
|
286
289
|
const optionsForDiff = (
|
|
287
290
|
olds: EnvironmentVariablesProps,
|
|
288
291
|
news: Input<EnvironmentVariablesProps>,
|
|
289
292
|
) => {
|
|
290
293
|
if (!("variables" in news))
|
|
291
294
|
return { ...olds, desiredNames: undefined, desiredVariables: undefined };
|
|
295
|
+
const desiredVariables =
|
|
296
|
+
!Output.isExpr(news.variables) &&
|
|
297
|
+
!Effect.isEffect(news.variables) &&
|
|
298
|
+
Predicate.isReadonlyObject(news.variables)
|
|
299
|
+
? definedVariables<Input<string | Redacted.Redacted<string>>>(
|
|
300
|
+
news.variables,
|
|
301
|
+
)
|
|
302
|
+
: undefined;
|
|
292
303
|
return {
|
|
293
304
|
driftPolicy: isResolved(news.driftPolicy)
|
|
294
305
|
? news.driftPolicy
|
|
@@ -301,13 +312,9 @@ const optionsForDiff = (
|
|
|
301
312
|
: olds.unownedPolicy,
|
|
302
313
|
lock: isResolved(news.lock) ? news.lock : olds.lock,
|
|
303
314
|
retry: isResolved(news.retry) ? news.retry : olds.retry,
|
|
304
|
-
desiredVariables
|
|
315
|
+
desiredVariables,
|
|
305
316
|
desiredNames:
|
|
306
|
-
|
|
307
|
-
!Effect.isEffect(news.variables) &&
|
|
308
|
-
Predicate.isReadonlyObject(news.variables)
|
|
309
|
-
? Rec.keys<string, unknown>(news.variables)
|
|
310
|
-
: undefined,
|
|
317
|
+
desiredVariables === undefined ? undefined : Rec.keys(desiredVariables),
|
|
311
318
|
};
|
|
312
319
|
};
|
|
313
320
|
|
|
@@ -484,7 +491,8 @@ export const provider = Effect.gen(function* () {
|
|
|
484
491
|
return yield* EnvironmentTargetChange.make({
|
|
485
492
|
url: output.url,
|
|
486
493
|
});
|
|
487
|
-
const
|
|
494
|
+
const desired = definedVariables(news.variables);
|
|
495
|
+
const names = Rec.keys(desired);
|
|
488
496
|
if (
|
|
489
497
|
names.length !== output.ownedNames.length ||
|
|
490
498
|
Arr.some(names, (name) => !output.ownedNames.includes(name))
|
|
@@ -494,7 +502,7 @@ export const provider = Effect.gen(function* () {
|
|
|
494
502
|
news.url,
|
|
495
503
|
news.deployKey,
|
|
496
504
|
);
|
|
497
|
-
for (const [name, value] of Rec.toEntries(
|
|
505
|
+
for (const [name, value] of Rec.toEntries(desired)) {
|
|
498
506
|
const observed = valueAt(variables, name);
|
|
499
507
|
if (
|
|
500
508
|
observed === undefined ||
|
|
@@ -510,14 +518,20 @@ export const provider = Effect.gen(function* () {
|
|
|
510
518
|
url,
|
|
511
519
|
olds.deployKey,
|
|
512
520
|
);
|
|
513
|
-
yield* checkDrift(
|
|
521
|
+
yield* checkDrift(
|
|
522
|
+
olds.driftPolicy,
|
|
523
|
+
output,
|
|
524
|
+
observed,
|
|
525
|
+
definedVariables(olds.variables),
|
|
526
|
+
);
|
|
514
527
|
yield* checkUnowned(
|
|
515
528
|
olds.unownedPolicy,
|
|
516
529
|
output,
|
|
517
|
-
Rec.keys(olds.variables),
|
|
530
|
+
Rec.keys(definedVariables(olds.variables)),
|
|
518
531
|
observed,
|
|
519
532
|
);
|
|
520
|
-
const ownedNames =
|
|
533
|
+
const ownedNames =
|
|
534
|
+
output?.ownedNames ?? Rec.keys(definedVariables(olds.variables));
|
|
521
535
|
const variables = select(observed, ownedNames);
|
|
522
536
|
if (output !== undefined)
|
|
523
537
|
return { ...output, deployKey: olds.deployKey, variables };
|
|
@@ -546,6 +560,7 @@ export const provider = Effect.gen(function* () {
|
|
|
546
560
|
news,
|
|
547
561
|
output,
|
|
548
562
|
}) {
|
|
563
|
+
news = { ...news, variables: definedVariables(news.variables) };
|
|
549
564
|
if (output === undefined) yield* checkpointCreate(fqn, instanceId, news);
|
|
550
565
|
if (output !== undefined && output.url !== news.url)
|
|
551
566
|
return yield* EnvironmentTargetChange.make({
|
|
@@ -660,7 +675,7 @@ export const provider = Effect.gen(function* () {
|
|
|
660
675
|
yield* checkUnowned(
|
|
661
676
|
olds.unownedPolicy,
|
|
662
677
|
output,
|
|
663
|
-
Rec.keys(olds.variables),
|
|
678
|
+
Rec.keys(definedVariables(olds.variables)),
|
|
664
679
|
observed,
|
|
665
680
|
);
|
|
666
681
|
const changes: Array<{
|