@tianshu-ai/tianshu 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (917) hide show
  1. package/LICENSE +200 -0
  2. package/README.md +284 -0
  3. package/README.zh-CN.md +136 -0
  4. package/bin/tianshu.mjs +32 -0
  5. package/package.json +60 -0
  6. package/packages/plugin-sdk/dist/agent-loop.d.ts +96 -0
  7. package/packages/plugin-sdk/dist/agent-loop.d.ts.map +1 -0
  8. package/packages/plugin-sdk/dist/agent-loop.js +11 -0
  9. package/packages/plugin-sdk/dist/agent-loop.js.map +1 -0
  10. package/packages/plugin-sdk/dist/capabilities.d.ts +48 -0
  11. package/packages/plugin-sdk/dist/capabilities.d.ts.map +1 -0
  12. package/packages/plugin-sdk/dist/capabilities.js +61 -0
  13. package/packages/plugin-sdk/dist/capabilities.js.map +1 -0
  14. package/packages/plugin-sdk/dist/catalog.d.ts +60 -0
  15. package/packages/plugin-sdk/dist/catalog.d.ts.map +1 -0
  16. package/packages/plugin-sdk/dist/catalog.js +11 -0
  17. package/packages/plugin-sdk/dist/catalog.js.map +1 -0
  18. package/packages/plugin-sdk/dist/client.d.ts +171 -0
  19. package/packages/plugin-sdk/dist/client.d.ts.map +1 -0
  20. package/packages/plugin-sdk/dist/client.js +96 -0
  21. package/packages/plugin-sdk/dist/client.js.map +1 -0
  22. package/packages/plugin-sdk/dist/index.d.ts +9 -0
  23. package/packages/plugin-sdk/dist/index.d.ts.map +1 -0
  24. package/packages/plugin-sdk/dist/index.js +19 -0
  25. package/packages/plugin-sdk/dist/index.js.map +1 -0
  26. package/packages/plugin-sdk/dist/lsp.d.ts +32 -0
  27. package/packages/plugin-sdk/dist/lsp.d.ts.map +1 -0
  28. package/packages/plugin-sdk/dist/lsp.js +19 -0
  29. package/packages/plugin-sdk/dist/lsp.js.map +1 -0
  30. package/packages/plugin-sdk/dist/manifest.d.ts +423 -0
  31. package/packages/plugin-sdk/dist/manifest.d.ts.map +1 -0
  32. package/packages/plugin-sdk/dist/manifest.js +7 -0
  33. package/packages/plugin-sdk/dist/manifest.js.map +1 -0
  34. package/packages/plugin-sdk/dist/mcp-client.d.ts +74 -0
  35. package/packages/plugin-sdk/dist/mcp-client.d.ts.map +1 -0
  36. package/packages/plugin-sdk/dist/mcp-client.js +226 -0
  37. package/packages/plugin-sdk/dist/mcp-client.js.map +1 -0
  38. package/packages/plugin-sdk/dist/mcp-fetch.d.ts +10 -0
  39. package/packages/plugin-sdk/dist/mcp-fetch.d.ts.map +1 -0
  40. package/packages/plugin-sdk/dist/mcp-fetch.js +130 -0
  41. package/packages/plugin-sdk/dist/mcp-fetch.js.map +1 -0
  42. package/packages/plugin-sdk/dist/mcp-toolset.d.ts +128 -0
  43. package/packages/plugin-sdk/dist/mcp-toolset.d.ts.map +1 -0
  44. package/packages/plugin-sdk/dist/mcp-toolset.js +246 -0
  45. package/packages/plugin-sdk/dist/mcp-toolset.js.map +1 -0
  46. package/packages/plugin-sdk/dist/server.d.ts +486 -0
  47. package/packages/plugin-sdk/dist/server.d.ts.map +1 -0
  48. package/packages/plugin-sdk/dist/server.js +10 -0
  49. package/packages/plugin-sdk/dist/server.js.map +1 -0
  50. package/packages/plugin-sdk/dist/session-inbox.d.ts +56 -0
  51. package/packages/plugin-sdk/dist/session-inbox.d.ts.map +1 -0
  52. package/packages/plugin-sdk/dist/session-inbox.js +12 -0
  53. package/packages/plugin-sdk/dist/session-inbox.js.map +1 -0
  54. package/packages/plugin-sdk/package.json +36 -0
  55. package/packages/server/builtinConfig/plugins/README.md +1 -0
  56. package/packages/server/builtinConfig/plugins/files/manifest.json +100 -0
  57. package/packages/server/builtinConfig/plugins/files/skills/files-workspace-layout.md +29 -0
  58. package/packages/server/builtinConfig/plugins/microsandbox/manifest.json +177 -0
  59. package/packages/server/builtinConfig/plugins/microsandbox/skills/microsandbox-browser-howto.md +155 -0
  60. package/packages/server/builtinConfig/plugins/microsandbox/skills/microsandbox-build-use.md +201 -0
  61. package/packages/server/builtinConfig/plugins/microsandbox/skills/microsandbox-config.md +38 -0
  62. package/packages/server/builtinConfig/plugins/microsandbox/skills/microsandbox-exec-howto.md +144 -0
  63. package/packages/server/builtinConfig/plugins/microsandbox/skills/microsandbox-libreoffice.md +159 -0
  64. package/packages/server/builtinConfig/plugins/microsandbox/skills/microsandbox-main-orchestration.md +75 -0
  65. package/packages/server/builtinConfig/plugins/microsandbox/templates/README.md +26 -0
  66. package/packages/server/builtinConfig/plugins/microsandbox/templates/browser.yaml +105 -0
  67. package/packages/server/builtinConfig/plugins/microsandbox/templates/task-runner-with-browser.yaml +80 -0
  68. package/packages/server/builtinConfig/plugins/microsandbox/templates/task-runner.yaml +80 -0
  69. package/packages/server/builtinConfig/plugins/web-search/manifest.json +65 -0
  70. package/packages/server/builtinConfig/plugins/web-search/skills/web-search-howto.md +69 -0
  71. package/packages/server/builtinConfig/plugins/workboard/agent-seeds/echo-demo/agent.json +7 -0
  72. package/packages/server/builtinConfig/plugins/workboard/agent-seeds/llm-default/SOUL.md +53 -0
  73. package/packages/server/builtinConfig/plugins/workboard/agent-seeds/llm-default/agent.json +7 -0
  74. package/packages/server/builtinConfig/plugins/workboard/manifest.json +180 -0
  75. package/packages/server/builtinConfig/plugins/workboard/skills/large-input-large-output.md +185 -0
  76. package/packages/server/builtinConfig/plugins/workboard/skills/workboard-howto.md +166 -0
  77. package/packages/server/builtinConfig/plugins/workboard/skills/worker-creator.md +267 -0
  78. package/packages/server/builtinConfig/plugins/workboard/skills/worker-fleet.md +431 -0
  79. package/packages/server/dist/catalog.d.ts +52 -0
  80. package/packages/server/dist/catalog.d.ts.map +1 -0
  81. package/packages/server/dist/catalog.js +189 -0
  82. package/packages/server/dist/catalog.js.map +1 -0
  83. package/packages/server/dist/chat/active-harnesses.d.ts +34 -0
  84. package/packages/server/dist/chat/active-harnesses.d.ts.map +1 -0
  85. package/packages/server/dist/chat/active-harnesses.js +118 -0
  86. package/packages/server/dist/chat/active-harnesses.js.map +1 -0
  87. package/packages/server/dist/chat/agent-loop.d.ts +64 -0
  88. package/packages/server/dist/chat/agent-loop.d.ts.map +1 -0
  89. package/packages/server/dist/chat/agent-loop.js +597 -0
  90. package/packages/server/dist/chat/agent-loop.js.map +1 -0
  91. package/packages/server/dist/chat/agent-tool-adapter.d.ts +33 -0
  92. package/packages/server/dist/chat/agent-tool-adapter.d.ts.map +1 -0
  93. package/packages/server/dist/chat/agent-tool-adapter.js +260 -0
  94. package/packages/server/dist/chat/agent-tool-adapter.js.map +1 -0
  95. package/packages/server/dist/chat/compact.d.ts +52 -0
  96. package/packages/server/dist/chat/compact.d.ts.map +1 -0
  97. package/packages/server/dist/chat/compact.js +248 -0
  98. package/packages/server/dist/chat/compact.js.map +1 -0
  99. package/packages/server/dist/chat/dump-system-prompt.d.ts +17 -0
  100. package/packages/server/dist/chat/dump-system-prompt.d.ts.map +1 -0
  101. package/packages/server/dist/chat/dump-system-prompt.js +58 -0
  102. package/packages/server/dist/chat/dump-system-prompt.js.map +1 -0
  103. package/packages/server/dist/chat/handler.d.ts +186 -0
  104. package/packages/server/dist/chat/handler.d.ts.map +1 -0
  105. package/packages/server/dist/chat/handler.js +1248 -0
  106. package/packages/server/dist/chat/handler.js.map +1 -0
  107. package/packages/server/dist/chat/image-fit.d.ts +34 -0
  108. package/packages/server/dist/chat/image-fit.d.ts.map +1 -0
  109. package/packages/server/dist/chat/image-fit.js +157 -0
  110. package/packages/server/dist/chat/image-fit.js.map +1 -0
  111. package/packages/server/dist/chat/messages.d.ts +118 -0
  112. package/packages/server/dist/chat/messages.d.ts.map +1 -0
  113. package/packages/server/dist/chat/messages.js +341 -0
  114. package/packages/server/dist/chat/messages.js.map +1 -0
  115. package/packages/server/dist/chat/session-inbox.d.ts +114 -0
  116. package/packages/server/dist/chat/session-inbox.d.ts.map +1 -0
  117. package/packages/server/dist/chat/session-inbox.js +418 -0
  118. package/packages/server/dist/chat/session-inbox.js.map +1 -0
  119. package/packages/server/dist/chat/sqlite-session-repo.d.ts +26 -0
  120. package/packages/server/dist/chat/sqlite-session-repo.d.ts.map +1 -0
  121. package/packages/server/dist/chat/sqlite-session-repo.js +132 -0
  122. package/packages/server/dist/chat/sqlite-session-repo.js.map +1 -0
  123. package/packages/server/dist/chat/sqlite-session-storage.d.ts +83 -0
  124. package/packages/server/dist/chat/sqlite-session-storage.d.ts.map +1 -0
  125. package/packages/server/dist/chat/sqlite-session-storage.js +418 -0
  126. package/packages/server/dist/chat/sqlite-session-storage.js.map +1 -0
  127. package/packages/server/dist/chat/stub-execution-env.d.ts +3 -0
  128. package/packages/server/dist/chat/stub-execution-env.d.ts.map +1 -0
  129. package/packages/server/dist/chat/stub-execution-env.js +87 -0
  130. package/packages/server/dist/chat/stub-execution-env.js.map +1 -0
  131. package/packages/server/dist/chat/token-estimate.d.ts +11 -0
  132. package/packages/server/dist/chat/token-estimate.d.ts.map +1 -0
  133. package/packages/server/dist/chat/token-estimate.js +67 -0
  134. package/packages/server/dist/chat/token-estimate.js.map +1 -0
  135. package/packages/server/dist/chat/ws-protocol.d.ts +244 -0
  136. package/packages/server/dist/chat/ws-protocol.d.ts.map +1 -0
  137. package/packages/server/dist/chat/ws-protocol.js +193 -0
  138. package/packages/server/dist/chat/ws-protocol.js.map +1 -0
  139. package/packages/server/dist/cli.d.ts +9 -0
  140. package/packages/server/dist/cli.d.ts.map +1 -0
  141. package/packages/server/dist/cli.js +329 -0
  142. package/packages/server/dist/cli.js.map +1 -0
  143. package/packages/server/dist/core/agent-seeds.d.ts +25 -0
  144. package/packages/server/dist/core/agent-seeds.d.ts.map +1 -0
  145. package/packages/server/dist/core/agent-seeds.js +69 -0
  146. package/packages/server/dist/core/agent-seeds.js.map +1 -0
  147. package/packages/server/dist/core/config.d.ts +172 -0
  148. package/packages/server/dist/core/config.d.ts.map +1 -0
  149. package/packages/server/dist/core/config.js +155 -0
  150. package/packages/server/dist/core/config.js.map +1 -0
  151. package/packages/server/dist/core/db-pool.d.ts +32 -0
  152. package/packages/server/dist/core/db-pool.d.ts.map +1 -0
  153. package/packages/server/dist/core/db-pool.js +108 -0
  154. package/packages/server/dist/core/db-pool.js.map +1 -0
  155. package/packages/server/dist/core/dev-mode.d.ts +13 -0
  156. package/packages/server/dist/core/dev-mode.d.ts.map +1 -0
  157. package/packages/server/dist/core/dev-mode.js +51 -0
  158. package/packages/server/dist/core/dev-mode.js.map +1 -0
  159. package/packages/server/dist/core/global-ops.d.ts +54 -0
  160. package/packages/server/dist/core/global-ops.d.ts.map +1 -0
  161. package/packages/server/dist/core/global-ops.js +143 -0
  162. package/packages/server/dist/core/global-ops.js.map +1 -0
  163. package/packages/server/dist/core/identity-resolvers.d.ts +102 -0
  164. package/packages/server/dist/core/identity-resolvers.d.ts.map +1 -0
  165. package/packages/server/dist/core/identity-resolvers.js +176 -0
  166. package/packages/server/dist/core/identity-resolvers.js.map +1 -0
  167. package/packages/server/dist/core/index.d.ts +13 -0
  168. package/packages/server/dist/core/index.d.ts.map +1 -0
  169. package/packages/server/dist/core/index.js +18 -0
  170. package/packages/server/dist/core/index.js.map +1 -0
  171. package/packages/server/dist/core/llm.d.ts +45 -0
  172. package/packages/server/dist/core/llm.d.ts.map +1 -0
  173. package/packages/server/dist/core/llm.js +140 -0
  174. package/packages/server/dist/core/llm.js.map +1 -0
  175. package/packages/server/dist/core/mcp-manager.d.ts +47 -0
  176. package/packages/server/dist/core/mcp-manager.d.ts.map +1 -0
  177. package/packages/server/dist/core/mcp-manager.js +129 -0
  178. package/packages/server/dist/core/mcp-manager.js.map +1 -0
  179. package/packages/server/dist/core/middleware.d.ts +31 -0
  180. package/packages/server/dist/core/middleware.d.ts.map +1 -0
  181. package/packages/server/dist/core/middleware.js +102 -0
  182. package/packages/server/dist/core/middleware.js.map +1 -0
  183. package/packages/server/dist/core/migrations/001-initial.d.ts +4 -0
  184. package/packages/server/dist/core/migrations/001-initial.d.ts.map +1 -0
  185. package/packages/server/dist/core/migrations/001-initial.js +66 -0
  186. package/packages/server/dist/core/migrations/001-initial.js.map +1 -0
  187. package/packages/server/dist/core/migrations/002-task-dependencies.d.ts +4 -0
  188. package/packages/server/dist/core/migrations/002-task-dependencies.d.ts.map +1 -0
  189. package/packages/server/dist/core/migrations/002-task-dependencies.js +20 -0
  190. package/packages/server/dist/core/migrations/002-task-dependencies.js.map +1 -0
  191. package/packages/server/dist/core/migrations/003-session-tree.d.ts +4 -0
  192. package/packages/server/dist/core/migrations/003-session-tree.d.ts.map +1 -0
  193. package/packages/server/dist/core/migrations/003-session-tree.js +96 -0
  194. package/packages/server/dist/core/migrations/003-session-tree.js.map +1 -0
  195. package/packages/server/dist/core/migrations/003-worker-agents.d.ts +4 -0
  196. package/packages/server/dist/core/migrations/003-worker-agents.d.ts.map +1 -0
  197. package/packages/server/dist/core/migrations/003-worker-agents.js +65 -0
  198. package/packages/server/dist/core/migrations/003-worker-agents.js.map +1 -0
  199. package/packages/server/dist/core/migrations/004-rebuild-message-chain.d.ts +4 -0
  200. package/packages/server/dist/core/migrations/004-rebuild-message-chain.d.ts.map +1 -0
  201. package/packages/server/dist/core/migrations/004-rebuild-message-chain.js +52 -0
  202. package/packages/server/dist/core/migrations/004-rebuild-message-chain.js.map +1 -0
  203. package/packages/server/dist/core/migrations/005-task-status-rename.d.ts +4 -0
  204. package/packages/server/dist/core/migrations/005-task-status-rename.d.ts.map +1 -0
  205. package/packages/server/dist/core/migrations/005-task-status-rename.js +64 -0
  206. package/packages/server/dist/core/migrations/005-task-status-rename.js.map +1 -0
  207. package/packages/server/dist/core/migrations/006-task-labels.d.ts +4 -0
  208. package/packages/server/dist/core/migrations/006-task-labels.d.ts.map +1 -0
  209. package/packages/server/dist/core/migrations/006-task-labels.js +43 -0
  210. package/packages/server/dist/core/migrations/006-task-labels.js.map +1 -0
  211. package/packages/server/dist/core/migrations/007-session-inbox.d.ts +4 -0
  212. package/packages/server/dist/core/migrations/007-session-inbox.d.ts.map +1 -0
  213. package/packages/server/dist/core/migrations/007-session-inbox.js +67 -0
  214. package/packages/server/dist/core/migrations/007-session-inbox.js.map +1 -0
  215. package/packages/server/dist/core/migrations/008-task-intervention.d.ts +4 -0
  216. package/packages/server/dist/core/migrations/008-task-intervention.d.ts.map +1 -0
  217. package/packages/server/dist/core/migrations/008-task-intervention.js +60 -0
  218. package/packages/server/dist/core/migrations/008-task-intervention.js.map +1 -0
  219. package/packages/server/dist/core/migrations/index.d.ts +12 -0
  220. package/packages/server/dist/core/migrations/index.d.ts.map +1 -0
  221. package/packages/server/dist/core/migrations/index.js +58 -0
  222. package/packages/server/dist/core/migrations/index.js.map +1 -0
  223. package/packages/server/dist/core/paths.d.ts +53 -0
  224. package/packages/server/dist/core/paths.d.ts.map +1 -0
  225. package/packages/server/dist/core/paths.js +125 -0
  226. package/packages/server/dist/core/paths.js.map +1 -0
  227. package/packages/server/dist/core/plugins/builtin-loader.d.ts +56 -0
  228. package/packages/server/dist/core/plugins/builtin-loader.d.ts.map +1 -0
  229. package/packages/server/dist/core/plugins/builtin-loader.js +153 -0
  230. package/packages/server/dist/core/plugins/builtin-loader.js.map +1 -0
  231. package/packages/server/dist/core/plugins/discovery.d.ts +28 -0
  232. package/packages/server/dist/core/plugins/discovery.d.ts.map +1 -0
  233. package/packages/server/dist/core/plugins/discovery.js +97 -0
  234. package/packages/server/dist/core/plugins/discovery.js.map +1 -0
  235. package/packages/server/dist/core/plugins/index.d.ts +6 -0
  236. package/packages/server/dist/core/plugins/index.d.ts.map +1 -0
  237. package/packages/server/dist/core/plugins/index.js +6 -0
  238. package/packages/server/dist/core/plugins/index.js.map +1 -0
  239. package/packages/server/dist/core/plugins/manifest.d.ts +9 -0
  240. package/packages/server/dist/core/plugins/manifest.d.ts.map +1 -0
  241. package/packages/server/dist/core/plugins/manifest.js +584 -0
  242. package/packages/server/dist/core/plugins/manifest.js.map +1 -0
  243. package/packages/server/dist/core/plugins/registry.d.ts +269 -0
  244. package/packages/server/dist/core/plugins/registry.d.ts.map +1 -0
  245. package/packages/server/dist/core/plugins/registry.js +1003 -0
  246. package/packages/server/dist/core/plugins/registry.js.map +1 -0
  247. package/packages/server/dist/core/plugins/secrets.d.ts +46 -0
  248. package/packages/server/dist/core/plugins/secrets.d.ts.map +1 -0
  249. package/packages/server/dist/core/plugins/secrets.js +174 -0
  250. package/packages/server/dist/core/plugins/secrets.js.map +1 -0
  251. package/packages/server/dist/core/plugins/skills.d.ts +131 -0
  252. package/packages/server/dist/core/plugins/skills.d.ts.map +1 -0
  253. package/packages/server/dist/core/plugins/skills.js +389 -0
  254. package/packages/server/dist/core/plugins/skills.js.map +1 -0
  255. package/packages/server/dist/core/templates.d.ts +28 -0
  256. package/packages/server/dist/core/templates.d.ts.map +1 -0
  257. package/packages/server/dist/core/templates.js +103 -0
  258. package/packages/server/dist/core/templates.js.map +1 -0
  259. package/packages/server/dist/core/tenant-context.d.ts +18 -0
  260. package/packages/server/dist/core/tenant-context.d.ts.map +1 -0
  261. package/packages/server/dist/core/tenant-context.js +42 -0
  262. package/packages/server/dist/core/tenant-context.js.map +1 -0
  263. package/packages/server/dist/core/tenant-id.d.ts +8 -0
  264. package/packages/server/dist/core/tenant-id.d.ts.map +1 -0
  265. package/packages/server/dist/core/tenant-id.js +53 -0
  266. package/packages/server/dist/core/tenant-id.js.map +1 -0
  267. package/packages/server/dist/core/tenant-skills.d.ts +29 -0
  268. package/packages/server/dist/core/tenant-skills.d.ts.map +1 -0
  269. package/packages/server/dist/core/tenant-skills.js +77 -0
  270. package/packages/server/dist/core/tenant-skills.js.map +1 -0
  271. package/packages/server/dist/core/worker-agents-fs.d.ts +44 -0
  272. package/packages/server/dist/core/worker-agents-fs.d.ts.map +1 -0
  273. package/packages/server/dist/core/worker-agents-fs.js +86 -0
  274. package/packages/server/dist/core/worker-agents-fs.js.map +1 -0
  275. package/packages/server/dist/core/worker-agents.d.ts +77 -0
  276. package/packages/server/dist/core/worker-agents.d.ts.map +1 -0
  277. package/packages/server/dist/core/worker-agents.js +191 -0
  278. package/packages/server/dist/core/worker-agents.js.map +1 -0
  279. package/packages/server/dist/index.d.ts +2 -0
  280. package/packages/server/dist/index.d.ts.map +1 -0
  281. package/packages/server/dist/index.js +623 -0
  282. package/packages/server/dist/index.js.map +1 -0
  283. package/packages/server/dist/lsp/client.d.ts +53 -0
  284. package/packages/server/dist/lsp/client.d.ts.map +1 -0
  285. package/packages/server/dist/lsp/client.js +258 -0
  286. package/packages/server/dist/lsp/client.js.map +1 -0
  287. package/packages/server/dist/lsp/format.d.ts +13 -0
  288. package/packages/server/dist/lsp/format.d.ts.map +1 -0
  289. package/packages/server/dist/lsp/format.js +55 -0
  290. package/packages/server/dist/lsp/format.js.map +1 -0
  291. package/packages/server/dist/lsp/index.d.ts +20 -0
  292. package/packages/server/dist/lsp/index.d.ts.map +1 -0
  293. package/packages/server/dist/lsp/index.js +32 -0
  294. package/packages/server/dist/lsp/index.js.map +1 -0
  295. package/packages/server/dist/lsp/language-registry.d.ts +29 -0
  296. package/packages/server/dist/lsp/language-registry.d.ts.map +1 -0
  297. package/packages/server/dist/lsp/language-registry.js +62 -0
  298. package/packages/server/dist/lsp/language-registry.js.map +1 -0
  299. package/packages/server/dist/lsp/manager.d.ts +77 -0
  300. package/packages/server/dist/lsp/manager.d.ts.map +1 -0
  301. package/packages/server/dist/lsp/manager.js +300 -0
  302. package/packages/server/dist/lsp/manager.js.map +1 -0
  303. package/packages/server/dist/plugins-routes.d.ts +96 -0
  304. package/packages/server/dist/plugins-routes.d.ts.map +1 -0
  305. package/packages/server/dist/plugins-routes.js +627 -0
  306. package/packages/server/dist/plugins-routes.js.map +1 -0
  307. package/packages/server/dist/setup/checks/config.d.ts +9 -0
  308. package/packages/server/dist/setup/checks/config.d.ts.map +1 -0
  309. package/packages/server/dist/setup/checks/config.js +66 -0
  310. package/packages/server/dist/setup/checks/config.js.map +1 -0
  311. package/packages/server/dist/setup/checks/db.d.ts +6 -0
  312. package/packages/server/dist/setup/checks/db.d.ts.map +1 -0
  313. package/packages/server/dist/setup/checks/db.js +79 -0
  314. package/packages/server/dist/setup/checks/db.js.map +1 -0
  315. package/packages/server/dist/setup/checks/known-models.d.ts +18 -0
  316. package/packages/server/dist/setup/checks/known-models.d.ts.map +1 -0
  317. package/packages/server/dist/setup/checks/known-models.js +119 -0
  318. package/packages/server/dist/setup/checks/known-models.js.map +1 -0
  319. package/packages/server/dist/setup/checks/network.d.ts +11 -0
  320. package/packages/server/dist/setup/checks/network.d.ts.map +1 -0
  321. package/packages/server/dist/setup/checks/network.js +176 -0
  322. package/packages/server/dist/setup/checks/network.js.map +1 -0
  323. package/packages/server/dist/setup/checks/plugins.d.ts +9 -0
  324. package/packages/server/dist/setup/checks/plugins.d.ts.map +1 -0
  325. package/packages/server/dist/setup/checks/plugins.js +194 -0
  326. package/packages/server/dist/setup/checks/plugins.js.map +1 -0
  327. package/packages/server/dist/setup/checks/providers.d.ts +12 -0
  328. package/packages/server/dist/setup/checks/providers.d.ts.map +1 -0
  329. package/packages/server/dist/setup/checks/providers.js +368 -0
  330. package/packages/server/dist/setup/checks/providers.js.map +1 -0
  331. package/packages/server/dist/setup/checks/runtime.d.ts +3 -0
  332. package/packages/server/dist/setup/checks/runtime.d.ts.map +1 -0
  333. package/packages/server/dist/setup/checks/runtime.js +44 -0
  334. package/packages/server/dist/setup/checks/runtime.js.map +1 -0
  335. package/packages/server/dist/setup/checks/sandbox.d.ts +9 -0
  336. package/packages/server/dist/setup/checks/sandbox.d.ts.map +1 -0
  337. package/packages/server/dist/setup/checks/sandbox.js +110 -0
  338. package/packages/server/dist/setup/checks/sandbox.js.map +1 -0
  339. package/packages/server/dist/setup/checks/tenants.d.ts +9 -0
  340. package/packages/server/dist/setup/checks/tenants.d.ts.map +1 -0
  341. package/packages/server/dist/setup/checks/tenants.js +509 -0
  342. package/packages/server/dist/setup/checks/tenants.js.map +1 -0
  343. package/packages/server/dist/setup/cli-agent.d.ts +39 -0
  344. package/packages/server/dist/setup/cli-agent.d.ts.map +1 -0
  345. package/packages/server/dist/setup/cli-agent.js +1353 -0
  346. package/packages/server/dist/setup/cli-agent.js.map +1 -0
  347. package/packages/server/dist/setup/doctor.d.ts +32 -0
  348. package/packages/server/dist/setup/doctor.d.ts.map +1 -0
  349. package/packages/server/dist/setup/doctor.js +80 -0
  350. package/packages/server/dist/setup/doctor.js.map +1 -0
  351. package/packages/server/dist/setup/launchd.d.ts +107 -0
  352. package/packages/server/dist/setup/launchd.d.ts.map +1 -0
  353. package/packages/server/dist/setup/launchd.js +309 -0
  354. package/packages/server/dist/setup/launchd.js.map +1 -0
  355. package/packages/server/dist/setup/load-env.d.ts +21 -0
  356. package/packages/server/dist/setup/load-env.d.ts.map +1 -0
  357. package/packages/server/dist/setup/load-env.js +88 -0
  358. package/packages/server/dist/setup/load-env.js.map +1 -0
  359. package/packages/server/dist/setup/probe-default-model.d.ts +28 -0
  360. package/packages/server/dist/setup/probe-default-model.d.ts.map +1 -0
  361. package/packages/server/dist/setup/probe-default-model.js +133 -0
  362. package/packages/server/dist/setup/probe-default-model.js.map +1 -0
  363. package/packages/server/dist/setup/render.d.ts +28 -0
  364. package/packages/server/dist/setup/render.d.ts.map +1 -0
  365. package/packages/server/dist/setup/render.js +60 -0
  366. package/packages/server/dist/setup/render.js.map +1 -0
  367. package/packages/server/dist/setup/repo-root.d.ts +3 -0
  368. package/packages/server/dist/setup/repo-root.d.ts.map +1 -0
  369. package/packages/server/dist/setup/repo-root.js +43 -0
  370. package/packages/server/dist/setup/repo-root.js.map +1 -0
  371. package/packages/server/dist/setup/service.d.ts +60 -0
  372. package/packages/server/dist/setup/service.d.ts.map +1 -0
  373. package/packages/server/dist/setup/service.js +345 -0
  374. package/packages/server/dist/setup/service.js.map +1 -0
  375. package/packages/server/dist/setup/start-server.d.ts +23 -0
  376. package/packages/server/dist/setup/start-server.d.ts.map +1 -0
  377. package/packages/server/dist/setup/start-server.js +465 -0
  378. package/packages/server/dist/setup/start-server.js.map +1 -0
  379. package/packages/server/dist/setup/wizard.d.ts +59 -0
  380. package/packages/server/dist/setup/wizard.d.ts.map +1 -0
  381. package/packages/server/dist/setup/wizard.js +556 -0
  382. package/packages/server/dist/setup/wizard.js.map +1 -0
  383. package/packages/server/dist/tools/edit-file.d.ts +13 -0
  384. package/packages/server/dist/tools/edit-file.d.ts.map +1 -0
  385. package/packages/server/dist/tools/edit-file.js +90 -0
  386. package/packages/server/dist/tools/edit-file.js.map +1 -0
  387. package/packages/server/dist/tools/glob.d.ts +12 -0
  388. package/packages/server/dist/tools/glob.d.ts.map +1 -0
  389. package/packages/server/dist/tools/glob.js +82 -0
  390. package/packages/server/dist/tools/glob.js.map +1 -0
  391. package/packages/server/dist/tools/index.d.ts +82 -0
  392. package/packages/server/dist/tools/index.d.ts.map +1 -0
  393. package/packages/server/dist/tools/index.js +72 -0
  394. package/packages/server/dist/tools/index.js.map +1 -0
  395. package/packages/server/dist/tools/list-dir.d.ts +24 -0
  396. package/packages/server/dist/tools/list-dir.d.ts.map +1 -0
  397. package/packages/server/dist/tools/list-dir.js +99 -0
  398. package/packages/server/dist/tools/list-dir.js.map +1 -0
  399. package/packages/server/dist/tools/path-helper.d.ts +15 -0
  400. package/packages/server/dist/tools/path-helper.d.ts.map +1 -0
  401. package/packages/server/dist/tools/path-helper.js +72 -0
  402. package/packages/server/dist/tools/path-helper.js.map +1 -0
  403. package/packages/server/dist/tools/read-file.d.ts +17 -0
  404. package/packages/server/dist/tools/read-file.d.ts.map +1 -0
  405. package/packages/server/dist/tools/read-file.js +94 -0
  406. package/packages/server/dist/tools/read-file.js.map +1 -0
  407. package/packages/server/dist/tools/sandbox.d.ts +57 -0
  408. package/packages/server/dist/tools/sandbox.d.ts.map +1 -0
  409. package/packages/server/dist/tools/sandbox.js +291 -0
  410. package/packages/server/dist/tools/sandbox.js.map +1 -0
  411. package/packages/server/dist/tools/write-file.d.ts +12 -0
  412. package/packages/server/dist/tools/write-file.d.ts.map +1 -0
  413. package/packages/server/dist/tools/write-file.js +67 -0
  414. package/packages/server/dist/tools/write-file.js.map +1 -0
  415. package/packages/server/dist/worker-agents-routes.d.ts +11 -0
  416. package/packages/server/dist/worker-agents-routes.d.ts.map +1 -0
  417. package/packages/server/dist/worker-agents-routes.js +253 -0
  418. package/packages/server/dist/worker-agents-routes.js.map +1 -0
  419. package/packages/server/package.json +41 -0
  420. package/packages/web/dist/assets/index-DH-gJ09_.js +60 -0
  421. package/packages/web/dist/assets/index-xU4lYYqY.css +2 -0
  422. package/packages/web/dist/index.html +14 -0
  423. package/packages/web/package.json +36 -0
  424. package/plugins/README.md +64 -0
  425. package/plugins/files/dist/client.d.ts +5 -0
  426. package/plugins/files/dist/client.d.ts.map +1 -0
  427. package/plugins/files/dist/client.js +354 -0
  428. package/plugins/files/dist/client.js.map +1 -0
  429. package/plugins/files/dist/server.d.ts +32 -0
  430. package/plugins/files/dist/server.d.ts.map +1 -0
  431. package/plugins/files/dist/server.js +514 -0
  432. package/plugins/files/dist/server.js.map +1 -0
  433. package/plugins/files/dist/tools/edit-file.d.ts +29 -0
  434. package/plugins/files/dist/tools/edit-file.d.ts.map +1 -0
  435. package/plugins/files/dist/tools/edit-file.js +230 -0
  436. package/plugins/files/dist/tools/edit-file.js.map +1 -0
  437. package/plugins/files/dist/tools/edit-file.prompt.md +36 -0
  438. package/plugins/files/dist/tools/glob.d.ts +12 -0
  439. package/plugins/files/dist/tools/glob.d.ts.map +1 -0
  440. package/plugins/files/dist/tools/glob.js +84 -0
  441. package/plugins/files/dist/tools/glob.js.map +1 -0
  442. package/plugins/files/dist/tools/index.d.ts +13 -0
  443. package/plugins/files/dist/tools/index.d.ts.map +1 -0
  444. package/plugins/files/dist/tools/index.js +158 -0
  445. package/plugins/files/dist/tools/index.js.map +1 -0
  446. package/plugins/files/dist/tools/list-dir.d.ts +24 -0
  447. package/plugins/files/dist/tools/list-dir.d.ts.map +1 -0
  448. package/plugins/files/dist/tools/list-dir.js +104 -0
  449. package/plugins/files/dist/tools/list-dir.js.map +1 -0
  450. package/plugins/files/dist/tools/load-prompt.d.ts +5 -0
  451. package/plugins/files/dist/tools/load-prompt.d.ts.map +1 -0
  452. package/plugins/files/dist/tools/load-prompt.js +39 -0
  453. package/plugins/files/dist/tools/load-prompt.js.map +1 -0
  454. package/plugins/files/dist/tools/path-helper.d.ts +32 -0
  455. package/plugins/files/dist/tools/path-helper.d.ts.map +1 -0
  456. package/plugins/files/dist/tools/path-helper.js +113 -0
  457. package/plugins/files/dist/tools/path-helper.js.map +1 -0
  458. package/plugins/files/dist/tools/read-file.d.ts +17 -0
  459. package/plugins/files/dist/tools/read-file.d.ts.map +1 -0
  460. package/plugins/files/dist/tools/read-file.js +109 -0
  461. package/plugins/files/dist/tools/read-file.js.map +1 -0
  462. package/plugins/files/dist/tools/read-tracker.d.ts +28 -0
  463. package/plugins/files/dist/tools/read-tracker.d.ts.map +1 -0
  464. package/plugins/files/dist/tools/read-tracker.js +135 -0
  465. package/plugins/files/dist/tools/read-tracker.js.map +1 -0
  466. package/plugins/files/dist/tools/replacers.d.ts +27 -0
  467. package/plugins/files/dist/tools/replacers.d.ts.map +1 -0
  468. package/plugins/files/dist/tools/replacers.js +221 -0
  469. package/plugins/files/dist/tools/replacers.js.map +1 -0
  470. package/plugins/files/dist/tools/tenant-config-delete.d.ts +12 -0
  471. package/plugins/files/dist/tools/tenant-config-delete.d.ts.map +1 -0
  472. package/plugins/files/dist/tools/tenant-config-delete.js +70 -0
  473. package/plugins/files/dist/tools/tenant-config-delete.js.map +1 -0
  474. package/plugins/files/dist/tools/tenant-config-edit.d.ts +25 -0
  475. package/plugins/files/dist/tools/tenant-config-edit.d.ts.map +1 -0
  476. package/plugins/files/dist/tools/tenant-config-edit.js +142 -0
  477. package/plugins/files/dist/tools/tenant-config-edit.js.map +1 -0
  478. package/plugins/files/dist/tools/tenant-config-glob.d.ts +12 -0
  479. package/plugins/files/dist/tools/tenant-config-glob.d.ts.map +1 -0
  480. package/plugins/files/dist/tools/tenant-config-glob.js +64 -0
  481. package/plugins/files/dist/tools/tenant-config-glob.js.map +1 -0
  482. package/plugins/files/dist/tools/tenant-config-helper.d.ts +64 -0
  483. package/plugins/files/dist/tools/tenant-config-helper.d.ts.map +1 -0
  484. package/plugins/files/dist/tools/tenant-config-helper.js +162 -0
  485. package/plugins/files/dist/tools/tenant-config-helper.js.map +1 -0
  486. package/plugins/files/dist/tools/tenant-config-list.d.ts +20 -0
  487. package/plugins/files/dist/tools/tenant-config-list.d.ts.map +1 -0
  488. package/plugins/files/dist/tools/tenant-config-list.js +95 -0
  489. package/plugins/files/dist/tools/tenant-config-list.js.map +1 -0
  490. package/plugins/files/dist/tools/tenant-config-read.d.ts +17 -0
  491. package/plugins/files/dist/tools/tenant-config-read.d.ts.map +1 -0
  492. package/plugins/files/dist/tools/tenant-config-read.js +87 -0
  493. package/plugins/files/dist/tools/tenant-config-read.js.map +1 -0
  494. package/plugins/files/dist/tools/tenant-config-write.d.ts +14 -0
  495. package/plugins/files/dist/tools/tenant-config-write.d.ts.map +1 -0
  496. package/plugins/files/dist/tools/tenant-config-write.js +78 -0
  497. package/plugins/files/dist/tools/tenant-config-write.js.map +1 -0
  498. package/plugins/files/dist/tools/text-shape.d.ts +20 -0
  499. package/plugins/files/dist/tools/text-shape.d.ts.map +1 -0
  500. package/plugins/files/dist/tools/text-shape.js +57 -0
  501. package/plugins/files/dist/tools/text-shape.js.map +1 -0
  502. package/plugins/files/dist/tools/write-file.d.ts +12 -0
  503. package/plugins/files/dist/tools/write-file.d.ts.map +1 -0
  504. package/plugins/files/dist/tools/write-file.js +89 -0
  505. package/plugins/files/dist/tools/write-file.js.map +1 -0
  506. package/plugins/files/dist/tools/write-file.prompt.md +14 -0
  507. package/plugins/files/manifest.json +100 -0
  508. package/plugins/files/package.json +39 -0
  509. package/plugins/files/skills/files-workspace-layout.md +29 -0
  510. package/plugins/microsandbox/dist/admin/browser-routes.d.ts +41 -0
  511. package/plugins/microsandbox/dist/admin/browser-routes.d.ts.map +1 -0
  512. package/plugins/microsandbox/dist/admin/browser-routes.js +208 -0
  513. package/plugins/microsandbox/dist/admin/browser-routes.js.map +1 -0
  514. package/plugins/microsandbox/dist/admin/preview-exec.d.ts +38 -0
  515. package/plugins/microsandbox/dist/admin/preview-exec.d.ts.map +1 -0
  516. package/plugins/microsandbox/dist/admin/preview-exec.js +185 -0
  517. package/plugins/microsandbox/dist/admin/preview-exec.js.map +1 -0
  518. package/plugins/microsandbox/dist/admin/routes.d.ts +35 -0
  519. package/plugins/microsandbox/dist/admin/routes.d.ts.map +1 -0
  520. package/plugins/microsandbox/dist/admin/routes.js +728 -0
  521. package/plugins/microsandbox/dist/admin/routes.js.map +1 -0
  522. package/plugins/microsandbox/dist/admin/sandboxfile-io.d.ts +11 -0
  523. package/plugins/microsandbox/dist/admin/sandboxfile-io.d.ts.map +1 -0
  524. package/plugins/microsandbox/dist/admin/sandboxfile-io.js +72 -0
  525. package/plugins/microsandbox/dist/admin/sandboxfile-io.js.map +1 -0
  526. package/plugins/microsandbox/dist/admin/templates.d.ts +16 -0
  527. package/plugins/microsandbox/dist/admin/templates.d.ts.map +1 -0
  528. package/plugins/microsandbox/dist/admin/templates.js +66 -0
  529. package/plugins/microsandbox/dist/admin/templates.js.map +1 -0
  530. package/plugins/microsandbox/dist/admin.d.ts +5 -0
  531. package/plugins/microsandbox/dist/admin.d.ts.map +1 -0
  532. package/plugins/microsandbox/dist/admin.js +256 -0
  533. package/plugins/microsandbox/dist/admin.js.map +1 -0
  534. package/plugins/microsandbox/dist/build/builder.d.ts +69 -0
  535. package/plugins/microsandbox/dist/build/builder.d.ts.map +1 -0
  536. package/plugins/microsandbox/dist/build/builder.js +257 -0
  537. package/plugins/microsandbox/dist/build/builder.js.map +1 -0
  538. package/plugins/microsandbox/dist/build/metadata.d.ts +27 -0
  539. package/plugins/microsandbox/dist/build/metadata.d.ts.map +1 -0
  540. package/plugins/microsandbox/dist/build/metadata.js +55 -0
  541. package/plugins/microsandbox/dist/build/metadata.js.map +1 -0
  542. package/plugins/microsandbox/dist/build/pointer.d.ts +51 -0
  543. package/plugins/microsandbox/dist/build/pointer.d.ts.map +1 -0
  544. package/plugins/microsandbox/dist/build/pointer.js +130 -0
  545. package/plugins/microsandbox/dist/build/pointer.js.map +1 -0
  546. package/plugins/microsandbox/dist/build/sandboxfile.d.ts +15 -0
  547. package/plugins/microsandbox/dist/build/sandboxfile.d.ts.map +1 -0
  548. package/plugins/microsandbox/dist/build/sandboxfile.js +176 -0
  549. package/plugins/microsandbox/dist/build/sandboxfile.js.map +1 -0
  550. package/plugins/microsandbox/dist/client.d.ts +5 -0
  551. package/plugins/microsandbox/dist/client.d.ts.map +1 -0
  552. package/plugins/microsandbox/dist/client.js +941 -0
  553. package/plugins/microsandbox/dist/client.js.map +1 -0
  554. package/plugins/microsandbox/dist/runner/browser.d.ts +50 -0
  555. package/plugins/microsandbox/dist/runner/browser.d.ts.map +1 -0
  556. package/plugins/microsandbox/dist/runner/browser.js +142 -0
  557. package/plugins/microsandbox/dist/runner/browser.js.map +1 -0
  558. package/plugins/microsandbox/dist/runner/free-port.d.ts +6 -0
  559. package/plugins/microsandbox/dist/runner/free-port.d.ts.map +1 -0
  560. package/plugins/microsandbox/dist/runner/free-port.js +53 -0
  561. package/plugins/microsandbox/dist/runner/free-port.js.map +1 -0
  562. package/plugins/microsandbox/dist/runner/index.d.ts +28 -0
  563. package/plugins/microsandbox/dist/runner/index.d.ts.map +1 -0
  564. package/plugins/microsandbox/dist/runner/index.js +72 -0
  565. package/plugins/microsandbox/dist/runner/index.js.map +1 -0
  566. package/plugins/microsandbox/dist/runner/microsandbox.d.ts +64 -0
  567. package/plugins/microsandbox/dist/runner/microsandbox.d.ts.map +1 -0
  568. package/plugins/microsandbox/dist/runner/microsandbox.js +668 -0
  569. package/plugins/microsandbox/dist/runner/microsandbox.js.map +1 -0
  570. package/plugins/microsandbox/dist/runner/nullable.d.ts +36 -0
  571. package/plugins/microsandbox/dist/runner/nullable.d.ts.map +1 -0
  572. package/plugins/microsandbox/dist/runner/nullable.js +82 -0
  573. package/plugins/microsandbox/dist/runner/nullable.js.map +1 -0
  574. package/plugins/microsandbox/dist/runner/pool.d.ts +97 -0
  575. package/plugins/microsandbox/dist/runner/pool.d.ts.map +1 -0
  576. package/plugins/microsandbox/dist/runner/pool.js +494 -0
  577. package/plugins/microsandbox/dist/runner/pool.js.map +1 -0
  578. package/plugins/microsandbox/dist/runner/types.d.ts +33 -0
  579. package/plugins/microsandbox/dist/runner/types.d.ts.map +1 -0
  580. package/plugins/microsandbox/dist/runner/types.js +79 -0
  581. package/plugins/microsandbox/dist/runner/types.js.map +1 -0
  582. package/plugins/microsandbox/dist/server.d.ts +7 -0
  583. package/plugins/microsandbox/dist/server.d.ts.map +1 -0
  584. package/plugins/microsandbox/dist/server.js +276 -0
  585. package/plugins/microsandbox/dist/server.js.map +1 -0
  586. package/plugins/microsandbox/dist/tools/browser.d.ts +25 -0
  587. package/plugins/microsandbox/dist/tools/browser.d.ts.map +1 -0
  588. package/plugins/microsandbox/dist/tools/browser.js +78 -0
  589. package/plugins/microsandbox/dist/tools/browser.js.map +1 -0
  590. package/plugins/microsandbox/dist/tools/build.d.ts +5 -0
  591. package/plugins/microsandbox/dist/tools/build.d.ts.map +1 -0
  592. package/plugins/microsandbox/dist/tools/build.js +243 -0
  593. package/plugins/microsandbox/dist/tools/build.js.map +1 -0
  594. package/plugins/microsandbox/dist/tools/index.d.ts +9 -0
  595. package/plugins/microsandbox/dist/tools/index.d.ts.map +1 -0
  596. package/plugins/microsandbox/dist/tools/index.js +430 -0
  597. package/plugins/microsandbox/dist/tools/index.js.map +1 -0
  598. package/plugins/microsandbox/dist/tools/mcp-client.d.ts +63 -0
  599. package/plugins/microsandbox/dist/tools/mcp-client.d.ts.map +1 -0
  600. package/plugins/microsandbox/dist/tools/mcp-client.js +226 -0
  601. package/plugins/microsandbox/dist/tools/mcp-client.js.map +1 -0
  602. package/plugins/microsandbox/manifest.json +177 -0
  603. package/plugins/microsandbox/package.json +38 -0
  604. package/plugins/microsandbox/skills/microsandbox-browser-howto.md +155 -0
  605. package/plugins/microsandbox/skills/microsandbox-build-use.md +201 -0
  606. package/plugins/microsandbox/skills/microsandbox-config.md +38 -0
  607. package/plugins/microsandbox/skills/microsandbox-exec-howto.md +144 -0
  608. package/plugins/microsandbox/skills/microsandbox-libreoffice.md +159 -0
  609. package/plugins/microsandbox/templates/README.md +26 -0
  610. package/plugins/web-search/dist/server.d.ts +4 -0
  611. package/plugins/web-search/dist/server.d.ts.map +1 -0
  612. package/plugins/web-search/dist/server.js +73 -0
  613. package/plugins/web-search/dist/server.js.map +1 -0
  614. package/plugins/web-search/dist/tools/health.d.ts +31 -0
  615. package/plugins/web-search/dist/tools/health.d.ts.map +1 -0
  616. package/plugins/web-search/dist/tools/health.js +59 -0
  617. package/plugins/web-search/dist/tools/health.js.map +1 -0
  618. package/plugins/web-search/dist/tools/index.d.ts +3 -0
  619. package/plugins/web-search/dist/tools/index.d.ts.map +1 -0
  620. package/plugins/web-search/dist/tools/index.js +2 -0
  621. package/plugins/web-search/dist/tools/index.js.map +1 -0
  622. package/plugins/web-search/dist/tools/providers.d.ts +43 -0
  623. package/plugins/web-search/dist/tools/providers.d.ts.map +1 -0
  624. package/plugins/web-search/dist/tools/providers.js +140 -0
  625. package/plugins/web-search/dist/tools/providers.js.map +1 -0
  626. package/plugins/web-search/dist/tools/web-search.d.ts +15 -0
  627. package/plugins/web-search/dist/tools/web-search.d.ts.map +1 -0
  628. package/plugins/web-search/dist/tools/web-search.js +244 -0
  629. package/plugins/web-search/dist/tools/web-search.js.map +1 -0
  630. package/plugins/web-search/manifest.json +65 -0
  631. package/plugins/web-search/node_modules/@esbuild/darwin-arm64/README.md +3 -0
  632. package/plugins/web-search/node_modules/@esbuild/darwin-arm64/package.json +20 -0
  633. package/plugins/web-search/node_modules/@vitest/expect/LICENSE +21 -0
  634. package/plugins/web-search/node_modules/@vitest/expect/README.md +21 -0
  635. package/plugins/web-search/node_modules/@vitest/expect/dist/index.d.ts +808 -0
  636. package/plugins/web-search/node_modules/@vitest/expect/dist/index.js +1799 -0
  637. package/plugins/web-search/node_modules/@vitest/expect/package.json +46 -0
  638. package/plugins/web-search/node_modules/@vitest/mocker/LICENSE +21 -0
  639. package/plugins/web-search/node_modules/@vitest/mocker/README.md +5 -0
  640. package/plugins/web-search/node_modules/@vitest/mocker/dist/auto-register.d.ts +2 -0
  641. package/plugins/web-search/node_modules/@vitest/mocker/dist/auto-register.js +9 -0
  642. package/plugins/web-search/node_modules/@vitest/mocker/dist/browser.d.ts +53 -0
  643. package/plugins/web-search/node_modules/@vitest/mocker/dist/browser.js +91 -0
  644. package/plugins/web-search/node_modules/@vitest/mocker/dist/chunk-interceptor-native.js +15 -0
  645. package/plugins/web-search/node_modules/@vitest/mocker/dist/chunk-mocker.js +1602 -0
  646. package/plugins/web-search/node_modules/@vitest/mocker/dist/chunk-pathe.M-eThtNZ.js +174 -0
  647. package/plugins/web-search/node_modules/@vitest/mocker/dist/chunk-registry.js +182 -0
  648. package/plugins/web-search/node_modules/@vitest/mocker/dist/chunk-utils.js +16 -0
  649. package/plugins/web-search/node_modules/@vitest/mocker/dist/index.d.ts +21 -0
  650. package/plugins/web-search/node_modules/@vitest/mocker/dist/index.js +174 -0
  651. package/plugins/web-search/node_modules/@vitest/mocker/dist/mocker.d-Ce9_ySj5.d.ts +83 -0
  652. package/plugins/web-search/node_modules/@vitest/mocker/dist/node.d.ts +821 -0
  653. package/plugins/web-search/node_modules/@vitest/mocker/dist/node.js +1306 -0
  654. package/plugins/web-search/node_modules/@vitest/mocker/dist/redirect.d.ts +3 -0
  655. package/plugins/web-search/node_modules/@vitest/mocker/dist/redirect.js +75 -0
  656. package/plugins/web-search/node_modules/@vitest/mocker/dist/register.d.ts +9 -0
  657. package/plugins/web-search/node_modules/@vitest/mocker/dist/register.js +41 -0
  658. package/plugins/web-search/node_modules/@vitest/mocker/dist/registry.d-D765pazg.d.ts +87 -0
  659. package/plugins/web-search/node_modules/@vitest/mocker/dist/types.d-D_aRZRdy.d.ts +8 -0
  660. package/plugins/web-search/node_modules/@vitest/mocker/package.json +82 -0
  661. package/plugins/web-search/node_modules/@vitest/pretty-format/LICENSE +21 -0
  662. package/plugins/web-search/node_modules/@vitest/pretty-format/dist/index.d.ts +119 -0
  663. package/plugins/web-search/node_modules/@vitest/pretty-format/dist/index.js +1387 -0
  664. package/plugins/web-search/node_modules/@vitest/pretty-format/package.json +44 -0
  665. package/plugins/web-search/node_modules/@vitest/runner/LICENSE +21 -0
  666. package/plugins/web-search/node_modules/@vitest/runner/README.md +5 -0
  667. package/plugins/web-search/node_modules/@vitest/runner/dist/chunk-hooks.js +2254 -0
  668. package/plugins/web-search/node_modules/@vitest/runner/dist/index.d.ts +261 -0
  669. package/plugins/web-search/node_modules/@vitest/runner/dist/index.js +6 -0
  670. package/plugins/web-search/node_modules/@vitest/runner/dist/tasks.d-CkscK4of.d.ts +558 -0
  671. package/plugins/web-search/node_modules/@vitest/runner/dist/types.d.ts +163 -0
  672. package/plugins/web-search/node_modules/@vitest/runner/dist/types.js +1 -0
  673. package/plugins/web-search/node_modules/@vitest/runner/dist/utils.d.ts +47 -0
  674. package/plugins/web-search/node_modules/@vitest/runner/dist/utils.js +6 -0
  675. package/plugins/web-search/node_modules/@vitest/runner/package.json +49 -0
  676. package/plugins/web-search/node_modules/@vitest/snapshot/LICENSE +21 -0
  677. package/plugins/web-search/node_modules/@vitest/snapshot/README.md +84 -0
  678. package/plugins/web-search/node_modules/@vitest/snapshot/dist/environment.d-DHdQ1Csl.d.ts +22 -0
  679. package/plugins/web-search/node_modules/@vitest/snapshot/dist/environment.d.ts +16 -0
  680. package/plugins/web-search/node_modules/@vitest/snapshot/dist/environment.js +40 -0
  681. package/plugins/web-search/node_modules/@vitest/snapshot/dist/index.d.ts +137 -0
  682. package/plugins/web-search/node_modules/@vitest/snapshot/dist/index.js +2305 -0
  683. package/plugins/web-search/node_modules/@vitest/snapshot/dist/manager.d.ts +18 -0
  684. package/plugins/web-search/node_modules/@vitest/snapshot/dist/manager.js +73 -0
  685. package/plugins/web-search/node_modules/@vitest/snapshot/dist/rawSnapshot.d-lFsMJFUd.d.ts +61 -0
  686. package/plugins/web-search/node_modules/@vitest/snapshot/package.json +54 -0
  687. package/plugins/web-search/node_modules/@vitest/spy/LICENSE +21 -0
  688. package/plugins/web-search/node_modules/@vitest/spy/README.md +3 -0
  689. package/plugins/web-search/node_modules/@vitest/spy/dist/index.d.ts +356 -0
  690. package/plugins/web-search/node_modules/@vitest/spy/dist/index.js +191 -0
  691. package/plugins/web-search/node_modules/@vitest/spy/package.json +38 -0
  692. package/plugins/web-search/node_modules/@vitest/utils/LICENSE +21 -0
  693. package/plugins/web-search/node_modules/@vitest/utils/dist/chunk-_commonjsHelpers.js +158 -0
  694. package/plugins/web-search/node_modules/@vitest/utils/dist/diff.d.ts +104 -0
  695. package/plugins/web-search/node_modules/@vitest/utils/dist/diff.js +2185 -0
  696. package/plugins/web-search/node_modules/@vitest/utils/dist/error.d.ts +9 -0
  697. package/plugins/web-search/node_modules/@vitest/utils/dist/error.js +162 -0
  698. package/plugins/web-search/node_modules/@vitest/utils/dist/helpers.d.ts +56 -0
  699. package/plugins/web-search/node_modules/@vitest/utils/dist/helpers.js +251 -0
  700. package/plugins/web-search/node_modules/@vitest/utils/dist/index.d.ts +57 -0
  701. package/plugins/web-search/node_modules/@vitest/utils/dist/index.js +633 -0
  702. package/plugins/web-search/node_modules/@vitest/utils/dist/source-map.d.ts +139 -0
  703. package/plugins/web-search/node_modules/@vitest/utils/dist/source-map.js +996 -0
  704. package/plugins/web-search/node_modules/@vitest/utils/dist/types.d-BCElaP-c.d.ts +53 -0
  705. package/plugins/web-search/node_modules/@vitest/utils/dist/types.d.ts +53 -0
  706. package/plugins/web-search/node_modules/@vitest/utils/dist/types.js +1 -0
  707. package/plugins/web-search/node_modules/@vitest/utils/package.json +77 -0
  708. package/plugins/web-search/node_modules/chai/LICENSE +21 -0
  709. package/plugins/web-search/node_modules/chai/README.md +162 -0
  710. package/plugins/web-search/node_modules/chai/package.json +74 -0
  711. package/plugins/web-search/node_modules/esbuild/README.md +3 -0
  712. package/plugins/web-search/node_modules/esbuild/package.json +49 -0
  713. package/plugins/web-search/node_modules/std-env/README.md +118 -0
  714. package/plugins/web-search/node_modules/std-env/dist/index.cjs +1 -0
  715. package/plugins/web-search/node_modules/std-env/dist/index.d.cts +92 -0
  716. package/plugins/web-search/node_modules/std-env/dist/index.d.mts +92 -0
  717. package/plugins/web-search/node_modules/std-env/dist/index.d.ts +92 -0
  718. package/plugins/web-search/node_modules/std-env/dist/index.mjs +1 -0
  719. package/plugins/web-search/node_modules/std-env/package.json +46 -0
  720. package/plugins/web-search/node_modules/tinyexec/LICENSE +21 -0
  721. package/plugins/web-search/node_modules/tinyexec/README.md +256 -0
  722. package/plugins/web-search/node_modules/tinyexec/dist/main.cjs +575 -0
  723. package/plugins/web-search/node_modules/tinyexec/dist/main.d.cts +70 -0
  724. package/plugins/web-search/node_modules/tinyexec/dist/main.d.ts +70 -0
  725. package/plugins/web-search/node_modules/tinyexec/dist/main.js +578 -0
  726. package/plugins/web-search/node_modules/tinyexec/package.json +66 -0
  727. package/plugins/web-search/node_modules/tinyrainbow/README.md +28 -0
  728. package/plugins/web-search/node_modules/tinyrainbow/dist/browser.d.ts +8 -0
  729. package/plugins/web-search/node_modules/tinyrainbow/dist/browser.js +20 -0
  730. package/plugins/web-search/node_modules/tinyrainbow/dist/chunk-BVHSVHOK.js +90 -0
  731. package/plugins/web-search/node_modules/tinyrainbow/dist/index-8b61d5bc.d.ts +59 -0
  732. package/plugins/web-search/node_modules/tinyrainbow/dist/node.d.ts +8 -0
  733. package/plugins/web-search/node_modules/tinyrainbow/dist/node.js +22 -0
  734. package/plugins/web-search/node_modules/tinyrainbow/package.json +37 -0
  735. package/plugins/web-search/node_modules/typescript/README.md +50 -0
  736. package/plugins/web-search/node_modules/typescript/package.json +120 -0
  737. package/plugins/web-search/node_modules/vite/README.md +20 -0
  738. package/plugins/web-search/node_modules/vite/dist/client/client.mjs +1106 -0
  739. package/plugins/web-search/node_modules/vite/dist/client/env.mjs +19 -0
  740. package/plugins/web-search/node_modules/vite/dist/node/chunks/build.js +4 -0
  741. package/plugins/web-search/node_modules/vite/dist/node/chunks/build2.js +5538 -0
  742. package/plugins/web-search/node_modules/vite/dist/node/chunks/chunk.js +48 -0
  743. package/plugins/web-search/node_modules/vite/dist/node/chunks/config.js +36065 -0
  744. package/plugins/web-search/node_modules/vite/dist/node/chunks/config2.js +4 -0
  745. package/plugins/web-search/node_modules/vite/dist/node/chunks/dist.js +6758 -0
  746. package/plugins/web-search/node_modules/vite/dist/node/chunks/lib.js +377 -0
  747. package/plugins/web-search/node_modules/vite/dist/node/chunks/logger.js +329 -0
  748. package/plugins/web-search/node_modules/vite/dist/node/chunks/moduleRunnerTransport.d.ts +96 -0
  749. package/plugins/web-search/node_modules/vite/dist/node/chunks/optimizer.js +4 -0
  750. package/plugins/web-search/node_modules/vite/dist/node/chunks/postcss-import.js +479 -0
  751. package/plugins/web-search/node_modules/vite/dist/node/chunks/preview.js +4 -0
  752. package/plugins/web-search/node_modules/vite/dist/node/chunks/server.js +4 -0
  753. package/plugins/web-search/node_modules/vite/dist/node/cli.js +698 -0
  754. package/plugins/web-search/node_modules/vite/dist/node/index.d.ts +3717 -0
  755. package/plugins/web-search/node_modules/vite/dist/node/index.js +30 -0
  756. package/plugins/web-search/node_modules/vite/dist/node/module-runner.d.ts +311 -0
  757. package/plugins/web-search/node_modules/vite/dist/node/module-runner.js +1160 -0
  758. package/plugins/web-search/node_modules/vite/package.json +199 -0
  759. package/plugins/web-search/node_modules/vite/types/package.json +4 -0
  760. package/plugins/web-search/node_modules/vitest/README.md +7 -0
  761. package/plugins/web-search/node_modules/vitest/dist/browser.d.ts +34 -0
  762. package/plugins/web-search/node_modules/vitest/dist/browser.js +8 -0
  763. package/plugins/web-search/node_modules/vitest/dist/chunks/_commonjsHelpers.BFTU3MAI.js +7 -0
  764. package/plugins/web-search/node_modules/vitest/dist/chunks/base.DfmxU-tU.js +38 -0
  765. package/plugins/web-search/node_modules/vitest/dist/chunks/benchmark.CYdenmiT.js +37 -0
  766. package/plugins/web-search/node_modules/vitest/dist/chunks/benchmark.d.BwvBVTda.d.ts +24 -0
  767. package/plugins/web-search/node_modules/vitest/dist/chunks/cac.0BJqEUeA.js +1469 -0
  768. package/plugins/web-search/node_modules/vitest/dist/chunks/cli-api.DWGBtMmz.js +10660 -0
  769. package/plugins/web-search/node_modules/vitest/dist/chunks/config.d.BKdhh7Zx.d.ts +224 -0
  770. package/plugins/web-search/node_modules/vitest/dist/chunks/console.CtFJOzRO.js +153 -0
  771. package/plugins/web-search/node_modules/vitest/dist/chunks/constants.DnKduX2e.js +44 -0
  772. package/plugins/web-search/node_modules/vitest/dist/chunks/coverage.DVF1vEu8.js +25 -0
  773. package/plugins/web-search/node_modules/vitest/dist/chunks/coverage.DfSpMS-b.js +4350 -0
  774. package/plugins/web-search/node_modules/vitest/dist/chunks/coverage.d.S9RMNXIe.d.ts +35 -0
  775. package/plugins/web-search/node_modules/vitest/dist/chunks/creator.GK6I-cL4.js +640 -0
  776. package/plugins/web-search/node_modules/vitest/dist/chunks/date.Bq6ZW5rf.js +73 -0
  777. package/plugins/web-search/node_modules/vitest/dist/chunks/defaults.B7q_naMc.js +115 -0
  778. package/plugins/web-search/node_modules/vitest/dist/chunks/env.D4Lgay0q.js +8 -0
  779. package/plugins/web-search/node_modules/vitest/dist/chunks/environment.d.cL3nLXbE.d.ts +119 -0
  780. package/plugins/web-search/node_modules/vitest/dist/chunks/execute.B7h3T_Hc.js +708 -0
  781. package/plugins/web-search/node_modules/vitest/dist/chunks/git.BVQ8w_Sw.js +72 -0
  782. package/plugins/web-search/node_modules/vitest/dist/chunks/global.d.MAmajcmJ.d.ts +136 -0
  783. package/plugins/web-search/node_modules/vitest/dist/chunks/globals.DEHgCU4V.js +26 -0
  784. package/plugins/web-search/node_modules/vitest/dist/chunks/index.B521nVV-.js +157 -0
  785. package/plugins/web-search/node_modules/vitest/dist/chunks/index.BCWujgDG.js +231 -0
  786. package/plugins/web-search/node_modules/vitest/dist/chunks/index.CdQS2e2Q.js +37 -0
  787. package/plugins/web-search/node_modules/vitest/dist/chunks/index.CmSc2RE5.js +587 -0
  788. package/plugins/web-search/node_modules/vitest/dist/chunks/index.CwejwG0H.js +105 -0
  789. package/plugins/web-search/node_modules/vitest/dist/chunks/index.D3XRDfWc.js +213 -0
  790. package/plugins/web-search/node_modules/vitest/dist/chunks/index.VByaPkjc.js +2183 -0
  791. package/plugins/web-search/node_modules/vitest/dist/chunks/index.X0nbfr6-.js +6584 -0
  792. package/plugins/web-search/node_modules/vitest/dist/chunks/inspector.C914Efll.js +57 -0
  793. package/plugins/web-search/node_modules/vitest/dist/chunks/mocker.d.BE_2ls6u.d.ts +17 -0
  794. package/plugins/web-search/node_modules/vitest/dist/chunks/node.fjCdwEIl.js +15 -0
  795. package/plugins/web-search/node_modules/vitest/dist/chunks/reporters.d.BuRON0I0.d.ts +3168 -0
  796. package/plugins/web-search/node_modules/vitest/dist/chunks/rpc.-pEldfrD.js +83 -0
  797. package/plugins/web-search/node_modules/vitest/dist/chunks/runBaseTests.9Ij9_de-.js +129 -0
  798. package/plugins/web-search/node_modules/vitest/dist/chunks/setup-common.Dd054P77.js +60 -0
  799. package/plugins/web-search/node_modules/vitest/dist/chunks/suite.d.FvehnV49.d.ts +10 -0
  800. package/plugins/web-search/node_modules/vitest/dist/chunks/typechecker.DRKU1-1g.js +874 -0
  801. package/plugins/web-search/node_modules/vitest/dist/chunks/utils.CAioKnHs.js +61 -0
  802. package/plugins/web-search/node_modules/vitest/dist/chunks/utils.XdZDrNZV.js +65 -0
  803. package/plugins/web-search/node_modules/vitest/dist/chunks/vi.bdSIJ99Y.js +4015 -0
  804. package/plugins/web-search/node_modules/vitest/dist/chunks/vite.d.BnOPPc46.d.ts +25 -0
  805. package/plugins/web-search/node_modules/vitest/dist/chunks/vm.BThCzidc.js +756 -0
  806. package/plugins/web-search/node_modules/vitest/dist/chunks/worker.d.CUgIPz9V.d.ts +176 -0
  807. package/plugins/web-search/node_modules/vitest/dist/chunks/worker.d.uzWsCv9X.d.ts +8 -0
  808. package/plugins/web-search/node_modules/vitest/dist/cli.js +27 -0
  809. package/plugins/web-search/node_modules/vitest/dist/config.cjs +148 -0
  810. package/plugins/web-search/node_modules/vitest/dist/config.d.ts +100 -0
  811. package/plugins/web-search/node_modules/vitest/dist/config.js +21 -0
  812. package/plugins/web-search/node_modules/vitest/dist/coverage.d.ts +108 -0
  813. package/plugins/web-search/node_modules/vitest/dist/coverage.js +34 -0
  814. package/plugins/web-search/node_modules/vitest/dist/environments.d.ts +26 -0
  815. package/plugins/web-search/node_modules/vitest/dist/environments.js +2 -0
  816. package/plugins/web-search/node_modules/vitest/dist/execute.d.ts +150 -0
  817. package/plugins/web-search/node_modules/vitest/dist/execute.js +13 -0
  818. package/plugins/web-search/node_modules/vitest/dist/index.d.ts +651 -0
  819. package/plugins/web-search/node_modules/vitest/dist/index.js +18 -0
  820. package/plugins/web-search/node_modules/vitest/dist/mocker.d.ts +1 -0
  821. package/plugins/web-search/node_modules/vitest/dist/mocker.js +1 -0
  822. package/plugins/web-search/node_modules/vitest/dist/node.d.ts +158 -0
  823. package/plugins/web-search/node_modules/vitest/dist/node.js +105 -0
  824. package/plugins/web-search/node_modules/vitest/dist/path.js +7 -0
  825. package/plugins/web-search/node_modules/vitest/dist/reporters.d.ts +25 -0
  826. package/plugins/web-search/node_modules/vitest/dist/reporters.js +23 -0
  827. package/plugins/web-search/node_modules/vitest/dist/runners.d.ts +46 -0
  828. package/plugins/web-search/node_modules/vitest/dist/runners.js +235 -0
  829. package/plugins/web-search/node_modules/vitest/dist/snapshot.d.ts +9 -0
  830. package/plugins/web-search/node_modules/vitest/dist/snapshot.js +4 -0
  831. package/plugins/web-search/node_modules/vitest/dist/spy.js +1 -0
  832. package/plugins/web-search/node_modules/vitest/dist/suite.d.ts +5 -0
  833. package/plugins/web-search/node_modules/vitest/dist/suite.js +5 -0
  834. package/plugins/web-search/node_modules/vitest/dist/worker.js +124 -0
  835. package/plugins/web-search/node_modules/vitest/dist/workers/forks.js +43 -0
  836. package/plugins/web-search/node_modules/vitest/dist/workers/runVmTests.js +90 -0
  837. package/plugins/web-search/node_modules/vitest/dist/workers/threads.js +31 -0
  838. package/plugins/web-search/node_modules/vitest/dist/workers/vmForks.js +47 -0
  839. package/plugins/web-search/node_modules/vitest/dist/workers/vmThreads.js +37 -0
  840. package/plugins/web-search/node_modules/vitest/dist/workers.d.ts +40 -0
  841. package/plugins/web-search/node_modules/vitest/dist/workers.js +30 -0
  842. package/plugins/web-search/node_modules/vitest/package.json +207 -0
  843. package/plugins/web-search/package.json +30 -0
  844. package/plugins/web-search/skills/web-search-howto.md +69 -0
  845. package/plugins/workboard/agent-seeds/echo-demo/agent.json +7 -0
  846. package/plugins/workboard/agent-seeds/llm-default/SOUL.md +53 -0
  847. package/plugins/workboard/agent-seeds/llm-default/agent.json +7 -0
  848. package/plugins/workboard/dist/client.d.ts +5 -0
  849. package/plugins/workboard/dist/client.d.ts.map +1 -0
  850. package/plugins/workboard/dist/client.js +895 -0
  851. package/plugins/workboard/dist/client.js.map +1 -0
  852. package/plugins/workboard/dist/db/agents.d.ts +100 -0
  853. package/plugins/workboard/dist/db/agents.d.ts.map +1 -0
  854. package/plugins/workboard/dist/db/agents.js +280 -0
  855. package/plugins/workboard/dist/db/agents.js.map +1 -0
  856. package/plugins/workboard/dist/db/schema.d.ts +3 -0
  857. package/plugins/workboard/dist/db/schema.d.ts.map +1 -0
  858. package/plugins/workboard/dist/db/schema.js +31 -0
  859. package/plugins/workboard/dist/db/schema.js.map +1 -0
  860. package/plugins/workboard/dist/db/session-history.d.ts +28 -0
  861. package/plugins/workboard/dist/db/session-history.d.ts.map +1 -0
  862. package/plugins/workboard/dist/db/session-history.js +224 -0
  863. package/plugins/workboard/dist/db/session-history.js.map +1 -0
  864. package/plugins/workboard/dist/db/tasks.d.ts +260 -0
  865. package/plugins/workboard/dist/db/tasks.d.ts.map +1 -0
  866. package/plugins/workboard/dist/db/tasks.js +451 -0
  867. package/plugins/workboard/dist/db/tasks.js.map +1 -0
  868. package/plugins/workboard/dist/db/worker-agents.d.ts +16 -0
  869. package/plugins/workboard/dist/db/worker-agents.d.ts.map +1 -0
  870. package/plugins/workboard/dist/db/worker-agents.js +62 -0
  871. package/plugins/workboard/dist/db/worker-agents.js.map +1 -0
  872. package/plugins/workboard/dist/effective-skills.d.ts +13 -0
  873. package/plugins/workboard/dist/effective-skills.d.ts.map +1 -0
  874. package/plugins/workboard/dist/effective-skills.js +126 -0
  875. package/plugins/workboard/dist/effective-skills.js.map +1 -0
  876. package/plugins/workboard/dist/fs-worker-agents.d.ts +35 -0
  877. package/plugins/workboard/dist/fs-worker-agents.d.ts.map +1 -0
  878. package/plugins/workboard/dist/fs-worker-agents.js +199 -0
  879. package/plugins/workboard/dist/fs-worker-agents.js.map +1 -0
  880. package/plugins/workboard/dist/migrate-worker-agents.d.ts +11 -0
  881. package/plugins/workboard/dist/migrate-worker-agents.d.ts.map +1 -0
  882. package/plugins/workboard/dist/migrate-worker-agents.js +89 -0
  883. package/plugins/workboard/dist/migrate-worker-agents.js.map +1 -0
  884. package/plugins/workboard/dist/routes/handlers.d.ts +106 -0
  885. package/plugins/workboard/dist/routes/handlers.d.ts.map +1 -0
  886. package/plugins/workboard/dist/routes/handlers.js +668 -0
  887. package/plugins/workboard/dist/routes/handlers.js.map +1 -0
  888. package/plugins/workboard/dist/server.d.ts +6 -0
  889. package/plugins/workboard/dist/server.d.ts.map +1 -0
  890. package/plugins/workboard/dist/server.js +368 -0
  891. package/plugins/workboard/dist/server.js.map +1 -0
  892. package/plugins/workboard/dist/tools/index.d.ts +70 -0
  893. package/plugins/workboard/dist/tools/index.d.ts.map +1 -0
  894. package/plugins/workboard/dist/tools/index.js +963 -0
  895. package/plugins/workboard/dist/tools/index.js.map +1 -0
  896. package/plugins/workboard/dist/types.d.ts +27 -0
  897. package/plugins/workboard/dist/types.d.ts.map +1 -0
  898. package/plugins/workboard/dist/types.js +16 -0
  899. package/plugins/workboard/dist/types.js.map +1 -0
  900. package/plugins/workboard/dist/worker/pool.d.ts +220 -0
  901. package/plugins/workboard/dist/worker/pool.d.ts.map +1 -0
  902. package/plugins/workboard/dist/worker/pool.js +866 -0
  903. package/plugins/workboard/dist/worker/pool.js.map +1 -0
  904. package/plugins/workboard/dist/worker/tool-policy.d.ts +27 -0
  905. package/plugins/workboard/dist/worker/tool-policy.d.ts.map +1 -0
  906. package/plugins/workboard/dist/worker/tool-policy.js +76 -0
  907. package/plugins/workboard/dist/worker/tool-policy.js.map +1 -0
  908. package/plugins/workboard/dist/worker-agents-page.d.ts +4 -0
  909. package/plugins/workboard/dist/worker-agents-page.d.ts.map +1 -0
  910. package/plugins/workboard/dist/worker-agents-page.js +193 -0
  911. package/plugins/workboard/dist/worker-agents-page.js.map +1 -0
  912. package/plugins/workboard/manifest.json +180 -0
  913. package/plugins/workboard/package.json +37 -0
  914. package/plugins/workboard/skills/large-input-large-output.md +185 -0
  915. package/plugins/workboard/skills/workboard-howto.md +166 -0
  916. package/plugins/workboard/skills/worker-creator.md +267 -0
  917. package/plugins/workboard/skills/worker-fleet.md +431 -0
@@ -0,0 +1,4015 @@
1
+ import { equals, iterableEquality, subsetEquality, JestExtend, JestChaiExpect, JestAsymmetricMatchers, GLOBAL_EXPECT, ASYMMETRIC_MATCHERS_OBJECT, getState, setState, addCustomEqualityTesters, customMatchers } from '@vitest/expect';
2
+ import { getCurrentTest } from '@vitest/runner';
3
+ import { getNames, getTestName } from '@vitest/runner/utils';
4
+ import * as chai$1 from 'chai';
5
+ import { g as getWorkerState, a as getCurrentEnvironment, i as isChildProcess, w as waitForImportsToResolve, r as resetModules } from './utils.XdZDrNZV.js';
6
+ import { getSafeTimers, assertTypes, createSimpleStackTrace } from '@vitest/utils';
7
+ import { g as getDefaultExportFromCjs, c as commonjsGlobal } from './_commonjsHelpers.BFTU3MAI.js';
8
+ import { stripSnapshotIndentation, addSerializer, SnapshotClient } from '@vitest/snapshot';
9
+ import '@vitest/utils/error';
10
+ import { fn, spyOn, mocks, isMockFunction } from '@vitest/spy';
11
+ import { parseSingleStack } from '@vitest/utils/source-map';
12
+ import { R as RealDate, r as resetDate, m as mockDate } from './date.Bq6ZW5rf.js';
13
+
14
+ // these matchers are not supported because they don't make sense with poll
15
+ const unsupported = [
16
+ "matchSnapshot",
17
+ "toMatchSnapshot",
18
+ "toMatchInlineSnapshot",
19
+ "toThrowErrorMatchingSnapshot",
20
+ "toThrowErrorMatchingInlineSnapshot",
21
+ "throws",
22
+ "Throw",
23
+ "throw",
24
+ "toThrow",
25
+ "toThrowError"
26
+ ];
27
+ function createExpectPoll(expect) {
28
+ return function poll(fn, options = {}) {
29
+ const state = getWorkerState();
30
+ const defaults = state.config.expect?.poll ?? {};
31
+ const { interval = defaults.interval ?? 50, timeout = defaults.timeout ?? 1e3, message } = options;
32
+ // @ts-expect-error private poll access
33
+ const assertion = expect(null, message).withContext({ poll: true });
34
+ fn = fn.bind(assertion);
35
+ const test = chai$1.util.flag(assertion, "vitest-test");
36
+ if (!test) throw new Error("expect.poll() must be called inside a test");
37
+ const proxy = new Proxy(assertion, { get(target, key, receiver) {
38
+ const assertionFunction = Reflect.get(target, key, receiver);
39
+ if (typeof assertionFunction !== "function") return assertionFunction instanceof chai$1.Assertion ? proxy : assertionFunction;
40
+ if (key === "assert") return assertionFunction;
41
+ if (typeof key === "string" && unsupported.includes(key)) throw new SyntaxError(`expect.poll() is not supported in combination with .${key}(). Use vi.waitFor() if your assertion condition is unstable.`);
42
+ return function(...args) {
43
+ const STACK_TRACE_ERROR = new Error("STACK_TRACE_ERROR");
44
+ const promise = () => new Promise((resolve, reject) => {
45
+ let intervalId;
46
+ let timeoutId;
47
+ let lastError;
48
+ const { setTimeout, clearTimeout } = getSafeTimers();
49
+ const check = async () => {
50
+ try {
51
+ chai$1.util.flag(assertion, "_name", key);
52
+ const obj = await fn();
53
+ chai$1.util.flag(assertion, "object", obj);
54
+ resolve(await assertionFunction.call(assertion, ...args));
55
+ clearTimeout(intervalId);
56
+ clearTimeout(timeoutId);
57
+ } catch (err) {
58
+ lastError = err;
59
+ if (!chai$1.util.flag(assertion, "_isLastPollAttempt")) intervalId = setTimeout(check, interval);
60
+ }
61
+ };
62
+ timeoutId = setTimeout(() => {
63
+ clearTimeout(intervalId);
64
+ chai$1.util.flag(assertion, "_isLastPollAttempt", true);
65
+ const rejectWithCause = (cause) => {
66
+ reject(copyStackTrace$1(new Error("Matcher did not succeed in time.", { cause }), STACK_TRACE_ERROR));
67
+ };
68
+ check().then(() => rejectWithCause(lastError)).catch((e) => rejectWithCause(e));
69
+ }, timeout);
70
+ check();
71
+ });
72
+ let awaited = false;
73
+ test.onFinished ??= [];
74
+ test.onFinished.push(() => {
75
+ if (!awaited) {
76
+ const negated = chai$1.util.flag(assertion, "negate") ? "not." : "";
77
+ const name = chai$1.util.flag(assertion, "_poll.element") ? "element(locator)" : "poll(assertion)";
78
+ const assertionString = `expect.${name}.${negated}${String(key)}()`;
79
+ const error = new Error(`${assertionString} was not awaited. This assertion is asynchronous and must be awaited; otherwise, it is not executed to avoid unhandled rejections:\n\nawait ${assertionString}\n`);
80
+ throw copyStackTrace$1(error, STACK_TRACE_ERROR);
81
+ }
82
+ });
83
+ let resultPromise;
84
+ // only .then is enough to check awaited, but we type this as `Promise<void>` in global types
85
+ // so let's follow it
86
+ return {
87
+ then(onFulfilled, onRejected) {
88
+ awaited = true;
89
+ return (resultPromise ||= promise()).then(onFulfilled, onRejected);
90
+ },
91
+ catch(onRejected) {
92
+ return (resultPromise ||= promise()).catch(onRejected);
93
+ },
94
+ finally(onFinally) {
95
+ return (resultPromise ||= promise()).finally(onFinally);
96
+ },
97
+ [Symbol.toStringTag]: "Promise"
98
+ };
99
+ };
100
+ } });
101
+ return proxy;
102
+ };
103
+ }
104
+ function copyStackTrace$1(target, source) {
105
+ if (source.stack !== void 0) target.stack = source.stack.replace(source.message, target.message);
106
+ return target;
107
+ }
108
+
109
+ function commonjsRequire(path) {
110
+ throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
111
+ }
112
+
113
+ var chaiSubset$1 = {exports: {}};
114
+
115
+ var chaiSubset = chaiSubset$1.exports;
116
+
117
+ var hasRequiredChaiSubset;
118
+
119
+ function requireChaiSubset () {
120
+ if (hasRequiredChaiSubset) return chaiSubset$1.exports;
121
+ hasRequiredChaiSubset = 1;
122
+ (function (module, exports) {
123
+ (function() {
124
+ (function(chaiSubset) {
125
+ if (typeof commonjsRequire === 'function' && 'object' === 'object' && 'object' === 'object') {
126
+ return module.exports = chaiSubset;
127
+ } else {
128
+ return chai.use(chaiSubset);
129
+ }
130
+ })(function(chai, utils) {
131
+ var Assertion = chai.Assertion;
132
+ var assertionPrototype = Assertion.prototype;
133
+
134
+ Assertion.addMethod('containSubset', function (expected) {
135
+ var actual = utils.flag(this, 'object');
136
+ var showDiff = chai.config.showDiff;
137
+
138
+ assertionPrototype.assert.call(this,
139
+ compare(expected, actual),
140
+ 'expected #{act} to contain subset #{exp}',
141
+ 'expected #{act} to not contain subset #{exp}',
142
+ expected,
143
+ actual,
144
+ showDiff
145
+ );
146
+ });
147
+
148
+ chai.assert.containSubset = function(val, exp, msg) {
149
+ new chai.Assertion(val, msg).to.be.containSubset(exp);
150
+ };
151
+
152
+ function compare(expected, actual) {
153
+ if (expected === actual) {
154
+ return true;
155
+ }
156
+ if (typeof(actual) !== typeof(expected)) {
157
+ return false;
158
+ }
159
+ if (typeof(expected) !== 'object' || expected === null) {
160
+ return expected === actual;
161
+ }
162
+ if (!!expected && !actual) {
163
+ return false;
164
+ }
165
+
166
+ if (Array.isArray(expected)) {
167
+ if (typeof(actual.length) !== 'number') {
168
+ return false;
169
+ }
170
+ var aa = Array.prototype.slice.call(actual);
171
+ return expected.every(function (exp) {
172
+ return aa.some(function (act) {
173
+ return compare(exp, act);
174
+ });
175
+ });
176
+ }
177
+
178
+ if (expected instanceof Date) {
179
+ if (actual instanceof Date) {
180
+ return expected.getTime() === actual.getTime();
181
+ } else {
182
+ return false;
183
+ }
184
+ }
185
+
186
+ return Object.keys(expected).every(function (key) {
187
+ var eo = expected[key];
188
+ var ao = actual[key];
189
+ if (typeof(eo) === 'object' && eo !== null && ao !== null) {
190
+ return compare(eo, ao);
191
+ }
192
+ if (typeof(eo) === 'function') {
193
+ return eo(ao);
194
+ }
195
+ return ao === eo;
196
+ });
197
+ }
198
+ });
199
+
200
+ }).call(chaiSubset);
201
+ } (chaiSubset$1));
202
+ return chaiSubset$1.exports;
203
+ }
204
+
205
+ var chaiSubsetExports = requireChaiSubset();
206
+ var Subset = /*@__PURE__*/getDefaultExportFromCjs(chaiSubsetExports);
207
+
208
+ function createAssertionMessage(util, assertion, hasArgs) {
209
+ const not = util.flag(assertion, "negate") ? "not." : "";
210
+ const name = `${util.flag(assertion, "_name")}(${"expected" })`;
211
+ const promiseName = util.flag(assertion, "promise");
212
+ const promise = promiseName ? `.${promiseName}` : "";
213
+ return `expect(actual)${promise}.${not}${name}`;
214
+ }
215
+ function recordAsyncExpect(_test, promise, assertion, error) {
216
+ const test = _test;
217
+ // record promise for test, that resolves before test ends
218
+ if (test && promise instanceof Promise) {
219
+ // if promise is explicitly awaited, remove it from the list
220
+ promise = promise.finally(() => {
221
+ if (!test.promises) return;
222
+ const index = test.promises.indexOf(promise);
223
+ if (index !== -1) test.promises.splice(index, 1);
224
+ });
225
+ // record promise
226
+ if (!test.promises) test.promises = [];
227
+ test.promises.push(promise);
228
+ let resolved = false;
229
+ test.onFinished ??= [];
230
+ test.onFinished.push(() => {
231
+ if (!resolved) {
232
+ const processor = globalThis.__vitest_worker__?.onFilterStackTrace || ((s) => s || "");
233
+ const stack = processor(error.stack);
234
+ console.warn([
235
+ `Promise returned by \`${assertion}\` was not awaited. `,
236
+ "Vitest currently auto-awaits hanging assertions at the end of the test, but this will cause the test to fail in Vitest 3. ",
237
+ "Please remember to await the assertion.\n",
238
+ stack
239
+ ].join(""));
240
+ }
241
+ });
242
+ return {
243
+ then(onFulfilled, onRejected) {
244
+ resolved = true;
245
+ return promise.then(onFulfilled, onRejected);
246
+ },
247
+ catch(onRejected) {
248
+ return promise.catch(onRejected);
249
+ },
250
+ finally(onFinally) {
251
+ return promise.finally(onFinally);
252
+ },
253
+ [Symbol.toStringTag]: "Promise"
254
+ };
255
+ }
256
+ return promise;
257
+ }
258
+
259
+ let _client;
260
+ function getSnapshotClient() {
261
+ if (!_client) _client = new SnapshotClient({ isEqual: (received, expected) => {
262
+ return equals(received, expected, [iterableEquality, subsetEquality]);
263
+ } });
264
+ return _client;
265
+ }
266
+ function getError(expected, promise) {
267
+ if (typeof expected !== "function") {
268
+ if (!promise) throw new Error(`expected must be a function, received ${typeof expected}`);
269
+ // when "promised", it receives thrown error
270
+ return expected;
271
+ }
272
+ try {
273
+ expected();
274
+ } catch (e) {
275
+ return e;
276
+ }
277
+ throw new Error("snapshot function didn't throw");
278
+ }
279
+ function getTestNames(test) {
280
+ return {
281
+ filepath: test.file.filepath,
282
+ name: getNames(test).slice(1).join(" > "),
283
+ testId: test.id
284
+ };
285
+ }
286
+ const SnapshotPlugin = (chai, utils) => {
287
+ function getTest(assertionName, obj) {
288
+ const test = utils.flag(obj, "vitest-test");
289
+ if (!test) throw new Error(`'${assertionName}' cannot be used without test context`);
290
+ return test;
291
+ }
292
+ for (const key of ["matchSnapshot", "toMatchSnapshot"]) utils.addMethod(chai.Assertion.prototype, key, function(properties, message) {
293
+ utils.flag(this, "_name", key);
294
+ const isNot = utils.flag(this, "negate");
295
+ if (isNot) throw new Error(`${key} cannot be used with "not"`);
296
+ const expected = utils.flag(this, "object");
297
+ const test = getTest(key, this);
298
+ if (typeof properties === "string" && typeof message === "undefined") {
299
+ message = properties;
300
+ properties = void 0;
301
+ }
302
+ const errorMessage = utils.flag(this, "message");
303
+ getSnapshotClient().assert({
304
+ received: expected,
305
+ message,
306
+ isInline: false,
307
+ properties,
308
+ errorMessage,
309
+ ...getTestNames(test)
310
+ });
311
+ });
312
+ utils.addMethod(chai.Assertion.prototype, "toMatchFileSnapshot", function(file, message) {
313
+ utils.flag(this, "_name", "toMatchFileSnapshot");
314
+ const isNot = utils.flag(this, "negate");
315
+ if (isNot) throw new Error("toMatchFileSnapshot cannot be used with \"not\"");
316
+ const error = new Error("resolves");
317
+ const expected = utils.flag(this, "object");
318
+ const test = getTest("toMatchFileSnapshot", this);
319
+ const errorMessage = utils.flag(this, "message");
320
+ const promise = getSnapshotClient().assertRaw({
321
+ received: expected,
322
+ message,
323
+ isInline: false,
324
+ rawSnapshot: { file },
325
+ errorMessage,
326
+ ...getTestNames(test)
327
+ });
328
+ return recordAsyncExpect(test, promise, createAssertionMessage(utils, this), error);
329
+ });
330
+ utils.addMethod(chai.Assertion.prototype, "toMatchInlineSnapshot", function __INLINE_SNAPSHOT__(properties, inlineSnapshot, message) {
331
+ utils.flag(this, "_name", "toMatchInlineSnapshot");
332
+ const isNot = utils.flag(this, "negate");
333
+ if (isNot) throw new Error("toMatchInlineSnapshot cannot be used with \"not\"");
334
+ const test = getTest("toMatchInlineSnapshot", this);
335
+ const isInsideEach = test.each || test.suite?.each;
336
+ if (isInsideEach) throw new Error("InlineSnapshot cannot be used inside of test.each or describe.each");
337
+ const expected = utils.flag(this, "object");
338
+ const error = utils.flag(this, "error");
339
+ if (typeof properties === "string") {
340
+ message = inlineSnapshot;
341
+ inlineSnapshot = properties;
342
+ properties = void 0;
343
+ }
344
+ if (inlineSnapshot) inlineSnapshot = stripSnapshotIndentation(inlineSnapshot);
345
+ const errorMessage = utils.flag(this, "message");
346
+ getSnapshotClient().assert({
347
+ received: expected,
348
+ message,
349
+ isInline: true,
350
+ properties,
351
+ inlineSnapshot,
352
+ error,
353
+ errorMessage,
354
+ ...getTestNames(test)
355
+ });
356
+ });
357
+ utils.addMethod(chai.Assertion.prototype, "toThrowErrorMatchingSnapshot", function(message) {
358
+ utils.flag(this, "_name", "toThrowErrorMatchingSnapshot");
359
+ const isNot = utils.flag(this, "negate");
360
+ if (isNot) throw new Error("toThrowErrorMatchingSnapshot cannot be used with \"not\"");
361
+ const expected = utils.flag(this, "object");
362
+ const test = getTest("toThrowErrorMatchingSnapshot", this);
363
+ const promise = utils.flag(this, "promise");
364
+ const errorMessage = utils.flag(this, "message");
365
+ getSnapshotClient().assert({
366
+ received: getError(expected, promise),
367
+ message,
368
+ errorMessage,
369
+ ...getTestNames(test)
370
+ });
371
+ });
372
+ utils.addMethod(chai.Assertion.prototype, "toThrowErrorMatchingInlineSnapshot", function __INLINE_SNAPSHOT__(inlineSnapshot, message) {
373
+ const isNot = utils.flag(this, "negate");
374
+ if (isNot) throw new Error("toThrowErrorMatchingInlineSnapshot cannot be used with \"not\"");
375
+ const test = getTest("toThrowErrorMatchingInlineSnapshot", this);
376
+ const isInsideEach = test.each || test.suite?.each;
377
+ if (isInsideEach) throw new Error("InlineSnapshot cannot be used inside of test.each or describe.each");
378
+ const expected = utils.flag(this, "object");
379
+ const error = utils.flag(this, "error");
380
+ const promise = utils.flag(this, "promise");
381
+ const errorMessage = utils.flag(this, "message");
382
+ if (inlineSnapshot) inlineSnapshot = stripSnapshotIndentation(inlineSnapshot);
383
+ getSnapshotClient().assert({
384
+ received: getError(expected, promise),
385
+ message,
386
+ inlineSnapshot,
387
+ isInline: true,
388
+ error,
389
+ errorMessage,
390
+ ...getTestNames(test)
391
+ });
392
+ });
393
+ utils.addMethod(chai.expect, "addSnapshotSerializer", addSerializer);
394
+ };
395
+
396
+ chai$1.use(JestExtend);
397
+ chai$1.use(JestChaiExpect);
398
+ chai$1.use(Subset);
399
+ chai$1.use(SnapshotPlugin);
400
+ chai$1.use(JestAsymmetricMatchers);
401
+
402
+ function createExpect(test) {
403
+ const expect = (value, message) => {
404
+ const { assertionCalls } = getState(expect);
405
+ setState({ assertionCalls: assertionCalls + 1 }, expect);
406
+ const assert = chai$1.expect(value, message);
407
+ const _test = test || getCurrentTest();
408
+ if (_test)
409
+ // @ts-expect-error internal
410
+ return assert.withTest(_test);
411
+ else return assert;
412
+ };
413
+ Object.assign(expect, chai$1.expect);
414
+ Object.assign(expect, globalThis[ASYMMETRIC_MATCHERS_OBJECT]);
415
+ expect.getState = () => getState(expect);
416
+ expect.setState = (state) => setState(state, expect);
417
+ // @ts-expect-error global is not typed
418
+ const globalState = getState(globalThis[GLOBAL_EXPECT]) || {};
419
+ setState({
420
+ ...globalState,
421
+ assertionCalls: 0,
422
+ isExpectingAssertions: false,
423
+ isExpectingAssertionsError: null,
424
+ expectedAssertionsNumber: null,
425
+ expectedAssertionsNumberErrorGen: null,
426
+ environment: getCurrentEnvironment(),
427
+ get testPath() {
428
+ return getWorkerState().filepath;
429
+ },
430
+ currentTestName: test ? getTestName(test) : globalState.currentTestName
431
+ }, expect);
432
+ // @ts-expect-error untyped
433
+ expect.extend = (matchers) => chai$1.expect.extend(expect, matchers);
434
+ expect.addEqualityTesters = (customTesters) => addCustomEqualityTesters(customTesters);
435
+ expect.soft = (...args) => {
436
+ // @ts-expect-error private soft access
437
+ return expect(...args).withContext({ soft: true });
438
+ };
439
+ expect.poll = createExpectPoll(expect);
440
+ expect.unreachable = (message) => {
441
+ chai$1.assert.fail(`expected${message ? ` "${message}" ` : " "}not to be reached`);
442
+ };
443
+ function assertions(expected) {
444
+ const errorGen = () => new Error(`expected number of assertions to be ${expected}, but got ${expect.getState().assertionCalls}`);
445
+ if (Error.captureStackTrace) Error.captureStackTrace(errorGen(), assertions);
446
+ expect.setState({
447
+ expectedAssertionsNumber: expected,
448
+ expectedAssertionsNumberErrorGen: errorGen
449
+ });
450
+ }
451
+ function hasAssertions() {
452
+ const error = new Error("expected any number of assertion, but got none");
453
+ if (Error.captureStackTrace) Error.captureStackTrace(error, hasAssertions);
454
+ expect.setState({
455
+ isExpectingAssertions: true,
456
+ isExpectingAssertionsError: error
457
+ });
458
+ }
459
+ chai$1.util.addMethod(expect, "assertions", assertions);
460
+ chai$1.util.addMethod(expect, "hasAssertions", hasAssertions);
461
+ expect.extend(customMatchers);
462
+ return expect;
463
+ }
464
+ const globalExpect = createExpect();
465
+ Object.defineProperty(globalThis, GLOBAL_EXPECT, {
466
+ value: globalExpect,
467
+ writable: true,
468
+ configurable: true
469
+ });
470
+
471
+ /**
472
+ * Gives access to injected context provided from the main thread.
473
+ * This usually returns a value provided by `globalSetup` or an external library.
474
+ */
475
+ function inject(key) {
476
+ const workerState = getWorkerState();
477
+ return workerState.providedContext[key];
478
+ }
479
+
480
+ var fakeTimersSrc = {};
481
+
482
+ var global;
483
+ var hasRequiredGlobal;
484
+
485
+ function requireGlobal () {
486
+ if (hasRequiredGlobal) return global;
487
+ hasRequiredGlobal = 1;
488
+
489
+ /**
490
+ * A reference to the global object
491
+ * @type {object} globalObject
492
+ */
493
+ var globalObject;
494
+
495
+ /* istanbul ignore else */
496
+ if (typeof commonjsGlobal !== "undefined") {
497
+ // Node
498
+ globalObject = commonjsGlobal;
499
+ } else if (typeof window !== "undefined") {
500
+ // Browser
501
+ globalObject = window;
502
+ } else {
503
+ // WebWorker
504
+ globalObject = self;
505
+ }
506
+
507
+ global = globalObject;
508
+ return global;
509
+ }
510
+
511
+ var throwsOnProto_1;
512
+ var hasRequiredThrowsOnProto;
513
+
514
+ function requireThrowsOnProto () {
515
+ if (hasRequiredThrowsOnProto) return throwsOnProto_1;
516
+ hasRequiredThrowsOnProto = 1;
517
+
518
+ /**
519
+ * Is true when the environment causes an error to be thrown for accessing the
520
+ * __proto__ property.
521
+ * This is necessary in order to support `node --disable-proto=throw`.
522
+ *
523
+ * See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/proto
524
+ * @type {boolean}
525
+ */
526
+ let throwsOnProto;
527
+ try {
528
+ const object = {};
529
+ // eslint-disable-next-line no-proto, no-unused-expressions
530
+ object.__proto__;
531
+ throwsOnProto = false;
532
+ } catch (_) {
533
+ // This branch is covered when tests are run with `--disable-proto=throw`,
534
+ // however we can test both branches at the same time, so this is ignored
535
+ /* istanbul ignore next */
536
+ throwsOnProto = true;
537
+ }
538
+
539
+ throwsOnProto_1 = throwsOnProto;
540
+ return throwsOnProto_1;
541
+ }
542
+
543
+ var copyPrototypeMethods;
544
+ var hasRequiredCopyPrototypeMethods;
545
+
546
+ function requireCopyPrototypeMethods () {
547
+ if (hasRequiredCopyPrototypeMethods) return copyPrototypeMethods;
548
+ hasRequiredCopyPrototypeMethods = 1;
549
+
550
+ var call = Function.call;
551
+ var throwsOnProto = requireThrowsOnProto();
552
+
553
+ var disallowedProperties = [
554
+ // ignore size because it throws from Map
555
+ "size",
556
+ "caller",
557
+ "callee",
558
+ "arguments",
559
+ ];
560
+
561
+ // This branch is covered when tests are run with `--disable-proto=throw`,
562
+ // however we can test both branches at the same time, so this is ignored
563
+ /* istanbul ignore next */
564
+ if (throwsOnProto) {
565
+ disallowedProperties.push("__proto__");
566
+ }
567
+
568
+ copyPrototypeMethods = function copyPrototypeMethods(prototype) {
569
+ // eslint-disable-next-line @sinonjs/no-prototype-methods/no-prototype-methods
570
+ return Object.getOwnPropertyNames(prototype).reduce(function (
571
+ result,
572
+ name
573
+ ) {
574
+ if (disallowedProperties.includes(name)) {
575
+ return result;
576
+ }
577
+
578
+ if (typeof prototype[name] !== "function") {
579
+ return result;
580
+ }
581
+
582
+ result[name] = call.bind(prototype[name]);
583
+
584
+ return result;
585
+ },
586
+ Object.create(null));
587
+ };
588
+ return copyPrototypeMethods;
589
+ }
590
+
591
+ var array;
592
+ var hasRequiredArray;
593
+
594
+ function requireArray () {
595
+ if (hasRequiredArray) return array;
596
+ hasRequiredArray = 1;
597
+
598
+ var copyPrototype = requireCopyPrototypeMethods();
599
+
600
+ array = copyPrototype(Array.prototype);
601
+ return array;
602
+ }
603
+
604
+ var calledInOrder_1;
605
+ var hasRequiredCalledInOrder;
606
+
607
+ function requireCalledInOrder () {
608
+ if (hasRequiredCalledInOrder) return calledInOrder_1;
609
+ hasRequiredCalledInOrder = 1;
610
+
611
+ var every = requireArray().every;
612
+
613
+ /**
614
+ * @private
615
+ */
616
+ function hasCallsLeft(callMap, spy) {
617
+ if (callMap[spy.id] === undefined) {
618
+ callMap[spy.id] = 0;
619
+ }
620
+
621
+ return callMap[spy.id] < spy.callCount;
622
+ }
623
+
624
+ /**
625
+ * @private
626
+ */
627
+ function checkAdjacentCalls(callMap, spy, index, spies) {
628
+ var calledBeforeNext = true;
629
+
630
+ if (index !== spies.length - 1) {
631
+ calledBeforeNext = spy.calledBefore(spies[index + 1]);
632
+ }
633
+
634
+ if (hasCallsLeft(callMap, spy) && calledBeforeNext) {
635
+ callMap[spy.id] += 1;
636
+ return true;
637
+ }
638
+
639
+ return false;
640
+ }
641
+
642
+ /**
643
+ * A Sinon proxy object (fake, spy, stub)
644
+ * @typedef {object} SinonProxy
645
+ * @property {Function} calledBefore - A method that determines if this proxy was called before another one
646
+ * @property {string} id - Some id
647
+ * @property {number} callCount - Number of times this proxy has been called
648
+ */
649
+
650
+ /**
651
+ * Returns true when the spies have been called in the order they were supplied in
652
+ * @param {SinonProxy[] | SinonProxy} spies An array of proxies, or several proxies as arguments
653
+ * @returns {boolean} true when spies are called in order, false otherwise
654
+ */
655
+ function calledInOrder(spies) {
656
+ var callMap = {};
657
+ // eslint-disable-next-line no-underscore-dangle
658
+ var _spies = arguments.length > 1 ? arguments : spies;
659
+
660
+ return every(_spies, checkAdjacentCalls.bind(null, callMap));
661
+ }
662
+
663
+ calledInOrder_1 = calledInOrder;
664
+ return calledInOrder_1;
665
+ }
666
+
667
+ var className_1;
668
+ var hasRequiredClassName;
669
+
670
+ function requireClassName () {
671
+ if (hasRequiredClassName) return className_1;
672
+ hasRequiredClassName = 1;
673
+
674
+ /**
675
+ * Returns a display name for a value from a constructor
676
+ * @param {object} value A value to examine
677
+ * @returns {(string|null)} A string or null
678
+ */
679
+ function className(value) {
680
+ const name = value.constructor && value.constructor.name;
681
+ return name || null;
682
+ }
683
+
684
+ className_1 = className;
685
+ return className_1;
686
+ }
687
+
688
+ var deprecated = {};
689
+
690
+ /* eslint-disable no-console */
691
+
692
+ var hasRequiredDeprecated;
693
+
694
+ function requireDeprecated () {
695
+ if (hasRequiredDeprecated) return deprecated;
696
+ hasRequiredDeprecated = 1;
697
+ (function (exports) {
698
+
699
+ /**
700
+ * Returns a function that will invoke the supplied function and print a
701
+ * deprecation warning to the console each time it is called.
702
+ * @param {Function} func
703
+ * @param {string} msg
704
+ * @returns {Function}
705
+ */
706
+ exports.wrap = function (func, msg) {
707
+ var wrapped = function () {
708
+ exports.printWarning(msg);
709
+ return func.apply(this, arguments);
710
+ };
711
+ if (func.prototype) {
712
+ wrapped.prototype = func.prototype;
713
+ }
714
+ return wrapped;
715
+ };
716
+
717
+ /**
718
+ * Returns a string which can be supplied to `wrap()` to notify the user that a
719
+ * particular part of the sinon API has been deprecated.
720
+ * @param {string} packageName
721
+ * @param {string} funcName
722
+ * @returns {string}
723
+ */
724
+ exports.defaultMsg = function (packageName, funcName) {
725
+ return `${packageName}.${funcName} is deprecated and will be removed from the public API in a future version of ${packageName}.`;
726
+ };
727
+
728
+ /**
729
+ * Prints a warning on the console, when it exists
730
+ * @param {string} msg
731
+ * @returns {undefined}
732
+ */
733
+ exports.printWarning = function (msg) {
734
+ /* istanbul ignore next */
735
+ if (typeof process === "object" && process.emitWarning) {
736
+ // Emit Warnings in Node
737
+ process.emitWarning(msg);
738
+ } else if (console.info) {
739
+ console.info(msg);
740
+ } else {
741
+ console.log(msg);
742
+ }
743
+ };
744
+ } (deprecated));
745
+ return deprecated;
746
+ }
747
+
748
+ var every;
749
+ var hasRequiredEvery;
750
+
751
+ function requireEvery () {
752
+ if (hasRequiredEvery) return every;
753
+ hasRequiredEvery = 1;
754
+
755
+ /**
756
+ * Returns true when fn returns true for all members of obj.
757
+ * This is an every implementation that works for all iterables
758
+ * @param {object} obj
759
+ * @param {Function} fn
760
+ * @returns {boolean}
761
+ */
762
+ every = function every(obj, fn) {
763
+ var pass = true;
764
+
765
+ try {
766
+ // eslint-disable-next-line @sinonjs/no-prototype-methods/no-prototype-methods
767
+ obj.forEach(function () {
768
+ if (!fn.apply(this, arguments)) {
769
+ // Throwing an error is the only way to break `forEach`
770
+ throw new Error();
771
+ }
772
+ });
773
+ } catch (e) {
774
+ pass = false;
775
+ }
776
+
777
+ return pass;
778
+ };
779
+ return every;
780
+ }
781
+
782
+ var functionName;
783
+ var hasRequiredFunctionName;
784
+
785
+ function requireFunctionName () {
786
+ if (hasRequiredFunctionName) return functionName;
787
+ hasRequiredFunctionName = 1;
788
+
789
+ /**
790
+ * Returns a display name for a function
791
+ * @param {Function} func
792
+ * @returns {string}
793
+ */
794
+ functionName = function functionName(func) {
795
+ if (!func) {
796
+ return "";
797
+ }
798
+
799
+ try {
800
+ return (
801
+ func.displayName ||
802
+ func.name ||
803
+ // Use function decomposition as a last resort to get function
804
+ // name. Does not rely on function decomposition to work - if it
805
+ // doesn't debugging will be slightly less informative
806
+ // (i.e. toString will say 'spy' rather than 'myFunc').
807
+ (String(func).match(/function ([^\s(]+)/) || [])[1]
808
+ );
809
+ } catch (e) {
810
+ // Stringify may fail and we might get an exception, as a last-last
811
+ // resort fall back to empty string.
812
+ return "";
813
+ }
814
+ };
815
+ return functionName;
816
+ }
817
+
818
+ var orderByFirstCall_1;
819
+ var hasRequiredOrderByFirstCall;
820
+
821
+ function requireOrderByFirstCall () {
822
+ if (hasRequiredOrderByFirstCall) return orderByFirstCall_1;
823
+ hasRequiredOrderByFirstCall = 1;
824
+
825
+ var sort = requireArray().sort;
826
+ var slice = requireArray().slice;
827
+
828
+ /**
829
+ * @private
830
+ */
831
+ function comparator(a, b) {
832
+ // uuid, won't ever be equal
833
+ var aCall = a.getCall(0);
834
+ var bCall = b.getCall(0);
835
+ var aId = (aCall && aCall.callId) || -1;
836
+ var bId = (bCall && bCall.callId) || -1;
837
+
838
+ return aId < bId ? -1 : 1;
839
+ }
840
+
841
+ /**
842
+ * A Sinon proxy object (fake, spy, stub)
843
+ * @typedef {object} SinonProxy
844
+ * @property {Function} getCall - A method that can return the first call
845
+ */
846
+
847
+ /**
848
+ * Sorts an array of SinonProxy instances (fake, spy, stub) by their first call
849
+ * @param {SinonProxy[] | SinonProxy} spies
850
+ * @returns {SinonProxy[]}
851
+ */
852
+ function orderByFirstCall(spies) {
853
+ return sort(slice(spies), comparator);
854
+ }
855
+
856
+ orderByFirstCall_1 = orderByFirstCall;
857
+ return orderByFirstCall_1;
858
+ }
859
+
860
+ var _function;
861
+ var hasRequired_function;
862
+
863
+ function require_function () {
864
+ if (hasRequired_function) return _function;
865
+ hasRequired_function = 1;
866
+
867
+ var copyPrototype = requireCopyPrototypeMethods();
868
+
869
+ _function = copyPrototype(Function.prototype);
870
+ return _function;
871
+ }
872
+
873
+ var map;
874
+ var hasRequiredMap;
875
+
876
+ function requireMap () {
877
+ if (hasRequiredMap) return map;
878
+ hasRequiredMap = 1;
879
+
880
+ var copyPrototype = requireCopyPrototypeMethods();
881
+
882
+ map = copyPrototype(Map.prototype);
883
+ return map;
884
+ }
885
+
886
+ var object;
887
+ var hasRequiredObject;
888
+
889
+ function requireObject () {
890
+ if (hasRequiredObject) return object;
891
+ hasRequiredObject = 1;
892
+
893
+ var copyPrototype = requireCopyPrototypeMethods();
894
+
895
+ object = copyPrototype(Object.prototype);
896
+ return object;
897
+ }
898
+
899
+ var set;
900
+ var hasRequiredSet;
901
+
902
+ function requireSet () {
903
+ if (hasRequiredSet) return set;
904
+ hasRequiredSet = 1;
905
+
906
+ var copyPrototype = requireCopyPrototypeMethods();
907
+
908
+ set = copyPrototype(Set.prototype);
909
+ return set;
910
+ }
911
+
912
+ var string;
913
+ var hasRequiredString;
914
+
915
+ function requireString () {
916
+ if (hasRequiredString) return string;
917
+ hasRequiredString = 1;
918
+
919
+ var copyPrototype = requireCopyPrototypeMethods();
920
+
921
+ string = copyPrototype(String.prototype);
922
+ return string;
923
+ }
924
+
925
+ var prototypes;
926
+ var hasRequiredPrototypes;
927
+
928
+ function requirePrototypes () {
929
+ if (hasRequiredPrototypes) return prototypes;
930
+ hasRequiredPrototypes = 1;
931
+
932
+ prototypes = {
933
+ array: requireArray(),
934
+ function: require_function(),
935
+ map: requireMap(),
936
+ object: requireObject(),
937
+ set: requireSet(),
938
+ string: requireString(),
939
+ };
940
+ return prototypes;
941
+ }
942
+
943
+ var typeDetect$1 = {exports: {}};
944
+
945
+ var typeDetect = typeDetect$1.exports;
946
+
947
+ var hasRequiredTypeDetect;
948
+
949
+ function requireTypeDetect () {
950
+ if (hasRequiredTypeDetect) return typeDetect$1.exports;
951
+ hasRequiredTypeDetect = 1;
952
+ (function (module, exports) {
953
+ (function (global, factory) {
954
+ module.exports = factory() ;
955
+ }(typeDetect, (function () {
956
+ /* !
957
+ * type-detect
958
+ * Copyright(c) 2013 jake luer <jake@alogicalparadox.com>
959
+ * MIT Licensed
960
+ */
961
+ var promiseExists = typeof Promise === 'function';
962
+
963
+ /* eslint-disable no-undef */
964
+ var globalObject = typeof self === 'object' ? self : commonjsGlobal; // eslint-disable-line id-blacklist
965
+
966
+ var symbolExists = typeof Symbol !== 'undefined';
967
+ var mapExists = typeof Map !== 'undefined';
968
+ var setExists = typeof Set !== 'undefined';
969
+ var weakMapExists = typeof WeakMap !== 'undefined';
970
+ var weakSetExists = typeof WeakSet !== 'undefined';
971
+ var dataViewExists = typeof DataView !== 'undefined';
972
+ var symbolIteratorExists = symbolExists && typeof Symbol.iterator !== 'undefined';
973
+ var symbolToStringTagExists = symbolExists && typeof Symbol.toStringTag !== 'undefined';
974
+ var setEntriesExists = setExists && typeof Set.prototype.entries === 'function';
975
+ var mapEntriesExists = mapExists && typeof Map.prototype.entries === 'function';
976
+ var setIteratorPrototype = setEntriesExists && Object.getPrototypeOf(new Set().entries());
977
+ var mapIteratorPrototype = mapEntriesExists && Object.getPrototypeOf(new Map().entries());
978
+ var arrayIteratorExists = symbolIteratorExists && typeof Array.prototype[Symbol.iterator] === 'function';
979
+ var arrayIteratorPrototype = arrayIteratorExists && Object.getPrototypeOf([][Symbol.iterator]());
980
+ var stringIteratorExists = symbolIteratorExists && typeof String.prototype[Symbol.iterator] === 'function';
981
+ var stringIteratorPrototype = stringIteratorExists && Object.getPrototypeOf(''[Symbol.iterator]());
982
+ var toStringLeftSliceLength = 8;
983
+ var toStringRightSliceLength = -1;
984
+ /**
985
+ * ### typeOf (obj)
986
+ *
987
+ * Uses `Object.prototype.toString` to determine the type of an object,
988
+ * normalising behaviour across engine versions & well optimised.
989
+ *
990
+ * @param {Mixed} object
991
+ * @return {String} object type
992
+ * @api public
993
+ */
994
+ function typeDetect(obj) {
995
+ /* ! Speed optimisation
996
+ * Pre:
997
+ * string literal x 3,039,035 ops/sec ±1.62% (78 runs sampled)
998
+ * boolean literal x 1,424,138 ops/sec ±4.54% (75 runs sampled)
999
+ * number literal x 1,653,153 ops/sec ±1.91% (82 runs sampled)
1000
+ * undefined x 9,978,660 ops/sec ±1.92% (75 runs sampled)
1001
+ * function x 2,556,769 ops/sec ±1.73% (77 runs sampled)
1002
+ * Post:
1003
+ * string literal x 38,564,796 ops/sec ±1.15% (79 runs sampled)
1004
+ * boolean literal x 31,148,940 ops/sec ±1.10% (79 runs sampled)
1005
+ * number literal x 32,679,330 ops/sec ±1.90% (78 runs sampled)
1006
+ * undefined x 32,363,368 ops/sec ±1.07% (82 runs sampled)
1007
+ * function x 31,296,870 ops/sec ±0.96% (83 runs sampled)
1008
+ */
1009
+ var typeofObj = typeof obj;
1010
+ if (typeofObj !== 'object') {
1011
+ return typeofObj;
1012
+ }
1013
+
1014
+ /* ! Speed optimisation
1015
+ * Pre:
1016
+ * null x 28,645,765 ops/sec ±1.17% (82 runs sampled)
1017
+ * Post:
1018
+ * null x 36,428,962 ops/sec ±1.37% (84 runs sampled)
1019
+ */
1020
+ if (obj === null) {
1021
+ return 'null';
1022
+ }
1023
+
1024
+ /* ! Spec Conformance
1025
+ * Test: `Object.prototype.toString.call(window)``
1026
+ * - Node === "[object global]"
1027
+ * - Chrome === "[object global]"
1028
+ * - Firefox === "[object Window]"
1029
+ * - PhantomJS === "[object Window]"
1030
+ * - Safari === "[object Window]"
1031
+ * - IE 11 === "[object Window]"
1032
+ * - IE Edge === "[object Window]"
1033
+ * Test: `Object.prototype.toString.call(this)``
1034
+ * - Chrome Worker === "[object global]"
1035
+ * - Firefox Worker === "[object DedicatedWorkerGlobalScope]"
1036
+ * - Safari Worker === "[object DedicatedWorkerGlobalScope]"
1037
+ * - IE 11 Worker === "[object WorkerGlobalScope]"
1038
+ * - IE Edge Worker === "[object WorkerGlobalScope]"
1039
+ */
1040
+ if (obj === globalObject) {
1041
+ return 'global';
1042
+ }
1043
+
1044
+ /* ! Speed optimisation
1045
+ * Pre:
1046
+ * array literal x 2,888,352 ops/sec ±0.67% (82 runs sampled)
1047
+ * Post:
1048
+ * array literal x 22,479,650 ops/sec ±0.96% (81 runs sampled)
1049
+ */
1050
+ if (
1051
+ Array.isArray(obj) &&
1052
+ (symbolToStringTagExists === false || !(Symbol.toStringTag in obj))
1053
+ ) {
1054
+ return 'Array';
1055
+ }
1056
+
1057
+ // Not caching existence of `window` and related properties due to potential
1058
+ // for `window` to be unset before tests in quasi-browser environments.
1059
+ if (typeof window === 'object' && window !== null) {
1060
+ /* ! Spec Conformance
1061
+ * (https://html.spec.whatwg.org/multipage/browsers.html#location)
1062
+ * WhatWG HTML$7.7.3 - The `Location` interface
1063
+ * Test: `Object.prototype.toString.call(window.location)``
1064
+ * - IE <=11 === "[object Object]"
1065
+ * - IE Edge <=13 === "[object Object]"
1066
+ */
1067
+ if (typeof window.location === 'object' && obj === window.location) {
1068
+ return 'Location';
1069
+ }
1070
+
1071
+ /* ! Spec Conformance
1072
+ * (https://html.spec.whatwg.org/#document)
1073
+ * WhatWG HTML$3.1.1 - The `Document` object
1074
+ * Note: Most browsers currently adher to the W3C DOM Level 2 spec
1075
+ * (https://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-26809268)
1076
+ * which suggests that browsers should use HTMLTableCellElement for
1077
+ * both TD and TH elements. WhatWG separates these.
1078
+ * WhatWG HTML states:
1079
+ * > For historical reasons, Window objects must also have a
1080
+ * > writable, configurable, non-enumerable property named
1081
+ * > HTMLDocument whose value is the Document interface object.
1082
+ * Test: `Object.prototype.toString.call(document)``
1083
+ * - Chrome === "[object HTMLDocument]"
1084
+ * - Firefox === "[object HTMLDocument]"
1085
+ * - Safari === "[object HTMLDocument]"
1086
+ * - IE <=10 === "[object Document]"
1087
+ * - IE 11 === "[object HTMLDocument]"
1088
+ * - IE Edge <=13 === "[object HTMLDocument]"
1089
+ */
1090
+ if (typeof window.document === 'object' && obj === window.document) {
1091
+ return 'Document';
1092
+ }
1093
+
1094
+ if (typeof window.navigator === 'object') {
1095
+ /* ! Spec Conformance
1096
+ * (https://html.spec.whatwg.org/multipage/webappapis.html#mimetypearray)
1097
+ * WhatWG HTML$8.6.1.5 - Plugins - Interface MimeTypeArray
1098
+ * Test: `Object.prototype.toString.call(navigator.mimeTypes)``
1099
+ * - IE <=10 === "[object MSMimeTypesCollection]"
1100
+ */
1101
+ if (typeof window.navigator.mimeTypes === 'object' &&
1102
+ obj === window.navigator.mimeTypes) {
1103
+ return 'MimeTypeArray';
1104
+ }
1105
+
1106
+ /* ! Spec Conformance
1107
+ * (https://html.spec.whatwg.org/multipage/webappapis.html#pluginarray)
1108
+ * WhatWG HTML$8.6.1.5 - Plugins - Interface PluginArray
1109
+ * Test: `Object.prototype.toString.call(navigator.plugins)``
1110
+ * - IE <=10 === "[object MSPluginsCollection]"
1111
+ */
1112
+ if (typeof window.navigator.plugins === 'object' &&
1113
+ obj === window.navigator.plugins) {
1114
+ return 'PluginArray';
1115
+ }
1116
+ }
1117
+
1118
+ if ((typeof window.HTMLElement === 'function' ||
1119
+ typeof window.HTMLElement === 'object') &&
1120
+ obj instanceof window.HTMLElement) {
1121
+ /* ! Spec Conformance
1122
+ * (https://html.spec.whatwg.org/multipage/webappapis.html#pluginarray)
1123
+ * WhatWG HTML$4.4.4 - The `blockquote` element - Interface `HTMLQuoteElement`
1124
+ * Test: `Object.prototype.toString.call(document.createElement('blockquote'))``
1125
+ * - IE <=10 === "[object HTMLBlockElement]"
1126
+ */
1127
+ if (obj.tagName === 'BLOCKQUOTE') {
1128
+ return 'HTMLQuoteElement';
1129
+ }
1130
+
1131
+ /* ! Spec Conformance
1132
+ * (https://html.spec.whatwg.org/#htmltabledatacellelement)
1133
+ * WhatWG HTML$4.9.9 - The `td` element - Interface `HTMLTableDataCellElement`
1134
+ * Note: Most browsers currently adher to the W3C DOM Level 2 spec
1135
+ * (https://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-82915075)
1136
+ * which suggests that browsers should use HTMLTableCellElement for
1137
+ * both TD and TH elements. WhatWG separates these.
1138
+ * Test: Object.prototype.toString.call(document.createElement('td'))
1139
+ * - Chrome === "[object HTMLTableCellElement]"
1140
+ * - Firefox === "[object HTMLTableCellElement]"
1141
+ * - Safari === "[object HTMLTableCellElement]"
1142
+ */
1143
+ if (obj.tagName === 'TD') {
1144
+ return 'HTMLTableDataCellElement';
1145
+ }
1146
+
1147
+ /* ! Spec Conformance
1148
+ * (https://html.spec.whatwg.org/#htmltableheadercellelement)
1149
+ * WhatWG HTML$4.9.9 - The `td` element - Interface `HTMLTableHeaderCellElement`
1150
+ * Note: Most browsers currently adher to the W3C DOM Level 2 spec
1151
+ * (https://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-82915075)
1152
+ * which suggests that browsers should use HTMLTableCellElement for
1153
+ * both TD and TH elements. WhatWG separates these.
1154
+ * Test: Object.prototype.toString.call(document.createElement('th'))
1155
+ * - Chrome === "[object HTMLTableCellElement]"
1156
+ * - Firefox === "[object HTMLTableCellElement]"
1157
+ * - Safari === "[object HTMLTableCellElement]"
1158
+ */
1159
+ if (obj.tagName === 'TH') {
1160
+ return 'HTMLTableHeaderCellElement';
1161
+ }
1162
+ }
1163
+ }
1164
+
1165
+ /* ! Speed optimisation
1166
+ * Pre:
1167
+ * Float64Array x 625,644 ops/sec ±1.58% (80 runs sampled)
1168
+ * Float32Array x 1,279,852 ops/sec ±2.91% (77 runs sampled)
1169
+ * Uint32Array x 1,178,185 ops/sec ±1.95% (83 runs sampled)
1170
+ * Uint16Array x 1,008,380 ops/sec ±2.25% (80 runs sampled)
1171
+ * Uint8Array x 1,128,040 ops/sec ±2.11% (81 runs sampled)
1172
+ * Int32Array x 1,170,119 ops/sec ±2.88% (80 runs sampled)
1173
+ * Int16Array x 1,176,348 ops/sec ±5.79% (86 runs sampled)
1174
+ * Int8Array x 1,058,707 ops/sec ±4.94% (77 runs sampled)
1175
+ * Uint8ClampedArray x 1,110,633 ops/sec ±4.20% (80 runs sampled)
1176
+ * Post:
1177
+ * Float64Array x 7,105,671 ops/sec ±13.47% (64 runs sampled)
1178
+ * Float32Array x 5,887,912 ops/sec ±1.46% (82 runs sampled)
1179
+ * Uint32Array x 6,491,661 ops/sec ±1.76% (79 runs sampled)
1180
+ * Uint16Array x 6,559,795 ops/sec ±1.67% (82 runs sampled)
1181
+ * Uint8Array x 6,463,966 ops/sec ±1.43% (85 runs sampled)
1182
+ * Int32Array x 5,641,841 ops/sec ±3.49% (81 runs sampled)
1183
+ * Int16Array x 6,583,511 ops/sec ±1.98% (80 runs sampled)
1184
+ * Int8Array x 6,606,078 ops/sec ±1.74% (81 runs sampled)
1185
+ * Uint8ClampedArray x 6,602,224 ops/sec ±1.77% (83 runs sampled)
1186
+ */
1187
+ var stringTag = (symbolToStringTagExists && obj[Symbol.toStringTag]);
1188
+ if (typeof stringTag === 'string') {
1189
+ return stringTag;
1190
+ }
1191
+
1192
+ var objPrototype = Object.getPrototypeOf(obj);
1193
+ /* ! Speed optimisation
1194
+ * Pre:
1195
+ * regex literal x 1,772,385 ops/sec ±1.85% (77 runs sampled)
1196
+ * regex constructor x 2,143,634 ops/sec ±2.46% (78 runs sampled)
1197
+ * Post:
1198
+ * regex literal x 3,928,009 ops/sec ±0.65% (78 runs sampled)
1199
+ * regex constructor x 3,931,108 ops/sec ±0.58% (84 runs sampled)
1200
+ */
1201
+ if (objPrototype === RegExp.prototype) {
1202
+ return 'RegExp';
1203
+ }
1204
+
1205
+ /* ! Speed optimisation
1206
+ * Pre:
1207
+ * date x 2,130,074 ops/sec ±4.42% (68 runs sampled)
1208
+ * Post:
1209
+ * date x 3,953,779 ops/sec ±1.35% (77 runs sampled)
1210
+ */
1211
+ if (objPrototype === Date.prototype) {
1212
+ return 'Date';
1213
+ }
1214
+
1215
+ /* ! Spec Conformance
1216
+ * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-promise.prototype-@@tostringtag)
1217
+ * ES6$25.4.5.4 - Promise.prototype[@@toStringTag] should be "Promise":
1218
+ * Test: `Object.prototype.toString.call(Promise.resolve())``
1219
+ * - Chrome <=47 === "[object Object]"
1220
+ * - Edge <=20 === "[object Object]"
1221
+ * - Firefox 29-Latest === "[object Promise]"
1222
+ * - Safari 7.1-Latest === "[object Promise]"
1223
+ */
1224
+ if (promiseExists && objPrototype === Promise.prototype) {
1225
+ return 'Promise';
1226
+ }
1227
+
1228
+ /* ! Speed optimisation
1229
+ * Pre:
1230
+ * set x 2,222,186 ops/sec ±1.31% (82 runs sampled)
1231
+ * Post:
1232
+ * set x 4,545,879 ops/sec ±1.13% (83 runs sampled)
1233
+ */
1234
+ if (setExists && objPrototype === Set.prototype) {
1235
+ return 'Set';
1236
+ }
1237
+
1238
+ /* ! Speed optimisation
1239
+ * Pre:
1240
+ * map x 2,396,842 ops/sec ±1.59% (81 runs sampled)
1241
+ * Post:
1242
+ * map x 4,183,945 ops/sec ±6.59% (82 runs sampled)
1243
+ */
1244
+ if (mapExists && objPrototype === Map.prototype) {
1245
+ return 'Map';
1246
+ }
1247
+
1248
+ /* ! Speed optimisation
1249
+ * Pre:
1250
+ * weakset x 1,323,220 ops/sec ±2.17% (76 runs sampled)
1251
+ * Post:
1252
+ * weakset x 4,237,510 ops/sec ±2.01% (77 runs sampled)
1253
+ */
1254
+ if (weakSetExists && objPrototype === WeakSet.prototype) {
1255
+ return 'WeakSet';
1256
+ }
1257
+
1258
+ /* ! Speed optimisation
1259
+ * Pre:
1260
+ * weakmap x 1,500,260 ops/sec ±2.02% (78 runs sampled)
1261
+ * Post:
1262
+ * weakmap x 3,881,384 ops/sec ±1.45% (82 runs sampled)
1263
+ */
1264
+ if (weakMapExists && objPrototype === WeakMap.prototype) {
1265
+ return 'WeakMap';
1266
+ }
1267
+
1268
+ /* ! Spec Conformance
1269
+ * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-dataview.prototype-@@tostringtag)
1270
+ * ES6$24.2.4.21 - DataView.prototype[@@toStringTag] should be "DataView":
1271
+ * Test: `Object.prototype.toString.call(new DataView(new ArrayBuffer(1)))``
1272
+ * - Edge <=13 === "[object Object]"
1273
+ */
1274
+ if (dataViewExists && objPrototype === DataView.prototype) {
1275
+ return 'DataView';
1276
+ }
1277
+
1278
+ /* ! Spec Conformance
1279
+ * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%mapiteratorprototype%-@@tostringtag)
1280
+ * ES6$23.1.5.2.2 - %MapIteratorPrototype%[@@toStringTag] should be "Map Iterator":
1281
+ * Test: `Object.prototype.toString.call(new Map().entries())``
1282
+ * - Edge <=13 === "[object Object]"
1283
+ */
1284
+ if (mapExists && objPrototype === mapIteratorPrototype) {
1285
+ return 'Map Iterator';
1286
+ }
1287
+
1288
+ /* ! Spec Conformance
1289
+ * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%setiteratorprototype%-@@tostringtag)
1290
+ * ES6$23.2.5.2.2 - %SetIteratorPrototype%[@@toStringTag] should be "Set Iterator":
1291
+ * Test: `Object.prototype.toString.call(new Set().entries())``
1292
+ * - Edge <=13 === "[object Object]"
1293
+ */
1294
+ if (setExists && objPrototype === setIteratorPrototype) {
1295
+ return 'Set Iterator';
1296
+ }
1297
+
1298
+ /* ! Spec Conformance
1299
+ * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%arrayiteratorprototype%-@@tostringtag)
1300
+ * ES6$22.1.5.2.2 - %ArrayIteratorPrototype%[@@toStringTag] should be "Array Iterator":
1301
+ * Test: `Object.prototype.toString.call([][Symbol.iterator]())``
1302
+ * - Edge <=13 === "[object Object]"
1303
+ */
1304
+ if (arrayIteratorExists && objPrototype === arrayIteratorPrototype) {
1305
+ return 'Array Iterator';
1306
+ }
1307
+
1308
+ /* ! Spec Conformance
1309
+ * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%stringiteratorprototype%-@@tostringtag)
1310
+ * ES6$21.1.5.2.2 - %StringIteratorPrototype%[@@toStringTag] should be "String Iterator":
1311
+ * Test: `Object.prototype.toString.call(''[Symbol.iterator]())``
1312
+ * - Edge <=13 === "[object Object]"
1313
+ */
1314
+ if (stringIteratorExists && objPrototype === stringIteratorPrototype) {
1315
+ return 'String Iterator';
1316
+ }
1317
+
1318
+ /* ! Speed optimisation
1319
+ * Pre:
1320
+ * object from null x 2,424,320 ops/sec ±1.67% (76 runs sampled)
1321
+ * Post:
1322
+ * object from null x 5,838,000 ops/sec ±0.99% (84 runs sampled)
1323
+ */
1324
+ if (objPrototype === null) {
1325
+ return 'Object';
1326
+ }
1327
+
1328
+ return Object
1329
+ .prototype
1330
+ .toString
1331
+ .call(obj)
1332
+ .slice(toStringLeftSliceLength, toStringRightSliceLength);
1333
+ }
1334
+
1335
+ return typeDetect;
1336
+
1337
+ })));
1338
+ } (typeDetect$1));
1339
+ return typeDetect$1.exports;
1340
+ }
1341
+
1342
+ var typeOf;
1343
+ var hasRequiredTypeOf;
1344
+
1345
+ function requireTypeOf () {
1346
+ if (hasRequiredTypeOf) return typeOf;
1347
+ hasRequiredTypeOf = 1;
1348
+
1349
+ var type = requireTypeDetect();
1350
+
1351
+ /**
1352
+ * Returns the lower-case result of running type from type-detect on the value
1353
+ * @param {*} value
1354
+ * @returns {string}
1355
+ */
1356
+ typeOf = function typeOf(value) {
1357
+ return type(value).toLowerCase();
1358
+ };
1359
+ return typeOf;
1360
+ }
1361
+
1362
+ var valueToString_1;
1363
+ var hasRequiredValueToString;
1364
+
1365
+ function requireValueToString () {
1366
+ if (hasRequiredValueToString) return valueToString_1;
1367
+ hasRequiredValueToString = 1;
1368
+
1369
+ /**
1370
+ * Returns a string representation of the value
1371
+ * @param {*} value
1372
+ * @returns {string}
1373
+ */
1374
+ function valueToString(value) {
1375
+ if (value && value.toString) {
1376
+ // eslint-disable-next-line @sinonjs/no-prototype-methods/no-prototype-methods
1377
+ return value.toString();
1378
+ }
1379
+ return String(value);
1380
+ }
1381
+
1382
+ valueToString_1 = valueToString;
1383
+ return valueToString_1;
1384
+ }
1385
+
1386
+ var lib;
1387
+ var hasRequiredLib;
1388
+
1389
+ function requireLib () {
1390
+ if (hasRequiredLib) return lib;
1391
+ hasRequiredLib = 1;
1392
+
1393
+ lib = {
1394
+ global: requireGlobal(),
1395
+ calledInOrder: requireCalledInOrder(),
1396
+ className: requireClassName(),
1397
+ deprecated: requireDeprecated(),
1398
+ every: requireEvery(),
1399
+ functionName: requireFunctionName(),
1400
+ orderByFirstCall: requireOrderByFirstCall(),
1401
+ prototypes: requirePrototypes(),
1402
+ typeOf: requireTypeOf(),
1403
+ valueToString: requireValueToString(),
1404
+ };
1405
+ return lib;
1406
+ }
1407
+
1408
+ var hasRequiredFakeTimersSrc;
1409
+
1410
+ function requireFakeTimersSrc () {
1411
+ if (hasRequiredFakeTimersSrc) return fakeTimersSrc;
1412
+ hasRequiredFakeTimersSrc = 1;
1413
+
1414
+ const globalObject = requireLib().global;
1415
+ let timersModule, timersPromisesModule;
1416
+ if (typeof __vitest_required__ !== 'undefined') {
1417
+ try {
1418
+ timersModule = __vitest_required__.timers;
1419
+ } catch (e) {
1420
+ // ignored
1421
+ }
1422
+ try {
1423
+ timersPromisesModule = __vitest_required__.timersPromises;
1424
+ } catch (e) {
1425
+ // ignored
1426
+ }
1427
+ }
1428
+
1429
+ /**
1430
+ * @typedef {object} IdleDeadline
1431
+ * @property {boolean} didTimeout - whether or not the callback was called before reaching the optional timeout
1432
+ * @property {function():number} timeRemaining - a floating-point value providing an estimate of the number of milliseconds remaining in the current idle period
1433
+ */
1434
+
1435
+ /**
1436
+ * Queues a function to be called during a browser's idle periods
1437
+ * @callback RequestIdleCallback
1438
+ * @param {function(IdleDeadline)} callback
1439
+ * @param {{timeout: number}} options - an options object
1440
+ * @returns {number} the id
1441
+ */
1442
+
1443
+ /**
1444
+ * @callback NextTick
1445
+ * @param {VoidVarArgsFunc} callback - the callback to run
1446
+ * @param {...*} args - optional arguments to call the callback with
1447
+ * @returns {void}
1448
+ */
1449
+
1450
+ /**
1451
+ * @callback SetImmediate
1452
+ * @param {VoidVarArgsFunc} callback - the callback to run
1453
+ * @param {...*} args - optional arguments to call the callback with
1454
+ * @returns {NodeImmediate}
1455
+ */
1456
+
1457
+ /**
1458
+ * @callback VoidVarArgsFunc
1459
+ * @param {...*} callback - the callback to run
1460
+ * @returns {void}
1461
+ */
1462
+
1463
+ /**
1464
+ * @typedef RequestAnimationFrame
1465
+ * @property {function(number):void} requestAnimationFrame
1466
+ * @returns {number} - the id
1467
+ */
1468
+
1469
+ /**
1470
+ * @typedef Performance
1471
+ * @property {function(): number} now
1472
+ */
1473
+
1474
+ /* eslint-disable jsdoc/require-property-description */
1475
+ /**
1476
+ * @typedef {object} Clock
1477
+ * @property {number} now - the current time
1478
+ * @property {Date} Date - the Date constructor
1479
+ * @property {number} loopLimit - the maximum number of timers before assuming an infinite loop
1480
+ * @property {RequestIdleCallback} requestIdleCallback
1481
+ * @property {function(number):void} cancelIdleCallback
1482
+ * @property {setTimeout} setTimeout
1483
+ * @property {clearTimeout} clearTimeout
1484
+ * @property {NextTick} nextTick
1485
+ * @property {queueMicrotask} queueMicrotask
1486
+ * @property {setInterval} setInterval
1487
+ * @property {clearInterval} clearInterval
1488
+ * @property {SetImmediate} setImmediate
1489
+ * @property {function(NodeImmediate):void} clearImmediate
1490
+ * @property {function():number} countTimers
1491
+ * @property {RequestAnimationFrame} requestAnimationFrame
1492
+ * @property {function(number):void} cancelAnimationFrame
1493
+ * @property {function():void} runMicrotasks
1494
+ * @property {function(string | number): number} tick
1495
+ * @property {function(string | number): Promise<number>} tickAsync
1496
+ * @property {function(): number} next
1497
+ * @property {function(): Promise<number>} nextAsync
1498
+ * @property {function(): number} runAll
1499
+ * @property {function(): number} runToFrame
1500
+ * @property {function(): Promise<number>} runAllAsync
1501
+ * @property {function(): number} runToLast
1502
+ * @property {function(): Promise<number>} runToLastAsync
1503
+ * @property {function(): void} reset
1504
+ * @property {function(number | Date): void} setSystemTime
1505
+ * @property {function(number): void} jump
1506
+ * @property {Performance} performance
1507
+ * @property {function(number[]): number[]} hrtime - process.hrtime (legacy)
1508
+ * @property {function(): void} uninstall Uninstall the clock.
1509
+ * @property {Function[]} methods - the methods that are faked
1510
+ * @property {boolean} [shouldClearNativeTimers] inherited from config
1511
+ * @property {{methodName:string, original:any}[] | undefined} timersModuleMethods
1512
+ * @property {{methodName:string, original:any}[] | undefined} timersPromisesModuleMethods
1513
+ * @property {Map<function(): void, AbortSignal>} abortListenerMap
1514
+ */
1515
+ /* eslint-enable jsdoc/require-property-description */
1516
+
1517
+ /**
1518
+ * Configuration object for the `install` method.
1519
+ * @typedef {object} Config
1520
+ * @property {number|Date} [now] a number (in milliseconds) or a Date object (default epoch)
1521
+ * @property {string[]} [toFake] names of the methods that should be faked.
1522
+ * @property {number} [loopLimit] the maximum number of timers that will be run when calling runAll()
1523
+ * @property {boolean} [shouldAdvanceTime] tells FakeTimers to increment mocked time automatically (default false)
1524
+ * @property {number} [advanceTimeDelta] increment mocked time every <<advanceTimeDelta>> ms (default: 20ms)
1525
+ * @property {boolean} [shouldClearNativeTimers] forwards clear timer calls to native functions if they are not fakes (default: false)
1526
+ * @property {boolean} [ignoreMissingTimers] default is false, meaning asking to fake timers that are not present will throw an error
1527
+ */
1528
+
1529
+ /* eslint-disable jsdoc/require-property-description */
1530
+ /**
1531
+ * The internal structure to describe a scheduled fake timer
1532
+ * @typedef {object} Timer
1533
+ * @property {Function} func
1534
+ * @property {*[]} args
1535
+ * @property {number} delay
1536
+ * @property {number} callAt
1537
+ * @property {number} createdAt
1538
+ * @property {boolean} immediate
1539
+ * @property {number} id
1540
+ * @property {Error} [error]
1541
+ */
1542
+
1543
+ /**
1544
+ * A Node timer
1545
+ * @typedef {object} NodeImmediate
1546
+ * @property {function(): boolean} hasRef
1547
+ * @property {function(): NodeImmediate} ref
1548
+ * @property {function(): NodeImmediate} unref
1549
+ */
1550
+ /* eslint-enable jsdoc/require-property-description */
1551
+
1552
+ /* eslint-disable complexity */
1553
+
1554
+ /**
1555
+ * Mocks available features in the specified global namespace.
1556
+ * @param {*} _global Namespace to mock (e.g. `window`)
1557
+ * @returns {FakeTimers}
1558
+ */
1559
+ function withGlobal(_global) {
1560
+ const maxTimeout = Math.pow(2, 31) - 1; //see https://heycam.github.io/webidl/#abstract-opdef-converttoint
1561
+ const idCounterStart = 1e12; // arbitrarily large number to avoid collisions with native timer IDs
1562
+ const NOOP = function () {
1563
+ return undefined;
1564
+ };
1565
+ const NOOP_ARRAY = function () {
1566
+ return [];
1567
+ };
1568
+ const isPresent = {};
1569
+ let timeoutResult,
1570
+ addTimerReturnsObject = false;
1571
+
1572
+ if (_global.setTimeout) {
1573
+ isPresent.setTimeout = true;
1574
+ timeoutResult = _global.setTimeout(NOOP, 0);
1575
+ addTimerReturnsObject = typeof timeoutResult === "object";
1576
+ }
1577
+ isPresent.clearTimeout = Boolean(_global.clearTimeout);
1578
+ isPresent.setInterval = Boolean(_global.setInterval);
1579
+ isPresent.clearInterval = Boolean(_global.clearInterval);
1580
+ isPresent.hrtime =
1581
+ _global.process && typeof _global.process.hrtime === "function";
1582
+ isPresent.hrtimeBigint =
1583
+ isPresent.hrtime && typeof _global.process.hrtime.bigint === "function";
1584
+ isPresent.nextTick =
1585
+ _global.process && typeof _global.process.nextTick === "function";
1586
+ const utilPromisify = _global.process && _global.__vitest_required__ && _global.__vitest_required__.util.promisify;
1587
+ isPresent.performance =
1588
+ _global.performance && typeof _global.performance.now === "function";
1589
+ const hasPerformancePrototype =
1590
+ _global.Performance &&
1591
+ (typeof _global.Performance).match(/^(function|object)$/);
1592
+ const hasPerformanceConstructorPrototype =
1593
+ _global.performance &&
1594
+ _global.performance.constructor &&
1595
+ _global.performance.constructor.prototype;
1596
+ isPresent.queueMicrotask = _global.hasOwnProperty("queueMicrotask");
1597
+ isPresent.requestAnimationFrame =
1598
+ _global.requestAnimationFrame &&
1599
+ typeof _global.requestAnimationFrame === "function";
1600
+ isPresent.cancelAnimationFrame =
1601
+ _global.cancelAnimationFrame &&
1602
+ typeof _global.cancelAnimationFrame === "function";
1603
+ isPresent.requestIdleCallback =
1604
+ _global.requestIdleCallback &&
1605
+ typeof _global.requestIdleCallback === "function";
1606
+ isPresent.cancelIdleCallbackPresent =
1607
+ _global.cancelIdleCallback &&
1608
+ typeof _global.cancelIdleCallback === "function";
1609
+ isPresent.setImmediate =
1610
+ _global.setImmediate && typeof _global.setImmediate === "function";
1611
+ isPresent.clearImmediate =
1612
+ _global.clearImmediate && typeof _global.clearImmediate === "function";
1613
+ isPresent.Intl = _global.Intl && typeof _global.Intl === "object";
1614
+
1615
+ if (_global.clearTimeout) {
1616
+ _global.clearTimeout(timeoutResult);
1617
+ }
1618
+
1619
+ const NativeDate = _global.Date;
1620
+ const NativeIntl = isPresent.Intl
1621
+ ? Object.defineProperties(
1622
+ Object.create(null),
1623
+ Object.getOwnPropertyDescriptors(_global.Intl),
1624
+ )
1625
+ : undefined;
1626
+ let uniqueTimerId = idCounterStart;
1627
+
1628
+ if (NativeDate === undefined) {
1629
+ throw new Error(
1630
+ "The global scope doesn't have a `Date` object" +
1631
+ " (see https://github.com/sinonjs/sinon/issues/1852#issuecomment-419622780)",
1632
+ );
1633
+ }
1634
+ isPresent.Date = true;
1635
+
1636
+ /**
1637
+ * The PerformanceEntry object encapsulates a single performance metric
1638
+ * that is part of the browser's performance timeline.
1639
+ *
1640
+ * This is an object returned by the `mark` and `measure` methods on the Performance prototype
1641
+ */
1642
+ class FakePerformanceEntry {
1643
+ constructor(name, entryType, startTime, duration) {
1644
+ this.name = name;
1645
+ this.entryType = entryType;
1646
+ this.startTime = startTime;
1647
+ this.duration = duration;
1648
+ }
1649
+
1650
+ toJSON() {
1651
+ return JSON.stringify({ ...this });
1652
+ }
1653
+ }
1654
+
1655
+ /**
1656
+ * @param {number} num
1657
+ * @returns {boolean}
1658
+ */
1659
+ function isNumberFinite(num) {
1660
+ if (Number.isFinite) {
1661
+ return Number.isFinite(num);
1662
+ }
1663
+
1664
+ return isFinite(num);
1665
+ }
1666
+
1667
+ let isNearInfiniteLimit = false;
1668
+
1669
+ /**
1670
+ * @param {Clock} clock
1671
+ * @param {number} i
1672
+ */
1673
+ function checkIsNearInfiniteLimit(clock, i) {
1674
+ if (clock.loopLimit && i === clock.loopLimit - 1) {
1675
+ isNearInfiniteLimit = true;
1676
+ }
1677
+ }
1678
+
1679
+ /**
1680
+ *
1681
+ */
1682
+ function resetIsNearInfiniteLimit() {
1683
+ isNearInfiniteLimit = false;
1684
+ }
1685
+
1686
+ /**
1687
+ * Parse strings like "01:10:00" (meaning 1 hour, 10 minutes, 0 seconds) into
1688
+ * number of milliseconds. This is used to support human-readable strings passed
1689
+ * to clock.tick()
1690
+ * @param {string} str
1691
+ * @returns {number}
1692
+ */
1693
+ function parseTime(str) {
1694
+ if (!str) {
1695
+ return 0;
1696
+ }
1697
+
1698
+ const strings = str.split(":");
1699
+ const l = strings.length;
1700
+ let i = l;
1701
+ let ms = 0;
1702
+ let parsed;
1703
+
1704
+ if (l > 3 || !/^(\d\d:){0,2}\d\d?$/.test(str)) {
1705
+ throw new Error(
1706
+ "tick only understands numbers, 'm:s' and 'h:m:s'. Each part must be two digits",
1707
+ );
1708
+ }
1709
+
1710
+ while (i--) {
1711
+ parsed = parseInt(strings[i], 10);
1712
+
1713
+ if (parsed >= 60) {
1714
+ throw new Error(`Invalid time ${str}`);
1715
+ }
1716
+
1717
+ ms += parsed * Math.pow(60, l - i - 1);
1718
+ }
1719
+
1720
+ return ms * 1000;
1721
+ }
1722
+
1723
+ /**
1724
+ * Get the decimal part of the millisecond value as nanoseconds
1725
+ * @param {number} msFloat the number of milliseconds
1726
+ * @returns {number} an integer number of nanoseconds in the range [0,1e6)
1727
+ *
1728
+ * Example: nanoRemainer(123.456789) -> 456789
1729
+ */
1730
+ function nanoRemainder(msFloat) {
1731
+ const modulo = 1e6;
1732
+ const remainder = (msFloat * 1e6) % modulo;
1733
+ const positiveRemainder =
1734
+ remainder < 0 ? remainder + modulo : remainder;
1735
+
1736
+ return Math.floor(positiveRemainder);
1737
+ }
1738
+
1739
+ /**
1740
+ * Used to grok the `now` parameter to createClock.
1741
+ * @param {Date|number} epoch the system time
1742
+ * @returns {number}
1743
+ */
1744
+ function getEpoch(epoch) {
1745
+ if (!epoch) {
1746
+ return 0;
1747
+ }
1748
+ if (typeof epoch.getTime === "function") {
1749
+ return epoch.getTime();
1750
+ }
1751
+ if (typeof epoch === "number") {
1752
+ return epoch;
1753
+ }
1754
+ throw new TypeError("now should be milliseconds since UNIX epoch");
1755
+ }
1756
+
1757
+ /**
1758
+ * @param {number} from
1759
+ * @param {number} to
1760
+ * @param {Timer} timer
1761
+ * @returns {boolean}
1762
+ */
1763
+ function inRange(from, to, timer) {
1764
+ return timer && timer.callAt >= from && timer.callAt <= to;
1765
+ }
1766
+
1767
+ /**
1768
+ * @param {Clock} clock
1769
+ * @param {Timer} job
1770
+ */
1771
+ function getInfiniteLoopError(clock, job) {
1772
+ const infiniteLoopError = new Error(
1773
+ `Aborting after running ${clock.loopLimit} timers, assuming an infinite loop!`,
1774
+ );
1775
+
1776
+ if (!job.error) {
1777
+ return infiniteLoopError;
1778
+ }
1779
+
1780
+ // pattern never matched in Node
1781
+ const computedTargetPattern = /target\.*[<|(|[].*?[>|\]|)]\s*/;
1782
+ let clockMethodPattern = new RegExp(
1783
+ String(Object.keys(clock).join("|")),
1784
+ );
1785
+
1786
+ if (addTimerReturnsObject) {
1787
+ // node.js environment
1788
+ clockMethodPattern = new RegExp(
1789
+ `\\s+at (Object\\.)?(?:${Object.keys(clock).join("|")})\\s+`,
1790
+ );
1791
+ }
1792
+
1793
+ let matchedLineIndex = -1;
1794
+ job.error.stack.split("\n").some(function (line, i) {
1795
+ // If we've matched a computed target line (e.g. setTimeout) then we
1796
+ // don't need to look any further. Return true to stop iterating.
1797
+ const matchedComputedTarget = line.match(computedTargetPattern);
1798
+ /* istanbul ignore if */
1799
+ if (matchedComputedTarget) {
1800
+ matchedLineIndex = i;
1801
+ return true;
1802
+ }
1803
+
1804
+ // If we've matched a clock method line, then there may still be
1805
+ // others further down the trace. Return false to keep iterating.
1806
+ const matchedClockMethod = line.match(clockMethodPattern);
1807
+ if (matchedClockMethod) {
1808
+ matchedLineIndex = i;
1809
+ return false;
1810
+ }
1811
+
1812
+ // If we haven't matched anything on this line, but we matched
1813
+ // previously and set the matched line index, then we can stop.
1814
+ // If we haven't matched previously, then we should keep iterating.
1815
+ return matchedLineIndex >= 0;
1816
+ });
1817
+
1818
+ const stack = `${infiniteLoopError}\n${job.type || "Microtask"} - ${
1819
+ job.func.name || "anonymous"
1820
+ }\n${job.error.stack
1821
+ .split("\n")
1822
+ .slice(matchedLineIndex + 1)
1823
+ .join("\n")}`;
1824
+
1825
+ try {
1826
+ Object.defineProperty(infiniteLoopError, "stack", {
1827
+ value: stack,
1828
+ });
1829
+ } catch (e) {
1830
+ // noop
1831
+ }
1832
+
1833
+ return infiniteLoopError;
1834
+ }
1835
+
1836
+ //eslint-disable-next-line jsdoc/require-jsdoc
1837
+ function createDate() {
1838
+ class ClockDate extends NativeDate {
1839
+ /**
1840
+ * @param {number} year
1841
+ * @param {number} month
1842
+ * @param {number} date
1843
+ * @param {number} hour
1844
+ * @param {number} minute
1845
+ * @param {number} second
1846
+ * @param {number} ms
1847
+ * @returns void
1848
+ */
1849
+ // eslint-disable-next-line no-unused-vars
1850
+ constructor(year, month, date, hour, minute, second, ms) {
1851
+ // Defensive and verbose to avoid potential harm in passing
1852
+ // explicit undefined when user does not pass argument
1853
+ if (arguments.length === 0) {
1854
+ super(ClockDate.clock.now);
1855
+ } else {
1856
+ super(...arguments);
1857
+ }
1858
+
1859
+ // ensures identity checks using the constructor prop still works
1860
+ // this should have no other functional effect
1861
+ Object.defineProperty(this, "constructor", {
1862
+ value: NativeDate,
1863
+ enumerable: false,
1864
+ });
1865
+ }
1866
+
1867
+ static [Symbol.hasInstance](instance) {
1868
+ return instance instanceof NativeDate;
1869
+ }
1870
+ }
1871
+
1872
+ ClockDate.isFake = true;
1873
+
1874
+ if (NativeDate.now) {
1875
+ ClockDate.now = function now() {
1876
+ return ClockDate.clock.now;
1877
+ };
1878
+ }
1879
+
1880
+ if (NativeDate.toSource) {
1881
+ ClockDate.toSource = function toSource() {
1882
+ return NativeDate.toSource();
1883
+ };
1884
+ }
1885
+
1886
+ ClockDate.toString = function toString() {
1887
+ return NativeDate.toString();
1888
+ };
1889
+
1890
+ // noinspection UnnecessaryLocalVariableJS
1891
+ /**
1892
+ * A normal Class constructor cannot be called without `new`, but Date can, so we need
1893
+ * to wrap it in a Proxy in order to ensure this functionality of Date is kept intact
1894
+ * @type {ClockDate}
1895
+ */
1896
+ const ClockDateProxy = new Proxy(ClockDate, {
1897
+ // handler for [[Call]] invocations (i.e. not using `new`)
1898
+ apply() {
1899
+ // the Date constructor called as a function, ref Ecma-262 Edition 5.1, section 15.9.2.
1900
+ // This remains so in the 10th edition of 2019 as well.
1901
+ if (this instanceof ClockDate) {
1902
+ throw new TypeError(
1903
+ "A Proxy should only capture `new` calls with the `construct` handler. This is not supposed to be possible, so check the logic.",
1904
+ );
1905
+ }
1906
+
1907
+ return new NativeDate(ClockDate.clock.now).toString();
1908
+ },
1909
+ });
1910
+
1911
+ return ClockDateProxy;
1912
+ }
1913
+
1914
+ /**
1915
+ * Mirror Intl by default on our fake implementation
1916
+ *
1917
+ * Most of the properties are the original native ones,
1918
+ * but we need to take control of those that have a
1919
+ * dependency on the current clock.
1920
+ * @returns {object} the partly fake Intl implementation
1921
+ */
1922
+ function createIntl() {
1923
+ const ClockIntl = {};
1924
+ /*
1925
+ * All properties of Intl are non-enumerable, so we need
1926
+ * to do a bit of work to get them out.
1927
+ */
1928
+ Object.getOwnPropertyNames(NativeIntl).forEach(
1929
+ (property) => (ClockIntl[property] = NativeIntl[property]),
1930
+ );
1931
+
1932
+ ClockIntl.DateTimeFormat = function (...args) {
1933
+ const realFormatter = new NativeIntl.DateTimeFormat(...args);
1934
+ const formatter = {};
1935
+
1936
+ ["formatRange", "formatRangeToParts", "resolvedOptions"].forEach(
1937
+ (method) => {
1938
+ formatter[method] =
1939
+ realFormatter[method].bind(realFormatter);
1940
+ },
1941
+ );
1942
+
1943
+ ["format", "formatToParts"].forEach((method) => {
1944
+ formatter[method] = function (date) {
1945
+ return realFormatter[method](date || ClockIntl.clock.now);
1946
+ };
1947
+ });
1948
+
1949
+ return formatter;
1950
+ };
1951
+
1952
+ ClockIntl.DateTimeFormat.prototype = Object.create(
1953
+ NativeIntl.DateTimeFormat.prototype,
1954
+ );
1955
+
1956
+ ClockIntl.DateTimeFormat.supportedLocalesOf =
1957
+ NativeIntl.DateTimeFormat.supportedLocalesOf;
1958
+
1959
+ return ClockIntl;
1960
+ }
1961
+
1962
+ //eslint-disable-next-line jsdoc/require-jsdoc
1963
+ function enqueueJob(clock, job) {
1964
+ // enqueues a microtick-deferred task - ecma262/#sec-enqueuejob
1965
+ if (!clock.jobs) {
1966
+ clock.jobs = [];
1967
+ }
1968
+ clock.jobs.push(job);
1969
+ }
1970
+
1971
+ //eslint-disable-next-line jsdoc/require-jsdoc
1972
+ function runJobs(clock) {
1973
+ // runs all microtick-deferred tasks - ecma262/#sec-runjobs
1974
+ if (!clock.jobs) {
1975
+ return;
1976
+ }
1977
+ for (let i = 0; i < clock.jobs.length; i++) {
1978
+ const job = clock.jobs[i];
1979
+ job.func.apply(null, job.args);
1980
+
1981
+ checkIsNearInfiniteLimit(clock, i);
1982
+ if (clock.loopLimit && i > clock.loopLimit) {
1983
+ throw getInfiniteLoopError(clock, job);
1984
+ }
1985
+ }
1986
+ resetIsNearInfiniteLimit();
1987
+ clock.jobs = [];
1988
+ }
1989
+
1990
+ /**
1991
+ * @param {Clock} clock
1992
+ * @param {Timer} timer
1993
+ * @returns {number} id of the created timer
1994
+ */
1995
+ function addTimer(clock, timer) {
1996
+ if (timer.func === undefined) {
1997
+ throw new Error("Callback must be provided to timer calls");
1998
+ }
1999
+
2000
+ if (addTimerReturnsObject) {
2001
+ // Node.js environment
2002
+ if (typeof timer.func !== "function") {
2003
+ throw new TypeError(
2004
+ `[ERR_INVALID_CALLBACK]: Callback must be a function. Received ${
2005
+ timer.func
2006
+ } of type ${typeof timer.func}`,
2007
+ );
2008
+ }
2009
+ }
2010
+
2011
+ if (isNearInfiniteLimit) {
2012
+ timer.error = new Error();
2013
+ }
2014
+
2015
+ timer.type = timer.immediate ? "Immediate" : "Timeout";
2016
+
2017
+ if (timer.hasOwnProperty("delay")) {
2018
+ if (typeof timer.delay !== "number") {
2019
+ timer.delay = parseInt(timer.delay, 10);
2020
+ }
2021
+
2022
+ if (!isNumberFinite(timer.delay)) {
2023
+ timer.delay = 0;
2024
+ }
2025
+ timer.delay = timer.delay > maxTimeout ? 1 : timer.delay;
2026
+ timer.delay = Math.max(0, timer.delay);
2027
+ }
2028
+
2029
+ if (timer.hasOwnProperty("interval")) {
2030
+ timer.type = "Interval";
2031
+ timer.interval = timer.interval > maxTimeout ? 1 : timer.interval;
2032
+ }
2033
+
2034
+ if (timer.hasOwnProperty("animation")) {
2035
+ timer.type = "AnimationFrame";
2036
+ timer.animation = true;
2037
+ }
2038
+
2039
+ if (timer.hasOwnProperty("idleCallback")) {
2040
+ timer.type = "IdleCallback";
2041
+ timer.idleCallback = true;
2042
+ }
2043
+
2044
+ if (!clock.timers) {
2045
+ clock.timers = {};
2046
+ }
2047
+
2048
+ timer.id = uniqueTimerId++;
2049
+ timer.createdAt = clock.now;
2050
+ timer.callAt =
2051
+ clock.now + (parseInt(timer.delay) || (clock.duringTick ? 1 : 0));
2052
+
2053
+ clock.timers[timer.id] = timer;
2054
+
2055
+ if (addTimerReturnsObject) {
2056
+ const res = {
2057
+ refed: true,
2058
+ ref: function () {
2059
+ this.refed = true;
2060
+ return res;
2061
+ },
2062
+ unref: function () {
2063
+ this.refed = false;
2064
+ return res;
2065
+ },
2066
+ hasRef: function () {
2067
+ return this.refed;
2068
+ },
2069
+ refresh: function () {
2070
+ timer.callAt =
2071
+ clock.now +
2072
+ (parseInt(timer.delay) || (clock.duringTick ? 1 : 0));
2073
+
2074
+ // it _might_ have been removed, but if not the assignment is perfectly fine
2075
+ clock.timers[timer.id] = timer;
2076
+
2077
+ return res;
2078
+ },
2079
+ [Symbol.toPrimitive]: function () {
2080
+ return timer.id;
2081
+ },
2082
+ };
2083
+ return res;
2084
+ }
2085
+
2086
+ return timer.id;
2087
+ }
2088
+
2089
+ /* eslint consistent-return: "off" */
2090
+ /**
2091
+ * Timer comparitor
2092
+ * @param {Timer} a
2093
+ * @param {Timer} b
2094
+ * @returns {number}
2095
+ */
2096
+ function compareTimers(a, b) {
2097
+ // Sort first by absolute timing
2098
+ if (a.callAt < b.callAt) {
2099
+ return -1;
2100
+ }
2101
+ if (a.callAt > b.callAt) {
2102
+ return 1;
2103
+ }
2104
+
2105
+ // Sort next by immediate, immediate timers take precedence
2106
+ if (a.immediate && !b.immediate) {
2107
+ return -1;
2108
+ }
2109
+ if (!a.immediate && b.immediate) {
2110
+ return 1;
2111
+ }
2112
+
2113
+ // Sort next by creation time, earlier-created timers take precedence
2114
+ if (a.createdAt < b.createdAt) {
2115
+ return -1;
2116
+ }
2117
+ if (a.createdAt > b.createdAt) {
2118
+ return 1;
2119
+ }
2120
+
2121
+ // Sort next by id, lower-id timers take precedence
2122
+ if (a.id < b.id) {
2123
+ return -1;
2124
+ }
2125
+ if (a.id > b.id) {
2126
+ return 1;
2127
+ }
2128
+
2129
+ // As timer ids are unique, no fallback `0` is necessary
2130
+ }
2131
+
2132
+ /**
2133
+ * @param {Clock} clock
2134
+ * @param {number} from
2135
+ * @param {number} to
2136
+ * @returns {Timer}
2137
+ */
2138
+ function firstTimerInRange(clock, from, to) {
2139
+ const timers = clock.timers;
2140
+ let timer = null;
2141
+ let id, isInRange;
2142
+
2143
+ for (id in timers) {
2144
+ if (timers.hasOwnProperty(id)) {
2145
+ isInRange = inRange(from, to, timers[id]);
2146
+
2147
+ if (
2148
+ isInRange &&
2149
+ (!timer || compareTimers(timer, timers[id]) === 1)
2150
+ ) {
2151
+ timer = timers[id];
2152
+ }
2153
+ }
2154
+ }
2155
+
2156
+ return timer;
2157
+ }
2158
+
2159
+ /**
2160
+ * @param {Clock} clock
2161
+ * @returns {Timer}
2162
+ */
2163
+ function firstTimer(clock) {
2164
+ const timers = clock.timers;
2165
+ let timer = null;
2166
+ let id;
2167
+
2168
+ for (id in timers) {
2169
+ if (timers.hasOwnProperty(id)) {
2170
+ if (!timer || compareTimers(timer, timers[id]) === 1) {
2171
+ timer = timers[id];
2172
+ }
2173
+ }
2174
+ }
2175
+
2176
+ return timer;
2177
+ }
2178
+
2179
+ /**
2180
+ * @param {Clock} clock
2181
+ * @returns {Timer}
2182
+ */
2183
+ function lastTimer(clock) {
2184
+ const timers = clock.timers;
2185
+ let timer = null;
2186
+ let id;
2187
+
2188
+ for (id in timers) {
2189
+ if (timers.hasOwnProperty(id)) {
2190
+ if (!timer || compareTimers(timer, timers[id]) === -1) {
2191
+ timer = timers[id];
2192
+ }
2193
+ }
2194
+ }
2195
+
2196
+ return timer;
2197
+ }
2198
+
2199
+ /**
2200
+ * @param {Clock} clock
2201
+ * @param {Timer} timer
2202
+ */
2203
+ function callTimer(clock, timer) {
2204
+ if (typeof timer.interval === "number") {
2205
+ clock.timers[timer.id].callAt += timer.interval;
2206
+ } else {
2207
+ delete clock.timers[timer.id];
2208
+ }
2209
+
2210
+ if (typeof timer.func === "function") {
2211
+ timer.func.apply(null, timer.args);
2212
+ } else {
2213
+ /* eslint no-eval: "off" */
2214
+ const eval2 = eval;
2215
+ (function () {
2216
+ eval2(timer.func);
2217
+ })();
2218
+ }
2219
+ }
2220
+
2221
+ /**
2222
+ * Gets clear handler name for a given timer type
2223
+ * @param {string} ttype
2224
+ */
2225
+ function getClearHandler(ttype) {
2226
+ if (ttype === "IdleCallback" || ttype === "AnimationFrame") {
2227
+ return `cancel${ttype}`;
2228
+ }
2229
+ return `clear${ttype}`;
2230
+ }
2231
+
2232
+ /**
2233
+ * Gets schedule handler name for a given timer type
2234
+ * @param {string} ttype
2235
+ */
2236
+ function getScheduleHandler(ttype) {
2237
+ if (ttype === "IdleCallback" || ttype === "AnimationFrame") {
2238
+ return `request${ttype}`;
2239
+ }
2240
+ return `set${ttype}`;
2241
+ }
2242
+
2243
+ /**
2244
+ * Creates an anonymous function to warn only once
2245
+ */
2246
+ function createWarnOnce() {
2247
+ let calls = 0;
2248
+ return function (msg) {
2249
+ // eslint-disable-next-line
2250
+ !calls++ && console.warn(msg);
2251
+ };
2252
+ }
2253
+ const warnOnce = createWarnOnce();
2254
+
2255
+ /**
2256
+ * @param {Clock} clock
2257
+ * @param {number} timerId
2258
+ * @param {string} ttype
2259
+ */
2260
+ function clearTimer(clock, timerId, ttype) {
2261
+ if (!timerId) {
2262
+ // null appears to be allowed in most browsers, and appears to be
2263
+ // relied upon by some libraries, like Bootstrap carousel
2264
+ return;
2265
+ }
2266
+
2267
+ if (!clock.timers) {
2268
+ clock.timers = {};
2269
+ }
2270
+
2271
+ // in Node, the ID is stored as the primitive value for `Timeout` objects
2272
+ // for `Immediate` objects, no ID exists, so it gets coerced to NaN
2273
+ const id = Number(timerId);
2274
+
2275
+ if (Number.isNaN(id) || id < idCounterStart) {
2276
+ const handlerName = getClearHandler(ttype);
2277
+
2278
+ if (clock.shouldClearNativeTimers === true) {
2279
+ const nativeHandler = clock[`_${handlerName}`];
2280
+ return typeof nativeHandler === "function"
2281
+ ? nativeHandler(timerId)
2282
+ : undefined;
2283
+ }
2284
+ warnOnce(
2285
+ `FakeTimers: ${handlerName} was invoked to clear a native timer instead of one created by this library.` +
2286
+ "\nTo automatically clean-up native timers, use `shouldClearNativeTimers`.",
2287
+ );
2288
+ }
2289
+
2290
+ if (clock.timers.hasOwnProperty(id)) {
2291
+ // check that the ID matches a timer of the correct type
2292
+ const timer = clock.timers[id];
2293
+ if (
2294
+ timer.type === ttype ||
2295
+ (timer.type === "Timeout" && ttype === "Interval") ||
2296
+ (timer.type === "Interval" && ttype === "Timeout")
2297
+ ) {
2298
+ delete clock.timers[id];
2299
+ } else {
2300
+ const clear = getClearHandler(ttype);
2301
+ const schedule = getScheduleHandler(timer.type);
2302
+ throw new Error(
2303
+ `Cannot clear timer: timer created with ${schedule}() but cleared with ${clear}()`,
2304
+ );
2305
+ }
2306
+ }
2307
+ }
2308
+
2309
+ /**
2310
+ * @param {Clock} clock
2311
+ * @param {Config} config
2312
+ * @returns {Timer[]}
2313
+ */
2314
+ function uninstall(clock, config) {
2315
+ let method, i, l;
2316
+ const installedHrTime = "_hrtime";
2317
+ const installedNextTick = "_nextTick";
2318
+
2319
+ for (i = 0, l = clock.methods.length; i < l; i++) {
2320
+ method = clock.methods[i];
2321
+ if (method === "hrtime" && _global.process) {
2322
+ _global.process.hrtime = clock[installedHrTime];
2323
+ } else if (method === "nextTick" && _global.process) {
2324
+ _global.process.nextTick = clock[installedNextTick];
2325
+ } else if (method === "performance") {
2326
+ const originalPerfDescriptor = Object.getOwnPropertyDescriptor(
2327
+ clock,
2328
+ `_${method}`,
2329
+ );
2330
+ if (
2331
+ originalPerfDescriptor &&
2332
+ originalPerfDescriptor.get &&
2333
+ !originalPerfDescriptor.set
2334
+ ) {
2335
+ Object.defineProperty(
2336
+ _global,
2337
+ method,
2338
+ originalPerfDescriptor,
2339
+ );
2340
+ } else if (originalPerfDescriptor.configurable) {
2341
+ _global[method] = clock[`_${method}`];
2342
+ }
2343
+ } else {
2344
+ if (_global[method] && _global[method].hadOwnProperty) {
2345
+ _global[method] = clock[`_${method}`];
2346
+ } else {
2347
+ try {
2348
+ delete _global[method];
2349
+ } catch (ignore) {
2350
+ /* eslint no-empty: "off" */
2351
+ }
2352
+ }
2353
+ }
2354
+ if (clock.timersModuleMethods !== undefined) {
2355
+ for (let j = 0; j < clock.timersModuleMethods.length; j++) {
2356
+ const entry = clock.timersModuleMethods[j];
2357
+ timersModule[entry.methodName] = entry.original;
2358
+ }
2359
+ }
2360
+ if (clock.timersPromisesModuleMethods !== undefined) {
2361
+ for (
2362
+ let j = 0;
2363
+ j < clock.timersPromisesModuleMethods.length;
2364
+ j++
2365
+ ) {
2366
+ const entry = clock.timersPromisesModuleMethods[j];
2367
+ timersPromisesModule[entry.methodName] = entry.original;
2368
+ }
2369
+ }
2370
+ }
2371
+
2372
+ if (config.shouldAdvanceTime === true) {
2373
+ _global.clearInterval(clock.attachedInterval);
2374
+ }
2375
+
2376
+ // Prevent multiple executions which will completely remove these props
2377
+ clock.methods = [];
2378
+
2379
+ for (const [listener, signal] of clock.abortListenerMap.entries()) {
2380
+ signal.removeEventListener("abort", listener);
2381
+ clock.abortListenerMap.delete(listener);
2382
+ }
2383
+
2384
+ // return pending timers, to enable checking what timers remained on uninstall
2385
+ if (!clock.timers) {
2386
+ return [];
2387
+ }
2388
+ return Object.keys(clock.timers).map(function mapper(key) {
2389
+ return clock.timers[key];
2390
+ });
2391
+ }
2392
+
2393
+ /**
2394
+ * @param {object} target the target containing the method to replace
2395
+ * @param {string} method the keyname of the method on the target
2396
+ * @param {Clock} clock
2397
+ */
2398
+ function hijackMethod(target, method, clock) {
2399
+ clock[method].hadOwnProperty = Object.prototype.hasOwnProperty.call(
2400
+ target,
2401
+ method,
2402
+ );
2403
+ clock[`_${method}`] = target[method];
2404
+
2405
+ if (method === "Date") {
2406
+ target[method] = clock[method];
2407
+ } else if (method === "Intl") {
2408
+ target[method] = clock[method];
2409
+ } else if (method === "performance") {
2410
+ const originalPerfDescriptor = Object.getOwnPropertyDescriptor(
2411
+ target,
2412
+ method,
2413
+ );
2414
+ // JSDOM has a read only performance field so we have to save/copy it differently
2415
+ if (
2416
+ originalPerfDescriptor &&
2417
+ originalPerfDescriptor.get &&
2418
+ !originalPerfDescriptor.set
2419
+ ) {
2420
+ Object.defineProperty(
2421
+ clock,
2422
+ `_${method}`,
2423
+ originalPerfDescriptor,
2424
+ );
2425
+
2426
+ const perfDescriptor = Object.getOwnPropertyDescriptor(
2427
+ clock,
2428
+ method,
2429
+ );
2430
+ Object.defineProperty(target, method, perfDescriptor);
2431
+ } else {
2432
+ target[method] = clock[method];
2433
+ }
2434
+ } else {
2435
+ target[method] = function () {
2436
+ return clock[method].apply(clock, arguments);
2437
+ };
2438
+
2439
+ Object.defineProperties(
2440
+ target[method],
2441
+ Object.getOwnPropertyDescriptors(clock[method]),
2442
+ );
2443
+ }
2444
+
2445
+ target[method].clock = clock;
2446
+ }
2447
+
2448
+ /**
2449
+ * @param {Clock} clock
2450
+ * @param {number} advanceTimeDelta
2451
+ */
2452
+ function doIntervalTick(clock, advanceTimeDelta) {
2453
+ clock.tick(advanceTimeDelta);
2454
+ }
2455
+
2456
+ /**
2457
+ * @typedef {object} Timers
2458
+ * @property {setTimeout} setTimeout
2459
+ * @property {clearTimeout} clearTimeout
2460
+ * @property {setInterval} setInterval
2461
+ * @property {clearInterval} clearInterval
2462
+ * @property {Date} Date
2463
+ * @property {Intl} Intl
2464
+ * @property {SetImmediate=} setImmediate
2465
+ * @property {function(NodeImmediate): void=} clearImmediate
2466
+ * @property {function(number[]):number[]=} hrtime
2467
+ * @property {NextTick=} nextTick
2468
+ * @property {Performance=} performance
2469
+ * @property {RequestAnimationFrame=} requestAnimationFrame
2470
+ * @property {boolean=} queueMicrotask
2471
+ * @property {function(number): void=} cancelAnimationFrame
2472
+ * @property {RequestIdleCallback=} requestIdleCallback
2473
+ * @property {function(number): void=} cancelIdleCallback
2474
+ */
2475
+
2476
+ /** @type {Timers} */
2477
+ const timers = {
2478
+ setTimeout: _global.setTimeout,
2479
+ clearTimeout: _global.clearTimeout,
2480
+ setInterval: _global.setInterval,
2481
+ clearInterval: _global.clearInterval,
2482
+ Date: _global.Date,
2483
+ };
2484
+
2485
+ if (isPresent.setImmediate) {
2486
+ timers.setImmediate = _global.setImmediate;
2487
+ }
2488
+
2489
+ if (isPresent.clearImmediate) {
2490
+ timers.clearImmediate = _global.clearImmediate;
2491
+ }
2492
+
2493
+ if (isPresent.hrtime) {
2494
+ timers.hrtime = _global.process.hrtime;
2495
+ }
2496
+
2497
+ if (isPresent.nextTick) {
2498
+ timers.nextTick = _global.process.nextTick;
2499
+ }
2500
+
2501
+ if (isPresent.performance) {
2502
+ timers.performance = _global.performance;
2503
+ }
2504
+
2505
+ if (isPresent.requestAnimationFrame) {
2506
+ timers.requestAnimationFrame = _global.requestAnimationFrame;
2507
+ }
2508
+
2509
+ if (isPresent.queueMicrotask) {
2510
+ timers.queueMicrotask = _global.queueMicrotask;
2511
+ }
2512
+
2513
+ if (isPresent.cancelAnimationFrame) {
2514
+ timers.cancelAnimationFrame = _global.cancelAnimationFrame;
2515
+ }
2516
+
2517
+ if (isPresent.requestIdleCallback) {
2518
+ timers.requestIdleCallback = _global.requestIdleCallback;
2519
+ }
2520
+
2521
+ if (isPresent.cancelIdleCallback) {
2522
+ timers.cancelIdleCallback = _global.cancelIdleCallback;
2523
+ }
2524
+
2525
+ if (isPresent.Intl) {
2526
+ timers.Intl = NativeIntl;
2527
+ }
2528
+
2529
+ const originalSetTimeout = _global.setImmediate || _global.setTimeout;
2530
+
2531
+ /**
2532
+ * @param {Date|number} [start] the system time - non-integer values are floored
2533
+ * @param {number} [loopLimit] maximum number of timers that will be run when calling runAll()
2534
+ * @returns {Clock}
2535
+ */
2536
+ function createClock(start, loopLimit) {
2537
+ // eslint-disable-next-line no-param-reassign
2538
+ start = Math.floor(getEpoch(start));
2539
+ // eslint-disable-next-line no-param-reassign
2540
+ loopLimit = loopLimit || 1000;
2541
+ let nanos = 0;
2542
+ const adjustedSystemTime = [0, 0]; // [millis, nanoremainder]
2543
+
2544
+ const clock = {
2545
+ now: start,
2546
+ Date: createDate(),
2547
+ loopLimit: loopLimit,
2548
+ };
2549
+
2550
+ clock.Date.clock = clock;
2551
+
2552
+ //eslint-disable-next-line jsdoc/require-jsdoc
2553
+ function getTimeToNextFrame() {
2554
+ return 16 - ((clock.now - start) % 16);
2555
+ }
2556
+
2557
+ //eslint-disable-next-line jsdoc/require-jsdoc
2558
+ function hrtime(prev) {
2559
+ const millisSinceStart = clock.now - adjustedSystemTime[0] - start;
2560
+ const secsSinceStart = Math.floor(millisSinceStart / 1000);
2561
+ const remainderInNanos =
2562
+ (millisSinceStart - secsSinceStart * 1e3) * 1e6 +
2563
+ nanos -
2564
+ adjustedSystemTime[1];
2565
+
2566
+ if (Array.isArray(prev)) {
2567
+ if (prev[1] > 1e9) {
2568
+ throw new TypeError(
2569
+ "Number of nanoseconds can't exceed a billion",
2570
+ );
2571
+ }
2572
+
2573
+ const oldSecs = prev[0];
2574
+ let nanoDiff = remainderInNanos - prev[1];
2575
+ let secDiff = secsSinceStart - oldSecs;
2576
+
2577
+ if (nanoDiff < 0) {
2578
+ nanoDiff += 1e9;
2579
+ secDiff -= 1;
2580
+ }
2581
+
2582
+ return [secDiff, nanoDiff];
2583
+ }
2584
+ return [secsSinceStart, remainderInNanos];
2585
+ }
2586
+
2587
+ /**
2588
+ * A high resolution timestamp in milliseconds.
2589
+ * @typedef {number} DOMHighResTimeStamp
2590
+ */
2591
+
2592
+ /**
2593
+ * performance.now()
2594
+ * @returns {DOMHighResTimeStamp}
2595
+ */
2596
+ function fakePerformanceNow() {
2597
+ const hrt = hrtime();
2598
+ const millis = hrt[0] * 1000 + hrt[1] / 1e6;
2599
+ return millis;
2600
+ }
2601
+
2602
+ if (isPresent.hrtimeBigint) {
2603
+ hrtime.bigint = function () {
2604
+ const parts = hrtime();
2605
+ return BigInt(parts[0]) * BigInt(1e9) + BigInt(parts[1]); // eslint-disable-line
2606
+ };
2607
+ }
2608
+
2609
+ if (isPresent.Intl) {
2610
+ clock.Intl = createIntl();
2611
+ clock.Intl.clock = clock;
2612
+ }
2613
+
2614
+ clock.requestIdleCallback = function requestIdleCallback(
2615
+ func,
2616
+ timeout,
2617
+ ) {
2618
+ let timeToNextIdlePeriod = 0;
2619
+
2620
+ if (clock.countTimers() > 0) {
2621
+ timeToNextIdlePeriod = 50; // const for now
2622
+ }
2623
+
2624
+ const result = addTimer(clock, {
2625
+ func: func,
2626
+ args: Array.prototype.slice.call(arguments, 2),
2627
+ delay:
2628
+ typeof timeout === "undefined"
2629
+ ? timeToNextIdlePeriod
2630
+ : Math.min(timeout, timeToNextIdlePeriod),
2631
+ idleCallback: true,
2632
+ });
2633
+
2634
+ return Number(result);
2635
+ };
2636
+
2637
+ clock.cancelIdleCallback = function cancelIdleCallback(timerId) {
2638
+ return clearTimer(clock, timerId, "IdleCallback");
2639
+ };
2640
+
2641
+ clock.setTimeout = function setTimeout(func, timeout) {
2642
+ return addTimer(clock, {
2643
+ func: func,
2644
+ args: Array.prototype.slice.call(arguments, 2),
2645
+ delay: timeout,
2646
+ });
2647
+ };
2648
+ if (typeof _global.Promise !== "undefined" && utilPromisify) {
2649
+ clock.setTimeout[utilPromisify.custom] =
2650
+ function promisifiedSetTimeout(timeout, arg) {
2651
+ return new _global.Promise(function setTimeoutExecutor(
2652
+ resolve,
2653
+ ) {
2654
+ addTimer(clock, {
2655
+ func: resolve,
2656
+ args: [arg],
2657
+ delay: timeout,
2658
+ });
2659
+ });
2660
+ };
2661
+ }
2662
+
2663
+ clock.clearTimeout = function clearTimeout(timerId) {
2664
+ return clearTimer(clock, timerId, "Timeout");
2665
+ };
2666
+
2667
+ clock.nextTick = function nextTick(func) {
2668
+ return enqueueJob(clock, {
2669
+ func: func,
2670
+ args: Array.prototype.slice.call(arguments, 1),
2671
+ error: isNearInfiniteLimit ? new Error() : null,
2672
+ });
2673
+ };
2674
+
2675
+ clock.queueMicrotask = function queueMicrotask(func) {
2676
+ return clock.nextTick(func); // explicitly drop additional arguments
2677
+ };
2678
+
2679
+ clock.setInterval = function setInterval(func, timeout) {
2680
+ // eslint-disable-next-line no-param-reassign
2681
+ timeout = parseInt(timeout, 10);
2682
+ return addTimer(clock, {
2683
+ func: func,
2684
+ args: Array.prototype.slice.call(arguments, 2),
2685
+ delay: timeout,
2686
+ interval: timeout,
2687
+ });
2688
+ };
2689
+
2690
+ clock.clearInterval = function clearInterval(timerId) {
2691
+ return clearTimer(clock, timerId, "Interval");
2692
+ };
2693
+
2694
+ if (isPresent.setImmediate) {
2695
+ clock.setImmediate = function setImmediate(func) {
2696
+ return addTimer(clock, {
2697
+ func: func,
2698
+ args: Array.prototype.slice.call(arguments, 1),
2699
+ immediate: true,
2700
+ });
2701
+ };
2702
+
2703
+ if (typeof _global.Promise !== "undefined" && utilPromisify) {
2704
+ clock.setImmediate[utilPromisify.custom] =
2705
+ function promisifiedSetImmediate(arg) {
2706
+ return new _global.Promise(
2707
+ function setImmediateExecutor(resolve) {
2708
+ addTimer(clock, {
2709
+ func: resolve,
2710
+ args: [arg],
2711
+ immediate: true,
2712
+ });
2713
+ },
2714
+ );
2715
+ };
2716
+ }
2717
+
2718
+ clock.clearImmediate = function clearImmediate(timerId) {
2719
+ return clearTimer(clock, timerId, "Immediate");
2720
+ };
2721
+ }
2722
+
2723
+ clock.countTimers = function countTimers() {
2724
+ return (
2725
+ Object.keys(clock.timers || {}).length +
2726
+ (clock.jobs || []).length
2727
+ );
2728
+ };
2729
+
2730
+ clock.requestAnimationFrame = function requestAnimationFrame(func) {
2731
+ const result = addTimer(clock, {
2732
+ func: func,
2733
+ delay: getTimeToNextFrame(),
2734
+ get args() {
2735
+ return [fakePerformanceNow()];
2736
+ },
2737
+ animation: true,
2738
+ });
2739
+
2740
+ return Number(result);
2741
+ };
2742
+
2743
+ clock.cancelAnimationFrame = function cancelAnimationFrame(timerId) {
2744
+ return clearTimer(clock, timerId, "AnimationFrame");
2745
+ };
2746
+
2747
+ clock.runMicrotasks = function runMicrotasks() {
2748
+ runJobs(clock);
2749
+ };
2750
+
2751
+ /**
2752
+ * @param {number|string} tickValue milliseconds or a string parseable by parseTime
2753
+ * @param {boolean} isAsync
2754
+ * @param {Function} resolve
2755
+ * @param {Function} reject
2756
+ * @returns {number|undefined} will return the new `now` value or nothing for async
2757
+ */
2758
+ function doTick(tickValue, isAsync, resolve, reject) {
2759
+ const msFloat =
2760
+ typeof tickValue === "number"
2761
+ ? tickValue
2762
+ : parseTime(tickValue);
2763
+ const ms = Math.floor(msFloat);
2764
+ const remainder = nanoRemainder(msFloat);
2765
+ let nanosTotal = nanos + remainder;
2766
+ let tickTo = clock.now + ms;
2767
+
2768
+ if (msFloat < 0) {
2769
+ throw new TypeError("Negative ticks are not supported");
2770
+ }
2771
+
2772
+ // adjust for positive overflow
2773
+ if (nanosTotal >= 1e6) {
2774
+ tickTo += 1;
2775
+ nanosTotal -= 1e6;
2776
+ }
2777
+
2778
+ nanos = nanosTotal;
2779
+ let tickFrom = clock.now;
2780
+ let previous = clock.now;
2781
+ // ESLint fails to detect this correctly
2782
+ /* eslint-disable prefer-const */
2783
+ let timer,
2784
+ firstException,
2785
+ oldNow,
2786
+ nextPromiseTick,
2787
+ compensationCheck,
2788
+ postTimerCall;
2789
+ /* eslint-enable prefer-const */
2790
+
2791
+ clock.duringTick = true;
2792
+
2793
+ // perform microtasks
2794
+ oldNow = clock.now;
2795
+ runJobs(clock);
2796
+ if (oldNow !== clock.now) {
2797
+ // compensate for any setSystemTime() call during microtask callback
2798
+ tickFrom += clock.now - oldNow;
2799
+ tickTo += clock.now - oldNow;
2800
+ }
2801
+
2802
+ //eslint-disable-next-line jsdoc/require-jsdoc
2803
+ function doTickInner() {
2804
+ // perform each timer in the requested range
2805
+ timer = firstTimerInRange(clock, tickFrom, tickTo);
2806
+ // eslint-disable-next-line no-unmodified-loop-condition
2807
+ while (timer && tickFrom <= tickTo) {
2808
+ if (clock.timers[timer.id]) {
2809
+ tickFrom = timer.callAt;
2810
+ clock.now = timer.callAt;
2811
+ oldNow = clock.now;
2812
+ try {
2813
+ runJobs(clock);
2814
+ callTimer(clock, timer);
2815
+ } catch (e) {
2816
+ firstException = firstException || e;
2817
+ }
2818
+
2819
+ if (isAsync) {
2820
+ // finish up after native setImmediate callback to allow
2821
+ // all native es6 promises to process their callbacks after
2822
+ // each timer fires.
2823
+ originalSetTimeout(nextPromiseTick);
2824
+ return;
2825
+ }
2826
+
2827
+ compensationCheck();
2828
+ }
2829
+
2830
+ postTimerCall();
2831
+ }
2832
+
2833
+ // perform process.nextTick()s again
2834
+ oldNow = clock.now;
2835
+ runJobs(clock);
2836
+ if (oldNow !== clock.now) {
2837
+ // compensate for any setSystemTime() call during process.nextTick() callback
2838
+ tickFrom += clock.now - oldNow;
2839
+ tickTo += clock.now - oldNow;
2840
+ }
2841
+ clock.duringTick = false;
2842
+
2843
+ // corner case: during runJobs new timers were scheduled which could be in the range [clock.now, tickTo]
2844
+ timer = firstTimerInRange(clock, tickFrom, tickTo);
2845
+ if (timer) {
2846
+ try {
2847
+ clock.tick(tickTo - clock.now); // do it all again - for the remainder of the requested range
2848
+ } catch (e) {
2849
+ firstException = firstException || e;
2850
+ }
2851
+ } else {
2852
+ // no timers remaining in the requested range: move the clock all the way to the end
2853
+ clock.now = tickTo;
2854
+
2855
+ // update nanos
2856
+ nanos = nanosTotal;
2857
+ }
2858
+ if (firstException) {
2859
+ throw firstException;
2860
+ }
2861
+
2862
+ if (isAsync) {
2863
+ resolve(clock.now);
2864
+ } else {
2865
+ return clock.now;
2866
+ }
2867
+ }
2868
+
2869
+ nextPromiseTick =
2870
+ isAsync &&
2871
+ function () {
2872
+ try {
2873
+ compensationCheck();
2874
+ postTimerCall();
2875
+ doTickInner();
2876
+ } catch (e) {
2877
+ reject(e);
2878
+ }
2879
+ };
2880
+
2881
+ compensationCheck = function () {
2882
+ // compensate for any setSystemTime() call during timer callback
2883
+ if (oldNow !== clock.now) {
2884
+ tickFrom += clock.now - oldNow;
2885
+ tickTo += clock.now - oldNow;
2886
+ previous += clock.now - oldNow;
2887
+ }
2888
+ };
2889
+
2890
+ postTimerCall = function () {
2891
+ timer = firstTimerInRange(clock, previous, tickTo);
2892
+ previous = tickFrom;
2893
+ };
2894
+
2895
+ return doTickInner();
2896
+ }
2897
+
2898
+ /**
2899
+ * @param {string|number} tickValue number of milliseconds or a human-readable value like "01:11:15"
2900
+ * @returns {number} will return the new `now` value
2901
+ */
2902
+ clock.tick = function tick(tickValue) {
2903
+ return doTick(tickValue, false);
2904
+ };
2905
+
2906
+ if (typeof _global.Promise !== "undefined") {
2907
+ /**
2908
+ * @param {string|number} tickValue number of milliseconds or a human-readable value like "01:11:15"
2909
+ * @returns {Promise}
2910
+ */
2911
+ clock.tickAsync = function tickAsync(tickValue) {
2912
+ return new _global.Promise(function (resolve, reject) {
2913
+ originalSetTimeout(function () {
2914
+ try {
2915
+ doTick(tickValue, true, resolve, reject);
2916
+ } catch (e) {
2917
+ reject(e);
2918
+ }
2919
+ });
2920
+ });
2921
+ };
2922
+ }
2923
+
2924
+ clock.next = function next() {
2925
+ runJobs(clock);
2926
+ const timer = firstTimer(clock);
2927
+ if (!timer) {
2928
+ return clock.now;
2929
+ }
2930
+
2931
+ clock.duringTick = true;
2932
+ try {
2933
+ clock.now = timer.callAt;
2934
+ callTimer(clock, timer);
2935
+ runJobs(clock);
2936
+ return clock.now;
2937
+ } finally {
2938
+ clock.duringTick = false;
2939
+ }
2940
+ };
2941
+
2942
+ if (typeof _global.Promise !== "undefined") {
2943
+ clock.nextAsync = function nextAsync() {
2944
+ return new _global.Promise(function (resolve, reject) {
2945
+ originalSetTimeout(function () {
2946
+ try {
2947
+ const timer = firstTimer(clock);
2948
+ if (!timer) {
2949
+ resolve(clock.now);
2950
+ return;
2951
+ }
2952
+
2953
+ let err;
2954
+ clock.duringTick = true;
2955
+ clock.now = timer.callAt;
2956
+ try {
2957
+ callTimer(clock, timer);
2958
+ } catch (e) {
2959
+ err = e;
2960
+ }
2961
+ clock.duringTick = false;
2962
+
2963
+ originalSetTimeout(function () {
2964
+ if (err) {
2965
+ reject(err);
2966
+ } else {
2967
+ resolve(clock.now);
2968
+ }
2969
+ });
2970
+ } catch (e) {
2971
+ reject(e);
2972
+ }
2973
+ });
2974
+ });
2975
+ };
2976
+ }
2977
+
2978
+ clock.runAll = function runAll() {
2979
+ let numTimers, i;
2980
+ runJobs(clock);
2981
+ for (i = 0; i < clock.loopLimit; i++) {
2982
+ if (!clock.timers) {
2983
+ resetIsNearInfiniteLimit();
2984
+ return clock.now;
2985
+ }
2986
+
2987
+ numTimers = Object.keys(clock.timers).length;
2988
+ if (numTimers === 0) {
2989
+ resetIsNearInfiniteLimit();
2990
+ return clock.now;
2991
+ }
2992
+
2993
+ clock.next();
2994
+ checkIsNearInfiniteLimit(clock, i);
2995
+ }
2996
+
2997
+ const excessJob = firstTimer(clock);
2998
+ throw getInfiniteLoopError(clock, excessJob);
2999
+ };
3000
+
3001
+ clock.runToFrame = function runToFrame() {
3002
+ return clock.tick(getTimeToNextFrame());
3003
+ };
3004
+
3005
+ if (typeof _global.Promise !== "undefined") {
3006
+ clock.runAllAsync = function runAllAsync() {
3007
+ return new _global.Promise(function (resolve, reject) {
3008
+ let i = 0;
3009
+ /**
3010
+ *
3011
+ */
3012
+ function doRun() {
3013
+ originalSetTimeout(function () {
3014
+ try {
3015
+ runJobs(clock);
3016
+
3017
+ let numTimers;
3018
+ if (i < clock.loopLimit) {
3019
+ if (!clock.timers) {
3020
+ resetIsNearInfiniteLimit();
3021
+ resolve(clock.now);
3022
+ return;
3023
+ }
3024
+
3025
+ numTimers = Object.keys(
3026
+ clock.timers,
3027
+ ).length;
3028
+ if (numTimers === 0) {
3029
+ resetIsNearInfiniteLimit();
3030
+ resolve(clock.now);
3031
+ return;
3032
+ }
3033
+
3034
+ clock.next();
3035
+
3036
+ i++;
3037
+
3038
+ doRun();
3039
+ checkIsNearInfiniteLimit(clock, i);
3040
+ return;
3041
+ }
3042
+
3043
+ const excessJob = firstTimer(clock);
3044
+ reject(getInfiniteLoopError(clock, excessJob));
3045
+ } catch (e) {
3046
+ reject(e);
3047
+ }
3048
+ });
3049
+ }
3050
+ doRun();
3051
+ });
3052
+ };
3053
+ }
3054
+
3055
+ clock.runToLast = function runToLast() {
3056
+ const timer = lastTimer(clock);
3057
+ if (!timer) {
3058
+ runJobs(clock);
3059
+ return clock.now;
3060
+ }
3061
+
3062
+ return clock.tick(timer.callAt - clock.now);
3063
+ };
3064
+
3065
+ if (typeof _global.Promise !== "undefined") {
3066
+ clock.runToLastAsync = function runToLastAsync() {
3067
+ return new _global.Promise(function (resolve, reject) {
3068
+ originalSetTimeout(function () {
3069
+ try {
3070
+ const timer = lastTimer(clock);
3071
+ if (!timer) {
3072
+ runJobs(clock);
3073
+ resolve(clock.now);
3074
+ }
3075
+
3076
+ resolve(clock.tickAsync(timer.callAt - clock.now));
3077
+ } catch (e) {
3078
+ reject(e);
3079
+ }
3080
+ });
3081
+ });
3082
+ };
3083
+ }
3084
+
3085
+ clock.reset = function reset() {
3086
+ nanos = 0;
3087
+ clock.timers = {};
3088
+ clock.jobs = [];
3089
+ clock.now = start;
3090
+ };
3091
+
3092
+ clock.setSystemTime = function setSystemTime(systemTime) {
3093
+ // determine time difference
3094
+ const newNow = getEpoch(systemTime);
3095
+ const difference = newNow - clock.now;
3096
+ let id, timer;
3097
+
3098
+ adjustedSystemTime[0] = adjustedSystemTime[0] + difference;
3099
+ adjustedSystemTime[1] = adjustedSystemTime[1] + nanos;
3100
+ // update 'system clock'
3101
+ clock.now = newNow;
3102
+ nanos = 0;
3103
+
3104
+ // update timers and intervals to keep them stable
3105
+ for (id in clock.timers) {
3106
+ if (clock.timers.hasOwnProperty(id)) {
3107
+ timer = clock.timers[id];
3108
+ timer.createdAt += difference;
3109
+ timer.callAt += difference;
3110
+ }
3111
+ }
3112
+ };
3113
+
3114
+ /**
3115
+ * @param {string|number} tickValue number of milliseconds or a human-readable value like "01:11:15"
3116
+ * @returns {number} will return the new `now` value
3117
+ */
3118
+ clock.jump = function jump(tickValue) {
3119
+ const msFloat =
3120
+ typeof tickValue === "number"
3121
+ ? tickValue
3122
+ : parseTime(tickValue);
3123
+ const ms = Math.floor(msFloat);
3124
+
3125
+ for (const timer of Object.values(clock.timers)) {
3126
+ if (clock.now + ms > timer.callAt) {
3127
+ timer.callAt = clock.now + ms;
3128
+ }
3129
+ }
3130
+ clock.tick(ms);
3131
+ };
3132
+
3133
+ if (isPresent.performance) {
3134
+ clock.performance = Object.create(null);
3135
+ clock.performance.now = fakePerformanceNow;
3136
+ }
3137
+
3138
+ if (isPresent.hrtime) {
3139
+ clock.hrtime = hrtime;
3140
+ }
3141
+
3142
+ return clock;
3143
+ }
3144
+
3145
+ /* eslint-disable complexity */
3146
+
3147
+ /**
3148
+ * @param {Config=} [config] Optional config
3149
+ * @returns {Clock}
3150
+ */
3151
+ function install(config) {
3152
+ if (
3153
+ arguments.length > 1 ||
3154
+ config instanceof Date ||
3155
+ Array.isArray(config) ||
3156
+ typeof config === "number"
3157
+ ) {
3158
+ throw new TypeError(
3159
+ `FakeTimers.install called with ${String(
3160
+ config,
3161
+ )} install requires an object parameter`,
3162
+ );
3163
+ }
3164
+
3165
+ if (_global.Date.isFake === true) {
3166
+ // Timers are already faked; this is a problem.
3167
+ // Make the user reset timers before continuing.
3168
+ throw new TypeError(
3169
+ "Can't install fake timers twice on the same global object.",
3170
+ );
3171
+ }
3172
+
3173
+ // eslint-disable-next-line no-param-reassign
3174
+ config = typeof config !== "undefined" ? config : {};
3175
+ config.shouldAdvanceTime = config.shouldAdvanceTime || false;
3176
+ config.advanceTimeDelta = config.advanceTimeDelta || 20;
3177
+ config.shouldClearNativeTimers =
3178
+ config.shouldClearNativeTimers || false;
3179
+
3180
+ if (config.target) {
3181
+ throw new TypeError(
3182
+ "config.target is no longer supported. Use `withGlobal(target)` instead.",
3183
+ );
3184
+ }
3185
+
3186
+ /**
3187
+ * @param {string} timer/object the name of the thing that is not present
3188
+ * @param timer
3189
+ */
3190
+ function handleMissingTimer(timer) {
3191
+ if (config.ignoreMissingTimers) {
3192
+ return;
3193
+ }
3194
+
3195
+ throw new ReferenceError(
3196
+ `non-existent timers and/or objects cannot be faked: '${timer}'`,
3197
+ );
3198
+ }
3199
+
3200
+ let i, l;
3201
+ const clock = createClock(config.now, config.loopLimit);
3202
+ clock.shouldClearNativeTimers = config.shouldClearNativeTimers;
3203
+
3204
+ clock.uninstall = function () {
3205
+ return uninstall(clock, config);
3206
+ };
3207
+
3208
+ clock.abortListenerMap = new Map();
3209
+
3210
+ clock.methods = config.toFake || [];
3211
+
3212
+ if (clock.methods.length === 0) {
3213
+ clock.methods = Object.keys(timers);
3214
+ }
3215
+
3216
+ if (config.shouldAdvanceTime === true) {
3217
+ const intervalTick = doIntervalTick.bind(
3218
+ null,
3219
+ clock,
3220
+ config.advanceTimeDelta,
3221
+ );
3222
+ const intervalId = _global.setInterval(
3223
+ intervalTick,
3224
+ config.advanceTimeDelta,
3225
+ );
3226
+ clock.attachedInterval = intervalId;
3227
+ }
3228
+
3229
+ if (clock.methods.includes("performance")) {
3230
+ const proto = (() => {
3231
+ if (hasPerformanceConstructorPrototype) {
3232
+ return _global.performance.constructor.prototype;
3233
+ }
3234
+ if (hasPerformancePrototype) {
3235
+ return _global.Performance.prototype;
3236
+ }
3237
+ })();
3238
+ if (proto) {
3239
+ Object.getOwnPropertyNames(proto).forEach(function (name) {
3240
+ if (name !== "now") {
3241
+ clock.performance[name] =
3242
+ name.indexOf("getEntries") === 0
3243
+ ? NOOP_ARRAY
3244
+ : NOOP;
3245
+ }
3246
+ });
3247
+ // ensure `mark` returns a value that is valid
3248
+ clock.performance.mark = (name) =>
3249
+ new FakePerformanceEntry(name, "mark", 0, 0);
3250
+ clock.performance.measure = (name) =>
3251
+ new FakePerformanceEntry(name, "measure", 0, 100);
3252
+ // `timeOrigin` should return the time of when the Window session started
3253
+ // (or the Worker was installed)
3254
+ clock.performance.timeOrigin = getEpoch(config.now);
3255
+ } else if ((config.toFake || []).includes("performance")) {
3256
+ return handleMissingTimer("performance");
3257
+ }
3258
+ }
3259
+ if (_global === globalObject && timersModule) {
3260
+ clock.timersModuleMethods = [];
3261
+ }
3262
+ if (_global === globalObject && timersPromisesModule) {
3263
+ clock.timersPromisesModuleMethods = [];
3264
+ }
3265
+ for (i = 0, l = clock.methods.length; i < l; i++) {
3266
+ const nameOfMethodToReplace = clock.methods[i];
3267
+
3268
+ if (!isPresent[nameOfMethodToReplace]) {
3269
+ handleMissingTimer(nameOfMethodToReplace);
3270
+ // eslint-disable-next-line
3271
+ continue;
3272
+ }
3273
+
3274
+ if (nameOfMethodToReplace === "hrtime") {
3275
+ if (
3276
+ _global.process &&
3277
+ typeof _global.process.hrtime === "function"
3278
+ ) {
3279
+ hijackMethod(_global.process, nameOfMethodToReplace, clock);
3280
+ }
3281
+ } else if (nameOfMethodToReplace === "nextTick") {
3282
+ if (
3283
+ _global.process &&
3284
+ typeof _global.process.nextTick === "function"
3285
+ ) {
3286
+ hijackMethod(_global.process, nameOfMethodToReplace, clock);
3287
+ }
3288
+ } else {
3289
+ hijackMethod(_global, nameOfMethodToReplace, clock);
3290
+ }
3291
+ if (
3292
+ clock.timersModuleMethods !== undefined &&
3293
+ timersModule[nameOfMethodToReplace]
3294
+ ) {
3295
+ const original = timersModule[nameOfMethodToReplace];
3296
+ clock.timersModuleMethods.push({
3297
+ methodName: nameOfMethodToReplace,
3298
+ original: original,
3299
+ });
3300
+ timersModule[nameOfMethodToReplace] =
3301
+ _global[nameOfMethodToReplace];
3302
+ }
3303
+ if (clock.timersPromisesModuleMethods !== undefined) {
3304
+ if (nameOfMethodToReplace === "setTimeout") {
3305
+ clock.timersPromisesModuleMethods.push({
3306
+ methodName: "setTimeout",
3307
+ original: timersPromisesModule.setTimeout,
3308
+ });
3309
+
3310
+ timersPromisesModule.setTimeout = (
3311
+ delay,
3312
+ value,
3313
+ options = {},
3314
+ ) =>
3315
+ new Promise((resolve, reject) => {
3316
+ const abort = () => {
3317
+ options.signal.removeEventListener(
3318
+ "abort",
3319
+ abort,
3320
+ );
3321
+ clock.abortListenerMap.delete(abort);
3322
+
3323
+ // This is safe, there is no code path that leads to this function
3324
+ // being invoked before handle has been assigned.
3325
+ // eslint-disable-next-line no-use-before-define
3326
+ clock.clearTimeout(handle);
3327
+ reject(options.signal.reason);
3328
+ };
3329
+
3330
+ const handle = clock.setTimeout(() => {
3331
+ if (options.signal) {
3332
+ options.signal.removeEventListener(
3333
+ "abort",
3334
+ abort,
3335
+ );
3336
+ clock.abortListenerMap.delete(abort);
3337
+ }
3338
+
3339
+ resolve(value);
3340
+ }, delay);
3341
+
3342
+ if (options.signal) {
3343
+ if (options.signal.aborted) {
3344
+ abort();
3345
+ } else {
3346
+ options.signal.addEventListener(
3347
+ "abort",
3348
+ abort,
3349
+ );
3350
+ clock.abortListenerMap.set(
3351
+ abort,
3352
+ options.signal,
3353
+ );
3354
+ }
3355
+ }
3356
+ });
3357
+ } else if (nameOfMethodToReplace === "setImmediate") {
3358
+ clock.timersPromisesModuleMethods.push({
3359
+ methodName: "setImmediate",
3360
+ original: timersPromisesModule.setImmediate,
3361
+ });
3362
+
3363
+ timersPromisesModule.setImmediate = (value, options = {}) =>
3364
+ new Promise((resolve, reject) => {
3365
+ const abort = () => {
3366
+ options.signal.removeEventListener(
3367
+ "abort",
3368
+ abort,
3369
+ );
3370
+ clock.abortListenerMap.delete(abort);
3371
+
3372
+ // This is safe, there is no code path that leads to this function
3373
+ // being invoked before handle has been assigned.
3374
+ // eslint-disable-next-line no-use-before-define
3375
+ clock.clearImmediate(handle);
3376
+ reject(options.signal.reason);
3377
+ };
3378
+
3379
+ const handle = clock.setImmediate(() => {
3380
+ if (options.signal) {
3381
+ options.signal.removeEventListener(
3382
+ "abort",
3383
+ abort,
3384
+ );
3385
+ clock.abortListenerMap.delete(abort);
3386
+ }
3387
+
3388
+ resolve(value);
3389
+ });
3390
+
3391
+ if (options.signal) {
3392
+ if (options.signal.aborted) {
3393
+ abort();
3394
+ } else {
3395
+ options.signal.addEventListener(
3396
+ "abort",
3397
+ abort,
3398
+ );
3399
+ clock.abortListenerMap.set(
3400
+ abort,
3401
+ options.signal,
3402
+ );
3403
+ }
3404
+ }
3405
+ });
3406
+ } else if (nameOfMethodToReplace === "setInterval") {
3407
+ clock.timersPromisesModuleMethods.push({
3408
+ methodName: "setInterval",
3409
+ original: timersPromisesModule.setInterval,
3410
+ });
3411
+
3412
+ timersPromisesModule.setInterval = (
3413
+ delay,
3414
+ value,
3415
+ options = {},
3416
+ ) => ({
3417
+ [Symbol.asyncIterator]: () => {
3418
+ const createResolvable = () => {
3419
+ let resolve, reject;
3420
+ const promise = new Promise((res, rej) => {
3421
+ resolve = res;
3422
+ reject = rej;
3423
+ });
3424
+ promise.resolve = resolve;
3425
+ promise.reject = reject;
3426
+ return promise;
3427
+ };
3428
+
3429
+ let done = false;
3430
+ let hasThrown = false;
3431
+ let returnCall;
3432
+ let nextAvailable = 0;
3433
+ const nextQueue = [];
3434
+
3435
+ const handle = clock.setInterval(() => {
3436
+ if (nextQueue.length > 0) {
3437
+ nextQueue.shift().resolve();
3438
+ } else {
3439
+ nextAvailable++;
3440
+ }
3441
+ }, delay);
3442
+
3443
+ const abort = () => {
3444
+ options.signal.removeEventListener(
3445
+ "abort",
3446
+ abort,
3447
+ );
3448
+ clock.abortListenerMap.delete(abort);
3449
+
3450
+ clock.clearInterval(handle);
3451
+ done = true;
3452
+ for (const resolvable of nextQueue) {
3453
+ resolvable.resolve();
3454
+ }
3455
+ };
3456
+
3457
+ if (options.signal) {
3458
+ if (options.signal.aborted) {
3459
+ done = true;
3460
+ } else {
3461
+ options.signal.addEventListener(
3462
+ "abort",
3463
+ abort,
3464
+ );
3465
+ clock.abortListenerMap.set(
3466
+ abort,
3467
+ options.signal,
3468
+ );
3469
+ }
3470
+ }
3471
+
3472
+ return {
3473
+ next: async () => {
3474
+ if (options.signal?.aborted && !hasThrown) {
3475
+ hasThrown = true;
3476
+ throw options.signal.reason;
3477
+ }
3478
+
3479
+ if (done) {
3480
+ return { done: true, value: undefined };
3481
+ }
3482
+
3483
+ if (nextAvailable > 0) {
3484
+ nextAvailable--;
3485
+ return { done: false, value: value };
3486
+ }
3487
+
3488
+ const resolvable = createResolvable();
3489
+ nextQueue.push(resolvable);
3490
+
3491
+ await resolvable;
3492
+
3493
+ if (returnCall && nextQueue.length === 0) {
3494
+ returnCall.resolve();
3495
+ }
3496
+
3497
+ if (options.signal?.aborted && !hasThrown) {
3498
+ hasThrown = true;
3499
+ throw options.signal.reason;
3500
+ }
3501
+
3502
+ if (done) {
3503
+ return { done: true, value: undefined };
3504
+ }
3505
+
3506
+ return { done: false, value: value };
3507
+ },
3508
+ return: async () => {
3509
+ if (done) {
3510
+ return { done: true, value: undefined };
3511
+ }
3512
+
3513
+ if (nextQueue.length > 0) {
3514
+ returnCall = createResolvable();
3515
+ await returnCall;
3516
+ }
3517
+
3518
+ clock.clearInterval(handle);
3519
+ done = true;
3520
+
3521
+ if (options.signal) {
3522
+ options.signal.removeEventListener(
3523
+ "abort",
3524
+ abort,
3525
+ );
3526
+ clock.abortListenerMap.delete(abort);
3527
+ }
3528
+
3529
+ return { done: true, value: undefined };
3530
+ },
3531
+ };
3532
+ },
3533
+ });
3534
+ }
3535
+ }
3536
+ }
3537
+
3538
+ return clock;
3539
+ }
3540
+
3541
+ /* eslint-enable complexity */
3542
+
3543
+ return {
3544
+ timers: timers,
3545
+ createClock: createClock,
3546
+ install: install,
3547
+ withGlobal: withGlobal,
3548
+ };
3549
+ }
3550
+
3551
+ /**
3552
+ * @typedef {object} FakeTimers
3553
+ * @property {Timers} timers
3554
+ * @property {createClock} createClock
3555
+ * @property {Function} install
3556
+ * @property {withGlobal} withGlobal
3557
+ */
3558
+
3559
+ /* eslint-enable complexity */
3560
+
3561
+ /** @type {FakeTimers} */
3562
+ const defaultImplementation = withGlobal(globalObject);
3563
+
3564
+ fakeTimersSrc.timers = defaultImplementation.timers;
3565
+ fakeTimersSrc.createClock = defaultImplementation.createClock;
3566
+ fakeTimersSrc.install = defaultImplementation.install;
3567
+ fakeTimersSrc.withGlobal = withGlobal;
3568
+ return fakeTimersSrc;
3569
+ }
3570
+
3571
+ var fakeTimersSrcExports = requireFakeTimersSrc();
3572
+
3573
+ class FakeTimers {
3574
+ _global;
3575
+ _clock;
3576
+ // | _fakingTime | _fakingDate |
3577
+ // +-------------+-------------+
3578
+ // | false | falsy | initial
3579
+ // | false | truthy | vi.setSystemTime called first (for mocking only Date without fake timers)
3580
+ // | true | falsy | vi.useFakeTimers called first
3581
+ // | true | truthy | unreachable
3582
+ _fakingTime;
3583
+ _fakingDate;
3584
+ _fakeTimers;
3585
+ _userConfig;
3586
+ _now = RealDate.now;
3587
+ constructor({ global, config }) {
3588
+ this._userConfig = config;
3589
+ this._fakingDate = null;
3590
+ this._fakingTime = false;
3591
+ this._fakeTimers = fakeTimersSrcExports.withGlobal(global);
3592
+ this._global = global;
3593
+ }
3594
+ clearAllTimers() {
3595
+ if (this._fakingTime) this._clock.reset();
3596
+ }
3597
+ dispose() {
3598
+ this.useRealTimers();
3599
+ }
3600
+ runAllTimers() {
3601
+ if (this._checkFakeTimers()) this._clock.runAll();
3602
+ }
3603
+ async runAllTimersAsync() {
3604
+ if (this._checkFakeTimers()) await this._clock.runAllAsync();
3605
+ }
3606
+ runOnlyPendingTimers() {
3607
+ if (this._checkFakeTimers()) this._clock.runToLast();
3608
+ }
3609
+ async runOnlyPendingTimersAsync() {
3610
+ if (this._checkFakeTimers()) await this._clock.runToLastAsync();
3611
+ }
3612
+ advanceTimersToNextTimer(steps = 1) {
3613
+ if (this._checkFakeTimers()) for (let i = steps; i > 0; i--) {
3614
+ this._clock.next();
3615
+ // Fire all timers at this point: https://github.com/sinonjs/fake-timers/issues/250
3616
+ this._clock.tick(0);
3617
+ if (this._clock.countTimers() === 0) break;
3618
+ }
3619
+ }
3620
+ async advanceTimersToNextTimerAsync(steps = 1) {
3621
+ if (this._checkFakeTimers()) for (let i = steps; i > 0; i--) {
3622
+ await this._clock.nextAsync();
3623
+ // Fire all timers at this point: https://github.com/sinonjs/fake-timers/issues/250
3624
+ this._clock.tick(0);
3625
+ if (this._clock.countTimers() === 0) break;
3626
+ }
3627
+ }
3628
+ advanceTimersByTime(msToRun) {
3629
+ if (this._checkFakeTimers()) this._clock.tick(msToRun);
3630
+ }
3631
+ async advanceTimersByTimeAsync(msToRun) {
3632
+ if (this._checkFakeTimers()) await this._clock.tickAsync(msToRun);
3633
+ }
3634
+ advanceTimersToNextFrame() {
3635
+ if (this._checkFakeTimers()) this._clock.runToFrame();
3636
+ }
3637
+ runAllTicks() {
3638
+ if (this._checkFakeTimers())
3639
+ // @ts-expect-error method not exposed
3640
+ this._clock.runMicrotasks();
3641
+ }
3642
+ useRealTimers() {
3643
+ if (this._fakingDate) {
3644
+ resetDate();
3645
+ this._fakingDate = null;
3646
+ }
3647
+ if (this._fakingTime) {
3648
+ this._clock.uninstall();
3649
+ this._fakingTime = false;
3650
+ }
3651
+ }
3652
+ useFakeTimers() {
3653
+ if (this._fakingDate) throw new Error("\"setSystemTime\" was called already and date was mocked. Reset timers using `vi.useRealTimers()` if you want to use fake timers again.");
3654
+ if (!this._fakingTime) {
3655
+ const toFake = Object.keys(this._fakeTimers.timers).filter((timer) => timer !== "nextTick" && timer !== "queueMicrotask");
3656
+ if (this._userConfig?.toFake?.includes("nextTick") && isChildProcess()) throw new Error("process.nextTick cannot be mocked inside child_process");
3657
+ this._clock = this._fakeTimers.install({
3658
+ now: Date.now(),
3659
+ ...this._userConfig,
3660
+ toFake: this._userConfig?.toFake || toFake,
3661
+ ignoreMissingTimers: true
3662
+ });
3663
+ this._fakingTime = true;
3664
+ }
3665
+ }
3666
+ reset() {
3667
+ if (this._checkFakeTimers()) {
3668
+ const { now } = this._clock;
3669
+ this._clock.reset();
3670
+ this._clock.setSystemTime(now);
3671
+ }
3672
+ }
3673
+ setSystemTime(now) {
3674
+ const date = typeof now === "undefined" || now instanceof Date ? now : new Date(now);
3675
+ if (this._fakingTime) this._clock.setSystemTime(date);
3676
+ else {
3677
+ this._fakingDate = date ?? new Date(this.getRealSystemTime());
3678
+ mockDate(this._fakingDate);
3679
+ }
3680
+ }
3681
+ getMockedSystemTime() {
3682
+ return this._fakingTime ? new Date(this._clock.now) : this._fakingDate;
3683
+ }
3684
+ getRealSystemTime() {
3685
+ return this._now();
3686
+ }
3687
+ getTimerCount() {
3688
+ if (this._checkFakeTimers()) return this._clock.countTimers();
3689
+ return 0;
3690
+ }
3691
+ configure(config) {
3692
+ this._userConfig = config;
3693
+ }
3694
+ isFakeTimers() {
3695
+ return this._fakingTime;
3696
+ }
3697
+ _checkFakeTimers() {
3698
+ if (!this._fakingTime) throw new Error("Timers are not mocked. Try calling \"vi.useFakeTimers()\" first.");
3699
+ return this._fakingTime;
3700
+ }
3701
+ }
3702
+
3703
+ function copyStackTrace(target, source) {
3704
+ if (source.stack !== void 0) target.stack = source.stack.replace(source.message, target.message);
3705
+ return target;
3706
+ }
3707
+ function waitFor(callback, options = {}) {
3708
+ const { setTimeout, setInterval, clearTimeout, clearInterval } = getSafeTimers();
3709
+ const { interval = 50, timeout = 1e3 } = typeof options === "number" ? { timeout: options } : options;
3710
+ const STACK_TRACE_ERROR = new Error("STACK_TRACE_ERROR");
3711
+ return new Promise((resolve, reject) => {
3712
+ let lastError;
3713
+ let promiseStatus = "idle";
3714
+ let timeoutId;
3715
+ let intervalId;
3716
+ const onResolve = (result) => {
3717
+ if (timeoutId) clearTimeout(timeoutId);
3718
+ if (intervalId) clearInterval(intervalId);
3719
+ resolve(result);
3720
+ };
3721
+ const handleTimeout = () => {
3722
+ if (intervalId) clearInterval(intervalId);
3723
+ let error = lastError;
3724
+ if (!error) error = copyStackTrace(new Error("Timed out in waitFor!"), STACK_TRACE_ERROR);
3725
+ reject(error);
3726
+ };
3727
+ const checkCallback = () => {
3728
+ if (vi.isFakeTimers()) vi.advanceTimersByTime(interval);
3729
+ if (promiseStatus === "pending") return;
3730
+ try {
3731
+ const result = callback();
3732
+ if (result !== null && typeof result === "object" && typeof result.then === "function") {
3733
+ const thenable = result;
3734
+ promiseStatus = "pending";
3735
+ thenable.then((resolvedValue) => {
3736
+ promiseStatus = "resolved";
3737
+ onResolve(resolvedValue);
3738
+ }, (rejectedValue) => {
3739
+ promiseStatus = "rejected";
3740
+ lastError = rejectedValue;
3741
+ });
3742
+ } else {
3743
+ onResolve(result);
3744
+ return true;
3745
+ }
3746
+ } catch (error) {
3747
+ lastError = error;
3748
+ }
3749
+ };
3750
+ if (checkCallback() === true) return;
3751
+ timeoutId = setTimeout(handleTimeout, timeout);
3752
+ intervalId = setInterval(checkCallback, interval);
3753
+ });
3754
+ }
3755
+ function waitUntil(callback, options = {}) {
3756
+ const { setTimeout, setInterval, clearTimeout, clearInterval } = getSafeTimers();
3757
+ const { interval = 50, timeout = 1e3 } = typeof options === "number" ? { timeout: options } : options;
3758
+ const STACK_TRACE_ERROR = new Error("STACK_TRACE_ERROR");
3759
+ return new Promise((resolve, reject) => {
3760
+ let promiseStatus = "idle";
3761
+ let timeoutId;
3762
+ let intervalId;
3763
+ const onReject = (error) => {
3764
+ if (intervalId) clearInterval(intervalId);
3765
+ if (!error) error = copyStackTrace(new Error("Timed out in waitUntil!"), STACK_TRACE_ERROR);
3766
+ reject(error);
3767
+ };
3768
+ const onResolve = (result) => {
3769
+ if (!result) return;
3770
+ if (timeoutId) clearTimeout(timeoutId);
3771
+ if (intervalId) clearInterval(intervalId);
3772
+ resolve(result);
3773
+ return true;
3774
+ };
3775
+ const checkCallback = () => {
3776
+ if (vi.isFakeTimers()) vi.advanceTimersByTime(interval);
3777
+ if (promiseStatus === "pending") return;
3778
+ try {
3779
+ const result = callback();
3780
+ if (result !== null && typeof result === "object" && typeof result.then === "function") {
3781
+ const thenable = result;
3782
+ promiseStatus = "pending";
3783
+ thenable.then((resolvedValue) => {
3784
+ promiseStatus = "resolved";
3785
+ onResolve(resolvedValue);
3786
+ }, (rejectedValue) => {
3787
+ promiseStatus = "rejected";
3788
+ onReject(rejectedValue);
3789
+ });
3790
+ } else return onResolve(result);
3791
+ } catch (error) {
3792
+ onReject(error);
3793
+ }
3794
+ };
3795
+ if (checkCallback() === true) return;
3796
+ timeoutId = setTimeout(onReject, timeout);
3797
+ intervalId = setInterval(checkCallback, interval);
3798
+ });
3799
+ }
3800
+
3801
+ function createVitest() {
3802
+ let _config = null;
3803
+ const workerState = getWorkerState();
3804
+ let _timers;
3805
+ const timers = () => _timers ||= new FakeTimers({
3806
+ global: globalThis,
3807
+ config: workerState.config.fakeTimers
3808
+ });
3809
+ const _stubsGlobal = /* @__PURE__ */ new Map();
3810
+ const _stubsEnv = /* @__PURE__ */ new Map();
3811
+ const _envBooleans = [
3812
+ "PROD",
3813
+ "DEV",
3814
+ "SSR"
3815
+ ];
3816
+ const utils = {
3817
+ useFakeTimers(config) {
3818
+ if (isChildProcess()) {
3819
+ if (config?.toFake?.includes("nextTick") || workerState.config?.fakeTimers?.toFake?.includes("nextTick")) throw new Error("vi.useFakeTimers({ toFake: [\"nextTick\"] }) is not supported in node:child_process. Use --pool=threads if mocking nextTick is required.");
3820
+ }
3821
+ if (config) timers().configure({
3822
+ ...workerState.config.fakeTimers,
3823
+ ...config
3824
+ });
3825
+ else timers().configure(workerState.config.fakeTimers);
3826
+ timers().useFakeTimers();
3827
+ return utils;
3828
+ },
3829
+ isFakeTimers() {
3830
+ return timers().isFakeTimers();
3831
+ },
3832
+ useRealTimers() {
3833
+ timers().useRealTimers();
3834
+ return utils;
3835
+ },
3836
+ runOnlyPendingTimers() {
3837
+ timers().runOnlyPendingTimers();
3838
+ return utils;
3839
+ },
3840
+ async runOnlyPendingTimersAsync() {
3841
+ await timers().runOnlyPendingTimersAsync();
3842
+ return utils;
3843
+ },
3844
+ runAllTimers() {
3845
+ timers().runAllTimers();
3846
+ return utils;
3847
+ },
3848
+ async runAllTimersAsync() {
3849
+ await timers().runAllTimersAsync();
3850
+ return utils;
3851
+ },
3852
+ runAllTicks() {
3853
+ timers().runAllTicks();
3854
+ return utils;
3855
+ },
3856
+ advanceTimersByTime(ms) {
3857
+ timers().advanceTimersByTime(ms);
3858
+ return utils;
3859
+ },
3860
+ async advanceTimersByTimeAsync(ms) {
3861
+ await timers().advanceTimersByTimeAsync(ms);
3862
+ return utils;
3863
+ },
3864
+ advanceTimersToNextTimer() {
3865
+ timers().advanceTimersToNextTimer();
3866
+ return utils;
3867
+ },
3868
+ async advanceTimersToNextTimerAsync() {
3869
+ await timers().advanceTimersToNextTimerAsync();
3870
+ return utils;
3871
+ },
3872
+ advanceTimersToNextFrame() {
3873
+ timers().advanceTimersToNextFrame();
3874
+ return utils;
3875
+ },
3876
+ getTimerCount() {
3877
+ return timers().getTimerCount();
3878
+ },
3879
+ setSystemTime(time) {
3880
+ timers().setSystemTime(time);
3881
+ return utils;
3882
+ },
3883
+ getMockedSystemTime() {
3884
+ return timers().getMockedSystemTime();
3885
+ },
3886
+ getRealSystemTime() {
3887
+ return timers().getRealSystemTime();
3888
+ },
3889
+ clearAllTimers() {
3890
+ timers().clearAllTimers();
3891
+ return utils;
3892
+ },
3893
+ spyOn,
3894
+ fn,
3895
+ waitFor,
3896
+ waitUntil,
3897
+ hoisted(factory) {
3898
+ assertTypes(factory, "\"vi.hoisted\" factory", ["function"]);
3899
+ return factory();
3900
+ },
3901
+ mock(path, factory) {
3902
+ if (typeof path !== "string") throw new TypeError(`vi.mock() expects a string path, but received a ${typeof path}`);
3903
+ const importer = getImporter("mock");
3904
+ _mocker().queueMock(path, importer, typeof factory === "function" ? () => factory(() => _mocker().importActual(path, importer, _mocker().getMockContext().callstack)) : factory);
3905
+ },
3906
+ unmock(path) {
3907
+ if (typeof path !== "string") throw new TypeError(`vi.unmock() expects a string path, but received a ${typeof path}`);
3908
+ _mocker().queueUnmock(path, getImporter("unmock"));
3909
+ },
3910
+ doMock(path, factory) {
3911
+ if (typeof path !== "string") throw new TypeError(`vi.doMock() expects a string path, but received a ${typeof path}`);
3912
+ const importer = getImporter("doMock");
3913
+ _mocker().queueMock(path, importer, typeof factory === "function" ? () => factory(() => _mocker().importActual(path, importer, _mocker().getMockContext().callstack)) : factory);
3914
+ },
3915
+ doUnmock(path) {
3916
+ if (typeof path !== "string") throw new TypeError(`vi.doUnmock() expects a string path, but received a ${typeof path}`);
3917
+ _mocker().queueUnmock(path, getImporter("doUnmock"));
3918
+ },
3919
+ async importActual(path) {
3920
+ return _mocker().importActual(path, getImporter("importActual"), _mocker().getMockContext().callstack);
3921
+ },
3922
+ async importMock(path) {
3923
+ return _mocker().importMock(path, getImporter("importMock"));
3924
+ },
3925
+ mockObject(value) {
3926
+ return _mocker().mockObject({ value }).value;
3927
+ },
3928
+ mocked(item, _options = {}) {
3929
+ return item;
3930
+ },
3931
+ isMockFunction(fn) {
3932
+ return isMockFunction(fn);
3933
+ },
3934
+ clearAllMocks() {
3935
+ [...mocks].reverse().forEach((spy) => spy.mockClear());
3936
+ return utils;
3937
+ },
3938
+ resetAllMocks() {
3939
+ [...mocks].reverse().forEach((spy) => spy.mockReset());
3940
+ return utils;
3941
+ },
3942
+ restoreAllMocks() {
3943
+ [...mocks].reverse().forEach((spy) => spy.mockRestore());
3944
+ return utils;
3945
+ },
3946
+ stubGlobal(name, value) {
3947
+ if (!_stubsGlobal.has(name)) _stubsGlobal.set(name, Object.getOwnPropertyDescriptor(globalThis, name));
3948
+ Object.defineProperty(globalThis, name, {
3949
+ value,
3950
+ writable: true,
3951
+ configurable: true,
3952
+ enumerable: true
3953
+ });
3954
+ return utils;
3955
+ },
3956
+ stubEnv(name, value) {
3957
+ if (!_stubsEnv.has(name)) _stubsEnv.set(name, process.env[name]);
3958
+ if (_envBooleans.includes(name)) process.env[name] = value ? "1" : "";
3959
+ else if (value === void 0) delete process.env[name];
3960
+ else process.env[name] = String(value);
3961
+ return utils;
3962
+ },
3963
+ unstubAllGlobals() {
3964
+ _stubsGlobal.forEach((original, name) => {
3965
+ if (!original) Reflect.deleteProperty(globalThis, name);
3966
+ else Object.defineProperty(globalThis, name, original);
3967
+ });
3968
+ _stubsGlobal.clear();
3969
+ return utils;
3970
+ },
3971
+ unstubAllEnvs() {
3972
+ _stubsEnv.forEach((original, name) => {
3973
+ if (original === void 0) delete process.env[name];
3974
+ else process.env[name] = original;
3975
+ });
3976
+ _stubsEnv.clear();
3977
+ return utils;
3978
+ },
3979
+ resetModules() {
3980
+ resetModules(workerState.moduleCache);
3981
+ return utils;
3982
+ },
3983
+ async dynamicImportSettled() {
3984
+ return waitForImportsToResolve();
3985
+ },
3986
+ setConfig(config) {
3987
+ if (!_config) _config = { ...workerState.config };
3988
+ Object.assign(workerState.config, config);
3989
+ },
3990
+ resetConfig() {
3991
+ if (_config) Object.assign(workerState.config, _config);
3992
+ }
3993
+ };
3994
+ return utils;
3995
+ }
3996
+ const vitest = createVitest();
3997
+ const vi = vitest;
3998
+ function _mocker() {
3999
+ // @ts-expect-error injected by vite-nide
4000
+ return typeof __vitest_mocker__ !== "undefined" ? __vitest_mocker__ : new Proxy({}, { get(_, name) {
4001
+ throw new Error(`Vitest mocker was not initialized in this environment. vi.${String(name)}() is forbidden.`);
4002
+ } });
4003
+ }
4004
+ function getImporter(name) {
4005
+ const stackTrace = createSimpleStackTrace({ stackTraceLimit: 5 });
4006
+ const stackArray = stackTrace.split("\n");
4007
+ // if there is no message in a stack trace, use the item - 1
4008
+ const importerStackIndex = stackArray.findIndex((stack) => {
4009
+ return stack.includes(` at Object.${name}`) || stack.includes(`${name}@`);
4010
+ });
4011
+ const stack = parseSingleStack(stackArray[importerStackIndex + 1]);
4012
+ return stack?.file || "";
4013
+ }
4014
+
4015
+ export { globalExpect as a, vitest as b, createExpect as c, getSnapshotClient as g, inject as i, vi as v };