@confect/core 10.0.0-next.15 → 10.0.0-next.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/CHANGELOG.md +246 -0
  2. package/dist/FunctionProvenance.d.ts +18 -18
  3. package/dist/FunctionProvenance.d.ts.map +1 -1
  4. package/dist/FunctionProvenance.js +1 -1
  5. package/dist/FunctionProvenance.js.map +1 -1
  6. package/dist/FunctionSpec.d.ts +54 -48
  7. package/dist/FunctionSpec.d.ts.map +1 -1
  8. package/dist/FunctionSpec.js +23 -5
  9. package/dist/FunctionSpec.js.map +1 -1
  10. package/dist/GroupPath.d.ts +1 -4
  11. package/dist/GroupPath.d.ts.map +1 -1
  12. package/dist/GroupPath.js.map +1 -1
  13. package/dist/GroupSpec.d.ts +16 -10
  14. package/dist/GroupSpec.d.ts.map +1 -1
  15. package/dist/GroupSpec.js +34 -11
  16. package/dist/GroupSpec.js.map +1 -1
  17. package/dist/Lazy.d.ts +2 -3
  18. package/dist/Lazy.d.ts.map +1 -1
  19. package/dist/Lazy.js +2 -3
  20. package/dist/Lazy.js.map +1 -1
  21. package/dist/MiddlewareSpec.d.ts +184 -0
  22. package/dist/MiddlewareSpec.d.ts.map +1 -0
  23. package/dist/MiddlewareSpec.js +55 -0
  24. package/dist/MiddlewareSpec.js.map +1 -0
  25. package/dist/Ref.d.ts +53 -37
  26. package/dist/Ref.d.ts.map +1 -1
  27. package/dist/Ref.js +53 -35
  28. package/dist/Ref.js.map +1 -1
  29. package/dist/Refs.d.ts +8 -3
  30. package/dist/Refs.d.ts.map +1 -1
  31. package/dist/Refs.js +3 -3
  32. package/dist/Refs.js.map +1 -1
  33. package/dist/SchemaToValidator.d.ts +99 -0
  34. package/dist/SchemaToValidator.d.ts.map +1 -0
  35. package/dist/SchemaToValidator.js +156 -0
  36. package/dist/SchemaToValidator.js.map +1 -0
  37. package/dist/Spec.d.ts +3 -2
  38. package/dist/Spec.d.ts.map +1 -1
  39. package/dist/Spec.js +1 -1
  40. package/dist/Spec.js.map +1 -1
  41. package/dist/Table.d.ts +74 -0
  42. package/dist/Table.d.ts.map +1 -0
  43. package/dist/Table.js +77 -0
  44. package/dist/Table.js.map +1 -0
  45. package/dist/Types.d.ts +8 -2
  46. package/dist/Types.d.ts.map +1 -1
  47. package/dist/Types.js.map +1 -1
  48. package/dist/index.d.ts +3 -1
  49. package/dist/index.d.ts.map +1 -1
  50. package/dist/index.js +4 -2
  51. package/package.json +9 -8
  52. package/src/FunctionProvenance.ts +8 -8
  53. package/src/FunctionSpec.ts +93 -14
  54. package/src/GroupPath.ts +1 -6
  55. package/src/GroupSpec.ts +125 -18
  56. package/src/Lazy.ts +2 -3
  57. package/src/MiddlewareSpec.ts +356 -0
  58. package/src/Ref.ts +310 -205
  59. package/src/Refs.ts +40 -16
  60. package/src/SchemaToValidator.ts +601 -0
  61. package/src/Spec.ts +4 -4
  62. package/src/Table.ts +426 -0
  63. package/src/Types.ts +9 -3
  64. package/src/index.ts +3 -1
  65. package/dist/Registry.d.ts +0 -24
  66. package/dist/Registry.d.ts.map +0 -1
  67. package/dist/Registry.js +0 -19
  68. package/dist/Registry.js.map +0 -1
  69. package/dist/tsconfig.src.tsbuildinfo +0 -1
  70. package/src/Registry.ts +0 -30
package/dist/Ref.d.ts CHANGED
@@ -4,55 +4,68 @@ import { ConvexError } from "convex/values";
4
4
  import * as Effect from "effect/Effect";
5
5
  import * as Option from "effect/Option";
6
6
  import * as Schema from "effect/Schema";
7
+ import type * as FunctionProvenance from "./FunctionProvenance";
7
8
  import type * as FunctionSpec from "./FunctionSpec";
9
+ import * as MiddlewareSpec from "./MiddlewareSpec";
8
10
  import type * as RuntimeAndFunctionType from "./RuntimeAndFunctionType";
9
- export interface Ref<_RuntimeAndFunctionType extends RuntimeAndFunctionType.RuntimeAndFunctionType, _FunctionVisibility extends FunctionVisibility, _Args, _Returns, _Error = never> {
10
- readonly _RuntimeAndFunctionType?: _RuntimeAndFunctionType;
11
- readonly _FunctionVisibility?: _FunctionVisibility;
12
- readonly _Args?: _Args;
13
- readonly _Returns?: _Returns;
14
- readonly _Error?: _Error;
11
+ export interface Base<RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType, FunctionVisibility_ extends FunctionVisibility, Args_, Returns_, Error_ = never> {
12
+ readonly "~RuntimeAndFunctionType": RuntimeAndFunctionType_;
13
+ readonly "~FunctionVisibility": FunctionVisibility_;
14
+ readonly "~Args": Args_;
15
+ readonly "~Returns": Returns_;
16
+ readonly "~Error": Error_;
15
17
  }
16
- export interface Any extends Ref<any, any, any, any, any> {
17
- }
18
- export interface AnyInternal extends Ref<any, "internal", any, any, any> {
19
- }
20
- export interface AnyPublic extends Ref<any, "public", any, any, any> {
18
+ /**
19
+ * A reference to a single Convex function, as callers see it: the wire name
20
+ * plus the data needed to encode args, decode returns, and decode typed
21
+ * errors. A ref is one of two shapes, keyed by the spec's provenance.
22
+ */
23
+ export type Ref<RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType, FunctionVisibility_ extends FunctionVisibility, Args_, Returns_, Error_ = never> = ConfectRef<RuntimeAndFunctionType_, FunctionVisibility_, Args_, Returns_, Error_> | ConvexRef<RuntimeAndFunctionType_, FunctionVisibility_, Args_, Returns_, Error_>;
24
+ export interface ConfectRef<RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType, FunctionVisibility_ extends FunctionVisibility, Args_, Returns_, Error_ = never> extends Base<RuntimeAndFunctionType_, FunctionVisibility_, Args_, Returns_, Error_> {
21
25
  }
22
- export interface AnyQuery extends Ref<RuntimeAndFunctionType.AnyQuery, FunctionVisibility, any, any, any> {
26
+ export interface ConvexRef<RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType, FunctionVisibility_ extends FunctionVisibility, Args_, Returns_, Error_ = never> extends Base<RuntimeAndFunctionType_, FunctionVisibility_, Args_, Returns_, Error_> {
23
27
  }
24
- export interface AnyPublicPaginatedQuery extends Ref<RuntimeAndFunctionType.AnyQuery, "public", {
28
+ export type Any = Ref<any, any, any, any, any>;
29
+ export type AnyInternal = Ref<any, "internal", any, any, any>;
30
+ export type AnyPublic = Ref<any, "public", any, any, any>;
31
+ export type AnyQuery = Ref<RuntimeAndFunctionType.AnyQuery, FunctionVisibility, any, any, any>;
32
+ export type AnyPublicPaginatedQuery = Ref<RuntimeAndFunctionType.AnyQuery, "public", {
25
33
  [key: string]: any;
26
34
  paginationOpts: PaginationOptions;
27
- }, PaginationResult<any>, any> {
28
- }
29
- export interface AnyMutation extends Ref<RuntimeAndFunctionType.AnyMutation, FunctionVisibility, any, any, any> {
30
- }
31
- export interface AnyAction extends Ref<RuntimeAndFunctionType.AnyAction, FunctionVisibility, any, any, any> {
32
- }
33
- export interface AnyPublicQuery extends Ref<RuntimeAndFunctionType.AnyQuery, "public", any, any, any> {
34
- }
35
- export interface AnyPublicMutation extends Ref<RuntimeAndFunctionType.AnyMutation, "public", any, any, any> {
36
- }
37
- export interface AnyPublicAction extends Ref<RuntimeAndFunctionType.AnyAction, "public", any, any, any> {
38
- }
39
- export type GetRuntimeAndFunctionType<Ref_> = Ref_ extends Ref<infer RuntimeAndFunctionType_, infer _FunctionVisibility, infer _Args, infer _Returns, infer _Error> ? RuntimeAndFunctionType_ : never;
40
- export type GetRuntime<Ref_> = Ref_ extends Ref<infer RuntimeAndFunctionType_, infer _FunctionVisibility, infer _Args, infer _Returns, infer _Error> ? RuntimeAndFunctionType.GetRuntime<RuntimeAndFunctionType_> : never;
41
- export type GetFunctionType<Ref_> = Ref_ extends Ref<infer RuntimeAndFunctionType_, infer _FunctionVisibility, infer _Args, infer _Returns, infer _Error> ? RuntimeAndFunctionType.GetFunctionType<RuntimeAndFunctionType_> : never;
42
- export type GetFunctionVisibility<Ref_> = Ref_ extends Ref<infer _RuntimeAndFunctionType, infer FunctionVisibility_, infer _Args, infer _Returns, infer _Error> ? FunctionVisibility_ : never;
43
- export type Args<Ref_> = Ref_ extends Ref<infer _RuntimeAndFunctionType, infer _FunctionVisibility, infer Args_, infer _Returns, infer _Error> ? Args_ : never;
35
+ }, PaginationResult<any>, any>;
36
+ export type AnyMutation = Ref<RuntimeAndFunctionType.AnyMutation, FunctionVisibility, any, any, any>;
37
+ export type AnyAction = Ref<RuntimeAndFunctionType.AnyAction, FunctionVisibility, any, any, any>;
38
+ export type AnyPublicQuery = Ref<RuntimeAndFunctionType.AnyQuery, "public", any, any, any>;
39
+ export type AnyPublicMutation = Ref<RuntimeAndFunctionType.AnyMutation, "public", any, any, any>;
40
+ export type AnyPublicAction = Ref<RuntimeAndFunctionType.AnyAction, "public", any, any, any>;
41
+ export type GetRuntimeAndFunctionType<Ref_> = Ref_ extends {
42
+ readonly "~RuntimeAndFunctionType": infer RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType;
43
+ } ? RuntimeAndFunctionType_ : never;
44
+ export type GetRuntime<Ref_> = RuntimeAndFunctionType.GetRuntime<GetRuntimeAndFunctionType<Ref_>>;
45
+ export type GetFunctionType<Ref_> = RuntimeAndFunctionType.GetFunctionType<GetRuntimeAndFunctionType<Ref_>>;
46
+ export type GetFunctionVisibility<Ref_> = Ref_ extends {
47
+ readonly "~FunctionVisibility": infer FunctionVisibility_;
48
+ } ? FunctionVisibility_ : never;
49
+ export type Args<Ref_> = Ref_ extends {
50
+ readonly "~Args": infer Args_;
51
+ } ? Args_ : never;
44
52
  export type OptionalArgs<Ref_ extends Any> = keyof Args<Ref_> extends never ? [args?: Args<Ref_>] : [args: Args<Ref_>];
45
- export type Returns<Ref_> = Ref_ extends Ref<infer _RuntimeAndFunctionType, infer _FunctionVisibility, infer _Args, infer Returns_, infer _Error> ? Returns_ : never;
46
- export type Error<Ref_> = Ref_ extends Ref<infer _RuntimeAndFunctionType, infer _FunctionVisibility, infer _Args, infer _Returns, infer Error_> ? Error_ : never;
53
+ export type Returns<Ref_> = Ref_ extends {
54
+ readonly "~Returns": infer Returns_;
55
+ } ? Returns_ : never;
56
+ export type Error<Ref_> = Ref_ extends {
57
+ readonly "~Error": infer Error_;
58
+ } ? Error_ : never;
47
59
  export type FunctionReference<Ref_ extends Any> = ConvexFunctionReference<GetFunctionType<Ref_>, GetFunctionVisibility<Ref_>>;
48
- export type FromFunctionSpec<FunctionSpec_ extends FunctionSpec.AnyWithProps> = Ref<FunctionSpec.GetRuntimeAndFunctionType<FunctionSpec_>, FunctionSpec.GetFunctionVisibility<FunctionSpec_>, FunctionSpec.Args<FunctionSpec_>, FunctionSpec.Returns<FunctionSpec_>, FunctionSpec.Error<FunctionSpec_>>;
60
+ export type FromFunctionSpec<FunctionSpec_ extends FunctionSpec.AnyWithProps, MiddlewareError = never> = FromFunctionSpecHelper<FunctionSpec_, FunctionSpec.GetRuntimeAndFunctionType<FunctionSpec_>, FunctionSpec.GetFunctionVisibility<FunctionSpec_>, FunctionSpec.Args<FunctionSpec_>, FunctionSpec.Returns<FunctionSpec_>, FunctionSpec.Error<FunctionSpec_> | MiddlewareError>;
61
+ type FromFunctionSpecHelper<FunctionSpec_ extends FunctionSpec.AnyWithProps, RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType, FunctionVisibility_ extends FunctionVisibility, Args_, Returns_, Error_> = FunctionSpec_ extends FunctionSpec.WithFunctionProvenance<FunctionSpec_, FunctionProvenance.AnyConvex> ? ConvexRef<RuntimeAndFunctionType_, FunctionVisibility_, Args_, Returns_, Error_> : FunctionSpec_ extends FunctionSpec.WithFunctionProvenance<FunctionSpec_, FunctionProvenance.AnyConfect> ? ConfectRef<RuntimeAndFunctionType_, FunctionVisibility_, Args_, Returns_, Error_> : Ref<RuntimeAndFunctionType_, FunctionVisibility_, Args_, Returns_, Error_>;
49
62
  export declare const make: <FunctionSpec_ extends FunctionSpec.AnyWithProps>(
50
63
  /**
51
64
  * The namespace portion of a Convex function name, i.e. the part before the
52
65
  * colon. For example, for `myGroupDir/myGroupMod:myFunc` this would be
53
66
  * `myGroupDir/myGroupMod`.
54
67
  */
55
- functionNamespace: string, functionSpec: FunctionSpec_) => FromFunctionSpec<FunctionSpec_>;
68
+ convexFunctionNamespace: string, functionSpec: FunctionSpec_, groupMiddlewareSpecs?: ReadonlyArray<MiddlewareSpec.AnyMiddlewareSpec>) => FromFunctionSpec<FunctionSpec_>;
56
69
  export declare const getConvexFunctionName: (ref: Any) => string;
57
70
  export declare const getFunctionReference: <Ref_ extends Any>(ref: Ref_) => FunctionReference<Ref_>;
58
71
  export declare const hasErrorSchema: (ref: Any) => boolean;
@@ -74,9 +87,11 @@ export declare const isConvexError: (error: unknown) => error is ConvexError<Val
74
87
  */
75
88
  export declare const decodeErrorOrElse: <Ref_ extends Any, E>(ref: Ref_, mapUnknownError: (error: unknown) => E) => (error: unknown) => Error<Ref_> | E;
76
89
  /**
77
- * Decode `encodedError` against the ref's error schema. Returns `None` if the
78
- * ref doesn't declare a typed error (Confect ref without an `error` schema, or
79
- * a Convex-provenance ref)—by definition there's nothing to decode the value
90
+ * Decode `encodedError` against the ref's error schema — the function's
91
+ * declared `error` schema unioned with its covering middlewares' error
92
+ * schemas. Returns `None` if the ref declares no typed error at all (Confect
93
+ * ref without an `error` schema and without failing middleware, or a
94
+ * Convex-provenance ref)—by definition there's nothing to decode the value
80
95
  * into, and the caller is responsible for deciding what to do (typically:
81
96
  * surface the original value as a defect).
82
97
  */
@@ -120,4 +135,5 @@ export declare const decodePaginationPageSync: <Ref_ extends AnyPublicPaginatedQ
120
135
  * no handler is provided.
121
136
  */
122
137
  export declare const runWithCodec: <Ref_ extends Any, E = never>(ref: Ref_, args: Args<Ref_>, call: (functionReference: FunctionReference<Ref_>, encodedArgs: unknown) => PromiseLike<unknown>, mapUnknownError?: (error: unknown) => E) => Effect.Effect<Returns<Ref_>, E | Error<Ref_> | Schema.SchemaError>;
138
+ export {};
123
139
  //# sourceMappingURL=Ref.d.ts.map
package/dist/Ref.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":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exportAll } from "./_virtual/_rolldown/runtime.js";
2
+ import { defineProperty } from "./Lazy.js";
3
+ import { errorSchemas } from "./MiddlewareSpec.js";
2
4
  import * as Schema from "effect/Schema";
3
5
  import * as Option from "effect/Option";
4
6
  import { makeFunctionReference } from "convex/server";
@@ -25,27 +27,41 @@ var Ref_exports = /* @__PURE__ */ __exportAll({
25
27
  make: () => make,
26
28
  runWithCodec: () => runWithCodec
27
29
  });
28
- const make = (functionNamespace, functionSpec) => ({
29
- functionSpec,
30
- functionNamespace
31
- });
32
- const getConvexFunctionName = (ref) => `${ref.functionNamespace}:${ref.functionSpec.name}`;
30
+ const make = (convexFunctionNamespace, functionSpec, groupMiddlewareSpecs = []) => {
31
+ const convexFunctionName = `${convexFunctionNamespace}:${functionSpec.name}`;
32
+ return Match.value(functionSpec.functionProvenance).pipe(Match.tag("Convex", () => ({
33
+ _tag: "Convex",
34
+ convexFunctionName
35
+ })), Match.tag("Confect", (provenance) => {
36
+ const ref = {
37
+ _tag: "Confect",
38
+ convexFunctionName,
39
+ kind: provenance.kind,
40
+ middlewareSpecs: [...groupMiddlewareSpecs, ...functionSpec.middlewareSpecs]
41
+ };
42
+ defineProperty(ref, "args", () => provenance.args);
43
+ defineProperty(ref, "returns", () => provenance.returns);
44
+ if ("error" in provenance) defineProperty(ref, "error", () => provenance.error);
45
+ return ref;
46
+ }), Match.exhaustive);
47
+ };
48
+ const getConvexFunctionName = (ref) => ref.convexFunctionName;
33
49
  const functionReferenceCache = /* @__PURE__ */ new Map();
34
50
  const getFunctionReference = (ref) => {
35
- const functionName = getConvexFunctionName(ref);
36
- const cached = functionReferenceCache.get(functionName);
51
+ const convexFunctionName = getConvexFunctionName(ref);
52
+ const cached = functionReferenceCache.get(convexFunctionName);
37
53
  if (cached !== void 0) return cached;
38
- const functionReference = makeFunctionReference(functionName);
39
- functionReferenceCache.set(functionName, functionReference);
54
+ const functionReference = makeFunctionReference(convexFunctionName);
55
+ functionReferenceCache.set(convexFunctionName, functionReference);
40
56
  return functionReference;
41
57
  };
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.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
- 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.decodeUnknownSync(confectFunctionProvenance.args)(encodedArgs)), Match.tag("Convex", () => encodedArgs), Match.exhaustive);
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.decodeUnknownSync(confectFunctionProvenance.returns)(encodedReturns)), Match.tag("Convex", () => encodedReturns), Match.exhaustive);
58
+ const hasErrorSchema = (ref) => Match.value(ref).pipe(Match.tag("Confect", (confectRef) => "error" in confectRef || confectRef.middlewareSpecs.some((middlewareSpec) => "error" in middlewareSpec)), Match.tag("Convex", () => false), Match.exhaustive);
59
+ const encodeArgs = (ref, args) => Match.value(ref).pipe(Match.tag("Confect", (confectRef) => Schema.encodeEffect(confectRef.args)(args)), Match.tag("Convex", () => Effect.succeed(args)), Match.exhaustive);
60
+ const decodeReturns = (ref, returns) => Match.value(ref).pipe(Match.tag("Confect", (confectRef) => Schema.decodeUnknownEffect(confectRef.returns)(returns)), Match.tag("Convex", () => Effect.succeed(returns)), Match.exhaustive);
61
+ const encodeArgsSync = (ref, args) => Match.value(ref).pipe(Match.tag("Confect", (confectRef) => Schema.encodeSync(confectRef.args)(args)), Match.tag("Convex", () => args), Match.exhaustive);
62
+ const decodeArgsSync = (ref, encodedArgs) => Match.value(ref).pipe(Match.tag("Confect", (confectRef) => Schema.decodeUnknownSync(confectRef.args)(encodedArgs)), Match.tag("Convex", () => encodedArgs), Match.exhaustive);
63
+ const encodeReturnsSync = (ref, returns) => Match.value(ref).pipe(Match.tag("Confect", (confectRef) => Schema.encodeSync(confectRef.returns)(returns)), Match.tag("Convex", () => returns), Match.exhaustive);
64
+ const decodeReturnsSync = (ref, encodedReturns) => Match.value(ref).pipe(Match.tag("Confect", (confectRef) => Schema.decodeUnknownSync(confectRef.returns)(encodedReturns)), Match.tag("Convex", () => encodedReturns), Match.exhaustive);
49
65
  const ConvexErrorIdentifier = Symbol.for("ConvexError");
50
66
  const isConvexError = (error) => error instanceof ConvexError || typeof error === "object" && error !== null && ConvexErrorIdentifier in error;
51
67
  /**
@@ -64,14 +80,23 @@ const decodeErrorOrElse = (ref, mapUnknownError) => (error) => {
64
80
  }
65
81
  return mapUnknownError(error);
66
82
  };
83
+ const errorSchemaOf = (ref) => Match.value(ref).pipe(Match.tag("Confect", (confectRef) => {
84
+ const schemas = [..."error" in confectRef && confectRef.error !== void 0 ? [confectRef.error] : [], ...errorSchemas(confectRef.middlewareSpecs)];
85
+ return schemas.length === 0 ? Option.none() : Option.some(schemas.length === 1 ? schemas[0] : Schema.Union(schemas));
86
+ }), Match.tag("Convex", () => Option.none()), Match.exhaustive);
67
87
  /**
68
- * Decode `encodedError` against the ref's error schema. Returns `None` if the
69
- * ref doesn't declare a typed error (Confect ref without an `error` schema, or
70
- * a Convex-provenance ref)—by definition there's nothing to decode the value
88
+ * Decode `encodedError` against the ref's error schema — the function's
89
+ * declared `error` schema unioned with its covering middlewares' error
90
+ * schemas. Returns `None` if the ref declares no typed error at all (Confect
91
+ * ref without an `error` schema and without failing middleware, or a
92
+ * Convex-provenance ref)—by definition there's nothing to decode the value
71
93
  * into, and the caller is responsible for deciding what to do (typically:
72
94
  * surface the original value as a defect).
73
95
  */
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);
96
+ const decodeError = (ref, encodedError) => Option.match(errorSchemaOf(ref), {
97
+ onNone: () => Effect.succeed(Option.none()),
98
+ onSome: (schema) => Effect.map(Schema.decodeUnknownEffect(schema)(encodedError), Option.some)
99
+ });
75
100
  /**
76
101
  * Synchronous counterpart to `decodeError`. Returns `None` when the value is
77
102
  * not this ref's typed error — either because the ref declares no `error`
@@ -87,7 +112,7 @@ const decodeError = (ref, encodedError) => Match.value(ref.functionSpec.function
87
112
  * in this module all throw on a parse failure, and this one deliberately
88
113
  * doesn't.
89
114
  */
90
- const decodeErrorOption = (ref, encodedError) => Match.value(ref.functionSpec.functionProvenance).pipe(Match.tag("Confect", (confectFunctionProvenance) => "error" in confectFunctionProvenance ? Schema.decodeUnknownOption(confectFunctionProvenance.error)(encodedError) : Option.none()), Match.tag("Convex", () => Option.none()), Match.exhaustive);
115
+ const decodeErrorOption = (ref, encodedError) => Option.flatMap(errorSchemaOf(ref), (schema) => Schema.decodeUnknownOption(schema)(encodedError));
91
116
  const missingPaginatedProvenanceError = (ref) => new globalThis.Error(`Paginated query ref "${getConvexFunctionName(ref)}" was not built with \`FunctionSpec.publicPaginatedQuery\` (or \`FunctionSpec.internalPaginatedQuery\`). Paginated encoding and decoding require the user-args and item schemas those constructors store. Define the function as, e.g.:
92
117
 
93
118
  FunctionSpec.publicPaginatedQuery({
@@ -95,6 +120,9 @@ const missingPaginatedProvenanceError = (ref) => new globalThis.Error(`Paginated
95
120
  args: () => Schema.Struct({ ... }), // optional; without paginationOpts
96
121
  item: () => ItemSchema,
97
122
  })`);
123
+ const paginatedKind = (ref) => Match.value(ref.kind).pipe(Match.tag("Paginated", (kind) => kind), Match.tag("Standard", () => {
124
+ throw missingPaginatedProvenanceError(ref);
125
+ }), Match.exhaustive);
98
126
  /**
99
127
  * Encode the args of a paginated query ref via its user-args schema —
100
128
  * `paginationOpts` is excluded, since the pagination protocol fields are
@@ -102,19 +130,13 @@ const missingPaginatedProvenanceError = (ref) => new globalThis.Error(`Paginated
102
130
  * the caller. Requires a ref built with `FunctionSpec.publicPaginatedQuery`
103
131
  * (or `internalPaginatedQuery`).
104
132
  */
105
- const encodePaginatedQueryArgsSync = (ref, args) => Match.value(ref.functionSpec.functionProvenance).pipe(Match.tag("Confect", (confectFunctionProvenance) => {
106
- if (confectFunctionProvenance.kind._tag !== "Paginated") throw missingPaginatedProvenanceError(ref);
107
- return Schema.encodeUnknownSync(confectFunctionProvenance.kind.userArgs)(args);
108
- }), Match.tag("Convex", () => args), Match.exhaustive);
133
+ const encodePaginatedQueryArgsSync = (ref, args) => Match.value(ref).pipe(Match.tag("Confect", (confectRef) => Schema.encodeUnknownSync(paginatedKind(confectRef).userArgs)(args)), Match.tag("Convex", () => args), Match.exhaustive);
109
134
  /**
110
135
  * Decode a page of a paginated query's results via the ref's item schema.
111
136
  * Requires a ref built with `FunctionSpec.publicPaginatedQuery` (or
112
137
  * `internalPaginatedQuery`).
113
138
  */
114
- const decodePaginationPageSync = (ref, encodedPage) => Match.value(ref.functionSpec.functionProvenance).pipe(Match.tag("Confect", (confectFunctionProvenance) => {
115
- if (confectFunctionProvenance.kind._tag !== "Paginated") throw missingPaginatedProvenanceError(ref);
116
- return Schema.decodeUnknownSync(confectFunctionProvenance.kind.page)(encodedPage);
117
- }), Match.tag("Convex", () => encodedPage), Match.exhaustive);
139
+ const decodePaginationPageSync = (ref, encodedPage) => Match.value(ref).pipe(Match.tag("Confect", (confectRef) => Schema.decodeUnknownSync(paginatedKind(confectRef).page)(encodedPage)), Match.tag("Convex", () => encodedPage), Match.exhaustive);
118
140
  /**
119
141
  * Encode args via the ref's args schema, invoke `call`, decode returns via the
120
142
  * ref's returns schema, and translate any thrown `ConvexError` into the ref's
@@ -125,7 +147,6 @@ const decodePaginationPageSync = (ref, encodedPage) => Match.value(ref.functionS
125
147
  */
126
148
  const runWithCodec = (ref, args, call, mapUnknownError) => Effect.gen(function* () {
127
149
  const functionReference = getFunctionReference(ref);
128
- const functionProvenance = ref.functionSpec.functionProvenance;
129
150
  const invoke = (encodedArgs) => Effect.tryPromise({
130
151
  try: () => Promise.resolve(call(functionReference, encodedArgs)),
131
152
  catch: (error) => {
@@ -137,11 +158,8 @@ const runWithCodec = (ref, args, call, mapUnknownError) => Effect.gen(function*
137
158
  throw error;
138
159
  }
139
160
  });
140
- return yield* Match.value(functionProvenance).pipe(Match.tag("Confect", (confectFunctionProvenance) => Effect.gen(function* () {
141
- const encodedArgs = yield* Schema.encodeEffect(confectFunctionProvenance.args)(args);
142
- const encodedReturns = yield* invoke(encodedArgs);
143
- return yield* Schema.decodeUnknownEffect(confectFunctionProvenance.returns)(encodedReturns);
144
- })), Match.tag("Convex", () => invoke(args)), Match.exhaustive);
161
+ const encodedReturns = yield* invoke(yield* encodeArgs(ref, args));
162
+ return yield* decodeReturns(ref, encodedReturns);
145
163
  });
146
164
  //#endregion
147
165
  export { Ref_exports, decodeArgsSync, decodeError, decodeErrorOption, decodeErrorOrElse, decodePaginationPageSync, decodeReturns, decodeReturnsSync, encodeArgs, encodeArgsSync, encodePaginatedQueryArgsSync, encodeReturnsSync, getConvexFunctionName, getFunctionReference, hasErrorSchema, isConvexError, make, runWithCodec };
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 PaginationOptions,\n PaginationResult,\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 AnyPublicPaginatedQuery extends Ref<\n RuntimeAndFunctionType.AnyQuery,\n \"public\",\n {\n [key: string]: any;\n paginationOpts: PaginationOptions;\n },\n PaginationResult<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 = decodeErrorOption(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`. Returns `None` when the value is\n * not this ref's typed error — either because the ref declares no `error`\n * schema, or because `encodedError` doesn't match the one it declares.\n *\n * The second case is reachable in normal operation: Convex raises its own\n * `ConvexError`s (an `InvalidCursor` pagination error, for instance), and\n * those never match a user-declared error schema. Callers pair this with a\n * fallback that surfaces the original error, so failing to decode must not\n * throw — a `ParseError` here would replace the real error with an opaque one\n * and lose the only useful diagnostic. Hence the `Option` suffix rather than\n * `Sync`, matching `Schema.decodeUnknownOption`: the sibling `*Sync` helpers\n * in this module all throw on a parse failure, and this one deliberately\n * doesn't.\n */\nexport const decodeErrorOption = <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 ? (Schema.decodeUnknownOption(confectFunctionProvenance.error)(\n encodedError,\n ) as Option.Option<Error<Ref_>>)\n : Option.none<Error<Ref_>>(),\n ),\n Match.tag(\"Convex\", () => Option.none<Error<Ref_>>()),\n Match.exhaustive,\n );\n\nconst missingPaginatedProvenanceError = (ref: Any) =>\n new globalThis.Error(\n `Paginated query ref \"${getConvexFunctionName(ref)}\" was not built with ` +\n \"`FunctionSpec.publicPaginatedQuery` (or `FunctionSpec.internalPaginatedQuery`). \" +\n \"Paginated encoding and decoding require the user-args and item schemas \" +\n \"those constructors store. Define the function as, e.g.:\\n\\n\" +\n \" FunctionSpec.publicPaginatedQuery({\\n\" +\n ' name: \"...\",\\n' +\n \" args: () => Schema.Struct({ ... }), // optional; without paginationOpts\\n\" +\n \" item: () => ItemSchema,\\n\" +\n \" })\",\n );\n\n/**\n * Encode the args of a paginated query ref via its user-args schema —\n * `paginationOpts` is excluded, since the pagination protocol fields are\n * managed by the client (e.g. `usePaginatedQuery` from `convex/react`), not by\n * the caller. Requires a ref built with `FunctionSpec.publicPaginatedQuery`\n * (or `internalPaginatedQuery`).\n */\nexport const encodePaginatedQueryArgsSync = <\n Ref_ extends AnyPublicPaginatedQuery,\n>(\n ref: Ref_,\n args: Omit<Args<Ref_>, \"paginationOpts\">,\n): unknown =>\n Match.value(ref.functionSpec.functionProvenance).pipe(\n Match.tag(\"Confect\", (confectFunctionProvenance) => {\n if (confectFunctionProvenance.kind._tag !== \"Paginated\") {\n throw missingPaginatedProvenanceError(ref);\n }\n return Schema.encodeUnknownSync(confectFunctionProvenance.kind.userArgs)(\n args,\n );\n }),\n Match.tag(\"Convex\", () => args),\n Match.exhaustive,\n );\n\n/**\n * Decode a page of a paginated query's results via the ref's item schema.\n * Requires a ref built with `FunctionSpec.publicPaginatedQuery` (or\n * `internalPaginatedQuery`).\n */\nexport const decodePaginationPageSync = <Ref_ extends AnyPublicPaginatedQuery>(\n ref: Ref_,\n encodedPage: unknown,\n): Returns<Ref_>[\"page\"] =>\n Match.value(ref.functionSpec.functionProvenance).pipe(\n Match.tag(\"Confect\", (confectFunctionProvenance) => {\n if (confectFunctionProvenance.kind._tag !== \"Paginated\") {\n throw missingPaginatedProvenanceError(ref);\n }\n return Schema.decodeUnknownSync(confectFunctionProvenance.kind.page)(\n encodedPage,\n );\n }),\n Match.tag(\"Convex\", () => encodedPage),\n Match.exhaustive,\n ) as Returns<Ref_>[\"page\"];\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 = decodeErrorOption(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":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAkMA,MAAa,QAMX,mBACA,kBACqC;CAAE;CAAc;AAAkB;AAEzE,MAAa,yBAAyB,QACpC,GAAG,IAAI,kBAAkB,GAAG,IAAI,aAAa;AAE/C,MAAM,yCAAyB,IAAI,IAAoC;AAEvE,MAAa,wBACX,QAC4B;CAC5B,MAAM,eAAe,sBAAsB,GAAG;CAE9C,MAAM,SAAS,uBAAuB,IAAI,YAAY;CACtD,IAAI,WAAW,KAAA,GACb,OAAO;CAGT,MAAM,oBAAoB,sBAAsB,YAAY;CAC5D,uBAAuB,IAAI,cAAc,iBAAiB;CAE1D,OAAO;AACT;AAEA,MAAa,kBAAkB,QAC7B,MAAM,MAAM,IAAI,aAAa,kBAAkB,CAAC,CAAC,KAC/C,MAAM,IACJ,YACC,8BAA8B,WAAW,yBAC5C,GACA,MAAM,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AAgB,OAAO,IAAI,CAAC,GACtC,MAAM,UACR;AACF,CAAC"}
1
+ {"version":3,"file":"Ref.js","names":["MiddlewareSpec.errorSchemas"],"sources":["../src/Ref.ts"],"sourcesContent":["import type {\n FunctionReference as ConvexFunctionReference,\n FunctionVisibility,\n PaginationOptions,\n PaginationResult,\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 FunctionProvenance from \"./FunctionProvenance\";\nimport type * as FunctionSpec from \"./FunctionSpec\";\nimport * as Lazy from \"./Lazy\";\nimport * as MiddlewareSpec from \"./MiddlewareSpec\";\nimport type * as RuntimeAndFunctionType from \"./RuntimeAndFunctionType\";\n\nexport interface Base<\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 convexFunctionName: string;\n}\n\n/**\n * A reference to a single Convex function, as callers see it: the wire name\n * plus the data needed to encode args, decode returns, and decode typed\n * errors. A ref is one of two shapes, keyed by the spec's provenance.\n */\nexport type Ref<\n RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility_ extends FunctionVisibility,\n Args_,\n Returns_,\n Error_ = never,\n> =\n | ConfectRef<\n RuntimeAndFunctionType_,\n FunctionVisibility_,\n Args_,\n Returns_,\n Error_\n >\n | ConvexRef<\n RuntimeAndFunctionType_,\n FunctionVisibility_,\n Args_,\n Returns_,\n Error_\n >;\n\nexport interface ConfectRef<\n RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility_ extends FunctionVisibility,\n Args_,\n Returns_,\n Error_ = never,\n> extends Base<\n RuntimeAndFunctionType_,\n FunctionVisibility_,\n Args_,\n Returns_,\n Error_\n> {\n /** @internal */\n readonly _tag: \"Confect\";\n /** @internal */\n readonly args: Schema.Codec<any, any>;\n /** @internal */\n readonly returns: Schema.Codec<any, any>;\n /** @internal */\n readonly kind: FunctionProvenance.ConfectKind;\n /** @internal */\n readonly middlewareSpecs: ReadonlyArray<MiddlewareSpec.AnyMiddlewareSpec>;\n /** @internal */\n readonly error?: Schema.Codec<any, any>;\n}\n\nexport interface ConvexRef<\n RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility_ extends FunctionVisibility,\n Args_,\n Returns_,\n Error_ = never,\n> extends Base<\n RuntimeAndFunctionType_,\n FunctionVisibility_,\n Args_,\n Returns_,\n Error_\n> {\n /** @internal */\n readonly _tag: \"Convex\";\n}\n\nexport type Any = Ref<any, any, any, any, any>;\n\nexport type AnyInternal = Ref<any, \"internal\", any, any, any>;\n\nexport type AnyPublic = Ref<any, \"public\", any, any, any>;\n\nexport type AnyQuery = Ref<\n RuntimeAndFunctionType.AnyQuery,\n FunctionVisibility,\n any,\n any,\n any\n>;\n\nexport type AnyPublicPaginatedQuery = Ref<\n RuntimeAndFunctionType.AnyQuery,\n \"public\",\n {\n [key: string]: any;\n paginationOpts: PaginationOptions;\n },\n PaginationResult<any>,\n any\n>;\n\nexport type AnyMutation = Ref<\n RuntimeAndFunctionType.AnyMutation,\n FunctionVisibility,\n any,\n any,\n any\n>;\n\nexport type AnyAction = Ref<\n RuntimeAndFunctionType.AnyAction,\n FunctionVisibility,\n any,\n any,\n any\n>;\n\nexport type AnyPublicQuery = Ref<\n RuntimeAndFunctionType.AnyQuery,\n \"public\",\n any,\n any,\n any\n>;\n\nexport type AnyPublicMutation = Ref<\n RuntimeAndFunctionType.AnyMutation,\n \"public\",\n any,\n any,\n any\n>;\n\nexport type AnyPublicAction = Ref<\n RuntimeAndFunctionType.AnyAction,\n \"public\",\n any,\n any,\n any\n>;\n\nexport type GetRuntimeAndFunctionType<Ref_> = Ref_ extends {\n readonly \"~RuntimeAndFunctionType\": infer RuntimeAndFunctionType_ extends\n RuntimeAndFunctionType.RuntimeAndFunctionType;\n}\n ? RuntimeAndFunctionType_\n : never;\n\nexport type GetRuntime<Ref_> = RuntimeAndFunctionType.GetRuntime<\n GetRuntimeAndFunctionType<Ref_>\n>;\n\nexport type GetFunctionType<Ref_> = RuntimeAndFunctionType.GetFunctionType<\n GetRuntimeAndFunctionType<Ref_>\n>;\n\nexport type GetFunctionVisibility<Ref_> = Ref_ extends {\n readonly \"~FunctionVisibility\": infer FunctionVisibility_;\n}\n ? FunctionVisibility_\n : never;\n\nexport type Args<Ref_> = Ref_ extends { readonly \"~Args\": infer Args_ }\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_> = Ref_ extends { readonly \"~Returns\": infer Returns_ }\n ? Returns_\n : never;\n\nexport type Error<Ref_> = Ref_ extends { readonly \"~Error\": infer Error_ }\n ? Error_\n : never;\n\nexport type FunctionReference<Ref_ extends Any> = ConvexFunctionReference<\n GetFunctionType<Ref_>,\n GetFunctionVisibility<Ref_>\n>;\n\nexport type FromFunctionSpec<\n FunctionSpec_ extends FunctionSpec.AnyWithProps,\n MiddlewareError = never,\n> = FromFunctionSpecHelper<\n FunctionSpec_,\n FunctionSpec.GetRuntimeAndFunctionType<FunctionSpec_>,\n FunctionSpec.GetFunctionVisibility<FunctionSpec_>,\n FunctionSpec.Args<FunctionSpec_>,\n FunctionSpec.Returns<FunctionSpec_>,\n FunctionSpec.Error<FunctionSpec_> | MiddlewareError\n>;\n\ntype FromFunctionSpecHelper<\n FunctionSpec_ extends FunctionSpec.AnyWithProps,\n RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility_ extends FunctionVisibility,\n Args_,\n Returns_,\n Error_,\n> =\n FunctionSpec_ extends FunctionSpec.WithFunctionProvenance<\n FunctionSpec_,\n FunctionProvenance.AnyConvex\n >\n ? ConvexRef<\n RuntimeAndFunctionType_,\n FunctionVisibility_,\n Args_,\n Returns_,\n Error_\n >\n : FunctionSpec_ extends FunctionSpec.WithFunctionProvenance<\n FunctionSpec_,\n FunctionProvenance.AnyConfect\n >\n ? ConfectRef<\n RuntimeAndFunctionType_,\n FunctionVisibility_,\n Args_,\n Returns_,\n Error_\n >\n : Ref<\n RuntimeAndFunctionType_,\n FunctionVisibility_,\n Args_,\n Returns_,\n Error_\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 convexFunctionNamespace: string,\n functionSpec: FunctionSpec_,\n groupMiddlewareSpecs: ReadonlyArray<MiddlewareSpec.AnyMiddlewareSpec> = [],\n): FromFunctionSpec<FunctionSpec_> => {\n const convexFunctionName = `${convexFunctionNamespace}:${functionSpec.name}`;\n\n return Match.value(functionSpec.functionProvenance).pipe(\n Match.tag(\n \"Convex\",\n (): Any =>\n ({\n _tag: \"Convex\",\n convexFunctionName,\n }) as Any,\n ),\n Match.tag(\"Confect\", (provenance): Any => {\n const ref = {\n _tag: \"Confect\" as const,\n convexFunctionName,\n kind: provenance.kind,\n middlewareSpecs: [\n ...groupMiddlewareSpecs,\n ...functionSpec.middlewareSpecs,\n ],\n };\n\n Lazy.defineProperty(ref, \"args\", () => provenance.args);\n Lazy.defineProperty(ref, \"returns\", () => provenance.returns);\n if (\"error\" in provenance) {\n Lazy.defineProperty(ref, \"error\", () => provenance.error);\n }\n\n return ref as unknown as Any;\n }),\n Match.exhaustive,\n ) as FromFunctionSpec<FunctionSpec_>;\n};\n\nexport const getConvexFunctionName = (ref: Any): string =>\n ref.convexFunctionName;\n\nconst functionReferenceCache = new Map<string, FunctionReference<Any>>();\n\nexport const getFunctionReference = <Ref_ extends Any>(\n ref: Ref_,\n): FunctionReference<Ref_> => {\n const convexFunctionName = getConvexFunctionName(ref);\n\n const cached = functionReferenceCache.get(convexFunctionName);\n if (cached !== undefined) {\n return cached as FunctionReference<Ref_>;\n }\n\n const functionReference = makeFunctionReference(convexFunctionName);\n functionReferenceCache.set(convexFunctionName, functionReference);\n\n return functionReference as FunctionReference<Ref_>;\n};\n\nexport const hasErrorSchema = (ref: Any): boolean =>\n Match.value(ref).pipe(\n Match.tag(\n \"Confect\",\n (confectRef) =>\n \"error\" in confectRef ||\n confectRef.middlewareSpecs.some(\n (middlewareSpec) => \"error\" in middlewareSpec,\n ),\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<Any>(ref).pipe(\n Match.tag(\"Confect\", (confectRef) =>\n Schema.encodeEffect(confectRef.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<Any>(ref).pipe(\n Match.tag(\"Confect\", (confectRef) =>\n Schema.decodeUnknownEffect(confectRef.returns)(returns),\n ),\n Match.tag(\"Convex\", () => Effect.succeed(returns as Returns<Ref_>)),\n Match.exhaustive,\n );\n\nexport const encodeArgsSync = <Ref_ extends Any>(\n ref: Ref_,\n args: Args<Ref_>,\n): unknown =>\n Match.value<Any>(ref).pipe(\n Match.tag(\"Confect\", (confectRef) =>\n Schema.encodeSync(confectRef.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<Any>(ref).pipe(\n Match.tag(\"Confect\", (confectRef) =>\n Schema.decodeUnknownSync(confectRef.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<Any>(ref).pipe(\n Match.tag(\"Confect\", (confectRef) =>\n Schema.encodeSync(confectRef.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<Any>(ref).pipe(\n Match.tag(\"Confect\", (confectRef) =>\n Schema.decodeUnknownSync(confectRef.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 = decodeErrorOption(ref, error.data);\n if (Option.isSome(decoded)) {\n return decoded.value;\n }\n }\n return mapUnknownError(error);\n };\n\nconst errorSchemaOf = (ref: Any): Option.Option<Schema.Codec<any, any>> =>\n Match.value(ref).pipe(\n Match.tag(\"Confect\", (confectRef) => {\n const schemas = [\n ...(\"error\" in confectRef && confectRef.error !== undefined\n ? [confectRef.error]\n : []),\n ...MiddlewareSpec.errorSchemas(confectRef.middlewareSpecs),\n ];\n return schemas.length === 0\n ? Option.none<Schema.Codec<any, any>>()\n : Option.some(\n schemas.length === 1 ? schemas[0]! : Schema.Union(schemas),\n );\n }),\n Match.tag(\"Convex\", () => Option.none<Schema.Codec<any, any>>()),\n Match.exhaustive,\n );\n\n/**\n * Decode `encodedError` against the ref's error schema — the function's\n * declared `error` schema unioned with its covering middlewares' error\n * schemas. Returns `None` if the ref declares no typed error at all (Confect\n * ref without an `error` schema and without failing middleware, or a\n * 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 Option.match(errorSchemaOf(ref), {\n onNone: () => Effect.succeed(Option.none<Error<Ref_>>()),\n onSome: (schema) =>\n Effect.map(\n Schema.decodeUnknownEffect(schema)(encodedError),\n Option.some,\n ) as Effect.Effect<Option.Option<Error<Ref_>>, Schema.SchemaError>,\n });\n\n/**\n * Synchronous counterpart to `decodeError`. Returns `None` when the value is\n * not this ref's typed error — either because the ref declares no `error`\n * schema, or because `encodedError` doesn't match the one it declares.\n *\n * The second case is reachable in normal operation: Convex raises its own\n * `ConvexError`s (an `InvalidCursor` pagination error, for instance), and\n * those never match a user-declared error schema. Callers pair this with a\n * fallback that surfaces the original error, so failing to decode must not\n * throw — a `ParseError` here would replace the real error with an opaque one\n * and lose the only useful diagnostic. Hence the `Option` suffix rather than\n * `Sync`, matching `Schema.decodeUnknownOption`: the sibling `*Sync` helpers\n * in this module all throw on a parse failure, and this one deliberately\n * doesn't.\n */\nexport const decodeErrorOption = <Ref_ extends Any>(\n ref: Ref_,\n encodedError: unknown,\n): Option.Option<Error<Ref_>> =>\n Option.flatMap(\n errorSchemaOf(ref),\n (schema) =>\n Schema.decodeUnknownOption(schema)(encodedError) as Option.Option<\n Error<Ref_>\n >,\n );\n\nconst missingPaginatedProvenanceError = (ref: Any) =>\n new globalThis.Error(\n `Paginated query ref \"${getConvexFunctionName(ref)}\" was not built with ` +\n \"`FunctionSpec.publicPaginatedQuery` (or `FunctionSpec.internalPaginatedQuery`). \" +\n \"Paginated encoding and decoding require the user-args and item schemas \" +\n \"those constructors store. Define the function as, e.g.:\\n\\n\" +\n \" FunctionSpec.publicPaginatedQuery({\\n\" +\n ' name: \"...\",\\n' +\n \" args: () => Schema.Struct({ ... }), // optional; without paginationOpts\\n\" +\n \" item: () => ItemSchema,\\n\" +\n \" })\",\n );\n\nconst paginatedKind = (\n ref: ConfectRef<any, any, any, any, any>,\n): FunctionProvenance.Paginated =>\n Match.value(ref.kind).pipe(\n Match.tag(\"Paginated\", (kind) => kind),\n Match.tag(\"Standard\", () => {\n throw missingPaginatedProvenanceError(ref);\n }),\n Match.exhaustive,\n );\n\n/**\n * Encode the args of a paginated query ref via its user-args schema —\n * `paginationOpts` is excluded, since the pagination protocol fields are\n * managed by the client (e.g. `usePaginatedQuery` from `convex/react`), not by\n * the caller. Requires a ref built with `FunctionSpec.publicPaginatedQuery`\n * (or `internalPaginatedQuery`).\n */\nexport const encodePaginatedQueryArgsSync = <\n Ref_ extends AnyPublicPaginatedQuery,\n>(\n ref: Ref_,\n args: Omit<Args<Ref_>, \"paginationOpts\">,\n): unknown =>\n Match.value<Any>(ref).pipe(\n Match.tag(\"Confect\", (confectRef) =>\n Schema.encodeUnknownSync(paginatedKind(confectRef).userArgs)(args),\n ),\n Match.tag(\"Convex\", () => args),\n Match.exhaustive,\n );\n\n/**\n * Decode a page of a paginated query's results via the ref's item schema.\n * Requires a ref built with `FunctionSpec.publicPaginatedQuery` (or\n * `internalPaginatedQuery`).\n */\nexport const decodePaginationPageSync = <Ref_ extends AnyPublicPaginatedQuery>(\n ref: Ref_,\n encodedPage: unknown,\n): Returns<Ref_>[\"page\"] =>\n Match.value<Any>(ref).pipe(\n Match.tag(\"Confect\", (confectRef) =>\n Schema.decodeUnknownSync(paginatedKind(confectRef).page)(encodedPage),\n ),\n Match.tag(\"Convex\", () => encodedPage),\n Match.exhaustive,\n ) as Returns<Ref_>[\"page\"];\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 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 = decodeErrorOption(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\n const encodedArgs = yield* encodeArgs(ref, args);\n const encodedReturns = yield* invoke(encodedArgs);\n return yield* decodeReturns(ref, encodedReturns);\n });\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuQA,MAAa,QAMX,yBACA,cACA,uBAAwE,CAAC,MACrC;CACpC,MAAM,qBAAqB,GAAG,wBAAwB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AW,GAAG,CAAC,CAAC,KACpB,MAAM,IAAI,YAAY,eACpB,OAAO,kBAAkB,cAAc,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,WAAW,CACtE,GACA,MAAM,IAAI,gBAAgB,WAAW,GACrC,MAAM,UACR;;;;;;;;;AAUF,MAAa,gBACX,KACA,MACA,MAIA,oBAEA,OAAO,IAAI,aAAa;CACtB,MAAM,oBAAoB,qBAAqB,GAAG;CAClD,MAAM,UACJ,gBAEA,OAAO,WAAW;EAChB,WAAW,QAAQ,QAAQ,KAAK,mBAAmB,WAAW,CAAC;EAC/D,QAAQ,UAA2B;GACjC,IAAI,cAAc,KAAK,GAAG;IACxB,MAAM,UAAU,kBAAkB,KAAK,MAAM,IAAI;IACjD,IAAI,OAAO,OAAO,OAAO,GACvB,OAAO,QAAQ;GAEnB;GACA,IAAI,oBAAoB,KAAA,GACtB,OAAO,gBAAgB,KAAK;GAE9B,MAAM;EACR;CACF,CAAC;CAGH,MAAM,iBAAiB,OAAO,OAAO,OADV,WAAW,KAAK,IAAI,CACC;CAChD,OAAO,OAAO,cAAc,KAAK,cAAc;AACjD,CAAC"}
package/dist/Refs.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { Types } from "effect";
2
2
  import type * as FunctionSpec from "./FunctionSpec";
3
3
  import type * as GroupSpec from "./GroupSpec";
4
+ import type * as MiddlewareSpec from "./MiddlewareSpec";
4
5
  import * as Ref from "./Ref";
5
6
  import type * as Spec from "./Spec";
6
7
  export type Refs<Spec_ extends Spec.AnyWithProps, Predicate extends Ref.Any = Ref.Any> = Types.Simplify<OmitEmpty<Helper<Spec.Groups<Spec_>, Predicate>>>;
@@ -8,13 +9,17 @@ export interface FromSpec<Spec_ extends Spec.AnyWithProps> {
8
9
  public: Refs<Spec_, Ref.AnyPublic>;
9
10
  internal: Refs<Spec_, Ref.AnyInternal>;
10
11
  }
11
- type GroupRefs<Group extends GroupSpec.AnyWithProps, Predicate extends Ref.Any> = Types.Simplify<OmitEmpty<Helper<GroupSpec.Groups<Group>, Predicate>> & FilteredFunctions<GroupSpec.Functions<Group>, Predicate>>;
12
+ type GroupRefs<Group extends GroupSpec.AnyWithProps, Predicate extends Ref.Any> = Types.Simplify<OmitEmpty<Helper<GroupSpec.Groups<Group>, Predicate>> & FilteredFunctions<GroupSpec.Functions<Group>, Predicate, MiddlewareSpec.Error<GroupSpec.MiddlewareSpecs<Group>>>>;
12
13
  type OmitEmpty<T> = {
13
14
  [K in keyof T as keyof T[K] extends never ? never : K]: T[K];
14
15
  };
15
16
  type FunctionSpecMatchesPredicate<FunctionSpec_ extends FunctionSpec.AnyWithProps, Predicate extends Ref.Any> = Ref.Ref<FunctionSpec.GetRuntimeAndFunctionType<FunctionSpec_>, FunctionSpec.GetFunctionVisibility<FunctionSpec_>, any, any> extends Predicate ? true : false;
16
- type FilteredFunctions<FunctionSpecs extends FunctionSpec.AnyWithProps, Predicate extends Ref.Any> = {
17
- [Name in FunctionSpec.Name<FunctionSpecs> as FunctionSpec.WithName<FunctionSpecs, Name> extends infer FunctionSpec_ extends FunctionSpec.AnyWithProps ? FunctionSpecMatchesPredicate<FunctionSpec_, Predicate> extends true ? Name : never : never]: FunctionSpec.WithName<FunctionSpecs, Name> extends infer F extends FunctionSpec.AnyWithProps ? Ref.FromFunctionSpec<F> : never;
17
+ type FilteredFunctions<FunctionSpecs extends FunctionSpec.AnyWithProps, Predicate extends Ref.Any, MiddlewareError> = {
18
+ [Name in FunctionSpec.Name<FunctionSpecs> as FunctionSpec.WithName<FunctionSpecs, Name> extends infer FunctionSpec_ extends FunctionSpec.AnyWithProps ? FunctionSpecMatchesPredicate<FunctionSpec_, Predicate> extends true ? Name : never : never]: FunctionSpec.WithName<FunctionSpecs, Name> extends infer F extends FunctionSpec.AnyWithProps ? Ref.FromFunctionSpec<F, F extends {
19
+ readonly functionProvenance: {
20
+ readonly _tag: "Confect";
21
+ };
22
+ } ? MiddlewareError | MiddlewareSpec.Error<FunctionSpec.MiddlewareSpecs<F>> : never> : never;
18
23
  };
19
24
  type Helper<Groups extends GroupSpec.AnyWithProps, Predicate extends Ref.Any> = {
20
25
  [GroupName in GroupSpec.Name<Groups>]: GroupSpec.WithName<Groups, GroupName> extends infer Group extends GroupSpec.AnyWithProps ? GroupRefs<Group, Predicate> : never;
@@ -1 +1 @@
1
- {"version":3,"file":"Refs.d.ts","sourceRoot":"","sources":["../src/Refs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAIpC,OAAO,KAAK,KAAK,YAAY,MAAM,gBAAgB,CAAC;AACpD,OAAO,KAAK,KAAK,SAAS,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;AAC7B,OAAO,KAAK,KAAK,IAAI,MAAM,QAAQ,CAAC;AAEpC,MAAM,MAAM,IAAI,CACd,KAAK,SAAS,IAAI,CAAC,YAAY,EAC/B,SAAS,SAAS,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,GAAG,IACjC,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;AAErE,MAAM,WAAW,QAAQ,CAAC,KAAK,SAAS,IAAI,CAAC,YAAY;IACvD,MAAM,EAAE,IAAI,CAAC,KAAK,EAAE,GAAG,CAAC,SAAS,CAAC,CAAC;IACnC,QAAQ,EAAE,IAAI,CAAC,KAAK,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC;CACxC;AAED,KAAK,SAAS,CACZ,KAAK,SAAS,SAAS,CAAC,YAAY,EACpC,SAAS,SAAS,GAAG,CAAC,GAAG,IACvB,KAAK,CAAC,QAAQ,CAChB,SAAS,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,SAAS,CAAC,CAAC,GACnD,iBAAiB,CAAC,SAAS,CAAC,SAAS,CAAC,KA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,GACf,cAAc,CAAC,KAAK,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,GACzD,KAAK,CACV,GACD,KAAK;CACV,CAAC;AAEF,KAAK,MAAM,CACT,MAAM,SAAS,SAAS,CAAC,YAAY,EACrC,SAAS,SAAS,GAAG,CAAC,GAAG,IACvB;KACD,SAAS,IAAI,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC,QAAQ,CACvD,MAAM,EACN,SAAS,CACV,SAAS,MAAM,KAAK,SAAS,SAAS,CAAC,YAAY,GAChD,SAAS,CAAC,KAAK,EAAE,SAAS,CAAC,GAC3B,KAAK;CACV,CAAC;AAQF,eAAO,MAAM,IAAI,GAAI,KAAK,SAAS,IAAI,CAAC,YAAY,QAC5C,KAAK,KACV,QAAQ,CAAC,KAAK,CAMhB,CAAC"}
package/dist/Refs.js CHANGED
@@ -12,12 +12,12 @@ const make = (spec) => {
12
12
  internal: refs
13
13
  };
14
14
  };
15
- const makeHelper = (groups, functionNamespace = Option.none()) => pipe(groups, Record.map((group, name) => {
16
- const currentFunctionNamespace = Option.match(functionNamespace, {
15
+ const makeHelper = (groups, convexFunctionNamespace = Option.none()) => pipe(groups, Record.map((group, name) => {
16
+ const currentConvexFunctionNamespace = Option.match(convexFunctionNamespace, {
17
17
  onNone: () => name,
18
18
  onSome: (parentNamespace) => `${parentNamespace}/${name}`
19
19
  });
20
- return Record.union(makeHelper(group.groups, Option.some(currentFunctionNamespace)), Record.map(group.functions, (function_) => make$1(currentFunctionNamespace, function_)), (_subGroup, _function) => {
20
+ return Record.union(makeHelper(group.groups, Option.some(currentConvexFunctionNamespace)), Record.map(group.functions, (function_) => make$1(currentConvexFunctionNamespace, function_, group.middlewareSpecs)), (_subGroup, _function) => {
21
21
  throw new Error(`Group and function at same level have same name ('${getConvexFunctionName(_function)}')`);
22
22
  });
23
23
  }));
package/dist/Refs.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Refs.js","names":["Ref.make","Ref.getConvexFunctionName"],"sources":["../src/Refs.ts"],"sourcesContent":["import type { Types } from \"effect\";\nimport { pipe } from \"effect/Function\";\nimport * as Option from \"effect/Option\";\nimport * as Record from \"effect/Record\";\nimport type * as FunctionSpec from \"./FunctionSpec\";\nimport type * as GroupSpec from \"./GroupSpec\";\nimport * as Ref from \"./Ref\";\nimport type * as Spec from \"./Spec\";\n\nexport type Refs<\n Spec_ extends Spec.AnyWithProps,\n Predicate extends Ref.Any = Ref.Any,\n> = Types.Simplify<OmitEmpty<Helper<Spec.Groups<Spec_>, Predicate>>>;\n\nexport interface FromSpec<Spec_ extends Spec.AnyWithProps> {\n public: Refs<Spec_, Ref.AnyPublic>;\n internal: Refs<Spec_, Ref.AnyInternal>;\n}\n\ntype GroupRefs<\n Group extends GroupSpec.AnyWithProps,\n Predicate extends Ref.Any,\n> = Types.Simplify<\n OmitEmpty<Helper<GroupSpec.Groups<Group>, Predicate>> &\n FilteredFunctions<GroupSpec.Functions<Group>, Predicate>\n>;\n\ntype OmitEmpty<T> = {\n [K in keyof T as keyof T[K] extends never ? never : K]: T[K];\n};\n\ntype FunctionSpecMatchesPredicate<\n FunctionSpec_ extends FunctionSpec.AnyWithProps,\n Predicate extends Ref.Any,\n> =\n Ref.Ref<\n FunctionSpec.GetRuntimeAndFunctionType<FunctionSpec_>,\n FunctionSpec.GetFunctionVisibility<FunctionSpec_>,\n any,\n any\n > extends Predicate\n ? true\n : false;\n\ntype FilteredFunctions<\n FunctionSpecs extends FunctionSpec.AnyWithProps,\n Predicate extends Ref.Any,\n> = {\n [Name in FunctionSpec.Name<FunctionSpecs> as FunctionSpec.WithName<\n FunctionSpecs,\n Name\n > extends infer FunctionSpec_ extends FunctionSpec.AnyWithProps\n ? FunctionSpecMatchesPredicate<FunctionSpec_, Predicate> extends true\n ? Name\n : never\n : never]: FunctionSpec.WithName<FunctionSpecs, Name> extends infer F extends\n FunctionSpec.AnyWithProps\n ? Ref.FromFunctionSpec<F>\n : never;\n};\n\ntype Helper<\n Groups extends GroupSpec.AnyWithProps,\n Predicate extends Ref.Any,\n> = {\n [GroupName in GroupSpec.Name<Groups>]: GroupSpec.WithName<\n Groups,\n GroupName\n > extends infer Group extends GroupSpec.AnyWithProps\n ? GroupRefs<Group, Predicate>\n : never;\n};\n\ntype Any =\n | {\n readonly [key: string]: Any;\n }\n | Ref.Any;\n\nexport const make = <Spec_ extends Spec.AnyWithProps>(\n spec: Spec_,\n): FromSpec<Spec_> => {\n const refs = makeHelper(spec.groups);\n return {\n public: refs as Refs<Spec_, Ref.AnyPublic>,\n internal: refs as Refs<Spec_, Ref.AnyInternal>,\n };\n};\n\nconst makeHelper = (\n groups: Record.ReadonlyRecord<string, GroupSpec.Any>,\n functionNamespace: Option.Option<string> = Option.none(),\n): Any =>\n pipe(\n groups as Record.ReadonlyRecord<string, GroupSpec.AnyWithProps>,\n Record.map((group, name) => {\n const currentFunctionNamespace = Option.match(functionNamespace, {\n onNone: () => name,\n onSome: (parentNamespace) => `${parentNamespace}/${name}`,\n });\n\n return Record.union(\n makeHelper(group.groups, Option.some(currentFunctionNamespace)),\n Record.map(group.functions, (function_) =>\n Ref.make(currentFunctionNamespace, function_),\n ),\n (_subGroup, _function) => {\n throw new Error(\n `Group and function at same level have same name ('${Ref.getConvexFunctionName(_function)}')`,\n );\n },\n );\n }),\n );\n"],"mappings":";;;;;;;AA+EA,MAAa,QACX,SACoB;CACpB,MAAM,OAAO,WAAW,KAAK,MAAM;CACnC,OAAO;EACL,QAAQ;EACR,UAAU;CACZ;AACF;AAEA,MAAM,cACJ,QACA,oBAA2C,OAAO,KAAK,MAEvD,KACE,QACA,OAAO,KAAK,OAAO,SAAS;CAC1B,MAAM,2BAA2B,OAAO,MAAM,mBAAmB;EAC/D,cAAc;EACd,SAAS,oBAAoB,GAAG,gBAAgB,GAAG;CACrD,CAAC;CAED,OAAO,OAAO,MACZ,WAAW,MAAM,QAAQ,OAAO,KAAK,wBAAwB,CAAC,GAC9D,OAAO,IAAI,MAAM,YAAY,cAC3BA,OAAS,0BAA0B,SAAS,CAC9C,IACC,WAAW,cAAc;EACxB,MAAM,IAAI,MACR,qDAAqDC,sBAA0B,SAAS,EAAE,GAC5F;CACF,CACF;AACF,CAAC,CACH"}
1
+ {"version":3,"file":"Refs.js","names":["Ref.make","Ref.getConvexFunctionName"],"sources":["../src/Refs.ts"],"sourcesContent":["import type { Types } from \"effect\";\nimport { pipe } from \"effect/Function\";\nimport * as Option from \"effect/Option\";\nimport * as Record from \"effect/Record\";\nimport type * as FunctionSpec from \"./FunctionSpec\";\nimport type * as GroupSpec from \"./GroupSpec\";\nimport type * as MiddlewareSpec from \"./MiddlewareSpec\";\nimport * as Ref from \"./Ref\";\nimport type * as Spec from \"./Spec\";\n\nexport type Refs<\n Spec_ extends Spec.AnyWithProps,\n Predicate extends Ref.Any = Ref.Any,\n> = Types.Simplify<OmitEmpty<Helper<Spec.Groups<Spec_>, Predicate>>>;\n\nexport interface FromSpec<Spec_ extends Spec.AnyWithProps> {\n public: Refs<Spec_, Ref.AnyPublic>;\n internal: Refs<Spec_, Ref.AnyInternal>;\n}\n\ntype GroupRefs<\n Group extends GroupSpec.AnyWithProps,\n Predicate extends Ref.Any,\n> = Types.Simplify<\n OmitEmpty<Helper<GroupSpec.Groups<Group>, Predicate>> &\n FilteredFunctions<\n GroupSpec.Functions<Group>,\n Predicate,\n MiddlewareSpec.Error<GroupSpec.MiddlewareSpecs<Group>>\n >\n>;\n\ntype OmitEmpty<T> = {\n [K in keyof T as keyof T[K] extends never ? never : K]: T[K];\n};\n\ntype FunctionSpecMatchesPredicate<\n FunctionSpec_ extends FunctionSpec.AnyWithProps,\n Predicate extends Ref.Any,\n> =\n Ref.Ref<\n FunctionSpec.GetRuntimeAndFunctionType<FunctionSpec_>,\n FunctionSpec.GetFunctionVisibility<FunctionSpec_>,\n any,\n any\n > extends Predicate\n ? true\n : false;\n\ntype FilteredFunctions<\n FunctionSpecs extends FunctionSpec.AnyWithProps,\n Predicate extends Ref.Any,\n MiddlewareError,\n> = {\n [\n Name in FunctionSpec.Name<FunctionSpecs> as FunctionSpec.WithName<\n FunctionSpecs,\n Name\n > extends infer FunctionSpec_ extends FunctionSpec.AnyWithProps\n ? FunctionSpecMatchesPredicate<FunctionSpec_, Predicate> extends true\n ? Name\n : never\n : never\n ]: FunctionSpec.WithName<FunctionSpecs, Name> extends infer F extends\n FunctionSpec.AnyWithProps\n ? Ref.FromFunctionSpec<\n F,\n F extends {\n readonly functionProvenance: { readonly _tag: \"Confect\" };\n }\n ?\n | MiddlewareError\n | MiddlewareSpec.Error<FunctionSpec.MiddlewareSpecs<F>>\n : never\n >\n : never;\n};\n\ntype Helper<\n Groups extends GroupSpec.AnyWithProps,\n Predicate extends Ref.Any,\n> = {\n [GroupName in GroupSpec.Name<Groups>]: GroupSpec.WithName<\n Groups,\n GroupName\n > extends infer Group extends GroupSpec.AnyWithProps\n ? GroupRefs<Group, Predicate>\n : never;\n};\n\ntype Any =\n | {\n readonly [key: string]: Any;\n }\n | Ref.Any;\n\nexport const make = <Spec_ extends Spec.AnyWithProps>(\n spec: Spec_,\n): FromSpec<Spec_> => {\n const refs = makeHelper(spec.groups);\n return {\n public: refs as Refs<Spec_, Ref.AnyPublic>,\n internal: refs as Refs<Spec_, Ref.AnyInternal>,\n };\n};\n\nconst makeHelper = (\n groups: Record.ReadonlyRecord<string, GroupSpec.Any>,\n convexFunctionNamespace: Option.Option<string> = Option.none(),\n): Any =>\n pipe(\n groups as Record.ReadonlyRecord<string, GroupSpec.AnyWithProps>,\n Record.map((group, name) => {\n const currentConvexFunctionNamespace = Option.match(\n convexFunctionNamespace,\n {\n onNone: () => name,\n onSome: (parentNamespace) => `${parentNamespace}/${name}`,\n },\n );\n\n return Record.union(\n makeHelper(group.groups, Option.some(currentConvexFunctionNamespace)),\n Record.map(group.functions, (function_) =>\n Ref.make(\n currentConvexFunctionNamespace,\n function_,\n group.middlewareSpecs,\n ),\n ),\n (_subGroup, _function) => {\n throw new Error(\n `Group and function at same level have same name ('${Ref.getConvexFunctionName(_function)}')`,\n );\n },\n );\n }),\n );\n"],"mappings":";;;;;;;AAgGA,MAAa,QACX,SACoB;CACpB,MAAM,OAAO,WAAW,KAAK,MAAM;CACnC,OAAO;EACL,QAAQ;EACR,UAAU;CACZ;AACF;AAEA,MAAM,cACJ,QACA,0BAAiD,OAAO,KAAK,MAE7D,KACE,QACA,OAAO,KAAK,OAAO,SAAS;CAC1B,MAAM,iCAAiC,OAAO,MAC5C,yBACA;EACE,cAAc;EACd,SAAS,oBAAoB,GAAG,gBAAgB,GAAG;CACrD,CACF;CAEA,OAAO,OAAO,MACZ,WAAW,MAAM,QAAQ,OAAO,KAAK,8BAA8B,CAAC,GACpE,OAAO,IAAI,MAAM,YAAY,cAC3BA,OACE,gCACA,WACA,MAAM,eACR,CACF,IACC,WAAW,cAAc;EACxB,MAAM,IAAI,MACR,qDAAqDC,sBAA0B,SAAS,EAAE,GAC5F;CACF,CACF;AACF,CAAC,CACH"}