@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,679 @@
1
+ import type { ProxyDraft } from './interface';
2
+ import { PROXY_DRAFT } from './constant';
3
+ import { internal } from './internal';
4
+ import {
5
+ ensureShallowCopy,
6
+ getProxyDraft,
7
+ isDraftable,
8
+ isEqual,
9
+ isPlainArray,
10
+ latest,
11
+ markChanged,
12
+ markFinalization,
13
+ } from './utils';
14
+ import { checksReads } from './unsafe';
15
+
16
+ const arrayProto = Array.prototype;
17
+ const arrayIncludes = arrayProto.includes;
18
+ const hasOwn = Object.prototype.hasOwnProperty;
19
+
20
+ // Receivers are recognized by identity only, so a borrowed method never reads
21
+ // a property of an object that is not one of these drafts. The array whose
22
+ // optimized method was read last is kept here with its producer's revoke list.
23
+ // `create` releases both when that producer ends, including failures while
24
+ // inspecting or finalizing the recipe's return value. Drafts returned by
25
+ // `create(base)` without a recipe have no such end and are only registered
26
+ // weakly.
27
+ let recentProxy: object | null = null;
28
+ let recentRevoke: unknown[] | null = null;
29
+ // Arrays of a live producer whose methods were read before another array's,
30
+ // as in `a.unshift(b.shift())`. Membership checks run no Proxy trap.
31
+ const arrayProxies = new WeakSet<object>();
32
+
33
+ /**
34
+ * Records that the get trap handed out an optimized method of `target`. Only
35
+ * a switch between arrays of a live producer adds a weak-collection entry, so
36
+ * the common case of one array per producer allocates nothing.
37
+ */
38
+ export function trackArrayMethod(target: ProxyDraft) {
39
+ const proxy = target.proxy!;
40
+ if (proxy !== recentProxy) {
41
+ if (recentRevoke !== null && recentRevoke.length > 0) {
42
+ arrayProxies.add(recentProxy!);
43
+ }
44
+ if (target.finalities.scoped) {
45
+ recentProxy = proxy;
46
+ recentRevoke = target.finalities.revoke;
47
+ } else {
48
+ arrayProxies.add(proxy);
49
+ recentProxy = null;
50
+ recentRevoke = null;
51
+ }
52
+ }
53
+ }
54
+
55
+ /**
56
+ * Called by `create` whenever a producer ends, normally or by an error, so
57
+ * this module keeps no reference to its drafts. Another producer's entry, such
58
+ * as an outer producer's, is left in place.
59
+ */
60
+ export function releaseArrayMethods(revoke: unknown[]) {
61
+ if (recentRevoke === revoke) {
62
+ recentProxy = null;
63
+ recentRevoke = null;
64
+ }
65
+ }
66
+
67
+ function canExecute(value: any) {
68
+ return (
69
+ (typeof value === 'object' && value !== null) || typeof value === 'function'
70
+ );
71
+ }
72
+
73
+ /**
74
+ * The array draft behind `this` when a method may run natively on its copy:
75
+ * plain arrays only, outside `current()` and without a custom mark.
76
+ */
77
+ function nativeState(self: any): ProxyDraft | null {
78
+ if (self !== recentProxy && !arrayProxies.has(self)) return null;
79
+ const target: ProxyDraft = self[PROXY_DRAFT];
80
+ return !target.finalized &&
81
+ !target.options.mark &&
82
+ isPlainArray(target.original)
83
+ ? target
84
+ : null;
85
+ }
86
+
87
+ // ToIntegerOrInfinity: the unary plus applies ToNumber, which rejects BigInt
88
+ // and Symbol values like the array methods do.
89
+ const toInteger = (value: any) => Math.trunc(+value) || 0;
90
+
91
+ // A relative index argument resolved against `length`, as the array methods do.
92
+ function relativeIndex(value: any, length: number, fallback: number) {
93
+ if (value === undefined) return fallback;
94
+ const integer = toInteger(value);
95
+ return integer < 0
96
+ ? Math.max(length + integer, 0)
97
+ : Math.min(integer, length);
98
+ }
99
+
100
+ // The native-method bookkeeping of an array draft, created on first use.
101
+ function arrayState(target: ProxyDraft) {
102
+ return (target.arrayState ??= {
103
+ relocated: false,
104
+ diffStart: 0,
105
+ diffEnd: 0,
106
+ baseRefs: null,
107
+ delta: 0,
108
+ lookups: 0,
109
+ inert: null,
110
+ dense: null,
111
+ });
112
+ }
113
+
114
+ // Moving methods leave sparse arrays to the proxy, where deleting a present
115
+ // index assigns undefined; patches rebuild changed holes separately. A hole
116
+ // reads as `undefined`, so an array in which the `includes` builtin finds no
117
+ // `undefined` has none; that scan is fast for every kind of array. Arrays that
118
+ // hold `undefined` are checked index by index with `in`, the HasProperty check
119
+ // of the native algorithms, which costs several times more per element once
120
+ // many array shapes have passed through it. Elements that are `undefined` are
121
+ // ordinary values and move natively.
122
+ function hasHoles(array: any[]) {
123
+ if (!arrayIncludes.call(array, undefined)) return false;
124
+ for (let index = 0; index < array.length; index += 1) {
125
+ if (!(index in array)) return true;
126
+ }
127
+ return false;
128
+ }
129
+
130
+ // Cached until an assignment past the end or a length change can leave holes.
131
+ function isDense(target: ProxyDraft) {
132
+ const state = arrayState(target);
133
+ let dense = state.dense;
134
+ if (dense === null) dense = state.dense = !hasHoles(latest(target));
135
+ return dense;
136
+ }
137
+
138
+ // Original index of each element of the original array, built once elements
139
+ // have been moved natively and identity against the index no longer works.
140
+ function baseIndices(target: ProxyDraft) {
141
+ const state = arrayState(target);
142
+ let indices = state.baseRefs;
143
+ if (indices === null) {
144
+ indices = state.baseRefs = new Map();
145
+ const original = target.original;
146
+ for (let index = 0; index < original.length; index += 1) {
147
+ indices.set(original[index], index);
148
+ }
149
+ }
150
+ return indices;
151
+ }
152
+
153
+ /**
154
+ * The original index of `value`, found at `index` once elements have moved
155
+ * natively, or undefined when it is not an element of the original array. The
156
+ * first few lookups find the index the map of original indices holds for a
157
+ * repeated element without indexing the array; later ones build the map.
158
+ */
159
+ function baseIndexOf(target: ProxyDraft, value: any, index: number) {
160
+ const state = arrayState(target);
161
+ if (state.baseRefs === null && state.lookups < 8) {
162
+ state.lookups += 1;
163
+ const original = target.original;
164
+ // The element is checked first where the last move took it from.
165
+ let found = +index + state.delta!;
166
+ if (!(found >= 0 && original[found] === value)) {
167
+ found = arrayProto.lastIndexOf.call(original, value);
168
+ return found === -1 ? undefined : found;
169
+ }
170
+ // Later copies of the element are found by searching forward, which V8
171
+ // runs on its fast path for frozen arrays too, unlike `lastIndexOf`. After
172
+ // 16 copies, each search starts twice as far ahead as the one before; the
173
+ // last copy then lies before the start of the first search that finds
174
+ // none, and is searched for backward from there, not from the end.
175
+ let step = 1;
176
+ for (
177
+ let next, copies = 0;
178
+ (next = arrayProto.indexOf.call(original, value, found + step)) !== -1;
179
+ ) {
180
+ found = next;
181
+ if (++copies > 16) step *= 2;
182
+ }
183
+ return step > 1
184
+ ? arrayProto.lastIndexOf.call(original, value, found + step - 1)
185
+ : found;
186
+ }
187
+ return baseIndices(target).get(value);
188
+ }
189
+
190
+ /**
191
+ * The original index under which a read of `value` at `index` drafts it, or
192
+ * -1 when the read hands it out as is: an element at its original index, or,
193
+ * once native operations moved elements, any element of the original array
194
+ * except a value the recipe assigned at `index`, whose record moves along
195
+ * with it. Reads, searches and removals all decide by it.
196
+ */
197
+ export function baseIndex(target: ProxyDraft, value: any, index: number) {
198
+ if (target.original[index] === value) return index;
199
+ const state = target.arrayState;
200
+ if (
201
+ state === null ||
202
+ !state.relocated ||
203
+ target.assignedMap!.get(String(index))
204
+ ) {
205
+ return -1;
206
+ }
207
+ const found = baseIndexOf(target, value, index);
208
+ return found === undefined ? -1 : found;
209
+ }
210
+
211
+ // The draft this array created for `index`, if any.
212
+ function childAt(target: ProxyDraft, index: number) {
213
+ return target.child !== null && target.childKey === String(index)
214
+ ? target.child
215
+ : target.children?.[index];
216
+ }
217
+
218
+ // Registers a draft created by this array at `index`, like the get trap does.
219
+ function registerChild(target: ProxyDraft, index: number, draft: any) {
220
+ if (target.child === null) {
221
+ target.child = draft;
222
+ target.childKey = String(index);
223
+ } else {
224
+ (target.children ??= [])[index] = draft;
225
+ }
226
+ }
227
+
228
+ // Bookkeeping for a value placed at `index` natively, like the set trap does:
229
+ // the original element of `index` is not recorded as assigned there, so a read
230
+ // drafts it, there and wherever it moves next, as on the proxy path.
231
+ function registerAssigned(target: ProxyDraft, index: number, value: any) {
232
+ const key = String(index);
233
+ const state = target.arrayState;
234
+ if (state !== null && canExecute(value)) state.inert = null;
235
+ const original = target.original;
236
+ if (hasOwn.call(original, index) && isEqual(value, original[index])) return;
237
+ target.assignedMap!.set(key, true);
238
+ if (typeof value === 'object' && value !== null) {
239
+ markFinalization(target, key, value);
240
+ }
241
+ }
242
+
243
+ // Only primitives have no conversion hooks. Functions can implement their
244
+ // own toString or Symbol.toPrimitive, just like objects. Cached until either
245
+ // kind of reference is assigned.
246
+ function isInert(target: ProxyDraft) {
247
+ const state = arrayState(target);
248
+ let inert = state.inert;
249
+ if (inert === null) {
250
+ const source = latest(target);
251
+ inert = true;
252
+ for (let index = 0; index < source.length; index += 1) {
253
+ if (canExecute(source[index])) {
254
+ inert = false;
255
+ break;
256
+ }
257
+ }
258
+ state.inert = inert;
259
+ }
260
+ return inert;
261
+ }
262
+
263
+ // Records that a native operation may have changed the indices in
264
+ // [from, to) and that elements may have moved away from their original index.
265
+ function markRange(target: ProxyDraft, from: number, to: number) {
266
+ const state = arrayState(target);
267
+ if (state.diffEnd > state.diffStart) {
268
+ state.diffStart = Math.min(state.diffStart, from);
269
+ state.diffEnd = Math.max(state.diffEnd, to);
270
+ } else {
271
+ state.diffStart = from;
272
+ state.diffEnd = to;
273
+ }
274
+ state.relocated = true;
275
+ }
276
+
277
+ /**
278
+ * After the proxy lengthened an array draft, by its length or by an assignment
279
+ * past its end, holes follow. An index that the array exposes again below the
280
+ * original length lost its element to a shorter length earlier; no assignment
281
+ * records such an index, and a native move may have dropped one, so patches
282
+ * compare it. Marking the range as moved leaves reads as they are: an exposed
283
+ * index holds a hole, and an assigned value is handed out as it is.
284
+ */
285
+ export function resized(target: ProxyDraft, previous: number) {
286
+ const state = target.arrayState;
287
+ if (state !== null) state.dense = null;
288
+ const end = Math.min(target.copy!.length, target.original.length);
289
+ if (previous < end) markRange(target, previous, end);
290
+ }
291
+
292
+ /**
293
+ * After a native operation moved elements: drafts created here take their
294
+ * new keys, assigned values are registered again at their new indices, and
295
+ * the array remembers that identity against the original index can no longer
296
+ * tell a moved base element from an assigned value.
297
+ */
298
+ function relocate(
299
+ target: ProxyDraft,
300
+ map: (index: number) => number,
301
+ from: number,
302
+ to: number,
303
+ // How far the operation shifted the elements it moved, if all alike.
304
+ delta?: number
305
+ ) {
306
+ markRange(target, from, to);
307
+ target.arrayState!.delta = delta;
308
+ const copy = target.copy!;
309
+ const entries: [number, any][] = [];
310
+ if (target.child !== null)
311
+ entries.push([Number(target.childKey), target.child]);
312
+ target.children?.forEach((draft: any, index: number) => {
313
+ entries.push([index, draft]);
314
+ });
315
+ target.child = null;
316
+ target.childKey = null;
317
+ target.children = undefined;
318
+ // Keys keep the original layout, which patch paths are expressed in; a
319
+ // moved draft is finalized into its new index through a callback instead.
320
+ for (let position = 0; position < entries.length; position += 1) {
321
+ const [index, draft] = entries[position];
322
+ const next = map(index);
323
+ if (next >= 0) {
324
+ registerChild(target, next, draft);
325
+ if (next !== index) markFinalization(target, String(next), draft);
326
+ }
327
+ }
328
+ const assignedMap = target.assignedMap!;
329
+ const assigned: [any, boolean][] = [];
330
+ assignedMap.forEach((flag, key) => {
331
+ if (key !== 'length') assigned.push([key, flag]);
332
+ });
333
+ // Clear every old index before writing the new ones: an index may be both.
334
+ for (let position = 0; position < assigned.length; position += 1) {
335
+ assignedMap.delete(assigned[position][0]);
336
+ }
337
+ // An assigned value that moved is registered again at its new index, as an
338
+ // assignment through the proxy would do: an object for finalization, and
339
+ // not at all where it meets the original element of that index; one that
340
+ // stayed keeps the registration it has.
341
+ for (let position = 0; position < assigned.length; position += 1) {
342
+ const [key, flag] = assigned[position];
343
+ const index = Number(key);
344
+ const next = map(index);
345
+ if (next >= 0) {
346
+ if (flag && next !== index) {
347
+ registerAssigned(target, next, copy[next]);
348
+ } else {
349
+ assignedMap.set(String(next), flag);
350
+ }
351
+ }
352
+ }
353
+ }
354
+
355
+ // Before removing the element at `index`: its draft, or the original index
356
+ // it needs as draft key, or -1 when it is exposed as is. This runs before the
357
+ // array changes. The current array decides what is at `index`; the child
358
+ // registry is only a cache, because writes through the set trap and the proxy
359
+ // path do not maintain it. As in the get trap, no property of the element is
360
+ // read: an element of the base state is drafted, and anything else, such as a
361
+ // draft assigned from another path, is exposed as it is.
362
+ function removalKey(target: ProxyDraft, index: number) {
363
+ const value = latest(target)[index];
364
+ if (typeof value !== 'object' || value === null) return -1;
365
+ if (childAt(target, index) === value) return value;
366
+ return isDraftable(value, target.options)
367
+ ? baseIndex(target, value, index)
368
+ : -1;
369
+ }
370
+
371
+ // A removed element is exposed as a draft when the user could otherwise
372
+ // modify the original array through it.
373
+ function removed(target: ProxyDraft, value: any, key: any) {
374
+ if (typeof key !== 'number') return key;
375
+ if (key < 0) return value;
376
+ // The draft is finalized against the parent's copy, which must exist.
377
+ ensureShallowCopy(target);
378
+ return internal.createDraft(
379
+ value,
380
+ target,
381
+ key,
382
+ target.finalities,
383
+ target.options
384
+ );
385
+ }
386
+
387
+ function prepare(target: ProxyDraft) {
388
+ ensureShallowCopy(target);
389
+ markChanged(target);
390
+ return target.copy! as any[];
391
+ }
392
+
393
+ type Native = (...args: any[]) => any;
394
+
395
+ // A method that runs `impl` on the array draft behind `this`, or the
396
+ // original method when `this` is not an eligible draft. `impl` receives the
397
+ // original method to fall back to the proxy path, which methods that move
398
+ // elements do for sparse arrays once cheaper checks have not settled the call.
399
+ // In strict mode, outside `unsafe()`, the proxy path checks each element it
400
+ // reads, and calls take it as they are: predicting its reads would inspect
401
+ // elements it never reads, and before arguments are converted. Strict mode
402
+ // only rejects objects, so an array of primitives keeps the native paths; it
403
+ // is recognized with `typeof` alone, which runs no trap, and cached per draft.
404
+ function native(
405
+ method: keyof typeof arrayProto,
406
+ impl: (target: ProxyDraft, self: any, args: any[], original: Native) => any
407
+ ): Native {
408
+ const original: Native = arrayProto[method] as any;
409
+ return function (this: any, ...args: any[]) {
410
+ const target = nativeState(this);
411
+ return target === null || (checksReads(target.options) && !isInert(target))
412
+ ? original.apply(this, args)
413
+ : impl(target, this, args, original);
414
+ };
415
+ }
416
+
417
+ // Whether `value`, found at `index`, is an element of the base state, by
418
+ // identity alone. A read through the proxy drafts such an element when it is
419
+ // draftable.
420
+ function isBaseElement(target: ProxyDraft, value: object, index: number) {
421
+ return (
422
+ childAt(target, index) !== value && baseIndex(target, value, index) !== -1
423
+ );
424
+ }
425
+
426
+ /**
427
+ * Whether `value`, which the array already holds at `index`, is an element of
428
+ * the base state that native methods moved there. The proxy path moves
429
+ * elements by reading them, so it holds a draft there, and assigning the raw
430
+ * element replaces the draft and records an assignment; the set trap records
431
+ * one as well instead of ignoring the assignment.
432
+ */
433
+ export function isMovedElement(target: ProxyDraft, value: any, index: any) {
434
+ return (
435
+ typeof value === 'object' &&
436
+ value !== null &&
437
+ value !== target.original[index] &&
438
+ baseIndex(target, value, index) !== -1
439
+ );
440
+ }
441
+
442
+ // Identity searches run natively on the current array and return what the
443
+ // proxy path returns, where every element is compared as a read hands it out.
444
+ // An object of the base state is drafted on read and so never found, unless
445
+ // the recipe assigned it at that index; a native hit on a drafted one is
446
+ // skipped and the search continues past it, so the result does not depend on
447
+ // which elements were read before. A primitive index argument converts without
448
+ // side effects, so the native method may convert it; an index that can run
449
+ // user code is converted on the proxy path, which keeps the length it read
450
+ // first. The search never reads a property of the value it is given.
451
+ function search(method: 'indexOf' | 'lastIndexOf' | 'includes') {
452
+ const nativeSearch: Native = arrayProto[method] as any;
453
+ const backwards = method === 'lastIndexOf';
454
+ const find: Native = (
455
+ backwards ? arrayProto.lastIndexOf : arrayProto.indexOf
456
+ ) as any;
457
+ return native(method, (target, self, args, original) => {
458
+ const source = latest(target);
459
+ if (source.length === 0) return method === 'includes' ? false : -1;
460
+ if (canExecute(args[1])) return original.apply(self, args);
461
+ const value = args[0];
462
+ if (typeof value !== 'object' || value === null) {
463
+ return nativeSearch.apply(source, args);
464
+ }
465
+ let index: number =
466
+ args.length > 1
467
+ ? find.call(source, value, args[1])
468
+ : find.call(source, value);
469
+ while (index !== -1) {
470
+ // An inherited element is handed out as it is until the proxy path's
471
+ // first drafting read copies it into an own element; the proxy path
472
+ // decides such a search.
473
+ if (!hasOwn.call(source, index)) {
474
+ return original.apply(self, args);
475
+ }
476
+ // This array's own drafts, values assigned in the recipe and other
477
+ // objects outside the base state are handed out as they are.
478
+ if (!isBaseElement(target, value, index)) break;
479
+ // A base element is drafted on read when it is draftable. Before it is
480
+ // inspected, rule out holes, behind which an inherited element could
481
+ // follow.
482
+ if (!isDense(target)) return original.apply(self, args);
483
+ if (!isDraftable(value, target.options)) break;
484
+ index = backwards
485
+ ? index === 0
486
+ ? -1
487
+ : find.call(source, value, index - 1)
488
+ : find.call(source, value, index + 1);
489
+ }
490
+ return method === 'includes' ? index !== -1 : index;
491
+ });
492
+ }
493
+
494
+ /**
495
+ * Array methods without callbacks run natively on the draft's copy instead
496
+ * of moving every element through the proxy traps.
497
+ */
498
+ export const arrayMethods: Record<PropertyKey, Native> = Object.assign(
499
+ Object.create(null),
500
+ {
501
+ indexOf: search('indexOf'),
502
+ lastIndexOf: search('lastIndexOf'),
503
+ includes: search('includes'),
504
+ // Keep conversion on the proxy whenever it can run user code. Native
505
+ // join handles its length snapshot, conversion order, and recursive calls.
506
+ join: native('join', (target, self, args) =>
507
+ arrayProto.join.call(
508
+ canExecute(args[0]) || !isInert(target) ? self : latest(target),
509
+ args[0]
510
+ )
511
+ ),
512
+ shift: native('shift', (target, self, args, original) => {
513
+ if (latest(target).length === 0) return undefined;
514
+ if (!isDense(target)) return original.apply(self, args);
515
+ const key = removalKey(target, 0);
516
+ const copy = prepare(target);
517
+ const value = arrayProto.shift.call(copy);
518
+ relocate(target, (index) => index - 1, 0, copy.length + 1, 1);
519
+ return removed(target, value, key);
520
+ }),
521
+ unshift: native('unshift', (target, self, items, original) => {
522
+ const count = items.length;
523
+ if (count === 0) return latest(target).length;
524
+ if (!isDense(target)) return original.apply(self, items);
525
+ const copy = prepare(target);
526
+ arrayProto.unshift.apply(copy, items);
527
+ relocate(target, (index) => index + count, 0, copy.length, -count);
528
+ for (let index = 0; index < count; index += 1) {
529
+ registerAssigned(target, index, items[index]);
530
+ }
531
+ return copy.length;
532
+ }),
533
+ splice: native('splice', (target, self, args, original) => {
534
+ // Let the native algorithm retain its length and read order when
535
+ // converting an argument can execute user code or change the draft.
536
+ if (canExecute(args[0]) || canExecute(args[1])) {
537
+ return original.apply(self, args);
538
+ }
539
+ const length = latest(target).length;
540
+ const start = relativeIndex(args[0], length, 0);
541
+ const deleteCount =
542
+ args.length === 0
543
+ ? 0
544
+ : args.length === 1
545
+ ? length - start
546
+ : Math.min(Math.max(toInteger(args[1]), 0), length - start);
547
+ const insertCount = Math.max(args.length - 2, 0);
548
+ if (deleteCount === 0 && insertCount === 0) {
549
+ return original.apply(self, args);
550
+ }
551
+ const source = latest(target);
552
+ if (deleteCount === insertCount) {
553
+ // Replacing elements with equal values changes nothing, as through
554
+ // the proxy; the removed elements are still exposed as drafts. This
555
+ // array's own draft also stands for its original. An own element of
556
+ // the base state only equals itself there. For any other object, the
557
+ // proxy path's assignment reads its draft symbol, so that path
558
+ // decides the call.
559
+ let same = true;
560
+ for (let index = 0; same && index < insertCount; index += 1) {
561
+ const at = start + index;
562
+ const value = source[at];
563
+ const item = args[index + 2];
564
+ if (!isEqual(item, value)) {
565
+ if (
566
+ typeof value !== 'object' ||
567
+ value === null ||
568
+ (hasOwn.call(source, at) && isBaseElement(target, value, at))
569
+ ) {
570
+ same = false;
571
+ } else if (childAt(target, at) === value) {
572
+ same = isEqual(item, getProxyDraft(value)!.original);
573
+ } else {
574
+ return original.apply(self, args);
575
+ }
576
+ }
577
+ }
578
+ if (same) return original.apply(self, args);
579
+ }
580
+ // Decided after the unchanged cases, which read only the replaced range.
581
+ if (!isDense(target)) return original.apply(self, args);
582
+ const keys: any[] = [];
583
+ for (let index = 0; index < deleteCount; index += 1) {
584
+ keys.push(removalKey(target, start + index));
585
+ }
586
+ const copy = prepare(target);
587
+ // Primitive arguments have no conversion side effects. Use the
588
+ // normalized indices for both the native call and draft bookkeeping.
589
+ const spliceArgs: any[] = [start, deleteCount];
590
+ for (let index = 2; index < args.length; index += 1) {
591
+ spliceArgs.push(args[index]);
592
+ }
593
+ const values: any[] = (arrayProto.splice as any).apply(copy, spliceArgs);
594
+ relocate(
595
+ target,
596
+ (index) =>
597
+ index < start
598
+ ? index
599
+ : index < start + deleteCount
600
+ ? -1
601
+ : index - deleteCount + insertCount,
602
+ start,
603
+ // Later indices keep their place when as many are inserted as deleted.
604
+ deleteCount === insertCount
605
+ ? start + deleteCount
606
+ : Math.max(length, copy.length),
607
+ deleteCount - insertCount
608
+ );
609
+ for (let index = 0; index < insertCount; index += 1) {
610
+ registerAssigned(target, start + index, args[index + 2]);
611
+ }
612
+ for (let index = 0; index < values.length; index += 1) {
613
+ values[index] = removed(target, values[index], keys[index]);
614
+ }
615
+ return values;
616
+ }),
617
+ // Sorting hands every element to the comparator, so only arrays of
618
+ // primitives are sorted natively; the rest sort through the proxy.
619
+ sort: native('sort', (target, self, [compare], original) => {
620
+ if (
621
+ (compare !== undefined && typeof compare !== 'function') ||
622
+ !isInert(target) ||
623
+ !isDense(target)
624
+ ) {
625
+ return original.call(self, compare);
626
+ }
627
+ const source = latest(target);
628
+ const length = source.length;
629
+ // Like the native method, collect the elements before the comparator
630
+ // runs, then write them back over anything the comparator changed
631
+ // through the draft.
632
+ // sort does not consult constructor or Symbol.species. Collect into
633
+ // an ordinary array rather than invoking slice's species creation.
634
+ const sorted = new Array(length);
635
+ for (let index = 0; index < length; index += 1) {
636
+ sorted[index] = source[index];
637
+ }
638
+ arrayProto.sort.call(sorted, compare);
639
+ let changed = false;
640
+ for (let index = 0; index < length; index += 1) {
641
+ if (!isEqual(sorted[index], source[index])) {
642
+ changed = true;
643
+ break;
644
+ }
645
+ }
646
+ const copy = changed ? prepare(target) : target.copy;
647
+ if (copy !== null) {
648
+ for (let index = 0; index < length; index += 1) {
649
+ copy[index] = sorted[index];
650
+ }
651
+ }
652
+ if (changed) markRange(target, 0, length);
653
+ return self;
654
+ }),
655
+ reverse: native('reverse', (target, self, args, original) => {
656
+ const source = latest(target);
657
+ const length = source.length;
658
+ if (length < 2) return self;
659
+ if (!isDense(target)) return original.apply(self, args);
660
+ // A palindrome by identity stays untouched, as through the proxy, while
661
+ // no assignment is recorded: the proxy path swaps an assigned value and
662
+ // the element that a read drafts, so the move must carry their records.
663
+ const assigned = target.assignedMap;
664
+ let changed = assigned !== undefined && assigned.size > 0;
665
+ for (
666
+ let low = 0, high = length - 1;
667
+ !changed && low < high;
668
+ low += 1, high -= 1
669
+ ) {
670
+ changed = !isEqual(source[low], source[high]);
671
+ }
672
+ if (changed) {
673
+ arrayProto.reverse.call(prepare(target));
674
+ relocate(target, (index) => length - 1 - index, 0, length);
675
+ }
676
+ return self;
677
+ }),
678
+ }
679
+ );
@@ -0,0 +1,17 @@
1
+ // Don't use `Symbol()` just for 3rd party access the draft
2
+ export const PROXY_DRAFT = Symbol.for('__MUTATIVE_PROXY_DRAFT__');
3
+ export const RAW_RETURN_SYMBOL = Symbol('__MUTATIVE_RAW_RETURN_SYMBOL__');
4
+
5
+ export const iteratorSymbol: typeof Symbol.iterator = Symbol.iterator;
6
+
7
+ // The prototype of built-in iterators. An iterator that inherits from it
8
+ // returns itself when iterated, and has the iterator helpers, such as
9
+ // `toArray()`, where the engine provides them.
10
+ export const iteratorPrototype = Object.getPrototypeOf(
11
+ Object.getPrototypeOf([][iteratorSymbol]())
12
+ );
13
+
14
+ export const dataTypes = {
15
+ mutable: 'mutable',
16
+ immutable: 'immutable',
17
+ } as const;