@gaganref/confect-core 10.3.1-fork.5 → 10.3.1-fork.51
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/dist/ActionCall.d.ts +18 -0
- package/dist/ActionCall.d.ts.map +1 -0
- package/dist/ActionCall.js +21 -0
- package/dist/ActionCall.js.map +1 -0
- package/dist/App.d.ts +13 -2
- package/dist/App.d.ts.map +1 -1
- package/dist/App.js +6 -3
- package/dist/App.js.map +1 -1
- package/dist/Auth.d.ts +31 -6
- package/dist/Auth.d.ts.map +1 -1
- package/dist/Auth.js +15 -1
- package/dist/Auth.js.map +1 -1
- package/dist/Callback.d.ts.map +1 -1
- package/dist/Callback.js +2 -2
- package/dist/Callback.js.map +1 -1
- package/dist/Component.d.ts.map +1 -1
- package/dist/Component.js +1 -1
- package/dist/Component.js.map +1 -1
- package/dist/FunctionSpec.d.ts +365 -2
- package/dist/FunctionSpec.d.ts.map +1 -1
- package/dist/FunctionSpec.js +66 -3
- package/dist/FunctionSpec.js.map +1 -1
- package/dist/GroupSpec.js +1 -1
- package/dist/Http.d.ts.map +1 -1
- package/dist/Http.js +2 -2
- package/dist/Http.js.map +1 -1
- package/dist/ManifestSection.d.ts +52 -0
- package/dist/ManifestSection.d.ts.map +1 -0
- package/dist/ManifestSection.js +7 -0
- package/dist/ManifestSection.js.map +1 -0
- package/dist/Profile.d.ts +95 -0
- package/dist/Profile.d.ts.map +1 -0
- package/dist/Profile.js +15 -0
- package/dist/Profile.js.map +1 -0
- package/dist/Ref.d.ts +4 -2
- package/dist/Ref.d.ts.map +1 -1
- package/dist/Ref.js +8 -4
- package/dist/Ref.js.map +1 -1
- package/dist/SchemaToValidator.d.ts +10 -1
- package/dist/SchemaToValidator.d.ts.map +1 -1
- package/dist/SchemaToValidator.js +19 -4
- package/dist/SchemaToValidator.js.map +1 -1
- package/dist/SystemFields.js +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -6
- package/dist/internal/scalarDocs.d.ts +5 -0
- package/dist/internal/scalarDocs.d.ts.map +1 -0
- package/dist/internal/scalarDocs.js +43 -0
- package/dist/internal/scalarDocs.js.map +1 -0
- package/package.json +3 -3
- package/src/ActionCall.ts +25 -0
- package/src/App.ts +19 -3
- package/src/Auth.ts +48 -6
- package/src/Callback.ts +1 -0
- package/src/Component.ts +2 -0
- package/src/FunctionSpec.ts +570 -5
- package/src/Http.ts +2 -5
- package/src/ManifestSection.ts +59 -0
- package/src/Profile.ts +141 -0
- package/src/Ref.ts +17 -4
- package/src/SchemaToValidator.ts +22 -1
- package/src/index.ts +3 -0
- package/src/internal/scalarDocs.ts +72 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaToValidator.js","names":["IdScope.app","GenericId.tableName","GenericId.scope","scope"],"sources":["../src/SchemaToValidator.ts"],"sourcesContent":["import * as IdScope from \"./IdScope.js\";\nimport type {\n GenericId as ConvexGenericId,\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 VRecord,\n VString,\n VUnion,\n} from \"convex/values\";\nimport { v } from \"convex/values\";\nimport { pipe } from \"effect/Function\";\nimport * as Array from \"effect/Array\";\nimport * as Data from \"effect/Data\";\nimport * as Effect from \"effect/Effect\";\nimport * as Match from \"effect/Match\";\nimport * as Number from \"effect/Number\";\nimport * as Option from \"effect/Option\";\nimport * as Predicate from \"effect/Predicate\";\nimport * as Schema from \"effect/Schema\";\nimport * as SchemaAST from \"effect/SchemaAST\";\nimport * as String from \"effect/String\";\n\nimport * as GenericId from \"./GenericId.js\";\nimport type {\n IsAny,\n IsOptional,\n IsRecord,\n IsRecursive,\n IsUnion,\n TypeError,\n UnionToTuple,\n} from \"./Types.js\";\n\n// Args\n\nexport const compileArgsSchema = <ConfectValue, ConvexValue>(\n argsSchema: Schema.Codec<ConfectValue, ConvexValue>,\n scope: IdScope.IdScope = IdScope.app,\n): PropertyValidators => {\n const ast = Schema.toEncoded(argsSchema).ast;\n\n return pipe(\n ast,\n Match.value,\n Match.tag(\"Objects\", (objectsAst) =>\n Array.isReadonlyArrayEmpty(objectsAst.indexSignatures)\n ? handlePropertySignatures(objectsAst, scope)\n : Effect.fail(new IndexSignaturesAreNotSupportedError()),\n ),\n Match.orElse(() => Effect.fail(new TopLevelMustBeObjectError())),\n Effect.runSync,\n );\n};\n\n// Returns\n\nexport const compileReturnsSchema = <ConfectValue, ConvexValue>(\n schema: Schema.Codec<ConfectValue, ConvexValue>,\n scope: IdScope.IdScope = IdScope.app,\n): Validator<any, any, any> =>\n Effect.runSync(compileAst(Schema.toEncoded(schema).ast, false, scope));\n\n// Table\n\n/**\n * Convert a table `Schema` to a table `Validator`.\n */\nexport type TableSchemaToTableValidator<\n TableSchema extends Schema.Codec<any, any>,\n> =\n ValueToValidator<TableSchema[\"Encoded\"]> extends infer Vd extends\n | VObject<any, any, any, any>\n | VUnion<any, any, any, any>\n ? Vd\n : never;\n\nexport const compileTableSchema = <TableSchema extends Schema.Codec<any, any>>(\n schema: TableSchema,\n scope: IdScope.IdScope = IdScope.app,\n): TableSchemaToTableValidator<TableSchema> => {\n const ast = Schema.toEncoded(schema).ast;\n\n return pipe(\n ast,\n Match.value,\n Match.tag(\"Objects\", ({ indexSignatures }) =>\n Array.isReadonlyArrayEmpty(indexSignatures)\n ? // oxlint-disable-next-line effecttsgo/unsafe-effect-type-assertion -- The return type is derived from the input schema and cannot be recovered from the runtime AST.\n (compileAst(ast, false, scope) as Effect.Effect<any>)\n : Effect.fail(new IndexSignaturesAreNotSupportedError()),\n ),\n Match.tag(\"Union\", (unionAst) => compileAst(unionAst, false, scope)),\n Match.orElse(() => Effect.fail(new TopLevelMustBeObjectOrUnionError())),\n Effect.runSync,\n );\n};\n\n// Compiler\n\nexport type ReadonlyValue =\n | string\n | number\n | bigint\n | boolean\n | ArrayBuffer\n | ReadonlyArrayValue\n | ReadonlyRecordValue\n | null;\n\ntype ReadonlyArrayValue = readonly ReadonlyValue[];\n\nexport type ReadonlyRecordValue = {\n readonly [key: string]: ReadonlyValue | undefined;\n};\n\ntype MutableValue<T> =\n T extends ReadonlyArray<infer El>\n ? MutableValue<El>[]\n : T extends ReadonlyRecordValue\n ? { -readonly [K in keyof T]: MutableValue<Exclude<T[K], undefined>> }\n : T;\n\nexport type ValueToValidator<Vl> = [Vl] extends [never]\n ? never\n : IsAny<Vl> extends true\n ? VAny\n : [Vl] extends [string | number | bigint | boolean | null | ArrayBuffer]\n ? ConvertValueToValidator<Vl>\n : IsRecursive<Vl> extends true\n ? VAny\n : [Vl] extends [ReadonlyValue]\n ? ConvertValueToValidator<Vl>\n : TypeError<\"Provided value is not a valid Convex value\", Vl>;\n\ntype OptionalValue<Vl, Optionality> = Optionality extends \"optional\"\n ? Vl | undefined\n : Vl;\n\ntype ConvertValueToValidator<\n Vl,\n Optionality extends \"required\" | \"optional\" = \"required\",\n> = [Vl] extends [never]\n ? never\n : IsAny<Vl> extends true\n ? VAny<any, Optionality>\n : [Vl] extends [null]\n ? VNull<OptionalValue<null, Optionality>, Optionality>\n : [Vl] extends [boolean]\n ? [boolean] extends [Vl]\n ? VBoolean<OptionalValue<boolean, Optionality>, Optionality>\n : VLiteral<OptionalValue<Vl, Optionality>, Optionality>\n : IsUnion<Vl> extends true\n ? UnionValueToValidator<Vl, Optionality>\n : [Vl] extends [number]\n ? [number] extends [Vl]\n ? VFloat64<OptionalValue<number, Optionality>, Optionality>\n : VLiteral<OptionalValue<Vl, Optionality>, Optionality>\n : [Vl] extends [bigint]\n ? [bigint] extends [Vl]\n ? VInt64<OptionalValue<bigint, Optionality>, Optionality>\n : VLiteral<OptionalValue<Vl, Optionality>, Optionality>\n : [Vl] extends [string]\n ? StringValueToValidator<Vl, Optionality>\n : [Vl] extends [ArrayBuffer]\n ? VBytes<OptionalValue<ArrayBuffer, Optionality>, Optionality>\n : IsRecursive<Vl> extends true\n ? VAny<any, Optionality>\n : Vl extends ReadonlyArray<infer El>\n ? VArray<\n OptionalValue<MutableValue<El[]>, Optionality>,\n ConvertValueToValidator<El>,\n Optionality\n >\n : Vl extends object\n ? ObjectValueToValidator<Vl, Optionality>\n : never;\n\ntype StringValueToValidator<Vl, Optionality extends \"required\" | \"optional\"> =\n Vl extends ConvexGenericId<string>\n ? VId<OptionalValue<Vl, Optionality>, Optionality>\n : [string] extends [Vl]\n ? VString<OptionalValue<string, Optionality>, Optionality>\n : VLiteral<OptionalValue<Vl, Optionality>, Optionality>;\n\ntype ObjectValueToValidator<Vl, Optionality extends \"required\" | \"optional\"> =\n IsRecord<MutableValue<Vl>> extends true\n ? ValueToValidator<Vl[keyof Vl]> extends infer VdValue extends Validator<\n any,\n \"required\",\n any\n >\n ? VRecord<\n OptionalValue<MutableValue<Vl>, Optionality>,\n VString,\n VdValue,\n Optionality\n >\n : never\n : ObjectFieldsToValidators<Vl> extends infer VdFields extends Record<\n string,\n any\n >\n ? VObject<\n OptionalValue<MutableValue<Vl>, Optionality>,\n VdFields,\n Optionality\n >\n : never;\n\ntype ObjectFieldsToValidators<Vl> = {\n -readonly [K in keyof Vl]-?: IsAny<Vl[K]> extends true\n ? IsOptional<Vl, K> extends true\n ? VAny<any, \"optional\">\n : VAny\n : undefined extends Vl[K]\n ? OptionalValueToValidator<Vl[K]>\n : [Vl[K]] extends [ReadonlyValue]\n ? ConvertValueToValidator<Vl[K]>\n : never;\n};\n\nexport type UndefinedOrValueToValidator<Vl extends ReadonlyValue | undefined> =\n undefined extends Vl\n ? OptionalValueToValidator<Vl>\n : [Vl] extends [ReadonlyValue]\n ? ValueToValidator<Vl>\n : never;\n\ntype UnionValueToValidator<Vl, Optionality extends \"required\" | \"optional\"> =\n IsRecursive<Vl> extends true\n ? VAny<any, Optionality>\n : VUnion<\n OptionalValue<MutableValue<Vl>, Optionality>,\n ValueTupleToValidatorTuple<UnionToTuple<Vl>>,\n Optionality\n >;\n\ntype ValueTupleToValidatorTuple<\n VlTuple extends readonly unknown[],\n Acc extends Validator<any, \"required\", any>[] = [],\n> = VlTuple extends\n | [true, false, ...infer VlRest]\n | [false, true, ...infer VlRest]\n ? ValueTupleToValidatorTuple<VlRest, [...Acc, VBoolean]>\n : VlTuple extends [infer Vl, ...infer VlRest]\n ? ValueTupleToValidatorTuple<VlRest, [...Acc, ConvertValueToValidator<Vl>]>\n : Acc;\n\ntype OptionalValueToValidator<Vl> = [Vl] extends [\n (infer Val extends ReadonlyValue) | undefined,\n]\n ? ConvertValueToValidator<Val, \"optional\">\n : never;\n\nexport const compileSchema = <T, E>(\n schema: Schema.Codec<T, E>,\n): ValueToValidator<(typeof schema)[\"Encoded\"]> =>\n Effect.runSync(compileAst(schema.ast)) as any;\n\nexport const isRecursive = (ast: SchemaAST.AST): boolean =>\n pipe(\n ast,\n Match.value,\n Match.tag(\n \"Literal\",\n \"Null\",\n \"Boolean\",\n \"String\",\n \"Number\",\n \"BigInt\",\n \"Unknown\",\n \"Any\",\n \"Declaration\",\n \"UniqueSymbol\",\n \"Symbol\",\n \"Undefined\",\n \"Void\",\n \"Never\",\n \"Enum\",\n \"TemplateLiteral\",\n \"ObjectKeyword\",\n () => false,\n ),\n Match.tag(\"Union\", ({ types }) =>\n Array.some(types, (type) => isRecursive(type)),\n ),\n Match.tag(\"Objects\", ({ propertySignatures }) =>\n Array.some(propertySignatures, ({ type }) => isRecursive(type)),\n ),\n Match.tag(\n \"Arrays\",\n ({ elements, rest }) =>\n Array.some(elements, (element) => isRecursive(element)) ||\n Array.some(rest, (element) => isRecursive(element)),\n ),\n Match.tag(\"Suspend\", () => true),\n Match.exhaustive,\n );\n\nexport const compileAst = (\n ast: SchemaAST.AST,\n isOptionalPropertyOfTypeLiteral = false,\n scope: IdScope.IdScope = IdScope.app,\n): Effect.Effect<\n Validator<any, any, any>,\n | UnsupportedSchemaTypeError\n | UnsupportedPropertySignatureKeyTypeError\n | IndexSignaturesAreNotSupportedError\n | MixedIndexAndPropertySignaturesAreNotSupportedError\n | OptionalTupleElementsAreNotSupportedError\n | EmptyTupleIsNotSupportedError\n | EmptyUnionIsNotSupportedError\n> =>\n isRecursive(ast)\n ? Effect.succeed(v.any())\n : pipe(\n ast,\n Match.value,\n Match.tag(\"Literal\", ({ literal }) =>\n pipe(\n literal,\n Match.value,\n Match.whenOr(\n Match.string,\n Match.number,\n Match.bigint,\n Match.boolean,\n (l) => v.literal(l),\n ),\n Match.exhaustive,\n Effect.succeed,\n ),\n ),\n Match.tag(\"Null\", () => Effect.succeed(v.null())),\n Match.tag(\"Boolean\", () => Effect.succeed(v.boolean())),\n Match.tag(\"String\", (stringAst) =>\n GenericId.tableName(stringAst).pipe(\n Option.match({\n onNone: () => Effect.succeed(v.string()),\n onSome: (tableName) =>\n Effect.succeed(\n GenericId.scope(stringAst) === scope\n ? v.id(tableName)\n : v.string(),\n ),\n }),\n ),\n ),\n Match.tag(\"Number\", () => Effect.succeed(v.float64())),\n Match.tag(\"BigInt\", () => Effect.succeed(v.int64())),\n Match.tag(\"Union\", (unionAst) =>\n handleUnion(unionAst, isOptionalPropertyOfTypeLiteral, scope),\n ),\n Match.tag(\"Objects\", (objectsAst) => handleObjects(objectsAst, scope)),\n Match.tag(\"Arrays\", (arraysAst) => handleArrays(arraysAst, scope)),\n Match.tag(\"Unknown\", \"Any\", () => Effect.succeed(v.any())),\n Match.tag(\"Declaration\", (declaration) =>\n Effect.mapBoth(\n // oxlint-disable-next-line effecttsgo/any-unknown-in-error-context -- Codec inputs are context-free, but Effect's SchemaAST.DeclarationRun erases their requirements to `any`.\n declaration.run(declaration.typeParameters)(\n new ArrayBuffer(0),\n declaration,\n {},\n ) as Effect.Effect<ArrayBuffer, unknown, never>,\n {\n onSuccess: () => v.bytes(),\n onFailure: () =>\n new UnsupportedSchemaTypeError({\n schemaType: declaration._tag,\n }),\n },\n ),\n ),\n Match.tag(\"Suspend\", () => Effect.succeed(v.any())),\n Match.tag(\n \"UniqueSymbol\",\n \"Symbol\",\n \"Undefined\",\n \"Void\",\n \"Never\",\n \"Enum\",\n \"TemplateLiteral\",\n \"ObjectKeyword\",\n () =>\n Effect.fail(\n new UnsupportedSchemaTypeError({\n schemaType: ast._tag,\n }),\n ),\n ),\n Match.exhaustive,\n );\n\nconst handleUnion = (\n { types }: SchemaAST.Union,\n isOptionalPropertyOfTypeLiteral: boolean,\n scope: IdScope.IdScope,\n) => handleUnionTypes(types, isOptionalPropertyOfTypeLiteral, scope);\n\nconst handleUnionTypes = Effect.fnUntraced(function* (\n types: SchemaAST.Union[\"types\"],\n isOptionalPropertyOfTypeLiteral: boolean,\n scope: IdScope.IdScope,\n) {\n const members = isOptionalPropertyOfTypeLiteral\n ? Array.filter(types, Predicate.not(SchemaAST.isUndefined))\n : types;\n\n const [firstValidator, secondValidator, ...restValidators] =\n yield* Effect.all(\n Array.map(members, (type) => compileAst(type, false, scope)),\n );\n\n if (firstValidator === undefined) {\n return yield* new EmptyUnionIsNotSupportedError();\n } else if (secondValidator === undefined) {\n return firstValidator;\n } else {\n return v.union(firstValidator, secondValidator, ...restValidators);\n }\n});\n\nconst handleObjects = (objectsAst: SchemaAST.Objects, scope: IdScope.IdScope) =>\n pipe(\n objectsAst.indexSignatures,\n Array.head,\n Option.match({\n onNone: () =>\n Effect.map(handlePropertySignatures(objectsAst, scope), v.object),\n onSome: ({ parameter, type }) =>\n pipe(\n objectsAst.propertySignatures,\n Array.head,\n Option.match({\n onNone: () =>\n Effect.map(\n Effect.all({\n parameter_: compileAst(parameter, false, scope),\n type_: compileAst(type, false, scope),\n }),\n ({ parameter_, type_ }) => v.record(parameter_, type_),\n ),\n onSome: () =>\n Effect.fail(\n new MixedIndexAndPropertySignaturesAreNotSupportedError(),\n ),\n }),\n ),\n }),\n );\n\nconst handleArrays = (\n { elements, rest }: SchemaAST.Arrays,\n scope: IdScope.IdScope,\n) => handleArrayElements(elements, rest, scope);\n\nconst handleArrayElements = Effect.fnUntraced(function* (\n elements: SchemaAST.Arrays[\"elements\"],\n rest: SchemaAST.Arrays[\"rest\"],\n scope: IdScope.IdScope,\n) {\n const [f, s, ...r] = elements;\n\n const elementToValidator = (element: SchemaAST.AST) =>\n SchemaAST.isOptional(element)\n ? Effect.fail(new OptionalTupleElementsAreNotSupportedError())\n : compileAst(element, false, scope);\n\n const arrayItemsValidator = yield* f === undefined\n ? pipe(\n rest,\n Array.head,\n Option.match({\n onNone: () => Effect.fail(new EmptyTupleIsNotSupportedError()),\n onSome: (type) => compileAst(type, false, scope),\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 = (\n objectsAst: SchemaAST.Objects,\n scope: IdScope.IdScope,\n) =>\n pipe(\n objectsAst.propertySignatures,\n Effect.forEach(({ type, name }) => {\n const isOptional = SchemaAST.isOptional(type);\n if (String.isString(name)) {\n // Somehow, somewhere, keys of type number are being coerced to strings…\n return Option.match(Number.parse(name), {\n onNone: () =>\n Effect.gen(function* () {\n const validator = yield* compileAst(type, isOptional, scope);\n\n return {\n propertyName: name,\n validator: isOptional ? v.optional(validator) : validator,\n };\n }),\n onSome: (number) =>\n Effect.fail(\n new UnsupportedPropertySignatureKeyTypeError({\n propertyKey: number,\n }),\n ),\n });\n } else {\n return Effect.fail(\n new UnsupportedPropertySignatureKeyTypeError({ propertyKey: name }),\n );\n }\n }),\n Effect.andThen((propertyNamesWithValidators) =>\n pipe(\n propertyNamesWithValidators,\n Array.reduce(\n {} as Record<string, Validator<any, any, any>>,\n (acc, { propertyName, validator }) => ({\n [propertyName]: validator,\n ...acc,\n }),\n ),\n Effect.succeed,\n ),\n ),\n );\n\n// Errors\n\nexport class TopLevelMustBeObjectError extends Data.TaggedError(\n \"TopLevelMustBeObjectError\",\n) {\n /* v8 ignore start */\n override get message() {\n return \"Top level schema must be an object\";\n }\n /* v8 ignore stop */\n}\n\nexport class TopLevelMustBeObjectOrUnionError extends Data.TaggedError(\n \"TopLevelMustBeObjectOrUnionError\",\n) {\n /* v8 ignore start */\n override get message() {\n return \"Top level schema must be an object or a union\";\n }\n /* v8 ignore stop */\n}\n\nexport class UnsupportedPropertySignatureKeyTypeError extends Data.TaggedError(\n \"UnsupportedPropertySignatureKeyTypeError\",\n)<{\n readonly propertyKey: number | symbol;\n}> {\n /* v8 ignore start */\n override get message() {\n return `Unsupported property signature '${this.propertyKey.toString()}'. Property is of type '${typeof this.propertyKey}' but only 'string' properties are supported.`;\n }\n /* v8 ignore stop */\n}\n\nexport class EmptyTupleIsNotSupportedError extends Data.TaggedError(\n \"EmptyTupleIsNotSupportedError\",\n) {\n /* v8 ignore start */\n override get message() {\n return \"Tuple must have at least one element\";\n }\n /* v8 ignore stop */\n}\n\nexport class EmptyUnionIsNotSupportedError extends Data.TaggedError(\n \"EmptyUnionIsNotSupportedError\",\n) {\n /* v8 ignore start */\n override get message() {\n return \"Union must have at least one member that compiles to a validator\";\n }\n /* v8 ignore stop */\n}\n\nexport class UnsupportedSchemaTypeError extends Data.TaggedError(\n \"UnsupportedSchemaTypeError\",\n)<{\n readonly schemaType: SchemaAST.AST[\"_tag\"];\n}> {\n /* v8 ignore start */\n override get message() {\n return `Unsupported schema type '${this.schemaType}'`;\n }\n /* v8 ignore stop */\n}\n\nexport class IndexSignaturesAreNotSupportedError extends Data.TaggedError(\n \"IndexSignaturesAreNotSupportedError\",\n) {\n /* v8 ignore start */\n override get message() {\n return \"Index signatures are not supported\";\n }\n /* v8 ignore stop */\n}\n\nexport class MixedIndexAndPropertySignaturesAreNotSupportedError extends Data.TaggedError(\n \"MixedIndexAndPropertySignaturesAreNotSupportedError\",\n) {\n /* v8 ignore start */\n override get message() {\n return \"Mixed index and property signatures are not supported\";\n }\n /* v8 ignore stop */\n}\n\nexport class OptionalTupleElementsAreNotSupportedError extends Data.TaggedError(\n \"OptionalTupleElementsAreNotSupportedError\",\n) {\n /* v8 ignore start */\n override get message() {\n return \"Optional tuple elements are not supported\";\n }\n /* v8 ignore stop */\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,MAAa,qBACX,YACA,QAAyBA,QACF;CACvB,MAAM,MAAM,OAAO,UAAU,UAAU,CAAC,CAAC;CAEzC,OAAO,KACL,KACA,MAAM,OACN,MAAM,IAAI,YAAY,eACpB,MAAM,qBAAqB,WAAW,eAAe,IACjD,yBAAyB,YAAY,KAAK,IAC1C,OAAO,KAAK,IAAI,oCAAoC,CAAC,CAC3D,GACA,MAAM,aAAa,OAAO,KAAK,IAAI,0BAA0B,CAAC,CAAC,GAC/D,OAAO,OACT;AACF;AAIA,MAAa,wBACX,QACA,QAAyBA,QAEzB,OAAO,QAAQ,WAAW,OAAO,UAAU,MAAM,CAAC,CAAC,KAAK,OAAO,KAAK,CAAC;AAgBvE,MAAa,sBACX,QACA,QAAyBA,QACoB;CAC7C,MAAM,MAAM,OAAO,UAAU,MAAM,CAAC,CAAC;CAErC,OAAO,KACL,KACA,MAAM,OACN,MAAM,IAAI,YAAY,EAAE,sBACtB,MAAM,qBAAqB,eAAe,IAErC,WAAW,KAAK,OAAO,KAAK,IAC7B,OAAO,KAAK,IAAI,oCAAoC,CAAC,CAC3D,GACA,MAAM,IAAI,UAAU,aAAa,WAAW,UAAU,OAAO,KAAK,CAAC,GACnE,MAAM,aAAa,OAAO,KAAK,IAAI,iCAAiC,CAAC,CAAC,GACtE,OAAO,OACT;AACF;AA+JA,MAAa,iBACX,WAEA,OAAO,QAAQ,WAAW,OAAO,GAAG,CAAC;AAEvC,MAAa,eAAe,QAC1B,KACE,KACA,MAAM,OACN,MAAM,IACJ,WACA,QACA,WACA,UACA,UACA,UACA,WACA,OACA,eACA,gBACA,UACA,aACA,QACA,SACA,QACA,mBACA,uBACM,KACR,GACA,MAAM,IAAI,UAAU,EAAE,YACpB,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EA,IAAa,sDAAb,cAAyE,KAAK,YAC5E,qDACF,CAAC,CAAC;;CAEA,IAAa,UAAU;EACrB,OAAO;CACT;AAEF;AAEA,IAAa,4CAAb,cAA+D,KAAK,YAClE,2CACF,CAAC,CAAC;;CAEA,IAAa,UAAU;EACrB,OAAO;CACT;AAEF"}
|
|
1
|
+
{"version":3,"file":"SchemaToValidator.js","names":["IdScope.app","GenericId.tableName","GenericId.scope","scope"],"sources":["../src/SchemaToValidator.ts"],"sourcesContent":["import * as IdScope from \"./IdScope.js\";\nimport type {\n GenericId as ConvexGenericId,\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 VRecord,\n VString,\n VUnion,\n} from \"convex/values\";\nimport { v } from \"convex/values\";\nimport { pipe } from \"effect/Function\";\nimport * as Array from \"effect/Array\";\nimport * as Data from \"effect/Data\";\nimport * as Effect from \"effect/Effect\";\nimport * as Match from \"effect/Match\";\nimport * as Number from \"effect/Number\";\nimport * as Option from \"effect/Option\";\nimport * as Predicate from \"effect/Predicate\";\nimport * as Schema from \"effect/Schema\";\nimport * as SchemaAST from \"effect/SchemaAST\";\nimport * as String from \"effect/String\";\n\nimport * as GenericId from \"./GenericId.js\";\nimport type {\n IsAny,\n IsOptional,\n IsRecord,\n IsRecursive,\n IsUnion,\n TypeError,\n UnionToTuple,\n} from \"./Types.js\";\n\n// Args\n\nexport const compileArgsSchema = <ConfectValue, ConvexValue>(\n argsSchema: Schema.Codec<ConfectValue, ConvexValue>,\n scope: IdScope.IdScope = IdScope.app,\n reservedArgument?: string,\n functionName?: string,\n): PropertyValidators => {\n const ast = Schema.toEncoded(argsSchema).ast;\n\n const validators = pipe(\n ast,\n Match.value,\n Match.tag(\"Objects\", (objectsAst) =>\n Array.isReadonlyArrayEmpty(objectsAst.indexSignatures)\n ? handlePropertySignatures(objectsAst, scope)\n : Effect.fail(new IndexSignaturesAreNotSupportedError()),\n ),\n Match.orElse(() => Effect.fail(new TopLevelMustBeObjectError())),\n Effect.runSync,\n );\n if (reservedArgument === undefined) return validators;\n if (Object.hasOwn(validators, reservedArgument)) {\n throw new ReservedArgumentCollision({\n functionName,\n argument: reservedArgument,\n });\n }\n return { ...validators, [reservedArgument]: v.optional(v.any()) };\n};\n\nexport class ReservedArgumentCollision extends Data.TaggedError(\n \"ReservedArgumentCollision\",\n)<{\n readonly functionName: string | undefined;\n readonly argument: string;\n}> {\n override get message() {\n return `${this.functionName} declares the argument \"${this.argument}\", which its profile reserves. Rename the argument.`;\n }\n}\n\n// Returns\n\nexport const compileReturnsSchema = <ConfectValue, ConvexValue>(\n schema: Schema.Codec<ConfectValue, ConvexValue>,\n scope: IdScope.IdScope = IdScope.app,\n): Validator<any, any, any> =>\n Effect.runSync(compileAst(Schema.toEncoded(schema).ast, false, scope));\n\n// Table\n\n/**\n * Convert a table `Schema` to a table `Validator`.\n */\nexport type TableSchemaToTableValidator<\n TableSchema extends Schema.Codec<any, any>,\n> =\n ValueToValidator<TableSchema[\"Encoded\"]> extends infer Vd extends\n | VObject<any, any, any, any>\n | VUnion<any, any, any, any>\n ? Vd\n : never;\n\nexport const compileTableSchema = <TableSchema extends Schema.Codec<any, any>>(\n schema: TableSchema,\n scope: IdScope.IdScope = IdScope.app,\n): TableSchemaToTableValidator<TableSchema> => {\n const ast = Schema.toEncoded(schema).ast;\n\n return pipe(\n ast,\n Match.value,\n Match.tag(\"Objects\", ({ indexSignatures }) =>\n Array.isReadonlyArrayEmpty(indexSignatures)\n ? // oxlint-disable-next-line effecttsgo/unsafe-effect-type-assertion -- The return type is derived from the input schema and cannot be recovered from the runtime AST.\n (compileAst(ast, false, scope) as Effect.Effect<any>)\n : Effect.fail(new IndexSignaturesAreNotSupportedError()),\n ),\n Match.tag(\"Union\", (unionAst) => compileAst(unionAst, false, scope)),\n Match.orElse(() => Effect.fail(new TopLevelMustBeObjectOrUnionError())),\n Effect.runSync,\n );\n};\n\n// Compiler\n\nexport type ReadonlyValue =\n | string\n | number\n | bigint\n | boolean\n | ArrayBuffer\n | ReadonlyArrayValue\n | ReadonlyRecordValue\n | null;\n\ntype ReadonlyArrayValue = readonly ReadonlyValue[];\n\nexport type ReadonlyRecordValue = {\n readonly [key: string]: ReadonlyValue | undefined;\n};\n\ntype MutableValue<T> =\n T extends ReadonlyArray<infer El>\n ? MutableValue<El>[]\n : T extends ReadonlyRecordValue\n ? { -readonly [K in keyof T]: MutableValue<Exclude<T[K], undefined>> }\n : T;\n\nexport type ValueToValidator<Vl> = [Vl] extends [never]\n ? never\n : IsAny<Vl> extends true\n ? VAny\n : [Vl] extends [string | number | bigint | boolean | null | ArrayBuffer]\n ? ConvertValueToValidator<Vl>\n : IsRecursive<Vl> extends true\n ? VAny\n : [Vl] extends [ReadonlyValue]\n ? ConvertValueToValidator<Vl>\n : TypeError<\"Provided value is not a valid Convex value\", Vl>;\n\ntype OptionalValue<Vl, Optionality> = Optionality extends \"optional\"\n ? Vl | undefined\n : Vl;\n\ntype ConvertValueToValidator<\n Vl,\n Optionality extends \"required\" | \"optional\" = \"required\",\n> = [Vl] extends [never]\n ? never\n : IsAny<Vl> extends true\n ? VAny<any, Optionality>\n : [Vl] extends [null]\n ? VNull<OptionalValue<null, Optionality>, Optionality>\n : [Vl] extends [boolean]\n ? [boolean] extends [Vl]\n ? VBoolean<OptionalValue<boolean, Optionality>, Optionality>\n : VLiteral<OptionalValue<Vl, Optionality>, Optionality>\n : IsUnion<Vl> extends true\n ? UnionValueToValidator<Vl, Optionality>\n : [Vl] extends [number]\n ? [number] extends [Vl]\n ? VFloat64<OptionalValue<number, Optionality>, Optionality>\n : VLiteral<OptionalValue<Vl, Optionality>, Optionality>\n : [Vl] extends [bigint]\n ? [bigint] extends [Vl]\n ? VInt64<OptionalValue<bigint, Optionality>, Optionality>\n : VLiteral<OptionalValue<Vl, Optionality>, Optionality>\n : [Vl] extends [string]\n ? StringValueToValidator<Vl, Optionality>\n : [Vl] extends [ArrayBuffer]\n ? VBytes<OptionalValue<ArrayBuffer, Optionality>, Optionality>\n : IsRecursive<Vl> extends true\n ? VAny<any, Optionality>\n : Vl extends ReadonlyArray<infer El>\n ? VArray<\n OptionalValue<MutableValue<El[]>, Optionality>,\n ConvertValueToValidator<El>,\n Optionality\n >\n : Vl extends object\n ? ObjectValueToValidator<Vl, Optionality>\n : never;\n\ntype StringValueToValidator<Vl, Optionality extends \"required\" | \"optional\"> =\n Vl extends ConvexGenericId<string>\n ? VId<OptionalValue<Vl, Optionality>, Optionality>\n : [string] extends [Vl]\n ? VString<OptionalValue<string, Optionality>, Optionality>\n : VLiteral<OptionalValue<Vl, Optionality>, Optionality>;\n\ntype ObjectValueToValidator<Vl, Optionality extends \"required\" | \"optional\"> =\n IsRecord<MutableValue<Vl>> extends true\n ? ValueToValidator<Vl[keyof Vl]> extends infer VdValue extends Validator<\n any,\n \"required\",\n any\n >\n ? VRecord<\n OptionalValue<MutableValue<Vl>, Optionality>,\n VString,\n VdValue,\n Optionality\n >\n : never\n : ObjectFieldsToValidators<Vl> extends infer VdFields extends Record<\n string,\n any\n >\n ? VObject<\n OptionalValue<MutableValue<Vl>, Optionality>,\n VdFields,\n Optionality\n >\n : never;\n\ntype ObjectFieldsToValidators<Vl> = {\n -readonly [K in keyof Vl]-?: IsAny<Vl[K]> extends true\n ? IsOptional<Vl, K> extends true\n ? VAny<any, \"optional\">\n : VAny\n : undefined extends Vl[K]\n ? OptionalValueToValidator<Vl[K]>\n : [Vl[K]] extends [ReadonlyValue]\n ? ConvertValueToValidator<Vl[K]>\n : never;\n};\n\nexport type UndefinedOrValueToValidator<Vl extends ReadonlyValue | undefined> =\n undefined extends Vl\n ? OptionalValueToValidator<Vl>\n : [Vl] extends [ReadonlyValue]\n ? ValueToValidator<Vl>\n : never;\n\ntype UnionValueToValidator<Vl, Optionality extends \"required\" | \"optional\"> =\n IsRecursive<Vl> extends true\n ? VAny<any, Optionality>\n : VUnion<\n OptionalValue<MutableValue<Vl>, Optionality>,\n ValueTupleToValidatorTuple<UnionToTuple<Vl>>,\n Optionality\n >;\n\ntype ValueTupleToValidatorTuple<\n VlTuple extends readonly unknown[],\n Acc extends Validator<any, \"required\", any>[] = [],\n> = VlTuple extends\n | [true, false, ...infer VlRest]\n | [false, true, ...infer VlRest]\n ? ValueTupleToValidatorTuple<VlRest, [...Acc, VBoolean]>\n : VlTuple extends [infer Vl, ...infer VlRest]\n ? ValueTupleToValidatorTuple<VlRest, [...Acc, ConvertValueToValidator<Vl>]>\n : Acc;\n\ntype OptionalValueToValidator<Vl> = [Vl] extends [\n (infer Val extends ReadonlyValue) | undefined,\n]\n ? ConvertValueToValidator<Val, \"optional\">\n : never;\n\nexport const compileSchema = <T, E>(\n schema: Schema.Codec<T, E>,\n): ValueToValidator<(typeof schema)[\"Encoded\"]> =>\n Effect.runSync(compileAst(schema.ast)) as any;\n\nexport const isRecursive = (ast: SchemaAST.AST): boolean =>\n pipe(\n ast,\n Match.value,\n Match.tag(\n \"Literal\",\n \"Null\",\n \"Boolean\",\n \"String\",\n \"Number\",\n \"BigInt\",\n \"Unknown\",\n \"Any\",\n \"Declaration\",\n \"UniqueSymbol\",\n \"Symbol\",\n \"Undefined\",\n \"Void\",\n \"Never\",\n \"Enum\",\n \"TemplateLiteral\",\n \"ObjectKeyword\",\n () => false,\n ),\n Match.tag(\"Union\", ({ types }) =>\n Array.some(types, (type) => isRecursive(type)),\n ),\n Match.tag(\"Objects\", ({ propertySignatures }) =>\n Array.some(propertySignatures, ({ type }) => isRecursive(type)),\n ),\n Match.tag(\n \"Arrays\",\n ({ elements, rest }) =>\n Array.some(elements, (element) => isRecursive(element)) ||\n Array.some(rest, (element) => isRecursive(element)),\n ),\n Match.tag(\"Suspend\", () => true),\n Match.exhaustive,\n );\n\nexport const compileAst = (\n ast: SchemaAST.AST,\n isOptionalPropertyOfTypeLiteral = false,\n scope: IdScope.IdScope = IdScope.app,\n): Effect.Effect<\n Validator<any, any, any>,\n | UnsupportedSchemaTypeError\n | UnsupportedPropertySignatureKeyTypeError\n | IndexSignaturesAreNotSupportedError\n | MixedIndexAndPropertySignaturesAreNotSupportedError\n | OptionalTupleElementsAreNotSupportedError\n | EmptyTupleIsNotSupportedError\n | EmptyUnionIsNotSupportedError\n> =>\n isRecursive(ast)\n ? Effect.succeed(v.any())\n : pipe(\n ast,\n Match.value,\n Match.tag(\"Literal\", ({ literal }) =>\n pipe(\n literal,\n Match.value,\n Match.whenOr(\n Match.string,\n Match.number,\n Match.bigint,\n Match.boolean,\n (l) => v.literal(l),\n ),\n Match.exhaustive,\n Effect.succeed,\n ),\n ),\n Match.tag(\"Null\", () => Effect.succeed(v.null())),\n Match.tag(\"Boolean\", () => Effect.succeed(v.boolean())),\n Match.tag(\"String\", (stringAst) =>\n GenericId.tableName(stringAst).pipe(\n Option.match({\n onNone: () => Effect.succeed(v.string()),\n onSome: (tableName) =>\n Effect.succeed(\n GenericId.scope(stringAst) === scope\n ? v.id(tableName)\n : v.string(),\n ),\n }),\n ),\n ),\n Match.tag(\"Number\", () => Effect.succeed(v.float64())),\n Match.tag(\"BigInt\", () => Effect.succeed(v.int64())),\n Match.tag(\"Union\", (unionAst) =>\n handleUnion(unionAst, isOptionalPropertyOfTypeLiteral, scope),\n ),\n Match.tag(\"Objects\", (objectsAst) => handleObjects(objectsAst, scope)),\n Match.tag(\"Arrays\", (arraysAst) => handleArrays(arraysAst, scope)),\n Match.tag(\"Unknown\", \"Any\", () => Effect.succeed(v.any())),\n Match.tag(\"Declaration\", (declaration) =>\n Effect.mapBoth(\n // oxlint-disable-next-line effecttsgo/any-unknown-in-error-context -- Codec inputs are context-free, but Effect's SchemaAST.DeclarationRun erases their requirements to `any`.\n declaration.run(declaration.typeParameters)(\n new ArrayBuffer(0),\n declaration,\n {},\n ) as Effect.Effect<ArrayBuffer, unknown, never>,\n {\n onSuccess: () => v.bytes(),\n onFailure: () =>\n new UnsupportedSchemaTypeError({\n schemaType: declaration._tag,\n }),\n },\n ),\n ),\n Match.tag(\"Suspend\", () => Effect.succeed(v.any())),\n Match.tag(\n \"UniqueSymbol\",\n \"Symbol\",\n \"Undefined\",\n \"Void\",\n \"Never\",\n \"Enum\",\n \"TemplateLiteral\",\n \"ObjectKeyword\",\n () =>\n Effect.fail(\n new UnsupportedSchemaTypeError({\n schemaType: ast._tag,\n }),\n ),\n ),\n Match.exhaustive,\n );\n\nconst handleUnion = (\n { types }: SchemaAST.Union,\n isOptionalPropertyOfTypeLiteral: boolean,\n scope: IdScope.IdScope,\n) => handleUnionTypes(types, isOptionalPropertyOfTypeLiteral, scope);\n\nconst handleUnionTypes = Effect.fnUntraced(function* (\n types: SchemaAST.Union[\"types\"],\n isOptionalPropertyOfTypeLiteral: boolean,\n scope: IdScope.IdScope,\n) {\n const members = isOptionalPropertyOfTypeLiteral\n ? Array.filter(types, Predicate.not(SchemaAST.isUndefined))\n : types;\n\n const [firstValidator, secondValidator, ...restValidators] =\n yield* Effect.all(\n Array.map(members, (type) => compileAst(type, false, scope)),\n );\n\n if (firstValidator === undefined) {\n return yield* new EmptyUnionIsNotSupportedError();\n } else if (secondValidator === undefined) {\n return firstValidator;\n } else {\n return v.union(firstValidator, secondValidator, ...restValidators);\n }\n});\n\nconst handleObjects = (objectsAst: SchemaAST.Objects, scope: IdScope.IdScope) =>\n pipe(\n objectsAst.indexSignatures,\n Array.head,\n Option.match({\n onNone: () =>\n Effect.map(handlePropertySignatures(objectsAst, scope), v.object),\n onSome: ({ parameter, type }) =>\n pipe(\n objectsAst.propertySignatures,\n Array.head,\n Option.match({\n onNone: () =>\n Effect.map(\n Effect.all({\n parameter_: compileAst(parameter, false, scope),\n type_: compileAst(type, false, scope),\n }),\n ({ parameter_, type_ }) => v.record(parameter_, type_),\n ),\n onSome: () =>\n Effect.fail(\n new MixedIndexAndPropertySignaturesAreNotSupportedError(),\n ),\n }),\n ),\n }),\n );\n\nconst handleArrays = (\n { elements, rest }: SchemaAST.Arrays,\n scope: IdScope.IdScope,\n) => handleArrayElements(elements, rest, scope);\n\nconst handleArrayElements = Effect.fnUntraced(function* (\n elements: SchemaAST.Arrays[\"elements\"],\n rest: SchemaAST.Arrays[\"rest\"],\n scope: IdScope.IdScope,\n) {\n const [f, s, ...r] = elements;\n\n const elementToValidator = (element: SchemaAST.AST) =>\n SchemaAST.isOptional(element)\n ? Effect.fail(new OptionalTupleElementsAreNotSupportedError())\n : compileAst(element, false, scope);\n\n const arrayItemsValidator = yield* f === undefined\n ? pipe(\n rest,\n Array.head,\n Option.match({\n onNone: () => Effect.fail(new EmptyTupleIsNotSupportedError()),\n onSome: (type) => compileAst(type, false, scope),\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 = (\n objectsAst: SchemaAST.Objects,\n scope: IdScope.IdScope,\n) =>\n pipe(\n objectsAst.propertySignatures,\n Effect.forEach(({ type, name }) => {\n const isOptional = SchemaAST.isOptional(type);\n if (String.isString(name)) {\n // Somehow, somewhere, keys of type number are being coerced to strings…\n return Option.match(Number.parse(name), {\n onNone: () =>\n Effect.gen(function* () {\n const validator = yield* compileAst(type, isOptional, scope);\n\n return {\n propertyName: name,\n validator: isOptional ? v.optional(validator) : validator,\n };\n }),\n onSome: (number) =>\n Effect.fail(\n new UnsupportedPropertySignatureKeyTypeError({\n propertyKey: number,\n }),\n ),\n });\n } else {\n return Effect.fail(\n new UnsupportedPropertySignatureKeyTypeError({ propertyKey: name }),\n );\n }\n }),\n Effect.andThen((propertyNamesWithValidators) =>\n pipe(\n propertyNamesWithValidators,\n Array.reduce(\n {} as Record<string, Validator<any, any, any>>,\n (acc, { propertyName, validator }) => ({\n [propertyName]: validator,\n ...acc,\n }),\n ),\n Effect.succeed,\n ),\n ),\n );\n\n// Errors\n\nexport class TopLevelMustBeObjectError extends Data.TaggedError(\n \"TopLevelMustBeObjectError\",\n) {\n /* v8 ignore start */\n override get message() {\n return \"Top level schema must be an object\";\n }\n /* v8 ignore stop */\n}\n\nexport class TopLevelMustBeObjectOrUnionError extends Data.TaggedError(\n \"TopLevelMustBeObjectOrUnionError\",\n) {\n /* v8 ignore start */\n override get message() {\n return \"Top level schema must be an object or a union\";\n }\n /* v8 ignore stop */\n}\n\nexport class UnsupportedPropertySignatureKeyTypeError extends Data.TaggedError(\n \"UnsupportedPropertySignatureKeyTypeError\",\n)<{\n readonly propertyKey: number | symbol;\n}> {\n /* v8 ignore start */\n override get message() {\n return `Unsupported property signature '${this.propertyKey.toString()}'. Property is of type '${typeof this.propertyKey}' but only 'string' properties are supported.`;\n }\n /* v8 ignore stop */\n}\n\nexport class EmptyTupleIsNotSupportedError extends Data.TaggedError(\n \"EmptyTupleIsNotSupportedError\",\n) {\n /* v8 ignore start */\n override get message() {\n return \"Tuple must have at least one element\";\n }\n /* v8 ignore stop */\n}\n\nexport class EmptyUnionIsNotSupportedError extends Data.TaggedError(\n \"EmptyUnionIsNotSupportedError\",\n) {\n /* v8 ignore start */\n override get message() {\n return \"Union must have at least one member that compiles to a validator\";\n }\n /* v8 ignore stop */\n}\n\nexport class UnsupportedSchemaTypeError extends Data.TaggedError(\n \"UnsupportedSchemaTypeError\",\n)<{\n readonly schemaType: SchemaAST.AST[\"_tag\"];\n}> {\n /* v8 ignore start */\n override get message() {\n return `Unsupported schema type '${this.schemaType}'`;\n }\n /* v8 ignore stop */\n}\n\nexport class IndexSignaturesAreNotSupportedError extends Data.TaggedError(\n \"IndexSignaturesAreNotSupportedError\",\n) {\n /* v8 ignore start */\n override get message() {\n return \"Index signatures are not supported\";\n }\n /* v8 ignore stop */\n}\n\nexport class MixedIndexAndPropertySignaturesAreNotSupportedError extends Data.TaggedError(\n \"MixedIndexAndPropertySignaturesAreNotSupportedError\",\n) {\n /* v8 ignore start */\n override get message() {\n return \"Mixed index and property signatures are not supported\";\n }\n /* v8 ignore stop */\n}\n\nexport class OptionalTupleElementsAreNotSupportedError extends Data.TaggedError(\n \"OptionalTupleElementsAreNotSupportedError\",\n) {\n /* v8 ignore start */\n override get message() {\n return \"Optional tuple elements are not supported\";\n }\n /* v8 ignore stop */\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,MAAa,qBACX,YACA,QAAyBA,KACzB,kBACA,iBACuB;CACvB,MAAM,MAAM,OAAO,UAAU,UAAU,CAAC,CAAC;CAEzC,MAAM,aAAa,KACjB,KACA,MAAM,OACN,MAAM,IAAI,YAAY,eACpB,MAAM,qBAAqB,WAAW,eAAe,IACjD,yBAAyB,YAAY,KAAK,IAC1C,OAAO,KAAK,IAAI,oCAAoC,CAAC,CAC3D,GACA,MAAM,aAAa,OAAO,KAAK,IAAI,0BAA0B,CAAC,CAAC,GAC/D,OAAO,OACT;CACA,IAAI,qBAAqB,KAAA,GAAW,OAAO;CAC3C,IAAI,OAAO,OAAO,YAAY,gBAAgB,GAC5C,MAAM,IAAI,0BAA0B;EAClC;EACA,UAAU;CACZ,CAAC;CAEH,OAAO;EAAE,GAAG;GAAa,mBAAmB,EAAE,SAAS,EAAE,IAAI,CAAC;CAAE;AAClE;AAEA,IAAa,4BAAb,cAA+C,KAAK,YAClD,2BACF,CAAC,CAGE;CACD,IAAa,UAAU;EACrB,OAAO,GAAG,KAAK,aAAa,0BAA0B,KAAK,SAAS;CACtE;AACF;AAIA,MAAa,wBACX,QACA,QAAyBA,QAEzB,OAAO,QAAQ,WAAW,OAAO,UAAU,MAAM,CAAC,CAAC,KAAK,OAAO,KAAK,CAAC;AAgBvE,MAAa,sBACX,QACA,QAAyBA,QACoB;CAC7C,MAAM,MAAM,OAAO,UAAU,MAAM,CAAC,CAAC;CAErC,OAAO,KACL,KACA,MAAM,OACN,MAAM,IAAI,YAAY,EAAE,sBACtB,MAAM,qBAAqB,eAAe,IAErC,WAAW,KAAK,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AAK,YAAY;CAC1H;AAEF;AAEA,IAAa,gCAAb,cAAmD,KAAK,YACtD,+BACF,CAAC,CAAC;;CAEA,IAAa,UAAU;EACrB,OAAO;CACT;AAEF;AAEA,IAAa,gCAAb,cAAmD,KAAK,YACtD,+BACF,CAAC,CAAC;;CAEA,IAAa,UAAU;EACrB,OAAO;CACT;AAEF;AAEA,IAAa,6BAAb,cAAgD,KAAK,YACnD,4BACF,CAAC,CAEE;;CAED,IAAa,UAAU;EACrB,OAAO,4BAA4B,KAAK,WAAW;CACrD;AAEF;AAEA,IAAa,sCAAb,cAAyD,KAAK,YAC5D,qCACF,CAAC,CAAC;;CAEA,IAAa,UAAU;EACrB,OAAO;CACT;AAEF;AAEA,IAAa,sDAAb,cAAyE,KAAK,YAC5E,qDACF,CAAC,CAAC;;CAEA,IAAa,UAAU;EACrB,OAAO;CACT;AAEF;AAEA,IAAa,4CAAb,cAA+D,KAAK,YAClE,2CACF,CAAC,CAAC;;CAEA,IAAa,UAAU;EACrB,OAAO;CACT;AAEF"}
|
package/dist/SystemFields.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
2
|
import { GenericId } from "./GenericId.js";
|
|
3
|
-
import * as Predicate from "effect/Predicate";
|
|
4
3
|
import * as Schema from "effect/Schema";
|
|
4
|
+
import * as Predicate from "effect/Predicate";
|
|
5
5
|
import * as SchemaGetter from "effect/SchemaGetter";
|
|
6
6
|
import * as Effect from "effect/Effect";
|
|
7
7
|
import * as Option from "effect/Option";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export * as ActionCall from "./ActionCall.js";
|
|
1
2
|
export * as Callback from "./Callback.js";
|
|
2
3
|
export * as FunctionProvenance from "./FunctionProvenance.js";
|
|
3
4
|
export * as FunctionSpec from "./FunctionSpec.js";
|
|
@@ -13,11 +14,13 @@ export * as GroupSpec from "./GroupSpec.js";
|
|
|
13
14
|
export * as Identifier from "./Identifier.js";
|
|
14
15
|
export * as Lazy from "./Lazy.js";
|
|
15
16
|
export * as Manifest from "./Manifest.js";
|
|
17
|
+
export * as ManifestSection from "./ManifestSection.js";
|
|
16
18
|
export * as MiddlewareAttachment from "./MiddlewareAttachment.js";
|
|
17
19
|
export * as MiddlewareSpec from "./MiddlewareSpec.js";
|
|
18
20
|
export * as PaginationError from "./PaginationError.js";
|
|
19
21
|
export * as PaginationOptions from "./PaginationOptions.js";
|
|
20
22
|
export * as PaginationResult from "./PaginationResult.js";
|
|
23
|
+
export * as Profile from "./Profile.js";
|
|
21
24
|
export * as Ref from "./Ref.js";
|
|
22
25
|
export * as Refs from "./Refs.js";
|
|
23
26
|
export * as RuntimeAndFunctionType from "./RuntimeAndFunctionType.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,kBAAkB,MAAM,yBAAyB,CAAC;AAC9D,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAC;AAClD,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAC;AAC9C,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OA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O,KAAK,SAAS,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAC;AAC9C,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,eAAe,MAAM,sBAAsB,CAAC;AACxD,OAAO,KAAK,oBAAoB,MAAM,2BAA2B,CAAC;AAClE,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAC;AACtD,OAAO,KAAK,eAAe,MAAM,sBAAsB,CAAC;AACxD,OAAO,KAAK,iBAAiB,MAAM,wBAAwB,CAAC;AAC5D,OAAO,KAAK,gBAAgB,MAAM,uBAAuB,CAAC;AAC1D,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,sBAAsB,MAAM,6BAA6B,CAAC;AACtE,OAAO,KAAK,iBAAiB,MAAM,wBAAwB,CAAC;AAC5D,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAC;AAClD,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,30 +1,33 @@
|
|
|
1
|
-
import { App_exports } from "./App.js";
|
|
2
|
-
import { Auth_exports } from "./Auth.js";
|
|
3
1
|
import { Lazy_exports } from "./Lazy.js";
|
|
4
2
|
import { PaginationOptions_exports } from "./PaginationOptions.js";
|
|
5
3
|
import { PaginationResult_exports } from "./PaginationResult.js";
|
|
6
4
|
import { FunctionProvenance_exports } from "./FunctionProvenance.js";
|
|
5
|
+
import { Identifier_exports } from "./Identifier.js";
|
|
7
6
|
import { MiddlewareSpec_exports } from "./MiddlewareSpec.js";
|
|
7
|
+
import { RuntimeAndFunctionType_exports } from "./RuntimeAndFunctionType.js";
|
|
8
|
+
import { FunctionSpec_exports } from "./FunctionSpec.js";
|
|
9
|
+
import { ActionCall_exports } from "./ActionCall.js";
|
|
10
|
+
import { App_exports } from "./App.js";
|
|
11
|
+
import { Auth_exports } from "./Auth.js";
|
|
8
12
|
import { Ref_exports } from "./Ref.js";
|
|
9
13
|
import { Callback_exports } from "./Callback.js";
|
|
10
14
|
import { IdScope_exports } from "./IdScope.js";
|
|
11
15
|
import { GenericId_exports } from "./GenericId.js";
|
|
12
16
|
import { MiddlewareAttachment_exports } from "./MiddlewareAttachment.js";
|
|
13
|
-
import { Identifier_exports } from "./Identifier.js";
|
|
14
17
|
import { GroupSpec_exports } from "./GroupSpec.js";
|
|
15
18
|
import { Spec_exports } from "./Spec.js";
|
|
16
19
|
import { Component_exports } from "./Component.js";
|
|
17
20
|
import { Env_exports } from "./Env.js";
|
|
18
|
-
import { RuntimeAndFunctionType_exports } from "./RuntimeAndFunctionType.js";
|
|
19
|
-
import { FunctionSpec_exports } from "./FunctionSpec.js";
|
|
20
21
|
import { GroupPath_exports } from "./GroupPath.js";
|
|
21
22
|
import { Http_exports } from "./Http.js";
|
|
22
23
|
import { Manifest_exports } from "./Manifest.js";
|
|
24
|
+
import { ManifestSection_exports } from "./ManifestSection.js";
|
|
23
25
|
import { PaginationError_exports } from "./PaginationError.js";
|
|
26
|
+
import { Profile_exports } from "./Profile.js";
|
|
24
27
|
import { Refs_exports } from "./Refs.js";
|
|
25
28
|
import { SchemaToValidator_exports } from "./SchemaToValidator.js";
|
|
26
29
|
import { SystemFields_exports } from "./SystemFields.js";
|
|
27
30
|
import { Table_exports } from "./Table.js";
|
|
28
31
|
import { Types_exports } from "./Types.js";
|
|
29
32
|
import { UserIdentity_exports } from "./UserIdentity.js";
|
|
30
|
-
export { App_exports as App, Auth_exports as Auth, Callback_exports as Callback, Component_exports as Component, Env_exports as Env, FunctionProvenance_exports as FunctionProvenance, FunctionSpec_exports as FunctionSpec, GenericId_exports as GenericId, GroupPath_exports as GroupPath, GroupSpec_exports as GroupSpec, Http_exports as Http, IdScope_exports as IdScope, Identifier_exports as Identifier, Lazy_exports as Lazy, Manifest_exports as Manifest, MiddlewareAttachment_exports as MiddlewareAttachment, MiddlewareSpec_exports as MiddlewareSpec, PaginationError_exports as PaginationError, PaginationOptions_exports as PaginationOptions, PaginationResult_exports as PaginationResult, Ref_exports as Ref, Refs_exports as Refs, RuntimeAndFunctionType_exports as RuntimeAndFunctionType, SchemaToValidator_exports as SchemaToValidator, Spec_exports as Spec, SystemFields_exports as SystemFields, Table_exports as Table, Types_exports as Types, UserIdentity_exports as UserIdentity };
|
|
33
|
+
export { ActionCall_exports as ActionCall, App_exports as App, Auth_exports as Auth, Callback_exports as Callback, Component_exports as Component, Env_exports as Env, FunctionProvenance_exports as FunctionProvenance, FunctionSpec_exports as FunctionSpec, GenericId_exports as GenericId, GroupPath_exports as GroupPath, GroupSpec_exports as GroupSpec, Http_exports as Http, IdScope_exports as IdScope, Identifier_exports as Identifier, Lazy_exports as Lazy, Manifest_exports as Manifest, ManifestSection_exports as ManifestSection, MiddlewareAttachment_exports as MiddlewareAttachment, MiddlewareSpec_exports as MiddlewareSpec, PaginationError_exports as PaginationError, PaginationOptions_exports as PaginationOptions, PaginationResult_exports as PaginationResult, Profile_exports as Profile, Ref_exports as Ref, Refs_exports as Refs, RuntimeAndFunctionType_exports as RuntimeAndFunctionType, SchemaToValidator_exports as SchemaToValidator, Spec_exports as Spec, SystemFields_exports as SystemFields, Table_exports as Table, Types_exports as Types, UserIdentity_exports as UserIdentity };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import * as HttpRouter from "effect/http/HttpRouter";
|
|
2
|
+
import type * as HttpApi from "effect/http-api/HttpApi";
|
|
3
|
+
import type * as HttpApiGroup from "effect/http-api/HttpApiGroup";
|
|
4
|
+
export declare const scalarDocs: <Id extends string, Groups extends HttpApiGroup.Constraint>(api: HttpApi.HttpApi<Id, Groups>, path: `/${string}`) => import("effect/Layer").Layer<never, never, HttpRouter.HttpRouter>;
|
|
5
|
+
//# sourceMappingURL=scalarDocs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scalarDocs.d.ts","sourceRoot":"","sources":["../../src/internal/scalarDocs.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC;AAErD,OAAO,KAAK,KAAK,OAAO,MAAM,yBAAyB,CAAC;AACxD,OAAO,KAAK,KAAK,YAAY,MAAM,8BAA8B,CAAC;AAuBlE,eAAO,MAAM,UAAU,GACrB,EAAE,SAAS,MAAM,EACjB,MAAM,SAAS,YAAY,CAAC,UAAU,OAEjC,OAAO,CAAC,OAAO,CAAC,EAAE,EAAE,MAAM,CAAC,QAC1B,IAAI,MAAM,EAAE,sEAuChB,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import * as HttpRouter from "effect/http/HttpRouter";
|
|
3
|
+
import * as HttpServerResponse from "effect/http/HttpServerResponse";
|
|
4
|
+
import * as OpenApi from "effect/http-api/OpenApi";
|
|
5
|
+
//#region src/internal/scalarDocs.ts
|
|
6
|
+
const escape = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">");
|
|
7
|
+
const escapeAttribute = (value) => escape(value).replaceAll("\"", """).replaceAll("'", "'");
|
|
8
|
+
const escapeJson = (value) => JSON.stringify(value).replaceAll("<", "\\u003c").replaceAll("\u2028", "\\u2028").replaceAll("\u2029", "\\u2029");
|
|
9
|
+
const scalarDocs = (api, path) => HttpRouter.use((router) => {
|
|
10
|
+
let response;
|
|
11
|
+
return router.add("GET", path, Effect.sync(() => {
|
|
12
|
+
if (response !== void 0) return response;
|
|
13
|
+
const spec = OpenApi.fromApi(api);
|
|
14
|
+
const description = (tag) => !spec.info.description ? "" : `<meta name="${tag}" content="${escapeAttribute(spec.info.description)}"/>`;
|
|
15
|
+
response = HttpServerResponse.html(`<!doctype html>
|
|
16
|
+
<html>
|
|
17
|
+
<head>
|
|
18
|
+
<meta charset="utf-8" />
|
|
19
|
+
<title>${escape(spec.info.title)}</title>
|
|
20
|
+
${description("description")}
|
|
21
|
+
${description("og:description")}
|
|
22
|
+
<meta
|
|
23
|
+
name="viewport"
|
|
24
|
+
content="width=device-width, initial-scale=1" />
|
|
25
|
+
</head>
|
|
26
|
+
<body>
|
|
27
|
+
<div id="api-reference-container"></div>
|
|
28
|
+
<script src="${escapeAttribute("https://cdn.jsdelivr.net/npm/@scalar/api-reference@latest/dist/browser/standalone.min.js")}" crossorigin><\/script>
|
|
29
|
+
<script>
|
|
30
|
+
window.Scalar.createApiReference(document.getElementById('api-reference-container'), {
|
|
31
|
+
...${escapeJson({ _integration: "html" })},
|
|
32
|
+
content: ${escapeJson(spec)}
|
|
33
|
+
})
|
|
34
|
+
<\/script>
|
|
35
|
+
</body>
|
|
36
|
+
</html>`);
|
|
37
|
+
return response;
|
|
38
|
+
}));
|
|
39
|
+
});
|
|
40
|
+
//#endregion
|
|
41
|
+
export { scalarDocs };
|
|
42
|
+
|
|
43
|
+
//# sourceMappingURL=scalarDocs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scalarDocs.js","names":[],"sources":["../../src/internal/scalarDocs.ts"],"sourcesContent":["import * as Effect from \"effect/Effect\";\nimport * as HttpRouter from \"effect/http/HttpRouter\";\nimport * as HttpServerResponse from \"effect/http/HttpServerResponse\";\nimport type * as HttpApi from \"effect/http-api/HttpApi\";\nimport type * as HttpApiGroup from \"effect/http-api/HttpApiGroup\";\nimport * as OpenApi from \"effect/http-api/OpenApi\";\n\nconst escape = (value: string) =>\n value\n .replaceAll(\"&\", \"&\")\n .replaceAll(\"<\", \"<\")\n .replaceAll(\">\", \">\");\n\nconst escapeAttribute = (value: string) =>\n escape(value).replaceAll('\"', \""\").replaceAll(\"'\", \"'\");\n\nconst escapeJson = (value: unknown) =>\n JSON.stringify(value)\n .replaceAll(\"<\", \"\\\\u003c\")\n .replaceAll(\"\\u2028\", \"\\\\u2028\")\n .replaceAll(\"\\u2029\", \"\\\\u2029\");\n\n// WORKAROUND: Effect 4.0.6's HttpApiScalar module imports its inline Scalar\n// script dynamically, and Convex's bundler then splits a schema that reaches it\n// into an imported chunk, which Convex refuses. This copies `layerCdn`'s page\n// byte for byte. Remove when `checkSchemaBundle.mjs` passes with\n// `HttpApiScalar.layerCdn` restored.\nexport const scalarDocs = <\n Id extends string,\n Groups extends HttpApiGroup.Constraint,\n>(\n api: HttpApi.HttpApi<Id, Groups>,\n path: `/${string}`,\n) =>\n HttpRouter.use((router) => {\n let response: HttpServerResponse.HttpServerResponse | undefined;\n return router.add(\n \"GET\",\n path,\n Effect.sync(() => {\n if (response !== undefined) return response;\n const spec = OpenApi.fromApi(api);\n const description = (tag: string) =>\n !spec.info.description\n ? \"\"\n : `<meta name=\"${tag}\" content=\"${escapeAttribute(spec.info.description)}\"/>`;\n response = HttpServerResponse.html(`<!doctype html>\n<html>\n <head>\n <meta charset=\"utf-8\" />\n <title>${escape(spec.info.title)}</title>\n ${description(\"description\")}\n ${description(\"og:description\")}\n <meta\n name=\"viewport\"\n content=\"width=device-width, initial-scale=1\" />\n </head>\n <body>\n <div id=\"api-reference-container\"></div>\n <script src=\"${escapeAttribute(\"https://cdn.jsdelivr.net/npm/@scalar/api-reference@latest/dist/browser/standalone.min.js\")}\" crossorigin></script>\n <script>\n window.Scalar.createApiReference(document.getElementById('api-reference-container'), {\n ...${escapeJson({ _integration: \"html\" })},\n content: ${escapeJson(spec)}\n })\n </script>\n </body>\n</html>`);\n return response;\n }),\n );\n });\n"],"mappings":";;;;;AAOA,MAAM,UAAU,UACd,MACG,WAAW,KAAK,OAAO,CAAC,CACxB,WAAW,KAAK,MAAM,CAAC,CACvB,WAAW,KAAK,MAAM;AAE3B,MAAM,mBAAmB,UACvB,OAAO,KAAK,CAAC,CAAC,WAAW,MAAK,QAAQ,CAAC,CAAC,WAAW,KAAK,OAAO;AAEjE,MAAM,cAAc,UAClB,KAAK,UAAU,KAAK,CAAC,CAClB,WAAW,KAAK,SAAS,CAAC,CAC1B,WAAW,UAAU,SAAS,CAAC,CAC/B,WAAW,UAAU,SAAS;AAOnC,MAAa,cAIX,KACA,SAEA,WAAW,KAAK,WAAW;CACzB,IAAI;CACJ,OAAO,OAAO,IACZ,OACA,MACA,OAAO,WAAW;EAChB,IAAI,aAAa,KAAA,GAAW,OAAO;EACnC,MAAM,OAAO,QAAQ,QAAQ,GAAG;EAChC,MAAM,eAAe,QACnB,CAAC,KAAK,KAAK,cACP,KACA,eAAe,IAAI,aAAa,gBAAgB,KAAK,KAAK,WAAW,EAAE;EAC7E,WAAW,mBAAmB,KAAK;;;;aAI9B,OAAO,KAAK,KAAK,KAAK,EAAE;MAC/B,YAAY,aAAa,EAAE;MAC3B,YAAY,gBAAgB,EAAE;;;;;;;mBAOjB,gBAAgB,0FAA0F,EAAE;;;aAGlH,WAAW,EAAE,cAAc,OAAO,CAAC,EAAE;mBAC/B,WAAW,IAAI,EAAE;;;;QAI5B;EACA,OAAO;CACT,CAAC,CACH;AACF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gaganref/confect-core",
|
|
3
|
-
"version": "10.3.1-fork.
|
|
3
|
+
"version": "10.3.1-fork.51",
|
|
4
4
|
"peerDependencies": {
|
|
5
|
-
"convex": "^1.
|
|
6
|
-
"effect": "
|
|
5
|
+
"convex": "^1.48.0",
|
|
6
|
+
"effect": ">=4.0.0 <4.1.0"
|
|
7
7
|
},
|
|
8
8
|
"description": "Shared specs and schemas used by all Confect packages",
|
|
9
9
|
"author": "RJ Dellecese",
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as Context from "effect/Context";
|
|
2
|
+
import type * as Effect from "effect/Effect";
|
|
3
|
+
import type * as Schema from "effect/Schema";
|
|
4
|
+
import * as FunctionSpec from "./FunctionSpec.js";
|
|
5
|
+
import * as MiddlewareSpec from "./MiddlewareSpec.js";
|
|
6
|
+
import type * as Ref from "./Ref.js";
|
|
7
|
+
|
|
8
|
+
export interface Call {
|
|
9
|
+
<Target extends Ref.AnyQuery | Ref.AnyMutation>(
|
|
10
|
+
target: Target,
|
|
11
|
+
...args: Ref.OptionalArgs<NoInfer<Target>>
|
|
12
|
+
): Effect.Effect<Ref.Returns<Target>, Ref.Error<Target> | Schema.SchemaError>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export class ActionCall extends Context.Service<ActionCall, Call>()(
|
|
16
|
+
"@confect/core/ActionCall",
|
|
17
|
+
) {}
|
|
18
|
+
export class Middleware extends MiddlewareSpec.MiddlewareSpec<
|
|
19
|
+
Middleware,
|
|
20
|
+
{ provides: ActionCall }
|
|
21
|
+
>()("@confect/core/ActionCall/Middleware", {
|
|
22
|
+
functionTypes: { query: false, mutation: false, action: true },
|
|
23
|
+
}) {}
|
|
24
|
+
|
|
25
|
+
export const profile = FunctionSpec.extend()({ middleware: [Middleware] });
|
package/src/App.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { Infer, Validator } from "convex/values";
|
|
|
3
3
|
import type * as HttpApi from "effect/http-api/HttpApi";
|
|
4
4
|
import * as Predicate from "effect/Predicate";
|
|
5
5
|
import type * as Env from "./Env.js";
|
|
6
|
+
import type * as MiddlewareSpec from "./MiddlewareSpec.js";
|
|
6
7
|
|
|
7
8
|
const TypeId = "~@confect/core/App";
|
|
8
9
|
const MountTypeId = "~@confect/core/App/Mount";
|
|
@@ -48,13 +49,21 @@ type HttpOptions =
|
|
|
48
49
|
| { readonly httpPrefix?: never; readonly api?: never }
|
|
49
50
|
| { readonly httpPrefix: HttpPrefix; readonly api?: Api };
|
|
50
51
|
|
|
51
|
-
export type Options<D extends Definition> = HttpOptions &
|
|
52
|
-
|
|
52
|
+
export type Options<D extends Definition> = HttpOptions & {
|
|
53
|
+
/**
|
|
54
|
+
* The package specifier of the module whose `register(t, name)` the generated
|
|
55
|
+
* test registry calls for this mount, in place of the component package's own
|
|
56
|
+
* `<package>/test`. The kit registers the mount's children.
|
|
57
|
+
*/
|
|
58
|
+
readonly testing?: string;
|
|
59
|
+
} & ([RequiredKeys<EnvOf<D>>] extends [never]
|
|
53
60
|
? { readonly env?: Bindings<EnvOf<D>> }
|
|
54
61
|
: { readonly env: Bindings<EnvOf<D>> });
|
|
55
62
|
|
|
56
63
|
type Exact<D extends Definition, O> = {
|
|
57
|
-
readonly [
|
|
64
|
+
readonly [
|
|
65
|
+
K in Exclude<keyof O, "env" | "httpPrefix" | "api" | "testing">
|
|
66
|
+
]: never;
|
|
58
67
|
} & (O extends { readonly env: infer B }
|
|
59
68
|
? {
|
|
60
69
|
readonly env: { readonly [K in Exclude<keyof B, keyof EnvOf<D>>]: never };
|
|
@@ -66,6 +75,7 @@ export interface MountData {
|
|
|
66
75
|
readonly httpPrefix: HttpPrefix | undefined;
|
|
67
76
|
readonly api: Api | undefined;
|
|
68
77
|
readonly env: Readonly<Record<string, string | Env.AnyEntry | undefined>>;
|
|
78
|
+
readonly testing: string | undefined;
|
|
69
79
|
}
|
|
70
80
|
|
|
71
81
|
/**
|
|
@@ -106,6 +116,7 @@ export function mount(
|
|
|
106
116
|
readonly httpPrefix?: HttpPrefix;
|
|
107
117
|
readonly api?: Api;
|
|
108
118
|
readonly env?: MountData["env"];
|
|
119
|
+
readonly testing?: string;
|
|
109
120
|
},
|
|
110
121
|
): AnyMount {
|
|
111
122
|
return {
|
|
@@ -114,6 +125,7 @@ export function mount(
|
|
|
114
125
|
httpPrefix: options?.httpPrefix,
|
|
115
126
|
api: options?.api,
|
|
116
127
|
env: options?.env ?? {},
|
|
128
|
+
testing: options?.testing,
|
|
117
129
|
// The overloads above carry the precise types; this body serves both.
|
|
118
130
|
} as AnyMount;
|
|
119
131
|
}
|
|
@@ -144,6 +156,7 @@ export interface App<
|
|
|
144
156
|
readonly kind: K;
|
|
145
157
|
readonly env: E;
|
|
146
158
|
readonly mounts: M;
|
|
159
|
+
readonly requiresMiddleware: ReadonlyArray<MiddlewareSpec.AnyMiddlewareSpec>;
|
|
147
160
|
}
|
|
148
161
|
|
|
149
162
|
export type Any = App<Env.Any, Readonly<Record<string, AnyMount>>>;
|
|
@@ -175,6 +188,7 @@ export const make = <
|
|
|
175
188
|
>(
|
|
176
189
|
options: {
|
|
177
190
|
readonly env: E;
|
|
191
|
+
readonly requiresMiddleware?: ReadonlyArray<MiddlewareSpec.AnyMiddlewareSpec>;
|
|
178
192
|
readonly mounts?: M & OwnedBy<NoInfer<Env.Name<E>>, NoInfer<M>>;
|
|
179
193
|
} & ([K] extends ["app"] ? { readonly kind?: K } : { readonly kind: K }),
|
|
180
194
|
): App<E, M, K> => ({
|
|
@@ -182,6 +196,7 @@ export const make = <
|
|
|
182
196
|
kind: options.kind ?? ("app" as K),
|
|
183
197
|
env: options.env,
|
|
184
198
|
mounts: options.mounts ?? ({} as M),
|
|
199
|
+
requiresMiddleware: options.requiresMiddleware ?? [],
|
|
185
200
|
});
|
|
186
201
|
|
|
187
202
|
export const isApp = (u: unknown): u is Any =>
|
|
@@ -207,4 +222,5 @@ export const mounts = (
|
|
|
207
222
|
httpPrefix: installed.httpPrefix,
|
|
208
223
|
api: installed.api,
|
|
209
224
|
env: installed.env,
|
|
225
|
+
testing: installed.testing,
|
|
210
226
|
}));
|
package/src/Auth.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { AuthProvider } from "convex/server";
|
|
2
2
|
import * as Predicate from "effect/Predicate";
|
|
3
3
|
import type * as App from "./App.js";
|
|
4
|
+
import type * as Env from "./Env.js";
|
|
4
5
|
import type { TypeError } from "./Types.js";
|
|
5
6
|
|
|
6
7
|
const TypeId = "~@confect/core/Auth";
|
|
8
|
+
const CloudUrlTypeId = "~@confect/core/Auth/CloudUrl";
|
|
7
9
|
const SiteUrlTypeId = "~@confect/core/Auth/SiteUrl";
|
|
8
10
|
|
|
9
11
|
/**
|
|
@@ -15,19 +17,59 @@ export interface SiteUrl {
|
|
|
15
17
|
readonly path: string;
|
|
16
18
|
}
|
|
17
19
|
|
|
18
|
-
|
|
20
|
+
/**
|
|
21
|
+
* The deployment's cloud URL (`CONVEX_CLOUD_URL`) plus a path.
|
|
22
|
+
*/
|
|
23
|
+
export interface CloudUrl {
|
|
24
|
+
readonly [CloudUrlTypeId]: typeof CloudUrlTypeId;
|
|
25
|
+
readonly path: string;
|
|
26
|
+
}
|
|
19
27
|
|
|
20
|
-
type
|
|
28
|
+
type Url =
|
|
29
|
+
| string
|
|
30
|
+
| SiteUrl
|
|
31
|
+
| CloudUrl
|
|
32
|
+
| Env.Entry<string, string, string, false>;
|
|
33
|
+
|
|
34
|
+
type WithUrls<P> = P extends unknown
|
|
21
35
|
? {
|
|
22
|
-
[K in keyof P]: K extends "domain" | "issuer" | "jwks"
|
|
36
|
+
[K in keyof P]: K extends "domain" | "issuer" | "jwks" | "applicationID"
|
|
37
|
+
? Url
|
|
38
|
+
: P[K];
|
|
23
39
|
}
|
|
24
40
|
: never;
|
|
25
41
|
|
|
26
42
|
/**
|
|
27
|
-
* Convex's
|
|
28
|
-
|
|
43
|
+
* Convex's provider list with deployment URLs and required, public env strings.
|
|
44
|
+
*/
|
|
45
|
+
export type Provider = WithUrls<AuthProvider> & {
|
|
46
|
+
/**
|
|
47
|
+
* Application-defined token family, copied to the runtime provider data.
|
|
48
|
+
*/
|
|
49
|
+
readonly family?: string;
|
|
50
|
+
/**
|
|
51
|
+
* Application-defined issuer name, for example a trusted service.
|
|
52
|
+
*/
|
|
53
|
+
readonly name?: string;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The cloud URL, or a path under it, resolved when Convex loads auth config.
|
|
29
58
|
*/
|
|
30
|
-
export
|
|
59
|
+
export const cloudUrl = (path: `/${string}` | "" = ""): CloudUrl => ({
|
|
60
|
+
[CloudUrlTypeId]: CloudUrlTypeId,
|
|
61
|
+
path,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The path of a cloud URL placeholder, or `undefined` for another value.
|
|
66
|
+
*/
|
|
67
|
+
export const cloudUrlPath = (u: unknown): string | undefined =>
|
|
68
|
+
Predicate.hasProperty(u, CloudUrlTypeId) &&
|
|
69
|
+
Predicate.hasProperty(u, "path") &&
|
|
70
|
+
typeof u.path === "string"
|
|
71
|
+
? u.path
|
|
72
|
+
: undefined;
|
|
31
73
|
|
|
32
74
|
export interface Auth<A extends App.Any> {
|
|
33
75
|
readonly [TypeId]: typeof TypeId;
|
package/src/Callback.ts
CHANGED
|
@@ -145,6 +145,7 @@ const fromText = <Contract_ extends Any>(
|
|
|
145
145
|
[],
|
|
146
146
|
// Convex types a handle as a string that is also a function reference.
|
|
147
147
|
text as unknown as FunctionReference<any, any>,
|
|
148
|
+
contract.functionType,
|
|
148
149
|
),
|
|
149
150
|
{ [HandleTypeId]: contract.id },
|
|
150
151
|
) as unknown as Handle<Contract_>;
|