Options
All
  • Public
  • Public/Protected
  • All
Menu

Module @cipherstash/stashjs

Index

Type Aliases

Aggregate: "count"
AggregateResult: { name: Aggregate; value: bigint }

Type declaration

AggregationOptions<R, M>: { aggregate: Aggregate; ofIndex: Extract<keyof M, string> }

Type Parameters

Type declaration

  • aggregate: Aggregate
  • ofIndex: Extract<keyof M, string>
AllCondition<R, M>: { conditions: Condition<R, M>[]; kind: "all" }

A Condition representing a logical AND between two other Conditions.

Type Parameters

Type declaration

AsyncResult<V, E>: Promise<Result<V, E>>

In TypeScript a Promise only accepts a type parameter for the success result which prevents exhaustive case analysis to ensure that all errors are handled. To work around this, StashJS mandates use of the AsyncResult type wherever we would normally use a promise. This means Promises always resolve (even for errors). The success type is a Result<E, R>. This means the compiler can use exhaustive case analysis to ensure that all errors are handled.

StashJS considers all unhandled rejections as bugs.

TODO: upgrade TypeScript then change definition to: type AsyncResult<R, E> = Awaited<Result<R, E>>

Type Parameters

  • V

  • E

CollectionMetadata: { name: string; recordType: RecordTypeDefinition }

Type declaration

  • name: string
  • recordType: RecordTypeDefinition
CollectionSchemaDefinition: { indexes: {}; type: {} }

Type declaration

  • indexes: {}
    • [key: string]: Mapping
  • type: {}
    • [key: string]: RecordTypeDefinition | TermType
Condition<R, M>: IndexCondition<R, M> | ConjunctiveCondition<R, M>

A condition is a single boolean expression within a Query.

A Condition can be an IndexCondition (an assertion about values in an index) or a ConjuctiveCondition (to combine multiple conditions into a more complex condition).

Type Parameters

ConjunctiveCondition<R, M>: AllCondition<R, M>

Currently only supports logical AND but will logical OR is coming soon.

Type Parameters

DynamicMatchCondition<R, M, N>: { indexName: N; kind: "dynamic-match"; op: "match"; value: string }

A Condition that performs a textual match of a supplied string term with the index.

Type Parameters

Type declaration

  • indexName: N
  • kind: "dynamic-match"
  • op: "match"
  • value: string
DynamicMatchFn: ((options: MatchOptions) => DynamicMatchMapping)

Type declaration

DynamicMatchMapping: { fieldType: "string"; kind: "dynamic-match" } & MatchOptions

A dynamic version of match mapping. This mapping matches all string fields in a document, regardless of depth. All of the terms will be run through the same text preprocessing pipeline and all terms will be stored in the same index.

Every term is first siphashed and then ORE encrypted.

DynamicMatchOperators<R, M, N>: { match: any }

The operations that can be performed on a DynamicMatch index.

Type Parameters

Type declaration

ExactCondition<R, M, N>: { indexName: N; kind: "exact"; op: "eq"; value: FieldTypeOfMapping<R, M[N]> }

A Condition that compares for equality a supplied value and the value from the named index.

Type Parameters

Type declaration

ExactFn<R>: (<F>(field: F, fieldType: TermType) => ExactMapping<R, F>)

Type Parameters

Type declaration

ExactMapping<R, F>: { field: F; fieldType: TermType; kind: "exact" }

An exact mapping on a field on a record.

Type Parameters

Type declaration

  • field: F
  • fieldType: TermType
  • kind: "exact"
ExactMappingFieldType: string | number | bigint | Date | boolean

The types that exact mappings can be defined on.

ExactOperators<R, M, N>: { eq: any }

The operations that can be performed on an Exact index.

Type Parameters

Type declaration

FieldDynamicMatchCondition<R, M, N>: { fieldName: string; indexName: N; kind: "field-dynamic-match"; op: "match"; value: string }

A Condition that performs a textual match of a supplied string term with the index.

Type Parameters

Type declaration

  • fieldName: string
  • indexName: N
  • kind: "field-dynamic-match"
  • op: "match"
  • value: string
FieldDynamicMatchFn: ((options: MatchOptions) => FieldDynamicMatchMapping)

Type declaration

FieldDynamicMatchMapping: { fieldType: "string"; kind: "field-dynamic-match" } & MatchOptions

A dynamic version of match mapping. This mapping matches all string fields in a document, regardless of depth. All of the terms will be run through the same text preprocessing pipeline and all terms will be stored in the same index.

Every term is first siphashed and then ORE encrypted.

FieldDynamicMatchOperators<R, M, N>: { match: any }

The operations that can be performed on a DynamicMatch index.

Type Parameters

Type declaration

FieldOfType<R, T>: FindFieldsOfType<R, Field<R>, T>

Represents all Fields on R of type T.

Type Parameters

  • R

  • T

FieldTypeOfMapping<R, M>: M extends ExactMapping<R, infer FOT> ? FieldType<R, FOT> : M extends RangeMapping<R, infer FOT> ? FieldType<R, FOT> : M extends MatchMapping<R, infer FOT> ? FieldType<R, FOT> : M extends DynamicMatchMapping ? MatchMappingFieldType : M extends FieldDynamicMatchMapping ? MatchMappingFieldType : never

This is a utility type that when provided with a StashRecord type and a MappingOn on that StashRecord type it will return the type of the underlying field on the StashRecord type (e.g. string or boolean etc)

Type Parameters

HasID: { id: string }

Type declaration

  • id: string
IndexCondition<R, M>: { [ N in Extract<keyof M, string>]: M[N] extends ExactMapping<R, infer _FOT> ? ExactCondition<R, M, N> : M[N] extends RangeMapping<R, infer _FOT> ? RangeCondition<R, M, N> : M[N] extends MatchMapping<R, infer _FOT> ? MatchCondition<R, M, N> : M[N] extends DynamicMatchMapping ? DynamicMatchCondition<R, M, N> : M[N] extends FieldDynamicMatchMapping ? FieldDynamicMatchCondition<R, M, N> : never }[Extract<keyof M, string>]

Represents a condition defined in terms of an index.

An IndexCondition can be one of ExactCondition, RangeCondition or MatchCondition.

Type Parameters

Type Parameters

Fields of this type can be indexed and queried.

This type represents all of the kinds of permitted mapping types allowed on a record.

Type Parameters

Mappings<R>: {}

This type represents an object whose keys are the name of the index being defined and whose values are the mappings. Values of this type will be serialized and stored with the a Collection in the data-service.

Type Parameters

Type declaration

MappingsDSL<R>: { DynamicMatch: DynamicMatchFn; Exact: ExactFn<R>; FieldDynamicMatch: FieldDynamicMatchFn; Match: MatchFn<R>; Range: RangeFn<R> }

Type Parameters

Type declaration

MappingsMeta<M>: M extends Mappings<infer _R> ? { [ F in keyof M]-?: { $indexId: string; $indexName: string; $prfKey: Buffer; $prpKey: Buffer } } : never

This type represents some auto-generated meta information about a Mappings. It associates a plain text $indexName and $indexId (UUID) and also stores the encryption key for the index.

Type Parameters

  • M

MatchCondition<R, M, N>: { indexName: N; kind: "match"; op: "match"; value: string }

A Condition that performs a textual match of a supplied string term with the index.

Type Parameters

Type declaration

  • indexName: N
  • kind: "match"
  • op: "match"
  • value: string
MatchFn<R>: (<F>(field: F[], options: MatchOptions) => MatchMapping<R, F>)

Type Parameters

Type declaration

MatchMapping<R, F>: { fieldType: "string"; fields: F[]; kind: "match" } & MatchOptions

A match mapping on a field on a record.

Type Parameters

MatchMappingFieldType: string

The types that match mappings can be defined on.

MatchOperators<R, M, N>: { match: any }

The operations that can be performed on a Match index.

Type Parameters

Type declaration

MatchOptions: { tokenFilters: (TokenFilter | Tokenizer)[]; tokenizer: Tokenizer }

Type declaration

  • tokenFilters: (TokenFilter | Tokenizer)[]
  • tokenizer: Tokenizer
OauthAuthenticationInfo: { accessToken: string; expiry: number; refreshToken: string }

Type declaration

  • accessToken: string
  • expiry: number
  • refreshToken: string
OperatorsForIndex<R, M, N>: M[N] extends ExactMapping<R, FieldOfType<R, ExactMappingFieldType>> ? ExactOperators<R, M, N> : M[N] extends RangeMapping<R, FieldOfType<R, RangeMappingFieldType>> ? RangeOperators<R, M, N> : M[N] extends MatchMapping<R, FieldOfType<R, MatchMappingFieldType>> ? MatchOperators<R, M, N> : M[N] extends DynamicMatchMapping ? DynamicMatchOperators<R, M, N> : M[N] extends FieldDynamicMatchMapping ? FieldDynamicMatchOperators<R, M, N> : never

Utility type that when given a record, mappings and the name of an index, returns a type that represents the operations supported by that index.

Type Parameters

Ordering: "ASC" | "DESC"
OrderingOptions<R, M>: { byIndex: Extract<keyof M, string>; direction: Ordering }

Type Parameters

Type declaration

  • byIndex: Extract<keyof M, string>
  • direction: Ordering
Query<R, M>: Condition<R, M>

A Query is defined in terms of Mappings over a particular StashRecord.

Note that Condition is a recursive type via.

Type Parameters

QueryBuilder<R, M>: NeverObjectToAny<{ [ F in Extract<keyof M, string>]: OperatorsForIndex<R, M, F> }>

This type represents the sole argument provided to the callback when building a Query with CollectionProxy.all($ => ...).

It represents a type where every string key is the name of an index and the values are objects whose keys are the available operations that can be performed on that index.

Type Parameters

QueryBuilderCallback<R, M>: (($: QueryBuilder<R, M>) => Query<R, M>)

Type Parameters

Type declaration

QueryOptions<R, M>: { aggregation?: AggregationOptions<R, M>[]; limit?: number; offset?: number; order?: OrderingOptions<R, M>[]; skipResults?: boolean }

Type Parameters

Type declaration

  • Optional aggregation?: AggregationOptions<R, M>[]
  • Optional limit?: number
  • Optional offset?: number
  • Optional order?: OrderingOptions<R, M>[]
  • Optional skipResults?: boolean
QueryResult<R>: { aggregates: AggregateResult[]; documents: R[]; took: number }

Type Parameters

  • R

Type declaration

RangeCondition<R, M, N>: M[N] extends RangeMapping<R, infer F> ? { indexName: N; kind: "range"; op: ("lt" | "lte" | "eq" | "gt" | "gte") & RangeOperator; value: FieldType<R, F> } | { indexName: N; kind: "range"; max: FieldType<R, F>; min: FieldType<R, F>; op: "between" & RangeOperator } : never

A Condition that performs a comparison operation between a supplied value and the value from the named index.

Type Parameters

RangeFn<R>: (<F>(field: F, fieldType: TermType) => RangeMapping<R, F>)

Type Parameters

Type declaration

RangeMapping<R, F>: { field: F; fieldType: TermType; kind: "range" }

A range mapping on a field on a record.

Type Parameters

Type declaration

  • field: F
  • fieldType: TermType
  • kind: "range"
RangeMappingFieldType: string | number | bigint | Date | boolean

The types that range mappings can be defined on.

RangeOperator: "lt" | "lte" | "eq" | "gt" | "gte" | "between"

The names of all of the range operators.

RangeOperators<R, M, N, T>: { between: any; eq: any; gt: any; gte: any; lt: any; lte: any }

The operations that can be performed on a Range index.

Type Parameters

Type declaration

Result<V, E>: Readonly<{ ok: true; tag: "Result.Ok"; value: V }> | Readonly<{ error: E; ok: false; tag: "Result.Err" }>

The return type of fallible operation that can either produce a success result with a value or an error result.

Type Parameters

  • V

  • E

StashConfiguration: { identityProvider: IdentityProvider; keyManagement: KMSKey; service: { host: string; port?: number; workspace: string } }

Type declaration

  • Readonly identityProvider: IdentityProvider
  • Readonly keyManagement: KMSKey
  • Readonly service: { host: string; port?: number; workspace: string }
    • Readonly host: string
    • Optional Readonly port?: number
    • Readonly workspace: string
StashRecord: { id?: string }

A new record is permitted to not already have an assigned ID (the client will create an ID when one is not already set).

Type declaration

  • Optional id?: string
Unit: {}

Type declaration

    Variables

    Unit: Unit
    defaults: ConfigurationTemplate = ...
    downcase: DowncaseFilter = ...
    profileStore: StoreWithReadWriteLock = ...
    standard: StandardTokenizer = ...
    stashOauth: StashOauth = ...
    upcase: UpcaseFilter = ...

    Functions

    • Err<E>(error: E): Result<never, E>
    • Produces a failure result.

      Type Parameters

      • E

      Parameters

      • error: E

        the error to wrap

      Returns Result<never, E>

      the failure result

    • Produces a success result.

      Type Parameters

      • V

      Parameters

      • value: V

        the value to wrap

      Returns Result<V, never>

      the success result

    • Returns Result<void, never>

    • Creates an AllCondition from at least two conditions.

      The first and second argument are mandatory and there can be zero or more additional arguments.

      Type Parameters

      Parameters

      • condition1: Condition<R, M>

        the first condition

      • condition2: Condition<R, M>

        the second condition

      • Rest ...remainingConditions: Condition<R, M>[]

        additional conditions

      Returns AllCondition<R, M>

      an AllCondition representing the logical AND of all of the provided conditions.

    • Concatenates a Result<Array, E> with a Result<R, E> producing a new Ok<Array> both r1 and r2 are not Err.

      Type Parameters

      • V

      • E

      Parameters

      • r1: Result<V[], E>

        the result array

      • r2: Result<V, E>

        a singular result

      Returns Result<V[], E>

      Ok<Array> | Err

    • convertAsyncErrorsTo<V, E1, E2>(errorConstructor: ((rejection: E1) => E2), result: AsyncResult<V, E1>): AsyncResult<V, E2>
    • Type Parameters

      • V

      • E1

      • E2

      Parameters

      • errorConstructor: ((rejection: E1) => E2)
          • (rejection: E1): E2
          • Parameters

            • rejection: E1

            Returns E2

      • result: AsyncResult<V, E1>

      Returns AsyncResult<V, E2>

    • convertErrorsTo<V, E1, E2>(errorConstructor: ((rejection: E1) => E2), result: Result<V, E1>): Result<V, E2>
    • Converts the error from a failure result to the error type returned by errorConstructor.

      If the result is a success it is simply returned.

      Type Parameters

      • V

      • E1

      • E2

      Parameters

      • errorConstructor: ((rejection: E1) => E2)

        a constructor function that can build the required error type

          • (rejection: E1): E2
          • Parameters

            • rejection: E1

            Returns E2

      • result: Result<V, E1>

        the result who's error (if it's a failure result) should be converted

      Returns Result<V, E2>

      a new result value with the desired a error type

    • convertPrivateApiResult<R, E>(asyncResult: AsyncResult<R, E>): Promise<R>
    • Type Parameters

      • R

      • E

      Parameters

      Returns Promise<R>

    • describeError(err: unknown): string
    • Parameters

      • err: unknown

      Returns string

    • fromPromise<V, E>(promise: Promise<V>, errorConstructor: ((rejection: any) => E)): AsyncResult<V, E>
    • Converts a Promise to an AsyncResult<R, E>.

      This is useful for wrapping code from other 3rd-party modules to make them compatible with the StashJS error handling convention.

      Type Parameters

      • V

      • E

      Parameters

      • promise: Promise<V>

        the promise to convert

      • errorConstructor: ((rejection: any) => E)

        an error constructor

          • (rejection: any): E
          • Parameters

            • rejection: any

            Returns E

      Returns AsyncResult<V, E>

      an AsyncResult

    • fromPromiseFn2<V, E, T1, T2>(fn: ((arg1: T1, arg2: T2) => Promise<V>), errorConstructor: ((rejection: any) => E)): ((arg1: T1, arg2: T2) => AsyncResult<V, E>)
    • Converts a 2-argument function that returns a promise, into a 2-argument function that returns an AsyncResult.

      WARNING: you must ensure that the error constructor passed in will produce errors of the type you want. It is impossible to correctly type this function due to the error provided by a try-catch always having type any or unknown. This in turn forces us to use any for the type of the errorConstructor argument.

      Type Parameters

      • V

      • E

      • T1

      • T2

      Parameters

      • fn: ((arg1: T1, arg2: T2) => Promise<V>)

        the function that returns a promise

          • (arg1: T1, arg2: T2): Promise<V>
          • Parameters

            • arg1: T1
            • arg2: T2

            Returns Promise<V>

      • errorConstructor: ((rejection: any) => E)

        an error constuctor

          • (rejection: any): E
          • Parameters

            • rejection: any

            Returns E

      Returns ((arg1: T1, arg2: T2) => AsyncResult<V, E>)

      a 2-argument function that returns an AsyncResult

        • Converts a 2-argument function that returns a promise, into a 2-argument function that returns an AsyncResult.

          WARNING: you must ensure that the error constructor passed in will produce errors of the type you want. It is impossible to correctly type this function due to the error provided by a try-catch always having type any or unknown. This in turn forces us to use any for the type of the errorConstructor argument.

          Parameters

          • arg1: T1
          • arg2: T2

          Returns AsyncResult<V, E>

          a 2-argument function that returns an AsyncResult

    • Combines an Array<Result<V, E>> into a single Result<Array, E>.

      If any of the results in the array is an Err then the final result is an Err.

      Type Parameters

      • V

      • E

      Parameters

      • results: Result<V, E>[]

        the array of results to combine

      Returns Result<V[], E>

      Ok<Array> | Err

    • gatherTuple2<V1, E1, V2, E2>(results: [Result<V1, E1>, Result<V2, E2>]): Result<[V1, V2], E1 | E2>
    • Type Parameters

      • V1

      • E1

      • V2

      • E2

      Parameters

      Returns Result<[V1, V2], E1 | E2>

    • gatherTuple3<V1, E1, V2, E2, V3, E3>(results: [Result<V1, E1>, Result<V2, E2>, Result<V3, E3>]): Result<[V1, V2, V3], E1 | E2 | E3>
    • Type Parameters

      • V1

      • E1

      • V2

      • E2

      • V3

      • E3

      Parameters

      Returns Result<[V1, V2, V3], E1 | E2 | E3>

    • Guard function to check for dynamic match mappings

      Parameters

      • mapping: any

      Returns mapping is DynamicMatchMapping

    • isErr<E>(result: any): result is { error: E; ok: false; tag: "Result.Err" }
    • Type Parameters

      • E

      Parameters

      • result: any

      Returns result is { error: E; ok: false; tag: "Result.Err" }

    • isExactMapping<R, F>(mapping: any): mapping is ExactMapping<R, F>
    • Guard function to check for exact mappings

      Type Parameters

      Parameters

      • mapping: any

      Returns mapping is ExactMapping<R, F>

    • isMatchMapping<R, F>(mapping: any): mapping is MatchMapping<R, F>
    • Guard function to check for match mappings

      Type Parameters

      Parameters

      • mapping: any

      Returns mapping is MatchMapping<R, F>

    • isOk<V>(result: any): result is { ok: true; tag: "Result.Ok"; value: V }
    • Type Parameters

      • V

      Parameters

      • result: any

      Returns result is { ok: true; tag: "Result.Ok"; value: V }

    • isRangeMapping<R, F>(mapping: any): mapping is RangeMapping<R, F>
    • Guard function to check for range mappings

      Type Parameters

      Parameters

      • mapping: any

      Returns mapping is RangeMapping<R, F>

    • ngram(config: NgramTokenizerConfig): NgramTokenizer
    • Parameters

      • config: NgramTokenizerConfig

      Returns NgramTokenizer

    • parallel<V0, V1, V2, E1, E2>(fn1: ((initialValue: V0) => AsyncResult<V1, E1>), fn2: ((initialValue: V0) => AsyncResult<V2, E2>)): ((initialValue: V0) => AsyncResult<[V0, V1, V2], E1 | E2>)
    • Converts two functions that return AsyncResult into one function that returns an AsyncResult with a tuple of success values.

      parallel is typically useful when you want two independent operations to participate in a sequence call.

      Type Parameters

      • V0

      • V1

      • V2

      • E1

      • E2

      Parameters

      Returns ((initialValue: V0) => AsyncResult<[V0, V1, V2], E1 | E2>)

      a three-element tuple

        • Converts two functions that return AsyncResult into one function that returns an AsyncResult with a tuple of success values.

          parallel is typically useful when you want two independent operations to participate in a sequence call.

          Parameters

          • initialValue: V0

          Returns AsyncResult<[V0, V1, V2], E1 | E2>

          a three-element tuple

    • Removes errors from an Array<Result<V, E>>.

      Type Parameters

      • V

      • E

      Parameters

      • results: Result<V, E>[]

        the array of results to remove errors from

      Returns Result<V, E>[]

      Array<Result<V, E>>

    • Executes two (up to four) functions in sequence, feeding the success result of the previous function into the sole argument of the next function in the sequence. The final result is the AsyncResult of the final function in the sequence.

      If a function in the sequence produces an error result then non of the subsequent functions will be executed and the return value will be the error result of the function that produced the error.

      Type Parameters

      • V1

      • V2

      • V3

      • E1

      • E2

      Parameters

      Returns ((value: V1) => AsyncResult<V3, E1 | E2>)

      a success result if all functions in the sequence succeeded or an error result from the function in the sequence that failed.

        • Executes two (up to four) functions in sequence, feeding the success result of the previous function into the sole argument of the next function in the sequence. The final result is the AsyncResult of the final function in the sequence.

          If a function in the sequence produces an error result then non of the subsequent functions will be executed and the return value will be the error result of the function that produced the error.

          Parameters

          • value: V1

          Returns AsyncResult<V3, E1 | E2>

          a success result if all functions in the sequence succeeded or an error result from the function in the sequence that failed.

    • Implementation.

      see

      {@link sequence<V1, V2, V3, E1, E2>}

      Type Parameters

      • V1

      • V2

      • V3

      • V4

      • E1

      • E2

      • E3

      Parameters

      Returns ((value: V1) => AsyncResult<V4, E1 | E2 | E3>)

      a success result if all functions in the sequence succeeded or an error result from the function in the sequence that failed.

        • see

          {@link sequence<V1, V2, V3, E1, E2>}

          Parameters

          • value: V1

          Returns AsyncResult<V4, E1 | E2 | E3>

          a success result if all functions in the sequence succeeded or an error result from the function in the sequence that failed.

    • Implementation.

      see

      {@link sequence<V1, V2, V3, V4, E1, E2, E3>}

      Type Parameters

      • V1

      • V2

      • V3

      • V4

      • V5

      • E1

      • E2

      • E3

      • E4

      Parameters

      Returns ((value: V1) => AsyncResult<V5, E1 | E2 | E3 | E4>)

      a success result if all functions in the sequence succeeded or an error result from the function in the sequence that failed.

        • see

          {@link sequence<V1, V2, V3, V4, E1, E2, E3>}

          Parameters

          • value: V1

          Returns AsyncResult<V5, E1 | E2 | E3 | E4>

          a success result if all functions in the sequence succeeded or an error result from the function in the sequence that failed.

    • streamRecords(plaintextRecords: Object[]): AsyncGenerator<Object, void, unknown>
    • Parameters

      • plaintextRecords: Object[]

      Returns AsyncGenerator<Object, void, unknown>

    • Utility function to convert a synchronouse result to an asyncronous result.

      Type Parameters

      • V

      • E

      Parameters

      • result: Result<V, E>

        the result to convert

      Returns AsyncResult<V, E>

      a resolved AsyncResult

    Generated using TypeDoc