@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.
Files changed (476) hide show
  1. package/lib/array/{arrayDiff.d.ts → diff.d.ts} +1 -1
  2. package/lib/array/diff.d.ts.map +1 -0
  3. package/lib/array/{arrayDiff.js → diff.js} +1 -1
  4. package/lib/array/diff.js.map +1 -0
  5. package/lib/array/{arraySame.d.ts → is-same.d.ts} +1 -1
  6. package/lib/array/is-same.d.ts.map +1 -0
  7. package/lib/array/{arraySame.js → is-same.js} +1 -1
  8. package/lib/array/is-same.js.map +1 -0
  9. package/lib/array/{normalizeArray.d.ts → normalize.d.ts} +1 -1
  10. package/lib/array/normalize.d.ts.map +1 -0
  11. package/lib/array/{normalizeArray.js → normalize.js} +1 -1
  12. package/lib/array/normalize.js.map +1 -0
  13. package/lib/array/{sortAlpha.d.ts → sort-alpha.d.ts} +1 -1
  14. package/lib/array/sort-alpha.d.ts.map +1 -0
  15. package/lib/array/{sortAlpha.js → sort-alpha.js} +1 -1
  16. package/lib/array/sort-alpha.js.map +1 -0
  17. package/lib/array/{arrayUnique.d.ts → unique.d.ts} +1 -1
  18. package/lib/array/unique.d.ts.map +1 -0
  19. package/lib/array/{arrayUnique.js → unique.js} +1 -1
  20. package/lib/array/unique.js.map +1 -0
  21. package/lib/autoindex.d.ts +148 -135
  22. package/lib/autoindex.d.ts.map +1 -1
  23. package/lib/autoindex.js +177 -153
  24. package/lib/autoindex.js.map +1 -1
  25. package/lib/date/{isInvalid.d.ts → is-invalid.d.ts} +1 -1
  26. package/lib/date/is-invalid.d.ts.map +1 -0
  27. package/lib/date/{isInvalid.js → is-invalid.js} +1 -1
  28. package/lib/date/is-invalid.js.map +1 -0
  29. package/lib/date/{timeString.d.ts → to-string.d.ts} +5 -5
  30. package/lib/date/to-string.d.ts.map +1 -0
  31. package/lib/date/{timeString.js → to-string.js} +24 -25
  32. package/lib/date/to-string.js.map +1 -0
  33. package/lib/debugging/{tryInspect.d.ts → inspect.d.ts} +2 -2
  34. package/lib/debugging/inspect.d.ts.map +1 -0
  35. package/lib/debugging/{tryInspect.js → inspect.js} +1 -1
  36. package/lib/debugging/inspect.js.map +1 -0
  37. package/lib/debugging/object-with-name.d.ts +38 -0
  38. package/lib/debugging/object-with-name.d.ts.map +1 -0
  39. package/lib/debugging/object-with-name.js +41 -0
  40. package/lib/debugging/object-with-name.js.map +1 -0
  41. package/lib/debugging/serializable.js +1 -1
  42. package/lib/debugging/serializable.js.map +1 -1
  43. package/lib/error/convert-unknown.d.ts +2 -0
  44. package/lib/error/convert-unknown.d.ts.map +1 -0
  45. package/lib/error/convert-unknown.js +9 -0
  46. package/lib/error/convert-unknown.js.map +1 -0
  47. package/lib/error/{getFrame.d.ts → get-frame.d.ts} +2 -2
  48. package/lib/error/get-frame.d.ts.map +1 -0
  49. package/lib/error/{getFrame.js → get-frame.js} +1 -1
  50. package/lib/error/get-frame.js.map +1 -0
  51. package/lib/error/{pretty.d.ts → pretty.nodejs.d.ts} +2 -1
  52. package/lib/error/pretty.nodejs.d.ts.map +1 -0
  53. package/lib/error/{pretty.js → pretty.nodejs.js} +3 -3
  54. package/lib/error/pretty.nodejs.js.map +1 -0
  55. package/lib/error/{stackTrace.d.ts → stack-trace.d.ts} +1 -1
  56. package/lib/error/stack-trace.d.ts.map +1 -0
  57. package/lib/error/{stackTrace.js → stack-trace.js} +1 -1
  58. package/lib/error/stack-trace.js.map +1 -0
  59. package/lib/function/{asyncCallbackList.d.ts → callback-list.async.d.ts} +3 -3
  60. package/lib/function/callback-list.async.d.ts.map +1 -0
  61. package/lib/function/{asyncCallbackList.js → callback-list.async.js} +3 -7
  62. package/lib/function/callback-list.async.js.map +1 -0
  63. package/lib/function/{callbackList.d.ts → callback-list.d.ts} +1 -1
  64. package/lib/function/callback-list.d.ts.map +1 -0
  65. package/lib/function/callback-list.delay.d.ts +15 -0
  66. package/lib/function/callback-list.delay.d.ts.map +1 -0
  67. package/lib/function/callback-list.delay.js +22 -0
  68. package/lib/function/callback-list.delay.js.map +1 -0
  69. package/lib/function/{callbackList.js → callback-list.js} +2 -2
  70. package/lib/function/callback-list.js.map +1 -0
  71. package/lib/function/noop.d.ts +2 -0
  72. package/lib/function/noop.d.ts.map +1 -0
  73. package/lib/function/noop.js +2 -0
  74. package/lib/function/noop.js.map +1 -0
  75. package/lib/legacy/rename.d.ts +13 -0
  76. package/lib/legacy/rename.d.ts.map +1 -0
  77. package/lib/legacy/rename.js +13 -0
  78. package/lib/legacy/rename.js.map +1 -0
  79. package/lib/lifecycle/cancellation/driver.browser.d.ts.map +1 -0
  80. package/lib/lifecycle/cancellation/driver.browser.js.map +1 -0
  81. package/lib/lifecycle/cancellation/driver.common.d.ts.map +1 -0
  82. package/lib/lifecycle/{promise/cancellationToken → cancellation}/driver.common.js +1 -1
  83. package/lib/lifecycle/cancellation/driver.common.js.map +1 -0
  84. package/lib/lifecycle/{promise/cancellationToken → cancellation}/source.d.ts +3 -3
  85. package/lib/lifecycle/cancellation/source.d.ts.map +1 -0
  86. package/lib/lifecycle/{promise/cancellationToken → cancellation}/source.js +2 -2
  87. package/lib/lifecycle/cancellation/source.js.map +1 -0
  88. package/lib/lifecycle/dispose/async-disposable.d.ts +17 -0
  89. package/lib/lifecycle/dispose/async-disposable.d.ts.map +1 -0
  90. package/lib/lifecycle/dispose/async-disposable.js +42 -0
  91. package/lib/lifecycle/dispose/async-disposable.js.map +1 -0
  92. package/lib/lifecycle/dispose/bridges/function.d.ts +17 -0
  93. package/lib/lifecycle/dispose/bridges/function.d.ts.map +1 -0
  94. package/lib/lifecycle/dispose/bridges/function.js +29 -0
  95. package/lib/lifecycle/dispose/bridges/function.js.map +1 -0
  96. package/lib/lifecycle/dispose/bridges/native.d.ts +10 -0
  97. package/lib/lifecycle/dispose/bridges/native.d.ts.map +1 -0
  98. package/lib/lifecycle/dispose/bridges/native.js +13 -0
  99. package/lib/lifecycle/dispose/bridges/native.js.map +1 -0
  100. package/lib/lifecycle/dispose/bridges/streams.d.ts +21 -0
  101. package/lib/lifecycle/dispose/bridges/streams.d.ts.map +1 -0
  102. package/lib/lifecycle/dispose/bridges/streams.js +60 -0
  103. package/lib/lifecycle/dispose/bridges/streams.js.map +1 -0
  104. package/lib/lifecycle/dispose/debug.js +17 -3
  105. package/lib/lifecycle/dispose/debug.js.map +1 -1
  106. package/lib/lifecycle/dispose/disposable.d.ts +22 -0
  107. package/lib/lifecycle/dispose/disposable.d.ts.map +1 -0
  108. package/lib/lifecycle/dispose/disposable.js +120 -0
  109. package/lib/lifecycle/dispose/disposable.js.map +1 -0
  110. package/lib/lifecycle/dispose/disposableEvent.d.ts +9 -14
  111. package/lib/lifecycle/dispose/disposableEvent.d.ts.map +1 -1
  112. package/lib/lifecycle/dispose/disposableEvent.js +14 -64
  113. package/lib/lifecycle/dispose/disposableEvent.js.map +1 -1
  114. package/lib/lifecycle/dispose/disposedError.d.ts +9 -4
  115. package/lib/lifecycle/dispose/disposedError.d.ts.map +1 -1
  116. package/lib/lifecycle/dispose/disposedError.js +28 -13
  117. package/lib/lifecycle/dispose/disposedError.js.map +1 -1
  118. package/lib/lifecycle/dispose/sync-disposable.d.ts +21 -0
  119. package/lib/lifecycle/dispose/sync-disposable.d.ts.map +1 -0
  120. package/lib/lifecycle/dispose/sync-disposable.js +52 -0
  121. package/lib/lifecycle/dispose/sync-disposable.js.map +1 -0
  122. package/lib/lifecycle/event/event.d.ts +18 -33
  123. package/lib/lifecycle/event/event.d.ts.map +1 -1
  124. package/lib/lifecycle/event/event.js +75 -64
  125. package/lib/lifecycle/event/event.js.map +1 -1
  126. package/lib/lifecycle/event/memorized.d.ts +4 -3
  127. package/lib/lifecycle/event/memorized.d.ts.map +1 -1
  128. package/lib/lifecycle/event/memorized.js +9 -10
  129. package/lib/lifecycle/event/memorized.js.map +1 -1
  130. package/lib/lifecycle/event/type.d.ts +47 -0
  131. package/lib/lifecycle/event/type.d.ts.map +1 -0
  132. package/lib/lifecycle/event/type.js +2 -0
  133. package/lib/lifecycle/event/type.js.map +1 -0
  134. package/lib/lifecycle/{dispose/lifecycle.global.d.ts → global/global-lifecycle.d.ts} +3 -15
  135. package/lib/lifecycle/global/global-lifecycle.d.ts.map +1 -0
  136. package/lib/lifecycle/{dispose/lifecycle.global.js → global/global-lifecycle.js} +8 -21
  137. package/lib/lifecycle/global/global-lifecycle.js.map +1 -0
  138. package/lib/log/logger.js +1 -1
  139. package/lib/log/logger.js.map +1 -1
  140. package/lib/{mapSet/customSet.d.ts → map-and-set/custom-set.d.ts} +4 -8
  141. package/lib/map-and-set/custom-set.d.ts.map +1 -0
  142. package/lib/{mapSet/customSet.js → map-and-set/custom-set.js} +6 -20
  143. package/lib/map-and-set/custom-set.js.map +1 -0
  144. package/lib/map-and-set/required-map.d.ts +28 -0
  145. package/lib/map-and-set/required-map.d.ts.map +1 -0
  146. package/lib/map-and-set/required-map.js +42 -0
  147. package/lib/map-and-set/required-map.js.map +1 -0
  148. package/lib/object/objectSame.js +1 -1
  149. package/lib/object/objectSame.js.map +1 -1
  150. package/lib/path/pathArray.js +1 -1
  151. package/lib/path/pathArray.js.map +1 -1
  152. package/lib/path/pathCalc.d.ts +10 -0
  153. package/lib/path/pathCalc.d.ts.map +1 -0
  154. package/lib/path/pathCalc.js +17 -0
  155. package/lib/path/pathCalc.js.map +1 -0
  156. package/lib/platform/compile.d.ts +7 -0
  157. package/lib/platform/compile.d.ts.map +1 -0
  158. package/lib/platform/compile.js +2 -0
  159. package/lib/platform/compile.js.map +1 -0
  160. package/lib/platform/globalSingleton.js +1 -1
  161. package/lib/platform/globalSingleton.js.map +1 -1
  162. package/lib/platform/os.d.ts.map +1 -1
  163. package/lib/platform/os.js +1 -1
  164. package/lib/platform/os.js.map +1 -1
  165. package/lib/promise/{awaitIterator.d.ts → await-iterator.d.ts} +1 -1
  166. package/lib/promise/await-iterator.d.ts.map +1 -0
  167. package/lib/promise/{awaitIterator.js → await-iterator.js} +1 -1
  168. package/lib/promise/await-iterator.js.map +1 -0
  169. package/lib/{lifecycle/promise/deferredPromise.d.ts → promise/deferred-promise.d.ts} +14 -6
  170. package/lib/promise/deferred-promise.d.ts.map +1 -0
  171. package/lib/{lifecycle/promise/deferredPromise.js → promise/deferred-promise.js} +57 -16
  172. package/lib/promise/deferred-promise.js.map +1 -0
  173. package/lib/promise/{promiseBool.d.ts → promise-bool.d.ts} +1 -1
  174. package/lib/promise/promise-bool.d.ts.map +1 -0
  175. package/lib/promise/{promiseBool.js → promise-bool.js} +1 -1
  176. package/lib/promise/promise-bool.js.map +1 -0
  177. package/lib/promise/{promiseCollection.d.ts → promise-list.d.ts} +3 -3
  178. package/lib/promise/promise-list.d.ts.map +1 -0
  179. package/lib/promise/{promiseCollection.js → promise-list.js} +3 -3
  180. package/lib/promise/promise-list.js.map +1 -0
  181. package/lib/re-export.d.ts +2 -0
  182. package/lib/re-export.d.ts.map +1 -0
  183. package/lib/re-export.js +2 -0
  184. package/lib/re-export.js.map +1 -0
  185. package/lib/reflection/classes/pointer.d.ts +5 -0
  186. package/lib/reflection/classes/pointer.d.ts.map +1 -0
  187. package/lib/reflection/classes/pointer.js +49 -0
  188. package/lib/reflection/classes/pointer.js.map +1 -0
  189. package/lib/reflection/classes/singleton.d.ts +10 -2
  190. package/lib/reflection/classes/singleton.d.ts.map +1 -1
  191. package/lib/reflection/classes/singleton.js +29 -21
  192. package/lib/reflection/classes/singleton.js.map +1 -1
  193. package/lib/reflection/methods/bind.d.ts +1 -4
  194. package/lib/reflection/methods/bind.d.ts.map +1 -1
  195. package/lib/reflection/methods/bind.js +17 -23
  196. package/lib/reflection/methods/bind.js.map +1 -1
  197. package/lib/reflection/methods/memorize.d.ts +7 -4
  198. package/lib/reflection/methods/memorize.d.ts.map +1 -1
  199. package/lib/reflection/methods/memorize.js +27 -23
  200. package/lib/reflection/methods/memorize.js.map +1 -1
  201. package/lib/schedule/extendable-timer.d.ts +16 -0
  202. package/lib/schedule/extendable-timer.d.ts.map +1 -0
  203. package/lib/schedule/extendable-timer.js +45 -0
  204. package/lib/schedule/extendable-timer.js.map +1 -0
  205. package/lib/{lifecycle/timeout → schedule}/interval.d.ts +3 -3
  206. package/lib/schedule/interval.d.ts.map +1 -0
  207. package/lib/{lifecycle/timeout → schedule}/interval.js +3 -3
  208. package/lib/schedule/interval.js.map +1 -0
  209. package/lib/schedule/local-type.d.ts +3 -0
  210. package/lib/schedule/local-type.d.ts.map +1 -0
  211. package/lib/schedule/local-type.js +2 -0
  212. package/lib/schedule/local-type.js.map +1 -0
  213. package/lib/schedule/scheduler.d.ts +4 -0
  214. package/lib/schedule/scheduler.d.ts.map +1 -0
  215. package/lib/schedule/scheduler.js +3 -0
  216. package/lib/schedule/scheduler.js.map +1 -0
  217. package/lib/{lifecycle/timeout → schedule}/timeout.d.ts +2 -3
  218. package/lib/schedule/timeout.d.ts.map +1 -0
  219. package/lib/{lifecycle/timeout → schedule}/timeout.js +5 -11
  220. package/lib/schedule/timeout.js.map +1 -0
  221. package/lib/state/{StateMachine.d.ts → simple-state-machine.d.ts} +1 -1
  222. package/lib/state/simple-state-machine.d.ts.map +1 -0
  223. package/lib/state/{StateMachine.js → simple-state-machine.js} +1 -1
  224. package/lib/state/simple-state-machine.js.map +1 -0
  225. package/lib/string/{castCase.d.ts → case-cast.d.ts} +1 -1
  226. package/lib/string/case-cast.d.ts.map +1 -0
  227. package/lib/string/{castCase.js → case-cast.js} +1 -1
  228. package/lib/string/case-cast.js.map +1 -0
  229. package/lib/string/{escapeRegexp.d.ts → escape-regexp.d.ts} +1 -1
  230. package/lib/string/escape-regexp.d.ts.map +1 -0
  231. package/lib/string/{escapeRegexp.js → escape-regexp.js} +1 -1
  232. package/lib/string/escape-regexp.js.map +1 -0
  233. package/lib/string/{sizeString.d.ts → human-bytes.d.ts} +1 -1
  234. package/lib/string/human-bytes.d.ts.map +1 -0
  235. package/lib/string/{sizeString.js → human-bytes.js} +1 -1
  236. package/lib/string/human-bytes.js.map +1 -0
  237. package/lib/tsconfig.tsbuildinfo +1 -1
  238. package/lib/typing-helper/callback.d.ts +5 -0
  239. package/lib/typing-helper/callback.d.ts.map +1 -0
  240. package/lib/typing-helper/callback.js +2 -0
  241. package/lib/typing-helper/callback.js.map +1 -0
  242. package/lib/typing-helper/deep.partial.d.ts.map +1 -0
  243. package/lib/typing-helper/deep.partial.js.map +1 -0
  244. package/lib/typing-helper/deep.readonly.d.ts.map +1 -0
  245. package/lib/typing-helper/deep.readonly.js.map +1 -0
  246. package/lib/typing-helper/deep.required.d.ts.map +1 -0
  247. package/lib/typing-helper/deep.required.js.map +1 -0
  248. package/lib/typing-helper/deep.writable.d.ts.map +1 -0
  249. package/lib/typing-helper/deep.writable.js.map +1 -0
  250. package/lib/typing-helper/literal.d.ts.map +1 -0
  251. package/lib/{typingHelper → typing-helper}/literal.js.map +1 -1
  252. package/package.json +8 -7
  253. package/src/autoindex.ts +239 -213
  254. package/src/date/{timeString.ts → to-string.ts} +28 -29
  255. package/src/debugging/{tryInspect.ts → inspect.ts} +1 -1
  256. package/src/debugging/object-with-name.ts +64 -0
  257. package/src/debugging/serializable.ts +1 -1
  258. package/src/error/convert-unknown.ts +9 -0
  259. package/src/error/{getFrame.ts → get-frame.ts} +1 -1
  260. package/src/error/{pretty.ts → pretty.nodejs.ts} +3 -2
  261. package/src/function/{asyncCallbackList.ts → callback-list.async.ts} +2 -7
  262. package/src/function/callback-list.delay.ts +29 -0
  263. package/src/function/{callbackList.ts → callback-list.ts} +1 -1
  264. package/src/function/noop.ts +1 -0
  265. package/src/global.d.ts +10 -0
  266. package/src/legacy/rename.ts +15 -0
  267. package/src/lifecycle/{promise/cancellationToken → cancellation}/driver.browser.ts +3 -4
  268. package/src/lifecycle/{promise/cancellationToken → cancellation}/driver.common.ts +3 -2
  269. package/src/lifecycle/{promise/cancellationToken → cancellation}/source.ts +4 -4
  270. package/src/lifecycle/dispose/async-disposable.ts +41 -0
  271. package/src/lifecycle/dispose/bridges/function.ts +31 -0
  272. package/src/lifecycle/dispose/bridges/native.ts +23 -0
  273. package/src/lifecycle/dispose/bridges/streams.ts +70 -0
  274. package/src/lifecycle/dispose/debug.ts +22 -4
  275. package/src/lifecycle/dispose/disposable.ts +162 -0
  276. package/src/lifecycle/dispose/disposableEvent.ts +20 -86
  277. package/src/lifecycle/dispose/disposedError.ts +36 -19
  278. package/src/lifecycle/dispose/sync-disposable.ts +53 -0
  279. package/src/lifecycle/event/event.ts +83 -76
  280. package/src/lifecycle/event/memorized.ts +13 -12
  281. package/src/lifecycle/event/type.ts +55 -0
  282. package/src/lifecycle/global/global-lifecycle.ts +49 -0
  283. package/src/log/logger.ts +1 -1
  284. package/src/{mapSet/customSet.ts → map-and-set/custom-set.ts} +7 -26
  285. package/src/{mapSet/extendMap.ts → map-and-set/required-map.ts} +21 -6
  286. package/src/object/objectSame.ts +1 -1
  287. package/src/path/pathArray.ts +1 -1
  288. package/src/path/pathCalc.ts +18 -0
  289. package/src/platform/compile.ts +6 -0
  290. package/src/platform/globalSingleton.ts +1 -1
  291. package/src/platform/os.ts +1 -1
  292. package/src/{lifecycle/promise/deferredPromise.ts → promise/deferred-promise.ts} +68 -27
  293. package/src/promise/{promiseCollection.ts → promise-list.ts} +2 -2
  294. package/src/re-export.ts +1 -0
  295. package/src/reflection/classes/pointer.ts +54 -0
  296. package/src/reflection/classes/singleton.ts +30 -21
  297. package/src/reflection/methods/bind.ts +15 -23
  298. package/src/reflection/methods/memorize.ts +30 -23
  299. package/src/schedule/extendable-timer.ts +49 -0
  300. package/src/{lifecycle/timeout → schedule}/interval.ts +4 -4
  301. package/src/schedule/local-type.ts +2 -0
  302. package/src/schedule/scheduler.ts +8 -0
  303. package/src/{lifecycle/timeout → schedule}/timeout.ts +7 -13
  304. package/src/state/{StateMachine.ts → simple-state-machine.ts} +3 -4
  305. package/src/tsconfig.json +3 -1
  306. package/src/typing-helper/callback.ts +4 -0
  307. package/lib/array/arrayDiff.d.ts.map +0 -1
  308. package/lib/array/arrayDiff.js.map +0 -1
  309. package/lib/array/arraySame.d.ts.map +0 -1
  310. package/lib/array/arraySame.js.map +0 -1
  311. package/lib/array/arrayUnique.d.ts.map +0 -1
  312. package/lib/array/arrayUnique.js.map +0 -1
  313. package/lib/array/normalizeArray.d.ts.map +0 -1
  314. package/lib/array/normalizeArray.js.map +0 -1
  315. package/lib/array/sortAlpha.d.ts.map +0 -1
  316. package/lib/array/sortAlpha.js.map +0 -1
  317. package/lib/date/isInvalid.d.ts.map +0 -1
  318. package/lib/date/isInvalid.js.map +0 -1
  319. package/lib/date/timeString.d.ts.map +0 -1
  320. package/lib/date/timeString.js.map +0 -1
  321. package/lib/debugging/tryInspect.d.ts.map +0 -1
  322. package/lib/debugging/tryInspect.js.map +0 -1
  323. package/lib/error/convertUnknown.d.ts +0 -2
  324. package/lib/error/convertUnknown.d.ts.map +0 -1
  325. package/lib/error/convertUnknown.js +0 -9
  326. package/lib/error/convertUnknown.js.map +0 -1
  327. package/lib/error/getFrame.d.ts.map +0 -1
  328. package/lib/error/getFrame.js.map +0 -1
  329. package/lib/error/pretty.d.ts.map +0 -1
  330. package/lib/error/pretty.js.map +0 -1
  331. package/lib/error/stackTrace.d.ts.map +0 -1
  332. package/lib/error/stackTrace.js.map +0 -1
  333. package/lib/error-wellknown/exit.error.d.ts +0 -13
  334. package/lib/error-wellknown/exit.error.d.ts.map +0 -1
  335. package/lib/error-wellknown/exit.error.js +0 -20
  336. package/lib/error-wellknown/exit.error.js.map +0 -1
  337. package/lib/function/asyncCallbackList.d.ts.map +0 -1
  338. package/lib/function/asyncCallbackList.js.map +0 -1
  339. package/lib/function/callbackList.d.ts.map +0 -1
  340. package/lib/function/callbackList.js.map +0 -1
  341. package/lib/function/delayCallbackList.d.ts +0 -17
  342. package/lib/function/delayCallbackList.d.ts.map +0 -1
  343. package/lib/function/delayCallbackList.js +0 -36
  344. package/lib/function/delayCallbackList.js.map +0 -1
  345. package/lib/function/functionName.d.ts +0 -26
  346. package/lib/function/functionName.d.ts.map +0 -1
  347. package/lib/function/functionName.js +0 -27
  348. package/lib/function/functionName.js.map +0 -1
  349. package/lib/lifecycle/dispose/bridges/rxjs.d.ts +0 -8
  350. package/lib/lifecycle/dispose/bridges/rxjs.d.ts.map +0 -1
  351. package/lib/lifecycle/dispose/bridges/rxjs.js +0 -4
  352. package/lib/lifecycle/dispose/bridges/rxjs.js.map +0 -1
  353. package/lib/lifecycle/dispose/lifecycle.async.d.ts +0 -37
  354. package/lib/lifecycle/dispose/lifecycle.async.d.ts.map +0 -1
  355. package/lib/lifecycle/dispose/lifecycle.async.js +0 -111
  356. package/lib/lifecycle/dispose/lifecycle.async.js.map +0 -1
  357. package/lib/lifecycle/dispose/lifecycle.d.ts +0 -32
  358. package/lib/lifecycle/dispose/lifecycle.d.ts.map +0 -1
  359. package/lib/lifecycle/dispose/lifecycle.global.d.ts.map +0 -1
  360. package/lib/lifecycle/dispose/lifecycle.global.js.map +0 -1
  361. package/lib/lifecycle/dispose/lifecycle.js +0 -67
  362. package/lib/lifecycle/dispose/lifecycle.js.map +0 -1
  363. package/lib/lifecycle/dispose/lifecycle.sync.d.ts +0 -45
  364. package/lib/lifecycle/dispose/lifecycle.sync.d.ts.map +0 -1
  365. package/lib/lifecycle/dispose/lifecycle.sync.js +0 -115
  366. package/lib/lifecycle/dispose/lifecycle.sync.js.map +0 -1
  367. package/lib/lifecycle/promise/cancel.d.ts +0 -10
  368. package/lib/lifecycle/promise/cancel.d.ts.map +0 -1
  369. package/lib/lifecycle/promise/cancel.js +0 -15
  370. package/lib/lifecycle/promise/cancel.js.map +0 -1
  371. package/lib/lifecycle/promise/cancellationToken/driver.browser.d.ts.map +0 -1
  372. package/lib/lifecycle/promise/cancellationToken/driver.browser.js.map +0 -1
  373. package/lib/lifecycle/promise/cancellationToken/driver.common.d.ts.map +0 -1
  374. package/lib/lifecycle/promise/cancellationToken/driver.common.js.map +0 -1
  375. package/lib/lifecycle/promise/cancellationToken/source.d.ts.map +0 -1
  376. package/lib/lifecycle/promise/cancellationToken/source.js.map +0 -1
  377. package/lib/lifecycle/promise/deferredPromise.d.ts.map +0 -1
  378. package/lib/lifecycle/promise/deferredPromise.js.map +0 -1
  379. package/lib/lifecycle/timeout/interval.d.ts.map +0 -1
  380. package/lib/lifecycle/timeout/interval.js.map +0 -1
  381. package/lib/lifecycle/timeout/timeout.d.ts.map +0 -1
  382. package/lib/lifecycle/timeout/timeout.js.map +0 -1
  383. package/lib/lifecycle/timeout/timeoutError.d.ts +0 -11
  384. package/lib/lifecycle/timeout/timeoutError.d.ts.map +0 -1
  385. package/lib/lifecycle/timeout/timeoutError.js +0 -16
  386. package/lib/lifecycle/timeout/timeoutError.js.map +0 -1
  387. package/lib/mapSet/customSet.d.ts.map +0 -1
  388. package/lib/mapSet/customSet.js.map +0 -1
  389. package/lib/mapSet/extendMap.d.ts +0 -21
  390. package/lib/mapSet/extendMap.d.ts.map +0 -1
  391. package/lib/mapSet/extendMap.js +0 -26
  392. package/lib/mapSet/extendMap.js.map +0 -1
  393. package/lib/promise/awaitIterator.d.ts.map +0 -1
  394. package/lib/promise/awaitIterator.js.map +0 -1
  395. package/lib/promise/finishAllPromise.d.ts +0 -13
  396. package/lib/promise/finishAllPromise.d.ts.map +0 -1
  397. package/lib/promise/finishAllPromise.js +0 -37
  398. package/lib/promise/finishAllPromise.js.map +0 -1
  399. package/lib/promise/promiseBool.d.ts.map +0 -1
  400. package/lib/promise/promiseBool.js.map +0 -1
  401. package/lib/promise/promiseCollection.d.ts.map +0 -1
  402. package/lib/promise/promiseCollection.js.map +0 -1
  403. package/lib/promise/timeoutPromiseCollection.d.ts +0 -7
  404. package/lib/promise/timeoutPromiseCollection.d.ts.map +0 -1
  405. package/lib/promise/timeoutPromiseCollection.js +0 -20
  406. package/lib/promise/timeoutPromiseCollection.js.map +0 -1
  407. package/lib/reflection/classes/hookClass.d.ts +0 -11
  408. package/lib/reflection/classes/hookClass.d.ts.map +0 -1
  409. package/lib/reflection/classes/hookClass.js +0 -34
  410. package/lib/reflection/classes/hookClass.js.map +0 -1
  411. package/lib/reflection/methods/initOnRead.d.ts +0 -7
  412. package/lib/reflection/methods/initOnRead.d.ts.map +0 -1
  413. package/lib/reflection/methods/initOnRead.js +0 -11
  414. package/lib/reflection/methods/initOnRead.js.map +0 -1
  415. package/lib/state/StateMachine.d.ts.map +0 -1
  416. package/lib/state/StateMachine.js.map +0 -1
  417. package/lib/string/castCase.d.ts.map +0 -1
  418. package/lib/string/castCase.js.map +0 -1
  419. package/lib/string/escapeRegexp.d.ts.map +0 -1
  420. package/lib/string/escapeRegexp.js.map +0 -1
  421. package/lib/string/sizeString.d.ts.map +0 -1
  422. package/lib/string/sizeString.js.map +0 -1
  423. package/lib/typingHelper/deep.partial.d.ts.map +0 -1
  424. package/lib/typingHelper/deep.partial.js.map +0 -1
  425. package/lib/typingHelper/deep.readonly.d.ts.map +0 -1
  426. package/lib/typingHelper/deep.readonly.js.map +0 -1
  427. package/lib/typingHelper/deep.required.d.ts.map +0 -1
  428. package/lib/typingHelper/deep.required.js.map +0 -1
  429. package/lib/typingHelper/deep.writable.d.ts.map +0 -1
  430. package/lib/typingHelper/deep.writable.js.map +0 -1
  431. package/lib/typingHelper/literal.d.ts.map +0 -1
  432. package/src/error/convertUnknown.ts +0 -9
  433. package/src/error-wellknown/exit.error.ts +0 -21
  434. package/src/function/delayCallbackList.ts +0 -45
  435. package/src/function/functionName.ts +0 -44
  436. package/src/lifecycle/dispose/bridges/rxjs.ts +0 -6
  437. package/src/lifecycle/dispose/lifecycle.async.ts +0 -134
  438. package/src/lifecycle/dispose/lifecycle.global.ts +0 -66
  439. package/src/lifecycle/dispose/lifecycle.sync.ts +0 -133
  440. package/src/lifecycle/dispose/lifecycle.ts +0 -94
  441. package/src/lifecycle/promise/cancel.ts +0 -16
  442. package/src/lifecycle/timeout/timeoutError.ts +0 -18
  443. package/src/promise/finishAllPromise.ts +0 -50
  444. package/src/promise/timeoutPromiseCollection.ts +0 -22
  445. package/src/reflection/classes/hookClass.ts +0 -47
  446. package/src/reflection/methods/initOnRead.ts +0 -11
  447. /package/lib/lifecycle/{promise/cancellationToken → cancellation}/driver.browser.d.ts +0 -0
  448. /package/lib/lifecycle/{promise/cancellationToken → cancellation}/driver.browser.js +0 -0
  449. /package/lib/lifecycle/{promise/cancellationToken → cancellation}/driver.common.d.ts +0 -0
  450. /package/lib/{typingHelper → typing-helper}/deep.partial.d.ts +0 -0
  451. /package/lib/{typingHelper → typing-helper}/deep.partial.js +0 -0
  452. /package/lib/{typingHelper → typing-helper}/deep.readonly.d.ts +0 -0
  453. /package/lib/{typingHelper → typing-helper}/deep.readonly.js +0 -0
  454. /package/lib/{typingHelper → typing-helper}/deep.required.d.ts +0 -0
  455. /package/lib/{typingHelper → typing-helper}/deep.required.js +0 -0
  456. /package/lib/{typingHelper → typing-helper}/deep.writable.d.ts +0 -0
  457. /package/lib/{typingHelper → typing-helper}/deep.writable.js +0 -0
  458. /package/lib/{typingHelper → typing-helper}/literal.d.ts +0 -0
  459. /package/lib/{typingHelper → typing-helper}/literal.js +0 -0
  460. /package/src/array/{arrayDiff.ts → diff.ts} +0 -0
  461. /package/src/array/{arraySame.ts → is-same.ts} +0 -0
  462. /package/src/array/{normalizeArray.ts → normalize.ts} +0 -0
  463. /package/src/array/{sortAlpha.ts → sort-alpha.ts} +0 -0
  464. /package/src/array/{arrayUnique.ts → unique.ts} +0 -0
  465. /package/src/date/{isInvalid.ts → is-invalid.ts} +0 -0
  466. /package/src/error/{stackTrace.ts → stack-trace.ts} +0 -0
  467. /package/src/promise/{awaitIterator.ts → await-iterator.ts} +0 -0
  468. /package/src/promise/{promiseBool.ts → promise-bool.ts} +0 -0
  469. /package/src/string/{castCase.ts → case-cast.ts} +0 -0
  470. /package/src/string/{escapeRegexp.ts → escape-regexp.ts} +0 -0
  471. /package/src/string/{sizeString.ts → human-bytes.ts} +0 -0
  472. /package/src/{typingHelper → typing-helper}/deep.partial.ts +0 -0
  473. /package/src/{typingHelper → typing-helper}/deep.readonly.ts +0 -0
  474. /package/src/{typingHelper → typing-helper}/deep.required.ts +0 -0
  475. /package/src/{typingHelper → typing-helper}/deep.writable.ts +0 -0
  476. /package/src/{typingHelper → typing-helper}/literal.ts +0 -0
@@ -1,5 +1,6 @@
1
- import type { IDisposable } from '../dispose/lifecycle.js';
2
- import { Emitter, type EventHandler } from './event.js';
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
- this._memo = data;
15
- this._is_memo = true;
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
- this._memo = data;
21
- this._is_memo = true;
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._is_memo) callback(this._memo!);
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,4 +1,4 @@
1
- import { nameFunction } from '../function/functionName.js';
1
+ import { nameFunction } from '../debugging/object-with-name.js';
2
2
  import { isWeb } from '../platform/os.js';
3
3
 
4
4
  export enum ColorKind {
@@ -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 insteadof ===
5
+ * Like a Set, but use custom compare function instead ===
12
6
  */
13
- export class CustomSet<Type = string> {
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
- setFinder(finder: Finder<Type>) {
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.finder(item) !== -1;
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.finder(item);
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.finder(item);
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 ExtendMap<K, V> extends Map<K, V> {
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 set to map
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
+ }
@@ -1,4 +1,4 @@
1
- import { isArraySame } from '../array/arraySame.js';
1
+ import { isArraySame } from '../array/is-same.js';
2
2
 
3
3
  /**
4
4
  * Should ensure a and b is none-null before call this
@@ -1,5 +1,5 @@
1
1
  import { isWindows } from '../platform/os.js';
2
- import { ucfirst } from '../string/castCase.js';
2
+ import { ucfirst } from '../string/case-cast.js';
3
3
  import { normalizePath } from './normalizePath.js';
4
4
 
5
5
  const isAbsolute = /^[a-z]:[/\\]/i;
@@ -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
+ }
@@ -0,0 +1,6 @@
1
+ declare global {
2
+ interface ImportMeta {
3
+ env?: Record<string, string>;
4
+ }
5
+ }
6
+ export const isProductionMode = import.meta.env?.['MODE'] === 'production';
@@ -1,6 +1,6 @@
1
1
  /** biome-ignore-all lint/suspicious/noShadowRestrictedNames: */
2
2
 
3
- import { functionName } from '../function/functionName.js';
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', () => {
@@ -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 type { IDisposable } from '../dispose/lifecycle.js';
2
- import { CanceledError } from './cancel.js';
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 p: Promise<T> & IProgressHolder<T, PT>;
17
- #completeCallback!: ValueCallback<T>;
18
- #errorCallback!: (err: any) => void;
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
- this.p = Object.assign(
24
- new Promise<any>((c, e) => {
25
- this.#completeCallback = c;
26
- this.#errorCallback = e;
27
- }),
28
- {
29
- progress: (fn: ProgressCallback<PT>) => {
30
- this.progress(fn);
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
- * whether the promise is completed (resolved or rejected)
81
+ * @deprecated use settled
79
82
  */
80
- get completed(): boolean {
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.#success = false;
115
- this.#errorCallback(new CanceledError());
116
- this.#no_more_progress();
126
+ this.error(new CanceledError());
117
127
  }
118
128
 
119
- #no_more_progress() {
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 '../lifecycle/promise/cancel.js';
2
- import { DeferredPromise } from '../lifecycle/promise/deferredPromise.js';
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>> = {};
@@ -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 { hookClass } from './hookClass.js';
1
+ import { definePrivateConstant } from '../../autoindex.js';
2
2
 
3
- export const singletonSymbol = Symbol('@gongt/singleton');
3
+ export const singletonSymbol = Symbol('@idlebox/singleton');
4
4
 
5
5
  export enum SingletonType {
6
6
  Throw = 0,
7
- Return = 1,
7
+ ReturnSame = 1,
8
8
  }
9
9
 
10
- export function singleton(type: SingletonType = SingletonType.Return): ClassDecorator {
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
- hook.beforeConstruct.push((cls) => {
21
- if (cls[singletonSymbol]) {
22
- if (type === SingletonType.Return) {
23
- return cls[singletonSymbol];
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
- throw new Error(`Duplicate new singleton class [${target.name}]`);
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
- const fn = oldFunc.bind(this);
14
- Object.defineProperty(this, propertyKey, {
15
- value: fn,
16
- writable: false,
17
- enumerable: true,
18
- configurable: false,
19
- });
20
- return fn;
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
- throw new TypeError('@bindThis can only use with method, but not property.');
25
- };
17
+ }