@twin.org/core 0.0.3-next.21 → 0.0.3-next.23
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/README.md +1 -9
- package/dist/es/encoding/base32.js +1 -1
- package/dist/es/encoding/base32.js.map +1 -1
- package/dist/es/factories/factory.js +1 -13
- package/dist/es/factories/factory.js.map +1 -1
- package/dist/es/helpers/arrayHelper.js.map +1 -1
- package/dist/es/index.js +2 -1
- package/dist/es/index.js.map +1 -1
- package/dist/es/types/objectOrArray.js.map +1 -0
- package/dist/es/types/singleOccurrenceArray.js +2 -0
- package/dist/es/types/singleOccurrenceArray.js.map +1 -0
- package/dist/es/utils/guards.js.map +1 -1
- package/dist/types/encoding/base32.d.ts +1 -1
- package/dist/types/factories/factory.d.ts +1 -5
- package/dist/types/helpers/arrayHelper.d.ts +1 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/types/singleOccurrenceArray.d.ts +9 -0
- package/dist/types/utils/guards.d.ts +1 -1
- package/docs/changelog.md +36 -1
- package/docs/examples.md +308 -1
- package/docs/reference/classes/AlreadyExistsError.md +18 -18
- package/docs/reference/classes/ArrayHelper.md +2 -2
- package/docs/reference/classes/AsyncCache.md +6 -6
- package/docs/reference/classes/Base32.md +4 -4
- package/docs/reference/classes/Base58.md +3 -3
- package/docs/reference/classes/Base64.md +4 -4
- package/docs/reference/classes/Base64Url.md +3 -3
- package/docs/reference/classes/BaseError.md +17 -17
- package/docs/reference/classes/BitString.md +6 -6
- package/docs/reference/classes/Coerce.md +11 -11
- package/docs/reference/classes/Compression.md +3 -3
- package/docs/reference/classes/ConflictError.md +18 -18
- package/docs/reference/classes/Converter.md +18 -18
- package/docs/reference/classes/EnvHelper.md +1 -1
- package/docs/reference/classes/ErrorHelper.md +3 -3
- package/docs/reference/classes/Factory.md +21 -31
- package/docs/reference/classes/FilenameHelper.md +1 -1
- package/docs/reference/classes/GeneralError.md +18 -18
- package/docs/reference/classes/GuardError.md +18 -18
- package/docs/reference/classes/Guards.md +31 -31
- package/docs/reference/classes/HexHelper.md +6 -6
- package/docs/reference/classes/I18n.md +14 -14
- package/docs/reference/classes/Is.md +40 -40
- package/docs/reference/classes/JsonHelper.md +8 -8
- package/docs/reference/classes/NotFoundError.md +18 -18
- package/docs/reference/classes/NotImplementedError.md +18 -18
- package/docs/reference/classes/NotSupportedError.md +18 -18
- package/docs/reference/classes/NumberHelper.md +2 -2
- package/docs/reference/classes/ObjectHelper.md +20 -20
- package/docs/reference/classes/RandomHelper.md +6 -6
- package/docs/reference/classes/SharedStore.md +3 -3
- package/docs/reference/classes/StringHelper.md +23 -23
- package/docs/reference/classes/Uint8ArrayHelper.md +1 -1
- package/docs/reference/classes/UnauthorizedError.md +18 -18
- package/docs/reference/classes/UnprocessableError.md +18 -18
- package/docs/reference/classes/Url.md +8 -8
- package/docs/reference/classes/Urn.md +22 -22
- package/docs/reference/classes/Validation.md +25 -25
- package/docs/reference/classes/ValidationError.md +18 -18
- package/docs/reference/index.md +2 -0
- package/docs/reference/interfaces/IComponent.md +4 -4
- package/docs/reference/interfaces/IError.md +6 -6
- package/docs/reference/interfaces/II18nShared.md +4 -4
- package/docs/reference/interfaces/IKeyValue.md +2 -2
- package/docs/reference/interfaces/ILabelledValue.md +2 -2
- package/docs/reference/interfaces/ILocale.md +2 -2
- package/docs/reference/interfaces/ILocalesIndex.md +1 -1
- package/docs/reference/interfaces/IPatchOperation.md +4 -4
- package/docs/reference/interfaces/IUrlParts.md +6 -6
- package/docs/reference/interfaces/IValidationFailure.md +3 -3
- package/docs/reference/type-aliases/SingleOccurrenceArray.md +15 -0
- package/docs/reference/type-aliases/SingleOccurrenceArrayDepthHelper.md +19 -0
- package/docs/reference/variables/CoerceType.md +10 -10
- package/docs/reference/variables/CompressionType.md +2 -2
- package/package.json +4 -4
- package/dist/es/models/objectOrArray.js.map +0 -1
- /package/dist/es/{models → types}/objectOrArray.js +0 -0
- /package/dist/types/{models → types}/objectOrArray.d.ts +0 -0
package/README.md
CHANGED
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
# TWIN Framework Core
|
|
2
2
|
|
|
3
|
-
This package
|
|
4
|
-
|
|
5
|
-
- Guards
|
|
6
|
-
- Type Checking
|
|
7
|
-
- Error Handling
|
|
8
|
-
- Validation
|
|
9
|
-
- Encoding
|
|
10
|
-
- Conversion
|
|
11
|
-
- Localisation
|
|
3
|
+
This package is part of the framework workspace and provides helper methods/classes for data type checking/validation/guarding/error handling to support consistent development workflows across the ecosystem.
|
|
12
4
|
|
|
13
5
|
## Installation
|
|
14
6
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base32.js","sourceRoot":"","sources":["../../../src/encoding/base32.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,+BAA+B;AAG/B,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C;;GAEG;AACH,MAAM,OAAO,MAAM;IAClB;;OAEG;IACI,MAAM,CAAU,UAAU,YAA4B;IAE7D;;;OAGG;IACK,MAAM,CAAU,SAAS,GAAW,kCAAkC,CAAC;IAE/E;;;;;OAKG;IACI,MAAM,CAAC,MAAM,CAAC,MAAc;QAClC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,YAAkB,MAAM,CAAC,CAAC;QAEzD,IAAI,IAAI,GAAG,CAAC,CAAC;QACb,IAAI,KAAK,GAAG,CAAC,CAAC;QAEd,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAEnC,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAEnE,KAAK,IAAI,CAAC,GAAG,CAAC,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AAC,CAAC,KAAK,KAAK,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;gBACxD,IAAI,IAAI,CAAC,CAAC;YACX,CAAC;QACF,CAAC;QAED,IAAI,IAAI,GAAG,CAAC,EAAE,CAAC;YACd,MAAM,IAAI,MAAM,CAAC,SAAS,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;QACxD,CAAC;QAED,OAAO,MAAM,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YAChC,MAAM,IAAI,GAAG,CAAC;QACf,CAAC;QAED,OAAO,MAAM,CAAC;IACf,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n/* eslint-disable no-bitwise */\n\nimport { nameof } from \"@twin.org/nameof\";\nimport { GeneralError } from \"../errors/generalError.js\";\nimport { Guards } from \"../utils/guards.js\";\n\n/**\n * Class to help with
|
|
1
|
+
{"version":3,"file":"base32.js","sourceRoot":"","sources":["../../../src/encoding/base32.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,+BAA+B;AAG/B,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C;;GAEG;AACH,MAAM,OAAO,MAAM;IAClB;;OAEG;IACI,MAAM,CAAU,UAAU,YAA4B;IAE7D;;;OAGG;IACK,MAAM,CAAU,SAAS,GAAW,kCAAkC,CAAC;IAE/E;;;;;OAKG;IACI,MAAM,CAAC,MAAM,CAAC,MAAc;QAClC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,YAAkB,MAAM,CAAC,CAAC;QAEzD,IAAI,IAAI,GAAG,CAAC,CAAC;QACb,IAAI,KAAK,GAAG,CAAC,CAAC;QAEd,MAAM,GAAG,MAAM,CAAC,OAAO,C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G,KAAK,CAAC,UAAU,EAAE,CAAC,EAAE,EAAE,CAAC;YAC3C,KAAK,GAAG,CAAC,KAAK,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;YAChC,IAAI,IAAI,CAAC,CAAC;YAEV,OAAO,IAAI,IAAI,CAAC,EAAE,CAAC;gBAClB,MAAM,IAAI,MAAM,CAAC,SAAS,CAAC,CAAC,KAAK,KAAK,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;gBACxD,IAAI,IAAI,CAAC,CAAC;YACX,CAAC;QACF,CAAC;QAED,IAAI,IAAI,GAAG,CAAC,EAAE,CAAC;YACd,MAAM,IAAI,MAAM,CAAC,SAAS,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;QACxD,CAAC;QAED,OAAO,MAAM,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YAChC,MAAM,IAAI,GAAG,CAAC;QACf,CAAC;QAED,OAAO,MAAM,CAAC;IACf,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n/* eslint-disable no-bitwise */\n\nimport { nameof } from \"@twin.org/nameof\";\nimport { GeneralError } from \"../errors/generalError.js\";\nimport { Guards } from \"../utils/guards.js\";\n\n/**\n * Class to help with base32 Encoding/Decoding.\n */\nexport class Base32 {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<Base32>();\n\n\t/**\n\t * Alphabet table for encoding.\n\t * @internal\n\t */\n\tprivate static readonly _ALPHABET: string = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567\";\n\n\t/**\n\t * Convert the base 32 string to a byte array.\n\t * @param base32 The base32 string to convert.\n\t * @returns The byte array.\n\t * @throws If the input string contains a character not in the Base32 alphabet.\n\t */\n\tpublic static decode(base32: string): Uint8Array {\n\t\tGuards.string(Base32.CLASS_NAME, nameof(base32), base32);\n\n\t\tlet bits = 0;\n\t\tlet value = 0;\n\n\t\tbase32 = base32.replace(/=+$/, \"\");\n\n\t\tlet index = 0;\n\t\tconst output = new Uint8Array(Math.trunc((base32.length * 5) / 8));\n\n\t\tfor (let i = 0; i < base32.length; i++) {\n\t\t\tconst idx = Base32._ALPHABET.indexOf(base32[i]);\n\n\t\t\tif (idx === -1) {\n\t\t\t\tthrow new GeneralError(Base32.CLASS_NAME, \"invalidCharacter\", {\n\t\t\t\t\tinvalidCharacter: base32[i]\n\t\t\t\t});\n\t\t\t}\n\t\t\tvalue = (value << 5) | idx;\n\t\t\tbits += 5;\n\n\t\t\tif (bits >= 8) {\n\t\t\t\toutput[index++] = (value >>> (bits - 8)) & 255;\n\t\t\t\tbits -= 8;\n\t\t\t}\n\t\t}\n\n\t\treturn output;\n\t}\n\n\t/**\n\t * Convert a byte array to base 32.\n\t * @param bytes The byte array to convert.\n\t * @returns The data as base32 string.\n\t */\n\tpublic static encode(bytes: Uint8Array): string {\n\t\tGuards.uint8Array(Base32.CLASS_NAME, nameof(bytes), bytes);\n\n\t\tlet bits = 0;\n\t\tlet value = 0;\n\t\tlet output = \"\";\n\n\t\tfor (let i = 0; i < bytes.byteLength; i++) {\n\t\t\tvalue = (value << 8) | bytes[i];\n\t\t\tbits += 8;\n\n\t\t\twhile (bits >= 5) {\n\t\t\t\toutput += Base32._ALPHABET[(value >>> (bits - 5)) & 31];\n\t\t\t\tbits -= 5;\n\t\t\t}\n\t\t}\n\n\t\tif (bits > 0) {\n\t\t\toutput += Base32._ALPHABET[(value << (5 - bits)) & 31];\n\t\t}\n\n\t\twhile (output.length % 8 !== 0) {\n\t\t\toutput += \"=\";\n\t\t}\n\n\t\treturn output;\n\t}\n}\n"]}
|
|
@@ -110,26 +110,14 @@ export class Factory {
|
|
|
110
110
|
* Register a new generator.
|
|
111
111
|
* @param name The name of the generator.
|
|
112
112
|
* @param generator The function to create an instance.
|
|
113
|
-
* @param options Options for the generator.
|
|
114
|
-
* @param options.isDefault Whether the generator is the default one i.e. should be the first generator.
|
|
115
113
|
*/
|
|
116
|
-
register(name, generator
|
|
114
|
+
register(name, generator) {
|
|
117
115
|
Guards.stringValue(Factory.CLASS_NAME, "name", name);
|
|
118
116
|
Guards.function(Factory.CLASS_NAME, "generator", generator);
|
|
119
117
|
this._generators[name] = {
|
|
120
118
|
generator,
|
|
121
119
|
order: this._orderCounter++
|
|
122
120
|
};
|
|
123
|
-
// If this is the default generator, we want to make sure it
|
|
124
|
-
// is the first one by resetting the order of all generators.
|
|
125
|
-
if (options?.isDefault ?? false) {
|
|
126
|
-
let lowestOrder = 0;
|
|
127
|
-
for (const generatorName in this._generators) {
|
|
128
|
-
lowestOrder = Math.min(lowestOrder, this._generators[generatorName].order);
|
|
129
|
-
this._generators[generatorName].order++;
|
|
130
|
-
}
|
|
131
|
-
this._generators[name].order = lowestOrder;
|
|
132
|
-
}
|
|
133
121
|
// Remove any existing instance
|
|
134
122
|
this.removeInstance(name);
|
|
135
123
|
if (this._autoInstance) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../src/factories/factory.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD;;GAEG;AACH,MAAM,OAAO,OAAO;IACnB;;OAEG;IACI,MAAM,CAAU,UAAU,aAAsC;IAEvE;;;OAGG;IACc,SAAS,CAAS;IAEnC;;;OAGG;IACK,WAAW,CAKjB;IAEF;;;OAGG;IACK,UAAU,CAAwB;IAE1C;;;OAGG;IACK,aAAa,CAAS;IAE9B;;;OAGG;IACc,aAAa,CAAU;IAExC;;;OAGG;IAC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CAAC,QAAQ,CAAC,CAAC;IAChF,CAAC;IAED;;;OAGG;IACI,KAAK;QACX,MAAM,YAAY,GAAsC,EAAE,CAAC;QAC3D,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YAC1C,YAAY,CAAC,IAAI,CAAC;gBACjB,IAAI,EAAE,SAAS;gBACf,KAAK,EAAE,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,KAAK;aACxC,CAAC,CAAC;QACJ,CAAC;QACD,OAAO,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IACxE,CAAC;IAED;;;;OAIG;IACI,OAAO,CAAC,IAAY;QAC1B,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,UAAU,UAAgB,IAAI,CAAC,CAAC;QAC3D,OAAO,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC;IAC3E,CAAC;IAED;;;;OAIG;IACK,cAAc,CAAC,IAAY;QAClC,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;IAED;;;;;;OAMG;IACK,cAAc,CAAC,KAAe,EAAE,IAAY;QACnD,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;IAClD,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { nameof } from \"@twin.org/nameof\";\nimport { GeneralError } from \"../errors/generalError.js\";\nimport { Guards } from \"../utils/guards.js\";\nimport { Is } from \"../utils/is.js\";\nimport { SharedStore } from \"../utils/sharedStore.js\";\n\n/**\n * Factory for creating implementation of generic types.\n */\nexport class Factory<T> {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<Factory<unknown>>();\n\n\t/**\n\t * Type name for the instances.\n\t * @internal\n\t */\n\tprivate readonly _typeName: string;\n\n\t/**\n\t * Store the generators.\n\t * @internal\n\t */\n\tprivate _generators: {\n\t\t[name: string]: {\n\t\t\tgenerator: (args?: unknown) => T;\n\t\t\torder: number;\n\t\t};\n\t};\n\n\t/**\n\t * Store the created instances.\n\t * @internal\n\t */\n\tprivate _instances: { [name: string]: T };\n\n\t/**\n\t * Counter for the ordering.\n\t * @internal\n\t */\n\tprivate _orderCounter: number;\n\n\t/**\n\t * Automatically created an instance when registered.\n\t * @internal\n\t */\n\tprivate readonly _autoInstance: boolean;\n\n\t/**\n\t * Match the name of the instance.\n\t * @internal\n\t */\n\tprivate readonly _matcher: (names: string[], name: string) => string | undefined;\n\n\t/**\n\t * Create a new instance of Factory, private use createFactory.\n\t * @param typeName The type name for the instances.\n\t * @param autoInstance Automatically create an instance when registered.\n\t * @param matcher Match the name of the instance.\n\t * @internal\n\t */\n\tprivate constructor(\n\t\ttypeName: string,\n\t\tautoInstance: boolean = false,\n\t\tmatcher?: (names: string[], name: string) => string | undefined\n\t) {\n\t\tthis._typeName = typeName;\n\t\tthis._generators = {};\n\t\tthis._instances = {};\n\t\tthis._orderCounter = 0;\n\t\tthis._autoInstance = autoInstance;\n\t\tthis._matcher = matcher ?? this.defaultMatcher.bind(this);\n\t}\n\n\t/**\n\t * Create a new factory, which is shared throughout all library instances.\n\t * @param typeName The type name for the instances.\n\t * @param autoInstance Automatically create an instance when registered.\n\t * @param matcher Match the name of the instance.\n\t * @returns The factory instance.\n\t */\n\tpublic static createFactory<U>(\n\t\ttypeName: string,\n\t\tautoInstance: boolean = false,\n\t\tmatcher?: (names: string[], name: string) => string | undefined\n\t): Factory<U> {\n\t\tconst factories = Factory.getFactories();\n\n\t\tif (Is.undefined(factories[typeName])) {\n\t\t\tfactories[typeName] = new Factory<U>(typeName, autoInstance, matcher);\n\t\t}\n\t\treturn factories[typeName] as Factory<U>;\n\t}\n\n\t/**\n\t * Get all the factories.\n\t * @returns All the factories.\n\t */\n\tpublic static getFactories(): { [typeName: string]: Factory<unknown> } {\n\t\tlet factories = SharedStore.get<{\n\t\t\t[typeName: string]: Factory<unknown>;\n\t\t}>(\"factories\");\n\n\t\tif (Is.undefined(factories)) {\n\t\t\tfactories = {};\n\t\t\tSharedStore.set(\"factories\", factories);\n\t\t}\n\n\t\treturn factories;\n\t}\n\n\t/**\n\t * Reset all the factories, which removes any created instances, but not the registrations.\n\t */\n\tpublic static resetFactories(): void {\n\t\tconst factories = Factory.getFactories();\n\n\t\tfor (const typeName in factories) {\n\t\t\tfactories[typeName].reset();\n\t\t}\n\t}\n\n\t/**\n\t * Clear all the factories, which removes anything registered with the factories.\n\t */\n\tpublic static clearFactories(): void {\n\t\tconst factories = Factory.getFactories();\n\n\t\tfor (const typeName in factories) {\n\t\t\tfactories[typeName].clear();\n\t\t}\n\t}\n\n\t/**\n\t * Get the type name of the factory.\n\t * @returns The type name of the factory.\n\t */\n\tpublic typeName(): string {\n\t\treturn this._typeName;\n\t}\n\n\t/**\n\t * Register a new generator.\n\t * @param name The name of the generator.\n\t * @param generator The function to create an instance.\n\t * @param options Options for the generator.\n\t * @param options.isDefault Whether the generator is the default one i.e. should be the first generator.\n\t */\n\tpublic register<U extends T>(\n\t\tname: string,\n\t\tgenerator: (args?: unknown) => U,\n\t\toptions?: { isDefault?: boolean }\n\t): void {\n\t\tGuards.stringValue(Factory.CLASS_NAME, nameof(name), name);\n\t\tGuards.function(Factory.CLASS_NAME, nameof(generator), generator);\n\t\tthis._generators[name] = {\n\t\t\tgenerator,\n\t\t\torder: this._orderCounter++\n\t\t};\n\n\t\t// If this is the default generator, we want to make sure it\n\t\t// is the first one by resetting the order of all generators.\n\t\tif (options?.isDefault ?? false) {\n\t\t\tlet lowestOrder = 0;\n\t\t\tfor (const generatorName in this._generators) {\n\t\t\t\tlowestOrder = Math.min(lowestOrder, this._generators[generatorName].order);\n\t\t\t\tthis._generators[generatorName].order++;\n\t\t\t}\n\n\t\t\tthis._generators[name].order = lowestOrder;\n\t\t}\n\n\t\t// Remove any existing instance\n\t\tthis.removeInstance(name);\n\t\tif (this._autoInstance) {\n\t\t\tthis._instances[name] = generator();\n\t\t}\n\t}\n\n\t/**\n\t * Unregister a generator.\n\t * @param name The name of the generator to unregister.\n\t * @throws GuardError if the parameters are invalid.\n\t * @throws GeneralError if no generator exists.\n\t */\n\tpublic unregister(name: string): void {\n\t\tGuards.stringValue(Factory.CLASS_NAME, nameof(name), name);\n\t\tif (!this._generators[name]) {\n\t\t\tthrow new GeneralError(Factory.CLASS_NAME, \"noUnregister\", {\n\t\t\t\ttypeName: this._typeName,\n\t\t\t\tname\n\t\t\t});\n\t\t}\n\t\tdelete this._generators[name];\n\t\t// Remove any existing instance\n\t\tthis.removeInstance(name);\n\t}\n\n\t/**\n\t * Get a generator instance.\n\t * @param name The name of the instance to generate.\n\t * @returns An instance of the item.\n\t * @throws GuardError if the parameters are invalid.\n\t * @throws GeneralError if no item exists to get.\n\t */\n\tpublic get<U extends T>(name: string): U {\n\t\tGuards.stringValue(Factory.CLASS_NAME, nameof(name), name);\n\t\tconst instance = this.getIfExists(name);\n\t\tif (!instance) {\n\t\t\tthrow new GeneralError(Factory.CLASS_NAME, \"noGet\", {\n\t\t\t\ttypeName: this._typeName,\n\t\t\t\tname\n\t\t\t});\n\t\t}\n\t\treturn instance as U;\n\t}\n\n\t/**\n\t * Get a generator instance with no exceptions.\n\t * @param name The name of the instance to generate.\n\t * @returns An instance of the item or undefined if it does not exist.\n\t */\n\tpublic getIfExists<U extends T>(name?: string): U | undefined {\n\t\tif (Is.empty(name)) {\n\t\t\treturn;\n\t\t}\n\t\tGuards.stringValue(Factory.CLASS_NAME, nameof(name), name);\n\n\t\tconst matchName = this._matcher(Object.keys(this._generators), name);\n\n\t\tif (Is.stringValue(matchName) && this._generators[matchName]) {\n\t\t\tif (!this._instances[matchName]) {\n\t\t\t\tthis._instances[matchName] = this._generators[matchName].generator();\n\t\t\t}\n\t\t\tif (this._instances[matchName]) {\n\t\t\t\treturn this._instances[matchName] as U;\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Create a new instance without caching it.\n\t * @param name The name of the instance to generate.\n\t * @param args The arguments to pass to the generator.\n\t * @returns A new instance of the item.\n\t * @throws GuardError if the parameters are invalid.\n\t * @throws GeneralError if no item exists to create.\n\t */\n\tpublic create<U extends T>(name: string, args?: unknown): U {\n\t\tGuards.stringValue(Factory.CLASS_NAME, nameof(name), name);\n\t\tconst instance = this.createIfExists(name, args);\n\t\tif (!instance) {\n\t\t\tthrow new GeneralError(Factory.CLASS_NAME, \"noCreate\", {\n\t\t\t\ttypeName: this._typeName,\n\t\t\t\tname,\n\t\t\t\targs: Is.undefined(args) ? \"\" : JSON.stringify(args)\n\t\t\t});\n\t\t}\n\t\treturn instance as U;\n\t}\n\n\t/**\n\t * Create a new instance without caching it if it exists.\n\t * @param name The name of the instance to generate.\n\t * @param args The arguments to pass to the generator.\n\t * @returns A new instance of the item if it exists.\n\t * @throws GuardError if the parameters are invalid.\n\t */\n\tpublic createIfExists<U extends T>(name: string, args?: unknown): U | undefined {\n\t\tGuards.stringValue(Factory.CLASS_NAME, nameof(name), name);\n\t\tconst matchName = this._matcher(Object.keys(this._generators), name);\n\n\t\tif (Is.stringValue(matchName) && this._generators[matchName]) {\n\t\t\treturn this._generators[matchName].generator(args) as U;\n\t\t}\n\t}\n\n\t/**\n\t * Remove all the instances and leave the generators intact.\n\t */\n\tpublic reset(): void {\n\t\tfor (const name in this._generators) {\n\t\t\tthis.removeInstance(name);\n\t\t}\n\t\tthis._instances = {};\n\t}\n\n\t/**\n\t * Remove all the instances and the generators.\n\t */\n\tpublic clear(): void {\n\t\tthis._instances = {};\n\t\tthis._generators = {};\n\t\tthis._orderCounter = 0;\n\t}\n\n\t/**\n\t * Get all the instances as a map.\n\t * @returns The instances as a map.\n\t */\n\tpublic instancesMap(): { [name: string]: T } {\n\t\treturn this._instances;\n\t}\n\n\t/**\n\t * Get all the instances as a list in the order they were registered.\n\t * @returns The instances as a list in the order they were registered.\n\t */\n\tpublic instancesList(): T[] {\n\t\tconst orderedInstances: { instance: T; order: number }[] = [];\n\t\tfor (const instanceName in this._instances) {\n\t\t\torderedInstances.push({\n\t\t\t\tinstance: this._instances[instanceName],\n\t\t\t\torder: this._generators[instanceName].order\n\t\t\t});\n\t\t}\n\t\treturn orderedInstances.sort((a, b) => a.order - b.order).map(o => o.instance);\n\t}\n\n\t/**\n\t * Get all the generator names in the order they were registered.\n\t * @returns The ordered generator names.\n\t */\n\tpublic names(): string[] {\n\t\tconst orderedNames: { name: string; order: number }[] = [];\n\t\tfor (const generator in this._generators) {\n\t\t\torderedNames.push({\n\t\t\t\tname: generator,\n\t\t\t\torder: this._generators[generator].order\n\t\t\t});\n\t\t}\n\t\treturn orderedNames.sort((a, b) => a.order - b.order).map(o => o.name);\n\t}\n\n\t/**\n\t * Does the factory contain the name.\n\t * @param name The name of the instance to find.\n\t * @returns True if the factory has a matching name.\n\t */\n\tpublic hasName(name: string): boolean {\n\t\tGuards.stringValue(Factory.CLASS_NAME, nameof(name), name);\n\t\treturn Is.stringValue(this._matcher(Object.keys(this._generators), name));\n\t}\n\n\t/**\n\t * Remove any instances of the given name.\n\t * @param name The name of the instances to remove.\n\t * @internal\n\t */\n\tprivate removeInstance(name: string): void {\n\t\tdelete this._instances[name];\n\t}\n\n\t/**\n\t * Match the requested name to the generator name.\n\t * @param names The list of names for all the generators.\n\t * @param name The name to match.\n\t * @returns The matched name or undefined if no match.\n\t * @internal\n\t */\n\tprivate defaultMatcher(names: string[], name: string): string | undefined {\n\t\treturn this._generators[name] ? name : undefined;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","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CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;IAChF,CAAC;IAED;;;OAGG;IACI,KAAK;QACX,MAAM,YAAY,GAAsC,EAAE,CAAC;QAC3D,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YAC1C,YAAY,CAAC,IAAI,CAAC;gBACjB,IAAI,EAAE,SAAS;gBACf,KAAK,EAAE,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,KAAK;aACxC,CAAC,CAAC;QACJ,CAAC;QACD,OAAO,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IACxE,CAAC;IAED;;;;OAIG;IACI,OAAO,CAAC,IAAY;QAC1B,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,UAAU,UAAgB,IAAI,CAAC,CAAC;QAC3D,OAAO,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC;IAC3E,CAAC;IAED;;;;OAIG;IACK,cAAc,CAAC,IAAY;QAClC,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;IAED;;;;;;OAMG;IACK,cAAc,CAAC,KAAe,EAAE,IAAY;QACnD,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;IAClD,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { nameof } from \"@twin.org/nameof\";\nimport { GeneralError } from \"../errors/generalError.js\";\nimport { Guards } from \"../utils/guards.js\";\nimport { Is } from \"../utils/is.js\";\nimport { SharedStore } from \"../utils/sharedStore.js\";\n\n/**\n * Factory for creating implementation of generic types.\n */\nexport class Factory<T> {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<Factory<unknown>>();\n\n\t/**\n\t * Type name for the instances.\n\t * @internal\n\t */\n\tprivate readonly _typeName: string;\n\n\t/**\n\t * Store the generators.\n\t * @internal\n\t */\n\tprivate _generators: {\n\t\t[name: string]: {\n\t\t\tgenerator: (args?: unknown) => T;\n\t\t\torder: number;\n\t\t};\n\t};\n\n\t/**\n\t * Store the created instances.\n\t * @internal\n\t */\n\tprivate _instances: { [name: string]: T };\n\n\t/**\n\t * Counter for the ordering.\n\t * @internal\n\t */\n\tprivate _orderCounter: number;\n\n\t/**\n\t * Automatically created an instance when registered.\n\t * @internal\n\t */\n\tprivate readonly _autoInstance: boolean;\n\n\t/**\n\t * Match the name of the instance.\n\t * @internal\n\t */\n\tprivate readonly _matcher: (names: string[], name: string) => string | undefined;\n\n\t/**\n\t * Create a new instance of Factory, private use createFactory.\n\t * @param typeName The type name for the instances.\n\t * @param autoInstance Automatically create an instance when registered.\n\t * @param matcher Match the name of the instance.\n\t * @internal\n\t */\n\tprivate constructor(\n\t\ttypeName: string,\n\t\tautoInstance: boolean = false,\n\t\tmatcher?: (names: string[], name: string) => string | undefined\n\t) {\n\t\tthis._typeName = typeName;\n\t\tthis._generators = {};\n\t\tthis._instances = {};\n\t\tthis._orderCounter = 0;\n\t\tthis._autoInstance = autoInstance;\n\t\tthis._matcher = matcher ?? this.defaultMatcher.bind(this);\n\t}\n\n\t/**\n\t * Create a new factory, which is shared throughout all library instances.\n\t * @param typeName The type name for the instances.\n\t * @param autoInstance Automatically create an instance when registered.\n\t * @param matcher Match the name of the instance.\n\t * @returns The factory instance.\n\t */\n\tpublic static createFactory<U>(\n\t\ttypeName: string,\n\t\tautoInstance: boolean = false,\n\t\tmatcher?: (names: string[], name: string) => string | undefined\n\t): Factory<U> {\n\t\tconst factories = Factory.getFactories();\n\n\t\tif (Is.undefined(factories[typeName])) {\n\t\t\tfactories[typeName] = new Factory<U>(typeName, autoInstance, matcher);\n\t\t}\n\t\treturn factories[typeName] as Factory<U>;\n\t}\n\n\t/**\n\t * Get all the factories.\n\t * @returns All the factories.\n\t */\n\tpublic static getFactories(): { [typeName: string]: Factory<unknown> } {\n\t\tlet factories = SharedStore.get<{\n\t\t\t[typeName: string]: Factory<unknown>;\n\t\t}>(\"factories\");\n\n\t\tif (Is.undefined(factories)) {\n\t\t\tfactories = {};\n\t\t\tSharedStore.set(\"factories\", factories);\n\t\t}\n\n\t\treturn factories;\n\t}\n\n\t/**\n\t * Reset all the factories, which removes any created instances, but not the registrations.\n\t */\n\tpublic static resetFactories(): void {\n\t\tconst factories = Factory.getFactories();\n\n\t\tfor (const typeName in factories) {\n\t\t\tfactories[typeName].reset();\n\t\t}\n\t}\n\n\t/**\n\t * Clear all the factories, which removes anything registered with the factories.\n\t */\n\tpublic static clearFactories(): void {\n\t\tconst factories = Factory.getFactories();\n\n\t\tfor (const typeName in factories) {\n\t\t\tfactories[typeName].clear();\n\t\t}\n\t}\n\n\t/**\n\t * Get the type name of the factory.\n\t * @returns The type name of the factory.\n\t */\n\tpublic typeName(): string {\n\t\treturn this._typeName;\n\t}\n\n\t/**\n\t * Register a new generator.\n\t * @param name The name of the generator.\n\t * @param generator The function to create an instance.\n\t */\n\tpublic register<U extends T>(name: string, generator: (args?: unknown) => U): void {\n\t\tGuards.stringValue(Factory.CLASS_NAME, nameof(name), name);\n\t\tGuards.function(Factory.CLASS_NAME, nameof(generator), generator);\n\t\tthis._generators[name] = {\n\t\t\tgenerator,\n\t\t\torder: this._orderCounter++\n\t\t};\n\n\t\t// Remove any existing instance\n\t\tthis.removeInstance(name);\n\t\tif (this._autoInstance) {\n\t\t\tthis._instances[name] = generator();\n\t\t}\n\t}\n\n\t/**\n\t * Unregister a generator.\n\t * @param name The name of the generator to unregister.\n\t * @throws GuardError if the parameters are invalid.\n\t * @throws GeneralError if no generator exists.\n\t */\n\tpublic unregister(name: string): void {\n\t\tGuards.stringValue(Factory.CLASS_NAME, nameof(name), name);\n\t\tif (!this._generators[name]) {\n\t\t\tthrow new GeneralError(Factory.CLASS_NAME, \"noUnregister\", {\n\t\t\t\ttypeName: this._typeName,\n\t\t\t\tname\n\t\t\t});\n\t\t}\n\t\tdelete this._generators[name];\n\t\t// Remove any existing instance\n\t\tthis.removeInstance(name);\n\t}\n\n\t/**\n\t * Get a generator instance.\n\t * @param name The name of the instance to generate.\n\t * @returns An instance of the item.\n\t * @throws GuardError if the parameters are invalid.\n\t * @throws GeneralError if no item exists to get.\n\t */\n\tpublic get<U extends T>(name: string): U {\n\t\tGuards.stringValue(Factory.CLASS_NAME, nameof(name), name);\n\t\tconst instance = this.getIfExists(name);\n\t\tif (!instance) {\n\t\t\tthrow new GeneralError(Factory.CLASS_NAME, \"noGet\", {\n\t\t\t\ttypeName: this._typeName,\n\t\t\t\tname\n\t\t\t});\n\t\t}\n\t\treturn instance as U;\n\t}\n\n\t/**\n\t * Get a generator instance with no exceptions.\n\t * @param name The name of the instance to generate.\n\t * @returns An instance of the item or undefined if it does not exist.\n\t */\n\tpublic getIfExists<U extends T>(name?: string): U | undefined {\n\t\tif (Is.empty(name)) {\n\t\t\treturn;\n\t\t}\n\t\tGuards.stringValue(Factory.CLASS_NAME, nameof(name), name);\n\n\t\tconst matchName = this._matcher(Object.keys(this._generators), name);\n\n\t\tif (Is.stringValue(matchName) && this._generators[matchName]) {\n\t\t\tif (!this._instances[matchName]) {\n\t\t\t\tthis._instances[matchName] = this._generators[matchName].generator();\n\t\t\t}\n\t\t\tif (this._instances[matchName]) {\n\t\t\t\treturn this._instances[matchName] as U;\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Create a new instance without caching it.\n\t * @param name The name of the instance to generate.\n\t * @param args The arguments to pass to the generator.\n\t * @returns A new instance of the item.\n\t * @throws GuardError if the parameters are invalid.\n\t * @throws GeneralError if no item exists to create.\n\t */\n\tpublic create<U extends T>(name: string, args?: unknown): U {\n\t\tGuards.stringValue(Factory.CLASS_NAME, nameof(name), name);\n\t\tconst instance = this.createIfExists(name, args);\n\t\tif (!instance) {\n\t\t\tthrow new GeneralError(Factory.CLASS_NAME, \"noCreate\", {\n\t\t\t\ttypeName: this._typeName,\n\t\t\t\tname,\n\t\t\t\targs: Is.undefined(args) ? \"\" : JSON.stringify(args)\n\t\t\t});\n\t\t}\n\t\treturn instance as U;\n\t}\n\n\t/**\n\t * Create a new instance without caching it if it exists.\n\t * @param name The name of the instance to generate.\n\t * @param args The arguments to pass to the generator.\n\t * @returns A new instance of the item if it exists.\n\t * @throws GuardError if the parameters are invalid.\n\t */\n\tpublic createIfExists<U extends T>(name: string, args?: unknown): U | undefined {\n\t\tGuards.stringValue(Factory.CLASS_NAME, nameof(name), name);\n\t\tconst matchName = this._matcher(Object.keys(this._generators), name);\n\n\t\tif (Is.stringValue(matchName) && this._generators[matchName]) {\n\t\t\treturn this._generators[matchName].generator(args) as U;\n\t\t}\n\t}\n\n\t/**\n\t * Remove all the instances and leave the generators intact.\n\t */\n\tpublic reset(): void {\n\t\tfor (const name in this._generators) {\n\t\t\tthis.removeInstance(name);\n\t\t}\n\t\tthis._instances = {};\n\t}\n\n\t/**\n\t * Remove all the instances and the generators.\n\t */\n\tpublic clear(): void {\n\t\tthis._instances = {};\n\t\tthis._generators = {};\n\t\tthis._orderCounter = 0;\n\t}\n\n\t/**\n\t * Get all the instances as a map.\n\t * @returns The instances as a map.\n\t */\n\tpublic instancesMap(): { [name: string]: T } {\n\t\treturn this._instances;\n\t}\n\n\t/**\n\t * Get all the instances as a list in the order they were registered.\n\t * @returns The instances as a list in the order they were registered.\n\t */\n\tpublic instancesList(): T[] {\n\t\tconst orderedInstances: { instance: T; order: number }[] = [];\n\t\tfor (const instanceName in this._instances) {\n\t\t\torderedInstances.push({\n\t\t\t\tinstance: this._instances[instanceName],\n\t\t\t\torder: this._generators[instanceName].order\n\t\t\t});\n\t\t}\n\t\treturn orderedInstances.sort((a, b) => a.order - b.order).map(o => o.instance);\n\t}\n\n\t/**\n\t * Get all the generator names in the order they were registered.\n\t * @returns The ordered generator names.\n\t */\n\tpublic names(): string[] {\n\t\tconst orderedNames: { name: string; order: number }[] = [];\n\t\tfor (const generator in this._generators) {\n\t\t\torderedNames.push({\n\t\t\t\tname: generator,\n\t\t\t\torder: this._generators[generator].order\n\t\t\t});\n\t\t}\n\t\treturn orderedNames.sort((a, b) => a.order - b.order).map(o => o.name);\n\t}\n\n\t/**\n\t * Does the factory contain the name.\n\t * @param name The name of the instance to find.\n\t * @returns True if the factory has a matching name.\n\t */\n\tpublic hasName(name: string): boolean {\n\t\tGuards.stringValue(Factory.CLASS_NAME, nameof(name), name);\n\t\treturn Is.stringValue(this._matcher(Object.keys(this._generators), name));\n\t}\n\n\t/**\n\t * Remove any instances of the given name.\n\t * @param name The name of the instances to remove.\n\t * @internal\n\t */\n\tprivate removeInstance(name: string): void {\n\t\tdelete this._instances[name];\n\t}\n\n\t/**\n\t * Match the requested name to the generator name.\n\t * @param names The list of names for all the generators.\n\t * @param name The name to match.\n\t * @returns The matched name or undefined if no match.\n\t * @internal\n\t */\n\tprivate defaultMatcher(names: string[], name: string): string | undefined {\n\t\treturn this._generators[name] ? name : undefined;\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"arrayHelper.js","sourceRoot":"","sources":["../../../src/helpers/arrayHelper.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAEpC;;GAEG;AACH,MAAM,OAAO,WAAW;IACvB;;;;;OAKG;IACI,MAAM,CAAC,OAAO,CAAC,IAAa,EAAE,IAAa;QACjD,IAAI,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;YACtC,OAAO,IAAI,CAAC;QACb,CAAC;QACD,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;YAC3F,OAAO,KAAK,CAAC;QACd,CAAC;QACD,IAAI,IAAI,CAAC,MAAM,KAAK,IAAI,CAAC,MAAM,EAAE,CAAC;YACjC,OAAO,KAAK,CAAC;QACd,CAAC;QACD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACtC,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;gBACzB,OAAO,KAAK,CAAC;YACd,CAAC;QACF,CAAC;QACD,OAAO,IAAI,CAAC;IACb,CAAC;IAeD;;;;OAIG;IACI,MAAM,CAAC,iBAAiB,CAC9B,KAAmC;QAEnC,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;YACrB,OAAO,SAAS,CAAC;QAClB,CAAC;QACD,IAAI,EAAE,CAAC,KAAK,CAAI,KAAK,CAAC,EAAE,CAAC;YACxB,OAAO,KAAK,CAAC;QACd,CAAC;QACD,OAAO,CAAC,KAAK,CAAC,CAAC;IAChB,CAAC;CACD","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { ObjectOrArray } from \"../
|
|
1
|
+
{"version":3,"file":"arrayHelper.js","sourceRoot":"","sources":["../../../src/helpers/arrayHelper.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAEpC;;GAEG;AACH,MAAM,OAAO,WAAW;IACvB;;;;;OAKG;IACI,MAAM,CAAC,OAAO,CAAC,IAAa,EAAE,IAAa;QACjD,IAAI,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;YACtC,OAAO,IAAI,CAAC;QACb,CAAC;QACD,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;YAC3F,OAAO,KAAK,CAAC;QACd,CAAC;QACD,IAAI,IAAI,CAAC,MAAM,KAAK,IAAI,CAAC,MAAM,EAAE,CAAC;YACjC,OAAO,KAAK,CAAC;QACd,CAAC;QACD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACtC,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;gBACzB,OAAO,KAAK,CAAC;YACd,CAAC;QACF,CAAC;QACD,OAAO,IAAI,CAAC;IACb,CAAC;IAeD;;;;OAIG;IACI,MAAM,CAAC,iBAAiB,CAC9B,KAAmC;QAEnC,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;YACrB,OAAO,SAAS,CAAC;QAClB,CAAC;QACD,IAAI,EAAE,CAAC,KAAK,CAAI,KAAK,CAAC,EAAE,CAAC;YACxB,OAAO,KAAK,CAAC;QACd,CAAC;QACD,OAAO,CAAC,KAAK,CAAC,CAAC;IAChB,CAAC;CACD","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { ObjectOrArray } from \"../types/objectOrArray.js\";\nimport { Is } from \"../utils/is.js\";\n\n/**\n * Class to help with arrays.\n */\nexport class ArrayHelper {\n\t/**\n\t * Do the two arrays match.\n\t * @param arr1 The first array.\n\t * @param arr2 The second array.\n\t * @returns True if both arrays are empty of have the same values.\n\t */\n\tpublic static matches(arr1: unknown, arr2: unknown): boolean {\n\t\tif (Is.empty(arr1) && Is.empty(arr2)) {\n\t\t\treturn true;\n\t\t}\n\t\tif (!((Is.array(arr1) && Is.array(arr2)) || (Is.typedArray(arr1) && Is.typedArray(arr2)))) {\n\t\t\treturn false;\n\t\t}\n\t\tif (arr1.length !== arr2.length) {\n\t\t\treturn false;\n\t\t}\n\t\tfor (let i = 0; i < arr1.length; i++) {\n\t\t\tif (arr1[i] !== arr2[i]) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t * Convert an object or array to an array.\n\t * @param value The object or array to convert.\n\t * @returns The array.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tpublic static fromObjectOrArray<T = unknown>(value: undefined): undefined;\n\t/**\n\t * Convert an object or array to an array.\n\t * @param value The object or array to convert.\n\t * @returns The array.\n\t */\n\tpublic static fromObjectOrArray<T = unknown>(value: ObjectOrArray<T>): T[];\n\t/**\n\t * Convert an object or array to an array.\n\t * @param value The object or array to convert.\n\t * @returns The array.\n\t */\n\tpublic static fromObjectOrArray<T = unknown>(\n\t\tvalue: ObjectOrArray<T> | undefined\n\t): T[] | undefined {\n\t\tif (Is.empty(value)) {\n\t\t\treturn undefined;\n\t\t}\n\t\tif (Is.array<T>(value)) {\n\t\t\treturn value;\n\t\t}\n\t\treturn [value];\n\t}\n}\n"]}
|
package/dist/es/index.js
CHANGED
|
@@ -41,8 +41,9 @@ export * from "./models/ILocalesIndex.js";
|
|
|
41
41
|
export * from "./models/IPatchOperation.js";
|
|
42
42
|
export * from "./models/IUrlParts.js";
|
|
43
43
|
export * from "./models/IValidationFailure.js";
|
|
44
|
-
export * from "./models/objectOrArray.js";
|
|
45
44
|
export * from "./types/bitString.js";
|
|
45
|
+
export * from "./types/objectOrArray.js";
|
|
46
|
+
export * from "./types/singleOccurrenceArray.js";
|
|
46
47
|
export * from "./types/url.js";
|
|
47
48
|
export * from "./types/urn.js";
|
|
48
49
|
export * from "./utils/asyncCache.js";
|
package/dist/es/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iCAAiC,CAAC;AAChD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iCAAiC,CAAC;AAChD,cAAc,wBAAwB,CAAC;AACvC,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,wBAAwB,CAAC;AACvC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,C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cAAc,qBAAqB,CAAC;AACpC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,uBAAuB,CAAC;AACtC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,kCAAkC,CAAC;AACjD,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./encoding/base32.js\";\nexport * from \"./encoding/base58.js\";\nexport * from \"./encoding/base64.js\";\nexport * from \"./encoding/base64Url.js\";\nexport * from \"./errors/alreadyExistsError.js\";\nexport * from \"./errors/baseError.js\";\nexport * from \"./errors/conflictError.js\";\nexport * from \"./errors/generalError.js\";\nexport * from \"./errors/guardError.js\";\nexport * from \"./errors/notFoundError.js\";\nexport * from \"./errors/notImplementedError.js\";\nexport * from \"./errors/notSupportedError.js\";\nexport * from \"./errors/unauthorizedError.js\";\nexport * from \"./errors/unprocessableError.js\";\nexport * from \"./errors/validationError.js\";\nexport * from \"./factories/componentFactory.js\";\nexport * from \"./factories/factory.js\";\nexport * from \"./helpers/arrayHelper.js\";\nexport * from \"./helpers/envHelper.js\";\nexport * from \"./helpers/errorHelper.js\";\nexport * from \"./helpers/filenameHelper.js\";\nexport * from \"./helpers/hexHelper.js\";\nexport * from \"./helpers/jsonHelper.js\";\nexport * from \"./helpers/numberHelper.js\";\nexport * from \"./helpers/objectHelper.js\";\nexport * from \"./helpers/randomHelper.js\";\nexport * from \"./helpers/stringHelper.js\";\nexport * from \"./helpers/uint8ArrayHelper.js\";\nexport * from \"./models/coerceType.js\";\nexport * from \"./models/compressionType.js\";\nexport * from \"./models/IComponent.js\";\nexport * from \"./models/IError.js\";\nexport * from \"./models/II18nShared.js\";\nexport * from \"./models/IKeyValue.js\";\nexport * from \"./models/ILabelledValue.js\";\nexport * from \"./models/ILocale.js\";\nexport * from \"./models/ILocaleDictionary.js\";\nexport * from \"./models/ILocalesIndex.js\";\nexport * from \"./models/IPatchOperation.js\";\nexport * from \"./models/IUrlParts.js\";\nexport * from \"./models/IValidationFailure.js\";\nexport * from \"./types/bitString.js\";\nexport * from \"./types/objectOrArray.js\";\nexport * from \"./types/singleOccurrenceArray.js\";\nexport * from \"./types/url.js\";\nexport * from \"./types/urn.js\";\nexport * from \"./utils/asyncCache.js\";\nexport * from \"./utils/coerce.js\";\nexport * from \"./utils/compression.js\";\nexport * from \"./utils/converter.js\";\nexport * from \"./utils/guards.js\";\nexport * from \"./utils/i18n.js\";\nexport * from \"./utils/is.js\";\nexport * from \"./utils/sharedStore.js\";\nexport * from \"./utils/validation.js\";\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"objectOrArray.js","sourceRoot":"","sources":["../../../src/types/objectOrArray.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n/**\n * Object or array data type\n */\nexport type ObjectOrArray<T = unknown> = T | T[];\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"singleOccurrenceArray.js","sourceRoot":"","sources":["../../../src/types/singleOccurrenceArray.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n/**\n * Helper with bounded recursion depth to keep type instantiation tractable.\n */\nexport type SingleOccurrenceArrayDepthHelper<T, U, Depth extends 0[]> = Depth[\"length\"] extends 16\n\t? [U, ...T[]]\n\t: [U, ...T[]] | [T, ...SingleOccurrenceArrayDepthHelper<T, U, [0, ...Depth]>];\n\n/**\n * Utility type to create a non-empty array with values of type T and exactly one value of type U.\n */\nexport type SingleOccurrenceArray<T = unknown, U = never> = SingleOccurrenceArrayDepthHelper<\n\tT,\n\tU,\n\t[]\n>;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"guards.js","sourceRoot":"","sources":["../../../src/utils/guards.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAGpD;;GAEG;AACH,MAAM,OAAO,MAAM;IAClB;;;;;;OAMG;IACI,MAAM,CAAC,OAAO,CAAC,MAAc,EAAE,QAAgB,EAAE,KAAc;QACrE,IAAI,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;YACzB,MAAM,IAAI,UAAU,CAAC,MAAM,EAAE,iBAAiB,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;QAClE,CAAC;IACF,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,MAAM,CAAC,MAAc,EAAE,QAAgB,EAAE,KAAc;QACpE,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;YACvB,MAAM,IAAI,UAAU,CAAC,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;QAC/D,CAAC;IACF,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,WAAW,CACxB,MAAc,EACd,QAAgB,EAChB,KAAc;QAEd,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAA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,CAAC,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,CAAC;YAC/B,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;gBAC1B,MAAM,IAAI,UAAU,CAAC,MAAM,EAAE,qBAAqB,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;YACtE,CAAC;YACD,MAAM,IAAI,UAAU,CAAC,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;QAC/D,CAAC;IACF,CAAC;CACD","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Is } from \"./is.js\";\nimport { GuardError } from \"../errors/guardError.js\";\nimport { ArrayHelper } from \"../helpers/arrayHelper.js\";\nimport { HexHelper } from \"../helpers/hexHelper.js\";\nimport type { ObjectOrArray } from \"../models/objectOrArray.js\";\n\n/**\n * Class to handle guard operations for parameters.\n */\nexport class Guards {\n\t/**\n\t * Is the property defined.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static defined(source: string, property: string, value: unknown): asserts value {\n\t\tif (Is.undefined(value)) {\n\t\t\tthrow new GuardError(source, \"guard.undefined\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a string.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static string(source: string, property: string, value: unknown): asserts value is string {\n\t\tif (!Is.string(value)) {\n\t\t\tthrow new GuardError(source, \"guard.string\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a string with a value.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static stringValue(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is string {\n\t\tif (!Is.string(value)) {\n\t\t\tthrow new GuardError(source, \"guard.string\", property, value);\n\t\t}\n\t\tif (value.length === 0) {\n\t\t\tthrow new GuardError(source, \"guard.stringEmpty\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a JSON value.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static json(source: string, property: string, value: unknown): asserts value is string {\n\t\tif (!Is.json(value)) {\n\t\t\tthrow new GuardError(source, \"guard.stringJson\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a base64 string.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static stringBase64(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is string {\n\t\tif (!Is.stringBase64(value)) {\n\t\t\tthrow new GuardError(source, \"guard.stringBase64\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a base64 url string.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static stringBase64Url(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is string {\n\t\tif (!Is.stringBase64Url(value)) {\n\t\t\tthrow new GuardError(source, \"guard.stringBase64Url\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a base58 string.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static stringBase58(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is string {\n\t\tif (!Is.stringBase58(value)) {\n\t\t\tthrow new GuardError(source, \"guard.stringBase58\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a string with a hex value.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @param allowPrefix Allow the hex to have the 0x prefix.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static stringHex(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown,\n\t\tallowPrefix: boolean = false\n\t): asserts value is string {\n\t\tGuards.stringValue(source, property, value);\n\t\tif (!HexHelper.isHex(value, allowPrefix)) {\n\t\t\tthrow new GuardError(source, \"guard.stringHex\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a string with a hex value with fixed length.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @param length The length of the string to match.\n\t * @param allowPrefix Allow the hex to have the 0x prefix.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static stringHexLength(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown,\n\t\tlength: number,\n\t\tallowPrefix: boolean = false\n\t): asserts value is string {\n\t\tGuards.stringHex(source, property, value, allowPrefix);\n\t\tif (HexHelper.stripPrefix(value).length !== length) {\n\t\t\tthrow new GuardError(\n\t\t\t\tsource,\n\t\t\t\t\"guard.stringHexLength\",\n\t\t\t\tproperty,\n\t\t\t\tvalue.length,\n\t\t\t\tlength.toString()\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a number.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static number(source: string, property: string, value: unknown): asserts value is number {\n\t\tif (!Is.number(value)) {\n\t\t\tthrow new GuardError(source, \"guard.number\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property an integer.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static integer(source: string, property: string, value: unknown): asserts value is number {\n\t\tif (!Is.integer(value)) {\n\t\t\tthrow new GuardError(source, \"guard.integer\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a bigint.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static bigint(source: string, property: string, value: unknown): asserts value is bigint {\n\t\tif (!Is.bigint(value)) {\n\t\t\tthrow new GuardError(source, \"guard.bigint\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a boolean.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static boolean(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is boolean {\n\t\tif (!Is.boolean(value)) {\n\t\t\tthrow new GuardError(source, \"guard.boolean\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a date.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static date(source: string, property: string, value: unknown): asserts value is Date {\n\t\tif (!Is.date(value)) {\n\t\t\tthrow new GuardError(source, \"guard.date\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a timestamp in milliseconds.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static timestampMilliseconds(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is number {\n\t\tif (!Is.timestampMilliseconds(value)) {\n\t\t\tthrow new GuardError(source, \"guard.timestampMilliseconds\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a timestamp in seconds.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static timestampSeconds(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is number {\n\t\tif (!Is.timestampSeconds(value)) {\n\t\t\tthrow new GuardError(source, \"guard.timestampSeconds\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property an object.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static object<T = { [id: string]: unknown }>(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is T {\n\t\tif (Is.undefined(value)) {\n\t\t\tthrow new GuardError(source, \"guard.objectUndefined\", property, value);\n\t\t}\n\t\tif (!Is.object<T>(value)) {\n\t\t\tthrow new GuardError(source, \"guard.object\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property is an object with at least one property.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static objectValue<T = { [id: string]: unknown }>(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is T {\n\t\tif (Is.undefined(value)) {\n\t\t\tthrow new GuardError(source, \"guard.objectUndefined\", property, value);\n\t\t}\n\t\tif (!Is.object<T>(value)) {\n\t\t\tthrow new GuardError(source, \"guard.object\", property, value);\n\t\t}\n\t\tif (Object.keys(value || {}).length === 0) {\n\t\t\tthrow new GuardError(source, \"guard.objectValue\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property is an array.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static array<T>(source: string, property: string, value: unknown): asserts value is T[] {\n\t\tif (!Is.array<T>(value)) {\n\t\t\tthrow new GuardError(source, \"guard.array\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property is an array with at least one item.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static arrayValue<T>(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is T[] {\n\t\tif (!Is.array(value)) {\n\t\t\tthrow new GuardError(source, \"guard.array\", property, value);\n\t\t}\n\t\tif (value.length === 0) {\n\t\t\tthrow new GuardError(source, \"guard.arrayValue\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property one of a list of items.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @param options The options the value must be one of.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static arrayOneOf<T>(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: T,\n\t\toptions: T[]\n\t): asserts value is T {\n\t\tif (!Is.array<T>(options)) {\n\t\t\tthrow new GuardError(source, \"guard.array\", property, value);\n\t\t}\n\t\tif (!options.includes(value)) {\n\t\t\tthrow new GuardError(source, \"guard.arrayOneOf\", property, value, options.join(\", \"));\n\t\t}\n\t}\n\n\t/**\n\t * Does the array start with the specified data.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @param startValues The values that must start the array.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static arrayStartsWith<T>(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown,\n\t\tstartValues: ObjectOrArray<T>\n\t): asserts value is T[] {\n\t\tif (!Is.arrayValue<T>(value)) {\n\t\t\tthrow new GuardError(source, \"guard.array\", property, value);\n\t\t}\n\n\t\tconst startValuesArray = ArrayHelper.fromObjectOrArray(startValues);\n\n\t\tif (!Is.arrayValue<T>(startValuesArray)) {\n\t\t\tthrow new GuardError(source, \"guard.array\", property, startValuesArray);\n\t\t}\n\n\t\tfor (let i = 0; i < startValuesArray.length; i++) {\n\t\t\tif (value[i] !== startValuesArray[i]) {\n\t\t\t\tthrow new GuardError(\n\t\t\t\t\tsource,\n\t\t\t\t\t\"guard.arrayStartsWith\",\n\t\t\t\t\tproperty,\n\t\t\t\t\tvalue,\n\t\t\t\t\tstartValuesArray.join(\", \")\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Does the array end with the specified data.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @param endValues The values that must end the array.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static arrayEndsWith<T>(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown,\n\t\tendValues: ObjectOrArray<T>\n\t): asserts value is T[] {\n\t\tif (!Is.arrayValue<T>(value)) {\n\t\t\tthrow new GuardError(source, \"guard.array\", property, value);\n\t\t}\n\n\t\tconst endValuesArray = ArrayHelper.fromObjectOrArray(endValues);\n\n\t\tif (!Is.arrayValue<T>(endValuesArray)) {\n\t\t\tthrow new GuardError(source, \"guard.array\", property, endValuesArray);\n\t\t}\n\n\t\tfor (let i = 0; i < endValuesArray.length; i++) {\n\t\t\tif (value[value.length - i - 1] !== endValuesArray[endValuesArray.length - i - 1]) {\n\t\t\t\tthrow new GuardError(\n\t\t\t\t\tsource,\n\t\t\t\t\t\"guard.arrayEndsWith\",\n\t\t\t\t\tproperty,\n\t\t\t\t\tvalue,\n\t\t\t\t\tendValuesArray.join(\", \")\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a Uint8Array.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static uint8Array(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is Uint8Array {\n\t\tif (!Is.uint8Array(value)) {\n\t\t\tthrow new GuardError(source, \"guard.uint8Array\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a function.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tpublic static function<T extends (...args: any[]) => any = (...args: any[]) => any>(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is T {\n\t\tif (!Is.function<T>(value)) {\n\t\t\tthrow new GuardError(source, \"guard.function\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a string formatted as an email address.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static email(source: string, property: string, value: unknown): asserts value is string {\n\t\tif (!Is.email(value)) {\n\t\t\tthrow new GuardError(source, \"guard.email\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a string containing uuidV7.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @param format The format of the uuidV7, either standard or compact.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static uuidV7(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown,\n\t\tformat?: \"standard\" | \"compact\"\n\t): asserts value is string {\n\t\tif (!Is.uuidV7(value, format)) {\n\t\t\tif (format === \"compact\") {\n\t\t\t\tthrow new GuardError(source, \"guard.uuidV7Compact\", property, value);\n\t\t\t}\n\t\t\tthrow new GuardError(source, \"guard.uuidV7\", property, value);\n\t\t}\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"guards.js","sourceRoot":"","sources":["../../../src/utils/guards.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAGpD;;GAEG;AACH,MAAM,OAAO,MAAM;IAClB;;;;;;OAMG;IACI,MAAM,CAAC,OAAO,CAAC,MAAc,EAAE,QAAgB,EAAE,KAAc;QACrE,IAAI,EAAE,CAAC,SAAS,C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AEd,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAI,KAAK,CAAC,EAAE,CAAC;YAC5B,MAAM,IAAI,UAAU,CAAC,MAAM,EAAE,gBAAgB,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;QACjE,CAAC;IACF,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,KAAK,CAAC,MAAc,EAAE,QAAgB,EAAE,KAAc;QACnE,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;YACtB,MAAM,IAAI,UAAU,CAAC,MAAM,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;QAC9D,CAAC;IACF,CAAC;IAED;;;;;;;OAOG;IACI,MAAM,CAAC,MAAM,CACnB,MAAc,EACd,QAAgB,EAChB,KAAc,EACd,MAA+B;QAE/B,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,CAAC;YAC/B,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;gBAC1B,MAAM,IAAI,UAAU,CAAC,MAAM,EAAE,qBAAqB,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;YACtE,CAAC;YACD,MAAM,IAAI,UAAU,CAAC,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;QAC/D,CAAC;IACF,CAAC;CACD","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Is } from \"./is.js\";\nimport { GuardError } from \"../errors/guardError.js\";\nimport { ArrayHelper } from \"../helpers/arrayHelper.js\";\nimport { HexHelper } from \"../helpers/hexHelper.js\";\nimport type { ObjectOrArray } from \"../types/objectOrArray.js\";\n\n/**\n * Class to handle guard operations for parameters.\n */\nexport class Guards {\n\t/**\n\t * Is the property defined.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static defined(source: string, property: string, value: unknown): asserts value {\n\t\tif (Is.undefined(value)) {\n\t\t\tthrow new GuardError(source, \"guard.undefined\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a string.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static string(source: string, property: string, value: unknown): asserts value is string {\n\t\tif (!Is.string(value)) {\n\t\t\tthrow new GuardError(source, \"guard.string\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a string with a value.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static stringValue(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is string {\n\t\tif (!Is.string(value)) {\n\t\t\tthrow new GuardError(source, \"guard.string\", property, value);\n\t\t}\n\t\tif (value.length === 0) {\n\t\t\tthrow new GuardError(source, \"guard.stringEmpty\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a JSON value.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static json(source: string, property: string, value: unknown): asserts value is string {\n\t\tif (!Is.json(value)) {\n\t\t\tthrow new GuardError(source, \"guard.stringJson\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a base64 string.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static stringBase64(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is string {\n\t\tif (!Is.stringBase64(value)) {\n\t\t\tthrow new GuardError(source, \"guard.stringBase64\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a base64 url string.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static stringBase64Url(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is string {\n\t\tif (!Is.stringBase64Url(value)) {\n\t\t\tthrow new GuardError(source, \"guard.stringBase64Url\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a base58 string.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static stringBase58(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is string {\n\t\tif (!Is.stringBase58(value)) {\n\t\t\tthrow new GuardError(source, \"guard.stringBase58\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a string with a hex value.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @param allowPrefix Allow the hex to have the 0x prefix.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static stringHex(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown,\n\t\tallowPrefix: boolean = false\n\t): asserts value is string {\n\t\tGuards.stringValue(source, property, value);\n\t\tif (!HexHelper.isHex(value, allowPrefix)) {\n\t\t\tthrow new GuardError(source, \"guard.stringHex\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a string with a hex value with fixed length.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @param length The length of the string to match.\n\t * @param allowPrefix Allow the hex to have the 0x prefix.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static stringHexLength(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown,\n\t\tlength: number,\n\t\tallowPrefix: boolean = false\n\t): asserts value is string {\n\t\tGuards.stringHex(source, property, value, allowPrefix);\n\t\tif (HexHelper.stripPrefix(value).length !== length) {\n\t\t\tthrow new GuardError(\n\t\t\t\tsource,\n\t\t\t\t\"guard.stringHexLength\",\n\t\t\t\tproperty,\n\t\t\t\tvalue.length,\n\t\t\t\tlength.toString()\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a number.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static number(source: string, property: string, value: unknown): asserts value is number {\n\t\tif (!Is.number(value)) {\n\t\t\tthrow new GuardError(source, \"guard.number\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property an integer.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static integer(source: string, property: string, value: unknown): asserts value is number {\n\t\tif (!Is.integer(value)) {\n\t\t\tthrow new GuardError(source, \"guard.integer\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a bigint.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static bigint(source: string, property: string, value: unknown): asserts value is bigint {\n\t\tif (!Is.bigint(value)) {\n\t\t\tthrow new GuardError(source, \"guard.bigint\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a boolean.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static boolean(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is boolean {\n\t\tif (!Is.boolean(value)) {\n\t\t\tthrow new GuardError(source, \"guard.boolean\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a date.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static date(source: string, property: string, value: unknown): asserts value is Date {\n\t\tif (!Is.date(value)) {\n\t\t\tthrow new GuardError(source, \"guard.date\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a timestamp in milliseconds.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static timestampMilliseconds(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is number {\n\t\tif (!Is.timestampMilliseconds(value)) {\n\t\t\tthrow new GuardError(source, \"guard.timestampMilliseconds\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a timestamp in seconds.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static timestampSeconds(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is number {\n\t\tif (!Is.timestampSeconds(value)) {\n\t\t\tthrow new GuardError(source, \"guard.timestampSeconds\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property an object.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static object<T = { [id: string]: unknown }>(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is T {\n\t\tif (Is.undefined(value)) {\n\t\t\tthrow new GuardError(source, \"guard.objectUndefined\", property, value);\n\t\t}\n\t\tif (!Is.object<T>(value)) {\n\t\t\tthrow new GuardError(source, \"guard.object\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property is an object with at least one property.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static objectValue<T = { [id: string]: unknown }>(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is T {\n\t\tif (Is.undefined(value)) {\n\t\t\tthrow new GuardError(source, \"guard.objectUndefined\", property, value);\n\t\t}\n\t\tif (!Is.object<T>(value)) {\n\t\t\tthrow new GuardError(source, \"guard.object\", property, value);\n\t\t}\n\t\tif (Object.keys(value || {}).length === 0) {\n\t\t\tthrow new GuardError(source, \"guard.objectValue\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property is an array.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static array<T>(source: string, property: string, value: unknown): asserts value is T[] {\n\t\tif (!Is.array<T>(value)) {\n\t\t\tthrow new GuardError(source, \"guard.array\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property is an array with at least one item.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static arrayValue<T>(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is T[] {\n\t\tif (!Is.array(value)) {\n\t\t\tthrow new GuardError(source, \"guard.array\", property, value);\n\t\t}\n\t\tif (value.length === 0) {\n\t\t\tthrow new GuardError(source, \"guard.arrayValue\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property one of a list of items.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @param options The options the value must be one of.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static arrayOneOf<T>(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: T,\n\t\toptions: T[]\n\t): asserts value is T {\n\t\tif (!Is.array<T>(options)) {\n\t\t\tthrow new GuardError(source, \"guard.array\", property, value);\n\t\t}\n\t\tif (!options.includes(value)) {\n\t\t\tthrow new GuardError(source, \"guard.arrayOneOf\", property, value, options.join(\", \"));\n\t\t}\n\t}\n\n\t/**\n\t * Does the array start with the specified data.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @param startValues The values that must start the array.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static arrayStartsWith<T>(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown,\n\t\tstartValues: ObjectOrArray<T>\n\t): asserts value is T[] {\n\t\tif (!Is.arrayValue<T>(value)) {\n\t\t\tthrow new GuardError(source, \"guard.array\", property, value);\n\t\t}\n\n\t\tconst startValuesArray = ArrayHelper.fromObjectOrArray(startValues);\n\n\t\tif (!Is.arrayValue<T>(startValuesArray)) {\n\t\t\tthrow new GuardError(source, \"guard.array\", property, startValuesArray);\n\t\t}\n\n\t\tfor (let i = 0; i < startValuesArray.length; i++) {\n\t\t\tif (value[i] !== startValuesArray[i]) {\n\t\t\t\tthrow new GuardError(\n\t\t\t\t\tsource,\n\t\t\t\t\t\"guard.arrayStartsWith\",\n\t\t\t\t\tproperty,\n\t\t\t\t\tvalue,\n\t\t\t\t\tstartValuesArray.join(\", \")\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Does the array end with the specified data.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @param endValues The values that must end the array.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static arrayEndsWith<T>(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown,\n\t\tendValues: ObjectOrArray<T>\n\t): asserts value is T[] {\n\t\tif (!Is.arrayValue<T>(value)) {\n\t\t\tthrow new GuardError(source, \"guard.array\", property, value);\n\t\t}\n\n\t\tconst endValuesArray = ArrayHelper.fromObjectOrArray(endValues);\n\n\t\tif (!Is.arrayValue<T>(endValuesArray)) {\n\t\t\tthrow new GuardError(source, \"guard.array\", property, endValuesArray);\n\t\t}\n\n\t\tfor (let i = 0; i < endValuesArray.length; i++) {\n\t\t\tif (value[value.length - i - 1] !== endValuesArray[endValuesArray.length - i - 1]) {\n\t\t\t\tthrow new GuardError(\n\t\t\t\t\tsource,\n\t\t\t\t\t\"guard.arrayEndsWith\",\n\t\t\t\t\tproperty,\n\t\t\t\t\tvalue,\n\t\t\t\t\tendValuesArray.join(\", \")\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a Uint8Array.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static uint8Array(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is Uint8Array {\n\t\tif (!Is.uint8Array(value)) {\n\t\t\tthrow new GuardError(source, \"guard.uint8Array\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a function.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tpublic static function<T extends (...args: any[]) => any = (...args: any[]) => any>(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is T {\n\t\tif (!Is.function<T>(value)) {\n\t\t\tthrow new GuardError(source, \"guard.function\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a string formatted as an email address.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static email(source: string, property: string, value: unknown): asserts value is string {\n\t\tif (!Is.email(value)) {\n\t\t\tthrow new GuardError(source, \"guard.email\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a string containing uuidV7.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @param format The format of the uuidV7, either standard or compact.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static uuidV7(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown,\n\t\tformat?: \"standard\" | \"compact\"\n\t): asserts value is string {\n\t\tif (!Is.uuidV7(value, format)) {\n\t\t\tif (format === \"compact\") {\n\t\t\t\tthrow new GuardError(source, \"guard.uuidV7Compact\", property, value);\n\t\t\t}\n\t\t\tthrow new GuardError(source, \"guard.uuidV7\", property, value);\n\t\t}\n\t}\n}\n"]}
|
|
@@ -38,12 +38,8 @@ export declare class Factory<T> {
|
|
|
38
38
|
* Register a new generator.
|
|
39
39
|
* @param name The name of the generator.
|
|
40
40
|
* @param generator The function to create an instance.
|
|
41
|
-
* @param options Options for the generator.
|
|
42
|
-
* @param options.isDefault Whether the generator is the default one i.e. should be the first generator.
|
|
43
41
|
*/
|
|
44
|
-
register<U extends T>(name: string, generator: (args?: unknown) => U
|
|
45
|
-
isDefault?: boolean;
|
|
46
|
-
}): void;
|
|
42
|
+
register<U extends T>(name: string, generator: (args?: unknown) => U): void;
|
|
47
43
|
/**
|
|
48
44
|
* Unregister a generator.
|
|
49
45
|
* @param name The name of the generator to unregister.
|
package/dist/types/index.d.ts
CHANGED
|
@@ -39,8 +39,9 @@ export * from "./models/ILocalesIndex.js";
|
|
|
39
39
|
export * from "./models/IPatchOperation.js";
|
|
40
40
|
export * from "./models/IUrlParts.js";
|
|
41
41
|
export * from "./models/IValidationFailure.js";
|
|
42
|
-
export * from "./models/objectOrArray.js";
|
|
43
42
|
export * from "./types/bitString.js";
|
|
43
|
+
export * from "./types/objectOrArray.js";
|
|
44
|
+
export * from "./types/singleOccurrenceArray.js";
|
|
44
45
|
export * from "./types/url.js";
|
|
45
46
|
export * from "./types/urn.js";
|
|
46
47
|
export * from "./utils/asyncCache.js";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper with bounded recursion depth to keep type instantiation tractable.
|
|
3
|
+
*/
|
|
4
|
+
export type SingleOccurrenceArrayDepthHelper<T, U, Depth extends 0[]> = Depth["length"] extends 16 ? [U, ...T[]] : [U, ...T[]] | [T, ...SingleOccurrenceArrayDepthHelper<T, U, [0, ...Depth]>];
|
|
5
|
+
/**
|
|
6
|
+
* Utility type to create a non-empty array with values of type T and exactly one value of type U.
|
|
7
|
+
*/
|
|
8
|
+
export type SingleOccurrenceArray<T = unknown, U = never> = SingleOccurrenceArrayDepthHelper<T, U, [
|
|
9
|
+
]>;
|
package/docs/changelog.md
CHANGED
|
@@ -1,4 +1,39 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.0.3-next.23](https://github.com/twinfoundation/framework/compare/core-v0.0.3-next.22...core-v0.0.3-next.23) (2026-03-17)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* add single occurrence array type ([e890e43](https://github.com/twinfoundation/framework/commit/e890e4399e75ae5097f3ad8b1007321cbb1ed4ac))
|
|
9
|
+
* add single occurrence array type ([#245](https://github.com/twinfoundation/framework/issues/245)) ([771dc78](https://github.com/twinfoundation/framework/commit/771dc78025b5546c9c9681be9494a76ab71171c6))
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Dependencies
|
|
13
|
+
|
|
14
|
+
* The following workspace dependencies were updated
|
|
15
|
+
* dependencies
|
|
16
|
+
* @twin.org/nameof bumped from 0.0.3-next.22 to 0.0.3-next.23
|
|
17
|
+
* devDependencies
|
|
18
|
+
* @twin.org/nameof-transformer bumped from 0.0.3-next.22 to 0.0.3-next.23
|
|
19
|
+
* @twin.org/nameof-vitest-plugin bumped from 0.0.3-next.22 to 0.0.3-next.23
|
|
20
|
+
|
|
21
|
+
## [0.0.3-next.22](https://github.com/twinfoundation/framework/compare/core-v0.0.3-next.21...core-v0.0.3-next.22) (2026-02-26)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
### Features
|
|
25
|
+
|
|
26
|
+
* simplify factory options ([7f85a85](https://github.com/twinfoundation/framework/commit/7f85a8553dd3008364e8e1104f2e6f6b6595d77e))
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
### Dependencies
|
|
30
|
+
|
|
31
|
+
* The following workspace dependencies were updated
|
|
32
|
+
* dependencies
|
|
33
|
+
* @twin.org/nameof bumped from 0.0.3-next.21 to 0.0.3-next.22
|
|
34
|
+
* devDependencies
|
|
35
|
+
* @twin.org/nameof-transformer bumped from 0.0.3-next.21 to 0.0.3-next.22
|
|
36
|
+
* @twin.org/nameof-vitest-plugin bumped from 0.0.3-next.21 to 0.0.3-next.22
|
|
2
37
|
|
|
3
38
|
## [0.0.3-next.21](https://github.com/twinfoundation/framework/compare/core-v0.0.3-next.20...core-v0.0.3-next.21) (2026-02-26)
|
|
4
39
|
|