// Type definitions for jsonld 1.5 // Project: https://github.com/digitalbazaar/jsonld.js // Definitions by: Jonas Erbe // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.6 import { Context, JsonLd, Document, Url, JsonLdProcessor, RemoteDocument } from './jsonld-spec'; // Some typealiases for better readability and some placeholders type MimeNQuad = 'application/n-quads'; type RdfDataSet = object; // Placeholder type RdfOrString = RdfDataSet|string; type Callback = (err: Error, res: T) => void; type DocCallback = Callback; /* * Declares interfaces used to type the methods options object. * The interfaces are usefull to avoid code replication. */ export namespace Options { interface DocLoader { documentLoader?: (url: Url, callback: (err: Error, remoteDoc: RemoteDocument) => void) => Promise; } interface Common extends DocLoader { base?: string; expandContext?: Context; } interface ExpMap { // TODO: Figure out type of info expansionMap?: (info: any) => any; } interface Compact extends Common, ExpMap { compactArrays?: boolean; appropriate?: boolean; compactToRelative?: boolean; graph?: boolean; skipExpansion?: boolean; expansion?: boolean; framing?: boolean; // TODO: Figure out type of info compactionMap?: (info: any) => void; } interface Expand extends Common, ExpMap { keepFreeFloatingNodes?: boolean; } type Flatten = Common; interface Frame { embed?: '@last' | '@always' | '@never' | '@link'; explicit?: boolean; requireAll?: boolean; omitDefault?: boolean; } interface Normalize extends Common { algorithm?: 'URDNA2015' | `URGNA2012`; skipExpansion?: boolean; expansion?: boolean; inputFormat?: MimeNQuad; format?: MimeNQuad; useNative?: boolean; } interface FromRdf { format?: MimeNQuad; rdfParser?: any; useRdfType?: boolean; useNativeTypes?: boolean; } interface ToRdf extends Common { skipExpansion?: boolean; format?: MimeNQuad; produceGeneralizedRdf?: boolean; } // TODO Complete and uncomment if needed (see comments at the end of the file) /* NOT USED AT THE MOMENT // type Link = Common; interface Issuer { issuer?: IdentifierIssuer; // a jsonld.IdentifierIssuer to use to label blank nodes. } type CreateNodeMap = Common&Issuer; interface Merge extends Common, Issuer{ mergeNodes?: boolean; //true to merge properties for nodes with the same ID, //false to ignore new properties for nodes with the same ID once //the ID has been defined; note that this may not prevent merging //new properties where a node is in the `object` position //(default: true). } interface Get { documentLoader?: DocLoader; // the document loader to use. } type ProcessContext = DocLoader; */ } export function compact(input: Document, ctx: Context, options: Options.Compact, callback: DocCallback): void; export function compact(input: Document, ctx: Context, callback: DocCallback): void; export function compact(input: Document, ctx: Context, options?: Options.Compact): Promise; export function expand(input: Document, options: Options.Expand, callback: DocCallback): void; export function expand(input: Document, callback: DocCallback): void; export function expand(input: Document, options?: Options.Expand): Promise; export function flatten(input: Document, ctx: Context|null, options: Options.Flatten, callback: DocCallback): void; export function flatten(input: Document, ctx: Context|null, callback: DocCallback): void; export function flatten(input: Document, ctx: Context|null, options?: Options.Flatten): Promise; export function frame(input: Document, frame: Document, options: Options.Frame, callback: DocCallback): void; export function frame(input: Document, frame: Document, callback: DocCallback): void; export function frame(input: Document, frame: Document, options?: Options.Frame): Promise; export function normalize(input: Document, options: Options.Normalize, callback: DocCallback): void; export function normalize(input: Document, callback: DocCallback): void; export function normalize(input: Document, options?: Options.Normalize): Promise; export function fromRDF(dataset: RdfOrString, options: Options.FromRdf, callback: DocCallback): void; export function fromRDF(dataset: RdfOrString, callback: DocCallback): void; export function fromRDF(dataset: RdfOrString, options?: Options.FromRdf): Promise; export function toRDF(input: Document, callback: Callback): void; export function toRDF(input: Document, options: Options.ToRdf, callback: Callback): void; export function toRDF(input: Document, options?: Options.ToRdf): Promise; export let JsonLdProcessor: JsonLdProcessor; // disable autoexport export {}; // TODO: Complete and export the following types if needed! // ************************************************************************************ // Not exported because of experimental state // export function link(input: Document, ctx: Context, options: Options.Link, callback: DocCallback): void; // export function link(input: Document, ctx: Context, callback: DocCallback): void; // export function link(input: Document, ctx: Context, options?: Options.Link): Promise; // Not exported because of experimental state // export function createNodeMapn(input: Document, options: Options.CreateNodeMap, callback: Callback): void; // export function createNodeMapn(input: Document, callback: Callback): void; // export function createNodeMapn(input: Document, options: Options.CreateNodeMap): Promise; // Not exported because of experimental state // export function merge (docs: Document, ctx: Context, options: Options.Merge, callback: DocCallback): void; // export function merge (docs: Document, ctx: Context, callback: DocCallback): void; // export function merge (docs: Document, ctx: Context, options: Options.Merge): Promise; /* export namespace documentLoader { function get(): NormalizedDocLoader; function set(v: DocLoader): void; } */ // default document loader not implemented // export function documentLoader(url: Url): DocLoader; /** * Deprecated default document loader. Do not use or override. */ // export function loadDocument(url: Url): Promise; // export function get (url: Url, options: Options.Get): Promise; // export function processContext(activeCtx: Context, localCtx: Context, options: Options.ProcessContext): Promise; // backwards compatibility // export function getContextValue(ctx: Context, key: string, type: JsonLDType): any; /** * Document loaders. */ /* export namespace documentLoaders { let node: DocLoader; let xhr: DocLoader; } export type DocumentLoaders = 'node' | 'xhr'; */ // export function useDocumentLoader (type: DocumentLoaders, ...params: any): void; // type ParserFunction = (input: string, callback: (err: Error, dataset: RdfDataSet) => Promise) => void; // export function registerRDFParser (contentType: MimeType, parser: ParserFunction): void; // export function unregisterRDFParser (contentType: MimeType): void; // TODO Still originial source code. Maybe build additional types from it // ****************************************************************************** /* URL API */ // jsonld.url = require('./url'); /* Utility API */ // jsonld.util = util; // backwards compatibility // Object.assign(jsonld, util); // reexpose API as jsonld.promises for backwards compatability // jsonld.promises = jsonld; // backwards compatibility // declare module 'RequestQueue'; // ******************************************************************************