@cognizone/model-utils
Classes​
Interfaces​
- ElasticAggregation
- ElasticBucket
- ElasticHit
- ElasticQuery
- ElasticSearchResponse
- GetSelectOptionsParams
- LangString
- LangStringSimple
- Pagination
- SelectOption
- SelectOptionCounts
- SelectOptionGroup
- SelectOptionsProvider
Type aliases​
Completable​
Ƭ Completable<T
>: Observable
<T
> | Promise
<T
> | T
The Completable
type represents a resource that should "complete" in the
Observable sense. A Completable
is either directly the generic type given,
a Promise
that returns that type or an Observable
that does the same.
Type parameters​
Name |
---|
T |
Defined in​
CzLabel​
Ƭ CzLabel: LangString
| LangStringSimple
| string
Union type that encompass all the usual types we use for labels
Defined in​
Dictionary​
Ƭ Dictionary<T
>: Object
A shorthand for indexed object with string
as keys
Type parameters​
Name |
---|
T |
Index signature​
â–ª [index: string
]: T
Defined in​
Many​
Ƭ Many<T
>: T
| T
[]
A shorthand to specify if it's either the given type or an array of it
Type parameters​
Name |
---|
T |
Defined in​
Nil​
Ƭ Nil<T
>: T
| null
| undefined
Shorthand type for type being either itself, null or undefined
Type parameters​
Name |
---|
T |
Defined in​
SelectOptionLabel​
Ƭ SelectOptionLabel: LangString
| LangStringSimple
| string
The label of a SelectOption
Defined in​
lib/models/select-option.ts:34
Sorter​
Ƭ Sorter<T
>: (a
: T
, b
: T
) => number
Type parameters​
Name |
---|
T |
Type declaration​
â–¸ (a
, b
): number
Describes a function to be used as argument for Array<T>::sort
Parameters​
Name | Type |
---|---|
a | T |
b | T |
Returns​
number
Defined in​
UnknownObject​
Ƭ UnknownObject: Record
<string
| number
| symbol
, unknown
>
To be used instead of {}
or object
as type for whe just want objects as type.
Defined in​
lib/models/unknown-object.ts:4
Functions​
awaitForCompletable​
â–¸ Const
awaitForCompletable<T
>(resource
): Promise
<T
>
deprecated
use completableToPromise instead
Type parameters​
Name |
---|
T |
Parameters​
Name | Type |
---|---|
resource | Completable <T > |
Returns​
Promise
<T
>
Defined in​
lib/utils/completable-to-promise.ts:9
completableToObservable​
â–¸ completableToObservable<T
>(resource
): Observable
<T
>
Convert a Completable to an Observable
Type parameters​
Name |
---|
T |
Parameters​
Name | Type | Description |
---|---|---|
resource | Completable <T > | The Completable to be transformed into an Observable . |
Returns​
Observable
<T
>
resource as an Observable
Defined in​
lib/utils/completable-to-observable.ts:11
completableToPromise​
â–¸ completableToPromise<T
>(resource
): Promise
<T
>
Convert a Completable to a Promise
Type parameters​
Name |
---|
T |
Parameters​
Name | Type | Description |
---|---|---|
resource | Completable <T > | The Completable to be transformed into a Promise . For ease of use, if it is an Observable , it is piped with first() |
Returns​
Promise
<T
>
resource as a Promise
Defined in​
lib/utils/completable-to-promise.ts:18
createElasticQuery​
â–¸ createElasticQuery(): ElasticQuery
Create a basic structure for an ElasticQuery
deprecated
Returns​
Defined in​
lib/models/elastic-query.ts:53
czLabelToString​
â–¸ czLabelToString(label
, lang
, fallbackLangs?
): string
| undefined
Extract from a CzLabel the label in a corresponding lang
. If not
found, it will try to extract the label of one of the fallback languages.
It is to be noted that even if the label is a string[] with multiple values,
only the 0th element will be taken.
Parameters​
Name | Type | Default value | Description |
---|---|---|---|
label | Nil <CzLabel > | undefined | - |
lang | string | undefined | The preferred lang to get the label for |
fallbackLangs | string [] | [] | ordered list of fallback languages |
Returns​
string
| undefined
Defined in​
lib/utils/cz-label-to-string.ts:14
dateToDateString​
â–¸ dateToDateString(value
): string
Returns the given Date
as a string
in the YYYY-MM-dd format
Parameters​
Name | Type |
---|---|
value | Date |
Returns​
string
Defined in​
lib/utils/date-to-date-string.ts:4
debounceSync​
â–¸ debounceSync<T
>(): MonoTypeOperatorFunction
<T
>
rxjs operator to be used for debouncing the source in a synchronous way
Type parameters​
Name |
---|
T |
Returns​
MonoTypeOperatorFunction
<T
>
Defined in​
lib/operators/debounce-sync.ts:7
downloadBlob​
â–¸ downloadBlob(data
, fileName?
): void
Triggers a browser download of the given Blob
, and should be cross-browser
compatible (looking at you IE).
Parameters​
Name | Type |
---|---|
data | Blob |
fileName? | string |
Returns​
void
Defined in​
extractOneSourceFromElasticResponse​
â–¸ extractOneSourceFromElasticResponse<T
>(response
): T
Extract the first _source
of the first hits
of an {@link ElasticResponse}
Type parameters​
Name |
---|
T |
Parameters​
Name | Type | Description |
---|---|---|
response | ElasticSearchResponse <T > | The json returned by a _search elastic call |
Returns​
T
Defined in​
lib/utils/extract-one-source-from-elastic-response.ts:9
extractSourcesFromElasticResponse​
â–¸ extractSourcesFromElasticResponse<T
>(response
): T
[]
Aggregate all _source
in all hits
of an {@link ElasticResponse} in a single array
Type parameters​
Name |
---|
T |
Parameters​
Name | Type | Description |
---|---|---|
response | ElasticSearchResponse <T > | The json returned by a _search elastic call |
Returns​
T
[]
Defined in​
lib/utils/extract-sources-from-elastic-response.ts:8
getAllProperties​
â–¸ getAllProperties(obj
): string
[]
get all properties of the given object, and goes up the prototype chain. This is mostly useful for debugging purposes and javascript digging.
Parameters​
Name | Type |
---|---|
obj | Object |
Returns​
string
[]
Defined in​
lib/utils/get-all-properties.ts:5
getAllSelectOptions​
â–¸ getAllSelectOptions<T
>(options
): SelectOption
<T
>[]
getAllSelectOptions
spread options and sub options into one flat list of options @typedef SelectOption []
Type parameters​
Name |
---|
T |
Parameters​
Name | Type |
---|---|
options | (SelectOption <T > | SelectOptionGroup <T >)[] |
Returns​
SelectOption
<T
>[]
Defined in​
lib/utils/get-all-select-options.ts:6
getLangStringValue​
â–¸ getLangStringValue(langString
, lang
, fallbackLangs?
): string
| undefined
Extract from a LangString the label in a corresponding lang
. If not
found, it will try to extract the label of one of the fallback languages.
If even there nothing is found, it will fallback to the first label found.
It is to be noted that even if the label is a string[] with multiple values,
only the 0th element will be taken.
Parameters​
Name | Type | Default value | Description |
---|---|---|---|
langString | Nil <LangString | LangStringSimple > | undefined | The lang string from which we want to extract a label |
lang | string | undefined | The preferred lang to get the label for |
fallbackLangs | string [] | [] | ordered list of fallback languages |
Returns​
string
| undefined
Defined in​
lib/utils/get-lang-string-value.ts:15
groupSelectOptions​
â–¸ groupSelectOptions<T
>(options
): SelectOptionGroup
<T
>[]
Type parameters​
Name |
---|
T |
Parameters​
Name | Type |
---|---|
options | (SelectOption <T > | SelectOptionGroup <T >)[] |
Returns​
SelectOptionGroup
<T
>[]
Defined in​
lib/utils/group-select-options.ts:4
isSelectOption​
â–¸ isSelectOption<T
>(o
): o is SelectOption<T>
Type parameters​
Name |
---|
T |
Parameters​
Name | Type |
---|---|
o | SelectOption <T > | SelectOptionGroup <T > |
Returns​
o is SelectOption<T>
Defined in​
lib/utils/is-select-option.ts:3
manyToArray​
â–¸ manyToArray<T
>(x
): T
[]
Convert a Many to an array. It gives an empty array if the given value is nullish.
Type parameters​
Name |
---|
T |
Parameters​
Name | Type |
---|---|
x | Many <T > |
Returns​
T
[]
Defined in​
manyToOne​
â–¸ manyToOne<T
>(x
): T
Convert a Many to its base type, taking the 0th element of the array, if applicable.
Type parameters​
Name |
---|
T |
Parameters​
Name | Type |
---|---|
x | Many <T > |
Returns​
T
Defined in​
mapElasticSources​
â–¸ mapElasticSources<T
, U
>(response
, project
): ElasticSearchResponse
<U
>
Return a transformed {@link ElasticResponse} where all _source
are transformed using the given project
function
Type parameters​
Name |
---|
T |
U |
Parameters​
Name | Type | Description |
---|---|---|
response | ElasticSearchResponse <T > | The json returned by a _search elastic call |
project | (data : T ) => U | The projection function |
Returns​
Defined in​
lib/utils/map-elastic-sources.ts:9
notNil​
â–¸ notNil<T
>(o
): o is Exclude<T, undefined | null>
Checking that the argument is not Nil, so basically o != null
. Its
main usage is to be used in array filtering or rxjs stream filtering, like:
const myStringArray = ['a', undefined, null, 'b'].filter(notNil); // ['a', 'b']
from(['a', undefined, null, 'b']).pipe(filter(notNil)).subscribe(console.log); // logs: 'a' and 'b'
Type parameters​
Name |
---|
T |
Parameters​
Name | Type |
---|---|
o | T |
Returns​
o is Exclude<T, undefined | null>
Defined in​
orElse​
â–¸ orElse<T
, R
>(value
): OperatorFunction
<T
, R
>
rxjs operator to be used for defaulting to a given value if the stream passes a nullish value. For example:
from(['a', undefined, 'c']).pipe(orElse('b')).subscribe(console.log) // logs 'a', 'b', 'c'.
Type parameters​
Name |
---|
T |
R |
Parameters​
Name | Type |
---|---|
value | R |
Returns​
OperatorFunction
<T
, R
>
Defined in​
selectOptionMatchQuery​
â–¸ selectOptionMatchQuery<T
>(option
, query
): boolean
This will (naively) check that on the labels of the given option matches the query.
Type parameters​
Name |
---|
T |
Parameters​
Name | Type |
---|---|
option | SelectOption <T > |
query | Nil <string > |
Returns​
boolean
Defined in​
lib/utils/select-option-match-query.ts:7
strictEntries​
â–¸ strictEntries<T
>(o
): [keyof T
, T
[keyof T
]][]
Same as Object.entries
, but strongly typed
Type parameters​
Name |
---|
T |
Parameters​
Name | Type |
---|---|
o | T |
Returns​
[keyof T
, T
[keyof T
]][]
Defined in​
trackBySelectOption​
â–¸ trackBySelectOption<T
>(index
, option
): T
a TrackByFn to be used with an *ngFor
in case it is used on an array of SelectOption
Type parameters​
Name |
---|
T |
Parameters​
Name | Type |
---|---|
index | number |
option | SelectOption <T > |
Returns​
T