@confect/server 9.1.0 → 9.1.2
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 +20 -0
- package/dist/DatabaseWriter.d.ts.map +1 -1
- package/dist/DatabaseWriter.js.map +1 -1
- package/dist/Document.d.ts +1 -1
- package/dist/Document.d.ts.map +1 -1
- package/dist/Document.js.map +1 -1
- package/dist/TableInfo.d.ts +6 -5
- package/dist/TableInfo.d.ts.map +1 -1
- package/dist/TableInfo.js.map +1 -1
- package/dist/tsconfig.src.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/DatabaseWriter.ts +4 -2
- package/src/Document.ts +3 -1
- package/src/TableInfo.ts +15 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @confect/server
|
|
2
2
|
|
|
3
|
+
## 9.1.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- e2bb5ef: Fix `db.patch`, `db.replace`, and `db.insert` rejecting branch-specific fields on tables whose schema is a `Schema.Union`.
|
|
8
|
+
|
|
9
|
+
Writing a field that only exists on one member of the union (e.g. patching `status` on the `Dropship` branch of a union-typed `orders` table) failed to typecheck — only the fields common to every member were accepted. These operations now accept every branch's fields. This also unblocks consuming a Confect backend as a referenced/composite TypeScript project, which previously failed to emit declarations because of these errors.
|
|
10
|
+
- @confect/core@9.1.2
|
|
11
|
+
|
|
12
|
+
## 9.1.1
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- 308b347: Fix codegen emitting an invalid `interface … extends Document.Document<…>` in `_generated/docs.ts` for tables whose document type is not a single object.
|
|
17
|
+
|
|
18
|
+
`Document.Document<Schema, Table>` is a type alias that resolves to whatever the table's schema is, so for a `Schema.Union` table (or any non-object document: branded primitives, `Schema.transform` results, …) it resolves to a union. An `interface` cannot extend a union, so the generated `XDoc` tripped `TS2312` and collapsed to an unusable type, which then broke every reader/writer helper that printed it.
|
|
19
|
+
|
|
20
|
+
Codegen now emits a `type` alias per table — `export type NotesDoc = Document.Document<typeof schemaDefinition, "notes">;` — which keeps the named document type (so declaration emit still prints `NotesDoc` rather than the expanded row) while supporting every document shape. Runtime behaviour is unchanged.
|
|
21
|
+
- @confect/core@9.1.1
|
|
22
|
+
|
|
3
23
|
## 9.1.0
|
|
4
24
|
|
|
5
25
|
### Minor Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DatabaseWriter.d.ts","sourceRoot":"","sources":["../src/DatabaseWriter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAIV,qBAAqB,EAEtB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE/C,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAEtC,OAAO,KAAK,KAAK,cAAc,MAAM,kBAAkB,CAAC;AACxD,OAAO,KAAK,KAAK,SAAS,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAE,cAAc,IAAI,eAAe,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAC;AACvC,OAAO,KAAK,gBAAgB,MAAM,oBAAoB,CAAC;AAIvD,MAAM,WAAW,2BAA2B,CAC1C,UAAU,SAAS,SAAS,CAAC,YAAY,EACzC,SAAS,SAAS,SAAS,CAAC,UAAU,CAAC,UAAU,CAAC,EAClD,GAAG,GAAG,eAAe,CAAC,UAAU,EAAE,SAAS,CAAC;IAE5C,QAAQ,CAAC,MAAM,EAAE,CACf,QAAQ,EAAE,QAAQ,CAAC,mBAAmB,CAAC,GAAG,CAAC,KACxC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,EAAE,QAAQ,CAAC,mBAAmB,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,EACtC,qBAAqB,CAAC,eAAe,EAAE,IAAI,CAAC,CAC7C,CAAC;AAEF,eAAO,MAAM,IAAI,GAAI,eAAe,SAAS,cAAc,CAAC,YAAY,EACtE,gBAAgB,eAAe,EAC/B,sBAAsB,qBAAqB,CACzC,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC,CAC1D,KACA,qBAAqB,CAAC,eAAe,CAmHvC,CAAC;AAEF,eAAO,MAAM,cAAc,GACzB,eAAe,SAAS,cAAc,CAAC,YAAY,EACnD,IAAI,GAAG,EAAE,OACN,iBAAiB,CAAC,eAAe,EAAE,IAAI,CAIP,CAAC;AAEtC,MAAM,MAAM,cAAc,CACxB,eAAe,SAAS,cAAc,CAAC,YAAY,IACjD,qBAAqB,CAAC,eAAe,CAAC,CAAC;AAE3C,eAAO,MAAM,KAAK,GAAI,eAAe,SAAS,cAAc,CAAC,YAAY,EACvE,gBAAgB,eAAe,EAC/B,sBAAsB,qBAAqB,CACzC,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC,CAC1D,0EAKA,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DatabaseWriter.js","names":["Document.encode","QueryInitializer.getById"],"sources":["../src/DatabaseWriter.ts"],"sourcesContent":["import type {\n BetterOmit,\n DocumentByName,\n Expand,\n GenericDatabaseWriter,\n WithoutSystemFields,\n} from \"convex/server\";\nimport type { GenericId } from \"convex/values\";\nimport { pipe } from \"effect/Function\";\nimport * as Context from \"effect/Context\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\nimport * as Record from \"effect/Record\";\nimport type * as DatabaseSchema from \"./DatabaseSchema\";\nimport type * as DataModel from \"./DataModel\";\nimport type { DocumentByName as DocumentByName_ } from \"./DataModel\";\nimport * as Document from \"./Document\";\nimport * as QueryInitializer from \"./QueryInitializer\";\nimport type * as Table from \"./Table\";\nimport type * as TableInfo from \"./TableInfo\";\n\nexport interface DatabaseWriterTableAccessor<\n DataModel_ extends DataModel.AnyWithProps,\n TableName extends DataModel.TableNames<DataModel_>,\n Doc = DocumentByName_<DataModel_, TableName>,\n> {\n readonly insert: (\n document: Document.WithoutSystemFields<Doc>,\n ) => Effect.Effect<GenericId<TableName>, Document.DocumentEncodeError>;\n readonly patch: (\n id: GenericId<TableName>,\n patchedValues: Partial<Document.WithoutSystemFields<Doc>>,\n ) => Effect.Effect<\n void,\n | QueryInitializer.GetByIdFailure\n | Document.DocumentDecodeError\n | Document.DocumentEncodeError\n >;\n readonly replace: (\n id: GenericId<TableName>,\n value: Document.WithoutSystemFields<Doc>,\n ) => Effect.Effect<void, Document.DocumentEncodeError>;\n readonly delete: (id: GenericId<TableName>) => Effect.Effect<void>;\n}\n\n/**\n * The service shape backing the `DatabaseWriter` tag. Named (rather than an\n * inferred anonymous object) so declaration emit prints\n * `DatabaseWriterService<…>` by reference instead of expanding the data model.\n * `Docs` is the optional named document registry (see `DatabaseReaderService`).\n */\nexport interface DatabaseWriterService<\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n Docs = {},\n> {\n readonly table: <\n const TableName extends DataModel.TableNames<\n DataModel.FromSchema<DatabaseSchema_>\n >,\n >(\n tableName: TableName,\n ) => DatabaseWriterTableAccessor<\n DataModel.FromSchema<DatabaseSchema_>,\n TableName,\n TableName extends keyof Docs\n ? Docs[TableName]\n : DocumentByName_<DataModel.FromSchema<DatabaseSchema_>, TableName>\n >;\n}\n\n/**\n * The tag's *Identifier* is `Docs`-independent (see `DatabaseReaderTag`); only\n * the *Service* carries `Docs` so writer inputs print the named doc interfaces.\n */\nexport type DatabaseWriterTag<\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n Docs = {},\n> = Context.Tag<\n DatabaseWriterService<DatabaseSchema_>,\n DatabaseWriterService<DatabaseSchema_, Docs>\n>;\n\nexport const make = <DatabaseSchema_ extends DatabaseSchema.AnyWithProps>(\n databaseSchema: DatabaseSchema_,\n convexDatabaseWriter: GenericDatabaseWriter<\n DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>\n >,\n): DatabaseWriterService<DatabaseSchema_> => {\n type DataModel_ = DataModel.FromSchema<DatabaseSchema_>;\n\n const table = <const TableName extends DataModel.TableNames<DataModel_>>(\n tableName: TableName,\n ) => {\n const tableDef = databaseSchema.tables[tableName] as Table.WithName<\n DatabaseSchema.Tables<DatabaseSchema_>,\n TableName\n >;\n\n const insert = (\n document: Document.WithoutSystemFields<\n DocumentByName_<DataModel_, TableName>\n >,\n ) =>\n Effect.gen(function* () {\n const encodedDocument = yield* Document.encode(\n document,\n tableName,\n tableDef.Fields,\n );\n\n const id = yield* Effect.promise(() =>\n convexDatabaseWriter.insert(\n tableName,\n encodedDocument as WithoutSystemFields<\n DocumentByName<DataModel.ToConvex<DataModel_>, TableName>\n >,\n ),\n );\n\n return id;\n });\n\n const patch = (\n id: GenericId<TableName>,\n patchedValues: Partial<\n WithoutSystemFields<DocumentByName_<DataModel_, TableName>>\n >,\n ) =>\n Effect.gen(function* () {\n const tableSchema = tableDef.Fields as TableInfo.TableSchema<\n DataModel.TableInfoWithName_<DataModel_, TableName>\n >;\n\n const originalDecodedDoc = yield* QueryInitializer.getById(\n tableName,\n convexDatabaseWriter as any,\n tableDef,\n )(id);\n\n const updatedEncodedDoc = yield* pipe(\n patchedValues,\n Record.reduce(originalDecodedDoc, (acc, value, key) =>\n value === undefined\n ? Record.remove(acc, key)\n : Record.set(acc, key, value),\n ),\n Document.encode(tableName, tableSchema),\n );\n\n yield* Effect.promise(() =>\n convexDatabaseWriter.replace(\n id,\n updatedEncodedDoc as Expand<\n BetterOmit<\n DocumentByName<DataModel.ToConvex<DataModel_>, TableName>,\n \"_creationTime\" | \"_id\"\n >\n >,\n ),\n );\n });\n\n const replace = (\n id: GenericId<TableName>,\n value: WithoutSystemFields
|
|
1
|
+
{"version":3,"file":"DatabaseWriter.js","names":["Document.encode","QueryInitializer.getById"],"sources":["../src/DatabaseWriter.ts"],"sourcesContent":["import type {\n BetterOmit,\n DocumentByName,\n Expand,\n GenericDatabaseWriter,\n WithoutSystemFields,\n} from \"convex/server\";\nimport type { GenericId } from \"convex/values\";\nimport { pipe } from \"effect/Function\";\nimport * as Context from \"effect/Context\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\nimport * as Record from \"effect/Record\";\nimport type * as DatabaseSchema from \"./DatabaseSchema\";\nimport type * as DataModel from \"./DataModel\";\nimport type { DocumentByName as DocumentByName_ } from \"./DataModel\";\nimport * as Document from \"./Document\";\nimport * as QueryInitializer from \"./QueryInitializer\";\nimport type * as Table from \"./Table\";\nimport type * as TableInfo from \"./TableInfo\";\n\nexport interface DatabaseWriterTableAccessor<\n DataModel_ extends DataModel.AnyWithProps,\n TableName extends DataModel.TableNames<DataModel_>,\n Doc = DocumentByName_<DataModel_, TableName>,\n> {\n readonly insert: (\n document: Document.WithoutSystemFields<Doc>,\n ) => Effect.Effect<GenericId<TableName>, Document.DocumentEncodeError>;\n readonly patch: (\n id: GenericId<TableName>,\n patchedValues: Partial<Document.WithoutSystemFields<Doc>>,\n ) => Effect.Effect<\n void,\n | QueryInitializer.GetByIdFailure\n | Document.DocumentDecodeError\n | Document.DocumentEncodeError\n >;\n readonly replace: (\n id: GenericId<TableName>,\n value: Document.WithoutSystemFields<Doc>,\n ) => Effect.Effect<void, Document.DocumentEncodeError>;\n readonly delete: (id: GenericId<TableName>) => Effect.Effect<void>;\n}\n\n/**\n * The service shape backing the `DatabaseWriter` tag. Named (rather than an\n * inferred anonymous object) so declaration emit prints\n * `DatabaseWriterService<…>` by reference instead of expanding the data model.\n * `Docs` is the optional named document registry (see `DatabaseReaderService`).\n */\nexport interface DatabaseWriterService<\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n Docs = {},\n> {\n readonly table: <\n const TableName extends DataModel.TableNames<\n DataModel.FromSchema<DatabaseSchema_>\n >,\n >(\n tableName: TableName,\n ) => DatabaseWriterTableAccessor<\n DataModel.FromSchema<DatabaseSchema_>,\n TableName,\n TableName extends keyof Docs\n ? Docs[TableName]\n : DocumentByName_<DataModel.FromSchema<DatabaseSchema_>, TableName>\n >;\n}\n\n/**\n * The tag's *Identifier* is `Docs`-independent (see `DatabaseReaderTag`); only\n * the *Service* carries `Docs` so writer inputs print the named doc interfaces.\n */\nexport type DatabaseWriterTag<\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n Docs = {},\n> = Context.Tag<\n DatabaseWriterService<DatabaseSchema_>,\n DatabaseWriterService<DatabaseSchema_, Docs>\n>;\n\nexport const make = <DatabaseSchema_ extends DatabaseSchema.AnyWithProps>(\n databaseSchema: DatabaseSchema_,\n convexDatabaseWriter: GenericDatabaseWriter<\n DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>\n >,\n): DatabaseWriterService<DatabaseSchema_> => {\n type DataModel_ = DataModel.FromSchema<DatabaseSchema_>;\n\n const table = <const TableName extends DataModel.TableNames<DataModel_>>(\n tableName: TableName,\n ) => {\n const tableDef = databaseSchema.tables[tableName] as Table.WithName<\n DatabaseSchema.Tables<DatabaseSchema_>,\n TableName\n >;\n\n const insert = (\n document: Document.WithoutSystemFields<\n DocumentByName_<DataModel_, TableName>\n >,\n ) =>\n Effect.gen(function* () {\n const encodedDocument = yield* Document.encode(\n document,\n tableName,\n tableDef.Fields,\n );\n\n const id = yield* Effect.promise(() =>\n convexDatabaseWriter.insert(\n tableName,\n encodedDocument as WithoutSystemFields<\n DocumentByName<DataModel.ToConvex<DataModel_>, TableName>\n >,\n ),\n );\n\n return id;\n });\n\n const patch = (\n id: GenericId<TableName>,\n patchedValues: Partial<\n Document.WithoutSystemFields<DocumentByName_<DataModel_, TableName>>\n >,\n ) =>\n Effect.gen(function* () {\n const tableSchema = tableDef.Fields as TableInfo.TableSchema<\n DataModel.TableInfoWithName_<DataModel_, TableName>\n >;\n\n const originalDecodedDoc = yield* QueryInitializer.getById(\n tableName,\n convexDatabaseWriter as any,\n tableDef,\n )(id);\n\n const updatedEncodedDoc = yield* pipe(\n patchedValues,\n Record.reduce(originalDecodedDoc, (acc, value, key) =>\n value === undefined\n ? Record.remove(acc, key)\n : Record.set(acc, key, value),\n ),\n Document.encode(tableName, tableSchema),\n );\n\n yield* Effect.promise(() =>\n convexDatabaseWriter.replace(\n id,\n updatedEncodedDoc as Expand<\n BetterOmit<\n DocumentByName<DataModel.ToConvex<DataModel_>, TableName>,\n \"_creationTime\" | \"_id\"\n >\n >,\n ),\n );\n });\n\n const replace = (\n id: GenericId<TableName>,\n value: Document.WithoutSystemFields<\n DocumentByName_<DataModel_, TableName>\n >,\n ) =>\n Effect.gen(function* () {\n const updatedEncodedDoc = yield* Document.encode(\n value,\n tableName,\n tableDef.Fields,\n );\n\n yield* Effect.promise(() =>\n convexDatabaseWriter.replace(\n id,\n updatedEncodedDoc as Expand<\n BetterOmit<\n DocumentByName<DataModel.ToConvex<DataModel_>, TableName>,\n \"_creationTime\" | \"_id\"\n >\n >,\n ),\n );\n });\n\n const delete_ = (id: GenericId<TableName>) =>\n Effect.promise(() => convexDatabaseWriter.delete(id));\n\n return {\n insert,\n patch,\n replace,\n delete: delete_,\n };\n };\n\n return {\n table,\n } as DatabaseWriterService<DatabaseSchema_>;\n};\n\nexport const DatabaseWriter = <\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n Docs = {},\n>(): DatabaseWriterTag<DatabaseSchema_, Docs> =>\n Context.GenericTag<\n DatabaseWriterService<DatabaseSchema_>,\n DatabaseWriterService<DatabaseSchema_, Docs>\n >(\"@confect/server/DatabaseWriter\");\n\nexport type DatabaseWriter<\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n> = DatabaseWriterService<DatabaseSchema_>;\n\nexport const layer = <DatabaseSchema_ extends DatabaseSchema.AnyWithProps>(\n databaseSchema: DatabaseSchema_,\n convexDatabaseWriter: GenericDatabaseWriter<\n DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>\n >,\n) =>\n Layer.succeed(\n DatabaseWriter<DatabaseSchema_>(),\n make(databaseSchema, convexDatabaseWriter),\n );\n"],"mappings":";;;;;;;;;;;;;;;AAkFA,MAAa,QACX,gBACA,yBAG2C;CAG3C,MAAM,SACJ,cACG;EACH,MAAM,WAAW,eAAe,OAAO;EAKvC,MAAM,UACJ,aAIA,OAAO,IAAI,aAAa;GACtB,MAAM,kBAAkB,OAAOA,OAC7B,UACA,WACA,SAAS,OACV;AAWD,UATW,OAAO,OAAO,cACvB,qBAAqB,OACnB,WACA,gBAGD,CACF;IAGD;EAEJ,MAAM,SACJ,IACA,kBAIA,OAAO,IAAI,aAAa;GACtB,MAAM,cAAc,SAAS;GAI7B,MAAM,qBAAqB,OAAOC,QAChC,WACA,sBACA,SACD,CAAC,GAAG;GAEL,MAAM,oBAAoB,OAAO,KAC/B,eACA,OAAO,OAAO,qBAAqB,KAAK,OAAO,QAC7C,UAAU,SACN,OAAO,OAAO,KAAK,IAAI,GACvB,OAAO,IAAI,KAAK,KAAK,MAAM,CAChC,EACDD,OAAgB,WAAW,YAAY,CACxC;AAED,UAAO,OAAO,cACZ,qBAAqB,QACnB,IACA,kBAMD,CACF;IACD;EAEJ,MAAM,WACJ,IACA,UAIA,OAAO,IAAI,aAAa;GACtB,MAAM,oBAAoB,OAAOA,OAC/B,OACA,WACA,SAAS,OACV;AAED,UAAO,OAAO,cACZ,qBAAqB,QACnB,IACA,kBAMD,CACF;IACD;EAEJ,MAAM,WAAW,OACf,OAAO,cAAc,qBAAqB,OAAO,GAAG,CAAC;AAEvD,SAAO;GACL;GACA;GACA;GACA,QAAQ;GACT;;AAGH,QAAO,EACL,OACD;;AAGH,MAAa,uBAIX,QAAQ,WAGN,iCAAiC;AAMrC,MAAa,SACX,gBACA,yBAIA,MAAM,QACJ,gBAAiC,EACjC,KAAK,gBAAgB,qBAAqB,CAC3C"}
|
package/dist/Document.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type * as DataModel from "./DataModel";
|
|
|
6
6
|
import type { ReadonlyValue } from "./SchemaToValidator";
|
|
7
7
|
import type * as TableInfo from "./TableInfo";
|
|
8
8
|
export type Document<Schema_ extends DatabaseSchema.AnyWithProps, TableName extends DatabaseSchema.TableNames<Schema_>> = DataModel.DocumentByName<DataModel.FromSchema<Schema_>, TableName>;
|
|
9
|
-
export type WithoutSystemFields<Doc> = Omit<Doc, "_creationTime" | "_id"
|
|
9
|
+
export type WithoutSystemFields<Doc> = Doc extends unknown ? Omit<Doc, "_creationTime" | "_id"> : never;
|
|
10
10
|
export type Any = any;
|
|
11
11
|
export type AnyEncoded = ReadonlyRecord<string, ReadonlyValue>;
|
|
12
12
|
export declare const decode: (<DataModel_ extends DataModel.AnyWithProps, TableName extends DataModel.TableNames<DataModel_>>(tableName: TableName, tableSchema: TableInfo.TableSchema<DataModel.TableInfoWithName_<DataModel_, TableName>>) => (self: DataModel.TableInfoWithName_<DataModel_, TableName>["convexDocument"]) => Effect.Effect<DataModel.TableInfoWithName_<DataModel_, TableName>["document"], DocumentDecodeError>) & (<DataModel_ extends DataModel.AnyWithProps, TableName extends DataModel.TableNames<DataModel_>>(self: DataModel.TableInfoWithName_<DataModel_, TableName>["convexDocument"], tableName: TableName, tableSchema: TableInfo.TableSchema<DataModel.TableInfoWithName_<DataModel_, TableName>>) => Effect.Effect<DataModel.TableInfoWithName_<DataModel_, TableName>["document"], DocumentDecodeError>);
|
package/dist/Document.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Document.d.ts","sourceRoot":"","sources":["../src/Document.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAGxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,KAAK,KAAK,cAAc,MAAM,kBAAkB,CAAC;AACxD,OAAO,KAAK,KAAK,SAAS,MAAM,aAAa,CA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AC,kBAAkB,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC,iBAAiB,CAAC,EACtE,mBAAmB,CACpB,MAEC,UAAU,SAAS,SAAS,CAAC,YAAY,EACzC,SAAS,SAAS,SAAS,CAAC,UAAU,CAAC,UAAU,CAAC,QAE5C,SAAS,CAAC,kBAAkB,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC,UAAU,CAAC,aAC1D,SAAS,eACP,SAAS,CAAC,WAAW,CAChC,SAAS,CAAC,kBAAkB,CAAC,UAAU,EAAE,SAAS,CAAC,CACpD,KACE,MAAM,CAAC,MAAM,CAChB,SAAS,CAAC,kBAAkB,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC,iBAAiB,CAAC,EACtE,mBAAmB,CACpB,CAuCF,CAAC;;;;;;;;AAEF,qBAAa,mBAAoB,SAAQ,wBAOxC;IACC,IAAa,OAAO,IAAI,MAAM,CAM7B;CACF;;;;;;;;AAED,qBAAa,mBAAoB,SAAQ,wBAOxC;IACC,IAAa,OAAO,IAAI,MAAM,CAM7B;CACF;AAED,eAAO,MAAM,oBAAoB,GAAI,6BAIlC;IACD,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB,WAAkE,CAAC"}
|
package/dist/Document.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Document.js","names":[],"sources":["../src/Document.ts"],"sourcesContent":["import * as SystemFields from \"@confect/core/SystemFields\";\nimport { pipe } from \"effect/Function\";\nimport * as Effect from \"effect/Effect\";\nimport * as Function from \"effect/Function\";\nimport * as ParseResult from \"effect/ParseResult\";\nimport * as Schema from \"effect/Schema\";\nimport type { ReadonlyRecord } from \"effect/Record\";\nimport type * as DatabaseSchema from \"./DatabaseSchema\";\nimport type * as DataModel from \"./DataModel\";\nimport type { ReadonlyValue } from \"./SchemaToValidator\";\nimport type * as TableInfo from \"./TableInfo\";\n\nexport type Document<\n Schema_ extends DatabaseSchema.AnyWithProps,\n TableName extends DatabaseSchema.TableNames<Schema_>,\n> = DataModel.DocumentByName<DataModel.FromSchema<Schema_>, TableName>;\n\nexport type WithoutSystemFields<Doc> = Omit<Doc, \"_creationTime\" | \"_id\"
|
|
1
|
+
{"version":3,"file":"Document.js","names":[],"sources":["../src/Document.ts"],"sourcesContent":["import * as SystemFields from \"@confect/core/SystemFields\";\nimport { pipe } from \"effect/Function\";\nimport * as Effect from \"effect/Effect\";\nimport * as Function from \"effect/Function\";\nimport * as ParseResult from \"effect/ParseResult\";\nimport * as Schema from \"effect/Schema\";\nimport type { ReadonlyRecord } from \"effect/Record\";\nimport type * as DatabaseSchema from \"./DatabaseSchema\";\nimport type * as DataModel from \"./DataModel\";\nimport type { ReadonlyValue } from \"./SchemaToValidator\";\nimport type * as TableInfo from \"./TableInfo\";\n\nexport type Document<\n Schema_ extends DatabaseSchema.AnyWithProps,\n TableName extends DatabaseSchema.TableNames<Schema_>,\n> = DataModel.DocumentByName<DataModel.FromSchema<Schema_>, TableName>;\n\nexport type WithoutSystemFields<Doc> = Doc extends unknown\n ? Omit<Doc, \"_creationTime\" | \"_id\">\n : never;\n\nexport type Any = any;\nexport type AnyEncoded = ReadonlyRecord<string, ReadonlyValue>;\n\ntype Decode = (doc: unknown) => Effect.Effect<unknown, ParseResult.ParseError>;\n\nconst decoderCache = new WeakMap<\n Schema.Schema.AnyNoContext,\n Map<string, Decode>\n>();\n\nconst getDecoder = (\n tableName: string,\n tableSchema: Schema.Schema.AnyNoContext,\n): Decode => {\n const byTable =\n decoderCache.get(tableSchema) ??\n (() => {\n const map = new Map<string, Decode>();\n decoderCache.set(tableSchema, map);\n return map;\n })();\n\n return (\n byTable.get(tableName) ??\n (() => {\n const decoder = Schema.decode(\n SystemFields.extendWithSystemFields(tableName, tableSchema),\n ) as Decode;\n byTable.set(tableName, decoder);\n return decoder;\n })()\n );\n};\n\nexport const decode = Function.dual<\n <\n DataModel_ extends DataModel.AnyWithProps,\n TableName extends DataModel.TableNames<DataModel_>,\n >(\n tableName: TableName,\n tableSchema: TableInfo.TableSchema<\n DataModel.TableInfoWithName_<DataModel_, TableName>\n >,\n ) => (\n self: DataModel.TableInfoWithName_<DataModel_, TableName>[\"convexDocument\"],\n ) => Effect.Effect<\n DataModel.TableInfoWithName_<DataModel_, TableName>[\"document\"],\n DocumentDecodeError\n >,\n <\n DataModel_ extends DataModel.AnyWithProps,\n TableName extends DataModel.TableNames<DataModel_>,\n >(\n self: DataModel.TableInfoWithName_<DataModel_, TableName>[\"convexDocument\"],\n tableName: TableName,\n tableSchema: TableInfo.TableSchema<\n DataModel.TableInfoWithName_<DataModel_, TableName>\n >,\n ) => Effect.Effect<\n DataModel.TableInfoWithName_<DataModel_, TableName>[\"document\"],\n DocumentDecodeError\n >\n>(\n 3,\n <\n DataModel_ extends DataModel.AnyWithProps,\n TableName extends DataModel.TableNames<DataModel_>,\n >(\n self: DataModel.TableInfoWithName_<DataModel_, TableName>[\"convexDocument\"],\n tableName: TableName,\n tableSchema: TableInfo.TableSchema<\n DataModel.TableInfoWithName_<DataModel_, TableName>\n >,\n ): Effect.Effect<\n DataModel.TableInfoWithName_<DataModel_, TableName>[\"document\"],\n DocumentDecodeError\n > =>\n pipe(\n self,\n getDecoder(tableName, tableSchema),\n Effect.catchIf(ParseResult.isParseError, (parseError) =>\n Effect.gen(function* () {\n const formattedParseError =\n yield* ParseResult.TreeFormatter.formatError(parseError);\n\n return yield* new DocumentDecodeError({\n tableName,\n id: self._id,\n parseError: formattedParseError,\n });\n }),\n ),\n Effect.map(\n (decodedDoc) =>\n decodedDoc as DataModel.TableInfoWithName_<\n DataModel_,\n TableName\n >[\"document\"],\n ),\n ),\n);\n\ntype Encode = (doc: unknown) => Effect.Effect<unknown, ParseResult.ParseError>;\n\nconst encoderCache = new WeakMap<Schema.Schema.AnyNoContext, Encode>();\n\nconst getEncoder = (tableSchema: Schema.Schema.AnyNoContext): Encode =>\n encoderCache.get(tableSchema) ??\n (() => {\n const encoder = Schema.encode(tableSchema) as Encode;\n encoderCache.set(tableSchema, encoder);\n return encoder;\n })();\n\nexport const encode = Function.dual<\n <\n DataModel_ extends DataModel.AnyWithProps,\n TableName extends DataModel.TableNames<DataModel_>,\n >(\n tableName: TableName,\n tableSchema: TableInfo.TableSchema<\n DataModel.TableInfoWithName_<DataModel_, TableName>\n >,\n ) => (\n self: DataModel.TableInfoWithName_<DataModel_, TableName>[\"document\"],\n ) => Effect.Effect<\n DataModel.TableInfoWithName_<DataModel_, TableName>[\"encodedDocument\"],\n DocumentEncodeError\n >,\n <\n DataModel_ extends DataModel.AnyWithProps,\n TableName extends DataModel.TableNames<DataModel_>,\n >(\n self: DataModel.TableInfoWithName_<DataModel_, TableName>[\"document\"],\n tableName: TableName,\n tableSchema: TableInfo.TableSchema<\n DataModel.TableInfoWithName_<DataModel_, TableName>\n >,\n ) => Effect.Effect<\n DataModel.TableInfoWithName_<DataModel_, TableName>[\"encodedDocument\"],\n DocumentEncodeError\n >\n>(\n 3,\n <\n DataModel_ extends DataModel.AnyWithProps,\n TableName extends DataModel.TableNames<DataModel_>,\n >(\n self: DataModel.TableInfoWithName_<DataModel_, TableName>[\"document\"],\n tableName: TableName,\n tableSchema: TableInfo.TableSchema<\n DataModel.TableInfoWithName_<DataModel_, TableName>\n >,\n ): Effect.Effect<\n DataModel.TableInfoWithName_<DataModel_, TableName>[\"encodedDocument\"],\n DocumentEncodeError\n > =>\n pipe(\n self,\n getEncoder(tableSchema),\n Effect.catchIf(ParseResult.isParseError, (parseError) =>\n Effect.gen(function* () {\n const formattedParseError =\n yield* ParseResult.TreeFormatter.formatError(parseError);\n\n return yield* new DocumentEncodeError({\n tableName,\n id: self._id,\n parseError: formattedParseError,\n });\n }),\n ),\n Effect.map(\n (encodedDoc) =>\n encodedDoc as DataModel.TableInfoWithName_<\n DataModel_,\n TableName\n >[\"encodedDocument\"],\n ),\n ),\n);\n\nexport class DocumentDecodeError extends Schema.TaggedError<DocumentDecodeError>()(\n \"DocumentDecodeError\",\n {\n tableName: Schema.String,\n id: Schema.String,\n parseError: Schema.String,\n },\n) {\n override get message(): string {\n return documentErrorMessage({\n id: this.id,\n tableName: this.tableName,\n message: `could not be decoded:\\n\\n${this.parseError}`,\n });\n }\n}\n\nexport class DocumentEncodeError extends Schema.TaggedError<DocumentEncodeError>()(\n \"DocumentEncodeError\",\n {\n tableName: Schema.String,\n id: Schema.String,\n parseError: Schema.String,\n },\n) {\n override get message(): string {\n return documentErrorMessage({\n id: this.id,\n tableName: this.tableName,\n message: `could not be encoded:\\n\\n${this.parseError}`,\n });\n }\n}\n\nexport const documentErrorMessage = ({\n id,\n tableName,\n message,\n}: {\n id: string;\n tableName: string;\n message: string;\n}) => `Document with ID '${id}' in table '${tableName}' ${message}`;\n"],"mappings":";;;;;;;;;;;;;;;;AA0BA,MAAM,+BAAe,IAAI,SAGtB;AAEH,MAAM,cACJ,WACA,gBACW;CACX,MAAM,UACJ,aAAa,IAAI,YAAY,WACtB;EACL,MAAM,sBAAM,IAAI,KAAqB;AACrC,eAAa,IAAI,aAAa,IAAI;AAClC,SAAO;KACL;AAEN,QACE,QAAQ,IAAI,UAAU,WACf;EACL,MAAM,UAAU,OAAO,OACrB,aAAa,uBAAuB,WAAW,YAAY,CAC5D;AACD,UAAQ,IAAI,WAAW,QAAQ;AAC/B,SAAO;KACL;;AAIR,MAAa,SAAS,SAAS,KA6B7B,IAKE,MACA,WACA,gBAOA,KACE,MACA,WAAW,WAAW,YAAY,EAClC,OAAO,QAAQ,YAAY,eAAe,eACxC,OAAO,IAAI,aAAa;CACtB,MAAM,sBACJ,OAAO,YAAY,cAAc,YAAY,WAAW;AAE1D,QAAO,OAAO,IAAI,oBAAoB;EACpC;EACA,IAAI,KAAK;EACT,YAAY;EACb,CAAC;EACF,CACH,EACD,OAAO,KACJ,eACC,WAIH,CACF,CACJ;AAID,MAAM,+BAAe,IAAI,SAA6C;AAEtE,MAAM,cAAc,gBAClB,aAAa,IAAI,YAAY,WACtB;CACL,MAAM,UAAU,OAAO,OAAO,YAAY;AAC1C,cAAa,IAAI,aAAa,QAAQ;AACtC,QAAO;IACL;AAEN,MAAa,SAAS,SAAS,KA6B7B,IAKE,MACA,WACA,gBAOA,KACE,MACA,WAAW,YAAY,EACvB,OAAO,QAAQ,YAAY,eAAe,eACxC,OAAO,IAAI,aAAa;CACtB,MAAM,sBACJ,OAAO,YAAY,cAAc,YAAY,WAAW;AAE1D,QAAO,OAAO,IAAI,oBAAoB;EACpC;EACA,IAAI,KAAK;EACT,YAAY;EACb,CAAC;EACF,CACH,EACD,OAAO,KACJ,eACC,WAIH,CACF,CACJ;AAED,IAAa,sBAAb,cAAyC,OAAO,aAAkC,CAChF,uBACA;CACE,WAAW,OAAO;CAClB,IAAI,OAAO;CACX,YAAY,OAAO;CACpB,CACF,CAAC;CACA,IAAa,UAAkB;AAC7B,SAAO,qBAAqB;GAC1B,IAAI,KAAK;GACT,WAAW,KAAK;GAChB,SAAS,4BAA4B,KAAK;GAC3C,CAAC;;;AAIN,IAAa,sBAAb,cAAyC,OAAO,aAAkC,CAChF,uBACA;CACE,WAAW,OAAO;CAClB,IAAI,OAAO;CACX,YAAY,OAAO;CACpB,CACF,CAAC;CACA,IAAa,UAAkB;AAC7B,SAAO,qBAAqB;GAC1B,IAAI,KAAK;GACT,WAAW,KAAK;GAChB,SAAS,4BAA4B,KAAK;GAC3C,CAAC;;;AAIN,MAAa,wBAAwB,EACnC,IACA,WACA,cAKI,qBAAqB,GAAG,cAAc,UAAU,IAAI"}
|
package/dist/TableInfo.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { GenericDocument, GenericFieldPaths, GenericTableIndexes, GenericTableSearchIndexes, GenericTableVectorIndexes, IdField, SystemFields, SystemIndexes } from "convex/server";
|
|
2
2
|
import type { GenericValidator } from "convex/values";
|
|
3
3
|
import type { Schema, Types } from "effect";
|
|
4
4
|
import type * as Document_ from "./Document";
|
|
5
5
|
import type * as Table from "./Table";
|
|
6
6
|
export declare const TypeId: "@confect/server/TableInfo";
|
|
7
7
|
export type TypeId = typeof TypeId;
|
|
8
|
-
export type TableInfo<Table_ extends Table.AnyWithProps> = Table_ extends Table.Table<infer TableName, infer
|
|
8
|
+
export type TableInfo<Table_ extends Table.AnyWithProps> = Table_ extends Table.Table<infer TableName, infer TableSchema_, infer TableValidator, infer Indexes, infer SearchIndexes, infer VectorIndexes> ? {
|
|
9
9
|
readonly [TypeId]: TypeId;
|
|
10
|
-
readonly document:
|
|
11
|
-
readonly encodedDocument:
|
|
10
|
+
readonly document: WithSystemFields<TableName, Schema.Schema.Type<TableSchema_>>;
|
|
11
|
+
readonly encodedDocument: WithSystemFields<TableName, Schema.Schema.Encoded<TableSchema_>>;
|
|
12
12
|
readonly convexDocument: ExtractConvexDocument<TableName, TableValidator>;
|
|
13
13
|
readonly fieldPaths: keyof IdField<TableName> | ExtractFieldPaths<TableValidator>;
|
|
14
14
|
readonly indexes: Types.Simplify<Indexes & SystemIndexes>;
|
|
@@ -36,7 +36,8 @@ export type ConvexTableInfo<TableInfo_ extends AnyWithProps> = {
|
|
|
36
36
|
};
|
|
37
37
|
export type TableSchema<TableInfo_ extends AnyWithProps> = Schema.Schema<TableInfo_["document"], TableInfo_["encodedDocument"]>;
|
|
38
38
|
export type Document<TableInfo_ extends AnyWithProps> = TableInfo_["document"];
|
|
39
|
+
type WithSystemFields<TableName extends string, Doc> = Doc extends unknown ? IdField<TableName> & SystemFields & Doc : never;
|
|
39
40
|
type ExtractFieldPaths<T extends GenericValidator> = T["fieldPaths"] | keyof SystemFields;
|
|
40
|
-
type ExtractConvexDocument<TableName extends string, T extends GenericValidator> =
|
|
41
|
+
type ExtractConvexDocument<TableName extends string, T extends GenericValidator> = WithSystemFields<TableName, T["type"]> extends GenericDocument ? WithSystemFields<TableName, T["type"]> : never;
|
|
41
42
|
export {};
|
|
42
43
|
//# sourceMappingURL=TableInfo.d.ts.map
|
package/dist/TableInfo.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TableInfo.d.ts","sourceRoot":"","sources":["../src/TableInfo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,
|
|
1
|
+
{"version":3,"file":"TableInfo.d.ts","sourceRoot":"","sources":["../src/TableInfo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,iBAAiB,EACjB,mBAAmB,EACnB,yBAAyB,EACzB,yBAAyB,EACzB,OAAO,EACP,YAAY,EACZ,aAAa,EACd,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,KAAK,KAAK,SAAS,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,KAAK,KAAK,MAAM,SAAS,CAAC;AAEtC,MAAM,CAAC,OAAO,CAAC,MAAM,MAAM,EAAE,2BAA2B,CAAC;AACzD,MAAM,MAAM,MAAM,GAAG,OAAO,MAAM,CAAC;AAEnC,MAAM,MAAM,SAAS,CAAC,MAAM,SAAS,KAAK,CAAC,YAAY,IACrD,MAAM,SAAS,KAAK,CAAC,KAAK,CACxB,MAAM,SAAS,EACf,MAAM,YAAY,EAClB,MAAM,cAAc,EACpB,MAAM,OAAO,EACb,MAAM,aAAa,EACnB,MAAM,aAAa,CACpB,GACG;IACE,QAAQ,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CACjC,SAAS,EACT,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CACjC,CAAC;IACF,QAAQ,CAAC,eAAe,EAAE,gBAAgB,CACxC,SAAS,EACT,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,CACpC,CAAC;IACF,QAAQ,CAAC,cAAc,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tB,UAAU,CAAC,iBAAiB,CAAC,CAC9B,CAAC;AAEF,MAAM,MAAM,QAAQ,CAAC,UAAU,SAAS,YAAY,IAAI,UAAU,CAAC,UAAU,CAAC,CAAC;AAE/E,KAAK,gBAAgB,CAAC,SAAS,SAAS,MAAM,EAAE,GAAG,IAAI,GAAG,SAAS,OAAO,GACtE,OAAO,CAAC,SAAS,CAAC,GAAG,YAAY,GAAG,GAAG,GACvC,KAAK,CAAC;AAKV,KAAK,iBAAiB,CAAC,CAAC,SAAS,gBAAgB,IAC7C,CAAC,CAAC,YAAY,CAAC,GACf,MAAM,YAAY,CAAC;AAEvB,KAAK,qBAAqB,CACxB,SAAS,SAAS,MAAM,EACxB,CAAC,SAAS,gBAAgB,IAE1B,gBAAgB,CAAC,SAAS,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,SAAS,eAAe,GAC1D,gBAAgB,CAAC,SAAS,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,GACtC,KAAK,CAAC"}
|
package/dist/TableInfo.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TableInfo.js","names":[],"sources":["../src/TableInfo.ts"],"sourcesContent":["import type {\n
|
|
1
|
+
{"version":3,"file":"TableInfo.js","names":[],"sources":["../src/TableInfo.ts"],"sourcesContent":["import type {\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: WithSystemFields<\n TableName,\n Schema.Schema.Type<TableSchema_>\n >;\n readonly encodedDocument: WithSystemFields<\n TableName,\n Schema.Schema.Encoded<TableSchema_>\n >;\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\ntype WithSystemFields<TableName extends string, Doc> = Doc extends unknown\n ? IdField<TableName> & SystemFields & Doc\n : never;\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 WithSystemFields<TableName, T[\"type\"]> extends GenericDocument\n ? WithSystemFields<TableName, T[\"type\"]>\n : never;\n\n// End of vendored types from convex-js, partially modified.\n"],"mappings":""}
|