UNPKG

schema-dts-gen

Version:

Generate TypeScript Definitions for Schema.org Schema

101 lines 3.99 kB
import type { DeclarationStatement, Statement, TypeNode, TypeParameterDeclaration } from 'typescript'; import { Context } from './context.js'; import { EnumValue } from './enum.js'; import { Property } from './property.js'; import { NamedNode, Quad } from 'n3'; /** Maps fully qualified IDs of each Class to the class itself. */ export type ClassMap = Map<string, Class>; /** * Represents a "Class" in Schema.org, except in cases where it is better * described by Builtin (i.e. is a DataType). * * In TypeScript, this corresponds to a collection of declarations: * 1. If the class has enum values, an Enum declaration. * 2. If the class has properties, the properties in an object literal. * 3. If the class has children, * a type union over all children. * otherwise, a "type" property. */ export declare class Class { readonly subject: NamedNode; private _comment?; private _typedefs; private _isDataType; private _explicitlyMarkedAsClass; private readonly children; private readonly _parents; private readonly _props; private readonly _enums; private readonly _supersededBy; private allParents; private namedParents; isNodeType(): boolean; get deprecated(): boolean; protected comment(context: Context): string | undefined; protected get typedefs(): TypeNode[]; private properties; private supersededBy; private enums; protected baseName(context: Context): string | undefined; protected leafName(context: Context): string | undefined; className(context: Context): string; constructor(subject: NamedNode); add(value: Quad, classMap: ClassMap): boolean; addTypedef(typedef: TypeNode): void; markAsExplicitClass(): void; private isMarkedAsClass; validateClass(): void; addProp(p: Property): void; addEnum(e: EnumValue): void; private skipBase; private baseDecl; protected leafDecl(context: Context): DeclarationStatement | undefined; protected nonEnumType(context: Context, skipDeprecated: boolean): TypeNode[]; private totalType; /** Generic Type Parameter Declarations for this class */ protected typeParameters(): readonly TypeParameterDeclaration[]; /** Generic Types to pass to this total type when referencing it. */ protected typeArguments(_: readonly TypeParameterDeclaration[]): readonly TypeNode[]; protected leafTypeArguments(): readonly TypeNode[]; toNode(context: Context, properties: { skipDeprecatedProperties: boolean; hasRole: boolean; }): readonly Statement[]; } /** * Represents a DataType. */ export declare class Builtin extends Class { constructor(subject: NamedNode); } /** * A "Native" Schema.org object that is best represented * in JSON-LD and JavaScript as a typedef to a native type. */ export declare class AliasBuiltin extends Builtin { constructor(subject: NamedNode, ...equivTo: TypeNode[]); static Alias(equivTo: string): TypeNode; static NumberStringLiteral(): TypeNode; } export declare class RoleBuiltin extends Builtin { private static readonly kContentTypename; private static readonly kPropertyTypename; protected typeParameters(): readonly TypeParameterDeclaration[]; protected leafTypeArguments(): readonly TypeNode[]; protected typeArguments(availableParams: readonly TypeParameterDeclaration[]): TypeNode[]; protected leafDecl(context: Context): DeclarationStatement; } export declare class DataTypeUnion extends Builtin { readonly wk: Builtin[]; constructor(subject: NamedNode, wk: Builtin[]); toNode(context: Context): DeclarationStatement[]; } /** * Defines a Sort order between Class declarations. * * DataTypes come first, next the 'DataType' union itself, followed by all * regular classes. Within each group, class names are ordered alphabetically in * UTF-16 code units order. */ export declare function Sort(a: Class, b: Class): number; //# sourceMappingURL=class.d.ts.map