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>>
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).
Currently only supports logical AND but will logical OR is coming soon.
A Condition that performs a textual match of a supplied string term with the index.
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.
The operations that can be performed on a DynamicMatch index.
A Condition that compares for equality a supplied value and the value from the named index.
An exact mapping on a field on a record.
The types that exact mappings can be defined on.
The operations that can be performed on an Exact index.
A Condition that performs a textual match of a supplied string term with the index.
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.
The operations that can be performed on a DynamicMatch index.
Represents all Fields on R of type T.
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)
Represents a condition defined in terms of an index.
An IndexCondition can be one of ExactCondition, RangeCondition or MatchCondition.
Fields of this type can be indexed and queried.
This type represents all of the kinds of permitted mapping types allowed on a record.
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.
This type represents some auto-generated meta information about a
Mappings
A Condition that performs a textual match of a supplied string term with the index.
A match mapping on a field on a record.
The types that match mappings can be defined on.
The operations that can be performed on a Match index.
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.
A Query is defined in terms of Mappings over a particular StashRecord.
Note that Condition is a recursive type via.
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.
A Condition that performs a comparison operation between a supplied value and the value from the named index.
A range mapping on a field on a record.
The types that range mappings can be defined on.
The names of all of the range operators.
The operations that can be performed on a Range index.
The return type of fallible operation that can either produce a success result with a value or an error result.
A new record is permitted to not already have an assigned ID (the client will create an ID when one is not already set).
Produces a failure result.
the error to wrap
the failure result
Creates an AllCondition from at least two conditions.
The first and second argument are mandatory and there can be zero or more additional arguments.
the first condition
the second condition
additional conditions
an AllCondition representing the logical AND of all of the provided conditions.
Converts the error from a failure result to the error type returned by errorConstructor
.
If the result is a success it is simply returned.
a constructor function that can build the required error type
the result who's error (if it's a failure result) should be converted
a new result value with the desired a error type
Converts a Promise
This is useful for wrapping code from other 3rd-party modules to make them compatible with the StashJS error handling convention.
the promise to convert
an error constructor
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.
the function that returns a promise
an error constuctor
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.
a 2-argument function that returns an AsyncResult
Guard function to check for dynamic match mappings
Guard function to check for exact mappings
Guard function to check for dynamic match mappings
Guard function to check for match mappings
Guard function to check for range mappings
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.
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.
a three-element tuple
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.
the first function in the sequence
the second function in the sequence
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.
a success result if all functions in the sequence succeeded or an error result from the function in the sequence that failed.
Implementation.
the first function in the sequence
the second function in the sequence
the third function in the sequence
a success result if all functions in the sequence succeeded or an error result from the function in the sequence that failed.
a success result if all functions in the sequence succeeded or an error result from the function in the sequence that failed.
Implementation.
the first function in the sequence
the second function in the sequence
the third function in the sequence
the fourth function in the sequence
a success result if all functions in the sequence succeeded or an error result from the function in the sequence that failed.
a success result if all functions in the sequence succeeded or an error result from the function in the sequence that failed.
Utility function to convert a synchronouse result to an asyncronous result.
the result to convert
a resolved AsyncResult
Generated using TypeDoc
A Condition representing a logical AND between two other Conditions.