modern-ts 0.8.0
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/LICENSE +201 -0
- package/README.md +223 -0
- package/README.zh-CN.md +223 -0
- package/dist/chunks/Errors-BWEYu-AB.cjs +2 -0
- package/dist/chunks/Errors-BWEYu-AB.cjs.map +1 -0
- package/dist/chunks/Errors-DwUAvFIF.mjs +63 -0
- package/dist/chunks/Errors-DwUAvFIF.mjs.map +1 -0
- package/dist/chunks/Math-CGEH1ClN.mjs +68 -0
- package/dist/chunks/Math-CGEH1ClN.mjs.map +1 -0
- package/dist/chunks/Math-CWZVxSF-.cjs +2 -0
- package/dist/chunks/Math-CWZVxSF-.cjs.map +1 -0
- package/dist/chunks/base-B9k8Lqvf.mjs +56 -0
- package/dist/chunks/base-B9k8Lqvf.mjs.map +1 -0
- package/dist/chunks/base-BTXL1y_I.cjs +2 -0
- package/dist/chunks/base-BTXL1y_I.cjs.map +1 -0
- package/dist/chunks/base-BpECeKwU.mjs +19 -0
- package/dist/chunks/base-BpECeKwU.mjs.map +1 -0
- package/dist/chunks/base-BvHqpP_s.cjs +2 -0
- package/dist/chunks/base-BvHqpP_s.cjs.map +1 -0
- package/dist/chunks/base-K-RHLZ-S.mjs +46 -0
- package/dist/chunks/base-K-RHLZ-S.mjs.map +1 -0
- package/dist/chunks/base-r6kn0B0D.cjs +2 -0
- package/dist/chunks/base-r6kn0B0D.cjs.map +1 -0
- package/dist/chunks/combine-async-DcG-3p8i.cjs +2 -0
- package/dist/chunks/combine-async-DcG-3p8i.cjs.map +1 -0
- package/dist/chunks/combine-async-Dcg4ya1R.mjs +236 -0
- package/dist/chunks/combine-async-Dcg4ya1R.mjs.map +1 -0
- package/dist/chunks/delay-CG3cD7bk.cjs +2 -0
- package/dist/chunks/delay-CG3cD7bk.cjs.map +1 -0
- package/dist/chunks/delay-CKIXpP71.mjs +32 -0
- package/dist/chunks/delay-CKIXpP71.mjs.map +1 -0
- package/dist/chunks/helper-BVabbpmX.mjs +165 -0
- package/dist/chunks/helper-BVabbpmX.mjs.map +1 -0
- package/dist/chunks/helper-tsqZMRHW.cjs +3 -0
- package/dist/chunks/helper-tsqZMRHW.cjs.map +1 -0
- package/dist/chunks/local-8JVtLN0O.mjs +10 -0
- package/dist/chunks/local-8JVtLN0O.mjs.map +1 -0
- package/dist/chunks/local-Da4yU-nE.cjs +2 -0
- package/dist/chunks/local-Da4yU-nE.cjs.map +1 -0
- package/dist/chunks/types-B7X_LBjM.cjs +2 -0
- package/dist/chunks/types-B7X_LBjM.cjs.map +1 -0
- package/dist/chunks/types-DE2SnSbz.mjs +5 -0
- package/dist/chunks/types-DE2SnSbz.mjs.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.mjs +759 -0
- package/dist/index.mjs.map +1 -0
- package/dist/subpath/Arr.cjs +2 -0
- package/dist/subpath/Arr.cjs.map +1 -0
- package/dist/subpath/Arr.mjs +539 -0
- package/dist/subpath/Arr.mjs.map +1 -0
- package/dist/subpath/Concurrent.cjs +15 -0
- package/dist/subpath/Concurrent.cjs.map +1 -0
- package/dist/subpath/Concurrent.mjs +4044 -0
- package/dist/subpath/Concurrent.mjs.map +1 -0
- package/dist/subpath/FetchQ.cjs +2 -0
- package/dist/subpath/FetchQ.cjs.map +1 -0
- package/dist/subpath/FetchQ.mjs +519 -0
- package/dist/subpath/FetchQ.mjs.map +1 -0
- package/dist/subpath/Fit.cjs +2 -0
- package/dist/subpath/Fit.cjs.map +1 -0
- package/dist/subpath/Fit.mjs +914 -0
- package/dist/subpath/Fit.mjs.map +1 -0
- package/dist/subpath/Lazy.cjs +2 -0
- package/dist/subpath/Lazy.cjs.map +1 -0
- package/dist/subpath/Lazy.mjs +72 -0
- package/dist/subpath/Lazy.mjs.map +1 -0
- package/dist/subpath/Maps.cjs +2 -0
- package/dist/subpath/Maps.cjs.map +1 -0
- package/dist/subpath/Maps.mjs +123 -0
- package/dist/subpath/Maps.mjs.map +1 -0
- package/dist/subpath/Maybe.cjs +2 -0
- package/dist/subpath/Maybe.cjs.map +1 -0
- package/dist/subpath/Maybe.mjs +329 -0
- package/dist/subpath/Maybe.mjs.map +1 -0
- package/dist/subpath/Reactive.cjs +2 -0
- package/dist/subpath/Reactive.cjs.map +1 -0
- package/dist/subpath/Reactive.mjs +1204 -0
- package/dist/subpath/Reactive.mjs.map +1 -0
- package/dist/subpath/Reader.cjs +2 -0
- package/dist/subpath/Reader.cjs.map +1 -0
- package/dist/subpath/Reader.mjs +75 -0
- package/dist/subpath/Reader.mjs.map +1 -0
- package/dist/subpath/ReaderT.cjs +2 -0
- package/dist/subpath/ReaderT.cjs.map +1 -0
- package/dist/subpath/ReaderT.mjs +148 -0
- package/dist/subpath/ReaderT.mjs.map +1 -0
- package/dist/subpath/Resource.cjs +2 -0
- package/dist/subpath/Resource.cjs.map +1 -0
- package/dist/subpath/Resource.mjs +150 -0
- package/dist/subpath/Resource.mjs.map +1 -0
- package/dist/subpath/Result.cjs +2 -0
- package/dist/subpath/Result.cjs.map +1 -0
- package/dist/subpath/Result.mjs +337 -0
- package/dist/subpath/Result.mjs.map +1 -0
- package/dist/subpath/Sets.cjs +2 -0
- package/dist/subpath/Sets.cjs.map +1 -0
- package/dist/subpath/Sets.mjs +92 -0
- package/dist/subpath/Sets.mjs.map +1 -0
- package/dist/subpath/Str.cjs +2 -0
- package/dist/subpath/Str.cjs.map +1 -0
- package/dist/subpath/Str.mjs +114 -0
- package/dist/subpath/Str.mjs.map +1 -0
- package/dist/subpath/TxScope.cjs +2 -0
- package/dist/subpath/TxScope.cjs.map +1 -0
- package/dist/subpath/TxScope.mjs +138 -0
- package/dist/subpath/TxScope.mjs.map +1 -0
- package/dist/subpath/TypeTool.cjs +2 -0
- package/dist/subpath/TypeTool.cjs.map +1 -0
- package/dist/subpath/TypeTool.mjs +9 -0
- package/dist/subpath/TypeTool.mjs.map +1 -0
- package/dist/subpath/Utils.cjs +2 -0
- package/dist/subpath/Utils.cjs.map +1 -0
- package/dist/subpath/Utils.mjs +835 -0
- package/dist/subpath/Utils.mjs.map +1 -0
- package/dist/subpath/VirtualTime.cjs +2 -0
- package/dist/subpath/VirtualTime.cjs.map +1 -0
- package/dist/subpath/VirtualTime.mjs +1186 -0
- package/dist/subpath/VirtualTime.mjs.map +1 -0
- package/dist/types/Arr.d.ts +2 -0
- package/dist/types/Concurrent/Lock/condition_variable.d.ts +138 -0
- package/dist/types/Concurrent/Lock/mutex.d.ts +185 -0
- package/dist/types/Concurrent/Lock/rwlock.d.ts +253 -0
- package/dist/types/Concurrent/Lock/semaphore.d.ts +208 -0
- package/dist/types/Concurrent/Valve/__export__.d.ts +5 -0
- package/dist/types/Concurrent/Valve/circuit-breaker.d.ts +146 -0
- package/dist/types/Concurrent/Valve/leaky-bucket.d.ts +115 -0
- package/dist/types/Concurrent/Valve/sliding-window.d.ts +91 -0
- package/dist/types/Concurrent/Valve/token-bucket.d.ts +68 -0
- package/dist/types/Concurrent/__export__.d.ts +15 -0
- package/dist/types/Concurrent/barrier.d.ts +255 -0
- package/dist/types/Concurrent/channel.d.ts +239 -0
- package/dist/types/Concurrent/delay.d.ts +42 -0
- package/dist/types/Concurrent/ext/map.d.ts +82 -0
- package/dist/types/Concurrent/ext/other.d.ts +113 -0
- package/dist/types/Concurrent/ext/race.d.ts +31 -0
- package/dist/types/Concurrent/ext/some.d.ts +64 -0
- package/dist/types/Concurrent/limiter.d.ts +131 -0
- package/dist/types/Concurrent/scheduler.d.ts +171 -0
- package/dist/types/Concurrent/task-scope.d.ts +282 -0
- package/dist/types/Concurrent.d.ts +2 -0
- package/dist/types/Errors.d.ts +66 -0
- package/dist/types/FetchQ.d.ts +2 -0
- package/dist/types/Fit/__export__.d.ts +5 -0
- package/dist/types/Fit/base.d.ts +325 -0
- package/dist/types/Fit/parser.d.ts +110 -0
- package/dist/types/Fit/standard-schema.d.ts +127 -0
- package/dist/types/Fit/sugar.d.ts +274 -0
- package/dist/types/Fit/tool.d.ts +585 -0
- package/dist/types/Fit.d.ts +2 -0
- package/dist/types/Lazy.d.ts +2 -0
- package/dist/types/Maps.d.ts +2 -0
- package/dist/types/Maybe/__export__.d.ts +6 -0
- package/dist/types/Maybe/base.d.ts +62 -0
- package/dist/types/Maybe/consumers-async.d.ts +58 -0
- package/dist/types/Maybe/consumers.d.ts +63 -0
- package/dist/types/Maybe/operators-async.d.ts +145 -0
- package/dist/types/Maybe/operators.d.ts +177 -0
- package/dist/types/Maybe/types.d.ts +12 -0
- package/dist/types/Maybe.d.ts +2 -0
- package/dist/types/MockClock/Timeline.d.ts +392 -0
- package/dist/types/MockClock/TimerHandle.d.ts +159 -0
- package/dist/types/MockClock/TimerHeap.d.ts +21 -0
- package/dist/types/MockClock/VirtualTimeManager.d.ts +23 -0
- package/dist/types/MockClock/__export__.d.ts +104 -0
- package/dist/types/MockClock/hooks/__export__.d.ts +9 -0
- package/dist/types/MockClock/hooks/hookAbortSignal.d.ts +3 -0
- package/dist/types/MockClock/hooks/hookDate.d.ts +3 -0
- package/dist/types/MockClock/hooks/hookIntl.d.ts +3 -0
- package/dist/types/MockClock/hooks/hookMessageChannel.d.ts +3 -0
- package/dist/types/MockClock/hooks/hookMicrotasks.d.ts +3 -0
- package/dist/types/MockClock/hooks/hookOs.d.ts +3 -0
- package/dist/types/MockClock/hooks/hookPerformance.d.ts +3 -0
- package/dist/types/MockClock/hooks/hookProcess.d.ts +3 -0
- package/dist/types/MockClock/hooks/hookTimers.d.ts +3 -0
- package/dist/types/MockClock/types.d.ts +103 -0
- package/dist/types/Other/FetchQ.d.ts +320 -0
- package/dist/types/Other/deque.d.ts +59 -0
- package/dist/types/Other/disjointSet.d.ts +53 -0
- package/dist/types/Other/heap.d.ts +41 -0
- package/dist/types/Other/lazy.d.ts +127 -0
- package/dist/types/Other/queue.d.ts +42 -0
- package/dist/types/Other/secret.d.ts +111 -0
- package/dist/types/Other/stack.d.ts +40 -0
- package/dist/types/Reactive/__export__.d.ts +4 -0
- package/dist/types/Reactive/event_emitter.d.ts +195 -0
- package/dist/types/Reactive/flow-combination.d.ts +74 -0
- package/dist/types/Reactive/flow.d.ts +180 -0
- package/dist/types/Reactive/pace.d.ts +80 -0
- package/dist/types/Reactive.d.ts +2 -0
- package/dist/types/Reader/__export-readerT__.d.ts +4 -0
- package/dist/types/Reader/__export-reader__.d.ts +4 -0
- package/dist/types/Reader/local.d.ts +39 -0
- package/dist/types/Reader/reader-async.d.ts +84 -0
- package/dist/types/Reader/reader.d.ts +96 -0
- package/dist/types/Reader/readerT-async.d.ts +186 -0
- package/dist/types/Reader/readerT.d.ts +178 -0
- package/dist/types/Reader/types.d.ts +37 -0
- package/dist/types/Reader.d.ts +2 -0
- package/dist/types/ReaderT.d.ts +2 -0
- package/dist/types/Resource/TxScope-async.d.ts +86 -0
- package/dist/types/Resource/TxScope.d.ts +85 -0
- package/dist/types/Resource/__export-TxScope__.d.ts +2 -0
- package/dist/types/Resource/__export-resource__.d.ts +2 -0
- package/dist/types/Resource/resource-async.d.ts +79 -0
- package/dist/types/Resource/resource.d.ts +78 -0
- package/dist/types/Resource/types.d.ts +79 -0
- package/dist/types/Resource.d.ts +2 -0
- package/dist/types/Result/Consumers/branch-async.d.ts +77 -0
- package/dist/types/Result/Consumers/branch.d.ts +70 -0
- package/dist/types/Result/Consumers/inspect.d.ts +66 -0
- package/dist/types/Result/Operators/Async/combine-async.d.ts +69 -0
- package/dist/types/Result/Operators/Async/partition-async.d.ts +29 -0
- package/dist/types/Result/Operators/Async/reduce-async.d.ts +15 -0
- package/dist/types/Result/Operators/Async/transform-async.d.ts +90 -0
- package/dist/types/Result/Operators/combine.d.ts +60 -0
- package/dist/types/Result/Operators/flatten.d.ts +26 -0
- package/dist/types/Result/Operators/partition.d.ts +25 -0
- package/dist/types/Result/Operators/reduce.d.ts +12 -0
- package/dist/types/Result/Operators/transform.d.ts +70 -0
- package/dist/types/Result/__export__.d.ts +14 -0
- package/dist/types/Result/base.d.ts +115 -0
- package/dist/types/Result/types.d.ts +34 -0
- package/dist/types/Result.d.ts +2 -0
- package/dist/types/Sets.d.ts +2 -0
- package/dist/types/Str.d.ts +2 -0
- package/dist/types/TxScope.d.ts +2 -0
- package/dist/types/TypeTool.d.ts +2 -0
- package/dist/types/Utils/Array/__export__.d.ts +10 -0
- package/dist/types/Utils/Array/filtering.d.ts +89 -0
- package/dist/types/Utils/Array/flatten.d.ts +45 -0
- package/dist/types/Utils/Array/grouping.d.ts +44 -0
- package/dist/types/Utils/Array/iteration.d.ts +86 -0
- package/dist/types/Utils/Array/operators.d.ts +62 -0
- package/dist/types/Utils/Array/randomization.d.ts +76 -0
- package/dist/types/Utils/Array/set.d.ts +108 -0
- package/dist/types/Utils/Array/slice.d.ts +189 -0
- package/dist/types/Utils/Array/sorting.d.ts +55 -0
- package/dist/types/Utils/Array/zip.d.ts +93 -0
- package/dist/types/Utils/Functions/__export__.d.ts +5 -0
- package/dist/types/Utils/Functions/base.d.ts +157 -0
- package/dist/types/Utils/Functions/curry.d.ts +73 -0
- package/dist/types/Utils/Functions/debounce.d.ts +240 -0
- package/dist/types/Utils/Functions/defer.d.ts +43 -0
- package/dist/types/Utils/Functions/pipe.d.ts +205 -0
- package/dist/types/Utils/Map.d.ts +284 -0
- package/dist/types/Utils/Math.d.ts +225 -0
- package/dist/types/Utils/Object/__export__.d.ts +2 -0
- package/dist/types/Utils/Object/base.d.ts +131 -0
- package/dist/types/Utils/Object/clone.d.ts +81 -0
- package/dist/types/Utils/Predicates.d.ts +361 -0
- package/dist/types/Utils/Set.d.ts +105 -0
- package/dist/types/Utils/String.d.ts +217 -0
- package/dist/types/Utils/__export__.d.ts +9 -0
- package/dist/types/Utils/type-tool.d.ts +168 -0
- package/dist/types/Utils.d.ts +2 -0
- package/dist/types/VirtualTime.d.ts +2 -0
- package/dist/types/helper.d.ts +71 -0
- package/dist/types/index.d.ts +21 -0
- package/dist/types/unknown-error.d.ts +98 -0
- package/package.json +179 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helper-BVabbpmX.mjs","sources":["../../src/unknown-error.ts","../../src/helper.ts"],"sourcesContent":["// ========================================\n// ./src/unknown-error.ts\n// ========================================\n\n/**\n * Standardized error classification structure.\n * Categorizes unknown error values into distinct types for consistent handling.\n */\nexport interface ErrorType {\n /**\n * Error classification code:\n * 0 = Standard Error instance\n * 1 = DOMException (specifically AbortError)\n * 2 = null or undefined value\n * 3 = Error-like object with 'message' property\n * 4 = Complex objects or primitive values without standard error structure\n */\n readonly type_code: 0 | 1 | 2 | 3 | 4;\n /** Human-readable error description, sanitized for safe display */\n readonly message: string;\n}\n\n/**\n * Safely extracts structured error information from any unknown value.\n * Handles edge cases including DOMExceptions, primitive values,\n * objects with circular references, getters, and Proxy traps.\n *\n * @param error_data - The captured exception value (typically from catch block)\n * @returns Normalized error object with classification and sanitized message\n *\n * @example\n * try { throw \"Raw string error\"; }\n * catch (e) { extractErrorInfo(e); }\n * // Returns: { type_code: 4, message: \"Primitive [string]: Raw string error\" }\n */\nexport function extractErrorInfo(error_data: unknown): ErrorType {\n // Handle AbortError DOMException (special case for abort signals)\n if (\n typeof DOMException !== 'undefined' &&\n error_data instanceof DOMException\n ) {\n return {type_code: 1, message: ''};\n }\n\n // Handle standard Error instances\n if (error_data instanceof Error) {\n return {type_code: 0, message: ''};\n }\n\n // Handle null/undefined values\n if (error_data === null || error_data === undefined) {\n return {\n type_code: 2,\n message: 'An unknown or null/undefined error occurred.',\n };\n }\n\n // Handle error-like objects (non-Error objects with 'message' property)\n if (typeof error_data === 'object') {\n // Safely check for own 'message' property (avoids getters/Proxy traps)\n const has_message_property = Object.prototype.hasOwnProperty.call(\n error_data,\n 'message',\n );\n\n if (has_message_property) {\n const maybeError = error_data as Partial<{message: unknown}>;\n\n // Safely extract message value\n try {\n const message_value = maybeError.message;\n\n // Use string message directly\n if (typeof message_value === 'string') {\n return {\n type_code: 3,\n message: message_value,\n };\n }\n // Convert non-object message values to string\n else if (\n message_value !== undefined &&\n (typeof message_value !== 'object' || Array.isArray(message_value))\n ) {\n return {\n type_code: 3,\n // eslint-disable-next-line @typescript-eslint/no-base-to-string\n message: String(message_value),\n };\n }\n } catch {\n // If accessing 'message' throws, treat as complex object\n }\n }\n }\n\n // Handle primitive types and complex objects\n let error_message: string;\n const data_type: string = typeof error_data;\n\n // Primitive types (non-object, non-function)\n if (data_type !== 'object' && data_type !== 'function') {\n // eslint-disable-next-line @typescript-eslint/no-base-to-string\n error_message = `Primitive [${data_type}]: ${String(error_data)}`;\n }\n // Complex objects (non-Error, non-error-like)\n else {\n let type_name: string;\n try {\n // Safely get type string (handles Proxy traps)\n type_name = Object.prototype.toString.call(error_data);\n } catch {\n type_name = '[object Object]'; // Fallback for trapped calls\n }\n\n let detail = type_name;\n\n // Attempt JSON serialization\n try {\n const json_string = JSON.stringify(error_data, null, 2);\n detail = `${type_name}: ${json_string.substring(0, 512)}`;\n } catch {\n // Fallback for circular references, BigInt, or getter exceptions\n const fallback_info: string[] = [];\n\n try {\n // Safely extract enumerable own properties using reflection\n for (const key of Object.keys(error_data)) {\n const descriptor = Object.getOwnPropertyDescriptor(error_data, key);\n\n // Only read non-getter properties safely\n if (descriptor && descriptor.value !== undefined) {\n const value: unknown = descriptor.value;\n const str_value = String(value).substring(0, 80);\n fallback_info.push(`${key}: ${str_value}`);\n }\n }\n } catch {\n fallback_info.push('Object details unavailable due to internal error.');\n }\n\n const details_string =\n fallback_info.length > 0\n ? `{ ${fallback_info.join(', ')} }`\n : type_name;\n detail = `${type_name}: ${details_string} (Serialization Failed)`;\n }\n\n error_message = `Complex Object ${detail}`;\n }\n\n return {\n type_code: 4,\n message: error_message,\n };\n}\n\n/**\n * Converts any thrown value into a DOMException while preserving original context.\n *\n * Error type handling:\n * - DOMException (type 1): Returns directly\n * - Error instances (type 0): Creates DOMException with preserved stack trace\n * - Other types (2-4): Creates wrapped DOMException with extracted message\n *\n * Original error is attached to the 'cause' property for debugging.\n *\n * @param error_data - Raw value caught in try/catch block\n * @param name - DOMException name (defaults to 'AbortError')\n * @returns DOMException instance with optional 'cause' property\n * @throws {TypeError} If DOMException constructor is unavailable\n *\n * @example\n * try { throw new Error(\"Network failure\"); }\n * catch (e) {\n * const domError = ensureDOMException(e);\n * console.log(domError.name); // \"DOMException\"\n * console.log(domError.cause); // Original Error instance\n * }\n *\n * @example\n * try { throw { code: 404, msg: \"Not found\" }; }\n * catch (e) {\n * const domError = ensureDOMException(e);\n * console.log(domError.message);\n * // \"DOMException Wrapped: Complex Object [object Object]...\"\n * }\n */\nexport function ensureDOMException(\n error_data: unknown,\n name: string = 'AbortError',\n): DOMException & {cause?: unknown} {\n const extract = extractErrorInfo(error_data);\n\n // Return DOMException directly\n if (extract.type_code === 1) {\n return error_data as DOMException & {cause?: unknown};\n }\n\n // Convert Error to DOMException with stack preservation\n if (extract.type_code === 0) {\n const e = error_data as Error;\n const dome = new DOMException(e.message);\n\n if ('stack' in e && typeof e.stack === 'string') {\n dome.stack = e.stack;\n }\n\n dome.cause = e;\n return dome as DOMException & {cause?: unknown};\n }\n\n // Wrap non-Error types in DOMException\n const error_message = `DOMException Wrapped: ${extract.message}`;\n const final_error = new DOMException(error_message, name);\n final_error.cause = error_data;\n\n return final_error as DOMException & {cause?: unknown};\n}\n\n/**\n * Ensures that the captured value is an Error instance. If not, it wraps the value in an Error object that includes the original information.\n * @param error_data - The value caught by the try...catch block (typically of type unknown).\n * @returns An object guaranteed to be of type Error, with an optional 'cause' property.\n */\nexport function ensureError(error_data: unknown): Error & {cause?: unknown} {\n const extract = extractErrorInfo(error_data);\n if (extract.type_code === 1 || extract.type_code === 0) {\n return error_data as Error & {cause?: unknown};\n }\n let error_message = extract.message;\n if (extract.type_code === 4) {\n error_message = `Wrapped: ${error_message}`;\n }\n\n const final_error = new Error(error_message);\n final_error.cause = error_data;\n return final_error as Error & {cause?: unknown};\n}\n\n/**\n * Used to wrap unknown type errors caught in try-catch blocks, ensuring the error chain remains intact.\n * @extends Error\n */\nexport class UnknownError extends Error {\n public override readonly cause: unknown;\n\n /**\n * Handles unknown type errors caught in try-catch blocks.\n * @param raw_error - The value caught by the try...catch block, of type unknown.\n * @param message - An optional custom message, which will be the primary message for this UnknownError.\n */\n constructor(raw_error: unknown, message?: string) {\n // 确保一定是 Error 类型 (返回值包含 cause 属性)\n const ensured_error = ensureError(raw_error);\n // 添加自定义消息\n const final_message = message ?? `UnknownError: ${ensured_error.message}`;\n super(final_message);\n this.name = 'UnknownError';\n this.cause = raw_error; // 手动添加,保证兼容性\n\n /* v8 ignore if -- @preserve */\n if (typeof Error.captureStackTrace === 'function') {\n Error.captureStackTrace(this, UnknownError);\n }\n }\n\n /**\n * Static constructor used to quickly create and wrap an UnknownError instance.\n * @param raw_error - The value caught by the try...catch block, of type unknown.\n * @param message - An optional custom message.\n * @returns The wrapped UnknownError instance.\n */\n static from(raw_error: unknown, message?: string): UnknownError {\n // -- 直接调用构造函数 --\n return new UnknownError(raw_error, message);\n }\n\n /**\n * Returns a visual representation of the error (excluding the stack trace).\n * @returns The visual error representation.\n */\n toString(): string {\n const causeString =\n this.cause instanceof Error ? this.cause.toString() : String(this.cause);\n return `${this.name}: ${this.message}\\nCaused by: ${causeString}`;\n }\n}\n","// ========================================\r\n// ./src/helper.ts\r\n// ========================================\r\n\r\nimport {UnknownError} from './unknown-error';\r\nimport type {MaybePromise} from './Utils/type-tool';\r\n\r\n/**\r\n * Checks if a value is a Promise-like object (i.e., \"thenable\").\r\n *\r\n * A value is considered Promise-like if it meets the following conditions:\r\n * 1. It is non-null.\r\n * 2. Its type is 'object' or 'function'.\r\n * 3. It possesses a property named 'then', and the value of this property is a function.\r\n * 4. Attempting to access the 'then' property does not throw an exception.\r\n *\r\n * This function also returns true when a native {@link Promise} instance is passed.\r\n *\r\n * @param value - The value to check.\r\n * @returns True if the value is Promise-like; otherwise, false.\r\n */\r\nexport const isPromiseLike = (\r\n value: unknown,\r\n): value is PromiseLike<unknown> => {\r\n if (\r\n value == null ||\r\n (typeof value !== 'object' && typeof value !== 'function')\r\n )\r\n return false;\r\n const thenable = value as {then?: unknown};\r\n try {\r\n return typeof thenable.then === 'function';\r\n } catch (e) {\r\n return false;\r\n }\r\n};\r\n\r\n/**\r\n * Checks if a value conforms to the standard \"Result object\" structure (Result-like).\r\n *\r\n * A value is considered Result-like if it meets the following conditions:\r\n * 1. It is a non-null 'object' type.\r\n * 2. It must contain a boolean property 'ok'.\r\n * 3. In the success state (ok: true), it must contain the 'value' property and must not contain the 'error' property.\r\n * 4. In the failure state (ok: false), it must contain the 'error' property and must not contain the 'value' property.\r\n *\r\n * @param value - The value to check.\r\n * @returns True if the value conforms to the Result-like structure; otherwise, false.\r\n */\r\nexport const isResultLike = (\r\n value: unknown,\r\n): value is {ok: boolean; value?: unknown; error?: unknown} =>\r\n // 快速排除非对象和 null\r\n typeof value !== 'object' || value === null\r\n ? false\r\n : (() => {\r\n const v = value as Record<string, unknown>;\r\n const ok = v.ok;\r\n if (typeof ok !== 'boolean') return false;\r\n return ok\r\n ? 'value' in v && !('error' in v)\r\n : 'error' in v && !('value' in v);\r\n })();\r\n\r\n\r\n export const wrapError = (e: unknown) =>\r\n e instanceof DOMException && e.name === 'AbortError'\r\n ? e\r\n : UnknownError.from(e);\r\n\r\n/**\r\n * Flushes all pending microtasks and macroscheduled tasks.\r\n * @description\r\n * This utility is particularly useful in testing environments to ensure that all\r\n * asynchronous operations (like Promises or API calls) and their subsequent\r\n * DOM updates have been processed before making assertions.\r\n * It uses `MessageChannel` to bypass the 4ms minimum delay typically\r\n * associated with `setTimeout(fn, 0)` in browsers.\r\n * @returns {Promise<void>} A promise that resolves after the task queue is cleared.\r\n * @example\r\n * ```typescript\r\n * await flushPromises();\r\n * expect(wrapper.text()).toContain('Data Loaded');\r\n * ```\r\n */\r\n/* v8 ignore next -- @preserve */\r\nexport const flushPromises = (): Promise<void> => {\r\n return new Promise((resolve) => queueMacroTask(resolve));\r\n};\r\n\r\n/**\r\n * Dynamically awaits a value based on whether it's PromiseLike or synchronous.\r\n * If the input is PromiseLike, it awaits the value; otherwise, returns the value directly.\r\n * @param value - The value to await or return synchronously\r\n * @returns A Promise containing the resolved value\r\n */\r\nexport const dynamicAwait = async <T>(value: MaybePromise<T>): Promise<T> =>\r\n isPromiseLike(value) ? await value : value;\r\n\r\n/**\r\n * Queues a callback to be executed in the next macro task.\r\n *\r\n * This function provides an optimized way to schedule callbacks with minimal delay:\r\n * 1. In Node.js: Uses `setImmediate` (optimal performance).\r\n * 2. In modern browsers: Uses `MessageChannel` to bypass the 4ms minimum delay of `setTimeout`.\r\n * 3. Fallback: Uses `setTimeout(callback, 0)` for legacy environments.\r\n *\r\n * The implementation batches multiple callbacks into a single macro task to improve performance.\r\n *\r\n * @param callback - The function to execute in the next macro task.\r\n */\r\n/* v8 ignore next -- @preserve */\r\nexport const queueMacroTask = (() => {\r\n // Node.js 优先使用 setImmediate,性能最优\r\n if (typeof setImmediate === 'function') return setImmediate;\r\n\r\n // 浏览器环境用 MessageChannel 模拟,性能优于 setTimeout(无4ms最小延迟)\r\n if (typeof MessageChannel !== 'undefined') {\r\n let queue: Array<() => void> = [];\r\n const channel = new MessageChannel();\r\n let is_pending = false;\r\n\r\n // 批量执行队列中的所有回调,避免多次触发宏任务\r\n const flush = () => {\r\n is_pending = false;\r\n const local_queue = queue;\r\n queue = [];\r\n for (let i = 0; i < local_queue.length; i++) local_queue[i]();\r\n };\r\n\r\n channel.port1.onmessage = flush;\r\n\r\n // 将回调加入队列,仅在队列为空时触发一次宏任务\r\n return (callback: VoidFunction) => {\r\n queue.push(callback);\r\n if (!is_pending) {\r\n is_pending = true;\r\n channel.port2.postMessage(null);\r\n }\r\n };\r\n }\r\n\r\n // 降级:老旧环境用 setTimeout,存在4ms最小延迟\r\n return (callback: VoidFunction) => setTimeout(callback, 0);\r\n})();\r\n"],"names":["extractErrorInfo","error_data","maybeError","message_value","error_message","data_type","type_name","detail","json_string","fallback_info","key","descriptor","value","str_value","details_string","ensureDOMException","name","extract","e","dome","final_error","ensureError","UnknownError","raw_error","message","ensured_error","final_message","causeString","isPromiseLike","thenable","isResultLike","v","ok","wrapError","flushPromises","resolve","queueMacroTask","dynamicAwait","queue","channel","is_pending","flush","local_queue","i","callback"],"mappings":"AAmCO,SAASA,EAAiBC,GAAgC;AAE/D,MACE,OAAO,eAAiB,OACxBA,aAAsB;AAEtB,WAAO,EAAC,WAAW,GAAG,SAAS,GAAA;AAIjC,MAAIA,aAAsB;AACxB,WAAO,EAAC,WAAW,GAAG,SAAS,GAAA;AAIjC,MAAIA,KAAe;AACjB,WAAO;AAAA,MACL,WAAW;AAAA,MACX,SAAS;AAAA,IAAA;AAKb,MAAI,OAAOA,KAAe,YAEK,OAAO,UAAU,eAAe;AAAA,IAC3DA;AAAA,IACA;AAAA,EAAA,GAGwB;AACxB,UAAMC,IAAaD;AAGnB,QAAI;AACF,YAAME,IAAgBD,EAAW;AAGjC,UAAI,OAAOC,KAAkB;AAC3B,eAAO;AAAA,UACL,WAAW;AAAA,UACX,SAASA;AAAA,QAAA;AAEb,UAGEA,MAAkB,WACjB,OAAOA,KAAkB,YAAY,MAAM,QAAQA,CAAa;AAEjE,eAAO;AAAA,UACL,WAAW;AAAA;AAAA,UAEX,SAAS,OAAOA,CAAa;AAAA,QAAA;AAAA,IAGnC,QAAQ;AAAA,IAER;AAAA,EACF;AAIF,MAAIC;AACJ,QAAMC,IAAoB,OAAOJ;AAGjC,MAAII,MAAc,YAAYA,MAAc;AAE1C,IAAAD,IAAgB,cAAcC,CAAS,MAAM,OAAOJ,CAAU,CAAC;AAAA,OAG5D;AACH,QAAIK;AACJ,QAAI;AAEF,MAAAA,IAAY,OAAO,UAAU,SAAS,KAAKL,CAAU;AAAA,IACvD,QAAQ;AACN,MAAAK,IAAY;AAAA,IACd;AAEA,QAAIC,IAASD;AAGb,QAAI;AACF,YAAME,IAAc,KAAK,UAAUP,GAAY,MAAM,CAAC;AACtD,MAAAM,IAAS,GAAGD,CAAS,KAAKE,EAAY,UA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KAC7BA,IACH,WAAWD,KAAK,EAAE,WAAWA,KAC7B,WAAWA,KAAK,EAAE,WAAWA;AAAA,EACnC,GAAA;AAAA,GAGaE,IAAY,CAAC,MAC9B,aAAa,gBAAgB,EAAE,SAAS,eACpC,IACAX,EAAa,KAAK,CAAC,GAkBZY,IAAgB,MACpB,IAAI,QAAQ,CAACC,MAAYC,EAAeD,CAAO,CAAC,GAS5CE,IAAe,OAAUzB,MACpCgB,EAAchB,CAAK,IAAI,MAAMA,IAAQA,GAe1BwB,KAAkB,MAAM;AAEnC,MAAI,OAAO,gBAAiB,WAAY,QAAO;AAG/C,MAAI,OAAO,iBAAmB,KAAa;AACzC,QAAIE,IAA2B,CAAA;AAC/B,UAAMC,IAAU,IAAI,eAAA;AACpB,QAAIC,IAAa;AAGjB,UAAMC,IAAQ,MAAM;AAClB,MAAAD,IAAa;AACb,YAAME,IAAcJ;AACpB,MAAAA,IAAQ,CAAA;AACR,eAASK,IAAI,GAAGA,IAAID,EAAY,QAAQC,IAAK,CAAAD,EAAYC,CAAC,EAAA;AAAA,IAC5D;AAEA,WAAAJ,EAAQ,MAAM,YAAYE,GAGnB,CAACG,MAA2B;AACjC,MAAAN,EAAM,KAAKM,CAAQ,GACdJ,MACHA,IAAa,IACbD,EAAQ,MAAM,YAAY,IAAI;AAAA,IAElC;AAAA,EACF;AAGA,SAAO,CAACK,MAA2B,WAAWA,GAAU,CAAC;AAC3D,GAAA;"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
"use strict";function a(e){if(typeof DOMException<"u"&&e instanceof DOMException)return{type_code:1,message:""};if(e instanceof Error)return{type_code:0,message:""};if(e==null)return{type_code:2,message:"An unknown or null/undefined error occurred."};if(typeof e=="object"&&Object.prototype.hasOwnProperty.call(e,"message")){const o=e;try{const s=o.message;if(typeof s=="string")return{type_code:3,message:s};if(s!==void 0&&(typeof s!="object"||Array.isArray(s)))return{type_code:3,message:String(s)}}catch{}}let t;const n=typeof e;if(n!=="object"&&n!=="function")t=`Primitive [${n}]: ${String(e)}`;else{let r;try{r=Object.prototype.toString.call(e)}catch{r="[object Object]"}let o=r;try{const s=JSON.stringify(e,null,2);o=`${r}: ${s.substring(0,512)}`}catch{const s=[];try{for(const f of Object.keys(e)){const u=Object.getOwnPropertyDescriptor(e,f);if(u&&u.value!==void 0){const g=u.value,m=String(g).substring(0,80);s.push(`${f}: ${m}`)}}}catch{s.push("Object details unavailable due to internal error.")}const c=s.length>0?`{ ${s.join(", ")} }`:r;o=`${r}: ${c} (Serialization Failed)`}t=`Complex Object ${o}`}return{type_code:4,message:t}}function h(e,t="AbortError"){const n=a(e);if(n.type_code===1)return e;if(n.type_code===0){const s=e,c=new DOMException(s.message);return"stack"in s&&typeof s.stack=="string"&&(c.stack=s.stack),c.cause=s,c}const r=`DOMException Wrapped: ${n.message}`,o=new DOMException(r,t);return o.cause=e,o}function p(e){const t=a(e);if(t.type_code===1||t.type_code===0)return e;let n=t.message;t.type_code===4&&(n=`Wrapped: ${n}`);const r=new Error(n);return r.cause=e,r}class i extends Error{cause;constructor(t,n){const r=p(t),o=n??`UnknownError: ${r.message}`;super(o),this.name="UnknownError",this.cause=t,typeof Error.captureStackTrace=="function"&&Error.captureStackTrace(this,i)}static from(t,n){return new i(t,n)}toString(){const t=this.cause instanceof Error?this.cause.toString():String(this.cause);return`${this.name}: ${this.message}
|
|
2
|
+
Caused by: ${t}`}}const l=e=>{if(e==null||typeof e!="object"&&typeof e!="function")return!1;const t=e;try{return typeof t.then=="function"}catch{return!1}},E=e=>typeof e!="object"||e===null?!1:(()=>{const t=e,n=t.ok;return typeof n!="boolean"?!1:n?"value"in t&&!("error"in t):"error"in t&&!("value"in t)})(),b=e=>e instanceof DOMException&&e.name==="AbortError"?e:i.from(e),d=()=>new Promise(e=>y(e)),k=async e=>l(e)?await e:e,y=(()=>{if(typeof setImmediate=="function")return setImmediate;if(typeof MessageChannel<"u"){let e=[];const t=new MessageChannel;let n=!1;const r=()=>{n=!1;const o=e;e=[];for(let s=0;s<o.length;s++)o[s]()};return t.port1.onmessage=r,o=>{e.push(o),n||(n=!0,t.port2.postMessage(null))}}return e=>setTimeout(e,0)})();exports.UnknownError=i;exports.dynamicAwait=k;exports.ensureDOMException=h;exports.ensureError=p;exports.extractErrorInfo=a;exports.flushPromises=d;exports.isPromiseLike=l;exports.isResultLike=E;exports.queueMacroTask=y;exports.wrapError=b;
|
|
3
|
+
//# sourceMappingURL=helper-tsqZMRHW.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helper-tsqZMRHW.cjs","sources":["../../src/unknown-error.ts","../../src/helper.ts"],"sourcesContent":["// ========================================\n// ./src/unknown-error.ts\n// ========================================\n\n/**\n * Standardized error classification structure.\n * Categorizes unknown error values into distinct types for consistent handling.\n */\nexport interface ErrorType {\n /**\n * Error classification code:\n * 0 = Standard Error instance\n * 1 = DOMException (specifically AbortError)\n * 2 = null or undefined value\n * 3 = Error-like object with 'message' property\n * 4 = Complex objects or primitive values without standard error structure\n */\n readonly type_code: 0 | 1 | 2 | 3 | 4;\n /** Human-readable error description, sanitized for safe display */\n readonly message: string;\n}\n\n/**\n * Safely extracts structured error information from any unknown value.\n * Handles edge cases including DOMExceptions, primitive values,\n * objects with circular references, getters, and Proxy traps.\n *\n * @param error_data - The captured exception value (typically from catch block)\n * @returns Normalized error object with classification and sanitized message\n *\n * @example\n * try { throw \"Raw string error\"; }\n * catch (e) { extractErrorInfo(e); }\n * // Returns: { type_code: 4, message: \"Primitive [string]: Raw string error\" }\n */\nexport function extractErrorInfo(error_data: unknown): ErrorType {\n // Handle AbortError DOMException (special case for abort signals)\n if (\n typeof DOMException !== 'undefined' &&\n error_data instanceof DOMException\n ) {\n return {type_code: 1, message: ''};\n }\n\n // Handle standard Error instances\n if (error_data instanceof Error) {\n return {type_code: 0, message: ''};\n }\n\n // Handle null/undefined values\n if (error_data === null || error_data === undefined) {\n return {\n type_code: 2,\n message: 'An unknown or null/undefined error occurred.',\n };\n }\n\n // Handle error-like objects (non-Error objects with 'message' property)\n if (typeof error_data === 'object') {\n // Safely check for own 'message' property (avoids getters/Proxy traps)\n const has_message_property = Object.prototype.hasOwnProperty.call(\n error_data,\n 'message',\n );\n\n if (has_message_property) {\n const maybeError = error_data as Partial<{message: unknown}>;\n\n // Safely extract message value\n try {\n const message_value = maybeError.message;\n\n // Use string message directly\n if (typeof message_value === 'string') {\n return {\n type_code: 3,\n message: message_value,\n };\n }\n // Convert non-object message values to string\n else if (\n message_value !== undefined &&\n (typeof message_value !== 'object' || Array.isArray(message_value))\n ) {\n return {\n type_code: 3,\n // eslint-disable-next-line @typescript-eslint/no-base-to-string\n message: String(message_value),\n };\n }\n } catch {\n // If accessing 'message' throws, treat as complex object\n }\n }\n }\n\n // Handle primitive types and complex objects\n let error_message: string;\n const data_type: string = typeof error_data;\n\n // Primitive types (non-object, non-function)\n if (data_type !== 'object' && data_type !== 'function') {\n // eslint-disable-next-line @typescript-eslint/no-base-to-string\n error_message = `Primitive [${data_type}]: ${String(error_data)}`;\n }\n // Complex objects (non-Error, non-error-like)\n else {\n let type_name: string;\n try {\n // Safely get type string (handles Proxy traps)\n type_name = Object.prototype.toString.call(error_data);\n } catch {\n type_name = '[object Object]'; // Fallback for trapped calls\n }\n\n let detail = type_name;\n\n // Attempt JSON serialization\n try {\n const json_string = JSON.stringify(error_data, null, 2);\n detail = `${type_name}: ${json_string.substring(0, 512)}`;\n } catch {\n // Fallback for circular references, BigInt, or getter exceptions\n const fallback_info: string[] = [];\n\n try {\n // Safely extract enumerable own properties using reflection\n for (const key of Object.keys(error_data)) {\n const descriptor = Object.getOwnPropertyDescriptor(error_data, key);\n\n // Only read non-getter properties safely\n if (descriptor && descriptor.value !== undefined) {\n const value: unknown = descriptor.value;\n const str_value = String(value).substring(0, 80);\n fallback_info.push(`${key}: ${str_value}`);\n }\n }\n } catch {\n fallback_info.push('Object details unavailable due to internal error.');\n }\n\n const details_string =\n fallback_info.length > 0\n ? `{ ${fallback_info.join(', ')} }`\n : type_name;\n detail = `${type_name}: ${details_string} (Serialization Failed)`;\n }\n\n error_message = `Complex Object ${detail}`;\n }\n\n return {\n type_code: 4,\n message: error_message,\n };\n}\n\n/**\n * Converts any thrown value into a DOMException while preserving original context.\n *\n * Error type handling:\n * - DOMException (type 1): Returns directly\n * - Error instances (type 0): Creates DOMException with preserved stack trace\n * - Other types (2-4): Creates wrapped DOMException with extracted message\n *\n * Original error is attached to the 'cause' property for debugging.\n *\n * @param error_data - Raw value caught in try/catch block\n * @param name - DOMException name (defaults to 'AbortError')\n * @returns DOMException instance with optional 'cause' property\n * @throws {TypeError} If DOMException constructor is unavailable\n *\n * @example\n * try { throw new Error(\"Network failure\"); }\n * catch (e) {\n * const domError = ensureDOMException(e);\n * console.log(domError.name); // \"DOMException\"\n * console.log(domError.cause); // Original Error instance\n * }\n *\n * @example\n * try { throw { code: 404, msg: \"Not found\" }; }\n * catch (e) {\n * const domError = ensureDOMException(e);\n * console.log(domError.message);\n * // \"DOMException Wrapped: Complex Object [object Object]...\"\n * }\n */\nexport function ensureDOMException(\n error_data: unknown,\n name: string = 'AbortError',\n): DOMException & {cause?: unknown} {\n const extract = extractErrorInfo(error_data);\n\n // Return DOMException directly\n if (extract.type_code === 1) {\n return error_data as DOMException & {cause?: unknown};\n }\n\n // Convert Error to DOMException with stack preservation\n if (extract.type_code === 0) {\n const e = error_data as Error;\n const dome = new DOMException(e.message);\n\n if ('stack' in e && typeof e.stack === 'string') {\n dome.stack = e.stack;\n }\n\n dome.cause = e;\n return dome as DOMException & {cause?: unknown};\n }\n\n // Wrap non-Error types in DOMException\n const error_message = `DOMException Wrapped: ${extract.message}`;\n const final_error = new DOMException(error_message, name);\n final_error.cause = error_data;\n\n return final_error as DOMException & {cause?: unknown};\n}\n\n/**\n * Ensures that the captured value is an Error instance. If not, it wraps the value in an Error object that includes the original information.\n * @param error_data - The value caught by the try...catch block (typically of type unknown).\n * @returns An object guaranteed to be of type Error, with an optional 'cause' property.\n */\nexport function ensureError(error_data: unknown): Error & {cause?: unknown} {\n const extract = extractErrorInfo(error_data);\n if (extract.type_code === 1 || extract.type_code === 0) {\n return error_data as Error & {cause?: unknown};\n }\n let error_message = extract.message;\n if (extract.type_code === 4) {\n error_message = `Wrapped: ${error_message}`;\n }\n\n const final_error = new Error(error_message);\n final_error.cause = error_data;\n return final_error as Error & {cause?: unknown};\n}\n\n/**\n * Used to wrap unknown type errors caught in try-catch blocks, ensuring the error chain remains intact.\n * @extends Error\n */\nexport class UnknownError extends Error {\n public override readonly cause: unknown;\n\n /**\n * Handles unknown type errors caught in try-catch blocks.\n * @param raw_error - The value caught by the try...catch block, of type unknown.\n * @param message - An optional custom message, which will be the primary message for this UnknownError.\n */\n constructor(raw_error: unknown, message?: string) {\n // 确保一定是 Error 类型 (返回值包含 cause 属性)\n const ensured_error = ensureError(raw_error);\n // 添加自定义消息\n const final_message = message ?? `UnknownError: ${ensured_error.message}`;\n super(final_message);\n this.name = 'UnknownError';\n this.cause = raw_error; // 手动添加,保证兼容性\n\n /* v8 ignore if -- @preserve */\n if (typeof Error.captureStackTrace === 'function') {\n Error.captureStackTrace(this, UnknownError);\n }\n }\n\n /**\n * Static constructor used to quickly create and wrap an UnknownError instance.\n * @param raw_error - The value caught by the try...catch block, of type unknown.\n * @param message - An optional custom message.\n * @returns The wrapped UnknownError instance.\n */\n static from(raw_error: unknown, message?: string): UnknownError {\n // -- 直接调用构造函数 --\n return new UnknownError(raw_error, message);\n }\n\n /**\n * Returns a visual representation of the error (excluding the stack trace).\n * @returns The visual error representation.\n */\n toString(): string {\n const causeString =\n this.cause instanceof Error ? this.cause.toString() : String(this.cause);\n return `${this.name}: ${this.message}\\nCaused by: ${causeString}`;\n }\n}\n","// ========================================\r\n// ./src/helper.ts\r\n// ========================================\r\n\r\nimport {UnknownError} from './unknown-error';\r\nimport type {MaybePromise} from './Utils/type-tool';\r\n\r\n/**\r\n * Checks if a value is a Promise-like object (i.e., \"thenable\").\r\n *\r\n * A value is considered Promise-like if it meets the following conditions:\r\n * 1. It is non-null.\r\n * 2. Its type is 'object' or 'function'.\r\n * 3. It possesses a property named 'then', and the value of this property is a function.\r\n * 4. Attempting to access the 'then' property does not throw an exception.\r\n *\r\n * This function also returns true when a native {@link Promise} instance is passed.\r\n *\r\n * @param value - The value to check.\r\n * @returns True if the value is Promise-like; otherwise, false.\r\n */\r\nexport const isPromiseLike = (\r\n value: unknown,\r\n): value is PromiseLike<unknown> => {\r\n if (\r\n value == null ||\r\n (typeof value !== 'object' && typeof value !== 'function')\r\n )\r\n return false;\r\n const thenable = value as {then?: unknown};\r\n try {\r\n return typeof thenable.then === 'function';\r\n } catch (e) {\r\n return false;\r\n }\r\n};\r\n\r\n/**\r\n * Checks if a value conforms to the standard \"Result object\" structure (Result-like).\r\n *\r\n * A value is considered Result-like if it meets the following conditions:\r\n * 1. It is a non-null 'object' type.\r\n * 2. It must contain a boolean property 'ok'.\r\n * 3. In the success state (ok: true), it must contain the 'value' property and must not contain the 'error' property.\r\n * 4. In the failure state (ok: false), it must contain the 'error' property and must not contain the 'value' property.\r\n *\r\n * @param value - The value to check.\r\n * @returns True if the value conforms to the Result-like structure; otherwise, false.\r\n */\r\nexport const isResultLike = (\r\n value: unknown,\r\n): value is {ok: boolean; value?: unknown; error?: unknown} =>\r\n // 快速排除非对象和 null\r\n typeof value !== 'object' || value === null\r\n ? false\r\n : (() => {\r\n const v = value as Record<string, unknown>;\r\n const ok = v.ok;\r\n if (typeof ok !== 'boolean') return false;\r\n return ok\r\n ? 'value' in v && !('error' in v)\r\n : 'error' in v && !('value' in v);\r\n })();\r\n\r\n\r\n export const wrapError = (e: unknown) =>\r\n e instanceof DOMException && e.name === 'AbortError'\r\n ? e\r\n : UnknownError.from(e);\r\n\r\n/**\r\n * Flushes all pending microtasks and macroscheduled tasks.\r\n * @description\r\n * This utility is particularly useful in testing environments to ensure that all\r\n * asynchronous operations (like Promises or API calls) and their subsequent\r\n * DOM updates have been processed before making assertions.\r\n * It uses `MessageChannel` to bypass the 4ms minimum delay typically\r\n * associated with `setTimeout(fn, 0)` in browsers.\r\n * @returns {Promise<void>} A promise that resolves after the task queue is cleared.\r\n * @example\r\n * ```typescript\r\n * await flushPromises();\r\n * expect(wrapper.text()).toContain('Data Loaded');\r\n * ```\r\n */\r\n/* v8 ignore next -- @preserve */\r\nexport const flushPromises = (): Promise<void> => {\r\n return new Promise((resolve) => queueMacroTask(resolve));\r\n};\r\n\r\n/**\r\n * Dynamically awaits a value based on whether it's PromiseLike or synchronous.\r\n * If the input is PromiseLike, it awaits the value; otherwise, returns the value directly.\r\n * @param value - The value to await or return synchronously\r\n * @returns A Promise containing the resolved value\r\n */\r\nexport const dynamicAwait = async <T>(value: MaybePromise<T>): Promise<T> =>\r\n isPromiseLike(value) ? await value : value;\r\n\r\n/**\r\n * Queues a callback to be executed in the next macro task.\r\n *\r\n * This function provides an optimized way to schedule callbacks with minimal delay:\r\n * 1. In Node.js: Uses `setImmediate` (optimal performance).\r\n * 2. In modern browsers: Uses `MessageChannel` to bypass the 4ms minimum delay of `setTimeout`.\r\n * 3. Fallback: Uses `setTimeout(callback, 0)` for legacy environments.\r\n *\r\n * The implementation batches multiple callbacks into a single macro task to improve performance.\r\n *\r\n * @param callback - The function to execute in the next macro task.\r\n */\r\n/* v8 ignore next -- @preserve */\r\nexport const queueMacroTask = (() => {\r\n // Node.js 优先使用 setImmediate,性能最优\r\n if (typeof setImmediate === 'function') return setImmediate;\r\n\r\n // 浏览器环境用 MessageChannel 模拟,性能优于 setTimeout(无4ms最小延迟)\r\n if (typeof MessageChannel !== 'undefined') {\r\n let queue: Array<() => void> = [];\r\n const channel = new MessageChannel();\r\n let is_pending = false;\r\n\r\n // 批量执行队列中的所有回调,避免多次触发宏任务\r\n const flush = () => {\r\n is_pending = false;\r\n const local_queue = queue;\r\n queue = [];\r\n for (let i = 0; i < local_queue.length; i++) local_queue[i]();\r\n };\r\n\r\n channel.port1.onmessage = flush;\r\n\r\n // 将回调加入队列,仅在队列为空时触发一次宏任务\r\n return (callback: VoidFunction) => {\r\n queue.push(callback);\r\n if (!is_pending) {\r\n is_pending = true;\r\n channel.port2.postMessage(null);\r\n }\r\n };\r\n }\r\n\r\n // 降级:老旧环境用 setTimeout,存在4ms最小延迟\r\n return (callback: VoidFunction) => setTimeout(callback, 0);\r\n})();\r\n"],"names":["extractErrorInfo","error_data","maybeError","message_value","error_message","data_type","type_name","detail","json_string","fallback_info","key","descriptor","value","str_value","details_string","ensureDOMException","name","extract","e","dome","final_error","ensureError","UnknownError","raw_error","message","ensured_error","final_message","causeString","isPromiseLike","thenable","isResultLike","v","ok","wrapError","flushPromises","resolve","queueMacroTask","dynamicAwait","queue","channel","is_pending","flush","local_queue","i","callback"],"mappings":"aAmCO,SAASA,EAAiBC,EAAgC,CAE/D,GACE,OAAO,aAAiB,KACxBA,aAAsB,aAEtB,MAAO,CAAC,UAAW,EAAG,QAAS,EAAA,EAIjC,GAAIA,aAAsB,MACxB,MAAO,CAAC,UAAW,EAAG,QAAS,EAAA,EAIjC,GAAIA,GAAe,KACjB,MAAO,CACL,UAAW,EACX,QAAS,8CAAA,EAKb,GAAI,OAAOA,GAAe,UAEK,OAAO,UAAU,eAAe,KAC3DA,EACA,SAAA,EAGwB,CACxB,MAAMC,EAAaD,EAGnB,GAAI,CACF,MAAME,EAAgBD,EAAW,QAGjC,GAAI,OAAOC,GAAkB,SAC3B,MAAO,CACL,UAAW,EACX,QAASA,CAAA,EAEb,GAGEA,IAAkB,SACjB,OAAOA,GAAkB,UAAY,MAAM,QAAQA,CAAa,GAEjE,MAAO,CACL,UAAW,EAEX,QAAS,OAAOA,CAAa,CAAA,CAGnC,MAAQ,CAER,CACF,CAIF,IAAIC,EACJ,MAAMC,EAAoB,OAAOJ,EAGjC,GAAII,IAAc,UAAYA,IAAc,WAE1CD,EAAgB,cAAcC,CAAS,MAAM,OAAOJ,CAAU,CAAC,OAG5D,CACH,IAAIK,EACJ,GAAI,CAEFA,EAAY,OAAO,UAAU,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B,aAAa,cAAgB,EAAE,OAAS,aACpC,EACAX,EAAa,KAAK,CAAC,EAkBZY,EAAgB,IACpB,IAAI,QAASC,GAAYC,EAAeD,CAAO,CAAC,EAS5CE,EAAe,MAAUzB,GACpCgB,EAAchB,CAAK,EAAI,MAAMA,EAAQA,EAe1BwB,GAAkB,IAAM,CAEnC,GAAI,OAAO,cAAiB,WAAY,OAAO,aAG/C,GAAI,OAAO,eAAmB,IAAa,CACzC,IAAIE,EAA2B,CAAA,EAC/B,MAAMC,EAAU,IAAI,eACpB,IAAIC,EAAa,GAGjB,MAAMC,EAAQ,IAAM,CAClBD,EAAa,GACb,MAAME,EAAcJ,EACpBA,EAAQ,CAAA,EACR,QAASK,EAAI,EAAGA,EAAID,EAAY,OAAQC,IAAKD,EAAYC,CAAC,EAAA,CAC5D,EAEA,OAAAJ,EAAQ,MAAM,UAAYE,EAGlBG,GAA2B,CACjCN,EAAM,KAAKM,CAAQ,EACdJ,IACHA,EAAa,GACbD,EAAQ,MAAM,YAAY,IAAI,EAElC,CACF,CAGA,OAAQK,GAA2B,WAAWA,EAAU,CAAC,CAC3D,GAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-8JVtLN0O.mjs","sources":["../../src/Reader/local.ts"],"sourcesContent":["// ========================================\r\n// ./src/Reader/local.ts\r\n// ========================================\r\nimport type {\r\n Reader,\r\n AsyncReader,\r\n ReaderT,\r\n AsyncReaderT,\r\n AnyReader,\r\n AnyReaderT,\r\n} from './types';\r\n\r\n/**\r\n * Implements the local function for ReaderT type.\r\n * @typeParam R - Environment type\r\n * @typeParam E - Error type\r\n * @typeParam A - Result type\r\n * @param reader - Original ReaderT\r\n * @param f_mod - Environment modification function that takes the current environment and returns a modified one\r\n * @returns A new ReaderT that executes with the modified environment\r\n */\r\nexport function local<R, E, A>(\r\n reader: ReaderT<R, E, A>,\r\n f_mod: (env: R) => R,\r\n): ReaderT<R, E, A>;\r\n\r\n/**\r\n * Implements the local function for AsyncReaderT type.\r\n * @typeParam R - Environment type\r\n * @typeParam E - Error type\r\n * @typeParam A - Result type\r\n * @param reader - Original AsyncReaderT\r\n * @param f_mod - Environment modification function that takes the current environment and returns a modified one\r\n * @returns A new AsyncReaderT that executes with the modified environment\r\n */\r\nexport function local<R, E, A>(\r\n reader: AsyncReaderT<R, E, A>,\r\n f_mod: (env: R) => R,\r\n): AsyncReaderT<R, E, A>;\r\n\r\n/**\r\n * Implements the local function for Reader type.\r\n * @typeParam R - Environment type\r\n * @typeParam A - Result type\r\n * @param reader - Original Reader\r\n * @param f_mod - Environment modification function that takes the current environment and returns a modified one\r\n * @returns A new Reader that executes with the modified environment\r\n */\r\nexport function local<R, A>(\r\n reader: Reader<R, A>,\r\n f_mod: (env: R) => R,\r\n): Reader<R, A>;\r\n\r\n/**\r\n * Implements the local function for AsyncReader type.\r\n * @typeParam R - Environment type\r\n * @typeParam A - Result type\r\n * @param reader - Original AsyncReader\r\n * @param f_mod - Environment modification function that takes the current environment and returns a modified one\r\n * @returns A new AsyncReader that executes with the modified environment\r\n */\r\nexport function local<R, A>(\r\n reader: AsyncReader<R, A>,\r\n f_mod: (env: R) => R,\r\n): AsyncReader<R, A>;\r\n\r\n/**\r\n * Generic implementation of the local function.\r\n *\r\n * This implementation handles all types of Reader and ReaderT, providing type safety through overloads.\r\n * It creates a new function that takes an environment, applies the modification function first,\r\n * then calls the original reader with the modified environment.\r\n *\r\n * @typeParam R - Environment type\r\n * @typeParam A - Result type\r\n * @typeParam E - Error type (only for ReaderT)\r\n * @param reader_like - Original Reader or ReaderT function\r\n * @param f_mod - Environment modification function\r\n * @returns A new Reader or ReaderT function\r\n */\r\nexport function local<R, A, E, T extends AnyReader<R, A> | AnyReaderT<R, E, A>>(\r\n reader_like: T,\r\n f_mod: (env: R) => R,\r\n): T {\r\n return ((env: R) => {\r\n const modified_env = f_mod(env);\r\n return reader_like(modified_env);\r\n }) as T;\r\n}\r\n"],"names":["local","reader_like","f_mod","env","modified_env"],"mappings":"AAgFO,SAASA,EACdC,GACAC,GACG;AACH,UAAQ,CAACC,MAAW;AAClB,UAAMC,IAAeF,EAAMC,CAAG;AAC9B,WAAOF,EAAYG,CAAY;AAAA,EACjC;AACF;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-Da4yU-nE.cjs","sources":["../../src/Reader/local.ts"],"sourcesContent":["// ========================================\r\n// ./src/Reader/local.ts\r\n// ========================================\r\nimport type {\r\n Reader,\r\n AsyncReader,\r\n ReaderT,\r\n AsyncReaderT,\r\n AnyReader,\r\n AnyReaderT,\r\n} from './types';\r\n\r\n/**\r\n * Implements the local function for ReaderT type.\r\n * @typeParam R - Environment type\r\n * @typeParam E - Error type\r\n * @typeParam A - Result type\r\n * @param reader - Original ReaderT\r\n * @param f_mod - Environment modification function that takes the current environment and returns a modified one\r\n * @returns A new ReaderT that executes with the modified environment\r\n */\r\nexport function local<R, E, A>(\r\n reader: ReaderT<R, E, A>,\r\n f_mod: (env: R) => R,\r\n): ReaderT<R, E, A>;\r\n\r\n/**\r\n * Implements the local function for AsyncReaderT type.\r\n * @typeParam R - Environment type\r\n * @typeParam E - Error type\r\n * @typeParam A - Result type\r\n * @param reader - Original AsyncReaderT\r\n * @param f_mod - Environment modification function that takes the current environment and returns a modified one\r\n * @returns A new AsyncReaderT that executes with the modified environment\r\n */\r\nexport function local<R, E, A>(\r\n reader: AsyncReaderT<R, E, A>,\r\n f_mod: (env: R) => R,\r\n): AsyncReaderT<R, E, A>;\r\n\r\n/**\r\n * Implements the local function for Reader type.\r\n * @typeParam R - Environment type\r\n * @typeParam A - Result type\r\n * @param reader - Original Reader\r\n * @param f_mod - Environment modification function that takes the current environment and returns a modified one\r\n * @returns A new Reader that executes with the modified environment\r\n */\r\nexport function local<R, A>(\r\n reader: Reader<R, A>,\r\n f_mod: (env: R) => R,\r\n): Reader<R, A>;\r\n\r\n/**\r\n * Implements the local function for AsyncReader type.\r\n * @typeParam R - Environment type\r\n * @typeParam A - Result type\r\n * @param reader - Original AsyncReader\r\n * @param f_mod - Environment modification function that takes the current environment and returns a modified one\r\n * @returns A new AsyncReader that executes with the modified environment\r\n */\r\nexport function local<R, A>(\r\n reader: AsyncReader<R, A>,\r\n f_mod: (env: R) => R,\r\n): AsyncReader<R, A>;\r\n\r\n/**\r\n * Generic implementation of the local function.\r\n *\r\n * This implementation handles all types of Reader and ReaderT, providing type safety through overloads.\r\n * It creates a new function that takes an environment, applies the modification function first,\r\n * then calls the original reader with the modified environment.\r\n *\r\n * @typeParam R - Environment type\r\n * @typeParam A - Result type\r\n * @typeParam E - Error type (only for ReaderT)\r\n * @param reader_like - Original Reader or ReaderT function\r\n * @param f_mod - Environment modification function\r\n * @returns A new Reader or ReaderT function\r\n */\r\nexport function local<R, A, E, T extends AnyReader<R, A> | AnyReaderT<R, E, A>>(\r\n reader_like: T,\r\n f_mod: (env: R) => R,\r\n): T {\r\n return ((env: R) => {\r\n const modified_env = f_mod(env);\r\n return reader_like(modified_env);\r\n }) as T;\r\n}\r\n"],"names":["local","reader_like","f_mod","env","modified_env"],"mappings":"aAgFO,SAASA,EACdC,EACAC,EACG,CACH,OAASC,GAAW,CAClB,MAAMC,EAAeF,EAAMC,CAAG,EAC9B,OAAOF,EAAYG,CAAY,CACjC,EACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-B7X_LBjM.cjs","sources":["../../src/Resource/types.ts"],"sourcesContent":["// ========================================\n// ./src/Resource/types.ts\n// ========================================\n\n/* eslint-disable @typescript-eslint/no-empty-object-type */\n\nimport type {MaybePromise} from '../Utils/type-tool';\n\n/**\n * Marker interface for opened state.\n * @public\n */\nexport interface StateOpened {}\n\n/**\n * Marker interface for closed state.\n */\nexport interface StateClosed {}\n\n/**\n * Marker interface for committed state.\n */\nexport interface StateCommit {}\n\n/**\n * Marker interface for rolled back state.\n */\nexport interface StateRollback {}\n\n// ------ 清理函数类型 ------\n\n/**\n * Synchronous cleanup function type.\n * @typeParam T - The type of the data to clean up\n */\nexport type Cleaner<T> = (data: T) => void;\n\n/**\n * Asynchronous cleanup function type.\n * @typeParam T - The type of the data to clean up\n */\nexport type AsyncCleaner<T> = (data: T) => PromiseLike<void> | void;\n\n/**\n * Union type for any cleanup function (synchronous or asynchronous).\n * @typeParam T - The type of the data to clean up\n */\nexport type AnyCleaner<T> = Cleaner<T> | AsyncCleaner<T>;\n\n// ------ 事务函数类型 ------\n\n/**\n * Synchronous commit function type.\n * @typeParam T - The type of the transaction data\n */\nexport type CommitUp<T> = (data: T) => void;\n\n/**\n * Synchronous rollback function type.\n * @typeParam T - The type of the transaction data\n */\nexport type RollbackUp<T> = (data: T) => void;\n\n/**\n * Asynchronous commit function type.\n * @typeParam T - The type of the transaction data\n */\nexport type AsyncCommitUp<T> = (data: T) => MaybePromise<void>;\n\n/**\n * Asynchronous rollback function type.\n * @typeParam T - The type of the transaction data\n */\nexport type AsyncRollbackUp<T> = (data: T) => MaybePromise<void>;\n\n// ------ 联合类型 ------\n\n/**\n * Union type for any commit function (synchronous or asynchronous).\n * @typeParam T - The type of the transaction data\n */\nexport type AnyCommitUp<T> = CommitUp<T> | AsyncCommitUp<T>;\n\n/**\n * Union type for any rollback function (synchronous or asynchronous).\n * @typeParam T - The type of the transaction data\n */\nexport type AnyRollbackUp<T> = RollbackUp<T> | AsyncRollbackUp<T>;\n\n// ------ 空 ------\n/**\n * A unique symbolic constant representing the absence of resources.\n * * @remarks\n * This is used as a placeholder within a `Resource` context to indicate\n * that the resource pool is exhausted or no resource is available.\n */\nexport const NONE = Symbol('None');\n\n/**\n * Represents the type of the {@link NONE} constant.\n * Use this type for type guards or function signatures that might return the `NONE` placeholder.\n */\nexport type NoneType = typeof NONE;\n"],"names":["NONE"],"mappings":"aAgGO,MAAMA,EAAO,OAAO,MAAM"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-DE2SnSbz.mjs","sources":["../../src/Resource/types.ts"],"sourcesContent":["// ========================================\n// ./src/Resource/types.ts\n// ========================================\n\n/* eslint-disable @typescript-eslint/no-empty-object-type */\n\nimport type {MaybePromise} from '../Utils/type-tool';\n\n/**\n * Marker interface for opened state.\n * @public\n */\nexport interface StateOpened {}\n\n/**\n * Marker interface for closed state.\n */\nexport interface StateClosed {}\n\n/**\n * Marker interface for committed state.\n */\nexport interface StateCommit {}\n\n/**\n * Marker interface for rolled back state.\n */\nexport interface StateRollback {}\n\n// ------ 清理函数类型 ------\n\n/**\n * Synchronous cleanup function type.\n * @typeParam T - The type of the data to clean up\n */\nexport type Cleaner<T> = (data: T) => void;\n\n/**\n * Asynchronous cleanup function type.\n * @typeParam T - The type of the data to clean up\n */\nexport type AsyncCleaner<T> = (data: T) => PromiseLike<void> | void;\n\n/**\n * Union type for any cleanup function (synchronous or asynchronous).\n * @typeParam T - The type of the data to clean up\n */\nexport type AnyCleaner<T> = Cleaner<T> | AsyncCleaner<T>;\n\n// ------ 事务函数类型 ------\n\n/**\n * Synchronous commit function type.\n * @typeParam T - The type of the transaction data\n */\nexport type CommitUp<T> = (data: T) => void;\n\n/**\n * Synchronous rollback function type.\n * @typeParam T - The type of the transaction data\n */\nexport type RollbackUp<T> = (data: T) => void;\n\n/**\n * Asynchronous commit function type.\n * @typeParam T - The type of the transaction data\n */\nexport type AsyncCommitUp<T> = (data: T) => MaybePromise<void>;\n\n/**\n * Asynchronous rollback function type.\n * @typeParam T - The type of the transaction data\n */\nexport type AsyncRollbackUp<T> = (data: T) => MaybePromise<void>;\n\n// ------ 联合类型 ------\n\n/**\n * Union type for any commit function (synchronous or asynchronous).\n * @typeParam T - The type of the transaction data\n */\nexport type AnyCommitUp<T> = CommitUp<T> | AsyncCommitUp<T>;\n\n/**\n * Union type for any rollback function (synchronous or asynchronous).\n * @typeParam T - The type of the transaction data\n */\nexport type AnyRollbackUp<T> = RollbackUp<T> | AsyncRollbackUp<T>;\n\n// ------ 空 ------\n/**\n * A unique symbolic constant representing the absence of resources.\n * * @remarks\n * This is used as a placeholder within a `Resource` context to indicate\n * that the resource pool is exhausted or no resource is available.\n */\nexport const NONE = Symbol('None');\n\n/**\n * Represents the type of the {@link NONE} constant.\n * Use this type for type guards or function signatures that might return the `NONE` placeholder.\n */\nexport type NoneType = typeof NONE;\n"],"names":["NONE"],"mappings":"AAgGO,MAAMA,IAAO,OAAO,MAAM;"}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("./chunks/helper-tsqZMRHW.cjs"),m=require("./subpath/FetchQ.cjs"),g=require("./subpath/Maybe.cjs"),S=require("./subpath/Result.cjs"),b=require("./subpath/Resource.cjs"),k=require("./subpath/TxScope.cjs"),w=require("./subpath/Reader.cjs"),F=require("./subpath/ReaderT.cjs"),x=require("./subpath/Lazy.cjs"),R=require("./subpath/Fit.cjs"),f=require("./chunks/Errors-BWEYu-AB.cjs"),A=require("./subpath/Arr.cjs"),O=require("./subpath/Str.cjs"),L=require("./subpath/Sets.cjs"),B=require("./subpath/Maps.cjs"),t=require("./subpath/Utils.cjs"),c=require("./chunks/base-r6kn0B0D.cjs"),a=require("./chunks/Math-CWZVxSF-.cjs"),i=require("./subpath/Concurrent.cjs"),E=require("./chunks/delay-CG3cD7bk.cjs"),n=require("./subpath/Reactive.cjs"),_=Symbol("Empty");class d extends Error{constructor(e){super(e),this.name="SecretError"}}class p{#e;constructor(e){this.#e=e,Object.seal(this)}static make(e){return new p(e)}static reveal(e){if(e.#e==_)throw new d("Attempt to access the deleted secret value.");return e.#e}static destroy(e){e.#e=_}static dispose(e,r){try{const s=p.reveal(e);return r(s)}finally{p.destroy(e)}}static async disposeAsync(e,r){try{const s=p.reveal(e);return await r(s)}finally{p.destroy(e)}}toJSON(){throw new d("Secret values cannot be serialized via toJSON()")}toString(){throw new d("Secret values cannot be converted to String via toString()")}[Symbol.for("nodejs.util.inspect.custom")](){throw new d("Secret values cannot be inspected via console.log")}valueOf(){throw new d("Secret values cannot be converted to Primitive via valueOf()")}[Symbol.toPrimitive](e){throw new d(`Secret values cannot be converted to Primitive via [Symbol.toPrimitive] (Hint: ${e})`)}get[Symbol.toStringTag](){throw new d("Secret values cannot be inspected via [Symbol.toStringTag]")}[Symbol.dispose](){this.#e=_}}class C{queue_data=[];head_idx=0;get size(){return this.queue_data.length-this.head_idx}isEmpty(){return this.head_idx>=this.queue_data.length}peek(){return this.queue_data[this.head_idx]??null}enqueue(e){this.queue_data.push(e)}dequeue(){if(this.isEmpty())return null;const e=this.queue_data[this.head_idx];return this.head_idx++,this.head_idx>this.queue_data.length/2&&(this.queue_data.splice(0,this.head_idx),this.head_idx=0),e}clear(){this.queue_data.length=0,this.head_idx=0}toArray(){return this.queue_data.slice(this.head_idx)}}class v{buffer=new Array(16);head_idx=0;tail_idx=0;count=0;get size(){return this.count}isEmpty(){return this.count===0}peekFront(){return this.isEmpty()?null:this.buffer[this.head_idx]}peekBack(){if(this.isEmpty())return null;const e=(this.tail_idx-1+this.buffer.length)%this.buffer.length;return this.buffer[e]}pushFront(e){this.ensureCapacity(),this.head_idx=(this.head_idx-1+this.buffer.length)%this.buffer.length,this.buffer[this.head_idx]=e,this.count++}pushBack(e){this.ensureCapacity(),this.buffer[this.tail_idx]=e,this.tail_idx=(this.tail_idx+1)%this.buffer.length,this.count++}popFront(){if(this.isEmpty())return null;const e=this.buffer[this.head_idx];return this.buffer[this.head_idx]=void 0,this.head_idx=(this.head_idx+1)%this.buffer.length,this.count--,e}popBack(){if(this.isEmpty())return null;this.tail_idx=(this.tail_idx-1+this.buffer.length)%this.buffer.length;const e=this.buffer[this.tail_idx];return this.buffer[this.tail_idx]=void 0,this.count--,e}clear(){for(let e=0;e<this.buffer.length;e++)this.buffer[e]=void 0;this.head_idx=0,this.tail_idx=0,this.count=0}toArray(){const e=new Array(this.count);for(let r=0;r<this.count;r++){const s=(this.head_idx+r)%this.buffer.length;e[r]=this.buffer[s]}return e}ensureCapacity(){if(this.count===this.buffer.length){const e=this.buffer.length,r=e*2,s=new Array(r);for(let o=0;o<this.count;o++){const l=(this.head_idx+o)%e;s[o]=this.buffer[l]}this.buffer=s,this.head_idx=0,this.tail_idx=this.count}}}class D{heap_data=[];comparer;constructor(e){this.comparer=e}get size(){return this.heap_data.length}isEmpty(){return this.heap_data.length===0}peek(){return this.heap_data[0]??null}push(e){this.heap_data.push(e),this.siftUp(this.heap_data.length-1)}pop(){if(this.heap_data.length===0)return null;const e=this.heap_data[0],r=this.heap_data.pop();return this.heap_data.length>0&&(this.heap_data[0]=r,this.siftDown(0)),e}siftUp(e){const r=this.heap_data[e];for(;e>0;){const s=e-1>>1;if(this.comparer(r,this.heap_data[s])>=0)break;this.heap_data[e]=this.heap_data[s],e=s}this.heap_data[e]=r}siftDown(e){const r=this.heap_data.length,s=this.heap_data[e];for(;;){const o=(e<<1)+1,l=o+1;let h=e;if(o<r&&this.comparer(this.heap_data[o],s)<0&&(h=o),l<r&&this.comparer(this.heap_data[l],this.heap_data[h])<0&&(h=l),h===e)break;this.heap_data[e]=this.heap_data[h],e=h}this.heap_data[e]=s}}class q{stack_data=[];get size(){return this.stack_data.length}isEmpty(){return this.stack_data.length===0}peek(){return this.stack_data[this.stack_data.length-1]??null}push(e){this.stack_data.push(e)}pop(){return this.stack_data.pop()??null}clear(){this.stack_data.length=0}toArray(){return[...this.stack_data]}}class N{parent=new Map;rank=new Map;count=0;get size(){return this.count}makeSet(e){this.parent.has(e)||(this.parent.set(e,e),this.rank.set(e,0),this.count++)}find(e){if(!this.parent.has(e))return null;let r=e;for(;this.parent.get(r)!==r;)r=this.parent.get(r);for(;e!==r;){const s=this.parent.get(e);this.parent.set(e,r),e=s}return r}union(e,r){const s=this.find(e),o=this.find(r);if(s===null||o===null||s===o)return!1;const l=this.rank.get(s),h=this.rank.get(o);return l<h?this.parent.set(s,o):l>h?this.parent.set(o,s):(this.parent.set(o,s),this.rank.set(s,l+1)),this.count--,!0}isConnected(e,r){const s=this.find(e),o=this.find(r);return s!==null&&o!==null&&s===o}contains(e){return this.parent.has(e)}clear(){this.parent.clear(),this.rank.clear(),this.count=0}getSetMembers(e){const r=this.find(e);if(r===null)return null;const s=new Array;for(const[o]of this.parent)this.find(o)===r&&s.push(o);return s}getAllSets(){const e=new Map;for(const r of this.parent.keys()){const s=this.find(r);e.has(s)||e.set(s,new Array),e.get(s).push(r)}return Array.from(e.values())}}exports.UnknownError=u.UnknownError;exports.dynamicAwait=u.dynamicAwait;exports.ensureDOMException=u.ensureDOMException;exports.ensureError=u.ensureError;exports.extractErrorInfo=u.extractErrorInfo;exports.flushPromises=u.flushPromises;exports.isPromiseLike=u.isPromiseLike;exports.isResultLike=u.isResultLike;exports.queueMacroTask=u.queueMacroTask;exports.FetchQ=m.FetchQ;exports.QContinue=m.QContinue;exports.QStop=m.QStop;exports.Maybe=g.__export__;exports.Result=S.__export__;exports.Resource=b.__exportResource__;exports.TxScope=k.__exportTxScope__;exports.Reader=w.__exportReader__;exports.ReaderT=F.__exportReaderT__;exports.Lazy=x.lazy;exports.f=R.__export__;exports.FlowCompletionError=f.FlowCompletionError;exports.LockError=f.LockError;exports.MutexError=f.MutexError;exports.ParameterError=f.ParameterError;exports.RWLockError=f.RWLockError;exports.UseAfterFreeError=f.UseAfterFreeError;exports.Arr=A.__export__;exports.Str=O.String;exports.Sets=L.Set;exports.Maps=B.Map;exports.CLONE_DEFAULT=t.CLONE_DEFAULT;exports.CLONE_FILTER=t.CLONE_FILTER;exports.CLONE_HOLE=t.CLONE_HOLE;exports.Debounced=t.Debounced;exports.MERGE_DEFAULT=t.MERGE_DEFAULT;exports.MERGE_SKIP=t.MERGE_SKIP;exports.NO_ERROR=t.NO_ERROR;exports.SKIPPED=t.SKIPPED;exports.__=t.__;exports.clone=t.clone;exports.cloneDeep=t.cloneDeep;exports.cloneDeepWith=t.cloneDeepWith;exports.createDebounce=t.createDebounce;exports.createThrottle=t.createThrottle;exports.curry=t.curry;exports.defer=t.defer;exports.findKey=t.findKey;exports.flattenObject=t.flattenObject;exports.getTag=t.getTag;exports.internalMerge=t.internalMerge;exports.invert=t.invert;exports.isArray=t.isArray;exports.isArrayBuffer=t.isArrayBuffer;exports.isArrayIndex=t.isArrayIndex;exports.isAsyncIterable=t.isAsyncIterable;exports.isBlob=t.isBlob;exports.isBoolean=t.isBoolean;exports.isBrowser=t.isBrowser;exports.isBuffer=t.isBuffer;exports.isClient=t.isClient;exports.isDate=t.isDate;exports.isEmail=t.isEmail;exports.isEmpty=t.isEmpty;exports.isEmptyObject=t.isEmptyObject;exports.isEqual=t.isEqual;exports.isEqualWith=t.isEqualWith;exports.isError=t.isError;exports.isFile=t.isFile;exports.isFinite=t.isFinite;exports.isFunction=t.isFunction;exports.isInstanceOf=t.isInstanceOf;exports.isInteger=t.isInteger;exports.isIterable=t.isIterable;exports.isJSON=t.isJSON;exports.isJSONArray=t.isJSONArray;exports.isJSONObject=t.isJSONObject;exports.isJSONValue=t.isJSONValue;exports.isLength=t.isLength;exports.isMap=t.isMap;exports.isNil=t.isNil;exports.isNode=t.isNode;exports.isNotNil=t.isNotNil;exports.isNotNullish=t.isNotNullish;exports.isNull=t.isNull;exports.isNumber=t.isNumber;exports.isObject=t.isObject;exports.isPlainObject=t.isPlainObject;exports.isPrimitive=t.isPrimitive;exports.isPromise=t.isPromise;exports.isPropertyKey=t.isPropertyKey;exports.isRegExp=t.isRegExp;exports.isSafeInteger=t.isSafeInteger;exports.isSerializable=t.isSerializable;exports.isSet=t.isSet;exports.isString=t.isString;exports.isSymbol=t.isSymbol;exports.isTypedArray=t.isTypedArray;exports.isUUID=t.isUUID;exports.isUndefined=t.isUndefined;exports.isUrl=t.isUrl;exports.isWeakMap=t.isWeakMap;exports.isWeakSet=t.isWeakSet;exports.mapKeys=t.mapKeys;exports.mapValues=t.mapValues;exports.merge=t.merge;exports.mergeWith=t.mergeWith;exports.omit=t.omit;exports.omitBy=t.omitBy;exports.pick=t.pick;exports.pickBy=t.pickBy;exports.pipe=t.pipe;exports.pipeAsync=t.pipeAsync;exports.run=t.run;exports.runAsync=t.runAsync;exports.toCamelCaseKeys=t.toCamelCaseKeys;exports.toSnakeCaseKeys=t.toSnakeCaseKeys;exports.useRAF=t.useRAF;exports.after=c.after;exports.ary=c.ary;exports.asyncNoop=c.asyncNoop;exports.attempt=c.attempt;exports.before=c.before;exports.identity=c.identity;exports.memoize=c.memoize;exports.negate=c.negate;exports.noop=c.noop;exports.once=c.once;exports.partial=c.partial;exports.partialRight=c.partialRight;exports.rest=c.rest;exports.spread=c.spread;exports.unary=c.unary;exports.angleDist=a.angleDist;exports.approxEqual=a.approxEqual;exports.bezier2=a.bezier2;exports.clamp=a.clamp;exports.gcd=a.gcd;exports.getDistance=a.getDistance;exports.getDistanceSq=a.getDistanceSq;exports.inRange=a.inRange;exports.isEven=a.isEven;exports.isOdd=a.isOdd;exports.lcm=a.lcm;exports.lerp=a.lerp;exports.mapRange=a.mapRange;exports.mean=a.mean;exports.meanBy=a.meanBy;exports.median=a.median;exports.medianBy=a.medianBy;exports.normalize=a.normalize;exports.random=a.random;exports.randomInt=a.randomInt;exports.range=a.range;exports.rangeRight=a.rangeRight;exports.round=a.round;exports.stdDev=a.stdDev;exports.sum=a.sum;exports.sumBy=a.sumBy;exports.toDegrees=a.toDegrees;exports.toRadians=a.toRadians;exports.wrapAngle=a.wrapAngle;exports.Barrier=i.Barrier;exports.CHANNEL_CLOSED=i.CHANNEL_CLOSED;exports.Channel=i.Channel;exports.CircuitBreaker=i.CircuitBreaker;exports.CircuitBreakerOpenError=i.CircuitBreakerOpenError;exports.ConditionVariable=i.ConditionVariable;exports.CyclicBarrier=i.CyclicBarrier;exports.DEBUG_CONDITION_VARIABLE=i.DEBUG_CONDITION_VARIABLE;exports.DEBUG_MUTEX=i.DEBUG_MUTEX;exports.DEBUG_RW_LOCK=i.DEBUG_RW_LOCK;exports.DEBUG_SEMAPHORE=i.DEBUG_SEMAPHORE;exports.LeakyBucket=i.LeakyBucket;exports.LeakyBucketReject=i.LeakyBucketReject;exports.Limiter=i.Limiter;exports.LockGuard=i.LockGuard;exports.MAP_SKIP=i.MAP_SKIP;exports.Mutex=i.Mutex;exports.PermitGuard=i.PermitGuard;exports.ReadLockGuard=i.ReadLockGuard;exports.ReadWriteLock=i.ReadWriteLock;exports.Scheduler=i.Scheduler;exports.Semaphore=i.Semaphore;exports.SlidingWindow=i.SlidingWindow;exports.TaskScope=i.TaskScope;exports.TokenBucket=i.TokenBucket;exports.WriteLockGuard=i.WriteLockGuard;exports.asyncAny=i.asyncAny;exports.asyncEvery=i.asyncEvery;exports.asyncFirst=i.asyncFirst;exports.asyncMap=i.asyncMap;exports.asyncMapIterable=i.asyncMapIterable;exports.asyncRace=i.asyncRace;exports.asyncSettle=i.asyncSettle;exports.asyncSome=i.asyncSome;exports.asyncTimeout=i.asyncTimeout;exports.asyncWaitFor=i.asyncWaitFor;exports.select=i.select;exports.withCondition=i.withCondition;exports.delay=E.delay;exports.delaySafe=E.delaySafe;exports.sleep=E.sleep;exports.BehaviorFlow=n.BehaviorFlow;exports.ColdFlow=n.ColdFlow;exports.Continue=n.Continue;exports.EventEmitter=n.EventEmitter;exports.Flow=n.Flow;exports.FlowContinue=n.FlowContinue;exports.FlowStop=n.FlowStop;exports.SerialColdFlow=n.SerialColdFlow;exports.SerialFlow=n.SerialFlow;exports.Stop=n.Stop;exports.combineLatestFlow=n.combineLatestFlow;exports.concatFlow=n.concatFlow;exports.expBackoff=n.expBackoff;exports.expJitter=n.expJitter;exports.forkJoinFlow=n.forkJoinFlow;exports.from=n.from;exports.fromProducer=n.fromProducer;exports.fromSerialProducer=n.fromSerialProducer;exports.mergeFlow=n.mergeFlow;exports.of=n.of;exports.pacer=n.pacer;exports.raceFlow=n.raceFlow;exports.retry=n.retry;exports.withLatestFromFlow=n.withLatestFromFlow;exports.zipFlow=n.zipFlow;exports.Deque=v;exports.DisjointSet=N;exports.EMPTY=_;exports.Heap=D;exports.Queue=C;exports.Secret=p;exports.SecretError=d;exports.Stack=q;
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/Other/secret.ts","../src/Other/queue.ts","../src/Other/deque.ts","../src/Other/heap.ts","../src/Other/stack.ts","../src/Other/disjointSet.ts"],"sourcesContent":["// ========================================\r\n// ./src/Other/secret.ts\r\n// ========================================\r\n\r\n/**\r\n * A unique Symbol used to represent the state of a Secret instance when its original\r\n * sensitive value has been destroyed or erased from memory.\r\n * @internal\r\n */\r\nexport const EMPTY = Symbol('Empty');\r\n\r\nexport class SecretError extends Error {\r\n constructor(message: string) {\r\n super(message);\r\n this.name = 'SecretError';\r\n }\r\n}\r\n\r\n/**\r\n * A secure container class for sensitive values (T).\r\n *\r\n * The class uses private fields, controlled access, and disposal mechanisms\r\n * to protect data from accidental exposure in logs, serialization, and memory dumps.\r\n *\r\n * @template T The type of the sensitive value being protected.\r\n * @implements {Disposable} (Implicitly, for TypeScript 5.2+ `using` support)\r\n */\r\nexport class Secret<T> {\r\n /**\r\n * The private field storing the sensitive value or the `EMPTY` Symbol if destroyed.\r\n * This is the core mechanism to prevent serialization and accidental console logging.\r\n * @private\r\n */\r\n #original_value: T | typeof EMPTY;\r\n\r\n /**\r\n * Creates a new Secret container for the given sensitive value.\r\n *\r\n * @param {T} value The sensitive value (e.g., an API key or password) to be secured.\r\n */\r\n constructor(value: T) {\r\n this.#original_value = value;\r\n Object.seal(this);\r\n }\r\n\r\n /**\r\n * A factory method to create a new Secret instance.\r\n *\r\n * @template T The type of the sensitive value.\r\n * @param {T} value The sensitive value to be wrapped.\r\n * @returns {Secret<T>} A new Secret instance containing the value.\r\n */\r\n static make<T>(value: T): Secret<T> {\r\n return new Secret(value);\r\n }\r\n\r\n /**\r\n * Reveals the original sensitive value stored within the Secret container.\r\n * This is the only intended method to retrieve the protected data.\r\n *\r\n * @template T The type of the value being revealed.\r\n * @param {Secret<T>} secret The Secret instance to reveal the value from.\r\n * @returns {T} The original sensitive value.\r\n * @throws {Error} If the Secret value has already been destroyed (`destroy` or `using` block exited).\r\n */\r\n static reveal<T>(secret: Secret<T>): T {\r\n if (secret.#original_value == EMPTY)\r\n throw new SecretError('Attempt to access the deleted secret value.');\r\n\r\n return secret.#original_value;\r\n }\r\n\r\n /**\r\n * Destroys the sensitive value by overwriting its memory location with the `Empty` Symbol.\r\n * This minimizes the duration the sensitive data resides in memory.\r\n *\r\n * After destruction, `reveal()` will throw an error.\r\n *\r\n * @template T The type of the value being destroyed.\r\n * @param {Secret<T>} secret The Secret instance to destroy.\r\n */\r\n static destroy<T>(secret: Secret<T>): void {\r\n secret.#original_value = EMPTY;\r\n }\r\n\r\n /**\r\n * Executes a callback function with the revealed sensitive value and ensures the secret\r\n * is destroyed immediately after the callback completes, regardless of success or failure.\r\n *\r\n * @template T The type of the sensitive value.\r\n * @template R The return type of the callback function.\r\n * @param {Secret<T>} secret The Secret instance to operate on.\r\n * @param {(value: T) => R} callback The function to execute with the revealed value.\r\n * @returns {R} The result of the callback function.\r\n */\r\n static dispose<T, R>(secret: Secret<T>, callback: (value: T) => R): R {\r\n try {\r\n const value = Secret.reveal(secret);\r\n return callback(value);\r\n } finally {\r\n Secret.destroy(secret);\r\n }\r\n }\r\n\r\n /**\r\n * Executes an asynchronous callback function with the revealed sensitive value and ensures the secret\r\n * is destroyed immediately after the callback completes, regardless of success or failure.\r\n *\r\n * @template T The type of the sensitive value.\r\n * @template R The resolved type of the callback function's Promise.\r\n * @param {Secret<T>} secret The Secret instance to operate on.\r\n * @param {(value: T) => Promise<R>} callback The asynchronous function to execute with the revealed value.\r\n * @returns {Promise<R>} A Promise that resolves to the result of the asynchronous callback.\r\n */\r\n static async disposeAsync<T, R>(\r\n secret: Secret<T>,\r\n callback: (value: T) => Promise<R>,\r\n ): Promise<R> {\r\n try {\r\n const value = Secret.reveal(secret);\r\n return await callback(value);\r\n } finally {\r\n Secret.destroy(secret);\r\n }\r\n }\r\n\r\n /**\r\n * Prevents accidental serialization of the secret value via `JSON.stringify()`.\r\n * @throws {SecretError} Always throws an error to prevent serialization.\r\n */\r\n toJSON() {\r\n throw new SecretError('Secret values cannot be serialized via toJSON()');\r\n }\r\n\r\n /**\r\n * Prevents accidental string conversion of the secret value.\r\n * @throws {SecretError} Always throws an error to prevent conversion.\r\n */\r\n toString() {\r\n throw new SecretError(\r\n 'Secret values cannot be converted to String via toString()',\r\n );\r\n }\r\n\r\n /**\r\n * Prevents accidental serialization of the secret value via `console.*`.\r\n * @throws {SecretError} Always throws an error to prevent serialization.\r\n */\r\n [Symbol.for('nodejs.util.inspect.custom')]() {\r\n throw new SecretError('Secret values cannot be inspected via console.log');\r\n }\r\n\r\n /**\r\n * Prevents accidental primitive conversion of the secret value.\r\n * @throws {SecretError} Always throws an error to prevent conversion.\r\n */\r\n valueOf() {\r\n throw new SecretError(\r\n 'Secret values cannot be converted to Primitive via valueOf()',\r\n );\r\n }\r\n\r\n /**\r\n * Prevents accidental primitive conversion of the secret value, respecting the `hint`.\r\n * @param {'string' | 'number' | 'default'} hint The desired conversion hint.\r\n * @throws {SecretError} Always throws an error to prevent conversion.\r\n */\r\n [Symbol.toPrimitive](hint: 'string' | 'number' | 'default') {\r\n throw new SecretError(\r\n `Secret values cannot be converted to Primitive via [Symbol.toPrimitive] (Hint: ${hint})`,\r\n );\r\n }\r\n\r\n /**\r\n * Prevents accidental inspection via `Object.prototype.toString.call()`.\r\n * @throws {SecretError} Always throws an error to prevent inspection.\r\n */\r\n get [Symbol.toStringTag]() {\r\n throw new SecretError(\r\n 'Secret values cannot be inspected via [Symbol.toStringTag]',\r\n );\r\n }\r\n\r\n /**\r\n * Implements the `[Symbol.dispose]` method, making the Secret compatible with\r\n * the TypeScript 5.2+ `using` declaration for automatic resource management.\r\n *\r\n * When a `using` block exits, this method is called, which internally calls `destroy`.\r\n * @internal\r\n */\r\n [Symbol.dispose](): void {\r\n this.#original_value = EMPTY;\r\n }\r\n}\r\n","// ============================================\n// ./src/Other/queue.ts\n// ============================================\n\n/**\n * A FIFO (First-In-First-Out) queue implementation\n * Uses circular buffer optimization to avoid O(n) shift operations\n * @template T The type of elements stored in the queue\n * @note It is recommended not to store `null` values in this queue, as `null` is used\n * by `peek()` and `dequeue()` to indicate an empty queue.\n * Storing `null` makes it impossible to distinguish between \"queue is empty\" and \"actual null value stored\".\n */\nexport class Queue<T> {\n private queue_data: T[] = [];\n private head_idx = 0;\n\n /**\n * Returns the number of elements in the queue\n */\n public get size(): number {\n return this.queue_data.length - this.head_idx;\n }\n\n /**\n * Checks if the queue is empty\n */\n public isEmpty(): boolean {\n return this.head_idx >= this.queue_data.length;\n }\n\n /**\n * Returns the front element without removing it\n * @returns The front element, or null if queue is empty\n */\n public peek(): T | null {\n return this.queue_data[this.head_idx] ?? null;\n }\n\n /**\n * Adds an element to the back of the queue\n */\n public enqueue(item: T): void {\n this.queue_data.push(item);\n }\n\n /**\n * Removes and returns the front element from the queue\n * @returns The front element, or null if queue is empty\n */\n public dequeue(): T | null {\n if (this.isEmpty()) return null;\n const item = this.queue_data[this.head_idx];\n this.head_idx++;\n\n // 当数组前半部分浪费空间超过一半时,裁剪数组以防止内存泄漏\n if (this.head_idx > this.queue_data.length / 2) {\n this.queue_data.splice(0, this.head_idx);\n this.head_idx = 0;\n }\n\n return item;\n }\n\n /**\n * Removes all elements from the queue\n */\n public clear(): void {\n this.queue_data.length = 0;\n this.head_idx = 0;\n }\n\n /**\n * Converts the queue to an array (front element at index 0)\n */\n public toArray(): T[] {\n return this.queue_data.slice(this.head_idx);\n }\n}\n","// ============================================\n// ./src/Other/deque.ts\n// ============================================\n\n/**\n * A double-ended queue (deque) implementation using circular buffer\n * Supports O(1) operations at both ends\n * @template T The type of elements stored in the deque\n * @note It is recommended not to store `null` values in this deque, as `null` is used\n * by `peekFront()`, `peekBack()`, `popFront()`, and `popBack()` to indicate an empty deque.\n * Storing `null` makes it impossible to distinguish between \"deque is empty\" and \"actual null value stored\".\n */\nexport class Deque<T> {\n private buffer: (T | undefined)[] = new Array<T | undefined>(16);\n private head_idx = 0;\n private tail_idx = 0;\n private count = 0;\n\n /**\n * Returns the number of elements in the deque\n */\n public get size(): number {\n return this.count;\n }\n\n /**\n * Checks if the deque is empty\n */\n public isEmpty(): boolean {\n return this.count === 0;\n }\n\n /**\n * Returns the front element without removing it\n * @returns The front element, or null if deque is empty\n */\n public peekFront(): T | null {\n if (this.isEmpty()) return null;\n return this.buffer[this.head_idx] as T;\n }\n\n /**\n * Returns the back element without removing it\n * @returns The back element, or null if deque is empty\n */\n public peekBack(): T | null {\n if (this.isEmpty()) return null;\n const back_idx =\n (this.tail_idx - 1 + this.buffer.length) % this.buffer.length;\n return this.buffer[back_idx] as T;\n }\n\n /**\n * Adds an element to the front of the deque\n */\n public pushFront(item: T): void {\n this.ensureCapacity();\n this.head_idx =\n (this.head_idx - 1 + this.buffer.length) % this.buffer.length;\n this.buffer[this.head_idx] = item;\n this.count++;\n }\n\n /**\n * Adds an element to the back of the deque\n */\n public pushBack(item: T): void {\n this.ensureCapacity();\n this.buffer[this.tail_idx] = item;\n this.tail_idx = (this.tail_idx + 1) % this.buffer.length;\n this.count++;\n }\n\n /**\n * Removes and returns the front element from the deque\n * @returns The front element, or null if deque is empty\n */\n public popFront(): T | null {\n if (this.isEmpty()) return null;\n const item = this.buffer[this.head_idx] as T;\n this.buffer[this.head_idx] = undefined;\n this.head_idx = (this.head_idx + 1) % this.buffer.length;\n this.count--;\n return item;\n }\n\n /**\n * Removes and returns the back element from the deque\n * @returns The back element, or null if deque is empty\n */\n public popBack(): T | null {\n if (this.isEmpty()) return null;\n this.tail_idx =\n (this.tail_idx - 1 + this.buffer.length) % this.buffer.length;\n const item = this.buffer[this.tail_idx] as T;\n this.buffer[this.tail_idx] = undefined;\n this.count--;\n return item;\n }\n\n /**\n * Removes all elements from the deque\n */\n public clear(): void {\n // 清空引用以便垃圾回收\n for (let i = 0; i < this.buffer.length; i++) this.buffer[i] = undefined;\n this.head_idx = 0;\n this.tail_idx = 0;\n this.count = 0;\n }\n\n /**\n * Converts the deque to an array (front element at index 0)\n */\n public toArray(): T[] {\n const result = new Array<T>(this.count);\n for (let i = 0; i < this.count; i++) {\n const idx = (this.head_idx + i) % this.buffer.length;\n result[i] = this.buffer[idx] as T;\n }\n return result;\n }\n\n // -- 当缓冲区满时,扩容为原来的 2 倍 --\n private ensureCapacity(): void {\n if (this.count === this.buffer.length) {\n const old_capacity = this.buffer.length;\n const new_capacity = old_capacity * 2;\n const new_buffer = new Array<T | undefined>(new_capacity);\n\n // 将元素按顺序复制到新缓冲区\n for (let i = 0; i < this.count; i++) {\n const old_idx = (this.head_idx + i) % old_capacity;\n new_buffer[i] = this.buffer[old_idx];\n }\n\n this.buffer = new_buffer;\n this.head_idx = 0;\n this.tail_idx = this.count;\n }\n }\n}\n","// ============================================\r\n// ./src/Other/heap.ts\r\n// ============================================\r\n\r\n/**\r\n * A binary heap implementation with customizable comparison function\r\n * Supports O(log n) push and pop operations\r\n * @template T The type of elements stored in the heap\r\n * @note It is recommended not to store `null` values in this heap, as `null` is used\r\n * by `peek()` and `pop()` to indicate an empty heap.\r\n * Storing `null` makes it impossible to distinguish between \"heap is empty\" and \"actual null value stored\".\r\n */\r\nexport class Heap<T> {\r\n private heap_data: T[] = [];\r\n private readonly comparer: (a: T, b: T) => number;\r\n\r\n /**\r\n * Creates a new heap with the specified comparison function\r\n * @param comparer A comparison function that returns negative if a < b, zero if a === b, positive if a > b\r\n */\r\n constructor(comparer: (a: T, b: T) => number) {\r\n this.comparer = comparer;\r\n }\r\n\r\n /**\r\n * Returns the number of elements in the heap\r\n */\r\n public get size(): number {\r\n return this.heap_data.length;\r\n }\r\n\r\n /**\r\n * Checks if the heap is empty\r\n */\r\n public isEmpty(): boolean {\r\n return this.heap_data.length === 0;\r\n }\r\n\r\n /**\r\n * Returns the top element without removing it\r\n * @returns The top element, or null if heap is empty\r\n */\r\n public peek(): T | null {\r\n return this.heap_data[0] ?? null;\r\n }\r\n\r\n /**\r\n * Adds an element to the heap\r\n */\r\n public push(item: T): void {\r\n this.heap_data.push(item);\r\n this.siftUp(this.heap_data.length - 1);\r\n }\r\n\r\n /**\r\n * Removes and returns the top element from the heap\r\n * @returns The top element, or null if heap is empty\r\n */\r\n public pop(): T | null {\r\n if (this.heap_data.length === 0) return null;\r\n const top = this.heap_data[0];\r\n const last = this.heap_data.pop()!;\r\n\r\n if (this.heap_data.length > 0) {\r\n this.heap_data[0] = last;\r\n this.siftDown(0);\r\n }\r\n return top;\r\n }\r\n\r\n // -- 向上调整,维护堆性质 --\r\n private siftUp(idx: number): void {\r\n const item = this.heap_data[idx];\r\n while (idx > 0) {\r\n const parent = (idx - 1) >> 1;\r\n if (this.comparer(item, this.heap_data[parent]) >= 0) break;\r\n this.heap_data[idx] = this.heap_data[parent];\r\n idx = parent;\r\n }\r\n this.heap_data[idx] = item;\r\n }\r\n\r\n // -- 向下调整,维护堆性质 --\r\n private siftDown(idx: number): void {\r\n const len = this.heap_data.length;\r\n const item = this.heap_data[idx];\r\n while (true) {\r\n const left = (idx << 1) + 1;\r\n const right = left + 1;\r\n let smallest = idx;\r\n\r\n if (left < len && this.comparer(this.heap_data[left], item) < 0)\r\n smallest = left;\r\n\r\n if (\r\n right < len &&\r\n this.comparer(this.heap_data[right], this.heap_data[smallest]) < 0\r\n )\r\n smallest = right;\r\n\r\n if (smallest === idx) break;\r\n this.heap_data[idx] = this.heap_data[smallest];\r\n idx = smallest;\r\n }\r\n this.heap_data[idx] = item;\r\n }\r\n}\r\n","// ============================================\n// ./src/Other/stack.ts\n// ============================================\n\n/**\n * A LIFO (Last-In-First-Out) stack implementation\n * @template T The type of elements stored in the stack\n * @note It is recommended not to store `null` values in this stack, as `null` is used\n * by `peek()` and `pop()` to indicate an empty stack.\n * Storing `null` makes it impossible to distinguish between \"stack is empty\" and \"actual null value stored\".\n */\nexport class Stack<T> {\n private stack_data: T[] = [];\n\n /**\n * Returns the number of elements in the stack\n */\n public get size(): number {\n return this.stack_data.length;\n }\n\n /**\n * Checks if the stack is empty\n */\n public isEmpty(): boolean {\n return this.stack_data.length === 0;\n }\n\n /**\n * Returns the top element without removing it\n * @returns The top element, or null if stack is empty\n */\n public peek(): T | null {\n return this.stack_data[this.stack_data.length - 1] ?? null;\n }\n\n /**\n * Pushes an element onto the top of the stack\n */\n public push(item: T): void {\n this.stack_data.push(item);\n }\n\n /**\n * Removes and returns the top element from the stack\n * @returns The top element, or null if stack is empty\n */\n public pop(): T | null {\n return this.stack_data.pop() ?? null;\n }\n\n /**\n * Removes all elements from the stack\n */\n public clear(): void {\n this.stack_data.length = 0;\n }\n\n /**\n * Converts the stack to an array (top element at the end)\n */\n public toArray(): T[] {\n return [...this.stack_data];\n }\n}\n","// ============================================\r\n// ./src/Other/disjointSet.ts\r\n// ============================================\r\n\r\n/**\r\n * A Disjoint Set Union (Union-Find) data structure with path compression and union by rank\r\n * Efficiently manages and queries disjoint sets with near-constant time operations\r\n * @template T The type of elements stored in the sets\r\n */\r\nexport class DisjointSet<T> {\r\n private parent: Map<T, T> = new Map<T, T>();\r\n private rank: Map<T, number> = new Map<T, number>();\r\n private count: number = 0;\r\n\r\n /**\r\n * Returns the number of distinct sets\r\n */\r\n public get size(): number {\r\n return this.count;\r\n }\r\n\r\n /**\r\n * Creates a new set containing only the given element\r\n * If the element already exists in a set, this operation has no effect\r\n */\r\n public makeSet(item: T): void {\r\n if (this.parent.has(item)) return;\r\n this.parent.set(item, item);\r\n this.rank.set(item, 0);\r\n this.count++;\r\n }\r\n\r\n /**\r\n * Finds the representative (root) of the set containing the given element\r\n * Applies path compression to optimize future queries\r\n * @returns The representative element, or null if the element is not in any set\r\n */\r\n public find(item: T): T | null {\r\n if (!this.parent.has(item)) return null;\r\n\r\n let root = item;\r\n while (this.parent.get(root) !== root) {\r\n root = this.parent.get(root)!;\r\n }\r\n\r\n // -- 路径压缩:将沿途所有节点的父节点直接指向根 --\r\n while (item !== root) {\r\n const next = this.parent.get(item)!;\r\n this.parent.set(item, root);\r\n item = next;\r\n }\r\n\r\n return root;\r\n }\r\n\r\n /**\r\n * Merges the sets containing two elements\r\n * Uses union by rank to keep the tree shallow\r\n * @returns true if the sets were merged (they were different), false if they were already in the same set\r\n */\r\n public union(item1: T, item2: T): boolean {\r\n const root1 = this.find(item1);\r\n const root2 = this.find(item2);\r\n\r\n if (root1 === null || root2 === null || root1 === root2) return false;\r\n\r\n // -- 按秩合并:将秩较小的树合并到秩较大的树 --\r\n const rank1 = this.rank.get(root1)!;\r\n const rank2 = this.rank.get(root2)!;\r\n\r\n if (rank1 < rank2) {\r\n this.parent.set(root1, root2);\r\n } else if (rank1 > rank2) {\r\n this.parent.set(root2, root1);\r\n } else {\r\n this.parent.set(root2, root1);\r\n this.rank.set(root1, rank1 + 1);\r\n }\r\n\r\n this.count--;\r\n return true;\r\n }\r\n\r\n /**\r\n * Checks if two elements are in the same set\r\n * @returns true if both elements exist and are in the same set, false otherwise\r\n */\r\n public isConnected(item1: T, item2: T): boolean {\r\n const root1 = this.find(item1);\r\n const root2 = this.find(item2);\r\n return root1 !== null && root2 !== null && root1 === root2;\r\n }\r\n\r\n /**\r\n * Checks if an element exists in any set\r\n */\r\n public contains(item: T): boolean {\r\n return this.parent.has(item);\r\n }\r\n\r\n /**\r\n * Removes all elements and resets the data structure\r\n */\r\n public clear(): void {\r\n this.parent.clear();\r\n this.rank.clear();\r\n this.count = 0;\r\n }\r\n\r\n /**\r\n * Returns all elements in the same set as the given element\r\n * @returns An array of elements in the same set, or null if the element is not in any set\r\n */\r\n public getSetMembers(item: T): T[] | null {\r\n const root = this.find(item);\r\n if (root === null) return null;\r\n\r\n const members = new Array<T>();\r\n for (const [elem] of this.parent) {\r\n if (this.find(elem) === root) {\r\n members.push(elem);\r\n }\r\n }\r\n return members;\r\n }\r\n\r\n /**\r\n * Returns all sets as an array of arrays\r\n */\r\n public getAllSets(): T[][] {\r\n const sets = new Map<T, T[]>();\r\n\r\n for (const item of this.parent.keys()) {\r\n const root = this.find(item)!;\r\n if (!sets.has(root)) {\r\n sets.set(root, new Array<T>());\r\n }\r\n sets.get(root)!.push(item);\r\n }\r\n\r\n return Array.from(sets.values());\r\n }\r\n}\r\n"],"names":["EMPTY","SecretError","message","Secret","#original_value","value","secret","callback","hint","Queue","item","Deque","back_idx","i","result","idx","old_capacity","new_capacity","new_buffer","old_idx","Heap","comparer","top","last","parent","len","left","right","smallest","Stack","DisjointSet","root","next","item1","item2","root1","root2","rank1","rank2","members","elem","sets"],"mappings":"4zBASaA,EAAQ,OAAO,OAAO,EAE5B,MAAMC,UAAoB,KAAM,CACrC,YAAYC,EAAiB,CAC3B,MAAMA,CAAO,EACb,KAAK,KAAO,aACd,CACF,CAWO,MAAMC,CAAU,CAMrBC,GAOA,YAAYC,EAAU,CACpB,KAAKD,GAAkBC,EACvB,OAAO,KAAK,IAAI,CAClB,CASA,OAAO,KAAQA,EAAqB,CAClC,OAAO,IAAIF,EAAOE,CAAK,CACzB,CAWA,OAAO,OAAUC,EAAsB,CACrC,GAAIA,EAAOF,IAAmBJ,EAC5B,MAAM,IAAIC,EAAY,6CAA6C,EAErE,OAAOK,EAAOF,EAChB,CAWA,OAAO,QAAWE,EAAyB,CACzCA,EAAOF,GAAkBJ,CAC3B,CAYA,OAAO,QAAcM,EAAmBC,EAA8B,CACpE,GAAI,CACF,MAAMF,EAAQF,EAAO,OAAOG,CAAM,EAClC,OAAOC,EAASF,CAAK,CACvB,QAAA,CACEF,EAAO,QAAQG,CAAM,CACvB,CACF,CAYA,aAAa,aACXA,EACAC,EACY,CACZ,GAAI,CACF,MAAMF,EAAQF,EAAO,OAAOG,CAAM,EAClC,OAAO,MAAMC,EAASF,CAAK,CAC7B,QAAA,CACEF,EAAO,QAAQG,CAAM,CACvB,CACF,CAMA,QAAS,CACP,MAAM,IAAIL,EAAY,iDAAiD,CACzE,CAMA,UAAW,CACT,MAAM,IAAIA,EACR,4DAAA,CAEJ,CAMA,CAAC,OAAO,IAAI,4BAA4B,CAAC,GAAI,CAC3C,MA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