@confect/server 9.0.0-next.7 → 9.0.0-next.8
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 +30 -0
- package/dist/ActionCtx.d.ts +1 -1
- package/dist/ActionCtx.js +1 -1
- package/dist/ActionCtx.js.map +1 -1
- package/dist/ActionRunner.d.ts +6 -4
- package/dist/ActionRunner.d.ts.map +1 -1
- package/dist/ActionRunner.js +4 -3
- package/dist/ActionRunner.js.map +1 -1
- package/dist/Auth.d.ts +5 -3
- package/dist/Auth.d.ts.map +1 -1
- package/dist/Auth.js +5 -1
- package/dist/Auth.js.map +1 -1
- package/dist/BlobNotFoundError.d.ts +1 -1
- package/dist/BlobNotFoundError.d.ts.map +1 -1
- package/dist/BlobNotFoundError.js +1 -1
- package/dist/BlobNotFoundError.js.map +1 -1
- package/dist/ConvexConfigProvider.d.ts +1 -1
- package/dist/ConvexConfigProvider.d.ts.map +1 -1
- package/dist/ConvexConfigProvider.js +6 -1
- package/dist/ConvexConfigProvider.js.map +1 -1
- package/dist/CronJob.d.ts +3 -3
- package/dist/CronJob.d.ts.map +1 -1
- package/dist/CronJob.js +1 -1
- package/dist/CronJob.js.map +1 -1
- package/dist/CronJobs.d.ts.map +1 -1
- package/dist/CronJobs.js +11 -4
- package/dist/CronJobs.js.map +1 -1
- package/dist/DatabaseReader.d.ts +436 -435
- package/dist/DatabaseReader.d.ts.map +1 -1
- package/dist/DatabaseReader.js +2 -1
- package/dist/DatabaseReader.js.map +1 -1
- package/dist/DatabaseSchema.js +1 -1
- package/dist/DatabaseSchema.js.map +1 -1
- package/dist/DatabaseWriter.d.ts +3 -1
- package/dist/DatabaseWriter.d.ts.map +1 -1
- package/dist/DatabaseWriter.js +5 -1
- package/dist/DatabaseWriter.js.map +1 -1
- package/dist/Document.d.ts +2 -1
- package/dist/Document.d.ts.map +1 -1
- package/dist/Document.js +5 -1
- package/dist/Document.js.map +1 -1
- package/dist/FunctionImpl.d.ts +2 -1
- package/dist/FunctionImpl.d.ts.map +1 -1
- package/dist/FunctionImpl.js +4 -1
- package/dist/FunctionImpl.js.map +1 -1
- package/dist/GroupImpl.d.ts +2 -1
- package/dist/GroupImpl.d.ts.map +1 -1
- package/dist/GroupImpl.js +9 -1
- package/dist/GroupImpl.js.map +1 -1
- package/dist/Handler.d.ts +2 -2
- package/dist/HttpApi.d.ts +4 -2
- package/dist/HttpApi.d.ts.map +1 -1
- package/dist/HttpApi.js +7 -2
- package/dist/HttpApi.js.map +1 -1
- package/dist/MutationCtx.d.ts +1 -1
- package/dist/MutationCtx.js +1 -1
- package/dist/MutationCtx.js.map +1 -1
- package/dist/MutationRunner.d.ts +6 -4
- package/dist/MutationRunner.d.ts.map +1 -1
- package/dist/MutationRunner.js +4 -3
- package/dist/MutationRunner.js.map +1 -1
- package/dist/OrderedQuery.d.ts +7 -5
- package/dist/OrderedQuery.d.ts.map +1 -1
- package/dist/OrderedQuery.js +4 -1
- package/dist/OrderedQuery.js.map +1 -1
- package/dist/QueryCtx.d.ts +1 -1
- package/dist/QueryCtx.js +1 -1
- package/dist/QueryCtx.js.map +1 -1
- package/dist/QueryInitializer.d.ts +2 -1
- package/dist/QueryInitializer.d.ts.map +1 -1
- package/dist/QueryInitializer.js +5 -1
- package/dist/QueryInitializer.js.map +1 -1
- package/dist/QueryRunner.d.ts +6 -4
- package/dist/QueryRunner.d.ts.map +1 -1
- package/dist/QueryRunner.js +4 -3
- package/dist/QueryRunner.js.map +1 -1
- package/dist/RegisteredConvexFunction.d.ts +117 -115
- package/dist/RegisteredConvexFunction.d.ts.map +1 -1
- package/dist/RegisteredConvexFunction.js +6 -1
- package/dist/RegisteredConvexFunction.js.map +1 -1
- package/dist/RegisteredFunction.d.ts +8 -6
- package/dist/RegisteredFunction.d.ts.map +1 -1
- package/dist/RegisteredFunction.js +5 -1
- package/dist/RegisteredFunction.js.map +1 -1
- package/dist/RegisteredFunctions.d.ts.map +1 -1
- package/dist/RegisteredFunctions.js +2 -1
- package/dist/RegisteredFunctions.js.map +1 -1
- package/dist/RegisteredNodeFunction.d.ts.map +1 -1
- package/dist/RegisteredNodeFunction.js +3 -2
- package/dist/RegisteredNodeFunction.js.map +1 -1
- package/dist/RegistryItem.js +1 -1
- package/dist/RegistryItem.js.map +1 -1
- package/dist/Scheduler.d.ts +12 -8
- package/dist/Scheduler.d.ts.map +1 -1
- package/dist/Scheduler.js +10 -6
- package/dist/Scheduler.js.map +1 -1
- package/dist/SchemaToValidator.d.ts +4 -1
- package/dist/SchemaToValidator.d.ts.map +1 -1
- package/dist/SchemaToValidator.js +13 -1
- package/dist/SchemaToValidator.js.map +1 -1
- package/dist/StorageActionWriter.d.ts +3 -2
- package/dist/StorageActionWriter.d.ts.map +1 -1
- package/dist/StorageActionWriter.js +4 -1
- package/dist/StorageActionWriter.js.map +1 -1
- package/dist/StorageReader.d.ts +3 -2
- package/dist/StorageReader.d.ts.map +1 -1
- package/dist/StorageReader.js +5 -1
- package/dist/StorageReader.js.map +1 -1
- package/dist/StorageWriter.d.ts +3 -2
- package/dist/StorageWriter.d.ts.map +1 -1
- package/dist/StorageWriter.js +4 -1
- package/dist/StorageWriter.js.map +1 -1
- package/dist/Table.d.ts +19 -19
- package/dist/Table.d.ts.map +1 -1
- package/dist/Table.js +2 -1
- package/dist/Table.js.map +1 -1
- package/dist/TableInfo.d.ts +1 -1
- package/dist/VectorSearch.d.ts +3 -1
- package/dist/VectorSearch.d.ts.map +1 -1
- package/dist/VectorSearch.js +3 -1
- package/dist/VectorSearch.js.map +1 -1
- package/dist/internal/utils.d.ts +3 -2
- package/dist/internal/utils.d.ts.map +1 -1
- package/dist/internal/utils.js +3 -1
- package/dist/internal/utils.js.map +1 -1
- package/package.json +2 -2
- package/src/ActionCtx.ts +1 -1
- package/src/ActionRunner.ts +2 -1
- package/src/Auth.ts +5 -1
- package/src/BlobNotFoundError.ts +1 -1
- package/src/ConvexConfigProvider.ts +6 -8
- package/src/CronJob.ts +1 -1
- package/src/CronJobs.ts +8 -10
- package/src/DatabaseReader.ts +2 -1
- package/src/DatabaseSchema.ts +1 -1
- package/src/DatabaseWriter.ts +5 -1
- package/src/Document.ts +5 -1
- package/src/FunctionImpl.ts +4 -1
- package/src/GroupImpl.ts +9 -11
- package/src/HttpApi.ts +8 -9
- package/src/MutationCtx.ts +1 -1
- package/src/MutationRunner.ts +2 -1
- package/src/OrderedQuery.ts +5 -1
- package/src/QueryCtx.ts +1 -1
- package/src/QueryInitializer.ts +5 -1
- package/src/QueryRunner.ts +2 -1
- package/src/RegisteredConvexFunction.ts +6 -1
- package/src/RegisteredFunction.ts +5 -1
- package/src/RegisteredFunctions.ts +3 -1
- package/src/RegisteredNodeFunction.ts +4 -2
- package/src/RegistryItem.ts +1 -1
- package/src/Scheduler.ts +5 -1
- package/src/SchemaToValidator.ts +14 -16
- package/src/StorageActionWriter.ts +4 -1
- package/src/StorageReader.ts +5 -1
- package/src/StorageWriter.ts +4 -1
- package/src/Table.ts +2 -1
- package/src/VectorSearch.ts +3 -1
- package/src/internal/utils.ts +3 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaToValidator.js","names":["GenericId"],"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 {\n Array,\n Cause,\n Data,\n Effect,\n Exit,\n Match,\n Number,\n Option,\n type ParseResult,\n pipe,\n Predicate,\n Schema,\n SchemaAST,\n String,\n} from \"effect\";\n\nimport * as GenericId from \"@confect/core/GenericId\";\nimport type {\n IsAny,\n IsOptional,\n IsRecord,\n IsRecursive,\n IsUnion,\n TypeError,\n UnionToTuple,\n} from \"@confect/core/Types\";\n\n// Args\n\nexport const compileArgsSchema = <ConfectValue, ConvexValue>(\n argsSchema: Schema.Schema<ConfectValue, ConvexValue>,\n): PropertyValidators => {\n const ast = Schema.encodedSchema(argsSchema).ast;\n\n return pipe(\n ast,\n Match.value,\n Match.tag(\"TypeLiteral\", (typeLiteralAst) =>\n Array.isEmptyReadonlyArray(typeLiteralAst.indexSignatures)\n ? handlePropertySignatures(typeLiteralAst)\n : Effect.fail(new IndexSignaturesAreNotSupportedError()),\n ),\n Match.orElse(() => Effect.fail(new TopLevelMustBeObjectError())),\n runSyncThrow,\n );\n};\n\n// Returns\n\nexport const compileReturnsSchema = <ConfectValue, ConvexValue>(\n schema: Schema.Schema<ConfectValue, ConvexValue>,\n): Validator<any, any, any> =>\n runSyncThrow(compileAst(Schema.encodedSchema(schema).ast));\n\n// Table\n\n/**\n * Convert a table `Schema` to a table `Validator`.\n */\nexport type TableSchemaToTableValidator<\n TableSchema extends Schema.Schema.AnyNoContext,\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 = <\n TableSchema extends Schema.Schema.AnyNoContext,\n>(\n schema: TableSchema,\n): TableSchemaToTableValidator<TableSchema> => {\n const ast = Schema.encodedSchema(schema).ast;\n\n return pipe(\n ast,\n Match.value,\n Match.tag(\"TypeLiteral\", ({ indexSignatures }) =>\n Array.isEmptyReadonlyArray(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 runSyncThrow,\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<T[K]> }\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 ? {\n -readonly [K in keyof Vl]: undefined extends Vl[K]\n ? MutableValue<Exclude<Vl[K], undefined>>\n : MutableValue<Vl[K]>;\n } 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.Schema<T, E>,\n): ValueToValidator<(typeof schema)[\"Encoded\"]> =>\n runSyncThrow(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 \"BooleanKeyword\",\n \"StringKeyword\",\n \"NumberKeyword\",\n \"BigIntKeyword\",\n \"UnknownKeyword\",\n \"AnyKeyword\",\n \"Declaration\",\n \"UniqueSymbol\",\n \"SymbolKeyword\",\n \"UndefinedKeyword\",\n \"VoidKeyword\",\n \"NeverKeyword\",\n \"Enums\",\n \"TemplateLiteral\",\n \"ObjectKeyword\",\n \"Transformation\",\n () => false,\n ),\n Match.tag(\"Union\", ({ types }) =>\n Array.some(types, (type) => isRecursive(type)),\n ),\n Match.tag(\"TypeLiteral\", ({ propertySignatures }) =>\n Array.some(propertySignatures, ({ type }) => isRecursive(type)),\n ),\n Match.tag(\n \"TupleType\",\n ({ elements: optionalElements, rest: elements }) =>\n Array.some(optionalElements, (optionalElement) =>\n isRecursive(optionalElement.type),\n ) || Array.some(elements, (element) => isRecursive(element.type)),\n ),\n Match.tag(\"Refinement\", ({ from }) => isRecursive(from)),\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> =>\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.when(Match.null, () => v.null()),\n Match.exhaustive,\n Effect.succeed,\n ),\n ),\n Match.tag(\"BooleanKeyword\", () => Effect.succeed(v.boolean())),\n Match.tag(\"StringKeyword\", (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(\"NumberKeyword\", () => Effect.succeed(v.float64())),\n Match.tag(\"BigIntKeyword\", () => Effect.succeed(v.int64())),\n Match.tag(\"Union\", (unionAst) =>\n handleUnion(unionAst, isOptionalPropertyOfTypeLiteral),\n ),\n Match.tag(\"TypeLiteral\", (typeLiteralAst) =>\n handleTypeLiteral(typeLiteralAst),\n ),\n Match.tag(\"TupleType\", (tupleTypeAst) => handleTupleType(tupleTypeAst)),\n Match.tag(\"UnknownKeyword\", \"AnyKeyword\", () =>\n Effect.succeed(v.any()),\n ),\n Match.tag(\"Declaration\", (declaration) =>\n Effect.mapBoth(\n declaration.decodeUnknown(...declaration.typeParameters)(\n new ArrayBuffer(0),\n {},\n declaration,\n ) as Effect.Effect<ArrayBuffer, ParseResult.ParseIssue>,\n {\n onSuccess: () => v.bytes(),\n onFailure: () =>\n new UnsupportedSchemaTypeError({\n schemaType: declaration._tag,\n }),\n },\n ),\n ),\n Match.tag(\"Refinement\", ({ from }) => compileAst(from)),\n Match.tag(\"Suspend\", () => Effect.succeed(v.any())),\n Match.tag(\n \"UniqueSymbol\",\n \"SymbolKeyword\",\n \"UndefinedKeyword\",\n \"VoidKeyword\",\n \"NeverKeyword\",\n \"Enums\",\n \"TemplateLiteral\",\n \"ObjectKeyword\",\n \"Transformation\",\n () =>\n new UnsupportedSchemaTypeError({\n schemaType: ast._tag,\n }),\n ),\n Match.exhaustive,\n );\n\nconst handleUnion = (\n { types: [first, second, ...rest] }: SchemaAST.Union,\n isOptionalPropertyOfTypeLiteral: boolean,\n) =>\n Effect.gen(function* () {\n const validatorEffects = isOptionalPropertyOfTypeLiteral\n ? Array.filterMap([first, second, ...rest], (type) =>\n Predicate.not(SchemaAST.isUndefinedKeyword)(type)\n ? Option.some(compileAst(type))\n : Option.none(),\n )\n : Array.map([first, second, ...rest], (type) => compileAst(type));\n\n const [firstValidator, secondValidator, ...restValidators] =\n yield* Effect.all(validatorEffects);\n\n /* v8 ignore start */\n if (firstValidator === undefined) {\n return yield* Effect.dieMessage(\n \"First validator of union is undefined; this should be impossible.\",\n );\n /* v8 ignore stop */\n } else if (secondValidator === undefined) {\n return firstValidator;\n } else {\n return v.union(firstValidator, secondValidator, ...restValidators);\n }\n });\n\nconst handleTypeLiteral = (typeLiteralAst: SchemaAST.TypeLiteral) =>\n pipe(\n typeLiteralAst.indexSignatures,\n Array.head,\n Option.match({\n onNone: () =>\n Effect.map(handlePropertySignatures(typeLiteralAst), v.object),\n onSome: ({ parameter, type }) =>\n pipe(\n typeLiteralAst.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 handleTupleType = ({ elements, rest }: SchemaAST.TupleType) =>\n Effect.gen(function* () {\n const restValidator = pipe(\n rest,\n Array.head,\n Option.map(({ type }) => compileAst(type)),\n Effect.flatten,\n );\n\n const [f, s, ...r] = elements;\n\n const elementToValidator = ({ type, isOptional }: SchemaAST.OptionalType) =>\n Effect.if(isOptional, {\n onTrue: () =>\n Effect.fail(new OptionalTupleElementsAreNotSupportedError()),\n onFalse: () => compileAst(type),\n });\n\n const arrayItemsValidator = yield* f === undefined\n ? pipe(\n restValidator,\n Effect.catchTag(\"NoSuchElementException\", () =>\n Effect.fail(new EmptyTupleIsNotSupportedError()),\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 = (typeLiteralAst: SchemaAST.TypeLiteral) =>\n pipe(\n typeLiteralAst.propertySignatures,\n Effect.forEach(({ type, name, isOptional }) => {\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\nconst runSyncThrow = <A, E>(effect: Effect.Effect<A, E>) =>\n pipe(\n effect,\n Effect.runSyncExit,\n Exit.match({\n onSuccess: (validator) => validator,\n onFailure: (cause) => {\n throw Cause.squash(cause);\n },\n }),\n );\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 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":";;;;;;;;;;;;;;;;;;;;;;AAiDA,MAAa,qBACX,eACuB;CACvB,MAAM,MAAM,OAAO,cAAc,WAAW,CAAC;AAE7C,QAAO,KACL,KACA,MAAM,OACN,MAAM,IAAI,gBAAgB,mBACxB,MAAM,qBAAqB,eAAe,gBAAgB,GAC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,eAAe;CAChB,GAAG;CACJ,EACF,EACD,OAAO,QACR,CACF,CACF;AAIH,MAAM,gBAAsB,WAC1B,KACE,QACA,OAAO,aACP,KAAK,MAAM;CACT,YAAY,cAAc;CAC1B,YAAY,UAAU;AACpB,QAAM,MAAM,OAAO,MAAM;;CAE5B,CAAC,CACH;AAEH,IAAa,4BAAb,cAA+C,KAAK,YAClD,4BACD,CAAC;;CAEA,IAAa,UAAU;AACrB,SAAO;;;AAKX,IAAa,mCAAb,cAAsD,KAAK,YACzD,mCACD,CAAC;;CAEA,IAAa,UAAU;AACrB,SAAO;;;AAKX,IAAa,2CAAb,cAA8D,KAAK,YACjE,2CACD,CAEE;;CAED,IAAa,UAAU;AACrB,SAAO,mCAAmC,KAAK,YAAY,UAAU,CAAC,0BAA0B,OAAO,KAAK,YAAY;;;AAK5H,IAAa,gCAAb,cAAmD,KAAK,YACtD,gCACD,CAAC;;CAEA,IAAa,UAAU;AACrB,SAAO;;;AAKX,IAAa,6BAAb,cAAgD,KAAK,YACnD,6BACD,CAEE;;CAED,IAAa,UAAU;AACrB,SAAO,4BAA4B,KAAK,WAAW;;;AAKvD,IAAa,sCAAb,cAAyD,KAAK,YAC5D,sCACD,CAAC;;CAEA,IAAa,UAAU;AACrB,SAAO;;;AAKX,IAAa,sDAAb,cAAyE,KAAK,YAC5E,sDACD,CAAC;;CAEA,IAAa,UAAU;AACrB,SAAO;;;AAKX,IAAa,4CAAb,cAA+D,KAAK,YAClE,4CACD,CAAC;;CAEA,IAAa,UAAU;AACrB,SAAO"}
|
|
1
|
+
{"version":3,"file":"SchemaToValidator.js","names":["GenericId"],"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 type { ParseResult } from \"effect\";\nimport * as Array from \"effect/Array\";\nimport * as Cause from \"effect/Cause\";\nimport * as Data from \"effect/Data\";\nimport * as Effect from \"effect/Effect\";\nimport * as Exit from \"effect/Exit\";\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 \"@confect/core/GenericId\";\nimport type {\n IsAny,\n IsOptional,\n IsRecord,\n IsRecursive,\n IsUnion,\n TypeError,\n UnionToTuple,\n} from \"@confect/core/Types\";\n\n// Args\n\nexport const compileArgsSchema = <ConfectValue, ConvexValue>(\n argsSchema: Schema.Schema<ConfectValue, ConvexValue>,\n): PropertyValidators => {\n const ast = Schema.encodedSchema(argsSchema).ast;\n\n return pipe(\n ast,\n Match.value,\n Match.tag(\"TypeLiteral\", (typeLiteralAst) =>\n Array.isEmptyReadonlyArray(typeLiteralAst.indexSignatures)\n ? handlePropertySignatures(typeLiteralAst)\n : Effect.fail(new IndexSignaturesAreNotSupportedError()),\n ),\n Match.orElse(() => Effect.fail(new TopLevelMustBeObjectError())),\n runSyncThrow,\n );\n};\n\n// Returns\n\nexport const compileReturnsSchema = <ConfectValue, ConvexValue>(\n schema: Schema.Schema<ConfectValue, ConvexValue>,\n): Validator<any, any, any> =>\n runSyncThrow(compileAst(Schema.encodedSchema(schema).ast));\n\n// Table\n\n/**\n * Convert a table `Schema` to a table `Validator`.\n */\nexport type TableSchemaToTableValidator<\n TableSchema extends Schema.Schema.AnyNoContext,\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 = <\n TableSchema extends Schema.Schema.AnyNoContext,\n>(\n schema: TableSchema,\n): TableSchemaToTableValidator<TableSchema> => {\n const ast = Schema.encodedSchema(schema).ast;\n\n return pipe(\n ast,\n Match.value,\n Match.tag(\"TypeLiteral\", ({ indexSignatures }) =>\n Array.isEmptyReadonlyArray(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 runSyncThrow,\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<T[K]> }\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 ? {\n -readonly [K in keyof Vl]: undefined extends Vl[K]\n ? MutableValue<Exclude<Vl[K], undefined>>\n : MutableValue<Vl[K]>;\n } 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.Schema<T, E>,\n): ValueToValidator<(typeof schema)[\"Encoded\"]> =>\n runSyncThrow(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 \"BooleanKeyword\",\n \"StringKeyword\",\n \"NumberKeyword\",\n \"BigIntKeyword\",\n \"UnknownKeyword\",\n \"AnyKeyword\",\n \"Declaration\",\n \"UniqueSymbol\",\n \"SymbolKeyword\",\n \"UndefinedKeyword\",\n \"VoidKeyword\",\n \"NeverKeyword\",\n \"Enums\",\n \"TemplateLiteral\",\n \"ObjectKeyword\",\n \"Transformation\",\n () => false,\n ),\n Match.tag(\"Union\", ({ types }) =>\n Array.some(types, (type) => isRecursive(type)),\n ),\n Match.tag(\"TypeLiteral\", ({ propertySignatures }) =>\n Array.some(propertySignatures, ({ type }) => isRecursive(type)),\n ),\n Match.tag(\n \"TupleType\",\n ({ elements: optionalElements, rest: elements }) =>\n Array.some(optionalElements, (optionalElement) =>\n isRecursive(optionalElement.type),\n ) || Array.some(elements, (element) => isRecursive(element.type)),\n ),\n Match.tag(\"Refinement\", ({ from }) => isRecursive(from)),\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> =>\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.when(Match.null, () => v.null()),\n Match.exhaustive,\n Effect.succeed,\n ),\n ),\n Match.tag(\"BooleanKeyword\", () => Effect.succeed(v.boolean())),\n Match.tag(\"StringKeyword\", (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(\"NumberKeyword\", () => Effect.succeed(v.float64())),\n Match.tag(\"BigIntKeyword\", () => Effect.succeed(v.int64())),\n Match.tag(\"Union\", (unionAst) =>\n handleUnion(unionAst, isOptionalPropertyOfTypeLiteral),\n ),\n Match.tag(\"TypeLiteral\", (typeLiteralAst) =>\n handleTypeLiteral(typeLiteralAst),\n ),\n Match.tag(\"TupleType\", (tupleTypeAst) => handleTupleType(tupleTypeAst)),\n Match.tag(\"UnknownKeyword\", \"AnyKeyword\", () =>\n Effect.succeed(v.any()),\n ),\n Match.tag(\"Declaration\", (declaration) =>\n Effect.mapBoth(\n declaration.decodeUnknown(...declaration.typeParameters)(\n new ArrayBuffer(0),\n {},\n declaration,\n ) as Effect.Effect<ArrayBuffer, ParseResult.ParseIssue>,\n {\n onSuccess: () => v.bytes(),\n onFailure: () =>\n new UnsupportedSchemaTypeError({\n schemaType: declaration._tag,\n }),\n },\n ),\n ),\n Match.tag(\"Refinement\", ({ from }) => compileAst(from)),\n Match.tag(\"Suspend\", () => Effect.succeed(v.any())),\n Match.tag(\n \"UniqueSymbol\",\n \"SymbolKeyword\",\n \"UndefinedKeyword\",\n \"VoidKeyword\",\n \"NeverKeyword\",\n \"Enums\",\n \"TemplateLiteral\",\n \"ObjectKeyword\",\n \"Transformation\",\n () =>\n new UnsupportedSchemaTypeError({\n schemaType: ast._tag,\n }),\n ),\n Match.exhaustive,\n );\n\nconst handleUnion = (\n { types: [first, second, ...rest] }: SchemaAST.Union,\n isOptionalPropertyOfTypeLiteral: boolean,\n) =>\n Effect.gen(function* () {\n const validatorEffects = isOptionalPropertyOfTypeLiteral\n ? Array.filterMap([first, second, ...rest], (type) =>\n Predicate.not(SchemaAST.isUndefinedKeyword)(type)\n ? Option.some(compileAst(type))\n : Option.none(),\n )\n : Array.map([first, second, ...rest], (type) => compileAst(type));\n\n const [firstValidator, secondValidator, ...restValidators] =\n yield* Effect.all(validatorEffects);\n\n /* v8 ignore start */\n if (firstValidator === undefined) {\n return yield* Effect.dieMessage(\n \"First validator of union is undefined; this should be impossible.\",\n );\n /* v8 ignore stop */\n } else if (secondValidator === undefined) {\n return firstValidator;\n } else {\n return v.union(firstValidator, secondValidator, ...restValidators);\n }\n });\n\nconst handleTypeLiteral = (typeLiteralAst: SchemaAST.TypeLiteral) =>\n pipe(\n typeLiteralAst.indexSignatures,\n Array.head,\n Option.match({\n onNone: () =>\n Effect.map(handlePropertySignatures(typeLiteralAst), v.object),\n onSome: ({ parameter, type }) =>\n pipe(\n typeLiteralAst.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 handleTupleType = ({ elements, rest }: SchemaAST.TupleType) =>\n Effect.gen(function* () {\n const restValidator = pipe(\n rest,\n Array.head,\n Option.map(({ type }) => compileAst(type)),\n Effect.flatten,\n );\n\n const [f, s, ...r] = elements;\n\n const elementToValidator = ({ type, isOptional }: SchemaAST.OptionalType) =>\n Effect.if(isOptional, {\n onTrue: () =>\n Effect.fail(new OptionalTupleElementsAreNotSupportedError()),\n onFalse: () => compileAst(type),\n });\n\n const arrayItemsValidator = yield* f === undefined\n ? pipe(\n restValidator,\n Effect.catchTag(\"NoSuchElementException\", () =>\n Effect.fail(new EmptyTupleIsNotSupportedError()),\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 = (typeLiteralAst: SchemaAST.TypeLiteral) =>\n pipe(\n typeLiteralAst.propertySignatures,\n Effect.forEach(({ type, name, isOptional }) => {\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\nconst runSyncThrow = <A, E>(effect: Effect.Effect<A, E>) =>\n pipe(\n effect,\n Effect.runSyncExit,\n Exit.match({\n onSuccess: (validator) => validator,\n onFailure: (cause) => {\n throw Cause.squash(cause);\n },\n }),\n );\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 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,MAAa,qBACX,eACuB;CACvB,MAAM,MAAM,OAAO,cAAc,WAAW,CAAC;AAE7C,QAAO,KACL,KACA,MAAM,OACN,MAAM,IAAI,gBAAgB,mBACxB,MAAM,qBAAqB,eAAe,gBAAgB,GACtD,yBAAyB,eAAe,GACxC,OAAO,KAAK,IAAI,qCAAqC,CAAC,CAC3D,EACD,MAAM,aAAa,OAAO,KAAK,IAAI,2BAA2B,CAAC,CAAC,EAChE,aACD;;AAKH,MAAa,wBACX,WAEA,aAAa,WAAW,OAAO,cAAc,OAAO,CAAC,IAAI,CAAC;AAgB5D,MAAa,sBAGX,WAC6C;CAC7C,MAAM,MAAM,OAAO,cAAc,OAAO,CAAC;AAEzC,QAAO,KACL,KACA,MAAM,OACN,MAAM,IAAI,gBAAgB,EAAE,sBAC1B,MAAM,qBAAqB,gBAAgB,GACtC,WAAW,IAAI,GAChB,OAAO,KAAK,IAAI,qCAAqC,CAAC,CAC3D,EACD,MAAM,IAAI,UAAU,aAAa,WAAW,SAAS,CAAC,EACtD,MAAM,aAAa,OAAO,KAAK,IAAI,kCAAkC,CAAC,CAAC,EACvE,aACD;;AA0JH,MAAa,iBACX,WAEA,aAAa,WAAW,OAAO,IAAI,CAAC;AAEtC,MAAa,eAAe,QAC1B,KACE,KACA,MAAM,OACN,MAAM,IACJ,WACA,kBACA,iBACA,iBACA,iBACA,kBACA,cACA,eACA,gBACA,iBACA,oBACA,eACA,gBACA,SACA,mB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sCACD,CAAC;;CAEA,IAAa,UAAU;AACrB,SAAO;;;AAKX,IAAa,sDAAb,cAAyE,KAAK,YAC5E,sDACD,CAAC;;CAEA,IAAa,UAAU;AACrB,SAAO;;;AAKX,IAAa,4CAAb,cAA+D,KAAK,YAClE,4CACD,CAAC;;CAEA,IAAa,UAAU;AACrB,SAAO"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { BlobNotFoundError } from "./BlobNotFoundError.js";
|
|
2
|
-
import
|
|
2
|
+
import * as effect_Context0 from "effect/Context";
|
|
3
3
|
import { StorageActionWriter as StorageActionWriter$1 } from "convex/server";
|
|
4
|
+
import * as Layer from "effect/Layer";
|
|
5
|
+
import * as Effect from "effect/Effect";
|
|
4
6
|
import { GenericId } from "convex/values";
|
|
5
|
-
import * as effect_Context0 from "effect/Context";
|
|
6
7
|
import * as effect_Cause0 from "effect/Cause";
|
|
7
8
|
|
|
8
9
|
//#region src/StorageActionWriter.d.ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StorageActionWriter.d.ts","names":[],"sources":["../src/StorageActionWriter.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"StorageActionWriter.d.ts","names":[],"sources":["../src/StorageActionWriter.ts"],"mappings":";;;;;;;;;;;;cAMwD,wBAAA,EAeL,eAAA,CAAA,QAAA;mBAZhC,SAAA,iBAAqB,MAAA,CAAA,MAAA,CAAA,IAAA,EAAA,iBAAA;gBAYxB,IAAA,EAAI,OAAA;IAAc,MAAA;EAAA,MAAiB,MAAA,CAAA,MAAA,CAAA,SAAA;AAAA;mBAZhC,SAAA,iBAAqB,MAAA,CAAA,MAAA,CAAA,IAAA,EAAA,iBAAA;gBAYxB,IAAA,EAAI,OAAA;IAAc,MAAA;EAAA,MAAiB,MAAA,CAAA,MAAA,CAAA,SAAA;AAAA;;qBAZhC,SAAA,iBAAqB,MAAA,CAAA,MAAA,CAAA,IAAA,EAAA,iBAAA;kBAYxB,IAAA,EAAI,OAAA;MAAc,MAAA;IAAA,MAAiB,MAAA,CAAA,MAAA,CAAA,SAAA;EAAA;;cAItC,mBAAA,SAA4B,wBAAA;EAAA,gBAGvB,KAAA,GAAS,mBAAA,EAAqB,qBAAA,KAAyB,KAAA,CAAA,KAAA,CAAA,mBAAA;AAAA"}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
2
|
import { BlobNotFoundError } from "./BlobNotFoundError.js";
|
|
3
|
-
import
|
|
3
|
+
import * as Layer from "effect/Layer";
|
|
4
|
+
import { flow } from "effect/Function";
|
|
5
|
+
import * as Effect from "effect/Effect";
|
|
6
|
+
import * as Option from "effect/Option";
|
|
4
7
|
|
|
5
8
|
//#region src/StorageActionWriter.ts
|
|
6
9
|
var StorageActionWriter_exports = /* @__PURE__ */ __exportAll({ StorageActionWriter: () => StorageActionWriter });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StorageActionWriter.js","names":[],"sources":["../src/StorageActionWriter.ts"],"sourcesContent":["import type { StorageActionWriter as ConvexStorageActionWriter } from \"convex/server\";\nimport type { GenericId } from \"convex/values\";\nimport { Effect
|
|
1
|
+
{"version":3,"file":"StorageActionWriter.js","names":[],"sources":["../src/StorageActionWriter.ts"],"sourcesContent":["import type { StorageActionWriter as ConvexStorageActionWriter } from \"convex/server\";\nimport type { GenericId } from \"convex/values\";\nimport { flow } from \"effect/Function\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\nimport * as Option from \"effect/Option\";\nimport { BlobNotFoundError } from \"./BlobNotFoundError\";\n\nconst make = (storageActionWriter: ConvexStorageActionWriter) => ({\n get: (storageId: GenericId<\"_storage\">) =>\n Effect.promise(() => storageActionWriter.get(storageId)).pipe(\n Effect.andThen(\n flow(\n Option.fromNullable,\n Option.match({\n onNone: () => Effect.fail(new BlobNotFoundError({ id: storageId })),\n onSome: Effect.succeed,\n }),\n ),\n ),\n ),\n store: (blob: Blob, options?: { sha256?: string }) =>\n Effect.promise(() => storageActionWriter.store(blob, options)),\n});\n\nexport class StorageActionWriter extends Effect.Tag(\n \"@confect/server/StorageActionWriter\",\n)<StorageActionWriter, ReturnType<typeof make>>() {\n static readonly layer = (storageActionWriter: ConvexStorageActionWriter) =>\n Layer.succeed(this, make(storageActionWriter));\n}\n"],"mappings":";;;;;;;;;AAQA,MAAM,QAAQ,yBAAoD;CAChE,MAAM,cACJ,OAAO,cAAc,oBAAoB,IAAI,UAAU,CAAC,CAAC,KACvD,OAAO,QACL,KACE,OAAO,cACP,OAAO,MAAM;EACX,cAAc,OAAO,KAAK,IAAI,kBAAkB,EAAE,IAAI,WAAW,CAAC,CAAC;EACnE,QAAQ,OAAO;EAChB,CAAC,CACH,CACF,CACF;CACH,QAAQ,MAAY,YAClB,OAAO,cAAc,oBAAoB,MAAM,MAAM,QAAQ,CAAC;CACjE;AAED,IAAa,sBAAb,cAAyC,OAAO,IAC9C,sCACD,EAAgD,CAAC;CAChD,OAAgB,SAAS,wBACvB,MAAM,QAAQ,MAAM,KAAK,oBAAoB,CAAC"}
|
package/dist/StorageReader.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { BlobNotFoundError } from "./BlobNotFoundError.js";
|
|
2
|
-
import
|
|
2
|
+
import * as effect_Context0 from "effect/Context";
|
|
3
3
|
import { StorageReader as StorageReader$1 } from "convex/server";
|
|
4
|
+
import * as Layer from "effect/Layer";
|
|
5
|
+
import * as Effect from "effect/Effect";
|
|
4
6
|
import { GenericId } from "convex/values";
|
|
5
|
-
import * as effect_Context0 from "effect/Context";
|
|
6
7
|
import * as effect_Cause0 from "effect/Cause";
|
|
7
8
|
|
|
8
9
|
//#region src/StorageReader.d.ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StorageReader.d.ts","names":[],"sources":["../src/StorageReader.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"StorageReader.d.ts","names":[],"sources":["../src/StorageReader.ts"],"mappings":";;;;;;;;;;;;cAOwD,kBAAA,EAGb,eAAA,CAAA,QAAA;sBAArB,SAAA,iBAAqB,MAAA,CAAA,MAAA,CAAA,GAAA,EAAA,iBAAA;AAAA;sBAArB,SAAA,iBAAqB,MAAA,CAAA,MAAA,CAAA,GAAA,EAAA,iBAAA;AAAA;;wBAArB,SAAA,iBAAqB,MAAA,CAAA,MAAA,CAAA,GAAA,EAAA,iBAAA;EAAA;;cAc9B,aAAA,SAAsB,kBAAA;EAAA,gBAIjB,KAAA,GAAS,aAAA,EAAe,eAAA,KAAmB,KAAA,CAAA,KAAA,CAAA,aAAA;AAAA"}
|
package/dist/StorageReader.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
2
|
import { BlobNotFoundError } from "./BlobNotFoundError.js";
|
|
3
|
-
import
|
|
3
|
+
import * as Layer from "effect/Layer";
|
|
4
|
+
import { flow, pipe } from "effect/Function";
|
|
5
|
+
import * as Effect from "effect/Effect";
|
|
6
|
+
import * as Option from "effect/Option";
|
|
7
|
+
import * as Schema from "effect/Schema";
|
|
4
8
|
|
|
5
9
|
//#region src/StorageReader.ts
|
|
6
10
|
var StorageReader_exports = /* @__PURE__ */ __exportAll({ StorageReader: () => StorageReader });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StorageReader.js","names":[],"sources":["../src/StorageReader.ts"],"sourcesContent":["import type { StorageReader as ConvexStorageReader } from \"convex/server\";\nimport type { GenericId } from \"convex/values\";\nimport {
|
|
1
|
+
{"version":3,"file":"StorageReader.js","names":[],"sources":["../src/StorageReader.ts"],"sourcesContent":["import type { StorageReader as ConvexStorageReader } from \"convex/server\";\nimport type { GenericId } from \"convex/values\";\nimport { flow, pipe } from \"effect/Function\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\nimport * as Option from \"effect/Option\";\nimport * as Schema from \"effect/Schema\";\nimport { BlobNotFoundError } from \"./BlobNotFoundError\";\n\nconst make = (storageReader: ConvexStorageReader) => ({\n getUrl: (storageId: GenericId<\"_storage\">) =>\n Effect.promise(() => storageReader.getUrl(storageId)).pipe(\n Effect.andThen(\n flow(\n Option.fromNullable,\n Option.match({\n onNone: () => Effect.fail(new BlobNotFoundError({ id: storageId })),\n onSome: (doc) => pipe(doc, Schema.decode(Schema.URL), Effect.orDie),\n }),\n ),\n ),\n ),\n});\n\nexport class StorageReader extends Effect.Tag(\"@confect/server/StorageReader\")<\n StorageReader,\n ReturnType<typeof make>\n>() {\n static readonly layer = (storageReader: ConvexStorageReader) =>\n Layer.succeed(this, make(storageReader));\n}\n"],"mappings":";;;;;;;;;;AASA,MAAM,QAAQ,mBAAwC,EACpD,SAAS,cACP,OAAO,cAAc,cAAc,OAAO,UAAU,CAAC,CAAC,KACpD,OAAO,QACL,KACE,OAAO,cACP,OAAO,MAAM;CACX,cAAc,OAAO,KAAK,IAAI,kBAAkB,EAAE,IAAI,WAAW,CAAC,CAAC;CACnE,SAAS,QAAQ,KAAK,KAAK,OAAO,OAAO,OAAO,IAAI,EAAE,OAAO,MAAM;CACpE,CAAC,CACH,CACF,CACF,EACJ;AAED,IAAa,gBAAb,cAAmC,OAAO,IAAI,gCAAgC,EAG3E,CAAC;CACF,OAAgB,SAAS,kBACvB,MAAM,QAAQ,MAAM,KAAK,cAAc,CAAC"}
|
package/dist/StorageWriter.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { BlobNotFoundError } from "./BlobNotFoundError.js";
|
|
2
|
-
import
|
|
2
|
+
import * as effect_Context0 from "effect/Context";
|
|
3
3
|
import { StorageWriter as StorageWriter$1 } from "convex/server";
|
|
4
|
+
import * as Layer from "effect/Layer";
|
|
5
|
+
import * as Effect from "effect/Effect";
|
|
4
6
|
import { GenericId } from "convex/values";
|
|
5
|
-
import * as effect_Context0 from "effect/Context";
|
|
6
7
|
import * as effect_Cause0 from "effect/Cause";
|
|
7
8
|
|
|
8
9
|
//#region src/StorageWriter.d.ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StorageWriter.d.ts","names":[],"sources":["../src/StorageWriter.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"StorageWriter.d.ts","names":[],"sources":["../src/StorageWriter.ts"],"mappings":";;;;;;;;;;;;cAMwD,kBAAA,EASb,eAAA,CAAA,QAAA;;sBAArB,SAAA,iBAAqB,MAAA,CAAA,MAAA,OAAA,iBAAA;AAAA;;sBAArB,SAAA,iBAAqB,MAAA,CAAA,MAAA,OAAA,iBAAA;AAAA;;;wBAArB,SAAA,iBAAqB,MAAA,CAAA,MAAA,OAAA,iBAAA;EAAA;;cAO9B,aAAA,SAAsB,kBAAA;EAAA,gBAIjB,KAAA,GAAS,aAAA,EAAe,eAAA,KAAmB,KAAA,CAAA,KAAA,CAAA,aAAA;AAAA"}
|
package/dist/StorageWriter.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
2
|
import { BlobNotFoundError } from "./BlobNotFoundError.js";
|
|
3
|
-
import
|
|
3
|
+
import * as Layer from "effect/Layer";
|
|
4
|
+
import { pipe } from "effect/Function";
|
|
5
|
+
import * as Effect from "effect/Effect";
|
|
6
|
+
import * as Schema from "effect/Schema";
|
|
4
7
|
|
|
5
8
|
//#region src/StorageWriter.ts
|
|
6
9
|
var StorageWriter_exports = /* @__PURE__ */ __exportAll({ StorageWriter: () => StorageWriter });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StorageWriter.js","names":[],"sources":["../src/StorageWriter.ts"],"sourcesContent":["import type { StorageWriter as ConvexStorageWriter } from \"convex/server\";\nimport type { GenericId } from \"convex/values\";\nimport { Effect
|
|
1
|
+
{"version":3,"file":"StorageWriter.js","names":[],"sources":["../src/StorageWriter.ts"],"sourcesContent":["import type { StorageWriter as ConvexStorageWriter } from \"convex/server\";\nimport type { GenericId } from \"convex/values\";\nimport { pipe } from \"effect/Function\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\nimport * as Schema from \"effect/Schema\";\nimport { BlobNotFoundError } from \"./BlobNotFoundError\";\n\nconst make = (storageWriter: ConvexStorageWriter) => ({\n generateUploadUrl: () =>\n Effect.promise(() => storageWriter.generateUploadUrl()).pipe(\n Effect.andThen((url) =>\n pipe(url, Schema.decode(Schema.URL), Effect.orDie),\n ),\n ),\n delete: (storageId: GenericId<\"_storage\">) =>\n Effect.tryPromise({\n try: () => storageWriter.delete(storageId),\n catch: () => new BlobNotFoundError({ id: storageId }),\n }),\n});\n\nexport class StorageWriter extends Effect.Tag(\"@confect/server/StorageWriter\")<\n StorageWriter,\n ReturnType<typeof make>\n>() {\n static readonly layer = (storageWriter: ConvexStorageWriter) =>\n Layer.succeed(this, make(storageWriter));\n}\n"],"mappings":";;;;;;;;;AAQA,MAAM,QAAQ,mBAAwC;CACpD,yBACE,OAAO,cAAc,cAAc,mBAAmB,CAAC,CAAC,KACtD,OAAO,SAAS,QACd,KAAK,KAAK,OAAO,OAAO,OAAO,IAAI,EAAE,OAAO,MAAM,CACnD,CACF;CACH,SAAS,cACP,OAAO,WAAW;EAChB,WAAW,cAAc,OAAO,UAAU;EAC1C,aAAa,IAAI,kBAAkB,EAAE,IAAI,WAAW,CAAC;EACtD,CAAC;CACL;AAED,IAAa,gBAAb,cAAmC,OAAO,IAAI,gCAAgC,EAG3E,CAAC;CACF,OAAgB,SAAS,kBACvB,MAAM,QAAQ,MAAM,KAAK,cAAc,CAAC"}
|
package/dist/Table.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TableSchemaToTableValidator } from "./SchemaToValidator.js";
|
|
2
|
-
import { Schema } from "effect";
|
|
3
2
|
import { Expand, GenericTableIndexes, GenericTableSearchIndexes, GenericTableVectorIndexes, IndexTiebreakerField, SearchIndexConfig, SystemFields, TableDefinition, VectorIndexConfig } from "convex/server";
|
|
3
|
+
import * as Schema from "effect/Schema";
|
|
4
4
|
import * as SystemFields$1 from "@confect/core/SystemFields";
|
|
5
5
|
import * as convex_values0 from "convex/values";
|
|
6
6
|
import { GenericValidator, Validator } from "convex/values";
|
|
@@ -78,8 +78,8 @@ declare const scheduledFunctionsTable: Table<"_scheduled_functions", Schema.Stru
|
|
|
78
78
|
kind: Schema.Literal<["canceled"]>;
|
|
79
79
|
}>]>;
|
|
80
80
|
}>, convex_values0.VObject<{
|
|
81
|
-
args: any[];
|
|
82
81
|
name: string;
|
|
82
|
+
args: any[];
|
|
83
83
|
scheduledTime: number;
|
|
84
84
|
state: {
|
|
85
85
|
kind: "pending";
|
|
@@ -88,15 +88,15 @@ declare const scheduledFunctionsTable: Table<"_scheduled_functions", Schema.Stru
|
|
|
88
88
|
} | {
|
|
89
89
|
kind: "success";
|
|
90
90
|
} | {
|
|
91
|
-
error: string;
|
|
92
91
|
kind: "failed";
|
|
92
|
+
error: string;
|
|
93
93
|
} | {
|
|
94
94
|
kind: "canceled";
|
|
95
95
|
};
|
|
96
96
|
completedTime?: number;
|
|
97
97
|
}, {
|
|
98
|
-
args: convex_values0.VArray<any[], convex_values0.VAny<any, "required", string>, "required">;
|
|
99
98
|
name: convex_values0.VString<string, "required">;
|
|
99
|
+
args: convex_values0.VArray<any[], convex_values0.VAny<any, "required", string>, "required">;
|
|
100
100
|
scheduledTime: convex_values0.VFloat64<number, "required">;
|
|
101
101
|
state: convex_values0.VUnion<{
|
|
102
102
|
kind: "pending";
|
|
@@ -105,8 +105,8 @@ declare const scheduledFunctionsTable: Table<"_scheduled_functions", Schema.Stru
|
|
|
105
105
|
} | {
|
|
106
106
|
kind: "success";
|
|
107
107
|
} | {
|
|
108
|
-
error: string;
|
|
109
108
|
kind: "failed";
|
|
109
|
+
error: string;
|
|
110
110
|
} | {
|
|
111
111
|
kind: "canceled";
|
|
112
112
|
}, [convex_values0.VObject<{
|
|
@@ -122,18 +122,18 @@ declare const scheduledFunctionsTable: Table<"_scheduled_functions", Schema.Stru
|
|
|
122
122
|
}, {
|
|
123
123
|
kind: convex_values0.VLiteral<"success", "required">;
|
|
124
124
|
}, "required", "kind">, convex_values0.VObject<{
|
|
125
|
-
error: string;
|
|
126
125
|
kind: "failed";
|
|
126
|
+
error: string;
|
|
127
127
|
}, {
|
|
128
|
-
error: convex_values0.VString<string, "required">;
|
|
129
128
|
kind: convex_values0.VLiteral<"failed", "required">;
|
|
130
|
-
|
|
129
|
+
error: convex_values0.VString<string, "required">;
|
|
130
|
+
}, "required", "kind" | "error">, convex_values0.VObject<{
|
|
131
131
|
kind: "canceled";
|
|
132
132
|
}, {
|
|
133
133
|
kind: convex_values0.VLiteral<"canceled", "required">;
|
|
134
|
-
}, "required", "kind">], "required", "
|
|
134
|
+
}, "required", "kind">], "required", "kind" | "error">;
|
|
135
135
|
completedTime: convex_values0.VFloat64<number | undefined, "optional">;
|
|
136
|
-
}, "required", "
|
|
136
|
+
}, "required", "name" | "args" | "scheduledTime" | "completedTime" | "state" | "state.kind" | "state.error">, {}, {}, {}>;
|
|
137
137
|
declare const storageTable: Table<"_storage", Schema.Struct<{
|
|
138
138
|
sha256: typeof Schema.String;
|
|
139
139
|
size: typeof Schema.Number;
|
|
@@ -170,8 +170,8 @@ declare const systemTables: {
|
|
|
170
170
|
kind: Schema.Literal<["canceled"]>;
|
|
171
171
|
}>]>;
|
|
172
172
|
}>, convex_values0.VObject<{
|
|
173
|
-
args: any[];
|
|
174
173
|
name: string;
|
|
174
|
+
args: any[];
|
|
175
175
|
scheduledTime: number;
|
|
176
176
|
state: {
|
|
177
177
|
kind: "pending";
|
|
@@ -180,15 +180,15 @@ declare const systemTables: {
|
|
|
180
180
|
} | {
|
|
181
181
|
kind: "success";
|
|
182
182
|
} | {
|
|
183
|
-
error: string;
|
|
184
183
|
kind: "failed";
|
|
184
|
+
error: string;
|
|
185
185
|
} | {
|
|
186
186
|
kind: "canceled";
|
|
187
187
|
};
|
|
188
188
|
completedTime?: number;
|
|
189
189
|
}, {
|
|
190
|
-
args: convex_values0.VArray<any[], convex_values0.VAny<any, "required", string>, "required">;
|
|
191
190
|
name: convex_values0.VString<string, "required">;
|
|
191
|
+
args: convex_values0.VArray<any[], convex_values0.VAny<any, "required", string>, "required">;
|
|
192
192
|
scheduledTime: convex_values0.VFloat64<number, "required">;
|
|
193
193
|
state: convex_values0.VUnion<{
|
|
194
194
|
kind: "pending";
|
|
@@ -197,8 +197,8 @@ declare const systemTables: {
|
|
|
197
197
|
} | {
|
|
198
198
|
kind: "success";
|
|
199
199
|
} | {
|
|
200
|
-
error: string;
|
|
201
200
|
kind: "failed";
|
|
201
|
+
error: string;
|
|
202
202
|
} | {
|
|
203
203
|
kind: "canceled";
|
|
204
204
|
}, [convex_values0.VObject<{
|
|
@@ -214,18 +214,18 @@ declare const systemTables: {
|
|
|
214
214
|
}, {
|
|
215
215
|
kind: convex_values0.VLiteral<"success", "required">;
|
|
216
216
|
}, "required", "kind">, convex_values0.VObject<{
|
|
217
|
-
error: string;
|
|
218
217
|
kind: "failed";
|
|
218
|
+
error: string;
|
|
219
219
|
}, {
|
|
220
|
-
error: convex_values0.VString<string, "required">;
|
|
221
220
|
kind: convex_values0.VLiteral<"failed", "required">;
|
|
222
|
-
|
|
221
|
+
error: convex_values0.VString<string, "required">;
|
|
222
|
+
}, "required", "kind" | "error">, convex_values0.VObject<{
|
|
223
223
|
kind: "canceled";
|
|
224
224
|
}, {
|
|
225
225
|
kind: convex_values0.VLiteral<"canceled", "required">;
|
|
226
|
-
}, "required", "kind">], "required", "
|
|
226
|
+
}, "required", "kind">], "required", "kind" | "error">;
|
|
227
227
|
completedTime: convex_values0.VFloat64<number | undefined, "optional">;
|
|
228
|
-
}, "required", "
|
|
228
|
+
}, "required", "name" | "args" | "scheduledTime" | "completedTime" | "state" | "state.kind" | "state.error">, {}, {}, {}>;
|
|
229
229
|
readonly _storage: Table<"_storage", Schema.Struct<{
|
|
230
230
|
sha256: typeof Schema.String;
|
|
231
231
|
size: typeof Schema.Number;
|
package/dist/Table.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Table.d.ts","names":[],"sources":["../src/Table.ts"],"mappings":";;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"Table.d.ts","names":[],"sources":["../src/Table.ts"],"mappings":";;;;;;;;;;;cAsBa,MAAA;AAAA,KACD,MAAA,UAAgB,MAAA;AAAA,cAaf,OAAA,GAAW,CAAA,cAAa,CAAA,IAAK,GAAA;AAAA,cAG7B,cAAA,GAAkB,CAAA,cAAa,CAAA,IAAK,UAAA;AAAA,UAOhC,KAAA,4CAEM,MAAA,CAAO,MAAA,CAAO,YAAA,0BACX,gBAAA,GACtB,2BAAA,CAA4B,YAAA,oBACb,mBAAA,8BACM,yBAAA,8BACA,yBAAA;EAAA,UAEb,MAAA,GAAS,MAAA;EAAA,SACV,SAAA,EAAW,KAAA;EAAA,SACX,eAAA,EAAiB,eAAA,CACxB,eAAA,EACA,QAAA,EACA,cAAA,EACA,cAAA;EAAA,SAEO,MAAA,EAAQ,YAAA;EAAA,SACR,GAAA,EAAK,cAAA,CAAa,sBAAA,CAAuB,KAAA,EAAO,YAAA;EAAA,SAChD,OAAA,EAAS,QAAA;AAAA;AAAA,UAGH,GAAA;EAAA,UACL,MAAA,GAAS,MAAA;EAAA,SACV,SAAA;AAAA;AAAA,KAGC,YAAA,GAAe,KAAA,MAEzB,MAAA,CAAO,MAAA,CAAO,YAAA,EACd,gBAAA,EACA,mBAAA,EACA,yBAAA,EACA,yBAAA;AAAA,UAgBe,YAAA,sBACM,MAAA,CAAO,MAAA,CAAO,YAAA,0BACX,gBAAA,GACtB,2BAAA,CAA4B,YAAA,oBACb,mBAAA,8BACM,yBAAA,8BACA,yBAAA;EAAA,6BAGrB,SAAA,EAAW,KAAA,GACV,KAAA,CACD,KAAA,EACA,YAAA,EACA,eAAA,EACA,QAAA,EACA,cAAA,EACA,cAAA;EAAA,UAGQ,MAAA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A,UAAiC,YAAA;;;;;;;KAU9D,iBAAA,WAA4B,SAAA,mBAI/B,CAAA,uBAAwB,YAAA"}
|
package/dist/Table.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
2
|
import { compileTableSchema } from "./SchemaToValidator.js";
|
|
3
|
-
import { Predicate, Schema } from "effect";
|
|
4
3
|
import { defineTable } from "convex/server";
|
|
4
|
+
import * as Schema from "effect/Schema";
|
|
5
|
+
import * as Predicate from "effect/Predicate";
|
|
5
6
|
import * as SystemFields$1 from "@confect/core/SystemFields";
|
|
6
7
|
import * as Lazy from "@confect/core/Lazy";
|
|
7
8
|
|
package/dist/Table.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Table.js","names":["SystemFields"],"sources":["../src/Table.ts"],"sourcesContent":["import * as Lazy from \"@confect/core/Lazy\";\nimport * as SystemFields from \"@confect/core/SystemFields\";\nimport {\n defineTable,\n type SystemFields as ConvexSystemFields,\n type Expand,\n type GenericTableIndexes,\n type GenericTableSearchIndexes,\n type GenericTableVectorIndexes,\n type IndexTiebreakerField,\n type SearchIndexConfig,\n type TableDefinition,\n type VectorIndexConfig,\n} from \"convex/server\";\nimport type { GenericValidator, Validator } from \"convex/values\";\nimport { Predicate, Schema } from \"effect\";\nimport {\n compileTableSchema,\n type TableSchemaToTableValidator,\n} from \"./SchemaToValidator\";\n\nexport const TypeId = \"@confect/server/Table\";\nexport type TypeId = typeof TypeId;\n\n// -----------------------------------------------------------------------------\n// Predicates\n// -----------------------------------------------------------------------------\n//\n// Both bound `Table`s and `UnnamedTable` callables share the same `[TypeId]`\n// brand. They disambiguate by whether a `tableName` property is set: bound\n// tables have one, unnamed callables do not.\n//\n// The discriminator is `tableName` (not `name`) so it does not collide with\n// the built-in `Function.prototype.name` that every JS function carries.\n\nexport const isTable = (u: unknown): u is Any =>\n Predicate.hasProperty(u, TypeId) && Predicate.hasProperty(u, \"tableName\");\n\nexport const isUnnamedTable = (u: unknown): u is UnnamedAny =>\n Predicate.hasProperty(u, TypeId) && !Predicate.hasProperty(u, \"tableName\");\n\n// -----------------------------------------------------------------------------\n// Bound Table\n// -----------------------------------------------------------------------------\n\nexport interface Table<\n Name_ extends string,\n TableSchema_ extends Schema.Schema.AnyNoContext,\n TableValidator_ extends GenericValidator =\n TableSchemaToTableValidator<TableSchema_>,\n Indexes_ extends GenericTableIndexes = {},\n SearchIndexes_ extends GenericTableSearchIndexes = {},\n VectorIndexes_ extends GenericTableVectorIndexes = {},\n> {\n readonly [TypeId]: TypeId;\n readonly tableName: Name_;\n readonly tableDefinition: TableDefinition<\n TableValidator_,\n Indexes_,\n SearchIndexes_,\n VectorIndexes_\n >;\n readonly Fields: TableSchema_;\n readonly Doc: SystemFields.ExtendWithSystemFields<Name_, TableSchema_>;\n readonly indexes: Indexes_;\n}\n\nexport interface Any {\n readonly [TypeId]: TypeId;\n readonly tableName: string;\n}\n\nexport type AnyWithProps = Table<\n any,\n Schema.Schema.AnyNoContext,\n GenericValidator,\n GenericTableIndexes,\n GenericTableSearchIndexes,\n GenericTableVectorIndexes\n>;\n\n// -----------------------------------------------------------------------------\n// UnnamedTable (callable)\n// -----------------------------------------------------------------------------\n//\n// `Table.make(lazyFields)` returns an `UnnamedTable`: a callable that\n// produces a fully bound `Table` when invoked with a name. Chaining methods\n// (`.index`, `.searchIndex`, `.vectorIndex`) live here and return new\n// `UnnamedTable`s, accumulating plain index metadata records. Neither the\n// field-schema nor the deploy-time `tableDefinition` is constructed at this\n// stage — the user-supplied `lazyFields` callback is just carried through.\n// The codegen pipeline emits a wrapper file per user-authored table that\n// simply invokes the unnamed callable with the filename basename.\n\nexport interface UnnamedTable<\n TableSchema_ extends Schema.Schema.AnyNoContext,\n TableValidator_ extends GenericValidator =\n TableSchemaToTableValidator<TableSchema_>,\n Indexes_ extends GenericTableIndexes = {},\n SearchIndexes_ extends GenericTableSearchIndexes = {},\n VectorIndexes_ extends GenericTableVectorIndexes = {},\n> {\n <const Name_ extends string>(\n tableName: Name_,\n ): Table<\n Name_,\n TableSchema_,\n TableValidator_,\n Indexes_,\n SearchIndexes_,\n VectorIndexes_\n >;\n\n readonly [TypeId]: TypeId;\n readonly indexes: Indexes_;\n\n index<\n IndexName extends string,\n FirstFieldPath extends ExtractFieldPaths<TableValidator_>,\n RestFieldPaths extends ExtractFieldPaths<TableValidator_>[],\n >(\n name: IndexName,\n fields: [FirstFieldPath, ...RestFieldPaths],\n ): UnnamedTable<\n TableSchema_,\n TableValidator_,\n Expand<\n Indexes_ &\n Record<\n IndexName,\n [FirstFieldPath, ...RestFieldPaths, IndexTiebreakerField]\n >\n >,\n SearchIndexes_,\n VectorIndexes_\n >;\n\n searchIndex<\n IndexName extends string,\n SearchField extends ExtractFieldPaths<TableValidator_>,\n FilterFields extends ExtractFieldPaths<TableValidator_> = never,\n >(\n name: IndexName,\n indexConfig: Expand<SearchIndexConfig<SearchField, FilterFields>>,\n ): UnnamedTable<\n TableSchema_,\n TableValidator_,\n Indexes_,\n Expand<\n SearchIndexes_ &\n Record<\n IndexName,\n {\n searchField: SearchField;\n filterFields: FilterFields;\n }\n >\n >,\n VectorIndexes_\n >;\n\n vectorIndex<\n IndexName extends string,\n VectorField extends ExtractFieldPaths<TableValidator_>,\n FilterFields extends ExtractFieldPaths<TableValidator_> = never,\n >(\n name: IndexName,\n indexConfig: Expand<VectorIndexConfig<VectorField, FilterFields>>,\n ): UnnamedTable<\n TableSchema_,\n TableValidator_,\n Indexes_,\n SearchIndexes_,\n Expand<\n VectorIndexes_ &\n Record<\n IndexName,\n {\n vectorField: VectorField;\n dimensions: number;\n filterFields: FilterFields;\n }\n >\n >\n >;\n}\n\nexport interface UnnamedAny {\n readonly [TypeId]: TypeId;\n}\n\nexport type UnnamedAnyWithProps = UnnamedTable<\n Schema.Schema.AnyNoContext,\n GenericValidator,\n GenericTableIndexes,\n GenericTableSearchIndexes,\n GenericTableVectorIndexes\n>;\n\n// -----------------------------------------------------------------------------\n// Type extractors\n// -----------------------------------------------------------------------------\n\nexport type Name<TableDef extends AnyWithProps> =\n TableDef extends Table<\n infer TableName,\n infer _TableSchema,\n infer _TableValidator,\n infer _Indexes,\n infer _SearchIndexes,\n infer _VectorIndexes\n >\n ? TableName & string\n : never;\n\nexport type TableSchema<TableDef extends AnyWithProps> =\n TableDef extends Table<\n infer _TableName,\n infer TableSchema_,\n infer _TableValidator,\n infer _Indexes,\n infer _SearchIndexes,\n infer _VectorIndexes\n >\n ? TableSchema_\n : never;\n\nexport type TableValidator<TableDef extends AnyWithProps> =\n TableDef extends Table<\n infer _TableName,\n infer _TableSchema,\n infer TableValidator_,\n infer _Indexes,\n infer _SearchIndexes,\n infer _VectorIndexes\n >\n ? TableValidator_\n : never;\n\nexport type Indexes<TableDef extends AnyWithProps> =\n TableDef extends Table<\n infer _TableName,\n infer _TableSchema,\n infer _TableValidator,\n infer Indexes_,\n infer _SearchIndexes,\n infer _VectorIndexes\n >\n ? Indexes_\n : never;\n\nexport type SearchIndexes<TableDef extends AnyWithProps> =\n TableDef extends Table<\n infer _TableName,\n infer _TableSchema,\n infer _TableValidator,\n infer _Indexes,\n infer SearchIndexes_,\n infer _VectorIndexes\n >\n ? SearchIndexes_\n : never;\n\nexport type VectorIndexes<TableDef extends AnyWithProps> =\n TableDef extends Table<\n infer _TableName,\n infer _TableSchema,\n infer _TableValidator,\n infer _Indexes,\n infer _SearchIndexes,\n infer VectorIndexes_\n >\n ? VectorIndexes_\n : never;\n\nexport type Doc<TableDef extends AnyWithProps> =\n TableDef extends Table<\n infer TableName,\n infer TableSchema_,\n infer _TableValidator,\n infer _Indexes,\n infer _SearchIndexes,\n infer _VectorIndexes\n >\n ? SystemFields.ExtendWithSystemFields<TableName, TableSchema_>\n : never;\n\nexport type Fields<TableDef extends AnyWithProps> =\n TableDef extends Table<\n infer _TableName,\n infer TableSchema_,\n infer _TableValidator,\n infer _Indexes,\n infer _SearchIndexes,\n infer _VectorIndexes\n >\n ? TableSchema_\n : never;\n\nexport type WithName<\n TableDef extends AnyWithProps,\n Name_ extends string,\n> = TableDef extends { readonly tableName: Name_ } ? TableDef : never;\n\nexport type TablesRecord<Tables extends AnyWithProps> = {\n readonly [TableName_ in Name<Tables>]: WithName<Tables, TableName_>;\n};\n\n// -----------------------------------------------------------------------------\n// Construction\n// -----------------------------------------------------------------------------\n//\n// `make` only stores the user-supplied `lazyFields` callback alongside any\n// chained index metadata. Neither `Fields` nor `Doc` nor `tableDefinition`\n// is constructed until first access on a bound `Table`. Each chain step is\n// O(1) (plain object spread of the metadata records) and never invokes the\n// callback. Binding via `unnamed(tableName)` installs lazy memoised getters\n// for `Fields`, `Doc`, and `tableDefinition` via `Lazy.defineProperty`, so the\n// first access materialises the value and replaces the getter with a plain\n// data property — second-and-subsequent accesses are observably\n// indistinguishable from a plain property and avoid all function-call\n// overhead.\n\ninterface UnnamedState<\n TableSchema_ extends Schema.Schema.AnyNoContext,\n Indexes_ extends GenericTableIndexes,\n SearchIndexes_ extends GenericTableSearchIndexes,\n VectorIndexes_ extends GenericTableVectorIndexes,\n> {\n readonly lazyFields: () => TableSchema_;\n readonly indexes: Indexes_;\n readonly searchIndexes: SearchIndexes_;\n readonly vectorIndexes: VectorIndexes_;\n}\n\nconst makeBound = <\n Name_ extends string,\n TableSchema_ extends Schema.Schema.AnyNoContext,\n TableValidator_ extends Validator<any, any, any>,\n Indexes_ extends GenericTableIndexes,\n SearchIndexes_ extends GenericTableSearchIndexes,\n VectorIndexes_ extends GenericTableVectorIndexes,\n>(\n tableName: Name_,\n state: UnnamedState<TableSchema_, Indexes_, SearchIndexes_, VectorIndexes_>,\n): Table<\n Name_,\n TableSchema_,\n TableValidator_,\n Indexes_,\n SearchIndexes_,\n VectorIndexes_\n> => {\n const bound = {\n [TypeId]: TypeId as TypeId,\n tableName,\n indexes: state.indexes,\n } as Table<\n Name_,\n TableSchema_,\n TableValidator_,\n Indexes_,\n SearchIndexes_,\n VectorIndexes_\n >;\n\n Lazy.defineProperty(bound, \"Fields\", () => state.lazyFields());\n\n Lazy.defineProperty(bound, \"Doc\", () =>\n SystemFields.extendWithSystemFields(\n tableName,\n (bound as { Fields: TableSchema_ }).Fields,\n ),\n );\n\n Lazy.defineProperty(bound, \"tableDefinition\", () => {\n const fields = (bound as { Fields: TableSchema_ }).Fields;\n let definition: TableDefinition<any, any, any, any> = defineTable(\n compileTableSchema(fields),\n );\n for (const [name, indexFields] of Object.entries(\n state.indexes as Record<string, any>,\n )) {\n definition = definition.index(name, indexFields);\n }\n for (const [name, config] of Object.entries(\n state.searchIndexes as Record<string, any>,\n )) {\n definition = definition.searchIndex(name, config);\n }\n for (const [name, config] of Object.entries(\n state.vectorIndexes as Record<string, any>,\n )) {\n definition = definition.vectorIndex(name, config);\n }\n return definition;\n });\n\n return bound;\n};\n\nconst makeUnnamed = <\n TableSchema_ extends Schema.Schema.AnyNoContext,\n TableValidator_ extends Validator<any, any, any>,\n Indexes_ extends GenericTableIndexes,\n SearchIndexes_ extends GenericTableSearchIndexes,\n VectorIndexes_ extends GenericTableVectorIndexes,\n>(\n state: UnnamedState<TableSchema_, Indexes_, SearchIndexes_, VectorIndexes_>,\n): UnnamedTable<\n TableSchema_,\n TableValidator_,\n Indexes_,\n SearchIndexes_,\n VectorIndexes_\n> => {\n type UnnamedTable_ = UnnamedTable<\n TableSchema_,\n TableValidator_,\n Indexes_,\n SearchIndexes_,\n VectorIndexes_\n >;\n\n type UnnamedTableFunction<FunctionName extends keyof UnnamedTable_> =\n UnnamedTable_[FunctionName];\n\n const bind = <const Name_ extends string>(\n tableName: Name_,\n ): Table<\n Name_,\n TableSchema_,\n TableValidator_,\n Indexes_,\n SearchIndexes_,\n VectorIndexes_\n > =>\n makeBound<\n Name_,\n TableSchema_,\n TableValidator_,\n Indexes_,\n SearchIndexes_,\n VectorIndexes_\n >(tableName, state);\n\n const index: UnnamedTableFunction<\"index\"> = (name, fields) =>\n makeUnnamed({\n lazyFields: state.lazyFields,\n indexes: {\n ...state.indexes,\n [name]: fields,\n } as any,\n searchIndexes: state.searchIndexes,\n vectorIndexes: state.vectorIndexes,\n });\n\n const searchIndex: UnnamedTableFunction<\"searchIndex\"> = (\n name,\n indexConfig,\n ) =>\n makeUnnamed({\n lazyFields: state.lazyFields,\n indexes: state.indexes,\n searchIndexes: {\n ...state.searchIndexes,\n [name]: indexConfig,\n } as any,\n vectorIndexes: state.vectorIndexes,\n });\n\n const vectorIndex: UnnamedTableFunction<\"vectorIndex\"> = (\n name,\n indexConfig,\n ) =>\n makeUnnamed({\n lazyFields: state.lazyFields,\n indexes: state.indexes,\n searchIndexes: state.searchIndexes,\n vectorIndexes: {\n ...state.vectorIndexes,\n [name]: indexConfig,\n } as any,\n });\n\n return Object.assign(bind, {\n [TypeId]: TypeId as TypeId,\n indexes: state.indexes,\n index,\n searchIndex,\n vectorIndex,\n }) satisfies UnnamedTable_;\n};\n\nexport const make = <const TableSchema_ extends Schema.Schema.AnyNoContext>(\n lazyFields: () => TableSchema_,\n): UnnamedTable<TableSchema_, TableSchemaToTableValidator<TableSchema_>> => {\n type TableValidator_ = TableSchemaToTableValidator<TableSchema_>;\n type UnnamedTable_ = UnnamedTable<TableSchema_, TableValidator_>;\n\n return makeUnnamed<TableSchema_, TableValidator_, {}, {}, {}>({\n lazyFields,\n indexes: {},\n searchIndexes: {},\n vectorIndexes: {},\n }) satisfies UnnamedTable_;\n};\n\n// -----------------------------------------------------------------------------\n// System tables\n// -----------------------------------------------------------------------------\n\nexport const scheduledFunctionsTable = make(() =>\n Schema.Struct({\n name: Schema.String,\n args: Schema.Array(Schema.Any),\n scheduledTime: Schema.Number,\n completedTime: Schema.optionalWith(Schema.Number, { exact: true }),\n state: Schema.Union(\n Schema.Struct({ kind: Schema.Literal(\"pending\") }),\n Schema.Struct({ kind: Schema.Literal(\"inProgress\") }),\n Schema.Struct({ kind: Schema.Literal(\"success\") }),\n Schema.Struct({\n kind: Schema.Literal(\"failed\"),\n error: Schema.String,\n }),\n Schema.Struct({ kind: Schema.Literal(\"canceled\") }),\n ),\n }),\n)(\"_scheduled_functions\");\n\nexport const storageTable = make(() =>\n Schema.Struct({\n sha256: Schema.String,\n size: Schema.Number,\n contentType: Schema.optionalWith(Schema.String, { exact: true }),\n }),\n)(\"_storage\");\n\nexport const systemTables = {\n _scheduled_functions: scheduledFunctionsTable,\n _storage: storageTable,\n} as const;\n\nexport type SystemTables = typeof scheduledFunctionsTable | typeof storageTable;\n\n// Vendored types from convex-js, partially modified. Ideally we could use these directly. See https://github.com/get-convex/convex-js/pull/14\n\n/**\n * Extract all of the index field paths within a {@link Validator}.\n *\n * This is used within {@link defineTable}.\n * @public\n */\ntype ExtractFieldPaths<T extends Validator<any, any, any>> =\n // Add in the system fields available in index definitions.\n // This should be everything except for `_id` because thats added to indexes\n // automatically.\n T[\"fieldPaths\"] | keyof ConvexSystemFields;\n"],"mappings":";;;;;;;;;;;;;;;;;AAqBA,MAAa,SAAS;AActB,MAAa,WAAW,MACtB,UAAU,YAAY,GAAG,OAAO,IAAI,UAAU,YAAY,GAAG,YAAY;AAE3E,MAAa,kBAAkB,MAC7B,UAAU,YAAY,GAAG,OAAO,IAAI,CAAC,UAAU,YAAY,GAAG,YAAY;AAwS5E,MAAM,aAQJ,WACA,UAQG;CACH,MAAM,QAAQ;GACX,SAAS;EACV;EACA,SAAS,MAAM;EAChB;AASD,MAAK,eAAe,OAAO,gBAAgB,MAAM,YAAY,CAAC;AAE9D,MAAK,eAAe,OAAO,aACzBA,eAAa,uBACX,WACC,MAAmC,OACrC,CACF;AAED,MAAK,eAAe,OAAO,yBAAyB;EAClD,MAAM,SAAU,MAAmC;EACnD,IAAI,aAAkD,YACpD,mBAAmB,OAAO,CAC3B;AACD,OAAK,MAAM,CAAC,MAAM,gBAAgB,OAAO,QACvC,MAAM,QACP,CACC,cAAa,WAAW,MAAM,MAAM,YAAY;AAElD,OAAK,MAAM,CAAC,MAAM,WAAW,OAAO,QAClC,MAAM,cACP,CAC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,CAAC,EAClD,OAAO,OAAO;EACZ,MAAM,OAAO,QAAQ,SAAS;EAC9B,OAAO,OAAO;EACf,CAAC,EACF,OAAO,OAAO,EAAE,MAAM,OAAO,QAAQ,WAAW,EAAE,CAAC,CACpD;CACF,CAAC,CACH,CAAC,uBAAuB;AAEzB,MAAa,eAAe,WAC1B,OAAO,OAAO;CACZ,QAAQ,OAAO;CACf,MAAM,OAAO;CACb,aAAa,OAAO,aAAa,OAAO,QAAQ,EAAE,OAAO,MAAM,CAAC;CACjE,CAAC,CACH,CAAC,WAAW;AAEb,MAAa,eAAe;CAC1B,sBAAsB;CACtB,UAAU;CACX"}
|
|
1
|
+
{"version":3,"file":"Table.js","names":["SystemFields"],"sources":["../src/Table.ts"],"sourcesContent":["import * as Lazy from \"@confect/core/Lazy\";\nimport * as SystemFields from \"@confect/core/SystemFields\";\nimport {\n defineTable,\n type SystemFields as ConvexSystemFields,\n type Expand,\n type GenericTableIndexes,\n type GenericTableSearchIndexes,\n type GenericTableVectorIndexes,\n type IndexTiebreakerField,\n type SearchIndexConfig,\n type TableDefinition,\n type VectorIndexConfig,\n} from \"convex/server\";\nimport type { GenericValidator, Validator } from \"convex/values\";\nimport * as Predicate from \"effect/Predicate\";\nimport * as Schema from \"effect/Schema\";\nimport {\n compileTableSchema,\n type TableSchemaToTableValidator,\n} from \"./SchemaToValidator\";\n\nexport const TypeId = \"@confect/server/Table\";\nexport type TypeId = typeof TypeId;\n\n// -----------------------------------------------------------------------------\n// Predicates\n// -----------------------------------------------------------------------------\n//\n// Both bound `Table`s and `UnnamedTable` callables share the same `[TypeId]`\n// brand. They disambiguate by whether a `tableName` property is set: bound\n// tables have one, unnamed callables do not.\n//\n// The discriminator is `tableName` (not `name`) so it does not collide with\n// the built-in `Function.prototype.name` that every JS function carries.\n\nexport const isTable = (u: unknown): u is Any =>\n Predicate.hasProperty(u, TypeId) && Predicate.hasProperty(u, \"tableName\");\n\nexport const isUnnamedTable = (u: unknown): u is UnnamedAny =>\n Predicate.hasProperty(u, TypeId) && !Predicate.hasProperty(u, \"tableName\");\n\n// -----------------------------------------------------------------------------\n// Bound Table\n// -----------------------------------------------------------------------------\n\nexport interface Table<\n Name_ extends string,\n TableSchema_ extends Schema.Schema.AnyNoContext,\n TableValidator_ extends GenericValidator =\n TableSchemaToTableValidator<TableSchema_>,\n Indexes_ extends GenericTableIndexes = {},\n SearchIndexes_ extends GenericTableSearchIndexes = {},\n VectorIndexes_ extends GenericTableVectorIndexes = {},\n> {\n readonly [TypeId]: TypeId;\n readonly tableName: Name_;\n readonly tableDefinition: TableDefinition<\n TableValidator_,\n Indexes_,\n SearchIndexes_,\n VectorIndexes_\n >;\n readonly Fields: TableSchema_;\n readonly Doc: SystemFields.ExtendWithSystemFields<Name_, TableSchema_>;\n readonly indexes: Indexes_;\n}\n\nexport interface Any {\n readonly [TypeId]: TypeId;\n readonly tableName: string;\n}\n\nexport type AnyWithProps = Table<\n any,\n Schema.Schema.AnyNoContext,\n GenericValidator,\n GenericTableIndexes,\n GenericTableSearchIndexes,\n GenericTableVectorIndexes\n>;\n\n// -----------------------------------------------------------------------------\n// UnnamedTable (callable)\n// -----------------------------------------------------------------------------\n//\n// `Table.make(lazyFields)` returns an `UnnamedTable`: a callable that\n// produces a fully bound `Table` when invoked with a name. Chaining methods\n// (`.index`, `.searchIndex`, `.vectorIndex`) live here and return new\n// `UnnamedTable`s, accumulating plain index metadata records. Neither the\n// field-schema nor the deploy-time `tableDefinition` is constructed at this\n// stage — the user-supplied `lazyFields` callback is just carried through.\n// The codegen pipeline emits a wrapper file per user-authored table that\n// simply invokes the unnamed callable with the filename basename.\n\nexport interface UnnamedTable<\n TableSchema_ extends Schema.Schema.AnyNoContext,\n TableValidator_ extends GenericValidator =\n TableSchemaToTableValidator<TableSchema_>,\n Indexes_ extends GenericTableIndexes = {},\n SearchIndexes_ extends GenericTableSearchIndexes = {},\n VectorIndexes_ extends GenericTableVectorIndexes = {},\n> {\n <const Name_ extends string>(\n tableName: Name_,\n ): Table<\n Name_,\n TableSchema_,\n TableValidator_,\n Indexes_,\n SearchIndexes_,\n VectorIndexes_\n >;\n\n readonly [TypeId]: TypeId;\n readonly indexes: Indexes_;\n\n index<\n IndexName extends string,\n FirstFieldPath extends ExtractFieldPaths<TableValidator_>,\n RestFieldPaths extends ExtractFieldPaths<TableValidator_>[],\n >(\n name: IndexName,\n fields: [FirstFieldPath, ...RestFieldPaths],\n ): UnnamedTable<\n TableSchema_,\n TableValidator_,\n Expand<\n Indexes_ &\n Record<\n IndexName,\n [FirstFieldPath, ...RestFieldPaths, IndexTiebreakerField]\n >\n >,\n SearchIndexes_,\n VectorIndexes_\n >;\n\n searchIndex<\n IndexName extends string,\n SearchField extends ExtractFieldPaths<TableValidator_>,\n FilterFields extends ExtractFieldPaths<TableValidator_> = never,\n >(\n name: IndexName,\n indexConfig: Expand<SearchIndexConfig<SearchField, FilterFields>>,\n ): UnnamedTable<\n TableSchema_,\n TableValidator_,\n Indexes_,\n Expand<\n SearchIndexes_ &\n Record<\n IndexName,\n {\n searchField: SearchField;\n filterFields: FilterFields;\n }\n >\n >,\n VectorIndexes_\n >;\n\n vectorIndex<\n IndexName extends string,\n VectorField extends ExtractFieldPaths<TableValidator_>,\n FilterFields extends ExtractFieldPaths<TableValidator_> = never,\n >(\n name: IndexName,\n indexConfig: Expand<VectorIndexConfig<VectorField, FilterFields>>,\n ): UnnamedTable<\n TableSchema_,\n TableValidator_,\n Indexes_,\n SearchIndexes_,\n Expand<\n VectorIndexes_ &\n Record<\n IndexName,\n {\n vectorField: VectorField;\n dimensions: number;\n filterFields: FilterFields;\n }\n >\n >\n >;\n}\n\nexport interface UnnamedAny {\n readonly [TypeId]: TypeId;\n}\n\nexport type UnnamedAnyWithProps = UnnamedTable<\n Schema.Schema.AnyNoContext,\n GenericValidator,\n GenericTableIndexes,\n GenericTableSearchIndexes,\n GenericTableVectorIndexes\n>;\n\n// -----------------------------------------------------------------------------\n// Type extractors\n// -----------------------------------------------------------------------------\n\nexport type Name<TableDef extends AnyWithProps> =\n TableDef extends Table<\n infer TableName,\n infer _TableSchema,\n infer _TableValidator,\n infer _Indexes,\n infer _SearchIndexes,\n infer _VectorIndexes\n >\n ? TableName & string\n : never;\n\nexport type TableSchema<TableDef extends AnyWithProps> =\n TableDef extends Table<\n infer _TableName,\n infer TableSchema_,\n infer _TableValidator,\n infer _Indexes,\n infer _SearchIndexes,\n infer _VectorIndexes\n >\n ? TableSchema_\n : never;\n\nexport type TableValidator<TableDef extends AnyWithProps> =\n TableDef extends Table<\n infer _TableName,\n infer _TableSchema,\n infer TableValidator_,\n infer _Indexes,\n infer _SearchIndexes,\n infer _VectorIndexes\n >\n ? TableValidator_\n : never;\n\nexport type Indexes<TableDef extends AnyWithProps> =\n TableDef extends Table<\n infer _TableName,\n infer _TableSchema,\n infer _TableValidator,\n infer Indexes_,\n infer _SearchIndexes,\n infer _VectorIndexes\n >\n ? Indexes_\n : never;\n\nexport type SearchIndexes<TableDef extends AnyWithProps> =\n TableDef extends Table<\n infer _TableName,\n infer _TableSchema,\n infer _TableValidator,\n infer _Indexes,\n infer SearchIndexes_,\n infer _VectorIndexes\n >\n ? SearchIndexes_\n : never;\n\nexport type VectorIndexes<TableDef extends AnyWithProps> =\n TableDef extends Table<\n infer _TableName,\n infer _TableSchema,\n infer _TableValidator,\n infer _Indexes,\n infer _SearchIndexes,\n infer VectorIndexes_\n >\n ? VectorIndexes_\n : never;\n\nexport type Doc<TableDef extends AnyWithProps> =\n TableDef extends Table<\n infer TableName,\n infer TableSchema_,\n infer _TableValidator,\n infer _Indexes,\n infer _SearchIndexes,\n infer _VectorIndexes\n >\n ? SystemFields.ExtendWithSystemFields<TableName, TableSchema_>\n : never;\n\nexport type Fields<TableDef extends AnyWithProps> =\n TableDef extends Table<\n infer _TableName,\n infer TableSchema_,\n infer _TableValidator,\n infer _Indexes,\n infer _SearchIndexes,\n infer _VectorIndexes\n >\n ? TableSchema_\n : never;\n\nexport type WithName<\n TableDef extends AnyWithProps,\n Name_ extends string,\n> = TableDef extends { readonly tableName: Name_ } ? TableDef : never;\n\nexport type TablesRecord<Tables extends AnyWithProps> = {\n readonly [TableName_ in Name<Tables>]: WithName<Tables, TableName_>;\n};\n\n// -----------------------------------------------------------------------------\n// Construction\n// -----------------------------------------------------------------------------\n//\n// `make` only stores the user-supplied `lazyFields` callback alongside any\n// chained index metadata. Neither `Fields` nor `Doc` nor `tableDefinition`\n// is constructed until first access on a bound `Table`. Each chain step is\n// O(1) (plain object spread of the metadata records) and never invokes the\n// callback. Binding via `unnamed(tableName)` installs lazy memoised getters\n// for `Fields`, `Doc`, and `tableDefinition` via `Lazy.defineProperty`, so the\n// first access materialises the value and replaces the getter with a plain\n// data property — second-and-subsequent accesses are observably\n// indistinguishable from a plain property and avoid all function-call\n// overhead.\n\ninterface UnnamedState<\n TableSchema_ extends Schema.Schema.AnyNoContext,\n Indexes_ extends GenericTableIndexes,\n SearchIndexes_ extends GenericTableSearchIndexes,\n VectorIndexes_ extends GenericTableVectorIndexes,\n> {\n readonly lazyFields: () => TableSchema_;\n readonly indexes: Indexes_;\n readonly searchIndexes: SearchIndexes_;\n readonly vectorIndexes: VectorIndexes_;\n}\n\nconst makeBound = <\n Name_ extends string,\n TableSchema_ extends Schema.Schema.AnyNoContext,\n TableValidator_ extends Validator<any, any, any>,\n Indexes_ extends GenericTableIndexes,\n SearchIndexes_ extends GenericTableSearchIndexes,\n VectorIndexes_ extends GenericTableVectorIndexes,\n>(\n tableName: Name_,\n state: UnnamedState<TableSchema_, Indexes_, SearchIndexes_, VectorIndexes_>,\n): Table<\n Name_,\n TableSchema_,\n TableValidator_,\n Indexes_,\n SearchIndexes_,\n VectorIndexes_\n> => {\n const bound = {\n [TypeId]: TypeId as TypeId,\n tableName,\n indexes: state.indexes,\n } as Table<\n Name_,\n TableSchema_,\n TableValidator_,\n Indexes_,\n SearchIndexes_,\n VectorIndexes_\n >;\n\n Lazy.defineProperty(bound, \"Fields\", () => state.lazyFields());\n\n Lazy.defineProperty(bound, \"Doc\", () =>\n SystemFields.extendWithSystemFields(\n tableName,\n (bound as { Fields: TableSchema_ }).Fields,\n ),\n );\n\n Lazy.defineProperty(bound, \"tableDefinition\", () => {\n const fields = (bound as { Fields: TableSchema_ }).Fields;\n let definition: TableDefinition<any, any, any, any> = defineTable(\n compileTableSchema(fields),\n );\n for (const [name, indexFields] of Object.entries(\n state.indexes as Record<string, any>,\n )) {\n definition = definition.index(name, indexFields);\n }\n for (const [name, config] of Object.entries(\n state.searchIndexes as Record<string, any>,\n )) {\n definition = definition.searchIndex(name, config);\n }\n for (const [name, config] of Object.entries(\n state.vectorIndexes as Record<string, any>,\n )) {\n definition = definition.vectorIndex(name, config);\n }\n return definition;\n });\n\n return bound;\n};\n\nconst makeUnnamed = <\n TableSchema_ extends Schema.Schema.AnyNoContext,\n TableValidator_ extends Validator<any, any, any>,\n Indexes_ extends GenericTableIndexes,\n SearchIndexes_ extends GenericTableSearchIndexes,\n VectorIndexes_ extends GenericTableVectorIndexes,\n>(\n state: UnnamedState<TableSchema_, Indexes_, SearchIndexes_, VectorIndexes_>,\n): UnnamedTable<\n TableSchema_,\n TableValidator_,\n Indexes_,\n SearchIndexes_,\n VectorIndexes_\n> => {\n type UnnamedTable_ = UnnamedTable<\n TableSchema_,\n TableValidator_,\n Indexes_,\n SearchIndexes_,\n VectorIndexes_\n >;\n\n type UnnamedTableFunction<FunctionName extends keyof UnnamedTable_> =\n UnnamedTable_[FunctionName];\n\n const bind = <const Name_ extends string>(\n tableName: Name_,\n ): Table<\n Name_,\n TableSchema_,\n TableValidator_,\n Indexes_,\n SearchIndexes_,\n VectorIndexes_\n > =>\n makeBound<\n Name_,\n TableSchema_,\n TableValidator_,\n Indexes_,\n SearchIndexes_,\n VectorIndexes_\n >(tableName, state);\n\n const index: UnnamedTableFunction<\"index\"> = (name, fields) =>\n makeUnnamed({\n lazyFields: state.lazyFields,\n indexes: {\n ...state.indexes,\n [name]: fields,\n } as any,\n searchIndexes: state.searchIndexes,\n vectorIndexes: state.vectorIndexes,\n });\n\n const searchIndex: UnnamedTableFunction<\"searchIndex\"> = (\n name,\n indexConfig,\n ) =>\n makeUnnamed({\n lazyFields: state.lazyFields,\n indexes: state.indexes,\n searchIndexes: {\n ...state.searchIndexes,\n [name]: indexConfig,\n } as any,\n vectorIndexes: state.vectorIndexes,\n });\n\n const vectorIndex: UnnamedTableFunction<\"vectorIndex\"> = (\n name,\n indexConfig,\n ) =>\n makeUnnamed({\n lazyFields: state.lazyFields,\n indexes: state.indexes,\n searchIndexes: state.searchIndexes,\n vectorIndexes: {\n ...state.vectorIndexes,\n [name]: indexConfig,\n } as any,\n });\n\n return Object.assign(bind, {\n [TypeId]: TypeId as TypeId,\n indexes: state.indexes,\n index,\n searchIndex,\n vectorIndex,\n }) satisfies UnnamedTable_;\n};\n\nexport const make = <const TableSchema_ extends Schema.Schema.AnyNoContext>(\n lazyFields: () => TableSchema_,\n): UnnamedTable<TableSchema_, TableSchemaToTableValidator<TableSchema_>> => {\n type TableValidator_ = TableSchemaToTableValidator<TableSchema_>;\n type UnnamedTable_ = UnnamedTable<TableSchema_, TableValidator_>;\n\n return makeUnnamed<TableSchema_, TableValidator_, {}, {}, {}>({\n lazyFields,\n indexes: {},\n searchIndexes: {},\n vectorIndexes: {},\n }) satisfies UnnamedTable_;\n};\n\n// -----------------------------------------------------------------------------\n// System tables\n// -----------------------------------------------------------------------------\n\nexport const scheduledFunctionsTable = make(() =>\n Schema.Struct({\n name: Schema.String,\n args: Schema.Array(Schema.Any),\n scheduledTime: Schema.Number,\n completedTime: Schema.optionalWith(Schema.Number, { exact: true }),\n state: Schema.Union(\n Schema.Struct({ kind: Schema.Literal(\"pending\") }),\n Schema.Struct({ kind: Schema.Literal(\"inProgress\") }),\n Schema.Struct({ kind: Schema.Literal(\"success\") }),\n Schema.Struct({\n kind: Schema.Literal(\"failed\"),\n error: Schema.String,\n }),\n Schema.Struct({ kind: Schema.Literal(\"canceled\") }),\n ),\n }),\n)(\"_scheduled_functions\");\n\nexport const storageTable = make(() =>\n Schema.Struct({\n sha256: Schema.String,\n size: Schema.Number,\n contentType: Schema.optionalWith(Schema.String, { exact: true }),\n }),\n)(\"_storage\");\n\nexport const systemTables = {\n _scheduled_functions: scheduledFunctionsTable,\n _storage: storageTable,\n} as const;\n\nexport type SystemTables = typeof scheduledFunctionsTable | typeof storageTable;\n\n// Vendored types from convex-js, partially modified. Ideally we could use these directly. See https://github.com/get-convex/convex-js/pull/14\n\n/**\n * Extract all of the index field paths within a {@link Validator}.\n *\n * This is used within {@link defineTable}.\n * @public\n */\ntype ExtractFieldPaths<T extends Validator<any, any, any>> =\n // Add in the system fields available in index definitions.\n // This should be everything except for `_id` because thats added to indexes\n // automatically.\n T[\"fieldPaths\"] | keyof ConvexSystemFields;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAsBA,MAAa,SAAS;AActB,MAAa,WAAW,MACtB,UAAU,YAAY,GAAG,OAAO,IAAI,UAAU,YAAY,GAAG,YAAY;AAE3E,MAAa,kBAAkB,MAC7B,UAAU,YAAY,GAAG,OAAO,IAAI,CAAC,UAAU,YAAY,GAAG,YAAY;AAwS5E,MAAM,aAQJ,WACA,UAQG;CACH,MAAM,QAAQ;GACX,SAAS;EACV;EACA,SAAS,MAAM;EAChB;AASD,MAAK,eAAe,OAAO,gBAAgB,MAAM,YAAY,CAAC;AAE9D,MAAK,eAAe,OAAO,aACzBA,eAAa,uBACX,WACC,MAAmC,OACrC,CACF;AAED,MAAK,eAAe,OAAO,yBAAyB;EAClD,MAAM,SAAU,MAAmC;EACnD,IAAI,aAAkD,YACpD,mBAAmB,OAAO,CAC3B;AACD,OAAK,MAAM,CAAC,MAAM,gBAAgB,OAAO,QACvC,MAAM,QACP,CACC,cAAa,WAAW,MAAM,MAAM,YAAY;AAElD,OAAK,MAAM,CAAC,MAAM,WAAW,OAAO,QAClC,MAAM,cACP,CACC,cAAa,WAAW,YAAY,MAAM,OAAO;AAEnD,OAAK,MAAM,CA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S;EAC9B,OAAO,OAAO;EACf,CAAC,EACF,OAAO,OAAO,EAAE,MAAM,OAAO,QAAQ,WAAW,EAAE,CAAC,CACpD;CACF,CAAC,CACH,CAAC,uBAAuB;AAEzB,MAAa,eAAe,WAC1B,OAAO,OAAO;CACZ,QAAQ,OAAO;CACf,MAAM,OAAO;CACb,aAAa,OAAO,aAAa,OAAO,QAAQ,EAAE,OAAO,MAAM,CAAC;CACjE,CAAC,CACH,CAAC,WAAW;AAEb,MAAa,eAAe;CAC1B,sBAAsB;CACtB,UAAU;CACX"}
|
package/dist/TableInfo.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { AnyWithProps as AnyWithProps$1, Table } from "./Table.js";
|
|
2
2
|
import { Any as Any$1, AnyEncoded } from "./Document.js";
|
|
3
|
-
import { Schema, Types } from "effect";
|
|
4
3
|
import { Expand, GenericDocument, GenericFieldPaths, GenericTableIndexes, GenericTableSearchIndexes, GenericTableVectorIndexes, IdField, SystemFields, SystemIndexes } from "convex/server";
|
|
5
4
|
import { GenericValidator } from "convex/values";
|
|
5
|
+
import { Schema, Types } from "effect";
|
|
6
6
|
|
|
7
7
|
//#region src/TableInfo.d.ts
|
|
8
8
|
declare namespace TableInfo_d_exports {
|
package/dist/VectorSearch.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { AnyWithProps, TableNames, ToConvex } from "./DataModel.js";
|
|
2
|
-
import
|
|
2
|
+
import * as Context from "effect/Context";
|
|
3
3
|
import * as convex_server0 from "convex/server";
|
|
4
4
|
import { Expand, GenericActionCtx, NamedTableInfo, VectorIndexNames, VectorSearchQuery } from "convex/server";
|
|
5
|
+
import * as Layer from "effect/Layer";
|
|
6
|
+
import * as Effect from "effect/Effect";
|
|
5
7
|
import { GenericId } from "convex/values";
|
|
6
8
|
|
|
7
9
|
//#region src/VectorSearch.d.ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VectorSearch.d.ts","names":[],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A,IAAA,SAAA,EAAA,SAAA,EAAA,SAAA,EAAA,SAAA,EAAA,KAAA"}
|
package/dist/VectorSearch.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
|
-
import
|
|
2
|
+
import * as Context from "effect/Context";
|
|
3
|
+
import * as Layer from "effect/Layer";
|
|
4
|
+
import * as Effect from "effect/Effect";
|
|
3
5
|
|
|
4
6
|
//#region src/VectorSearch.ts
|
|
5
7
|
var VectorSearch_exports = /* @__PURE__ */ __exportAll({
|
package/dist/VectorSearch.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VectorSearch.js","names":[],"sources":["../src/VectorSearch.ts"],"sourcesContent":["import type {\n Expand,\n GenericActionCtx,\n NamedTableInfo,\n VectorIndexNames,\n VectorSearchQuery,\n} from \"convex/server\";\nimport type { GenericId } from \"convex/values\";\nimport
|
|
1
|
+
{"version":3,"file":"VectorSearch.js","names":[],"sources":["../src/VectorSearch.ts"],"sourcesContent":["import type {\n Expand,\n GenericActionCtx,\n NamedTableInfo,\n VectorIndexNames,\n VectorSearchQuery,\n} from \"convex/server\";\nimport type { GenericId } from \"convex/values\";\nimport * as Context from \"effect/Context\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\nimport type * as DataModel from \"./DataModel\";\n\ntype ConvexVectorSearch<DataModel_ extends DataModel.AnyWithProps> =\n GenericActionCtx<DataModel.ToConvex<DataModel_>>[\"vectorSearch\"];\n\nexport const make =\n <DataModel_ extends DataModel.AnyWithProps>(\n vectorSearch: ConvexVectorSearch<DataModel_>,\n ) =>\n <\n TableName extends DataModel.TableNames<DataModel_>,\n IndexName extends VectorIndexNames<\n NamedTableInfo<DataModel.ToConvex<DataModel_>, TableName>\n >,\n >(\n tableName: TableName,\n indexName: IndexName,\n query: Expand<\n VectorSearchQuery<\n NamedTableInfo<DataModel.ToConvex<DataModel_>, TableName>,\n IndexName\n >\n >,\n ): Effect.Effect<Array<{ _id: GenericId<TableName>; _score: number }>> =>\n Effect.promise(() => vectorSearch(tableName, indexName, query));\n\nexport const VectorSearch = <DataModel_ extends DataModel.AnyWithProps>() =>\n Context.GenericTag<ReturnType<typeof make<DataModel_>>>(\n \"@confect/server/VectorSearch\",\n );\n\nexport type VectorSearch<DataModel_ extends DataModel.AnyWithProps> =\n ReturnType<typeof VectorSearch<DataModel_>>[\"Identifier\"];\n\nexport const layer = <DataModel_ extends DataModel.AnyWithProps>(\n vectorSearch: ConvexVectorSearch<DataModel_>,\n) => Layer.succeed(VectorSearch<DataModel_>(), make(vectorSearch));\n"],"mappings":";;;;;;;;;;;AAgBA,MAAa,QAET,kBAQA,WACA,WACA,UAOA,OAAO,cAAc,aAAa,WAAW,WAAW,MAAM,CAAC;AAEnE,MAAa,qBACX,QAAQ,WACN,+BACD;AAKH,MAAa,SACX,iBACG,MAAM,QAAQ,cAA0B,EAAE,KAAK,aAAa,CAAC"}
|
package/dist/internal/utils.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as Effect$1 from "effect/Effect";
|
|
2
|
+
import { Predicate } from "effect";
|
|
2
3
|
|
|
3
4
|
//#region src/internal/utils.d.ts
|
|
4
5
|
type NestedObject<T> = {
|
|
@@ -8,7 +9,7 @@ declare const mapLeaves: <T, U>(obj: NestedObject<T>, leafRefinement: Predicate.
|
|
|
8
9
|
declare const forEachBranchLeaves: <T, A, E, R>(obj: NestedObject<T>, leafRefinement: Predicate.Refinement<unknown, T>, f: (branchLeaves: {
|
|
9
10
|
path: string[];
|
|
10
11
|
values: Record<string, T>;
|
|
11
|
-
}) => Effect.Effect<A, E, R>) => Effect.Effect<void, E, R>;
|
|
12
|
+
}) => Effect$1.Effect<A, E, R>) => Effect$1.Effect<void, E, R>;
|
|
12
13
|
declare const setNestedProperty: <T extends object>(obj: T, path: PropertyKey[], value: any) => T;
|
|
13
14
|
//#endregion
|
|
14
15
|
export { forEachBranchLeaves, mapLeaves, setNestedProperty };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","names":[],"sources":["../../src/internal/utils.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.ts","names":[],"sources":["../../src/internal/utils.ts"],"mappings":";;;;KAKK,YAAA;EAAA,CACF,GAAA,WAAc,CAAA,GAAI,YAAA,CAAa,CAAA;AAAA;AAAA,cAGrB,SAAA,SACX,GAAA,EAAK,YAAA,CAAa,CAAA,GAClB,cAAA,EAAgB,SAAA,CAAU,UAAA,UAAoB,CAAA,GAC9C,CAAA,GAAI,KAAA,EAAO,CAAA,KAAM,CAAA,KAChB,YAAA,CAAa,CAAA;AAAA,cAyCH,mBAAA,eACX,GAAA,EAAK,YAAA,CAAa,CAAA,GAClB,cAAA,EAAgB,SAAA,CAAU,UAAA,UAAoB,CAAA,GAC9C,CAAA,GAAI,YAAA;EACF,IAAA;EACA,MAAA,EAAQ,MAAA,SAAe,CAAA;AAAA,MACnB,QAAA,CAAO,MAAA,CAAO,CAAA,EAAG,CAAA,EAAG,CAAA,MACzB,QAAA,CAAO,MAAA,OAAa,CAAA,EAAG,CAAA;AAAA,cAOb,iBAAA,qBACX,GAAA,EAAK,CAAA,EACL,IAAA,EAAM,WAAA,IACN,KAAA,UACC,CAAA"}
|
package/dist/internal/utils.js
CHANGED