@twin.org/core 0.0.1-next.1
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/LICENSE +201 -0
- package/README.md +29 -0
- package/dist/cjs/index.cjs +4221 -0
- package/dist/esm/index.mjs +4184 -0
- package/dist/types/encoding/base32.d.ts +18 -0
- package/dist/types/encoding/base64.d.ts +24 -0
- package/dist/types/encoding/base64Url.d.ts +18 -0
- package/dist/types/errors/alreadyExistsError.d.ts +18 -0
- package/dist/types/errors/baseError.d.ts +103 -0
- package/dist/types/errors/conflictError.d.ts +19 -0
- package/dist/types/errors/generalError.d.ts +20 -0
- package/dist/types/errors/guardError.d.ts +19 -0
- package/dist/types/errors/notFoundError.d.ts +18 -0
- package/dist/types/errors/notImplementedError.d.ts +16 -0
- package/dist/types/errors/notSupportedError.d.ts +17 -0
- package/dist/types/errors/unauthorizedError.d.ts +17 -0
- package/dist/types/errors/unprocessableError.d.ts +20 -0
- package/dist/types/errors/validationError.d.ts +18 -0
- package/dist/types/factories/componentFactory.d.ts +6 -0
- package/dist/types/factories/factory.d.ts +67 -0
- package/dist/types/helpers/arrayHelper.d.ts +12 -0
- package/dist/types/helpers/errorHelper.d.ts +24 -0
- package/dist/types/helpers/filenameHelper.d.ts +11 -0
- package/dist/types/helpers/hexHelper.d.ts +30 -0
- package/dist/types/helpers/jsonHelper.d.ts +29 -0
- package/dist/types/helpers/objectHelper.d.ts +74 -0
- package/dist/types/helpers/randomHelper.d.ts +11 -0
- package/dist/types/helpers/stringHelper.d.ts +90 -0
- package/dist/types/index.d.ts +46 -0
- package/dist/types/models/IComponent.d.ts +29 -0
- package/dist/types/models/IError.d.ts +31 -0
- package/dist/types/models/IKeyValue.d.ts +13 -0
- package/dist/types/models/ILabelledValue.d.ts +13 -0
- package/dist/types/models/ILocale.d.ts +13 -0
- package/dist/types/models/ILocaleDictionary.d.ts +6 -0
- package/dist/types/models/ILocalesIndex.d.ts +10 -0
- package/dist/types/models/IPatchOperation.d.ts +21 -0
- package/dist/types/models/IUrlParts.d.ts +29 -0
- package/dist/types/models/IValidationFailure.d.ts +23 -0
- package/dist/types/models/compressionType.d.ts +17 -0
- package/dist/types/types/bitString.d.ts +41 -0
- package/dist/types/types/url.d.ts +56 -0
- package/dist/types/types/urn.d.ts +93 -0
- package/dist/types/utils/asyncCache.d.ts +33 -0
- package/dist/types/utils/coerce.d.ts +61 -0
- package/dist/types/utils/compression.d.ts +20 -0
- package/dist/types/utils/converter.d.ts +85 -0
- package/dist/types/utils/guards.d.ts +190 -0
- package/dist/types/utils/i18n.d.ts +81 -0
- package/dist/types/utils/is.d.ts +205 -0
- package/dist/types/utils/validation.d.ts +245 -0
- package/docs/changelog.md +5 -0
- package/docs/examples.md +1 -0
- package/docs/reference/classes/AlreadyExistsError.md +375 -0
- package/docs/reference/classes/ArrayHelper.md +37 -0
- package/docs/reference/classes/AsyncCache.md +117 -0
- package/docs/reference/classes/Base32.md +57 -0
- package/docs/reference/classes/Base64.md +74 -0
- package/docs/reference/classes/Base64Url.md +54 -0
- package/docs/reference/classes/BaseError.md +344 -0
- package/docs/reference/classes/BitString.md +123 -0
- package/docs/reference/classes/Coerce.md +209 -0
- package/docs/reference/classes/Compression.md +61 -0
- package/docs/reference/classes/ConflictError.md +379 -0
- package/docs/reference/classes/Converter.md +285 -0
- package/docs/reference/classes/ErrorHelper.md +73 -0
- package/docs/reference/classes/Factory.md +221 -0
- package/docs/reference/classes/FilenameHelper.md +33 -0
- package/docs/reference/classes/GeneralError.md +375 -0
- package/docs/reference/classes/GuardError.md +379 -0
- package/docs/reference/classes/Guards.md +711 -0
- package/docs/reference/classes/HexHelper.md +97 -0
- package/docs/reference/classes/I18n.md +237 -0
- package/docs/reference/classes/Is.md +693 -0
- package/docs/reference/classes/JsonHelper.md +92 -0
- package/docs/reference/classes/NotFoundError.md +375 -0
- package/docs/reference/classes/NotImplementedError.md +367 -0
- package/docs/reference/classes/NotSupportedError.md +371 -0
- package/docs/reference/classes/ObjectHelper.md +287 -0
- package/docs/reference/classes/RandomHelper.md +33 -0
- package/docs/reference/classes/StringHelper.md +270 -0
- package/docs/reference/classes/UnauthorizedError.md +371 -0
- package/docs/reference/classes/UnprocessableError.md +375 -0
- package/docs/reference/classes/Url.md +167 -0
- package/docs/reference/classes/Urn.md +295 -0
- package/docs/reference/classes/Validation.md +821 -0
- package/docs/reference/classes/ValidationError.md +371 -0
- package/docs/reference/index.md +60 -0
- package/docs/reference/interfaces/IComponent.md +79 -0
- package/docs/reference/interfaces/IError.md +55 -0
- package/docs/reference/interfaces/IKeyValue.md +23 -0
- package/docs/reference/interfaces/ILabelledValue.md +23 -0
- package/docs/reference/interfaces/ILocale.md +19 -0
- package/docs/reference/interfaces/ILocaleDictionary.md +7 -0
- package/docs/reference/interfaces/ILocalesIndex.md +11 -0
- package/docs/reference/interfaces/IPatchOperation.md +35 -0
- package/docs/reference/interfaces/IUrlParts.md +51 -0
- package/docs/reference/interfaces/IValidationFailure.md +39 -0
- package/docs/reference/type-aliases/CompressionType.md +5 -0
- package/docs/reference/variables/ComponentFactory.md +5 -0
- package/docs/reference/variables/CompressionType.md +19 -0
- package/locales/en.json +98 -0
- package/package.json +65 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Class to help with base63 Encoding/Decoding.
|
|
3
|
+
*/
|
|
4
|
+
export declare class Base32 {
|
|
5
|
+
/**
|
|
6
|
+
* Convert the base 32 string to a byte array.
|
|
7
|
+
* @param base32 The base32 string to convert.
|
|
8
|
+
* @returns The byte array.
|
|
9
|
+
* @throws If the input string contains a character not in the Base32 alphabet.
|
|
10
|
+
*/
|
|
11
|
+
static decode(base32: string): Uint8Array;
|
|
12
|
+
/**
|
|
13
|
+
* Convert a byte array to base 32.
|
|
14
|
+
* @param bytes The byte array to convert.
|
|
15
|
+
* @returns The data as base32 string.
|
|
16
|
+
*/
|
|
17
|
+
static encode(bytes: Uint8Array): string;
|
|
18
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Class to help with base64 Encoding/Decoding.
|
|
3
|
+
* Sourced from https://github.com/beatgammit/base64-js.
|
|
4
|
+
*/
|
|
5
|
+
export declare class Base64 {
|
|
6
|
+
/**
|
|
7
|
+
* Get the byte length of the data.
|
|
8
|
+
* @param base64 The base64 string.
|
|
9
|
+
* @returns The byte length of the data.
|
|
10
|
+
*/
|
|
11
|
+
static byteLength(base64: string): number;
|
|
12
|
+
/**
|
|
13
|
+
* Convert the base 64 string to a byte array.
|
|
14
|
+
* @param base64 The base64 string to convert.
|
|
15
|
+
* @returns The byte array.
|
|
16
|
+
*/
|
|
17
|
+
static decode(base64: string): Uint8Array;
|
|
18
|
+
/**
|
|
19
|
+
* Convert a byte array to base 64.
|
|
20
|
+
* @param bytes The byte array to convert.
|
|
21
|
+
* @returns The data as base64 string.
|
|
22
|
+
*/
|
|
23
|
+
static encode(bytes: Uint8Array): string;
|
|
24
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Class to help with base64 URL Encoding/Decoding.
|
|
3
|
+
* https://www.rfc-editor.org/rfc/rfc4648#section-5.
|
|
4
|
+
*/
|
|
5
|
+
export declare class Base64Url {
|
|
6
|
+
/**
|
|
7
|
+
* Convert the base 64 string to a byte array.
|
|
8
|
+
* @param base64Url The base64 url string to convert.
|
|
9
|
+
* @returns The byte array.
|
|
10
|
+
*/
|
|
11
|
+
static decode(base64Url: string): Uint8Array;
|
|
12
|
+
/**
|
|
13
|
+
* Convert a byte array to base 64 url.
|
|
14
|
+
* @param bytes The byte array to convert.
|
|
15
|
+
* @returns The data as base64 url string.
|
|
16
|
+
*/
|
|
17
|
+
static encode(bytes: Uint8Array): string;
|
|
18
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { BaseError } from "./baseError";
|
|
2
|
+
/**
|
|
3
|
+
* Class to handle errors which are triggered by data already existing.
|
|
4
|
+
*/
|
|
5
|
+
export declare class AlreadyExistsError extends BaseError {
|
|
6
|
+
/**
|
|
7
|
+
* Runtime name for the class.
|
|
8
|
+
*/
|
|
9
|
+
static readonly CLASS_NAME: string;
|
|
10
|
+
/**
|
|
11
|
+
* Create a new instance of AlreadyExistsError.
|
|
12
|
+
* @param source The source of the error.
|
|
13
|
+
* @param message The message as a code.
|
|
14
|
+
* @param existingId The id for the item.
|
|
15
|
+
* @param inner The inner error if we have wrapped another error.
|
|
16
|
+
*/
|
|
17
|
+
constructor(source: string, message: string, existingId?: string, inner?: unknown);
|
|
18
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import type { IError } from "../models/IError";
|
|
2
|
+
/**
|
|
3
|
+
* Class to handle errors.
|
|
4
|
+
*/
|
|
5
|
+
export declare class BaseError extends Error implements IError {
|
|
6
|
+
/**
|
|
7
|
+
* The source of the error.
|
|
8
|
+
*/
|
|
9
|
+
source?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Any additional information for the error.
|
|
12
|
+
*/
|
|
13
|
+
properties?: {
|
|
14
|
+
[id: string]: unknown;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* The inner error if there was one.
|
|
18
|
+
*/
|
|
19
|
+
inner?: IError;
|
|
20
|
+
/**
|
|
21
|
+
* Create a new instance of BaseError.
|
|
22
|
+
* @param name The name of the error.
|
|
23
|
+
* @param source The source of the error.
|
|
24
|
+
* @param message The message as a code.
|
|
25
|
+
* @param properties Any additional information for the error.
|
|
26
|
+
* @param inner The inner error if we have wrapped another error.
|
|
27
|
+
*/
|
|
28
|
+
constructor(name: string, source: string, message: string, properties?: {
|
|
29
|
+
[id: string]: unknown;
|
|
30
|
+
}, inner?: unknown);
|
|
31
|
+
/**
|
|
32
|
+
* Construct an error from an existing one.
|
|
33
|
+
* @param err The existing error.
|
|
34
|
+
* @returns The new instance.
|
|
35
|
+
*/
|
|
36
|
+
static fromError(err: unknown): BaseError;
|
|
37
|
+
/**
|
|
38
|
+
* Flatten an error tree.
|
|
39
|
+
* @param err The starting error.
|
|
40
|
+
* @returns The list of all internal errors.
|
|
41
|
+
*/
|
|
42
|
+
static flatten(err: unknown): IError[];
|
|
43
|
+
/**
|
|
44
|
+
* Expand an error tree.
|
|
45
|
+
* @param errors The list of errors to expand.
|
|
46
|
+
* @returns The first level error.
|
|
47
|
+
*/
|
|
48
|
+
static expand(errors: IError[] | undefined): IError | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Test to see if the error has the specified error name.
|
|
51
|
+
* @param error The error to test.
|
|
52
|
+
* @param name The name to check for.
|
|
53
|
+
* @returns True if the error has the name.
|
|
54
|
+
*/
|
|
55
|
+
static isErrorName(error: unknown, name: string | RegExp): error is BaseError;
|
|
56
|
+
/**
|
|
57
|
+
* Test to see if the error has the specified error message.
|
|
58
|
+
* @param error The error to test.
|
|
59
|
+
* @param message The message to check for.
|
|
60
|
+
* @returns True if the error has the name.
|
|
61
|
+
*/
|
|
62
|
+
static isErrorMessage(error: unknown, message: string | RegExp): error is BaseError;
|
|
63
|
+
/**
|
|
64
|
+
* Test to see if the error has the specified error code.
|
|
65
|
+
* @param error The error to test.
|
|
66
|
+
* @param code The code to check for.
|
|
67
|
+
* @returns True if the error has the code.
|
|
68
|
+
*/
|
|
69
|
+
static isErrorCode(error: unknown, code: string | RegExp): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Test to see if any of the errors or children have the given error name.
|
|
72
|
+
* @param error The error to test.
|
|
73
|
+
* @param name The name to check for.
|
|
74
|
+
* @returns True if the error has the name.
|
|
75
|
+
*/
|
|
76
|
+
static someErrorName(error: unknown, name: string | RegExp): error is BaseError;
|
|
77
|
+
/**
|
|
78
|
+
* Test to see if any of the errors or children have the given error message.
|
|
79
|
+
* @param error The error to test.
|
|
80
|
+
* @param message The message to check for.
|
|
81
|
+
* @returns True if the error has the name.
|
|
82
|
+
*/
|
|
83
|
+
static someErrorMessage(error: unknown, message: string | RegExp): error is BaseError;
|
|
84
|
+
/**
|
|
85
|
+
* Test to see if any of the errors or children are from a specific class.
|
|
86
|
+
* @param error The error to test.
|
|
87
|
+
* @param cls The class to check for.
|
|
88
|
+
* @returns True if the error has the specific class.
|
|
89
|
+
*/
|
|
90
|
+
static someErrorClass(error: unknown, cls: string): error is BaseError;
|
|
91
|
+
/**
|
|
92
|
+
* Test to see if any of the errors or children have the given error code.
|
|
93
|
+
* @param error The error to test.
|
|
94
|
+
* @param code The code to check for.
|
|
95
|
+
* @returns True if the error has the name.
|
|
96
|
+
*/
|
|
97
|
+
static someErrorCode(error: unknown, code: string | RegExp): error is BaseError;
|
|
98
|
+
/**
|
|
99
|
+
* Serialize the error to the error model.
|
|
100
|
+
* @returns The error model.
|
|
101
|
+
*/
|
|
102
|
+
toJsonObject(): IError;
|
|
103
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BaseError } from "./baseError";
|
|
2
|
+
/**
|
|
3
|
+
* Class to handle errors which are triggered by conflicting data.
|
|
4
|
+
*/
|
|
5
|
+
export declare class ConflictError extends BaseError {
|
|
6
|
+
/**
|
|
7
|
+
* Runtime name for the class.
|
|
8
|
+
*/
|
|
9
|
+
static readonly CLASS_NAME: string;
|
|
10
|
+
/**
|
|
11
|
+
* Create a new instance of ConflictError.
|
|
12
|
+
* @param source The source of the error.
|
|
13
|
+
* @param message The message as a code.
|
|
14
|
+
* @param conflictId The id that has conflicts.
|
|
15
|
+
* @param conflicts The conflicts that occurred.
|
|
16
|
+
* @param inner The inner error if we have wrapped another error.
|
|
17
|
+
*/
|
|
18
|
+
constructor(source: string, message: string, conflictId?: string, conflicts?: string[], inner?: unknown);
|
|
19
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { BaseError } from "./baseError";
|
|
2
|
+
/**
|
|
3
|
+
* Class to handle errors.
|
|
4
|
+
*/
|
|
5
|
+
export declare class GeneralError extends BaseError {
|
|
6
|
+
/**
|
|
7
|
+
* Runtime name for the class.
|
|
8
|
+
*/
|
|
9
|
+
static readonly CLASS_NAME: string;
|
|
10
|
+
/**
|
|
11
|
+
* Create a new instance of GeneralError.
|
|
12
|
+
* @param source The source of the error.
|
|
13
|
+
* @param message The message as a code.
|
|
14
|
+
* @param properties Any additional information for the error.
|
|
15
|
+
* @param inner The inner error if we have wrapped another error.
|
|
16
|
+
*/
|
|
17
|
+
constructor(source: string, message: string, properties?: {
|
|
18
|
+
[id: string]: unknown;
|
|
19
|
+
}, inner?: unknown);
|
|
20
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BaseError } from "./baseError";
|
|
2
|
+
/**
|
|
3
|
+
* Class to handle errors which are triggered by data guards.
|
|
4
|
+
*/
|
|
5
|
+
export declare class GuardError extends BaseError {
|
|
6
|
+
/**
|
|
7
|
+
* Runtime name for the class.
|
|
8
|
+
*/
|
|
9
|
+
static readonly CLASS_NAME: string;
|
|
10
|
+
/**
|
|
11
|
+
* Create a new instance of GuardError.
|
|
12
|
+
* @param source The source of the error.
|
|
13
|
+
* @param message The message as a code.
|
|
14
|
+
* @param propertyName The property which triggered the guard error for the item.
|
|
15
|
+
* @param propertyValue The property value which triggered the guard error for the item.
|
|
16
|
+
* @param propertyOptions The property options which might be allowed.
|
|
17
|
+
*/
|
|
18
|
+
constructor(source: string, message: string, propertyName: string, propertyValue: unknown, propertyOptions?: string);
|
|
19
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { BaseError } from "./baseError";
|
|
2
|
+
/**
|
|
3
|
+
* Class to handle errors which are triggered by data not being found.
|
|
4
|
+
*/
|
|
5
|
+
export declare class NotFoundError extends BaseError {
|
|
6
|
+
/**
|
|
7
|
+
* Runtime name for the class.
|
|
8
|
+
*/
|
|
9
|
+
static readonly CLASS_NAME: string;
|
|
10
|
+
/**
|
|
11
|
+
* Create a new instance of NotFoundError.
|
|
12
|
+
* @param source The source of the error.
|
|
13
|
+
* @param message The message as a code.
|
|
14
|
+
* @param notFoundId The id for the item.
|
|
15
|
+
* @param inner The inner error if we have wrapped another error.
|
|
16
|
+
*/
|
|
17
|
+
constructor(source: string, message: string, notFoundId?: string, inner?: unknown);
|
|
18
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BaseError } from "./baseError";
|
|
2
|
+
/**
|
|
3
|
+
* Class to handle errors.
|
|
4
|
+
*/
|
|
5
|
+
export declare class NotImplementedError extends BaseError {
|
|
6
|
+
/**
|
|
7
|
+
* Runtime name for the class.
|
|
8
|
+
*/
|
|
9
|
+
static readonly CLASS_NAME: string;
|
|
10
|
+
/**
|
|
11
|
+
* Create a new instance of NotImplementedError.
|
|
12
|
+
* @param source The source of the error.
|
|
13
|
+
* @param method The method for the error.
|
|
14
|
+
*/
|
|
15
|
+
constructor(source: string, method: string);
|
|
16
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BaseError } from "./baseError";
|
|
2
|
+
/**
|
|
3
|
+
* Class to handle errors when a feature is unsupported.
|
|
4
|
+
*/
|
|
5
|
+
export declare class NotSupportedError extends BaseError {
|
|
6
|
+
/**
|
|
7
|
+
* Runtime name for the class.
|
|
8
|
+
*/
|
|
9
|
+
static readonly CLASS_NAME: string;
|
|
10
|
+
/**
|
|
11
|
+
* Create a new instance of NotSupportedError.
|
|
12
|
+
* @param source The source of the error.
|
|
13
|
+
* @param message The message as a code.
|
|
14
|
+
* @param inner The inner error if we have wrapped another error.
|
|
15
|
+
*/
|
|
16
|
+
constructor(source: string, message: string, inner?: unknown);
|
|
17
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BaseError } from "./baseError";
|
|
2
|
+
/**
|
|
3
|
+
* Class to handle errors which are triggered by access not being unauthorized.
|
|
4
|
+
*/
|
|
5
|
+
export declare class UnauthorizedError extends BaseError {
|
|
6
|
+
/**
|
|
7
|
+
* Runtime name for the class.
|
|
8
|
+
*/
|
|
9
|
+
static readonly CLASS_NAME: string;
|
|
10
|
+
/**
|
|
11
|
+
* Create a new instance of UnauthorizedError.
|
|
12
|
+
* @param source The source of the error.
|
|
13
|
+
* @param message The message as a code.
|
|
14
|
+
* @param inner The inner error if we have wrapped another error.
|
|
15
|
+
*/
|
|
16
|
+
constructor(source: string, message: string, inner?: unknown);
|
|
17
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { BaseError } from "./baseError";
|
|
2
|
+
/**
|
|
3
|
+
* Class to handle errors when some data can not be processed.
|
|
4
|
+
*/
|
|
5
|
+
export declare class UnprocessableError extends BaseError {
|
|
6
|
+
/**
|
|
7
|
+
* Runtime name for the class.
|
|
8
|
+
*/
|
|
9
|
+
static readonly CLASS_NAME: string;
|
|
10
|
+
/**
|
|
11
|
+
* Create a new instance of UnprocessableError.
|
|
12
|
+
* @param source The source of the error.
|
|
13
|
+
* @param message The message as a code.
|
|
14
|
+
* @param properties Any additional information for the error.
|
|
15
|
+
* @param inner The inner error if we have wrapped another error.
|
|
16
|
+
*/
|
|
17
|
+
constructor(source: string, message: string, properties?: {
|
|
18
|
+
[id: string]: unknown;
|
|
19
|
+
}, inner?: unknown);
|
|
20
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { BaseError } from "./baseError";
|
|
2
|
+
import type { IValidationFailure } from "../models/IValidationFailure";
|
|
3
|
+
/**
|
|
4
|
+
* Class to handle errors which are triggered by entity validation.
|
|
5
|
+
*/
|
|
6
|
+
export declare class ValidationError extends BaseError {
|
|
7
|
+
/**
|
|
8
|
+
* Runtime name for the class.s
|
|
9
|
+
*/
|
|
10
|
+
static readonly CLASS_NAME: string;
|
|
11
|
+
/**
|
|
12
|
+
* Create a new instance of ValidationError.
|
|
13
|
+
* @param source The source of the error.
|
|
14
|
+
* @param validationObject The object that failed validation.
|
|
15
|
+
* @param validationFailures The validation failures.
|
|
16
|
+
*/
|
|
17
|
+
constructor(source: string, validationObject: string, validationFailures: IValidationFailure[]);
|
|
18
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Factory for creating implementation of generic types.
|
|
3
|
+
*/
|
|
4
|
+
export declare class Factory<T> {
|
|
5
|
+
/**
|
|
6
|
+
* Create a new factory, which is shared throughout all library instances.
|
|
7
|
+
* @param typeName The type name for the instances.
|
|
8
|
+
* @param autoInstance Automatically create an instance when registered.
|
|
9
|
+
* @param matcher Match the name of the instance.
|
|
10
|
+
* @returns The factory instance.
|
|
11
|
+
*/
|
|
12
|
+
static createFactory<U>(typeName: string, autoInstance?: boolean, matcher?: (names: string[], name: string) => string | undefined): Factory<U>;
|
|
13
|
+
/**
|
|
14
|
+
* Register a new generator.
|
|
15
|
+
* @param name The name of the generator.
|
|
16
|
+
* @param generator The function to create an instance.
|
|
17
|
+
*/
|
|
18
|
+
register<U extends T>(name: string, generator: () => U): void;
|
|
19
|
+
/**
|
|
20
|
+
* Unregister a generator.
|
|
21
|
+
* @param name The name of the generator to unregister.
|
|
22
|
+
* @throws GuardError if the parameters are invalid.
|
|
23
|
+
* @throws GeneralError if no generator exists.
|
|
24
|
+
*/
|
|
25
|
+
unregister(name: string): void;
|
|
26
|
+
/**
|
|
27
|
+
* Get a generator instance.
|
|
28
|
+
* @param name The name of the instance to generate.
|
|
29
|
+
* @returns An instance of the item.
|
|
30
|
+
* @throws GuardError if the parameters are invalid.
|
|
31
|
+
* @throws GeneralError if no item exists to get.
|
|
32
|
+
*/
|
|
33
|
+
get<U extends T>(name: string): U;
|
|
34
|
+
/**
|
|
35
|
+
* Get a generator instance with no exceptions.
|
|
36
|
+
* @param name The name of the instance to generate.
|
|
37
|
+
* @returns An instance of the item or undefined if it does not exist.
|
|
38
|
+
*/
|
|
39
|
+
getIfExists<U extends T>(name: string): U | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* Reset all the instances.
|
|
42
|
+
*/
|
|
43
|
+
reset(): void;
|
|
44
|
+
/**
|
|
45
|
+
* Get all the instances as a map.
|
|
46
|
+
* @returns The instances as a map.
|
|
47
|
+
*/
|
|
48
|
+
instancesMap(): {
|
|
49
|
+
[name: string]: T;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Get all the instances as a list in the order they were registered.
|
|
53
|
+
* @returns The instances as a list in the order they were registered.
|
|
54
|
+
*/
|
|
55
|
+
instancesList(): T[];
|
|
56
|
+
/**
|
|
57
|
+
* Get all the generator names in the order they were registered.
|
|
58
|
+
* @returns The ordered generator names.
|
|
59
|
+
*/
|
|
60
|
+
names(): string[];
|
|
61
|
+
/**
|
|
62
|
+
* Does the factory contain the name.
|
|
63
|
+
* @param name The name of the instance to find.
|
|
64
|
+
* @returns True if the factory has a matching name.
|
|
65
|
+
*/
|
|
66
|
+
hasName(name: string): boolean;
|
|
67
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Class to help with arrays.
|
|
3
|
+
*/
|
|
4
|
+
export declare class ArrayHelper {
|
|
5
|
+
/**
|
|
6
|
+
* Do the two arrays match.
|
|
7
|
+
* @param arr1 The first array.
|
|
8
|
+
* @param arr2 The second array.
|
|
9
|
+
* @returns True if both arrays are empty of have the same values.
|
|
10
|
+
*/
|
|
11
|
+
static matches(arr1: unknown, arr2: unknown): boolean;
|
|
12
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { IError } from "../models/IError";
|
|
2
|
+
/**
|
|
3
|
+
* Error helper functions.
|
|
4
|
+
*/
|
|
5
|
+
export declare class ErrorHelper {
|
|
6
|
+
/**
|
|
7
|
+
* Format Errors and returns just their messages.
|
|
8
|
+
* @param error The error to format.
|
|
9
|
+
* @returns The error formatted including any inner errors.
|
|
10
|
+
*/
|
|
11
|
+
static formatErrors(error: unknown): string[];
|
|
12
|
+
/**
|
|
13
|
+
* Localize the content of an error and any inner errors.
|
|
14
|
+
* @param error The error to format.
|
|
15
|
+
* @returns The localized version of the errors flattened.
|
|
16
|
+
*/
|
|
17
|
+
static localizeErrors(error: unknown): IError[];
|
|
18
|
+
/**
|
|
19
|
+
* Localize the content of an error and any inner errors.
|
|
20
|
+
* @param error The error to format.
|
|
21
|
+
* @returns The localized version of the errors flattened.
|
|
22
|
+
*/
|
|
23
|
+
static formatValidationErrors(error: IError): string | undefined;
|
|
24
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Class to help with filenames.
|
|
3
|
+
*/
|
|
4
|
+
export declare class FilenameHelper {
|
|
5
|
+
/**
|
|
6
|
+
* Replaces any unsafe characters in the filename.
|
|
7
|
+
* @param filename The filename to make safe.
|
|
8
|
+
* @returns The safe filename.
|
|
9
|
+
*/
|
|
10
|
+
static safeFilename(filename: unknown): string;
|
|
11
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper methods for hex conversions.
|
|
3
|
+
*/
|
|
4
|
+
export declare class HexHelper {
|
|
5
|
+
/**
|
|
6
|
+
* Strip the 0x prefix if it exists.
|
|
7
|
+
* @param hex The hex value to strip.
|
|
8
|
+
* @returns The stripped hex without the prefix.
|
|
9
|
+
*/
|
|
10
|
+
static stripPrefix(hex: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Add the 0x prefix if it does not exist.
|
|
13
|
+
* @param hex The hex value to add the prefix to.
|
|
14
|
+
* @returns The hex with the prefix.
|
|
15
|
+
*/
|
|
16
|
+
static addPrefix(hex: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* Does the hex string have the prefix.
|
|
19
|
+
* @param hex The hex value to check for the prefix.
|
|
20
|
+
* @returns True if the hex string has the prefix.
|
|
21
|
+
*/
|
|
22
|
+
static hasPrefix(hex: string): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Is the data hex format.
|
|
25
|
+
* @param value The value to test.
|
|
26
|
+
* @param allowPrefix Allow the hex to have the 0x prefix.
|
|
27
|
+
* @returns True if the string is hex.
|
|
28
|
+
*/
|
|
29
|
+
static isHex(value: string, allowPrefix?: boolean): boolean;
|
|
30
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { IPatchOperation } from "../models/IPatchOperation";
|
|
2
|
+
/**
|
|
3
|
+
* Helpers methods for JSON objects.
|
|
4
|
+
*/
|
|
5
|
+
export declare class JsonHelper {
|
|
6
|
+
/**
|
|
7
|
+
* Serializes in canonical format.
|
|
8
|
+
* Based on https://www.rfc-editor.org/rfc/rfc8785.
|
|
9
|
+
* @param object The object to be serialized.
|
|
10
|
+
* @returns The serialized object.
|
|
11
|
+
*/
|
|
12
|
+
static canonicalize(object: unknown): string;
|
|
13
|
+
/**
|
|
14
|
+
* Creates a RFC 6902 diff set.
|
|
15
|
+
* Based on https://www.rfc-editor.org/rfc/rfc6902.
|
|
16
|
+
* @param object1 The first object.
|
|
17
|
+
* @param object2 The second object.
|
|
18
|
+
* @returns The list of patches.
|
|
19
|
+
*/
|
|
20
|
+
static diff<T = unknown>(object1: T, object2: T): IPatchOperation[];
|
|
21
|
+
/**
|
|
22
|
+
* Applies a RFC 6902 diff set to an object.
|
|
23
|
+
* Based on https://www.rfc-editor.org/rfc/rfc6902.
|
|
24
|
+
* @param object The object to patch.
|
|
25
|
+
* @param patches The second object.
|
|
26
|
+
* @returns The updated object.
|
|
27
|
+
*/
|
|
28
|
+
static patch<T = unknown>(object: T, patches: IPatchOperation[]): T;
|
|
29
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Class to help with objects.
|
|
3
|
+
*/
|
|
4
|
+
export declare class ObjectHelper {
|
|
5
|
+
/**
|
|
6
|
+
* Convert an object to bytes.
|
|
7
|
+
* @param obj The object to convert.
|
|
8
|
+
* @param format Format the JSON content.
|
|
9
|
+
* @returns The object as bytes.
|
|
10
|
+
*/
|
|
11
|
+
static toBytes<T>(obj: T | undefined, format?: boolean): Uint8Array;
|
|
12
|
+
/**
|
|
13
|
+
* Convert a bytes to an object.
|
|
14
|
+
* @param bytes The bytes to convert to an object.
|
|
15
|
+
* @returns The object.
|
|
16
|
+
* @throws GeneralError if there was an error parsing the JSON.
|
|
17
|
+
*/
|
|
18
|
+
static fromBytes<T>(bytes: Uint8Array | undefined | null): T;
|
|
19
|
+
/**
|
|
20
|
+
* Make a deep clone of an object.
|
|
21
|
+
* @param obj The object to clone.
|
|
22
|
+
* @returns The objects clone.
|
|
23
|
+
*/
|
|
24
|
+
static clone<T>(obj: T): T;
|
|
25
|
+
/**
|
|
26
|
+
* Deep merge objects.
|
|
27
|
+
* @param obj1 The first object to merge.
|
|
28
|
+
* @param obj2 The second object to merge.
|
|
29
|
+
* @returns The combined deep merge of the objects.
|
|
30
|
+
*/
|
|
31
|
+
static merge<T = unknown, U = unknown>(obj1: T, obj2: U): T & U;
|
|
32
|
+
/**
|
|
33
|
+
* Does one object equal another.
|
|
34
|
+
* @param obj1 The first object to compare.
|
|
35
|
+
* @param obj2 The second object to compare.
|
|
36
|
+
* @param strictPropertyOrder Should the properties be in the same order, defaults to true.
|
|
37
|
+
* @returns True is the objects are equal.
|
|
38
|
+
*/
|
|
39
|
+
static equal<T>(obj1: T, obj2: T, strictPropertyOrder?: boolean): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Get the property of an unknown object.
|
|
42
|
+
* @param obj The object to get the property from.
|
|
43
|
+
* @param property The property to get, can be separated by dots for nested path.
|
|
44
|
+
* @returns The property.
|
|
45
|
+
*/
|
|
46
|
+
static propertyGet<T = unknown>(obj: unknown, property: string): T | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* Set the property of an unknown object.
|
|
49
|
+
* @param obj The object to set the property from.
|
|
50
|
+
* @param property The property to set.
|
|
51
|
+
* @param value The value to set.
|
|
52
|
+
*/
|
|
53
|
+
static propertySet(obj: unknown, property: string, value: unknown): void;
|
|
54
|
+
/**
|
|
55
|
+
* Delete the property of an unknown object.
|
|
56
|
+
* @param obj The object to set the property from.
|
|
57
|
+
* @param property The property to set
|
|
58
|
+
*/
|
|
59
|
+
static propertyDelete(obj: unknown, property: string): void;
|
|
60
|
+
/**
|
|
61
|
+
* Pick a subset of properties from an object.
|
|
62
|
+
* @param obj The object to pick the properties from.
|
|
63
|
+
* @param keys The property keys to pick.
|
|
64
|
+
* @returns The partial object.
|
|
65
|
+
*/
|
|
66
|
+
static pick<T>(obj: T | undefined, keys?: (keyof T)[]): Partial<T>;
|
|
67
|
+
/**
|
|
68
|
+
* Omit a subset of properties from an object.
|
|
69
|
+
* @param obj The object to omit the properties from.
|
|
70
|
+
* @param keys The property keys to omit.
|
|
71
|
+
* @returns The partial object.
|
|
72
|
+
*/
|
|
73
|
+
static omit<T>(obj: T | undefined, keys?: (keyof T)[]): Partial<T>;
|
|
74
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Class to help with random generation.
|
|
3
|
+
*/
|
|
4
|
+
export declare class RandomHelper {
|
|
5
|
+
/**
|
|
6
|
+
* Generate a new random array.
|
|
7
|
+
* @param length The length of buffer to create.
|
|
8
|
+
* @returns The random array.
|
|
9
|
+
*/
|
|
10
|
+
static generate(length: number): Uint8Array;
|
|
11
|
+
}
|