@confect/core 10.0.0-next.9 → 10.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/CHANGELOG.md +964 -47
  2. package/README.md +3 -1
  3. package/dist/FunctionProvenance.d.ts +166 -68
  4. package/dist/FunctionProvenance.d.ts.map +1 -1
  5. package/dist/FunctionProvenance.js +55 -13
  6. package/dist/FunctionProvenance.js.map +1 -1
  7. package/dist/FunctionSpec.d.ts +320 -138
  8. package/dist/FunctionSpec.d.ts.map +1 -1
  9. package/dist/FunctionSpec.js +56 -13
  10. package/dist/FunctionSpec.js.map +1 -1
  11. package/dist/GenericId.d.ts.map +1 -1
  12. package/dist/GenericId.js +1 -1
  13. package/dist/GroupPath.d.ts +6 -10
  14. package/dist/GroupPath.d.ts.map +1 -1
  15. package/dist/GroupPath.js.map +1 -1
  16. package/dist/GroupSpec.d.ts +25 -12
  17. package/dist/GroupSpec.d.ts.map +1 -1
  18. package/dist/GroupSpec.js +51 -14
  19. package/dist/GroupSpec.js.map +1 -1
  20. package/dist/Identifier.d.ts +6 -5
  21. package/dist/Identifier.d.ts.map +1 -1
  22. package/dist/Identifier.js +6 -5
  23. package/dist/Identifier.js.map +1 -1
  24. package/dist/Lazy.d.ts +11 -14
  25. package/dist/Lazy.d.ts.map +1 -1
  26. package/dist/Lazy.js +11 -14
  27. package/dist/Lazy.js.map +1 -1
  28. package/dist/MiddlewareAttachment.d.ts +171 -0
  29. package/dist/MiddlewareAttachment.d.ts.map +1 -0
  30. package/dist/MiddlewareAttachment.js +48 -0
  31. package/dist/MiddlewareAttachment.js.map +1 -0
  32. package/dist/MiddlewareSpec.d.ts +198 -0
  33. package/dist/MiddlewareSpec.d.ts.map +1 -0
  34. package/dist/MiddlewareSpec.js +60 -0
  35. package/dist/MiddlewareSpec.js.map +1 -0
  36. package/dist/PaginationError.d.ts +20 -0
  37. package/dist/PaginationError.d.ts.map +1 -0
  38. package/dist/PaginationError.js +31 -0
  39. package/dist/PaginationError.js.map +1 -0
  40. package/dist/PaginationOptions.d.ts +23 -0
  41. package/dist/PaginationOptions.d.ts.map +1 -0
  42. package/dist/PaginationOptions.js +29 -0
  43. package/dist/PaginationOptions.js.map +1 -0
  44. package/dist/PaginationResult.d.ts +1 -0
  45. package/dist/PaginationResult.d.ts.map +1 -1
  46. package/dist/PaginationResult.js.map +1 -1
  47. package/dist/Ref.d.ts +135 -47
  48. package/dist/Ref.d.ts.map +1 -1
  49. package/dist/Ref.js +104 -46
  50. package/dist/Ref.js.map +1 -1
  51. package/dist/Refs.d.ts +10 -5
  52. package/dist/Refs.d.ts.map +1 -1
  53. package/dist/Refs.js +5 -4
  54. package/dist/Refs.js.map +1 -1
  55. package/dist/SchemaToValidator.d.ts +99 -0
  56. package/dist/SchemaToValidator.d.ts.map +1 -0
  57. package/dist/SchemaToValidator.js +158 -0
  58. package/dist/SchemaToValidator.js.map +1 -0
  59. package/dist/Spec.d.ts +16 -12
  60. package/dist/Spec.d.ts.map +1 -1
  61. package/dist/Spec.js +14 -9
  62. package/dist/Spec.js.map +1 -1
  63. package/dist/SystemFields.d.ts +20 -19
  64. package/dist/SystemFields.d.ts.map +1 -1
  65. package/dist/SystemFields.js +22 -21
  66. package/dist/SystemFields.js.map +1 -1
  67. package/dist/Table.d.ts +75 -0
  68. package/dist/Table.d.ts.map +1 -0
  69. package/dist/Table.js +77 -0
  70. package/dist/Table.js.map +1 -0
  71. package/dist/Types.d.ts +8 -2
  72. package/dist/Types.d.ts.map +1 -1
  73. package/dist/Types.js.map +1 -1
  74. package/dist/UserIdentity.d.ts.map +1 -1
  75. package/dist/index.d.ts +6 -1
  76. package/dist/index.d.ts.map +1 -1
  77. package/dist/index.js +9 -4
  78. package/package.json +17 -15
  79. package/src/FunctionProvenance.ts +197 -34
  80. package/src/FunctionSpec.ts +332 -86
  81. package/src/GroupPath.ts +6 -12
  82. package/src/GroupSpec.ts +184 -25
  83. package/src/Identifier.ts +6 -5
  84. package/src/Lazy.ts +11 -14
  85. package/src/MiddlewareAttachment.ts +106 -0
  86. package/src/MiddlewareSpec.ts +392 -0
  87. package/src/PaginationError.ts +78 -0
  88. package/src/PaginationOptions.ts +23 -0
  89. package/src/PaginationResult.ts +4 -0
  90. package/src/Ref.ts +468 -236
  91. package/src/Refs.ts +43 -18
  92. package/src/SchemaToValidator.ts +612 -0
  93. package/src/Spec.ts +50 -39
  94. package/src/SystemFields.ts +40 -42
  95. package/src/Table.ts +427 -0
  96. package/src/Types.ts +9 -3
  97. package/src/index.ts +6 -1
  98. package/dist/Registry.d.ts +0 -24
  99. package/dist/Registry.d.ts.map +0 -1
  100. package/dist/Registry.js +0 -19
  101. package/dist/Registry.js.map +0 -1
  102. package/dist/tsconfig.src.tsbuildinfo +0 -1
  103. package/src/Registry.ts +0 -30
package/dist/Ref.js CHANGED
@@ -1,82 +1,144 @@
1
1
  import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
- import * as Option from "effect/Option";
2
+ import { defineProperty } from "./Lazy.js";
3
+ import { errorSchemas } from "./MiddlewareSpec.js";
3
4
  import * as Schema from "effect/Schema";
4
- import { makeFunctionReference } from "convex/server";
5
+ import * as Option from "effect/Option";
5
6
  import { ConvexError } from "convex/values";
6
- import * as Effect from "effect/Effect";
7
7
  import * as Match from "effect/Match";
8
+ import { makeFunctionReference } from "convex/server";
9
+ import * as Effect from "effect/Effect";
8
10
  //#region src/Ref.ts
9
11
  var Ref_exports = /* @__PURE__ */ __exportAll({
10
12
  decodeArgsSync: () => decodeArgsSync,
11
13
  decodeError: () => decodeError,
14
+ decodeErrorOption: () => decodeErrorOption,
12
15
  decodeErrorOrElse: () => decodeErrorOrElse,
13
- decodeErrorSync: () => decodeErrorSync,
16
+ decodePaginationPageSync: () => decodePaginationPageSync,
14
17
  decodeReturns: () => decodeReturns,
15
18
  decodeReturnsSync: () => decodeReturnsSync,
16
19
  encodeArgs: () => encodeArgs,
17
20
  encodeArgsSync: () => encodeArgsSync,
21
+ encodePaginatedQueryArgsSync: () => encodePaginatedQueryArgsSync,
18
22
  encodeReturnsSync: () => encodeReturnsSync,
19
23
  getConvexFunctionName: () => getConvexFunctionName,
20
24
  getFunctionReference: () => getFunctionReference,
21
25
  hasErrorSchema: () => hasErrorSchema,
22
26
  isConvexError: () => isConvexError,
23
27
  make: () => make,
24
- maybeDecodeErrorSync: () => maybeDecodeErrorSync,
25
28
  runWithCodec: () => runWithCodec
26
29
  });
27
- const make = (functionNamespace, functionSpec) => ({
28
- functionSpec,
29
- functionNamespace
30
- });
31
- const getConvexFunctionName = (ref) => `${ref.functionNamespace}:${ref.functionSpec.name}`;
30
+ const make = (convexFunctionNamespace, functionSpec, groupMiddlewareAttachments = []) => {
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
+ middlewareAttachments: [...groupMiddlewareAttachments, ...functionSpec.middlewareAttachments],
41
+ get middlewareSpecs() {
42
+ return this.middlewareAttachments.map(({ spec }) => spec);
43
+ }
44
+ };
45
+ defineProperty(ref, "args", () => provenance.args);
46
+ defineProperty(ref, "returns", () => provenance.returns);
47
+ if ("error" in provenance) defineProperty(ref, "error", () => provenance.error);
48
+ return ref;
49
+ }), Match.exhaustive);
50
+ };
51
+ const getConvexFunctionName = (ref) => ref.convexFunctionName;
32
52
  const functionReferenceCache = /* @__PURE__ */ new Map();
33
53
  const getFunctionReference = (ref) => {
34
- const functionName = getConvexFunctionName(ref);
35
- const cached = functionReferenceCache.get(functionName);
54
+ const convexFunctionName = getConvexFunctionName(ref);
55
+ const cached = functionReferenceCache.get(convexFunctionName);
36
56
  if (cached !== void 0) return cached;
37
- const functionReference = makeFunctionReference(functionName);
38
- functionReferenceCache.set(functionName, functionReference);
57
+ const functionReference = makeFunctionReference(convexFunctionName);
58
+ functionReferenceCache.set(convexFunctionName, functionReference);
39
59
  return functionReference;
40
60
  };
41
- const hasErrorSchema = (ref) => Match.value(ref.functionSpec.functionProvenance).pipe(Match.tag("Confect", (confectFunctionProvenance) => "error" in confectFunctionProvenance), Match.tag("Convex", () => false), Match.exhaustive);
42
- 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);
43
- 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);
44
- 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);
45
- 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);
46
- 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);
47
- 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);
61
+ 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);
62
+ 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);
63
+ 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);
64
+ const encodeArgsSync = (ref, args) => Match.value(ref).pipe(Match.tag("Confect", (confectRef) => Schema.encodeSync(confectRef.args)(args)), Match.tag("Convex", () => args), Match.exhaustive);
65
+ const decodeArgsSync = (ref, encodedArgs) => Match.value(ref).pipe(Match.tag("Confect", (confectRef) => Schema.decodeUnknownSync(confectRef.args)(encodedArgs)), Match.tag("Convex", () => encodedArgs), Match.exhaustive);
66
+ const encodeReturnsSync = (ref, returns) => Match.value(ref).pipe(Match.tag("Confect", (confectRef) => Schema.encodeSync(confectRef.returns)(returns)), Match.tag("Convex", () => returns), Match.exhaustive);
67
+ const decodeReturnsSync = (ref, encodedReturns) => Match.value(ref).pipe(Match.tag("Confect", (confectRef) => Schema.decodeUnknownSync(confectRef.returns)(encodedReturns)), Match.tag("Convex", () => encodedReturns), Match.exhaustive);
48
68
  const ConvexErrorIdentifier = Symbol.for("ConvexError");
49
69
  const isConvexError = (error) => error instanceof ConvexError || typeof error === "object" && error !== null && ConvexErrorIdentifier in error;
50
70
  /**
51
71
  * Build a callback-style handler that decodes the ref's typed error from a
52
72
  * caught `ConvexError`, or else forwards the value to `mapUnknownError`. The
53
- * fallback is also invoked when the input *is* a `ConvexError` but the ref
54
- * doesn't declare a typed-error schema—by definition such a value falls
55
- * outside the ref's error contract. Useful when adapting non-Effect APIs (e.g.
56
- * emitter callbacks for streamed subscriptions) to the same error semantics
57
- * that `runWithCodec` provides.
73
+ * fallback is also invoked when the input _is_ a `ConvexError` but the ref
74
+ * doesn't declare a typed-error schema—by definition such a value falls outside
75
+ * the ref's error contract. Useful when adapting non-Effect APIs (e.g. emitter
76
+ * callbacks for streamed subscriptions) to the same error semantics that
77
+ * `runWithCodec` provides.
58
78
  */
59
79
  const decodeErrorOrElse = (ref, mapUnknownError) => (error) => {
60
80
  if (isConvexError(error)) {
61
- const decoded = decodeErrorSync(ref, error.data);
81
+ const decoded = decodeErrorOption(ref, error.data);
62
82
  if (Option.isSome(decoded)) return decoded.value;
63
83
  }
64
84
  return mapUnknownError(error);
65
85
  };
86
+ const errorSchemaOf = (ref) => Match.value(ref).pipe(Match.tag("Confect", (confectRef) => {
87
+ const schemas = [..."error" in confectRef && confectRef.error !== void 0 ? [confectRef.error] : [], ...errorSchemas(confectRef.middlewareSpecs)];
88
+ return schemas.length === 0 ? Option.none() : Option.some(schemas.length === 1 ? schemas[0] : Schema.Union(schemas));
89
+ }), Match.tag("Convex", () => Option.none()), Match.exhaustive);
90
+ /**
91
+ * Decode `encodedError` against the ref's error schema—the function's declared
92
+ * `error` schema unioned with its covering middlewares' error schemas. Returns
93
+ * `None` if the ref declares no typed error at all (Confect ref without an
94
+ * `error` schema and without failing middleware, or a Convex-provenance ref)—by
95
+ * definition there's nothing to decode the value into, and the caller is
96
+ * responsible for deciding what to do (typically: surface the original value as
97
+ * a defect).
98
+ */
99
+ const decodeError = (ref, encodedError) => Option.match(errorSchemaOf(ref), {
100
+ onNone: () => Effect.succeed(Option.none()),
101
+ onSome: (schema) => Effect.asSome(Schema.decodeUnknownEffect(schema)(encodedError))
102
+ });
103
+ /**
104
+ * Synchronous counterpart to `decodeError`. Returns `None` when the value is
105
+ * not this ref's typed error—either because the ref declares no `error` schema,
106
+ * or because `encodedError` doesn't match the one it declares.
107
+ *
108
+ * The second case is reachable in normal operation: Convex raises its own
109
+ * `ConvexError`s (an `InvalidCursor` pagination error, for instance), and those
110
+ * never match a user-declared error schema. Callers pair this with a fallback
111
+ * that surfaces the original error, so failing to decode must not throw—a
112
+ * `ParseError` here would replace the real error with an opaque one and lose
113
+ * the only useful diagnostic. Hence the `Option` suffix rather than `Sync`,
114
+ * matching `Schema.decodeUnknownOption`: the sibling `*Sync` helpers in this
115
+ * module all throw on a parse failure, and this one deliberately doesn't.
116
+ */
117
+ const decodeErrorOption = (ref, encodedError) => Option.flatMap(errorSchemaOf(ref), (schema) => Schema.decodeUnknownOption(schema)(encodedError));
118
+ 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.:
119
+
120
+ FunctionSpec.publicPaginatedQuery({
121
+ name: "...",
122
+ args: () => ({ ... }), // optional; without paginationOpts
123
+ item: () => ItemSchema,
124
+ })`);
125
+ const paginatedKind = (ref) => Match.value(ref.kind).pipe(Match.tag("Paginated", (kind) => kind), Match.tag("Standard", () => {
126
+ throw missingPaginatedProvenanceError(ref);
127
+ }), Match.exhaustive);
66
128
  /**
67
- * Decode `encodedError` against the ref's error schema. Returns `None` if the
68
- * ref doesn't declare a typed error (Confect ref without an `error` schema, or
69
- * a Convex-provenance ref)—by definition there's nothing to decode the value
70
- * into, and the caller is responsible for deciding what to do (typically:
71
- * surface the original value as a defect).
129
+ * Encode the args of a paginated query ref via its user-args
130
+ * schema—`paginationOpts` is excluded, since the pagination protocol fields are
131
+ * managed by the client (e.g. `usePaginatedQuery` from `convex/react`), not by
132
+ * the caller. Requires a ref built with `FunctionSpec.publicPaginatedQuery` (or
133
+ * `internalPaginatedQuery`).
72
134
  */
73
- 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);
135
+ const encodePaginatedQueryArgsSync = (ref, args) => Match.value(ref).pipe(Match.tag("Confect", (confectRef) => Schema.encodeUnknownSync(paginatedKind(confectRef).userArgs)(args)), Match.tag("Convex", () => args), Match.exhaustive);
74
136
  /**
75
- * Synchronous counterpart to `decodeError`. Throws on schema decode failure;
76
- * returns `None` when the ref doesn't declare a typed error.
137
+ * Decode a page of a paginated query's results via the ref's item schema.
138
+ * Requires a ref built with `FunctionSpec.publicPaginatedQuery` (or
139
+ * `internalPaginatedQuery`).
77
140
  */
78
- 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);
79
- 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;
141
+ const decodePaginationPageSync = (ref, encodedPage) => Match.value(ref).pipe(Match.tag("Confect", (confectRef) => Schema.decodeUnknownSync(paginatedKind(confectRef).page)(encodedPage)), Match.tag("Convex", () => encodedPage), Match.exhaustive);
80
142
  /**
81
143
  * Encode args via the ref's args schema, invoke `call`, decode returns via the
82
144
  * ref's returns schema, and translate any thrown `ConvexError` into the ref's
@@ -85,27 +147,23 @@ const maybeDecodeErrorSync = (ref, error) => isConvexError(error) ? Match.value(
85
147
  * `mapUnknownError` to be turned into a typed `E`, or surfaced as a defect when
86
148
  * no handler is provided.
87
149
  */
88
- const runWithCodec = (ref, args, call, mapUnknownError) => Effect.gen(function* () {
150
+ const runWithCodec = Effect.fnUntraced(function* (ref, args, call, mapUnknownError) {
89
151
  const functionReference = getFunctionReference(ref);
90
- const functionProvenance = ref.functionSpec.functionProvenance;
91
152
  const invoke = (encodedArgs) => Effect.tryPromise({
92
153
  try: () => Promise.resolve(call(functionReference, encodedArgs)),
93
154
  catch: (error) => {
94
155
  if (isConvexError(error)) {
95
- const decoded = decodeErrorSync(ref, error.data);
156
+ const decoded = decodeErrorOption(ref, error.data);
96
157
  if (Option.isSome(decoded)) return decoded.value;
97
158
  }
98
159
  if (mapUnknownError !== void 0) return mapUnknownError(error);
99
160
  throw error;
100
161
  }
101
162
  });
102
- return yield* Match.value(functionProvenance).pipe(Match.tag("Confect", (confectFunctionProvenance) => Effect.gen(function* () {
103
- const encodedArgs = yield* Schema.encodeEffect(confectFunctionProvenance.args)(args);
104
- const encodedReturns = yield* invoke(encodedArgs);
105
- return yield* Schema.decodeUnknownEffect(confectFunctionProvenance.returns)(encodedReturns);
106
- })), Match.tag("Convex", () => invoke(args)), Match.exhaustive);
163
+ const encodedReturns = yield* invoke(yield* encodeArgs(ref, args));
164
+ return yield* decodeReturns(ref, encodedReturns);
107
165
  });
108
166
  //#endregion
109
- export { Ref_exports, decodeArgsSync, decodeError, decodeErrorOrElse, decodeErrorSync, decodeReturns, decodeReturnsSync, encodeArgs, encodeArgsSync, encodeReturnsSync, getConvexFunctionName, getFunctionReference, hasErrorSchema, isConvexError, make, maybeDecodeErrorSync, runWithCodec };
167
+ export { Ref_exports, decodeArgsSync, decodeError, decodeErrorOption, decodeErrorOrElse, decodePaginationPageSync, decodeReturns, decodeReturnsSync, encodeArgs, encodeArgsSync, encodePaginatedQueryArgsSync, encodeReturnsSync, getConvexFunctionName, getFunctionReference, hasErrorSchema, isConvexError, make, runWithCodec };
110
168
 
111
169
  //# sourceMappingURL=Ref.js.map
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 * 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;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,IAAI,gBAAgB,KAAK,GAC/B,MAAM,UACR;AAEF,MAAa,cACX,KACA,SAEA,MAAM,MAAM,IAAI,aAAa,kBAAkB,CAAC,CAAC,KAC/C,MAAM,IAAI,YAAY,8BACpB,OAAO,aAAa,0BAA0B,IAAI,CAAC,CAAC,IAAI,CAC1D,GACA,MAAM,IAAI,gBAAgB,OAAO,QAAQ,IAAI,CAAC,GAC9C,MAAM,UACR;AAEF,MAAa,iBACX,KACA,YAEA,MAAM,MAAM,IAAI,aAAa,kBAAkB,CAAC,CAAC,KAC/C,MAAM,IAAI,YAAY,8BACpB,OAAO,oBAAoB,0BAA0B,OAAO,CAAC,CAAC,OAAO,CACvE,GACA,MAAM,IAAI,gBAAgB,OAAO,QAAQ,OAAO,CAAC,GACjD,MAAM,UACR;AAEF,MAAa,kBACX,KACA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AM,MAAM,kBAAkB,CAAC,CAAC,KAC5C,MAAM,IAAI,YAAY,8BACpB,OAAO,IAAI,aAAa;EACtB,MAAM,cAAc,OAAO,OAAO,aAChC,0BAA0B,IAC5B,CAAC,CAAC,IAAI;EACN,MAAM,iBAAiB,OAAO,OAAO,WAAW;EAChD,OAAO,OAAO,OAAO,oBACnB,0BAA0B,OAC5B,CAAC,CAAC,cAAc;CAClB,CAAC,CACH,GACA,MAAM,IAAI,gBAAgB,OAAO,IAAI,CAAC,GACtC,MAAM,UACR;AACF,CAAC"}
1
+ {"version":3,"file":"Ref.js","names":["MiddlewareSpec.errorSchemas"],"sources":["../src/Ref.ts"],"sourcesContent":["import type * as MiddlewareAttachment from \"./MiddlewareAttachment\";\nimport type {\n DefaultFunctionArgs,\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_ extends DefaultFunctionArgs,\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 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 errors.\n * 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_ extends DefaultFunctionArgs,\n Returns_,\n Error_ = never,\n> =\n | ConfectRefWithTypes<\n RuntimeAndFunctionType_,\n FunctionVisibility_,\n FunctionProvenance.ArgsFields,\n Args_,\n Returns_,\n Error_\n >\n | ConvexRef<\n RuntimeAndFunctionType_,\n FunctionVisibility_,\n Args_,\n Returns_,\n Error_\n >;\n\nexport type ConfectRef<\n RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility_ extends FunctionVisibility,\n ArgsFields_ extends FunctionProvenance.ArgsFields,\n ReturnsSchema_ extends Schema.Codec<any, any>,\n ErrorSchema_ extends Schema.Codec<any, any> = never,\n MiddlewareError_ = never,\n> = ConfectRefWithTypes<\n RuntimeAndFunctionType_,\n FunctionVisibility_,\n ArgsFields_,\n Schema.Struct.Type<ArgsFields_>,\n ReturnsSchema_[\"Type\"],\n ErrorSchema_[\"Type\"] | MiddlewareError_\n>;\n\n/**\n * Internal form used while mapping a spec to a ref. Supplying the already\n * derived value types avoids repeatedly expanding `Schema.Struct` for every\n * leaf in a generated ref tree; the public `ConfectRef` alias still derives the\n * same values from its fields and schemas.\n */\ninterface ConfectRefWithTypes<\n RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility_ extends FunctionVisibility,\n ArgsFields_ extends FunctionProvenance.ArgsFields,\n Args_ extends DefaultFunctionArgs,\n Returns_,\n Error_,\n> extends Base<\n RuntimeAndFunctionType_,\n FunctionVisibility_,\n Args_,\n Returns_,\n Error_\n> {\n readonly _tag: \"Confect\";\n readonly args: FunctionProvenance.ArgsSchema<ArgsFields_>;\n readonly returns: Schema.Codec<any, any>;\n readonly kind: FunctionProvenance.ConfectKind;\n readonly middlewareSpecs: ReadonlyArray<MiddlewareSpec.AnyMiddlewareSpec>;\n readonly middlewareAttachments: ReadonlyArray<MiddlewareAttachment.MiddlewareAttachment>;\n readonly error?: Schema.Codec<any, any>;\n}\n\nexport interface ConvexRef<\n RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility_ extends FunctionVisibility,\n Args_ extends DefaultFunctionArgs,\n Returns_,\n Error_ = never,\n> extends Base<\n RuntimeAndFunctionType_,\n FunctionVisibility_,\n Args_,\n Returns_,\n Error_\n> {\n readonly _tag: \"Convex\";\n}\n\nexport type Any = Ref<any, any, any, any, any>;\n\n/**\n * Erased Confect-provenance ref used by provenance-specific APIs.\n */\nexport type AnyConfect = Extract<Any, { readonly _tag: \"Confect\" }>;\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 AnyPaginatedQuery = AnyQuery &\n Base<\n RuntimeAndFunctionType.AnyQuery,\n FunctionVisibility,\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 AnyConfectPublicQuery = Extract<AnyPublicQuery, AnyConfect>;\n\nexport type AnyPublicPaginatedQuery = AnyPublicQuery & AnyPaginatedQuery;\n\nexport type AnyConfectPublicPaginatedQuery = AnyConfectPublicQuery &\n AnyPublicPaginatedQuery;\n\nexport type AnyPublicMutation = Ref<\n RuntimeAndFunctionType.AnyMutation,\n \"public\",\n any,\n any,\n any\n>;\n\nexport type AnyConfectPublicMutation = Extract<AnyPublicMutation, AnyConfect>;\n\nexport type AnyPublicAction = Ref<\n RuntimeAndFunctionType.AnyAction,\n \"public\",\n any,\n any,\n any\n>;\n\nexport type AnyConfectPublicAction = Extract<AnyPublicAction, AnyConfect>;\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\n/**\n * The field map captured by a Confect-provenance ref.\n */\nexport type ArgsFields<Ref_> = Ref_ extends {\n readonly _tag: \"Confect\";\n readonly args: {\n readonly fields: infer ArgsFields_ extends FunctionProvenance.ArgsFields;\n };\n}\n ? ArgsFields_\n : never;\n\n/**\n * The assembled args schema carried by a Confect-provenance ref.\n */\nexport type ArgsSchema<Ref_> = Ref_ extends {\n readonly _tag: \"Confect\";\n readonly args: infer ArgsSchema_ extends FunctionProvenance.AnyArgsSchema;\n}\n ? ArgsSchema_\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.ArgsFields<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 ArgsFields_ extends FunctionProvenance.ArgsFields,\n Args_ extends DefaultFunctionArgs,\n Returns_,\n Error_,\n> =\n FunctionSpec_ extends FunctionSpec.WithFunctionProvenance<\n FunctionSpec_,\n FunctionProvenance.AnyConvex\n >\n ? ConvexRef<\n RuntimeAndFunctionType_,\n FunctionVisibility_,\n Args_ extends DefaultFunctionArgs ? Args_ : never,\n Returns_,\n never\n >\n : FunctionSpec_ extends FunctionSpec.WithFunctionProvenance<\n FunctionSpec_,\n FunctionProvenance.AnyConfect\n >\n ? ConfectRefWithTypes<\n RuntimeAndFunctionType_,\n FunctionVisibility_,\n ArgsFields_,\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 groupMiddlewareAttachments: ReadonlyArray<MiddlewareAttachment.MiddlewareAttachment> = [],\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 middlewareAttachments: [\n ...groupMiddlewareAttachments,\n ...functionSpec.middlewareAttachments,\n ],\n get middlewareSpecs() {\n return this.middlewareAttachments.map(({ spec }) => spec);\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 outside\n * the ref's error contract. Useful when adapting non-Effect APIs (e.g. emitter\n * callbacks for streamed subscriptions) to the same error semantics that\n * `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 declared\n * `error` schema unioned with its covering middlewares' error schemas. Returns\n * `None` if the ref declares no typed error at all (Confect ref without an\n * `error` schema and without failing middleware, or a Convex-provenance ref)—by\n * definition there's nothing to decode the value into, and the caller is\n * responsible for deciding what to do (typically: surface the original value as\n * 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.asSome(\n Schema.decodeUnknownEffect(schema)(encodedError),\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` schema,\n * 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 those\n * never match a user-declared error schema. Callers pair this with a fallback\n * that surfaces the original error, so failing to decode must not throw—a\n * `ParseError` here would replace the real error with an opaque one and lose\n * the only useful diagnostic. Hence the `Option` suffix rather than `Sync`,\n * matching `Schema.decodeUnknownOption`: the sibling `*Sync` helpers in this\n * module all throw on a parse failure, and this one deliberately 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: () => ({ ... }), // optional; without paginationOpts\\n\" +\n \" item: () => ItemSchema,\\n\" +\n \" })\",\n );\n\nconst paginatedKind = (ref: AnyConfect): 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\n * schema—`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` (or\n * `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 = Effect.fnUntraced(function* <\n Ref_ extends Any,\n E = never,\n>(\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.fn.Return<Returns<Ref_>, E | Error<Ref_> | Schema.SchemaError> {\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoUA,MAAa,QAMX,yBACA,cACA,6BAAuF,CAAC,MACpD;CACpC,MAAM,qBAAqB,GAAG,wBAAwB,GAAG,aAAa;CAEtE,OAAO,MAAM,MAAM,aAAa,kBAAkB,CAAC,CAAC,KAClD,MAAM,IACJ,iBAEG;EACC,MAAM;EACN;CACF,EACJ,GACA,MAAM,IAAI,YAAY,eAAoB;EACxC,MAAM,MAAM;GACV,MAAM;GACN;GACA,MAAM,WAAW;GACjB,uBAAuB,CACrB,GAAG,4BACH,GAAG,aAAa,qBAClB;GACA,IAAI,kBAAkB;IACpB,OAAO,KAAK,sBAAsB,KAAK,EAAE,WAAW,IAAI;GAC1D;EACF;EAEA,eAAoB,KAAK,cAAc,WAAW,IAAI;EACtD,eAAoB,KAAK,iBAAiB,WAAW,OAAO;EAC5D,IAAI,WAAW,YACb,eAAoB,KAAK,eAAe,WAAW,KAAK;EAG1D,OAAO;CACT,CAAC,GACD,MAAM,UACR;AACF;AAEA,MAAa,yBAAyB,QACpC,IAAI;AAEN,MAAM,yCAAyB,IAAI,IAAoC;AAEvE,MAAa,wBACX,QAC4B;CAC5B,MAAM,qBAAqB,sBAAsB,GAAG;CAEpD,MAAM,SAAS,u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,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,20 +1,25 @@
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
- import type * as Spec from "./Spec";
6
+ import * 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>>>;
7
8
  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
- 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;
16
+ type FunctionSpecMatchesPredicate<FunctionSpec_ extends FunctionSpec.AnyWithProps, Predicate extends Ref.Any> = Ref.Ref<FunctionSpec.GetRuntimeAndFunctionType<FunctionSpec_>, FunctionSpec.GetFunctionVisibility<FunctionSpec_>, any, any, any> extends Predicate ? true : false;
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,SA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C,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
@@ -1,23 +1,24 @@
1
1
  import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
2
  import { getConvexFunctionName, make as make$1 } from "./Ref.js";
3
+ import { groups } from "./Spec.js";
3
4
  import * as Option from "effect/Option";
4
5
  import * as Record from "effect/Record";
5
6
  import { pipe } from "effect/Function";
6
7
  //#region src/Refs.ts
7
8
  var Refs_exports = /* @__PURE__ */ __exportAll({ make: () => make });
8
9
  const make = (spec) => {
9
- const refs = makeHelper(spec.groups);
10
+ const refs = makeHelper(groups(spec));
10
11
  return {
11
12
  public: refs,
12
13
  internal: refs
13
14
  };
14
15
  };
15
- const makeHelper = (groups, functionNamespace = Option.none()) => pipe(groups, Record.map((group, name) => {
16
- const currentFunctionNamespace = Option.match(functionNamespace, {
16
+ const makeHelper = (groups, convexFunctionNamespace = Option.none()) => pipe(groups, Record.map((group, name) => {
17
+ const currentConvexFunctionNamespace = Option.match(convexFunctionNamespace, {
17
18
  onNone: () => name,
18
19
  onSome: (parentNamespace) => `${parentNamespace}/${name}`
19
20
  });
20
- return Record.union(makeHelper(group.groups, Option.some(currentFunctionNamespace)), Record.map(group.functions, (function_) => make$1(currentFunctionNamespace, function_)), (_subGroup, _function) => {
21
+ return Record.union(makeHelper(group.groups, Option.some(currentConvexFunctionNamespace)), Record.map(group.functions, (function_) => make$1(currentConvexFunctionNamespace, function_, group.middlewareAttachments)), (_subGroup, _function) => {
21
22
  throw new Error(`Group and function at same level have same name ('${getConvexFunctionName(_function)}')`);
22
23
  });
23
24
  }));
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":["Spec.groups","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 * 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 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(spec));\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.middlewareAttachments,\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":";;;;;;;;AAiGA,MAAa,QACX,SACoB;CACpB,MAAM,OAAO,WAAWA,OAAY,IAAI,CAAC;CACzC,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,cAC3BC,OACE,gCACA,WACA,MAAM,qBACR,CACF,IACC,WAAW,cAAc;EACxB,MAAM,IAAI,MACR,qDAAqDC,sBAA0B,SAAS,EAAE,GAC5F;CACF,CACF;AACF,CAAC,CACH"}
@@ -0,0 +1,99 @@
1
+ import type { PropertyValidators, Validator, VAny, VArray, VBoolean, VBytes, VFloat64, VId, VInt64, VLiteral, VNull, VObject, VOptional, VRecord, VString, VUnion } from "convex/values";
2
+ import * as Effect from "effect/Effect";
3
+ import * as Schema from "effect/Schema";
4
+ import * as SchemaAST from "effect/SchemaAST";
5
+ import * as GenericId from "./GenericId";
6
+ import type { IsAny, IsOptional, IsRecord, IsRecursive, IsUnion, TypeError, UnionToTuple } from "./Types";
7
+ export declare const compileArgsSchema: <ConfectValue, ConvexValue>(argsSchema: Schema.Codec<ConfectValue, ConvexValue>) => PropertyValidators;
8
+ export declare const compileReturnsSchema: <ConfectValue, ConvexValue>(schema: Schema.Codec<ConfectValue, ConvexValue>) => Validator<any, any, any>;
9
+ /**
10
+ * Convert a table `Schema` to a table `Validator`.
11
+ */
12
+ export type TableSchemaToTableValidator<TableSchema extends Schema.Codec<any, any>> = ValueToValidator<TableSchema["Encoded"]> extends infer Vd extends VObject<any, any, any, any> | VUnion<any, any, any, any> ? Vd : never;
13
+ export declare const compileTableSchema: <TableSchema extends Schema.Codec<any, any>>(schema: TableSchema) => TableSchemaToTableValidator<TableSchema>;
14
+ export type ReadonlyValue = string | number | bigint | boolean | ArrayBuffer | ReadonlyArrayValue | ReadonlyRecordValue | null;
15
+ type ReadonlyArrayValue = readonly ReadonlyValue[];
16
+ export type ReadonlyRecordValue = {
17
+ readonly [key: string]: ReadonlyValue | undefined;
18
+ };
19
+ type MutableValue<T> = T extends ReadonlyArray<infer El> ? MutableValue<El>[] : T extends ReadonlyRecordValue ? {
20
+ -readonly [K in keyof T]: MutableValue<Exclude<T[K], undefined>>;
21
+ } : T;
22
+ export type ValueToValidator<Vl> = [Vl] extends [never] ? never : IsAny<Vl> extends true ? VAny : [Vl] extends [null] ? VNull : [Vl] extends [boolean] ? [boolean] extends [Vl] ? VBoolean : VLiteral<Vl> : IsUnion<Vl> extends true ? IsRecursive<Vl> extends true ? VAny : [Vl] extends [ReadonlyValue] ? UnionValueToValidator<Vl> : TypeError<"Provided value is not a valid Convex value", Vl> : [Vl] extends [number] ? [number] extends [Vl] ? VFloat64 : VLiteral<Vl> : [Vl] extends [bigint] ? [bigint] extends [Vl] ? VInt64 : VLiteral<Vl> : [Vl] extends [string] ? Vl extends {
23
+ __tableName: infer TableName extends string;
24
+ } ? VId<GenericId.GenericId<TableName>> : [string] extends [Vl] ? VString : VLiteral<Vl> : [Vl] extends [ArrayBuffer] ? VBytes : IsRecursive<Vl> extends true ? VAny : [Vl] extends [ReadonlyValue] ? Vl extends ReadonlyArray<ReadonlyValue> ? ArrayValueToValidator<Vl> : Vl extends ReadonlyRecordValue ? RecordValueToValidator<Vl> : TypeError<"Unexpected value", Vl> : TypeError<"Provided value is not a valid Convex value", Vl>;
25
+ type ArrayValueToValidator<Vl extends ReadonlyArray<ReadonlyValue>> = Vl extends ReadonlyArray<infer El extends ReadonlyValue> ? ValueToValidator<El> extends infer Vd extends Validator<any, any, any> ? VArray<MutableValue<El[]>, Vd> : never : never;
26
+ type RecordValueToValidator<Vl> = Vl extends ReadonlyRecordValue ? {
27
+ -readonly [K in keyof Vl]-?: IsAny<Vl[K]> extends true ? IsOptional<Vl, K> extends true ? VOptional<VAny> : VAny : UndefinedOrValueToValidator<Vl[K]>;
28
+ } extends infer VdRecord extends Record<string, any> ? MutableValue<Vl> extends infer VlRecord extends Record<string, any> ? IsRecord<VlRecord> extends true ? VRecord<VlRecord, VString, VdRecord[keyof VdRecord]> : VObject<VlRecord, VdRecord> : never : never : never;
29
+ export type UndefinedOrValueToValidator<Vl extends ReadonlyValue | undefined> = undefined extends Vl ? [Vl] extends [(infer Val extends ReadonlyValue) | undefined] ? ValueToValidator<Val> extends infer Vd extends Validator<any, "required", any> ? VOptional<Vd> : never : never : [Vl] extends [ReadonlyValue] ? ValueToValidator<Vl> : never;
30
+ type UnionValueToValidator<Vl extends ReadonlyValue> = [Vl] extends [
31
+ ReadonlyValue
32
+ ] ? IsUnion<Vl> extends true ? UnionToTuple<Vl> extends infer VlTuple extends ReadonlyArray<ReadonlyValue> ? ValueTupleToValidatorTuple<VlTuple> extends infer VdTuple extends Validator<any, "required", any>[] ? VUnion<MutableValue<Vl>, VdTuple> : TypeError<"Failed to convert value tuple to validator tuple"> : TypeError<"Failed to convert union to tuple"> : TypeError<"Expected a union of values, but got a single value instead"> : TypeError<"Provided value is not a valid Convex value">;
33
+ type ValueTupleToValidatorTuple<VlTuple extends ReadonlyArray<ReadonlyValue>> = VlTuple extends [true, false, ...infer VlRest extends ReadonlyArray<ReadonlyValue>] | [false, true, ...infer VlRest extends ReadonlyArray<ReadonlyValue>] ? ValueTupleToValidatorTuple<VlRest> extends infer VdRest extends Validator<any, any, any>[] ? [VBoolean<boolean>, ...VdRest] : never : VlTuple extends [
34
+ infer Vl extends ReadonlyValue,
35
+ ...infer VlRest extends ReadonlyArray<ReadonlyValue>
36
+ ] ? ValueToValidator<Vl> extends infer Vd extends Validator<any, any, any> ? ValueTupleToValidatorTuple<VlRest> extends infer VdRest extends Validator<any, "required", any>[] ? [Vd, ...VdRest] : never : never : [];
37
+ export declare const compileSchema: <T, E>(schema: Schema.Codec<T, E>) => ValueToValidator<(typeof schema)["Encoded"]>;
38
+ export declare const isRecursive: (ast: SchemaAST.AST) => boolean;
39
+ export declare const compileAst: (ast: SchemaAST.AST, isOptionalPropertyOfTypeLiteral?: boolean) => Effect.Effect<Validator<any, any, any>, UnsupportedSchemaTypeError | UnsupportedPropertySignatureKeyTypeError | IndexSignaturesAreNotSupportedError | MixedIndexAndPropertySignaturesAreNotSupportedError | OptionalTupleElementsAreNotSupportedError | EmptyTupleIsNotSupportedError | EmptyUnionIsNotSupportedError>;
40
+ declare const TopLevelMustBeObjectError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
41
+ readonly _tag: "TopLevelMustBeObjectError";
42
+ } & Readonly<A>;
43
+ export declare class TopLevelMustBeObjectError extends TopLevelMustBeObjectError_base {
44
+ get message(): string;
45
+ }
46
+ declare const TopLevelMustBeObjectOrUnionError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
47
+ readonly _tag: "TopLevelMustBeObjectOrUnionError";
48
+ } & Readonly<A>;
49
+ export declare class TopLevelMustBeObjectOrUnionError extends TopLevelMustBeObjectOrUnionError_base {
50
+ get message(): string;
51
+ }
52
+ declare const UnsupportedPropertySignatureKeyTypeError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
53
+ readonly _tag: "UnsupportedPropertySignatureKeyTypeError";
54
+ } & Readonly<A>;
55
+ export declare class UnsupportedPropertySignatureKeyTypeError extends UnsupportedPropertySignatureKeyTypeError_base<{
56
+ readonly propertyKey: number | symbol;
57
+ }> {
58
+ get message(): string;
59
+ }
60
+ declare const EmptyTupleIsNotSupportedError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
61
+ readonly _tag: "EmptyTupleIsNotSupportedError";
62
+ } & Readonly<A>;
63
+ export declare class EmptyTupleIsNotSupportedError extends EmptyTupleIsNotSupportedError_base {
64
+ get message(): string;
65
+ }
66
+ declare const EmptyUnionIsNotSupportedError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
67
+ readonly _tag: "EmptyUnionIsNotSupportedError";
68
+ } & Readonly<A>;
69
+ export declare class EmptyUnionIsNotSupportedError extends EmptyUnionIsNotSupportedError_base {
70
+ get message(): string;
71
+ }
72
+ declare const UnsupportedSchemaTypeError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
73
+ readonly _tag: "UnsupportedSchemaTypeError";
74
+ } & Readonly<A>;
75
+ export declare class UnsupportedSchemaTypeError extends UnsupportedSchemaTypeError_base<{
76
+ readonly schemaType: SchemaAST.AST["_tag"];
77
+ }> {
78
+ get message(): string;
79
+ }
80
+ declare const IndexSignaturesAreNotSupportedError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
81
+ readonly _tag: "IndexSignaturesAreNotSupportedError";
82
+ } & Readonly<A>;
83
+ export declare class IndexSignaturesAreNotSupportedError extends IndexSignaturesAreNotSupportedError_base {
84
+ get message(): string;
85
+ }
86
+ declare const MixedIndexAndPropertySignaturesAreNotSupportedError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
87
+ readonly _tag: "MixedIndexAndPropertySignaturesAreNotSupportedError";
88
+ } & Readonly<A>;
89
+ export declare class MixedIndexAndPropertySignaturesAreNotSupportedError extends MixedIndexAndPropertySignaturesAreNotSupportedError_base {
90
+ get message(): string;
91
+ }
92
+ declare const OptionalTupleElementsAreNotSupportedError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
93
+ readonly _tag: "OptionalTupleElementsAreNotSupportedError";
94
+ } & Readonly<A>;
95
+ export declare class OptionalTupleElementsAreNotSupportedError extends OptionalTupleElementsAreNotSupportedError_base {
96
+ get message(): string;
97
+ }
98
+ export {};
99
+ //# sourceMappingURL=SchemaToValidator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SchemaToValidator.d.ts","sourceRoot":"","sources":["../src/SchemaToValidator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,SAAS,EACT,IAAI,EACJ,MAAM,EACN,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,GAAG,EACH,MAAM,EACN,QAAQ,EACR,KAAK,EACL,OAAO,EACP,SAAS,EACT,OAAO,EACP,OAAO,EACP,MAAM,EACP,MAAM,eAAe,CAAC;AAKvB,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAKxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,SAAS,MAAM,kBAAkB,CAAC;AAG9C,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,EACV,KAAK,EACL,UAAU,EACV,QAAQ,EACR,WAAW,EACX,OAAO,EACP,SAAS,EACT,YAAY,EACb,MAAM,SAAS,CAAC;AAIjB,eAAO,MAAM,iBAAiB,GAAI,YAAY,EAAE,WAAW,cAC7C,M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