@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.
Files changed (103) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +29 -0
  3. package/dist/cjs/index.cjs +4221 -0
  4. package/dist/esm/index.mjs +4184 -0
  5. package/dist/types/encoding/base32.d.ts +18 -0
  6. package/dist/types/encoding/base64.d.ts +24 -0
  7. package/dist/types/encoding/base64Url.d.ts +18 -0
  8. package/dist/types/errors/alreadyExistsError.d.ts +18 -0
  9. package/dist/types/errors/baseError.d.ts +103 -0
  10. package/dist/types/errors/conflictError.d.ts +19 -0
  11. package/dist/types/errors/generalError.d.ts +20 -0
  12. package/dist/types/errors/guardError.d.ts +19 -0
  13. package/dist/types/errors/notFoundError.d.ts +18 -0
  14. package/dist/types/errors/notImplementedError.d.ts +16 -0
  15. package/dist/types/errors/notSupportedError.d.ts +17 -0
  16. package/dist/types/errors/unauthorizedError.d.ts +17 -0
  17. package/dist/types/errors/unprocessableError.d.ts +20 -0
  18. package/dist/types/errors/validationError.d.ts +18 -0
  19. package/dist/types/factories/componentFactory.d.ts +6 -0
  20. package/dist/types/factories/factory.d.ts +67 -0
  21. package/dist/types/helpers/arrayHelper.d.ts +12 -0
  22. package/dist/types/helpers/errorHelper.d.ts +24 -0
  23. package/dist/types/helpers/filenameHelper.d.ts +11 -0
  24. package/dist/types/helpers/hexHelper.d.ts +30 -0
  25. package/dist/types/helpers/jsonHelper.d.ts +29 -0
  26. package/dist/types/helpers/objectHelper.d.ts +74 -0
  27. package/dist/types/helpers/randomHelper.d.ts +11 -0
  28. package/dist/types/helpers/stringHelper.d.ts +90 -0
  29. package/dist/types/index.d.ts +46 -0
  30. package/dist/types/models/IComponent.d.ts +29 -0
  31. package/dist/types/models/IError.d.ts +31 -0
  32. package/dist/types/models/IKeyValue.d.ts +13 -0
  33. package/dist/types/models/ILabelledValue.d.ts +13 -0
  34. package/dist/types/models/ILocale.d.ts +13 -0
  35. package/dist/types/models/ILocaleDictionary.d.ts +6 -0
  36. package/dist/types/models/ILocalesIndex.d.ts +10 -0
  37. package/dist/types/models/IPatchOperation.d.ts +21 -0
  38. package/dist/types/models/IUrlParts.d.ts +29 -0
  39. package/dist/types/models/IValidationFailure.d.ts +23 -0
  40. package/dist/types/models/compressionType.d.ts +17 -0
  41. package/dist/types/types/bitString.d.ts +41 -0
  42. package/dist/types/types/url.d.ts +56 -0
  43. package/dist/types/types/urn.d.ts +93 -0
  44. package/dist/types/utils/asyncCache.d.ts +33 -0
  45. package/dist/types/utils/coerce.d.ts +61 -0
  46. package/dist/types/utils/compression.d.ts +20 -0
  47. package/dist/types/utils/converter.d.ts +85 -0
  48. package/dist/types/utils/guards.d.ts +190 -0
  49. package/dist/types/utils/i18n.d.ts +81 -0
  50. package/dist/types/utils/is.d.ts +205 -0
  51. package/dist/types/utils/validation.d.ts +245 -0
  52. package/docs/changelog.md +5 -0
  53. package/docs/examples.md +1 -0
  54. package/docs/reference/classes/AlreadyExistsError.md +375 -0
  55. package/docs/reference/classes/ArrayHelper.md +37 -0
  56. package/docs/reference/classes/AsyncCache.md +117 -0
  57. package/docs/reference/classes/Base32.md +57 -0
  58. package/docs/reference/classes/Base64.md +74 -0
  59. package/docs/reference/classes/Base64Url.md +54 -0
  60. package/docs/reference/classes/BaseError.md +344 -0
  61. package/docs/reference/classes/BitString.md +123 -0
  62. package/docs/reference/classes/Coerce.md +209 -0
  63. package/docs/reference/classes/Compression.md +61 -0
  64. package/docs/reference/classes/ConflictError.md +379 -0
  65. package/docs/reference/classes/Converter.md +285 -0
  66. package/docs/reference/classes/ErrorHelper.md +73 -0
  67. package/docs/reference/classes/Factory.md +221 -0
  68. package/docs/reference/classes/FilenameHelper.md +33 -0
  69. package/docs/reference/classes/GeneralError.md +375 -0
  70. package/docs/reference/classes/GuardError.md +379 -0
  71. package/docs/reference/classes/Guards.md +711 -0
  72. package/docs/reference/classes/HexHelper.md +97 -0
  73. package/docs/reference/classes/I18n.md +237 -0
  74. package/docs/reference/classes/Is.md +693 -0
  75. package/docs/reference/classes/JsonHelper.md +92 -0
  76. package/docs/reference/classes/NotFoundError.md +375 -0
  77. package/docs/reference/classes/NotImplementedError.md +367 -0
  78. package/docs/reference/classes/NotSupportedError.md +371 -0
  79. package/docs/reference/classes/ObjectHelper.md +287 -0
  80. package/docs/reference/classes/RandomHelper.md +33 -0
  81. package/docs/reference/classes/StringHelper.md +270 -0
  82. package/docs/reference/classes/UnauthorizedError.md +371 -0
  83. package/docs/reference/classes/UnprocessableError.md +375 -0
  84. package/docs/reference/classes/Url.md +167 -0
  85. package/docs/reference/classes/Urn.md +295 -0
  86. package/docs/reference/classes/Validation.md +821 -0
  87. package/docs/reference/classes/ValidationError.md +371 -0
  88. package/docs/reference/index.md +60 -0
  89. package/docs/reference/interfaces/IComponent.md +79 -0
  90. package/docs/reference/interfaces/IError.md +55 -0
  91. package/docs/reference/interfaces/IKeyValue.md +23 -0
  92. package/docs/reference/interfaces/ILabelledValue.md +23 -0
  93. package/docs/reference/interfaces/ILocale.md +19 -0
  94. package/docs/reference/interfaces/ILocaleDictionary.md +7 -0
  95. package/docs/reference/interfaces/ILocalesIndex.md +11 -0
  96. package/docs/reference/interfaces/IPatchOperation.md +35 -0
  97. package/docs/reference/interfaces/IUrlParts.md +51 -0
  98. package/docs/reference/interfaces/IValidationFailure.md +39 -0
  99. package/docs/reference/type-aliases/CompressionType.md +5 -0
  100. package/docs/reference/variables/ComponentFactory.md +5 -0
  101. package/docs/reference/variables/CompressionType.md +19 -0
  102. package/locales/en.json +98 -0
  103. package/package.json +65 -0
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Class to help with string.
3
+ */
4
+ export declare class StringHelper {
5
+ /**
6
+ * Trim trailing slashes from a string.
7
+ * @param value The value to trim.
8
+ * @returns The trimmed value.
9
+ */
10
+ static trimTrailingSlashes(value: string | undefined): string;
11
+ /**
12
+ * Trim leading slashes from a string.
13
+ * @param value The value to trim.
14
+ * @returns The trimmed value.
15
+ */
16
+ static trimLeadingSlashes(value: string | undefined): string;
17
+ /**
18
+ * Convert the input string to kebab case.
19
+ * @param input The input to convert.
20
+ * @param stripInterfacePrefix Strip interface prefixes.
21
+ * @returns The kebab case version of the input.
22
+ */
23
+ static kebabCase(input: string, stripInterfacePrefix?: boolean): string;
24
+ /**
25
+ * Convert the input string to snake case.
26
+ * @param input The input to convert.
27
+ * @param stripInterfacePrefix Strip interface prefixes.
28
+ * @returns The snake case version of the input.
29
+ */
30
+ static snakeCase(input: string, stripInterfacePrefix?: boolean): string;
31
+ /**
32
+ * Title case all the words.
33
+ * @param input The input to convert.
34
+ * @param stripInterfacePrefix Strip interface prefixes.
35
+ * @returns The title case version of the input.
36
+ */
37
+ static titleCase(input: string, stripInterfacePrefix?: boolean): string;
38
+ /**
39
+ * Pascal case all the words.
40
+ * @param input The input to convert.
41
+ * @param stripInterfacePrefix Strip interface prefixes.
42
+ * @returns The pascal case version of the input.
43
+ */
44
+ static pascalCase(input: string, stripInterfacePrefix?: boolean): string;
45
+ /**
46
+ * Camel case all the words.
47
+ * @param input The input to convert.
48
+ * @param stripInterfacePrefix Strip interface prefixes.
49
+ * @returns The camel case version of the input.
50
+ */
51
+ static camelCase(input: string, stripInterfacePrefix?: boolean): string;
52
+ /**
53
+ * Convert the words to a path.
54
+ * @param input The input to convert.
55
+ * @param stripInterfacePrefix Strip interface prefixes.
56
+ * @returns The path version of the input.
57
+ */
58
+ static wordPath(input: string, stripInterfacePrefix?: boolean): string;
59
+ /**
60
+ * Strip interface prefix if there is one.
61
+ * @param input The input to strip.
62
+ * @returns The input with any interface prefix stripped.
63
+ */
64
+ static stripPrefix(input: string): string;
65
+ /**
66
+ * Split a string into words.
67
+ * @param input The input to split.
68
+ * @returns The string split into words.
69
+ */
70
+ static words(input: string): string[];
71
+ /**
72
+ * Check if a Node.js Buffer or Uint8Array is UTF-8.
73
+ * Url https://tools.ietf.org/html/rfc3629
74
+ * Source https://github.com/hcodes/isutf8
75
+ * UTF8-char = UTF8-1 / UTF8-2 / UTF8-3 / UTF8-4.
76
+ * UTF8-1 = %x00-7F.
77
+ * UTF8-2 = %xC2-DF UTF8-tail.
78
+ * UTF8-3 = %xE0 %xA0-BF UTF8-tail.
79
+ * - %xE1-EC 2( UTF8-tail ).
80
+ * - %xED %x80-9F UTF8-tail.
81
+ * - %xEE-EF 2( UTF8-tail ).
82
+ * UTF8-4 = %xF0 %x90-BF 2( UTF8-tail ).
83
+ * - %xF1-F3 3( UTF8-tail ).
84
+ * - %xF4 %x80-8F 2( UTF8-tail ).
85
+ * UTF8-tail = %x80-BF.
86
+ * @param data The data to check.
87
+ * @returns True if the data is utf8.
88
+ */
89
+ static isUtf8(data: Uint8Array): boolean;
90
+ }
@@ -0,0 +1,46 @@
1
+ export * from "./encoding/base32";
2
+ export * from "./encoding/base64";
3
+ export * from "./encoding/base64Url";
4
+ export * from "./errors/alreadyExistsError";
5
+ export * from "./errors/baseError";
6
+ export * from "./errors/conflictError";
7
+ export * from "./errors/generalError";
8
+ export * from "./errors/guardError";
9
+ export * from "./errors/notFoundError";
10
+ export * from "./errors/notImplementedError";
11
+ export * from "./errors/notSupportedError";
12
+ export * from "./errors/unauthorizedError";
13
+ export * from "./errors/unprocessableError";
14
+ export * from "./errors/validationError";
15
+ export * from "./factories/componentFactory";
16
+ export * from "./factories/factory";
17
+ export * from "./helpers/arrayHelper";
18
+ export * from "./helpers/errorHelper";
19
+ export * from "./helpers/filenameHelper";
20
+ export * from "./helpers/hexHelper";
21
+ export * from "./helpers/jsonHelper";
22
+ export * from "./helpers/objectHelper";
23
+ export * from "./helpers/randomHelper";
24
+ export * from "./helpers/stringHelper";
25
+ export * from "./models/compressionType";
26
+ export * from "./models/IComponent";
27
+ export * from "./models/IError";
28
+ export * from "./models/IKeyValue";
29
+ export * from "./models/ILabelledValue";
30
+ export * from "./models/ILocale";
31
+ export * from "./models/ILocaleDictionary";
32
+ export * from "./models/ILocalesIndex";
33
+ export * from "./models/IPatchOperation";
34
+ export * from "./models/IUrlParts";
35
+ export * from "./models/IValidationFailure";
36
+ export * from "./types/bitString";
37
+ export * from "./types/url";
38
+ export * from "./types/urn";
39
+ export * from "./utils/asyncCache";
40
+ export * from "./utils/coerce";
41
+ export * from "./utils/compression";
42
+ export * from "./utils/converter";
43
+ export * from "./utils/guards";
44
+ export * from "./utils/i18n";
45
+ export * from "./utils/is";
46
+ export * from "./utils/validation";
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Interface describing a component which can be bootstrapped, started and stopped.
3
+ */
4
+ export interface IComponent {
5
+ /**
6
+ * The name of the component.
7
+ */
8
+ readonly CLASS_NAME: string;
9
+ /**
10
+ * Bootstrap the component by creating and initializing any resources it needs.
11
+ * @param nodeLoggingConnectorType The node logging connector type, defaults to "node-logging".
12
+ * @returns True if the bootstrapping process was successful.
13
+ */
14
+ bootstrap?(nodeLoggingConnectorType?: string): Promise<boolean>;
15
+ /**
16
+ * The component needs to be started when the node is initialized.
17
+ * @param nodeIdentity The identity of the node starting the component.
18
+ * @param nodeLoggingConnectorType The node logging connector type, defaults to "node-logging".
19
+ * @returns Nothing.
20
+ */
21
+ start?(nodeIdentity: string, nodeLoggingConnectorType?: string): Promise<void>;
22
+ /**
23
+ * The component needs to be stopped when the node is closed.
24
+ * @param nodeIdentity The identity of the node stopping the component.
25
+ * @param nodeLoggingConnectorType The node logging connector type, defaults to "node-logging".
26
+ * @returns Nothing.
27
+ */
28
+ stop?(nodeIdentity: string, nodeLoggingConnectorType?: string): Promise<void>;
29
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Model to describe serialized error.
3
+ */
4
+ export interface IError {
5
+ /**
6
+ * The name for the error.
7
+ */
8
+ name: string;
9
+ /**
10
+ * The message for the error.
11
+ */
12
+ message: string;
13
+ /**
14
+ * The source of the error.
15
+ */
16
+ source?: string;
17
+ /**
18
+ * Any additional information for the error.
19
+ */
20
+ properties?: {
21
+ [id: string]: unknown;
22
+ };
23
+ /**
24
+ * The stack trace for the error.
25
+ */
26
+ stack?: string;
27
+ /**
28
+ * The inner error if there was one.
29
+ */
30
+ inner?: IError;
31
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Interface describing a key/value pair.
3
+ */
4
+ export interface IKeyValue<T> {
5
+ /**
6
+ * The key for the item.
7
+ */
8
+ key: string;
9
+ /**
10
+ * The value for the item.
11
+ */
12
+ value: T;
13
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Interface describing a label/value pair.
3
+ */
4
+ export interface ILabelledValue<T> {
5
+ /**
6
+ * The label for the item.
7
+ */
8
+ label: string;
9
+ /**
10
+ * The value for the item.
11
+ */
12
+ value: T;
13
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Model for a local.
3
+ */
4
+ export interface ILocale {
5
+ /**
6
+ * The label.
7
+ */
8
+ label: string;
9
+ /**
10
+ * The code.
11
+ */
12
+ code: string;
13
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Type for the JSON locale dictionary files.
3
+ */
4
+ export interface ILocaleDictionary {
5
+ [key: string]: string | ILocaleDictionary;
6
+ }
@@ -0,0 +1,10 @@
1
+ import type { ILocale } from "./ILocale";
2
+ /**
3
+ * Model for a locales index.
4
+ */
5
+ export interface ILocalesIndex {
6
+ /**
7
+ * The list of locales.
8
+ */
9
+ locales: ILocale[];
10
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Interface describing a patch operation to add a property.
3
+ */
4
+ export interface IPatchOperation {
5
+ /**
6
+ * The operation that was performed on the item.
7
+ */
8
+ op: "add" | "remove" | "replace" | "move" | "copy" | "test";
9
+ /**
10
+ * The path to the object that was changed.
11
+ */
12
+ path: string;
13
+ /**
14
+ * The path the value was copied or moved from.
15
+ */
16
+ from?: string;
17
+ /**
18
+ * The value to add.
19
+ */
20
+ value?: unknown;
21
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Model to describe the parts of a url.
3
+ */
4
+ export interface IUrlParts {
5
+ /**
6
+ * The schema for the url.
7
+ */
8
+ schema: string;
9
+ /**
10
+ * The host for the url.
11
+ */
12
+ host: string;
13
+ /**
14
+ * The port for the url.
15
+ */
16
+ port?: number;
17
+ /**
18
+ * The path for the url.
19
+ */
20
+ path: string;
21
+ /**
22
+ * The params for the url.
23
+ */
24
+ params?: string;
25
+ /**
26
+ * The hash for the url.
27
+ */
28
+ hash?: string;
29
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Interface describing the reason a validation failed.
3
+ */
4
+ export interface IValidationFailure {
5
+ /**
6
+ * The property that failed validation.
7
+ */
8
+ property: string;
9
+ /**
10
+ * The reason the validation failed as an i18 resource error.
11
+ */
12
+ reason: string;
13
+ /**
14
+ * The optional human readable name for the field as an i18 resource.
15
+ */
16
+ fieldName?: string;
17
+ /**
18
+ * Additional properties for the validation failure.
19
+ */
20
+ properties?: {
21
+ [id: string]: unknown;
22
+ };
23
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Compression types.
3
+ */
4
+ export declare const CompressionType: {
5
+ /**
6
+ * Gzip.
7
+ */
8
+ readonly Gzip: "gzip";
9
+ /**
10
+ * deflate.
11
+ */
12
+ readonly Deflate: "deflate";
13
+ };
14
+ /**
15
+ * Compression types.
16
+ */
17
+ export type CompressionType = (typeof CompressionType)[keyof typeof CompressionType];
@@ -0,0 +1,41 @@
1
+ /**
2
+ * A class to represent a bit string.
3
+ */
4
+ export declare class BitString {
5
+ /**
6
+ * Create a new instance of BitString.
7
+ * @param numberBits The length of the bit string.
8
+ */
9
+ constructor(numberBits: number);
10
+ /**
11
+ * Create a new instance of BitString from a bit array.
12
+ * @param bits The bits to create the bit string from.
13
+ * @param numberBits The number of bits in the bit string.
14
+ * @returns The new instance of BitString.
15
+ */
16
+ static fromBits(bits: Uint8Array, numberBits: number): BitString;
17
+ /**
18
+ * Get the bit at the given index.
19
+ * @param index The index to get the bit for.
20
+ * @returns True if the bit at the index is set.
21
+ * @throws GeneralError if the index is out of range.
22
+ */
23
+ getBit(index: number): boolean;
24
+ /**
25
+ * Set the bit at the given index.
26
+ * @param index The index to set the bit for.
27
+ * @param value The value to set the bit to.
28
+ * @throws GeneralError if the index is out of range.
29
+ */
30
+ setBit(index: number, value: boolean): void;
31
+ /**
32
+ * Get the bits of the bit string.
33
+ * @returns The bits stored in a Uint8Array.
34
+ */
35
+ getBits(): Uint8Array;
36
+ /**
37
+ * Get the length of the bit string.
38
+ * @returns The length of the bit string.
39
+ */
40
+ getLength(): number;
41
+ }
@@ -0,0 +1,56 @@
1
+ import type { IUrlParts } from "../models/IUrlParts";
2
+ import type { IValidationFailure } from "../models/IValidationFailure";
3
+ /**
4
+ * Class to help with urls.
5
+ */
6
+ export declare class Url {
7
+ /**
8
+ * Create a new instance of Url.
9
+ * @param url The url string.
10
+ */
11
+ constructor(url: string);
12
+ /**
13
+ * Try and parse a string into the url parts.
14
+ * @param url The url to parse.
15
+ * @returns The formatted url or undefined if the value is not a url.
16
+ */
17
+ static tryParseExact(url: unknown): Url | undefined;
18
+ /**
19
+ * Parse a string into the url parts.
20
+ * @param source The source of the error.
21
+ * @param property The name of the property.
22
+ * @param value The url to parse.
23
+ * @throws GuardError If the value does not match the assertion.
24
+ */
25
+ static guard(source: string, property: string, value: unknown): asserts value is string;
26
+ /**
27
+ * Validate a string as a Url.
28
+ * @param property Throw an exception if the url property is invalid.
29
+ * @param value The url to parse.
30
+ * @param failures The list of failures to add to.
31
+ * @returns The formatted url.
32
+ */
33
+ static validate(property: string, value: unknown, failures: IValidationFailure[]): value is Url;
34
+ /**
35
+ * Construct a url from a URL.
36
+ * @param url The url to construct from.
37
+ * @returns The formatted url.
38
+ */
39
+ static fromURLToParts(url: URL): IUrlParts;
40
+ /**
41
+ * Construct a url from valid parts.
42
+ * @param urlParts The url to create the parts from.
43
+ * @returns The formatted url.
44
+ */
45
+ static fromParts(urlParts: IUrlParts): Url;
46
+ /**
47
+ * Get the parts of the url.
48
+ * @returns The parts of the url.
49
+ */
50
+ parts(): IUrlParts;
51
+ /**
52
+ * Convert the parts in to a full string.
53
+ * @returns The formatted url.
54
+ */
55
+ toString(): string;
56
+ }
@@ -0,0 +1,93 @@
1
+ import type { IValidationFailure } from "../models/IValidationFailure";
2
+ /**
3
+ * Class to help with urns.
4
+ */
5
+ export declare class Urn {
6
+ /**
7
+ * Create a new instance of Urn.
8
+ * @param namespaceIdentifier The identifier for the namespace.
9
+ * @param namespaceSpecific The specific part of the namespace.
10
+ */
11
+ constructor(namespaceIdentifier: string, namespaceSpecific: string | string[]);
12
+ /**
13
+ * Generate a random identifier with 32 byte id.
14
+ * @param namespace The prefix for the urn.
15
+ * @returns A new Id in URN format.
16
+ */
17
+ static generateRandom(namespace: string): Urn;
18
+ /**
19
+ * Does the provided urn match the namespace.
20
+ * @param urn The urn to check.
21
+ * @param namespace The namespace to match.
22
+ * @returns True if the namespace matches.
23
+ */
24
+ static hasNamespace(urn: string, namespace: string): boolean;
25
+ /**
26
+ * Try and parse a string into the urn parts.
27
+ * @param urn The urn to parse.
28
+ * @returns The formatted urn or undefined if the value is not a urn.
29
+ */
30
+ static tryParseExact(urn: unknown): Urn | undefined;
31
+ /**
32
+ * Construct a urn from a string that has already been validated.
33
+ * @param urn The urn to parse.
34
+ * @returns The formatted urn.
35
+ */
36
+ static fromValidString(urn: string): Urn;
37
+ /**
38
+ * Add a urn: prefix if there isn't one already.
39
+ * @param urn The urn string to add a prefix to.
40
+ * @returns The urn with a prefix.
41
+ */
42
+ static addPrefix(urn: unknown): string | undefined;
43
+ /**
44
+ * Parse a string into the urn parts.
45
+ * @param source The source of the error.
46
+ * @param property The name of the property.
47
+ * @param value The urn to parse.
48
+ * @throws GuardError If the value does not match the assertion.
49
+ */
50
+ static guard(source: string, property: string, value: unknown): asserts value is string;
51
+ /**
52
+ * Validate a string as a Urn.
53
+ * @param property Throw an exception if the urn property is invalid.
54
+ * @param value The urn to parse.
55
+ * @param failures The list of failures to add to.
56
+ * @returns The formatted urn.
57
+ */
58
+ static validate(property: string, value: unknown, failures: IValidationFailure[]): value is string;
59
+ /**
60
+ * Get the parts.
61
+ * @param startIndex The index to start from, defaults to 0.
62
+ * @returns The parts.
63
+ */
64
+ parts(startIndex?: number): string[];
65
+ /**
66
+ * Get the namespace identifier.
67
+ * @returns The namespace identifier.
68
+ */
69
+ namespaceIdentifier(): string;
70
+ /**
71
+ * Get the namespace method, the first component after the identifier.
72
+ * @returns The namespace method.
73
+ */
74
+ namespaceMethod(): string;
75
+ /**
76
+ * Get the namespace specific parts.
77
+ * @param startIndex The index to start from, defaults to 0.
78
+ * @returns The namespace specific parts.
79
+ */
80
+ namespaceSpecificParts(startIndex?: number): string[];
81
+ /**
82
+ * Get the namespace specific.
83
+ * @param startIndex The index to start from, defaults to 0.
84
+ * @returns The namespace specific.
85
+ */
86
+ namespaceSpecific(startIndex?: number): string;
87
+ /**
88
+ * Convert the parts in to a full string.
89
+ * @param omitPrefix Omit the urn: prefix from the string.
90
+ * @returns The formatted urn.
91
+ */
92
+ toString(omitPrefix?: boolean): string;
93
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Cache the results from asynchronous requests.
3
+ */
4
+ export declare class AsyncCache {
5
+ /**
6
+ * Execute an async request and cache the result.
7
+ * @param key The key for the entry in the cache.
8
+ * @param ttlMs The TTL of the entry in the cache.
9
+ * @param requestMethod The method to call if not cached.
10
+ * @returns The response.
11
+ */
12
+ static exec<T = unknown>(key: string, ttlMs: number | undefined, requestMethod: () => Promise<T>): Promise<T> | undefined;
13
+ /**
14
+ * Get an entry from the cache.
15
+ * @param key The key to get from the cache.
16
+ * @returns The item from the cache if it exists.
17
+ */
18
+ static get<T = unknown>(key: string): Promise<T | undefined>;
19
+ /**
20
+ * Remove an entry from the cache.
21
+ * @param key The key to remove from the cache.
22
+ */
23
+ static remove(key: string): void;
24
+ /**
25
+ * Clear the cache.
26
+ * @param prefix Optional prefix to clear only entries with that prefix.
27
+ */
28
+ static clearCache(prefix?: string): void;
29
+ /**
30
+ * Perform a cleanup of the expired entries in the cache.
31
+ */
32
+ static cleanupExpired(): void;
33
+ }
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Coerce an object from one type to another.
3
+ */
4
+ export declare class Coerce {
5
+ /**
6
+ * Coerce the value to a string.
7
+ * @param value The value to coerce.
8
+ * @throws TypeError If the value can not be coerced.
9
+ * @returns The value if it can be coerced.
10
+ */
11
+ static string(value: unknown): string | undefined;
12
+ /**
13
+ * Coerce the value to a number.
14
+ * @param value The value to coerce.
15
+ * @throws TypeError If the value can not be coerced.
16
+ * @returns The value if it can be coerced.
17
+ */
18
+ static number(value: unknown): number | undefined;
19
+ /**
20
+ * Coerce the value to a bigint.
21
+ * @param value The value to coerce.
22
+ * @throws TypeError If the value can not be coerced.
23
+ * @returns The value if it can be coerced.
24
+ */
25
+ static bigint(value: unknown): bigint | undefined;
26
+ /**
27
+ * Coerce the value to a boolean.
28
+ * @param value The value to coerce.
29
+ * @throws TypeError If the value can not be coerced.
30
+ * @returns The value if it can be coerced.
31
+ */
32
+ static boolean(value: unknown): boolean | undefined;
33
+ /**
34
+ * Coerce the value to a date.
35
+ * @param value The value to coerce.
36
+ * @throws TypeError If the value can not be coerced.
37
+ * @returns The value if it can be coerced.
38
+ */
39
+ static date(value: unknown): Date | undefined;
40
+ /**
41
+ * Coerce the value to a date/time.
42
+ * @param value The value to coerce.
43
+ * @throws TypeError If the value can not be coerced.
44
+ * @returns The value if it can be coerced.
45
+ */
46
+ static dateTime(value: unknown): Date | undefined;
47
+ /**
48
+ * Coerce the value to a time.
49
+ * @param value The value to coerce.
50
+ * @throws TypeError If the value can not be coerced.
51
+ * @returns The value if it can be coerced.
52
+ */
53
+ static time(value: unknown): Date | undefined;
54
+ /**
55
+ * Coerce the value to an object.
56
+ * @param value The value to coerce.
57
+ * @throws TypeError If the value can not be coerced.
58
+ * @returns The value if it can be coerced.
59
+ */
60
+ static object<T = unknown>(value: unknown): T | undefined;
61
+ }
@@ -0,0 +1,20 @@
1
+ import { CompressionType } from "../models/compressionType";
2
+ /**
3
+ * A class to handle compression.
4
+ */
5
+ export declare class Compression {
6
+ /**
7
+ * Compress bytes using GZIP.
8
+ * @param bytes The bytes to compress.
9
+ * @param type The type of compression to use.
10
+ * @returns The compressed bytes.
11
+ */
12
+ static compress(bytes: Uint8Array, type: CompressionType): Promise<Uint8Array>;
13
+ /**
14
+ * Decompress a gzipped compressed byte array.
15
+ * @param compressedBytes The compressed bytes.
16
+ * @param type The type of compression to use.
17
+ * @returns The decompressed bytes.
18
+ */
19
+ static decompress(compressedBytes: Uint8Array, type: CompressionType): Promise<Uint8Array>;
20
+ }