@tstdl/base 0.90.57 → 0.90.59
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +136 -116
- package/json-path/json-path.d.ts +11 -9
- package/json-path/json-path.js +9 -6
- package/jsx/render-to-string.d.ts +2 -0
- package/jsx/render-to-string.js +9 -3
- package/package.json +9 -9
- package/queue/mongo/queue.provider.d.ts +2 -4
- package/random/series.d.ts +1 -1
- package/schema/constraints/maximum.d.ts +1 -1
- package/schema/constraints/minimum-date.d.ts +1 -1
- package/schema/constraints/minimum.d.ts +1 -1
- package/schema/constraints/pattern.d.ts +1 -1
- package/schema/types/types.d.ts +2 -2
- package/search-index/elastic/query-builder/boolean-query-builder.d.ts +1 -4
- package/search-index/elastic/query-builder/boolean-query-builder.js +23 -23
- package/templates/renderers/jsx.template-renderer.d.ts +1 -1
- package/templates/renderers/jsx.template-renderer.js +3 -3
- package/theme/theme-service.d.ts +1 -1
- package/theme/theme-service.js +3 -2
- package/types.d.ts +26 -12
- package/utils/async-iterable-helpers/to-async-iterator.js +2 -2
- package/utils/async-iterator-iterable-iterator.js +3 -3
- package/utils/base64.js +1 -1
- package/utils/cryptography.d.ts +13 -13
- package/utils/cryptography.js +12 -12
- package/utils/date-time.js +1 -1
- package/utils/encoding.d.ts +6 -6
- package/utils/encoding.js +6 -6
- package/utils/enum.js +9 -15
- package/utils/equals.js +3 -2
- package/utils/format-error.d.ts +5 -5
- package/utils/format.js +7 -6
- package/utils/helpers.d.ts +9 -9
- package/utils/helpers.js +3 -3
- package/utils/object/decycle.d.ts +2 -2
- package/utils/object/decycle.js +8 -8
- package/utils/object/dereference.d.ts +4 -4
- package/utils/object/dereference.js +4 -4
- package/utils/object/forward-ref.js +2 -2
- package/utils/object/lazy-property.d.ts +9 -9
- package/utils/object/lazy-property.js +4 -3
- package/utils/object/merge.d.ts +1 -1
- package/utils/object/merge.js +3 -3
- package/utils/object/object.d.ts +2 -2
- package/utils/object/object.js +2 -2
- package/utils/object/property-name.d.ts +15 -15
- package/utils/object/property-name.js +12 -12
- package/utils/patch-worker.d.ts +3 -3
- package/utils/patterns.d.ts +2 -2
- package/utils/patterns.js +3 -3
- package/utils/periodic-reporter.d.ts +1 -1
- package/utils/periodic-sampler.d.ts +1 -1
- package/utils/periodic-sampler.js +7 -5
- package/utils/random.d.ts +2 -2
- package/utils/random.js +2 -2
- package/utils/reactive-value-to-signal.d.ts +1 -1
- package/utils/reactive-value-to-signal.js +1 -1
- package/utils/repl.js +1 -0
- package/utils/singleton.d.ts +5 -4
- package/utils/singleton.js +3 -3
- package/utils/stream/finalize-stream.d.ts +5 -5
- package/utils/stream/readable-stream-adapter.d.ts +1 -1
- package/utils/stream/readable-stream-adapter.js +2 -2
- package/utils/stream/readable-stream-from-promise.d.ts +1 -1
- package/utils/stream/slice.js +1 -1
- package/utils/stream/to-bytes-stream.js +4 -4
- package/utils/timing.d.ts +5 -5
- package/utils/timing.js +4 -4
- package/utils/type-guards.js +1 -1
- package/utils/type-of.d.ts +3 -2
- package/utils/type-of.js +1 -1
- package/utils/units.js +3 -2
- package/utils/url-builder.js +3 -3
- package/utils/value-or-provider.js +1 -1
- package/utils/z-base32.js +1 -3
- package/web-types.d.ts +1 -1
|
@@ -1,52 +1,52 @@
|
|
|
1
1
|
export class BoolQueryBuilder {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
#must;
|
|
3
|
+
#should;
|
|
4
|
+
#mustNot;
|
|
5
|
+
#filter;
|
|
6
6
|
get totalQueries() {
|
|
7
|
-
return this.
|
|
7
|
+
return this.#must.length + this.#should.length + this.#mustNot.length + this.#filter.length;
|
|
8
8
|
}
|
|
9
9
|
constructor() {
|
|
10
|
-
this
|
|
11
|
-
this
|
|
12
|
-
this
|
|
13
|
-
this
|
|
10
|
+
this.#must = [];
|
|
11
|
+
this.#should = [];
|
|
12
|
+
this.#mustNot = [];
|
|
13
|
+
this.#filter = [];
|
|
14
14
|
}
|
|
15
15
|
build() {
|
|
16
16
|
const queryObj = {
|
|
17
17
|
bool: {}
|
|
18
18
|
};
|
|
19
|
-
if (this.
|
|
20
|
-
queryObj.bool.must = this
|
|
19
|
+
if (this.#must.length > 0) {
|
|
20
|
+
queryObj.bool.must = this.#must;
|
|
21
21
|
}
|
|
22
|
-
if (this.
|
|
23
|
-
queryObj.bool.should = this
|
|
22
|
+
if (this.#should.length > 0) {
|
|
23
|
+
queryObj.bool.should = this.#should;
|
|
24
24
|
}
|
|
25
|
-
if (this.
|
|
26
|
-
queryObj.bool.must_not = this
|
|
25
|
+
if (this.#mustNot.length > 0) {
|
|
26
|
+
queryObj.bool.must_not = this.#mustNot;
|
|
27
27
|
}
|
|
28
|
-
if (this.
|
|
29
|
-
queryObj.bool.filter = this
|
|
28
|
+
if (this.#filter.length > 0) {
|
|
29
|
+
queryObj.bool.filter = this.#filter;
|
|
30
30
|
}
|
|
31
|
-
if (this.
|
|
32
|
-
return [...this
|
|
31
|
+
if (this.#mustNot.length == 0 && (this.#must.length + this.#should.length + this.#filter.length) == 1) {
|
|
32
|
+
return [...this.#must, ...this.#should, ...this.#filter][0];
|
|
33
33
|
}
|
|
34
34
|
return queryObj;
|
|
35
35
|
}
|
|
36
36
|
must(...queries) {
|
|
37
|
-
this.
|
|
37
|
+
this.#must.push(...queries);
|
|
38
38
|
return this;
|
|
39
39
|
}
|
|
40
40
|
should(...queries) {
|
|
41
|
-
this.
|
|
41
|
+
this.#should.push(...queries);
|
|
42
42
|
return this;
|
|
43
43
|
}
|
|
44
44
|
mustNot(...queries) {
|
|
45
|
-
this.
|
|
45
|
+
this.#mustNot.push(...queries);
|
|
46
46
|
return this;
|
|
47
47
|
}
|
|
48
48
|
filter(...queries) {
|
|
49
|
-
this.
|
|
49
|
+
this.#filter.push(...queries);
|
|
50
50
|
return this;
|
|
51
51
|
}
|
|
52
52
|
}
|
|
@@ -6,5 +6,5 @@ export type JsxTemplateRenderObject = TemplateRenderObject<'jsx', undefined, Jsx
|
|
|
6
6
|
export declare class JsxTemplateRenderer extends TemplateRenderer<'jsx', undefined> {
|
|
7
7
|
constructor();
|
|
8
8
|
canHandleType(type: string): boolean;
|
|
9
|
-
_render({ template }: JsxTemplateRenderObject, context: Record): TemplateRenderResult
|
|
9
|
+
_render({ template }: JsxTemplateRenderObject, context: Record): Promise<TemplateRenderResult>;
|
|
10
10
|
}
|
|
@@ -8,7 +8,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
10
|
import { Singleton } from '../../injector/decorators.js';
|
|
11
|
-
import {
|
|
11
|
+
import { renderJsxAsync } from '../../jsx/render-to-string.js';
|
|
12
12
|
import { TemplateRenderer } from '../template.renderer.js';
|
|
13
13
|
let JsxTemplateRenderer = class JsxTemplateRenderer extends TemplateRenderer {
|
|
14
14
|
constructor() {
|
|
@@ -17,8 +17,8 @@ let JsxTemplateRenderer = class JsxTemplateRenderer extends TemplateRenderer {
|
|
|
17
17
|
canHandleType(type) {
|
|
18
18
|
return (type == 'jsx');
|
|
19
19
|
}
|
|
20
|
-
_render({ template }, context) {
|
|
21
|
-
return
|
|
20
|
+
async _render({ template }, context) {
|
|
21
|
+
return renderJsxAsync(template, context);
|
|
22
22
|
}
|
|
23
23
|
};
|
|
24
24
|
JsxTemplateRenderer = __decorate([
|
package/theme/theme-service.d.ts
CHANGED
package/theme/theme-service.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-magic-numbers */
|
|
1
2
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
3
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
4
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -81,8 +82,8 @@ function _generateColorTones(base) {
|
|
|
81
82
|
function toColorTonesWithRgb(tones) {
|
|
82
83
|
return {
|
|
83
84
|
/* eslint-disable @typescript-eslint/naming-convention, quote-props */
|
|
84
|
-
base: tones.base,
|
|
85
|
-
baseRgb: getRgbString(tones.base),
|
|
85
|
+
'base': tones.base,
|
|
86
|
+
'baseRgb': getRgbString(tones.base),
|
|
86
87
|
'50': tones['50'],
|
|
87
88
|
'50Rgb': getRgbString(tones['50']),
|
|
88
89
|
'100': tones['100'],
|
package/types.d.ts
CHANGED
|
@@ -3,14 +3,14 @@ import type { CamelCase, Except } from 'type-fest';
|
|
|
3
3
|
import type { Signal } from './signals/api.js';
|
|
4
4
|
export type ObjectLiteral = {};
|
|
5
5
|
export type PrimitiveTypeMap = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
string: string;
|
|
7
|
+
number: number;
|
|
8
|
+
boolean: boolean;
|
|
9
|
+
bigint: bigint;
|
|
10
|
+
symbol: symbol;
|
|
11
|
+
object: object;
|
|
12
|
+
function: Function;
|
|
13
|
+
undefined: undefined;
|
|
14
14
|
};
|
|
15
15
|
export type PrimitiveTypeString<T extends PrimitiveTypeMap[keyof PrimitiveTypeMap] = PrimitiveTypeMap[keyof PrimitiveTypeMap]> = Simplify<keyof PickBy<PrimitiveTypeMap, T>>;
|
|
16
16
|
export type PrimitiveType<T extends keyof PrimitiveTypeMap = keyof PrimitiveTypeMap> = Simplify<PrimitiveTypeMap[T]>;
|
|
@@ -105,13 +105,13 @@ export type OmitNever<T extends Record> = {
|
|
|
105
105
|
};
|
|
106
106
|
export type SharedProperties<A, B, C = unknown, D = unknown, E = unknown, F = unknown, G = unknown, H = unknown, I = unknown, J = unknown> = OmitNever<Pick<A & B & C & D & E & F & G & H & I & J, keyof A & keyof B & keyof ReplaceIfUnknown<C, never> & keyof ReplaceIfUnknown<D, never> & keyof ReplaceIfUnknown<E, never> & keyof ReplaceIfUnknown<F, never> & keyof ReplaceIfUnknown<G, never> & keyof ReplaceIfUnknown<H, never> & keyof ReplaceIfUnknown<I, never> & keyof ReplaceIfUnknown<J, never>>>;
|
|
107
107
|
/**
|
|
108
|
-
*
|
|
108
|
+
* Omit properties from a type that extend from a specific type.
|
|
109
109
|
*/
|
|
110
110
|
export type OmitBy<T, V> = Omit<T, {
|
|
111
111
|
[K in keyof T]: V extends Extract<T[K], V> ? K : never;
|
|
112
112
|
}[keyof T]>;
|
|
113
113
|
/**
|
|
114
|
-
*
|
|
114
|
+
* Normalize properties of a type that allow `undefined` to make them optional.
|
|
115
115
|
*/
|
|
116
116
|
export type Optionalize<T extends object> = OmitBy<T, undefined> & Partial<PickBy<T, undefined>>;
|
|
117
117
|
export type SimplifiedOptionalize<T extends object> = SimplifyObject<Optionalize<T>>;
|
|
@@ -137,7 +137,7 @@ export type UndefinableObject<T extends Record> = {
|
|
|
137
137
|
[K in keyof T]: T[K] | undefined;
|
|
138
138
|
};
|
|
139
139
|
/**
|
|
140
|
-
*
|
|
140
|
+
* Pick properties from a type that extend from a specific type.
|
|
141
141
|
*/
|
|
142
142
|
export type PickBy<T, V> = Pick<T, {
|
|
143
143
|
[K in keyof T]: V extends Extract<T[K], V> ? K : never;
|
|
@@ -146,7 +146,7 @@ export type NonNullable<T> = T extends null ? never : T;
|
|
|
146
146
|
export type NonUndefinable<T> = T extends undefined ? never : T;
|
|
147
147
|
export type NonNullOrUndefinable<T> = T extends null | undefined ? never : T;
|
|
148
148
|
/**
|
|
149
|
-
*
|
|
149
|
+
* Makes optional properties required and removes null and undefined
|
|
150
150
|
*/
|
|
151
151
|
export type DeepNonNullable<T> = T extends Record ? {
|
|
152
152
|
[P in keyof T]-?: DeepNonNullable<T[P]>;
|
|
@@ -194,4 +194,18 @@ export type TypeFromPath<T extends Record, Path extends Paths<T> | string> = {
|
|
|
194
194
|
export type ConstructorParameterDecorator = (target: Object, propertyKey: undefined, parameterIndex: number) => void;
|
|
195
195
|
export type ReactiveValue<T> = T | Signal<T> | Observable<T>;
|
|
196
196
|
export type PascalCase<Value> = CamelCase<Value> extends string ? Capitalize<CamelCase<Value>> : CamelCase<Value>;
|
|
197
|
+
type PickOmitDeepSelection<T> = T extends (infer U)[] ? (boolean | PickOmitDeepSelection<U>) : T extends Record<any> ? (boolean | {
|
|
198
|
+
[P in keyof T]?: PickOmitDeepSelection<T[P]>;
|
|
199
|
+
}) : boolean;
|
|
200
|
+
export type PickDeepSelection<T> = PickOmitDeepSelection<T>;
|
|
201
|
+
export type OmitDeepSelection<T> = PickOmitDeepSelection<T>;
|
|
202
|
+
export type PickDeep<T, S extends PickDeepSelection<T>> = T extends Record<any> ? Simplify<{
|
|
203
|
+
[P in keyof S as S[P] extends (true | Record<any>) ? P : never]: S[P] extends true ? T[Extract<P, keyof T>] : T[Extract<P, keyof T>] extends (infer U)[] ? S[P] extends PickDeepSelection<U> ? PickDeep<U, S[P]>[] : never : S[P] extends Record<any> ? S[P] extends PickDeepSelection<T[Extract<P, keyof T>]> ? PickDeep<T[Extract<P, keyof T>], S[P]> : never : never;
|
|
204
|
+
}> : T;
|
|
205
|
+
export type OmitDeep<T, S extends OmitDeepSelection<T>> = T extends Record<any> ? Simplify<{
|
|
206
|
+
[P in keyof T as true extends S[Extract<P, keyof S>] ? never : P]: [
|
|
207
|
+
S[Extract<P, keyof S>]
|
|
208
|
+
] extends ([false] | [never]) ? T[P] : S[Extract<P, keyof S>] extends Record<any> ? T[P] extends (infer U)[] ? S[Extract<P, keyof S>] extends OmitDeepSelection<U> ? OmitDeep<U, S[Extract<P, keyof S>]>[] : never : S[Extract<P, keyof S>] extends OmitDeepSelection<T[P]> ? OmitDeep<T[P], S[Extract<P, keyof S>]> : never : never;
|
|
209
|
+
}> : T;
|
|
210
|
+
export type AnyFunction = Function;
|
|
197
211
|
export {};
|
|
@@ -21,12 +21,12 @@ export function iteratorToAsyncIterator(iterator) {
|
|
|
21
21
|
return iterator.next(...args);
|
|
22
22
|
}
|
|
23
23
|
};
|
|
24
|
-
if (isDefined(iterator.return)) {
|
|
24
|
+
if (isDefined(iterator.return)) {
|
|
25
25
|
asyncIterator.return = async function _return(value) {
|
|
26
26
|
return iterator.return(await value);
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
|
-
if (isDefined(iterator.throw)) {
|
|
29
|
+
if (isDefined(iterator.throw)) {
|
|
30
30
|
asyncIterator.throw = async function _throw(error) {
|
|
31
31
|
return iterator.throw(error);
|
|
32
32
|
};
|
|
@@ -10,17 +10,17 @@ export class AsyncIteratorIterableIterator {
|
|
|
10
10
|
return this.iterator.next(...args);
|
|
11
11
|
}
|
|
12
12
|
async return(value) {
|
|
13
|
-
assertDefined(this.iterator.return, 'underlying iterator has no return function defined');
|
|
13
|
+
assertDefined(this.iterator.return, 'underlying iterator has no return function defined');
|
|
14
14
|
return this.iterator.return(value);
|
|
15
15
|
}
|
|
16
16
|
async throw(error) {
|
|
17
|
-
assertDefined(this.iterator.throw, 'underlying iterator has no throw function defined');
|
|
17
|
+
assertDefined(this.iterator.throw, 'underlying iterator has no throw function defined');
|
|
18
18
|
return this.iterator.throw(error);
|
|
19
19
|
}
|
|
20
20
|
async *[Symbol.asyncIterator]() {
|
|
21
21
|
let finished = false;
|
|
22
22
|
try {
|
|
23
|
-
while (true) {
|
|
23
|
+
while (true) {
|
|
24
24
|
const result = await this.iterator.next();
|
|
25
25
|
if (result.done == true) {
|
|
26
26
|
finished = true;
|
package/utils/base64.js
CHANGED
package/utils/cryptography.d.ts
CHANGED
|
@@ -32,34 +32,34 @@ export interface DigestResult extends CryptionResult {
|
|
|
32
32
|
export interface SignResult extends CryptionResult {
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
35
|
-
*
|
|
35
|
+
* Encrypt data
|
|
36
36
|
* @param algorithm algorithm as supported by Web Crypto API
|
|
37
37
|
* @param key key
|
|
38
38
|
* @param data data to encrypt. Encodes string to utf8
|
|
39
39
|
*/
|
|
40
40
|
export declare function encrypt(algorithm: CryptionAlgorithm, key: CryptoKey, data: BinaryData | string): CryptionResult;
|
|
41
41
|
/**
|
|
42
|
-
*
|
|
42
|
+
* Decrypt data
|
|
43
43
|
* @param algorithm algorithm as supported by Web Crypto API
|
|
44
44
|
* @param key key
|
|
45
45
|
* @param data data to decrypt
|
|
46
46
|
*/
|
|
47
47
|
export declare function decrypt(algorithm: CryptionAlgorithm, key: CryptoKey, bytes: BinaryData): DecryptionResult;
|
|
48
48
|
/**
|
|
49
|
-
*
|
|
49
|
+
* Hashes data
|
|
50
50
|
* @param algorithm algorithm as supported by Web Crypto API
|
|
51
51
|
* @param data data to encrypt. Encodes string to utf8
|
|
52
52
|
*/
|
|
53
53
|
export declare function digest(algorithm: HashAlgorithmIdentifier, data: BinaryData | string): DigestResult;
|
|
54
54
|
/**
|
|
55
|
-
*
|
|
55
|
+
* Signs data
|
|
56
56
|
* @param algorithm algorithm as supported by Web Crypto API
|
|
57
57
|
* @param key key
|
|
58
58
|
* @param data data to sign
|
|
59
59
|
*/
|
|
60
60
|
export declare function sign(algorithm: SignAlgorithm, key: CryptoKey, data: BinaryData | string): SignResult;
|
|
61
61
|
/**
|
|
62
|
-
*
|
|
62
|
+
* Verifies data
|
|
63
63
|
* @param algorithm algorithm as supported by Web Crypto API
|
|
64
64
|
* @param key key
|
|
65
65
|
* @param signature signature
|
|
@@ -67,14 +67,14 @@ export declare function sign(algorithm: SignAlgorithm, key: CryptoKey, data: Bin
|
|
|
67
67
|
*/
|
|
68
68
|
export declare function verify(algorithm: SignAlgorithm, key: CryptoKey, signature: BinaryData | string, data: BinaryData | string): Promise<boolean>;
|
|
69
69
|
/**
|
|
70
|
-
*
|
|
70
|
+
* Imports a HMAC CryptoKey
|
|
71
71
|
* @param algorithm hash algorithm
|
|
72
72
|
* @param key JWK or binary key
|
|
73
73
|
* @param extractable whether the key can be used for exportKey
|
|
74
74
|
*/
|
|
75
75
|
export declare function importHmacKey(algorithm: HashAlgorithmIdentifier, key: Key | string, extractable?: boolean): Promise<CryptoKey>;
|
|
76
76
|
/**
|
|
77
|
-
*
|
|
77
|
+
* Imports a CryptoKey for symmetric encryption
|
|
78
78
|
* @param algorithm symmetric algorithm
|
|
79
79
|
* @param length key length
|
|
80
80
|
* @param key JWK or binary key
|
|
@@ -82,39 +82,39 @@ export declare function importHmacKey(algorithm: HashAlgorithmIdentifier, key: K
|
|
|
82
82
|
*/
|
|
83
83
|
export declare function importSymmetricKey(algorithm: SymmetricAlgorithm, length: 128 | 192 | 256, key: Key | string, extractable?: boolean): Promise<CryptoKey>;
|
|
84
84
|
/**
|
|
85
|
-
*
|
|
85
|
+
* Imports an ECDSA CryptoKey
|
|
86
86
|
* @param curve ECDSA curve
|
|
87
87
|
* @param key JWK or DER encoded key
|
|
88
88
|
* @param extractable whether the key can be used for exportKey
|
|
89
89
|
*/
|
|
90
90
|
export declare function importEcdsaKey(curve: EcdsaCurve, key: Key | string, extractable?: boolean): Promise<CryptoKey>;
|
|
91
91
|
/**
|
|
92
|
-
*
|
|
92
|
+
* Import a pbkdf2 CryptoKey
|
|
93
93
|
* @param key binary key
|
|
94
94
|
* @param extractable whether the key can be used for exportKey
|
|
95
95
|
*/
|
|
96
96
|
export declare function importPbkdf2Key(key: BinaryData | string, extractable?: boolean): Promise<CryptoKey>;
|
|
97
97
|
/**
|
|
98
|
-
*
|
|
98
|
+
* Generates a new ECDSA CryptoKeyPair
|
|
99
99
|
* @param curve ECDSA cruve to use
|
|
100
100
|
* @param extractable whether the key can be used for exportKey
|
|
101
101
|
* @param usages whether to generate a key for signing, verifiying or both. Defaults to both
|
|
102
102
|
*/
|
|
103
103
|
export declare function generateEcdsaKey(curve: EcdsaCurve, extractable?: boolean, usages?: TypedExtract<KeyUsage, 'sign' | 'verify'>[]): Promise<CryptoKeyPair>;
|
|
104
104
|
/**
|
|
105
|
-
*
|
|
105
|
+
* Generates a pbkdf2 CryptoKey
|
|
106
106
|
* @param extractable whether the key can be used for exportKey
|
|
107
107
|
*/
|
|
108
108
|
export declare function generatePbkdf2Key(extractable?: boolean): Promise<CryptoKey>;
|
|
109
109
|
/**
|
|
110
|
-
*
|
|
110
|
+
* Derive byte array from key
|
|
111
111
|
* @param length length in bytes
|
|
112
112
|
* @param algorithm algorithm to derive with
|
|
113
113
|
* @param baseKey key to derive from
|
|
114
114
|
*/
|
|
115
115
|
export declare function deriveBytes(algorithm: DeriveAlgorithm, baseKey: CryptoKey, length: number): Promise<Uint8Array>;
|
|
116
116
|
/**
|
|
117
|
-
*
|
|
117
|
+
* Derive multiply byte arrays from key
|
|
118
118
|
* @param algorithm algorithm to derive with
|
|
119
119
|
* @param baseKey key to derive from
|
|
120
120
|
* @param length length of each Uint8Array in bytes, if single number is provided, it is used for every array
|
package/utils/cryptography.js
CHANGED
|
@@ -6,7 +6,7 @@ import { isArray, isDefined, isString } from './type-guards.js';
|
|
|
6
6
|
import { zBase32Encode } from './z-base32.js';
|
|
7
7
|
const subtle = globalThis.crypto.subtle;
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* Encrypt data
|
|
10
10
|
* @param algorithm algorithm as supported by Web Crypto API
|
|
11
11
|
* @param key key
|
|
12
12
|
* @param data data to encrypt. Encodes string to utf8
|
|
@@ -23,7 +23,7 @@ export function encrypt(algorithm, key, data) {
|
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
|
-
*
|
|
26
|
+
* Decrypt data
|
|
27
27
|
* @param algorithm algorithm as supported by Web Crypto API
|
|
28
28
|
* @param key key
|
|
29
29
|
* @param data data to decrypt
|
|
@@ -40,7 +40,7 @@ export function decrypt(algorithm, key, bytes) {
|
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
42
|
/**
|
|
43
|
-
*
|
|
43
|
+
* Hashes data
|
|
44
44
|
* @param algorithm algorithm as supported by Web Crypto API
|
|
45
45
|
* @param data data to encrypt. Encodes string to utf8
|
|
46
46
|
*/
|
|
@@ -57,7 +57,7 @@ export function digest(algorithm, data) {
|
|
|
57
57
|
return result;
|
|
58
58
|
}
|
|
59
59
|
/**
|
|
60
|
-
*
|
|
60
|
+
* Signs data
|
|
61
61
|
* @param algorithm algorithm as supported by Web Crypto API
|
|
62
62
|
* @param key key
|
|
63
63
|
* @param data data to sign
|
|
@@ -75,7 +75,7 @@ export function sign(algorithm, key, data) {
|
|
|
75
75
|
return result;
|
|
76
76
|
}
|
|
77
77
|
/**
|
|
78
|
-
*
|
|
78
|
+
* Verifies data
|
|
79
79
|
* @param algorithm algorithm as supported by Web Crypto API
|
|
80
80
|
* @param key key
|
|
81
81
|
* @param signature signature
|
|
@@ -87,7 +87,7 @@ export async function verify(algorithm, key, signature, data) {
|
|
|
87
87
|
return subtle.verify(algorithm, key, signatureBytes, dataBytes);
|
|
88
88
|
}
|
|
89
89
|
/**
|
|
90
|
-
*
|
|
90
|
+
* Imports a HMAC CryptoKey
|
|
91
91
|
* @param algorithm hash algorithm
|
|
92
92
|
* @param key JWK or binary key
|
|
93
93
|
* @param extractable whether the key can be used for exportKey
|
|
@@ -100,7 +100,7 @@ export async function importHmacKey(algorithm, key, extractable = false) {
|
|
|
100
100
|
return subtle.importKey('jwk', binaryKey, { name: 'HMAC', hash: algorithm }, extractable, ['sign', 'verify']);
|
|
101
101
|
}
|
|
102
102
|
/**
|
|
103
|
-
*
|
|
103
|
+
* Imports a CryptoKey for symmetric encryption
|
|
104
104
|
* @param algorithm symmetric algorithm
|
|
105
105
|
* @param length key length
|
|
106
106
|
* @param key JWK or binary key
|
|
@@ -114,7 +114,7 @@ export async function importSymmetricKey(algorithm, length, key, extractable = f
|
|
|
114
114
|
return subtle.importKey('jwk', binaryKey, { name: algorithm, length }, extractable, ['encrypt', 'decrypt']);
|
|
115
115
|
}
|
|
116
116
|
/**
|
|
117
|
-
*
|
|
117
|
+
* Imports an ECDSA CryptoKey
|
|
118
118
|
* @param curve ECDSA curve
|
|
119
119
|
* @param key JWK or DER encoded key
|
|
120
120
|
* @param extractable whether the key can be used for exportKey
|
|
@@ -127,7 +127,7 @@ export async function importEcdsaKey(curve, key, extractable = false) {
|
|
|
127
127
|
return subtle.importKey('jwk', binaryKey, { name: 'ECDSA', namedCurve: curve }, extractable, ['verify']);
|
|
128
128
|
}
|
|
129
129
|
/**
|
|
130
|
-
*
|
|
130
|
+
* Import a pbkdf2 CryptoKey
|
|
131
131
|
* @param key binary key
|
|
132
132
|
* @param extractable whether the key can be used for exportKey
|
|
133
133
|
*/
|
|
@@ -136,7 +136,7 @@ export async function importPbkdf2Key(key, extractable = false) {
|
|
|
136
136
|
return globalThis.crypto.subtle.importKey('raw', binaryKey, { name: 'PBKDF2' }, extractable, ['deriveKey', 'deriveBits']);
|
|
137
137
|
}
|
|
138
138
|
/**
|
|
139
|
-
*
|
|
139
|
+
* Generates a new ECDSA CryptoKeyPair
|
|
140
140
|
* @param curve ECDSA cruve to use
|
|
141
141
|
* @param extractable whether the key can be used for exportKey
|
|
142
142
|
* @param usages whether to generate a key for signing, verifiying or both. Defaults to both
|
|
@@ -145,7 +145,7 @@ export async function generateEcdsaKey(curve, extractable = false, usages = ['si
|
|
|
145
145
|
return subtle.generateKey({ name: 'ECDSA', namedCurve: curve }, extractable, usages);
|
|
146
146
|
}
|
|
147
147
|
/**
|
|
148
|
-
*
|
|
148
|
+
* Generates a pbkdf2 CryptoKey
|
|
149
149
|
* @param extractable whether the key can be used for exportKey
|
|
150
150
|
*/
|
|
151
151
|
export async function generatePbkdf2Key(extractable = false) {
|
|
@@ -153,7 +153,7 @@ export async function generatePbkdf2Key(extractable = false) {
|
|
|
153
153
|
return importPbkdf2Key(key, extractable);
|
|
154
154
|
}
|
|
155
155
|
/**
|
|
156
|
-
*
|
|
156
|
+
* Derive byte array from key
|
|
157
157
|
* @param length length in bytes
|
|
158
158
|
* @param algorithm algorithm to derive with
|
|
159
159
|
* @param baseKey key to derive from
|
package/utils/date-time.js
CHANGED
|
@@ -100,7 +100,7 @@ export function dateTimeToTime(dateTime) {
|
|
|
100
100
|
if (interval.isValid) {
|
|
101
101
|
return interval.count('milliseconds');
|
|
102
102
|
}
|
|
103
|
-
throw new Error(
|
|
103
|
+
throw new Error(`Invalid DateTime: ${interval.invalidExplanation}`);
|
|
104
104
|
}
|
|
105
105
|
export function numericDateTimeToDateTime({ date, time }, zone) {
|
|
106
106
|
return numericDateToDateTime(date, undefined, { zone }).set({ millisecond: time });
|
package/utils/encoding.d.ts
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
import type { BinaryData } from '../types.js';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Encodes text to utf8
|
|
4
4
|
* @param text text to encode
|
|
5
5
|
* @returns utf8 encoded text
|
|
6
6
|
*/
|
|
7
7
|
export declare function encodeUtf8(text: string): Uint8Array;
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* Encodes text stream to utf8 bytes stream
|
|
10
10
|
*/
|
|
11
11
|
export declare function encodeUtf8Stream(): TransformStream<string, Uint8Array>;
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* Decodes buffer to string
|
|
14
14
|
* @param buffer buffer to decode
|
|
15
15
|
* @param encoding encoding, defaults to utf8
|
|
16
16
|
* @returns decoded string
|
|
17
17
|
*/
|
|
18
18
|
export declare function decodeText(buffer: BinaryData, encoding?: string): string;
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
20
|
+
* Transforms binary stream to string stream
|
|
21
21
|
* @param encoding encoding, defaults to utf8
|
|
22
22
|
* @returns stream of decoded string
|
|
23
23
|
*/
|
|
24
24
|
export declare function decodeTextStream(encoding?: string): TransformStream<BinaryData, string>;
|
|
25
25
|
/**
|
|
26
|
-
*
|
|
26
|
+
* Encodes buffer to hex
|
|
27
27
|
* @param buffer buffer to encode
|
|
28
28
|
* @returns hex encoded string
|
|
29
29
|
*/
|
|
30
30
|
export declare function encodeHex(buffer: BinaryData): string;
|
|
31
31
|
/**
|
|
32
|
-
*
|
|
32
|
+
* Decodes hex string to buffer
|
|
33
33
|
* @param hex hex string to decode
|
|
34
34
|
* @returns decoded buffer
|
|
35
35
|
*/
|
package/utils/encoding.js
CHANGED
|
@@ -5,7 +5,7 @@ import { isUndefined } from './type-guards.js';
|
|
|
5
5
|
const byteToHex = createArray(2 ** 8, (i) => i).map((value) => value.toString(16).padStart(2, '0'));
|
|
6
6
|
const hexToByte = new Map(byteToHex.map((hex, value) => [hex, value]));
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* Encodes text to utf8
|
|
9
9
|
* @param text text to encode
|
|
10
10
|
* @returns utf8 encoded text
|
|
11
11
|
*/
|
|
@@ -14,13 +14,13 @@ export function encodeUtf8(text) {
|
|
|
14
14
|
return encoder.encode(text);
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
|
-
*
|
|
17
|
+
* Encodes text stream to utf8 bytes stream
|
|
18
18
|
*/
|
|
19
19
|
export function encodeUtf8Stream() {
|
|
20
20
|
return new TextEncoderStream();
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
23
|
+
* Decodes buffer to string
|
|
24
24
|
* @param buffer buffer to decode
|
|
25
25
|
* @param encoding encoding, defaults to utf8
|
|
26
26
|
* @returns decoded string
|
|
@@ -30,7 +30,7 @@ export function decodeText(buffer, encoding) {
|
|
|
30
30
|
return decoder.decode(buffer);
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
33
|
-
*
|
|
33
|
+
* Transforms binary stream to string stream
|
|
34
34
|
* @param encoding encoding, defaults to utf8
|
|
35
35
|
* @returns stream of decoded string
|
|
36
36
|
*/
|
|
@@ -38,7 +38,7 @@ export function decodeTextStream(encoding) {
|
|
|
38
38
|
return new TextDecoderStream(encoding, { fatal: true });
|
|
39
39
|
}
|
|
40
40
|
/**
|
|
41
|
-
*
|
|
41
|
+
* Encodes buffer to hex
|
|
42
42
|
* @param buffer buffer to encode
|
|
43
43
|
* @returns hex encoded string
|
|
44
44
|
*/
|
|
@@ -52,7 +52,7 @@ export function encodeHex(buffer) {
|
|
|
52
52
|
return result;
|
|
53
53
|
}
|
|
54
54
|
/**
|
|
55
|
-
*
|
|
55
|
+
* Decodes hex string to buffer
|
|
56
56
|
* @param hex hex string to decode
|
|
57
57
|
* @returns decoded buffer
|
|
58
58
|
*/
|
package/utils/enum.js
CHANGED
|
@@ -2,9 +2,15 @@ import { randomItem } from './array/array.js';
|
|
|
2
2
|
import { memoizeSingle } from './function/memoize.js';
|
|
3
3
|
import { objectEntries } from './object/object.js';
|
|
4
4
|
import { isNumber } from './type-guards.js';
|
|
5
|
-
const memoizedEnumEntries = memoizeSingle(
|
|
6
|
-
const memoizedEnumKeys = memoizeSingle(
|
|
7
|
-
const
|
|
5
|
+
const memoizedEnumEntries = memoizeSingle((enumeration) => objectEntries(enumeration).filter((entry) => Number.isNaN(Number(entry[0]))), { weak: true });
|
|
6
|
+
const memoizedEnumKeys = memoizeSingle((enumeration) => {
|
|
7
|
+
const entries = enumEntries(enumeration);
|
|
8
|
+
return entries.map((entry) => entry[0]);
|
|
9
|
+
}, { weak: true });
|
|
10
|
+
const memoizedEnumValues = memoizeSingle((enumeration) => {
|
|
11
|
+
const entries = enumEntries(enumeration);
|
|
12
|
+
return entries.map((entry) => entry[1]);
|
|
13
|
+
}, { weak: true });
|
|
8
14
|
export function enumValueName(enumeration, value) {
|
|
9
15
|
return isNumber(value) ? enumeration[value]?.toString() ?? value.toString() : value;
|
|
10
16
|
}
|
|
@@ -20,15 +26,3 @@ export function enumValues(enumeration) {
|
|
|
20
26
|
export function randomEnumValue(enumeration) {
|
|
21
27
|
return randomItem(enumValues(enumeration));
|
|
22
28
|
}
|
|
23
|
-
function _enumEntries(enumeration) {
|
|
24
|
-
return objectEntries(enumeration)
|
|
25
|
-
.filter((entry) => Number.isNaN(Number(entry[0])));
|
|
26
|
-
}
|
|
27
|
-
function _enumKeys(enumeration) {
|
|
28
|
-
const entries = enumEntries(enumeration);
|
|
29
|
-
return entries.map((entry) => entry[0]);
|
|
30
|
-
}
|
|
31
|
-
function _enumValues(enumeration) {
|
|
32
|
-
const entries = enumEntries(enumeration);
|
|
33
|
-
return entries.map((entry) => entry[1]);
|
|
34
|
-
}
|
package/utils/equals.js
CHANGED
|
@@ -47,7 +47,7 @@ export function equals(a, b, options = {}, visitedNodes = new Set()) {
|
|
|
47
47
|
return (options.deep == true)
|
|
48
48
|
? a.toString() == b.toString()
|
|
49
49
|
: false;
|
|
50
|
-
case 'object':
|
|
50
|
+
case 'object': {
|
|
51
51
|
if (isNull(a) || isNull(b)) { // hasn't passed equals check at top, so one must be a true object
|
|
52
52
|
return false;
|
|
53
53
|
}
|
|
@@ -71,13 +71,14 @@ export function equals(a, b, options = {}, visitedNodes = new Set()) {
|
|
|
71
71
|
if (Equals.symbol in b) {
|
|
72
72
|
return b[Equals.symbol](a);
|
|
73
73
|
}
|
|
74
|
-
if ((aPrototype != Object.prototype) && isNotNull(aPrototype)) { //
|
|
74
|
+
if ((aPrototype != Object.prototype) && isNotNull(aPrototype)) { // Checking a is enough, because b must have equal prototype (checked above)
|
|
75
75
|
throw new Error('Equals only supports literal objects, arrays, primitives and Equals interface implementations.');
|
|
76
76
|
}
|
|
77
77
|
if (options.deep == false) {
|
|
78
78
|
return false;
|
|
79
79
|
}
|
|
80
80
|
return objectEquals(a, b, options, visitedNodes);
|
|
81
|
+
}
|
|
81
82
|
default:
|
|
82
83
|
return a === b;
|
|
83
84
|
}
|
package/utils/format-error.d.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
import type { UndefinableJson } from '../types.js';
|
|
2
2
|
export type FormatErrorOptions = {
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Include error name in message
|
|
5
5
|
*/
|
|
6
6
|
includeName?: boolean;
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* Include all error properties beside name and message
|
|
9
9
|
*/
|
|
10
10
|
includeRest?: boolean | 'if-no-extra-info';
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* Include extraInfo from errors implementing {@link ErrorExtraInfo}
|
|
13
13
|
*/
|
|
14
14
|
includeExtraInfo?: boolean;
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
16
|
+
* Include stack trace
|
|
17
17
|
*/
|
|
18
18
|
includeStack?: boolean;
|
|
19
19
|
};
|
|
20
20
|
export interface ErrorExtraInfo {
|
|
21
|
-
/**
|
|
21
|
+
/** Format extra data (without message and stack) as JSON */
|
|
22
22
|
getExtraInfo(): UndefinableJson | undefined;
|
|
23
23
|
}
|
|
24
24
|
export declare function formatError(error: any, options?: FormatErrorOptions): string;
|