@confect/server 1.0.0-next.0
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 +12 -0
- package/LICENSE +7 -0
- package/dist/ActionCtx.d.ts +12 -0
- package/dist/ActionCtx.d.ts.map +1 -0
- package/dist/ActionCtx.js +10 -0
- package/dist/ActionCtx.js.map +1 -0
- package/dist/ActionRunner.d.ts +15 -0
- package/dist/ActionRunner.d.ts.map +1 -0
- package/dist/ActionRunner.js +23 -0
- package/dist/ActionRunner.js.map +1 -0
- package/dist/Api.d.ts +27 -0
- package/dist/Api.d.ts.map +1 -0
- package/dist/Api.js +26 -0
- package/dist/Api.js.map +1 -0
- package/dist/Auth.d.ts +30 -0
- package/dist/Auth.d.ts.map +1 -0
- package/dist/Auth.js +24 -0
- package/dist/Auth.js.map +1 -0
- package/dist/DataModel.d.ts +33 -0
- package/dist/DataModel.d.ts.map +1 -0
- package/dist/DataModel.js +6 -0
- package/dist/DataModel.js.map +1 -0
- package/dist/DatabaseReader.d.ts +73 -0
- package/dist/DatabaseReader.d.ts.map +1 -0
- package/dist/DatabaseReader.js +32 -0
- package/dist/DatabaseReader.js.map +1 -0
- package/dist/DatabaseSchema.d.ts +139 -0
- package/dist/DatabaseSchema.d.ts.map +1 -0
- package/dist/DatabaseSchema.js +45 -0
- package/dist/DatabaseSchema.js.map +1 -0
- package/dist/DatabaseWriter.d.ts +39 -0
- package/dist/DatabaseWriter.d.ts.map +1 -0
- package/dist/DatabaseWriter.js +43 -0
- package/dist/DatabaseWriter.js.map +1 -0
- package/dist/Document.d.ts +47 -0
- package/dist/Document.d.ts.map +1 -0
- package/dist/Document.js +66 -0
- package/dist/Document.js.map +1 -0
- package/dist/FunctionImpl.d.ts +34 -0
- package/dist/FunctionImpl.d.ts.map +1 -0
- package/dist/FunctionImpl.js +35 -0
- package/dist/FunctionImpl.js.map +1 -0
- package/dist/GroupImpl.d.ts +24 -0
- package/dist/GroupImpl.d.ts.map +1 -0
- package/dist/GroupImpl.js +14 -0
- package/dist/GroupImpl.js.map +1 -0
- package/dist/Handler.d.ts +31 -0
- package/dist/Handler.d.ts.map +1 -0
- package/dist/Handler.js +6 -0
- package/dist/Handler.js.map +1 -0
- package/dist/HttpApi.d.ts +26 -0
- package/dist/HttpApi.d.ts.map +1 -0
- package/dist/HttpApi.js +74 -0
- package/dist/HttpApi.js.map +1 -0
- package/dist/Impl.d.ts +24 -0
- package/dist/Impl.d.ts.map +1 -0
- package/dist/Impl.js +28 -0
- package/dist/Impl.js.map +1 -0
- package/dist/MutationCtx.d.ts +12 -0
- package/dist/MutationCtx.d.ts.map +1 -0
- package/dist/MutationCtx.js +10 -0
- package/dist/MutationCtx.js.map +1 -0
- package/dist/MutationRunner.d.ts +24 -0
- package/dist/MutationRunner.d.ts.map +1 -0
- package/dist/MutationRunner.js +33 -0
- package/dist/MutationRunner.js.map +1 -0
- package/dist/OrderedQuery.d.ts +23 -0
- package/dist/OrderedQuery.d.ts.map +1 -0
- package/dist/OrderedQuery.js +34 -0
- package/dist/OrderedQuery.js.map +1 -0
- package/dist/QueryCtx.d.ts +12 -0
- package/dist/QueryCtx.d.ts.map +1 -0
- package/dist/QueryCtx.js +10 -0
- package/dist/QueryCtx.js.map +1 -0
- package/dist/QueryInitializer.d.ts +49 -0
- package/dist/QueryInitializer.d.ts.map +1 -0
- package/dist/QueryInitializer.js +83 -0
- package/dist/QueryInitializer.js.map +1 -0
- package/dist/QueryRunner.d.ts +14 -0
- package/dist/QueryRunner.d.ts.map +1 -0
- package/dist/QueryRunner.js +23 -0
- package/dist/QueryRunner.js.map +1 -0
- package/dist/RegisteredFunctions.d.ts +66 -0
- package/dist/RegisteredFunctions.d.ts.map +1 -0
- package/dist/RegisteredFunctions.js +71 -0
- package/dist/RegisteredFunctions.js.map +1 -0
- package/dist/Registry.d.ts +15 -0
- package/dist/Registry.d.ts.map +1 -0
- package/dist/Registry.js +10 -0
- package/dist/Registry.js.map +1 -0
- package/dist/RegistryItem.d.ts +31 -0
- package/dist/RegistryItem.d.ts.map +1 -0
- package/dist/RegistryItem.js +20 -0
- package/dist/RegistryItem.js.map +1 -0
- package/dist/Scheduler.d.ts +23 -0
- package/dist/Scheduler.d.ts.map +1 -0
- package/dist/Scheduler.js +24 -0
- package/dist/Scheduler.js.map +1 -0
- package/dist/SchemaToValidator.d.ts +88 -0
- package/dist/SchemaToValidator.d.ts.map +1 -0
- package/dist/SchemaToValidator.js +155 -0
- package/dist/SchemaToValidator.js.map +1 -0
- package/dist/Storage.d.ts +69 -0
- package/dist/Storage.d.ts.map +1 -0
- package/dist/Storage.js +46 -0
- package/dist/Storage.js.map +1 -0
- package/dist/Table.d.ts +247 -0
- package/dist/Table.d.ts.map +1 -0
- package/dist/Table.js +97 -0
- package/dist/Table.js.map +1 -0
- package/dist/TableInfo.d.ts +48 -0
- package/dist/TableInfo.d.ts.map +1 -0
- package/dist/TableInfo.js +6 -0
- package/dist/TableInfo.js.map +1 -0
- package/dist/VectorSearch.d.ts +42 -0
- package/dist/VectorSearch.d.ts.map +1 -0
- package/dist/VectorSearch.js +16 -0
- package/dist/VectorSearch.js.map +1 -0
- package/dist/_virtual/rolldown_runtime.js +13 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +31 -0
- package/dist/internal/utils.d.ts +15 -0
- package/dist/internal/utils.d.ts.map +1 -0
- package/dist/internal/utils.js +49 -0
- package/dist/internal/utils.js.map +1 -0
- package/package.json +90 -0
- package/src/ActionCtx.ts +9 -0
- package/src/ActionRunner.ts +28 -0
- package/src/Api.ts +63 -0
- package/src/Auth.ts +31 -0
- package/src/DataModel.ts +69 -0
- package/src/DatabaseReader.ts +75 -0
- package/src/DatabaseSchema.ts +134 -0
- package/src/DatabaseWriter.ts +166 -0
- package/src/Document.ts +200 -0
- package/src/FunctionImpl.ts +112 -0
- package/src/GroupImpl.ts +60 -0
- package/src/Handler.ts +105 -0
- package/src/HttpApi.ts +232 -0
- package/src/Impl.ts +57 -0
- package/src/MutationCtx.ts +11 -0
- package/src/MutationRunner.ts +41 -0
- package/src/OrderedQuery.ts +109 -0
- package/src/QueryCtx.ts +9 -0
- package/src/QueryInitializer.ts +308 -0
- package/src/QueryRunner.ts +29 -0
- package/src/RegisteredFunctions.ts +381 -0
- package/src/Registry.ts +13 -0
- package/src/RegistryItem.ts +44 -0
- package/src/Scheduler.ts +39 -0
- package/src/SchemaToValidator.ts +619 -0
- package/src/Storage.ts +86 -0
- package/src/Table.ts +439 -0
- package/src/TableInfo.ts +91 -0
- package/src/VectorSearch.ts +46 -0
- package/src/index.ts +29 -0
- package/src/internal/utils.ts +87 -0
package/dist/Table.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { __export } from "./_virtual/rolldown_runtime.js";
|
|
2
|
+
import { compileTableSchema } from "./SchemaToValidator.js";
|
|
3
|
+
import { Predicate, Schema } from "effect";
|
|
4
|
+
import { defineTable } from "convex/server";
|
|
5
|
+
import * as SystemFields$1 from "@confect/core/SystemFields";
|
|
6
|
+
|
|
7
|
+
//#region src/Table.ts
|
|
8
|
+
var Table_exports = /* @__PURE__ */ __export({
|
|
9
|
+
TypeId: () => TypeId,
|
|
10
|
+
isTable: () => isTable,
|
|
11
|
+
make: () => make,
|
|
12
|
+
scheduledFunctionsTable: () => scheduledFunctionsTable,
|
|
13
|
+
storageTable: () => storageTable,
|
|
14
|
+
systemTables: () => systemTables
|
|
15
|
+
});
|
|
16
|
+
const TypeId = "@confect/server/Table";
|
|
17
|
+
const isTable = (u) => Predicate.hasProperty(u, TypeId);
|
|
18
|
+
const Proto = {
|
|
19
|
+
[TypeId]: TypeId,
|
|
20
|
+
index(name, fields) {
|
|
21
|
+
return makeProto({
|
|
22
|
+
name: this.name,
|
|
23
|
+
Fields: this.Fields,
|
|
24
|
+
Doc: this.Doc,
|
|
25
|
+
tableDefinition: this.tableDefinition.index(name, fields),
|
|
26
|
+
indexes: {
|
|
27
|
+
...this.indexes,
|
|
28
|
+
[name]: fields
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
},
|
|
32
|
+
searchIndex(name, indexConfig) {
|
|
33
|
+
return makeProto({
|
|
34
|
+
name: this.name,
|
|
35
|
+
Fields: this.Fields,
|
|
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
|
+
}
|
|
54
|
+
};
|
|
55
|
+
const makeProto = ({ name, Fields, Doc, tableDefinition, indexes }) => Object.assign(Object.create(Proto), {
|
|
56
|
+
name,
|
|
57
|
+
Fields,
|
|
58
|
+
Doc,
|
|
59
|
+
tableDefinition,
|
|
60
|
+
indexes
|
|
61
|
+
});
|
|
62
|
+
/**
|
|
63
|
+
* Create a table.
|
|
64
|
+
*/
|
|
65
|
+
const make = (name, fields) => {
|
|
66
|
+
const tableDefinition = defineTable(compileTableSchema(fields));
|
|
67
|
+
return makeProto({
|
|
68
|
+
name,
|
|
69
|
+
Fields: fields,
|
|
70
|
+
Doc: SystemFields$1.extendWithSystemFields(name, fields),
|
|
71
|
+
tableDefinition,
|
|
72
|
+
indexes: {}
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
const scheduledFunctionsTable = make("_scheduled_functions", Schema.Struct({
|
|
76
|
+
name: Schema.String,
|
|
77
|
+
args: Schema.Array(Schema.Any),
|
|
78
|
+
scheduledTime: Schema.Number,
|
|
79
|
+
completedTime: Schema.optionalWith(Schema.Number, { exact: true }),
|
|
80
|
+
state: Schema.Union(Schema.Struct({ kind: Schema.Literal("pending") }), Schema.Struct({ kind: Schema.Literal("inProgress") }), Schema.Struct({ kind: Schema.Literal("success") }), Schema.Struct({
|
|
81
|
+
kind: Schema.Literal("failed"),
|
|
82
|
+
error: Schema.String
|
|
83
|
+
}), Schema.Struct({ kind: Schema.Literal("canceled") }))
|
|
84
|
+
}));
|
|
85
|
+
const storageTable = make("_storage", Schema.Struct({
|
|
86
|
+
sha256: Schema.String,
|
|
87
|
+
size: Schema.Number,
|
|
88
|
+
contentType: Schema.optionalWith(Schema.String, { exact: true })
|
|
89
|
+
}));
|
|
90
|
+
const systemTables = {
|
|
91
|
+
_scheduled_functions: scheduledFunctionsTable,
|
|
92
|
+
_storage: storageTable
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
//#endregion
|
|
96
|
+
export { Table_exports, TypeId, isTable, make, scheduledFunctionsTable, storageTable, systemTables };
|
|
97
|
+
//# sourceMappingURL=Table.js.map
|
|
@@ -0,0 +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\n GenericValidator = 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\n GenericValidator = 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"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { AnyWithProps as AnyWithProps$1, Table } from "./Table.js";
|
|
2
|
+
import { Any as Any$1, AnyEncoded } from "./Document.js";
|
|
3
|
+
import { Schema, Types } from "effect";
|
|
4
|
+
import { Expand, GenericDocument, GenericFieldPaths, GenericTableIndexes, GenericTableSearchIndexes, GenericTableVectorIndexes, IdField, SystemFields, SystemIndexes } from "convex/server";
|
|
5
|
+
import { GenericValidator } from "convex/values";
|
|
6
|
+
|
|
7
|
+
//#region src/TableInfo.d.ts
|
|
8
|
+
declare namespace TableInfo_d_exports {
|
|
9
|
+
export { Any, AnyWithProps, ConvexTableInfo, Document, TableInfo, TableSchema, TypeId };
|
|
10
|
+
}
|
|
11
|
+
declare const TypeId: "@confect/server/TableInfo";
|
|
12
|
+
type TypeId = typeof TypeId;
|
|
13
|
+
type TableInfo<Table_ extends AnyWithProps$1> = Table_ extends Table<infer TableName, infer _TableSchema, infer TableValidator, infer Indexes, infer SearchIndexes, infer VectorIndexes> ? {
|
|
14
|
+
readonly [TypeId]: TypeId;
|
|
15
|
+
readonly document: Table_["Doc"]["Type"];
|
|
16
|
+
readonly encodedDocument: Table_["Doc"]["Encoded"];
|
|
17
|
+
readonly convexDocument: ExtractConvexDocument<TableName, TableValidator>;
|
|
18
|
+
readonly fieldPaths: keyof IdField<TableName> | ExtractFieldPaths<TableValidator>;
|
|
19
|
+
readonly indexes: Types.Simplify<Indexes & SystemIndexes>;
|
|
20
|
+
readonly searchIndexes: SearchIndexes;
|
|
21
|
+
readonly vectorIndexes: VectorIndexes;
|
|
22
|
+
} : never;
|
|
23
|
+
interface Any {
|
|
24
|
+
readonly [TypeId]: TypeId;
|
|
25
|
+
}
|
|
26
|
+
interface AnyWithProps extends Any {
|
|
27
|
+
readonly document: Any$1;
|
|
28
|
+
readonly encodedDocument: AnyEncoded;
|
|
29
|
+
readonly convexDocument: GenericDocument;
|
|
30
|
+
readonly fieldPaths: GenericFieldPaths;
|
|
31
|
+
readonly indexes: GenericTableIndexes;
|
|
32
|
+
readonly searchIndexes: GenericTableSearchIndexes;
|
|
33
|
+
readonly vectorIndexes: GenericTableVectorIndexes;
|
|
34
|
+
}
|
|
35
|
+
type ConvexTableInfo<TableInfo_ extends AnyWithProps> = {
|
|
36
|
+
document: TableInfo_["convexDocument"];
|
|
37
|
+
fieldPaths: TableInfo_["fieldPaths"];
|
|
38
|
+
indexes: TableInfo_["indexes"];
|
|
39
|
+
searchIndexes: TableInfo_["searchIndexes"];
|
|
40
|
+
vectorIndexes: TableInfo_["vectorIndexes"];
|
|
41
|
+
};
|
|
42
|
+
type TableSchema<TableInfo_ extends AnyWithProps> = Schema.Schema<TableInfo_["document"], TableInfo_["encodedDocument"]>;
|
|
43
|
+
type Document<TableInfo_ extends AnyWithProps> = TableInfo_["document"];
|
|
44
|
+
type ExtractFieldPaths<T extends GenericValidator> = T["fieldPaths"] | keyof SystemFields;
|
|
45
|
+
type ExtractConvexDocument<TableName$1 extends string, T extends GenericValidator> = Expand<IdField<TableName$1> & SystemFields & T["type"]> extends GenericDocument ? Expand<IdField<TableName$1> & SystemFields & T["type"]> : never;
|
|
46
|
+
//#endregion
|
|
47
|
+
export { Any, AnyWithProps, ConvexTableInfo, Document, TableInfo, TableInfo_d_exports, TableSchema, TypeId };
|
|
48
|
+
//# sourceMappingURL=TableInfo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TableInfo.d.ts","names":[],"sources":["../src/TableInfo.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;cAgBqB;KACT,MAAA,UAAgB;KAEhB,yBAAyB,kBACnC,eAAe;YASC,MAAA,GAAS;qBACA;4BACO;2BAED,sBACvB,WACA;6BAGQ,QAAQ,aACd,kBAAkB;oBACJ,KAAA,CAAM,SAAS,UAAU;0BACnB;0BACA;;AA1BX,UA8BJ,GAAA,CA9BuC;EAC5C,UA8BA,MAAA,CA9BM,EA8BG,MA9BO;AAE5B;AAAqC,UA+BpB,YAAA,SAAqB,GA/BD,CAAA;EACnC,SAAA,QAAA,EA+BmB,KA/BnB;EAAe,SAAA,eAAA,EAgCW,UAhCX;EASU,SAAA,cAAA,EAwBA,eAxBA;EAAT,SAAA,UAAA,EAyBK,iBAzBL;EACS,SAAA,OAAA,EAyBP,mBAzBO;EACO,SAAA,aAAA,EAyBR,yBAzBQ;EAGxB,SAAA,aAAA,EAuBgB,yBAvBhB;;AADuB,KA2BrB,eA3BqB,CAAA,mBA2Bc,YA3Bd,CAAA,GAAA;EAKP,QAAA,EAuBd,UAvBc,CAAA,gBAAA,CAAA;EAAR,UAAA,EAwBJ,UAxBI,CAAA,YAAA,CAAA;EACY,OAAA,EAwBnB,UAxBmB,CAAA,SAAA,CAAA;EAAlB,aAAA,EAyBK,UAzBL,CAAA,eAAA,CAAA;EAC6B,aAAA,EAyBxB,UAzBwB,CAAA,eAAA,CAAA;CAAU;AAAnB,KA4BpB,WA5BoB,CAAA,mBA4BW,YA5BX,CAAA,GA4B2B,MAAA,CAAO,MA5BlC,CA6B9B,UA7B8B,CAAA,UAAA,CAAA,EA8B9B,UA9B8B,CAAA,iBAAA,CAAA,CAAA;AACA,KAgCpB,QAhCoB,CAAA,mBAgCQ,YAhCR,CAAA,GAgCwB,UAhCxB,CAAA,UAAA,CAAA;KAqC3B,iBApC2B,CAAA,UAoCC,gBApCD,CAAA,GAqC5B,CArC4B,CAAA,YAAA,CAAA,GAAA,MAsCtB,YAtCsB;KAwC3B,qBAxCwC,CAAA,oBAAA,MAAA,EAAA,UA0CjC,gBA1CiC,CAAA,GA4C3C,MA5C2C,CA4CpC,OA5CoC,CA4C5B,WA5C4B,CAAA,GA4Cf,YA5Ce,GA4CA,CA5CA,CAAA,MAAA,CAAA,CAAA,SA4CmB,eA5CnB,GA6CvC,MA7CuC,CA6ChC,OA7CgC,CA6CxB,WA7CwB,CAAA,GA6CX,YA7CW,GA6CI,CA7CJ,CAAA,MAAA,CAAA,CAAA,GAAA,KAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TableInfo.js","names":[],"sources":["../src/TableInfo.ts"],"sourcesContent":["import type {\n Expand,\n GenericDocument,\n GenericFieldPaths,\n GenericTableIndexes,\n GenericTableSearchIndexes,\n GenericTableVectorIndexes,\n IdField,\n SystemFields,\n SystemIndexes,\n} from \"convex/server\";\nimport type { GenericValidator } from \"convex/values\";\nimport type { Schema, Types } from \"effect\";\nimport type * as Document_ from \"./Document\";\nimport type * as Table from \"./Table\";\n\nexport declare const TypeId: \"@confect/server/TableInfo\";\nexport type TypeId = typeof TypeId;\n\nexport type TableInfo<Table_ extends Table.AnyWithProps> =\n Table_ extends Table.Table<\n infer TableName,\n infer _TableSchema,\n infer TableValidator,\n infer Indexes,\n infer SearchIndexes,\n infer VectorIndexes\n >\n ? {\n readonly [TypeId]: TypeId;\n readonly document: Table_[\"Doc\"][\"Type\"];\n readonly encodedDocument: Table_[\"Doc\"][\"Encoded\"];\n // TODO: Can we exclude this and derive the convex document type from the encoded document?\n readonly convexDocument: ExtractConvexDocument<\n TableName,\n TableValidator\n >;\n readonly fieldPaths:\n | keyof IdField<TableName>\n | ExtractFieldPaths<TableValidator>;\n readonly indexes: Types.Simplify<Indexes & SystemIndexes>;\n readonly searchIndexes: SearchIndexes;\n readonly vectorIndexes: VectorIndexes;\n }\n : never;\n\nexport interface Any {\n readonly [TypeId]: TypeId;\n}\n\nexport interface AnyWithProps extends Any {\n readonly document: Document_.Any;\n readonly encodedDocument: Document_.AnyEncoded;\n readonly convexDocument: GenericDocument;\n readonly fieldPaths: GenericFieldPaths;\n readonly indexes: GenericTableIndexes;\n readonly searchIndexes: GenericTableSearchIndexes;\n readonly vectorIndexes: GenericTableVectorIndexes;\n}\n\nexport type ConvexTableInfo<TableInfo_ extends AnyWithProps> = {\n document: TableInfo_[\"convexDocument\"];\n fieldPaths: TableInfo_[\"fieldPaths\"];\n indexes: TableInfo_[\"indexes\"];\n searchIndexes: TableInfo_[\"searchIndexes\"];\n vectorIndexes: TableInfo_[\"vectorIndexes\"];\n};\n\nexport type TableSchema<TableInfo_ extends AnyWithProps> = Schema.Schema<\n TableInfo_[\"document\"],\n TableInfo_[\"encodedDocument\"]\n>;\n\nexport type Document<TableInfo_ extends AnyWithProps> = TableInfo_[\"document\"];\n\n// Vendored types from convex-js, partially modified.\n// See https://github.com/get-convex/convex-js/pull/14\n\ntype ExtractFieldPaths<T extends GenericValidator> =\n | T[\"fieldPaths\"]\n | keyof SystemFields;\n\ntype ExtractConvexDocument<\n TableName extends string,\n T extends GenericValidator,\n> =\n Expand<IdField<TableName> & SystemFields & T[\"type\"]> extends GenericDocument\n ? Expand<IdField<TableName> & SystemFields & T[\"type\"]>\n : never;\n\n// End of vendored types from convex-js, partially modified.\n"],"mappings":""}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { AnyWithProps, TableNames, ToConvex } from "./DataModel.js";
|
|
2
|
+
import { Context, Effect, Layer } from "effect";
|
|
3
|
+
import * as convex_server40 from "convex/server";
|
|
4
|
+
import { Expand, GenericActionCtx, NamedTableInfo, VectorIndexNames, VectorSearchQuery } from "convex/server";
|
|
5
|
+
import { GenericId } from "convex/values";
|
|
6
|
+
|
|
7
|
+
//#region src/VectorSearch.d.ts
|
|
8
|
+
declare namespace VectorSearch_d_exports {
|
|
9
|
+
export { VectorSearch, layer, make };
|
|
10
|
+
}
|
|
11
|
+
type ConvexVectorSearch<DataModel_ extends AnyWithProps> = GenericActionCtx<ToConvex<DataModel_>>["vectorSearch"];
|
|
12
|
+
declare const make: <DataModel_ extends AnyWithProps>(vectorSearch: ConvexVectorSearch<DataModel_>) => <TableName extends TableNames<DataModel_>, IndexName extends VectorIndexNames<NamedTableInfo<ToConvex<DataModel_>, TableName>>>(tableName: TableName, indexName: IndexName, query: Expand<VectorSearchQuery<NamedTableInfo<ToConvex<DataModel_>, TableName>, IndexName>>) => Effect.Effect<Array<{
|
|
13
|
+
_id: GenericId<TableName>;
|
|
14
|
+
_score: number;
|
|
15
|
+
}>>;
|
|
16
|
+
declare const VectorSearch: <DataModel_ extends AnyWithProps>() => Context.Tag<(<TableName extends TableNames<DataModel_>, IndexName extends keyof convex_server40.VectorIndexes<NamedTableInfo<ToConvex<DataModel_>, TableName>>>(tableName: TableName, indexName: IndexName, query: {
|
|
17
|
+
vector: number[];
|
|
18
|
+
limit?: number;
|
|
19
|
+
filter?: (q: convex_server40.VectorFilterBuilder<convex_server40.DocumentByInfo<NamedTableInfo<ToConvex<DataModel_>, TableName>>, convex_server40.NamedVectorIndex<NamedTableInfo<ToConvex<DataModel_>, TableName>, IndexName>>) => convex_server40.FilterExpression<boolean>;
|
|
20
|
+
}) => Effect.Effect<{
|
|
21
|
+
_id: GenericId<TableName>;
|
|
22
|
+
_score: number;
|
|
23
|
+
}[], never, never>), <TableName extends TableNames<DataModel_>, IndexName extends keyof convex_server40.VectorIndexes<NamedTableInfo<ToConvex<DataModel_>, TableName>>>(tableName: TableName, indexName: IndexName, query: {
|
|
24
|
+
vector: number[];
|
|
25
|
+
limit?: number;
|
|
26
|
+
filter?: (q: convex_server40.VectorFilterBuilder<convex_server40.DocumentByInfo<NamedTableInfo<ToConvex<DataModel_>, TableName>>, convex_server40.NamedVectorIndex<NamedTableInfo<ToConvex<DataModel_>, TableName>, IndexName>>) => convex_server40.FilterExpression<boolean>;
|
|
27
|
+
}) => Effect.Effect<{
|
|
28
|
+
_id: GenericId<TableName>;
|
|
29
|
+
_score: number;
|
|
30
|
+
}[], never, never>>;
|
|
31
|
+
type VectorSearch<DataModel_ extends AnyWithProps> = ReturnType<typeof VectorSearch<DataModel_>>["Identifier"];
|
|
32
|
+
declare const layer: <DataModel_ extends AnyWithProps>(vectorSearch: ConvexVectorSearch<DataModel_>) => Layer.Layer<(<TableName extends TableNames<DataModel_>, IndexName extends keyof convex_server40.VectorIndexes<NamedTableInfo<ToConvex<DataModel_>, TableName>>>(tableName: TableName, indexName: IndexName, query: {
|
|
33
|
+
vector: number[];
|
|
34
|
+
limit?: number;
|
|
35
|
+
filter?: (q: convex_server40.VectorFilterBuilder<convex_server40.DocumentByInfo<NamedTableInfo<ToConvex<DataModel_>, TableName>>, convex_server40.NamedVectorIndex<NamedTableInfo<ToConvex<DataModel_>, TableName>, IndexName>>) => convex_server40.FilterExpression<boolean>;
|
|
36
|
+
}) => Effect.Effect<{
|
|
37
|
+
_id: GenericId<TableName>;
|
|
38
|
+
_score: number;
|
|
39
|
+
}[], never, never>), never, never>;
|
|
40
|
+
//#endregion
|
|
41
|
+
export { VectorSearch, VectorSearch_d_exports, layer, make };
|
|
42
|
+
//# sourceMappingURL=VectorSearch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VectorSearch.d.ts","names":[],"sources":["../src/VectorSearch.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;KAWK,sCAAsC,gBACzC,iBAAiB,SAAmB;cAEzB,0BACS,4BACJ,mBAAmB,mCAGf,WAAqB,+BACrB,iBAChB,eAAe,SAAmB,aAAa,wBAGtC,sBACA,kBACJ,OACL,kBACE,eAAe,SAAmB,aAAa,YAC/C,gBAGH,MAAA,CAAO,OAAO;OAAa,UAAU;;;cAG7B,kCAAmC,mBAAsB,OAAA,CAAA,wBAhBzD,WAAA,qCACA,eAAA,CAAA,cAAA,eAAA,SAAA,aAAA,wBAAA,sBAAA;;;;AAXiC,CAAA,EAAA,gBAEzC,CAAA;EAAsC,GAAA,WAAA,UAAA,CAAA;EACL,MAAA,EAAA,MAAA;CAAnB,EAAA,EAAA,KAAA,EAAA,KAAA,CAAA,CAAA,EAAA,CAAA,kBAON,UAPM,CAON,UAPM,CAAA,EAAA,kBAAA,MAQN,eAAA,CAAA,aARM,CAQN,cARM,CAQN,QARM,CAQN,UARM,CAAA,EAQN,SARM,CAAA,CAAA,CAAA,CAAA,SAAA,EAQN,SARM,EAAA,SAAA,EAQN,SARM,EAAA,KAAA,EAAA;EAAjB,MAAA,EAAA,MAAA,EAAA;EAAgB,KAAA,CAAA,EAAA,MAAA;EAEL,MAAA,CAmBsD,EAAA,CAAA,CAAA,qCAAA,+BAAA,eAAA,SAAA,WAAA,CAAA,WAAA,CAAA,CAAA,kCAAA,eAAA,SAAA,WAAA,CAAA,WAAA,CAAA,WAAA,CAAA,CAAA,EAAA,mCAAA,CAAA,OAAA,CAAA;CAlB7C,EAAA,gBAAA,CAAA;EACe,GAAA,WAAA,UAAA,CAAA;EAAnB,MAAA,EAAA,MAAA;CAGyB,EAAA,EAAA,KAAA,EAAA,KAAA,CAAA,CAAA;AAArB,KAqBV,YArBU,CAAA,mBAqBsB,YArBtB,CAAA,GAsBpB,UAtBoB,CAAA,OAsBF,YAtBE,CAsBW,UAtBX,CAAA,CAAA,CAAA,YAAA,CAAA;AAEkB,cAsB3B,KAtB2B,EAAA,CAAA,mBAsBC,YAtBD,CAAA,CAAA,YAAA,EAuBxB,kBAvBwB,CAuBL,UAvBK,CAAA,EAAA,GAuBM,KAAA,CAAA,KAvBN,CAAA,CAAA,CAAA,kBAF3B,UAE2B,CAF3B,UAE2B,CAAA,EAAA,kBAAA,MAD3B,eAAA,CAAA,aAC2B,CAD3B,cAC2B,CAD3B,QAC2B,CAD3B,UAC2B,CAAA,EAD3B,SAC2B,CAAA,CAAA,CAAA,CAAA,SAAA,EAD3B,SAC2B,EAAA,SAAA,EAD3B,SAC2B,EAAA,KAAA,EAAA;EAAnB,MAAA,EAAA,MAAA,EAAA;EAAgC,KAAA,CAAA,EAAA,MAAA;EAA/C,MAAA,CAAA,EAAA,CAAA,CAAA,qCAAA,+BAAA,eAAA,SAAA,WAAA,CAAA,WAAA,CAAA,CAAA,kCAAA,eAAA,SAAA,WAAA,CAAA,WAAA,CAAA,WAAA,CAAA,CAAA,EAAA,mCAAA,CAAA,OAAA,CAAA;CADgB,EAAA,gBAAA,CAAA;EAIP,GAAA,WAAA,UAAA,CAAA;EACA,MAAA,EAAA,MAAA;CAG2B,EAAA,EAAA,KAAA,EAAA,KAAA,CAAA,CAAA,EAAA,KAAA,EAAA,KAAA,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { __export } from "./_virtual/rolldown_runtime.js";
|
|
2
|
+
import { Context, Effect, Layer } from "effect";
|
|
3
|
+
|
|
4
|
+
//#region src/VectorSearch.ts
|
|
5
|
+
var VectorSearch_exports = /* @__PURE__ */ __export({
|
|
6
|
+
VectorSearch: () => VectorSearch,
|
|
7
|
+
layer: () => layer,
|
|
8
|
+
make: () => make
|
|
9
|
+
});
|
|
10
|
+
const make = (vectorSearch) => (tableName, indexName, query) => Effect.promise(() => vectorSearch(tableName, indexName, query));
|
|
11
|
+
const VectorSearch = () => Context.GenericTag("@confect/server/VectorSearch");
|
|
12
|
+
const layer = (vectorSearch) => Layer.succeed(VectorSearch(), make(vectorSearch));
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
export { VectorSearch, VectorSearch_exports, layer, make };
|
|
16
|
+
//# sourceMappingURL=VectorSearch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VectorSearch.js","names":[],"sources":["../src/VectorSearch.ts"],"sourcesContent":["import type {\n Expand,\n GenericActionCtx,\n NamedTableInfo,\n VectorIndexNames,\n VectorSearchQuery,\n} from \"convex/server\";\nimport type { GenericId } from \"convex/values\";\nimport { Context, Effect, Layer } from \"effect\";\nimport type * as DataModel from \"./DataModel\";\n\ntype ConvexVectorSearch<DataModel_ extends DataModel.AnyWithProps> =\n GenericActionCtx<DataModel.ToConvex<DataModel_>>[\"vectorSearch\"];\n\nexport const make =\n <DataModel_ extends DataModel.AnyWithProps>(\n vectorSearch: ConvexVectorSearch<DataModel_>,\n ) =>\n <\n TableName extends DataModel.TableNames<DataModel_>,\n IndexName extends VectorIndexNames<\n NamedTableInfo<DataModel.ToConvex<DataModel_>, TableName>\n >,\n >(\n tableName: TableName,\n indexName: IndexName,\n query: Expand<\n VectorSearchQuery<\n NamedTableInfo<DataModel.ToConvex<DataModel_>, TableName>,\n IndexName\n >\n >,\n ): Effect.Effect<Array<{ _id: GenericId<TableName>; _score: number }>> =>\n Effect.promise(() => vectorSearch(tableName, indexName, query));\n\nexport const VectorSearch = <DataModel_ extends DataModel.AnyWithProps>() =>\n Context.GenericTag<ReturnType<typeof make<DataModel_>>>(\n \"@confect/server/VectorSearch\",\n );\n\nexport type VectorSearch<DataModel_ extends DataModel.AnyWithProps> =\n ReturnType<typeof VectorSearch<DataModel_>>[\"Identifier\"];\n\nexport const layer = <DataModel_ extends DataModel.AnyWithProps>(\n vectorSearch: ConvexVectorSearch<DataModel_>,\n) => Layer.succeed(VectorSearch<DataModel_>(), make(vectorSearch));\n"],"mappings":";;;;;;;;;AAcA,MAAa,QAET,kBAQA,WACA,WACA,UAOA,OAAO,cAAc,aAAa,WAAW,WAAW,MAAM,CAAC;AAEnE,MAAa,qBACX,QAAQ,WACN,+BACD;AAKH,MAAa,SACX,iBACG,MAAM,QAAQ,cAA0B,EAAE,KAAK,aAAa,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __export = (all) => {
|
|
4
|
+
let target = {};
|
|
5
|
+
for (var name in all) __defProp(target, name, {
|
|
6
|
+
get: all[name],
|
|
7
|
+
enumerable: true
|
|
8
|
+
});
|
|
9
|
+
return target;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
export { __export };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ActionCtx_d_exports } from "./ActionCtx.js";
|
|
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
|
+
import { Auth_d_exports } from "./Auth.js";
|
|
8
|
+
import { Document_d_exports } from "./Document.js";
|
|
9
|
+
import { TableInfo_d_exports } from "./TableInfo.js";
|
|
10
|
+
import { DataModel_d_exports } from "./DataModel.js";
|
|
11
|
+
import { OrderedQuery_d_exports } from "./OrderedQuery.js";
|
|
12
|
+
import { QueryInitializer_d_exports } from "./QueryInitializer.js";
|
|
13
|
+
import { DatabaseReader_d_exports } from "./DatabaseReader.js";
|
|
14
|
+
import { DatabaseWriter_d_exports } from "./DatabaseWriter.js";
|
|
15
|
+
import { MutationCtx_d_exports } from "./MutationCtx.js";
|
|
16
|
+
import { MutationRunner_d_exports } from "./MutationRunner.js";
|
|
17
|
+
import { QueryCtx_d_exports } from "./QueryCtx.js";
|
|
18
|
+
import { QueryRunner_d_exports } from "./QueryRunner.js";
|
|
19
|
+
import { Scheduler_d_exports } from "./Scheduler.js";
|
|
20
|
+
import { Storage_d_exports } from "./Storage.js";
|
|
21
|
+
import { VectorSearch_d_exports } from "./VectorSearch.js";
|
|
22
|
+
import { Handler_d_exports } from "./Handler.js";
|
|
23
|
+
import { FunctionImpl_d_exports } from "./FunctionImpl.js";
|
|
24
|
+
import { GroupImpl_d_exports } from "./GroupImpl.js";
|
|
25
|
+
import { HttpApi_d_exports } from "./HttpApi.js";
|
|
26
|
+
import { Impl_d_exports } from "./Impl.js";
|
|
27
|
+
import { RegisteredFunctions_d_exports } from "./RegisteredFunctions.js";
|
|
28
|
+
import { RegistryItem_d_exports } from "./RegistryItem.js";
|
|
29
|
+
import { Registry_d_exports } from "./Registry.js";
|
|
30
|
+
export { ActionCtx_d_exports as ActionCtx, ActionRunner_d_exports as ActionRunner, Api_d_exports as Api, Auth_d_exports as Auth, 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, Impl_d_exports as Impl, 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, RegisteredFunctions_d_exports as RegisteredFunctions, Registry_d_exports as Registry, RegistryItem_d_exports as RegistryItem, Scheduler_d_exports as Scheduler, SchemaToValidator_d_exports as SchemaToValidator, Storage_d_exports as Storage, Table_d_exports as Table, TableInfo_d_exports as TableInfo, VectorSearch_d_exports as VectorSearch };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ActionCtx_exports } from "./ActionCtx.js";
|
|
2
|
+
import { ActionRunner_exports } from "./ActionRunner.js";
|
|
3
|
+
import { Api_exports } from "./Api.js";
|
|
4
|
+
import { Auth_exports } from "./Auth.js";
|
|
5
|
+
import { DataModel_exports } from "./DataModel.js";
|
|
6
|
+
import { SchemaToValidator_exports } from "./SchemaToValidator.js";
|
|
7
|
+
import { Table_exports } from "./Table.js";
|
|
8
|
+
import { DatabaseSchema_exports } from "./DatabaseSchema.js";
|
|
9
|
+
import { Document_exports } from "./Document.js";
|
|
10
|
+
import { OrderedQuery_exports } from "./OrderedQuery.js";
|
|
11
|
+
import { QueryInitializer_exports } from "./QueryInitializer.js";
|
|
12
|
+
import { DatabaseReader_exports } from "./DatabaseReader.js";
|
|
13
|
+
import { DatabaseWriter_exports } from "./DatabaseWriter.js";
|
|
14
|
+
import { Registry_exports } from "./Registry.js";
|
|
15
|
+
import { RegistryItem_exports } from "./RegistryItem.js";
|
|
16
|
+
import { FunctionImpl_exports } from "./FunctionImpl.js";
|
|
17
|
+
import { GroupImpl_exports } from "./GroupImpl.js";
|
|
18
|
+
import { Handler_exports } from "./Handler.js";
|
|
19
|
+
import { MutationRunner_exports } from "./MutationRunner.js";
|
|
20
|
+
import { QueryRunner_exports } from "./QueryRunner.js";
|
|
21
|
+
import { Scheduler_exports } from "./Scheduler.js";
|
|
22
|
+
import { Storage_exports } from "./Storage.js";
|
|
23
|
+
import { HttpApi_exports } from "./HttpApi.js";
|
|
24
|
+
import { Impl_exports } from "./Impl.js";
|
|
25
|
+
import { MutationCtx_exports } from "./MutationCtx.js";
|
|
26
|
+
import { QueryCtx_exports } from "./QueryCtx.js";
|
|
27
|
+
import { VectorSearch_exports } from "./VectorSearch.js";
|
|
28
|
+
import { RegisteredFunctions_exports } from "./RegisteredFunctions.js";
|
|
29
|
+
import { TableInfo_exports } from "./TableInfo.js";
|
|
30
|
+
|
|
31
|
+
export { ActionCtx_exports as ActionCtx, ActionRunner_exports as ActionRunner, Api_exports as Api, Auth_exports as Auth, 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, Impl_exports as Impl, MutationCtx_exports as MutationCtx, MutationRunner_exports as MutationRunner, OrderedQuery_exports as OrderedQuery, QueryCtx_exports as QueryCtx, QueryInitializer_exports as QueryInitializer, QueryRunner_exports as QueryRunner, RegisteredFunctions_exports as RegisteredFunctions, Registry_exports as Registry, RegistryItem_exports as RegistryItem, Scheduler_exports as Scheduler, SchemaToValidator_exports as SchemaToValidator, Storage_exports as Storage, Table_exports as Table, TableInfo_exports as TableInfo, VectorSearch_exports as VectorSearch };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Effect, Predicate } from "effect";
|
|
2
|
+
|
|
3
|
+
//#region src/internal/utils.d.ts
|
|
4
|
+
type NestedObject<T> = {
|
|
5
|
+
[key: string]: T | NestedObject<T>;
|
|
6
|
+
};
|
|
7
|
+
declare const mapLeaves: <T, U>(obj: NestedObject<T>, leafRefinement: Predicate.Refinement<unknown, T>, f: (value: T) => U) => NestedObject<U>;
|
|
8
|
+
declare const forEachBranchLeaves: <T, A, E, R>(obj: NestedObject<T>, leafRefinement: Predicate.Refinement<unknown, T>, f: (branchLeaves: {
|
|
9
|
+
path: string[];
|
|
10
|
+
values: Record<string, T>;
|
|
11
|
+
}) => Effect.Effect<A, E, R>) => Effect.Effect<void, E, R>;
|
|
12
|
+
declare const setNestedProperty: <T extends object>(obj: T, path: PropertyKey[], value: any) => T;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { forEachBranchLeaves, mapLeaves, setNestedProperty };
|
|
15
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","names":[],"sources":["../../src/internal/utils.ts"],"sourcesContent":[],"mappings":";;;KAGK;EAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EACY,CADA,GACI,YADJ,CACiB,CADjB,CAAA;CACA;AAAiB,cAGrB,SAHqB,EAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,GAAA,EAI3B,YAJ2B,CAId,CAJc,CAAA,EAAA,cAAA,EAKhB,SAAA,CAAU,UALM,CAAA,OAAA,EAKc,CALd,CAAA,EAAA,CAAA,EAAA,CAAA,KAAA,EAMrB,CANqB,EAAA,GAMf,CANe,EAAA,GAO/B,YAP+B,CAOlB,CAPkB,CAAA;AAAb,cAgDR,mBAhDQ,EAAA,CAAA,CAAA,EAAA,CAAA,EAAA,CAAA,EAAA,CAAA,CAAA,CAAA,GAAA,EAiDd,YAjDc,CAiDD,CAjDC,CAAA,EAAA,cAAA,EAkDH,SAAA,CAAU,UAlDP,CAAA,OAAA,EAkD2B,CAlD3B,CAAA,EAAA,CAAA,EAAA,CAAA,YAAA,EAAA;EAAY,IAAA,EAAA,MAAA,EAAA;EAGpB,MAAA,EAkDD,MAhCX,CAAA,MAAA,EAgC0B,CAhC1B,CAAA;CAjBmB,EAAA,GAkDZ,MAAA,CAAO,MAlDK,CAkDE,CAlDF,EAkDK,CAlDL,EAkDQ,CAlDR,CAAA,EAAA,GAmDjB,MAAA,CAAO,MAnDU,CAAA,IAAA,EAmDG,CAnDH,EAmDM,CAnDN,CAAA;AAAb,cA0DM,iBA1DN,EAAA,CAAA,UAAA,MAAA,CAAA,CAAA,GAAA,EA2DA,CA3DA,EAAA,IAAA,EA4DC,WA5DD,EAAA,EAAA,KAAA,EAAA,GAAA,EAAA,GA8DJ,CA9DI"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Array, Effect, Record } from "effect";
|
|
2
|
+
|
|
3
|
+
//#region src/internal/utils.ts
|
|
4
|
+
const mapLeaves = (obj, leafRefinement, f) => {
|
|
5
|
+
const result = {};
|
|
6
|
+
for (const key in obj) {
|
|
7
|
+
const value = obj[key];
|
|
8
|
+
if (leafRefinement(value)) result[key] = f(value);
|
|
9
|
+
else result[key] = mapLeaves(value, leafRefinement, f);
|
|
10
|
+
}
|
|
11
|
+
return result;
|
|
12
|
+
};
|
|
13
|
+
const collectBranchLeaves = (obj, leafRefinement, path = []) => {
|
|
14
|
+
const leaves = Record.filter(obj, leafRefinement);
|
|
15
|
+
const currentBranch = Record.keys(leaves).length > 0 ? [{
|
|
16
|
+
path,
|
|
17
|
+
values: leaves
|
|
18
|
+
}] : [];
|
|
19
|
+
const nestedBranches = Array.flatMap(Record.keys(obj), (key) => {
|
|
20
|
+
const value = obj[key];
|
|
21
|
+
if (!leafRefinement(value) && typeof value === "object") return collectBranchLeaves(value, leafRefinement, [...path, key]);
|
|
22
|
+
return [];
|
|
23
|
+
});
|
|
24
|
+
return [...currentBranch, ...nestedBranches];
|
|
25
|
+
};
|
|
26
|
+
const forEachBranchLeaves = (obj, leafRefinement, f) => {
|
|
27
|
+
const branchLeaves = collectBranchLeaves(obj, leafRefinement);
|
|
28
|
+
return Effect.forEach(branchLeaves, f, { discard: true });
|
|
29
|
+
};
|
|
30
|
+
const setNestedProperty = (obj, path, value) => {
|
|
31
|
+
if (path.length === 0) return obj;
|
|
32
|
+
if (path.length === 1) {
|
|
33
|
+
const key$1 = path[0];
|
|
34
|
+
return {
|
|
35
|
+
...obj,
|
|
36
|
+
[key$1]: value
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
const [head, ...tail] = path;
|
|
40
|
+
const key = head;
|
|
41
|
+
return {
|
|
42
|
+
...obj,
|
|
43
|
+
[key]: setNestedProperty(obj[key] ?? {}, tail, value)
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
//#endregion
|
|
48
|
+
export { forEachBranchLeaves, mapLeaves, setNestedProperty };
|
|
49
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","names":["result: any","key"],"sources":["../../src/internal/utils.ts"],"sourcesContent":["import type { Predicate } from \"effect\";\nimport { Array, Effect, Record } from \"effect\";\n\ntype NestedObject<T> = {\n [key: string]: T | NestedObject<T>;\n};\n\nexport const mapLeaves = <T, U>(\n obj: NestedObject<T>,\n leafRefinement: Predicate.Refinement<unknown, T>,\n f: (value: T) => U,\n): NestedObject<U> => {\n const result: any = {};\n\n for (const key in obj) {\n const value = obj[key];\n\n if (leafRefinement(value)) {\n result[key] = f(value as T);\n } else {\n result[key] = mapLeaves(value as NestedObject<T>, leafRefinement, f);\n }\n }\n\n return result;\n};\n\nconst collectBranchLeaves = <T>(\n obj: NestedObject<T>,\n leafRefinement: Predicate.Refinement<unknown, T>,\n path: string[] = [],\n): { path: string[]; values: Record<string, T> }[] => {\n const leaves = Record.filter(obj, leafRefinement) as Record<string, T>;\n const hasLeaves = Record.keys(leaves).length > 0;\n\n const currentBranch = hasLeaves ? [{ path, values: leaves }] : [];\n\n const nestedBranches = Array.flatMap(Record.keys(obj), (key) => {\n const value = obj[key];\n\n if (!leafRefinement(value) && typeof value === \"object\") {\n return collectBranchLeaves(value as NestedObject<T>, leafRefinement, [\n ...path,\n key,\n ]);\n }\n return [];\n });\n\n return [...currentBranch, ...nestedBranches];\n};\n\nexport const forEachBranchLeaves = <T, A, E, R>(\n obj: NestedObject<T>,\n leafRefinement: Predicate.Refinement<unknown, T>,\n f: (branchLeaves: {\n path: string[];\n values: Record<string, T>;\n }) => Effect.Effect<A, E, R>,\n): Effect.Effect<void, E, R> => {\n const branchLeaves = collectBranchLeaves(obj, leafRefinement);\n return Effect.forEach(branchLeaves, f, {\n discard: true,\n });\n};\n\nexport const setNestedProperty = <T extends object>(\n obj: T,\n path: PropertyKey[],\n value: any,\n): T => {\n if (path.length === 0) {\n return obj;\n }\n\n if (path.length === 1) {\n const key = path[0] as keyof T;\n return { ...obj, [key]: value };\n }\n\n const [head, ...tail] = path;\n const key = head as keyof T;\n return {\n ...obj,\n [key]: setNestedProperty((obj as any)[key] ?? {}, tail, value),\n };\n};\n"],"mappings":";;;AAOA,MAAa,aACX,KACA,gBACA,MACoB;CACpB,MAAMA,SAAc,EAAE;AAEtB,MAAK,MAAM,OAAO,KAAK;EACrB,MAAM,QAAQ,IAAI;AAElB,MAAI,eAAe,MAAM,CACvB,QAAO,OAAO,EAAE,MAAW;MAE3B,QAAO,OAAO,UAAU,OAA0B,gBAAgB,EAAE;;AAIxE,QAAO;;AAGT,MAAM,uBACJ,KACA,gBACA,OAAiB,EAAE,KACiC;CACpD,MAAM,SAAS,OAAO,OAAO,KAAK,eAAe;CAGjD,MAAM,gBAFY,OAAO,KAAK,OAAO,CAAC,SAAS,IAEb,CAAC;EAAE;EAAM,QAAQ;EAAQ,CAAC,GAAG,EAAE;CAEjE,MAAM,iBAAiB,MAAM,QAAQ,OAAO,KAAK,IAAI,GAAG,QAAQ;EAC9D,MAAM,QAAQ,IAAI;AAElB,MAAI,CAAC,eAAe,MAAM,IAAI,OAAO,UAAU,SAC7C,QAAO,oBAAoB,OAA0B,gBAAgB,CACnE,GAAG,MACH,IACD,CAAC;AAEJ,SAAO,EAAE;GACT;AAEF,QAAO,CAAC,GAAG,eAAe,GAAG,eAAe;;AAG9C,MAAa,uBACX,KACA,gBACA,MAI8B;CAC9B,MAAM,eAAe,oBAAoB,KAAK,eAAe;AAC7D,QAAO,OAAO,QAAQ,cAAc,GAAG,EACrC,SAAS,MACV,CAAC;;AAGJ,MAAa,qBACX,KACA,MACA,UACM;AACN,KAAI,KAAK,WAAW,EAClB,QAAO;AAGT,KAAI,KAAK,WAAW,GAAG;EACrB,MAAMC,QAAM,KAAK;AACjB,SAAO;GAAE,GAAG;IAAMA,QAAM;GAAO;;CAGjC,MAAM,CAAC,MAAM,GAAG,QAAQ;CACxB,MAAM,MAAM;AACZ,QAAO;EACL,GAAG;GACF,MAAM,kBAAmB,IAAY,QAAQ,EAAE,EAAE,MAAM,MAAM;EAC/D"}
|
package/package.json
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@confect/server",
|
|
3
|
+
"version": "1.0.0-next.0",
|
|
4
|
+
"description": "Confect server",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/rjdellecese/confect.git"
|
|
8
|
+
},
|
|
9
|
+
"bugs": {
|
|
10
|
+
"url": "https://github.com/rjdellecese/confect/issues"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://confect.rjdellecese.com",
|
|
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
|
+
},
|
|
35
|
+
"keywords": [
|
|
36
|
+
"effect",
|
|
37
|
+
"convex"
|
|
38
|
+
],
|
|
39
|
+
"author": "RJ Dellecese",
|
|
40
|
+
"license": "ISC",
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@effect/cluster": "0.52.9",
|
|
43
|
+
"@effect/experimental": "0.57.1",
|
|
44
|
+
"@effect/language-service": "0.56.0",
|
|
45
|
+
"@effect/platform-node": "0.100.0",
|
|
46
|
+
"@effect/rpc": "0.72.1",
|
|
47
|
+
"@effect/sql": "0.48.0",
|
|
48
|
+
"@effect/vitest": "0.27.0",
|
|
49
|
+
"@effect/workflow": "^0.12.5",
|
|
50
|
+
"@eslint/js": "9.39.1",
|
|
51
|
+
"@swc/jest": "0.2.39",
|
|
52
|
+
"@tsconfig/strictest": "2.0.8",
|
|
53
|
+
"@types/node": "24.10.1",
|
|
54
|
+
"@vitest/coverage-v8": "3.2.4",
|
|
55
|
+
"convex-test": "0.0.38",
|
|
56
|
+
"dotenv": "17.2.3",
|
|
57
|
+
"eslint": "9.39.1",
|
|
58
|
+
"prettier": "3.6.2",
|
|
59
|
+
"tsdown": "0.16.4",
|
|
60
|
+
"typescript": "5.9.3",
|
|
61
|
+
"typescript-eslint": "8.46.4",
|
|
62
|
+
"vite": "7.2.2",
|
|
63
|
+
"vite-tsconfig-paths": "5.1.4",
|
|
64
|
+
"vitest": "3.2.4",
|
|
65
|
+
"@confect/cli": "1.0.0-next.0",
|
|
66
|
+
"@confect/test": "1.0.0-next.0"
|
|
67
|
+
},
|
|
68
|
+
"peerDependencies": {
|
|
69
|
+
"@effect/platform": "^0.93.2",
|
|
70
|
+
"convex": "^1.30.0",
|
|
71
|
+
"effect": "^3.19.3",
|
|
72
|
+
"@confect/core": "1.0.0-next.0"
|
|
73
|
+
},
|
|
74
|
+
"engines": {
|
|
75
|
+
"node": ">=22",
|
|
76
|
+
"pnpm": ">=10"
|
|
77
|
+
},
|
|
78
|
+
"main": "./dist/index.js",
|
|
79
|
+
"module": "./dist/index.js",
|
|
80
|
+
"types": "./dist/index.d.ts",
|
|
81
|
+
"scripts": {
|
|
82
|
+
"build": "tsdown --config-loader unrun",
|
|
83
|
+
"dev": "tsdown --watch",
|
|
84
|
+
"test": "vitest run",
|
|
85
|
+
"typecheck": "tsc --noEmit --project tsconfig.json",
|
|
86
|
+
"fix": "prettier --write . && eslint --fix . --max-warnings=0",
|
|
87
|
+
"lint": "prettier --check . && eslint . --max-warnings=0",
|
|
88
|
+
"clean": "rm -rf dist coverage node_modules"
|
|
89
|
+
}
|
|
90
|
+
}
|
package/src/ActionCtx.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { GenericActionCtx, GenericDataModel } from "convex/server";
|
|
2
|
+
import { Context } from "effect";
|
|
3
|
+
|
|
4
|
+
export const ActionCtx = <DataModel extends GenericDataModel>() =>
|
|
5
|
+
Context.GenericTag<GenericActionCtx<DataModel>>("@confect/server/ActionCtx");
|
|
6
|
+
|
|
7
|
+
export type ActionCtx<DataModel extends GenericDataModel> = ReturnType<
|
|
8
|
+
typeof ActionCtx<DataModel>
|
|
9
|
+
>["Identifier"];
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as Ref from "@confect/core/Ref";
|
|
2
|
+
import { type GenericActionCtx } from "convex/server";
|
|
3
|
+
import { Context, Effect, Layer, Schema } from "effect";
|
|
4
|
+
|
|
5
|
+
const makeActionRunner =
|
|
6
|
+
(runAction: GenericActionCtx<any>["runAction"]) =>
|
|
7
|
+
<Action extends Ref.AnyAction>(
|
|
8
|
+
action: Action,
|
|
9
|
+
args: Ref.Args<Action>["Type"],
|
|
10
|
+
) =>
|
|
11
|
+
Effect.gen(function* () {
|
|
12
|
+
const function_ = Ref.getFunction(action);
|
|
13
|
+
const functionName = Ref.getConvexFunctionName(action);
|
|
14
|
+
|
|
15
|
+
const encodedArgs = yield* Schema.encode(function_.args)(args);
|
|
16
|
+
const encodedReturns = yield* Effect.promise(() =>
|
|
17
|
+
runAction(functionName as any, encodedArgs),
|
|
18
|
+
);
|
|
19
|
+
return yield* Schema.decode(function_.returns)(encodedReturns);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
export const ActionRunner = Context.GenericTag<
|
|
23
|
+
ReturnType<typeof makeActionRunner>
|
|
24
|
+
>("@confect/server/ActionRunner");
|
|
25
|
+
export type ActionRunner = typeof ActionRunner.Identifier;
|
|
26
|
+
|
|
27
|
+
export const layer = (runAction: GenericActionCtx<any>["runAction"]) =>
|
|
28
|
+
Layer.succeed(ActionRunner, makeActionRunner(runAction));
|
package/src/Api.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type * as Spec from "@confect/core/Spec";
|
|
2
|
+
import type { GenericSchema, SchemaDefinition } from "convex/server";
|
|
3
|
+
import { defineSchema as defineConvexSchema } from "convex/server";
|
|
4
|
+
import { pipe, Predicate, Record } from "effect";
|
|
5
|
+
import type * as DatabaseSchema from "./DatabaseSchema";
|
|
6
|
+
|
|
7
|
+
export const TypeId = "@confect/server/Api";
|
|
8
|
+
export type TypeId = typeof TypeId;
|
|
9
|
+
|
|
10
|
+
export const isApi = (u: unknown): u is Any => Predicate.hasProperty(u, TypeId);
|
|
11
|
+
|
|
12
|
+
export interface Api<
|
|
13
|
+
DatabaseSchema_ extends DatabaseSchema.AnyWithProps,
|
|
14
|
+
Spec_ extends Spec.AnyWithProps,
|
|
15
|
+
> {
|
|
16
|
+
readonly [TypeId]: TypeId;
|
|
17
|
+
readonly spec: Spec_;
|
|
18
|
+
readonly databaseSchema: DatabaseSchema_;
|
|
19
|
+
readonly convexSchemaDefinition: SchemaDefinition<GenericSchema, true>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface Any {
|
|
23
|
+
readonly [TypeId]: TypeId;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface AnyWithProps
|
|
27
|
+
extends Api<DatabaseSchema.AnyWithProps, Spec.AnyWithProps> {}
|
|
28
|
+
|
|
29
|
+
export type Schema<Api_ extends AnyWithProps> = Api_["databaseSchema"];
|
|
30
|
+
|
|
31
|
+
export type Groups<Api_ extends AnyWithProps> = Spec.Groups<Api_["spec"]>;
|
|
32
|
+
|
|
33
|
+
const Proto = {
|
|
34
|
+
[TypeId]: TypeId,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const makeProto = <
|
|
38
|
+
DatabaseSchema_ extends DatabaseSchema.AnyWithProps,
|
|
39
|
+
Spec_ extends Spec.AnyWithProps,
|
|
40
|
+
>({
|
|
41
|
+
databaseSchema,
|
|
42
|
+
spec,
|
|
43
|
+
}: {
|
|
44
|
+
databaseSchema: DatabaseSchema.AnyWithProps;
|
|
45
|
+
spec: Spec_;
|
|
46
|
+
}): Api<DatabaseSchema_, Spec_> =>
|
|
47
|
+
Object.assign(Object.create(Proto), {
|
|
48
|
+
databaseSchema,
|
|
49
|
+
spec,
|
|
50
|
+
convexSchemaDefinition: pipe(
|
|
51
|
+
databaseSchema.tables,
|
|
52
|
+
Record.map(({ tableDefinition }) => tableDefinition),
|
|
53
|
+
defineConvexSchema,
|
|
54
|
+
),
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
export const make = <
|
|
58
|
+
DatabaseSchema_ extends DatabaseSchema.AnyWithProps,
|
|
59
|
+
Spec_ extends Spec.AnyWithProps,
|
|
60
|
+
>(
|
|
61
|
+
databaseSchema: DatabaseSchema_,
|
|
62
|
+
spec: Spec_,
|
|
63
|
+
): Api<DatabaseSchema_, Spec_> => makeProto({ databaseSchema, spec });
|