@twin.org/core 0.0.4-next.1 → 0.0.4-next.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/dist/es/encoding/base64.js +2 -1
  2. package/dist/es/encoding/base64.js.map +1 -1
  3. package/dist/es/errors/conflictError.js +1 -1
  4. package/dist/es/errors/conflictError.js.map +1 -1
  5. package/dist/es/errors/generalError.js +1 -1
  6. package/dist/es/errors/generalError.js.map +1 -1
  7. package/dist/es/errors/notImplementedError.js +1 -1
  8. package/dist/es/errors/notImplementedError.js.map +1 -1
  9. package/dist/es/errors/validationError.js +1 -1
  10. package/dist/es/errors/validationError.js.map +1 -1
  11. package/dist/es/factories/factory.js +9 -0
  12. package/dist/es/factories/factory.js.map +1 -1
  13. package/dist/es/helpers/arrayHelper.js +1 -1
  14. package/dist/es/helpers/arrayHelper.js.map +1 -1
  15. package/dist/es/helpers/errorHelper.js +1 -1
  16. package/dist/es/helpers/errorHelper.js.map +1 -1
  17. package/dist/es/helpers/jsonHelper.js +1 -1
  18. package/dist/es/helpers/jsonHelper.js.map +1 -1
  19. package/dist/es/helpers/objectHelper.js +2 -2
  20. package/dist/es/helpers/objectHelper.js.map +1 -1
  21. package/dist/es/helpers/stringHelper.js +2 -2
  22. package/dist/es/helpers/stringHelper.js.map +1 -1
  23. package/dist/es/index.js +4 -0
  24. package/dist/es/index.js.map +1 -1
  25. package/dist/es/models/IComponent.js.map +1 -1
  26. package/dist/es/models/ILocale.js.map +1 -1
  27. package/dist/es/models/ISharedObjectBufferOptions.js +4 -0
  28. package/dist/es/models/ISharedObjectBufferOptions.js.map +1 -0
  29. package/dist/es/models/ISharedObjectBufferWorkerMessage.js +2 -0
  30. package/dist/es/models/ISharedObjectBufferWorkerMessage.js.map +1 -0
  31. package/dist/es/models/IValidationFailure.js.map +1 -1
  32. package/dist/es/models/sharedObjectBufferMessageTypes.js +13 -0
  33. package/dist/es/models/sharedObjectBufferMessageTypes.js.map +1 -0
  34. package/dist/es/utils/asyncCache.js +4 -1
  35. package/dist/es/utils/asyncCache.js.map +1 -1
  36. package/dist/es/utils/coerce.js +10 -20
  37. package/dist/es/utils/coerce.js.map +1 -1
  38. package/dist/es/utils/compression.js +1 -1
  39. package/dist/es/utils/compression.js.map +1 -1
  40. package/dist/es/utils/guards.js +36 -0
  41. package/dist/es/utils/guards.js.map +1 -1
  42. package/dist/es/utils/is.js +9 -9
  43. package/dist/es/utils/is.js.map +1 -1
  44. package/dist/es/utils/mutex.js +55 -17
  45. package/dist/es/utils/mutex.js.map +1 -1
  46. package/dist/es/utils/sharedObjectBuffer.js +305 -0
  47. package/dist/es/utils/sharedObjectBuffer.js.map +1 -0
  48. package/dist/es/utils/sharedStore.js +2 -2
  49. package/dist/es/utils/sharedStore.js.map +1 -1
  50. package/dist/types/errors/conflictError.d.ts +1 -1
  51. package/dist/types/errors/generalError.d.ts +1 -1
  52. package/dist/types/errors/notImplementedError.d.ts +1 -1
  53. package/dist/types/errors/validationError.d.ts +1 -1
  54. package/dist/types/factories/factory.d.ts +6 -0
  55. package/dist/types/helpers/arrayHelper.d.ts +1 -1
  56. package/dist/types/helpers/errorHelper.d.ts +1 -1
  57. package/dist/types/helpers/jsonHelper.d.ts +1 -1
  58. package/dist/types/helpers/objectHelper.d.ts +2 -2
  59. package/dist/types/helpers/stringHelper.d.ts +2 -2
  60. package/dist/types/index.d.ts +4 -0
  61. package/dist/types/models/IComponent.d.ts +2 -2
  62. package/dist/types/models/ILocale.d.ts +1 -1
  63. package/dist/types/models/ISharedObjectBufferOptions.d.ts +17 -0
  64. package/dist/types/models/ISharedObjectBufferWorkerMessage.d.ts +29 -0
  65. package/dist/types/models/IValidationFailure.d.ts +1 -1
  66. package/dist/types/models/sharedObjectBufferMessageTypes.d.ts +13 -0
  67. package/dist/types/utils/asyncCache.d.ts +1 -8
  68. package/dist/types/utils/coerce.d.ts +10 -20
  69. package/dist/types/utils/compression.d.ts +1 -1
  70. package/dist/types/utils/guards.d.ts +24 -0
  71. package/dist/types/utils/is.d.ts +9 -9
  72. package/dist/types/utils/sharedObjectBuffer.d.ts +74 -0
  73. package/dist/types/utils/sharedStore.d.ts +2 -2
  74. package/docs/changelog.md +242 -0
  75. package/docs/reference/classes/ArrayHelper.md +1 -1
  76. package/docs/reference/classes/AsyncCache.md +1 -1
  77. package/docs/reference/classes/Coerce.md +10 -50
  78. package/docs/reference/classes/Compression.md +1 -1
  79. package/docs/reference/classes/ConflictError.md +1 -1
  80. package/docs/reference/classes/ErrorHelper.md +1 -1
  81. package/docs/reference/classes/Factory.md +28 -0
  82. package/docs/reference/classes/GeneralError.md +1 -1
  83. package/docs/reference/classes/Guards.md +108 -0
  84. package/docs/reference/classes/Is.md +9 -9
  85. package/docs/reference/classes/JsonHelper.md +1 -1
  86. package/docs/reference/classes/NotImplementedError.md +1 -1
  87. package/docs/reference/classes/ObjectHelper.md +2 -2
  88. package/docs/reference/classes/SharedObjectBuffer.md +192 -0
  89. package/docs/reference/classes/SharedStore.md +2 -2
  90. package/docs/reference/classes/StringHelper.md +16 -13
  91. package/docs/reference/classes/ValidationError.md +1 -1
  92. package/docs/reference/index.md +5 -0
  93. package/docs/reference/interfaces/IComponent.md +2 -2
  94. package/docs/reference/interfaces/ILocale.md +1 -1
  95. package/docs/reference/interfaces/ISharedObjectBufferOptions.md +33 -0
  96. package/docs/reference/interfaces/ISharedObjectBufferWorkerMessage.md +44 -0
  97. package/docs/reference/interfaces/IValidationFailure.md +1 -1
  98. package/docs/reference/type-aliases/SharedObjectBufferMessageTypes.md +5 -0
  99. package/docs/reference/variables/SharedObjectBufferMessageTypes.md +13 -0
  100. package/locales/en.json +10 -2
  101. package/package.json +4 -4
@@ -1 +1 @@
1
- {"version":3,"file":"stringHelper.js","sourceRoot":"","sources":["../../../src/helpers/stringHelper.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,gCAAgC;AAChC,+BAA+B;AAC/B,OAAO,EAAE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ACD","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n/* eslint-disable no-continue */\n/* eslint-disable no-bitwise */\nimport { Is } from \"../utils/is.js\";\n\n/**\n * Class to help with string.\n */\nexport class StringHelper {\n\t/**\n\t * Implementation signature for trimTrailingSlashes.\n\t * @param value The value to trim.\n\t * @returns The trimmed string or the original.\n\t */\n\tpublic static trimTrailingSlashes(value: string): string {\n\t\tif (Is.string(value)) {\n\t\t\treturn value.replace(/\\/+$/, \"\");\n\t\t}\n\t\treturn value;\n\t}\n\n\t/**\n\t * Implementation signature for trimLeadingSlashes.\n\t * @param value The value to trim.\n\t * @returns The trimmed string or the original.\n\t */\n\tpublic static trimLeadingSlashes(value: string): string {\n\t\tif (Is.string(value)) {\n\t\t\treturn value.replace(/^\\/+/, \"\");\n\t\t}\n\t\treturn value;\n\t}\n\n\t/**\n\t * Trim both leading and trailing slashes from a string.\n\t * @param value The value to trim.\n\t * @returns The trimmed string or the original.\n\t */\n\tpublic static trimLeadingAndTrailingSlashes(value: string): string {\n\t\tif (Is.string(value)) {\n\t\t\treturn value.replace(/^\\/+|\\/+$/g, \"\");\n\t\t}\n\t\treturn value;\n\t}\n\n\t/**\n\t * Convert the input string to kebab case.\n\t * @param input The input to convert.\n\t * @param stripInterfacePrefix Strip interface prefixes.\n\t * @returns The kebab case version of the input.\n\t */\n\tpublic static kebabCase(input: string, stripInterfacePrefix: boolean = true): string {\n\t\tif (Is.stringValue(input)) {\n\t\t\tlet output = input;\n\t\t\tif (stripInterfacePrefix && /^I[A-Z]/.test(output)) {\n\t\t\t\toutput = output.slice(1);\n\t\t\t}\n\t\t\treturn StringHelper.words(output).join(\"-\").toLowerCase();\n\t\t}\n\t\treturn \"\";\n\t}\n\n\t/**\n\t * Convert the input string to snake case.\n\t * @param input The input to convert.\n\t * @param stripInterfacePrefix Strip interface prefixes.\n\t * @returns The snake case version of the input.\n\t */\n\tpublic static snakeCase(input: string, stripInterfacePrefix: boolean = true): string {\n\t\tif (Is.stringValue(input)) {\n\t\t\tlet output = input;\n\t\t\tif (stripInterfacePrefix && /^I[A-Z]/.test(output)) {\n\t\t\t\toutput = output.slice(1);\n\t\t\t}\n\t\t\treturn StringHelper.words(output).join(\"_\").toLowerCase();\n\t\t}\n\t\treturn \"\";\n\t}\n\n\t/**\n\t * Title case all the words.\n\t * @param input The input to convert.\n\t * @param stripInterfacePrefix Strip interface prefixes.\n\t * @returns The title case version of the input.\n\t */\n\tpublic static titleCase(input: string, stripInterfacePrefix: boolean = true): string {\n\t\tif (Is.stringValue(input)) {\n\t\t\tlet output = input;\n\t\t\tif (stripInterfacePrefix && /^I[A-Z]/.test(output)) {\n\t\t\t\toutput = output.slice(1);\n\t\t\t}\n\t\t\treturn StringHelper.words(output)\n\t\t\t\t.map(w => `${w[0].toUpperCase()}${w.slice(1).toLowerCase()}`)\n\t\t\t\t.join(\" \");\n\t\t}\n\t\treturn \"\";\n\t}\n\n\t/**\n\t * Pascal case all the words.\n\t * @param input The input to convert.\n\t * @param stripInterfacePrefix Strip interface prefixes.\n\t * @returns The pascal case version of the input.\n\t */\n\tpublic static pascalCase(input: string, stripInterfacePrefix: boolean = true): string {\n\t\tif (Is.stringValue(input)) {\n\t\t\tlet output = input;\n\t\t\tif (stripInterfacePrefix && /^I[A-Z]/.test(output)) {\n\t\t\t\toutput = output.slice(1);\n\t\t\t}\n\t\t\treturn StringHelper.words(output)\n\t\t\t\t.map(w => `${w[0].toUpperCase()}${w.slice(1).toLowerCase()}`)\n\t\t\t\t.join(\"\");\n\t\t}\n\t\treturn \"\";\n\t}\n\n\t/**\n\t * Camel case all the words.\n\t * @param input The input to convert.\n\t * @param stripInterfacePrefix Strip interface prefixes.\n\t * @returns The camel case version of the input.\n\t */\n\tpublic static camelCase(input: string, stripInterfacePrefix: boolean = true): string {\n\t\tif (Is.stringValue(input)) {\n\t\t\tlet output = input;\n\t\t\tif (stripInterfacePrefix && /^I[A-Z]/.test(output)) {\n\t\t\t\toutput = output.slice(1);\n\t\t\t}\n\t\t\tconst words = StringHelper.words(output);\n\t\t\treturn words.length === 0\n\t\t\t\t? \"\"\n\t\t\t\t: `${words[0].toLowerCase()}${words\n\t\t\t\t\t\t.slice(1)\n\t\t\t\t\t\t.map(w => `${w[0].toUpperCase()}${w.slice(1).toLowerCase()}`)\n\t\t\t\t\t\t.join(\"\")}`;\n\t\t}\n\t\treturn \"\";\n\t}\n\n\t/**\n\t * Convert the words to a path.\n\t * @param input The input to convert.\n\t * @param stripInterfacePrefix Strip interface prefixes.\n\t * @returns The path version of the input.\n\t */\n\tpublic static wordPath(input: string, stripInterfacePrefix: boolean = true): string {\n\t\tif (Is.stringValue(input)) {\n\t\t\tlet output = input;\n\t\t\tif (stripInterfacePrefix && /^I[A-Z]/.test(output)) {\n\t\t\t\toutput = output.slice(1);\n\t\t\t}\n\t\t\tconst words = StringHelper.words(output);\n\t\t\treturn words.join(\"/\").toLowerCase();\n\t\t}\n\t\treturn \"\";\n\t}\n\n\t/**\n\t * Strip interface prefix if there is one.\n\t * @param input The input to strip.\n\t * @returns The input with any interface prefix stripped.\n\t */\n\tpublic static stripPrefix(input: string): string {\n\t\tif (Is.stringValue(input)) {\n\t\t\tlet output = input;\n\t\t\tif (/^I[A-Z]/.test(output)) {\n\t\t\t\toutput = output.slice(1);\n\t\t\t}\n\t\t\treturn output;\n\t\t}\n\t\treturn \"\";\n\t}\n\n\t/**\n\t * Split a string into words.\n\t * @param input The input to split.\n\t * @returns The string split into words.\n\t */\n\tpublic static words(input: string): string[] {\n\t\tif (!Is.stringValue(input)) {\n\t\t\treturn [];\n\t\t}\n\t\treturn (\n\t\t\tinput\n\t\t\t\t.replace(/([A-Z])/g, \" $1\")\n\t\t\t\t.trim()\n\t\t\t\t.match(/[^\\u0000-\\u002F\\u003A-\\u0040\\u005B-\\u0060\\u007B-\\u007F]+/g) ?? []\n\t\t);\n\t}\n\n\t/**\n\t * Check if a Node.js Buffer or Uint8Array is UTF-8.\n\t * Url https://tools.ietf.org/html/rfc3629\n\t * Source https://github.com/hcodes/isutf8\n\t * UTF8-char = UTF8-1 / UTF8-2 / UTF8-3 / UTF8-4.\n\t * UTF8-1 = %x00-7F.\n\t * UTF8-2 = %xC2-DF UTF8-tail.\n\t * UTF8-3 = %xE0 %xA0-BF UTF8-tail.\n\t * - %xE1-EC 2( UTF8-tail ).\n\t * - %xED %x80-9F UTF8-tail.\n\t * - %xEE-EF 2( UTF8-tail ).\n\t * UTF8-4 = %xF0 %x90-BF 2( UTF8-tail ).\n\t * - %xF1-F3 3( UTF8-tail ).\n\t * - %xF4 %x80-8F 2( UTF8-tail ).\n\t * UTF8-tail = %x80-BF.\n\t * @param data The data to check.\n\t * @returns True if the data is utf8.\n\t */\n\tpublic static isUtf8(data: Uint8Array): boolean {\n\t\tif (!Is.uint8Array(data)) {\n\t\t\treturn false;\n\t\t}\n\n\t\tlet i = 0;\n\t\tconst len = data.length;\n\n\t\twhile (i < len) {\n\t\t\t// UTF8-1 = %x00-7F\n\t\t\tif (data[i] <= 0x7f) {\n\t\t\t\ti++;\n\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// UTF8-2 = %xC2-DF UTF8-tail\n\t\t\tif (data[i] >= 0xc2 && data[i] <= 0xdf) {\n\t\t\t\t// if(buf[i + 1] >= 0x80 && buf[i + 1] <= 0xBF) {\n\t\t\t\tif (data[i + 1] >> 6 === 2) {\n\t\t\t\t\ti += 2;\n\n\t\t\t\t\tcontinue;\n\t\t\t\t} else {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// UTF8-3 = %xE0 %xA0-BF UTF8-tail\n\t\t\t// UTF8-3 = %xED %x80-9F UTF8-tail\n\t\t\tif (\n\t\t\t\t((data[i] === 0xe0 && data[i + 1] >= 0xa0 && data[i + 1] <= 0xbf) ||\n\t\t\t\t\t(data[i] === 0xed && data[i + 1] >= 0x80 && data[i + 1] <= 0x9f)) &&\n\t\t\t\tdata[i + 2] >> 6 === 2\n\t\t\t) {\n\t\t\t\ti += 3;\n\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// UTF8-3 = %xE1-EC 2( UTF8-tail )\n\t\t\t// UTF8-3 = %xEE-EF 2( UTF8-tail )\n\t\t\tif (\n\t\t\t\t((data[i] >= 0xe1 && data[i] <= 0xec) || (data[i] >= 0xee && data[i] <= 0xef)) &&\n\t\t\t\tdata[i + 1] >> 6 === 2 &&\n\t\t\t\tdata[i + 2] >> 6 === 2\n\t\t\t) {\n\t\t\t\ti += 3;\n\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// UTF8-4 = %xF0 %x90-BF 2( UTF8-tail )\n\t\t\t// %xF1-F3 3( UTF8-tail )\n\t\t\t// %xF4 %x80-8F 2( UTF8-tail )\n\t\t\tif (\n\t\t\t\t((data[i] === 0xf0 && data[i + 1] >= 0x90 && data[i + 1] <= 0xbf) ||\n\t\t\t\t\t(data[i] >= 0xf1 && data[i] <= 0xf3 && data[i + 1] >> 6 === 2) ||\n\t\t\t\t\t(data[i] === 0xf4 && data[i + 1] >= 0x80 && data[i + 1] <= 0x8f)) &&\n\t\t\t\tdata[i + 2] >> 6 === 2 &&\n\t\t\t\tdata[i + 3] >> 6 === 2\n\t\t\t) {\n\t\t\t\ti += 4;\n\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\treturn false;\n\t\t}\n\n\t\treturn true;\n\t}\n}\n"]}
1
+ {"version":3,"file":"stringHelper.js","sourceRoot":"","sources":["../../../src/helpers/stringHelper.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,gCAAgC;AAChC,+BAA+B;AAC/B,OAAO,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAEpC;;GAEG;AACH,MAAM,OAAO,YAAY;IACxB;;;;OAIG;IACI,MAAM,CAAC,mBAAmB,CAAC,KAAa;QAC9C,IAAI,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;YACt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AI,IAAI,CAAC,CAAC;gBAC9E,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC;gBACtB,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,EACrB,CAAC;gBACF,CAAC,IAAI,CAAC,CAAC;gBAEP,SAAS;YACV,CAAC;YAED,uCAAuC;YACvC,kCAAkC;YAClC,uCAAuC;YACvC,IACC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,IAAI,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,IAAI,IAAI,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC;gBAChE,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,IAAI,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBAC9D,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,IAAI,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,IAAI,IAAI,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC;gBAClE,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC;gBACtB,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,EACrB,CAAC;gBACF,CAAC,IAAI,CAAC,CAAC;gBAEP,SAAS;YACV,CAAC;YAED,OAAO,KAAK,CAAC;QACd,CAAC;QAED,OAAO,IAAI,CAAC;IACb,CAAC;CACD","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n/* eslint-disable no-continue */\n/* eslint-disable no-bitwise */\nimport { Is } from \"../utils/is.js\";\n\n/**\n * Class to help with string.\n */\nexport class StringHelper {\n\t/**\n\t * Implementation signature for trimTrailingSlashes.\n\t * @param value The value to trim.\n\t * @returns The trimmed string or the original.\n\t */\n\tpublic static trimTrailingSlashes(value: string): string {\n\t\tif (Is.string(value)) {\n\t\t\treturn value.replace(/\\/+$/, \"\");\n\t\t}\n\t\treturn value;\n\t}\n\n\t/**\n\t * Implementation signature for trimLeadingSlashes.\n\t * @param value The value to trim.\n\t * @returns The trimmed string or the original.\n\t */\n\tpublic static trimLeadingSlashes(value: string): string {\n\t\tif (Is.string(value)) {\n\t\t\treturn value.replace(/^\\/+/, \"\");\n\t\t}\n\t\treturn value;\n\t}\n\n\t/**\n\t * Trim both leading and trailing slashes from a string.\n\t * @param value The value to trim.\n\t * @returns The trimmed string or the original.\n\t */\n\tpublic static trimLeadingAndTrailingSlashes(value: string): string {\n\t\tif (Is.string(value)) {\n\t\t\treturn value.replace(/^\\/+|\\/+$/g, \"\");\n\t\t}\n\t\treturn value;\n\t}\n\n\t/**\n\t * Convert the input string to kebab case.\n\t * @param input The input to convert.\n\t * @param stripInterfacePrefix Strip interface prefixes.\n\t * @returns The kebab case version of the input.\n\t */\n\tpublic static kebabCase(input: string, stripInterfacePrefix: boolean = true): string {\n\t\tif (Is.stringValue(input)) {\n\t\t\tlet output = input;\n\t\t\tif (stripInterfacePrefix && /^I[A-Z]/.test(output)) {\n\t\t\t\toutput = output.slice(1);\n\t\t\t}\n\t\t\treturn StringHelper.words(output).join(\"-\").toLowerCase();\n\t\t}\n\t\treturn \"\";\n\t}\n\n\t/**\n\t * Convert the input string to snake case.\n\t * @param input The input to convert.\n\t * @param stripInterfacePrefix Strip interface prefixes.\n\t * @returns The snake case version of the input.\n\t */\n\tpublic static snakeCase(input: string, stripInterfacePrefix: boolean = true): string {\n\t\tif (Is.stringValue(input)) {\n\t\t\tlet output = input;\n\t\t\tif (stripInterfacePrefix && /^I[A-Z]/.test(output)) {\n\t\t\t\toutput = output.slice(1);\n\t\t\t}\n\t\t\treturn StringHelper.words(output).join(\"_\").toLowerCase();\n\t\t}\n\t\treturn \"\";\n\t}\n\n\t/**\n\t * Title case all the words.\n\t * @param input The input to convert.\n\t * @param stripInterfacePrefix Strip interface prefixes.\n\t * @returns The title case version of the input.\n\t */\n\tpublic static titleCase(input: string, stripInterfacePrefix: boolean = true): string {\n\t\tif (Is.stringValue(input)) {\n\t\t\tlet output = input;\n\t\t\tif (stripInterfacePrefix && /^I[A-Z]/.test(output)) {\n\t\t\t\toutput = output.slice(1);\n\t\t\t}\n\t\t\treturn StringHelper.words(output)\n\t\t\t\t.map(w => `${w[0].toUpperCase()}${w.slice(1).toLowerCase()}`)\n\t\t\t\t.join(\" \");\n\t\t}\n\t\treturn \"\";\n\t}\n\n\t/**\n\t * Pascal case all the words.\n\t * @param input The input to convert.\n\t * @param stripInterfacePrefix Strip interface prefixes.\n\t * @returns The pascal case version of the input.\n\t */\n\tpublic static pascalCase(input: string, stripInterfacePrefix: boolean = true): string {\n\t\tif (Is.stringValue(input)) {\n\t\t\tlet output = input;\n\t\t\tif (stripInterfacePrefix && /^I[A-Z]/.test(output)) {\n\t\t\t\toutput = output.slice(1);\n\t\t\t}\n\t\t\treturn StringHelper.words(output)\n\t\t\t\t.map(w => `${w[0].toUpperCase()}${w.slice(1).toLowerCase()}`)\n\t\t\t\t.join(\"\");\n\t\t}\n\t\treturn \"\";\n\t}\n\n\t/**\n\t * Camel case all the words.\n\t * @param input The input to convert.\n\t * @param stripInterfacePrefix Strip interface prefixes.\n\t * @returns The camel case version of the input.\n\t */\n\tpublic static camelCase(input: string, stripInterfacePrefix: boolean = true): string {\n\t\tif (Is.stringValue(input)) {\n\t\t\tlet output = input;\n\t\t\tif (stripInterfacePrefix && /^I[A-Z]/.test(output)) {\n\t\t\t\toutput = output.slice(1);\n\t\t\t}\n\t\t\tconst words = StringHelper.words(output);\n\t\t\treturn words.length === 0\n\t\t\t\t? \"\"\n\t\t\t\t: `${words[0].toLowerCase()}${words\n\t\t\t\t\t\t.slice(1)\n\t\t\t\t\t\t.map(w => `${w[0].toUpperCase()}${w.slice(1).toLowerCase()}`)\n\t\t\t\t\t\t.join(\"\")}`;\n\t\t}\n\t\treturn \"\";\n\t}\n\n\t/**\n\t * Convert the words to a path.\n\t * @param input The input to convert.\n\t * @param stripInterfacePrefix Strip interface prefixes.\n\t * @returns The path version of the input.\n\t */\n\tpublic static wordPath(input: string, stripInterfacePrefix: boolean = true): string {\n\t\tif (Is.stringValue(input)) {\n\t\t\tlet output = input;\n\t\t\tif (stripInterfacePrefix && /^I[A-Z]/.test(output)) {\n\t\t\t\toutput = output.slice(1);\n\t\t\t}\n\t\t\tconst words = StringHelper.words(output);\n\t\t\treturn words.join(\"/\").toLowerCase();\n\t\t}\n\t\treturn \"\";\n\t}\n\n\t/**\n\t * Strip interface prefix if there is one.\n\t * @param input The input to strip.\n\t * @returns The input with any interface prefix stripped.\n\t */\n\tpublic static stripPrefix(input: string): string {\n\t\tif (Is.stringValue(input)) {\n\t\t\tlet output = input;\n\t\t\tif (/^I[A-Z]/.test(output)) {\n\t\t\t\toutput = output.slice(1);\n\t\t\t}\n\t\t\treturn output;\n\t\t}\n\t\treturn \"\";\n\t}\n\n\t/**\n\t * Split a string into words.\n\t * @param input The input to split.\n\t * @returns The string split into words.\n\t */\n\tpublic static words(input: string): string[] {\n\t\tif (!Is.stringValue(input)) {\n\t\t\treturn [];\n\t\t}\n\t\treturn (\n\t\t\tinput\n\t\t\t\t.replace(/([A-Z])/g, \" $1\")\n\t\t\t\t.trim()\n\t\t\t\t.match(/[^\\u0000-\\u002F\\u003A-\\u0040\\u005B-\\u0060\\u007B-\\u007F]+/g) ?? []\n\t\t);\n\t}\n\n\t/**\n\t * Check if a Node.js Buffer or Uint8Array is UTF-8.\n\t * @see https://tools.ietf.org/html/rfc3629\n\t * @see https://github.com/hcodes/isutf8\n\t * UTF8-char = UTF8-1 / UTF8-2 / UTF8-3 / UTF8-4.\n\t * UTF8-1 = %x00-7F.\n\t * UTF8-2 = %xC2-DF UTF8-tail.\n\t * UTF8-3 = %xE0 %xA0-BF UTF8-tail.\n\t * - %xE1-EC 2( UTF8-tail ).\n\t * - %xED %x80-9F UTF8-tail.\n\t * - %xEE-EF 2( UTF8-tail ).\n\t * UTF8-4 = %xF0 %x90-BF 2( UTF8-tail ).\n\t * - %xF1-F3 3( UTF8-tail ).\n\t * - %xF4 %x80-8F 2( UTF8-tail ).\n\t * UTF8-tail = %x80-BF.\n\t * @param data The data to check.\n\t * @returns True if the data is utf8.\n\t */\n\tpublic static isUtf8(data: Uint8Array): boolean {\n\t\tif (!Is.uint8Array(data)) {\n\t\t\treturn false;\n\t\t}\n\n\t\tlet i = 0;\n\t\tconst len = data.length;\n\n\t\twhile (i < len) {\n\t\t\t// UTF8-1 = %x00-7F\n\t\t\tif (data[i] <= 0x7f) {\n\t\t\t\ti++;\n\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// UTF8-2 = %xC2-DF UTF8-tail\n\t\t\tif (data[i] >= 0xc2 && data[i] <= 0xdf) {\n\t\t\t\t// if(buf[i + 1] >= 0x80 && buf[i + 1] <= 0xBF) {\n\t\t\t\tif (data[i + 1] >> 6 === 2) {\n\t\t\t\t\ti += 2;\n\n\t\t\t\t\tcontinue;\n\t\t\t\t} else {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// UTF8-3 = %xE0 %xA0-BF UTF8-tail\n\t\t\t// UTF8-3 = %xED %x80-9F UTF8-tail\n\t\t\tif (\n\t\t\t\t((data[i] === 0xe0 && data[i + 1] >= 0xa0 && data[i + 1] <= 0xbf) ||\n\t\t\t\t\t(data[i] === 0xed && data[i + 1] >= 0x80 && data[i + 1] <= 0x9f)) &&\n\t\t\t\tdata[i + 2] >> 6 === 2\n\t\t\t) {\n\t\t\t\ti += 3;\n\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// UTF8-3 = %xE1-EC 2( UTF8-tail )\n\t\t\t// UTF8-3 = %xEE-EF 2( UTF8-tail )\n\t\t\tif (\n\t\t\t\t((data[i] >= 0xe1 && data[i] <= 0xec) || (data[i] >= 0xee && data[i] <= 0xef)) &&\n\t\t\t\tdata[i + 1] >> 6 === 2 &&\n\t\t\t\tdata[i + 2] >> 6 === 2\n\t\t\t) {\n\t\t\t\ti += 3;\n\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// UTF8-4 = %xF0 %x90-BF 2( UTF8-tail )\n\t\t\t// %xF1-F3 3( UTF8-tail )\n\t\t\t// %xF4 %x80-8F 2( UTF8-tail )\n\t\t\tif (\n\t\t\t\t((data[i] === 0xf0 && data[i + 1] >= 0x90 && data[i + 1] <= 0xbf) ||\n\t\t\t\t\t(data[i] >= 0xf1 && data[i] <= 0xf3 && data[i + 1] >> 6 === 2) ||\n\t\t\t\t\t(data[i] === 0xf4 && data[i + 1] >= 0x80 && data[i + 1] <= 0x8f)) &&\n\t\t\t\tdata[i + 2] >> 6 === 2 &&\n\t\t\t\tdata[i + 3] >> 6 === 2\n\t\t\t) {\n\t\t\t\ti += 4;\n\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\treturn false;\n\t\t}\n\n\t\treturn true;\n\t}\n}\n"]}
package/dist/es/index.js CHANGED
@@ -42,9 +42,12 @@ export * from "./models/ILocaleDictionary.js";
42
42
  export * from "./models/ILocalesIndex.js";
43
43
  export * from "./models/IMutexWorkerMessage.js";
44
44
  export * from "./models/IPatchOperation.js";
45
+ export * from "./models/ISharedObjectBufferOptions.js";
46
+ export * from "./models/ISharedObjectBufferWorkerMessage.js";
45
47
  export * from "./models/IUrlParts.js";
46
48
  export * from "./models/IValidationFailure.js";
47
49
  export * from "./models/mutexMessageTypes.js";
50
+ export * from "./models/sharedObjectBufferMessageTypes.js";
48
51
  export * from "./types/bitString.js";
49
52
  export * from "./types/objectOrArray.js";
50
53
  export * from "./types/singleOccurrenceArray.js";
@@ -59,6 +62,7 @@ export * from "./utils/guards.js";
59
62
  export * from "./utils/i18n.js";
60
63
  export * from "./utils/is.js";
61
64
  export * from "./utils/mutex.js";
65
+ export * from "./utils/sharedObjectBuffer.js";
62
66
  export * from "./utils/sharedStore.js";
63
67
  export * from "./utils/validation.js";
64
68
  //# sourceMappingURL=index.js.map
@@ -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,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qBAAqB,CAAC;AACpC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iCAAiC,CAAC;AAChD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,uBAAuB,CAAC;AACtC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,kCAAkC,CAAC;AACjD,cAAc,6CAA6C,CAAC;AAC5D,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,kBAAkB,CAAC;AACjC,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/healthStatus.js\";\nexport * from \"./models/IComponent.js\";\nexport * from \"./models/IError.js\";\nexport * from \"./models/IHealth.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/IMutexWorkerMessage.js\";\nexport * from \"./models/IPatchOperation.js\";\nexport * from \"./models/IUrlParts.js\";\nexport * from \"./models/IValidationFailure.js\";\nexport * from \"./models/mutexMessageTypes.js\";\nexport * from \"./types/bitString.js\";\nexport * from \"./types/objectOrArray.js\";\nexport * from \"./types/singleOccurrenceArray.js\";\nexport * from \"./types/singleOccurrenceArrayDepthHelper.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/mutex.js\";\nexport * from \"./utils/sharedStore.js\";\nexport * from \"./utils/validation.js\";\n"]}
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,CAA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CAA6C,CAAC;AAC5D,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,kBAAkB,CAAC;AACjC,cAAc,+BAA+B,CAAC;AAC9C,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/healthStatus.js\";\nexport * from \"./models/IComponent.js\";\nexport * from \"./models/IError.js\";\nexport * from \"./models/IHealth.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/IMutexWorkerMessage.js\";\nexport * from \"./models/IPatchOperation.js\";\nexport * from \"./models/ISharedObjectBufferOptions.js\";\nexport * from \"./models/ISharedObjectBufferWorkerMessage.js\";\nexport * from \"./models/IUrlParts.js\";\nexport * from \"./models/IValidationFailure.js\";\nexport * from \"./models/mutexMessageTypes.js\";\nexport * from \"./models/sharedObjectBufferMessageTypes.js\";\nexport * from \"./types/bitString.js\";\nexport * from \"./types/objectOrArray.js\";\nexport * from \"./types/singleOccurrenceArray.js\";\nexport * from \"./types/singleOccurrenceArrayDepthHelper.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/mutex.js\";\nexport * from \"./utils/sharedObjectBuffer.js\";\nexport * from \"./utils/sharedStore.js\";\nexport * from \"./utils/validation.js\";\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"IComponent.js","sourceRoot":"","sources":["../../../src/models/IComponent.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IHealth } from \"./IHealth.js\";\n\n/**\n * Interface describing a component which can be bootstrapped, started and stopped.\n */\nexport interface IComponent {\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tclassName(): string;\n\n\t/**\n\t * Bootstrap the component by creating and initializing any resources it needs.\n\t * @param nodeLoggingComponentType The node logging component type.\n\t * @returns True if the bootstrapping process was successful.\n\t */\n\tbootstrap?(nodeLoggingComponentType?: string): Promise<boolean>;\n\n\t/**\n\t * Teardown the component by releasing any resources it holds.\n\t * @param nodeLoggingComponentType The node logging component type.\n\t * @returns True if the teardown process was successful.\n\t */\n\tteardown?(nodeLoggingComponentType?: string): Promise<boolean>;\n\n\t/**\n\t * The component needs to be started when the node is initialized.\n\t * @param nodeLoggingComponentType The node logging component type.\n\t * @returns Nothing.\n\t */\n\tstart?(nodeLoggingComponentType?: string): Promise<void>;\n\n\t/**\n\t * The component needs to be stopped when the node is closed.\n\t * @param nodeLoggingComponentType The node logging component type.\n\t * @returns Nothing.\n\t */\n\tstop?(nodeLoggingComponentType?: string): Promise<void>;\n\n\t/**\n\t * Returns the health status of the component.\n\t * @returns The health status of the component, can return multiple entries for elements within the component.\n\t */\n\thealth?(): Promise<IHealth[]>;\n}\n"]}
1
+ {"version":3,"file":"IComponent.js","sourceRoot":"","sources":["../../../src/models/IComponent.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IHealth } from \"./IHealth.js\";\n\n/**\n * Interface describing a component which can be bootstrapped, started and stopped.\n */\nexport interface IComponent {\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tclassName(): string;\n\n\t/**\n\t * Bootstrap the component by creating and initializing any resources it needs.\n\t * @param nodeLoggingComponentType The node logging component type.\n\t * @returns True if the bootstrapping process was successful.\n\t */\n\tbootstrap?(nodeLoggingComponentType?: string): Promise<boolean>;\n\n\t/**\n\t * Teardown the component by releasing any resources it holds.\n\t * @param nodeLoggingComponentType The node logging component type.\n\t * @returns True if the teardown process was successful.\n\t */\n\tteardown?(nodeLoggingComponentType?: string): Promise<boolean>;\n\n\t/**\n\t * The component needs to be started when the node is initialized.\n\t * @param nodeLoggingComponentType The node logging component type.\n\t * @returns A promise that resolves when the component has started.\n\t */\n\tstart?(nodeLoggingComponentType?: string): Promise<void>;\n\n\t/**\n\t * The component needs to be stopped when the node is closed.\n\t * @param nodeLoggingComponentType The node logging component type.\n\t * @returns A promise that resolves when the component has stopped.\n\t */\n\tstop?(nodeLoggingComponentType?: string): Promise<void>;\n\n\t/**\n\t * Returns the health status of the component.\n\t * @returns The health status of the component, can return multiple entries for elements within the component.\n\t */\n\thealth?(): Promise<IHealth[]>;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"ILocale.js","sourceRoot":"","sources":["../../../src/models/ILocale.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n/**\n * Model for a local.\n */\nexport interface ILocale {\n\t/**\n\t * The label.\n\t */\n\tlabel: string;\n\n\t/**\n\t * The code.\n\t */\n\tcode: string;\n}\n"]}
1
+ {"version":3,"file":"ILocale.js","sourceRoot":"","sources":["../../../src/models/ILocale.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n/**\n * Model for a locale.\n */\nexport interface ILocale {\n\t/**\n\t * The label.\n\t */\n\tlabel: string;\n\n\t/**\n\t * The code.\n\t */\n\tcode: string;\n}\n"]}
@@ -0,0 +1,4 @@
1
+ // Copyright 2026 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ export {};
4
+ //# sourceMappingURL=ISharedObjectBufferOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ISharedObjectBufferOptions.js","sourceRoot":"","sources":["../../../src/models/ISharedObjectBufferOptions.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * Options for configuring buffer capacity when creating a shared object buffer.\n */\nexport interface ISharedObjectBufferOptions {\n\t/**\n\t * Initial payload capacity hint in bytes.\n\t * Only honoured when the buffer does not yet exist; ignored on subsequent writes.\n\t * @default 1 MiB.\n\t */\n\tinitialCapacityBytes?: number;\n\n\t/**\n\t * Maximum allowed payload capacity in bytes. The buffer will never grow beyond this limit.\n\t * Only honoured when the buffer does not yet exist; ignored on subsequent writes.\n\t * @default 256 MiB.\n\t */\n\tmaxCapacityBytes?: number;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ISharedObjectBufferWorkerMessage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ISharedObjectBufferWorkerMessage.js","sourceRoot":"","sources":["../../../src/models/ISharedObjectBufferWorkerMessage.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { MessagePort } from \"node:worker_threads\";\nimport type { ISharedObjectBufferOptions } from \"./ISharedObjectBufferOptions.js\";\nimport type { SharedObjectBufferMessageTypes } from \"./sharedObjectBufferMessageTypes.js\";\n\n/**\n * Message sent from a worker thread to the main thread to request the SharedArrayBuffer for an object.\n */\nexport interface ISharedObjectBufferWorkerMessage {\n\t/**\n\t * The message type discriminant.\n\t */\n\ttype: typeof SharedObjectBufferMessageTypes.GetBuffer;\n\n\t/**\n\t * The object id name that identifies which buffer is being requested.\n\t */\n\tobjectId: string;\n\n\t/**\n\t * One-shot SharedArrayBuffer used for the Atomics.wait/notify handshake so the\n\t * worker can block synchronously until the main thread has posted the response.\n\t */\n\tsignal: SharedArrayBuffer;\n\n\t/**\n\t * MessagePort through which the main thread returns the object buffer.\n\t */\n\tport: MessagePort;\n\n\t/**\n\t * Options for creating or fetching the buffer.\n\t */\n\toptions?: ISharedObjectBufferOptions;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"IValidationFailure.js","sourceRoot":"","sources":["../../../src/models/IValidationFailure.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n/**\n * Interface describing the reason a validation failed.\n */\nexport interface IValidationFailure {\n\t/**\n\t * The property that failed validation.\n\t */\n\tproperty: string;\n\n\t/**\n\t * The reason the validation failed as an i18 resource error.\n\t */\n\treason: string;\n\n\t/**\n\t * Additional properties for the validation failure.\n\t */\n\tproperties?: { [id: string]: unknown };\n}\n"]}
1
+ {"version":3,"file":"IValidationFailure.js","sourceRoot":"","sources":["../../../src/models/IValidationFailure.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n/**\n * Interface describing the reason a validation failed.\n */\nexport interface IValidationFailure {\n\t/**\n\t * The property that failed validation.\n\t */\n\tproperty: string;\n\n\t/**\n\t * The reason the validation failed as an i18n resource key.\n\t */\n\treason: string;\n\n\t/**\n\t * Additional properties for the validation failure.\n\t */\n\tproperties?: { [id: string]: unknown };\n}\n"]}
@@ -0,0 +1,13 @@
1
+ // Copyright 2026 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ /**
4
+ * Message type constants for the SharedObjectBuffer worker-to-main-thread protocol.
5
+ */
6
+ // eslint-disable-next-line @typescript-eslint/naming-convention
7
+ export const SharedObjectBufferMessageTypes = {
8
+ /**
9
+ * Worker requests the SharedArrayBuffer for a named object from the main thread.
10
+ */
11
+ GetBuffer: "twin:sharedObjectBuffer:getBuffer"
12
+ };
13
+ //# sourceMappingURL=sharedObjectBufferMessageTypes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sharedObjectBufferMessageTypes.js","sourceRoot":"","sources":["../../../src/models/sharedObjectBufferMessageTypes.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AAEvC;;GAEG;AACH,gEAAgE;AAChE,MAAM,CAAC,MAAM,8BAA8B,GAAG;IAC7C;;OAEG;IACH,SAAS,EAAE,mCAAmC;CACrC,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * Message type constants for the SharedObjectBuffer worker-to-main-thread protocol.\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport const SharedObjectBufferMessageTypes = {\n\t/**\n\t * Worker requests the SharedArrayBuffer for a named object from the main thread.\n\t */\n\tGetBuffer: \"twin:sharedObjectBuffer:getBuffer\"\n} as const;\n\n/**\n * Union of all SharedObjectBuffer message type strings.\n */\nexport type SharedObjectBufferMessageTypes =\n\t(typeof SharedObjectBufferMessageTypes)[keyof typeof SharedObjectBufferMessageTypes];\n"]}
@@ -157,7 +157,7 @@ export class AsyncCache {
157
157
  * @param key The key to set in the cache.
158
158
  * @param value The value to set in the cache.
159
159
  * @param ttlMs The TTL of the entry in the cache in milliseconds. Defaults to 1000 (1 second).
160
- * @returns Nothing.
160
+ * @returns A promise that resolves when the entry has been stored.
161
161
  */
162
162
  static async set(key, value, ttlMs) {
163
163
  const expires = Date.now() + (ttlMs ?? 1000);
@@ -246,6 +246,7 @@ export class AsyncCache {
246
246
  * @param requestMethod The method to execute.
247
247
  * @param resolve The resolver for the waiter.
248
248
  * @param reject The rejector for the waiter.
249
+ * @internal
249
250
  */
250
251
  static async resolveWaiter(requestMethod, resolve, reject) {
251
252
  try {
@@ -298,6 +299,7 @@ export class AsyncCache {
298
299
  * Deletes the given key from the cache if it has expired and is not in-progress.
299
300
  * Returns true if the entry was evicted.
300
301
  * @param key The cache entry key to check.
302
+ * @returns True if the expired entry was removed; otherwise, false.
301
303
  * @internal
302
304
  */
303
305
  static evictIfExpired(key) {
@@ -312,6 +314,7 @@ export class AsyncCache {
312
314
  /**
313
315
  * Returns the expiry timestamp of the tracked next-expiry entry, or undefined if there
314
316
  * is no tracked entry or it is no longer present in the cache.
317
+ * @returns The next tracked expiry timestamp, if one is still available.
315
318
  * @internal
316
319
  */
317
320
  static getNextExpiry() {
@@ -1 +1 @@
1
- {"version":3,"file":"asyncCache.js","sourceRoot":"","sources":["../../../src/utils/asyncCache.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,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YAC9F,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC;YAClB,OAAO,IAAI,CAAC;QACb,CAAC;QACD,OAAO,KAAK,CAAC;IACd,CAAC;IAED;;;;OAIG;IACK,MAAM,CAAC,aAAa;QAC3B,MAAM,OAAO,GAAG,WAAW,CAAC,GAAG,CAAS,UAAU,CAAC,sBAAsB,CAAC,CAAC;QAC3E,IAAI,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;YACvB,OAAO,SAAS,CAAC;QAClB,CAAC;QACD,MAAM,KAAK,GAAG,UAAU,CAAC,cAAc,EAAE,CAAC;QAC1C,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC;QACjC,OAAO,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC;IAC5D,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Is } from \"./is.js\";\nimport { SharedStore } from \"./sharedStore.js\";\n\n/**\n * Cache the results from asynchronous requests.\n */\nexport class AsyncCache {\n\t/**\n\t * Cache key for the shared cache object in the SharedStore.\n\t * @internal\n\t */\n\tprivate static readonly _CACHE_KEY = \"asyncCache\";\n\n\t/**\n\t * Cache key for the entry key of the soonest-expiring cache entry, used to optimize cleanup.\n\t * @internal\n\t */\n\tprivate static readonly _NEXT_EXPIRY_CACHE_KEY = \"asyncCacheNextExpiryKey\";\n\n\t/**\n\t * Cache key for the timestamp of the last full cleanup scan.\n\t * @internal\n\t */\n\tprivate static readonly _LAST_CLEANUP_KEY = \"asyncCacheLastCleanup\";\n\n\t/**\n\t * Minimum interval in ms between full cleanup scans.\n\t * @internal\n\t */\n\tprivate static readonly _CLEANUP_INTERVAL_MS = 5000;\n\n\t/**\n\t * Execute an async request and cache the result.\n\t * @param key The key for the entry in the cache.\n\t * @param ttlMs The TTL of the entry in the cache.\n\t * @param requestMethod The method to call if not cached.\n\t * @param cacheFailures Cache failure results, defaults to false.\n\t * @returns The response.\n\t */\n\tpublic static async exec<T = unknown>(\n\t\tkey: string,\n\t\tttlMs: number | undefined,\n\t\trequestMethod: () => Promise<T>,\n\t\tcacheFailures?: boolean\n\t): Promise<T> {\n\t\tconst cacheEnabled = Is.integer(ttlMs) && ttlMs > 0;\n\t\tif (!cacheEnabled) {\n\t\t\t// No caching, just execute the request method\n\t\t\treturn requestMethod();\n\t\t}\n\n\t\tAsyncCache.cleanupExpired();\n\t\t// Cleanup will not necessarily remove the entry for the key we are requesting\n\t\t// as it is throttled, so we also check and evict if expired here to ensure we don't return stale data.\n\t\tAsyncCache.evictIfExpired(key);\n\n\t\tconst cache = AsyncCache.getSharedCache<T>();\n\t\tconst cachedEntry = cache[key];\n\n\t\t// Do we have a cache entry for the key\n\t\tif (cachedEntry) {\n\t\t\tif (!Is.empty(cachedEntry.result)) {\n\t\t\t\t// If the cache has already resulted in a value, resolve it\n\t\t\t\treturn Promise.resolve(cachedEntry.result);\n\t\t\t} else if (!Is.empty(cachedEntry.error)) {\n\t\t\t\t// If the cache has already resulted in an error, reject it\n\t\t\t\treturn Promise.reject(cachedEntry.error);\n\t\t\t}\n\n\t\t\t// Otherwise create a promise to return and store the resolver\n\t\t\t// and rejector in the cache entry, so that we can call then\n\t\t\t// when the request is done\n\n\t\t\tlet storedResolve: ((value: T | PromiseLike<T>) => void) | undefined;\n\t\t\tlet storedReject: ((reason?: unknown) => void) | undefined;\n\t\t\tconst wait = new Promise<T>((resolve, reject) => {\n\t\t\t\tstoredResolve = resolve;\n\t\t\t\tstoredReject = reject;\n\t\t\t});\n\t\t\tif (!Is.empty(storedResolve) && !Is.empty(storedReject)) {\n\t\t\t\tcachedEntry.promiseQueue.push({\n\t\t\t\t\trequestMethod,\n\t\t\t\t\tresolve: storedResolve,\n\t\t\t\t\treject: storedReject\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn wait;\n\t\t}\n\n\t\t// If we don't have a cache entry, create a new one\n\t\tconst expires = Date.now() + ttlMs;\n\t\tconst cacheEntry: {\n\t\t\tresult?: T;\n\t\t\terror?: unknown;\n\t\t\tinProgress?: boolean;\n\t\t\tpromiseQueue: {\n\t\t\t\trequestMethod: () => Promise<T>;\n\t\t\t\tresolve: (value: T | PromiseLike<T>) => void;\n\t\t\t\treject: (reason?: unknown) => void;\n\t\t\t}[];\n\t\t\texpires: number;\n\t\t} = {\n\t\t\tinProgress: true,\n\t\t\tpromiseQueue: [],\n\t\t\texpires\n\t\t};\n\t\tcache[key] = cacheEntry;\n\t\tAsyncCache.updateNextExpiryKey(key, expires);\n\n\t\t// Return a promise that wraps the original request method\n\t\t// so that we can store any results or errors in the cache\n\t\treturn new Promise((resolve, reject) => {\n\t\t\t// Call the request method and store the result\n\t\t\trequestMethod()\n\t\t\t\t// eslint-disable-next-line promise/prefer-await-to-then\n\t\t\t\t.then(res => {\n\t\t\t\t\t// If the request was successful, store the result\n\t\t\t\t\tcacheEntry.inProgress = false;\n\t\t\t\t\tcacheEntry.result = res;\n\n\t\t\t\t\t// and resolve both this promise and all the waiters\n\t\t\t\t\tresolve(res);\n\t\t\t\t\tfor (const wait of cacheEntry.promiseQueue) {\n\t\t\t\t\t\twait.resolve(res);\n\t\t\t\t\t}\n\t\t\t\t\tcacheEntry.promiseQueue = [];\n\t\t\t\t\treturn res;\n\t\t\t\t})\n\t\t\t\t// eslint-disable-next-line promise/prefer-await-to-then\n\t\t\t\t.catch((err: unknown) => {\n\t\t\t\t\t// Reject the promise\n\t\t\t\t\treject(err);\n\t\t\t\t\tcacheEntry.inProgress = false;\n\n\t\t\t\t\t// Handle the waiters based on the cacheFailures flag\n\t\t\t\t\tif (cacheFailures ?? false) {\n\t\t\t\t\t\t// If we are caching failures, store the error and reject the waiters\n\t\t\t\t\t\tcacheEntry.error = err;\n\t\t\t\t\t\tfor (const wait of cacheEntry.promiseQueue) {\n\t\t\t\t\t\t\twait.reject(err);\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// Clear the waiters so we don't call them again\n\t\t\t\t\t\tcacheEntry.promiseQueue = [];\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// If not caching failures for any queued requests we\n\t\t\t\t\t\t// have no value to either resolve or reject, so we\n\t\t\t\t\t\t// just resolve with the original request method\n\t\t\t\t\t\tfor (const wait of cacheEntry.promiseQueue) {\n\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-floating-promises\n\t\t\t\t\t\t\tAsyncCache.resolveWaiter(wait.requestMethod, wait.resolve, wait.reject);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (cache[key] === cacheEntry) {\n\t\t\t\t\t\t\tdelete cache[key];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t});\n\t}\n\n\t/**\n\t * Get an entry from the cache.\n\t * @param key The key to get from the cache.\n\t * @returns The item from the cache if it exists, or undefined if the key is missing, expired, or\n\t * its request is still in-progress. Throws if a cached failure exists for the key.\n\t */\n\tpublic static async get<T = unknown>(key: string): Promise<T | undefined> {\n\t\tif (AsyncCache.evictIfExpired(key)) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst cache = AsyncCache.getSharedCache<T>();\n\t\tconst entry = cache[key];\n\n\t\tif (!Is.empty(entry?.result)) {\n\t\t\t// If the cache has already resulted in a value, resolve it\n\t\t\treturn entry.result;\n\t\t}\n\n\t\tif (!Is.empty(entry?.error)) {\n\t\t\t// If the cache has already resulted in an error, reject it\n\t\t\tthrow entry.error as Error;\n\t\t}\n\t}\n\n\t/**\n\t * Set an entry into the cache.\n\t * @param key The key to set in the cache.\n\t * @param value The value to set in the cache.\n\t * @param ttlMs The TTL of the entry in the cache in milliseconds. Defaults to 1000 (1 second).\n\t * @returns Nothing.\n\t */\n\tpublic static async set<T = unknown>(key: string, value: T, ttlMs?: number): Promise<void> {\n\t\tconst expires = Date.now() + (ttlMs ?? 1000);\n\t\tconst cache = AsyncCache.getSharedCache();\n\t\tcache[key] = {\n\t\t\tresult: value,\n\t\t\tpromiseQueue: [],\n\t\t\texpires\n\t\t};\n\t\tAsyncCache.updateNextExpiryKey(key, expires);\n\t}\n\n\t/**\n\t * Remove an entry from the cache.\n\t * @param key The key to remove from the cache.\n\t */\n\tpublic static remove(key: string): void {\n\t\tconst cache = AsyncCache.getSharedCache();\n\t\tdelete cache[key];\n\t\tconst nextKey = SharedStore.get<string>(AsyncCache._NEXT_EXPIRY_CACHE_KEY);\n\t\tif (nextKey === key) {\n\t\t\tAsyncCache.recalculateNextKey();\n\t\t}\n\t}\n\n\t/**\n\t * Clear the cache.\n\t * @param prefix Optional prefix to clear only entries with that prefix.\n\t */\n\tpublic static clearCache(prefix?: string): void {\n\t\tconst cache = AsyncCache.getSharedCache();\n\t\tif (Is.stringValue(prefix)) {\n\t\t\tconst nextKey = SharedStore.get<string>(AsyncCache._NEXT_EXPIRY_CACHE_KEY);\n\t\t\tlet nextKeyRemoved = false;\n\t\t\tfor (const entry in cache) {\n\t\t\t\tif (entry.startsWith(prefix)) {\n\t\t\t\t\tif (entry === nextKey) {\n\t\t\t\t\t\tnextKeyRemoved = true;\n\t\t\t\t\t}\n\t\t\t\t\tdelete cache[entry];\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (nextKeyRemoved) {\n\t\t\t\tAsyncCache.recalculateNextKey();\n\t\t\t}\n\t\t} else {\n\t\t\tSharedStore.set(AsyncCache._CACHE_KEY, {});\n\t\t\tSharedStore.set(AsyncCache._NEXT_EXPIRY_CACHE_KEY, undefined);\n\t\t\tSharedStore.set(AsyncCache._LAST_CLEANUP_KEY, Date.now());\n\t\t}\n\t}\n\n\t/**\n\t * Perform a cleanup of the expired entries in the cache.\n\t */\n\tpublic static cleanupExpired(): void {\n\t\tconst now = Date.now();\n\t\tconst lastCleanup = SharedStore.get<number>(AsyncCache._LAST_CLEANUP_KEY) ?? 0;\n\t\tif (now - lastCleanup < AsyncCache._CLEANUP_INTERVAL_MS) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst expiry = AsyncCache.getNextExpiry();\n\t\tif (expiry !== undefined && expiry > now) {\n\t\t\t// Nothing is expired yet. Stamp the time so the throttle suppresses further checks\n\t\t\t// for the next interval. Per-key freshness is still guaranteed because exec() and\n\t\t\t// get() call evictIfExpired() directly before reading the cache.\n\t\t\tSharedStore.set(AsyncCache._LAST_CLEANUP_KEY, now);\n\t\t\treturn;\n\t\t}\n\n\t\tSharedStore.set(AsyncCache._LAST_CLEANUP_KEY, now);\n\t\tAsyncCache.recalculateNextKey();\n\t}\n\n\t/**\n\t * Get the shared cache.\n\t * @returns The shared cache.\n\t * @internal\n\t */\n\tprivate static getSharedCache<T = unknown>(): {\n\t\t[url: string]: {\n\t\t\tresult?: T;\n\t\t\terror?: unknown;\n\t\t\tinProgress?: boolean;\n\t\t\tpromiseQueue: {\n\t\t\t\trequestMethod: () => Promise<T>;\n\t\t\t\tresolve: (value: T | PromiseLike<T>) => void;\n\t\t\t\treject: (reason?: unknown) => void;\n\t\t\t}[];\n\t\t\texpires: number;\n\t\t};\n\t} {\n\t\tlet sharedCache = SharedStore.get<{\n\t\t\t[url: string]: {\n\t\t\t\tresult?: T;\n\t\t\t\terror?: unknown;\n\t\t\t\tinProgress?: boolean;\n\t\t\t\tpromiseQueue: {\n\t\t\t\t\trequestMethod: () => Promise<T>;\n\t\t\t\t\tresolve: (value: T | PromiseLike<T>) => void;\n\t\t\t\t\treject: (reason?: unknown) => void;\n\t\t\t\t}[];\n\t\t\t\texpires: number;\n\t\t\t};\n\t\t}>(AsyncCache._CACHE_KEY);\n\n\t\tif (Is.undefined(sharedCache)) {\n\t\t\tsharedCache = {};\n\t\t\tSharedStore.set(AsyncCache._CACHE_KEY, sharedCache);\n\t\t}\n\n\t\treturn sharedCache;\n\t}\n\n\t/**\n\t * Resolve a waiter by re-running its request method safely.\n\t * @param requestMethod The method to execute.\n\t * @param resolve The resolver for the waiter.\n\t * @param reject The rejector for the waiter.\n\t */\n\tprivate static async resolveWaiter<T>(\n\t\trequestMethod: () => Promise<T>,\n\t\tresolve: (value: T | PromiseLike<T>) => void,\n\t\treject: (reason?: unknown) => void\n\t): Promise<void> {\n\t\ttry {\n\t\t\tresolve(await requestMethod());\n\t\t} catch (waitErr) {\n\t\t\treject(waitErr);\n\t\t}\n\t}\n\n\t/**\n\t * Scan all cache entries, delete any that have expired, and record the key of the\n\t * soonest-expiring remaining entry.\n\t * @internal\n\t */\n\tprivate static recalculateNextKey(): void {\n\t\tconst now = Date.now();\n\t\tconst cache = AsyncCache.getSharedCache();\n\n\t\tif (Object.keys(cache).length === 0) {\n\t\t\tSharedStore.set(AsyncCache._NEXT_EXPIRY_CACHE_KEY, undefined);\n\t\t\treturn;\n\t\t}\n\n\t\tlet newNextKey: string | undefined;\n\t\tlet newNextExpiry = Number.MAX_SAFE_INTEGER;\n\t\tfor (const entryKey in cache) {\n\t\t\tconst { expires, inProgress } = cache[entryKey];\n\t\t\tif (expires > 0 && expires < now && inProgress !== true) {\n\t\t\t\tdelete cache[entryKey];\n\t\t\t} else if (expires > 0 && expires < newNextExpiry) {\n\t\t\t\tnewNextExpiry = expires;\n\t\t\t\tnewNextKey = entryKey;\n\t\t\t}\n\t\t}\n\t\tSharedStore.set(AsyncCache._NEXT_EXPIRY_CACHE_KEY, newNextKey);\n\t}\n\n\t/**\n\t * Update the tracked next-expiry entry key if the given entry expires sooner than the current one.\n\t * @param key The cache entry key.\n\t * @param expires The expiry timestamp of the entry.\n\t * @internal\n\t */\n\tprivate static updateNextExpiryKey(key: string, expires: number): void {\n\t\tconst expiry = AsyncCache.getNextExpiry();\n\t\tif (expiry !== undefined && expiry <= expires) {\n\t\t\treturn;\n\t\t}\n\t\tSharedStore.set(AsyncCache._NEXT_EXPIRY_CACHE_KEY, key);\n\t}\n\n\t/**\n\t * Deletes the given key from the cache if it has expired and is not in-progress.\n\t * Returns true if the entry was evicted.\n\t * @param key The cache entry key to check.\n\t * @internal\n\t */\n\tprivate static evictIfExpired(key: string): boolean {\n\t\tconst cache = AsyncCache.getSharedCache();\n\t\tconst entry = cache[key];\n\t\tif (!Is.empty(entry) && entry.expires > 0 && entry.expires < Date.now() && !entry.inProgress) {\n\t\t\tdelete cache[key];\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * Returns the expiry timestamp of the tracked next-expiry entry, or undefined if there\n\t * is no tracked entry or it is no longer present in the cache.\n\t * @internal\n\t */\n\tprivate static getNextExpiry(): number | undefined {\n\t\tconst nextKey = SharedStore.get<string>(AsyncCache._NEXT_EXPIRY_CACHE_KEY);\n\t\tif (Is.empty(nextKey)) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst cache = AsyncCache.getSharedCache();\n\t\tconst nextEntry = cache[nextKey];\n\t\treturn Is.empty(nextEntry) ? undefined : nextEntry.expires;\n\t}\n}\n"]}
1
+ {"version":3,"file":"asyncCache.js","sourceRoot":"","sources":["../../../src/utils/asyncCache.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAC7B,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C;;GAEG;AACH,MAAM,OAAO,UAAU;IACtB;;;OAGG;IACK,MAAM,CAAU,UAAU,GAAG,YAAY,CAAC;IAElD;;;OAGG;IACK,MAAM,CAAU,sBAAsB,GAAG,yBAAyB,CAAC;IAE3E;;;OAGG;IACK,MAAM,CAAU,iBAAiB,GAAG,uBAAuB,CAAC;IAEpE;;;OAGG;IACK,MAAM,CAAU,oBAAoB,GAAG,IAAI,CAAC;IAEpD;;;;;;;OAOG;IACI,MAAM,CAAC,KAAK,CAAC,IAAI,CACvB,GAAW,EACX,KAAyB,EACzB,aAA+B,EAC/B,aAAuB;QAEvB,MAAM,YAAY,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC;QACpD,IAAI,CAAC,YAAY,EAAE,CAAC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IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Is } from \"./is.js\";\nimport { SharedStore } from \"./sharedStore.js\";\n\n/**\n * Cache the results from asynchronous requests.\n */\nexport class AsyncCache {\n\t/**\n\t * Cache key for the shared cache object in the SharedStore.\n\t * @internal\n\t */\n\tprivate static readonly _CACHE_KEY = \"asyncCache\";\n\n\t/**\n\t * Cache key for the entry key of the soonest-expiring cache entry, used to optimize cleanup.\n\t * @internal\n\t */\n\tprivate static readonly _NEXT_EXPIRY_CACHE_KEY = \"asyncCacheNextExpiryKey\";\n\n\t/**\n\t * Cache key for the timestamp of the last full cleanup scan.\n\t * @internal\n\t */\n\tprivate static readonly _LAST_CLEANUP_KEY = \"asyncCacheLastCleanup\";\n\n\t/**\n\t * Minimum interval in ms between full cleanup scans.\n\t * @internal\n\t */\n\tprivate static readonly _CLEANUP_INTERVAL_MS = 5000;\n\n\t/**\n\t * Execute an async request and cache the result.\n\t * @param key The key for the entry in the cache.\n\t * @param ttlMs The TTL of the entry in the cache.\n\t * @param requestMethod The method to call if not cached.\n\t * @param cacheFailures Cache failure results, defaults to false.\n\t * @returns The response.\n\t */\n\tpublic static async exec<T = unknown>(\n\t\tkey: string,\n\t\tttlMs: number | undefined,\n\t\trequestMethod: () => Promise<T>,\n\t\tcacheFailures?: boolean\n\t): Promise<T> {\n\t\tconst cacheEnabled = Is.integer(ttlMs) && ttlMs > 0;\n\t\tif (!cacheEnabled) {\n\t\t\t// No caching, just execute the request method\n\t\t\treturn requestMethod();\n\t\t}\n\n\t\tAsyncCache.cleanupExpired();\n\t\t// Cleanup will not necessarily remove the entry for the key we are requesting\n\t\t// as it is throttled, so we also check and evict if expired here to ensure we don't return stale data.\n\t\tAsyncCache.evictIfExpired(key);\n\n\t\tconst cache = AsyncCache.getSharedCache<T>();\n\t\tconst cachedEntry = cache[key];\n\n\t\t// Do we have a cache entry for the key\n\t\tif (cachedEntry) {\n\t\t\tif (!Is.empty(cachedEntry.result)) {\n\t\t\t\t// If the cache has already resulted in a value, resolve it\n\t\t\t\treturn Promise.resolve(cachedEntry.result);\n\t\t\t} else if (!Is.empty(cachedEntry.error)) {\n\t\t\t\t// If the cache has already resulted in an error, reject it\n\t\t\t\treturn Promise.reject(cachedEntry.error);\n\t\t\t}\n\n\t\t\t// Otherwise create a promise to return and store the resolver\n\t\t\t// and rejector in the cache entry, so that we can call then\n\t\t\t// when the request is done\n\n\t\t\tlet storedResolve: ((value: T | PromiseLike<T>) => void) | undefined;\n\t\t\tlet storedReject: ((reason?: unknown) => void) | undefined;\n\t\t\tconst wait = new Promise<T>((resolve, reject) => {\n\t\t\t\tstoredResolve = resolve;\n\t\t\t\tstoredReject = reject;\n\t\t\t});\n\t\t\tif (!Is.empty(storedResolve) && !Is.empty(storedReject)) {\n\t\t\t\tcachedEntry.promiseQueue.push({\n\t\t\t\t\trequestMethod,\n\t\t\t\t\tresolve: storedResolve,\n\t\t\t\t\treject: storedReject\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn wait;\n\t\t}\n\n\t\t// If we don't have a cache entry, create a new one\n\t\tconst expires = Date.now() + ttlMs;\n\t\tconst cacheEntry: {\n\t\t\tresult?: T;\n\t\t\terror?: unknown;\n\t\t\tinProgress?: boolean;\n\t\t\tpromiseQueue: {\n\t\t\t\trequestMethod: () => Promise<T>;\n\t\t\t\tresolve: (value: T | PromiseLike<T>) => void;\n\t\t\t\treject: (reason?: unknown) => void;\n\t\t\t}[];\n\t\t\texpires: number;\n\t\t} = {\n\t\t\tinProgress: true,\n\t\t\tpromiseQueue: [],\n\t\t\texpires\n\t\t};\n\t\tcache[key] = cacheEntry;\n\t\tAsyncCache.updateNextExpiryKey(key, expires);\n\n\t\t// Return a promise that wraps the original request method\n\t\t// so that we can store any results or errors in the cache\n\t\treturn new Promise((resolve, reject) => {\n\t\t\t// Call the request method and store the result\n\t\t\trequestMethod()\n\t\t\t\t// eslint-disable-next-line promise/prefer-await-to-then\n\t\t\t\t.then(res => {\n\t\t\t\t\t// If the request was successful, store the result\n\t\t\t\t\tcacheEntry.inProgress = false;\n\t\t\t\t\tcacheEntry.result = res;\n\n\t\t\t\t\t// and resolve both this promise and all the waiters\n\t\t\t\t\tresolve(res);\n\t\t\t\t\tfor (const wait of cacheEntry.promiseQueue) {\n\t\t\t\t\t\twait.resolve(res);\n\t\t\t\t\t}\n\t\t\t\t\tcacheEntry.promiseQueue = [];\n\t\t\t\t\treturn res;\n\t\t\t\t})\n\t\t\t\t// eslint-disable-next-line promise/prefer-await-to-then\n\t\t\t\t.catch((err: unknown) => {\n\t\t\t\t\t// Reject the promise\n\t\t\t\t\treject(err);\n\t\t\t\t\tcacheEntry.inProgress = false;\n\n\t\t\t\t\t// Handle the waiters based on the cacheFailures flag\n\t\t\t\t\tif (cacheFailures ?? false) {\n\t\t\t\t\t\t// If we are caching failures, store the error and reject the waiters\n\t\t\t\t\t\tcacheEntry.error = err;\n\t\t\t\t\t\tfor (const wait of cacheEntry.promiseQueue) {\n\t\t\t\t\t\t\twait.reject(err);\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// Clear the waiters so we don't call them again\n\t\t\t\t\t\tcacheEntry.promiseQueue = [];\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// If not caching failures for any queued requests we\n\t\t\t\t\t\t// have no value to either resolve or reject, so we\n\t\t\t\t\t\t// just resolve with the original request method\n\t\t\t\t\t\tfor (const wait of cacheEntry.promiseQueue) {\n\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-floating-promises\n\t\t\t\t\t\t\tAsyncCache.resolveWaiter(wait.requestMethod, wait.resolve, wait.reject);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (cache[key] === cacheEntry) {\n\t\t\t\t\t\t\tdelete cache[key];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t});\n\t}\n\n\t/**\n\t * Get an entry from the cache.\n\t * @param key The key to get from the cache.\n\t * @returns The item from the cache if it exists, or undefined if the key is missing, expired, or\n\t * its request is still in-progress. Throws if a cached failure exists for the key.\n\t */\n\tpublic static async get<T = unknown>(key: string): Promise<T | undefined> {\n\t\tif (AsyncCache.evictIfExpired(key)) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst cache = AsyncCache.getSharedCache<T>();\n\t\tconst entry = cache[key];\n\n\t\tif (!Is.empty(entry?.result)) {\n\t\t\t// If the cache has already resulted in a value, resolve it\n\t\t\treturn entry.result;\n\t\t}\n\n\t\tif (!Is.empty(entry?.error)) {\n\t\t\t// If the cache has already resulted in an error, reject it\n\t\t\tthrow entry.error as Error;\n\t\t}\n\t}\n\n\t/**\n\t * Set an entry into the cache.\n\t * @param key The key to set in the cache.\n\t * @param value The value to set in the cache.\n\t * @param ttlMs The TTL of the entry in the cache in milliseconds. Defaults to 1000 (1 second).\n\t * @returns A promise that resolves when the entry has been stored.\n\t */\n\tpublic static async set<T = unknown>(key: string, value: T, ttlMs?: number): Promise<void> {\n\t\tconst expires = Date.now() + (ttlMs ?? 1000);\n\t\tconst cache = AsyncCache.getSharedCache();\n\t\tcache[key] = {\n\t\t\tresult: value,\n\t\t\tpromiseQueue: [],\n\t\t\texpires\n\t\t};\n\t\tAsyncCache.updateNextExpiryKey(key, expires);\n\t}\n\n\t/**\n\t * Remove an entry from the cache.\n\t * @param key The key to remove from the cache.\n\t */\n\tpublic static remove(key: string): void {\n\t\tconst cache = AsyncCache.getSharedCache();\n\t\tdelete cache[key];\n\t\tconst nextKey = SharedStore.get<string>(AsyncCache._NEXT_EXPIRY_CACHE_KEY);\n\t\tif (nextKey === key) {\n\t\t\tAsyncCache.recalculateNextKey();\n\t\t}\n\t}\n\n\t/**\n\t * Clear the cache.\n\t * @param prefix Optional prefix to clear only entries with that prefix.\n\t */\n\tpublic static clearCache(prefix?: string): void {\n\t\tconst cache = AsyncCache.getSharedCache();\n\t\tif (Is.stringValue(prefix)) {\n\t\t\tconst nextKey = SharedStore.get<string>(AsyncCache._NEXT_EXPIRY_CACHE_KEY);\n\t\t\tlet nextKeyRemoved = false;\n\t\t\tfor (const entry in cache) {\n\t\t\t\tif (entry.startsWith(prefix)) {\n\t\t\t\t\tif (entry === nextKey) {\n\t\t\t\t\t\tnextKeyRemoved = true;\n\t\t\t\t\t}\n\t\t\t\t\tdelete cache[entry];\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (nextKeyRemoved) {\n\t\t\t\tAsyncCache.recalculateNextKey();\n\t\t\t}\n\t\t} else {\n\t\t\tSharedStore.set(AsyncCache._CACHE_KEY, {});\n\t\t\tSharedStore.set(AsyncCache._NEXT_EXPIRY_CACHE_KEY, undefined);\n\t\t\tSharedStore.set(AsyncCache._LAST_CLEANUP_KEY, Date.now());\n\t\t}\n\t}\n\n\t/**\n\t * Perform a cleanup of the expired entries in the cache.\n\t */\n\tpublic static cleanupExpired(): void {\n\t\tconst now = Date.now();\n\t\tconst lastCleanup = SharedStore.get<number>(AsyncCache._LAST_CLEANUP_KEY) ?? 0;\n\t\tif (now - lastCleanup < AsyncCache._CLEANUP_INTERVAL_MS) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst expiry = AsyncCache.getNextExpiry();\n\t\tif (expiry !== undefined && expiry > now) {\n\t\t\t// Nothing is expired yet. Stamp the time so the throttle suppresses further checks\n\t\t\t// for the next interval. Per-key freshness is still guaranteed because exec() and\n\t\t\t// get() call evictIfExpired() directly before reading the cache.\n\t\t\tSharedStore.set(AsyncCache._LAST_CLEANUP_KEY, now);\n\t\t\treturn;\n\t\t}\n\n\t\tSharedStore.set(AsyncCache._LAST_CLEANUP_KEY, now);\n\t\tAsyncCache.recalculateNextKey();\n\t}\n\n\t/**\n\t * Get the shared cache.\n\t * @returns The shared cache.\n\t * @internal\n\t */\n\tprivate static getSharedCache<T = unknown>(): {\n\t\t[url: string]: {\n\t\t\tresult?: T;\n\t\t\terror?: unknown;\n\t\t\tinProgress?: boolean;\n\t\t\tpromiseQueue: {\n\t\t\t\trequestMethod: () => Promise<T>;\n\t\t\t\tresolve: (value: T | PromiseLike<T>) => void;\n\t\t\t\treject: (reason?: unknown) => void;\n\t\t\t}[];\n\t\t\texpires: number;\n\t\t};\n\t} {\n\t\tlet sharedCache = SharedStore.get<{\n\t\t\t[url: string]: {\n\t\t\t\tresult?: T;\n\t\t\t\terror?: unknown;\n\t\t\t\tinProgress?: boolean;\n\t\t\t\tpromiseQueue: {\n\t\t\t\t\trequestMethod: () => Promise<T>;\n\t\t\t\t\tresolve: (value: T | PromiseLike<T>) => void;\n\t\t\t\t\treject: (reason?: unknown) => void;\n\t\t\t\t}[];\n\t\t\t\texpires: number;\n\t\t\t};\n\t\t}>(AsyncCache._CACHE_KEY);\n\n\t\tif (Is.undefined(sharedCache)) {\n\t\t\tsharedCache = {};\n\t\t\tSharedStore.set(AsyncCache._CACHE_KEY, sharedCache);\n\t\t}\n\n\t\treturn sharedCache;\n\t}\n\n\t/**\n\t * Resolve a waiter by re-running its request method safely.\n\t * @param requestMethod The method to execute.\n\t * @param resolve The resolver for the waiter.\n\t * @param reject The rejector for the waiter.\n\t * @internal\n\t */\n\tprivate static async resolveWaiter<T>(\n\t\trequestMethod: () => Promise<T>,\n\t\tresolve: (value: T | PromiseLike<T>) => void,\n\t\treject: (reason?: unknown) => void\n\t): Promise<void> {\n\t\ttry {\n\t\t\tresolve(await requestMethod());\n\t\t} catch (waitErr) {\n\t\t\treject(waitErr);\n\t\t}\n\t}\n\n\t/**\n\t * Scan all cache entries, delete any that have expired, and record the key of the\n\t * soonest-expiring remaining entry.\n\t * @internal\n\t */\n\tprivate static recalculateNextKey(): void {\n\t\tconst now = Date.now();\n\t\tconst cache = AsyncCache.getSharedCache();\n\n\t\tif (Object.keys(cache).length === 0) {\n\t\t\tSharedStore.set(AsyncCache._NEXT_EXPIRY_CACHE_KEY, undefined);\n\t\t\treturn;\n\t\t}\n\n\t\tlet newNextKey: string | undefined;\n\t\tlet newNextExpiry = Number.MAX_SAFE_INTEGER;\n\t\tfor (const entryKey in cache) {\n\t\t\tconst { expires, inProgress } = cache[entryKey];\n\t\t\tif (expires > 0 && expires < now && inProgress !== true) {\n\t\t\t\tdelete cache[entryKey];\n\t\t\t} else if (expires > 0 && expires < newNextExpiry) {\n\t\t\t\tnewNextExpiry = expires;\n\t\t\t\tnewNextKey = entryKey;\n\t\t\t}\n\t\t}\n\t\tSharedStore.set(AsyncCache._NEXT_EXPIRY_CACHE_KEY, newNextKey);\n\t}\n\n\t/**\n\t * Update the tracked next-expiry entry key if the given entry expires sooner than the current one.\n\t * @param key The cache entry key.\n\t * @param expires The expiry timestamp of the entry.\n\t * @internal\n\t */\n\tprivate static updateNextExpiryKey(key: string, expires: number): void {\n\t\tconst expiry = AsyncCache.getNextExpiry();\n\t\tif (expiry !== undefined && expiry <= expires) {\n\t\t\treturn;\n\t\t}\n\t\tSharedStore.set(AsyncCache._NEXT_EXPIRY_CACHE_KEY, key);\n\t}\n\n\t/**\n\t * Deletes the given key from the cache if it has expired and is not in-progress.\n\t * Returns true if the entry was evicted.\n\t * @param key The cache entry key to check.\n\t * @returns True if the expired entry was removed; otherwise, false.\n\t * @internal\n\t */\n\tprivate static evictIfExpired(key: string): boolean {\n\t\tconst cache = AsyncCache.getSharedCache();\n\t\tconst entry = cache[key];\n\t\tif (!Is.empty(entry) && entry.expires > 0 && entry.expires < Date.now() && !entry.inProgress) {\n\t\t\tdelete cache[key];\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * Returns the expiry timestamp of the tracked next-expiry entry, or undefined if there\n\t * is no tracked entry or it is no longer present in the cache.\n\t * @returns The next tracked expiry timestamp, if one is still available.\n\t * @internal\n\t */\n\tprivate static getNextExpiry(): number | undefined {\n\t\tconst nextKey = SharedStore.get<string>(AsyncCache._NEXT_EXPIRY_CACHE_KEY);\n\t\tif (Is.empty(nextKey)) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst cache = AsyncCache.getSharedCache();\n\t\tconst nextEntry = cache[nextKey];\n\t\treturn Is.empty(nextEntry) ? undefined : nextEntry.expires;\n\t}\n}\n"]}
@@ -10,8 +10,7 @@ export class Coerce {
10
10
  /**
11
11
  * Coerce the value to a string.
12
12
  * @param value The value to coerce.
13
- * @throws TypeError If the value can not be coerced.
14
- * @returns The value if it can be coerced.
13
+ * @returns The coerced string, or undefined if the value cannot be coerced.
15
14
  */
16
15
  static string(value) {
17
16
  if (Is.undefined(value)) {
@@ -33,8 +32,7 @@ export class Coerce {
33
32
  /**
34
33
  * Coerce the value to a number.
35
34
  * @param value The value to coerce.
36
- * @throws TypeError If the value can not be coerced.
37
- * @returns The value if it can be coerced.
35
+ * @returns The coerced number, or undefined if the value cannot be coerced.
38
36
  */
39
37
  static number(value) {
40
38
  if (Is.undefined(value)) {
@@ -59,8 +57,7 @@ export class Coerce {
59
57
  /**
60
58
  * Coerce the value to an integer.
61
59
  * @param value The value to coerce.
62
- * @throws TypeError If the value can not be coerced.
63
- * @returns The value if it can be coerced.
60
+ * @returns The coerced integer, or undefined if the value cannot be coerced.
64
61
  */
65
62
  static integer(value) {
66
63
  const num = Coerce.number(value);
@@ -71,8 +68,7 @@ export class Coerce {
71
68
  /**
72
69
  * Coerce the value to a bigint.
73
70
  * @param value The value to coerce.
74
- * @throws TypeError If the value can not be coerced.
75
- * @returns The value if it can be coerced.
71
+ * @returns The coerced bigint, or undefined if the value cannot be coerced.
76
72
  */
77
73
  static bigint(value) {
78
74
  if (Is.undefined(value)) {
@@ -97,8 +93,7 @@ export class Coerce {
97
93
  /**
98
94
  * Coerce the value to a boolean.
99
95
  * @param value The value to coerce.
100
- * @throws TypeError If the value can not be coerced.
101
- * @returns The value if it can be coerced.
96
+ * @returns The coerced boolean, or undefined if the value cannot be coerced.
102
97
  */
103
98
  static boolean(value) {
104
99
  if (Is.undefined(value)) {
@@ -123,8 +118,7 @@ export class Coerce {
123
118
  /**
124
119
  * Coerce the value to a date.
125
120
  * @param value The value to coerce.
126
- * @throws TypeError If the value can not be coerced.
127
- * @returns The value if it can be coerced.
121
+ * @returns The coerced date, or undefined if the value cannot be coerced.
128
122
  */
129
123
  static date(value) {
130
124
  if (Is.undefined(value)) {
@@ -147,8 +141,7 @@ export class Coerce {
147
141
  /**
148
142
  * Coerce the value to a date/time.
149
143
  * @param value The value to coerce.
150
- * @throws TypeError If the value can not be coerced.
151
- * @returns The value if it can be coerced.
144
+ * @returns The coerced date/time, or undefined if the value cannot be coerced.
152
145
  */
153
146
  static dateTime(value) {
154
147
  if (Is.undefined(value)) {
@@ -171,8 +164,7 @@ export class Coerce {
171
164
  /**
172
165
  * Coerce the value to a time.
173
166
  * @param value The value to coerce.
174
- * @throws TypeError If the value can not be coerced.
175
- * @returns The value if it can be coerced.
167
+ * @returns The coerced time, or undefined if the value cannot be coerced.
176
168
  */
177
169
  static time(value) {
178
170
  if (Is.undefined(value)) {
@@ -197,8 +189,7 @@ export class Coerce {
197
189
  /**
198
190
  * Coerce the value to an object.
199
191
  * @param value The value to coerce.
200
- * @throws TypeError If the value can not be coerced.
201
- * @returns The value if it can be coerced.
192
+ * @returns The coerced object, or undefined if the value cannot be coerced.
202
193
  */
203
194
  static object(value) {
204
195
  if (Is.undefined(value)) {
@@ -217,8 +208,7 @@ export class Coerce {
217
208
  /**
218
209
  * Coerce the value to a Uint8Array.
219
210
  * @param value The value to coerce.
220
- * @throws TypeError If the value can not be coerced.
221
- * @returns The value if it can be coerced.
211
+ * @returns The coerced Uint8Array, or undefined if the value cannot be coerced.
222
212
  */
223
213
  static uint8Array(value) {
224
214
  if (Is.undefined(value)) {
@@ -1 +1 @@
1
- {"version":3,"file":"coerce.js","sourceRoot":"","sources":["../../../src/utils/coerce.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD;;GAEG;AACH,MAAM,OAAO,MAAM;IAClB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YAC/B,KAAK,UAAU,CAAC,IAAI;gBACnB,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAC3B,KAAK,UAAU,CAAC,MAAM;gBACrB,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC7B,KAAK,UAAU,CAAC,UAAU;gBACzB,OAAO,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;YACjC;gBACC,OAAO,KAAK,CAAC;QACf,CAAC;IACF,CAAC;CACD","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Converter } from \"./converter.js\";\nimport { Is } from \"./is.js\";\nimport { CoerceType } from \"../models/coerceType.js\";\n\n/**\n * Coerce an object from one type to another.\n */\nexport class Coerce {\n\t/**\n\t * Coerce the value to a string.\n\t * @param value The value to coerce.\n\t * @throws TypeError If the value can not be coerced.\n\t * @returns The value if it can be coerced.\n\t */\n\tpublic static string(value: unknown): string | undefined {\n\t\tif (Is.undefined(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.string(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.number(value)) {\n\t\t\treturn value.toString();\n\t\t}\n\t\tif (Is.boolean(value)) {\n\t\t\treturn value ? \"true\" : \"false\";\n\t\t}\n\t\tif (Is.date(value)) {\n\t\t\treturn value.toISOString();\n\t\t}\n\t}\n\n\t/**\n\t * Coerce the value to a number.\n\t * @param value The value to coerce.\n\t * @throws TypeError If the value can not be coerced.\n\t * @returns The value if it can be coerced.\n\t */\n\tpublic static number(value: unknown): number | undefined {\n\t\tif (Is.undefined(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.number(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.string(value)) {\n\t\t\tconst parsed = Number.parseFloat(value);\n\t\t\tif (Is.number(parsed)) {\n\t\t\t\treturn parsed;\n\t\t\t}\n\t\t}\n\t\tif (Is.boolean(value)) {\n\t\t\treturn value ? 1 : 0;\n\t\t}\n\t\tif (Is.date(value)) {\n\t\t\treturn value.getTime();\n\t\t}\n\t}\n\n\t/**\n\t * Coerce the value to an integer.\n\t * @param value The value to coerce.\n\t * @throws TypeError If the value can not be coerced.\n\t * @returns The value if it can be coerced.\n\t */\n\tpublic static integer(value: unknown): number | undefined {\n\t\tconst num = Coerce.number(value);\n\t\tif (!Is.undefined(num)) {\n\t\t\treturn Math.trunc(num);\n\t\t}\n\t}\n\n\t/**\n\t * Coerce the value to a bigint.\n\t * @param value The value to coerce.\n\t * @throws TypeError If the value can not be coerced.\n\t * @returns The value if it can be coerced.\n\t */\n\tpublic static bigint(value: unknown): bigint | undefined {\n\t\tif (Is.undefined(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.bigint(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.number(value)) {\n\t\t\treturn BigInt(value);\n\t\t}\n\t\tif (Is.string(value)) {\n\t\t\tconst parsed = Number.parseFloat(value);\n\t\t\tif (Is.integer(parsed)) {\n\t\t\t\treturn BigInt(parsed);\n\t\t\t}\n\t\t}\n\t\tif (Is.boolean(value)) {\n\t\t\treturn value ? 1n : 0n;\n\t\t}\n\t}\n\n\t/**\n\t * Coerce the value to a boolean.\n\t * @param value The value to coerce.\n\t * @throws TypeError If the value can not be coerced.\n\t * @returns The value if it can be coerced.\n\t */\n\tpublic static boolean(value: unknown): boolean | undefined {\n\t\tif (Is.undefined(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.boolean(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.number(value)) {\n\t\t\t// eslint-disable-next-line no-unneeded-ternary\n\t\t\treturn value ? true : false;\n\t\t}\n\t\tif (Is.string(value)) {\n\t\t\tif (/true/i.test(value)) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif (/false/i.test(value)) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Coerce the value to a date.\n\t * @param value The value to coerce.\n\t * @throws TypeError If the value can not be coerced.\n\t * @returns The value if it can be coerced.\n\t */\n\tpublic static date(value: unknown): Date | undefined {\n\t\tif (Is.undefined(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.date(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.number(value)) {\n\t\t\treturn new Date(value);\n\t\t}\n\t\tif (Is.string(value)) {\n\t\t\tconst dt = new Date(value);\n\t\t\tif (!Number.isNaN(dt.getTime())) {\n\t\t\t\tconst utc = Date.UTC(dt.getUTCFullYear(), dt.getUTCMonth(), dt.getUTCDate());\n\t\t\t\treturn new Date(utc);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Coerce the value to a date/time.\n\t * @param value The value to coerce.\n\t * @throws TypeError If the value can not be coerced.\n\t * @returns The value if it can be coerced.\n\t */\n\tpublic static dateTime(value: unknown): Date | undefined {\n\t\tif (Is.undefined(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.date(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.number(value)) {\n\t\t\treturn new Date(value);\n\t\t}\n\t\tif (Is.string(value)) {\n\t\t\tconst dt = new Date(value);\n\t\t\tif (!Number.isNaN(dt.getTime())) {\n\t\t\t\tconst utc = Date.UTC(\n\t\t\t\t\tdt.getUTCFullYear(),\n\t\t\t\t\tdt.getUTCMonth(),\n\t\t\t\t\tdt.getUTCDate(),\n\t\t\t\t\tdt.getUTCHours(),\n\t\t\t\t\tdt.getUTCMinutes(),\n\t\t\t\t\tdt.getUTCSeconds(),\n\t\t\t\t\tdt.getUTCMilliseconds()\n\t\t\t\t);\n\t\t\t\treturn new Date(utc);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Coerce the value to a time.\n\t * @param value The value to coerce.\n\t * @throws TypeError If the value can not be coerced.\n\t * @returns The value if it can be coerced.\n\t */\n\tpublic static time(value: unknown): Date | undefined {\n\t\tif (Is.undefined(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.date(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.number(value)) {\n\t\t\tconst dt = new Date(value);\n\t\t\tdt.setFullYear(1970, 0, 1);\n\t\t\treturn dt;\n\t\t}\n\t\tif (Is.string(value)) {\n\t\t\tconst dt = new Date(value);\n\t\t\tif (!Number.isNaN(dt.getTime())) {\n\t\t\t\tconst utc = Date.UTC(\n\t\t\t\t\t1970,\n\t\t\t\t\t0,\n\t\t\t\t\t1,\n\t\t\t\t\tdt.getUTCHours(),\n\t\t\t\t\tdt.getUTCMinutes(),\n\t\t\t\t\tdt.getUTCSeconds(),\n\t\t\t\t\tdt.getUTCMilliseconds()\n\t\t\t\t);\n\t\t\t\treturn new Date(utc);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Coerce the value to an object.\n\t * @param value The value to coerce.\n\t * @throws TypeError If the value can not be coerced.\n\t * @returns The value if it can be coerced.\n\t */\n\tpublic static object<T = unknown>(value: unknown): T | undefined {\n\t\tif (Is.undefined(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.object<T>(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.stringValue(value)) {\n\t\t\ttry {\n\t\t\t\treturn JSON.parse(value) as T;\n\t\t\t} catch {}\n\t\t}\n\t}\n\n\t/**\n\t * Coerce the value to a Uint8Array.\n\t * @param value The value to coerce.\n\t * @throws TypeError If the value can not be coerced.\n\t * @returns The value if it can be coerced.\n\t */\n\tpublic static uint8Array(value: unknown): Uint8Array | undefined {\n\t\tif (Is.undefined(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.string(value)) {\n\t\t\tif (Is.stringHex(value.toLowerCase(), true)) {\n\t\t\t\treturn Converter.hexToBytes(value.toLowerCase());\n\t\t\t}\n\t\t\tif (Is.stringBase64(value)) {\n\t\t\t\treturn Converter.base64ToBytes(value);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Coerces a value based on the coercion type.\n\t * @param value The value to coerce.\n\t * @param type The coercion type to perform.\n\t * @returns The coerced value.\n\t */\n\tpublic static byType(value: unknown, type?: CoerceType): unknown {\n\t\tswitch (type) {\n\t\t\tcase CoerceType.String:\n\t\t\t\treturn Coerce.string(value);\n\t\t\tcase CoerceType.Number:\n\t\t\t\treturn Coerce.number(value);\n\t\t\tcase CoerceType.Integer:\n\t\t\t\treturn Coerce.integer(value);\n\t\t\tcase CoerceType.BigInt:\n\t\t\t\treturn Coerce.bigint(value);\n\t\t\tcase CoerceType.Boolean:\n\t\t\t\treturn Coerce.boolean(value);\n\t\t\tcase CoerceType.Date:\n\t\t\t\treturn Coerce.date(value);\n\t\t\tcase CoerceType.DateTime:\n\t\t\t\treturn Coerce.dateTime(value);\n\t\t\tcase CoerceType.Time:\n\t\t\t\treturn Coerce.time(value);\n\t\t\tcase CoerceType.Object:\n\t\t\t\treturn Coerce.object(value);\n\t\t\tcase CoerceType.Uint8Array:\n\t\t\t\treturn Coerce.uint8Array(value);\n\t\t\tdefault:\n\t\t\t\treturn value;\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"coerce.js","sourceRoot":"","sources":["../../../src/utils/coerce.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD;;GAEG;AACH,MAAM,OAAO,MAAM;IAClB;;;;OAIG;IACI,MAAM,CAAC,MAAM,CAAC,KAAc;QAClC,IAAI,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;YACzB,OAAO,KAAK,CAAC;QACd,CAAC;QACD,IAAI,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;YACtB,OAAO,KAAK,CAAC;QACd,CAAC;QACD,IAAI,EAAE,CAAC,MAAM,CAAC,KAAK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AC;QACf,CAAC;IACF,CAAC;CACD","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Converter } from \"./converter.js\";\nimport { Is } from \"./is.js\";\nimport { CoerceType } from \"../models/coerceType.js\";\n\n/**\n * Coerce an object from one type to another.\n */\nexport class Coerce {\n\t/**\n\t * Coerce the value to a string.\n\t * @param value The value to coerce.\n\t * @returns The coerced string, or undefined if the value cannot be coerced.\n\t */\n\tpublic static string(value: unknown): string | undefined {\n\t\tif (Is.undefined(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.string(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.number(value)) {\n\t\t\treturn value.toString();\n\t\t}\n\t\tif (Is.boolean(value)) {\n\t\t\treturn value ? \"true\" : \"false\";\n\t\t}\n\t\tif (Is.date(value)) {\n\t\t\treturn value.toISOString();\n\t\t}\n\t}\n\n\t/**\n\t * Coerce the value to a number.\n\t * @param value The value to coerce.\n\t * @returns The coerced number, or undefined if the value cannot be coerced.\n\t */\n\tpublic static number(value: unknown): number | undefined {\n\t\tif (Is.undefined(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.number(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.string(value)) {\n\t\t\tconst parsed = Number.parseFloat(value);\n\t\t\tif (Is.number(parsed)) {\n\t\t\t\treturn parsed;\n\t\t\t}\n\t\t}\n\t\tif (Is.boolean(value)) {\n\t\t\treturn value ? 1 : 0;\n\t\t}\n\t\tif (Is.date(value)) {\n\t\t\treturn value.getTime();\n\t\t}\n\t}\n\n\t/**\n\t * Coerce the value to an integer.\n\t * @param value The value to coerce.\n\t * @returns The coerced integer, or undefined if the value cannot be coerced.\n\t */\n\tpublic static integer(value: unknown): number | undefined {\n\t\tconst num = Coerce.number(value);\n\t\tif (!Is.undefined(num)) {\n\t\t\treturn Math.trunc(num);\n\t\t}\n\t}\n\n\t/**\n\t * Coerce the value to a bigint.\n\t * @param value The value to coerce.\n\t * @returns The coerced bigint, or undefined if the value cannot be coerced.\n\t */\n\tpublic static bigint(value: unknown): bigint | undefined {\n\t\tif (Is.undefined(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.bigint(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.number(value)) {\n\t\t\treturn BigInt(value);\n\t\t}\n\t\tif (Is.string(value)) {\n\t\t\tconst parsed = Number.parseFloat(value);\n\t\t\tif (Is.integer(parsed)) {\n\t\t\t\treturn BigInt(parsed);\n\t\t\t}\n\t\t}\n\t\tif (Is.boolean(value)) {\n\t\t\treturn value ? 1n : 0n;\n\t\t}\n\t}\n\n\t/**\n\t * Coerce the value to a boolean.\n\t * @param value The value to coerce.\n\t * @returns The coerced boolean, or undefined if the value cannot be coerced.\n\t */\n\tpublic static boolean(value: unknown): boolean | undefined {\n\t\tif (Is.undefined(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.boolean(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.number(value)) {\n\t\t\t// eslint-disable-next-line no-unneeded-ternary\n\t\t\treturn value ? true : false;\n\t\t}\n\t\tif (Is.string(value)) {\n\t\t\tif (/true/i.test(value)) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif (/false/i.test(value)) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Coerce the value to a date.\n\t * @param value The value to coerce.\n\t * @returns The coerced date, or undefined if the value cannot be coerced.\n\t */\n\tpublic static date(value: unknown): Date | undefined {\n\t\tif (Is.undefined(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.date(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.number(value)) {\n\t\t\treturn new Date(value);\n\t\t}\n\t\tif (Is.string(value)) {\n\t\t\tconst dt = new Date(value);\n\t\t\tif (!Number.isNaN(dt.getTime())) {\n\t\t\t\tconst utc = Date.UTC(dt.getUTCFullYear(), dt.getUTCMonth(), dt.getUTCDate());\n\t\t\t\treturn new Date(utc);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Coerce the value to a date/time.\n\t * @param value The value to coerce.\n\t * @returns The coerced date/time, or undefined if the value cannot be coerced.\n\t */\n\tpublic static dateTime(value: unknown): Date | undefined {\n\t\tif (Is.undefined(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.date(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.number(value)) {\n\t\t\treturn new Date(value);\n\t\t}\n\t\tif (Is.string(value)) {\n\t\t\tconst dt = new Date(value);\n\t\t\tif (!Number.isNaN(dt.getTime())) {\n\t\t\t\tconst utc = Date.UTC(\n\t\t\t\t\tdt.getUTCFullYear(),\n\t\t\t\t\tdt.getUTCMonth(),\n\t\t\t\t\tdt.getUTCDate(),\n\t\t\t\t\tdt.getUTCHours(),\n\t\t\t\t\tdt.getUTCMinutes(),\n\t\t\t\t\tdt.getUTCSeconds(),\n\t\t\t\t\tdt.getUTCMilliseconds()\n\t\t\t\t);\n\t\t\t\treturn new Date(utc);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Coerce the value to a time.\n\t * @param value The value to coerce.\n\t * @returns The coerced time, or undefined if the value cannot be coerced.\n\t */\n\tpublic static time(value: unknown): Date | undefined {\n\t\tif (Is.undefined(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.date(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.number(value)) {\n\t\t\tconst dt = new Date(value);\n\t\t\tdt.setFullYear(1970, 0, 1);\n\t\t\treturn dt;\n\t\t}\n\t\tif (Is.string(value)) {\n\t\t\tconst dt = new Date(value);\n\t\t\tif (!Number.isNaN(dt.getTime())) {\n\t\t\t\tconst utc = Date.UTC(\n\t\t\t\t\t1970,\n\t\t\t\t\t0,\n\t\t\t\t\t1,\n\t\t\t\t\tdt.getUTCHours(),\n\t\t\t\t\tdt.getUTCMinutes(),\n\t\t\t\t\tdt.getUTCSeconds(),\n\t\t\t\t\tdt.getUTCMilliseconds()\n\t\t\t\t);\n\t\t\t\treturn new Date(utc);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Coerce the value to an object.\n\t * @param value The value to coerce.\n\t * @returns The coerced object, or undefined if the value cannot be coerced.\n\t */\n\tpublic static object<T = unknown>(value: unknown): T | undefined {\n\t\tif (Is.undefined(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.object<T>(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.stringValue(value)) {\n\t\t\ttry {\n\t\t\t\treturn JSON.parse(value) as T;\n\t\t\t} catch {}\n\t\t}\n\t}\n\n\t/**\n\t * Coerce the value to a Uint8Array.\n\t * @param value The value to coerce.\n\t * @returns The coerced Uint8Array, or undefined if the value cannot be coerced.\n\t */\n\tpublic static uint8Array(value: unknown): Uint8Array | undefined {\n\t\tif (Is.undefined(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.string(value)) {\n\t\t\tif (Is.stringHex(value.toLowerCase(), true)) {\n\t\t\t\treturn Converter.hexToBytes(value.toLowerCase());\n\t\t\t}\n\t\t\tif (Is.stringBase64(value)) {\n\t\t\t\treturn Converter.base64ToBytes(value);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Coerces a value based on the coercion type.\n\t * @param value The value to coerce.\n\t * @param type The coercion type to perform.\n\t * @returns The coerced value.\n\t */\n\tpublic static byType(value: unknown, type?: CoerceType): unknown {\n\t\tswitch (type) {\n\t\t\tcase CoerceType.String:\n\t\t\t\treturn Coerce.string(value);\n\t\t\tcase CoerceType.Number:\n\t\t\t\treturn Coerce.number(value);\n\t\t\tcase CoerceType.Integer:\n\t\t\t\treturn Coerce.integer(value);\n\t\t\tcase CoerceType.BigInt:\n\t\t\t\treturn Coerce.bigint(value);\n\t\t\tcase CoerceType.Boolean:\n\t\t\t\treturn Coerce.boolean(value);\n\t\t\tcase CoerceType.Date:\n\t\t\t\treturn Coerce.date(value);\n\t\t\tcase CoerceType.DateTime:\n\t\t\t\treturn Coerce.dateTime(value);\n\t\t\tcase CoerceType.Time:\n\t\t\t\treturn Coerce.time(value);\n\t\t\tcase CoerceType.Object:\n\t\t\t\treturn Coerce.object(value);\n\t\t\tcase CoerceType.Uint8Array:\n\t\t\t\treturn Coerce.uint8Array(value);\n\t\t\tdefault:\n\t\t\t\treturn value;\n\t\t}\n\t}\n}\n"]}
@@ -9,7 +9,7 @@ export class Compression {
9
9
  */
10
10
  static CLASS_NAME = "Compression";
11
11
  /**
12
- * Compress bytes using GZIP.
12
+ * Compress bytes using the specified compression type.
13
13
  * @param bytes The bytes to compress.
14
14
  * @param type The type of compression to use.
15
15
  * @returns The compressed bytes.
@@ -1 +1 @@
1
- {"version":3,"file":"compression.js","sourceRoot":"","sources":["../../../src/utils/compression.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAE/D;;GAEG;AACH,MAAM,OAAO,WAAW;IACvB;;OAEG;IACI,MAAM,CAAU,UAAU,iBAAiC;IAElE;;;;;OAKG;IACI,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAiB,EAAE,IAAqB;QACpE,MAAM,CAAC,UAAU,CAAC,WAAW,CAAC,UAAU,WAAiB,KAAK,CAAC,CAAC;QAChE,MAAM,CAAC,UAAU,CAAC,WAAW,CAAC,UAAU,UAAgB,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,CAAC;QAE9F,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC/C,MAAM,iBAAiB,GAAG,IAAI,iBAAiB,CAAC,IAAI,CAAC,CAAC;QACtD,MAAM,eAAe,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAC;QACrE,MAAM,cAAc,GAAG,MAAM,IAAI,QAAQ,CAAC,eAAe,CAAC,CAAC,IAAI,EAAE,CAAC;QAElE,MAAM,eAAe,GAAG,IAAI,UAAU,CAAC,MAAM,cAAc,CAAC,WAAW,EAAE,CAAC,CAAC;QAE3E,yDAAyD;QACzD,kEAAkE;QAClE,sCAAsC;QACtC,IAAI,IAAI,KAAK,eAAe,CAAC,IAAI,IAAI,eAAe,CAAC,MAAM,IAAI,EAAE,EAAE,CAAC;YACnE,eAAe,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QACxB,CAAC;QAED,OAAO,eAAe,CAAC;IACxB,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,KAAK,CAAC,UAAU,CAC7B,eAA2B,EAC3B,IAAqB;QAErB,MAAM,CAAC,UAAU,CAAC,WAAW,CAAC,UAAU,qBAA2B,eAAe,CAAC,CAAC;QACpF,MAAM,CAAC,UAAU,CAAC,WAAW,CAAC,UAAU,UAAgB,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,CAAC;QAE9F,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,CAAC,IAAI,UAAU,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;QACzD,MAAM,mBAAmB,GAAG,IAAI,mBAAmB,CAAC,IAAI,CAAC,CAAC;QAC1D,MAAM,iBAAiB,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,WAAW,CAAC,mBAAmB,CAAC,CAAC;QACzE,MAAM,gBAAgB,GAAG,MAAM,IAAI,QAAQ,CAAC,iBAAiB,CAAC,CAAC,IAAI,EAAE,CAAC;QAEtE,OAAO,IAAI,UAAU,CAAC,MAAM,gBAAgB,CAAC,KAAK,EAAE,CAAC,CAAC;IACvD,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { nameof } from \"@twin.org/nameof\";\nimport { Guards } from \"./guards.js\";\nimport { CompressionType } from \"../models/compressionType.js\";\n\n/**\n * A class to handle compression.\n */\nexport class Compression {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<Compression>();\n\n\t/**\n\t * Compress bytes using GZIP.\n\t * @param bytes The bytes to compress.\n\t * @param type The type of compression to use.\n\t * @returns The compressed bytes.\n\t */\n\tpublic static async compress(bytes: Uint8Array, type: CompressionType): Promise<Uint8Array> {\n\t\tGuards.uint8Array(Compression.CLASS_NAME, nameof(bytes), bytes);\n\t\tGuards.arrayOneOf(Compression.CLASS_NAME, nameof(type), type, Object.values(CompressionType));\n\n\t\tconst blob = new Blob([new Uint8Array(bytes)]);\n\t\tconst compressionStream = new CompressionStream(type);\n\t\tconst compressionPipe = blob.stream().pipeThrough(compressionStream);\n\t\tconst compressedBlob = await new Response(compressionPipe).blob();\n\n\t\tconst compressedBytes = new Uint8Array(await compressedBlob.arrayBuffer());\n\n\t\t// GZIP header contains a byte which specifies the OS the\n\t\t// compression was performed on. We set this to 3 (Unix) to ensure\n\t\t// that we produce consistent results.\n\t\tif (type === CompressionType.Gzip && compressedBytes.length >= 10) {\n\t\t\tcompressedBytes[9] = 3;\n\t\t}\n\n\t\treturn compressedBytes;\n\t}\n\n\t/**\n\t * Decompress a gzipped compressed byte array.\n\t * @param compressedBytes The compressed bytes.\n\t * @param type The type of compression to use.\n\t * @returns The decompressed bytes.\n\t */\n\tpublic static async decompress(\n\t\tcompressedBytes: Uint8Array,\n\t\ttype: CompressionType\n\t): Promise<Uint8Array> {\n\t\tGuards.uint8Array(Compression.CLASS_NAME, nameof(compressedBytes), compressedBytes);\n\t\tGuards.arrayOneOf(Compression.CLASS_NAME, nameof(type), type, Object.values(CompressionType));\n\n\t\tconst blob = new Blob([new Uint8Array(compressedBytes)]);\n\t\tconst decompressionStream = new DecompressionStream(type);\n\t\tconst decompressionPipe = blob.stream().pipeThrough(decompressionStream);\n\t\tconst decompressedBlob = await new Response(decompressionPipe).blob();\n\n\t\treturn new Uint8Array(await decompressedBl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AAC,UAAU,CAC7B,eAA2B,EAC3B,IAAqB;QAErB,MAAM,CAAC,UAAU,CAAC,WAAW,CAAC,UAAU,qBAA2B,eAAe,CAAC,CAAC;QACpF,MAAM,CAAC,UAAU,CAAC,WAAW,CAAC,UAAU,UAAgB,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,CAAC;QAE9F,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,CAAC,IAAI,UAAU,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;QACzD,MAAM,mBAAmB,GAAG,IAAI,mBAAmB,CAAC,IAAI,CAAC,CAAC;QAC1D,MAAM,iBAAiB,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,WAAW,CAAC,mBAAmB,CAAC,CAAC;QACzE,MAAM,gBAAgB,GAAG,MAAM,IAAI,QAAQ,CAAC,iBAAiB,CAAC,CAAC,IAAI,EAAE,CAAC;QAEtE,OAAO,IAAI,UAAU,CAAC,MAAM,gBAAgB,CAAC,KAAK,EAAE,CAAC,CAAC;IACvD,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { nameof } from \"@twin.org/nameof\";\nimport { Guards } from \"./guards.js\";\nimport { CompressionType } from \"../models/compressionType.js\";\n\n/**\n * A class to handle compression.\n */\nexport class Compression {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<Compression>();\n\n\t/**\n\t * Compress bytes using the specified compression type.\n\t * @param bytes The bytes to compress.\n\t * @param type The type of compression to use.\n\t * @returns The compressed bytes.\n\t */\n\tpublic static async compress(bytes: Uint8Array, type: CompressionType): Promise<Uint8Array> {\n\t\tGuards.uint8Array(Compression.CLASS_NAME, nameof(bytes), bytes);\n\t\tGuards.arrayOneOf(Compression.CLASS_NAME, nameof(type), type, Object.values(CompressionType));\n\n\t\tconst blob = new Blob([new Uint8Array(bytes)]);\n\t\tconst compressionStream = new CompressionStream(type);\n\t\tconst compressionPipe = blob.stream().pipeThrough(compressionStream);\n\t\tconst compressedBlob = await new Response(compressionPipe).blob();\n\n\t\tconst compressedBytes = new Uint8Array(await compressedBlob.arrayBuffer());\n\n\t\t// GZIP header contains a byte which specifies the OS the\n\t\t// compression was performed on. We set this to 3 (Unix) to ensure\n\t\t// that we produce consistent results.\n\t\tif (type === CompressionType.Gzip && compressedBytes.length >= 10) {\n\t\t\tcompressedBytes[9] = 3;\n\t\t}\n\n\t\treturn compressedBytes;\n\t}\n\n\t/**\n\t * Decompress a gzipped compressed byte array.\n\t * @param compressedBytes The compressed bytes.\n\t * @param type The type of compression to use.\n\t * @returns The decompressed bytes.\n\t */\n\tpublic static async decompress(\n\t\tcompressedBytes: Uint8Array,\n\t\ttype: CompressionType\n\t): Promise<Uint8Array> {\n\t\tGuards.uint8Array(Compression.CLASS_NAME, nameof(compressedBytes), compressedBytes);\n\t\tGuards.arrayOneOf(Compression.CLASS_NAME, nameof(type), type, Object.values(CompressionType));\n\n\t\tconst blob = new Blob([new Uint8Array(compressedBytes)]);\n\t\tconst decompressionStream = new DecompressionStream(type);\n\t\tconst decompressionPipe = blob.stream().pipeThrough(decompressionStream);\n\t\tconst decompressedBlob = await new Response(decompressionPipe).blob();\n\n\t\treturn new Uint8Array(await decompressedBlob.bytes());\n\t}\n}\n"]}
@@ -184,6 +184,42 @@ export class Guards {
184
184
  throw new GuardError(source, "guard.date", property, value);
185
185
  }
186
186
  }
187
+ /**
188
+ * Is the property a date-only string (ISO 8601 date, no time component).
189
+ * @param source The source of the error.
190
+ * @param property The name of the property.
191
+ * @param value The value to test.
192
+ * @throws GuardError If the value does not match the assertion.
193
+ */
194
+ static dateString(source, property, value) {
195
+ if (!Is.dateString(value)) {
196
+ throw new GuardError(source, "guard.dateString", property, value);
197
+ }
198
+ }
199
+ /**
200
+ * Is the property a date-time string (ISO 8601 with T separator).
201
+ * @param source The source of the error.
202
+ * @param property The name of the property.
203
+ * @param value The value to test.
204
+ * @throws GuardError If the value does not match the assertion.
205
+ */
206
+ static dateTimeString(source, property, value) {
207
+ if (!Is.dateTimeString(value)) {
208
+ throw new GuardError(source, "guard.dateTimeString", property, value);
209
+ }
210
+ }
211
+ /**
212
+ * Is the property a time-only string (ISO 8601 time, no date component).
213
+ * @param source The source of the error.
214
+ * @param property The name of the property.
215
+ * @param value The value to test.
216
+ * @throws GuardError If the value does not match the assertion.
217
+ */
218
+ static timeString(source, property, value) {
219
+ if (!Is.timeString(value)) {
220
+ throw new GuardError(source, "guard.timeString", property, value);
221
+ }
222
+ }
187
223
  /**
188
224
  * Is the property a timestamp in milliseconds.
189
225
  * @param source The source of the error.