@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/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@confect/core",
3
3
  "description": "Shared specs and schemas used by all Confect packages",
4
- "version": "10.0.0-next.17",
4
+ "version": "10.0.0-next.19",
5
5
  "author": "RJ Dellecese",
6
6
  "bugs": {
7
7
  "url": "https://github.com/rjdellecese/confect/issues"
8
8
  },
9
9
  "devDependencies": {
10
- "@effect/vitest": "4.0.0-rc.111",
10
+ "@effect/vitest": "4.0.0-rc.112",
11
11
  "@types/node": "22.20.1",
12
- "effect": "4.0.0-rc.111",
12
+ "effect": "4.0.0-rc.112",
13
13
  "tsdown": "0.22.14",
14
14
  "tsx": "4.23.12",
15
15
  "typescript": "7.0.2",
@@ -51,7 +51,7 @@
51
51
  "module": "./dist/index.js",
52
52
  "peerDependencies": {
53
53
  "convex": "^1.32.0",
54
- "effect": "^4.0.0-rc.111"
54
+ "effect": "^4.0.0-rc.112"
55
55
  },
56
56
  "repository": {
57
57
  "type": "git",
@@ -5,27 +5,52 @@ import * as Lazy from "./Lazy";
5
5
  import * as PaginationOptions from "./PaginationOptions";
6
6
  import * as PaginationResult from "./PaginationResult";
7
7
 
8
+ /**
9
+ * A field map accepted as Confect function args. Restricting each field to a
10
+ * context-free codec means the struct assembled from the fields can always be
11
+ * encoded and decoded synchronously at a Convex boundary.
12
+ */
13
+ // eslint-disable-next-line import/namespace -- oxlint's namespace resolution misses type-only exports, and `Schema` is an interface/namespace
14
+ export type ArgsFields = {
15
+ readonly [key: PropertyKey]: Schema.ConstraintCodec<any, any>;
16
+ };
17
+
18
+ /**
19
+ * A struct-shaped Confect args schema that keeps its exact field map while
20
+ * erasing the rest of `Schema.Struct`'s large implementation type. Decoded and
21
+ * encoded args are derived directly from `ArgsFields_`; keeping the runtime
22
+ * codec structural prevents every ref lookup from expanding the full Effect
23
+ * schema type.
24
+ */
25
+ export interface ArgsSchema<
26
+ ArgsFields_ extends ArgsFields,
27
+ > extends Schema.Codec<any, any> {
28
+ readonly fields: ArgsFields_;
29
+ }
30
+
31
+ /** Erased structural view used after the exact field map is no longer needed. */
32
+ export type AnyArgsSchema = ArgsSchema<ArgsFields>;
33
+
8
34
  export type FunctionProvenance = Data.TaggedEnum<{
9
35
  Confect: {
10
- args: Schema.Codec<any, any>;
36
+ args: AnyArgsSchema;
11
37
  returns: Schema.Codec<any, any>;
12
38
  error?: Schema.Codec<any, any>;
13
39
  kind: ConfectKind;
14
40
  };
15
41
  Convex: {
16
- /** @internal */
17
- _args: DefaultFunctionArgs;
18
- /** @internal */
19
- _returns: any;
42
+ "~args": DefaultFunctionArgs;
43
+ "~returns": any;
20
44
  };
21
45
  }>;
22
46
 
23
47
  /**
24
48
  * The declaration shape of a Confect function — orthogonal to both the
25
49
  * provenance origin (Confect vs Convex) and the function type
26
- * (query/mutation/action). A `Standard` function declares its `args` and
27
- * `returns` schemas directly; a `Paginated` function declares `userArgs` and
28
- * `item` schemas from which the Convex-facing `args`/`returns` are composed.
50
+ * (query/mutation/action). A `Standard` function declares its args fields and
51
+ * returns schema directly; a `Paginated` function declares user-args fields
52
+ * and an item schema from which the Convex-facing `args`/`returns` are
53
+ * composed.
29
54
  */
30
55
  export type ConfectKind = Standard | Paginated;
31
56
 
@@ -34,12 +59,12 @@ export interface Standard {
34
59
  }
35
60
 
36
61
  export interface Paginated<
37
- UserArgs extends AnyUserArgs = AnyUserArgs,
62
+ UserArgsFields_ extends ArgsFields = ArgsFields,
38
63
  Item extends Schema.Codec<any, any> = Schema.Codec<any, any>,
39
64
  > {
40
65
  readonly _tag: "Paginated";
41
66
  /** User-declared args — no `paginationOpts`. */
42
- readonly userArgs: UserArgs;
67
+ readonly userArgs: ArgsSchema<UserArgsFields_>;
43
68
  /** Page element schema. */
44
69
  readonly item: Item;
45
70
  /** Mutable array of items — the page decode target. */
@@ -47,28 +72,31 @@ export interface Paginated<
47
72
  }
48
73
 
49
74
  export interface Confect<
50
- Args extends Schema.Codec<any, any>,
75
+ ArgsFields_ extends ArgsFields,
51
76
  Returns extends Schema.Codec<any, any>,
52
77
  Error extends Schema.Codec<any, any> = never,
53
78
  Kind extends ConfectKind = ConfectKind,
54
79
  > {
55
80
  readonly _tag: "Confect";
56
- readonly args: Args;
81
+ readonly "~ArgsFields": ArgsFields_;
82
+ readonly args: ArgsSchema<ArgsFields_>;
57
83
  readonly returns: Returns;
58
84
  readonly error?: Error;
59
85
  readonly kind: Kind;
60
86
  }
61
87
 
62
- export interface AnyConfect extends Confect<
63
- Schema.Codec<any, any>,
64
- Schema.Codec<any, any>,
65
- Schema.Codec<any, any>
66
- > {}
88
+ export interface AnyConfect {
89
+ readonly _tag: "Confect";
90
+ readonly args: AnyArgsSchema;
91
+ readonly returns: Schema.Codec<any, any>;
92
+ readonly error?: Schema.Codec<any, any>;
93
+ readonly kind: ConfectKind;
94
+ }
67
95
 
68
96
  export interface Convex<Args extends DefaultFunctionArgs, Returns> {
69
97
  readonly _tag: "Convex";
70
- readonly _args: Args;
71
- readonly _returns: Returns;
98
+ readonly "~args": Args;
99
+ readonly "~returns": Returns;
72
100
  }
73
101
 
74
102
  export interface AnyConvex extends Convex<DefaultFunctionArgs, any> {}
@@ -78,13 +106,13 @@ export const FunctionProvenance = Data.taggedEnum<FunctionProvenance>();
78
106
  const Standard: Standard = { _tag: "Standard" };
79
107
 
80
108
  /**
81
- * Build a `Confect` provenance from lazy schema thunks. `args`, `returns`,
82
- * and `error` are exposed as sync lazy memoised getters (via {@link Lazy.defineProperty})
83
- * that only evaluate their thunk on first access, mirroring how `Table`
84
- * defers `Fields`/`Doc`/`tableDefinition`. This keeps importing the assembled
85
- * `_generated/spec.ts` cheap — no `Schema.Struct(...)` / `Schema.Array(...)`
86
- * work runs at module load; it is deferred to the first invocation that
87
- * actually compiles validators or runs a codec.
109
+ * Build a `Confect` provenance from lazy args-fields and schema thunks.
110
+ * `args`, `returns`, and `error` are exposed as sync lazy memoised getters
111
+ * (via {@link Lazy.defineProperty}) that only evaluate their thunk on first
112
+ * access, mirroring how `Table` defers `Fields`/`Doc`. This keeps importing the
113
+ * assembled `_generated/spec.ts` cheap — no `Schema.Struct(...)` /
114
+ * `Schema.Array(...)` work runs at module load; it is deferred to the first
115
+ * invocation that actually compiles validators or runs a codec.
88
116
  *
89
117
  * The object is built by hand rather than through `FunctionProvenance.Confect`
90
118
  * because the `Data` constructor copies its input with `Object.assign`, which
@@ -94,53 +122,40 @@ const Standard: Standard = { _tag: "Standard" };
94
122
  * relies on `Data`'s structural `Equal`/`Hash` for provenance values.
95
123
  */
96
124
  export const Confect = <
97
- Args extends Schema.Codec<any, any>,
125
+ const ArgsFields_ extends ArgsFields,
98
126
  Returns extends Schema.Codec<any, any>,
99
127
  Error extends Schema.Codec<any, any> = never,
100
128
  >(
101
- args: () => Args,
129
+ args: () => ArgsFields_,
102
130
  returns: () => Returns,
103
131
  error?: () => Error,
104
- ): Confect<Args, Returns, Error, Standard> => {
132
+ ): Confect<ArgsFields_, Returns, Error, Standard> => {
105
133
  const provenance = { _tag: "Confect" as const, kind: Standard };
106
134
 
107
- Lazy.defineProperty(provenance, "args", args);
135
+ Lazy.defineProperty(provenance, "args", () => Schema.Struct(args()));
108
136
  Lazy.defineProperty(provenance, "returns", returns);
109
137
  if (error !== undefined) {
110
138
  Lazy.defineProperty(provenance, "error", error);
111
139
  }
112
140
 
113
- return provenance as Confect<Args, Returns, Error, Standard>;
141
+ return provenance as Confect<ArgsFields_, Returns, Error, Standard>;
114
142
  };
115
143
 
116
- /**
117
- * Any struct-shaped, context-free schema usable as a paginated query's user
118
- * args. A structural bound rather than `Schema.Struct<Schema.Struct.Fields>`
119
- * because `Schema.Struct` is not covariant in its fields parameter — concrete
120
- * structs do not extend `Schema.Struct<Schema.Struct.Fields>`.
121
- */
122
- // eslint-disable-next-line import/namespace -- oxlint's namespace resolution misses type-only exports, and `Schema` is an interface/namespace
123
- export interface AnyUserArgs extends Schema.Codec<any, any> {
124
- readonly fields: Schema.Struct.Fields;
125
- }
126
-
127
144
  /**
128
145
  * The composed args schema of a paginated query: the user-declared fields
129
146
  * plus the `paginationOpts` field managed by Convex's pagination protocol.
130
147
  *
131
- * The `extends infer ... extends` conditional lets TypeScript accept the
132
- * composed struct where `Schema.Codec<any, any>` is required even while
133
- * `UserArgs` is an unresolved type parameter; for concrete user args it
134
- * evaluates away entirely.
148
+ * The fields-first representation keeps the user-declared map available for
149
+ * type-level composition without reconstructing it from an erased schema.
135
150
  */
136
- export type PaginatedArgs<UserArgs extends AnyUserArgs> =
137
- Schema.Struct<
138
- UserArgs["fields"] & {
139
- paginationOpts: typeof PaginationOptions.PaginationOptions;
140
- }
141
- > extends infer ComposedArgs extends Schema.Codec<any, any>
142
- ? ComposedArgs
143
- : never;
151
+ export type PaginatedArgsFields<UserArgsFields extends ArgsFields> =
152
+ UserArgsFields & {
153
+ readonly paginationOpts: typeof PaginationOptions.PaginationOptions;
154
+ };
155
+
156
+ export type PaginatedArgs<UserArgsFields extends ArgsFields> = Schema.Struct<
157
+ PaginatedArgsFields<UserArgsFields>
158
+ >;
144
159
 
145
160
  /**
146
161
  * The composed returns schema of a paginated query: a `PaginationResult` of
@@ -153,21 +168,19 @@ export type PaginatedReturns<Item extends Schema.Codec<any, any>> =
153
168
  : never;
154
169
 
155
170
  export interface ConfectPaginated<
156
- UserArgs extends AnyUserArgs,
171
+ UserArgsFields extends ArgsFields,
157
172
  Item extends Schema.Codec<any, any>,
158
173
  Error extends Schema.Codec<any, any> = never,
159
174
  > extends Confect<
160
- PaginatedArgs<UserArgs>,
175
+ PaginatedArgsFields<UserArgsFields>,
161
176
  PaginatedReturns<Item>,
162
177
  Error,
163
- Paginated<UserArgs, Item>
178
+ Paginated<UserArgsFields, Item>
164
179
  > {}
165
180
 
166
- export interface AnyConfectPaginated extends ConfectPaginated<
167
- AnyUserArgs,
168
- Schema.Codec<any, any>,
169
- Schema.Codec<any, any>
170
- > {}
181
+ export interface AnyConfectPaginated extends AnyConfect {
182
+ readonly kind: Paginated;
183
+ }
171
184
 
172
185
  /**
173
186
  * Build the provenance of a paginated query from lazy schema thunks, with the
@@ -180,25 +193,25 @@ export interface AnyConfectPaginated extends ConfectPaginated<
180
193
  * composed schemas can never drift from the stored user schemas.
181
194
  */
182
195
  export const ConfectPaginated = <
183
- UserArgs extends AnyUserArgs,
196
+ const UserArgsFields_ extends ArgsFields,
184
197
  Item extends Schema.Codec<any, any>,
185
198
  Error extends Schema.Codec<any, any> = never,
186
199
  >(
187
- userArgs: () => UserArgs,
200
+ userArgs: () => UserArgsFields_,
188
201
  item: () => Item,
189
202
  error?: () => Error,
190
- ): ConfectPaginated<UserArgs, Item, Error> => {
203
+ ): ConfectPaginated<UserArgsFields_, Item, Error> => {
191
204
  const kind = { _tag: "Paginated" as const };
192
- const paginatedKind = kind as Paginated<UserArgs, Item>;
205
+ const paginatedKind = kind as Paginated<UserArgsFields_, Item>;
193
206
 
194
- Lazy.defineProperty(kind, "userArgs", userArgs);
207
+ Lazy.defineProperty(kind, "userArgs", () => Schema.Struct(userArgs()));
195
208
  Lazy.defineProperty(kind, "item", item);
196
209
  Lazy.defineProperty(kind, "page", () =>
197
210
  Schema.mutable(Schema.Array(paginatedKind.item)),
198
211
  );
199
212
 
200
213
  const provenance = { _tag: "Confect" as const, kind: paginatedKind };
201
- const self = provenance as ConfectPaginated<UserArgs, Item, Error>;
214
+ const self = provenance as ConfectPaginated<UserArgsFields_, Item, Error>;
202
215
 
203
216
  Lazy.defineProperty(provenance, "args", () => {
204
217
  const fields = paginatedKind.userArgs.fields;
@@ -223,10 +236,10 @@ export const ConfectPaginated = <
223
236
  return self;
224
237
  };
225
238
 
226
- export const Convex = <_Args extends DefaultFunctionArgs, _Returns>() =>
239
+ export const Convex = <Args extends DefaultFunctionArgs, Returns>() =>
227
240
  FunctionProvenance.Convex(
228
241
  {} as {
229
- _args: _Args;
230
- _returns: _Returns;
242
+ "~args": Args;
243
+ "~returns": Returns;
231
244
  },
232
245
  );