UNPKG

@wikipathways/cxml

Version:

Advanced schema-aware streaming XML parser

43 lines 2.11 kB
/// <reference types="node" /> import * as stream from "stream"; import * as Promise from "bluebird"; import { Context } from "../xml/Context"; import { HandlerInstance } from "./Rule"; import { ItemParsed } from "../spinoffs/xpath"; export declare type ItemParsedKey = keyof ItemParsed; export declare type ItemParsedValue = ItemParsed[ItemParsedKey]; export declare type AttachmentMethodNames = "_after" | "_before"; export declare type BTreeFinal = Map<AttachmentMethodNames, Function>; export declare type BTreeIntermediate<T> = Map<ItemParsed, T | BTreeFinal>; export declare type BTree<T> = BTreeIntermediate<T> & BTreeFinal; export interface CxmlDate extends Date { cxmlTimezoneOffset: number; } export declare type NonBinaryOpToRights = { [K in "=" | "!="]: string | number; }; export declare type BinaryOpToRights = { [K in "&lt;" | "&lt;=" | "&gt;" | ">" | "&gt;=" | ">="]: number; }; export declare type OpToRights = NonBinaryOpToRights & BinaryOpToRights; export declare type OpHandlerInputGeneric<T, K extends keyof T> = { left: string; op: K; right: T[K]; }; export declare type OpHandlerInput = OpHandlerInputGeneric<OpToRights, keyof OpToRights>; export declare type OpHandlersGeneric<T, K extends keyof T> = { [K: string]: (item: HandlerInstance, left: string, right: T[K]) => boolean; }; export declare type OpHandlers = OpHandlersGeneric<OpToRights, keyof OpToRights>; export declare class Parser<T> { xpathNamespaceTbl: Record<string, string>; constructor(xpathNamespaceTbl?: Record<string, string>); bTree: BTree<any> & BTree<T>; attach<CustomHandler extends HandlerInstance>(handler: { new (): CustomHandler; }, xpath: string): void; parse<Output extends HandlerInstance>(stream: string | stream.Readable | NodeJS.ReadableStream, output: Output, context?: Context): Promise<Output>; _parse<Output extends HandlerInstance>(stream: string | stream.Readable | NodeJS.ReadableStream, output: Output, context: Context, resolve: (item: Output) => void, reject: (err: Error) => void): void; } //# sourceMappingURL=Parser.d.ts.map