@confect/core 9.2.2 → 10.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 +16 -1
- package/dist/FunctionProvenance.d.ts +30 -30
- package/dist/FunctionProvenance.d.ts.map +1 -1
- package/dist/FunctionProvenance.js.map +1 -1
- package/dist/FunctionSpec.d.ts +14 -14
- package/dist/FunctionSpec.d.ts.map +1 -1
- package/dist/FunctionSpec.js.map +1 -1
- package/dist/GenericId.d.ts +2 -2
- package/dist/GenericId.d.ts.map +1 -1
- package/dist/GenericId.js +4 -3
- package/dist/GenericId.js.map +1 -1
- package/dist/PaginationResult.d.ts +6 -10
- package/dist/PaginationResult.d.ts.map +1 -1
- package/dist/PaginationResult.js +6 -2
- package/dist/PaginationResult.js.map +1 -1
- package/dist/Ref.d.ts +5 -5
- package/dist/Ref.d.ts.map +1 -1
- package/dist/Ref.js +10 -10
- package/dist/Ref.js.map +1 -1
- package/dist/Refs.js +1 -1
- package/dist/Registry.d.ts +1 -4
- package/dist/Registry.d.ts.map +1 -1
- package/dist/Registry.js +1 -1
- package/dist/Registry.js.map +1 -1
- package/dist/SystemFields.d.ts +51 -10
- package/dist/SystemFields.d.ts.map +1 -1
- package/dist/SystemFields.js +79 -2
- package/dist/SystemFields.js.map +1 -1
- package/dist/UserIdentity.d.ts +20 -54
- package/dist/UserIdentity.d.ts.map +1 -1
- package/dist/UserIdentity.js +17 -17
- package/dist/UserIdentity.js.map +1 -1
- package/dist/tsconfig.src.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/src/FunctionProvenance.ts +12 -12
- package/src/FunctionSpec.ts +9 -9
- package/src/GenericId.ts +7 -7
- package/src/PaginationResult.ts +5 -8
- package/src/Ref.ts +21 -16
- package/src/Registry.ts +3 -3
- package/src/SystemFields.ts +255 -26
- package/src/UserIdentity.ts +17 -17
package/dist/Ref.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
|
+
import * as Option from "effect/Option";
|
|
2
3
|
import * as Schema from "effect/Schema";
|
|
3
4
|
import { makeFunctionReference } from "convex/server";
|
|
4
5
|
import { ConvexError } from "convex/values";
|
|
5
6
|
import * as Effect from "effect/Effect";
|
|
6
7
|
import * as Match from "effect/Match";
|
|
7
|
-
import * as Option from "effect/Option";
|
|
8
8
|
|
|
9
9
|
//#region src/Ref.ts
|
|
10
10
|
var Ref_exports = /* @__PURE__ */ __exportAll({
|
|
@@ -40,12 +40,12 @@ const getFunctionReference = (ref) => {
|
|
|
40
40
|
return functionReference;
|
|
41
41
|
};
|
|
42
42
|
const hasErrorSchema = (ref) => Match.value(ref.functionSpec.functionProvenance).pipe(Match.tag("Confect", (confectFunctionProvenance) => "error" in confectFunctionProvenance), Match.tag("Convex", () => false), Match.exhaustive);
|
|
43
|
-
const encodeArgs = (ref, args) => Match.value(ref.functionSpec.functionProvenance).pipe(Match.tag("Confect", (confectFunctionProvenance) => Schema.
|
|
44
|
-
const decodeReturns = (ref, returns) => Match.value(ref.functionSpec.functionProvenance).pipe(Match.tag("Confect", (confectFunctionProvenance) => Schema.
|
|
43
|
+
const encodeArgs = (ref, args) => Match.value(ref.functionSpec.functionProvenance).pipe(Match.tag("Confect", (confectFunctionProvenance) => Schema.encodeEffect(confectFunctionProvenance.args)(args)), Match.tag("Convex", () => Effect.succeed(args)), Match.exhaustive);
|
|
44
|
+
const decodeReturns = (ref, returns) => Match.value(ref.functionSpec.functionProvenance).pipe(Match.tag("Confect", (confectFunctionProvenance) => Schema.decodeUnknownEffect(confectFunctionProvenance.returns)(returns)), Match.tag("Convex", () => Effect.succeed(returns)), Match.exhaustive);
|
|
45
45
|
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);
|
|
46
|
-
const decodeArgsSync = (ref, encodedArgs) => Match.value(ref.functionSpec.functionProvenance).pipe(Match.tag("Confect", (confectFunctionProvenance) => Schema.
|
|
46
|
+
const decodeArgsSync = (ref, encodedArgs) => Match.value(ref.functionSpec.functionProvenance).pipe(Match.tag("Confect", (confectFunctionProvenance) => Schema.decodeUnknownSync(confectFunctionProvenance.args)(encodedArgs)), Match.tag("Convex", () => encodedArgs), Match.exhaustive);
|
|
47
47
|
const encodeReturnsSync = (ref, returns) => Match.value(ref.functionSpec.functionProvenance).pipe(Match.tag("Confect", (confectFunctionProvenance) => Schema.encodeSync(confectFunctionProvenance.returns)(returns)), Match.tag("Convex", () => returns), Match.exhaustive);
|
|
48
|
-
const decodeReturnsSync = (ref, encodedReturns) => Match.value(ref.functionSpec.functionProvenance).pipe(Match.tag("Confect", (confectFunctionProvenance) => Schema.
|
|
48
|
+
const decodeReturnsSync = (ref, encodedReturns) => Match.value(ref.functionSpec.functionProvenance).pipe(Match.tag("Confect", (confectFunctionProvenance) => Schema.decodeUnknownSync(confectFunctionProvenance.returns)(encodedReturns)), Match.tag("Convex", () => encodedReturns), Match.exhaustive);
|
|
49
49
|
const ConvexErrorIdentifier = Symbol.for("ConvexError");
|
|
50
50
|
const isConvexError = (error) => error instanceof ConvexError || typeof error === "object" && error !== null && ConvexErrorIdentifier in error;
|
|
51
51
|
/**
|
|
@@ -71,13 +71,13 @@ const decodeErrorOrElse = (ref, mapUnknownError) => (error) => {
|
|
|
71
71
|
* into, and the caller is responsible for deciding what to do (typically:
|
|
72
72
|
* surface the original value as a defect).
|
|
73
73
|
*/
|
|
74
|
-
const decodeError = (ref, encodedError) => Match.value(ref.functionSpec.functionProvenance).pipe(Match.tag("Confect", (confectFunctionProvenance) => "error" in confectFunctionProvenance ? Effect.map(Schema.
|
|
74
|
+
const decodeError = (ref, encodedError) => Match.value(ref.functionSpec.functionProvenance).pipe(Match.tag("Confect", (confectFunctionProvenance) => "error" in confectFunctionProvenance ? Effect.map(Schema.decodeUnknownEffect(confectFunctionProvenance.error)(encodedError), Option.some) : Effect.succeed(Option.none())), Match.tag("Convex", () => Effect.succeed(Option.none())), Match.exhaustive);
|
|
75
75
|
/**
|
|
76
76
|
* Synchronous counterpart to `decodeError`. Throws on schema decode failure;
|
|
77
77
|
* returns `None` when the ref doesn't declare a typed error.
|
|
78
78
|
*/
|
|
79
|
-
const decodeErrorSync = (ref, encodedError) => Match.value(ref.functionSpec.functionProvenance).pipe(Match.tag("Confect", (confectFunctionProvenance) => "error" in confectFunctionProvenance ? Option.some(Schema.
|
|
80
|
-
const maybeDecodeErrorSync = (ref, error) => isConvexError(error) ? Match.value(ref.functionSpec.functionProvenance).pipe(Match.tag("Confect", (confectFunctionProvenance) => "error" in confectFunctionProvenance ? Schema.
|
|
79
|
+
const decodeErrorSync = (ref, encodedError) => Match.value(ref.functionSpec.functionProvenance).pipe(Match.tag("Confect", (confectFunctionProvenance) => "error" in confectFunctionProvenance ? Option.some(Schema.decodeUnknownSync(confectFunctionProvenance.error)(encodedError)) : Option.none()), Match.tag("Convex", () => Option.none()), Match.exhaustive);
|
|
80
|
+
const maybeDecodeErrorSync = (ref, error) => isConvexError(error) ? Match.value(ref.functionSpec.functionProvenance).pipe(Match.tag("Confect", (confectFunctionProvenance) => "error" in confectFunctionProvenance ? Schema.decodeUnknownSync(confectFunctionProvenance.error)(error.data) : error), Match.tag("Convex", () => error), Match.exhaustive) : error;
|
|
81
81
|
/**
|
|
82
82
|
* Encode args via the ref's args schema, invoke `call`, decode returns via the
|
|
83
83
|
* ref's returns schema, and translate any thrown `ConvexError` into the ref's
|
|
@@ -101,8 +101,8 @@ const runWithCodec = (ref, args, call, mapUnknownError) => Effect.gen(function*
|
|
|
101
101
|
}
|
|
102
102
|
});
|
|
103
103
|
return yield* Match.value(functionProvenance).pipe(Match.tag("Confect", (confectFunctionProvenance) => Effect.gen(function* () {
|
|
104
|
-
const encodedReturns = yield* invoke(yield* Schema.
|
|
105
|
-
return yield* Schema.
|
|
104
|
+
const encodedReturns = yield* invoke(yield* Schema.encodeEffect(confectFunctionProvenance.args)(args));
|
|
105
|
+
return yield* Schema.decodeUnknownEffect(confectFunctionProvenance.returns)(encodedReturns);
|
|
106
106
|
})), Match.tag("Convex", () => invoke(args)), Match.exhaustive);
|
|
107
107
|
});
|
|
108
108
|
|
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 * as Effect from \"effect/Effect\";\nimport * as Match from \"effect/Match\";\nimport * as Option from \"effect/Option\";\nimport * as Schema from \"effect/Schema\";\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\nconst functionReferenceCache = new Map<string, FunctionReference<Any>>();\n\nexport const getFunctionReference = <Ref_ extends Any>(\n ref: Ref_,\n): FunctionReference<Ref_> => {\n const functionName = getConvexFunctionName(ref);\n\n const cached = functionReferenceCache.get(functionName);\n if (cached !== undefined) {\n return cached as FunctionReference<Ref_>;\n }\n\n const functionReference = makeFunctionReference(functionName);\n functionReferenceCache.set(functionName, functionReference);\n\n return functionReference as FunctionReference<Ref_>;\n};\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 decodeArgsSync = <Ref_ extends Any>(\n ref: Ref_,\n encodedArgs: unknown,\n): Args<Ref_> =>\n Match.value(ref.functionSpec.functionProvenance).pipe(\n Match.tag(\"Confect\", (confectFunctionProvenance) =>\n Schema.decodeSync(confectFunctionProvenance.args)(encodedArgs),\n ),\n Match.tag(\"Convex\", () => encodedArgs),\n Match.exhaustive,\n ) as Args<Ref_>;\n\nexport const encodeReturnsSync = <Ref_ extends Any>(\n ref: Ref_,\n returns: Returns<Ref_>,\n): unknown =>\n Match.value(ref.functionSpec.functionProvenance).pipe(\n Match.tag(\"Confect\", (confectFunctionProvenance) =>\n Schema.encodeSync(confectFunctionProvenance.returns)(returns),\n ),\n Match.tag(\"Convex\", () => returns),\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAsLA,MAAa,QAMX,mBACA,kBACqC;CAAE;CAAc;CAAmB;AAE1E,MAAa,yBAAyB,QACpC,GAAG,IAAI,kBAAkB,GAAG,IAAI,aAAa;AAE/C,MAAM,yCAAyB,IAAI,KAAqC;AAExE,MAAa,wBACX,QAC4B;CAC5B,MAAM,eAAe,sBAAsB,IAAI;CAE/C,MAAM,SAAS,uBAAuB,IAAI,aAAa;AACvD,KAAI,WAAW,OACb,QAAO;CAGT,MAAM,oBAAoB,sBAAsB,aAAa;AAC7D,wBAAuB,IAAI,cAAc,kBAAkB;AAE3D,QAAO;;AAGT,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,0BAA0B,KAAK,CAAC,KAAK,CACpD,EACD,MAAM,IAAI,gBAAgB,OA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UAAU,gBAAgB,KAAK,MAAM,KAAK;AAChD,QAAI,OAAO,OAAO,QAAQ,CACxB,QAAO,QAAQ;;AAGnB,OAAI,oBAAoB,OACtB,QAAO,gBAAgB,MAAM;AAE/B,SAAM;;EAET,CAAC;AACJ,QAAO,OAAO,MAAM,MAAM,mBAAmB,CAAC,KAC5C,MAAM,IAAI,YAAY,8BACpB,OAAO,IAAI,aAAa;EAItB,MAAM,iBAAiB,OAAO,OAHV,OAAO,OAAO,OAChC,0BAA0B,KAC3B,CAAC,KAAK,CAC0C;AACjD,SAAO,OAAO,OAAO,OAAO,0BAA0B,QAAQ,CAC5D,eACD;GACD,CACH,EACD,MAAM,IAAI,gBAAgB,OAAO,KAAK,CAAC,EACvC,MAAM,WACP;EACD"}
|
|
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 * as Effect from \"effect/Effect\";\nimport * as Match from \"effect/Match\";\nimport * as Option from \"effect/Option\";\nimport * as Schema from \"effect/Schema\";\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\nconst functionReferenceCache = new Map<string, FunctionReference<Any>>();\n\nexport const getFunctionReference = <Ref_ extends Any>(\n ref: Ref_,\n): FunctionReference<Ref_> => {\n const functionName = getConvexFunctionName(ref);\n\n const cached = functionReferenceCache.get(functionName);\n if (cached !== undefined) {\n return cached as FunctionReference<Ref_>;\n }\n\n const functionReference = makeFunctionReference(functionName);\n functionReferenceCache.set(functionName, functionReference);\n\n return functionReference as FunctionReference<Ref_>;\n};\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, Schema.SchemaError> =>\n Match.value(ref.functionSpec.functionProvenance).pipe(\n Match.tag(\"Confect\", (confectFunctionProvenance) =>\n Schema.encodeEffect(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_>, Schema.SchemaError> =>\n Match.value(ref.functionSpec.functionProvenance).pipe(\n Match.tag(\"Confect\", (confectFunctionProvenance) =>\n Schema.decodeUnknownEffect(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 decodeArgsSync = <Ref_ extends Any>(\n ref: Ref_,\n encodedArgs: unknown,\n): Args<Ref_> =>\n Match.value(ref.functionSpec.functionProvenance).pipe(\n Match.tag(\"Confect\", (confectFunctionProvenance) =>\n Schema.decodeUnknownSync(confectFunctionProvenance.args)(encodedArgs),\n ),\n Match.tag(\"Convex\", () => encodedArgs),\n Match.exhaustive,\n ) as Args<Ref_>;\n\nexport const encodeReturnsSync = <Ref_ extends Any>(\n ref: Ref_,\n returns: Returns<Ref_>,\n): unknown =>\n Match.value(ref.functionSpec.functionProvenance).pipe(\n Match.tag(\"Confect\", (confectFunctionProvenance) =>\n Schema.encodeSync(confectFunctionProvenance.returns)(returns),\n ),\n Match.tag(\"Convex\", () => returns),\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.decodeUnknownSync(confectFunctionProvenance.returns)(\n encodedReturns,\n ),\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_>>, Schema.SchemaError> =>\n Match.value(ref.functionSpec.functionProvenance).pipe(\n Match.tag(\"Confect\", (confectFunctionProvenance) =>\n \"error\" in confectFunctionProvenance\n ? Effect.map(\n Schema.decodeUnknownEffect(confectFunctionProvenance.error)(\n encodedError,\n ),\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.decodeUnknownSync(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.decodeUnknownSync(confectFunctionProvenance.error)(\n error.data,\n )\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_> | Schema.SchemaError> =>\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.encodeEffect(\n confectFunctionProvenance.args,\n )(args);\n const encodedReturns = yield* invoke(encodedArgs);\n return yield* Schema.decodeUnknownEffect(\n confectFunctionProvenance.returns,\n )(encodedReturns);\n }),\n ),\n Match.tag(\"Convex\", () => invoke(args)),\n Match.exhaustive,\n );\n });\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAqLA,MAAa,QAMX,mBACA,kBACqC;CAAE;CAAc;CAAmB;AAE1E,MAAa,yBAAyB,QACpC,GAAG,IAAI,kBAAkB,GAAG,IAAI,aAAa;AAE/C,MAAM,yCAAyB,IAAI,KAAqC;AAExE,MAAa,wBACX,QAC4B;CAC5B,MAAM,eAAe,sBAAsB,IAAI;CAE/C,MAAM,SAAS,uBAAuB,IAAI,aAAa;AACvD,KAAI,WAAW,OACb,QAAO;CAGT,MAAM,oBAAoB,sBAAsB,aAAa;AAC7D,wBAAuB,IAAI,cAAc,kBAAkB;AAE3D,QAAO;;AAGT,MAAa,kBAAkB,QAC7B,MAAM,MAAM,IAAI,a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;;;;;;;AAUN,MAAa,gBACX,KACA,MACA,MAIA,oBAEA,OAAO,IAAI,aAAa;CACtB,MAAM,oBAAoB,qBAAqB,IAAI;CACnD,MAAM,qBAAqB,IAAI,aAAa;CAC5C,MAAM,UACJ,gBAEA,OAAO,WAAW;EAChB,WAAW,QAAQ,QAAQ,KAAK,mBAAmB,YAAY,CAAC;EAChE,QAAQ,UAA2B;AACjC,OAAI,cAAc,MAAM,EAAE;IACxB,MAAM,UAAU,gBAAgB,KAAK,MAAM,KAAK;AAChD,QAAI,OAAO,OAAO,QAAQ,CACxB,QAAO,QAAQ;;AAGnB,OAAI,oBAAoB,OACtB,QAAO,gBAAgB,MAAM;AAE/B,SAAM;;EAET,CAAC;AACJ,QAAO,OAAO,MAAM,MAAM,mBAAmB,CAAC,KAC5C,MAAM,IAAI,YAAY,8BACpB,OAAO,IAAI,aAAa;EAItB,MAAM,iBAAiB,OAAO,OAHV,OAAO,OAAO,aAChC,0BAA0B,KAC3B,CAAC,KAAK,CAC0C;AACjD,SAAO,OAAO,OAAO,oBACnB,0BAA0B,QAC3B,CAAC,eAAe;GACjB,CACH,EACD,MAAM,IAAI,gBAAgB,OAAO,KAAK,CAAC,EACvC,MAAM,WACP;EACD"}
|
package/dist/Refs.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
2
|
import { getConvexFunctionName, make as make$1 } from "./Ref.js";
|
|
3
|
-
import * as Record from "effect/Record";
|
|
4
3
|
import * as Option from "effect/Option";
|
|
4
|
+
import * as Record from "effect/Record";
|
|
5
5
|
import { pipe } from "effect/Function";
|
|
6
6
|
|
|
7
7
|
//#region src/Refs.ts
|
package/dist/Registry.d.ts
CHANGED
|
@@ -11,7 +11,6 @@ import * as Ref from "effect/Ref";
|
|
|
11
11
|
export interface RegistryItems {
|
|
12
12
|
readonly [key: string]: unknown | RegistryItems;
|
|
13
13
|
}
|
|
14
|
-
declare const Registry_base: Context.ReferenceClass<Registry, "@confect/core/Registry", Ref.Ref<RegistryItems>>;
|
|
15
14
|
/**
|
|
16
15
|
* Effect `Context.Reference` keyed by `@confect/core/Registry`. Lives in
|
|
17
16
|
* `@confect/core` so `@confect/server` (which writes to it from
|
|
@@ -21,7 +20,5 @@ declare const Registry_base: Context.ReferenceClass<Registry, "@confect/core/Reg
|
|
|
21
20
|
* Effect's global default-value cache to align two separately-defined tags
|
|
22
21
|
* by string key.
|
|
23
22
|
*/
|
|
24
|
-
export declare
|
|
25
|
-
}
|
|
26
|
-
export {};
|
|
23
|
+
export declare const Registry: Context.Reference<Ref.Ref<RegistryItems>>;
|
|
27
24
|
//# sourceMappingURL=Registry.d.ts.map
|
package/dist/Registry.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Registry.d.ts","sourceRoot":"","sources":["../src/Registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,GAAG,MAAM,YAAY,CAAC;AAElC;;;;;;;GAOG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,GAAG,aAAa,CAAC;CACjD
|
|
1
|
+
{"version":3,"file":"Registry.d.ts","sourceRoot":"","sources":["../src/Registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,GAAG,MAAM,YAAY,CAAC;AAElC;;;;;;;GAOG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,GAAG,aAAa,CAAC;CACjD;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,QAAQ,2CAKpB,CAAC"}
|
package/dist/Registry.js
CHANGED
|
@@ -13,7 +13,7 @@ var Registry_exports = /* @__PURE__ */ __exportAll({ Registry: () => Registry })
|
|
|
13
13
|
* Effect's global default-value cache to align two separately-defined tags
|
|
14
14
|
* by string key.
|
|
15
15
|
*/
|
|
16
|
-
|
|
16
|
+
const Registry = Context.Reference("@confect/core/Registry", { defaultValue: () => Ref.makeUnsafe({}) });
|
|
17
17
|
|
|
18
18
|
//#endregion
|
|
19
19
|
export { Registry, Registry_exports };
|
package/dist/Registry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Registry.js","names":[],"sources":["../src/Registry.ts"],"sourcesContent":["import * as Context from \"effect/Context\";\nimport * as Ref from \"effect/Ref\";\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
|
|
1
|
+
{"version":3,"file":"Registry.js","names":[],"sources":["../src/Registry.ts"],"sourcesContent":["import * as Context from \"effect/Context\";\nimport * as Ref from \"effect/Ref\";\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 const Registry = Context.Reference<Ref.Ref<RegistryItems>>(\n \"@confect/core/Registry\",\n {\n defaultValue: () => Ref.makeUnsafe<RegistryItems>({}),\n },\n);\n"],"mappings":";;;;;;;;;;;;;;;AAwBA,MAAa,WAAW,QAAQ,UAC9B,0BACA,EACE,oBAAoB,IAAI,WAA0B,EAAE,CAAC,EACtD,CACF"}
|
package/dist/SystemFields.d.ts
CHANGED
|
@@ -1,22 +1,63 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { IdField, SystemFields as NonIdSystemFields } from "convex/server";
|
|
2
2
|
import * as Schema from "effect/Schema";
|
|
3
|
-
import * as
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
import * as Struct from "effect/Struct";
|
|
4
|
+
/**
|
|
5
|
+
* Produces a schema for Convex system fields. In Confect, system fields include `_id`.
|
|
6
|
+
*/
|
|
7
|
+
export declare const SystemFields: <TableName extends string>(tableName: TableName) => Schema.Struct<{
|
|
8
|
+
readonly _id: Schema.Codec<import("convex/values").GenericId<TableName>, import("convex/values").GenericId<TableName>, never, never>;
|
|
9
|
+
readonly _creationTime: Schema.Number;
|
|
7
10
|
}>;
|
|
8
11
|
/**
|
|
9
|
-
*
|
|
12
|
+
* The field map added to a table schema, derived from {@link SystemFields} so it
|
|
13
|
+
* stays in lockstep with the runtime schema.
|
|
10
14
|
*/
|
|
11
|
-
|
|
15
|
+
type SystemFieldsFor<TableName extends string> = ReturnType<typeof SystemFields<TableName>>["fields"];
|
|
12
16
|
/**
|
|
13
17
|
* Extend a table schema with Convex system fields.
|
|
18
|
+
*
|
|
19
|
+
* A plain `Struct` gains the fields via `Schema.fieldsAssign` and a `Union`
|
|
20
|
+
* has them distributed across its members, preserving the schema's
|
|
21
|
+
* `Struct`/`Union` structure. Any other object-shaped schema — one built with
|
|
22
|
+
* `Schema.decodeTo`/`Schema.encodeKeys`, a branded struct, a suspended schema
|
|
23
|
+
* — is extended at the AST level: every object node in its encoding chain
|
|
24
|
+
* gains the system fields, and each transformation is wrapped so the fields
|
|
25
|
+
* bypass the user-defined getters. Schemas that do not resolve to an object
|
|
26
|
+
* shape at every step (such as `Schema.Class`, whose decoded values are class
|
|
27
|
+
* instances) are rejected with a descriptive error.
|
|
28
|
+
*
|
|
29
|
+
* Note that struct-level checks on an extended schema observe the value with
|
|
30
|
+
* the system fields attached, and encoding an extended schema emits the system
|
|
31
|
+
* fields alongside the table fields.
|
|
32
|
+
*/
|
|
33
|
+
export declare const extendWithSystemFields: <TableName extends string, TableSchema extends Schema.Codec<any, any>>(tableName: TableName, schema: TableSchema) => ExtendWithSystemFields<TableName, TableSchema>;
|
|
34
|
+
/**
|
|
35
|
+
* Applies the system fields to a single struct, mirroring `Schema.fieldsAssign`.
|
|
36
|
+
* Any other (already-extended or opaque) schema falls back to a `Codec` carrying
|
|
37
|
+
* the system-field document shape.
|
|
14
38
|
*/
|
|
15
|
-
|
|
39
|
+
type ApplySystemFields<TableName extends string, S> = S extends Schema.Struct<infer Fields extends Schema.Struct.Fields> ? Schema.Struct<Struct.Simplify<Struct.Assign<Fields, SystemFieldsFor<TableName>>>> : S extends Schema.Codec<infer Type, infer Encoded> ? Schema.Codec<WithSystemFields<TableName, Type>, WithSystemFields<TableName, Encoded>> : never;
|
|
16
40
|
/**
|
|
17
41
|
* Extend a table schema with Convex system fields at the type level.
|
|
42
|
+
*
|
|
43
|
+
* This mirrors the runtime {@link extendWithSystemFields}: a `Struct` gains the
|
|
44
|
+
* system fields directly (matching `Schema.fieldsAssign`), and a `Union` has
|
|
45
|
+
* them distributed across its members (matching
|
|
46
|
+
* `union.mapMembers(Tuple.map(Schema.fieldsAssign(...)))`). The `Struct`/`Union`
|
|
47
|
+
* structure is preserved rather than collapsed to a bare `Codec`; any other
|
|
48
|
+
* schema falls back to a `Codec` carrying the system-field document shape,
|
|
49
|
+
* matching the runtime's AST-level extension.
|
|
50
|
+
*/
|
|
51
|
+
export type ExtendWithSystemFields<TableName extends string, TableSchema extends Schema.Top> = TableSchema extends Schema.Union<infer Members extends ReadonlyArray<Schema.Top>> ? Schema.Union<Struct.Simplify<Readonly<{
|
|
52
|
+
[K in keyof Members]: ExtendWithSystemFields<TableName, Members[K]>;
|
|
53
|
+
}>>> : ApplySystemFields<TableName, TableSchema>;
|
|
54
|
+
/**
|
|
55
|
+
* The decoded/encoded document shape: a table's fields plus Convex's system
|
|
56
|
+
* fields. Deliberately a bare intersection (no `Expand`/`Simplify`) — flattening
|
|
57
|
+
* it with a homomorphic mapped type collapses to `{ [x: string]: any }` when
|
|
58
|
+
* `Document` is still an unresolved generic, which breaks structural
|
|
59
|
+
* comparability in the database reader/writer plumbing.
|
|
18
60
|
*/
|
|
19
|
-
export type
|
|
20
|
-
export type WithSystemFields<TableName extends string, Document> = Expand<Readonly<IdField<TableName>> & Readonly<NonIdSystemFields> & Document>;
|
|
61
|
+
export type WithSystemFields<TableName extends string, Document> = Document extends unknown ? IdField<TableName> & NonIdSystemFields & Document : never;
|
|
21
62
|
export {};
|
|
22
63
|
//# sourceMappingURL=SystemFields.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SystemFields.d.ts","sourceRoot":"","sources":["../src/SystemFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"SystemFields.d.ts","sourceRoot":"","sources":["../src/SystemFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,IAAI,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAOhF,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAIxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAGxC;;GAEG;AACH,eAAO,MAAM,YAAY,GAAI,SAAS,SAAS,MAAM,EA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G,sBAAsB,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;CACpE,CAAC,CACH,CACF,GACD,iBAAiB,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;AAEhD;;;;;;GAMG;AACH,MAAM,MAAM,gBAAgB,CAC1B,SAAS,SAAS,MAAM,EACxB,QAAQ,IACN,QAAQ,SAAS,OAAO,GACxB,OAAO,CAAC,SAAS,CAAC,GAAG,iBAAiB,GAAG,QAAQ,GACjD,KAAK,CAAC"}
|
package/dist/SystemFields.js
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
2
|
import { GenericId } from "./GenericId.js";
|
|
3
|
+
import * as Predicate from "effect/Predicate";
|
|
4
|
+
import * as Option from "effect/Option";
|
|
3
5
|
import * as Schema from "effect/Schema";
|
|
6
|
+
import * as SchemaAST from "effect/SchemaAST";
|
|
7
|
+
import * as Record from "effect/Record";
|
|
8
|
+
import * as Effect from "effect/Effect";
|
|
9
|
+
import { pipe } from "effect/Function";
|
|
10
|
+
import * as Array from "effect/Array";
|
|
11
|
+
import * as SchemaGetter from "effect/SchemaGetter";
|
|
12
|
+
import * as SchemaTransformation from "effect/SchemaTransformation";
|
|
13
|
+
import * as Struct from "effect/Struct";
|
|
4
14
|
|
|
5
15
|
//#region src/SystemFields.ts
|
|
6
16
|
var SystemFields_exports = /* @__PURE__ */ __exportAll({
|
|
@@ -8,16 +18,83 @@ var SystemFields_exports = /* @__PURE__ */ __exportAll({
|
|
|
8
18
|
extendWithSystemFields: () => extendWithSystemFields
|
|
9
19
|
});
|
|
10
20
|
/**
|
|
11
|
-
* Produces a schema for Convex system fields.
|
|
21
|
+
* Produces a schema for Convex system fields. In Confect, system fields include `_id`.
|
|
12
22
|
*/
|
|
13
23
|
const SystemFields = (tableName) => Schema.Struct({
|
|
14
24
|
_id: GenericId(tableName),
|
|
15
25
|
_creationTime: Schema.Number
|
|
16
26
|
});
|
|
17
27
|
/**
|
|
28
|
+
* The system field names, derived from {@link SystemFields} so they stay in
|
|
29
|
+
* lockstep with the schema.
|
|
30
|
+
*/
|
|
31
|
+
const systemFieldNames = Record.keys(SystemFields("").fields);
|
|
32
|
+
const isSystemFieldKey = (key) => Predicate.isString(key) && Array.contains(systemFieldNames, key);
|
|
33
|
+
const splitSystemFields = (input) => {
|
|
34
|
+
const keys = Reflect.ownKeys(input);
|
|
35
|
+
const pick = (pickedKeys) => Record.fromEntries(Array.map(pickedKeys, (key) => [key, input[key]]));
|
|
36
|
+
return {
|
|
37
|
+
system: pick(Array.filter(keys, isSystemFieldKey)),
|
|
38
|
+
rest: pick(Array.filter(keys, Predicate.not(isSystemFieldKey)))
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Wraps a transformation getter so the system fields bypass it: they are split
|
|
43
|
+
* off the input before the user-defined getter runs and merged back into its
|
|
44
|
+
* output. Transformations construct fresh objects, so without this the system
|
|
45
|
+
* fields would be dropped at every transformation step.
|
|
46
|
+
*/
|
|
47
|
+
const wrapGetter = (getter) => new SchemaGetter.Getter((input, options) => {
|
|
48
|
+
if (Option.isNone(input) || !Predicate.isObject(input.value)) return getter.run(input, options);
|
|
49
|
+
const { system, rest } = splitSystemFields(input.value);
|
|
50
|
+
return getter.run(Option.some(rest), options).pipe(Effect.map(Option.map((output) => Predicate.isObject(output) ? Struct.assign(output, system) : output)));
|
|
51
|
+
});
|
|
52
|
+
const wrapTransformation = (transformation) => {
|
|
53
|
+
if (!SchemaTransformation.isTransformation(transformation)) throw new Error("Cannot extend a table schema that uses decoding/encoding middleware with system fields");
|
|
54
|
+
return new SchemaTransformation.Transformation(wrapGetter(transformation.decode), wrapGetter(transformation.encode));
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Builds an AST walker that adds the given system-field property signatures to
|
|
58
|
+
* every object node of a schema's AST — including each step of its encoding
|
|
59
|
+
* chain — wrapping transformations so the fields survive them.
|
|
60
|
+
*/
|
|
61
|
+
const makeExtendAst = (systemPropertySignatures) => {
|
|
62
|
+
const extendEncoding = (encoding) => Array.map(encoding, (link) => new SchemaAST.Link(extendAst(link.to), wrapTransformation(link.transformation)));
|
|
63
|
+
const extendAst = (ast) => {
|
|
64
|
+
if (SchemaAST.isUnion(ast)) return new SchemaAST.Union(Array.map(ast.types, extendAst), ast.mode, ast.annotations, ast.checks, ast.encoding === void 0 ? void 0 : extendEncoding(ast.encoding), ast.context, ast.encodingChecks);
|
|
65
|
+
if (SchemaAST.isSuspend(ast)) return new SchemaAST.Suspend(() => extendAst(ast.thunk()), ast.annotations, void 0, ast.encoding === void 0 ? void 0 : extendEncoding(ast.encoding), ast.context);
|
|
66
|
+
if (SchemaAST.isObjects(ast)) return new SchemaAST.Objects(Array.appendAll(ast.propertySignatures, systemPropertySignatures), ast.indexSignatures, ast.annotations, ast.checks, ast.encoding === void 0 ? void 0 : extendEncoding(ast.encoding), ast.context, ast.encodingChecks);
|
|
67
|
+
throw new Error(ast._tag === "Declaration" ? "Cannot extend a `Declaration` schema (such as a `Schema.Class`) with system fields: its decoded values are constructed instances, which cannot gain extra fields. Use a plain `Schema.Struct`, or transform to one with `Schema.decodeTo`." : `Cannot extend a \`${ast._tag}\` schema node with system fields: a table schema must resolve to an object shape at every step of its encoding.`);
|
|
68
|
+
};
|
|
69
|
+
return extendAst;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
18
72
|
* Extend a table schema with Convex system fields.
|
|
73
|
+
*
|
|
74
|
+
* A plain `Struct` gains the fields via `Schema.fieldsAssign` and a `Union`
|
|
75
|
+
* has them distributed across its members, preserving the schema's
|
|
76
|
+
* `Struct`/`Union` structure. Any other object-shaped schema — one built with
|
|
77
|
+
* `Schema.decodeTo`/`Schema.encodeKeys`, a branded struct, a suspended schema
|
|
78
|
+
* — is extended at the AST level: every object node in its encoding chain
|
|
79
|
+
* gains the system fields, and each transformation is wrapped so the fields
|
|
80
|
+
* bypass the user-defined getters. Schemas that do not resolve to an object
|
|
81
|
+
* shape at every step (such as `Schema.Class`, whose decoded values are class
|
|
82
|
+
* instances) are rejected with a descriptive error.
|
|
83
|
+
*
|
|
84
|
+
* Note that struct-level checks on an extended schema observe the value with
|
|
85
|
+
* the system fields attached, and encoding an extended schema emits the system
|
|
86
|
+
* fields alongside the table fields.
|
|
19
87
|
*/
|
|
20
|
-
const extendWithSystemFields = (tableName, schema) =>
|
|
88
|
+
const extendWithSystemFields = (tableName, schema) => {
|
|
89
|
+
const system = SystemFields(tableName).fields;
|
|
90
|
+
const extendAst = makeExtendAst(pipe(system, Record.toEntries, Array.map(([name, field]) => new SchemaAST.PropertySignature(name, field.ast))));
|
|
91
|
+
const extend = (s) => {
|
|
92
|
+
if (s.ast.encoding === void 0 && SchemaAST.isUnion(s.ast) && Array.isArray(s.members)) return Schema.Union(Array.map(s.members, extend));
|
|
93
|
+
if (s.ast.encoding === void 0 && SchemaAST.isObjects(s.ast) && typeof s.mapFields === "function") return Schema.fieldsAssign(system)(s);
|
|
94
|
+
return Schema.make(extendAst(s.ast));
|
|
95
|
+
};
|
|
96
|
+
return extend(schema);
|
|
97
|
+
};
|
|
21
98
|
|
|
22
99
|
//#endregion
|
|
23
100
|
export { SystemFields, SystemFields_exports, extendWithSystemFields };
|
package/dist/SystemFields.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SystemFields.js","names":["GenericId.GenericId"],"sources":["../src/SystemFields.ts"],"sourcesContent":["import type {\n Expand,\n IdField,\n SystemFields as NonIdSystemFields,\n} from \"convex/server\";\nimport * as Schema from \"effect/Schema\";\nimport * as GenericId from \"./GenericId\";\n\ntype SystemFieldsSchema<TableName extends string> = Schema.Struct<{\n _id: Schema.Schema<\n GenericId.GenericId<TableName>,\n GenericId.GenericId<TableName>,\n never\n >;\n _creationTime: typeof Schema.Number;\n}>;\n\n/**\n * Produces a schema for Convex system fields.\n */\nexport const SystemFields = <TableName extends string>(\n tableName: TableName,\n): SystemFieldsSchema<TableName> =>\n Schema.Struct({\n _id: GenericId.GenericId(tableName),\n _creationTime: Schema.Number,\n });\n\n/**\n * Extend a table schema with Convex system fields.\n */\nexport const extendWithSystemFields = <\n TableName extends string,\n TableSchema extends Schema.Schema.AnyNoContext,\n>(\n tableName: TableName,\n schema: TableSchema,\n): ExtendWithSystemFields<TableName, TableSchema> =>\n Schema.extend(SystemFields(tableName), schema);\n\n/**\n * Extend a table schema with Convex system fields at the type level.\n */\nexport type ExtendWithSystemFields<\n TableName extends string,\n TableSchema extends Schema.Schema.AnyNoContext,\n> = Schema.extend<SystemFieldsSchema<TableName>, TableSchema>;\n\nexport type WithSystemFields<TableName extends string, Document> = Expand<\n Readonly<IdField<TableName>> & Readonly<NonIdSystemFields> & Document\n>;\n"],"mappings":";;;;;;;;;;;;AAoBA,MAAa,gBACX,cAEA,OAAO,OAAO;CACZ,KAAKA,UAAoB,UAAU;CACnC,eAAe,OAAO;CACvB,CAAC;;;;AAKJ,MAAa,0BAIX,WACA,WAEA,OAAO,OAAO,aAAa,UAAU,EAAE,OAAO"}
|
|
1
|
+
{"version":3,"file":"SystemFields.js","names":["GenericId.GenericId"],"sources":["../src/SystemFields.ts"],"sourcesContent":["import type { IdField, SystemFields as NonIdSystemFields } from \"convex/server\";\nimport { pipe } from \"effect/Function\";\nimport * as Array from \"effect/Array\";\nimport * as Effect from \"effect/Effect\";\nimport * as Option from \"effect/Option\";\nimport * as Predicate from \"effect/Predicate\";\nimport * as Record from \"effect/Record\";\nimport * as Schema from \"effect/Schema\";\nimport * as SchemaAST from \"effect/SchemaAST\";\nimport * as SchemaGetter from \"effect/SchemaGetter\";\nimport * as SchemaTransformation from \"effect/SchemaTransformation\";\nimport * as Struct from \"effect/Struct\";\nimport * as GenericId from \"./GenericId\";\n\n/**\n * Produces a schema for Convex system fields. In Confect, system fields include `_id`.\n */\nexport const SystemFields = <TableName extends string>(tableName: TableName) =>\n Schema.Struct({\n _id: GenericId.GenericId(tableName),\n _creationTime: Schema.Number,\n });\n\n/**\n * The field map added to a table schema, derived from {@link SystemFields} so it\n * stays in lockstep with the runtime schema.\n */\ntype SystemFieldsFor<TableName extends string> = ReturnType<\n typeof SystemFields<TableName>\n>[\"fields\"];\n\n/**\n * The system field names, derived from {@link SystemFields} so they stay in\n * lockstep with the schema.\n */\nconst systemFieldNames: ReadonlyArray<string> = Record.keys(\n SystemFields(\"\").fields,\n);\n\nconst isSystemFieldKey = (key: string | symbol): key is string =>\n Predicate.isString(key) && Array.contains(systemFieldNames, key);\n\nconst splitSystemFields = (input: { [key: PropertyKey]: unknown }) => {\n const keys = Reflect.ownKeys(input);\n const pick = (pickedKeys: ReadonlyArray<string | symbol>) =>\n Record.fromEntries(\n Array.map(pickedKeys, (key) => [key, input[key]] as const),\n );\n return {\n system: pick(Array.filter(keys, isSystemFieldKey)),\n rest: pick(Array.filter(keys, Predicate.not(isSystemFieldKey))),\n };\n};\n\n/**\n * Wraps a transformation getter so the system fields bypass it: they are split\n * off the input before the user-defined getter runs and merged back into its\n * output. Transformations construct fresh objects, so without this the system\n * fields would be dropped at every transformation step.\n */\nconst wrapGetter = (\n getter: SchemaGetter.Getter<any, any, any>,\n): SchemaGetter.Getter<any, any, any> =>\n new SchemaGetter.Getter((input, options) => {\n if (Option.isNone(input) || !Predicate.isObject(input.value)) {\n return getter.run(input, options);\n }\n const { system, rest } = splitSystemFields(input.value);\n return getter\n .run(Option.some(rest), options)\n .pipe(\n Effect.map(\n Option.map((output) =>\n Predicate.isObject(output) ? Struct.assign(output, system) : output,\n ),\n ),\n );\n });\n\nconst wrapTransformation = (\n transformation: SchemaAST.Link[\"transformation\"],\n): SchemaTransformation.Transformation<any, any, any, any> => {\n if (!SchemaTransformation.isTransformation(transformation)) {\n throw new Error(\n \"Cannot extend a table schema that uses decoding/encoding middleware with system fields\",\n );\n }\n return new SchemaTransformation.Transformation(\n wrapGetter(transformation.decode),\n wrapGetter(transformation.encode),\n );\n};\n\n/**\n * Builds an AST walker that adds the given system-field property signatures to\n * every object node of a schema's AST — including each step of its encoding\n * chain — wrapping transformations so the fields survive them.\n */\nconst makeExtendAst = (\n systemPropertySignatures: ReadonlyArray<SchemaAST.PropertySignature>,\n) => {\n const extendEncoding = (encoding: SchemaAST.Encoding): SchemaAST.Encoding =>\n Array.map(\n encoding,\n (link) =>\n new SchemaAST.Link(\n extendAst(link.to),\n wrapTransformation(link.transformation),\n ),\n );\n\n const extendAst = (ast: SchemaAST.AST): SchemaAST.AST => {\n if (SchemaAST.isUnion(ast)) {\n return new SchemaAST.Union(\n Array.map(ast.types, extendAst),\n ast.mode,\n ast.annotations,\n ast.checks,\n ast.encoding === undefined ? undefined : extendEncoding(ast.encoding),\n ast.context,\n ast.encodingChecks,\n );\n }\n if (SchemaAST.isSuspend(ast)) {\n return new SchemaAST.Suspend(\n () => extendAst(ast.thunk()),\n ast.annotations,\n undefined,\n ast.encoding === undefined ? undefined : extendEncoding(ast.encoding),\n ast.context,\n );\n }\n if (SchemaAST.isObjects(ast)) {\n return new SchemaAST.Objects(\n Array.appendAll(ast.propertySignatures, systemPropertySignatures),\n ast.indexSignatures,\n ast.annotations,\n ast.checks,\n ast.encoding === undefined ? undefined : extendEncoding(ast.encoding),\n ast.context,\n ast.encodingChecks,\n );\n }\n throw new Error(\n ast._tag === \"Declaration\"\n ? \"Cannot extend a `Declaration` schema (such as a `Schema.Class`) with system fields: its decoded values are constructed instances, which cannot gain extra fields. Use a plain `Schema.Struct`, or transform to one with `Schema.decodeTo`.\"\n : `Cannot extend a \\`${ast._tag}\\` schema node with system fields: a table schema must resolve to an object shape at every step of its encoding.`,\n );\n };\n\n return extendAst;\n};\n\n/**\n * Extend a table schema with Convex system fields.\n *\n * A plain `Struct` gains the fields via `Schema.fieldsAssign` and a `Union`\n * has them distributed across its members, preserving the schema's\n * `Struct`/`Union` structure. Any other object-shaped schema — one built with\n * `Schema.decodeTo`/`Schema.encodeKeys`, a branded struct, a suspended schema\n * — is extended at the AST level: every object node in its encoding chain\n * gains the system fields, and each transformation is wrapped so the fields\n * bypass the user-defined getters. Schemas that do not resolve to an object\n * shape at every step (such as `Schema.Class`, whose decoded values are class\n * instances) are rejected with a descriptive error.\n *\n * Note that struct-level checks on an extended schema observe the value with\n * the system fields attached, and encoding an extended schema emits the system\n * fields alongside the table fields.\n */\nexport const extendWithSystemFields = <\n TableName extends string,\n TableSchema extends Schema.Codec<any, any>,\n>(\n tableName: TableName,\n schema: TableSchema,\n): ExtendWithSystemFields<TableName, TableSchema> => {\n const system = SystemFields(tableName).fields;\n\n const extendAst = makeExtendAst(\n pipe(\n system,\n Record.toEntries,\n Array.map(\n ([name, field]) => new SchemaAST.PropertySignature(name, field.ast),\n ),\n ),\n );\n\n const extend = (s: Schema.Top): Schema.Top => {\n if (\n s.ast.encoding === undefined &&\n SchemaAST.isUnion(s.ast) &&\n Array.isArray(\n (s as Partial<Schema.Union<ReadonlyArray<Schema.Top>>>).members,\n )\n ) {\n return Schema.Union(\n Array.map(\n (s as Schema.Union<ReadonlyArray<Schema.Top>>).members,\n extend,\n ),\n );\n }\n if (\n s.ast.encoding === undefined &&\n SchemaAST.isObjects(s.ast) &&\n typeof (s as Partial<Schema.Struct<Schema.Struct.Fields>>).mapFields ===\n \"function\"\n ) {\n return Schema.fieldsAssign(system)(\n s as Schema.Struct<Schema.Struct.Fields>,\n );\n }\n return Schema.make(extendAst(s.ast));\n };\n\n return extend(schema) as unknown as ExtendWithSystemFields<\n TableName,\n TableSchema\n >;\n};\n\n/**\n * Applies the system fields to a single struct, mirroring `Schema.fieldsAssign`.\n * Any other (already-extended or opaque) schema falls back to a `Codec` carrying\n * the system-field document shape.\n */\ntype ApplySystemFields<TableName extends string, S> =\n S extends Schema.Struct<infer Fields extends Schema.Struct.Fields>\n ? Schema.Struct<\n Struct.Simplify<Struct.Assign<Fields, SystemFieldsFor<TableName>>>\n >\n : S extends Schema.Codec<infer Type, infer Encoded>\n ? Schema.Codec<\n WithSystemFields<TableName, Type>,\n WithSystemFields<TableName, Encoded>\n >\n : never;\n\n/**\n * Extend a table schema with Convex system fields at the type level.\n *\n * This mirrors the runtime {@link extendWithSystemFields}: a `Struct` gains the\n * system fields directly (matching `Schema.fieldsAssign`), and a `Union` has\n * them distributed across its members (matching\n * `union.mapMembers(Tuple.map(Schema.fieldsAssign(...)))`). The `Struct`/`Union`\n * structure is preserved rather than collapsed to a bare `Codec`; any other\n * schema falls back to a `Codec` carrying the system-field document shape,\n * matching the runtime's AST-level extension.\n */\nexport type ExtendWithSystemFields<\n TableName extends string,\n TableSchema extends Schema.Top,\n> =\n TableSchema extends Schema.Union<\n infer Members extends ReadonlyArray<Schema.Top>\n >\n ? Schema.Union<\n Struct.Simplify<\n Readonly<{\n [K in keyof Members]: ExtendWithSystemFields<TableName, Members[K]>;\n }>\n >\n >\n : ApplySystemFields<TableName, TableSchema>;\n\n/**\n * The decoded/encoded document shape: a table's fields plus Convex's system\n * fields. Deliberately a bare intersection (no `Expand`/`Simplify`) — flattening\n * it with a homomorphic mapped type collapses to `{ [x: string]: any }` when\n * `Document` is still an unresolved generic, which breaks structural\n * comparability in the database reader/writer plumbing.\n */\nexport type WithSystemFields<\n TableName extends string,\n Document,\n> = Document extends unknown\n ? IdField<TableName> & NonIdSystemFields & Document\n : never;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAiBA,MAAa,gBAA0C,cACrD,OAAO,OAAO;CACZ,KAAKA,UAAoB,UAAU;CACnC,eAAe,OAAO;CACvB,CAAC;;;;;AAcJ,MAAM,mBAA0C,OAAO,KACrD,aAAa,GAAG,CAAC,OAClB;AAED,MAAM,oBAAoB,QACxB,UAAU,SAAS,IAAI,IAAI,MAAM,SAAS,kBAAkB,IAAI;AAElE,MAAM,qBAAqB,UAA2C;CACpE,MAAM,OAAO,QAAQ,QAAQ,MAAM;CACnC,MAAM,QAAQ,eACZ,OAAO,YACL,MAAM,IAAI,aAAa,QAAQ,CAAC,KAAK,MAAM,KAAK,CAAU,CAC3D;AACH,QAAO;EACL,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ACrE,IAAI,QACL;AAEH,MAAI,UAAU,UAAU,IAAI,CAC1B,QAAO,IAAI,UAAU,QACnB,MAAM,UAAU,IAAI,oBAAoB,yBAAyB,EACjE,IAAI,iBACJ,IAAI,aACJ,IAAI,QACJ,IAAI,aAAa,SAAY,SAAY,eAAe,IAAI,SAAS,EACrE,IAAI,SACJ,IAAI,eACL;AAEH,QAAM,IAAI,MACR,IAAI,SAAS,gBACT,+OACA,qBAAqB,IAAI,KAAK,kHACnC;;AAGH,QAAO;;;;;;;;;;;;;;;;;;;AAoBT,MAAa,0BAIX,WACA,WACmD;CACnD,MAAM,SAAS,aAAa,UAAU,CAAC;CAEvC,MAAM,YAAY,cAChB,KACE,QACA,OAAO,WACP,MAAM,KACH,CAAC,MAAM,WAAW,IAAI,UAAU,kBAAkB,MAAM,MAAM,IAAI,CACpE,CACF,CACF;CAED,MAAM,UAAU,MAA8B;AAC5C,MACE,EAAE,IAAI,aAAa,UACnB,UAAU,QAAQ,EAAE,IAAI,IACxB,MAAM,QACH,EAAuD,QACzD,CAED,QAAO,OAAO,MACZ,MAAM,IACH,EAA8C,SAC/C,OACD,CACF;AAEH,MACE,EAAE,IAAI,aAAa,UACnB,UAAU,UAAU,EAAE,IAAI,IAC1B,OAAQ,EAAmD,cACzD,WAEF,QAAO,OAAO,aAAa,OAAO,CAChC,EACD;AAEH,SAAO,OAAO,KAAK,UAAU,EAAE,IAAI,CAAC;;AAGtC,QAAO,OAAO,OAAO"}
|
package/dist/UserIdentity.d.ts
CHANGED
|
@@ -1,58 +1,24 @@
|
|
|
1
1
|
import * as Schema from "effect/Schema";
|
|
2
2
|
export declare const UserIdentity: <CustomClaimsFields extends Schema.Struct.Fields>(customClaimsFields: CustomClaimsFields) => Schema.Struct<CustomClaimsFields & {
|
|
3
|
-
tokenIdentifier:
|
|
4
|
-
subject:
|
|
5
|
-
issuer:
|
|
6
|
-
name: Schema.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}>;
|
|
24
|
-
pictureUrl: Schema.optionalWith<typeof Schema.String, {
|
|
25
|
-
exact: true;
|
|
26
|
-
}>;
|
|
27
|
-
email: Schema.optionalWith<typeof Schema.String, {
|
|
28
|
-
exact: true;
|
|
29
|
-
}>;
|
|
30
|
-
emailVerified: Schema.optionalWith<typeof Schema.Boolean, {
|
|
31
|
-
exact: true;
|
|
32
|
-
}>;
|
|
33
|
-
gender: Schema.optionalWith<typeof Schema.String, {
|
|
34
|
-
exact: true;
|
|
35
|
-
}>;
|
|
36
|
-
birthday: Schema.optionalWith<typeof Schema.String, {
|
|
37
|
-
exact: true;
|
|
38
|
-
}>;
|
|
39
|
-
timezone: Schema.optionalWith<typeof Schema.String, {
|
|
40
|
-
exact: true;
|
|
41
|
-
}>;
|
|
42
|
-
language: Schema.optionalWith<typeof Schema.String, {
|
|
43
|
-
exact: true;
|
|
44
|
-
}>;
|
|
45
|
-
phoneNumber: Schema.optionalWith<typeof Schema.String, {
|
|
46
|
-
exact: true;
|
|
47
|
-
}>;
|
|
48
|
-
phoneNumberVerified: Schema.optionalWith<typeof Schema.Boolean, {
|
|
49
|
-
exact: true;
|
|
50
|
-
}>;
|
|
51
|
-
address: Schema.optionalWith<typeof Schema.String, {
|
|
52
|
-
exact: true;
|
|
53
|
-
}>;
|
|
54
|
-
updatedAt: Schema.optionalWith<typeof Schema.String, {
|
|
55
|
-
exact: true;
|
|
56
|
-
}>;
|
|
3
|
+
readonly tokenIdentifier: Schema.String;
|
|
4
|
+
readonly subject: Schema.String;
|
|
5
|
+
readonly issuer: Schema.String;
|
|
6
|
+
readonly name: Schema.optionalKey<Schema.String>;
|
|
7
|
+
readonly givenName: Schema.optionalKey<Schema.String>;
|
|
8
|
+
readonly familyName: Schema.optionalKey<Schema.String>;
|
|
9
|
+
readonly nickname: Schema.optionalKey<Schema.String>;
|
|
10
|
+
readonly preferredUsername: Schema.optionalKey<Schema.String>;
|
|
11
|
+
readonly profileUrl: Schema.optionalKey<Schema.String>;
|
|
12
|
+
readonly pictureUrl: Schema.optionalKey<Schema.String>;
|
|
13
|
+
readonly email: Schema.optionalKey<Schema.String>;
|
|
14
|
+
readonly emailVerified: Schema.optionalKey<Schema.Boolean>;
|
|
15
|
+
readonly gender: Schema.optionalKey<Schema.String>;
|
|
16
|
+
readonly birthday: Schema.optionalKey<Schema.String>;
|
|
17
|
+
readonly timezone: Schema.optionalKey<Schema.String>;
|
|
18
|
+
readonly language: Schema.optionalKey<Schema.String>;
|
|
19
|
+
readonly phoneNumber: Schema.optionalKey<Schema.String>;
|
|
20
|
+
readonly phoneNumberVerified: Schema.optionalKey<Schema.Boolean>;
|
|
21
|
+
readonly address: Schema.optionalKey<Schema.String>;
|
|
22
|
+
readonly updatedAt: Schema.optionalKey<Schema.String>;
|
|
57
23
|
}>;
|
|
58
24
|
//# sourceMappingURL=UserIdentity.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UserIdentity.d.ts","sourceRoot":"","sources":["../src/UserIdentity.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,eAAO,MAAM,YAAY,GAAI,kBAAkB,SAAS,MAAM,CAAC,MAAM,CAAC,MAAM,EAC1E,oBAAoB,kBAAkB
|
|
1
|
+
{"version":3,"file":"UserIdentity.d.ts","sourceRoot":"","sources":["../src/UserIdentity.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,eAAO,MAAM,YAAY,GAAI,kBAAkB,SAAS,MAAM,CAAC,MAAM,CAAC,MAAM,EAC1E,oBAAoB,kBAAkB;;;;;;;;;;;;;;;;;;;;;EAwBpC,CAAC"}
|
package/dist/UserIdentity.js
CHANGED
|
@@ -8,23 +8,23 @@ const UserIdentity = (customClaimsFields) => Schema.Struct({
|
|
|
8
8
|
tokenIdentifier: Schema.String,
|
|
9
9
|
subject: Schema.String,
|
|
10
10
|
issuer: Schema.String,
|
|
11
|
-
name: Schema.
|
|
12
|
-
givenName: Schema.
|
|
13
|
-
familyName: Schema.
|
|
14
|
-
nickname: Schema.
|
|
15
|
-
preferredUsername: Schema.
|
|
16
|
-
profileUrl: Schema.
|
|
17
|
-
pictureUrl: Schema.
|
|
18
|
-
email: Schema.
|
|
19
|
-
emailVerified: Schema.
|
|
20
|
-
gender: Schema.
|
|
21
|
-
birthday: Schema.
|
|
22
|
-
timezone: Schema.
|
|
23
|
-
language: Schema.
|
|
24
|
-
phoneNumber: Schema.
|
|
25
|
-
phoneNumberVerified: Schema.
|
|
26
|
-
address: Schema.
|
|
27
|
-
updatedAt: Schema.
|
|
11
|
+
name: Schema.optionalKey(Schema.String),
|
|
12
|
+
givenName: Schema.optionalKey(Schema.String),
|
|
13
|
+
familyName: Schema.optionalKey(Schema.String),
|
|
14
|
+
nickname: Schema.optionalKey(Schema.String),
|
|
15
|
+
preferredUsername: Schema.optionalKey(Schema.String),
|
|
16
|
+
profileUrl: Schema.optionalKey(Schema.String),
|
|
17
|
+
pictureUrl: Schema.optionalKey(Schema.String),
|
|
18
|
+
email: Schema.optionalKey(Schema.String),
|
|
19
|
+
emailVerified: Schema.optionalKey(Schema.Boolean),
|
|
20
|
+
gender: Schema.optionalKey(Schema.String),
|
|
21
|
+
birthday: Schema.optionalKey(Schema.String),
|
|
22
|
+
timezone: Schema.optionalKey(Schema.String),
|
|
23
|
+
language: Schema.optionalKey(Schema.String),
|
|
24
|
+
phoneNumber: Schema.optionalKey(Schema.String),
|
|
25
|
+
phoneNumberVerified: Schema.optionalKey(Schema.Boolean),
|
|
26
|
+
address: Schema.optionalKey(Schema.String),
|
|
27
|
+
updatedAt: Schema.optionalKey(Schema.String)
|
|
28
28
|
});
|
|
29
29
|
|
|
30
30
|
//#endregion
|
package/dist/UserIdentity.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UserIdentity.js","names":[],"sources":["../src/UserIdentity.ts"],"sourcesContent":["import * as Schema from \"effect/Schema\";\n\nexport const UserIdentity = <CustomClaimsFields extends Schema.Struct.Fields>(\n customClaimsFields: CustomClaimsFields,\n) =>\n Schema.Struct({\n ...customClaimsFields,\n tokenIdentifier: Schema.String,\n subject: Schema.String,\n issuer: Schema.String,\n name: Schema.
|
|
1
|
+
{"version":3,"file":"UserIdentity.js","names":[],"sources":["../src/UserIdentity.ts"],"sourcesContent":["import * as Schema from \"effect/Schema\";\n\nexport const UserIdentity = <CustomClaimsFields extends Schema.Struct.Fields>(\n customClaimsFields: CustomClaimsFields,\n) =>\n Schema.Struct({\n ...customClaimsFields,\n tokenIdentifier: Schema.String,\n subject: Schema.String,\n issuer: Schema.String,\n name: Schema.optionalKey(Schema.String),\n givenName: Schema.optionalKey(Schema.String),\n familyName: Schema.optionalKey(Schema.String),\n nickname: Schema.optionalKey(Schema.String),\n preferredUsername: Schema.optionalKey(Schema.String),\n profileUrl: Schema.optionalKey(Schema.String),\n pictureUrl: Schema.optionalKey(Schema.String),\n email: Schema.optionalKey(Schema.String),\n emailVerified: Schema.optionalKey(Schema.Boolean),\n gender: Schema.optionalKey(Schema.String),\n birthday: Schema.optionalKey(Schema.String),\n timezone: Schema.optionalKey(Schema.String),\n language: Schema.optionalKey(Schema.String),\n phoneNumber: Schema.optionalKey(Schema.String),\n phoneNumberVerified: Schema.optionalKey(Schema.Boolean),\n address: Schema.optionalKey(Schema.String),\n updatedAt: Schema.optionalKey(Schema.String),\n });\n"],"mappings":";;;;;AAEA,MAAa,gBACX,uBAEA,OAAO,OAAO;CACZ,GAAG;CACH,iBAAiB,OAAO;CACxB,SAAS,OAAO;CAChB,QAAQ,OAAO;CACf,MAAM,OAAO,YAAY,OAAO,OAAO;CACvC,WAAW,OAAO,YAAY,OAAO,OAAO;CAC5C,YAAY,OAAO,YAAY,OAAO,OAAO;CAC7C,UAAU,OAAO,YAAY,OAAO,OAAO;CAC3C,mBAAmB,OAAO,YAAY,OAAO,OAAO;CACpD,YAAY,OAAO,YAAY,OAAO,OAAO;CAC7C,YAAY,OAAO,YAAY,OAAO,OAAO;CAC7C,OAAO,OAAO,YAAY,OAAO,OAAO;CACxC,eAAe,OAAO,YAAY,OAAO,QAAQ;CACjD,QAAQ,OAAO,YAAY,OAAO,OAAO;CACzC,UAAU,OAAO,YAAY,OAAO,OAAO;CAC3C,UAAU,OAAO,YAAY,OAAO,OAAO;CAC3C,UAAU,OAAO,YAAY,OAAO,OAAO;CAC3C,aAAa,OAAO,YAAY,OAAO,OAAO;CAC9C,qBAAqB,OAAO,YAAY,OAAO,QAAQ;CACvD,SAAS,OAAO,YAAY,OAAO,OAAO;CAC1C,WAAW,OAAO,YAAY,OAAO,OAAO;CAC7C,CAAC"}
|