@gaganref/confect-alchemy 10.6.0-fork.22 → 10.6.0-fork.24
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/Convex.d.ts +1 -0
- package/dist/Convex.d.ts.map +1 -1
- package/dist/Convex.js +3 -1
- package/dist/Convex.js.map +1 -1
- package/dist/ConvexClient.d.ts +39 -0
- package/dist/ConvexClient.d.ts.map +1 -1
- package/dist/ConvexClient.js +46 -4
- package/dist/ConvexClient.js.map +1 -1
- package/dist/EnvironmentVariables.d.ts +76 -21
- package/dist/EnvironmentVariables.d.ts.map +1 -1
- package/dist/EnvironmentVariables.js +188 -12
- package/dist/EnvironmentVariables.js.map +1 -1
- package/dist/Providers.d.ts.map +1 -1
- package/dist/Providers.js +9 -4
- 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/Lifecycle.js +1 -1
- package/dist/internal/Lifecycle.js.map +1 -1
- package/dist/internal/LocalBackend.d.ts +2 -0
- package/dist/internal/LocalBackend.d.ts.map +1 -1
- package/dist/internal/LocalBackend.js +2 -0
- package/dist/internal/LocalBackend.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 +3 -2
- package/dist/internal/PushLock.js.map +1 -1
- package/package.json +3 -3
- package/src/Convex.ts +6 -0
- package/src/ConvexClient.ts +121 -3
- package/src/EnvironmentVariables.ts +481 -16
- package/src/Providers.ts +6 -0
- package/src/UsageLimit.ts +253 -0
- package/src/internal/Lifecycle.ts +1 -1
- package/src/internal/LocalBackend.ts +2 -0
- package/src/internal/PushLock.ts +4 -1
|
@@ -1,26 +1,175 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PushLock, PushLockError } from "./internal/PushLock.js";
|
|
2
|
+
import { ConvexApiError, ConvexClient, layer as layer$1 } from "./ConvexClient.js";
|
|
2
3
|
import { checkpointCreate, shouldAdopt } from "./internal/Lifecycle.js";
|
|
4
|
+
import * as Output from "alchemy/Output";
|
|
3
5
|
import * as Effect from "effect/Effect";
|
|
4
6
|
import * as Provider from "alchemy/Provider";
|
|
5
7
|
import { Resource } from "alchemy/Resource";
|
|
6
8
|
import * as Layer from "effect/Layer";
|
|
7
9
|
import * as FetchHttpClient from "effect/http/FetchHttpClient";
|
|
10
|
+
import * as Config from "effect/Config";
|
|
8
11
|
import * as Redacted from "effect/Redacted";
|
|
9
12
|
import * as Schema from "effect/Schema";
|
|
13
|
+
import * as Option from "effect/Option";
|
|
10
14
|
import * as Arr from "effect/Array";
|
|
11
15
|
import * as Rec from "effect/Record";
|
|
16
|
+
import * as Result from "effect/Result";
|
|
17
|
+
import * as Duration from "effect/Duration";
|
|
18
|
+
import * as Predicate from "effect/Predicate";
|
|
19
|
+
import * as Schedule from "effect/Schedule";
|
|
12
20
|
import { OwnedBySomeoneElse, Unowned } from "alchemy/AdoptPolicy";
|
|
13
21
|
import { isResolved } from "alchemy/Diff";
|
|
22
|
+
import * as Effectable from "effect/Effectable";
|
|
14
23
|
// src/EnvironmentVariables.ts
|
|
15
|
-
const
|
|
24
|
+
const environmentVariables = Resource("Convex.EnvironmentVariables");
|
|
25
|
+
const EnvironmentVariables = Object.assign(new Proxy(environmentVariables, { apply: (target, _this, args) => {
|
|
26
|
+
if (args.length === 1) return Object.assign(EnvironmentVariables, args[0]);
|
|
27
|
+
const [id, props] = args;
|
|
28
|
+
return target(id, (Effect.isEffect(props) ? props : Effect.succeed(props)).pipe(Effect.flatMap((options) => Effect.fromResult(validateSafety(options)).pipe(Effect.orDie, Effect.as({
|
|
29
|
+
...options,
|
|
30
|
+
...options.retry === void 0 ? {} : { retry: checkedRetry(options.retry) },
|
|
31
|
+
...options.lock === void 0 ? {} : { lock: checkedLock(options.lock) }
|
|
32
|
+
})))));
|
|
33
|
+
} }), Effectable.Prototype({
|
|
34
|
+
label: "Resource<Convex.EnvironmentVariables>",
|
|
35
|
+
evaluate: () => Effect.succeed(EnvironmentVariables)
|
|
36
|
+
}));
|
|
16
37
|
var EnvironmentTargetChange = class extends Schema.TaggedError()("EnvironmentTargetChange", { url: Schema.String }) {};
|
|
38
|
+
var EnvironmentVariableDrift = class extends Schema.TaggedError()("EnvironmentVariableDrift", { variableName: Schema.String }) {
|
|
39
|
+
get message() {
|
|
40
|
+
return `Environment variable ${this.variableName} differs from its last managed value`;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
var EnvironmentVariableUnowned = class extends Schema.TaggedError()("EnvironmentVariableUnowned", { variableName: Schema.String }) {
|
|
44
|
+
get message() {
|
|
45
|
+
return `Environment variable ${this.variableName} is neither owned nor desired`;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
var EnvironmentVariablesInvalidOption = class extends Schema.TaggedError()("EnvironmentVariablesInvalidOption", { option: Schema.Literals([
|
|
49
|
+
"maxAttempts",
|
|
50
|
+
"delay",
|
|
51
|
+
"deploymentName"
|
|
52
|
+
]) }) {
|
|
53
|
+
get message() {
|
|
54
|
+
switch (this.option) {
|
|
55
|
+
case "maxAttempts": return "Environment retry maxAttempts must be an integer from 1 to 10";
|
|
56
|
+
case "delay": return "Environment retry delay must be from 1 to 10000 milliseconds";
|
|
57
|
+
case "deploymentName": return "Environment lock deploymentName must contain lowercase letters or digits separated by single hyphens";
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
const validateMaxAttempts = (maxAttempts) => Number.isInteger(maxAttempts) && maxAttempts >= 1 && maxAttempts <= 10 ? Result.succeed(void 0) : Result.fail(EnvironmentVariablesInvalidOption.make({ option: "maxAttempts" }));
|
|
62
|
+
const validateDelay = (delay) => {
|
|
63
|
+
const parsed = Duration.fromInput(delay);
|
|
64
|
+
return Option.isSome(parsed) && Duration.toMillis(parsed.value) >= 1 && Duration.toMillis(parsed.value) <= 1e4 ? Result.succeed(parsed.value) : Result.fail(EnvironmentVariablesInvalidOption.make({ option: "delay" }));
|
|
65
|
+
};
|
|
66
|
+
const validateDeploymentName = (deploymentName) => /^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(deploymentName) ? Result.succeed(void 0) : Result.fail(EnvironmentVariablesInvalidOption.make({ option: "deploymentName" }));
|
|
67
|
+
const validateSafety = (options) => Result.gen(function* () {
|
|
68
|
+
let duration;
|
|
69
|
+
if ("retry" in options && options.retry !== void 0 && "maxAttempts" in options.retry && "delay" in options.retry) {
|
|
70
|
+
if (isResolved(options.retry.maxAttempts)) yield* validateMaxAttempts(options.retry.maxAttempts);
|
|
71
|
+
if (isResolved(options.retry.delay)) duration = yield* validateDelay(options.retry.delay);
|
|
72
|
+
}
|
|
73
|
+
if ("lock" in options && options.lock !== void 0 && "deploymentName" in options.lock && isResolved(options.lock.deploymentName)) yield* validateDeploymentName(options.lock.deploymentName);
|
|
74
|
+
return duration;
|
|
75
|
+
});
|
|
76
|
+
const checkedInput = (input, validate) => {
|
|
77
|
+
const check = (value) => Effect.fromResult(validate(value)).pipe(Effect.orDie, Effect.as(value));
|
|
78
|
+
if (Config.isConfig(input)) return input.pipe(Config.mapEffect(check));
|
|
79
|
+
return input;
|
|
80
|
+
};
|
|
81
|
+
const checkedRetry = (input) => {
|
|
82
|
+
if ("maxAttempts" in input && "delay" in input) return {
|
|
83
|
+
...input,
|
|
84
|
+
maxAttempts: checkedInput(input.maxAttempts, validateMaxAttempts),
|
|
85
|
+
delay: checkedInput(input.delay, validateDelay)
|
|
86
|
+
};
|
|
87
|
+
return checkedInput(input, (retry) => validateSafety({ retry }));
|
|
88
|
+
};
|
|
89
|
+
const checkedLock = (input) => {
|
|
90
|
+
if ("deploymentName" in input) return {
|
|
91
|
+
...input,
|
|
92
|
+
deploymentName: checkedInput(input.deploymentName, validateDeploymentName)
|
|
93
|
+
};
|
|
94
|
+
return checkedInput(input, (lock) => validateSafety({ lock }));
|
|
95
|
+
};
|
|
96
|
+
const ownershipConflict = (variableName) => new OwnedBySomeoneElse({
|
|
97
|
+
message: "An existing environment variable requires explicit adoption in a separate resource.",
|
|
98
|
+
resourceType: EnvironmentVariables.Type,
|
|
99
|
+
physicalName: variableName
|
|
100
|
+
});
|
|
101
|
+
const optionsForDiff = (olds, news) => {
|
|
102
|
+
if (!("variables" in news)) return {
|
|
103
|
+
...olds,
|
|
104
|
+
desiredNames: void 0,
|
|
105
|
+
desiredVariables: void 0
|
|
106
|
+
};
|
|
107
|
+
return {
|
|
108
|
+
driftPolicy: isResolved(news.driftPolicy) ? news.driftPolicy : olds.driftPolicy,
|
|
109
|
+
adoptMatching: isResolved(news.adoptMatching) ? news.adoptMatching : olds.adoptMatching,
|
|
110
|
+
unownedPolicy: isResolved(news.unownedPolicy) ? news.unownedPolicy : olds.unownedPolicy,
|
|
111
|
+
lock: isResolved(news.lock) ? news.lock : olds.lock,
|
|
112
|
+
retry: isResolved(news.retry) ? news.retry : olds.retry,
|
|
113
|
+
desiredVariables: news.variables,
|
|
114
|
+
desiredNames: !Output.isExpr(news.variables) && !Effect.isEffect(news.variables) && Predicate.isReadonlyObject(news.variables) ? Rec.keys(news.variables) : void 0
|
|
115
|
+
};
|
|
116
|
+
};
|
|
17
117
|
const provider = Effect.gen(function* () {
|
|
18
118
|
const client = yield* ConvexClient;
|
|
119
|
+
const lock = yield* Effect.serviceOption(PushLock);
|
|
120
|
+
const withSafety = Effect.fn("EnvironmentVariables.withSafety")(function* (options, effect) {
|
|
121
|
+
const duration = yield* Effect.fromResult(validateSafety(options));
|
|
122
|
+
let attempt = effect;
|
|
123
|
+
if (options.retry !== void 0 && duration !== void 0) {
|
|
124
|
+
const { maxAttempts } = options.retry;
|
|
125
|
+
attempt = effect.pipe(Effect.retry({
|
|
126
|
+
times: maxAttempts - 1,
|
|
127
|
+
schedule: Schedule.spaced(duration),
|
|
128
|
+
while: (error) => Schema.is(ConvexApiError)(error) && error.serverCode === "OptimisticConcurrencyControlFailure"
|
|
129
|
+
}));
|
|
130
|
+
}
|
|
131
|
+
if (options.lock === void 0) return yield* attempt;
|
|
132
|
+
if (Option.isNone(lock)) return yield* PushLockError.make({
|
|
133
|
+
deploymentName: options.lock.deploymentName,
|
|
134
|
+
reason: "configuration",
|
|
135
|
+
missing: "PushLock"
|
|
136
|
+
});
|
|
137
|
+
return yield* lock.value.withLock(options.lock.deploymentName, attempt);
|
|
138
|
+
});
|
|
19
139
|
const redacted = (value) => typeof value === "string" ? Redacted.make(value) : value;
|
|
20
140
|
const valueAt = (variables, name) => Rec.has(variables, name) ? variables[name] : void 0;
|
|
21
141
|
const select = (variables, names) => Rec.fromEntries(Arr.flatMap(names, (name) => !Rec.has(variables, name) ? [] : [[name, variables[name]]]));
|
|
22
|
-
|
|
23
|
-
|
|
142
|
+
const checkDrift = (policy, output, observed, desired) => {
|
|
143
|
+
if (policy !== "error" || output === void 0) return Effect.void;
|
|
144
|
+
const desiredVariables = Predicate.isReadonlyObject(desired) && !Output.isExpr(desired) && !Effect.isEffect(desired) ? desired : void 0;
|
|
145
|
+
for (const name of output.ownedNames) {
|
|
146
|
+
const previous = valueAt(output.variables, name);
|
|
147
|
+
const current = valueAt(observed, name);
|
|
148
|
+
const wanted = desiredVariables?.[name];
|
|
149
|
+
if (current !== void 0 && (desiredVariables === void 0 || wanted !== void 0 && !isResolved(wanted))) continue;
|
|
150
|
+
if (current !== void 0 && (typeof wanted === "string" || Redacted.isRedacted(wanted)) && Redacted.value(current) === (typeof wanted === "string" ? wanted : Redacted.value(wanted))) continue;
|
|
151
|
+
if (previous === void 0 && current === void 0) continue;
|
|
152
|
+
if (previous === void 0 || current === void 0 || Redacted.value(previous) !== Redacted.value(current)) return Effect.fail(EnvironmentVariableDrift.make({ variableName: name }));
|
|
153
|
+
}
|
|
154
|
+
return Effect.void;
|
|
155
|
+
};
|
|
156
|
+
const checkUnowned = (policy, output, desiredNames, observed) => {
|
|
157
|
+
if (policy !== "error" || desiredNames === void 0) return Effect.void;
|
|
158
|
+
for (const name of Rec.keys(observed)) if (output?.ownedNames.includes(name) !== true && !desiredNames.includes(name)) return Effect.fail(EnvironmentVariableUnowned.make({ variableName: name }));
|
|
159
|
+
return Effect.void;
|
|
160
|
+
};
|
|
161
|
+
const service = {
|
|
162
|
+
diff: Effect.fn("EnvironmentVariables.diff")(function* ({ olds, news, output }) {
|
|
163
|
+
const options = optionsForDiff(olds, news);
|
|
164
|
+
if (output !== void 0 && (options.driftPolicy === "error" || options.unownedPolicy === "error" || options.adoptMatching === true)) {
|
|
165
|
+
const observed = yield* client.listEnvironmentVariables(output.url, output.deployKey);
|
|
166
|
+
yield* checkDrift(options.driftPolicy, output, observed, options.desiredVariables);
|
|
167
|
+
if (options.adoptMatching === true && Predicate.isReadonlyObject(options.desiredVariables) && !Output.isExpr(options.desiredVariables) && !Effect.isEffect(options.desiredVariables)) for (const [name, wanted] of Rec.toEntries(options.desiredVariables)) {
|
|
168
|
+
const current = valueAt(observed, name);
|
|
169
|
+
if (!output.ownedNames.includes(name) && current !== void 0 && (typeof wanted === "string" || Redacted.isRedacted(wanted)) && Redacted.value(current) !== (typeof wanted === "string" ? wanted : Redacted.value(wanted))) return yield* ownershipConflict(name);
|
|
170
|
+
}
|
|
171
|
+
yield* checkUnowned(options.unownedPolicy, output, options.desiredNames, observed);
|
|
172
|
+
}
|
|
24
173
|
if (!isResolved(news) || output === void 0) return;
|
|
25
174
|
if (news.url !== output.url) return yield* EnvironmentTargetChange.make({ url: output.url });
|
|
26
175
|
const names = Rec.keys(news.variables);
|
|
@@ -35,6 +184,8 @@ const provider = Effect.gen(function* () {
|
|
|
35
184
|
const url = output?.url ?? olds.url;
|
|
36
185
|
if (url === void 0 || olds.deployKey === void 0) return;
|
|
37
186
|
const observed = yield* client.listEnvironmentVariables(url, olds.deployKey);
|
|
187
|
+
yield* checkDrift(olds.driftPolicy, output, observed, olds.variables);
|
|
188
|
+
yield* checkUnowned(olds.unownedPolicy, output, Rec.keys(olds.variables), observed);
|
|
38
189
|
const ownedNames = output?.ownedNames ?? Rec.keys(olds.variables);
|
|
39
190
|
const variables = select(observed, ownedNames);
|
|
40
191
|
if (output !== void 0) return {
|
|
@@ -43,6 +194,10 @@ const provider = Effect.gen(function* () {
|
|
|
43
194
|
variables
|
|
44
195
|
};
|
|
45
196
|
if (Rec.keys(variables).length === 0) return void 0;
|
|
197
|
+
if (olds.adoptMatching === true) {
|
|
198
|
+
for (const [name, value] of Rec.toEntries(variables)) if (Redacted.value(value) !== Redacted.value(redacted(olds.variables[name]))) return yield* ownershipConflict(name);
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
46
201
|
return Unowned({
|
|
47
202
|
url,
|
|
48
203
|
deployKey: olds.deployKey,
|
|
@@ -55,8 +210,10 @@ const provider = Effect.gen(function* () {
|
|
|
55
210
|
if (output === void 0) yield* checkpointCreate(fqn, instanceId, news);
|
|
56
211
|
if (output !== void 0 && output.url !== news.url) return yield* EnvironmentTargetChange.make({ url: output.url });
|
|
57
212
|
const observed = yield* client.listEnvironmentVariables(news.url, news.deployKey);
|
|
213
|
+
yield* checkDrift(news.driftPolicy, output, observed, news.variables);
|
|
214
|
+
yield* checkUnowned(news.unownedPolicy, output, Rec.keys(news.variables), observed);
|
|
58
215
|
const ownedNames = Rec.keys(news.variables);
|
|
59
|
-
if (output === void 0 && (yield* shouldAdopt(fqn))) {
|
|
216
|
+
if (output === void 0 && news.adoptMatching !== true && (yield* shouldAdopt(fqn))) {
|
|
60
217
|
const variables = select(observed, ownedNames);
|
|
61
218
|
output = {
|
|
62
219
|
url: news.url,
|
|
@@ -68,10 +225,21 @@ const provider = Effect.gen(function* () {
|
|
|
68
225
|
yield* checkpointCreate(fqn, instanceId, news, output);
|
|
69
226
|
}
|
|
70
227
|
const previousNames = output?.ownedNames ?? [];
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
228
|
+
let originals = output?.originals ?? {};
|
|
229
|
+
for (const name of ownedNames) {
|
|
230
|
+
const current = valueAt(observed, name);
|
|
231
|
+
if (previousNames.includes(name) || current === void 0) continue;
|
|
232
|
+
if (news.adoptMatching === true && Redacted.value(current) === Redacted.value(redacted(news.variables[name]))) {
|
|
233
|
+
originals = Rec.set(originals, name, current);
|
|
234
|
+
yield* Effect.logInfo(`Adopted environment variable ${name}`);
|
|
235
|
+
} else return yield* ownershipConflict(name);
|
|
236
|
+
}
|
|
237
|
+
if (output === void 0 && news.adoptMatching === true) yield* checkpointCreate(fqn, instanceId, news, {
|
|
238
|
+
url: news.url,
|
|
239
|
+
deployKey: news.deployKey,
|
|
240
|
+
ownedNames,
|
|
241
|
+
variables: select(observed, ownedNames),
|
|
242
|
+
originals
|
|
75
243
|
});
|
|
76
244
|
const desired = Rec.fromEntries(Arr.map(Rec.toEntries(news.variables), ([name, value]) => [name, redacted(value)]));
|
|
77
245
|
const changes = [];
|
|
@@ -99,12 +267,14 @@ const provider = Effect.gen(function* () {
|
|
|
99
267
|
deployKey: news.deployKey,
|
|
100
268
|
ownedNames,
|
|
101
269
|
variables: desired,
|
|
102
|
-
originals: select(
|
|
270
|
+
originals: select(originals, ownedNames)
|
|
103
271
|
};
|
|
104
272
|
}),
|
|
105
|
-
delete: Effect.fn("EnvironmentVariables.delete")(function* ({ output }) {
|
|
273
|
+
delete: Effect.fn("EnvironmentVariables.delete")(function* ({ olds, output }) {
|
|
106
274
|
const observed = yield* client.listEnvironmentVariables(output.url, output.deployKey).pipe(Effect.catchTag("ConvexNotFound", () => Effect.void));
|
|
107
275
|
if (observed === void 0) return;
|
|
276
|
+
yield* checkDrift(olds.driftPolicy, output, observed, {});
|
|
277
|
+
yield* checkUnowned(olds.unownedPolicy, output, Rec.keys(olds.variables), observed);
|
|
108
278
|
const changes = [];
|
|
109
279
|
for (const name of output.ownedNames) {
|
|
110
280
|
const original = valueAt(output.originals, name);
|
|
@@ -119,6 +289,12 @@ const provider = Effect.gen(function* () {
|
|
|
119
289
|
if (changes.length > 0) yield* client.updateEnvironmentVariables(output.url, output.deployKey, changes).pipe(Effect.catchTag("ConvexNotFound", () => Effect.void));
|
|
120
290
|
})
|
|
121
291
|
};
|
|
292
|
+
return {
|
|
293
|
+
diff: (input) => withSafety(optionsForDiff(input.olds, input.news), service.diff(input)),
|
|
294
|
+
read: (input) => withSafety(input.olds, service.read(input)),
|
|
295
|
+
reconcile: (input) => withSafety(input.news, service.reconcile(input)),
|
|
296
|
+
delete: (input) => withSafety(input.olds, service.delete(input))
|
|
297
|
+
};
|
|
122
298
|
});
|
|
123
299
|
/**
|
|
124
300
|
* Under `alchemy dev` variables are managed on the local backend. A backend
|
|
@@ -131,6 +307,6 @@ const localProvider = Effect.map(provider, (service) => ({
|
|
|
131
307
|
}));
|
|
132
308
|
const layer = Provider.effect(EnvironmentVariables, provider);
|
|
133
309
|
const localLayer = Provider.effect(EnvironmentVariables, localProvider).pipe(Layer.provide(layer$1({ mode: "local" }).pipe(Layer.provide(FetchHttpClient.layer))));
|
|
134
|
-
export { EnvironmentTargetChange, EnvironmentVariables, layer, localLayer, localProvider, provider };
|
|
310
|
+
export { EnvironmentTargetChange, EnvironmentVariableDrift, EnvironmentVariableUnowned, EnvironmentVariables, EnvironmentVariablesInvalidOption, layer, localLayer, localProvider, provider };
|
|
135
311
|
|
|
136
312
|
//# sourceMappingURL=EnvironmentVariables.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EnvironmentVariables.js","names":["ConvexClient.ConvexClient","ConvexClient.layer"],"sources":["../src/EnvironmentVariables.ts"],"sourcesContent":["import { OwnedBySomeoneElse, Unowned } from \"alchemy/AdoptPolicy\";\nimport { isResolved } from \"alchemy/Diff\";\nimport * as Provider from \"alchemy/Provider\";\nimport { Resource } from \"alchemy/Resource\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\nimport * as FetchHttpClient from \"effect/http/FetchHttpClient\";\nimport * as Redacted from \"effect/Redacted\";\nimport * as Schema from \"effect/Schema\";\n\nimport * as ConvexClient from \"./ConvexClient.js\";\nimport type { Providers } from \"./Providers.js\";\nimport { checkpointCreate, shouldAdopt } from \"./internal/Lifecycle.js\";\nimport * as Arr from \"effect/Array\";\nimport * as Rec from \"effect/Record\";\n\nexport interface EnvironmentVariablesProps {\n readonly url: string;\n readonly deployKey: Redacted.Redacted<string>;\n readonly variables: Readonly<\n Record<string, string | Redacted.Redacted<string>>\n >;\n}\n\nexport interface EnvironmentVariablesAttributes {\n readonly url: string;\n readonly deployKey: Redacted.Redacted<string>;\n readonly ownedNames: ReadonlyArray<string>;\n readonly variables: Readonly<Record<string, Redacted.Redacted<string>>>;\n readonly originals: Readonly<Record<string, Redacted.Redacted<string>>>;\n}\n\nexport type EnvironmentVariables = Resource<\n \"Convex.EnvironmentVariables\",\n EnvironmentVariablesProps,\n EnvironmentVariablesAttributes,\n never,\n Providers\n>;\nexport const EnvironmentVariables = Resource<EnvironmentVariables>(\n \"Convex.EnvironmentVariables\",\n);\n\nexport class EnvironmentTargetChange extends Schema.TaggedError<\n EnvironmentTargetChange,\n { readonly brand: unique symbol }\n>()(\"EnvironmentTargetChange\", { url: Schema.String }) {}\n\nexport const provider = Effect.gen(function* () {\n const client = yield* ConvexClient.ConvexClient;\n const redacted = (value: string | Redacted.Redacted<string>) =>\n typeof value === \"string\" ? Redacted.make(value) : value;\n const valueAt = (\n variables: Readonly<Record<string, Redacted.Redacted<string>>>,\n name: string,\n ) => (Rec.has(variables, name) ? variables[name] : undefined);\n const select = (\n variables: Readonly<Record<string, Redacted.Redacted<string>>>,\n names: ReadonlyArray<string>,\n ) =>\n Rec.fromEntries(\n Arr.flatMap(names, (name) =>\n !Rec.has(variables, name) ? [] : [[name, variables[name]]],\n ),\n );\n return {\n diff: Effect.fn(\"EnvironmentVariables.diff\")(function* ({ news, output }) {\n if (!isResolved(news) || output === undefined) return;\n if (news.url !== output.url)\n return yield* EnvironmentTargetChange.make({\n url: output.url,\n });\n const names = Rec.keys(news.variables);\n if (\n names.length !== output.ownedNames.length ||\n Arr.some(names, (name) => !output.ownedNames.includes(name))\n )\n return { action: \"update\" };\n const variables = yield* client.listEnvironmentVariables(\n news.url,\n news.deployKey,\n );\n for (const [name, value] of Rec.toEntries(news.variables)) {\n const observed = valueAt(variables, name);\n if (\n observed === undefined ||\n Redacted.value(observed) !== Redacted.value(redacted(value))\n )\n return { action: \"update\" };\n }\n }),\n read: Effect.fn(\"EnvironmentVariables.read\")(function* ({ olds, output }) {\n const url = output?.url ?? olds.url;\n if (url === undefined || olds.deployKey === undefined) return;\n const observed = yield* client.listEnvironmentVariables(\n url,\n olds.deployKey,\n );\n const ownedNames = output?.ownedNames ?? Rec.keys(olds.variables);\n const variables = select(observed, ownedNames);\n if (output !== undefined)\n return { ...output, deployKey: olds.deployKey, variables };\n if (Rec.keys(variables).length === 0) return undefined;\n return Unowned({\n url,\n deployKey: olds.deployKey,\n ownedNames,\n variables,\n originals: variables,\n });\n }),\n reconcile: Effect.fn(\"EnvironmentVariables.reconcile\")(function* ({\n fqn,\n instanceId,\n news,\n output,\n }) {\n if (output === undefined) yield* checkpointCreate(fqn, instanceId, news);\n if (output !== undefined && output.url !== news.url)\n return yield* EnvironmentTargetChange.make({\n url: output.url,\n });\n const observed = yield* client.listEnvironmentVariables(\n news.url,\n news.deployKey,\n );\n const ownedNames = Rec.keys(news.variables);\n if (output === undefined && (yield* shouldAdopt(fqn))) {\n const variables = select(observed, ownedNames);\n output = {\n url: news.url,\n deployKey: news.deployKey,\n ownedNames,\n variables,\n originals: variables,\n };\n yield* checkpointCreate(fqn, instanceId, news, output);\n }\n const previousNames = output?.ownedNames ?? [];\n for (const name of ownedNames) {\n if (\n !previousNames.includes(name) &&\n valueAt(observed, name) !== undefined\n )\n return yield* new OwnedBySomeoneElse({\n message:\n \"An existing environment variable requires explicit adoption in a separate resource.\",\n resourceType: EnvironmentVariables.Type,\n physicalName: name,\n });\n }\n const desired = Rec.fromEntries(\n Arr.map(Rec.toEntries(news.variables), ([name, value]) => [\n name,\n redacted(value),\n ]),\n );\n const changes: Array<{\n name: string;\n value?: Redacted.Redacted<string>;\n }> = [];\n for (const [name, value] of Rec.toEntries(desired)) {\n const current = valueAt(observed, name);\n if (\n current === undefined ||\n Redacted.value(current) !== Redacted.value(value)\n )\n changes.push({ name, value });\n }\n for (const name of previousNames) {\n if (Rec.has(desired, name)) continue;\n const original =\n output !== undefined ? valueAt(output.originals, name) : undefined;\n const current = valueAt(observed, name);\n if (original !== undefined) {\n if (\n current === undefined ||\n Redacted.value(current) !== Redacted.value(original)\n )\n changes.push({ name, value: original });\n } else if (current !== undefined) changes.push({ name });\n }\n if (changes.length > 0)\n yield* client.updateEnvironmentVariables(\n news.url,\n news.deployKey,\n changes,\n );\n return {\n url: news.url,\n deployKey: news.deployKey,\n ownedNames,\n variables: desired,\n originals: select(output?.originals ?? {}, ownedNames),\n };\n }),\n delete: Effect.fn(\"EnvironmentVariables.delete\")(function* ({ output }) {\n const observed = yield* client\n .listEnvironmentVariables(output.url, output.deployKey)\n .pipe(Effect.catchTag(\"ConvexNotFound\", () => Effect.void));\n if (observed === undefined) return;\n const changes: Array<{\n name: string;\n value?: Redacted.Redacted<string>;\n }> = [];\n for (const name of output.ownedNames) {\n const original = valueAt(output.originals, name);\n const current = valueAt(observed, name);\n if (original !== undefined) {\n if (\n current === undefined ||\n Redacted.value(current) !== Redacted.value(original)\n )\n changes.push({ name, value: original });\n } else if (current !== undefined) changes.push({ name });\n }\n if (changes.length > 0)\n yield* client\n .updateEnvironmentVariables(output.url, output.deployKey, changes)\n .pipe(Effect.catchTag(\"ConvexNotFound\", () => Effect.void));\n }),\n } satisfies Provider.ProviderServiceInput<EnvironmentVariables>;\n});\n\n/**\n * Under `alchemy dev` variables are managed on the local backend. A backend\n * that is not running keeps its variables in its retained data, so removing\n * them is skipped rather than failing the apply.\n */\nexport const localProvider = Effect.map(\n provider,\n (service) =>\n ({\n ...service,\n delete: (input) =>\n service.delete(input).pipe(\n Effect.catchIf(\n (error) =>\n error._tag === \"ConvexApiError\" &&\n error.code === \"TransportError\",\n () => Effect.void,\n ),\n ),\n }) satisfies Provider.ProviderServiceInput<EnvironmentVariables>,\n);\n\nexport const layer = Provider.effect(EnvironmentVariables, provider);\nexport const localLayer = Provider.effect(\n EnvironmentVariables,\n localProvider,\n).pipe(\n Layer.provide(\n ConvexClient.layer({ mode: \"local\" }).pipe(\n Layer.provide(FetchHttpClient.layer),\n ),\n ),\n);\n"],"mappings":";;;;;;;;;;;;;;AAuCA,MAAa,uBAAuB,SAClC,6BACF;AAEA,IAAa,0BAAb,cAA6C,OAAO,YAGlD,CAAC,CAAC,2BAA2B,EAAE,KAAK,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC;AAExD,MAAa,WAAW,OAAO,IAAI,aAAa;CAC9C,MAAM,SAAS,OAAOA;CACtB,MAAM,YAAY,UAChB,OAAO,UAAU,WAAW,SAAS,KAAK,KAAK,IAAI;CACrD,MAAM,WACJ,WACA,SACI,IAAI,IAAI,WAAW,IAAI,IAAI,UAAU,QAAQ,KAAA;CACnD,MAAM,UACJ,WACA,UAEA,IAAI,YACF,IAAI,QAAQ,QAAQ,SAClB,CAAC,IAAI,IAAI,WAAW,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,UAAU,KAAK,CAAC,CAC3D,CACF;CACF,OAAO;EACL,MAAM,OAAO,GAAG,2BAA2B,CAAC,CAAC,WAAW,EAAE,MAAM,UAAU;GACxE,IAAI,CAAC,WAAW,IAAI,KAAK,WAAW,KAAA,GAAW;GAC/C,IAAI,KAAK,QAAQ,OAAO,KACtB,OAAO,OAAO,wBAAwB,KAAK,EACzC,KAAK,OAAO,IACd,CAAC;GACH,MAAM,QAAQ,IAAI,KAAK,KAAK,SAAS;GACrC,IACE,MAAM,WAAW,OAAO,WAAW,UACnC,IAAI,KAAK,QAAQ,SAAS,CAAC,OAAO,WAAW,SAAS,IAAI,CAAC,GAE3D,OAAO,EAAE,QAAQ,SAAS;GAC5B,MAAM,YAAY,OAAO,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gB,KAAK,CACrC,CACF,CACF"}
|
|
1
|
+
{"version":3,"file":"EnvironmentVariables.js","names":["ConvexClient.ConvexClient","ConvexClient.ConvexApiError","ConvexClient.layer"],"sources":["../src/EnvironmentVariables.ts"],"sourcesContent":["import { OwnedBySomeoneElse, Unowned } from \"alchemy/AdoptPolicy\";\nimport { isResolved } from \"alchemy/Diff\";\nimport type { Input, InputProps } from \"alchemy/Input\";\nimport * as Output from \"alchemy/Output\";\nimport * as Provider from \"alchemy/Provider\";\nimport {\n Resource,\n type ResourceClass,\n type ResourceConstructor,\n} from \"alchemy/Resource\";\nimport * as Effectable from \"effect/Effectable\";\nimport * as Config from \"effect/Config\";\nimport * as Result from \"effect/Result\";\nimport * as Duration from \"effect/Duration\";\nimport * as Option from \"effect/Option\";\nimport * as Predicate from \"effect/Predicate\";\nimport * as Schedule from \"effect/Schedule\";\nimport { PushLock, PushLockError } from \"./internal/PushLock.js\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\nimport * as FetchHttpClient from \"effect/http/FetchHttpClient\";\nimport * as Redacted from \"effect/Redacted\";\nimport * as Schema from \"effect/Schema\";\n\nimport * as ConvexClient from \"./ConvexClient.js\";\nimport type { Providers } from \"./Providers.js\";\nimport { checkpointCreate, shouldAdopt } from \"./internal/Lifecycle.js\";\nimport * as Arr from \"effect/Array\";\nimport * as Rec from \"effect/Record\";\n\nexport interface EnvironmentVariablesProps {\n /**\n * Refuse live owned values that differ from both the last write and the\n * desired value. Defaults to `overwrite`.\n */\n readonly driftPolicy?: \"overwrite\" | \"error\";\n /**\n * Adopt unowned desired names only when their live values match. Defaults to\n * false.\n */\n readonly adoptMatching?: boolean;\n /**\n * Refuse live names that are neither owned nor desired. Defaults to `ignore`.\n */\n readonly unownedPolicy?: \"ignore\" | \"error\";\n /**\n * Share the deployment push lock for checks and writes. Absent by default.\n */\n readonly lock?: { readonly deploymentName: string };\n /**\n * Retry write conflicts only, with 1 to 10 attempts and a delay of 1 to 10000\n * ms. Absent means one attempt.\n */\n readonly retry?: {\n readonly maxAttempts: number;\n readonly delay: Duration.Input;\n };\n readonly url: string;\n readonly deployKey: Redacted.Redacted<string>;\n readonly variables: Readonly<\n Record<string, string | Redacted.Redacted<string>>\n >;\n}\n\nexport interface EnvironmentVariablesAttributes {\n readonly url: string;\n readonly deployKey: Redacted.Redacted<string>;\n readonly ownedNames: ReadonlyArray<string>;\n readonly variables: Readonly<Record<string, Redacted.Redacted<string>>>;\n readonly originals: Readonly<Record<string, Redacted.Redacted<string>>>;\n}\n\nexport type EnvironmentVariables = Resource<\n \"Convex.EnvironmentVariables\",\n EnvironmentVariablesProps,\n EnvironmentVariablesAttributes,\n never,\n Providers\n>;\nconst environmentVariables = Resource<EnvironmentVariables>(\n \"Convex.EnvironmentVariables\",\n);\n\n// Alchemy skips provider reads for fresh resources with unresolved inputs.\nexport const EnvironmentVariables: ResourceClass<EnvironmentVariables> =\n Object.assign(\n new Proxy(environmentVariables, {\n apply: <PropsReq>(\n target: ResourceClass<EnvironmentVariables>,\n _this: unknown,\n args:\n | [methods: object]\n | [\n id: string,\n props:\n | InputProps<EnvironmentVariablesProps>\n | Effect.Effect<\n InputProps<EnvironmentVariablesProps>,\n never,\n PropsReq\n >,\n ],\n ) => {\n if (args.length === 1)\n return Object.assign(EnvironmentVariables, args[0]);\n const [id, props] = args;\n return target(\n id,\n (Effect.isEffect(props) ? props : Effect.succeed(props)).pipe(\n Effect.flatMap((options) =>\n Effect.fromResult(validateSafety(options)).pipe(\n Effect.orDie,\n Effect.as({\n ...options,\n ...(options.retry === undefined\n ? {}\n : { retry: checkedRetry(options.retry) }),\n ...(options.lock === undefined\n ? {}\n : { lock: checkedLock(options.lock) }),\n }),\n ),\n ),\n ),\n );\n },\n }),\n Effectable.Prototype<\n Effect.Effect<ResourceConstructor<EnvironmentVariables>>\n >({\n label: \"Resource<Convex.EnvironmentVariables>\",\n evaluate: () => Effect.succeed(EnvironmentVariables),\n }),\n );\n\nexport class EnvironmentTargetChange extends Schema.TaggedError<\n EnvironmentTargetChange,\n { readonly brand: unique symbol }\n>()(\"EnvironmentTargetChange\", { url: Schema.String }) {}\n\nexport class EnvironmentVariableDrift extends Schema.TaggedError<\n EnvironmentVariableDrift,\n { readonly brand: unique symbol }\n>()(\"EnvironmentVariableDrift\", { variableName: Schema.String }) {\n override get message() {\n return `Environment variable ${this.variableName} differs from its last managed value`;\n }\n}\n\nexport class EnvironmentVariableUnowned extends Schema.TaggedError<\n EnvironmentVariableUnowned,\n { readonly brand: unique symbol }\n>()(\"EnvironmentVariableUnowned\", { variableName: Schema.String }) {\n override get message() {\n return `Environment variable ${this.variableName} is neither owned nor desired`;\n }\n}\n\nexport class EnvironmentVariablesInvalidOption extends Schema.TaggedError<\n EnvironmentVariablesInvalidOption,\n { readonly brand: unique symbol }\n>()(\"EnvironmentVariablesInvalidOption\", {\n option: Schema.Literals([\"maxAttempts\", \"delay\", \"deploymentName\"]),\n}) {\n override get message() {\n switch (this.option) {\n case \"maxAttempts\":\n return \"Environment retry maxAttempts must be an integer from 1 to 10\";\n case \"delay\":\n return \"Environment retry delay must be from 1 to 10000 milliseconds\";\n case \"deploymentName\":\n return \"Environment lock deploymentName must contain lowercase letters or digits separated by single hyphens\";\n }\n }\n}\n\ntype SafetyOptions = {\n readonly retry?: EnvironmentVariablesProps[\"retry\"];\n readonly lock?: EnvironmentVariablesProps[\"lock\"];\n};\n\nconst validateMaxAttempts = (\n maxAttempts: number,\n): Result.Result<void, EnvironmentVariablesInvalidOption> =>\n Number.isInteger(maxAttempts) && maxAttempts >= 1 && maxAttempts <= 10\n ? Result.succeed(undefined)\n : Result.fail(\n EnvironmentVariablesInvalidOption.make({ option: \"maxAttempts\" }),\n );\n\nconst validateDelay = (\n delay: Duration.Input,\n): Result.Result<Duration.Duration, EnvironmentVariablesInvalidOption> => {\n const parsed = Duration.fromInput(delay);\n return Option.isSome(parsed) &&\n Duration.toMillis(parsed.value) >= 1 &&\n Duration.toMillis(parsed.value) <= 10000\n ? Result.succeed(parsed.value)\n : Result.fail(EnvironmentVariablesInvalidOption.make({ option: \"delay\" }));\n};\n\nconst validateDeploymentName = (\n deploymentName: string,\n): Result.Result<void, EnvironmentVariablesInvalidOption> =>\n /^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(deploymentName)\n ? Result.succeed(undefined)\n : Result.fail(\n EnvironmentVariablesInvalidOption.make({ option: \"deploymentName\" }),\n );\n\nconst validateSafety = (\n options: Input<SafetyOptions>,\n): Result.Result<\n Duration.Duration | undefined,\n EnvironmentVariablesInvalidOption\n> =>\n Result.gen(function* () {\n let duration: Duration.Duration | undefined;\n if (\n \"retry\" in options &&\n options.retry !== undefined &&\n \"maxAttempts\" in options.retry &&\n \"delay\" in options.retry\n ) {\n if (isResolved(options.retry.maxAttempts))\n yield* validateMaxAttempts(options.retry.maxAttempts);\n if (isResolved(options.retry.delay))\n duration = yield* validateDelay(options.retry.delay);\n }\n if (\n \"lock\" in options &&\n options.lock !== undefined &&\n \"deploymentName\" in options.lock &&\n isResolved(options.lock.deploymentName)\n )\n yield* validateDeploymentName(options.lock.deploymentName);\n return duration;\n });\n\nconst checkedInput = <A>(\n input: Exclude<Input<A>, undefined>,\n validate: (\n value: A,\n ) => Result.Result<unknown, EnvironmentVariablesInvalidOption>,\n): Exclude<Input<A>, undefined> => {\n const check = (value: A) =>\n Effect.fromResult(validate(value)).pipe(Effect.orDie, Effect.as(value));\n if (Config.isConfig(input)) return input.pipe(Config.mapEffect(check));\n return input;\n};\n\nconst checkedRetry = (\n input: Exclude<Input<SafetyOptions[\"retry\"]>, undefined>,\n): Exclude<Input<SafetyOptions[\"retry\"]>, undefined> => {\n if (\"maxAttempts\" in input && \"delay\" in input)\n return {\n ...input,\n maxAttempts: checkedInput(input.maxAttempts, validateMaxAttempts),\n delay: checkedInput(input.delay, validateDelay),\n };\n return checkedInput(input, (retry) => validateSafety({ retry }));\n};\n\nconst checkedLock = (\n input: Exclude<Input<SafetyOptions[\"lock\"]>, undefined>,\n): Exclude<Input<SafetyOptions[\"lock\"]>, undefined> => {\n if (\"deploymentName\" in input)\n return {\n ...input,\n deploymentName: checkedInput(\n input.deploymentName,\n validateDeploymentName,\n ),\n };\n return checkedInput(input, (lock) => validateSafety({ lock }));\n};\n\nconst ownershipConflict = (variableName: string) =>\n new OwnedBySomeoneElse({\n message:\n \"An existing environment variable requires explicit adoption in a separate resource.\",\n resourceType: EnvironmentVariables.Type,\n physicalName: variableName,\n });\n\nconst optionsForDiff = (\n olds: EnvironmentVariablesProps,\n news: Input<EnvironmentVariablesProps>,\n) => {\n if (!(\"variables\" in news))\n return { ...olds, desiredNames: undefined, desiredVariables: undefined };\n return {\n driftPolicy: isResolved(news.driftPolicy)\n ? news.driftPolicy\n : olds.driftPolicy,\n adoptMatching: isResolved(news.adoptMatching)\n ? news.adoptMatching\n : olds.adoptMatching,\n unownedPolicy: isResolved(news.unownedPolicy)\n ? news.unownedPolicy\n : olds.unownedPolicy,\n lock: isResolved(news.lock) ? news.lock : olds.lock,\n retry: isResolved(news.retry) ? news.retry : olds.retry,\n desiredVariables: news.variables,\n desiredNames:\n !Output.isExpr(news.variables) &&\n !Effect.isEffect(news.variables) &&\n Predicate.isReadonlyObject(news.variables)\n ? Rec.keys<string, unknown>(news.variables)\n : undefined,\n };\n};\n\nexport const provider = Effect.gen(function* () {\n const client = yield* ConvexClient.ConvexClient;\n const lock = yield* Effect.serviceOption(PushLock);\n const withSafety = Effect.fn(\"EnvironmentVariables.withSafety\")(function* <\n A,\n E,\n R,\n >(\n options: {\n readonly lock?: EnvironmentVariablesProps[\"lock\"];\n readonly retry?: EnvironmentVariablesProps[\"retry\"];\n },\n effect: Effect.Effect<A, E, R>,\n ) {\n const duration = yield* Effect.fromResult(validateSafety(options));\n let attempt = effect;\n if (options.retry !== undefined && duration !== undefined) {\n const { maxAttempts } = options.retry;\n attempt = effect.pipe(\n Effect.retry({\n times: maxAttempts - 1,\n schedule: Schedule.spaced(duration),\n while: (error) =>\n Schema.is(ConvexClient.ConvexApiError)(error) &&\n error.serverCode === \"OptimisticConcurrencyControlFailure\",\n }),\n );\n }\n if (options.lock === undefined) return yield* attempt;\n if (Option.isNone(lock))\n return yield* PushLockError.make({\n deploymentName: options.lock.deploymentName,\n reason: \"configuration\",\n missing: \"PushLock\",\n });\n return yield* lock.value.withLock(options.lock.deploymentName, attempt);\n });\n const redacted = (value: string | Redacted.Redacted<string>) =>\n typeof value === \"string\" ? Redacted.make(value) : value;\n const valueAt = (\n variables: Readonly<Record<string, Redacted.Redacted<string>>>,\n name: string,\n ) => (Rec.has(variables, name) ? variables[name] : undefined);\n const select = (\n variables: Readonly<Record<string, Redacted.Redacted<string>>>,\n names: ReadonlyArray<string>,\n ) =>\n Rec.fromEntries(\n Arr.flatMap(names, (name) =>\n !Rec.has(variables, name) ? [] : [[name, variables[name]]],\n ),\n );\n const checkDrift = (\n policy: EnvironmentVariablesProps[\"driftPolicy\"],\n output: EnvironmentVariablesAttributes | undefined,\n observed: ConvexClient.EnvironmentVariables,\n desired: Input<EnvironmentVariablesProps[\"variables\"]> | undefined,\n ) => {\n if (policy !== \"error\" || output === undefined) return Effect.void;\n const desiredVariables =\n Predicate.isReadonlyObject(desired) &&\n !Output.isExpr(desired) &&\n !Effect.isEffect(desired)\n ? desired\n : undefined;\n for (const name of output.ownedNames) {\n const previous = valueAt(output.variables, name);\n const current = valueAt(observed, name);\n const wanted = desiredVariables?.[name];\n if (\n current !== undefined &&\n (desiredVariables === undefined ||\n (wanted !== undefined && !isResolved(wanted)))\n )\n continue;\n if (\n current !== undefined &&\n (typeof wanted === \"string\" || Redacted.isRedacted(wanted)) &&\n Redacted.value(current) ===\n (typeof wanted === \"string\" ? wanted : Redacted.value(wanted))\n )\n continue;\n if (previous === undefined && current === undefined) continue;\n if (\n previous === undefined ||\n current === undefined ||\n Redacted.value(previous) !== Redacted.value(current)\n )\n return Effect.fail(\n EnvironmentVariableDrift.make({ variableName: name }),\n );\n }\n return Effect.void;\n };\n const checkUnowned = (\n policy: EnvironmentVariablesProps[\"unownedPolicy\"],\n output: EnvironmentVariablesAttributes | undefined,\n desiredNames: ReadonlyArray<string> | undefined,\n observed: ConvexClient.EnvironmentVariables,\n ) => {\n if (policy !== \"error\" || desiredNames === undefined) return Effect.void;\n for (const name of Rec.keys(observed)) {\n if (\n output?.ownedNames.includes(name) !== true &&\n !desiredNames.includes(name)\n )\n return Effect.fail(\n EnvironmentVariableUnowned.make({ variableName: name }),\n );\n }\n return Effect.void;\n };\n const service = {\n diff: Effect.fn(\"EnvironmentVariables.diff\")(function* ({\n olds,\n news,\n output,\n }) {\n const options = optionsForDiff(olds, news);\n if (\n output !== undefined &&\n (options.driftPolicy === \"error\" ||\n options.unownedPolicy === \"error\" ||\n options.adoptMatching === true)\n ) {\n const observed = yield* client.listEnvironmentVariables(\n output.url,\n output.deployKey,\n );\n yield* checkDrift(\n options.driftPolicy,\n output,\n observed,\n options.desiredVariables,\n );\n if (\n options.adoptMatching === true &&\n Predicate.isReadonlyObject(options.desiredVariables) &&\n !Output.isExpr(options.desiredVariables) &&\n !Effect.isEffect(options.desiredVariables)\n ) {\n for (const [name, wanted] of Rec.toEntries(\n options.desiredVariables,\n )) {\n const current = valueAt(observed, name);\n if (\n !output.ownedNames.includes(name) &&\n current !== undefined &&\n (typeof wanted === \"string\" || Redacted.isRedacted(wanted)) &&\n Redacted.value(current) !==\n (typeof wanted === \"string\" ? wanted : Redacted.value(wanted))\n )\n return yield* ownershipConflict(name);\n }\n }\n yield* checkUnowned(\n options.unownedPolicy,\n output,\n options.desiredNames,\n observed,\n );\n }\n if (!isResolved(news) || output === undefined) return;\n if (news.url !== output.url)\n return yield* EnvironmentTargetChange.make({\n url: output.url,\n });\n const names = Rec.keys(news.variables);\n if (\n names.length !== output.ownedNames.length ||\n Arr.some(names, (name) => !output.ownedNames.includes(name))\n )\n return { action: \"update\" };\n const variables = yield* client.listEnvironmentVariables(\n news.url,\n news.deployKey,\n );\n for (const [name, value] of Rec.toEntries(news.variables)) {\n const observed = valueAt(variables, name);\n if (\n observed === undefined ||\n Redacted.value(observed) !== Redacted.value(redacted(value))\n )\n return { action: \"update\" };\n }\n }),\n read: Effect.fn(\"EnvironmentVariables.read\")(function* ({ olds, output }) {\n const url = output?.url ?? olds.url;\n if (url === undefined || olds.deployKey === undefined) return;\n const observed = yield* client.listEnvironmentVariables(\n url,\n olds.deployKey,\n );\n yield* checkDrift(olds.driftPolicy, output, observed, olds.variables);\n yield* checkUnowned(\n olds.unownedPolicy,\n output,\n Rec.keys(olds.variables),\n observed,\n );\n const ownedNames = output?.ownedNames ?? Rec.keys(olds.variables);\n const variables = select(observed, ownedNames);\n if (output !== undefined)\n return { ...output, deployKey: olds.deployKey, variables };\n if (Rec.keys(variables).length === 0) return undefined;\n if (olds.adoptMatching === true) {\n for (const [name, value] of Rec.toEntries(variables)) {\n if (\n Redacted.value(value) !==\n Redacted.value(redacted(olds.variables[name]))\n )\n return yield* ownershipConflict(name);\n }\n return undefined;\n }\n return Unowned({\n url,\n deployKey: olds.deployKey,\n ownedNames,\n variables,\n originals: variables,\n });\n }),\n reconcile: Effect.fn(\"EnvironmentVariables.reconcile\")(function* ({\n fqn,\n instanceId,\n news,\n output,\n }) {\n if (output === undefined) yield* checkpointCreate(fqn, instanceId, news);\n if (output !== undefined && output.url !== news.url)\n return yield* EnvironmentTargetChange.make({\n url: output.url,\n });\n const observed = yield* client.listEnvironmentVariables(\n news.url,\n news.deployKey,\n );\n yield* checkDrift(news.driftPolicy, output, observed, news.variables);\n yield* checkUnowned(\n news.unownedPolicy,\n output,\n Rec.keys(news.variables),\n observed,\n );\n const ownedNames = Rec.keys(news.variables);\n if (\n output === undefined &&\n news.adoptMatching !== true &&\n (yield* shouldAdopt(fqn))\n ) {\n const variables = select(observed, ownedNames);\n output = {\n url: news.url,\n deployKey: news.deployKey,\n ownedNames,\n variables,\n originals: variables,\n };\n yield* checkpointCreate(fqn, instanceId, news, output);\n }\n const previousNames = output?.ownedNames ?? [];\n let originals = output?.originals ?? {};\n for (const name of ownedNames) {\n const current = valueAt(observed, name);\n if (previousNames.includes(name) || current === undefined) continue;\n if (\n news.adoptMatching === true &&\n Redacted.value(current) ===\n Redacted.value(redacted(news.variables[name]))\n ) {\n originals = Rec.set(originals, name, current);\n yield* Effect.logInfo(`Adopted environment variable ${name}`);\n } else {\n return yield* ownershipConflict(name);\n }\n }\n if (output === undefined && news.adoptMatching === true) {\n yield* checkpointCreate(fqn, instanceId, news, {\n url: news.url,\n deployKey: news.deployKey,\n ownedNames,\n variables: select(observed, ownedNames),\n originals,\n } satisfies EnvironmentVariablesAttributes);\n }\n const desired = Rec.fromEntries(\n Arr.map(Rec.toEntries(news.variables), ([name, value]) => [\n name,\n redacted(value),\n ]),\n );\n const changes: Array<{\n name: string;\n value?: Redacted.Redacted<string>;\n }> = [];\n for (const [name, value] of Rec.toEntries(desired)) {\n const current = valueAt(observed, name);\n if (\n current === undefined ||\n Redacted.value(current) !== Redacted.value(value)\n )\n changes.push({ name, value });\n }\n for (const name of previousNames) {\n if (Rec.has(desired, name)) continue;\n const original =\n output !== undefined ? valueAt(output.originals, name) : undefined;\n const current = valueAt(observed, name);\n if (original !== undefined) {\n if (\n current === undefined ||\n Redacted.value(current) !== Redacted.value(original)\n )\n changes.push({ name, value: original });\n } else if (current !== undefined) changes.push({ name });\n }\n if (changes.length > 0)\n yield* client.updateEnvironmentVariables(\n news.url,\n news.deployKey,\n changes,\n );\n return {\n url: news.url,\n deployKey: news.deployKey,\n ownedNames,\n variables: desired,\n originals: select(originals, ownedNames),\n };\n }),\n delete: Effect.fn(\"EnvironmentVariables.delete\")(function* ({\n olds,\n output,\n }) {\n const observed = yield* client\n .listEnvironmentVariables(output.url, output.deployKey)\n .pipe(Effect.catchTag(\"ConvexNotFound\", () => Effect.void));\n if (observed === undefined) return;\n yield* checkDrift(olds.driftPolicy, output, observed, {});\n yield* checkUnowned(\n olds.unownedPolicy,\n output,\n Rec.keys(olds.variables),\n observed,\n );\n const changes: Array<{\n name: string;\n value?: Redacted.Redacted<string>;\n }> = [];\n for (const name of output.ownedNames) {\n const original = valueAt(output.originals, name);\n const current = valueAt(observed, name);\n if (original !== undefined) {\n if (\n current === undefined ||\n Redacted.value(current) !== Redacted.value(original)\n )\n changes.push({ name, value: original });\n } else if (current !== undefined) changes.push({ name });\n }\n if (changes.length > 0)\n yield* client\n .updateEnvironmentVariables(output.url, output.deployKey, changes)\n .pipe(Effect.catchTag(\"ConvexNotFound\", () => Effect.void));\n }),\n } satisfies Provider.ProviderServiceInput<EnvironmentVariables>;\n return {\n diff: (input) =>\n withSafety(optionsForDiff(input.olds, input.news), service.diff(input)),\n read: (input) => withSafety(input.olds, service.read(input)),\n reconcile: (input) => withSafety(input.news, service.reconcile(input)),\n delete: (input) => withSafety(input.olds, service.delete(input)),\n } satisfies Provider.ProviderServiceInput<EnvironmentVariables>;\n});\n\n/**\n * Under `alchemy dev` variables are managed on the local backend. A backend\n * that is not running keeps its variables in its retained data, so removing\n * them is skipped rather than failing the apply.\n */\nexport const localProvider = Effect.map(\n provider,\n (service) =>\n ({\n ...service,\n delete: (input) =>\n service.delete(input).pipe(\n Effect.catchIf(\n (error) =>\n error._tag === \"ConvexApiError\" &&\n error.code === \"TransportError\",\n () => Effect.void,\n ),\n ),\n }) satisfies Provider.ProviderServiceInput<EnvironmentVariables>,\n);\n\nexport const layer = Provider.effect(EnvironmentVariables, provider);\nexport const localLayer = Provider.effect(\n EnvironmentVariables,\n localProvider,\n).pipe(\n Layer.provide(\n ConvexClient.layer({ mode: \"local\" }).pipe(\n Layer.provide(FetchHttpClient.layer),\n ),\n ),\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA+EA,MAAM,uBAAuB,SAC3B,6BACF;AAGA,MAAa,uBACX,OAAO,OACL,IAAI,MAAM,sBAAsB,EAC9B,QACE,QACA,OACA,SAYG;CACH,IAAI,KAAK,WAAW,GAClB,OAAO,OAAO,OAAO,sBAAsB,KAAK,EAAE;CACpD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OACJ,2BAA2B,OAAO,KAAK,OAAO,WAAW,OAAO,CAAC,CACjE,KAAK,OAAO,SAAS,wBAAwB,OAAO,IAAI,CAAC;EAChE,CAAC;CACH;CACA,OAAO;EACL,OAAO,UACL,WAAW,eAAe,MAAM,MAAM,MAAM,IAAI,GAAG,QAAQ,KAAK,KAAK,CAAC;EACxE,OAAO,UAAU,WAAW,MAAM,MAAM,QAAQ,KAAK,KAAK,CAAC;EAC3D,YAAY,UAAU,WAAW,MAAM,MAAM,QAAQ,UAAU,KAAK,CAAC;EACrE,SAAS,UAAU,WAAW,MAAM,MAAM,QAAQ,OAAO,KAAK,CAAC;CACjE;AACF,CAAC;;;;;;AAOD,MAAa,gBAAgB,OAAO,IAClC,WACC,aACE;CACC,GAAG;CACH,SAAS,UACP,QAAQ,OAAO,KAAK,CAAC,CAAC,KACpB,OAAO,SACJ,UACC,MAAM,SAAS,oBACf,MAAM,SAAS,wBACX,OAAO,IACf,CACF;AACJ,EACJ;AAEA,MAAa,QAAQ,SAAS,OAAO,sBAAsB,QAAQ;AACnE,MAAa,aAAa,SAAS,OACjC,sBACA,aACF,CAAC,CAAC,KACA,MAAM,QACJC,QAAmB,EAAE,MAAM,QAAQ,CAAC,CAAC,CAAC,KACpC,MAAM,QAAQ,gBAAgB,KAAK,CACrC,CACF,CACF"}
|
package/dist/Providers.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Providers.d.ts","sources":["../src/Providers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,QAAQ,MAAM,kBAAkB,CAAC;AAC7C,OAAO,KAAK,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;;
|
|
1
|
+
{"version":3,"file":"Providers.d.ts","sources":["../src/Providers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,QAAQ,MAAM,kBAAkB,CAAC;AAC7C,OAAO,KAAK,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;;AAYtC,qBAAa,SAAU,SAAQ,cAE9B;CAAG;AAEJ;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS,aAAc;IAClC,QAAQ,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;CAC5C,qXA6CE,CAAC"}
|
package/dist/Providers.js
CHANGED
|
@@ -4,8 +4,9 @@ import { Deployment, layer as layer$2, localLayer as localLayer$1 } from "./Depl
|
|
|
4
4
|
import { DeployKey, layer as layer$3, localLayer as localLayer$2 } from "./DeployKey.js";
|
|
5
5
|
import { EnvironmentVariables, layer as layer$4, localLayer as localLayer$3 } from "./EnvironmentVariables.js";
|
|
6
6
|
import { Project, layer as layer$5, localLayer as localLayer$4 } from "./Project.js";
|
|
7
|
-
import { layer as layer$6 } from "./
|
|
8
|
-
import { layer as layer$7 } from "./internal/
|
|
7
|
+
import { UsageLimit, layer as layer$6, localLayer as localLayer$5 } from "./UsageLimit.js";
|
|
8
|
+
import { layer as layer$7 } from "./internal/CommandRunner.js";
|
|
9
|
+
import { layer as layer$8 } from "./internal/PushLock.js";
|
|
9
10
|
import * as Provider from "alchemy/Provider";
|
|
10
11
|
import * as Layer from "effect/Layer";
|
|
11
12
|
import * as FetchHttpClient from "effect/http/FetchHttpClient";
|
|
@@ -25,7 +26,8 @@ const providers = (options) => Layer.effect(Providers, Provider.collection([
|
|
|
25
26
|
Deployment,
|
|
26
27
|
DeployKey,
|
|
27
28
|
EnvironmentVariables,
|
|
28
|
-
Code
|
|
29
|
+
Code,
|
|
30
|
+
UsageLimit
|
|
29
31
|
])).pipe(Layer.provide(Layer.mergeAll(ProviderLayer.dual(Project, {
|
|
30
32
|
live: () => layer$5,
|
|
31
33
|
local: () => localLayer$4
|
|
@@ -38,10 +40,13 @@ const providers = (options) => Layer.effect(Providers, Provider.collection([
|
|
|
38
40
|
}), ProviderLayer.dual(EnvironmentVariables, {
|
|
39
41
|
live: () => layer$4,
|
|
40
42
|
local: () => localLayer$3
|
|
43
|
+
}), ProviderLayer.dual(UsageLimit, {
|
|
44
|
+
live: () => layer$6,
|
|
45
|
+
local: () => localLayer$5
|
|
41
46
|
}), ProviderLayer.dual(Code, {
|
|
42
47
|
live: () => layer,
|
|
43
48
|
local: () => localLayer
|
|
44
|
-
}))), Layer.provide(layer$1(options).pipe(Layer.provide(FetchHttpClient.layer))), Layer.provide(layer$
|
|
49
|
+
}))), Layer.provide(layer$1(options).pipe(Layer.provide(FetchHttpClient.layer))), Layer.provide(layer$7), Layer.provide(layer$8()));
|
|
45
50
|
export { Providers, providers };
|
|
46
51
|
|
|
47
52
|
//# sourceMappingURL=Providers.js.map
|
package/dist/Providers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Providers.js","names":["Project.Project","Deployment.Deployment","DeployKey.DeployKey","EnvironmentVariables.EnvironmentVariables","Code.Code","Project.layer","Project.localLayer","Deployment.layer","Deployment.localLayer","DeployKey.layer","DeployKey.localLayer","EnvironmentVariables.layer","EnvironmentVariables.localLayer","Code.layer","Code.localLayer","ConvexClient.layer","CommandRunner.layer","PushLock.layer"],"sources":["../src/Providers.ts"],"sourcesContent":["import * as ProviderLayer from \"alchemy/Local/ProviderLayer\";\nimport * as Provider from \"alchemy/Provider\";\nimport type * as Redacted from \"effect/Redacted\";\nimport * as Layer from \"effect/Layer\";\nimport * as FetchHttpClient from \"effect/http/FetchHttpClient\";\nimport * as Code from \"./Code.js\";\nimport * as ConvexClient from \"./ConvexClient.js\";\nimport * as Deployment from \"./Deployment.js\";\nimport * as DeployKey from \"./DeployKey.js\";\nimport * as EnvironmentVariables from \"./EnvironmentVariables.js\";\nimport * as Project from \"./Project.js\";\nimport * as CommandRunner from \"./internal/CommandRunner.js\";\nimport * as PushLock from \"./internal/PushLock.js\";\n\nexport class Providers extends Provider.ProviderCollection<Providers>()(\n \"@confect/alchemy/Providers\",\n) {}\n\n/**\n * Register Convex resources without eagerly resolving management credentials.\n * `alchemy deploy` resolves each resource to its cloud provider; `alchemy dev`\n * resolves the same resources to local providers backed by a local Convex\n * backend, so one stack definition serves both.\n *\n * @stability unstable\n */\nexport const providers = (options?: {\n readonly token?: Redacted.Redacted<string>;\n}) =>\n Layer.effect(\n Providers,\n Provider.collection([\n Project.Project,\n Deployment.Deployment,\n DeployKey.DeployKey,\n EnvironmentVariables.EnvironmentVariables,\n Code.Code,\n ]),\n ).pipe(\n Layer.provide(\n Layer.mergeAll(\n ProviderLayer.dual(Project.Project, {\n live: () => Project.layer,\n local: () => Project.localLayer,\n }),\n ProviderLayer.dual(Deployment.Deployment, {\n live: () => Deployment.layer,\n local: () => Deployment.localLayer,\n }),\n ProviderLayer.dual(DeployKey.DeployKey, {\n live: () => DeployKey.layer,\n local: () => DeployKey.localLayer,\n }),\n ProviderLayer.dual(EnvironmentVariables.EnvironmentVariables, {\n live: () => EnvironmentVariables.layer,\n local: () => EnvironmentVariables.localLayer,\n }),\n ProviderLayer.dual(Code.Code, {\n live: () => Code.layer,\n local: () => Code.localLayer,\n }),\n ),\n ),\n Layer.provide(\n ConvexClient.layer(options).pipe(Layer.provide(FetchHttpClient.layer)),\n ),\n Layer.provide(CommandRunner.layer),\n Layer.provide(PushLock.layer()),\n );\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"Providers.js","names":["Project.Project","Deployment.Deployment","DeployKey.DeployKey","EnvironmentVariables.EnvironmentVariables","Code.Code","UsageLimit.UsageLimit","Project.layer","Project.localLayer","Deployment.layer","Deployment.localLayer","DeployKey.layer","DeployKey.localLayer","EnvironmentVariables.layer","EnvironmentVariables.localLayer","UsageLimit.layer","UsageLimit.localLayer","Code.layer","Code.localLayer","ConvexClient.layer","CommandRunner.layer","PushLock.layer"],"sources":["../src/Providers.ts"],"sourcesContent":["import * as ProviderLayer from \"alchemy/Local/ProviderLayer\";\nimport * as Provider from \"alchemy/Provider\";\nimport type * as Redacted from \"effect/Redacted\";\nimport * as Layer from \"effect/Layer\";\nimport * as FetchHttpClient from \"effect/http/FetchHttpClient\";\nimport * as Code from \"./Code.js\";\nimport * as ConvexClient from \"./ConvexClient.js\";\nimport * as Deployment from \"./Deployment.js\";\nimport * as DeployKey from \"./DeployKey.js\";\nimport * as EnvironmentVariables from \"./EnvironmentVariables.js\";\nimport * as Project from \"./Project.js\";\nimport * as UsageLimit from \"./UsageLimit.js\";\nimport * as CommandRunner from \"./internal/CommandRunner.js\";\nimport * as PushLock from \"./internal/PushLock.js\";\n\nexport class Providers extends Provider.ProviderCollection<Providers>()(\n \"@confect/alchemy/Providers\",\n) {}\n\n/**\n * Register Convex resources without eagerly resolving management credentials.\n * `alchemy deploy` resolves each resource to its cloud provider; `alchemy dev`\n * resolves the same resources to local providers backed by a local Convex\n * backend, so one stack definition serves both.\n *\n * @stability unstable\n */\nexport const providers = (options?: {\n readonly token?: Redacted.Redacted<string>;\n}) =>\n Layer.effect(\n Providers,\n Provider.collection([\n Project.Project,\n Deployment.Deployment,\n DeployKey.DeployKey,\n EnvironmentVariables.EnvironmentVariables,\n Code.Code,\n UsageLimit.UsageLimit,\n ]),\n ).pipe(\n Layer.provide(\n Layer.mergeAll(\n ProviderLayer.dual(Project.Project, {\n live: () => Project.layer,\n local: () => Project.localLayer,\n }),\n ProviderLayer.dual(Deployment.Deployment, {\n live: () => Deployment.layer,\n local: () => Deployment.localLayer,\n }),\n ProviderLayer.dual(DeployKey.DeployKey, {\n live: () => DeployKey.layer,\n local: () => DeployKey.localLayer,\n }),\n ProviderLayer.dual(EnvironmentVariables.EnvironmentVariables, {\n live: () => EnvironmentVariables.layer,\n local: () => EnvironmentVariables.localLayer,\n }),\n ProviderLayer.dual(UsageLimit.UsageLimit, {\n live: () => UsageLimit.layer,\n local: () => UsageLimit.localLayer,\n }),\n ProviderLayer.dual(Code.Code, {\n live: () => Code.layer,\n local: () => Code.localLayer,\n }),\n ),\n ),\n Layer.provide(\n ConvexClient.layer(options).pipe(Layer.provide(FetchHttpClient.layer)),\n ),\n Layer.provide(CommandRunner.layer),\n Layer.provide(PushLock.layer()),\n );\n"],"mappings":";;;;;;;;;;;;;;AAeA,IAAa,YAAb,cAA+B,SAAS,mBAA8B,CAAC,CACrE,4BACF,CAAC,CAAC,CAAC;;;;;;;;;AAUH,MAAa,aAAa,YAGxB,MAAM,OACJ,WACA,SAAS,WAAW;CAClBA;CACAC;CACAC;CACAC;CACAC;CACAC;AACF,CAAC,CACH,CAAC,CAAC,KACA,MAAM,QACJ,MAAM,SACJ,cAAc,KAAKL,SAAiB;CAClC,YAAYM;CACZ,aAAaC;AACf,CAAC,GACD,cAAc,KAAKN,YAAuB;CACxC,YAAYO;CACZ,aAAaC;AACf,CAAC,GACD,cAAc,KAAKP,WAAqB;CACtC,YAAYQ;CACZ,aAAaC;AACf,CAAC,GACD,cAAc,KAAKR,sBAA2C;CAC5D,YAAYS;CACZ,aAAaC;AACf,CAAC,GACD,cAAc,KAAKR,YAAuB;CACxC,YAAYS;CACZ,aAAaC;AACf,CAAC,GACD,cAAc,KAAKX,MAAW;CAC5B,YAAYY;CACZ,aAAaC;AACf,CAAC,CACH,CACF,GACA,MAAM,QACJC,QAAmB,OAAO,CAAC,CAAC,KAAK,MAAM,QAAQ,gBAAgB,KAAK,CAAC,CACvE,GACA,MAAM,QAAQC,OAAmB,GACjC,MAAM,QAAQC,QAAe,CAAC,CAChC"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import type { UsageLimitMetric, UsageLimitType, UsageLimitWindow } from "@convex-dev/platform/deploymentApi";
|
|
2
|
+
import { OwnedBySomeoneElse } from "alchemy/AdoptPolicy";
|
|
3
|
+
import * as Provider from "alchemy/Provider";
|
|
4
|
+
import { Resource } from "alchemy/Resource";
|
|
5
|
+
import * as Effect from "effect/Effect";
|
|
6
|
+
import * as Schema from "effect/Schema";
|
|
7
|
+
import { ConvexClient } from "./ConvexClient.js";
|
|
8
|
+
import type { Providers } from "./Providers.js";
|
|
9
|
+
export interface UsageLimitProps {
|
|
10
|
+
readonly deployment: {
|
|
11
|
+
readonly name: string;
|
|
12
|
+
readonly url: string;
|
|
13
|
+
};
|
|
14
|
+
readonly metric: UsageLimitMetric;
|
|
15
|
+
readonly window: UsageLimitWindow;
|
|
16
|
+
readonly limit: number;
|
|
17
|
+
readonly limitType?: UsageLimitType;
|
|
18
|
+
readonly enabled?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface UsageLimitAttributes {
|
|
21
|
+
readonly deployment: {
|
|
22
|
+
readonly name: string;
|
|
23
|
+
readonly url: string;
|
|
24
|
+
};
|
|
25
|
+
readonly id: string;
|
|
26
|
+
readonly metric: UsageLimitMetric;
|
|
27
|
+
readonly window: UsageLimitWindow;
|
|
28
|
+
readonly limit: number;
|
|
29
|
+
readonly limitType: UsageLimitType;
|
|
30
|
+
readonly enabled: boolean;
|
|
31
|
+
}
|
|
32
|
+
export type UsageLimit = Resource<"Convex.UsageLimit", UsageLimitProps, UsageLimitAttributes, never, Providers>;
|
|
33
|
+
export declare const UsageLimit: import("alchemy").ResourceClass<UsageLimit>;
|
|
34
|
+
declare const UsageLimitTargetChange_base: Schema.Class<UsageLimitTargetChange, Schema.TaggedStruct<"UsageLimitTargetChange", {
|
|
35
|
+
readonly deploymentName: Schema.String;
|
|
36
|
+
}>, import("effect/Cause").YieldableError & {
|
|
37
|
+
readonly brand: unique symbol;
|
|
38
|
+
}>;
|
|
39
|
+
export declare class UsageLimitTargetChange extends UsageLimitTargetChange_base {
|
|
40
|
+
}
|
|
41
|
+
declare const AmbiguousUsageLimit_base: Schema.Class<AmbiguousUsageLimit, Schema.TaggedStruct<"AmbiguousUsageLimit", {
|
|
42
|
+
readonly deploymentName: Schema.String;
|
|
43
|
+
readonly metric: Schema.String;
|
|
44
|
+
readonly window: Schema.String;
|
|
45
|
+
readonly limitType: Schema.String;
|
|
46
|
+
readonly limitIds: Schema.$Array<Schema.String>;
|
|
47
|
+
}>, import("effect/Cause").YieldableError & {
|
|
48
|
+
readonly brand: unique symbol;
|
|
49
|
+
}>;
|
|
50
|
+
export declare class AmbiguousUsageLimit extends AmbiguousUsageLimit_base {
|
|
51
|
+
get message(): string;
|
|
52
|
+
}
|
|
53
|
+
declare const InvalidUsageLimit_base: Schema.Class<InvalidUsageLimit, Schema.TaggedStruct<"InvalidUsageLimit", {
|
|
54
|
+
readonly limit: Schema.String;
|
|
55
|
+
}>, import("effect/Cause").YieldableError & {
|
|
56
|
+
readonly brand: unique symbol;
|
|
57
|
+
}>;
|
|
58
|
+
export declare class InvalidUsageLimit extends InvalidUsageLimit_base {
|
|
59
|
+
get message(): string;
|
|
60
|
+
}
|
|
61
|
+
declare const UnsupportedLocalUsageLimit_base: Schema.Class<UnsupportedLocalUsageLimit, Schema.TaggedStruct<"UnsupportedLocalUsageLimit", {}>, import("effect/Cause").YieldableError & {
|
|
62
|
+
readonly brand: unique symbol;
|
|
63
|
+
}>;
|
|
64
|
+
export declare class UnsupportedLocalUsageLimit extends UnsupportedLocalUsageLimit_base {
|
|
65
|
+
get message(): string;
|
|
66
|
+
}
|
|
67
|
+
export declare const provider: Effect.Effect<{
|
|
68
|
+
diff: (args_0: {
|
|
69
|
+
id: string;
|
|
70
|
+
fqn: string;
|
|
71
|
+
instanceId: string;
|
|
72
|
+
olds: UsageLimitProps;
|
|
73
|
+
news: import("alchemy").Input<UsageLimitProps>;
|
|
74
|
+
oldBindings: import("alchemy").ResourceBinding<never>[];
|
|
75
|
+
newBindings: import("alchemy").Input<import("alchemy").ResourceBinding<never>[]>;
|
|
76
|
+
output: UsageLimitAttributes | undefined;
|
|
77
|
+
}) => Effect.Effect<{
|
|
78
|
+
action: "replace";
|
|
79
|
+
} | {
|
|
80
|
+
action: "update";
|
|
81
|
+
} | undefined, import("./ConvexClient.js").ConvexApiError | import("./ConvexClient.js").ConvexConflict | InvalidUsageLimit, never>;
|
|
82
|
+
read: (args_0: {
|
|
83
|
+
id: string;
|
|
84
|
+
fqn: string;
|
|
85
|
+
instanceId: string;
|
|
86
|
+
olds: UsageLimitProps;
|
|
87
|
+
output: UsageLimitAttributes | undefined;
|
|
88
|
+
previous?: UsageLimitAttributes;
|
|
89
|
+
}) => Effect.Effect<{
|
|
90
|
+
id: string;
|
|
91
|
+
metric: "actionComputeConvexGbHours" | "actionComputeCpuGbHours" | "actionComputeNodeJsGbHours" | "aiGatewayCostDollars" | "dataEgressGb" | "databaseIoGb" | "functionCalls" | "queryMutationComputeGbHours" | "searchQueryGb";
|
|
92
|
+
window: "day" | "month";
|
|
93
|
+
limitType: "disable" | "warning";
|
|
94
|
+
limit: number;
|
|
95
|
+
enabled: boolean;
|
|
96
|
+
deployment: {
|
|
97
|
+
readonly name: string;
|
|
98
|
+
readonly url: string;
|
|
99
|
+
};
|
|
100
|
+
} | undefined, AmbiguousUsageLimit | import("./ConvexClient.js").ConvexApiError | import("./ConvexClient.js").ConvexConflict | InvalidUsageLimit, never>;
|
|
101
|
+
reconcile: (args_0: {
|
|
102
|
+
id: string;
|
|
103
|
+
fqn: string;
|
|
104
|
+
instanceId: string;
|
|
105
|
+
news: UsageLimitProps;
|
|
106
|
+
olds: UsageLimitProps | undefined;
|
|
107
|
+
output: UsageLimitAttributes | undefined;
|
|
108
|
+
session: import("alchemy/Report").ScopedPlanStatusSession;
|
|
109
|
+
bindings: import("alchemy").ResourceBinding<never>[];
|
|
110
|
+
}) => Effect.Effect<{
|
|
111
|
+
id: string;
|
|
112
|
+
metric: "actionComputeConvexGbHours" | "actionComputeCpuGbHours" | "actionComputeNodeJsGbHours" | "aiGatewayCostDollars" | "dataEgressGb" | "databaseIoGb" | "functionCalls" | "queryMutationComputeGbHours" | "searchQueryGb";
|
|
113
|
+
window: "day" | "month";
|
|
114
|
+
limitType: "disable" | "warning";
|
|
115
|
+
limit: number;
|
|
116
|
+
enabled: boolean;
|
|
117
|
+
deployment: {
|
|
118
|
+
readonly name: string;
|
|
119
|
+
readonly url: string;
|
|
120
|
+
};
|
|
121
|
+
}, AmbiguousUsageLimit | import("./ConvexClient.js").ConvexApiError | import("./ConvexClient.js").ConvexConflict | import("./ConvexClient.js").ConvexNotFound | InvalidUsageLimit | import("./internal/Lifecycle.js").LifecycleStateError | OwnedBySomeoneElse | import("alchemy/State/State").StateStoreError | UsageLimitTargetChange, never>;
|
|
122
|
+
delete: (args_0: {
|
|
123
|
+
id: string;
|
|
124
|
+
fqn: string;
|
|
125
|
+
instanceId: string;
|
|
126
|
+
olds: UsageLimitProps;
|
|
127
|
+
output: UsageLimitAttributes;
|
|
128
|
+
session: import("alchemy/Report").ScopedPlanStatusSession;
|
|
129
|
+
bindings: import("alchemy").ResourceBinding<never>[];
|
|
130
|
+
force?: boolean;
|
|
131
|
+
}) => Effect.Effect<void, import("./ConvexClient.js").ConvexApiError | import("./ConvexClient.js").ConvexConflict, never>;
|
|
132
|
+
}, never, ConvexClient>;
|
|
133
|
+
export declare const localProvider: Effect.Effect<{
|
|
134
|
+
reconcile: () => Effect.Effect<never, UnsupportedLocalUsageLimit, never>;
|
|
135
|
+
delete: () => Effect.Effect<void, never, never>;
|
|
136
|
+
}, never, never>;
|
|
137
|
+
export declare const layer: import("effect/Layer").Layer<Provider.Provider<UsageLimit>, never, ConvexClient>;
|
|
138
|
+
export declare const localLayer: import("effect/Layer").Layer<Provider.Provider<UsageLimit>, never, never>;
|
|
139
|
+
export {};
|
|
140
|
+
//# sourceMappingURL=UsageLimit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UsageLimit.d.ts","sources":["../src/UsageLimit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EACjB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAW,MAAM,qBAAqB,CAAC;AAElE,OAAO,KAAK,QAAQ,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,OAAO,KAAK,MAAM,MAAM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