pyric 0.0.1 → 0.1.0-alpha.7

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 (786) hide show
  1. package/README.md +52 -1
  2. package/dist/app/index.d.ts +81 -0
  3. package/dist/app/index.d.ts.map +1 -0
  4. package/dist/app/index.js +78 -0
  5. package/dist/app/index.js.map +1 -0
  6. package/dist/auth/index.d.ts +346 -0
  7. package/dist/auth/index.d.ts.map +1 -0
  8. package/dist/auth/index.js +701 -0
  9. package/dist/auth/index.js.map +1 -0
  10. package/dist/auth/prod-backend.d.ts +39 -0
  11. package/dist/auth/prod-backend.d.ts.map +1 -0
  12. package/dist/auth/prod-backend.js +179 -0
  13. package/dist/auth/prod-backend.js.map +1 -0
  14. package/dist/auth/providers.d.ts +107 -0
  15. package/dist/auth/providers.d.ts.map +1 -0
  16. package/dist/auth/providers.js +138 -0
  17. package/dist/auth/providers.js.map +1 -0
  18. package/dist/auth/sandbox-backend.d.ts +769 -0
  19. package/dist/auth/sandbox-backend.d.ts.map +1 -0
  20. package/dist/auth/sandbox-backend.js +1598 -0
  21. package/dist/auth/sandbox-backend.js.map +1 -0
  22. package/dist/auth/target.d.ts +40 -0
  23. package/dist/auth/target.d.ts.map +1 -0
  24. package/dist/auth/target.js +28 -0
  25. package/dist/auth/target.js.map +1 -0
  26. package/dist/auth/types.d.ts +252 -0
  27. package/dist/auth/types.d.ts.map +1 -0
  28. package/dist/auth/types.js +26 -0
  29. package/dist/auth/types.js.map +1 -0
  30. package/dist/database/constraints/atoms.d.ts +29 -0
  31. package/dist/database/constraints/atoms.d.ts.map +1 -0
  32. package/dist/database/constraints/atoms.js +43 -0
  33. package/dist/database/constraints/atoms.js.map +1 -0
  34. package/dist/database/constraints/compose.d.ts +16 -0
  35. package/dist/database/constraints/compose.d.ts.map +1 -0
  36. package/dist/database/constraints/compose.js +15 -0
  37. package/dist/database/constraints/compose.js.map +1 -0
  38. package/dist/database/constraints/data.d.ts +30 -0
  39. package/dist/database/constraints/data.d.ts.map +1 -0
  40. package/dist/database/constraints/data.js +46 -0
  41. package/dist/database/constraints/data.js.map +1 -0
  42. package/dist/database/constraints/document.d.ts +42 -0
  43. package/dist/database/constraints/document.d.ts.map +1 -0
  44. package/dist/database/constraints/document.js +86 -0
  45. package/dist/database/constraints/document.js.map +1 -0
  46. package/dist/database/constraints/game.d.ts +30 -0
  47. package/dist/database/constraints/game.d.ts.map +1 -0
  48. package/dist/database/constraints/game.js +49 -0
  49. package/dist/database/constraints/game.js.map +1 -0
  50. package/dist/database/constraints/index.d.ts +12 -0
  51. package/dist/database/constraints/index.d.ts.map +1 -0
  52. package/dist/database/constraints/index.js +9 -0
  53. package/dist/database/constraints/index.js.map +1 -0
  54. package/dist/database/constraints/policies.d.ts +16 -0
  55. package/dist/database/constraints/policies.d.ts.map +1 -0
  56. package/dist/database/constraints/policies.js +17 -0
  57. package/dist/database/constraints/policies.js.map +1 -0
  58. package/dist/database/constraints/ruleset.d.ts +5 -0
  59. package/dist/database/constraints/ruleset.d.ts.map +1 -0
  60. package/dist/database/constraints/ruleset.js +132 -0
  61. package/dist/database/constraints/ruleset.js.map +1 -0
  62. package/dist/database/constraints/schema.d.ts +17 -0
  63. package/dist/database/constraints/schema.d.ts.map +1 -0
  64. package/dist/database/constraints/schema.js +74 -0
  65. package/dist/database/constraints/schema.js.map +1 -0
  66. package/dist/database/constraints/types.d.ts +22 -0
  67. package/dist/database/constraints/types.d.ts.map +1 -0
  68. package/dist/database/constraints/types.js +2 -0
  69. package/dist/database/constraints/types.js.map +1 -0
  70. package/dist/database/crawl/handler.d.ts +7 -0
  71. package/dist/database/crawl/handler.d.ts.map +1 -0
  72. package/dist/database/crawl/handler.js +91 -0
  73. package/dist/database/crawl/handler.js.map +1 -0
  74. package/dist/database/crawl/semaphore.d.ts +9 -0
  75. package/dist/database/crawl/semaphore.d.ts.map +1 -0
  76. package/dist/database/crawl/semaphore.js +27 -0
  77. package/dist/database/crawl/semaphore.js.map +1 -0
  78. package/dist/database/crawl/spec.d.ts +33 -0
  79. package/dist/database/crawl/spec.d.ts.map +1 -0
  80. package/dist/database/crawl/spec.js +12 -0
  81. package/dist/database/crawl/spec.js.map +1 -0
  82. package/dist/database/data/handler.d.ts +9 -0
  83. package/dist/database/data/handler.d.ts.map +1 -0
  84. package/dist/database/data/handler.js +96 -0
  85. package/dist/database/data/handler.js.map +1 -0
  86. package/dist/database/data/spec.d.ts +77 -0
  87. package/dist/database/data/spec.d.ts.map +1 -0
  88. package/dist/database/data/spec.js +17 -0
  89. package/dist/database/data/spec.js.map +1 -0
  90. package/dist/database/data/validated.d.ts +8 -0
  91. package/dist/database/data/validated.d.ts.map +1 -0
  92. package/dist/database/data/validated.js +99 -0
  93. package/dist/database/data/validated.js.map +1 -0
  94. package/dist/database/grammar/RtdbExpr.ohm +98 -0
  95. package/dist/database/grammar/RtdbExpr.ohm.generated.d.ts +2 -0
  96. package/dist/database/grammar/RtdbExpr.ohm.generated.d.ts.map +1 -0
  97. package/dist/database/grammar/RtdbExpr.ohm.generated.js +103 -0
  98. package/dist/database/grammar/RtdbExpr.ohm.generated.js.map +1 -0
  99. package/dist/database/grammar/RtdbExprParser.d.ts +5 -0
  100. package/dist/database/grammar/RtdbExprParser.d.ts.map +1 -0
  101. package/dist/database/grammar/RtdbExprParser.js +53 -0
  102. package/dist/database/grammar/RtdbExprParser.js.map +1 -0
  103. package/dist/database/grammar/linter.d.ts +3 -0
  104. package/dist/database/grammar/linter.d.ts.map +1 -0
  105. package/dist/database/grammar/linter.js +66 -0
  106. package/dist/database/grammar/linter.js.map +1 -0
  107. package/dist/database/grammar/simulator.d.ts +31 -0
  108. package/dist/database/grammar/simulator.d.ts.map +1 -0
  109. package/dist/database/grammar/simulator.js +255 -0
  110. package/dist/database/grammar/simulator.js.map +1 -0
  111. package/dist/database/grammar/validator.d.ts +3 -0
  112. package/dist/database/grammar/validator.d.ts.map +1 -0
  113. package/dist/database/grammar/validator.js +84 -0
  114. package/dist/database/grammar/validator.js.map +1 -0
  115. package/dist/database/host.d.ts +50 -0
  116. package/dist/database/host.d.ts.map +1 -0
  117. package/dist/database/host.js +41 -0
  118. package/dist/database/host.js.map +1 -0
  119. package/dist/database/index.d.ts +40 -0
  120. package/dist/database/index.d.ts.map +1 -0
  121. package/dist/database/index.js +47 -0
  122. package/dist/database/index.js.map +1 -0
  123. package/dist/database/initialize-from-app.d.ts +28 -0
  124. package/dist/database/initialize-from-app.d.ts.map +1 -0
  125. package/dist/database/initialize-from-app.js +23 -0
  126. package/dist/database/initialize-from-app.js.map +1 -0
  127. package/dist/database/ir/handler.d.ts +6 -0
  128. package/dist/database/ir/handler.d.ts.map +1 -0
  129. package/dist/database/ir/handler.js +52 -0
  130. package/dist/database/ir/handler.js.map +1 -0
  131. package/dist/database/ir/spec.d.ts +25 -0
  132. package/dist/database/ir/spec.d.ts.map +1 -0
  133. package/dist/database/ir/spec.js +11 -0
  134. package/dist/database/ir/spec.js.map +1 -0
  135. package/dist/database/mapper.d.ts +9 -0
  136. package/dist/database/mapper.d.ts.map +1 -0
  137. package/dist/database/mapper.js +115 -0
  138. package/dist/database/mapper.js.map +1 -0
  139. package/dist/database/modular.d.ts +604 -0
  140. package/dist/database/modular.d.ts.map +1 -0
  141. package/dist/database/modular.js +1226 -0
  142. package/dist/database/modular.js.map +1 -0
  143. package/dist/database/replay.d.ts +33 -0
  144. package/dist/database/replay.d.ts.map +1 -0
  145. package/dist/database/replay.js +124 -0
  146. package/dist/database/replay.js.map +1 -0
  147. package/dist/database/resolver.d.ts +4 -0
  148. package/dist/database/resolver.d.ts.map +1 -0
  149. package/dist/database/resolver.js +66 -0
  150. package/dist/database/resolver.js.map +1 -0
  151. package/dist/database/sandbox/backend.d.ts +403 -0
  152. package/dist/database/sandbox/backend.d.ts.map +1 -0
  153. package/dist/database/sandbox/backend.js +1467 -0
  154. package/dist/database/sandbox/backend.js.map +1 -0
  155. package/dist/database/sandbox/data-tree.d.ts +123 -0
  156. package/dist/database/sandbox/data-tree.d.ts.map +1 -0
  157. package/dist/database/sandbox/data-tree.js +310 -0
  158. package/dist/database/sandbox/data-tree.js.map +1 -0
  159. package/dist/database/sandbox/normalize.d.ts +77 -0
  160. package/dist/database/sandbox/normalize.d.ts.map +1 -0
  161. package/dist/database/sandbox/normalize.js +165 -0
  162. package/dist/database/sandbox/normalize.js.map +1 -0
  163. package/dist/database/sandbox/push-id.d.ts +32 -0
  164. package/dist/database/sandbox/push-id.d.ts.map +1 -0
  165. package/dist/database/sandbox/push-id.js +82 -0
  166. package/dist/database/sandbox/push-id.js.map +1 -0
  167. package/dist/database/sandbox/query.d.ts +175 -0
  168. package/dist/database/sandbox/query.d.ts.map +1 -0
  169. package/dist/database/sandbox/query.js +269 -0
  170. package/dist/database/sandbox/query.js.map +1 -0
  171. package/dist/database/sandbox/rules-eval.d.ts +69 -0
  172. package/dist/database/sandbox/rules-eval.d.ts.map +1 -0
  173. package/dist/database/sandbox/rules-eval.js +124 -0
  174. package/dist/database/sandbox/rules-eval.js.map +1 -0
  175. package/dist/database/sandbox/sentinels.d.ts +71 -0
  176. package/dist/database/sandbox/sentinels.d.ts.map +1 -0
  177. package/dist/database/sandbox/sentinels.js +92 -0
  178. package/dist/database/sandbox/sentinels.js.map +1 -0
  179. package/dist/database/simulation/handler.d.ts +6 -0
  180. package/dist/database/simulation/handler.d.ts.map +1 -0
  181. package/dist/database/simulation/handler.js +236 -0
  182. package/dist/database/simulation/handler.js.map +1 -0
  183. package/dist/database/simulation/spec.d.ts +69 -0
  184. package/dist/database/simulation/spec.d.ts.map +1 -0
  185. package/dist/database/simulation/spec.js +25 -0
  186. package/dist/database/simulation/spec.js.map +1 -0
  187. package/dist/database/tools.d.ts +22 -0
  188. package/dist/database/tools.d.ts.map +1 -0
  189. package/dist/database/tools.js +272 -0
  190. package/dist/database/tools.js.map +1 -0
  191. package/dist/database/types.d.ts +210 -0
  192. package/dist/database/types.d.ts.map +1 -0
  193. package/dist/database/types.js +26 -0
  194. package/dist/database/types.js.map +1 -0
  195. package/dist/database/write/handler.d.ts +7 -0
  196. package/dist/database/write/handler.d.ts.map +1 -0
  197. package/dist/database/write/handler.js +42 -0
  198. package/dist/database/write/handler.js.map +1 -0
  199. package/dist/database/write/spec.d.ts +18 -0
  200. package/dist/database/write/spec.d.ts.map +1 -0
  201. package/dist/database/write/spec.js +7 -0
  202. package/dist/database/write/spec.js.map +1 -0
  203. package/dist/firestore/index.d.ts +533 -0
  204. package/dist/firestore/index.d.ts.map +1 -0
  205. package/dist/firestore/index.js +1536 -0
  206. package/dist/firestore/index.js.map +1 -0
  207. package/dist/firestore/tools.d.ts +67 -0
  208. package/dist/firestore/tools.d.ts.map +1 -0
  209. package/dist/firestore/tools.js +318 -0
  210. package/dist/firestore/tools.js.map +1 -0
  211. package/dist/firestore-values/index.d.ts +63 -0
  212. package/dist/firestore-values/index.d.ts.map +1 -0
  213. package/dist/firestore-values/index.js +148 -0
  214. package/dist/firestore-values/index.js.map +1 -0
  215. package/dist/project-scope.d.ts +5 -0
  216. package/dist/project-scope.d.ts.map +1 -0
  217. package/dist/project-scope.js +2 -0
  218. package/dist/project-scope.js.map +1 -0
  219. package/dist/rules/extract.d.ts +28 -0
  220. package/dist/rules/extract.d.ts.map +1 -0
  221. package/dist/rules/extract.js +25 -0
  222. package/dist/rules/extract.js.map +1 -0
  223. package/dist/rules/generators/assembler.d.ts +19 -0
  224. package/dist/rules/generators/assembler.d.ts.map +1 -0
  225. package/dist/rules/generators/assembler.js +292 -0
  226. package/dist/rules/generators/assembler.js.map +1 -0
  227. package/dist/rules/generators/expressions.d.ts +52 -0
  228. package/dist/rules/generators/expressions.d.ts.map +1 -0
  229. package/dist/rules/generators/expressions.js +117 -0
  230. package/dist/rules/generators/expressions.js.map +1 -0
  231. package/dist/rules/generators/grid.d.ts +22 -0
  232. package/dist/rules/generators/grid.d.ts.map +1 -0
  233. package/dist/rules/generators/grid.js +52 -0
  234. package/dist/rules/generators/grid.js.map +1 -0
  235. package/dist/rules/grammar/FirestoreAST.d.ts +129 -0
  236. package/dist/rules/grammar/FirestoreAST.d.ts.map +1 -0
  237. package/dist/rules/grammar/FirestoreAST.js +3 -0
  238. package/dist/rules/grammar/FirestoreAST.js.map +1 -0
  239. package/dist/rules/grammar/FirestoreAssembler.d.ts +5 -0
  240. package/dist/rules/grammar/FirestoreAssembler.d.ts.map +1 -0
  241. package/dist/rules/grammar/FirestoreAssembler.js +158 -0
  242. package/dist/rules/grammar/FirestoreAssembler.js.map +1 -0
  243. package/dist/rules/grammar/FirestoreParser.d.ts +46 -0
  244. package/dist/rules/grammar/FirestoreParser.d.ts.map +1 -0
  245. package/dist/rules/grammar/FirestoreParser.js +409 -0
  246. package/dist/rules/grammar/FirestoreParser.js.map +1 -0
  247. package/dist/rules/grammar/FirestoreRules.ohm +229 -0
  248. package/dist/rules/grammar/FirestoreRules.ohm.generated.d.ts +2 -0
  249. package/dist/rules/grammar/FirestoreRules.ohm.generated.d.ts.map +1 -0
  250. package/dist/rules/grammar/FirestoreRules.ohm.generated.js +234 -0
  251. package/dist/rules/grammar/FirestoreRules.ohm.generated.js.map +1 -0
  252. package/dist/rules/grammar/FirestoreValidator.d.ts +10 -0
  253. package/dist/rules/grammar/FirestoreValidator.d.ts.map +1 -0
  254. package/dist/rules/grammar/FirestoreValidator.js +482 -0
  255. package/dist/rules/grammar/FirestoreValidator.js.map +1 -0
  256. package/dist/rules/index.d.ts +67 -0
  257. package/dist/rules/index.d.ts.map +1 -0
  258. package/dist/rules/index.js +80 -0
  259. package/dist/rules/index.js.map +1 -0
  260. package/dist/rules/indexes/extract/annotation-collect.d.ts +42 -0
  261. package/dist/rules/indexes/extract/annotation-collect.d.ts.map +1 -0
  262. package/dist/rules/indexes/extract/annotation-collect.js +69 -0
  263. package/dist/rules/indexes/extract/annotation-collect.js.map +1 -0
  264. package/dist/rules/indexes/extract/annotations.d.ts +50 -0
  265. package/dist/rules/indexes/extract/annotations.d.ts.map +1 -0
  266. package/dist/rules/indexes/extract/annotations.js +144 -0
  267. package/dist/rules/indexes/extract/annotations.js.map +1 -0
  268. package/dist/rules/indexes/extract/ast.d.ts +54 -0
  269. package/dist/rules/indexes/extract/ast.d.ts.map +1 -0
  270. package/dist/rules/indexes/extract/ast.js +119 -0
  271. package/dist/rules/indexes/extract/ast.js.map +1 -0
  272. package/dist/rules/indexes/extract/classify.d.ts +41 -0
  273. package/dist/rules/indexes/extract/classify.d.ts.map +1 -0
  274. package/dist/rules/indexes/extract/classify.js +138 -0
  275. package/dist/rules/indexes/extract/classify.js.map +1 -0
  276. package/dist/rules/indexes/extract/composite.d.ts +38 -0
  277. package/dist/rules/indexes/extract/composite.d.ts.map +1 -0
  278. package/dist/rules/indexes/extract/composite.js +85 -0
  279. package/dist/rules/indexes/extract/composite.js.map +1 -0
  280. package/dist/rules/indexes/extract/dataflow.d.ts +45 -0
  281. package/dist/rules/indexes/extract/dataflow.d.ts.map +1 -0
  282. package/dist/rules/indexes/extract/dataflow.js +200 -0
  283. package/dist/rules/indexes/extract/dataflow.js.map +1 -0
  284. package/dist/rules/indexes/extract/enumerate.d.ts +41 -0
  285. package/dist/rules/indexes/extract/enumerate.d.ts.map +1 -0
  286. package/dist/rules/indexes/extract/enumerate.js +163 -0
  287. package/dist/rules/indexes/extract/enumerate.js.map +1 -0
  288. package/dist/rules/indexes/extract/extractor.d.ts +3 -0
  289. package/dist/rules/indexes/extract/extractor.d.ts.map +1 -0
  290. package/dist/rules/indexes/extract/extractor.js +274 -0
  291. package/dist/rules/indexes/extract/extractor.js.map +1 -0
  292. package/dist/rules/indexes/extract/types.d.ts +211 -0
  293. package/dist/rules/indexes/extract/types.d.ts.map +1 -0
  294. package/dist/rules/indexes/extract/types.js +14 -0
  295. package/dist/rules/indexes/extract/types.js.map +1 -0
  296. package/dist/rules/indexes/extractHandler.d.ts +16 -0
  297. package/dist/rules/indexes/extractHandler.d.ts.map +1 -0
  298. package/dist/rules/indexes/extractHandler.js +100 -0
  299. package/dist/rules/indexes/extractHandler.js.map +1 -0
  300. package/dist/rules/indexes/extractTool.d.ts +15 -0
  301. package/dist/rules/indexes/extractTool.d.ts.map +1 -0
  302. package/dist/rules/indexes/extractTool.js +55 -0
  303. package/dist/rules/indexes/extractTool.js.map +1 -0
  304. package/dist/rules/indexes/types.d.ts +71 -0
  305. package/dist/rules/indexes/types.d.ts.map +1 -0
  306. package/dist/rules/indexes/types.js +15 -0
  307. package/dist/rules/indexes/types.js.map +1 -0
  308. package/dist/rules/inspect/handler.d.ts +6 -0
  309. package/dist/rules/inspect/handler.d.ts.map +1 -0
  310. package/dist/rules/inspect/handler.js +144 -0
  311. package/dist/rules/inspect/handler.js.map +1 -0
  312. package/dist/rules/inspect/spec.d.ts +37 -0
  313. package/dist/rules/inspect/spec.d.ts.map +1 -0
  314. package/dist/rules/inspect/spec.js +2 -0
  315. package/dist/rules/inspect/spec.js.map +1 -0
  316. package/dist/rules/inspect/tools.d.ts +21 -0
  317. package/dist/rules/inspect/tools.d.ts.map +1 -0
  318. package/dist/rules/inspect/tools.js +21 -0
  319. package/dist/rules/inspect/tools.js.map +1 -0
  320. package/dist/rules/linter/ast-utils.d.ts +97 -0
  321. package/dist/rules/linter/ast-utils.d.ts.map +1 -0
  322. package/dist/rules/linter/ast-utils.js +491 -0
  323. package/dist/rules/linter/ast-utils.js.map +1 -0
  324. package/dist/rules/linter/hallucinations.d.ts +34 -0
  325. package/dist/rules/linter/hallucinations.d.ts.map +1 -0
  326. package/dist/rules/linter/hallucinations.js +334 -0
  327. package/dist/rules/linter/hallucinations.js.map +1 -0
  328. package/dist/rules/linter/linter.d.ts +84 -0
  329. package/dist/rules/linter/linter.d.ts.map +1 -0
  330. package/dist/rules/linter/linter.js +784 -0
  331. package/dist/rules/linter/linter.js.map +1 -0
  332. package/dist/rules/modules/resolver-browser.d.ts +41 -0
  333. package/dist/rules/modules/resolver-browser.d.ts.map +1 -0
  334. package/dist/rules/modules/resolver-browser.js +63 -0
  335. package/dist/rules/modules/resolver-browser.js.map +1 -0
  336. package/dist/rules/modules/resolver-core.d.ts +51 -0
  337. package/dist/rules/modules/resolver-core.d.ts.map +1 -0
  338. package/dist/rules/modules/resolver-core.js +338 -0
  339. package/dist/rules/modules/resolver-core.js.map +1 -0
  340. package/dist/rules/modules/resolver.d.ts +17 -0
  341. package/dist/rules/modules/resolver.d.ts.map +1 -0
  342. package/dist/rules/modules/resolver.js +49 -0
  343. package/dist/rules/modules/resolver.js.map +1 -0
  344. package/dist/rules/modules/stdlib/atomic.rules +52 -0
  345. package/dist/rules/modules/stdlib/atomic.test.json +152 -0
  346. package/dist/rules/modules/stdlib/auth.rules +7 -0
  347. package/dist/rules/modules/stdlib/auth.test.json +53 -0
  348. package/dist/rules/modules/stdlib/content.rules +50 -0
  349. package/dist/rules/modules/stdlib/content.test.json +238 -0
  350. package/dist/rules/modules/stdlib/counters.rules +41 -0
  351. package/dist/rules/modules/stdlib/counters.test.json +254 -0
  352. package/dist/rules/modules/stdlib/geometry.rules +43 -0
  353. package/dist/rules/modules/stdlib/geometry.test.json +200 -0
  354. package/dist/rules/modules/stdlib/joining.rules +49 -0
  355. package/dist/rules/modules/stdlib/joining.test.json +287 -0
  356. package/dist/rules/modules/stdlib/lifecycle.rules +51 -0
  357. package/dist/rules/modules/stdlib/lifecycle.test.json +288 -0
  358. package/dist/rules/modules/stdlib/lobby.rules +44 -0
  359. package/dist/rules/modules/stdlib/lobby.test.json +32 -0
  360. package/dist/rules/modules/stdlib/membership.rules +40 -0
  361. package/dist/rules/modules/stdlib/membership.test.json +107 -0
  362. package/dist/rules/modules/stdlib/spaces.rules +46 -0
  363. package/dist/rules/modules/stdlib/spaces.test.json +392 -0
  364. package/dist/rules/modules/stdlib/state.rules +28 -0
  365. package/dist/rules/modules/stdlib/state.test.json +55 -0
  366. package/dist/rules/modules/stdlib/timing.rules +20 -0
  367. package/dist/rules/modules/stdlib/timing.test.json +106 -0
  368. package/dist/rules/modules/stdlib/transitions.rules +34 -0
  369. package/dist/rules/modules/stdlib/transitions.test.json +86 -0
  370. package/dist/rules/modules/stdlib/turns.rules +27 -0
  371. package/dist/rules/modules/stdlib/turns.test.json +64 -0
  372. package/dist/rules/modules/stdlib/validation.rules +31 -0
  373. package/dist/rules/modules/stdlib/validation.test.json +184 -0
  374. package/dist/rules/modules/stdlib-content.d.ts +11 -0
  375. package/dist/rules/modules/stdlib-content.d.ts.map +1 -0
  376. package/dist/rules/modules/stdlib-content.js +590 -0
  377. package/dist/rules/modules/stdlib-content.js.map +1 -0
  378. package/dist/rules/node.d.ts +17 -0
  379. package/dist/rules/node.d.ts.map +1 -0
  380. package/dist/rules/node.js +21 -0
  381. package/dist/rules/node.js.map +1 -0
  382. package/dist/rules/rtdb.d.ts +28 -0
  383. package/dist/rules/rtdb.d.ts.map +1 -0
  384. package/dist/rules/rtdb.js +15 -0
  385. package/dist/rules/rtdb.js.map +1 -0
  386. package/dist/rules/simulator/evaluator.d.ts +179 -0
  387. package/dist/rules/simulator/evaluator.d.ts.map +1 -0
  388. package/dist/rules/simulator/evaluator.js +1221 -0
  389. package/dist/rules/simulator/evaluator.js.map +1 -0
  390. package/dist/rules/simulator/expression/eval-errors.d.ts +86 -0
  391. package/dist/rules/simulator/expression/eval-errors.d.ts.map +1 -0
  392. package/dist/rules/simulator/expression/eval-errors.js +68 -0
  393. package/dist/rules/simulator/expression/eval-errors.js.map +1 -0
  394. package/dist/rules/simulator/expression/evaluator.d.ts +43 -0
  395. package/dist/rules/simulator/expression/evaluator.d.ts.map +1 -0
  396. package/dist/rules/simulator/expression/evaluator.js +298 -0
  397. package/dist/rules/simulator/expression/evaluator.js.map +1 -0
  398. package/dist/rules/simulator/expression/lexer.d.ts +36 -0
  399. package/dist/rules/simulator/expression/lexer.d.ts.map +1 -0
  400. package/dist/rules/simulator/expression/lexer.js +318 -0
  401. package/dist/rules/simulator/expression/lexer.js.map +1 -0
  402. package/dist/rules/simulator/expression/parser.d.ts +39 -0
  403. package/dist/rules/simulator/expression/parser.d.ts.map +1 -0
  404. package/dist/rules/simulator/expression/parser.js +329 -0
  405. package/dist/rules/simulator/expression/parser.js.map +1 -0
  406. package/dist/rules/simulator/expression/types.d.ts +137 -0
  407. package/dist/rules/simulator/expression/types.d.ts.map +1 -0
  408. package/dist/rules/simulator/expression/types.js +90 -0
  409. package/dist/rules/simulator/expression/types.js.map +1 -0
  410. package/dist/rules/simulator/expression/walk-data.d.ts +52 -0
  411. package/dist/rules/simulator/expression/walk-data.d.ts.map +1 -0
  412. package/dist/rules/simulator/expression/walk-data.js +167 -0
  413. package/dist/rules/simulator/expression/walk-data.js.map +1 -0
  414. package/dist/rules/simulator/firestore-set.d.ts +25 -0
  415. package/dist/rules/simulator/firestore-set.d.ts.map +1 -0
  416. package/dist/rules/simulator/firestore-set.js +89 -0
  417. package/dist/rules/simulator/firestore-set.js.map +1 -0
  418. package/dist/rules/simulator/handler.d.ts +36 -0
  419. package/dist/rules/simulator/handler.d.ts.map +1 -0
  420. package/dist/rules/simulator/handler.js +583 -0
  421. package/dist/rules/simulator/handler.js.map +1 -0
  422. package/dist/rules/simulator/mapdiff.d.ts +29 -0
  423. package/dist/rules/simulator/mapdiff.d.ts.map +1 -0
  424. package/dist/rules/simulator/mapdiff.js +72 -0
  425. package/dist/rules/simulator/mapdiff.js.map +1 -0
  426. package/dist/rules/simulator/project-after-state.d.ts +33 -0
  427. package/dist/rules/simulator/project-after-state.d.ts.map +1 -0
  428. package/dist/rules/simulator/project-after-state.js +88 -0
  429. package/dist/rules/simulator/project-after-state.js.map +1 -0
  430. package/dist/rules/simulator/query-proof.d.ts +80 -0
  431. package/dist/rules/simulator/query-proof.d.ts.map +1 -0
  432. package/dist/rules/simulator/query-proof.js +142 -0
  433. package/dist/rules/simulator/query-proof.js.map +1 -0
  434. package/dist/rules/simulator/value-equality.d.ts +8 -0
  435. package/dist/rules/simulator/value-equality.d.ts.map +1 -0
  436. package/dist/rules/simulator/value-equality.js +40 -0
  437. package/dist/rules/simulator/value-equality.js.map +1 -0
  438. package/dist/rules/simulator/wrappers/base.d.ts +129 -0
  439. package/dist/rules/simulator/wrappers/base.d.ts.map +1 -0
  440. package/dist/rules/simulator/wrappers/base.js +90 -0
  441. package/dist/rules/simulator/wrappers/base.js.map +1 -0
  442. package/dist/rules/simulator/wrappers/bytes.d.ts +45 -0
  443. package/dist/rules/simulator/wrappers/bytes.d.ts.map +1 -0
  444. package/dist/rules/simulator/wrappers/bytes.js +130 -0
  445. package/dist/rules/simulator/wrappers/bytes.js.map +1 -0
  446. package/dist/rules/simulator/wrappers/duration.d.ts +76 -0
  447. package/dist/rules/simulator/wrappers/duration.d.ts.map +1 -0
  448. package/dist/rules/simulator/wrappers/duration.js +176 -0
  449. package/dist/rules/simulator/wrappers/duration.js.map +1 -0
  450. package/dist/rules/simulator/wrappers/float.d.ts +52 -0
  451. package/dist/rules/simulator/wrappers/float.d.ts.map +1 -0
  452. package/dist/rules/simulator/wrappers/float.js +88 -0
  453. package/dist/rules/simulator/wrappers/float.js.map +1 -0
  454. package/dist/rules/simulator/wrappers/latlng.d.ts +40 -0
  455. package/dist/rules/simulator/wrappers/latlng.d.ts.map +1 -0
  456. package/dist/rules/simulator/wrappers/latlng.js +100 -0
  457. package/dist/rules/simulator/wrappers/latlng.js.map +1 -0
  458. package/dist/rules/simulator/wrappers/path.d.ts +75 -0
  459. package/dist/rules/simulator/wrappers/path.d.ts.map +1 -0
  460. package/dist/rules/simulator/wrappers/path.js +158 -0
  461. package/dist/rules/simulator/wrappers/path.js.map +1 -0
  462. package/dist/rules/simulator/wrappers/reference.d.ts +82 -0
  463. package/dist/rules/simulator/wrappers/reference.d.ts.map +1 -0
  464. package/dist/rules/simulator/wrappers/reference.js +145 -0
  465. package/dist/rules/simulator/wrappers/reference.js.map +1 -0
  466. package/dist/rules/simulator/wrappers/timestamp.d.ts +86 -0
  467. package/dist/rules/simulator/wrappers/timestamp.d.ts.map +1 -0
  468. package/dist/rules/simulator/wrappers/timestamp.js +207 -0
  469. package/dist/rules/simulator/wrappers/timestamp.js.map +1 -0
  470. package/dist/rules/simulator/wrappers/vector.d.ts +43 -0
  471. package/dist/rules/simulator/wrappers/vector.d.ts.map +1 -0
  472. package/dist/rules/simulator/wrappers/vector.js +80 -0
  473. package/dist/rules/simulator/wrappers/vector.js.map +1 -0
  474. package/dist/rules/simulator-tools-impl.d.ts +64 -0
  475. package/dist/rules/simulator-tools-impl.d.ts.map +1 -0
  476. package/dist/rules/simulator-tools-impl.js +462 -0
  477. package/dist/rules/simulator-tools-impl.js.map +1 -0
  478. package/dist/rules/simulator.d.ts +20 -0
  479. package/dist/rules/simulator.d.ts.map +1 -0
  480. package/dist/rules/simulator.js +24 -0
  481. package/dist/rules/simulator.js.map +1 -0
  482. package/dist/rules/stdlib-modules.d.ts +73 -0
  483. package/dist/rules/stdlib-modules.d.ts.map +1 -0
  484. package/dist/rules/stdlib-modules.js +849 -0
  485. package/dist/rules/stdlib-modules.js.map +1 -0
  486. package/dist/rules/stdlib-tools.d.ts +19 -0
  487. package/dist/rules/stdlib-tools.d.ts.map +1 -0
  488. package/dist/rules/stdlib-tools.js +164 -0
  489. package/dist/rules/stdlib-tools.js.map +1 -0
  490. package/dist/rules/test/handler.d.ts +9 -0
  491. package/dist/rules/test/handler.d.ts.map +1 -0
  492. package/dist/rules/test/handler.js +124 -0
  493. package/dist/rules/test/handler.js.map +1 -0
  494. package/dist/rules/test/spec.d.ts +517 -0
  495. package/dist/rules/test/spec.d.ts.map +1 -0
  496. package/dist/rules/test/spec.js +227 -0
  497. package/dist/rules/test/spec.js.map +1 -0
  498. package/dist/rules/tools.d.ts +41 -0
  499. package/dist/rules/tools.d.ts.map +1 -0
  500. package/dist/rules/tools.js +124 -0
  501. package/dist/rules/tools.js.map +1 -0
  502. package/dist/rules/write/handler.d.ts +6 -0
  503. package/dist/rules/write/handler.d.ts.map +1 -0
  504. package/dist/rules/write/handler.js +126 -0
  505. package/dist/rules/write/handler.js.map +1 -0
  506. package/dist/rules/write/spec.d.ts +28 -0
  507. package/dist/rules/write/spec.d.ts.map +1 -0
  508. package/dist/rules/write/spec.js +2 -0
  509. package/dist/rules/write/spec.js.map +1 -0
  510. package/dist/sandbox/admin-compat.d.ts +20 -0
  511. package/dist/sandbox/admin-compat.d.ts.map +1 -0
  512. package/dist/sandbox/admin-compat.js +19 -0
  513. package/dist/sandbox/admin-compat.js.map +1 -0
  514. package/dist/sandbox/admin-firestore/error-translation.d.ts +86 -0
  515. package/dist/sandbox/admin-firestore/error-translation.d.ts.map +1 -0
  516. package/dist/sandbox/admin-firestore/error-translation.js +204 -0
  517. package/dist/sandbox/admin-firestore/error-translation.js.map +1 -0
  518. package/dist/sandbox/admin-firestore/index.d.ts +169 -0
  519. package/dist/sandbox/admin-firestore/index.d.ts.map +1 -0
  520. package/dist/sandbox/admin-firestore/index.js +456 -0
  521. package/dist/sandbox/admin-firestore/index.js.map +1 -0
  522. package/dist/sandbox/admin-firestore/remote.d.ts +97 -0
  523. package/dist/sandbox/admin-firestore/remote.d.ts.map +1 -0
  524. package/dist/sandbox/admin-firestore/remote.js +735 -0
  525. package/dist/sandbox/admin-firestore/remote.js.map +1 -0
  526. package/dist/sandbox/branches/index.d.ts +141 -0
  527. package/dist/sandbox/branches/index.d.ts.map +1 -0
  528. package/dist/sandbox/branches/index.js +327 -0
  529. package/dist/sandbox/branches/index.js.map +1 -0
  530. package/dist/sandbox/firestore/admin-compat/batch.d.ts +34 -0
  531. package/dist/sandbox/firestore/admin-compat/batch.d.ts.map +1 -0
  532. package/dist/sandbox/firestore/admin-compat/batch.js +73 -0
  533. package/dist/sandbox/firestore/admin-compat/batch.js.map +1 -0
  534. package/dist/sandbox/firestore/admin-compat/doc-ref.d.ts +38 -0
  535. package/dist/sandbox/firestore/admin-compat/doc-ref.d.ts.map +1 -0
  536. package/dist/sandbox/firestore/admin-compat/doc-ref.js +154 -0
  537. package/dist/sandbox/firestore/admin-compat/doc-ref.js.map +1 -0
  538. package/dist/sandbox/firestore/admin-compat/firestore.d.ts +45 -0
  539. package/dist/sandbox/firestore/admin-compat/firestore.d.ts.map +1 -0
  540. package/dist/sandbox/firestore/admin-compat/firestore.js +114 -0
  541. package/dist/sandbox/firestore/admin-compat/firestore.js.map +1 -0
  542. package/dist/sandbox/firestore/admin-compat/index.d.ts +45 -0
  543. package/dist/sandbox/firestore/admin-compat/index.d.ts.map +1 -0
  544. package/dist/sandbox/firestore/admin-compat/index.js +27 -0
  545. package/dist/sandbox/firestore/admin-compat/index.js.map +1 -0
  546. package/dist/sandbox/firestore/admin-compat/paths.d.ts +37 -0
  547. package/dist/sandbox/firestore/admin-compat/paths.d.ts.map +1 -0
  548. package/dist/sandbox/firestore/admin-compat/paths.js +49 -0
  549. package/dist/sandbox/firestore/admin-compat/paths.js.map +1 -0
  550. package/dist/sandbox/firestore/admin-compat/query.d.ts +261 -0
  551. package/dist/sandbox/firestore/admin-compat/query.d.ts.map +1 -0
  552. package/dist/sandbox/firestore/admin-compat/query.js +704 -0
  553. package/dist/sandbox/firestore/admin-compat/query.js.map +1 -0
  554. package/dist/sandbox/firestore/admin-compat/read-translation.d.ts +8 -0
  555. package/dist/sandbox/firestore/admin-compat/read-translation.d.ts.map +1 -0
  556. package/dist/sandbox/firestore/admin-compat/read-translation.js +59 -0
  557. package/dist/sandbox/firestore/admin-compat/read-translation.js.map +1 -0
  558. package/dist/sandbox/firestore/admin-compat/snapshots.d.ts +39 -0
  559. package/dist/sandbox/firestore/admin-compat/snapshots.d.ts.map +1 -0
  560. package/dist/sandbox/firestore/admin-compat/snapshots.js +50 -0
  561. package/dist/sandbox/firestore/admin-compat/snapshots.js.map +1 -0
  562. package/dist/sandbox/firestore/admin-compat/transaction.d.ts +35 -0
  563. package/dist/sandbox/firestore/admin-compat/transaction.d.ts.map +1 -0
  564. package/dist/sandbox/firestore/admin-compat/transaction.js +88 -0
  565. package/dist/sandbox/firestore/admin-compat/transaction.js.map +1 -0
  566. package/dist/sandbox/firestore/admin-compat/types.d.ts +297 -0
  567. package/dist/sandbox/firestore/admin-compat/types.d.ts.map +1 -0
  568. package/dist/sandbox/firestore/admin-compat/types.js +127 -0
  569. package/dist/sandbox/firestore/admin-compat/types.js.map +1 -0
  570. package/dist/sandbox/firestore/admin-compat/value-order.d.ts +49 -0
  571. package/dist/sandbox/firestore/admin-compat/value-order.d.ts.map +1 -0
  572. package/dist/sandbox/firestore/admin-compat/value-order.js +172 -0
  573. package/dist/sandbox/firestore/admin-compat/value-order.js.map +1 -0
  574. package/dist/sandbox/firestore/auto-id.d.ts +26 -0
  575. package/dist/sandbox/firestore/auto-id.d.ts.map +1 -0
  576. package/dist/sandbox/firestore/auto-id.js +36 -0
  577. package/dist/sandbox/firestore/auto-id.js.map +1 -0
  578. package/dist/sandbox/firestore/converters/bytes-geopoint.d.ts +48 -0
  579. package/dist/sandbox/firestore/converters/bytes-geopoint.d.ts.map +1 -0
  580. package/dist/sandbox/firestore/converters/bytes-geopoint.js +85 -0
  581. package/dist/sandbox/firestore/converters/bytes-geopoint.js.map +1 -0
  582. package/dist/sandbox/firestore/converters/fieldvalue.d.ts +69 -0
  583. package/dist/sandbox/firestore/converters/fieldvalue.d.ts.map +1 -0
  584. package/dist/sandbox/firestore/converters/fieldvalue.js +166 -0
  585. package/dist/sandbox/firestore/converters/fieldvalue.js.map +1 -0
  586. package/dist/sandbox/firestore/converters/reference.d.ts +31 -0
  587. package/dist/sandbox/firestore/converters/reference.d.ts.map +1 -0
  588. package/dist/sandbox/firestore/converters/reference.js +51 -0
  589. package/dist/sandbox/firestore/converters/reference.js.map +1 -0
  590. package/dist/sandbox/firestore/converters/timestamp.d.ts +32 -0
  591. package/dist/sandbox/firestore/converters/timestamp.d.ts.map +1 -0
  592. package/dist/sandbox/firestore/converters/timestamp.js +63 -0
  593. package/dist/sandbox/firestore/converters/timestamp.js.map +1 -0
  594. package/dist/sandbox/firestore/converters/user-timestamp.d.ts +46 -0
  595. package/dist/sandbox/firestore/converters/user-timestamp.d.ts.map +1 -0
  596. package/dist/sandbox/firestore/converters/user-timestamp.js +65 -0
  597. package/dist/sandbox/firestore/converters/user-timestamp.js.map +1 -0
  598. package/dist/sandbox/firestore/converters/vector.d.ts +24 -0
  599. package/dist/sandbox/firestore/converters/vector.d.ts.map +1 -0
  600. package/dist/sandbox/firestore/converters/vector.js +53 -0
  601. package/dist/sandbox/firestore/converters/vector.js.map +1 -0
  602. package/dist/sandbox/firestore/errors.d.ts +82 -0
  603. package/dist/sandbox/firestore/errors.d.ts.map +1 -0
  604. package/dist/sandbox/firestore/errors.js +54 -0
  605. package/dist/sandbox/firestore/errors.js.map +1 -0
  606. package/dist/sandbox/firestore/event-log.d.ts +99 -0
  607. package/dist/sandbox/firestore/event-log.d.ts.map +1 -0
  608. package/dist/sandbox/firestore/event-log.js +67 -0
  609. package/dist/sandbox/firestore/event-log.js.map +1 -0
  610. package/dist/sandbox/firestore/field-merge.d.ts +64 -0
  611. package/dist/sandbox/firestore/field-merge.d.ts.map +1 -0
  612. package/dist/sandbox/firestore/field-merge.js +221 -0
  613. package/dist/sandbox/firestore/field-merge.js.map +1 -0
  614. package/dist/sandbox/firestore/list-query-proof.d.ts +77 -0
  615. package/dist/sandbox/firestore/list-query-proof.d.ts.map +1 -0
  616. package/dist/sandbox/firestore/list-query-proof.js +170 -0
  617. package/dist/sandbox/firestore/list-query-proof.js.map +1 -0
  618. package/dist/sandbox/firestore/local-environment.d.ts +806 -0
  619. package/dist/sandbox/firestore/local-environment.d.ts.map +1 -0
  620. package/dist/sandbox/firestore/local-environment.js +3028 -0
  621. package/dist/sandbox/firestore/local-environment.js.map +1 -0
  622. package/dist/sandbox/firestore/local-state.d.ts +196 -0
  623. package/dist/sandbox/firestore/local-state.d.ts.map +1 -0
  624. package/dist/sandbox/firestore/local-state.js +413 -0
  625. package/dist/sandbox/firestore/local-state.js.map +1 -0
  626. package/dist/sandbox/firestore/overlay-backing.d.ts +44 -0
  627. package/dist/sandbox/firestore/overlay-backing.d.ts.map +1 -0
  628. package/dist/sandbox/firestore/overlay-backing.js +82 -0
  629. package/dist/sandbox/firestore/overlay-backing.js.map +1 -0
  630. package/dist/sandbox/firestore/sentinel-capture.d.ts +30 -0
  631. package/dist/sandbox/firestore/sentinel-capture.d.ts.map +1 -0
  632. package/dist/sandbox/firestore/sentinel-capture.js +61 -0
  633. package/dist/sandbox/firestore/sentinel-capture.js.map +1 -0
  634. package/dist/sandbox/firestore/snapshot-listeners.d.ts +284 -0
  635. package/dist/sandbox/firestore/snapshot-listeners.d.ts.map +1 -0
  636. package/dist/sandbox/firestore/snapshot-listeners.js +194 -0
  637. package/dist/sandbox/firestore/snapshot-listeners.js.map +1 -0
  638. package/dist/sandbox/firestore/topk.d.ts +12 -0
  639. package/dist/sandbox/firestore/topk.d.ts.map +1 -0
  640. package/dist/sandbox/firestore/topk.js +42 -0
  641. package/dist/sandbox/firestore/topk.js.map +1 -0
  642. package/dist/sandbox/firestore/transaction-merge.d.ts +55 -0
  643. package/dist/sandbox/firestore/transaction-merge.d.ts.map +1 -0
  644. package/dist/sandbox/firestore/transaction-merge.js +107 -0
  645. package/dist/sandbox/firestore/transaction-merge.js.map +1 -0
  646. package/dist/sandbox/firestore/transaction-types.d.ts +152 -0
  647. package/dist/sandbox/firestore/transaction-types.d.ts.map +1 -0
  648. package/dist/sandbox/firestore/transaction-types.js +10 -0
  649. package/dist/sandbox/firestore/transaction-types.js.map +1 -0
  650. package/dist/sandbox/firestore/transaction.d.ts +79 -0
  651. package/dist/sandbox/firestore/transaction.d.ts.map +1 -0
  652. package/dist/sandbox/firestore/transaction.js +95 -0
  653. package/dist/sandbox/firestore/transaction.js.map +1 -0
  654. package/dist/sandbox/firestore/value-equality.d.ts +2 -0
  655. package/dist/sandbox/firestore/value-equality.d.ts.map +1 -0
  656. package/dist/sandbox/firestore/value-equality.js +35 -0
  657. package/dist/sandbox/firestore/value-equality.js.map +1 -0
  658. package/dist/sandbox/firestore/value-resolver.d.ts +172 -0
  659. package/dist/sandbox/firestore/value-resolver.d.ts.map +1 -0
  660. package/dist/sandbox/firestore/value-resolver.js +221 -0
  661. package/dist/sandbox/firestore/value-resolver.js.map +1 -0
  662. package/dist/sandbox/firestore/wire-encoder.d.ts +14 -0
  663. package/dist/sandbox/firestore/wire-encoder.d.ts.map +1 -0
  664. package/dist/sandbox/firestore/wire-encoder.js +130 -0
  665. package/dist/sandbox/firestore/wire-encoder.js.map +1 -0
  666. package/dist/sandbox/index.d.ts +50 -0
  667. package/dist/sandbox/index.d.ts.map +1 -0
  668. package/dist/sandbox/index.js +63 -0
  669. package/dist/sandbox/index.js.map +1 -0
  670. package/dist/sandbox/internal/index.d.ts +36 -0
  671. package/dist/sandbox/internal/index.d.ts.map +1 -0
  672. package/dist/sandbox/internal/index.js +72 -0
  673. package/dist/sandbox/internal/index.js.map +1 -0
  674. package/dist/sandbox/internal/sandbox-impl.d.ts +343 -0
  675. package/dist/sandbox/internal/sandbox-impl.d.ts.map +1 -0
  676. package/dist/sandbox/internal/sandbox-impl.js +718 -0
  677. package/dist/sandbox/internal/sandbox-impl.js.map +1 -0
  678. package/dist/sandbox/persistence/backends.d.ts +37 -0
  679. package/dist/sandbox/persistence/backends.d.ts.map +1 -0
  680. package/dist/sandbox/persistence/backends.js +202 -0
  681. package/dist/sandbox/persistence/backends.js.map +1 -0
  682. package/dist/sandbox/persistence/chunk-format.d.ts +58 -0
  683. package/dist/sandbox/persistence/chunk-format.d.ts.map +1 -0
  684. package/dist/sandbox/persistence/chunk-format.js +163 -0
  685. package/dist/sandbox/persistence/chunk-format.js.map +1 -0
  686. package/dist/sandbox/persistence/controller.d.ts +39 -0
  687. package/dist/sandbox/persistence/controller.d.ts.map +1 -0
  688. package/dist/sandbox/persistence/controller.js +605 -0
  689. package/dist/sandbox/persistence/controller.js.map +1 -0
  690. package/dist/sandbox/persistence/index.d.ts +13 -0
  691. package/dist/sandbox/persistence/index.d.ts.map +1 -0
  692. package/dist/sandbox/persistence/index.js +5 -0
  693. package/dist/sandbox/persistence/index.js.map +1 -0
  694. package/dist/sandbox/persistence/serialize.d.ts +53 -0
  695. package/dist/sandbox/persistence/serialize.d.ts.map +1 -0
  696. package/dist/sandbox/persistence/serialize.js +98 -0
  697. package/dist/sandbox/persistence/serialize.js.map +1 -0
  698. package/dist/sandbox/persistence/types.d.ts +118 -0
  699. package/dist/sandbox/persistence/types.d.ts.map +1 -0
  700. package/dist/sandbox/persistence/types.js +15 -0
  701. package/dist/sandbox/persistence/types.js.map +1 -0
  702. package/dist/sandbox/remote.d.ts +118 -0
  703. package/dist/sandbox/remote.d.ts.map +1 -0
  704. package/dist/sandbox/remote.js +60 -0
  705. package/dist/sandbox/remote.js.map +1 -0
  706. package/dist/sandbox/replay/index.d.ts +106 -0
  707. package/dist/sandbox/replay/index.d.ts.map +1 -0
  708. package/dist/sandbox/replay/index.js +246 -0
  709. package/dist/sandbox/replay/index.js.map +1 -0
  710. package/dist/sandbox/sandbox-context.d.ts +40 -0
  711. package/dist/sandbox/sandbox-context.d.ts.map +1 -0
  712. package/dist/sandbox/sandbox-context.js +72 -0
  713. package/dist/sandbox/sandbox-context.js.map +1 -0
  714. package/dist/sandbox/tab-sync/index.d.ts +120 -0
  715. package/dist/sandbox/tab-sync/index.d.ts.map +1 -0
  716. package/dist/sandbox/tab-sync/index.js +272 -0
  717. package/dist/sandbox/tab-sync/index.js.map +1 -0
  718. package/dist/sandbox/types.d.ts +1235 -0
  719. package/dist/sandbox/types.d.ts.map +1 -0
  720. package/dist/sandbox/types.js +46 -0
  721. package/dist/sandbox/types.js.map +1 -0
  722. package/dist/storage/admin/api.d.ts +206 -0
  723. package/dist/storage/admin/api.d.ts.map +1 -0
  724. package/dist/storage/admin/api.js +349 -0
  725. package/dist/storage/admin/api.js.map +1 -0
  726. package/dist/storage/admin/handler.d.ts +29 -0
  727. package/dist/storage/admin/handler.d.ts.map +1 -0
  728. package/dist/storage/admin/handler.js +82 -0
  729. package/dist/storage/admin/handler.js.map +1 -0
  730. package/dist/storage/admin/spec.d.ts +64 -0
  731. package/dist/storage/admin/spec.d.ts.map +1 -0
  732. package/dist/storage/admin/spec.js +8 -0
  733. package/dist/storage/admin/spec.js.map +1 -0
  734. package/dist/storage/admin/tools.d.ts +23 -0
  735. package/dist/storage/admin/tools.d.ts.map +1 -0
  736. package/dist/storage/admin/tools.js +90 -0
  737. package/dist/storage/admin/tools.js.map +1 -0
  738. package/dist/storage/download.d.ts +27 -0
  739. package/dist/storage/download.d.ts.map +1 -0
  740. package/dist/storage/download.js +136 -0
  741. package/dist/storage/download.js.map +1 -0
  742. package/dist/storage/enforce.d.ts +26 -0
  743. package/dist/storage/enforce.d.ts.map +1 -0
  744. package/dist/storage/enforce.js +16 -0
  745. package/dist/storage/enforce.js.map +1 -0
  746. package/dist/storage/errors.d.ts +46 -0
  747. package/dist/storage/errors.d.ts.map +1 -0
  748. package/dist/storage/errors.js +62 -0
  749. package/dist/storage/errors.js.map +1 -0
  750. package/dist/storage/index.d.ts +49 -0
  751. package/dist/storage/index.d.ts.map +1 -0
  752. package/dist/storage/index.js +60 -0
  753. package/dist/storage/index.js.map +1 -0
  754. package/dist/storage/internal.d.ts +18 -0
  755. package/dist/storage/internal.d.ts.map +1 -0
  756. package/dist/storage/internal.js +18 -0
  757. package/dist/storage/internal.js.map +1 -0
  758. package/dist/storage/list.d.ts +17 -0
  759. package/dist/storage/list.d.ts.map +1 -0
  760. package/dist/storage/list.js +91 -0
  761. package/dist/storage/list.js.map +1 -0
  762. package/dist/storage/metadata.d.ts +86 -0
  763. package/dist/storage/metadata.d.ts.map +1 -0
  764. package/dist/storage/metadata.js +167 -0
  765. package/dist/storage/metadata.js.map +1 -0
  766. package/dist/storage/persistence.d.ts +134 -0
  767. package/dist/storage/persistence.d.ts.map +1 -0
  768. package/dist/storage/persistence.js +132 -0
  769. package/dist/storage/persistence.js.map +1 -0
  770. package/dist/storage/reference.d.ts +63 -0
  771. package/dist/storage/reference.d.ts.map +1 -0
  772. package/dist/storage/reference.js +156 -0
  773. package/dist/storage/reference.js.map +1 -0
  774. package/dist/storage/rules.d.ts +176 -0
  775. package/dist/storage/rules.d.ts.map +1 -0
  776. package/dist/storage/rules.js +621 -0
  777. package/dist/storage/rules.js.map +1 -0
  778. package/dist/storage/service.d.ts +139 -0
  779. package/dist/storage/service.d.ts.map +1 -0
  780. package/dist/storage/service.js +241 -0
  781. package/dist/storage/service.js.map +1 -0
  782. package/dist/storage/upload.d.ts +43 -0
  783. package/dist/storage/upload.d.ts.map +1 -0
  784. package/dist/storage/upload.js +235 -0
  785. package/dist/storage/upload.js.map +1 -0
  786. package/package.json +109 -3
@@ -0,0 +1,718 @@
1
+ /**
2
+ * Internal `Sandbox` implementation — backs the public interface from
3
+ * `/app` and exposes the hook (`getEnv`) that other in-package modules
4
+ * (notably `/firestore`) need to reach the underlying
5
+ * `LocalEnvironment`.
6
+ *
7
+ * Not in the package's `exports` map — external consumers can't import
8
+ * this module. Internal modules can because workspace path resolution
9
+ * doesn't go through the exports gate.
10
+ *
11
+ * Why a class plus a private accessor: `/app` keeps its dependency
12
+ * direction clean by exposing only the `Sandbox` interface. Service
13
+ * modules need `LocalEnvironment` access but should not couple to
14
+ * `/app`'s implementation; they read it through {@link getEnv}.
15
+ *
16
+ * The class is identity-agnostic per the multi-context redesign — it
17
+ * holds the env, listener registries, and lifecycle. Identity belongs
18
+ * to {@link SandboxContext}, derived via `withAuth`.
19
+ */
20
+ import { LocalEnvironment } from '../firestore/local-environment.js';
21
+ import { SandboxError } from '../types.js';
22
+ import { SandboxContextImpl, validateAuthState } from '../sandbox-context.js';
23
+ import { attachPersistence, } from '../persistence/controller.js';
24
+ import { attachTabSync } from '../tab-sync/index.js';
25
+ let nextSandboxEventId = 1;
26
+ function makeSandboxEventId() {
27
+ const seq = (nextSandboxEventId++).toString(36);
28
+ const rnd = Math.random().toString(36).slice(2, 7);
29
+ return `sbe-${seq}-${rnd}`;
30
+ }
31
+ /**
32
+ * Stamp {@link EventProvenance} onto a `SandboxEvent` in ONE place — the
33
+ * single choke-point every emitter routes through (see {@link
34
+ * SandboxImpl.emitEvent}). This is the Pyric Studio "event unification"
35
+ * keystone: today only Firestore emits, but every service's emit path is
36
+ * meant to funnel here so the unified `onEvent`/`history()` stream carries
37
+ * who/what/which-service for each event.
38
+ *
39
+ * Semantics — **additive, override-aware, no clobber**:
40
+ * - `service` defaults to `'firestore'` (the only emitter today). An
41
+ * Auth/Storage/RTDB emit site passes its own service via
42
+ * `overrides.service`; a value already on the event is kept.
43
+ * - `actor` defaults to `{ kind: 'app' }` (the served app). Studio /
44
+ * agent / app-builder emitters override.
45
+ * - `authLens` defaults to `{ mode: 'app-session' }` (the app's own
46
+ * signed-in user). Admin / impersonation paths override.
47
+ * - `planId` only set when an override supplies it (agent-plan ops).
48
+ *
49
+ * A field the event ALREADY carries always wins over the default — so an
50
+ * upstream emitter that pre-stamped provenance is never downgraded. The
51
+ * returned object is a shallow copy; the input is not mutated.
52
+ */
53
+ export function stampProvenance(event, overrides) {
54
+ const out = { ...event };
55
+ out.service = event.service ?? overrides?.service ?? 'firestore';
56
+ out.actor = event.actor ?? overrides?.actor ?? { kind: 'app' };
57
+ out.authLens = event.authLens ?? overrides?.authLens ?? { mode: 'app-session' };
58
+ const planId = event.planId ?? overrides?.planId;
59
+ if (planId !== undefined)
60
+ out.planId = planId;
61
+ return out;
62
+ }
63
+ /**
64
+ * Concrete `Sandbox`. Holds the live `LocalEnvironment` directly and
65
+ * swaps it on `reset()`. Existing `SandboxContext`s continue to work
66
+ * after reset because they hold a reference to *this* sandbox object,
67
+ * not to a particular env — the next operation calls back through
68
+ * `getEnv()` and gets whatever env is current.
69
+ *
70
+ * Subscriber registries (`onDenial` / `onSnapshotError` / `onRequest`)
71
+ * live on the sandbox, NOT on `LocalEnvironment`. `reset()` swaps the
72
+ * env without invalidating user callbacks — see #307 probe (E7) for
73
+ * the bug that motivated this layout. The sandbox installs ONE adapter
74
+ * subscription per channel on the current env that fans out to the
75
+ * user registry; on swap, the adapter subscriptions get re-attached
76
+ * to the new env while user callbacks stay put.
77
+ */
78
+ export class SandboxImpl {
79
+ _env;
80
+ /** User callbacks; stable across `reset()`. */
81
+ eventSubs = new Set();
82
+ /** Adapter unsubscribers for the current env; refreshed on reset. */
83
+ envUnsubs = [];
84
+ /** Monotonic — surfaced on session_boundary events so consumers can
85
+ * segment a persisted stream. Increments on every dispatched event. */
86
+ dispatchedCount = 0;
87
+ /** Append-only history of every SandboxEvent emitted on this sandbox.
88
+ * Cleared on `reset()` AFTER the session_boundary event is appended,
89
+ * so the boundary is the last entry of the old session's history.
90
+ * v1 doesn't cap; consumers persist the snapshot they need. */
91
+ eventHistory = [];
92
+ /** Ambient provenance for the current {@link runWithProvenance} window
93
+ * (undefined outside any window). Purely synchronous — set on entry,
94
+ * restored in `finally` — so deferred work (microtask listener drains)
95
+ * never observes a window it didn't open. */
96
+ ambientProvenance;
97
+ /**
98
+ * Currently authenticated user. Mutated by `pyric/auth` (and any
99
+ * future stateful identity bridge). Read per-call by service
100
+ * factories that want to see auth changes without re-binding.
101
+ * Defaults to `null` (anonymous / signed out).
102
+ */
103
+ _currentUser = null;
104
+ /** Subscribers to currentUser changes. Stable across reset() and
105
+ * dispose() the same way `eventSubs` is — dispose clears them. */
106
+ currentUserSubs = new Set();
107
+ /** Persistence controller. Null until `enablePersistence` is called.
108
+ * Survives `reset()` so the next write re-flushes the empty state;
109
+ * cleared by `dispose()` so the sandbox releases its event listeners. */
110
+ persistence = null;
111
+ /** In-flight `enablePersistence` call. Awaiting this lets concurrent
112
+ * enable calls share the same attach work (and same restored state)
113
+ * rather than racing two restores. */
114
+ enablePersistencePromise = null;
115
+ /**
116
+ * Persistable-service registry. Each entry is one service (auth,
117
+ * storage, …) that contributes its own state to the sandbox snapshot.
118
+ * The sandbox stays service-agnostic: it just calls `snapshot()` /
119
+ * `restore()` and defers the shape entirely to each service.
120
+ *
121
+ * Cleared in `dispose()`. The controller is notified via
122
+ * `_onServiceRegistered` whenever a new entry arrives so it can
123
+ * subscribe the service's change notifications without requiring the
124
+ * service to register BEFORE `enablePersistence` is called.
125
+ */
126
+ serviceRegistry = new Map();
127
+ /**
128
+ * Optional callback set by the persistence controller so it learns
129
+ * about services registered AFTER `enablePersistence`. Supports the
130
+ * late-registration case: `enablePersistence` then later `getAuth()`
131
+ * (which registers 'auth'). The controller wires up the subscribe
132
+ * hook and schedules a flush.
133
+ *
134
+ * Only one controller at a time (enforced by `enablePersistence`),
135
+ * so a single slot is sufficient.
136
+ */
137
+ _onServiceRegistered = null;
138
+ constructor(env) {
139
+ this._env = env;
140
+ this.attachToEnv();
141
+ }
142
+ /** Factory used by `initializeSandbox`. */
143
+ static createRoot() {
144
+ return new SandboxImpl(new LocalEnvironment());
145
+ }
146
+ /**
147
+ * Resolve the live `LocalEnvironment`. Stable across resets — the
148
+ * sandbox holds whatever env is current, and consumers of `getEnv`
149
+ * always see the latest one.
150
+ */
151
+ getEnv() {
152
+ return this._env;
153
+ }
154
+ withAuth(auth) {
155
+ validateAuthState(auth);
156
+ return new SandboxContextImpl(this, auth);
157
+ }
158
+ /**
159
+ * Install one adapter subscription per env-level channel. Each adapter
160
+ * translates the env's payload into a `SandboxEvent` and dispatches
161
+ * through {@link emit}. Refreshed on `reset()` after the env swap.
162
+ */
163
+ attachToEnv() {
164
+ this.envUnsubs.push(this._env.onRequest((event) => {
165
+ // RequestEvent already carries `kind: 'request'` from buildRequestEvent.
166
+ this.emitEvent(event);
167
+ }));
168
+ this.envUnsubs.push(this._env.onWrite((event) => {
169
+ // WriteSandboxEvent already carries `kind: 'write'` from emitWrite.
170
+ this.emitEvent(event);
171
+ }));
172
+ this.envUnsubs.push(this._env.onSnapshotDelivery((event) => this.emitEvent(event)));
173
+ this.envUnsubs.push(this._env.onSnapshotSuppressed((event) => this.emitEvent(event)));
174
+ this.envUnsubs.push(this._env.onListenerLifecycle((event) => this.emitEvent(event)));
175
+ // Listener errored events surface via the env's onSnapshotError
176
+ // channel. attach/detach come from onListenerLifecycle (registered
177
+ // below). `listenerId` is now plumbed through emitSnapshotError, so
178
+ // consumers can correlate errored events with the prior attach.
179
+ this.envUnsubs.push(this._env.onSnapshotError((err, target, listenerId) => {
180
+ const ev = {
181
+ kind: 'listener_errored',
182
+ id: makeSandboxEventId(),
183
+ at: Date.now(),
184
+ listenerId,
185
+ target: target.kind === 'doc'
186
+ ? { kind: 'doc', path: target.path }
187
+ : { kind: 'query', collection: target.collection },
188
+ auth: err.request?.auth ?? null,
189
+ error: {
190
+ code: 'permission-denied',
191
+ message: err.message,
192
+ },
193
+ };
194
+ this.emitEvent(ev);
195
+ }));
196
+ // onDenial is intentionally NOT bridged into a distinct event kind —
197
+ // denials are `kind === 'request' && result === 'deny'` events, which
198
+ // the onRequest bridge above already covers. Subscribing to onDenial
199
+ // here would double-emit.
200
+ }
201
+ /**
202
+ * THE unified emit choke-point. Every SandboxEvent — from any service —
203
+ * flows through here so provenance is stamped in exactly one place
204
+ * ({@link stampProvenance}) and the event lands on the single
205
+ * `onEvent`/`history()` stream.
206
+ *
207
+ * `provenance` lets a non-default emitter (a future Auth/Storage/RTDB
208
+ * emit site, or a Studio admin/agent/impersonation path) declare its
209
+ * `service`/`actor`/`authLens`/`planId`. Omitted ⇒ Firestore / app /
210
+ * app-session defaults, which is exactly today's Firestore behaviour —
211
+ * so routing the existing Firestore emitters through here is a no-op on
212
+ * what consumers observe beyond the additive provenance fields.
213
+ */
214
+ emitEvent(event, provenance) {
215
+ // Ambient window values ({@link runWithProvenance}) fill in for fields
216
+ // the explicit per-emit override doesn't name; fields the event itself
217
+ // carries still win inside stampProvenance.
218
+ const merged = this.ambientProvenance
219
+ ? { ...this.ambientProvenance, ...provenance }
220
+ : provenance;
221
+ this.dispatch(stampProvenance(event, merged));
222
+ }
223
+ /**
224
+ * See `Sandbox.runWithProvenance` (types.ts) for the contract: ambient
225
+ * provenance defaults for events emitted synchronously during `fn`.
226
+ * Nested windows merge (innermost wins per field) and restore on exit.
227
+ */
228
+ runWithProvenance(provenance, fn) {
229
+ const prev = this.ambientProvenance;
230
+ this.ambientProvenance = prev ? { ...prev, ...provenance } : provenance;
231
+ try {
232
+ return fn();
233
+ }
234
+ finally {
235
+ this.ambientProvenance = prev;
236
+ }
237
+ }
238
+ /**
239
+ * Dispatch a (already-stamped) SandboxEvent to all user subscribers.
240
+ * Synchronous, with sync-throw + async-rejection isolation so a faulty
241
+ * subscriber can't destabilize the sandbox or crash the process via
242
+ * unhandledRejection. All callers go through {@link emitEvent}; this is
243
+ * the raw fan-out + history append it wraps.
244
+ */
245
+ dispatch(event) {
246
+ // Append to history unconditionally — consumers that call
247
+ // sandbox.history() expect every event the sandbox saw, regardless
248
+ // of whether onEvent subscribers were attached at emit time.
249
+ this.eventHistory.push(event);
250
+ this.dispatchedCount++;
251
+ if (this.eventSubs.size === 0)
252
+ return;
253
+ for (const cb of this.eventSubs) {
254
+ try {
255
+ const result = cb(event);
256
+ if (result && typeof result.then === 'function') {
257
+ result.catch(() => { });
258
+ }
259
+ }
260
+ catch { /* swallow — observational */ }
261
+ }
262
+ }
263
+ /**
264
+ * Internal entry point for sandbox-level event sources (snapshot
265
+ * deliveries / lifecycle / session_boundary) that don't have an
266
+ * env-level channel to ride on. Exposed only to the same package via
267
+ * {@link emitSandboxEvent}. Stamps provenance like every other emit.
268
+ */
269
+ emitInternal(event, provenance) {
270
+ this.emitEvent(event, provenance);
271
+ }
272
+ /**
273
+ * Subscribe to every event the sandbox emits. Survives `reset()`.
274
+ */
275
+ onEvent(cb) {
276
+ this.eventSubs.add(cb);
277
+ return () => { this.eventSubs.delete(cb); };
278
+ }
279
+ /**
280
+ * Every SandboxEvent emitted on this sandbox since init (or since
281
+ * the last `reset()`). Returns a defensive copy — mutating the
282
+ * returned array doesn't affect future history() calls.
283
+ *
284
+ * Replay engine consumes this: hand the array to
285
+ * `replay(events, rules)` from `pyric/sandbox` and the
286
+ * engine re-issues every captured write against a fresh sandbox.
287
+ *
288
+ * `reset()` clears the history AFTER emitting the closing
289
+ * session_boundary event, so the last entry of a pre-reset history
290
+ * is always `{ kind: 'session_boundary', phase: 'reset' }`. Likewise
291
+ * `dispose()` leaves the boundary as the final entry.
292
+ */
293
+ history() {
294
+ return [...this.eventHistory];
295
+ }
296
+ /**
297
+ * Prime the event-history log with events from a PRIOR session of the
298
+ * SAME origin (the served `.pyric/last-session.json` capture), for display
299
+ * continuity after a SharedWorker death — Traffic / activity / metrics read
300
+ * `history()` (and history-first `onEvent` batches), so a fresh worker would
301
+ * otherwise show an empty feed even though the data restored from IDB.
302
+ *
303
+ * This is history-priming ONLY:
304
+ * - events are APPENDED to `eventHistory` so `history()` and any consumer
305
+ * that subscribes AFTER boot (Studio's history-first batch) sees them;
306
+ * - they are NOT dispatched to live `onEvent` subscribers (no re-emission);
307
+ * - no operation is re-executed — the underlying data is restored
308
+ * separately from persistence, these events are the record of it;
309
+ * - `dispatchedCount` is untouched (it counts THIS session's live
310
+ * dispatches, which drive session_boundary's priorOpCount).
311
+ *
312
+ * No-op unless history is empty, so a warm sandbox (live events already
313
+ * accumulated during boot) is never disturbed and primed events can never
314
+ * interleave after live ones. Returns the number of events primed.
315
+ */
316
+ primeEventHistory(events) {
317
+ if (this.eventHistory.length > 0)
318
+ return 0;
319
+ if (events.length === 0)
320
+ return 0;
321
+ this.eventHistory.push(...events);
322
+ return events.length;
323
+ }
324
+ /**
325
+ * Admin-plane access. Identity-agnostic: admin reads aren't gated on
326
+ * auth, so they're a sandbox property — not something contexts carry.
327
+ */
328
+ get admin() {
329
+ return {
330
+ getDocument: (path) => this._env.getDocument(path),
331
+ listDocuments: (prefix) => this._env.listDocuments(prefix),
332
+ setDocument: (path, data) => this._env.adminSetDocument(path, data),
333
+ deleteDocument: (path) => this._env.adminDeleteDocument(path),
334
+ };
335
+ }
336
+ reset() {
337
+ // Emit the boundary BEFORE the swap so consumers see "session N
338
+ // closed" before any post-reset events arrive. Subscribers in
339
+ // eventSubs survive the swap.
340
+ const boundary = {
341
+ kind: 'session_boundary',
342
+ id: makeSandboxEventId(),
343
+ at: Date.now(),
344
+ phase: 'reset',
345
+ priorOpCount: this.dispatchedCount,
346
+ };
347
+ this.emitEvent(boundary);
348
+ // The boundary is now the last entry in eventHistory; clear the
349
+ // history AFTER emit so consumers that took a snapshot before
350
+ // reset() retain the boundary in their copy.
351
+ this.eventHistory = [];
352
+ // Clear currentUser to null and notify — a reset wipes everything
353
+ // including signed-in identity. Subscribers see the sign-out so
354
+ // their UI / Firestore handles reflect the post-reset state.
355
+ if (this._currentUser !== null) {
356
+ this._currentUser = null;
357
+ this.notifyCurrentUserSubs(null);
358
+ }
359
+ // Detach adapter subscriptions from the outgoing env first
360
+ // (otherwise dispose() would invoke them with cleared registries —
361
+ // harmless but wasteful). Then dispose, swap, re-attach.
362
+ for (const unsub of this.envUnsubs)
363
+ unsub();
364
+ this.envUnsubs = [];
365
+ this._env.dispose();
366
+ this._env = new LocalEnvironment();
367
+ this.attachToEnv();
368
+ }
369
+ dispose() {
370
+ // Emit dispose boundary so consumers can flush their buffers /
371
+ // close out forensic logs cleanly.
372
+ const boundary = {
373
+ kind: 'session_boundary',
374
+ id: makeSandboxEventId(),
375
+ at: Date.now(),
376
+ phase: 'dispose',
377
+ priorOpCount: this.dispatchedCount,
378
+ };
379
+ this.emitEvent(boundary);
380
+ for (const unsub of this.envUnsubs)
381
+ unsub();
382
+ this.envUnsubs = [];
383
+ this._env.dispose();
384
+ // Detach persistence first so its event subscription doesn't fire
385
+ // after we clear `eventSubs` below — the controller registers via
386
+ // `onEvent`, so its unsubscribe is the safe way out.
387
+ if (this.persistence) {
388
+ this.persistence.dispose();
389
+ this.persistence = null;
390
+ }
391
+ // Clear the service registry and detach the late-registration hook.
392
+ // The controller's dispose() (above) is responsible for unsubscribing
393
+ // any service change notifications it hooked up — we just drop our
394
+ // reference here so a dead sandbox doesn't hold service closures.
395
+ this.serviceRegistry.clear();
396
+ this._onServiceRegistered = null;
397
+ // Drop user callbacks too — a disposed sandbox is dead, holding
398
+ // subscriptions on it would leak.
399
+ this.eventSubs.clear();
400
+ this.currentUserSubs.clear();
401
+ }
402
+ snapshot() {
403
+ // Collect each registered service's snapshot under its name. The
404
+ // snapshot is taken at call time — the registry is live, so services
405
+ // registered after `enablePersistence` are naturally included the
406
+ // next time flush calls this.
407
+ const services = {};
408
+ for (const [name, svc] of this.serviceRegistry) {
409
+ services[name] = svc.snapshot();
410
+ }
411
+ return { firestore: this._env.snapshot(), services };
412
+ }
413
+ loadSnapshot(data) {
414
+ // Clobber: reset() to a clean env + cleared session, then rebuild firestore
415
+ // and restore services from the snapshot. This mirrors the persistence
416
+ // controller's boot restore (admin.setDocument per doc + svc.restore per
417
+ // service), but reset()s FIRST so the result is a TOTAL replace — documents
418
+ // absent from `data` do not survive — rather than the controller's
419
+ // onto-an-empty-env overlay. reset() emits the session_boundary and
420
+ // re-attaches the env; the per-doc writes below re-evaluate live listeners
421
+ // and dirty the controller so the loaded state is flushed.
422
+ this.reset();
423
+ for (const [path, docData] of Object.entries(data.firestore)) {
424
+ this._env.adminSetDocument(path, docData);
425
+ }
426
+ // Only services that are BOTH in the snapshot AND currently registered are
427
+ // restored; each is isolated so one broken service doesn't abort the load.
428
+ for (const [name, svc] of this.serviceRegistry) {
429
+ if (!(name in data.services))
430
+ continue;
431
+ try {
432
+ svc.restore(data.services[name]);
433
+ }
434
+ catch (e) {
435
+ console.warn(`[sandbox] loadSnapshot: service '${name}' restore failed — ` +
436
+ `Firestore is intact; that service's state may be incomplete:`, e);
437
+ }
438
+ }
439
+ }
440
+ /**
441
+ * Current authenticated user across the sandbox. See the doc on
442
+ * {@link Sandbox.currentUser} — used by `pyric/auth` to thread
443
+ * identity through stateful Auth handles.
444
+ */
445
+ get currentUser() {
446
+ return this._currentUser;
447
+ }
448
+ set currentUser(user) {
449
+ // Validate per `withAuth` rules so the surface stays consistent —
450
+ // null is anonymous; anything else must be a well-formed AuthState.
451
+ validateAuthState(user);
452
+ // No-op when the new value is structurally equal to the old —
453
+ // saves a wasted listener fire on idempotent sign-in/out flows.
454
+ if (currentUserEqual(this._currentUser, user))
455
+ return;
456
+ this._currentUser = user;
457
+ this.notifyCurrentUserSubs(user);
458
+ }
459
+ onCurrentUserChanged(cb) {
460
+ this.currentUserSubs.add(cb);
461
+ return () => { this.currentUserSubs.delete(cb); };
462
+ }
463
+ notifyCurrentUserSubs(user) {
464
+ // Re-evaluate LIVE Firestore listeners against the new identity BEFORE
465
+ // notifying currentUser subscribers. A `getFirestore(sandbox)`
466
+ // `onSnapshot` follows `sandbox.currentUser`, so a sign-out / sign-in
467
+ // must re-establish it under the new auth (an auth-gated listener loses
468
+ // access on sign-out) — matching production's listener re-establishment.
469
+ // `_currentUser` is already updated by the caller (setter / reset), so
470
+ // `user` IS the new auth. `AuthState` is structurally the `ListenerAuth`
471
+ // shape the env expects (`{ uid, token? } | null`). No-op when there are
472
+ // no live listeners (e.g. the post-`reset()` env is freshly empty).
473
+ this._env.reevaluateLiveListeners(user);
474
+ if (this.currentUserSubs.size === 0)
475
+ return;
476
+ for (const cb of this.currentUserSubs) {
477
+ try {
478
+ const result = cb(user);
479
+ if (result && typeof result.then === 'function') {
480
+ result.catch(() => { });
481
+ }
482
+ }
483
+ catch { /* swallow — observational */ }
484
+ }
485
+ }
486
+ /**
487
+ * Wire a persistence controller into this sandbox. Restores any
488
+ * prior snapshot before resolving so the in-memory state matches
489
+ * the backend by the time the caller's await returns.
490
+ *
491
+ * Concurrent calls share the same in-flight attach; the second
492
+ * caller sees the same restored state without a duplicate restore
493
+ * pass. Repeat calls after the first resolves are accepted only when
494
+ * the `key` matches — different keys would mean re-pointing the
495
+ * sandbox at a new backend mid-flight, which is conceptually muddled
496
+ * and rejected.
497
+ */
498
+ async enablePersistence(options) {
499
+ if (this.persistence) {
500
+ if (this.persistence.options.key !== options.key) {
501
+ throw new SandboxError('failed-precondition', `Persistence already enabled with key '${this.persistence.options.key}'; ` +
502
+ `cannot re-enable with key '${options.key}'. Dispose and recreate the sandbox.`);
503
+ }
504
+ return;
505
+ }
506
+ if (this.enablePersistencePromise)
507
+ return this.enablePersistencePromise;
508
+ this.enablePersistencePromise = (async () => {
509
+ const controller = await attachPersistence(this, options);
510
+ // Race-safe: if `dispose()` ran while attach was awaiting, drop
511
+ // the controller on the floor immediately rather than leaving a
512
+ // detached event subscription dangling on the (now-dead) sandbox.
513
+ this.persistence = controller;
514
+ })();
515
+ try {
516
+ await this.enablePersistencePromise;
517
+ }
518
+ finally {
519
+ this.enablePersistencePromise = null;
520
+ }
521
+ }
522
+ /**
523
+ * Enable cross-tab realtime sync. Delegates to `attachTabSync` which
524
+ * wires the `BroadcastChannel` + `onEvent` subscription. Returns the
525
+ * disable function from `attachTabSync` so the caller can tear down
526
+ * sync without knowing the internals. Mirrors the pattern used by
527
+ * `enablePersistence` → `attachPersistence`.
528
+ */
529
+ enableTabSync(options) {
530
+ return attachTabSync(this, options);
531
+ }
532
+ async flush() {
533
+ if (!this.persistence) {
534
+ throw new SandboxError('failed-precondition', 'flush() called before enablePersistence()');
535
+ }
536
+ await this.persistence.flush();
537
+ }
538
+ async clearPersistence() {
539
+ if (!this.persistence)
540
+ return;
541
+ await this.persistence.clear();
542
+ }
543
+ registerPersistableService(name, hooks) {
544
+ if (this.serviceRegistry.has(name)) {
545
+ throw new SandboxError('failed-precondition', `registerPersistableService: a service named '${name}' is already registered on this sandbox. ` +
546
+ `Each service name must be unique — the auth package registers 'auth' exactly once per sandbox.`);
547
+ }
548
+ this.serviceRegistry.set(name, hooks);
549
+ // Notify the persistence controller so it can subscribe to change
550
+ // notifications from this service even if it was registered AFTER
551
+ // `enablePersistence` was called (the late-registration path: user
552
+ // calls `enablePersistence`, later calls `getAuth(sandbox)` which
553
+ // triggers this registration).
554
+ if (this._onServiceRegistered) {
555
+ this._onServiceRegistered(name, hooks);
556
+ }
557
+ return () => {
558
+ this.serviceRegistry.delete(name);
559
+ };
560
+ }
561
+ /**
562
+ * Internal hook for the persistence controller: called once at attach
563
+ * time so the controller can be notified when a service registers
564
+ * AFTER `enablePersistence`. Only one controller can be active at a
565
+ * time, so a single callback slot is sufficient.
566
+ *
567
+ * Pass `null` to detach (called by the controller's `dispose()`).
568
+ */
569
+ setServiceRegistrationHook(cb) {
570
+ this._onServiceRegistered = cb;
571
+ }
572
+ /**
573
+ * Internal: iterate the current service registry. Used by the
574
+ * persistence controller's restore path to apply each service's
575
+ * saved state from the blob.
576
+ */
577
+ getServiceRegistry() {
578
+ return this.serviceRegistry;
579
+ }
580
+ }
581
+ /**
582
+ * Structural equality on AuthState — both null, or same uid + same
583
+ * `token` JSON. Used by the `currentUser` setter to skip no-op
584
+ * notifications (matches `firebase/auth`'s observer behavior: it does
585
+ * NOT re-fire when the user object is set to the same identity).
586
+ */
587
+ function currentUserEqual(a, b) {
588
+ if (a === b)
589
+ return true;
590
+ if (a === null || b === null)
591
+ return false;
592
+ if (a.uid !== b.uid)
593
+ return false;
594
+ // Token comparison via JSON — tokens are plain object claim maps,
595
+ // not expected to contain non-serializable values.
596
+ const aTok = a.token === undefined ? undefined : JSON.stringify(a.token);
597
+ const bTok = b.token === undefined ? undefined : JSON.stringify(b.token);
598
+ return aTok === bTok;
599
+ }
600
+ /**
601
+ * Internal helper for service modules: given a `Sandbox` (or a
602
+ * `SandboxContext`'s underlying sandbox), return its `LocalEnvironment`.
603
+ * Throws if the handle isn't a `SandboxImpl` (i.e. somebody hand-rolled
604
+ * one) — custom Sandbox implementations are not supported.
605
+ */
606
+ export function getInternalEnv(sandbox) {
607
+ if (!(sandbox instanceof SandboxImpl)) {
608
+ throw new SandboxError('invalid-argument', 'Sandbox handle was not produced by initializeSandbox(); custom Sandbox implementations are not supported.');
609
+ }
610
+ return sandbox.getEnv();
611
+ }
612
+ /**
613
+ * Prime a sandbox's `history()` log with events from a prior session of the
614
+ * same origin (the served capture file), WITHOUT dispatching them to live
615
+ * `onEvent` subscribers or re-executing any op. History-priming seam for the
616
+ * served worker's boot-time event hydration — see
617
+ * {@link SandboxImpl.primeEventHistory}. No-op unless history is empty.
618
+ * Returns the number of events primed.
619
+ *
620
+ * Throws if `sandbox` wasn't produced by `initializeSandbox()` (same guard
621
+ * as {@link getInternalEnv}).
622
+ */
623
+ export function primeEventHistory(sandbox, events) {
624
+ if (!(sandbox instanceof SandboxImpl)) {
625
+ throw new SandboxError('invalid-argument', 'Sandbox handle was not produced by initializeSandbox(); custom Sandbox implementations are not supported.');
626
+ }
627
+ return sandbox.primeEventHistory(events);
628
+ }
629
+ /**
630
+ * Emit a `SandboxEvent` onto a sandbox's unified `onEvent`/`history()`
631
+ * stream, stamping {@link EventProvenance} through the single
632
+ * {@link SandboxImpl.emitEvent} choke-point.
633
+ *
634
+ * **This is the seam the Pyric Studio event-unification keystone reserves
635
+ * for non-Firestore services.** Firestore already emits via the env→sandbox
636
+ * fan-out in {@link SandboxImpl.attachToEnv} (no caller needs this for it).
637
+ * Auth / Storage / RTDB are meant to call this from their own emit sites so
638
+ * their activity lands on the same stream — e.g.
639
+ * `emitSandboxEvent(sandbox, userCreatedEvent, { service: 'auth' })`.
640
+ *
641
+ * STATUS (Wave 1.5, Gap #1): Auth / Storage / RTDB now emit here. They share
642
+ * one additive union variant — {@link ServiceMutationEvent} (`kind:
643
+ * 'service_mutation'`) — built via {@link makeServiceMutationEvent}, rather
644
+ * than bending into Firestore's rule-eval-shaped `request`/`write` kinds.
645
+ * Wired emit sites:
646
+ * - auth: user create/update/delete, users-clear, sign-in, sign-out
647
+ * (`SandboxBackend` in `pyric/auth`).
648
+ * - storage: object put / delete / metadata-update (`pyric/storage`).
649
+ * - rtdb: set / update / remove / transaction-commit
650
+ * (`RtdbBackend` in `pyric/database`, via the modular surface).
651
+ * Firestore still rides the env→sandbox fan-out and is unchanged. See
652
+ * the design rationale.
653
+ *
654
+ * Throws if `sandbox` wasn't produced by `initializeSandbox()` (same guard
655
+ * as {@link getInternalEnv}).
656
+ */
657
+ export function emitSandboxEvent(sandbox, event, provenance) {
658
+ if (!(sandbox instanceof SandboxImpl)) {
659
+ throw new SandboxError('invalid-argument', 'Sandbox handle was not produced by initializeSandbox(); custom Sandbox implementations are not supported.');
660
+ }
661
+ sandbox.emitInternal(event, provenance);
662
+ }
663
+ /**
664
+ * Build a {@link ServiceMutationEvent} with a fresh `id` + `at` minted from
665
+ * the same monotonic counter Firestore events use — so a non-Firestore
666
+ * service (auth/storage/rtdb) doesn't have to re-implement id minting or
667
+ * worry about colliding with the Firestore stream's ids.
668
+ *
669
+ * The returned event is NOT yet dispatched; hand it to
670
+ * {@link emitSandboxEvent} (which stamps provenance and lands it on the
671
+ * unified stream). The convenience seam for the keystone: a service emit
672
+ * site is `emitSandboxEvent(sandbox, makeServiceMutationEvent({ ... }), { service })`.
673
+ */
674
+ export function makeServiceMutationEvent(fields) {
675
+ return {
676
+ kind: 'service_mutation',
677
+ id: makeSandboxEventId(),
678
+ at: Date.now(),
679
+ ...fields,
680
+ };
681
+ }
682
+ export function makeSandboxOperationEvent(fields) {
683
+ const { at, ...rest } = fields;
684
+ return {
685
+ kind: 'operation',
686
+ id: makeSandboxEventId(),
687
+ at: at ?? Date.now(),
688
+ ...rest,
689
+ };
690
+ }
691
+ export function makeSandboxCommitEvent(fields) {
692
+ const { at, ...rest } = fields;
693
+ return {
694
+ kind: 'commit',
695
+ id: makeSandboxEventId(),
696
+ at: at ?? Date.now(),
697
+ ...rest,
698
+ };
699
+ }
700
+ export function makeSandboxListenerEvent(fields) {
701
+ const { at, ...rest } = fields;
702
+ return {
703
+ kind: 'listener',
704
+ id: makeSandboxEventId(),
705
+ at: at ?? Date.now(),
706
+ ...rest,
707
+ };
708
+ }
709
+ export function makeSandboxRuntimeErrorEvent(fields) {
710
+ const { at, ...rest } = fields;
711
+ return {
712
+ kind: 'runtime_error',
713
+ id: makeSandboxEventId(),
714
+ at: at ?? Date.now(),
715
+ ...rest,
716
+ };
717
+ }
718
+ //# sourceMappingURL=sandbox-impl.js.map