@confect/core 10.0.0-next.22 → 10.0.0-next.24
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 +24 -0
- package/dist/FunctionProvenance.d.ts +34 -25
- package/dist/FunctionProvenance.d.ts.map +1 -1
- package/dist/FunctionProvenance.js +13 -11
- package/dist/FunctionProvenance.js.map +1 -1
- package/dist/FunctionSpec.d.ts +12 -8
- package/dist/FunctionSpec.d.ts.map +1 -1
- package/dist/FunctionSpec.js.map +1 -1
- package/dist/GroupPath.d.ts +5 -6
- package/dist/GroupPath.d.ts.map +1 -1
- package/dist/GroupPath.js.map +1 -1
- package/dist/GroupSpec.d.ts +5 -2
- package/dist/GroupSpec.d.ts.map +1 -1
- package/dist/GroupSpec.js +2 -2
- package/dist/GroupSpec.js.map +1 -1
- package/dist/Identifier.d.ts +5 -4
- package/dist/Identifier.d.ts.map +1 -1
- package/dist/Identifier.js +5 -4
- package/dist/Identifier.js.map +1 -1
- package/dist/Lazy.d.ts +11 -12
- package/dist/Lazy.d.ts.map +1 -1
- package/dist/Lazy.js +11 -12
- package/dist/Lazy.js.map +1 -1
- package/dist/MiddlewareSpec.d.ts +27 -25
- package/dist/MiddlewareSpec.d.ts.map +1 -1
- package/dist/MiddlewareSpec.js +8 -4
- package/dist/MiddlewareSpec.js.map +1 -1
- package/dist/PaginationError.d.ts +9 -3
- package/dist/PaginationError.d.ts.map +1 -1
- package/dist/PaginationError.js +9 -3
- package/dist/PaginationError.js.map +1 -1
- package/dist/PaginationOptions.d.ts +2 -2
- package/dist/PaginationOptions.js +2 -2
- package/dist/PaginationOptions.js.map +1 -1
- package/dist/Ref.d.ts +38 -32
- package/dist/Ref.d.ts.map +1 -1
- package/dist/Ref.js +25 -25
- package/dist/Ref.js.map +1 -1
- package/dist/Refs.d.ts +1 -1
- package/dist/Refs.d.ts.map +1 -1
- package/dist/Refs.js +2 -1
- package/dist/Refs.js.map +1 -1
- package/dist/Spec.d.ts +14 -11
- package/dist/Spec.d.ts.map +1 -1
- package/dist/Spec.js +13 -8
- package/dist/Spec.js.map +1 -1
- package/dist/SystemFields.d.ts +14 -12
- package/dist/SystemFields.d.ts.map +1 -1
- package/dist/SystemFields.js +11 -9
- package/dist/SystemFields.js.map +1 -1
- package/dist/Table.d.ts +1 -0
- package/dist/Table.d.ts.map +1 -1
- package/dist/Table.js.map +1 -1
- package/dist/index.js +1 -1
- package/package.json +6 -5
- package/src/FunctionProvenance.ts +34 -25
- package/src/FunctionSpec.ts +12 -8
- package/src/GroupPath.ts +5 -6
- package/src/GroupSpec.ts +9 -5
- package/src/Identifier.ts +5 -4
- package/src/Lazy.ts +11 -12
- package/src/MiddlewareSpec.ts +27 -25
- package/src/PaginationError.ts +9 -3
- package/src/PaginationOptions.ts +2 -2
- package/src/Ref.ts +38 -32
- package/src/Refs.ts +2 -2
- package/src/Spec.ts +49 -38
- package/src/SystemFields.ts +22 -22
- package/src/Table.ts +1 -0
package/dist/SystemFields.d.ts
CHANGED
|
@@ -2,7 +2,8 @@ import type { IdField, SystemFields as NonIdSystemFields } from "convex/server";
|
|
|
2
2
|
import * as Schema from "effect/Schema";
|
|
3
3
|
import * as Struct from "effect/Struct";
|
|
4
4
|
/**
|
|
5
|
-
* Produces a schema for Convex system fields. In Confect, system fields include
|
|
5
|
+
* Produces a schema for Convex system fields. In Confect, system fields include
|
|
6
|
+
* `_id`.
|
|
6
7
|
*/
|
|
7
8
|
export declare const SystemFields: <TableName extends string>(tableName: TableName) => Schema.Struct<{
|
|
8
9
|
readonly _id: Schema.Codec<import("convex/values").GenericId<TableName>, import("convex/values").GenericId<TableName>, never, never>;
|
|
@@ -16,10 +17,11 @@ type SystemFieldsFor<TableName extends string> = ReturnType<typeof SystemFields<
|
|
|
16
17
|
/**
|
|
17
18
|
* Extend a table schema with Convex system fields.
|
|
18
19
|
*
|
|
19
|
-
* A plain `Struct` gains the fields via `Schema.fieldsAssign` and a `Union`
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* `Schema.decodeTo`/`Schema.encodeKeys`, a branded struct, a suspended
|
|
20
|
+
* A plain `Struct` gains the fields via `Schema.fieldsAssign` and a `Union` has
|
|
21
|
+
* them distributed across its members, preserving the schema's `Struct`/`Union`
|
|
22
|
+
* structure. Any other object-shaped schema—one built with
|
|
23
|
+
* `Schema.decodeTo`/`Schema.encodeKeys`, a branded struct, a suspended
|
|
24
|
+
* schema—is extended at the AST level: every object node in its encoding chain
|
|
23
25
|
* gains the system fields, and each transformation is wrapped so the fields
|
|
24
26
|
* bypass the user-defined getters. Schemas that do not resolve to an object
|
|
25
27
|
* shape at every step (such as `Schema.Class`, whose decoded values are class
|
|
@@ -31,9 +33,9 @@ type SystemFieldsFor<TableName extends string> = ReturnType<typeof SystemFields<
|
|
|
31
33
|
*/
|
|
32
34
|
export declare const extendWithSystemFields: <TableName extends string, TableSchema extends Schema.Codec<any, any>>(tableName: TableName, schema: TableSchema) => ExtendWithSystemFields<TableName, TableSchema>;
|
|
33
35
|
/**
|
|
34
|
-
* Applies the system fields to a single struct, mirroring
|
|
35
|
-
* Any other (already-extended or opaque) schema falls
|
|
36
|
-
* the system-field document shape.
|
|
36
|
+
* Applies the system fields to a single struct, mirroring
|
|
37
|
+
* `Schema.fieldsAssign`. Any other (already-extended or opaque) schema falls
|
|
38
|
+
* back to a `Codec` carrying the system-field document shape.
|
|
37
39
|
*/
|
|
38
40
|
type ApplySystemFields<TableName extends string, S> = S extends Schema.Struct<infer Fields extends Schema.Struct.Fields> ? Schema.Struct<Struct.Simplify<Struct.Assign<Fields, SystemFieldsFor<TableName>>>> : S extends Schema.Codec<infer Type, infer Encoded> ? Schema.Codec<WithSystemFields<TableName, Type>, WithSystemFields<TableName, Encoded>> : never;
|
|
39
41
|
/**
|
|
@@ -42,10 +44,10 @@ type ApplySystemFields<TableName extends string, S> = S extends Schema.Struct<in
|
|
|
42
44
|
* This mirrors the runtime {@link extendWithSystemFields}: a `Struct` gains the
|
|
43
45
|
* system fields directly (matching `Schema.fieldsAssign`), and a `Union` has
|
|
44
46
|
* them distributed across its members (matching
|
|
45
|
-
* `union.mapMembers(Tuple.map(Schema.fieldsAssign(...)))`). The
|
|
46
|
-
* structure is preserved rather than collapsed to a bare
|
|
47
|
-
* schema falls back to a `Codec` carrying the system-field
|
|
48
|
-
* matching the runtime's AST-level extension.
|
|
47
|
+
* `union.mapMembers(Tuple.map(Schema.fieldsAssign(...)))`). The
|
|
48
|
+
* `Struct`/`Union` structure is preserved rather than collapsed to a bare
|
|
49
|
+
* `Codec`; any other schema falls back to a `Codec` carrying the system-field
|
|
50
|
+
* document shape, matching the runtime's AST-level extension.
|
|
49
51
|
*/
|
|
50
52
|
export type ExtendWithSystemFields<TableName extends string, TableSchema extends Schema.Top> = TableSchema extends Schema.Union<infer Members extends ReadonlyArray<Schema.Top>> ? Schema.Union<Struct.Simplify<Readonly<{
|
|
51
53
|
[K in keyof Members]: ExtendWithSystemFields<TableName, Members[K]>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SystemFields.d.ts","sourceRoot":"","sources":["../src/SystemFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,IAAI,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAOhF,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAIxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAGxC
|
|
1
|
+
{"version":3,"file":"SystemFields.d.ts","sourceRoot":"","sources":["../src/SystemFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,IAAI,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAOhF,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAIxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAGxC;;;GAGG;AACH,eAAO,MAAM,YAAY,GAAI,SAAS,SAAS,MAAM,aAAa,SAAS;;;EAIvE,C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,CAAC,CAAC,CAAC;CACpE,CAAC,CACH,CACF,GACD,iBAAiB,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;AAEhD;;;;;;GAMG;AACH,MAAM,MAAM,gBAAgB,CAC1B,SAAS,SAAS,MAAM,EACxB,QAAQ,IACN,QAAQ,SAAS,OAAO,GACxB,OAAO,CAAC,SAAS,CAAC,GAAG,iBAAiB,GAAG,QAAQ,GACjD,KAAK,CAAC"}
|
package/dist/SystemFields.js
CHANGED
|
@@ -7,17 +7,18 @@ import * as SchemaAST from "effect/SchemaAST";
|
|
|
7
7
|
import * as Record from "effect/Record";
|
|
8
8
|
import * as Effect from "effect/Effect";
|
|
9
9
|
import { pipe } from "effect/Function";
|
|
10
|
+
import * as Struct from "effect/Struct";
|
|
10
11
|
import * as Array from "effect/Array";
|
|
11
12
|
import * as SchemaGetter from "effect/SchemaGetter";
|
|
12
13
|
import * as SchemaTransformation from "effect/SchemaTransformation";
|
|
13
|
-
import * as Struct from "effect/Struct";
|
|
14
14
|
//#region src/SystemFields.ts
|
|
15
15
|
var SystemFields_exports = /* @__PURE__ */ __exportAll({
|
|
16
16
|
SystemFields: () => SystemFields,
|
|
17
17
|
extendWithSystemFields: () => extendWithSystemFields
|
|
18
18
|
});
|
|
19
19
|
/**
|
|
20
|
-
* Produces a schema for Convex system fields. In Confect, system fields include
|
|
20
|
+
* Produces a schema for Convex system fields. In Confect, system fields include
|
|
21
|
+
* `_id`.
|
|
21
22
|
*/
|
|
22
23
|
const SystemFields = (tableName) => Schema.Struct({
|
|
23
24
|
_id: GenericId(tableName),
|
|
@@ -43,10 +44,10 @@ const splitSystemFields = (input) => {
|
|
|
43
44
|
* output. Transformations construct fresh objects, so without this the system
|
|
44
45
|
* fields would be dropped at every transformation step.
|
|
45
46
|
*/
|
|
46
|
-
const wrapGetter = (getter) =>
|
|
47
|
-
if (Option.isNone(input) || !Predicate.isObject(input.value)) return
|
|
47
|
+
const wrapGetter = (getter) => SchemaGetter.transformOptionalEffect((input, options) => {
|
|
48
|
+
if (Option.isNone(input) || !Predicate.isObject(input.value)) return SchemaGetter.run(getter, input, options);
|
|
48
49
|
const { system, rest } = splitSystemFields(input.value);
|
|
49
|
-
return
|
|
50
|
+
return SchemaGetter.run(getter, Option.some(rest), options).pipe(Effect.map(Option.map((output) => Predicate.isObject(output) ? Struct.assign(output, system) : output)));
|
|
50
51
|
});
|
|
51
52
|
const wrapTransformation = (transformation) => {
|
|
52
53
|
if (!SchemaTransformation.isTransformation(transformation)) throw new Error("Cannot extend a table schema that uses decoding/encoding middleware with system fields");
|
|
@@ -70,10 +71,11 @@ const makeExtendAst = (systemPropertySignatures) => {
|
|
|
70
71
|
/**
|
|
71
72
|
* Extend a table schema with Convex system fields.
|
|
72
73
|
*
|
|
73
|
-
* A plain `Struct` gains the fields via `Schema.fieldsAssign` and a `Union`
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
* `Schema.decodeTo`/`Schema.encodeKeys`, a branded struct, a suspended
|
|
74
|
+
* A plain `Struct` gains the fields via `Schema.fieldsAssign` and a `Union` has
|
|
75
|
+
* them distributed across its members, preserving the schema's `Struct`/`Union`
|
|
76
|
+
* structure. Any other object-shaped schema—one built with
|
|
77
|
+
* `Schema.decodeTo`/`Schema.encodeKeys`, a branded struct, a suspended
|
|
78
|
+
* schema—is extended at the AST level: every object node in its encoding chain
|
|
77
79
|
* gains the system fields, and each transformation is wrapped so the fields
|
|
78
80
|
* bypass the user-defined getters. Schemas that do not resolve to an object
|
|
79
81
|
* shape at every step (such as `Schema.Class`, whose decoded values are class
|
package/dist/SystemFields.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SystemFields.js","names":["GenericId.GenericId"],"sources":["../src/SystemFields.ts"],"sourcesContent":["import type { IdField, SystemFields as NonIdSystemFields } from \"convex/server\";\nimport { pipe } from \"effect/Function\";\nimport * as Array from \"effect/Array\";\nimport * as Effect from \"effect/Effect\";\nimport * as Option from \"effect/Option\";\nimport * as Predicate from \"effect/Predicate\";\nimport * as Record from \"effect/Record\";\nimport * as Schema from \"effect/Schema\";\nimport * as SchemaAST from \"effect/SchemaAST\";\nimport * as SchemaGetter from \"effect/SchemaGetter\";\nimport * as SchemaTransformation from \"effect/SchemaTransformation\";\nimport * as Struct from \"effect/Struct\";\nimport * as GenericId from \"./GenericId\";\n\n/**\n * Produces a schema for Convex system fields. In Confect, system fields include `_id`.\n */\nexport const SystemFields = <TableName extends string>(tableName: TableName) =>\n Schema.Struct({\n _id: GenericId.GenericId(tableName),\n _creationTime: Schema.Finite,\n });\n\n/**\n * The field map added to a table schema, derived from {@link SystemFields} so it\n * stays in lockstep with the runtime schema.\n */\ntype SystemFieldsFor<TableName extends string> = ReturnType<\n typeof SystemFields<TableName>\n>[\"fields\"];\n\n/**\n * The system field names, derived from {@link SystemFields} so they stay in\n * lockstep with the schema.\n */\nconst systemFieldNames: ReadonlyArray<string> = Record.keys(\n SystemFields(\"\").fields,\n);\n\nconst isSystemFieldKey = (key: string | symbol): key is string =>\n Predicate.isString(key) && Array.contains(systemFieldNames, key);\n\nconst splitSystemFields = (input: { [key: PropertyKey]: unknown }) => {\n const keys = Reflect.ownKeys(input);\n const pick = (pickedKeys: ReadonlyArray<string | symbol>) =>\n Record.fromEntries(\n Array.map(pickedKeys, (key) => [key, input[key]] as const),\n );\n return {\n system: pick(Array.filter(keys, isSystemFieldKey)),\n rest: pick(Array.filter(keys, Predicate.not(isSystemFieldKey))),\n };\n};\n\n/**\n * Wraps a transformation getter so the system fields bypass it: they are split\n * off the input before the user-defined getter runs and merged back into its\n * output. Transformations construct fresh objects, so without this the system\n * fields would be dropped at every transformation step.\n */\nconst wrapGetter = <R>(\n getter: SchemaGetter.Getter<any, any, R>,\n): SchemaGetter.Getter<any, any, R> =>\n new SchemaGetter.Getter((input, options) => {\n if (Option.isNone(input) || !Predicate.isObject(input.value)) {\n return getter.run(input, options);\n }\n const { system, rest } = splitSystemFields(input.value);\n return getter\n .run(Option.some(rest), options)\n .pipe(\n Effect.map(\n Option.map((output) =>\n Predicate.isObject(output) ? Struct.assign(output, system) : output,\n ),\n ),\n );\n });\n\nconst wrapTransformation = (\n transformation: SchemaAST.Link[\"transformation\"],\n): SchemaTransformation.Transformation<any, any, any, any> => {\n if (!SchemaTransformation.isTransformation(transformation)) {\n throw new Error(\n \"Cannot extend a table schema that uses decoding/encoding middleware with system fields\",\n );\n }\n return new SchemaTransformation.Transformation(\n wrapGetter(transformation.decode),\n wrapGetter(transformation.encode),\n );\n};\n\n/**\n * Builds an AST walker that adds the given system-field property signatures to\n * every object node of a schema's AST—including each step of its encoding\n * chain—wrapping transformations so the fields survive them.\n */\nconst makeExtendAst = (\n systemPropertySignatures: ReadonlyArray<SchemaAST.PropertySignature>,\n) => {\n const extendEncoding = (encoding: SchemaAST.Encoding): SchemaAST.Encoding =>\n Array.map(\n encoding,\n (link) =>\n new SchemaAST.Link(\n extendAst(link.to),\n wrapTransformation(link.transformation),\n ),\n );\n\n const extendAst = (ast: SchemaAST.AST): SchemaAST.AST => {\n if (SchemaAST.isUnion(ast)) {\n return new SchemaAST.Union(\n Array.map(ast.types, extendAst),\n ast.options,\n ast.annotations,\n ast.checks,\n ast.encoding === undefined ? undefined : extendEncoding(ast.encoding),\n ast.context,\n ast.encodingChecks,\n );\n }\n if (SchemaAST.isSuspend(ast)) {\n return new SchemaAST.Suspend(\n () => extendAst(ast.thunk()),\n ast.annotations,\n undefined,\n ast.encoding === undefined ? undefined : extendEncoding(ast.encoding),\n ast.context,\n );\n }\n if (SchemaAST.isObjects(ast)) {\n return new SchemaAST.Objects(\n Array.appendAll(ast.propertySignatures, systemPropertySignatures),\n ast.indexSignatures,\n ast.annotations,\n ast.checks,\n ast.encoding === undefined ? undefined : extendEncoding(ast.encoding),\n ast.context,\n ast.encodingChecks,\n );\n }\n throw new Error(\n ast._tag === \"Declaration\"\n ? \"Cannot extend a `Declaration` schema (such as a `Schema.Class`) with system fields: its decoded values are constructed instances, which cannot gain extra fields. Use a plain `Schema.Struct`, or transform to one with `Schema.decodeTo`.\"\n : `Cannot extend a \\`${ast._tag}\\` schema node with system fields: a table schema must resolve to an object shape at every step of its encoding.`,\n );\n };\n\n return extendAst;\n};\n\n/**\n * Extend a table schema with Convex system fields.\n *\n * A plain `Struct` gains the fields via `Schema.fieldsAssign` and a `Union`\n * has them distributed across its members, preserving the schema's\n * `Struct`/`Union` structure. Any other object-shaped schema—one built with\n * `Schema.decodeTo`/`Schema.encodeKeys`, a branded struct, a suspended schema—is extended at the AST level: every object node in its encoding chain\n * gains the system fields, and each transformation is wrapped so the fields\n * bypass the user-defined getters. Schemas that do not resolve to an object\n * shape at every step (such as `Schema.Class`, whose decoded values are class\n * instances) are rejected with a descriptive error.\n *\n * Note that struct-level checks on an extended schema observe the value with\n * the system fields attached, and encoding an extended schema emits the system\n * fields alongside the table fields.\n */\nexport const extendWithSystemFields = <\n TableName extends string,\n TableSchema extends Schema.Codec<any, any>,\n>(\n tableName: TableName,\n schema: TableSchema,\n): ExtendWithSystemFields<TableName, TableSchema> => {\n const system = SystemFields(tableName).fields;\n\n const extendAst = makeExtendAst(\n pipe(\n system,\n Record.toEntries,\n Array.map(\n ([name, field]) => new SchemaAST.PropertySignature(name, field.ast),\n ),\n ),\n );\n\n const extend = (s: Schema.Top): Schema.Top => {\n if (\n s.ast.encoding === undefined &&\n SchemaAST.isUnion(s.ast) &&\n Array.isArray((s as { readonly members?: unknown }).members)\n ) {\n return Schema.Union(\n Array.map(\n (s as Schema.Union<ReadonlyArray<Schema.Top>>).members,\n extend,\n ),\n );\n }\n if (\n s.ast.encoding === undefined &&\n SchemaAST.isObjects(s.ast) &&\n typeof (s as { readonly mapFields?: unknown }).mapFields === \"function\"\n ) {\n return Schema.fieldsAssign(system)(\n s as Schema.Struct<Schema.Struct.Fields>,\n );\n }\n return Schema.make(extendAst(s.ast));\n };\n\n return extend(schema) as unknown as ExtendWithSystemFields<\n TableName,\n TableSchema\n >;\n};\n\n/**\n * Applies the system fields to a single struct, mirroring `Schema.fieldsAssign`.\n * Any other (already-extended or opaque) schema falls back to a `Codec` carrying\n * the system-field document shape.\n */\ntype ApplySystemFields<TableName extends string, S> =\n S extends Schema.Struct<infer Fields extends Schema.Struct.Fields>\n ? Schema.Struct<\n Struct.Simplify<Struct.Assign<Fields, SystemFieldsFor<TableName>>>\n >\n : S extends Schema.Codec<infer Type, infer Encoded>\n ? Schema.Codec<\n WithSystemFields<TableName, Type>,\n WithSystemFields<TableName, Encoded>\n >\n : never;\n\n/**\n * Extend a table schema with Convex system fields at the type level.\n *\n * This mirrors the runtime {@link extendWithSystemFields}: a `Struct` gains the\n * system fields directly (matching `Schema.fieldsAssign`), and a `Union` has\n * them distributed across its members (matching\n * `union.mapMembers(Tuple.map(Schema.fieldsAssign(...)))`). The `Struct`/`Union`\n * structure is preserved rather than collapsed to a bare `Codec`; any other\n * schema falls back to a `Codec` carrying the system-field document shape,\n * matching the runtime's AST-level extension.\n */\nexport type ExtendWithSystemFields<\n TableName extends string,\n TableSchema extends Schema.Top,\n> =\n TableSchema extends Schema.Union<\n infer Members extends ReadonlyArray<Schema.Top>\n >\n ? Schema.Union<\n Struct.Simplify<\n Readonly<{\n [K in keyof Members]: ExtendWithSystemFields<TableName, Members[K]>;\n }>\n >\n >\n : ApplySystemFields<TableName, TableSchema>;\n\n/**\n * The decoded/encoded document shape: a table's fields plus Convex's system\n * fields. Deliberately a bare intersection (no `Expand`/`Simplify`)—flattening\n * it with a homomorphic mapped type collapses to `{ [x: string]: any }` when\n * `Document` is still an unresolved generic, which breaks structural\n * comparability in the database reader/writer plumbing.\n */\nexport type WithSystemFields<\n TableName extends string,\n Document,\n> = Document extends unknown\n ? IdField<TableName> & NonIdSystemFields & Document\n : never;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAiBA,MAAa,gBAA0C,cACrD,OAAO,OAAO;CACZ,KAAKA,UAAoB,SAAS;CAClC,eAAe,OAAO;AACxB,CAAC;;;;;AAcH,MAAM,mBAA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AEF,OAAO,OAAO,KAAK,UAAU,EAAE,GAAG,CAAC;CACrC;CAEA,OAAO,OAAO,MAAM;AAItB"}
|
|
1
|
+
{"version":3,"file":"SystemFields.js","names":["GenericId.GenericId"],"sources":["../src/SystemFields.ts"],"sourcesContent":["import type { IdField, SystemFields as NonIdSystemFields } from \"convex/server\";\nimport { pipe } from \"effect/Function\";\nimport * as Array from \"effect/Array\";\nimport * as Effect from \"effect/Effect\";\nimport * as Option from \"effect/Option\";\nimport * as Predicate from \"effect/Predicate\";\nimport * as Record from \"effect/Record\";\nimport * as Schema from \"effect/Schema\";\nimport * as SchemaAST from \"effect/SchemaAST\";\nimport * as SchemaGetter from \"effect/SchemaGetter\";\nimport * as SchemaTransformation from \"effect/SchemaTransformation\";\nimport * as Struct from \"effect/Struct\";\nimport * as GenericId from \"./GenericId\";\n\n/**\n * Produces a schema for Convex system fields. In Confect, system fields include\n * `_id`.\n */\nexport const SystemFields = <TableName extends string>(tableName: TableName) =>\n Schema.Struct({\n _id: GenericId.GenericId(tableName),\n _creationTime: Schema.Finite,\n });\n\n/**\n * The field map added to a table schema, derived from {@link SystemFields} so it\n * stays in lockstep with the runtime schema.\n */\ntype SystemFieldsFor<TableName extends string> = ReturnType<\n typeof SystemFields<TableName>\n>[\"fields\"];\n\n/**\n * The system field names, derived from {@link SystemFields} so they stay in\n * lockstep with the schema.\n */\nconst systemFieldNames: ReadonlyArray<string> = Record.keys(\n SystemFields(\"\").fields,\n);\n\nconst isSystemFieldKey = (key: string | symbol): key is string =>\n Predicate.isString(key) && Array.contains(systemFieldNames, key);\n\nconst splitSystemFields = (input: { [key: PropertyKey]: unknown }) => {\n const keys = Reflect.ownKeys(input);\n const pick = (pickedKeys: ReadonlyArray<string | symbol>) =>\n Record.fromEntries(\n Array.map(pickedKeys, (key) => [key, input[key]] as const),\n );\n return {\n system: pick(Array.filter(keys, isSystemFieldKey)),\n rest: pick(Array.filter(keys, Predicate.not(isSystemFieldKey))),\n };\n};\n\n/**\n * Wraps a transformation getter so the system fields bypass it: they are split\n * off the input before the user-defined getter runs and merged back into its\n * output. Transformations construct fresh objects, so without this the system\n * fields would be dropped at every transformation step.\n */\nconst wrapGetter = <R>(\n getter: SchemaGetter.Getter<any, any, R>,\n): SchemaGetter.Getter<any, any, R> =>\n SchemaGetter.transformOptionalEffect((input, options) => {\n if (Option.isNone(input) || !Predicate.isObject(input.value)) {\n return SchemaGetter.run(getter, input, options);\n }\n const { system, rest } = splitSystemFields(input.value);\n return SchemaGetter.run(getter, Option.some(rest), options).pipe(\n Effect.map(\n Option.map((output) =>\n Predicate.isObject(output) ? Struct.assign(output, system) : output,\n ),\n ),\n );\n });\n\nconst wrapTransformation = (\n transformation: SchemaAST.Link[\"transformation\"],\n): SchemaTransformation.Transformation<any, any, any, any> => {\n if (!SchemaTransformation.isTransformation(transformation)) {\n throw new Error(\n \"Cannot extend a table schema that uses decoding/encoding middleware with system fields\",\n );\n }\n return new SchemaTransformation.Transformation(\n wrapGetter(transformation.decode),\n wrapGetter(transformation.encode),\n );\n};\n\n/**\n * Builds an AST walker that adds the given system-field property signatures to\n * every object node of a schema's AST—including each step of its encoding\n * chain—wrapping transformations so the fields survive them.\n */\nconst makeExtendAst = (\n systemPropertySignatures: ReadonlyArray<SchemaAST.PropertySignature>,\n) => {\n const extendEncoding = (encoding: SchemaAST.Encoding): SchemaAST.Encoding =>\n Array.map(\n encoding,\n (link) =>\n new SchemaAST.Link(\n extendAst(link.to),\n wrapTransformation(link.transformation),\n ),\n );\n\n const extendAst = (ast: SchemaAST.AST): SchemaAST.AST => {\n if (SchemaAST.isUnion(ast)) {\n return new SchemaAST.Union(\n Array.map(ast.types, extendAst),\n ast.options,\n ast.annotations,\n ast.checks,\n ast.encoding === undefined ? undefined : extendEncoding(ast.encoding),\n ast.context,\n ast.encodingChecks,\n );\n }\n if (SchemaAST.isSuspend(ast)) {\n return new SchemaAST.Suspend(\n () => extendAst(ast.thunk()),\n ast.annotations,\n undefined,\n ast.encoding === undefined ? undefined : extendEncoding(ast.encoding),\n ast.context,\n );\n }\n if (SchemaAST.isObjects(ast)) {\n return new SchemaAST.Objects(\n Array.appendAll(ast.propertySignatures, systemPropertySignatures),\n ast.indexSignatures,\n ast.annotations,\n ast.checks,\n ast.encoding === undefined ? undefined : extendEncoding(ast.encoding),\n ast.context,\n ast.encodingChecks,\n );\n }\n throw new Error(\n ast._tag === \"Declaration\"\n ? \"Cannot extend a `Declaration` schema (such as a `Schema.Class`) with system fields: its decoded values are constructed instances, which cannot gain extra fields. Use a plain `Schema.Struct`, or transform to one with `Schema.decodeTo`.\"\n : `Cannot extend a \\`${ast._tag}\\` schema node with system fields: a table schema must resolve to an object shape at every step of its encoding.`,\n );\n };\n\n return extendAst;\n};\n\n/**\n * Extend a table schema with Convex system fields.\n *\n * A plain `Struct` gains the fields via `Schema.fieldsAssign` and a `Union` has\n * them distributed across its members, preserving the schema's `Struct`/`Union`\n * structure. Any other object-shaped schema—one built with\n * `Schema.decodeTo`/`Schema.encodeKeys`, a branded struct, a suspended\n * schema—is extended at the AST level: every object node in its encoding chain\n * gains the system fields, and each transformation is wrapped so the fields\n * bypass the user-defined getters. Schemas that do not resolve to an object\n * shape at every step (such as `Schema.Class`, whose decoded values are class\n * instances) are rejected with a descriptive error.\n *\n * Note that struct-level checks on an extended schema observe the value with\n * the system fields attached, and encoding an extended schema emits the system\n * fields alongside the table fields.\n */\nexport const extendWithSystemFields = <\n TableName extends string,\n TableSchema extends Schema.Codec<any, any>,\n>(\n tableName: TableName,\n schema: TableSchema,\n): ExtendWithSystemFields<TableName, TableSchema> => {\n const system = SystemFields(tableName).fields;\n\n const extendAst = makeExtendAst(\n pipe(\n system,\n Record.toEntries,\n Array.map(\n ([name, field]) => new SchemaAST.PropertySignature(name, field.ast),\n ),\n ),\n );\n\n const extend = (s: Schema.Top): Schema.Top => {\n if (\n s.ast.encoding === undefined &&\n SchemaAST.isUnion(s.ast) &&\n Array.isArray((s as { readonly members?: unknown }).members)\n ) {\n return Schema.Union(\n Array.map(\n (s as Schema.Union<ReadonlyArray<Schema.Top>>).members,\n extend,\n ),\n );\n }\n if (\n s.ast.encoding === undefined &&\n SchemaAST.isObjects(s.ast) &&\n typeof (s as { readonly mapFields?: unknown }).mapFields === \"function\"\n ) {\n return Schema.fieldsAssign(system)(\n s as Schema.Struct<Schema.Struct.Fields>,\n );\n }\n return Schema.make(extendAst(s.ast));\n };\n\n return extend(schema) as unknown as ExtendWithSystemFields<\n TableName,\n TableSchema\n >;\n};\n\n/**\n * Applies the system fields to a single struct, mirroring\n * `Schema.fieldsAssign`. Any other (already-extended or opaque) schema falls\n * back to a `Codec` carrying the system-field document shape.\n */\ntype ApplySystemFields<TableName extends string, S> =\n S extends Schema.Struct<infer Fields extends Schema.Struct.Fields>\n ? Schema.Struct<\n Struct.Simplify<Struct.Assign<Fields, SystemFieldsFor<TableName>>>\n >\n : S extends Schema.Codec<infer Type, infer Encoded>\n ? Schema.Codec<\n WithSystemFields<TableName, Type>,\n WithSystemFields<TableName, Encoded>\n >\n : never;\n\n/**\n * Extend a table schema with Convex system fields at the type level.\n *\n * This mirrors the runtime {@link extendWithSystemFields}: a `Struct` gains the\n * system fields directly (matching `Schema.fieldsAssign`), and a `Union` has\n * them distributed across its members (matching\n * `union.mapMembers(Tuple.map(Schema.fieldsAssign(...)))`). The\n * `Struct`/`Union` structure is preserved rather than collapsed to a bare\n * `Codec`; any other schema falls back to a `Codec` carrying the system-field\n * document shape, matching the runtime's AST-level extension.\n */\nexport type ExtendWithSystemFields<\n TableName extends string,\n TableSchema extends Schema.Top,\n> =\n TableSchema extends Schema.Union<\n infer Members extends ReadonlyArray<Schema.Top>\n >\n ? Schema.Union<\n Struct.Simplify<\n Readonly<{\n [K in keyof Members]: ExtendWithSystemFields<TableName, Members[K]>;\n }>\n >\n >\n : ApplySystemFields<TableName, TableSchema>;\n\n/**\n * The decoded/encoded document shape: a table's fields plus Convex's system\n * fields. Deliberately a bare intersection (no `Expand`/`Simplify`)—flattening\n * it with a homomorphic mapped type collapses to `{ [x: string]: any }` when\n * `Document` is still an unresolved generic, which breaks structural\n * comparability in the database reader/writer plumbing.\n */\nexport type WithSystemFields<\n TableName extends string,\n Document,\n> = Document extends unknown\n ? IdField<TableName> & NonIdSystemFields & Document\n : never;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAkBA,MAAa,gBAA0C,cACrD,OAAO,OAAO;CACZ,KAAKA,UAAoB,SAAS;CAClC,eAAe,OAAO;AACxB,CAAC;;;;;AAcH,MAAM,mBAA0C,OAAO,KACrD,aAAa,EAAE,CAAC,CAAC,MACnB;AAEA,MAAM,oBAAoB,QACxB,UAAU,SAAS,GAAG,KAAK,MAAM,SAAS,kBAAkB,GAAG;AAEjE,MAAM,qBAAqB,UAA2C;CACpE,MAAM,OAAO,QAAQ,QAAQ,KAAK;CAClC,MAAM,QAAQ,eACZ,OAAO,YACL,MAAM,IAAI,aAAa,QAAQ,CAAC,KAAK,MAAM,IAAI,CAAU,CAC3D;CACF,OAAO;EACL,QAAQ,KAAK,MAAM,OAAO,MAAM,gBAAgB,CAAC;EACjD,MAAM,KAAK,MAAM,OAAO,MAAM,UAAU,IAAI,gBAAgB,CAAC,CAAC;CAChE;AACF;;;;;;;AAQA,MAAM,cACJ,WAEA,aAAa,yBAAyB,OAAO,YAAY;CACvD,IAAI,OAAO,OAAO,KAAK,KAAK,CAAC,UAAU,SAAS,MAAM,KAAK,GACzD,OAAO,aAAa,IAAI,QAAQ,OAAO,OAAO;CAEhD,MAAM,EAAE,QAAQ,SAAS,kBAAkB,MAAM,KAAK;CACtD,OAAO,aAAa,IAAI,QAAQ,OAAO,KAAK,IAAI,GAAG,OAAO,CAAC,CAAC,KAC1D,OAAO,IACL,OAAO,KAAK,WACV,UAAU,SAAS,MAAM,IAAI,OAAO,OAAO,QAAQ,MAAM,IAAI,MAC/D,CACF,CACF;AACF,CAAC;AAEH,MAAM,sBACJ,mBAC4D;CAC5D,IAAI,CAAC,qBAAqB,iBAAiB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ACpE,CACF,CACF;CAEA,MAAM,UAAU,MAA8B;EAC5C,IACE,EAAE,IAAI,aAAa,KAAA,KACnB,UAAU,QAAQ,EAAE,GAAG,KACvB,MAAM,QAAS,EAAqC,OAAO,GAE3D,OAAO,OAAO,MACZ,MAAM,IACH,EAA8C,SAC/C,MACF,CACF;EAEF,IACE,EAAE,IAAI,aAAa,KAAA,KACnB,UAAU,UAAU,EAAE,GAAG,KACzB,OAAQ,EAAuC,cAAc,YAE7D,OAAO,OAAO,aAAa,MAAM,CAAC,CAChC,CACF;EAEF,OAAO,OAAO,KAAK,UAAU,EAAE,GAAG,CAAC;CACrC;CAEA,OAAO,OAAO,MAAM;AAItB"}
|
package/dist/Table.d.ts
CHANGED
|
@@ -67,6 +67,7 @@ export declare const make: <const TableSchema_ extends Schema.Codec<any, any>>(l
|
|
|
67
67
|
* Extract all of the index field paths within a Convex `Validator`.
|
|
68
68
|
*
|
|
69
69
|
* This is used when declaring table indexes.
|
|
70
|
+
*
|
|
70
71
|
* @public
|
|
71
72
|
*/
|
|
72
73
|
type ExtractFieldPaths<T extends Validator<any, any, any>> = T["fieldPaths"] | keyof ConvexSystemFields;
|
package/dist/Table.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Table.d.ts","sourceRoot":"","sources":["../src/Table.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,YAAY,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,KAAK,EACV,YAAY,IAAI,kBAAkB,EAClC,MAAM,EACN,mBAAmB,EACnB,yBAAyB,EACzB,yBAAyB,EACzB,oBAAoB,EACpB,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAEjE,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAC;AAE7C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G;AACH,KAAK,iBAAiB,CAAC,CAAC,SAAS,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,IAIvD,CAAC,CAAC,YAAY,CAAC,GAAG,MAAM,kBAAkB,CAAC"}
|
package/dist/Table.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Table.js","names":["SystemFields.extendWithSystemFields"],"sources":["../src/Table.ts"],"sourcesContent":["import * as Lazy from \"./Lazy\";\nimport * as SystemFields from \"./SystemFields\";\nimport type { TableSchemaToTableValidator } from \"./SchemaToValidator\";\nimport type {\n SystemFields as ConvexSystemFields,\n Expand,\n GenericTableIndexes,\n GenericTableSearchIndexes,\n GenericTableVectorIndexes,\n IndexTiebreakerField,\n SearchIndexConfig,\n VectorIndexConfig,\n} from \"convex/server\";\nimport type { GenericValidator, Validator } from \"convex/values\";\nimport * as Predicate from \"effect/Predicate\";\nimport type * as Schema from \"effect/Schema\";\n\nexport const TypeId = \"~@confect/core/Table\";\nexport type TypeId = typeof TypeId;\n\n// -----------------------------------------------------------------------------\n// Predicates\n// -----------------------------------------------------------------------------\n//\n// Both bound `Table`s and `UnnamedTable` callables share the same `[TypeId]`\n// brand. They disambiguate by whether a `tableName` property is set: bound\n// tables have one, unnamed callables do not.\n//\n// The discriminator is `tableName` (not `name`) so it does not collide with\n// the built-in `Function.prototype.name` that every JS function carries.\n\nexport const isTable = (u: unknown): u is Any =>\n Predicate.hasProperty(u, TypeId) && Predicate.hasProperty(u, \"tableName\");\n\nexport const isUnnamedTable = (u: unknown): u is UnnamedAny =>\n Predicate.hasProperty(u, TypeId) && !Predicate.hasProperty(u, \"tableName\");\n\n// -----------------------------------------------------------------------------\n// Bound Table\n// -----------------------------------------------------------------------------\n//\n// A bound `Table` is the client-safe document schema: `Fields`, `Doc`, and\n// the index metadata records. The Convex deploy `tableDefinition` (which\n// value-imports `convex/server`) is produced separately by\n// `@confect/server/Table.tableDefinition`.\n\nexport interface Table<\n Name_ extends string,\n TableSchema_ extends Schema.Codec<any, any>,\n TableValidator_ extends GenericValidator =\n TableSchemaToTableValidator<TableSchema_>,\n Indexes_ extends GenericTableIndexes = {},\n SearchIndexes_ extends GenericTableSearchIndexes = {},\n VectorIndexes_ extends GenericTableVectorIndexes = {},\n> {\n readonly [TypeId]: TypeId;\n readonly tableName: Name_;\n readonly Fields: TableSchema_;\n readonly Doc: SystemFields.ExtendWithSystemFields<Name_, TableSchema_>;\n readonly indexes: Indexes_;\n readonly searchIndexes: SearchIndexes_;\n readonly vectorIndexes: VectorIndexes_;\n readonly \"~TableValidator\": TableValidator_;\n}\n\nexport interface Any {\n readonly [TypeId]: TypeId;\n readonly tableName: string;\n}\n\nexport type AnyWithProps = Table<\n any,\n Schema.Codec<any, any>,\n GenericValidator,\n GenericTableIndexes,\n GenericTableSearchIndexes,\n GenericTableVectorIndexes\n>;\n\n// -----------------------------------------------------------------------------\n// UnnamedTable (callable)\n// -----------------------------------------------------------------------------\n//\n// `Table.make(lazyFields)` returns an `UnnamedTable`: a callable that\n// produces a fully bound `Table` when invoked with a name. Chaining methods\n// (`.index`, `.searchIndex`, `.vectorIndex`) live here and return new\n// `UnnamedTable`s, accumulating plain index metadata records. The\n// user-supplied `lazyFields` callback is just carried through until first\n// access of `Fields`/`Doc` on a bound table. The codegen pipeline emits a\n// wrapper file per user-authored table that simply invokes the unnamed\n// callable with the filename basename.\n\nexport interface UnnamedTable<\n TableSchema_ extends Schema.Codec<any, any>,\n TableValidator_ extends GenericValidator =\n TableSchemaToTableValidator<TableSchema_>,\n Indexes_ extends GenericTableIndexes = {},\n SearchIndexes_ extends GenericTableSearchIndexes = {},\n VectorIndexes_ extends GenericTableVectorIndexes = {},\n> {\n <const Name_ extends string>(\n tableName: Name_,\n ): Table<\n Name_,\n TableSchema_,\n TableValidator_,\n Indexes_,\n SearchIndexes_,\n VectorIndexes_\n >;\n\n readonly [TypeId]: TypeId;\n readonly indexes: Indexes_;\n readonly searchIndexes: SearchIndexes_;\n readonly vectorIndexes: VectorIndexes_;\n readonly \"~TableValidator\": TableValidator_;\n\n index<\n IndexName extends string,\n FirstFieldPath extends ExtractFieldPaths<TableValidator_>,\n RestFieldPaths extends ExtractFieldPaths<TableValidator_>[],\n >(\n name: IndexName,\n fields: [FirstFieldPath, ...RestFieldPaths],\n ): UnnamedTable<\n TableSchema_,\n TableValidator_,\n Expand<\n Indexes_ &\n Record<\n IndexName,\n [FirstFieldPath, ...RestFieldPaths, IndexTiebreakerField]\n >\n >,\n SearchIndexes_,\n VectorIndexes_\n >;\n\n searchIndex<\n IndexName extends string,\n SearchField extends ExtractFieldPaths<TableValidator_>,\n FilterFields extends ExtractFieldPaths<TableValidator_> = never,\n >(\n name: IndexName,\n indexConfig: Expand<SearchIndexConfig<SearchField, FilterFields>>,\n ): UnnamedTable<\n TableSchema_,\n TableValidator_,\n Indexes_,\n Expand<\n SearchIndexes_ &\n Record<\n IndexName,\n {\n searchField: SearchField;\n filterFields: FilterFields;\n }\n >\n >,\n VectorIndexes_\n >;\n\n vectorIndex<\n IndexName extends string,\n VectorField extends ExtractFieldPaths<TableValidator_>,\n FilterFields extends ExtractFieldPaths<TableValidator_> = never,\n >(\n name: IndexName,\n indexConfig: Expand<VectorIndexConfig<VectorField, FilterFields>>,\n ): UnnamedTable<\n TableSchema_,\n TableValidator_,\n Indexes_,\n SearchIndexes_,\n Expand<\n VectorIndexes_ &\n Record<\n IndexName,\n {\n vectorField: VectorField;\n dimensions: number;\n filterFields: FilterFields;\n }\n >\n >\n >;\n}\n\nexport interface UnnamedAny {\n readonly [TypeId]: TypeId;\n}\n\nexport type UnnamedAnyWithProps = UnnamedTable<\n Schema.Codec<any, any>,\n GenericValidator,\n GenericTableIndexes,\n GenericTableSearchIndexes,\n GenericTableVectorIndexes\n>;\n\n// -----------------------------------------------------------------------------\n// Type extractors\n// -----------------------------------------------------------------------------\n\nexport type Name<TableDef extends AnyWithProps> = TableDef[\"tableName\"] &\n string;\n\nexport type TableSchema<TableDef extends AnyWithProps> = TableDef[\"Fields\"];\n\nexport type TableValidator<TableDef extends AnyWithProps> =\n TableDef[\"~TableValidator\"];\n\nexport type Indexes<TableDef extends AnyWithProps> = TableDef[\"indexes\"];\n\nexport type SearchIndexes<TableDef extends AnyWithProps> =\n TableDef[\"searchIndexes\"];\n\nexport type VectorIndexes<TableDef extends AnyWithProps> =\n TableDef[\"vectorIndexes\"];\n\nexport type Doc<TableDef extends AnyWithProps> = TableDef[\"Doc\"];\n\nexport type Fields<TableDef extends AnyWithProps> = TableDef[\"Fields\"];\n\nexport type WithName<\n TableDef extends AnyWithProps,\n Name_ extends string,\n> = TableDef extends { readonly tableName: Name_ } ? TableDef : never;\n\nexport type TablesRecord<Tables extends AnyWithProps> = {\n readonly [TableName_ in Name<Tables>]: WithName<Tables, TableName_>;\n};\n\n// -----------------------------------------------------------------------------\n// Construction\n// -----------------------------------------------------------------------------\n//\n// `make` only stores the user-supplied `lazyFields` callback alongside any\n// chained index metadata. Neither `Fields` nor `Doc` is constructed until\n// first access on a bound `Table`. Each chain step is O(1) (plain object\n// spread of the metadata records) and never invokes the callback. Binding\n// via `unnamed(tableName)` installs lazy memoised getters for `Fields` and\n// `Doc` via `Lazy.defineProperty`, so the first access materialises the\n// value and replaces the getter with a plain data property—second-and-\n// subsequent accesses are observably indistinguishable from a plain\n// property and avoid all function-call overhead.\n\ninterface UnnamedState<\n TableSchema_ extends Schema.Codec<any, any>,\n Indexes_ extends GenericTableIndexes,\n SearchIndexes_ extends GenericTableSearchIndexes,\n VectorIndexes_ extends GenericTableVectorIndexes,\n> {\n readonly lazyFields: () => TableSchema_;\n readonly indexes: Indexes_;\n readonly searchIndexes: SearchIndexes_;\n readonly vectorIndexes: VectorIndexes_;\n}\n\nconst makeBound = <\n Name_ extends string,\n TableSchema_ extends Schema.Codec<any, any>,\n TableValidator_ extends Validator<any, any, any>,\n Indexes_ extends GenericTableIndexes,\n SearchIndexes_ extends GenericTableSearchIndexes,\n VectorIndexes_ extends GenericTableVectorIndexes,\n>(\n tableName: Name_,\n state: UnnamedState<TableSchema_, Indexes_, SearchIndexes_, VectorIndexes_>,\n): Table<\n Name_,\n TableSchema_,\n TableValidator_,\n Indexes_,\n SearchIndexes_,\n VectorIndexes_\n> => {\n const bound = {\n [TypeId]: TypeId as TypeId,\n tableName,\n indexes: state.indexes,\n searchIndexes: state.searchIndexes,\n vectorIndexes: state.vectorIndexes,\n } as Table<\n Name_,\n TableSchema_,\n TableValidator_,\n Indexes_,\n SearchIndexes_,\n VectorIndexes_\n >;\n\n Lazy.defineProperty(bound, \"Fields\", () => state.lazyFields());\n\n Lazy.defineProperty(bound, \"Doc\", () =>\n SystemFields.extendWithSystemFields(\n tableName,\n (bound as { Fields: TableSchema_ }).Fields,\n ),\n );\n\n return bound;\n};\n\nconst makeUnnamed = <\n TableSchema_ extends Schema.Codec<any, any>,\n TableValidator_ extends Validator<any, any, any>,\n Indexes_ extends GenericTableIndexes,\n SearchIndexes_ extends GenericTableSearchIndexes,\n VectorIndexes_ extends GenericTableVectorIndexes,\n>(\n state: UnnamedState<TableSchema_, Indexes_, SearchIndexes_, VectorIndexes_>,\n): UnnamedTable<\n TableSchema_,\n TableValidator_,\n Indexes_,\n SearchIndexes_,\n VectorIndexes_\n> => {\n type UnnamedTable_ = UnnamedTable<\n TableSchema_,\n TableValidator_,\n Indexes_,\n SearchIndexes_,\n VectorIndexes_\n >;\n\n type UnnamedTableFunction<FunctionName extends keyof UnnamedTable_> =\n UnnamedTable_[FunctionName];\n\n const bind = <const Name_ extends string>(\n tableName: Name_,\n ): Table<\n Name_,\n TableSchema_,\n TableValidator_,\n Indexes_,\n SearchIndexes_,\n VectorIndexes_\n > =>\n makeBound<\n Name_,\n TableSchema_,\n TableValidator_,\n Indexes_,\n SearchIndexes_,\n VectorIndexes_\n >(tableName, state);\n\n const index: UnnamedTableFunction<\"index\"> = (name, fields) =>\n makeUnnamed({\n lazyFields: state.lazyFields,\n indexes: {\n ...state.indexes,\n [name]: fields,\n } as any,\n searchIndexes: state.searchIndexes,\n vectorIndexes: state.vectorIndexes,\n });\n\n const searchIndex: UnnamedTableFunction<\"searchIndex\"> = (\n name,\n indexConfig,\n ) =>\n makeUnnamed({\n lazyFields: state.lazyFields,\n indexes: state.indexes,\n searchIndexes: {\n ...state.searchIndexes,\n [name]: indexConfig,\n } as any,\n vectorIndexes: state.vectorIndexes,\n });\n\n const vectorIndex: UnnamedTableFunction<\"vectorIndex\"> = (\n name,\n indexConfig,\n ) =>\n makeUnnamed({\n lazyFields: state.lazyFields,\n indexes: state.indexes,\n searchIndexes: state.searchIndexes,\n vectorIndexes: {\n ...state.vectorIndexes,\n [name]: indexConfig,\n } as any,\n });\n\n return Object.assign(bind, {\n [TypeId]: TypeId as TypeId,\n indexes: state.indexes,\n searchIndexes: state.searchIndexes,\n vectorIndexes: state.vectorIndexes,\n index,\n searchIndex,\n vectorIndex,\n }) as UnnamedTable_;\n};\n\nexport const make = <const TableSchema_ extends Schema.Codec<any, any>>(\n lazyFields: () => TableSchema_,\n): UnnamedTable<TableSchema_, TableSchemaToTableValidator<TableSchema_>> => {\n type TableValidator_ = TableSchemaToTableValidator<TableSchema_>;\n type UnnamedTable_ = UnnamedTable<TableSchema_, TableValidator_>;\n\n return makeUnnamed<TableSchema_, TableValidator_, {}, {}, {}>({\n lazyFields,\n indexes: {},\n searchIndexes: {},\n vectorIndexes: {},\n }) as UnnamedTable_;\n};\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 Convex `Validator`.\n *\n * This is used when declaring table indexes.\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":";;;;;;;;;;;AAiBA,MAAa,SAAS;AActB,MAAa,WAAW,MACtB,UAAU,YAAY,GAAA,sBAAS,KAAK,UAAU,YAAY,GAAG,WAAW;AAE1E,MAAa,kBAAkB,MAC7B,UAAU,YAAY,GAAA,sBAAS,KAAK,CAAC,UAAU,YAAY,GAAG,WAAW;AAgO3E,MAAM,aAQJ,WACA,UAQG;CACH,MAAM,QAAQ;GACX,SAAS;EACV;EACA,SAAS,MAAM;EACf,eAAe,MAAM;EACrB,eAAe,MAAM;CACvB;CASA,eAAoB,OAAO,gBAAgB,MAAM,WAAW,CAAC;CAE7D,eAAoB,OAAO,aACzBA,uBACE,WACC,MAAmC,MACtC,CACF;CAEA,OAAO;AACT;AAEA,MAAM,eAOJ,UAOG;CAYH,MAAM,QACJ,cASA,UAOE,WAAW,KAAK;CAEpB,MAAM,SAAwC,MAAM,WAClD,YAAY;EACV,YAAY,MAAM;EAClB,SAAS;GACP,GAAG,MAAM;IACR,OAAO;EACV;EACA,eAAe,MAAM;EACrB,eAAe,MAAM;CACvB,CAAC;CAEH,MAAM,eACJ,MACA,gBAEA,YAAY;EACV,YAAY,MAAM;EAClB,SAAS,MAAM;EACf,eAAe;GACb,GAAG,MAAM;IACR,OAAO;EACV;EACA,eAAe,MAAM;CACvB,CAAC;CAEH,MAAM,eACJ,MACA,gBAEA,YAAY;EACV,YAAY,MAAM;EAClB,SAAS,MAAM;EACf,eAAe,MAAM;EACrB,eAAe;GACb,GAAG,MAAM;IACR,OAAO;EACV;CACF,CAAC;CAEH,OAAO,OAAO,OAAO,MAAM;GACxB,SAAS;EACV,SAAS,MAAM;EACf,eAAe,MAAM;EACrB,eAAe,MAAM;EACrB;EACA;EACA;CACF,CAAC;AACH;AAEA,MAAa,QACX,eAC0E;CAI1E,OAAO,YAAuD;EAC5D;EACA,SAAS,CAAC;EACV,eAAe,CAAC;EAChB,eAAe,CAAC;CAClB,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"Table.js","names":["SystemFields.extendWithSystemFields"],"sources":["../src/Table.ts"],"sourcesContent":["import * as Lazy from \"./Lazy\";\nimport * as SystemFields from \"./SystemFields\";\nimport type { TableSchemaToTableValidator } from \"./SchemaToValidator\";\nimport type {\n SystemFields as ConvexSystemFields,\n Expand,\n GenericTableIndexes,\n GenericTableSearchIndexes,\n GenericTableVectorIndexes,\n IndexTiebreakerField,\n SearchIndexConfig,\n VectorIndexConfig,\n} from \"convex/server\";\nimport type { GenericValidator, Validator } from \"convex/values\";\nimport * as Predicate from \"effect/Predicate\";\nimport type * as Schema from \"effect/Schema\";\n\nexport const TypeId = \"~@confect/core/Table\";\nexport type TypeId = typeof TypeId;\n\n// -----------------------------------------------------------------------------\n// Predicates\n// -----------------------------------------------------------------------------\n//\n// Both bound `Table`s and `UnnamedTable` callables share the same `[TypeId]`\n// brand. They disambiguate by whether a `tableName` property is set: bound\n// tables have one, unnamed callables do not.\n//\n// The discriminator is `tableName` (not `name`) so it does not collide with\n// the built-in `Function.prototype.name` that every JS function carries.\n\nexport const isTable = (u: unknown): u is Any =>\n Predicate.hasProperty(u, TypeId) && Predicate.hasProperty(u, \"tableName\");\n\nexport const isUnnamedTable = (u: unknown): u is UnnamedAny =>\n Predicate.hasProperty(u, TypeId) && !Predicate.hasProperty(u, \"tableName\");\n\n// -----------------------------------------------------------------------------\n// Bound Table\n// -----------------------------------------------------------------------------\n//\n// A bound `Table` is the client-safe document schema: `Fields`, `Doc`, and\n// the index metadata records. The Convex deploy `tableDefinition` (which\n// value-imports `convex/server`) is produced separately by\n// `@confect/server/Table.tableDefinition`.\n\nexport interface Table<\n Name_ extends string,\n TableSchema_ extends Schema.Codec<any, any>,\n TableValidator_ extends GenericValidator =\n TableSchemaToTableValidator<TableSchema_>,\n Indexes_ extends GenericTableIndexes = {},\n SearchIndexes_ extends GenericTableSearchIndexes = {},\n VectorIndexes_ extends GenericTableVectorIndexes = {},\n> {\n readonly [TypeId]: TypeId;\n readonly tableName: Name_;\n readonly Fields: TableSchema_;\n readonly Doc: SystemFields.ExtendWithSystemFields<Name_, TableSchema_>;\n readonly indexes: Indexes_;\n readonly searchIndexes: SearchIndexes_;\n readonly vectorIndexes: VectorIndexes_;\n readonly \"~TableValidator\": TableValidator_;\n}\n\nexport interface Any {\n readonly [TypeId]: TypeId;\n readonly tableName: string;\n}\n\nexport type AnyWithProps = Table<\n any,\n Schema.Codec<any, any>,\n GenericValidator,\n GenericTableIndexes,\n GenericTableSearchIndexes,\n GenericTableVectorIndexes\n>;\n\n// -----------------------------------------------------------------------------\n// UnnamedTable (callable)\n// -----------------------------------------------------------------------------\n//\n// `Table.make(lazyFields)` returns an `UnnamedTable`: a callable that\n// produces a fully bound `Table` when invoked with a name. Chaining methods\n// (`.index`, `.searchIndex`, `.vectorIndex`) live here and return new\n// `UnnamedTable`s, accumulating plain index metadata records. The\n// user-supplied `lazyFields` callback is just carried through until first\n// access of `Fields`/`Doc` on a bound table. The codegen pipeline emits a\n// wrapper file per user-authored table that simply invokes the unnamed\n// callable with the filename basename.\n\nexport interface UnnamedTable<\n TableSchema_ extends Schema.Codec<any, any>,\n TableValidator_ extends GenericValidator =\n TableSchemaToTableValidator<TableSchema_>,\n Indexes_ extends GenericTableIndexes = {},\n SearchIndexes_ extends GenericTableSearchIndexes = {},\n VectorIndexes_ extends GenericTableVectorIndexes = {},\n> {\n <const Name_ extends string>(\n tableName: Name_,\n ): Table<\n Name_,\n TableSchema_,\n TableValidator_,\n Indexes_,\n SearchIndexes_,\n VectorIndexes_\n >;\n\n readonly [TypeId]: TypeId;\n readonly indexes: Indexes_;\n readonly searchIndexes: SearchIndexes_;\n readonly vectorIndexes: VectorIndexes_;\n readonly \"~TableValidator\": TableValidator_;\n\n index<\n IndexName extends string,\n FirstFieldPath extends ExtractFieldPaths<TableValidator_>,\n RestFieldPaths extends ExtractFieldPaths<TableValidator_>[],\n >(\n name: IndexName,\n fields: [FirstFieldPath, ...RestFieldPaths],\n ): UnnamedTable<\n TableSchema_,\n TableValidator_,\n Expand<\n Indexes_ &\n Record<\n IndexName,\n [FirstFieldPath, ...RestFieldPaths, IndexTiebreakerField]\n >\n >,\n SearchIndexes_,\n VectorIndexes_\n >;\n\n searchIndex<\n IndexName extends string,\n SearchField extends ExtractFieldPaths<TableValidator_>,\n FilterFields extends ExtractFieldPaths<TableValidator_> = never,\n >(\n name: IndexName,\n indexConfig: Expand<SearchIndexConfig<SearchField, FilterFields>>,\n ): UnnamedTable<\n TableSchema_,\n TableValidator_,\n Indexes_,\n Expand<\n SearchIndexes_ &\n Record<\n IndexName,\n {\n searchField: SearchField;\n filterFields: FilterFields;\n }\n >\n >,\n VectorIndexes_\n >;\n\n vectorIndex<\n IndexName extends string,\n VectorField extends ExtractFieldPaths<TableValidator_>,\n FilterFields extends ExtractFieldPaths<TableValidator_> = never,\n >(\n name: IndexName,\n indexConfig: Expand<VectorIndexConfig<VectorField, FilterFields>>,\n ): UnnamedTable<\n TableSchema_,\n TableValidator_,\n Indexes_,\n SearchIndexes_,\n Expand<\n VectorIndexes_ &\n Record<\n IndexName,\n {\n vectorField: VectorField;\n dimensions: number;\n filterFields: FilterFields;\n }\n >\n >\n >;\n}\n\nexport interface UnnamedAny {\n readonly [TypeId]: TypeId;\n}\n\nexport type UnnamedAnyWithProps = UnnamedTable<\n Schema.Codec<any, any>,\n GenericValidator,\n GenericTableIndexes,\n GenericTableSearchIndexes,\n GenericTableVectorIndexes\n>;\n\n// -----------------------------------------------------------------------------\n// Type extractors\n// -----------------------------------------------------------------------------\n\nexport type Name<TableDef extends AnyWithProps> = TableDef[\"tableName\"] &\n string;\n\nexport type TableSchema<TableDef extends AnyWithProps> = TableDef[\"Fields\"];\n\nexport type TableValidator<TableDef extends AnyWithProps> =\n TableDef[\"~TableValidator\"];\n\nexport type Indexes<TableDef extends AnyWithProps> = TableDef[\"indexes\"];\n\nexport type SearchIndexes<TableDef extends AnyWithProps> =\n TableDef[\"searchIndexes\"];\n\nexport type VectorIndexes<TableDef extends AnyWithProps> =\n TableDef[\"vectorIndexes\"];\n\nexport type Doc<TableDef extends AnyWithProps> = TableDef[\"Doc\"];\n\nexport type Fields<TableDef extends AnyWithProps> = TableDef[\"Fields\"];\n\nexport type WithName<\n TableDef extends AnyWithProps,\n Name_ extends string,\n> = TableDef extends { readonly tableName: Name_ } ? TableDef : never;\n\nexport type TablesRecord<Tables extends AnyWithProps> = {\n readonly [TableName_ in Name<Tables>]: WithName<Tables, TableName_>;\n};\n\n// -----------------------------------------------------------------------------\n// Construction\n// -----------------------------------------------------------------------------\n//\n// `make` only stores the user-supplied `lazyFields` callback alongside any\n// chained index metadata. Neither `Fields` nor `Doc` is constructed until\n// first access on a bound `Table`. Each chain step is O(1) (plain object\n// spread of the metadata records) and never invokes the callback. Binding\n// via `unnamed(tableName)` installs lazy memoised getters for `Fields` and\n// `Doc` via `Lazy.defineProperty`, so the first access materialises the\n// value and replaces the getter with a plain data property—second-and-\n// subsequent accesses are observably indistinguishable from a plain\n// property and avoid all function-call overhead.\n\ninterface UnnamedState<\n TableSchema_ extends Schema.Codec<any, any>,\n Indexes_ extends GenericTableIndexes,\n SearchIndexes_ extends GenericTableSearchIndexes,\n VectorIndexes_ extends GenericTableVectorIndexes,\n> {\n readonly lazyFields: () => TableSchema_;\n readonly indexes: Indexes_;\n readonly searchIndexes: SearchIndexes_;\n readonly vectorIndexes: VectorIndexes_;\n}\n\nconst makeBound = <\n Name_ extends string,\n TableSchema_ extends Schema.Codec<any, any>,\n TableValidator_ extends Validator<any, any, any>,\n Indexes_ extends GenericTableIndexes,\n SearchIndexes_ extends GenericTableSearchIndexes,\n VectorIndexes_ extends GenericTableVectorIndexes,\n>(\n tableName: Name_,\n state: UnnamedState<TableSchema_, Indexes_, SearchIndexes_, VectorIndexes_>,\n): Table<\n Name_,\n TableSchema_,\n TableValidator_,\n Indexes_,\n SearchIndexes_,\n VectorIndexes_\n> => {\n const bound = {\n [TypeId]: TypeId as TypeId,\n tableName,\n indexes: state.indexes,\n searchIndexes: state.searchIndexes,\n vectorIndexes: state.vectorIndexes,\n } as Table<\n Name_,\n TableSchema_,\n TableValidator_,\n Indexes_,\n SearchIndexes_,\n VectorIndexes_\n >;\n\n Lazy.defineProperty(bound, \"Fields\", () => state.lazyFields());\n\n Lazy.defineProperty(bound, \"Doc\", () =>\n SystemFields.extendWithSystemFields(\n tableName,\n (bound as { Fields: TableSchema_ }).Fields,\n ),\n );\n\n return bound;\n};\n\nconst makeUnnamed = <\n TableSchema_ extends Schema.Codec<any, any>,\n TableValidator_ extends Validator<any, any, any>,\n Indexes_ extends GenericTableIndexes,\n SearchIndexes_ extends GenericTableSearchIndexes,\n VectorIndexes_ extends GenericTableVectorIndexes,\n>(\n state: UnnamedState<TableSchema_, Indexes_, SearchIndexes_, VectorIndexes_>,\n): UnnamedTable<\n TableSchema_,\n TableValidator_,\n Indexes_,\n SearchIndexes_,\n VectorIndexes_\n> => {\n type UnnamedTable_ = UnnamedTable<\n TableSchema_,\n TableValidator_,\n Indexes_,\n SearchIndexes_,\n VectorIndexes_\n >;\n\n type UnnamedTableFunction<FunctionName extends keyof UnnamedTable_> =\n UnnamedTable_[FunctionName];\n\n const bind = <const Name_ extends string>(\n tableName: Name_,\n ): Table<\n Name_,\n TableSchema_,\n TableValidator_,\n Indexes_,\n SearchIndexes_,\n VectorIndexes_\n > =>\n makeBound<\n Name_,\n TableSchema_,\n TableValidator_,\n Indexes_,\n SearchIndexes_,\n VectorIndexes_\n >(tableName, state);\n\n const index: UnnamedTableFunction<\"index\"> = (name, fields) =>\n makeUnnamed({\n lazyFields: state.lazyFields,\n indexes: {\n ...state.indexes,\n [name]: fields,\n } as any,\n searchIndexes: state.searchIndexes,\n vectorIndexes: state.vectorIndexes,\n });\n\n const searchIndex: UnnamedTableFunction<\"searchIndex\"> = (\n name,\n indexConfig,\n ) =>\n makeUnnamed({\n lazyFields: state.lazyFields,\n indexes: state.indexes,\n searchIndexes: {\n ...state.searchIndexes,\n [name]: indexConfig,\n } as any,\n vectorIndexes: state.vectorIndexes,\n });\n\n const vectorIndex: UnnamedTableFunction<\"vectorIndex\"> = (\n name,\n indexConfig,\n ) =>\n makeUnnamed({\n lazyFields: state.lazyFields,\n indexes: state.indexes,\n searchIndexes: state.searchIndexes,\n vectorIndexes: {\n ...state.vectorIndexes,\n [name]: indexConfig,\n } as any,\n });\n\n return Object.assign(bind, {\n [TypeId]: TypeId as TypeId,\n indexes: state.indexes,\n searchIndexes: state.searchIndexes,\n vectorIndexes: state.vectorIndexes,\n index,\n searchIndex,\n vectorIndex,\n }) as UnnamedTable_;\n};\n\nexport const make = <const TableSchema_ extends Schema.Codec<any, any>>(\n lazyFields: () => TableSchema_,\n): UnnamedTable<TableSchema_, TableSchemaToTableValidator<TableSchema_>> => {\n type TableValidator_ = TableSchemaToTableValidator<TableSchema_>;\n type UnnamedTable_ = UnnamedTable<TableSchema_, TableValidator_>;\n\n return makeUnnamed<TableSchema_, TableValidator_, {}, {}, {}>({\n lazyFields,\n indexes: {},\n searchIndexes: {},\n vectorIndexes: {},\n }) as UnnamedTable_;\n};\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 Convex `Validator`.\n *\n * This is used when declaring table indexes.\n *\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":";;;;;;;;;;;AAiBA,MAAa,SAAS;AActB,MAAa,WAAW,MACtB,UAAU,YAAY,GAAA,sBAAS,KAAK,UAAU,YAAY,GAAG,WAAW;AAE1E,MAAa,kBAAkB,MAC7B,UAAU,YAAY,GAAA,sBAAS,KAAK,CAAC,UAAU,YAAY,GAAG,WAAW;AAgO3E,MAAM,aAQJ,WACA,UAQG;CACH,MAAM,QAAQ;GACX,SAAS;EACV;EACA,SAAS,MAAM;EACf,eAAe,MAAM;EACrB,eAAe,MAAM;CACvB;CASA,eAAoB,OAAO,gBAAgB,MAAM,WAAW,CAAC;CAE7D,eAAoB,OAAO,aACzBA,uBACE,WACC,MAAmC,MACtC,CACF;CAEA,OAAO;AACT;AAEA,MAAM,eAOJ,UAOG;CAYH,MAAM,QACJ,cASA,UAOE,WAAW,KAAK;CAEpB,MAAM,SAAwC,MAAM,WAClD,YAAY;EACV,YAAY,MAAM;EAClB,SAAS;GACP,GAAG,MAAM;IACR,OAAO;EACV;EACA,eAAe,MAAM;EACrB,eAAe,MAAM;CACvB,CAAC;CAEH,MAAM,eACJ,MACA,gBAEA,YAAY;EACV,YAAY,MAAM;EAClB,SAAS,MAAM;EACf,eAAe;GACb,GAAG,MAAM;IACR,OAAO;EACV;EACA,eAAe,MAAM;CACvB,CAAC;CAEH,MAAM,eACJ,MACA,gBAEA,YAAY;EACV,YAAY,MAAM;EAClB,SAAS,MAAM;EACf,eAAe,MAAM;EACrB,eAAe;GACb,GAAG,MAAM;IACR,OAAO;EACV;CACF,CAAC;CAEH,OAAO,OAAO,OAAO,MAAM;GACxB,SAAS;EACV,SAAS,MAAM;EACf,eAAe,MAAM;EACrB,eAAe,MAAM;EACrB;EACA;EACA;CACF,CAAC;AACH;AAEA,MAAa,QACX,eAC0E;CAI1E,OAAO,YAAuD;EAC5D;EACA,SAAS,CAAC;EACV,eAAe,CAAC;EAChB,eAAe,CAAC;CAClB,CAAC;AACH"}
|
package/dist/index.js
CHANGED
|
@@ -12,9 +12,9 @@ import { GroupSpec_exports } from "./GroupSpec.js";
|
|
|
12
12
|
import { MiddlewareSpec_exports } from "./MiddlewareSpec.js";
|
|
13
13
|
import { PaginationError_exports } from "./PaginationError.js";
|
|
14
14
|
import { Ref_exports } from "./Ref.js";
|
|
15
|
+
import { Spec_exports } from "./Spec.js";
|
|
15
16
|
import { Refs_exports } from "./Refs.js";
|
|
16
17
|
import { SchemaToValidator_exports } from "./SchemaToValidator.js";
|
|
17
|
-
import { Spec_exports } from "./Spec.js";
|
|
18
18
|
import { SystemFields_exports } from "./SystemFields.js";
|
|
19
19
|
import { Table_exports } from "./Table.js";
|
|
20
20
|
import { Types_exports } from "./Types.js";
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@confect/core",
|
|
3
3
|
"description": "Shared specs and schemas used by all Confect packages",
|
|
4
|
-
"version": "10.0.0-next.
|
|
4
|
+
"version": "10.0.0-next.24",
|
|
5
5
|
"author": "RJ Dellecese",
|
|
6
6
|
"bugs": {
|
|
7
7
|
"url": "https://github.com/rjdellecese/confect/issues"
|
|
8
8
|
},
|
|
9
9
|
"devDependencies": {
|
|
10
|
-
"@effect/vitest": "4.0.0-rc.
|
|
10
|
+
"@effect/vitest": "4.0.0-rc.117",
|
|
11
11
|
"@types/node": "24.13.3",
|
|
12
12
|
"confect-bench-harness": "0.0.0",
|
|
13
|
-
"effect": "4.0.0-rc.
|
|
13
|
+
"effect": "4.0.0-rc.117",
|
|
14
14
|
"tsdown": "0.23.0",
|
|
15
15
|
"tsx": "4.23.13",
|
|
16
16
|
"typescript": "7.0.2",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"module": "./dist/index.js",
|
|
52
52
|
"peerDependencies": {
|
|
53
53
|
"convex": "^1.32.0",
|
|
54
|
-
"effect": "^4.0.0-rc.
|
|
54
|
+
"effect": "^4.0.0-rc.117"
|
|
55
55
|
},
|
|
56
56
|
"repository": {
|
|
57
57
|
"type": "git",
|
|
@@ -65,6 +65,7 @@
|
|
|
65
65
|
"clean": "shx rm -rf dist coverage node_modules",
|
|
66
66
|
"dev": "tsdown --watch --no-clean --config-loader unrun",
|
|
67
67
|
"test": "vitest run",
|
|
68
|
-
"typecheck": "tsc -b tsconfig.src.json"
|
|
68
|
+
"typecheck": "tsc -b tsconfig.src.json",
|
|
69
|
+
"typecheck:inexact": "tsc --noEmit --project tsconfig.json --exactOptionalPropertyTypes false"
|
|
69
70
|
}
|
|
70
71
|
}
|
|
@@ -27,7 +27,9 @@ export interface ArgsSchema<
|
|
|
27
27
|
readonly fields: ArgsFields_;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
/**
|
|
30
|
+
/**
|
|
31
|
+
* Erased structural view used after the exact field map is no longer needed.
|
|
32
|
+
*/
|
|
31
33
|
export type AnyArgsSchema = ArgsSchema<ArgsFields>;
|
|
32
34
|
|
|
33
35
|
export type FunctionProvenance = Data.TaggedEnum<{
|
|
@@ -44,12 +46,11 @@ export type FunctionProvenance = Data.TaggedEnum<{
|
|
|
44
46
|
}>;
|
|
45
47
|
|
|
46
48
|
/**
|
|
47
|
-
* The declaration shape of a Confect function—orthogonal to both the
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* composed.
|
|
49
|
+
* The declaration shape of a Confect function—orthogonal to both the provenance
|
|
50
|
+
* origin (Confect vs Convex) and the function type (query/mutation/action). A
|
|
51
|
+
* `Standard` function declares its args fields and returns schema directly; a
|
|
52
|
+
* `Paginated` function declares user-args fields and an item schema from which
|
|
53
|
+
* the Convex-facing `args`/`returns` are composed.
|
|
53
54
|
*/
|
|
54
55
|
export type ConfectKind = Standard | Paginated;
|
|
55
56
|
|
|
@@ -62,11 +63,17 @@ export interface Paginated<
|
|
|
62
63
|
Item extends Schema.Codec<any, any> = Schema.Codec<any, any>,
|
|
63
64
|
> {
|
|
64
65
|
readonly _tag: "Paginated";
|
|
65
|
-
/**
|
|
66
|
+
/**
|
|
67
|
+
* User-declared args—no `paginationOpts`.
|
|
68
|
+
*/
|
|
66
69
|
readonly userArgs: ArgsSchema<UserArgsFields_>;
|
|
67
|
-
/**
|
|
70
|
+
/**
|
|
71
|
+
* Page element schema.
|
|
72
|
+
*/
|
|
68
73
|
readonly item: Item;
|
|
69
|
-
/**
|
|
74
|
+
/**
|
|
75
|
+
* Mutable array of items—the page decode target.
|
|
76
|
+
*/
|
|
70
77
|
readonly page: Schema.Codec<any, any>;
|
|
71
78
|
}
|
|
72
79
|
|
|
@@ -105,18 +112,20 @@ export const FunctionProvenance = Data.taggedEnum<FunctionProvenance>();
|
|
|
105
112
|
const Standard: Standard = { _tag: "Standard" };
|
|
106
113
|
|
|
107
114
|
/**
|
|
108
|
-
* Build a `Confect` provenance from lazy args-fields and schema thunks.
|
|
109
|
-
* `
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
* assembled `_generated/spec.ts` cheap—no
|
|
113
|
-
*
|
|
115
|
+
* Build a `Confect` provenance from lazy args-fields and schema thunks. `args`,
|
|
116
|
+
* `returns`, and `error` are exposed as sync lazy memoised getters (via
|
|
117
|
+
* {@link Lazy.defineProperty}) that only evaluate their thunk on first access,
|
|
118
|
+
* mirroring how `Table` defers `Fields`/`Doc`. This keeps importing the
|
|
119
|
+
* assembled `_generated/spec.ts` cheap—no
|
|
120
|
+
* `Schema.Struct(...)`/`Schema.Array(...)` work runs at module load; it is
|
|
121
|
+
* deferred to the first invocation that actually compiles validators or runs a
|
|
122
|
+
* codec.
|
|
114
123
|
*
|
|
115
124
|
* The object is built by hand rather than through `FunctionProvenance.Confect`
|
|
116
125
|
* because the `Data` constructor copies its input with `Object.assign`, which
|
|
117
|
-
* would force the getters at construction time and defeat the laziness.
|
|
118
|
-
*
|
|
119
|
-
*
|
|
126
|
+
* would force the getters at construction time and defeat the laziness. `error`
|
|
127
|
+
* is only installed when an `errorThunk` is provided, so its absence is
|
|
128
|
+
* observable via `"error" in provenance` without forcing anything; nothing
|
|
120
129
|
* relies on `Data`'s structural `Equal`/`Hash` for provenance values.
|
|
121
130
|
*/
|
|
122
131
|
export const Confect = <
|
|
@@ -140,8 +149,8 @@ export const Confect = <
|
|
|
140
149
|
};
|
|
141
150
|
|
|
142
151
|
/**
|
|
143
|
-
* The composed args schema of a paginated query: the user-declared fields
|
|
144
|
-
*
|
|
152
|
+
* The composed args schema of a paginated query: the user-declared fields plus
|
|
153
|
+
* the `paginationOpts` field managed by Convex's pagination protocol.
|
|
145
154
|
*
|
|
146
155
|
* The fields-first representation keeps the user-declared map available for
|
|
147
156
|
* type-level composition without reconstructing it from an erased schema.
|
|
@@ -156,8 +165,8 @@ export type PaginatedArgs<UserArgsFields extends ArgsFields> = Schema.Struct<
|
|
|
156
165
|
>;
|
|
157
166
|
|
|
158
167
|
/**
|
|
159
|
-
* The composed returns schema of a paginated query: a `PaginationResult` of
|
|
160
|
-
*
|
|
168
|
+
* The composed returns schema of a paginated query: a `PaginationResult` of the
|
|
169
|
+
* item schema. Same deferred-conditional device as {@link PaginatedArgs}.
|
|
161
170
|
*/
|
|
162
171
|
export type PaginatedReturns<Item extends Schema.Codec<any, any>> =
|
|
163
172
|
PaginationResult.PaginationResult<Item> extends infer ComposedReturns extends
|
|
@@ -182,8 +191,8 @@ export interface AnyConfectPaginated extends AnyConfect {
|
|
|
182
191
|
|
|
183
192
|
/**
|
|
184
193
|
* Build the provenance of a paginated query from lazy schema thunks, with the
|
|
185
|
-
* same laziness contract as {@link Confect}. The user-facing schemas live on
|
|
186
|
-
*
|
|
194
|
+
* same laziness contract as {@link Confect}. The user-facing schemas live on the
|
|
195
|
+
* `Paginated` kind (`kind.userArgs`, `kind.item`, `kind.page`)—the kind
|
|
187
196
|
* container is built eagerly (it is cheap) while the schemas inside it stay
|
|
188
197
|
* lazy. The composed Convex-facing `args`/`returns` are derived lazily from
|
|
189
198
|
* them: `args` spreads the user fields plus `paginationOpts`, and `returns`
|
package/src/FunctionSpec.ts
CHANGED
|
@@ -141,7 +141,9 @@ export type Name<FunctionSpec_ extends AnyWithProps> = FunctionSpec_["name"];
|
|
|
141
141
|
export type MiddlewareSpecs<FunctionSpec_ extends AnyWithProps> =
|
|
142
142
|
FunctionSpec_["middlewareSpecs"][number];
|
|
143
143
|
|
|
144
|
-
/**
|
|
144
|
+
/**
|
|
145
|
+
* The field map declared by a Confect-provenance spec.
|
|
146
|
+
*/
|
|
145
147
|
export type ArgsFields<FunctionSpec_ extends AnyWithProps> =
|
|
146
148
|
FunctionSpec_ extends {
|
|
147
149
|
readonly functionProvenance: {
|
|
@@ -157,7 +159,9 @@ export type ArgsFields<FunctionSpec_ extends AnyWithProps> =
|
|
|
157
159
|
? FunctionProvenance.ArgsFields
|
|
158
160
|
: never;
|
|
159
161
|
|
|
160
|
-
/**
|
|
162
|
+
/**
|
|
163
|
+
* The args schema assembled from a Confect-provenance spec's field map.
|
|
164
|
+
*/
|
|
161
165
|
export type ArgsSchema<FunctionSpec_ extends AnyWithProps> =
|
|
162
166
|
FunctionSpec_ extends {
|
|
163
167
|
readonly functionProvenance: {
|
|
@@ -191,10 +195,10 @@ export type ErrorSchema<FunctionSpec_ extends AnyWithProps> =
|
|
|
191
195
|
FunctionSpec_ extends {
|
|
192
196
|
readonly functionProvenance: {
|
|
193
197
|
readonly _tag: "Confect";
|
|
194
|
-
readonly error?: infer ErrorSchema_
|
|
198
|
+
readonly error?: infer ErrorSchema_;
|
|
195
199
|
};
|
|
196
200
|
}
|
|
197
|
-
? ErrorSchema_
|
|
201
|
+
? Extract<ErrorSchema_, Schema.Codec<any, any>>
|
|
198
202
|
: never;
|
|
199
203
|
|
|
200
204
|
export type Args<FunctionSpec_ extends AnyWithProps> = FunctionSpec_ extends {
|
|
@@ -395,10 +399,10 @@ const make = <
|
|
|
395
399
|
};
|
|
396
400
|
|
|
397
401
|
/**
|
|
398
|
-
* `Schema.Struct` fields that must not declare `paginationOpts`. Used to
|
|
399
|
-
*
|
|
400
|
-
*
|
|
401
|
-
*
|
|
402
|
+
* `Schema.Struct` fields that must not declare `paginationOpts`. Used to reject
|
|
403
|
+
* a user args schema that redeclares the field the paginated constructors add
|
|
404
|
+
* themselves; the check reports at the `args` thunk with an unsatisfiable type
|
|
405
|
+
* when violated.
|
|
402
406
|
*/
|
|
403
407
|
type ForbidPaginationOpts<
|
|
404
408
|
UserArgsFields extends FunctionProvenance.ArgsFields,
|
package/src/GroupPath.ts
CHANGED
|
@@ -4,7 +4,8 @@ import type * as GroupSpec from "./GroupSpec";
|
|
|
4
4
|
* Recursively generates paths for a group and its nested groups.
|
|
5
5
|
*
|
|
6
6
|
* - For a group with no subgroups, returns just the group name.
|
|
7
|
-
* - For a group with subgroups, returns the group name plus all possible paths
|
|
7
|
+
* - For a group with subgroups, returns the group name plus all possible paths
|
|
8
|
+
* through its direct subgroups.
|
|
8
9
|
*/
|
|
9
10
|
export type All<
|
|
10
11
|
Group extends GroupSpec.AnyWithProps,
|
|
@@ -26,13 +27,11 @@ type AllHelper<
|
|
|
26
27
|
: never;
|
|
27
28
|
|
|
28
29
|
/**
|
|
29
|
-
* Recursively extracts the group at the given dot-separated path.
|
|
30
|
-
*
|
|
30
|
+
* Recursively extracts the group at the given dot-separated path. Path must
|
|
31
|
+
* match the format defined in `Path` above, e.g. "group" or "group.subgroup".
|
|
31
32
|
*
|
|
32
33
|
* @example
|
|
33
|
-
*
|
|
34
|
-
* type G = WithPath<RootGroup, "group.subgroup">;
|
|
35
|
-
* ```
|
|
34
|
+
* type G = WithPath<RootGroup, "group.subgroup">;
|
|
36
35
|
*/
|
|
37
36
|
export type GroupAt<
|
|
38
37
|
Group,
|
package/src/GroupSpec.ts
CHANGED
|
@@ -129,7 +129,10 @@ export type WithName<
|
|
|
129
129
|
Name_ extends Name<Group>,
|
|
130
130
|
> = Extract<Group, { readonly name: Name_ }>;
|
|
131
131
|
|
|
132
|
-
/**
|
|
132
|
+
/**
|
|
133
|
+
* Assigns a segment name to a leaf group created with {@link make} for typing
|
|
134
|
+
* and refs.
|
|
135
|
+
*/
|
|
133
136
|
export type NamedAt<Group extends Any, Name_ extends string> = Omit<
|
|
134
137
|
Group,
|
|
135
138
|
"name"
|
|
@@ -349,10 +352,11 @@ export const makeNodeAt = <const Name_ extends string>(
|
|
|
349
352
|
});
|
|
350
353
|
};
|
|
351
354
|
|
|
352
|
-
export
|
|
355
|
+
export function withName<const Name_ extends string, Group extends Any>(
|
|
353
356
|
name: Name_,
|
|
354
|
-
group:
|
|
355
|
-
):
|
|
357
|
+
group: Group,
|
|
358
|
+
): NamedAt<Group, Name_>;
|
|
359
|
+
export function withName(name: string, group: Any): AnyWithProps {
|
|
356
360
|
validateConfectFunctionIdentifier(name);
|
|
357
361
|
const group_ = group as AnyWithProps;
|
|
358
362
|
|
|
@@ -367,7 +371,7 @@ export const withName = <const Name_ extends string>(
|
|
|
367
371
|
groups: group_.groups,
|
|
368
372
|
middlewareAttachments: group_.middlewareAttachments,
|
|
369
373
|
});
|
|
370
|
-
}
|
|
374
|
+
}
|
|
371
375
|
|
|
372
376
|
export const validateMiddleware = (
|
|
373
377
|
group: AnyWithProps,
|
package/src/Identifier.ts
CHANGED
|
@@ -95,15 +95,16 @@ export const validateConfectFunctionIdentifier = (identifier: string) => {
|
|
|
95
95
|
};
|
|
96
96
|
|
|
97
97
|
/**
|
|
98
|
-
* Validate that `identifier` is suitable as a Convex table name (and,
|
|
99
|
-
* as a `confect/tables/<identifier>.ts` filename).
|
|
98
|
+
* Validate that `identifier` is suitable as a Convex table name (and,
|
|
99
|
+
* equivalently, as a `confect/tables/<identifier>.ts` filename).
|
|
100
100
|
*
|
|
101
101
|
* Rules:
|
|
102
|
+
*
|
|
102
103
|
* - Must match `/^[A-Za-z][A-Za-z0-9_]*$/`—letter-leading, alphanumeric plus
|
|
103
104
|
* underscore. No `$` (not a valid Convex table name character); no leading
|
|
104
105
|
* `_` (Convex reserves `_<name>` for its system tables).
|
|
105
|
-
* - Must not be a reserved JavaScript identifier, so the name can also be used
|
|
106
|
-
*
|
|
106
|
+
* - Must not be a reserved JavaScript identifier, so the name can also be used as
|
|
107
|
+
* a binding name in generated code without escaping.
|
|
107
108
|
*/
|
|
108
109
|
export const validateConfectTableIdentifier = (identifier: string) => {
|
|
109
110
|
if (!matchesTableNamePattern(identifier)) {
|
package/src/Lazy.ts
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Install a lazy memoised property on `target`. The first access runs
|
|
3
|
-
* `compute()` and replaces the getter with a plain, non-writable data
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* observably indistinguishable.
|
|
3
|
+
* `compute()` and replaces the getter with a plain, non-writable data property
|
|
4
|
+
* whose value is the computed result. Subsequent accesses hit the V8 fast path
|
|
5
|
+
* for own data properties—no function call, identical returned reference—so
|
|
6
|
+
* first and second-and-subsequent accesses are observably indistinguishable.
|
|
8
7
|
*
|
|
9
|
-
* The replacement property is `enumerable: true` so the lazy property
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* forcing the computation.
|
|
8
|
+
* The replacement property is `enumerable: true` so the lazy property still
|
|
9
|
+
* participates in `Object.keys`/`JSON.stringify` after it materialises,
|
|
10
|
+
* matching the shape of a plain data property. The property is also
|
|
11
|
+
* `enumerable` before materialising, so presence checks (`"key" in target`,
|
|
12
|
+
* `Object.hasOwn(target, key)`) observe it without forcing the computation.
|
|
15
13
|
*
|
|
16
14
|
* This is the single shared implementation consumed across packages (e.g.
|
|
17
|
-
* `@confect/core`'s lazy `FunctionSpec` schemas and lazy `Table`
|
|
15
|
+
* `@confect/core`'s lazy `FunctionSpec` schemas and lazy `Table`
|
|
16
|
+
* `Fields`/`Doc`), so there is no chance of the two drifting apart.
|
|
18
17
|
*/
|
|
19
18
|
export const defineProperty = <T extends object, K extends PropertyKey>(
|
|
20
19
|
target: T,
|