@astrogate/sdk 0.0.0-stage → 0.1.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 (440) hide show
  1. package/README.md +6 -2
  2. package/THIRD_PARTY_NOTICES.md +17 -0
  3. package/dist/browser.d.ts +85 -0
  4. package/dist/browser.js +16 -0
  5. package/dist/database-binding.d.ts +7 -0
  6. package/dist/database-binding.js +11 -0
  7. package/dist/hosted-session.d.ts +1 -0
  8. package/dist/hosted-session.js +11 -0
  9. package/dist/http.d.ts +24 -0
  10. package/dist/http.js +92 -0
  11. package/dist/inventory.d.ts +7 -0
  12. package/dist/inventory.js +18 -0
  13. package/dist/management-read.d.ts +17 -0
  14. package/dist/management-read.js +104 -0
  15. package/dist/management.d.ts +347 -0
  16. package/dist/management.js +137 -0
  17. package/dist/operator.d.ts +136 -0
  18. package/dist/operator.js +53 -0
  19. package/dist/react.d.ts +16 -0
  20. package/dist/react.js +10 -0
  21. package/dist/server.d.ts +27 -0
  22. package/dist/server.js +30 -0
  23. package/dist/services.d.ts +7 -0
  24. package/dist/services.js +53 -0
  25. package/dist/storage.d.ts +68 -0
  26. package/dist/storage.js +30 -0
  27. package/dist/tasks.d.ts +42 -0
  28. package/dist/tasks.js +24 -0
  29. package/dist/wire.gen.d.ts +7107 -0
  30. package/dist/wire.gen.js +5 -0
  31. package/native-provenance.json +15 -0
  32. package/node_modules/@instantdb/admin/LICENSE +202 -0
  33. package/node_modules/@instantdb/admin/dist/esm/index.d.ts +607 -0
  34. package/node_modules/@instantdb/admin/dist/esm/index.js +1036 -0
  35. package/node_modules/@instantdb/admin/dist/esm/polyfill.d.ts +16 -0
  36. package/node_modules/@instantdb/admin/dist/esm/polyfill.js +21 -0
  37. package/node_modules/@instantdb/admin/dist/esm/subscribe.d.ts +38 -0
  38. package/node_modules/@instantdb/admin/dist/esm/subscribe.js +301 -0
  39. package/node_modules/@instantdb/admin/dist/esm/version.d.ts +2 -0
  40. package/node_modules/@instantdb/admin/dist/esm/version.js +2 -0
  41. package/node_modules/@instantdb/admin/package.json +23 -0
  42. package/node_modules/@instantdb/core/LICENSE +202 -0
  43. package/node_modules/@instantdb/core/dist/esm/Connection.d.ts +92 -0
  44. package/node_modules/@instantdb/core/dist/esm/Connection.js +188 -0
  45. package/node_modules/@instantdb/core/dist/esm/InMemoryStorage.d.ts +10 -0
  46. package/node_modules/@instantdb/core/dist/esm/InMemoryStorage.js +25 -0
  47. package/node_modules/@instantdb/core/dist/esm/IndexedDBStorage.d.ts +17 -0
  48. package/node_modules/@instantdb/core/dist/esm/IndexedDBStorage.js +309 -0
  49. package/node_modules/@instantdb/core/dist/esm/InstantError.d.ts +6 -0
  50. package/node_modules/@instantdb/core/dist/esm/InstantError.js +23 -0
  51. package/node_modules/@instantdb/core/dist/esm/Reactor.d.ts +430 -0
  52. package/node_modules/@instantdb/core/dist/esm/Reactor.js +2369 -0
  53. package/node_modules/@instantdb/core/dist/esm/StorageAPI.d.ts +39 -0
  54. package/node_modules/@instantdb/core/dist/esm/StorageAPI.js +65 -0
  55. package/node_modules/@instantdb/core/dist/esm/Stream.d.ts +120 -0
  56. package/node_modules/@instantdb/core/dist/esm/Stream.js +811 -0
  57. package/node_modules/@instantdb/core/dist/esm/SyncTable.d.ts +144 -0
  58. package/node_modules/@instantdb/core/dist/esm/SyncTable.js +523 -0
  59. package/node_modules/@instantdb/core/dist/esm/WindowNetworkListener.d.ts +4 -0
  60. package/node_modules/@instantdb/core/dist/esm/WindowNetworkListener.js +19 -0
  61. package/node_modules/@instantdb/core/dist/esm/attrTypes.d.ts +25 -0
  62. package/node_modules/@instantdb/core/dist/esm/attrTypes.js +1 -0
  63. package/node_modules/@instantdb/core/dist/esm/authAPI.d.ts +64 -0
  64. package/node_modules/@instantdb/core/dist/esm/authAPI.js +103 -0
  65. package/node_modules/@instantdb/core/dist/esm/clientTypes.d.ts +40 -0
  66. package/node_modules/@instantdb/core/dist/esm/clientTypes.js +1 -0
  67. package/node_modules/@instantdb/core/dist/esm/coreTypes.d.ts +33 -0
  68. package/node_modules/@instantdb/core/dist/esm/coreTypes.js +1 -0
  69. package/node_modules/@instantdb/core/dist/esm/createRouteHandler.d.ts +7 -0
  70. package/node_modules/@instantdb/core/dist/esm/createRouteHandler.js +51 -0
  71. package/node_modules/@instantdb/core/dist/esm/datalog.d.ts +7 -0
  72. package/node_modules/@instantdb/core/dist/esm/datalog.js +99 -0
  73. package/node_modules/@instantdb/core/dist/esm/devtool.d.ts +3 -0
  74. package/node_modules/@instantdb/core/dist/esm/devtool.js +144 -0
  75. package/node_modules/@instantdb/core/dist/esm/framework.d.ts +80 -0
  76. package/node_modules/@instantdb/core/dist/esm/framework.js +243 -0
  77. package/node_modules/@instantdb/core/dist/esm/helperTypes.d.ts +75 -0
  78. package/node_modules/@instantdb/core/dist/esm/helperTypes.js +1 -0
  79. package/node_modules/@instantdb/core/dist/esm/index.d.ts +597 -0
  80. package/node_modules/@instantdb/core/dist/esm/index.js +649 -0
  81. package/node_modules/@instantdb/core/dist/esm/infiniteQuery.d.ts +25 -0
  82. package/node_modules/@instantdb/core/dist/esm/infiniteQuery.js +430 -0
  83. package/node_modules/@instantdb/core/dist/esm/instaml.d.ts +17 -0
  84. package/node_modules/@instantdb/core/dist/esm/instaml.js +576 -0
  85. package/node_modules/@instantdb/core/dist/esm/instaql.d.ts +12 -0
  86. package/node_modules/@instantdb/core/dist/esm/instaql.js +632 -0
  87. package/node_modules/@instantdb/core/dist/esm/instatx.d.ts +127 -0
  88. package/node_modules/@instantdb/core/dist/esm/instatx.js +93 -0
  89. package/node_modules/@instantdb/core/dist/esm/model/instaqlResult.d.ts +7 -0
  90. package/node_modules/@instantdb/core/dist/esm/model/instaqlResult.js +24 -0
  91. package/node_modules/@instantdb/core/dist/esm/parseSchemaFromJSON.d.ts +2 -0
  92. package/node_modules/@instantdb/core/dist/esm/parseSchemaFromJSON.js +142 -0
  93. package/node_modules/@instantdb/core/dist/esm/presence.d.ts +50 -0
  94. package/node_modules/@instantdb/core/dist/esm/presence.js +50 -0
  95. package/node_modules/@instantdb/core/dist/esm/presenceTypes.d.ts +9 -0
  96. package/node_modules/@instantdb/core/dist/esm/presenceTypes.js +3 -0
  97. package/node_modules/@instantdb/core/dist/esm/queryTypes.d.ts +271 -0
  98. package/node_modules/@instantdb/core/dist/esm/queryTypes.js +3 -0
  99. package/node_modules/@instantdb/core/dist/esm/queryValidation.d.ts +5 -0
  100. package/node_modules/@instantdb/core/dist/esm/queryValidation.js +287 -0
  101. package/node_modules/@instantdb/core/dist/esm/reactorTypes.d.ts +29 -0
  102. package/node_modules/@instantdb/core/dist/esm/reactorTypes.js +1 -0
  103. package/node_modules/@instantdb/core/dist/esm/routeHandlerProtocol.d.ts +19 -0
  104. package/node_modules/@instantdb/core/dist/esm/routeHandlerProtocol.js +1 -0
  105. package/node_modules/@instantdb/core/dist/esm/rulesTypes.d.ts +85 -0
  106. package/node_modules/@instantdb/core/dist/esm/rulesTypes.js +1 -0
  107. package/node_modules/@instantdb/core/dist/esm/sanityCheckQueries.d.ts +18 -0
  108. package/node_modules/@instantdb/core/dist/esm/sanityCheckQueries.js +152 -0
  109. package/node_modules/@instantdb/core/dist/esm/schema.d.ts +72 -0
  110. package/node_modules/@instantdb/core/dist/esm/schema.js +128 -0
  111. package/node_modules/@instantdb/core/dist/esm/schemaTypes.d.ts +244 -0
  112. package/node_modules/@instantdb/core/dist/esm/schemaTypes.js +106 -0
  113. package/node_modules/@instantdb/core/dist/esm/store.d.ts +89 -0
  114. package/node_modules/@instantdb/core/dist/esm/store.js +722 -0
  115. package/node_modules/@instantdb/core/dist/esm/transactionValidation.d.ts +7 -0
  116. package/node_modules/@instantdb/core/dist/esm/transactionValidation.js +130 -0
  117. package/node_modules/@instantdb/core/dist/esm/utils/Deferred.d.ts +8 -0
  118. package/node_modules/@instantdb/core/dist/esm/utils/Deferred.js +17 -0
  119. package/node_modules/@instantdb/core/dist/esm/utils/PersistedObject.d.ts +80 -0
  120. package/node_modules/@instantdb/core/dist/esm/utils/PersistedObject.js +448 -0
  121. package/node_modules/@instantdb/core/dist/esm/utils/dates.d.ts +1 -0
  122. package/node_modules/@instantdb/core/dist/esm/utils/dates.js +211 -0
  123. package/node_modules/@instantdb/core/dist/esm/utils/error.d.ts +2 -0
  124. package/node_modules/@instantdb/core/dist/esm/utils/error.js +8 -0
  125. package/node_modules/@instantdb/core/dist/esm/utils/fetch.d.ts +125 -0
  126. package/node_modules/@instantdb/core/dist/esm/utils/fetch.js +31 -0
  127. package/node_modules/@instantdb/core/dist/esm/utils/flags.d.ts +4 -0
  128. package/node_modules/@instantdb/core/dist/esm/utils/flags.js +10 -0
  129. package/node_modules/@instantdb/core/dist/esm/utils/id.d.ts +3 -0
  130. package/node_modules/@instantdb/core/dist/esm/utils/id.js +25 -0
  131. package/node_modules/@instantdb/core/dist/esm/utils/linkIndex.d.ts +7 -0
  132. package/node_modules/@instantdb/core/dist/esm/utils/linkIndex.js +17 -0
  133. package/node_modules/@instantdb/core/dist/esm/utils/log.d.ts +6 -0
  134. package/node_modules/@instantdb/core/dist/esm/utils/log.js +13 -0
  135. package/node_modules/@instantdb/core/dist/esm/utils/object.d.ts +16 -0
  136. package/node_modules/@instantdb/core/dist/esm/utils/object.js +143 -0
  137. package/node_modules/@instantdb/core/dist/esm/utils/pgtime.d.ts +197 -0
  138. package/node_modules/@instantdb/core/dist/esm/utils/pgtime.js +197 -0
  139. package/node_modules/@instantdb/core/dist/esm/utils/pick.d.ts +1 -0
  140. package/node_modules/@instantdb/core/dist/esm/utils/pick.js +9 -0
  141. package/node_modules/@instantdb/core/dist/esm/utils/strings.d.ts +1 -0
  142. package/node_modules/@instantdb/core/dist/esm/utils/strings.js +15 -0
  143. package/node_modules/@instantdb/core/dist/esm/utils/weakHash.d.ts +15 -0
  144. package/node_modules/@instantdb/core/dist/esm/utils/weakHash.js +71 -0
  145. package/node_modules/@instantdb/core/dist/esm/utils/weakHashLegacy.d.ts +7 -0
  146. package/node_modules/@instantdb/core/dist/esm/utils/weakHashLegacy.js +72 -0
  147. package/node_modules/@instantdb/core/dist/esm/version.d.ts +2 -0
  148. package/node_modules/@instantdb/core/dist/esm/version.js +2 -0
  149. package/node_modules/@instantdb/core/dist/esm/warningToggle.d.ts +2 -0
  150. package/node_modules/@instantdb/core/dist/esm/warningToggle.js +4 -0
  151. package/node_modules/@instantdb/core/package.json +20 -0
  152. package/node_modules/@instantdb/eventsource/LICENSE +22 -0
  153. package/node_modules/@instantdb/eventsource/README.md +226 -0
  154. package/node_modules/@instantdb/eventsource/dist/index.cjs +279 -0
  155. package/node_modules/@instantdb/eventsource/dist/index.cjs.map +1 -0
  156. package/node_modules/@instantdb/eventsource/dist/index.d.cts +346 -0
  157. package/node_modules/@instantdb/eventsource/dist/index.d.ts +346 -0
  158. package/node_modules/@instantdb/eventsource/dist/index.js +279 -0
  159. package/node_modules/@instantdb/eventsource/dist/index.js.map +1 -0
  160. package/node_modules/@instantdb/eventsource/package.json +128 -0
  161. package/node_modules/@instantdb/eventsource/src/EventSource.ts +614 -0
  162. package/node_modules/@instantdb/eventsource/src/errors.ts +141 -0
  163. package/node_modules/@instantdb/eventsource/src/index.ts +3 -0
  164. package/node_modules/@instantdb/eventsource/src/types.ts +164 -0
  165. package/node_modules/@instantdb/react/LICENSE +202 -0
  166. package/node_modules/@instantdb/react/dist/esm/Cursors.d.ts +18 -0
  167. package/node_modules/@instantdb/react/dist/esm/Cursors.js +103 -0
  168. package/node_modules/@instantdb/react/dist/esm/InstantReactWebDatabase.d.ts +5 -0
  169. package/node_modules/@instantdb/react/dist/esm/InstantReactWebDatabase.js +5 -0
  170. package/node_modules/@instantdb/react/dist/esm/index.d.ts +6 -0
  171. package/node_modules/@instantdb/react/dist/esm/index.js +22 -0
  172. package/node_modules/@instantdb/react/dist/esm/init.d.ts +40 -0
  173. package/node_modules/@instantdb/react/dist/esm/init.js +49 -0
  174. package/node_modules/@instantdb/react/dist/esm/next-ssr/HydrationStreamProvider.d.ts +65 -0
  175. package/node_modules/@instantdb/react/dist/esm/next-ssr/HydrationStreamProvider.js +96 -0
  176. package/node_modules/@instantdb/react/dist/esm/next-ssr/InstantNextDatabase.d.ts +11 -0
  177. package/node_modules/@instantdb/react/dist/esm/next-ssr/InstantNextDatabase.js +31 -0
  178. package/node_modules/@instantdb/react/dist/esm/next-ssr/InstantSuspenseProvider.d.ts +24 -0
  179. package/node_modules/@instantdb/react/dist/esm/next-ssr/InstantSuspenseProvider.js +162 -0
  180. package/node_modules/@instantdb/react/dist/esm/next-ssr/getUserFromInstantCookie.d.ts +9 -0
  181. package/node_modules/@instantdb/react/dist/esm/next-ssr/getUserFromInstantCookie.js +16 -0
  182. package/node_modules/@instantdb/react/dist/esm/next-ssr/htmlescape.d.ts +2 -0
  183. package/node_modules/@instantdb/react/dist/esm/next-ssr/htmlescape.js +20 -0
  184. package/node_modules/@instantdb/react/dist/esm/next-ssr/index.d.ts +29 -0
  185. package/node_modules/@instantdb/react/dist/esm/next-ssr/index.js +34 -0
  186. package/node_modules/@instantdb/react/dist/esm/version.d.ts +2 -0
  187. package/node_modules/@instantdb/react/dist/esm/version.js +2 -0
  188. package/node_modules/@instantdb/react/package.json +24 -0
  189. package/node_modules/@instantdb/react-common/LICENSE +202 -0
  190. package/node_modules/@instantdb/react-common/dist/esm/InstantReactAbstractDatabase.d.ts +282 -0
  191. package/node_modules/@instantdb/react-common/dist/esm/InstantReactAbstractDatabase.js +386 -0
  192. package/node_modules/@instantdb/react-common/dist/esm/InstantReactRoom.d.ts +182 -0
  193. package/node_modules/@instantdb/react-common/dist/esm/InstantReactRoom.js +280 -0
  194. package/node_modules/@instantdb/react-common/dist/esm/index.d.ts +4 -0
  195. package/node_modules/@instantdb/react-common/dist/esm/index.js +3 -0
  196. package/node_modules/@instantdb/react-common/dist/esm/useInfiniteQuerySubscription.d.ts +27 -0
  197. package/node_modules/@instantdb/react-common/dist/esm/useInfiniteQuerySubscription.js +53 -0
  198. package/node_modules/@instantdb/react-common/dist/esm/useQuery.d.ts +6 -0
  199. package/node_modules/@instantdb/react-common/dist/esm/useQuery.js +75 -0
  200. package/node_modules/@instantdb/react-common/dist/esm/useTimeout.d.ts +4 -0
  201. package/node_modules/@instantdb/react-common/dist/esm/useTimeout.js +17 -0
  202. package/node_modules/@instantdb/react-common/dist/esm/version.d.ts +2 -0
  203. package/node_modules/@instantdb/react-common/dist/esm/version.js +2 -0
  204. package/node_modules/@instantdb/react-common/package.json +22 -0
  205. package/node_modules/@instantdb/version/LICENSE +202 -0
  206. package/node_modules/@instantdb/version/dist/esm/index.d.ts +2 -0
  207. package/node_modules/@instantdb/version/dist/esm/index.js +2 -0
  208. package/node_modules/@instantdb/version/dist/esm/version.d.ts +2 -0
  209. package/node_modules/@instantdb/version/dist/esm/version.js +5 -0
  210. package/node_modules/@instantdb/version/package.json +16 -0
  211. package/node_modules/@instantdb/webhooks/LICENSE +202 -0
  212. package/node_modules/@instantdb/webhooks/dist/esm/index.d.ts +587 -0
  213. package/node_modules/@instantdb/webhooks/dist/esm/index.js +748 -0
  214. package/node_modules/@instantdb/webhooks/package.json +18 -0
  215. package/node_modules/cookie/LICENSE +24 -0
  216. package/node_modules/cookie/README.md +295 -0
  217. package/node_modules/cookie/dist/index.d.ts +143 -0
  218. package/node_modules/cookie/dist/index.js +355 -0
  219. package/node_modules/cookie/dist/index.js.map +1 -0
  220. package/node_modules/cookie/package.json +57 -0
  221. package/node_modules/eventsource/LICENSE +22 -0
  222. package/node_modules/eventsource/README.md +252 -0
  223. package/node_modules/eventsource/dist/EventSource.d.ts +128 -0
  224. package/node_modules/eventsource/dist/EventSource.d.ts.map +1 -0
  225. package/node_modules/eventsource/dist/EventSource.js +556 -0
  226. package/node_modules/eventsource/dist/EventSource.js.map +1 -0
  227. package/node_modules/eventsource/dist/errors.d.ts +53 -0
  228. package/node_modules/eventsource/dist/errors.d.ts.map +1 -0
  229. package/node_modules/eventsource/dist/errors.js +120 -0
  230. package/node_modules/eventsource/dist/errors.js.map +1 -0
  231. package/node_modules/eventsource/dist/index.d.ts +4 -0
  232. package/node_modules/eventsource/dist/index.d.ts.map +1 -0
  233. package/node_modules/eventsource/dist/index.js +3 -0
  234. package/node_modules/eventsource/dist/index.js.map +1 -0
  235. package/node_modules/eventsource/dist/types.d.ts +156 -0
  236. package/node_modules/eventsource/dist/types.d.ts.map +1 -0
  237. package/node_modules/eventsource/dist/types.js +2 -0
  238. package/node_modules/eventsource/dist/types.js.map +1 -0
  239. package/node_modules/eventsource/node_modules/eventsource-parser/LICENSE +21 -0
  240. package/node_modules/eventsource/node_modules/eventsource-parser/README.md +177 -0
  241. package/node_modules/eventsource/node_modules/eventsource-parser/dist/errors.d.ts +35 -0
  242. package/node_modules/eventsource/node_modules/eventsource-parser/dist/errors.d.ts.map +1 -0
  243. package/node_modules/eventsource/node_modules/eventsource-parser/dist/errors.js +16 -0
  244. package/node_modules/eventsource/node_modules/eventsource-parser/dist/errors.js.map +1 -0
  245. package/node_modules/eventsource/node_modules/eventsource-parser/dist/index.d.ts +4 -0
  246. package/node_modules/eventsource/node_modules/eventsource-parser/dist/index.d.ts.map +1 -0
  247. package/node_modules/eventsource/node_modules/eventsource-parser/dist/index.js +3 -0
  248. package/node_modules/eventsource/node_modules/eventsource-parser/dist/index.js.map +1 -0
  249. package/node_modules/eventsource/node_modules/eventsource-parser/dist/parse.d.ts +12 -0
  250. package/node_modules/eventsource/node_modules/eventsource-parser/dist/parse.d.ts.map +1 -0
  251. package/node_modules/eventsource/node_modules/eventsource-parser/dist/parse.js +509 -0
  252. package/node_modules/eventsource/node_modules/eventsource-parser/dist/parse.js.map +1 -0
  253. package/node_modules/eventsource/node_modules/eventsource-parser/dist/stream.d.ts +76 -0
  254. package/node_modules/eventsource/node_modules/eventsource-parser/dist/stream.d.ts.map +1 -0
  255. package/node_modules/eventsource/node_modules/eventsource-parser/dist/stream.js +59 -0
  256. package/node_modules/eventsource/node_modules/eventsource-parser/dist/stream.js.map +1 -0
  257. package/node_modules/eventsource/node_modules/eventsource-parser/dist/types.d.ts +130 -0
  258. package/node_modules/eventsource/node_modules/eventsource-parser/dist/types.d.ts.map +1 -0
  259. package/node_modules/eventsource/node_modules/eventsource-parser/dist/types.js +1 -0
  260. package/node_modules/eventsource/node_modules/eventsource-parser/dist/types.js.map +1 -0
  261. package/node_modules/eventsource/node_modules/eventsource-parser/package.json +96 -0
  262. package/node_modules/eventsource/node_modules/eventsource-parser/src/errors.ts +44 -0
  263. package/node_modules/eventsource/node_modules/eventsource-parser/src/index.ts +3 -0
  264. package/node_modules/eventsource/node_modules/eventsource-parser/src/parse.ts +576 -0
  265. package/node_modules/eventsource/node_modules/eventsource-parser/src/stream.ts +118 -0
  266. package/node_modules/eventsource/node_modules/eventsource-parser/src/types.ts +138 -0
  267. package/node_modules/eventsource/package.json +103 -0
  268. package/node_modules/eventsource/src/EventSource.ts +844 -0
  269. package/node_modules/eventsource/src/errors.ts +141 -0
  270. package/node_modules/eventsource/src/index.ts +3 -0
  271. package/node_modules/eventsource/src/types.ts +166 -0
  272. package/node_modules/eventsource-parser/LICENSE +21 -0
  273. package/node_modules/eventsource-parser/README.md +157 -0
  274. package/node_modules/eventsource-parser/dist/index.cjs +177 -0
  275. package/node_modules/eventsource-parser/dist/index.cjs.map +1 -0
  276. package/node_modules/eventsource-parser/dist/index.d.cts +169 -0
  277. package/node_modules/eventsource-parser/dist/index.d.ts +169 -0
  278. package/node_modules/eventsource-parser/dist/index.js +177 -0
  279. package/node_modules/eventsource-parser/dist/index.js.map +1 -0
  280. package/node_modules/eventsource-parser/dist/stream.cjs +29 -0
  281. package/node_modules/eventsource-parser/dist/stream.cjs.map +1 -0
  282. package/node_modules/eventsource-parser/dist/stream.d.cts +134 -0
  283. package/node_modules/eventsource-parser/dist/stream.d.ts +134 -0
  284. package/node_modules/eventsource-parser/dist/stream.js +30 -0
  285. package/node_modules/eventsource-parser/dist/stream.js.map +1 -0
  286. package/node_modules/eventsource-parser/package.json +92 -0
  287. package/node_modules/eventsource-parser/src/errors.ts +44 -0
  288. package/node_modules/eventsource-parser/src/index.ts +8 -0
  289. package/node_modules/eventsource-parser/src/parse.ts +439 -0
  290. package/node_modules/eventsource-parser/src/stream.ts +107 -0
  291. package/node_modules/eventsource-parser/src/types.ts +122 -0
  292. package/node_modules/eventsource-parser/stream.js +2 -0
  293. package/node_modules/mutative/LICENSE +21 -0
  294. package/node_modules/mutative/README.md +870 -0
  295. package/node_modules/mutative/dist/apply.d.ts +31 -0
  296. package/node_modules/mutative/dist/array.d.ts +45 -0
  297. package/node_modules/mutative/dist/constant.d.ts +8 -0
  298. package/node_modules/mutative/dist/create.d.ts +46 -0
  299. package/node_modules/mutative/dist/current.d.ts +23 -0
  300. package/node_modules/mutative/dist/draft.d.ts +3 -0
  301. package/node_modules/mutative/dist/draftify.d.ts +2 -0
  302. package/node_modules/mutative/dist/error.d.ts +54 -0
  303. package/node_modules/mutative/dist/index.d.mts +1 -0
  304. package/node_modules/mutative/dist/index.d.ts +12 -0
  305. package/node_modules/mutative/dist/index.js +8 -0
  306. package/node_modules/mutative/dist/index.mjs +3 -0
  307. package/node_modules/mutative/dist/interface.d.ts +200 -0
  308. package/node_modules/mutative/dist/internal.d.ts +4 -0
  309. package/node_modules/mutative/dist/makeCreator.d.ts +54 -0
  310. package/node_modules/mutative/dist/map.d.ts +15 -0
  311. package/node_modules/mutative/dist/mutative.cjs.development.js +2126 -0
  312. package/node_modules/mutative/dist/mutative.cjs.development.js.map +1 -0
  313. package/node_modules/mutative/dist/mutative.cjs.production.min.js +2 -0
  314. package/node_modules/mutative/dist/mutative.cjs.production.min.js.map +1 -0
  315. package/node_modules/mutative/dist/mutative.esm.js +2123 -0
  316. package/node_modules/mutative/dist/mutative.esm.js.map +1 -0
  317. package/node_modules/mutative/dist/mutative.esm.mjs +2123 -0
  318. package/node_modules/mutative/dist/mutative.esm.mjs.map +1 -0
  319. package/node_modules/mutative/dist/mutative.esm.production.min.mjs +2 -0
  320. package/node_modules/mutative/dist/mutative.esm.production.min.mjs.map +1 -0
  321. package/node_modules/mutative/dist/mutative.umd.development.js +2132 -0
  322. package/node_modules/mutative/dist/mutative.umd.development.js.map +1 -0
  323. package/node_modules/mutative/dist/mutative.umd.production.min.js +2 -0
  324. package/node_modules/mutative/dist/mutative.umd.production.min.js.map +1 -0
  325. package/node_modules/mutative/dist/original.d.ts +19 -0
  326. package/node_modules/mutative/dist/patch.d.ts +2 -0
  327. package/node_modules/mutative/dist/rawReturn.d.ts +19 -0
  328. package/node_modules/mutative/dist/set.d.ts +14 -0
  329. package/node_modules/mutative/dist/unsafe.d.ts +34 -0
  330. package/node_modules/mutative/dist/utils/cast.d.ts +13 -0
  331. package/node_modules/mutative/dist/utils/copy.d.ts +5 -0
  332. package/node_modules/mutative/dist/utils/deepFreeze.d.ts +1 -0
  333. package/node_modules/mutative/dist/utils/draft.d.ts +27 -0
  334. package/node_modules/mutative/dist/utils/finalize.d.ts +13 -0
  335. package/node_modules/mutative/dist/utils/forEach.d.ts +1 -0
  336. package/node_modules/mutative/dist/utils/index.d.ts +7 -0
  337. package/node_modules/mutative/dist/utils/mark.d.ts +2 -0
  338. package/node_modules/mutative/dist/utils/marker.d.ts +5 -0
  339. package/node_modules/mutative/dist/utils/proto.d.ts +10 -0
  340. package/node_modules/mutative/package.json +142 -0
  341. package/node_modules/mutative/src/apply.ts +239 -0
  342. package/node_modules/mutative/src/array.ts +679 -0
  343. package/node_modules/mutative/src/constant.ts +17 -0
  344. package/node_modules/mutative/src/create.ts +27 -0
  345. package/node_modules/mutative/src/current.ts +206 -0
  346. package/node_modules/mutative/src/draft.ts +489 -0
  347. package/node_modules/mutative/src/draftify.ts +57 -0
  348. package/node_modules/mutative/src/error.ts +129 -0
  349. package/node_modules/mutative/src/index.ts +21 -0
  350. package/node_modules/mutative/src/interface.ts +321 -0
  351. package/node_modules/mutative/src/internal.ts +5 -0
  352. package/node_modules/mutative/src/makeCreator.ts +382 -0
  353. package/node_modules/mutative/src/map.ts +160 -0
  354. package/node_modules/mutative/src/original.ts +28 -0
  355. package/node_modules/mutative/src/patch.ts +386 -0
  356. package/node_modules/mutative/src/rawReturn.ts +41 -0
  357. package/node_modules/mutative/src/set.ts +201 -0
  358. package/node_modules/mutative/src/unsafe.ts +66 -0
  359. package/node_modules/mutative/src/utils/cast.ts +22 -0
  360. package/node_modules/mutative/src/utils/copy.ts +224 -0
  361. package/node_modules/mutative/src/utils/deepFreeze.ts +103 -0
  362. package/node_modules/mutative/src/utils/draft.ts +189 -0
  363. package/node_modules/mutative/src/utils/finalize.ts +232 -0
  364. package/node_modules/mutative/src/utils/forEach.ts +24 -0
  365. package/node_modules/mutative/src/utils/index.ts +7 -0
  366. package/node_modules/mutative/src/utils/mark.ts +11 -0
  367. package/node_modules/mutative/src/utils/marker.ts +34 -0
  368. package/node_modules/mutative/src/utils/proto.ts +38 -0
  369. package/node_modules/uuid/LICENSE.md +9 -0
  370. package/node_modules/uuid/README.md +491 -0
  371. package/node_modules/uuid/dist/index.d.ts +15 -0
  372. package/node_modules/uuid/dist/index.js +14 -0
  373. package/node_modules/uuid/dist/max.d.ts +2 -0
  374. package/node_modules/uuid/dist/max.js +1 -0
  375. package/node_modules/uuid/dist/md5.d.ts +2 -0
  376. package/node_modules/uuid/dist/md5.js +135 -0
  377. package/node_modules/uuid/dist/nil.d.ts +2 -0
  378. package/node_modules/uuid/dist/nil.js +1 -0
  379. package/node_modules/uuid/dist/parse.d.ts +3 -0
  380. package/node_modules/uuid/dist/parse.js +9 -0
  381. package/node_modules/uuid/dist/regex.d.ts +2 -0
  382. package/node_modules/uuid/dist/regex.js +1 -0
  383. package/node_modules/uuid/dist/rng.d.ts +1 -0
  384. package/node_modules/uuid/dist/rng.js +4 -0
  385. package/node_modules/uuid/dist/sha1.d.ts +2 -0
  386. package/node_modules/uuid/dist/sha1.js +70 -0
  387. package/node_modules/uuid/dist/stringify.d.ts +3 -0
  388. package/node_modules/uuid/dist/stringify.js +35 -0
  389. package/node_modules/uuid/dist/types.d.ts +22 -0
  390. package/node_modules/uuid/dist/types.js +1 -0
  391. package/node_modules/uuid/dist/uuid-bin.d.ts +1 -0
  392. package/node_modules/uuid/dist/uuid-bin.js +70 -0
  393. package/node_modules/uuid/dist/v1.d.ts +11 -0
  394. package/node_modules/uuid/dist/v1.js +87 -0
  395. package/node_modules/uuid/dist/v1ToV6.d.ts +3 -0
  396. package/node_modules/uuid/dist/v1ToV6.js +10 -0
  397. package/node_modules/uuid/dist/v3.d.ts +9 -0
  398. package/node_modules/uuid/dist/v3.js +9 -0
  399. package/node_modules/uuid/dist/v35.d.ts +7 -0
  400. package/node_modules/uuid/dist/v35.js +39 -0
  401. package/node_modules/uuid/dist/v4.d.ts +4 -0
  402. package/node_modules/uuid/dist/v4.js +29 -0
  403. package/node_modules/uuid/dist/v5.d.ts +9 -0
  404. package/node_modules/uuid/dist/v5.js +9 -0
  405. package/node_modules/uuid/dist/v6.d.ts +4 -0
  406. package/node_modules/uuid/dist/v6.js +20 -0
  407. package/node_modules/uuid/dist/v6ToV1.d.ts +2 -0
  408. package/node_modules/uuid/dist/v6ToV1.js +10 -0
  409. package/node_modules/uuid/dist/v7.d.ts +9 -0
  410. package/node_modules/uuid/dist/v7.js +68 -0
  411. package/node_modules/uuid/dist/validate.d.ts +2 -0
  412. package/node_modules/uuid/dist/validate.js +5 -0
  413. package/node_modules/uuid/dist/version.d.ts +2 -0
  414. package/node_modules/uuid/dist/version.js +8 -0
  415. package/node_modules/uuid/dist-node/bin/uuid +2 -0
  416. package/node_modules/uuid/dist-node/index.js +14 -0
  417. package/node_modules/uuid/dist-node/max.js +1 -0
  418. package/node_modules/uuid/dist-node/md5.js +11 -0
  419. package/node_modules/uuid/dist-node/nil.js +1 -0
  420. package/node_modules/uuid/dist-node/parse.js +9 -0
  421. package/node_modules/uuid/dist-node/regex.js +1 -0
  422. package/node_modules/uuid/dist-node/rng.js +4 -0
  423. package/node_modules/uuid/dist-node/sha1.js +11 -0
  424. package/node_modules/uuid/dist-node/stringify.js +35 -0
  425. package/node_modules/uuid/dist-node/types.js +1 -0
  426. package/node_modules/uuid/dist-node/uuid-bin.js +70 -0
  427. package/node_modules/uuid/dist-node/v1.js +87 -0
  428. package/node_modules/uuid/dist-node/v1ToV6.js +10 -0
  429. package/node_modules/uuid/dist-node/v3.js +9 -0
  430. package/node_modules/uuid/dist-node/v35.js +39 -0
  431. package/node_modules/uuid/dist-node/v4.js +29 -0
  432. package/node_modules/uuid/dist-node/v5.js +9 -0
  433. package/node_modules/uuid/dist-node/v6.js +20 -0
  434. package/node_modules/uuid/dist-node/v6ToV1.js +10 -0
  435. package/node_modules/uuid/dist-node/v7.js +68 -0
  436. package/node_modules/uuid/dist-node/validate.js +5 -0
  437. package/node_modules/uuid/dist-node/version.js +8 -0
  438. package/node_modules/uuid/package.json +115 -0
  439. package/package.json +80 -4
  440. package/release.json +78 -0
@@ -0,0 +1,722 @@
1
+ import { create } from 'mutative';
2
+ import { immutableDeepMerge } from './utils/object.js';
3
+ import { coerceToDate } from './utils/dates.js';
4
+ export class AttrsStoreClass {
5
+ attrs;
6
+ linkIndex;
7
+ _blobAttrs = null;
8
+ _primaryKeys = null;
9
+ _forwardIdents = null;
10
+ _revIdents = null;
11
+ constructor(attrs, linkIndex) {
12
+ this.attrs = attrs;
13
+ this.linkIndex = linkIndex;
14
+ }
15
+ resetAttrIndexes() {
16
+ this._blobAttrs = null;
17
+ this._primaryKeys = null;
18
+ this._forwardIdents = null;
19
+ this._revIdents = null;
20
+ }
21
+ addAttr(attr) {
22
+ this.attrs[attr.id] = attr;
23
+ this.resetAttrIndexes();
24
+ }
25
+ deleteAttr(attrId) {
26
+ delete this.attrs[attrId];
27
+ this.resetAttrIndexes();
28
+ }
29
+ updateAttr(partialAttr) {
30
+ const attr = this.attrs[partialAttr.id];
31
+ if (!attr)
32
+ return;
33
+ this.attrs[partialAttr.id] = { ...attr, ...partialAttr };
34
+ this.resetAttrIndexes();
35
+ }
36
+ getAttr(id) {
37
+ return this.attrs[id];
38
+ }
39
+ get blobAttrs() {
40
+ if (this._blobAttrs) {
41
+ return this._blobAttrs;
42
+ }
43
+ this._blobAttrs = new Map();
44
+ for (const attr of Object.values(this.attrs)) {
45
+ if (isBlob(attr)) {
46
+ const [_, fwdEtype, fwdLabel] = attr['forward-identity'];
47
+ setInMap(this.blobAttrs, [fwdEtype, fwdLabel], attr);
48
+ }
49
+ }
50
+ return this._blobAttrs;
51
+ }
52
+ get primaryKeys() {
53
+ if (this._primaryKeys) {
54
+ return this._primaryKeys;
55
+ }
56
+ this._primaryKeys = new Map();
57
+ for (const attr of Object.values(this.attrs)) {
58
+ if (attr['primary?']) {
59
+ const [_, fwdEtype] = attr['forward-identity'];
60
+ setInMap(this._primaryKeys, [fwdEtype], attr);
61
+ }
62
+ }
63
+ return this._primaryKeys;
64
+ }
65
+ get forwardIdents() {
66
+ if (this._forwardIdents) {
67
+ return this._forwardIdents;
68
+ }
69
+ this._forwardIdents = new Map();
70
+ for (const attr of Object.values(this.attrs)) {
71
+ const fwdIdent = attr['forward-identity'];
72
+ const [_, fwdEtype, fwdLabel] = fwdIdent;
73
+ setInMap(this._forwardIdents, [fwdEtype, fwdLabel], attr);
74
+ }
75
+ return this._forwardIdents;
76
+ }
77
+ get revIdents() {
78
+ if (this._revIdents) {
79
+ return this._revIdents;
80
+ }
81
+ this._revIdents = new Map();
82
+ for (const attr of Object.values(this.attrs)) {
83
+ const revIdent = attr['reverse-identity'];
84
+ if (revIdent) {
85
+ const [_, revEtype, revLabel] = revIdent;
86
+ setInMap(this._revIdents, [revEtype, revLabel], attr);
87
+ }
88
+ }
89
+ return this._revIdents;
90
+ }
91
+ toJSON() {
92
+ return { attrs: this.attrs, linkIndex: this.linkIndex };
93
+ }
94
+ }
95
+ function hasEA(attr) {
96
+ return attr['cardinality'] === 'one';
97
+ }
98
+ function isRef(attr) {
99
+ return attr['value-type'] === 'ref';
100
+ }
101
+ export function isBlob(attr) {
102
+ return attr['value-type'] === 'blob';
103
+ }
104
+ function getAttr(attrs, attrId) {
105
+ return attrs[attrId];
106
+ }
107
+ export function getInMap(obj, path) {
108
+ return path.reduce((acc, key) => acc && acc.get(key), obj);
109
+ }
110
+ function deleteInMap(m, path) {
111
+ if (path.length === 0)
112
+ throw new Error('path must have at least one element');
113
+ if (path.length === 1) {
114
+ m.delete(path[0]);
115
+ return;
116
+ }
117
+ const [head, ...tail] = path;
118
+ if (!m.has(head))
119
+ return;
120
+ deleteInMap(m.get(head), tail);
121
+ }
122
+ function setInMap(m, path, value) {
123
+ let current = m;
124
+ const lastI = path.length - 1;
125
+ for (let i = 0; i < lastI; i++) {
126
+ const part = path[i];
127
+ let nextMap = current.get(part);
128
+ if (nextMap === undefined) {
129
+ nextMap = new Map();
130
+ current.set(part, nextMap);
131
+ }
132
+ current = nextMap;
133
+ }
134
+ if (lastI > -1) {
135
+ current.set(path[lastI], value);
136
+ }
137
+ }
138
+ function isDateAttr(attr) {
139
+ return attr['checked-data-type'] === 'date';
140
+ }
141
+ function createTripleIndexes(attrsStore, triples, useDateObjects) {
142
+ const eav = new Map();
143
+ const aev = new Map();
144
+ const vae = new Map();
145
+ for (const triple of triples) {
146
+ let [eid, aid, v] = triple;
147
+ const attr = attrsStore.getAttr(aid);
148
+ if (!attr) {
149
+ console.warn('no such attr', aid, eid);
150
+ continue;
151
+ }
152
+ if (attr['checked-data-type'] === 'date' && useDateObjects) {
153
+ v = coerceToDate(v);
154
+ triple[2] = v;
155
+ }
156
+ if (isRef(attr)) {
157
+ setInMap(vae, [v, aid, eid], triple);
158
+ }
159
+ setInMap(eav, [eid, aid, v], triple);
160
+ setInMap(aev, [aid, eid, v], triple);
161
+ }
162
+ return { eav, aev, vae };
163
+ }
164
+ function createAttrIndexes(attrs) {
165
+ const blobAttrs = new Map();
166
+ const primaryKeys = new Map();
167
+ const forwardIdents = new Map();
168
+ const revIdents = new Map();
169
+ for (const attr of Object.values(attrs)) {
170
+ const fwdIdent = attr['forward-identity'];
171
+ const [_, fwdEtype, fwdLabel] = fwdIdent;
172
+ const revIdent = attr['reverse-identity'];
173
+ setInMap(forwardIdents, [fwdEtype, fwdLabel], attr);
174
+ if (isBlob(attr)) {
175
+ setInMap(blobAttrs, [fwdEtype, fwdLabel], attr);
176
+ }
177
+ if (attr['primary?']) {
178
+ setInMap(primaryKeys, [fwdEtype], attr);
179
+ }
180
+ if (revIdent) {
181
+ const [_, revEtype, revLabel] = revIdent;
182
+ setInMap(revIdents, [revEtype, revLabel], attr);
183
+ }
184
+ }
185
+ return { blobAttrs, primaryKeys, forwardIdents, revIdents };
186
+ }
187
+ export function toJSON(store) {
188
+ return {
189
+ triples: allMapValues(store.eav, 3),
190
+ cardinalityInference: store.cardinalityInference,
191
+ useDateObjects: store.useDateObjects,
192
+ version: 1,
193
+ };
194
+ }
195
+ export function fromJSON(attrsStore, storeJSON) {
196
+ return createStore(attrsStore, storeJSON.triples, storeJSON.cardinalityInference, storeJSON.useDateObjects);
197
+ }
198
+ export function attrsStoreFromJSON(attrsStoreJSON, storeJSON) {
199
+ if (attrsStoreJSON) {
200
+ return new AttrsStoreClass(attrsStoreJSON.attrs, attrsStoreJSON.linkIndex);
201
+ }
202
+ if (storeJSON && '__type' in storeJSON) {
203
+ return new AttrsStoreClass(storeJSON.attrs, storeJSON.linkIndex);
204
+ }
205
+ }
206
+ export function hasTriple(store, [e, a, v]) {
207
+ return getInMap(store.eav, [e, a, v]) !== undefined;
208
+ }
209
+ export function hasEntity(store, e) {
210
+ return getInMap(store.eav, [e]) !== undefined;
211
+ }
212
+ export function createStore(attrsStore, triples, enableCardinalityInference, useDateObjects) {
213
+ const store = createTripleIndexes(attrsStore, triples, useDateObjects);
214
+ store.cardinalityInference = enableCardinalityInference;
215
+ store.useDateObjects = useDateObjects;
216
+ return store;
217
+ }
218
+ // We may have local triples with lookup refs in them,
219
+ // we need to convert those lookup refs to eids to insert them
220
+ // into the store. If we can't find the lookup ref locally,
221
+ // then we drop the triple and have to wait for the server response
222
+ // to see the optimistic updates.
223
+ function resolveLookupRefs(store, triple) {
224
+ let eid;
225
+ // Check if `e` is a lookup ref
226
+ if (Array.isArray(triple[0])) {
227
+ const [a, v] = triple[0];
228
+ const eMaps = store.aev.get(a);
229
+ if (!eMaps) {
230
+ // We don't have the attr, so don't try to add the
231
+ // triple to the store
232
+ return null;
233
+ }
234
+ // This would be a lot more efficient with a ave index
235
+ const triples = allMapValues(eMaps, 2);
236
+ eid = triples.find((x) => x[2] === v)?.[0];
237
+ }
238
+ else {
239
+ eid = triple[0];
240
+ }
241
+ if (!eid) {
242
+ // We don't know the eid that the ref refers to, so
243
+ // we can't add the triple to the store.
244
+ return null;
245
+ }
246
+ // Check if v is a lookup ref
247
+ const lookupV = triple[2];
248
+ if (Array.isArray(lookupV) &&
249
+ lookupV.length === 2 &&
250
+ store.aev.get(lookupV[0])) {
251
+ const [a, v] = lookupV;
252
+ const eMaps = store.aev.get(a);
253
+ if (!eMaps) {
254
+ // We don't have the attr, so don't try to add the
255
+ // triple to the store
256
+ return null;
257
+ }
258
+ const triples = allMapValues(eMaps, 2);
259
+ const value = triples.find((x) => x[2] === v)?.[0];
260
+ if (!value) {
261
+ return null;
262
+ }
263
+ const [_e, aid, _v, ...rest] = triple;
264
+ return [eid, aid, value, ...rest];
265
+ }
266
+ else {
267
+ const [_, ...rest] = triple;
268
+ return [eid, ...rest];
269
+ }
270
+ }
271
+ export function retractTriple(store, attrsStore, rawTriple) {
272
+ const triple = resolveLookupRefs(store, rawTriple);
273
+ if (!triple) {
274
+ return;
275
+ }
276
+ const [eid, aid, v] = triple;
277
+ const attr = attrsStore.getAttr(aid);
278
+ if (!attr) {
279
+ return;
280
+ }
281
+ deleteInMap(store.eav, [eid, aid, v]);
282
+ deleteInMap(store.aev, [aid, eid, v]);
283
+ if (isRef(attr)) {
284
+ deleteInMap(store.vae, [v, aid, eid]);
285
+ }
286
+ }
287
+ let _seed = 0;
288
+ function getCreatedAt(store, attr, triple) {
289
+ const [eid, aid, v] = triple;
290
+ let createdAt;
291
+ const t = getInMap(store.eav, [eid, aid, v]);
292
+ if (t) {
293
+ createdAt = t[3];
294
+ }
295
+ /**
296
+ * (XXX)
297
+ * Two hacks here, for generating a `createdAt`
298
+ *
299
+ * 1. We multiply Date.now() by 10, to make sure that
300
+ * `createdAt` is always greater than anything the server
301
+ * could return
302
+ *
303
+ * We do this because right now we know we _only_ insert
304
+ * triples as optimistic updates.
305
+ *
306
+ * 2. We increment by `_seed`, to make sure there are no
307
+ * two triples with the same `createdAt`. This is
308
+ * done to make tests more predictable.
309
+ *
310
+ * We may need to rethink this. Because we * 10, we can't
311
+ * use this value as an _actual_ `createdAt` timestamp.
312
+ * Eventually we may want too though; For example, we could
313
+ * use `createdAt` for each triple, to infer a `createdAt` and
314
+ * `updatedAt` value for each object.
315
+ */
316
+ return createdAt || Date.now() * 10 + _seed++;
317
+ }
318
+ export function addTriple(store, attrsStore, rawTriple) {
319
+ const triple = resolveLookupRefs(store, rawTriple);
320
+ if (!triple) {
321
+ return;
322
+ }
323
+ let [eid, aid, v] = triple;
324
+ const attr = attrsStore.getAttr(aid);
325
+ if (!attr) {
326
+ // (XXX): Due to the way we're handling attrs, it's
327
+ // possible to enter a state where we receive a triple without an attr.
328
+ // See: https://github.com/jsventures/instant-local/pull/132 for details.
329
+ // For now, if we receive a command without an attr, we no-op.
330
+ return;
331
+ }
332
+ if (attr['checked-data-type'] === 'date' && store.useDateObjects) {
333
+ v = coerceToDate(v);
334
+ }
335
+ const existingTriple = getInMap(store.eav, [eid, aid, v]);
336
+ // Reuse the created_at for a triple if it's already in the store.
337
+ // Prevents updates from temporarily pushing an entity to the top
338
+ // while waiting for the server response.
339
+ const t = existingTriple?.[3] ?? getCreatedAt(store, attr, triple);
340
+ const enhancedTriple = [eid, aid, v, t];
341
+ if (hasEA(attr)) {
342
+ setInMap(store.eav, [eid, aid], new Map([[v, enhancedTriple]]));
343
+ setInMap(store.aev, [aid, eid], new Map([[v, enhancedTriple]]));
344
+ }
345
+ else {
346
+ setInMap(store.eav, [eid, aid, v], enhancedTriple);
347
+ setInMap(store.aev, [aid, eid, v], enhancedTriple);
348
+ }
349
+ if (isRef(attr)) {
350
+ setInMap(store.vae, [v, aid, eid], enhancedTriple);
351
+ }
352
+ }
353
+ function mergeTriple(store, attrsStore, rawTriple) {
354
+ const triple = resolveLookupRefs(store, rawTriple);
355
+ if (!triple) {
356
+ return;
357
+ }
358
+ const [eid, aid, update] = triple;
359
+ const attr = attrsStore.getAttr(aid);
360
+ if (!attr)
361
+ return;
362
+ if (!isBlob(attr))
363
+ throw new Error('merge operation is not supported for links');
364
+ const eavValuesMap = getInMap(store.eav, [eid, aid]);
365
+ if (!eavValuesMap)
366
+ return;
367
+ const currentTriple = eavValuesMap.values().next()?.value;
368
+ if (!currentTriple)
369
+ return;
370
+ const currentValue = currentTriple[2];
371
+ const updatedValue = immutableDeepMerge(currentValue, update);
372
+ const enhancedTriple = [
373
+ eid,
374
+ aid,
375
+ updatedValue,
376
+ getCreatedAt(store, attr, currentTriple),
377
+ ];
378
+ setInMap(store.eav, [eid, aid], new Map([[updatedValue, enhancedTriple]]));
379
+ setInMap(store.aev, [aid, eid], new Map([[updatedValue, enhancedTriple]]));
380
+ }
381
+ function deleteEntity(store, attrsStore, args) {
382
+ const [lookup, etype] = args;
383
+ const triple = resolveLookupRefs(store, [lookup]);
384
+ if (!triple) {
385
+ return;
386
+ }
387
+ const [id] = triple;
388
+ // delete forward links and attributes + cardinality one links
389
+ const eMap = store.eav.get(id);
390
+ if (eMap) {
391
+ for (const a of eMap.keys()) {
392
+ const attr = attrsStore.getAttr(a);
393
+ // delete cascade refs
394
+ if (attr && attr['on-delete-reverse'] === 'cascade') {
395
+ allMapValues(eMap.get(a), 1).forEach(([e, a, v]) => deleteEntity(store, attrsStore, [v, attr['reverse-identity']?.[1]]));
396
+ }
397
+ if (
398
+ // Fall back to deleting everything if we've rehydrated tx-steps from
399
+ // the store that didn't set `etype` in deleteEntity
400
+ !etype ||
401
+ // If we don't know about the attr, let's just get rid of it
402
+ !attr ||
403
+ // Make sure it matches the etype
404
+ attr['forward-identity']?.[1] === etype) {
405
+ deleteInMap(store.aev, [a, id]);
406
+ deleteInMap(store.eav, [id, a]);
407
+ }
408
+ }
409
+ // Clear out the eav index for `id` if we deleted all of the attributes
410
+ if (eMap.size === 0) {
411
+ deleteInMap(store.eav, [id]);
412
+ }
413
+ }
414
+ // delete reverse links
415
+ const vaeTriples = store.vae.get(id) && allMapValues(store.vae.get(id), 2);
416
+ if (vaeTriples) {
417
+ vaeTriples.forEach((triple) => {
418
+ const [e, a, v] = triple;
419
+ const attr = attrsStore.getAttr(a);
420
+ if (!etype || !attr || attr['reverse-identity']?.[1] === etype) {
421
+ deleteInMap(store.eav, [e, a, v]);
422
+ deleteInMap(store.aev, [a, e, v]);
423
+ deleteInMap(store.vae, [v, a, e]);
424
+ }
425
+ if (attr &&
426
+ attr['on-delete'] === 'cascade' &&
427
+ attr['reverse-identity']?.[1] === etype) {
428
+ deleteEntity(store, attrsStore, [e, attr['forward-identity']?.[1]]);
429
+ }
430
+ });
431
+ }
432
+ // Clear out vae index for `id` if we deleted all the reverse attributes
433
+ if (store.vae.get(id)?.size === 0) {
434
+ deleteInMap(store.vae, [id]);
435
+ }
436
+ }
437
+ // (XXX): Whenever we change/delete attrs,
438
+ // We indiscriminately reset the index map.
439
+ // There are lots of opportunities for optimization:
440
+ // * We _only_ need to run this indexes change. We could detect that
441
+ // * We could batch this reset at the end
442
+ // * We could add an ave index for all triples, so removing the
443
+ // right triples is easy and fast.
444
+ function resetIndexMap(store, attrsStore, newTriples) {
445
+ const newIndexMap = createTripleIndexes(attrsStore, newTriples, store.useDateObjects);
446
+ Object.keys(newIndexMap).forEach((key) => {
447
+ store[key] = newIndexMap[key];
448
+ });
449
+ }
450
+ function addAttr(attrsStore, [attr]) {
451
+ attrsStore.addAttr(attr);
452
+ }
453
+ function getAllTriples(store) {
454
+ return allMapValues(store.eav, 3);
455
+ }
456
+ function deleteAttr(store, attrsStore, [id]) {
457
+ if (!attrsStore.getAttr(id))
458
+ return;
459
+ const newTriples = getAllTriples(store).filter(([_, aid]) => aid !== id);
460
+ attrsStore.deleteAttr(id);
461
+ resetIndexMap(store, attrsStore, newTriples);
462
+ }
463
+ function updateAttr(store, attrsStore, [partialAttr]) {
464
+ const attr = attrsStore.getAttr(partialAttr.id);
465
+ if (!attr)
466
+ return;
467
+ attrsStore.updateAttr(partialAttr);
468
+ resetIndexMap(store, attrsStore, getAllTriples(store));
469
+ }
470
+ function applyTxStep(store, attrsStore, txStep) {
471
+ const [action, ...args] = txStep;
472
+ switch (action) {
473
+ case 'add-triple':
474
+ addTriple(store, attrsStore, args);
475
+ break;
476
+ case 'deep-merge-triple':
477
+ mergeTriple(store, attrsStore, args);
478
+ break;
479
+ case 'retract-triple':
480
+ retractTriple(store, attrsStore, args);
481
+ break;
482
+ case 'delete-entity':
483
+ deleteEntity(store, attrsStore, args);
484
+ break;
485
+ case 'add-attr':
486
+ addAttr(attrsStore, args);
487
+ break;
488
+ case 'delete-attr':
489
+ deleteAttr(store, attrsStore, args);
490
+ break;
491
+ case 'update-attr':
492
+ updateAttr(store, attrsStore, args);
493
+ break;
494
+ case 'restore-attr':
495
+ break;
496
+ case 'rule-params':
497
+ break;
498
+ default:
499
+ throw new Error(`unhandled transaction action: ${action}`);
500
+ }
501
+ }
502
+ export function allMapValues(m, level, res = []) {
503
+ if (!m) {
504
+ return res;
505
+ }
506
+ if (level === 0) {
507
+ return res;
508
+ }
509
+ if (level === 1) {
510
+ for (const v of m.values()) {
511
+ res.push(v);
512
+ }
513
+ return res;
514
+ }
515
+ for (const v of m.values()) {
516
+ allMapValues(v, level - 1, res);
517
+ }
518
+ return res;
519
+ }
520
+ function triplesByValue(store, m, v) {
521
+ const res = [];
522
+ if (v?.hasOwnProperty('$not')) {
523
+ for (const candidate of m.keys()) {
524
+ if (v.$not !== candidate) {
525
+ res.push(m.get(candidate));
526
+ }
527
+ }
528
+ return res;
529
+ }
530
+ if (v?.hasOwnProperty('$isNull')) {
531
+ const { attrId, isNull, reverse } = v.$isNull;
532
+ if (reverse) {
533
+ for (const candidate of m.keys()) {
534
+ const vMap = store.vae.get(candidate);
535
+ const isValNull = !vMap || !vMap.get(attrId);
536
+ if (isNull ? isValNull : !isValNull) {
537
+ res.push(m.get(candidate));
538
+ }
539
+ }
540
+ }
541
+ else {
542
+ const aMap = store.aev.get(attrId);
543
+ for (const candidate of m.keys()) {
544
+ const isValNull = !aMap || aMap.get(candidate)?.get(null) || !aMap.get(candidate);
545
+ if (isNull ? isValNull : !isValNull) {
546
+ res.push(m.get(candidate));
547
+ }
548
+ }
549
+ }
550
+ return res;
551
+ }
552
+ if (v?.$comparator) {
553
+ // TODO: A sorted index would be nice here
554
+ return allMapValues(m, 1).filter(v.$op);
555
+ }
556
+ const values = v.in || v.$in || [v];
557
+ for (const value of values) {
558
+ const triple = m.get(value);
559
+ if (triple) {
560
+ res.push(triple);
561
+ }
562
+ }
563
+ return res;
564
+ }
565
+ // A poor man's pattern matching
566
+ // Returns either eav, ea, ev, av, v, or ''
567
+ function whichIdx(e, a, v) {
568
+ let res = '';
569
+ if (e !== undefined) {
570
+ res += 'e';
571
+ }
572
+ if (a !== undefined) {
573
+ res += 'a';
574
+ }
575
+ if (v !== undefined) {
576
+ res += 'v';
577
+ }
578
+ return res;
579
+ }
580
+ export function getTriples(store, [e, a, v]) {
581
+ const idx = whichIdx(e, a, v);
582
+ switch (idx) {
583
+ case 'e': {
584
+ const eMap = store.eav.get(e);
585
+ return allMapValues(eMap, 2);
586
+ }
587
+ case 'ea': {
588
+ const aMap = store.eav.get(e)?.get(a);
589
+ return allMapValues(aMap, 1);
590
+ }
591
+ case 'eav': {
592
+ const aMap = store.eav.get(e)?.get(a);
593
+ if (!aMap) {
594
+ return [];
595
+ }
596
+ return triplesByValue(store, aMap, v);
597
+ }
598
+ case 'ev': {
599
+ const eMap = store.eav.get(e);
600
+ if (!eMap) {
601
+ return [];
602
+ }
603
+ const res = [];
604
+ for (const aMap of eMap.values()) {
605
+ res.push(...triplesByValue(store, aMap, v));
606
+ }
607
+ return res;
608
+ }
609
+ case 'a': {
610
+ const aMap = store.aev.get(a);
611
+ return allMapValues(aMap, 2);
612
+ }
613
+ case 'av': {
614
+ const aMap = store.aev.get(a);
615
+ if (!aMap) {
616
+ return [];
617
+ }
618
+ const res = [];
619
+ for (const eMap of aMap.values()) {
620
+ res.push(...triplesByValue(store, eMap, v));
621
+ }
622
+ return res;
623
+ }
624
+ case 'v': {
625
+ const res = [];
626
+ for (const eMap of store.eav.values()) {
627
+ for (const aMap of eMap.values()) {
628
+ res.push(...triplesByValue(store, aMap, v));
629
+ }
630
+ }
631
+ return res;
632
+ }
633
+ default: {
634
+ return allMapValues(store.eav, 3);
635
+ }
636
+ }
637
+ }
638
+ export function getAsObject(store, attrs, e) {
639
+ const obj = {};
640
+ if (!attrs) {
641
+ return obj;
642
+ }
643
+ for (const [label, attr] of attrs.entries()) {
644
+ const aMap = store.eav.get(e)?.get(attr.id);
645
+ const triples = allMapValues(aMap, 1);
646
+ for (const triple of triples) {
647
+ obj[label] = triple[2];
648
+ }
649
+ }
650
+ return obj;
651
+ }
652
+ export function getAttrByFwdIdentName(attrsStore, inputEtype, inputLabel) {
653
+ return attrsStore.forwardIdents.get(inputEtype)?.get(inputLabel);
654
+ }
655
+ export function getAttrByReverseIdentName(attrsStore, inputEtype, inputLabel) {
656
+ return attrsStore.revIdents.get(inputEtype)?.get(inputLabel);
657
+ }
658
+ export function getBlobAttrs(attrsStore, etype) {
659
+ return attrsStore.blobAttrs.get(etype);
660
+ }
661
+ export function getPrimaryKeyAttr(attrsStore, etype) {
662
+ const fromPrimary = attrsStore.primaryKeys.get(etype);
663
+ if (fromPrimary) {
664
+ return fromPrimary;
665
+ }
666
+ return attrsStore.forwardIdents.get(etype)?.get('id');
667
+ }
668
+ function findTriple(store, attrsStore, rawTriple) {
669
+ const triple = resolveLookupRefs(store, rawTriple);
670
+ if (!triple) {
671
+ return;
672
+ }
673
+ const [eid, aid, v] = triple;
674
+ const attr = attrsStore.getAttr(aid);
675
+ if (!attr) {
676
+ // (XXX): Due to the way we're handling attrs, it's
677
+ // possible to enter a state where we receive a triple without an attr.
678
+ // See: https://github.com/jsventures/instant-local/pull/132 for details.
679
+ // For now, if we receive a command without an attr, we no-op.
680
+ return;
681
+ }
682
+ return getInMap(store.eav, [eid, aid]);
683
+ }
684
+ export function transact(store, attrsStore, txSteps) {
685
+ const txStepsFiltered = txSteps.filter(([action, eid, attrId, value, opts]) => {
686
+ if (action !== 'add-triple' && action !== 'deep-merge-triple') {
687
+ return true;
688
+ }
689
+ const mode = opts?.mode;
690
+ if (mode !== 'create' && mode !== 'update') {
691
+ return true;
692
+ }
693
+ let exists = false;
694
+ const attr = attrsStore.getAttr(attrId);
695
+ if (attr) {
696
+ const idAttr = getPrimaryKeyAttr(attrsStore, attr['forward-identity'][1]);
697
+ exists = !!findTriple(store, attrsStore, [
698
+ eid,
699
+ idAttr?.id,
700
+ eid,
701
+ ]);
702
+ }
703
+ if (mode === 'create' && exists) {
704
+ return false;
705
+ }
706
+ if (mode === 'update' && !exists) {
707
+ return false;
708
+ }
709
+ return true;
710
+ });
711
+ return create({ store, attrsStore }, (draft) => {
712
+ txStepsFiltered.forEach((txStep) => {
713
+ applyTxStep(draft.store, draft.attrsStore, txStep);
714
+ });
715
+ }, {
716
+ mark: (target) => {
717
+ if (target instanceof AttrsStoreClass) {
718
+ return 'immutable';
719
+ }
720
+ },
721
+ });
722
+ }