Skip to main content

Module: @divine/uri

Namespaces

Classes

Interfaces

Type Aliases

CredentialsProvider

Ƭ CredentialsProvider<C>: (options: CredentialsProviderOptions<C>) => Promise<C | undefined>

Type parameters

NameTypeDescription
Cextends CredentialsThe type of credentials that is to be provied.

Type declaration

▸ (options): Promise<C | undefined>

A function used to provide or validate credentials for a request.

Params

options Information about the request how the provider should operate.

Parameters
NameType
optionsCredentialsProviderOptions<C>
Returns

Promise<C | undefined>

Defined in

uri/src/auth-schemes.ts:77

Variables

FIELDS

Const FIELDS: typeof FIELDS

Used in WithFields to attach field metadata to an object.

Defined in

uri/src/uri.ts:19


FINALIZE

Const FINALIZE: typeof FINALIZE

Used in Finalizable to attach a finializer function to an object.

Defined in

uri/src/uri.ts:22


HEADERS

Const HEADERS: typeof HEADERS

Used in Metadata to attach response headers to an object.

Defined in

uri/src/uri.ts:25


NULL

Const NULL: typeof NULL

This symbol, wrapped in an Object, represents a null value.

Defined in

uri/src/uri.ts:13


STATUS

Const STATUS: typeof STATUS

Used in Metadata to attach a response status code to an object.

Defined in

uri/src/uri.ts:28


STATUS_TEXT

Const STATUS_TEXT: typeof STATUS_TEXT

Used in Metadata to attach a response status message to an object.

Defined in

uri/src/uri.ts:31


VOID

Const VOID: typeof VOID

This symbol, wrapped in an Object, represents an undefined value.

Defined in

uri/src/uri.ts:16

Functions

encodeFilePath

encodeFilePath(filepath, type?): string

Normalizes a file path and then applies percentEncode to each individual path components.

Parameters

NameTypeDescription
filepathstringThe file path to encode.
type?"posix" | "windows"Indictes how the file path should be normalized.

Returns

string

The encoded file path.

Defined in

uri/src/file-utils.ts:24


guessContentType

guessContentType(pathname, knownContentType?): ContentType | undefined

If the media type is unknown, guesses the content type based on a path/file name. If the media type is known, that is what will be returned.

Parameters

NameTypeDescription
pathnamestringThe name of the object whose media type to guess.
knownContentType?string | ContentTypeIf provided, the actual media type.

Returns

ContentType | undefined

The value of knownContentType or a media type derived from the file name extension, or undefined.

Defined in

uri/src/file-utils.ts:58


guessFileExtension

guessFileExtension(contentType, invent, knownExtension?): string

If the file extension is unknown, derives the file name extension based on a media type. If the file extension is known, that is what will be returned.

Parameters

NameTypeDescription
contentTypestring | ContentTypeThe media type of the object whose file extension to guess.
inventtrueSet to true to invent an unofficial file extension if none could be guessed based on the media type.
knownExtension?stringIf provided, the actual file extension.

Returns

string

The value of knownExtension or a file extension derived from the media type.

Defined in

uri/src/file-utils.ts:74

guessFileExtension(contentType, invent?, knownExtension?): string | undefined

If the file extension is unknown, derives the file name extension based on a media type. If the file extension is known, that is what will be returned.

Parameters

NameTypeDescription
contentTypestring | ContentTypeThe media type of the object whose file extension to guess.
invent?booleanIf false, this method returns undefined if the file extension is unknown.
knownExtension?stringIf provided, the actual file extension.

Returns

string | undefined

The value of knownExtension or a file extension derived from the media type, or undefined if the file extension is unknown.

Defined in

uri/src/file-utils.ts:85


isEventStreamEvent

isEventStreamEvent(event): event is EventStreamEvent

Checks whether the passed argument is an EventStreamEvent.

Parameters

NameTypeDescription
eventanyThe object to check

Returns

event is EventStreamEvent

true if event is an EventStreamEvent.

Defined in

uri/src/parsers/event-stream.ts:25


q

q(query, ...params): DBQuery

Constructs a DBQuery from a template literal.

All values/parameters will either be quoted and encoded or sent separately to the database server for processing, depending on the actual database driver. Example:

const query = q`select * from table where first_name = ${firstName}`;

See also quote, raw, join, list, values and assign for handy utility functions.

Throws

TypeError If one of the parameters is undefined.

Parameters

NameType
queryTemplateStringsArray
...paramsunknown[]

Returns

DBQuery

A new DBQeury object.

Defined in

uri/src/protocols/database.ts:30

q(query, params): DBQuery

Constructs a DBQuery from a query string. The string may contain {prop} placeholders, which will then be resolved against properties in params.

All values/parameters will either be quoted and encoded or sent separately to the database server for processing, depending on the actual database driver. Example:

const query = q('select * from table where first_name = {name}', { name: firstName });

See also quote, raw, join, list, values and assign for handy utility functions.

Throws

TypeError If one of the parameters is undefined.

Parameters

NameTypeDescription
querystringThe query, with {prop} placeholders for parameters.
paramsParamsAn record with parameters, used to look up placeholders from the query. Parameters may be DBQuery instances themselves, or of any type supported by the database.

Returns

DBQuery

A new DBQeury object.

Defined in

uri/src/protocols/database.ts:51


toObject

toObject<T>(value): T

Converts a primitive value to an object and returns objects as-is.

undefined will be converted to Object(VOID) and null to Object(NULL). Any other non-object value will be converted via Object(value), which means that a string value will become a String object, a number will become a Number instance, et cetera.

toPrimitive can be used to reverse this operation.

Type parameters

NameType
Textends object

Parameters

NameTypeDescription
valueunknownThe value to convert to an object.

Returns

T

The value converted to an object.

Defined in

uri/src/parsers.ts:19


toPrimitive

toPrimitive(value): BasicTypes | symbol | undefined

Converts an object created by toObject back into the original value.

Parameters

NameTypeDescription
valueanyThe object that should be converted back to its original value.

Returns

BasicTypes | symbol | undefined

The original value.

Defined in

uri/src/parsers.ts:32


uri

uri(strings, ...values): string

@divine/uri template literal tag function that applies percentEncode to all arguments

Parameters

NameTypeDescription
stringsTemplateStringsArrayThe template string array.
...valuesunknown[]The values to be encoded.

Returns

string

A string with the arguments encoded.

Defined in

uri/src/file-utils.ts:13