@astrogate/sdk 0.0.0-stage → 0.1.0-rc.1

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,489 @@
1
+ import {
2
+ DraftType,
3
+ Finalities,
4
+ Patches,
5
+ ProxyDraft,
6
+ Options,
7
+ Operation,
8
+ } from './interface';
9
+ import { dataTypes, PROXY_DRAFT } from './constant';
10
+ import { mapHandler, mapHandlerKeys } from './map';
11
+ import { setHandler, setHandlerKeys } from './set';
12
+ import {
13
+ arrayMethods,
14
+ baseIndex,
15
+ isMovedElement,
16
+ resized,
17
+ trackArrayMethod,
18
+ } from './array';
19
+ import { internal } from './internal';
20
+ import {
21
+ deepFreeze,
22
+ ensureShallowCopy,
23
+ getDescriptor,
24
+ getProxyDraft,
25
+ getType,
26
+ isEqual,
27
+ isDraftable,
28
+ latest,
29
+ markChanged,
30
+ revokeProxy,
31
+ markFinalization,
32
+ finalizeNode,
33
+ } from './utils';
34
+ import { checkReadable } from './unsafe';
35
+ import { generatePatches } from './patch';
36
+ import { die, ErrorCode } from './error';
37
+
38
+ /**
39
+ * Accepts the keys the array set trap has always accepted: canonical
40
+ * non-negative integer strings via an allocation-free scan, and other
41
+ * spellings such as '-0' via the original numeric round trip.
42
+ */
43
+ function isArrayIndexKey(key: string | number | symbol) {
44
+ if (typeof key === 'string' && key.length < 16) {
45
+ let index = 0;
46
+ while (index < key.length) {
47
+ const code = key.charCodeAt(index);
48
+ if (code < 48 || code > 57) break;
49
+ index += 1;
50
+ }
51
+ if (
52
+ index > 0 &&
53
+ index === key.length &&
54
+ (index === 1 || key.charCodeAt(0) !== 48)
55
+ ) {
56
+ return true;
57
+ }
58
+ }
59
+ let _key: number;
60
+ return (
61
+ Number.isInteger((_key = Number(key))) &&
62
+ _key >= 0 &&
63
+ (key === 0 || _key === 0 || String(_key) === String(key))
64
+ );
65
+ }
66
+
67
+ const hasOwn = Object.prototype.hasOwnProperty;
68
+
69
+ function getTrap(
70
+ target: ProxyDraft,
71
+ key: string | number | symbol,
72
+ receiver: any
73
+ ) {
74
+ if (key === PROXY_DRAFT) return target;
75
+ const { options, type } = target;
76
+ const source = latest(target);
77
+ let markResult: any;
78
+ if (options.mark) {
79
+ // The mark classifies the value the draft holds now, so a value the
80
+ // recipe assigned is read back as assigned. `size` is read without the
81
+ // proxy as receiver: the Map and Set getters reject any other receiver.
82
+ const value =
83
+ key === 'size' && (source instanceof Map || source instanceof Set)
84
+ ? Reflect.get(source, key)
85
+ : Reflect.get(source, key, receiver);
86
+ markResult = options.mark(value, dataTypes);
87
+ if (markResult === dataTypes.mutable) {
88
+ if (options.strict) {
89
+ checkReadable(value, options, true);
90
+ }
91
+ return value;
92
+ }
93
+ }
94
+
95
+ if (type === DraftType.Map) {
96
+ if (mapHandlerKeys.includes(key as any)) {
97
+ if (key === 'size') {
98
+ return Object.getOwnPropertyDescriptor(mapHandler, 'size')!.get!.call(
99
+ target.proxy
100
+ );
101
+ }
102
+ const handle = mapHandler[key as keyof typeof mapHandler] as Function;
103
+ return handle.bind(target.proxy);
104
+ }
105
+ } else if (type === DraftType.Set) {
106
+ if (setHandlerKeys.includes(key as any)) {
107
+ if (key === 'size') {
108
+ return Object.getOwnPropertyDescriptor(setHandler, 'size')!.get!.call(
109
+ target.proxy
110
+ );
111
+ }
112
+ const handle = setHandler[key as keyof typeof setHandler] as Function;
113
+ return handle.bind(target.proxy);
114
+ }
115
+ }
116
+
117
+ if (
118
+ type === DraftType.Map
119
+ ? !(source as Map<any, any>).has(key)
120
+ : !hasOwn.call(source, key)
121
+ ) {
122
+ if (
123
+ type === DraftType.Array &&
124
+ Object.getPrototypeOf(target.original) === Array.prototype
125
+ ) {
126
+ // Methods of plain arrays that can run natively on the copy; see
127
+ // `arrayMethods`. Subclasses resolve their own methods below.
128
+ const method = arrayMethods[key as any];
129
+ if (method !== undefined) {
130
+ trackArrayMethod(target);
131
+ return method;
132
+ }
133
+ }
134
+ const desc = getDescriptor(source, key);
135
+ return desc
136
+ ? `value` in desc
137
+ ? desc.value
138
+ : // !case: support for getter
139
+ desc.get?.call(target.proxy)
140
+ : undefined;
141
+ }
142
+ const value = source[key];
143
+ if (options.strict) {
144
+ checkReadable(value, options);
145
+ }
146
+ if (target.finalized || typeof value !== 'object' || value === null) {
147
+ return value;
148
+ }
149
+ // This draft's own child at this key is returned without a proxy round
150
+ // trip and without reading the original object. The first child is kept
151
+ // inline; further children are registered per draft.
152
+ if (value === target.child && key === target.childKey) return value;
153
+ const children = target.children;
154
+ if (
155
+ children !== undefined &&
156
+ (type === DraftType.Array ? children[key as number] : children.get(key)) ===
157
+ value
158
+ ) {
159
+ return value;
160
+ }
161
+ // Non-draftable values never reach the original object either, so an
162
+ // accessor that returns a Date or similar is not re-invoked for a copy.
163
+ if (!isDraftable(value, options)) return value;
164
+ // Reassigned values, and fresh objects produced by an accessor on the
165
+ // original, differ from the original at this key and are not drafted. After
166
+ // a native array operation moved elements, an original element may sit at
167
+ // any index, so membership in the original array decides instead, except
168
+ // for a value the recipe assigned at this index; see `baseIndex`.
169
+ let draftKey: any = key;
170
+ if (value !== target.original[key]) {
171
+ draftKey = baseIndex(target, value, key as number);
172
+ if (draftKey === -1) return value;
173
+ }
174
+ ensureShallowCopy(target);
175
+ const draft = createDraft(
176
+ value,
177
+ target,
178
+ type === DraftType.Array ? Number(draftKey) : draftKey,
179
+ target.finalities,
180
+ options
181
+ );
182
+ target.copy![key] = draft;
183
+ // A moved element keeps its original index as key for patch paths and is
184
+ // finalized into its current index through a callback.
185
+ if (draftKey !== key) markFinalization(target, key, draft);
186
+ if (target.child === null || target.childKey === key) {
187
+ target.child = draft;
188
+ target.childKey = key;
189
+ } else if (type === DraftType.Array) {
190
+ (target.children ??= [])[key as any] = draft;
191
+ } else {
192
+ (target.children ??= new Map()).set(key, draft);
193
+ }
194
+ // !case: support for custom shallow copy function
195
+ if (typeof markResult === 'function') {
196
+ const subProxyDraft = getProxyDraft(draft)!;
197
+ ensureShallowCopy(subProxyDraft);
198
+ // Trigger a custom shallow copy to update to a new copy
199
+ markChanged(subProxyDraft);
200
+ return subProxyDraft.copy;
201
+ }
202
+ return draft;
203
+ }
204
+
205
+ function setTrap(
206
+ target: ProxyDraft,
207
+ key: string | number | symbol,
208
+ value: any
209
+ ) {
210
+ if (target.type === DraftType.Set || target.type === DraftType.Map) {
211
+ die(ErrorCode.CannotAssignToMapOrSet);
212
+ }
213
+ if (
214
+ target.type === DraftType.Array &&
215
+ key !== 'length' &&
216
+ !isArrayIndexKey(key)
217
+ ) {
218
+ die(ErrorCode.InvalidArrayIndex);
219
+ }
220
+ const source = latest(target);
221
+ // An own data property shadows any prototype setter, so the prototype
222
+ // chain only needs to be searched for keys the source does not own.
223
+ if (!hasOwn.call(source, key)) {
224
+ const desc = getDescriptor(source, key);
225
+ if (desc?.set) {
226
+ // !case: cover the case of setter
227
+ desc.set.call(target.proxy, value);
228
+ return true;
229
+ }
230
+ }
231
+ const current = source[key];
232
+ const currentProxyDraft = getProxyDraft(current);
233
+ const original = target.original;
234
+ if (currentProxyDraft && isEqual(currentProxyDraft.original, value)) {
235
+ // !case: assigning the original object of the draft at this key drops
236
+ // the draft. The key holds its original value again unless the draft
237
+ // was moved here from another key, in which case it is an assignment.
238
+ target.copy![key] = value;
239
+ target.assignedMap = target.assignedMap ?? new Map();
240
+ if (hasOwn.call(original, key) && isEqual(value, original[key])) {
241
+ target.assignedMap.delete(key);
242
+ } else {
243
+ markChanged(target);
244
+ target.assignedMap.set(key, true);
245
+ markFinalization(target, key, value);
246
+ }
247
+ return true;
248
+ }
249
+ // !case: handle new props with value 'undefined'
250
+ // The current copy decides whether the key exists: a key removed from the
251
+ // copy, by delete or by a shrinking array method, is added back by this
252
+ // assignment even when the original still has it.
253
+ if (
254
+ isEqual(value, current) &&
255
+ (value !== undefined || hasOwn.call(source, key)) &&
256
+ (target.arrayState === null || !isMovedElement(target, value, key))
257
+ )
258
+ return true;
259
+ ensureShallowCopy(target);
260
+ markChanged(target);
261
+ const arrayState = target.arrayState;
262
+ if (
263
+ arrayState !== null &&
264
+ ((typeof value === 'object' && value !== null) ||
265
+ typeof value === 'function')
266
+ ) {
267
+ arrayState.inert = null;
268
+ }
269
+ if (hasOwn.call(original, key) && isEqual(value, original[key])) {
270
+ // !case: handle the case of assigning the original non-draftable value to a draft
271
+ target.assignedMap!.delete(key);
272
+ } else {
273
+ target.assignedMap!.set(key, true);
274
+ }
275
+ // A longer length, or an index past the end, leaves holes behind.
276
+ const length = target.type === DraftType.Array ? target.copy!.length : -1;
277
+ target.copy![key] = value;
278
+ if (
279
+ length !== -1 &&
280
+ target.copy!.length > length + (key === 'length' ? 0 : 1)
281
+ ) {
282
+ resized(target, length);
283
+ }
284
+ markFinalization(target, key, value);
285
+ return true;
286
+ }
287
+
288
+ function hasTrap(target: ProxyDraft, key: string | symbol) {
289
+ return key in latest(target);
290
+ }
291
+
292
+ function ownKeysTrap(target: ProxyDraft) {
293
+ return Reflect.ownKeys(latest(target));
294
+ }
295
+
296
+ function getOwnPropertyDescriptorTrap(
297
+ target: ProxyDraft,
298
+ key: string | symbol
299
+ ) {
300
+ const source = latest(target);
301
+ const descriptor = Reflect.getOwnPropertyDescriptor(source, key);
302
+ if (!descriptor) return descriptor;
303
+ return {
304
+ writable: true,
305
+ configurable: target.type !== DraftType.Array || key !== 'length',
306
+ enumerable: descriptor.enumerable,
307
+ value: source[key],
308
+ };
309
+ }
310
+
311
+ function getPrototypeOfTrap(target: ProxyDraft) {
312
+ return Reflect.getPrototypeOf(target.original);
313
+ }
314
+
315
+ function setPrototypeOfTrap(): never {
316
+ die(ErrorCode.CannotSetPrototypeOfDraft);
317
+ }
318
+
319
+ function definePropertyTrap(): never {
320
+ die(ErrorCode.CannotDefinePropertyOnDraft);
321
+ }
322
+
323
+ function deletePropertyTrap(target: ProxyDraft, key: string | symbol) {
324
+ if (target.type === DraftType.Array) {
325
+ // A deleted index holds `undefined` afterwards. Deleting an index the
326
+ // array does not have changes nothing, as in JavaScript; assigning
327
+ // `undefined` to it would lengthen an array that the recipe shortened.
328
+ // Other keys reach the set trap, which rejects them.
329
+ if (!hasOwn.call(latest(target), key) && isArrayIndexKey(key)) return true;
330
+ return setTrap(target, key, undefined);
331
+ }
332
+ if (target.original[key] !== undefined || key in target.original) {
333
+ // !case: delete an existing key
334
+ ensureShallowCopy(target);
335
+ markChanged(target);
336
+ target.assignedMap!.set(key, false);
337
+ } else {
338
+ target.assignedMap = target.assignedMap ?? new Map();
339
+ // The original non-existent key has been deleted
340
+ target.assignedMap.delete(key);
341
+ }
342
+ if (target.copy) delete target.copy[key];
343
+ return true;
344
+ }
345
+
346
+ const objectHandler: ProxyHandler<ProxyDraft> = {
347
+ get: getTrap,
348
+ set: setTrap,
349
+ has: hasTrap,
350
+ ownKeys: ownKeysTrap,
351
+ getOwnPropertyDescriptor: getOwnPropertyDescriptorTrap,
352
+ getPrototypeOf: getPrototypeOfTrap,
353
+ setPrototypeOf: setPrototypeOfTrap,
354
+ defineProperty: definePropertyTrap,
355
+ deleteProperty: deletePropertyTrap,
356
+ };
357
+
358
+ // Array drafts use a one-element array as the proxy target so that
359
+ // `Array.isArray(draft)` holds; these wrappers unwrap the state from it.
360
+ const arrayHandler: ProxyHandler<[ProxyDraft]> = {};
361
+ Object.keys(objectHandler).forEach((name) => {
362
+ const trap = objectHandler[name as keyof ProxyHandler<ProxyDraft>] as (
363
+ ...args: any[]
364
+ ) => any;
365
+ (arrayHandler as any)[name] = (target: [ProxyDraft], key: any, value: any) =>
366
+ trap(target[0], key, value);
367
+ });
368
+
369
+ export function createDraft<T extends object>(
370
+ original: T,
371
+ parentDraft: ProxyDraft | null,
372
+ key: string | number | symbol | undefined,
373
+ finalities: Finalities,
374
+ options: Options<any, any>
375
+ ): T {
376
+ const type = getType(original);
377
+ // Every field is initialized here so all draft states share one shape.
378
+ const proxyDraft: ProxyDraft = {
379
+ type,
380
+ finalized: false,
381
+ operated: false,
382
+ parent: parentDraft,
383
+ key,
384
+ original,
385
+ copy: null,
386
+ proxy: null,
387
+ finalities,
388
+ options,
389
+ // The drafts of a Set draft's items and the objects it added; see
390
+ // `src/set.ts`.
391
+ setMap: undefined,
392
+ assignedMap: undefined,
393
+ callbacks: undefined,
394
+ children: undefined,
395
+ child: null,
396
+ childKey: null,
397
+ arrayState: null,
398
+ };
399
+ const { proxy, revoke } =
400
+ type === DraftType.Array
401
+ ? Proxy.revocable<any>([proxyDraft], arrayHandler)
402
+ : Proxy.revocable<any>(proxyDraft, objectHandler);
403
+ finalities.revoke.push(revoke);
404
+ proxyDraft.proxy = proxy;
405
+ finalities.draft.push(proxyDraft);
406
+ return proxy;
407
+ }
408
+
409
+ internal.createDraft = createDraft;
410
+
411
+ // Development builds warn once, in strict mode, when a producer leaves at
412
+ // least this many drafts unchanged.
413
+ const UNCHANGED_DRAFTS_WARNING_THRESHOLD = 1000;
414
+ let unchangedDraftsWarned = false;
415
+
416
+ /**
417
+ * Every object read through a draft becomes a draft, so a search through a
418
+ * large draft array creates one per element it visits. Drafts that are
419
+ * unchanged and still at the key they were read from count; elements that
420
+ * array methods drafted when removing or moving them do not. An object or
421
+ * array draft has a copy before it drafts a child.
422
+ */
423
+ function warnUnchangedDrafts(finalities: Finalities) {
424
+ let count = 0;
425
+ for (const entry of finalities.draft) {
426
+ if (typeof entry !== 'function' && !entry.operated) {
427
+ const parent = entry.parent;
428
+ if (
429
+ parent !== null &&
430
+ (parent.type === DraftType.Array || parent.type === DraftType.Object) &&
431
+ parent.copy[entry.key!] === entry.proxy
432
+ ) {
433
+ count += 1;
434
+ }
435
+ }
436
+ }
437
+ if (count >= UNCHANGED_DRAFTS_WARNING_THRESHOLD) {
438
+ unchangedDraftsWarned = true;
439
+ console.warn(
440
+ `Strict mode: the recipe left ${count} drafts unchanged; every object read through a draft becomes one. For read-only scans of large arrays, search 'current(draft.list)' instead; see https://mutative.js.org/docs/api-reference/current`
441
+ );
442
+ }
443
+ }
444
+
445
+ export function finalizeDraft<T>(
446
+ result: T,
447
+ returnedValue: [T] | [],
448
+ patches?: Patches,
449
+ inversePatches?: Patches,
450
+ enableAutoFreeze?: boolean
451
+ ) {
452
+ const proxyDraft = getProxyDraft(result);
453
+ if (__DEV__ && proxyDraft?.options.strict && !unchangedDraftsWarned) {
454
+ warnUnchangedDrafts(proxyDraft.finalities);
455
+ }
456
+ const original = proxyDraft?.original ?? result;
457
+ const hasReturnedValue = !!returnedValue.length;
458
+ if (proxyDraft?.operated) {
459
+ const list = proxyDraft.finalities.draft;
460
+ while (list.length > 0) {
461
+ const entry = list.pop()!;
462
+ if (typeof entry === 'function') {
463
+ entry(patches, inversePatches);
464
+ } else {
465
+ finalizeNode(entry, generatePatches, patches, inversePatches);
466
+ }
467
+ }
468
+ }
469
+ const state = hasReturnedValue
470
+ ? returnedValue[0]
471
+ : proxyDraft
472
+ ? proxyDraft.operated
473
+ ? proxyDraft.copy
474
+ : proxyDraft.original
475
+ : result;
476
+ if (proxyDraft) revokeProxy(proxyDraft.finalities);
477
+ if (enableAutoFreeze) {
478
+ deepFreeze(state);
479
+ }
480
+ return [
481
+ state,
482
+ patches && hasReturnedValue
483
+ ? [{ op: Operation.Replace, path: [], value: returnedValue[0] }]
484
+ : patches,
485
+ inversePatches && hasReturnedValue
486
+ ? [{ op: Operation.Replace, path: [], value: original }]
487
+ : inversePatches,
488
+ ] as [T, Patches | undefined, Patches | undefined];
489
+ }
@@ -0,0 +1,57 @@
1
+ import {
2
+ Finalities,
3
+ Options,
4
+ Patches,
5
+ PatchesOptions,
6
+ Result,
7
+ } from './interface';
8
+ import { createDraft, finalizeDraft } from './draft';
9
+ import { isDraftable } from './utils';
10
+ import { dataTypes } from './constant';
11
+
12
+ export function draftify<
13
+ T extends object,
14
+ O extends PatchesOptions = false,
15
+ F extends boolean = false,
16
+ >(
17
+ baseState: T,
18
+ options: Options<O, F>
19
+ ): [T, (returnedValue: [T] | []) => Result<T, O, F>, Finalities] {
20
+ const finalities: Finalities = {
21
+ draft: [],
22
+ revoke: [],
23
+ handledSet: new WeakSet<any>(),
24
+ scoped: true,
25
+ };
26
+ let patches: Patches | undefined;
27
+ let inversePatches: Patches | undefined;
28
+ if (options.enablePatches) {
29
+ patches = [];
30
+ inversePatches = [];
31
+ }
32
+ const isMutable =
33
+ options.mark?.(baseState, dataTypes) === dataTypes.mutable ||
34
+ !isDraftable(baseState, options);
35
+ const draft = isMutable
36
+ ? baseState
37
+ : createDraft(baseState, null, undefined, finalities, options);
38
+ return [
39
+ draft,
40
+ (returnedValue: [T] | [] = []) => {
41
+ const [finalizedState, finalizedPatches, finalizedInversePatches] =
42
+ finalizeDraft(
43
+ draft,
44
+ returnedValue,
45
+ patches,
46
+ inversePatches,
47
+ options.enableAutoFreeze
48
+ );
49
+ return (
50
+ options.enablePatches
51
+ ? [finalizedState, finalizedPatches, finalizedInversePatches]
52
+ : finalizedState
53
+ ) as Result<T, O, F>;
54
+ },
55
+ finalities,
56
+ ];
57
+ }
@@ -0,0 +1,129 @@
1
+ /**
2
+ * Error codes are kept as a const enum so production builds can inline them.
3
+ * Verify that production bundles contain neither an `ErrorCode` object nor
4
+ * the member names when changing the build toolchain.
5
+ * Keep numeric codes stable; retired codes must not be reassigned.
6
+ */
7
+ export const enum ErrorCode {
8
+ InvalidBaseState = 0,
9
+ CannotAssignToMapOrSet = 1,
10
+ InvalidArrayIndex = 2,
11
+ CannotSetPrototypeOfDraft = 3,
12
+ CannotDefinePropertyOnDraft = 4,
13
+ MutateAndReturn = 5,
14
+ CannotReturnModifiedChildDraft = 6,
15
+ CurrentOnNonDraft = 7,
16
+ StrictModeAccess = 8,
17
+ UnsupportedMarkResult = 9,
18
+ InvalidMark = 10,
19
+ CannotModifyFrozenObject = 11,
20
+ // 12 was InvalidPatchPath and is reserved for historical errors.
21
+ ReservedPatchAttribute = 13,
22
+ CannotApplyPatch = 14,
23
+ ReplacePatchOnSet = 15,
24
+ UnsupportedPatchOperation = 16,
25
+ ApplyOptionsToDraft = 17,
26
+ OriginalOnNonDraft = 18,
27
+ RawReturnWithoutValue = 19,
28
+ RawReturnWithExtraArguments = 20,
29
+ ReplaceMutableRoot = 21,
30
+ }
31
+
32
+ type ErrorArguments = {
33
+ [ErrorCode.InvalidBaseState]: [];
34
+ [ErrorCode.CannotAssignToMapOrSet]: [];
35
+ [ErrorCode.InvalidArrayIndex]: [];
36
+ [ErrorCode.CannotSetPrototypeOfDraft]: [];
37
+ [ErrorCode.CannotDefinePropertyOnDraft]: [];
38
+ [ErrorCode.MutateAndReturn]: [];
39
+ [ErrorCode.CannotReturnModifiedChildDraft]: [];
40
+ [ErrorCode.CurrentOnNonDraft]: [target: any];
41
+ [ErrorCode.StrictModeAccess]: [];
42
+ [ErrorCode.UnsupportedMarkResult]: [markResult: any];
43
+ [ErrorCode.InvalidMark]: [];
44
+ [ErrorCode.CannotModifyFrozenObject]: [];
45
+ [ErrorCode.ReservedPatchAttribute]: [];
46
+ [ErrorCode.CannotApplyPatch]: [path: (string | number)[]];
47
+ [ErrorCode.ReplacePatchOnSet]: [];
48
+ [ErrorCode.UnsupportedPatchOperation]: [op: string];
49
+ [ErrorCode.ApplyOptionsToDraft]: [];
50
+ [ErrorCode.OriginalOnNonDraft]: [target: any];
51
+ [ErrorCode.RawReturnWithoutValue]: [];
52
+ [ErrorCode.RawReturnWithExtraArguments]: [];
53
+ [ErrorCode.ReplaceMutableRoot]: [];
54
+ };
55
+
56
+ type ErrorBuilders = {
57
+ [Code in ErrorCode]: (...args: ErrorArguments[Code]) => string;
58
+ };
59
+
60
+ const errors: ErrorBuilders = __DEV__
61
+ ? [
62
+ // ErrorCode.InvalidBaseState
63
+ () =>
64
+ `Invalid base state: create() only supports plain objects, arrays, Set, Map or using mark() to mark the state as immutable.`,
65
+ // ErrorCode.CannotAssignToMapOrSet
66
+ () => `Map/Set draft does not support any property assignment.`,
67
+ // ErrorCode.InvalidArrayIndex
68
+ () => `Only supports setting array indices and the 'length' property.`,
69
+ // ErrorCode.CannotSetPrototypeOfDraft
70
+ () => `Cannot call 'setPrototypeOf()' on drafts`,
71
+ // ErrorCode.CannotDefinePropertyOnDraft
72
+ () => `Cannot call 'defineProperty()' on drafts`,
73
+ // ErrorCode.MutateAndReturn
74
+ () =>
75
+ `Either the value is returned as a new non-draft value, or only the draft is modified without returning any value.`,
76
+ // ErrorCode.CannotReturnModifiedChildDraft
77
+ () => `Cannot return a modified child draft.`,
78
+ // ErrorCode.CurrentOnNonDraft
79
+ (target) => `current() is only used for Draft, parameter: ${target}`,
80
+ // ErrorCode.StrictModeAccess
81
+ () =>
82
+ `Strict mode: Mutable data cannot be accessed directly, please use 'unsafe(callback)' wrap.`,
83
+ // ErrorCode.UnsupportedMarkResult
84
+ (markResult) => `Unsupported mark result: ${markResult}`,
85
+ // ErrorCode.InvalidMark
86
+ () =>
87
+ `Please check mark() to ensure that it is a stable marker draftable function.`,
88
+ // ErrorCode.CannotModifyFrozenObject
89
+ () => `Cannot modify frozen object`,
90
+ // Retired InvalidPatchPath (12).
91
+ undefined,
92
+ // ErrorCode.ReservedPatchAttribute
93
+ () =>
94
+ `Patching reserved attributes like __proto__ and constructor is not allowed.`,
95
+ // ErrorCode.CannotApplyPatch
96
+ (path) => `Cannot apply patch at '${path.join('/')}'.`,
97
+ // ErrorCode.ReplacePatchOnSet
98
+ () => `Cannot apply replace patch to set.`,
99
+ // ErrorCode.UnsupportedPatchOperation
100
+ (op) => `Unsupported patch operation: ${op}.`,
101
+ // ErrorCode.ApplyOptionsToDraft
102
+ () => `Cannot apply patches with options to a draft.`,
103
+ // ErrorCode.OriginalOnNonDraft
104
+ (target) => `original() is only used for a draft, parameter: ${target}`,
105
+ // ErrorCode.RawReturnWithoutValue
106
+ () => 'rawReturn() must be called with a value.',
107
+ // ErrorCode.RawReturnWithExtraArguments
108
+ () => 'rawReturn() must be called with one argument.',
109
+ // ErrorCode.ReplaceMutableRoot
110
+ () =>
111
+ 'apply() with the mutable option changes the state in place, so a patch cannot replace the root state with another value.',
112
+ ]
113
+ : ([] as unknown as ErrorBuilders);
114
+
115
+ export function die<Code extends ErrorCode>(
116
+ error: Code,
117
+ ...args: ErrorArguments[Code]
118
+ ): never {
119
+ if (__DEV__) {
120
+ throw new Error(
121
+ (errors[error] as (...builderArgs: ErrorArguments[Code]) => string)(
122
+ ...args
123
+ )
124
+ );
125
+ }
126
+ throw new Error(
127
+ `Minified Mutative error #${error}; visit https://mutative.js.org/docs/extra-topics/errors`
128
+ );
129
+ }
@@ -0,0 +1,21 @@
1
+ export { makeCreator } from './makeCreator';
2
+ export { create } from './create';
3
+ export { apply } from './apply';
4
+ export { original } from './original';
5
+ export { current } from './current';
6
+ export { unsafe } from './unsafe';
7
+ export { rawReturn } from './rawReturn';
8
+ export { isDraft } from './utils/draft';
9
+ export { isDraftable } from './utils/draft';
10
+ export { markSimpleObject } from './utils/marker';
11
+
12
+ export { castDraft, castImmutable, castMutable } from './utils/cast';
13
+ export type {
14
+ Immutable,
15
+ Draft,
16
+ Patches,
17
+ Patch,
18
+ ExternalOptions as Options,
19
+ PatchesOptions,
20
+ DraftedObject,
21
+ } from './interface';