@twin.org/core 0.0.3-next.3 → 0.0.3-next.30

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 (92) hide show
  1. package/README.md +1 -9
  2. package/dist/es/encoding/base32.js +1 -1
  3. package/dist/es/encoding/base32.js.map +1 -1
  4. package/dist/es/factories/factory.js +41 -0
  5. package/dist/es/factories/factory.js.map +1 -1
  6. package/dist/es/helpers/arrayHelper.js.map +1 -1
  7. package/dist/es/helpers/randomHelper.js +50 -2
  8. package/dist/es/helpers/randomHelper.js.map +1 -1
  9. package/dist/es/index.js +2 -1
  10. package/dist/es/index.js.map +1 -1
  11. package/dist/es/types/objectOrArray.js.map +1 -0
  12. package/dist/es/types/singleOccurrenceArray.js +2 -0
  13. package/dist/es/types/singleOccurrenceArray.js.map +1 -0
  14. package/dist/es/types/urn.js +1 -2
  15. package/dist/es/types/urn.js.map +1 -1
  16. package/dist/es/utils/asyncCache.js +92 -74
  17. package/dist/es/utils/asyncCache.js.map +1 -1
  18. package/dist/es/utils/guards.js +16 -0
  19. package/dist/es/utils/guards.js.map +1 -1
  20. package/dist/es/utils/is.js +16 -0
  21. package/dist/es/utils/is.js.map +1 -1
  22. package/dist/types/encoding/base32.d.ts +1 -1
  23. package/dist/types/factories/factory.d.ts +23 -1
  24. package/dist/types/helpers/arrayHelper.d.ts +1 -1
  25. package/dist/types/helpers/randomHelper.d.ts +16 -0
  26. package/dist/types/index.d.ts +2 -1
  27. package/dist/types/types/singleOccurrenceArray.d.ts +9 -0
  28. package/dist/types/utils/asyncCache.d.ts +7 -0
  29. package/dist/types/utils/guards.d.ts +10 -1
  30. package/dist/types/utils/is.d.ts +7 -0
  31. package/docs/changelog.md +524 -1
  32. package/docs/examples.md +308 -1
  33. package/docs/reference/classes/AlreadyExistsError.md +35 -35
  34. package/docs/reference/classes/ArrayHelper.md +2 -2
  35. package/docs/reference/classes/AsyncCache.md +8 -8
  36. package/docs/reference/classes/Base32.md +4 -4
  37. package/docs/reference/classes/Base58.md +3 -3
  38. package/docs/reference/classes/Base64.md +4 -4
  39. package/docs/reference/classes/Base64Url.md +3 -3
  40. package/docs/reference/classes/BaseError.md +34 -34
  41. package/docs/reference/classes/BitString.md +6 -6
  42. package/docs/reference/classes/Coerce.md +11 -11
  43. package/docs/reference/classes/Compression.md +3 -3
  44. package/docs/reference/classes/ConflictError.md +35 -35
  45. package/docs/reference/classes/Converter.md +18 -18
  46. package/docs/reference/classes/EnvHelper.md +1 -1
  47. package/docs/reference/classes/ErrorHelper.md +3 -3
  48. package/docs/reference/classes/Factory.md +112 -18
  49. package/docs/reference/classes/FilenameHelper.md +1 -1
  50. package/docs/reference/classes/GeneralError.md +35 -35
  51. package/docs/reference/classes/GuardError.md +35 -35
  52. package/docs/reference/classes/Guards.md +72 -30
  53. package/docs/reference/classes/HexHelper.md +6 -6
  54. package/docs/reference/classes/I18n.md +14 -14
  55. package/docs/reference/classes/Is.md +67 -39
  56. package/docs/reference/classes/JsonHelper.md +10 -10
  57. package/docs/reference/classes/NotFoundError.md +35 -35
  58. package/docs/reference/classes/NotImplementedError.md +35 -35
  59. package/docs/reference/classes/NotSupportedError.md +35 -35
  60. package/docs/reference/classes/NumberHelper.md +2 -2
  61. package/docs/reference/classes/ObjectHelper.md +32 -32
  62. package/docs/reference/classes/RandomHelper.md +53 -1
  63. package/docs/reference/classes/SharedStore.md +3 -3
  64. package/docs/reference/classes/StringHelper.md +23 -23
  65. package/docs/reference/classes/Uint8ArrayHelper.md +1 -1
  66. package/docs/reference/classes/UnauthorizedError.md +35 -35
  67. package/docs/reference/classes/UnprocessableError.md +35 -35
  68. package/docs/reference/classes/Url.md +8 -8
  69. package/docs/reference/classes/Urn.md +24 -24
  70. package/docs/reference/classes/Validation.md +25 -25
  71. package/docs/reference/classes/ValidationError.md +35 -35
  72. package/docs/reference/index.md +2 -0
  73. package/docs/reference/interfaces/IComponent.md +4 -4
  74. package/docs/reference/interfaces/IError.md +10 -10
  75. package/docs/reference/interfaces/II18nShared.md +4 -4
  76. package/docs/reference/interfaces/IKeyValue.md +2 -2
  77. package/docs/reference/interfaces/ILabelledValue.md +2 -2
  78. package/docs/reference/interfaces/ILocale.md +2 -2
  79. package/docs/reference/interfaces/ILocaleDictionary.md +1 -1
  80. package/docs/reference/interfaces/ILocalesIndex.md +1 -1
  81. package/docs/reference/interfaces/IPatchOperation.md +6 -6
  82. package/docs/reference/interfaces/IUrlParts.md +9 -9
  83. package/docs/reference/interfaces/IValidationFailure.md +4 -4
  84. package/docs/reference/type-aliases/SingleOccurrenceArray.md +15 -0
  85. package/docs/reference/type-aliases/SingleOccurrenceArrayDepthHelper.md +19 -0
  86. package/docs/reference/variables/CoerceType.md +10 -10
  87. package/docs/reference/variables/CompressionType.md +2 -2
  88. package/locales/en.json +5 -2
  89. package/package.json +4 -4
  90. package/dist/es/models/objectOrArray.js.map +0 -1
  91. /package/dist/es/{models → types}/objectOrArray.js +0 -0
  92. /package/dist/types/{models → types}/objectOrArray.d.ts +0 -0
@@ -1 +1 @@
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;;;;;;;OAOG;IACI,MAAM,CAAC,IAAI,CACjB,GAAW,EACX,KAAyB,EACzB,aAA+B,EAC/B,aAAuB;QAEvB,MAAM,YAAY,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;QACrD,IAAI,YAAY,EAAE,CAAC;YAClB,UAAU,CAAC,cAAc,EAAE,CAAC;YAE5B,MAAM,KAAK,GAAG,UAAU,CAAC,cAAc,EAAK,CAAC;YAE7C,uCAAuC;YACvC,IAAI,KA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AAE,CAAC;YAC5B,KAAK,MAAM,KAAK,IAAI,KAAK,EAAE,CAAC;gBAC3B,IAAI,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;oBAC9B,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC;gBACrB,CAAC;YACF,CAAC;QACF,CAAC;aAAM,CAAC;YACP,WAAW,CAAC,GAAG,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;QACnC,CAAC;IACF,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,cAAc;QAC3B,MAAM,KAAK,GAAG,UAAU,CAAC,cAAc,EAAE,CAAC;QAC1C,KAAK,MAAM,KAAK,IAAI,KAAK,EAAE,CAAC;YAC3B,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,OAAO,GAAG,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;gBACnE,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC;YACrB,CAAC;QACF,CAAC;IACF,CAAC;IAED;;;;OAIG;IACK,MAAM,CAAC,cAAc;QAY5B,IAAI,WAAW,GAAG,WAAW,CAAC,GAAG,CAW9B,YAAY,CAAC,CAAC;QAEjB,IAAI,EAAE,CAAC,SAAS,CAAC,WAAW,CAAC,EAAE,CAAC;YAC/B,WAAW,GAAG,EAAE,CAAC;YACjB,WAAW,CAAC,GAAG,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC;QAC5C,CAAC;QAED,OAAO,WAAW,CAAC;IACpB,CAAC;CACD","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 * 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 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> | undefined {\n\t\tconst cacheEnabled = Is.integer(ttlMs) && ttlMs >= 0;\n\t\tif (cacheEnabled) {\n\t\t\tAsyncCache.cleanupExpired();\n\n\t\t\tconst cache = AsyncCache.getSharedCache<T>();\n\n\t\t\t// Do we have a cache entry for the key\n\t\t\tif (cache[key]) {\n\t\t\t\tif (!Is.empty(cache[key].result)) {\n\t\t\t\t\t// If the cache has already resulted in a value, resolve it\n\t\t\t\t\treturn Promise.resolve(cache[key].result);\n\t\t\t\t} else if (!Is.empty(cache[key].error)) {\n\t\t\t\t\t// If the cache has already resulted in an error, reject it\n\t\t\t\t\treturn Promise.reject(cache[key].error);\n\t\t\t\t}\n\n\t\t\t\t// Otherwise create a promise to return and store the resolver\n\t\t\t\t// and rejector in the cache entry, so that we can call then\n\t\t\t\t// when the request is done\n\n\t\t\t\tlet storedResolve: ((value: T | PromiseLike<T>) => void) | undefined;\n\t\t\t\tlet storedReject: ((reason?: unknown) => void) | undefined;\n\t\t\t\tconst wait = new Promise<T>((resolve, reject) => {\n\t\t\t\t\tstoredResolve = resolve;\n\t\t\t\t\tstoredReject = reject;\n\t\t\t\t});\n\t\t\t\tif (!Is.empty(storedResolve) && !Is.empty(storedReject)) {\n\t\t\t\t\tcache[key].promiseQueue.push({\n\t\t\t\t\t\trequestMethod,\n\t\t\t\t\t\tresolve: storedResolve,\n\t\t\t\t\t\treject: storedReject\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\treturn wait;\n\t\t\t}\n\n\t\t\t// If we don't have a cache entry, create a new one\n\t\t\tcache[key] = {\n\t\t\t\tpromiseQueue: [],\n\t\t\t\texpires: ttlMs === 0 ? 0 : Date.now() + ttlMs\n\t\t\t};\n\n\t\t\t// Return a promise that wraps the original request method\n\t\t\t// so that we can store any results or errors in the cache\n\t\t\treturn new Promise((resolve, reject) => {\n\t\t\t\t// Call the request method and store the result\n\t\t\t\trequestMethod()\n\t\t\t\t\t// eslint-disable-next-line promise/prefer-await-to-then\n\t\t\t\t\t.then(res => {\n\t\t\t\t\t\t// If the request was successful, store the result\n\t\t\t\t\t\tcache[key].result = res;\n\n\t\t\t\t\t\t// and resolve both this promise and all the waiters\n\t\t\t\t\t\tresolve(res);\n\t\t\t\t\t\tfor (const wait of cache[key].promiseQueue) {\n\t\t\t\t\t\t\twait.resolve(res);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn res;\n\t\t\t\t\t})\n\t\t\t\t\t// eslint-disable-next-line promise/prefer-await-to-then\n\t\t\t\t\t.catch((err: Error) => {\n\t\t\t\t\t\t// Reject the promise\n\t\t\t\t\t\treject(err);\n\n\t\t\t\t\t\t// Handle the waiters based on the cacheFailures flag\n\t\t\t\t\t\tif (cacheFailures ?? false) {\n\t\t\t\t\t\t\t// If we are caching failures, store the error and reject the waiters\n\t\t\t\t\t\t\tcache[key].error = err;\n\t\t\t\t\t\t\tfor (const wait of cache[key].promiseQueue) {\n\t\t\t\t\t\t\t\twait.reject(err);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// Clear the waiters so we don't call them again\n\t\t\t\t\t\t\tcache[key].promiseQueue = [];\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t// If not caching failures for any queued requests we\n\t\t\t\t\t\t\t// have no value to either resolve or reject, so we\n\t\t\t\t\t\t\t// just resolve with the original request method\n\t\t\t\t\t\t\tfor (const wait of cache[key].promiseQueue) {\n\t\t\t\t\t\t\t\twait.resolve(wait.requestMethod());\n\t\t\t\t\t\t\t}\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});\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.\n\t */\n\tpublic static async get<T = unknown>(key: string): Promise<T | undefined> {\n\t\tconst cache = AsyncCache.getSharedCache<T>();\n\t\tif (!Is.empty(cache[key].result)) {\n\t\t\t// If the cache has already resulted in a value, resolve it\n\t\t\treturn cache[key].result;\n\t\t} else if (!Is.empty(cache[key].error)) {\n\t\t\t// If the cache has already resulted in an error, reject it\n\t\t\tthrow cache[key].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 ms, defaults to 1s.\n\t * @returns Nothing.\n\t */\n\tpublic static async set<T = unknown>(key: string, value: T, ttlMs?: number): Promise<void> {\n\t\tconst cache = AsyncCache.getSharedCache();\n\t\tcache[key] = {\n\t\t\tresult: value,\n\t\t\tpromiseQueue: [],\n\t\t\texpires: Date.now() + (ttlMs ?? 1000)\n\t\t};\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}\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\tfor (const entry in cache) {\n\t\t\t\tif (entry.startsWith(prefix)) {\n\t\t\t\t\tdelete cache[entry];\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tSharedStore.set(\"asyncCache\", {});\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 cache = AsyncCache.getSharedCache();\n\t\tfor (const entry in cache) {\n\t\t\tif (cache[entry].expires > 0 && cache[entry].expires < Date.now()) {\n\t\t\t\tdelete cache[entry];\n\t\t\t}\n\t\t}\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?: Error;\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?: Error;\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\");\n\n\t\tif (Is.undefined(sharedCache)) {\n\t\t\tsharedCache = {};\n\t\t\tSharedStore.set(\"asyncCache\", sharedCache);\n\t\t}\n\n\t\treturn sharedCache;\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;;;;;;;OAOG;IACI,MAAM,CAAC,IAAI,CACjB,GAAW,EACX,KAAyB,EACzB,aAA+B,EAC/B,aAAuB;QAEvB,MAAM,YAAY,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;QACrD,IAAI,CAAC,YAAY,EAAE,CAAC;YACnB,8CAA8C;YAC9C,OAAO,aAAa,EAAE,CAAC;QACxB,CAAC;QAED,UAA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,OAA4C,EAC5C,MAAkC;QAElC,IAAI,CAAC;YACJ,OAAO,CAAC,MAAM,aAAa,EAAE,CAAC,CAAC;QAChC,CAAC;QAAC,OAAO,OAAO,EAAE,CAAC;YAClB,MAAM,CAAC,OAAO,CAAC,CAAC;QACjB,CAAC;IACF,CAAC;CACD","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 * 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 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> | undefined {\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\n\t\tconst cache = AsyncCache.getSharedCache<T>();\n\n\t\t// Do we have a cache entry for the key\n\t\tif (cache[key]) {\n\t\t\tif (!Is.empty(cache[key].result)) {\n\t\t\t\t// If the cache has already resulted in a value, resolve it\n\t\t\t\treturn Promise.resolve(cache[key].result);\n\t\t\t} else if (!Is.empty(cache[key].error)) {\n\t\t\t\t// If the cache has already resulted in an error, reject it\n\t\t\t\treturn Promise.reject(cache[key].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\tcache[key].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\tcache[key] = {\n\t\t\tpromiseQueue: [],\n\t\t\texpires: ttlMs === 0 ? 0 : Date.now() + ttlMs\n\t\t};\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\tcache[key].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 cache[key].promiseQueue) {\n\t\t\t\t\t\twait.resolve(res);\n\t\t\t\t\t}\n\t\t\t\t\tcache[key].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\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\tcache[key].error = err;\n\t\t\t\t\t\tfor (const wait of cache[key].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\tcache[key].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 cache[key].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\tdelete cache[key];\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.\n\t */\n\tpublic static async get<T = unknown>(key: string): Promise<T | undefined> {\n\t\tconst cache = AsyncCache.getSharedCache<T>();\n\t\tif (!Is.empty(cache[key]?.result)) {\n\t\t\t// If the cache has already resulted in a value, resolve it\n\t\t\treturn cache[key].result;\n\t\t}\n\n\t\tif (!Is.empty(cache[key]?.error)) {\n\t\t\t// If the cache has already resulted in an error, reject it\n\t\t\tthrow cache[key].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 ms, defaults to 1s.\n\t * @returns Nothing.\n\t */\n\tpublic static async set<T = unknown>(key: string, value: T, ttlMs?: number): Promise<void> {\n\t\tconst cache = AsyncCache.getSharedCache();\n\t\tcache[key] = {\n\t\t\tresult: value,\n\t\t\tpromiseQueue: [],\n\t\t\texpires: Date.now() + (ttlMs ?? 1000)\n\t\t};\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}\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\tfor (const entry in cache) {\n\t\t\t\tif (entry.startsWith(prefix)) {\n\t\t\t\t\tdelete cache[entry];\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tSharedStore.set(\"asyncCache\", {});\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 cache = AsyncCache.getSharedCache();\n\t\tfor (const entry in cache) {\n\t\t\tif (cache[entry].expires > 0 && cache[entry].expires < Date.now()) {\n\t\t\t\tdelete cache[entry];\n\t\t\t}\n\t\t}\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\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\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\");\n\n\t\tif (Is.undefined(sharedCache)) {\n\t\t\tsharedCache = {};\n\t\t\tSharedStore.set(\"asyncCache\", 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"]}
@@ -365,5 +365,21 @@ export class Guards {
365
365
  throw new GuardError(source, "guard.email", property, value);
366
366
  }
367
367
  }
368
+ /**
369
+ * Is the property a string containing uuidV7.
370
+ * @param source The source of the error.
371
+ * @param property The name of the property.
372
+ * @param value The value to test.
373
+ * @param format The format of the uuidV7, either standard or compact.
374
+ * @throws GuardError If the value does not match the assertion.
375
+ */
376
+ static uuidV7(source, property, value, format) {
377
+ if (!Is.uuidV7(value, format)) {
378
+ if (format === "compact") {
379
+ throw new GuardError(source, "guard.uuidV7Compact", property, value);
380
+ }
381
+ throw new GuardError(source, "guard.uuidV7", property, value);
382
+ }
383
+ }
368
384
  }
369
385
  //# sourceMappingURL=guards.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"guards.js","sourceRoot":"","sources":["../../../src/utils/guards.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAGpD;;GAEG;AACH,MAAM,OAAO,MAAM;IAClB;;;;;;OAMG;IACI,MAAM,CAAC,OAAO,CAAC,MAAc,EAAE,QAAgB,EAAE,KAAc;QACrE,IAAI,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;YACzB,MAAM,IAAI,UAAU,CAAC,MAAM,EAAE,iBAAiB,EAAE,QAAQ,EAAE,KA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M,EAAE,gBAAgB,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;QACjE,CAAC;IACF,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,KAAK,CAAC,MAAc,EAAE,QAAgB,EAAE,KAAc;QACnE,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;YACtB,MAAM,IAAI,UAAU,CAAC,MAAM,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;QAC9D,CAAC;IACF,CAAC;CACD","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Is } from \"./is.js\";\nimport { GuardError } from \"../errors/guardError.js\";\nimport { ArrayHelper } from \"../helpers/arrayHelper.js\";\nimport { HexHelper } from \"../helpers/hexHelper.js\";\nimport type { ObjectOrArray } from \"../models/objectOrArray.js\";\n\n/**\n * Class to handle guard operations for parameters.\n */\nexport class Guards {\n\t/**\n\t * Is the property defined.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static defined(source: string, property: string, value: unknown): asserts value {\n\t\tif (Is.undefined(value)) {\n\t\t\tthrow new GuardError(source, \"guard.undefined\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a string.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static string(source: string, property: string, value: unknown): asserts value is string {\n\t\tif (!Is.string(value)) {\n\t\t\tthrow new GuardError(source, \"guard.string\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a string with a value.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static stringValue(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is string {\n\t\tif (!Is.string(value)) {\n\t\t\tthrow new GuardError(source, \"guard.string\", property, value);\n\t\t}\n\t\tif (value.length === 0) {\n\t\t\tthrow new GuardError(source, \"guard.stringEmpty\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a JSON value.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static json(source: string, property: string, value: unknown): asserts value is string {\n\t\tif (!Is.json(value)) {\n\t\t\tthrow new GuardError(source, \"guard.stringJson\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a base64 string.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static stringBase64(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is string {\n\t\tif (!Is.stringBase64(value)) {\n\t\t\tthrow new GuardError(source, \"guard.stringBase64\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a base64 url string.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static stringBase64Url(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is string {\n\t\tif (!Is.stringBase64Url(value)) {\n\t\t\tthrow new GuardError(source, \"guard.stringBase64Url\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a base58 string.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static stringBase58(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is string {\n\t\tif (!Is.stringBase58(value)) {\n\t\t\tthrow new GuardError(source, \"guard.stringBase58\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a string with a hex value.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @param allowPrefix Allow the hex to have the 0x prefix.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static stringHex(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown,\n\t\tallowPrefix: boolean = false\n\t): asserts value is string {\n\t\tGuards.stringValue(source, property, value);\n\t\tif (!HexHelper.isHex(value, allowPrefix)) {\n\t\t\tthrow new GuardError(source, \"guard.stringHex\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a string with a hex value with fixed length.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @param length The length of the string to match.\n\t * @param allowPrefix Allow the hex to have the 0x prefix.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static stringHexLength(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown,\n\t\tlength: number,\n\t\tallowPrefix: boolean = false\n\t): asserts value is string {\n\t\tGuards.stringHex(source, property, value, allowPrefix);\n\t\tif (HexHelper.stripPrefix(value).length !== length) {\n\t\t\tthrow new GuardError(\n\t\t\t\tsource,\n\t\t\t\t\"guard.stringHexLength\",\n\t\t\t\tproperty,\n\t\t\t\tvalue.length,\n\t\t\t\tlength.toString()\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a number.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static number(source: string, property: string, value: unknown): asserts value is number {\n\t\tif (!Is.number(value)) {\n\t\t\tthrow new GuardError(source, \"guard.number\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property an integer.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static integer(source: string, property: string, value: unknown): asserts value is number {\n\t\tif (!Is.integer(value)) {\n\t\t\tthrow new GuardError(source, \"guard.integer\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a bigint.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static bigint(source: string, property: string, value: unknown): asserts value is bigint {\n\t\tif (!Is.bigint(value)) {\n\t\t\tthrow new GuardError(source, \"guard.bigint\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a boolean.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static boolean(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is boolean {\n\t\tif (!Is.boolean(value)) {\n\t\t\tthrow new GuardError(source, \"guard.boolean\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a date.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static date(source: string, property: string, value: unknown): asserts value is Date {\n\t\tif (!Is.date(value)) {\n\t\t\tthrow new GuardError(source, \"guard.date\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a timestamp in milliseconds.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static timestampMilliseconds(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is number {\n\t\tif (!Is.timestampMilliseconds(value)) {\n\t\t\tthrow new GuardError(source, \"guard.timestampMilliseconds\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a timestamp in seconds.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static timestampSeconds(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is number {\n\t\tif (!Is.timestampSeconds(value)) {\n\t\t\tthrow new GuardError(source, \"guard.timestampSeconds\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property an object.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static object<T = { [id: string]: unknown }>(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is T {\n\t\tif (Is.undefined(value)) {\n\t\t\tthrow new GuardError(source, \"guard.objectUndefined\", property, value);\n\t\t}\n\t\tif (!Is.object<T>(value)) {\n\t\t\tthrow new GuardError(source, \"guard.object\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property is an object with at least one property.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static objectValue<T = { [id: string]: unknown }>(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is T {\n\t\tif (Is.undefined(value)) {\n\t\t\tthrow new GuardError(source, \"guard.objectUndefined\", property, value);\n\t\t}\n\t\tif (!Is.object<T>(value)) {\n\t\t\tthrow new GuardError(source, \"guard.object\", property, value);\n\t\t}\n\t\tif (Object.keys(value || {}).length === 0) {\n\t\t\tthrow new GuardError(source, \"guard.objectValue\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property is an array.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static array<T>(source: string, property: string, value: unknown): asserts value is T[] {\n\t\tif (!Is.array<T>(value)) {\n\t\t\tthrow new GuardError(source, \"guard.array\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property is an array with at least one item.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static arrayValue<T>(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is T[] {\n\t\tif (!Is.array(value)) {\n\t\t\tthrow new GuardError(source, \"guard.array\", property, value);\n\t\t}\n\t\tif (value.length === 0) {\n\t\t\tthrow new GuardError(source, \"guard.arrayValue\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property one of a list of items.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @param options The options the value must be one of.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static arrayOneOf<T>(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: T,\n\t\toptions: T[]\n\t): asserts value is T {\n\t\tif (!Is.array<T>(options)) {\n\t\t\tthrow new GuardError(source, \"guard.array\", property, value);\n\t\t}\n\t\tif (!options.includes(value)) {\n\t\t\tthrow new GuardError(source, \"guard.arrayOneOf\", property, value, options.join(\", \"));\n\t\t}\n\t}\n\n\t/**\n\t * Does the array start with the specified data.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @param startValues The values that must start the array.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static arrayStartsWith<T>(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown,\n\t\tstartValues: ObjectOrArray<T>\n\t): asserts value is T[] {\n\t\tif (!Is.arrayValue<T>(value)) {\n\t\t\tthrow new GuardError(source, \"guard.array\", property, value);\n\t\t}\n\n\t\tconst startValuesArray = ArrayHelper.fromObjectOrArray(startValues);\n\n\t\tif (!Is.arrayValue<T>(startValuesArray)) {\n\t\t\tthrow new GuardError(source, \"guard.array\", property, startValuesArray);\n\t\t}\n\n\t\tfor (let i = 0; i < startValuesArray.length; i++) {\n\t\t\tif (value[i] !== startValuesArray[i]) {\n\t\t\t\tthrow new GuardError(\n\t\t\t\t\tsource,\n\t\t\t\t\t\"guard.arrayStartsWith\",\n\t\t\t\t\tproperty,\n\t\t\t\t\tvalue,\n\t\t\t\t\tstartValuesArray.join(\", \")\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Does the array end with the specified data.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @param endValues The values that must end the array.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static arrayEndsWith<T>(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown,\n\t\tendValues: ObjectOrArray<T>\n\t): asserts value is T[] {\n\t\tif (!Is.arrayValue<T>(value)) {\n\t\t\tthrow new GuardError(source, \"guard.array\", property, value);\n\t\t}\n\n\t\tconst endValuesArray = ArrayHelper.fromObjectOrArray(endValues);\n\n\t\tif (!Is.arrayValue<T>(endValuesArray)) {\n\t\t\tthrow new GuardError(source, \"guard.array\", property, endValuesArray);\n\t\t}\n\n\t\tfor (let i = 0; i < endValuesArray.length; i++) {\n\t\t\tif (value[value.length - i - 1] !== endValuesArray[endValuesArray.length - i - 1]) {\n\t\t\t\tthrow new GuardError(\n\t\t\t\t\tsource,\n\t\t\t\t\t\"guard.arrayEndsWith\",\n\t\t\t\t\tproperty,\n\t\t\t\t\tvalue,\n\t\t\t\t\tendValuesArray.join(\", \")\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a Uint8Array.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static uint8Array(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is Uint8Array {\n\t\tif (!Is.uint8Array(value)) {\n\t\t\tthrow new GuardError(source, \"guard.uint8Array\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a function.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tpublic static function<T extends (...args: any[]) => any = (...args: any[]) => any>(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is T {\n\t\tif (!Is.function<T>(value)) {\n\t\t\tthrow new GuardError(source, \"guard.function\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a string formatted as an email address.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static email(source: string, property: string, value: unknown): asserts value is string {\n\t\tif (!Is.email(value)) {\n\t\t\tthrow new GuardError(source, \"guard.email\", property, value);\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"guards.js","sourceRoot":"","sources":["../../../src/utils/guards.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAGpD;;GAEG;AACH,MAAM,OAAO,MAAM;IAClB;;;;;;OAMG;IACI,MAAM,CAAC,OAAO,CAAC,MAAc,EAAE,QAAgB,EAAE,KAAc;QACrE,IAAI,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;YACzB,MAAM,IAAI,UAAU,CAAC,MAAM,EAAE,iBAAiB,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;QAClE,CAAC;IACF,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,MAAM,CAAC,MAAc,EAAE,QAAgB,EAAE,KAAc;QACpE,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;YACvB,MAAM,IAAI,UAAU,CAAC,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;QAC/D,CAAC;IACF,CAAC;IAED;;;;;;OAMG;IACI,M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AAC;IACF,CAAC;IAED;;;;;;;OAOG;IACI,MAAM,CAAC,MAAM,CACnB,MAAc,EACd,QAAgB,EAChB,KAAc,EACd,MAA+B;QAE/B,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,CAAC;YAC/B,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;gBAC1B,MAAM,IAAI,UAAU,CAAC,MAAM,EAAE,qBAAqB,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;YACtE,CAAC;YACD,MAAM,IAAI,UAAU,CAAC,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;QAC/D,CAAC;IACF,CAAC;CACD","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Is } from \"./is.js\";\nimport { GuardError } from \"../errors/guardError.js\";\nimport { ArrayHelper } from \"../helpers/arrayHelper.js\";\nimport { HexHelper } from \"../helpers/hexHelper.js\";\nimport type { ObjectOrArray } from \"../types/objectOrArray.js\";\n\n/**\n * Class to handle guard operations for parameters.\n */\nexport class Guards {\n\t/**\n\t * Is the property defined.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static defined(source: string, property: string, value: unknown): asserts value {\n\t\tif (Is.undefined(value)) {\n\t\t\tthrow new GuardError(source, \"guard.undefined\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a string.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static string(source: string, property: string, value: unknown): asserts value is string {\n\t\tif (!Is.string(value)) {\n\t\t\tthrow new GuardError(source, \"guard.string\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a string with a value.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static stringValue(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is string {\n\t\tif (!Is.string(value)) {\n\t\t\tthrow new GuardError(source, \"guard.string\", property, value);\n\t\t}\n\t\tif (value.length === 0) {\n\t\t\tthrow new GuardError(source, \"guard.stringEmpty\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a JSON value.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static json(source: string, property: string, value: unknown): asserts value is string {\n\t\tif (!Is.json(value)) {\n\t\t\tthrow new GuardError(source, \"guard.stringJson\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a base64 string.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static stringBase64(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is string {\n\t\tif (!Is.stringBase64(value)) {\n\t\t\tthrow new GuardError(source, \"guard.stringBase64\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a base64 url string.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static stringBase64Url(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is string {\n\t\tif (!Is.stringBase64Url(value)) {\n\t\t\tthrow new GuardError(source, \"guard.stringBase64Url\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a base58 string.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static stringBase58(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is string {\n\t\tif (!Is.stringBase58(value)) {\n\t\t\tthrow new GuardError(source, \"guard.stringBase58\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a string with a hex value.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @param allowPrefix Allow the hex to have the 0x prefix.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static stringHex(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown,\n\t\tallowPrefix: boolean = false\n\t): asserts value is string {\n\t\tGuards.stringValue(source, property, value);\n\t\tif (!HexHelper.isHex(value, allowPrefix)) {\n\t\t\tthrow new GuardError(source, \"guard.stringHex\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a string with a hex value with fixed length.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @param length The length of the string to match.\n\t * @param allowPrefix Allow the hex to have the 0x prefix.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static stringHexLength(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown,\n\t\tlength: number,\n\t\tallowPrefix: boolean = false\n\t): asserts value is string {\n\t\tGuards.stringHex(source, property, value, allowPrefix);\n\t\tif (HexHelper.stripPrefix(value).length !== length) {\n\t\t\tthrow new GuardError(\n\t\t\t\tsource,\n\t\t\t\t\"guard.stringHexLength\",\n\t\t\t\tproperty,\n\t\t\t\tvalue.length,\n\t\t\t\tlength.toString()\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a number.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static number(source: string, property: string, value: unknown): asserts value is number {\n\t\tif (!Is.number(value)) {\n\t\t\tthrow new GuardError(source, \"guard.number\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property an integer.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static integer(source: string, property: string, value: unknown): asserts value is number {\n\t\tif (!Is.integer(value)) {\n\t\t\tthrow new GuardError(source, \"guard.integer\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a bigint.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static bigint(source: string, property: string, value: unknown): asserts value is bigint {\n\t\tif (!Is.bigint(value)) {\n\t\t\tthrow new GuardError(source, \"guard.bigint\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a boolean.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static boolean(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is boolean {\n\t\tif (!Is.boolean(value)) {\n\t\t\tthrow new GuardError(source, \"guard.boolean\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a date.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static date(source: string, property: string, value: unknown): asserts value is Date {\n\t\tif (!Is.date(value)) {\n\t\t\tthrow new GuardError(source, \"guard.date\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a timestamp in milliseconds.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static timestampMilliseconds(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is number {\n\t\tif (!Is.timestampMilliseconds(value)) {\n\t\t\tthrow new GuardError(source, \"guard.timestampMilliseconds\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a timestamp in seconds.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static timestampSeconds(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is number {\n\t\tif (!Is.timestampSeconds(value)) {\n\t\t\tthrow new GuardError(source, \"guard.timestampSeconds\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property an object.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static object<T = { [id: string]: unknown }>(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is T {\n\t\tif (Is.undefined(value)) {\n\t\t\tthrow new GuardError(source, \"guard.objectUndefined\", property, value);\n\t\t}\n\t\tif (!Is.object<T>(value)) {\n\t\t\tthrow new GuardError(source, \"guard.object\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property is an object with at least one property.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static objectValue<T = { [id: string]: unknown }>(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is T {\n\t\tif (Is.undefined(value)) {\n\t\t\tthrow new GuardError(source, \"guard.objectUndefined\", property, value);\n\t\t}\n\t\tif (!Is.object<T>(value)) {\n\t\t\tthrow new GuardError(source, \"guard.object\", property, value);\n\t\t}\n\t\tif (Object.keys(value || {}).length === 0) {\n\t\t\tthrow new GuardError(source, \"guard.objectValue\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property is an array.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static array<T>(source: string, property: string, value: unknown): asserts value is T[] {\n\t\tif (!Is.array<T>(value)) {\n\t\t\tthrow new GuardError(source, \"guard.array\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property is an array with at least one item.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static arrayValue<T>(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is T[] {\n\t\tif (!Is.array(value)) {\n\t\t\tthrow new GuardError(source, \"guard.array\", property, value);\n\t\t}\n\t\tif (value.length === 0) {\n\t\t\tthrow new GuardError(source, \"guard.arrayValue\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property one of a list of items.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @param options The options the value must be one of.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static arrayOneOf<T>(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: T,\n\t\toptions: T[]\n\t): asserts value is T {\n\t\tif (!Is.array<T>(options)) {\n\t\t\tthrow new GuardError(source, \"guard.array\", property, value);\n\t\t}\n\t\tif (!options.includes(value)) {\n\t\t\tthrow new GuardError(source, \"guard.arrayOneOf\", property, value, options.join(\", \"));\n\t\t}\n\t}\n\n\t/**\n\t * Does the array start with the specified data.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @param startValues The values that must start the array.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static arrayStartsWith<T>(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown,\n\t\tstartValues: ObjectOrArray<T>\n\t): asserts value is T[] {\n\t\tif (!Is.arrayValue<T>(value)) {\n\t\t\tthrow new GuardError(source, \"guard.array\", property, value);\n\t\t}\n\n\t\tconst startValuesArray = ArrayHelper.fromObjectOrArray(startValues);\n\n\t\tif (!Is.arrayValue<T>(startValuesArray)) {\n\t\t\tthrow new GuardError(source, \"guard.array\", property, startValuesArray);\n\t\t}\n\n\t\tfor (let i = 0; i < startValuesArray.length; i++) {\n\t\t\tif (value[i] !== startValuesArray[i]) {\n\t\t\t\tthrow new GuardError(\n\t\t\t\t\tsource,\n\t\t\t\t\t\"guard.arrayStartsWith\",\n\t\t\t\t\tproperty,\n\t\t\t\t\tvalue,\n\t\t\t\t\tstartValuesArray.join(\", \")\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Does the array end with the specified data.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @param endValues The values that must end the array.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static arrayEndsWith<T>(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown,\n\t\tendValues: ObjectOrArray<T>\n\t): asserts value is T[] {\n\t\tif (!Is.arrayValue<T>(value)) {\n\t\t\tthrow new GuardError(source, \"guard.array\", property, value);\n\t\t}\n\n\t\tconst endValuesArray = ArrayHelper.fromObjectOrArray(endValues);\n\n\t\tif (!Is.arrayValue<T>(endValuesArray)) {\n\t\t\tthrow new GuardError(source, \"guard.array\", property, endValuesArray);\n\t\t}\n\n\t\tfor (let i = 0; i < endValuesArray.length; i++) {\n\t\t\tif (value[value.length - i - 1] !== endValuesArray[endValuesArray.length - i - 1]) {\n\t\t\t\tthrow new GuardError(\n\t\t\t\t\tsource,\n\t\t\t\t\t\"guard.arrayEndsWith\",\n\t\t\t\t\tproperty,\n\t\t\t\t\tvalue,\n\t\t\t\t\tendValuesArray.join(\", \")\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a Uint8Array.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static uint8Array(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is Uint8Array {\n\t\tif (!Is.uint8Array(value)) {\n\t\t\tthrow new GuardError(source, \"guard.uint8Array\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a function.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tpublic static function<T extends (...args: any[]) => any = (...args: any[]) => any>(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is T {\n\t\tif (!Is.function<T>(value)) {\n\t\t\tthrow new GuardError(source, \"guard.function\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a string formatted as an email address.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static email(source: string, property: string, value: unknown): asserts value is string {\n\t\tif (!Is.email(value)) {\n\t\t\tthrow new GuardError(source, \"guard.email\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a string containing uuidV7.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @param format The format of the uuidV7, either standard or compact.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static uuidV7(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown,\n\t\tformat?: \"standard\" | \"compact\"\n\t): asserts value is string {\n\t\tif (!Is.uuidV7(value, format)) {\n\t\t\tif (format === \"compact\") {\n\t\t\t\tthrow new GuardError(source, \"guard.uuidV7Compact\", property, value);\n\t\t\t}\n\t\t\tthrow new GuardError(source, \"guard.uuidV7\", property, value);\n\t\t}\n\t}\n}\n"]}
@@ -347,5 +347,21 @@ export class Is {
347
347
  const str = Function.prototype.toString.call(obj);
348
348
  return /^class\s/.test(str);
349
349
  }
350
+ /**
351
+ * Is the value a uuidV7 string.
352
+ * @param value The value to test.
353
+ * @param format The format of the UUIDv7 string.
354
+ * @returns True if the value is a uuidV7 string.
355
+ */
356
+ static uuidV7(value, format) {
357
+ if (format === "compact") {
358
+ // 32 hex chars, where:
359
+ // - char 13 (0-based index 12) is the version (7)
360
+ // - char 17 (0-based index 16) is the variant (8, 9, a, b)
361
+ return Is.stringValue(value) && /^[\da-f]{12}7[\da-f]{3}[89ab][\da-f]{15}$/i.test(value);
362
+ }
363
+ return (Is.stringValue(value) &&
364
+ /^[\da-f]{8}-[\da-f]{4}-7[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i.test(value));
365
+ }
350
366
  }
351
367
  //# sourceMappingURL=is.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"is.js","sourceRoot":"","sources":["../../../src/utils/is.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD;;GAEG;AACH,MAAM,OAAO,EAAE;IACd;;;;OAIG;IACI,MAAM,CAAC,SAAS,CAAC,KAAc;QACrC,OAAO,KAAK,KAAK,SAAS,CAAC;IAC5B,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,IAAI,CAAC,KAAc;QAChC,OAAO,KAAK,KAAK,IAAI,CAAC;IACvB,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,KAAK,CAAC,KAAc;QACjC,OAAO,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,CAAC;IAC9C,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,QAAQ,CAAC,KAAc;QACpC,OAAO,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,CAAC;IAC9C,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,MAAM,CAAC,KAAc;QAClC,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC;IAClC,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,WAAW,CAAC,KAAc;QACvC,OAAO,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC;IACpD,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,IAAI,CAAC,KAAc;QAChC,IAAI,CAAC,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,EAA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AgD;QAChD,OAAO,KAAK,YAAY,UAAU,CAAC;IACpC,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,UAAU,CACvB,KAAc;QAUd,4DAA4D;QAC5D,gDAAgD;QAChD,OAAO,KAAK,YAAY,MAAM,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;IAC3D,CAAC;IAED;;;;OAIG;IACH,8DAA8D;IACvD,MAAM,CAAC,QAAQ,CACrB,KAAc;QAEd,OAAO,OAAO,KAAK,KAAK,UAAU,CAAC;IACpC,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,KAAK,CAAC,KAAc;QACjC,OAAO,CACN,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC;YACrB,wHAAwH,CAAC,IAAI,CAC5H,KAAK,CACL,CACD,CAAC;IACH,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,OAAO,CAAc,KAAc;QAChD,yDAAyD;QACzD,gDAAgD;QAChD,OAAO,KAAK,YAAY,OAAO,CAAC;IACjC,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,MAAM,CAAC,KAAc;QAClC,wDAAwD;QACxD,gDAAgD;QAChD,OAAO,KAAK,YAAY,MAAM,CAAC;IAChC,CAAC;IAED;;;;OAIG;IACH,8DAA8D;IACvD,MAAM,CAAC,KAAK,CAAc,GAAY;QAC5C,IAAI,OAAO,GAAG,KAAK,UAAU,EAAE,CAAC;YAC/B,OAAO,KAAK,CAAC;QACd,CAAC;QACD,MAAM,GAAG,GAAG,QAAQ,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAClD,OAAO,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;CACD","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { HexHelper } from \"../helpers/hexHelper.js\";\n\n/**\n * Class to check types of objects.\n */\nexport class Is {\n\t/**\n\t * Is the property undefined.\n\t * @param value The value to test.\n\t * @returns True if the value is a empty.\n\t */\n\tpublic static undefined(value: unknown): value is undefined {\n\t\treturn value === undefined;\n\t}\n\n\t/**\n\t * Is the property null.\n\t * @param value The value to test.\n\t * @returns True if the value is a empty.\n\t */\n\tpublic static null(value: unknown): value is null {\n\t\treturn value === null;\n\t}\n\n\t/**\n\t * Is the property null or undefined.\n\t * @param value The value to test.\n\t * @returns True if the value is a empty.\n\t */\n\tpublic static empty(value: unknown): value is undefined | null {\n\t\treturn value === null || value === undefined;\n\t}\n\n\t/**\n\t * Is the property is not null or undefined.\n\t * @param value The value to test.\n\t * @returns True if the value is a not empty.\n\t */\n\tpublic static notEmpty(value: unknown): boolean {\n\t\treturn value !== null && value !== undefined;\n\t}\n\n\t/**\n\t * Is the value a string.\n\t * @param value The value to test.\n\t * @returns True if the value is a string.\n\t */\n\tpublic static string(value: unknown): value is string {\n\t\treturn typeof value === \"string\";\n\t}\n\n\t/**\n\t * Is the value a string.\n\t * @param value The value to test.\n\t * @returns True if the value is a string.\n\t */\n\tpublic static stringValue(value: unknown): value is string {\n\t\treturn Is.string(value) && value.trim().length > 0;\n\t}\n\n\t/**\n\t * Is the value a JSON string.\n\t * @param value The value to test.\n\t * @returns True if the value is a JSON string.\n\t */\n\tpublic static json(value: unknown): value is string {\n\t\tif (!Is.stringValue(value)) {\n\t\t\treturn false;\n\t\t}\n\n\t\ttry {\n\t\t\tconst json = JSON.parse(value);\n\t\t\treturn (\n\t\t\t\tIs.object(json) ||\n\t\t\t\tIs.array(json) ||\n\t\t\t\tIs.string(json) ||\n\t\t\t\tIs.number(json) ||\n\t\t\t\tIs.boolean(json) ||\n\t\t\t\tIs.null(json)\n\t\t\t);\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t/**\n\t * Is the value a base64 string.\n\t * @param value The value to test.\n\t * @returns True if the value is a base64 string.\n\t */\n\tpublic static stringBase64(value: unknown): value is string {\n\t\treturn (\n\t\t\tIs.stringValue(value) &&\n\t\t\t// eslint-disable-next-line unicorn/better-regex\n\t\t\t/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(value)\n\t\t);\n\t}\n\n\t/**\n\t * Is the value a base64 url string.\n\t * @param value The value to test.\n\t * @returns True if the value is a base64 string.\n\t */\n\tpublic static stringBase64Url(value: unknown): value is string {\n\t\treturn (\n\t\t\tIs.stringValue(value) &&\n\t\t\t// eslint-disable-next-line unicorn/better-regex\n\t\t\t/^([A-Za-z0-9-_])*$/.test(value)\n\t\t);\n\t}\n\n\t/**\n\t * Is the value a base58 string.\n\t * @param value The value to test.\n\t * @returns True if the value is a base58 string.\n\t */\n\tpublic static stringBase58(value: unknown): value is string {\n\t\treturn (\n\t\t\tIs.stringValue(value) &&\n\t\t\t// eslint-disable-next-line unicorn/better-regex\n\t\t\t/^[A-HJ-NP-Za-km-z1-9]*$/.test(value)\n\t\t);\n\t}\n\n\t/**\n\t * Is the value a hex string.\n\t * @param value The value to test.\n\t * @param allowPrefix Allow the hex to have the 0x prefix.\n\t * @returns True if the value is a hex string.\n\t */\n\tpublic static stringHex(value: unknown, allowPrefix: boolean = false): value is string {\n\t\treturn Is.string(value) && HexHelper.isHex(value, allowPrefix);\n\t}\n\n\t/**\n\t * Is the value a hex string of fixed length.\n\t * @param value The value to test.\n\t * @param length The length to test.\n\t * @param allowPrefix Allow the hex to have the 0x prefix.\n\t * @returns True if the value is a hex string of required length.\n\t */\n\tpublic static stringHexLength(\n\t\tvalue: unknown,\n\t\tlength: number,\n\t\tallowPrefix: boolean = false\n\t): value is string {\n\t\treturn Is.stringHex(value, allowPrefix) && value.length === length;\n\t}\n\n\t/**\n\t * Is the value a number.\n\t * @param value The value to test.\n\t * @returns True if the value is a number.\n\t */\n\tpublic static number(value: unknown): value is number {\n\t\treturn typeof value === \"number\" && Number.isFinite(value) && !Number.isNaN(value);\n\t}\n\n\t/**\n\t * Is the value an integer.\n\t * @param value The value to test.\n\t * @returns True if the value is an integer.\n\t */\n\tpublic static integer(value: unknown): value is number {\n\t\treturn Is.number(value) && Number.isInteger(value);\n\t}\n\n\t/**\n\t * Is the value a big integer.\n\t * @param value The value to test.\n\t * @returns True if the value is a big integer.\n\t */\n\tpublic static bigint(value: unknown): value is bigint {\n\t\treturn typeof value === \"bigint\";\n\t}\n\n\t/**\n\t * Is the value a boolean.\n\t * @param value The value to test.\n\t * @returns True if the value is a boolean.\n\t */\n\tpublic static boolean(value: unknown): value is boolean {\n\t\treturn typeof value === \"boolean\";\n\t}\n\n\t/**\n\t * Is the value a date.\n\t * @param value The value to test.\n\t * @returns True if the value is a date.\n\t */\n\tpublic static date(value: unknown): value is Date {\n\t\treturn (\n\t\t\tObject.prototype.toString.call(value) === \"[object Date]\" &&\n\t\t\t!Number.isNaN((value as Date).getTime())\n\t\t);\n\t}\n\n\t/**\n\t * Is the value an empty date.\n\t * @param value The value to test.\n\t * @returns True if the value is an empty date.\n\t */\n\tpublic static dateEmpty(value: unknown): boolean {\n\t\treturn (\n\t\t\tObject.prototype.toString.call(value) === \"[object Date]\" &&\n\t\t\tNumber.isNaN((value as Date).getTime())\n\t\t);\n\t}\n\n\t/**\n\t * Is the value a date string.\n\t * @param value The value to test.\n\t * @returns True if the value is a string in ISO 8601 date format.\n\t */\n\tpublic static dateString(value: unknown): boolean {\n\t\tif (typeof value !== \"string\" || value.length === 0 || value.includes(\"T\")) {\n\t\t\treturn false;\n\t\t}\n\t\treturn !Number.isNaN(Date.parse(value));\n\t}\n\n\t/**\n\t * Is the value a date string.\n\t * @param value The value to test.\n\t * @returns True if the value is a string in ISO 8601 date/time format.\n\t */\n\tpublic static dateTimeString(value: unknown): boolean {\n\t\tif (typeof value !== \"string\" || value.length === 0 || !value.includes(\"T\")) {\n\t\t\treturn false;\n\t\t}\n\t\treturn !Number.isNaN(Date.parse(value));\n\t}\n\n\t/**\n\t * Is the value a time string.\n\t * @param value The value to test.\n\t * @returns True if the value is a string in ISO 8601 time format.\n\t */\n\tpublic static timeString(value: unknown): boolean {\n\t\tif (typeof value !== \"string\" || value.length === 0 || value.includes(\"T\")) {\n\t\t\treturn false;\n\t\t}\n\t\treturn !Number.isNaN(Date.parse(`1970-01-01T${value}`));\n\t}\n\n\t/**\n\t * Is the value a timestamp in seconds.\n\t * @param value The value to test.\n\t * @returns True if the value is a date.\n\t */\n\tpublic static timestampSeconds(value: unknown): value is number {\n\t\tif (!Is.integer(value)) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn value.toString().length < 12;\n\t}\n\n\t/**\n\t * Is the value a timestamp in milliseconds.\n\t * @param value The value to test.\n\t * @returns True if the value is a date.\n\t */\n\tpublic static timestampMilliseconds(value: unknown): value is number {\n\t\tif (!Is.integer(value)) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn value.toString().length >= 12;\n\t}\n\n\t/**\n\t * Is the value an object.\n\t * @param value The value to test.\n\t * @returns True if the value is a object.\n\t */\n\tpublic static object<T = { [id: string]: unknown }>(value: unknown): value is T {\n\t\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n\t}\n\n\t/**\n\t * Is the value an object with at least one property.\n\t * @param value The value to test.\n\t * @returns True if the value is a object.\n\t */\n\tpublic static objectValue<T = { [id: string]: unknown }>(value: unknown): value is T {\n\t\treturn (\n\t\t\ttypeof value === \"object\" &&\n\t\t\tvalue !== null &&\n\t\t\t!Array.isArray(value) &&\n\t\t\tObject.keys(value).length > 0\n\t\t);\n\t}\n\n\t/**\n\t * Is the value an array.\n\t * @param value The value to test.\n\t * @returns True if the value is an array.\n\t */\n\tpublic static array<T>(value: unknown): value is T[] {\n\t\treturn Array.isArray(value);\n\t}\n\n\t/**\n\t * Is the value an array with at least one element.\n\t * @param value The value to test.\n\t * @returns True if the value is an array with at least one element.\n\t */\n\tpublic static arrayValue<T>(value: unknown): value is T[] {\n\t\treturn Array.isArray(value) && value.length > 0;\n\t}\n\n\t/**\n\t * Is the value an array with at least one element.\n\t * @param value The value to test.\n\t * @param options The options the value must be one of.\n\t * @returns True if the value is an element from the options array.\n\t */\n\tpublic static arrayOneOf<T>(value: T, options: T[]): value is T {\n\t\tif (Is.empty(value) || !Is.array<T>(options) || !options.includes(value)) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn true;\n\t}\n\n\t/**\n\t * Is the value a Uint8Array.\n\t * @param value The value to test.\n\t * @returns True if the value is a Uint8Array.\n\t */\n\tpublic static uint8Array(value: unknown): value is Uint8Array {\n\t\t// This is the only way we can reliably check for Uint8Array\n\t\t// eslint-disable-next-line no-restricted-syntax\n\t\treturn value instanceof Uint8Array;\n\t}\n\n\t/**\n\t * Is the value a TypedArray.\n\t * @param value The value to test.\n\t * @returns True if the value is a TypedArray.\n\t */\n\tpublic static typedArray(\n\t\tvalue: unknown\n\t): value is\n\t\t| Uint8Array\n\t\t| Int8Array\n\t\t| Uint16Array\n\t\t| Int16Array\n\t\t| Uint32Array\n\t\t| Int32Array\n\t\t| Float32Array\n\t\t| Float64Array {\n\t\t// This is the only way we can reliably check for TypedArray\n\t\t// eslint-disable-next-line no-restricted-syntax\n\t\treturn value instanceof Object.getPrototypeOf(Uint8Array);\n\t}\n\n\t/**\n\t * Is the property a function.\n\t * @param value The value to test.\n\t * @returns True if the value is a function.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tpublic static function<T extends (...args: any[]) => any = (...args: any[]) => any>(\n\t\tvalue: unknown\n\t): value is T {\n\t\treturn typeof value === \"function\";\n\t}\n\n\t/**\n\t * Is the value a string formatted as an email address.\n\t * @param value The value to test.\n\t * @returns True if the value is a string.\n\t */\n\tpublic static email(value: unknown): value is string {\n\t\treturn (\n\t\t\tIs.stringValue(value) &&\n\t\t\t/^[\\w!#$%&'*+./=?^`{|}~-]+@[\\dA-Za-z](?:[\\dA-Za-z-]{0,61}[\\dA-Za-z])?(?:\\.[\\dA-Za-z](?:[\\dA-Za-z-]{0,61}[\\dA-Za-z])?)*$/.test(\n\t\t\t\tvalue\n\t\t\t)\n\t\t);\n\t}\n\n\t/**\n\t * Is the value a promise.\n\t * @param value The value to test.\n\t * @returns True if the value is a promise.\n\t */\n\tpublic static promise<T = unknown>(value: unknown): value is Promise<T> {\n\t\t// This is the only way we can reliably check for Promise\n\t\t// eslint-disable-next-line no-restricted-syntax\n\t\treturn value instanceof Promise;\n\t}\n\n\t/**\n\t * Is the value a regexp.\n\t * @param value The value to test.\n\t * @returns True if the value is a regexp.\n\t */\n\tpublic static regexp(value: unknown): value is RegExp {\n\t\t// This is the only way we can reliably check for RegExp\n\t\t// eslint-disable-next-line no-restricted-syntax\n\t\treturn value instanceof RegExp;\n\t}\n\n\t/**\n\t * Is the provided object a class constructor.\n\t * @param obj The object to check.\n\t * @returns True if the object is a class, false otherwise.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tpublic static class<T = unknown>(obj: unknown): obj is new (...args: any[]) => T {\n\t\tif (typeof obj !== \"function\") {\n\t\t\treturn false;\n\t\t}\n\t\tconst str = Function.prototype.toString.call(obj);\n\t\treturn /^class\\s/.test(str);\n\t}\n}\n"]}
1
+ {"version":3,"file":"is.js","sourceRoot":"","sources":["../../../src/utils/is.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD;;GAEG;AACH,MAAM,OAAO,EAAE;IACd;;;;OAIG;IACI,MAAM,CAAC,SAAS,CAAC,KAAc;QACrC,OAAO,KAAK,KAAK,SAAS,CAAC;IAC5B,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,IAAI,CAAC,KAAc;QAChC,OAAO,KAAK,KAAK,IAAI,CAAC;IACvB,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,KAAK,CAAC,KAAc;QACjC,OAAO,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,CAAC;IAC9C,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,QAAQ,CAAC,KAAc;QACpC,OAAO,KAAK,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C,KAAK,CAAc,GAAY;QAC5C,IAAI,OAAO,GAAG,KAAK,UAAU,EAAE,CAAC;YAC/B,OAAO,KAAK,CAAC;QACd,CAAC;QACD,MAAM,GAAG,GAAG,QAAQ,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAClD,OAAO,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,MAAM,CAAC,KAAc,EAAE,MAA+B;QACnE,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YAC1B,uBAAuB;YACvB,kDAAkD;YAClD,2DAA2D;YAC3D,OAAO,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,4CAA4C,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC1F,CAAC;QAED,OAAO,CACN,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC;YACrB,mEAAmE,CAAC,IAAI,CAAC,KAAK,CAAC,CAC/E,CAAC;IACH,CAAC;CACD","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { HexHelper } from \"../helpers/hexHelper.js\";\n\n/**\n * Class to check types of objects.\n */\nexport class Is {\n\t/**\n\t * Is the property undefined.\n\t * @param value The value to test.\n\t * @returns True if the value is a empty.\n\t */\n\tpublic static undefined(value: unknown): value is undefined {\n\t\treturn value === undefined;\n\t}\n\n\t/**\n\t * Is the property null.\n\t * @param value The value to test.\n\t * @returns True if the value is a empty.\n\t */\n\tpublic static null(value: unknown): value is null {\n\t\treturn value === null;\n\t}\n\n\t/**\n\t * Is the property null or undefined.\n\t * @param value The value to test.\n\t * @returns True if the value is a empty.\n\t */\n\tpublic static empty(value: unknown): value is undefined | null {\n\t\treturn value === null || value === undefined;\n\t}\n\n\t/**\n\t * Is the property is not null or undefined.\n\t * @param value The value to test.\n\t * @returns True if the value is a not empty.\n\t */\n\tpublic static notEmpty(value: unknown): boolean {\n\t\treturn value !== null && value !== undefined;\n\t}\n\n\t/**\n\t * Is the value a string.\n\t * @param value The value to test.\n\t * @returns True if the value is a string.\n\t */\n\tpublic static string(value: unknown): value is string {\n\t\treturn typeof value === \"string\";\n\t}\n\n\t/**\n\t * Is the value a string.\n\t * @param value The value to test.\n\t * @returns True if the value is a string.\n\t */\n\tpublic static stringValue(value: unknown): value is string {\n\t\treturn Is.string(value) && value.trim().length > 0;\n\t}\n\n\t/**\n\t * Is the value a JSON string.\n\t * @param value The value to test.\n\t * @returns True if the value is a JSON string.\n\t */\n\tpublic static json(value: unknown): value is string {\n\t\tif (!Is.stringValue(value)) {\n\t\t\treturn false;\n\t\t}\n\n\t\ttry {\n\t\t\tconst json = JSON.parse(value);\n\t\t\treturn (\n\t\t\t\tIs.object(json) ||\n\t\t\t\tIs.array(json) ||\n\t\t\t\tIs.string(json) ||\n\t\t\t\tIs.number(json) ||\n\t\t\t\tIs.boolean(json) ||\n\t\t\t\tIs.null(json)\n\t\t\t);\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t/**\n\t * Is the value a base64 string.\n\t * @param value The value to test.\n\t * @returns True if the value is a base64 string.\n\t */\n\tpublic static stringBase64(value: unknown): value is string {\n\t\treturn (\n\t\t\tIs.stringValue(value) &&\n\t\t\t// eslint-disable-next-line unicorn/better-regex\n\t\t\t/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(value)\n\t\t);\n\t}\n\n\t/**\n\t * Is the value a base64 url string.\n\t * @param value The value to test.\n\t * @returns True if the value is a base64 string.\n\t */\n\tpublic static stringBase64Url(value: unknown): value is string {\n\t\treturn (\n\t\t\tIs.stringValue(value) &&\n\t\t\t// eslint-disable-next-line unicorn/better-regex\n\t\t\t/^([A-Za-z0-9-_])*$/.test(value)\n\t\t);\n\t}\n\n\t/**\n\t * Is the value a base58 string.\n\t * @param value The value to test.\n\t * @returns True if the value is a base58 string.\n\t */\n\tpublic static stringBase58(value: unknown): value is string {\n\t\treturn (\n\t\t\tIs.stringValue(value) &&\n\t\t\t// eslint-disable-next-line unicorn/better-regex\n\t\t\t/^[A-HJ-NP-Za-km-z1-9]*$/.test(value)\n\t\t);\n\t}\n\n\t/**\n\t * Is the value a hex string.\n\t * @param value The value to test.\n\t * @param allowPrefix Allow the hex to have the 0x prefix.\n\t * @returns True if the value is a hex string.\n\t */\n\tpublic static stringHex(value: unknown, allowPrefix: boolean = false): value is string {\n\t\treturn Is.string(value) && HexHelper.isHex(value, allowPrefix);\n\t}\n\n\t/**\n\t * Is the value a hex string of fixed length.\n\t * @param value The value to test.\n\t * @param length The length to test.\n\t * @param allowPrefix Allow the hex to have the 0x prefix.\n\t * @returns True if the value is a hex string of required length.\n\t */\n\tpublic static stringHexLength(\n\t\tvalue: unknown,\n\t\tlength: number,\n\t\tallowPrefix: boolean = false\n\t): value is string {\n\t\treturn Is.stringHex(value, allowPrefix) && value.length === length;\n\t}\n\n\t/**\n\t * Is the value a number.\n\t * @param value The value to test.\n\t * @returns True if the value is a number.\n\t */\n\tpublic static number(value: unknown): value is number {\n\t\treturn typeof value === \"number\" && Number.isFinite(value) && !Number.isNaN(value);\n\t}\n\n\t/**\n\t * Is the value an integer.\n\t * @param value The value to test.\n\t * @returns True if the value is an integer.\n\t */\n\tpublic static integer(value: unknown): value is number {\n\t\treturn Is.number(value) && Number.isInteger(value);\n\t}\n\n\t/**\n\t * Is the value a big integer.\n\t * @param value The value to test.\n\t * @returns True if the value is a big integer.\n\t */\n\tpublic static bigint(value: unknown): value is bigint {\n\t\treturn typeof value === \"bigint\";\n\t}\n\n\t/**\n\t * Is the value a boolean.\n\t * @param value The value to test.\n\t * @returns True if the value is a boolean.\n\t */\n\tpublic static boolean(value: unknown): value is boolean {\n\t\treturn typeof value === \"boolean\";\n\t}\n\n\t/**\n\t * Is the value a date.\n\t * @param value The value to test.\n\t * @returns True if the value is a date.\n\t */\n\tpublic static date(value: unknown): value is Date {\n\t\treturn (\n\t\t\tObject.prototype.toString.call(value) === \"[object Date]\" &&\n\t\t\t!Number.isNaN((value as Date).getTime())\n\t\t);\n\t}\n\n\t/**\n\t * Is the value an empty date.\n\t * @param value The value to test.\n\t * @returns True if the value is an empty date.\n\t */\n\tpublic static dateEmpty(value: unknown): boolean {\n\t\treturn (\n\t\t\tObject.prototype.toString.call(value) === \"[object Date]\" &&\n\t\t\tNumber.isNaN((value as Date).getTime())\n\t\t);\n\t}\n\n\t/**\n\t * Is the value a date string.\n\t * @param value The value to test.\n\t * @returns True if the value is a string in ISO 8601 date format.\n\t */\n\tpublic static dateString(value: unknown): boolean {\n\t\tif (typeof value !== \"string\" || value.length === 0 || value.includes(\"T\")) {\n\t\t\treturn false;\n\t\t}\n\t\treturn !Number.isNaN(Date.parse(value));\n\t}\n\n\t/**\n\t * Is the value a date string.\n\t * @param value The value to test.\n\t * @returns True if the value is a string in ISO 8601 date/time format.\n\t */\n\tpublic static dateTimeString(value: unknown): boolean {\n\t\tif (typeof value !== \"string\" || value.length === 0 || !value.includes(\"T\")) {\n\t\t\treturn false;\n\t\t}\n\t\treturn !Number.isNaN(Date.parse(value));\n\t}\n\n\t/**\n\t * Is the value a time string.\n\t * @param value The value to test.\n\t * @returns True if the value is a string in ISO 8601 time format.\n\t */\n\tpublic static timeString(value: unknown): boolean {\n\t\tif (typeof value !== \"string\" || value.length === 0 || value.includes(\"T\")) {\n\t\t\treturn false;\n\t\t}\n\t\treturn !Number.isNaN(Date.parse(`1970-01-01T${value}`));\n\t}\n\n\t/**\n\t * Is the value a timestamp in seconds.\n\t * @param value The value to test.\n\t * @returns True if the value is a date.\n\t */\n\tpublic static timestampSeconds(value: unknown): value is number {\n\t\tif (!Is.integer(value)) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn value.toString().length < 12;\n\t}\n\n\t/**\n\t * Is the value a timestamp in milliseconds.\n\t * @param value The value to test.\n\t * @returns True if the value is a date.\n\t */\n\tpublic static timestampMilliseconds(value: unknown): value is number {\n\t\tif (!Is.integer(value)) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn value.toString().length >= 12;\n\t}\n\n\t/**\n\t * Is the value an object.\n\t * @param value The value to test.\n\t * @returns True if the value is a object.\n\t */\n\tpublic static object<T = { [id: string]: unknown }>(value: unknown): value is T {\n\t\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n\t}\n\n\t/**\n\t * Is the value an object with at least one property.\n\t * @param value The value to test.\n\t * @returns True if the value is a object.\n\t */\n\tpublic static objectValue<T = { [id: string]: unknown }>(value: unknown): value is T {\n\t\treturn (\n\t\t\ttypeof value === \"object\" &&\n\t\t\tvalue !== null &&\n\t\t\t!Array.isArray(value) &&\n\t\t\tObject.keys(value).length > 0\n\t\t);\n\t}\n\n\t/**\n\t * Is the value an array.\n\t * @param value The value to test.\n\t * @returns True if the value is an array.\n\t */\n\tpublic static array<T>(value: unknown): value is T[] {\n\t\treturn Array.isArray(value);\n\t}\n\n\t/**\n\t * Is the value an array with at least one element.\n\t * @param value The value to test.\n\t * @returns True if the value is an array with at least one element.\n\t */\n\tpublic static arrayValue<T>(value: unknown): value is T[] {\n\t\treturn Array.isArray(value) && value.length > 0;\n\t}\n\n\t/**\n\t * Is the value an array with at least one element.\n\t * @param value The value to test.\n\t * @param options The options the value must be one of.\n\t * @returns True if the value is an element from the options array.\n\t */\n\tpublic static arrayOneOf<T>(value: T, options: T[]): value is T {\n\t\tif (Is.empty(value) || !Is.array<T>(options) || !options.includes(value)) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn true;\n\t}\n\n\t/**\n\t * Is the value a Uint8Array.\n\t * @param value The value to test.\n\t * @returns True if the value is a Uint8Array.\n\t */\n\tpublic static uint8Array(value: unknown): value is Uint8Array {\n\t\t// This is the only way we can reliably check for Uint8Array\n\t\t// eslint-disable-next-line no-restricted-syntax\n\t\treturn value instanceof Uint8Array;\n\t}\n\n\t/**\n\t * Is the value a TypedArray.\n\t * @param value The value to test.\n\t * @returns True if the value is a TypedArray.\n\t */\n\tpublic static typedArray(\n\t\tvalue: unknown\n\t): value is\n\t\t| Uint8Array\n\t\t| Int8Array\n\t\t| Uint16Array\n\t\t| Int16Array\n\t\t| Uint32Array\n\t\t| Int32Array\n\t\t| Float32Array\n\t\t| Float64Array {\n\t\t// This is the only way we can reliably check for TypedArray\n\t\t// eslint-disable-next-line no-restricted-syntax\n\t\treturn value instanceof Object.getPrototypeOf(Uint8Array);\n\t}\n\n\t/**\n\t * Is the property a function.\n\t * @param value The value to test.\n\t * @returns True if the value is a function.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tpublic static function<T extends (...args: any[]) => any = (...args: any[]) => any>(\n\t\tvalue: unknown\n\t): value is T {\n\t\treturn typeof value === \"function\";\n\t}\n\n\t/**\n\t * Is the value a string formatted as an email address.\n\t * @param value The value to test.\n\t * @returns True if the value is a string.\n\t */\n\tpublic static email(value: unknown): value is string {\n\t\treturn (\n\t\t\tIs.stringValue(value) &&\n\t\t\t/^[\\w!#$%&'*+./=?^`{|}~-]+@[\\dA-Za-z](?:[\\dA-Za-z-]{0,61}[\\dA-Za-z])?(?:\\.[\\dA-Za-z](?:[\\dA-Za-z-]{0,61}[\\dA-Za-z])?)*$/.test(\n\t\t\t\tvalue\n\t\t\t)\n\t\t);\n\t}\n\n\t/**\n\t * Is the value a promise.\n\t * @param value The value to test.\n\t * @returns True if the value is a promise.\n\t */\n\tpublic static promise<T = unknown>(value: unknown): value is Promise<T> {\n\t\t// This is the only way we can reliably check for Promise\n\t\t// eslint-disable-next-line no-restricted-syntax\n\t\treturn value instanceof Promise;\n\t}\n\n\t/**\n\t * Is the value a regexp.\n\t * @param value The value to test.\n\t * @returns True if the value is a regexp.\n\t */\n\tpublic static regexp(value: unknown): value is RegExp {\n\t\t// This is the only way we can reliably check for RegExp\n\t\t// eslint-disable-next-line no-restricted-syntax\n\t\treturn value instanceof RegExp;\n\t}\n\n\t/**\n\t * Is the provided object a class constructor.\n\t * @param obj The object to check.\n\t * @returns True if the object is a class, false otherwise.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tpublic static class<T = unknown>(obj: unknown): obj is new (...args: any[]) => T {\n\t\tif (typeof obj !== \"function\") {\n\t\t\treturn false;\n\t\t}\n\t\tconst str = Function.prototype.toString.call(obj);\n\t\treturn /^class\\s/.test(str);\n\t}\n\n\t/**\n\t * Is the value a uuidV7 string.\n\t * @param value The value to test.\n\t * @param format The format of the UUIDv7 string.\n\t * @returns True if the value is a uuidV7 string.\n\t */\n\tpublic static uuidV7(value: unknown, format?: \"standard\" | \"compact\"): value is string {\n\t\tif (format === \"compact\") {\n\t\t\t// 32 hex chars, where:\n\t\t\t// - char 13 (0-based index 12) is the version (7)\n\t\t\t// - char 17 (0-based index 16) is the variant (8, 9, a, b)\n\t\t\treturn Is.stringValue(value) && /^[\\da-f]{12}7[\\da-f]{3}[89ab][\\da-f]{15}$/i.test(value);\n\t\t}\n\n\t\treturn (\n\t\t\tIs.stringValue(value) &&\n\t\t\t/^[\\da-f]{8}-[\\da-f]{4}-7[\\da-f]{3}-[89ab][\\da-f]{3}-[\\da-f]{12}$/i.test(value)\n\t\t);\n\t}\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Class to help with base63 Encoding/Decoding.
2
+ * Class to help with base32 Encoding/Decoding.
3
3
  */
4
4
  export declare class Base32 {
5
5
  /**
@@ -29,12 +29,17 @@ export declare class Factory<T> {
29
29
  * Clear all the factories, which removes anything registered with the factories.
30
30
  */
31
31
  static clearFactories(): void;
32
+ /**
33
+ * Get the type name of the factory.
34
+ * @returns The type name of the factory.
35
+ */
36
+ typeName(): string;
32
37
  /**
33
38
  * Register a new generator.
34
39
  * @param name The name of the generator.
35
40
  * @param generator The function to create an instance.
36
41
  */
37
- register<U extends T>(name: string, generator: () => U): void;
42
+ register<U extends T>(name: string, generator: (args?: unknown) => U): void;
38
43
  /**
39
44
  * Unregister a generator.
40
45
  * @param name The name of the generator to unregister.
@@ -56,6 +61,23 @@ export declare class Factory<T> {
56
61
  * @returns An instance of the item or undefined if it does not exist.
57
62
  */
58
63
  getIfExists<U extends T>(name?: string): U | undefined;
64
+ /**
65
+ * Create a new instance without caching it.
66
+ * @param name The name of the instance to generate.
67
+ * @param args The arguments to pass to the generator.
68
+ * @returns A new instance of the item.
69
+ * @throws GuardError if the parameters are invalid.
70
+ * @throws GeneralError if no item exists to create.
71
+ */
72
+ create<U extends T>(name: string, args?: unknown): U;
73
+ /**
74
+ * Create a new instance without caching it if it exists.
75
+ * @param name The name of the instance to generate.
76
+ * @param args The arguments to pass to the generator.
77
+ * @returns A new instance of the item if it exists.
78
+ * @throws GuardError if the parameters are invalid.
79
+ */
80
+ createIfExists<U extends T>(name: string, args?: unknown): U | undefined;
59
81
  /**
60
82
  * Remove all the instances and leave the generators intact.
61
83
  */
@@ -1,4 +1,4 @@
1
- import type { ObjectOrArray } from "../models/objectOrArray.js";
1
+ import type { ObjectOrArray } from "../types/objectOrArray.js";
2
2
  /**
3
3
  * Class to help with arrays.
4
4
  */
@@ -2,10 +2,26 @@
2
2
  * Class to help with random generation.
3
3
  */
4
4
  export declare class RandomHelper {
5
+ /**
6
+ * Runtime name for the class.
7
+ */
8
+ static readonly CLASS_NAME: string;
5
9
  /**
6
10
  * Generate a new random array.
7
11
  * @param length The length of buffer to create.
8
12
  * @returns The random array.
9
13
  */
10
14
  static generate(length: number): Uint8Array;
15
+ /**
16
+ * Generate a new UUIDv7.
17
+ * @param format The format of the UUIDv7 string.
18
+ * @returns The UUIDv7 string.
19
+ */
20
+ static generateUuidV7(format?: "standard" | "compact"): string;
21
+ /**
22
+ * Extract the unix timestamp (ms) from a UUIDv7.
23
+ * @param uuid The UUIDv7 string.
24
+ * @returns The unix timestamp in milliseconds.
25
+ */
26
+ static uuidV7ExtractTimestamp(uuid: string): number;
11
27
  }
@@ -39,8 +39,9 @@ export * from "./models/ILocalesIndex.js";
39
39
  export * from "./models/IPatchOperation.js";
40
40
  export * from "./models/IUrlParts.js";
41
41
  export * from "./models/IValidationFailure.js";
42
- export * from "./models/objectOrArray.js";
43
42
  export * from "./types/bitString.js";
43
+ export * from "./types/objectOrArray.js";
44
+ export * from "./types/singleOccurrenceArray.js";
44
45
  export * from "./types/url.js";
45
46
  export * from "./types/urn.js";
46
47
  export * from "./utils/asyncCache.js";
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Helper with bounded recursion depth to keep type instantiation tractable.
3
+ */
4
+ export type SingleOccurrenceArrayDepthHelper<T, U, Depth extends 0[]> = Depth["length"] extends 16 ? [U, ...T[]] : [U, ...T[]] | [T, ...SingleOccurrenceArrayDepthHelper<T, U, [0, ...Depth]>];
5
+ /**
6
+ * Utility type to create a non-empty array with values of type T and exactly one value of type U.
7
+ */
8
+ export type SingleOccurrenceArray<T = unknown, U = never> = SingleOccurrenceArrayDepthHelper<T, U, [
9
+ ]>;
@@ -39,4 +39,11 @@ export declare class AsyncCache {
39
39
  * Perform a cleanup of the expired entries in the cache.
40
40
  */
41
41
  static cleanupExpired(): void;
42
+ /**
43
+ * Resolve a waiter by re-running its request method safely.
44
+ * @param requestMethod The method to execute.
45
+ * @param resolve The resolver for the waiter.
46
+ * @param reject The rejector for the waiter.
47
+ */
48
+ private static resolveWaiter;
42
49
  }
@@ -1,4 +1,4 @@
1
- import type { ObjectOrArray } from "../models/objectOrArray.js";
1
+ import type { ObjectOrArray } from "../types/objectOrArray.js";
2
2
  /**
3
3
  * Class to handle guard operations for parameters.
4
4
  */
@@ -221,4 +221,13 @@ export declare class Guards {
221
221
  * @throws GuardError If the value does not match the assertion.
222
222
  */
223
223
  static email(source: string, property: string, value: unknown): asserts value is string;
224
+ /**
225
+ * Is the property a string containing uuidV7.
226
+ * @param source The source of the error.
227
+ * @param property The name of the property.
228
+ * @param value The value to test.
229
+ * @param format The format of the uuidV7, either standard or compact.
230
+ * @throws GuardError If the value does not match the assertion.
231
+ */
232
+ static uuidV7(source: string, property: string, value: unknown, format?: "standard" | "compact"): asserts value is string;
224
233
  }
@@ -220,4 +220,11 @@ export declare class Is {
220
220
  * @returns True if the object is a class, false otherwise.
221
221
  */
222
222
  static class<T = unknown>(obj: unknown): obj is new (...args: any[]) => T;
223
+ /**
224
+ * Is the value a uuidV7 string.
225
+ * @param value The value to test.
226
+ * @param format The format of the UUIDv7 string.
227
+ * @returns True if the value is a uuidV7 string.
228
+ */
229
+ static uuidV7(value: unknown, format?: "standard" | "compact"): value is string;
223
230
  }