@gaganref/confect-alchemy 10.6.0-fork.3 → 10.6.0-fork.31
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 +4 -1
- package/dist/Convex.d.ts.map +1 -1
- package/dist/Convex.js +10 -1
- package/dist/Convex.js.map +1 -1
- package/dist/ConvexClient.d.ts +92 -3
- package/dist/ConvexClient.d.ts.map +1 -1
- package/dist/ConvexClient.js +149 -27
- package/dist/ConvexClient.js.map +1 -1
- package/dist/CustomDomain.d.ts +156 -0
- package/dist/CustomDomain.d.ts.map +1 -0
- package/dist/CustomDomain.js +255 -0
- package/dist/CustomDomain.js.map +1 -0
- package/dist/DeployKey.js +3 -3
- package/dist/Deployment.d.ts +29 -3
- package/dist/Deployment.d.ts.map +1 -1
- package/dist/Deployment.js +39 -15
- package/dist/Deployment.js.map +1 -1
- package/dist/EnvironmentVariables.d.ts +76 -21
- package/dist/EnvironmentVariables.d.ts.map +1 -1
- package/dist/EnvironmentVariables.js +203 -19
- package/dist/EnvironmentVariables.js.map +1 -1
- package/dist/LogStream.d.ts +134 -0
- package/dist/LogStream.d.ts.map +1 -0
- package/dist/LogStream.js +324 -0
- package/dist/LogStream.js.map +1 -0
- package/dist/Project.js +2 -2
- package/dist/Providers.d.ts.map +1 -1
- package/dist/Providers.js +30 -15
- package/dist/Providers.js.map +1 -1
- package/dist/UsageLimit.d.ts +140 -0
- package/dist/UsageLimit.d.ts.map +1 -0
- package/dist/UsageLimit.js +145 -0
- package/dist/UsageLimit.js.map +1 -0
- 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.d.ts +4 -0
- package/dist/internal/CommandRunner.d.ts.map +1 -1
- package/dist/internal/CommandRunner.js +92 -6
- package/dist/internal/CommandRunner.js.map +1 -1
- 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/Lifecycle.d.ts +1 -0
- package/dist/internal/Lifecycle.d.ts.map +1 -1
- package/dist/internal/Lifecycle.js +24 -2
- package/dist/internal/Lifecycle.js.map +1 -1
- package/dist/internal/LocalBackend.d.ts +9 -0
- package/dist/internal/LocalBackend.d.ts.map +1 -1
- package/dist/internal/LocalBackend.js +14 -5
- package/dist/internal/LocalBackend.js.map +1 -1
- package/dist/internal/LogStream.d.ts +115 -0
- package/dist/internal/LogStream.d.ts.map +1 -0
- package/dist/internal/LogStream.js +123 -0
- package/dist/internal/LogStream.js.map +1 -0
- package/dist/internal/MountInit.d.ts +4 -5
- package/dist/internal/MountInit.d.ts.map +1 -1
- package/dist/internal/MountInit.js +17 -36
- package/dist/internal/MountInit.js.map +1 -1
- package/dist/internal/PushLock.d.ts +1 -0
- package/dist/internal/PushLock.d.ts.map +1 -1
- package/dist/internal/PushLock.js +4 -3
- package/dist/internal/PushLock.js.map +1 -1
- package/dist/internal/ResourceIdentity.js +1 -1
- package/dist/internal/Zip.js +1 -1
- package/package.json +4 -4
- package/src/Backend.ts +422 -12
- package/src/Code.ts +13 -0
- package/src/Confect.ts +7 -1
- package/src/Convex.ts +24 -1
- package/src/ConvexClient.ts +364 -31
- package/src/CustomDomain.ts +453 -0
- package/src/Deployment.ts +74 -12
- package/src/EnvironmentVariables.ts +505 -19
- package/src/LogStream.ts +662 -0
- package/src/Providers.ts +18 -0
- package/src/UsageLimit.ts +253 -0
- package/src/internal/CodeDeployment.ts +115 -0
- package/src/internal/CommandRunner.ts +182 -1
- package/src/internal/FunctionsDirectory.ts +27 -0
- package/src/internal/Lifecycle.ts +21 -1
- package/src/internal/LocalBackend.ts +9 -0
- package/src/internal/LogStream.ts +154 -0
- package/src/internal/MountInit.ts +24 -65
- package/src/internal/PushLock.ts +4 -1
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,5 +18,28 @@ 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";
|
|
29
|
+
export {
|
|
30
|
+
LogStream,
|
|
31
|
+
type LogStreamProps,
|
|
32
|
+
type LogStreamAttributes,
|
|
33
|
+
} from "./LogStream.js";
|
|
34
|
+
|
|
35
|
+
export {
|
|
36
|
+
CustomDomain,
|
|
37
|
+
type CustomDomainProps,
|
|
38
|
+
type CustomDomainAttributes,
|
|
39
|
+
} from "./CustomDomain.js";
|
|
40
|
+
|
|
41
|
+
export {
|
|
42
|
+
UsageLimit,
|
|
43
|
+
type UsageLimitProps,
|
|
44
|
+
type UsageLimitAttributes,
|
|
45
|
+
} from "./UsageLimit.js";
|