@confect/server 9.0.0-next.5 → 9.0.0-next.6
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.
- package/CHANGELOG.md +156 -0
- package/dist/Auth.d.ts +1 -1
- package/dist/DatabaseReader.d.ts +4299 -26
- package/dist/DatabaseReader.d.ts.map +1 -1
- package/dist/DatabaseReader.js +5 -6
- package/dist/DatabaseReader.js.map +1 -1
- package/dist/DatabaseSchema.d.ts +25 -112
- package/dist/DatabaseSchema.d.ts.map +1 -1
- package/dist/DatabaseSchema.js +20 -30
- package/dist/DatabaseSchema.js.map +1 -1
- package/dist/DatabaseWriter.d.ts +4 -4
- package/dist/DatabaseWriter.d.ts.map +1 -1
- package/dist/DatabaseWriter.js +3 -4
- package/dist/DatabaseWriter.js.map +1 -1
- package/dist/FunctionImpl.d.ts +26 -17
- package/dist/FunctionImpl.d.ts.map +1 -1
- package/dist/FunctionImpl.js +22 -14
- package/dist/FunctionImpl.js.map +1 -1
- package/dist/GroupImpl.d.ts +22 -13
- package/dist/GroupImpl.d.ts.map +1 -1
- package/dist/GroupImpl.js +34 -35
- package/dist/GroupImpl.js.map +1 -1
- package/dist/Handler.d.ts +1 -1
- package/dist/QueryInitializer.d.ts +1 -1
- package/dist/QueryInitializer.d.ts.map +1 -1
- package/dist/QueryInitializer.js.map +1 -1
- package/dist/RegisteredConvexFunction.d.ts +1084 -17
- package/dist/RegisteredConvexFunction.d.ts.map +1 -1
- package/dist/RegisteredConvexFunction.js +4 -4
- package/dist/RegisteredConvexFunction.js.map +1 -1
- package/dist/RegisteredFunction.d.ts +3 -3
- package/dist/RegisteredFunction.d.ts.map +1 -1
- package/dist/RegisteredFunctions.d.ts +36 -12
- package/dist/RegisteredFunctions.d.ts.map +1 -1
- package/dist/RegisteredFunctions.js +21 -9
- package/dist/RegisteredFunctions.js.map +1 -1
- package/dist/RegisteredNodeFunction.d.ts +4 -4
- package/dist/RegisteredNodeFunction.d.ts.map +1 -1
- package/dist/RegisteredNodeFunction.js +2 -2
- package/dist/RegisteredNodeFunction.js.map +1 -1
- package/dist/StorageActionWriter.d.ts +1 -1
- package/dist/Table.d.ts +35 -27
- package/dist/Table.d.ts.map +1 -1
- package/dist/Table.js +69 -60
- package/dist/Table.js.map +1 -1
- package/dist/index.d.ts +4 -5
- package/dist/index.js +4 -5
- package/package.json +51 -52
- package/src/DatabaseReader.ts +17 -21
- package/src/DatabaseSchema.ts +38 -98
- package/src/DatabaseWriter.ts +8 -5
- package/src/FunctionImpl.ts +33 -43
- package/src/GroupImpl.ts +45 -69
- package/src/QueryInitializer.ts +10 -2
- package/src/RegisteredConvexFunction.ts +5 -6
- package/src/RegisteredFunctions.ts +67 -93
- package/src/RegisteredNodeFunction.ts +3 -4
- package/src/Table.ts +251 -131
- package/src/index.ts +0 -1
- package/dist/Api.d.ts +0 -43
- package/dist/Api.d.ts.map +0 -1
- package/dist/Api.js +0 -43
- package/dist/Api.js.map +0 -1
- package/src/Api.ts +0 -102
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,
|
|
@@ -21,8 +22,26 @@ import {
|
|
|
21
22
|
export const TypeId = "@confect/server/Table";
|
|
22
23
|
export type TypeId = typeof TypeId;
|
|
23
24
|
|
|
25
|
+
// -----------------------------------------------------------------------------
|
|
26
|
+
// Predicates
|
|
27
|
+
// -----------------------------------------------------------------------------
|
|
28
|
+
//
|
|
29
|
+
// Both bound `Table`s and `UnnamedTable` callables share the same `[TypeId]`
|
|
30
|
+
// brand. They disambiguate by whether a `tableName` property is set: bound
|
|
31
|
+
// tables have one, unnamed callables do not.
|
|
32
|
+
//
|
|
33
|
+
// The discriminator is `tableName` (not `name`) so it does not collide with
|
|
34
|
+
// the built-in `Function.prototype.name` that every JS function carries.
|
|
35
|
+
|
|
24
36
|
export const isTable = (u: unknown): u is Any =>
|
|
25
|
-
Predicate.hasProperty(u, TypeId);
|
|
37
|
+
Predicate.hasProperty(u, TypeId) && Predicate.hasProperty(u, "tableName");
|
|
38
|
+
|
|
39
|
+
export const isUnnamedTable = (u: unknown): u is UnnamedAny =>
|
|
40
|
+
Predicate.hasProperty(u, TypeId) && !Predicate.hasProperty(u, "tableName");
|
|
41
|
+
|
|
42
|
+
// -----------------------------------------------------------------------------
|
|
43
|
+
// Bound Table
|
|
44
|
+
// -----------------------------------------------------------------------------
|
|
26
45
|
|
|
27
46
|
export interface Table<
|
|
28
47
|
Name_ extends string,
|
|
@@ -34,18 +53,65 @@ export interface Table<
|
|
|
34
53
|
VectorIndexes_ extends GenericTableVectorIndexes = {},
|
|
35
54
|
> {
|
|
36
55
|
readonly [TypeId]: TypeId;
|
|
56
|
+
readonly tableName: Name_;
|
|
37
57
|
readonly tableDefinition: TableDefinition<
|
|
38
58
|
TableValidator_,
|
|
39
59
|
Indexes_,
|
|
40
60
|
SearchIndexes_,
|
|
41
61
|
VectorIndexes_
|
|
42
62
|
>;
|
|
43
|
-
|
|
44
|
-
readonly name: Name_;
|
|
45
|
-
|
|
46
63
|
readonly Fields: TableSchema_;
|
|
47
64
|
readonly Doc: SystemFields.ExtendWithSystemFields<Name_, TableSchema_>;
|
|
65
|
+
readonly indexes: Indexes_;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface Any {
|
|
69
|
+
readonly [TypeId]: TypeId;
|
|
70
|
+
readonly tableName: string;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export type AnyWithProps = Table<
|
|
74
|
+
any,
|
|
75
|
+
Schema.Schema.AnyNoContext,
|
|
76
|
+
GenericValidator,
|
|
77
|
+
GenericTableIndexes,
|
|
78
|
+
GenericTableSearchIndexes,
|
|
79
|
+
GenericTableVectorIndexes
|
|
80
|
+
>;
|
|
81
|
+
|
|
82
|
+
// -----------------------------------------------------------------------------
|
|
83
|
+
// UnnamedTable (callable)
|
|
84
|
+
// -----------------------------------------------------------------------------
|
|
85
|
+
//
|
|
86
|
+
// `Table.make(lazyFields)` returns an `UnnamedTable`: a callable that
|
|
87
|
+
// produces a fully bound `Table` when invoked with a name. Chaining methods
|
|
88
|
+
// (`.index`, `.searchIndex`, `.vectorIndex`) live here and return new
|
|
89
|
+
// `UnnamedTable`s, accumulating plain index metadata records. Neither the
|
|
90
|
+
// field-schema nor the deploy-time `tableDefinition` is constructed at this
|
|
91
|
+
// stage — the user-supplied `lazyFields` callback is just carried through.
|
|
92
|
+
// The codegen pipeline emits a wrapper file per user-authored table that
|
|
93
|
+
// simply invokes the unnamed callable with the filename basename.
|
|
94
|
+
|
|
95
|
+
export interface UnnamedTable<
|
|
96
|
+
TableSchema_ extends Schema.Schema.AnyNoContext,
|
|
97
|
+
TableValidator_ extends GenericValidator =
|
|
98
|
+
TableSchemaToTableValidator<TableSchema_>,
|
|
99
|
+
Indexes_ extends GenericTableIndexes = {},
|
|
100
|
+
SearchIndexes_ extends GenericTableSearchIndexes = {},
|
|
101
|
+
VectorIndexes_ extends GenericTableVectorIndexes = {},
|
|
102
|
+
> {
|
|
103
|
+
<const Name_ extends string>(
|
|
104
|
+
tableName: Name_,
|
|
105
|
+
): Table<
|
|
106
|
+
Name_,
|
|
107
|
+
TableSchema_,
|
|
108
|
+
TableValidator_,
|
|
109
|
+
Indexes_,
|
|
110
|
+
SearchIndexes_,
|
|
111
|
+
VectorIndexes_
|
|
112
|
+
>;
|
|
48
113
|
|
|
114
|
+
readonly [TypeId]: TypeId;
|
|
49
115
|
readonly indexes: Indexes_;
|
|
50
116
|
|
|
51
117
|
index<
|
|
@@ -55,8 +121,7 @@ export interface Table<
|
|
|
55
121
|
>(
|
|
56
122
|
name: IndexName,
|
|
57
123
|
fields: [FirstFieldPath, ...RestFieldPaths],
|
|
58
|
-
):
|
|
59
|
-
Name_,
|
|
124
|
+
): UnnamedTable<
|
|
60
125
|
TableSchema_,
|
|
61
126
|
TableValidator_,
|
|
62
127
|
Expand<
|
|
@@ -77,8 +142,7 @@ export interface Table<
|
|
|
77
142
|
>(
|
|
78
143
|
name: IndexName,
|
|
79
144
|
indexConfig: Expand<SearchIndexConfig<SearchField, FilterFields>>,
|
|
80
|
-
):
|
|
81
|
-
Name_,
|
|
145
|
+
): UnnamedTable<
|
|
82
146
|
TableSchema_,
|
|
83
147
|
TableValidator_,
|
|
84
148
|
Indexes_,
|
|
@@ -102,8 +166,7 @@ export interface Table<
|
|
|
102
166
|
>(
|
|
103
167
|
name: IndexName,
|
|
104
168
|
indexConfig: Expand<VectorIndexConfig<VectorField, FilterFields>>,
|
|
105
|
-
):
|
|
106
|
-
Name_,
|
|
169
|
+
): UnnamedTable<
|
|
107
170
|
TableSchema_,
|
|
108
171
|
TableValidator_,
|
|
109
172
|
Indexes_,
|
|
@@ -122,12 +185,11 @@ export interface Table<
|
|
|
122
185
|
>;
|
|
123
186
|
}
|
|
124
187
|
|
|
125
|
-
export interface
|
|
188
|
+
export interface UnnamedAny {
|
|
126
189
|
readonly [TypeId]: TypeId;
|
|
127
190
|
}
|
|
128
191
|
|
|
129
|
-
export type
|
|
130
|
-
any,
|
|
192
|
+
export type UnnamedAnyWithProps = UnnamedTable<
|
|
131
193
|
Schema.Schema.AnyNoContext,
|
|
132
194
|
GenericValidator,
|
|
133
195
|
GenericTableIndexes,
|
|
@@ -135,6 +197,10 @@ export type AnyWithProps = Table<
|
|
|
135
197
|
GenericTableVectorIndexes
|
|
136
198
|
>;
|
|
137
199
|
|
|
200
|
+
// -----------------------------------------------------------------------------
|
|
201
|
+
// Type extractors
|
|
202
|
+
// -----------------------------------------------------------------------------
|
|
203
|
+
|
|
138
204
|
export type Name<TableDef extends AnyWithProps> =
|
|
139
205
|
TableDef extends Table<
|
|
140
206
|
infer TableName,
|
|
@@ -234,162 +300,217 @@ export type Fields<TableDef extends AnyWithProps> =
|
|
|
234
300
|
export type WithName<
|
|
235
301
|
TableDef extends AnyWithProps,
|
|
236
302
|
Name_ extends string,
|
|
237
|
-
> = TableDef extends { readonly
|
|
303
|
+
> = TableDef extends { readonly tableName: Name_ } ? TableDef : never;
|
|
238
304
|
|
|
239
305
|
export type TablesRecord<Tables extends AnyWithProps> = {
|
|
240
306
|
readonly [TableName_ in Name<Tables>]: WithName<Tables, TableName_>;
|
|
241
307
|
};
|
|
242
308
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
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
|
-
};
|
|
309
|
+
// -----------------------------------------------------------------------------
|
|
310
|
+
// Construction
|
|
311
|
+
// -----------------------------------------------------------------------------
|
|
312
|
+
//
|
|
313
|
+
// `make` only stores the user-supplied `lazyFields` callback alongside any
|
|
314
|
+
// chained index metadata. Neither `Fields` nor `Doc` nor `tableDefinition`
|
|
315
|
+
// is constructed until first access on a bound `Table`. Each chain step is
|
|
316
|
+
// O(1) (plain object spread of the metadata records) and never invokes the
|
|
317
|
+
// callback. Binding via `unnamed(tableName)` installs lazy memoised getters
|
|
318
|
+
// for `Fields`, `Doc`, and `tableDefinition` via `Lazy.defineProperty`, so the
|
|
319
|
+
// first access materialises the value and replaces the getter with a plain
|
|
320
|
+
// data property — second-and-subsequent accesses are observably
|
|
321
|
+
// indistinguishable from a plain property and avoid all function-call
|
|
322
|
+
// overhead.
|
|
323
|
+
|
|
324
|
+
interface UnnamedState<
|
|
325
|
+
TableSchema_ extends Schema.Schema.AnyNoContext,
|
|
326
|
+
Indexes_ extends GenericTableIndexes,
|
|
327
|
+
SearchIndexes_ extends GenericTableSearchIndexes,
|
|
328
|
+
VectorIndexes_ extends GenericTableVectorIndexes,
|
|
329
|
+
> {
|
|
330
|
+
readonly lazyFields: () => TableSchema_;
|
|
331
|
+
readonly indexes: Indexes_;
|
|
332
|
+
readonly searchIndexes: SearchIndexes_;
|
|
333
|
+
readonly vectorIndexes: VectorIndexes_;
|
|
334
|
+
}
|
|
305
335
|
|
|
306
|
-
const
|
|
336
|
+
const makeBound = <
|
|
307
337
|
Name_ extends string,
|
|
308
338
|
TableSchema_ extends Schema.Schema.AnyNoContext,
|
|
309
339
|
TableValidator_ extends Validator<any, any, any>,
|
|
310
340
|
Indexes_ extends GenericTableIndexes,
|
|
311
341
|
SearchIndexes_ extends GenericTableSearchIndexes,
|
|
312
342
|
VectorIndexes_ extends GenericTableVectorIndexes,
|
|
313
|
-
>(
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
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<
|
|
343
|
+
>(
|
|
344
|
+
tableName: Name_,
|
|
345
|
+
state: UnnamedState<TableSchema_, Indexes_, SearchIndexes_, VectorIndexes_>,
|
|
346
|
+
): Table<
|
|
331
347
|
Name_,
|
|
332
348
|
TableSchema_,
|
|
333
349
|
TableValidator_,
|
|
334
350
|
Indexes_,
|
|
335
351
|
SearchIndexes_,
|
|
336
352
|
VectorIndexes_
|
|
337
|
-
> =>
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
353
|
+
> => {
|
|
354
|
+
const bound = {
|
|
355
|
+
[TypeId]: TypeId as TypeId,
|
|
356
|
+
tableName,
|
|
357
|
+
indexes: state.indexes,
|
|
358
|
+
} as Table<
|
|
359
|
+
Name_,
|
|
360
|
+
TableSchema_,
|
|
361
|
+
TableValidator_,
|
|
362
|
+
Indexes_,
|
|
363
|
+
SearchIndexes_,
|
|
364
|
+
VectorIndexes_
|
|
365
|
+
>;
|
|
366
|
+
|
|
367
|
+
Lazy.defineProperty(bound, "Fields", () => state.lazyFields());
|
|
368
|
+
|
|
369
|
+
Lazy.defineProperty(bound, "Doc", () =>
|
|
370
|
+
SystemFields.extendWithSystemFields(
|
|
371
|
+
tableName,
|
|
372
|
+
(bound as { Fields: TableSchema_ }).Fields,
|
|
373
|
+
),
|
|
374
|
+
);
|
|
375
|
+
|
|
376
|
+
Lazy.defineProperty(bound, "tableDefinition", () => {
|
|
377
|
+
const fields = (bound as { Fields: TableSchema_ }).Fields;
|
|
378
|
+
let definition: TableDefinition<any, any, any, any> = defineTable(
|
|
379
|
+
compileTableSchema(fields),
|
|
380
|
+
);
|
|
381
|
+
for (const [name, indexFields] of Object.entries(
|
|
382
|
+
state.indexes as Record<string, any>,
|
|
383
|
+
)) {
|
|
384
|
+
definition = definition.index(name, indexFields);
|
|
385
|
+
}
|
|
386
|
+
for (const [name, config] of Object.entries(
|
|
387
|
+
state.searchIndexes as Record<string, any>,
|
|
388
|
+
)) {
|
|
389
|
+
definition = definition.searchIndex(name, config);
|
|
390
|
+
}
|
|
391
|
+
for (const [name, config] of Object.entries(
|
|
392
|
+
state.vectorIndexes as Record<string, any>,
|
|
393
|
+
)) {
|
|
394
|
+
definition = definition.vectorIndex(name, config);
|
|
395
|
+
}
|
|
396
|
+
return definition;
|
|
344
397
|
});
|
|
345
398
|
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
const Name_ extends string,
|
|
399
|
+
return bound;
|
|
400
|
+
};
|
|
401
|
+
|
|
402
|
+
const makeUnnamed = <
|
|
351
403
|
TableSchema_ extends Schema.Schema.AnyNoContext,
|
|
352
|
-
TableValidator_ extends
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
VectorIndexes_ extends GenericTableVectorIndexes = {},
|
|
404
|
+
TableValidator_ extends Validator<any, any, any>,
|
|
405
|
+
Indexes_ extends GenericTableIndexes,
|
|
406
|
+
SearchIndexes_ extends GenericTableSearchIndexes,
|
|
407
|
+
VectorIndexes_ extends GenericTableVectorIndexes,
|
|
357
408
|
>(
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
): Table<
|
|
361
|
-
Name_,
|
|
409
|
+
state: UnnamedState<TableSchema_, Indexes_, SearchIndexes_, VectorIndexes_>,
|
|
410
|
+
): UnnamedTable<
|
|
362
411
|
TableSchema_,
|
|
363
412
|
TableValidator_,
|
|
364
413
|
Indexes_,
|
|
365
414
|
SearchIndexes_,
|
|
366
415
|
VectorIndexes_
|
|
367
416
|
> => {
|
|
368
|
-
|
|
369
|
-
|
|
417
|
+
type UnnamedTable_ = UnnamedTable<
|
|
418
|
+
TableSchema_,
|
|
419
|
+
TableValidator_,
|
|
420
|
+
Indexes_,
|
|
421
|
+
SearchIndexes_,
|
|
422
|
+
VectorIndexes_
|
|
423
|
+
>;
|
|
370
424
|
|
|
371
|
-
|
|
425
|
+
type UnnamedTableFunction<FunctionName extends keyof UnnamedTable_> =
|
|
426
|
+
UnnamedTable_[FunctionName];
|
|
427
|
+
|
|
428
|
+
const bind = <const Name_ extends string>(
|
|
429
|
+
tableName: Name_,
|
|
430
|
+
): Table<
|
|
372
431
|
Name_,
|
|
373
432
|
TableSchema_,
|
|
374
433
|
TableValidator_,
|
|
375
434
|
Indexes_,
|
|
376
435
|
SearchIndexes_,
|
|
377
436
|
VectorIndexes_
|
|
378
|
-
>
|
|
437
|
+
> =>
|
|
438
|
+
makeBound<
|
|
439
|
+
Name_,
|
|
440
|
+
TableSchema_,
|
|
441
|
+
TableValidator_,
|
|
442
|
+
Indexes_,
|
|
443
|
+
SearchIndexes_,
|
|
444
|
+
VectorIndexes_
|
|
445
|
+
>(tableName, state);
|
|
446
|
+
|
|
447
|
+
const index: UnnamedTableFunction<"index"> = (name, fields) =>
|
|
448
|
+
makeUnnamed({
|
|
449
|
+
lazyFields: state.lazyFields,
|
|
450
|
+
indexes: {
|
|
451
|
+
...state.indexes,
|
|
452
|
+
[name]: fields,
|
|
453
|
+
} as any,
|
|
454
|
+
searchIndexes: state.searchIndexes,
|
|
455
|
+
vectorIndexes: state.vectorIndexes,
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
const searchIndex: UnnamedTableFunction<"searchIndex"> = (
|
|
379
459
|
name,
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
460
|
+
indexConfig,
|
|
461
|
+
) =>
|
|
462
|
+
makeUnnamed({
|
|
463
|
+
lazyFields: state.lazyFields,
|
|
464
|
+
indexes: state.indexes,
|
|
465
|
+
searchIndexes: {
|
|
466
|
+
...state.searchIndexes,
|
|
467
|
+
[name]: indexConfig,
|
|
468
|
+
} as any,
|
|
469
|
+
vectorIndexes: state.vectorIndexes,
|
|
470
|
+
});
|
|
471
|
+
|
|
472
|
+
const vectorIndex: UnnamedTableFunction<"vectorIndex"> = (
|
|
473
|
+
name,
|
|
474
|
+
indexConfig,
|
|
475
|
+
) =>
|
|
476
|
+
makeUnnamed({
|
|
477
|
+
lazyFields: state.lazyFields,
|
|
478
|
+
indexes: state.indexes,
|
|
479
|
+
searchIndexes: state.searchIndexes,
|
|
480
|
+
vectorIndexes: {
|
|
481
|
+
...state.vectorIndexes,
|
|
482
|
+
[name]: indexConfig,
|
|
483
|
+
} as any,
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
return Object.assign(bind, {
|
|
487
|
+
[TypeId]: TypeId as TypeId,
|
|
488
|
+
indexes: state.indexes,
|
|
489
|
+
index,
|
|
490
|
+
searchIndex,
|
|
491
|
+
vectorIndex,
|
|
492
|
+
}) satisfies UnnamedTable_;
|
|
493
|
+
};
|
|
494
|
+
|
|
495
|
+
export const make = <const TableSchema_ extends Schema.Schema.AnyNoContext>(
|
|
496
|
+
lazyFields: () => TableSchema_,
|
|
497
|
+
): UnnamedTable<TableSchema_, TableSchemaToTableValidator<TableSchema_>> => {
|
|
498
|
+
type TableValidator_ = TableSchemaToTableValidator<TableSchema_>;
|
|
499
|
+
type UnnamedTable_ = UnnamedTable<TableSchema_, TableValidator_>;
|
|
500
|
+
|
|
501
|
+
return makeUnnamed<TableSchema_, TableValidator_, {}, {}, {}>({
|
|
502
|
+
lazyFields,
|
|
503
|
+
indexes: {},
|
|
504
|
+
searchIndexes: {},
|
|
505
|
+
vectorIndexes: {},
|
|
506
|
+
}) satisfies UnnamedTable_;
|
|
385
507
|
};
|
|
386
508
|
|
|
387
509
|
// -----------------------------------------------------------------------------
|
|
388
510
|
// System tables
|
|
389
511
|
// -----------------------------------------------------------------------------
|
|
390
512
|
|
|
391
|
-
export const scheduledFunctionsTable = make(
|
|
392
|
-
"_scheduled_functions",
|
|
513
|
+
export const scheduledFunctionsTable = make(() =>
|
|
393
514
|
Schema.Struct({
|
|
394
515
|
name: Schema.String,
|
|
395
516
|
args: Schema.Array(Schema.Any),
|
|
@@ -406,16 +527,15 @@ export const scheduledFunctionsTable = make(
|
|
|
406
527
|
Schema.Struct({ kind: Schema.Literal("canceled") }),
|
|
407
528
|
),
|
|
408
529
|
}),
|
|
409
|
-
);
|
|
530
|
+
)("_scheduled_functions");
|
|
410
531
|
|
|
411
|
-
export const storageTable = make(
|
|
412
|
-
"_storage",
|
|
532
|
+
export const storageTable = make(() =>
|
|
413
533
|
Schema.Struct({
|
|
414
534
|
sha256: Schema.String,
|
|
415
535
|
size: Schema.Number,
|
|
416
536
|
contentType: Schema.optionalWith(Schema.String, { exact: true }),
|
|
417
537
|
}),
|
|
418
|
-
);
|
|
538
|
+
)("_storage");
|
|
419
539
|
|
|
420
540
|
export const systemTables = {
|
|
421
541
|
_scheduled_functions: scheduledFunctionsTable,
|
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";
|
package/dist/Api.d.ts
DELETED
|
@@ -1,43 +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 GroupSpec from "@confect/core/GroupSpec";
|
|
5
|
-
import * as Spec from "@confect/core/Spec";
|
|
6
|
-
|
|
7
|
-
//#region src/Api.d.ts
|
|
8
|
-
declare namespace Api_d_exports {
|
|
9
|
-
export { Any, AnyWithProps, AnyWithPropsWithRuntime, Api, GetSpec, Groups, Schema, TypeId, isApi, make, resolveGroupPathUnsafe };
|
|
10
|
-
}
|
|
11
|
-
declare const TypeId = "@confect/server/Api";
|
|
12
|
-
type TypeId = typeof TypeId;
|
|
13
|
-
declare const isApi: (u: unknown) => u is Any;
|
|
14
|
-
interface Api<DatabaseSchema_ extends AnyWithProps$1, Spec_ extends Spec.AnyWithProps> {
|
|
15
|
-
readonly [TypeId]: TypeId;
|
|
16
|
-
readonly spec: Spec_;
|
|
17
|
-
readonly databaseSchema: DatabaseSchema_;
|
|
18
|
-
readonly convexSchemaDefinition: SchemaDefinition<GenericSchema, true>;
|
|
19
|
-
}
|
|
20
|
-
interface Any {
|
|
21
|
-
readonly [TypeId]: TypeId;
|
|
22
|
-
}
|
|
23
|
-
interface AnyWithProps extends Api<AnyWithProps$1, Spec.AnyWithProps> {}
|
|
24
|
-
interface AnyWithPropsWithRuntime<Runtime extends RuntimeAndFunctionType.Runtime> extends Api<AnyWithProps$1, Spec.AnyWithPropsWithRuntime<Runtime>> {}
|
|
25
|
-
type Schema<Api_ extends AnyWithProps> = Api_["databaseSchema"];
|
|
26
|
-
type GetSpec<Api_ extends AnyWithProps> = Api_["spec"];
|
|
27
|
-
type Groups<Api_ extends AnyWithProps> = Spec.Groups<Api_["spec"]>;
|
|
28
|
-
declare const make: <DatabaseSchema_ extends AnyWithProps$1, Spec_ extends Spec.AnyWithProps>(databaseSchema: DatabaseSchema_, spec: Spec_) => Api<DatabaseSchema_, Spec_>;
|
|
29
|
-
/**
|
|
30
|
-
* Resolve the dot-path of `group` within `api.spec` by reading the immutable
|
|
31
|
-
* `paths` mapping that codegen populated in `_generated/spec.ts`. Throws when
|
|
32
|
-
* the spec is not registered, with a message pointing the caller at the
|
|
33
|
-
* place to register it.
|
|
34
|
-
*
|
|
35
|
-
* The legacy identity-based tree walk (`packages/server/src/GroupPath.ts`)
|
|
36
|
-
* was deleted in favor of this O(1) map lookup; both the registration
|
|
37
|
-
* mechanism (`Spec.addPath`) and the lookup key are the same JS reference
|
|
38
|
-
* thanks to ES module dedup between `_generated/spec.ts` and `*.impl.ts`.
|
|
39
|
-
*/
|
|
40
|
-
declare const resolveGroupPathUnsafe: (api: AnyWithProps, group: GroupSpec.AnyWithProps) => string;
|
|
41
|
-
//#endregion
|
|
42
|
-
export { Any, AnyWithProps, AnyWithPropsWithRuntime, Api, Api_d_exports, GetSpec, Groups, Schema, TypeId, isApi, make, resolveGroupPathUnsafe };
|
|
43
|
-
//# 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":";;;;;;;;;;cAQa,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;;AAlExB;;;;;AAEA;;;;;cA6Ea,sBAAA,GACX,GAAA,EAAK,YAAA,EACL,KAAA,EAAO,SAAA,CAAU,YAAA"}
|
package/dist/Api.js
DELETED
|
@@ -1,43 +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
|
-
resolveGroupPathUnsafe: () => resolveGroupPathUnsafe
|
|
11
|
-
});
|
|
12
|
-
const TypeId = "@confect/server/Api";
|
|
13
|
-
const isApi = (u) => Predicate.hasProperty(u, TypeId);
|
|
14
|
-
const Proto = { [TypeId]: TypeId };
|
|
15
|
-
const makeProto = ({ databaseSchema, spec }) => Object.assign(Object.create(Proto), {
|
|
16
|
-
databaseSchema,
|
|
17
|
-
spec,
|
|
18
|
-
convexSchemaDefinition: pipe(databaseSchema.tables, Record.map(({ tableDefinition }) => tableDefinition), defineSchema)
|
|
19
|
-
});
|
|
20
|
-
const make = (databaseSchema, spec) => makeProto({
|
|
21
|
-
databaseSchema,
|
|
22
|
-
spec
|
|
23
|
-
});
|
|
24
|
-
/**
|
|
25
|
-
* Resolve the dot-path of `group` within `api.spec` by reading the immutable
|
|
26
|
-
* `paths` mapping that codegen populated in `_generated/spec.ts`. Throws when
|
|
27
|
-
* the spec is not registered, with a message pointing the caller at the
|
|
28
|
-
* place to register it.
|
|
29
|
-
*
|
|
30
|
-
* The legacy identity-based tree walk (`packages/server/src/GroupPath.ts`)
|
|
31
|
-
* was deleted in favor of this O(1) map lookup; both the registration
|
|
32
|
-
* mechanism (`Spec.addPath`) and the lookup key are the same JS reference
|
|
33
|
-
* thanks to ES module dedup between `_generated/spec.ts` and `*.impl.ts`.
|
|
34
|
-
*/
|
|
35
|
-
const resolveGroupPathUnsafe = (api, group) => {
|
|
36
|
-
const groupPath = api.spec.paths.get(group);
|
|
37
|
-
if (groupPath === void 0) throw new Error("GroupSpec has no registered path in this api's spec. Ensure the spec is added via Spec.addPath in _generated/spec.ts (or, in tests, call .addPath(spec, 'dot.path') on the Spec you pass to Api.make).");
|
|
38
|
-
return groupPath;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
//#endregion
|
|
42
|
-
export { Api_exports, TypeId, isApi, make, resolveGroupPathUnsafe };
|
|
43
|
-
//# sourceMappingURL=Api.js.map
|
package/dist/Api.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Api.js","names":["defineConvexSchema"],"sources":["../src/Api.ts"],"sourcesContent":["import type { RuntimeAndFunctionType } from \"@confect/core\";\nimport type * as GroupSpec from \"@confect/core/GroupSpec\";\nimport type * as Spec from \"@confect/core/Spec\";\nimport type { GenericSchema, SchemaDefinition } from \"convex/server\";\nimport { defineSchema as defineConvexSchema } from \"convex/server\";\nimport { pipe, Predicate, Record } from \"effect\";\nimport type * as DatabaseSchema from \"./DatabaseSchema\";\n\nexport const TypeId = \"@confect/server/Api\";\nexport type TypeId = typeof TypeId;\n\nexport const isApi = (u: unknown): u is Any => Predicate.hasProperty(u, TypeId);\n\nexport interface Api<\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n Spec_ extends Spec.AnyWithProps,\n> {\n readonly [TypeId]: TypeId;\n readonly spec: Spec_;\n readonly databaseSchema: DatabaseSchema_;\n readonly convexSchemaDefinition: SchemaDefinition<GenericSchema, true>;\n}\n\nexport interface Any {\n readonly [TypeId]: TypeId;\n}\n\nexport interface AnyWithProps extends Api<\n DatabaseSchema.AnyWithProps,\n Spec.AnyWithProps\n> {}\n\nexport interface AnyWithPropsWithRuntime<\n Runtime extends RuntimeAndFunctionType.Runtime,\n> extends Api<\n DatabaseSchema.AnyWithProps,\n Spec.AnyWithPropsWithRuntime<Runtime>\n> {}\n\nexport type Schema<Api_ extends AnyWithProps> = Api_[\"databaseSchema\"];\n\nexport type GetSpec<Api_ extends AnyWithProps> = Api_[\"spec\"];\n\nexport type Groups<Api_ extends AnyWithProps> = Spec.Groups<Api_[\"spec\"]>;\n\nconst Proto = {\n [TypeId]: TypeId,\n};\n\nconst makeProto = <\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n Spec_ extends Spec.AnyWithProps,\n>({\n databaseSchema,\n spec,\n}: {\n databaseSchema: DatabaseSchema.AnyWithProps;\n spec: Spec_;\n}): Api<DatabaseSchema_, Spec_> =>\n Object.assign(Object.create(Proto), {\n databaseSchema,\n spec,\n convexSchemaDefinition: pipe(\n databaseSchema.tables,\n Record.map(({ tableDefinition }) => tableDefinition),\n defineConvexSchema,\n ),\n });\n\nexport const make = <\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n Spec_ extends Spec.AnyWithProps,\n>(\n databaseSchema: DatabaseSchema_,\n spec: Spec_,\n): Api<DatabaseSchema_, Spec_> => makeProto({ databaseSchema, spec });\n\n/**\n * Resolve the dot-path of `group` within `api.spec` by reading the immutable\n * `paths` mapping that codegen populated in `_generated/spec.ts`. Throws when\n * the spec is not registered, with a message pointing the caller at the\n * place to register it.\n *\n * The legacy identity-based tree walk (`packages/server/src/GroupPath.ts`)\n * was deleted in favor of this O(1) map lookup; both the registration\n * mechanism (`Spec.addPath`) and the lookup key are the same JS reference\n * thanks to ES module dedup between `_generated/spec.ts` and `*.impl.ts`.\n */\nexport const resolveGroupPathUnsafe = (\n api: AnyWithProps,\n group: GroupSpec.AnyWithProps,\n): string => {\n const groupPath = api.spec.paths.get(group);\n if (groupPath === undefined) {\n throw new Error(\n \"GroupSpec has no registered path in this api's spec. \" +\n \"Ensure the spec is added via Spec.addPath in _generated/spec.ts \" +\n \"(or, in tests, call .addPath(spec, 'dot.path') on the Spec you pass to Api.make).\",\n );\n }\n return groupPath;\n};\n"],"mappings":";;;;;;;;;;;AAQA,MAAa,SAAS;AAGtB,MAAa,SAAS,MAAyB,UAAU,YAAY,GAAG,OAAO;AAkC/E,MAAM,QAAQ,GACX,SAAS,QACX;AAED,MAAM,aAGJ,EACA,gBACA,WAKA,OAAO,OAAO,OAAO,OAAO,MAAM,EAAE;CAClC;CACA;CACA,wBAAwB,KACtB,eAAe,QACf,OAAO,KAAK,EAAE,sBAAsB,gBAAgB,EACpDA,aACD;CACF,CAAC;AAEJ,MAAa,QAIX,gBACA,SACgC,UAAU;CAAE;CAAgB;CAAM,CAAC;;;;;;;;;;;;AAarE,MAAa,0BACX,KACA,UACW;CACX,MAAM,YAAY,IAAI,KAAK,MAAM,IAAI,MAAM;AAC3C,KAAI,cAAc,OAChB,OAAM,IAAI,MACR,yMAGD;AAEH,QAAO"}
|