@wener/utils 1.1.51 → 1.1.54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/arrays/MaybeArray.js +58 -8
- package/lib/arrays/arrayFromAsync.js +254 -6
- package/lib/asyncs/AsyncInterval.js +145 -9
- package/lib/asyncs/MaybePromise.js +0 -2
- package/lib/asyncs/Promises.js +95 -48
- package/lib/asyncs/createAsyncIterator.js +313 -23
- package/lib/asyncs/createLazyPromise.js +72 -31
- package/lib/asyncs/createLazyPromise.test.js +367 -0
- package/lib/asyncs/firstOfAsyncIterator.js +6 -6
- package/lib/asyncs/generatorOfStream.js +125 -14
- package/lib/asyncs/isIterator.js +1 -3
- package/lib/asyncs/isPromise.js +2 -4
- package/lib/asyncs/isThenable.js +0 -2
- package/lib/asyncs/nextOfAsyncIterator.js +15 -9
- package/lib/asyncs/promiseOfCallback.js +2 -4
- package/lib/asyncs/timeout.js +122 -13
- package/lib/browsers/copy.js +7 -8
- package/lib/browsers/download.js +215 -40
- package/lib/browsers/getFileFromDataTransfer.js +17 -14
- package/lib/browsers/loaders.js +251 -18
- package/lib/crypto/base.js +3 -3
- package/lib/crypto/getNodeCrypto.js +3 -5
- package/lib/crypto/hashing.js +236 -30
- package/lib/crypto/hashing.test.js +323 -0
- package/lib/crypto/md5.bench.js +11 -11
- package/lib/crypto/md5.d.js +0 -2
- package/lib/crypto/md5.js +0 -2
- package/lib/crypto/md5.test.js +7 -0
- package/lib/crypto/pem/pem.js +197 -35
- package/lib/crypto/pem/pem.test.js +104 -0
- package/lib/crypto/randomUUIDv7.js +0 -2
- package/lib/crypto/ulid.js +84 -48
- package/lib/crypto/ulid.test.js +115 -0
- package/lib/emitter/types.js +0 -2
- package/lib/errors/DetailError.js +297 -0
- package/lib/errors/Errors.js +136 -137
- package/lib/errors/Errors.test.js +24 -0
- package/lib/fetch/HttpStatus.js +1 -3
- package/lib/fetch/createFetchWith.js +188 -19
- package/lib/fetch/createFetchWithLogging.js +17 -16
- package/lib/fetch/createFetchWithRetry.js +40 -24
- package/lib/fetch/dumpRequest.js +467 -41
- package/lib/fetch/dumpRequest.test.js +384 -0
- package/lib/fetch/dumpResponse.js +271 -16
- package/lib/fetch/dumpResponse.test.js +393 -0
- package/lib/fetch/http.types.js +0 -2
- package/lib/fetch/index.js +5 -7
- package/lib/fetch/isTextContentType.js +5 -0
- package/lib/fetch/resolveRequest.js +7 -0
- package/lib/fetch/types.js +0 -2
- package/lib/i18n/createTranslate.js +40 -20
- package/lib/i18n/createTranslate.test.js +177 -0
- package/lib/index.js +75 -76
- package/lib/io/AbstractEncoding.js +0 -2
- package/lib/io/ArrayBuffer.test-d.js +4 -6
- package/lib/io/ArrayBuffers.base64.test.js +60 -0
- package/lib/io/ArrayBuffers.js +396 -171
- package/lib/io/ArrayBuffers.test.js +77 -0
- package/lib/io/Buffer.js +190 -20
- package/lib/io/Buffer.test.js +22 -0
- package/lib/io/ByteBuffer.js +752 -441
- package/lib/io/ByteBuffer.test.js +184 -0
- package/lib/io/base64.js +17 -19
- package/lib/io/dump.js +16 -16
- package/lib/io/isBuffer.js +2 -3
- package/lib/io/isBuffer.test.js +8 -0
- package/lib/io/isTransferable.js +16 -8
- package/lib/io/isTransferable.test.js +17 -0
- package/lib/io/parseDataUri.js +288 -40
- package/lib/io/parseDataUri.test.js +286 -0
- package/lib/io/types.js +1 -0
- package/lib/langs/AsyncCloser.js +270 -34
- package/lib/langs/Closer.js +95 -29
- package/lib/langs/MaybeFunction.js +38 -5
- package/lib/langs/classOf.js +0 -2
- package/lib/langs/deepEqual.js +82 -22
- package/lib/langs/deepEqual.test.js +11 -0
- package/lib/langs/deepFreeze.js +28 -9
- package/lib/langs/getGlobalStates.js +14 -10
- package/lib/langs/getObjectId.js +4 -6
- package/lib/langs/ifPresent.js +0 -2
- package/lib/langs/isClass.js +0 -2
- package/lib/langs/isDefined.js +0 -2
- package/lib/langs/isEmptyObject.js +1 -3
- package/lib/langs/isFunction.js +0 -2
- package/lib/langs/isNil.js +3 -0
- package/lib/langs/isPlainObject.js +2 -4
- package/lib/langs/langs.test.js +126 -0
- package/lib/langs/memoize.js +11 -7
- package/lib/langs/mixin.js +7 -4
- package/lib/langs/mixin.test.js +135 -0
- package/lib/langs/parseBoolean.js +11 -8
- package/lib/langs/parseDate.js +20 -0
- package/lib/langs/shallowClone.js +5 -3
- package/lib/langs/shallowEqual.js +8 -6
- package/lib/libs/ms.js +28 -26
- package/lib/libs/ms.test.js +301 -0
- package/lib/logger/const.js +15 -0
- package/lib/logger/index.js +1 -0
- package/lib/logger/types.js +1 -0
- package/lib/maths/clamp.js +81 -12
- package/lib/maths/clamp.test.js +186 -0
- package/lib/maths/createRandom.test.js +36 -0
- package/lib/maths/random.js +162 -13
- package/lib/modules/isModule.js +0 -2
- package/lib/modules/parseModuleId.js +14 -15
- package/lib/modules/parseModuleId.test.js +153 -0
- package/lib/objects/computeIfAbsent.js +8 -3
- package/lib/objects/get.js +26 -8
- package/lib/objects/get.test-d.js +23 -25
- package/lib/objects/merge/index.js +1 -3
- package/lib/objects/merge/isMergeableObject.js +5 -3
- package/lib/objects/merge/merge.js +82 -26
- package/lib/objects/merge/merge.test.js +1397 -0
- package/lib/objects/parseObjectPath.js +47 -15
- package/lib/objects/parseObjectPath.test.js +138 -0
- package/lib/objects/set.js +25 -19
- package/lib/objects/set.test.js +522 -0
- package/lib/schema/typebox/index.js +2 -3
- package/lib/schema/typebox/typebox.js +6 -6
- package/lib/scripts/getGenerateContext.js +386 -77
- package/lib/server/crypto/md5.js +0 -2
- package/lib/server/fetch/createFetchWithProxy.js +2 -4
- package/lib/server/fetch/createFetchWithProxyByNodeFetch.js +258 -31
- package/lib/server/fetch/createFetchWithProxyByUndici.js +307 -49
- package/lib/server/getPackageDir.js +2 -3
- package/lib/server/index.js +5 -7
- package/lib/server/jsdom.js +1 -3
- package/lib/server/node-fetch.js +2 -4
- package/lib/server/polyfill/polyfillBrowser.js +163 -9
- package/lib/server/polyfill/polyfillBrowser.test.js +164 -0
- package/lib/server/polyfill/polyfillCrypto.js +157 -9
- package/lib/server/polyfill/polyfillFetch.js +13 -13
- package/lib/server/polyfill/polyfillJsDom.js +264 -58
- package/lib/server/polyfill/polyfillWebSocket.js +11 -11
- package/lib/server/ws.js +1 -3
- package/lib/strings/bytes.test.js +327 -0
- package/lib/strings/camelCase.js +23 -14
- package/lib/strings/formatBytes.js +29 -20
- package/lib/strings/parseBytes.js +54 -0
- package/lib/strings/renderTemplate.js +17 -12
- package/lib/strings/renderTemplate.test.js +104 -0
- package/lib/typedoc.js +2 -4
- package/lib/types.d.js +0 -2
- package/lib/validations/asserts.js +0 -2
- package/lib/validations/isUUID.js +0 -2
- package/lib/validations/isUUID.test.js +87 -0
- package/lib/validations/parseTimestamp.js +12 -7
- package/lib/validations/parseTimestamp.test.js +6 -0
- package/lib/web/getGlobalThis.js +3 -4
- package/lib/web/getRandomValues.js +28 -20
- package/lib/web/randomUUID.js +7 -8
- package/lib/web/requestIdleCallback.js +13 -9
- package/lib/web/structuredClone.js +35 -28
- package/lib/web/structuredClone.test.js +81 -0
- package/package.json +9 -14
- package/src/arrays/MaybeArray.ts +22 -22
- package/src/arrays/arrayFromAsync.ts +3 -3
- package/src/asyncs/AsyncInterval.ts +8 -8
- package/src/asyncs/Promises.ts +51 -51
- package/src/asyncs/createAsyncIterator.ts +33 -33
- package/src/asyncs/createLazyPromise.test.ts +73 -73
- package/src/asyncs/createLazyPromise.ts +68 -73
- package/src/asyncs/firstOfAsyncIterator.ts +5 -5
- package/src/asyncs/generatorOfStream.ts +12 -12
- package/src/asyncs/isIterator.ts +1 -1
- package/src/asyncs/isThenable.ts +2 -2
- package/src/asyncs/nextOfAsyncIterator.ts +20 -20
- package/src/asyncs/promiseOfCallback.ts +13 -13
- package/src/asyncs/timeout.ts +23 -23
- package/src/browsers/copy.ts +48 -48
- package/src/browsers/download.ts +38 -36
- package/src/browsers/getFileFromDataTransfer.ts +35 -35
- package/src/browsers/loaders.ts +49 -49
- package/src/crypto/base.ts +3 -3
- package/src/crypto/getNodeCrypto.ts +2 -2
- package/src/crypto/hashing.test.ts +33 -47
- package/src/crypto/hashing.ts +67 -67
- package/src/crypto/md5.bench.ts +20 -24
- package/src/crypto/md5.test.ts +3 -3
- package/src/crypto/pem/pem.test.ts +26 -42
- package/src/crypto/pem/pem.ts +65 -65
- package/src/crypto/ulid.test.ts +31 -31
- package/src/crypto/ulid.ts +116 -116
- package/src/emitter/types.ts +6 -6
- package/src/errors/DetailError.ts +151 -0
- package/src/errors/Errors.test.ts +15 -15
- package/src/errors/Errors.ts +97 -238
- package/src/fetch/HttpStatus.ts +77 -77
- package/src/fetch/createFetchWith.ts +25 -25
- package/src/fetch/createFetchWithLogging.ts +12 -15
- package/src/fetch/createFetchWithRetry.ts +79 -79
- package/src/fetch/dumpRequest.test.ts +176 -0
- package/src/fetch/dumpRequest.ts +149 -52
- package/src/fetch/dumpResponse.test.ts +160 -0
- package/src/fetch/dumpResponse.ts +48 -20
- package/src/fetch/http.types.ts +35 -35
- package/src/fetch/isTextContentType.ts +12 -0
- package/src/fetch/resolveRequest.ts +1 -0
- package/src/fetch/types.ts +2 -2
- package/src/i18n/createTranslate.test.ts +90 -113
- package/src/i18n/createTranslate.ts +55 -55
- package/src/index.ts +26 -26
- package/src/io/AbstractEncoding.ts +12 -12
- package/src/io/ArrayBuffer.test-d.ts +1 -1
- package/src/io/ArrayBuffers.base64.test.ts +52 -52
- package/src/io/ArrayBuffers.test.ts +14 -14
- package/src/io/ArrayBuffers.ts +645 -415
- package/src/io/Buffer.test.ts +17 -17
- package/src/io/Buffer.ts +17 -17
- package/src/io/ByteBuffer.test.ts +37 -37
- package/src/io/ByteBuffer.ts +574 -566
- package/src/io/base64.ts +46 -44
- package/src/io/dump.ts +22 -22
- package/src/io/isBuffer.test.ts +2 -2
- package/src/io/isBuffer.ts +1 -1
- package/src/io/isTransferable.test.ts +4 -4
- package/src/io/isTransferable.ts +29 -29
- package/src/io/parseDataUri.test.ts +22 -27
- package/src/io/parseDataUri.ts +57 -57
- package/src/io/types.ts +13 -0
- package/src/langs/AsyncCloser.ts +34 -34
- package/src/langs/Closer.ts +28 -28
- package/src/langs/MaybeFunction.ts +5 -5
- package/src/langs/classOf.ts +1 -1
- package/src/langs/deepEqual.test.ts +1 -12
- package/src/langs/deepEqual.ts +82 -82
- package/src/langs/deepFreeze.ts +11 -11
- package/src/langs/getGlobalStates.ts +16 -16
- package/src/langs/getObjectId.ts +10 -13
- package/src/langs/ifPresent.ts +2 -2
- package/src/langs/isClass.ts +1 -1
- package/src/langs/isDefined.ts +1 -1
- package/src/langs/isEmptyObject.ts +1 -1
- package/src/langs/isFunction.ts +1 -1
- package/src/langs/isNil.ts +3 -0
- package/src/langs/isPlainObject.ts +4 -4
- package/src/langs/langs.test.ts +18 -18
- package/src/langs/memoize.ts +21 -21
- package/src/langs/mixin.test.ts +22 -26
- package/src/langs/mixin.ts +6 -9
- package/src/langs/parseBoolean.ts +30 -26
- package/src/langs/parseDate.ts +13 -0
- package/src/langs/shallowClone.ts +11 -11
- package/src/langs/shallowEqual.ts +19 -19
- package/src/libs/ms.test.ts +274 -274
- package/src/libs/ms.ts +137 -137
- package/src/logger/const.ts +18 -0
- package/src/logger/index.ts +2 -0
- package/src/logger/types.ts +10 -0
- package/src/maths/clamp.test.ts +18 -18
- package/src/maths/clamp.ts +17 -17
- package/src/maths/createRandom.test.ts +12 -0
- package/src/maths/random.ts +50 -14
- package/src/modules/isModule.ts +4 -4
- package/src/modules/parseModuleId.test.ts +61 -68
- package/src/modules/parseModuleId.ts +29 -43
- package/src/objects/computeIfAbsent.ts +10 -10
- package/src/objects/get.test-d.ts +33 -51
- package/src/objects/get.ts +31 -31
- package/src/objects/merge/isMergeableObject.ts +5 -5
- package/src/objects/merge/merge.test.ts +658 -880
- package/src/objects/merge/merge.ts +84 -84
- package/src/objects/parseObjectPath.test.ts +13 -13
- package/src/objects/parseObjectPath.ts +25 -25
- package/src/objects/set.test.ts +271 -366
- package/src/objects/set.ts +36 -36
- package/src/schema/typebox/typebox.ts +20 -26
- package/src/scripts/getGenerateContext.ts +79 -79
- package/src/server/crypto/md5.ts +1 -1
- package/src/server/fetch/createFetchWithProxyByNodeFetch.ts +28 -31
- package/src/server/fetch/createFetchWithProxyByUndici.ts +63 -69
- package/src/server/getPackageDir.ts +7 -7
- package/src/server/polyfill/polyfillBrowser.test.ts +10 -10
- package/src/server/polyfill/polyfillBrowser.ts +3 -3
- package/src/server/polyfill/polyfillCrypto.ts +6 -6
- package/src/server/polyfill/polyfillFetch.ts +11 -21
- package/src/server/polyfill/polyfillJsDom.ts +59 -71
- package/src/server/polyfill/polyfillWebSocket.ts +14 -14
- package/src/strings/bytes.test.ts +69 -0
- package/src/strings/camelCase.ts +58 -63
- package/src/strings/formatBytes.ts +50 -29
- package/src/strings/parseBytes.ts +66 -0
- package/src/strings/renderTemplate.test.ts +10 -17
- package/src/strings/renderTemplate.ts +19 -22
- package/src/types.d.ts +9 -9
- package/src/validations/asserts.ts +8 -8
- package/src/validations/isUUID.test.ts +8 -8
- package/src/validations/isUUID.ts +1 -1
- package/src/validations/parseTimestamp.test.ts +2 -2
- package/src/validations/parseTimestamp.ts +21 -21
- package/src/web/getGlobalThis.ts +6 -6
- package/src/web/getRandomValues.ts +29 -29
- package/src/web/randomUUID.ts +5 -5
- package/src/web/requestIdleCallback.ts +7 -10
- package/src/web/structuredClone.test.ts +8 -8
- package/src/web/structuredClone.ts +62 -62
- package/tsconfig.json +26 -34
- package/lib/arrays/MaybeArray.js.map +0 -1
- package/lib/arrays/arrayFromAsync.js.map +0 -1
- package/lib/asyncs/AsyncInterval.js.map +0 -1
- package/lib/asyncs/MaybePromise.js.map +0 -1
- package/lib/asyncs/Promises.js.map +0 -1
- package/lib/asyncs/createAsyncIterator.js.map +0 -1
- package/lib/asyncs/createLazyPromise.js.map +0 -1
- package/lib/asyncs/firstOfAsyncIterator.js.map +0 -1
- package/lib/asyncs/generatorOfStream.js.map +0 -1
- package/lib/asyncs/isIterator.js.map +0 -1
- package/lib/asyncs/isPromise.js.map +0 -1
- package/lib/asyncs/isThenable.js.map +0 -1
- package/lib/asyncs/nextOfAsyncIterator.js.map +0 -1
- package/lib/asyncs/promiseOfCallback.js.map +0 -1
- package/lib/asyncs/timeout.js.map +0 -1
- package/lib/browsers/copy.js.map +0 -1
- package/lib/browsers/download.js.map +0 -1
- package/lib/browsers/getFileFromDataTransfer.js.map +0 -1
- package/lib/browsers/loaders.js.map +0 -1
- package/lib/cn/division/DivisionCode.js +0 -215
- package/lib/cn/division/DivisionCode.js.map +0 -1
- package/lib/cn/division/binarySearch.js +0 -27
- package/lib/cn/division/binarySearch.js.map +0 -1
- package/lib/cn/formatChineseAmount.js +0 -77
- package/lib/cn/formatChineseAmount.js.map +0 -1
- package/lib/cn/id/Mod11.js +0 -43
- package/lib/cn/id/Mod11.js.map +0 -1
- package/lib/cn/id/ResidentIdNumber.js +0 -98
- package/lib/cn/id/ResidentIdNumber.js.map +0 -1
- package/lib/cn/id/types.js +0 -8
- package/lib/cn/id/types.js.map +0 -1
- package/lib/cn/index.js +0 -14
- package/lib/cn/index.js.map +0 -1
- package/lib/cn/parseChineseNumber.js +0 -94
- package/lib/cn/parseChineseNumber.js.map +0 -1
- package/lib/cn/pinyin/cartesianProduct.js +0 -22
- package/lib/cn/pinyin/cartesianProduct.js.map +0 -1
- package/lib/cn/pinyin/data.json +0 -413
- package/lib/cn/pinyin/loader.js +0 -15
- package/lib/cn/pinyin/loader.js.map +0 -1
- package/lib/cn/pinyin/preload.js +0 -4
- package/lib/cn/pinyin/preload.js.map +0 -1
- package/lib/cn/pinyin/toPinyinPure.js +0 -32
- package/lib/cn/pinyin/toPinyinPure.js.map +0 -1
- package/lib/cn/pinyin/transform.js +0 -14
- package/lib/cn/pinyin/transform.js.map +0 -1
- package/lib/cn/types.js +0 -3
- package/lib/cn/types.js.map +0 -1
- package/lib/cn/uscc/Mod31.js +0 -49
- package/lib/cn/uscc/Mod31.js.map +0 -1
- package/lib/cn/uscc/USCC.js +0 -94
- package/lib/cn/uscc/USCC.js.map +0 -1
- package/lib/cn/uscc/isUSCC.js +0 -8
- package/lib/cn/uscc/isUSCC.js.map +0 -1
- package/lib/crypto/base.js.map +0 -1
- package/lib/crypto/getNodeCrypto.js.map +0 -1
- package/lib/crypto/hashing.js.map +0 -1
- package/lib/crypto/md5.bench.js.map +0 -1
- package/lib/crypto/md5.d.js.map +0 -1
- package/lib/crypto/md5.js.map +0 -1
- package/lib/crypto/pem/pem.js.map +0 -1
- package/lib/crypto/randomUUIDv7.js.map +0 -1
- package/lib/crypto/ulid.js.map +0 -1
- package/lib/emitter/types.js.map +0 -1
- package/lib/errors/Errors.js.map +0 -1
- package/lib/fetch/HttpStatus.js.map +0 -1
- package/lib/fetch/createFetchWith.js.map +0 -1
- package/lib/fetch/createFetchWithLogging.js.map +0 -1
- package/lib/fetch/createFetchWithRetry.js.map +0 -1
- package/lib/fetch/dumpRequest.js.map +0 -1
- package/lib/fetch/dumpResponse.js.map +0 -1
- package/lib/fetch/http.types.js.map +0 -1
- package/lib/fetch/index.js.map +0 -1
- package/lib/fetch/types.js.map +0 -1
- package/lib/i18n/createTranslate.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/io/AbstractEncoding.js.map +0 -1
- package/lib/io/ArrayBuffer.test-d.js.map +0 -1
- package/lib/io/ArrayBuffers.js.map +0 -1
- package/lib/io/Buffer.js.map +0 -1
- package/lib/io/ByteBuffer.js.map +0 -1
- package/lib/io/base64.js.map +0 -1
- package/lib/io/dump.js.map +0 -1
- package/lib/io/isBuffer.js.map +0 -1
- package/lib/io/isTransferable.js.map +0 -1
- package/lib/io/parseDataUri.js.map +0 -1
- package/lib/langs/AsyncCloser.js.map +0 -1
- package/lib/langs/Closer.js.map +0 -1
- package/lib/langs/MaybeFunction.js.map +0 -1
- package/lib/langs/classOf.js.map +0 -1
- package/lib/langs/deepEqual.js.map +0 -1
- package/lib/langs/deepFreeze.js.map +0 -1
- package/lib/langs/getGlobalStates.js.map +0 -1
- package/lib/langs/getObjectId.js.map +0 -1
- package/lib/langs/ifPresent.js.map +0 -1
- package/lib/langs/isClass.js.map +0 -1
- package/lib/langs/isDefined.js.map +0 -1
- package/lib/langs/isEmptyObject.js.map +0 -1
- package/lib/langs/isFunction.js.map +0 -1
- package/lib/langs/isNullish.js +0 -5
- package/lib/langs/isNullish.js.map +0 -1
- package/lib/langs/isPlainObject.js.map +0 -1
- package/lib/langs/memoize.js.map +0 -1
- package/lib/langs/mixin.js.map +0 -1
- package/lib/langs/parseBoolean.js.map +0 -1
- package/lib/langs/shallowClone.js.map +0 -1
- package/lib/langs/shallowEqual.js.map +0 -1
- package/lib/libs/ms.js.map +0 -1
- package/lib/logging/Logger.js +0 -5
- package/lib/logging/Logger.js.map +0 -1
- package/lib/logging/createChildLogger.js +0 -16
- package/lib/logging/createChildLogger.js.map +0 -1
- package/lib/logging/createLogger.js +0 -63
- package/lib/logging/createLogger.js.map +0 -1
- package/lib/logging/createNoopLogger.js +0 -13
- package/lib/logging/createNoopLogger.js.map +0 -1
- package/lib/logging/slog.js +0 -143
- package/lib/logging/slog.js.map +0 -1
- package/lib/maths/clamp.js.map +0 -1
- package/lib/maths/random.js.map +0 -1
- package/lib/mitt/index.js +0 -77
- package/lib/mitt/index.js.map +0 -1
- package/lib/modules/isModule.js.map +0 -1
- package/lib/modules/parseModuleId.js.map +0 -1
- package/lib/objects/computeIfAbsent.js.map +0 -1
- package/lib/objects/get.js.map +0 -1
- package/lib/objects/get.test-d.js.map +0 -1
- package/lib/objects/merge/index.js.map +0 -1
- package/lib/objects/merge/isMergeableObject.js.map +0 -1
- package/lib/objects/merge/merge.js.map +0 -1
- package/lib/objects/parseObjectPath.js.map +0 -1
- package/lib/objects/set.js.map +0 -1
- package/lib/schema/typebox/index.js.map +0 -1
- package/lib/schema/typebox/typebox.js.map +0 -1
- package/lib/scripts/getGenerateContext.js.map +0 -1
- package/lib/server/crypto/md5.js.map +0 -1
- package/lib/server/fetch/createFetchWithProxy.js.map +0 -1
- package/lib/server/fetch/createFetchWithProxyByNodeFetch.js.map +0 -1
- package/lib/server/fetch/createFetchWithProxyByUndici.js.map +0 -1
- package/lib/server/getPackageDir.js.map +0 -1
- package/lib/server/index.js.map +0 -1
- package/lib/server/jsdom.js.map +0 -1
- package/lib/server/node-fetch.js.map +0 -1
- package/lib/server/polyfill/polyfillBrowser.js.map +0 -1
- package/lib/server/polyfill/polyfillCrypto.js.map +0 -1
- package/lib/server/polyfill/polyfillFetch.js.map +0 -1
- package/lib/server/polyfill/polyfillJsDom.js.map +0 -1
- package/lib/server/polyfill/polyfillWebSocket.js.map +0 -1
- package/lib/server/ws.js.map +0 -1
- package/lib/strings/camelCase.js.map +0 -1
- package/lib/strings/formatBytes.js.map +0 -1
- package/lib/strings/renderTemplate.js.map +0 -1
- package/lib/typedoc.js.map +0 -1
- package/lib/types.d.js.map +0 -1
- package/lib/validations/asserts.js.map +0 -1
- package/lib/validations/isUUID.js.map +0 -1
- package/lib/validations/parseTimestamp.js.map +0 -1
- package/lib/web/getGlobalThis.js.map +0 -1
- package/lib/web/getRandomValues.js.map +0 -1
- package/lib/web/randomUUID.js.map +0 -1
- package/lib/web/requestIdleCallback.js.map +0 -1
- package/lib/web/structuredClone.js.map +0 -1
- package/src/cn/README.md +0 -3
- package/src/cn/division/DivisionCode.ts +0 -173
- package/src/cn/division/binarySearch.test.ts +0 -64
- package/src/cn/division/binarySearch.ts +0 -25
- package/src/cn/division/division.test.ts +0 -22
- package/src/cn/formatChineseAmount.ts +0 -61
- package/src/cn/id/Mod11.ts +0 -26
- package/src/cn/id/ResidentIdNumber.ts +0 -126
- package/src/cn/id/id.test.ts +0 -20
- package/src/cn/id/types.ts +0 -26
- package/src/cn/index.ts +0 -17
- package/src/cn/parseChineseNumber.test.ts +0 -159
- package/src/cn/parseChineseNumber.ts +0 -97
- package/src/cn/pinyin/cartesianProduct.test.ts +0 -64
- package/src/cn/pinyin/cartesianProduct.ts +0 -24
- package/src/cn/pinyin/data.json +0 -413
- package/src/cn/pinyin/loader.ts +0 -12
- package/src/cn/pinyin/preload.ts +0 -3
- package/src/cn/pinyin/toPinyin.test.ts +0 -12
- package/src/cn/pinyin/toPinyinPure.ts +0 -43
- package/src/cn/pinyin/transform.ts +0 -12
- package/src/cn/scripts/gen.test.ts +0 -131
- package/src/cn/types.ts +0 -11
- package/src/cn/uscc/Mod31.ts +0 -38
- package/src/cn/uscc/USCC.ts +0 -94
- package/src/cn/uscc/isUSCC.ts +0 -8
- package/src/cn/uscc/uscc.test.ts +0 -16
- package/src/langs/isNullish.ts +0 -3
- package/src/logging/Logger.ts +0 -25
- package/src/logging/createChildLogger.ts +0 -16
- package/src/logging/createLogger.ts +0 -50
- package/src/logging/createNoopLogger.ts +0 -13
- package/src/logging/logger.test.ts +0 -36
- package/src/logging/slog.test.ts +0 -8
- package/src/logging/slog.ts +0 -221
- package/src/mitt/README.md +0 -1
- package/src/mitt/index.ts +0 -114
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { getHttpStatusText } from '../fetch/HttpStatus';
|
|
2
|
+
|
|
3
|
+
export interface ErrorDetailInit {
|
|
4
|
+
message?: string;
|
|
5
|
+
status: number;
|
|
6
|
+
description?: string;
|
|
7
|
+
code?: number | string;
|
|
8
|
+
metadata?: Record<string, any>;
|
|
9
|
+
cause?: any;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class DetailError extends Error {
|
|
13
|
+
readonly detail: ErrorDetail;
|
|
14
|
+
readonly status: number;
|
|
15
|
+
readonly description?: string;
|
|
16
|
+
|
|
17
|
+
constructor(detail: ErrorDetail) {
|
|
18
|
+
super(detail.message, { cause: detail.cause });
|
|
19
|
+
this.detail = detail;
|
|
20
|
+
this.status = detail.status;
|
|
21
|
+
this.description = detail.description;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
toJSON() {
|
|
25
|
+
return {
|
|
26
|
+
code: this.detail.code,
|
|
27
|
+
message: this.message,
|
|
28
|
+
status: this.status,
|
|
29
|
+
description: this.description,
|
|
30
|
+
cause: this.cause,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export class DetailHolder implements ErrorDetail {
|
|
36
|
+
readonly message: string;
|
|
37
|
+
readonly status: number;
|
|
38
|
+
readonly code: number | string;
|
|
39
|
+
readonly metadata?: Record<string, any>;
|
|
40
|
+
readonly description?: string;
|
|
41
|
+
readonly cause?: any;
|
|
42
|
+
|
|
43
|
+
constructor({
|
|
44
|
+
status,
|
|
45
|
+
message = getHttpStatusText(status),
|
|
46
|
+
code = status,
|
|
47
|
+
metadata,
|
|
48
|
+
description,
|
|
49
|
+
cause,
|
|
50
|
+
}: ErrorDetailInit) {
|
|
51
|
+
this.message = message ?? String(status);
|
|
52
|
+
this.status = status;
|
|
53
|
+
this.code = code;
|
|
54
|
+
this.description = description;
|
|
55
|
+
this.metadata = metadata;
|
|
56
|
+
this.cause = cause;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
with(o?: Partial<ErrorDetailInit> | string): DetailHolder {
|
|
60
|
+
if (typeof o === 'string') {
|
|
61
|
+
o = { message: o };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (o === undefined) {
|
|
65
|
+
return new DetailHolder(this);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return new DetailHolder({
|
|
69
|
+
status: this.status,
|
|
70
|
+
code: this.code,
|
|
71
|
+
message: this.message,
|
|
72
|
+
metadata: this.metadata,
|
|
73
|
+
cause: this.cause,
|
|
74
|
+
...o,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
asError(o?: Partial<ErrorDetailInit> | string): Error {
|
|
79
|
+
if (typeof o === 'string') {
|
|
80
|
+
o = { message: o };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return new DetailError(this.with(o));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
require(v: any, o?: Partial<ErrorDetailInit> | string): any {
|
|
87
|
+
if (v === undefined || v === null) {
|
|
88
|
+
throw this.asError(o);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return v;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
check(cond: any, o?: Partial<ErrorDetailInit> | string) {
|
|
95
|
+
switch (cond) {
|
|
96
|
+
case false:
|
|
97
|
+
case undefined:
|
|
98
|
+
case null: {
|
|
99
|
+
throw this.asError(o);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
throw(o?: string | Partial<ErrorDetailInit>): never {
|
|
105
|
+
throw this.asError(o);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
toJSON() {
|
|
109
|
+
return {
|
|
110
|
+
code: this.code,
|
|
111
|
+
message: this.message,
|
|
112
|
+
status: this.status,
|
|
113
|
+
description: this.description,
|
|
114
|
+
cause: this.cause,
|
|
115
|
+
metadata: this.metadata,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
asResponse(): Response {
|
|
120
|
+
return new Response(JSON.stringify(this.toJSON()), {
|
|
121
|
+
status: this.status,
|
|
122
|
+
statusText: this.description,
|
|
123
|
+
headers: { 'Content-Type': 'application/json' },
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export interface ErrorDetail {
|
|
129
|
+
readonly message: string;
|
|
130
|
+
readonly status: number;
|
|
131
|
+
readonly code?: number | string;
|
|
132
|
+
readonly metadata?: Record<string, any>;
|
|
133
|
+
readonly description?: string;
|
|
134
|
+
readonly cause?: any;
|
|
135
|
+
|
|
136
|
+
with(message: string): ErrorDetail;
|
|
137
|
+
|
|
138
|
+
with(o?: Partial<ErrorDetailInit>): ErrorDetail;
|
|
139
|
+
|
|
140
|
+
asError(o?: string | Partial<ErrorDetailInit>): Error;
|
|
141
|
+
|
|
142
|
+
asResponse(): Response;
|
|
143
|
+
|
|
144
|
+
throw(o?: string | Partial<ErrorDetailInit>): never;
|
|
145
|
+
|
|
146
|
+
require<T>(v: T | undefined, o?: Partial<ErrorDetailInit> | string): NonNullable<T>;
|
|
147
|
+
|
|
148
|
+
check(condition: boolean, o?: Partial<ErrorDetailInit> | string): asserts condition;
|
|
149
|
+
|
|
150
|
+
check<T>(v: T | undefined | null, o?: Partial<ErrorDetailInit> | string): asserts v is NonNullable<T>;
|
|
151
|
+
}
|
|
@@ -2,21 +2,21 @@ import { test } from 'vitest';
|
|
|
2
2
|
import { Errors } from './Errors';
|
|
3
3
|
|
|
4
4
|
test('Errors', () => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
5
|
+
{
|
|
6
|
+
let a: string | undefined = '';
|
|
7
|
+
Errors.NotFound.check(a);
|
|
8
|
+
let b: string = a;
|
|
9
|
+
hole(b);
|
|
10
|
+
}
|
|
11
|
+
if (false) {
|
|
12
|
+
// 不能同时 asserts 且返回
|
|
13
|
+
// https://stackoverflow.com/a/73252858/1870054
|
|
14
|
+
// https://github.com/microsoft/TypeScript/issues/34636
|
|
15
|
+
let a: string | undefined;
|
|
16
|
+
Errors.NotFound.require(a);
|
|
17
|
+
// let c: string = a;
|
|
18
|
+
// hole(c);
|
|
19
|
+
}
|
|
20
20
|
});
|
|
21
21
|
|
|
22
22
|
function hole(..._: any[]) {}
|
package/src/errors/Errors.ts
CHANGED
|
@@ -1,159 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DetailError, DetailHolder, type ErrorDetail, type ErrorDetailInit } from './DetailError';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
message?: string;
|
|
5
|
-
status: number;
|
|
6
|
-
description?: string;
|
|
7
|
-
code?: number | string;
|
|
8
|
-
metadata?: Record<string, any>;
|
|
9
|
-
cause?: any;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export class DetailError extends Error {
|
|
13
|
-
readonly status: number;
|
|
14
|
-
readonly description?: string;
|
|
15
|
-
|
|
16
|
-
constructor(readonly detail: ErrorDetail) {
|
|
17
|
-
super(detail.message, {
|
|
18
|
-
cause: detail.cause,
|
|
19
|
-
});
|
|
20
|
-
this.status = detail.status;
|
|
21
|
-
this.description = detail.description;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
toJSON() {
|
|
25
|
-
return {
|
|
26
|
-
code: this.detail.code,
|
|
27
|
-
message: this.message,
|
|
28
|
-
status: this.status,
|
|
29
|
-
description: this.description,
|
|
30
|
-
cause: this.cause,
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
class DetailHolder implements ErrorDetail {
|
|
36
|
-
readonly message: string;
|
|
37
|
-
readonly status: number;
|
|
38
|
-
readonly code: number | string;
|
|
39
|
-
readonly metadata?: Record<string, any>;
|
|
40
|
-
readonly description?: string;
|
|
41
|
-
readonly cause?: any;
|
|
42
|
-
|
|
43
|
-
constructor({
|
|
44
|
-
status,
|
|
45
|
-
message = getHttpStatusText(status),
|
|
46
|
-
code = status,
|
|
47
|
-
metadata,
|
|
48
|
-
description,
|
|
49
|
-
cause,
|
|
50
|
-
}: ErrorDetailInit) {
|
|
51
|
-
this.message = message ?? String(status);
|
|
52
|
-
this.status = status;
|
|
53
|
-
this.code = code;
|
|
54
|
-
this.description = description;
|
|
55
|
-
this.metadata = metadata;
|
|
56
|
-
this.cause = cause;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
with(o?: Partial<ErrorDetailInit> | string): DetailHolder {
|
|
60
|
-
if (typeof o === 'string') {
|
|
61
|
-
o = { message: o };
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (o === undefined) {
|
|
65
|
-
return new DetailHolder(this);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return new DetailHolder({
|
|
69
|
-
status: this.status,
|
|
70
|
-
code: this.code,
|
|
71
|
-
message: this.message,
|
|
72
|
-
metadata: this.metadata,
|
|
73
|
-
cause: this.cause,
|
|
74
|
-
...o,
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
asError(o?: Partial<ErrorDetailInit> | string): Error {
|
|
79
|
-
if (typeof o === 'string') {
|
|
80
|
-
o = { message: o };
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return new DetailError(this.with(o));
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
require(v: any, o?: Partial<ErrorDetailInit> | string): any {
|
|
87
|
-
if (v === undefined || v === null) {
|
|
88
|
-
throw this.asError(o);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return v;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
check(cond: any, o?: Partial<ErrorDetailInit> | string) {
|
|
95
|
-
switch (cond) {
|
|
96
|
-
case false:
|
|
97
|
-
case undefined:
|
|
98
|
-
case null: {
|
|
99
|
-
throw this.asError(o);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
throw(o?: string | Partial<ErrorDetailInit>): never {
|
|
105
|
-
throw this.asError(o);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
toJSON() {
|
|
109
|
-
return {
|
|
110
|
-
code: this.code,
|
|
111
|
-
message: this.message,
|
|
112
|
-
status: this.status,
|
|
113
|
-
description: this.description,
|
|
114
|
-
cause: this.cause,
|
|
115
|
-
metadata: this.metadata,
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
asResponse(): Response {
|
|
120
|
-
return new Response(JSON.stringify(this.toJSON()), {
|
|
121
|
-
status: this.status,
|
|
122
|
-
statusText: this.description,
|
|
123
|
-
headers: {
|
|
124
|
-
'Content-Type': 'application/json',
|
|
125
|
-
},
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export interface ErrorDetail {
|
|
131
|
-
readonly message: string;
|
|
132
|
-
readonly status: number;
|
|
133
|
-
readonly code?: number | string;
|
|
134
|
-
readonly metadata?: Record<string, any>;
|
|
135
|
-
readonly description?: string;
|
|
136
|
-
readonly cause?: any;
|
|
137
|
-
|
|
138
|
-
with(message: string): ErrorDetail;
|
|
139
|
-
|
|
140
|
-
with(o?: Partial<ErrorDetailInit>): ErrorDetail;
|
|
141
|
-
|
|
142
|
-
asError(o?: string | Partial<ErrorDetailInit>): Error;
|
|
143
|
-
|
|
144
|
-
asResponse(): Response;
|
|
145
|
-
|
|
146
|
-
throw(o?: string | Partial<ErrorDetailInit>): never;
|
|
147
|
-
|
|
148
|
-
require<T>(v: T | undefined, o?: Partial<ErrorDetailInit> | string): NonNullable<T>;
|
|
149
|
-
|
|
150
|
-
check(condition: boolean, o?: Partial<ErrorDetailInit> | string): asserts condition;
|
|
151
|
-
|
|
152
|
-
check<T>(v: T | undefined | null, o?: Partial<ErrorDetailInit> | string): asserts v is NonNullable<T>;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
export namespace Errors {
|
|
156
|
-
/*
|
|
3
|
+
/*
|
|
157
4
|
https://github.com/tc39/proposal-error-cause
|
|
158
5
|
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause
|
|
159
6
|
Stage 3
|
|
@@ -161,87 +8,99 @@ Chrome 93, Safari 15, Node 16.9
|
|
|
161
8
|
|
|
162
9
|
https://www.npmjs.com/package/pony-cause
|
|
163
10
|
*/
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
11
|
+
export namespace Errors {
|
|
12
|
+
export const BadRequest: ErrorDetail = create({ status: 400 });
|
|
13
|
+
export const Unauthorized: ErrorDetail = create({ status: 403 });
|
|
14
|
+
export const Forbidden: ErrorDetail = create({ status: 403 });
|
|
15
|
+
export const NotFound: ErrorDetail = create({ status: 404 });
|
|
16
|
+
export const InternalServerError: ErrorDetail = create({ status: 500 });
|
|
17
|
+
export const NotImplemented: ErrorDetail = create({ status: 501 });
|
|
18
|
+
export const BadGateway = create({ status: 502, message: 'Bad Gateway' });
|
|
19
|
+
export const ServiceUnavailable: ErrorDetail = create({ status: 503 });
|
|
20
|
+
|
|
21
|
+
export const IllegalState = create({ status: 500, message: 'Illegal State' });
|
|
22
|
+
export const UnsupportedOperation = create({ status: 500, message: 'Unsupported Operation' });
|
|
23
|
+
export const IllegalArgument = create({ status: 400, message: 'Illegal Argument' });
|
|
24
|
+
export const InvalidType = create({ status: 400, message: 'Invalid Type' });
|
|
25
|
+
|
|
26
|
+
// known errors
|
|
27
|
+
// TypeError when an operation could not be performed, typically (but not exclusively) when a value is not of the expected type.
|
|
28
|
+
// RangeError when a number is not within the correct range allowed.
|
|
29
|
+
// AggregateError when multiple errors need to be reported by an operation, for example by Promise.all().
|
|
30
|
+
// 例如 Promise.any() 会返回一个 AggregateError,其中包含所有 rejected 的 Promise 的错误。
|
|
31
|
+
// EvalError when an error occurs during the evaluation of JavaScript code.
|
|
32
|
+
// ReferenceError when a non-existent variable is referenced.
|
|
33
|
+
// SyntaxError when a syntax error occurs while parsing code in eval().
|
|
34
|
+
// URIError when encodeURI() or decodeURI() are passed invalid parameters.
|
|
35
|
+
// InternalError when an internal error in the JavaScript engine is thrown. E.g. "too much recursion".
|
|
36
|
+
// DOMException when an error occurs in the DOM.
|
|
37
|
+
|
|
38
|
+
export const resolvers: ((e: any) => ErrorDetail | void)[] = [];
|
|
39
|
+
|
|
40
|
+
export function create(init: ErrorDetailInit): ErrorDetail {
|
|
41
|
+
return new DetailHolder(init);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function ok(res: Response, o?: Partial<ErrorDetailInit>) {
|
|
45
|
+
if (res.ok) {
|
|
46
|
+
return res;
|
|
47
|
+
}
|
|
48
|
+
throw create({
|
|
49
|
+
description: res.statusText,
|
|
50
|
+
status: res.status,
|
|
51
|
+
...o,
|
|
52
|
+
metadata: { ...o?.metadata, response: res },
|
|
53
|
+
}).asError();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function resolve(e: any): ErrorDetail {
|
|
57
|
+
if (e instanceof DetailHolder) {
|
|
58
|
+
return e;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (e instanceof DetailError) {
|
|
62
|
+
return e.detail;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
for (const resolver of resolvers) {
|
|
66
|
+
const r = resolver(e);
|
|
67
|
+
if (r) {
|
|
68
|
+
return r;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (isError(e)) {
|
|
73
|
+
const { message, code, status } = e as any;
|
|
74
|
+
// can get status from NestJS HttpException
|
|
75
|
+
return new DetailHolder({ message, status: parseInt(status) || 500, code, cause: e });
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return new DetailHolder({ message: e.message, status: 500, cause: e });
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Check if the given value is an Error
|
|
83
|
+
* @see https://github.com/tc39/proposal-is-error
|
|
84
|
+
*/
|
|
85
|
+
export function isError(e: any): e is Error {
|
|
86
|
+
if ('isError' in Error) {
|
|
87
|
+
// will handle cross-realm
|
|
88
|
+
return (Error as any).isError(e);
|
|
89
|
+
}
|
|
90
|
+
return e instanceof Error;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function isAbort(e: any): e is Error {
|
|
94
|
+
if (!isError(e)) {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
return e.name === 'AbortError';
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function isTimeout(e: any): e is Error {
|
|
101
|
+
if (!isError(e)) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
return e.name === 'TimeoutError' || e.name === 'Timeout';
|
|
105
|
+
}
|
|
239
106
|
}
|
|
240
|
-
|
|
241
|
-
// interface ZodError {
|
|
242
|
-
// path: Array<string | number>;
|
|
243
|
-
// message: string;
|
|
244
|
-
// code: string;
|
|
245
|
-
// expected?: any;
|
|
246
|
-
// received?: any;
|
|
247
|
-
// }
|