@confect/core 10.0.0-next.17 → 10.0.0-next.19

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.
Files changed (68) hide show
  1. package/CHANGELOG.md +81 -0
  2. package/dist/FunctionProvenance.d.ts +81 -60
  3. package/dist/FunctionProvenance.d.ts.map +1 -1
  4. package/dist/FunctionProvenance.js +9 -9
  5. package/dist/FunctionProvenance.js.map +1 -1
  6. package/dist/FunctionSpec.d.ts +256 -144
  7. package/dist/FunctionSpec.d.ts.map +1 -1
  8. package/dist/FunctionSpec.js +25 -20
  9. package/dist/FunctionSpec.js.map +1 -1
  10. package/dist/GroupPath.d.ts +1 -4
  11. package/dist/GroupPath.d.ts.map +1 -1
  12. package/dist/GroupPath.js.map +1 -1
  13. package/dist/GroupSpec.d.ts +5 -3
  14. package/dist/GroupSpec.d.ts.map +1 -1
  15. package/dist/GroupSpec.js +1 -1
  16. package/dist/GroupSpec.js.map +1 -1
  17. package/dist/Lazy.d.ts +2 -3
  18. package/dist/Lazy.d.ts.map +1 -1
  19. package/dist/Lazy.js +2 -3
  20. package/dist/Lazy.js.map +1 -1
  21. package/dist/MiddlewareSpec.d.ts +2 -2
  22. package/dist/MiddlewareSpec.d.ts.map +1 -1
  23. package/dist/MiddlewareSpec.js +1 -1
  24. package/dist/MiddlewareSpec.js.map +1 -1
  25. package/dist/PaginationError.d.ts +14 -0
  26. package/dist/PaginationError.d.ts.map +1 -0
  27. package/dist/PaginationError.js +25 -0
  28. package/dist/PaginationError.js.map +1 -0
  29. package/dist/Ref.d.ts +66 -20
  30. package/dist/Ref.d.ts.map +1 -1
  31. package/dist/Ref.js +3 -3
  32. package/dist/Ref.js.map +1 -1
  33. package/dist/Refs.d.ts +1 -1
  34. package/dist/Refs.d.ts.map +1 -1
  35. package/dist/Refs.js.map +1 -1
  36. package/dist/SchemaToValidator.d.ts +99 -0
  37. package/dist/SchemaToValidator.d.ts.map +1 -0
  38. package/dist/SchemaToValidator.js +156 -0
  39. package/dist/SchemaToValidator.js.map +1 -0
  40. package/dist/Spec.d.ts +3 -2
  41. package/dist/Spec.d.ts.map +1 -1
  42. package/dist/Spec.js +1 -1
  43. package/dist/Spec.js.map +1 -1
  44. package/dist/Table.d.ts +74 -0
  45. package/dist/Table.d.ts.map +1 -0
  46. package/dist/Table.js +77 -0
  47. package/dist/Table.js.map +1 -0
  48. package/dist/Types.d.ts +8 -2
  49. package/dist/Types.d.ts.map +1 -1
  50. package/dist/Types.js.map +1 -1
  51. package/dist/index.d.ts +3 -0
  52. package/dist/index.d.ts.map +1 -1
  53. package/dist/index.js +4 -1
  54. package/package.json +4 -4
  55. package/src/FunctionProvenance.ts +84 -71
  56. package/src/FunctionSpec.ts +193 -110
  57. package/src/GroupPath.ts +1 -6
  58. package/src/GroupSpec.ts +6 -6
  59. package/src/Lazy.ts +2 -3
  60. package/src/MiddlewareSpec.ts +2 -2
  61. package/src/PaginationError.ts +72 -0
  62. package/src/Ref.ts +164 -153
  63. package/src/Refs.ts +1 -0
  64. package/src/SchemaToValidator.ts +601 -0
  65. package/src/Spec.ts +4 -4
  66. package/src/Table.ts +426 -0
  67. package/src/Types.ts +9 -3
  68. package/src/index.ts +3 -0
@@ -0,0 +1,156 @@
1
+ import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
+ import { tableName } from "./GenericId.js";
3
+ import * as Data from "effect/Data";
4
+ import * as Schema from "effect/Schema";
5
+ import * as Predicate from "effect/Predicate";
6
+ import * as Option from "effect/Option";
7
+ import * as SchemaAST from "effect/SchemaAST";
8
+ import { v } from "convex/values";
9
+ import * as Match from "effect/Match";
10
+ import * as Effect from "effect/Effect";
11
+ import { pipe } from "effect/Function";
12
+ import * as Array from "effect/Array";
13
+ import * as Number from "effect/Number";
14
+ import * as String from "effect/String";
15
+ //#region src/SchemaToValidator.ts
16
+ var SchemaToValidator_exports = /* @__PURE__ */ __exportAll({
17
+ EmptyTupleIsNotSupportedError: () => EmptyTupleIsNotSupportedError,
18
+ EmptyUnionIsNotSupportedError: () => EmptyUnionIsNotSupportedError,
19
+ IndexSignaturesAreNotSupportedError: () => IndexSignaturesAreNotSupportedError,
20
+ MixedIndexAndPropertySignaturesAreNotSupportedError: () => MixedIndexAndPropertySignaturesAreNotSupportedError,
21
+ OptionalTupleElementsAreNotSupportedError: () => OptionalTupleElementsAreNotSupportedError,
22
+ TopLevelMustBeObjectError: () => TopLevelMustBeObjectError,
23
+ TopLevelMustBeObjectOrUnionError: () => TopLevelMustBeObjectOrUnionError,
24
+ UnsupportedPropertySignatureKeyTypeError: () => UnsupportedPropertySignatureKeyTypeError,
25
+ UnsupportedSchemaTypeError: () => UnsupportedSchemaTypeError,
26
+ compileArgsSchema: () => compileArgsSchema,
27
+ compileAst: () => compileAst,
28
+ compileReturnsSchema: () => compileReturnsSchema,
29
+ compileSchema: () => compileSchema,
30
+ compileTableSchema: () => compileTableSchema,
31
+ isRecursive: () => isRecursive
32
+ });
33
+ const compileArgsSchema = (argsSchema) => {
34
+ const ast = Schema.toEncoded(argsSchema).ast;
35
+ return pipe(ast, Match.value, Match.tag("Objects", (objectsAst) => Array.isReadonlyArrayEmpty(objectsAst.indexSignatures) ? handlePropertySignatures(objectsAst) : Effect.fail(new IndexSignaturesAreNotSupportedError())), Match.orElse(() => Effect.fail(new TopLevelMustBeObjectError())), Effect.runSync);
36
+ };
37
+ const compileReturnsSchema = (schema) => Effect.runSync(compileAst(Schema.toEncoded(schema).ast));
38
+ const compileTableSchema = (schema) => {
39
+ const ast = Schema.toEncoded(schema).ast;
40
+ return pipe(ast, Match.value, Match.tag("Objects", ({ indexSignatures }) => Array.isReadonlyArrayEmpty(indexSignatures) ? compileAst(ast) : Effect.fail(new IndexSignaturesAreNotSupportedError())), Match.tag("Union", (unionAst) => compileAst(unionAst)), Match.orElse(() => Effect.fail(new TopLevelMustBeObjectOrUnionError())), Effect.runSync);
41
+ };
42
+ const compileSchema = (schema) => Effect.runSync(compileAst(schema.ast));
43
+ const isRecursive = (ast) => pipe(ast, Match.value, Match.tag("Literal", "Null", "Boolean", "String", "Number", "BigInt", "Unknown", "Any", "Declaration", "UniqueSymbol", "Symbol", "Undefined", "Void", "Never", "Enum", "TemplateLiteral", "ObjectKeyword", () => false), Match.tag("Union", ({ types }) => Array.some(types, (type) => isRecursive(type))), Match.tag("Objects", ({ propertySignatures }) => Array.some(propertySignatures, ({ type }) => isRecursive(type))), Match.tag("Arrays", ({ elements, rest }) => Array.some(elements, (element) => isRecursive(element)) || Array.some(rest, (element) => isRecursive(element))), Match.tag("Suspend", () => true), Match.exhaustive);
44
+ const compileAst = (ast, isOptionalPropertyOfTypeLiteral = false) => isRecursive(ast) ? Effect.succeed(v.any()) : pipe(ast, Match.value, Match.tag("Literal", ({ literal }) => pipe(literal, Match.value, Match.whenOr(Match.string, Match.number, Match.bigint, Match.boolean, (l) => v.literal(l)), Match.exhaustive, Effect.succeed)), Match.tag("Null", () => Effect.succeed(v.null())), Match.tag("Boolean", () => Effect.succeed(v.boolean())), Match.tag("String", (stringAst) => tableName(stringAst).pipe(Option.match({
45
+ onNone: () => Effect.succeed(v.string()),
46
+ onSome: (tableName) => Effect.succeed(v.id(tableName))
47
+ }))), Match.tag("Number", () => Effect.succeed(v.float64())), Match.tag("BigInt", () => Effect.succeed(v.int64())), Match.tag("Union", (unionAst) => handleUnion(unionAst, isOptionalPropertyOfTypeLiteral)), Match.tag("Objects", (objectsAst) => handleObjects(objectsAst)), Match.tag("Arrays", (arraysAst) => handleArrays(arraysAst)), Match.tag("Unknown", "Any", () => Effect.succeed(v.any())), Match.tag("Declaration", (declaration) => Effect.mapBoth(declaration.run(declaration.typeParameters)(/* @__PURE__ */ new ArrayBuffer(0), declaration, {}), {
48
+ onSuccess: () => v.bytes(),
49
+ onFailure: () => new UnsupportedSchemaTypeError({ schemaType: declaration._tag })
50
+ })), Match.tag("Suspend", () => Effect.succeed(v.any())), Match.tag("UniqueSymbol", "Symbol", "Undefined", "Void", "Never", "Enum", "TemplateLiteral", "ObjectKeyword", () => Effect.fail(new UnsupportedSchemaTypeError({ schemaType: ast._tag }))), Match.exhaustive);
51
+ const handleUnion = ({ types }, isOptionalPropertyOfTypeLiteral) => Effect.gen(function* () {
52
+ const members = isOptionalPropertyOfTypeLiteral ? Array.filter(types, Predicate.not(SchemaAST.isUndefined)) : types;
53
+ const [firstValidator, secondValidator, ...restValidators] = yield* Effect.all(Array.map(members, (type) => compileAst(type)));
54
+ if (firstValidator === void 0) return yield* new EmptyUnionIsNotSupportedError();
55
+ else if (secondValidator === void 0) return firstValidator;
56
+ else return v.union(firstValidator, secondValidator, ...restValidators);
57
+ });
58
+ const handleObjects = (objectsAst) => pipe(objectsAst.indexSignatures, Array.head, Option.match({
59
+ onNone: () => Effect.map(handlePropertySignatures(objectsAst), v.object),
60
+ onSome: ({ parameter, type }) => pipe(objectsAst.propertySignatures, Array.head, Option.match({
61
+ onNone: () => Effect.map(Effect.all({
62
+ parameter_: compileAst(parameter),
63
+ type_: compileAst(type)
64
+ }), ({ parameter_, type_ }) => v.record(parameter_, type_)),
65
+ onSome: () => Effect.fail(new MixedIndexAndPropertySignaturesAreNotSupportedError())
66
+ }))
67
+ }));
68
+ const handleArrays = ({ elements, rest }) => Effect.gen(function* () {
69
+ const [f, s, ...r] = elements;
70
+ const elementToValidator = (element) => SchemaAST.isOptional(element) ? Effect.fail(new OptionalTupleElementsAreNotSupportedError()) : compileAst(element);
71
+ const arrayItemsValidator = yield* f === void 0 ? pipe(rest, Array.head, Option.match({
72
+ onNone: () => Effect.fail(new EmptyTupleIsNotSupportedError()),
73
+ onSome: (type) => compileAst(type)
74
+ })) : s === void 0 ? elementToValidator(f) : Effect.gen(function* () {
75
+ const firstValidator = yield* elementToValidator(f);
76
+ const secondValidator = yield* elementToValidator(s);
77
+ const restValidators = yield* Effect.forEach(r, elementToValidator);
78
+ return v.union(firstValidator, secondValidator, ...restValidators);
79
+ });
80
+ return v.array(arrayItemsValidator);
81
+ });
82
+ const handlePropertySignatures = (objectsAst) => pipe(objectsAst.propertySignatures, Effect.forEach(({ type, name }) => {
83
+ const isOptional = SchemaAST.isOptional(type);
84
+ if (String.isString(name)) return Option.match(Number.parse(name), {
85
+ onNone: () => Effect.gen(function* () {
86
+ const validator = yield* compileAst(type, isOptional);
87
+ return {
88
+ propertyName: name,
89
+ validator: isOptional ? v.optional(validator) : validator
90
+ };
91
+ }),
92
+ onSome: (number) => Effect.fail(new UnsupportedPropertySignatureKeyTypeError({ propertyKey: number }))
93
+ });
94
+ else return Effect.fail(new UnsupportedPropertySignatureKeyTypeError({ propertyKey: name }));
95
+ }), Effect.andThen((propertyNamesWithValidators) => pipe(propertyNamesWithValidators, Array.reduce({}, (acc, { propertyName, validator }) => ({
96
+ [propertyName]: validator,
97
+ ...acc
98
+ })), Effect.succeed)));
99
+ var TopLevelMustBeObjectError = class extends Data.TaggedError("TopLevelMustBeObjectError") {
100
+ /* v8 ignore start */
101
+ get message() {
102
+ return "Top level schema must be an object";
103
+ }
104
+ };
105
+ var TopLevelMustBeObjectOrUnionError = class extends Data.TaggedError("TopLevelMustBeObjectOrUnionError") {
106
+ /* v8 ignore start */
107
+ get message() {
108
+ return "Top level schema must be an object or a union";
109
+ }
110
+ };
111
+ var UnsupportedPropertySignatureKeyTypeError = class extends Data.TaggedError("UnsupportedPropertySignatureKeyTypeError") {
112
+ /* v8 ignore start */
113
+ get message() {
114
+ return `Unsupported property signature '${this.propertyKey.toString()}'. Property is of type '${typeof this.propertyKey}' but only 'string' properties are supported.`;
115
+ }
116
+ };
117
+ var EmptyTupleIsNotSupportedError = class extends Data.TaggedError("EmptyTupleIsNotSupportedError") {
118
+ /* v8 ignore start */
119
+ get message() {
120
+ return "Tuple must have at least one element";
121
+ }
122
+ };
123
+ var EmptyUnionIsNotSupportedError = class extends Data.TaggedError("EmptyUnionIsNotSupportedError") {
124
+ /* v8 ignore start */
125
+ get message() {
126
+ return "Union must have at least one member that compiles to a validator";
127
+ }
128
+ };
129
+ var UnsupportedSchemaTypeError = class extends Data.TaggedError("UnsupportedSchemaTypeError") {
130
+ /* v8 ignore start */
131
+ get message() {
132
+ return `Unsupported schema type '${this.schemaType}'`;
133
+ }
134
+ };
135
+ var IndexSignaturesAreNotSupportedError = class extends Data.TaggedError("IndexSignaturesAreNotSupportedError") {
136
+ /* v8 ignore start */
137
+ get message() {
138
+ return "Index signatures are not supported";
139
+ }
140
+ };
141
+ var MixedIndexAndPropertySignaturesAreNotSupportedError = class extends Data.TaggedError("MixedIndexAndPropertySignaturesAreNotSupportedError") {
142
+ /* v8 ignore start */
143
+ get message() {
144
+ return "Mixed index and property signatures are not supported";
145
+ }
146
+ };
147
+ var OptionalTupleElementsAreNotSupportedError = class extends Data.TaggedError("OptionalTupleElementsAreNotSupportedError") {
148
+ /* v8 ignore start */
149
+ get message() {
150
+ return "Optional tuple elements are not supported";
151
+ }
152
+ };
153
+ //#endregion
154
+ export { EmptyTupleIsNotSupportedError, EmptyUnionIsNotSupportedError, IndexSignaturesAreNotSupportedError, MixedIndexAndPropertySignaturesAreNotSupportedError, OptionalTupleElementsAreNotSupportedError, SchemaToValidator_exports, TopLevelMustBeObjectError, TopLevelMustBeObjectOrUnionError, UnsupportedPropertySignatureKeyTypeError, UnsupportedSchemaTypeError, compileArgsSchema, compileAst, compileReturnsSchema, compileSchema, compileTableSchema, isRecursive };
155
+
156
+ //# sourceMappingURL=SchemaToValidator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SchemaToValidator.js","names":["GenericId.tableName"],"sources":["../src/SchemaToValidator.ts"],"sourcesContent":["import type {\n PropertyValidators,\n Validator,\n VAny,\n VArray,\n VBoolean,\n VBytes,\n VFloat64,\n VId,\n VInt64,\n VLiteral,\n VNull,\n VObject,\n VOptional,\n VRecord,\n VString,\n VUnion,\n} from \"convex/values\";\nimport { v } from \"convex/values\";\nimport { pipe } from \"effect/Function\";\nimport * as Array from \"effect/Array\";\nimport * as Data from \"effect/Data\";\nimport * as Effect from \"effect/Effect\";\nimport * as Match from \"effect/Match\";\nimport * as Number from \"effect/Number\";\nimport * as Option from \"effect/Option\";\nimport * as Predicate from \"effect/Predicate\";\nimport * as Schema from \"effect/Schema\";\nimport * as SchemaAST from \"effect/SchemaAST\";\nimport * as String from \"effect/String\";\n\nimport * as GenericId from \"./GenericId\";\nimport type {\n IsAny,\n IsOptional,\n IsRecord,\n IsRecursive,\n IsUnion,\n TypeError,\n UnionToTuple,\n} from \"./Types\";\n\n// Args\n\nexport const compileArgsSchema = <ConfectValue, ConvexValue>(\n argsSchema: Schema.Codec<ConfectValue, ConvexValue>,\n): PropertyValidators => {\n const ast = Schema.toEncoded(argsSchema).ast;\n\n return pipe(\n ast,\n Match.value,\n Match.tag(\"Objects\", (objectsAst) =>\n Array.isReadonlyArrayEmpty(objectsAst.indexSignatures)\n ? handlePropertySignatures(objectsAst)\n : Effect.fail(new IndexSignaturesAreNotSupportedError()),\n ),\n Match.orElse(() => Effect.fail(new TopLevelMustBeObjectError())),\n Effect.runSync,\n );\n};\n\n// Returns\n\nexport const compileReturnsSchema = <ConfectValue, ConvexValue>(\n schema: Schema.Codec<ConfectValue, ConvexValue>,\n): Validator<any, any, any> =>\n Effect.runSync(compileAst(Schema.toEncoded(schema).ast));\n\n// Table\n\n/**\n * Convert a table `Schema` to a table `Validator`.\n */\nexport type TableSchemaToTableValidator<\n TableSchema extends Schema.Codec<any, any>,\n> =\n ValueToValidator<TableSchema[\"Encoded\"]> extends infer Vd extends\n | VObject<any, any, any, any>\n | VUnion<any, any, any, any>\n ? Vd\n : never;\n\nexport const compileTableSchema = <TableSchema extends Schema.Codec<any, any>>(\n schema: TableSchema,\n): TableSchemaToTableValidator<TableSchema> => {\n const ast = Schema.toEncoded(schema).ast;\n\n return pipe(\n ast,\n Match.value,\n Match.tag(\"Objects\", ({ indexSignatures }) =>\n Array.isReadonlyArrayEmpty(indexSignatures)\n ? (compileAst(ast) as Effect.Effect<any>)\n : Effect.fail(new IndexSignaturesAreNotSupportedError()),\n ),\n Match.tag(\"Union\", (unionAst) => compileAst(unionAst)),\n Match.orElse(() => Effect.fail(new TopLevelMustBeObjectOrUnionError())),\n Effect.runSync,\n );\n};\n\n// Compiler\n\nexport type ReadonlyValue =\n | string\n | number\n | bigint\n | boolean\n | ArrayBuffer\n | ReadonlyArrayValue\n | ReadonlyRecordValue\n | null;\n\ntype ReadonlyArrayValue = readonly ReadonlyValue[];\n\nexport type ReadonlyRecordValue = {\n readonly [key: string]: ReadonlyValue | undefined;\n};\n\ntype MutableValue<T> =\n T extends ReadonlyArray<infer El>\n ? MutableValue<El>[]\n : T extends ReadonlyRecordValue\n ? { -readonly [K in keyof T]: MutableValue<Exclude<T[K], undefined>> }\n : T;\n\nexport type ValueToValidator<Vl> = [Vl] extends [never]\n ? never\n : IsAny<Vl> extends true\n ? VAny\n : [Vl] extends [null]\n ? VNull\n : [Vl] extends [boolean]\n ? [boolean] extends [Vl]\n ? VBoolean\n : VLiteral<Vl>\n : IsUnion<Vl> extends true\n ? IsRecursive<Vl> extends true\n ? VAny\n : [Vl] extends [ReadonlyValue]\n ? UnionValueToValidator<Vl>\n : TypeError<\"Provided value is not a valid Convex value\", Vl>\n : [Vl] extends [number]\n ? [number] extends [Vl]\n ? VFloat64\n : VLiteral<Vl>\n : [Vl] extends [bigint]\n ? [bigint] extends [Vl]\n ? VInt64\n : VLiteral<Vl>\n : [Vl] extends [string]\n ? Vl extends {\n __tableName: infer TableName extends string;\n }\n ? VId<GenericId.GenericId<TableName>>\n : [string] extends [Vl]\n ? VString\n : VLiteral<Vl>\n : [Vl] extends [ArrayBuffer]\n ? VBytes\n : IsRecursive<Vl> extends true\n ? VAny\n : [Vl] extends [ReadonlyValue]\n ? Vl extends ReadonlyArray<ReadonlyValue>\n ? ArrayValueToValidator<Vl>\n : Vl extends ReadonlyRecordValue\n ? RecordValueToValidator<Vl>\n : TypeError<\"Unexpected value\", Vl>\n : TypeError<\n \"Provided value is not a valid Convex value\",\n Vl\n >;\n\ntype ArrayValueToValidator<Vl extends ReadonlyArray<ReadonlyValue>> =\n Vl extends ReadonlyArray<infer El extends ReadonlyValue>\n ? ValueToValidator<El> extends infer Vd extends Validator<any, any, any>\n ? VArray<MutableValue<El[]>, Vd>\n : never\n : never;\n\ntype RecordValueToValidator<Vl> = Vl extends ReadonlyRecordValue\n ? {\n -readonly [K in keyof Vl]-?: IsAny<Vl[K]> extends true\n ? IsOptional<Vl, K> extends true\n ? VOptional<VAny>\n : VAny\n : UndefinedOrValueToValidator<Vl[K]>;\n } extends infer VdRecord extends Record<string, any>\n ? MutableValue<Vl> extends infer VlRecord extends Record<string, any>\n ? IsRecord<VlRecord> extends true\n ? VRecord<VlRecord, VString, VdRecord[keyof VdRecord]>\n : VObject<VlRecord, VdRecord>\n : never\n : never\n : never;\n\nexport type UndefinedOrValueToValidator<Vl extends ReadonlyValue | undefined> =\n undefined extends Vl\n ? [Vl] extends [(infer Val extends ReadonlyValue) | undefined]\n ? ValueToValidator<Val> extends infer Vd extends Validator<\n any,\n \"required\",\n any\n >\n ? VOptional<Vd>\n : never\n : never\n : [Vl] extends [ReadonlyValue]\n ? ValueToValidator<Vl>\n : never;\n\ntype UnionValueToValidator<Vl extends ReadonlyValue> = [Vl] extends [\n ReadonlyValue,\n]\n ? IsUnion<Vl> extends true\n ? UnionToTuple<Vl> extends infer VlTuple extends\n ReadonlyArray<ReadonlyValue>\n ? ValueTupleToValidatorTuple<VlTuple> extends infer VdTuple extends\n Validator<any, \"required\", any>[]\n ? VUnion<MutableValue<Vl>, VdTuple>\n : TypeError<\"Failed to convert value tuple to validator tuple\">\n : TypeError<\"Failed to convert union to tuple\">\n : TypeError<\"Expected a union of values, but got a single value instead\">\n : TypeError<\"Provided value is not a valid Convex value\">;\n\ntype ValueTupleToValidatorTuple<VlTuple extends ReadonlyArray<ReadonlyValue>> =\n VlTuple extends\n | [true, false, ...infer VlRest extends ReadonlyArray<ReadonlyValue>]\n | [false, true, ...infer VlRest extends ReadonlyArray<ReadonlyValue>]\n ? ValueTupleToValidatorTuple<VlRest> extends infer VdRest extends Validator<\n any,\n any,\n any\n >[]\n ? [VBoolean<boolean>, ...VdRest]\n : never\n : VlTuple extends [\n infer Vl extends ReadonlyValue,\n ...infer VlRest extends ReadonlyArray<ReadonlyValue>,\n ]\n ? ValueToValidator<Vl> extends infer Vd extends Validator<any, any, any>\n ? ValueTupleToValidatorTuple<VlRest> extends infer VdRest extends\n Validator<any, \"required\", any>[]\n ? [Vd, ...VdRest]\n : never\n : never\n : [];\n\nexport const compileSchema = <T, E>(\n schema: Schema.Codec<T, E>,\n): ValueToValidator<(typeof schema)[\"Encoded\"]> =>\n Effect.runSync(compileAst(schema.ast)) as any;\n\nexport const isRecursive = (ast: SchemaAST.AST): boolean =>\n pipe(\n ast,\n Match.value,\n Match.tag(\n \"Literal\",\n \"Null\",\n \"Boolean\",\n \"String\",\n \"Number\",\n \"BigInt\",\n \"Unknown\",\n \"Any\",\n \"Declaration\",\n \"UniqueSymbol\",\n \"Symbol\",\n \"Undefined\",\n \"Void\",\n \"Never\",\n \"Enum\",\n \"TemplateLiteral\",\n \"ObjectKeyword\",\n () => false,\n ),\n Match.tag(\"Union\", ({ types }) =>\n Array.some(types, (type) => isRecursive(type)),\n ),\n Match.tag(\"Objects\", ({ propertySignatures }) =>\n Array.some(propertySignatures, ({ type }) => isRecursive(type)),\n ),\n Match.tag(\n \"Arrays\",\n ({ elements, rest }) =>\n Array.some(elements, (element) => isRecursive(element)) ||\n Array.some(rest, (element) => isRecursive(element)),\n ),\n Match.tag(\"Suspend\", () => true),\n Match.exhaustive,\n );\n\nexport const compileAst = (\n ast: SchemaAST.AST,\n isOptionalPropertyOfTypeLiteral = false,\n): Effect.Effect<\n Validator<any, any, any>,\n | UnsupportedSchemaTypeError\n | UnsupportedPropertySignatureKeyTypeError\n | IndexSignaturesAreNotSupportedError\n | MixedIndexAndPropertySignaturesAreNotSupportedError\n | OptionalTupleElementsAreNotSupportedError\n | EmptyTupleIsNotSupportedError\n | EmptyUnionIsNotSupportedError\n> =>\n isRecursive(ast)\n ? Effect.succeed(v.any())\n : pipe(\n ast,\n Match.value,\n Match.tag(\"Literal\", ({ literal }) =>\n pipe(\n literal,\n Match.value,\n Match.whenOr(\n Match.string,\n Match.number,\n Match.bigint,\n Match.boolean,\n (l) => v.literal(l),\n ),\n Match.exhaustive,\n Effect.succeed,\n ),\n ),\n Match.tag(\"Null\", () => Effect.succeed(v.null())),\n Match.tag(\"Boolean\", () => Effect.succeed(v.boolean())),\n Match.tag(\"String\", (stringAst) =>\n GenericId.tableName(stringAst).pipe(\n Option.match({\n onNone: () => Effect.succeed(v.string()),\n onSome: (tableName) => Effect.succeed(v.id(tableName)),\n }),\n ),\n ),\n Match.tag(\"Number\", () => Effect.succeed(v.float64())),\n Match.tag(\"BigInt\", () => Effect.succeed(v.int64())),\n Match.tag(\"Union\", (unionAst) =>\n handleUnion(unionAst, isOptionalPropertyOfTypeLiteral),\n ),\n Match.tag(\"Objects\", (objectsAst) => handleObjects(objectsAst)),\n Match.tag(\"Arrays\", (arraysAst) => handleArrays(arraysAst)),\n Match.tag(\"Unknown\", \"Any\", () => Effect.succeed(v.any())),\n Match.tag(\"Declaration\", (declaration) =>\n Effect.mapBoth(\n declaration.run(declaration.typeParameters)(\n new ArrayBuffer(0),\n declaration,\n {},\n ) as Effect.Effect<ArrayBuffer, unknown, never>,\n {\n onSuccess: () => v.bytes(),\n onFailure: () =>\n new UnsupportedSchemaTypeError({\n schemaType: declaration._tag,\n }),\n },\n ),\n ),\n Match.tag(\"Suspend\", () => Effect.succeed(v.any())),\n Match.tag(\n \"UniqueSymbol\",\n \"Symbol\",\n \"Undefined\",\n \"Void\",\n \"Never\",\n \"Enum\",\n \"TemplateLiteral\",\n \"ObjectKeyword\",\n () =>\n Effect.fail(\n new UnsupportedSchemaTypeError({\n schemaType: ast._tag,\n }),\n ),\n ),\n Match.exhaustive,\n );\n\nconst handleUnion = (\n { types }: SchemaAST.Union,\n isOptionalPropertyOfTypeLiteral: boolean,\n) =>\n Effect.gen(function* () {\n const members = isOptionalPropertyOfTypeLiteral\n ? Array.filter(types, Predicate.not(SchemaAST.isUndefined))\n : types;\n\n const [firstValidator, secondValidator, ...restValidators] =\n yield* Effect.all(Array.map(members, (type) => compileAst(type)));\n\n if (firstValidator === undefined) {\n return yield* new EmptyUnionIsNotSupportedError();\n } else if (secondValidator === undefined) {\n return firstValidator;\n } else {\n return v.union(firstValidator, secondValidator, ...restValidators);\n }\n });\n\nconst handleObjects = (objectsAst: SchemaAST.Objects) =>\n pipe(\n objectsAst.indexSignatures,\n Array.head,\n Option.match({\n onNone: () => Effect.map(handlePropertySignatures(objectsAst), v.object),\n onSome: ({ parameter, type }) =>\n pipe(\n objectsAst.propertySignatures,\n Array.head,\n Option.match({\n onNone: () =>\n Effect.map(\n Effect.all({\n parameter_: compileAst(parameter),\n type_: compileAst(type),\n }),\n ({ parameter_, type_ }) => v.record(parameter_, type_),\n ),\n onSome: () =>\n Effect.fail(\n new MixedIndexAndPropertySignaturesAreNotSupportedError(),\n ),\n }),\n ),\n }),\n );\n\nconst handleArrays = ({ elements, rest }: SchemaAST.Arrays) =>\n Effect.gen(function* () {\n const [f, s, ...r] = elements;\n\n const elementToValidator = (element: SchemaAST.AST) =>\n SchemaAST.isOptional(element)\n ? Effect.fail(new OptionalTupleElementsAreNotSupportedError())\n : compileAst(element);\n\n const arrayItemsValidator = yield* f === undefined\n ? pipe(\n rest,\n Array.head,\n Option.match({\n onNone: () => Effect.fail(new EmptyTupleIsNotSupportedError()),\n onSome: (type) => compileAst(type),\n }),\n )\n : s === undefined\n ? elementToValidator(f)\n : Effect.gen(function* () {\n const firstValidator = yield* elementToValidator(f);\n const secondValidator = yield* elementToValidator(s);\n const restValidators = yield* Effect.forEach(r, elementToValidator);\n\n return v.union(firstValidator, secondValidator, ...restValidators);\n });\n\n return v.array(arrayItemsValidator);\n });\n\nconst handlePropertySignatures = (objectsAst: SchemaAST.Objects) =>\n pipe(\n objectsAst.propertySignatures,\n Effect.forEach(({ type, name }) => {\n const isOptional = SchemaAST.isOptional(type);\n if (String.isString(name)) {\n // Somehow, somewhere, keys of type number are being coerced to strings…\n return Option.match(Number.parse(name), {\n onNone: () =>\n Effect.gen(function* () {\n const validator = yield* compileAst(type, isOptional);\n\n return {\n propertyName: name,\n validator: isOptional ? v.optional(validator) : validator,\n };\n }),\n onSome: (number) =>\n Effect.fail(\n new UnsupportedPropertySignatureKeyTypeError({\n propertyKey: number,\n }),\n ),\n });\n } else {\n return Effect.fail(\n new UnsupportedPropertySignatureKeyTypeError({ propertyKey: name }),\n );\n }\n }),\n Effect.andThen((propertyNamesWithValidators) =>\n pipe(\n propertyNamesWithValidators,\n Array.reduce(\n {} as Record<string, Validator<any, any, any>>,\n (acc, { propertyName, validator }) => ({\n [propertyName]: validator,\n ...acc,\n }),\n ),\n Effect.succeed,\n ),\n ),\n );\n\n// Errors\n\nexport class TopLevelMustBeObjectError extends Data.TaggedError(\n \"TopLevelMustBeObjectError\",\n) {\n /* v8 ignore start */\n override get message() {\n return \"Top level schema must be an object\";\n }\n /* v8 ignore stop */\n}\n\nexport class TopLevelMustBeObjectOrUnionError extends Data.TaggedError(\n \"TopLevelMustBeObjectOrUnionError\",\n) {\n /* v8 ignore start */\n override get message() {\n return \"Top level schema must be an object or a union\";\n }\n /* v8 ignore stop */\n}\n\nexport class UnsupportedPropertySignatureKeyTypeError extends Data.TaggedError(\n \"UnsupportedPropertySignatureKeyTypeError\",\n)<{\n readonly propertyKey: number | symbol;\n}> {\n /* v8 ignore start */\n override get message() {\n return `Unsupported property signature '${this.propertyKey.toString()}'. Property is of type '${typeof this.propertyKey}' but only 'string' properties are supported.`;\n }\n /* v8 ignore stop */\n}\n\nexport class EmptyTupleIsNotSupportedError extends Data.TaggedError(\n \"EmptyTupleIsNotSupportedError\",\n) {\n /* v8 ignore start */\n override get message() {\n return \"Tuple must have at least one element\";\n }\n /* v8 ignore stop */\n}\n\nexport class EmptyUnionIsNotSupportedError extends Data.TaggedError(\n \"EmptyUnionIsNotSupportedError\",\n) {\n /* v8 ignore start */\n override get message() {\n return \"Union must have at least one member that compiles to a validator\";\n }\n /* v8 ignore stop */\n}\n\nexport class UnsupportedSchemaTypeError extends Data.TaggedError(\n \"UnsupportedSchemaTypeError\",\n)<{\n readonly schemaType: SchemaAST.AST[\"_tag\"];\n}> {\n /* v8 ignore start */\n override get message() {\n return `Unsupported schema type '${this.schemaType}'`;\n }\n /* v8 ignore stop */\n}\n\nexport class IndexSignaturesAreNotSupportedError extends Data.TaggedError(\n \"IndexSignaturesAreNotSupportedError\",\n) {\n /* v8 ignore start */\n override get message() {\n return \"Index signatures are not supported\";\n }\n /* v8 ignore stop */\n}\n\nexport class MixedIndexAndPropertySignaturesAreNotSupportedError extends Data.TaggedError(\n \"MixedIndexAndPropertySignaturesAreNotSupportedError\",\n) {\n /* v8 ignore start */\n override get message() {\n return \"Mixed index and property signatures are not supported\";\n }\n /* v8 ignore stop */\n}\n\nexport class OptionalTupleElementsAreNotSupportedError extends Data.TaggedError(\n \"OptionalTupleElementsAreNotSupportedError\",\n) {\n /* v8 ignore start */\n override get message() {\n return \"Optional tuple elements are not supported\";\n }\n /* v8 ignore stop */\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,MAAa,qBACX,eACuB;CACvB,MAAM,MAAM,OAAO,UAAU,UAAU,CAAC,CAAC;CAEzC,OAAO,KACL,KACA,MAAM,OACN,MAAM,IAAI,YAAY,eACpB,MAAM,qBAAqB,WAAW,eAAe,IACjD,yBAAyB,UAAU,IACnC,OAAO,KAAK,IAAI,oCAAoC,CAAC,CAC3D,GACA,MAAM,aAAa,OAAO,KAAK,IAAI,0BAA0B,CAAC,CAAC,GAC/D,OAAO,OACT;AACF;AAIA,MAAa,wBACX,WAEA,OAAO,QAAQ,WAAW,OAAO,UAAU,MAAM,CAAC,CAAC,GAAG,CAAC;AAgBzD,MAAa,sBACX,WAC6C;CAC7C,MAAM,MAAM,OAAO,U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AU;EACrB,OAAO;CACT;AAEF;AAEA,IAAa,6BAAb,cAAgD,KAAK,YACnD,4BACF,CAAC,CAEE;;CAED,IAAa,UAAU;EACrB,OAAO,4BAA4B,KAAK,WAAW;CACrD;AAEF;AAEA,IAAa,sCAAb,cAAyD,KAAK,YAC5D,qCACF,CAAC,CAAC;;CAEA,IAAa,UAAU;EACrB,OAAO;CACT;AAEF;AAEA,IAAa,sDAAb,cAAyE,KAAK,YAC5E,qDACF,CAAC,CAAC;;CAEA,IAAa,UAAU;EACrB,OAAO;CACT;AAEF;AAEA,IAAa,4CAAb,cAA+D,KAAK,YAClE,2CACF,CAAC,CAAC;;CAEA,IAAa,UAAU;EACrB,OAAO;CACT;AAEF"}
package/dist/Spec.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as GroupSpec from "./GroupSpec";
2
- export declare const TypeId = "@confect/core/Spec";
2
+ export declare const TypeId = "~@confect/core/Spec";
3
3
  export type TypeId = typeof TypeId;
4
4
  export declare const isSpec: (u: unknown) => u is AnyWithProps;
5
5
  /**
@@ -14,6 +14,7 @@ export interface Spec<Groups_ extends GroupSpec.AnyWithProps = never> {
14
14
  readonly groups: {
15
15
  [GroupName in GroupSpec.Name<Groups_>]: GroupSpec.WithName<Groups_, GroupName>;
16
16
  };
17
+ readonly "~Groups": Groups_;
17
18
  add<Group extends GroupSpec.AnyWithProps>(group: Group): Spec<Groups_ | Group>;
18
19
  addAt<const Name extends string, Group extends GroupSpec.AnyWithProps>(name: Name, group: Group): Spec<Groups_ | GroupSpec.NamedAt<Group, Name>>;
19
20
  }
@@ -22,6 +23,6 @@ export interface Any {
22
23
  }
23
24
  export interface AnyWithProps extends Spec<GroupSpec.AnyWithProps> {
24
25
  }
25
- export type Groups<Spec_ extends AnyWithProps> = Spec_["groups"][keyof Spec_["groups"]];
26
+ export type Groups<Spec_ extends AnyWithProps> = Spec_["~Groups"];
26
27
  export declare const make: () => Spec;
27
28
  //# sourceMappingURL=Spec.d.ts.map
@@ -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M,IAAI,QAAO,IAAiC,CAAC"}
package/dist/Spec.js CHANGED
@@ -8,7 +8,7 @@ var Spec_exports = /* @__PURE__ */ __exportAll({
8
8
  isSpec: () => isSpec,
9
9
  make: () => make
10
10
  });
11
- const TypeId = "@confect/core/Spec";
11
+ const TypeId = "~@confect/core/Spec";
12
12
  const isSpec = (u) => Predicate.hasProperty(u, TypeId);
13
13
  const Proto = {
14
14
  [TypeId]: TypeId,
package/dist/Spec.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Spec.js","names":["GroupSpec.withName"],"sources":["../src/Spec.ts"],"sourcesContent":["import * as Predicate from \"effect/Predicate\";\nimport * as Record from \"effect/Record\";\nimport * as GroupSpec from \"./GroupSpec\";\n\nexport const TypeId = \"@confect/core/Spec\";\nexport type TypeId = typeof TypeId;\n\nexport const isSpec = (u: unknown): u is AnyWithProps =>\n Predicate.hasProperty(u, TypeId);\n\n/**\n * A Confect spec: a flat container of function groups. Groups may be of any\n * runtime — a group built with `GroupSpec.makeNode()` (a Node action group) sits\n * alongside `GroupSpec.make()` groups in the same namespace. The runtime of a\n * group lives on the group itself (`GroupSpec.runtime`) and on each function's\n * `RuntimeAndFunctionType`; the spec does not carry a runtime of its own.\n */\nexport interface Spec<Groups_ extends GroupSpec.AnyWithProps = never> {\n readonly [TypeId]: TypeId;\n readonly groups: {\n [GroupName in GroupSpec.Name<Groups_>]: GroupSpec.WithName<\n Groups_,\n GroupName\n >;\n };\n\n add<Group extends GroupSpec.AnyWithProps>(\n group: Group,\n ): Spec<Groups_ | Group>;\n\n addAt<const Name extends string, Group extends GroupSpec.AnyWithProps>(\n name: Name,\n group: Group,\n ): Spec<Groups_ | GroupSpec.NamedAt<Group, Name>>;\n}\n\nexport interface Any {\n readonly [TypeId]: TypeId;\n}\n\nexport interface AnyWithProps extends Spec<GroupSpec.AnyWithProps> {}\n\nexport type Groups<Spec_ extends AnyWithProps> =\n Spec_[\"groups\"][keyof Spec_[\"groups\"]];\n\nconst Proto = {\n [TypeId]: TypeId,\n\n add<Group extends GroupSpec.AnyWithProps>(this: AnyWithProps, group: Group) {\n return makeProto({\n groups: Record.set(this.groups, group.name, group),\n });\n },\n\n addAt<Group extends GroupSpec.AnyWithProps>(\n this: AnyWithProps,\n name: string,\n group: Group,\n ) {\n return makeProto({\n groups: Record.set(this.groups, name, GroupSpec.withName(name, group)),\n });\n },\n};\n\nconst makeProto = <Groups_ extends GroupSpec.AnyWithProps>({\n groups,\n}: {\n groups: Record.ReadonlyRecord<string, Groups_>;\n}): Spec<Groups_> =>\n Object.assign(Object.create(Proto), {\n groups,\n });\n\nexport const make = (): Spec => makeProto({ groups: {} });\n"],"mappings":";;;;;;;;;;AAIA,MAAa,SAAS;AAGtB,MAAa,UAAU,MACrB,UAAU,YAAY,GAAG,MAAM;AAqCjC,MAAM,QAAQ;EACX,SAAS;CAEV,IAA8D,OAAc;EAC1E,OAAO,UAAU,EACf,QAAQ,OAAO,IAAI,KAAK,QAAQ,MAAM,MAAM,KAAK,EACnD,CAAC;CACH;CAEA,MAEE,MACA,OACA;EACA,OAAO,UAAU,EACf,QAAQ,OAAO,IAAI,KAAK,QAAQ,MAAMA,SAAmB,MAAM,KAAK,CAAC,EACvE,CAAC;CACH;AACF;AAEA,MAAM,aAAqD,EACzD,aAIA,OAAO,OAAO,OAAO,OAAO,KAAK,GAAG,EAClC,OACF,CAAC;AAEH,MAAa,aAAmB,UAAU,EAAE,QAAQ,CAAC,EAAE,CAAC"}
1
+ {"version":3,"file":"Spec.js","names":["GroupSpec.withName"],"sources":["../src/Spec.ts"],"sourcesContent":["import * as Predicate from \"effect/Predicate\";\nimport * as Record from \"effect/Record\";\nimport * as GroupSpec from \"./GroupSpec\";\n\nexport const TypeId = \"~@confect/core/Spec\";\nexport type TypeId = typeof TypeId;\n\nexport const isSpec = (u: unknown): u is AnyWithProps =>\n Predicate.hasProperty(u, TypeId);\n\n/**\n * A Confect spec: a flat container of function groups. Groups may be of any\n * runtime — a group built with `GroupSpec.makeNode()` (a Node action group) sits\n * alongside `GroupSpec.make()` groups in the same namespace. The runtime of a\n * group lives on the group itself (`GroupSpec.runtime`) and on each function's\n * `RuntimeAndFunctionType`; the spec does not carry a runtime of its own.\n */\nexport interface Spec<Groups_ extends GroupSpec.AnyWithProps = never> {\n readonly [TypeId]: TypeId;\n readonly groups: {\n [GroupName in GroupSpec.Name<Groups_>]: GroupSpec.WithName<\n Groups_,\n GroupName\n >;\n };\n readonly \"~Groups\": Groups_;\n\n add<Group extends GroupSpec.AnyWithProps>(\n group: Group,\n ): Spec<Groups_ | Group>;\n\n addAt<const Name extends string, Group extends GroupSpec.AnyWithProps>(\n name: Name,\n group: Group,\n ): Spec<Groups_ | GroupSpec.NamedAt<Group, Name>>;\n}\n\nexport interface Any {\n readonly [TypeId]: TypeId;\n}\n\nexport interface AnyWithProps extends Spec<GroupSpec.AnyWithProps> {}\n\nexport type Groups<Spec_ extends AnyWithProps> = Spec_[\"~Groups\"];\n\nconst Proto = {\n [TypeId]: TypeId,\n\n add<Group extends GroupSpec.AnyWithProps>(this: AnyWithProps, group: Group) {\n return makeProto({\n groups: Record.set(this.groups, group.name, group),\n });\n },\n\n addAt<Group extends GroupSpec.AnyWithProps>(\n this: AnyWithProps,\n name: string,\n group: Group,\n ) {\n return makeProto({\n groups: Record.set(this.groups, name, GroupSpec.withName(name, group)),\n });\n },\n};\n\nconst makeProto = <Groups_ extends GroupSpec.AnyWithProps>({\n groups,\n}: {\n groups: Record.ReadonlyRecord<string, Groups_>;\n}): Spec<Groups_> =>\n Object.assign(Object.create(Proto), {\n groups,\n }) as Spec<Groups_>;\n\nexport const make = (): Spec => makeProto({ groups: {} });\n"],"mappings":";;;;;;;;;;AAIA,MAAa,SAAS;AAGtB,MAAa,UAAU,MACrB,UAAU,YAAY,GAAG,MAAM;AAqCjC,MAAM,QAAQ;EACX,SAAS;CAEV,IAA8D,OAAc;EAC1E,OAAO,UAAU,EACf,QAAQ,OAAO,IAAI,KAAK,QAAQ,MAAM,MAAM,KAAK,EACnD,CAAC;CACH;CAEA,MAEE,MACA,OACA;EACA,OAAO,UAAU,EACf,QAAQ,OAAO,IAAI,KAAK,QAAQ,MAAMA,SAAmB,MAAM,KAAK,CAAC,EACvE,CAAC;CACH;AACF;AAEA,MAAM,aAAqD,EACzD,aAIA,OAAO,OAAO,OAAO,OAAO,KAAK,GAAG,EAClC,OACF,CAAC;AAEH,MAAa,aAAmB,UAAU,EAAE,QAAQ,CAAC,EAAE,CAAC"}
@@ -0,0 +1,74 @@
1
+ import * as SystemFields from "./SystemFields";
2
+ import type { TableSchemaToTableValidator } from "./SchemaToValidator";
3
+ import type { SystemFields as ConvexSystemFields, Expand, GenericTableIndexes, GenericTableSearchIndexes, GenericTableVectorIndexes, IndexTiebreakerField, SearchIndexConfig, VectorIndexConfig } from "convex/server";
4
+ import type { GenericValidator, Validator } from "convex/values";
5
+ import type * as Schema from "effect/Schema";
6
+ export declare const TypeId = "~@confect/core/Table";
7
+ export type TypeId = typeof TypeId;
8
+ export declare const isTable: (u: unknown) => u is Any;
9
+ export declare const isUnnamedTable: (u: unknown) => u is UnnamedAny;
10
+ export interface Table<Name_ extends string, TableSchema_ extends Schema.Codec<any, any>, TableValidator_ extends GenericValidator = TableSchemaToTableValidator<TableSchema_>, Indexes_ extends GenericTableIndexes = {}, SearchIndexes_ extends GenericTableSearchIndexes = {}, VectorIndexes_ extends GenericTableVectorIndexes = {}> {
11
+ readonly [TypeId]: TypeId;
12
+ readonly tableName: Name_;
13
+ readonly Fields: TableSchema_;
14
+ readonly Doc: SystemFields.ExtendWithSystemFields<Name_, TableSchema_>;
15
+ readonly indexes: Indexes_;
16
+ readonly searchIndexes: SearchIndexes_;
17
+ readonly vectorIndexes: VectorIndexes_;
18
+ readonly "~TableValidator": TableValidator_;
19
+ }
20
+ export interface Any {
21
+ readonly [TypeId]: TypeId;
22
+ readonly tableName: string;
23
+ }
24
+ export type AnyWithProps = Table<any, Schema.Codec<any, any>, GenericValidator, GenericTableIndexes, GenericTableSearchIndexes, GenericTableVectorIndexes>;
25
+ export interface UnnamedTable<TableSchema_ extends Schema.Codec<any, any>, TableValidator_ extends GenericValidator = TableSchemaToTableValidator<TableSchema_>, Indexes_ extends GenericTableIndexes = {}, SearchIndexes_ extends GenericTableSearchIndexes = {}, VectorIndexes_ extends GenericTableVectorIndexes = {}> {
26
+ <const Name_ extends string>(tableName: Name_): Table<Name_, TableSchema_, TableValidator_, Indexes_, SearchIndexes_, VectorIndexes_>;
27
+ readonly [TypeId]: TypeId;
28
+ readonly indexes: Indexes_;
29
+ readonly searchIndexes: SearchIndexes_;
30
+ readonly vectorIndexes: VectorIndexes_;
31
+ readonly "~TableValidator": TableValidator_;
32
+ index<IndexName extends string, FirstFieldPath extends ExtractFieldPaths<TableValidator_>, RestFieldPaths extends ExtractFieldPaths<TableValidator_>[]>(name: IndexName, fields: [FirstFieldPath, ...RestFieldPaths]): UnnamedTable<TableSchema_, TableValidator_, Expand<Indexes_ & Record<IndexName, [
33
+ FirstFieldPath,
34
+ ...RestFieldPaths,
35
+ IndexTiebreakerField
36
+ ]>>, SearchIndexes_, VectorIndexes_>;
37
+ searchIndex<IndexName extends string, SearchField extends ExtractFieldPaths<TableValidator_>, FilterFields extends ExtractFieldPaths<TableValidator_> = never>(name: IndexName, indexConfig: Expand<SearchIndexConfig<SearchField, FilterFields>>): UnnamedTable<TableSchema_, TableValidator_, Indexes_, Expand<SearchIndexes_ & Record<IndexName, {
38
+ searchField: SearchField;
39
+ filterFields: FilterFields;
40
+ }>>, VectorIndexes_>;
41
+ vectorIndex<IndexName extends string, VectorField extends ExtractFieldPaths<TableValidator_>, FilterFields extends ExtractFieldPaths<TableValidator_> = never>(name: IndexName, indexConfig: Expand<VectorIndexConfig<VectorField, FilterFields>>): UnnamedTable<TableSchema_, TableValidator_, Indexes_, SearchIndexes_, Expand<VectorIndexes_ & Record<IndexName, {
42
+ vectorField: VectorField;
43
+ dimensions: number;
44
+ filterFields: FilterFields;
45
+ }>>>;
46
+ }
47
+ export interface UnnamedAny {
48
+ readonly [TypeId]: TypeId;
49
+ }
50
+ export type UnnamedAnyWithProps = UnnamedTable<Schema.Codec<any, any>, GenericValidator, GenericTableIndexes, GenericTableSearchIndexes, GenericTableVectorIndexes>;
51
+ export type Name<TableDef extends AnyWithProps> = TableDef["tableName"] & string;
52
+ export type TableSchema<TableDef extends AnyWithProps> = TableDef["Fields"];
53
+ export type TableValidator<TableDef extends AnyWithProps> = TableDef["~TableValidator"];
54
+ export type Indexes<TableDef extends AnyWithProps> = TableDef["indexes"];
55
+ export type SearchIndexes<TableDef extends AnyWithProps> = TableDef["searchIndexes"];
56
+ export type VectorIndexes<TableDef extends AnyWithProps> = TableDef["vectorIndexes"];
57
+ export type Doc<TableDef extends AnyWithProps> = TableDef["Doc"];
58
+ export type Fields<TableDef extends AnyWithProps> = TableDef["Fields"];
59
+ export type WithName<TableDef extends AnyWithProps, Name_ extends string> = TableDef extends {
60
+ readonly tableName: Name_;
61
+ } ? TableDef : never;
62
+ export type TablesRecord<Tables extends AnyWithProps> = {
63
+ readonly [TableName_ in Name<Tables>]: WithName<Tables, TableName_>;
64
+ };
65
+ export declare const make: <const TableSchema_ extends Schema.Codec<any, any>>(lazyFields: () => TableSchema_) => UnnamedTable<TableSchema_, TableSchemaToTableValidator<TableSchema_>>;
66
+ /**
67
+ * Extract all of the index field paths within a Convex `Validator`.
68
+ *
69
+ * This is used when declaring table indexes.
70
+ * @public
71
+ */
72
+ type ExtractFieldPaths<T extends Validator<any, any, any>> = T["fieldPaths"] | keyof ConvexSystemFields;
73
+ export {};
74
+ //# sourceMappingURL=Table.d.ts.map
@@ -0,0 +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,I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,CAUtE,CAAC;AAIF;;;;;GAKG;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 ADDED
@@ -0,0 +1,77 @@
1
+ import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
+ import { defineProperty } from "./Lazy.js";
3
+ import { extendWithSystemFields } from "./SystemFields.js";
4
+ import * as Predicate from "effect/Predicate";
5
+ //#region src/Table.ts
6
+ var Table_exports = /* @__PURE__ */ __exportAll({
7
+ TypeId: () => TypeId,
8
+ isTable: () => isTable,
9
+ isUnnamedTable: () => isUnnamedTable,
10
+ make: () => make
11
+ });
12
+ const TypeId = "~@confect/core/Table";
13
+ const isTable = (u) => Predicate.hasProperty(u, "~@confect/core/Table") && Predicate.hasProperty(u, "tableName");
14
+ const isUnnamedTable = (u) => Predicate.hasProperty(u, "~@confect/core/Table") && !Predicate.hasProperty(u, "tableName");
15
+ const makeBound = (tableName, state) => {
16
+ const bound = {
17
+ [TypeId]: TypeId,
18
+ tableName,
19
+ indexes: state.indexes,
20
+ searchIndexes: state.searchIndexes,
21
+ vectorIndexes: state.vectorIndexes
22
+ };
23
+ defineProperty(bound, "Fields", () => state.lazyFields());
24
+ defineProperty(bound, "Doc", () => extendWithSystemFields(tableName, bound.Fields));
25
+ return bound;
26
+ };
27
+ const makeUnnamed = (state) => {
28
+ const bind = (tableName) => makeBound(tableName, state);
29
+ const index = (name, fields) => makeUnnamed({
30
+ lazyFields: state.lazyFields,
31
+ indexes: {
32
+ ...state.indexes,
33
+ [name]: fields
34
+ },
35
+ searchIndexes: state.searchIndexes,
36
+ vectorIndexes: state.vectorIndexes
37
+ });
38
+ const searchIndex = (name, indexConfig) => makeUnnamed({
39
+ lazyFields: state.lazyFields,
40
+ indexes: state.indexes,
41
+ searchIndexes: {
42
+ ...state.searchIndexes,
43
+ [name]: indexConfig
44
+ },
45
+ vectorIndexes: state.vectorIndexes
46
+ });
47
+ const vectorIndex = (name, indexConfig) => makeUnnamed({
48
+ lazyFields: state.lazyFields,
49
+ indexes: state.indexes,
50
+ searchIndexes: state.searchIndexes,
51
+ vectorIndexes: {
52
+ ...state.vectorIndexes,
53
+ [name]: indexConfig
54
+ }
55
+ });
56
+ return Object.assign(bind, {
57
+ [TypeId]: TypeId,
58
+ indexes: state.indexes,
59
+ searchIndexes: state.searchIndexes,
60
+ vectorIndexes: state.vectorIndexes,
61
+ index,
62
+ searchIndex,
63
+ vectorIndex
64
+ });
65
+ };
66
+ const make = (lazyFields) => {
67
+ return makeUnnamed({
68
+ lazyFields,
69
+ indexes: {},
70
+ searchIndexes: {},
71
+ vectorIndexes: {}
72
+ });
73
+ };
74
+ //#endregion
75
+ export { Table_exports, TypeId, isTable, isUnnamedTable, make };
76
+
77
+ //# sourceMappingURL=Table.js.map
@@ -0,0 +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"}
package/dist/Types.d.ts CHANGED
@@ -12,8 +12,14 @@ export type IsRecord<T> = [T] extends [never] ? false : IsUnion<T> extends true
12
12
  export type DeepMutable<T> = IsAny<T> extends true ? any : T extends NonRecursiveLeaf ? T : T extends ReadonlyMap<infer K, infer V> ? Map<DeepMutable<K>, DeepMutable<V>> : T extends ReadonlySet<infer V> ? Set<DeepMutable<V>> : [keyof T] extends [never] ? T : {
13
13
  -readonly [K in keyof T]: IsOptional<T, K> extends true ? DeepMutable<Exclude<T[K], undefined>> : DeepMutable<T[K]>;
14
14
  };
15
- export type TypeError<Message extends string, T = never> = [Message, T];
16
- export type TypeDefect<Message extends string, T = never> = [Message, T];
15
+ export interface TypeError<Message extends string, T = never> {
16
+ readonly "~@confect/core/Types/TypeError": Message;
17
+ readonly "~value"?: T;
18
+ }
19
+ export interface TypeDefect<Message extends string, T = never> {
20
+ readonly "~@confect/core/Types/TypeDefect": Message;
21
+ readonly "~value"?: T;
22
+ }
17
23
  export type IsRecursive<T> = true extends DetectCycle<T> ? true : false;
18
24
  type NonRecursiveLeaf = Brand.Brand<any> | GenericId<any> | ArrayBuffer;
19
25
  type DetectCycle<T, Cache extends any[] = []> = IsAny<T> extends true ? false : [T] extends [any] ? T extends NonRecursiveLeaf ? false : T extends Cache[number] ? true : T extends Array<infer U> ? DetectCycle<U, [...Cache, T]> : T extends Map<infer _U, infer V> ? DetectCycle<V, [...Cache, T]> : T extends Set<infer U> ? DetectCycle<U, [...Cache, T]> : T extends object ? true extends {
@@ -1 +1 @@
1
- {"version":3,"file":"Types.d.ts","s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E,MAAM,YAAY,KAClB,IAAI,GACL,YAAY,GACZ,KAAK,CAAC;AAEV,KAAK,OAAO,CAAC,CAAC,EAAE,IAAI,IAAI,CAAC,SAAS,IAAI,GAAG,CAAC,GAAG,IAAI,CAAC;AAMlD,MAAM,MAAM,oBAAoB,CAC9B,eAAe,SAAS,gBAAgB,EACxC,KAAK,SAAS,qBAAqB,CAAC,eAAe,CAAC,EACpD,CAAC,SAAS,MAAM,EAAE,IAChB,CAAC,SAAS,SAAS,CAAC,GAAG,MAAM,IAAI,EAAE,GAAG,CAAC,GACvC,IAAI,SAAS,SAAS,MAAM,EAAE,GAC5B;KACG,CAAC,IAAI,MAAM,IAAI,GAAG,sBAAsB,CACvC,cAAc,CAAC,eAAe,EAAE,KAAK,CAAC,EACtC,IAAI,CAAC,CAAC,CAAC,CACR;CACF,GACD,KAAK,GACP,KAAK,CAAC;AAGV,MAAM,MAAM,kBAAkB,CAAC,SAAS,SAAS,gBAAgB,IAAI;IACnE,GAAG,EAAE,qBAAqB,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,CAAC;IAC7C,KAAK,EAAE,qBAAqB,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,CAAC;CAClD,CAAC"}
package/dist/Types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Types.js","names":[],"sources":["../src/Types.ts"],"sourcesContent":["import type {\n DocumentByName,\n FieldTypeFromFieldPath,\n GenericDatabaseReader,\n GenericDataModel,\n TableNamesInDataModel,\n} from \"convex/server\";\nimport type { GenericId } from \"convex/values\";\nimport type { Brand } from \"effect\";\n\nexport type IsOptional<T, K extends keyof T> =\n {} extends Pick<T, K> ? true : false;\n\nexport type IsAny<T> = 0 extends 1 & T ? true : false;\n\nexport type IsUnion<T, U extends T = T> = T extends unknown\n ? [U] extends [T]\n ? false\n : true\n : never;\n\n// https://stackoverflow.com/a/52806744\nexport type IsValueLiteral<Vl> = [Vl] extends [never]\n ? never\n : IsUnion<Vl> extends true\n ? false\n : [Vl] extends [string | number | bigint | boolean]\n ? [string] extends [Vl]\n ? false\n : [number] extends [Vl]\n ? false\n : [boolean] extends [Vl]\n ? false\n : [bigint] extends [Vl]\n ? false\n : true\n : false;\n\n/**\n * Only checks for records with string keys.\n */\nexport type IsRecord<T> = [T] extends [never]\n ? false\n : IsUnion<T> extends true\n ? false\n : T extends Record<string, infer V>\n ? string extends keyof T\n ? keyof T extends string\n ? T extends Record<string, V>\n ? Record<string, V> extends T\n ? true\n : false\n : false\n : false\n : false\n : false;\n\nexport type DeepMutable<T> =\n IsAny<T> extends true\n ? any\n : T extends NonRecursiveLeaf\n ? T\n : T extends ReadonlyMap<infer K, infer V>\n ? Map<DeepMutable<K>, DeepMutable<V>>\n : T extends ReadonlySet<infer V>\n ? Set<DeepMutable<V>>\n : [keyof T] extends [never]\n ? T\n : {\n -readonly [K in keyof T]: IsOptional<T, K> extends true\n ? DeepMutable<Exclude<T[K], undefined>>\n : DeepMutable<T[K]>;\n };\n\nexport type TypeError<Message extends string, T = never> = [Message, T];\n\nexport type TypeDefect<Message extends string, T = never> = [Message, T];\n\nexport type IsRecursive<T> = true extends DetectCycle<T> ? true : false;\n\ntype NonRecursiveLeaf = Brand.Brand<any> | GenericId<any> | ArrayBuffer;\n\ntype DetectCycle<T, Cache extends any[] = []> =\n IsAny<T> extends true\n ? false\n : [T] extends [any]\n ? T extends NonRecursiveLeaf\n ? false\n : T extends Cache[number]\n ? true\n : T extends Array<infer U>\n ? DetectCycle<U, [...Cache, T]>\n : T extends Map<infer _U, infer V>\n ? DetectCycle<V, [...Cache, T]>\n : T extends Set<infer U>\n ? DetectCycle<U, [...Cache, T]>\n : T extends object\n ? true extends {\n [K in keyof T]: DetectCycle<T[K], [...Cache, T]>;\n }[keyof T]\n ? true\n : false\n : false\n : never;\n\n//////////////////////////////////\n// START: Vendored from Arktype //\n//////////////////////////////////\n\n// https://github.com/arktypeio/arktype/blob/2e911d01a741ccee7a17e31ee144049817fabbb8/ark/util/unionToTuple.ts#L9\n\nexport type UnionToTuple<t> =\n _unionToTuple<t, []> extends infer result ? conform<result, t[]> : never;\n\ntype _unionToTuple<t, result extends unknown[]> =\n getLastBranch<t> extends infer current\n ? [t] extends [never]\n ? result\n : _unionToTuple<Exclude<t, current>, [current, ...result]>\n : never;\n\ntype getLastBranch<t> =\n intersectUnion<t extends unknown ? (x: t) => void : never> extends (\n x: infer branch,\n ) => void\n ? branch\n : never;\n\ntype intersectUnion<t> = (t extends unknown ? (_: t) => void : never) extends (\n _: infer intersection,\n) => void\n ? intersection\n : never;\n\ntype conform<t, base> = t extends base ? t : base;\n\n////////////////////////////////\n// END: Vendored from Arktype //\n////////////////////////////////\n\nexport type IndexFieldTypesForEq<\n ConvexDataModel extends GenericDataModel,\n Table extends TableNamesInDataModel<ConvexDataModel>,\n T extends string[],\n> = T extends readonly [...infer Rest, any]\n ? Rest extends readonly string[]\n ? {\n [K in keyof Rest]: FieldTypeFromFieldPath<\n DocumentByName<ConvexDataModel, Table>,\n Rest[K]\n >;\n }\n : never\n : never;\n\n// Would prefer to use `BaseDatabaseReader` from the `convex` package, but it's not exported.\nexport type BaseDatabaseReader<DataModel extends GenericDataModel> = {\n get: GenericDatabaseReader<DataModel>[\"get\"];\n query: GenericDatabaseReader<DataModel>[\"query\"];\n};\n"],"mappings":""}
1
+ {"version":3,"file":"Types.js","names":[],"sources":["../src/Types.ts"],"sourcesContent":["import type {\n DocumentByName,\n FieldTypeFromFieldPath,\n GenericDatabaseReader,\n GenericDataModel,\n TableNamesInDataModel,\n} from \"convex/server\";\nimport type { GenericId } from \"convex/values\";\nimport type { Brand } from \"effect\";\n\nexport type IsOptional<T, K extends keyof T> =\n {} extends Pick<T, K> ? true : false;\n\nexport type IsAny<T> = 0 extends 1 & T ? true : false;\n\nexport type IsUnion<T, U extends T = T> = T extends unknown\n ? [U] extends [T]\n ? false\n : true\n : never;\n\n// https://stackoverflow.com/a/52806744\nexport type IsValueLiteral<Vl> = [Vl] extends [never]\n ? never\n : IsUnion<Vl> extends true\n ? false\n : [Vl] extends [string | number | bigint | boolean]\n ? [string] extends [Vl]\n ? false\n : [number] extends [Vl]\n ? false\n : [boolean] extends [Vl]\n ? false\n : [bigint] extends [Vl]\n ? false\n : true\n : false;\n\n/**\n * Only checks for records with string keys.\n */\nexport type IsRecord<T> = [T] extends [never]\n ? false\n : IsUnion<T> extends true\n ? false\n : T extends Record<string, infer V>\n ? string extends keyof T\n ? keyof T extends string\n ? T extends Record<string, V>\n ? Record<string, V> extends T\n ? true\n : false\n : false\n : false\n : false\n : false;\n\nexport type DeepMutable<T> =\n IsAny<T> extends true\n ? any\n : T extends NonRecursiveLeaf\n ? T\n : T extends ReadonlyMap<infer K, infer V>\n ? Map<DeepMutable<K>, DeepMutable<V>>\n : T extends ReadonlySet<infer V>\n ? Set<DeepMutable<V>>\n : [keyof T] extends [never]\n ? T\n : {\n -readonly [K in keyof T]: IsOptional<T, K> extends true\n ? DeepMutable<Exclude<T[K], undefined>>\n : DeepMutable<T[K]>;\n };\n\nexport interface TypeError<Message extends string, T = never> {\n readonly \"~@confect/core/Types/TypeError\": Message;\n readonly \"~value\"?: T;\n}\n\nexport interface TypeDefect<Message extends string, T = never> {\n readonly \"~@confect/core/Types/TypeDefect\": Message;\n readonly \"~value\"?: T;\n}\n\nexport type IsRecursive<T> = true extends DetectCycle<T> ? true : false;\n\ntype NonRecursiveLeaf = Brand.Brand<any> | GenericId<any> | ArrayBuffer;\n\ntype DetectCycle<T, Cache extends any[] = []> =\n IsAny<T> extends true\n ? false\n : [T] extends [any]\n ? T extends NonRecursiveLeaf\n ? false\n : T extends Cache[number]\n ? true\n : T extends Array<infer U>\n ? DetectCycle<U, [...Cache, T]>\n : T extends Map<infer _U, infer V>\n ? DetectCycle<V, [...Cache, T]>\n : T extends Set<infer U>\n ? DetectCycle<U, [...Cache, T]>\n : T extends object\n ? true extends {\n [K in keyof T]: DetectCycle<T[K], [...Cache, T]>;\n }[keyof T]\n ? true\n : false\n : false\n : never;\n\n//////////////////////////////////\n// START: Vendored from Arktype //\n//////////////////////////////////\n\n// https://github.com/arktypeio/arktype/blob/2e911d01a741ccee7a17e31ee144049817fabbb8/ark/util/unionToTuple.ts#L9\n\nexport type UnionToTuple<t> =\n _unionToTuple<t, []> extends infer result ? conform<result, t[]> : never;\n\ntype _unionToTuple<t, result extends unknown[]> =\n getLastBranch<t> extends infer current\n ? [t] extends [never]\n ? result\n : _unionToTuple<Exclude<t, current>, [current, ...result]>\n : never;\n\ntype getLastBranch<t> =\n intersectUnion<t extends unknown ? (x: t) => void : never> extends (\n x: infer branch,\n ) => void\n ? branch\n : never;\n\ntype intersectUnion<t> = (t extends unknown ? (_: t) => void : never) extends (\n _: infer intersection,\n) => void\n ? intersection\n : never;\n\ntype conform<t, base> = t extends base ? t : base;\n\n////////////////////////////////\n// END: Vendored from Arktype //\n////////////////////////////////\n\nexport type IndexFieldTypesForEq<\n ConvexDataModel extends GenericDataModel,\n Table extends TableNamesInDataModel<ConvexDataModel>,\n T extends string[],\n> = T extends readonly [...infer Rest, any]\n ? Rest extends readonly string[]\n ? {\n [K in keyof Rest]: FieldTypeFromFieldPath<\n DocumentByName<ConvexDataModel, Table>,\n Rest[K]\n >;\n }\n : never\n : never;\n\n// Would prefer to use `BaseDatabaseReader` from the `convex` package, but it's not exported.\nexport type BaseDatabaseReader<DataModel extends GenericDataModel> = {\n get: GenericDatabaseReader<DataModel>[\"get\"];\n query: GenericDatabaseReader<DataModel>[\"query\"];\n};\n"],"mappings":""}
package/dist/index.d.ts CHANGED
@@ -6,13 +6,16 @@ export * as GroupSpec from "./GroupSpec";
6
6
  export * as Identifier from "./Identifier";
7
7
  export * as Lazy from "./Lazy";
8
8
  export * as MiddlewareSpec from "./MiddlewareSpec";
9
+ export * as PaginationError from "./PaginationError";
9
10
  export * as PaginationOptions from "./PaginationOptions";
10
11
  export * as PaginationResult from "./PaginationResult";
11
12
  export * as Ref from "./Ref";
12
13
  export * as Refs from "./Refs";
13
14
  export * as RuntimeAndFunctionType from "./RuntimeAndFunctionType";
15
+ export * as SchemaToValidator from "./SchemaToValidator";
14
16
  export * as Spec from "./Spec";
15
17
  export * as SystemFields from "./SystemFields";
18
+ export * as Table from "./Table";
16
19
  export * as Types from "./Types";
17
20
  export * as UserIdentity from "./UserIdentity";
18
21
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,kBAAkB,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,YAAY,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC;AAC3C,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AAC/B,OAAO,KAAK,cAAc,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,iBAAiB,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,gBAAgB,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;AAC7B,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AAC/B,OAAO,KAAK,sBAAsB,MAAM,0BAA0B,CAAC;AACnE,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AAC/B,OAAO,KAAK,YAAY,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,KAAK,YAAY,MAAM,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,kBAAkB,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,YAAY,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC;AAC3C,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AAC/B,OAAO,KAAK,cAAc,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,eAAe,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,iBAAiB,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,gBAAgB,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;AAC7B,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AAC/B,OAAO,KAAK,sBAAsB,MAAM,0BAA0B,CAAC;AACnE,OAAO,KAAK,iBAAiB,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AAC/B,OAAO,KAAK,YAAY,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,KAAK,YAAY,MAAM,gBAAgB,CAAC"}
package/dist/index.js CHANGED
@@ -9,10 +9,13 @@ import { GenericId_exports } from "./GenericId.js";
9
9
  import { GroupPath_exports } from "./GroupPath.js";
10
10
  import { GroupSpec_exports } from "./GroupSpec.js";
11
11
  import { MiddlewareSpec_exports } from "./MiddlewareSpec.js";
12
+ import { PaginationError_exports } from "./PaginationError.js";
12
13
  import { Ref_exports } from "./Ref.js";
13
14
  import { Refs_exports } from "./Refs.js";
15
+ import { SchemaToValidator_exports } from "./SchemaToValidator.js";
14
16
  import { Spec_exports } from "./Spec.js";
15
17
  import { SystemFields_exports } from "./SystemFields.js";
18
+ import { Table_exports } from "./Table.js";
16
19
  import { Types_exports } from "./Types.js";
17
20
  import { UserIdentity_exports } from "./UserIdentity.js";
18
- export { FunctionProvenance_exports as FunctionProvenance, FunctionSpec_exports as FunctionSpec, GenericId_exports as GenericId, GroupPath_exports as GroupPath, GroupSpec_exports as GroupSpec, Identifier_exports as Identifier, Lazy_exports as Lazy, MiddlewareSpec_exports as MiddlewareSpec, PaginationOptions_exports as PaginationOptions, PaginationResult_exports as PaginationResult, Ref_exports as Ref, Refs_exports as Refs, RuntimeAndFunctionType_exports as RuntimeAndFunctionType, Spec_exports as Spec, SystemFields_exports as SystemFields, Types_exports as Types, UserIdentity_exports as UserIdentity };
21
+ export { FunctionProvenance_exports as FunctionProvenance, FunctionSpec_exports as FunctionSpec, GenericId_exports as GenericId, GroupPath_exports as GroupPath, GroupSpec_exports as GroupSpec, Identifier_exports as Identifier, Lazy_exports as Lazy, MiddlewareSpec_exports as MiddlewareSpec, PaginationError_exports as PaginationError, PaginationOptions_exports as PaginationOptions, PaginationResult_exports as PaginationResult, Ref_exports as Ref, Refs_exports as Refs, RuntimeAndFunctionType_exports as RuntimeAndFunctionType, SchemaToValidator_exports as SchemaToValidator, Spec_exports as Spec, SystemFields_exports as SystemFields, Table_exports as Table, Types_exports as Types, UserIdentity_exports as UserIdentity };