@minca/core 0.2.0 → 0.4.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 (420) hide show
  1. package/README.md +2 -2
  2. package/dist/{session → hosting}/hosting.d.ts +2 -8
  3. package/dist/hosting/hosting.d.ts.map +1 -0
  4. package/dist/{session → hosting}/hosting.js +3 -3
  5. package/dist/hosting/hosting.js.map +1 -0
  6. package/dist/identity/abilities.d.ts +0 -2
  7. package/dist/identity/abilities.d.ts.map +1 -1
  8. package/dist/identity/abilities.js +2 -2
  9. package/dist/identity/abilities.js.map +1 -1
  10. package/dist/identity/account-vault.d.ts +0 -2
  11. package/dist/identity/account-vault.d.ts.map +1 -1
  12. package/dist/identity/account-vault.js +1 -1
  13. package/dist/identity/account-vault.js.map +1 -1
  14. package/dist/identity/crypto-p256.d.ts +1 -1
  15. package/dist/identity/crypto-p256.d.ts.map +1 -1
  16. package/dist/identity/ucan.d.ts +2 -1
  17. package/dist/identity/ucan.d.ts.map +1 -1
  18. package/dist/identity/ucan.js +1 -1
  19. package/dist/identity/ucan.js.map +1 -1
  20. package/dist/inbox/inbox.d.ts +0 -21
  21. package/dist/inbox/inbox.d.ts.map +1 -1
  22. package/dist/inbox/inbox.js +4 -4
  23. package/dist/inbox/inbox.js.map +1 -1
  24. package/dist/inbox/index.d.ts +4 -5
  25. package/dist/inbox/index.d.ts.map +1 -1
  26. package/dist/inbox/index.js +2 -3
  27. package/dist/inbox/index.js.map +1 -1
  28. package/dist/inbox/names.d.ts +0 -4
  29. package/dist/inbox/names.d.ts.map +1 -1
  30. package/dist/inbox/names.js +2 -2
  31. package/dist/inbox/names.js.map +1 -1
  32. package/dist/index.d.ts +50 -84
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +38 -60
  35. package/dist/index.js.map +1 -1
  36. package/dist/network/mesh.d.ts.map +1 -1
  37. package/dist/network/mesh.js +23 -3
  38. package/dist/network/mesh.js.map +1 -1
  39. package/dist/network/network-manager.d.ts +5 -0
  40. package/dist/network/network-manager.d.ts.map +1 -1
  41. package/dist/network/network-manager.js +3 -0
  42. package/dist/network/network-manager.js.map +1 -1
  43. package/dist/network/peer-auth.d.ts +17 -5
  44. package/dist/network/peer-auth.d.ts.map +1 -1
  45. package/dist/network/peer-auth.js +19 -9
  46. package/dist/network/peer-auth.js.map +1 -1
  47. package/dist/network/rendezvous.d.ts +2 -0
  48. package/dist/network/rendezvous.d.ts.map +1 -1
  49. package/dist/network/rendezvous.js +5 -0
  50. package/dist/network/rendezvous.js.map +1 -1
  51. package/dist/network/rtc-transport.d.ts.map +1 -1
  52. package/dist/network/rtc-transport.js +9 -3
  53. package/dist/network/rtc-transport.js.map +1 -1
  54. package/dist/network/transport.d.ts +12 -0
  55. package/dist/network/transport.d.ts.map +1 -1
  56. package/dist/network/ws-transport.d.ts +1 -1
  57. package/dist/network/ws-transport.d.ts.map +1 -1
  58. package/dist/network/ws-transport.js +14 -4
  59. package/dist/network/ws-transport.js.map +1 -1
  60. package/dist/node/carrier.d.ts +1 -33
  61. package/dist/node/carrier.d.ts.map +1 -1
  62. package/dist/node/carrier.js +38 -68
  63. package/dist/node/carrier.js.map +1 -1
  64. package/dist/node/index.d.ts +5 -16
  65. package/dist/node/index.d.ts.map +1 -1
  66. package/dist/node/index.js +2 -9
  67. package/dist/node/index.js.map +1 -1
  68. package/dist/node/node-carriers.d.ts.map +1 -1
  69. package/dist/node/node-carriers.js +21 -52
  70. package/dist/node/node-carriers.js.map +1 -1
  71. package/dist/node/node-context.d.ts +0 -2
  72. package/dist/node/node-context.d.ts.map +1 -1
  73. package/dist/node/node-context.js.map +1 -1
  74. package/dist/node/node-hosting.d.ts.map +1 -1
  75. package/dist/node/node-hosting.js +14 -5
  76. package/dist/node/node-hosting.js.map +1 -1
  77. package/dist/node/node-records.js +2 -2
  78. package/dist/node/node-records.js.map +1 -1
  79. package/dist/node/node.d.ts.map +1 -1
  80. package/dist/node/node.js +152 -36
  81. package/dist/node/node.js.map +1 -1
  82. package/dist/node/space-checks.d.ts +3 -1
  83. package/dist/node/space-checks.d.ts.map +1 -1
  84. package/dist/node/space-checks.js +7 -3
  85. package/dist/node/space-checks.js.map +1 -1
  86. package/dist/node/space-holding.d.ts +5 -0
  87. package/dist/node/space-holding.d.ts.map +1 -1
  88. package/dist/node/space-holding.js +90 -5
  89. package/dist/node/space-holding.js.map +1 -1
  90. package/dist/node/space-lines.d.ts +3 -0
  91. package/dist/node/space-lines.d.ts.map +1 -1
  92. package/dist/node/space-lines.js +13 -1
  93. package/dist/node/space-lines.js.map +1 -1
  94. package/dist/node/space-membership.js +4 -4
  95. package/dist/node/space-membership.js.map +1 -1
  96. package/dist/node/space-mirrors.d.ts +1 -1
  97. package/dist/node/space-mirrors.d.ts.map +1 -1
  98. package/dist/node/space-mirrors.js +17 -5
  99. package/dist/node/space-mirrors.js.map +1 -1
  100. package/dist/node/space-peers.d.ts +7 -2
  101. package/dist/node/space-peers.d.ts.map +1 -1
  102. package/dist/node/space-peers.js +44 -10
  103. package/dist/node/space-peers.js.map +1 -1
  104. package/dist/node/space-runtime.d.ts +7 -3
  105. package/dist/node/space-runtime.d.ts.map +1 -1
  106. package/dist/node/space-runtime.js +32 -10
  107. package/dist/node/space-runtime.js.map +1 -1
  108. package/dist/node/space-standing.d.ts +1 -1
  109. package/dist/node/space-standing.d.ts.map +1 -1
  110. package/dist/node/space-standing.js +23 -42
  111. package/dist/node/space-standing.js.map +1 -1
  112. package/dist/node/space-warrants.js +1 -1
  113. package/dist/node/space-warrants.js.map +1 -1
  114. package/dist/node/space-writing.d.ts.map +1 -1
  115. package/dist/node/space-writing.js +21 -32
  116. package/dist/node/space-writing.js.map +1 -1
  117. package/dist/node/stores.d.ts +9 -57
  118. package/dist/node/stores.d.ts.map +1 -1
  119. package/dist/node/stores.js +1 -72
  120. package/dist/node/stores.js.map +1 -1
  121. package/dist/node/types.d.ts +19 -8
  122. package/dist/node/types.d.ts.map +1 -1
  123. package/dist/node/writer-keys.d.ts +15 -14
  124. package/dist/node/writer-keys.d.ts.map +1 -1
  125. package/dist/node/writer-keys.js +3 -115
  126. package/dist/node/writer-keys.js.map +1 -1
  127. package/dist/privacy/direct.d.ts +0 -7
  128. package/dist/privacy/direct.d.ts.map +1 -1
  129. package/dist/privacy/direct.js +2 -2
  130. package/dist/privacy/direct.js.map +1 -1
  131. package/dist/query/filter.d.ts +0 -2
  132. package/dist/query/filter.d.ts.map +1 -1
  133. package/dist/query/filter.js +1 -1
  134. package/dist/query/filter.js.map +1 -1
  135. package/dist/query/types.d.ts +2 -6
  136. package/dist/query/types.d.ts.map +1 -1
  137. package/dist/query/types.js.map +1 -1
  138. package/dist/records/key.d.ts +18 -19
  139. package/dist/records/key.d.ts.map +1 -1
  140. package/dist/records/key.js +55 -43
  141. package/dist/records/key.js.map +1 -1
  142. package/dist/records/links.js +1 -1
  143. package/dist/records/rules.d.ts +1 -1
  144. package/dist/records/rules.d.ts.map +1 -1
  145. package/dist/records/rules.js +6 -4
  146. package/dist/records/rules.js.map +1 -1
  147. package/dist/schemas/direct.d.ts +70 -0
  148. package/dist/schemas/direct.d.ts.map +1 -0
  149. package/dist/schemas/direct.js +39 -0
  150. package/dist/schemas/direct.js.map +1 -0
  151. package/dist/schemas/index.d.ts +10 -73
  152. package/dist/schemas/index.d.ts.map +1 -1
  153. package/dist/schemas/index.js +8 -66
  154. package/dist/schemas/index.js.map +1 -1
  155. package/dist/space/account-registry.d.ts +0 -3
  156. package/dist/space/account-registry.d.ts.map +1 -1
  157. package/dist/space/account-registry.js.map +1 -1
  158. package/dist/space/own-automations.d.ts +51 -95
  159. package/dist/space/own-automations.d.ts.map +1 -1
  160. package/dist/space/own-automations.js +100 -295
  161. package/dist/space/own-automations.js.map +1 -1
  162. package/dist/space/pass.d.ts +8 -3
  163. package/dist/space/pass.d.ts.map +1 -1
  164. package/dist/space/pass.js +4 -3
  165. package/dist/space/pass.js.map +1 -1
  166. package/dist/space/space-manager.d.ts +1 -3
  167. package/dist/space/space-manager.d.ts.map +1 -1
  168. package/dist/space/space-manager.js +5 -7
  169. package/dist/space/space-manager.js.map +1 -1
  170. package/dist/storage/body-cache.d.ts +29 -0
  171. package/dist/storage/body-cache.d.ts.map +1 -0
  172. package/dist/storage/body-cache.js +64 -0
  173. package/dist/storage/body-cache.js.map +1 -0
  174. package/dist/storage/encrypted-adapter.d.ts +0 -5
  175. package/dist/storage/encrypted-adapter.d.ts.map +1 -1
  176. package/dist/storage/encrypted-adapter.js +1 -1
  177. package/dist/storage/encrypted-adapter.js.map +1 -1
  178. package/dist/storage/mirror.d.ts.map +1 -1
  179. package/dist/storage/mirror.js +35 -16
  180. package/dist/storage/mirror.js.map +1 -1
  181. package/dist/storage/segment.d.ts +6 -2
  182. package/dist/storage/segment.d.ts.map +1 -1
  183. package/dist/storage/segment.js +8 -4
  184. package/dist/storage/segment.js.map +1 -1
  185. package/dist/storage/shared-store.d.ts +32 -0
  186. package/dist/storage/shared-store.d.ts.map +1 -0
  187. package/dist/storage/{folder-reconcile.js → shared-store.js} +15 -15
  188. package/dist/storage/shared-store.js.map +1 -0
  189. package/dist/storage/storage-provider.d.ts +19 -9
  190. package/dist/storage/storage-provider.d.ts.map +1 -1
  191. package/dist/storage/storage-provider.js +155 -62
  192. package/dist/storage/storage-provider.js.map +1 -1
  193. package/dist/sync/sync-engine.d.ts +17 -4
  194. package/dist/sync/sync-engine.d.ts.map +1 -1
  195. package/dist/sync/sync-engine.js +298 -84
  196. package/dist/sync/sync-engine.js.map +1 -1
  197. package/dist/sync/sync-messages.d.ts +5 -1
  198. package/dist/sync/sync-messages.d.ts.map +1 -1
  199. package/dist/sync/sync-messages.js +1 -1
  200. package/dist/sync/sync-messages.js.map +1 -1
  201. package/dist/types.d.ts +19 -7
  202. package/dist/types.d.ts.map +1 -1
  203. package/dist/types.js +4 -1
  204. package/dist/types.js.map +1 -1
  205. package/dist/utils/index.d.ts +5 -5
  206. package/dist/utils/index.d.ts.map +1 -1
  207. package/dist/utils/index.js +5 -5
  208. package/dist/utils/index.js.map +1 -1
  209. package/dist/utils/step.d.ts +8 -0
  210. package/dist/utils/step.d.ts.map +1 -0
  211. package/dist/utils/step.js +15 -0
  212. package/dist/utils/step.js.map +1 -0
  213. package/docs/README.md +4 -3
  214. package/docs/actions.md +41 -2
  215. package/docs/agents.md +13 -10
  216. package/docs/automations.md +16 -48
  217. package/docs/blueprints-and-guides.md +2 -2
  218. package/docs/bots.md +3 -3
  219. package/docs/building-an-app.md +2 -2
  220. package/docs/collections.md +2 -4
  221. package/docs/computed.md +1 -2
  222. package/docs/node.md +108 -40
  223. package/docs/proposing-collections.md +3 -3
  224. package/docs/query-format.md +6 -5
  225. package/docs/records-and-queries.md +12 -13
  226. package/docs/sign-in.md +16 -16
  227. package/docs/spaces.md +0 -5
  228. package/docs/standard-library.md +6 -8
  229. package/docs/storage.md +114 -22
  230. package/docs/usernames.md +1 -1
  231. package/package.json +15 -25
  232. package/dist/identity/account-store.d.ts +0 -83
  233. package/dist/identity/account-store.d.ts.map +0 -1
  234. package/dist/identity/account-store.js +0 -234
  235. package/dist/identity/account-store.js.map +0 -1
  236. package/dist/identity/device-key.d.ts +0 -26
  237. package/dist/identity/device-key.d.ts.map +0 -1
  238. package/dist/identity/device-key.js +0 -48
  239. package/dist/identity/device-key.js.map +0 -1
  240. package/dist/identity/idb.d.ts +0 -19
  241. package/dist/identity/idb.d.ts.map +0 -1
  242. package/dist/identity/idb.js +0 -56
  243. package/dist/identity/idb.js.map +0 -1
  244. package/dist/node/actions.d.ts +0 -85
  245. package/dist/node/actions.d.ts.map +0 -1
  246. package/dist/node/actions.js +0 -921
  247. package/dist/node/actions.js.map +0 -1
  248. package/dist/node/host.d.ts +0 -187
  249. package/dist/node/host.d.ts.map +0 -1
  250. package/dist/node/host.js +0 -818
  251. package/dist/node/host.js.map +0 -1
  252. package/dist/node/usage.d.ts +0 -32
  253. package/dist/node/usage.d.ts.map +0 -1
  254. package/dist/node/usage.js +0 -217
  255. package/dist/node/usage.js.map +0 -1
  256. package/dist/node/watch-notifications.d.ts +0 -25
  257. package/dist/node/watch-notifications.d.ts.map +0 -1
  258. package/dist/node/watch-notifications.js +0 -166
  259. package/dist/node/watch-notifications.js.map +0 -1
  260. package/dist/node/worker.d.ts +0 -83
  261. package/dist/node/worker.d.ts.map +0 -1
  262. package/dist/node/worker.js +0 -305
  263. package/dist/node/worker.js.map +0 -1
  264. package/dist/node-worker.d.ts +0 -2
  265. package/dist/node-worker.d.ts.map +0 -1
  266. package/dist/node-worker.js +0 -16
  267. package/dist/node-worker.js.map +0 -1
  268. package/dist/schemas/automations.d.ts +0 -390
  269. package/dist/schemas/automations.d.ts.map +0 -1
  270. package/dist/schemas/automations.js +0 -619
  271. package/dist/schemas/automations.js.map +0 -1
  272. package/dist/schemas/blueprints.d.ts +0 -122
  273. package/dist/schemas/blueprints.d.ts.map +0 -1
  274. package/dist/schemas/blueprints.js +0 -337
  275. package/dist/schemas/blueprints.js.map +0 -1
  276. package/dist/schemas/choosing.d.ts +0 -19
  277. package/dist/schemas/choosing.d.ts.map +0 -1
  278. package/dist/schemas/choosing.js +0 -69
  279. package/dist/schemas/choosing.js.map +0 -1
  280. package/dist/schemas/connectors.d.ts +0 -202
  281. package/dist/schemas/connectors.d.ts.map +0 -1
  282. package/dist/schemas/connectors.js +0 -140
  283. package/dist/schemas/connectors.js.map +0 -1
  284. package/dist/schemas/cron.d.ts +0 -14
  285. package/dist/schemas/cron.d.ts.map +0 -1
  286. package/dist/schemas/cron.js +0 -75
  287. package/dist/schemas/cron.js.map +0 -1
  288. package/dist/schemas/geo.d.ts +0 -63
  289. package/dist/schemas/geo.d.ts.map +0 -1
  290. package/dist/schemas/geo.js +0 -131
  291. package/dist/schemas/geo.js.map +0 -1
  292. package/dist/schemas/guides.d.ts +0 -26
  293. package/dist/schemas/guides.d.ts.map +0 -1
  294. package/dist/schemas/guides.js +0 -33
  295. package/dist/schemas/guides.js.map +0 -1
  296. package/dist/schemas/library/annotations.d.ts +0 -616
  297. package/dist/schemas/library/annotations.d.ts.map +0 -1
  298. package/dist/schemas/library/annotations.js +0 -156
  299. package/dist/schemas/library/annotations.js.map +0 -1
  300. package/dist/schemas/library/collections.d.ts +0 -211
  301. package/dist/schemas/library/collections.d.ts.map +0 -1
  302. package/dist/schemas/library/collections.js +0 -57
  303. package/dist/schemas/library/collections.js.map +0 -1
  304. package/dist/schemas/library/community.d.ts +0 -1136
  305. package/dist/schemas/library/community.d.ts.map +0 -1
  306. package/dist/schemas/library/community.js +0 -315
  307. package/dist/schemas/library/community.js.map +0 -1
  308. package/dist/schemas/library/life.d.ts +0 -1440
  309. package/dist/schemas/library/life.d.ts.map +0 -1
  310. package/dist/schemas/library/life.js +0 -202
  311. package/dist/schemas/library/life.js.map +0 -1
  312. package/dist/schemas/library/media.d.ts +0 -1002
  313. package/dist/schemas/library/media.d.ts.map +0 -1
  314. package/dist/schemas/library/media.js +0 -110
  315. package/dist/schemas/library/media.js.map +0 -1
  316. package/dist/schemas/library/money.d.ts +0 -1221
  317. package/dist/schemas/library/money.d.ts.map +0 -1
  318. package/dist/schemas/library/money.js +0 -168
  319. package/dist/schemas/library/money.js.map +0 -1
  320. package/dist/schemas/library/planning.d.ts +0 -1107
  321. package/dist/schemas/library/planning.d.ts.map +0 -1
  322. package/dist/schemas/library/planning.js +0 -214
  323. package/dist/schemas/library/planning.js.map +0 -1
  324. package/dist/schemas/library/publishing.d.ts +0 -1499
  325. package/dist/schemas/library/publishing.d.ts.map +0 -1
  326. package/dist/schemas/library/publishing.js +0 -285
  327. package/dist/schemas/library/publishing.js.map +0 -1
  328. package/dist/schemas/library/social.d.ts +0 -1257
  329. package/dist/schemas/library/social.d.ts.map +0 -1
  330. package/dist/schemas/library/social.js +0 -147
  331. package/dist/schemas/library/social.js.map +0 -1
  332. package/dist/schemas/standard.d.ts +0 -21
  333. package/dist/schemas/standard.d.ts.map +0 -1
  334. package/dist/schemas/standard.js +0 -39
  335. package/dist/schemas/standard.js.map +0 -1
  336. package/dist/session/account-hint.d.ts +0 -13
  337. package/dist/session/account-hint.d.ts.map +0 -1
  338. package/dist/session/account-hint.js +0 -54
  339. package/dist/session/account-hint.js.map +0 -1
  340. package/dist/session/auth.d.ts +0 -411
  341. package/dist/session/auth.d.ts.map +0 -1
  342. package/dist/session/auth.js +0 -1529
  343. package/dist/session/auth.js.map +0 -1
  344. package/dist/session/channel-room.d.ts +0 -26
  345. package/dist/session/channel-room.d.ts.map +0 -1
  346. package/dist/session/channel-room.js +0 -56
  347. package/dist/session/channel-room.js.map +0 -1
  348. package/dist/session/connect-code.d.ts +0 -127
  349. package/dist/session/connect-code.d.ts.map +0 -1
  350. package/dist/session/connect-code.js +0 -408
  351. package/dist/session/connect-code.js.map +0 -1
  352. package/dist/session/connect.d.ts +0 -386
  353. package/dist/session/connect.d.ts.map +0 -1
  354. package/dist/session/connect.js +0 -583
  355. package/dist/session/connect.js.map +0 -1
  356. package/dist/session/connection.d.ts +0 -135
  357. package/dist/session/connection.d.ts.map +0 -1
  358. package/dist/session/connection.js +0 -215
  359. package/dist/session/connection.js.map +0 -1
  360. package/dist/session/credentials.d.ts +0 -30
  361. package/dist/session/credentials.d.ts.map +0 -1
  362. package/dist/session/credentials.js +0 -63
  363. package/dist/session/credentials.js.map +0 -1
  364. package/dist/session/hosting.d.ts.map +0 -1
  365. package/dist/session/hosting.js.map +0 -1
  366. package/dist/session/index.d.ts +0 -29
  367. package/dist/session/index.d.ts.map +0 -1
  368. package/dist/session/index.js +0 -21
  369. package/dist/session/index.js.map +0 -1
  370. package/dist/session/pairing.d.ts +0 -97
  371. package/dist/session/pairing.d.ts.map +0 -1
  372. package/dist/session/pairing.js +0 -251
  373. package/dist/session/pairing.js.map +0 -1
  374. package/dist/session/password-strength.d.ts +0 -22
  375. package/dist/session/password-strength.d.ts.map +0 -1
  376. package/dist/session/password-strength.js +0 -130
  377. package/dist/session/password-strength.js.map +0 -1
  378. package/dist/session/places.d.ts +0 -71
  379. package/dist/session/places.d.ts.map +0 -1
  380. package/dist/session/places.js +0 -130
  381. package/dist/session/places.js.map +0 -1
  382. package/dist/session/popup.d.ts +0 -13
  383. package/dist/session/popup.d.ts.map +0 -1
  384. package/dist/session/popup.js +0 -23
  385. package/dist/session/popup.js.map +0 -1
  386. package/dist/session/stay-signed-in.d.ts +0 -49
  387. package/dist/session/stay-signed-in.d.ts.map +0 -1
  388. package/dist/session/stay-signed-in.js +0 -141
  389. package/dist/session/stay-signed-in.js.map +0 -1
  390. package/dist/storage/blob/directory.d.ts +0 -14
  391. package/dist/storage/blob/directory.d.ts.map +0 -1
  392. package/dist/storage/blob/directory.js +0 -87
  393. package/dist/storage/blob/directory.js.map +0 -1
  394. package/dist/storage/blob/memory.d.ts +0 -6
  395. package/dist/storage/blob/memory.d.ts.map +0 -1
  396. package/dist/storage/blob/memory.js +0 -20
  397. package/dist/storage/blob/memory.js.map +0 -1
  398. package/dist/storage/blob/s3.d.ts +0 -16
  399. package/dist/storage/blob/s3.d.ts.map +0 -1
  400. package/dist/storage/blob/s3.js +0 -91
  401. package/dist/storage/blob/s3.js.map +0 -1
  402. package/dist/storage/directory-access.d.ts +0 -36
  403. package/dist/storage/directory-access.d.ts.map +0 -1
  404. package/dist/storage/directory-access.js +0 -89
  405. package/dist/storage/directory-access.js.map +0 -1
  406. package/dist/storage/folder-adapter.d.ts +0 -94
  407. package/dist/storage/folder-adapter.d.ts.map +0 -1
  408. package/dist/storage/folder-adapter.js +0 -215
  409. package/dist/storage/folder-adapter.js.map +0 -1
  410. package/dist/storage/folder-reconcile.d.ts +0 -33
  411. package/dist/storage/folder-reconcile.d.ts.map +0 -1
  412. package/dist/storage/folder-reconcile.js.map +0 -1
  413. package/dist/storage/index.d.ts +0 -6
  414. package/dist/storage/index.d.ts.map +0 -1
  415. package/dist/storage/index.js +0 -5
  416. package/dist/storage/index.js.map +0 -1
  417. package/dist/storage/indexeddb-adapter.d.ts +0 -8
  418. package/dist/storage/indexeddb-adapter.d.ts.map +0 -1
  419. package/dist/storage/indexeddb-adapter.js +0 -103
  420. package/dist/storage/indexeddb-adapter.js.map +0 -1
@@ -1,619 +0,0 @@
1
- import { nameOf, plainQuery, } from '../query/types.js';
2
- import { checkFilter, checkQuery, matches } from '../query/filter.js';
3
- import { causeOf, namedComputed } from '../query/computed.js';
4
- import { quickAddBody } from '../schema/quick-add.js';
5
- import { schemaProblem } from '../schema/collection-def.js';
6
- import { isObject } from '../utils/guards.js';
7
- import { checkCron, cronMatches } from './cron.js';
8
- import { definedNames } from './defined.js';
9
- import { about, define, one, person, text, typed, when as moment, words } from './fragments.js';
10
- export const automation = typed()({
11
- name: 'std.automation',
12
- title: 'Automation',
13
- description: 'When records in the space are a certain way, or at set times, do something.',
14
- schema: {
15
- type: 'object',
16
- properties: {
17
- name: words(120),
18
- when: { type: 'object' },
19
- every: text(100, 'Five cron fields, minute hour day month weekday, local time', 9),
20
- then: { type: 'object' },
21
- by: person('The bot that runs it'),
22
- picked: { type: 'object' },
23
- paused: { type: 'boolean' },
24
- since: moment('Nothing that came to hold before this sets it off'),
25
- spaces: { description: 'Every space of the account ("all"), or a list of their ids' },
26
- open: words(2000),
27
- app: {
28
- type: 'object',
29
- properties: { origin: words(200), name: words(80) },
30
- required: ['origin'],
31
- },
32
- },
33
- required: ['name', 'then', 'since'],
34
- },
35
- });
36
- export const automationRun = define({
37
- name: 'std.automation-run',
38
- title: 'Automation run',
39
- description: 'An automation acted on a record: once each, whichever device did it.',
40
- schema: {
41
- type: 'object',
42
- properties: { did: words(500), ok: { type: 'boolean' }, at: moment(), made: words(256) },
43
- required: ['did', 'ok', 'at'],
44
- },
45
- links: {
46
- automation: one([automation.name], 'The automation that ran'),
47
- about: about('The record it ran for'),
48
- },
49
- rules: { onePer: ['link:automation', 'link:about'] },
50
- });
51
- export const ACTIVITY_STATES = ['working', 'waiting', 'done', 'failed'];
52
- /**
53
- * Someone at work on a record, for apps to show while it lasts: "My bot is
54
- * replying…" under a message, a spinner on a task. One per account per
55
- * record, changed in place as the work goes on. Its writer's word, like a
56
- * status, and only theirs to change.
57
- */
58
- export const activity = define({
59
- name: 'std.activity',
60
- title: 'Activity',
61
- description: 'Someone at work on a record: working, waiting, done or failed.',
62
- schema: {
63
- type: 'object',
64
- properties: {
65
- state: { type: 'string', enum: [...ACTIVITY_STATES] },
66
- label: words(120),
67
- at: moment('When it came to this state'),
68
- },
69
- required: ['state', 'at'],
70
- },
71
- links: { about: about('What the work is on') },
72
- rules: { onePer: ['@author', 'link:about'] },
73
- });
74
- /**
75
- * How long a `working` or `waiting` activity is believed without a change:
76
- * one whose writer went away mid-way would otherwise show forever.
77
- */
78
- export const ACTIVITY_STALE_SECONDS = 300;
79
- /** Whether an activity says someone is at work on it now: working or waiting, and not gone stale */
80
- export function activeNow(body, now = Date.now()) {
81
- if (!body || (body.state !== 'working' && body.state !== 'waiting'))
82
- return false;
83
- const at = Date.parse(body.at);
84
- return Number.isFinite(at) && now - at < ACTIVITY_STALE_SECONDS * 1000;
85
- }
86
- /**
87
- * Says where this account's work on a record stands: its one `std.activity`
88
- * about it, made or changed. Without a label, the one it had stays. Null
89
- * where the space keeps no `std.activity`.
90
- */
91
- export async function setActivity(node, space, on, state, label) {
92
- if (!(await definedNames(node, space)).has(activity.name))
93
- return null;
94
- const mine = await node.records.linked(space, on, { rel: 'about', collection: activity.name });
95
- const kept = label ?? mine.find((record) => record.root === node.did && !record.deleted)?.body?.label;
96
- const body = {
97
- state,
98
- ...(kept ? { label: kept.slice(0, 120) } : {}),
99
- at: new Date().toISOString(),
100
- };
101
- // One per account per record: a put for one it already has is that record's next version.
102
- return node.records.put(space, activity.name, body, { links: [{ rel: 'about', to: on }] });
103
- }
104
- /** In an action, the record the automation holds for */
105
- export const IT = '$it';
106
- /** In an automation's query or condition, whoever runs it: its maker, or the bot named in `by` */
107
- export const ME = '$me';
108
- /**
109
- * The command a maker needs a grant of in a space for a bot there to run
110
- * their rules: a library command, which no peer checks (docs/automations.md)
111
- */
112
- export const INSTRUCT = `/${automation.name}/instruct`;
113
- const said = { type: 'string', pattern: '\\S' };
114
- const named = { type: 'string', minLength: 1 };
115
- const saying = { type: 'object', properties: { text: { ...said, maxLength: 500 } }, required: ['text'] };
116
- /** Each kind of action's shape, which the stored schema leaves open */
117
- const ACTIONS = {
118
- notify: saying,
119
- ask: saying,
120
- add: {
121
- type: 'object',
122
- properties: {
123
- collection: named,
124
- text: said,
125
- links: {
126
- type: 'array',
127
- items: { type: 'object', properties: { rel: named, to: named }, required: ['rel', 'to'] },
128
- },
129
- },
130
- required: ['collection', 'text'],
131
- },
132
- set: {
133
- type: 'object',
134
- properties: { field: named, value: { type: ['string', 'number', 'boolean'] } },
135
- required: ['field', 'value'],
136
- },
137
- };
138
- /** An automation's shape, with what sets it off spelled out */
139
- const AUTOMATION = {
140
- ...automation.schema,
141
- properties: {
142
- ...automation.schema.properties,
143
- when: {
144
- type: 'object',
145
- properties: { from: { type: 'array', items: named }, others: { type: 'boolean' } },
146
- },
147
- spaces: {
148
- anyOf: [{ const: 'all' }, { type: 'array', minItems: 1, maxItems: 256, items: { type: 'string' } }],
149
- },
150
- },
151
- };
152
- /** Why this can't be an automation, or null when it can */
153
- export function checkAutomation(value) {
154
- if (!isObject(value))
155
- return 'An automation must be an object';
156
- const shape = schemaProblem(AUTOMATION, value);
157
- if (shape)
158
- return shape;
159
- if (typeof value.name !== 'string' || !value.name.trim())
160
- return 'An automation needs a name';
161
- if (value.when === undefined && value.every === undefined)
162
- return 'An automation needs a when: { query, holds? }, an every, or both';
163
- if (isObject(value.when)) {
164
- const query = checkQuery(value.when.query);
165
- if (query)
166
- return `when.query: ${query}`;
167
- const holds = value.when.holds === undefined ? null : checkFilter(value.when.holds, 'when.holds', { include: true });
168
- if (holds)
169
- return holds;
170
- }
171
- const every = typeof value.every === 'string' ? checkCron(value.every) : null;
172
- if (every)
173
- return `every: ${every}`;
174
- const then = value.then;
175
- const action = isObject(then) && typeof then.kind === 'string' ? ACTIONS[then.kind] : undefined;
176
- if (!isObject(then) || !action)
177
- return `then.kind must be one of ${Object.keys(ACTIONS).join(', ')}`;
178
- const actionShape = schemaProblem(action, then, 'then');
179
- if (actionShape)
180
- return actionShape;
181
- if (then.kind === 'set' && value.when === undefined)
182
- return 'An automation that changes a record needs a when';
183
- if (typeof value.since !== 'string' || !Number.isFinite(Date.parse(value.since)))
184
- return 'since must be a date';
185
- if (value.open !== undefined && !isWebAddress(value.open))
186
- return 'open must be an https:// address';
187
- if (isObject(value.app) && !isOrigin(value.app.origin))
188
- return 'app.origin must be a web origin';
189
- return null;
190
- }
191
- /** An https:// address, or http:// on this machine */
192
- function isWebAddress(value) {
193
- const url = parseUrl(value);
194
- return url?.protocol === 'https:' || (url?.protocol === 'http:' && LOCAL_HOSTS.includes(url.hostname));
195
- }
196
- const LOCAL_HOSTS = ['localhost', '127.0.0.1'];
197
- /** A browser extension's origin, which `URL` gives none */
198
- const EXTENSION_ORIGIN = /^(chrome|moz|safari-web)-extension:\/\/[a-z0-9-]{1,64}$/i;
199
- /** `https://chat.example`, nothing after it: what a browser reports as a message's origin */
200
- function isOrigin(value) {
201
- if (typeof value !== 'string')
202
- return false;
203
- return EXTENSION_ORIGIN.test(value) || parseUrl(value)?.origin === value;
204
- }
205
- function parseUrl(value) {
206
- if (typeof value !== 'string')
207
- return null;
208
- try {
209
- return new URL(value);
210
- }
211
- catch {
212
- return null;
213
- }
214
- }
215
- const isAutomation = (value) => checkAutomation(value) === null;
216
- /** An automation record's body, when it is one */
217
- export const automationOf = (record) => isAutomation(record.body) ? record.body : null;
218
- /** `$me` wherever it is a value, as the account running the automation */
219
- export function asRunner(value, me) {
220
- // eslint-disable-next-line typescript/consistent-type-assertions -- the same shape, with one string swapped for another
221
- return JSON.parse(JSON.stringify(value), (_key, found) => (found === ME ? me : found));
222
- }
223
- /**
224
- * The records an automation holds for now, most recently changed first, for `me`,
225
- * who runs it. Includes that count are run as lists and counted here, so the
226
- * newest of them can tell when the automation came to hold.
227
- */
228
- export async function matching(node, space, ruleWhen, me, limit = 200) {
229
- const when = asRunner(ruleWhen, me);
230
- const query = plainQuery(when.query);
231
- const { include, counted } = countsAsLists(query.include ?? {});
232
- const { records } = await node.records.query(space, {
233
- ...query,
234
- include,
235
- sort: query.sort ?? { '@updatedAt': 'desc' },
236
- limit: query.limit ?? limit,
237
- });
238
- const holds = (subject) => when.holds === undefined || matches(subject, when.holds);
239
- const causeIn = await causeFinder(node, space, query, when.holds, holds);
240
- const found = [];
241
- for (const record of records) {
242
- const { included, newest } = readIncluded(record, counted);
243
- if (!holds({ ...record, included }))
244
- continue;
245
- const cause = await causeIn(record, included);
246
- // What made it hold can't be told: better quiet than set off by the wrong one.
247
- if (!cause)
248
- continue;
249
- const moment = cause === record ? newest : Math.max(newest, Date.parse(cause.updatedAt));
250
- found.push({ record, included, moment, cause });
251
- }
252
- return found;
253
- }
254
- /** A query's includes, with those that count turned into lists, and the names of those */
255
- function countsAsLists(include) {
256
- const counted = new Set();
257
- const lists = Object.fromEntries(Object.entries(include).map(([name, found]) => {
258
- if (!found.count)
259
- return [name, found];
260
- counted.add(name);
261
- const { count: _count, limit: _limit, ...listed } = found;
262
- return [name, listed];
263
- }));
264
- return { include: lists, counted };
265
- }
266
- /** What a record's includes found, counted ones as numbers, and the newest moment among it and them */
267
- function readIncluded(record, counted) {
268
- let newest = Date.parse(record.updatedAt);
269
- const included = {};
270
- for (const [name, value] of Object.entries(record.included)) {
271
- if (typeof value === 'number') {
272
- included[name] = value;
273
- continue;
274
- }
275
- for (const one of value)
276
- newest = Math.max(newest, Date.parse(one.createdAt));
277
- included[name] = counted.has(name) ? value.length : value;
278
- }
279
- return { included, newest };
280
- }
281
- /**
282
- * How to tell what made a record hold. A computed field the automation reads
283
- * changes when what it reads is written: a 👍 can make a todo done. It is what
284
- * made it hold, not what came last: a 😡 after the second 👍 sets nothing off.
285
- */
286
- async function causeFinder(node, space, query, holdsFilter, holds) {
287
- const name = nameOf(query.collection);
288
- const fields = (await node.collections.list(space)).find((c) => c.name === name)?.computed ?? {};
289
- const read = { ...namedComputed(fields, query.where), ...namedComputed(fields, holdsFilter) };
290
- if (Object.keys(read).length === 0)
291
- return async (record) => record;
292
- const source = {
293
- linked: (key, o) => node.records.linked(space, key, o),
294
- };
295
- return (record, included) => causeOf(source, record, read, (computed) => {
296
- const subject = { ...record, included, computed };
297
- return matches(subject, query.where ?? {}) && holds(subject);
298
- });
299
- }
300
- /** What a record is called, for `{title}`: its first text among the usual names, or its key */
301
- function titleOf(record) {
302
- const body = isObject(record.body) ? record.body : {};
303
- for (const name of ['title', 'name', 'question', 'text']) {
304
- const value = body[name];
305
- if (typeof value === 'string' && value.trim())
306
- return value.length > 80 ? `${value.slice(0, 79)}…` : value;
307
- }
308
- return record.key;
309
- }
310
- /** `{title}`, and `{<include>}` as a count, filled in */
311
- export function fillAutomationText(text, match, title = titleOf) {
312
- return text.replace(/\{([A-Za-z_][A-Za-z0-9_]*)\}/g, (whole, name) => {
313
- if (!match)
314
- return whole;
315
- if (name === 'title')
316
- return title(match.record);
317
- const value = match.included[name];
318
- if (typeof value === 'number')
319
- return String(value);
320
- if (Array.isArray(value))
321
- return String(value.length);
322
- return whole;
323
- });
324
- }
325
- /** Does what an automation says, as whoever runs it; says what happened */
326
- export async function act(node, trigger, options = {}) {
327
- const { automation: active, match } = trigger;
328
- const at = new Date().toISOString();
329
- const fill = (template) => fillAutomationText(template, match, options.title);
330
- const space = active.space;
331
- const then = active.body.then;
332
- try {
333
- switch (then.kind) {
334
- case 'notify': {
335
- const text = fill(then.text);
336
- const shown = options.notify?.(active.body.name, text, match?.record) ?? false;
337
- return { did: shown ? `Notified: ${text}` : 'Nothing here could notify', ok: shown, at };
338
- }
339
- case 'ask':
340
- if (!options.ask)
341
- return { did: 'Nothing here can ask an agent', ok: false, at };
342
- return { ...(await options.ask(trigger)), at };
343
- case 'add': {
344
- const collections = await node.collections.list(space);
345
- const target = collections.find((c) => c.name === then.collection && c.version !== null);
346
- const thing = (target?.title ?? then.collection.split('.').pop() ?? then.collection).toLowerCase();
347
- const fresh = target ? quickAddBody(target.schema, fill(then.text)) : null;
348
- if (!target || !fresh)
349
- return { did: `This space can't add a ${thing} from a line of text`, ok: false, at };
350
- // Without a record, as when the time set it off, a link to it has nothing to point at.
351
- const links = (then.links ?? []).flatMap((l) => l.to !== IT ? [l] : match ? [{ rel: l.rel, to: match.record.key }] : []);
352
- const made = await node.records.put(space, target.name, fresh, { links });
353
- return { did: `Added a ${thing}: ${fill(then.text)}`, ok: true, at, made: made.key };
354
- }
355
- case 'set': {
356
- const current = match ? await node.records.get(space, match.record.key) : null;
357
- const was = isObject(current?.body) ? current.body : null;
358
- if (!current || !was)
359
- return { did: 'It is not there any more', ok: false, at };
360
- if (!(await node.records.can(space, 'edit', current.key)))
361
- return { did: 'Only whoever made it can change it', ok: false, at };
362
- await node.records.update(space, current.key, { ...was, [then.field]: then.value });
363
- return { did: `${fill('“{title}”')}: set ${then.field} to ${String(then.value)}`, ok: true, at };
364
- }
365
- }
366
- }
367
- catch (error) {
368
- return { did: error instanceof Error ? error.message : String(error), ok: false, at };
369
- }
370
- }
371
- /** Whether someone holds one of these roles; `member` is any place at all, and a founder holds every role's power */
372
- const holdsOneOf = (access, did, names) => {
373
- const member = access?.members.find((one) => one.did === did);
374
- if (!member)
375
- return false;
376
- return member.founder || names.includes('member') || member.roles.some((role) => names.includes(role));
377
- };
378
- /** Whether an automation can run where `options` are: one that asks needs an agent */
379
- const runnable = (active, options) => active.body.then.kind !== 'ask' || !!options.ask;
380
- /**
381
- * The automations in a space that `account` runs, none paused and none whose
382
- * current version an agent wrote: those it made without `by`, and those
383
- * naming it in `by` whose maker may instruct it here (`std.automation/instruct`).
384
- */
385
- export async function automationsFor(node, space, account, access) {
386
- const records = await node.records.list(space, { collection: automation.name });
387
- const active = [];
388
- for (const record of records) {
389
- const maker = record.createdBy;
390
- const body = automationOf(record);
391
- // A key given records only, an agent's, may suggest an automation; it runs once the person saves it themselves.
392
- if (!record.verified || record.recordsOnly || !maker || !body || body.paused)
393
- continue;
394
- if (await runsIt(node, space, account, maker, body.by, access))
395
- active.push({ space, key: record.key, maker, body });
396
- }
397
- return active;
398
- }
399
- /** Whether `account` runs an automation: its own without `by`, or one naming it whose maker may instruct it */
400
- async function runsIt(node, space, account, maker, by, access) {
401
- if (by === undefined)
402
- return maker === account;
403
- if (by !== account)
404
- return false;
405
- if (maker === account)
406
- return true;
407
- const isMember = access?.members.some((member) => member.did === maker) ?? false;
408
- return isMember && node.spaces.may(space, INSTRUCT, {}, maker);
409
- }
410
- /** How many automations in a space an agent wrote for `account`, waiting for the person to save them */
411
- export async function suggestedAutomations(node, space, account) {
412
- const records = await node.records.list(space, { collection: automation.name });
413
- return records.filter((record) => record.createdBy === account && record.recordsOnly).length;
414
- }
415
- const linkTo = (record, rel) => record.links.find((l) => l.rel === rel)?.to;
416
- /** The records each automation has run for, by automation key, and the records automations wrote */
417
- async function runsIn(node, space) {
418
- const by = new Map();
419
- const made = new Set();
420
- for (const run of await node.records.list(space, { collection: automationRun.name })) {
421
- if (isObject(run.body) && typeof run.body.made === 'string')
422
- made.add(run.body.made);
423
- const ran = linkTo(run, 'automation');
424
- const on = linkTo(run, 'about');
425
- if (!ran || !on)
426
- continue;
427
- const seen = by.get(ran) ?? new Set();
428
- by.set(ran, seen.add(on));
429
- }
430
- return { by, made };
431
- }
432
- /**
433
- * Whether this claim is the one that acts. Two devices of one account may both
434
- * claim a record before either hears the other; after a wait, the earlier
435
- * claim (by time, then key) acts and the later is taken back.
436
- */
437
- async function actsFirst(node, space, mine, wait) {
438
- if (wait <= 0)
439
- return true;
440
- await new Promise((resolve) => setTimeout(resolve, wait));
441
- const ran = linkTo(mine, 'automation');
442
- const on = linkTo(mine, 'about');
443
- if (!ran || !on)
444
- return true;
445
- const runs = await node.records.linked(space, on, { rel: 'about', collection: automationRun.name });
446
- const claims = runs.filter((run) => run.links.some((l) => l.rel === 'automation' && l.to === ran));
447
- const earliest = claims.sort((a, b) => a.createdAt.localeCompare(b.createdAt) || a.key.localeCompare(b.key))[0];
448
- if (!earliest || earliest.key === mine.key)
449
- return true;
450
- await node.records.delete(space, mine.key).catch(() => { });
451
- return false;
452
- }
453
- /**
454
- * Runs, once, every automation `account` runs in a space: acts for each record
455
- * an automation newly holds for, and leaves a run for it. `startAutomations`
456
- * calls it when records change; a device can call it itself.
457
- */
458
- export async function runAutomations(node, space, account, options = {}) {
459
- const defined = await definedNames(node, space);
460
- if (!defined.has(automation.name) || !defined.has(automationRun.name))
461
- return;
462
- const access = await node.spaces.access(space).catch(() => undefined);
463
- const rules = (await automationsFor(node, space, account, access)).filter((r) => r.body.when && runnable(r, options));
464
- if (rules.length === 0)
465
- return;
466
- const busy = options.busy ?? new Set();
467
- const { by: runs, made } = await runsIn(node, space);
468
- for (const active of rules) {
469
- const when = active.body.when;
470
- if (!when || !defined.has(nameOf(when.query.collection)))
471
- continue;
472
- const since = Date.parse(active.body.since);
473
- for (const match of await matching(node, space, when, account)) {
474
- const key = match.record.key;
475
- const claim = `${active.key} ${key}`;
476
- const handled = made.has(key) || runs.get(active.key)?.has(key) || busy.has(claim);
477
- if (match.moment < since || handled || !setsOff(match, when, account, access, options.bot))
478
- continue;
479
- busy.add(claim);
480
- try {
481
- await claimAndAct(node, active, match, options, made);
482
- }
483
- finally {
484
- busy.delete(claim);
485
- }
486
- }
487
- }
488
- }
489
- /** Whether whoever made a match hold may set the automation off for its runner */
490
- function setsOff(match, when, account, access, bot) {
491
- const cause = match.cause ?? match.record;
492
- const by = cause.createdBy ?? cause.root;
493
- // What the runner's agent, or the bot, wrote itself never sets an automation off: it would set itself off.
494
- if (by === account && (cause.recordsOnly || bot))
495
- return false;
496
- if (when.from && !holdsOneOf(access, by ?? '', when.from))
497
- return false;
498
- return !(when.others && by === account);
499
- }
500
- /** Claims the record with a run first, so a second look leaves it alone, then acts and fills the run in */
501
- async function claimAndAct(node, active, match, options, made) {
502
- const space = active.space;
503
- const links = [
504
- { rel: 'automation', to: active.key },
505
- { rel: 'about', to: match.record.key },
506
- ];
507
- const claim = { did: 'Running…', ok: true, at: new Date().toISOString() };
508
- const run = await node.records.put(space, automationRun.name, claim, { links });
509
- if (!(await actsFirst(node, space, run, options.claimMs ?? 0)))
510
- return;
511
- const trigger = { automation: active, match };
512
- const done = await act(node, trigger, options);
513
- if (done.made)
514
- made.add(done.made);
515
- await node.records.update(space, run.key, done, { links });
516
- options.onRun?.(trigger, done);
517
- }
518
- /**
519
- * Runs the automations `account` runs, in every space it follows, until stopped:
520
- * once at the start, after each change in a space, and at the times automations
521
- * name. The one loop every runner uses, an app, `minca agent` or a bot.
522
- */
523
- export function startAutomations(node, options) {
524
- const { account } = options;
525
- const busy = options.busy ?? new Set();
526
- const now = options.now ?? (() => new Date());
527
- let stopped = false;
528
- let spaces = [];
529
- /** The automations it runs, by space */
530
- const kept = new Map();
531
- let shown = null;
532
- let running = null;
533
- /** Spaces with a change not yet looked at; null means the list of spaces changed */
534
- const dirty = new Set([null]);
535
- /** The minute each timed automation last ran, so it runs once in it */
536
- const ranAt = new Map();
537
- const allKept = () => [...kept.values()].flat();
538
- async function run() {
539
- while (dirty.size && !stopped) {
540
- const changed = [...dirty];
541
- dirty.clear();
542
- try {
543
- if (!(await look(changed)))
544
- return;
545
- announce();
546
- }
547
- catch (error) {
548
- options.onError?.(error);
549
- }
550
- }
551
- }
552
- /** Runs the automations of the spaces that changed; false when stopped part way */
553
- async function look(changed) {
554
- const everySpace = changed.includes(null);
555
- if (everySpace)
556
- spaces = (await node.spaces.list()).map((space) => space.id);
557
- for (const space of kept.keys())
558
- if (!spaces.includes(space))
559
- kept.delete(space);
560
- const looking = everySpace ? spaces : changed.filter((s) => !!s && spaces.includes(s));
561
- for (const space of looking) {
562
- if (stopped)
563
- return false;
564
- const access = await node.spaces.access(space).catch(() => undefined);
565
- const rules = await automationsFor(node, space, account, access);
566
- kept.set(space, rules.filter((r) => runnable(r, options)));
567
- await runAutomations(node, space, account, { ...options, busy });
568
- }
569
- return true;
570
- }
571
- /** Tells `onRules` the automations it runs, when they changed */
572
- function announce() {
573
- const all = allKept();
574
- const names = all.map((r) => `${r.space}/${r.key}/${r.body.name}`).join();
575
- if (names === shown)
576
- return;
577
- shown = names;
578
- options.onRules?.(all);
579
- }
580
- function kick() {
581
- running ??= run().finally(() => {
582
- running = null;
583
- if (dirty.size && !stopped)
584
- kick();
585
- });
586
- }
587
- /** Runs each timed automation that names this minute, once in it */
588
- function tick() {
589
- const at = now();
590
- const minute = `${at.getFullYear()}-${at.getMonth()}-${at.getDate()} ${at.getHours()}:${at.getMinutes()}`;
591
- for (const active of allKept()) {
592
- const every = active.body.every;
593
- const id = `${active.space}/${active.key}`;
594
- if (!every || ranAt.get(id) === minute || !cronMatches(every, at))
595
- continue;
596
- ranAt.set(id, minute);
597
- const trigger = { automation: active, at };
598
- void act(node, trigger, options).then((done) => options.onRun?.(trigger, done), (error) => options.onError?.(error));
599
- }
600
- }
601
- const unsubscribe = node.subscribe((event) => {
602
- if (event.type === 'spaces' || event.type === 'account')
603
- dirty.add(null);
604
- else if (event.type === 'records')
605
- dirty.add(spaces.includes(event.space) ? event.space : null);
606
- else
607
- return;
608
- kick();
609
- });
610
- kick();
611
- const timer = options.timed === false ? undefined : setInterval(tick, options.tickMs ?? 15_000);
612
- return () => {
613
- stopped = true;
614
- if (timer)
615
- clearInterval(timer);
616
- unsubscribe();
617
- };
618
- }
619
- //# sourceMappingURL=automations.js.map