Comunica
    Preparing search index...

    An HTTP service that exposes a Comunica engine as a SPARQL endpoint.

    Index

    Constructors

    Properties

    context: any
    contextOverride: boolean
    emitVoid: boolean
    engine: Promise<
        QueryEngineBase<
            IQueryContextCommon,
            QueryStringContext,
            QueryAlgebraContext,
        >,
    >
    freshWorkerPerQuery: boolean
    graphStore: HttpServiceGraphStore | undefined
    lastQueryId: number = 0
    port: number
    shutdownWorker: (() => Promise<void>) | undefined

    Ends all open connections and stops this worker, once it runs as a worker.

    timeout: number
    voidMetadataEmitter: VoidMetadataEmitter
    warmup: number
    workers: number
    ALLOWED_METHODS: "GET, HEAD, OPTIONS, POST, QUERY" = 'GET, HEAD, OPTIONS, POST, QUERY'

    The HTTP methods this service handles, as advertised via the Allow and Access-Control-Allow-Methods headers.

    MIME_HTML: "text/html" = 'text/html'
    MIME_JSON: "application/json" = 'application/json'
    MIME_PLAIN: "text/plain" = 'text/plain'
    MIME_SPARQL_QUERY: "application/sparql-query" = 'application/sparql-query'

    The query format that is accepted in the body of HTTP QUERY requests (RFC 10008).

    NEGOTIATION_CACHE_SIZE: 1000 = 1_000

    The maximum number of distinct request headers for which negotiated media types are cached.

    Methods

    • Apply the dataset that a request specifies through the SPARQL protocol to the query it contains. The query is returned unchanged if the request does not specify a dataset.

      Parameters

      • engine: QueryEngineBase

        A SPARQL engine.

      • queryBody: IQueryBody

        The query body.

      • requestUrl: UrlWithParsedQuery

        The parsed request URL.

      • context: Record<string, any>

        The query context.

      Returns Promise<string | BaseOperation>

      The query to execute.

    • Handles an HTTP request.

      Parameters

      • engine: QueryEngineBase

        A SPARQL engine.

      • variants: { quality: number; type: string }[]

        Allowed variants.

      • stdout: Writable

        Output stream.

      • stderr: Writable

        Error output stream.

      • request: IncomingMessage

        Request object.

      • response: ServerResponse

        Response object.

      Returns Promise<void>

    • Determine the media type of the response, or null to fall back to the default media type of the result.

      Parameters

      • variants: { quality: number; type: string }[]

        Allowed variants.

      • request: IncomingMessage

        Request object.

      Returns string | null

    • Start the HTTP service.

      Parameters

      • stdout: Writable

        The output stream to log to.

      • stderr: Writable

        The error stream to log errors to.

      Returns Promise<void>

    • Start the HTTP service as master.

      Parameters

      • stdout: Writable

        The output stream to log to.

      • stderr: Writable

        The error stream to log errors to.

      Returns Promise<void>

    • Start the HTTP service as worker.

      Parameters

      • stdout: Writable

        The output stream to log to.

      • stderr: Writable

        The error stream to log errors to.

      Returns Promise<void>

    • Stop after timeout or if the connection is terminated

      Parameters

      • response: ServerResponse

        Response object.

      • queryId: number

        The unique query id.

      • stderr: Writable

        Error stream to write to.

      • OptionaleventEmitter: EventEmitter<DefaultEventMap>

        Query result stream.

      Returns void

    • Stop this worker because a query took longer than the timeout. The main process then starts a new worker.

      Parameters

      • queryId: number

        The id of the query that timed out.

      • stderr: Writable

        Error stream to write to.

      Returns void

    • Warm up the engine over the sources of this endpoint, so that the just-in-time compiler has optimized the engine before it handles requests. Failures are logged, but do not prevent the worker from starting.

      Parameters

      • engine: QueryEngineBase

        A SPARQL engine.

      • stderr: Writable

        Error stream to write to.

      Returns Promise<void>

    • Writes a 400 response with the given message.

      Parameters

      • stdout: Writable

        Output stream.

      • response: ServerResponse

        Response object.

      • message: string

        The reason why the request was rejected.

      Returns void

    • Writes the outcome of a request of the Graph Store HTTP Protocol.

      Parameters

      • engine: QueryEngineBase

        A SPARQL engine.

      • stdout: Writable

        Output stream.

      • request: IncomingMessage

        Request object.

      • response: ServerResponse

        Response object.

      • result: IGraphStoreResult

        The outcome of the request.

      • mediaType: string

        The requested response media type.

      Returns Promise<void>

    • Writes an HTML view with YASGUI for querying the endpoint.

      Parameters

      • stdout: Writable

        Output stream.

      • request: IncomingMessage

        Request object.

      • response: ServerResponse

        Response object.

      Returns Promise<void>

    • Answers a CORS preflight request, which browsers always send for the methods that are not simple: QUERY, and the PUT and DELETE of the Graph Store HTTP Protocol.

      Parameters

      • stdout: Writable

        Output stream.

      • request: IncomingMessage

        Request object.

      • response: ServerResponse

        Response object.

      • methodAdvertisementHeaders: Record<string, string>

        The headers that advertise the allowed methods.

      Returns void

    • Writes the result of the given SPARQL query.

      Parameters

      • engine: QueryEngineBase

        A SPARQL engine.

      • stdout: Writable

        Output stream.

      • stderr: Writable

        Error output stream.

      • request: IncomingMessage

        Request object.

      • response: ServerResponse

        Response object.

      • queryBody: IQueryBody | undefined

        The query body.

      • mediaType: string

        The requested response media type.

      • headOnly: boolean

        If only the header should be written.

      • readOnly: boolean

        If only data can be read, but not updated. (i.e., if we're in a GET request)

      • queryId: number

        The unique id of this query.

      Returns Promise<void>

    • Parameters

      • engine: QueryEngineBase
      • stdout: Writable
      • stderr: Writable
      • request: IncomingMessage
      • response: ServerResponse
      • mediaType: string
      • headOnly: boolean

      Returns Promise<void>

    • Apply the protocol-specified dataset to the WHERE clauses of an update operation.

      Parameters

      • algebraFactory: AlgebraFactory

        An algebra factory.

      • operation: BaseOperation

        An update operation.

      • dataset: { default: NamedNode<string>[]; named: NamedNode<string>[] }

        The protocol-specified dataset.

        • default: NamedNode<string>[]

          The graphs that form the default graph.

        • named: NamedNode<string>[]

          The named graphs.

      Returns BaseOperation

      The update operation with the dataset applied.

    • Takes parsed commandline arguments and turns them into an object used in the HttpServiceSparqlEndpoint constructor

      Parameters

      • argv: string[]

        The commandline arguments that the script was called with

      • moduleRootPath: string

        The path to the invoking module.

      • env: ProcessEnv

        The process env to get constants from.

      • defaultConfigPath: string

        The path to get the config from if none is defined in the environment.

      • stderr: Writable

        The error stream.

      • exit: (code: number) => void

        An exit process callback.

      • cliArgsHandlers: ICliArgsHandler[]

        Enables manipulation of the CLI arguments and their processing.

      Returns Promise<IHttpServiceSparqlEndpointArgs>

    • Determine the base IRI that relative IRIs in a request are resolved against.

      Parameters

      • request: IncomingMessage

        Request object.

      • port: number

        The port this service is running on.

      • path: string = '/sparql'

        The path of the service on this server.

      Returns string

      The base IRI.

    • Determines the headers with which this service advertises the HTTP methods and query formats it supports.

      Parameters

      • headers: Record<string, string>

        The headers to extend.

      Returns Record<string, string>

      The given headers, extended with the method advertisement headers.

    • Determine the RDF dataset that a request specifies through the SPARQL protocol.

      Parameters

      • requestUrl: UrlWithParsedQuery

        The parsed request URL.

      • type: "query" | "void"

        The type of operation the dataset applies to.

      Returns { default: NamedNode<string>[]; named: NamedNode<string>[] }

      The graphs that form the default graph, and the named graphs.

    • Reads the body of a request as a UTF-8 string.

      Parameters

      • request: IncomingMessage

        Request object.

      Returns Promise<string>

      A promise resolving to the request body.

    • Starts the server

      Parameters

      • argv: string[]

        The commandline arguments that the script was called with

      • stdout: Writable

        The output stream to log to.

      • stderr: Writable

        The error stream to log errors to.

      • moduleRootPath: string

        The path to the invoking module.

      • env: ProcessEnv

        The process env to get constants from.

      • defaultConfigPath: string

        The path to get the config from if none is defined in the environment.

      • exit: (code: number) => void

        The callback to invoke to stop the script.

      • cliArgsHandlers: ICliArgsHandler[] = []

        Enables manipulation of the CLI arguments and their processing.

      Returns Promise<void>

      A promise that resolves when the server has been started.