@twin.org/core 0.0.2-next.19 → 0.0.2-next.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +108 -76
- package/dist/esm/index.mjs +108 -76
- package/dist/types/encoding/base32.d.ts +4 -0
- package/dist/types/encoding/base58.d.ts +4 -0
- package/dist/types/encoding/base64.d.ts +4 -0
- package/dist/types/encoding/base64Url.d.ts +4 -0
- package/dist/types/factories/factory.d.ts +4 -0
- package/dist/types/helpers/jsonHelper.d.ts +4 -0
- package/dist/types/helpers/objectHelper.d.ts +4 -0
- package/dist/types/models/IComponent.d.ts +4 -2
- package/dist/types/models/IValidationFailure.d.ts +0 -4
- package/dist/types/types/bitString.d.ts +4 -0
- package/dist/types/types/url.d.ts +6 -1
- package/dist/types/types/urn.d.ts +6 -1
- package/dist/types/utils/compression.d.ts +4 -0
- package/dist/types/utils/i18n.d.ts +15 -0
- package/dist/types/utils/is.d.ts +1 -1
- package/docs/changelog.md +34 -0
- package/docs/reference/classes/Base32.md +8 -0
- package/docs/reference/classes/Base58.md +8 -0
- package/docs/reference/classes/Base64.md +8 -0
- package/docs/reference/classes/Base64Url.md +8 -0
- package/docs/reference/classes/BitString.md +8 -0
- package/docs/reference/classes/Compression.md +8 -0
- package/docs/reference/classes/Factory.md +8 -0
- package/docs/reference/classes/I18n.md +52 -0
- package/docs/reference/classes/Is.md +4 -4
- package/docs/reference/classes/JsonHelper.md +8 -0
- package/docs/reference/classes/ObjectHelper.md +8 -0
- package/docs/reference/classes/Url.md +15 -1
- package/docs/reference/classes/Urn.md +15 -1
- package/docs/reference/interfaces/IComponent.md +5 -5
- package/docs/reference/interfaces/IValidationFailure.md +0 -8
- package/locales/.validate-ignore +1 -0
- package/locales/en.json +4 -5
- package/package.json +17 -3
package/dist/esm/index.mjs
CHANGED
|
@@ -329,6 +329,8 @@ class Is {
|
|
|
329
329
|
* @returns True if the value is a Uint8Array.
|
|
330
330
|
*/
|
|
331
331
|
static uint8Array(value) {
|
|
332
|
+
// This is the only way we can reliably check for Uint8Array
|
|
333
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
332
334
|
return value instanceof Uint8Array;
|
|
333
335
|
}
|
|
334
336
|
/**
|
|
@@ -337,6 +339,8 @@ class Is {
|
|
|
337
339
|
* @returns True if the value is a TypedArray.
|
|
338
340
|
*/
|
|
339
341
|
static typedArray(value) {
|
|
342
|
+
// This is the only way we can reliably check for TypedArray
|
|
343
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
340
344
|
return value instanceof Object.getPrototypeOf(Uint8Array);
|
|
341
345
|
}
|
|
342
346
|
/**
|
|
@@ -344,6 +348,7 @@ class Is {
|
|
|
344
348
|
* @param value The value to test.
|
|
345
349
|
* @returns True if the value is a function.
|
|
346
350
|
*/
|
|
351
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
347
352
|
static function(value) {
|
|
348
353
|
return typeof value === "function";
|
|
349
354
|
}
|
|
@@ -362,6 +367,8 @@ class Is {
|
|
|
362
367
|
* @returns True if the value is a promise.
|
|
363
368
|
*/
|
|
364
369
|
static promise(value) {
|
|
370
|
+
// This is the only way we can reliably check for Promise
|
|
371
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
365
372
|
return value instanceof Promise;
|
|
366
373
|
}
|
|
367
374
|
/**
|
|
@@ -370,6 +377,8 @@ class Is {
|
|
|
370
377
|
* @returns True if the value is a regexp.
|
|
371
378
|
*/
|
|
372
379
|
static regexp(value) {
|
|
380
|
+
// This is the only way we can reliably check for RegExp
|
|
381
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
373
382
|
return value instanceof RegExp;
|
|
374
383
|
}
|
|
375
384
|
/**
|
|
@@ -837,6 +846,8 @@ class BaseError extends Error {
|
|
|
837
846
|
* @returns True if the error is an aggregate error.
|
|
838
847
|
*/
|
|
839
848
|
static isAggregateError(err) {
|
|
849
|
+
// This is the only way we can reliably check for AggregateError
|
|
850
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
840
851
|
return err instanceof AggregateError;
|
|
841
852
|
}
|
|
842
853
|
/**
|
|
@@ -1034,7 +1045,7 @@ class Guards {
|
|
|
1034
1045
|
*/
|
|
1035
1046
|
static stringBase64(source, property, value) {
|
|
1036
1047
|
if (!Is.stringBase64(value)) {
|
|
1037
|
-
throw new GuardError(source, "guard.
|
|
1048
|
+
throw new GuardError(source, "guard.stringBase64", property, value);
|
|
1038
1049
|
}
|
|
1039
1050
|
}
|
|
1040
1051
|
/**
|
|
@@ -1046,7 +1057,7 @@ class Guards {
|
|
|
1046
1057
|
*/
|
|
1047
1058
|
static stringBase64Url(source, property, value) {
|
|
1048
1059
|
if (!Is.stringBase64Url(value)) {
|
|
1049
|
-
throw new GuardError(source, "guard.
|
|
1060
|
+
throw new GuardError(source, "guard.stringBase64Url", property, value);
|
|
1050
1061
|
}
|
|
1051
1062
|
}
|
|
1052
1063
|
/**
|
|
@@ -1058,7 +1069,7 @@ class Guards {
|
|
|
1058
1069
|
*/
|
|
1059
1070
|
static stringBase58(source, property, value) {
|
|
1060
1071
|
if (!Is.stringBase58(value)) {
|
|
1061
|
-
throw new GuardError(source, "guard.
|
|
1072
|
+
throw new GuardError(source, "guard.stringBase58", property, value);
|
|
1062
1073
|
}
|
|
1063
1074
|
}
|
|
1064
1075
|
/**
|
|
@@ -1343,9 +1354,8 @@ class Guards {
|
|
|
1343
1354
|
class Base32 {
|
|
1344
1355
|
/**
|
|
1345
1356
|
* Runtime name for the class.
|
|
1346
|
-
* @internal
|
|
1347
1357
|
*/
|
|
1348
|
-
static
|
|
1358
|
+
static CLASS_NAME = "Base32";
|
|
1349
1359
|
/**
|
|
1350
1360
|
* Alphabet table for encoding.
|
|
1351
1361
|
* @internal
|
|
@@ -1358,7 +1368,7 @@ class Base32 {
|
|
|
1358
1368
|
* @throws If the input string contains a character not in the Base32 alphabet.
|
|
1359
1369
|
*/
|
|
1360
1370
|
static decode(base32) {
|
|
1361
|
-
Guards.string(Base32.
|
|
1371
|
+
Guards.string(Base32.CLASS_NAME, "base32", base32);
|
|
1362
1372
|
let bits = 0;
|
|
1363
1373
|
let value = 0;
|
|
1364
1374
|
base32 = base32.replace(/=+$/, "");
|
|
@@ -1367,7 +1377,7 @@ class Base32 {
|
|
|
1367
1377
|
for (let i = 0; i < base32.length; i++) {
|
|
1368
1378
|
const idx = Base32._ALPHABET.indexOf(base32[i]);
|
|
1369
1379
|
if (idx === -1) {
|
|
1370
|
-
throw new GeneralError(Base32.
|
|
1380
|
+
throw new GeneralError(Base32.CLASS_NAME, "invalidCharacter", {
|
|
1371
1381
|
invalidCharacter: base32[i]
|
|
1372
1382
|
});
|
|
1373
1383
|
}
|
|
@@ -1386,7 +1396,7 @@ class Base32 {
|
|
|
1386
1396
|
* @returns The data as base32 string.
|
|
1387
1397
|
*/
|
|
1388
1398
|
static encode(bytes) {
|
|
1389
|
-
Guards.uint8Array(Base32.
|
|
1399
|
+
Guards.uint8Array(Base32.CLASS_NAME, "bytes", bytes);
|
|
1390
1400
|
let bits = 0;
|
|
1391
1401
|
let value = 0;
|
|
1392
1402
|
let output = "";
|
|
@@ -1414,9 +1424,8 @@ class Base32 {
|
|
|
1414
1424
|
class Base58 {
|
|
1415
1425
|
/**
|
|
1416
1426
|
* Runtime name for the class.
|
|
1417
|
-
* @internal
|
|
1418
1427
|
*/
|
|
1419
|
-
static
|
|
1428
|
+
static CLASS_NAME = "Base58";
|
|
1420
1429
|
/**
|
|
1421
1430
|
* Alphabet table for encoding.
|
|
1422
1431
|
* @internal
|
|
@@ -1443,7 +1452,7 @@ class Base58 {
|
|
|
1443
1452
|
* @throws If the input string contains a character not in the Base58 alphabet.
|
|
1444
1453
|
*/
|
|
1445
1454
|
static decode(base58) {
|
|
1446
|
-
Guards.string(Base58.
|
|
1455
|
+
Guards.string(Base58.CLASS_NAME, "base58", base58);
|
|
1447
1456
|
let zeroes = 0;
|
|
1448
1457
|
for (let i = 0; i < base58.length; i++) {
|
|
1449
1458
|
if (base58[i] !== "1") {
|
|
@@ -1457,11 +1466,11 @@ class Base58 {
|
|
|
1457
1466
|
for (let i = zeroes; i < base58.length; i++) {
|
|
1458
1467
|
const ch = base58.charCodeAt(i);
|
|
1459
1468
|
if (ch & 0xff80) {
|
|
1460
|
-
throw new GeneralError(Base58.
|
|
1469
|
+
throw new GeneralError(Base58.CLASS_NAME, "invalidCharacter", { invalidCharacter: ch });
|
|
1461
1470
|
}
|
|
1462
1471
|
const val = Base58._ALPHABET_REVERSE[ch];
|
|
1463
1472
|
if (val === -1) {
|
|
1464
|
-
throw new GeneralError(Base58.
|
|
1473
|
+
throw new GeneralError(Base58.CLASS_NAME, "invalidCharacter", { invalidCharacter: ch });
|
|
1465
1474
|
}
|
|
1466
1475
|
let carry = val;
|
|
1467
1476
|
let j = 0;
|
|
@@ -1492,7 +1501,7 @@ class Base58 {
|
|
|
1492
1501
|
* @returns The data as base58 string.
|
|
1493
1502
|
*/
|
|
1494
1503
|
static encode(bytes) {
|
|
1495
|
-
Guards.uint8Array(Base58.
|
|
1504
|
+
Guards.uint8Array(Base58.CLASS_NAME, "bytes", bytes);
|
|
1496
1505
|
let zeroes = 0;
|
|
1497
1506
|
for (let i = 0; i < bytes.length; i++) {
|
|
1498
1507
|
if (bytes[i] !== 0) {
|
|
@@ -1542,9 +1551,8 @@ class Base58 {
|
|
|
1542
1551
|
class Base64 {
|
|
1543
1552
|
/**
|
|
1544
1553
|
* Runtime name for the class.
|
|
1545
|
-
* @internal
|
|
1546
1554
|
*/
|
|
1547
|
-
static
|
|
1555
|
+
static CLASS_NAME = "Base64";
|
|
1548
1556
|
/**
|
|
1549
1557
|
* Alphabet table for encoding.
|
|
1550
1558
|
* @internal
|
|
@@ -1637,7 +1645,7 @@ class Base64 {
|
|
|
1637
1645
|
* @returns The byte array.
|
|
1638
1646
|
*/
|
|
1639
1647
|
static decode(base64) {
|
|
1640
|
-
Guards.string(Base64.
|
|
1648
|
+
Guards.string(Base64.CLASS_NAME, "base64", base64);
|
|
1641
1649
|
let tmp;
|
|
1642
1650
|
const lens = Base64.getLengths(base64);
|
|
1643
1651
|
const validLen = lens[0];
|
|
@@ -1679,7 +1687,7 @@ class Base64 {
|
|
|
1679
1687
|
* @returns The data as base64 string.
|
|
1680
1688
|
*/
|
|
1681
1689
|
static encode(bytes) {
|
|
1682
|
-
Guards.uint8Array(Base64.
|
|
1690
|
+
Guards.uint8Array(Base64.CLASS_NAME, "bytes", bytes);
|
|
1683
1691
|
let tmp;
|
|
1684
1692
|
const len = bytes.length;
|
|
1685
1693
|
const extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes
|
|
@@ -1719,7 +1727,7 @@ class Base64 {
|
|
|
1719
1727
|
static getLengths(base64) {
|
|
1720
1728
|
const len = base64.length;
|
|
1721
1729
|
if (len % 4 > 0) {
|
|
1722
|
-
throw new GeneralError(Base64.
|
|
1730
|
+
throw new GeneralError(Base64.CLASS_NAME, "length4Multiple", { value: len });
|
|
1723
1731
|
}
|
|
1724
1732
|
// Trim off extra bytes after placeholder bytes are found
|
|
1725
1733
|
// See: https://github.com/beatgammit/base64-js/issues/42
|
|
@@ -1768,16 +1776,15 @@ class Base64 {
|
|
|
1768
1776
|
class Base64Url {
|
|
1769
1777
|
/**
|
|
1770
1778
|
* Runtime name for the class.
|
|
1771
|
-
* @internal
|
|
1772
1779
|
*/
|
|
1773
|
-
static
|
|
1780
|
+
static CLASS_NAME = "Base64";
|
|
1774
1781
|
/**
|
|
1775
1782
|
* Convert the base 64 string to a byte array.
|
|
1776
1783
|
* @param base64Url The base64 url string to convert.
|
|
1777
1784
|
* @returns The byte array.
|
|
1778
1785
|
*/
|
|
1779
1786
|
static decode(base64Url) {
|
|
1780
|
-
Guards.string(Base64Url.
|
|
1787
|
+
Guards.string(Base64Url.CLASS_NAME, "base64Url", base64Url);
|
|
1781
1788
|
let base64 = base64Url;
|
|
1782
1789
|
// Base 64 url can have padding removed, so add it back if it is missing.
|
|
1783
1790
|
if (base64.length > 0 && !base64.endsWith("=")) {
|
|
@@ -1795,7 +1802,7 @@ class Base64Url {
|
|
|
1795
1802
|
* @returns The data as base64 url string.
|
|
1796
1803
|
*/
|
|
1797
1804
|
static encode(bytes) {
|
|
1798
|
-
Guards.uint8Array(Base64Url.
|
|
1805
|
+
Guards.uint8Array(Base64Url.CLASS_NAME, "bytes", bytes);
|
|
1799
1806
|
const base64 = Base64.encode(bytes);
|
|
1800
1807
|
// Base 64 url can have padding removed, so remove it.
|
|
1801
1808
|
return base64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
@@ -2024,9 +2031,8 @@ class SharedStore {
|
|
|
2024
2031
|
class Factory {
|
|
2025
2032
|
/**
|
|
2026
2033
|
* Runtime name for the class.
|
|
2027
|
-
* @internal
|
|
2028
2034
|
*/
|
|
2029
|
-
static
|
|
2035
|
+
static CLASS_NAME = "Factory";
|
|
2030
2036
|
/**
|
|
2031
2037
|
* Type name for the instances.
|
|
2032
2038
|
* @internal
|
|
@@ -2122,8 +2128,8 @@ class Factory {
|
|
|
2122
2128
|
* @param generator The function to create an instance.
|
|
2123
2129
|
*/
|
|
2124
2130
|
register(name, generator) {
|
|
2125
|
-
Guards.stringValue(Factory.
|
|
2126
|
-
Guards.function(Factory.
|
|
2131
|
+
Guards.stringValue(Factory.CLASS_NAME, "name", name);
|
|
2132
|
+
Guards.function(Factory.CLASS_NAME, "generator", generator);
|
|
2127
2133
|
this._generators[name] = {
|
|
2128
2134
|
generator,
|
|
2129
2135
|
order: this._orderCounter++
|
|
@@ -2141,9 +2147,9 @@ class Factory {
|
|
|
2141
2147
|
* @throws GeneralError if no generator exists.
|
|
2142
2148
|
*/
|
|
2143
2149
|
unregister(name) {
|
|
2144
|
-
Guards.stringValue(Factory.
|
|
2150
|
+
Guards.stringValue(Factory.CLASS_NAME, "name", name);
|
|
2145
2151
|
if (!this._generators[name]) {
|
|
2146
|
-
throw new GeneralError(Factory.
|
|
2152
|
+
throw new GeneralError(Factory.CLASS_NAME, "noUnregister", {
|
|
2147
2153
|
typeName: this._typeName,
|
|
2148
2154
|
name
|
|
2149
2155
|
});
|
|
@@ -2160,10 +2166,10 @@ class Factory {
|
|
|
2160
2166
|
* @throws GeneralError if no item exists to get.
|
|
2161
2167
|
*/
|
|
2162
2168
|
get(name) {
|
|
2163
|
-
Guards.stringValue(Factory.
|
|
2169
|
+
Guards.stringValue(Factory.CLASS_NAME, "name", name);
|
|
2164
2170
|
const instance = this.getIfExists(name);
|
|
2165
2171
|
if (!instance) {
|
|
2166
|
-
throw new GeneralError(Factory.
|
|
2172
|
+
throw new GeneralError(Factory.CLASS_NAME, "noGet", {
|
|
2167
2173
|
typeName: this._typeName,
|
|
2168
2174
|
name
|
|
2169
2175
|
});
|
|
@@ -2179,7 +2185,7 @@ class Factory {
|
|
|
2179
2185
|
if (Is.empty(name)) {
|
|
2180
2186
|
return;
|
|
2181
2187
|
}
|
|
2182
|
-
Guards.stringValue(Factory.
|
|
2188
|
+
Guards.stringValue(Factory.CLASS_NAME, "name", name);
|
|
2183
2189
|
const matchName = this._matcher(Object.keys(this._generators), name);
|
|
2184
2190
|
if (Is.stringValue(matchName) && this._generators[matchName]) {
|
|
2185
2191
|
if (!this._instances[matchName]) {
|
|
@@ -2248,7 +2254,7 @@ class Factory {
|
|
|
2248
2254
|
* @returns True if the factory has a matching name.
|
|
2249
2255
|
*/
|
|
2250
2256
|
hasName(name) {
|
|
2251
|
-
Guards.stringValue(Factory.
|
|
2257
|
+
Guards.stringValue(Factory.CLASS_NAME, "name", name);
|
|
2252
2258
|
return Is.stringValue(this._matcher(Object.keys(this._generators), name));
|
|
2253
2259
|
}
|
|
2254
2260
|
/**
|
|
@@ -2374,7 +2380,7 @@ class Converter {
|
|
|
2374
2380
|
*/
|
|
2375
2381
|
static bytesToHex(array, includePrefix = false, startIndex, length, reverse) {
|
|
2376
2382
|
let hex = "";
|
|
2377
|
-
|
|
2383
|
+
Converter.buildHexLookups();
|
|
2378
2384
|
if (Converter._ENCODE_LOOKUP) {
|
|
2379
2385
|
const len = length ?? array.length;
|
|
2380
2386
|
const start = startIndex ?? 0;
|
|
@@ -2402,7 +2408,7 @@ class Converter {
|
|
|
2402
2408
|
const sizeof = strippedHex.length >> 1;
|
|
2403
2409
|
const length = sizeof << 1;
|
|
2404
2410
|
const array = new Uint8Array(sizeof);
|
|
2405
|
-
|
|
2411
|
+
Converter.buildHexLookups();
|
|
2406
2412
|
if (Converter._DECODE_LOOKUP) {
|
|
2407
2413
|
let i = 0;
|
|
2408
2414
|
let n = 0;
|
|
@@ -2537,9 +2543,8 @@ class Converter {
|
|
|
2537
2543
|
class JsonHelper {
|
|
2538
2544
|
/**
|
|
2539
2545
|
* Runtime name for the class.
|
|
2540
|
-
* @internal
|
|
2541
2546
|
*/
|
|
2542
|
-
static
|
|
2547
|
+
static CLASS_NAME = "JsonHelper";
|
|
2543
2548
|
/**
|
|
2544
2549
|
* Serializes in canonical format.
|
|
2545
2550
|
* Based on https://www.rfc-editor.org/rfc/rfc8785.
|
|
@@ -2550,7 +2555,7 @@ class JsonHelper {
|
|
|
2550
2555
|
const buffer = [];
|
|
2551
2556
|
if (object === null ||
|
|
2552
2557
|
typeof object !== "object" ||
|
|
2553
|
-
("toJSON" in object && object.toJSON
|
|
2558
|
+
("toJSON" in object && Is.function(object.toJSON))) {
|
|
2554
2559
|
// Primitive data type
|
|
2555
2560
|
buffer.push(JSON.stringify(object));
|
|
2556
2561
|
}
|
|
@@ -2605,7 +2610,7 @@ class JsonHelper {
|
|
|
2605
2610
|
const result = applyPatch(clone, patches);
|
|
2606
2611
|
for (let i = 0; i < result.length; i++) {
|
|
2607
2612
|
if (!Is.empty(result[i])) {
|
|
2608
|
-
throw new GeneralError(JsonHelper.
|
|
2613
|
+
throw new GeneralError(JsonHelper.CLASS_NAME, "failedPatch", { index: i }, result[i]);
|
|
2609
2614
|
}
|
|
2610
2615
|
}
|
|
2611
2616
|
return clone;
|
|
@@ -2642,6 +2647,9 @@ class JsonHelper {
|
|
|
2642
2647
|
*/
|
|
2643
2648
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2644
2649
|
static stringifyExReplacer(key, value) {
|
|
2650
|
+
// The this in the replacer is the containing object
|
|
2651
|
+
// so we need to get the actual value from there
|
|
2652
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
2645
2653
|
const rawValue = this[key];
|
|
2646
2654
|
if (Is.bigint(rawValue)) {
|
|
2647
2655
|
return {
|
|
@@ -2693,9 +2701,8 @@ class JsonHelper {
|
|
|
2693
2701
|
class ObjectHelper {
|
|
2694
2702
|
/**
|
|
2695
2703
|
* Runtime name for the class.
|
|
2696
|
-
* @internal
|
|
2697
2704
|
*/
|
|
2698
|
-
static
|
|
2705
|
+
static CLASS_NAME = "ObjectHelper";
|
|
2699
2706
|
/**
|
|
2700
2707
|
* Convert an object to bytes.
|
|
2701
2708
|
* @param obj The object to convert.
|
|
@@ -2724,7 +2731,7 @@ class ObjectHelper {
|
|
|
2724
2731
|
return JSON.parse(utf8);
|
|
2725
2732
|
}
|
|
2726
2733
|
catch (err) {
|
|
2727
|
-
throw new GeneralError(ObjectHelper.
|
|
2734
|
+
throw new GeneralError(ObjectHelper.CLASS_NAME, "failedBytesToJSON", undefined, err);
|
|
2728
2735
|
}
|
|
2729
2736
|
}
|
|
2730
2737
|
/**
|
|
@@ -2837,7 +2844,7 @@ class ObjectHelper {
|
|
|
2837
2844
|
pathValue[arrayIndex] = value;
|
|
2838
2845
|
}
|
|
2839
2846
|
else {
|
|
2840
|
-
throw new GeneralError(ObjectHelper.
|
|
2847
|
+
throw new GeneralError(ObjectHelper.CLASS_NAME, "cannotSetArrayIndex", {
|
|
2841
2848
|
property,
|
|
2842
2849
|
index: arrayIndex
|
|
2843
2850
|
});
|
|
@@ -2847,7 +2854,7 @@ class ObjectHelper {
|
|
|
2847
2854
|
pathValue[pathPart] = value;
|
|
2848
2855
|
}
|
|
2849
2856
|
else {
|
|
2850
|
-
throw new GeneralError(ObjectHelper.
|
|
2857
|
+
throw new GeneralError(ObjectHelper.CLASS_NAME, "cannotSetProperty", { property });
|
|
2851
2858
|
}
|
|
2852
2859
|
}
|
|
2853
2860
|
else {
|
|
@@ -3189,7 +3196,6 @@ class I18n {
|
|
|
3189
3196
|
* @param translation The translation to merge.
|
|
3190
3197
|
* @param propertyPath The current root path.
|
|
3191
3198
|
* @param mergedKeys The merged keys dictionary to populate.
|
|
3192
|
-
* @internal
|
|
3193
3199
|
*/
|
|
3194
3200
|
static flattenTranslationKeys(translation, propertyPath, mergedKeys) {
|
|
3195
3201
|
for (const key in translation) {
|
|
@@ -3203,6 +3209,31 @@ class I18n {
|
|
|
3203
3209
|
}
|
|
3204
3210
|
}
|
|
3205
3211
|
}
|
|
3212
|
+
/**
|
|
3213
|
+
* Get a list of the property names from the message.
|
|
3214
|
+
* @param message The message to extract the property names from.
|
|
3215
|
+
* @returns The list of property names.
|
|
3216
|
+
*/
|
|
3217
|
+
static getPropertyNames(message) {
|
|
3218
|
+
const properties = new Set();
|
|
3219
|
+
// Handle basic placeholders: {property}
|
|
3220
|
+
const basicRegex = /{([$A-Z_a-z][\w$]*)}/g;
|
|
3221
|
+
let match;
|
|
3222
|
+
while ((match = basicRegex.exec(message)) !== null) {
|
|
3223
|
+
properties.add(match[1]);
|
|
3224
|
+
}
|
|
3225
|
+
// Handle ICU format with types: {property, number}, {property, date}, etc.
|
|
3226
|
+
const icuRegex = /{([$A-Z_a-z][\w$]*)\s*,\s*\w+/g;
|
|
3227
|
+
while ((match = icuRegex.exec(message)) !== null) {
|
|
3228
|
+
properties.add(match[1]);
|
|
3229
|
+
}
|
|
3230
|
+
// Handle plural/select: {count, plural, one {1 item} other {# items}}
|
|
3231
|
+
const pluralSelectRegex = /{([$A-Z_a-z][\w$]*)\s*,\s*(plural|select|selectordinal)/g;
|
|
3232
|
+
while ((match = pluralSelectRegex.exec(message)) !== null) {
|
|
3233
|
+
properties.add(match[1]);
|
|
3234
|
+
}
|
|
3235
|
+
return Array.from(properties);
|
|
3236
|
+
}
|
|
3206
3237
|
/**
|
|
3207
3238
|
* Get the I18n shared data.
|
|
3208
3239
|
* @returns The I18n shared data.
|
|
@@ -3732,9 +3763,8 @@ const CompressionType = {
|
|
|
3732
3763
|
class BitString {
|
|
3733
3764
|
/**
|
|
3734
3765
|
* Runtime name for the class.
|
|
3735
|
-
* @internal
|
|
3736
3766
|
*/
|
|
3737
|
-
static
|
|
3767
|
+
static CLASS_NAME = "BitString";
|
|
3738
3768
|
/**
|
|
3739
3769
|
* The storage for the bits.
|
|
3740
3770
|
* @internal
|
|
@@ -3750,7 +3780,7 @@ class BitString {
|
|
|
3750
3780
|
* @param numberBits The length of the bit string.
|
|
3751
3781
|
*/
|
|
3752
3782
|
constructor(numberBits) {
|
|
3753
|
-
Guards.integer(BitString.
|
|
3783
|
+
Guards.integer(BitString.CLASS_NAME, "numberBits", numberBits);
|
|
3754
3784
|
this._numberBits = numberBits;
|
|
3755
3785
|
this._bits = new Uint8Array(Math.ceil(numberBits / 8));
|
|
3756
3786
|
}
|
|
@@ -3761,8 +3791,8 @@ class BitString {
|
|
|
3761
3791
|
* @returns The new instance of BitString.
|
|
3762
3792
|
*/
|
|
3763
3793
|
static fromBits(bits, numberBits) {
|
|
3764
|
-
Guards.uint8Array(BitString.
|
|
3765
|
-
Guards.integer(BitString.
|
|
3794
|
+
Guards.uint8Array(BitString.CLASS_NAME, "bits", bits);
|
|
3795
|
+
Guards.integer(BitString.CLASS_NAME, "numberBits", numberBits);
|
|
3766
3796
|
const bs = new BitString(numberBits);
|
|
3767
3797
|
bs._bits.set(bits);
|
|
3768
3798
|
return bs;
|
|
@@ -3774,9 +3804,9 @@ class BitString {
|
|
|
3774
3804
|
* @throws GeneralError if the index is out of range.
|
|
3775
3805
|
*/
|
|
3776
3806
|
getBit(index) {
|
|
3777
|
-
Guards.integer(BitString.
|
|
3807
|
+
Guards.integer(BitString.CLASS_NAME, "index", index);
|
|
3778
3808
|
if (index < 0 || index >= this._numberBits) {
|
|
3779
|
-
throw new GeneralError(BitString.
|
|
3809
|
+
throw new GeneralError(BitString.CLASS_NAME, "outOfRange", {
|
|
3780
3810
|
index,
|
|
3781
3811
|
numberBits: this._numberBits
|
|
3782
3812
|
});
|
|
@@ -3793,7 +3823,7 @@ class BitString {
|
|
|
3793
3823
|
*/
|
|
3794
3824
|
setBit(index, value) {
|
|
3795
3825
|
if (index < 0 || index >= this._numberBits) {
|
|
3796
|
-
throw new GeneralError(BitString.
|
|
3826
|
+
throw new GeneralError(BitString.CLASS_NAME, "outOfRange", {
|
|
3797
3827
|
index,
|
|
3798
3828
|
numberBits: this._numberBits
|
|
3799
3829
|
});
|
|
@@ -3829,9 +3859,8 @@ class BitString {
|
|
|
3829
3859
|
class Url {
|
|
3830
3860
|
/**
|
|
3831
3861
|
* Runtime name for the class.
|
|
3832
|
-
* @internal
|
|
3833
3862
|
*/
|
|
3834
|
-
static
|
|
3863
|
+
static CLASS_NAME = "Url";
|
|
3835
3864
|
/**
|
|
3836
3865
|
* The internal representation of the url.
|
|
3837
3866
|
* @internal
|
|
@@ -3842,13 +3871,13 @@ class Url {
|
|
|
3842
3871
|
* @param url The url string.
|
|
3843
3872
|
*/
|
|
3844
3873
|
constructor(url) {
|
|
3845
|
-
Guards.stringValue(Url.
|
|
3874
|
+
Guards.stringValue(Url.CLASS_NAME, "url", url);
|
|
3846
3875
|
try {
|
|
3847
3876
|
const u = new URL(url);
|
|
3848
3877
|
this._urlParts = Url.fromURLToParts(u);
|
|
3849
3878
|
}
|
|
3850
3879
|
catch {
|
|
3851
|
-
throw new GuardError(Url.
|
|
3880
|
+
throw new GuardError(Url.CLASS_NAME, "guard.url", "url", url);
|
|
3852
3881
|
}
|
|
3853
3882
|
}
|
|
3854
3883
|
/**
|
|
@@ -3887,13 +3916,15 @@ class Url {
|
|
|
3887
3916
|
* @param property Throw an exception if the url property is invalid.
|
|
3888
3917
|
* @param value The url to parse.
|
|
3889
3918
|
* @param failures The list of failures to add to.
|
|
3919
|
+
* @param fieldNameResource The optional human readable name for the field as an i18 resource.
|
|
3890
3920
|
* @returns The formatted url.
|
|
3891
3921
|
*/
|
|
3892
|
-
static validate(property, value, failures) {
|
|
3922
|
+
static validate(property, value, failures, fieldNameResource) {
|
|
3893
3923
|
if (!Is.stringValue(value)) {
|
|
3894
3924
|
failures.push({
|
|
3895
3925
|
property,
|
|
3896
|
-
reason: "validation.
|
|
3926
|
+
reason: "validation.beNotEmpty",
|
|
3927
|
+
properties: { fieldName: fieldNameResource ?? "validation.defaultFieldName", value }
|
|
3897
3928
|
});
|
|
3898
3929
|
return false;
|
|
3899
3930
|
}
|
|
@@ -3901,7 +3932,8 @@ class Url {
|
|
|
3901
3932
|
if (Is.undefined(result)) {
|
|
3902
3933
|
failures.push({
|
|
3903
3934
|
property,
|
|
3904
|
-
reason: "validation.beUrl"
|
|
3935
|
+
reason: "validation.beUrl",
|
|
3936
|
+
properties: { fieldName: fieldNameResource ?? "validation.defaultFieldName", value }
|
|
3905
3937
|
});
|
|
3906
3938
|
return false;
|
|
3907
3939
|
}
|
|
@@ -3967,9 +3999,8 @@ class Url {
|
|
|
3967
3999
|
class Urn {
|
|
3968
4000
|
/**
|
|
3969
4001
|
* Runtime name for the class.
|
|
3970
|
-
* @internal
|
|
3971
4002
|
*/
|
|
3972
|
-
static
|
|
4003
|
+
static CLASS_NAME = "Urn";
|
|
3973
4004
|
/**
|
|
3974
4005
|
* The specific part of the namespace.
|
|
3975
4006
|
* @internal
|
|
@@ -3981,15 +4012,15 @@ class Urn {
|
|
|
3981
4012
|
* @param namespaceSpecific The specific part of the namespace.
|
|
3982
4013
|
*/
|
|
3983
4014
|
constructor(namespaceIdentifier, namespaceSpecific) {
|
|
3984
|
-
Guards.stringValue(Urn.
|
|
4015
|
+
Guards.stringValue(Urn.CLASS_NAME, "namespaceIdentifier", namespaceIdentifier);
|
|
3985
4016
|
// Strip leading and trailing colons
|
|
3986
4017
|
this._urnParts = [this.stripColons(namespaceIdentifier)];
|
|
3987
4018
|
if (Is.array(namespaceSpecific)) {
|
|
3988
|
-
Guards.arrayValue(Urn.
|
|
4019
|
+
Guards.arrayValue(Urn.CLASS_NAME, "namespaceSpecific", namespaceSpecific);
|
|
3989
4020
|
this._urnParts.push(...namespaceSpecific);
|
|
3990
4021
|
}
|
|
3991
4022
|
else {
|
|
3992
|
-
Guards.stringValue(Urn.
|
|
4023
|
+
Guards.stringValue(Urn.CLASS_NAME, "namespaceSpecific", namespaceSpecific);
|
|
3993
4024
|
this._urnParts.push(...this.stripColons(namespaceSpecific).split(":"));
|
|
3994
4025
|
}
|
|
3995
4026
|
}
|
|
@@ -4089,13 +4120,15 @@ class Urn {
|
|
|
4089
4120
|
* @param property Throw an exception if the urn property is invalid.
|
|
4090
4121
|
* @param value The urn to parse.
|
|
4091
4122
|
* @param failures The list of failures to add to.
|
|
4123
|
+
* @param fieldNameResource The optional human readable name for the field as an i18 resource.
|
|
4092
4124
|
* @returns The formatted urn.
|
|
4093
4125
|
*/
|
|
4094
|
-
static validate(property, value, failures) {
|
|
4126
|
+
static validate(property, value, failures, fieldNameResource) {
|
|
4095
4127
|
if (!Is.stringValue(value)) {
|
|
4096
4128
|
failures.push({
|
|
4097
4129
|
property,
|
|
4098
|
-
reason: "validation.
|
|
4130
|
+
reason: "validation.beNotEmpty",
|
|
4131
|
+
properties: { fieldName: fieldNameResource ?? "validation.defaultFieldName", value }
|
|
4099
4132
|
});
|
|
4100
4133
|
return false;
|
|
4101
4134
|
}
|
|
@@ -4103,7 +4136,8 @@ class Urn {
|
|
|
4103
4136
|
if (Is.undefined(result)) {
|
|
4104
4137
|
failures.push({
|
|
4105
4138
|
property,
|
|
4106
|
-
reason: "validation.beUrn"
|
|
4139
|
+
reason: "validation.beUrn",
|
|
4140
|
+
properties: { fieldName: fieldNameResource ?? "validation.defaultFieldName", value }
|
|
4107
4141
|
});
|
|
4108
4142
|
return false;
|
|
4109
4143
|
}
|
|
@@ -4349,9 +4383,8 @@ class AsyncCache {
|
|
|
4349
4383
|
class Compression {
|
|
4350
4384
|
/**
|
|
4351
4385
|
* Runtime name for the class.
|
|
4352
|
-
* @internal
|
|
4353
4386
|
*/
|
|
4354
|
-
static
|
|
4387
|
+
static CLASS_NAME = "Compression";
|
|
4355
4388
|
/**
|
|
4356
4389
|
* Compress bytes using GZIP.
|
|
4357
4390
|
* @param bytes The bytes to compress.
|
|
@@ -4359,8 +4392,8 @@ class Compression {
|
|
|
4359
4392
|
* @returns The compressed bytes.
|
|
4360
4393
|
*/
|
|
4361
4394
|
static async compress(bytes, type) {
|
|
4362
|
-
Guards.uint8Array(Compression.
|
|
4363
|
-
Guards.arrayOneOf(Compression.
|
|
4395
|
+
Guards.uint8Array(Compression.CLASS_NAME, "bytes", bytes);
|
|
4396
|
+
Guards.arrayOneOf(Compression.CLASS_NAME, "type", type, Object.values(CompressionType));
|
|
4364
4397
|
const blob = new Blob([new Uint8Array(bytes)]);
|
|
4365
4398
|
const compressionStream = new CompressionStream(type);
|
|
4366
4399
|
const compressionPipe = blob.stream().pipeThrough(compressionStream);
|
|
@@ -4381,8 +4414,8 @@ class Compression {
|
|
|
4381
4414
|
* @returns The decompressed bytes.
|
|
4382
4415
|
*/
|
|
4383
4416
|
static async decompress(compressedBytes, type) {
|
|
4384
|
-
Guards.uint8Array(Compression.
|
|
4385
|
-
Guards.arrayOneOf(Compression.
|
|
4417
|
+
Guards.uint8Array(Compression.CLASS_NAME, "compressedBytes", compressedBytes);
|
|
4418
|
+
Guards.arrayOneOf(Compression.CLASS_NAME, "type", type, Object.values(CompressionType));
|
|
4386
4419
|
const blob = new Blob([new Uint8Array(compressedBytes)]);
|
|
4387
4420
|
const decompressionStream = new DecompressionStream(type);
|
|
4388
4421
|
const decompressionPipe = blob.stream().pipeThrough(decompressionStream);
|
|
@@ -4411,8 +4444,7 @@ class Validation {
|
|
|
4411
4444
|
failures.push({
|
|
4412
4445
|
property,
|
|
4413
4446
|
reason: "validation.beEmpty",
|
|
4414
|
-
fieldName: fieldNameResource ?? "validation.defaultFieldName",
|
|
4415
|
-
properties: { value }
|
|
4447
|
+
properties: { fieldName: fieldNameResource ?? "validation.defaultFieldName", value }
|
|
4416
4448
|
});
|
|
4417
4449
|
}
|
|
4418
4450
|
return is;
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
* Class to help with base63 Encoding/Decoding.
|
|
3
3
|
*/
|
|
4
4
|
export declare class Base32 {
|
|
5
|
+
/**
|
|
6
|
+
* Runtime name for the class.
|
|
7
|
+
*/
|
|
8
|
+
static readonly CLASS_NAME: string;
|
|
5
9
|
/**
|
|
6
10
|
* Convert the base 32 string to a byte array.
|
|
7
11
|
* @param base32 The base32 string to convert.
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
* Class to help with base58 Encoding/Decoding.
|
|
3
3
|
*/
|
|
4
4
|
export declare class Base58 {
|
|
5
|
+
/**
|
|
6
|
+
* Runtime name for the class.
|
|
7
|
+
*/
|
|
8
|
+
static readonly CLASS_NAME: string;
|
|
5
9
|
/**
|
|
6
10
|
* Convert the base 58 string to a byte array.
|
|
7
11
|
* @param base58 The base58 string to convert.
|
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
* https://www.rfc-editor.org/rfc/rfc4648#section-5.
|
|
4
4
|
*/
|
|
5
5
|
export declare class Base64Url {
|
|
6
|
+
/**
|
|
7
|
+
* Runtime name for the class.
|
|
8
|
+
*/
|
|
9
|
+
static readonly CLASS_NAME: string;
|
|
6
10
|
/**
|
|
7
11
|
* Convert the base 64 string to a byte array.
|
|
8
12
|
* @param base64Url The base64 url string to convert.
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
* Factory for creating implementation of generic types.
|
|
3
3
|
*/
|
|
4
4
|
export declare class Factory<T> {
|
|
5
|
+
/**
|
|
6
|
+
* Runtime name for the class.
|
|
7
|
+
*/
|
|
8
|
+
static readonly CLASS_NAME: string;
|
|
5
9
|
/**
|
|
6
10
|
* Create a new factory, which is shared throughout all library instances.
|
|
7
11
|
* @param typeName The type name for the instances.
|