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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/FunctionProvenance.d.ts +18 -18
  3. package/dist/FunctionProvenance.d.ts.map +1 -1
  4. package/dist/FunctionProvenance.js +1 -1
  5. package/dist/FunctionProvenance.js.map +1 -1
  6. package/dist/FunctionSpec.d.ts +5 -5
  7. package/dist/FunctionSpec.d.ts.map +1 -1
  8. package/dist/FunctionSpec.js +1 -1
  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/Ref.d.ts +26 -16
  26. package/dist/Ref.d.ts.map +1 -1
  27. package/dist/Ref.js.map +1 -1
  28. package/dist/SchemaToValidator.d.ts +99 -0
  29. package/dist/SchemaToValidator.d.ts.map +1 -0
  30. package/dist/SchemaToValidator.js +156 -0
  31. package/dist/SchemaToValidator.js.map +1 -0
  32. package/dist/Spec.d.ts +3 -2
  33. package/dist/Spec.d.ts.map +1 -1
  34. package/dist/Spec.js +1 -1
  35. package/dist/Spec.js.map +1 -1
  36. package/dist/Table.d.ts +74 -0
  37. package/dist/Table.d.ts.map +1 -0
  38. package/dist/Table.js +77 -0
  39. package/dist/Table.js.map +1 -0
  40. package/dist/Types.d.ts +8 -2
  41. package/dist/Types.d.ts.map +1 -1
  42. package/dist/Types.js.map +1 -1
  43. package/dist/index.d.ts +2 -0
  44. package/dist/index.d.ts.map +1 -1
  45. package/dist/index.js +3 -1
  46. package/package.json +1 -1
  47. package/src/FunctionProvenance.ts +8 -8
  48. package/src/FunctionSpec.ts +5 -5
  49. package/src/GroupPath.ts +1 -6
  50. package/src/GroupSpec.ts +6 -6
  51. package/src/Lazy.ts +2 -3
  52. package/src/MiddlewareSpec.ts +2 -2
  53. package/src/Ref.ts +84 -124
  54. package/src/SchemaToValidator.ts +601 -0
  55. package/src/Spec.ts +4 -4
  56. package/src/Table.ts +426 -0
  57. package/src/Types.ts +9 -3
  58. package/src/index.ts +2 -0
@@ -14,9 +14,9 @@ export type FunctionProvenance = Data.TaggedEnum<{
14
14
  };
15
15
  Convex: {
16
16
  /** @internal */
17
- _args: DefaultFunctionArgs;
17
+ "~args": DefaultFunctionArgs;
18
18
  /** @internal */
19
- _returns: any;
19
+ "~returns": any;
20
20
  };
21
21
  }>;
22
22
 
@@ -67,8 +67,8 @@ export interface AnyConfect extends Confect<
67
67
 
68
68
  export interface Convex<Args extends DefaultFunctionArgs, Returns> {
69
69
  readonly _tag: "Convex";
70
- readonly _args: Args;
71
- readonly _returns: Returns;
70
+ readonly "~args": Args;
71
+ readonly "~returns": Returns;
72
72
  }
73
73
 
74
74
  export interface AnyConvex extends Convex<DefaultFunctionArgs, any> {}
@@ -81,7 +81,7 @@ const Standard: Standard = { _tag: "Standard" };
81
81
  * Build a `Confect` provenance from lazy schema thunks. `args`, `returns`,
82
82
  * and `error` are exposed as sync lazy memoised getters (via {@link Lazy.defineProperty})
83
83
  * that only evaluate their thunk on first access, mirroring how `Table`
84
- * defers `Fields`/`Doc`/`tableDefinition`. This keeps importing the assembled
84
+ * defers `Fields`/`Doc`. This keeps importing the assembled
85
85
  * `_generated/spec.ts` cheap — no `Schema.Struct(...)` / `Schema.Array(...)`
86
86
  * work runs at module load; it is deferred to the first invocation that
87
87
  * actually compiles validators or runs a codec.
@@ -223,10 +223,10 @@ export const ConfectPaginated = <
223
223
  return self;
224
224
  };
225
225
 
226
- export const Convex = <_Args extends DefaultFunctionArgs, _Returns>() =>
226
+ export const Convex = <Args extends DefaultFunctionArgs, Returns>() =>
227
227
  FunctionProvenance.Convex(
228
228
  {} as {
229
- _args: _Args;
230
- _returns: _Returns;
229
+ "~args": Args;
230
+ "~returns": Returns;
231
231
  },
232
232
  );
@@ -12,7 +12,7 @@ import { validateConfectFunctionIdentifier } from "./Identifier";
12
12
  import type * as MiddlewareSpec from "./MiddlewareSpec";
13
13
  import * as RuntimeAndFunctionType from "./RuntimeAndFunctionType";
14
14
 
15
- export const TypeId = "@confect/core/FunctionSpec";
15
+ export const TypeId = "~@confect/core/FunctionSpec";
16
16
  export type TypeId = typeof TypeId;
17
17
 
18
18
  export const isFunctionSpec = (u: unknown): u is AnyWithProps =>
@@ -140,7 +140,7 @@ export type Args<FunctionSpec_ extends AnyWithProps> = FunctionSpec_ extends {
140
140
  }
141
141
  ? ArgsSchema_["Type"]
142
142
  : FunctionSpec_ extends {
143
- functionProvenance: { _tag: "Convex"; _args: infer Args_ };
143
+ functionProvenance: { _tag: "Convex"; "~args": infer Args_ };
144
144
  }
145
145
  ? Args_
146
146
  : never;
@@ -154,7 +154,7 @@ export type Returns<FunctionSpec_ extends AnyWithProps> =
154
154
  }
155
155
  ? ReturnsSchema_["Type"]
156
156
  : FunctionSpec_ extends {
157
- functionProvenance: { _tag: "Convex"; _returns: infer Returns_ };
157
+ functionProvenance: { _tag: "Convex"; "~returns": infer Returns_ };
158
158
  }
159
159
  ? Awaited<Returns_>
160
160
  : never;
@@ -168,7 +168,7 @@ export type EncodedArgs<FunctionSpec_ extends AnyWithProps> =
168
168
  }
169
169
  ? ArgsSchema_["Encoded"]
170
170
  : FunctionSpec_ extends {
171
- functionProvenance: { _tag: "Convex"; _args: infer Args_ };
171
+ functionProvenance: { _tag: "Convex"; "~args": infer Args_ };
172
172
  }
173
173
  ? Args_
174
174
  : never;
@@ -182,7 +182,7 @@ export type EncodedReturns<FunctionSpec_ extends AnyWithProps> =
182
182
  }
183
183
  ? ReturnsSchema_["Encoded"]
184
184
  : FunctionSpec_ extends {
185
- functionProvenance: { _tag: "Convex"; _returns: infer Returns_ };
185
+ functionProvenance: { _tag: "Convex"; "~returns": infer Returns_ };
186
186
  }
187
187
  ? Returns_
188
188
  : never;
package/src/GroupPath.ts CHANGED
@@ -1,4 +1,3 @@
1
- import type { Record } from "effect";
2
1
  import type * as GroupSpec from "./GroupSpec";
3
2
 
4
3
  /**
@@ -41,11 +40,7 @@ export type GroupAt<
41
40
  > = Group extends GroupSpec.AnyWithProps
42
41
  ? Path extends `${infer Head}.${infer Tail}`
43
42
  ? Group extends { readonly name: Head }
44
- ? Group extends {
45
- readonly groups: Record.ReadonlyRecord<string, infer SubGroup>;
46
- }
47
- ? GroupAt<SubGroup, Tail>
48
- : never
43
+ ? GroupAt<GroupSpec.Groups<Group>, Tail>
49
44
  : never
50
45
  : GroupSpec.WithName<Group, Path>
51
46
  : never;
package/src/GroupSpec.ts CHANGED
@@ -5,7 +5,7 @@ import type * as MiddlewareSpec from "./MiddlewareSpec";
5
5
  import type * as RuntimeAndFunctionType from "./RuntimeAndFunctionType";
6
6
  import { validateConfectFunctionIdentifier } from "./Identifier";
7
7
 
8
- export const TypeId = "@confect/core/GroupSpec";
8
+ export const TypeId = "~@confect/core/GroupSpec";
9
9
  export type TypeId = typeof TypeId;
10
10
 
11
11
  export const isGroupSpec = (u: unknown): u is AnyWithProps =>
@@ -36,6 +36,8 @@ export interface GroupSpec<
36
36
  [GroupName in Name<Groups_>]: WithName<Groups_, GroupName>;
37
37
  };
38
38
  readonly middlewareSpecs: ReadonlyArray<MiddlewareSpecs_>;
39
+ readonly "~Functions": Functions_;
40
+ readonly "~Groups": Groups_;
39
41
 
40
42
  addFunction<Function extends FunctionSpec.AnyWithPropsWithRuntime<Runtime>>(
41
43
  function_: Function &
@@ -103,11 +105,9 @@ export interface AnyWithPropsWithRuntime<
103
105
 
104
106
  export type Name<Group extends AnyWithProps> = Group["name"];
105
107
 
106
- export type Functions<Group extends AnyWithProps> =
107
- Group["functions"][keyof Group["functions"]];
108
+ export type Functions<Group extends AnyWithProps> = Group["~Functions"];
108
109
 
109
- export type Groups<Group extends AnyWithProps> =
110
- Group["groups"][keyof Group["groups"]];
110
+ export type Groups<Group extends AnyWithProps> = Group["~Groups"];
111
111
 
112
112
  export type MiddlewareSpecs<Group extends AnyWithProps> =
113
113
  Group["middlewareSpecs"][number];
@@ -271,7 +271,7 @@ const makeProto = <
271
271
  functions,
272
272
  groups,
273
273
  middlewareSpecs,
274
- });
274
+ }) as GroupSpec<Runtime, Name_, Functions_, Groups_, MiddlewareSpecs_>;
275
275
 
276
276
  export const make = (): GroupSpec<"Convex", ""> =>
277
277
  makeProto({
package/src/Lazy.ts CHANGED
@@ -14,9 +14,8 @@
14
14
  * forcing the computation.
15
15
  *
16
16
  * This is the single shared implementation consumed across packages (e.g.
17
- * `@confect/core`'s lazy `FunctionSpec` schemas and `@confect/server`'s lazy
18
- * `Table` `Fields` / `Doc` / `tableDefinition`), so there is no chance of the
19
- * two drifting apart.
17
+ * `@confect/core`'s lazy `FunctionSpec` schemas and lazy `Table` `Fields` /
18
+ * `Doc`), so there is no chance of the two drifting apart.
20
19
  */
21
20
  export const defineProperty = <T extends object, K extends PropertyKey>(
22
21
  target: T,
@@ -8,7 +8,7 @@ import type * as FunctionSpec from "./FunctionSpec";
8
8
  import * as Lazy from "./Lazy";
9
9
  import type * as RuntimeAndFunctionType from "./RuntimeAndFunctionType";
10
10
 
11
- export const TypeId = "@confect/core/MiddlewareSpec";
11
+ export const TypeId = "~@confect/core/MiddlewareSpec";
12
12
  export type TypeId = typeof TypeId;
13
13
 
14
14
  export const isMiddlewareSpec = (u: unknown): u is AnyMiddlewareSpec =>
@@ -228,7 +228,7 @@ export const errorSchemas = (
228
228
  * problem at the `.middleware()` / `.addFunction()` call site.
229
229
  */
230
230
  export interface AttachmentError<Message extends string> {
231
- readonly "~confect/MiddlewareSpec/AttachmentError": Message;
231
+ readonly "~@confect/core/MiddlewareSpec/AttachmentError": Message;
232
232
  }
233
233
 
234
234
  type FunctionTypeOf<FunctionSpec_ extends FunctionSpec.AnyWithProps> =
package/src/Ref.ts CHANGED
@@ -18,17 +18,17 @@ import * as MiddlewareSpec from "./MiddlewareSpec";
18
18
  import type * as RuntimeAndFunctionType from "./RuntimeAndFunctionType";
19
19
 
20
20
  export interface Base<
21
- _RuntimeAndFunctionType extends RuntimeAndFunctionType.RuntimeAndFunctionType,
22
- _FunctionVisibility extends FunctionVisibility,
23
- _Args,
24
- _Returns,
25
- _Error = never,
21
+ RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,
22
+ FunctionVisibility_ extends FunctionVisibility,
23
+ Args_,
24
+ Returns_,
25
+ Error_ = never,
26
26
  > {
27
- readonly _RuntimeAndFunctionType?: _RuntimeAndFunctionType;
28
- readonly _FunctionVisibility?: _FunctionVisibility;
29
- readonly _Args?: _Args;
30
- readonly _Returns?: _Returns;
31
- readonly _Error?: _Error;
27
+ readonly "~RuntimeAndFunctionType": RuntimeAndFunctionType_;
28
+ readonly "~FunctionVisibility": FunctionVisibility_;
29
+ readonly "~Args": Args_;
30
+ readonly "~Returns": Returns_;
31
+ readonly "~Error": Error_;
32
32
  /** @internal */
33
33
  readonly convexFunctionName: string;
34
34
  }
@@ -39,39 +39,39 @@ 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_,
45
+ Returns_,
46
+ Error_ = never,
47
47
  > =
48
48
  | ConfectRef<
49
- _RuntimeAndFunctionType,
50
- _FunctionVisibility,
51
- _Args,
52
- _Returns,
53
- _Error
49
+ RuntimeAndFunctionType_,
50
+ FunctionVisibility_,
51
+ Args_,
52
+ Returns_,
53
+ Error_
54
54
  >
55
55
  | ConvexRef<
56
- _RuntimeAndFunctionType,
57
- _FunctionVisibility,
58
- _Args,
59
- _Returns,
60
- _Error
56
+ RuntimeAndFunctionType_,
57
+ FunctionVisibility_,
58
+ Args_,
59
+ Returns_,
60
+ Error_
61
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
+ RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,
65
+ FunctionVisibility_ extends FunctionVisibility,
66
+ Args_,
67
+ Returns_,
68
+ Error_ = never,
69
69
  > extends Base<
70
- _RuntimeAndFunctionType,
71
- _FunctionVisibility,
72
- _Args,
73
- _Returns,
74
- _Error
70
+ RuntimeAndFunctionType_,
71
+ FunctionVisibility_,
72
+ Args_,
73
+ Returns_,
74
+ Error_
75
75
  > {
76
76
  /** @internal */
77
77
  readonly _tag: "Confect";
@@ -88,17 +88,17 @@ export interface ConfectRef<
88
88
  }
89
89
 
90
90
  export interface ConvexRef<
91
- _RuntimeAndFunctionType extends RuntimeAndFunctionType.RuntimeAndFunctionType,
92
- _FunctionVisibility extends FunctionVisibility,
93
- _Args,
94
- _Returns,
95
- _Error = never,
91
+ RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,
92
+ FunctionVisibility_ extends FunctionVisibility,
93
+ Args_,
94
+ Returns_,
95
+ Error_ = never,
96
96
  > extends Base<
97
- _RuntimeAndFunctionType,
98
- _FunctionVisibility,
99
- _Args,
100
- _Returns,
101
- _Error
97
+ RuntimeAndFunctionType_,
98
+ FunctionVisibility_,
99
+ Args_,
100
+ Returns_,
101
+ Error_
102
102
  > {
103
103
  /** @internal */
104
104
  readonly _tag: "Convex";
@@ -169,86 +169,42 @@ export type AnyPublicAction = Ref<
169
169
  any
170
170
  >;
171
171
 
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;
172
+ export type GetRuntimeAndFunctionType<Ref_> = Ref_ extends {
173
+ readonly "~RuntimeAndFunctionType": infer RuntimeAndFunctionType_ extends
174
+ RuntimeAndFunctionType.RuntimeAndFunctionType;
175
+ }
176
+ ? RuntimeAndFunctionType_
177
+ : never;
178
+
179
+ export type GetRuntime<Ref_> = RuntimeAndFunctionType.GetRuntime<
180
+ GetRuntimeAndFunctionType<Ref_>
181
+ >;
182
+
183
+ export type GetFunctionType<Ref_> = RuntimeAndFunctionType.GetFunctionType<
184
+ GetRuntimeAndFunctionType<Ref_>
185
+ >;
186
+
187
+ export type GetFunctionVisibility<Ref_> = Ref_ extends {
188
+ readonly "~FunctionVisibility": infer FunctionVisibility_;
189
+ }
190
+ ? FunctionVisibility_
191
+ : never;
192
+
193
+ export type Args<Ref_> = Ref_ extends { readonly "~Args": infer Args_ }
194
+ ? Args_
195
+ : never;
226
196
 
227
197
  export type OptionalArgs<Ref_ extends Any> = keyof Args<Ref_> extends never
228
198
  ? [args?: Args<Ref_>]
229
199
  : [args: Args<Ref_>];
230
200
 
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;
201
+ export type Returns<Ref_> = Ref_ extends { readonly "~Returns": infer Returns_ }
202
+ ? Returns_
203
+ : never;
204
+
205
+ export type Error<Ref_> = Ref_ extends { readonly "~Error": infer Error_ }
206
+ ? Error_
207
+ : never;
252
208
 
253
209
  export type FunctionReference<Ref_ extends Any> = ConvexFunctionReference<
254
210
  GetFunctionType<Ref_>,
@@ -318,10 +274,14 @@ export const make = <FunctionSpec_ extends FunctionSpec.AnyWithProps>(
318
274
  const convexFunctionName = `${convexFunctionNamespace}:${functionSpec.name}`;
319
275
 
320
276
  return Match.value(functionSpec.functionProvenance).pipe(
321
- Match.tag("Convex", (): Any => ({
322
- _tag: "Convex",
323
- convexFunctionName,
324
- })),
277
+ Match.tag(
278
+ "Convex",
279
+ (): Any =>
280
+ ({
281
+ _tag: "Convex",
282
+ convexFunctionName,
283
+ }) as Any,
284
+ ),
325
285
  Match.tag("Confect", (provenance): Any => {
326
286
  const ref = {
327
287
  _tag: "Confect" as const,