@confect/core 10.0.0-next.17 → 10.0.0-next.19

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 (68) hide show
  1. package/CHANGELOG.md +81 -0
  2. package/dist/FunctionProvenance.d.ts +81 -60
  3. package/dist/FunctionProvenance.d.ts.map +1 -1
  4. package/dist/FunctionProvenance.js +9 -9
  5. package/dist/FunctionProvenance.js.map +1 -1
  6. package/dist/FunctionSpec.d.ts +256 -144
  7. package/dist/FunctionSpec.d.ts.map +1 -1
  8. package/dist/FunctionSpec.js +25 -20
  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 +5 -3
  14. package/dist/GroupSpec.d.ts.map +1 -1
  15. package/dist/GroupSpec.js +1 -1
  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 +2 -2
  22. package/dist/MiddlewareSpec.d.ts.map +1 -1
  23. package/dist/MiddlewareSpec.js +1 -1
  24. package/dist/MiddlewareSpec.js.map +1 -1
  25. package/dist/PaginationError.d.ts +14 -0
  26. package/dist/PaginationError.d.ts.map +1 -0
  27. package/dist/PaginationError.js +25 -0
  28. package/dist/PaginationError.js.map +1 -0
  29. package/dist/Ref.d.ts +66 -20
  30. package/dist/Ref.d.ts.map +1 -1
  31. package/dist/Ref.js +3 -3
  32. package/dist/Ref.js.map +1 -1
  33. package/dist/Refs.d.ts +1 -1
  34. package/dist/Refs.d.ts.map +1 -1
  35. package/dist/Refs.js.map +1 -1
  36. package/dist/SchemaToValidator.d.ts +99 -0
  37. package/dist/SchemaToValidator.d.ts.map +1 -0
  38. package/dist/SchemaToValidator.js +156 -0
  39. package/dist/SchemaToValidator.js.map +1 -0
  40. package/dist/Spec.d.ts +3 -2
  41. package/dist/Spec.d.ts.map +1 -1
  42. package/dist/Spec.js +1 -1
  43. package/dist/Spec.js.map +1 -1
  44. package/dist/Table.d.ts +74 -0
  45. package/dist/Table.d.ts.map +1 -0
  46. package/dist/Table.js +77 -0
  47. package/dist/Table.js.map +1 -0
  48. package/dist/Types.d.ts +8 -2
  49. package/dist/Types.d.ts.map +1 -1
  50. package/dist/Types.js.map +1 -1
  51. package/dist/index.d.ts +3 -0
  52. package/dist/index.d.ts.map +1 -1
  53. package/dist/index.js +4 -1
  54. package/package.json +4 -4
  55. package/src/FunctionProvenance.ts +84 -71
  56. package/src/FunctionSpec.ts +193 -110
  57. package/src/GroupPath.ts +1 -6
  58. package/src/GroupSpec.ts +6 -6
  59. package/src/Lazy.ts +2 -3
  60. package/src/MiddlewareSpec.ts +2 -2
  61. package/src/PaginationError.ts +72 -0
  62. package/src/Ref.ts +164 -153
  63. package/src/Refs.ts +1 -0
  64. package/src/SchemaToValidator.ts +601 -0
  65. package/src/Spec.ts +4 -4
  66. package/src/Table.ts +426 -0
  67. package/src/Types.ts +9 -3
  68. package/src/index.ts +3 -0
package/src/Ref.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type {
2
+ DefaultFunctionArgs,
2
3
  FunctionReference as ConvexFunctionReference,
3
4
  FunctionVisibility,
4
5
  PaginationOptions,
@@ -18,18 +19,17 @@ import * as MiddlewareSpec from "./MiddlewareSpec";
18
19
  import type * as RuntimeAndFunctionType from "./RuntimeAndFunctionType";
19
20
 
20
21
  export interface Base<
21
- _RuntimeAndFunctionType extends RuntimeAndFunctionType.RuntimeAndFunctionType,
22
- _FunctionVisibility extends FunctionVisibility,
23
- _Args,
24
- _Returns,
25
- _Error = never,
22
+ RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,
23
+ FunctionVisibility_ extends FunctionVisibility,
24
+ Args_ extends DefaultFunctionArgs,
25
+ Returns_,
26
+ Error_ = never,
26
27
  > {
27
- readonly _RuntimeAndFunctionType?: _RuntimeAndFunctionType;
28
- readonly _FunctionVisibility?: _FunctionVisibility;
29
- readonly _Args?: _Args;
30
- readonly _Returns?: _Returns;
31
- readonly _Error?: _Error;
32
- /** @internal */
28
+ readonly "~RuntimeAndFunctionType": RuntimeAndFunctionType_;
29
+ readonly "~FunctionVisibility": FunctionVisibility_;
30
+ readonly "~Args": Args_;
31
+ readonly "~Returns": Returns_;
32
+ readonly "~Error": Error_;
33
33
  readonly convexFunctionName: string;
34
34
  }
35
35
 
@@ -39,73 +39,93 @@ export interface Base<
39
39
  * errors. A ref is one of two shapes, keyed by the spec's provenance.
40
40
  */
41
41
  export type Ref<
42
- _RuntimeAndFunctionType extends RuntimeAndFunctionType.RuntimeAndFunctionType,
43
- _FunctionVisibility extends FunctionVisibility,
44
- _Args,
45
- _Returns,
46
- _Error = never,
42
+ RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,
43
+ FunctionVisibility_ extends FunctionVisibility,
44
+ Args_ extends DefaultFunctionArgs,
45
+ Returns_,
46
+ Error_ = never,
47
47
  > =
48
- | ConfectRef<
49
- _RuntimeAndFunctionType,
50
- _FunctionVisibility,
51
- _Args,
52
- _Returns,
53
- _Error
48
+ | ConfectRefWithTypes<
49
+ RuntimeAndFunctionType_,
50
+ FunctionVisibility_,
51
+ FunctionProvenance.ArgsFields,
52
+ Args_,
53
+ Returns_,
54
+ Error_
54
55
  >
55
56
  | ConvexRef<
56
- _RuntimeAndFunctionType,
57
- _FunctionVisibility,
58
- _Args,
59
- _Returns,
60
- _Error
57
+ RuntimeAndFunctionType_,
58
+ FunctionVisibility_,
59
+ Args_,
60
+ Returns_,
61
+ Error_
61
62
  >;
62
63
 
63
- export interface ConfectRef<
64
- _RuntimeAndFunctionType extends RuntimeAndFunctionType.RuntimeAndFunctionType,
65
- _FunctionVisibility extends FunctionVisibility,
66
- _Args,
67
- _Returns,
68
- _Error = never,
64
+ export type ConfectRef<
65
+ RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,
66
+ FunctionVisibility_ extends FunctionVisibility,
67
+ ArgsFields_ extends FunctionProvenance.ArgsFields,
68
+ ReturnsSchema_ extends Schema.Codec<any, any>,
69
+ ErrorSchema_ extends Schema.Codec<any, any> = never,
70
+ MiddlewareError_ = never,
71
+ > = ConfectRefWithTypes<
72
+ RuntimeAndFunctionType_,
73
+ FunctionVisibility_,
74
+ ArgsFields_,
75
+ Schema.Struct.Type<ArgsFields_>,
76
+ ReturnsSchema_["Type"],
77
+ ErrorSchema_["Type"] | MiddlewareError_
78
+ >;
79
+
80
+ /**
81
+ * Internal form used while mapping a spec to a ref. Supplying the already
82
+ * derived value types avoids repeatedly expanding `Schema.Struct` for every
83
+ * leaf in a generated ref tree; the public `ConfectRef` alias still derives
84
+ * the same values from its fields and schemas.
85
+ */
86
+ interface ConfectRefWithTypes<
87
+ RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,
88
+ FunctionVisibility_ extends FunctionVisibility,
89
+ ArgsFields_ extends FunctionProvenance.ArgsFields,
90
+ Args_ extends DefaultFunctionArgs,
91
+ Returns_,
92
+ Error_,
69
93
  > extends Base<
70
- _RuntimeAndFunctionType,
71
- _FunctionVisibility,
72
- _Args,
73
- _Returns,
74
- _Error
94
+ RuntimeAndFunctionType_,
95
+ FunctionVisibility_,
96
+ Args_,
97
+ Returns_,
98
+ Error_
75
99
  > {
76
- /** @internal */
77
100
  readonly _tag: "Confect";
78
- /** @internal */
79
- readonly args: Schema.Codec<any, any>;
80
- /** @internal */
101
+ readonly args: FunctionProvenance.ArgsSchema<ArgsFields_>;
81
102
  readonly returns: Schema.Codec<any, any>;
82
- /** @internal */
83
103
  readonly kind: FunctionProvenance.ConfectKind;
84
- /** @internal */
85
104
  readonly middlewareSpecs: ReadonlyArray<MiddlewareSpec.AnyMiddlewareSpec>;
86
- /** @internal */
87
105
  readonly error?: Schema.Codec<any, any>;
88
106
  }
89
107
 
90
108
  export interface ConvexRef<
91
- _RuntimeAndFunctionType extends RuntimeAndFunctionType.RuntimeAndFunctionType,
92
- _FunctionVisibility extends FunctionVisibility,
93
- _Args,
94
- _Returns,
95
- _Error = never,
109
+ RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,
110
+ FunctionVisibility_ extends FunctionVisibility,
111
+ Args_ extends DefaultFunctionArgs,
112
+ Returns_,
113
+ Error_ = never,
96
114
  > extends Base<
97
- _RuntimeAndFunctionType,
98
- _FunctionVisibility,
99
- _Args,
100
- _Returns,
101
- _Error
115
+ RuntimeAndFunctionType_,
116
+ FunctionVisibility_,
117
+ Args_,
118
+ Returns_,
119
+ Error_
102
120
  > {
103
- /** @internal */
104
121
  readonly _tag: "Convex";
105
122
  }
106
123
 
107
124
  export type Any = Ref<any, any, any, any, any>;
108
125
 
126
+ /** Erased Confect-provenance ref used by provenance-specific APIs. */
127
+ export type AnyConfect = Extract<Any, { readonly _tag: "Confect" }>;
128
+
109
129
  export type AnyInternal = Ref<any, "internal", any, any, any>;
110
130
 
111
131
  export type AnyPublic = Ref<any, "public", any, any, any>;
@@ -118,16 +138,17 @@ export type AnyQuery = Ref<
118
138
  any
119
139
  >;
120
140
 
121
- export type AnyPublicPaginatedQuery = Ref<
122
- RuntimeAndFunctionType.AnyQuery,
123
- "public",
124
- {
125
- [key: string]: any;
126
- paginationOpts: PaginationOptions;
127
- },
128
- PaginationResult<any>,
129
- any
130
- >;
141
+ export type AnyPaginatedQuery = AnyQuery &
142
+ Base<
143
+ RuntimeAndFunctionType.AnyQuery,
144
+ FunctionVisibility,
145
+ {
146
+ [key: string]: any;
147
+ paginationOpts: PaginationOptions;
148
+ },
149
+ PaginationResult<any>,
150
+ any
151
+ >;
131
152
 
132
153
  export type AnyMutation = Ref<
133
154
  RuntimeAndFunctionType.AnyMutation,
@@ -153,6 +174,13 @@ export type AnyPublicQuery = Ref<
153
174
  any
154
175
  >;
155
176
 
177
+ export type AnyConfectPublicQuery = Extract<AnyPublicQuery, AnyConfect>;
178
+
179
+ export type AnyPublicPaginatedQuery = AnyPublicQuery & AnyPaginatedQuery;
180
+
181
+ export type AnyConfectPublicPaginatedQuery = AnyConfectPublicQuery &
182
+ AnyPublicPaginatedQuery;
183
+
156
184
  export type AnyPublicMutation = Ref<
157
185
  RuntimeAndFunctionType.AnyMutation,
158
186
  "public",
@@ -161,6 +189,8 @@ export type AnyPublicMutation = Ref<
161
189
  any
162
190
  >;
163
191
 
192
+ export type AnyConfectPublicMutation = Extract<AnyPublicMutation, AnyConfect>;
193
+
164
194
  export type AnyPublicAction = Ref<
165
195
  RuntimeAndFunctionType.AnyAction,
166
196
  "public",
@@ -169,86 +199,62 @@ export type AnyPublicAction = Ref<
169
199
  any
170
200
  >;
171
201
 
172
- export type GetRuntimeAndFunctionType<Ref_> =
173
- Ref_ extends Base<
174
- infer RuntimeAndFunctionType_,
175
- infer _FunctionVisibility,
176
- infer _Args,
177
- infer _Returns,
178
- infer _Error
179
- >
180
- ? RuntimeAndFunctionType_
181
- : never;
182
-
183
- export type GetRuntime<Ref_> =
184
- Ref_ extends Base<
185
- infer RuntimeAndFunctionType_,
186
- infer _FunctionVisibility,
187
- infer _Args,
188
- infer _Returns,
189
- infer _Error
190
- >
191
- ? RuntimeAndFunctionType.GetRuntime<RuntimeAndFunctionType_>
192
- : never;
193
-
194
- export type GetFunctionType<Ref_> =
195
- Ref_ extends Base<
196
- infer RuntimeAndFunctionType_,
197
- infer _FunctionVisibility,
198
- infer _Args,
199
- infer _Returns,
200
- infer _Error
201
- >
202
- ? RuntimeAndFunctionType.GetFunctionType<RuntimeAndFunctionType_>
203
- : never;
204
-
205
- export type GetFunctionVisibility<Ref_> =
206
- Ref_ extends Base<
207
- infer _RuntimeAndFunctionType,
208
- infer FunctionVisibility_,
209
- infer _Args,
210
- infer _Returns,
211
- infer _Error
212
- >
213
- ? FunctionVisibility_
214
- : never;
215
-
216
- export type Args<Ref_> =
217
- Ref_ extends Base<
218
- infer _RuntimeAndFunctionType,
219
- infer _FunctionVisibility,
220
- infer Args_,
221
- infer _Returns,
222
- infer _Error
223
- >
224
- ? Args_
225
- : never;
202
+ export type AnyConfectPublicAction = Extract<AnyPublicAction, AnyConfect>;
203
+
204
+ export type GetRuntimeAndFunctionType<Ref_> = Ref_ extends {
205
+ readonly "~RuntimeAndFunctionType": infer RuntimeAndFunctionType_ extends
206
+ RuntimeAndFunctionType.RuntimeAndFunctionType;
207
+ }
208
+ ? RuntimeAndFunctionType_
209
+ : never;
210
+
211
+ export type GetRuntime<Ref_> = RuntimeAndFunctionType.GetRuntime<
212
+ GetRuntimeAndFunctionType<Ref_>
213
+ >;
214
+
215
+ export type GetFunctionType<Ref_> = RuntimeAndFunctionType.GetFunctionType<
216
+ GetRuntimeAndFunctionType<Ref_>
217
+ >;
218
+
219
+ export type GetFunctionVisibility<Ref_> = Ref_ extends {
220
+ readonly "~FunctionVisibility": infer FunctionVisibility_;
221
+ }
222
+ ? FunctionVisibility_
223
+ : never;
224
+
225
+ export type Args<Ref_> = Ref_ extends { readonly "~Args": infer Args_ }
226
+ ? Args_
227
+ : never;
228
+
229
+ /** The field map captured by a Confect-provenance ref. */
230
+ export type ArgsFields<Ref_> = Ref_ extends {
231
+ readonly _tag: "Confect";
232
+ readonly args: {
233
+ readonly fields: infer ArgsFields_ extends FunctionProvenance.ArgsFields;
234
+ };
235
+ }
236
+ ? ArgsFields_
237
+ : never;
238
+
239
+ /** The assembled args schema carried by a Confect-provenance ref. */
240
+ export type ArgsSchema<Ref_> = Ref_ extends {
241
+ readonly _tag: "Confect";
242
+ readonly args: infer ArgsSchema_ extends FunctionProvenance.AnyArgsSchema;
243
+ }
244
+ ? ArgsSchema_
245
+ : never;
226
246
 
227
247
  export type OptionalArgs<Ref_ extends Any> = keyof Args<Ref_> extends never
228
248
  ? [args?: Args<Ref_>]
229
249
  : [args: Args<Ref_>];
230
250
 
231
- export type Returns<Ref_> =
232
- Ref_ extends Base<
233
- infer _RuntimeAndFunctionType,
234
- infer _FunctionVisibility,
235
- infer _Args,
236
- infer Returns_,
237
- infer _Error
238
- >
239
- ? Returns_
240
- : never;
241
-
242
- export type Error<Ref_> =
243
- Ref_ extends Base<
244
- infer _RuntimeAndFunctionType,
245
- infer _FunctionVisibility,
246
- infer _Args,
247
- infer _Returns,
248
- infer Error_
249
- >
250
- ? Error_
251
- : never;
251
+ export type Returns<Ref_> = Ref_ extends { readonly "~Returns": infer Returns_ }
252
+ ? Returns_
253
+ : never;
254
+
255
+ export type Error<Ref_> = Ref_ extends { readonly "~Error": infer Error_ }
256
+ ? Error_
257
+ : never;
252
258
 
253
259
  export type FunctionReference<Ref_ extends Any> = ConvexFunctionReference<
254
260
  GetFunctionType<Ref_>,
@@ -262,6 +268,7 @@ export type FromFunctionSpec<
262
268
  FunctionSpec_,
263
269
  FunctionSpec.GetRuntimeAndFunctionType<FunctionSpec_>,
264
270
  FunctionSpec.GetFunctionVisibility<FunctionSpec_>,
271
+ FunctionSpec.ArgsFields<FunctionSpec_>,
265
272
  FunctionSpec.Args<FunctionSpec_>,
266
273
  FunctionSpec.Returns<FunctionSpec_>,
267
274
  FunctionSpec.Error<FunctionSpec_> | MiddlewareError
@@ -271,7 +278,8 @@ type FromFunctionSpecHelper<
271
278
  FunctionSpec_ extends FunctionSpec.AnyWithProps,
272
279
  RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,
273
280
  FunctionVisibility_ extends FunctionVisibility,
274
- Args_,
281
+ ArgsFields_ extends FunctionProvenance.ArgsFields,
282
+ Args_ extends DefaultFunctionArgs,
275
283
  Returns_,
276
284
  Error_,
277
285
  > =
@@ -282,17 +290,18 @@ type FromFunctionSpecHelper<
282
290
  ? ConvexRef<
283
291
  RuntimeAndFunctionType_,
284
292
  FunctionVisibility_,
285
- Args_,
293
+ Args_ extends DefaultFunctionArgs ? Args_ : never,
286
294
  Returns_,
287
- Error_
295
+ never
288
296
  >
289
297
  : FunctionSpec_ extends FunctionSpec.WithFunctionProvenance<
290
298
  FunctionSpec_,
291
299
  FunctionProvenance.AnyConfect
292
300
  >
293
- ? ConfectRef<
301
+ ? ConfectRefWithTypes<
294
302
  RuntimeAndFunctionType_,
295
303
  FunctionVisibility_,
304
+ ArgsFields_,
296
305
  Args_,
297
306
  Returns_,
298
307
  Error_
@@ -318,10 +327,14 @@ export const make = <FunctionSpec_ extends FunctionSpec.AnyWithProps>(
318
327
  const convexFunctionName = `${convexFunctionNamespace}:${functionSpec.name}`;
319
328
 
320
329
  return Match.value(functionSpec.functionProvenance).pipe(
321
- Match.tag("Convex", (): Any => ({
322
- _tag: "Convex",
323
- convexFunctionName,
324
- })),
330
+ Match.tag(
331
+ "Convex",
332
+ (): Any =>
333
+ ({
334
+ _tag: "Convex",
335
+ convexFunctionName,
336
+ }) as Any,
337
+ ),
325
338
  Match.tag("Confect", (provenance): Any => {
326
339
  const ref = {
327
340
  _tag: "Confect" as const,
@@ -557,14 +570,12 @@ const missingPaginatedProvenanceError = (ref: Any) =>
557
570
  "those constructors store. Define the function as, e.g.:\n\n" +
558
571
  " FunctionSpec.publicPaginatedQuery({\n" +
559
572
  ' name: "...",\n' +
560
- " args: () => Schema.Struct({ ... }), // optional; without paginationOpts\n" +
573
+ " args: () => ({ ... }), // optional; without paginationOpts\n" +
561
574
  " item: () => ItemSchema,\n" +
562
575
  " })",
563
576
  );
564
577
 
565
- const paginatedKind = (
566
- ref: ConfectRef<any, any, any, any, any>,
567
- ): FunctionProvenance.Paginated =>
578
+ const paginatedKind = (ref: AnyConfect): FunctionProvenance.Paginated =>
568
579
  Match.value(ref.kind).pipe(
569
580
  Match.tag("Paginated", (kind) => kind),
570
581
  Match.tag("Standard", () => {
package/src/Refs.ts CHANGED
@@ -42,6 +42,7 @@ type FunctionSpecMatchesPredicate<
42
42
  FunctionSpec.GetRuntimeAndFunctionType<FunctionSpec_>,
43
43
  FunctionSpec.GetFunctionVisibility<FunctionSpec_>,
44
44
  any,
45
+ any,
45
46
  any
46
47
  > extends Predicate
47
48
  ? true