@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,321 @@
1
+ import { dataTypes } from './constant';
2
+
3
+ export const enum DraftType {
4
+ Object,
5
+ Array,
6
+ Map,
7
+ Set,
8
+ }
9
+
10
+ export const Operation = {
11
+ Remove: 'remove',
12
+ Replace: 'replace',
13
+ Add: 'add',
14
+ } as const;
15
+
16
+ export type DataType = keyof typeof dataTypes;
17
+
18
+ /**
19
+ * The `enablePatches` option: `true` or an object generates patches, `false`
20
+ * does not.
21
+ */
22
+ export type PatchesOptions =
23
+ | boolean
24
+ | {
25
+ /**
26
+ * Whether a patch path is an array of keys, as by default, or a JSON
27
+ * Pointer string, such as `/list/0`.
28
+ */
29
+ pathAsArray?: boolean;
30
+ /**
31
+ * Whether an array that gets shorter gets a `replace` patch of its
32
+ * `length`, as by default, or a `remove` patch for each index that it
33
+ * loses, as JSON Patch requires.
34
+ * Recreating holes in a sparse array still uses length patches;
35
+ * JSON cannot represent holes.
36
+ */
37
+ arrayLengthAssignment?: boolean;
38
+ };
39
+
40
+ export type FinalizeCallback = (
41
+ patches?: Patches,
42
+ inversePatches?: Patches
43
+ ) => void;
44
+
45
+ export interface Finalities {
46
+ // Draft nodes and deferred callbacks, finalized in reverse order.
47
+ draft: (ProxyDraft | FinalizeCallback)[];
48
+ revoke: (() => void)[];
49
+ handledSet: WeakSet<any>;
50
+ // Whether the producer runs a recipe inside `create`, which then sees it end
51
+ // and releases module-level references to its drafts. False for drafts
52
+ // returned by `create(base)` without a recipe.
53
+ scoped: boolean;
54
+ }
55
+
56
+ export interface ProxyDraft<T = any> {
57
+ type: DraftType;
58
+ operated: boolean;
59
+ finalized: boolean;
60
+ original: T;
61
+ copy: T | null;
62
+ proxy: T | null;
63
+ finalities: Finalities;
64
+ options: Options<any, any>;
65
+ parent: ProxyDraft | null;
66
+ key: string | number | symbol | undefined;
67
+ // The drafts of a Set draft's items and the objects it added, with its items
68
+ // in order once finalization rebuilt it.
69
+ setMap: (Map<any, any> & { items?: any[] }) | undefined;
70
+ assignedMap: Map<any, boolean> | undefined;
71
+ callbacks: FinalizeCallback[] | undefined;
72
+ // Child drafts created by this draft, by key.
73
+ children: any;
74
+ child: any;
75
+ childKey: any;
76
+ // Bookkeeping of array methods that ran natively, created on demand.
77
+ arrayState: ArrayState | null;
78
+ }
79
+
80
+ export interface ArrayState {
81
+ // Elements may have moved away from their original index.
82
+ relocated: boolean;
83
+ // Index range whose contents may have changed; patch generation compares
84
+ // it in full.
85
+ diffStart: number;
86
+ diffEnd: number;
87
+ // Original index by element of the original array, built lazily.
88
+ baseRefs: Map<any, number> | null;
89
+ // How far the last native move shifted the elements it moved, when it
90
+ // shifted all of them alike.
91
+ delta: number | undefined;
92
+ // Original indices looked up by searching before `baseRefs` is built.
93
+ lookups: number;
94
+ // Whether no element can be drafted; null until checked.
95
+ inert: boolean | null;
96
+ // Whether the array has no holes; null until checked.
97
+ dense: boolean | null;
98
+ }
99
+
100
+ export interface IPatch {
101
+ op: (typeof Operation)[keyof typeof Operation];
102
+ value?: any;
103
+ }
104
+
105
+ /**
106
+ * An `add`, `remove` or `replace` operation at a path, as `create()` generates
107
+ * it with `enablePatches` and `apply()` applies it. The path is an array of
108
+ * keys, or a JSON Pointer string with `pathAsArray: false`.
109
+ */
110
+ export type Patch<P extends PatchesOptions = any> = P extends {
111
+ pathAsArray: false;
112
+ }
113
+ ? IPatch & {
114
+ path: string;
115
+ }
116
+ : P extends true | object
117
+ ? IPatch & {
118
+ path: (string | number)[];
119
+ }
120
+ : IPatch & {
121
+ path: string | (string | number)[];
122
+ };
123
+
124
+ /**
125
+ * Patches in the order in which `apply()` applies them.
126
+ */
127
+ export type Patches<P extends PatchesOptions = any> = Patch<P>[];
128
+
129
+ export type Result<
130
+ T extends any,
131
+ O extends PatchesOptions,
132
+ F extends boolean,
133
+ > = O extends true | object
134
+ ? [F extends true ? Immutable<T> : T, Patches<O>, Patches<O>]
135
+ : F extends true
136
+ ? Immutable<T>
137
+ : T;
138
+
139
+ export type CreateResult<
140
+ T extends any,
141
+ O extends PatchesOptions,
142
+ F extends boolean,
143
+ R extends void | Promise<void> | T | Promise<T>,
144
+ > = R extends Promise<void> | Promise<T>
145
+ ? Promise<Result<T, O, F>>
146
+ : Result<T, O, F>;
147
+
148
+ type BaseMark = null | undefined | DataType;
149
+ type MarkWithCopy = BaseMark | (() => any);
150
+
151
+ export type Mark<O extends PatchesOptions, F extends boolean> = (
152
+ target: any,
153
+ types: typeof dataTypes
154
+ ) => O extends true | object
155
+ ? BaseMark
156
+ : F extends true
157
+ ? BaseMark
158
+ : MarkWithCopy;
159
+
160
+ export interface ApplyMutableOptions {
161
+ /**
162
+ * If it's `true`, the state will be mutated directly.
163
+ */
164
+ mutable?: boolean;
165
+ }
166
+
167
+ export interface Options<O extends PatchesOptions, F extends boolean> {
168
+ /**
169
+ * In strict mode, reading an object that cannot be drafted from a draft,
170
+ * such as a class instance that no mark makes draftable, or a value that
171
+ * `mark` makes mutable, throws unless the read happens inside `unsafe()`.
172
+ * A value returned with `rawReturn()` is still searched for drafts, which
173
+ * development builds report with a warning. Development builds also warn
174
+ * once when a recipe leaves 1,000 or more drafts unchanged.
175
+ */
176
+ strict?: boolean;
177
+ /**
178
+ * Generate patches: the result is then
179
+ * `[state, patches, inversePatches]`.
180
+ */
181
+ enablePatches?: O;
182
+ /**
183
+ * Freeze the next state deeply, also the parts that it shares with the base
184
+ * state. Development builds also throw for an object that holds itself.
185
+ */
186
+ enableAutoFreeze?: F;
187
+ /**
188
+ * Decide how values are drafted: a mark returns `immutable` to make a value
189
+ * draftable, such as a class instance, `mutable` to keep it out of drafts so
190
+ * that the recipe changes it in place, or a function that returns a shallow
191
+ * copy of the value, which needs patches and auto-freeze off. With several
192
+ * marks, the first one that returns a value decides.
193
+ */
194
+ mark?: Mark<O, F>;
195
+ }
196
+
197
+ export interface ExternalOptions<O extends PatchesOptions, F extends boolean> {
198
+ /**
199
+ * In strict mode, reading an object that cannot be drafted from a draft,
200
+ * such as a class instance that no mark makes draftable, or a value that
201
+ * `mark` makes mutable, throws unless the read happens inside `unsafe()`.
202
+ * A value returned with `rawReturn()` is still searched for drafts, which
203
+ * development builds report with a warning. Development builds also warn
204
+ * once when a recipe leaves 1,000 or more drafts unchanged.
205
+ */
206
+ strict?: boolean;
207
+ /**
208
+ * Generate patches: the result is then
209
+ * `[state, patches, inversePatches]`.
210
+ */
211
+ enablePatches?: O;
212
+ /**
213
+ * Freeze the next state deeply, also the parts that it shares with the base
214
+ * state. Development builds also throw for an object that holds itself.
215
+ */
216
+ enableAutoFreeze?: F;
217
+ /**
218
+ * Decide how values are drafted: a mark returns `immutable` to make a value
219
+ * draftable, such as a class instance, `mutable` to keep it out of drafts so
220
+ * that the recipe changes it in place, or a function that returns a shallow
221
+ * copy of the value, which needs patches and auto-freeze off. With several
222
+ * marks, the first one that returns a value decides.
223
+ */
224
+ mark?: Mark<O, F>[] | Mark<O, F>;
225
+ }
226
+
227
+ // Exclude `symbol`
228
+ type Primitive = string | number | bigint | boolean | null | undefined;
229
+
230
+ type ImmutableMap<K, V> = ReadonlyMap<Immutable<K>, Immutable<V>>;
231
+ type ImmutableSet<T> = ReadonlySet<Immutable<T>>;
232
+ type ImmutableObject<T> = { readonly [K in keyof T]: Immutable<T[K]> };
233
+
234
+ export type IfAvailable<T, Fallback = void> = true | false extends (
235
+ T extends never ? true : false
236
+ )
237
+ ? Fallback
238
+ : keyof T extends never
239
+ ? Fallback
240
+ : T;
241
+ type WeakReferences =
242
+ | IfAvailable<WeakMap<any, any>>
243
+ | IfAvailable<WeakSet<any>>;
244
+ type AtomicObject = Function | Promise<any> | Date | RegExp;
245
+
246
+ /**
247
+ * A deeply readonly `T`, the type of a state that `enableAutoFreeze` freezes:
248
+ * Maps and Sets become `ReadonlyMap` and `ReadonlySet`, and functions,
249
+ * Promises, dates and regular expressions keep their types.
250
+ */
251
+ export type Immutable<T> = T extends Primitive | AtomicObject
252
+ ? T
253
+ : T extends IfAvailable<ReadonlyMap<infer K, infer V>>
254
+ ? ImmutableMap<K, V>
255
+ : T extends IfAvailable<ReadonlySet<infer V>>
256
+ ? ImmutableSet<V>
257
+ : T extends WeakReferences
258
+ ? T
259
+ : T extends object
260
+ ? ImmutableObject<T>
261
+ : T;
262
+
263
+ type DraftedMap<K, V> = Map<K, Draft<V>>;
264
+ type DraftedSet<T> = Set<Draft<T>>;
265
+ /**
266
+ * The draft of an object type: writable properties whose values are drafts.
267
+ */
268
+ export type DraftedObject<T> = {
269
+ -readonly [K in keyof T]: Draft<T[K]>;
270
+ };
271
+
272
+ /**
273
+ * The type of a draft of `T`: its objects, arrays, Maps and Sets without
274
+ * `readonly`, deeply, so that a recipe can change them. Functions, Promises,
275
+ * dates and regular expressions keep their types.
276
+ */
277
+ export type Draft<T> = T extends Primitive | AtomicObject
278
+ ? T
279
+ : T extends IfAvailable<ReadonlyMap<infer K, infer V>>
280
+ ? DraftedMap<K, V>
281
+ : T extends IfAvailable<ReadonlySet<infer V>>
282
+ ? DraftedSet<V>
283
+ : T extends WeakReferences
284
+ ? T
285
+ : T extends object
286
+ ? DraftedObject<T>
287
+ : T;
288
+
289
+ export type ApplyImmutableOptions<F extends boolean> = Pick<
290
+ Options<boolean, F>,
291
+ Exclude<keyof Options<boolean, F>, 'enablePatches'>
292
+ > & { mutable?: false };
293
+
294
+ export type ApplyOptions<F extends boolean> =
295
+ | ApplyImmutableOptions<F>
296
+ | ApplyMutableOptions;
297
+
298
+ // Distribute over boolean and undefined so optional or widened freeze flags
299
+ // keep both possible states instead of silently promising a writable result.
300
+ type ApplyFrozenState<T, F> = F extends true ? Immutable<T> : T;
301
+
302
+ type ApplyState<T, F extends boolean, A> = F extends true
303
+ ? Immutable<T>
304
+ : 'enableAutoFreeze' extends keyof A
305
+ ? ApplyFrozenState<T, A['enableAutoFreeze']>
306
+ : T;
307
+
308
+ // `apply()` changes the state in place and returns nothing with `mutable`,
309
+ // and returns a frozen state with `enableAutoFreeze`, as `create()` does.
310
+ // A boolean or optional `mutable` flag can also select the void result.
311
+ export type ApplyResult<
312
+ T extends object,
313
+ F extends boolean = false,
314
+ A extends ApplyOptions<boolean> | undefined = ApplyImmutableOptions<F>,
315
+ > = A extends { mutable: true }
316
+ ? void
317
+ : 'mutable' extends keyof A
318
+ ? true extends A['mutable']
319
+ ? ApplyState<T, F, A> | void
320
+ : ApplyState<T, F, A>
321
+ : ApplyState<T, F, A>;
@@ -0,0 +1,5 @@
1
+ import { createDraft } from './draft';
2
+
3
+ export const internal = {} as {
4
+ createDraft: typeof createDraft;
5
+ };
@@ -0,0 +1,382 @@
1
+ import {
2
+ CreateResult,
3
+ Draft,
4
+ Mark,
5
+ Options,
6
+ ExternalOptions,
7
+ PatchesOptions,
8
+ Result,
9
+ } from './interface';
10
+ import { draftify } from './draftify';
11
+ import { releaseArrayMethods } from './array';
12
+ import {
13
+ getProxyDraft,
14
+ isDraft,
15
+ isDraftable,
16
+ isEqual,
17
+ revokeProxy,
18
+ } from './utils';
19
+ import { current, handleReturnValue } from './current';
20
+ import { RAW_RETURN_SYMBOL, dataTypes } from './constant';
21
+ import { die, ErrorCode } from './error';
22
+
23
+ // TypeScript infers no type parameter from this deferred indexed access, so T
24
+ // keeps its default, never, unless the call supplies the state type.
25
+ type ExplicitState<T> = [T][T extends any ? 0 : never];
26
+
27
+ type ExplicitReturn<T> = void | ExplicitState<T> | Draft<ExplicitState<T>>;
28
+
29
+ // An async recipe widens the literals it returns unless a Promise is among
30
+ // the return types of the first overload that checks it, and a literal that
31
+ // it returns directly needs a Promise as the whole return type. Actual
32
+ // Promises lack the impossible field and still select the async overload.
33
+ type AsyncRecipeContext<T> = Promise<ExplicitReturn<T>> & {
34
+ readonly __mutativeAsyncContext: never;
35
+ };
36
+
37
+ type IsExplicitPrimitive<T> = [ExplicitState<T>] extends [
38
+ string | number | bigint | boolean | symbol | null | undefined,
39
+ ]
40
+ ? true
41
+ : false;
42
+
43
+ type ExplicitSyncReturn<T> =
44
+ IsExplicitPrimitive<T> extends true
45
+ ? AsyncRecipeContext<T>
46
+ : ExplicitReturn<T> | AsyncRecipeContext<T>;
47
+
48
+ type ExplicitRecipe<T, P extends any[], R> = [T] extends [never]
49
+ ? never
50
+ : (draft: Draft<ExplicitState<T>>, ...args: P) => R;
51
+
52
+ // The first overload only gives the async recipes of a primitive state their
53
+ // context, so its synchronous recipes take this one, which comes before the
54
+ // overload of a recipe that may or may not return a Promise.
55
+ type ExplicitPrimitiveRecipe<T, P extends any[]> =
56
+ IsExplicitPrimitive<T> extends true
57
+ ? ExplicitRecipe<T, P, ExplicitReturn<T>>
58
+ : never;
59
+
60
+ /** @inline */ type MakeCreator = <
61
+ _F extends boolean = false,
62
+ _O extends PatchesOptions = false,
63
+ >(
64
+ options?: ExternalOptions<_O, _F>
65
+ ) => {
66
+ // With an explicit state type, TypeScript infers no other type argument, and
67
+ // the default return type `void` of the overloads below also accepts an
68
+ // async recipe. These overloads tell async recipes apart by their return
69
+ // type; an inferred call leaves T at never and skips them.
70
+ <T = never, F extends boolean = _F, O extends PatchesOptions = _O>(
71
+ base: ExplicitState<T>,
72
+ mutate: ExplicitRecipe<T, [], ExplicitSyncReturn<T>>,
73
+ options?: ExternalOptions<O, F>
74
+ ): Result<ExplicitState<T>, O, F>;
75
+ <T = never, F extends boolean = _F, O extends PatchesOptions = _O>(
76
+ base: ExplicitState<T>,
77
+ mutate: ExplicitRecipe<T, [], Promise<ExplicitReturn<T>>>,
78
+ options?: ExternalOptions<O, F>
79
+ ): Promise<Result<ExplicitState<T>, O, F>>;
80
+ // A synchronous recipe of a primitive state.
81
+ <T = never, F extends boolean = _F, O extends PatchesOptions = _O>(
82
+ base: ExplicitState<T>,
83
+ mutate: ExplicitPrimitiveRecipe<T, []>,
84
+ options?: ExternalOptions<O, F>
85
+ ): Result<ExplicitState<T>, O, F>;
86
+ // A recipe that may or may not return a Promise gives either result.
87
+ <T = never, F extends boolean = _F, O extends PatchesOptions = _O>(
88
+ base: ExplicitState<T>,
89
+ mutate: ExplicitRecipe<
90
+ T,
91
+ [],
92
+ ExplicitReturn<T> | Promise<ExplicitReturn<T>>
93
+ >,
94
+ options?: ExternalOptions<O, F>
95
+ ): Result<ExplicitState<T>, O, F> | Promise<Result<ExplicitState<T>, O, F>>;
96
+ <
97
+ T extends any,
98
+ F extends boolean = _F,
99
+ O extends PatchesOptions = _O,
100
+ R extends void | Promise<void> | T | Promise<T> = void,
101
+ >(
102
+ base: T,
103
+ mutate: (draft: Draft<T>) => R,
104
+ options?: ExternalOptions<O, F>
105
+ ): CreateResult<T, O, F, R>;
106
+ <
107
+ T extends any,
108
+ F extends boolean = _F,
109
+ O extends PatchesOptions = _O,
110
+ R extends void | Promise<void> = void,
111
+ >(
112
+ base: T,
113
+ mutate: (draft: T) => R,
114
+ options?: ExternalOptions<O, F>
115
+ ): CreateResult<T, O, F, R>;
116
+ <
117
+ T = never,
118
+ P extends any[] = [],
119
+ F extends boolean = _F,
120
+ O extends PatchesOptions = _O,
121
+ >(
122
+ mutate: ExplicitRecipe<T, P, ExplicitSyncReturn<T>>,
123
+ options?: ExternalOptions<O, F>
124
+ ): (base: ExplicitState<T>, ...args: P) => Result<ExplicitState<T>, O, F>;
125
+ <
126
+ T = never,
127
+ P extends any[] = [],
128
+ F extends boolean = _F,
129
+ O extends PatchesOptions = _O,
130
+ >(
131
+ mutate: ExplicitRecipe<T, P, Promise<ExplicitReturn<T>>>,
132
+ options?: ExternalOptions<O, F>
133
+ ): (
134
+ base: ExplicitState<T>,
135
+ ...args: P
136
+ ) => Promise<Result<ExplicitState<T>, O, F>>;
137
+ <
138
+ T = never,
139
+ P extends any[] = [],
140
+ F extends boolean = _F,
141
+ O extends PatchesOptions = _O,
142
+ >(
143
+ mutate: ExplicitPrimitiveRecipe<T, P>,
144
+ options?: ExternalOptions<O, F>
145
+ ): (base: ExplicitState<T>, ...args: P) => Result<ExplicitState<T>, O, F>;
146
+ <
147
+ T = never,
148
+ P extends any[] = [],
149
+ F extends boolean = _F,
150
+ O extends PatchesOptions = _O,
151
+ >(
152
+ mutate: ExplicitRecipe<
153
+ T,
154
+ P,
155
+ ExplicitReturn<T> | Promise<ExplicitReturn<T>>
156
+ >,
157
+ options?: ExternalOptions<O, F>
158
+ ): (
159
+ base: ExplicitState<T>,
160
+ ...args: P
161
+ ) => Result<ExplicitState<T>, O, F> | Promise<Result<ExplicitState<T>, O, F>>;
162
+ <
163
+ T extends any,
164
+ P extends any[] = [],
165
+ F extends boolean = _F,
166
+ O extends PatchesOptions = _O,
167
+ R extends void | Promise<void> | T | Promise<T> = void,
168
+ >(
169
+ mutate: (draft: Draft<T>, ...args: P) => R,
170
+ options?: ExternalOptions<O, F>
171
+ ): (base: T, ...args: P) => CreateResult<T, O, F, R>;
172
+ // A recipe that annotates its draft with the state type itself, such as a
173
+ // type parameter, which TypeScript cannot match against `Draft<T>`.
174
+ <
175
+ T extends any,
176
+ P extends any[] = [],
177
+ F extends boolean = _F,
178
+ O extends PatchesOptions = _O,
179
+ R extends void | Promise<void> | T | Promise<T> = void,
180
+ >(
181
+ mutate: (draft: T, ...args: P) => R,
182
+ options?: ExternalOptions<O, F>
183
+ ): (base: T, ...args: P) => CreateResult<T, O, F, R>;
184
+ <T extends any, O extends PatchesOptions = _O, F extends boolean = _F>(
185
+ base: T,
186
+ options?: ExternalOptions<O, F>
187
+ ): [Draft<T>, () => Result<T, O, F>];
188
+ };
189
+
190
+ // Development builds warn once about a draft base, see `makeCreator`.
191
+ let draftBaseWarned = false;
192
+
193
+ /**
194
+ * `makeCreator(options)` to make a creator function.
195
+ *
196
+ * ## Example
197
+ *
198
+ * ```ts
199
+ * import { makeCreator } from 'mutative';
200
+ *
201
+ * const baseState = { foo: { bar: 'str' }, arr: [] };
202
+ * const create = makeCreator({ enableAutoFreeze: true });
203
+ * const state = create(
204
+ * baseState,
205
+ * (draft) => {
206
+ * draft.foo.bar = 'str2';
207
+ * },
208
+ * );
209
+ *
210
+ * expect(state).toEqual({ foo: { bar: 'str2' }, arr: [] });
211
+ * expect(state).not.toBe(baseState);
212
+ * expect(state.foo).not.toBe(baseState.foo);
213
+ * expect(state.arr).toBe(baseState.arr);
214
+ * expect(Object.isFrozen(state)).toBeTruthy();
215
+ * ```
216
+ */
217
+ export const makeCreator: MakeCreator = (arg) => {
218
+ if (
219
+ __DEV__ &&
220
+ arg !== undefined &&
221
+ Object.prototype.toString.call(arg) !== '[object Object]'
222
+ ) {
223
+ throw new Error(
224
+ `Invalid options: ${String(arg)}, 'options' should be an object.`
225
+ );
226
+ }
227
+ return function create(arg0: any, arg1: any, arg2?: any): any {
228
+ if (typeof arg0 === 'function' && typeof arg1 !== 'function') {
229
+ return function (this: any, base: any, ...args: any[]) {
230
+ return create(
231
+ base,
232
+ (draft: any) => arg0.call(this, draft, ...args),
233
+ arg1
234
+ );
235
+ };
236
+ }
237
+ const base = arg0;
238
+ const mutate = arg1 as (...args: any[]) => any;
239
+ let options = arg2;
240
+ if (typeof arg1 !== 'function') {
241
+ options = arg1;
242
+ }
243
+ if (
244
+ __DEV__ &&
245
+ options !== undefined &&
246
+ Object.prototype.toString.call(options) !== '[object Object]'
247
+ ) {
248
+ throw new Error(
249
+ `Invalid options: ${options}, 'options' should be an object.`
250
+ );
251
+ }
252
+ options = {
253
+ ...arg,
254
+ ...options,
255
+ };
256
+ const draftBase = isDraft(base);
257
+ // A draft base is drafted as `current(draft)`, so the values that the
258
+ // recipe leaves unchanged are objects of the base state.
259
+ if (
260
+ __DEV__ &&
261
+ draftBase &&
262
+ typeof arg1 === 'function' &&
263
+ !draftBaseWarned
264
+ ) {
265
+ draftBaseWarned = true;
266
+ console.warn(
267
+ `create() received a draft as its base and drafts current(draft), unlike Immer's produce: the values that its recipe leaves unchanged are objects of the base state, so changing them after the result is assigned back changes the base state. Make such changes in the recipe or before calling create(); see https://mutative.js.org/docs/api-reference/create#create-on-a-draft`
268
+ );
269
+ }
270
+ const state = draftBase ? current(base) : base;
271
+ const mark = Array.isArray(options.mark)
272
+ ? (((value: unknown, types: typeof dataTypes) => {
273
+ for (const mark of options.mark as Mark<any, any>[]) {
274
+ if (__DEV__ && typeof mark !== 'function') {
275
+ throw new Error(
276
+ `Invalid mark: ${mark}, 'mark' should be a function.`
277
+ );
278
+ }
279
+ const result = mark(value, types);
280
+ if (result) {
281
+ return result;
282
+ }
283
+ }
284
+ return;
285
+ }) as Mark<any, any>)
286
+ : options.mark;
287
+ const enablePatches = options.enablePatches ?? false;
288
+ const strict = options.strict ?? false;
289
+ const enableAutoFreeze = options.enableAutoFreeze ?? false;
290
+ const _options: Options<any, any> = {
291
+ enableAutoFreeze,
292
+ mark,
293
+ strict,
294
+ enablePatches,
295
+ };
296
+ if (
297
+ !isDraftable(state, _options) &&
298
+ typeof state === 'object' &&
299
+ state !== null
300
+ ) {
301
+ die(ErrorCode.InvalidBaseState);
302
+ }
303
+ const [draft, finalize, finalities] = draftify(state, _options);
304
+ if (typeof arg1 !== 'function') {
305
+ if (!isDraftable(state, _options)) {
306
+ die(ErrorCode.InvalidBaseState);
307
+ }
308
+ finalities.scoped = false;
309
+ return [draft, finalize];
310
+ }
311
+ // A failed producer revokes its drafts, without reading the root draft,
312
+ // which finalization may already have revoked, and releases the array
313
+ // method cache, which must not keep it alive.
314
+ function fail(error: unknown): never {
315
+ revokeProxy(finalities);
316
+ releaseArrayMethods(finalities.revoke);
317
+ throw error;
318
+ }
319
+ let result: any;
320
+ try {
321
+ result = mutate(draft);
322
+ } catch (error) {
323
+ fail(error);
324
+ }
325
+ const returnValue = (value: any) => {
326
+ const proxyDraft = getProxyDraft(draft)!;
327
+ if (!isDraft(value)) {
328
+ if (
329
+ value !== undefined &&
330
+ !isEqual(value, draft) &&
331
+ proxyDraft?.operated
332
+ ) {
333
+ die(ErrorCode.MutateAndReturn);
334
+ }
335
+ const rawReturnValue = value?.[RAW_RETURN_SYMBOL] as [any] | undefined;
336
+ if (rawReturnValue) {
337
+ const _value = rawReturnValue[0];
338
+ if (_options.strict && typeof value === 'object' && value !== null) {
339
+ handleReturnValue(proxyDraft, value, true);
340
+ }
341
+ return finalize([_value]);
342
+ }
343
+ if (value !== undefined) {
344
+ if (typeof value === 'object' && value !== null) {
345
+ handleReturnValue(proxyDraft, value);
346
+ }
347
+ return finalize([value]);
348
+ }
349
+ }
350
+ if (value === draft || value === undefined) {
351
+ return finalize([]);
352
+ }
353
+ const returnedProxyDraft = getProxyDraft(value)!;
354
+ if (_options === returnedProxyDraft.options) {
355
+ if (returnedProxyDraft.operated) {
356
+ die(ErrorCode.CannotReturnModifiedChildDraft);
357
+ }
358
+ return finalize([current(value)]);
359
+ }
360
+ return finalize([value]);
361
+ };
362
+ // Returned values are checked and finalized after the recipe, and a
363
+ // failure there ends the producer like an error in the recipe does.
364
+ const finish = (value: any) => {
365
+ try {
366
+ return returnValue(value);
367
+ } catch (error) {
368
+ return fail(error);
369
+ } finally {
370
+ releaseArrayMethods(finalities.revoke);
371
+ }
372
+ };
373
+ try {
374
+ // Classifying a returned Proxy, or reading/calling an overridden then,
375
+ // can throw before a Promise has registered the failure handler.
376
+ if (result instanceof Promise) return result.then(finish, fail);
377
+ } catch (error) {
378
+ return fail(error);
379
+ }
380
+ return finish(result);
381
+ };
382
+ };