@twin.org/core 0.0.1-next.9 → 0.0.2-next.3
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/dist/cjs/index.cjs +1574 -833
- package/dist/esm/index.mjs +1571 -834
- package/dist/types/errors/baseError.d.ts +8 -1
- package/dist/types/factories/factory.d.ts +20 -1
- package/dist/types/helpers/arrayHelper.d.ts +13 -0
- package/dist/types/helpers/envHelper.d.ts +16 -0
- package/dist/types/helpers/errorHelper.d.ts +2 -1
- package/dist/types/helpers/jsonHelper.d.ts +30 -0
- package/dist/types/helpers/objectHelper.d.ts +25 -0
- package/dist/types/helpers/uint8ArrayHelper.d.ts +11 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/models/IComponent.d.ts +12 -3
- package/dist/types/models/II18nShared.d.ts +29 -0
- package/dist/types/models/coerceType.d.ts +49 -0
- package/dist/types/models/compressionType.d.ts +1 -1
- package/dist/types/models/objectOrArray.d.ts +4 -0
- package/dist/types/utils/asyncCache.d.ts +10 -1
- package/dist/types/utils/coerce.d.ts +22 -0
- package/dist/types/utils/guards.d.ts +35 -0
- package/dist/types/utils/is.d.ts +12 -0
- package/dist/types/utils/sharedStore.d.ts +23 -0
- package/dist/types/utils/validation.d.ts +2 -0
- package/docs/changelog.md +323 -1
- package/docs/reference/classes/AlreadyExistsError.md +103 -27
- package/docs/reference/classes/ArrayHelper.md +71 -5
- package/docs/reference/classes/AsyncCache.md +75 -13
- package/docs/reference/classes/Base32.md +9 -5
- package/docs/reference/classes/Base58.md +9 -5
- package/docs/reference/classes/Base64.md +12 -6
- package/docs/reference/classes/Base64Url.md +9 -5
- package/docs/reference/classes/BaseError.md +101 -29
- package/docs/reference/classes/BitString.md +23 -11
- package/docs/reference/classes/Coerce.md +110 -12
- package/docs/reference/classes/Compression.md +19 -11
- package/docs/reference/classes/ConflictError.md +106 -28
- package/docs/reference/classes/Converter.md +72 -28
- package/docs/reference/classes/EnvHelper.md +45 -0
- package/docs/reference/classes/ErrorHelper.md +19 -7
- package/docs/reference/classes/Factory.md +95 -17
- package/docs/reference/classes/FilenameHelper.md +6 -4
- package/docs/reference/classes/GeneralError.md +101 -27
- package/docs/reference/classes/GuardError.md +106 -28
- package/docs/reference/classes/Guards.md +398 -80
- package/docs/reference/classes/HexHelper.md +18 -8
- package/docs/reference/classes/I18n.md +46 -20
- package/docs/reference/classes/Is.md +179 -51
- package/docs/reference/classes/JsonHelper.md +146 -10
- package/docs/reference/classes/NotFoundError.md +103 -27
- package/docs/reference/classes/NotImplementedError.md +97 -25
- package/docs/reference/classes/NotSupportedError.md +100 -26
- package/docs/reference/classes/ObjectHelper.md +197 -39
- package/docs/reference/classes/RandomHelper.md +6 -4
- package/docs/reference/classes/SharedStore.md +94 -0
- package/docs/reference/classes/StringHelper.md +54 -20
- package/docs/reference/classes/Uint8ArrayHelper.md +35 -0
- package/docs/reference/classes/UnauthorizedError.md +100 -26
- package/docs/reference/classes/UnprocessableError.md +101 -27
- package/docs/reference/classes/Url.md +37 -17
- package/docs/reference/classes/Urn.md +63 -27
- package/docs/reference/classes/Validation.md +349 -135
- package/docs/reference/classes/ValidationError.md +100 -26
- package/docs/reference/index.md +7 -0
- package/docs/reference/interfaces/IComponent.md +30 -8
- package/docs/reference/interfaces/IError.md +2 -2
- package/docs/reference/interfaces/II18nShared.md +47 -0
- package/docs/reference/interfaces/IKeyValue.md +3 -1
- package/docs/reference/interfaces/ILabelledValue.md +3 -1
- package/docs/reference/interfaces/ILocaleDictionary.md +1 -1
- package/docs/reference/interfaces/IPatchOperation.md +1 -1
- package/docs/reference/interfaces/IValidationFailure.md +1 -1
- package/docs/reference/type-aliases/CoerceType.md +5 -0
- package/docs/reference/type-aliases/CompressionType.md +1 -1
- package/docs/reference/type-aliases/ObjectOrArray.md +11 -0
- package/docs/reference/variables/CoerceType.md +67 -0
- package/docs/reference/variables/CompressionType.md +1 -1
- package/locales/en.json +14 -1
- package/package.json +7 -7
|
@@ -95,9 +95,16 @@ export declare class BaseError extends Error implements IError {
|
|
|
95
95
|
* @returns True if the error has the name.
|
|
96
96
|
*/
|
|
97
97
|
static someErrorCode(error: unknown, code: string | RegExp): error is BaseError;
|
|
98
|
+
/**
|
|
99
|
+
* Is the error empty.
|
|
100
|
+
* @param err The error to check for being empty.
|
|
101
|
+
* @returns True if the error is empty.
|
|
102
|
+
*/
|
|
103
|
+
static isEmpty(err: IError): boolean;
|
|
98
104
|
/**
|
|
99
105
|
* Serialize the error to the error model.
|
|
106
|
+
* @param includeStackTrace Whether to include the error stack in the model, defaults to false.
|
|
100
107
|
* @returns The error model.
|
|
101
108
|
*/
|
|
102
|
-
toJsonObject(): IError;
|
|
109
|
+
toJsonObject(includeStackTrace?: boolean): IError;
|
|
103
110
|
}
|
|
@@ -10,6 +10,21 @@ export declare class Factory<T> {
|
|
|
10
10
|
* @returns The factory instance.
|
|
11
11
|
*/
|
|
12
12
|
static createFactory<U>(typeName: string, autoInstance?: boolean, matcher?: (names: string[], name: string) => string | undefined): Factory<U>;
|
|
13
|
+
/**
|
|
14
|
+
* Get all the factories.
|
|
15
|
+
* @returns All the factories.
|
|
16
|
+
*/
|
|
17
|
+
static getFactories(): {
|
|
18
|
+
[typeName: string]: Factory<unknown>;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Reset all the factories, which removes any created instances, but not the registrations.
|
|
22
|
+
*/
|
|
23
|
+
static resetFactories(): void;
|
|
24
|
+
/**
|
|
25
|
+
* Clear all the factories, which removes anything registered with the factories.
|
|
26
|
+
*/
|
|
27
|
+
static clearFactories(): void;
|
|
13
28
|
/**
|
|
14
29
|
* Register a new generator.
|
|
15
30
|
* @param name The name of the generator.
|
|
@@ -38,9 +53,13 @@ export declare class Factory<T> {
|
|
|
38
53
|
*/
|
|
39
54
|
getIfExists<U extends T>(name: string): U | undefined;
|
|
40
55
|
/**
|
|
41
|
-
*
|
|
56
|
+
* Remove all the instances and leave the generators intact.
|
|
42
57
|
*/
|
|
43
58
|
reset(): void;
|
|
59
|
+
/**
|
|
60
|
+
* Remove all the instances and the generators.
|
|
61
|
+
*/
|
|
62
|
+
clear(): void;
|
|
44
63
|
/**
|
|
45
64
|
* Get all the instances as a map.
|
|
46
65
|
* @returns The instances as a map.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ObjectOrArray } from "../models/objectOrArray";
|
|
1
2
|
/**
|
|
2
3
|
* Class to help with arrays.
|
|
3
4
|
*/
|
|
@@ -9,4 +10,16 @@ export declare class ArrayHelper {
|
|
|
9
10
|
* @returns True if both arrays are empty of have the same values.
|
|
10
11
|
*/
|
|
11
12
|
static matches(arr1: unknown, arr2: unknown): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Convert an object or array to an array.
|
|
15
|
+
* @param value The object or array to convert.
|
|
16
|
+
* @returns The array.
|
|
17
|
+
*/
|
|
18
|
+
static fromObjectOrArray<T = unknown>(value: undefined): undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Convert an object or array to an array.
|
|
21
|
+
* @param value The object or array to convert.
|
|
22
|
+
* @returns The array.
|
|
23
|
+
*/
|
|
24
|
+
static fromObjectOrArray<T = unknown>(value: ObjectOrArray<T>): T[];
|
|
12
25
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment variable helper.
|
|
3
|
+
*/
|
|
4
|
+
export declare class EnvHelper {
|
|
5
|
+
/**
|
|
6
|
+
* Get the environment variable as an object with camel cased names.
|
|
7
|
+
* @param envVars The environment variables.
|
|
8
|
+
* @param prefix The prefix of the environment variables, if not provided gets all.
|
|
9
|
+
* @returns The object with camel cased names.
|
|
10
|
+
*/
|
|
11
|
+
static envToJson<T = {
|
|
12
|
+
[id: string]: string;
|
|
13
|
+
}>(envVars: {
|
|
14
|
+
[id: string]: string | undefined;
|
|
15
|
+
}, prefix?: string): T;
|
|
16
|
+
}
|
|
@@ -6,9 +6,10 @@ export declare class ErrorHelper {
|
|
|
6
6
|
/**
|
|
7
7
|
* Format Errors and returns just their messages.
|
|
8
8
|
* @param error The error to format.
|
|
9
|
+
* @param includeDetails Whether to include error details, defaults to false.
|
|
9
10
|
* @returns The error formatted including any inner errors.
|
|
10
11
|
*/
|
|
11
|
-
static formatErrors(error: unknown): string[];
|
|
12
|
+
static formatErrors(error: unknown, includeDetails?: boolean): string[];
|
|
12
13
|
/**
|
|
13
14
|
* Localize the content of an error and any inner errors.
|
|
14
15
|
* @param error The error to format.
|
|
@@ -24,6 +24,36 @@ export declare class JsonHelper {
|
|
|
24
24
|
* @param object The object to patch.
|
|
25
25
|
* @param patches The second object.
|
|
26
26
|
* @returns The updated object.
|
|
27
|
+
* @throws GeneralError if the patch fails.
|
|
27
28
|
*/
|
|
28
29
|
static patch<T = unknown>(object: T, patches: IPatchOperation[]): T;
|
|
30
|
+
/**
|
|
31
|
+
* Stringify the JSON with support for extended data types date/bigint/uint8array.
|
|
32
|
+
* @param object The object to stringify.
|
|
33
|
+
* @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.
|
|
34
|
+
* @returns The stringified object.
|
|
35
|
+
*/
|
|
36
|
+
static stringifyEx(object: any, space?: string | number): string;
|
|
37
|
+
/**
|
|
38
|
+
* Parse the JSON string with support for extended data types date/bigint/uint8array.
|
|
39
|
+
* @param json The object to pause.
|
|
40
|
+
* @returns The object.
|
|
41
|
+
*/
|
|
42
|
+
static parseEx(json: string): any;
|
|
43
|
+
/**
|
|
44
|
+
* Replacer function to handle extended data types.
|
|
45
|
+
* @param this The object.
|
|
46
|
+
* @param key The key.
|
|
47
|
+
* @param value The value.
|
|
48
|
+
* @returns The value.
|
|
49
|
+
*/
|
|
50
|
+
static stringifyExReplacer(this: any, key: string, value: unknown): unknown;
|
|
51
|
+
/**
|
|
52
|
+
* Reviver function to handle extended data types.
|
|
53
|
+
* @param this The object.
|
|
54
|
+
* @param key The key.
|
|
55
|
+
* @param value The value.
|
|
56
|
+
* @returns The value.
|
|
57
|
+
*/
|
|
58
|
+
static parseExReviver(this: any, key: string, value: unknown): unknown;
|
|
29
59
|
}
|
|
@@ -49,6 +49,7 @@ export declare class ObjectHelper {
|
|
|
49
49
|
* @param obj The object to set the property from.
|
|
50
50
|
* @param property The property to set.
|
|
51
51
|
* @param value The value to set.
|
|
52
|
+
* @throws GeneralError if the property target is not an object.
|
|
52
53
|
*/
|
|
53
54
|
static propertySet(obj: unknown, property: string, value: unknown): void;
|
|
54
55
|
/**
|
|
@@ -79,4 +80,28 @@ export declare class ObjectHelper {
|
|
|
79
80
|
* @returns The partial object.
|
|
80
81
|
*/
|
|
81
82
|
static omit<T>(obj: T | undefined, keys?: (keyof T)[]): Partial<T>;
|
|
83
|
+
/**
|
|
84
|
+
* Converter the non JSON primitives to extended types.
|
|
85
|
+
* @param obj The object to convert.
|
|
86
|
+
* @returns The object with extended properties.
|
|
87
|
+
*/
|
|
88
|
+
static toExtended(obj: any): any;
|
|
89
|
+
/**
|
|
90
|
+
* Converter the extended types to non JSON primitives.
|
|
91
|
+
* @param obj The object to convert.
|
|
92
|
+
* @returns The object with regular properties.
|
|
93
|
+
*/
|
|
94
|
+
static fromExtended(obj: any): any;
|
|
95
|
+
/**
|
|
96
|
+
* Remove empty properties from an object.
|
|
97
|
+
* @param obj The object to remove the empty properties from.
|
|
98
|
+
* @param options The options for the removal.
|
|
99
|
+
* @param options.removeUndefined Remove undefined properties, defaults to true.
|
|
100
|
+
* @param options.removeNull Remove null properties, defaults to false.
|
|
101
|
+
* @returns The object with empty properties removed.
|
|
102
|
+
*/
|
|
103
|
+
static removeEmptyProperties<T = unknown>(obj: T, options?: {
|
|
104
|
+
removeUndefined?: boolean;
|
|
105
|
+
removeNull?: boolean;
|
|
106
|
+
}): T;
|
|
82
107
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Class to help with uint8 arrays.
|
|
3
|
+
*/
|
|
4
|
+
export declare class Uint8ArrayHelper {
|
|
5
|
+
/**
|
|
6
|
+
* Concatenate multiple arrays.
|
|
7
|
+
* @param arrays The array to concatenate.
|
|
8
|
+
* @returns The combined array.
|
|
9
|
+
*/
|
|
10
|
+
static concat(arrays: Uint8Array[]): Uint8Array;
|
|
11
|
+
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export * from "./errors/validationError";
|
|
|
16
16
|
export * from "./factories/componentFactory";
|
|
17
17
|
export * from "./factories/factory";
|
|
18
18
|
export * from "./helpers/arrayHelper";
|
|
19
|
+
export * from "./helpers/envHelper";
|
|
19
20
|
export * from "./helpers/errorHelper";
|
|
20
21
|
export * from "./helpers/filenameHelper";
|
|
21
22
|
export * from "./helpers/hexHelper";
|
|
@@ -23,9 +24,12 @@ export * from "./helpers/jsonHelper";
|
|
|
23
24
|
export * from "./helpers/objectHelper";
|
|
24
25
|
export * from "./helpers/randomHelper";
|
|
25
26
|
export * from "./helpers/stringHelper";
|
|
27
|
+
export * from "./helpers/uint8ArrayHelper";
|
|
28
|
+
export * from "./models/coerceType";
|
|
26
29
|
export * from "./models/compressionType";
|
|
27
30
|
export * from "./models/IComponent";
|
|
28
31
|
export * from "./models/IError";
|
|
32
|
+
export * from "./models/II18nShared";
|
|
29
33
|
export * from "./models/IKeyValue";
|
|
30
34
|
export * from "./models/ILabelledValue";
|
|
31
35
|
export * from "./models/ILocale";
|
|
@@ -34,6 +38,7 @@ export * from "./models/ILocalesIndex";
|
|
|
34
38
|
export * from "./models/IPatchOperation";
|
|
35
39
|
export * from "./models/IUrlParts";
|
|
36
40
|
export * from "./models/IValidationFailure";
|
|
41
|
+
export * from "./models/objectOrArray";
|
|
37
42
|
export * from "./types/bitString";
|
|
38
43
|
export * from "./types/url";
|
|
39
44
|
export * from "./types/urn";
|
|
@@ -44,4 +49,5 @@ export * from "./utils/converter";
|
|
|
44
49
|
export * from "./utils/guards";
|
|
45
50
|
export * from "./utils/i18n";
|
|
46
51
|
export * from "./utils/is";
|
|
52
|
+
export * from "./utils/sharedStore";
|
|
47
53
|
export * from "./utils/validation";
|
|
@@ -9,21 +9,30 @@ export interface IComponent {
|
|
|
9
9
|
/**
|
|
10
10
|
* Bootstrap the component by creating and initializing any resources it needs.
|
|
11
11
|
* @param nodeLoggingConnectorType The node logging connector type, defaults to "node-logging".
|
|
12
|
+
* @param componentState A persistent state which can be modified by the method.
|
|
12
13
|
* @returns True if the bootstrapping process was successful.
|
|
13
14
|
*/
|
|
14
|
-
bootstrap?(nodeLoggingConnectorType
|
|
15
|
+
bootstrap?(nodeLoggingConnectorType: string | undefined, componentState?: {
|
|
16
|
+
[id: string]: unknown;
|
|
17
|
+
}): Promise<boolean>;
|
|
15
18
|
/**
|
|
16
19
|
* The component needs to be started when the node is initialized.
|
|
17
20
|
* @param nodeIdentity The identity of the node starting the component.
|
|
18
21
|
* @param nodeLoggingConnectorType The node logging connector type, defaults to "node-logging".
|
|
22
|
+
* @param componentState A persistent state which can be modified by the method.
|
|
19
23
|
* @returns Nothing.
|
|
20
24
|
*/
|
|
21
|
-
start?(nodeIdentity: string, nodeLoggingConnectorType
|
|
25
|
+
start?(nodeIdentity: string, nodeLoggingConnectorType: string | undefined, componentState?: {
|
|
26
|
+
[id: string]: unknown;
|
|
27
|
+
}): Promise<void>;
|
|
22
28
|
/**
|
|
23
29
|
* The component needs to be stopped when the node is closed.
|
|
24
30
|
* @param nodeIdentity The identity of the node stopping the component.
|
|
25
31
|
* @param nodeLoggingConnectorType The node logging connector type, defaults to "node-logging".
|
|
32
|
+
* @param componentState A persistent state which can be modified by the method.
|
|
26
33
|
* @returns Nothing.
|
|
27
34
|
*/
|
|
28
|
-
stop?(nodeIdentity: string, nodeLoggingConnectorType
|
|
35
|
+
stop?(nodeIdentity: string, nodeLoggingConnectorType: string | undefined, componentState?: {
|
|
36
|
+
[id: string]: unknown;
|
|
37
|
+
}): Promise<void>;
|
|
29
38
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shared state for the I18n global.
|
|
3
|
+
*/
|
|
4
|
+
export interface II18nShared {
|
|
5
|
+
/**
|
|
6
|
+
* Dictionaries for lookups.
|
|
7
|
+
*/
|
|
8
|
+
localeDictionaries: {
|
|
9
|
+
[locale: string]: {
|
|
10
|
+
[key: string]: string;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* The current locale.
|
|
15
|
+
*/
|
|
16
|
+
currentLocale: string;
|
|
17
|
+
/**
|
|
18
|
+
* Change handler for the locale being updated.
|
|
19
|
+
*/
|
|
20
|
+
localeChangedHandlers: {
|
|
21
|
+
[id: string]: (locale: string) => void;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Change handler for the dictionaries being updated.
|
|
25
|
+
*/
|
|
26
|
+
dictionaryChangedHandlers: {
|
|
27
|
+
[id: string]: (locale: string) => void;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The types the extracted data can be coerced to.
|
|
3
|
+
*/
|
|
4
|
+
export declare const CoerceType: {
|
|
5
|
+
/**
|
|
6
|
+
* String.
|
|
7
|
+
*/
|
|
8
|
+
readonly String: "string";
|
|
9
|
+
/**
|
|
10
|
+
* Number.
|
|
11
|
+
*/
|
|
12
|
+
readonly Number: "number";
|
|
13
|
+
/**
|
|
14
|
+
* Integer.
|
|
15
|
+
*/
|
|
16
|
+
readonly Integer: "integer";
|
|
17
|
+
/**
|
|
18
|
+
* Boolean.
|
|
19
|
+
*/
|
|
20
|
+
readonly Boolean: "boolean";
|
|
21
|
+
/**
|
|
22
|
+
* Big Integer.
|
|
23
|
+
*/
|
|
24
|
+
readonly BigInt: "bigint";
|
|
25
|
+
/**
|
|
26
|
+
* Date.
|
|
27
|
+
*/
|
|
28
|
+
readonly Date: "date";
|
|
29
|
+
/**
|
|
30
|
+
* Date Time.
|
|
31
|
+
*/
|
|
32
|
+
readonly DateTime: "datetime";
|
|
33
|
+
/**
|
|
34
|
+
* Time.
|
|
35
|
+
*/
|
|
36
|
+
readonly Time: "time";
|
|
37
|
+
/**
|
|
38
|
+
* Object.
|
|
39
|
+
*/
|
|
40
|
+
readonly Object: "object";
|
|
41
|
+
/**
|
|
42
|
+
* Uint8Array.
|
|
43
|
+
*/
|
|
44
|
+
readonly Uint8Array: "uint8array";
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* The types the extracted data can be coerced to.
|
|
48
|
+
*/
|
|
49
|
+
export type CoerceType = (typeof CoerceType)[keyof typeof CoerceType];
|
|
@@ -7,15 +7,24 @@ export declare class AsyncCache {
|
|
|
7
7
|
* @param key The key for the entry in the cache.
|
|
8
8
|
* @param ttlMs The TTL of the entry in the cache.
|
|
9
9
|
* @param requestMethod The method to call if not cached.
|
|
10
|
+
* @param cacheFailures Cache failure results, defaults to false.
|
|
10
11
|
* @returns The response.
|
|
11
12
|
*/
|
|
12
|
-
static exec<T = unknown>(key: string, ttlMs: number | undefined, requestMethod: () => Promise<T
|
|
13
|
+
static exec<T = unknown>(key: string, ttlMs: number | undefined, requestMethod: () => Promise<T>, cacheFailures?: boolean): Promise<T> | undefined;
|
|
13
14
|
/**
|
|
14
15
|
* Get an entry from the cache.
|
|
15
16
|
* @param key The key to get from the cache.
|
|
16
17
|
* @returns The item from the cache if it exists.
|
|
17
18
|
*/
|
|
18
19
|
static get<T = unknown>(key: string): Promise<T | undefined>;
|
|
20
|
+
/**
|
|
21
|
+
* Set an entry into the cache.
|
|
22
|
+
* @param key The key to set in the cache.
|
|
23
|
+
* @param value The value to set in the cache.
|
|
24
|
+
* @param ttlMs The TTL of the entry in the cache in ms, defaults to 1s.
|
|
25
|
+
* @returns Nothing.
|
|
26
|
+
*/
|
|
27
|
+
static set<T = unknown>(key: string, value: T, ttlMs?: number): Promise<void>;
|
|
19
28
|
/**
|
|
20
29
|
* Remove an entry from the cache.
|
|
21
30
|
* @param key The key to remove from the cache.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CoerceType } from "../models/coerceType";
|
|
1
2
|
/**
|
|
2
3
|
* Coerce an object from one type to another.
|
|
3
4
|
*/
|
|
@@ -16,6 +17,13 @@ export declare class Coerce {
|
|
|
16
17
|
* @returns The value if it can be coerced.
|
|
17
18
|
*/
|
|
18
19
|
static number(value: unknown): number | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Coerce the value to an integer.
|
|
22
|
+
* @param value The value to coerce.
|
|
23
|
+
* @throws TypeError If the value can not be coerced.
|
|
24
|
+
* @returns The value if it can be coerced.
|
|
25
|
+
*/
|
|
26
|
+
static integer(value: unknown): number | undefined;
|
|
19
27
|
/**
|
|
20
28
|
* Coerce the value to a bigint.
|
|
21
29
|
* @param value The value to coerce.
|
|
@@ -58,4 +66,18 @@ export declare class Coerce {
|
|
|
58
66
|
* @returns The value if it can be coerced.
|
|
59
67
|
*/
|
|
60
68
|
static object<T = unknown>(value: unknown): T | undefined;
|
|
69
|
+
/**
|
|
70
|
+
* Coerce the value to a Uint8Array.
|
|
71
|
+
* @param value The value to coerce.
|
|
72
|
+
* @throws TypeError If the value can not be coerced.
|
|
73
|
+
* @returns The value if it can be coerced.
|
|
74
|
+
*/
|
|
75
|
+
static uint8Array(value: unknown): Uint8Array | undefined;
|
|
76
|
+
/**
|
|
77
|
+
* Coerces a value based on the coercion type.
|
|
78
|
+
* @param value The value to coerce.
|
|
79
|
+
* @param type The coercion type to perform.
|
|
80
|
+
* @returns The coerced value.
|
|
81
|
+
*/
|
|
82
|
+
static byType(value: unknown, type?: CoerceType): unknown;
|
|
61
83
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ObjectOrArray } from "../models/objectOrArray";
|
|
1
2
|
/**
|
|
2
3
|
* Class to handle guard operations for parameters.
|
|
3
4
|
*/
|
|
@@ -26,6 +27,14 @@ export declare class Guards {
|
|
|
26
27
|
* @throws GuardError If the value does not match the assertion.
|
|
27
28
|
*/
|
|
28
29
|
static stringValue(source: string, property: string, value: unknown): asserts value is string;
|
|
30
|
+
/**
|
|
31
|
+
* Is the property a JSON value.
|
|
32
|
+
* @param source The source of the error.
|
|
33
|
+
* @param property The name of the property.
|
|
34
|
+
* @param value The value to test.
|
|
35
|
+
* @throws GuardError If the value does not match the assertion.
|
|
36
|
+
*/
|
|
37
|
+
static json(source: string, property: string, value: unknown): asserts value is string;
|
|
29
38
|
/**
|
|
30
39
|
* Is the property a base64 string.
|
|
31
40
|
* @param source The source of the error.
|
|
@@ -42,6 +51,14 @@ export declare class Guards {
|
|
|
42
51
|
* @throws GuardError If the value does not match the assertion.
|
|
43
52
|
*/
|
|
44
53
|
static stringBase64Url(source: string, property: string, value: unknown): asserts value is string;
|
|
54
|
+
/**
|
|
55
|
+
* Is the property a base58 string.
|
|
56
|
+
* @param source The source of the error.
|
|
57
|
+
* @param property The name of the property.
|
|
58
|
+
* @param value The value to test.
|
|
59
|
+
* @throws GuardError If the value does not match the assertion.
|
|
60
|
+
*/
|
|
61
|
+
static stringBase58(source: string, property: string, value: unknown): asserts value is string;
|
|
45
62
|
/**
|
|
46
63
|
* Is the property a string with a hex value.
|
|
47
64
|
* @param source The source of the error.
|
|
@@ -162,6 +179,24 @@ export declare class Guards {
|
|
|
162
179
|
* @throws GuardError If the value does not match the assertion.
|
|
163
180
|
*/
|
|
164
181
|
static arrayOneOf<T>(source: string, property: string, value: T, options: T[]): asserts value is T;
|
|
182
|
+
/**
|
|
183
|
+
* Does the array start with the specified data.
|
|
184
|
+
* @param source The source of the error.
|
|
185
|
+
* @param property The name of the property.
|
|
186
|
+
* @param value The value to test.
|
|
187
|
+
* @param startValues The values that must start the array.
|
|
188
|
+
* @throws GuardError If the value does not match the assertion.
|
|
189
|
+
*/
|
|
190
|
+
static arrayStartsWith<T>(source: string, property: string, value: unknown, startValues: ObjectOrArray<T>): asserts value is T[];
|
|
191
|
+
/**
|
|
192
|
+
* Does the array end with the specified data.
|
|
193
|
+
* @param source The source of the error.
|
|
194
|
+
* @param property The name of the property.
|
|
195
|
+
* @param value The value to test.
|
|
196
|
+
* @param endValues The values that must end the array.
|
|
197
|
+
* @throws GuardError If the value does not match the assertion.
|
|
198
|
+
*/
|
|
199
|
+
static arrayEndsWith<T>(source: string, property: string, value: unknown, endValues: ObjectOrArray<T>): asserts value is T[];
|
|
165
200
|
/**
|
|
166
201
|
* Is the property a Uint8Array.
|
|
167
202
|
* @param source The source of the error.
|
package/dist/types/utils/is.d.ts
CHANGED
|
@@ -56,6 +56,12 @@ export declare class Is {
|
|
|
56
56
|
* @returns True if the value is a base64 string.
|
|
57
57
|
*/
|
|
58
58
|
static stringBase64Url(value: unknown): value is string;
|
|
59
|
+
/**
|
|
60
|
+
* Is the value a base58 string.
|
|
61
|
+
* @param value The value to test.
|
|
62
|
+
* @returns True if the value is a base58 string.
|
|
63
|
+
*/
|
|
64
|
+
static stringBase58(value: unknown): value is string;
|
|
59
65
|
/**
|
|
60
66
|
* Is the value a hex string.
|
|
61
67
|
* @param value The value to test.
|
|
@@ -202,4 +208,10 @@ export declare class Is {
|
|
|
202
208
|
* @returns True if the value is a promise.
|
|
203
209
|
*/
|
|
204
210
|
static promise<T = unknown>(value: unknown): value is Promise<T>;
|
|
211
|
+
/**
|
|
212
|
+
* Is the value a regexp.
|
|
213
|
+
* @param value The value to test.
|
|
214
|
+
* @returns True if the value is a regexp.
|
|
215
|
+
*/
|
|
216
|
+
static regexp(value: unknown): value is RegExp;
|
|
205
217
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provide a store for shared objects which can be accesses through multiple
|
|
3
|
+
* instance loads of a packages.
|
|
4
|
+
*/
|
|
5
|
+
export declare class SharedStore {
|
|
6
|
+
/**
|
|
7
|
+
* Get a property from the shared store.
|
|
8
|
+
* @param prop The name of the property to get.
|
|
9
|
+
* @returns The property if it exists.
|
|
10
|
+
*/
|
|
11
|
+
static get<T = unknown>(prop: string): T | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Set the property in the shared store.
|
|
14
|
+
* @param prop The name of the property to set.
|
|
15
|
+
* @param value The value to set.
|
|
16
|
+
*/
|
|
17
|
+
static set<T = unknown>(prop: string, value: T): void;
|
|
18
|
+
/**
|
|
19
|
+
* Remove a property from the shared store.
|
|
20
|
+
* @param prop The name of the property to remove.
|
|
21
|
+
*/
|
|
22
|
+
static remove(prop: string): void;
|
|
23
|
+
}
|
|
@@ -30,9 +30,11 @@ export declare class Validation {
|
|
|
30
30
|
* @param options Additional options for the validation.
|
|
31
31
|
* @param options.minLength The minimum length of the string.
|
|
32
32
|
* @param options.maxLength The maximum length of the string.
|
|
33
|
+
* @param options.format Specific format to check.
|
|
33
34
|
* @returns True if the value is a valid string.
|
|
34
35
|
*/
|
|
35
36
|
static string(property: string, value: unknown, failures: IValidationFailure[], fieldNameResource?: string, options?: {
|
|
37
|
+
format?: "base64" | "base58" | "hex" | RegExp;
|
|
36
38
|
minLength?: number;
|
|
37
39
|
maxLength?: number;
|
|
38
40
|
}): value is string;
|