@wener/utils 1.1.51 → 1.1.53
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 +2 -202
- package/lib/errors/Errors.mod.js +206 -0
- 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 +74 -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 +2 -334
- package/lib/io/ArrayBuffers.mod.js +531 -0
- 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/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.mod.ts +104 -0
- package/src/errors/Errors.test.ts +15 -15
- package/src/errors/Errors.ts +1 -247
- 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 +17 -19
- 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.mod.ts +670 -0
- package/src/io/ArrayBuffers.test.ts +14 -14
- package/src/io/ArrayBuffers.ts +1 -446
- 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/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 +35 -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,297 @@
|
|
|
1
|
+
function _assert_this_initialized(self) {
|
|
2
|
+
if (self === void 0) {
|
|
3
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
4
|
+
}
|
|
5
|
+
return self;
|
|
6
|
+
}
|
|
7
|
+
function _call_super(_this, derived, args) {
|
|
8
|
+
derived = _get_prototype_of(derived);
|
|
9
|
+
return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
|
|
10
|
+
}
|
|
11
|
+
function _class_call_check(instance, Constructor) {
|
|
12
|
+
if (!(instance instanceof Constructor)) {
|
|
13
|
+
throw new TypeError("Cannot call a class as a function");
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function _construct(Parent, args, Class) {
|
|
17
|
+
if (_is_native_reflect_construct()) {
|
|
18
|
+
_construct = Reflect.construct;
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
_construct = function construct(Parent, args, Class) {
|
|
22
|
+
var a = [
|
|
23
|
+
null
|
|
24
|
+
];
|
|
25
|
+
a.push.apply(a, args);
|
|
26
|
+
var Constructor = Function.bind.apply(Parent, a);
|
|
27
|
+
var instance = new Constructor();
|
|
28
|
+
if (Class)
|
|
29
|
+
_set_prototype_of(instance, Class.prototype);
|
|
30
|
+
return instance;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
return _construct.apply(null, arguments);
|
|
34
|
+
}
|
|
35
|
+
function _defineProperties(target, props) {
|
|
36
|
+
for (var i = 0; i < props.length; i++) {
|
|
37
|
+
var descriptor = props[i];
|
|
38
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
39
|
+
descriptor.configurable = true;
|
|
40
|
+
if ("value" in descriptor)
|
|
41
|
+
descriptor.writable = true;
|
|
42
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
46
|
+
if (protoProps)
|
|
47
|
+
_defineProperties(Constructor.prototype, protoProps);
|
|
48
|
+
if (staticProps)
|
|
49
|
+
_defineProperties(Constructor, staticProps);
|
|
50
|
+
return Constructor;
|
|
51
|
+
}
|
|
52
|
+
function _define_property(obj, key, value) {
|
|
53
|
+
if (key in obj) {
|
|
54
|
+
Object.defineProperty(obj, key, {
|
|
55
|
+
value: value,
|
|
56
|
+
enumerable: true,
|
|
57
|
+
configurable: true,
|
|
58
|
+
writable: true
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
obj[key] = value;
|
|
63
|
+
}
|
|
64
|
+
return obj;
|
|
65
|
+
}
|
|
66
|
+
function _get_prototype_of(o) {
|
|
67
|
+
_get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
|
|
68
|
+
return o.__proto__ || Object.getPrototypeOf(o);
|
|
69
|
+
};
|
|
70
|
+
return _get_prototype_of(o);
|
|
71
|
+
}
|
|
72
|
+
function _inherits(subClass, superClass) {
|
|
73
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
74
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
75
|
+
}
|
|
76
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
77
|
+
constructor: {
|
|
78
|
+
value: subClass,
|
|
79
|
+
writable: true,
|
|
80
|
+
configurable: true
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
if (superClass)
|
|
84
|
+
_set_prototype_of(subClass, superClass);
|
|
85
|
+
}
|
|
86
|
+
function _is_native_function(fn) {
|
|
87
|
+
return Function.toString.call(fn).indexOf("[native code]") !== -1;
|
|
88
|
+
}
|
|
89
|
+
function _object_spread(target) {
|
|
90
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
91
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
92
|
+
var ownKeys = Object.keys(source);
|
|
93
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
94
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
|
|
95
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
96
|
+
}));
|
|
97
|
+
}
|
|
98
|
+
ownKeys.forEach(function (key) {
|
|
99
|
+
_define_property(target, key, source[key]);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
return target;
|
|
103
|
+
}
|
|
104
|
+
function _possible_constructor_return(self, call) {
|
|
105
|
+
if (call && (_type_of(call) === "object" || typeof call === "function")) {
|
|
106
|
+
return call;
|
|
107
|
+
}
|
|
108
|
+
return _assert_this_initialized(self);
|
|
109
|
+
}
|
|
110
|
+
function _set_prototype_of(o, p) {
|
|
111
|
+
_set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
|
|
112
|
+
o.__proto__ = p;
|
|
113
|
+
return o;
|
|
114
|
+
};
|
|
115
|
+
return _set_prototype_of(o, p);
|
|
116
|
+
}
|
|
117
|
+
function _type_of(obj) {
|
|
118
|
+
"@swc/helpers - typeof";
|
|
119
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
120
|
+
}
|
|
121
|
+
function _wrap_native_super(Class) {
|
|
122
|
+
var _cache = typeof Map === "function" ? new Map() : undefined;
|
|
123
|
+
_wrap_native_super = function wrapNativeSuper(Class) {
|
|
124
|
+
if (Class === null || !_is_native_function(Class))
|
|
125
|
+
return Class;
|
|
126
|
+
if (typeof Class !== "function") {
|
|
127
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
128
|
+
}
|
|
129
|
+
if (typeof _cache !== "undefined") {
|
|
130
|
+
if (_cache.has(Class))
|
|
131
|
+
return _cache.get(Class);
|
|
132
|
+
_cache.set(Class, Wrapper);
|
|
133
|
+
}
|
|
134
|
+
function Wrapper() {
|
|
135
|
+
return _construct(Class, arguments, _get_prototype_of(this).constructor);
|
|
136
|
+
}
|
|
137
|
+
Wrapper.prototype = Object.create(Class.prototype, {
|
|
138
|
+
constructor: {
|
|
139
|
+
value: Wrapper,
|
|
140
|
+
enumerable: false,
|
|
141
|
+
writable: true,
|
|
142
|
+
configurable: true
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
return _set_prototype_of(Wrapper, Class);
|
|
146
|
+
};
|
|
147
|
+
return _wrap_native_super(Class);
|
|
148
|
+
}
|
|
149
|
+
function _is_native_reflect_construct() {
|
|
150
|
+
try {
|
|
151
|
+
var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () { }));
|
|
152
|
+
}
|
|
153
|
+
catch (_) { }
|
|
154
|
+
return (_is_native_reflect_construct = function () {
|
|
155
|
+
return !!result;
|
|
156
|
+
})();
|
|
157
|
+
}
|
|
158
|
+
import { getHttpStatusText } from "../fetch/HttpStatus.js";
|
|
159
|
+
export var DetailError = /*#__PURE__*/ function (Error1) {
|
|
160
|
+
"use strict";
|
|
161
|
+
_inherits(DetailError, Error1);
|
|
162
|
+
function DetailError(detail) {
|
|
163
|
+
_class_call_check(this, DetailError);
|
|
164
|
+
var _this;
|
|
165
|
+
_this = _call_super(this, DetailError, [
|
|
166
|
+
detail.message,
|
|
167
|
+
{
|
|
168
|
+
cause: detail.cause
|
|
169
|
+
}
|
|
170
|
+
]), _define_property(_this, "detail", void 0), _define_property(_this, "status", void 0), _define_property(_this, "description", void 0);
|
|
171
|
+
_this.detail = detail;
|
|
172
|
+
_this.status = detail.status;
|
|
173
|
+
_this.description = detail.description;
|
|
174
|
+
return _this;
|
|
175
|
+
}
|
|
176
|
+
_create_class(DetailError, [
|
|
177
|
+
{
|
|
178
|
+
key: "toJSON",
|
|
179
|
+
value: function toJSON() {
|
|
180
|
+
return {
|
|
181
|
+
code: this.detail.code,
|
|
182
|
+
message: this.message,
|
|
183
|
+
status: this.status,
|
|
184
|
+
description: this.description,
|
|
185
|
+
cause: this.cause
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
]);
|
|
190
|
+
return DetailError;
|
|
191
|
+
}(_wrap_native_super(Error));
|
|
192
|
+
export var DetailHolder = /*#__PURE__*/ function () {
|
|
193
|
+
"use strict";
|
|
194
|
+
function DetailHolder(param) {
|
|
195
|
+
var status = param.status, _param_message = param.message, message = _param_message === void 0 ? getHttpStatusText(status) : _param_message, _param_code = param.code, code = _param_code === void 0 ? status : _param_code, metadata = param.metadata, description = param.description, cause = param.cause;
|
|
196
|
+
_class_call_check(this, DetailHolder);
|
|
197
|
+
_define_property(this, "message", void 0);
|
|
198
|
+
_define_property(this, "status", void 0);
|
|
199
|
+
_define_property(this, "code", void 0);
|
|
200
|
+
_define_property(this, "metadata", void 0);
|
|
201
|
+
_define_property(this, "description", void 0);
|
|
202
|
+
_define_property(this, "cause", void 0);
|
|
203
|
+
this.message = message !== null && message !== void 0 ? message : String(status);
|
|
204
|
+
this.status = status;
|
|
205
|
+
this.code = code;
|
|
206
|
+
this.description = description;
|
|
207
|
+
this.metadata = metadata;
|
|
208
|
+
this.cause = cause;
|
|
209
|
+
}
|
|
210
|
+
_create_class(DetailHolder, [
|
|
211
|
+
{
|
|
212
|
+
key: "with",
|
|
213
|
+
value: function _with(o) {
|
|
214
|
+
if (typeof o === "string") {
|
|
215
|
+
o = {
|
|
216
|
+
message: o
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
if (o === undefined) {
|
|
220
|
+
return new DetailHolder(this);
|
|
221
|
+
}
|
|
222
|
+
return new DetailHolder(_object_spread({
|
|
223
|
+
status: this.status,
|
|
224
|
+
code: this.code,
|
|
225
|
+
message: this.message,
|
|
226
|
+
metadata: this.metadata,
|
|
227
|
+
cause: this.cause
|
|
228
|
+
}, o));
|
|
229
|
+
}
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
key: "asError",
|
|
233
|
+
value: function asError(o) {
|
|
234
|
+
if (typeof o === "string") {
|
|
235
|
+
o = {
|
|
236
|
+
message: o
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
return new DetailError(this.with(o));
|
|
240
|
+
}
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
key: "require",
|
|
244
|
+
value: function require(v, o) {
|
|
245
|
+
if (v === undefined || v === null) {
|
|
246
|
+
throw this.asError(o);
|
|
247
|
+
}
|
|
248
|
+
return v;
|
|
249
|
+
}
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
key: "check",
|
|
253
|
+
value: function check(cond, o) {
|
|
254
|
+
switch (cond) {
|
|
255
|
+
case false:
|
|
256
|
+
case undefined:
|
|
257
|
+
case null:
|
|
258
|
+
{
|
|
259
|
+
throw this.asError(o);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
key: "throw",
|
|
266
|
+
value: function _throw(o) {
|
|
267
|
+
throw this.asError(o);
|
|
268
|
+
}
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
key: "toJSON",
|
|
272
|
+
value: function toJSON() {
|
|
273
|
+
return {
|
|
274
|
+
code: this.code,
|
|
275
|
+
message: this.message,
|
|
276
|
+
status: this.status,
|
|
277
|
+
description: this.description,
|
|
278
|
+
cause: this.cause,
|
|
279
|
+
metadata: this.metadata
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
},
|
|
283
|
+
{
|
|
284
|
+
key: "asResponse",
|
|
285
|
+
value: function asResponse() {
|
|
286
|
+
return new Response(JSON.stringify(this.toJSON()), {
|
|
287
|
+
status: this.status,
|
|
288
|
+
statusText: this.description,
|
|
289
|
+
headers: {
|
|
290
|
+
"Content-Type": "application/json"
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
]);
|
|
296
|
+
return DetailHolder;
|
|
297
|
+
}();
|
package/lib/errors/Errors.js
CHANGED
|
@@ -1,202 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
export
|
|
3
|
-
detail;
|
|
4
|
-
status;
|
|
5
|
-
description;
|
|
6
|
-
constructor(detail){
|
|
7
|
-
super(detail.message, {
|
|
8
|
-
cause: detail.cause
|
|
9
|
-
}), this.detail = detail;
|
|
10
|
-
this.status = detail.status;
|
|
11
|
-
this.description = detail.description;
|
|
12
|
-
}
|
|
13
|
-
toJSON() {
|
|
14
|
-
return {
|
|
15
|
-
code: this.detail.code,
|
|
16
|
-
message: this.message,
|
|
17
|
-
status: this.status,
|
|
18
|
-
description: this.description,
|
|
19
|
-
cause: this.cause
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
let DetailHolder = class DetailHolder {
|
|
24
|
-
message;
|
|
25
|
-
status;
|
|
26
|
-
code;
|
|
27
|
-
metadata;
|
|
28
|
-
description;
|
|
29
|
-
cause;
|
|
30
|
-
constructor({ status, message = getHttpStatusText(status), code = status, metadata, description, cause }){
|
|
31
|
-
this.message = message ?? String(status);
|
|
32
|
-
this.status = status;
|
|
33
|
-
this.code = code;
|
|
34
|
-
this.description = description;
|
|
35
|
-
this.metadata = metadata;
|
|
36
|
-
this.cause = cause;
|
|
37
|
-
}
|
|
38
|
-
with(o) {
|
|
39
|
-
if (typeof o === 'string') {
|
|
40
|
-
o = {
|
|
41
|
-
message: o
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
if (o === undefined) {
|
|
45
|
-
return new DetailHolder(this);
|
|
46
|
-
}
|
|
47
|
-
return new DetailHolder({
|
|
48
|
-
status: this.status,
|
|
49
|
-
code: this.code,
|
|
50
|
-
message: this.message,
|
|
51
|
-
metadata: this.metadata,
|
|
52
|
-
cause: this.cause,
|
|
53
|
-
...o
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
asError(o) {
|
|
57
|
-
if (typeof o === 'string') {
|
|
58
|
-
o = {
|
|
59
|
-
message: o
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
return new DetailError(this.with(o));
|
|
63
|
-
}
|
|
64
|
-
require(v, o) {
|
|
65
|
-
if (v === undefined || v === null) {
|
|
66
|
-
throw this.asError(o);
|
|
67
|
-
}
|
|
68
|
-
return v;
|
|
69
|
-
}
|
|
70
|
-
check(cond, o) {
|
|
71
|
-
switch(cond){
|
|
72
|
-
case false:
|
|
73
|
-
case undefined:
|
|
74
|
-
case null:
|
|
75
|
-
{
|
|
76
|
-
throw this.asError(o);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
throw(o) {
|
|
81
|
-
throw this.asError(o);
|
|
82
|
-
}
|
|
83
|
-
toJSON() {
|
|
84
|
-
return {
|
|
85
|
-
code: this.code,
|
|
86
|
-
message: this.message,
|
|
87
|
-
status: this.status,
|
|
88
|
-
description: this.description,
|
|
89
|
-
cause: this.cause,
|
|
90
|
-
metadata: this.metadata
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
asResponse() {
|
|
94
|
-
return new Response(JSON.stringify(this.toJSON()), {
|
|
95
|
-
status: this.status,
|
|
96
|
-
statusText: this.description,
|
|
97
|
-
headers: {
|
|
98
|
-
'Content-Type': 'application/json'
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
export var Errors;
|
|
104
|
-
(function(Errors) {
|
|
105
|
-
/*
|
|
106
|
-
https://github.com/tc39/proposal-error-cause
|
|
107
|
-
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause
|
|
108
|
-
Stage 3
|
|
109
|
-
Chrome 93, Safari 15, Node 16.9
|
|
110
|
-
|
|
111
|
-
https://www.npmjs.com/package/pony-cause
|
|
112
|
-
*/ Errors.BadRequest = create({
|
|
113
|
-
status: 400
|
|
114
|
-
});
|
|
115
|
-
Errors.Unauthorized = create({
|
|
116
|
-
status: 403
|
|
117
|
-
});
|
|
118
|
-
Errors.Forbidden = create({
|
|
119
|
-
status: 403
|
|
120
|
-
});
|
|
121
|
-
Errors.NotFound = create({
|
|
122
|
-
status: 404
|
|
123
|
-
});
|
|
124
|
-
Errors.InternalServerError = create({
|
|
125
|
-
status: 500
|
|
126
|
-
});
|
|
127
|
-
Errors.NotImplemented = create({
|
|
128
|
-
status: 501
|
|
129
|
-
});
|
|
130
|
-
Errors.ServiceUnavailable = create({
|
|
131
|
-
status: 503
|
|
132
|
-
});
|
|
133
|
-
// known errors
|
|
134
|
-
// TypeError when an operation could not be performed, typically (but not exclusively) when a value is not of the expected type.
|
|
135
|
-
// RangeError when a number is not within the correct range allowed.
|
|
136
|
-
// AggregateError when multiple errors need to be reported by an operation, for example by Promise.all().
|
|
137
|
-
// 例如 Promise.any() 会返回一个 AggregateError,其中包含所有 rejected 的 Promise 的错误。
|
|
138
|
-
// EvalError when an error occurs during the evaluation of JavaScript code.
|
|
139
|
-
// ReferenceError when a non-existent variable is referenced.
|
|
140
|
-
// SyntaxError when a syntax error occurs while parsing code in eval().
|
|
141
|
-
// URIError when encodeURI() or decodeURI() are passed invalid parameters.
|
|
142
|
-
// InternalError when an internal error in the JavaScript engine is thrown. E.g. "too much recursion".
|
|
143
|
-
// DOMException when an error occurs in the DOM.
|
|
144
|
-
Errors.resolvers = [];
|
|
145
|
-
function create(init) {
|
|
146
|
-
return new DetailHolder(init);
|
|
147
|
-
}
|
|
148
|
-
Errors.create = create;
|
|
149
|
-
function ok(res, o) {
|
|
150
|
-
if (res.ok) {
|
|
151
|
-
return res;
|
|
152
|
-
}
|
|
153
|
-
throw create({
|
|
154
|
-
description: res.statusText,
|
|
155
|
-
status: res.status,
|
|
156
|
-
...o,
|
|
157
|
-
metadata: {
|
|
158
|
-
...o?.metadata,
|
|
159
|
-
response: res
|
|
160
|
-
}
|
|
161
|
-
}).asError();
|
|
162
|
-
}
|
|
163
|
-
Errors.ok = ok;
|
|
164
|
-
function resolve(e) {
|
|
165
|
-
if (e instanceof DetailHolder) {
|
|
166
|
-
return e;
|
|
167
|
-
}
|
|
168
|
-
if (e instanceof DetailError) {
|
|
169
|
-
return e.detail;
|
|
170
|
-
}
|
|
171
|
-
for (const resolver of Errors.resolvers){
|
|
172
|
-
const r = resolver(e);
|
|
173
|
-
if (r) {
|
|
174
|
-
return r;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
if (e instanceof Error) {
|
|
178
|
-
const { message, code, status } = e;
|
|
179
|
-
// can get status from NestJS HttpException
|
|
180
|
-
return new DetailHolder({
|
|
181
|
-
message,
|
|
182
|
-
status: parseInt(status) || 500,
|
|
183
|
-
code,
|
|
184
|
-
cause: e
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
return new DetailHolder({
|
|
188
|
-
message: e.message,
|
|
189
|
-
status: 500,
|
|
190
|
-
cause: e
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
Errors.resolve = resolve;
|
|
194
|
-
})(Errors || (Errors = {})); // interface ZodError {
|
|
195
|
-
// path: Array<string | number>;
|
|
196
|
-
// message: string;
|
|
197
|
-
// code: string;
|
|
198
|
-
// expected?: any;
|
|
199
|
-
// received?: any;
|
|
200
|
-
// }
|
|
201
|
-
|
|
202
|
-
//# sourceMappingURL=Errors.js.map
|
|
1
|
+
import * as _Errors from "./Errors.mod.js";
|
|
2
|
+
export { _Errors as Errors };
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
function _define_property(obj, key, value) {
|
|
2
|
+
if (key in obj) {
|
|
3
|
+
Object.defineProperty(obj, key, {
|
|
4
|
+
value: value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
obj[key] = value;
|
|
12
|
+
}
|
|
13
|
+
return obj;
|
|
14
|
+
}
|
|
15
|
+
function _instanceof(left, right) {
|
|
16
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
17
|
+
return !!right[Symbol.hasInstance](left);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
return left instanceof right;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function _object_spread(target) {
|
|
24
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
25
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
26
|
+
var ownKeys = Object.keys(source);
|
|
27
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
28
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
|
|
29
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
30
|
+
}));
|
|
31
|
+
}
|
|
32
|
+
ownKeys.forEach(function (key) {
|
|
33
|
+
_define_property(target, key, source[key]);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
return target;
|
|
37
|
+
}
|
|
38
|
+
function ownKeys(object, enumerableOnly) {
|
|
39
|
+
var keys = Object.keys(object);
|
|
40
|
+
if (Object.getOwnPropertySymbols) {
|
|
41
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
42
|
+
if (enumerableOnly) {
|
|
43
|
+
symbols = symbols.filter(function (sym) {
|
|
44
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
keys.push.apply(keys, symbols);
|
|
48
|
+
}
|
|
49
|
+
return keys;
|
|
50
|
+
}
|
|
51
|
+
function _object_spread_props(target, source) {
|
|
52
|
+
source = source != null ? source : {};
|
|
53
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
54
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
ownKeys(Object(source)).forEach(function (key) {
|
|
58
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
return target;
|
|
62
|
+
}
|
|
63
|
+
import { DetailError, DetailHolder } from "./DetailError.js";
|
|
64
|
+
/*
|
|
65
|
+
https://github.com/tc39/proposal-error-cause
|
|
66
|
+
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause
|
|
67
|
+
Stage 3
|
|
68
|
+
Chrome 93, Safari 15, Node 16.9
|
|
69
|
+
|
|
70
|
+
https://www.npmjs.com/package/pony-cause
|
|
71
|
+
*/ export var BadRequest = create({
|
|
72
|
+
status: 400
|
|
73
|
+
});
|
|
74
|
+
export var Unauthorized = create({
|
|
75
|
+
status: 403
|
|
76
|
+
});
|
|
77
|
+
export var Forbidden = create({
|
|
78
|
+
status: 403
|
|
79
|
+
});
|
|
80
|
+
export var NotFound = create({
|
|
81
|
+
status: 404
|
|
82
|
+
});
|
|
83
|
+
export var InternalServerError = create({
|
|
84
|
+
status: 500
|
|
85
|
+
});
|
|
86
|
+
export var NotImplemented = create({
|
|
87
|
+
status: 501
|
|
88
|
+
});
|
|
89
|
+
export var ServiceUnavailable = create({
|
|
90
|
+
status: 503
|
|
91
|
+
});
|
|
92
|
+
export var IllegalState = create({
|
|
93
|
+
status: 500,
|
|
94
|
+
message: "Illegal State"
|
|
95
|
+
});
|
|
96
|
+
export var UnsupportedOperation = create({
|
|
97
|
+
status: 500,
|
|
98
|
+
message: "Unsupported Operation"
|
|
99
|
+
});
|
|
100
|
+
export var IllegalArgument = create({
|
|
101
|
+
status: 400,
|
|
102
|
+
message: "Illegal Argument"
|
|
103
|
+
});
|
|
104
|
+
export var InvalidType = create({
|
|
105
|
+
status: 400,
|
|
106
|
+
message: "Invalid Type"
|
|
107
|
+
});
|
|
108
|
+
// known errors
|
|
109
|
+
// TypeError when an operation could not be performed, typically (but not exclusively) when a value is not of the expected type.
|
|
110
|
+
// RangeError when a number is not within the correct range allowed.
|
|
111
|
+
// AggregateError when multiple errors need to be reported by an operation, for example by Promise.all().
|
|
112
|
+
// 例如 Promise.any() 会返回一个 AggregateError,其中包含所有 rejected 的 Promise 的错误。
|
|
113
|
+
// EvalError when an error occurs during the evaluation of JavaScript code.
|
|
114
|
+
// ReferenceError when a non-existent variable is referenced.
|
|
115
|
+
// SyntaxError when a syntax error occurs while parsing code in eval().
|
|
116
|
+
// URIError when encodeURI() or decodeURI() are passed invalid parameters.
|
|
117
|
+
// InternalError when an internal error in the JavaScript engine is thrown. E.g. "too much recursion".
|
|
118
|
+
// DOMException when an error occurs in the DOM.
|
|
119
|
+
export var resolvers = [];
|
|
120
|
+
export function create(init) {
|
|
121
|
+
return new DetailHolder(init);
|
|
122
|
+
}
|
|
123
|
+
export function ok(res, o) {
|
|
124
|
+
if (res.ok) {
|
|
125
|
+
return res;
|
|
126
|
+
}
|
|
127
|
+
throw create(_object_spread_props(_object_spread({
|
|
128
|
+
description: res.statusText,
|
|
129
|
+
status: res.status
|
|
130
|
+
}, o), {
|
|
131
|
+
metadata: _object_spread_props(_object_spread({}, o === null || o === void 0 ? void 0 : o.metadata), {
|
|
132
|
+
response: res
|
|
133
|
+
})
|
|
134
|
+
})).asError();
|
|
135
|
+
}
|
|
136
|
+
export function resolve(e) {
|
|
137
|
+
if (_instanceof(e, DetailHolder)) {
|
|
138
|
+
return e;
|
|
139
|
+
}
|
|
140
|
+
if (_instanceof(e, DetailError)) {
|
|
141
|
+
return e.detail;
|
|
142
|
+
}
|
|
143
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
144
|
+
try {
|
|
145
|
+
for (var _iterator = resolvers[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
146
|
+
var resolver = _step.value;
|
|
147
|
+
var r = resolver(e);
|
|
148
|
+
if (r) {
|
|
149
|
+
return r;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
catch (err) {
|
|
154
|
+
_didIteratorError = true;
|
|
155
|
+
_iteratorError = err;
|
|
156
|
+
}
|
|
157
|
+
finally {
|
|
158
|
+
try {
|
|
159
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
160
|
+
_iterator.return();
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
finally {
|
|
164
|
+
if (_didIteratorError) {
|
|
165
|
+
throw _iteratorError;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
if (isError(e)) {
|
|
170
|
+
var message = e.message, code = e.code, status = e.status;
|
|
171
|
+
// can get status from NestJS HttpException
|
|
172
|
+
return new DetailHolder({
|
|
173
|
+
message: message,
|
|
174
|
+
status: parseInt(status) || 500,
|
|
175
|
+
code: code,
|
|
176
|
+
cause: e
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
return new DetailHolder({
|
|
180
|
+
message: e.message,
|
|
181
|
+
status: 500,
|
|
182
|
+
cause: e
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Check if the given value is an Error
|
|
187
|
+
* @see https://github.com/tc39/proposal-is-error
|
|
188
|
+
*/ export function isError(e) {
|
|
189
|
+
if ("isError" in Error) {
|
|
190
|
+
// will handle cross-realm
|
|
191
|
+
return Error.isError(e);
|
|
192
|
+
}
|
|
193
|
+
return _instanceof(e, Error);
|
|
194
|
+
}
|
|
195
|
+
export function isAbort(e) {
|
|
196
|
+
if (!isError(e)) {
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
return e.name === "AbortError";
|
|
200
|
+
}
|
|
201
|
+
export function isTimeout(e) {
|
|
202
|
+
if (!isError(e)) {
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
return e.name === "TimeoutError" || e.name === "Timeout";
|
|
206
|
+
}
|