@confect/core 9.0.0-next.5 → 9.0.0-next.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/Lazy.js ADDED
@@ -0,0 +1,44 @@
1
+ import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
+
3
+ //#region src/Lazy.ts
4
+ var Lazy_exports = /* @__PURE__ */ __exportAll({ defineProperty: () => defineProperty });
5
+ /**
6
+ * Install a lazy memoised property on `target`. The first access runs
7
+ * `compute()` and replaces the getter with a plain, non-writable data
8
+ * property whose value is the computed result. Subsequent accesses hit
9
+ * the V8 fast path for own data properties — no function call, identical
10
+ * returned reference — so first and second-and-subsequent accesses are
11
+ * observably indistinguishable.
12
+ *
13
+ * The replacement property is `enumerable: true` so the lazy property
14
+ * still participates in `Object.keys` / `JSON.stringify` after it
15
+ * materialises, matching the shape of a plain data property. The property
16
+ * is also `enumerable` before materialising, so presence checks
17
+ * (`"key" in target`, `Object.hasOwn(target, key)`) observe it without
18
+ * forcing the computation.
19
+ *
20
+ * This is the single shared implementation consumed across packages (e.g.
21
+ * `@confect/core`'s lazy `FunctionSpec` schemas and `@confect/server`'s lazy
22
+ * `Table` `Fields` / `Doc` / `tableDefinition`), so there is no chance of the
23
+ * two drifting apart.
24
+ */
25
+ const defineProperty = (target, key, compute) => {
26
+ Object.defineProperty(target, key, {
27
+ configurable: true,
28
+ enumerable: true,
29
+ get() {
30
+ const value = compute();
31
+ Object.defineProperty(this, key, {
32
+ value,
33
+ writable: false,
34
+ enumerable: true,
35
+ configurable: false
36
+ });
37
+ return value;
38
+ }
39
+ });
40
+ };
41
+
42
+ //#endregion
43
+ export { Lazy_exports, defineProperty };
44
+ //# sourceMappingURL=Lazy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Lazy.js","names":[],"sources":["../src/Lazy.ts"],"sourcesContent":["/**\n * Install a lazy memoised property on `target`. The first access runs\n * `compute()` and replaces the getter with a plain, non-writable data\n * property whose value is the computed result. Subsequent accesses hit\n * the V8 fast path for own data properties — no function call, identical\n * returned reference — so first and second-and-subsequent accesses are\n * observably indistinguishable.\n *\n * The replacement property is `enumerable: true` so the lazy property\n * still participates in `Object.keys` / `JSON.stringify` after it\n * materialises, matching the shape of a plain data property. The property\n * is also `enumerable` before materialising, so presence checks\n * (`\"key\" in target`, `Object.hasOwn(target, key)`) observe it without\n * forcing the computation.\n *\n * This is the single shared implementation consumed across packages (e.g.\n * `@confect/core`'s lazy `FunctionSpec` schemas and `@confect/server`'s lazy\n * `Table` `Fields` / `Doc` / `tableDefinition`), so there is no chance of the\n * two drifting apart.\n */\nexport const defineProperty = <T extends object, K extends PropertyKey>(\n target: T,\n key: K,\n compute: () => unknown,\n): void => {\n Object.defineProperty(target, key, {\n configurable: true,\n enumerable: true,\n get(this: T) {\n const value = compute();\n Object.defineProperty(this, key, {\n value,\n writable: false,\n enumerable: true,\n configurable: false,\n });\n return value;\n },\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAoBA,MAAa,kBACX,QACA,KACA,YACS;AACT,QAAO,eAAe,QAAQ,KAAK;EACjC,cAAc;EACd,YAAY;EACZ,MAAa;GACX,MAAM,QAAQ,SAAS;AACvB,UAAO,eAAe,MAAM,KAAK;IAC/B;IACA,UAAU;IACV,YAAY;IACZ,cAAc;IACf,CAAC;AACF,UAAO;;EAEV,CAAC"}
package/dist/Ref.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Ref.d.ts","names":[],"sources":["../src/Ref.ts"],"mappings":";;;;;;;;;;UAYiB,GAAA,iCACiB,sBAAA,8BACJ,kBAAA;EAAA,SAKnB,uBAAA,GAA0B,uBAAA;EAAA,SAC1B,mBAAA,GAAsB,mBAAA;EAAA,SACtB,KAAA,GAAQ,KAAA;EAAA,SACR,QAAA,GAAW,QAAA;EAAA,SACX,MAAA,GAAS,MAAA;AAAA;AAAA,UAOH,GAAA,SAAY,GAAA;AAAA,UAEZ,WAAA,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AK,IAAA,EACL,IAAA,EAAM,IAAA,CAAK,IAAA;AAAA,cAUA,iBAAA,gBAAkC,GAAA,EAC7C,GAAA,EAAK,IAAA,EACL,cAAA,cACC,OAAA,CAAQ,IAAA;AAAA,cAWE,aAAA,GAAiB,KAAA,cAAiB,KAAA,IAAS,WAAA,CAAY,KAAA;;;;;;;;;;cAevD,iBAAA,gBACG,GAAA,KAAQ,GAAA,EAAK,IAAA,EAAM,eAAA,GAAkB,KAAA,cAAmB,CAAA,MACrE,KAAA,cAAiB,KAAA,CAAM,IAAA,IAAQ,CAAA;;;;;;;;cAiBrB,WAAA,gBAA4B,GAAA,EACvC,GAAA,EAAK,IAAA,EACL,YAAA,cACC,MAAA,CAAO,MAAA,CAAO,MAAA,CAAO,MAAA,CAAO,KAAA,CAAM,IAAA,IAAQ,WAAA,CAAY,UAAA;;AAxQzD;;;cA0Ra,eAAA,gBAAgC,GAAA,EAC3C,GAAA,EAAK,IAAA,EACL,YAAA,cACC,MAAA,CAAO,MAAA,CAAO,KAAA,CAAM,IAAA;AAAA,cAeV,oBAAA,gBAAqC,GAAA,EAChD,GAAA,EAAK,IAAA,EACL,KAAA;AA5SF;;;;;AAEA;;;AAFA,cAkUa,YAAA,gBAA6B,GAAA,aACxC,GAAA,EAAK,IAAA,EACL,IAAA,EAAM,IAAA,CAAK,IAAA,GACX,IAAA,GACE,iBAAA,EAAmB,iBAAA,CAAkB,IAAA,GACrC,WAAA,cACG,WAAA,WACL,eAAA,IAAmB,KAAA,cAAmB,CAAA,KACrC,MAAA,CAAO,MAAA,CAAO,OAAA,CAAQ,IAAA,GAAO,CAAA,GAAI,KAAA,CAAM,IAAA,IAAQ,WAAA,CAAY,UAAA"}
package/dist/Ref.js CHANGED
@@ -26,7 +26,7 @@ const make = (functionNamespace, functionSpec) => ({
26
26
  });
27
27
  const getConvexFunctionName = (ref) => `${ref.functionNamespace}:${ref.functionSpec.name}`;
28
28
  const getFunctionReference = (ref) => makeFunctionReference(getConvexFunctionName(ref));
29
- const hasErrorSchema = (ref) => Match.value(ref.functionSpec.functionProvenance).pipe(Match.tag("Confect", (confectFunctionProvenance) => confectFunctionProvenance.error !== void 0), Match.tag("Convex", () => false), Match.exhaustive);
29
+ const hasErrorSchema = (ref) => Match.value(ref.functionSpec.functionProvenance).pipe(Match.tag("Confect", (confectFunctionProvenance) => "error" in confectFunctionProvenance), Match.tag("Convex", () => false), Match.exhaustive);
30
30
  const encodeArgs = (ref, args) => Match.value(ref.functionSpec.functionProvenance).pipe(Match.tag("Confect", (confectFunctionProvenance) => Schema.encode(confectFunctionProvenance.args)(args)), Match.tag("Convex", () => Effect.succeed(args)), Match.exhaustive);
31
31
  const decodeReturns = (ref, returns) => Match.value(ref.functionSpec.functionProvenance).pipe(Match.tag("Confect", (confectFunctionProvenance) => Schema.decode(confectFunctionProvenance.returns)(returns)), Match.tag("Convex", () => Effect.succeed(returns)), Match.exhaustive);
32
32
  const encodeArgsSync = (ref, args) => Match.value(ref.functionSpec.functionProvenance).pipe(Match.tag("Confect", (confectFunctionProvenance) => Schema.encodeSync(confectFunctionProvenance.args)(args)), Match.tag("Convex", () => args), Match.exhaustive);
@@ -56,13 +56,13 @@ const decodeErrorOrElse = (ref, mapUnknownError) => (error) => {
56
56
  * into, and the caller is responsible for deciding what to do (typically:
57
57
  * surface the original value as a defect).
58
58
  */
59
- const decodeError = (ref, encodedError) => Match.value(ref.functionSpec.functionProvenance).pipe(Match.tag("Confect", (confectFunctionProvenance) => confectFunctionProvenance.error !== void 0 ? Effect.map(Schema.decode(confectFunctionProvenance.error)(encodedError), Option.some) : Effect.succeed(Option.none())), Match.tag("Convex", () => Effect.succeed(Option.none())), Match.exhaustive);
59
+ const decodeError = (ref, encodedError) => Match.value(ref.functionSpec.functionProvenance).pipe(Match.tag("Confect", (confectFunctionProvenance) => "error" in confectFunctionProvenance ? Effect.map(Schema.decode(confectFunctionProvenance.error)(encodedError), Option.some) : Effect.succeed(Option.none())), Match.tag("Convex", () => Effect.succeed(Option.none())), Match.exhaustive);
60
60
  /**
61
61
  * Synchronous counterpart to `decodeError`. Throws on schema decode failure;
62
62
  * returns `None` when the ref doesn't declare a typed error.
63
63
  */
64
- const decodeErrorSync = (ref, encodedError) => Match.value(ref.functionSpec.functionProvenance).pipe(Match.tag("Confect", (confectFunctionProvenance) => confectFunctionProvenance.error !== void 0 ? Option.some(Schema.decodeSync(confectFunctionProvenance.error)(encodedError)) : Option.none()), Match.tag("Convex", () => Option.none()), Match.exhaustive);
65
- const maybeDecodeErrorSync = (ref, error) => isConvexError(error) ? Match.value(ref.functionSpec.functionProvenance).pipe(Match.tag("Confect", (confectFunctionProvenance) => confectFunctionProvenance.error !== void 0 ? Schema.decodeSync(confectFunctionProvenance.error)(error.data) : error), Match.tag("Convex", () => error), Match.exhaustive) : error;
64
+ const decodeErrorSync = (ref, encodedError) => Match.value(ref.functionSpec.functionProvenance).pipe(Match.tag("Confect", (confectFunctionProvenance) => "error" in confectFunctionProvenance ? Option.some(Schema.decodeSync(confectFunctionProvenance.error)(encodedError)) : Option.none()), Match.tag("Convex", () => Option.none()), Match.exhaustive);
65
+ const maybeDecodeErrorSync = (ref, error) => isConvexError(error) ? Match.value(ref.functionSpec.functionProvenance).pipe(Match.tag("Confect", (confectFunctionProvenance) => "error" in confectFunctionProvenance ? Schema.decodeSync(confectFunctionProvenance.error)(error.data) : error), Match.tag("Convex", () => error), Match.exhaustive) : error;
66
66
  /**
67
67
  * Encode args via the ref's args schema, invoke `call`, decode returns via the
68
68
  * ref's returns schema, and translate any thrown `ConvexError` into the ref's
package/dist/Ref.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Ref.js","names":[],"sources":["../src/Ref.ts"],"sourcesContent":["import type {\n FunctionReference as ConvexFunctionReference,\n FunctionVisibility,\n} from \"convex/server\";\nimport { makeFunctionReference } from \"convex/server\";\nimport type { Value } from \"convex/values\";\nimport { ConvexError } from \"convex/values\";\nimport type { ParseResult } from \"effect\";\nimport { Effect, Match, Option, Schema } from \"effect\";\nimport type * as FunctionSpec from \"./FunctionSpec\";\nimport type * as RuntimeAndFunctionType from \"./RuntimeAndFunctionType\";\n\nexport interface Ref<\n _RuntimeAndFunctionType extends RuntimeAndFunctionType.RuntimeAndFunctionType,\n _FunctionVisibility extends FunctionVisibility,\n _Args,\n _Returns,\n _Error = never,\n> {\n readonly _RuntimeAndFunctionType?: _RuntimeAndFunctionType;\n readonly _FunctionVisibility?: _FunctionVisibility;\n readonly _Args?: _Args;\n readonly _Returns?: _Returns;\n readonly _Error?: _Error;\n /** @internal */\n readonly functionSpec: FunctionSpec.AnyWithProps;\n /** @internal */\n readonly functionNamespace: string;\n}\n\nexport interface Any extends Ref<any, any, any, any, any> {}\n\nexport interface AnyInternal extends Ref<any, \"internal\", any, any, any> {}\n\nexport interface AnyPublic extends Ref<any, \"public\", any, any, any> {}\n\nexport interface AnyQuery extends Ref<\n RuntimeAndFunctionType.AnyQuery,\n FunctionVisibility,\n any,\n any,\n any\n> {}\n\nexport interface AnyMutation extends Ref<\n RuntimeAndFunctionType.AnyMutation,\n FunctionVisibility,\n any,\n any,\n any\n> {}\n\nexport interface AnyAction extends Ref<\n RuntimeAndFunctionType.AnyAction,\n FunctionVisibility,\n any,\n any,\n any\n> {}\n\nexport interface AnyPublicQuery extends Ref<\n RuntimeAndFunctionType.AnyQuery,\n \"public\",\n any,\n any,\n any\n> {}\n\nexport interface AnyPublicMutation extends Ref<\n RuntimeAndFunctionType.AnyMutation,\n \"public\",\n any,\n any,\n any\n> {}\n\nexport interface AnyPublicAction extends Ref<\n RuntimeAndFunctionType.AnyAction,\n \"public\",\n any,\n any,\n any\n> {}\n\nexport type GetRuntimeAndFunctionType<Ref_> =\n Ref_ extends Ref<\n infer RuntimeAndFunctionType_,\n infer _FunctionVisibility,\n infer _Args,\n infer _Returns,\n infer _Error\n >\n ? RuntimeAndFunctionType_\n : never;\n\nexport type GetRuntime<Ref_> =\n Ref_ extends Ref<\n infer RuntimeAndFunctionType_,\n infer _FunctionVisibility,\n infer _Args,\n infer _Returns,\n infer _Error\n >\n ? RuntimeAndFunctionType.GetRuntime<RuntimeAndFunctionType_>\n : never;\n\nexport type GetFunctionType<Ref_> =\n Ref_ extends Ref<\n infer RuntimeAndFunctionType_,\n infer _FunctionVisibility,\n infer _Args,\n infer _Returns,\n infer _Error\n >\n ? RuntimeAndFunctionType.GetFunctionType<RuntimeAndFunctionType_>\n : never;\n\nexport type GetFunctionVisibility<Ref_> =\n Ref_ extends Ref<\n infer _RuntimeAndFunctionType,\n infer FunctionVisibility_,\n infer _Args,\n infer _Returns,\n infer _Error\n >\n ? FunctionVisibility_\n : never;\n\nexport type Args<Ref_> =\n Ref_ extends Ref<\n infer _RuntimeAndFunctionType,\n infer _FunctionVisibility,\n infer Args_,\n infer _Returns,\n infer _Error\n >\n ? Args_\n : never;\n\nexport type OptionalArgs<Ref_ extends Any> = keyof Args<Ref_> extends never\n ? [args?: Args<Ref_>]\n : [args: Args<Ref_>];\n\nexport type Returns<Ref_> =\n Ref_ extends Ref<\n infer _RuntimeAndFunctionType,\n infer _FunctionVisibility,\n infer _Args,\n infer Returns_,\n infer _Error\n >\n ? Returns_\n : never;\n\nexport type Error<Ref_> =\n Ref_ extends Ref<\n infer _RuntimeAndFunctionType,\n infer _FunctionVisibility,\n infer _Args,\n infer _Returns,\n infer Error_\n >\n ? Error_\n : never;\n\nexport type FunctionReference<Ref_ extends Any> = ConvexFunctionReference<\n GetFunctionType<Ref_>,\n GetFunctionVisibility<Ref_>\n>;\n\nexport type FromFunctionSpec<FunctionSpec_ extends FunctionSpec.AnyWithProps> =\n Ref<\n FunctionSpec.GetRuntimeAndFunctionType<FunctionSpec_>,\n FunctionSpec.GetFunctionVisibility<FunctionSpec_>,\n FunctionSpec.Args<FunctionSpec_>,\n FunctionSpec.Returns<FunctionSpec_>,\n FunctionSpec.Error<FunctionSpec_>\n >;\n\nexport const make = <FunctionSpec_ extends FunctionSpec.AnyWithProps>(\n /**\n * The namespace portion of a Convex function name, i.e. the part before the\n * colon. For example, for `myGroupDir/myGroupMod:myFunc` this would be\n * `myGroupDir/myGroupMod`.\n */\n functionNamespace: string,\n functionSpec: FunctionSpec_,\n): FromFunctionSpec<FunctionSpec_> => ({ functionSpec, functionNamespace });\n\nexport const getConvexFunctionName = (ref: Any): string =>\n `${ref.functionNamespace}:${ref.functionSpec.name}`;\n\nexport const getFunctionReference = <Ref_ extends Any>(\n ref: Ref_,\n): FunctionReference<Ref_> =>\n makeFunctionReference(getConvexFunctionName(ref)) as FunctionReference<Ref_>;\n\nexport const hasErrorSchema = (ref: Any): boolean =>\n Match.value(ref.functionSpec.functionProvenance).pipe(\n Match.tag(\n \"Confect\",\n (confectFunctionProvenance) =>\n confectFunctionProvenance.error !== undefined,\n ),\n Match.tag(\"Convex\", () => false),\n Match.exhaustive,\n );\n\nexport const encodeArgs = <Ref_ extends Any>(\n ref: Ref_,\n args: Args<Ref_>,\n): Effect.Effect<unknown, ParseResult.ParseError> =>\n Match.value(ref.functionSpec.functionProvenance).pipe(\n Match.tag(\"Confect\", (confectFunctionProvenance) =>\n Schema.encode(confectFunctionProvenance.args)(args),\n ),\n Match.tag(\"Convex\", () => Effect.succeed(args)),\n Match.exhaustive,\n );\n\nexport const decodeReturns = <Ref_ extends Any>(\n ref: Ref_,\n returns: unknown,\n): Effect.Effect<Returns<Ref_>, ParseResult.ParseError> =>\n Match.value(ref.functionSpec.functionProvenance).pipe(\n Match.tag(\"Confect\", (confectFunctionProvenance) =>\n Schema.decode(confectFunctionProvenance.returns)(returns),\n ),\n Match.tag(\"Convex\", () => Effect.succeed(returns)),\n Match.exhaustive,\n );\n\nexport const encodeArgsSync = <Ref_ extends Any>(\n ref: Ref_,\n args: Args<Ref_>,\n): unknown =>\n Match.value(ref.functionSpec.functionProvenance).pipe(\n Match.tag(\"Confect\", (confectFunctionProvenance) =>\n Schema.encodeSync(confectFunctionProvenance.args)(args),\n ),\n Match.tag(\"Convex\", () => args),\n Match.exhaustive,\n );\n\nexport const decodeReturnsSync = <Ref_ extends Any>(\n ref: Ref_,\n encodedReturns: unknown,\n): Returns<Ref_> =>\n Match.value(ref.functionSpec.functionProvenance).pipe(\n Match.tag(\"Confect\", (confectFunctionProvenance) =>\n Schema.decodeSync(confectFunctionProvenance.returns)(encodedReturns),\n ),\n Match.tag(\"Convex\", () => encodedReturns),\n Match.exhaustive,\n ) as Returns<Ref_>;\n\nconst ConvexErrorIdentifier = Symbol.for(\"ConvexError\");\n\nexport const isConvexError = (error: unknown): error is ConvexError<Value> =>\n error instanceof ConvexError ||\n (typeof error === \"object\" &&\n error !== null &&\n ConvexErrorIdentifier in error);\n\n/**\n * Build a callback-style handler that decodes the ref's typed error from a\n * caught `ConvexError`, or else forwards the value to `mapUnknownError`. The\n * fallback is also invoked when the input *is* a `ConvexError` but the ref\n * doesn't declare a typed-error schema—by definition such a value falls\n * outside the ref's error contract. Useful when adapting non-Effect APIs (e.g.\n * emitter callbacks for streamed subscriptions) to the same error semantics\n * that `runWithCodec` provides.\n */\nexport const decodeErrorOrElse =\n <Ref_ extends Any, E>(ref: Ref_, mapUnknownError: (error: unknown) => E) =>\n (error: unknown): Error<Ref_> | E => {\n if (isConvexError(error)) {\n const decoded = decodeErrorSync(ref, error.data);\n if (Option.isSome(decoded)) {\n return decoded.value;\n }\n }\n return mapUnknownError(error);\n };\n\n/**\n * Decode `encodedError` against the ref's error schema. Returns `None` if the\n * ref doesn't declare a typed error (Confect ref without an `error` schema, or\n * a Convex-provenance ref)—by definition there's nothing to decode the value\n * into, and the caller is responsible for deciding what to do (typically:\n * surface the original value as a defect).\n */\nexport const decodeError = <Ref_ extends Any>(\n ref: Ref_,\n encodedError: unknown,\n): Effect.Effect<Option.Option<Error<Ref_>>, ParseResult.ParseError> =>\n Match.value(ref.functionSpec.functionProvenance).pipe(\n Match.tag(\"Confect\", (confectFunctionProvenance) =>\n confectFunctionProvenance.error !== undefined\n ? Effect.map(\n Schema.decode(confectFunctionProvenance.error)(encodedError),\n Option.some,\n )\n : Effect.succeed(Option.none<Error<Ref_>>()),\n ),\n Match.tag(\"Convex\", () => Effect.succeed(Option.none<Error<Ref_>>())),\n Match.exhaustive,\n );\n\n/**\n * Synchronous counterpart to `decodeError`. Throws on schema decode failure;\n * returns `None` when the ref doesn't declare a typed error.\n */\nexport const decodeErrorSync = <Ref_ extends Any>(\n ref: Ref_,\n encodedError: unknown,\n): Option.Option<Error<Ref_>> =>\n Match.value(ref.functionSpec.functionProvenance).pipe(\n Match.tag(\"Confect\", (confectFunctionProvenance) =>\n confectFunctionProvenance.error !== undefined\n ? Option.some(\n Schema.decodeSync(confectFunctionProvenance.error)(\n encodedError,\n ) as Error<Ref_>,\n )\n : Option.none<Error<Ref_>>(),\n ),\n Match.tag(\"Convex\", () => Option.none<Error<Ref_>>()),\n Match.exhaustive,\n );\n\nexport const maybeDecodeErrorSync = <Ref_ extends Any>(\n ref: Ref_,\n error: unknown,\n): unknown =>\n isConvexError(error)\n ? Match.value(ref.functionSpec.functionProvenance).pipe(\n Match.tag(\"Confect\", (confectFunctionProvenance) =>\n confectFunctionProvenance.error !== undefined\n ? Schema.decodeSync(confectFunctionProvenance.error)(error.data)\n : error,\n ),\n Match.tag(\"Convex\", () => error),\n Match.exhaustive,\n )\n : error;\n\n/**\n * Encode args via the ref's args schema, invoke `call`, decode returns via the\n * ref's returns schema, and translate any thrown `ConvexError` into the ref's\n * typed error. Anything else the Promise rejects with—network failures,\n * server-side runtime errors, validation failures, etc.—is passed to\n * `mapUnknownError` to be turned into a typed `E`, or surfaced as a defect when\n * no handler is provided.\n */\nexport const runWithCodec = <Ref_ extends Any, E = never>(\n ref: Ref_,\n args: Args<Ref_>,\n call: (\n functionReference: FunctionReference<Ref_>,\n encodedArgs: unknown,\n ) => PromiseLike<unknown>,\n mapUnknownError?: (error: unknown) => E,\n): Effect.Effect<Returns<Ref_>, E | Error<Ref_> | ParseResult.ParseError> =>\n Effect.gen(function* () {\n const functionReference = getFunctionReference(ref);\n const functionProvenance = ref.functionSpec.functionProvenance;\n const invoke = (\n encodedArgs: unknown,\n ): Effect.Effect<unknown, Error<Ref_> | E> =>\n Effect.tryPromise({\n try: () => Promise.resolve(call(functionReference, encodedArgs)),\n catch: (error): Error<Ref_> | E => {\n if (isConvexError(error)) {\n const decoded = decodeErrorSync(ref, error.data);\n if (Option.isSome(decoded)) {\n return decoded.value;\n }\n }\n if (mapUnknownError !== undefined) {\n return mapUnknownError(error);\n }\n throw error;\n },\n });\n return yield* Match.value(functionProvenance).pipe(\n Match.tag(\"Confect\", (confectFunctionProvenance) =>\n Effect.gen(function* () {\n const encodedArgs = yield* Schema.encode(\n confectFunctionProvenance.args,\n )(args);\n const encodedReturns = yield* invoke(encodedArgs);\n return yield* Schema.decode(confectFunctionProvenance.returns)(\n encodedReturns,\n );\n }),\n ),\n Match.tag(\"Convex\", () => invoke(args)),\n Match.exhaustive,\n );\n });\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAmLA,MAAa,QAMX,mBACA,kBACqC;CAAE;CAAc;CAAmB;AAE1E,MAAa,yBAAyB,QACpC,GAAG,IAAI,kBAAkB,GAAG,IAAI,aAAa;AAE/C,MAAa,wBACX,QAEA,sBAAsB,sBAAsB,IAAI,CAAC;AAEnD,MAAa,kBAAkB,QAC7B,MAAM,MAAM,IAAI,aAAa,mBAAmB,CAAC,KAC/C,MAAM,IACJ,YACC,8BACC,0BAA0B,UAAU,OACvC,EACD,MAAM,IAAI,gBAAgB,MAAM,EAChC,MAAM,WACP;AAEH,MAAa,cACX,KACA,SAEA,MAAM,MAAM,IAAI,aAAa,mBAAmB,CAAC,KAC/C,MAAM,IAAI,YAAY,8BACpB,OAAO,OAAO,0BAA0B,KAAK,CAAC,KAAK,CACpD,EACD,MAAM,IAAI,gBAAgB,OAAO,QAAQ,KAAK,CAAC,EAC/C,MAAM,WACP;AAEH,MAAa,iBACX,KACA,YAEA,MAAM,MAAM,IAAI,aAAa,mBAAmB,CAAC,KAC/C,MAAM,IAAI,YAAY,8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"sources":["../src/Ref.ts"],"sourcesContent":["import type {\n FunctionReference as ConvexFunctionReference,\n FunctionVisibility,\n} from \"convex/server\";\nimport { makeFunctionReference } from \"convex/server\";\nimport type { Value } from \"convex/values\";\nimport { ConvexError } from \"convex/values\";\nimport type { ParseResult } from \"effect\";\nimport { Effect, Match, Option, Schema } from \"effect\";\nimport type * as FunctionSpec from \"./FunctionSpec\";\nimport type * as RuntimeAndFunctionType from \"./RuntimeAndFunctionType\";\n\nexport interface Ref<\n _RuntimeAndFunctionType extends RuntimeAndFunctionType.RuntimeAndFunctionType,\n _FunctionVisibility extends FunctionVisibility,\n _Args,\n _Returns,\n _Error = never,\n> {\n readonly _RuntimeAndFunctionType?: _RuntimeAndFunctionType;\n readonly _FunctionVisibility?: _FunctionVisibility;\n readonly _Args?: _Args;\n readonly _Returns?: _Returns;\n readonly _Error?: _Error;\n /** @internal */\n readonly functionSpec: FunctionSpec.AnyWithProps;\n /** @internal */\n readonly functionNamespace: string;\n}\n\nexport interface Any extends Ref<any, any, any, any, any> {}\n\nexport interface AnyInternal extends Ref<any, \"internal\", any, any, any> {}\n\nexport interface AnyPublic extends Ref<any, \"public\", any, any, any> {}\n\nexport interface AnyQuery extends Ref<\n RuntimeAndFunctionType.AnyQuery,\n FunctionVisibility,\n any,\n any,\n any\n> {}\n\nexport interface AnyMutation extends Ref<\n RuntimeAndFunctionType.AnyMutation,\n FunctionVisibility,\n any,\n any,\n any\n> {}\n\nexport interface AnyAction extends Ref<\n RuntimeAndFunctionType.AnyAction,\n FunctionVisibility,\n any,\n any,\n any\n> {}\n\nexport interface AnyPublicQuery extends Ref<\n RuntimeAndFunctionType.AnyQuery,\n \"public\",\n any,\n any,\n any\n> {}\n\nexport interface AnyPublicMutation extends Ref<\n RuntimeAndFunctionType.AnyMutation,\n \"public\",\n any,\n any,\n any\n> {}\n\nexport interface AnyPublicAction extends Ref<\n RuntimeAndFunctionType.AnyAction,\n \"public\",\n any,\n any,\n any\n> {}\n\nexport type GetRuntimeAndFunctionType<Ref_> =\n Ref_ extends Ref<\n infer RuntimeAndFunctionType_,\n infer _FunctionVisibility,\n infer _Args,\n infer _Returns,\n infer _Error\n >\n ? RuntimeAndFunctionType_\n : never;\n\nexport type GetRuntime<Ref_> =\n Ref_ extends Ref<\n infer RuntimeAndFunctionType_,\n infer _FunctionVisibility,\n infer _Args,\n infer _Returns,\n infer _Error\n >\n ? RuntimeAndFunctionType.GetRuntime<RuntimeAndFunctionType_>\n : never;\n\nexport type GetFunctionType<Ref_> =\n Ref_ extends Ref<\n infer RuntimeAndFunctionType_,\n infer _FunctionVisibility,\n infer _Args,\n infer _Returns,\n infer _Error\n >\n ? RuntimeAndFunctionType.GetFunctionType<RuntimeAndFunctionType_>\n : never;\n\nexport type GetFunctionVisibility<Ref_> =\n Ref_ extends Ref<\n infer _RuntimeAndFunctionType,\n infer FunctionVisibility_,\n infer _Args,\n infer _Returns,\n infer _Error\n >\n ? FunctionVisibility_\n : never;\n\nexport type Args<Ref_> =\n Ref_ extends Ref<\n infer _RuntimeAndFunctionType,\n infer _FunctionVisibility,\n infer Args_,\n infer _Returns,\n infer _Error\n >\n ? Args_\n : never;\n\nexport type OptionalArgs<Ref_ extends Any> = keyof Args<Ref_> extends never\n ? [args?: Args<Ref_>]\n : [args: Args<Ref_>];\n\nexport type Returns<Ref_> =\n Ref_ extends Ref<\n infer _RuntimeAndFunctionType,\n infer _FunctionVisibility,\n infer _Args,\n infer Returns_,\n infer _Error\n >\n ? Returns_\n : never;\n\nexport type Error<Ref_> =\n Ref_ extends Ref<\n infer _RuntimeAndFunctionType,\n infer _FunctionVisibility,\n infer _Args,\n infer _Returns,\n infer Error_\n >\n ? Error_\n : never;\n\nexport type FunctionReference<Ref_ extends Any> = ConvexFunctionReference<\n GetFunctionType<Ref_>,\n GetFunctionVisibility<Ref_>\n>;\n\nexport type FromFunctionSpec<FunctionSpec_ extends FunctionSpec.AnyWithProps> =\n Ref<\n FunctionSpec.GetRuntimeAndFunctionType<FunctionSpec_>,\n FunctionSpec.GetFunctionVisibility<FunctionSpec_>,\n FunctionSpec.Args<FunctionSpec_>,\n FunctionSpec.Returns<FunctionSpec_>,\n FunctionSpec.Error<FunctionSpec_>\n >;\n\nexport const make = <FunctionSpec_ extends FunctionSpec.AnyWithProps>(\n /**\n * The namespace portion of a Convex function name, i.e. the part before the\n * colon. For example, for `myGroupDir/myGroupMod:myFunc` this would be\n * `myGroupDir/myGroupMod`.\n */\n functionNamespace: string,\n functionSpec: FunctionSpec_,\n): FromFunctionSpec<FunctionSpec_> => ({ functionSpec, functionNamespace });\n\nexport const getConvexFunctionName = (ref: Any): string =>\n `${ref.functionNamespace}:${ref.functionSpec.name}`;\n\nexport const getFunctionReference = <Ref_ extends Any>(\n ref: Ref_,\n): FunctionReference<Ref_> =>\n makeFunctionReference(getConvexFunctionName(ref)) as FunctionReference<Ref_>;\n\nexport const hasErrorSchema = (ref: Any): boolean =>\n Match.value(ref.functionSpec.functionProvenance).pipe(\n Match.tag(\n \"Confect\",\n (confectFunctionProvenance) => \"error\" in confectFunctionProvenance,\n ),\n Match.tag(\"Convex\", () => false),\n Match.exhaustive,\n );\n\nexport const encodeArgs = <Ref_ extends Any>(\n ref: Ref_,\n args: Args<Ref_>,\n): Effect.Effect<unknown, ParseResult.ParseError> =>\n Match.value(ref.functionSpec.functionProvenance).pipe(\n Match.tag(\"Confect\", (confectFunctionProvenance) =>\n Schema.encode(confectFunctionProvenance.args)(args),\n ),\n Match.tag(\"Convex\", () => Effect.succeed(args)),\n Match.exhaustive,\n );\n\nexport const decodeReturns = <Ref_ extends Any>(\n ref: Ref_,\n returns: unknown,\n): Effect.Effect<Returns<Ref_>, ParseResult.ParseError> =>\n Match.value(ref.functionSpec.functionProvenance).pipe(\n Match.tag(\"Confect\", (confectFunctionProvenance) =>\n Schema.decode(confectFunctionProvenance.returns)(returns),\n ),\n Match.tag(\"Convex\", () => Effect.succeed(returns)),\n Match.exhaustive,\n );\n\nexport const encodeArgsSync = <Ref_ extends Any>(\n ref: Ref_,\n args: Args<Ref_>,\n): unknown =>\n Match.value(ref.functionSpec.functionProvenance).pipe(\n Match.tag(\"Confect\", (confectFunctionProvenance) =>\n Schema.encodeSync(confectFunctionProvenance.args)(args),\n ),\n Match.tag(\"Convex\", () => args),\n Match.exhaustive,\n );\n\nexport const decodeReturnsSync = <Ref_ extends Any>(\n ref: Ref_,\n encodedReturns: unknown,\n): Returns<Ref_> =>\n Match.value(ref.functionSpec.functionProvenance).pipe(\n Match.tag(\"Confect\", (confectFunctionProvenance) =>\n Schema.decodeSync(confectFunctionProvenance.returns)(encodedReturns),\n ),\n Match.tag(\"Convex\", () => encodedReturns),\n Match.exhaustive,\n ) as Returns<Ref_>;\n\nconst ConvexErrorIdentifier = Symbol.for(\"ConvexError\");\n\nexport const isConvexError = (error: unknown): error is ConvexError<Value> =>\n error instanceof ConvexError ||\n (typeof error === \"object\" &&\n error !== null &&\n ConvexErrorIdentifier in error);\n\n/**\n * Build a callback-style handler that decodes the ref's typed error from a\n * caught `ConvexError`, or else forwards the value to `mapUnknownError`. The\n * fallback is also invoked when the input *is* a `ConvexError` but the ref\n * doesn't declare a typed-error schema—by definition such a value falls\n * outside the ref's error contract. Useful when adapting non-Effect APIs (e.g.\n * emitter callbacks for streamed subscriptions) to the same error semantics\n * that `runWithCodec` provides.\n */\nexport const decodeErrorOrElse =\n <Ref_ extends Any, E>(ref: Ref_, mapUnknownError: (error: unknown) => E) =>\n (error: unknown): Error<Ref_> | E => {\n if (isConvexError(error)) {\n const decoded = decodeErrorSync(ref, error.data);\n if (Option.isSome(decoded)) {\n return decoded.value;\n }\n }\n return mapUnknownError(error);\n };\n\n/**\n * Decode `encodedError` against the ref's error schema. Returns `None` if the\n * ref doesn't declare a typed error (Confect ref without an `error` schema, or\n * a Convex-provenance ref)—by definition there's nothing to decode the value\n * into, and the caller is responsible for deciding what to do (typically:\n * surface the original value as a defect).\n */\nexport const decodeError = <Ref_ extends Any>(\n ref: Ref_,\n encodedError: unknown,\n): Effect.Effect<Option.Option<Error<Ref_>>, ParseResult.ParseError> =>\n Match.value(ref.functionSpec.functionProvenance).pipe(\n Match.tag(\"Confect\", (confectFunctionProvenance) =>\n \"error\" in confectFunctionProvenance\n ? Effect.map(\n Schema.decode(confectFunctionProvenance.error)(encodedError),\n Option.some,\n )\n : Effect.succeed(Option.none<Error<Ref_>>()),\n ),\n Match.tag(\"Convex\", () => Effect.succeed(Option.none<Error<Ref_>>())),\n Match.exhaustive,\n );\n\n/**\n * Synchronous counterpart to `decodeError`. Throws on schema decode failure;\n * returns `None` when the ref doesn't declare a typed error.\n */\nexport const decodeErrorSync = <Ref_ extends Any>(\n ref: Ref_,\n encodedError: unknown,\n): Option.Option<Error<Ref_>> =>\n Match.value(ref.functionSpec.functionProvenance).pipe(\n Match.tag(\"Confect\", (confectFunctionProvenance) =>\n \"error\" in confectFunctionProvenance\n ? Option.some(\n Schema.decodeSync(confectFunctionProvenance.error)(\n encodedError,\n ) as Error<Ref_>,\n )\n : Option.none<Error<Ref_>>(),\n ),\n Match.tag(\"Convex\", () => Option.none<Error<Ref_>>()),\n Match.exhaustive,\n );\n\nexport const maybeDecodeErrorSync = <Ref_ extends Any>(\n ref: Ref_,\n error: unknown,\n): unknown =>\n isConvexError(error)\n ? Match.value(ref.functionSpec.functionProvenance).pipe(\n Match.tag(\"Confect\", (confectFunctionProvenance) =>\n \"error\" in confectFunctionProvenance\n ? Schema.decodeSync(confectFunctionProvenance.error)(error.data)\n : error,\n ),\n Match.tag(\"Convex\", () => error),\n Match.exhaustive,\n )\n : error;\n\n/**\n * Encode args via the ref's args schema, invoke `call`, decode returns via the\n * ref's returns schema, and translate any thrown `ConvexError` into the ref's\n * typed error. Anything else the Promise rejects with—network failures,\n * server-side runtime errors, validation failures, etc.—is passed to\n * `mapUnknownError` to be turned into a typed `E`, or surfaced as a defect when\n * no handler is provided.\n */\nexport const runWithCodec = <Ref_ extends Any, E = never>(\n ref: Ref_,\n args: Args<Ref_>,\n call: (\n functionReference: FunctionReference<Ref_>,\n encodedArgs: unknown,\n ) => PromiseLike<unknown>,\n mapUnknownError?: (error: unknown) => E,\n): Effect.Effect<Returns<Ref_>, E | Error<Ref_> | ParseResult.ParseError> =>\n Effect.gen(function* () {\n const functionReference = getFunctionReference(ref);\n const functionProvenance = ref.functionSpec.functionProvenance;\n const invoke = (\n encodedArgs: unknown,\n ): Effect.Effect<unknown, Error<Ref_> | E> =>\n Effect.tryPromise({\n try: () => Promise.resolve(call(functionReference, encodedArgs)),\n catch: (error): Error<Ref_> | E => {\n if (isConvexError(error)) {\n const decoded = decodeErrorSync(ref, error.data);\n if (Option.isSome(decoded)) {\n return decoded.value;\n }\n }\n if (mapUnknownError !== undefined) {\n return mapUnknownError(error);\n }\n throw error;\n },\n });\n return yield* Match.value(functionProvenance).pipe(\n Match.tag(\"Confect\", (confectFunctionProvenance) =>\n Effect.gen(function* () {\n const encodedArgs = yield* Schema.encode(\n confectFunctionProvenance.args,\n )(args);\n const encodedReturns = yield* invoke(encodedArgs);\n return yield* Schema.decode(confectFunctionProvenance.returns)(\n encodedReturns,\n );\n }),\n ),\n Match.tag(\"Convex\", () => invoke(args)),\n Match.exhaustive,\n );\n });\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAmLA,MAAa,QAMX,mBACA,kBACqC;CAAE;CAAc;CAAmB;AAE1E,MAAa,yBAAyB,QACpC,GAAG,IAAI,kBAAkB,GAAG,IAAI,aAAa;AAE/C,MAAa,wBACX,QAEA,sBAAsB,sBAAsB,IAAI,CAAC;AAEnD,MAAa,kBAAkB,QAC7B,MAAM,MAAM,IAAI,aAAa,mBAAmB,CAAC,KAC/C,MAAM,IACJ,YACC,8BAA8B,WAAW,0BAC3C,EACD,MAAM,IAAI,gBAAgB,MAAM,EAChC,MAAM,WACP;AAEH,MAAa,cACX,KACA,SAEA,MAAM,MAAM,IAAI,aAAa,mBAAmB,CAAC,KAC/C,MAAM,IAAI,YAAY,8BACpB,OAAO,OAAO,0BAA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;AACjD,SAAO,OAAO,OAAO,OAAO,0BAA0B,QAAQ,CAC5D,eACD;GACD,CACH,EACD,MAAM,IAAI,gBAAgB,OAAO,KAAK,CAAC,EACvC,MAAM,WACP;EACD"}
package/dist/Spec.d.ts CHANGED
@@ -14,26 +14,8 @@ interface Spec<Runtime$1 extends Runtime, Groups_ extends AnyWithPropsWithRuntim
14
14
  readonly [TypeId]: TypeId;
15
15
  readonly runtime: Runtime$1;
16
16
  readonly groups: { [GroupName in Name<Groups_>]: WithName<Groups_, GroupName> };
17
- /**
18
- * Mapping from an imported leaf `GroupSpec` reference to its full dot-path
19
- * within this spec tree. Populated by codegen-emitted `_generated/spec.ts`
20
- * via {@link Spec#addPath}; consumed by `FunctionImpl.make` /
21
- * `GroupImpl.make` to resolve a spec's location without walking the tree.
22
- */
23
- readonly paths: ReadonlyMap<AnyWithProps$1, string>;
24
17
  add<Group extends AnyWithPropsWithRuntime$1<Runtime$1>>(group: Group): Spec<Runtime$1, Groups_ | Group>;
25
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>>;
26
- /**
27
- * Register the imported leaf `group` at `path` within this spec's path
28
- * mapping. Returns a new `Spec` with one additional entry. The tree shape
29
- * (`groups`) is unaffected — registration and tree assembly are
30
- * independent steps, both performed by codegen in `_generated/spec.ts`.
31
- *
32
- * Re-registering the same group with the same path is a no-op (cheap
33
- * defense for codegen watch-mode re-imports). Re-registering with a
34
- * different path throws.
35
- */
36
- addPath(group: AnyWithProps$1, path: string): Spec<Runtime$1, Groups_>;
37
19
  }
38
20
  interface Any {
39
21
  readonly [TypeId]: TypeId;
@@ -44,11 +26,10 @@ type Groups<Spec_ extends AnyWithProps> = Spec_["groups"][keyof Spec_["groups"]]
44
26
  declare const make: () => Spec<"Convex">;
45
27
  declare const makeNode: () => Spec<"Node">;
46
28
  /**
47
- * Merges a Convex spec with an optional Node spec for use with `Api.make`.
29
+ * Merges a Convex spec with an optional Node spec into a single assembled
30
+ * spec (used by codegen to build `Refs.make` and to enumerate function paths).
48
31
  * When `nodeSpec` is provided, its groups are merged under a "node" namespace,
49
- * mirroring the structure used by `Refs.make`. The node spec's `paths`
50
- * entries are re-prefixed with `"node."` so they continue to identify the
51
- * same leaves at their new positions in the merged tree.
32
+ * mirroring the structure used by `Refs.make`.
52
33
  */
53
34
  declare const merge: <ConvexSpec extends AnyWithPropsWithRuntime<"Convex">, NodeSpec extends AnyWithPropsWithRuntime<"Node">>(convexSpec: ConvexSpec, nodeSpec?: NodeSpec) => AnyWithProps;
54
35
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"Spec.d.ts","names":[],"sources":["../src/Spec.ts"],"mappings":";;;;;;;cAKa,MAAA;AAAA,KACD,MAAA,UAAgB,MAAA;AAAA,cAEf,MAAA,GAAU,CAAA,cAAa,CAAA,IAAK,YAAA;AAAA,cAG5B,YAAA,GACX,CAAA,cACC,CAAA,IAAK,uBAAA;AAAA,cAKK,UAAA,GAAc,CAAA,cAAa,CAAA,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;;;;;;;WASK,KAAA,EAAO,WAAA,CAAY,cAAA;EAE5B,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;EAhDnC;;AACnB;;;;;AAEA;;;EAyDE,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AAkB,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;;;cA0Ga,KAAA,sBACQ,uBAAA,6BACF,uBAAA,UAEjB,UAAA,EAAY,UAAA,EACZ,QAAA,GAAW,QAAA,KACV,YAAA"}
package/dist/Spec.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
- import { validateConfectFunctionIdentifier } from "./internal/utils.js";
3
2
  import { makeNodeAt, withName } from "./GroupSpec.js";
4
- import { Array, Option, Predicate, Record, String } from "effect";
3
+ import { Array, Option, Predicate, Record } from "effect";
5
4
 
6
5
  //#region src/Spec.ts
7
6
  var Spec_exports = /* @__PURE__ */ __exportAll({
@@ -17,68 +16,38 @@ const TypeId = "@confect/core/Spec";
17
16
  const isSpec = (u) => Predicate.hasProperty(u, TypeId);
18
17
  const isConvexSpec = (u) => Predicate.hasProperty(u, TypeId) && Predicate.hasProperty(u, "runtime") && u.runtime === "Convex";
19
18
  const isNodeSpec = (u) => Predicate.hasProperty(u, TypeId) && Predicate.hasProperty(u, "runtime") && u.runtime === "Node";
20
- const validatePath = (path) => {
21
- if (path.length === 0) throw new Error("Expected a non-empty Confect group path, but received an empty string.");
22
- const segments = String.split(path, ".");
23
- for (const segment of segments) {
24
- if (segment.length === 0) throw new Error(`Expected a Confect group path made of dot-separated identifier segments, but received: "${path}".`);
25
- validateConfectFunctionIdentifier(segment);
26
- }
27
- };
28
19
  const Proto = {
29
20
  [TypeId]: TypeId,
30
21
  add(group) {
31
22
  return makeProto({
32
23
  runtime: this.runtime,
33
- groups: Record.set(this.groups, group.name, group),
34
- paths: this.paths
24
+ groups: Record.set(this.groups, group.name, group)
35
25
  });
36
26
  },
37
27
  addAt(name, group) {
38
28
  return makeProto({
39
29
  runtime: this.runtime,
40
- groups: Record.set(this.groups, name, withName(name, group)),
41
- paths: this.paths
42
- });
43
- },
44
- addPath(group, path) {
45
- validatePath(path);
46
- const existing = this.paths.get(group);
47
- if (existing !== void 0) {
48
- if (existing === path) return this;
49
- throw new Error(`Spec.addPath: the provided GroupSpec is already registered at "${existing}", but was re-registered at "${path}". Each GroupSpec must have at most one path.`);
50
- }
51
- const nextPaths = new Map(this.paths);
52
- nextPaths.set(group, path);
53
- return makeProto({
54
- runtime: this.runtime,
55
- groups: this.groups,
56
- paths: nextPaths
30
+ groups: Record.set(this.groups, name, withName(name, group))
57
31
  });
58
32
  }
59
33
  };
60
- const makeProto = ({ runtime, groups, paths }) => Object.assign(Object.create(Proto), {
34
+ const makeProto = ({ runtime, groups }) => Object.assign(Object.create(Proto), {
61
35
  runtime,
62
- groups,
63
- paths
36
+ groups
64
37
  });
65
- const emptyPaths = () => /* @__PURE__ */ new Map();
66
38
  const make = () => makeProto({
67
39
  runtime: "Convex",
68
- groups: {},
69
- paths: emptyPaths()
40
+ groups: {}
70
41
  });
71
42
  const makeNode = () => makeProto({
72
43
  runtime: "Node",
73
- groups: {},
74
- paths: emptyPaths()
44
+ groups: {}
75
45
  });
76
46
  /**
77
- * Merges a Convex spec with an optional Node spec for use with `Api.make`.
47
+ * Merges a Convex spec with an optional Node spec into a single assembled
48
+ * spec (used by codegen to build `Refs.make` and to enumerate function paths).
78
49
  * When `nodeSpec` is provided, its groups are merged under a "node" namespace,
79
- * mirroring the structure used by `Refs.make`. The node spec's `paths`
80
- * entries are re-prefixed with `"node."` so they continue to identify the
81
- * same leaves at their new positions in the merged tree.
50
+ * mirroring the structure used by `Refs.make`.
82
51
  */
83
52
  const merge = (convexSpec, nodeSpec) => {
84
53
  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({
@@ -88,12 +57,9 @@ const merge = (convexSpec, nodeSpec) => {
88
57
  node: nodeGroup
89
58
  })
90
59
  }));
91
- const paths = new Map(convexSpec.paths);
92
- if (nodeSpec !== void 0) for (const [group, path] of nodeSpec.paths) paths.set(group, `node.${path}`);
93
60
  return Object.assign(Object.create(Proto), {
94
61
  runtime: "Convex",
95
- groups,
96
- paths
62
+ groups
97
63
  });
98
64
  };
99
65
 
package/dist/Spec.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Spec.js","names":["GroupSpec.withName","GroupSpec.makeNodeAt"],"sources":["../src/Spec.ts"],"sourcesContent":["import { Array, Option, Predicate, Record, String } from \"effect\";\nimport * as GroupSpec from \"./GroupSpec\";\nimport type * as RuntimeAndFunctionType from \"./RuntimeAndFunctionType\";\nimport { validateConfectFunctionIdentifier } from \"./internal/utils\";\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 * Mapping from an imported leaf `GroupSpec` reference to its full dot-path\n * within this spec tree. Populated by codegen-emitted `_generated/spec.ts`\n * via {@link Spec#addPath}; consumed by `FunctionImpl.make` /\n * `GroupImpl.make` to resolve a spec's location without walking the tree.\n */\n readonly paths: ReadonlyMap<GroupSpec.AnyWithProps, string>;\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 /**\n * Register the imported leaf `group` at `path` within this spec's path\n * mapping. Returns a new `Spec` with one additional entry. The tree shape\n * (`groups`) is unaffected — registration and tree assembly are\n * independent steps, both performed by codegen in `_generated/spec.ts`.\n *\n * Re-registering the same group with the same path is a no-op (cheap\n * defense for codegen watch-mode re-imports). Re-registering with a\n * different path throws.\n */\n addPath(group: GroupSpec.AnyWithProps, path: string): Spec<Runtime, Groups_>;\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 validatePath = (path: string): void => {\n if (path.length === 0) {\n throw new Error(\n \"Expected a non-empty Confect group path, but received an empty string.\",\n );\n }\n\n const segments = String.split(path, \".\");\n\n for (const segment of segments) {\n if (segment.length === 0) {\n throw new Error(\n `Expected a Confect group path made of dot-separated identifier segments, but received: \"${path}\".`,\n );\n }\n validateConfectFunctionIdentifier(segment);\n }\n};\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 paths: this.paths,\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 paths: this.paths,\n });\n },\n\n addPath(this: AnyWithProps, group: GroupSpec.AnyWithProps, path: string) {\n validatePath(path);\n\n const existing = this.paths.get(group);\n if (existing !== undefined) {\n if (existing === path) {\n return this;\n }\n throw new Error(\n `Spec.addPath: the provided GroupSpec is already registered at \"${existing}\", but was re-registered at \"${path}\". Each GroupSpec must have at most one path.`,\n );\n }\n\n const nextPaths = new Map(this.paths);\n nextPaths.set(group, path);\n\n return makeProto({\n runtime: this.runtime,\n groups: this.groups,\n paths: nextPaths,\n });\n },\n};\n\nconst makeProto = <\n Runtime extends RuntimeAndFunctionType.Runtime,\n Groups_ extends GroupSpec.AnyWithPropsWithRuntime<Runtime>,\n>({\n runtime,\n groups,\n paths,\n}: {\n runtime: Runtime;\n groups: Record.ReadonlyRecord<string, Groups_>;\n paths: ReadonlyMap<GroupSpec.AnyWithProps, string>;\n}): Spec<Runtime, Groups_> =>\n Object.assign(Object.create(Proto), {\n runtime,\n groups,\n paths,\n });\n\nconst emptyPaths = (): ReadonlyMap<GroupSpec.AnyWithProps, string> => new Map();\n\nexport const make = (): Spec<\"Convex\"> =>\n makeProto({ runtime: \"Convex\", groups: {}, paths: emptyPaths() });\n\nexport const makeNode = (): Spec<\"Node\"> =>\n makeProto({ runtime: \"Node\", groups: {}, paths: emptyPaths() });\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`. The node spec's `paths`\n * entries are re-prefixed with `\"node.\"` so they continue to identify the\n * same leaves at their new positions in the merged tree.\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 const paths = new Map(convexSpec.paths);\n if (nodeSpec !== undefined) {\n for (const [group, path] of nodeSpec.paths) {\n paths.set(group, `node.${path}`);\n }\n }\n\n return Object.assign(Object.create(Proto), {\n runtime: \"Convex\" as const,\n groups,\n paths,\n }) as AnyWithProps;\n};\n"],"mappings":";;;;;;;;;;;;;;;AAKA,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;AA+DhB,MAAM,gBAAgB,SAAuB;AAC3C,KAAI,KAAK,WAAW,EAClB,OAAM,IAAI,MACR,yEACD;CAGH,MAAM,WAAW,OAAO,MAAM,MAAM,IAAI;AAExC,MAAK,MAAM,WAAW,UAAU;AAC9B,MAAI,QAAQ,WAAW,EACrB,OAAM,IAAI,MACR,2FAA2F,KAAK,IACjG;AAEH,oCAAkC,QAAQ;;;AAI9C,MAAM,QAAQ;EACX,SAAS;CAEV,IAA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AE,GAAG,WAAW;GAAQ,MAAM;GAAW;EAClE,CAAC,CACH;CAED,MAAM,QAAQ,IAAI,IAAI,WAAW,MAAM;AACvC,KAAI,aAAa,OACf,MAAK,MAAM,CAAC,OAAO,SAAS,SAAS,MACnC,OAAM,IAAI,OAAO,QAAQ,OAAO;AAIpC,QAAO,OAAO,OAAO,OAAO,OAAO,MAAM,EAAE;EACzC,SAAS;EACT;EACA;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 into a single assembled\n * spec (used by codegen to build `Refs.make` and to enumerate function paths).\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;;;;;;;AAQ5C,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
@@ -4,6 +4,8 @@ import { FunctionSpec_d_exports } from "./FunctionSpec.js";
4
4
  import { GenericId_d_exports } from "./GenericId.js";
5
5
  import { GroupSpec_d_exports } from "./GroupSpec.js";
6
6
  import { GroupPath_d_exports } from "./GroupPath.js";
7
+ import { Identifier_d_exports } from "./Identifier.js";
8
+ import { Lazy_d_exports } from "./Lazy.js";
7
9
  import { PaginationResult_d_exports } from "./PaginationResult.js";
8
10
  import { Ref_d_exports } from "./Ref.js";
9
11
  import { Spec_d_exports } from "./Spec.js";
@@ -12,4 +14,4 @@ import { Registry_d_exports } from "./Registry.js";
12
14
  import { SystemFields_d_exports } from "./SystemFields.js";
13
15
  import { Types_d_exports } from "./Types.js";
14
16
  import { UserIdentity_d_exports } from "./UserIdentity.js";
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 };
17
+ 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, Identifier_d_exports as Identifier, Lazy_d_exports as Lazy, 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
@@ -1,4 +1,6 @@
1
+ import { Lazy_exports } from "./Lazy.js";
1
2
  import { FunctionProvenance_exports } from "./FunctionProvenance.js";
3
+ import { Identifier_exports } from "./Identifier.js";
2
4
  import { RuntimeAndFunctionType_exports } from "./RuntimeAndFunctionType.js";
3
5
  import { FunctionSpec_exports } from "./FunctionSpec.js";
4
6
  import { GenericId_exports } from "./GenericId.js";
@@ -13,4 +15,4 @@ import { SystemFields_exports } from "./SystemFields.js";
13
15
  import { Types_exports } from "./Types.js";
14
16
  import { UserIdentity_exports } from "./UserIdentity.js";
15
17
 
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 };
18
+ export { FunctionProvenance_exports as FunctionProvenance, FunctionSpec_exports as FunctionSpec, GenericId_exports as GenericId, GroupPath_exports as GroupPath, GroupSpec_exports as GroupSpec, Identifier_exports as Identifier, Lazy_exports as Lazy, 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,25 +1,28 @@
1
1
  {
2
2
  "name": "@confect/core",
3
- "version": "9.0.0-next.5",
4
3
  "description": "Shared specs and schemas used by all Confect packages",
5
- "repository": {
6
- "type": "git",
7
- "url": "https://github.com/rjdellecese/confect.git"
8
- },
4
+ "version": "9.0.0-next.6",
5
+ "author": "RJ Dellecese",
9
6
  "bugs": {
10
7
  "url": "https://github.com/rjdellecese/confect/issues"
11
8
  },
12
- "homepage": "https://confect.dev",
13
- "sideEffects": false,
14
- "type": "module",
15
- "files": [
16
- "CHANGELOG.md",
17
- "LICENSE",
18
- "README.md",
19
- "dist",
20
- "package.json",
21
- "src"
22
- ],
9
+ "devDependencies": {
10
+ "@ark/attest": "0.56.0",
11
+ "@effect/vitest": "0.29.0",
12
+ "@eslint/js": "10.0.1",
13
+ "@types/node": "25.3.3",
14
+ "effect": "3.21.2",
15
+ "eslint": "10.0.2",
16
+ "prettier": "3.8.1",
17
+ "tsdown": "0.20.3",
18
+ "tsx": "4.21.0",
19
+ "typescript": "5.9.3",
20
+ "typescript-eslint": "8.56.1",
21
+ "vitest": "3.2.4"
22
+ },
23
+ "engines": {
24
+ "node": ">=22"
25
+ },
23
26
  "exports": {
24
27
  ".": {
25
28
  "types": "./dist/index.d.ts",
@@ -32,46 +35,42 @@
32
35
  "./package.json": "./package.json",
33
36
  "./internal/*": null
34
37
  },
38
+ "files": [
39
+ "CHANGELOG.md",
40
+ "LICENSE",
41
+ "README.md",
42
+ "dist",
43
+ "package.json",
44
+ "src"
45
+ ],
46
+ "homepage": "https://confect.dev",
35
47
  "keywords": [
36
- "effect",
37
- "convex"
48
+ "convex",
49
+ "effect"
38
50
  ],
39
- "author": "RJ Dellecese",
40
51
  "license": "ISC",
41
- "devDependencies": {
42
- "@ark/attest": "0.56.0",
43
- "@effect/vitest": "0.29.0",
44
- "@eslint/js": "10.0.1",
45
- "@types/node": "25.3.3",
46
- "effect": "3.21.2",
47
- "eslint": "10.0.2",
48
- "prettier": "3.8.1",
49
- "tsdown": "0.20.3",
50
- "tsx": "4.21.0",
51
- "typescript": "5.9.3",
52
- "typescript-eslint": "8.56.1",
53
- "vitest": "3.2.4"
54
- },
52
+ "main": "./dist/index.js",
53
+ "module": "./dist/index.js",
55
54
  "peerDependencies": {
56
55
  "convex": "1.39.1",
57
56
  "effect": "^3.21.2"
58
57
  },
59
- "engines": {
60
- "node": ">=22",
61
- "pnpm": ">=10"
58
+ "repository": {
59
+ "type": "git",
60
+ "url": "https://github.com/rjdellecese/confect.git"
62
61
  },
63
- "main": "./dist/index.js",
64
- "module": "./dist/index.js",
62
+ "sideEffects": false,
63
+ "type": "module",
65
64
  "types": "./dist/index.d.ts",
66
65
  "scripts": {
66
+ "bench": "tsx test/Refs.bench.ts",
67
67
  "build": "tsdown --config-loader unrun",
68
+ "clean": "rm -rf dist coverage node_modules",
68
69
  "dev": "tsdown --watch",
69
- "test": "vitest run",
70
- "typecheck": "tsc --noEmit --project tsconfig.json",
71
70
  "fix": "prettier --write . && eslint --fix . --max-warnings=0",
72
71
  "format": "prettier --check .",
73
72
  "lint": "eslint . --max-warnings=0",
74
- "bench": "tsx test/Refs.bench.ts",
75
- "clean": "rm -rf dist coverage node_modules"
73
+ "test": "vitest run",
74
+ "typecheck": "tsc --noEmit --project tsconfig.json"
76
75
  }
77
76
  }
@@ -1,6 +1,7 @@
1
1
  import type { DefaultFunctionArgs } from "convex/server";
2
2
  import type { Schema } from "effect";
3
3
  import { Data } from "effect";
4
+ import * as Lazy from "./Lazy";
4
5
 
5
6
  export type FunctionProvenance = Data.TaggedEnum<{
6
7
  Confect: {
@@ -43,20 +44,41 @@ export interface AnyConvex extends Convex<DefaultFunctionArgs, any> {}
43
44
 
44
45
  export const FunctionProvenance = Data.taggedEnum<FunctionProvenance>();
45
46
 
47
+ /**
48
+ * Build a `Confect` provenance from lazy schema thunks. `args`, `returns`,
49
+ * and `error` are exposed as sync lazy memoised getters (via {@link Lazy.defineProperty})
50
+ * that only evaluate their thunk on first access, mirroring how `Table`
51
+ * defers `Fields`/`Doc`/`tableDefinition`. This keeps importing the assembled
52
+ * `_generated/spec.ts` cheap — no `Schema.Struct(...)` / `Schema.Array(...)`
53
+ * work runs at module load; it is deferred to the first invocation that
54
+ * actually compiles validators or runs a codec.
55
+ *
56
+ * The object is built by hand rather than through `FunctionProvenance.Confect`
57
+ * because the `Data` constructor copies its input with `Object.assign`, which
58
+ * would force the getters at construction time and defeat the laziness.
59
+ * `error` is only installed when an `errorThunk` is provided, so its absence
60
+ * is observable via `"error" in provenance` without forcing anything; nothing
61
+ * relies on `Data`'s structural `Equal`/`Hash` for provenance values.
62
+ */
46
63
  export const Confect = <
47
64
  Args extends Schema.Schema.AnyNoContext,
48
65
  Returns extends Schema.Schema.AnyNoContext,
49
66
  Error extends Schema.Schema.AnyNoContext = never,
50
67
  >(
51
- args: Args,
52
- returns: Returns,
53
- error?: Error,
54
- ) =>
55
- FunctionProvenance.Confect({
56
- args,
57
- returns,
58
- ...(error !== undefined ? { error } : {}),
59
- });
68
+ args: () => Args,
69
+ returns: () => Returns,
70
+ error?: () => Error,
71
+ ): Confect<Args, Returns, Error> => {
72
+ const provenance = { _tag: "Confect" as const };
73
+
74
+ Lazy.defineProperty(provenance, "args", args);
75
+ Lazy.defineProperty(provenance, "returns", returns);
76
+ if (error !== undefined) {
77
+ Lazy.defineProperty(provenance, "error", error);
78
+ }
79
+
80
+ return provenance as Confect<Args, Returns, Error>;
81
+ };
60
82
 
61
83
  export const Convex = <_Args extends DefaultFunctionArgs, _Returns>() =>
62
84
  FunctionProvenance.Convex(
@@ -8,7 +8,7 @@ import type {
8
8
  import type { Schema } from "effect";
9
9
  import { Predicate } from "effect";
10
10
  import * as FunctionProvenance from "./FunctionProvenance";
11
- import { validateConfectFunctionIdentifier } from "./internal/utils";
11
+ import { validateConfectFunctionIdentifier } from "./Identifier";
12
12
  import * as RuntimeAndFunctionType from "./RuntimeAndFunctionType";
13
13
 
14
14
  export const TypeId = "@confect/core/FunctionSpec";
@@ -225,9 +225,9 @@ const make =
225
225
  error,
226
226
  }: {
227
227
  name: Name_;
228
- args: Args_;
229
- returns: Returns_;
230
- error?: Error_;
228
+ args: () => Args_;
229
+ returns: () => Returns_;
230
+ error?: () => Error_;
231
231
  }): FunctionSpec<
232
232
  RuntimeAndFunctionType_,
233
233
  FunctionVisibility_,
package/src/GroupSpec.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Predicate, Record } from "effect";
2
2
  import type * as FunctionSpec from "./FunctionSpec";
3
3
  import type * as RuntimeAndFunctionType from "./RuntimeAndFunctionType";
4
- import { validateConfectFunctionIdentifier } from "./internal/utils";
4
+ import { validateConfectFunctionIdentifier } from "./Identifier";
5
5
 
6
6
  export const TypeId = "@confect/core/GroupSpec";
7
7
  export type TypeId = typeof TypeId;