@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/dist/Table.js
CHANGED
|
@@ -3,76 +3,85 @@ import { compileTableSchema } from "./SchemaToValidator.js";
|
|
|
3
3
|
import { Predicate, Schema } from "effect";
|
|
4
4
|
import { defineTable } from "convex/server";
|
|
5
5
|
import * as SystemFields$1 from "@confect/core/SystemFields";
|
|
6
|
+
import * as Lazy from "@confect/core/Lazy";
|
|
6
7
|
|
|
7
8
|
//#region src/Table.ts
|
|
8
9
|
var Table_exports = /* @__PURE__ */ __exportAll({
|
|
9
10
|
TypeId: () => TypeId,
|
|
10
11
|
isTable: () => isTable,
|
|
12
|
+
isUnnamedTable: () => isUnnamedTable,
|
|
11
13
|
make: () => make,
|
|
12
14
|
scheduledFunctionsTable: () => scheduledFunctionsTable,
|
|
13
15
|
storageTable: () => storageTable,
|
|
14
16
|
systemTables: () => systemTables
|
|
15
17
|
});
|
|
16
18
|
const TypeId = "@confect/server/Table";
|
|
17
|
-
const isTable = (u) => Predicate.hasProperty(u, TypeId);
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
Doc: this.Doc,
|
|
37
|
-
tableDefinition: this.tableDefinition.searchIndex(name, indexConfig),
|
|
38
|
-
indexes: this.indexes
|
|
39
|
-
});
|
|
40
|
-
},
|
|
41
|
-
vectorIndex(name, indexConfig) {
|
|
42
|
-
return makeProto({
|
|
43
|
-
name: this.name,
|
|
44
|
-
Fields: this.Fields,
|
|
45
|
-
Doc: this.Doc,
|
|
46
|
-
tableDefinition: this.tableDefinition.vectorIndex(name, {
|
|
47
|
-
vectorField: indexConfig.vectorField,
|
|
48
|
-
dimensions: indexConfig.dimensions,
|
|
49
|
-
...indexConfig.filterFields ? { filterFields: indexConfig.filterFields } : {}
|
|
50
|
-
}),
|
|
51
|
-
indexes: this.indexes
|
|
52
|
-
});
|
|
53
|
-
}
|
|
19
|
+
const isTable = (u) => Predicate.hasProperty(u, TypeId) && Predicate.hasProperty(u, "tableName");
|
|
20
|
+
const isUnnamedTable = (u) => Predicate.hasProperty(u, TypeId) && !Predicate.hasProperty(u, "tableName");
|
|
21
|
+
const makeBound = (tableName, state) => {
|
|
22
|
+
const bound = {
|
|
23
|
+
[TypeId]: TypeId,
|
|
24
|
+
tableName,
|
|
25
|
+
indexes: state.indexes
|
|
26
|
+
};
|
|
27
|
+
Lazy.defineProperty(bound, "Fields", () => state.lazyFields());
|
|
28
|
+
Lazy.defineProperty(bound, "Doc", () => SystemFields$1.extendWithSystemFields(tableName, bound.Fields));
|
|
29
|
+
Lazy.defineProperty(bound, "tableDefinition", () => {
|
|
30
|
+
const fields = bound.Fields;
|
|
31
|
+
let definition = defineTable(compileTableSchema(fields));
|
|
32
|
+
for (const [name, indexFields] of Object.entries(state.indexes)) definition = definition.index(name, indexFields);
|
|
33
|
+
for (const [name, config] of Object.entries(state.searchIndexes)) definition = definition.searchIndex(name, config);
|
|
34
|
+
for (const [name, config] of Object.entries(state.vectorIndexes)) definition = definition.vectorIndex(name, config);
|
|
35
|
+
return definition;
|
|
36
|
+
});
|
|
37
|
+
return bound;
|
|
54
38
|
};
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
39
|
+
const makeUnnamed = (state) => {
|
|
40
|
+
const bind = (tableName) => makeBound(tableName, state);
|
|
41
|
+
const index = (name, fields) => makeUnnamed({
|
|
42
|
+
lazyFields: state.lazyFields,
|
|
43
|
+
indexes: {
|
|
44
|
+
...state.indexes,
|
|
45
|
+
[name]: fields
|
|
46
|
+
},
|
|
47
|
+
searchIndexes: state.searchIndexes,
|
|
48
|
+
vectorIndexes: state.vectorIndexes
|
|
49
|
+
});
|
|
50
|
+
const searchIndex = (name, indexConfig) => makeUnnamed({
|
|
51
|
+
lazyFields: state.lazyFields,
|
|
52
|
+
indexes: state.indexes,
|
|
53
|
+
searchIndexes: {
|
|
54
|
+
...state.searchIndexes,
|
|
55
|
+
[name]: indexConfig
|
|
56
|
+
},
|
|
57
|
+
vectorIndexes: state.vectorIndexes
|
|
58
|
+
});
|
|
59
|
+
const vectorIndex = (name, indexConfig) => makeUnnamed({
|
|
60
|
+
lazyFields: state.lazyFields,
|
|
61
|
+
indexes: state.indexes,
|
|
62
|
+
searchIndexes: state.searchIndexes,
|
|
63
|
+
vectorIndexes: {
|
|
64
|
+
...state.vectorIndexes,
|
|
65
|
+
[name]: indexConfig
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
return Object.assign(bind, {
|
|
69
|
+
[TypeId]: TypeId,
|
|
70
|
+
indexes: state.indexes,
|
|
71
|
+
index,
|
|
72
|
+
searchIndex,
|
|
73
|
+
vectorIndex
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
const make = (lazyFields) => {
|
|
77
|
+
return makeUnnamed({
|
|
78
|
+
lazyFields,
|
|
79
|
+
indexes: {},
|
|
80
|
+
searchIndexes: {},
|
|
81
|
+
vectorIndexes: {}
|
|
73
82
|
});
|
|
74
83
|
};
|
|
75
|
-
const scheduledFunctionsTable = make(
|
|
84
|
+
const scheduledFunctionsTable = make(() => Schema.Struct({
|
|
76
85
|
name: Schema.String,
|
|
77
86
|
args: Schema.Array(Schema.Any),
|
|
78
87
|
scheduledTime: Schema.Number,
|
|
@@ -81,17 +90,17 @@ const scheduledFunctionsTable = make("_scheduled_functions", Schema.Struct({
|
|
|
81
90
|
kind: Schema.Literal("failed"),
|
|
82
91
|
error: Schema.String
|
|
83
92
|
}), Schema.Struct({ kind: Schema.Literal("canceled") }))
|
|
84
|
-
}));
|
|
85
|
-
const storageTable = make(
|
|
93
|
+
}))("_scheduled_functions");
|
|
94
|
+
const storageTable = make(() => Schema.Struct({
|
|
86
95
|
sha256: Schema.String,
|
|
87
96
|
size: Schema.Number,
|
|
88
97
|
contentType: Schema.optionalWith(Schema.String, { exact: true })
|
|
89
|
-
}));
|
|
98
|
+
}))("_storage");
|
|
90
99
|
const systemTables = {
|
|
91
100
|
_scheduled_functions: scheduledFunctionsTable,
|
|
92
101
|
_storage: storageTable
|
|
93
102
|
};
|
|
94
103
|
|
|
95
104
|
//#endregion
|
|
96
|
-
export { Table_exports, TypeId, isTable, make, scheduledFunctionsTable, storageTable, systemTables };
|
|
105
|
+
export { Table_exports, TypeId, isTable, isUnnamedTable, make, scheduledFunctionsTable, storageTable, systemTables };
|
|
97
106
|
//# sourceMappingURL=Table.js.map
|
package/dist/Table.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Table.js","names":["SystemFields"],"sources":["../src/Table.ts"],"sourcesContent":["import * as SystemFields from \"@confect/core/SystemFields\";\nimport {\n defineTable,\n type SystemFields as ConvexSystemFields,\n type Expand,\n type GenericTableIndexes,\n type GenericTableSearchIndexes,\n type GenericTableVectorIndexes,\n type IndexTiebreakerField,\n type SearchIndexConfig,\n type TableDefinition,\n type VectorIndexConfig,\n} from \"convex/server\";\nimport type { GenericValidator, Validator } from \"convex/values\";\nimport { Predicate, Schema } from \"effect\";\nimport {\n compileTableSchema,\n type TableSchemaToTableValidator,\n} from \"./SchemaToValidator\";\n\nexport const TypeId = \"@confect/server/Table\";\nexport type TypeId = typeof TypeId;\n\nexport const isTable = (u: unknown): u is Any =>\n Predicate.hasProperty(u, TypeId);\n\nexport interface Table<\n Name_ extends string,\n TableSchema_ extends Schema.Schema.AnyNoContext,\n TableValidator_ extends GenericValidator =\n TableSchemaToTableValidator<TableSchema_>,\n Indexes_ extends GenericTableIndexes = {},\n SearchIndexes_ extends GenericTableSearchIndexes = {},\n VectorIndexes_ extends GenericTableVectorIndexes = {},\n> {\n readonly [TypeId]: TypeId;\n readonly tableDefinition: TableDefinition<\n TableValidator_,\n Indexes_,\n SearchIndexes_,\n VectorIndexes_\n >;\n\n readonly name: Name_;\n\n readonly Fields: TableSchema_;\n readonly Doc: SystemFields.ExtendWithSystemFields<Name_, TableSchema_>;\n\n readonly indexes: Indexes_;\n\n index<\n IndexName extends string,\n FirstFieldPath extends ExtractFieldPaths<TableValidator_>,\n RestFieldPaths extends ExtractFieldPaths<TableValidator_>[],\n >(\n name: IndexName,\n fields: [FirstFieldPath, ...RestFieldPaths],\n ): Table<\n Name_,\n TableSchema_,\n TableValidator_,\n Expand<\n Indexes_ &\n Record<\n IndexName,\n [FirstFieldPath, ...RestFieldPaths, IndexTiebreakerField]\n >\n >,\n SearchIndexes_,\n VectorIndexes_\n >;\n\n searchIndex<\n IndexName extends string,\n SearchField extends ExtractFieldPaths<TableValidator_>,\n FilterFields extends ExtractFieldPaths<TableValidator_> = never,\n >(\n name: IndexName,\n indexConfig: Expand<SearchIndexConfig<SearchField, FilterFields>>,\n ): Table<\n Name_,\n TableSchema_,\n TableValidator_,\n Indexes_,\n Expand<\n SearchIndexes_ &\n Record<\n IndexName,\n {\n searchField: SearchField;\n filterFields: FilterFields;\n }\n >\n >,\n VectorIndexes_\n >;\n\n vectorIndex<\n IndexName extends string,\n VectorField extends ExtractFieldPaths<TableValidator_>,\n FilterFields extends ExtractFieldPaths<TableValidator_> = never,\n >(\n name: IndexName,\n indexConfig: Expand<VectorIndexConfig<VectorField, FilterFields>>,\n ): Table<\n Name_,\n TableSchema_,\n TableValidator_,\n Indexes_,\n SearchIndexes_,\n Expand<\n VectorIndexes_ &\n Record<\n IndexName,\n {\n vectorField: VectorField;\n dimensions: number;\n filterFields: FilterFields;\n }\n >\n >\n >;\n}\n\nexport interface Any {\n readonly [TypeId]: TypeId;\n}\n\nexport type AnyWithProps = Table<\n any,\n Schema.Schema.AnyNoContext,\n GenericValidator,\n GenericTableIndexes,\n GenericTableSearchIndexes,\n GenericTableVectorIndexes\n>;\n\nexport type Name<TableDef extends AnyWithProps> =\n TableDef extends Table<\n infer TableName,\n infer _TableSchema,\n infer _TableValidator,\n infer _Indexes,\n infer _SearchIndexes,\n infer _VectorIndexes\n >\n ? TableName & string\n : never;\n\nexport type TableSchema<TableDef extends AnyWithProps> =\n TableDef extends Table<\n infer _TableName,\n infer TableSchema_,\n infer _TableValidator,\n infer _Indexes,\n infer _SearchIndexes,\n infer _VectorIndexes\n >\n ? TableSchema_\n : never;\n\nexport type TableValidator<TableDef extends AnyWithProps> =\n TableDef extends Table<\n infer _TableName,\n infer _TableSchema,\n infer TableValidator_,\n infer _Indexes,\n infer _SearchIndexes,\n infer _VectorIndexes\n >\n ? TableValidator_\n : never;\n\nexport type Indexes<TableDef extends AnyWithProps> =\n TableDef extends Table<\n infer _TableName,\n infer _TableSchema,\n infer _TableValidator,\n infer Indexes_,\n infer _SearchIndexes,\n infer _VectorIndexes\n >\n ? Indexes_\n : never;\n\nexport type SearchIndexes<TableDef extends AnyWithProps> =\n TableDef extends Table<\n infer _TableName,\n infer _TableSchema,\n infer _TableValidator,\n infer _Indexes,\n infer SearchIndexes_,\n infer _VectorIndexes\n >\n ? SearchIndexes_\n : never;\n\nexport type VectorIndexes<TableDef extends AnyWithProps> =\n TableDef extends Table<\n infer _TableName,\n infer _TableSchema,\n infer _TableValidator,\n infer _Indexes,\n infer _SearchIndexes,\n infer VectorIndexes_\n >\n ? VectorIndexes_\n : never;\n\nexport type Doc<TableDef extends AnyWithProps> =\n TableDef extends Table<\n infer TableName,\n infer TableSchema_,\n infer _TableValidator,\n infer _Indexes,\n infer _SearchIndexes,\n infer _VectorIndexes\n >\n ? SystemFields.ExtendWithSystemFields<TableName, TableSchema_>\n : never;\n\nexport type Fields<TableDef extends AnyWithProps> =\n TableDef extends Table<\n infer _TableName,\n infer TableSchema_,\n infer _TableValidator,\n infer _Indexes,\n infer _SearchIndexes,\n infer _VectorIndexes\n >\n ? TableSchema_\n : never;\n\nexport type WithName<\n TableDef extends AnyWithProps,\n Name_ extends string,\n> = TableDef extends { readonly name: Name_ } ? TableDef : never;\n\nexport type TablesRecord<Tables extends AnyWithProps> = {\n readonly [TableName_ in Name<Tables>]: WithName<Tables, TableName_>;\n};\n\nconst Proto = {\n [TypeId]: TypeId,\n\n index<\n IndexName extends string,\n FirstFieldPath extends string,\n RestFieldPaths extends string[],\n >(\n this: AnyWithProps,\n name: IndexName,\n fields: [FirstFieldPath, ...RestFieldPaths],\n ) {\n return makeProto({\n name: this.name,\n Fields: this.Fields,\n Doc: this.Doc,\n tableDefinition: this.tableDefinition.index(name, fields as any),\n indexes: {\n ...this.indexes,\n [name]: fields,\n },\n });\n },\n\n searchIndex<IndexName extends string, SearchField extends string>(\n this: AnyWithProps,\n name: IndexName,\n indexConfig: SearchIndexConfig<SearchField, any>,\n ) {\n return makeProto({\n name: this.name,\n Fields: this.Fields,\n Doc: this.Doc,\n tableDefinition: this.tableDefinition.searchIndex(name, indexConfig),\n indexes: this.indexes,\n });\n },\n\n vectorIndex<IndexName extends string, VectorField extends string>(\n this: AnyWithProps,\n name: IndexName,\n indexConfig: {\n vectorField: VectorField;\n dimensions: number;\n filterFields?: string[] | undefined;\n },\n ) {\n return makeProto({\n name: this.name,\n Fields: this.Fields,\n Doc: this.Doc,\n tableDefinition: this.tableDefinition.vectorIndex(name, {\n vectorField: indexConfig.vectorField,\n dimensions: indexConfig.dimensions,\n ...(indexConfig.filterFields\n ? { filterFields: indexConfig.filterFields }\n : {}),\n }),\n indexes: this.indexes,\n });\n },\n};\n\nconst makeProto = <\n Name_ extends string,\n TableSchema_ extends Schema.Schema.AnyNoContext,\n TableValidator_ extends Validator<any, any, any>,\n Indexes_ extends GenericTableIndexes,\n SearchIndexes_ extends GenericTableSearchIndexes,\n VectorIndexes_ extends GenericTableVectorIndexes,\n>({\n name,\n Fields,\n Doc,\n tableDefinition,\n indexes,\n}: {\n name: Name_;\n Fields: TableSchema_;\n Doc: SystemFields.ExtendWithSystemFields<Name_, TableSchema_>;\n tableDefinition: TableDefinition<\n TableValidator_,\n Indexes_,\n SearchIndexes_,\n VectorIndexes_\n >;\n indexes: Indexes_;\n}): Table<\n Name_,\n TableSchema_,\n TableValidator_,\n Indexes_,\n SearchIndexes_,\n VectorIndexes_\n> =>\n Object.assign(Object.create(Proto), {\n name,\n Fields,\n Doc,\n tableDefinition,\n indexes,\n });\n\n/**\n * Create a table.\n */\nexport const make = <\n const Name_ extends string,\n TableSchema_ extends Schema.Schema.AnyNoContext,\n TableValidator_ extends GenericValidator =\n TableSchemaToTableValidator<TableSchema_>,\n Indexes_ extends GenericTableIndexes = {},\n SearchIndexes_ extends GenericTableSearchIndexes = {},\n VectorIndexes_ extends GenericTableVectorIndexes = {},\n>(\n name: Name_,\n fields: TableSchema_,\n): Table<\n Name_,\n TableSchema_,\n TableValidator_,\n Indexes_,\n SearchIndexes_,\n VectorIndexes_\n> => {\n const tableValidator = compileTableSchema(fields) as any;\n const tableDefinition = defineTable(tableValidator) as any;\n\n return makeProto<\n Name_,\n TableSchema_,\n TableValidator_,\n Indexes_,\n SearchIndexes_,\n VectorIndexes_\n >({\n name,\n Fields: fields,\n Doc: SystemFields.extendWithSystemFields(name, fields),\n tableDefinition,\n indexes: {} as Indexes_,\n });\n};\n\n// -----------------------------------------------------------------------------\n// System tables\n// -----------------------------------------------------------------------------\n\nexport const scheduledFunctionsTable = make(\n \"_scheduled_functions\",\n Schema.Struct({\n name: Schema.String,\n args: Schema.Array(Schema.Any),\n scheduledTime: Schema.Number,\n completedTime: Schema.optionalWith(Schema.Number, { exact: true }),\n state: Schema.Union(\n Schema.Struct({ kind: Schema.Literal(\"pending\") }),\n Schema.Struct({ kind: Schema.Literal(\"inProgress\") }),\n Schema.Struct({ kind: Schema.Literal(\"success\") }),\n Schema.Struct({\n kind: Schema.Literal(\"failed\"),\n error: Schema.String,\n }),\n Schema.Struct({ kind: Schema.Literal(\"canceled\") }),\n ),\n }),\n);\n\nexport const storageTable = make(\n \"_storage\",\n Schema.Struct({\n sha256: Schema.String,\n size: Schema.Number,\n contentType: Schema.optionalWith(Schema.String, { exact: true }),\n }),\n);\n\nexport const systemTables = {\n _scheduled_functions: scheduledFunctionsTable,\n _storage: storageTable,\n} as const;\n\nexport type SystemTables = typeof scheduledFunctionsTable | typeof storageTable;\n\n// Vendored types from convex-js, partially modified. Ideally we could use these directly. See https://github.com/get-convex/convex-js/pull/14\n\n/**\n * Extract all of the index field paths within a {@link Validator}.\n *\n * This is used within {@link defineTable}.\n * @public\n */\ntype ExtractFieldPaths<T extends Validator<any, any, any>> =\n // Add in the system fields available in index definitions.\n // This should be everything except for `_id` because thats added to indexes\n // automatically.\n T[\"fieldPaths\"] | keyof ConvexSystemFields;\n"],"mappings":";;;;;;;;;;;;;;;AAoBA,MAAa,SAAS;AAGtB,MAAa,WAAW,MACtB,UAAU,YAAY,GAAG,OAAO;AA0NlC,MAAM,QAAQ;EACX,SAAS;CAEV,MAME,MACA,QACA;AACA,SAAO,UAAU;GACf,MAAM,KAAK;GACX,QAAQ,KAAK;GACb,KAAK,KAAK;GACV,iBAAiB,KAAK,gBAAgB,MAAM,MAAM,OAAc;GAChE,SAAS;IACP,GAAG,KAAK;KACP,OAAO;IACT;GACF,CAAC;;CAGJ,YAEE,MACA,aACA;AACA,SAAO,UAAU;GACf,MAAM,KAAK;GACX,QAAQ,KAAK;GACb,KAAK,KAAK;GACV,iBAAiB,KAAK,gBAAgB,YAAY,MAAM,YAAY;GACpE,SAAS,KAAK;GACf,CAAC;;CAGJ,YAEE,MACA,aAKA;AACA,SAAO,UAAU;GACf,MAAM,KAAK;GACX,QAAQ,KAAK;GACb,KAAK,KAAK;GACV,iBAAiB,KAAK,gBAAgB,YAAY,MAAM;IACtD,aAAa,YAAY;IACzB,YAAY,YAAY;IACxB,GAAI,YAAY,eACZ,EAAE,cAAc,YAAY,cAAc,GAC1C,EAAE;IACP,CAAC;GACF,SAAS,KAAK;GACf,CAAC;;CAEL;AAED,MAAM,aAOJ,EACA,MACA,QACA,KACA,iBACA,cAoBA,OAAO,OAAO,OAAO,OAAO,MAAM,EAAE;CAClC;CACA;CACA;CACA;CACA;CACD,CAAC;;;;AAKJ,MAAa,QASX,MACA,WAQG;CAEH,MAAM,kBAAkB,YADD,mBAAmB,OAAO,CACE;AAEnD,QAAO,UAOL;EACA;EACA,QAAQ;EACR,KAAKA,eAAa,uBAAuB,MAAM,OAAO;EACtD;EACA,SAAS,EAAE;EACZ,CAAC;;AAOJ,MAAa,0BAA0B,KACrC,wBACA,OAAO,OAAO;CACZ,MAAM,OAAO;CACb,MAAM,OAAO,MAAM,OAAO,IAAI;CAC9B,eAAe,OAAO;CACtB,eAAe,OAAO,aAAa,OAAO,QAAQ,EAAE,OAAO,MAAM,CAAC;CAClE,OAAO,OAAO,MACZ,OAAO,OAAO,EAAE,MAAM,OAAO,QAAQ,UAAU,EAAE,CAAC,EAClD,OAAO,OAAO,EAAE,MAAM,OAAO,QAAQ,aAAa,EAAE,CAAC,EACrD,OAAO,OAAO,EAAE,MAAM,OAAO,QAAQ,UAAU,EAAE,CAAC,EAClD,OAAO,OAAO;EACZ,MAAM,OAAO,QAAQ,SAAS;EAC9B,OAAO,OAAO;EACf,CAAC,EACF,OAAO,OAAO,EAAE,MAAM,OAAO,QAAQ,WAAW,EAAE,CAAC,CACpD;CACF,CAAC,CACH;AAED,MAAa,eAAe,KAC1B,YACA,OAAO,OAAO;CACZ,QAAQ,OAAO;CACf,MAAM,OAAO;CACb,aAAa,OAAO,aAAa,OAAO,QAAQ,EAAE,OAAO,MAAM,CAAC;CACjE,CAAC,CACH;AAED,MAAa,eAAe;CAC1B,sBAAsB;CACtB,UAAU;CACX"}
|
|
1
|
+
{"version":3,"file":"Table.js","names":["SystemFields"],"sources":["../src/Table.ts"],"sourcesContent":["import * as Lazy from \"@confect/core/Lazy\";\nimport * as SystemFields from \"@confect/core/SystemFields\";\nimport {\n defineTable,\n type SystemFields as ConvexSystemFields,\n type Expand,\n type GenericTableIndexes,\n type GenericTableSearchIndexes,\n type GenericTableVectorIndexes,\n type IndexTiebreakerField,\n type SearchIndexConfig,\n type TableDefinition,\n type VectorIndexConfig,\n} from \"convex/server\";\nimport type { GenericValidator, Validator } from \"convex/values\";\nimport { Predicate, Schema } from \"effect\";\nimport {\n compileTableSchema,\n type TableSchemaToTableValidator,\n} from \"./SchemaToValidator\";\n\nexport const TypeId = \"@confect/server/Table\";\nexport type TypeId = typeof TypeId;\n\n// -----------------------------------------------------------------------------\n// Predicates\n// -----------------------------------------------------------------------------\n//\n// Both bound `Table`s and `UnnamedTable` callables share the same `[TypeId]`\n// brand. They disambiguate by whether a `tableName` property is set: bound\n// tables have one, unnamed callables do not.\n//\n// The discriminator is `tableName` (not `name`) so it does not collide with\n// the built-in `Function.prototype.name` that every JS function carries.\n\nexport const isTable = (u: unknown): u is Any =>\n Predicate.hasProperty(u, TypeId) && Predicate.hasProperty(u, \"tableName\");\n\nexport const isUnnamedTable = (u: unknown): u is UnnamedAny =>\n Predicate.hasProperty(u, TypeId) && !Predicate.hasProperty(u, \"tableName\");\n\n// -----------------------------------------------------------------------------\n// Bound Table\n// -----------------------------------------------------------------------------\n\nexport interface Table<\n Name_ extends string,\n TableSchema_ extends Schema.Schema.AnyNoContext,\n TableValidator_ extends GenericValidator =\n TableSchemaToTableValidator<TableSchema_>,\n Indexes_ extends GenericTableIndexes = {},\n SearchIndexes_ extends GenericTableSearchIndexes = {},\n VectorIndexes_ extends GenericTableVectorIndexes = {},\n> {\n readonly [TypeId]: TypeId;\n readonly tableName: Name_;\n readonly tableDefinition: TableDefinition<\n TableValidator_,\n Indexes_,\n SearchIndexes_,\n VectorIndexes_\n >;\n readonly Fields: TableSchema_;\n readonly Doc: SystemFields.ExtendWithSystemFields<Name_, TableSchema_>;\n readonly indexes: Indexes_;\n}\n\nexport interface Any {\n readonly [TypeId]: TypeId;\n readonly tableName: string;\n}\n\nexport type AnyWithProps = Table<\n any,\n Schema.Schema.AnyNoContext,\n GenericValidator,\n GenericTableIndexes,\n GenericTableSearchIndexes,\n GenericTableVectorIndexes\n>;\n\n// -----------------------------------------------------------------------------\n// UnnamedTable (callable)\n// -----------------------------------------------------------------------------\n//\n// `Table.make(lazyFields)` returns an `UnnamedTable`: a callable that\n// produces a fully bound `Table` when invoked with a name. Chaining methods\n// (`.index`, `.searchIndex`, `.vectorIndex`) live here and return new\n// `UnnamedTable`s, accumulating plain index metadata records. Neither the\n// field-schema nor the deploy-time `tableDefinition` is constructed at this\n// stage — the user-supplied `lazyFields` callback is just carried through.\n// The codegen pipeline emits a wrapper file per user-authored table that\n// simply invokes the unnamed callable with the filename basename.\n\nexport interface UnnamedTable<\n TableSchema_ extends Schema.Schema.AnyNoContext,\n TableValidator_ extends GenericValidator =\n TableSchemaToTableValidator<TableSchema_>,\n Indexes_ extends GenericTableIndexes = {},\n SearchIndexes_ extends GenericTableSearchIndexes = {},\n VectorIndexes_ extends GenericTableVectorIndexes = {},\n> {\n <const Name_ extends string>(\n tableName: Name_,\n ): Table<\n Name_,\n TableSchema_,\n TableValidator_,\n Indexes_,\n SearchIndexes_,\n VectorIndexes_\n >;\n\n readonly [TypeId]: TypeId;\n readonly indexes: Indexes_;\n\n index<\n IndexName extends string,\n FirstFieldPath extends ExtractFieldPaths<TableValidator_>,\n RestFieldPaths extends ExtractFieldPaths<TableValidator_>[],\n >(\n name: IndexName,\n fields: [FirstFieldPath, ...RestFieldPaths],\n ): UnnamedTable<\n TableSchema_,\n TableValidator_,\n Expand<\n Indexes_ &\n Record<\n IndexName,\n [FirstFieldPath, ...RestFieldPaths, IndexTiebreakerField]\n >\n >,\n SearchIndexes_,\n VectorIndexes_\n >;\n\n searchIndex<\n IndexName extends string,\n SearchField extends ExtractFieldPaths<TableValidator_>,\n FilterFields extends ExtractFieldPaths<TableValidator_> = never,\n >(\n name: IndexName,\n indexConfig: Expand<SearchIndexConfig<SearchField, FilterFields>>,\n ): UnnamedTable<\n TableSchema_,\n TableValidator_,\n Indexes_,\n Expand<\n SearchIndexes_ &\n Record<\n IndexName,\n {\n searchField: SearchField;\n filterFields: FilterFields;\n }\n >\n >,\n VectorIndexes_\n >;\n\n vectorIndex<\n IndexName extends string,\n VectorField extends ExtractFieldPaths<TableValidator_>,\n FilterFields extends ExtractFieldPaths<TableValidator_> = never,\n >(\n name: IndexName,\n indexConfig: Expand<VectorIndexConfig<VectorField, FilterFields>>,\n ): UnnamedTable<\n TableSchema_,\n TableValidator_,\n Indexes_,\n SearchIndexes_,\n Expand<\n VectorIndexes_ &\n Record<\n IndexName,\n {\n vectorField: VectorField;\n dimensions: number;\n filterFields: FilterFields;\n }\n >\n >\n >;\n}\n\nexport interface UnnamedAny {\n readonly [TypeId]: TypeId;\n}\n\nexport type UnnamedAnyWithProps = UnnamedTable<\n Schema.Schema.AnyNoContext,\n GenericValidator,\n GenericTableIndexes,\n GenericTableSearchIndexes,\n GenericTableVectorIndexes\n>;\n\n// -----------------------------------------------------------------------------\n// Type extractors\n// -----------------------------------------------------------------------------\n\nexport type Name<TableDef extends AnyWithProps> =\n TableDef extends Table<\n infer TableName,\n infer _TableSchema,\n infer _TableValidator,\n infer _Indexes,\n infer _SearchIndexes,\n infer _VectorIndexes\n >\n ? TableName & string\n : never;\n\nexport type TableSchema<TableDef extends AnyWithProps> =\n TableDef extends Table<\n infer _TableName,\n infer TableSchema_,\n infer _TableValidator,\n infer _Indexes,\n infer _SearchIndexes,\n infer _VectorIndexes\n >\n ? TableSchema_\n : never;\n\nexport type TableValidator<TableDef extends AnyWithProps> =\n TableDef extends Table<\n infer _TableName,\n infer _TableSchema,\n infer TableValidator_,\n infer _Indexes,\n infer _SearchIndexes,\n infer _VectorIndexes\n >\n ? TableValidator_\n : never;\n\nexport type Indexes<TableDef extends AnyWithProps> =\n TableDef extends Table<\n infer _TableName,\n infer _TableSchema,\n infer _TableValidator,\n infer Indexes_,\n infer _SearchIndexes,\n infer _VectorIndexes\n >\n ? Indexes_\n : never;\n\nexport type SearchIndexes<TableDef extends AnyWithProps> =\n TableDef extends Table<\n infer _TableName,\n infer _TableSchema,\n infer _TableValidator,\n infer _Indexes,\n infer SearchIndexes_,\n infer _VectorIndexes\n >\n ? SearchIndexes_\n : never;\n\nexport type VectorIndexes<TableDef extends AnyWithProps> =\n TableDef extends Table<\n infer _TableName,\n infer _TableSchema,\n infer _TableValidator,\n infer _Indexes,\n infer _SearchIndexes,\n infer VectorIndexes_\n >\n ? VectorIndexes_\n : never;\n\nexport type Doc<TableDef extends AnyWithProps> =\n TableDef extends Table<\n infer TableName,\n infer TableSchema_,\n infer _TableValidator,\n infer _Indexes,\n infer _SearchIndexes,\n infer _VectorIndexes\n >\n ? SystemFields.ExtendWithSystemFields<TableName, TableSchema_>\n : never;\n\nexport type Fields<TableDef extends AnyWithProps> =\n TableDef extends Table<\n infer _TableName,\n infer TableSchema_,\n infer _TableValidator,\n infer _Indexes,\n infer _SearchIndexes,\n infer _VectorIndexes\n >\n ? TableSchema_\n : never;\n\nexport type WithName<\n TableDef extends AnyWithProps,\n Name_ extends string,\n> = TableDef extends { readonly tableName: Name_ } ? TableDef : never;\n\nexport type TablesRecord<Tables extends AnyWithProps> = {\n readonly [TableName_ in Name<Tables>]: WithName<Tables, TableName_>;\n};\n\n// -----------------------------------------------------------------------------\n// Construction\n// -----------------------------------------------------------------------------\n//\n// `make` only stores the user-supplied `lazyFields` callback alongside any\n// chained index metadata. Neither `Fields` nor `Doc` nor `tableDefinition`\n// is constructed until first access on a bound `Table`. Each chain step is\n// O(1) (plain object spread of the metadata records) and never invokes the\n// callback. Binding via `unnamed(tableName)` installs lazy memoised getters\n// for `Fields`, `Doc`, and `tableDefinition` via `Lazy.defineProperty`, so the\n// first access materialises the value and replaces the getter with a plain\n// data property — second-and-subsequent accesses are observably\n// indistinguishable from a plain property and avoid all function-call\n// overhead.\n\ninterface UnnamedState<\n TableSchema_ extends Schema.Schema.AnyNoContext,\n Indexes_ extends GenericTableIndexes,\n SearchIndexes_ extends GenericTableSearchIndexes,\n VectorIndexes_ extends GenericTableVectorIndexes,\n> {\n readonly lazyFields: () => TableSchema_;\n readonly indexes: Indexes_;\n readonly searchIndexes: SearchIndexes_;\n readonly vectorIndexes: VectorIndexes_;\n}\n\nconst makeBound = <\n Name_ extends string,\n TableSchema_ extends Schema.Schema.AnyNoContext,\n TableValidator_ extends Validator<any, any, any>,\n Indexes_ extends GenericTableIndexes,\n SearchIndexes_ extends GenericTableSearchIndexes,\n VectorIndexes_ extends GenericTableVectorIndexes,\n>(\n tableName: Name_,\n state: UnnamedState<TableSchema_, Indexes_, SearchIndexes_, VectorIndexes_>,\n): Table<\n Name_,\n TableSchema_,\n TableValidator_,\n Indexes_,\n SearchIndexes_,\n VectorIndexes_\n> => {\n const bound = {\n [TypeId]: TypeId as TypeId,\n tableName,\n indexes: state.indexes,\n } as Table<\n Name_,\n TableSchema_,\n TableValidator_,\n Indexes_,\n SearchIndexes_,\n VectorIndexes_\n >;\n\n Lazy.defineProperty(bound, \"Fields\", () => state.lazyFields());\n\n Lazy.defineProperty(bound, \"Doc\", () =>\n SystemFields.extendWithSystemFields(\n tableName,\n (bound as { Fields: TableSchema_ }).Fields,\n ),\n );\n\n Lazy.defineProperty(bound, \"tableDefinition\", () => {\n const fields = (bound as { Fields: TableSchema_ }).Fields;\n let definition: TableDefinition<any, any, any, any> = defineTable(\n compileTableSchema(fields),\n );\n for (const [name, indexFields] of Object.entries(\n state.indexes as Record<string, any>,\n )) {\n definition = definition.index(name, indexFields);\n }\n for (const [name, config] of Object.entries(\n state.searchIndexes as Record<string, any>,\n )) {\n definition = definition.searchIndex(name, config);\n }\n for (const [name, config] of Object.entries(\n state.vectorIndexes as Record<string, any>,\n )) {\n definition = definition.vectorIndex(name, config);\n }\n return definition;\n });\n\n return bound;\n};\n\nconst makeUnnamed = <\n TableSchema_ extends Schema.Schema.AnyNoContext,\n TableValidator_ extends Validator<any, any, any>,\n Indexes_ extends GenericTableIndexes,\n SearchIndexes_ extends GenericTableSearchIndexes,\n VectorIndexes_ extends GenericTableVectorIndexes,\n>(\n state: UnnamedState<TableSchema_, Indexes_, SearchIndexes_, VectorIndexes_>,\n): UnnamedTable<\n TableSchema_,\n TableValidator_,\n Indexes_,\n SearchIndexes_,\n VectorIndexes_\n> => {\n type UnnamedTable_ = UnnamedTable<\n TableSchema_,\n TableValidator_,\n Indexes_,\n SearchIndexes_,\n VectorIndexes_\n >;\n\n type UnnamedTableFunction<FunctionName extends keyof UnnamedTable_> =\n UnnamedTable_[FunctionName];\n\n const bind = <const Name_ extends string>(\n tableName: Name_,\n ): Table<\n Name_,\n TableSchema_,\n TableValidator_,\n Indexes_,\n SearchIndexes_,\n VectorIndexes_\n > =>\n makeBound<\n Name_,\n TableSchema_,\n TableValidator_,\n Indexes_,\n SearchIndexes_,\n VectorIndexes_\n >(tableName, state);\n\n const index: UnnamedTableFunction<\"index\"> = (name, fields) =>\n makeUnnamed({\n lazyFields: state.lazyFields,\n indexes: {\n ...state.indexes,\n [name]: fields,\n } as any,\n searchIndexes: state.searchIndexes,\n vectorIndexes: state.vectorIndexes,\n });\n\n const searchIndex: UnnamedTableFunction<\"searchIndex\"> = (\n name,\n indexConfig,\n ) =>\n makeUnnamed({\n lazyFields: state.lazyFields,\n indexes: state.indexes,\n searchIndexes: {\n ...state.searchIndexes,\n [name]: indexConfig,\n } as any,\n vectorIndexes: state.vectorIndexes,\n });\n\n const vectorIndex: UnnamedTableFunction<\"vectorIndex\"> = (\n name,\n indexConfig,\n ) =>\n makeUnnamed({\n lazyFields: state.lazyFields,\n indexes: state.indexes,\n searchIndexes: state.searchIndexes,\n vectorIndexes: {\n ...state.vectorIndexes,\n [name]: indexConfig,\n } as any,\n });\n\n return Object.assign(bind, {\n [TypeId]: TypeId as TypeId,\n indexes: state.indexes,\n index,\n searchIndex,\n vectorIndex,\n }) satisfies UnnamedTable_;\n};\n\nexport const make = <const TableSchema_ extends Schema.Schema.AnyNoContext>(\n lazyFields: () => TableSchema_,\n): UnnamedTable<TableSchema_, TableSchemaToTableValidator<TableSchema_>> => {\n type TableValidator_ = TableSchemaToTableValidator<TableSchema_>;\n type UnnamedTable_ = UnnamedTable<TableSchema_, TableValidator_>;\n\n return makeUnnamed<TableSchema_, TableValidator_, {}, {}, {}>({\n lazyFields,\n indexes: {},\n searchIndexes: {},\n vectorIndexes: {},\n }) satisfies UnnamedTable_;\n};\n\n// -----------------------------------------------------------------------------\n// System tables\n// -----------------------------------------------------------------------------\n\nexport const scheduledFunctionsTable = make(() =>\n Schema.Struct({\n name: Schema.String,\n args: Schema.Array(Schema.Any),\n scheduledTime: Schema.Number,\n completedTime: Schema.optionalWith(Schema.Number, { exact: true }),\n state: Schema.Union(\n Schema.Struct({ kind: Schema.Literal(\"pending\") }),\n Schema.Struct({ kind: Schema.Literal(\"inProgress\") }),\n Schema.Struct({ kind: Schema.Literal(\"success\") }),\n Schema.Struct({\n kind: Schema.Literal(\"failed\"),\n error: Schema.String,\n }),\n Schema.Struct({ kind: Schema.Literal(\"canceled\") }),\n ),\n }),\n)(\"_scheduled_functions\");\n\nexport const storageTable = make(() =>\n Schema.Struct({\n sha256: Schema.String,\n size: Schema.Number,\n contentType: Schema.optionalWith(Schema.String, { exact: true }),\n }),\n)(\"_storage\");\n\nexport const systemTables = {\n _scheduled_functions: scheduledFunctionsTable,\n _storage: storageTable,\n} as const;\n\nexport type SystemTables = typeof scheduledFunctionsTable | typeof storageTable;\n\n// Vendored types from convex-js, partially modified. Ideally we could use these directly. See https://github.com/get-convex/convex-js/pull/14\n\n/**\n * Extract all of the index field paths within a {@link Validator}.\n *\n * This is used within {@link defineTable}.\n * @public\n */\ntype ExtractFieldPaths<T extends Validator<any, any, any>> =\n // Add in the system fields available in index definitions.\n // This should be everything except for `_id` because thats added to indexes\n // automatically.\n T[\"fieldPaths\"] | keyof ConvexSystemFields;\n"],"mappings":";;;;;;;;;;;;;;;;;AAqBA,MAAa,SAAS;AActB,MAAa,WAAW,MACtB,UAAU,YAAY,GAAG,OAAO,IAAI,UAAU,YAAY,GAAG,YAAY;AAE3E,MAAa,kBAAkB,MAC7B,UAAU,YAAY,GAAG,OAAO,IAAI,CAAC,UAAU,YAAY,GAAG,YAAY;AAwS5E,MAAM,aAQJ,WACA,UAQG;CACH,MAAM,QAAQ;GACX,SAAS;EACV;EACA,SAAS,MAAM;EAChB;AASD,MAAK,eAAe,OAAO,gBAAgB,MAAM,YAAY,CAAC;AAE9D,MAAK,eAAe,OAAO,aACzBA,eAAa,uBACX,WACC,MAAmC,OACrC,CACF;AAED,MAAK,eAAe,OAAO,yBAAyB;EAClD,MAAM,SAAU,MAAmC;EACnD,IAAI,aAAkD,YACpD,mBAAmB,OAAO,CAC3B;AACD,OAAK,MAAM,CAAC,MAAM,gBAAgB,OAAO,QACvC,MAAM,QACP,CACC,cAAa,WAAW,MAAM,MAAM,YAAY;AAElD,OAAK,MAAM,CAAC,MAAM,WAAW,OAAO,QAClC,MAAM,cACP,CACC,cAAa,WAAW,YAAY,MAAM,OAAO;AAEnD,OAAK,MAAM,CAAC,MAAM,WAAW,OAAO,QAClC,MAAM,cACP,CACC,cAAa,WAAW,YAAY,MAAM,OAAO;AAEnD,SAAO;GACP;AAEF,QAAO;;AAGT,MAAM,eAOJ,UAOG;CAYH,MAAM,QACJ,cASA,UAOE,WAAW,MAAM;CAErB,MAAM,SAAwC,MAAM,WAClD,YAAY;EACV,YAAY,MAAM;EAClB,SAAS;GACP,GAAG,MAAM;IACR,OAAO;GACT;EACD,eAAe,MAAM;EACrB,eAAe,MAAM;EACtB,CAAC;CAEJ,MAAM,eACJ,MACA,gBAEA,YAAY;EACV,YAAY,MAAM;EAClB,SAAS,MAAM;EACf,eAAe;GACb,GAAG,MAAM;IACR,OAAO;GACT;EACD,eAAe,MAAM;EACtB,CAAC;CAEJ,MAAM,eACJ,MACA,gBAEA,YAAY;EACV,YAAY,MAAM;EAClB,SAAS,MAAM;EACf,eAAe,MAAM;EACrB,eAAe;GACb,GAAG,MAAM;IACR,OAAO;GACT;EACF,CAAC;AAEJ,QAAO,OAAO,OAAO,MAAM;GACxB,SAAS;EACV,SAAS,MAAM;EACf;EACA;EACA;EACD,CAAC;;AAGJ,MAAa,QACX,eAC0E;AAI1E,QAAO,YAAuD;EAC5D;EACA,SAAS,EAAE;EACX,eAAe,EAAE;EACjB,eAAe,EAAE;EAClB,CAAC;;AAOJ,MAAa,0BAA0B,WACrC,OAAO,OAAO;CACZ,MAAM,OAAO;CACb,MAAM,OAAO,MAAM,OAAO,IAAI;CAC9B,eAAe,OAAO;CACtB,eAAe,OAAO,aAAa,OAAO,QAAQ,EAAE,OAAO,MAAM,CAAC;CAClE,OAAO,OAAO,MACZ,OAAO,OAAO,EAAE,MAAM,OAAO,QAAQ,UAAU,EAAE,CAAC,EAClD,OAAO,OAAO,EAAE,MAAM,OAAO,QAAQ,aAAa,EAAE,CAAC,EACrD,OAAO,OAAO,EAAE,MAAM,OAAO,QAAQ,UAAU,EAAE,CAAC,EAClD,OAAO,OAAO;EACZ,MAAM,OAAO,QAAQ,SAAS;EAC9B,OAAO,OAAO;EACf,CAAC,EACF,OAAO,OAAO,EAAE,MAAM,OAAO,QAAQ,WAAW,EAAE,CAAC,CACpD;CACF,CAAC,CACH,CAAC,uBAAuB;AAEzB,MAAa,eAAe,WAC1B,OAAO,OAAO;CACZ,QAAQ,OAAO;CACf,MAAM,OAAO;CACb,aAAa,OAAO,aAAa,OAAO,QAAQ,EAAE,OAAO,MAAM,CAAC;CACjE,CAAC,CACH,CAAC,WAAW;AAEb,MAAa,eAAe;CAC1B,sBAAsB;CACtB,UAAU;CACX"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { ActionCtx_d_exports } from "./ActionCtx.js";
|
|
2
2
|
import { ActionRunner_d_exports } from "./ActionRunner.js";
|
|
3
|
-
import { SchemaToValidator_d_exports } from "./SchemaToValidator.js";
|
|
4
|
-
import { Table_d_exports } from "./Table.js";
|
|
5
|
-
import { DatabaseSchema_d_exports } from "./DatabaseSchema.js";
|
|
6
|
-
import { Api_d_exports } from "./Api.js";
|
|
7
3
|
import { Auth_d_exports } from "./Auth.js";
|
|
8
4
|
import { BlobNotFoundError_d_exports } from "./BlobNotFoundError.js";
|
|
9
5
|
import { ConvexConfigProvider_d_exports } from "./ConvexConfigProvider.js";
|
|
10
6
|
import { CronJob_d_exports } from "./CronJob.js";
|
|
11
7
|
import { CronJobs_d_exports } from "./CronJobs.js";
|
|
8
|
+
import { SchemaToValidator_d_exports } from "./SchemaToValidator.js";
|
|
9
|
+
import { Table_d_exports } from "./Table.js";
|
|
10
|
+
import { DatabaseSchema_d_exports } from "./DatabaseSchema.js";
|
|
12
11
|
import { Document_d_exports } from "./Document.js";
|
|
13
12
|
import { TableInfo_d_exports } from "./TableInfo.js";
|
|
14
13
|
import { DataModel_d_exports } from "./DataModel.js";
|
|
@@ -33,4 +32,4 @@ import { HttpApi_d_exports } from "./HttpApi.js";
|
|
|
33
32
|
import { RegistryItem_d_exports } from "./RegistryItem.js";
|
|
34
33
|
import { RegisteredConvexFunction_d_exports } from "./RegisteredConvexFunction.js";
|
|
35
34
|
import { RegisteredFunctions_d_exports } from "./RegisteredFunctions.js";
|
|
36
|
-
export { ActionCtx_d_exports as ActionCtx, ActionRunner_d_exports as ActionRunner,
|
|
35
|
+
export { ActionCtx_d_exports as ActionCtx, ActionRunner_d_exports as ActionRunner, Auth_d_exports as Auth, BlobNotFoundError_d_exports as BlobNotFoundError, ConvexConfigProvider_d_exports as ConvexConfigProvider, CronJob_d_exports as CronJob, CronJobs_d_exports as CronJobs, DataModel_d_exports as DataModel, DatabaseReader_d_exports as DatabaseReader, DatabaseSchema_d_exports as DatabaseSchema, DatabaseWriter_d_exports as DatabaseWriter, Document_d_exports as Document, FunctionImpl_d_exports as FunctionImpl, GroupImpl_d_exports as GroupImpl, Handler_d_exports as Handler, HttpApi_d_exports as HttpApi, MutationCtx_d_exports as MutationCtx, MutationRunner_d_exports as MutationRunner, OrderedQuery_d_exports as OrderedQuery, QueryCtx_d_exports as QueryCtx, QueryInitializer_d_exports as QueryInitializer, QueryRunner_d_exports as QueryRunner, RegisteredConvexFunction_d_exports as RegisteredConvexFunction, RegisteredFunction_d_exports as RegisteredFunction, RegisteredFunctions_d_exports as RegisteredFunctions, RegistryItem_d_exports as RegistryItem, Scheduler_d_exports as Scheduler, SchemaToValidator_d_exports as SchemaToValidator, StorageActionWriter_d_exports as StorageActionWriter, StorageReader_d_exports as StorageReader, StorageWriter_d_exports as StorageWriter, Table_d_exports as Table, TableInfo_d_exports as TableInfo, VectorSearch_d_exports as VectorSearch };
|
package/dist/index.js
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
import { ActionCtx_exports } from "./ActionCtx.js";
|
|
2
2
|
import { ActionRunner_exports } from "./ActionRunner.js";
|
|
3
|
-
import { Api_exports } from "./Api.js";
|
|
4
3
|
import { Auth_exports } from "./Auth.js";
|
|
5
4
|
import { BlobNotFoundError_exports } from "./BlobNotFoundError.js";
|
|
6
5
|
import { ConvexConfigProvider_exports } from "./ConvexConfigProvider.js";
|
|
7
6
|
import { CronJob_exports } from "./CronJob.js";
|
|
8
7
|
import { CronJobs_exports } from "./CronJobs.js";
|
|
9
8
|
import { DataModel_exports } from "./DataModel.js";
|
|
10
|
-
import { SchemaToValidator_exports } from "./SchemaToValidator.js";
|
|
11
|
-
import { Table_exports } from "./Table.js";
|
|
12
|
-
import { DatabaseSchema_exports } from "./DatabaseSchema.js";
|
|
13
9
|
import { Document_exports } from "./Document.js";
|
|
14
10
|
import { OrderedQuery_exports } from "./OrderedQuery.js";
|
|
15
11
|
import { QueryInitializer_exports } from "./QueryInitializer.js";
|
|
12
|
+
import { SchemaToValidator_exports } from "./SchemaToValidator.js";
|
|
13
|
+
import { Table_exports } from "./Table.js";
|
|
16
14
|
import { DatabaseReader_exports } from "./DatabaseReader.js";
|
|
15
|
+
import { DatabaseSchema_exports } from "./DatabaseSchema.js";
|
|
17
16
|
import { DatabaseWriter_exports } from "./DatabaseWriter.js";
|
|
18
17
|
import { RegistryItem_exports } from "./RegistryItem.js";
|
|
19
18
|
import { FunctionImpl_exports } from "./FunctionImpl.js";
|
|
@@ -34,4 +33,4 @@ import { RegisteredConvexFunction_exports } from "./RegisteredConvexFunction.js"
|
|
|
34
33
|
import { RegisteredFunctions_exports } from "./RegisteredFunctions.js";
|
|
35
34
|
import { TableInfo_exports } from "./TableInfo.js";
|
|
36
35
|
|
|
37
|
-
export { ActionCtx_exports as ActionCtx, ActionRunner_exports as ActionRunner,
|
|
36
|
+
export { ActionCtx_exports as ActionCtx, ActionRunner_exports as ActionRunner, Auth_exports as Auth, BlobNotFoundError_exports as BlobNotFoundError, ConvexConfigProvider_exports as ConvexConfigProvider, CronJob_exports as CronJob, CronJobs_exports as CronJobs, DataModel_exports as DataModel, DatabaseReader_exports as DatabaseReader, DatabaseSchema_exports as DatabaseSchema, DatabaseWriter_exports as DatabaseWriter, Document_exports as Document, FunctionImpl_exports as FunctionImpl, GroupImpl_exports as GroupImpl, Handler_exports as Handler, HttpApi_exports as HttpApi, MutationCtx_exports as MutationCtx, MutationRunner_exports as MutationRunner, OrderedQuery_exports as OrderedQuery, QueryCtx_exports as QueryCtx, QueryInitializer_exports as QueryInitializer, QueryRunner_exports as QueryRunner, RegisteredConvexFunction_exports as RegisteredConvexFunction, RegisteredFunction_exports as RegisteredFunction, RegisteredFunctions_exports as RegisteredFunctions, RegistryItem_exports as RegistryItem, Scheduler_exports as Scheduler, SchemaToValidator_exports as SchemaToValidator, StorageActionWriter_exports as StorageActionWriter, StorageReader_exports as StorageReader, StorageWriter_exports as StorageWriter, Table_exports as Table, TableInfo_exports as TableInfo, VectorSearch_exports as VectorSearch };
|
package/package.json
CHANGED
|
@@ -1,47 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@confect/server",
|
|
3
|
-
"version": "9.0.0-next.5",
|
|
4
3
|
"description": "Backend bindings to the Convex platform",
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
"url": "https://github.com/rjdellecese/confect.git"
|
|
8
|
-
},
|
|
4
|
+
"version": "9.0.0-next.6",
|
|
5
|
+
"author": "RJ Dellecese",
|
|
9
6
|
"bugs": {
|
|
10
7
|
"url": "https://github.com/rjdellecese/confect/issues"
|
|
11
8
|
},
|
|
12
|
-
"homepage": "https://confect.dev",
|
|
13
|
-
"sideEffects": false,
|
|
14
|
-
"type": "module",
|
|
15
|
-
"files": [
|
|
16
|
-
"CHANGELOG.md",
|
|
17
|
-
"LICENSE",
|
|
18
|
-
"README.md",
|
|
19
|
-
"dist",
|
|
20
|
-
"package.json",
|
|
21
|
-
"src"
|
|
22
|
-
],
|
|
23
|
-
"exports": {
|
|
24
|
-
".": {
|
|
25
|
-
"types": "./dist/index.d.ts",
|
|
26
|
-
"default": "./dist/index.js"
|
|
27
|
-
},
|
|
28
|
-
"./*": {
|
|
29
|
-
"types": "./dist/*.d.ts",
|
|
30
|
-
"default": "./dist/*.js"
|
|
31
|
-
},
|
|
32
|
-
"./package.json": "./package.json",
|
|
33
|
-
"./internal/*": null,
|
|
34
|
-
"./node": {
|
|
35
|
-
"types": "./dist/node.d.ts",
|
|
36
|
-
"default": "./dist/node.js"
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
"keywords": [
|
|
40
|
-
"effect",
|
|
41
|
-
"convex"
|
|
42
|
-
],
|
|
43
|
-
"author": "RJ Dellecese",
|
|
44
|
-
"license": "ISC",
|
|
45
9
|
"devDependencies": {
|
|
46
10
|
"@ark/attest": "0.56.0",
|
|
47
11
|
"@effect/cluster": "0.58.2",
|
|
@@ -68,33 +32,68 @@
|
|
|
68
32
|
"vite-tsconfig-paths": "6.1.1",
|
|
69
33
|
"vitest": "3.2.4"
|
|
70
34
|
},
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": ">=22"
|
|
37
|
+
},
|
|
38
|
+
"exports": {
|
|
39
|
+
".": {
|
|
40
|
+
"types": "./dist/index.d.ts",
|
|
41
|
+
"default": "./dist/index.js"
|
|
42
|
+
},
|
|
43
|
+
"./*": {
|
|
44
|
+
"types": "./dist/*.d.ts",
|
|
45
|
+
"default": "./dist/*.js"
|
|
46
|
+
},
|
|
47
|
+
"./package.json": "./package.json",
|
|
48
|
+
"./internal/*": null,
|
|
49
|
+
"./node": {
|
|
50
|
+
"types": "./dist/node.d.ts",
|
|
51
|
+
"default": "./dist/node.js"
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
"files": [
|
|
55
|
+
"CHANGELOG.md",
|
|
56
|
+
"LICENSE",
|
|
57
|
+
"README.md",
|
|
58
|
+
"dist",
|
|
59
|
+
"package.json",
|
|
60
|
+
"src"
|
|
61
|
+
],
|
|
62
|
+
"homepage": "https://confect.dev",
|
|
63
|
+
"keywords": [
|
|
64
|
+
"convex",
|
|
65
|
+
"effect"
|
|
66
|
+
],
|
|
67
|
+
"license": "ISC",
|
|
68
|
+
"main": "./dist/index.js",
|
|
69
|
+
"module": "./dist/index.js",
|
|
71
70
|
"peerDependencies": {
|
|
72
71
|
"@effect/platform": "^0.96.1",
|
|
73
72
|
"@effect/platform-node": "^0.106.0",
|
|
74
73
|
"convex": "1.39.1",
|
|
75
74
|
"effect": "^3.21.2",
|
|
76
|
-
"@confect/core": "^9.0.0-next.
|
|
75
|
+
"@confect/core": "^9.0.0-next.6"
|
|
77
76
|
},
|
|
78
|
-
"
|
|
79
|
-
"
|
|
80
|
-
"
|
|
77
|
+
"repository": {
|
|
78
|
+
"type": "git",
|
|
79
|
+
"url": "https://github.com/rjdellecese/confect.git"
|
|
81
80
|
},
|
|
82
|
-
"
|
|
83
|
-
"
|
|
81
|
+
"sideEffects": false,
|
|
82
|
+
"type": "module",
|
|
84
83
|
"types": "./dist/index.d.ts",
|
|
85
84
|
"scripts": {
|
|
85
|
+
"bench": "tsx test/SchemaToValidator.bench.ts && tsx test/Document.bench.ts",
|
|
86
86
|
"build": "tsdown --config-loader unrun",
|
|
87
|
-
"
|
|
88
|
-
"test": "vitest run",
|
|
89
|
-
"test:mock-backend": "vitest run --config vitest.mock-backend.config.ts",
|
|
90
|
-
"test:local-backend": "vitest run --config vitest.local-backend.config.ts",
|
|
91
|
-
"codegen:mock-backend": "cd test/mock-backend/fixtures && pnpm confect codegen && CONVEX_AGENT_MODE=anonymous pnpm convex dev --once --typecheck=disable --tail-logs=disable",
|
|
87
|
+
"clean": "rm -rf dist coverage node_modules",
|
|
92
88
|
"codegen:local-backend": "cd test/local-backend/fixtures && pnpm confect codegen && CONVEX_AGENT_MODE=anonymous pnpm convex dev --once --typecheck=disable --tail-logs=disable",
|
|
93
|
-
"
|
|
89
|
+
"codegen:mock-backend": "cd test/mock-backend/fixtures && pnpm confect codegen && CONVEX_AGENT_MODE=anonymous pnpm convex dev --once --typecheck=disable --tail-logs=disable",
|
|
90
|
+
"dev": "tsdown --watch",
|
|
94
91
|
"fix": "prettier --write . && eslint --fix . --max-warnings=0",
|
|
95
92
|
"format": "prettier --check .",
|
|
96
93
|
"lint": "eslint . --max-warnings=0",
|
|
97
|
-
"
|
|
98
|
-
"
|
|
94
|
+
"test": "vitest run",
|
|
95
|
+
"test:local-backend": "vitest run --config vitest.local-backend.config.ts",
|
|
96
|
+
"test:mock-backend": "vitest run --config vitest.mock-backend.config.ts",
|
|
97
|
+
"typecheck": "tsc --noEmit --project tsconfig.json"
|
|
99
98
|
}
|
|
100
99
|
}
|
package/src/DatabaseReader.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { GenericDatabaseReader } from "convex/server";
|
|
2
|
-
import {
|
|
2
|
+
import { Context, Layer } from "effect";
|
|
3
3
|
import type { BaseDatabaseReader } from "@confect/core/Types";
|
|
4
|
-
import * as DatabaseSchema from "./DatabaseSchema";
|
|
4
|
+
import type * as DatabaseSchema from "./DatabaseSchema";
|
|
5
5
|
import type * as DataModel from "./DataModel";
|
|
6
6
|
import * as QueryInitializer from "./QueryInitializer";
|
|
7
7
|
import * as Table from "./Table";
|
|
@@ -13,35 +13,31 @@ export const make = <DatabaseSchema_ extends DatabaseSchema.AnyWithProps>(
|
|
|
13
13
|
>,
|
|
14
14
|
) => {
|
|
15
15
|
type Tables = DatabaseSchema.Tables<DatabaseSchema_>;
|
|
16
|
-
type IncludedTables =
|
|
17
|
-
const extendedTables = DatabaseSchema.extendWithSystemTables(
|
|
18
|
-
databaseSchema.tables as Table.TablesRecord<Tables>,
|
|
19
|
-
);
|
|
16
|
+
type IncludedTables = Tables | Table.SystemTables;
|
|
20
17
|
|
|
21
18
|
return {
|
|
22
19
|
table: <const TableName extends Table.Name<IncludedTables>>(
|
|
23
20
|
tableName: TableName,
|
|
24
21
|
) => {
|
|
25
|
-
const
|
|
26
|
-
(def) => def.name === tableName,
|
|
27
|
-
) as Table.WithName<IncludedTables, TableName>;
|
|
22
|
+
const isSystem = Object.hasOwn(Table.systemTables, tableName);
|
|
28
23
|
|
|
29
|
-
const baseDatabaseReader: BaseDatabaseReader<any> =
|
|
30
|
-
|
|
31
|
-
(systemTableDef) => systemTableDef.name === tableName,
|
|
32
|
-
)
|
|
33
|
-
? ({
|
|
24
|
+
const baseDatabaseReader: BaseDatabaseReader<any> = isSystem
|
|
25
|
+
? {
|
|
34
26
|
get: convexDatabaseReader.system.get,
|
|
35
27
|
query: convexDatabaseReader.system.query,
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
>)
|
|
39
|
-
: ({
|
|
28
|
+
}
|
|
29
|
+
: {
|
|
40
30
|
get: convexDatabaseReader.get,
|
|
41
31
|
query: convexDatabaseReader.query,
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const table = (
|
|
35
|
+
isSystem
|
|
36
|
+
? (Table.systemTables as Record<string, Table.AnyWithProps>)[
|
|
37
|
+
tableName
|
|
38
|
+
]
|
|
39
|
+
: databaseSchema.tables[tableName]
|
|
40
|
+
) as Table.WithName<IncludedTables, TableName>;
|
|
45
41
|
|
|
46
42
|
return QueryInitializer.make<IncludedTables, TableName>(
|
|
47
43
|
tableName,
|