@samebase/alchemy-convex 0.34.0 → 0.35.0
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/README.md +12 -9
- package/lib/{State-CuktZaOh.js → State-ceE-WFI3.js} +52 -51
- package/lib/{State-CuktZaOh.js.map → State-ceE-WFI3.js.map} +1 -1
- package/lib/cli.js +1 -1
- package/lib/index.d.ts +10 -5
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/package.json +1 -1
- package/src/RunRecord.ts +62 -5
- package/src/State.ts +13 -67
- package/src/store/component/_generated/api.ts +0 -2
- package/src/store/component/_generated/component.ts +5 -74
- package/src/store/component/reader.ts +46 -55
- package/src/store/component/schema.ts +4 -2
- package/src/store/component/state.ts +23 -72
- package/src/store/convex/state.ts +8 -25
- package/src/store/convex/version.ts +3 -1
- package/src/store/component/runRecord.ts +0 -57
package/lib/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { a as runRecord, n as state, r as RUN_RECORD_KEY } from "./State-
|
|
2
|
+
import { a as runRecord, n as state, r as RUN_RECORD_KEY } from "./State-ceE-WFI3.js";
|
|
3
3
|
import * as Effect from "effect/Effect";
|
|
4
4
|
import * as Schema from "effect/Schema";
|
|
5
5
|
import * as Layer from "effect/Layer";
|
package/lib/index.d.ts
CHANGED
|
@@ -491,12 +491,17 @@ interface RunEnvironment {
|
|
|
491
491
|
*/
|
|
492
492
|
export declare const runRecord: (where: RunEnvironment) => Effect.Effect<RunRecord, RunRecordError>;
|
|
493
493
|
/**
|
|
494
|
-
* The
|
|
495
|
-
* {@link RUN_RECORD_KEY}
|
|
496
|
-
*
|
|
497
|
-
*
|
|
494
|
+
* The state of `inner`, with the record of this run in each stage output that it writes, under
|
|
495
|
+
* {@link RUN_RECORD_KEY}: `state: withRunRecord(Convex.state())`, or the same over another state
|
|
496
|
+
* layer, such as the Cloudflare state store of Alchemy. Every other call goes to `inner` as it is.
|
|
497
|
+
*
|
|
498
|
+
* The record is derived once, at the first use of the state, and `recordedAt` is the time of the
|
|
499
|
+
* output write. A checkout that gives no record, such as a tarball without git, a checkout without
|
|
500
|
+
* `origin`, or a detached HEAD, still reads, plans, and destroys: its outputs are written without
|
|
501
|
+
* the record, and the log says why. The engine writes the output only after a full successful
|
|
502
|
+
* apply, so the record names the last full successful deploy of the stage.
|
|
498
503
|
*/
|
|
499
|
-
export declare const withRunRecord: (
|
|
504
|
+
export declare const withRunRecord: <E, R>(inner: Layer.Layer<State, E, R>) => Layer.Layer<State, E, R>;
|
|
500
505
|
//#endregion
|
|
501
506
|
//#region src/SharedHubClient.d.ts
|
|
502
507
|
/**
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/Credentials.ts","../src/ManagementApi.ts","../src/Providers.ts","../src/Push.ts","../src/Deployment.ts","../src/Component.ts","../src/LocalDeployment.ts","../src/Project.ts","../src/RunRecord.ts","../src/SharedHubClient.ts","../src/State.ts"],"mappings":";;;;;;;;;;;;;;;;;UA6BiB;;WAEN,aAAa,SAAS;;WAEtB;;UAGM;;WAEN,aAAa,OAAO,OAAO;;WAE3B,gBAAgB,OAAO;;WAEvB,WAAW,OAAO,OAAO,SAAS;;;qBAGhC,oBAAoB;;qBAKpB;;qBAGA;;;;qBAOA,yBAAyB;;;;;;;;;qBAiCzB,kBAAiB,MAAM,MAAM;;qBA0B7B,aAAc;WAChB,cAAc,SAAS;WACvB,YAAY,SAAS;MAC5B,MAAM,MAAM;;;KCvGJ,mBAAmB,kBAAkB;KACrC,mBAAmB,kBAAkB;;UAGhC,YAAY;WAClB,OAAO;WACP;WACA,UAAU;;;;;;;;;;;;;qBAQR,uBAAuB;UAuBnB;;WAEN,UAAU,GACjB,mBACA,MAAM,QAAQ,qBAAqB,QAAQ,YAAY,QACpD,OAAO,OAAO,GAAG;;WAEb,cACP,mBAC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;;;;;;;;;qBAMF,4BAA4B;MAS1B;;;;;UC7OE;WACN;WACA;WACA;;;;;;;;;qBAUE,gBAAiB;EAC5B,YAAY;EACZ;EACA,WAAW;MACZ,OAAA,yBAAA;;;;;;;qBCFY,gCAAgC;MAI9B;;UAeE;;WAEN;;WAEA,KAAK,SAAS,eAAe;;UAGvB;WACN;WACA;WACA;;WAEA;;YAGC,kBAAkB,mCAE5B,sBACA,kCAEA;qBAEW,mCAAe,yBAAA;;;;;;;;;;KCxBhB,mBAAmB;KAInB;;WAGG;WACA;;WAEA,mBAAmB;;WAEnB;;;WAIA;WACA;;UAGE;WACN;WACA;WACA;WACA;WACA;WACA;;YAGC,UAAU,2BAA2B,cAAc,0BAA0B;qBAC5E,2BAAO,cAAA;;;;;;;qBAGP,0BAA0B;MAIxB;;;;;;;;;;;;qBASF,gCAAgC;MAS9B;;;;;;;;qBAOF,yBAAyB;MAKvB;;;;;;qBAMF,+BAA+B;MAI7B;;;;;;;qBAMF,wBAAwB;MAItB;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/Credentials.ts","../src/ManagementApi.ts","../src/Providers.ts","../src/Push.ts","../src/Deployment.ts","../src/Component.ts","../src/LocalDeployment.ts","../src/Project.ts","../src/RunRecord.ts","../src/SharedHubClient.ts","../src/State.ts"],"mappings":";;;;;;;;;;;;;;;;;UA6BiB;;WAEN,aAAa,SAAS;;WAEtB;;UAGM;;WAEN,aAAa,OAAO,OAAO;;WAE3B,gBAAgB,OAAO;;WAEvB,WAAW,OAAO,OAAO,SAAS;;;qBAGhC,oBAAoB;;qBAKpB;;qBAGA;;;;qBAOA,yBAAyB;;;;;;;;;qBAiCzB,kBAAiB,MAAM,MAAM;;qBA0B7B,aAAc;WAChB,cAAc,SAAS;WACvB,YAAY,SAAS;MAC5B,MAAM,MAAM;;;KCvGJ,mBAAmB,kBAAkB;KACrC,mBAAmB,kBAAkB;;UAGhC,YAAY;WAClB,OAAO;WACP;WACA,UAAU;;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SAAS;;cAKtC,YAAU,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;UA6BC,kCAAkC,OAAO,OAAO,YAAY;YAqYjE,kBAAkB,qCAE5B,sBACA,kCAEA;qBAEW,mCAAe,yBAAA;WAzDV,OAAA,YAAM;aAAsB;QAAe,OAAA;;;;;;;;;;;;;WAmClC,YAAA,QAAA,oBAAe,OAAA;;;;;;;;;qBCjb7B;;;;;;;;qBAyXA,aAAY,MAAM,MAAM,cAAc,oBAAoB"}
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as ManagementApi, C as ConvexCliNotFound, D as parseDeployOutput, E as VariablesOwnedBySomeoneElse, F as CredentialsError, I as DEPLOY_KEY_ENV, L as fromConfig, M as readLocalDeployment, N as ACCESS_TOKEN_ENV, O as push, P as Credentials, R as fromValues, S as ConvexAppNotFound, T as PushTargetMismatch, _ as DeploymentIdentityChange, a as runRecord, b as ProductionDeploymentNotFound, c as CreatedProjectNotFound, d as ProjectNotFound, f as ProjectProvider, g as Deployment, h as AmbiguousDeployment, i as RunRecordError, j as ManagementApiLive, k as ConvexApiError, l as Project, m as AbsoluteRootDir, n as state, o as withRunRecord, p as ProjectTeamChange, r as RUN_RECORD_KEY, s as AmbiguousProject, t as STORE_PROJECT_NAME, u as ProjectDeploymentChange, v as DeploymentProvider, w as EnvironmentNeedsDeployKey, x as CodePushFailed, y as DeploymentResource } from "./State-
|
|
1
|
+
import { A as ManagementApi, C as ConvexCliNotFound, D as parseDeployOutput, E as VariablesOwnedBySomeoneElse, F as CredentialsError, I as DEPLOY_KEY_ENV, L as fromConfig, M as readLocalDeployment, N as ACCESS_TOKEN_ENV, O as push, P as Credentials, R as fromValues, S as ConvexAppNotFound, T as PushTargetMismatch, _ as DeploymentIdentityChange, a as runRecord, b as ProductionDeploymentNotFound, c as CreatedProjectNotFound, d as ProjectNotFound, f as ProjectProvider, g as Deployment, h as AmbiguousDeployment, i as RunRecordError, j as ManagementApiLive, k as ConvexApiError, l as Project, m as AbsoluteRootDir, n as state, o as withRunRecord, p as ProjectTeamChange, r as RUN_RECORD_KEY, s as AmbiguousProject, t as STORE_PROJECT_NAME, u as ProjectDeploymentChange, v as DeploymentProvider, w as EnvironmentNeedsDeployKey, x as CodePushFailed, y as DeploymentResource } from "./State-ceE-WFI3.js";
|
|
2
2
|
import { toPath } from "alchemy/FQN";
|
|
3
3
|
import { Stack } from "alchemy/Stack";
|
|
4
4
|
import * as Effect from "effect/Effect";
|
package/package.json
CHANGED
package/src/RunRecord.ts
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
// The run record: what the stage output says about the run that wrote it.
|
|
2
2
|
// Alchemy state holds no time, author, commit, branch, or run (measured in
|
|
3
|
-
// the Samebase research of 2026-10-21), so
|
|
4
|
-
// the output document under the reserved key `samebase.run`. The
|
|
5
|
-
// depends on no store: it comes from the GitHub Actions variables, or
|
|
6
|
-
// git in the checkout that runs the stack, and holds no secret
|
|
3
|
+
// the Samebase research of 2026-10-21), so the layer `withRunRecord` adds this
|
|
4
|
+
// record to the output document under the reserved key `samebase.run`. The
|
|
5
|
+
// record depends on no store: it comes from the GitHub Actions variables, or
|
|
6
|
+
// from git in the checkout that runs the stack, and holds no secret, and the
|
|
7
|
+
// layer goes over any state layer. See docs/design/convex-state.md.
|
|
7
8
|
import { execFile } from "node:child_process";
|
|
8
9
|
import { readFile, realpath } from "node:fs/promises";
|
|
9
10
|
import { relative, sep } from "node:path";
|
|
10
11
|
import { promisify } from "node:util";
|
|
12
|
+
import { State, type StateService } from "alchemy/State";
|
|
11
13
|
import * as Clock from "effect/Clock";
|
|
12
14
|
import * as Effect from "effect/Effect";
|
|
15
|
+
import * as Layer from "effect/Layer";
|
|
13
16
|
import * as Schema from "effect/Schema";
|
|
14
17
|
|
|
15
18
|
/** The key of the record in the stage output document. */
|
|
@@ -206,9 +209,63 @@ const isPlainObject = (value: unknown): value is Record<string, unknown> => {
|
|
|
206
209
|
* key: a string, an array, null, or an object that is not plain, such as a
|
|
207
210
|
* Date. A value that the stack itself put under the key stays.
|
|
208
211
|
*/
|
|
209
|
-
export const
|
|
212
|
+
export const outputWithRunRecord = (output: unknown, record: RunRecord): object | undefined =>
|
|
210
213
|
isPlainObject(output)
|
|
211
214
|
? RUN_RECORD_KEY in output
|
|
212
215
|
? output
|
|
213
216
|
: { ...output, [RUN_RECORD_KEY]: record }
|
|
214
217
|
: undefined;
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* The state of `inner`, with the record of this run in each stage output that it writes, under
|
|
221
|
+
* {@link RUN_RECORD_KEY}: `state: withRunRecord(Convex.state())`, or the same over another state
|
|
222
|
+
* layer, such as the Cloudflare state store of Alchemy. Every other call goes to `inner` as it is.
|
|
223
|
+
*
|
|
224
|
+
* The record is derived once, at the first use of the state, and `recordedAt` is the time of the
|
|
225
|
+
* output write. A checkout that gives no record, such as a tarball without git, a checkout without
|
|
226
|
+
* `origin`, or a detached HEAD, still reads, plans, and destroys: its outputs are written without
|
|
227
|
+
* the record, and the log says why. The engine writes the output only after a full successful
|
|
228
|
+
* apply, so the record names the last full successful deploy of the stage.
|
|
229
|
+
*/
|
|
230
|
+
export const withRunRecord = <E, R>(inner: Layer.Layer<State, E, R>): Layer.Layer<State, E, R> =>
|
|
231
|
+
Layer.effect(
|
|
232
|
+
State,
|
|
233
|
+
Effect.gen(function* () {
|
|
234
|
+
const open = yield* State;
|
|
235
|
+
return yield* Effect.cached(
|
|
236
|
+
Effect.gen(function* () {
|
|
237
|
+
const service = yield* open;
|
|
238
|
+
const run = yield* runRecord({ cwd: process.cwd(), env: process.env }).pipe(
|
|
239
|
+
Effect.catch((error) =>
|
|
240
|
+
Effect.logWarning(
|
|
241
|
+
`The stage outputs of this run carry no run record. ${error.message}`,
|
|
242
|
+
).pipe(Effect.as(undefined)),
|
|
243
|
+
),
|
|
244
|
+
);
|
|
245
|
+
const documentOf = (request: { stack: string; stage: string; value: unknown }) =>
|
|
246
|
+
Effect.gen(function* () {
|
|
247
|
+
if (run === undefined) return request.value;
|
|
248
|
+
const document = outputWithRunRecord(request.value, {
|
|
249
|
+
...run,
|
|
250
|
+
recordedAt: yield* now,
|
|
251
|
+
});
|
|
252
|
+
if (document !== undefined) return document;
|
|
253
|
+
yield* Effect.logWarning(
|
|
254
|
+
`The output of ${request.stack}/${request.stage} is not a plain object, so it carries no run record.`,
|
|
255
|
+
);
|
|
256
|
+
return request.value;
|
|
257
|
+
});
|
|
258
|
+
const wrapped: StateService = {
|
|
259
|
+
...service,
|
|
260
|
+
setOutput: (request) =>
|
|
261
|
+
documentOf(request).pipe(
|
|
262
|
+
Effect.flatMap((value) =>
|
|
263
|
+
service.setOutput({ stack: request.stack, stage: request.stage, value }),
|
|
264
|
+
),
|
|
265
|
+
),
|
|
266
|
+
};
|
|
267
|
+
return wrapped;
|
|
268
|
+
}),
|
|
269
|
+
);
|
|
270
|
+
}),
|
|
271
|
+
).pipe(Layer.provide(inner));
|
package/src/State.ts
CHANGED
|
@@ -33,13 +33,12 @@
|
|
|
33
33
|
// with a store of its own version. An older store is pushed over; a newer one
|
|
34
34
|
// fails the run.
|
|
35
35
|
//
|
|
36
|
-
// The
|
|
37
|
-
//
|
|
38
|
-
//
|
|
39
|
-
//
|
|
36
|
+
// The store holds Alchemy's state interface and nothing else, so a stack can
|
|
37
|
+
// use the state store of Alchemy's Cloudflare package in its place. The run
|
|
38
|
+
// record that Samebase reads is a layer over any state: see `withRunRecord` in
|
|
39
|
+
// src/RunRecord.ts.
|
|
40
40
|
import { dirname, join } from "node:path";
|
|
41
41
|
import { fileURLToPath } from "node:url";
|
|
42
|
-
import * as Clock from "effect/Clock";
|
|
43
42
|
import * as Effect from "effect/Effect";
|
|
44
43
|
import * as Layer from "effect/Layer";
|
|
45
44
|
import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
|
|
@@ -81,7 +80,6 @@ import {
|
|
|
81
80
|
withPushKey,
|
|
82
81
|
writeVariables,
|
|
83
82
|
} from "./Push.ts";
|
|
84
|
-
import { type RunRecord, runRecord, withRunRecord } from "./RunRecord.ts";
|
|
85
83
|
import { stateKeyName } from "./store/convex/sealing.ts";
|
|
86
84
|
import { STORE_VERSION } from "./store/convex/version.ts";
|
|
87
85
|
import { newKey, newKeyId } from "./store/sealedSecret.ts";
|
|
@@ -173,7 +171,7 @@ export interface FunctionApi {
|
|
|
173
171
|
/** POST /api/function, the call that `convex run` makes: the reply, which can be a function error. */
|
|
174
172
|
readonly call: (
|
|
175
173
|
path: string,
|
|
176
|
-
args: Record<string, string | boolean |
|
|
174
|
+
args: Record<string, string | boolean | undefined>,
|
|
177
175
|
) => Effect.Effect<Reply, StateStoreError>;
|
|
178
176
|
}
|
|
179
177
|
|
|
@@ -193,20 +191,9 @@ const valueOf = (reply: Reply) =>
|
|
|
193
191
|
: Effect.fail(failure(reply.errorMessage.trim()));
|
|
194
192
|
|
|
195
193
|
/** The functions of the store with Alchemy's encoding: the JSON text of encodeState. */
|
|
196
|
-
const remoteOf = (api: FunctionApi
|
|
197
|
-
const run = (name: string, args: Record<string, string |
|
|
194
|
+
const remoteOf = (api: FunctionApi) => {
|
|
195
|
+
const run = (name: string, args: Record<string, string | undefined>) =>
|
|
198
196
|
api.call(`state:${name}`, args).pipe(Effect.flatMap(valueOf));
|
|
199
|
-
const write = (name: string, args: Record<string, string>) =>
|
|
200
|
-
Effect.gen(function* () {
|
|
201
|
-
const currentRun =
|
|
202
|
-
record === undefined
|
|
203
|
-
? undefined
|
|
204
|
-
: {
|
|
205
|
-
...record,
|
|
206
|
-
recordedAt: new Date(yield* Clock.currentTimeMillis).toISOString(),
|
|
207
|
-
};
|
|
208
|
-
return yield* run(name, { ...args, run: currentRun });
|
|
209
|
-
});
|
|
210
197
|
const strings = (name: string, args: Record<string, string>) =>
|
|
211
198
|
run(name, args).pipe(Effect.flatMap(decode(Schema.Array(Schema.String), name)));
|
|
212
199
|
const optional = (name: string, args: Record<string, string>) =>
|
|
@@ -235,13 +222,13 @@ const remoteOf = (api: FunctionApi, record: RunRecord | undefined) => {
|
|
|
235
222
|
Effect.map((text): unknown => (text === null ? undefined : JSON.parse(text, reviveState))),
|
|
236
223
|
),
|
|
237
224
|
set: (r: { stack: string; stage: string; fqn: string; value: PersistedState }) =>
|
|
238
|
-
|
|
225
|
+
run("set", { stack: r.stack, stage: r.stage, fqn: r.fqn, value: encode(r.value) }),
|
|
239
226
|
delete: (r: { stack: string; stage: string; fqn: string }) =>
|
|
240
|
-
|
|
227
|
+
run("remove", { stack: r.stack, stage: r.stage, fqn: r.fqn }),
|
|
241
228
|
deleteStack: (r: { stack: string; stage?: string }) =>
|
|
242
229
|
run("removeStack", { stack: r.stack, stage: r.stage }),
|
|
243
230
|
setOutput: (r: { stack: string; stage: string; value: unknown }) =>
|
|
244
|
-
|
|
231
|
+
run("setOutput", { stack: r.stack, stage: r.stage, value: encode(r.value) }),
|
|
245
232
|
};
|
|
246
233
|
};
|
|
247
234
|
|
|
@@ -275,8 +262,6 @@ export interface StoreOptions {
|
|
|
275
262
|
readonly scope: Scope.Scope;
|
|
276
263
|
/** The functions directory that an outdated store gets: {@link storeDirectory}. */
|
|
277
264
|
readonly store: string;
|
|
278
|
-
/** The run recorded with resource writes and output, or undefined for a run without one. */
|
|
279
|
-
readonly run: RunRecord | undefined;
|
|
280
265
|
}
|
|
281
266
|
|
|
282
267
|
/**
|
|
@@ -452,22 +437,7 @@ export const makeConvexState = (options: StoreOptions) =>
|
|
|
452
437
|
|
|
453
438
|
yield* ensureSealed(options, deployment, functions);
|
|
454
439
|
|
|
455
|
-
const remote = remoteOf(functions
|
|
456
|
-
/** The stack's output plus the record, when the run has one and the output has a place for it. */
|
|
457
|
-
const documentOf = (request: { stack: string; stage: string; value: unknown }) =>
|
|
458
|
-
Effect.gen(function* () {
|
|
459
|
-
const { run } = options;
|
|
460
|
-
if (run === undefined) return request.value;
|
|
461
|
-
const recordedAt = new Date(yield* Clock.currentTimeMillis).toISOString();
|
|
462
|
-
const document = withRunRecord(request.value, { ...run, recordedAt });
|
|
463
|
-
if (document === undefined) {
|
|
464
|
-
yield* Effect.logWarning(
|
|
465
|
-
`Convex state: the output of ${request.stack}/${request.stage} is not a plain object, so it carries no run record.`,
|
|
466
|
-
);
|
|
467
|
-
return request.value;
|
|
468
|
-
}
|
|
469
|
-
return document;
|
|
470
|
-
});
|
|
440
|
+
const remote = remoteOf(functions);
|
|
471
441
|
const service: StateService = {
|
|
472
442
|
id: "convex",
|
|
473
443
|
getVersion: () => Effect.succeed(STATE_STORE_VERSION),
|
|
@@ -480,13 +450,7 @@ export const makeConvexState = (options: StoreOptions) =>
|
|
|
480
450
|
set: (request) => remote.set(request).pipe(Effect.as(request.value)),
|
|
481
451
|
delete: (request) => remote.delete(request).pipe(Effect.asVoid),
|
|
482
452
|
deleteStack: (request) => remote.deleteStack(request).pipe(Effect.asVoid),
|
|
483
|
-
|
|
484
|
-
setOutput: (request) =>
|
|
485
|
-
Effect.gen(function* () {
|
|
486
|
-
const value = yield* documentOf(request);
|
|
487
|
-
yield* remote.setOutput({ stack: request.stack, stage: request.stage, value });
|
|
488
|
-
return value;
|
|
489
|
-
}),
|
|
453
|
+
setOutput: (request) => remote.setOutput(request).pipe(Effect.as(request.value)),
|
|
490
454
|
};
|
|
491
455
|
return service;
|
|
492
456
|
});
|
|
@@ -511,25 +475,7 @@ export const state = (): Layer.Layer<State, never, ChildProcessSpawner.ChildProc
|
|
|
511
475
|
const api = yield* ManagementApi.pipe(
|
|
512
476
|
Effect.provide(ManagementApiLive().pipe(Layer.provide(fromConfig()))),
|
|
513
477
|
);
|
|
514
|
-
|
|
515
|
-
// that gives none, such as a tarball without git, a checkout
|
|
516
|
-
// without origin, or a detached HEAD, still reads, plans, and
|
|
517
|
-
// destroys: its outputs are written without the record, and the
|
|
518
|
-
// log says why.
|
|
519
|
-
const run = yield* runRecord({ cwd: process.cwd(), env: process.env }).pipe(
|
|
520
|
-
Effect.catch((error) =>
|
|
521
|
-
Effect.logWarning(
|
|
522
|
-
`Convex state: the stage outputs of this run carry no record. ${error.message}`,
|
|
523
|
-
).pipe(Effect.as(undefined)),
|
|
524
|
-
),
|
|
525
|
-
);
|
|
526
|
-
return yield* makeConvexState({
|
|
527
|
-
api,
|
|
528
|
-
spawner,
|
|
529
|
-
scope,
|
|
530
|
-
store: storeDirectory(),
|
|
531
|
-
run,
|
|
532
|
-
});
|
|
478
|
+
return yield* makeConvexState({ api, spawner, scope, store: storeDirectory() });
|
|
533
479
|
}).pipe(Effect.provideContext(context), Effect.orDie),
|
|
534
480
|
);
|
|
535
481
|
}),
|
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
|
|
11
11
|
import type * as keys from "../keys.js";
|
|
12
12
|
import type * as reader from "../reader.js";
|
|
13
|
-
import type * as runRecord from "../runRecord.js";
|
|
14
13
|
import type * as state from "../state.js";
|
|
15
14
|
|
|
16
15
|
import type {
|
|
@@ -23,7 +22,6 @@ import { anyApi, componentsGeneric } from "convex/server";
|
|
|
23
22
|
const fullApi: ApiFromModules<{
|
|
24
23
|
keys: typeof keys;
|
|
25
24
|
reader: typeof reader;
|
|
26
|
-
runRecord: typeof runRecord;
|
|
27
25
|
state: typeof state;
|
|
28
26
|
}> = anyApi as any;
|
|
29
27
|
|
|
@@ -62,20 +62,8 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
|
|
|
62
62
|
stacks: Array<{
|
|
63
63
|
name: string;
|
|
64
64
|
stages: Array<{
|
|
65
|
-
deployedHeadCommit: string | null;
|
|
66
65
|
name: string;
|
|
67
|
-
output: string;
|
|
68
|
-
record: {
|
|
69
|
-
branch: string;
|
|
70
|
-
headCommit: string;
|
|
71
|
-
pullRequest: number | null;
|
|
72
|
-
recordedAt: string;
|
|
73
|
-
repository: string;
|
|
74
|
-
runUrl: string | null;
|
|
75
|
-
source: "github-actions" | "checkout";
|
|
76
|
-
stackFile: string;
|
|
77
|
-
version: 1;
|
|
78
|
-
};
|
|
66
|
+
output: string | null;
|
|
79
67
|
resources: Array<{ fqn: string; value: string }>;
|
|
80
68
|
}>;
|
|
81
69
|
}>;
|
|
@@ -123,20 +111,9 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
|
|
|
123
111
|
{ stack: string },
|
|
124
112
|
{
|
|
125
113
|
stages: Array<{
|
|
114
|
+
name: string;
|
|
126
115
|
output: string | null;
|
|
127
|
-
record: {
|
|
128
|
-
branch: string;
|
|
129
|
-
headCommit: string;
|
|
130
|
-
pullRequest: number | null;
|
|
131
|
-
recordedAt: string;
|
|
132
|
-
repository: string;
|
|
133
|
-
runUrl: string | null;
|
|
134
|
-
source: "github-actions" | "checkout";
|
|
135
|
-
stackFile: string;
|
|
136
|
-
version: 1;
|
|
137
|
-
} | null;
|
|
138
116
|
resources: Array<{ fqn: string; value: string }>;
|
|
139
|
-
stage: string;
|
|
140
117
|
}>;
|
|
141
118
|
},
|
|
142
119
|
Name
|
|
@@ -144,22 +121,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
|
|
|
144
121
|
remove: FunctionReference<
|
|
145
122
|
"mutation",
|
|
146
123
|
"internal",
|
|
147
|
-
{
|
|
148
|
-
fqn: string;
|
|
149
|
-
run: {
|
|
150
|
-
branch: string;
|
|
151
|
-
headCommit: string;
|
|
152
|
-
pullRequest: number | null;
|
|
153
|
-
recordedAt: string;
|
|
154
|
-
repository: string;
|
|
155
|
-
runUrl: string | null;
|
|
156
|
-
source: "github-actions" | "checkout";
|
|
157
|
-
stackFile: string;
|
|
158
|
-
version: 1;
|
|
159
|
-
} | null;
|
|
160
|
-
stack: string;
|
|
161
|
-
stage: string;
|
|
162
|
-
},
|
|
124
|
+
{ fqn: string; stack: string; stage: string },
|
|
163
125
|
null,
|
|
164
126
|
Name
|
|
165
127
|
>;
|
|
@@ -223,45 +185,14 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
|
|
|
223
185
|
set: FunctionReference<
|
|
224
186
|
"mutation",
|
|
225
187
|
"internal",
|
|
226
|
-
{
|
|
227
|
-
fqn: string;
|
|
228
|
-
run: {
|
|
229
|
-
branch: string;
|
|
230
|
-
headCommit: string;
|
|
231
|
-
pullRequest: number | null;
|
|
232
|
-
recordedAt: string;
|
|
233
|
-
repository: string;
|
|
234
|
-
runUrl: string | null;
|
|
235
|
-
source: "github-actions" | "checkout";
|
|
236
|
-
stackFile: string;
|
|
237
|
-
version: 1;
|
|
238
|
-
} | null;
|
|
239
|
-
stack: string;
|
|
240
|
-
stage: string;
|
|
241
|
-
value: string;
|
|
242
|
-
},
|
|
188
|
+
{ fqn: string; stack: string; stage: string; value: string },
|
|
243
189
|
null,
|
|
244
190
|
Name
|
|
245
191
|
>;
|
|
246
192
|
setOutput: FunctionReference<
|
|
247
193
|
"mutation",
|
|
248
194
|
"internal",
|
|
249
|
-
{
|
|
250
|
-
run: {
|
|
251
|
-
branch: string;
|
|
252
|
-
headCommit: string;
|
|
253
|
-
pullRequest: number | null;
|
|
254
|
-
recordedAt: string;
|
|
255
|
-
repository: string;
|
|
256
|
-
runUrl: string | null;
|
|
257
|
-
source: "github-actions" | "checkout";
|
|
258
|
-
stackFile: string;
|
|
259
|
-
version: 1;
|
|
260
|
-
} | null;
|
|
261
|
-
stack: string;
|
|
262
|
-
stage: string;
|
|
263
|
-
value: string;
|
|
264
|
-
},
|
|
195
|
+
{ stack: string; stage: string; value: string },
|
|
265
196
|
null,
|
|
266
197
|
Name
|
|
267
198
|
>;
|
|
@@ -1,35 +1,36 @@
|
|
|
1
1
|
// The redacted read of one repository. The app checks the reader's verified
|
|
2
2
|
// token and passes the repository that the token names: a component has no
|
|
3
|
-
// `ctx.auth`.
|
|
4
|
-
|
|
3
|
+
// `ctx.auth`. The reply is Alchemy state only, in the stage shape of
|
|
4
|
+
// `readStack`: the reader takes anything else, such as a run record, from the
|
|
5
|
+
// outputs.
|
|
6
|
+
import { v } from "convex/values";
|
|
5
7
|
// oxlint-disable-next-line samebase/no-raw-public-convex-function-builders -- Store entrypoints have no app wrapper; the reader and the deploy key enforce access.
|
|
6
8
|
import { query } from "./_generated/server.js";
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
const stage = v.object({
|
|
10
|
-
name: v.string(),
|
|
11
|
-
record: runRecord,
|
|
12
|
-
deployedHeadCommit: v.union(v.string(), v.null()),
|
|
13
|
-
resources: v.array(v.object({ fqn: v.string(), value: v.string() })),
|
|
14
|
-
output: v.string(),
|
|
15
|
-
});
|
|
9
|
+
import { storedStage } from "./state.ts";
|
|
16
10
|
|
|
17
11
|
/** The reply of {@link repository}. */
|
|
18
12
|
export const repositoryReply = v.object({
|
|
19
13
|
store: v.literal("found"),
|
|
20
|
-
stacks: v.array(v.object({ name: v.string(), stages: v.array(
|
|
14
|
+
stacks: v.array(v.object({ name: v.string(), stages: v.array(storedStage) })),
|
|
21
15
|
});
|
|
22
16
|
|
|
23
17
|
/** Alchemy encodes a secret as an object with __redacted__; discard that whole object's contents. */
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
18
|
+
const withoutSecrets = (text: string) =>
|
|
19
|
+
JSON.stringify(
|
|
20
|
+
JSON.parse(text, (_key, value: unknown) =>
|
|
21
|
+
typeof value === "object" && value !== null && "__redacted__" in value
|
|
22
|
+
? { __redacted__: null }
|
|
23
|
+
: value,
|
|
24
|
+
),
|
|
29
25
|
);
|
|
30
|
-
}
|
|
31
26
|
|
|
32
|
-
|
|
27
|
+
const byName = <T extends { name: string }>(a: T, b: T) =>
|
|
28
|
+
a.name < b.name ? -1 : a.name > b.name ? 1 : 0;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The stacks of `repository`: the stack of that name and the stacks below `repository + "/"`, each
|
|
32
|
+
* with every stage that has a resource or an output, in name order. Resources stay in fqn order.
|
|
33
|
+
*/
|
|
33
34
|
export const repository = query({
|
|
34
35
|
args: { repository: v.string() },
|
|
35
36
|
returns: repositoryReply,
|
|
@@ -55,51 +56,41 @@ export const repository = query({
|
|
|
55
56
|
.withIndex("by_stage", (q) => q.gte("stack", `${name}/`).lt("stack", `${name}0`))
|
|
56
57
|
.collect(),
|
|
57
58
|
]);
|
|
58
|
-
const stacks = new Map<
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
let stages = stacks.get(row.stack);
|
|
59
|
+
const stacks = new Map<
|
|
60
|
+
string,
|
|
61
|
+
Map<
|
|
62
|
+
string,
|
|
63
|
+
{ name: string; resources: { fqn: string; value: string }[]; output: string | null }
|
|
64
|
+
>
|
|
65
|
+
>();
|
|
66
|
+
const stageOf = (stack: string, stage: string) => {
|
|
67
|
+
let stages = stacks.get(stack);
|
|
69
68
|
if (stages === undefined) {
|
|
70
69
|
stages = new Map();
|
|
71
|
-
stacks.set(
|
|
70
|
+
stacks.set(stack, stages);
|
|
72
71
|
}
|
|
73
|
-
stages.
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
72
|
+
let found = stages.get(stage);
|
|
73
|
+
if (found === undefined) {
|
|
74
|
+
found = { name: stage, resources: [], output: null };
|
|
75
|
+
stages.set(stage, found);
|
|
76
|
+
}
|
|
77
|
+
return found;
|
|
78
|
+
};
|
|
79
|
+
for (const row of [...rootResources, ...childResources]) {
|
|
80
|
+
stageOf(row.stack, row.stage).resources.push({
|
|
81
|
+
fqn: row.fqn,
|
|
82
|
+
value: withoutSecrets(row.value),
|
|
82
83
|
});
|
|
83
84
|
}
|
|
84
|
-
for (const row of [...
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
?.get(row.stage)
|
|
88
|
-
?.resources.push({
|
|
89
|
-
fqn: row.fqn,
|
|
90
|
-
value: JSON.stringify(withoutSecrets(row.value)),
|
|
91
|
-
});
|
|
85
|
+
for (const row of [...rootOutputs, ...childOutputs]) {
|
|
86
|
+
const stage = stageOf(row.stack, row.stage);
|
|
87
|
+
if (row.value !== undefined) stage.output = withoutSecrets(row.value);
|
|
92
88
|
}
|
|
93
89
|
return {
|
|
94
90
|
store: "found" as const,
|
|
95
91
|
stacks: [...stacks]
|
|
96
|
-
.
|
|
97
|
-
.
|
|
98
|
-
name,
|
|
99
|
-
stages: [...stages.values()].sort((a, b) =>
|
|
100
|
-
a.name < b.name ? -1 : a.name > b.name ? 1 : 0,
|
|
101
|
-
),
|
|
102
|
-
})),
|
|
92
|
+
.map(([stack, stages]) => ({ name: stack, stages: [...stages.values()].sort(byName) }))
|
|
93
|
+
.sort(byName),
|
|
103
94
|
};
|
|
104
95
|
},
|
|
105
96
|
});
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { defineSchema, defineTable } from "convex/server";
|
|
2
2
|
import { v } from "convex/values";
|
|
3
|
-
import { runRecord } from "./runRecord.ts";
|
|
4
3
|
|
|
5
4
|
// `value` is the JSON text of Alchemy's encodeState(...): the same text that
|
|
6
5
|
// Alchemy's local state writes to a file. A Convex object would reject keys
|
|
@@ -15,8 +14,11 @@ export default defineSchema({
|
|
|
15
14
|
outputs: defineTable({
|
|
16
15
|
stack: v.string(),
|
|
17
16
|
stage: v.string(),
|
|
17
|
+
// Store version 6 and older wrote `currentRun` on each resource write, and an output row that
|
|
18
|
+
// had only that field had no `value`. Nothing reads or writes `currentRun` now. A push checks
|
|
19
|
+
// every row against this schema, so both declarations stay for the rows of an older store.
|
|
18
20
|
value: v.optional(v.string()),
|
|
19
|
-
currentRun: v.optional(
|
|
21
|
+
currentRun: v.optional(v.any()),
|
|
20
22
|
}).index("by_stage", ["stack", "stage"]),
|
|
21
23
|
// One row: the key that seals new secrets, the count of its rotations, and the last count for
|
|
22
24
|
// which a reseal finished.
|