import type { IncomingHttpHeaders, IncomingMessage, OutgoingHttpHeaders } from 'node:http'; import type { parse } from 'node:querystring'; import type { ReadableStream } from 'node:stream/web'; import type { DatasetCore, NamedNode, Quad, Stream, Term } from '@rdfjs/types'; import type { GraphPointer, MultiPointer } from 'clownface'; import type { Options as EndpointOptions, StreamClient } from 'sparql-http-client/StreamClient.js'; import type { ParsingClient } from 'sparql-http-client/ParsingClient.js'; import type { Client } from 'sparql-http-client'; import type { KopflosEnvironment } from './env/index.js'; import type { ResourceShapeLookup, ResourceShapeMatch } from './resourceShape.js'; import type { ResourceLoader, ResourceLoaderLookup } from './resourceLoader.js'; import type { Handler, HandlerLookup } from './handler.js'; import type { HttpMethod } from './httpMethods.js'; import type { DecoratorLookup } from './decorators.js'; declare module '@rdfjs/types' { interface Stream extends AsyncIterable { } } type Dataset = ReturnType; export interface Body { isRDF: boolean; quadStream: Stream; dataset: Promise; pointer(): Promise>; raw: IncomingMessage; } export type Query = ReturnType; interface KopflosRequest { iri: NamedNode; method: HttpMethod; headers: IncomingHttpHeaders; body: Body; query: Query; } type ResultBody = Stream | DatasetCore | GraphPointer | Error | ReadableStream; export interface ResultEnvelope { body?: ResultBody | string; status?: number; headers?: OutgoingHttpHeaders; end?: boolean; } export type KopflosResponse = ResultBody | ResultEnvelope; export interface KopflosPlugin { readonly name?: string; onStart?(instance: Kopflos): Promise | void; onReady?(instance: Kopflos): Promise | void; onStop?(instance: Kopflos): Promise | void; apiTriples?(instance: Kopflos): Promise | DatasetCore | Stream; apiGraphs?(instance: Kopflos): Array; watchPaths?(instance: Kopflos): Array; build?: (env: KopflosEnvironment, plugins: readonly KopflosPlugin[]) => Promise | void; } export interface Plugins extends Record { } export interface Kopflos { get dataset(): D; get env(): KopflosEnvironment; get apis(): MultiPointer; get plugins(): ReadonlyArray; get start(): () => Promise; getPlugin(name: N): Plugins[N] | undefined; handleRequest(req: KopflosRequest): Promise; loadApiGraphs(): Promise; } interface Clients { stream: StreamClient; parsed: ParsingClient; } type Endpoint = string | EndpointOptions | Clients | Client; export interface Variables { [key: string]: unknown; } export interface KopflosConfig { [key: string]: unknown; mode?: 'development' | 'production'; baseIri: string; apiPath?: string; buildDir?: string; sparql: Record & { default: Endpoint; }; codeBase?: string; apiGraphs?: Array; plugins?: KopflosPlugin[]; variables?: Variables; } export interface Options { dataset?: DatasetCore; resourceShapeLookup?: ResourceShapeLookup; resourceLoaderLookup?: ResourceLoaderLookup; decoratorLookup?: DecoratorLookup; handlerLookup?: HandlerLookup; basePath?: string; } export default class Impl implements Kopflos { private readonly options; readonly apiGraphs: Array; readonly dataset: Dataset; readonly env: KopflosEnvironment; readonly plugins: Array; readonly start: () => Promise; readonly ready: () => Promise; private decorators; constructor({ variables, plugins, apiPath, ...config }: KopflosConfig, options?: Options); get graph(): import("clownface").AnyPointer; get apis(): MultiPointer; getPlugin(name: N): Plugins[N] | undefined; getResponse(req: KopflosRequest): Promise; private applicableDecorators; handleRequest(req: KopflosRequest): Promise; findResourceShape(iri: NamedNode): Promise; findResourceLoader(resourceShape: GraphPointer): Promise; loadHandlerChain(method: HttpMethod, resourceShapeMatch: ResourceShapeMatch, coreRepresentation: Stream): Promise<[GraphPointer, Handler[]] | KopflosResponse>; private isEnvelope; private asEnvelope; loadApiGraphs(): Promise; stop(): Promise; } export {};