@confect/core 10.0.0-next.9 → 10.0.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 +958 -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 +16 -15
  64. package/dist/SystemFields.d.ts.map +1 -1
  65. package/dist/SystemFields.js +16 -15
  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 +30 -31
  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
@@ -1,17 +1,20 @@
1
+ import type * as MiddlewareAttachment from "./MiddlewareAttachment";
1
2
  import type {
3
+ DefaultFunctionArgs,
2
4
  FunctionType,
3
5
  FunctionVisibility,
4
6
  RegisteredAction,
5
7
  RegisteredMutation,
6
8
  RegisteredQuery,
7
9
  } from "convex/server";
8
- import type { Schema } from "effect";
10
+ import type * as Schema from "effect/Schema";
9
11
  import * as Predicate from "effect/Predicate";
10
12
  import * as FunctionProvenance from "./FunctionProvenance";
11
13
  import { validateConfectFunctionIdentifier } from "./Identifier";
14
+ import type * as MiddlewareSpec from "./MiddlewareSpec";
12
15
  import * as RuntimeAndFunctionType from "./RuntimeAndFunctionType";
13
16
 
14
- export const TypeId = "@confect/core/FunctionSpec";
17
+ export const TypeId = "~@confect/core/FunctionSpec";
15
18
  export type TypeId = typeof TypeId;
16
19
 
17
20
  export const isFunctionSpec = (u: unknown): u is AnyWithProps =>
@@ -22,12 +25,48 @@ export interface FunctionSpec<
22
25
  FunctionVisibility_ extends FunctionVisibility,
23
26
  Name_ extends string,
24
27
  FunctionProvenance_ extends FunctionProvenance.FunctionProvenance,
28
+ MiddlewareSpecs_ extends MiddlewareSpec.AnyMiddlewareSpec = never,
25
29
  > {
26
30
  readonly [TypeId]: TypeId;
27
31
  readonly runtimeAndFunctionType: RuntimeAndFunctionType_;
28
32
  readonly functionVisibility: FunctionVisibility_;
29
33
  readonly name: Name_;
30
34
  readonly functionProvenance: FunctionProvenance_;
35
+ readonly middlewareSpecs: ReadonlyArray<MiddlewareSpecs_>;
36
+ readonly middlewareAttachments: ReadonlyArray<
37
+ MiddlewareAttachment.MiddlewareAttachment<MiddlewareSpecs_>
38
+ >;
39
+ }
40
+
41
+ export interface Builder<
42
+ RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,
43
+ FunctionVisibility_ extends FunctionVisibility,
44
+ Name_ extends string,
45
+ FunctionProvenance_ extends FunctionProvenance.FunctionProvenance,
46
+ MiddlewareSpecs_ extends MiddlewareSpec.AnyMiddlewareSpec = never,
47
+ > extends FunctionSpec<
48
+ RuntimeAndFunctionType_,
49
+ FunctionVisibility_,
50
+ Name_,
51
+ FunctionProvenance_,
52
+ MiddlewareSpecs_
53
+ > {
54
+ middleware<MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec>(
55
+ middlewareSpec: MiddlewareSpec_ &
56
+ MiddlewareSpec.ValidateFunctionAttach<
57
+ MiddlewareSpec_,
58
+ RuntimeAndFunctionType_,
59
+ FunctionProvenance_,
60
+ MiddlewareSpecs_
61
+ >,
62
+ ...options: MiddlewareAttachment.Args<NoInfer<MiddlewareSpec_>>
63
+ ): Builder<
64
+ RuntimeAndFunctionType_,
65
+ FunctionVisibility_,
66
+ Name_,
67
+ FunctionProvenance_,
68
+ MiddlewareSpecs_ | MiddlewareSpec_
69
+ >;
31
70
  }
32
71
 
33
72
  export interface Any {
@@ -38,21 +77,24 @@ export interface AnyWithProps extends FunctionSpec<
38
77
  RuntimeAndFunctionType.RuntimeAndFunctionType,
39
78
  FunctionVisibility,
40
79
  string,
41
- FunctionProvenance.FunctionProvenance
80
+ FunctionProvenance.FunctionProvenance,
81
+ MiddlewareSpec.AnyMiddlewareSpec
42
82
  > {}
43
83
 
44
84
  export interface AnyConfect extends FunctionSpec<
45
85
  RuntimeAndFunctionType.RuntimeAndFunctionType,
46
86
  FunctionVisibility,
47
87
  string,
48
- FunctionProvenance.AnyConfect
88
+ FunctionProvenance.AnyConfect,
89
+ MiddlewareSpec.AnyMiddlewareSpec
49
90
  > {}
50
91
 
51
92
  export interface AnyConvex extends FunctionSpec<
52
93
  RuntimeAndFunctionType.RuntimeAndFunctionType,
53
94
  FunctionVisibility,
54
95
  string,
55
- FunctionProvenance.AnyConvex
96
+ FunctionProvenance.AnyConvex,
97
+ MiddlewareSpec.AnyMiddlewareSpec
56
98
  > {}
57
99
 
58
100
  export interface AnyWithPropsWithRuntime<
@@ -61,7 +103,8 @@ export interface AnyWithPropsWithRuntime<
61
103
  RuntimeAndFunctionType.WithRuntime<Runtime>,
62
104
  FunctionVisibility,
63
105
  string,
64
- FunctionProvenance.FunctionProvenance
106
+ FunctionProvenance.FunctionProvenance,
107
+ MiddlewareSpec.AnyMiddlewareSpec
65
108
  > {}
66
109
 
67
110
  export interface AnyWithPropsWithFunctionType<
@@ -70,7 +113,8 @@ export interface AnyWithPropsWithFunctionType<
70
113
  RuntimeAndFunctionType_,
71
114
  FunctionVisibility,
72
115
  string,
73
- FunctionProvenance.FunctionProvenance
116
+ FunctionProvenance.FunctionProvenance,
117
+ MiddlewareSpec.AnyMiddlewareSpec
74
118
  > {}
75
119
 
76
120
  export interface AnyWithPropsWithFunctionProvenance<
@@ -79,7 +123,8 @@ export interface AnyWithPropsWithFunctionProvenance<
79
123
  RuntimeAndFunctionType.RuntimeAndFunctionType,
80
124
  FunctionVisibility,
81
125
  string,
82
- FunctionProvenance_
126
+ FunctionProvenance_,
127
+ MiddlewareSpec.AnyMiddlewareSpec
83
128
  > {}
84
129
 
85
130
  export type GetRuntimeAndFunctionType<FunctionSpec_ extends AnyWithProps> =
@@ -88,83 +133,126 @@ export type GetRuntimeAndFunctionType<FunctionSpec_ extends AnyWithProps> =
88
133
  export type GetFunctionVisibility<FunctionSpec_ extends AnyWithProps> =
89
134
  FunctionSpec_["functionVisibility"];
90
135
 
136
+ export type GetFunctionProvenance<FunctionSpec_ extends AnyWithProps> =
137
+ FunctionSpec_["functionProvenance"];
138
+
91
139
  export type Name<FunctionSpec_ extends AnyWithProps> = FunctionSpec_["name"];
92
140
 
141
+ export type MiddlewareSpecs<FunctionSpec_ extends AnyWithProps> =
142
+ FunctionSpec_["middlewareSpecs"][number];
143
+
144
+ /**
145
+ * The field map declared by a Confect-provenance spec.
146
+ */
147
+ export type ArgsFields<FunctionSpec_ extends AnyWithProps> =
148
+ FunctionSpec_ extends {
149
+ readonly functionProvenance: {
150
+ readonly _tag: "Confect";
151
+ readonly "~ArgsFields": infer ArgsFields_ extends
152
+ FunctionProvenance.ArgsFields;
153
+ };
154
+ }
155
+ ? ArgsFields_
156
+ : FunctionSpec_ extends {
157
+ readonly functionProvenance: { readonly _tag: "Confect" };
158
+ }
159
+ ? FunctionProvenance.ArgsFields
160
+ : never;
161
+
162
+ /**
163
+ * The args schema assembled from a Confect-provenance spec's field map.
164
+ */
165
+ export type ArgsSchema<FunctionSpec_ extends AnyWithProps> =
166
+ FunctionSpec_ extends {
167
+ readonly functionProvenance: {
168
+ readonly _tag: "Confect";
169
+ readonly "~ArgsFields": infer ArgsFields_ extends
170
+ FunctionProvenance.ArgsFields;
171
+ };
172
+ }
173
+ ? Schema.Struct<ArgsFields_>
174
+ : FunctionSpec_ extends {
175
+ readonly functionProvenance: {
176
+ readonly _tag: "Confect";
177
+ readonly args: infer ArgsSchema_ extends
178
+ FunctionProvenance.AnyArgsSchema;
179
+ };
180
+ }
181
+ ? ArgsSchema_
182
+ : never;
183
+
184
+ export type ReturnsSchema<FunctionSpec_ extends AnyWithProps> =
185
+ FunctionSpec_ extends {
186
+ readonly functionProvenance: {
187
+ readonly _tag: "Confect";
188
+ readonly returns: infer ReturnsSchema_ extends Schema.Codec<any, any>;
189
+ };
190
+ }
191
+ ? ReturnsSchema_
192
+ : never;
193
+
194
+ export type ErrorSchema<FunctionSpec_ extends AnyWithProps> =
195
+ FunctionSpec_ extends {
196
+ readonly functionProvenance: {
197
+ readonly _tag: "Confect";
198
+ readonly error?: infer ErrorSchema_;
199
+ };
200
+ }
201
+ ? Extract<ErrorSchema_, Schema.Codec<any, any>>
202
+ : never;
203
+
93
204
  export type Args<FunctionSpec_ extends AnyWithProps> = FunctionSpec_ extends {
94
- functionProvenance: {
95
- _tag: "Confect";
96
- args: infer ArgsSchema_ extends Schema.Codec<any, any>;
97
- };
205
+ readonly functionProvenance: { readonly _tag: "Confect" };
98
206
  }
99
- ? ArgsSchema_["Type"]
100
- : FunctionSpec_ extends {
101
- functionProvenance: { _tag: "Convex"; _args: infer Args_ };
102
- }
207
+ ? ArgsSchema<FunctionSpec_>["Type"]
208
+ : GetFunctionProvenance<FunctionSpec_> extends FunctionProvenance.Convex<
209
+ infer Args_,
210
+ any
211
+ >
103
212
  ? Args_
104
213
  : never;
105
214
 
106
215
  export type Returns<FunctionSpec_ extends AnyWithProps> =
107
216
  FunctionSpec_ extends {
108
- functionProvenance: {
109
- _tag: "Confect";
110
- returns: infer ReturnsSchema_ extends Schema.Codec<any, any>;
111
- };
217
+ readonly functionProvenance: { readonly _tag: "Confect" };
112
218
  }
113
- ? ReturnsSchema_["Type"]
114
- : FunctionSpec_ extends {
115
- functionProvenance: { _tag: "Convex"; _returns: infer Returns_ };
116
- }
219
+ ? ReturnsSchema<FunctionSpec_>["Type"]
220
+ : GetFunctionProvenance<FunctionSpec_> extends FunctionProvenance.Convex<
221
+ any,
222
+ infer Returns_
223
+ >
117
224
  ? Awaited<Returns_>
118
225
  : never;
119
226
 
120
227
  export type EncodedArgs<FunctionSpec_ extends AnyWithProps> =
121
228
  FunctionSpec_ extends {
122
- functionProvenance: {
123
- _tag: "Confect";
124
- args: infer ArgsSchema_ extends Schema.Codec<any, any>;
125
- };
229
+ readonly functionProvenance: { readonly _tag: "Confect" };
126
230
  }
127
- ? ArgsSchema_["Encoded"]
128
- : FunctionSpec_ extends {
129
- functionProvenance: { _tag: "Convex"; _args: infer Args_ };
130
- }
231
+ ? ArgsSchema<FunctionSpec_>["Encoded"]
232
+ : GetFunctionProvenance<FunctionSpec_> extends FunctionProvenance.Convex<
233
+ infer Args_,
234
+ any
235
+ >
131
236
  ? Args_
132
237
  : never;
133
238
 
134
239
  export type EncodedReturns<FunctionSpec_ extends AnyWithProps> =
135
240
  FunctionSpec_ extends {
136
- functionProvenance: {
137
- _tag: "Confect";
138
- returns: infer ReturnsSchema_ extends Schema.Codec<any, any>;
139
- };
241
+ readonly functionProvenance: { readonly _tag: "Confect" };
140
242
  }
141
- ? ReturnsSchema_["Encoded"]
142
- : FunctionSpec_ extends {
143
- functionProvenance: { _tag: "Convex"; _returns: infer Returns_ };
144
- }
243
+ ? ReturnsSchema<FunctionSpec_>["Encoded"]
244
+ : GetFunctionProvenance<FunctionSpec_> extends FunctionProvenance.Convex<
245
+ any,
246
+ infer Returns_
247
+ >
145
248
  ? Returns_
146
249
  : never;
147
250
 
148
- export type Error<FunctionSpec_ extends AnyWithProps> = FunctionSpec_ extends {
149
- functionProvenance: FunctionProvenance.Confect<
150
- any,
151
- any,
152
- infer ErrorSchema_ extends Schema.Codec<any, any>
153
- >;
154
- }
155
- ? ErrorSchema_["Type"]
156
- : never;
251
+ export type Error<FunctionSpec_ extends AnyWithProps> =
252
+ ErrorSchema<FunctionSpec_>["Type"];
157
253
 
158
254
  export type EncodedError<FunctionSpec_ extends AnyWithProps> =
159
- FunctionSpec_ extends {
160
- functionProvenance: FunctionProvenance.Confect<
161
- any,
162
- any,
163
- infer ErrorSchema_ extends Schema.Codec<any, any>
164
- >;
165
- }
166
- ? ErrorSchema_["Encoded"]
167
- : never;
255
+ ErrorSchema<FunctionSpec_>["Encoded"];
168
256
 
169
257
  export type WithName<
170
258
  FunctionSpec_ extends AnyWithProps,
@@ -202,53 +290,202 @@ export type WithoutName<
202
290
 
203
291
  const Proto = {
204
292
  [TypeId]: TypeId,
205
- };
206
293
 
207
- const make =
208
- <
209
- RuntimeAndFunctionType_ extends
210
- RuntimeAndFunctionType.RuntimeAndFunctionType,
211
- FunctionVisibility_ extends FunctionVisibility,
212
- >(
213
- runtimeAndFunctionType: RuntimeAndFunctionType_,
214
- functionVisibility: FunctionVisibility_,
215
- ) =>
216
- <
294
+ get middlewareSpecs() {
295
+ return this.middlewareAttachments.map(({ spec }) => spec);
296
+ },
297
+
298
+ middleware(
299
+ this: AnyWithProps,
300
+ middlewareSpec: MiddlewareSpec.AnyMiddlewareSpec,
301
+ ...options: ReadonlyArray<unknown>
302
+ ) {
303
+ if (this.functionProvenance._tag === "Convex") {
304
+ throw new Error(
305
+ `Plain Convex function "${this.name}" cannot have middleware`,
306
+ );
307
+ }
308
+ const functionType = this.runtimeAndFunctionType.functionType;
309
+ if (!middlewareSpec.functionTypes[functionType]) {
310
+ throw new Error(
311
+ `Middleware "${middlewareSpec.key}" does not declare function type "${functionType}" of function "${this.name}"`,
312
+ );
313
+ }
314
+ if (
315
+ !("options" in middlewareSpec) &&
316
+ this.middlewareAttachments.some(
317
+ ({ spec }) => spec.key === middlewareSpec.key,
318
+ )
319
+ ) {
320
+ throw new Error(
321
+ `Middleware "${middlewareSpec.key}" is already attached to function "${this.name}"`,
322
+ );
323
+ }
324
+
325
+ return Object.assign(Object.create(Proto), {
326
+ runtimeAndFunctionType: this.runtimeAndFunctionType,
327
+ functionVisibility: this.functionVisibility,
328
+ name: this.name,
329
+ functionProvenance: this.functionProvenance,
330
+ middlewareAttachments: [
331
+ ...this.middlewareAttachments,
332
+ { spec: middlewareSpec, options: options[0] },
333
+ ],
334
+ });
335
+ },
336
+ } satisfies ThisType<AnyWithProps>;
337
+
338
+ interface Options {
339
+ readonly name: string;
340
+ readonly args?: () => FunctionProvenance.ArgsFields;
341
+ readonly returns: () => Schema.Codec<any, any>;
342
+ readonly error?: () => Schema.Codec<any, any>;
343
+ }
344
+
345
+ const make = <
346
+ RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,
347
+ FunctionVisibility_ extends FunctionVisibility,
348
+ >(
349
+ runtimeAndFunctionType: RuntimeAndFunctionType_,
350
+ functionVisibility: FunctionVisibility_,
351
+ ) => {
352
+ function makeSpec<
217
353
  const Name_ extends string,
218
- Args_ extends Schema.Codec<any, any>,
354
+ const ArgsFields_ extends FunctionProvenance.ArgsFields,
219
355
  Returns_ extends Schema.Codec<any, any>,
220
356
  Error_ extends Schema.Codec<any, any> = never,
221
- >({
222
- name,
223
- args,
224
- returns,
225
- error,
226
- }: {
357
+ >(options: {
227
358
  name: Name_;
228
- args: () => Args_;
359
+ args: () => ArgsFields_;
229
360
  returns: () => Returns_;
230
361
  error?: () => Error_;
231
- }): FunctionSpec<
362
+ }): Builder<
232
363
  RuntimeAndFunctionType_,
233
364
  FunctionVisibility_,
234
365
  Name_,
235
- FunctionProvenance.Confect<Args_, Returns_, Error_>
236
- > => {
366
+ FunctionProvenance.Confect<ArgsFields_, Returns_, Error_>
367
+ >;
368
+ function makeSpec<
369
+ const Name_ extends string,
370
+ Returns_ extends Schema.Codec<any, any>,
371
+ Error_ extends Schema.Codec<any, any> = never,
372
+ >(options: {
373
+ name: Name_;
374
+ args?: never;
375
+ returns: () => Returns_;
376
+ error?: () => Error_;
377
+ }): Builder<
378
+ RuntimeAndFunctionType_,
379
+ FunctionVisibility_,
380
+ Name_,
381
+ FunctionProvenance.Confect<{}, Returns_, Error_>
382
+ >;
383
+ function makeSpec({ name, args, returns, error }: Options) {
237
384
  validateConfectFunctionIdentifier(name);
238
385
 
239
386
  return Object.assign(Object.create(Proto), {
240
387
  runtimeAndFunctionType,
241
388
  functionVisibility,
242
389
  name,
243
- functionProvenance: FunctionProvenance.Confect(args, returns, error),
390
+ functionProvenance:
391
+ args === undefined
392
+ ? FunctionProvenance.Confect(() => ({}), returns, error)
393
+ : FunctionProvenance.Confect(args, returns, error),
394
+ middlewareAttachments: [],
244
395
  });
245
- };
396
+ }
397
+
398
+ return makeSpec;
399
+ };
400
+
401
+ /**
402
+ * `Schema.Struct` fields that must not declare `paginationOpts`. Used to reject
403
+ * a user args schema that redeclares the field the paginated constructors add
404
+ * themselves; the check reports at the `args` thunk with an unsatisfiable type
405
+ * when violated.
406
+ */
407
+ type ForbidPaginationOpts<
408
+ UserArgsFields extends FunctionProvenance.ArgsFields,
409
+ > = "paginationOpts" extends keyof UserArgsFields
410
+ ? { readonly paginationOpts: never }
411
+ : unknown;
412
+
413
+ interface PaginatedOptions {
414
+ readonly name: string;
415
+ readonly args?: () => FunctionProvenance.ArgsFields;
416
+ readonly item: () => Schema.Codec<any, any>;
417
+ readonly error?: () => Schema.Codec<any, any>;
418
+ }
419
+
420
+ const makePaginated = <
421
+ RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,
422
+ FunctionVisibility_ extends FunctionVisibility,
423
+ >(
424
+ runtimeAndFunctionType: RuntimeAndFunctionType_,
425
+ functionVisibility: FunctionVisibility_,
426
+ ) => {
427
+ function makeSpec<
428
+ const Name_ extends string,
429
+ const UserArgsFields_ extends FunctionProvenance.ArgsFields,
430
+ Item_ extends Schema.Codec<any, any>,
431
+ Error_ extends Schema.Codec<any, any> = never,
432
+ >(options: {
433
+ name: Name_;
434
+ args: () => UserArgsFields_ & ForbidPaginationOpts<UserArgsFields_>;
435
+ item: () => Item_;
436
+ error?: () => Error_;
437
+ }): Builder<
438
+ RuntimeAndFunctionType_,
439
+ FunctionVisibility_,
440
+ Name_,
441
+ FunctionProvenance.ConfectPaginated<UserArgsFields_, Item_, Error_>
442
+ >;
443
+ function makeSpec<
444
+ const Name_ extends string,
445
+ Item_ extends Schema.Codec<any, any>,
446
+ Error_ extends Schema.Codec<any, any> = never,
447
+ >(options: {
448
+ name: Name_;
449
+ args?: never;
450
+ item: () => Item_;
451
+ error?: () => Error_;
452
+ }): Builder<
453
+ RuntimeAndFunctionType_,
454
+ FunctionVisibility_,
455
+ Name_,
456
+ FunctionProvenance.ConfectPaginated<{}, Item_, Error_>
457
+ >;
458
+ function makeSpec({ name, args, item, error }: PaginatedOptions) {
459
+ validateConfectFunctionIdentifier(name);
460
+
461
+ return Object.assign(Object.create(Proto), {
462
+ runtimeAndFunctionType,
463
+ functionVisibility,
464
+ name,
465
+ functionProvenance:
466
+ args === undefined
467
+ ? FunctionProvenance.ConfectPaginated(() => ({}), item, error)
468
+ : FunctionProvenance.ConfectPaginated(args, item, error),
469
+ middlewareAttachments: [],
470
+ });
471
+ }
472
+
473
+ return makeSpec;
474
+ };
246
475
 
247
476
  export const publicQuery = make(RuntimeAndFunctionType.ConvexQuery, "public");
248
477
  export const internalQuery = make(
249
478
  RuntimeAndFunctionType.ConvexQuery,
250
479
  "internal",
251
480
  );
481
+ export const publicPaginatedQuery = makePaginated(
482
+ RuntimeAndFunctionType.ConvexQuery,
483
+ "public",
484
+ );
485
+ export const internalPaginatedQuery = makePaginated(
486
+ RuntimeAndFunctionType.ConvexQuery,
487
+ "internal",
488
+ );
252
489
  export const publicMutation = make(
253
490
  RuntimeAndFunctionType.ConvexMutation,
254
491
  "public",
@@ -285,11 +522,19 @@ type MatchingRegisteredFunction<
285
522
  : never;
286
523
 
287
524
  type ExtractArgs<F> =
288
- F extends RegisteredQuery<any, infer A, any>
525
+ F extends RegisteredQuery<any, infer A extends DefaultFunctionArgs, any>
289
526
  ? A
290
- : F extends RegisteredMutation<any, infer A, any>
527
+ : F extends RegisteredMutation<
528
+ any,
529
+ infer A extends DefaultFunctionArgs,
530
+ any
531
+ >
291
532
  ? A
292
- : F extends RegisteredAction<any, infer A, any>
533
+ : F extends RegisteredAction<
534
+ any,
535
+ infer A extends DefaultFunctionArgs,
536
+ any
537
+ >
293
538
  ? A
294
539
  : never;
295
540
 
@@ -319,7 +564,7 @@ const makeConvex =
319
564
  >() =>
320
565
  <const Name_ extends string>(
321
566
  name: Name_,
322
- ): FunctionSpec<
567
+ ): Builder<
323
568
  RuntimeAndFunctionType_,
324
569
  FunctionVisibility_,
325
570
  Name_,
@@ -335,6 +580,7 @@ const makeConvex =
335
580
  ExtractArgs<F>,
336
581
  ExtractReturns<F>
337
582
  >(),
583
+ middlewareAttachments: [],
338
584
  }) as any;
339
585
  };
340
586
 
package/src/GroupPath.ts CHANGED
@@ -1,11 +1,11 @@
1
- import type { Record } from "effect";
2
1
  import type * as GroupSpec from "./GroupSpec";
3
2
 
4
3
  /**
5
4
  * Recursively generates paths for a group and its nested groups.
6
5
  *
7
6
  * - For a group with no subgroups, returns just the group name.
8
- * - For a group with subgroups, returns the group name plus all possible paths through its direct subgroups.
7
+ * - For a group with subgroups, returns the group name plus all possible paths
8
+ * through its direct subgroups.
9
9
  */
10
10
  export type All<
11
11
  Group extends GroupSpec.AnyWithProps,
@@ -27,13 +27,11 @@ type AllHelper<
27
27
  : never;
28
28
 
29
29
  /**
30
- * Recursively extracts the group at the given dot-separated path.
31
- * Path must match the format defined in `Path` above, e.g. "group" or "group.subgroup".
30
+ * Recursively extracts the group at the given dot-separated path. Path must
31
+ * match the format defined in `Path` above, e.g. "group" or "group.subgroup".
32
32
  *
33
33
  * @example
34
- * ```ts
35
- * type G = WithPath<RootGroup, "group.subgroup">;
36
- * ```
34
+ * type G = WithPath<RootGroup, "group.subgroup">;
37
35
  */
38
36
  export type GroupAt<
39
37
  Group,
@@ -41,11 +39,7 @@ export type GroupAt<
41
39
  > = Group extends GroupSpec.AnyWithProps
42
40
  ? Path extends `${infer Head}.${infer Tail}`
43
41
  ? Group extends { readonly name: Head }
44
- ? Group extends {
45
- readonly groups: Record.ReadonlyRecord<string, infer SubGroup>;
46
- }
47
- ? GroupAt<SubGroup, Tail>
48
- : never
42
+ ? GroupAt<GroupSpec.Groups<Group>, Tail>
49
43
  : never
50
44
  : GroupSpec.WithName<Group, Path>
51
45
  : never;