@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/cjs/index.cjs
CHANGED
|
@@ -331,6 +331,8 @@ class Is {
|
|
|
331
331
|
* @returns True if the value is a Uint8Array.
|
|
332
332
|
*/
|
|
333
333
|
static uint8Array(value) {
|
|
334
|
+
// This is the only way we can reliably check for Uint8Array
|
|
335
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
334
336
|
return value instanceof Uint8Array;
|
|
335
337
|
}
|
|
336
338
|
/**
|
|
@@ -339,6 +341,8 @@ class Is {
|
|
|
339
341
|
* @returns True if the value is a TypedArray.
|
|
340
342
|
*/
|
|
341
343
|
static typedArray(value) {
|
|
344
|
+
// This is the only way we can reliably check for TypedArray
|
|
345
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
342
346
|
return value instanceof Object.getPrototypeOf(Uint8Array);
|
|
343
347
|
}
|
|
344
348
|
/**
|
|
@@ -346,6 +350,7 @@ class Is {
|
|
|
346
350
|
* @param value The value to test.
|
|
347
351
|
* @returns True if the value is a function.
|
|
348
352
|
*/
|
|
353
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
349
354
|
static function(value) {
|
|
350
355
|
return typeof value === "function";
|
|
351
356
|
}
|
|
@@ -364,6 +369,8 @@ class Is {
|
|
|
364
369
|
* @returns True if the value is a promise.
|
|
365
370
|
*/
|
|
366
371
|
static promise(value) {
|
|
372
|
+
// This is the only way we can reliably check for Promise
|
|
373
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
367
374
|
return value instanceof Promise;
|
|
368
375
|
}
|
|
369
376
|
/**
|
|
@@ -372,6 +379,8 @@ class Is {
|
|
|
372
379
|
* @returns True if the value is a regexp.
|
|
373
380
|
*/
|
|
374
381
|
static regexp(value) {
|
|
382
|
+
// This is the only way we can reliably check for RegExp
|
|
383
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
375
384
|
return value instanceof RegExp;
|
|
376
385
|
}
|
|
377
386
|
/**
|
|
@@ -839,6 +848,8 @@ class BaseError extends Error {
|
|
|
839
848
|
* @returns True if the error is an aggregate error.
|
|
840
849
|
*/
|
|
841
850
|
static isAggregateError(err) {
|
|
851
|
+
// This is the only way we can reliably check for AggregateError
|
|
852
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
842
853
|
return err instanceof AggregateError;
|
|
843
854
|
}
|
|
844
855
|
/**
|
|
@@ -1036,7 +1047,7 @@ class Guards {
|
|
|
1036
1047
|
*/
|
|
1037
1048
|
static stringBase64(source, property, value) {
|
|
1038
1049
|
if (!Is.stringBase64(value)) {
|
|
1039
|
-
throw new GuardError(source, "guard.
|
|
1050
|
+
throw new GuardError(source, "guard.stringBase64", property, value);
|
|
1040
1051
|
}
|
|
1041
1052
|
}
|
|
1042
1053
|
/**
|
|
@@ -1048,7 +1059,7 @@ class Guards {
|
|
|
1048
1059
|
*/
|
|
1049
1060
|
static stringBase64Url(source, property, value) {
|
|
1050
1061
|
if (!Is.stringBase64Url(value)) {
|
|
1051
|
-
throw new GuardError(source, "guard.
|
|
1062
|
+
throw new GuardError(source, "guard.stringBase64Url", property, value);
|
|
1052
1063
|
}
|
|
1053
1064
|
}
|
|
1054
1065
|
/**
|
|
@@ -1060,7 +1071,7 @@ class Guards {
|
|
|
1060
1071
|
*/
|
|
1061
1072
|
static stringBase58(source, property, value) {
|
|
1062
1073
|
if (!Is.stringBase58(value)) {
|
|
1063
|
-
throw new GuardError(source, "guard.
|
|
1074
|
+
throw new GuardError(source, "guard.stringBase58", property, value);
|
|
1064
1075
|
}
|
|
1065
1076
|
}
|
|
1066
1077
|
/**
|
|
@@ -1345,9 +1356,8 @@ class Guards {
|
|
|
1345
1356
|
class Base32 {
|
|
1346
1357
|
/**
|
|
1347
1358
|
* Runtime name for the class.
|
|
1348
|
-
* @internal
|
|
1349
1359
|
*/
|
|
1350
|
-
static
|
|
1360
|
+
static CLASS_NAME = "Base32";
|
|
1351
1361
|
/**
|
|
1352
1362
|
* Alphabet table for encoding.
|
|
1353
1363
|
* @internal
|
|
@@ -1360,7 +1370,7 @@ class Base32 {
|
|
|
1360
1370
|
* @throws If the input string contains a character not in the Base32 alphabet.
|
|
1361
1371
|
*/
|
|
1362
1372
|
static decode(base32) {
|
|
1363
|
-
Guards.string(Base32.
|
|
1373
|
+
Guards.string(Base32.CLASS_NAME, "base32", base32);
|
|
1364
1374
|
let bits = 0;
|
|
1365
1375
|
let value = 0;
|
|
1366
1376
|
base32 = base32.replace(/=+$/, "");
|
|
@@ -1369,7 +1379,7 @@ class Base32 {
|
|
|
1369
1379
|
for (let i = 0; i < base32.length; i++) {
|
|
1370
1380
|
const idx = Base32._ALPHABET.indexOf(base32[i]);
|
|
1371
1381
|
if (idx === -1) {
|
|
1372
|
-
throw new GeneralError(Base32.
|
|
1382
|
+
throw new GeneralError(Base32.CLASS_NAME, "invalidCharacter", {
|
|
1373
1383
|
invalidCharacter: base32[i]
|
|
1374
1384
|
});
|
|
1375
1385
|
}
|
|
@@ -1388,7 +1398,7 @@ class Base32 {
|
|
|
1388
1398
|
* @returns The data as base32 string.
|
|
1389
1399
|
*/
|
|
1390
1400
|
static encode(bytes) {
|
|
1391
|
-
Guards.uint8Array(Base32.
|
|
1401
|
+
Guards.uint8Array(Base32.CLASS_NAME, "bytes", bytes);
|
|
1392
1402
|
let bits = 0;
|
|
1393
1403
|
let value = 0;
|
|
1394
1404
|
let output = "";
|
|
@@ -1416,9 +1426,8 @@ class Base32 {
|
|
|
1416
1426
|
class Base58 {
|
|
1417
1427
|
/**
|
|
1418
1428
|
* Runtime name for the class.
|
|
1419
|
-
* @internal
|
|
1420
1429
|
*/
|
|
1421
|
-
static
|
|
1430
|
+
static CLASS_NAME = "Base58";
|
|
1422
1431
|
/**
|
|
1423
1432
|
* Alphabet table for encoding.
|
|
1424
1433
|
* @internal
|
|
@@ -1445,7 +1454,7 @@ class Base58 {
|
|
|
1445
1454
|
* @throws If the input string contains a character not in the Base58 alphabet.
|
|
1446
1455
|
*/
|
|
1447
1456
|
static decode(base58) {
|
|
1448
|
-
Guards.string(Base58.
|
|
1457
|
+
Guards.string(Base58.CLASS_NAME, "base58", base58);
|
|
1449
1458
|
let zeroes = 0;
|
|
1450
1459
|
for (let i = 0; i < base58.length; i++) {
|
|
1451
1460
|
if (base58[i] !== "1") {
|
|
@@ -1459,11 +1468,11 @@ class Base58 {
|
|
|
1459
1468
|
for (let i = zeroes; i < base58.length; i++) {
|
|
1460
1469
|
const ch = base58.charCodeAt(i);
|
|
1461
1470
|
if (ch & 0xff80) {
|
|
1462
|
-
throw new GeneralError(Base58.
|
|
1471
|
+
throw new GeneralError(Base58.CLASS_NAME, "invalidCharacter", { invalidCharacter: ch });
|
|
1463
1472
|
}
|
|
1464
1473
|
const val = Base58._ALPHABET_REVERSE[ch];
|
|
1465
1474
|
if (val === -1) {
|
|
1466
|
-
throw new GeneralError(Base58.
|
|
1475
|
+
throw new GeneralError(Base58.CLASS_NAME, "invalidCharacter", { invalidCharacter: ch });
|
|
1467
1476
|
}
|
|
1468
1477
|
let carry = val;
|
|
1469
1478
|
let j = 0;
|
|
@@ -1494,7 +1503,7 @@ class Base58 {
|
|
|
1494
1503
|
* @returns The data as base58 string.
|
|
1495
1504
|
*/
|
|
1496
1505
|
static encode(bytes) {
|
|
1497
|
-
Guards.uint8Array(Base58.
|
|
1506
|
+
Guards.uint8Array(Base58.CLASS_NAME, "bytes", bytes);
|
|
1498
1507
|
let zeroes = 0;
|
|
1499
1508
|
for (let i = 0; i < bytes.length; i++) {
|
|
1500
1509
|
if (bytes[i] !== 0) {
|
|
@@ -1544,9 +1553,8 @@ class Base58 {
|
|
|
1544
1553
|
class Base64 {
|
|
1545
1554
|
/**
|
|
1546
1555
|
* Runtime name for the class.
|
|
1547
|
-
* @internal
|
|
1548
1556
|
*/
|
|
1549
|
-
static
|
|
1557
|
+
static CLASS_NAME = "Base64";
|
|
1550
1558
|
/**
|
|
1551
1559
|
* Alphabet table for encoding.
|
|
1552
1560
|
* @internal
|
|
@@ -1639,7 +1647,7 @@ class Base64 {
|
|
|
1639
1647
|
* @returns The byte array.
|
|
1640
1648
|
*/
|
|
1641
1649
|
static decode(base64) {
|
|
1642
|
-
Guards.string(Base64.
|
|
1650
|
+
Guards.string(Base64.CLASS_NAME, "base64", base64);
|
|
1643
1651
|
let tmp;
|
|
1644
1652
|
const lens = Base64.getLengths(base64);
|
|
1645
1653
|
const validLen = lens[0];
|
|
@@ -1681,7 +1689,7 @@ class Base64 {
|
|
|
1681
1689
|
* @returns The data as base64 string.
|
|
1682
1690
|
*/
|
|
1683
1691
|
static encode(bytes) {
|
|
1684
|
-
Guards.uint8Array(Base64.
|
|
1692
|
+
Guards.uint8Array(Base64.CLASS_NAME, "bytes", bytes);
|
|
1685
1693
|
let tmp;
|
|
1686
1694
|
const len = bytes.length;
|
|
1687
1695
|
const extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes
|
|
@@ -1721,7 +1729,7 @@ class Base64 {
|
|
|
1721
1729
|
static getLengths(base64) {
|
|
1722
1730
|
const len = base64.length;
|
|
1723
1731
|
if (len % 4 > 0) {
|
|
1724
|
-
throw new GeneralError(Base64.
|
|
1732
|
+
throw new GeneralError(Base64.CLASS_NAME, "length4Multiple", { value: len });
|
|
1725
1733
|
}
|
|
1726
1734
|
// Trim off extra bytes after placeholder bytes are found
|
|
1727
1735
|
// See: https://github.com/beatgammit/base64-js/issues/42
|
|
@@ -1770,16 +1778,15 @@ class Base64 {
|
|
|
1770
1778
|
class Base64Url {
|
|
1771
1779
|
/**
|
|
1772
1780
|
* Runtime name for the class.
|
|
1773
|
-
* @internal
|
|
1774
1781
|
*/
|
|
1775
|
-
static
|
|
1782
|
+
static CLASS_NAME = "Base64";
|
|
1776
1783
|
/**
|
|
1777
1784
|
* Convert the base 64 string to a byte array.
|
|
1778
1785
|
* @param base64Url The base64 url string to convert.
|
|
1779
1786
|
* @returns The byte array.
|
|
1780
1787
|
*/
|
|
1781
1788
|
static decode(base64Url) {
|
|
1782
|
-
Guards.string(Base64Url.
|
|
1789
|
+
Guards.string(Base64Url.CLASS_NAME, "base64Url", base64Url);
|
|
1783
1790
|
let base64 = base64Url;
|
|
1784
1791
|
// Base 64 url can have padding removed, so add it back if it is missing.
|
|
1785
1792
|
if (base64.length > 0 && !base64.endsWith("=")) {
|
|
@@ -1797,7 +1804,7 @@ class Base64Url {
|
|
|
1797
1804
|
* @returns The data as base64 url string.
|
|
1798
1805
|
*/
|
|
1799
1806
|
static encode(bytes) {
|
|
1800
|
-
Guards.uint8Array(Base64Url.
|
|
1807
|
+
Guards.uint8Array(Base64Url.CLASS_NAME, "bytes", bytes);
|
|
1801
1808
|
const base64 = Base64.encode(bytes);
|
|
1802
1809
|
// Base 64 url can have padding removed, so remove it.
|
|
1803
1810
|
return base64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
@@ -2026,9 +2033,8 @@ class SharedStore {
|
|
|
2026
2033
|
class Factory {
|
|
2027
2034
|
/**
|
|
2028
2035
|
* Runtime name for the class.
|
|
2029
|
-
* @internal
|
|
2030
2036
|
*/
|
|
2031
|
-
static
|
|
2037
|
+
static CLASS_NAME = "Factory";
|
|
2032
2038
|
/**
|
|
2033
2039
|
* Type name for the instances.
|
|
2034
2040
|
* @internal
|
|
@@ -2124,8 +2130,8 @@ class Factory {
|
|
|
2124
2130
|
* @param generator The function to create an instance.
|
|
2125
2131
|
*/
|
|
2126
2132
|
register(name, generator) {
|
|
2127
|
-
Guards.stringValue(Factory.
|
|
2128
|
-
Guards.function(Factory.
|
|
2133
|
+
Guards.stringValue(Factory.CLASS_NAME, "name", name);
|
|
2134
|
+
Guards.function(Factory.CLASS_NAME, "generator", generator);
|
|
2129
2135
|
this._generators[name] = {
|
|
2130
2136
|
generator,
|
|
2131
2137
|
order: this._orderCounter++
|
|
@@ -2143,9 +2149,9 @@ class Factory {
|
|
|
2143
2149
|
* @throws GeneralError if no generator exists.
|
|
2144
2150
|
*/
|
|
2145
2151
|
unregister(name) {
|
|
2146
|
-
Guards.stringValue(Factory.
|
|
2152
|
+
Guards.stringValue(Factory.CLASS_NAME, "name", name);
|
|
2147
2153
|
if (!this._generators[name]) {
|
|
2148
|
-
throw new GeneralError(Factory.
|
|
2154
|
+
throw new GeneralError(Factory.CLASS_NAME, "noUnregister", {
|
|
2149
2155
|
typeName: this._typeName,
|
|
2150
2156
|
name
|
|
2151
2157
|
});
|
|
@@ -2162,10 +2168,10 @@ class Factory {
|
|
|
2162
2168
|
* @throws GeneralError if no item exists to get.
|
|
2163
2169
|
*/
|
|
2164
2170
|
get(name) {
|
|
2165
|
-
Guards.stringValue(Factory.
|
|
2171
|
+
Guards.stringValue(Factory.CLASS_NAME, "name", name);
|
|
2166
2172
|
const instance = this.getIfExists(name);
|
|
2167
2173
|
if (!instance) {
|
|
2168
|
-
throw new GeneralError(Factory.
|
|
2174
|
+
throw new GeneralError(Factory.CLASS_NAME, "noGet", {
|
|
2169
2175
|
typeName: this._typeName,
|
|
2170
2176
|
name
|
|
2171
2177
|
});
|
|
@@ -2181,7 +2187,7 @@ class Factory {
|
|
|
2181
2187
|
if (Is.empty(name)) {
|
|
2182
2188
|
return;
|
|
2183
2189
|
}
|
|
2184
|
-
Guards.stringValue(Factory.
|
|
2190
|
+
Guards.stringValue(Factory.CLASS_NAME, "name", name);
|
|
2185
2191
|
const matchName = this._matcher(Object.keys(this._generators), name);
|
|
2186
2192
|
if (Is.stringValue(matchName) && this._generators[matchName]) {
|
|
2187
2193
|
if (!this._instances[matchName]) {
|
|
@@ -2250,7 +2256,7 @@ class Factory {
|
|
|
2250
2256
|
* @returns True if the factory has a matching name.
|
|
2251
2257
|
*/
|
|
2252
2258
|
hasName(name) {
|
|
2253
|
-
Guards.stringValue(Factory.
|
|
2259
|
+
Guards.stringValue(Factory.CLASS_NAME, "name", name);
|
|
2254
2260
|
return Is.stringValue(this._matcher(Object.keys(this._generators), name));
|
|
2255
2261
|
}
|
|
2256
2262
|
/**
|
|
@@ -2376,7 +2382,7 @@ class Converter {
|
|
|
2376
2382
|
*/
|
|
2377
2383
|
static bytesToHex(array, includePrefix = false, startIndex, length, reverse) {
|
|
2378
2384
|
let hex = "";
|
|
2379
|
-
|
|
2385
|
+
Converter.buildHexLookups();
|
|
2380
2386
|
if (Converter._ENCODE_LOOKUP) {
|
|
2381
2387
|
const len = length ?? array.length;
|
|
2382
2388
|
const start = startIndex ?? 0;
|
|
@@ -2404,7 +2410,7 @@ class Converter {
|
|
|
2404
2410
|
const sizeof = strippedHex.length >> 1;
|
|
2405
2411
|
const length = sizeof << 1;
|
|
2406
2412
|
const array = new Uint8Array(sizeof);
|
|
2407
|
-
|
|
2413
|
+
Converter.buildHexLookups();
|
|
2408
2414
|
if (Converter._DECODE_LOOKUP) {
|
|
2409
2415
|
let i = 0;
|
|
2410
2416
|
let n = 0;
|
|
@@ -2539,9 +2545,8 @@ class Converter {
|
|
|
2539
2545
|
class JsonHelper {
|
|
2540
2546
|
/**
|
|
2541
2547
|
* Runtime name for the class.
|
|
2542
|
-
* @internal
|
|
2543
2548
|
*/
|
|
2544
|
-
static
|
|
2549
|
+
static CLASS_NAME = "JsonHelper";
|
|
2545
2550
|
/**
|
|
2546
2551
|
* Serializes in canonical format.
|
|
2547
2552
|
* Based on https://www.rfc-editor.org/rfc/rfc8785.
|
|
@@ -2552,7 +2557,7 @@ class JsonHelper {
|
|
|
2552
2557
|
const buffer = [];
|
|
2553
2558
|
if (object === null ||
|
|
2554
2559
|
typeof object !== "object" ||
|
|
2555
|
-
("toJSON" in object && object.toJSON
|
|
2560
|
+
("toJSON" in object && Is.function(object.toJSON))) {
|
|
2556
2561
|
// Primitive data type
|
|
2557
2562
|
buffer.push(JSON.stringify(object));
|
|
2558
2563
|
}
|
|
@@ -2607,7 +2612,7 @@ class JsonHelper {
|
|
|
2607
2612
|
const result = rfc6902.applyPatch(clone, patches);
|
|
2608
2613
|
for (let i = 0; i < result.length; i++) {
|
|
2609
2614
|
if (!Is.empty(result[i])) {
|
|
2610
|
-
throw new GeneralError(JsonHelper.
|
|
2615
|
+
throw new GeneralError(JsonHelper.CLASS_NAME, "failedPatch", { index: i }, result[i]);
|
|
2611
2616
|
}
|
|
2612
2617
|
}
|
|
2613
2618
|
return clone;
|
|
@@ -2644,6 +2649,9 @@ class JsonHelper {
|
|
|
2644
2649
|
*/
|
|
2645
2650
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2646
2651
|
static stringifyExReplacer(key, value) {
|
|
2652
|
+
// The this in the replacer is the containing object
|
|
2653
|
+
// so we need to get the actual value from there
|
|
2654
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
2647
2655
|
const rawValue = this[key];
|
|
2648
2656
|
if (Is.bigint(rawValue)) {
|
|
2649
2657
|
return {
|
|
@@ -2695,9 +2703,8 @@ class JsonHelper {
|
|
|
2695
2703
|
class ObjectHelper {
|
|
2696
2704
|
/**
|
|
2697
2705
|
* Runtime name for the class.
|
|
2698
|
-
* @internal
|
|
2699
2706
|
*/
|
|
2700
|
-
static
|
|
2707
|
+
static CLASS_NAME = "ObjectHelper";
|
|
2701
2708
|
/**
|
|
2702
2709
|
* Convert an object to bytes.
|
|
2703
2710
|
* @param obj The object to convert.
|
|
@@ -2726,7 +2733,7 @@ class ObjectHelper {
|
|
|
2726
2733
|
return JSON.parse(utf8);
|
|
2727
2734
|
}
|
|
2728
2735
|
catch (err) {
|
|
2729
|
-
throw new GeneralError(ObjectHelper.
|
|
2736
|
+
throw new GeneralError(ObjectHelper.CLASS_NAME, "failedBytesToJSON", undefined, err);
|
|
2730
2737
|
}
|
|
2731
2738
|
}
|
|
2732
2739
|
/**
|
|
@@ -2839,7 +2846,7 @@ class ObjectHelper {
|
|
|
2839
2846
|
pathValue[arrayIndex] = value;
|
|
2840
2847
|
}
|
|
2841
2848
|
else {
|
|
2842
|
-
throw new GeneralError(ObjectHelper.
|
|
2849
|
+
throw new GeneralError(ObjectHelper.CLASS_NAME, "cannotSetArrayIndex", {
|
|
2843
2850
|
property,
|
|
2844
2851
|
index: arrayIndex
|
|
2845
2852
|
});
|
|
@@ -2849,7 +2856,7 @@ class ObjectHelper {
|
|
|
2849
2856
|
pathValue[pathPart] = value;
|
|
2850
2857
|
}
|
|
2851
2858
|
else {
|
|
2852
|
-
throw new GeneralError(ObjectHelper.
|
|
2859
|
+
throw new GeneralError(ObjectHelper.CLASS_NAME, "cannotSetProperty", { property });
|
|
2853
2860
|
}
|
|
2854
2861
|
}
|
|
2855
2862
|
else {
|
|
@@ -3191,7 +3198,6 @@ class I18n {
|
|
|
3191
3198
|
* @param translation The translation to merge.
|
|
3192
3199
|
* @param propertyPath The current root path.
|
|
3193
3200
|
* @param mergedKeys The merged keys dictionary to populate.
|
|
3194
|
-
* @internal
|
|
3195
3201
|
*/
|
|
3196
3202
|
static flattenTranslationKeys(translation, propertyPath, mergedKeys) {
|
|
3197
3203
|
for (const key in translation) {
|
|
@@ -3205,6 +3211,31 @@ class I18n {
|
|
|
3205
3211
|
}
|
|
3206
3212
|
}
|
|
3207
3213
|
}
|
|
3214
|
+
/**
|
|
3215
|
+
* Get a list of the property names from the message.
|
|
3216
|
+
* @param message The message to extract the property names from.
|
|
3217
|
+
* @returns The list of property names.
|
|
3218
|
+
*/
|
|
3219
|
+
static getPropertyNames(message) {
|
|
3220
|
+
const properties = new Set();
|
|
3221
|
+
// Handle basic placeholders: {property}
|
|
3222
|
+
const basicRegex = /{([$A-Z_a-z][\w$]*)}/g;
|
|
3223
|
+
let match;
|
|
3224
|
+
while ((match = basicRegex.exec(message)) !== null) {
|
|
3225
|
+
properties.add(match[1]);
|
|
3226
|
+
}
|
|
3227
|
+
// Handle ICU format with types: {property, number}, {property, date}, etc.
|
|
3228
|
+
const icuRegex = /{([$A-Z_a-z][\w$]*)\s*,\s*\w+/g;
|
|
3229
|
+
while ((match = icuRegex.exec(message)) !== null) {
|
|
3230
|
+
properties.add(match[1]);
|
|
3231
|
+
}
|
|
3232
|
+
// Handle plural/select: {count, plural, one {1 item} other {# items}}
|
|
3233
|
+
const pluralSelectRegex = /{([$A-Z_a-z][\w$]*)\s*,\s*(plural|select|selectordinal)/g;
|
|
3234
|
+
while ((match = pluralSelectRegex.exec(message)) !== null) {
|
|
3235
|
+
properties.add(match[1]);
|
|
3236
|
+
}
|
|
3237
|
+
return Array.from(properties);
|
|
3238
|
+
}
|
|
3208
3239
|
/**
|
|
3209
3240
|
* Get the I18n shared data.
|
|
3210
3241
|
* @returns The I18n shared data.
|
|
@@ -3734,9 +3765,8 @@ const CompressionType = {
|
|
|
3734
3765
|
class BitString {
|
|
3735
3766
|
/**
|
|
3736
3767
|
* Runtime name for the class.
|
|
3737
|
-
* @internal
|
|
3738
3768
|
*/
|
|
3739
|
-
static
|
|
3769
|
+
static CLASS_NAME = "BitString";
|
|
3740
3770
|
/**
|
|
3741
3771
|
* The storage for the bits.
|
|
3742
3772
|
* @internal
|
|
@@ -3752,7 +3782,7 @@ class BitString {
|
|
|
3752
3782
|
* @param numberBits The length of the bit string.
|
|
3753
3783
|
*/
|
|
3754
3784
|
constructor(numberBits) {
|
|
3755
|
-
Guards.integer(BitString.
|
|
3785
|
+
Guards.integer(BitString.CLASS_NAME, "numberBits", numberBits);
|
|
3756
3786
|
this._numberBits = numberBits;
|
|
3757
3787
|
this._bits = new Uint8Array(Math.ceil(numberBits / 8));
|
|
3758
3788
|
}
|
|
@@ -3763,8 +3793,8 @@ class BitString {
|
|
|
3763
3793
|
* @returns The new instance of BitString.
|
|
3764
3794
|
*/
|
|
3765
3795
|
static fromBits(bits, numberBits) {
|
|
3766
|
-
Guards.uint8Array(BitString.
|
|
3767
|
-
Guards.integer(BitString.
|
|
3796
|
+
Guards.uint8Array(BitString.CLASS_NAME, "bits", bits);
|
|
3797
|
+
Guards.integer(BitString.CLASS_NAME, "numberBits", numberBits);
|
|
3768
3798
|
const bs = new BitString(numberBits);
|
|
3769
3799
|
bs._bits.set(bits);
|
|
3770
3800
|
return bs;
|
|
@@ -3776,9 +3806,9 @@ class BitString {
|
|
|
3776
3806
|
* @throws GeneralError if the index is out of range.
|
|
3777
3807
|
*/
|
|
3778
3808
|
getBit(index) {
|
|
3779
|
-
Guards.integer(BitString.
|
|
3809
|
+
Guards.integer(BitString.CLASS_NAME, "index", index);
|
|
3780
3810
|
if (index < 0 || index >= this._numberBits) {
|
|
3781
|
-
throw new GeneralError(BitString.
|
|
3811
|
+
throw new GeneralError(BitString.CLASS_NAME, "outOfRange", {
|
|
3782
3812
|
index,
|
|
3783
3813
|
numberBits: this._numberBits
|
|
3784
3814
|
});
|
|
@@ -3795,7 +3825,7 @@ class BitString {
|
|
|
3795
3825
|
*/
|
|
3796
3826
|
setBit(index, value) {
|
|
3797
3827
|
if (index < 0 || index >= this._numberBits) {
|
|
3798
|
-
throw new GeneralError(BitString.
|
|
3828
|
+
throw new GeneralError(BitString.CLASS_NAME, "outOfRange", {
|
|
3799
3829
|
index,
|
|
3800
3830
|
numberBits: this._numberBits
|
|
3801
3831
|
});
|
|
@@ -3831,9 +3861,8 @@ class BitString {
|
|
|
3831
3861
|
class Url {
|
|
3832
3862
|
/**
|
|
3833
3863
|
* Runtime name for the class.
|
|
3834
|
-
* @internal
|
|
3835
3864
|
*/
|
|
3836
|
-
static
|
|
3865
|
+
static CLASS_NAME = "Url";
|
|
3837
3866
|
/**
|
|
3838
3867
|
* The internal representation of the url.
|
|
3839
3868
|
* @internal
|
|
@@ -3844,13 +3873,13 @@ class Url {
|
|
|
3844
3873
|
* @param url The url string.
|
|
3845
3874
|
*/
|
|
3846
3875
|
constructor(url) {
|
|
3847
|
-
Guards.stringValue(Url.
|
|
3876
|
+
Guards.stringValue(Url.CLASS_NAME, "url", url);
|
|
3848
3877
|
try {
|
|
3849
3878
|
const u = new URL(url);
|
|
3850
3879
|
this._urlParts = Url.fromURLToParts(u);
|
|
3851
3880
|
}
|
|
3852
3881
|
catch {
|
|
3853
|
-
throw new GuardError(Url.
|
|
3882
|
+
throw new GuardError(Url.CLASS_NAME, "guard.url", "url", url);
|
|
3854
3883
|
}
|
|
3855
3884
|
}
|
|
3856
3885
|
/**
|
|
@@ -3889,13 +3918,15 @@ class Url {
|
|
|
3889
3918
|
* @param property Throw an exception if the url property is invalid.
|
|
3890
3919
|
* @param value The url to parse.
|
|
3891
3920
|
* @param failures The list of failures to add to.
|
|
3921
|
+
* @param fieldNameResource The optional human readable name for the field as an i18 resource.
|
|
3892
3922
|
* @returns The formatted url.
|
|
3893
3923
|
*/
|
|
3894
|
-
static validate(property, value, failures) {
|
|
3924
|
+
static validate(property, value, failures, fieldNameResource) {
|
|
3895
3925
|
if (!Is.stringValue(value)) {
|
|
3896
3926
|
failures.push({
|
|
3897
3927
|
property,
|
|
3898
|
-
reason: "validation.
|
|
3928
|
+
reason: "validation.beNotEmpty",
|
|
3929
|
+
properties: { fieldName: fieldNameResource ?? "validation.defaultFieldName", value }
|
|
3899
3930
|
});
|
|
3900
3931
|
return false;
|
|
3901
3932
|
}
|
|
@@ -3903,7 +3934,8 @@ class Url {
|
|
|
3903
3934
|
if (Is.undefined(result)) {
|
|
3904
3935
|
failures.push({
|
|
3905
3936
|
property,
|
|
3906
|
-
reason: "validation.beUrl"
|
|
3937
|
+
reason: "validation.beUrl",
|
|
3938
|
+
properties: { fieldName: fieldNameResource ?? "validation.defaultFieldName", value }
|
|
3907
3939
|
});
|
|
3908
3940
|
return false;
|
|
3909
3941
|
}
|
|
@@ -3969,9 +4001,8 @@ class Url {
|
|
|
3969
4001
|
class Urn {
|
|
3970
4002
|
/**
|
|
3971
4003
|
* Runtime name for the class.
|
|
3972
|
-
* @internal
|
|
3973
4004
|
*/
|
|
3974
|
-
static
|
|
4005
|
+
static CLASS_NAME = "Urn";
|
|
3975
4006
|
/**
|
|
3976
4007
|
* The specific part of the namespace.
|
|
3977
4008
|
* @internal
|
|
@@ -3983,15 +4014,15 @@ class Urn {
|
|
|
3983
4014
|
* @param namespaceSpecific The specific part of the namespace.
|
|
3984
4015
|
*/
|
|
3985
4016
|
constructor(namespaceIdentifier, namespaceSpecific) {
|
|
3986
|
-
Guards.stringValue(Urn.
|
|
4017
|
+
Guards.stringValue(Urn.CLASS_NAME, "namespaceIdentifier", namespaceIdentifier);
|
|
3987
4018
|
// Strip leading and trailing colons
|
|
3988
4019
|
this._urnParts = [this.stripColons(namespaceIdentifier)];
|
|
3989
4020
|
if (Is.array(namespaceSpecific)) {
|
|
3990
|
-
Guards.arrayValue(Urn.
|
|
4021
|
+
Guards.arrayValue(Urn.CLASS_NAME, "namespaceSpecific", namespaceSpecific);
|
|
3991
4022
|
this._urnParts.push(...namespaceSpecific);
|
|
3992
4023
|
}
|
|
3993
4024
|
else {
|
|
3994
|
-
Guards.stringValue(Urn.
|
|
4025
|
+
Guards.stringValue(Urn.CLASS_NAME, "namespaceSpecific", namespaceSpecific);
|
|
3995
4026
|
this._urnParts.push(...this.stripColons(namespaceSpecific).split(":"));
|
|
3996
4027
|
}
|
|
3997
4028
|
}
|
|
@@ -4091,13 +4122,15 @@ class Urn {
|
|
|
4091
4122
|
* @param property Throw an exception if the urn property is invalid.
|
|
4092
4123
|
* @param value The urn to parse.
|
|
4093
4124
|
* @param failures The list of failures to add to.
|
|
4125
|
+
* @param fieldNameResource The optional human readable name for the field as an i18 resource.
|
|
4094
4126
|
* @returns The formatted urn.
|
|
4095
4127
|
*/
|
|
4096
|
-
static validate(property, value, failures) {
|
|
4128
|
+
static validate(property, value, failures, fieldNameResource) {
|
|
4097
4129
|
if (!Is.stringValue(value)) {
|
|
4098
4130
|
failures.push({
|
|
4099
4131
|
property,
|
|
4100
|
-
reason: "validation.
|
|
4132
|
+
reason: "validation.beNotEmpty",
|
|
4133
|
+
properties: { fieldName: fieldNameResource ?? "validation.defaultFieldName", value }
|
|
4101
4134
|
});
|
|
4102
4135
|
return false;
|
|
4103
4136
|
}
|
|
@@ -4105,7 +4138,8 @@ class Urn {
|
|
|
4105
4138
|
if (Is.undefined(result)) {
|
|
4106
4139
|
failures.push({
|
|
4107
4140
|
property,
|
|
4108
|
-
reason: "validation.beUrn"
|
|
4141
|
+
reason: "validation.beUrn",
|
|
4142
|
+
properties: { fieldName: fieldNameResource ?? "validation.defaultFieldName", value }
|
|
4109
4143
|
});
|
|
4110
4144
|
return false;
|
|
4111
4145
|
}
|
|
@@ -4351,9 +4385,8 @@ class AsyncCache {
|
|
|
4351
4385
|
class Compression {
|
|
4352
4386
|
/**
|
|
4353
4387
|
* Runtime name for the class.
|
|
4354
|
-
* @internal
|
|
4355
4388
|
*/
|
|
4356
|
-
static
|
|
4389
|
+
static CLASS_NAME = "Compression";
|
|
4357
4390
|
/**
|
|
4358
4391
|
* Compress bytes using GZIP.
|
|
4359
4392
|
* @param bytes The bytes to compress.
|
|
@@ -4361,8 +4394,8 @@ class Compression {
|
|
|
4361
4394
|
* @returns The compressed bytes.
|
|
4362
4395
|
*/
|
|
4363
4396
|
static async compress(bytes, type) {
|
|
4364
|
-
Guards.uint8Array(Compression.
|
|
4365
|
-
Guards.arrayOneOf(Compression.
|
|
4397
|
+
Guards.uint8Array(Compression.CLASS_NAME, "bytes", bytes);
|
|
4398
|
+
Guards.arrayOneOf(Compression.CLASS_NAME, "type", type, Object.values(CompressionType));
|
|
4366
4399
|
const blob = new Blob([new Uint8Array(bytes)]);
|
|
4367
4400
|
const compressionStream = new CompressionStream(type);
|
|
4368
4401
|
const compressionPipe = blob.stream().pipeThrough(compressionStream);
|
|
@@ -4383,8 +4416,8 @@ class Compression {
|
|
|
4383
4416
|
* @returns The decompressed bytes.
|
|
4384
4417
|
*/
|
|
4385
4418
|
static async decompress(compressedBytes, type) {
|
|
4386
|
-
Guards.uint8Array(Compression.
|
|
4387
|
-
Guards.arrayOneOf(Compression.
|
|
4419
|
+
Guards.uint8Array(Compression.CLASS_NAME, "compressedBytes", compressedBytes);
|
|
4420
|
+
Guards.arrayOneOf(Compression.CLASS_NAME, "type", type, Object.values(CompressionType));
|
|
4388
4421
|
const blob = new Blob([new Uint8Array(compressedBytes)]);
|
|
4389
4422
|
const decompressionStream = new DecompressionStream(type);
|
|
4390
4423
|
const decompressionPipe = blob.stream().pipeThrough(decompressionStream);
|
|
@@ -4413,8 +4446,7 @@ class Validation {
|
|
|
4413
4446
|
failures.push({
|
|
4414
4447
|
property,
|
|
4415
4448
|
reason: "validation.beEmpty",
|
|
4416
|
-
fieldName: fieldNameResource ?? "validation.defaultFieldName",
|
|
4417
|
-
properties: { value }
|
|
4449
|
+
properties: { fieldName: fieldNameResource ?? "validation.defaultFieldName", value }
|
|
4418
4450
|
});
|
|
4419
4451
|
}
|
|
4420
4452
|
return is;
|