@iota-uz/sdk 0.46.0 → 0.47.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 (535) hide show
  1. package/README.md +5 -0
  2. package/dist/client-host/identity.d.ts +4 -4
  3. package/dist/client-host/identity.js +2 -2
  4. package/dist/lens/{CascadePanel-Bha4qY7J.js → CascadePanel-BlYJd18G.js} +1 -1
  5. package/dist/lens/{ChartDataEquivalent-Bwgn4yYB.js → ChartDataEquivalent-B6xSOdzC.js} +1 -1
  6. package/dist/lens/{ChartPanel-BZpzBuwl.js → ChartPanel-BIJjrs5D.js} +159 -159
  7. package/dist/lens/{CoveragePanel-D40AuKkD.js → CoveragePanel-CHtXDMtt.js} +1 -1
  8. package/dist/lens/{GaugePanel-C9k2TuJH.js → GaugePanel-By0TOJPa.js} +1 -1
  9. package/dist/lens/LensDashboard.d.ts +13 -0
  10. package/dist/lens/LensDashboard.d.ts.map +1 -1
  11. package/dist/lens/{MapPanel-ZYxfDsPM.js → MapPanel-Cw4ELCiM.js} +3 -3
  12. package/dist/lens/{MetricFlowPanel-CmESLoLK.js → MetricFlowPanel-Gr5wi3nI.js} +2 -2
  13. package/dist/lens/{MetricHierarchyPanel-UZVuJ5P2.js → MetricHierarchyPanel-VLA_5LXX.js} +2 -2
  14. package/dist/lens/{MetricRelationshipPanel-CXLdScAy.js → MetricRelationshipPanel-DFP566_c.js} +2 -2
  15. package/dist/lens/{PrintReport-lrfdCTZO.js → PrintReport-C0OV1iHP.js} +5 -5
  16. package/dist/lens/{QualityChip-BYz-DHfs.js → QualityChip-DTi-0jdh.js} +1 -1
  17. package/dist/lens/SaveInvestigation-CX1Abyl8.js +309 -0
  18. package/dist/lens/TablePanel-BusKU7cU.js +994 -0
  19. package/dist/lens/{adapter-CeAqYWqm.js → adapter-CQg4-M7p.js} +7 -7
  20. package/dist/lens/contract/schemas.d.ts +2 -0
  21. package/dist/lens/contract/schemas.d.ts.map +1 -1
  22. package/dist/lens/contract/types.d.ts +12 -0
  23. package/dist/lens/contract/types.d.ts.map +1 -1
  24. package/dist/lens/{dashboardEdit-DKVE_6J_.js → dashboardEdit-CJgCVfi_.js} +1 -1
  25. package/dist/lens/explore/DrillOverlay.d.ts +38 -0
  26. package/dist/lens/explore/DrillOverlay.d.ts.map +1 -1
  27. package/dist/lens/explore/ExplorePanel.d.ts.map +1 -1
  28. package/dist/lens/explore/SaveInvestigation.d.ts +21 -0
  29. package/dist/lens/explore/SaveInvestigation.d.ts.map +1 -0
  30. package/dist/lens/explore/drillHost.d.ts +25 -0
  31. package/dist/lens/explore/drillHost.d.ts.map +1 -0
  32. package/dist/lens/explore/investigation.d.ts +174 -0
  33. package/dist/lens/explore/investigation.d.ts.map +1 -0
  34. package/dist/lens/explore/provenanceLabels.d.ts +10 -0
  35. package/dist/lens/explore/provenanceLabels.d.ts.map +1 -0
  36. package/dist/lens/index-DR7Hf8Km.js +19805 -0
  37. package/dist/lens/{index-DkVTXC8W.js → index-DZFw4cqF.js} +1 -1
  38. package/dist/lens/index.d.ts +7 -1
  39. package/dist/lens/index.d.ts.map +1 -1
  40. package/dist/lens/index.js +67 -53
  41. package/dist/lens/{install-CQ_iMuAE.js → install-B2lTK6uo.js} +1 -1
  42. package/dist/lens/{install-Ch0_qifK.js → install-BXr4Mnc0.js} +1 -1
  43. package/dist/lens/{install-CKmxqMe1.js → install-CicNQ_ks.js} +1 -1
  44. package/dist/lens/{install-BwD_xNlp.js → install-d8A0WPiw.js} +1 -1
  45. package/dist/lens/{keys-BBmWdfaH.js → keys-C-Akc9lZ.js} +2 -2
  46. package/dist/lens/panels/ChartPanel.d.ts.map +1 -1
  47. package/dist/lens/panels/TablePanel.d.ts.map +1 -1
  48. package/dist/lens/panels/actions.d.ts.map +1 -1
  49. package/dist/lens/panels/panelFailure.d.ts.map +1 -1
  50. package/dist/lens/{prefetch-BXoUIIgq.js → prefetch-C9kxuIs8.js} +2 -2
  51. package/dist/lens/{prefetchPanels-a-zs_bDm.js → prefetchPanels-gbY9RIqL.js} +1 -1
  52. package/dist/lens/{print-CpgWJxDG.js → print-CllsAP3d.js} +1 -1
  53. package/dist/lens/reports/ReportCompositionEditor.d.ts +8 -2
  54. package/dist/lens/reports/ReportCompositionEditor.d.ts.map +1 -1
  55. package/dist/lens/reports/ReportDefinitionEditor.d.ts +54 -0
  56. package/dist/lens/reports/ReportDefinitionEditor.d.ts.map +1 -0
  57. package/dist/lens/reports/ReportPicker.d.ts +6 -0
  58. package/dist/lens/reports/ReportPicker.d.ts.map +1 -1
  59. package/dist/lens/reports/dashboardEdit.d.ts +3 -0
  60. package/dist/lens/reports/dashboardEdit.d.ts.map +1 -1
  61. package/dist/lens/reports/editing.d.ts +35 -0
  62. package/dist/lens/reports/editing.d.ts.map +1 -1
  63. package/dist/lens/reports/picker.d.ts +4 -1
  64. package/dist/lens/reports/picker.d.ts.map +1 -1
  65. package/dist/lens/runtime/index.d.ts +0 -1
  66. package/dist/lens/runtime/index.d.ts.map +1 -1
  67. package/dist/lens/runtime/messages.d.ts +2 -2
  68. package/dist/lens/runtime/messages.d.ts.map +1 -1
  69. package/dist/lens/runtime/provider.d.ts +5 -1
  70. package/dist/lens/runtime/provider.d.ts.map +1 -1
  71. package/dist/lens/runtime/returnContext.d.ts +62 -0
  72. package/dist/lens/runtime/returnContext.d.ts.map +1 -0
  73. package/dist/lens/runtime/tableSummary.d.ts +9 -0
  74. package/dist/lens/runtime/tableSummary.d.ts.map +1 -0
  75. package/dist/lens/{scales-BLf9OweG.js → scales-CO6Q9RtG.js} +1 -1
  76. package/dist/lens/style.css +1 -1
  77. package/dist/runtime/README.md +24 -0
  78. package/dist/runtime/assert.d.ts +51 -0
  79. package/dist/runtime/assert.js +172 -0
  80. package/dist/runtime/build/README.txt +1 -0
  81. package/dist/runtime/build/extract.mjs +342 -0
  82. package/dist/runtime/build/shared-exports.json +388 -0
  83. package/dist/runtime/build/test-child.mjs +136 -0
  84. package/dist/runtime/build/theme/tailwind.config.js +121 -0
  85. package/dist/runtime/build/theme/theme.css +462 -0
  86. package/dist/runtime/build/theme/utilities.css +1 -0
  87. package/dist/runtime/build/vendor/lib/lib.d.ts +22 -0
  88. package/dist/runtime/build/vendor/lib/lib.decorators.d.ts +384 -0
  89. package/dist/runtime/build/vendor/lib/lib.decorators.legacy.d.ts +22 -0
  90. package/dist/runtime/build/vendor/lib/lib.dom.asynciterable.d.ts +41 -0
  91. package/dist/runtime/build/vendor/lib/lib.dom.d.ts +28983 -0
  92. package/dist/runtime/build/vendor/lib/lib.dom.iterable.d.ts +491 -0
  93. package/dist/runtime/build/vendor/lib/lib.es2015.collection.d.ts +147 -0
  94. package/dist/runtime/build/vendor/lib/lib.es2015.core.d.ts +597 -0
  95. package/dist/runtime/build/vendor/lib/lib.es2015.d.ts +28 -0
  96. package/dist/runtime/build/vendor/lib/lib.es2015.generator.d.ts +77 -0
  97. package/dist/runtime/build/vendor/lib/lib.es2015.iterable.d.ts +590 -0
  98. package/dist/runtime/build/vendor/lib/lib.es2015.promise.d.ts +81 -0
  99. package/dist/runtime/build/vendor/lib/lib.es2015.proxy.d.ts +128 -0
  100. package/dist/runtime/build/vendor/lib/lib.es2015.reflect.d.ts +144 -0
  101. package/dist/runtime/build/vendor/lib/lib.es2015.symbol.d.ts +46 -0
  102. package/dist/runtime/build/vendor/lib/lib.es2015.symbol.wellknown.d.ts +326 -0
  103. package/dist/runtime/build/vendor/lib/lib.es2016.array.include.d.ts +116 -0
  104. package/dist/runtime/build/vendor/lib/lib.es2016.d.ts +21 -0
  105. package/dist/runtime/build/vendor/lib/lib.es2016.full.d.ts +23 -0
  106. package/dist/runtime/build/vendor/lib/lib.es2016.intl.d.ts +31 -0
  107. package/dist/runtime/build/vendor/lib/lib.es2017.arraybuffer.d.ts +21 -0
  108. package/dist/runtime/build/vendor/lib/lib.es2017.d.ts +26 -0
  109. package/dist/runtime/build/vendor/lib/lib.es2017.date.d.ts +31 -0
  110. package/dist/runtime/build/vendor/lib/lib.es2017.full.d.ts +23 -0
  111. package/dist/runtime/build/vendor/lib/lib.es2017.intl.d.ts +44 -0
  112. package/dist/runtime/build/vendor/lib/lib.es2017.object.d.ts +49 -0
  113. package/dist/runtime/build/vendor/lib/lib.es2017.sharedmemory.d.ts +135 -0
  114. package/dist/runtime/build/vendor/lib/lib.es2017.string.d.ts +45 -0
  115. package/dist/runtime/build/vendor/lib/lib.es2017.typedarrays.d.ts +53 -0
  116. package/dist/runtime/build/vendor/lib/lib.es2018.asyncgenerator.d.ts +77 -0
  117. package/dist/runtime/build/vendor/lib/lib.es2018.asynciterable.d.ts +53 -0
  118. package/dist/runtime/build/vendor/lib/lib.es2018.d.ts +24 -0
  119. package/dist/runtime/build/vendor/lib/lib.es2018.full.d.ts +24 -0
  120. package/dist/runtime/build/vendor/lib/lib.es2018.intl.d.ts +83 -0
  121. package/dist/runtime/build/vendor/lib/lib.es2018.promise.d.ts +30 -0
  122. package/dist/runtime/build/vendor/lib/lib.es2018.regexp.d.ts +37 -0
  123. package/dist/runtime/build/vendor/lib/lib.es2019.array.d.ts +79 -0
  124. package/dist/runtime/build/vendor/lib/lib.es2019.d.ts +24 -0
  125. package/dist/runtime/build/vendor/lib/lib.es2019.full.d.ts +24 -0
  126. package/dist/runtime/build/vendor/lib/lib.es2019.intl.d.ts +23 -0
  127. package/dist/runtime/build/vendor/lib/lib.es2019.object.d.ts +33 -0
  128. package/dist/runtime/build/vendor/lib/lib.es2019.string.d.ts +37 -0
  129. package/dist/runtime/build/vendor/lib/lib.es2019.symbol.d.ts +24 -0
  130. package/dist/runtime/build/vendor/lib/lib.es2020.bigint.d.ts +731 -0
  131. package/dist/runtime/build/vendor/lib/lib.es2020.d.ts +27 -0
  132. package/dist/runtime/build/vendor/lib/lib.es2020.date.d.ts +42 -0
  133. package/dist/runtime/build/vendor/lib/lib.es2020.full.d.ts +24 -0
  134. package/dist/runtime/build/vendor/lib/lib.es2020.intl.d.ts +474 -0
  135. package/dist/runtime/build/vendor/lib/lib.es2020.number.d.ts +28 -0
  136. package/dist/runtime/build/vendor/lib/lib.es2020.promise.d.ts +47 -0
  137. package/dist/runtime/build/vendor/lib/lib.es2020.sharedmemory.d.ts +99 -0
  138. package/dist/runtime/build/vendor/lib/lib.es2020.string.d.ts +44 -0
  139. package/dist/runtime/build/vendor/lib/lib.es2020.symbol.wellknown.d.ts +41 -0
  140. package/dist/runtime/build/vendor/lib/lib.es2021.d.ts +23 -0
  141. package/dist/runtime/build/vendor/lib/lib.es2021.full.d.ts +24 -0
  142. package/dist/runtime/build/vendor/lib/lib.es2021.intl.d.ts +166 -0
  143. package/dist/runtime/build/vendor/lib/lib.es2021.promise.d.ts +48 -0
  144. package/dist/runtime/build/vendor/lib/lib.es2021.string.d.ts +33 -0
  145. package/dist/runtime/build/vendor/lib/lib.es2021.weakref.d.ts +78 -0
  146. package/dist/runtime/build/vendor/lib/lib.es2022.array.d.ts +121 -0
  147. package/dist/runtime/build/vendor/lib/lib.es2022.d.ts +25 -0
  148. package/dist/runtime/build/vendor/lib/lib.es2022.error.d.ts +75 -0
  149. package/dist/runtime/build/vendor/lib/lib.es2022.full.d.ts +24 -0
  150. package/dist/runtime/build/vendor/lib/lib.es2022.intl.d.ts +121 -0
  151. package/dist/runtime/build/vendor/lib/lib.es2022.object.d.ts +26 -0
  152. package/dist/runtime/build/vendor/lib/lib.es2022.regexp.d.ts +39 -0
  153. package/dist/runtime/build/vendor/lib/lib.es2022.string.d.ts +25 -0
  154. package/dist/runtime/build/vendor/lib/lib.es2023.array.d.ts +924 -0
  155. package/dist/runtime/build/vendor/lib/lib.es2023.collection.d.ts +21 -0
  156. package/dist/runtime/build/vendor/lib/lib.es2023.d.ts +22 -0
  157. package/dist/runtime/build/vendor/lib/lib.es2023.full.d.ts +24 -0
  158. package/dist/runtime/build/vendor/lib/lib.es2023.intl.d.ts +56 -0
  159. package/dist/runtime/build/vendor/lib/lib.es2024.arraybuffer.d.ts +65 -0
  160. package/dist/runtime/build/vendor/lib/lib.es2024.collection.d.ts +29 -0
  161. package/dist/runtime/build/vendor/lib/lib.es2024.d.ts +26 -0
  162. package/dist/runtime/build/vendor/lib/lib.es2024.full.d.ts +24 -0
  163. package/dist/runtime/build/vendor/lib/lib.es2024.object.d.ts +29 -0
  164. package/dist/runtime/build/vendor/lib/lib.es2024.promise.d.ts +35 -0
  165. package/dist/runtime/build/vendor/lib/lib.es2024.regexp.d.ts +25 -0
  166. package/dist/runtime/build/vendor/lib/lib.es2024.sharedmemory.d.ts +68 -0
  167. package/dist/runtime/build/vendor/lib/lib.es2024.string.d.ts +29 -0
  168. package/dist/runtime/build/vendor/lib/lib.es5.d.ts +4585 -0
  169. package/dist/runtime/build/vendor/lib/lib.es6.d.ts +23 -0
  170. package/dist/runtime/build/vendor/lib/lib.esnext.array.d.ts +35 -0
  171. package/dist/runtime/build/vendor/lib/lib.esnext.collection.d.ts +96 -0
  172. package/dist/runtime/build/vendor/lib/lib.esnext.d.ts +25 -0
  173. package/dist/runtime/build/vendor/lib/lib.esnext.decorators.d.ts +28 -0
  174. package/dist/runtime/build/vendor/lib/lib.esnext.disposable.d.ts +193 -0
  175. package/dist/runtime/build/vendor/lib/lib.esnext.full.d.ts +24 -0
  176. package/dist/runtime/build/vendor/lib/lib.esnext.intl.d.ts +21 -0
  177. package/dist/runtime/build/vendor/lib/lib.esnext.iterator.d.ts +148 -0
  178. package/dist/runtime/build/vendor/node-types/assert/strict.d.ts +111 -0
  179. package/dist/runtime/build/vendor/node-types/assert.d.ts +1115 -0
  180. package/dist/runtime/build/vendor/node-types/async_hooks.d.ts +619 -0
  181. package/dist/runtime/build/vendor/node-types/buffer.buffer.d.ts +477 -0
  182. package/dist/runtime/build/vendor/node-types/buffer.d.ts +1941 -0
  183. package/dist/runtime/build/vendor/node-types/child_process.d.ts +1480 -0
  184. package/dist/runtime/build/vendor/node-types/cluster.d.ts +578 -0
  185. package/dist/runtime/build/vendor/node-types/compatibility/iterators.d.ts +21 -0
  186. package/dist/runtime/build/vendor/node-types/console.d.ts +453 -0
  187. package/dist/runtime/build/vendor/node-types/constants.d.ts +21 -0
  188. package/dist/runtime/build/vendor/node-types/crypto.d.ts +5484 -0
  189. package/dist/runtime/build/vendor/node-types/dgram.d.ts +715 -0
  190. package/dist/runtime/build/vendor/node-types/diagnostics_channel.d.ts +576 -0
  191. package/dist/runtime/build/vendor/node-types/dns/promises.d.ts +503 -0
  192. package/dist/runtime/build/vendor/node-types/dns.d.ts +923 -0
  193. package/dist/runtime/build/vendor/node-types/domain.d.ts +166 -0
  194. package/dist/runtime/build/vendor/node-types/events.d.ts +967 -0
  195. package/dist/runtime/build/vendor/node-types/fs/promises.d.ts +1354 -0
  196. package/dist/runtime/build/vendor/node-types/fs.d.ts +4777 -0
  197. package/dist/runtime/build/vendor/node-types/globals.d.ts +170 -0
  198. package/dist/runtime/build/vendor/node-types/globals.typedarray.d.ts +41 -0
  199. package/dist/runtime/build/vendor/node-types/http.d.ts +2246 -0
  200. package/dist/runtime/build/vendor/node-types/http2.d.ts +2882 -0
  201. package/dist/runtime/build/vendor/node-types/https.d.ts +585 -0
  202. package/dist/runtime/build/vendor/node-types/index.d.ts +101 -0
  203. package/dist/runtime/build/vendor/node-types/inspector.d.ts +323 -0
  204. package/dist/runtime/build/vendor/node-types/inspector.generated.d.ts +4406 -0
  205. package/dist/runtime/build/vendor/node-types/module.d.ts +844 -0
  206. package/dist/runtime/build/vendor/node-types/net.d.ts +1197 -0
  207. package/dist/runtime/build/vendor/node-types/os.d.ts +507 -0
  208. package/dist/runtime/build/vendor/node-types/package.json +140 -0
  209. package/dist/runtime/build/vendor/node-types/path.d.ts +200 -0
  210. package/dist/runtime/build/vendor/node-types/perf_hooks.d.ts +1054 -0
  211. package/dist/runtime/build/vendor/node-types/process.d.ts +2101 -0
  212. package/dist/runtime/build/vendor/node-types/punycode.d.ts +117 -0
  213. package/dist/runtime/build/vendor/node-types/querystring.d.ts +152 -0
  214. package/dist/runtime/build/vendor/node-types/readline/promises.d.ts +161 -0
  215. package/dist/runtime/build/vendor/node-types/readline.d.ts +600 -0
  216. package/dist/runtime/build/vendor/node-types/repl.d.ts +438 -0
  217. package/dist/runtime/build/vendor/node-types/sea.d.ts +162 -0
  218. package/dist/runtime/build/vendor/node-types/sqlite.d.ts +1182 -0
  219. package/dist/runtime/build/vendor/node-types/stream/consumers.d.ts +45 -0
  220. package/dist/runtime/build/vendor/node-types/stream/promises.d.ts +90 -0
  221. package/dist/runtime/build/vendor/node-types/stream/web.d.ts +596 -0
  222. package/dist/runtime/build/vendor/node-types/stream.d.ts +1707 -0
  223. package/dist/runtime/build/vendor/node-types/string_decoder.d.ts +67 -0
  224. package/dist/runtime/build/vendor/node-types/test.d.ts +2656 -0
  225. package/dist/runtime/build/vendor/node-types/timers/promises.d.ts +108 -0
  226. package/dist/runtime/build/vendor/node-types/timers.d.ts +285 -0
  227. package/dist/runtime/build/vendor/node-types/tls.d.ts +1314 -0
  228. package/dist/runtime/build/vendor/node-types/trace_events.d.ts +197 -0
  229. package/dist/runtime/build/vendor/node-types/ts5.6/buffer.buffer.d.ts +473 -0
  230. package/dist/runtime/build/vendor/node-types/ts5.6/compatibility/float16array.d.ts +71 -0
  231. package/dist/runtime/build/vendor/node-types/ts5.6/globals.typedarray.d.ts +36 -0
  232. package/dist/runtime/build/vendor/node-types/ts5.6/index.d.ts +103 -0
  233. package/dist/runtime/build/vendor/node-types/ts5.7/compatibility/float16array.d.ts +72 -0
  234. package/dist/runtime/build/vendor/node-types/ts5.7/index.d.ts +103 -0
  235. package/dist/runtime/build/vendor/node-types/tty.d.ts +209 -0
  236. package/dist/runtime/build/vendor/node-types/url.d.ts +1103 -0
  237. package/dist/runtime/build/vendor/node-types/util.d.ts +2379 -0
  238. package/dist/runtime/build/vendor/node-types/v8.d.ts +1010 -0
  239. package/dist/runtime/build/vendor/node-types/vm.d.ts +1160 -0
  240. package/dist/runtime/build/vendor/node-types/wasi.d.ts +202 -0
  241. package/dist/runtime/build/vendor/node-types/web-globals/abortcontroller.d.ts +34 -0
  242. package/dist/runtime/build/vendor/node-types/web-globals/crypto.d.ts +32 -0
  243. package/dist/runtime/build/vendor/node-types/web-globals/domexception.d.ts +68 -0
  244. package/dist/runtime/build/vendor/node-types/web-globals/events.d.ts +97 -0
  245. package/dist/runtime/build/vendor/node-types/web-globals/fetch.d.ts +62 -0
  246. package/dist/runtime/build/vendor/node-types/web-globals/navigator.d.ts +25 -0
  247. package/dist/runtime/build/vendor/node-types/web-globals/storage.d.ts +24 -0
  248. package/dist/runtime/build/vendor/node-types/web-globals/streams.d.ts +22 -0
  249. package/dist/runtime/build/vendor/node-types/worker_threads.d.ts +894 -0
  250. package/dist/runtime/build/vendor/node-types/zlib.d.ts +768 -0
  251. package/dist/runtime/build/vendor/node_modules/csstype/LICENSE +19 -0
  252. package/dist/runtime/build/vendor/node_modules/csstype/index.d.ts +22569 -0
  253. package/dist/runtime/build/vendor/node_modules/csstype/index.js.flow +6863 -0
  254. package/dist/runtime/build/vendor/node_modules/csstype/package.json +70 -0
  255. package/dist/runtime/build/vendor/node_modules/seroval/LICENSE +7 -0
  256. package/dist/runtime/build/vendor/node_modules/seroval/dist/cjs/development/index.cjs +4232 -0
  257. package/dist/runtime/build/vendor/node_modules/seroval/dist/cjs/production/index.cjs +3 -0
  258. package/dist/runtime/build/vendor/node_modules/seroval/dist/esm/development/index.mjs +4209 -0
  259. package/dist/runtime/build/vendor/node_modules/seroval/dist/esm/production/index.mjs +3 -0
  260. package/dist/runtime/build/vendor/node_modules/seroval/dist/types/core/Serializer.d.ts +28 -0
  261. package/dist/runtime/build/vendor/node_modules/seroval/dist/types/core/base-primitives.d.ts +28 -0
  262. package/dist/runtime/build/vendor/node_modules/seroval/dist/types/core/compat.d.ts +15 -0
  263. package/dist/runtime/build/vendor/node_modules/seroval/dist/types/core/constants.d.ts +105 -0
  264. package/dist/runtime/build/vendor/node_modules/seroval/dist/types/core/constructors.d.ts +50 -0
  265. package/dist/runtime/build/vendor/node_modules/seroval/dist/types/core/context/async-parser.d.ts +20 -0
  266. package/dist/runtime/build/vendor/node_modules/seroval/dist/types/core/context/deserializer.d.ts +52 -0
  267. package/dist/runtime/build/vendor/node_modules/seroval/dist/types/core/context/parser.d.ts +62 -0
  268. package/dist/runtime/build/vendor/node_modules/seroval/dist/types/core/context/serializer.d.ts +103 -0
  269. package/dist/runtime/build/vendor/node_modules/seroval/dist/types/core/context/sync-parser.d.ts +61 -0
  270. package/dist/runtime/build/vendor/node_modules/seroval/dist/types/core/cross/index.d.ts +24 -0
  271. package/dist/runtime/build/vendor/node_modules/seroval/dist/types/core/errors.d.ts +47 -0
  272. package/dist/runtime/build/vendor/node_modules/seroval/dist/types/core/function-string.d.ts +3 -0
  273. package/dist/runtime/build/vendor/node_modules/seroval/dist/types/core/keys.d.ts +4 -0
  274. package/dist/runtime/build/vendor/node_modules/seroval/dist/types/core/literals.d.ts +10 -0
  275. package/dist/runtime/build/vendor/node_modules/seroval/dist/types/core/node.d.ts +8 -0
  276. package/dist/runtime/build/vendor/node_modules/seroval/dist/types/core/opaque-reference.d.ts +9 -0
  277. package/dist/runtime/build/vendor/node_modules/seroval/dist/types/core/plugin.d.ts +52 -0
  278. package/dist/runtime/build/vendor/node_modules/seroval/dist/types/core/reference.d.ts +6 -0
  279. package/dist/runtime/build/vendor/node_modules/seroval/dist/types/core/sequence.d.ts +11 -0
  280. package/dist/runtime/build/vendor/node_modules/seroval/dist/types/core/special-reference.d.ts +16 -0
  281. package/dist/runtime/build/vendor/node_modules/seroval/dist/types/core/stream.d.ts +17 -0
  282. package/dist/runtime/build/vendor/node_modules/seroval/dist/types/core/string.d.ts +4 -0
  283. package/dist/runtime/build/vendor/node_modules/seroval/dist/types/core/symbols.d.ts +14 -0
  284. package/dist/runtime/build/vendor/node_modules/seroval/dist/types/core/tree/index.d.ts +21 -0
  285. package/dist/runtime/build/vendor/node_modules/seroval/dist/types/core/types.d.ts +233 -0
  286. package/dist/runtime/build/vendor/node_modules/seroval/dist/types/core/utils/error.d.ts +6 -0
  287. package/dist/runtime/build/vendor/node_modules/seroval/dist/types/core/utils/get-identifier.d.ts +2 -0
  288. package/dist/runtime/build/vendor/node_modules/seroval/dist/types/core/utils/get-object-flag.d.ts +3 -0
  289. package/dist/runtime/build/vendor/node_modules/seroval/dist/types/core/utils/is-valid-identifier.d.ts +2 -0
  290. package/dist/runtime/build/vendor/node_modules/seroval/dist/types/core/utils/promise-to-result.d.ts +2 -0
  291. package/dist/runtime/build/vendor/node_modules/seroval/dist/types/core/utils/typed-array.d.ts +6 -0
  292. package/dist/runtime/build/vendor/node_modules/seroval/dist/types/core/utils/valid-properties.d.ts +3 -0
  293. package/dist/runtime/build/vendor/node_modules/seroval/dist/types/index.d.ts +18 -0
  294. package/dist/runtime/build/vendor/node_modules/seroval/package.json +67 -0
  295. package/dist/runtime/build/vendor/node_modules/seroval/src/core/Serializer.ts +119 -0
  296. package/dist/runtime/build/vendor/node_modules/seroval/src/core/base-primitives.ts +537 -0
  297. package/dist/runtime/build/vendor/node_modules/seroval/src/core/compat.ts +23 -0
  298. package/dist/runtime/build/vendor/node_modules/seroval/src/core/constants.ts +202 -0
  299. package/dist/runtime/build/vendor/node_modules/seroval/src/core/constructors.ts +265 -0
  300. package/dist/runtime/build/vendor/node_modules/seroval/src/core/context/async-parser.ts +666 -0
  301. package/dist/runtime/build/vendor/node_modules/seroval/src/core/context/deserializer.ts +832 -0
  302. package/dist/runtime/build/vendor/node_modules/seroval/src/core/context/parser.ts +335 -0
  303. package/dist/runtime/build/vendor/node_modules/seroval/src/core/context/serializer.ts +1524 -0
  304. package/dist/runtime/build/vendor/node_modules/seroval/src/core/context/sync-parser.ts +943 -0
  305. package/dist/runtime/build/vendor/node_modules/seroval/src/core/cross/index.ts +190 -0
  306. package/dist/runtime/build/vendor/node_modules/seroval/src/core/errors.ts +196 -0
  307. package/dist/runtime/build/vendor/node_modules/seroval/src/core/function-string.ts +31 -0
  308. package/dist/runtime/build/vendor/node_modules/seroval/src/core/keys.ts +17 -0
  309. package/dist/runtime/build/vendor/node_modules/seroval/src/core/literals.ts +43 -0
  310. package/dist/runtime/build/vendor/node_modules/seroval/src/core/node.ts +40 -0
  311. package/dist/runtime/build/vendor/node_modules/seroval/src/core/opaque-reference.ts +9 -0
  312. package/dist/runtime/build/vendor/node_modules/seroval/src/core/plugin.ts +105 -0
  313. package/dist/runtime/build/vendor/node_modules/seroval/src/core/reference.ts +66 -0
  314. package/dist/runtime/build/vendor/node_modules/seroval/src/core/sequence.ts +59 -0
  315. package/dist/runtime/build/vendor/node_modules/seroval/src/core/special-reference.ts +42 -0
  316. package/dist/runtime/build/vendor/node_modules/seroval/src/core/stream.ts +71 -0
  317. package/dist/runtime/build/vendor/node_modules/seroval/src/core/string.ts +86 -0
  318. package/dist/runtime/build/vendor/node_modules/seroval/src/core/symbols.ts +20 -0
  319. package/dist/runtime/build/vendor/node_modules/seroval/src/core/tree/index.ts +134 -0
  320. package/dist/runtime/build/vendor/node_modules/seroval/src/core/types.ts +377 -0
  321. package/dist/runtime/build/vendor/node_modules/seroval/src/core/utils/error.ts +73 -0
  322. package/dist/runtime/build/vendor/node_modules/seroval/src/core/utils/get-identifier.ts +18 -0
  323. package/dist/runtime/build/vendor/node_modules/seroval/src/core/utils/get-object-flag.ts +14 -0
  324. package/dist/runtime/build/vendor/node_modules/seroval/src/core/utils/is-valid-identifier.ts +12 -0
  325. package/dist/runtime/build/vendor/node_modules/seroval/src/core/utils/promise-to-result.ts +9 -0
  326. package/dist/runtime/build/vendor/node_modules/seroval/src/core/utils/typed-array.ts +56 -0
  327. package/dist/runtime/build/vendor/node_modules/seroval/src/core/utils/valid-properties.ts +34 -0
  328. package/dist/runtime/build/vendor/node_modules/seroval/src/index.ts +36 -0
  329. package/dist/runtime/build/vendor/node_modules/seroval-plugins/LICENSE +7 -0
  330. package/dist/runtime/build/vendor/node_modules/seroval-plugins/dist/cjs/development/web.cjs +826 -0
  331. package/dist/runtime/build/vendor/node_modules/seroval-plugins/dist/cjs/production/web.cjs +1 -0
  332. package/dist/runtime/build/vendor/node_modules/seroval-plugins/dist/esm/development/web.mjs +803 -0
  333. package/dist/runtime/build/vendor/node_modules/seroval-plugins/dist/esm/production/web.mjs +1 -0
  334. package/dist/runtime/build/vendor/node_modules/seroval-plugins/dist/types/web/abort-signal.d.ts +3 -0
  335. package/dist/runtime/build/vendor/node_modules/seroval-plugins/dist/types/web/blob.d.ts +3 -0
  336. package/dist/runtime/build/vendor/node_modules/seroval-plugins/dist/types/web/custom-event.d.ts +3 -0
  337. package/dist/runtime/build/vendor/node_modules/seroval-plugins/dist/types/web/dom-exception.d.ts +3 -0
  338. package/dist/runtime/build/vendor/node_modules/seroval-plugins/dist/types/web/event.d.ts +3 -0
  339. package/dist/runtime/build/vendor/node_modules/seroval-plugins/dist/types/web/file.d.ts +3 -0
  340. package/dist/runtime/build/vendor/node_modules/seroval-plugins/dist/types/web/form-data.d.ts +3 -0
  341. package/dist/runtime/build/vendor/node_modules/seroval-plugins/dist/types/web/headers.d.ts +3 -0
  342. package/dist/runtime/build/vendor/node_modules/seroval-plugins/dist/types/web/image-data.d.ts +3 -0
  343. package/dist/runtime/build/vendor/node_modules/seroval-plugins/dist/types/web/index.d.ts +15 -0
  344. package/dist/runtime/build/vendor/node_modules/seroval-plugins/dist/types/web/readable-stream.d.ts +3 -0
  345. package/dist/runtime/build/vendor/node_modules/seroval-plugins/dist/types/web/request.d.ts +3 -0
  346. package/dist/runtime/build/vendor/node_modules/seroval-plugins/dist/types/web/response.d.ts +3 -0
  347. package/dist/runtime/build/vendor/node_modules/seroval-plugins/dist/types/web/url-search-params.d.ts +3 -0
  348. package/dist/runtime/build/vendor/node_modules/seroval-plugins/dist/types/web/url.d.ts +3 -0
  349. package/dist/runtime/build/vendor/node_modules/seroval-plugins/package.json +70 -0
  350. package/dist/runtime/build/vendor/node_modules/seroval-plugins/web/abort-signal.ts +131 -0
  351. package/dist/runtime/build/vendor/node_modules/seroval-plugins/web/blob.ts +41 -0
  352. package/dist/runtime/build/vendor/node_modules/seroval-plugins/web/custom-event.ts +66 -0
  353. package/dist/runtime/build/vendor/node_modules/seroval-plugins/web/dom-exception.ts +57 -0
  354. package/dist/runtime/build/vendor/node_modules/seroval-plugins/web/event.ts +62 -0
  355. package/dist/runtime/build/vendor/node_modules/seroval-plugins/web/file.ts +50 -0
  356. package/dist/runtime/build/vendor/node_modules/seroval-plugins/web/form-data.ts +105 -0
  357. package/dist/runtime/build/vendor/node_modules/seroval-plugins/web/headers.ts +49 -0
  358. package/dist/runtime/build/vendor/node_modules/seroval-plugins/web/image-data.ts +74 -0
  359. package/dist/runtime/build/vendor/node_modules/seroval-plugins/web/index.ts +14 -0
  360. package/dist/runtime/build/vendor/node_modules/seroval-plugins/web/readable-stream.ts +148 -0
  361. package/dist/runtime/build/vendor/node_modules/seroval-plugins/web/request.ts +82 -0
  362. package/dist/runtime/build/vendor/node_modules/seroval-plugins/web/response.ts +65 -0
  363. package/dist/runtime/build/vendor/node_modules/seroval-plugins/web/url-search-params.ts +40 -0
  364. package/dist/runtime/build/vendor/node_modules/seroval-plugins/web/url.ts +37 -0
  365. package/dist/runtime/build/vendor/node_modules/solid-js/dist/server.cjs +824 -0
  366. package/dist/runtime/build/vendor/node_modules/solid-js/dist/server.js +770 -0
  367. package/dist/runtime/build/vendor/node_modules/solid-js/dist/solid.cjs +1808 -0
  368. package/dist/runtime/build/vendor/node_modules/solid-js/dist/solid.js +1753 -0
  369. package/dist/runtime/build/vendor/node_modules/solid-js/jsx-runtime.d.ts +1 -0
  370. package/dist/runtime/build/vendor/node_modules/solid-js/package.json +243 -0
  371. package/dist/runtime/build/vendor/node_modules/solid-js/store/dist/server.cjs +133 -0
  372. package/dist/runtime/build/vendor/node_modules/solid-js/store/dist/server.js +121 -0
  373. package/dist/runtime/build/vendor/node_modules/solid-js/store/dist/store.cjs +463 -0
  374. package/dist/runtime/build/vendor/node_modules/solid-js/store/dist/store.js +454 -0
  375. package/dist/runtime/build/vendor/node_modules/solid-js/store/package.json +46 -0
  376. package/dist/runtime/build/vendor/node_modules/solid-js/store/types/index.d.ts +12 -0
  377. package/dist/runtime/build/vendor/node_modules/solid-js/store/types/modifiers.d.ts +6 -0
  378. package/dist/runtime/build/vendor/node_modules/solid-js/store/types/mutable.d.ts +5 -0
  379. package/dist/runtime/build/vendor/node_modules/solid-js/store/types/server.d.ts +17 -0
  380. package/dist/runtime/build/vendor/node_modules/solid-js/store/types/store.d.ts +108 -0
  381. package/dist/runtime/build/vendor/node_modules/solid-js/types/index.d.ts +23 -0
  382. package/dist/runtime/build/vendor/node_modules/solid-js/types/jsx.d.ts +4253 -0
  383. package/dist/runtime/build/vendor/node_modules/solid-js/types/reactive/array.d.ts +44 -0
  384. package/dist/runtime/build/vendor/node_modules/solid-js/types/reactive/observable.d.ts +36 -0
  385. package/dist/runtime/build/vendor/node_modules/solid-js/types/reactive/scheduler.d.ts +10 -0
  386. package/dist/runtime/build/vendor/node_modules/solid-js/types/reactive/signal.d.ts +581 -0
  387. package/dist/runtime/build/vendor/node_modules/solid-js/types/render/Suspense.d.ts +26 -0
  388. package/dist/runtime/build/vendor/node_modules/solid-js/types/render/component.d.ts +111 -0
  389. package/dist/runtime/build/vendor/node_modules/solid-js/types/render/flow.d.ts +118 -0
  390. package/dist/runtime/build/vendor/node_modules/solid-js/types/render/hydration.d.ts +24 -0
  391. package/dist/runtime/build/vendor/node_modules/solid-js/types/render/index.d.ts +4 -0
  392. package/dist/runtime/build/vendor/node_modules/solid-js/types/server/index.d.ts +3 -0
  393. package/dist/runtime/build/vendor/node_modules/solid-js/types/server/reactive.d.ts +98 -0
  394. package/dist/runtime/build/vendor/node_modules/solid-js/types/server/rendering.d.ts +160 -0
  395. package/dist/runtime/build/vendor/node_modules/solid-js/web/dist/server.cjs +900 -0
  396. package/dist/runtime/build/vendor/node_modules/solid-js/web/dist/server.js +786 -0
  397. package/dist/runtime/build/vendor/node_modules/solid-js/web/dist/web.cjs +884 -0
  398. package/dist/runtime/build/vendor/node_modules/solid-js/web/dist/web.js +772 -0
  399. package/dist/runtime/build/vendor/node_modules/solid-js/web/package.json +46 -0
  400. package/dist/runtime/build/vendor/node_modules/solid-js/web/storage/dist/storage.cjs +12 -0
  401. package/dist/runtime/build/vendor/node_modules/solid-js/web/storage/dist/storage.js +10 -0
  402. package/dist/runtime/build/vendor/node_modules/solid-js/web/storage/package.json +15 -0
  403. package/dist/runtime/build/vendor/node_modules/solid-js/web/storage/types/index.d.ts +2 -0
  404. package/dist/runtime/build/vendor/node_modules/solid-js/web/types/client.d.ts +93 -0
  405. package/dist/runtime/build/vendor/node_modules/solid-js/web/types/core.d.ts +2 -0
  406. package/dist/runtime/build/vendor/node_modules/solid-js/web/types/index.d.ts +50 -0
  407. package/dist/runtime/build/vendor/node_modules/solid-js/web/types/jsx.d.ts +1 -0
  408. package/dist/runtime/build/vendor/node_modules/solid-js/web/types/server-mock.d.ts +65 -0
  409. package/dist/runtime/build/vendor/node_modules/solid-js/web/types/server.d.ts +187 -0
  410. package/dist/runtime/build/worker.mjs +293415 -0
  411. package/dist/runtime/catalog/sdk-natives.json +655 -0
  412. package/dist/runtime/cli/iota-ext.mjs +1028 -0
  413. package/dist/runtime/client-host/entry.d.ts +10 -0
  414. package/dist/runtime/client-host/entry.js +124 -0
  415. package/dist/runtime/client-host/hooks.d.ts +43 -0
  416. package/dist/runtime/client-host/hooks.js +94 -0
  417. package/dist/runtime/client-host/index.d.ts +9 -0
  418. package/dist/runtime/client-host/index.js +9 -0
  419. package/dist/runtime/client-host/islands.d.ts +44 -0
  420. package/dist/runtime/client-host/islands.js +165 -0
  421. package/dist/runtime/client-host/kit.d.ts +10 -0
  422. package/dist/runtime/client-host/kit.js +37 -0
  423. package/dist/runtime/client-host/page.d.ts +53 -0
  424. package/dist/runtime/client-host/page.js +217 -0
  425. package/dist/runtime/client-host/params.d.ts +8 -0
  426. package/dist/runtime/client-host/params.js +36 -0
  427. package/dist/runtime/client-host/protocol.d.ts +78 -0
  428. package/dist/runtime/client-host/protocol.js +26 -0
  429. package/dist/runtime/client-host/shared.d.ts +12 -0
  430. package/dist/runtime/client-host/shared.js +49 -0
  431. package/dist/runtime/client-host/shell.d.ts +88 -0
  432. package/dist/runtime/client-host/shell.js +195 -0
  433. package/dist/runtime/client-host/slots.d.ts +54 -0
  434. package/dist/runtime/client-host/slots.js +90 -0
  435. package/dist/runtime/client-host/styles.d.ts +7 -0
  436. package/dist/runtime/client-host/styles.js +61 -0
  437. package/dist/runtime/client-host/transport.d.ts +45 -0
  438. package/dist/runtime/client-host/transport.js +115 -0
  439. package/dist/runtime/client.d.ts +226 -0
  440. package/dist/runtime/client.js +121 -0
  441. package/dist/runtime/contracts.d.ts +204 -0
  442. package/dist/runtime/contracts.js +195 -0
  443. package/dist/runtime/docs/authoring.md +1609 -0
  444. package/dist/runtime/docs/example/docs/en/admin/limits.md +10 -0
  445. package/dist/runtime/docs/example/docs/en/getting-started.md +13 -0
  446. package/dist/runtime/docs/example/docs/en/points.md +9 -0
  447. package/dist/runtime/docs/example/docs/ru/getting-started.md +12 -0
  448. package/dist/runtime/docs/example/package.json +27 -0
  449. package/dist/runtime/docs/example/src/ClientScreen.tsx +10 -0
  450. package/dist/runtime/docs/example/src/RedemptionScreen.tsx +7 -0
  451. package/dist/runtime/docs/example/src/RewardsScreen.module.css +13 -0
  452. package/dist/runtime/docs/example/src/RewardsScreen.tsx +51 -0
  453. package/dist/runtime/docs/example/src/client.tsx +40 -0
  454. package/dist/runtime/docs/example/src/contracts.ts +132 -0
  455. package/dist/runtime/docs/example/src/css-modules.d.ts +5 -0
  456. package/dist/runtime/docs/example/src/server.test.ts +156 -0
  457. package/dist/runtime/docs/example/src/server.ts +188 -0
  458. package/dist/runtime/docs/example/tsconfig.json +16 -0
  459. package/dist/runtime/entity.d.ts +237 -0
  460. package/dist/runtime/entity.js +201 -0
  461. package/dist/runtime/fakes.d.ts +80 -0
  462. package/dist/runtime/fakes.js +88 -0
  463. package/dist/runtime/fixtures.d.ts +34 -0
  464. package/dist/runtime/fixtures.js +60 -0
  465. package/dist/runtime/help.d.ts +22 -0
  466. package/dist/runtime/help.js +51 -0
  467. package/dist/runtime/host/context.mjs +392 -0
  468. package/dist/runtime/host/errors.mjs +64 -0
  469. package/dist/runtime/host/loader.mjs +28 -0
  470. package/dist/runtime/host/protocol.mjs +4 -0
  471. package/dist/runtime/host/register.mjs +8 -0
  472. package/dist/runtime/host/sdk/assert.mjs +153 -0
  473. package/dist/runtime/host/sdk/client-host/hooks.mjs +86 -0
  474. package/dist/runtime/host/sdk/client-host/protocol.mjs +30 -0
  475. package/dist/runtime/host/sdk/client-host/slots.mjs +82 -0
  476. package/dist/runtime/host/sdk/client-host/styles.mjs +45 -0
  477. package/dist/runtime/host/sdk/client-host/transport.mjs +102 -0
  478. package/dist/runtime/host/sdk/client.mjs +115 -0
  479. package/dist/runtime/host/sdk/contracts.mjs +185 -0
  480. package/dist/runtime/host/sdk/entity.mjs +183 -0
  481. package/dist/runtime/host/sdk/fakes.mjs +88 -0
  482. package/dist/runtime/host/sdk/fixtures.mjs +56 -0
  483. package/dist/runtime/host/sdk/help.mjs +37 -0
  484. package/dist/runtime/host/sdk/index.mjs +83 -0
  485. package/dist/runtime/host/sdk/kit.mjs +11 -0
  486. package/dist/runtime/host/sdk/manifest.mjs +276 -0
  487. package/dist/runtime/host/sdk/model.mjs +4 -0
  488. package/dist/runtime/host/sdk/resource.mjs +34 -0
  489. package/dist/runtime/host/sdk/schema.mjs +75 -0
  490. package/dist/runtime/host/sdk/server.mjs +43 -0
  491. package/dist/runtime/host/sdk/testhost.mjs +992 -0
  492. package/dist/runtime/host/sdk/testing.mjs +21 -0
  493. package/dist/runtime/host/sdk/wire.mjs +207 -0
  494. package/dist/runtime/host/worker.mjs +252 -0
  495. package/dist/runtime/index.d.ts +10 -0
  496. package/dist/runtime/index.js +5 -0
  497. package/dist/runtime/kit.d.ts +5 -0
  498. package/dist/runtime/kit.js +14 -0
  499. package/dist/runtime/manifest.d.ts +17 -0
  500. package/dist/runtime/manifest.js +323 -0
  501. package/dist/runtime/model.d.ts +224 -0
  502. package/dist/runtime/model.js +3 -0
  503. package/dist/runtime/resource.d.ts +31 -0
  504. package/dist/runtime/resource.js +35 -0
  505. package/dist/runtime/schema.d.ts +97 -0
  506. package/dist/runtime/schema.js +73 -0
  507. package/dist/runtime/server.d.ts +445 -0
  508. package/dist/runtime/server.js +41 -0
  509. package/dist/runtime/testhost.d.ts +216 -0
  510. package/dist/runtime/testhost.js +1146 -0
  511. package/dist/runtime/testing.d.ts +10 -0
  512. package/dist/runtime/testing.js +7 -0
  513. package/dist/runtime/wire.d.ts +26 -0
  514. package/dist/runtime/wire.js +236 -0
  515. package/dist/sdk-identity.cjs +3 -3
  516. package/dist/sdk-identity.js +3 -3
  517. package/dist/sdk-identity.json +2 -2
  518. package/dist/solid-ui/embedded-css.d.ts +2 -0
  519. package/dist/solid-ui/embedded-css.js +1 -0
  520. package/dist/solid-ui/embedded.css +2 -0
  521. package/dist/testing/components.d.ts +73 -0
  522. package/dist/testing/components.js +96 -0
  523. package/dist/testing/htmx.d.ts +44 -0
  524. package/dist/testing/htmx.js +284 -0
  525. package/dist/testing/index.d.ts +4 -41
  526. package/dist/testing/index.js +3 -206
  527. package/dist/testing/scenarios.d.ts +83 -0
  528. package/dist/testing/scenarios.js +74 -0
  529. package/dist/testing/wait.d.ts +7 -0
  530. package/dist/testing/wait.js +19 -0
  531. package/package.json +33 -2
  532. package/dist/lens/TablePanel-C09tzJOL.js +0 -980
  533. package/dist/lens/index-DcVtZneD.js +0 -18473
  534. package/dist/lens/runtime/recovery.d.ts +0 -26
  535. package/dist/lens/runtime/recovery.d.ts.map +0 -1
@@ -0,0 +1,1146 @@
1
+ import { compileFilter } from "./entity.js";
2
+ import { fakeEffects } from "./fakes.js";
3
+ import { EPOCH, OVERLAY_OF } from "./fixtures.js";
4
+ import { decode, encode, validate } from "./wire.js";
5
+ // ---------------------------------------------------------------- errors and registry
6
+ /** Rejections the real host produces (`code` mirrors pkg/extruntime/data and the host worker). */
7
+ export class TestHostError extends Error {
8
+ kind;
9
+ code;
10
+ constructor(code, message) {
11
+ super(message);
12
+ this.name = 'TestHostError';
13
+ this.kind = 'internal';
14
+ this.code = code;
15
+ }
16
+ }
17
+ const fail = (code, message) => {
18
+ throw new TestHostError(code, message);
19
+ };
20
+ /** A task's assignee as the runtime records it: a user as given, a permission as `{ permission: <id> }`. */
21
+ const assigneeOf = (assignee) => {
22
+ const permission = assignee?.permission;
23
+ return typeof permission === 'object' && permission !== null && typeof permission.id === 'string' ? { permission: permission.id } : assignee;
24
+ };
25
+ /** The permission a task is assigned to, if it is assigned by permission. */
26
+ const permissionOf = (assignee) => {
27
+ const permission = assignee?.permission;
28
+ return typeof permission === 'string' ? permission : undefined;
29
+ };
30
+ /** Shared with the build worker's test runner (test-child.ts) through the global symbol registry. */
31
+ function state() {
32
+ const g = globalThis;
33
+ return (g[Symbol.for('iota.testing.state')] ??= { cases: [], http: null });
34
+ }
35
+ let prefix = '';
36
+ /** Registers a test case for the package test runner (`*.test.ts`). */
37
+ export function test(name, fn, options = {}) {
38
+ state().cases.push({ name: prefix + name, fn, ...(options.timeoutMs === undefined ? {} : { timeoutMs: options.timeoutMs }) });
39
+ }
40
+ /** Groups cases: their names are prefixed with the group name. */
41
+ export function describe(name, body) {
42
+ const before = prefix;
43
+ prefix = `${before}${name} > `;
44
+ try {
45
+ body();
46
+ }
47
+ finally {
48
+ prefix = before;
49
+ }
50
+ }
51
+ const POLICY_REASON = /^[a-z0-9_.-]{1,64}$/;
52
+ const VERSION_SEGMENT = /^v[1-9][0-9]*$/;
53
+ /** The notification catalog key of a notice ID, like the platform: snake_case segments and a trailing `.vN`. */
54
+ function noticeKey(id) {
55
+ const snake = (s) => s.replace(/(?<=[^A-Z_])([A-Z])/g, '_$1').toLowerCase();
56
+ const segments = id.split('.').map(snake);
57
+ const last = segments[segments.length - 1] ?? '';
58
+ if (!VERSION_SEGMENT.test(last))
59
+ segments.push('v1');
60
+ return { key: segments.join('.'), version: Number((segments[segments.length - 1] ?? 'v1').slice(1)) };
61
+ }
62
+ const DURATION = /^(\d+)(ms|s|m|h|d)$/;
63
+ const UNIT_MS = { ms: 1, s: 1000, m: 60_000, h: 3_600_000, d: 86_400_000 };
64
+ function durationMs(d) {
65
+ const m = DURATION.exec(d);
66
+ if (m === null)
67
+ return fail('runtime.invalidDuration', `invalid duration "${d}"`);
68
+ return Number(m[1]) * UNIT_MS[m[2]];
69
+ }
70
+ const json = (value) => (value === undefined ? value : JSON.parse(JSON.stringify(value)));
71
+ const isRecord = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
72
+ function cmpDecimal(a, b) {
73
+ const parse = (s) => {
74
+ const neg = s.startsWith('-');
75
+ const [i = '0', f = ''] = (neg ? s.slice(1) : s).split('.');
76
+ return [neg, i.replace(/^0+(?=\d)/, ''), f];
77
+ };
78
+ const [an, ai, af] = parse(a);
79
+ const [bn, bi, bf] = parse(b);
80
+ const scale = Math.max(af.length, bf.length);
81
+ const x = BigInt(ai + af.padEnd(scale, '0')) * (an ? -1n : 1n);
82
+ const y = BigInt(bi + bf.padEnd(scale, '0')) * (bn ? -1n : 1n);
83
+ return x < y ? -1 : x > y ? 1 : 0;
84
+ }
85
+ const order = (x, y) => (x < y ? -1 : x > y ? 1 : 0);
86
+ /** Orders two non-null values of a wire type; refs compare by key. */
87
+ function compare(type, a, b) {
88
+ const key = (v) => (isRecord(v) ? String(v.key) : String(v));
89
+ switch (type?.kind) {
90
+ case 'int':
91
+ return order(Number(a), Number(b));
92
+ case 'int64':
93
+ return order(BigInt(String(a)), BigInt(String(b)));
94
+ case 'decimal':
95
+ return cmpDecimal(String(a), String(b));
96
+ case 'datetime':
97
+ return order(Date.parse(String(a)), Date.parse(String(b)));
98
+ case 'bool':
99
+ return order(Boolean(a), Boolean(b));
100
+ case 'ref':
101
+ return order(key(a), key(b));
102
+ case 'json':
103
+ case 'object':
104
+ case 'array':
105
+ return JSON.stringify(a) === JSON.stringify(b) ? 0 : 1;
106
+ case undefined:
107
+ return typeof a === 'number' && typeof b === 'number' ? order(a, b) : order(key(a), key(b));
108
+ default:
109
+ return order(String(a), String(b));
110
+ }
111
+ }
112
+ const ORDERABLE = new Set(['string', 'int', 'int64', 'decimal', 'date', 'datetime', 'uuid', 'enum']);
113
+ const MAX_PATH = 4;
114
+ const MAX_IN = 1000;
115
+ const DEFAULT_LIMIT = 100;
116
+ const MAX_LIMIT = 1000;
117
+ /** SQL LIKE (`%`, `_`, backslash escape) as a regular expression. */
118
+ function likeToRegExp(pattern) {
119
+ let out = '';
120
+ for (let i = 0; i < pattern.length; i++) {
121
+ const ch = pattern[i] ?? '';
122
+ if (ch === '\\' && i + 1 < pattern.length)
123
+ out += (pattern[++i] ?? '').replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
124
+ else if (ch === '%')
125
+ out += '[\\s\\S]*';
126
+ else if (ch === '_')
127
+ out += '[\\s\\S]';
128
+ else
129
+ out += ch.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
130
+ }
131
+ return new RegExp(`^${out}$`);
132
+ }
133
+ // ---------------------------------------------------------------- storage
134
+ class Store {
135
+ tables = new Map();
136
+ overlays = new Map();
137
+ clone() {
138
+ const c = new Store();
139
+ for (const [id, rows] of this.tables)
140
+ c.tables.set(id, new Map([...rows].map(([k, r]) => [k, structuredClone(r)])));
141
+ for (const [id, rows] of this.overlays)
142
+ c.overlays.set(id, new Map([...rows].map(([k, r]) => [k, structuredClone(r)])));
143
+ return c;
144
+ }
145
+ table(id) {
146
+ let t = this.tables.get(id);
147
+ if (t === undefined)
148
+ this.tables.set(id, (t = new Map()));
149
+ return t;
150
+ }
151
+ overlay(id) {
152
+ let t = this.overlays.get(id);
153
+ if (t === undefined)
154
+ this.overlays.set(id, (t = new Map()));
155
+ return t;
156
+ }
157
+ }
158
+ const isOverlay = (d) => d.kind === 'overlay';
159
+ // ---------------------------------------------------------------- the host
160
+ export function createTestHost(options = {}) {
161
+ const fakes = options.fakes ?? fakeEffects();
162
+ state().http = fakes.http;
163
+ const permissions = new Set(options.user?.permissions ?? []);
164
+ const user = {
165
+ tenantId: 'tenant-test',
166
+ userId: (options.user?.id ?? '1'),
167
+ kind: options.user?.kind ?? 'initiator',
168
+ ...(options.user?.locale === undefined ? {} : { locale: options.user.locale }),
169
+ has: (p) => {
170
+ const id = typeof p === 'string' ? p : p.id;
171
+ return id === '' || permissions.has(id);
172
+ },
173
+ };
174
+ const holds = (userId, permission) => userId === user.userId ? permissions.has(permission) : (options.users?.[userId]?.includes(permission) ?? false);
175
+ let store = new Store();
176
+ const defs = new Map();
177
+ const committed = { emitted: [], notices: [], started: [], signals: [] };
178
+ const deliveries = [];
179
+ const logs = [];
180
+ const impls = new Map();
181
+ const writeRules = new Map();
182
+ const opGuards = new Map();
183
+ const prechecks = new Map();
184
+ const workflowDefs = new Map();
185
+ /** Runs the test drives, by instance, and signals that arrived before a run exists for the instance. */
186
+ const runs = new Map();
187
+ const inboxes = new Map();
188
+ let clockMs = Date.parse(options.now ?? EPOCH);
189
+ let counter = 0;
190
+ const nextId = (p) => `${p}-${++counter}`;
191
+ const nextKey = () => `00000000-0000-4000-8000-${(++counter).toString(16).padStart(12, '0')}`;
192
+ const nowIso = () => new Date(clockMs).toISOString();
193
+ const register = (def) => {
194
+ if (!defs.has(def.id))
195
+ defs.set(def.id, def);
196
+ };
197
+ for (const d of options.entities ?? [])
198
+ register(d);
199
+ const templateSets = new Map();
200
+ for (const item of options.implementations ?? []) {
201
+ if (item.serverKind === 'templates')
202
+ templateSets.set(item.notice.id, item);
203
+ else
204
+ impls.set(item.contract.id, item);
205
+ }
206
+ for (const set of options.templates ?? [])
207
+ templateSets.set(set.notice.id, set);
208
+ const push = (map, id, value) => void map.set(id, [...(map.get(id) ?? []), value]);
209
+ for (const g of options.guards ?? []) {
210
+ if (g.phase === 'write')
211
+ push(writeRules, g.target.id, g);
212
+ else if (g.phase === 'operation')
213
+ push(opGuards, g.target.id, g);
214
+ else
215
+ push(prechecks, g.target.id, g);
216
+ if (g.phase === 'write')
217
+ register(g.target);
218
+ }
219
+ for (const f of options.fixtures ?? []) {
220
+ const overlayId = f[OVERLAY_OF];
221
+ if (typeof overlayId === 'string') {
222
+ const row = f;
223
+ store.overlay(overlayId).set(String(row.baseKey), structuredClone({ ...row }));
224
+ }
225
+ else {
226
+ const fx = f;
227
+ // `ref` is derived on read (like the worker); the table holds the stored columns only.
228
+ const record = structuredClone({ ...fx.record });
229
+ delete record.ref;
230
+ store.table(fx.ref.entity).set(fx.ref.key, record);
231
+ }
232
+ }
233
+ // ---- read model
234
+ // System columns every entity row has (filterable/orderable as in the Go store).
235
+ const SYSTEM_TYPES = { key: { kind: 'string' }, createdAt: { kind: 'datetime' }, updatedAt: { kind: 'datetime' } };
236
+ const typeAt = (def, key) => def?.fields[key]?.type ?? (def !== undefined && def.resource.kind === 'entity' ? SYSTEM_TYPES[key] : undefined);
237
+ const hiddenField = (def, key) => {
238
+ const required = (def?.resource.access?.fields ?? {})[key] ?? [];
239
+ return required.some((p) => !user.has(p));
240
+ };
241
+ const subjectRef = () => ({ entity: 'core.user', key: user.userId });
242
+ /** SQL-style evaluation of a filter against a row of `def`. */
243
+ const matches = (s, def, row, filter, trusted) => {
244
+ for (const [path, cond] of Object.entries(filter.fields ?? {}).sort(([a], [b]) => (a < b ? -1 : 1))) {
245
+ const [value, type] = resolvePath(s, def, row, path, trusted);
246
+ if (!condition(cond, value, type, path))
247
+ return false;
248
+ }
249
+ const alternatives = filter.or ?? [];
250
+ return alternatives.length === 0 || alternatives.some((alt) => matches(s, def, row, alt, trusted));
251
+ };
252
+ const resolvePath = (s, def, row, path, trusted) => {
253
+ const segments = path.split('.');
254
+ if (segments.length > MAX_PATH)
255
+ fail('data.invalidQuery', `path "${path}" is deeper than ${MAX_PATH}`);
256
+ let current = row;
257
+ let currentDef = def;
258
+ for (const seg of segments.slice(0, -1)) {
259
+ const type = typeAt(currentDef, seg);
260
+ if (currentDef !== undefined && type === undefined)
261
+ fail('data.unknownField', `"${seg}" on ${currentDef.id}`);
262
+ if (!trusted && hiddenField(currentDef, seg))
263
+ fail('data.fieldNotAccessible', `"${seg}" on ${currentDef?.id ?? '?'}`);
264
+ if (type !== undefined && type.kind !== 'ref')
265
+ fail('data.invalidQuery', `"${seg}" is not a ref, cannot continue path "${path}"`);
266
+ const target = current === undefined ? undefined : current[seg];
267
+ const targetDef = type?.entity === undefined ? undefined : defs.get(type.entity);
268
+ const next = target?.entity === undefined || target.key === undefined ? undefined : s.table(target.entity).get(target.key);
269
+ // A joined entity is visible only through its own read access.
270
+ current = next !== undefined && targetDef !== undefined && !trusted && !visible(s, targetDef, next) ? undefined : next;
271
+ currentDef = targetDef;
272
+ }
273
+ const last = segments[segments.length - 1] ?? '';
274
+ const type = typeAt(currentDef, last);
275
+ if (currentDef !== undefined && type === undefined)
276
+ fail('data.unknownField', `"${last}" on ${currentDef.id}`);
277
+ if (!trusted && hiddenField(currentDef, last))
278
+ fail('data.fieldNotAccessible', `"${last}" on ${currentDef?.id ?? '?'}`);
279
+ return [current === undefined ? null : (current[last] ?? null), type];
280
+ };
281
+ const resolveValue = (raw) => {
282
+ if (isRecord(raw) && Object.keys(raw).length === 1 && '$' in raw) {
283
+ if (raw.$ !== 'user')
284
+ fail('data.invalidQuery', `unknown placeholder ${JSON.stringify(raw)}`);
285
+ return subjectRef();
286
+ }
287
+ return raw;
288
+ };
289
+ const condition = (c, value, type, field) => {
290
+ const present = value !== null && value !== undefined;
291
+ const checked = (raw) => {
292
+ const v = resolveValue(raw);
293
+ if (v !== null && type !== undefined) {
294
+ try {
295
+ validate({ ...type, optional: undefined, nullable: undefined }, v);
296
+ }
297
+ catch (e) {
298
+ fail('data.invalidQuery', `value for "${field}": ${e.message}`);
299
+ }
300
+ }
301
+ return v;
302
+ };
303
+ const eq = (raw) => {
304
+ const v = checked(raw);
305
+ return present && v !== null && compare(type, value, v) === 0;
306
+ };
307
+ const parts = [];
308
+ if (c.eq !== undefined)
309
+ parts.push(c.eq === null ? !present : eq(c.eq));
310
+ if (c.ne !== undefined)
311
+ parts.push(c.ne === null ? present : !present || !eq(c.ne));
312
+ if (c.in !== undefined) {
313
+ if (c.in.length > MAX_IN)
314
+ fail('data.invalidQuery', `"${field}": in-list longer than ${MAX_IN}`);
315
+ parts.push(c.in.length === 0 ? false : c.in.map(checked).some((v) => present && v !== null && compare(type, value, v) === 0));
316
+ }
317
+ for (const [op, raw] of [['lt', c.lt], ['lte', c.lte], ['gt', c.gt], ['gte', c.gte]]) {
318
+ if (raw === undefined)
319
+ continue;
320
+ if (type !== undefined && !ORDERABLE.has(type.kind))
321
+ fail('data.invalidQuery', `"${field}" (${type.kind}) cannot be compared with ${op}`);
322
+ const v = checked(raw);
323
+ const d = present && v !== null ? compare(type, value, v) : undefined;
324
+ parts.push(d !== undefined && (op === 'lt' ? d < 0 : op === 'lte' ? d <= 0 : op === 'gt' ? d > 0 : d >= 0));
325
+ }
326
+ if (c.isNull !== undefined)
327
+ parts.push(c.isNull ? !present : present);
328
+ if (c.like !== undefined) {
329
+ if (type !== undefined && type.kind !== 'string' && type.kind !== 'enum')
330
+ fail('data.invalidQuery', `"${field}" (${type.kind}) does not support like`);
331
+ parts.push(present && likeToRegExp(c.like).test(String(value)));
332
+ }
333
+ if (parts.length === 0)
334
+ fail('data.invalidQuery', `empty condition for "${field}"`);
335
+ return parts.every(Boolean);
336
+ };
337
+ /** Row visibility of an entity for the subject: the OR of the applicable read rules. */
338
+ const visible = (s, def, row) => {
339
+ const rules = def.resource.access?.read ?? [];
340
+ if (rules.length === 0)
341
+ return true;
342
+ for (const rule of rules) {
343
+ if (!user.has(rule.permission ?? ''))
344
+ continue;
345
+ if (rule.all === true)
346
+ return true;
347
+ if (rule.rows !== undefined && matches(s, def, row, rule.rows, true))
348
+ return true;
349
+ }
350
+ return false;
351
+ };
352
+ /** Entity rows carry a typed `ref` to themselves (`Row<E>.ref`); overlay rows (keyed by `baseKey`) have none. */
353
+ const withRef = (def, row) => (isOverlay(def) ? row : { ...row, ref: { entity: def.id, key: String(row.key) } });
354
+ const project = (def, row) => {
355
+ const out = {};
356
+ for (const [k, v] of Object.entries(row))
357
+ if (!(k in def.fields) || !hiddenField(def, k))
358
+ out[k] = structuredClone(v);
359
+ return withRef(def, out);
360
+ };
361
+ const makeReader = (s) => {
362
+ /** Visible rows matching the filter, before ordering and paging. */
363
+ const matching = (entity, where) => {
364
+ register(entity);
365
+ const st = s();
366
+ const filter = where === undefined ? {} : compileFilter(where);
367
+ return [...st.table(entity.id).values()].filter((r) => visible(st, entity, r)).filter((r) => matches(st, entity, r, filter, false));
368
+ };
369
+ const find = (entity, q = {}) => {
370
+ const st = s();
371
+ const limit = q.limit ?? 0;
372
+ const offset = q.offset ?? 0;
373
+ if (limit < 0 || offset < 0)
374
+ fail('data.invalidQuery', 'limit and offset must not be negative');
375
+ let rows = matching(entity, q.where);
376
+ const orders = (q.orderBy ?? []).map((o) => ({ field: o.field, desc: o.desc === true }));
377
+ for (const o of orders) {
378
+ const sample = rows[0];
379
+ const [, type] = sample === undefined ? [null, typeAt(entity, o.field.split('.')[0] ?? '')] : resolvePath(st, entity, sample, o.field, false);
380
+ if (type !== undefined && !ORDERABLE.has(type.kind) && type.kind !== 'ref' && type.kind !== 'bool')
381
+ fail('data.invalidQuery', `"${o.field}" (${type.kind}) cannot be ordered`);
382
+ }
383
+ const keyed = rows.map((r) => ({ r, vals: orders.map((o) => resolvePath(st, entity, r, o.field, false)) }));
384
+ keyed.sort((a, b) => {
385
+ for (const [i, o] of orders.entries()) {
386
+ const [av, type] = a.vals[i] ?? [null, undefined];
387
+ const [bv] = b.vals[i] ?? [null, undefined];
388
+ // PostgreSQL: NULLS LAST ascending, NULLS FIRST descending.
389
+ const an = av === null || av === undefined;
390
+ const bn = bv === null || bv === undefined;
391
+ const d = an && bn ? 0 : an ? 1 : bn ? -1 : compare(type, av, bv);
392
+ if (d !== 0)
393
+ return o.desc ? -d : d;
394
+ }
395
+ return order(String(a.r.key), String(b.r.key));
396
+ });
397
+ rows = keyed.map((k) => k.r);
398
+ return rows.slice(offset, offset + Math.min(limit === 0 ? DEFAULT_LIMIT : limit, MAX_LIMIT)).map((r) => project(entity, r));
399
+ };
400
+ const get = (def, ref) => {
401
+ register(def);
402
+ const st = s();
403
+ if (isOverlay(def)) {
404
+ // An overlay row is readable only together with its base row (the Go store joins the base under its read rules).
405
+ const row = st.overlay(def.id).get(ref.key);
406
+ const base = st.tables.get(def.base.id)?.get(ref.key);
407
+ if (row === undefined || (base !== undefined && !visible(st, defs.get(def.base.id) ?? def.base, base)))
408
+ return null;
409
+ return project(def, row);
410
+ }
411
+ if (ref.entity !== def.id)
412
+ fail('data.invalidRef', `ref to "${ref.entity}" used with entity "${def.id}"`);
413
+ const row = st.table(def.id).get(ref.key);
414
+ return row === undefined || !visible(st, def, row) ? null : project(def, row);
415
+ };
416
+ const count = (entity, where) => matching(entity, where).length;
417
+ return {
418
+ get: (async (def, ref) => get(def, ref)),
419
+ find: (async (entity, q) => {
420
+ return find(entity, q);
421
+ }),
422
+ count: (async (entity, where) => count(entity, where)),
423
+ };
424
+ };
425
+ // ---- contexts
426
+ const logger = () => {
427
+ const at = (level) => (message, fields) => void logs.push({ level, message: fields === undefined ? message : `${message} ${JSON.stringify(fields)}` });
428
+ return { debug: at('debug'), info: at('info'), warn: at('warn'), error: at('error') };
429
+ };
430
+ const invocation = (parentId) => ({
431
+ id: nextId('inv'),
432
+ trigger: options.trigger ?? 'ui',
433
+ ...(parentId === undefined ? {} : { parentId }),
434
+ });
435
+ const secrets = {
436
+ get: async (name) => options.secrets?.[name] ?? fail('runtime.secretUndeclared', `secret "${name}" is not provided to this test host`),
437
+ };
438
+ /**
439
+ * Read-only data access over `s()` plus `query`, which runs a bound query on the store the call sees (the
440
+ * transaction's working state inside a transaction, the committed state it started from otherwise).
441
+ * `open` rejects use after the owning transaction ended.
442
+ */
443
+ const readContext = (s, info, open = () => undefined) => {
444
+ const reader = makeReader(s);
445
+ return {
446
+ user,
447
+ invocation: info,
448
+ log: logger(),
449
+ get: (async (...a) => (open(), reader.get(...a))),
450
+ find: (async (...a) => (open(), reader.find(...a))),
451
+ count: (async (...a) => (open(), reader.count(...a))),
452
+ query: (async (q, input) => {
453
+ open();
454
+ return runQuery(s(), q, input, info.id);
455
+ }),
456
+ };
457
+ };
458
+ /** Context of precheck / guard / write-rule handlers: reads, identity and log. It has no write members. */
459
+ const guardContext = (ctx) => Object.freeze({ user: ctx.user, invocation: ctx.invocation, log: ctx.log, get: ctx.get, find: ctx.find, count: ctx.count, query: ctx.query });
460
+ /** Runs a bound query against `snapshot` with the caller's rights. */
461
+ const runQuery = async (snapshot, q, input, parent) => {
462
+ if (q.kind !== 'query')
463
+ return fail('runtime.invalidInput', `"${q.id}" is a ${q.kind}, not a query`);
464
+ const valid = validateInput(q, input);
465
+ const handler = implementationOf(q.id).handler;
466
+ const out = await handler(readContext(() => snapshot, invocation(parent)), valid);
467
+ return decode(q.output, encode(q.output, out));
468
+ };
469
+ // ---- signals
470
+ /** Validates a signal to a started instance (or a run) and returns what is delivered. */
471
+ const checkSignal = (target, name, payload, starting) => {
472
+ const run = runs.get(target.instance);
473
+ const workflowId = run?.workflow.id ?? [...committed.started, ...starting].find((x) => x.instance === target.instance)?.workflow;
474
+ if (workflowId === undefined || workflowId !== target.workflow) {
475
+ return fail('workflow.unknownInstance', `no started instance "${target.instance}" of workflow "${target.workflow}"`);
476
+ }
477
+ const schema = (run?.workflow ?? workflowDefs.get(workflowId))?.signals[name]?.schema;
478
+ if (schema === undefined)
479
+ return fail('workflow.unknownSignal', `workflow "${workflowId}" declares no signal "${name}"`);
480
+ try {
481
+ return { workflow: workflowId, instance: target.instance, name, payload: json(encode(schema, payload)) };
482
+ }
483
+ catch (e) {
484
+ return fail('workflow.invalidSignal', `signal "${name}" of "${workflowId}": ${e.message}`);
485
+ }
486
+ };
487
+ const deliverSignal = (signal) => {
488
+ committed.signals.push(signal);
489
+ const run = runs.get(signal.instance);
490
+ if (run !== undefined)
491
+ run.push(signal.name, signal.payload);
492
+ else
493
+ inboxes.set(signal.instance, [...(inboxes.get(signal.instance) ?? []), { name: signal.name, payload: signal.payload }]);
494
+ };
495
+ const validateInput = (c, input) => {
496
+ try {
497
+ return decode(c.input, encode(c.input, input));
498
+ }
499
+ catch (e) {
500
+ return fail('runtime.invalidInput', `${c.id}: ${e.message}`);
501
+ }
502
+ };
503
+ const implementationOf = (id) => {
504
+ const impl = impls.get(id);
505
+ if (impl === undefined)
506
+ return fail('test.noImplementation', `no implementation of "${id}" is bound in this test host; pass it in createTestHost({ implementations })`);
507
+ return impl;
508
+ };
509
+ /** Entity write rules run in the writing transaction, before the row is written, with a read-only context. */
510
+ const writeRuleHooks = async (tx, def, op, existing, proposed) => {
511
+ const rules = writeRules.get(def.id) ?? [];
512
+ if (rules.length === 0)
513
+ return;
514
+ const changed = Object.keys(def.fields).filter((k) => JSON.stringify(existing?.[k] ?? null) !== JSON.stringify(proposed?.[k] ?? null));
515
+ const change = {
516
+ op,
517
+ existing: existing === null ? null : withRef(def, structuredClone(existing)),
518
+ proposed: proposed === null ? null : withRef(def, structuredClone(proposed)),
519
+ changed,
520
+ };
521
+ for (const rule of rules)
522
+ await rule.handler(guardContext(tx), change);
523
+ };
524
+ /** Runs an operation / atomic command in the caller's transaction, guards first (read-only context). */
525
+ const callCallable = async (tx, callable, input) => {
526
+ const valid = validateInput(callable, input);
527
+ for (const g of opGuards.get(callable.id) ?? [])
528
+ await g.handler(guardContext(tx), valid);
529
+ const out = await implementationOf(callable.id).handler(tx, valid);
530
+ return callable.output === undefined ? undefined : decode(callable.output, encode(callable.output, out));
531
+ };
532
+ const makeTx = (scope) => {
533
+ const guard = () => {
534
+ if (!scope.open)
535
+ fail('runtime.txClosed', 'transaction is closed');
536
+ };
537
+ const reads = readContext(() => scope.store, scope.info, guard);
538
+ const own = (def, op) => {
539
+ register(def);
540
+ if (def.entityKind === 'native')
541
+ fail('data.nativeWrite', `${op} on native entity "${def.id}": native entities are read-only through generic data calls`);
542
+ };
543
+ // Field access is symmetric (pkg/extruntime/data): a field the subject cannot read cannot be written by it.
544
+ const writable = (def, values) => {
545
+ for (const k of Object.keys(values)) {
546
+ if (values[k] !== undefined && hiddenField(def, k))
547
+ fail('data.fieldNotAccessible', `"${k}" on ${def.id}`);
548
+ }
549
+ };
550
+ const checkUnique = (def, row, exceptKey) => {
551
+ for (const [k, f] of Object.entries(def.fields)) {
552
+ if (f.spec.unique !== true || row[k] === null || row[k] === undefined)
553
+ continue;
554
+ for (const other of scope.store.table(def.id).values()) {
555
+ if (other.key !== exceptKey && JSON.stringify(other[k]) === JSON.stringify(row[k]))
556
+ fail('data.unique', `field "${k}" already holds this value`);
557
+ }
558
+ }
559
+ };
560
+ const shapeOf = (def, keys) => {
561
+ const properties = keys.map((k) => {
562
+ const f = def.fields[k];
563
+ if (f === undefined)
564
+ return fail('data.unknownField', `"${k}" on ${def.id}`);
565
+ return { name: k, type: f.type };
566
+ });
567
+ return { type: { kind: 'object', properties } };
568
+ };
569
+ const tx = {
570
+ ...reads,
571
+ insert: async (def, values) => {
572
+ guard();
573
+ own(def, 'insert');
574
+ writable(def, values);
575
+ const row = {};
576
+ for (const [k, f] of Object.entries(def.fields))
577
+ row[k] = values[k] !== undefined ? values[k] : (f.spec.default ?? null);
578
+ for (const k of Object.keys(values))
579
+ if (!(k in def.fields))
580
+ fail('data.unknownField', `"${k}" on ${def.id}`);
581
+ try {
582
+ encode(shapeOf(def, Object.keys(def.fields)), row);
583
+ }
584
+ catch (e) {
585
+ fail('data.invalidValue', e.message);
586
+ }
587
+ checkUnique(def, row, undefined);
588
+ const full = { key: nextKey(), createdAt: nowIso(), updatedAt: nowIso(), rowVersion: 1, ...structuredClone(row) };
589
+ await writeRuleHooks(tx, def, 'insert', null, full);
590
+ scope.store.table(def.id).set(String(full.key), full);
591
+ return project(def, full);
592
+ },
593
+ update: async (def, ref, patch, opts) => {
594
+ guard();
595
+ own(def, 'update');
596
+ writable(def, patch);
597
+ const existing = scope.store.table(def.id).get(ref.key);
598
+ if (existing === undefined || !visible(scope.store, def, existing))
599
+ return fail('data.notFound', `${def.id} ${ref.key}`);
600
+ if (opts?.rowVersion !== undefined && opts.rowVersion !== existing.rowVersion) {
601
+ fail('data.versionConflict', `${def.id} ${ref.key} is at version ${String(existing.rowVersion)}, expected ${opts.rowVersion}`);
602
+ }
603
+ const keys = Object.keys(patch).filter((k) => patch[k] !== undefined);
604
+ try {
605
+ encode(shapeOf(def, keys), Object.fromEntries(keys.map((k) => [k, patch[k]])));
606
+ }
607
+ catch (e) {
608
+ fail('data.invalidValue', e.message);
609
+ }
610
+ const next = { ...structuredClone(existing), ...structuredClone(Object.fromEntries(keys.map((k) => [k, patch[k]]))) };
611
+ checkUnique(def, next, ref.key);
612
+ next.updatedAt = nowIso();
613
+ next.rowVersion = Number(existing.rowVersion) + 1;
614
+ await writeRuleHooks(tx, def, 'update', existing, next);
615
+ scope.store.table(def.id).set(ref.key, next);
616
+ return project(def, next);
617
+ },
618
+ delete: async (def, ref) => {
619
+ guard();
620
+ own(def, 'delete');
621
+ const existing = scope.store.table(def.id).get(ref.key);
622
+ if (existing === undefined || !visible(scope.store, def, existing))
623
+ return fail('data.notFound', `${def.id} ${ref.key}`);
624
+ await writeRuleHooks(tx, def, 'delete', existing, null);
625
+ scope.store.table(def.id).delete(ref.key);
626
+ },
627
+ put: async (overlay, base, values) => {
628
+ guard();
629
+ register(overlay);
630
+ writable(overlay, values);
631
+ const baseTable = scope.store.tables.get(overlay.base.id);
632
+ if (baseTable !== undefined && !baseTable.has(base.key))
633
+ fail('data.notFound', `${overlay.base.id} ${base.key}`);
634
+ const keys = Object.keys(values).filter((k) => values[k] !== undefined);
635
+ try {
636
+ encode(shapeOf(overlay, keys), Object.fromEntries(keys.map((k) => [k, values[k]])));
637
+ }
638
+ catch (e) {
639
+ fail('data.invalidValue', e.message);
640
+ }
641
+ const existing = scope.store.overlay(overlay.id).get(base.key);
642
+ const row = existing === undefined ? { baseKey: base.key } : structuredClone(existing);
643
+ for (const [k, f] of Object.entries(overlay.fields)) {
644
+ if (values[k] !== undefined)
645
+ row[k] = structuredClone(values[k]);
646
+ else if (!(k in row))
647
+ row[k] = f.spec.default ?? null;
648
+ }
649
+ scope.store.overlay(overlay.id).set(base.key, row);
650
+ return project(overlay, row);
651
+ },
652
+ call: async (callable, input) => {
653
+ guard();
654
+ const c = callable;
655
+ if (!(c.kind === 'operation' || (c.kind === 'command' && c.atomic === true))) {
656
+ fail('runtime.ordinaryCommandInTx', `tx.call accepts only operations and atomic commands, not ${c.kind === 'command' ? 'ordinary command ' : c.kind + ' '}"${c.id}"`);
657
+ }
658
+ return callCallable(tx, callable, input);
659
+ },
660
+ emit: async (event, args) => {
661
+ guard();
662
+ if (event.subject !== undefined && args.subject?.entity !== event.subject.id)
663
+ fail('runtime.invalidInput', `event "${event.id}" needs a subject of "${event.subject.id}"`);
664
+ scope.pending.emitted.push({ event: event.id, subject: args.subject, payload: encode(event.payload, args.payload), initiator: user.userId });
665
+ },
666
+ notify: async (notice, args) => {
667
+ guard();
668
+ if (notice.subject !== undefined && args.subject?.entity !== notice.subject.id)
669
+ fail('runtime.invalidInput', `notice "${notice.id}" needs a subject of "${notice.subject.id}"`);
670
+ if (args.to.length === 0 || args.channels.length === 0)
671
+ fail('runtime.invalidInput', `notice "${notice.id}" needs recipients and channels`);
672
+ if (templateSets.size > 0 && !templateSets.has(notice.id)) {
673
+ fail('notify.noTemplates', `no templates(...) for notice "${notice.id}" are bound in this test host; pass them in createTestHost({ templates })`);
674
+ }
675
+ const sent = { notice: notice.id, subject: args.subject, payload: encode(notice.payload, args.payload), to: json(args.to), channels: [...args.channels] };
676
+ scope.pending.notices.push({ sent, schema: notice.payload, seq: nextId('ntc') });
677
+ },
678
+ start: async (wf, input, opts) => {
679
+ guard();
680
+ if (!scope.derived && opts?.key === undefined)
681
+ fail('runtime.startKeyRequired', `tx.start("${wf.id}") needs { key } outside subscriptions and workflows`);
682
+ const known = opts?.key === undefined ? undefined : [...committed.started, ...scope.pending.started].find((x) => x.workflow === wf.id && x.key === opts.key);
683
+ if (known !== undefined)
684
+ return { workflow: wf.id, instance: known.instance };
685
+ const instance = nextId('wf');
686
+ scope.pending.started.push({ workflow: wf.id, instance, key: opts?.key, input: encode(wf.input, validateInput(wf, input)) });
687
+ workflowDefs.set(wf.id, wf);
688
+ return { workflow: wf.id, instance };
689
+ },
690
+ signal: async (target, name, payload) => {
691
+ guard();
692
+ scope.pending.signals.push(checkSignal(target, name, payload, scope.pending.started));
693
+ },
694
+ };
695
+ return tx;
696
+ };
697
+ // ---- notice delivery (after commit, like the runtime: rendering and providers never roll a transaction back)
698
+ const channelTargets = async (recipient, channel, locale) => {
699
+ if (recipient.kind === 'address') {
700
+ const address = recipient.address[channel];
701
+ return address === undefined || address === '' ? { targets: [], reason: `the address has no ${channel} entry` } : { targets: [address] };
702
+ }
703
+ if (recipient.kind === 'user') {
704
+ const key = recipient.user.key;
705
+ const row = store.table('core.user').get(key);
706
+ if (row === undefined) {
707
+ return { targets: [], reason: `no core.user fixture with key "${key}": add fixture(core.User, { ... }, { key: "${key}" }) to createTestHost({ fixtures })` };
708
+ }
709
+ if (typeof row.uiLanguage === 'string' && row.uiLanguage !== '')
710
+ locale.value = row.uiLanguage;
711
+ const value = channel === 'sms' ? row.phone : channel === 'email' ? row.email : key;
712
+ return typeof value === 'string' && value !== '' ? { targets: [value] } : { targets: [], reason: `the core.user fixture "${key}" has no ${channel === 'sms' ? 'phone' : 'email'}` };
713
+ }
714
+ if (channel === 'inApp')
715
+ return { targets: [], reason: 'inApp notifications address ERP users, not records' };
716
+ const record = recipient.record;
717
+ let found = options.contacts === undefined ? undefined : await options.contacts(record);
718
+ if (found === undefined) {
719
+ const resolver = [...impls.values()].find((i) => i.contract.kind === 'contactResolver' && i.contract.entity.id === record.entity);
720
+ if (resolver === undefined) {
721
+ return { targets: [], reason: `no contact data for ${record.entity}: pass createTestHost({ contacts }) or bind its contactResolver in implementations` };
722
+ }
723
+ found = await resolver.handler(queryContext(), record);
724
+ }
725
+ const list = found[channel] ?? [];
726
+ return list.length > 0 ? { targets: [...list] } : { targets: [], reason: `the contact data of ${record.entity} "${record.key}" has no ${channel} target` };
727
+ };
728
+ /** The platform's composite policy for one target: bound `deliveryPolicy` implementations of the record's entity, first denial wins. */
729
+ const evaluatePolicies = async (sent, recipient, channel, address) => {
730
+ if (recipient.kind !== 'record')
731
+ return { allow: true };
732
+ const bound = [...impls.values()]
733
+ .filter((i) => i.contract.kind === 'deliveryPolicy' && i.contract.entity.id === recipient.record.entity)
734
+ .sort((a, b) => (a.contract.id < b.contract.id ? -1 : a.contract.id > b.contract.id ? 1 : 0));
735
+ if (bound.length === 0)
736
+ return { allow: true };
737
+ const { key, version } = noticeKey(sent.notice);
738
+ const owner = sent.notice.split('.').slice(0, 2).join('.');
739
+ const request = {
740
+ notice: { key, version, snapshot: options.snapshot ?? `${owner}@0.0.0` },
741
+ subject: sent.subject === undefined ? null : { entity: sent.subject.entity, key: sent.subject.key },
742
+ recipient: { kind: 'record', ref: recipient.record, address: null },
743
+ channel,
744
+ target: { address, deviceId: null },
745
+ };
746
+ for (const impl of bound) {
747
+ let decision;
748
+ try {
749
+ decision = await impl.handler(queryContext(), json(request));
750
+ }
751
+ catch (e) {
752
+ return { allow: false, failed: true, reason: `delivery policy ${impl.contract.id} failed: ${e instanceof Error ? e.message : String(e)}` };
753
+ }
754
+ const verdict = decision;
755
+ if (typeof verdict !== 'object' || verdict === null || typeof verdict.allow !== 'boolean') {
756
+ return { allow: false, failed: true, reason: `delivery policy ${impl.contract.id} must return {allow: boolean, reason?: string}` };
757
+ }
758
+ if (!verdict.allow) {
759
+ const reason = typeof verdict.reason === 'string' && POLICY_REASON.test(verdict.reason) ? verdict.reason : '';
760
+ return { allow: false, failed: false, reason: reason === '' ? 'policy_denied' : `policy_denied:${reason}` };
761
+ }
762
+ }
763
+ return { allow: true };
764
+ };
765
+ const deliverNotice = async ({ sent, schema, seq }) => {
766
+ const set = templateSets.get(sent.notice);
767
+ const renderers = (set?.renderers ?? {});
768
+ for (const raw of sent.to) {
769
+ const recipient = raw;
770
+ for (const channel of sent.channels) {
771
+ const record = (partial) => void deliveries.push({ notice: sent.notice, channel, recipient, ...partial });
772
+ const locale = { value: user.locale ?? 'en' };
773
+ const resolved = await channelTargets(recipient, channel, locale);
774
+ if (resolved.targets.length === 0) {
775
+ record({ target: undefined, status: 'skipped', reason: resolved.reason ?? 'no target' });
776
+ continue;
777
+ }
778
+ const render = renderers[channel];
779
+ for (const target of resolved.targets) {
780
+ if (render === undefined) {
781
+ record({ target, status: 'skipped', reason: `the templates of ${sent.notice} have no ${channel} renderer` });
782
+ continue;
783
+ }
784
+ if (channel !== 'inApp') {
785
+ const verdict = await evaluatePolicies(sent, recipient, channel, target);
786
+ if (!verdict.allow) {
787
+ record({ target, status: verdict.failed ? 'failed' : 'skipped', reason: verdict.reason });
788
+ continue;
789
+ }
790
+ }
791
+ let content;
792
+ const idempotencyKey = `${seq}:${channel}:${target}`;
793
+ try {
794
+ const rendered = await render({ payload: decode(schema, sent.payload), subject: sent.subject, locale: locale.value });
795
+ content = json(rendered);
796
+ if (channel === 'sms')
797
+ await fakes.sms.send({ to: target, text: String(rendered), idempotencyKey });
798
+ else if (channel === 'email')
799
+ await fakes.email.send({ to: target, ...rendered, idempotencyKey });
800
+ else if (channel === 'push')
801
+ await fakes.push.send({ to: target, ...rendered, idempotencyKey });
802
+ else
803
+ await fakes.inApp.send({ to: target, ...rendered, idempotencyKey });
804
+ }
805
+ catch (e) {
806
+ record({ target, status: 'failed', reason: e instanceof Error ? e.message : String(e) });
807
+ continue;
808
+ }
809
+ record({ target, status: 'delivered', content });
810
+ }
811
+ }
812
+ }
813
+ };
814
+ const flush = async (pending) => {
815
+ committed.emitted.push(...pending.emitted);
816
+ committed.notices.push(...pending.notices.map((n) => n.sent));
817
+ committed.started.push(...pending.started);
818
+ for (const signal of pending.signals)
819
+ deliverSignal(signal);
820
+ if (templateSets.size > 0)
821
+ for (const n of pending.notices)
822
+ await deliverNotice(n);
823
+ };
824
+ /** Runs `body` in a transaction on a working copy: adopted on success, discarded on throw. */
825
+ const inTransaction = async (body, derived, info = invocation()) => {
826
+ const scope = { store: store.clone(), pending: { emitted: [], notices: [], started: [], signals: [] }, open: true, derived, info };
827
+ const tx = makeTx(scope);
828
+ try {
829
+ const result = await body(tx);
830
+ scope.open = false;
831
+ store = scope.store;
832
+ await flush(scope.pending);
833
+ return result;
834
+ }
835
+ catch (e) {
836
+ scope.open = false;
837
+ throw e;
838
+ }
839
+ };
840
+ const queryContext = (info = invocation()) => readContext(() => store, info);
841
+ const commandContext = (info = invocation()) => {
842
+ let inTx = false;
843
+ const snapshot = queryContext(info);
844
+ const ctx = {
845
+ user,
846
+ invocation: info,
847
+ log: logger(),
848
+ secrets,
849
+ // Callable like the worker's `ctx.query`: it is the read-only snapshot context and runs a query.
850
+ query: Object.assign((q, input) => snapshot.query(q, input), snapshot),
851
+ async transaction(callback) {
852
+ if (inTx)
853
+ fail('runtime.nestedTransaction', 'ctx.transaction cannot be nested');
854
+ inTx = true;
855
+ try {
856
+ return await inTransaction((tx) => callback(tx), false, info);
857
+ }
858
+ finally {
859
+ inTx = false;
860
+ }
861
+ },
862
+ call: (async (command, input) => {
863
+ // Like the Go host: an intent never runs while this invocation holds an open transaction.
864
+ if (inTx)
865
+ fail('runtime.intentInTransaction', 'ctx.call is not allowed while a transaction is open; finish the transaction first');
866
+ return invokeCommand(command, input, info.id);
867
+ }),
868
+ signal: (async (target, name, payload) => deliverSignal(checkSignal(target, name, payload, []))),
869
+ };
870
+ return ctx;
871
+ };
872
+ /** A new command invocation: prechecks and the bound implementation, in the right context kind. */
873
+ const invokeCommand = async (command, input, parent) => {
874
+ const valid = validateInput(command, input);
875
+ const info = invocation(parent);
876
+ const finish = (out) => (command.output === undefined ? undefined : decode(command.output, encode(command.output, out)));
877
+ if (command.atomic) {
878
+ return finish(await inTransaction((tx) => callCallable(tx, command, valid), false, info));
879
+ }
880
+ for (const g of prechecks.get(command.id) ?? [])
881
+ await g.handler(guardContext(queryContext(info)), valid);
882
+ return finish(await implementationOf(command.id).handler(commandContext(info), valid));
883
+ };
884
+ // ---- workflows
885
+ class Suspend extends Error {
886
+ on;
887
+ constructor(on) {
888
+ super(`workflow suspended on ${on.kind} "${on.name}"`);
889
+ this.name = 'Suspend';
890
+ this.on = on;
891
+ }
892
+ }
893
+ const createWorkflow = (impl, input, instanceId) => {
894
+ const instance = instanceId ?? nextId('wf');
895
+ const workflow = impl.contract;
896
+ const validInput = validateInput(workflow, input);
897
+ const startedAs = committed.started.find((x) => x.instance === instance);
898
+ if (startedAs !== undefined && startedAs.workflow !== workflow.id) {
899
+ fail('workflow.unknownInstance', `instance "${instance}" was started as "${startedAs.workflow}", not "${workflow.id}"`);
900
+ }
901
+ if (runs.has(instance))
902
+ fail('test.duplicateRun', `instance "${instance}" already has a run in this test host`);
903
+ const journal = new Map();
904
+ const tasks = [];
905
+ // Signals that reached the instance before the test created its run are consumed in arrival order.
906
+ const signals = (inboxes.get(instance) ?? []).map((x) => ({ ...x, consumed: false }));
907
+ inboxes.delete(instance);
908
+ workflowDefs.set(workflow.id, workflow);
909
+ runs.set(instance, { workflow, push: (name, payload) => void signals.push({ name, payload, consumed: false }) });
910
+ const run = async () => {
911
+ const counters = new Map();
912
+ const occurrence = (name, kind) => {
913
+ const n = counters.get(name) ?? 0;
914
+ counters.set(name, n + 1);
915
+ const key = `${name}#${n}`;
916
+ const occ = journal.get(key);
917
+ if (occ !== undefined && occ.kind !== kind)
918
+ fail('workflow.nondeterminism', `occurrence ${key} was ${occ.kind}, now ${kind}`);
919
+ return { key, n, occ };
920
+ };
921
+ const done = (key, kind, result, prior) => void journal.set(key, { kind, status: 'completed', result: result === undefined ? null : json(result), attempts: (prior?.attempts ?? 0) + 1 });
922
+ const wf = {
923
+ user,
924
+ instance: { id: instance },
925
+ log: logger(),
926
+ secrets,
927
+ transaction: (async (name, body, txInput) => {
928
+ const { key, occ } = occurrence(name, 'transaction');
929
+ if (occ?.status === 'completed')
930
+ return occ.result;
931
+ // Overloads: (name, callback) | (name, { output }, callback) | (name, callable, input).
932
+ const callback = typeof body === 'function' ? body : typeof txInput === 'function' ? txInput : undefined;
933
+ const schema = callback !== undefined && isRecord(body) ? body.output : undefined;
934
+ const result = callback !== undefined
935
+ ? await inTransaction(async (tx) => callback(tx), true)
936
+ : await inTransaction((tx) => callCallable(tx, body, txInput), true);
937
+ if (schema !== undefined)
938
+ encode(schema, result);
939
+ done(key, 'transaction', result);
940
+ return result;
941
+ }),
942
+ step: (async (name, a, b) => {
943
+ const effect = (typeof a === 'function' ? a : b);
944
+ const schema = isRecord(a) ? a.output : undefined;
945
+ const { key, n, occ } = occurrence(name, 'step');
946
+ if (occ?.status === 'completed')
947
+ return occ.result;
948
+ const attempt = occ ?? { kind: 'step', status: 'waiting', attempts: 0 };
949
+ journal.set(key, { ...attempt, attempts: attempt.attempts + 1 });
950
+ const value = await effect({ idempotencyKey: `${instance}:${name}:${n}` });
951
+ if (schema !== undefined)
952
+ encode(schema, value);
953
+ done(key, 'step', value, journal.get(key));
954
+ return value;
955
+ }),
956
+ sleep: async (name, duration) => {
957
+ const { key, n, occ } = occurrence(name, 'sleep');
958
+ if (occ?.status === 'completed')
959
+ return;
960
+ const wakeAt = occ?.wakeAt ?? clockMs + durationMs(duration);
961
+ if (clockMs >= wakeAt)
962
+ return done(key, 'sleep', null);
963
+ journal.set(key, { kind: 'sleep', status: 'waiting', wakeAt, attempts: 1 });
964
+ throw new Suspend({ kind: 'sleep', name, n, wakeAt: new Date(wakeAt).toISOString() });
965
+ },
966
+ waitFor: (async (name, signal, opts) => {
967
+ const { key, n, occ } = occurrence(name, 'waitFor');
968
+ const reply = (result) => (opts === undefined ? result.payload : result);
969
+ if (occ?.status === 'completed')
970
+ return reply(occ.result);
971
+ const queued = signals.find((s) => !s.consumed && s.name === signal.name);
972
+ if (queued !== undefined) {
973
+ queued.consumed = true;
974
+ const result = { outcome: 'received', payload: queued.payload };
975
+ done(key, 'waitFor', result);
976
+ return reply(result);
977
+ }
978
+ const wakeAt = opts === undefined ? undefined : (occ?.wakeAt ?? clockMs + durationMs(opts.timeout));
979
+ if (wakeAt !== undefined && clockMs >= wakeAt) {
980
+ done(key, 'waitFor', { outcome: 'timeout' });
981
+ return reply({ outcome: 'timeout' });
982
+ }
983
+ journal.set(key, { kind: 'waitFor', status: 'waiting', ...(wakeAt === undefined ? {} : { wakeAt }), attempts: 1 });
984
+ throw new Suspend({ kind: 'signal', name, n });
985
+ }),
986
+ task: (async (name, spec) => {
987
+ const { key, n, occ } = occurrence(name, 'task');
988
+ if (occ?.status === 'completed')
989
+ return occ.result;
990
+ let task = tasks.find((t) => t.name === name && t.n === n);
991
+ if (task === undefined) {
992
+ task = {
993
+ name, n, subject: spec.subject, assignee: assigneeOf(spec.assignee), status: 'open', mutableStatus: 'open', schema: spec.decision,
994
+ ...(spec.timeout === undefined ? {} : { due: clockMs + durationMs(spec.timeout) }),
995
+ };
996
+ tasks.push(task);
997
+ }
998
+ if (task.mutableStatus === 'decided') {
999
+ const result = { outcome: 'decided', decision: task.decision, by: (task.by ?? user.userId) };
1000
+ done(key, 'task', result);
1001
+ return result;
1002
+ }
1003
+ if (task.due !== undefined && clockMs >= task.due) {
1004
+ task.mutableStatus = 'expired';
1005
+ done(key, 'task', { outcome: 'timeout' });
1006
+ return { outcome: 'timeout' };
1007
+ }
1008
+ journal.set(key, { kind: 'task', status: 'waiting', attempts: 1 });
1009
+ throw new Suspend({ kind: 'task', name, n });
1010
+ }),
1011
+ call: (async (name, command, callInput) => {
1012
+ const { key, occ } = occurrence(name, 'call');
1013
+ if (occ?.status === 'completed')
1014
+ return occ.result;
1015
+ const result = await invokeCommand(command, callInput, instance);
1016
+ done(key, 'call', result);
1017
+ return result;
1018
+ }),
1019
+ start: (async (name, child, childInput) => {
1020
+ const { key, n, occ } = occurrence(name, 'start');
1021
+ if (occ?.status === 'completed')
1022
+ return occ.result;
1023
+ const childInstance = nextId('wf');
1024
+ workflowDefs.set(child.id, child);
1025
+ committed.started.push({ workflow: child.id, instance: childInstance, key: `${instance}:${name}:${n}`, input: encode(child.input, validateInput(child, childInput)) });
1026
+ const handle = { workflow: child.id, instance: childInstance };
1027
+ done(key, 'start', handle);
1028
+ return handle;
1029
+ }),
1030
+ now: async (name) => {
1031
+ const { key, occ } = occurrence(name, 'now');
1032
+ if (occ?.status === 'completed')
1033
+ return occ.result;
1034
+ const at = nowIso();
1035
+ done(key, 'now', at);
1036
+ return at;
1037
+ },
1038
+ uuid: async (name) => {
1039
+ const { key, occ } = occurrence(name, 'uuid');
1040
+ if (occ?.status === 'completed')
1041
+ return occ.result;
1042
+ const id = nextKey();
1043
+ done(key, 'uuid', id);
1044
+ return id;
1045
+ },
1046
+ };
1047
+ try {
1048
+ const value = await impl.handler(wf, validInput);
1049
+ return { status: 'completed', value };
1050
+ }
1051
+ catch (e) {
1052
+ if (e instanceof Suspend)
1053
+ return { status: 'suspended', on: e.on };
1054
+ return { status: 'failed', error: e };
1055
+ }
1056
+ };
1057
+ const driver = {
1058
+ instance,
1059
+ run,
1060
+ decide(name, decision, opts = {}) {
1061
+ const task = tasks.find((t) => t.name === name && t.mutableStatus === 'open' && (opts.n === undefined || t.n === opts.n));
1062
+ if (task === undefined)
1063
+ return fail('workflow.noOpenTask', `no open task "${name}" in ${instance}`);
1064
+ const required = permissionOf(task.assignee);
1065
+ if (required !== undefined && !holds(opts.by ?? user.userId, required)) {
1066
+ return fail('workflow.forbidden', `user ${opts.by ?? user.userId} does not hold permission ${required}, which task "${name}" is assigned to`);
1067
+ }
1068
+ try {
1069
+ encode(task.schema, decision);
1070
+ }
1071
+ catch (e) {
1072
+ return fail('workflow.invalidDecision', e.message);
1073
+ }
1074
+ task.decision = json(decision);
1075
+ task.by = opts.by ?? user.userId;
1076
+ task.mutableStatus = 'decided';
1077
+ },
1078
+ signal(signal, payload) {
1079
+ const name = typeof signal === 'string' ? signal : signal.name;
1080
+ deliverSignal(checkSignal({ workflow: workflow.id, instance }, name, payload, []));
1081
+ },
1082
+ get tasks() {
1083
+ return tasks.map((t) => ({ name: t.name, n: t.n, subject: t.subject, assignee: t.assignee, status: t.mutableStatus }));
1084
+ },
1085
+ get journal() {
1086
+ return [...journal].filter(([, o]) => o.status === 'completed').map(([k]) => k);
1087
+ },
1088
+ };
1089
+ return driver;
1090
+ };
1091
+ // ---- public surface
1092
+ const host = {
1093
+ fakes,
1094
+ user,
1095
+ clock: {
1096
+ now: nowIso,
1097
+ advance: (d) => void (clockMs += durationMs(d)),
1098
+ },
1099
+ get emitted() {
1100
+ return committed.emitted;
1101
+ },
1102
+ get notices() {
1103
+ return committed.notices;
1104
+ },
1105
+ get deliveries() {
1106
+ return deliveries;
1107
+ },
1108
+ get started() {
1109
+ return committed.started;
1110
+ },
1111
+ get signals() {
1112
+ return committed.signals;
1113
+ },
1114
+ get logs() {
1115
+ return logs;
1116
+ },
1117
+ query: () => queryContext(),
1118
+ command: () => commandContext(),
1119
+ transaction: (callback) => inTransaction(async (tx) => callback(tx), false),
1120
+ deliver: (async (subscription, event) => {
1121
+ const payload = decode(subscription.event.payload, event.payload);
1122
+ const delivered = {
1123
+ id: nextId('evt'),
1124
+ event: subscription.event.id,
1125
+ occurredAt: nowIso(),
1126
+ subject: event.subject,
1127
+ payload,
1128
+ initiator: (event.initiator ?? user.userId),
1129
+ };
1130
+ await inTransaction(async (tx) => {
1131
+ await subscription.handler(tx, delivered);
1132
+ }, true);
1133
+ }),
1134
+ workflow: ((impl, input, opts) => createWorkflow(impl, input, opts?.instance)),
1135
+ table: ((entity) => {
1136
+ register(entity);
1137
+ return [...store.table(entity.id).values()].map((r) => project(entity, r));
1138
+ }),
1139
+ overlayRow: ((overlay, base) => {
1140
+ register(overlay);
1141
+ const row = store.overlay(overlay.id).get(base.key);
1142
+ return row === undefined ? null : project(overlay, row);
1143
+ }),
1144
+ };
1145
+ return host;
1146
+ }