Options
All
  • Public
  • Public/Protected
  • All
Menu

Index

Classes

Interfaces

Type aliases

Variables

Functions

Type aliases

Guarded

Guarded<T>: T & Guard

A stream that is guarded from emitting errors when there are no listeners. If an error occurs while no listener is attached, it will store the error and emit it once a listener is added (or a timeout occurs).

Type parameters

  • T: NodeJS.EventEmitter = NodeJS.EventEmitter

HttpRequest

HttpRequest: Guarded<IncomingMessage>

An incoming HTTP request;

HttpResponse

HttpResponse: ServerResponse

An outgoing HTTP response;

LogLevel

LogLevel: "error" | "warn" | "info" | "verbose" | "debug" | "silly"

Different log levels, from most important to least important.

MetadataIdentifier

MetadataIdentifier: ResourceIdentifier | NamedNode | BlankNode

MetadataRecord

MetadataRecord: Record<string, MetadataValue>

MetadataValue

MetadataValue: NamedNode | Literal | string | (NamedNode | Literal | string)[]

Namespace

Namespace<TKey, TValue>: { namespace: TValue } & RecordOf<TKey, TValue>

Type parameters

  • TKey: any[]

  • TValue

ValuePreferences

ValuePreferences: Record<string, number>

Represents preferred values along a single content negotiation dimension.

The number represents how preferred this value is from 0 to 1. Follows the quality values rule from RFC 7231: "The weight is normalized to a real number in the range 0 through 1, where 0.001 is the least preferred and 1 is the most preferred; a value of 0 means "not acceptable"."

Variables

Const ACL

ACL: { namespace: TValue } & Record<"default" | "accessTo" | "agent" | "agentClass" | "AuthenticatedAgent" | "mode" | "Write" | "Read" | "Append" | "Control", string> & { terms: Namespace<typeof localNames, NamedNode> } = ...

Const APPLICATION_OCTET_STREAM

APPLICATION_OCTET_STREAM: "application/octet-stream" = 'application/octet-stream'

Const APPLICATION_SPARQL_UPDATE

APPLICATION_SPARQL_UPDATE: "application/sparql-update" = 'application/sparql-update'

Const AUTH

AUTH: { namespace: TValue } & Record<"userMode" | "publicMode", string> & { terms: Namespace<typeof localNames, NamedNode> } = ...

Const CONTENT_TYPE

CONTENT_TYPE: string = ...

Const CONTENT_TYPE_TERM

CONTENT_TYPE_TERM: NamedNode<string> = ...

Const DC

DC: { namespace: TValue } & Record<"modified", string> & { terms: Namespace<typeof localNames, NamedNode> } = ...

Const FOAF

FOAF: { namespace: TValue } & Record<"Agent", string> & { terms: Namespace<typeof localNames, NamedNode> } = ...

Const HTTP

HTTP: { namespace: TValue } & Record<"location" | "slug", string> & { terms: Namespace<typeof localNames, NamedNode> } = ...

Const INTERNAL_ALL

INTERNAL_ALL: "internal/*" = 'internal/*'

Const INTERNAL_QUADS

INTERNAL_QUADS: "internal/quads" = 'internal/quads'

Const LDP

LDP: { namespace: TValue } & Record<"contains" | "BasicContainer" | "Container" | "Resource", string> & { terms: Namespace<typeof localNames, NamedNode> } = ...

Const MA

MA: { namespace: TValue } & Record<"format", string> & { terms: Namespace<typeof localNames, NamedNode> } = ...

Const PIM

PIM: { namespace: TValue } & Record<"Storage", string> & { terms: Namespace<typeof localNames, NamedNode> } = ...

Const POSIX

POSIX: { namespace: TValue } & Record<"mtime" | "size", string> & { terms: Namespace<typeof localNames, NamedNode> } = ...

Const PREFERRED_PREFIX

PREFERRED_PREFIX: string = ...

Const PREFERRED_PREFIX_TERM

PREFERRED_PREFIX_TERM: NamedNode<string> = ...

Const RDF

RDF: { namespace: TValue } & Record<"type", string> & { terms: Namespace<typeof localNames, NamedNode> } = ...

Const TEMPLATE

TEMPLATE: { namespace: TValue } & Record<"ResourceStore", string> & { terms: Namespace<typeof localNames, NamedNode> } = ...

Const TEMPLATE_VARIABLE

TEMPLATE_VARIABLE: { namespace: TValue } & Record<"baseUrl" | "rootFilePath" | "sparqlEndpoint" | "templateConfig", string> & { terms: Namespace<typeof localNames, NamedNode> } = ...

Const TEXT_TURTLE

TEXT_TURTLE: "text/turtle" = 'text/turtle'

Const VANN

VANN: { namespace: TValue } & Record<"preferredNamespacePrefix", string> & { terms: Namespace<typeof localNames, NamedNode> } = ...

Const XSD

XSD: { namespace: TValue } & Record<"dateTime" | "integer", string> & { terms: Namespace<typeof localNames, NamedNode> } = ...

Functions

absoluteFilePath

  • absoluteFilePath(path: string): string
  • Resolves a path to its absolute form. Absolute inputs will not be changed (except changing Windows to POSIX). Relative inputs will be interpreted relative to process.cwd().

    Parameters

    • path: string

      Path to check (POSIX or Windows).

    Returns string

    The potentially changed path (POSIX).

addGeneratedResources

addHeader

  • addHeader(response: ServerResponse, name: string, value: string | string[]): void
  • Adds a header value without overriding previous values.

    Parameters

    • response: ServerResponse
    • name: string
    • value: string | string[]

    Returns void

createNamespace

  • createNamespace<TKey, TValue>(baseUri: string, toValue: (expanded: string) => TValue, ...localNames: TKey[]): Namespace<TKey[], TValue>
  • Creates a function that expands local names from the given base URI, and exports the given local names as properties on the returned object.

    Type parameters

    • TKey: string

    • TValue

    Parameters

    • baseUri: string
    • toValue: (expanded: string) => TValue
        • (expanded: string): TValue
        • Parameters

          • expanded: string

          Returns TValue

    • Rest ...localNames: TKey[]

    Returns Namespace<TKey[], TValue>

createSubdomainRegexp

  • createSubdomainRegexp(baseUrl: string): RegExp
  • Creates a regular expression that matches URLs containing the given baseUrl, or a subdomain of the given baseUrl. In case there is a subdomain, the first match of the regular expression will be that subdomain.

    Examples with baseUrl http://test.com/foo/:

    • Will match http://test.com/foo/
    • Will match http://test.com/foo/bar/baz
    • Will match http://alice.bob.test.com/foo/bar/baz, first match result will be alice.bob
    • Will not match http://test.com/
    • Will not match http://alicetest.com/foo/

    Parameters

    • baseUrl: string

      Base URL for the regular expression.

    Returns RegExp

createTermNamespace

  • createTermNamespace<T>(baseUri: string, ...localNames: T[]): Namespace<T[], NamedNode<string>>
  • Creates a function that expands local names from the given base URI into named nodes, and exports the given local names as properties on the returned object.

    Type parameters

    • T: string

    Parameters

    • baseUri: string
    • Rest ...localNames: T[]

    Returns Namespace<T[], NamedNode<string>>

createUriAndTermNamespace

  • createUriAndTermNamespace<T>(baseUri: string, ...localNames: T[]): { namespace: TValue } & Record<T, string> & { terms: Namespace<typeof localNames, NamedNode> }
  • Creates a function that expands local names from the given base URI into string, and exports the given local names as properties on the returned object. Under the terms property, it exposes the expanded local names as named nodes.

    Type parameters

    • T: string

    Parameters

    • baseUri: string
    • Rest ...localNames: T[]

    Returns { namespace: TValue } & Record<T, string> & { terms: Namespace<typeof localNames, NamedNode> }

createUriNamespace

  • createUriNamespace<T>(baseUri: string, ...localNames: T[]): Namespace<T[], string>
  • Creates a function that expands local names from the given base URI into strings, and exports the given local names as properties on the returned object.

    Type parameters

    • T: string

    Parameters

    • baseUri: string
    • Rest ...localNames: T[]

    Returns Namespace<T[], string>

decodeUriPathComponents

  • decodeUriPathComponents(path: string): string

encodeUriPathComponents

  • encodeUriPathComponents(path: string): string
  • Encodes all (non-slash) special characters in a URI path.

    Parameters

    • path: string

    Returns string

ensureTrailingSlash

  • ensureTrailingSlash(path: string): string
  • Makes sure the input path has exactly 1 slash at the end. Multiple slashes will get merged into one. If there is no slash it will be added.

    Parameters

    • path: string

      Path to check.

    Returns string

    The potentially changed path.

extractScheme

  • extractScheme(url: string): { rest: string; scheme: string }
  • Splits a URL (or similar) string into a part containing its scheme and one containing the rest. E.g., http://test.com/ results in { scheme: 'http://', rest: 'test.com/' }.

    Parameters

    • url: string

      String to parse.

    Returns { rest: string; scheme: string }

    • rest: string
    • scheme: string

getExtension

  • getExtension(path: string): string
  • Extracts the extension (without dot) from a path. Custom function since path.extname does not work on all cases (e.g. ".acl")

    Parameters

    • path: string

      Input path to parse.

    Returns string

getLoggerFor

  • getLoggerFor(loggable: string | Instance): Logger
  • Gets a logger instance for the given class instance.

    The returned type of logger depends on the configured LoggerFactory in {@link Setup}.

    The following shows a typical pattern on how to create loggers:

    class MyClass {
      protected readonly logger = getLoggerFor(this);
    }
    

    If no class is applicable, a logger can also be created as follows:

    const logger = getLoggerFor('MyFunction');
    

    Parameters

    • loggable: string | Instance

      A class instance or a class string name.

    Returns Logger

guardStream

  • guardStream<T>(stream: T): Guarded<T>
  • Makes sure that listeners always receive the error event of a stream, even if it was thrown before the listener was attached.

    When guarding a stream it is assumed that error listeners already attached should be ignored, only error listeners attached after the stream is guarded will prevent an error from being logged.

    If the input is already guarded the guard will be reset, which means ignoring error listeners already attached.

    Type parameters

    • T: EventEmitter<T>

    Parameters

    • stream: T

      Stream that can potentially throw an error.

    Returns Guarded<T>

    The stream.

guardedStreamFrom

  • guardedStreamFrom(contents: string | Iterable<any>, options?: ReadableOptions): Guarded<Readable>
  • Converts a string or array to a stream and applies an error guard so that it is Guarded.

    Parameters

    • contents: string | Iterable<any>

      Data to stream.

    • Optional options: ReadableOptions

      Options to pass to the Readable constructor. See {@link Readable.from}.

    Returns Guarded<Readable>

hasMatchingMediaTypes

  • hasMatchingMediaTypes(preferredTypes?: Record<string, number>, availableTypes?: Record<string, number>): boolean
  • Determines whether any available type satisfies the preferences.

    throws

    BadRequestHttpError If the type preferences are undefined or if there are duplicate preferences.

    Parameters

    • Optional preferredTypes: Record<string, number>

      Preferences for output type.

    • Optional availableTypes: Record<string, number>

      Media types to compare to the preferences.

    Returns boolean

    Whether there is at least one preference match.

isContainerIdentifier

isContainerPath

  • isContainerPath(path: string): boolean
  • Checks if the path corresponds to a container path (ending in a /).

    Parameters

    • path: string

      Path to check.

    Returns boolean

isGuarded

  • isGuarded<T>(stream: T): stream is Guarded<T>
  • Determines whether the stream is guarded from emitting errors.

    Type parameters

    • T: EventEmitter<T>

    Parameters

    • stream: T

    Returns stream is Guarded<T>

isRepresentationMetadata

isResourceIdentifier

isSystemError

isTerm

  • isTerm(input?: any): input is Term
  • Parameters

    • Optional input: any

      Checks if this is a {@link Term}.

    Returns input is Term

isValidVariable

  • isValidVariable(variable: string): boolean
  • Checks if the given variable is one that is supported. This can be used to weed out irrelevant parameters in an object.

    Parameters

    • variable: string

    Returns boolean

joinFilePath

  • joinFilePath(basePath: string, ...paths: string[]): string
  • Adds the paths to the base path.

    Parameters

    • basePath: string

      The base path (POSIX or Windows).

    • Rest ...paths: string[]

      Subpaths to attach (POSIX).

    Returns string

    The potentially changed path (POSIX).

matchesMediaType

  • matchesMediaType(mediaA: string, mediaB: string): boolean
  • Checks if the given two media types/ranges match each other. Takes wildcards into account.

    Parameters

    • mediaA: string

      Media type to match.

    • mediaB: string

      Media type to match.

    Returns boolean

    True if the media type patterns can match each other.

matchingMediaTypes

  • matchingMediaTypes(preferredTypes?: Record<string, number>, availableTypes?: Record<string, number>): string[]
  • Filters media types based on the given preferences. Based on RFC 7231 - Content negotiation. Will add a default internal/*;q=0 to the preferences to prevent accidental use of internal types. Since more specific media ranges override less specific ones, this will be ignored if there is a specific internal type preference.

    This should be called even if there are no preferredTypes since this also filters out internal types.

    throws

    BadRequestHttpError If the type preferences are undefined or if there are duplicate preferences.

    Parameters

    • preferredTypes: Record<string, number> = ...

      Preferences for output type.

    • availableTypes: Record<string, number> = ...

      Media types to compare to the preferences.

    Returns string[]

    The weighted and filtered list of matching types.

normalizeFilePath

  • normalizeFilePath(path: string): string
  • Resolves relative segments in the path.

    Parameters

    • path: string

      Path to check (POSIX or Windows).

    Returns string

    The potentially changed path (POSIX).

parseAccept

  • parseAccept(input: string): Accept[]

parseAcceptCharset

parseAcceptDateTime

parseAcceptEncoding

parseAcceptLanguage

parseForwarded

  • parseForwarded(headers: IncomingHttpHeaders): Forwarded
  • Parses a Forwarded header value and will fall back to X-Forwarded-* headers.

    Parameters

    • headers: IncomingHttpHeaders

      The incoming HTTP headers.

    Returns Forwarded

    The parsed Forwarded header.

parseParameters

  • parseParameters(parameters: string[], replacements: Record<string, string>): { name: string; value: string }[]
  • Parses a list of split parameters and checks their validity.

    throws

    BadRequestHttpError Thrown on invalid parameter syntax.

    Parameters

    • parameters: string[]

      A list of split parameters (token [ "=" ( token / quoted-string ) ])

    • replacements: Record<string, string>

      The double quoted strings that need to be replaced.

    Returns { name: string; value: string }[]

    An array of name/value objects corresponding to the parameters.

parseQuads

  • parseQuads(readable: Guarded<Readable>, options?: ParserOptions): Promise<Quad[]>
  • Helper function to convert a Readable into an array of quads.

    Parameters

    • readable: Guarded<Readable>

      The readable object.

    • options: ParserOptions = ...

      Options for the parser.

    Returns Promise<Quad[]>

    A promise containing the array of quads.

pipeSafely

  • pipeSafely<T>(readable: ReadableStream, destination: T, mapError?: (error: Error) => Error): Guarded<T>
  • Pipes one stream into another and emits errors of the first stream with the second. In case of an error in the first stream the second one will be destroyed with the given error. This will also make the stream Guarded.

    Type parameters

    • T: Writable<T>

    Parameters

    • readable: ReadableStream

      Initial readable stream.

    • destination: T

      The destination for writing data.

    • Optional mapError: (error: Error) => Error

      Optional function that takes the error and converts it to a new error.

        • (error: Error): Error
        • Parameters

          • error: Error

          Returns Error

    Returns Guarded<T>

    The destination stream.

pushQuad

  • pushQuad(quads: Readable | Quad[], subject: string | NamedNode<string>, predicate: string | NamedNode<string>, object: string | Literal | NamedNode<string>): void
  • Generates a quad with the given subject/predicate/object and pushes it to the given array.

    Parameters

    • quads: Readable | Quad[]
    • subject: string | NamedNode<string>
    • predicate: string | NamedNode<string>
    • object: string | Literal | NamedNode<string>

    Returns void

readableToString

  • readableToString(stream: Readable): Promise<string>
  • Joins all strings of a stream.

    Parameters

    • stream: Readable

      Stream of strings.

    Returns Promise<string>

    The joined string.

resetGlobalLoggerFactory

  • resetGlobalLoggerFactory(): void
  • Resets the global logger factory to undefined.

    This typically only needs to be called during testing. Call this at your own risk.

    Returns void

serializeQuads

  • serializeQuads(quads: Quad[], contentType?: string): Guarded<Readable>
  • Helper function for serializing an array of quads, with as result a Readable object.

    Parameters

    • quads: Quad[]

      The array of quads.

    • Optional contentType: string

      The content-type to serialize to.

    Returns Guarded<Readable>

    The Readable object.

setGlobalLoggerFactory

splitAndClean

  • splitAndClean(input: string): string[]
  • Splits the input string on commas, trims all parts and filters out empty ones.

    Parameters

    • input: string

      Input header string.

    Returns string[]

supportsMediaTypeConversion

  • supportsMediaTypeConversion(inputType?: string, outputTypes?: Record<string, number>, convertorIn?: Record<string, number>, convertorOut?: Record<string, number>): void
  • Determines whether the given conversion request is supported, given the available content type conversions:

    • Checks if there is a content type for the input.
    • Checks if the input type is supported by the parser.
    • Checks if the parser can produce one of the preferred output types. Throws an error with details if conversion is not possible.

    Parameters

    • inputType: string = 'unknown'

      Actual input type.

    • outputTypes: Record<string, number> = ...

      Acceptable output types.

    • convertorIn: Record<string, number> = ...

      Media types that can be parsed by the converter.

    • convertorOut: Record<string, number> = ...

      Media types that can be produced by the converter.

    Returns void

toCachedNamedNode

  • toCachedNamedNode(name: string | NamedNode<string>): NamedNode<string>
  • Converts the incoming name (URI or shorthand) to a named node. The generated terms get cached to reduce the number of created nodes, so only use this for internal constants!

    Parameters

    • name: string | NamedNode<string>

      Predicate to potentially transform.

    Returns NamedNode<string>

toCanonicalUriPath

  • toCanonicalUriPath(path: string): string
  • Converts a URI path to the canonical version by splitting on slashes, decoding any percent-based encodings, and then encoding any special characters.

    Parameters

    • path: string

    Returns string

toLiteral

  • toLiteral(object: string | number, dataType: NamedNode<string>): Literal
  • Creates a literal by first converting the dataType string to a named node.

    Parameters

    • object: string | number

      Object value.

    • dataType: NamedNode<string>

      Object data type (as string).

    Returns Literal

toObjectTerm

  • toObjectTerm(object: string, preferLiteral?: boolean): NamedNode<string>
  • toObjectTerm<T>(object: T, preferLiteral?: boolean): T
  • toObjectTerm<T>(object: string | T, preferLiteral?: boolean): NamedNode<string> | T
  • Converts an object term when needed.

    Parameters

    • object: string

      Object to potentially transform.

    • Optional preferLiteral: boolean

      Whether strings are converted to literals or named nodes.

    Returns NamedNode<string>

  • Type parameters

    • T: Term

    Parameters

    • object: T
    • Optional preferLiteral: boolean

    Returns T

  • Type parameters

    • T: Term

    Parameters

    • object: string | T
    • Optional preferLiteral: boolean

    Returns NamedNode<string> | T

Const toPredicateTerm

  • toPredicateTerm(subject: string): NamedNode<string>
  • toPredicateTerm<T>(subject: T): T
  • toPredicateTerm<T>(subject: string | T): NamedNode<string> | T

toSubjectTerm

  • toSubjectTerm(subject: string): NamedNode<string>
  • toSubjectTerm<T>(subject: T): T
  • toSubjectTerm<T>(subject: string | T): NamedNode<string> | T
  • Converts a subject to a named node when needed.

    Parameters

    • subject: string

      Subject to potentially transform.

    Returns NamedNode<string>

  • Type parameters

    • T: Term

    Parameters

    • subject: T

    Returns T

  • Type parameters

    • T: Term

    Parameters

    • subject: string | T

    Returns NamedNode<string> | T

transformQuotedStrings

  • transformQuotedStrings(input: string): { replacements: Record<string, string>; result: string }
  • Replaces all double quoted strings in the input string with "0", "1", etc.

    Parameters

    • input: string

      The Accept header string.

    Returns { replacements: Record<string, string>; result: string }

    The transformed string and a map with keys "0", etc. and values the original string that was there.

    • replacements: Record<string, string>
    • result: string

transformSafely

  • Transforms a stream, ensuring that all errors are forwarded.

    Type parameters

    • T = any

    Parameters

    Returns Guarded<Transform>

    The transformed stream

trimTrailingSlashes

  • trimTrailingSlashes(path: string): string
  • Makes sure the input path has no slashes at the end.

    Parameters

    • path: string

      Path to check.

    Returns string

    The potentially changed path.