@zk-tech/bedrock 0.0.1

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 (390) hide show
  1. package/README.md +24 -0
  2. package/dist/array/index.cjs +22 -0
  3. package/dist/array/index.cjs.map +1 -0
  4. package/dist/array/index.d.cts +13 -0
  5. package/dist/array/index.d.ts +13 -0
  6. package/dist/array/index.js +19 -0
  7. package/dist/array/index.js.map +1 -0
  8. package/dist/assert/index.cjs +29 -0
  9. package/dist/assert/index.cjs.map +1 -0
  10. package/dist/assert/index.d.cts +25 -0
  11. package/dist/assert/index.d.ts +25 -0
  12. package/dist/assert/index.js +24 -0
  13. package/dist/assert/index.js.map +1 -0
  14. package/dist/async/index.cjs +746 -0
  15. package/dist/async/index.cjs.map +1 -0
  16. package/dist/async/index.d.cts +47 -0
  17. package/dist/async/index.d.ts +47 -0
  18. package/dist/async/index.js +738 -0
  19. package/dist/async/index.js.map +1 -0
  20. package/dist/barrier-316Xonfd.d.cts +18 -0
  21. package/dist/barrier-316Xonfd.d.ts +18 -0
  22. package/dist/byte/index.cjs +59 -0
  23. package/dist/byte/index.cjs.map +1 -0
  24. package/dist/byte/index.d.cts +12 -0
  25. package/dist/byte/index.d.ts +12 -0
  26. package/dist/byte/index.js +49 -0
  27. package/dist/byte/index.js.map +1 -0
  28. package/dist/cache/index.cjs +418 -0
  29. package/dist/cache/index.cjs.map +1 -0
  30. package/dist/cache/index.d.cts +40 -0
  31. package/dist/cache/index.d.ts +40 -0
  32. package/dist/cache/index.js +415 -0
  33. package/dist/cache/index.js.map +1 -0
  34. package/dist/cancellation-BIIv2UJm.d.cts +25 -0
  35. package/dist/cancellation-ClqPPsV1.d.ts +25 -0
  36. package/dist/context/index.cjs +59 -0
  37. package/dist/context/index.cjs.map +1 -0
  38. package/dist/context/index.d.cts +33 -0
  39. package/dist/context/index.d.ts +33 -0
  40. package/dist/context/index.js +51 -0
  41. package/dist/context/index.js.map +1 -0
  42. package/dist/di/index.cjs +1965 -0
  43. package/dist/di/index.cjs.map +1 -0
  44. package/dist/di/index.d.cts +140 -0
  45. package/dist/di/index.d.ts +140 -0
  46. package/dist/di/index.js +1949 -0
  47. package/dist/di/index.js.map +1 -0
  48. package/dist/disposable-t-B15Nu57y.d.ts +93 -0
  49. package/dist/disposable-t-CVsiyHPL.d.cts +93 -0
  50. package/dist/dispose/index.cjs +356 -0
  51. package/dist/dispose/index.cjs.map +1 -0
  52. package/dist/dispose/index.d.cts +26 -0
  53. package/dist/dispose/index.d.ts +26 -0
  54. package/dist/dispose/index.js +340 -0
  55. package/dist/dispose/index.js.map +1 -0
  56. package/dist/dispose-base-CAeXDpjg.d.cts +6 -0
  57. package/dist/dispose-base-CAeXDpjg.d.ts +6 -0
  58. package/dist/emitter-CAfCtSTg.d.cts +35 -0
  59. package/dist/emitter-DeM5mlEm.d.ts +35 -0
  60. package/dist/error/index.cjs +145 -0
  61. package/dist/error/index.cjs.map +1 -0
  62. package/dist/error/index.d.cts +45 -0
  63. package/dist/error/index.d.ts +45 -0
  64. package/dist/error/index.js +126 -0
  65. package/dist/error/index.js.map +1 -0
  66. package/dist/error-base-B4zaiJ5m.d.cts +32 -0
  67. package/dist/error-base-B4zaiJ5m.d.ts +32 -0
  68. package/dist/event/index.cjs +550 -0
  69. package/dist/event/index.cjs.map +1 -0
  70. package/dist/event/index.d.cts +139 -0
  71. package/dist/event/index.d.ts +139 -0
  72. package/dist/event/index.js +538 -0
  73. package/dist/event/index.js.map +1 -0
  74. package/dist/function/index.cjs +132 -0
  75. package/dist/function/index.cjs.map +1 -0
  76. package/dist/function/index.d.cts +26 -0
  77. package/dist/function/index.d.ts +26 -0
  78. package/dist/function/index.js +129 -0
  79. package/dist/function/index.js.map +1 -0
  80. package/dist/graph-BGbNOniY.d.cts +23 -0
  81. package/dist/graph-BGbNOniY.d.ts +23 -0
  82. package/dist/hash/index.cjs +54 -0
  83. package/dist/hash/index.cjs.map +1 -0
  84. package/dist/hash/index.d.cts +5 -0
  85. package/dist/hash/index.d.ts +5 -0
  86. package/dist/hash/index.js +50 -0
  87. package/dist/hash/index.js.map +1 -0
  88. package/dist/instantiation-service.interface-CVFMBUUD.d.cts +78 -0
  89. package/dist/instantiation-service.interface-CVFMBUUD.d.ts +78 -0
  90. package/dist/json/index.cjs +28 -0
  91. package/dist/json/index.cjs.map +1 -0
  92. package/dist/json/index.d.cts +8 -0
  93. package/dist/json/index.d.ts +8 -0
  94. package/dist/json/index.js +26 -0
  95. package/dist/json/index.js.map +1 -0
  96. package/dist/launch/index.cjs +213 -0
  97. package/dist/launch/index.cjs.map +1 -0
  98. package/dist/launch/index.d.cts +46 -0
  99. package/dist/launch/index.d.ts +46 -0
  100. package/dist/launch/index.js +211 -0
  101. package/dist/launch/index.js.map +1 -0
  102. package/dist/linked-list-CUkue5DZ.d.cts +24 -0
  103. package/dist/linked-list-CUkue5DZ.d.ts +24 -0
  104. package/dist/lock/index.cjs +662 -0
  105. package/dist/lock/index.cjs.map +1 -0
  106. package/dist/lock/index.d.cts +145 -0
  107. package/dist/lock/index.d.ts +145 -0
  108. package/dist/lock/index.js +656 -0
  109. package/dist/lock/index.js.map +1 -0
  110. package/dist/lodash-es/index.cjs +14 -0
  111. package/dist/lodash-es/index.cjs.map +1 -0
  112. package/dist/lodash-es/index.d.cts +1 -0
  113. package/dist/lodash-es/index.d.ts +1 -0
  114. package/dist/lodash-es/index.js +3 -0
  115. package/dist/lodash-es/index.js.map +1 -0
  116. package/dist/math/index.cjs +161 -0
  117. package/dist/math/index.cjs.map +1 -0
  118. package/dist/math/index.d.cts +76 -0
  119. package/dist/math/index.d.ts +76 -0
  120. package/dist/math/index.js +156 -0
  121. package/dist/math/index.js.map +1 -0
  122. package/dist/network/index.cjs +91 -0
  123. package/dist/network/index.cjs.map +1 -0
  124. package/dist/network/index.d.cts +62 -0
  125. package/dist/network/index.d.ts +62 -0
  126. package/dist/network/index.js +82 -0
  127. package/dist/network/index.js.map +1 -0
  128. package/dist/objects/index.cjs +80 -0
  129. package/dist/objects/index.cjs.map +1 -0
  130. package/dist/objects/index.d.cts +11 -0
  131. package/dist/objects/index.d.ts +11 -0
  132. package/dist/objects/index.js +77 -0
  133. package/dist/objects/index.js.map +1 -0
  134. package/dist/platform/index.cjs +62 -0
  135. package/dist/platform/index.cjs.map +1 -0
  136. package/dist/platform/index.d.cts +21 -0
  137. package/dist/platform/index.d.ts +21 -0
  138. package/dist/platform/index.js +48 -0
  139. package/dist/platform/index.js.map +1 -0
  140. package/dist/promise/index.cjs +639 -0
  141. package/dist/promise/index.cjs.map +1 -0
  142. package/dist/promise/index.d.cts +63 -0
  143. package/dist/promise/index.d.ts +63 -0
  144. package/dist/promise/index.js +633 -0
  145. package/dist/promise/index.js.map +1 -0
  146. package/dist/scheduler/index.cjs +599 -0
  147. package/dist/scheduler/index.cjs.map +1 -0
  148. package/dist/scheduler/index.d.cts +57 -0
  149. package/dist/scheduler/index.d.ts +57 -0
  150. package/dist/scheduler/index.js +594 -0
  151. package/dist/scheduler/index.js.map +1 -0
  152. package/dist/sprintf/index.cjs +101 -0
  153. package/dist/sprintf/index.cjs.map +1 -0
  154. package/dist/sprintf/index.d.cts +3 -0
  155. package/dist/sprintf/index.d.ts +3 -0
  156. package/dist/sprintf/index.js +99 -0
  157. package/dist/sprintf/index.js.map +1 -0
  158. package/dist/structure/index.cjs +300 -0
  159. package/dist/structure/index.cjs.map +1 -0
  160. package/dist/structure/index.d.cts +21 -0
  161. package/dist/structure/index.d.ts +21 -0
  162. package/dist/structure/index.js +296 -0
  163. package/dist/structure/index.js.map +1 -0
  164. package/dist/type/index.cjs +4 -0
  165. package/dist/type/index.cjs.map +1 -0
  166. package/dist/type/index.d.cts +20 -0
  167. package/dist/type/index.d.ts +20 -0
  168. package/dist/type/index.js +3 -0
  169. package/dist/type/index.js.map +1 -0
  170. package/dist/undo-redo-stack/index.cjs +545 -0
  171. package/dist/undo-redo-stack/index.cjs.map +1 -0
  172. package/dist/undo-redo-stack/index.d.cts +130 -0
  173. package/dist/undo-redo-stack/index.d.ts +130 -0
  174. package/dist/undo-redo-stack/index.js +542 -0
  175. package/dist/undo-redo-stack/index.js.map +1 -0
  176. package/dist/uuid/index.cjs +67 -0
  177. package/dist/uuid/index.cjs.map +1 -0
  178. package/dist/uuid/index.d.cts +17 -0
  179. package/dist/uuid/index.d.ts +17 -0
  180. package/dist/uuid/index.js +61 -0
  181. package/dist/uuid/index.js.map +1 -0
  182. package/dist/worker/index.cjs +271 -0
  183. package/dist/worker/index.cjs.map +1 -0
  184. package/dist/worker/index.d.cts +66 -0
  185. package/dist/worker/index.d.ts +66 -0
  186. package/dist/worker/index.js +267 -0
  187. package/dist/worker/index.js.map +1 -0
  188. package/package.json +285 -0
  189. package/src/_internal/logger.ts +59 -0
  190. package/src/array/array.test.ts +35 -0
  191. package/src/array/array.ts +25 -0
  192. package/src/array/index.ts +1 -0
  193. package/src/assert/assert.test.ts +86 -0
  194. package/src/assert/assert.ts +42 -0
  195. package/src/assert/index.ts +2 -0
  196. package/src/async/barrier.test.ts +90 -0
  197. package/src/async/barrier.ts +58 -0
  198. package/src/async/cancellation.test.ts +85 -0
  199. package/src/async/cancellation.ts +193 -0
  200. package/src/async/index.ts +18 -0
  201. package/src/async/queue/queue.test.ts +70 -0
  202. package/src/async/queue/queue.ts +56 -0
  203. package/src/async/queue/task.test.ts +155 -0
  204. package/src/async/queue/task.ts +67 -0
  205. package/src/async/utils.test.ts +28 -0
  206. package/src/async/utils.ts +8 -0
  207. package/src/async/wait.ts +9 -0
  208. package/src/byte/format.test.ts +64 -0
  209. package/src/byte/format.ts +44 -0
  210. package/src/byte/index.ts +2 -0
  211. package/src/byte/node_modules/.vitest/results.json +1 -0
  212. package/src/byte/var.ts +11 -0
  213. package/src/cache/index.ts +2 -0
  214. package/src/cache/lru-with-timeout.test.ts +88 -0
  215. package/src/cache/lru-with-timeout.ts +85 -0
  216. package/src/cache/lru.test.ts +56 -0
  217. package/src/cache/lru.ts +59 -0
  218. package/src/context/context.test.ts +17 -0
  219. package/src/context/context.ts +60 -0
  220. package/src/context/index.ts +8 -0
  221. package/src/di/base.ts +73 -0
  222. package/src/di/container-service.test.ts +179 -0
  223. package/src/di/context.web.tsx +41 -0
  224. package/src/di/descriptor.ts +31 -0
  225. package/src/di/idle-value.test.ts +73 -0
  226. package/src/di/idle-value.ts +63 -0
  227. package/src/di/index.common.ts +32 -0
  228. package/src/di/index.ts +2 -0
  229. package/src/di/instantiation-service.interface.ts +46 -0
  230. package/src/di/instantiation-service.test.ts +337 -0
  231. package/src/di/instantiation-service.ts +468 -0
  232. package/src/di/lazy/foo.mock.ts +28 -0
  233. package/src/di/lazy/idle-load.ts +39 -0
  234. package/src/di/lazy/index.ts +4 -0
  235. package/src/di/lazy/lazy-service.test.ts +65 -0
  236. package/src/di/lazy/lazy-service.ts +71 -0
  237. package/src/di/lazy/type.ts +5 -0
  238. package/src/di/node_modules/.vitest/results.json +1 -0
  239. package/src/di/proxy-builder.test.ts +45 -0
  240. package/src/di/proxy-builder.ts +38 -0
  241. package/src/di/service-collection.test.ts +27 -0
  242. package/src/di/service-collection.ts +46 -0
  243. package/src/di/service-ownership-collection.test.ts +39 -0
  244. package/src/di/service-ownership-collection.ts +38 -0
  245. package/src/di/service-registry.test.ts +66 -0
  246. package/src/di/service-registry.ts +99 -0
  247. package/src/di/trace.ts +85 -0
  248. package/src/dispose/disposable-store.test.ts +57 -0
  249. package/src/dispose/disposable-store.ts +80 -0
  250. package/src/dispose/disposable-t.test.ts +123 -0
  251. package/src/dispose/disposable-t.ts +238 -0
  252. package/src/dispose/disposable-utils.test.ts +15 -0
  253. package/src/dispose/disposable-utils.ts +28 -0
  254. package/src/dispose/dispose-base.ts +9 -0
  255. package/src/dispose/index.ts +34 -0
  256. package/src/dispose/logger.test.ts +65 -0
  257. package/src/dispose/logger.ts +39 -0
  258. package/src/dispose/timer.test.ts +30 -0
  259. package/src/dispose/timer.ts +16 -0
  260. package/src/dispose/tracker.test.ts +51 -0
  261. package/src/dispose/tracker.ts +105 -0
  262. package/src/error/error-base.ts +45 -0
  263. package/src/error/error-code.ts +39 -0
  264. package/src/error/error-const.test.ts +30 -0
  265. package/src/error/error-const.ts +16 -0
  266. package/src/error/error-or.test.ts +44 -0
  267. package/src/error/error-or.ts +2 -0
  268. package/src/error/error-t.test.ts +116 -0
  269. package/src/error/error-t.ts +100 -0
  270. package/src/error/index.ts +24 -0
  271. package/src/error/node_modules/.vitest/results.json +1 -0
  272. package/src/event/disposable-linked-list.ts +29 -0
  273. package/src/event/emitter.test.ts +191 -0
  274. package/src/event/emitter.ts +162 -0
  275. package/src/event/error-handler.ts +22 -0
  276. package/src/event/index.ts +34 -0
  277. package/src/event/once.ts +29 -0
  278. package/src/event/phase-emitter.test.ts +212 -0
  279. package/src/event/phase-emitter.ts +209 -0
  280. package/src/event/shortcut-event-utils.ts +33 -0
  281. package/src/event/utils.ts +6 -0
  282. package/src/event/when.ts +40 -0
  283. package/src/function/debounce.test.ts +274 -0
  284. package/src/function/debounce.ts +168 -0
  285. package/src/function/index.ts +2 -0
  286. package/src/function/node_modules/.vitest/results.json +1 -0
  287. package/src/function/throttle.test.ts +179 -0
  288. package/src/function/throttle.ts +26 -0
  289. package/src/hash/hash-t.test.ts +100 -0
  290. package/src/hash/hash-t.ts +51 -0
  291. package/src/hash/index.ts +3 -0
  292. package/src/json/index.ts +1 -0
  293. package/src/json/node_modules/.vitest/results.json +1 -0
  294. package/src/json/parse.ts +19 -0
  295. package/src/launch/abstract-job.ts +45 -0
  296. package/src/launch/cost-recorder.ts +22 -0
  297. package/src/launch/index.ts +2 -0
  298. package/src/launch/job-scheduler.test.ts +122 -0
  299. package/src/launch/job-scheduler.ts +118 -0
  300. package/src/launch/node_modules/.vitest/deps/_metadata.json +8 -0
  301. package/src/launch/node_modules/.vitest/deps/package.json +3 -0
  302. package/src/launch/node_modules/.vitest/results.json +1 -0
  303. package/src/lock/README.md +11 -0
  304. package/src/lock/capability.test.ts +110 -0
  305. package/src/lock/capability.ts +89 -0
  306. package/src/lock/index.ts +15 -0
  307. package/src/lock/node_modules/.vitest/results.json +1 -0
  308. package/src/lock/semaphore.ts +21 -0
  309. package/src/lock/shared-mutex.test.ts +537 -0
  310. package/src/lock/shared-mutex.ts +242 -0
  311. package/src/lock/utils.test.ts +165 -0
  312. package/src/lock/utils.ts +135 -0
  313. package/src/lodash-es/index.ts +1 -0
  314. package/src/math/degree.ts +16 -0
  315. package/src/math/index.ts +7 -0
  316. package/src/math/math.test.ts +40 -0
  317. package/src/math/math.ts +64 -0
  318. package/src/math/node_modules/.vitest/results.json +1 -0
  319. package/src/math/vector.test.ts +73 -0
  320. package/src/math/vector.ts +114 -0
  321. package/src/network/client.interface.ts +104 -0
  322. package/src/network/client.web.ts +24 -0
  323. package/src/network/index.common.ts +10 -0
  324. package/src/network/index.ts +2 -0
  325. package/src/network/plugins/retry.ts +98 -0
  326. package/src/objects/deep-clone.test.ts +40 -0
  327. package/src/objects/deep-clone.ts +13 -0
  328. package/src/objects/deep-equal.test.ts +86 -0
  329. package/src/objects/deep-equal.ts +60 -0
  330. package/src/objects/index.ts +4 -0
  331. package/src/platform/index.ts +64 -0
  332. package/src/promise/index.ts +16 -0
  333. package/src/promise/promise.test.ts +254 -0
  334. package/src/promise/promise.ts +212 -0
  335. package/src/scheduler/callback-token.ts +31 -0
  336. package/src/scheduler/core/actuator-args.test.ts +47 -0
  337. package/src/scheduler/core/actuator.test.ts +82 -0
  338. package/src/scheduler/core/actuator.ts +58 -0
  339. package/src/scheduler/core/chunk-scheduler.test.ts +54 -0
  340. package/src/scheduler/core/chunk-scheduler.ts +28 -0
  341. package/src/scheduler/core/node_modules/.vitest/results.json +1 -0
  342. package/src/scheduler/core/scheduler.test.ts +328 -0
  343. package/src/scheduler/core/scheduler.ts +172 -0
  344. package/src/scheduler/core/task-queue.test.ts +78 -0
  345. package/src/scheduler/core/task-queue.ts +44 -0
  346. package/src/scheduler/core/task.test.ts +34 -0
  347. package/src/scheduler/core/task.ts +52 -0
  348. package/src/scheduler/core/utils.ts +48 -0
  349. package/src/scheduler/executor/abstract-executor.test.ts +44 -0
  350. package/src/scheduler/executor/abstract-executor.ts +38 -0
  351. package/src/scheduler/executor/executor.interface.ts +39 -0
  352. package/src/scheduler/executor/idle-callback-executor.test.ts +70 -0
  353. package/src/scheduler/executor/idle-callback-executor.ts +98 -0
  354. package/src/scheduler/executor/make-executor.ts +18 -0
  355. package/src/scheduler/executor/post-message-executor.test.ts +66 -0
  356. package/src/scheduler/executor/post-message-executor.ts +52 -0
  357. package/src/scheduler/index.ts +15 -0
  358. package/src/scheduler/lv-scheduler-callback.ts +19 -0
  359. package/src/scheduler/lv-scheduler-config.ts +17 -0
  360. package/src/scheduler/type.ts +48 -0
  361. package/src/sprintf/index.ts +2 -0
  362. package/src/sprintf/sprintf.test.ts +95 -0
  363. package/src/sprintf/sprintf.ts +97 -0
  364. package/src/structure/graph.test.ts +181 -0
  365. package/src/structure/graph.ts +105 -0
  366. package/src/structure/index.ts +8 -0
  367. package/src/structure/linked-list.test.ts +74 -0
  368. package/src/structure/linked-list.ts +145 -0
  369. package/src/structure/min-heap.test.ts +71 -0
  370. package/src/structure/min-heap.ts +91 -0
  371. package/src/type/REAME.md +2 -0
  372. package/src/type/distributive-omit.interface.ts +4 -0
  373. package/src/type/index.ts +3 -0
  374. package/src/type/object-key-paths.interface.ts +40 -0
  375. package/src/undo-redo-stack/README.md +61 -0
  376. package/src/undo-redo-stack/action-stack.test.ts +330 -0
  377. package/src/undo-redo-stack/action-stack.ts +150 -0
  378. package/src/undo-redo-stack/element.ts +4 -0
  379. package/src/undo-redo-stack/index.ts +7 -0
  380. package/src/undo-redo-stack/state-stack.test.ts +118 -0
  381. package/src/undo-redo-stack/state-stack.ts +133 -0
  382. package/src/uuid/index.ts +7 -0
  383. package/src/uuid/uuid.ts +86 -0
  384. package/src/worker/cors-worker.ts +38 -0
  385. package/src/worker/index.ts +4 -0
  386. package/src/worker/node_modules/.vitest/results.json +1 -0
  387. package/src/worker/promise-worker-main-thread.test.ts +91 -0
  388. package/src/worker/promise-worker-main-thread.ts +76 -0
  389. package/src/worker/promise-worker-worker-thread.ts +64 -0
  390. package/src/worker/promise-worker.interface.ts +15 -0
@@ -0,0 +1,738 @@
1
+ // src/_internal/logger.ts
2
+ var Logger = {
3
+ error(...data) {
4
+ if (typeof console.error === "function") {
5
+ console.error(...data);
6
+ }
7
+ },
8
+ info(...data) {
9
+ if (typeof console.info === "function") {
10
+ console.info(...data);
11
+ }
12
+ },
13
+ log(...data) {
14
+ if (typeof console.log === "function") {
15
+ console.log(...data);
16
+ }
17
+ },
18
+ time(label) {
19
+ if (typeof console.time === "function") {
20
+ console.time(label);
21
+ }
22
+ },
23
+ timeEnd(label) {
24
+ if (typeof console.timeEnd === "function") {
25
+ console.timeEnd(label);
26
+ }
27
+ },
28
+ timeLog(label, ...data) {
29
+ if (typeof console.timeLog === "function") {
30
+ console.timeLog(label, ...data);
31
+ }
32
+ },
33
+ timeStamp(label) {
34
+ if (typeof console.timeStamp === "function") {
35
+ console.timeStamp(label);
36
+ }
37
+ },
38
+ trace(...data) {
39
+ if (typeof console.trace === "function") {
40
+ console.trace(...data);
41
+ }
42
+ },
43
+ warn(...data) {
44
+ if (typeof console.warn === "function") {
45
+ console.warn(...data);
46
+ }
47
+ },
48
+ profile(label) {
49
+ if (typeof console.profile === "function") {
50
+ console.profile(label);
51
+ }
52
+ },
53
+ profileEnd(label) {
54
+ if (typeof console.profileEnd === "function") {
55
+ console.profileEnd(label);
56
+ }
57
+ }
58
+ };
59
+ function BRANCH_DISPOSE(from, to) {
60
+ }
61
+
62
+ // src/dispose/dispose-base.ts
63
+ var EmptyDispose = Object.freeze({ dispose() {
64
+ } });
65
+ function SET_PARENT_OF_DISPOSABLE(child, parent) {
66
+ }
67
+
68
+ // src/dispose/disposable-store.ts
69
+ var _DisposableStore = class _DisposableStore {
70
+ constructor() {
71
+ this._toDispose = /* @__PURE__ */ new Set();
72
+ this._isDisposed = false;
73
+ }
74
+ get isDisposed() {
75
+ return this._isDisposed;
76
+ }
77
+ dispose() {
78
+ if (this._isDisposed) {
79
+ Logger.warn(new Error("DisposableStore has disposed.").stack);
80
+ return;
81
+ }
82
+ this._isDisposed = true;
83
+ this.clear();
84
+ }
85
+ clear() {
86
+ if (this._toDispose.size === 0) {
87
+ return;
88
+ }
89
+ for (const disposable of this._toDispose) {
90
+ BRANCH_DISPOSE(this.constructor.name, disposable.constructor.name);
91
+ }
92
+ const errors = [];
93
+ for (const disposable of this._toDispose) {
94
+ try {
95
+ disposable.dispose();
96
+ } catch (e) {
97
+ errors.push(e);
98
+ }
99
+ }
100
+ this._toDispose.clear();
101
+ if (errors.length > 0) {
102
+ throw new AggregateError(errors, "find error when dispose store.");
103
+ }
104
+ }
105
+ add(o) {
106
+ if (!o) {
107
+ return o;
108
+ }
109
+ if (o === this) {
110
+ throw new Error("Cannot register a disposable on itself.");
111
+ }
112
+ if (this._isDisposed) {
113
+ if (!_DisposableStore.DISABLE_DISPOSED_WARNING) {
114
+ Logger.warn(
115
+ new Error(
116
+ "Trying to add a disposable to a DisposableStore that has already been disposed of. The added object will be leaked!"
117
+ ).stack
118
+ );
119
+ }
120
+ } else {
121
+ this._toDispose.add(o);
122
+ }
123
+ return o;
124
+ }
125
+ };
126
+ _DisposableStore.DISABLE_DISPOSED_WARNING = false;
127
+ var DisposableStore = _DisposableStore;
128
+
129
+ // src/dispose/disposable-t.ts
130
+ var Disposable = class {
131
+ constructor() {
132
+ this._store = new DisposableStore();
133
+ SET_PARENT_OF_DISPOSABLE(this._store);
134
+ }
135
+ // 销毁该节点和所有的子节点
136
+ dispose() {
137
+ BRANCH_DISPOSE(this.constructor.name, this._store.constructor.name);
138
+ this._store.dispose();
139
+ }
140
+ // 挂载子节点
141
+ _register(o) {
142
+ if (o === this) {
143
+ throw new Error("Cannot register a disposable on itself!");
144
+ }
145
+ return this._store.add(o);
146
+ }
147
+ };
148
+ var SafeDisposable = class {
149
+ constructor(value) {
150
+ this._value = value;
151
+ }
152
+ get value() {
153
+ return this._value;
154
+ }
155
+ isEmpty() {
156
+ return this._value === void 0;
157
+ }
158
+ dispose() {
159
+ if (!this._value) {
160
+ return;
161
+ }
162
+ this._value.dispose();
163
+ this._value = void 0;
164
+ }
165
+ };
166
+
167
+ // src/dispose/disposable-utils.ts
168
+ function makeSafeDisposable(fn) {
169
+ const disposable = new SafeDisposable({
170
+ dispose: fn
171
+ });
172
+ return disposable;
173
+ }
174
+
175
+ // src/structure/linked-list.ts
176
+ var ListNode = class {
177
+ constructor(value, next = null, prev = null) {
178
+ this.value = value;
179
+ this.next = next;
180
+ this.prev = prev;
181
+ }
182
+ };
183
+ var LinkedList = class {
184
+ constructor() {
185
+ this._head = null;
186
+ this._tail = null;
187
+ this._count = 0;
188
+ }
189
+ get size() {
190
+ return this._count;
191
+ }
192
+ get firstNode() {
193
+ return this._head;
194
+ }
195
+ isEmpty() {
196
+ return this._head === null;
197
+ }
198
+ clear() {
199
+ let current = this._head;
200
+ while (current !== null) {
201
+ const next = current.next;
202
+ current.prev = null;
203
+ current.next = null;
204
+ current = next;
205
+ }
206
+ this._head = null;
207
+ this._tail = null;
208
+ this._count = 0;
209
+ }
210
+ unshift(value) {
211
+ const node = new ListNode(value);
212
+ if (this.isEmpty()) {
213
+ this._head = node;
214
+ this._tail = node;
215
+ } else {
216
+ const oldHead = this._head;
217
+ this._head = node;
218
+ node.next = oldHead;
219
+ oldHead.prev = node;
220
+ }
221
+ this._count++;
222
+ return this;
223
+ }
224
+ push(value) {
225
+ const node = new ListNode(value);
226
+ if (this.isEmpty()) {
227
+ this._head = node;
228
+ this._tail = node;
229
+ } else {
230
+ const oldTail = this._tail;
231
+ this._tail = node;
232
+ node.prev = oldTail;
233
+ oldTail.next = node;
234
+ }
235
+ this._count++;
236
+ return this;
237
+ }
238
+ shift() {
239
+ if (this.isEmpty()) {
240
+ return null;
241
+ }
242
+ const node = this._head;
243
+ const value = node.value;
244
+ this._remove(node);
245
+ return value;
246
+ }
247
+ pop() {
248
+ if (this.isEmpty()) {
249
+ return null;
250
+ }
251
+ const node = this._tail;
252
+ const value = node.value;
253
+ this._remove(node);
254
+ return value;
255
+ }
256
+ toArray() {
257
+ const result = [];
258
+ for (const value of this) {
259
+ result.push(value);
260
+ }
261
+ return result;
262
+ }
263
+ *[Symbol.iterator]() {
264
+ let current = this._head;
265
+ while (current !== null) {
266
+ yield current.value;
267
+ current = current.next;
268
+ }
269
+ }
270
+ _remove(node) {
271
+ if (node.prev === null && node.next === null && node !== this._head && node !== this._tail) {
272
+ return;
273
+ }
274
+ if (node === this._head) {
275
+ this._head = node.next;
276
+ if (this._head) {
277
+ this._head.prev = null;
278
+ }
279
+ }
280
+ if (node === this._tail) {
281
+ this._tail = node.prev;
282
+ if (this._tail) {
283
+ this._tail.next = null;
284
+ }
285
+ }
286
+ if (node.prev) {
287
+ node.prev.next = node.next;
288
+ }
289
+ if (node.next) {
290
+ node.next.prev = node.prev;
291
+ }
292
+ node.prev = null;
293
+ node.next = null;
294
+ this._count--;
295
+ }
296
+ };
297
+
298
+ // src/event/disposable-linked-list.ts
299
+ var DisposableLinkedList = class extends LinkedList {
300
+ unshiftAndGetDisposableNode(value) {
301
+ this.unshift(value);
302
+ const node = this._head;
303
+ let hasRemoved = false;
304
+ return () => {
305
+ if (!hasRemoved) {
306
+ hasRemoved = true;
307
+ super._remove(node);
308
+ }
309
+ };
310
+ }
311
+ pushAndGetDisposableNode(value) {
312
+ this.push(value);
313
+ const node = this._tail;
314
+ let hasRemoved = false;
315
+ return () => {
316
+ if (!hasRemoved) {
317
+ hasRemoved = true;
318
+ super._remove(node);
319
+ }
320
+ };
321
+ }
322
+ };
323
+
324
+ // src/event/error-handler.ts
325
+ function asyncUnexpectedError(e) {
326
+ setTimeout(() => {
327
+ throw e;
328
+ }, 0);
329
+ }
330
+
331
+ // src/event/emitter.ts
332
+ var Listener = class {
333
+ constructor(callback, callbackThis) {
334
+ this._callback = callback;
335
+ this._callbackThis = callbackThis;
336
+ }
337
+ invoke(...args) {
338
+ this._callback.call(this._callbackThis, ...args);
339
+ }
340
+ };
341
+ var EventDeliveryQueueElement = class {
342
+ constructor(emitter, listener, event) {
343
+ this.emitter = emitter;
344
+ this.listener = listener;
345
+ this.event = event;
346
+ }
347
+ };
348
+ var EventDeliveryQueue = class {
349
+ constructor(_onListenerError = asyncUnexpectedError) {
350
+ this._onListenerError = _onListenerError;
351
+ this._queue = new DisposableLinkedList();
352
+ }
353
+ get size() {
354
+ return this._queue.size;
355
+ }
356
+ push(emitter, listener, event) {
357
+ this._queue.push(new EventDeliveryQueueElement(emitter, listener, event));
358
+ }
359
+ clear(emitter) {
360
+ const newQueue = new DisposableLinkedList();
361
+ for (const element of this._queue) {
362
+ if (element.emitter !== emitter) {
363
+ newQueue.push(element);
364
+ }
365
+ }
366
+ this._queue = newQueue;
367
+ }
368
+ deliver() {
369
+ while (this._queue.size > 0) {
370
+ const element = this._queue.shift();
371
+ try {
372
+ element.listener.invoke(...element.event);
373
+ } catch (e) {
374
+ this._onListenerError(e);
375
+ }
376
+ }
377
+ }
378
+ };
379
+ var Emitter = class {
380
+ constructor(options) {
381
+ this._disposed = false;
382
+ this._options = options;
383
+ }
384
+ get event() {
385
+ if (this._event) {
386
+ return this._event;
387
+ }
388
+ this._event = (callback, thisArgs) => {
389
+ const listener = new Listener(callback, thisArgs);
390
+ if (!this._listeners) {
391
+ this._listeners = new DisposableLinkedList();
392
+ }
393
+ const removeListener = this._listeners.pushAndGetDisposableNode(listener);
394
+ if (this._options?.onAddListener) {
395
+ this._options.onAddListener(this, callback, thisArgs);
396
+ }
397
+ const result = () => {
398
+ if (!this._disposed) {
399
+ removeListener();
400
+ if (this._options?.onRemoveListener) {
401
+ this._options.onRemoveListener(this, callback, thisArgs);
402
+ }
403
+ }
404
+ };
405
+ return makeSafeDisposable(result);
406
+ };
407
+ return this._event;
408
+ }
409
+ dispose() {
410
+ if (this._disposed) {
411
+ return;
412
+ }
413
+ this._disposed = true;
414
+ this._listeners?.clear();
415
+ this._deliveryQueue?.clear(this);
416
+ }
417
+ fire(...event) {
418
+ if (!this._listeners || this._listeners.size === 0) {
419
+ return;
420
+ }
421
+ if (this._listeners.size === 1) {
422
+ const listener = this._listeners.firstNode;
423
+ try {
424
+ listener.value.invoke(...event);
425
+ } catch (e) {
426
+ if (this._options?.onListenerError) {
427
+ this._options.onListenerError(e);
428
+ } else {
429
+ asyncUnexpectedError(e);
430
+ }
431
+ }
432
+ return;
433
+ }
434
+ this._deliveryQueue ?? (this._deliveryQueue = new EventDeliveryQueue(this._options?.onListenerError));
435
+ for (const listener of this._listeners) {
436
+ this._deliveryQueue.push(this, listener, event);
437
+ }
438
+ this._deliveryQueue.deliver();
439
+ }
440
+ };
441
+
442
+ // src/async/cancellation.ts
443
+ var shortcutEvent = Object.freeze(function(callback, context) {
444
+ const handle = setTimeout(callback.bind(context), 0);
445
+ return {
446
+ dispose() {
447
+ clearTimeout(handle);
448
+ }
449
+ };
450
+ });
451
+ var MutableToken = class {
452
+ constructor() {
453
+ // 是否已经取消该异步调用
454
+ this._isCancelled = false;
455
+ this._emitter = null;
456
+ }
457
+ get reason() {
458
+ return this._reason;
459
+ }
460
+ // 获取当前是否已经取消该异步调用
461
+ get isCancellationRequested() {
462
+ return this._isCancelled;
463
+ }
464
+ // 外界可以监听异步取消发起
465
+ get onCancellationRequested() {
466
+ if (this._isCancelled) {
467
+ return shortcutEvent;
468
+ }
469
+ if (!this._emitter) {
470
+ this._emitter = new Emitter();
471
+ }
472
+ return this._emitter.event;
473
+ }
474
+ cancel(reason) {
475
+ if (!this._isCancelled) {
476
+ this._reason = reason;
477
+ this._isCancelled = true;
478
+ if (this._emitter) {
479
+ this._emitter.fire();
480
+ this.dispose();
481
+ }
482
+ }
483
+ }
484
+ dispose() {
485
+ if (this._emitter) {
486
+ this._emitter.dispose();
487
+ this._emitter = null;
488
+ }
489
+ }
490
+ };
491
+ var CancellationToken = class {
492
+ };
493
+ CancellationToken.None = Object.freeze({
494
+ isCancellationRequested: false,
495
+ onCancellationRequested: () => EmptyDispose
496
+ });
497
+ CancellationToken.Cancelled = Object.freeze({
498
+ isCancellationRequested: true,
499
+ onCancellationRequested: shortcutEvent
500
+ });
501
+ CancellationToken.Make = (reason) => {
502
+ return Object.freeze({
503
+ isCancellationRequested: true,
504
+ onCancellationRequested: shortcutEvent,
505
+ reason
506
+ });
507
+ };
508
+ var CancellationTokenSource = class {
509
+ constructor(parent) {
510
+ // 真正的token
511
+ this._token = void 0;
512
+ // 可能存在父级CancellationTokenSource
513
+ this._parentListener = void 0;
514
+ // 为了支持signal场景,所以在需要时会初始化浏览器提供的abortController原生结构
515
+ this._abortController = void 0;
516
+ this._parentListener = parent?.onCancellationRequested(this.cancel, this);
517
+ }
518
+ /**
519
+ * 传统的cancellation用法
520
+ */
521
+ get token() {
522
+ if (!this._token) {
523
+ this._token = new MutableToken();
524
+ }
525
+ return this._token;
526
+ }
527
+ /**
528
+ * 对齐浏览器提供的abortSignal,支持给fetch、axios等传参使用
529
+ */
530
+ get signal() {
531
+ if (this._abortController) {
532
+ return this._abortController.signal;
533
+ }
534
+ this._abortController = new AbortController();
535
+ if (this._token?.isCancellationRequested) {
536
+ this._abortController.abort();
537
+ }
538
+ return this._abortController.signal;
539
+ }
540
+ cancel(reason) {
541
+ if (!this._token) {
542
+ this._token = reason === void 0 ? CancellationToken.Cancelled : CancellationToken.Make(reason);
543
+ } else if (this._token instanceof MutableToken) {
544
+ this._token.cancel(reason);
545
+ }
546
+ if (this._abortController) {
547
+ this._abortController.abort(reason);
548
+ }
549
+ }
550
+ dispose(cancel = false) {
551
+ if (cancel) {
552
+ this.cancel();
553
+ }
554
+ this._parentListener?.dispose();
555
+ if (!this._token) {
556
+ this._token = CancellationToken.None;
557
+ } else if (this._token instanceof MutableToken) {
558
+ this._token.dispose();
559
+ }
560
+ }
561
+ };
562
+
563
+ // src/async/wait.ts
564
+ function wait(ms) {
565
+ return new Promise((resolve) => setTimeout(resolve, ms));
566
+ }
567
+ var sleep = wait;
568
+
569
+ // src/async/barrier.ts
570
+ var Barrier = class {
571
+ constructor() {
572
+ this._isOpen = false;
573
+ this._promise = new Promise((c, e) => {
574
+ this._completePromise = c;
575
+ this._rejectPromise = e;
576
+ });
577
+ }
578
+ isOpen() {
579
+ return this._isOpen;
580
+ }
581
+ open() {
582
+ this._isOpen = true;
583
+ this._completePromise(true);
584
+ }
585
+ reject(e) {
586
+ this._rejectPromise(e);
587
+ }
588
+ wait() {
589
+ return this._promise;
590
+ }
591
+ };
592
+ function makeBarrierByPromise(promise, openWhenReject = false) {
593
+ const barrier = new Barrier();
594
+ promise.then(() => barrier.open()).catch((err) => {
595
+ if (openWhenReject) {
596
+ barrier.open();
597
+ throw err;
598
+ } else {
599
+ barrier.reject(err);
600
+ }
601
+ });
602
+ return barrier;
603
+ }
604
+
605
+ // src/error/error-t.ts
606
+ var lvErrorRefSymbol = /* @__PURE__ */ Symbol("lvErrorRef");
607
+ function findJsError(error) {
608
+ let obj = error;
609
+ while (obj) {
610
+ if (obj instanceof Error) {
611
+ return obj;
612
+ }
613
+ obj = obj.cause;
614
+ }
615
+ return new Error(error.toString());
616
+ }
617
+ function printCause(cause) {
618
+ if (cause === void 0) {
619
+ return "";
620
+ } else if (cause instanceof Error) {
621
+ return `
622
+ caused by [jsError]${cause.name}-${cause.message}`;
623
+ } else {
624
+ return `
625
+ caused by [${cause.code}]${cause.msg}${cause.ok ? "" : printCause(cause.cause)}`;
626
+ }
627
+ }
628
+ function internalMakeError(code, msg, cause, errorInfo) {
629
+ const errorRef = {
630
+ ok: false,
631
+ code,
632
+ msg,
633
+ cause,
634
+ errorInfo,
635
+ toString() {
636
+ return `[${code}]${msg}.${cause ? printCause(cause) : ""}`;
637
+ },
638
+ pair() {
639
+ return [errorRef, null];
640
+ },
641
+ stack: cause instanceof Error ? cause.stack : void 0,
642
+ findJsError: () => findJsError(errorRef),
643
+ ...{ [lvErrorRefSymbol]: true }
644
+ // 跳过类型检测
645
+ };
646
+ return errorRef;
647
+ }
648
+ function makeErrorBy(code, msg, cause, errorInfo) {
649
+ return internalMakeError(code, msg, cause, errorInfo);
650
+ }
651
+
652
+ // src/async/queue/task.ts
653
+ var AsyncTask = class extends Disposable {
654
+ constructor(_callback, _cancellationToken) {
655
+ super();
656
+ this._callback = _callback;
657
+ this._cancellationToken = _cancellationToken;
658
+ this._onSuccess = this._store.add(new Emitter());
659
+ this.onSuccess = this._onSuccess.event;
660
+ this._onFailure = this._store.add(new Emitter());
661
+ this.onFailure = this._onFailure.event;
662
+ this._onCancel = this._store.add(new Emitter());
663
+ this.onCancel = this._onCancel.event;
664
+ this._isExec = false;
665
+ this._isCancel = false;
666
+ this._cancellationToken?.onCancellationRequested(() => {
667
+ this.cancel();
668
+ });
669
+ }
670
+ /** 这个方法不对外暴露,只提供给 queue 使用. */
671
+ async safeExec() {
672
+ if (this._isCancel || this._isExec) {
673
+ return;
674
+ }
675
+ try {
676
+ this._isExec = true;
677
+ await this._callback(this._cancellationToken ?? CancellationToken.None);
678
+ this._onSuccess.fire();
679
+ } catch (err) {
680
+ this._onFailure.fire(makeErrorBy(-1, "exec error", err));
681
+ }
682
+ }
683
+ cancel() {
684
+ if (this._isCancel) {
685
+ return;
686
+ }
687
+ if (this._isExec) {
688
+ return;
689
+ }
690
+ this._isCancel = true;
691
+ this._callback = null;
692
+ this._onCancel.fire();
693
+ }
694
+ };
695
+
696
+ // src/async/queue/queue.ts
697
+ var AsyncQueue = class extends Disposable {
698
+ constructor(options) {
699
+ super();
700
+ this._queue = [];
701
+ this._maxConcurrent = 1;
702
+ this._execCounter = 0;
703
+ this._maxConcurrent = options.concurrent;
704
+ }
705
+ /** 添加一个异步任务到队列 */
706
+ addTask(callback, cancellationToken) {
707
+ if (cancellationToken?.isCancellationRequested) {
708
+ return new AsyncTask(null);
709
+ }
710
+ const task = new AsyncTask(callback);
711
+ this._queue.push(this._store.add(task));
712
+ this._next();
713
+ return task;
714
+ }
715
+ // 执行下一个任务,如果当前并发数小于最大并发数,并且队列不为空,则从队列中取出一个任务并执行,否则什么都不做
716
+ _next() {
717
+ if (this._queue.length && this._execCounter < this._maxConcurrent && this._queue.length > 0) {
718
+ const task = this._queue.shift();
719
+ this._execCounter++;
720
+ task.safeExec().finally(() => {
721
+ this._execCounter--;
722
+ this._next();
723
+ });
724
+ }
725
+ }
726
+ };
727
+
728
+ // src/async/utils.ts
729
+ function invokeNextLoop(fn) {
730
+ const handle = setTimeout(() => {
731
+ fn();
732
+ }, 0);
733
+ return makeSafeDisposable(() => clearTimeout(handle));
734
+ }
735
+
736
+ export { AsyncQueue, Barrier, CancellationTokenSource, invokeNextLoop, makeBarrierByPromise, sleep, wait };
737
+ //# sourceMappingURL=index.js.map
738
+ //# sourceMappingURL=index.js.map