import type { StandardSchemaV1 } from '@standard-schema/spec'; import * as interfaces from '../interfaces/index.ts'; import * as syntax from '../syntax/index.ts'; import type { $type } from '../types/brand.ts'; /** * flag indicating whether xrpc schema generation helpers are used. set to true * when query() or procedure() is called. this enables conditional tree-shaking * of validation code when schemas are not used. * @deprecated internal flag for tree-shaking, do not use directly */ export declare let xrpcSchemaGenerated: boolean; type Identity = T; type Flatten = Identity<{ [K in keyof T]: T[K]; }>; type InputType = 'unknown' | 'null' | 'undefined' | 'string' | 'integer' | 'boolean' | 'blob' | 'bytes' | 'cid-link' | 'object' | 'array'; type StringFormatMap = { 'at-identifier': syntax.ActorIdentifier; 'at-uri': syntax.ResourceUri; cid: syntax.Cid; datetime: syntax.Datetime; did: syntax.Did; handle: syntax.Handle; language: syntax.LanguageCode; nsid: syntax.Nsid; 'record-key': syntax.RecordKey; tid: syntax.Tid; uri: syntax.GenericUri; }; export type StringFormat = keyof StringFormatMap; type Literal = string | number | boolean; type Key = string | number; type IssueFormatter = () => string; export type IssueLeaf = { ok: false; msg: IssueFormatter; } & ({ code: 'missing_value'; } | { code: 'invalid_literal'; expected: readonly Literal[]; } | { code: 'invalid_type'; expected: InputType; } | { code: 'invalid_variant'; expected: string[]; } | { code: 'invalid_integer_range'; min: number; max: number; } | { code: 'invalid_string_format'; expected: StringFormat; } | { code: 'invalid_string_graphemes'; minGraphemes: number; maxGraphemes: number; } | { code: 'invalid_string_length'; minLength: number; maxLength: number; } | { code: 'invalid_array_length'; minLength: number; maxLength: number; } | { code: 'invalid_bytes_size'; minSize: number; maxSize: number; }); export type IssueTree = IssueLeaf | { ok: false; code: 'prepend'; key: Key; tree: IssueTree; } | { ok: false; code: 'join'; left: IssueTree; right: IssueTree; }; export type Issue = { code: 'missing_value'; path: Key[]; } | { code: 'invalid_literal'; path: Key[]; expected: readonly Literal[]; } | { code: 'invalid_type'; path: Key[]; expected: InputType; } | { code: 'invalid_variant'; path: Key[]; expected: string[]; } | { code: 'invalid_integer_range'; path: Key[]; min: number; max: number; } | { code: 'invalid_string_format'; path: Key[]; expected: StringFormat; } | { code: 'invalid_string_graphemes'; path: Key[]; minGraphemes: number; maxGraphemes: number; } | { code: 'invalid_string_length'; path: Key[]; minLength: number; maxLength: number; } | { code: 'invalid_array_length'; path: Key[]; minLength: number; maxLength: number; } | { code: 'invalid_bytes_size'; path: Key[]; minSize: number; maxSize: number; }; export type Ok = { ok: true; value: T; }; export type Err = { ok: false; readonly message: string; readonly issues: readonly Issue[]; throw(): never; }; export type ValidationResult = Ok | Err; export declare const ok: (value: T) => Ok; declare const kType: unique symbol; type kType = typeof kType; export declare const FLAG_EMPTY = 0; export declare const FLAG_ABORT_EARLY: number; type MatcherResult = undefined | Ok | IssueTree; type Matcher = (input: unknown, flags: number) => MatcherResult; type LexStandardSchemaResult = StandardSchemaV1.Result>; interface LexStandardSchema extends StandardSchemaV1.Props { readonly validate: (value: unknown) => LexStandardSchemaResult | Promise>; readonly types?: StandardSchemaV1.Types, InferOutput>; } export interface BaseSchema { readonly kind: 'schema'; readonly type: string; readonly '~run': Matcher; readonly '~standard': LexStandardSchema; readonly [kType]?: { in: TInput; out: TOutput; }; } export type InferInput = NonNullable['in']; export type InferOutput = NonNullable['out']; export declare class ValidationError extends Error { #private; readonly name = "ValidationError"; constructor(issueTree: IssueTree); get message(): string; get issues(): readonly Issue[]; } export declare const is: >(schema: TSchema, input: unknown) => input is InferInput; export declare const safeParse: >(schema: TSchema, input: unknown) => ValidationResult>; export declare const parse: >(schema: TSchema, input: unknown) => InferOutput; export interface BaseConstraint { readonly kind: 'constraint'; readonly type: string; readonly '~run': (input: TType, flags: number) => MatcherResult; } type ConstraintTuple = readonly [BaseConstraint, ...BaseConstraint[]]; export type SchemaWithConstraint>> = TItem & { readonly constraints: TConstraints; }; export declare const constrain: , const TConstraints extends ConstraintTuple>>(base: TItem, constraints: TConstraints) => SchemaWithConstraint; export interface BaseMetadata { readonly kind: 'metadata'; readonly type: string; } export interface LiteralSchema extends BaseSchema { readonly type: 'literal'; readonly expected: T; } export declare const literal: (value: T) => LiteralSchema; export interface LiteralEnumSchema extends BaseSchema { readonly type: 'literal_enum'; readonly expected: TEnums; } export declare const literalEnum: (values: TEnums) => LiteralEnumSchema; export interface BooleanSchema extends BaseSchema { readonly type: 'boolean'; } export declare const boolean: () => BooleanSchema; export interface IntegerSchema extends BaseSchema { readonly type: 'integer'; } export declare const integer: () => IntegerSchema; export interface IntegerRangeConstraint extends BaseConstraint { readonly type: 'integer_range'; readonly min: TMin; readonly max: TMax; } export declare const integerRange: { (min: TMin): IntegerRangeConstraint; (min: TMin, max: TMax): IntegerRangeConstraint; }; export interface StringSchema extends BaseSchema { readonly type: 'string'; readonly format: null; } export interface FormattedStringSchema extends BaseSchema { readonly type: 'string'; readonly format: TFormat; } export declare const string: () => StringSchema; export declare const actorIdentifierString: () => FormattedStringSchema<"at-identifier">; export declare const resourceUriString: () => FormattedStringSchema<"at-uri">; export declare const cidString: () => FormattedStringSchema<"cid">; export declare const datetimeString: () => FormattedStringSchema<"datetime">; export declare const didString: () => FormattedStringSchema<"did">; export declare const handleString: () => FormattedStringSchema<"handle">; export declare const languageCodeString: () => FormattedStringSchema<"language">; export declare const nsidString: () => FormattedStringSchema<"nsid">; export declare const recordKeyString: () => FormattedStringSchema<"record-key">; export declare const tidString: () => FormattedStringSchema<"tid">; export declare const genericUriString: () => FormattedStringSchema<"uri">; export interface StringLengthConstraint extends BaseConstraint { readonly type: 'string_length'; readonly minLength: TMinLength; readonly maxLength: TMaxLength; } export declare const stringLength: { (min: TMinLength): StringLengthConstraint; (min: TMinLength, max: TMaxLength): StringLengthConstraint; }; export interface StringGraphemesConstraint extends BaseConstraint { readonly type: 'string_graphemes'; readonly minGraphemes: TMinGraphemes; readonly maxGraphemes: TMaxGraphemes; } export declare const stringGraphemes: { (min: TMinGraphemes): StringGraphemesConstraint; (min: TMinGraphemes, max: TMaxGraphemes): StringGraphemesConstraint; }; export interface BlobSchema extends BaseSchema { readonly type: 'blob'; } export declare const blob: () => BlobSchema; export interface BytesSchema extends BaseSchema { readonly type: 'bytes'; } export declare const bytes: () => BytesSchema; export interface BytesSizeConstraint extends BaseConstraint { readonly type: 'bytes_size'; readonly minSize: TMinLength; readonly maxSize: TMaxLength; } export declare const bytesSize: { (min: TMinLength): BytesSizeConstraint; (min: TMinLength, max: TMaxLength): BytesSizeConstraint; }; export interface CidLinkSchema extends BaseSchema { readonly type: 'cid_link'; } export declare const cidLink: () => CidLinkSchema; export interface NullableSchema extends BaseSchema | null, InferOutput | null> { readonly type: 'nullable'; readonly wrapped: TItem; } export declare const nullable: >(wrapped: TItem) => NullableSchema; export type DefaultValue = InferOutput | (() => InferOutput) | undefined; export type InferOptionalOutput> = undefined extends TDefault ? InferOutput | undefined : InferOutput; export interface OptionalSchema = DefaultValue> extends BaseSchema | undefined, InferOptionalOutput> { readonly type: 'optional'; readonly wrapped: TItem; readonly default: TDefault; } export declare const optional: { (wrapped: TItem): OptionalSchema; >(wrapped: TItem, defaultValue: TDefault): OptionalSchema; }; export interface ArraySchema extends BaseSchema { readonly type: 'array'; readonly item: TItem; readonly [kType]?: { in: InferInput[]; out: InferOutput[]; }; } export declare const array: >(item: TItem | (() => TItem)) => ArraySchema; export interface ArrayLengthConstraint extends BaseConstraint { readonly type: 'array_length'; readonly minLength: TMinLength; readonly maxLength: TMaxLength; } export declare const arrayLength: { (min: TMinLength): ArrayLengthConstraint; (min: TMinLength, max: TMaxLength): ArrayLengthConstraint; }; export type LooseObjectShape = Record; export type ObjectShape = Record; export type OptionalObjectInputKeys = { [Key in keyof TShape]: TShape[Key] extends OptionalSchema ? Key : never; }[keyof TShape]; export type OptionalObjectOutputKeys = { [Key in keyof TShape]: TShape[Key] extends OptionalSchema ? undefined extends Default ? Key : never : never; }[keyof TShape]; type InferObjectInput = Flatten<{ -readonly [Key in keyof TShape as Key extends OptionalObjectInputKeys ? never : Key]: InferInput; } & { -readonly [Key in keyof TShape as Key extends OptionalObjectInputKeys ? Key : never]?: InferInput; }>; type InferObjectOutput = Flatten<{ -readonly [Key in keyof TShape as Key extends OptionalObjectOutputKeys ? never : Key]: InferOutput; } & { -readonly [Key in keyof TShape as Key extends OptionalObjectOutputKeys ? Key : never]?: InferOutput; }>; export interface ObjectSchema extends BaseSchema> { readonly type: 'object'; readonly shape: Readonly; readonly [kType]?: { in: InferObjectInput; out: InferObjectOutput; }; } export declare const object: (shape: TShape) => ObjectSchema; export type RecordObjectShape = { $type: LiteralSchema; [key: string]: BaseSchema; }; export type RecordKeySchema = StringSchema | FormattedStringSchema | LiteralSchema; export type RecordObjectSchema = ObjectSchema; export interface RecordSchema extends BaseSchema> { readonly type: 'record'; readonly key: TKey; readonly object: TObject; readonly [kType]?: { in: InferInput; out: InferOutput; }; } export declare const record: >(key: TKey, object: TObject) => RecordSchema; type VariantTuple = readonly ObjectSchema[]; type InferVariantInput = $type.enforce>; type InferVariantOutput = $type.enforce>; export interface VariantSchema extends BaseSchema> { readonly type: 'variant'; readonly members: TMembers; readonly closed: TClosed; readonly [kType]?: { in: InferVariantInput; out: InferVariantOutput; }; } export declare const variant: { (members: TMembers): VariantSchema; (members: TMembers, closed: TClosed): VariantSchema; }; export interface UnknownSchema extends BaseSchema> { readonly type: 'unknown'; } export declare const unknown: () => UnknownSchema; export interface XRPCLexBodyParam { readonly type: 'lex'; readonly schema: TSchema; } export interface XRPCBlobBodyParam { readonly type: 'blob'; readonly encoding?: string[]; } export type XRPCBodyParam = XRPCLexBodyParam | XRPCBlobBodyParam | null; export type InferXRPCBodyInput = T extends XRPCLexBodyParam ? InferInput : T extends XRPCBlobBodyParam ? Blob : T extends null ? void : never; export type InferXRPCBodyOutput = T extends XRPCLexBodyParam ? InferOutput : T extends XRPCBlobBodyParam ? Blob : T extends null ? void : never; export interface XRPCProcedureMetadata extends BaseMetadata { readonly type: 'xrpc_procedure'; readonly nsid: TNsid; readonly params: TParams; readonly input: TInput; readonly output: TOutput; } export declare const procedure: | null, TInput extends XRPCBodyParam, TOutput extends XRPCBodyParam>(nsid: TNsid, options: { params: TParams; input: TInput; output: TOutput; }) => XRPCProcedureMetadata; export interface XRPCQueryMetadata extends BaseMetadata { readonly type: 'xrpc_query'; readonly nsid: TNsid; readonly params: TParams; readonly output: TOutput; } export declare const query: | null, TOutput extends XRPCBodyParam>(nsid: TNsid, options: { params: TParams; output: TOutput; }) => XRPCQueryMetadata; export interface XRPCSubscriptionMetadata | VariantSchema | null = ObjectSchema | VariantSchema | null, TNsid extends syntax.Nsid = syntax.Nsid> extends BaseMetadata { readonly type: 'xrpc_subscription'; readonly nsid: TNsid; readonly params: TParams; readonly message: TMessage; } export declare const subscription: | null, TMessage extends ObjectSchema | VariantSchema | null>(nsid: TNsid, options: { params: TParams; readonly message: TMessage; }) => XRPCSubscriptionMetadata; export {}; //# sourceMappingURL=index.d.ts.map