@confect/server 9.0.0-next.1 → 9.0.0-next.10

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 (190) hide show
  1. package/CHANGELOG.md +293 -4
  2. package/dist/ActionCtx.d.ts +4 -11
  3. package/dist/ActionCtx.d.ts.map +1 -1
  4. package/dist/ActionCtx.js +1 -1
  5. package/dist/ActionCtx.js.map +1 -1
  6. package/dist/ActionRunner.d.ts +8 -13
  7. package/dist/ActionRunner.d.ts.map +1 -1
  8. package/dist/ActionRunner.js +4 -3
  9. package/dist/ActionRunner.js.map +1 -1
  10. package/dist/Auth.d.ts +17 -23
  11. package/dist/Auth.d.ts.map +1 -1
  12. package/dist/Auth.js +5 -1
  13. package/dist/Auth.js.map +1 -1
  14. package/dist/BlobNotFoundError.d.ts +6 -12
  15. package/dist/BlobNotFoundError.d.ts.map +1 -1
  16. package/dist/BlobNotFoundError.js +1 -1
  17. package/dist/BlobNotFoundError.js.map +1 -1
  18. package/dist/ConvexConfigProvider.d.ts +2 -9
  19. package/dist/ConvexConfigProvider.d.ts.map +1 -1
  20. package/dist/ConvexConfigProvider.js +6 -1
  21. package/dist/ConvexConfigProvider.js.map +1 -1
  22. package/dist/CronJob.d.ts +12 -19
  23. package/dist/CronJob.d.ts.map +1 -1
  24. package/dist/CronJob.js +1 -1
  25. package/dist/CronJob.js.map +1 -1
  26. package/dist/CronJobs.d.ts +11 -18
  27. package/dist/CronJobs.d.ts.map +1 -1
  28. package/dist/CronJobs.js +11 -4
  29. package/dist/CronJobs.js.map +1 -1
  30. package/dist/DataModel.d.ts +24 -29
  31. package/dist/DataModel.d.ts.map +1 -1
  32. package/dist/DatabaseReader.d.ts +4323 -64
  33. package/dist/DatabaseReader.d.ts.map +1 -1
  34. package/dist/DatabaseReader.js +6 -6
  35. package/dist/DatabaseReader.js.map +1 -1
  36. package/dist/DatabaseSchema.d.ts +38 -130
  37. package/dist/DatabaseSchema.d.ts.map +1 -1
  38. package/dist/DatabaseSchema.js +20 -30
  39. package/dist/DatabaseSchema.js.map +1 -1
  40. package/dist/DatabaseWriter.d.ts +38 -42
  41. package/dist/DatabaseWriter.d.ts.map +1 -1
  42. package/dist/DatabaseWriter.js +8 -5
  43. package/dist/DatabaseWriter.js.map +1 -1
  44. package/dist/Document.d.ts +28 -37
  45. package/dist/Document.d.ts.map +1 -1
  46. package/dist/Document.js +5 -1
  47. package/dist/Document.js.map +1 -1
  48. package/dist/FunctionImpl.d.ts +30 -29
  49. package/dist/FunctionImpl.d.ts.map +1 -1
  50. package/dist/FunctionImpl.js +25 -14
  51. package/dist/FunctionImpl.js.map +1 -1
  52. package/dist/GroupImpl.d.ts +45 -41
  53. package/dist/GroupImpl.d.ts.map +1 -1
  54. package/dist/GroupImpl.js +42 -35
  55. package/dist/GroupImpl.js.map +1 -1
  56. package/dist/Handler.d.ts +34 -40
  57. package/dist/Handler.d.ts.map +1 -1
  58. package/dist/HttpApi.d.ts +21 -25
  59. package/dist/HttpApi.d.ts.map +1 -1
  60. package/dist/HttpApi.js +11 -6
  61. package/dist/HttpApi.js.map +1 -1
  62. package/dist/MutationCtx.d.ts +4 -11
  63. package/dist/MutationCtx.d.ts.map +1 -1
  64. package/dist/MutationCtx.js +1 -1
  65. package/dist/MutationCtx.js.map +1 -1
  66. package/dist/MutationRunner.d.ts +8 -13
  67. package/dist/MutationRunner.d.ts.map +1 -1
  68. package/dist/MutationRunner.js +4 -3
  69. package/dist/MutationRunner.js.map +1 -1
  70. package/dist/OrderedQuery.d.ts +16 -21
  71. package/dist/OrderedQuery.d.ts.map +1 -1
  72. package/dist/OrderedQuery.js +4 -1
  73. package/dist/OrderedQuery.js.map +1 -1
  74. package/dist/QueryCtx.d.ts +4 -11
  75. package/dist/QueryCtx.d.ts.map +1 -1
  76. package/dist/QueryCtx.js +1 -1
  77. package/dist/QueryCtx.js.map +1 -1
  78. package/dist/QueryInitializer.d.ts +34 -39
  79. package/dist/QueryInitializer.d.ts.map +1 -1
  80. package/dist/QueryInitializer.js +5 -1
  81. package/dist/QueryInitializer.js.map +1 -1
  82. package/dist/QueryRunner.d.ts +8 -13
  83. package/dist/QueryRunner.d.ts.map +1 -1
  84. package/dist/QueryRunner.js +4 -3
  85. package/dist/QueryRunner.js.map +1 -1
  86. package/dist/RegisteredConvexFunction.d.ts +1107 -60
  87. package/dist/RegisteredConvexFunction.d.ts.map +1 -1
  88. package/dist/RegisteredConvexFunction.js +14 -9
  89. package/dist/RegisteredConvexFunction.js.map +1 -1
  90. package/dist/RegisteredFunction.d.ts +48 -64
  91. package/dist/RegisteredFunction.d.ts.map +1 -1
  92. package/dist/RegisteredFunction.js +9 -5
  93. package/dist/RegisteredFunction.js.map +1 -1
  94. package/dist/RegisteredFunctions.d.ts +48 -26
  95. package/dist/RegisteredFunctions.d.ts.map +1 -1
  96. package/dist/RegisteredFunctions.js +22 -9
  97. package/dist/RegisteredFunctions.js.map +1 -1
  98. package/dist/RegisteredNodeFunction.d.ts +4 -14
  99. package/dist/RegisteredNodeFunction.d.ts.map +1 -1
  100. package/dist/RegisteredNodeFunction.js +5 -4
  101. package/dist/RegisteredNodeFunction.js.map +1 -1
  102. package/dist/RegistryItem.d.ts +17 -27
  103. package/dist/RegistryItem.d.ts.map +1 -1
  104. package/dist/RegistryItem.js +1 -1
  105. package/dist/RegistryItem.js.map +1 -1
  106. package/dist/Scheduler.d.ts +16 -20
  107. package/dist/Scheduler.d.ts.map +1 -1
  108. package/dist/Scheduler.js +10 -6
  109. package/dist/Scheduler.js.map +1 -1
  110. package/dist/SchemaToValidator.d.ts +71 -64
  111. package/dist/SchemaToValidator.d.ts.map +1 -1
  112. package/dist/SchemaToValidator.js +15 -3
  113. package/dist/SchemaToValidator.js.map +1 -1
  114. package/dist/StorageActionWriter.d.ts +21 -28
  115. package/dist/StorageActionWriter.d.ts.map +1 -1
  116. package/dist/StorageActionWriter.js +4 -1
  117. package/dist/StorageActionWriter.js.map +1 -1
  118. package/dist/StorageReader.d.ts +14 -21
  119. package/dist/StorageReader.d.ts.map +1 -1
  120. package/dist/StorageReader.js +5 -1
  121. package/dist/StorageReader.js.map +1 -1
  122. package/dist/StorageWriter.d.ts +16 -23
  123. package/dist/StorageWriter.d.ts.map +1 -1
  124. package/dist/StorageWriter.js +4 -1
  125. package/dist/StorageWriter.js.map +1 -1
  126. package/dist/Table.d.ts +204 -197
  127. package/dist/Table.d.ts.map +1 -1
  128. package/dist/Table.js +72 -62
  129. package/dist/Table.js.map +1 -1
  130. package/dist/TableInfo.d.ts +35 -41
  131. package/dist/TableInfo.d.ts.map +1 -1
  132. package/dist/VectorSearch.d.ts +30 -35
  133. package/dist/VectorSearch.d.ts.map +1 -1
  134. package/dist/VectorSearch.js +3 -1
  135. package/dist/VectorSearch.js.map +1 -1
  136. package/dist/index.d.ts +35 -36
  137. package/dist/index.d.ts.map +1 -0
  138. package/dist/index.js +4 -5
  139. package/dist/internal/utils.d.ts +9 -11
  140. package/dist/internal/utils.d.ts.map +1 -1
  141. package/dist/internal/utils.js +3 -1
  142. package/dist/internal/utils.js.map +1 -1
  143. package/dist/node.d.ts +2 -2
  144. package/dist/node.d.ts.map +1 -0
  145. package/dist/tsconfig.src.tsbuildinfo +1 -0
  146. package/package.json +50 -59
  147. package/src/ActionCtx.ts +1 -1
  148. package/src/ActionRunner.ts +2 -1
  149. package/src/Auth.ts +5 -1
  150. package/src/BlobNotFoundError.ts +1 -1
  151. package/src/ConvexConfigProvider.ts +6 -8
  152. package/src/CronJob.ts +1 -1
  153. package/src/CronJobs.ts +8 -10
  154. package/src/DatabaseReader.ts +18 -21
  155. package/src/DatabaseSchema.ts +38 -98
  156. package/src/DatabaseWriter.ts +13 -6
  157. package/src/Document.ts +5 -1
  158. package/src/FunctionImpl.ts +36 -44
  159. package/src/GroupImpl.ts +54 -81
  160. package/src/HttpApi.ts +8 -9
  161. package/src/MutationCtx.ts +1 -1
  162. package/src/MutationRunner.ts +2 -1
  163. package/src/OrderedQuery.ts +5 -1
  164. package/src/QueryCtx.ts +1 -1
  165. package/src/QueryInitializer.ts +15 -3
  166. package/src/QueryRunner.ts +2 -1
  167. package/src/RegisteredConvexFunction.ts +11 -7
  168. package/src/RegisteredFunction.ts +5 -1
  169. package/src/RegisteredFunctions.ts +69 -93
  170. package/src/RegisteredNodeFunction.ts +7 -6
  171. package/src/RegistryItem.ts +1 -1
  172. package/src/Scheduler.ts +5 -1
  173. package/src/SchemaToValidator.ts +14 -16
  174. package/src/StorageActionWriter.ts +4 -1
  175. package/src/StorageReader.ts +5 -1
  176. package/src/StorageWriter.ts +4 -1
  177. package/src/Table.ts +253 -132
  178. package/src/VectorSearch.ts +3 -1
  179. package/src/index.ts +0 -1
  180. package/src/internal/utils.ts +3 -1
  181. package/dist/Api.d.ts +0 -30
  182. package/dist/Api.d.ts.map +0 -1
  183. package/dist/Api.js +0 -26
  184. package/dist/Api.js.map +0 -1
  185. package/dist/GroupPath.d.ts +0 -8
  186. package/dist/GroupPath.d.ts.map +0 -1
  187. package/dist/GroupPath.js +0 -10
  188. package/dist/GroupPath.js.map +0 -1
  189. package/src/Api.ts +0 -75
  190. package/src/GroupPath.ts +0 -43
@@ -17,22 +17,20 @@ import type {
17
17
  VUnion,
18
18
  } from "convex/values";
19
19
  import { v } from "convex/values";
20
- import {
21
- Array,
22
- Cause,
23
- Data,
24
- Effect,
25
- Exit,
26
- Match,
27
- Number,
28
- Option,
29
- type ParseResult,
30
- pipe,
31
- Predicate,
32
- Schema,
33
- SchemaAST,
34
- String,
35
- } from "effect";
20
+ import { pipe } from "effect/Function";
21
+ import type { ParseResult } from "effect";
22
+ import * as Array from "effect/Array";
23
+ import * as Cause from "effect/Cause";
24
+ import * as Data from "effect/Data";
25
+ import * as Effect from "effect/Effect";
26
+ import * as Exit from "effect/Exit";
27
+ import * as Match from "effect/Match";
28
+ import * as Number from "effect/Number";
29
+ import * as Option from "effect/Option";
30
+ import * as Predicate from "effect/Predicate";
31
+ import * as Schema from "effect/Schema";
32
+ import * as SchemaAST from "effect/SchemaAST";
33
+ import * as String from "effect/String";
36
34
 
37
35
  import * as GenericId from "@confect/core/GenericId";
38
36
  import type {
@@ -1,6 +1,9 @@
1
1
  import type { StorageActionWriter as ConvexStorageActionWriter } from "convex/server";
2
2
  import type { GenericId } from "convex/values";
3
- import { Effect, flow, Layer, Option } from "effect";
3
+ import { flow } from "effect/Function";
4
+ import * as Effect from "effect/Effect";
5
+ import * as Layer from "effect/Layer";
6
+ import * as Option from "effect/Option";
4
7
  import { BlobNotFoundError } from "./BlobNotFoundError";
5
8
 
6
9
  const make = (storageActionWriter: ConvexStorageActionWriter) => ({
@@ -1,6 +1,10 @@
1
1
  import type { StorageReader as ConvexStorageReader } from "convex/server";
2
2
  import type { GenericId } from "convex/values";
3
- import { Effect, flow, Layer, Option, pipe, Schema } from "effect";
3
+ import { flow, pipe } from "effect/Function";
4
+ import * as Effect from "effect/Effect";
5
+ import * as Layer from "effect/Layer";
6
+ import * as Option from "effect/Option";
7
+ import * as Schema from "effect/Schema";
4
8
  import { BlobNotFoundError } from "./BlobNotFoundError";
5
9
 
6
10
  const make = (storageReader: ConvexStorageReader) => ({
@@ -1,6 +1,9 @@
1
1
  import type { StorageWriter as ConvexStorageWriter } from "convex/server";
2
2
  import type { GenericId } from "convex/values";
3
- import { Effect, Layer, pipe, Schema } from "effect";
3
+ import { pipe } from "effect/Function";
4
+ import * as Effect from "effect/Effect";
5
+ import * as Layer from "effect/Layer";
6
+ import * as Schema from "effect/Schema";
4
7
  import { BlobNotFoundError } from "./BlobNotFoundError";
5
8
 
6
9
  const make = (storageWriter: ConvexStorageWriter) => ({
package/src/Table.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import * as Lazy from "@confect/core/Lazy";
1
2
  import * as SystemFields from "@confect/core/SystemFields";
2
3
  import {
3
4
  defineTable,
@@ -12,7 +13,8 @@ import {
12
13
  type VectorIndexConfig,
13
14
  } from "convex/server";
14
15
  import type { GenericValidator, Validator } from "convex/values";
15
- import { Predicate, Schema } from "effect";
16
+ import * as Predicate from "effect/Predicate";
17
+ import * as Schema from "effect/Schema";
16
18
  import {
17
19
  compileTableSchema,
18
20
  type TableSchemaToTableValidator,
@@ -21,8 +23,26 @@ import {
21
23
  export const TypeId = "@confect/server/Table";
22
24
  export type TypeId = typeof TypeId;
23
25
 
26
+ // -----------------------------------------------------------------------------
27
+ // Predicates
28
+ // -----------------------------------------------------------------------------
29
+ //
30
+ // Both bound `Table`s and `UnnamedTable` callables share the same `[TypeId]`
31
+ // brand. They disambiguate by whether a `tableName` property is set: bound
32
+ // tables have one, unnamed callables do not.
33
+ //
34
+ // The discriminator is `tableName` (not `name`) so it does not collide with
35
+ // the built-in `Function.prototype.name` that every JS function carries.
36
+
24
37
  export const isTable = (u: unknown): u is Any =>
25
- Predicate.hasProperty(u, TypeId);
38
+ Predicate.hasProperty(u, TypeId) && Predicate.hasProperty(u, "tableName");
39
+
40
+ export const isUnnamedTable = (u: unknown): u is UnnamedAny =>
41
+ Predicate.hasProperty(u, TypeId) && !Predicate.hasProperty(u, "tableName");
42
+
43
+ // -----------------------------------------------------------------------------
44
+ // Bound Table
45
+ // -----------------------------------------------------------------------------
26
46
 
27
47
  export interface Table<
28
48
  Name_ extends string,
@@ -34,18 +54,65 @@ export interface Table<
34
54
  VectorIndexes_ extends GenericTableVectorIndexes = {},
35
55
  > {
36
56
  readonly [TypeId]: TypeId;
57
+ readonly tableName: Name_;
37
58
  readonly tableDefinition: TableDefinition<
38
59
  TableValidator_,
39
60
  Indexes_,
40
61
  SearchIndexes_,
41
62
  VectorIndexes_
42
63
  >;
43
-
44
- readonly name: Name_;
45
-
46
64
  readonly Fields: TableSchema_;
47
65
  readonly Doc: SystemFields.ExtendWithSystemFields<Name_, TableSchema_>;
66
+ readonly indexes: Indexes_;
67
+ }
68
+
69
+ export interface Any {
70
+ readonly [TypeId]: TypeId;
71
+ readonly tableName: string;
72
+ }
73
+
74
+ export type AnyWithProps = Table<
75
+ any,
76
+ Schema.Schema.AnyNoContext,
77
+ GenericValidator,
78
+ GenericTableIndexes,
79
+ GenericTableSearchIndexes,
80
+ GenericTableVectorIndexes
81
+ >;
82
+
83
+ // -----------------------------------------------------------------------------
84
+ // UnnamedTable (callable)
85
+ // -----------------------------------------------------------------------------
86
+ //
87
+ // `Table.make(lazyFields)` returns an `UnnamedTable`: a callable that
88
+ // produces a fully bound `Table` when invoked with a name. Chaining methods
89
+ // (`.index`, `.searchIndex`, `.vectorIndex`) live here and return new
90
+ // `UnnamedTable`s, accumulating plain index metadata records. Neither the
91
+ // field-schema nor the deploy-time `tableDefinition` is constructed at this
92
+ // stage — the user-supplied `lazyFields` callback is just carried through.
93
+ // The codegen pipeline emits a wrapper file per user-authored table that
94
+ // simply invokes the unnamed callable with the filename basename.
95
+
96
+ export interface UnnamedTable<
97
+ TableSchema_ extends Schema.Schema.AnyNoContext,
98
+ TableValidator_ extends GenericValidator =
99
+ TableSchemaToTableValidator<TableSchema_>,
100
+ Indexes_ extends GenericTableIndexes = {},
101
+ SearchIndexes_ extends GenericTableSearchIndexes = {},
102
+ VectorIndexes_ extends GenericTableVectorIndexes = {},
103
+ > {
104
+ <const Name_ extends string>(
105
+ tableName: Name_,
106
+ ): Table<
107
+ Name_,
108
+ TableSchema_,
109
+ TableValidator_,
110
+ Indexes_,
111
+ SearchIndexes_,
112
+ VectorIndexes_
113
+ >;
48
114
 
115
+ readonly [TypeId]: TypeId;
49
116
  readonly indexes: Indexes_;
50
117
 
51
118
  index<
@@ -55,8 +122,7 @@ export interface Table<
55
122
  >(
56
123
  name: IndexName,
57
124
  fields: [FirstFieldPath, ...RestFieldPaths],
58
- ): Table<
59
- Name_,
125
+ ): UnnamedTable<
60
126
  TableSchema_,
61
127
  TableValidator_,
62
128
  Expand<
@@ -77,8 +143,7 @@ export interface Table<
77
143
  >(
78
144
  name: IndexName,
79
145
  indexConfig: Expand<SearchIndexConfig<SearchField, FilterFields>>,
80
- ): Table<
81
- Name_,
146
+ ): UnnamedTable<
82
147
  TableSchema_,
83
148
  TableValidator_,
84
149
  Indexes_,
@@ -102,8 +167,7 @@ export interface Table<
102
167
  >(
103
168
  name: IndexName,
104
169
  indexConfig: Expand<VectorIndexConfig<VectorField, FilterFields>>,
105
- ): Table<
106
- Name_,
170
+ ): UnnamedTable<
107
171
  TableSchema_,
108
172
  TableValidator_,
109
173
  Indexes_,
@@ -122,12 +186,11 @@ export interface Table<
122
186
  >;
123
187
  }
124
188
 
125
- export interface Any {
189
+ export interface UnnamedAny {
126
190
  readonly [TypeId]: TypeId;
127
191
  }
128
192
 
129
- export type AnyWithProps = Table<
130
- any,
193
+ export type UnnamedAnyWithProps = UnnamedTable<
131
194
  Schema.Schema.AnyNoContext,
132
195
  GenericValidator,
133
196
  GenericTableIndexes,
@@ -135,6 +198,10 @@ export type AnyWithProps = Table<
135
198
  GenericTableVectorIndexes
136
199
  >;
137
200
 
201
+ // -----------------------------------------------------------------------------
202
+ // Type extractors
203
+ // -----------------------------------------------------------------------------
204
+
138
205
  export type Name<TableDef extends AnyWithProps> =
139
206
  TableDef extends Table<
140
207
  infer TableName,
@@ -234,162 +301,217 @@ export type Fields<TableDef extends AnyWithProps> =
234
301
  export type WithName<
235
302
  TableDef extends AnyWithProps,
236
303
  Name_ extends string,
237
- > = TableDef extends { readonly name: Name_ } ? TableDef : never;
304
+ > = TableDef extends { readonly tableName: Name_ } ? TableDef : never;
238
305
 
239
306
  export type TablesRecord<Tables extends AnyWithProps> = {
240
307
  readonly [TableName_ in Name<Tables>]: WithName<Tables, TableName_>;
241
308
  };
242
309
 
243
- const Proto = {
244
- [TypeId]: TypeId,
245
-
246
- index<
247
- IndexName extends string,
248
- FirstFieldPath extends string,
249
- RestFieldPaths extends string[],
250
- >(
251
- this: AnyWithProps,
252
- name: IndexName,
253
- fields: [FirstFieldPath, ...RestFieldPaths],
254
- ) {
255
- return makeProto({
256
- name: this.name,
257
- Fields: this.Fields,
258
- Doc: this.Doc,
259
- tableDefinition: this.tableDefinition.index(name, fields as any),
260
- indexes: {
261
- ...this.indexes,
262
- [name]: fields,
263
- },
264
- });
265
- },
266
-
267
- searchIndex<IndexName extends string, SearchField extends string>(
268
- this: AnyWithProps,
269
- name: IndexName,
270
- indexConfig: SearchIndexConfig<SearchField, any>,
271
- ) {
272
- return makeProto({
273
- name: this.name,
274
- Fields: this.Fields,
275
- Doc: this.Doc,
276
- tableDefinition: this.tableDefinition.searchIndex(name, indexConfig),
277
- indexes: this.indexes,
278
- });
279
- },
280
-
281
- vectorIndex<IndexName extends string, VectorField extends string>(
282
- this: AnyWithProps,
283
- name: IndexName,
284
- indexConfig: {
285
- vectorField: VectorField;
286
- dimensions: number;
287
- filterFields?: string[] | undefined;
288
- },
289
- ) {
290
- return makeProto({
291
- name: this.name,
292
- Fields: this.Fields,
293
- Doc: this.Doc,
294
- tableDefinition: this.tableDefinition.vectorIndex(name, {
295
- vectorField: indexConfig.vectorField,
296
- dimensions: indexConfig.dimensions,
297
- ...(indexConfig.filterFields
298
- ? { filterFields: indexConfig.filterFields }
299
- : {}),
300
- }),
301
- indexes: this.indexes,
302
- });
303
- },
304
- };
310
+ // -----------------------------------------------------------------------------
311
+ // Construction
312
+ // -----------------------------------------------------------------------------
313
+ //
314
+ // `make` only stores the user-supplied `lazyFields` callback alongside any
315
+ // chained index metadata. Neither `Fields` nor `Doc` nor `tableDefinition`
316
+ // is constructed until first access on a bound `Table`. Each chain step is
317
+ // O(1) (plain object spread of the metadata records) and never invokes the
318
+ // callback. Binding via `unnamed(tableName)` installs lazy memoised getters
319
+ // for `Fields`, `Doc`, and `tableDefinition` via `Lazy.defineProperty`, so the
320
+ // first access materialises the value and replaces the getter with a plain
321
+ // data property — second-and-subsequent accesses are observably
322
+ // indistinguishable from a plain property and avoid all function-call
323
+ // overhead.
324
+
325
+ interface UnnamedState<
326
+ TableSchema_ extends Schema.Schema.AnyNoContext,
327
+ Indexes_ extends GenericTableIndexes,
328
+ SearchIndexes_ extends GenericTableSearchIndexes,
329
+ VectorIndexes_ extends GenericTableVectorIndexes,
330
+ > {
331
+ readonly lazyFields: () => TableSchema_;
332
+ readonly indexes: Indexes_;
333
+ readonly searchIndexes: SearchIndexes_;
334
+ readonly vectorIndexes: VectorIndexes_;
335
+ }
305
336
 
306
- const makeProto = <
337
+ const makeBound = <
307
338
  Name_ extends string,
308
339
  TableSchema_ extends Schema.Schema.AnyNoContext,
309
340
  TableValidator_ extends Validator<any, any, any>,
310
341
  Indexes_ extends GenericTableIndexes,
311
342
  SearchIndexes_ extends GenericTableSearchIndexes,
312
343
  VectorIndexes_ extends GenericTableVectorIndexes,
313
- >({
314
- name,
315
- Fields,
316
- Doc,
317
- tableDefinition,
318
- indexes,
319
- }: {
320
- name: Name_;
321
- Fields: TableSchema_;
322
- Doc: SystemFields.ExtendWithSystemFields<Name_, TableSchema_>;
323
- tableDefinition: TableDefinition<
324
- TableValidator_,
325
- Indexes_,
326
- SearchIndexes_,
327
- VectorIndexes_
328
- >;
329
- indexes: Indexes_;
330
- }): Table<
344
+ >(
345
+ tableName: Name_,
346
+ state: UnnamedState<TableSchema_, Indexes_, SearchIndexes_, VectorIndexes_>,
347
+ ): Table<
331
348
  Name_,
332
349
  TableSchema_,
333
350
  TableValidator_,
334
351
  Indexes_,
335
352
  SearchIndexes_,
336
353
  VectorIndexes_
337
- > =>
338
- Object.assign(Object.create(Proto), {
339
- name,
340
- Fields,
341
- Doc,
342
- tableDefinition,
343
- indexes,
354
+ > => {
355
+ const bound = {
356
+ [TypeId]: TypeId as TypeId,
357
+ tableName,
358
+ indexes: state.indexes,
359
+ } as Table<
360
+ Name_,
361
+ TableSchema_,
362
+ TableValidator_,
363
+ Indexes_,
364
+ SearchIndexes_,
365
+ VectorIndexes_
366
+ >;
367
+
368
+ Lazy.defineProperty(bound, "Fields", () => state.lazyFields());
369
+
370
+ Lazy.defineProperty(bound, "Doc", () =>
371
+ SystemFields.extendWithSystemFields(
372
+ tableName,
373
+ (bound as { Fields: TableSchema_ }).Fields,
374
+ ),
375
+ );
376
+
377
+ Lazy.defineProperty(bound, "tableDefinition", () => {
378
+ const fields = (bound as { Fields: TableSchema_ }).Fields;
379
+ let definition: TableDefinition<any, any, any, any> = defineTable(
380
+ compileTableSchema(fields),
381
+ );
382
+ for (const [name, indexFields] of Object.entries(
383
+ state.indexes as Record<string, any>,
384
+ )) {
385
+ definition = definition.index(name, indexFields);
386
+ }
387
+ for (const [name, config] of Object.entries(
388
+ state.searchIndexes as Record<string, any>,
389
+ )) {
390
+ definition = definition.searchIndex(name, config);
391
+ }
392
+ for (const [name, config] of Object.entries(
393
+ state.vectorIndexes as Record<string, any>,
394
+ )) {
395
+ definition = definition.vectorIndex(name, config);
396
+ }
397
+ return definition;
344
398
  });
345
399
 
346
- /**
347
- * Create a table.
348
- */
349
- export const make = <
350
- const Name_ extends string,
400
+ return bound;
401
+ };
402
+
403
+ const makeUnnamed = <
351
404
  TableSchema_ extends Schema.Schema.AnyNoContext,
352
- TableValidator_ extends GenericValidator =
353
- TableSchemaToTableValidator<TableSchema_>,
354
- Indexes_ extends GenericTableIndexes = {},
355
- SearchIndexes_ extends GenericTableSearchIndexes = {},
356
- VectorIndexes_ extends GenericTableVectorIndexes = {},
405
+ TableValidator_ extends Validator<any, any, any>,
406
+ Indexes_ extends GenericTableIndexes,
407
+ SearchIndexes_ extends GenericTableSearchIndexes,
408
+ VectorIndexes_ extends GenericTableVectorIndexes,
357
409
  >(
358
- name: Name_,
359
- fields: TableSchema_,
360
- ): Table<
361
- Name_,
410
+ state: UnnamedState<TableSchema_, Indexes_, SearchIndexes_, VectorIndexes_>,
411
+ ): UnnamedTable<
362
412
  TableSchema_,
363
413
  TableValidator_,
364
414
  Indexes_,
365
415
  SearchIndexes_,
366
416
  VectorIndexes_
367
417
  > => {
368
- const tableValidator = compileTableSchema(fields) as any;
369
- const tableDefinition = defineTable(tableValidator) as any;
418
+ type UnnamedTable_ = UnnamedTable<
419
+ TableSchema_,
420
+ TableValidator_,
421
+ Indexes_,
422
+ SearchIndexes_,
423
+ VectorIndexes_
424
+ >;
370
425
 
371
- return makeProto<
426
+ type UnnamedTableFunction<FunctionName extends keyof UnnamedTable_> =
427
+ UnnamedTable_[FunctionName];
428
+
429
+ const bind = <const Name_ extends string>(
430
+ tableName: Name_,
431
+ ): Table<
372
432
  Name_,
373
433
  TableSchema_,
374
434
  TableValidator_,
375
435
  Indexes_,
376
436
  SearchIndexes_,
377
437
  VectorIndexes_
378
- >({
438
+ > =>
439
+ makeBound<
440
+ Name_,
441
+ TableSchema_,
442
+ TableValidator_,
443
+ Indexes_,
444
+ SearchIndexes_,
445
+ VectorIndexes_
446
+ >(tableName, state);
447
+
448
+ const index: UnnamedTableFunction<"index"> = (name, fields) =>
449
+ makeUnnamed({
450
+ lazyFields: state.lazyFields,
451
+ indexes: {
452
+ ...state.indexes,
453
+ [name]: fields,
454
+ } as any,
455
+ searchIndexes: state.searchIndexes,
456
+ vectorIndexes: state.vectorIndexes,
457
+ });
458
+
459
+ const searchIndex: UnnamedTableFunction<"searchIndex"> = (
379
460
  name,
380
- Fields: fields,
381
- Doc: SystemFields.extendWithSystemFields(name, fields),
382
- tableDefinition,
383
- indexes: {} as Indexes_,
384
- });
461
+ indexConfig,
462
+ ) =>
463
+ makeUnnamed({
464
+ lazyFields: state.lazyFields,
465
+ indexes: state.indexes,
466
+ searchIndexes: {
467
+ ...state.searchIndexes,
468
+ [name]: indexConfig,
469
+ } as any,
470
+ vectorIndexes: state.vectorIndexes,
471
+ });
472
+
473
+ const vectorIndex: UnnamedTableFunction<"vectorIndex"> = (
474
+ name,
475
+ indexConfig,
476
+ ) =>
477
+ makeUnnamed({
478
+ lazyFields: state.lazyFields,
479
+ indexes: state.indexes,
480
+ searchIndexes: state.searchIndexes,
481
+ vectorIndexes: {
482
+ ...state.vectorIndexes,
483
+ [name]: indexConfig,
484
+ } as any,
485
+ });
486
+
487
+ return Object.assign(bind, {
488
+ [TypeId]: TypeId as TypeId,
489
+ indexes: state.indexes,
490
+ index,
491
+ searchIndex,
492
+ vectorIndex,
493
+ }) satisfies UnnamedTable_;
494
+ };
495
+
496
+ export const make = <const TableSchema_ extends Schema.Schema.AnyNoContext>(
497
+ lazyFields: () => TableSchema_,
498
+ ): UnnamedTable<TableSchema_, TableSchemaToTableValidator<TableSchema_>> => {
499
+ type TableValidator_ = TableSchemaToTableValidator<TableSchema_>;
500
+ type UnnamedTable_ = UnnamedTable<TableSchema_, TableValidator_>;
501
+
502
+ return makeUnnamed<TableSchema_, TableValidator_, {}, {}, {}>({
503
+ lazyFields,
504
+ indexes: {},
505
+ searchIndexes: {},
506
+ vectorIndexes: {},
507
+ }) satisfies UnnamedTable_;
385
508
  };
386
509
 
387
510
  // -----------------------------------------------------------------------------
388
511
  // System tables
389
512
  // -----------------------------------------------------------------------------
390
513
 
391
- export const scheduledFunctionsTable = make(
392
- "_scheduled_functions",
514
+ export const scheduledFunctionsTable = make(() =>
393
515
  Schema.Struct({
394
516
  name: Schema.String,
395
517
  args: Schema.Array(Schema.Any),
@@ -406,16 +528,15 @@ export const scheduledFunctionsTable = make(
406
528
  Schema.Struct({ kind: Schema.Literal("canceled") }),
407
529
  ),
408
530
  }),
409
- );
531
+ )("_scheduled_functions");
410
532
 
411
- export const storageTable = make(
412
- "_storage",
533
+ export const storageTable = make(() =>
413
534
  Schema.Struct({
414
535
  sha256: Schema.String,
415
536
  size: Schema.Number,
416
537
  contentType: Schema.optionalWith(Schema.String, { exact: true }),
417
538
  }),
418
- );
539
+ )("_storage");
419
540
 
420
541
  export const systemTables = {
421
542
  _scheduled_functions: scheduledFunctionsTable,
@@ -6,7 +6,9 @@ import type {
6
6
  VectorSearchQuery,
7
7
  } from "convex/server";
8
8
  import type { GenericId } from "convex/values";
9
- import { Context, Effect, Layer } from "effect";
9
+ import * as Context from "effect/Context";
10
+ import * as Effect from "effect/Effect";
11
+ import * as Layer from "effect/Layer";
10
12
  import type * as DataModel from "./DataModel";
11
13
 
12
14
  type ConvexVectorSearch<DataModel_ extends DataModel.AnyWithProps> =
package/src/index.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  export * as ActionCtx from "./ActionCtx";
2
2
  export * as ActionRunner from "./ActionRunner";
3
- export * as Api from "./Api";
4
3
  export * as Auth from "./Auth";
5
4
  export * as BlobNotFoundError from "./BlobNotFoundError";
6
5
  export * as ConvexConfigProvider from "./ConvexConfigProvider";
@@ -1,5 +1,7 @@
1
1
  import type { Predicate } from "effect";
2
- import { Array, Effect, Record } from "effect";
2
+ import * as Array from "effect/Array";
3
+ import * as Effect from "effect/Effect";
4
+ import * as Record from "effect/Record";
3
5
 
4
6
  type NestedObject<T> = {
5
7
  [key: string]: T | NestedObject<T>;
package/dist/Api.d.ts DELETED
@@ -1,30 +0,0 @@
1
- import { AnyWithProps as AnyWithProps$1 } from "./DatabaseSchema.js";
2
- import { GenericSchema, SchemaDefinition } from "convex/server";
3
- import { RuntimeAndFunctionType } from "@confect/core";
4
- import * as Spec from "@confect/core/Spec";
5
-
6
- //#region src/Api.d.ts
7
- declare namespace Api_d_exports {
8
- export { Any, AnyWithProps, AnyWithPropsWithRuntime, Api, GetSpec, Groups, Schema, TypeId, isApi, make };
9
- }
10
- declare const TypeId = "@confect/server/Api";
11
- type TypeId = typeof TypeId;
12
- declare const isApi: (u: unknown) => u is Any;
13
- interface Api<DatabaseSchema_ extends AnyWithProps$1, Spec_ extends Spec.AnyWithProps> {
14
- readonly [TypeId]: TypeId;
15
- readonly spec: Spec_;
16
- readonly databaseSchema: DatabaseSchema_;
17
- readonly convexSchemaDefinition: SchemaDefinition<GenericSchema, true>;
18
- }
19
- interface Any {
20
- readonly [TypeId]: TypeId;
21
- }
22
- interface AnyWithProps extends Api<AnyWithProps$1, Spec.AnyWithProps> {}
23
- interface AnyWithPropsWithRuntime<Runtime extends RuntimeAndFunctionType.Runtime> extends Api<AnyWithProps$1, Spec.AnyWithPropsWithRuntime<Runtime>> {}
24
- type Schema<Api_ extends AnyWithProps> = Api_["databaseSchema"];
25
- type GetSpec<Api_ extends AnyWithProps> = Api_["spec"];
26
- type Groups<Api_ extends AnyWithProps> = Spec.Groups<Api_["spec"]>;
27
- declare const make: <DatabaseSchema_ extends AnyWithProps$1, Spec_ extends Spec.AnyWithProps>(databaseSchema: DatabaseSchema_, spec: Spec_) => Api<DatabaseSchema_, Spec_>;
28
- //#endregion
29
- export { Any, AnyWithProps, AnyWithPropsWithRuntime, Api, Api_d_exports, GetSpec, Groups, Schema, TypeId, isApi, make };
30
- //# sourceMappingURL=Api.d.ts.map
package/dist/Api.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"Api.d.ts","names":[],"sources":["../src/Api.ts"],"mappings":";;;;;;;;;cAOa,MAAA;AAAA,KACD,MAAA,UAAgB,MAAA;AAAA,cAEf,KAAA,GAAS,CAAA,cAAa,CAAA,IAAK,GAAA;AAAA,UAEvB,GAAA,yBACS,cAAA,gBACV,IAAA,CAAK,YAAA;EAAA,UAET,MAAA,GAAS,MAAA;EAAA,SACV,IAAA,EAAM,KAAA;EAAA,SACN,cAAA,EAAgB,eAAA;EAAA,SAChB,sBAAA,EAAwB,gBAAA,CAAiB,aAAA;AAAA;AAAA,UAGnC,GAAA;EAAA,UACL,MAAA,GAAS,MAAA;AAAA;AAAA,UAGJ,YAAA,SAAqB,GAAA,CACpC,cAAA,EACA,IAAA,CAAK,YAAA;AAAA,UAGU,uBAAA,iBACC,sBAAA,CAAuB,OAAA,UAC/B,GAAA,CACR,cAAA,EACA,IAAA,CAAK,uBAAA,CAAwB,OAAA;AAAA,KAGnB,MAAA,cAAoB,YAAA,IAAgB,IAAA;AAAA,KAEpC,OAAA,cAAqB,YAAA,IAAgB,IAAA;AAAA,KAErC,MAAA,cAAoB,YAAA,IAAgB,IAAA,CAAK,MAAA,CAAO,IAAA;AAAA,cA0B/C,IAAA,2BACa,cAAA,gBACV,IAAA,CAAK,YAAA,EAEnB,cAAA,EAAgB,eAAA,EAChB,IAAA,EAAM,KAAA,KACL,GAAA,CAAI,eAAA,EAAiB,KAAA"}
package/dist/Api.js DELETED
@@ -1,26 +0,0 @@
1
- import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
- import { Predicate, Record, pipe } from "effect";
3
- import { defineSchema } from "convex/server";
4
-
5
- //#region src/Api.ts
6
- var Api_exports = /* @__PURE__ */ __exportAll({
7
- TypeId: () => TypeId,
8
- isApi: () => isApi,
9
- make: () => make
10
- });
11
- const TypeId = "@confect/server/Api";
12
- const isApi = (u) => Predicate.hasProperty(u, TypeId);
13
- const Proto = { [TypeId]: TypeId };
14
- const makeProto = ({ databaseSchema, spec }) => Object.assign(Object.create(Proto), {
15
- databaseSchema,
16
- spec,
17
- convexSchemaDefinition: pipe(databaseSchema.tables, Record.map(({ tableDefinition }) => tableDefinition), defineSchema)
18
- });
19
- const make = (databaseSchema, spec) => makeProto({
20
- databaseSchema,
21
- spec
22
- });
23
-
24
- //#endregion
25
- export { Api_exports, TypeId, isApi, make };
26
- //# sourceMappingURL=Api.js.map