@confect/core 7.0.0 → 9.0.0-next.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/CHANGELOG.md CHANGED
@@ -1,5 +1,55 @@
1
1
  # @confect/core
2
2
 
3
+ ## 9.0.0-next.0
4
+
5
+ ### Major Changes
6
+
7
+ - 6db3a3a: Derive Confect function paths from the filesystem layout of `confect/`. Each group lives in a colocated `*.spec.ts`/`*.impl.ts` pair, and the group's name is its path within `confect/` (file stem for top-level groups, dot-joined directory path for nested groups). See [Project Structure](https://confect.dev/concepts/project-structure), [File Naming Conventions](https://confect.dev/concepts/file-naming-conventions), and [The Spec/Impl Model](https://confect.dev/concepts/spec-impl-model) for the current model.
8
+
9
+ Each `*.spec.ts` default-exports its `GroupSpec`. Each `*.impl.ts` default-imports its sibling spec, builds its `GroupImpl`, and default-exports the result of `GroupImpl.finalize`. Named co-exports on `*.spec.ts` (such as error classes) remain allowed.
10
+
11
+ ### Why
12
+
13
+ The previous model assembled every group's impl into a single root `confect/impl.ts` (plus `confect/nodeImpl.ts`), which `confect codegen` emitted as the aggregate `_generated/registeredFunctions.ts`. Every generated `convex/` module — one per Convex function — imported from that aggregate, so loading any single query, mutation, or action transitively loaded the impl module of every other Convex function in the project, along with all of their dependencies. For large projects this inflated each function's bundle and added meaningful cold-start cost on Convex.
14
+
15
+ Splitting impl across colocated `*.impl.ts` files is the vehicle for fixing that. With this change, `confect codegen` emits one `_generated/registeredFunctions/{path}.ts` per group, and each generated `convex/` module imports only its own group's per-group registry — which in turn imports only its own sibling `.impl.ts`. A Convex function's cold-start bundle now scales with its own group's impl rather than with the size of the whole project.
16
+
17
+ ### Breaking changes
18
+ - `GroupSpec.make()` and `GroupSpec.makeNode()` no longer take a name argument; the group name is derived from the spec file's path within `confect/`.
19
+ - `FunctionImpl.make(api, groupSpec, fn, handler)` and `GroupImpl.make(api, groupSpec)` now take the imported sibling spec object as their second argument instead of a dot-path string.
20
+ - Every `GroupImpl` pipeline must end with `GroupImpl.finalize`, which only typechecks once every function declared by the spec has a corresponding `FunctionImpl` provided to the group layer. `GroupImpl.finalize` snapshots the names of every registered function onto the produced `Finalized` `GroupImpl` service value, and `confect codegen` reads those names to verify per-function coverage against the spec at runtime.
21
+ - The previously-exported `Impl.make` and `Impl.finalize` (used by the old root `impl.ts`/`nodeImpl.ts` files) are removed. Per-group completeness is now enforced by `GroupImpl.finalize`.
22
+ - Root `confect/spec.ts`, `confect/impl.ts`, `confect/nodeSpec.ts`, `confect/nodeImpl.ts`, and any parent aggregator `*.spec.ts`/`*.impl.ts` files are no longer used. `confect codegen` deletes any of these on upgrade, along with the stale `_generated/registeredFunctions.ts` and `_generated/nodeRegisteredFunctions.ts`.
23
+ - Every module under `convex/` is re-emitted to import from `_generated/registeredFunctions/{path}` instead of the previous aggregate file. Users who commit `convex/` to source control should expect a full rewrite of that directory on first codegen.
24
+
25
+ ### Migration
26
+ 1. For each existing group, create a colocated `confect/{path}.spec.ts` and `confect/{path}.impl.ts` pair (under a subdirectory for nested groups).
27
+ - In each spec, call `GroupSpec.make()` (or `GroupSpec.makeNode()`) without a name and `export default` the result.
28
+ - In each impl, default-import the sibling spec (e.g. `import notes from "./notes.spec"`), pass it to `FunctionImpl.make`/`GroupImpl.make` in place of the previous dot-path string, append `GroupImpl.finalize` to the pipeline, and `export default` the resulting `GroupImpl` layer:
29
+ ```ts
30
+ export default GroupImpl.make(api, notes).pipe(
31
+ Layer.provide(list),
32
+ Layer.provide(insert),
33
+ GroupImpl.finalize,
34
+ );
35
+ ```
36
+ 2. Delete root `confect/spec.ts`, `confect/impl.ts`, `confect/nodeSpec.ts`, `confect/nodeImpl.ts`, and any parent aggregator spec/impl files. (`confect codegen` will also delete any of these it finds, plus the stale `_generated/registeredFunctions.ts` and `_generated/nodeRegisteredFunctions.ts`, so this step can be skipped.)
37
+ 3. Run `confect codegen`. Every module under `convex/` will be re-emitted.
38
+
39
+ ## 8.0.0
40
+
41
+ ### Minor Changes
42
+
43
+ - 4bb2722: Bump Effect ecosystem to latest. `@effect/platform` is now `^0.96.1` and `@effect/platform-node` is now `^0.106.0` in `@confect/server`'s peer dependencies; `effect` peer is now `^3.21.2` across packages. Consumers must upgrade `@effect/platform`, `@effect/platform-node`, and `effect` in lockstep when bumping `@confect/server`.
44
+
45
+ ### Patch Changes
46
+
47
+ - 40c1cff: Switch sibling `@confect/*` peer-dependency specifiers from `workspace:*` to `workspace:^`. Published peer ranges are now caret-based (e.g. `^7.0.0`) instead of exact-pinned, so non-major upgrades of one `@confect/*` package no longer fall out of range for its peer dependents.
48
+
49
+ Paired with the Changesets `onlyUpdatePeerDependentsWhenOutOfRange` flag, this prevents the entire `@confect/*` family from being promoted to a major bump on every release when only minor/patch changes are present.
50
+
51
+ `@confect/cli` additionally moves `@effect/platform` from `peerDependencies` to `dependencies`, since the CLI consumes it as an internal implementation detail (for `FileSystem`/`Path`) rather than exposing it in its public API. Consumers no longer need to install `@effect/platform` themselves to use the CLI.
52
+
3
53
  ## 7.0.0
4
54
 
5
55
  ### Minor Changes
@@ -1 +1 @@
1
- {"version":3,"file":"FunctionSpec.d.ts","names":[],"sources":["../src/FunctionSpec.ts"],"mappings":";;;;;;;;;cAaa,MAAA;AAAA,KACD,MAAA,UAAgB,MAAA;AAAA,cAEf,cAAA,GAAkB,CAAA,cAAa,CAAA,IAAK,YAAA;AAAA,UAGhC,YAAA,iCACiB,sBAAA,8BACJ,kBAAA,oDAEA,kBAAA;EAAA,UAElB,MAAA,GAAS,MAAA;EAAA,SACV,sBAAA,EAAwB,uBAAA;EAAA,SACxB,kBAAA,EAAoB,mBAAA;EAAA,SACpB,IAAA,EAAM,KAAA;EAAA,SACN,kBAAA,EAAoB,mBAAA;AAAA;AAAA,UAGd,GAAA;EAAA,UACL,MAAA,GAAS,MAAA;AAAA;AAAA,UAGJ,YAAA,SAAqB,YAAA,CACpC,sBAAA,EACA,kBAAA,UAEA,kBAAA;AAAA,UAGe,UAAA,SAAmB,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YAAA,mBACX,MAAA,CAAO,MAAA,CAAO,YAAA,iBAChB,MAAA,CAAO,MAAA,CAAO,YAAA;EAAY,IAAA;EAAA,IAAA;EAAA,OAAA;EAAA;AAAA;;;;;;;;;KAmExC,WAAA,MACH,CAAA,SAAU,eAAA,sBACN,CAAA,GACA,CAAA,SAAU,kBAAA,sBACR,CAAA,GACA,CAAA,SAAU,gBAAA,sBACR,CAAA;AAAA,KAGL,cAAA,MACH,CAAA,SAAU,eAAA,sBACN,CAAA,GACA,CAAA,SAAU,kBAAA,sBACR,CAAA,GACA,CAAA,SAAU,gBAAA,sBACR,CAAA;AAAA,cAuCG,iBAAA,aA1BR,eAAA,wDAMD,IAAA,EAAM,KAAA,KAAK,YAAA;EAAA;;;cAwBF,mBAAA,aA9BR,eAAA,0DAMD,IAAA,EAAM,KAAA,KAAK,YAAA;EAAA;;;cA4BF,oBAAA,aAlCR,kBAAA,wDAMD,IAAA,EAAM,KAAA,KAAK,YAAA;EAAA;;;cAgCF,sBAAA,aAtCR,kBAAA,0DAMD,IAAA,EAAM,KAAA,KAAK,YAAA;EAAA;;;cAoCF,kBAAA,aA1CR,gBAAA,wDAMD,IAAA,EAAM,KAAA,KAAK,YAAA;EAAA;;;cAwCF,oBAAA,aA9CR,gBAAA,0DAMD,IAAA,EAAM,KAAA,KAAK,YAAA;EAAA;;;cA4CF,sBAAA,aAlDR,gBAAA,wDAMD,IAAA,EAAM,KAAA,KAAK,YAAA;EAAA;;;cAgDF,wBAAA,aAtDR,gBAAA,0DAMD,IAAA,EAAM,KAAA,KAAK,YAAA;EAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"FunctionSpec.js","names":["FunctionProvenance.Confect","RuntimeAndFunctionType.ConvexQuery","RuntimeAndFunctionType.ConvexMutation","RuntimeAndFunctionType.ConvexAction","RuntimeAndFunctionType.NodeAction","FunctionProvenance.Convex"],"sources":["../src/FunctionSpec.ts"],"sourcesContent":["import type {\n FunctionType,\n FunctionVisibility,\n RegisteredAction,\n RegisteredMutation,\n RegisteredQuery,\n} from \"convex/server\";\nimport type { Schema } from \"effect\";\nimport { Predicate } from \"effect\";\nimport * as FunctionProvenance from \"./FunctionProvenance\";\nimport { validateConfectFunctionIdentifier } from \"./internal/utils\";\nimport * as RuntimeAndFunctionType from \"./RuntimeAndFunctionType\";\n\nexport const TypeId = \"@confect/core/FunctionSpec\";\nexport type TypeId = typeof TypeId;\n\nexport const isFunctionSpec = (u: unknown): u is AnyWithProps =>\n Predicate.hasProperty(u, TypeId);\n\nexport interface FunctionSpec<\n RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility_ extends FunctionVisibility,\n Name_ extends string,\n FunctionProvenance_ extends FunctionProvenance.FunctionProvenance,\n> {\n readonly [TypeId]: TypeId;\n readonly runtimeAndFunctionType: RuntimeAndFunctionType_;\n readonly functionVisibility: FunctionVisibility_;\n readonly name: Name_;\n readonly functionProvenance: FunctionProvenance_;\n}\n\nexport interface Any {\n readonly [TypeId]: TypeId;\n}\n\nexport interface AnyWithProps extends FunctionSpec<\n RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility,\n string,\n FunctionProvenance.FunctionProvenance\n> {}\n\nexport interface AnyConfect extends FunctionSpec<\n RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility,\n string,\n FunctionProvenance.AnyConfect\n> {}\n\nexport interface AnyConvex extends FunctionSpec<\n RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility,\n string,\n FunctionProvenance.AnyConvex\n> {}\n\nexport interface AnyWithPropsWithRuntime<\n Runtime extends RuntimeAndFunctionType.Runtime,\n> extends FunctionSpec<\n RuntimeAndFunctionType.WithRuntime<Runtime>,\n FunctionVisibility,\n string,\n FunctionProvenance.FunctionProvenance\n> {}\n\nexport interface AnyWithPropsWithFunctionType<\n RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,\n> extends FunctionSpec<\n RuntimeAndFunctionType_,\n FunctionVisibility,\n string,\n FunctionProvenance.FunctionProvenance\n> {}\n\nexport interface AnyWithPropsWithFunctionProvenance<\n FunctionProvenance_ extends FunctionProvenance.FunctionProvenance,\n> extends FunctionSpec<\n RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility,\n string,\n FunctionProvenance_\n> {}\n\nexport type GetRuntimeAndFunctionType<FunctionSpec_ extends AnyWithProps> =\n FunctionSpec_[\"runtimeAndFunctionType\"];\n\nexport type GetFunctionVisibility<FunctionSpec_ extends AnyWithProps> =\n FunctionSpec_[\"functionVisibility\"];\n\nexport type Name<FunctionSpec_ extends AnyWithProps> = FunctionSpec_[\"name\"];\n\nexport type Args<FunctionSpec_ extends AnyWithProps> = FunctionSpec_ extends {\n functionProvenance: {\n _tag: \"Confect\";\n args: infer ArgsSchema_ extends Schema.Schema.AnyNoContext;\n };\n}\n ? ArgsSchema_[\"Type\"]\n : FunctionSpec_ extends {\n functionProvenance: { _tag: \"Convex\"; _args: infer Args_ };\n }\n ? Args_\n : never;\n\nexport type Returns<FunctionSpec_ extends AnyWithProps> =\n FunctionSpec_ extends {\n functionProvenance: {\n _tag: \"Confect\";\n returns: infer ReturnsSchema_ extends Schema.Schema.AnyNoContext;\n };\n }\n ? ReturnsSchema_[\"Type\"]\n : FunctionSpec_ extends {\n functionProvenance: { _tag: \"Convex\"; _returns: infer Returns_ };\n }\n ? Awaited<Returns_>\n : never;\n\nexport type EncodedArgs<FunctionSpec_ extends AnyWithProps> =\n FunctionSpec_ extends {\n functionProvenance: {\n _tag: \"Confect\";\n args: infer ArgsSchema_ extends Schema.Schema.AnyNoContext;\n };\n }\n ? ArgsSchema_[\"Encoded\"]\n : FunctionSpec_ extends {\n functionProvenance: { _tag: \"Convex\"; _args: infer Args_ };\n }\n ? Args_\n : never;\n\nexport type EncodedReturns<FunctionSpec_ extends AnyWithProps> =\n FunctionSpec_ extends {\n functionProvenance: {\n _tag: \"Confect\";\n returns: infer ReturnsSchema_ extends Schema.Schema.AnyNoContext;\n };\n }\n ? ReturnsSchema_[\"Encoded\"]\n : FunctionSpec_ extends {\n functionProvenance: { _tag: \"Convex\"; _returns: infer Returns_ };\n }\n ? Returns_\n : never;\n\nexport type Error<FunctionSpec_ extends AnyWithProps> = FunctionSpec_ extends {\n functionProvenance: FunctionProvenance.Confect<\n any,\n any,\n infer ErrorSchema_ extends Schema.Schema.AnyNoContext\n >;\n}\n ? ErrorSchema_[\"Type\"]\n : never;\n\nexport type EncodedError<FunctionSpec_ extends AnyWithProps> =\n FunctionSpec_ extends {\n functionProvenance: FunctionProvenance.Confect<\n any,\n any,\n infer ErrorSchema_ extends Schema.Schema.AnyNoContext\n >;\n }\n ? ErrorSchema_[\"Encoded\"]\n : never;\n\nexport type WithName<\n FunctionSpec_ extends AnyWithProps,\n Name_ extends string,\n> = Extract<FunctionSpec_, { readonly name: Name_ }>;\n\nexport type WithRuntimeAndFunctionType<\n FunctionSpec_ extends AnyWithProps,\n RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,\n> = Extract<\n FunctionSpec_,\n { readonly runtimeAndFunctionType: RuntimeAndFunctionType_ }\n>;\n\nexport type WithFunctionType<\n FunctionSpec_ extends AnyWithProps,\n FunctionType_ extends FunctionType,\n> = Extract<\n FunctionSpec_,\n { readonly runtimeAndFunctionType: { readonly functionType: FunctionType_ } }\n>;\n\nexport type WithFunctionProvenance<\n FunctionSpec_ extends AnyWithProps,\n FunctionProvenance_ extends FunctionProvenance.FunctionProvenance,\n> = Extract<\n FunctionSpec_,\n { readonly functionProvenance: FunctionProvenance_ }\n>;\n\nexport type WithoutName<\n FunctionSpec_ extends AnyWithProps,\n Name_ extends Name<FunctionSpec_>,\n> = Exclude<FunctionSpec_, { readonly name: Name_ }>;\n\nconst Proto = {\n [TypeId]: TypeId,\n};\n\nconst make =\n <\n RuntimeAndFunctionType_ extends\n RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility_ extends FunctionVisibility,\n >(\n runtimeAndFunctionType: RuntimeAndFunctionType_,\n functionVisibility: FunctionVisibility_,\n ) =>\n <\n const Name_ extends string,\n Args_ extends Schema.Schema.AnyNoContext,\n Returns_ extends Schema.Schema.AnyNoContext,\n Error_ extends Schema.Schema.AnyNoContext = never,\n >({\n name,\n args,\n returns,\n error,\n }: {\n name: Name_;\n args: Args_;\n returns: Returns_;\n error?: Error_;\n }): FunctionSpec<\n RuntimeAndFunctionType_,\n FunctionVisibility_,\n Name_,\n FunctionProvenance.Confect<Args_, Returns_, Error_>\n > => {\n validateConfectFunctionIdentifier(name);\n\n return Object.assign(Object.create(Proto), {\n runtimeAndFunctionType,\n functionVisibility,\n name,\n functionProvenance: FunctionProvenance.Confect(args, returns, error),\n });\n };\n\nexport const publicQuery = make(RuntimeAndFunctionType.ConvexQuery, \"public\");\nexport const internalQuery = make(\n RuntimeAndFunctionType.ConvexQuery,\n \"internal\",\n);\nexport const publicMutation = make(\n RuntimeAndFunctionType.ConvexMutation,\n \"public\",\n);\nexport const internalMutation = make(\n RuntimeAndFunctionType.ConvexMutation,\n \"internal\",\n);\nexport const publicAction = make(RuntimeAndFunctionType.ConvexAction, \"public\");\nexport const internalAction = make(\n RuntimeAndFunctionType.ConvexAction,\n \"internal\",\n);\n\nexport const publicNodeAction = make(\n RuntimeAndFunctionType.NodeAction,\n \"public\",\n);\nexport const internalNodeAction = make(\n RuntimeAndFunctionType.NodeAction,\n \"internal\",\n);\n\ntype MatchingRegisteredFunction<\n RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility_ extends FunctionVisibility,\n> =\n RuntimeAndFunctionType.GetFunctionType<RuntimeAndFunctionType_> extends \"query\"\n ? RegisteredQuery<FunctionVisibility_, any, any>\n : RuntimeAndFunctionType.GetFunctionType<RuntimeAndFunctionType_> extends \"mutation\"\n ? RegisteredMutation<FunctionVisibility_, any, any>\n : RuntimeAndFunctionType.GetFunctionType<RuntimeAndFunctionType_> extends \"action\"\n ? RegisteredAction<FunctionVisibility_, any, any>\n : never;\n\ntype ExtractArgs<F> =\n F extends RegisteredQuery<any, infer A, any>\n ? A\n : F extends RegisteredMutation<any, infer A, any>\n ? A\n : F extends RegisteredAction<any, infer A, any>\n ? A\n : never;\n\ntype ExtractReturns<F> =\n F extends RegisteredQuery<any, any, infer R>\n ? R\n : F extends RegisteredMutation<any, any, infer R>\n ? R\n : F extends RegisteredAction<any, any, infer R>\n ? R\n : never;\n\nconst makeConvex =\n <\n RuntimeAndFunctionType_ extends\n RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility_ extends FunctionVisibility,\n >(\n runtimeAndFunctionType: RuntimeAndFunctionType_,\n functionVisibility: FunctionVisibility_,\n ) =>\n <\n F extends MatchingRegisteredFunction<\n RuntimeAndFunctionType_,\n FunctionVisibility_\n >,\n >() =>\n <const Name_ extends string>(\n name: Name_,\n ): FunctionSpec<\n RuntimeAndFunctionType_,\n FunctionVisibility_,\n Name_,\n FunctionProvenance.Convex<ExtractArgs<F>, ExtractReturns<F>>\n > => {\n validateConfectFunctionIdentifier(name);\n\n return Object.assign(Object.create(Proto), {\n runtimeAndFunctionType,\n functionVisibility,\n name,\n functionProvenance: FunctionProvenance.Convex(),\n }) as any;\n };\n\nexport const convexPublicQuery = makeConvex(\n RuntimeAndFunctionType.ConvexQuery,\n \"public\",\n);\nexport const convexInternalQuery = makeConvex(\n RuntimeAndFunctionType.ConvexQuery,\n \"internal\",\n);\nexport const convexPublicMutation = makeConvex(\n RuntimeAndFunctionType.ConvexMutation,\n \"public\",\n);\nexport const convexInternalMutation = makeConvex(\n RuntimeAndFunctionType.ConvexMutation,\n \"internal\",\n);\nexport const convexPublicAction = makeConvex(\n RuntimeAndFunctionType.ConvexAction,\n \"public\",\n);\nexport const convexInternalAction = makeConvex(\n RuntimeAndFunctionType.ConvexAction,\n \"internal\",\n);\nexport const convexPublicNodeAction = makeConvex(\n RuntimeAndFunctionType.NodeAction,\n \"public\",\n);\nexport const convexInternalNodeAction = makeConvex(\n RuntimeAndFunctionType.NodeAction,\n \"internal\",\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAaA,MAAa,SAAS;AAGtB,MAAa,kBAAkB,MAC7B,UAAU,YAAY,GAAG,OAAO;AAyLlC,MAAM,QAAQ,GACX,SAAS,QACX;AAED,MAAM,QAMF,wBACA,wBAOA,EACA,MACA,MACA,SACA,YAWG;AACH,mCAAkC,KAAK;AAEvC,QAAO,OAAO,OAAO,OAAO,OAAO,MAAM,EAAE;EACzC;EACA;EACA;EACA,oBAAoBA,QAA2B,MAAM,SAAS,MAAM;EACrE,CAAC;;AAGN,MAAa,cAAc,KAAKC,aAAoC,SAAS;AAC7E,MAAa,gBAAgB,KAC3BA,aACA,WACD;AACD,MAAa,iBAAiB,KAC5BC,gBACA,SACD;AACD,MAAa,mBAAmB,KAC9BA,gBACA,WACD;AACD,MAAa,eAAe,KAAKC,cAAqC,SAAS;AAC/E,MAAa,iBAAiB,KAC5BA,cACA,WACD;AAED,MAAa,mBAAmB,KAC9BC,YACA,SACD;AACD,MAAa,qBAAqB,KAChCA,YACA,WACD;AAgCD,MAAM,cAMF,wBACA,8BASA,SAMG;AACH,mCAAkC,KAAK;AAEvC,QAAO,OAAO,OAAO,OAAO,OAAO,MAAM,EAAE;EACzC;EACA;EACA;EACA,oBAAoBC,QAA2B;EAChD,CAAC;;AAGN,MAAa,oBAAoB,WAC/BJ,aACA,SACD;AACD,MAAa,sBAAsB,WACjCA,aACA,WACD;AACD,MAAa,uBAAuB,WAClCC,gBACA,SACD;AACD,MAAa,yBAAyB,WACpCA,gBACA,WACD;AACD,MAAa,qBAAqB,WAChCC,cACA,SACD;AACD,MAAa,uBAAuB,WAClCA,cACA,WACD;AACD,MAAa,yBAAyB,WACpCC,YACA,SACD;AACD,MAAa,2BAA2B,WACtCA,YACA,WACD"}
1
+ {"version":3,"file":"FunctionSpec.js","names":["FunctionProvenance.Confect","RuntimeAndFunctionType.ConvexQuery","RuntimeAndFunctionType.ConvexMutation","RuntimeAndFunctionType.ConvexAction","RuntimeAndFunctionType.NodeAction","FunctionProvenance.Convex"],"sources":["../src/FunctionSpec.ts"],"sourcesContent":["import type {\n FunctionType,\n FunctionVisibility,\n RegisteredAction,\n RegisteredMutation,\n RegisteredQuery,\n} from \"convex/server\";\nimport type { Schema } from \"effect\";\nimport { Predicate } from \"effect\";\nimport * as FunctionProvenance from \"./FunctionProvenance\";\nimport { validateConfectFunctionIdentifier } from \"./internal/utils\";\nimport * as RuntimeAndFunctionType from \"./RuntimeAndFunctionType\";\n\nexport const TypeId = \"@confect/core/FunctionSpec\";\nexport type TypeId = typeof TypeId;\n\nexport const isFunctionSpec = (u: unknown): u is AnyWithProps =>\n Predicate.hasProperty(u, TypeId);\n\nexport interface FunctionSpec<\n RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility_ extends FunctionVisibility,\n Name_ extends string,\n FunctionProvenance_ extends FunctionProvenance.FunctionProvenance,\n> {\n readonly [TypeId]: TypeId;\n readonly runtimeAndFunctionType: RuntimeAndFunctionType_;\n readonly functionVisibility: FunctionVisibility_;\n readonly name: Name_;\n readonly functionProvenance: FunctionProvenance_;\n}\n\nexport interface Any {\n readonly [TypeId]: TypeId;\n}\n\nexport interface AnyWithProps extends FunctionSpec<\n RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility,\n string,\n FunctionProvenance.FunctionProvenance\n> {}\n\nexport interface AnyConfect extends FunctionSpec<\n RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility,\n string,\n FunctionProvenance.AnyConfect\n> {}\n\nexport interface AnyConvex extends FunctionSpec<\n RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility,\n string,\n FunctionProvenance.AnyConvex\n> {}\n\nexport interface AnyWithPropsWithRuntime<\n Runtime extends RuntimeAndFunctionType.Runtime,\n> extends FunctionSpec<\n RuntimeAndFunctionType.WithRuntime<Runtime>,\n FunctionVisibility,\n string,\n FunctionProvenance.FunctionProvenance\n> {}\n\nexport interface AnyWithPropsWithFunctionType<\n RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,\n> extends FunctionSpec<\n RuntimeAndFunctionType_,\n FunctionVisibility,\n string,\n FunctionProvenance.FunctionProvenance\n> {}\n\nexport interface AnyWithPropsWithFunctionProvenance<\n FunctionProvenance_ extends FunctionProvenance.FunctionProvenance,\n> extends FunctionSpec<\n RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility,\n string,\n FunctionProvenance_\n> {}\n\nexport type GetRuntimeAndFunctionType<FunctionSpec_ extends AnyWithProps> =\n FunctionSpec_[\"runtimeAndFunctionType\"];\n\nexport type GetFunctionVisibility<FunctionSpec_ extends AnyWithProps> =\n FunctionSpec_[\"functionVisibility\"];\n\nexport type Name<FunctionSpec_ extends AnyWithProps> = FunctionSpec_[\"name\"];\n\nexport type Args<FunctionSpec_ extends AnyWithProps> = FunctionSpec_ extends {\n functionProvenance: {\n _tag: \"Confect\";\n args: infer ArgsSchema_ extends Schema.Schema.AnyNoContext;\n };\n}\n ? ArgsSchema_[\"Type\"]\n : FunctionSpec_ extends {\n functionProvenance: { _tag: \"Convex\"; _args: infer Args_ };\n }\n ? Args_\n : never;\n\nexport type Returns<FunctionSpec_ extends AnyWithProps> =\n FunctionSpec_ extends {\n functionProvenance: {\n _tag: \"Confect\";\n returns: infer ReturnsSchema_ extends Schema.Schema.AnyNoContext;\n };\n }\n ? ReturnsSchema_[\"Type\"]\n : FunctionSpec_ extends {\n functionProvenance: { _tag: \"Convex\"; _returns: infer Returns_ };\n }\n ? Awaited<Returns_>\n : never;\n\nexport type EncodedArgs<FunctionSpec_ extends AnyWithProps> =\n FunctionSpec_ extends {\n functionProvenance: {\n _tag: \"Confect\";\n args: infer ArgsSchema_ extends Schema.Schema.AnyNoContext;\n };\n }\n ? ArgsSchema_[\"Encoded\"]\n : FunctionSpec_ extends {\n functionProvenance: { _tag: \"Convex\"; _args: infer Args_ };\n }\n ? Args_\n : never;\n\nexport type EncodedReturns<FunctionSpec_ extends AnyWithProps> =\n FunctionSpec_ extends {\n functionProvenance: {\n _tag: \"Confect\";\n returns: infer ReturnsSchema_ extends Schema.Schema.AnyNoContext;\n };\n }\n ? ReturnsSchema_[\"Encoded\"]\n : FunctionSpec_ extends {\n functionProvenance: { _tag: \"Convex\"; _returns: infer Returns_ };\n }\n ? Returns_\n : never;\n\nexport type Error<FunctionSpec_ extends AnyWithProps> = FunctionSpec_ extends {\n functionProvenance: FunctionProvenance.Confect<\n any,\n any,\n infer ErrorSchema_ extends Schema.Schema.AnyNoContext\n >;\n}\n ? ErrorSchema_[\"Type\"]\n : never;\n\nexport type EncodedError<FunctionSpec_ extends AnyWithProps> =\n FunctionSpec_ extends {\n functionProvenance: FunctionProvenance.Confect<\n any,\n any,\n infer ErrorSchema_ extends Schema.Schema.AnyNoContext\n >;\n }\n ? ErrorSchema_[\"Encoded\"]\n : never;\n\nexport type WithName<\n FunctionSpec_ extends AnyWithProps,\n Name_ extends string,\n> = Extract<FunctionSpec_, { readonly name: Name_ }>;\n\nexport type WithRuntimeAndFunctionType<\n FunctionSpec_ extends AnyWithProps,\n RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,\n> = Extract<\n FunctionSpec_,\n { readonly runtimeAndFunctionType: RuntimeAndFunctionType_ }\n>;\n\nexport type WithFunctionType<\n FunctionSpec_ extends AnyWithProps,\n FunctionType_ extends FunctionType,\n> = Extract<\n FunctionSpec_,\n { readonly runtimeAndFunctionType: { readonly functionType: FunctionType_ } }\n>;\n\nexport type WithFunctionProvenance<\n FunctionSpec_ extends AnyWithProps,\n FunctionProvenance_ extends FunctionProvenance.FunctionProvenance,\n> = Extract<\n FunctionSpec_,\n { readonly functionProvenance: FunctionProvenance_ }\n>;\n\nexport type WithoutName<\n FunctionSpec_ extends AnyWithProps,\n Name_ extends Name<FunctionSpec_>,\n> = Exclude<FunctionSpec_, { readonly name: Name_ }>;\n\nconst Proto = {\n [TypeId]: TypeId,\n};\n\nconst make =\n <\n RuntimeAndFunctionType_ extends\n RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility_ extends FunctionVisibility,\n >(\n runtimeAndFunctionType: RuntimeAndFunctionType_,\n functionVisibility: FunctionVisibility_,\n ) =>\n <\n const Name_ extends string,\n Args_ extends Schema.Schema.AnyNoContext,\n Returns_ extends Schema.Schema.AnyNoContext,\n Error_ extends Schema.Schema.AnyNoContext = never,\n >({\n name,\n args,\n returns,\n error,\n }: {\n name: Name_;\n args: Args_;\n returns: Returns_;\n error?: Error_;\n }): FunctionSpec<\n RuntimeAndFunctionType_,\n FunctionVisibility_,\n Name_,\n FunctionProvenance.Confect<Args_, Returns_, Error_>\n > => {\n validateConfectFunctionIdentifier(name);\n\n return Object.assign(Object.create(Proto), {\n runtimeAndFunctionType,\n functionVisibility,\n name,\n functionProvenance: FunctionProvenance.Confect(args, returns, error),\n });\n };\n\nexport const publicQuery = make(RuntimeAndFunctionType.ConvexQuery, \"public\");\nexport const internalQuery = make(\n RuntimeAndFunctionType.ConvexQuery,\n \"internal\",\n);\nexport const publicMutation = make(\n RuntimeAndFunctionType.ConvexMutation,\n \"public\",\n);\nexport const internalMutation = make(\n RuntimeAndFunctionType.ConvexMutation,\n \"internal\",\n);\nexport const publicAction = make(RuntimeAndFunctionType.ConvexAction, \"public\");\nexport const internalAction = make(\n RuntimeAndFunctionType.ConvexAction,\n \"internal\",\n);\n\nexport const publicNodeAction = make(\n RuntimeAndFunctionType.NodeAction,\n \"public\",\n);\nexport const internalNodeAction = make(\n RuntimeAndFunctionType.NodeAction,\n \"internal\",\n);\n\ntype MatchingRegisteredFunction<\n RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility_ extends FunctionVisibility,\n> =\n RuntimeAndFunctionType.GetFunctionType<RuntimeAndFunctionType_> extends \"query\"\n ? RegisteredQuery<FunctionVisibility_, any, any>\n : RuntimeAndFunctionType.GetFunctionType<RuntimeAndFunctionType_> extends \"mutation\"\n ? RegisteredMutation<FunctionVisibility_, any, any>\n : RuntimeAndFunctionType.GetFunctionType<RuntimeAndFunctionType_> extends \"action\"\n ? RegisteredAction<FunctionVisibility_, any, any>\n : never;\n\ntype ExtractArgs<F> =\n F extends RegisteredQuery<any, infer A, any>\n ? A\n : F extends RegisteredMutation<any, infer A, any>\n ? A\n : F extends RegisteredAction<any, infer A, any>\n ? A\n : never;\n\ntype ExtractReturns<F> =\n F extends RegisteredQuery<any, any, infer R>\n ? R\n : F extends RegisteredMutation<any, any, infer R>\n ? R\n : F extends RegisteredAction<any, any, infer R>\n ? R\n : never;\n\nconst makeConvex =\n <\n RuntimeAndFunctionType_ extends\n RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility_ extends FunctionVisibility,\n >(\n runtimeAndFunctionType: RuntimeAndFunctionType_,\n functionVisibility: FunctionVisibility_,\n ) =>\n <\n F extends MatchingRegisteredFunction<\n RuntimeAndFunctionType_,\n FunctionVisibility_\n >,\n >() =>\n <const Name_ extends string>(\n name: Name_,\n ): FunctionSpec<\n RuntimeAndFunctionType_,\n FunctionVisibility_,\n Name_,\n FunctionProvenance.Convex<ExtractArgs<F>, ExtractReturns<F>>\n > => {\n validateConfectFunctionIdentifier(name);\n\n return Object.assign(Object.create(Proto), {\n runtimeAndFunctionType,\n functionVisibility,\n name,\n functionProvenance: FunctionProvenance.Convex<\n ExtractArgs<F>,\n ExtractReturns<F>\n >(),\n }) as any;\n };\n\nexport const convexPublicQuery = makeConvex(\n RuntimeAndFunctionType.ConvexQuery,\n \"public\",\n);\nexport const convexInternalQuery = makeConvex(\n RuntimeAndFunctionType.ConvexQuery,\n \"internal\",\n);\nexport const convexPublicMutation = makeConvex(\n RuntimeAndFunctionType.ConvexMutation,\n \"public\",\n);\nexport const convexInternalMutation = makeConvex(\n RuntimeAndFunctionType.ConvexMutation,\n \"internal\",\n);\nexport const convexPublicAction = makeConvex(\n RuntimeAndFunctionType.ConvexAction,\n \"public\",\n);\nexport const convexInternalAction = makeConvex(\n RuntimeAndFunctionType.ConvexAction,\n \"internal\",\n);\nexport const convexPublicNodeAction = makeConvex(\n RuntimeAndFunctionType.NodeAction,\n \"public\",\n);\nexport const convexInternalNodeAction = makeConvex(\n RuntimeAndFunctionType.NodeAction,\n \"internal\",\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAaA,MAAa,SAAS;AAGtB,MAAa,kBAAkB,MAC7B,UAAU,YAAY,GAAG,OAAO;AAyLlC,MAAM,QAAQ,GACX,SAAS,QACX;AAED,MAAM,QAMF,wBACA,wBAOA,EACA,MACA,MACA,SACA,YAWG;AACH,mCAAkC,KAAK;AAEvC,QAAO,OAAO,OAAO,OAAO,OAAO,MAAM,EAAE;EACzC;EACA;EACA;EACA,oBAAoBA,QAA2B,MAAM,SAAS,MAAM;EACrE,CAAC;;AAGN,MAAa,cAAc,KAAKC,aAAoC,SAAS;AAC7E,MAAa,gBAAgB,KAC3BA,aACA,WACD;AACD,MAAa,iBAAiB,KAC5BC,gBACA,SACD;AACD,MAAa,mBAAmB,KAC9BA,gBACA,WACD;AACD,MAAa,eAAe,KAAKC,cAAqC,SAAS;AAC/E,MAAa,iBAAiB,KAC5BA,cACA,WACD;AAED,MAAa,mBAAmB,KAC9BC,YACA,SACD;AACD,MAAa,qBAAqB,KAChCA,YACA,WACD;AAgCD,MAAM,cAMF,wBACA,8BASA,SAMG;AACH,mCAAkC,KAAK;AAEvC,QAAO,OAAO,OAAO,OAAO,OAAO,MAAM,EAAE;EACzC;EACA;EACA;EACA,oBAAoBC,QAGjB;EACJ,CAAC;;AAGN,MAAa,oBAAoB,WAC/BJ,aACA,SACD;AACD,MAAa,sBAAsB,WACjCA,aACA,WACD;AACD,MAAa,uBAAuB,WAClCC,gBACA,SACD;AACD,MAAa,yBAAyB,WACpCA,gBACA,WACD;AACD,MAAa,qBAAqB,WAChCC,cACA,SACD;AACD,MAAa,uBAAuB,WAClCA,cACA,WACD;AACD,MAAa,yBAAyB,WACpCC,YACA,SACD;AACD,MAAa,2BAA2B,WACtCA,YACA,WACD"}
@@ -3,11 +3,11 @@ import { AnyWithProps as AnyWithProps$1, AnyWithPropsWithRuntime as AnyWithProps
3
3
 
4
4
  //#region src/GroupSpec.d.ts
5
5
  declare namespace GroupSpec_d_exports {
6
- export { Any, AnyWithProps, AnyWithPropsWithRuntime, Functions, GroupNames, GroupSpec, Groups, Name, TypeId, WithName, isGroupSpec, make, makeNode };
6
+ export { Any, AnyWithProps, AnyWithPropsWithRuntime, Functions, GroupNames, GroupSpec, Groups, Name, NamedAt, TypeId, WithName, isGroupSpec, make, makeAt, makeNode, makeNodeAt, withName };
7
7
  }
8
8
  declare const TypeId = "@confect/core/GroupSpec";
9
9
  type TypeId = typeof TypeId;
10
- declare const isGroupSpec: (u: unknown) => u is Any;
10
+ declare const isGroupSpec: (u: unknown) => u is AnyWithProps;
11
11
  interface GroupSpec<Runtime$2 extends Runtime, Name_ extends string, Functions_ extends AnyWithPropsWithRuntime$1<Runtime$2> = never, Groups_ extends AnyWithPropsWithRuntime<Runtime$2> = never> {
12
12
  readonly [TypeId]: TypeId;
13
13
  readonly runtime: Runtime$2;
@@ -16,6 +16,7 @@ interface GroupSpec<Runtime$2 extends Runtime, Name_ extends string, Functions_
16
16
  readonly groups: { [GroupName in Name<Groups_>]: WithName<Groups_, GroupName> };
17
17
  addFunction<Function extends AnyWithPropsWithRuntime$1<Runtime$2>>(function_: Function): GroupSpec<Runtime$2, Name_, Functions_ | Function, Groups_>;
18
18
  addGroup<Group extends AnyWithPropsWithRuntime<Runtime$2>>(group: Group): GroupSpec<Runtime$2, Name_, Functions_, Groups_ | Group>;
19
+ addGroupAt<const AtName extends string, Group extends AnyWithPropsWithRuntime<Runtime$2>>(name: AtName, group: Group): GroupSpec<Runtime$2, Name_, Functions_, Groups_ | NamedAt<Group, AtName>>;
19
20
  }
20
21
  interface Any {
21
22
  readonly [TypeId]: TypeId;
@@ -29,8 +30,15 @@ type GroupNames<Group extends AnyWithProps> = [Groups<Group>] extends [never] ?
29
30
  type WithName<Group extends AnyWithProps, Name_ extends Name<Group>> = Extract<Group, {
30
31
  readonly name: Name_;
31
32
  }>;
32
- declare const make: <const Name_ extends string>(name: Name_) => GroupSpec<"Convex", Name_>;
33
- declare const makeNode: <const Name_ extends string>(name: Name_) => GroupSpec<"Node", Name_>;
33
+ /** Assigns a segment name to a leaf group created with {@link make} for typing and refs. */
34
+ type NamedAt<Group extends Any, Name_ extends string> = Omit<Group, "name"> & {
35
+ readonly name: Name_;
36
+ };
37
+ declare const make: () => GroupSpec<"Convex", "">;
38
+ declare const makeAt: <const Name_ extends string>(name: Name_) => GroupSpec<"Convex", Name_>;
39
+ declare const makeNode: () => GroupSpec<"Node", "">;
40
+ declare const makeNodeAt: <const Name_ extends string>(name: Name_) => GroupSpec<"Node", Name_>;
41
+ declare const withName: <const Name_ extends string>(name: Name_, group: Any) => AnyWithProps;
34
42
  //#endregion
35
- export { Any, AnyWithProps, AnyWithPropsWithRuntime, Functions, GroupNames, GroupSpec, GroupSpec_d_exports, Groups, Name, TypeId, WithName, isGroupSpec, make, makeNode };
43
+ export { Any, AnyWithProps, AnyWithPropsWithRuntime, Functions, GroupNames, GroupSpec, GroupSpec_d_exports, Groups, Name, NamedAt, TypeId, WithName, isGroupSpec, make, makeAt, makeNode, makeNodeAt, withName };
36
44
  //# sourceMappingURL=GroupSpec.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"GroupSpec.d.ts","names":[],"sources":["../src/GroupSpec.ts"],"mappings":";;;;;;;cAKa,MAAA;AAAA,KACD,MAAA,UAAgB,MAAA;AAAA,cAEf,WAAA,GAAe,CAAA,cAAa,CAAA,IAAK,GAAA;AAAA,UAG7B,SAAA,mBACC,OAAA,2CAEG,yBAAA,CAAqC,SAAA,2BACxC,uBAAA,CAAwB,SAAA;EAAA,UAE9B,MAAA,GAAS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A;AAAA,KAGd,IAAA,eAAmB,YAAA,IAAgB,KAAA;AAAA,KAEnC,SAAA,eAAwB,YAAA,IAClC,KAAA,oBAAyB,KAAA;AAAA,KAEf,MAAA,eAAqB,YAAA,IAC/B,KAAA,iBAAsB,KAAA;AAAA,KAEZ,UAAA,eAAyB,YAAA,KAAiB,MAAA,CAAO,KAAA,6BAIzD,IAAA,CAAK,MAAA,CAAO,KAAA;AAAA,KAEJ,QAAA,eACI,YAAA,gBACA,IAAA,CAAK,KAAA,KACjB,OAAA,CAAQ,KAAA;EAAA,SAAkB,IAAA,EAAM,KAAA;AAAA;;KAGxB,OAAA,eAAsB,GAAA,0BAA6B,IAAA,CAC7D,KAAA;EAAA,SAGS,IAAA,EAAM,KAAA;AAAA;AAAA,cAoEJ,IAAA,QAAW,SAAA;AAAA,cAQX,MAAA,+BACX,IAAA,EAAM,KAAA,KACL,SAAA,WAAoB,KAAA;AAAA,cAWV,QAAA,QAAe,SAAA;AAAA,cAQf,UAAA,+BACX,IAAA,EAAM,KAAA,KACL,SAAA,SAAkB,KAAA;AAAA,cAWR,QAAA,+BACX,IAAA,EAAM,KAAA,EACN,KAAA,EAAO,GAAA,KACN,YAAA"}
package/dist/GroupSpec.js CHANGED
@@ -7,7 +7,10 @@ var GroupSpec_exports = /* @__PURE__ */ __exportAll({
7
7
  TypeId: () => TypeId,
8
8
  isGroupSpec: () => isGroupSpec,
9
9
  make: () => make,
10
- makeNode: () => makeNode
10
+ makeAt: () => makeAt,
11
+ makeNode: () => makeNode,
12
+ makeNodeAt: () => makeNodeAt,
13
+ withName: () => withName
11
14
  });
12
15
  const TypeId = "@confect/core/GroupSpec";
13
16
  const isGroupSpec = (u) => Predicate.hasProperty(u, TypeId);
@@ -31,6 +34,16 @@ const Proto = {
31
34
  functions: this_.functions,
32
35
  groups: Record.set(this_.groups, group_.name, group_)
33
36
  });
37
+ },
38
+ addGroupAt(name, group) {
39
+ const this_ = this;
40
+ const group_ = group;
41
+ return makeProto({
42
+ runtime: this_.runtime,
43
+ name: this_.name,
44
+ functions: this_.functions,
45
+ groups: Record.set(this_.groups, name, withName(name, group_))
46
+ });
34
47
  }
35
48
  };
36
49
  const makeProto = ({ runtime, name, functions, groups }) => Object.assign(Object.create(Proto), {
@@ -39,7 +52,13 @@ const makeProto = ({ runtime, name, functions, groups }) => Object.assign(Object
39
52
  functions,
40
53
  groups
41
54
  });
42
- const make = (name) => {
55
+ const make = () => makeProto({
56
+ runtime: "Convex",
57
+ name: "",
58
+ functions: Record.empty(),
59
+ groups: Record.empty()
60
+ });
61
+ const makeAt = (name) => {
43
62
  validateConfectFunctionIdentifier(name);
44
63
  return makeProto({
45
64
  runtime: "Convex",
@@ -48,7 +67,13 @@ const make = (name) => {
48
67
  groups: Record.empty()
49
68
  });
50
69
  };
51
- const makeNode = (name) => {
70
+ const makeNode = () => makeProto({
71
+ runtime: "Node",
72
+ name: "",
73
+ functions: Record.empty(),
74
+ groups: Record.empty()
75
+ });
76
+ const makeNodeAt = (name) => {
52
77
  validateConfectFunctionIdentifier(name);
53
78
  return makeProto({
54
79
  runtime: "Node",
@@ -57,7 +82,13 @@ const makeNode = (name) => {
57
82
  groups: Record.empty()
58
83
  });
59
84
  };
85
+ const withName = (name, group) => {
86
+ validateConfectFunctionIdentifier(name);
87
+ const group_ = group;
88
+ if (group_.name === name) return group_;
89
+ return Object.assign(group_, { name });
90
+ };
60
91
 
61
92
  //#endregion
62
- export { GroupSpec_exports, TypeId, isGroupSpec, make, makeNode };
93
+ export { GroupSpec_exports, TypeId, isGroupSpec, make, makeAt, makeNode, makeNodeAt, withName };
63
94
  //# sourceMappingURL=GroupSpec.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"GroupSpec.js","names":[],"sources":["../src/GroupSpec.ts"],"sourcesContent":["import { Predicate, Record } from \"effect\";\nimport type * as FunctionSpec from \"./FunctionSpec\";\nimport type * as RuntimeAndFunctionType from \"./RuntimeAndFunctionType\";\nimport { validateConfectFunctionIdentifier } from \"./internal/utils\";\n\nexport const TypeId = \"@confect/core/GroupSpec\";\nexport type TypeId = typeof TypeId;\n\nexport const isGroupSpec = (u: unknown): u is Any =>\n Predicate.hasProperty(u, TypeId);\n\nexport interface GroupSpec<\n Runtime extends RuntimeAndFunctionType.Runtime,\n Name_ extends string,\n Functions_ extends FunctionSpec.AnyWithPropsWithRuntime<Runtime> = never,\n Groups_ extends AnyWithPropsWithRuntime<Runtime> = never,\n> {\n readonly [TypeId]: TypeId;\n readonly runtime: Runtime;\n readonly name: Name_;\n readonly functions: {\n [FunctionName in FunctionSpec.Name<\n FunctionSpec.AnyWithPropsWithRuntime<Runtime>\n >]: FunctionSpec.WithName<Functions_, FunctionName>;\n };\n readonly groups: {\n [GroupName in Name<Groups_>]: WithName<Groups_, GroupName>;\n };\n\n addFunction<Function extends FunctionSpec.AnyWithPropsWithRuntime<Runtime>>(\n function_: Function,\n ): GroupSpec<Runtime, Name_, Functions_ | Function, Groups_>;\n\n addGroup<Group extends AnyWithPropsWithRuntime<Runtime>>(\n group: Group,\n ): GroupSpec<Runtime, Name_, Functions_, Groups_ | Group>;\n}\n\nexport interface Any {\n readonly [TypeId]: TypeId;\n}\n\nexport interface AnyWithProps extends GroupSpec<\n RuntimeAndFunctionType.Runtime,\n string,\n FunctionSpec.AnyWithProps,\n AnyWithProps\n> {}\n\nexport interface AnyWithPropsWithRuntime<\n Runtime extends RuntimeAndFunctionType.Runtime,\n> extends GroupSpec<\n Runtime,\n string,\n FunctionSpec.AnyWithPropsWithRuntime<Runtime>,\n AnyWithPropsWithRuntime<Runtime>\n> {}\n\nexport type Name<Group extends AnyWithProps> = Group[\"name\"];\n\nexport type Functions<Group extends AnyWithProps> =\n Group[\"functions\"][keyof Group[\"functions\"]];\n\nexport type Groups<Group extends AnyWithProps> =\n Group[\"groups\"][keyof Group[\"groups\"]];\n\nexport type GroupNames<Group extends AnyWithProps> = [Groups<Group>] extends [\n never,\n]\n ? never\n : Name<Groups<Group>>;\n\nexport type WithName<\n Group extends AnyWithProps,\n Name_ extends Name<Group>,\n> = Extract<Group, { readonly name: Name_ }>;\n\nconst Proto = {\n [TypeId]: TypeId,\n\n addFunction<Function extends FunctionSpec.AnyWithProps>(\n this: Any,\n function_: Function,\n ) {\n const this_ = this as AnyWithProps;\n\n return makeProto({\n runtime: this_.runtime,\n name: this_.name,\n functions: Record.set(this_.functions, function_.name, function_),\n groups: this_.groups,\n });\n },\n\n addGroup<Group extends Any>(this: Any, group: Group) {\n const this_ = this as AnyWithProps;\n const group_ = group as unknown as AnyWithProps;\n\n return makeProto({\n runtime: this_.runtime,\n name: this_.name,\n functions: this_.functions,\n groups: Record.set(this_.groups, group_.name, group_),\n });\n },\n};\n\nconst makeProto = <\n Runtime extends RuntimeAndFunctionType.Runtime,\n Name_ extends string,\n Functions_ extends FunctionSpec.AnyWithPropsWithRuntime<Runtime>,\n Groups_ extends AnyWithPropsWithRuntime<Runtime>,\n>({\n runtime,\n name,\n functions,\n groups,\n}: {\n runtime: Runtime;\n name: Name_;\n functions: Record.ReadonlyRecord<string, Functions_>;\n groups: Record.ReadonlyRecord<string, Groups_>;\n}): GroupSpec<Runtime, Name_, Functions_, Groups_> =>\n Object.assign(Object.create(Proto), {\n runtime,\n name,\n functions,\n groups,\n });\n\nexport const make = <const Name_ extends string>(\n name: Name_,\n): GroupSpec<\"Convex\", Name_> => {\n validateConfectFunctionIdentifier(name);\n\n return makeProto({\n runtime: \"Convex\",\n name,\n functions: Record.empty(),\n groups: Record.empty(),\n });\n};\n\nexport const makeNode = <const Name_ extends string>(\n name: Name_,\n): GroupSpec<\"Node\", Name_> => {\n validateConfectFunctionIdentifier(name);\n\n return makeProto({\n runtime: \"Node\",\n name,\n functions: Record.empty(),\n groups: Record.empty(),\n });\n};\n"],"mappings":";;;;;;;;;;;AAKA,MAAa,SAAS;AAGtB,MAAa,eAAe,MAC1B,UAAU,YAAY,GAAG,OAAO;AAoElC,MAAM,QAAQ;EACX,SAAS;CAEV,YAEE,WACA;EACA,MAAM,QAAQ;AAEd,SAAO,UAAU;GACf,SAAS,MAAM;GACf,MAAM,MAAM;GACZ,WAAW,OAAO,IAAI,MAAM,WAAW,UAAU,MAAM,UAAU;GACjE,QAAQ,MAAM;GACf,CAAC;;CAGJ,SAAuC,OAAc;EACnD,MAAM,QAAQ;EACd,MAAM,SAAS;AAEf,SAAO,UAAU;GACf,SAAS,MAAM;GACf,MAAM,MAAM;GACZ,WAAW,MAAM;GACjB,QAAQ,OAAO,IAAI,MAAM,QAAQ,OAAO,MAAM,OAAO;GACtD,CAAC;;CAEL;AAED,MAAM,aAKJ,EACA,SACA,MACA,WACA,aAOA,OAAO,OAAO,OAAO,OAAO,MAAM,EAAE;CAClC;CACA;CACA;CACA;CACD,CAAC;AAEJ,MAAa,QACX,SAC+B;AAC/B,mCAAkC,KAAK;AAEvC,QAAO,UAAU;EACf,SAAS;EACT;EACA,WAAW,OAAO,OAAO;EACzB,QAAQ,OAAO,OAAO;EACvB,CAAC;;AAGJ,MAAa,YACX,SAC6B;AAC7B,mCAAkC,KAAK;AAEvC,QAAO,UAAU;EACf,SAAS;EACT;EACA,WAAW,OAAO,OAAO;EACzB,QAAQ,OAAO,OAAO;EACvB,CAAC"}
1
+ {"version":3,"file":"GroupSpec.js","names":[],"sources":["../src/GroupSpec.ts"],"sourcesContent":["import { Predicate, Record } from \"effect\";\nimport type * as FunctionSpec from \"./FunctionSpec\";\nimport type * as RuntimeAndFunctionType from \"./RuntimeAndFunctionType\";\nimport { validateConfectFunctionIdentifier } from \"./internal/utils\";\n\nexport const TypeId = \"@confect/core/GroupSpec\";\nexport type TypeId = typeof TypeId;\n\nexport const isGroupSpec = (u: unknown): u is AnyWithProps =>\n Predicate.hasProperty(u, TypeId);\n\nexport interface GroupSpec<\n Runtime extends RuntimeAndFunctionType.Runtime,\n Name_ extends string,\n Functions_ extends FunctionSpec.AnyWithPropsWithRuntime<Runtime> = never,\n Groups_ extends AnyWithPropsWithRuntime<Runtime> = never,\n> {\n readonly [TypeId]: TypeId;\n readonly runtime: Runtime;\n readonly name: Name_;\n readonly functions: {\n [FunctionName in FunctionSpec.Name<\n FunctionSpec.AnyWithPropsWithRuntime<Runtime>\n >]: FunctionSpec.WithName<Functions_, FunctionName>;\n };\n readonly groups: {\n [GroupName in Name<Groups_>]: WithName<Groups_, GroupName>;\n };\n\n addFunction<Function extends FunctionSpec.AnyWithPropsWithRuntime<Runtime>>(\n function_: Function,\n ): GroupSpec<Runtime, Name_, Functions_ | Function, Groups_>;\n\n addGroup<Group extends AnyWithPropsWithRuntime<Runtime>>(\n group: Group,\n ): GroupSpec<Runtime, Name_, Functions_, Groups_ | Group>;\n\n addGroupAt<\n const AtName extends string,\n Group extends AnyWithPropsWithRuntime<Runtime>,\n >(\n name: AtName,\n group: Group,\n ): GroupSpec<Runtime, Name_, Functions_, Groups_ | NamedAt<Group, AtName>>;\n}\n\nexport interface Any {\n readonly [TypeId]: TypeId;\n}\n\nexport interface AnyWithProps extends GroupSpec<\n RuntimeAndFunctionType.Runtime,\n string,\n FunctionSpec.AnyWithProps,\n AnyWithProps\n> {}\n\nexport interface AnyWithPropsWithRuntime<\n Runtime extends RuntimeAndFunctionType.Runtime,\n> extends GroupSpec<\n Runtime,\n string,\n FunctionSpec.AnyWithPropsWithRuntime<Runtime>,\n AnyWithPropsWithRuntime<Runtime>\n> {}\n\nexport type Name<Group extends AnyWithProps> = Group[\"name\"];\n\nexport type Functions<Group extends AnyWithProps> =\n Group[\"functions\"][keyof Group[\"functions\"]];\n\nexport type Groups<Group extends AnyWithProps> =\n Group[\"groups\"][keyof Group[\"groups\"]];\n\nexport type GroupNames<Group extends AnyWithProps> = [Groups<Group>] extends [\n never,\n]\n ? never\n : Name<Groups<Group>>;\n\nexport type WithName<\n Group extends AnyWithProps,\n Name_ extends Name<Group>,\n> = Extract<Group, { readonly name: Name_ }>;\n\n/** Assigns a segment name to a leaf group created with {@link make} for typing and refs. */\nexport type NamedAt<Group extends Any, Name_ extends string> = Omit<\n Group,\n \"name\"\n> & {\n readonly name: Name_;\n};\n\nconst Proto = {\n [TypeId]: TypeId,\n\n addFunction<Function extends FunctionSpec.AnyWithProps>(\n this: Any,\n function_: Function,\n ) {\n const this_ = this as AnyWithProps;\n\n return makeProto({\n runtime: this_.runtime,\n name: this_.name,\n functions: Record.set(this_.functions, function_.name, function_),\n groups: this_.groups,\n });\n },\n\n addGroup<Group extends Any>(this: Any, group: Group) {\n const this_ = this as AnyWithProps;\n const group_ = group as unknown as AnyWithProps;\n\n return makeProto({\n runtime: this_.runtime,\n name: this_.name,\n functions: this_.functions,\n groups: Record.set(this_.groups, group_.name, group_),\n });\n },\n\n addGroupAt<Group extends Any>(this: Any, name: string, group: Group) {\n const this_ = this as AnyWithProps;\n const group_ = group as unknown as AnyWithProps;\n\n return makeProto({\n runtime: this_.runtime,\n name: this_.name,\n functions: this_.functions,\n groups: Record.set(this_.groups, name, withName(name, group_)),\n });\n },\n};\n\nconst makeProto = <\n Runtime extends RuntimeAndFunctionType.Runtime,\n Name_ extends string,\n Functions_ extends FunctionSpec.AnyWithPropsWithRuntime<Runtime>,\n Groups_ extends AnyWithPropsWithRuntime<Runtime>,\n>({\n runtime,\n name,\n functions,\n groups,\n}: {\n runtime: Runtime;\n name: Name_;\n functions: Record.ReadonlyRecord<string, Functions_>;\n groups: Record.ReadonlyRecord<string, Groups_>;\n}): GroupSpec<Runtime, Name_, Functions_, Groups_> =>\n Object.assign(Object.create(Proto), {\n runtime,\n name,\n functions,\n groups,\n });\n\nexport const make = (): GroupSpec<\"Convex\", \"\"> =>\n makeProto({\n runtime: \"Convex\",\n name: \"\",\n functions: Record.empty(),\n groups: Record.empty(),\n });\n\nexport const makeAt = <const Name_ extends string>(\n name: Name_,\n): GroupSpec<\"Convex\", Name_> => {\n validateConfectFunctionIdentifier(name);\n\n return makeProto({\n runtime: \"Convex\",\n name,\n functions: Record.empty(),\n groups: Record.empty(),\n });\n};\n\nexport const makeNode = (): GroupSpec<\"Node\", \"\"> =>\n makeProto({\n runtime: \"Node\",\n name: \"\",\n functions: Record.empty(),\n groups: Record.empty(),\n });\n\nexport const makeNodeAt = <const Name_ extends string>(\n name: Name_,\n): GroupSpec<\"Node\", Name_> => {\n validateConfectFunctionIdentifier(name);\n\n return makeProto({\n runtime: \"Node\",\n name,\n functions: Record.empty(),\n groups: Record.empty(),\n });\n};\n\nexport const withName = <const Name_ extends string>(\n name: Name_,\n group: Any,\n): AnyWithProps => {\n validateConfectFunctionIdentifier(name);\n const group_ = group as AnyWithProps;\n\n if (group_.name === name) {\n return group_;\n }\n\n // Keep object identity so impls can pass the same GroupSpec instance\n // imported from a sibling `.spec.ts` into `resolveGroupPath`.\n return Object.assign(group_, { name }) as AnyWithProps;\n};\n"],"mappings":";;;;;;;;;;;;;;AAKA,MAAa,SAAS;AAGtB,MAAa,eAAe,MAC1B,UAAU,YAAY,GAAG,OAAO;AAoFlC,MAAM,QAAQ;EACX,SAAS;CAEV,YAEE,WACA;EACA,MAAM,QAAQ;AAEd,SAAO,UAAU;GACf,SAAS,MAAM;GACf,MAAM,MAAM;GACZ,WAAW,OAAO,IAAI,MAAM,WAAW,UAAU,MAAM,UAAU;GACjE,QAAQ,MAAM;GACf,CAAC;;CAGJ,SAAuC,OAAc;EACnD,MAAM,QAAQ;EACd,MAAM,SAAS;AAEf,SAAO,UAAU;GACf,SAAS,MAAM;GACf,MAAM,MAAM;GACZ,WAAW,MAAM;GACjB,QAAQ,OAAO,IAAI,MAAM,QAAQ,OAAO,MAAM,OAAO;GACtD,CAAC;;CAGJ,WAAyC,MAAc,OAAc;EACnE,MAAM,QAAQ;EACd,MAAM,SAAS;AAEf,SAAO,UAAU;GACf,SAAS,MAAM;GACf,MAAM,MAAM;GACZ,WAAW,MAAM;GACjB,QAAQ,OAAO,IAAI,MAAM,QAAQ,MAAM,SAAS,MAAM,OAAO,CAAC;GAC/D,CAAC;;CAEL;AAED,MAAM,aAKJ,EACA,SACA,MACA,WACA,aAOA,OAAO,OAAO,OAAO,OAAO,MAAM,EAAE;CAClC;CACA;CACA;CACA;CACD,CAAC;AAEJ,MAAa,aACX,UAAU;CACR,SAAS;CACT,MAAM;CACN,WAAW,OAAO,OAAO;CACzB,QAAQ,OAAO,OAAO;CACvB,CAAC;AAEJ,MAAa,UACX,SAC+B;AAC/B,mCAAkC,KAAK;AAEvC,QAAO,UAAU;EACf,SAAS;EACT;EACA,WAAW,OAAO,OAAO;EACzB,QAAQ,OAAO,OAAO;EACvB,CAAC;;AAGJ,MAAa,iBACX,UAAU;CACR,SAAS;CACT,MAAM;CACN,WAAW,OAAO,OAAO;CACzB,QAAQ,OAAO,OAAO;CACvB,CAAC;AAEJ,MAAa,cACX,SAC6B;AAC7B,mCAAkC,KAAK;AAEvC,QAAO,UAAU;EACf,SAAS;EACT;EACA,WAAW,OAAO,OAAO;EACzB,QAAQ,OAAO,OAAO;EACvB,CAAC;;AAGJ,MAAa,YACX,MACA,UACiB;AACjB,mCAAkC,KAAK;CACvC,MAAM,SAAS;AAEf,KAAI,OAAO,SAAS,KAClB,QAAO;AAKT,QAAO,OAAO,OAAO,QAAQ,EAAE,MAAM,CAAC"}
package/dist/Refs.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { AnyWithProps, GetFunctionVisibility, GetRuntimeAndFunctionType, Name as Name$1, WithName } from "./FunctionSpec.js";
2
2
  import { AnyWithProps as AnyWithProps$1, Functions, GroupSpec, Groups, Name as Name$2, WithName as WithName$1 } from "./GroupSpec.js";
3
- import { Any, AnyInternal, AnyPublic, FromFunctionSpec, Ref } from "./Ref.js";
3
+ import { Any, AnyInternal, AnyPublic, FromFunctionSpec, Ref as Ref$1 } from "./Ref.js";
4
4
  import { AnyWithPropsWithRuntime, Groups as Groups$1 } from "./Spec.js";
5
5
  import { Types } from "effect";
6
6
 
@@ -11,7 +11,7 @@ declare namespace Refs_d_exports {
11
11
  type Refs<ConvexSpec extends AnyWithPropsWithRuntime<"Convex">, NodeSpec extends AnyWithPropsWithRuntime<"Node"> = never, Predicate extends Any = Any> = Types.Simplify<OmitEmpty<Helper<Groups$1<ConvexSpec> | (NodeSpec extends never ? never : GroupSpec<"Node", "node", never, NodeSpec["groups"][keyof NodeSpec["groups"]]>), Predicate>>>;
12
12
  type GroupRefs<Group extends AnyWithProps$1, Predicate extends Any> = Types.Simplify<OmitEmpty<Helper<Groups<Group>, Predicate>> & FilteredFunctions<Functions<Group>, Predicate>>;
13
13
  type OmitEmpty<T> = { [K in keyof T as keyof T[K] extends never ? never : K]: T[K] };
14
- type FunctionSpecMatchesPredicate<FunctionSpec_ extends AnyWithProps, Predicate extends Any> = Ref<GetRuntimeAndFunctionType<FunctionSpec_>, GetFunctionVisibility<FunctionSpec_>, any, any> extends Predicate ? true : false;
14
+ type FunctionSpecMatchesPredicate<FunctionSpec_ extends AnyWithProps, Predicate extends Any> = Ref$1<GetRuntimeAndFunctionType<FunctionSpec_>, GetFunctionVisibility<FunctionSpec_>, any, any> extends Predicate ? true : false;
15
15
  type FilteredFunctions<FunctionSpecs extends AnyWithProps, Predicate extends Any> = { [Name in Name$1<FunctionSpecs> as WithName<FunctionSpecs, Name> extends infer FunctionSpec_ extends AnyWithProps ? FunctionSpecMatchesPredicate<FunctionSpec_, Predicate> extends true ? Name : never : never]: WithName<FunctionSpecs, Name> extends infer F extends AnyWithProps ? FromFunctionSpec<F> : never };
16
16
  type Helper<Groups extends AnyWithProps$1, Predicate extends Any> = { [GroupName in Name$2<Groups>]: WithName$1<Groups, GroupName> extends infer Group extends AnyWithProps$1 ? GroupRefs<Group, Predicate> : never };
17
17
  declare const make: <ConvexSpec extends AnyWithPropsWithRuntime<"Convex">, NodeSpec extends AnyWithPropsWithRuntime<"Node"> = never>(convexSpec: ConvexSpec, nodeSpec?: NodeSpec) => {
@@ -1 +1 @@
1
- {"version":3,"file":"Refs.d.ts","names":[],"sources":["../src/Refs.ts"],"mappings":";;;;;;;;;;KAOY,IAAA,oBACS,uBAAA,6BACF,uBAAA,oCACC,GAAA,GAAU,GAAA,IAC1B,KA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.js CHANGED
@@ -1,24 +1,29 @@
1
1
  import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
- import { makeNode } from "./GroupSpec.js";
2
+ import { makeNodeAt } from "./GroupSpec.js";
3
3
  import { getConvexFunctionName, make as make$1 } from "./Ref.js";
4
- import { Array, Record, pipe } from "effect";
4
+ import { Array, Option, Record, pipe } from "effect";
5
5
 
6
6
  //#region src/Refs.ts
7
7
  var Refs_exports = /* @__PURE__ */ __exportAll({ make: () => make });
8
8
  const make = (convexSpec, nodeSpec) => {
9
- const nodeGroup = nodeSpec ? Array.reduce(Record.values(nodeSpec.groups), makeNode("node"), (nodeGroupSpec, group) => nodeGroupSpec.addGroup(group)) : null;
10
- const refs = makeHelper(nodeGroup ? {
11
- ...convexSpec.groups,
12
- node: nodeGroup
13
- } : convexSpec.groups);
9
+ const refs = makeHelper(Option.fromNullable(nodeSpec).pipe(Option.map((nodeSpec_) => Array.reduce(Record.toEntries(nodeSpec_.groups), makeNodeAt("node"), (nodeGroupSpec, [name, group]) => nodeGroupSpec.addGroupAt(name, group))), Option.match({
10
+ onNone: () => convexSpec.groups,
11
+ onSome: (nodeGroup) => ({
12
+ ...convexSpec.groups,
13
+ node: nodeGroup
14
+ })
15
+ })));
14
16
  return {
15
17
  public: refs,
16
18
  internal: refs
17
19
  };
18
20
  };
19
- const makeHelper = (groups, functionNamespace = null) => pipe(groups, Record.map((group) => {
20
- const currentFunctionNamespace = functionNamespace ? `${functionNamespace}/${group.name}` : group.name;
21
- return Record.union(makeHelper(group.groups, currentFunctionNamespace), Record.map(group.functions, (function_) => make$1(currentFunctionNamespace, function_)), (_subGroup, _function) => {
21
+ const makeHelper = (groups, functionNamespace = Option.none()) => pipe(groups, Record.map((group, name) => {
22
+ const currentFunctionNamespace = Option.match(functionNamespace, {
23
+ onNone: () => name,
24
+ onSome: (parentNamespace) => `${parentNamespace}/${name}`
25
+ });
26
+ return Record.union(makeHelper(group.groups, Option.some(currentFunctionNamespace)), Record.map(group.functions, (function_) => make$1(currentFunctionNamespace, function_)), (_subGroup, _function) => {
22
27
  throw new Error(`Group and function at same level have same name ('${getConvexFunctionName(_function)}')`);
23
28
  });
24
29
  }));
package/dist/Refs.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Refs.js","names":["GroupSpec.makeNode","Ref.make","Ref.getConvexFunctionName"],"sources":["../src/Refs.ts"],"sourcesContent":["import type { Types } from \"effect\";\nimport { Array, pipe, Record } from \"effect\";\nimport type * as FunctionSpec from \"./FunctionSpec\";\nimport * as GroupSpec from \"./GroupSpec\";\nimport * as Ref from \"./Ref\";\nimport type * as Spec from \"./Spec\";\n\nexport type Refs<\n ConvexSpec extends Spec.AnyWithPropsWithRuntime<\"Convex\">,\n NodeSpec extends Spec.AnyWithPropsWithRuntime<\"Node\"> = never,\n Predicate extends Ref.Any = Ref.Any,\n> = Types.Simplify<\n OmitEmpty<\n Helper<\n | Spec.Groups<ConvexSpec>\n | (NodeSpec extends never\n ? never\n : GroupSpec.GroupSpec<\n \"Node\",\n \"node\",\n never,\n NodeSpec[\"groups\"][keyof NodeSpec[\"groups\"]]\n >),\n Predicate\n >\n >\n>;\n\ntype GroupRefs<\n Group extends GroupSpec.AnyWithProps,\n Predicate extends Ref.Any,\n> = Types.Simplify<\n OmitEmpty<Helper<GroupSpec.Groups<Group>, Predicate>> &\n FilteredFunctions<GroupSpec.Functions<Group>, Predicate>\n>;\n\ntype OmitEmpty<T> = {\n [K in keyof T as keyof T[K] extends never ? never : K]: T[K];\n};\n\ntype FunctionSpecMatchesPredicate<\n FunctionSpec_ extends FunctionSpec.AnyWithProps,\n Predicate extends Ref.Any,\n> =\n Ref.Ref<\n FunctionSpec.GetRuntimeAndFunctionType<FunctionSpec_>,\n FunctionSpec.GetFunctionVisibility<FunctionSpec_>,\n any,\n any\n > extends Predicate\n ? true\n : false;\n\ntype FilteredFunctions<\n FunctionSpecs extends FunctionSpec.AnyWithProps,\n Predicate extends Ref.Any,\n> = {\n [Name in FunctionSpec.Name<FunctionSpecs> as FunctionSpec.WithName<\n FunctionSpecs,\n Name\n > extends infer FunctionSpec_ extends FunctionSpec.AnyWithProps\n ? FunctionSpecMatchesPredicate<FunctionSpec_, Predicate> extends true\n ? Name\n : never\n : never]: FunctionSpec.WithName<FunctionSpecs, Name> extends infer F extends\n FunctionSpec.AnyWithProps\n ? Ref.FromFunctionSpec<F>\n : never;\n};\n\ntype Helper<\n Groups extends GroupSpec.AnyWithProps,\n Predicate extends Ref.Any,\n> = {\n [GroupName in GroupSpec.Name<Groups>]: GroupSpec.WithName<\n Groups,\n GroupName\n > extends infer Group extends GroupSpec.AnyWithProps\n ? GroupRefs<Group, Predicate>\n : never;\n};\n\ntype Any =\n | {\n readonly [key: string]: Any;\n }\n | Ref.Any;\n\nexport const make = <\n ConvexSpec extends Spec.AnyWithPropsWithRuntime<\"Convex\">,\n NodeSpec extends Spec.AnyWithPropsWithRuntime<\"Node\"> = never,\n>(\n convexSpec: ConvexSpec,\n nodeSpec?: NodeSpec,\n): {\n public: Refs<ConvexSpec, NodeSpec, Ref.AnyPublic>;\n internal: Refs<ConvexSpec, NodeSpec, Ref.AnyInternal>;\n} => {\n const nodeGroup = nodeSpec\n ? Array.reduce(\n Record.values(nodeSpec.groups),\n GroupSpec.makeNode(\"node\"),\n (nodeGroupSpec, group) => nodeGroupSpec.addGroup(group),\n )\n : null;\n\n const groups = nodeGroup\n ? { ...convexSpec.groups, node: nodeGroup }\n : convexSpec.groups;\n const refs = makeHelper(groups);\n return {\n public: refs as Refs<ConvexSpec, NodeSpec, Ref.AnyPublic>,\n internal: refs as Refs<ConvexSpec, NodeSpec, Ref.AnyInternal>,\n };\n};\n\nconst makeHelper = (\n groups: Record.ReadonlyRecord<string, GroupSpec.Any>,\n functionNamespace: string | null = null,\n): Any =>\n pipe(\n groups as Record.ReadonlyRecord<string, GroupSpec.AnyWithProps>,\n Record.map((group) => {\n const currentFunctionNamespace = functionNamespace\n ? `${functionNamespace}/${group.name}`\n : group.name;\n\n return Record.union(\n makeHelper(group.groups, currentFunctionNamespace),\n Record.map(group.functions, (function_) =>\n Ref.make(currentFunctionNamespace, function_),\n ),\n (_subGroup, _function) => {\n throw new Error(\n `Group and function at same level have same name ('${Ref.getConvexFunctionName(_function)}')`,\n );\n },\n );\n }),\n );\n"],"mappings":";;;;;;;AAwFA,MAAa,QAIX,YACA,aAIG;CACH,MAAM,YAAY,WACd,MAAM,OACJ,OAAO,OAAO,SAAS,OAAO,EAC9BA,SAAmB,OAAO,GACzB,eAAe,UAAU,cAAc,SAAS,MAAM,CACxD,GACD;CAKJ,MAAM,OAAO,WAHE,YACX;EAAE,GAAG,WAAW;EAAQ,MAAM;EAAW,GACzC,WAAW,OACgB;AAC/B,QAAO;EACL,QAAQ;EACR,UAAU;EACX;;AAGH,MAAM,cACJ,QACA,oBAAmC,SAEnC,KACE,QACA,OAAO,KAAK,UAAU;CACpB,MAAM,2BAA2B,oBAC7B,GAAG,kBAAkB,GAAG,MAAM,SAC9B,MAAM;AAEV,QAAO,OAAO,MACZ,WAAW,MAAM,QAAQ,yBAAyB,EAClD,OAAO,IAAI,MAAM,YAAY,cAC3BC,OAAS,0BAA0B,UAAU,CAC9C,GACA,WAAW,cAAc;AACxB,QAAM,IAAI,MACR,qDAAqDC,sBAA0B,UAAU,CAAC,IAC3F;GAEJ;EACD,CACH"}
1
+ {"version":3,"file":"Refs.js","names":["GroupSpec.makeNodeAt","Ref.make","Ref.getConvexFunctionName"],"sources":["../src/Refs.ts"],"sourcesContent":["import type { Types } from \"effect\";\nimport { Array, Option, pipe, Record } from \"effect\";\nimport type * as FunctionSpec from \"./FunctionSpec\";\nimport * as GroupSpec from \"./GroupSpec\";\nimport * as Ref from \"./Ref\";\nimport type * as Spec from \"./Spec\";\n\nexport type Refs<\n ConvexSpec extends Spec.AnyWithPropsWithRuntime<\"Convex\">,\n NodeSpec extends Spec.AnyWithPropsWithRuntime<\"Node\"> = never,\n Predicate extends Ref.Any = Ref.Any,\n> = Types.Simplify<\n OmitEmpty<\n Helper<\n | Spec.Groups<ConvexSpec>\n | (NodeSpec extends never\n ? never\n : GroupSpec.GroupSpec<\n \"Node\",\n \"node\",\n never,\n NodeSpec[\"groups\"][keyof NodeSpec[\"groups\"]]\n >),\n Predicate\n >\n >\n>;\n\ntype GroupRefs<\n Group extends GroupSpec.AnyWithProps,\n Predicate extends Ref.Any,\n> = Types.Simplify<\n OmitEmpty<Helper<GroupSpec.Groups<Group>, Predicate>> &\n FilteredFunctions<GroupSpec.Functions<Group>, Predicate>\n>;\n\ntype OmitEmpty<T> = {\n [K in keyof T as keyof T[K] extends never ? never : K]: T[K];\n};\n\ntype FunctionSpecMatchesPredicate<\n FunctionSpec_ extends FunctionSpec.AnyWithProps,\n Predicate extends Ref.Any,\n> =\n Ref.Ref<\n FunctionSpec.GetRuntimeAndFunctionType<FunctionSpec_>,\n FunctionSpec.GetFunctionVisibility<FunctionSpec_>,\n any,\n any\n > extends Predicate\n ? true\n : false;\n\ntype FilteredFunctions<\n FunctionSpecs extends FunctionSpec.AnyWithProps,\n Predicate extends Ref.Any,\n> = {\n [Name in FunctionSpec.Name<FunctionSpecs> as FunctionSpec.WithName<\n FunctionSpecs,\n Name\n > extends infer FunctionSpec_ extends FunctionSpec.AnyWithProps\n ? FunctionSpecMatchesPredicate<FunctionSpec_, Predicate> extends true\n ? Name\n : never\n : never]: FunctionSpec.WithName<FunctionSpecs, Name> extends infer F extends\n FunctionSpec.AnyWithProps\n ? Ref.FromFunctionSpec<F>\n : never;\n};\n\ntype Helper<\n Groups extends GroupSpec.AnyWithProps,\n Predicate extends Ref.Any,\n> = {\n [GroupName in GroupSpec.Name<Groups>]: GroupSpec.WithName<\n Groups,\n GroupName\n > extends infer Group extends GroupSpec.AnyWithProps\n ? GroupRefs<Group, Predicate>\n : never;\n};\n\ntype Any =\n | {\n readonly [key: string]: Any;\n }\n | Ref.Any;\n\nexport const make = <\n ConvexSpec extends Spec.AnyWithPropsWithRuntime<\"Convex\">,\n NodeSpec extends Spec.AnyWithPropsWithRuntime<\"Node\"> = never,\n>(\n convexSpec: ConvexSpec,\n nodeSpec?: NodeSpec,\n): {\n public: Refs<ConvexSpec, NodeSpec, Ref.AnyPublic>;\n internal: Refs<ConvexSpec, NodeSpec, Ref.AnyInternal>;\n} => {\n const groups = Option.fromNullable(nodeSpec).pipe(\n Option.map((nodeSpec_) =>\n Array.reduce(\n Record.toEntries(nodeSpec_.groups),\n GroupSpec.makeNodeAt(\"node\"),\n (nodeGroupSpec, [name, group]) => nodeGroupSpec.addGroupAt(name, group),\n ),\n ),\n Option.match({\n onNone: () => convexSpec.groups,\n onSome: (nodeGroup) => ({ ...convexSpec.groups, node: nodeGroup }),\n }),\n );\n const refs = makeHelper(groups);\n return {\n public: refs as Refs<ConvexSpec, NodeSpec, Ref.AnyPublic>,\n internal: refs as Refs<ConvexSpec, NodeSpec, Ref.AnyInternal>,\n };\n};\n\nconst makeHelper = (\n groups: Record.ReadonlyRecord<string, GroupSpec.Any>,\n functionNamespace: Option.Option<string> = Option.none(),\n): Any =>\n pipe(\n groups as Record.ReadonlyRecord<string, GroupSpec.AnyWithProps>,\n Record.map((group, name) => {\n const currentFunctionNamespace = Option.match(functionNamespace, {\n onNone: () => name,\n onSome: (parentNamespace) => `${parentNamespace}/${name}`,\n });\n\n return Record.union(\n makeHelper(group.groups, Option.some(currentFunctionNamespace)),\n Record.map(group.functions, (function_) =>\n Ref.make(currentFunctionNamespace, function_),\n ),\n (_subGroup, _function) => {\n throw new Error(\n `Group and function at same level have same name ('${Ref.getConvexFunctionName(_function)}')`,\n );\n },\n );\n }),\n );\n"],"mappings":";;;;;;;AAwFA,MAAa,QAIX,YACA,aAIG;CAcH,MAAM,OAAO,WAbE,OAAO,aAAa,SAAS,CAAC,KAC3C,OAAO,KAAK,cACV,MAAM,OACJ,OAAO,UAAU,UAAU,OAAO,EAClCA,WAAqB,OAAO,GAC3B,eAAe,CAAC,MAAM,WAAW,cAAc,WAAW,MAAM,MAAM,CACxE,CACF,EACD,OAAO,MAAM;EACX,cAAc,WAAW;EACzB,SAAS,eAAe;GAAE,GAAG,WAAW;GAAQ,MAAM;GAAW;EAClE,CAAC,CACH,CAC8B;AAC/B,QAAO;EACL,QAAQ;EACR,UAAU;EACX;;AAGH,MAAM,cACJ,QACA,oBAA2C,OAAO,MAAM,KAExD,KACE,QACA,OAAO,KAAK,OAAO,SAAS;CAC1B,MAAM,2BAA2B,OAAO,MAAM,mBAAmB;EAC/D,cAAc;EACd,SAAS,oBAAoB,GAAG,gBAAgB,GAAG;EACpD,CAAC;AAEF,QAAO,OAAO,MACZ,WAAW,MAAM,QAAQ,OAAO,KAAK,yBAAyB,CAAC,EAC/D,OAAO,IAAI,MAAM,YAAY,cAC3BC,OAAS,0BAA0B,UAAU,CAC9C,GACA,WAAW,cAAc;AACxB,QAAM,IAAI,MACR,qDAAqDC,sBAA0B,UAAU,CAAC,IAC3F;GAEJ;EACD,CACH"}
@@ -0,0 +1,31 @@
1
+ import { Context, Ref } from "effect";
2
+
3
+ //#region src/Registry.d.ts
4
+ declare namespace Registry_d_exports {
5
+ export { Registry, RegistryItems };
6
+ }
7
+ /**
8
+ * Recursive tree that mirrors a `Spec`'s group structure. Leaves are the
9
+ * per-function items written by each `FunctionImpl`'s layer initializer. The
10
+ * leaf type is intentionally `unknown` here so `@confect/core` does not need
11
+ * to know about `@confect/server`'s `RegistryItem` shape; producers and
12
+ * consumers (the server runtime and the CLI's `implValidation`) narrow as
13
+ * needed.
14
+ */
15
+ interface RegistryItems {
16
+ readonly [key: string]: unknown | RegistryItems;
17
+ }
18
+ declare const Registry_base: Context.ReferenceClass<Registry, "@confect/core/Registry", Ref.Ref<RegistryItems>>;
19
+ /**
20
+ * Effect `Context.Reference` keyed by `@confect/core/Registry`. Lives in
21
+ * `@confect/core` so `@confect/server` (which writes to it from
22
+ * `FunctionImpl` initializers and reads it from `RegisteredFunctions`) and
23
+ * `@confect/cli` (which inspects it during impl validation) can share the
24
+ * exact same `Ref` instance by importing the same tag — without relying on
25
+ * Effect's global default-value cache to align two separately-defined tags
26
+ * by string key.
27
+ */
28
+ declare class Registry extends Registry_base {}
29
+ //#endregion
30
+ export { Registry, RegistryItems, Registry_d_exports };
31
+ //# sourceMappingURL=Registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Registry.d.ts","names":[],"sources":["../src/Registry.ts"],"mappings":";;;;;;;;;;;;;AAUA;UAAiB,aAAA;EAAA,UACL,GAAA,qBAAwB,aAAA;AAAA;AAAA,cACnC,aAAA;AAAA;;;;;;;;;AAAA,cAWY,QAAA,SAAiB,aAAA"}
@@ -0,0 +1,19 @@
1
+ import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
+ import { Context, Ref } from "effect";
3
+
4
+ //#region src/Registry.ts
5
+ var Registry_exports = /* @__PURE__ */ __exportAll({ Registry: () => Registry });
6
+ /**
7
+ * Effect `Context.Reference` keyed by `@confect/core/Registry`. Lives in
8
+ * `@confect/core` so `@confect/server` (which writes to it from
9
+ * `FunctionImpl` initializers and reads it from `RegisteredFunctions`) and
10
+ * `@confect/cli` (which inspects it during impl validation) can share the
11
+ * exact same `Ref` instance by importing the same tag — without relying on
12
+ * Effect's global default-value cache to align two separately-defined tags
13
+ * by string key.
14
+ */
15
+ var Registry = class extends Context.Reference()("@confect/core/Registry", { defaultValue: () => Ref.unsafeMake({}) }) {};
16
+
17
+ //#endregion
18
+ export { Registry, Registry_exports };
19
+ //# sourceMappingURL=Registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Registry.js","names":[],"sources":["../src/Registry.ts"],"sourcesContent":["import { Context, Ref } from \"effect\";\n\n/**\n * Recursive tree that mirrors a `Spec`'s group structure. Leaves are the\n * per-function items written by each `FunctionImpl`'s layer initializer. The\n * leaf type is intentionally `unknown` here so `@confect/core` does not need\n * to know about `@confect/server`'s `RegistryItem` shape; producers and\n * consumers (the server runtime and the CLI's `implValidation`) narrow as\n * needed.\n */\nexport interface RegistryItems {\n readonly [key: string]: unknown | RegistryItems;\n}\n\n/**\n * Effect `Context.Reference` keyed by `@confect/core/Registry`. Lives in\n * `@confect/core` so `@confect/server` (which writes to it from\n * `FunctionImpl` initializers and reads it from `RegisteredFunctions`) and\n * `@confect/cli` (which inspects it during impl validation) can share the\n * exact same `Ref` instance by importing the same tag — without relying on\n * Effect's global default-value cache to align two separately-defined tags\n * by string key.\n */\nexport class Registry extends Context.Reference<Registry>()(\n \"@confect/core/Registry\",\n {\n defaultValue: () => Ref.unsafeMake<RegistryItems>({}),\n },\n) {}\n"],"mappings":";;;;;;;;;;;;;;AAuBA,IAAa,WAAb,cAA8B,QAAQ,WAAqB,CACzD,0BACA,EACE,oBAAoB,IAAI,WAA0B,EAAE,CAAC,EACtD,CACF,CAAC"}
package/dist/Spec.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Runtime } from "./RuntimeAndFunctionType.js";
2
- import { AnyWithProps as AnyWithProps$1, AnyWithPropsWithRuntime as AnyWithPropsWithRuntime$1, Name, WithName } from "./GroupSpec.js";
2
+ import { AnyWithProps as AnyWithProps$1, AnyWithPropsWithRuntime as AnyWithPropsWithRuntime$1, Name, NamedAt, WithName } from "./GroupSpec.js";
3
3
 
4
4
  //#region src/Spec.d.ts
5
5
  declare namespace Spec_d_exports {
@@ -15,6 +15,7 @@ interface Spec<Runtime$1 extends Runtime, Groups_ extends AnyWithPropsWithRuntim
15
15
  readonly runtime: Runtime$1;
16
16
  readonly groups: { [GroupName in Name<Groups_>]: WithName<Groups_, GroupName> };
17
17
  add<Group extends AnyWithPropsWithRuntime$1<Runtime$1>>(group: Group): Spec<Runtime$1, Groups_ | Group>;
18
+ addAt<const Name$1 extends string, Group extends AnyWithPropsWithRuntime$1<Runtime$1>>(name: Name$1, group: Group): Spec<Runtime$1, Groups_ | NamedAt<Group, Name$1>>;
18
19
  }
19
20
  interface Any {
20
21
  readonly [TypeId]: TypeId;
@@ -1 +1 @@
1
- {"version":3,"file":"Spec.d.ts","names":[],"sources":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IAAK,uBAAA;AAAA,UAK5B,IAAA,mBACC,OAAA,kBACA,yBAAA,CAAkC,SAAA;EAAA,UAExC,MAAA,GAAS,MAAA;EAAA,SACV,OAAA,EAAS,SAAA;EAAA,SACT,MAAA,kBACO,IAAA,CAAe,OAAA,IAAW,QAAA,CACtC,OAAA,EACA,SAAA;EAIJ,GAAA,eAAkB,yBAAA,CAAkC,SAAA,GAClD,KAAA,EAAO,KAAA,GACN,IAAA,CAAK,SAAA,EAAS,OAAA,GAAU,KAAA;EAE3B,KAAA,4CAEgB,yBAAA,CAAkC,SAAA,GAEhD,IAAA,EAAM,MAAA,EACN,KAAA,EAAO,KAAA,GACN,IAAA,CAAK,SAAA,EAAS,OAAA,GAAU,OAAA,CAAkB,KAAA,EAAO,MAAA;AAAA;AAAA,UAGrC,GAAA;EAAA,UACL,MAAA,GAAS,MAAA;AAAA;AAAA,UAGJ,YAAA,SAAqB,IAAA,CACpC,OAAA,EACA,cAAA;AAAA,UAGe,uBAAA,mBACC,OAAA,UACR,IAAA,CAAK,SAAA,EAAS,yBAAA,CAAkC,SAAA;AAAA,KAE9C,MAAA,eAAqB,YAAA,IAC/B,KAAA,iBAAsB,KAAA;AAAA,cAuCX,IAAA,QAAW,IAAA;AAAA,cAGX,QAAA,QAAe,IAAA;;;;AAjG5B;;cAyGa,KAAA,sBACQ,uBAAA,6BACF,uBAAA,UAEjB,UAAA,EAAY,UAAA,EACZ,QAAA,GAAW,QAAA,KACV,YAAA"}
package/dist/Spec.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
- import { makeNode as makeNode$1 } from "./GroupSpec.js";
3
- import { Array, Predicate, Record } from "effect";
2
+ import { makeNodeAt, withName } from "./GroupSpec.js";
3
+ import { Array, Option, Predicate, Record } from "effect";
4
4
 
5
5
  //#region src/Spec.ts
6
6
  var Spec_exports = /* @__PURE__ */ __exportAll({
@@ -23,6 +23,12 @@ const Proto = {
23
23
  runtime: this.runtime,
24
24
  groups: Record.set(this.groups, group.name, group)
25
25
  });
26
+ },
27
+ addAt(name, group) {
28
+ return makeProto({
29
+ runtime: this.runtime,
30
+ groups: Record.set(this.groups, name, withName(name, group))
31
+ });
26
32
  }
27
33
  };
28
34
  const makeProto = ({ runtime, groups }) => Object.assign(Object.create(Proto), {
@@ -43,11 +49,13 @@ const makeNode = () => makeProto({
43
49
  * mirroring the structure used by `Refs.make`.
44
50
  */
45
51
  const merge = (convexSpec, nodeSpec) => {
46
- const nodeGroup = nodeSpec ? Array.reduce(Record.values(nodeSpec.groups), makeNode$1("node"), (nodeGroupSpec, group) => nodeGroupSpec.addGroup(group)) : null;
47
- const groups = nodeGroup ? {
48
- ...convexSpec.groups,
49
- node: nodeGroup
50
- } : convexSpec.groups;
52
+ const groups = Option.fromNullable(nodeSpec).pipe(Option.map((nodeSpec_) => Array.reduce(Record.toEntries(nodeSpec_.groups), makeNodeAt("node"), (nodeGroupSpec, [name, group]) => nodeGroupSpec.addGroupAt(name, group))), Option.match({
53
+ onNone: () => convexSpec.groups,
54
+ onSome: (nodeGroup) => ({
55
+ ...convexSpec.groups,
56
+ node: nodeGroup
57
+ })
58
+ }));
51
59
  return Object.assign(Object.create(Proto), {
52
60
  runtime: "Convex",
53
61
  groups
package/dist/Spec.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Spec.js","names":["GroupSpec.makeNode"],"sources":["../src/Spec.ts"],"sourcesContent":["import { Array, Predicate, Record } from \"effect\";\nimport * as GroupSpec from \"./GroupSpec\";\nimport type * as RuntimeAndFunctionType from \"./RuntimeAndFunctionType\";\n\nexport const TypeId = \"@confect/core/Spec\";\nexport type TypeId = typeof TypeId;\n\nexport const isSpec = (u: unknown): u is AnyWithProps =>\n Predicate.hasProperty(u, TypeId);\n\nexport const isConvexSpec = (\n u: unknown,\n): u is AnyWithPropsWithRuntime<\"Convex\"> =>\n Predicate.hasProperty(u, TypeId) &&\n Predicate.hasProperty(u, \"runtime\") &&\n u.runtime === \"Convex\";\n\nexport const isNodeSpec = (u: unknown): u is AnyWithPropsWithRuntime<\"Node\"> =>\n Predicate.hasProperty(u, TypeId) &&\n Predicate.hasProperty(u, \"runtime\") &&\n u.runtime === \"Node\";\n\nexport interface Spec<\n Runtime extends RuntimeAndFunctionType.Runtime,\n Groups_ extends GroupSpec.AnyWithPropsWithRuntime<Runtime> = never,\n> {\n readonly [TypeId]: TypeId;\n readonly runtime: Runtime;\n readonly groups: {\n [GroupName in GroupSpec.Name<Groups_>]: GroupSpec.WithName<\n Groups_,\n GroupName\n >;\n };\n\n add<Group extends GroupSpec.AnyWithPropsWithRuntime<Runtime>>(\n group: Group,\n ): Spec<Runtime, Groups_ | Group>;\n}\n\nexport interface Any {\n readonly [TypeId]: TypeId;\n}\n\nexport interface AnyWithProps extends Spec<\n RuntimeAndFunctionType.Runtime,\n GroupSpec.AnyWithProps\n> {}\n\nexport interface AnyWithPropsWithRuntime<\n Runtime extends RuntimeAndFunctionType.Runtime,\n> extends Spec<Runtime, GroupSpec.AnyWithPropsWithRuntime<Runtime>> {}\n\nexport type Groups<Spec_ extends AnyWithProps> =\n Spec_[\"groups\"][keyof Spec_[\"groups\"]];\n\nconst Proto = {\n [TypeId]: TypeId,\n\n add<Group extends GroupSpec.AnyWithProps>(this: AnyWithProps, group: Group) {\n return makeProto({\n runtime: this.runtime,\n groups: Record.set(this.groups, group.name, group),\n });\n },\n};\n\nconst makeProto = <\n Runtime extends RuntimeAndFunctionType.Runtime,\n Groups_ extends GroupSpec.AnyWithPropsWithRuntime<Runtime>,\n>({\n runtime,\n groups,\n}: {\n runtime: Runtime;\n groups: Record.ReadonlyRecord<string, Groups_>;\n}): Spec<Runtime, Groups_> =>\n Object.assign(Object.create(Proto), {\n runtime,\n groups,\n });\n\nexport const make = (): Spec<\"Convex\"> =>\n makeProto({ runtime: \"Convex\", groups: {} });\n\nexport const makeNode = (): Spec<\"Node\"> =>\n makeProto({ runtime: \"Node\", groups: {} });\n\n/**\n * Merges a Convex spec with an optional Node spec for use with `Api.make`.\n * When `nodeSpec` is provided, its groups are merged under a \"node\" namespace,\n * mirroring the structure used by `Refs.make`.\n */\nexport const merge = <\n ConvexSpec extends AnyWithPropsWithRuntime<\"Convex\">,\n NodeSpec extends AnyWithPropsWithRuntime<\"Node\">,\n>(\n convexSpec: ConvexSpec,\n nodeSpec?: NodeSpec,\n): AnyWithProps => {\n const nodeGroup = nodeSpec\n ? Array.reduce(\n Record.values(nodeSpec.groups),\n GroupSpec.makeNode(\"node\"),\n (nodeGroupSpec, group) => nodeGroupSpec.addGroup(group),\n )\n : null;\n\n const groups = nodeGroup\n ? { ...convexSpec.groups, node: nodeGroup }\n : convexSpec.groups;\n\n return Object.assign(Object.create(Proto), {\n runtime: \"Convex\" as const,\n groups,\n }) as AnyWithProps;\n};\n"],"mappings":";;;;;;;;;;;;;;AAIA,MAAa,SAAS;AAGtB,MAAa,UAAU,MACrB,UAAU,YAAY,GAAG,OAAO;AAElC,MAAa,gBACX,MAEA,UAAU,YAAY,GAAG,OAAO,IAChC,UAAU,YAAY,GAAG,UAAU,IACnC,EAAE,YAAY;AAEhB,MAAa,cAAc,MACzB,UAAU,YAAY,GAAG,OAAO,IAChC,UAAU,YAAY,GAAG,UAAU,IACnC,EAAE,YAAY;AAoChB,MAAM,QAAQ;EACX,SAAS;CAEV,IAA8D,OAAc;AAC1E,SAAO,UAAU;GACf,SAAS,KAAK;GACd,QAAQ,OAAO,IAAI,KAAK,QAAQ,MAAM,MAAM,MAAM;GACnD,CAAC;;CAEL;AAED,MAAM,aAGJ,EACA,SACA,aAKA,OAAO,OAAO,OAAO,OAAO,MAAM,EAAE;CAClC;CACA;CACD,CAAC;AAEJ,MAAa,aACX,UAAU;CAAE,SAAS;CAAU,QAAQ,EAAE;CAAE,CAAC;AAE9C,MAAa,iBACX,UAAU;CAAE,SAAS;CAAQ,QAAQ,EAAE;CAAE,CAAC;;;;;;AAO5C,MAAa,SAIX,YACA,aACiB;CACjB,MAAM,YAAY,WACd,MAAM,OACJ,OAAO,OAAO,SAAS,OAAO,EAC9BA,WAAmB,OAAO,GACzB,eAAe,UAAU,cAAc,SAAS,MAAM,CACxD,GACD;CAEJ,MAAM,SAAS,YACX;EAAE,GAAG,WAAW;EAAQ,MAAM;EAAW,GACzC,WAAW;AAEf,QAAO,OAAO,OAAO,OAAO,OAAO,MAAM,EAAE;EACzC,SAAS;EACT;EACD,CAAC"}
1
+ {"version":3,"file":"Spec.js","names":["GroupSpec.withName","GroupSpec.makeNodeAt"],"sources":["../src/Spec.ts"],"sourcesContent":["import { Array, Option, Predicate, Record } from \"effect\";\nimport * as GroupSpec from \"./GroupSpec\";\nimport type * as RuntimeAndFunctionType from \"./RuntimeAndFunctionType\";\n\nexport const TypeId = \"@confect/core/Spec\";\nexport type TypeId = typeof TypeId;\n\nexport const isSpec = (u: unknown): u is AnyWithProps =>\n Predicate.hasProperty(u, TypeId);\n\nexport const isConvexSpec = (\n u: unknown,\n): u is AnyWithPropsWithRuntime<\"Convex\"> =>\n Predicate.hasProperty(u, TypeId) &&\n Predicate.hasProperty(u, \"runtime\") &&\n u.runtime === \"Convex\";\n\nexport const isNodeSpec = (u: unknown): u is AnyWithPropsWithRuntime<\"Node\"> =>\n Predicate.hasProperty(u, TypeId) &&\n Predicate.hasProperty(u, \"runtime\") &&\n u.runtime === \"Node\";\n\nexport interface Spec<\n Runtime extends RuntimeAndFunctionType.Runtime,\n Groups_ extends GroupSpec.AnyWithPropsWithRuntime<Runtime> = never,\n> {\n readonly [TypeId]: TypeId;\n readonly runtime: Runtime;\n readonly groups: {\n [GroupName in GroupSpec.Name<Groups_>]: GroupSpec.WithName<\n Groups_,\n GroupName\n >;\n };\n\n add<Group extends GroupSpec.AnyWithPropsWithRuntime<Runtime>>(\n group: Group,\n ): Spec<Runtime, Groups_ | Group>;\n\n addAt<\n const Name extends string,\n Group extends GroupSpec.AnyWithPropsWithRuntime<Runtime>,\n >(\n name: Name,\n group: Group,\n ): Spec<Runtime, Groups_ | GroupSpec.NamedAt<Group, Name>>;\n}\n\nexport interface Any {\n readonly [TypeId]: TypeId;\n}\n\nexport interface AnyWithProps extends Spec<\n RuntimeAndFunctionType.Runtime,\n GroupSpec.AnyWithProps\n> {}\n\nexport interface AnyWithPropsWithRuntime<\n Runtime extends RuntimeAndFunctionType.Runtime,\n> extends Spec<Runtime, GroupSpec.AnyWithPropsWithRuntime<Runtime>> {}\n\nexport type Groups<Spec_ extends AnyWithProps> =\n Spec_[\"groups\"][keyof Spec_[\"groups\"]];\n\nconst Proto = {\n [TypeId]: TypeId,\n\n add<Group extends GroupSpec.AnyWithProps>(this: AnyWithProps, group: Group) {\n return makeProto({\n runtime: this.runtime,\n groups: Record.set(this.groups, group.name, group),\n });\n },\n\n addAt<Group extends GroupSpec.AnyWithProps>(\n this: AnyWithProps,\n name: string,\n group: Group,\n ) {\n return makeProto({\n runtime: this.runtime,\n groups: Record.set(this.groups, name, GroupSpec.withName(name, group)),\n });\n },\n};\n\nconst makeProto = <\n Runtime extends RuntimeAndFunctionType.Runtime,\n Groups_ extends GroupSpec.AnyWithPropsWithRuntime<Runtime>,\n>({\n runtime,\n groups,\n}: {\n runtime: Runtime;\n groups: Record.ReadonlyRecord<string, Groups_>;\n}): Spec<Runtime, Groups_> =>\n Object.assign(Object.create(Proto), {\n runtime,\n groups,\n });\n\nexport const make = (): Spec<\"Convex\"> =>\n makeProto({ runtime: \"Convex\", groups: {} });\n\nexport const makeNode = (): Spec<\"Node\"> =>\n makeProto({ runtime: \"Node\", groups: {} });\n\n/**\n * Merges a Convex spec with an optional Node spec for use with `Api.make`.\n * When `nodeSpec` is provided, its groups are merged under a \"node\" namespace,\n * mirroring the structure used by `Refs.make`.\n */\nexport const merge = <\n ConvexSpec extends AnyWithPropsWithRuntime<\"Convex\">,\n NodeSpec extends AnyWithPropsWithRuntime<\"Node\">,\n>(\n convexSpec: ConvexSpec,\n nodeSpec?: NodeSpec,\n): AnyWithProps => {\n const groups = Option.fromNullable(nodeSpec).pipe(\n Option.map((nodeSpec_) =>\n Array.reduce(\n Record.toEntries(nodeSpec_.groups),\n GroupSpec.makeNodeAt(\"node\"),\n (nodeGroupSpec, [name, group]) => nodeGroupSpec.addGroupAt(name, group),\n ),\n ),\n Option.match({\n onNone: () => convexSpec.groups,\n onSome: (nodeGroup) => ({ ...convexSpec.groups, node: nodeGroup }),\n }),\n );\n\n return Object.assign(Object.create(Proto), {\n runtime: \"Convex\" as const,\n groups,\n }) as AnyWithProps;\n};\n"],"mappings":";;;;;;;;;;;;;;AAIA,MAAa,SAAS;AAGtB,MAAa,UAAU,MACrB,UAAU,YAAY,GAAG,OAAO;AAElC,MAAa,gBACX,MAEA,UAAU,YAAY,GAAG,OAAO,IAChC,UAAU,YAAY,GAAG,UAAU,IACnC,EAAE,YAAY;AAEhB,MAAa,cAAc,MACzB,UAAU,YAAY,GAAG,OAAO,IAChC,UAAU,YAAY,GAAG,UAAU,IACnC,EAAE,YAAY;AA4ChB,MAAM,QAAQ;EACX,SAAS;CAEV,IAA8D,OAAc;AAC1E,SAAO,UAAU;GACf,SAAS,KAAK;GACd,QAAQ,OAAO,IAAI,KAAK,QAAQ,MAAM,MAAM,MAAM;GACnD,CAAC;;CAGJ,MAEE,MACA,OACA;AACA,SAAO,UAAU;GACf,SAAS,KAAK;GACd,QAAQ,OAAO,IAAI,KAAK,QAAQ,MAAMA,SAAmB,MAAM,MAAM,CAAC;GACvE,CAAC;;CAEL;AAED,MAAM,aAGJ,EACA,SACA,aAKA,OAAO,OAAO,OAAO,OAAO,MAAM,EAAE;CAClC;CACA;CACD,CAAC;AAEJ,MAAa,aACX,UAAU;CAAE,SAAS;CAAU,QAAQ,EAAE;CAAE,CAAC;AAE9C,MAAa,iBACX,UAAU;CAAE,SAAS;CAAQ,QAAQ,EAAE;CAAE,CAAC;;;;;;AAO5C,MAAa,SAIX,YACA,aACiB;CACjB,MAAM,SAAS,OAAO,aAAa,SAAS,CAAC,KAC3C,OAAO,KAAK,cACV,MAAM,OACJ,OAAO,UAAU,UAAU,OAAO,EAClCC,WAAqB,OAAO,GAC3B,eAAe,CAAC,MAAM,WAAW,cAAc,WAAW,MAAM,MAAM,CACxE,CACF,EACD,OAAO,MAAM;EACX,cAAc,WAAW;EACzB,SAAS,eAAe;GAAE,GAAG,WAAW;GAAQ,MAAM;GAAW;EAClE,CAAC,CACH;AAED,QAAO,OAAO,OAAO,OAAO,OAAO,MAAM,EAAE;EACzC,SAAS;EACT;EACD,CAAC"}
package/dist/index.d.ts CHANGED
@@ -8,7 +8,8 @@ import { PaginationResult_d_exports } from "./PaginationResult.js";
8
8
  import { Ref_d_exports } from "./Ref.js";
9
9
  import { Spec_d_exports } from "./Spec.js";
10
10
  import { Refs_d_exports } from "./Refs.js";
11
+ import { Registry_d_exports } from "./Registry.js";
11
12
  import { SystemFields_d_exports } from "./SystemFields.js";
12
13
  import { Types_d_exports } from "./Types.js";
13
14
  import { UserIdentity_d_exports } from "./UserIdentity.js";
14
- export { FunctionProvenance_d_exports as FunctionProvenance, FunctionSpec_d_exports as FunctionSpec, GenericId_d_exports as GenericId, GroupPath_d_exports as GroupPath, GroupSpec_d_exports as GroupSpec, PaginationResult_d_exports as PaginationResult, Ref_d_exports as Ref, Refs_d_exports as Refs, RuntimeAndFunctionType_d_exports as RuntimeAndFunctionType, Spec_d_exports as Spec, SystemFields_d_exports as SystemFields, Types_d_exports as Types, UserIdentity_d_exports as UserIdentity };
15
+ export { FunctionProvenance_d_exports as FunctionProvenance, FunctionSpec_d_exports as FunctionSpec, GenericId_d_exports as GenericId, GroupPath_d_exports as GroupPath, GroupSpec_d_exports as GroupSpec, PaginationResult_d_exports as PaginationResult, Ref_d_exports as Ref, Refs_d_exports as Refs, Registry_d_exports as Registry, RuntimeAndFunctionType_d_exports as RuntimeAndFunctionType, Spec_d_exports as Spec, SystemFields_d_exports as SystemFields, Types_d_exports as Types, UserIdentity_d_exports as UserIdentity };
package/dist/index.js CHANGED
@@ -7,9 +7,10 @@ import { GroupSpec_exports } from "./GroupSpec.js";
7
7
  import { PaginationResult_exports } from "./PaginationResult.js";
8
8
  import { Ref_exports } from "./Ref.js";
9
9
  import { Refs_exports } from "./Refs.js";
10
+ import { Registry_exports } from "./Registry.js";
10
11
  import { Spec_exports } from "./Spec.js";
11
12
  import { SystemFields_exports } from "./SystemFields.js";
12
13
  import { Types_exports } from "./Types.js";
13
14
  import { UserIdentity_exports } from "./UserIdentity.js";
14
15
 
15
- export { FunctionProvenance_exports as FunctionProvenance, FunctionSpec_exports as FunctionSpec, GenericId_exports as GenericId, GroupPath_exports as GroupPath, GroupSpec_exports as GroupSpec, PaginationResult_exports as PaginationResult, Ref_exports as Ref, Refs_exports as Refs, RuntimeAndFunctionType_exports as RuntimeAndFunctionType, Spec_exports as Spec, SystemFields_exports as SystemFields, Types_exports as Types, UserIdentity_exports as UserIdentity };
16
+ export { FunctionProvenance_exports as FunctionProvenance, FunctionSpec_exports as FunctionSpec, GenericId_exports as GenericId, GroupPath_exports as GroupPath, GroupSpec_exports as GroupSpec, PaginationResult_exports as PaginationResult, Ref_exports as Ref, Refs_exports as Refs, Registry_exports as Registry, RuntimeAndFunctionType_exports as RuntimeAndFunctionType, Spec_exports as Spec, SystemFields_exports as SystemFields, Types_exports as Types, UserIdentity_exports as UserIdentity };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@confect/core",
3
- "version": "7.0.0",
3
+ "version": "9.0.0-next.0",
4
4
  "description": "Shared specs and schemas used by all Confect packages",
5
5
  "repository": {
6
6
  "type": "git",
@@ -40,21 +40,21 @@
40
40
  "license": "ISC",
41
41
  "devDependencies": {
42
42
  "@ark/attest": "0.56.0",
43
- "@effect/vitest": "0.27.0",
43
+ "@effect/vitest": "0.29.0",
44
44
  "@eslint/js": "10.0.1",
45
45
  "@types/node": "25.3.3",
46
- "effect": "3.19.19",
46
+ "effect": "3.21.2",
47
47
  "eslint": "10.0.2",
48
48
  "prettier": "3.8.1",
49
49
  "tsdown": "0.20.3",
50
- "tsx": "^4.21.0",
50
+ "tsx": "4.21.0",
51
51
  "typescript": "5.9.3",
52
52
  "typescript-eslint": "8.56.1",
53
53
  "vitest": "3.2.4"
54
54
  },
55
55
  "peerDependencies": {
56
- "convex": "^1.30.0",
57
- "effect": "^3.19.16"
56
+ "convex": "1.39.1",
57
+ "effect": "^3.21.2"
58
58
  },
59
59
  "engines": {
60
60
  "node": ">=22",
@@ -331,7 +331,10 @@ const makeConvex =
331
331
  runtimeAndFunctionType,
332
332
  functionVisibility,
333
333
  name,
334
- functionProvenance: FunctionProvenance.Convex(),
334
+ functionProvenance: FunctionProvenance.Convex<
335
+ ExtractArgs<F>,
336
+ ExtractReturns<F>
337
+ >(),
335
338
  }) as any;
336
339
  };
337
340
 
package/src/GroupSpec.ts CHANGED
@@ -6,7 +6,7 @@ import { validateConfectFunctionIdentifier } from "./internal/utils";
6
6
  export const TypeId = "@confect/core/GroupSpec";
7
7
  export type TypeId = typeof TypeId;
8
8
 
9
- export const isGroupSpec = (u: unknown): u is Any =>
9
+ export const isGroupSpec = (u: unknown): u is AnyWithProps =>
10
10
  Predicate.hasProperty(u, TypeId);
11
11
 
12
12
  export interface GroupSpec<
@@ -34,6 +34,14 @@ export interface GroupSpec<
34
34
  addGroup<Group extends AnyWithPropsWithRuntime<Runtime>>(
35
35
  group: Group,
36
36
  ): GroupSpec<Runtime, Name_, Functions_, Groups_ | Group>;
37
+
38
+ addGroupAt<
39
+ const AtName extends string,
40
+ Group extends AnyWithPropsWithRuntime<Runtime>,
41
+ >(
42
+ name: AtName,
43
+ group: Group,
44
+ ): GroupSpec<Runtime, Name_, Functions_, Groups_ | NamedAt<Group, AtName>>;
37
45
  }
38
46
 
39
47
  export interface Any {
@@ -75,6 +83,14 @@ export type WithName<
75
83
  Name_ extends Name<Group>,
76
84
  > = Extract<Group, { readonly name: Name_ }>;
77
85
 
86
+ /** Assigns a segment name to a leaf group created with {@link make} for typing and refs. */
87
+ export type NamedAt<Group extends Any, Name_ extends string> = Omit<
88
+ Group,
89
+ "name"
90
+ > & {
91
+ readonly name: Name_;
92
+ };
93
+
78
94
  const Proto = {
79
95
  [TypeId]: TypeId,
80
96
 
@@ -103,6 +119,18 @@ const Proto = {
103
119
  groups: Record.set(this_.groups, group_.name, group_),
104
120
  });
105
121
  },
122
+
123
+ addGroupAt<Group extends Any>(this: Any, name: string, group: Group) {
124
+ const this_ = this as AnyWithProps;
125
+ const group_ = group as unknown as AnyWithProps;
126
+
127
+ return makeProto({
128
+ runtime: this_.runtime,
129
+ name: this_.name,
130
+ functions: this_.functions,
131
+ groups: Record.set(this_.groups, name, withName(name, group_)),
132
+ });
133
+ },
106
134
  };
107
135
 
108
136
  const makeProto = <
@@ -128,7 +156,15 @@ const makeProto = <
128
156
  groups,
129
157
  });
130
158
 
131
- export const make = <const Name_ extends string>(
159
+ export const make = (): GroupSpec<"Convex", ""> =>
160
+ makeProto({
161
+ runtime: "Convex",
162
+ name: "",
163
+ functions: Record.empty(),
164
+ groups: Record.empty(),
165
+ });
166
+
167
+ export const makeAt = <const Name_ extends string>(
132
168
  name: Name_,
133
169
  ): GroupSpec<"Convex", Name_> => {
134
170
  validateConfectFunctionIdentifier(name);
@@ -141,7 +177,15 @@ export const make = <const Name_ extends string>(
141
177
  });
142
178
  };
143
179
 
144
- export const makeNode = <const Name_ extends string>(
180
+ export const makeNode = (): GroupSpec<"Node", ""> =>
181
+ makeProto({
182
+ runtime: "Node",
183
+ name: "",
184
+ functions: Record.empty(),
185
+ groups: Record.empty(),
186
+ });
187
+
188
+ export const makeNodeAt = <const Name_ extends string>(
145
189
  name: Name_,
146
190
  ): GroupSpec<"Node", Name_> => {
147
191
  validateConfectFunctionIdentifier(name);
@@ -153,3 +197,19 @@ export const makeNode = <const Name_ extends string>(
153
197
  groups: Record.empty(),
154
198
  });
155
199
  };
200
+
201
+ export const withName = <const Name_ extends string>(
202
+ name: Name_,
203
+ group: Any,
204
+ ): AnyWithProps => {
205
+ validateConfectFunctionIdentifier(name);
206
+ const group_ = group as AnyWithProps;
207
+
208
+ if (group_.name === name) {
209
+ return group_;
210
+ }
211
+
212
+ // Keep object identity so impls can pass the same GroupSpec instance
213
+ // imported from a sibling `.spec.ts` into `resolveGroupPath`.
214
+ return Object.assign(group_, { name }) as AnyWithProps;
215
+ };
package/src/Refs.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { Types } from "effect";
2
- import { Array, pipe, Record } from "effect";
2
+ import { Array, Option, pipe, Record } from "effect";
3
3
  import type * as FunctionSpec from "./FunctionSpec";
4
4
  import * as GroupSpec from "./GroupSpec";
5
5
  import * as Ref from "./Ref";
@@ -96,17 +96,19 @@ export const make = <
96
96
  public: Refs<ConvexSpec, NodeSpec, Ref.AnyPublic>;
97
97
  internal: Refs<ConvexSpec, NodeSpec, Ref.AnyInternal>;
98
98
  } => {
99
- const nodeGroup = nodeSpec
100
- ? Array.reduce(
101
- Record.values(nodeSpec.groups),
102
- GroupSpec.makeNode("node"),
103
- (nodeGroupSpec, group) => nodeGroupSpec.addGroup(group),
104
- )
105
- : null;
106
-
107
- const groups = nodeGroup
108
- ? { ...convexSpec.groups, node: nodeGroup }
109
- : convexSpec.groups;
99
+ const groups = Option.fromNullable(nodeSpec).pipe(
100
+ Option.map((nodeSpec_) =>
101
+ Array.reduce(
102
+ Record.toEntries(nodeSpec_.groups),
103
+ GroupSpec.makeNodeAt("node"),
104
+ (nodeGroupSpec, [name, group]) => nodeGroupSpec.addGroupAt(name, group),
105
+ ),
106
+ ),
107
+ Option.match({
108
+ onNone: () => convexSpec.groups,
109
+ onSome: (nodeGroup) => ({ ...convexSpec.groups, node: nodeGroup }),
110
+ }),
111
+ );
110
112
  const refs = makeHelper(groups);
111
113
  return {
112
114
  public: refs as Refs<ConvexSpec, NodeSpec, Ref.AnyPublic>,
@@ -116,17 +118,18 @@ export const make = <
116
118
 
117
119
  const makeHelper = (
118
120
  groups: Record.ReadonlyRecord<string, GroupSpec.Any>,
119
- functionNamespace: string | null = null,
121
+ functionNamespace: Option.Option<string> = Option.none(),
120
122
  ): Any =>
121
123
  pipe(
122
124
  groups as Record.ReadonlyRecord<string, GroupSpec.AnyWithProps>,
123
- Record.map((group) => {
124
- const currentFunctionNamespace = functionNamespace
125
- ? `${functionNamespace}/${group.name}`
126
- : group.name;
125
+ Record.map((group, name) => {
126
+ const currentFunctionNamespace = Option.match(functionNamespace, {
127
+ onNone: () => name,
128
+ onSome: (parentNamespace) => `${parentNamespace}/${name}`,
129
+ });
127
130
 
128
131
  return Record.union(
129
- makeHelper(group.groups, currentFunctionNamespace),
132
+ makeHelper(group.groups, Option.some(currentFunctionNamespace)),
130
133
  Record.map(group.functions, (function_) =>
131
134
  Ref.make(currentFunctionNamespace, function_),
132
135
  ),
@@ -0,0 +1,29 @@
1
+ import { Context, Ref } from "effect";
2
+
3
+ /**
4
+ * Recursive tree that mirrors a `Spec`'s group structure. Leaves are the
5
+ * per-function items written by each `FunctionImpl`'s layer initializer. The
6
+ * leaf type is intentionally `unknown` here so `@confect/core` does not need
7
+ * to know about `@confect/server`'s `RegistryItem` shape; producers and
8
+ * consumers (the server runtime and the CLI's `implValidation`) narrow as
9
+ * needed.
10
+ */
11
+ export interface RegistryItems {
12
+ readonly [key: string]: unknown | RegistryItems;
13
+ }
14
+
15
+ /**
16
+ * Effect `Context.Reference` keyed by `@confect/core/Registry`. Lives in
17
+ * `@confect/core` so `@confect/server` (which writes to it from
18
+ * `FunctionImpl` initializers and reads it from `RegisteredFunctions`) and
19
+ * `@confect/cli` (which inspects it during impl validation) can share the
20
+ * exact same `Ref` instance by importing the same tag — without relying on
21
+ * Effect's global default-value cache to align two separately-defined tags
22
+ * by string key.
23
+ */
24
+ export class Registry extends Context.Reference<Registry>()(
25
+ "@confect/core/Registry",
26
+ {
27
+ defaultValue: () => Ref.unsafeMake<RegistryItems>({}),
28
+ },
29
+ ) {}
package/src/Spec.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Array, Predicate, Record } from "effect";
1
+ import { Array, Option, Predicate, Record } from "effect";
2
2
  import * as GroupSpec from "./GroupSpec";
3
3
  import type * as RuntimeAndFunctionType from "./RuntimeAndFunctionType";
4
4
 
@@ -36,6 +36,14 @@ export interface Spec<
36
36
  add<Group extends GroupSpec.AnyWithPropsWithRuntime<Runtime>>(
37
37
  group: Group,
38
38
  ): Spec<Runtime, Groups_ | Group>;
39
+
40
+ addAt<
41
+ const Name extends string,
42
+ Group extends GroupSpec.AnyWithPropsWithRuntime<Runtime>,
43
+ >(
44
+ name: Name,
45
+ group: Group,
46
+ ): Spec<Runtime, Groups_ | GroupSpec.NamedAt<Group, Name>>;
39
47
  }
40
48
 
41
49
  export interface Any {
@@ -63,6 +71,17 @@ const Proto = {
63
71
  groups: Record.set(this.groups, group.name, group),
64
72
  });
65
73
  },
74
+
75
+ addAt<Group extends GroupSpec.AnyWithProps>(
76
+ this: AnyWithProps,
77
+ name: string,
78
+ group: Group,
79
+ ) {
80
+ return makeProto({
81
+ runtime: this.runtime,
82
+ groups: Record.set(this.groups, name, GroupSpec.withName(name, group)),
83
+ });
84
+ },
66
85
  };
67
86
 
68
87
  const makeProto = <
@@ -98,17 +117,19 @@ export const merge = <
98
117
  convexSpec: ConvexSpec,
99
118
  nodeSpec?: NodeSpec,
100
119
  ): AnyWithProps => {
101
- const nodeGroup = nodeSpec
102
- ? Array.reduce(
103
- Record.values(nodeSpec.groups),
104
- GroupSpec.makeNode("node"),
105
- (nodeGroupSpec, group) => nodeGroupSpec.addGroup(group),
106
- )
107
- : null;
108
-
109
- const groups = nodeGroup
110
- ? { ...convexSpec.groups, node: nodeGroup }
111
- : convexSpec.groups;
120
+ const groups = Option.fromNullable(nodeSpec).pipe(
121
+ Option.map((nodeSpec_) =>
122
+ Array.reduce(
123
+ Record.toEntries(nodeSpec_.groups),
124
+ GroupSpec.makeNodeAt("node"),
125
+ (nodeGroupSpec, [name, group]) => nodeGroupSpec.addGroupAt(name, group),
126
+ ),
127
+ ),
128
+ Option.match({
129
+ onNone: () => convexSpec.groups,
130
+ onSome: (nodeGroup) => ({ ...convexSpec.groups, node: nodeGroup }),
131
+ }),
132
+ );
112
133
 
113
134
  return Object.assign(Object.create(Proto), {
114
135
  runtime: "Convex" as const,
package/src/index.ts CHANGED
@@ -6,6 +6,7 @@ export * as GroupSpec from "./GroupSpec";
6
6
  export * as PaginationResult from "./PaginationResult";
7
7
  export * as Ref from "./Ref";
8
8
  export * as Refs from "./Refs";
9
+ export * as Registry from "./Registry";
9
10
  export * as RuntimeAndFunctionType from "./RuntimeAndFunctionType";
10
11
  export * as Spec from "./Spec";
11
12
  export * as SystemFields from "./SystemFields";