UNPKG

iproto

Version:

290 lines (288 loc) 7.68 kB
type ShapeOptions = { root: string; }; declare namespace Shape { type LiteralValueType = "boolean" | "int" | "float" | "string"; type LiteralValue = { type: "boolean"; value: boolean; } | { type: "string"; value: string; } | { type: "int"; value: number; } | { type: "float"; value: number; }; type Declaration = Directive | Enum | Exception | Scalar | Endpoint | Struct; type DirectiveLocation = "endpoint" | "enum" | "exception" | "field" | "module" | "scalar" | "struct" | "variant"; type Type = Enum | Scalar | Struct; interface DirectiveParameter { $type: "DirectiveParameter"; name: string; optional: boolean; type: LiteralValueType; comment: string; } interface Directive { $type: "Directive"; locations: Array<DirectiveLocation>; name: string; parameters: Array<DirectiveParameter>; comment: string; } interface ScalarOption { $type: "ScalarOption"; name: string; type: LiteralValueType; comment: string; } interface Scalar { $type: "Scalar"; directives: Array<ReferenceDirective>; name: string; options: Array<ScalarOption>; parameters: Array<string>; comment: string; } interface Enum { $type: "Enum"; directives: Array<ReferenceDirective>; members: Array<EnumMember>; name: string; comment: string; } interface EnumMember { $type: "EnumMember"; directives: Array<ReferenceDirective>; name: string; comment: string; } interface Field { $type: "Field"; directives: Array<ReferenceDirective>; name: string; type: ReferenceType; comment: string; } interface Struct { $type: "Struct"; directives: Array<ReferenceDirective>; mixins: Array<ReferenceType>; fields: Array<Field>; name: string; comment: string; } interface Exception { $type: "Exception"; directives: Array<ReferenceDirective>; fields: Array<Field>; name: string; comment: string; } interface Endpoint { $type: "Endpoint"; directives: Array<ReferenceDirective>; input?: ReferenceType; name: string; output?: ReferenceType; comment: string; } interface Module { $type: "Module"; directives: Array<ReferenceDirective>; name: string; declarations: Array<Declaration>; comment: string; } interface ReferenceDirectiveArgument { $type: "ReferenceDirectiveArgument"; name: string; value: LiteralValue; } interface ReferenceDirective { $type: "ReferenceDirective"; $target: string; $module: string; $name: string; arguments: Record<string, LiteralValue>; } interface ReferenceType { $type: "ReferenceType"; $target: string; $kind: Type["$type"]; $module: string; $name: string; arguments: Array<ReferenceType>; options: Record<string, LiteralValue>; } type Modules = Array<Module>; type ReferenceStringOptions = { const?: Extract<LiteralValue, { type: "string"; }>; max?: Extract<LiteralValue, { type: "int"; }>; min?: Extract<LiteralValue, { type: "int"; }>; length?: Extract<LiteralValue, { type: "int"; }>; nonempty?: Extract<LiteralValue, { type: "boolean"; }>; pattern?: Extract<LiteralValue, { type: "string"; }>; email?: Extract<LiteralValue, { type: "boolean"; }>; uuid?: Extract<LiteralValue, { type: "boolean"; }>; prefix?: Extract<LiteralValue, { type: "string"; }>; suffix?: Extract<LiteralValue, { type: "string"; }>; url?: Extract<LiteralValue, { type: "boolean"; }>; nanoid?: Extract<LiteralValue, { type: "boolean"; }>; }; type ReferenceFloatOptions = { const?: Extract<LiteralValue, { type: "float"; }>; lt?: Extract<LiteralValue, { type: "float"; }>; gt?: Extract<LiteralValue, { type: "float"; }>; lte?: Extract<LiteralValue, { type: "float"; }>; gte?: Extract<LiteralValue, { type: "float"; }>; positive?: Extract<LiteralValue, { type: "boolean"; }>; nonnegative?: Extract<LiteralValue, { type: "boolean"; }>; negative?: Extract<LiteralValue, { type: "boolean"; }>; nonpositive?: Extract<LiteralValue, { type: "boolean"; }>; }; type ReferenceIntOptions = { const?: Extract<LiteralValue, { type: "int"; }>; lt?: Extract<LiteralValue, { type: "int"; }>; gt?: Extract<LiteralValue, { type: "int"; }>; lte?: Extract<LiteralValue, { type: "int"; }>; gte?: Extract<LiteralValue, { type: "int"; }>; positive?: Extract<LiteralValue, { type: "boolean"; }>; nonnegative?: Extract<LiteralValue, { type: "boolean"; }>; negative?: Extract<LiteralValue, { type: "boolean"; }>; nonpositive?: Extract<LiteralValue, { type: "boolean"; }>; }; type ReferenceBooleanOptions = { const?: Extract<LiteralValue, { type: "boolean"; }>; }; type ReferenceBinaryOptions = { min?: Extract<LiteralValue, { type: "int"; }>; min_kb?: Extract<LiteralValue, { type: "float"; }>; min_mb?: Extract<LiteralValue, { type: "float"; }>; max?: Extract<LiteralValue, { type: "int"; }>; max_kb?: Extract<LiteralValue, { type: "float"; }>; max_mb?: Extract<LiteralValue, { type: "float"; }>; nonempty?: Extract<LiteralValue, { type: "boolean"; }>; }; type ReferenceListOptions = { max?: Extract<LiteralValue, { type: "int"; }>; min?: Extract<LiteralValue, { type: "int"; }>; length?: Extract<LiteralValue, { type: "int"; }>; nonempty?: Extract<LiteralValue, { type: "boolean"; }>; }; type ReferenceDictionaryOptions = { max?: Extract<LiteralValue, { type: "int"; }>; min?: Extract<LiteralValue, { type: "int"; }>; size?: Extract<LiteralValue, { type: "int"; }>; nonempty?: Extract<LiteralValue, { type: "boolean"; }>; }; } declare class Shape { private root; private services; private ready; constructor(options: ShapeOptions); private init; private normalizeComment; private generateModule; private generateReferenceType; private generateReferenceDirectives; private generateDeclaration; generate(): Promise<Shape.Modules>; } export { Shape, type ShapeOptions };