@idlebox/common 1.4.19 → 1.4.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/array/{arrayDiff.d.ts → diff.d.ts} +1 -1
- package/lib/array/diff.d.ts.map +1 -0
- package/lib/array/{arrayDiff.js → diff.js} +1 -1
- package/lib/array/diff.js.map +1 -0
- package/lib/array/{arraySame.d.ts → is-same.d.ts} +1 -1
- package/lib/array/is-same.d.ts.map +1 -0
- package/lib/array/{arraySame.js → is-same.js} +1 -1
- package/lib/array/is-same.js.map +1 -0
- package/lib/array/{normalizeArray.d.ts → normalize.d.ts} +1 -1
- package/lib/array/normalize.d.ts.map +1 -0
- package/lib/array/{normalizeArray.js → normalize.js} +1 -1
- package/lib/array/normalize.js.map +1 -0
- package/lib/array/{sortAlpha.d.ts → sort-alpha.d.ts} +1 -1
- package/lib/array/sort-alpha.d.ts.map +1 -0
- package/lib/array/{sortAlpha.js → sort-alpha.js} +1 -1
- package/lib/array/sort-alpha.js.map +1 -0
- package/lib/array/{arrayUnique.d.ts → unique.d.ts} +1 -1
- package/lib/array/unique.d.ts.map +1 -0
- package/lib/array/{arrayUnique.js → unique.js} +1 -1
- package/lib/array/unique.js.map +1 -0
- package/lib/autoindex.d.ts +148 -135
- package/lib/autoindex.d.ts.map +1 -1
- package/lib/autoindex.js +177 -153
- package/lib/autoindex.js.map +1 -1
- package/lib/date/{isInvalid.d.ts → is-invalid.d.ts} +1 -1
- package/lib/date/is-invalid.d.ts.map +1 -0
- package/lib/date/{isInvalid.js → is-invalid.js} +1 -1
- package/lib/date/is-invalid.js.map +1 -0
- package/lib/date/{timeString.d.ts → to-string.d.ts} +5 -5
- package/lib/date/to-string.d.ts.map +1 -0
- package/lib/date/{timeString.js → to-string.js} +24 -25
- package/lib/date/to-string.js.map +1 -0
- package/lib/debugging/{tryInspect.d.ts → inspect.d.ts} +2 -2
- package/lib/debugging/inspect.d.ts.map +1 -0
- package/lib/debugging/{tryInspect.js → inspect.js} +1 -1
- package/lib/debugging/inspect.js.map +1 -0
- package/lib/debugging/object-with-name.d.ts +38 -0
- package/lib/debugging/object-with-name.d.ts.map +1 -0
- package/lib/debugging/object-with-name.js +41 -0
- package/lib/debugging/object-with-name.js.map +1 -0
- package/lib/debugging/serializable.js +1 -1
- package/lib/debugging/serializable.js.map +1 -1
- package/lib/error/convert-unknown.d.ts +2 -0
- package/lib/error/convert-unknown.d.ts.map +1 -0
- package/lib/error/convert-unknown.js +9 -0
- package/lib/error/convert-unknown.js.map +1 -0
- package/lib/error/{getFrame.d.ts → get-frame.d.ts} +2 -2
- package/lib/error/get-frame.d.ts.map +1 -0
- package/lib/error/{getFrame.js → get-frame.js} +1 -1
- package/lib/error/get-frame.js.map +1 -0
- package/lib/error/{pretty.d.ts → pretty.nodejs.d.ts} +2 -1
- package/lib/error/pretty.nodejs.d.ts.map +1 -0
- package/lib/error/{pretty.js → pretty.nodejs.js} +3 -3
- package/lib/error/pretty.nodejs.js.map +1 -0
- package/lib/error/{stackTrace.d.ts → stack-trace.d.ts} +1 -1
- package/lib/error/stack-trace.d.ts.map +1 -0
- package/lib/error/{stackTrace.js → stack-trace.js} +1 -1
- package/lib/error/stack-trace.js.map +1 -0
- package/lib/function/{asyncCallbackList.d.ts → callback-list.async.d.ts} +3 -3
- package/lib/function/callback-list.async.d.ts.map +1 -0
- package/lib/function/{asyncCallbackList.js → callback-list.async.js} +3 -7
- package/lib/function/callback-list.async.js.map +1 -0
- package/lib/function/{callbackList.d.ts → callback-list.d.ts} +1 -1
- package/lib/function/callback-list.d.ts.map +1 -0
- package/lib/function/callback-list.delay.d.ts +15 -0
- package/lib/function/callback-list.delay.d.ts.map +1 -0
- package/lib/function/callback-list.delay.js +22 -0
- package/lib/function/callback-list.delay.js.map +1 -0
- package/lib/function/{callbackList.js → callback-list.js} +2 -2
- package/lib/function/callback-list.js.map +1 -0
- package/lib/function/noop.d.ts +2 -0
- package/lib/function/noop.d.ts.map +1 -0
- package/lib/function/noop.js +2 -0
- package/lib/function/noop.js.map +1 -0
- package/lib/legacy/rename.d.ts +13 -0
- package/lib/legacy/rename.d.ts.map +1 -0
- package/lib/legacy/rename.js +13 -0
- package/lib/legacy/rename.js.map +1 -0
- package/lib/lifecycle/cancellation/driver.browser.d.ts.map +1 -0
- package/lib/lifecycle/cancellation/driver.browser.js.map +1 -0
- package/lib/lifecycle/cancellation/driver.common.d.ts.map +1 -0
- package/lib/lifecycle/{promise/cancellationToken → cancellation}/driver.common.js +1 -1
- package/lib/lifecycle/cancellation/driver.common.js.map +1 -0
- package/lib/lifecycle/{promise/cancellationToken → cancellation}/source.d.ts +3 -3
- package/lib/lifecycle/cancellation/source.d.ts.map +1 -0
- package/lib/lifecycle/{promise/cancellationToken → cancellation}/source.js +2 -2
- package/lib/lifecycle/cancellation/source.js.map +1 -0
- package/lib/lifecycle/dispose/async-disposable.d.ts +17 -0
- package/lib/lifecycle/dispose/async-disposable.d.ts.map +1 -0
- package/lib/lifecycle/dispose/async-disposable.js +42 -0
- package/lib/lifecycle/dispose/async-disposable.js.map +1 -0
- package/lib/lifecycle/dispose/bridges/function.d.ts +17 -0
- package/lib/lifecycle/dispose/bridges/function.d.ts.map +1 -0
- package/lib/lifecycle/dispose/bridges/function.js +29 -0
- package/lib/lifecycle/dispose/bridges/function.js.map +1 -0
- package/lib/lifecycle/dispose/bridges/native.d.ts +10 -0
- package/lib/lifecycle/dispose/bridges/native.d.ts.map +1 -0
- package/lib/lifecycle/dispose/bridges/native.js +13 -0
- package/lib/lifecycle/dispose/bridges/native.js.map +1 -0
- package/lib/lifecycle/dispose/bridges/streams.d.ts +21 -0
- package/lib/lifecycle/dispose/bridges/streams.d.ts.map +1 -0
- package/lib/lifecycle/dispose/bridges/streams.js +60 -0
- package/lib/lifecycle/dispose/bridges/streams.js.map +1 -0
- package/lib/lifecycle/dispose/debug.js +17 -3
- package/lib/lifecycle/dispose/debug.js.map +1 -1
- package/lib/lifecycle/dispose/disposable.d.ts +22 -0
- package/lib/lifecycle/dispose/disposable.d.ts.map +1 -0
- package/lib/lifecycle/dispose/disposable.js +120 -0
- package/lib/lifecycle/dispose/disposable.js.map +1 -0
- package/lib/lifecycle/dispose/disposableEvent.d.ts +9 -14
- package/lib/lifecycle/dispose/disposableEvent.d.ts.map +1 -1
- package/lib/lifecycle/dispose/disposableEvent.js +14 -64
- package/lib/lifecycle/dispose/disposableEvent.js.map +1 -1
- package/lib/lifecycle/dispose/disposedError.d.ts +9 -4
- package/lib/lifecycle/dispose/disposedError.d.ts.map +1 -1
- package/lib/lifecycle/dispose/disposedError.js +28 -13
- package/lib/lifecycle/dispose/disposedError.js.map +1 -1
- package/lib/lifecycle/dispose/sync-disposable.d.ts +21 -0
- package/lib/lifecycle/dispose/sync-disposable.d.ts.map +1 -0
- package/lib/lifecycle/dispose/sync-disposable.js +52 -0
- package/lib/lifecycle/dispose/sync-disposable.js.map +1 -0
- package/lib/lifecycle/event/event.d.ts +18 -33
- package/lib/lifecycle/event/event.d.ts.map +1 -1
- package/lib/lifecycle/event/event.js +75 -64
- package/lib/lifecycle/event/event.js.map +1 -1
- package/lib/lifecycle/event/memorized.d.ts +4 -3
- package/lib/lifecycle/event/memorized.d.ts.map +1 -1
- package/lib/lifecycle/event/memorized.js +9 -10
- package/lib/lifecycle/event/memorized.js.map +1 -1
- package/lib/lifecycle/event/type.d.ts +47 -0
- package/lib/lifecycle/event/type.d.ts.map +1 -0
- package/lib/lifecycle/event/type.js +2 -0
- package/lib/lifecycle/event/type.js.map +1 -0
- package/lib/lifecycle/{dispose/lifecycle.global.d.ts → global/global-lifecycle.d.ts} +3 -15
- package/lib/lifecycle/global/global-lifecycle.d.ts.map +1 -0
- package/lib/lifecycle/{dispose/lifecycle.global.js → global/global-lifecycle.js} +8 -21
- package/lib/lifecycle/global/global-lifecycle.js.map +1 -0
- package/lib/log/logger.js +1 -1
- package/lib/log/logger.js.map +1 -1
- package/lib/{mapSet/customSet.d.ts → map-and-set/custom-set.d.ts} +4 -8
- package/lib/map-and-set/custom-set.d.ts.map +1 -0
- package/lib/{mapSet/customSet.js → map-and-set/custom-set.js} +6 -20
- package/lib/map-and-set/custom-set.js.map +1 -0
- package/lib/map-and-set/required-map.d.ts +28 -0
- package/lib/map-and-set/required-map.d.ts.map +1 -0
- package/lib/map-and-set/required-map.js +42 -0
- package/lib/map-and-set/required-map.js.map +1 -0
- package/lib/object/objectSame.js +1 -1
- package/lib/object/objectSame.js.map +1 -1
- package/lib/path/pathArray.js +1 -1
- package/lib/path/pathArray.js.map +1 -1
- package/lib/path/pathCalc.d.ts +10 -0
- package/lib/path/pathCalc.d.ts.map +1 -0
- package/lib/path/pathCalc.js +17 -0
- package/lib/path/pathCalc.js.map +1 -0
- package/lib/platform/compile.d.ts +7 -0
- package/lib/platform/compile.d.ts.map +1 -0
- package/lib/platform/compile.js +2 -0
- package/lib/platform/compile.js.map +1 -0
- package/lib/platform/globalSingleton.js +1 -1
- package/lib/platform/globalSingleton.js.map +1 -1
- package/lib/platform/os.d.ts.map +1 -1
- package/lib/platform/os.js +1 -1
- package/lib/platform/os.js.map +1 -1
- package/lib/promise/{awaitIterator.d.ts → await-iterator.d.ts} +1 -1
- package/lib/promise/await-iterator.d.ts.map +1 -0
- package/lib/promise/{awaitIterator.js → await-iterator.js} +1 -1
- package/lib/promise/await-iterator.js.map +1 -0
- package/lib/{lifecycle/promise/deferredPromise.d.ts → promise/deferred-promise.d.ts} +14 -6
- package/lib/promise/deferred-promise.d.ts.map +1 -0
- package/lib/{lifecycle/promise/deferredPromise.js → promise/deferred-promise.js} +57 -16
- package/lib/promise/deferred-promise.js.map +1 -0
- package/lib/promise/{promiseBool.d.ts → promise-bool.d.ts} +1 -1
- package/lib/promise/promise-bool.d.ts.map +1 -0
- package/lib/promise/{promiseBool.js → promise-bool.js} +1 -1
- package/lib/promise/promise-bool.js.map +1 -0
- package/lib/promise/{promiseCollection.d.ts → promise-list.d.ts} +3 -3
- package/lib/promise/promise-list.d.ts.map +1 -0
- package/lib/promise/{promiseCollection.js → promise-list.js} +3 -3
- package/lib/promise/promise-list.js.map +1 -0
- package/lib/re-export.d.ts +2 -0
- package/lib/re-export.d.ts.map +1 -0
- package/lib/re-export.js +2 -0
- package/lib/re-export.js.map +1 -0
- package/lib/reflection/classes/pointer.d.ts +5 -0
- package/lib/reflection/classes/pointer.d.ts.map +1 -0
- package/lib/reflection/classes/pointer.js +49 -0
- package/lib/reflection/classes/pointer.js.map +1 -0
- package/lib/reflection/classes/singleton.d.ts +10 -2
- package/lib/reflection/classes/singleton.d.ts.map +1 -1
- package/lib/reflection/classes/singleton.js +29 -21
- package/lib/reflection/classes/singleton.js.map +1 -1
- package/lib/reflection/methods/bind.d.ts +1 -4
- package/lib/reflection/methods/bind.d.ts.map +1 -1
- package/lib/reflection/methods/bind.js +17 -23
- package/lib/reflection/methods/bind.js.map +1 -1
- package/lib/reflection/methods/memorize.d.ts +7 -4
- package/lib/reflection/methods/memorize.d.ts.map +1 -1
- package/lib/reflection/methods/memorize.js +27 -23
- package/lib/reflection/methods/memorize.js.map +1 -1
- package/lib/schedule/extendable-timer.d.ts +16 -0
- package/lib/schedule/extendable-timer.d.ts.map +1 -0
- package/lib/schedule/extendable-timer.js +45 -0
- package/lib/schedule/extendable-timer.js.map +1 -0
- package/lib/{lifecycle/timeout → schedule}/interval.d.ts +3 -3
- package/lib/schedule/interval.d.ts.map +1 -0
- package/lib/{lifecycle/timeout → schedule}/interval.js +3 -3
- package/lib/schedule/interval.js.map +1 -0
- package/lib/schedule/local-type.d.ts +3 -0
- package/lib/schedule/local-type.d.ts.map +1 -0
- package/lib/schedule/local-type.js +2 -0
- package/lib/schedule/local-type.js.map +1 -0
- package/lib/schedule/scheduler.d.ts +4 -0
- package/lib/schedule/scheduler.d.ts.map +1 -0
- package/lib/schedule/scheduler.js +3 -0
- package/lib/schedule/scheduler.js.map +1 -0
- package/lib/{lifecycle/timeout → schedule}/timeout.d.ts +2 -3
- package/lib/schedule/timeout.d.ts.map +1 -0
- package/lib/{lifecycle/timeout → schedule}/timeout.js +5 -11
- package/lib/schedule/timeout.js.map +1 -0
- package/lib/state/{StateMachine.d.ts → simple-state-machine.d.ts} +1 -1
- package/lib/state/simple-state-machine.d.ts.map +1 -0
- package/lib/state/{StateMachine.js → simple-state-machine.js} +1 -1
- package/lib/state/simple-state-machine.js.map +1 -0
- package/lib/string/{castCase.d.ts → case-cast.d.ts} +1 -1
- package/lib/string/case-cast.d.ts.map +1 -0
- package/lib/string/{castCase.js → case-cast.js} +1 -1
- package/lib/string/case-cast.js.map +1 -0
- package/lib/string/{escapeRegexp.d.ts → escape-regexp.d.ts} +1 -1
- package/lib/string/escape-regexp.d.ts.map +1 -0
- package/lib/string/{escapeRegexp.js → escape-regexp.js} +1 -1
- package/lib/string/escape-regexp.js.map +1 -0
- package/lib/string/{sizeString.d.ts → human-bytes.d.ts} +1 -1
- package/lib/string/human-bytes.d.ts.map +1 -0
- package/lib/string/{sizeString.js → human-bytes.js} +1 -1
- package/lib/string/human-bytes.js.map +1 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/typing-helper/callback.d.ts +5 -0
- package/lib/typing-helper/callback.d.ts.map +1 -0
- package/lib/typing-helper/callback.js +2 -0
- package/lib/typing-helper/callback.js.map +1 -0
- package/lib/typing-helper/deep.partial.d.ts.map +1 -0
- package/lib/typing-helper/deep.partial.js.map +1 -0
- package/lib/typing-helper/deep.readonly.d.ts.map +1 -0
- package/lib/typing-helper/deep.readonly.js.map +1 -0
- package/lib/typing-helper/deep.required.d.ts.map +1 -0
- package/lib/typing-helper/deep.required.js.map +1 -0
- package/lib/typing-helper/deep.writable.d.ts.map +1 -0
- package/lib/typing-helper/deep.writable.js.map +1 -0
- package/lib/typing-helper/literal.d.ts.map +1 -0
- package/lib/{typingHelper → typing-helper}/literal.js.map +1 -1
- package/package.json +8 -7
- package/src/autoindex.ts +239 -213
- package/src/date/{timeString.ts → to-string.ts} +28 -29
- package/src/debugging/{tryInspect.ts → inspect.ts} +1 -1
- package/src/debugging/object-with-name.ts +64 -0
- package/src/debugging/serializable.ts +1 -1
- package/src/error/convert-unknown.ts +9 -0
- package/src/error/{getFrame.ts → get-frame.ts} +1 -1
- package/src/error/{pretty.ts → pretty.nodejs.ts} +3 -2
- package/src/function/{asyncCallbackList.ts → callback-list.async.ts} +2 -7
- package/src/function/callback-list.delay.ts +29 -0
- package/src/function/{callbackList.ts → callback-list.ts} +1 -1
- package/src/function/noop.ts +1 -0
- package/src/global.d.ts +10 -0
- package/src/legacy/rename.ts +15 -0
- package/src/lifecycle/{promise/cancellationToken → cancellation}/driver.browser.ts +3 -4
- package/src/lifecycle/{promise/cancellationToken → cancellation}/driver.common.ts +3 -2
- package/src/lifecycle/{promise/cancellationToken → cancellation}/source.ts +4 -4
- package/src/lifecycle/dispose/async-disposable.ts +41 -0
- package/src/lifecycle/dispose/bridges/function.ts +31 -0
- package/src/lifecycle/dispose/bridges/native.ts +23 -0
- package/src/lifecycle/dispose/bridges/streams.ts +70 -0
- package/src/lifecycle/dispose/debug.ts +22 -4
- package/src/lifecycle/dispose/disposable.ts +162 -0
- package/src/lifecycle/dispose/disposableEvent.ts +20 -86
- package/src/lifecycle/dispose/disposedError.ts +36 -19
- package/src/lifecycle/dispose/sync-disposable.ts +53 -0
- package/src/lifecycle/event/event.ts +83 -76
- package/src/lifecycle/event/memorized.ts +13 -12
- package/src/lifecycle/event/type.ts +55 -0
- package/src/lifecycle/global/global-lifecycle.ts +49 -0
- package/src/log/logger.ts +1 -1
- package/src/{mapSet/customSet.ts → map-and-set/custom-set.ts} +7 -26
- package/src/{mapSet/extendMap.ts → map-and-set/required-map.ts} +21 -6
- package/src/object/objectSame.ts +1 -1
- package/src/path/pathArray.ts +1 -1
- package/src/path/pathCalc.ts +18 -0
- package/src/platform/compile.ts +6 -0
- package/src/platform/globalSingleton.ts +1 -1
- package/src/platform/os.ts +1 -1
- package/src/{lifecycle/promise/deferredPromise.ts → promise/deferred-promise.ts} +68 -27
- package/src/promise/{promiseCollection.ts → promise-list.ts} +2 -2
- package/src/re-export.ts +1 -0
- package/src/reflection/classes/pointer.ts +54 -0
- package/src/reflection/classes/singleton.ts +30 -21
- package/src/reflection/methods/bind.ts +15 -23
- package/src/reflection/methods/memorize.ts +30 -23
- package/src/schedule/extendable-timer.ts +49 -0
- package/src/{lifecycle/timeout → schedule}/interval.ts +4 -4
- package/src/schedule/local-type.ts +2 -0
- package/src/schedule/scheduler.ts +8 -0
- package/src/{lifecycle/timeout → schedule}/timeout.ts +7 -13
- package/src/state/{StateMachine.ts → simple-state-machine.ts} +3 -4
- package/src/tsconfig.json +3 -1
- package/src/typing-helper/callback.ts +4 -0
- package/lib/array/arrayDiff.d.ts.map +0 -1
- package/lib/array/arrayDiff.js.map +0 -1
- package/lib/array/arraySame.d.ts.map +0 -1
- package/lib/array/arraySame.js.map +0 -1
- package/lib/array/arrayUnique.d.ts.map +0 -1
- package/lib/array/arrayUnique.js.map +0 -1
- package/lib/array/normalizeArray.d.ts.map +0 -1
- package/lib/array/normalizeArray.js.map +0 -1
- package/lib/array/sortAlpha.d.ts.map +0 -1
- package/lib/array/sortAlpha.js.map +0 -1
- package/lib/date/isInvalid.d.ts.map +0 -1
- package/lib/date/isInvalid.js.map +0 -1
- package/lib/date/timeString.d.ts.map +0 -1
- package/lib/date/timeString.js.map +0 -1
- package/lib/debugging/tryInspect.d.ts.map +0 -1
- package/lib/debugging/tryInspect.js.map +0 -1
- package/lib/error/convertUnknown.d.ts +0 -2
- package/lib/error/convertUnknown.d.ts.map +0 -1
- package/lib/error/convertUnknown.js +0 -9
- package/lib/error/convertUnknown.js.map +0 -1
- package/lib/error/getFrame.d.ts.map +0 -1
- package/lib/error/getFrame.js.map +0 -1
- package/lib/error/pretty.d.ts.map +0 -1
- package/lib/error/pretty.js.map +0 -1
- package/lib/error/stackTrace.d.ts.map +0 -1
- package/lib/error/stackTrace.js.map +0 -1
- package/lib/error-wellknown/exit.error.d.ts +0 -13
- package/lib/error-wellknown/exit.error.d.ts.map +0 -1
- package/lib/error-wellknown/exit.error.js +0 -20
- package/lib/error-wellknown/exit.error.js.map +0 -1
- package/lib/function/asyncCallbackList.d.ts.map +0 -1
- package/lib/function/asyncCallbackList.js.map +0 -1
- package/lib/function/callbackList.d.ts.map +0 -1
- package/lib/function/callbackList.js.map +0 -1
- package/lib/function/delayCallbackList.d.ts +0 -17
- package/lib/function/delayCallbackList.d.ts.map +0 -1
- package/lib/function/delayCallbackList.js +0 -36
- package/lib/function/delayCallbackList.js.map +0 -1
- package/lib/function/functionName.d.ts +0 -26
- package/lib/function/functionName.d.ts.map +0 -1
- package/lib/function/functionName.js +0 -27
- package/lib/function/functionName.js.map +0 -1
- package/lib/lifecycle/dispose/bridges/rxjs.d.ts +0 -8
- package/lib/lifecycle/dispose/bridges/rxjs.d.ts.map +0 -1
- package/lib/lifecycle/dispose/bridges/rxjs.js +0 -4
- package/lib/lifecycle/dispose/bridges/rxjs.js.map +0 -1
- package/lib/lifecycle/dispose/lifecycle.async.d.ts +0 -37
- package/lib/lifecycle/dispose/lifecycle.async.d.ts.map +0 -1
- package/lib/lifecycle/dispose/lifecycle.async.js +0 -111
- package/lib/lifecycle/dispose/lifecycle.async.js.map +0 -1
- package/lib/lifecycle/dispose/lifecycle.d.ts +0 -32
- package/lib/lifecycle/dispose/lifecycle.d.ts.map +0 -1
- package/lib/lifecycle/dispose/lifecycle.global.d.ts.map +0 -1
- package/lib/lifecycle/dispose/lifecycle.global.js.map +0 -1
- package/lib/lifecycle/dispose/lifecycle.js +0 -67
- package/lib/lifecycle/dispose/lifecycle.js.map +0 -1
- package/lib/lifecycle/dispose/lifecycle.sync.d.ts +0 -45
- package/lib/lifecycle/dispose/lifecycle.sync.d.ts.map +0 -1
- package/lib/lifecycle/dispose/lifecycle.sync.js +0 -115
- package/lib/lifecycle/dispose/lifecycle.sync.js.map +0 -1
- package/lib/lifecycle/promise/cancel.d.ts +0 -10
- package/lib/lifecycle/promise/cancel.d.ts.map +0 -1
- package/lib/lifecycle/promise/cancel.js +0 -15
- package/lib/lifecycle/promise/cancel.js.map +0 -1
- package/lib/lifecycle/promise/cancellationToken/driver.browser.d.ts.map +0 -1
- package/lib/lifecycle/promise/cancellationToken/driver.browser.js.map +0 -1
- package/lib/lifecycle/promise/cancellationToken/driver.common.d.ts.map +0 -1
- package/lib/lifecycle/promise/cancellationToken/driver.common.js.map +0 -1
- package/lib/lifecycle/promise/cancellationToken/source.d.ts.map +0 -1
- package/lib/lifecycle/promise/cancellationToken/source.js.map +0 -1
- package/lib/lifecycle/promise/deferredPromise.d.ts.map +0 -1
- package/lib/lifecycle/promise/deferredPromise.js.map +0 -1
- package/lib/lifecycle/timeout/interval.d.ts.map +0 -1
- package/lib/lifecycle/timeout/interval.js.map +0 -1
- package/lib/lifecycle/timeout/timeout.d.ts.map +0 -1
- package/lib/lifecycle/timeout/timeout.js.map +0 -1
- package/lib/lifecycle/timeout/timeoutError.d.ts +0 -11
- package/lib/lifecycle/timeout/timeoutError.d.ts.map +0 -1
- package/lib/lifecycle/timeout/timeoutError.js +0 -16
- package/lib/lifecycle/timeout/timeoutError.js.map +0 -1
- package/lib/mapSet/customSet.d.ts.map +0 -1
- package/lib/mapSet/customSet.js.map +0 -1
- package/lib/mapSet/extendMap.d.ts +0 -21
- package/lib/mapSet/extendMap.d.ts.map +0 -1
- package/lib/mapSet/extendMap.js +0 -26
- package/lib/mapSet/extendMap.js.map +0 -1
- package/lib/promise/awaitIterator.d.ts.map +0 -1
- package/lib/promise/awaitIterator.js.map +0 -1
- package/lib/promise/finishAllPromise.d.ts +0 -13
- package/lib/promise/finishAllPromise.d.ts.map +0 -1
- package/lib/promise/finishAllPromise.js +0 -37
- package/lib/promise/finishAllPromise.js.map +0 -1
- package/lib/promise/promiseBool.d.ts.map +0 -1
- package/lib/promise/promiseBool.js.map +0 -1
- package/lib/promise/promiseCollection.d.ts.map +0 -1
- package/lib/promise/promiseCollection.js.map +0 -1
- package/lib/promise/timeoutPromiseCollection.d.ts +0 -7
- package/lib/promise/timeoutPromiseCollection.d.ts.map +0 -1
- package/lib/promise/timeoutPromiseCollection.js +0 -20
- package/lib/promise/timeoutPromiseCollection.js.map +0 -1
- package/lib/reflection/classes/hookClass.d.ts +0 -11
- package/lib/reflection/classes/hookClass.d.ts.map +0 -1
- package/lib/reflection/classes/hookClass.js +0 -34
- package/lib/reflection/classes/hookClass.js.map +0 -1
- package/lib/reflection/methods/initOnRead.d.ts +0 -7
- package/lib/reflection/methods/initOnRead.d.ts.map +0 -1
- package/lib/reflection/methods/initOnRead.js +0 -11
- package/lib/reflection/methods/initOnRead.js.map +0 -1
- package/lib/state/StateMachine.d.ts.map +0 -1
- package/lib/state/StateMachine.js.map +0 -1
- package/lib/string/castCase.d.ts.map +0 -1
- package/lib/string/castCase.js.map +0 -1
- package/lib/string/escapeRegexp.d.ts.map +0 -1
- package/lib/string/escapeRegexp.js.map +0 -1
- package/lib/string/sizeString.d.ts.map +0 -1
- package/lib/string/sizeString.js.map +0 -1
- package/lib/typingHelper/deep.partial.d.ts.map +0 -1
- package/lib/typingHelper/deep.partial.js.map +0 -1
- package/lib/typingHelper/deep.readonly.d.ts.map +0 -1
- package/lib/typingHelper/deep.readonly.js.map +0 -1
- package/lib/typingHelper/deep.required.d.ts.map +0 -1
- package/lib/typingHelper/deep.required.js.map +0 -1
- package/lib/typingHelper/deep.writable.d.ts.map +0 -1
- package/lib/typingHelper/deep.writable.js.map +0 -1
- package/lib/typingHelper/literal.d.ts.map +0 -1
- package/src/error/convertUnknown.ts +0 -9
- package/src/error-wellknown/exit.error.ts +0 -21
- package/src/function/delayCallbackList.ts +0 -45
- package/src/function/functionName.ts +0 -44
- package/src/lifecycle/dispose/bridges/rxjs.ts +0 -6
- package/src/lifecycle/dispose/lifecycle.async.ts +0 -134
- package/src/lifecycle/dispose/lifecycle.global.ts +0 -66
- package/src/lifecycle/dispose/lifecycle.sync.ts +0 -133
- package/src/lifecycle/dispose/lifecycle.ts +0 -94
- package/src/lifecycle/promise/cancel.ts +0 -16
- package/src/lifecycle/timeout/timeoutError.ts +0 -18
- package/src/promise/finishAllPromise.ts +0 -50
- package/src/promise/timeoutPromiseCollection.ts +0 -22
- package/src/reflection/classes/hookClass.ts +0 -47
- package/src/reflection/methods/initOnRead.ts +0 -11
- /package/lib/lifecycle/{promise/cancellationToken → cancellation}/driver.browser.d.ts +0 -0
- /package/lib/lifecycle/{promise/cancellationToken → cancellation}/driver.browser.js +0 -0
- /package/lib/lifecycle/{promise/cancellationToken → cancellation}/driver.common.d.ts +0 -0
- /package/lib/{typingHelper → typing-helper}/deep.partial.d.ts +0 -0
- /package/lib/{typingHelper → typing-helper}/deep.partial.js +0 -0
- /package/lib/{typingHelper → typing-helper}/deep.readonly.d.ts +0 -0
- /package/lib/{typingHelper → typing-helper}/deep.readonly.js +0 -0
- /package/lib/{typingHelper → typing-helper}/deep.required.d.ts +0 -0
- /package/lib/{typingHelper → typing-helper}/deep.required.js +0 -0
- /package/lib/{typingHelper → typing-helper}/deep.writable.d.ts +0 -0
- /package/lib/{typingHelper → typing-helper}/deep.writable.js +0 -0
- /package/lib/{typingHelper → typing-helper}/literal.d.ts +0 -0
- /package/lib/{typingHelper → typing-helper}/literal.js +0 -0
- /package/src/array/{arrayDiff.ts → diff.ts} +0 -0
- /package/src/array/{arraySame.ts → is-same.ts} +0 -0
- /package/src/array/{normalizeArray.ts → normalize.ts} +0 -0
- /package/src/array/{sortAlpha.ts → sort-alpha.ts} +0 -0
- /package/src/array/{arrayUnique.ts → unique.ts} +0 -0
- /package/src/date/{isInvalid.ts → is-invalid.ts} +0 -0
- /package/src/error/{stackTrace.ts → stack-trace.ts} +0 -0
- /package/src/promise/{awaitIterator.ts → await-iterator.ts} +0 -0
- /package/src/promise/{promiseBool.ts → promise-bool.ts} +0 -0
- /package/src/string/{castCase.ts → case-cast.ts} +0 -0
- /package/src/string/{escapeRegexp.ts → escape-regexp.ts} +0 -0
- /package/src/string/{sizeString.ts → human-bytes.ts} +0 -0
- /package/src/{typingHelper → typing-helper}/deep.partial.ts +0 -0
- /package/src/{typingHelper → typing-helper}/deep.readonly.ts +0 -0
- /package/src/{typingHelper → typing-helper}/deep.required.ts +0 -0
- /package/src/{typingHelper → typing-helper}/deep.writable.ts +0 -0
- /package/src/{typingHelper → typing-helper}/literal.ts +0 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { IDisposable } from '../dispose/
|
|
2
|
-
import { Emitter
|
|
1
|
+
import type { IDisposable } from '../dispose/disposable.js';
|
|
2
|
+
import { Emitter } from './event.js';
|
|
3
|
+
import type { EventHandler } from './type.js';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* 会记住上次fire的内容,并在每个新的handler注册时立即调用一次的Emitter
|
|
@@ -7,29 +8,29 @@ import { Emitter, type EventHandler } from './event.js';
|
|
|
7
8
|
* @public
|
|
8
9
|
*/
|
|
9
10
|
export class MemorizedEmitter<T> extends Emitter<T> {
|
|
10
|
-
private _memo?: T;
|
|
11
|
-
private _is_memo = false;
|
|
11
|
+
private _memo?: { data: T };
|
|
12
12
|
|
|
13
13
|
public override fire(data: T) {
|
|
14
|
-
|
|
15
|
-
this.
|
|
16
|
-
return super.fire(data);
|
|
14
|
+
super.fire(data);
|
|
15
|
+
this._memo = { data };
|
|
17
16
|
}
|
|
18
17
|
|
|
19
18
|
public override fireNoError(data: T) {
|
|
20
|
-
|
|
21
|
-
this.
|
|
22
|
-
return super.fireNoError(data);
|
|
19
|
+
super.fireNoError(data);
|
|
20
|
+
this._memo = { data };
|
|
23
21
|
}
|
|
24
22
|
|
|
25
23
|
public override handle(callback: EventHandler<T>): IDisposable {
|
|
26
|
-
if (this.
|
|
24
|
+
if (this._memo) callback(this._memo.data);
|
|
27
25
|
return super.handle(callback);
|
|
28
26
|
}
|
|
29
27
|
|
|
28
|
+
public override once(): never {
|
|
29
|
+
throw new Error('once() is not supported for MemorizedEmitter');
|
|
30
|
+
}
|
|
31
|
+
|
|
30
32
|
public forget() {
|
|
31
33
|
this._memo = undefined;
|
|
32
|
-
this._is_memo = false;
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
override dispose(): void {
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { IDisposable } from '../dispose/disposable.js';
|
|
2
|
+
import type { Emitter } from './event.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 事件注册对象
|
|
6
|
+
*/
|
|
7
|
+
export interface IEventEmitter<T = unknown> extends IDisposable {
|
|
8
|
+
/**
|
|
9
|
+
* @returns 当前注册回调数量
|
|
10
|
+
*/
|
|
11
|
+
listenerCount(): number;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 触发本事件,任何一个回调错误,都会导致直接抛出异常,其他未知数量的回调将不会被执行
|
|
15
|
+
* @param data 回调数据
|
|
16
|
+
*/
|
|
17
|
+
fire(data: T): void;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 与 `fire()`相同,但是忽略任何错误
|
|
21
|
+
* 即便出错也继续执行全部callback
|
|
22
|
+
*
|
|
23
|
+
* 抛出的异常会直接丢弃
|
|
24
|
+
* 除了disposed错误外,其他错误都不会被重新抛出
|
|
25
|
+
*/
|
|
26
|
+
fireNoError(data: T): void;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 注册本事件的新回调
|
|
30
|
+
* @param callback 回调函数
|
|
31
|
+
*/
|
|
32
|
+
readonly register: EventRegister<T>;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @alias register AI喜欢用event
|
|
36
|
+
*/
|
|
37
|
+
readonly event: EventRegister<T>;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* 注册一次性回调
|
|
41
|
+
* @param callback 回调函数
|
|
42
|
+
*/
|
|
43
|
+
once(callback: EventHandler<T>): IDisposable;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export type EventHandler<T> = (data: T) => void;
|
|
47
|
+
|
|
48
|
+
export interface EventRegister<T> {
|
|
49
|
+
(callback: EventHandler<T>): IDisposable;
|
|
50
|
+
once(callback: EventHandler<T>): IDisposable;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export type EventEmitterMap<T extends Record<string, unknown>> = {
|
|
54
|
+
[K in keyof T]: Emitter<T[K]>;
|
|
55
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { globalSingletonStrong } from '../../platform/globalSingleton.js';
|
|
2
|
+
import { createSymbol } from '../../platform/globalSymbol.js';
|
|
3
|
+
import { UnorderedAsyncDisposable, type EnhancedAsyncDisposable } from '../dispose/async-disposable.js';
|
|
4
|
+
import { _debug_dispose } from '../dispose/debug.js';
|
|
5
|
+
import type { IAsyncDisposable, IDisposable } from '../dispose/disposable.js';
|
|
6
|
+
|
|
7
|
+
const symbol = createSymbol('lifecycle', 'application');
|
|
8
|
+
|
|
9
|
+
function create(): EnhancedAsyncDisposable {
|
|
10
|
+
return new UnorderedAsyncDisposable('global');
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const logger = _debug_dispose.extend('global');
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Add object into global disposable store, it will be dispose when call to `disposeGlobal`
|
|
17
|
+
*/
|
|
18
|
+
export function registerGlobalLifecycle(object: IDisposable | IAsyncDisposable) {
|
|
19
|
+
globalSingletonStrong(symbol, create)._register(object);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Same as disposeGlobal, but do not throw by duplicate call
|
|
24
|
+
*/
|
|
25
|
+
export function ensureDisposeGlobal() {
|
|
26
|
+
const obj = globalSingletonStrong<EnhancedAsyncDisposable>(symbol);
|
|
27
|
+
if (obj && !obj.disposed) {
|
|
28
|
+
return Promise.try(() => obj.dispose());
|
|
29
|
+
}
|
|
30
|
+
return Promise.resolve();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Dispose the global disposable store
|
|
35
|
+
* this function must be manually called by user, when registerGlobalLifecycle is used
|
|
36
|
+
*
|
|
37
|
+
* @throws when call twice
|
|
38
|
+
*/
|
|
39
|
+
export function disposeGlobal() {
|
|
40
|
+
const obj = globalSingletonStrong<EnhancedAsyncDisposable>(symbol);
|
|
41
|
+
if (obj?.disposed) {
|
|
42
|
+
throw new Error('global already disposed.');
|
|
43
|
+
}
|
|
44
|
+
if (obj) {
|
|
45
|
+
return Promise.try(() => obj.dispose());
|
|
46
|
+
}
|
|
47
|
+
if (logger.enabled) logger(`dispose global (not exists)`);
|
|
48
|
+
return Promise.resolve();
|
|
49
|
+
}
|
package/src/log/logger.ts
CHANGED
|
@@ -1,34 +1,20 @@
|
|
|
1
1
|
/** Find the index of given item */
|
|
2
2
|
export type Finder<Type> = (this: Type[], item: Type) => number;
|
|
3
3
|
|
|
4
|
-
type MyFinder<Type> = (item: Type) => number;
|
|
5
|
-
|
|
6
|
-
export function RegexpFinder(this: RegExp[], item: RegExp): number {
|
|
7
|
-
return this.findIndex((e) => e.toString() === item.toString());
|
|
8
|
-
}
|
|
9
|
-
|
|
10
4
|
/**
|
|
11
|
-
* Like a Set, but use custom compare function
|
|
5
|
+
* Like a Set, but use custom compare function instead ===
|
|
12
6
|
*/
|
|
13
|
-
export class CustomSet<Type
|
|
14
|
-
protected registry: Type[];
|
|
15
|
-
private finder: MyFinder<Type>;
|
|
16
|
-
|
|
17
|
-
constructor(finder: Finder<Type> = Array.prototype.indexOf) {
|
|
18
|
-
this.registry = [];
|
|
19
|
-
this.finder = finder.bind(this.registry);
|
|
20
|
-
}
|
|
7
|
+
export abstract class CustomSet<Type> {
|
|
8
|
+
protected registry: Type[] = [];
|
|
21
9
|
|
|
22
|
-
|
|
23
|
-
this.finder = finder.bind(this.registry);
|
|
24
|
-
}
|
|
10
|
+
protected abstract compare(item1: Type, item2: Type): number;
|
|
25
11
|
|
|
26
12
|
has(item: Type): boolean {
|
|
27
|
-
return this.
|
|
13
|
+
return this.registry.findIndex((e) => this.compare(e, item) === 0) !== -1;
|
|
28
14
|
}
|
|
29
15
|
|
|
30
16
|
add(item: Type): boolean {
|
|
31
|
-
const index = this.
|
|
17
|
+
const index = this.registry.findIndex((e) => this.compare(e, item) === 0);
|
|
32
18
|
if (index === -1) {
|
|
33
19
|
this.registry.push(item);
|
|
34
20
|
return true;
|
|
@@ -44,7 +30,7 @@ export class CustomSet<Type = string> {
|
|
|
44
30
|
}
|
|
45
31
|
|
|
46
32
|
delete(item: Type): boolean {
|
|
47
|
-
const index = this.
|
|
33
|
+
const index = this.registry.findIndex((e) => this.compare(e, item) === 0);
|
|
48
34
|
if (index === -1) {
|
|
49
35
|
return false;
|
|
50
36
|
}
|
|
@@ -67,10 +53,6 @@ export class CustomSet<Type = string> {
|
|
|
67
53
|
return this.registry.length;
|
|
68
54
|
}
|
|
69
55
|
|
|
70
|
-
get size() {
|
|
71
|
-
return this.registry.length;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
56
|
[Symbol.iterator](): Iterator<Type> {
|
|
75
57
|
return this.registry[Symbol.iterator]();
|
|
76
58
|
}
|
|
@@ -80,7 +62,6 @@ export class CustomSet<Type = string> {
|
|
|
80
62
|
values(): Iterator<Type> {
|
|
81
63
|
return this.registry[Symbol.iterator]();
|
|
82
64
|
}
|
|
83
|
-
|
|
84
65
|
toArray() {
|
|
85
66
|
return this.registry.slice();
|
|
86
67
|
}
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
export interface MapLike<V> {
|
|
2
|
-
[id: string]: V;
|
|
3
|
-
}
|
|
4
|
-
|
|
5
1
|
/**
|
|
6
2
|
* A map, will throw error when try to get not exists key
|
|
7
3
|
*/
|
|
8
|
-
export class
|
|
4
|
+
export class RequiredMap<K, V> extends Map<K, V> {
|
|
9
5
|
/**
|
|
10
6
|
* Get value from map, if not exists, throw an error
|
|
11
7
|
*/
|
|
@@ -26,7 +22,7 @@ export class ExtendMap<K, V> extends Map<K, V> {
|
|
|
26
22
|
}
|
|
27
23
|
|
|
28
24
|
/**
|
|
29
|
-
* Get a value, if not exists, call init() and
|
|
25
|
+
* Get a value, if not exists, call init() and save to map
|
|
30
26
|
*/
|
|
31
27
|
public entry(id: K, init: (id: K) => V): V {
|
|
32
28
|
if (super.has(id)) {
|
|
@@ -37,3 +33,22 @@ export class ExtendMap<K, V> extends Map<K, V> {
|
|
|
37
33
|
return nv;
|
|
38
34
|
}
|
|
39
35
|
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* A map that holds instances, automatically create new instance
|
|
39
|
+
*/
|
|
40
|
+
export abstract class InstanceMap<K, V> extends Map<K, V> {
|
|
41
|
+
protected abstract instance(key: K): V;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Get a value, if not exists, call init() and save to map
|
|
45
|
+
*/
|
|
46
|
+
public override get(id: K): V {
|
|
47
|
+
if (super.has(id)) {
|
|
48
|
+
return super.get(id)!;
|
|
49
|
+
}
|
|
50
|
+
const nv = this.instance(id);
|
|
51
|
+
super.set(id, nv);
|
|
52
|
+
return nv;
|
|
53
|
+
}
|
|
54
|
+
}
|
package/src/object/objectSame.ts
CHANGED
package/src/path/pathArray.ts
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { normalizePath } from './normalizePath.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 检查两个路径是否存在父子关系
|
|
5
|
+
*
|
|
6
|
+
* @param parent 父目录
|
|
7
|
+
* @param child 子目录
|
|
8
|
+
* @param equalsOk 默认为false,相等不属于父子。设为true则相等返回true
|
|
9
|
+
* @returns 如果parent是child的父目录,则返回true
|
|
10
|
+
*/
|
|
11
|
+
export function isPathContains(parent: string, child: string, equalsOk = false): boolean {
|
|
12
|
+
const nParent = normalizePath(parent);
|
|
13
|
+
const nChild = normalizePath(child);
|
|
14
|
+
|
|
15
|
+
if (nParent === nChild) return equalsOk;
|
|
16
|
+
|
|
17
|
+
return nChild.startsWith(`${nParent}/`);
|
|
18
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** biome-ignore-all lint/suspicious/noShadowRestrictedNames: */
|
|
2
2
|
|
|
3
|
-
import { functionName } from '../
|
|
3
|
+
import { functionName } from '../debugging/object-with-name.js';
|
|
4
4
|
import { ensureGlobalObject } from './globalObject.js';
|
|
5
5
|
|
|
6
6
|
const singletonRegistry = ensureGlobalObject('@@idlebox/global-singleton', () => {
|
package/src/platform/os.ts
CHANGED
|
@@ -6,7 +6,7 @@ declare const global: any;
|
|
|
6
6
|
/**
|
|
7
7
|
* buy detect process.pid, is there any bundler mock this?
|
|
8
8
|
*/
|
|
9
|
-
export const hasProcess = typeof process?.pid === 'number';
|
|
9
|
+
export const hasProcess = typeof process !== 'undefined' && typeof process?.pid === 'number';
|
|
10
10
|
export const hasWindow = typeof window !== 'undefined' && globalThis === window;
|
|
11
11
|
export const hasGlobal = typeof global !== 'undefined' && globalThis === global;
|
|
12
12
|
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { CanceledError, TimeoutError } from '@idlebox/errors';
|
|
2
|
+
import type { TimeoutType } from '../autoindex.js';
|
|
3
|
+
import type { IDisposable } from '../lifecycle/dispose/disposable.js';
|
|
4
|
+
import { scheduler } from '../schedule/scheduler.js';
|
|
3
5
|
|
|
4
6
|
export type ValueCallback<T = any> = (value: T | Promise<T>) => void;
|
|
5
7
|
export type ProgressCallback<T = any> = (value: T) => void;
|
|
@@ -13,25 +15,27 @@ export interface IProgressHolder<T, PT> {
|
|
|
13
15
|
* @public
|
|
14
16
|
*/
|
|
15
17
|
export class DeferredPromise<T, PT = any> {
|
|
16
|
-
readonly
|
|
17
|
-
#completeCallback
|
|
18
|
-
#errorCallback
|
|
18
|
+
readonly promise: Promise<T> & IProgressHolder<T, PT>;
|
|
19
|
+
#completeCallback: ValueCallback<T>;
|
|
20
|
+
#errorCallback: (err: any) => void;
|
|
19
21
|
#success?: boolean;
|
|
20
22
|
#progressList: ProgressCallback<PT>[] = [];
|
|
21
23
|
|
|
22
24
|
constructor() {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
{
|
|
29
|
-
progress
|
|
30
|
-
|
|
31
|
-
return this.p;
|
|
32
|
-
},
|
|
25
|
+
const { promise, resolve, reject } = Promise.withResolvers<T>();
|
|
26
|
+
this.#completeCallback = resolve;
|
|
27
|
+
this.#errorCallback = reject;
|
|
28
|
+
|
|
29
|
+
this.promise = Object.assign(promise, {
|
|
30
|
+
progress: (fn: ProgressCallback<PT>) => {
|
|
31
|
+
this.progress(fn);
|
|
32
|
+
return this.p;
|
|
33
33
|
},
|
|
34
|
-
);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
get p() {
|
|
38
|
+
return this.promise;
|
|
35
39
|
}
|
|
36
40
|
|
|
37
41
|
/**
|
|
@@ -42,7 +46,7 @@ export class DeferredPromise<T, PT = any> {
|
|
|
42
46
|
notify(progress: PT): this {
|
|
43
47
|
if (this.#success !== undefined) throw new Error('no more event after settled');
|
|
44
48
|
for (const cb of this.#progressList) {
|
|
45
|
-
cb(progress);
|
|
49
|
+
scheduler(cb.bind(undefined, progress));
|
|
46
50
|
}
|
|
47
51
|
return this;
|
|
48
52
|
}
|
|
@@ -50,9 +54,8 @@ export class DeferredPromise<T, PT = any> {
|
|
|
50
54
|
/**
|
|
51
55
|
* register a progress callback
|
|
52
56
|
* @param fn progress callback function, will be called when notify is called
|
|
53
|
-
* @returns
|
|
54
57
|
*/
|
|
55
|
-
progress(fn: ProgressCallback<PT>): IDisposable {
|
|
58
|
+
protected progress(fn: ProgressCallback<PT>): IDisposable {
|
|
56
59
|
if (this.#success !== undefined) throw new Error('no more listener after settled');
|
|
57
60
|
this.#progressList.push(fn);
|
|
58
61
|
|
|
@@ -75,9 +78,16 @@ export class DeferredPromise<T, PT = any> {
|
|
|
75
78
|
}
|
|
76
79
|
|
|
77
80
|
/**
|
|
78
|
-
*
|
|
81
|
+
* @deprecated use settled
|
|
79
82
|
*/
|
|
80
|
-
get completed()
|
|
83
|
+
get completed() {
|
|
84
|
+
return this.settled;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* whether the promise is settled (resolved or rejected)
|
|
89
|
+
*/
|
|
90
|
+
get settled(): boolean {
|
|
81
91
|
return this.#success !== undefined;
|
|
82
92
|
}
|
|
83
93
|
|
|
@@ -93,31 +103,62 @@ export class DeferredPromise<T, PT = any> {
|
|
|
93
103
|
* resolve the promise
|
|
94
104
|
*/
|
|
95
105
|
complete(value: T) {
|
|
106
|
+
if (this.settled) return;
|
|
96
107
|
this.#success = true;
|
|
108
|
+
this.#after_settled();
|
|
97
109
|
this.#completeCallback(value);
|
|
98
|
-
this.#no_more_progress();
|
|
99
110
|
}
|
|
100
111
|
|
|
101
112
|
/**
|
|
102
113
|
* reject the promise
|
|
103
114
|
*/
|
|
104
115
|
error(err: any) {
|
|
116
|
+
if (this.settled) return;
|
|
105
117
|
this.#success = false;
|
|
118
|
+
this.#after_settled();
|
|
106
119
|
this.#errorCallback(err);
|
|
107
|
-
this.#no_more_progress();
|
|
108
120
|
}
|
|
109
121
|
|
|
110
122
|
/**
|
|
111
123
|
* reject the deferred with {CancelError}
|
|
112
124
|
*/
|
|
113
125
|
cancel() {
|
|
114
|
-
this
|
|
115
|
-
this.#errorCallback(new CanceledError());
|
|
116
|
-
this.#no_more_progress();
|
|
126
|
+
this.error(new CanceledError());
|
|
117
127
|
}
|
|
118
128
|
|
|
119
|
-
#
|
|
129
|
+
#after_settled() {
|
|
120
130
|
this.#progressList.length = 0;
|
|
131
|
+
this.#cancel_timeout();
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
get callback() {
|
|
135
|
+
if (this.#success !== undefined) throw new Error('can not generate callback after settled');
|
|
136
|
+
|
|
137
|
+
return (error?: null | undefined | Error, data?: T) => {
|
|
138
|
+
if (error) {
|
|
139
|
+
this.error(error);
|
|
140
|
+
} else {
|
|
141
|
+
this.complete(data as any);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
#timer?: TimeoutType;
|
|
147
|
+
#cancel_timeout() {
|
|
148
|
+
if (this.#timer) {
|
|
149
|
+
clearTimeout(this.#timer);
|
|
150
|
+
this.#timer = undefined;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
timeout(ms: number) {
|
|
154
|
+
if (this.settled) throw new Error('no more timeout after settled');
|
|
155
|
+
this.#timer = setTimeout(() => {
|
|
156
|
+
this.error(new TimeoutError(ms, 'promise not settled'));
|
|
157
|
+
}, ms);
|
|
158
|
+
|
|
159
|
+
return {
|
|
160
|
+
dispose: () => this.#cancel_timeout(),
|
|
161
|
+
};
|
|
121
162
|
}
|
|
122
163
|
|
|
123
164
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { CanceledError } from '
|
|
2
|
-
import { DeferredPromise } from '
|
|
1
|
+
import { CanceledError } from '@idlebox/errors';
|
|
2
|
+
import { DeferredPromise } from './deferred-promise.js';
|
|
3
3
|
|
|
4
4
|
export class PromiseCollection {
|
|
5
5
|
protected readonly promiseList: Record<string, DeferredPromise<any>> = {};
|
package/src/re-export.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@idlebox/errors';
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export type Ref<T = any> = { reference: T };
|
|
2
|
+
|
|
3
|
+
export function Pointer<T>(_object: Ref<T>): T {
|
|
4
|
+
const object = _object as any;
|
|
5
|
+
|
|
6
|
+
return new Proxy(
|
|
7
|
+
{},
|
|
8
|
+
{
|
|
9
|
+
apply(_, thisArg, argArray) {
|
|
10
|
+
return Reflect.apply(object.reference, thisArg, argArray);
|
|
11
|
+
},
|
|
12
|
+
construct(_, argArray, new_) {
|
|
13
|
+
return Reflect.construct(object.reference, argArray, new_);
|
|
14
|
+
},
|
|
15
|
+
defineProperty(_, property, attributes) {
|
|
16
|
+
return Reflect.defineProperty(object.reference, property, attributes);
|
|
17
|
+
},
|
|
18
|
+
deleteProperty(_, p) {
|
|
19
|
+
return Reflect.deleteProperty(object.reference, p);
|
|
20
|
+
},
|
|
21
|
+
get(_, p, _receiver) {
|
|
22
|
+
const value = object.reference[p];
|
|
23
|
+
if (typeof value === 'function') {
|
|
24
|
+
return value.bind(object.reference);
|
|
25
|
+
}
|
|
26
|
+
return value;
|
|
27
|
+
},
|
|
28
|
+
getOwnPropertyDescriptor(_, p) {
|
|
29
|
+
return Reflect.getOwnPropertyDescriptor(object.reference, p);
|
|
30
|
+
},
|
|
31
|
+
getPrototypeOf(_) {
|
|
32
|
+
return Reflect.getPrototypeOf(object);
|
|
33
|
+
},
|
|
34
|
+
has(_, p) {
|
|
35
|
+
return Reflect.has(object.reference, p);
|
|
36
|
+
},
|
|
37
|
+
isExtensible(_) {
|
|
38
|
+
return Reflect.isExtensible(object);
|
|
39
|
+
},
|
|
40
|
+
ownKeys(_) {
|
|
41
|
+
return Reflect.ownKeys(object);
|
|
42
|
+
},
|
|
43
|
+
preventExtensions(_) {
|
|
44
|
+
return Reflect.preventExtensions(object);
|
|
45
|
+
},
|
|
46
|
+
set(_, p, newValue, receiver) {
|
|
47
|
+
return Reflect.set(object.reference, p, newValue, receiver);
|
|
48
|
+
},
|
|
49
|
+
setPrototypeOf(_, v) {
|
|
50
|
+
return Reflect.setPrototypeOf(object.reference, v);
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
) as any;
|
|
54
|
+
}
|
|
@@ -1,32 +1,41 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { definePrivateConstant } from '../../autoindex.js';
|
|
2
2
|
|
|
3
|
-
export const singletonSymbol = Symbol('@
|
|
3
|
+
export const singletonSymbol = Symbol('@idlebox/singleton');
|
|
4
4
|
|
|
5
5
|
export enum SingletonType {
|
|
6
6
|
Throw = 0,
|
|
7
|
-
|
|
7
|
+
ReturnSame = 1,
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
return (target: any): any => {
|
|
12
|
-
const hook = hookClass(target);
|
|
13
|
-
if (!hook.beforeConstruct) {
|
|
14
|
-
hook.beforeConstruct = [];
|
|
15
|
-
}
|
|
16
|
-
if (!hook.afterConstruct) {
|
|
17
|
-
hook.afterConstruct = [];
|
|
18
|
-
}
|
|
10
|
+
type AnyClass = new (...args: any) => any;
|
|
19
11
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
12
|
+
/**
|
|
13
|
+
* 单例类修饰器
|
|
14
|
+
* @param type
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
export function singleton(type: SingletonType = SingletonType.ReturnSame) {
|
|
18
|
+
return <T extends AnyClass>(Class: T, ctx: ClassDecoratorContext): T => {
|
|
19
|
+
if (ctx.kind !== 'class') throw new Error(`this decorator can only be applied to classes`);
|
|
20
|
+
|
|
21
|
+
const name = ctx.name;
|
|
22
|
+
return new Proxy(Class, {
|
|
23
|
+
construct(target, args) {
|
|
24
|
+
const exists = (Class as any)[singletonSymbol];
|
|
25
|
+
if (exists) {
|
|
26
|
+
if (type === SingletonType.Throw) throw new Error(`can not recreate singleton class #${name}`);
|
|
27
|
+
return exists;
|
|
24
28
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
hook.afterConstruct.push((obj) => {
|
|
29
|
-
target[singletonSymbol] = obj;
|
|
29
|
+
const instance = Reflect.construct(target, args);
|
|
30
|
+
return instance;
|
|
31
|
+
},
|
|
30
32
|
});
|
|
31
33
|
};
|
|
32
34
|
}
|
|
35
|
+
|
|
36
|
+
export function createSingleton<T>(Class: new () => T): T {
|
|
37
|
+
if (!(Class as any)[singletonSymbol]) {
|
|
38
|
+
definePrivateConstant(Class, singletonSymbol, new Class());
|
|
39
|
+
}
|
|
40
|
+
return (Class as any)[singletonSymbol];
|
|
41
|
+
}
|
|
@@ -1,25 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
* Auto bind `this` to class method
|
|
3
|
-
*/
|
|
4
|
-
export const bindThis: MethodDecorator = <T>(_target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>) => {
|
|
5
|
-
const oldFunc = descriptor.value;
|
|
6
|
-
if (typeof oldFunc === 'function') {
|
|
7
|
-
return {
|
|
8
|
-
enumerable: true,
|
|
9
|
-
configurable: true,
|
|
10
|
-
get: function (this: any) {
|
|
11
|
-
delete this[propertyKey];
|
|
1
|
+
import { nameObject } from '../../autoindex.js';
|
|
12
2
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
3
|
+
export function bindThis(method: Function, context: ClassMethodDecoratorContext) {
|
|
4
|
+
if (context.kind !== 'method') throw new Error(`this decorator can only be applied to classes`);
|
|
5
|
+
|
|
6
|
+
if (context.static) throw new TypeError('this decorator not supported on static methods.');
|
|
7
|
+
if (context.private) {
|
|
8
|
+
return nameObject(`${context.name.toString()}.bounded`, function (this: any, ...args: any[]) {
|
|
9
|
+
return method.apply(this, args);
|
|
10
|
+
});
|
|
11
|
+
} else {
|
|
12
|
+
context.addInitializer(function (this: any) {
|
|
13
|
+
this[context.name] = nameObject(`${context.name.toString()}.bounded`, method.bind(this));
|
|
14
|
+
});
|
|
15
|
+
return undefined;
|
|
23
16
|
}
|
|
24
|
-
|
|
25
|
-
};
|
|
17
|
+
}
|