@lostgradient/weft 0.2.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 (1075) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +493 -0
  3. package/dist/alerting/alert-manager.d.ts +42 -0
  4. package/dist/alerting/alert-manager.js +167 -0
  5. package/dist/alerting/index.d.ts +2 -0
  6. package/dist/alerting/index.js +1 -0
  7. package/dist/alerting/sliding-window.d.ts +26 -0
  8. package/dist/alerting/sliding-window.js +97 -0
  9. package/dist/alerting/types.d.ts +157 -0
  10. package/dist/alerting/types.js +0 -0
  11. package/dist/cli/api-arguments.d.ts +2 -0
  12. package/dist/cli/api-arguments.js +48 -0
  13. package/dist/cli/api.d.ts +13 -0
  14. package/dist/cli/api.js +191 -0
  15. package/dist/cli/codegen-arguments.d.ts +10 -0
  16. package/dist/cli/codegen-arguments.js +50 -0
  17. package/dist/cli/codegen-emit-keywords.d.ts +28 -0
  18. package/dist/cli/codegen-emit-keywords.js +48 -0
  19. package/dist/cli/codegen-emit.d.ts +50 -0
  20. package/dist/cli/codegen-emit.js +280 -0
  21. package/dist/cli/codegen.d.ts +38 -0
  22. package/dist/cli/codegen.js +268 -0
  23. package/dist/cli/command-suggestions.d.ts +9 -0
  24. package/dist/cli/command-suggestions.js +27 -0
  25. package/dist/cli/completions.d.ts +17 -0
  26. package/dist/cli/completions.js +112 -0
  27. package/dist/cli/conformance.d.ts +9 -0
  28. package/dist/cli/conformance.js +226 -0
  29. package/dist/cli/doctor.d.ts +6 -0
  30. package/dist/cli/doctor.js +9 -0
  31. package/dist/cli/generated/operation-client.generated.d.ts +605 -0
  32. package/dist/cli/generated/operation-client.generated.js +60 -0
  33. package/dist/cli/help-text.d.ts +13 -0
  34. package/dist/cli/help-text.js +269 -0
  35. package/dist/cli/index.d.ts +23 -0
  36. package/dist/cli/index.js +34 -0
  37. package/dist/cli/json-rpc-client.d.ts +15 -0
  38. package/dist/cli/json-rpc-client.js +37 -0
  39. package/dist/cli/noun-verb-arguments.d.ts +15 -0
  40. package/dist/cli/noun-verb-arguments.js +190 -0
  41. package/dist/cli/operation-catalog-snapshot.d.ts +38 -0
  42. package/dist/cli/operation-catalog-snapshot.js +48 -0
  43. package/dist/cli/operation-client-runtime.d.ts +47 -0
  44. package/dist/cli/operation-client-runtime.js +33 -0
  45. package/dist/cli/output.d.ts +66 -0
  46. package/dist/cli/output.js +83 -0
  47. package/dist/cli/parse-arguments.d.ts +3 -0
  48. package/dist/cli/parse-arguments.js +214 -0
  49. package/dist/cli/parse-schedule-arguments.d.ts +9 -0
  50. package/dist/cli/parse-schedule-arguments.js +132 -0
  51. package/dist/cli/schedule.d.ts +3 -0
  52. package/dist/cli/schedule.js +128 -0
  53. package/dist/cli/serve-registrations.d.ts +15 -0
  54. package/dist/cli/serve-registrations.js +23 -0
  55. package/dist/cli/server-client.d.ts +45 -0
  56. package/dist/cli/server-client.js +33 -0
  57. package/dist/cli/server-commands.d.ts +19 -0
  58. package/dist/cli/server-commands.js +151 -0
  59. package/dist/cli/storage-backend-arguments.d.ts +15 -0
  60. package/dist/cli/storage-backend-arguments.js +16 -0
  61. package/dist/cli/storage-factory.d.ts +8 -0
  62. package/dist/cli/storage-factory.js +18 -0
  63. package/dist/cli/subcommand-detection.d.ts +2 -0
  64. package/dist/cli/subcommand-detection.js +38 -0
  65. package/dist/cli/tail.d.ts +50 -0
  66. package/dist/cli/tail.js +161 -0
  67. package/dist/cli/timeline.d.ts +9 -0
  68. package/dist/cli/timeline.js +78 -0
  69. package/dist/cli/types.d.ts +224 -0
  70. package/dist/cli/types.js +0 -0
  71. package/dist/cli/utilities.d.ts +9 -0
  72. package/dist/cli/utilities.js +120 -0
  73. package/dist/cli/validate.d.ts +6 -0
  74. package/dist/cli/validate.js +70 -0
  75. package/dist/cli/version-check.d.ts +7 -0
  76. package/dist/cli/version-check.js +16 -0
  77. package/dist/cli/version.d.ts +7 -0
  78. package/dist/cli/version.js +4 -0
  79. package/dist/cli/workflow-commands.d.ts +15 -0
  80. package/dist/cli/workflow-commands.js +195 -0
  81. package/dist/cli-main.d.ts +2 -0
  82. package/dist/cli-main.js +402 -0
  83. package/dist/client/event-stream-transport.d.ts +73 -0
  84. package/dist/client/event-stream-transport.js +59 -0
  85. package/dist/client/event-stream.d.ts +90 -0
  86. package/dist/client/event-stream.js +221 -0
  87. package/dist/client/event-tail.d.ts +50 -0
  88. package/dist/client/event-tail.js +0 -0
  89. package/dist/client/handle-delegation.d.ts +73 -0
  90. package/dist/client/handle-delegation.js +66 -0
  91. package/dist/client/http-client-requests.d.ts +65 -0
  92. package/dist/client/http-client-requests.js +178 -0
  93. package/dist/client/http-client.d.ts +130 -0
  94. package/dist/client/http-client.js +217 -0
  95. package/dist/client/http-handle.d.ts +27 -0
  96. package/dist/client/http-handle.js +43 -0
  97. package/dist/client/http-operations.d.ts +29 -0
  98. package/dist/client/http-operations.js +36 -0
  99. package/dist/client/http-request.d.ts +101 -0
  100. package/dist/client/http-request.js +73 -0
  101. package/dist/client/http-schedule-handle.d.ts +5 -0
  102. package/dist/client/http-schedule-handle.js +5 -0
  103. package/dist/client/in-process-operations.d.ts +30 -0
  104. package/dist/client/in-process-operations.js +17 -0
  105. package/dist/client/index.d.ts +15 -0
  106. package/dist/client/index.js +2 -0
  107. package/dist/client/interface.d.ts +333 -0
  108. package/dist/client/interface.js +0 -0
  109. package/dist/client/local-event-tail.d.ts +30 -0
  110. package/dist/client/local-event-tail.js +131 -0
  111. package/dist/client/local.d.ts +115 -0
  112. package/dist/client/local.js +178 -0
  113. package/dist/client/open-event-subscription.d.ts +33 -0
  114. package/dist/client/open-event-subscription.js +5 -0
  115. package/dist/client/schedule-list-search-params.d.ts +3 -0
  116. package/dist/client/schedule-list-search-params.js +18 -0
  117. package/dist/client/search-params.d.ts +3 -0
  118. package/dist/client/search-params.js +54 -0
  119. package/dist/client/start-body.d.ts +9 -0
  120. package/dist/client/start-body.js +23 -0
  121. package/dist/client/workflow-name-typing.d.ts +33 -0
  122. package/dist/client/workflow-name-typing.js +0 -0
  123. package/dist/connection.d.ts +121 -0
  124. package/dist/connection.js +161 -0
  125. package/dist/core/activity-registry.d.ts +135 -0
  126. package/dist/core/activity-registry.js +174 -0
  127. package/dist/core/activity.d.ts +2 -0
  128. package/dist/core/activity.js +1 -0
  129. package/dist/core/aggregate-validation.d.ts +85 -0
  130. package/dist/core/aggregate-validation.js +48 -0
  131. package/dist/core/atomic-state-events.d.ts +214 -0
  132. package/dist/core/atomic-state-events.js +39 -0
  133. package/dist/core/atomic-state.d.ts +79 -0
  134. package/dist/core/atomic-state.js +231 -0
  135. package/dist/core/bulk-workflow-filter.d.ts +23 -0
  136. package/dist/core/bulk-workflow-filter.js +38 -0
  137. package/dist/core/checkpoint/comparison.d.ts +2 -0
  138. package/dist/core/checkpoint/comparison.js +137 -0
  139. package/dist/core/checkpoint/index.d.ts +4 -0
  140. package/dist/core/checkpoint/index.js +3 -0
  141. package/dist/core/checkpoint/interfaces.d.ts +11 -0
  142. package/dist/core/checkpoint/interfaces.js +0 -0
  143. package/dist/core/checkpoint/lifecycle.d.ts +49 -0
  144. package/dist/core/checkpoint/lifecycle.js +36 -0
  145. package/dist/core/checkpoint/serialization.d.ts +31 -0
  146. package/dist/core/checkpoint/serialization.js +155 -0
  147. package/dist/core/checkpoint/validation.d.ts +4 -0
  148. package/dist/core/checkpoint/validation.js +26 -0
  149. package/dist/core/checkpoint.d.ts +1 -0
  150. package/dist/core/checkpoint.js +1 -0
  151. package/dist/core/codec/api.d.ts +32 -0
  152. package/dist/core/codec/api.js +9 -0
  153. package/dist/core/codec/extension-codec.d.ts +7 -0
  154. package/dist/core/codec/extension-codec.js +145 -0
  155. package/dist/core/codec/index.d.ts +3 -0
  156. package/dist/core/codec/index.js +2 -0
  157. package/dist/core/codec/validation.d.ts +28 -0
  158. package/dist/core/codec/validation.js +139 -0
  159. package/dist/core/codec-helpers.d.ts +8 -0
  160. package/dist/core/codec-helpers.js +19 -0
  161. package/dist/core/codec.d.ts +1 -0
  162. package/dist/core/codec.js +1 -0
  163. package/dist/core/compression.d.ts +127 -0
  164. package/dist/core/compression.js +88 -0
  165. package/dist/core/concurrency-lock-record.d.ts +122 -0
  166. package/dist/core/concurrency-lock-record.js +53 -0
  167. package/dist/core/concurrency.d.ts +221 -0
  168. package/dist/core/concurrency.js +93 -0
  169. package/dist/core/constraint.d.ts +144 -0
  170. package/dist/core/constraint.js +3 -0
  171. package/dist/core/context/attributes.d.ts +7 -0
  172. package/dist/core/context/attributes.js +29 -0
  173. package/dist/core/context/child-workflow-pipe.d.ts +18 -0
  174. package/dist/core/context/child-workflow-pipe.js +111 -0
  175. package/dist/core/context/durable-operations.d.ts +29 -0
  176. package/dist/core/context/durable-operations.js +166 -0
  177. package/dist/core/context/index.d.ts +114 -0
  178. package/dist/core/context/index.js +224 -0
  179. package/dist/core/context/internals.d.ts +30 -0
  180. package/dist/core/context/internals.js +36 -0
  181. package/dist/core/context/operation-request.d.ts +160 -0
  182. package/dist/core/context/operation-request.js +0 -0
  183. package/dist/core/context/parallel-cache-entry.d.ts +91 -0
  184. package/dist/core/context/parallel-cache-entry.js +92 -0
  185. package/dist/core/context/parallel-operations.d.ts +9 -0
  186. package/dist/core/context/parallel-operations.js +202 -0
  187. package/dist/core/context/run-operation.d.ts +21 -0
  188. package/dist/core/context/run-operation.js +231 -0
  189. package/dist/core/context/saga.d.ts +4 -0
  190. package/dist/core/context/saga.js +65 -0
  191. package/dist/core/context/session-state.d.ts +22 -0
  192. package/dist/core/context/session-state.js +154 -0
  193. package/dist/core/context/speculate-operations.d.ts +4 -0
  194. package/dist/core/context/speculate-operations.js +14 -0
  195. package/dist/core/context/speculative-child.d.ts +6 -0
  196. package/dist/core/context/speculative-child.js +67 -0
  197. package/dist/core/context/state-namespace.d.ts +27 -0
  198. package/dist/core/context/state-namespace.js +138 -0
  199. package/dist/core/context/types.d.ts +181 -0
  200. package/dist/core/context/types.js +0 -0
  201. package/dist/core/context/updates.d.ts +46 -0
  202. package/dist/core/context/updates.js +21 -0
  203. package/dist/core/context/validation.d.ts +2 -0
  204. package/dist/core/context/validation.js +12 -0
  205. package/dist/core/context.d.ts +1 -0
  206. package/dist/core/context.js +1 -0
  207. package/dist/core/debug-output.d.ts +3 -0
  208. package/dist/core/debug-output.js +112 -0
  209. package/dist/core/effect-log/index.d.ts +194 -0
  210. package/dist/core/effect-log/index.js +104 -0
  211. package/dist/core/engine/activity-reconciliation.d.ts +108 -0
  212. package/dist/core/engine/activity-reconciliation.js +182 -0
  213. package/dist/core/engine/aggregate.d.ts +47 -0
  214. package/dist/core/engine/aggregate.js +132 -0
  215. package/dist/core/engine/anonymous-signal-sequence.d.ts +4 -0
  216. package/dist/core/engine/anonymous-signal-sequence.js +101 -0
  217. package/dist/core/engine/async-activity-completion.d.ts +141 -0
  218. package/dist/core/engine/async-activity-completion.js +131 -0
  219. package/dist/core/engine/attributes-tags.d.ts +31 -0
  220. package/dist/core/engine/attributes-tags.js +178 -0
  221. package/dist/core/engine/broadcast.d.ts +8 -0
  222. package/dist/core/engine/broadcast.js +26 -0
  223. package/dist/core/engine/bulk-operations-purge.d.ts +11 -0
  224. package/dist/core/engine/bulk-operations-purge.js +246 -0
  225. package/dist/core/engine/bulk-operations-shared.d.ts +28 -0
  226. package/dist/core/engine/bulk-operations-shared.js +198 -0
  227. package/dist/core/engine/bulk-operations.d.ts +21 -0
  228. package/dist/core/engine/bulk-operations.js +128 -0
  229. package/dist/core/engine/callback-creators-bundles.d.ts +25 -0
  230. package/dist/core/engine/callback-creators-bundles.js +154 -0
  231. package/dist/core/engine/callback-creators-core.d.ts +39 -0
  232. package/dist/core/engine/callback-creators-core.js +136 -0
  233. package/dist/core/engine/callback-creators-router-registry.d.ts +4 -0
  234. package/dist/core/engine/callback-creators-router-registry.js +9 -0
  235. package/dist/core/engine/callback-creators-router.d.ts +3 -0
  236. package/dist/core/engine/callback-creators-router.js +68 -0
  237. package/dist/core/engine/callback-creators-schedule.d.ts +13 -0
  238. package/dist/core/engine/callback-creators-schedule.js +65 -0
  239. package/dist/core/engine/callback-creators.d.ts +9 -0
  240. package/dist/core/engine/callback-creators.js +87 -0
  241. package/dist/core/engine/cancel-handlers.d.ts +6 -0
  242. package/dist/core/engine/cancel-handlers.js +32 -0
  243. package/dist/core/engine/checkpoint-commit-snapshots.d.ts +4 -0
  244. package/dist/core/engine/checkpoint-commit-snapshots.js +16 -0
  245. package/dist/core/engine/checkpoint-io.d.ts +34 -0
  246. package/dist/core/engine/checkpoint-io.js +183 -0
  247. package/dist/core/engine/checkpoint-reads.d.ts +22 -0
  248. package/dist/core/engine/checkpoint-reads.js +98 -0
  249. package/dist/core/engine/child-workflow.d.ts +20 -0
  250. package/dist/core/engine/child-workflow.js +72 -0
  251. package/dist/core/engine/completed-review-storage.d.ts +14 -0
  252. package/dist/core/engine/completed-review-storage.js +61 -0
  253. package/dist/core/engine/constraints.d.ts +24 -0
  254. package/dist/core/engine/constraints.js +57 -0
  255. package/dist/core/engine/construction.d.ts +60 -0
  256. package/dist/core/engine/construction.js +213 -0
  257. package/dist/core/engine/disposal.d.ts +9 -0
  258. package/dist/core/engine/disposal.js +58 -0
  259. package/dist/core/engine/engine-create-types.d.ts +70 -0
  260. package/dist/core/engine/engine-create-types.js +0 -0
  261. package/dist/core/engine/engine-internal-types.d.ts +59 -0
  262. package/dist/core/engine/engine-internal-types.js +0 -0
  263. package/dist/core/engine/engine-leak-warnings.d.ts +26 -0
  264. package/dist/core/engine/engine-leak-warnings.js +42 -0
  265. package/dist/core/engine/engine-runtime-helpers.d.ts +8 -0
  266. package/dist/core/engine/engine-runtime-helpers.js +52 -0
  267. package/dist/core/engine/engine-state-namespace.d.ts +20 -0
  268. package/dist/core/engine/engine-state-namespace.js +0 -0
  269. package/dist/core/engine/errors.d.ts +215 -0
  270. package/dist/core/engine/errors.js +90 -0
  271. package/dist/core/engine/event-log-compaction.d.ts +102 -0
  272. package/dist/core/engine/event-log-compaction.js +76 -0
  273. package/dist/core/engine/guards.d.ts +17 -0
  274. package/dist/core/engine/guards.js +43 -0
  275. package/dist/core/engine/handle-iteration.d.ts +2 -0
  276. package/dist/core/engine/handle-iteration.js +59 -0
  277. package/dist/core/engine/handle-result.d.ts +8 -0
  278. package/dist/core/engine/handle-result.js +74 -0
  279. package/dist/core/engine/handles.d.ts +137 -0
  280. package/dist/core/engine/handles.js +173 -0
  281. package/dist/core/engine/index.d.ts +311 -0
  282. package/dist/core/engine/index.js +595 -0
  283. package/dist/core/engine/inline-launch-queue.d.ts +17 -0
  284. package/dist/core/engine/inline-launch-queue.js +93 -0
  285. package/dist/core/engine/inline-parking.d.ts +26 -0
  286. package/dist/core/engine/inline-parking.js +86 -0
  287. package/dist/core/engine/internals.d.ts +167 -0
  288. package/dist/core/engine/internals.js +11 -0
  289. package/dist/core/engine/lifecycle/fork-helpers.d.ts +9 -0
  290. package/dist/core/engine/lifecycle/fork-helpers.js +66 -0
  291. package/dist/core/engine/lifecycle/persist.d.ts +22 -0
  292. package/dist/core/engine/lifecycle/persist.js +80 -0
  293. package/dist/core/engine/lifecycle/resume.d.ts +4 -0
  294. package/dist/core/engine/lifecycle/resume.js +136 -0
  295. package/dist/core/engine/lifecycle/shared.d.ts +79 -0
  296. package/dist/core/engine/lifecycle/shared.js +49 -0
  297. package/dist/core/engine/lifecycle/start-batch.d.ts +7 -0
  298. package/dist/core/engine/lifecycle/start-batch.js +70 -0
  299. package/dist/core/engine/lifecycle/start-exec.d.ts +5 -0
  300. package/dist/core/engine/lifecycle/start-exec.js +39 -0
  301. package/dist/core/engine/lifecycle/start.d.ts +13 -0
  302. package/dist/core/engine/lifecycle/start.js +163 -0
  303. package/dist/core/engine/lifecycle/transition.d.ts +8 -0
  304. package/dist/core/engine/lifecycle/transition.js +183 -0
  305. package/dist/core/engine/lifecycle.d.ts +8 -0
  306. package/dist/core/engine/lifecycle.js +40 -0
  307. package/dist/core/engine/list-candidate-resolution.d.ts +15 -0
  308. package/dist/core/engine/list-candidate-resolution.js +88 -0
  309. package/dist/core/engine/listing.d.ts +17 -0
  310. package/dist/core/engine/listing.js +186 -0
  311. package/dist/core/engine/operations-activity.d.ts +40 -0
  312. package/dist/core/engine/operations-activity.js +194 -0
  313. package/dist/core/engine/operations-coordination.d.ts +39 -0
  314. package/dist/core/engine/operations-coordination.js +162 -0
  315. package/dist/core/engine/operations-data.d.ts +23 -0
  316. package/dist/core/engine/operations-data.js +38 -0
  317. package/dist/core/engine/operations-router.d.ts +75 -0
  318. package/dist/core/engine/operations-router.js +90 -0
  319. package/dist/core/engine/operations-speculate.d.ts +16 -0
  320. package/dist/core/engine/operations-speculate.js +40 -0
  321. package/dist/core/engine/operations-state.d.ts +16 -0
  322. package/dist/core/engine/operations-state.js +27 -0
  323. package/dist/core/engine/operations-stream.d.ts +20 -0
  324. package/dist/core/engine/operations-stream.js +54 -0
  325. package/dist/core/engine/operations-time.d.ts +28 -0
  326. package/dist/core/engine/operations-time.js +167 -0
  327. package/dist/core/engine/parallel-dispatch.d.ts +92 -0
  328. package/dist/core/engine/parallel-dispatch.js +45 -0
  329. package/dist/core/engine/pending-updates.d.ts +18 -0
  330. package/dist/core/engine/pending-updates.js +109 -0
  331. package/dist/core/engine/persisted-data-version.d.ts +24 -0
  332. package/dist/core/engine/persisted-data-version.js +25 -0
  333. package/dist/core/engine/queries.d.ts +3 -0
  334. package/dist/core/engine/queries.js +17 -0
  335. package/dist/core/engine/registration.d.ts +6 -0
  336. package/dist/core/engine/registration.js +107 -0
  337. package/dist/core/engine/retention.d.ts +15 -0
  338. package/dist/core/engine/retention.js +76 -0
  339. package/dist/core/engine/review-list-entries.d.ts +6 -0
  340. package/dist/core/engine/review-list-entries.js +117 -0
  341. package/dist/core/engine/reviews.d.ts +34 -0
  342. package/dist/core/engine/reviews.js +242 -0
  343. package/dist/core/engine/schedule-occurrence.d.ts +35 -0
  344. package/dist/core/engine/schedule-occurrence.js +26 -0
  345. package/dist/core/engine/schedule-timer.d.ts +4 -0
  346. package/dist/core/engine/schedule-timer.js +77 -0
  347. package/dist/core/engine/schedules.d.ts +34 -0
  348. package/dist/core/engine/schedules.js +204 -0
  349. package/dist/core/engine/signals.d.ts +40 -0
  350. package/dist/core/engine/signals.js +185 -0
  351. package/dist/core/engine/speculative-execution-state.d.ts +8 -0
  352. package/dist/core/engine/speculative-execution-state.js +26 -0
  353. package/dist/core/engine/state-utilities.d.ts +62 -0
  354. package/dist/core/engine/state-utilities.js +306 -0
  355. package/dist/core/engine/storage-io.d.ts +21 -0
  356. package/dist/core/engine/storage-io.js +82 -0
  357. package/dist/core/engine/strategy-helpers.d.ts +27 -0
  358. package/dist/core/engine/strategy-helpers.js +47 -0
  359. package/dist/core/engine/stream-chunk-loading.d.ts +5 -0
  360. package/dist/core/engine/stream-chunk-loading.js +22 -0
  361. package/dist/core/engine/sub-operation.d.ts +24 -0
  362. package/dist/core/engine/sub-operation.js +78 -0
  363. package/dist/core/engine/termination/cleanup.d.ts +67 -0
  364. package/dist/core/engine/termination/cleanup.js +167 -0
  365. package/dist/core/engine/termination/complete.d.ts +13 -0
  366. package/dist/core/engine/termination/complete.js +249 -0
  367. package/dist/core/engine/termination.d.ts +7 -0
  368. package/dist/core/engine/termination.js +23 -0
  369. package/dist/core/engine/updates.d.ts +56 -0
  370. package/dist/core/engine/updates.js +230 -0
  371. package/dist/core/engine/validation/schedule.d.ts +38 -0
  372. package/dist/core/engine/validation/schedule.js +258 -0
  373. package/dist/core/engine/validation.d.ts +40 -0
  374. package/dist/core/engine/validation.js +144 -0
  375. package/dist/core/engine/workflow-feed.d.ts +82 -0
  376. package/dist/core/engine/workflow-feed.js +96 -0
  377. package/dist/core/engine/workflow-indexes.d.ts +103 -0
  378. package/dist/core/engine/workflow-indexes.js +93 -0
  379. package/dist/core/engine/workflow-state-stream.d.ts +9 -0
  380. package/dist/core/engine/workflow-state-stream.js +126 -0
  381. package/dist/core/engine/workflow-visibility-queries.d.ts +40 -0
  382. package/dist/core/engine/workflow-visibility-queries.js +56 -0
  383. package/dist/core/engine-helpers.d.ts +56 -0
  384. package/dist/core/engine-helpers.js +52 -0
  385. package/dist/core/engine.d.ts +1 -0
  386. package/dist/core/engine.js +1 -0
  387. package/dist/core/event-log-shared.d.ts +65 -0
  388. package/dist/core/event-log-shared.js +31 -0
  389. package/dist/core/event-log-verify.d.ts +51 -0
  390. package/dist/core/event-log-verify.js +64 -0
  391. package/dist/core/event-log.d.ts +112 -0
  392. package/dist/core/event-log.js +81 -0
  393. package/dist/core/events/activity-events.d.ts +104 -0
  394. package/dist/core/events/activity-events.js +63 -0
  395. package/dist/core/events/attribute-events.d.ts +22 -0
  396. package/dist/core/events/attribute-events.js +10 -0
  397. package/dist/core/events/event-map.d.ts +80 -0
  398. package/dist/core/events/event-map.js +0 -0
  399. package/dist/core/events/index.d.ts +7 -0
  400. package/dist/core/events/index.js +7 -0
  401. package/dist/core/events/signal-events.d.ts +45 -0
  402. package/dist/core/events/signal-events.js +23 -0
  403. package/dist/core/events/system-events.d.ts +149 -0
  404. package/dist/core/events/system-events.js +92 -0
  405. package/dist/core/events/update-events.d.ts +53 -0
  406. package/dist/core/events/update-events.js +31 -0
  407. package/dist/core/events/workflow-events.d.ts +198 -0
  408. package/dist/core/events/workflow-events.js +91 -0
  409. package/dist/core/events.d.ts +1 -0
  410. package/dist/core/events.js +1 -0
  411. package/dist/core/execution-strategy.d.ts +107 -0
  412. package/dist/core/execution-strategy.js +0 -0
  413. package/dist/core/failure-categories.d.ts +18 -0
  414. package/dist/core/failure-categories.js +70 -0
  415. package/dist/core/fault-code.d.ts +92 -0
  416. package/dist/core/fault-code.js +21 -0
  417. package/dist/core/inline-execution-strategy.d.ts +76 -0
  418. package/dist/core/inline-execution-strategy.js +264 -0
  419. package/dist/core/interceptor/activity-composition.d.ts +20 -0
  420. package/dist/core/interceptor/activity-composition.js +17 -0
  421. package/dist/core/interceptor/index.d.ts +25 -0
  422. package/dist/core/interceptor/index.js +8 -0
  423. package/dist/core/interceptor/interception-contexts.d.ts +200 -0
  424. package/dist/core/interceptor/interception-contexts.js +0 -0
  425. package/dist/core/interceptor/interceptor-interfaces.d.ts +149 -0
  426. package/dist/core/interceptor/interceptor-interfaces.js +9 -0
  427. package/dist/core/interceptor/split.d.ts +11 -0
  428. package/dist/core/interceptor/split.js +14 -0
  429. package/dist/core/interceptor/workflow-composition.d.ts +21 -0
  430. package/dist/core/interceptor/workflow-composition.js +116 -0
  431. package/dist/core/interceptor.d.ts +1 -0
  432. package/dist/core/interceptor.js +1 -0
  433. package/dist/core/json.d.ts +56 -0
  434. package/dist/core/json.js +77 -0
  435. package/dist/core/list-filter-validation.d.ts +78 -0
  436. package/dist/core/list-filter-validation.js +75 -0
  437. package/dist/core/payload-size.d.ts +78 -0
  438. package/dist/core/payload-size.js +27 -0
  439. package/dist/core/persisted-data-incompatible-error.d.ts +48 -0
  440. package/dist/core/persisted-data-incompatible-error.js +12 -0
  441. package/dist/core/registry-snapshot.d.ts +69 -0
  442. package/dist/core/registry-snapshot.js +70 -0
  443. package/dist/core/review/events.d.ts +73 -0
  444. package/dist/core/review/events.js +31 -0
  445. package/dist/core/review/index.d.ts +265 -0
  446. package/dist/core/review/index.js +96 -0
  447. package/dist/core/runtime-workflow-engine.d.ts +16 -0
  448. package/dist/core/runtime-workflow-engine.js +6 -0
  449. package/dist/core/schedule/cron-formatter.d.ts +10 -0
  450. package/dist/core/schedule/cron-formatter.js +103 -0
  451. package/dist/core/schedule/cron-occurrence.d.ts +3 -0
  452. package/dist/core/schedule/cron-occurrence.js +129 -0
  453. package/dist/core/schedule/cron-parser.d.ts +2 -0
  454. package/dist/core/schedule/cron-parser.js +93 -0
  455. package/dist/core/schedule/cron-types.d.ts +35 -0
  456. package/dist/core/schedule/cron-types.js +0 -0
  457. package/dist/core/schedule/index.d.ts +3 -0
  458. package/dist/core/schedule/index.js +2 -0
  459. package/dist/core/schedule/interval-occurrence.d.ts +31 -0
  460. package/dist/core/schedule/interval-occurrence.js +26 -0
  461. package/dist/core/schedule.d.ts +1 -0
  462. package/dist/core/schedule.js +1 -0
  463. package/dist/core/scheduler/duration.d.ts +44 -0
  464. package/dist/core/scheduler/duration.js +48 -0
  465. package/dist/core/scheduler/index.d.ts +4 -0
  466. package/dist/core/scheduler/index.js +3 -0
  467. package/dist/core/scheduler/scheduler-class.d.ts +52 -0
  468. package/dist/core/scheduler/scheduler-class.js +167 -0
  469. package/dist/core/scheduler/timer-batch.d.ts +10 -0
  470. package/dist/core/scheduler/timer-batch.js +42 -0
  471. package/dist/core/scheduler/timer-sources.d.ts +17 -0
  472. package/dist/core/scheduler/timer-sources.js +61 -0
  473. package/dist/core/scheduler.d.ts +1 -0
  474. package/dist/core/scheduler.js +1 -0
  475. package/dist/core/search-attributes.d.ts +67 -0
  476. package/dist/core/search-attributes.js +196 -0
  477. package/dist/core/session-state.d.ts +18 -0
  478. package/dist/core/session-state.js +71 -0
  479. package/dist/core/signal-id.d.ts +2 -0
  480. package/dist/core/signal-id.js +10 -0
  481. package/dist/core/start-workflow-validation.d.ts +14 -0
  482. package/dist/core/start-workflow-validation.js +63 -0
  483. package/dist/core/step-context.d.ts +97 -0
  484. package/dist/core/step-context.js +113 -0
  485. package/dist/core/timeouts.d.ts +98 -0
  486. package/dist/core/timeouts.js +38 -0
  487. package/dist/core/types/activity.d.ts +316 -0
  488. package/dist/core/types/activity.js +15 -0
  489. package/dist/core/types/archive-adapter.d.ts +49 -0
  490. package/dist/core/types/archive-adapter.js +0 -0
  491. package/dist/core/types/bulk.d.ts +312 -0
  492. package/dist/core/types/bulk.js +1 -0
  493. package/dist/core/types/checkpoint.d.ts +237 -0
  494. package/dist/core/types/checkpoint.js +12 -0
  495. package/dist/core/types/clone-plain.d.ts +17 -0
  496. package/dist/core/types/clone-plain.js +25 -0
  497. package/dist/core/types/constants.d.ts +54 -0
  498. package/dist/core/types/constants.js +1 -0
  499. package/dist/core/types/deep-freeze.d.ts +31 -0
  500. package/dist/core/types/deep-freeze.js +31 -0
  501. package/dist/core/types/definition-schema-to-json.d.ts +41 -0
  502. package/dist/core/types/definition-schema-to-json.js +56 -0
  503. package/dist/core/types/definition-schema.d.ts +341 -0
  504. package/dist/core/types/definition-schema.js +45 -0
  505. package/dist/core/types/history-policy.d.ts +92 -0
  506. package/dist/core/types/history-policy.js +1 -0
  507. package/dist/core/types/identity.d.ts +55 -0
  508. package/dist/core/types/identity.js +0 -0
  509. package/dist/core/types/message-handles.d.ts +229 -0
  510. package/dist/core/types/message-handles.js +36 -0
  511. package/dist/core/types/name-grammar.d.ts +30 -0
  512. package/dist/core/types/name-grammar.js +9 -0
  513. package/dist/core/types/options.d.ts +360 -0
  514. package/dist/core/types/options.js +0 -0
  515. package/dist/core/types/payload-size-policy.d.ts +47 -0
  516. package/dist/core/types/payload-size-policy.js +0 -0
  517. package/dist/core/types/registry-type-helpers.d.ts +1 -0
  518. package/dist/core/types/registry-type-helpers.js +0 -0
  519. package/dist/core/types/retry-retention.d.ts +163 -0
  520. package/dist/core/types/retry-retention.js +6 -0
  521. package/dist/core/types/reviews.d.ts +170 -0
  522. package/dist/core/types/reviews.js +0 -0
  523. package/dist/core/types/schedules.d.ts +176 -0
  524. package/dist/core/types/schedules.js +3 -0
  525. package/dist/core/types/search-attributes.d.ts +127 -0
  526. package/dist/core/types/search-attributes.js +8 -0
  527. package/dist/core/types/serializer.d.ts +30 -0
  528. package/dist/core/types/serializer.js +0 -0
  529. package/dist/core/types/standard-schema-validate.d.ts +113 -0
  530. package/dist/core/types/standard-schema-validate.js +60 -0
  531. package/dist/core/types/state.d.ts +261 -0
  532. package/dist/core/types/state.js +0 -0
  533. package/dist/core/types/workflow-builder-helpers.d.ts +310 -0
  534. package/dist/core/types/workflow-builder-helpers.js +0 -0
  535. package/dist/core/types/workflow-builder-runtime.d.ts +97 -0
  536. package/dist/core/types/workflow-builder-runtime.js +137 -0
  537. package/dist/core/types/workflow-builder.d.ts +343 -0
  538. package/dist/core/types/workflow-builder.js +0 -0
  539. package/dist/core/types/workflow-context.d.ts +168 -0
  540. package/dist/core/types/workflow-context.js +0 -0
  541. package/dist/core/types/workflow-definition.d.ts +61 -0
  542. package/dist/core/types/workflow-definition.js +0 -0
  543. package/dist/core/types/workflow-function.d.ts +330 -0
  544. package/dist/core/types/workflow-function.js +9 -0
  545. package/dist/core/types/workflow-registries.d.ts +203 -0
  546. package/dist/core/types/workflow-registries.js +0 -0
  547. package/dist/core/types/workflow-registry.d.ts +31 -0
  548. package/dist/core/types/workflow-registry.js +0 -0
  549. package/dist/core/types.d.ts +26 -0
  550. package/dist/core/types.js +26 -0
  551. package/dist/core/updates.d.ts +183 -0
  552. package/dist/core/updates.js +141 -0
  553. package/dist/core/versioning.d.ts +153 -0
  554. package/dist/core/versioning.js +94 -0
  555. package/dist/core/weft-error.d.ts +82 -0
  556. package/dist/core/weft-error.js +43 -0
  557. package/dist/core/worker-checkpoint-resume-state.d.ts +11 -0
  558. package/dist/core/worker-checkpoint-resume-state.js +40 -0
  559. package/dist/core/worker-execution-dispatcher.d.ts +42 -0
  560. package/dist/core/worker-execution-dispatcher.js +95 -0
  561. package/dist/core/worker-execution-ownership.d.ts +20 -0
  562. package/dist/core/worker-execution-ownership.js +91 -0
  563. package/dist/core/worker-execution-strategy-options.d.ts +7 -0
  564. package/dist/core/worker-execution-strategy-options.js +0 -0
  565. package/dist/core/worker-execution-strategy.d.ts +29 -0
  566. package/dist/core/worker-execution-strategy.js +356 -0
  567. package/dist/core/worker-listener-registry.d.ts +11 -0
  568. package/dist/core/worker-listener-registry.js +35 -0
  569. package/dist/core/worker-message-helpers.d.ts +5 -0
  570. package/dist/core/worker-message-helpers.js +14 -0
  571. package/dist/core/worker-protocol-guard.d.ts +20 -0
  572. package/dist/core/worker-protocol-guard.js +69 -0
  573. package/dist/core/worker-protocol.d.ts +27 -0
  574. package/dist/core/worker-protocol.js +346 -0
  575. package/dist/core/worker-turn-watchdog.d.ts +14 -0
  576. package/dist/core/worker-turn-watchdog.js +40 -0
  577. package/dist/core/workflow-identifiers.d.ts +1 -0
  578. package/dist/core/workflow-identifiers.js +19 -0
  579. package/dist/core/workflow-tags.d.ts +9 -0
  580. package/dist/core/workflow-tags.js +37 -0
  581. package/dist/core/workflow-version-tuple.d.ts +67 -0
  582. package/dist/core/workflow-version-tuple.js +77 -0
  583. package/dist/diagnostics/doctor.d.ts +30 -0
  584. package/dist/diagnostics/doctor.js +173 -0
  585. package/dist/diagnostics/format.d.ts +77 -0
  586. package/dist/diagnostics/format.js +115 -0
  587. package/dist/diagnostics/index.d.ts +15 -0
  588. package/dist/diagnostics/index.js +10 -0
  589. package/dist/diagnostics/memory-profiler.d.ts +136 -0
  590. package/dist/diagnostics/memory-profiler.js +93 -0
  591. package/dist/diagnostics/recommendations.d.ts +37 -0
  592. package/dist/diagnostics/recommendations.js +116 -0
  593. package/dist/diagnostics/types.d.ts +178 -0
  594. package/dist/diagnostics/types.js +9 -0
  595. package/dist/diagnostics/validate.d.ts +79 -0
  596. package/dist/diagnostics/validate.js +88 -0
  597. package/dist/diagnostics/version-check.d.ts +34 -0
  598. package/dist/diagnostics/version-check.js +61 -0
  599. package/dist/index.d.ts +109 -0
  600. package/dist/index.js +182 -0
  601. package/dist/json-schema.d.ts +55 -0
  602. package/dist/json-schema.js +4 -0
  603. package/dist/mcp/access.d.ts +21 -0
  604. package/dist/mcp/access.js +22 -0
  605. package/dist/mcp/cli.d.ts +2 -0
  606. package/dist/mcp/cli.js +72 -0
  607. package/dist/mcp/dispatcher.d.ts +13 -0
  608. package/dist/mcp/dispatcher.js +198 -0
  609. package/dist/mcp/http.d.ts +64 -0
  610. package/dist/mcp/http.js +272 -0
  611. package/dist/mcp/index.d.ts +17 -0
  612. package/dist/mcp/index.js +26 -0
  613. package/dist/mcp/list-filter.d.ts +10 -0
  614. package/dist/mcp/list-filter.js +116 -0
  615. package/dist/mcp/protocol.d.ts +89 -0
  616. package/dist/mcp/protocol.js +64 -0
  617. package/dist/mcp/resources.d.ts +40 -0
  618. package/dist/mcp/resources.js +141 -0
  619. package/dist/mcp/session.d.ts +138 -0
  620. package/dist/mcp/session.js +204 -0
  621. package/dist/mcp/stdio.d.ts +89 -0
  622. package/dist/mcp/stdio.js +204 -0
  623. package/dist/mcp/tools.d.ts +27 -0
  624. package/dist/mcp/tools.js +262 -0
  625. package/dist/observability/activity-interceptor.d.ts +3 -0
  626. package/dist/observability/activity-interceptor.js +34 -0
  627. package/dist/observability/index.d.ts +60 -0
  628. package/dist/observability/index.js +4 -0
  629. package/dist/observability/metrics-catalog.d.ts +128 -0
  630. package/dist/observability/metrics-catalog.js +110 -0
  631. package/dist/observability/metrics-snapshot.d.ts +106 -0
  632. package/dist/observability/metrics-snapshot.js +0 -0
  633. package/dist/observability/metrics.d.ts +156 -0
  634. package/dist/observability/metrics.js +152 -0
  635. package/dist/observability/no-op-telemetry.d.ts +168 -0
  636. package/dist/observability/no-op-telemetry.js +96 -0
  637. package/dist/observability/propagation.d.ts +121 -0
  638. package/dist/observability/propagation.js +41 -0
  639. package/dist/observability/span-helpers.d.ts +50 -0
  640. package/dist/observability/span-helpers.js +83 -0
  641. package/dist/observability/types.d.ts +92 -0
  642. package/dist/observability/types.js +0 -0
  643. package/dist/observability/workflow-interceptor.d.ts +3 -0
  644. package/dist/observability/workflow-interceptor.js +106 -0
  645. package/dist/observability/workflow-lifecycle.d.ts +8 -0
  646. package/dist/observability/workflow-lifecycle.js +103 -0
  647. package/dist/runtime/portable.d.ts +119 -0
  648. package/dist/runtime/portable.js +90 -0
  649. package/dist/server/api-catalog.d.ts +85 -0
  650. package/dist/server/api-catalog.js +47 -0
  651. package/dist/server/asyncapi-channels.d.ts +40 -0
  652. package/dist/server/asyncapi-channels.js +264 -0
  653. package/dist/server/asyncapi.d.ts +25 -0
  654. package/dist/server/asyncapi.js +110 -0
  655. package/dist/server/attribute-filters.d.ts +37 -0
  656. package/dist/server/attribute-filters.js +39 -0
  657. package/dist/server/authentication/api-key.d.ts +3 -0
  658. package/dist/server/authentication/api-key.js +80 -0
  659. package/dist/server/authentication/audit.d.ts +116 -0
  660. package/dist/server/authentication/audit.js +25 -0
  661. package/dist/server/authentication/crypto.d.ts +7 -0
  662. package/dist/server/authentication/crypto.js +99 -0
  663. package/dist/server/authentication/index.d.ts +68 -0
  664. package/dist/server/authentication/index.js +144 -0
  665. package/dist/server/authentication/rate-limiter.d.ts +126 -0
  666. package/dist/server/authentication/rate-limiter.js +61 -0
  667. package/dist/server/authentication/redaction.d.ts +72 -0
  668. package/dist/server/authentication/redaction.js +30 -0
  669. package/dist/server/authentication/rotating-api-key-store.d.ts +107 -0
  670. package/dist/server/authentication/rotating-api-key-store.js +43 -0
  671. package/dist/server/authentication/types.d.ts +290 -0
  672. package/dist/server/authentication/types.js +13 -0
  673. package/dist/server/authentication.d.ts +1 -0
  674. package/dist/server/authentication.js +1 -0
  675. package/dist/server/authorization-scope.d.ts +43 -0
  676. package/dist/server/authorization-scope.js +53 -0
  677. package/dist/server/authorization.d.ts +55 -0
  678. package/dist/server/authorization.js +87 -0
  679. package/dist/server/deadline-tracker.d.ts +47 -0
  680. package/dist/server/deadline-tracker.js +106 -0
  681. package/dist/server/discovery-filter.d.ts +13 -0
  682. package/dist/server/discovery-filter.js +5 -0
  683. package/dist/server/discovery-info.d.ts +69 -0
  684. package/dist/server/discovery-info.js +12 -0
  685. package/dist/server/engine-event-feed-backend.d.ts +31 -0
  686. package/dist/server/engine-event-feed-backend.js +36 -0
  687. package/dist/server/fault-to-http.d.ts +14 -0
  688. package/dist/server/fault-to-http.js +29 -0
  689. package/dist/server/fault-to-json-rpc.d.ts +23 -0
  690. package/dist/server/fault-to-json-rpc.js +60 -0
  691. package/dist/server/handler/binding-dispatch.d.ts +11 -0
  692. package/dist/server/handler/binding-dispatch.js +13 -0
  693. package/dist/server/handler/index.d.ts +31 -0
  694. package/dist/server/handler/index.js +78 -0
  695. package/dist/server/handler/response-helpers.d.ts +5 -0
  696. package/dist/server/handler/response-helpers.js +28 -0
  697. package/dist/server/handler/route-dispatch.d.ts +144 -0
  698. package/dist/server/handler/route-dispatch.js +192 -0
  699. package/dist/server/handler/route-matching.d.ts +55 -0
  700. package/dist/server/handler/route-matching.js +45 -0
  701. package/dist/server/handler.d.ts +1 -0
  702. package/dist/server/handler.js +56 -0
  703. package/dist/server/index.d.ts +346 -0
  704. package/dist/server/index.js +64 -0
  705. package/dist/server/interactive-operations.d.ts +18 -0
  706. package/dist/server/interactive-operations.js +28 -0
  707. package/dist/server/json-rpc-dispatch.d.ts +49 -0
  708. package/dist/server/json-rpc-dispatch.js +92 -0
  709. package/dist/server/json-rpc-framing.d.ts +42 -0
  710. package/dist/server/json-rpc-framing.js +15 -0
  711. package/dist/server/json-rpc-http.d.ts +33 -0
  712. package/dist/server/json-rpc-http.js +112 -0
  713. package/dist/server/json-rpc-parse.d.ts +69 -0
  714. package/dist/server/json-rpc-parse.js +139 -0
  715. package/dist/server/json-rpc-protocol.d.ts +76 -0
  716. package/dist/server/json-rpc-protocol.js +27 -0
  717. package/dist/server/json-rpc-transport-helpers.d.ts +17 -0
  718. package/dist/server/json-rpc-transport-helpers.js +26 -0
  719. package/dist/server/json-rpc-websocket-runtime.d.ts +37 -0
  720. package/dist/server/json-rpc-websocket-runtime.js +51 -0
  721. package/dist/server/json-rpc-websocket-validation.d.ts +38 -0
  722. package/dist/server/json-rpc-websocket-validation.js +96 -0
  723. package/dist/server/json-rpc-websocket.d.ts +60 -0
  724. package/dist/server/json-rpc-websocket.js +268 -0
  725. package/dist/server/json-schema-utilities.d.ts +4 -0
  726. package/dist/server/json-schema-utilities.js +16 -0
  727. package/dist/server/mcp-discovery.d.ts +57 -0
  728. package/dist/server/mcp-discovery.js +50 -0
  729. package/dist/server/openapi-canonical-json.d.ts +10 -0
  730. package/dist/server/openapi-canonical-json.js +13 -0
  731. package/dist/server/openapi-error-responses.d.ts +15 -0
  732. package/dist/server/openapi-error-responses.js +36 -0
  733. package/dist/server/openapi-schemas.d.ts +17 -0
  734. package/dist/server/openapi-schemas.js +69 -0
  735. package/dist/server/openapi.d.ts +48 -0
  736. package/dist/server/openapi.js +290 -0
  737. package/dist/server/openrpc-document-schema.d.ts +112 -0
  738. package/dist/server/openrpc-document-schema.js +65 -0
  739. package/dist/server/openrpc-errors.d.ts +73 -0
  740. package/dist/server/openrpc-errors.js +57 -0
  741. package/dist/server/openrpc.d.ts +53 -0
  742. package/dist/server/openrpc.js +179 -0
  743. package/dist/server/operation-catalog/activity-adapter.d.ts +11 -0
  744. package/dist/server/operation-catalog/activity-adapter.js +9 -0
  745. package/dist/server/operation-catalog/dispatch-allowlist.d.ts +4 -0
  746. package/dist/server/operation-catalog/dispatch-allowlist.js +4 -0
  747. package/dist/server/operation-catalog/dispatch-preparation.d.ts +39 -0
  748. package/dist/server/operation-catalog/dispatch-preparation.js +52 -0
  749. package/dist/server/operation-catalog/index.d.ts +22 -0
  750. package/dist/server/operation-catalog/index.js +17 -0
  751. package/dist/server/operation-catalog/pipeline-helpers.d.ts +66 -0
  752. package/dist/server/operation-catalog/pipeline-helpers.js +179 -0
  753. package/dist/server/operation-catalog/pipeline-stages.d.ts +23 -0
  754. package/dist/server/operation-catalog/pipeline-stages.js +189 -0
  755. package/dist/server/operation-catalog/pipeline.d.ts +7 -0
  756. package/dist/server/operation-catalog/pipeline.js +32 -0
  757. package/dist/server/operation-catalog/raise-fault.d.ts +32 -0
  758. package/dist/server/operation-catalog/raise-fault.js +18 -0
  759. package/dist/server/operation-catalog/registry.d.ts +6 -0
  760. package/dist/server/operation-catalog/registry.js +93 -0
  761. package/dist/server/operation-catalog/stream-pipeline.d.ts +25 -0
  762. package/dist/server/operation-catalog/stream-pipeline.js +122 -0
  763. package/dist/server/operation-catalog/types.d.ts +246 -0
  764. package/dist/server/operation-catalog/types.js +9 -0
  765. package/dist/server/operation-catalog/workflow-adapter.d.ts +55 -0
  766. package/dist/server/operation-catalog/workflow-adapter.js +85 -0
  767. package/dist/server/operation-catalog.d.ts +1 -0
  768. package/dist/server/operation-catalog.js +1 -0
  769. package/dist/server/operation-fault.d.ts +153 -0
  770. package/dist/server/operation-fault.js +50 -0
  771. package/dist/server/operation-registry.d.ts +100 -0
  772. package/dist/server/operation-registry.js +56 -0
  773. package/dist/server/operations/add-workflow-tags.d.ts +15 -0
  774. package/dist/server/operations/add-workflow-tags.js +13 -0
  775. package/dist/server/operations/aggregate-workflows.d.ts +81 -0
  776. package/dist/server/operations/aggregate-workflows.js +110 -0
  777. package/dist/server/operations/async-activity.d.ts +44 -0
  778. package/dist/server/operations/async-activity.js +134 -0
  779. package/dist/server/operations/bulk-cancel-workflows.d.ts +7 -0
  780. package/dist/server/operations/bulk-cancel-workflows.js +64 -0
  781. package/dist/server/operations/bulk-delete-workflows.d.ts +7 -0
  782. package/dist/server/operations/bulk-delete-workflows.js +71 -0
  783. package/dist/server/operations/bulk-filter-helpers.d.ts +62 -0
  784. package/dist/server/operations/bulk-filter-helpers.js +334 -0
  785. package/dist/server/operations/bulk-mutate-workflow-tags.d.ts +94 -0
  786. package/dist/server/operations/bulk-mutate-workflow-tags.js +100 -0
  787. package/dist/server/operations/bulk-operation-helpers.d.ts +27 -0
  788. package/dist/server/operations/bulk-operation-helpers.js +29 -0
  789. package/dist/server/operations/bulk-signal-workflows.d.ts +87 -0
  790. package/dist/server/operations/bulk-signal-workflows.js +80 -0
  791. package/dist/server/operations/cancel-schedule.d.ts +13 -0
  792. package/dist/server/operations/cancel-schedule.js +43 -0
  793. package/dist/server/operations/cancel-workflow.d.ts +13 -0
  794. package/dist/server/operations/cancel-workflow.js +34 -0
  795. package/dist/server/operations/create-schedule.d.ts +29 -0
  796. package/dist/server/operations/create-schedule.js +116 -0
  797. package/dist/server/operations/failure-category-filter.d.ts +2 -0
  798. package/dist/server/operations/failure-category-filter.js +19 -0
  799. package/dist/server/operations/fork-workflow.d.ts +29 -0
  800. package/dist/server/operations/fork-workflow.js +88 -0
  801. package/dist/server/operations/get-checkpoint-at.d.ts +15 -0
  802. package/dist/server/operations/get-checkpoint-at.js +74 -0
  803. package/dist/server/operations/get-registry.d.ts +26 -0
  804. package/dist/server/operations/get-registry.js +56 -0
  805. package/dist/server/operations/get-retention-overview.d.ts +9 -0
  806. package/dist/server/operations/get-retention-overview.js +39 -0
  807. package/dist/server/operations/get-review.d.ts +15 -0
  808. package/dist/server/operations/get-review.js +57 -0
  809. package/dist/server/operations/get-schedule.d.ts +20 -0
  810. package/dist/server/operations/get-schedule.js +48 -0
  811. package/dist/server/operations/get-stream-chunks.d.ts +19 -0
  812. package/dist/server/operations/get-stream-chunks.js +71 -0
  813. package/dist/server/operations/get-system-metrics.d.ts +42 -0
  814. package/dist/server/operations/get-system-metrics.js +43 -0
  815. package/dist/server/operations/get-task-diagnostics.d.ts +184 -0
  816. package/dist/server/operations/get-task-diagnostics.js +340 -0
  817. package/dist/server/operations/get-update-result.d.ts +18 -0
  818. package/dist/server/operations/get-update-result.js +55 -0
  819. package/dist/server/operations/get-workflow-attributes.d.ts +13 -0
  820. package/dist/server/operations/get-workflow-attributes.js +51 -0
  821. package/dist/server/operations/get-workflow-events.d.ts +15 -0
  822. package/dist/server/operations/get-workflow-events.js +51 -0
  823. package/dist/server/operations/get-workflow-result.d.ts +14 -0
  824. package/dist/server/operations/get-workflow-result.js +93 -0
  825. package/dist/server/operations/get-workflow-timeline.d.ts +13 -0
  826. package/dist/server/operations/get-workflow-timeline.js +51 -0
  827. package/dist/server/operations/get-workflow.d.ts +36 -0
  828. package/dist/server/operations/get-workflow.js +49 -0
  829. package/dist/server/operations/list-checkpoints.d.ts +13 -0
  830. package/dist/server/operations/list-checkpoints.js +43 -0
  831. package/dist/server/operations/list-filter-query-extractor.d.ts +23 -0
  832. package/dist/server/operations/list-filter-query-extractor.js +87 -0
  833. package/dist/server/operations/list-reviews.d.ts +19 -0
  834. package/dist/server/operations/list-reviews.js +77 -0
  835. package/dist/server/operations/list-schedules.d.ts +28 -0
  836. package/dist/server/operations/list-schedules.js +108 -0
  837. package/dist/server/operations/list-task-queues.d.ts +71 -0
  838. package/dist/server/operations/list-task-queues.js +105 -0
  839. package/dist/server/operations/list-workers.d.ts +56 -0
  840. package/dist/server/operations/list-workers.js +92 -0
  841. package/dist/server/operations/list-workflows.d.ts +79 -0
  842. package/dist/server/operations/list-workflows.js +136 -0
  843. package/dist/server/operations/operation-helpers.d.ts +21 -0
  844. package/dist/server/operations/operation-helpers.js +22 -0
  845. package/dist/server/operations/pause-schedule.d.ts +13 -0
  846. package/dist/server/operations/pause-schedule.js +43 -0
  847. package/dist/server/operations/purge-workflows.d.ts +41 -0
  848. package/dist/server/operations/purge-workflows.js +57 -0
  849. package/dist/server/operations/query-workflow.d.ts +19 -0
  850. package/dist/server/operations/query-workflow.js +99 -0
  851. package/dist/server/operations/recover-all.d.ts +13 -0
  852. package/dist/server/operations/recover-all.js +65 -0
  853. package/dist/server/operations/remove-workflow-tags.d.ts +15 -0
  854. package/dist/server/operations/remove-workflow-tags.js +13 -0
  855. package/dist/server/operations/replay-workflow.d.ts +28 -0
  856. package/dist/server/operations/replay-workflow.js +69 -0
  857. package/dist/server/operations/resume-schedule.d.ts +13 -0
  858. package/dist/server/operations/resume-schedule.js +43 -0
  859. package/dist/server/operations/resume-workflow.d.ts +17 -0
  860. package/dist/server/operations/resume-workflow.js +40 -0
  861. package/dist/server/operations/schedule-faults.d.ts +14 -0
  862. package/dist/server/operations/schedule-faults.js +41 -0
  863. package/dist/server/operations/set-workflow-attributes.d.ts +19 -0
  864. package/dist/server/operations/set-workflow-attributes.js +67 -0
  865. package/dist/server/operations/signal-workflow.d.ts +23 -0
  866. package/dist/server/operations/signal-workflow.js +58 -0
  867. package/dist/server/operations/single-workflow-control-operation.d.ts +32 -0
  868. package/dist/server/operations/single-workflow-control-operation.js +44 -0
  869. package/dist/server/operations/single-workflow-tag-mutation.d.ts +27 -0
  870. package/dist/server/operations/single-workflow-tag-mutation.js +108 -0
  871. package/dist/server/operations/sse-stream.d.ts +13 -0
  872. package/dist/server/operations/sse-stream.js +42 -0
  873. package/dist/server/operations/start-workflow.d.ts +33 -0
  874. package/dist/server/operations/start-workflow.js +181 -0
  875. package/dist/server/operations/storage.d.ts +112 -0
  876. package/dist/server/operations/storage.js +358 -0
  877. package/dist/server/operations/stream-workflow-sse.d.ts +17 -0
  878. package/dist/server/operations/stream-workflow-sse.js +94 -0
  879. package/dist/server/operations/submit-review-decision.d.ts +25 -0
  880. package/dist/server/operations/submit-review-decision.js +113 -0
  881. package/dist/server/operations/timeout-workflow.d.ts +11 -0
  882. package/dist/server/operations/timeout-workflow.js +34 -0
  883. package/dist/server/operations/update-schedule.d.ts +15 -0
  884. package/dist/server/operations/update-schedule.js +60 -0
  885. package/dist/server/operations/update-workflow.d.ts +27 -0
  886. package/dist/server/operations/update-workflow.js +109 -0
  887. package/dist/server/operations/worker-drain.d.ts +69 -0
  888. package/dist/server/operations/worker-drain.js +214 -0
  889. package/dist/server/operations/workflow-events-subscription.d.ts +47 -0
  890. package/dist/server/operations/workflow-events-subscription.js +51 -0
  891. package/dist/server/principal.d.ts +176 -0
  892. package/dist/server/principal.js +59 -0
  893. package/dist/server/rest-binding.d.ts +158 -0
  894. package/dist/server/rest-binding.js +35 -0
  895. package/dist/server/rest-bindings.d.ts +76 -0
  896. package/dist/server/rest-bindings.js +376 -0
  897. package/dist/server/route-model.d.ts +268 -0
  898. package/dist/server/route-model.js +166 -0
  899. package/dist/server/runtime/authentication-bridge.d.ts +22 -0
  900. package/dist/server/runtime/authentication-bridge.js +194 -0
  901. package/dist/server/runtime/context.d.ts +73 -0
  902. package/dist/server/runtime/context.js +0 -0
  903. package/dist/server/runtime/cors.d.ts +149 -0
  904. package/dist/server/runtime/cors.js +123 -0
  905. package/dist/server/runtime/event-broadcasting.d.ts +71 -0
  906. package/dist/server/runtime/event-broadcasting.js +205 -0
  907. package/dist/server/runtime/request-gate.d.ts +54 -0
  908. package/dist/server/runtime/request-gate.js +71 -0
  909. package/dist/server/runtime/shutdown.d.ts +10 -0
  910. package/dist/server/runtime/shutdown.js +18 -0
  911. package/dist/server/runtime/stop-server.d.ts +3 -0
  912. package/dist/server/runtime/stop-server.js +19 -0
  913. package/dist/server/runtime/task-dispatch.d.ts +8 -0
  914. package/dist/server/runtime/task-dispatch.js +157 -0
  915. package/dist/server/runtime/task-metrics.d.ts +12 -0
  916. package/dist/server/runtime/task-metrics.js +36 -0
  917. package/dist/server/runtime/task-polling.d.ts +9 -0
  918. package/dist/server/runtime/task-polling.js +132 -0
  919. package/dist/server/runtime/task-reconciliation.d.ts +17 -0
  920. package/dist/server/runtime/task-reconciliation.js +163 -0
  921. package/dist/server/runtime/websocket-stream.d.ts +15 -0
  922. package/dist/server/runtime/websocket-stream.js +79 -0
  923. package/dist/server/runtime/websocket-upgrade.d.ts +8 -0
  924. package/dist/server/runtime/websocket-upgrade.js +76 -0
  925. package/dist/server/runtime/websocket-worker.d.ts +7 -0
  926. package/dist/server/runtime/websocket-worker.js +224 -0
  927. package/dist/server/runtime-helpers.d.ts +18 -0
  928. package/dist/server/runtime-helpers.js +23 -0
  929. package/dist/server/sequence-cursor.d.ts +5 -0
  930. package/dist/server/sequence-cursor.js +19 -0
  931. package/dist/server/serve-internals.d.ts +83 -0
  932. package/dist/server/serve-internals.js +203 -0
  933. package/dist/server/stdio-session.d.ts +51 -0
  934. package/dist/server/stdio-session.js +245 -0
  935. package/dist/server/task-queue-summary.d.ts +27 -0
  936. package/dist/server/task-queue-summary.js +34 -0
  937. package/dist/server/task-queue-types.d.ts +95 -0
  938. package/dist/server/task-queue-types.js +0 -0
  939. package/dist/server/task-queue.d.ts +90 -0
  940. package/dist/server/task-queue.js +247 -0
  941. package/dist/server/task-resolved-record.d.ts +12 -0
  942. package/dist/server/task-resolved-record.js +35 -0
  943. package/dist/server/task-state.d.ts +152 -0
  944. package/dist/server/task-state.js +178 -0
  945. package/dist/server/workflow-event-feed.d.ts +166 -0
  946. package/dist/server/workflow-event-feed.js +193 -0
  947. package/dist/service-worker/index.d.ts +123 -0
  948. package/dist/service-worker/index.js +56 -0
  949. package/dist/service-worker/scheduler.d.ts +37 -0
  950. package/dist/service-worker/scheduler.js +117 -0
  951. package/dist/service-worker/setup.d.ts +127 -0
  952. package/dist/service-worker/setup.js +129 -0
  953. package/dist/service-worker/shared.d.ts +94 -0
  954. package/dist/service-worker/shared.js +15 -0
  955. package/dist/storage/auto.d.ts +45 -0
  956. package/dist/storage/auto.js +2 -0
  957. package/dist/storage/bun-sql.d.ts +64 -0
  958. package/dist/storage/bun-sql.js +575 -0
  959. package/dist/storage/byte-encoding.d.ts +6 -0
  960. package/dist/storage/byte-encoding.js +16 -0
  961. package/dist/storage/capabilities.d.ts +187 -0
  962. package/dist/storage/capabilities.js +19 -0
  963. package/dist/storage/compressed-storage.d.ts +45 -0
  964. package/dist/storage/compressed-storage.js +2 -0
  965. package/dist/storage/default-scope.d.ts +17 -0
  966. package/dist/storage/default-scope.js +1 -0
  967. package/dist/storage/delete-range.d.ts +109 -0
  968. package/dist/storage/delete-range.js +64 -0
  969. package/dist/storage/derived-operations.d.ts +53 -0
  970. package/dist/storage/derived-operations.js +31 -0
  971. package/dist/storage/http.d.ts +67 -0
  972. package/dist/storage/http.js +2 -0
  973. package/dist/storage/index.d.ts +292 -0
  974. package/dist/storage/index.js +51 -0
  975. package/dist/storage/indexeddb.d.ts +49 -0
  976. package/dist/storage/indexeddb.js +1 -0
  977. package/dist/storage/interface.d.ts +340 -0
  978. package/dist/storage/interface.js +2 -0
  979. package/dist/storage/key-prefixes.d.ts +19 -0
  980. package/dist/storage/key-prefixes.js +35 -0
  981. package/dist/storage/lmdb.d.ts +40 -0
  982. package/dist/storage/lmdb.js +2 -0
  983. package/dist/storage/memory.d.ts +46 -0
  984. package/dist/storage/memory.js +2 -0
  985. package/dist/storage/node-sqlite.d.ts +85 -0
  986. package/dist/storage/node-sqlite.js +323 -0
  987. package/dist/storage/read-only-query.d.ts +2 -0
  988. package/dist/storage/read-only-query.js +19 -0
  989. package/dist/storage/resolve.d.ts +180 -0
  990. package/dist/storage/resolve.js +2 -0
  991. package/dist/storage/scoped-storage.d.ts +68 -0
  992. package/dist/storage/scoped-storage.js +2 -0
  993. package/dist/storage/sqlite-key-value-queries.d.ts +40 -0
  994. package/dist/storage/sqlite-key-value-queries.js +64 -0
  995. package/dist/storage/sqlite.d.ts +31 -0
  996. package/dist/storage/sqlite.js +0 -0
  997. package/dist/storage/text-value-import.d.ts +87 -0
  998. package/dist/storage/text-value-import.js +50 -0
  999. package/dist/storage/text-value-store.d.ts +171 -0
  1000. package/dist/storage/text-value-store.js +55 -0
  1001. package/dist/storage/turso.d.ts +60 -0
  1002. package/dist/storage/turso.js +5 -0
  1003. package/dist/storage/typed-storage.d.ts +258 -0
  1004. package/dist/storage/typed-storage.js +2 -0
  1005. package/dist/storage/web-extension.d.ts +55 -0
  1006. package/dist/storage/web-extension.js +1 -0
  1007. package/dist/testing/chaos.d.ts +157 -0
  1008. package/dist/testing/chaos.js +69 -0
  1009. package/dist/testing/event-loop.d.ts +4 -0
  1010. package/dist/testing/event-loop.js +21 -0
  1011. package/dist/testing/index.d.ts +126 -0
  1012. package/dist/testing/index.js +61 -0
  1013. package/dist/testing/mocks.d.ts +145 -0
  1014. package/dist/testing/mocks.js +136 -0
  1015. package/dist/testing/subprocess-engine.d.ts +100 -0
  1016. package/dist/testing/subprocess-engine.js +291 -0
  1017. package/dist/testing/test-engine.d.ts +145 -0
  1018. package/dist/testing/test-engine.js +147 -0
  1019. package/dist/testing/time-control.d.ts +59 -0
  1020. package/dist/testing/time-control.js +68 -0
  1021. package/dist/version.d.ts +12 -0
  1022. package/dist/version.js +1 -0
  1023. package/dist/worker/activity-table.d.ts +33 -0
  1024. package/dist/worker/activity-table.js +20 -0
  1025. package/dist/worker/execute-with-interceptors.d.ts +28 -0
  1026. package/dist/worker/execute-with-interceptors.js +21 -0
  1027. package/dist/worker/heartbeat.d.ts +34 -0
  1028. package/dist/worker/heartbeat.js +31 -0
  1029. package/dist/worker/index.d.ts +57 -0
  1030. package/dist/worker/index.js +334 -0
  1031. package/dist/worker/long-poll.d.ts +54 -0
  1032. package/dist/worker/long-poll.js +134 -0
  1033. package/dist/worker/options.d.ts +66 -0
  1034. package/dist/worker/options.js +19 -0
  1035. package/dist/worker/protocol-internals.d.ts +82 -0
  1036. package/dist/worker/protocol-internals.js +56 -0
  1037. package/dist/worker/protocol-messages.d.ts +264 -0
  1038. package/dist/worker/protocol-messages.js +0 -0
  1039. package/dist/worker/protocol-schemas.d.ts +559 -0
  1040. package/dist/worker/protocol-schemas.js +180 -0
  1041. package/dist/worker/protocol-version.d.ts +71 -0
  1042. package/dist/worker/protocol-version.js +1 -0
  1043. package/dist/worker/protocol.d.ts +72 -0
  1044. package/dist/worker/protocol.js +2 -0
  1045. package/dist/worker/registry/fair-share.d.ts +59 -0
  1046. package/dist/worker/registry/fair-share.js +15 -0
  1047. package/dist/worker/registry/routing.d.ts +17 -0
  1048. package/dist/worker/registry/routing.js +16 -0
  1049. package/dist/worker/registry/summary.d.ts +87 -0
  1050. package/dist/worker/registry/summary.js +81 -0
  1051. package/dist/worker/registry/types.d.ts +123 -0
  1052. package/dist/worker/registry/types.js +0 -0
  1053. package/dist/worker/registry.d.ts +94 -0
  1054. package/dist/worker/registry.js +305 -0
  1055. package/dist/worker/remote-activity-context.d.ts +15 -0
  1056. package/dist/worker/remote-activity-context.js +0 -0
  1057. package/dist/worker/task-result-outbox.d.ts +40 -0
  1058. package/dist/worker/task-result-outbox.js +42 -0
  1059. package/dist/worker/worker-protocol-incompatible-error.d.ts +52 -0
  1060. package/dist/worker/worker-protocol-incompatible-error.js +15 -0
  1061. package/dist/worker/workflow-activity-binding.d.ts +96 -0
  1062. package/dist/worker/workflow-activity-binding.js +22 -0
  1063. package/dist/workers/activity-runner.d.ts +87 -0
  1064. package/dist/workers/activity-runner.js +29 -0
  1065. package/dist/workers/activity-worker-dispatcher.d.ts +85 -0
  1066. package/dist/workers/activity-worker-dispatcher.js +68 -0
  1067. package/dist/workers/activity-worker-entry.d.ts +99 -0
  1068. package/dist/workers/activity-worker-entry.js +59 -0
  1069. package/dist/workers/pool.d.ts +83 -0
  1070. package/dist/workers/pool.js +174 -0
  1071. package/dist/workers/workflow-runner.d.ts +79 -0
  1072. package/dist/workers/workflow-runner.js +245 -0
  1073. package/dist/workers/workflow-worker-entry.d.ts +24 -0
  1074. package/dist/workers/workflow-worker-entry.js +70 -0
  1075. package/package.json +297 -0
@@ -0,0 +1,258 @@
1
+ import type { JSONValue } from '../core/json.ts';
2
+ import { type DeleteRangeOptions } from './delete-range.ts';
3
+ import { type ScanOptions, type Storage } from './interface.ts';
4
+ /**
5
+ * Encode/decode pair that bridges a typed domain value to and from `Uint8Array`.
6
+ *
7
+ * Implement this interface to plug a custom serialization format into
8
+ * {@link withCodec}. Two built-in factories — {@link jsonCodec} and
9
+ * {@link msgpackCodec} — cover the most common cases.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * import { type StorageCodec, withCodec, MemoryStorage } from '@lostgradient/weft';
14
+ *
15
+ * const encoder = new TextEncoder();
16
+ * const decoder = new TextDecoder();
17
+ *
18
+ * const csvCodec: StorageCodec<string[]> = {
19
+ * encode: (row) => encoder.encode(row.join(',')),
20
+ * decode: (bytes) => decoder.decode(bytes).split(','),
21
+ * };
22
+ *
23
+ * await using raw = new MemoryStorage();
24
+ * const store = withCodec(raw, csvCodec);
25
+ * await store.put('row:1', ['alice', '30', 'eng']);
26
+ * const row = await store.get('row:1');
27
+ * console.log(row?.join('|'));
28
+ * ```
29
+ */
30
+ export interface StorageCodec<Value> {
31
+ encode(value: Value): Uint8Array;
32
+ decode(bytes: Uint8Array): Value;
33
+ }
34
+ /**
35
+ * Validator or narrowing function passed as an optional argument to
36
+ * {@link jsonCodec} and {@link msgpackCodec}.
37
+ *
38
+ * Receives the raw decoded value (`unknown`) and must return the strongly-typed
39
+ * `Value` — either by assertion after runtime validation or by throwing when the
40
+ * shape is unexpected. Omitting it leaves the codec untyped (`JSONValue` /
41
+ * `MessagePackValue`).
42
+ */
43
+ export type StorageValueParser<Value> = (value: unknown) => Value;
44
+ export type MessagePackPrimitive = bigint | boolean | null | number | string | undefined;
45
+ /**
46
+ * Recursive union of every value that MessagePack can encode and decode.
47
+ *
48
+ * A superset of {@link JSONValue} that additionally supports `Date`, `Map`,
49
+ * `Set`, `Uint8Array`, `RegExp`, `Error`, `ArrayBuffer`, and `bigint`. Its
50
+ * array branch is `ReadonlyArray` (matching `JSONValue`), so every `JSONValue`
51
+ * — including `readonly` arrays and `as const` tuples — is assignable here and
52
+ * accepted by `msgpackCodec<Value extends MessagePackValue>`. The encoder only
53
+ * reads its input, so a readonly bound is sound. Prefer this codec when your
54
+ * domain objects contain binary data or richly-typed primitives that JSON
55
+ * cannot represent without custom serialisation.
56
+ */
57
+ export type MessagePackValue = ArrayBuffer | Date | Error | Map<MessagePackValue, MessagePackValue> | MessagePackPrimitive | ReadonlyArray<MessagePackValue> | RegExp | Set<MessagePackValue> | Uint8Array | {
58
+ [key: string]: MessagePackValue;
59
+ };
60
+ /**
61
+ * Typed version of `BatchOperation` — a put or delete applied as part of an
62
+ * atomic batch in a {@link TypedStorage} instance.
63
+ *
64
+ * Build an array of these and pass it to `TypedStorage.batch()` to apply
65
+ * multiple mutations in a single round-trip without encoding each value
66
+ * individually at the call site.
67
+ *
68
+ * @example
69
+ * ```ts
70
+ * import { MemoryStorage, withCodec, jsonCodec, type TypedBatchOperation } from '@lostgradient/weft';
71
+ *
72
+ * await using raw = new MemoryStorage();
73
+ * const store = withCodec(raw, jsonCodec());
74
+ *
75
+ * const ops: TypedBatchOperation<{ count: number }>[] = [
76
+ * { type: 'put', key: 'a', value: { count: 1 } },
77
+ * { type: 'put', key: 'b', value: { count: 2 } },
78
+ * { type: 'delete', key: 'old' },
79
+ * ];
80
+ * await store.batch(ops);
81
+ * ```
82
+ */
83
+ export type TypedBatchOperation<Value> = {
84
+ type: 'put';
85
+ key: string;
86
+ value: Value;
87
+ } | {
88
+ type: 'delete';
89
+ key: string;
90
+ };
91
+ /**
92
+ * Typed compare-and-swap precondition used by
93
+ * {@link ConditionalTypedStorage.conditionalBatch}.
94
+ *
95
+ * @example
96
+ * ```ts
97
+ * import { type TypedConditionalBatchCondition } from '@lostgradient/weft/storage';
98
+ *
99
+ * type SessionMetadata = { lastUsedAt: string };
100
+ * const condition: TypedConditionalBatchCondition<SessionMetadata> = {
101
+ * key: 'session:1',
102
+ * expectedValue: { lastUsedAt: '2026-06-01T00:00:00.000Z' },
103
+ * };
104
+ * console.log(condition.key); // 'session:1'
105
+ * ```
106
+ */
107
+ export type TypedConditionalBatchCondition<Value> = {
108
+ /** Key whose current decoded value must match `expectedValue`. */
109
+ key: string;
110
+ /** Required current value, or `null` to require the key to be absent. */
111
+ expectedValue: Value | null;
112
+ };
113
+ /**
114
+ * Options for {@link withCodec}.
115
+ *
116
+ * @example
117
+ * ```ts
118
+ * import { type CodecStorageOptions } from '@lostgradient/weft/storage';
119
+ *
120
+ * const options: CodecStorageOptions = {
121
+ * disposeUnderlyingStorage: false,
122
+ * };
123
+ * console.log(options.disposeUnderlyingStorage); // false
124
+ * ```
125
+ */
126
+ export type CodecStorageOptions = {
127
+ /**
128
+ * Whether disposing the typed wrapper also disposes the wrapped storage.
129
+ * Defaults to `true` to preserve the owning-wrapper behavior. Set `false`
130
+ * when several typed views share the same storage instance.
131
+ */
132
+ disposeUnderlyingStorage?: boolean;
133
+ };
134
+ /**
135
+ * Disposable typed key-value store interface over a raw {@link Storage}.
136
+ *
137
+ * Mirrors the `Storage` interface but operates on `Value` instead of
138
+ * `Uint8Array` — encoding and decoding is handled transparently by the
139
+ * underlying codec. Obtain a `TypedStorage` via {@link withCodec},
140
+ * {@link jsonCodec}, or {@link msgpackCodec} rather than implementing it
141
+ * directly. Note: `TypedStorage` intentionally does not surface
142
+ * `Storage.query` or `Storage.scoped` — drop down to the underlying raw
143
+ * storage to use those operations.
144
+ *
145
+ * @example
146
+ * ```ts
147
+ * import { MemoryStorage, withCodec, jsonCodec, type TypedStorage } from '@lostgradient/weft';
148
+ *
149
+ * type User = { name: string; age: number };
150
+ *
151
+ * await using raw = new MemoryStorage();
152
+ * const users: TypedStorage<User> = withCodec(
153
+ * raw,
154
+ * jsonCodec((v) => v as User),
155
+ * );
156
+ *
157
+ * await users.put('user:1', { name: 'Alice', age: 30 });
158
+ * const alice = await users.get('user:1');
159
+ * console.log(alice?.name); // 'Alice'
160
+ * ```
161
+ */
162
+ export interface TypedStorage<Value> extends Disposable {
163
+ get(key: string): Promise<Value | null>;
164
+ put(key: string, value: Value): Promise<void>;
165
+ delete(key: string): Promise<void>;
166
+ scan(prefix: string, options?: ScanOptions): AsyncIterable<[string, Value]>;
167
+ batch(operations: TypedBatchOperation<Value>[]): Promise<void>;
168
+ has(key: string): Promise<boolean>;
169
+ deletePrefix(prefix: string): Promise<number>;
170
+ deleteRange?(prefix: string, options: DeleteRangeOptions): Promise<number>;
171
+ keys(prefix: string, options?: ScanOptions): AsyncIterable<string>;
172
+ count(prefix: string): Promise<number>;
173
+ }
174
+ /**
175
+ * Typed storage returned by {@link withCodec}. It extends the base
176
+ * {@link TypedStorage} shape with compare-and-swap support without requiring
177
+ * every external `TypedStorage` implementation to define the method.
178
+ */
179
+ export interface ConditionalTypedStorage<Value> extends TypedStorage<Value> {
180
+ conditionalBatch(conditions: TypedConditionalBatchCondition<Value>[], operations: TypedBatchOperation<Value>[]): Promise<boolean>;
181
+ }
182
+ /**
183
+ * Wraps a raw {@link Storage} with a {@link StorageCodec} to produce a
184
+ * {@link TypedStorage} that encodes and decodes values automatically.
185
+ *
186
+ * Use the built-in {@link jsonCodec} or {@link msgpackCodec} factories as the
187
+ * `codec` argument, or supply a custom implementation. The returned store
188
+ * disposes the underlying storage when its own `[Symbol.dispose]` is called
189
+ * unless `disposeUnderlyingStorage: false` is provided.
190
+ *
191
+ * @example
192
+ * ```ts
193
+ * import { MemoryStorage, withCodec, jsonCodec } from '@lostgradient/weft';
194
+ *
195
+ * type Config = { retries: number; timeout: number };
196
+ *
197
+ * await using raw = new MemoryStorage();
198
+ * const configStore = withCodec(raw, jsonCodec<Config>((v) => v as Config));
199
+ *
200
+ * await configStore.put('cfg:default', { retries: 3, timeout: 5000 });
201
+ * const cfg = await configStore.get('cfg:default');
202
+ * console.log(cfg?.retries); // 3
203
+ * ```
204
+ */
205
+ export declare function withCodec<Value>(storage: Storage, codec: StorageCodec<Value>, options?: CodecStorageOptions): ConditionalTypedStorage<Value>;
206
+ /**
207
+ * Creates a {@link StorageCodec} that serialises values as UTF-8 JSON.
208
+ *
209
+ * Call without arguments to get a `StorageCodec<JSONValue>`. Pass an optional
210
+ * {@link StorageValueParser} to narrow the output to a concrete type — useful
211
+ * when you have a Zod schema or manual shape check.
212
+ *
213
+ * @example
214
+ * ```ts
215
+ * import { MemoryStorage, withCodec, jsonCodec } from '@lostgradient/weft';
216
+ *
217
+ * type Point = { x: number; y: number };
218
+ * const isPoint = (v: unknown): v is Point =>
219
+ * typeof v === 'object' && v !== null && 'x' in v && 'y' in v;
220
+ *
221
+ * await using raw = new MemoryStorage();
222
+ * const points = withCodec(raw, jsonCodec<Point>((v) => {
223
+ * if (!isPoint(v)) throw new TypeError('not a Point');
224
+ * return v;
225
+ * }));
226
+ *
227
+ * await points.put('p:1', { x: 10, y: 20 });
228
+ * const p = await points.get('p:1');
229
+ * console.log(p?.x); // 10
230
+ * ```
231
+ */
232
+ export declare function jsonCodec(): StorageCodec<JSONValue>;
233
+ export declare function jsonCodec<Value extends JSONValue>(parse: StorageValueParser<Value>): StorageCodec<Value>;
234
+ /**
235
+ * Creates a {@link StorageCodec} that serialises values with MessagePack.
236
+ *
237
+ * Prefer this over {@link jsonCodec} when your domain objects contain binary
238
+ * data (`Uint8Array`, `ArrayBuffer`), `Date`, `Map`, or `Set` — types that
239
+ * JSON cannot round-trip without custom replacers. Pass an optional
240
+ * {@link StorageValueParser} to narrow the decoded type.
241
+ *
242
+ * @example
243
+ * ```ts
244
+ * import { MemoryStorage, withCodec, msgpackCodec } from '@lostgradient/weft';
245
+ *
246
+ * type Event = { ts: Date; payload: Uint8Array };
247
+ *
248
+ * await using raw = new MemoryStorage();
249
+ * const events = withCodec(raw, msgpackCodec<Event>((v) => v as Event));
250
+ *
251
+ * const evt: Event = { ts: new Date(), payload: new Uint8Array([1, 2, 3]) };
252
+ * await events.put('evt:1', evt);
253
+ * const loaded = await events.get('evt:1');
254
+ * console.log(loaded?.ts instanceof Date); // true
255
+ * ```
256
+ */
257
+ export declare function msgpackCodec(): StorageCodec<MessagePackValue>;
258
+ export declare function msgpackCodec<Value extends MessagePackValue>(parse: StorageValueParser<Value>): StorageCodec<Value>;
@@ -0,0 +1,2 @@
1
+ // @bun
2
+ var wW=Object.defineProperty;var jW=(W)=>W;function hW(W,$){this[W]=jW.bind(null,$)}var b0=(W,$)=>{for(var Z in $)wW(W,Z,{get:$[Z],enumerable:!0,configurable:!0,set:hW.bind($,Z)})};var X=(W,$)=>()=>(W&&($=W(W=0)),$);function v(W,$,Z){if(!W.capabilities()[$])throw Error(`Feature "${Z}" requires storage capability "${$}", but this storage backend does not provide it.`)}function mW(W){let $=W.capabilities(),Z=[];if($.persistence!=="local")Z.push(`persistence must be "local" (got "${$.persistence}")`);if($.readAfterWrite!=="linearizable")Z.push(`readAfterWrite must be "linearizable" (got "${$.readAfterWrite}")`);if($.scanConsistency!=="snapshot")Z.push(`scanConsistency must be "snapshot" (got "${$.scanConsistency}")`);if(!$.atomicBatch)Z.push("atomicBatch must be true");if(!$.conditionalBatch)Z.push("conditionalBatch must be true");if(Z.length>0)throw Error(`Storage is not durable enough for recovery: ${Z.join("; ")}.`)}var b="default";async function r(W,$){return await W.get($)!==null}async function*z(W,$,Z){for await(let[G]of W.scan($,Z))yield G}async function s(W,$){let Z=0;for await(let G of z(W,$))Z++;return Z}async function a(W,$){let Z=[];for await(let G of z(W,$))Z.push({type:"delete",key:G});if(Z.length===0)return 0;return await W.batch(Z),Z.length}async function o(W,$,Z){let G=[];for await(let J of z(W,$,Z))G.push({type:"delete",key:J});if(G.length===0)return 0;return await W.batch(G),G.length}var gW;var t=X(()=>{gW=["actrec:","archive:","async-act:","attr:","audit:bulk:","blob:","budget:","budget-charged:","ev:","idx:","offload:","op:","review:","schedule:","schedule-due:","schedule-run:","sig:","sigres:","sigseq:","state:","tag:","tool-effect:","upd:","upk:","upr:","wf:","wf-cleanup:","wf-cleanup-needed:","wf-deadline:","wf-delayed:","wf-headers:","wf-idx-","wf-terminal:"]});function i0(W){return W.length>0?W.slice(0,-1)+String.fromCharCode(W.charCodeAt(W.length-1)+1):"\xFF"}function r0(W,$={}){if($.gt!==void 0&&W<=$.gt)return!1;if($.gte!==void 0&&W<$.gte)return!1;if($.lt!==void 0&&W>=$.lt)return!1;if($.lte!==void 0&&W>$.lte)return!1;return!0}function s0(W,$){if(W===null||$===null)return W===$;if(W.byteLength!==$.byteLength)return!1;for(let Z=0;Z<W.byteLength;Z++)if(W[Z]!==$[Z])return!1;return!0}async function e(W,$){if(W.has)return W.has($);return r(W,$)}function WW(W,$,Z){if(W.keys)return W.keys($,Z);return z(W,$,Z)}async function $W(W,$){if(W.count)return W.count($);return s(W,$)}async function ZW(W,$){if(W.deletePrefix)return W.deletePrefix($);return a(W,$)}async function GW(W,$,Z){if(v(W,"conditionalBatch","storageConditionalBatch"),!W.conditionalBatch)throw Error("This storage backend reports conditionalBatch capability but does not implement the conditionalBatch() method.");return W.conditionalBatch($,Z)}function q(W){return encodeURIComponent(W)}function a0(W){return decodeURIComponent(W)}function o0(W){try{return decodeURIComponent(W)}catch{return null}}var N=(W)=>String(W).padStart(16,"0"),t0;var JW=X(()=>{t();t0={workflow:(W)=>`wf:${q(W)}`,checkpoint:(W)=>`wf:${q(W)}:ckpt`,checkpointHistory:(W,$)=>`wf:${q(W)}:ckpt:${String($).padStart(10,"0")}`,timelinePrefix:(W)=>`wf:${q(W)}:timeline:`,timeline:(W,$)=>`wf:${q(W)}:timeline:${String($).padStart(10,"0")}`,schedule:(W)=>`schedule:${q(W)}`,scheduleTick:(W,$)=>`schedule-due:${String(W).padStart(16,"0")}:${q($)}`,scheduleRun:(W)=>`schedule-run:${q(W)}`,operation:(W,$,Z)=>`op:${W}:${N($)}:${Z}`,operationInflight:(W)=>`op:inflight:${W}`,operationQueued:(W)=>`op:queued:${W}`,operationResolved:(W)=>`op:resolved:${W}`,bulkOperationAuditPrefix:()=>"audit:bulk:",bulkOperationAudit:(W,$,Z)=>`audit:bulk:${N(W)}:${q($)}:${q(Z)}`,operationResolvedByTimePrefix:()=>"op:resolved-by-time:",operationResolvedByTime:(W,$)=>`op:resolved-by-time:${N(W)}:${q($)}`,asyncActivity:(W,$)=>`async-act:v1:${q(W)}:${q($)}`,activityReconciliationPrefix:(W)=>`actrec:v1:${q(W)}:`,activityReconciliation:(W,$,Z)=>`actrec:v1:${q(W)}:${q($)}:${Z}`,eventPrefix:(W)=>`ev:${q(W)}:`,event:(W,$)=>`ev:${q(W)}:${String($).padStart(10,"0")}`,eventHead:(W)=>`ev:${q(W)}:head`,eventWatermark:(W)=>`ev:${q(W)}:watermark`,signal:(W,$,Z)=>`sig:${q(W)}:${$}:${q(Z)}`,signalSequence:(W)=>`sigseq:v1:${q(W)}`,signalAcceptedResponsePrefix:(W)=>`sigres:v1:${q(W)}:`,signalAcceptedResponse:(W,$,Z)=>`sigres:v1:${q(W)}:${q($)}:${q(Z)}`,deadline:(W,$)=>`wf-deadline:${N(W)}:${q($)}`,terminalCleanup:(W,$)=>`wf-cleanup:${N(W)}:${q($)}`,delayedStart:(W,$)=>`wf-delayed:${N(W)}:${q($)}`,terminalWorkflowPrefix:()=>"wf-terminal:",terminalWorkflow:(W,$)=>`wf-terminal:${N(W)}:${q($)}`,attribute:(W)=>`attr:${q(W)}`,attributeIndex:(W,$,Z)=>`idx:${W}:${$}:${q(Z)}`,tagIndex:(W,$)=>`tag:${q(W)}:${q($)}`,updatePrefix:(W)=>`upd:${q(W)}:`,update:(W,$)=>`upd:${q(W)}:${$}`,updateResponse:(W)=>`upr:${W}`,updateIdempotency:(W,$)=>`upk:${q(W)}:${$}`,budget:(W,$,Z)=>`budget:${W}:${$}:${Z}`,review:(W,$)=>`review:${q(W)}:${$}`,workflowHeaders:(W)=>`wf-headers:${q(W)}`,terminalCleanupNeeded:(W)=>`wf-cleanup-needed:${q(W)}`,offload:(W,$)=>`offload:${q(W)}:${$}`,archive:(W,$)=>`archive:${q(W)}:${$}`,stateExecution:(W,$)=>`state:execution:${q(W)}:${q($)}`,stateWorkflow:(W,$)=>`state:workflow-scope:${b}:${q(W)}:${q($)}`,streamChunkPrefix:(W,$)=>`blob:${q(W)}:${$}:chunk:`,streamChunk:(W,$,Z)=>`blob:${q(W)}:${$}:chunk:${String(Z).padStart(10,"0")}`,streamMetadata:(W,$)=>`blob:${q(W)}:${$}:meta`,budgetCharged:(W)=>`budget-charged:${W}`,toolEffect:(W,$,Z)=>`tool-effect:${q(W)}:${$}:${Z}`,workflowVisibilityStatus:(W,$)=>`wf-idx-status:${q(W)}:${q($)}`,workflowVisibilityType:(W,$)=>`wf-idx-type:${q(W)}:${q($)}`,workflowVisibilityCreated:(W,$)=>`wf-idx-created:${N(W)}:${q($)}`,workflowVisibilityUpdated:(W,$)=>`wf-idx-updated:${N(W)}:${q($)}`,workflowVisibilityDeadline:(W,$)=>`wf-idx-deadline:${N(W)}:${q($)}`,workflowVisibilityManifest:(W)=>`wf-idx-manifest:${q(W)}`,workflowVisibilityMetaVersion:()=>"wf-idx-meta:version",workflowVisibilityMetaBuiltAt:()=>"wf-idx-meta:built-at",workflowVisibilityMetaCursor:()=>"wf-idx-meta:cursor"}});function QW(W){let $=W.length,Z=0,G=0;while(G<$){let J=W.charCodeAt(G++);if((J&4294967168)===0){Z++;continue}else if((J&4294965248)===0)Z+=2;else{if(J>=55296&&J<=56319){if(G<$){let Q=W.charCodeAt(G);if((Q&64512)===56320)++G,J=((J&1023)<<10)+(Q&1023)+65536}}if((J&4294901760)===0)Z+=3;else Z+=4}}return Z}function vW(W,$,Z){let G=W.length,J=Z,Q=0;while(Q<G){let F=W.charCodeAt(Q++);if((F&4294967168)===0){$[J++]=F;continue}else if((F&4294965248)===0)$[J++]=F>>6&31|192;else{if(F>=55296&&F<=56319){if(Q<G){let H=W.charCodeAt(Q);if((H&64512)===56320)++Q,F=((F&1023)<<10)+(H&1023)+65536}}if((F&4294901760)===0)$[J++]=F>>12&15|224,$[J++]=F>>6&63|128;else $[J++]=F>>18&7|240,$[J++]=F>>12&63|128,$[J++]=F>>6&63|128}$[J++]=F&63|128}}function fW(W,$,Z){bW.encodeInto(W,$.subarray(Z))}function qW(W,$,Z){if(W.length>yW)fW(W,$,Z);else vW(W,$,Z)}function y(W,$,Z){let G=$,J=G+Z,Q=[],F="";while(G<J){let H=W[G++];if((H&128)===0)Q.push(H);else if((H&224)===192){let A=W[G++]&63;Q.push((H&31)<<6|A)}else if((H&240)===224){let A=W[G++]&63,g=W[G++]&63;Q.push((H&31)<<12|A<<6|g)}else if((H&248)===240){let A=W[G++]&63,g=W[G++]&63,kW=W[G++]&63,B=(H&7)<<18|A<<12|g<<6|kW;if(B>65535)B-=65536,Q.push(B>>>10&1023|55296),B=56320|B&1023;Q.push(B)}else Q.push(H);if(Q.length>=lW)F+=String.fromCharCode(...Q),Q.length=0}if(Q.length>0)F+=String.fromCharCode(...Q);return F}function cW(W,$,Z){let G=W.subarray($,$+Z);return pW.decode(G)}function FW(W,$,Z){if(Z>uW)return cW(W,$,Z);else return y(W,$,Z)}var bW,yW=50,lW=4096,pW,uW=200;var C=X(()=>{bW=new TextEncoder;pW=new TextDecoder});class K{type;data;constructor(W,$){this.type=W,this.data=$}}var V;var f=X(()=>{V=class V extends Error{constructor(W){super(W);let $=Object.create(V.prototype);Object.setPrototypeOf(this,$),Object.defineProperty(this,"name",{configurable:!0,enumerable:!1,value:V.name})}}});function XW(W,$,Z){let G=Z/4294967296,J=Z;W.setUint32($,G),W.setUint32($+4,J)}function x(W,$,Z){let G=Math.floor(Z/4294967296),J=Z;W.setUint32($,G),W.setUint32($+4,J)}function S(W,$){let Z=W.getInt32($),G=W.getUint32($+4);return Z*4294967296+G}function YW(W,$){let Z=W.getUint32($),G=W.getUint32($+4);return Z*4294967296+G}var O=4294967295;function rW({sec:W,nsec:$}){if(W>=0&&$>=0&&W<=iW)if($===0&&W<=nW){let Z=new Uint8Array(4);return new DataView(Z.buffer).setUint32(0,W),Z}else{let Z=W/4294967296,G=W&4294967295,J=new Uint8Array(8),Q=new DataView(J.buffer);return Q.setUint32(0,$<<2|Z&3),Q.setUint32(4,G),J}else{let Z=new Uint8Array(12),G=new DataView(Z.buffer);return G.setUint32(0,$),x(G,4,W),Z}}function sW(W){let $=W.getTime(),Z=Math.floor($/1000),G=($-Z*1000)*1e6,J=Math.floor(G/1e9);return{sec:Z+J,nsec:G-J*1e9}}function aW(W){if(W instanceof Date){let $=sW(W);return rW($)}else return null}function oW(W){let $=new DataView(W.buffer,W.byteOffset,W.byteLength);switch(W.byteLength){case 4:{let Z=$.getUint32(0),G=0;return{sec:Z,nsec:0}}case 8:{let Z=$.getUint32(0),G=$.getUint32(4),J=(Z&3)*4294967296+G,Q=Z>>>2;return{sec:J,nsec:Q}}case 12:{let Z=S($,4),G=$.getUint32(0);return{sec:Z,nsec:G}}default:throw new V(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${W.length}`)}}function tW(W){let $=oW(W);return new Date($.sec*1000+$.nsec/1e6)}var dW=-1,nW=4294967295,iW=17179869183,HW;var VW=X(()=>{f();HW={type:dW,encode:aW,decode:tW}});var R;var E=X(()=>{VW();R=class R{static defaultCodec=new R;__brand;builtInEncoders=[];builtInDecoders=[];encoders=[];decoders=[];constructor(){this.register(HW)}register({type:W,encode:$,decode:Z}){if(W>=0)this.encoders[W]=$,this.decoders[W]=Z;else{let G=-1-W;this.builtInEncoders[G]=$,this.builtInDecoders[G]=Z}}tryToEncode(W,$){for(let Z=0;Z<this.builtInEncoders.length;Z++){let G=this.builtInEncoders[Z];if(G!=null){let J=G(W,$);if(J!=null){let Q=-1-Z;return new K(Q,J)}}}for(let Z=0;Z<this.encoders.length;Z++){let G=this.encoders[Z];if(G!=null){let J=G(W,$);if(J!=null)return new K(Z,J)}}if(W instanceof K)return W;return null}decode(W,$,Z){let G=$<0?this.builtInDecoders[-1-$]:this.decoders[$];if(G)return G(W,$,Z);else return new K($,W)}}});function eW(W){return W instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&W instanceof SharedArrayBuffer}function T(W){if(W instanceof Uint8Array)return W;else if(ArrayBuffer.isView(W))return new Uint8Array(W.buffer,W.byteOffset,W.byteLength);else if(eW(W))return new Uint8Array(W);else return Uint8Array.from(W)}class k{extensionCodec;context;useBigInt64;maxDepth;initialBufferSize;sortKeys;forceFloat32;ignoreUndefined;forceIntegerToFloat;pos;view;bytes;entered=!1;constructor(W){this.extensionCodec=W?.extensionCodec??R.defaultCodec,this.context=W?.context,this.useBigInt64=W?.useBigInt64??!1,this.maxDepth=W?.maxDepth??W0,this.initialBufferSize=W?.initialBufferSize??$0,this.sortKeys=W?.sortKeys??!1,this.forceFloat32=W?.forceFloat32??!1,this.ignoreUndefined=W?.ignoreUndefined??!1,this.forceIntegerToFloat=W?.forceIntegerToFloat??!1,this.pos=0,this.view=new DataView(new ArrayBuffer(this.initialBufferSize)),this.bytes=new Uint8Array(this.view.buffer)}clone(){return new k({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,maxDepth:this.maxDepth,initialBufferSize:this.initialBufferSize,sortKeys:this.sortKeys,forceFloat32:this.forceFloat32,ignoreUndefined:this.ignoreUndefined,forceIntegerToFloat:this.forceIntegerToFloat})}reinitializeState(){this.pos=0}encodeSharedRef(W){if(this.entered)return this.clone().encodeSharedRef(W);try{return this.entered=!0,this.reinitializeState(),this.doEncode(W,1),this.bytes.subarray(0,this.pos)}finally{this.entered=!1}}encode(W){if(this.entered)return this.clone().encode(W);try{return this.entered=!0,this.reinitializeState(),this.doEncode(W,1),this.bytes.slice(0,this.pos)}finally{this.entered=!1}}doEncode(W,$){if($>this.maxDepth)throw Error(`Too deep objects in depth ${$}`);if(W==null)this.encodeNil();else if(typeof W==="boolean")this.encodeBoolean(W);else if(typeof W==="number")if(!this.forceIntegerToFloat)this.encodeNumber(W);else this.encodeNumberAsFloat(W);else if(typeof W==="string")this.encodeString(W);else if(this.useBigInt64&&typeof W==="bigint")this.encodeBigInt64(W);else this.encodeObject(W,$)}ensureBufferSizeToWrite(W){let $=this.pos+W;if(this.view.byteLength<$)this.resizeBuffer($*2)}resizeBuffer(W){let $=new ArrayBuffer(W),Z=new Uint8Array($),G=new DataView($);Z.set(this.bytes),this.view=G,this.bytes=Z}encodeNil(){this.writeU8(192)}encodeBoolean(W){if(W===!1)this.writeU8(194);else this.writeU8(195)}encodeNumber(W){if(!this.forceIntegerToFloat&&Number.isSafeInteger(W))if(W>=0)if(W<128)this.writeU8(W);else if(W<256)this.writeU8(204),this.writeU8(W);else if(W<65536)this.writeU8(205),this.writeU16(W);else if(W<4294967296)this.writeU8(206),this.writeU32(W);else if(!this.useBigInt64)this.writeU8(207),this.writeU64(W);else this.encodeNumberAsFloat(W);else if(W>=-32)this.writeU8(224|W+32);else if(W>=-128)this.writeU8(208),this.writeI8(W);else if(W>=-32768)this.writeU8(209),this.writeI16(W);else if(W>=-2147483648)this.writeU8(210),this.writeI32(W);else if(!this.useBigInt64)this.writeU8(211),this.writeI64(W);else this.encodeNumberAsFloat(W);else this.encodeNumberAsFloat(W)}encodeNumberAsFloat(W){if(this.forceFloat32)this.writeU8(202),this.writeF32(W);else this.writeU8(203),this.writeF64(W)}encodeBigInt64(W){if(W>=BigInt(0))this.writeU8(207),this.writeBigUint64(W);else this.writeU8(211),this.writeBigInt64(W)}writeStringHeader(W){if(W<32)this.writeU8(160+W);else if(W<256)this.writeU8(217),this.writeU8(W);else if(W<65536)this.writeU8(218),this.writeU16(W);else if(W<4294967296)this.writeU8(219),this.writeU32(W);else throw Error(`Too long string: ${W} bytes in UTF-8`)}encodeString(W){let Z=QW(W);this.ensureBufferSizeToWrite(5+Z),this.writeStringHeader(Z),qW(W,this.bytes,this.pos),this.pos+=Z}encodeObject(W,$){let Z=this.extensionCodec.tryToEncode(W,this.context);if(Z!=null)this.encodeExtension(Z);else if(Array.isArray(W))this.encodeArray(W,$);else if(ArrayBuffer.isView(W))this.encodeBinary(W);else if(typeof W==="object")this.encodeMap(W,$);else throw Error(`Unrecognized object: ${Object.prototype.toString.apply(W)}`)}encodeBinary(W){let $=W.byteLength;if($<256)this.writeU8(196),this.writeU8($);else if($<65536)this.writeU8(197),this.writeU16($);else if($<4294967296)this.writeU8(198),this.writeU32($);else throw Error(`Too large binary: ${$}`);let Z=T(W);this.writeU8a(Z)}encodeArray(W,$){let Z=W.length;if(Z<16)this.writeU8(144+Z);else if(Z<65536)this.writeU8(220),this.writeU16(Z);else if(Z<4294967296)this.writeU8(221),this.writeU32(Z);else throw Error(`Too large array: ${Z}`);for(let G of W)this.doEncode(G,$+1)}countWithoutUndefined(W,$){let Z=0;for(let G of $)if(W[G]!==void 0)Z++;return Z}encodeMap(W,$){let Z=Object.keys(W);if(this.sortKeys)Z.sort();let G=this.ignoreUndefined?this.countWithoutUndefined(W,Z):Z.length;if(G<16)this.writeU8(128+G);else if(G<65536)this.writeU8(222),this.writeU16(G);else if(G<4294967296)this.writeU8(223),this.writeU32(G);else throw Error(`Too large map object: ${G}`);for(let J of Z){let Q=W[J];if(!(this.ignoreUndefined&&Q===void 0))this.encodeString(J),this.doEncode(Q,$+1)}}encodeExtension(W){if(typeof W.data==="function"){let Z=W.data(this.pos+6),G=Z.length;if(G>=4294967296)throw Error(`Too large extension object: ${G}`);this.writeU8(201),this.writeU32(G),this.writeI8(W.type),this.writeU8a(Z);return}let $=W.data.length;if($===1)this.writeU8(212);else if($===2)this.writeU8(213);else if($===4)this.writeU8(214);else if($===8)this.writeU8(215);else if($===16)this.writeU8(216);else if($<256)this.writeU8(199),this.writeU8($);else if($<65536)this.writeU8(200),this.writeU16($);else if($<4294967296)this.writeU8(201),this.writeU32($);else throw Error(`Too large extension object: ${$}`);this.writeI8(W.type),this.writeU8a(W.data)}writeU8(W){this.ensureBufferSizeToWrite(1),this.view.setUint8(this.pos,W),this.pos++}writeU8a(W){let $=W.length;this.ensureBufferSizeToWrite($),this.bytes.set(W,this.pos),this.pos+=$}writeI8(W){this.ensureBufferSizeToWrite(1),this.view.setInt8(this.pos,W),this.pos++}writeU16(W){this.ensureBufferSizeToWrite(2),this.view.setUint16(this.pos,W),this.pos+=2}writeI16(W){this.ensureBufferSizeToWrite(2),this.view.setInt16(this.pos,W),this.pos+=2}writeU32(W){this.ensureBufferSizeToWrite(4),this.view.setUint32(this.pos,W),this.pos+=4}writeI32(W){this.ensureBufferSizeToWrite(4),this.view.setInt32(this.pos,W),this.pos+=4}writeF32(W){this.ensureBufferSizeToWrite(4),this.view.setFloat32(this.pos,W),this.pos+=4}writeF64(W){this.ensureBufferSizeToWrite(8),this.view.setFloat64(this.pos,W),this.pos+=8}writeU64(W){this.ensureBufferSizeToWrite(8),XW(this.view,this.pos,W),this.pos+=8}writeI64(W){this.ensureBufferSizeToWrite(8),x(this.view,this.pos,W),this.pos+=8}writeBigUint64(W){this.ensureBufferSizeToWrite(8),this.view.setBigUint64(this.pos,W),this.pos+=8}writeBigInt64(W){this.ensureBufferSizeToWrite(8),this.view.setBigInt64(this.pos,W),this.pos+=8}}var W0=100,$0=2048;var PW=X(()=>{C();E()});function M(W,$){return new k($).encodeSharedRef(W)}var NW=X(()=>{PW()});function w(W){return`${W<0?"-":""}0x${Math.abs(W).toString(16).padStart(2,"0")}`}class l{hit=0;miss=0;caches;maxKeyLength;maxLengthPerKey;constructor(W=Z0,$=G0){this.maxKeyLength=W,this.maxLengthPerKey=$,this.caches=[];for(let Z=0;Z<this.maxKeyLength;Z++)this.caches.push([])}canBeCached(W){return W>0&&W<=this.maxKeyLength}find(W,$,Z){let G=this.caches[Z-1];W:for(let J of G){let Q=J.bytes;for(let F=0;F<Z;F++)if(Q[F]!==W[$+F])continue W;return J.str}return null}store(W,$){let Z=this.caches[W.length-1],G={bytes:W,str:$};if(Z.length>=this.maxLengthPerKey)Z[Math.random()*Z.length|0]=G;else Z.push(G)}decode(W,$,Z){let G=this.find(W,$,Z);if(G!=null)return this.hit++,G;this.miss++;let J=y(W,$,Z),Q=Uint8Array.prototype.slice.call(W,$,$+Z);return this.store(Q,J),J}}var Z0=16,G0=16;var RW=X(()=>{C()});class _W{stack=[];stackHeadPosition=-1;get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState(W){let $=this.getUninitializedStateFromPool();$.type=p,$.position=0,$.size=W,$.array=Array(W)}pushMapState(W){let $=this.getUninitializedStateFromPool();$.type=L,$.readCount=0,$.size=W,$.map={}}getUninitializedStateFromPool(){if(this.stackHeadPosition++,this.stackHeadPosition===this.stack.length){let W={type:void 0,size:0,array:void 0,position:0,readCount:0,map:void 0,key:null};this.stack.push(W)}return this.stack[this.stackHeadPosition]}release(W){if(this.stack[this.stackHeadPosition]!==W)throw Error("Invalid stack state. Released state is not on top of the stack.");if(W.type===p){let Z=W;Z.size=0,Z.array=void 0,Z.position=0,Z.type=void 0}if(W.type===L||W.type===UW){let Z=W;Z.size=0,Z.map=void 0,Z.readCount=0,Z.type=void 0}this.stackHeadPosition--}reset(){this.stack.length=0,this.stackHeadPosition=-1}}class j{extensionCodec;context;useBigInt64;rawStrings;maxStrLength;maxBinLength;maxArrayLength;maxMapLength;maxExtLength;keyDecoder;mapKeyConverter;totalPos=0;pos=0;view=u;bytes=Q0;headByte=D;stack=new _W;entered=!1;constructor(W){this.extensionCodec=W?.extensionCodec??R.defaultCodec,this.context=W?.context,this.useBigInt64=W?.useBigInt64??!1,this.rawStrings=W?.rawStrings??!1,this.maxStrLength=W?.maxStrLength??O,this.maxBinLength=W?.maxBinLength??O,this.maxArrayLength=W?.maxArrayLength??O,this.maxMapLength=W?.maxMapLength??O,this.maxExtLength=W?.maxExtLength??O,this.keyDecoder=W?.keyDecoder!==void 0?W.keyDecoder:q0,this.mapKeyConverter=W?.mapKeyConverter??J0}clone(){return new j({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,rawStrings:this.rawStrings,maxStrLength:this.maxStrLength,maxBinLength:this.maxBinLength,maxArrayLength:this.maxArrayLength,maxMapLength:this.maxMapLength,maxExtLength:this.maxExtLength,keyDecoder:this.keyDecoder})}reinitializeState(){this.totalPos=0,this.headByte=D,this.stack.reset()}setBuffer(W){let $=T(W);this.bytes=$,this.view=new DataView($.buffer,$.byteOffset,$.byteLength),this.pos=0}appendBuffer(W){if(this.headByte===D&&!this.hasRemaining(1))this.setBuffer(W);else{let $=this.bytes.subarray(this.pos),Z=T(W),G=new Uint8Array($.length+Z.length);G.set($),G.set(Z,$.length),this.setBuffer(G)}}hasRemaining(W){return this.view.byteLength-this.pos>=W}createExtraByteError(W){let{view:$,pos:Z}=this;return RangeError(`Extra ${$.byteLength-Z} of ${$.byteLength} byte(s) found at buffer[${W}]`)}decode(W){if(this.entered)return this.clone().decode(W);try{this.entered=!0,this.reinitializeState(),this.setBuffer(W);let $=this.doDecodeSync();if(this.hasRemaining(1))throw this.createExtraByteError(this.pos);return $}finally{this.entered=!1}}*decodeMulti(W){if(this.entered){yield*this.clone().decodeMulti(W);return}try{this.entered=!0,this.reinitializeState(),this.setBuffer(W);while(this.hasRemaining(1))yield this.doDecodeSync()}finally{this.entered=!1}}async decodeAsync(W){if(this.entered)return this.clone().decodeAsync(W);try{this.entered=!0;let $=!1,Z;for await(let F of W){if($)throw this.entered=!1,this.createExtraByteError(this.totalPos);this.appendBuffer(F);try{Z=this.doDecodeSync(),$=!0}catch(H){if(!(H instanceof RangeError))throw H}this.totalPos+=this.pos}if($){if(this.hasRemaining(1))throw this.createExtraByteError(this.totalPos);return Z}let{headByte:G,pos:J,totalPos:Q}=this;throw RangeError(`Insufficient data in parsing ${w(G)} at ${Q} (${J} in the current buffer)`)}finally{this.entered=!1}}decodeArrayStream(W){return this.decodeMultiAsync(W,!0)}decodeStream(W){return this.decodeMultiAsync(W,!1)}async*decodeMultiAsync(W,$){if(this.entered){yield*this.clone().decodeMultiAsync(W,$);return}try{this.entered=!0;let Z=$,G=-1;for await(let J of W){if($&&G===0)throw this.createExtraByteError(this.totalPos);if(this.appendBuffer(J),Z)G=this.readArraySize(),Z=!1,this.complete();try{while(!0)if(yield this.doDecodeSync(),--G===0)break}catch(Q){if(!(Q instanceof RangeError))throw Q}this.totalPos+=this.pos}}finally{this.entered=!1}}doDecodeSync(){W:while(!0){let W=this.readHeadByte(),$;if(W>=224)$=W-256;else if(W<192)if(W<128)$=W;else if(W<144){let G=W-128;if(G!==0){this.pushMapState(G),this.complete();continue W}else $={}}else if(W<160){let G=W-144;if(G!==0){this.pushArrayState(G),this.complete();continue W}else $=[]}else{let G=W-160;$=this.decodeString(G,0)}else if(W===192)$=null;else if(W===194)$=!1;else if(W===195)$=!0;else if(W===202)$=this.readF32();else if(W===203)$=this.readF64();else if(W===204)$=this.readU8();else if(W===205)$=this.readU16();else if(W===206)$=this.readU32();else if(W===207)if(this.useBigInt64)$=this.readU64AsBigInt();else $=this.readU64();else if(W===208)$=this.readI8();else if(W===209)$=this.readI16();else if(W===210)$=this.readI32();else if(W===211)if(this.useBigInt64)$=this.readI64AsBigInt();else $=this.readI64();else if(W===217){let G=this.lookU8();$=this.decodeString(G,1)}else if(W===218){let G=this.lookU16();$=this.decodeString(G,2)}else if(W===219){let G=this.lookU32();$=this.decodeString(G,4)}else if(W===220){let G=this.readU16();if(G!==0){this.pushArrayState(G),this.complete();continue W}else $=[]}else if(W===221){let G=this.readU32();if(G!==0){this.pushArrayState(G),this.complete();continue W}else $=[]}else if(W===222){let G=this.readU16();if(G!==0){this.pushMapState(G),this.complete();continue W}else $={}}else if(W===223){let G=this.readU32();if(G!==0){this.pushMapState(G),this.complete();continue W}else $={}}else if(W===196){let G=this.lookU8();$=this.decodeBinary(G,1)}else if(W===197){let G=this.lookU16();$=this.decodeBinary(G,2)}else if(W===198){let G=this.lookU32();$=this.decodeBinary(G,4)}else if(W===212)$=this.decodeExtension(1,0);else if(W===213)$=this.decodeExtension(2,0);else if(W===214)$=this.decodeExtension(4,0);else if(W===215)$=this.decodeExtension(8,0);else if(W===216)$=this.decodeExtension(16,0);else if(W===199){let G=this.lookU8();$=this.decodeExtension(G,1)}else if(W===200){let G=this.lookU16();$=this.decodeExtension(G,2)}else if(W===201){let G=this.lookU32();$=this.decodeExtension(G,4)}else throw new V(`Unrecognized type byte: ${w(W)}`);this.complete();let Z=this.stack;while(Z.length>0){let G=Z.top();if(G.type===p)if(G.array[G.position]=$,G.position++,G.position===G.size)$=G.array,Z.release(G);else continue W;else if(G.type===L){if($==="__proto__")throw new V("The key __proto__ is not allowed");G.key=this.mapKeyConverter($),G.type=UW;continue W}else if(G.map[G.key]=$,G.readCount++,G.readCount===G.size)$=G.map,Z.release(G);else{G.key=null,G.type=L;continue W}}return $}}readHeadByte(){if(this.headByte===D)this.headByte=this.readU8();return this.headByte}complete(){this.headByte=D}readArraySize(){let W=this.readHeadByte();switch(W){case 220:return this.readU16();case 221:return this.readU32();default:if(W<160)return W-144;else throw new V(`Unrecognized array type byte: ${w(W)}`)}}pushMapState(W){if(W>this.maxMapLength)throw new V(`Max length exceeded: map length (${W}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.pushMapState(W)}pushArrayState(W){if(W>this.maxArrayLength)throw new V(`Max length exceeded: array length (${W}) > maxArrayLength (${this.maxArrayLength})`);this.stack.pushArrayState(W)}decodeString(W,$){if(!this.rawStrings||this.stateIsMapKey())return this.decodeUtf8String(W,$);return this.decodeBinary(W,$)}decodeUtf8String(W,$){if(W>this.maxStrLength)throw new V(`Max length exceeded: UTF-8 byte length (${W}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+$+W)throw MW;let Z=this.pos+$,G;if(this.stateIsMapKey()&&this.keyDecoder?.canBeCached(W))G=this.keyDecoder.decode(this.bytes,Z,W);else G=FW(this.bytes,Z,W);return this.pos+=$+W,G}stateIsMapKey(){if(this.stack.length>0)return this.stack.top().type===L;return!1}decodeBinary(W,$){if(W>this.maxBinLength)throw new V(`Max length exceeded: bin length (${W}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining(W+$))throw MW;let Z=this.pos+$,G=this.bytes.subarray(Z,Z+W);return this.pos+=$+W,G}decodeExtension(W,$){if(W>this.maxExtLength)throw new V(`Max length exceeded: ext length (${W}) > maxExtLength (${this.maxExtLength})`);let Z=this.view.getInt8(this.pos+$),G=this.decodeBinary(W,$+1);return this.extensionCodec.decode(G,Z,this.context)}lookU8(){return this.view.getUint8(this.pos)}lookU16(){return this.view.getUint16(this.pos)}lookU32(){return this.view.getUint32(this.pos)}readU8(){let W=this.view.getUint8(this.pos);return this.pos++,W}readI8(){let W=this.view.getInt8(this.pos);return this.pos++,W}readU16(){let W=this.view.getUint16(this.pos);return this.pos+=2,W}readI16(){let W=this.view.getInt16(this.pos);return this.pos+=2,W}readU32(){let W=this.view.getUint32(this.pos);return this.pos+=4,W}readI32(){let W=this.view.getInt32(this.pos);return this.pos+=4,W}readU64(){let W=YW(this.view,this.pos);return this.pos+=8,W}readI64(){let W=S(this.view,this.pos);return this.pos+=8,W}readU64AsBigInt(){let W=this.view.getBigUint64(this.pos);return this.pos+=8,W}readI64AsBigInt(){let W=this.view.getBigInt64(this.pos);return this.pos+=8,W}readF32(){let W=this.view.getFloat32(this.pos);return this.pos+=4,W}readF64(){let W=this.view.getFloat64(this.pos);return this.pos+=8,W}}var p="array",L="map_key",UW="map_value",J0=(W)=>{if(typeof W==="string"||typeof W==="number")return W;throw new V("The type of key must be string or number but "+typeof W)},D=-1,u,Q0,MW,q0;var BW=X(()=>{E();C();RW();f();u=new DataView(new ArrayBuffer(0)),Q0=new Uint8Array(u.buffer);try{u.getInt8(0)}catch(W){if(!(W instanceof RangeError))throw Error("This module is not supported in the current JavaScript engine because DataView does not throw RangeError on out-of-bounds access")}MW=RangeError("Insufficient data"),q0=new l});function U(W,$){return new j($).decode(W)}var KW=X(()=>{BW()});var c=X(()=>{NW();KW();E()});function d(W){if(typeof W==="object"&&W!==null&&!Array.isArray(W))return W;return{}}function h(W){return Array.isArray(W)?W:[]}function OW(W){if(!(W instanceof Date))return null;let $=new ArrayBuffer(8);return new DataView($).setFloat64(0,W.getTime()),new Uint8Array($)}function AW(W){let $=new DataView(W.buffer,W.byteOffset,W.byteLength).getFloat64(0);return new Date($)}function R0(W){return typeof W==="object"&&W!==null&&"__tag"in W&&W.__tag===zW}function _(W,$){if(W===void 0)return N0;if(W===null||typeof W!=="object")return W;if($.has(W))return W;$.add(W);try{return M0(W,$)}finally{$.delete(W)}}function M0(W,$){if(Array.isArray(W))return U0(W,$);if(W instanceof Map)return _0(W,$);if(W instanceof Set)return B0(W,$);if(K0(W))return W;return O0(W,$)}function U0(W,$){let Z=Array.from({length:W.length});for(let G=0;G<W.length;G++)Z[G]=_(W[G],$);return Z}function _0(W,$){let Z=new Map;for(let[G,J]of W)Z.set(_(G,$),_(J,$));return Z}function B0(W,$){let Z=new Set;for(let G of W)Z.add(_(G,$));return Z}function K0(W){return W instanceof Date||W instanceof RegExp||W instanceof Error||W instanceof Uint8Array||W instanceof ArrayBuffer}function O0(W,$){let Z=W,G={};for(let J of Object.keys(Z))G[J]=_(Z[J],$);return G}var F0=1,X0=2,Y0=3,H0=4,V0=5,P0=6,P,zW,N0;var TW=X(()=>{c();P=new R;P.register({type:F0,encode:OW,decode:AW});P.register({type:X0,encode(W){if(W instanceof RegExp)return M({source:W.source,flags:W.flags});return null},decode(W){let $=d(U(W)),Z=typeof $.source==="string"?$.source:"",G=typeof $.flags==="string"?$.flags:"";return new RegExp(Z,G)}});P.register({type:Y0,encode(W){if(W instanceof Map){let $=[...W.entries()];return M($,{extensionCodec:P})}return null},decode(W){let Z=h(U(W,{extensionCodec:P})).map((G)=>{let J=h(G);return[J[0],J[1]]});return new Map(Z)}});P.register({type:H0,encode(W){if(W instanceof Set){let $=[...W.values()];return M($,{extensionCodec:P})}return null},decode(W){let $=h(U(W,{extensionCodec:P}));return new Set($)}});zW=Symbol("UndefinedSentinel"),N0=Object.freeze({__tag:zW});P.register({type:V0,encode(W){if(R0(W))return new Uint8Array(0);return null},decode(){return}});P.register({type:P0,encode(W){if(W instanceof Error)return M({name:W.name,message:W.message,stack:W.stack});return null},decode(W){let $=d(U(W)),Z=typeof $.name==="string"?$.name:"Error",G=typeof $.message==="string"?$.message:"",J=typeof $.stack==="string"?$.stack:void 0,Q=Error(G);if(Q.name=Z,J!==void 0)Q.stack=J;return Q}})});function n(W){let $=_(W,new Set);return M($,{extensionCodec:P})}function i(W){return U(W,{extensionCodec:P})}var DW=X(()=>{c();TW()});function m(W,$=""){let Z=[];return I(W,$,Z,new Set),{valid:Z.length===0,errors:Z}}function A0(W){let $=Object.getPrototypeOf(W);return z0($)&&!T0(W)&&D0($)}function z0(W){return W!==Object.prototype&&W!==null}function T0(W){return Array.isArray(W)||W instanceof Date||W instanceof RegExp||W instanceof Map||W instanceof Set||W instanceof Error||W instanceof Uint8Array||W instanceof ArrayBuffer}function D0(W){if(typeof W!=="object"||W===null)return!1;return Object.getOwnPropertyNames(W).some((Z)=>{if(Z==="constructor")return!1;let G=Object.getOwnPropertyDescriptor(W,Z);return G!==void 0&&typeof G.value==="function"})}function LW(W,$,Z,G){W.push({path:$,value:Z,reason:G.reason,suggestion:G.suggestion})}function L0(W){if(typeof W==="function")return{reason:"Functions cannot be serialized.",suggestion:"Move this into ctx.run() or reconstruct it on resume."};if(typeof W==="symbol")return{reason:"Symbols cannot be serialized.",suggestion:"Use a string identifier instead of a Symbol."};return null}function I0(W,$){if(W instanceof WeakRef)return{reason:"WeakRef cannot be serialized.",suggestion:"Store the referenced value directly instead of using a WeakRef."};if(W instanceof WeakMap)return{reason:"WeakMap cannot be serialized.",suggestion:"Use a Map instead of a WeakMap."};if(W instanceof WeakSet)return{reason:"WeakSet cannot be serialized.",suggestion:"Use a Set instead of a WeakSet."};if($.has(W))return{reason:"Circular reference detected.",suggestion:"Remove the circular reference or restructure the data."};if(A0(W))return{reason:"Class instances with methods cannot be serialized.",suggestion:"Store only the data and reconstruct the instance."};return null}function C0(W){return W instanceof Date||W instanceof RegExp||W instanceof Error||W instanceof Uint8Array||W instanceof ArrayBuffer}function x0(W,$,Z,G){for(let[J,Q]of W){let F=String(J);I(Q,$?`${$}.${F}`:F,Z,G)}}function S0(W,$,Z,G){let J=0;for(let Q of W){let F=$?`${$}[${J}]`:`[${J}]`;I(Q,F,Z,G),J++}}function E0(W,$,Z,G){for(let J=0;J<W.length;J++){let Q=$?`${$}[${J}]`:`[${J}]`;I(W[J],Q,Z,G)}}function k0(W,$,Z,G){for(let J of Object.keys(W)){let Q=$?`${$}.${J}`:J;I(W[J],Q,Z,G)}}function I(W,$,Z,G){if(W===null||W===void 0)return;let J=L0(W);if(J){LW(Z,$,W,J);return}if(typeof W!=="object")return;let Q=I0(W,G);if(Q){LW(Z,$,W,Q);return}G.add(W);try{if(C0(W))return;if(W instanceof Map){x0(W,$,Z,G);return}if(W instanceof Set){S0(W,$,Z,G);return}if(Array.isArray(W)){E0(W,$,Z,G);return}k0(W,$,Z,G)}finally{G.delete(W)}}var IW=X(()=>{DW()});var CW=X(()=>{IW()});function w0(W){if(W===void 0)return;if(typeof W!=="number"||!Number.isInteger(W)||W<0)throw Error("deleteRange limit must be a finite non-negative integer");return W===0?0:W}function j0(W){let $={},Z=!1;for(let J of["gt","gte","lt","lte"]){let Q=W[J];if(Q===void 0)continue;if(typeof Q!=="string")throw Error("deleteRange bounds must be strings");$[J]=Q,Z=!0}if(!Z)throw Error("deleteRange requires at least one of gt/gte/lt/lte; use deletePrefix to delete a whole prefix");let G=w0(W.limit);if(G!==void 0)$.limit=G;return $}async function xW(W,$,Z){let G=j0(Z);if(W.deleteRange)return W.deleteRange($,G);return o(W,$,G)}var SW=()=>{};CW();SW();JW();class EW{#W;#$;#Z;constructor(W,$,Z={}){this.#W=W,this.#$=$,this.#Z=Z.disposeUnderlyingStorage??!0}async get(W){let $=await this.#W.get(W);return $===null?null:this.#$.decode($)}async put(W,$){await this.#W.put(W,this.#$.encode($))}async delete(W){await this.#W.delete(W)}async*scan(W,$){for await(let[Z,G]of this.#W.scan(W,$))yield[Z,this.#$.decode(G)]}async batch(W){await this.#W.batch(this.#G(W))}#G(W){return W.map((Z)=>{if(Z.type==="put")return{type:"put",key:Z.key,value:this.#$.encode(Z.value)};return Z})}#J(W){return W.map(($)=>({key:$.key,expectedValue:$.expectedValue===null?null:this.#$.encode($.expectedValue)}))}async conditionalBatch(W,$){return GW(this.#W,this.#J(W),this.#G($))}async has(W){return e(this.#W,W)}async deletePrefix(W){return ZW(this.#W,W)}async deleteRange(W,$){return xW(this.#W,W,$)}keys(W,$){return WW(this.#W,W,$)}async count(W){return $W(this.#W,W)}[Symbol.dispose](){if(!this.#Z)return;this.#W[Symbol.dispose]()}}function z6(W,$,Z={}){return new EW(W,$,Z)}function h0(W){try{let $=JSON.stringify(W);if($===void 0)throw TypeError("jsonCodec only supports JSON-serializable values.");return new TextEncoder().encode($)}catch($){throw TypeError("jsonCodec only supports JSON-serializable values.",{cause:$})}}function m0(W){let $=m(W);if(!$.valid)throw TypeError(`msgpackCodec only supports structuredClone-compatible values. ${$.errors[0]?.reason??""}`.trim());return n(W)}function g0(W){return JSON.parse(new TextDecoder().decode(W))}function v0(W){let $=i(W),Z=m($);if(!Z.valid)throw TypeError(`msgpackCodec decoded a non-cloneable value. ${Z.errors[0]?.reason??""}`.trim());return $}function T6(W){return{encode($){return h0($)},decode($){let Z=g0($);return W?W(Z):Z}}}function D6(W){return{encode($){return m0($)},decode($){let Z=v0($);return W?W(Z):Z}}}export{z6 as withCodec,D6 as msgpackCodec,T6 as jsonCodec};
@@ -0,0 +1,55 @@
1
+ import { type DeleteRangeOptions } from './delete-range.ts';
2
+ import { type BatchOperation, type ScanOptions, type Storage, type StorageCapabilities } from './interface.ts';
3
+ /** Named WebExtension storage area used by {@link WebExtensionStorage}.
4
+ * @example
5
+ * ```ts
6
+ * import { WebExtensionStorage, type WebExtensionStorageArea } from '@lostgradient/weft/storage/web-extension';
7
+ * const area: WebExtensionStorageArea = 'local';
8
+ * const storage = new WebExtensionStorage({ area });
9
+ * ```
10
+ */
11
+ export type WebExtensionStorageArea = 'local' | 'sync' | 'session' | 'managed';
12
+ /** Constructor options for {@link WebExtensionStorage}.
13
+ * @example
14
+ * ```ts
15
+ * import { WebExtensionStorage, type WebExtensionStorageOptions } from '@lostgradient/weft/storage/web-extension';
16
+ * const options: WebExtensionStorageOptions = { area: 'sync' };
17
+ * const storage = new WebExtensionStorage(options);
18
+ * ```
19
+ */
20
+ export type WebExtensionStorageOptions = {
21
+ area?: WebExtensionStorageArea;
22
+ };
23
+ /**
24
+ * WebExtension storage adapter for browser extension contexts.
25
+ *
26
+ * Values are stored as JSON envelopes containing base64-encoded `Uint8Array`
27
+ * bytes so the canonical Weft storage value type stays portable across
28
+ * `browser.storage` and callback-style `chrome.storage` implementations.
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * import { Engine } from '@lostgradient/weft';
33
+ * import { WebExtensionStorage } from '@lostgradient/weft/storage/web-extension';
34
+ *
35
+ * await using storage = new WebExtensionStorage({ area: 'local' });
36
+ * await using engine = new Engine({ storage });
37
+ * ```
38
+ */
39
+ export declare class WebExtensionStorage implements Storage {
40
+ #private;
41
+ constructor(options?: WebExtensionStorageOptions);
42
+ capabilities(): StorageCapabilities;
43
+ get(key: string): Promise<Uint8Array | null>;
44
+ put(key: string, value: Uint8Array): Promise<void>;
45
+ delete(key: string): Promise<void>;
46
+ scan(prefix: string, options?: ScanOptions): AsyncIterable<[string, Uint8Array]>;
47
+ batch(operations: BatchOperation[]): Promise<void>;
48
+ has(key: string): Promise<boolean>;
49
+ keys(prefix: string, options?: ScanOptions): AsyncIterable<string>;
50
+ count(prefix: string): Promise<number>;
51
+ deletePrefix(prefix: string): Promise<number>;
52
+ deleteRange(prefix: string, options: DeleteRangeOptions): Promise<number>;
53
+ scoped(prefix: string): Storage;
54
+ [Symbol.dispose](): void;
55
+ }
@@ -0,0 +1 @@
1
+ var p=Object.defineProperty;var s=(J)=>J;function a(J,X){this[J]=s.bind(null,X)}var UJ=(J,X)=>{for(var Z in X)p(J,Z,{get:X[Z],enumerable:!0,configurable:!0,set:a.bind(X,Z)})};function K(J){let X=[];for(let Z=0;Z<J.length;Z+=512)X.push(String.fromCharCode(...J.subarray(Z,Z+512)));return btoa(X.join(""))}function b(J){let X=atob(J),Z=new Uint8Array(X.length);for(let F=0;F<X.length;F+=1)Z[F]=X.charCodeAt(F);return Z}function B(J){return typeof J==="object"&&J!==null&&!Array.isArray(J)}async function _(J,X){return await J.get(X)!==null}async function*M(J,X,Z){for await(let[F]of J.scan(X,Z))yield F}async function L(J,X){let Z=0;for await(let F of M(J,X))Z++;return Z}async function D(J,X){let Z=[];for await(let F of M(J,X))Z.push({type:"delete",key:F});if(Z.length===0)return 0;return await J.batch(Z),Z.length}async function W(J,X,Z){let F=[];for await(let V of M(J,X,Z))F.push({type:"delete",key:V});if(F.length===0)return 0;return await J.batch(F),F.length}function O(J,X,Z){if(!J.capabilities()[X])throw Error(`Feature "${Z}" requires storage capability "${X}", but this storage backend does not provide it.`)}var I="default";function S(J){return J.length>0?J.slice(0,-1)+String.fromCharCode(J.charCodeAt(J.length-1)+1):"ÿ"}function x(J,X={}){if(X.gt!==void 0&&J<=X.gt)return!1;if(X.gte!==void 0&&J<X.gte)return!1;if(X.lt!==void 0&&J>=X.lt)return!1;if(X.lte!==void 0&&J>X.lte)return!1;return!0}function WJ(J,X){if(J===null||X===null)return J===X;if(J.byteLength!==X.byteLength)return!1;for(let Z=0;Z<J.byteLength;Z++)if(J[Z]!==X[Z])return!1;return!0}async function v(J,X){if(J.has)return J.has(X);return _(J,X)}function w(J,X,Z){if(J.keys)return J.keys(X,Z);return M(J,X,Z)}async function u(J,X){if(J.count)return J.count(X);return L(J,X)}async function m(J,X){if(J.deletePrefix)return J.deletePrefix(X);return D(J,X)}async function k(J,X,Z){if(O(J,"conditionalBatch","storageConditionalBatch"),!J.conditionalBatch)throw Error("This storage backend reports conditionalBatch capability but does not implement the conditionalBatch() method.");return J.conditionalBatch(X,Z)}function $(J){return encodeURIComponent(J)}function zJ(J){try{return decodeURIComponent(J)}catch{return null}}var G=(J)=>String(J).padStart(16,"0"),BJ={workflow:(J)=>`wf:${$(J)}`,checkpoint:(J)=>`wf:${$(J)}:ckpt`,checkpointHistory:(J,X)=>`wf:${$(J)}:ckpt:${String(X).padStart(10,"0")}`,timelinePrefix:(J)=>`wf:${$(J)}:timeline:`,timeline:(J,X)=>`wf:${$(J)}:timeline:${String(X).padStart(10,"0")}`,schedule:(J)=>`schedule:${$(J)}`,scheduleTick:(J,X)=>`schedule-due:${String(J).padStart(16,"0")}:${$(X)}`,scheduleRun:(J)=>`schedule-run:${$(J)}`,operation:(J,X,Z)=>`op:${J}:${G(X)}:${Z}`,operationInflight:(J)=>`op:inflight:${J}`,operationQueued:(J)=>`op:queued:${J}`,operationResolved:(J)=>`op:resolved:${J}`,bulkOperationAuditPrefix:()=>"audit:bulk:",bulkOperationAudit:(J,X,Z)=>`audit:bulk:${G(J)}:${$(X)}:${$(Z)}`,operationResolvedByTimePrefix:()=>"op:resolved-by-time:",operationResolvedByTime:(J,X)=>`op:resolved-by-time:${G(J)}:${$(X)}`,asyncActivity:(J,X)=>`async-act:v1:${$(J)}:${$(X)}`,activityReconciliationPrefix:(J)=>`actrec:v1:${$(J)}:`,activityReconciliation:(J,X,Z)=>`actrec:v1:${$(J)}:${$(X)}:${Z}`,eventPrefix:(J)=>`ev:${$(J)}:`,event:(J,X)=>`ev:${$(J)}:${String(X).padStart(10,"0")}`,eventHead:(J)=>`ev:${$(J)}:head`,eventWatermark:(J)=>`ev:${$(J)}:watermark`,signal:(J,X,Z)=>`sig:${$(J)}:${X}:${$(Z)}`,signalSequence:(J)=>`sigseq:v1:${$(J)}`,signalAcceptedResponsePrefix:(J)=>`sigres:v1:${$(J)}:`,signalAcceptedResponse:(J,X,Z)=>`sigres:v1:${$(J)}:${$(X)}:${$(Z)}`,deadline:(J,X)=>`wf-deadline:${G(J)}:${$(X)}`,terminalCleanup:(J,X)=>`wf-cleanup:${G(J)}:${$(X)}`,delayedStart:(J,X)=>`wf-delayed:${G(J)}:${$(X)}`,terminalWorkflowPrefix:()=>"wf-terminal:",terminalWorkflow:(J,X)=>`wf-terminal:${G(J)}:${$(X)}`,attribute:(J)=>`attr:${$(J)}`,attributeIndex:(J,X,Z)=>`idx:${J}:${X}:${$(Z)}`,tagIndex:(J,X)=>`tag:${$(J)}:${$(X)}`,updatePrefix:(J)=>`upd:${$(J)}:`,update:(J,X)=>`upd:${$(J)}:${X}`,updateResponse:(J)=>`upr:${J}`,updateIdempotency:(J,X)=>`upk:${$(J)}:${X}`,budget:(J,X,Z)=>`budget:${J}:${X}:${Z}`,review:(J,X)=>`review:${$(J)}:${X}`,workflowHeaders:(J)=>`wf-headers:${$(J)}`,terminalCleanupNeeded:(J)=>`wf-cleanup-needed:${$(J)}`,offload:(J,X)=>`offload:${$(J)}:${X}`,archive:(J,X)=>`archive:${$(J)}:${X}`,stateExecution:(J,X)=>`state:execution:${$(J)}:${$(X)}`,stateWorkflow:(J,X)=>`state:workflow-scope:${I}:${$(J)}:${$(X)}`,streamChunkPrefix:(J,X)=>`blob:${$(J)}:${X}:chunk:`,streamChunk:(J,X,Z)=>`blob:${$(J)}:${X}:chunk:${String(Z).padStart(10,"0")}`,streamMetadata:(J,X)=>`blob:${$(J)}:${X}:meta`,budgetCharged:(J)=>`budget-charged:${J}`,toolEffect:(J,X,Z)=>`tool-effect:${$(J)}:${X}:${Z}`,workflowVisibilityStatus:(J,X)=>`wf-idx-status:${$(J)}:${$(X)}`,workflowVisibilityType:(J,X)=>`wf-idx-type:${$(J)}:${$(X)}`,workflowVisibilityCreated:(J,X)=>`wf-idx-created:${G(J)}:${$(X)}`,workflowVisibilityUpdated:(J,X)=>`wf-idx-updated:${G(J)}:${$(X)}`,workflowVisibilityDeadline:(J,X)=>`wf-idx-deadline:${G(J)}:${$(X)}`,workflowVisibilityManifest:(J)=>`wf-idx-manifest:${$(J)}`,workflowVisibilityMetaVersion:()=>"wf-idx-meta:version",workflowVisibilityMetaBuiltAt:()=>"wf-idx-meta:built-at",workflowVisibilityMetaCursor:()=>"wf-idx-meta:cursor"};function i(J){if(J===void 0)return;if(typeof J!=="number"||!Number.isInteger(J)||J<0)throw Error("deleteRange limit must be a finite non-negative integer");return J===0?0:J}function N(J){let X={},Z=!1;for(let V of["gt","gte","lt","lte"]){let H=J[V];if(H===void 0)continue;if(typeof H!=="string")throw Error("deleteRange bounds must be strings");X[V]=H,Z=!0}if(!Z)throw Error("deleteRange requires at least one of gt/gte/lt/lte; use deletePrefix to delete a whole prefix");let F=i(J.limit);if(F!==void 0)X.limit=F;return X}async function f(J,X,Z){let F=N(Z);if(J.deleteRange)return J.deleteRange(X,F);return W(J,X,F)}function n(J,X){let Z={key:J,open:!1};if(X.gte!==void 0&&X.gte>Z.key)Z.key=X.gte,Z.open=!1;if(X.gt!==void 0&&X.gt>=Z.key)Z.key=X.gt,Z.open=!0;return Z}function r(J,X){let Z={key:S(J),open:!0};if(X.lt!==void 0&&X.lt<=Z.key)Z.key=X.lt,Z.open=!0;if(X.lte!==void 0&&X.lte<Z.key)Z.key=X.lte,Z.open=!1;return Z}function TJ(J,X){let Z=n(J,X),F=r(J,X);if(Z.key>F.key||Z.key===F.key&&(Z.open||F.open))return null;return{lower:Z,upper:F}}function A(J){return J.replaceAll(/:+$/g,"")}function t(J,X){let Z=A(J),F=A(X);if(Z.length===0)return F;if(F.length===0)return Z;return`${Z}:${F}`}class R{#X;#Z;constructor(J,X){this.#X=J,this.#Z=A(X)}#J(J){if(this.#Z.length===0)return J;return J.length===0?`${this.#Z}:`:`${this.#Z}:${J}`}#$(J){if(this.#Z.length===0)return J;return J.slice(this.#Z.length+1)}#F(J={}){let X={};if(J.limit!==void 0)X.limit=J.limit;if(J.reverse!==void 0)X.reverse=J.reverse;if(J.gt!==void 0)X.gt=this.#J(J.gt);if(J.gte!==void 0)X.gte=this.#J(J.gte);if(J.lt!==void 0)X.lt=this.#J(J.lt);if(J.lte!==void 0)X.lte=this.#J(J.lte);return X}#H(J){let X={};if(J.limit!==void 0)X.limit=J.limit;if(J.gt!==void 0)X.gt=this.#J(J.gt);if(J.gte!==void 0)X.gte=this.#J(J.gte);if(J.lt!==void 0)X.lt=this.#J(J.lt);if(J.lte!==void 0)X.lte=this.#J(J.lte);return X}capabilities(){return this.#X.capabilities()}scoped(J){return new R(this.#X,t(this.#Z,J))}async get(J){return this.#X.get(this.#J(J))}async put(J,X){await this.#X.put(this.#J(J),X)}async delete(J){await this.#X.delete(this.#J(J))}async*scan(J,X){for await(let[Z,F]of this.#X.scan(this.#J(J),this.#F(X)))yield[this.#$(Z),F]}async batch(J){await this.#X.batch(J.map((X)=>{if(X.type==="put")return{type:"put",key:this.#J(X.key),value:X.value};return{type:"delete",key:this.#J(X.key)}}))}async conditionalBatch(J,X){return k(this.#X,J.map((Z)=>({key:this.#J(Z.key),expectedValue:Z.expectedValue})),X.map((Z)=>{if(Z.type==="put")return{type:"put",key:this.#J(Z.key),value:Z.value};return{type:"delete",key:this.#J(Z.key)}}))}async has(J){return v(this.#X,this.#J(J))}async deletePrefix(J){return m(this.#X,this.#J(J))}async deleteRange(J,X){let Z=this.#H(N(X));return f(this.#X,this.#J(J),Z)}async*keys(J,X){for await(let Z of w(this.#X,this.#J(J),this.#F(X)))yield this.#$(Z)}async count(J){return u(this.#X,this.#J(J))}[Symbol.dispose](){this.#X[Symbol.dispose]()}}function c(J,X){return new R(J,X)}var d=1,Y="__weftStorageKeyspace",o=102400,e=8192;function JJ(J){return typeof J==="object"&&J!==null&&"then"in J&&typeof J.then==="function"}function E(J){if(!B(J))return!1;if(J.__weftStorage!==d)return!1;return typeof J.value==="string"}function XJ(J){if(!B(J))return!1;return Object.values(J).every(E)}function z(J){if(J!==Y)return;throw Error(`WebExtensionStorage key "${Y}" is reserved for adapter metadata.`)}function ZJ(J){for(let X of J)z(X.key)}function g(J){return{__weftStorage:d,value:K(J)}}function y(J){if(!E(J))return null;return b(J.value)}function $J(J){return E(J)}function P(J){return new TextEncoder().encode(JSON.stringify(J)).byteLength}function FJ(){let J=globalThis,X=J.browser??J.chrome;if(X?.storage===void 0)throw Error("WebExtensionStorage requires globalThis.browser.storage or globalThis.chrome.storage.");return X}function HJ(J,X){let Z=J.storage?.[X];if(Z===void 0)throw Error(`WebExtensionStorage area "${X}" is not available.`);return Z}function VJ(J){if(J==="session")return"ephemeral";if(J==="sync"||J==="managed")return"remote";return"local"}function GJ(J){let X=J.runtime?.lastError?.message;return X===void 0?null:Error(X)}async function T(J,X,Z){return new Promise((F,V)=>{let H=!1,q=(U)=>{if(H)return;let C=GJ(J);if(H=!0,C!==null)V(C);else F(U)},h=(U)=>{if(H)return;H=!0,V(U)},l=(U)=>q(U),Q;try{Q=X(l)}catch{try{Q=Z()}catch(U){h(U);return}}if(JJ(Q))Q.then(q,h)})}class j{static#X=new WeakMap;#Z;#J;#$;#F;#H;constructor(J={}){this.#$=J.area??"local",this.#F=VJ(this.#$),this.#Z=FJ(),this.#J=HJ(this.#Z,this.#$),this.#H=()=>{},this.#Z.storage?.onChanged?.addListener?.(this.#H)}capabilities(){return{persistence:this.#F,readAfterWrite:"session",scanConsistency:"best-effort",atomicBatch:!0,conditionalBatch:!1,boundedRangeDelete:!1}}async#q(J){return T(this.#Z,(X)=>this.#J.get(J,X),()=>this.#J.get(J))}async#j(J){await T(this.#Z,(X)=>this.#J.set(J,X),()=>this.#J.set(J))}async#N(J){if(this.#J.getBytesInUse===void 0)return null;return T(this.#Z,(X)=>this.#J.getBytesInUse?.(J,X),()=>this.#J.getBytesInUse?.(J))}async#V(){let X=(await this.#q(Y))[Y];if(X===void 0)return{};if(!XJ(X))throw Error("WebExtensionStorage keyspace is not a valid storage envelope map.");return{...X}}async#U(J){let X={[Y]:J};await this.#_(X),await this.#j(X)}async#M(J){let X=j.#X.get(this.#J)??Promise.resolve(),Z={},F=new Promise((H)=>{Z.release=H}),V=X.catch(()=>{return}).then(()=>F);j.#X.set(this.#J,V),await X.catch(()=>{return});try{return await J()}finally{if(Z.release?.(),j.#X.get(this.#J)===V)j.#X.delete(this.#J)}}#G(){if(this.#$==="managed")throw Error('WebExtensionStorage area "managed" is read-only.')}#Y(J){let X=this.#J.QUOTA_BYTES_PER_ITEM??e;for(let[Z,F]of Object.entries(J)){let V=P({[Z]:F});if(V>X)throw Error(`WebExtensionStorage sync item quota exceeded for "${Z}": ${String(V)} > ${String(X)}.`)}}async#Q(J){let X=Object.keys(J),Z=await this.#N(null),F=await this.#N(X);if(Z!==null&&F!==null)return Z-F+P(J);let V=await this.#q(null);return P({...V,...J})}async#_(J){if(this.#$!=="sync")return;this.#Y(J);let X=this.#J.QUOTA_BYTES??o,Z=await this.#Q(J);if(Z>X)throw Error(`WebExtensionStorage sync total quota exceeded: ${String(Z)} > ${String(X)}.`)}async get(J){z(J);let X=await this.#V();return y(X[J])}async put(J,X){this.#G(),z(J),await this.#M(async()=>{let Z=await this.#V();Z[J]=g(X),await this.#U(Z)})}async delete(J){this.#G(),z(J),await this.#M(async()=>{let X=await this.#V();if(!(J in X))return;delete X[J],await this.#U(X)})}async*scan(J,X={}){let Z=await this.#V(),F=Object.keys(Z).filter((H)=>H.startsWith(J)).filter((H)=>x(H,X)).filter((H)=>$J(Z[H])).toSorted();if(X.reverse)F=F.toReversed();let V=0;for(let H of F){if(X.limit!==void 0&&V>=X.limit)break;let q=y(Z[H]);if(q===null)continue;yield[H,q],V+=1}}async batch(J){if(this.#G(),J.length===0)return;ZJ(J),await this.#M(async()=>{let X=await this.#V();for(let Z of J)if(Z.type==="put")X[Z.key]=g(Z.value);else delete X[Z.key];await this.#U(X)})}has(J){return _(this,J)}async*keys(J,X){yield*M(this,J,X)}count(J){return L(this,J)}async deletePrefix(J){return this.#G(),D(this,J)}async deleteRange(J,X){let Z=N(X);return this.#G(),W(this,J,Z)}scoped(J){return c(this,J)}[Symbol.dispose](){this.#Z.storage?.onChanged?.removeListener?.(this.#H)}}export{j as WebExtensionStorage};
@@ -0,0 +1,157 @@
1
+ /**
2
+ * Chaos testing primitives for weft workflows.
3
+ *
4
+ * Provides `ChaosScenario` — a type describing fault probability distributions
5
+ * per fault class — and `withChaos(mock, scenario)` — a combinator that wraps
6
+ * any activity mock function with fault injection controlled by the scenario.
7
+ *
8
+ * @module testing/chaos
9
+ */
10
+ import { timeoutFailureCategoryMarker } from '../core/failure-categories.ts';
11
+ export type { FailureCategory } from '../core/types.ts';
12
+ /**
13
+ * Fault classes that chaos injection can produce.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import { withChaos, type FaultClass } from '@lostgradient/weft/testing';
18
+ *
19
+ * const faults: FaultClass[] = ['transient', 'error'];
20
+ * const noisy = withChaos(
21
+ * async (x: number) => x * 2,
22
+ * { faultRate: 0.3, faults },
23
+ * );
24
+ * ```
25
+ */
26
+ export type FaultClass = 'transient' | 'timeout' | 'error' | 'delay';
27
+ /**
28
+ * Describes fault probability distributions for a chaos test run.
29
+ *
30
+ * Attach a `ChaosScenario` to `TestEngine.runN` options or pass it directly
31
+ * to `withChaos` to control how and how often faults are injected.
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * import { withChaos, type ChaosScenario } from '@lostgradient/weft/testing';
36
+ *
37
+ * const scenario: ChaosScenario = {
38
+ * faultRate: 0.2,
39
+ * faults: ['transient', 'delay'],
40
+ * seed: 42,
41
+ * };
42
+ * const noisyMock = withChaos(async (input: string) => input.toUpperCase(), scenario);
43
+ * ```
44
+ */
45
+ export interface ChaosScenario {
46
+ /**
47
+ * Probability [0, 1] that any given activity call will have a fault injected.
48
+ * `0` means never inject; `1` means always inject.
49
+ */
50
+ faultRate: number;
51
+ /**
52
+ * Which fault classes to enable. If omitted, defaults to all classes.
53
+ * When a fault fires, one class is chosen uniformly at random from this list.
54
+ */
55
+ faults?: FaultClass[];
56
+ /**
57
+ * Optional integer seed for a deterministic pseudo-random number generator.
58
+ * When provided, two `withChaos` wrappers created from the same scenario
59
+ * will produce identical fault patterns over the same number of calls.
60
+ */
61
+ seed?: number;
62
+ }
63
+ /**
64
+ * Transient chaos fault. Represents a retryable failure — the kind of error an
65
+ * engine retry policy should re-attempt. Carries `retryable = true` so consumers
66
+ * inspecting the error can make an informed retry decision without parsing
67
+ * error messages.
68
+ *
69
+ * @example
70
+ * ```ts
71
+ * import { ChaosTransientError } from '@lostgradient/weft/testing';
72
+ *
73
+ * const err = new ChaosTransientError();
74
+ * console.log(err.retryable); // true
75
+ * console.log(err.name); // 'ChaosTransientError'
76
+ * ```
77
+ */
78
+ export declare class ChaosTransientError extends Error {
79
+ /** Discriminator for retry-policy consumers. Always `true` for this class. */
80
+ readonly retryable: true;
81
+ constructor(message?: string);
82
+ }
83
+ /**
84
+ * Non-retryable chaos fault. Represents a permanent failure — the kind of
85
+ * error a retry policy should surface immediately without further attempts.
86
+ * Carries `retryable = false` and a `.name` suitable for inclusion in a
87
+ * {@link RetryPolicy.nonRetryableErrors} list.
88
+ *
89
+ * @example
90
+ * ```ts
91
+ * import { ChaosNonRetryableError } from '@lostgradient/weft/testing';
92
+ *
93
+ * const err = new ChaosNonRetryableError();
94
+ * console.log(err.retryable); // false
95
+ * console.log(err.name); // 'ChaosNonRetryableError'
96
+ * ```
97
+ */
98
+ export declare class ChaosNonRetryableError extends Error {
99
+ /** Discriminator for retry-policy consumers. Always `false` for this class. */
100
+ readonly retryable: false;
101
+ constructor(message?: string);
102
+ }
103
+ /**
104
+ * Timeout chaos fault. Thrown when the simulated activity runs long enough for
105
+ * an `AbortSignal.timeout()` to fire. Unlike the other fault classes this is
106
+ * emitted after the injected timeout actually elapses, so calling code
107
+ * exercises the same async/abort shape it would see from a real slow dependency.
108
+ *
109
+ * @example
110
+ * ```ts
111
+ * import { ChaosTimeoutError } from '@lostgradient/weft/testing';
112
+ *
113
+ * const err = new ChaosTimeoutError(25);
114
+ * console.log(err.timeoutMilliseconds); // 25
115
+ * console.log(err.name); // 'ChaosTimeoutError'
116
+ * ```
117
+ */
118
+ export declare class ChaosTimeoutError extends Error {
119
+ /** Milliseconds the chaos wrapper waited before raising the timeout. */
120
+ readonly timeoutMilliseconds: number;
121
+ readonly [timeoutFailureCategoryMarker] = true;
122
+ constructor(timeoutMilliseconds: number);
123
+ }
124
+ /**
125
+ * Wraps an activity mock function with fault injection driven by `scenario`.
126
+ *
127
+ * On each call the combinator consults the PRNG (seeded or `Math.random`) to
128
+ * decide whether to inject a fault. If yes, it picks a fault class and produces
129
+ * a behavior that is observably distinct from every other class:
130
+ *
131
+ * - `'transient'` throws {@link ChaosTransientError} (retryable).
132
+ * - `'error'` throws {@link ChaosNonRetryableError} (non-retryable).
133
+ * - `'timeout'` waits for an `AbortSignal.timeout()` to fire, then throws
134
+ * {@link ChaosTimeoutError}. This actually occupies the async timeline so
135
+ * that engine timeout-handling paths can run.
136
+ * - `'delay'` calls the underlying mock after a short sleep.
137
+ *
138
+ * If no fault fires the underlying `mock` is called normally.
139
+ *
140
+ * @param mock The activity mock implementation to wrap.
141
+ * @param scenario The `ChaosScenario` controlling fault injection.
142
+ * @returns A new function with the same signature that may throw.
143
+ *
144
+ * @example
145
+ * ```ts
146
+ * import { TestEngine, withChaos } from '@lostgradient/weft/testing';
147
+ *
148
+ * const noisySendEmail = withChaos(
149
+ * async (input: unknown) => ({ sent: true }),
150
+ * { faultRate: 0.3, faults: ['transient'], seed: 1 },
151
+ * );
152
+ * const realSendEmail = async (i: unknown) => ({ sent: true });
153
+ * const engine = new TestEngine();
154
+ * engine.mock(realSendEmail, noisySendEmail);
155
+ * ```
156
+ */
157
+ export declare function withChaos<TInput, TOutput>(mock: (input: TInput) => Promise<TOutput> | TOutput, scenario: ChaosScenario): (input: TInput) => Promise<TOutput>;
@@ -0,0 +1,69 @@
1
+ import { timeoutFailureCategoryMarker } from "../core/failure-categories.js";
2
+ import { sleep } from "../runtime/portable.js";
3
+ function makePrng(seed) {
4
+ let s = seed >>> 0;
5
+ return function next() {
6
+ s += 1831565813;
7
+ let z = s;
8
+ z = Math.imul(z ^ z >>> 15, z | 1);
9
+ z ^= z + Math.imul(z ^ z >>> 7, z | 61);
10
+ return ((z ^ z >>> 14) >>> 0) / 4294967296;
11
+ };
12
+ }
13
+
14
+ export class ChaosTransientError extends Error {
15
+ retryable = !0;
16
+ constructor(message = "[chaos] transient fault injected") {
17
+ super(message);
18
+ this.name = "ChaosTransientError";
19
+ }
20
+ }
21
+
22
+ export class ChaosNonRetryableError extends Error {
23
+ retryable = !1;
24
+ constructor(message = "[chaos] non-retryable fault injected") {
25
+ super(message);
26
+ this.name = "ChaosNonRetryableError";
27
+ }
28
+ }
29
+
30
+ export class ChaosTimeoutError extends Error {
31
+ timeoutMilliseconds;
32
+ [timeoutFailureCategoryMarker] = !0;
33
+ constructor(timeoutMilliseconds) {
34
+ super(`[chaos] timeout fault fired after ${timeoutMilliseconds}ms`);
35
+ this.name = "ChaosTimeoutError";
36
+ this.timeoutMilliseconds = timeoutMilliseconds;
37
+ }
38
+ }
39
+ const DELAY_FAULT_MS = 50, TIMEOUT_FAULT_MS = 25;
40
+ async function raiseTimeoutFault(timeoutMilliseconds) {
41
+ const signal = AbortSignal.timeout(timeoutMilliseconds);
42
+ return new Promise((_resolve, reject) => {
43
+ if (signal.aborted) {
44
+ reject(new ChaosTimeoutError(timeoutMilliseconds));
45
+ return;
46
+ }
47
+ signal.addEventListener("abort", () => reject(new ChaosTimeoutError(timeoutMilliseconds)), {
48
+ once: !0
49
+ });
50
+ });
51
+ }
52
+ export function withChaos(mock, scenario) {
53
+ const random = scenario.seed !== void 0 ? makePrng(scenario.seed) : () => Math.random(), enabledFaults = scenario.faults && scenario.faults.length > 0 ? scenario.faults : ["transient", "timeout", "error", "delay"];
54
+ return async function chaosWrapped(input) {
55
+ if (random() < scenario.faultRate)
56
+ switch (enabledFaults[Math.floor(random() * enabledFaults.length)]) {
57
+ case "transient":
58
+ throw new ChaosTransientError;
59
+ case "timeout":
60
+ return raiseTimeoutFault(TIMEOUT_FAULT_MS);
61
+ case "error":
62
+ throw new ChaosNonRetryableError;
63
+ case "delay":
64
+ await sleep(DELAY_FAULT_MS);
65
+ return mock(input);
66
+ }
67
+ return mock(input);
68
+ };
69
+ }
@@ -0,0 +1,4 @@
1
+ /** Let promise continuations and queued microtasks settle without advancing time. */
2
+ export declare function flushPortableMicrotasks(turns?: number): Promise<void>;
3
+ /** Yield one event-loop turn without importing test-runner-only timer APIs. */
4
+ export declare function yieldToPortableEventLoop(): Promise<void>;