@confect/core 10.0.0-next.2 → 10.0.0-next.21

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 (94) hide show
  1. package/CHANGELOG.md +531 -0
  2. package/README.md +3 -1
  3. package/dist/FunctionProvenance.d.ts +155 -65
  4. package/dist/FunctionProvenance.d.ts.map +1 -1
  5. package/dist/FunctionProvenance.js +51 -10
  6. package/dist/FunctionProvenance.js.map +1 -1
  7. package/dist/FunctionSpec.d.ts +314 -138
  8. package/dist/FunctionSpec.d.ts.map +1 -1
  9. package/dist/FunctionSpec.js +50 -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 +1 -4
  14. package/dist/GroupPath.d.ts.map +1 -1
  15. package/dist/GroupPath.js.map +1 -1
  16. package/dist/GroupSpec.d.ts +16 -10
  17. package/dist/GroupSpec.d.ts.map +1 -1
  18. package/dist/GroupSpec.js +34 -11
  19. package/dist/GroupSpec.js.map +1 -1
  20. package/dist/Identifier.d.ts.map +1 -1
  21. package/dist/Lazy.d.ts +2 -3
  22. package/dist/Lazy.d.ts.map +1 -1
  23. package/dist/Lazy.js +2 -3
  24. package/dist/Lazy.js.map +1 -1
  25. package/dist/MiddlewareSpec.d.ts +184 -0
  26. package/dist/MiddlewareSpec.d.ts.map +1 -0
  27. package/dist/MiddlewareSpec.js +55 -0
  28. package/dist/MiddlewareSpec.js.map +1 -0
  29. package/dist/PaginationError.d.ts +14 -0
  30. package/dist/PaginationError.d.ts.map +1 -0
  31. package/dist/PaginationError.js +25 -0
  32. package/dist/PaginationError.js.map +1 -0
  33. package/dist/PaginationOptions.d.ts +23 -0
  34. package/dist/PaginationOptions.d.ts.map +1 -0
  35. package/dist/PaginationOptions.js +29 -0
  36. package/dist/PaginationOptions.js.map +1 -0
  37. package/dist/PaginationResult.d.ts +1 -0
  38. package/dist/PaginationResult.d.ts.map +1 -1
  39. package/dist/PaginationResult.js.map +1 -1
  40. package/dist/Ref.d.ts +120 -39
  41. package/dist/Ref.d.ts.map +1 -1
  42. package/dist/Ref.js +94 -38
  43. package/dist/Ref.js.map +1 -1
  44. package/dist/Refs.d.ts +9 -4
  45. package/dist/Refs.d.ts.map +1 -1
  46. package/dist/Refs.js +3 -3
  47. package/dist/Refs.js.map +1 -1
  48. package/dist/SchemaToValidator.d.ts +99 -0
  49. package/dist/SchemaToValidator.d.ts.map +1 -0
  50. package/dist/SchemaToValidator.js +156 -0
  51. package/dist/SchemaToValidator.js.map +1 -0
  52. package/dist/Spec.d.ts +3 -2
  53. package/dist/Spec.d.ts.map +1 -1
  54. package/dist/Spec.js +1 -1
  55. package/dist/Spec.js.map +1 -1
  56. package/dist/SystemFields.d.ts +1 -1
  57. package/dist/SystemFields.d.ts.map +1 -1
  58. package/dist/SystemFields.js +2 -2
  59. package/dist/SystemFields.js.map +1 -1
  60. package/dist/Table.d.ts +74 -0
  61. package/dist/Table.d.ts.map +1 -0
  62. package/dist/Table.js +77 -0
  63. package/dist/Table.js.map +1 -0
  64. package/dist/Types.d.ts +8 -2
  65. package/dist/Types.d.ts.map +1 -1
  66. package/dist/Types.js.map +1 -1
  67. package/dist/UserIdentity.d.ts.map +1 -1
  68. package/dist/index.d.ts +5 -1
  69. package/dist/index.d.ts.map +1 -1
  70. package/dist/index.js +7 -3
  71. package/package.json +15 -14
  72. package/src/FunctionProvenance.ts +186 -31
  73. package/src/FunctionSpec.ts +313 -85
  74. package/src/GroupPath.ts +1 -6
  75. package/src/GroupSpec.ts +125 -18
  76. package/src/Lazy.ts +2 -3
  77. package/src/MiddlewareSpec.ts +356 -0
  78. package/src/PaginationError.ts +72 -0
  79. package/src/PaginationOptions.ts +23 -0
  80. package/src/PaginationResult.ts +4 -0
  81. package/src/Ref.ts +429 -208
  82. package/src/Refs.ts +41 -16
  83. package/src/SchemaToValidator.ts +603 -0
  84. package/src/Spec.ts +4 -4
  85. package/src/SystemFields.ts +6 -9
  86. package/src/Table.ts +426 -0
  87. package/src/Types.ts +9 -3
  88. package/src/index.ts +5 -1
  89. package/dist/Registry.d.ts +0 -24
  90. package/dist/Registry.d.ts.map +0 -1
  91. package/dist/Registry.js +0 -19
  92. package/dist/Registry.js.map +0 -1
  93. package/dist/tsconfig.src.tsbuildinfo +0 -1
  94. package/src/Registry.ts +0 -30
package/src/Spec.ts CHANGED
@@ -2,7 +2,7 @@ import * as Predicate from "effect/Predicate";
2
2
  import * as Record from "effect/Record";
3
3
  import * as GroupSpec from "./GroupSpec";
4
4
 
5
- export const TypeId = "@confect/core/Spec";
5
+ export const TypeId = "~@confect/core/Spec";
6
6
  export type TypeId = typeof TypeId;
7
7
 
8
8
  export const isSpec = (u: unknown): u is AnyWithProps =>
@@ -23,6 +23,7 @@ export interface Spec<Groups_ extends GroupSpec.AnyWithProps = never> {
23
23
  GroupName
24
24
  >;
25
25
  };
26
+ readonly "~Groups": Groups_;
26
27
 
27
28
  add<Group extends GroupSpec.AnyWithProps>(
28
29
  group: Group,
@@ -40,8 +41,7 @@ export interface Any {
40
41
 
41
42
  export interface AnyWithProps extends Spec<GroupSpec.AnyWithProps> {}
42
43
 
43
- export type Groups<Spec_ extends AnyWithProps> =
44
- Spec_["groups"][keyof Spec_["groups"]];
44
+ export type Groups<Spec_ extends AnyWithProps> = Spec_["~Groups"];
45
45
 
46
46
  const Proto = {
47
47
  [TypeId]: TypeId,
@@ -70,6 +70,6 @@ const makeProto = <Groups_ extends GroupSpec.AnyWithProps>({
70
70
  }): Spec<Groups_> =>
71
71
  Object.assign(Object.create(Proto), {
72
72
  groups,
73
- });
73
+ }) as Spec<Groups_>;
74
74
 
75
75
  export const make = (): Spec => makeProto({ groups: {} });
@@ -18,7 +18,7 @@ import * as GenericId from "./GenericId";
18
18
  export const SystemFields = <TableName extends string>(tableName: TableName) =>
19
19
  Schema.Struct({
20
20
  _id: GenericId.GenericId(tableName),
21
- _creationTime: Schema.Number,
21
+ _creationTime: Schema.Finite,
22
22
  });
23
23
 
24
24
  /**
@@ -58,9 +58,9 @@ const splitSystemFields = (input: { [key: PropertyKey]: unknown }) => {
58
58
  * output. Transformations construct fresh objects, so without this the system
59
59
  * fields would be dropped at every transformation step.
60
60
  */
61
- const wrapGetter = (
62
- getter: SchemaGetter.Getter<any, any, any>,
63
- ): SchemaGetter.Getter<any, any, any> =>
61
+ const wrapGetter = <R>(
62
+ getter: SchemaGetter.Getter<any, any, R>,
63
+ ): SchemaGetter.Getter<any, any, R> =>
64
64
  new SchemaGetter.Getter((input, options) => {
65
65
  if (Option.isNone(input) || !Predicate.isObject(input.value)) {
66
66
  return getter.run(input, options);
@@ -191,9 +191,7 @@ export const extendWithSystemFields = <
191
191
  if (
192
192
  s.ast.encoding === undefined &&
193
193
  SchemaAST.isUnion(s.ast) &&
194
- Array.isArray(
195
- (s as Partial<Schema.Union<ReadonlyArray<Schema.Top>>>).members,
196
- )
194
+ Array.isArray((s as { readonly members?: unknown }).members)
197
195
  ) {
198
196
  return Schema.Union(
199
197
  Array.map(
@@ -205,8 +203,7 @@ export const extendWithSystemFields = <
205
203
  if (
206
204
  s.ast.encoding === undefined &&
207
205
  SchemaAST.isObjects(s.ast) &&
208
- typeof (s as Partial<Schema.Struct<Schema.Struct.Fields>>).mapFields ===
209
- "function"
206
+ typeof (s as { readonly mapFields?: unknown }).mapFields === "function"
210
207
  ) {
211
208
  return Schema.fieldsAssign(system)(
212
209
  s as Schema.Struct<Schema.Struct.Fields>,
package/src/Table.ts ADDED
@@ -0,0 +1,426 @@
1
+ import * as Lazy from "./Lazy";
2
+ import * as SystemFields from "./SystemFields";
3
+ import type { TableSchemaToTableValidator } from "./SchemaToValidator";
4
+ import type {
5
+ SystemFields as ConvexSystemFields,
6
+ Expand,
7
+ GenericTableIndexes,
8
+ GenericTableSearchIndexes,
9
+ GenericTableVectorIndexes,
10
+ IndexTiebreakerField,
11
+ SearchIndexConfig,
12
+ VectorIndexConfig,
13
+ } from "convex/server";
14
+ import type { GenericValidator, Validator } from "convex/values";
15
+ import * as Predicate from "effect/Predicate";
16
+ import type * as Schema from "effect/Schema";
17
+
18
+ export const TypeId = "~@confect/core/Table";
19
+ export type TypeId = typeof TypeId;
20
+
21
+ // -----------------------------------------------------------------------------
22
+ // Predicates
23
+ // -----------------------------------------------------------------------------
24
+ //
25
+ // Both bound `Table`s and `UnnamedTable` callables share the same `[TypeId]`
26
+ // brand. They disambiguate by whether a `tableName` property is set: bound
27
+ // tables have one, unnamed callables do not.
28
+ //
29
+ // The discriminator is `tableName` (not `name`) so it does not collide with
30
+ // the built-in `Function.prototype.name` that every JS function carries.
31
+
32
+ export const isTable = (u: unknown): u is Any =>
33
+ Predicate.hasProperty(u, TypeId) && Predicate.hasProperty(u, "tableName");
34
+
35
+ export const isUnnamedTable = (u: unknown): u is UnnamedAny =>
36
+ Predicate.hasProperty(u, TypeId) && !Predicate.hasProperty(u, "tableName");
37
+
38
+ // -----------------------------------------------------------------------------
39
+ // Bound Table
40
+ // -----------------------------------------------------------------------------
41
+ //
42
+ // A bound `Table` is the client-safe document schema: `Fields`, `Doc`, and
43
+ // the index metadata records. The Convex deploy `tableDefinition` (which
44
+ // value-imports `convex/server`) is produced separately by
45
+ // `@confect/server/Table.tableDefinition`.
46
+
47
+ export interface Table<
48
+ Name_ extends string,
49
+ TableSchema_ extends Schema.Codec<any, any>,
50
+ TableValidator_ extends GenericValidator =
51
+ TableSchemaToTableValidator<TableSchema_>,
52
+ Indexes_ extends GenericTableIndexes = {},
53
+ SearchIndexes_ extends GenericTableSearchIndexes = {},
54
+ VectorIndexes_ extends GenericTableVectorIndexes = {},
55
+ > {
56
+ readonly [TypeId]: TypeId;
57
+ readonly tableName: Name_;
58
+ readonly Fields: TableSchema_;
59
+ readonly Doc: SystemFields.ExtendWithSystemFields<Name_, TableSchema_>;
60
+ readonly indexes: Indexes_;
61
+ readonly searchIndexes: SearchIndexes_;
62
+ readonly vectorIndexes: VectorIndexes_;
63
+ readonly "~TableValidator": TableValidator_;
64
+ }
65
+
66
+ export interface Any {
67
+ readonly [TypeId]: TypeId;
68
+ readonly tableName: string;
69
+ }
70
+
71
+ export type AnyWithProps = Table<
72
+ any,
73
+ Schema.Codec<any, any>,
74
+ GenericValidator,
75
+ GenericTableIndexes,
76
+ GenericTableSearchIndexes,
77
+ GenericTableVectorIndexes
78
+ >;
79
+
80
+ // -----------------------------------------------------------------------------
81
+ // UnnamedTable (callable)
82
+ // -----------------------------------------------------------------------------
83
+ //
84
+ // `Table.make(lazyFields)` returns an `UnnamedTable`: a callable that
85
+ // produces a fully bound `Table` when invoked with a name. Chaining methods
86
+ // (`.index`, `.searchIndex`, `.vectorIndex`) live here and return new
87
+ // `UnnamedTable`s, accumulating plain index metadata records. The
88
+ // user-supplied `lazyFields` callback is just carried through until first
89
+ // access of `Fields` / `Doc` on a bound table. The codegen pipeline emits a
90
+ // wrapper file per user-authored table that simply invokes the unnamed
91
+ // callable with the filename basename.
92
+
93
+ export interface UnnamedTable<
94
+ TableSchema_ extends Schema.Codec<any, any>,
95
+ TableValidator_ extends GenericValidator =
96
+ TableSchemaToTableValidator<TableSchema_>,
97
+ Indexes_ extends GenericTableIndexes = {},
98
+ SearchIndexes_ extends GenericTableSearchIndexes = {},
99
+ VectorIndexes_ extends GenericTableVectorIndexes = {},
100
+ > {
101
+ <const Name_ extends string>(
102
+ tableName: Name_,
103
+ ): Table<
104
+ Name_,
105
+ TableSchema_,
106
+ TableValidator_,
107
+ Indexes_,
108
+ SearchIndexes_,
109
+ VectorIndexes_
110
+ >;
111
+
112
+ readonly [TypeId]: TypeId;
113
+ readonly indexes: Indexes_;
114
+ readonly searchIndexes: SearchIndexes_;
115
+ readonly vectorIndexes: VectorIndexes_;
116
+ readonly "~TableValidator": TableValidator_;
117
+
118
+ index<
119
+ IndexName extends string,
120
+ FirstFieldPath extends ExtractFieldPaths<TableValidator_>,
121
+ RestFieldPaths extends ExtractFieldPaths<TableValidator_>[],
122
+ >(
123
+ name: IndexName,
124
+ fields: [FirstFieldPath, ...RestFieldPaths],
125
+ ): UnnamedTable<
126
+ TableSchema_,
127
+ TableValidator_,
128
+ Expand<
129
+ Indexes_ &
130
+ Record<
131
+ IndexName,
132
+ [FirstFieldPath, ...RestFieldPaths, IndexTiebreakerField]
133
+ >
134
+ >,
135
+ SearchIndexes_,
136
+ VectorIndexes_
137
+ >;
138
+
139
+ searchIndex<
140
+ IndexName extends string,
141
+ SearchField extends ExtractFieldPaths<TableValidator_>,
142
+ FilterFields extends ExtractFieldPaths<TableValidator_> = never,
143
+ >(
144
+ name: IndexName,
145
+ indexConfig: Expand<SearchIndexConfig<SearchField, FilterFields>>,
146
+ ): UnnamedTable<
147
+ TableSchema_,
148
+ TableValidator_,
149
+ Indexes_,
150
+ Expand<
151
+ SearchIndexes_ &
152
+ Record<
153
+ IndexName,
154
+ {
155
+ searchField: SearchField;
156
+ filterFields: FilterFields;
157
+ }
158
+ >
159
+ >,
160
+ VectorIndexes_
161
+ >;
162
+
163
+ vectorIndex<
164
+ IndexName extends string,
165
+ VectorField extends ExtractFieldPaths<TableValidator_>,
166
+ FilterFields extends ExtractFieldPaths<TableValidator_> = never,
167
+ >(
168
+ name: IndexName,
169
+ indexConfig: Expand<VectorIndexConfig<VectorField, FilterFields>>,
170
+ ): UnnamedTable<
171
+ TableSchema_,
172
+ TableValidator_,
173
+ Indexes_,
174
+ SearchIndexes_,
175
+ Expand<
176
+ VectorIndexes_ &
177
+ Record<
178
+ IndexName,
179
+ {
180
+ vectorField: VectorField;
181
+ dimensions: number;
182
+ filterFields: FilterFields;
183
+ }
184
+ >
185
+ >
186
+ >;
187
+ }
188
+
189
+ export interface UnnamedAny {
190
+ readonly [TypeId]: TypeId;
191
+ }
192
+
193
+ export type UnnamedAnyWithProps = UnnamedTable<
194
+ Schema.Codec<any, any>,
195
+ GenericValidator,
196
+ GenericTableIndexes,
197
+ GenericTableSearchIndexes,
198
+ GenericTableVectorIndexes
199
+ >;
200
+
201
+ // -----------------------------------------------------------------------------
202
+ // Type extractors
203
+ // -----------------------------------------------------------------------------
204
+
205
+ export type Name<TableDef extends AnyWithProps> = TableDef["tableName"] &
206
+ string;
207
+
208
+ export type TableSchema<TableDef extends AnyWithProps> = TableDef["Fields"];
209
+
210
+ export type TableValidator<TableDef extends AnyWithProps> =
211
+ TableDef["~TableValidator"];
212
+
213
+ export type Indexes<TableDef extends AnyWithProps> = TableDef["indexes"];
214
+
215
+ export type SearchIndexes<TableDef extends AnyWithProps> =
216
+ TableDef["searchIndexes"];
217
+
218
+ export type VectorIndexes<TableDef extends AnyWithProps> =
219
+ TableDef["vectorIndexes"];
220
+
221
+ export type Doc<TableDef extends AnyWithProps> = TableDef["Doc"];
222
+
223
+ export type Fields<TableDef extends AnyWithProps> = TableDef["Fields"];
224
+
225
+ export type WithName<
226
+ TableDef extends AnyWithProps,
227
+ Name_ extends string,
228
+ > = TableDef extends { readonly tableName: Name_ } ? TableDef : never;
229
+
230
+ export type TablesRecord<Tables extends AnyWithProps> = {
231
+ readonly [TableName_ in Name<Tables>]: WithName<Tables, TableName_>;
232
+ };
233
+
234
+ // -----------------------------------------------------------------------------
235
+ // Construction
236
+ // -----------------------------------------------------------------------------
237
+ //
238
+ // `make` only stores the user-supplied `lazyFields` callback alongside any
239
+ // chained index metadata. Neither `Fields` nor `Doc` is constructed until
240
+ // first access on a bound `Table`. Each chain step is O(1) (plain object
241
+ // spread of the metadata records) and never invokes the callback. Binding
242
+ // via `unnamed(tableName)` installs lazy memoised getters for `Fields` and
243
+ // `Doc` via `Lazy.defineProperty`, so the first access materialises the
244
+ // value and replaces the getter with a plain data property — second-and-
245
+ // subsequent accesses are observably indistinguishable from a plain
246
+ // property and avoid all function-call overhead.
247
+
248
+ interface UnnamedState<
249
+ TableSchema_ extends Schema.Codec<any, any>,
250
+ Indexes_ extends GenericTableIndexes,
251
+ SearchIndexes_ extends GenericTableSearchIndexes,
252
+ VectorIndexes_ extends GenericTableVectorIndexes,
253
+ > {
254
+ readonly lazyFields: () => TableSchema_;
255
+ readonly indexes: Indexes_;
256
+ readonly searchIndexes: SearchIndexes_;
257
+ readonly vectorIndexes: VectorIndexes_;
258
+ }
259
+
260
+ const makeBound = <
261
+ Name_ extends string,
262
+ TableSchema_ extends Schema.Codec<any, any>,
263
+ TableValidator_ extends Validator<any, any, any>,
264
+ Indexes_ extends GenericTableIndexes,
265
+ SearchIndexes_ extends GenericTableSearchIndexes,
266
+ VectorIndexes_ extends GenericTableVectorIndexes,
267
+ >(
268
+ tableName: Name_,
269
+ state: UnnamedState<TableSchema_, Indexes_, SearchIndexes_, VectorIndexes_>,
270
+ ): Table<
271
+ Name_,
272
+ TableSchema_,
273
+ TableValidator_,
274
+ Indexes_,
275
+ SearchIndexes_,
276
+ VectorIndexes_
277
+ > => {
278
+ const bound = {
279
+ [TypeId]: TypeId as TypeId,
280
+ tableName,
281
+ indexes: state.indexes,
282
+ searchIndexes: state.searchIndexes,
283
+ vectorIndexes: state.vectorIndexes,
284
+ } as Table<
285
+ Name_,
286
+ TableSchema_,
287
+ TableValidator_,
288
+ Indexes_,
289
+ SearchIndexes_,
290
+ VectorIndexes_
291
+ >;
292
+
293
+ Lazy.defineProperty(bound, "Fields", () => state.lazyFields());
294
+
295
+ Lazy.defineProperty(bound, "Doc", () =>
296
+ SystemFields.extendWithSystemFields(
297
+ tableName,
298
+ (bound as { Fields: TableSchema_ }).Fields,
299
+ ),
300
+ );
301
+
302
+ return bound;
303
+ };
304
+
305
+ const makeUnnamed = <
306
+ TableSchema_ extends Schema.Codec<any, any>,
307
+ TableValidator_ extends Validator<any, any, any>,
308
+ Indexes_ extends GenericTableIndexes,
309
+ SearchIndexes_ extends GenericTableSearchIndexes,
310
+ VectorIndexes_ extends GenericTableVectorIndexes,
311
+ >(
312
+ state: UnnamedState<TableSchema_, Indexes_, SearchIndexes_, VectorIndexes_>,
313
+ ): UnnamedTable<
314
+ TableSchema_,
315
+ TableValidator_,
316
+ Indexes_,
317
+ SearchIndexes_,
318
+ VectorIndexes_
319
+ > => {
320
+ type UnnamedTable_ = UnnamedTable<
321
+ TableSchema_,
322
+ TableValidator_,
323
+ Indexes_,
324
+ SearchIndexes_,
325
+ VectorIndexes_
326
+ >;
327
+
328
+ type UnnamedTableFunction<FunctionName extends keyof UnnamedTable_> =
329
+ UnnamedTable_[FunctionName];
330
+
331
+ const bind = <const Name_ extends string>(
332
+ tableName: Name_,
333
+ ): Table<
334
+ Name_,
335
+ TableSchema_,
336
+ TableValidator_,
337
+ Indexes_,
338
+ SearchIndexes_,
339
+ VectorIndexes_
340
+ > =>
341
+ makeBound<
342
+ Name_,
343
+ TableSchema_,
344
+ TableValidator_,
345
+ Indexes_,
346
+ SearchIndexes_,
347
+ VectorIndexes_
348
+ >(tableName, state);
349
+
350
+ const index: UnnamedTableFunction<"index"> = (name, fields) =>
351
+ makeUnnamed({
352
+ lazyFields: state.lazyFields,
353
+ indexes: {
354
+ ...state.indexes,
355
+ [name]: fields,
356
+ } as any,
357
+ searchIndexes: state.searchIndexes,
358
+ vectorIndexes: state.vectorIndexes,
359
+ });
360
+
361
+ const searchIndex: UnnamedTableFunction<"searchIndex"> = (
362
+ name,
363
+ indexConfig,
364
+ ) =>
365
+ makeUnnamed({
366
+ lazyFields: state.lazyFields,
367
+ indexes: state.indexes,
368
+ searchIndexes: {
369
+ ...state.searchIndexes,
370
+ [name]: indexConfig,
371
+ } as any,
372
+ vectorIndexes: state.vectorIndexes,
373
+ });
374
+
375
+ const vectorIndex: UnnamedTableFunction<"vectorIndex"> = (
376
+ name,
377
+ indexConfig,
378
+ ) =>
379
+ makeUnnamed({
380
+ lazyFields: state.lazyFields,
381
+ indexes: state.indexes,
382
+ searchIndexes: state.searchIndexes,
383
+ vectorIndexes: {
384
+ ...state.vectorIndexes,
385
+ [name]: indexConfig,
386
+ } as any,
387
+ });
388
+
389
+ return Object.assign(bind, {
390
+ [TypeId]: TypeId as TypeId,
391
+ indexes: state.indexes,
392
+ searchIndexes: state.searchIndexes,
393
+ vectorIndexes: state.vectorIndexes,
394
+ index,
395
+ searchIndex,
396
+ vectorIndex,
397
+ }) as UnnamedTable_;
398
+ };
399
+
400
+ export const make = <const TableSchema_ extends Schema.Codec<any, any>>(
401
+ lazyFields: () => TableSchema_,
402
+ ): UnnamedTable<TableSchema_, TableSchemaToTableValidator<TableSchema_>> => {
403
+ type TableValidator_ = TableSchemaToTableValidator<TableSchema_>;
404
+ type UnnamedTable_ = UnnamedTable<TableSchema_, TableValidator_>;
405
+
406
+ return makeUnnamed<TableSchema_, TableValidator_, {}, {}, {}>({
407
+ lazyFields,
408
+ indexes: {},
409
+ searchIndexes: {},
410
+ vectorIndexes: {},
411
+ }) as UnnamedTable_;
412
+ };
413
+
414
+ // Vendored types from convex-js, partially modified. Ideally we could use these directly. See https://github.com/get-convex/convex-js/pull/14
415
+
416
+ /**
417
+ * Extract all of the index field paths within a Convex `Validator`.
418
+ *
419
+ * This is used when declaring table indexes.
420
+ * @public
421
+ */
422
+ type ExtractFieldPaths<T extends Validator<any, any, any>> =
423
+ // Add in the system fields available in index definitions.
424
+ // This should be everything except for `_id` because thats added to indexes
425
+ // automatically.
426
+ T["fieldPaths"] | keyof ConvexSystemFields;
package/src/Types.ts CHANGED
@@ -72,9 +72,15 @@ export type DeepMutable<T> =
72
72
  : DeepMutable<T[K]>;
73
73
  };
74
74
 
75
- export type TypeError<Message extends string, T = never> = [Message, T];
76
-
77
- export type TypeDefect<Message extends string, T = never> = [Message, T];
75
+ export interface TypeError<Message extends string, T = never> {
76
+ readonly "~@confect/core/Types/TypeError": Message;
77
+ readonly "~value"?: T;
78
+ }
79
+
80
+ export interface TypeDefect<Message extends string, T = never> {
81
+ readonly "~@confect/core/Types/TypeDefect": Message;
82
+ readonly "~value"?: T;
83
+ }
78
84
 
79
85
  export type IsRecursive<T> = true extends DetectCycle<T> ? true : false;
80
86
 
package/src/index.ts CHANGED
@@ -5,12 +5,16 @@ export * as GroupPath from "./GroupPath";
5
5
  export * as GroupSpec from "./GroupSpec";
6
6
  export * as Identifier from "./Identifier";
7
7
  export * as Lazy from "./Lazy";
8
+ export * as MiddlewareSpec from "./MiddlewareSpec";
9
+ export * as PaginationError from "./PaginationError";
10
+ export * as PaginationOptions from "./PaginationOptions";
8
11
  export * as PaginationResult from "./PaginationResult";
9
12
  export * as Ref from "./Ref";
10
13
  export * as Refs from "./Refs";
11
- export * as Registry from "./Registry";
12
14
  export * as RuntimeAndFunctionType from "./RuntimeAndFunctionType";
15
+ export * as SchemaToValidator from "./SchemaToValidator";
13
16
  export * as Spec from "./Spec";
14
17
  export * as SystemFields from "./SystemFields";
18
+ export * as Table from "./Table";
15
19
  export * as Types from "./Types";
16
20
  export * as UserIdentity from "./UserIdentity";
@@ -1,24 +0,0 @@
1
- import * as Context from "effect/Context";
2
- import * as Ref from "effect/Ref";
3
- /**
4
- * Recursive tree that mirrors a `Spec`'s group structure. Leaves are the
5
- * per-function items written by each `FunctionImpl`'s layer initializer. The
6
- * leaf type is intentionally `unknown` here so `@confect/core` does not need
7
- * to know about `@confect/server`'s `RegistryItem` shape; producers and
8
- * consumers (the server runtime and the CLI's `implValidation`) narrow as
9
- * needed.
10
- */
11
- export interface RegistryItems {
12
- readonly [key: string]: unknown | RegistryItems;
13
- }
14
- /**
15
- * Effect `Context.Reference` keyed by `@confect/core/Registry`. Lives in
16
- * `@confect/core` so `@confect/server` (which writes to it from
17
- * `FunctionImpl` initializers and reads it from `RegisteredFunctions`) and
18
- * `@confect/cli` (which inspects it during impl validation) can share the
19
- * exact same `Ref` instance by importing the same tag — without relying on
20
- * Effect's global default-value cache to align two separately-defined tags
21
- * by string key.
22
- */
23
- export declare const Registry: Context.Reference<Ref.Ref<RegistryItems>>;
24
- //# sourceMappingURL=Registry.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Registry.d.ts","sourceRoot":"","sources":["../src/Registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,GAAG,MAAM,YAAY,CAAC;AAElC;;;;;;;GAOG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,GAAG,aAAa,CAAC;CACjD;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,QAAQ,2CAKpB,CAAC"}
package/dist/Registry.js DELETED
@@ -1,19 +0,0 @@
1
- import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
- import * as Context from "effect/Context";
3
- import * as Ref from "effect/Ref";
4
- //#region src/Registry.ts
5
- var Registry_exports = /* @__PURE__ */ __exportAll({ Registry: () => Registry });
6
- /**
7
- * Effect `Context.Reference` keyed by `@confect/core/Registry`. Lives in
8
- * `@confect/core` so `@confect/server` (which writes to it from
9
- * `FunctionImpl` initializers and reads it from `RegisteredFunctions`) and
10
- * `@confect/cli` (which inspects it during impl validation) can share the
11
- * exact same `Ref` instance by importing the same tag — without relying on
12
- * Effect's global default-value cache to align two separately-defined tags
13
- * by string key.
14
- */
15
- const Registry = Context.Reference("@confect/core/Registry", { defaultValue: () => Ref.makeUnsafe({}) });
16
- //#endregion
17
- export { Registry, Registry_exports };
18
-
19
- //# sourceMappingURL=Registry.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Registry.js","names":[],"sources":["../src/Registry.ts"],"sourcesContent":["import * as Context from \"effect/Context\";\nimport * as Ref from \"effect/Ref\";\n\n/**\n * Recursive tree that mirrors a `Spec`'s group structure. Leaves are the\n * per-function items written by each `FunctionImpl`'s layer initializer. The\n * leaf type is intentionally `unknown` here so `@confect/core` does not need\n * to know about `@confect/server`'s `RegistryItem` shape; producers and\n * consumers (the server runtime and the CLI's `implValidation`) narrow as\n * needed.\n */\nexport interface RegistryItems {\n readonly [key: string]: unknown | RegistryItems;\n}\n\n/**\n * Effect `Context.Reference` keyed by `@confect/core/Registry`. Lives in\n * `@confect/core` so `@confect/server` (which writes to it from\n * `FunctionImpl` initializers and reads it from `RegisteredFunctions`) and\n * `@confect/cli` (which inspects it during impl validation) can share the\n * exact same `Ref` instance by importing the same tag — without relying on\n * Effect's global default-value cache to align two separately-defined tags\n * by string key.\n */\nexport const Registry = Context.Reference<Ref.Ref<RegistryItems>>(\n \"@confect/core/Registry\",\n {\n defaultValue: () => Ref.makeUnsafe<RegistryItems>({}),\n },\n);\n"],"mappings":";;;;;;;;;;;;;;AAwBA,MAAa,WAAW,QAAQ,UAC9B,0BACA,EACE,oBAAoB,IAAI,WAA0B,CAAC,CAAC,EACtD,CACF"}