@samebase/alchemy-convex 0.11.0 → 0.13.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@samebase/alchemy-convex",
3
- "version": "0.11.0",
3
+ "version": "0.13.0",
4
4
  "description": "The Convex plane for Alchemy v2: projects, deployments, environment variables, and the push of the functions",
5
5
  "keywords": [
6
6
  "alchemy",
@@ -31,6 +31,10 @@
31
31
  ".": {
32
32
  "types": "./lib/index.d.ts",
33
33
  "import": "./lib/index.js"
34
+ },
35
+ "./state/convex.config": {
36
+ "types": "./src/store/component/convex.config.ts",
37
+ "default": "./src/store/component/convex.config.ts"
34
38
  }
35
39
  },
36
40
  "publishConfig": {
package/src/State.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  // Alchemy state in Convex: `state: Convex.state({ team })` in `Alchemy.Stack`.
2
2
  //
3
- // One project for each Convex team, `alchemy-state`, holds the state of
3
+ // One project for each Convex team, `samebase`, holds the state of
4
4
  // every stack and stage of the team in its production deployment: the
5
5
  // tables `resources (stack, stage, fqn, value)` and `outputs (stack, stage,
6
- // value)`, served by the functions of src/store/convex. The store lives
6
+ // value)` of the alchemyState component (src/store/component), served by the
7
+ // functions of src/store/convex. The store lives
7
8
  // outside every resource that a stack manages, so a stack can create and
8
9
  // destroy its own project. See docs/design/convex-state.md.
9
10
  //
@@ -18,7 +19,7 @@
18
19
  // repository-scoped subscriptions with secret values removed. A key that stops working during a
19
20
  // long run (it expires after two hours) is replaced once per call.
20
21
  //
21
- // Two first runs of a team can both create a project named `alchemy-state`.
22
+ // Two first runs of a team can both create a project named `samebase`.
22
23
  // The run whose project is not the oldest deletes its own, before it writes
23
24
  // anything, and uses the oldest: both runs end on one store.
24
25
  //
@@ -79,7 +80,7 @@ import { type RunRecord, runRecord, withRunRecord } from "./RunRecord.ts";
79
80
  import { STORE_VERSION } from "./store/convex/version.ts";
80
81
 
81
82
  /** The name of the state project in each team. */
82
- export const STORE_PROJECT_NAME = "alchemy-state";
83
+ export const STORE_PROJECT_NAME = "samebase";
83
84
 
84
85
  /**
85
86
  * The actions of the key of one run: the internal queries and mutations of
@@ -244,13 +245,14 @@ const storeVersion = (api: FunctionApi) =>
244
245
  * The functions directory of the store app, `src/store/convex` of this
245
246
  * package. This file is `src/State.ts` in a checkout and a chunk in `lib/`
246
247
  * in the installed package, which ships `src` too, so the directory is
247
- * `../src/store/convex` from either place.
248
+ * `../src/store/convex` from either place. Its `convex.config.ts` mounts the
249
+ * alchemyState component of `src/store/component`, inside the same push root.
248
250
  */
249
251
  export const storeDirectory = () =>
250
252
  join(dirname(fileURLToPath(import.meta.url)), "..", "src", "store", "convex");
251
253
 
252
254
  export interface StoreOptions {
253
- /** Team slug or numeric team id of the `alchemy-state` project, or undefined with a team access token, which names its team. */
255
+ /** Team slug or numeric team id of the `samebase` project, or undefined with a team access token, which names its team. */
254
256
  readonly team: string | number | undefined;
255
257
  readonly api: ManagementApiService;
256
258
  readonly spawner: ChildProcessSpawner.ChildProcessSpawner["Service"];
@@ -327,7 +329,7 @@ const createStoreProject = (api: ManagementApiService, teamId: number, team: str
327
329
  });
328
330
 
329
331
  /**
330
- * The StateService over the `alchemy-state` project of the team: found or
332
+ * The StateService over the `samebase` project of the team: found or
331
333
  * created, its store pushed when it is missing or older, and read and
332
334
  * written with the keys of this run.
333
335
  */
@@ -355,7 +357,7 @@ export const makeConvexState = (options: StoreOptions) =>
355
357
  }),
356
358
  ),
357
359
  );
358
- const mint = createDeployKey(api, deployment.name, "alchemy-state", RUN_KEY_ACTIONS).pipe(
360
+ const mint = createDeployKey(api, deployment.name, STORE_PROJECT_NAME, RUN_KEY_ACTIONS).pipe(
359
361
  Effect.map((key) => {
360
362
  keys.push(key);
361
363
  return makeFunctionApi(deployment.deploymentUrl, key);
@@ -439,7 +441,7 @@ export const makeConvexState = (options: StoreOptions) =>
439
441
  });
440
442
 
441
443
  /**
442
- * Alchemy state in the `alchemy-state` project of `team`, with the team token
444
+ * Alchemy state in the `samebase` project of `team`, with the team token
443
445
  * in CONVEX_ACCESS_TOKEN or the Convex CLI login. A team access token names
444
446
  * its team, so `team` is optional with one; the Convex CLI login needs the
445
447
  * slug or the id. The first use of the run finds or creates the project and
@@ -0,0 +1,54 @@
1
+ /* eslint-disable */
2
+ /**
3
+ * Generated `api` utility.
4
+ *
5
+ * THIS CODE IS AUTOMATICALLY GENERATED.
6
+ *
7
+ * To regenerate, run `npx convex dev`.
8
+ * @module
9
+ */
10
+
11
+ import type * as reader from "../reader.js";
12
+ import type * as runRecord from "../runRecord.js";
13
+ import type * as state from "../state.js";
14
+
15
+ import type {
16
+ ApiFromModules,
17
+ FilterApi,
18
+ FunctionReference,
19
+ } from "convex/server";
20
+ import { anyApi, componentsGeneric } from "convex/server";
21
+
22
+ const fullApi: ApiFromModules<{
23
+ reader: typeof reader;
24
+ runRecord: typeof runRecord;
25
+ state: typeof state;
26
+ }> = anyApi as any;
27
+
28
+ /**
29
+ * A utility for referencing Convex functions in your app's public API.
30
+ *
31
+ * Usage:
32
+ * ```js
33
+ * const myFunctionReference = api.myModule.myFunction;
34
+ * ```
35
+ */
36
+ export const api: FilterApi<
37
+ typeof fullApi,
38
+ FunctionReference<any, "public">
39
+ > = anyApi as any;
40
+
41
+ /**
42
+ * A utility for referencing Convex functions in your app's internal API.
43
+ *
44
+ * Usage:
45
+ * ```js
46
+ * const myFunctionReference = internal.myModule.myFunction;
47
+ * ```
48
+ */
49
+ export const internal: FilterApi<
50
+ typeof fullApi,
51
+ FunctionReference<any, "internal">
52
+ > = anyApi as any;
53
+
54
+ export const components = componentsGeneric() as unknown as {};
@@ -0,0 +1,193 @@
1
+ /* eslint-disable */
2
+ /**
3
+ * Generated `ComponentApi` utility.
4
+ *
5
+ * THIS CODE IS AUTOMATICALLY GENERATED.
6
+ *
7
+ * To regenerate, run `npx convex dev`.
8
+ * @module
9
+ */
10
+
11
+ import type { FunctionReference } from "convex/server";
12
+
13
+ /**
14
+ * A utility for referencing a Convex component's exposed API.
15
+ *
16
+ * Useful when expecting a parameter like `components.myComponent`.
17
+ * Usage:
18
+ * ```ts
19
+ * async function myFunction(ctx: QueryCtx, component: ComponentApi) {
20
+ * return ctx.runQuery(component.someFile.someQuery, { ...args });
21
+ * }
22
+ * ```
23
+ */
24
+ export type ComponentApi<Name extends string | undefined = string | undefined> =
25
+ {
26
+ reader: {
27
+ repository: FunctionReference<
28
+ "query",
29
+ "internal",
30
+ { repository: string },
31
+ {
32
+ stacks: Array<{
33
+ name: string;
34
+ stages: Array<{
35
+ deployedHeadCommit: string | null;
36
+ name: string;
37
+ output: string;
38
+ record: {
39
+ branch: string;
40
+ headCommit: string;
41
+ pullRequest: number | null;
42
+ recordedAt: string;
43
+ repository: string;
44
+ runUrl: string | null;
45
+ source: "github-actions" | "laptop";
46
+ stackFile: string;
47
+ version: 1;
48
+ };
49
+ resources: Array<{ fqn: string; value: string }>;
50
+ }>;
51
+ }>;
52
+ store: "found";
53
+ },
54
+ Name
55
+ >;
56
+ };
57
+ state: {
58
+ get: FunctionReference<
59
+ "query",
60
+ "internal",
61
+ { fqn: string; stack: string; stage: string },
62
+ string | null,
63
+ Name
64
+ >;
65
+ getOutput: FunctionReference<
66
+ "query",
67
+ "internal",
68
+ { stack: string; stage: string },
69
+ string | null,
70
+ Name
71
+ >;
72
+ list: FunctionReference<
73
+ "query",
74
+ "internal",
75
+ { stack: string; stage: string },
76
+ Array<string>,
77
+ Name
78
+ >;
79
+ readStack: FunctionReference<
80
+ "query",
81
+ "internal",
82
+ { stack: string },
83
+ {
84
+ stages: Array<{
85
+ output: string | null;
86
+ record: {
87
+ branch: string;
88
+ headCommit: string;
89
+ pullRequest: number | null;
90
+ recordedAt: string;
91
+ repository: string;
92
+ runUrl: string | null;
93
+ source: "github-actions" | "laptop";
94
+ stackFile: string;
95
+ version: 1;
96
+ } | null;
97
+ resources: Array<{ fqn: string; value: string }>;
98
+ stage: string;
99
+ }>;
100
+ },
101
+ Name
102
+ >;
103
+ remove: FunctionReference<
104
+ "mutation",
105
+ "internal",
106
+ {
107
+ fqn: string;
108
+ run: {
109
+ branch: string;
110
+ headCommit: string;
111
+ pullRequest: number | null;
112
+ recordedAt: string;
113
+ repository: string;
114
+ runUrl: string | null;
115
+ source: "github-actions" | "laptop";
116
+ stackFile: string;
117
+ version: 1;
118
+ } | null;
119
+ stack: string;
120
+ stage: string;
121
+ },
122
+ null,
123
+ Name
124
+ >;
125
+ removeStack: FunctionReference<
126
+ "mutation",
127
+ "internal",
128
+ { stack: string; stage: string | null },
129
+ null,
130
+ Name
131
+ >;
132
+ replaced: FunctionReference<
133
+ "query",
134
+ "internal",
135
+ { stack: string; stage: string },
136
+ Array<string>,
137
+ Name
138
+ >;
139
+ set: FunctionReference<
140
+ "mutation",
141
+ "internal",
142
+ {
143
+ fqn: string;
144
+ run: {
145
+ branch: string;
146
+ headCommit: string;
147
+ pullRequest: number | null;
148
+ recordedAt: string;
149
+ repository: string;
150
+ runUrl: string | null;
151
+ source: "github-actions" | "laptop";
152
+ stackFile: string;
153
+ version: 1;
154
+ } | null;
155
+ stack: string;
156
+ stage: string;
157
+ value: string;
158
+ },
159
+ null,
160
+ Name
161
+ >;
162
+ setOutput: FunctionReference<
163
+ "mutation",
164
+ "internal",
165
+ {
166
+ run: {
167
+ branch: string;
168
+ headCommit: string;
169
+ pullRequest: number | null;
170
+ recordedAt: string;
171
+ repository: string;
172
+ runUrl: string | null;
173
+ source: "github-actions" | "laptop";
174
+ stackFile: string;
175
+ version: 1;
176
+ } | null;
177
+ stack: string;
178
+ stage: string;
179
+ value: string;
180
+ },
181
+ null,
182
+ Name
183
+ >;
184
+ stacks: FunctionReference<"query", "internal", {}, Array<string>, Name>;
185
+ stages: FunctionReference<
186
+ "query",
187
+ "internal",
188
+ { stack: string },
189
+ Array<string>,
190
+ Name
191
+ >;
192
+ };
193
+ };
@@ -0,0 +1,60 @@
1
+ /* eslint-disable */
2
+ /**
3
+ * Generated data model types.
4
+ *
5
+ * THIS CODE IS AUTOMATICALLY GENERATED.
6
+ *
7
+ * To regenerate, run `npx convex dev`.
8
+ * @module
9
+ */
10
+
11
+ import type {
12
+ DataModelFromSchemaDefinition,
13
+ DocumentByName,
14
+ TableNamesInDataModel,
15
+ SystemTableNames,
16
+ } from "convex/server";
17
+ import type { GenericId } from "convex/values";
18
+ import schema from "../schema.js";
19
+
20
+ /**
21
+ * The names of all of your Convex tables.
22
+ */
23
+ export type TableNames = TableNamesInDataModel<DataModel>;
24
+
25
+ /**
26
+ * The type of a document stored in Convex.
27
+ *
28
+ * @typeParam TableName - A string literal type of the table name (like "users").
29
+ */
30
+ export type Doc<TableName extends TableNames> = DocumentByName<
31
+ DataModel,
32
+ TableName
33
+ >;
34
+
35
+ /**
36
+ * An identifier for a document in Convex.
37
+ *
38
+ * Convex documents are uniquely identified by their `Id`, which is accessible
39
+ * on the `_id` field. To learn more, see [Document IDs](https://docs.convex.dev/using/document-ids).
40
+ *
41
+ * Documents can be loaded using `db.get(tableName, id)` in query and mutation functions.
42
+ *
43
+ * IDs are just strings at runtime, but this type can be used to distinguish them from other
44
+ * strings when type checking.
45
+ *
46
+ * @typeParam TableName - A string literal type of the table name (like "users").
47
+ */
48
+ export type Id<TableName extends TableNames | SystemTableNames> =
49
+ GenericId<TableName>;
50
+
51
+ /**
52
+ * A type describing your Convex data model.
53
+ *
54
+ * This type includes information about what tables you have, the type of
55
+ * documents stored in those tables, and the indexes defined on them.
56
+ *
57
+ * This type is used to parameterize methods like `queryGeneric` and
58
+ * `mutationGeneric` to make them type-safe.
59
+ */
60
+ export type DataModel = DataModelFromSchemaDefinition<typeof schema>;
@@ -0,0 +1,169 @@
1
+ /* eslint-disable */
2
+ /**
3
+ * Generated utilities for implementing server-side Convex query and mutation functions.
4
+ *
5
+ * THIS CODE IS AUTOMATICALLY GENERATED.
6
+ *
7
+ * To regenerate, run `npx convex dev`.
8
+ * @module
9
+ */
10
+
11
+ import type {
12
+ ActionBuilder,
13
+ HttpActionBuilder,
14
+ MutationBuilder,
15
+ QueryBuilder,
16
+ GenericActionCtx,
17
+ GenericMutationCtx,
18
+ GenericQueryCtx,
19
+ GenericDatabaseReader,
20
+ GenericDatabaseWriter,
21
+ } from "convex/server";
22
+ import {
23
+ actionGeneric,
24
+ httpActionGeneric,
25
+ queryGeneric,
26
+ mutationGeneric,
27
+ internalActionGeneric,
28
+ internalMutationGeneric,
29
+ internalQueryGeneric,
30
+ } from "convex/server";
31
+ import type { DataModel } from "./dataModel.js";
32
+
33
+ /**
34
+ * Typesafe environment variables.
35
+ *
36
+ * This includes platform-provided env vars and any variables declared in
37
+ * `convex.config.ts`.
38
+ */
39
+ type Env = {
40
+ readonly CONVEX_CLOUD_URL: string;
41
+ readonly CONVEX_SITE_URL: string;
42
+ };
43
+
44
+ /**
45
+ * Define a query in this Convex app's public API.
46
+ *
47
+ * This function will be allowed to read your Convex database and will be accessible from the client.
48
+ *
49
+ * @param func - The query function. It receives a {@link QueryCtx} as its first argument.
50
+ * @returns The wrapped query. Include this as an `export` to name it and make it accessible.
51
+ */
52
+ export const query: QueryBuilder<DataModel, "public"> = queryGeneric;
53
+
54
+ /**
55
+ * Define a query that is only accessible from other Convex functions (but not from the client).
56
+ *
57
+ * This function will be allowed to read from your Convex database. It will not be accessible from the client.
58
+ *
59
+ * @param func - The query function. It receives a {@link QueryCtx} as its first argument.
60
+ * @returns The wrapped query. Include this as an `export` to name it and make it accessible.
61
+ */
62
+ export const internalQuery: QueryBuilder<DataModel, "internal"> =
63
+ internalQueryGeneric;
64
+
65
+ /**
66
+ * Define a mutation in this Convex app's public API.
67
+ *
68
+ * This function will be allowed to modify your Convex database and will be accessible from the client.
69
+ *
70
+ * @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
71
+ * @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
72
+ */
73
+ export const mutation: MutationBuilder<DataModel, "public"> = mutationGeneric;
74
+
75
+ /**
76
+ * Define a mutation that is only accessible from other Convex functions (but not from the client).
77
+ *
78
+ * This function will be allowed to modify your Convex database. It will not be accessible from the client.
79
+ *
80
+ * @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
81
+ * @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
82
+ */
83
+ export const internalMutation: MutationBuilder<DataModel, "internal"> =
84
+ internalMutationGeneric;
85
+
86
+ /**
87
+ * Define an action in this Convex app's public API.
88
+ *
89
+ * An action is a function which can execute any JavaScript code, including non-deterministic
90
+ * code and code with side-effects, like calling third-party services.
91
+ * They can be run in Convex's JavaScript environment or in Node.js using the "use node" directive.
92
+ * They can interact with the database indirectly by calling queries and mutations using the {@link ActionCtx}.
93
+ *
94
+ * @param func - The action. It receives an {@link ActionCtx} as its first argument.
95
+ * @returns The wrapped action. Include this as an `export` to name it and make it accessible.
96
+ */
97
+ export const action: ActionBuilder<DataModel, "public"> = actionGeneric;
98
+
99
+ /**
100
+ * Define an action that is only accessible from other Convex functions (but not from the client).
101
+ *
102
+ * @param func - The function. It receives an {@link ActionCtx} as its first argument.
103
+ * @returns The wrapped function. Include this as an `export` to name it and make it accessible.
104
+ */
105
+ export const internalAction: ActionBuilder<DataModel, "internal"> =
106
+ internalActionGeneric;
107
+
108
+ /**
109
+ * Define an HTTP action.
110
+ *
111
+ * The wrapped function will be used to respond to HTTP requests received
112
+ * by a Convex deployment if the requests matches the path and method where
113
+ * this action is routed. Be sure to route your httpAction in `convex/http.js`.
114
+ *
115
+ * @param func - The function. It receives an {@link ActionCtx} as its first argument
116
+ * and a Fetch API `Request` object as its second.
117
+ * @returns The wrapped function. Import this function from `convex/http.js` and route it to hook it up.
118
+ */
119
+ export const httpAction: HttpActionBuilder = httpActionGeneric;
120
+ export const env: Env = (globalThis as unknown as { process: { env: Env } })
121
+ .process.env;
122
+
123
+ /**
124
+ * A set of services for use within Convex query functions.
125
+ *
126
+ * The query context is passed as the first argument to any Convex query
127
+ * function run on the server.
128
+ *
129
+ * If you're using code generation, use the `QueryCtx` type in `convex/_generated/server.d.ts` instead.
130
+ */
131
+ export type QueryCtx = GenericQueryCtx<DataModel>;
132
+
133
+ /**
134
+ * A set of services for use within Convex mutation functions.
135
+ *
136
+ * The mutation context is passed as the first argument to any Convex mutation
137
+ * function run on the server.
138
+ *
139
+ * If you're using code generation, use the `MutationCtx` type in `convex/_generated/server.d.ts` instead.
140
+ */
141
+ export type MutationCtx = GenericMutationCtx<DataModel>;
142
+
143
+ /**
144
+ * A set of services for use within Convex action functions.
145
+ *
146
+ * The action context is passed as the first argument to any Convex action
147
+ * function run on the server.
148
+ */
149
+ export type ActionCtx = GenericActionCtx<DataModel>;
150
+
151
+ /**
152
+ * An interface to read from the database within Convex query functions.
153
+ *
154
+ * The two entry points are {@link DatabaseReader.get}, which fetches a single
155
+ * document by its {@link Id}, or {@link DatabaseReader.query}, which starts
156
+ * building a query.
157
+ */
158
+ export type DatabaseReader = GenericDatabaseReader<DataModel>;
159
+
160
+ /**
161
+ * An interface to read from and write to the database within Convex mutation
162
+ * functions.
163
+ *
164
+ * Convex guarantees that all writes within a single mutation are
165
+ * executed atomically, so you never have to worry about partial writes leaving
166
+ * your data in an inconsistent state. See [the Convex Guide](https://docs.convex.dev/understanding/convex-fundamentals/functions#atomicity-and-optimistic-concurrency-control)
167
+ * for the guarantees Convex provides your functions.
168
+ */
169
+ export type DatabaseWriter = GenericDatabaseWriter<DataModel>;
@@ -0,0 +1,3 @@
1
+ import { defineComponent } from "convex/server";
2
+
3
+ export default defineComponent("alchemyState");
@@ -0,0 +1,104 @@
1
+ // The redacted read of one repository. The app checks the reader's verified
2
+ // token and passes the repository that the token names: a component has no
3
+ // `ctx.auth`.
4
+ import { v, type Infer } from "convex/values";
5
+ import { query } from "./_generated/server.js";
6
+ import { runRecord, validate } from "./runRecord.ts";
7
+
8
+ const stage = v.object({
9
+ name: v.string(),
10
+ record: runRecord,
11
+ deployedHeadCommit: v.union(v.string(), v.null()),
12
+ resources: v.array(v.object({ fqn: v.string(), value: v.string() })),
13
+ output: v.string(),
14
+ });
15
+
16
+ /** The reply of {@link repository}. */
17
+ export const repositoryReply = v.object({
18
+ store: v.literal("found"),
19
+ stacks: v.array(v.object({ name: v.string(), stages: v.array(stage) })),
20
+ });
21
+
22
+ /** Alchemy encodes a secret as an object with __redacted__; discard that whole object's contents. */
23
+ function withoutSecrets(text: string): unknown {
24
+ return JSON.parse(text, (_key, value: unknown) =>
25
+ typeof value === "object" && value !== null && "__redacted__" in value
26
+ ? { __redacted__: null }
27
+ : value,
28
+ );
29
+ }
30
+
31
+ /** The stacks of `repository`: the stack of that name and the stacks below `repository + "/"`. */
32
+ export const repository = query({
33
+ args: { repository: v.string() },
34
+ returns: repositoryReply,
35
+ handler: async (ctx, args) => {
36
+ const name = args.repository;
37
+ // The exact name and its slash-prefixed children exclude names such as owner/app-other.
38
+ // All four reads share the query transaction, including writes made while provisioning.
39
+ const [rootResources, childResources, rootOutputs, childOutputs] = await Promise.all([
40
+ ctx.db
41
+ .query("resources")
42
+ .withIndex("by_fqn", (q) => q.eq("stack", name))
43
+ .collect(),
44
+ ctx.db
45
+ .query("resources")
46
+ .withIndex("by_fqn", (q) => q.gte("stack", `${name}/`).lt("stack", `${name}0`))
47
+ .collect(),
48
+ ctx.db
49
+ .query("outputs")
50
+ .withIndex("by_stage", (q) => q.eq("stack", name))
51
+ .collect(),
52
+ ctx.db
53
+ .query("outputs")
54
+ .withIndex("by_stage", (q) => q.gte("stack", `${name}/`).lt("stack", `${name}0`))
55
+ .collect(),
56
+ ]);
57
+ const stacks = new Map<string, Map<string, Infer<typeof stage>>>();
58
+ for (const row of [...rootOutputs, ...childOutputs]) {
59
+ const record = row.currentRun;
60
+ if (record === undefined || record.repository !== name) continue;
61
+ // The output keeps the record of the last completed deploy under `samebase.run`.
62
+ let output = row.value === undefined ? null : withoutSecrets(row.value);
63
+ let deployed: unknown = null;
64
+ if (typeof output === "object" && output !== null && "samebase.run" in output) {
65
+ ({ "samebase.run": deployed, ...output } = output);
66
+ }
67
+ let stages = stacks.get(row.stack);
68
+ if (stages === undefined) {
69
+ stages = new Map();
70
+ stacks.set(row.stack, stages);
71
+ }
72
+ stages.set(row.stage, {
73
+ name: row.stage,
74
+ record,
75
+ deployedHeadCommit:
76
+ validate(runRecord, deployed) && deployed.repository === name
77
+ ? deployed.headCommit
78
+ : null,
79
+ resources: [],
80
+ output: JSON.stringify(output),
81
+ });
82
+ }
83
+ for (const row of [...rootResources, ...childResources]) {
84
+ stacks
85
+ .get(row.stack)
86
+ ?.get(row.stage)
87
+ ?.resources.push({
88
+ fqn: row.fqn,
89
+ value: JSON.stringify(withoutSecrets(row.value)),
90
+ });
91
+ }
92
+ return {
93
+ store: "found" as const,
94
+ stacks: [...stacks]
95
+ .sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
96
+ .map(([name, stages]) => ({
97
+ name,
98
+ stages: [...stages.values()].sort((a, b) =>
99
+ a.name < b.name ? -1 : a.name > b.name ? 1 : 0,
100
+ ),
101
+ })),
102
+ };
103
+ },
104
+ });