@confect/cli 9.0.0-next.8 → 9.0.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.
Files changed (44) hide show
  1. package/CHANGELOG.md +187 -1
  2. package/dist/Bundler.mjs +1 -4
  3. package/dist/Bundler.mjs.map +1 -1
  4. package/dist/CodegenError.mjs +3 -13
  5. package/dist/CodegenError.mjs.map +1 -1
  6. package/dist/LeafModule.mjs +9 -22
  7. package/dist/LeafModule.mjs.map +1 -1
  8. package/dist/SpecAssemblyNode.mjs +1 -8
  9. package/dist/SpecAssemblyNode.mjs.map +1 -1
  10. package/dist/confect/codegen.mjs +26 -69
  11. package/dist/confect/codegen.mjs.map +1 -1
  12. package/dist/confect/dev.mjs +0 -3
  13. package/dist/confect/dev.mjs.map +1 -1
  14. package/dist/log.mjs +2 -2
  15. package/dist/log.mjs.map +1 -1
  16. package/dist/package.mjs +1 -1
  17. package/dist/templates.mjs +5 -14
  18. package/dist/templates.mjs.map +1 -1
  19. package/dist/utils.mjs +32 -22
  20. package/dist/utils.mjs.map +1 -1
  21. package/package.json +4 -21
  22. package/dist/index.d.mts +0 -1
  23. package/src/BuildError.ts +0 -217
  24. package/src/Bundler.ts +0 -145
  25. package/src/CodeBlockWriter.ts +0 -65
  26. package/src/CodegenError.ts +0 -443
  27. package/src/ConfectDirectory.ts +0 -45
  28. package/src/ConvexDirectory.ts +0 -72
  29. package/src/FunctionPath.ts +0 -27
  30. package/src/FunctionPaths.ts +0 -107
  31. package/src/GroupPath.ts +0 -116
  32. package/src/GroupPaths.ts +0 -7
  33. package/src/LeafModule.ts +0 -323
  34. package/src/ProjectRoot.ts +0 -55
  35. package/src/SpecAssemblyNode.ts +0 -88
  36. package/src/TableModule.ts +0 -157
  37. package/src/cliApp.ts +0 -8
  38. package/src/confect/codegen.ts +0 -908
  39. package/src/confect/dev.ts +0 -790
  40. package/src/confect.ts +0 -19
  41. package/src/index.ts +0 -23
  42. package/src/log.ts +0 -110
  43. package/src/templates.ts +0 -633
  44. package/src/utils.ts +0 -428
package/src/GroupPath.ts DELETED
@@ -1,116 +0,0 @@
1
- import { type GroupSpec, type Spec } from "@confect/core";
2
- import * as Path from "@effect/platform/Path";
3
- import { pipe } from "effect/Function";
4
- import * as Array from "effect/Array";
5
- import * as Data from "effect/Data";
6
- import * as Effect from "effect/Effect";
7
- import * as Option from "effect/Option";
8
- import * as Record from "effect/Record";
9
- import * as Schema from "effect/Schema";
10
- import * as String from "effect/String";
11
-
12
- /**
13
- * The path to a group in the Confect API.
14
- */
15
- export class GroupPath extends Schema.Class<GroupPath>("GroupPath")({
16
- pathSegments: Schema.Data(Schema.NonEmptyArray(Schema.NonEmptyString)),
17
- }) {}
18
-
19
- /**
20
- * Create a GroupPath from path segments.
21
- */
22
- export const make = (pathSegments: readonly [string, ...string[]]): GroupPath =>
23
- GroupPath.make({ pathSegments: Data.array(pathSegments) });
24
-
25
- /**
26
- * Append a group name to a GroupPath to create a new GroupPath.
27
- */
28
- export const append = (groupPath: GroupPath, groupName: string): GroupPath =>
29
- make([...groupPath.pathSegments, groupName]);
30
-
31
- /**
32
- * Expects a path string of the form `./group1/group2.ts`, relative to the Convex functions directory.
33
- */
34
- export const fromGroupModulePath = (groupModulePath: string) =>
35
- Effect.gen(function* () {
36
- const path = yield* Path.Path;
37
-
38
- const { dir, name, ext } = path.parse(groupModulePath);
39
-
40
- if (ext === ".ts") {
41
- const dirSegments = Array.filter(
42
- String.split(dir, path.sep),
43
- String.isNonEmpty,
44
- );
45
- yield* Effect.logDebug(Array.append(dirSegments, name));
46
- return make(Array.append(dirSegments, name));
47
- } else {
48
- return yield* new GroupModulePathIsNotATypeScriptFileError({
49
- path: groupModulePath,
50
- });
51
- }
52
- });
53
-
54
- /**
55
- * Get the module path for a group, relative to the Convex functions directory.
56
- */
57
- export const modulePath = (groupPath: GroupPath) =>
58
- Effect.gen(function* () {
59
- const path = yield* Path.Path;
60
-
61
- return path.join(...groupPath.pathSegments) + ".ts";
62
- });
63
-
64
- export const getGroupSpec = (
65
- spec: Spec.AnyWithProps,
66
- groupPath: GroupPath,
67
- ): Option.Option<GroupSpec.AnyWithProps> =>
68
- pipe(
69
- groupPath.pathSegments,
70
- Array.matchLeft({
71
- onEmpty: () => Option.none(),
72
- onNonEmpty: (head, tail) =>
73
- pipe(
74
- Record.get(spec.groups, head),
75
- Option.flatMap((group) =>
76
- Array.isNonEmptyArray(tail)
77
- ? getGroupSpecHelper(group, tail)
78
- : Option.some(group),
79
- ),
80
- ),
81
- }),
82
- );
83
-
84
- const getGroupSpecHelper = (
85
- group: GroupSpec.AnyWithProps,
86
- remainingPath: ReadonlyArray<string>,
87
- ): Option.Option<GroupSpec.AnyWithProps> =>
88
- pipe(
89
- remainingPath,
90
- Array.matchLeft({
91
- onEmpty: () => Option.some(group),
92
- onNonEmpty: (head, tail) =>
93
- pipe(
94
- Record.get(group.groups, head),
95
- Option.flatMap((subGroup) =>
96
- Array.isNonEmptyArray(tail)
97
- ? getGroupSpecHelper(subGroup, tail)
98
- : Option.some(subGroup),
99
- ),
100
- ),
101
- }),
102
- );
103
-
104
- export const toString = (groupPath: GroupPath) =>
105
- Array.join(groupPath.pathSegments, ".");
106
-
107
- export class GroupModulePathIsNotATypeScriptFileError extends Schema.TaggedError<GroupModulePathIsNotATypeScriptFileError>()(
108
- "GroupModulePathIsNotATypeScriptFileError",
109
- {
110
- path: Schema.NonEmptyString,
111
- },
112
- ) {
113
- override get message(): string {
114
- return `Expected group module path to end with .ts, got ${this.path}`;
115
- }
116
- }
package/src/GroupPaths.ts DELETED
@@ -1,7 +0,0 @@
1
- import * as Schema from "effect/Schema";
2
- import * as GroupPath from "./GroupPath";
3
-
4
- export const GroupPaths = Schema.HashSetFromSelf(GroupPath.GroupPath).pipe(
5
- Schema.brand("@confect/cli/GroupPaths"),
6
- );
7
- export type GroupPaths = typeof GroupPaths.Type;
package/src/LeafModule.ts DELETED
@@ -1,323 +0,0 @@
1
- import { GroupSpec, Registry } from "@confect/core";
2
- import * as GroupImpl from "@confect/server/GroupImpl";
3
- import * as FileSystem from "@effect/platform/FileSystem";
4
- import * as Path from "@effect/platform/Path";
5
- import type { Context } from "effect";
6
- import * as Array from "effect/Array";
7
- import * as Effect from "effect/Effect";
8
- import * as Layer from "effect/Layer";
9
- import * as Option from "effect/Option";
10
- import * as Ref from "effect/Ref";
11
- import * as String from "effect/String";
12
- import { fromBundlerError } from "./BuildError";
13
- import * as Bundler from "./Bundler";
14
- import {
15
- ImplMissingDefaultLayerError,
16
- ImplMissingFunctionsError,
17
- ImplMissingSpecImportError,
18
- ImplNotFinalizedError,
19
- SpecMissingDefaultGroupSpecError,
20
- SpecRuntimeMismatchError,
21
- } from "./CodegenError";
22
- import { ConfectDirectory } from "./ConfectDirectory";
23
- import { removePathExtension } from "./utils";
24
-
25
- export interface LeafModule {
26
- readonly relativePath: string;
27
- readonly pathSegments: readonly [string, ...string[]];
28
- readonly groupPathDot: string;
29
- readonly registryGroupPathDot: string;
30
- readonly exportName: string;
31
- readonly runtime: "Convex" | "Node";
32
- readonly specImportPath: string;
33
- }
34
-
35
- export const SPEC_SUFFIX = ".spec.ts";
36
- export const IMPL_SUFFIX = ".impl.ts";
37
-
38
- const swapModuleSuffix = (
39
- relativePath: string,
40
- fromSuffix: string,
41
- toSuffix: string,
42
- ) =>
43
- Effect.gen(function* () {
44
- const path = yield* Path.Path;
45
- const { dir, name, ext } = path.parse(relativePath);
46
- if (ext !== ".ts" || !name.endsWith(fromSuffix.slice(0, -".ts".length))) {
47
- return relativePath;
48
- }
49
-
50
- const stem = name.slice(0, -fromSuffix.slice(0, -".ts".length).length);
51
- const nextName = `${stem}${toSuffix.slice(0, -".ts".length)}`;
52
- return dir.length > 0
53
- ? path.join(dir, `${nextName}${ext}`)
54
- : `${nextName}${ext}`;
55
- });
56
-
57
- export const isLeafSpecPath = (relativePath: string) =>
58
- relativePath.endsWith(SPEC_SUFFIX);
59
-
60
- export const isLeafImplPath = (relativePath: string) =>
61
- relativePath.endsWith(IMPL_SUFFIX);
62
-
63
- export const exportNameFromModulePath = (relativePath: string) =>
64
- Effect.gen(function* () {
65
- const path = yield* Path.Path;
66
- const { name, ext } = path.parse(relativePath);
67
- if (ext !== ".ts") {
68
- return name;
69
- }
70
- return name.endsWith(".spec") ? name.slice(0, -".spec".length) : name;
71
- });
72
-
73
- export const groupPathFromRelativeModulePath = (relativePath: string) =>
74
- Effect.gen(function* () {
75
- const path = yield* Path.Path;
76
- const { dir, name, ext } = path.parse(relativePath);
77
- const stem =
78
- ext === ".ts" && name.endsWith(".spec")
79
- ? name.slice(0, -".spec".length)
80
- : name;
81
- const dirSegments = Array.filter(
82
- String.split(dir, path.sep),
83
- String.isNonEmpty,
84
- );
85
- const pathSegments = Array.append(dirSegments, stem) as [
86
- string,
87
- ...string[],
88
- ];
89
- return {
90
- pathSegments,
91
- groupPathDot: Array.join(pathSegments, "."),
92
- };
93
- });
94
-
95
- export const specImportPathFromGenerated = (specRelativePath: string) =>
96
- Effect.gen(function* () {
97
- const withoutExt = yield* removePathExtension(specRelativePath);
98
- return `../${withoutExt}`;
99
- });
100
-
101
- export const specPathForImpl = (implRelativePath: string) =>
102
- swapModuleSuffix(implRelativePath, IMPL_SUFFIX, SPEC_SUFFIX);
103
-
104
- export const implPathForSpec = (specRelativePath: string) =>
105
- swapModuleSuffix(specRelativePath, SPEC_SUFFIX, IMPL_SUFFIX);
106
-
107
- export const isNodeLeafModule = (relativePath: string) =>
108
- relativePath.startsWith("node/") || relativePath.startsWith("node\\");
109
-
110
- export const toNodeRegistryLeaf = (leaf: LeafModule): LeafModule => ({
111
- ...leaf,
112
- pathSegments: [leaf.exportName],
113
- groupPathDot: leaf.exportName,
114
- });
115
-
116
- export const registeredFunctionsRelativePath = (leaf: LeafModule) =>
117
- Effect.gen(function* () {
118
- const path = yield* Path.Path;
119
- return (
120
- path.join(
121
- "registeredFunctions",
122
- ...leaf.pathSegments.slice(leaf.runtime === "Node" ? 1 : 0),
123
- ) + ".ts"
124
- );
125
- });
126
-
127
- export const discoverLeafSpecFiles = Effect.gen(function* () {
128
- const fs = yield* FileSystem.FileSystem;
129
- const path = yield* Path.Path;
130
- const confectDirectory = yield* ConfectDirectory.get;
131
-
132
- const excludedDirs = new Set(["_generated", "tables"]);
133
- const excludedFiles = new Set(["nodeSpec.ts", "spec.ts"]);
134
-
135
- const allPaths = yield* fs.readDirectory(confectDirectory, {
136
- recursive: true,
137
- });
138
-
139
- return Array.filter(allPaths, (relativePath) => {
140
- if (!isLeafSpecPath(relativePath)) {
141
- return false;
142
- }
143
-
144
- if (excludedFiles.has(relativePath)) {
145
- return false;
146
- }
147
-
148
- const segments = String.split(relativePath, path.sep);
149
- return !Array.some(segments, (segment) => excludedDirs.has(segment));
150
- });
151
- });
152
-
153
- export const discoverLeafImplFiles = Effect.gen(function* () {
154
- const fs = yield* FileSystem.FileSystem;
155
- const path = yield* Path.Path;
156
- const confectDirectory = yield* ConfectDirectory.get;
157
-
158
- const excludedDirs = new Set(["_generated", "tables"]);
159
-
160
- const allPaths = yield* fs.readDirectory(confectDirectory, {
161
- recursive: true,
162
- });
163
-
164
- return Array.filter(allPaths, (relativePath) => {
165
- if (!isLeafImplPath(relativePath)) {
166
- return false;
167
- }
168
-
169
- const segments = String.split(relativePath, path.sep);
170
- return !Array.some(segments, (segment) => excludedDirs.has(segment));
171
- });
172
- });
173
-
174
- export const toLeafModule = (specRelativePath: string) =>
175
- Effect.gen(function* () {
176
- const exportName = yield* exportNameFromModulePath(specRelativePath);
177
- const { pathSegments, groupPathDot } =
178
- yield* groupPathFromRelativeModulePath(specRelativePath);
179
- const specImportPath = yield* specImportPathFromGenerated(specRelativePath);
180
- const runtime = isNodeLeafModule(specRelativePath) ? "Node" : "Convex";
181
-
182
- return {
183
- relativePath: specRelativePath,
184
- pathSegments,
185
- groupPathDot,
186
- exportName,
187
- runtime,
188
- registryGroupPathDot: runtime === "Node" ? exportName : groupPathDot,
189
- specImportPath,
190
- } satisfies LeafModule;
191
- });
192
-
193
- const absoluteModulePath = (relativePath: string) =>
194
- Effect.gen(function* () {
195
- const confectDirectory = yield* ConfectDirectory.get;
196
- const path = yield* Path.Path;
197
- return path.resolve(confectDirectory, relativePath);
198
- });
199
-
200
- /**
201
- * Validate that the leaf's spec file default-exports a `GroupSpec` whose
202
- * runtime matches the leaf's location (`Convex` for files outside
203
- * `confect/node/`, `Node` for files inside it). Returns the validated
204
- * `GroupSpec` so callers can avoid re-bundling for later inspection (e.g.
205
- * parent/child name-collision checks at codegen time).
206
- */
207
- export const validateSpec = (leaf: LeafModule) =>
208
- Effect.gen(function* () {
209
- const absolutePath = yield* absoluteModulePath(leaf.relativePath);
210
- const { module } = yield* Bundler.bundle(absolutePath).pipe(
211
- Effect.mapError((error) => fromBundlerError(leaf.relativePath, error)),
212
- );
213
-
214
- const groupSpec = module.default;
215
-
216
- if (!GroupSpec.isGroupSpec(groupSpec)) {
217
- return yield* new SpecMissingDefaultGroupSpecError({
218
- specPath: leaf.relativePath,
219
- });
220
- }
221
-
222
- if (groupSpec.runtime !== leaf.runtime) {
223
- return yield* new SpecRuntimeMismatchError({
224
- specPath: leaf.relativePath,
225
- expectedRuntime: leaf.runtime,
226
- actualRuntime: groupSpec.runtime,
227
- });
228
- }
229
-
230
- return groupSpec;
231
- });
232
-
233
- /**
234
- * Walk the built `Context` for a `Finalized` `GroupImpl` service value. The
235
- * lookup is value-shaped (via `GroupImpl.isFinalizedGroupImpl`) so we don't
236
- * need to know the group's path up front to construct a typed tag for it.
237
- */
238
- const findFinalizedGroupImpl = <S>(
239
- context: Context.Context<S>,
240
- ): Option.Option<GroupImpl.AnyFinalized> =>
241
- Array.findFirst(context.unsafeMap.values(), GroupImpl.isFinalizedGroupImpl);
242
-
243
- /**
244
- * Build the impl layer with a fresh `Registry` so each validation is
245
- * isolated from prior validations' `FunctionImpl.make` writes. The CLI no
246
- * longer reads the registry directly — `GroupImpl.finalize` snapshots the
247
- * registered function names onto the produced `Finalized` `GroupImpl`
248
- * service value — but a fresh `Ref` is still required because the default
249
- * `Context.Reference` is cached globally and would otherwise accumulate
250
- * items across impls.
251
- */
252
- const buildImplLayer = (implLayer: Layer.Layer<unknown>) =>
253
- Effect.gen(function* () {
254
- const registry = Ref.unsafeMake<Registry.RegistryItems>({});
255
- return yield* Layer.build(
256
- implLayer as Layer.Layer<unknown, never, never>,
257
- ).pipe(Effect.provideService(Registry.Registry, registry));
258
- }).pipe(Effect.scoped);
259
-
260
- /**
261
- * Validate that the leaf's sibling impl file imports the spec, default-exports
262
- * a finalized `GroupImpl` layer, and provides a `FunctionImpl` for every
263
- * function declared by the spec.
264
- */
265
- export const validateImpl = (leaf: LeafModule) =>
266
- Effect.gen(function* () {
267
- const implRelativePath = yield* implPathForSpec(leaf.relativePath);
268
- const implAbsolutePath = yield* absoluteModulePath(implRelativePath);
269
- const specAbsolutePath = yield* absoluteModulePath(leaf.relativePath);
270
-
271
- const bundled = yield* Bundler.bundle(implAbsolutePath).pipe(
272
- Effect.mapError((error) => fromBundlerError(implRelativePath, error)),
273
- );
274
-
275
- if (
276
- !(yield* Bundler.directlyImports(
277
- bundled,
278
- implAbsolutePath,
279
- specAbsolutePath,
280
- ))
281
- ) {
282
- return yield* new ImplMissingSpecImportError({
283
- implPath: implRelativePath,
284
- expectedSpecPath: leaf.relativePath,
285
- });
286
- }
287
-
288
- if (!Layer.isLayer(bundled.module.default)) {
289
- return yield* new ImplMissingDefaultLayerError({
290
- implPath: implRelativePath,
291
- });
292
- }
293
-
294
- const { module: specModule } = yield* Bundler.bundle(specAbsolutePath).pipe(
295
- Effect.mapError((error) => fromBundlerError(leaf.relativePath, error)),
296
- );
297
- const groupSpec = specModule.default as GroupSpec.AnyWithProps;
298
- const expectedFunctionNames = Object.keys(groupSpec.functions);
299
-
300
- const context = yield* buildImplLayer(
301
- bundled.module.default as Layer.Layer<unknown>,
302
- );
303
- const finalizedGroupImpl = yield* Option.match(
304
- findFinalizedGroupImpl(context),
305
- {
306
- onNone: () => new ImplNotFinalizedError({ implPath: implRelativePath }),
307
- onSome: Effect.succeed,
308
- },
309
- );
310
-
311
- const registeredSet = new Set(finalizedGroupImpl.registeredFunctionNames);
312
- const missing = expectedFunctionNames.filter(
313
- (name) => !registeredSet.has(name),
314
- );
315
-
316
- if (missing.length > 0) {
317
- return yield* new ImplMissingFunctionsError({
318
- implPath: implRelativePath,
319
- groupPath: leaf.groupPathDot,
320
- missingFunctionNames: missing,
321
- });
322
- }
323
- });
@@ -1,55 +0,0 @@
1
- import * as FileSystem from "@effect/platform/FileSystem";
2
- import * as Path from "@effect/platform/Path";
3
- import * as NodeFileSystem from "@effect/platform-node/NodeFileSystem";
4
- import * as Array from "effect/Array";
5
- import * as Effect from "effect/Effect";
6
- import * as Option from "effect/Option";
7
- import * as Ref from "effect/Ref";
8
- import * as Schema from "effect/Schema";
9
-
10
- export class ProjectRoot extends Effect.Service<ProjectRoot>()(
11
- "@confect/cli/ProjectRoot",
12
- {
13
- effect: Effect.gen(function* () {
14
- const projectRoot = yield* findProjectRoot;
15
-
16
- const ref = yield* Ref.make<string>(projectRoot);
17
-
18
- return { get: Ref.get(ref) } as const;
19
- }),
20
- dependencies: [NodeFileSystem.layer],
21
- accessors: true,
22
- },
23
- ) {}
24
-
25
- export const findProjectRoot = Effect.gen(function* () {
26
- const fs = yield* FileSystem.FileSystem;
27
- const path = yield* Path.Path;
28
-
29
- const startDir = path.resolve(".");
30
- const root = path.parse(startDir).root;
31
-
32
- const directories = Array.unfold(startDir, (dir) =>
33
- dir === root
34
- ? Option.none()
35
- : Option.some([dir, path.dirname(dir)] as const),
36
- );
37
-
38
- const projectRoot = yield* Effect.findFirst(directories, (dir) =>
39
- fs.exists(path.join(dir, "package.json")),
40
- );
41
-
42
- return yield* Option.match(projectRoot, {
43
- onNone: () => Effect.fail(new ProjectRootNotFoundError()),
44
- onSome: Effect.succeed,
45
- });
46
- });
47
-
48
- export class ProjectRootNotFoundError extends Schema.TaggedError<ProjectRootNotFoundError>()(
49
- "ProjectRootNotFoundError",
50
- {},
51
- ) {
52
- override get message(): string {
53
- return "Could not find project root (no 'package.json' found)";
54
- }
55
- }
@@ -1,88 +0,0 @@
1
- import type { LeafModule } from "./LeafModule";
2
- import { pipe } from "effect/Function";
3
- import * as Array from "effect/Array";
4
- import * as Option from "effect/Option";
5
- import * as Order from "effect/Order";
6
- import * as Record from "effect/Record";
7
-
8
- export interface SpecImportBinding {
9
- readonly importPath: string;
10
- readonly exportName: string;
11
- readonly localName: string;
12
- }
13
-
14
- export interface SpecAssemblyNode {
15
- readonly segment: string;
16
- readonly importBinding: Option.Option<SpecImportBinding>;
17
- readonly children: ReadonlyArray<SpecAssemblyNode>;
18
- }
19
-
20
- const importBindingFromLeaf = (leaf: LeafModule): SpecImportBinding => ({
21
- importPath: leaf.specImportPath,
22
- exportName: leaf.exportName,
23
- localName: leaf.pathSegments.join("_"),
24
- });
25
-
26
- const assemblyNodesAtDepth = (
27
- leaves: ReadonlyArray<LeafModule>,
28
- depth: number,
29
- ): ReadonlyArray<SpecAssemblyNode> =>
30
- pipe(
31
- Array.groupBy(leaves, (leaf) => leaf.pathSegments[depth]!),
32
- Record.toEntries,
33
- Array.sortBy(Order.mapInput(Order.string, ([segment]) => segment)),
34
- Array.map(([segment, groupLeaves]) => {
35
- const terminal = Array.findFirst(
36
- groupLeaves,
37
- (leaf) => leaf.pathSegments.length === depth + 1,
38
- );
39
- const descendants = Array.filter(
40
- groupLeaves,
41
- (leaf) => leaf.pathSegments.length > depth + 1,
42
- );
43
- return {
44
- segment,
45
- importBinding: Option.map(terminal, importBindingFromLeaf),
46
- children: assemblyNodesAtDepth(descendants, depth + 1),
47
- };
48
- }),
49
- );
50
-
51
- export const assemblyNodesFromLeaves = (
52
- leaves: ReadonlyArray<LeafModule>,
53
- ): ReadonlyArray<SpecAssemblyNode> => assemblyNodesAtDepth(leaves, 0);
54
-
55
- export const partitionByRuntime = (
56
- leaves: ReadonlyArray<LeafModule>,
57
- ): {
58
- readonly convex: ReadonlyArray<LeafModule>;
59
- readonly node: ReadonlyArray<LeafModule>;
60
- } => {
61
- const [node, convex] = Array.partition(
62
- leaves,
63
- (leaf) => leaf.runtime === "Convex",
64
- );
65
- return { convex, node };
66
- };
67
-
68
- const importBindingsForNode = (
69
- node: SpecAssemblyNode,
70
- ): ReadonlyArray<SpecImportBinding> =>
71
- pipe(node.children, Array.flatMap(importBindingsForNode), (childBindings) =>
72
- Option.match(node.importBinding, {
73
- onNone: () => childBindings,
74
- onSome: (binding) => Array.prepend(childBindings, binding),
75
- }),
76
- );
77
-
78
- export const collectImportBindings = (
79
- nodes: ReadonlyArray<SpecAssemblyNode>,
80
- ): ReadonlyArray<SpecImportBinding> =>
81
- pipe(
82
- Array.flatMap(nodes, importBindingsForNode),
83
- (bindings) =>
84
- Record.fromIterableBy(bindings, (binding) => binding.importPath),
85
- Record.toEntries,
86
- Array.map(([, binding]) => binding),
87
- Array.sortBy(Order.mapInput(Order.string, (binding) => binding.localName)),
88
- );