@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,141 @@
1
+ /**
2
+ * An extended version of the `Event` emitted by the `EventSource` object when an error occurs.
3
+ * While the spec does not include any additional properties, we intentionally go beyond the spec
4
+ * and provide some (minimal) additional information to aid in debugging.
5
+ *
6
+ * @public
7
+ */
8
+ export class ErrorEvent extends Event {
9
+ /**
10
+ * HTTP status code, if this was triggered by an HTTP error
11
+ * Note: this is not part of the spec, but is included for better error handling.
12
+ *
13
+ * @public
14
+ */
15
+ public code?: number | undefined
16
+
17
+ /**
18
+ * Optional message attached to the error.
19
+ * Note: this is not part of the spec, but is included for better error handling.
20
+ *
21
+ * @public
22
+ */
23
+ public message?: string | undefined
24
+
25
+ /**
26
+ * Constructs a new `ErrorEvent` instance. This is typically not called directly,
27
+ * but rather emitted by the `EventSource` object when an error occurs.
28
+ *
29
+ * @param type - The type of the event (should be "error")
30
+ * @param errorEventInitDict - Optional properties to include in the error event
31
+ */
32
+ constructor(
33
+ type: string,
34
+ errorEventInitDict?: {message?: string | undefined; code?: number | undefined},
35
+ ) {
36
+ super(type)
37
+ this.code = errorEventInitDict?.code ?? undefined
38
+ this.message = errorEventInitDict?.message ?? undefined
39
+ }
40
+
41
+ /**
42
+ * Node.js "hides" the `message` and `code` properties of the `ErrorEvent` instance,
43
+ * when it is `console.log`'ed. This makes it harder to debug errors. To ease debugging,
44
+ * we explicitly include the properties in the `inspect` method.
45
+ *
46
+ * This is automatically called by Node.js when you `console.log` an instance of this class.
47
+ *
48
+ * @param _depth - The current depth
49
+ * @param options - The options passed to `util.inspect`
50
+ * @param inspect - The inspect function to use (prevents having to import it from `util`)
51
+ * @returns A string representation of the error
52
+ */
53
+ [Symbol.for('nodejs.util.inspect.custom')](
54
+ _depth: number,
55
+ options: {colors: boolean},
56
+ inspect: (obj: unknown, inspectOptions: {colors: boolean}) => string,
57
+ ): string {
58
+ return inspect(inspectableError(this), options)
59
+ }
60
+
61
+ /**
62
+ * Deno "hides" the `message` and `code` properties of the `ErrorEvent` instance,
63
+ * when it is `console.log`'ed. This makes it harder to debug errors. To ease debugging,
64
+ * we explicitly include the properties in the `inspect` method.
65
+ *
66
+ * This is automatically called by Deno when you `console.log` an instance of this class.
67
+ *
68
+ * @param inspect - The inspect function to use (prevents having to import it from `util`)
69
+ * @param options - The options passed to `Deno.inspect`
70
+ * @returns A string representation of the error
71
+ */
72
+ [Symbol.for('Deno.customInspect')](
73
+ inspect: (obj: unknown, inspectOptions: {colors: boolean}) => string,
74
+ options: {colors: boolean},
75
+ ): string {
76
+ return inspect(inspectableError(this), options)
77
+ }
78
+ }
79
+
80
+ /**
81
+ * For environments where DOMException may not exist, we will use a SyntaxError instead.
82
+ * While this isn't strictly according to spec, it is very close.
83
+ *
84
+ * @param message - The message to include in the error
85
+ * @returns A `DOMException` or `SyntaxError` instance
86
+ * @internal
87
+ */
88
+ export function syntaxError(message: string): SyntaxError {
89
+ // If someone can figure out a way to make this work without depending on DOM/Node.js typings,
90
+ // and without casting to `any`, please send a PR 🙏
91
+
92
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
93
+ const DomException = (globalThis as any).DOMException
94
+ if (typeof DomException === 'function') {
95
+ return new DomException(message, 'SyntaxError')
96
+ }
97
+
98
+ return new SyntaxError(message)
99
+ }
100
+
101
+ /**
102
+ * Flatten an error into a single error message string.
103
+ * Unwraps nested errors and joins them with a comma.
104
+ *
105
+ * @param err - The error to flatten
106
+ * @returns A string representation of the error
107
+ * @internal
108
+ */
109
+ export function flattenError(err: unknown): string {
110
+ if (!(err instanceof Error)) {
111
+ return `${err}`
112
+ }
113
+
114
+ if ('errors' in err && Array.isArray(err.errors)) {
115
+ return err.errors.map(flattenError).join(', ')
116
+ }
117
+
118
+ if ('cause' in err && err.cause instanceof Error) {
119
+ return `${err}: ${flattenError(err.cause)}`
120
+ }
121
+
122
+ return err.message
123
+ }
124
+
125
+ /**
126
+ * Convert an `ErrorEvent` instance into a plain object for inspection.
127
+ *
128
+ * @param err - The `ErrorEvent` instance to inspect
129
+ * @returns A plain object representation of the error
130
+ * @internal
131
+ */
132
+ function inspectableError(err: ErrorEvent) {
133
+ return {
134
+ type: err.type,
135
+ message: err.message,
136
+ code: err.code,
137
+ defaultPrevented: err.defaultPrevented,
138
+ cancelable: err.cancelable,
139
+ timeStamp: err.timeStamp,
140
+ }
141
+ }
@@ -0,0 +1,3 @@
1
+ export {ErrorEvent} from './errors.ts'
2
+ export {EventSource, type EventSourceConstructor} from './EventSource.ts'
3
+ export type * from './types.ts'
@@ -0,0 +1,166 @@
1
+ import type {ErrorEvent} from './errors.ts'
2
+
3
+ /**
4
+ * Stripped down version of `fetch()`, only defining the parts we care about.
5
+ * This ensures it should work with "most" fetch implementations.
6
+ *
7
+ * @public
8
+ */
9
+ export type FetchLike = (
10
+ url: string | URL,
11
+ init: EventSourceFetchInit,
12
+ ) => Promise<FetchLikeResponse>
13
+
14
+ /**
15
+ * Subset of `RequestInit` used for `fetch()` calls made by the `EventSource` class.
16
+ * As we know that we will be passing certain values, we can be more specific and have
17
+ * users not have to do optional chaining and similar for things that will always be there.
18
+ *
19
+ * @public
20
+ */
21
+ export interface EventSourceFetchInit {
22
+ /** An AbortSignal to set request's signal. Typed as `any` because of polyfill inconsistencies. */
23
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
24
+ signal: {aborted: boolean} | any
25
+
26
+ /** A Headers object, an object literal, or an array of two-item arrays to set request's headers. */
27
+ headers: {
28
+ [key: string]: string
29
+ Accept: 'text/event-stream'
30
+ }
31
+
32
+ /** A string to indicate whether the request will use CORS, or will be restricted to same-origin URLs. Sets request's mode. */
33
+ mode: 'cors' | 'no-cors' | 'same-origin'
34
+
35
+ /** A string indicating whether credentials will be sent with the request always, never, or only when sent to a same-origin URL. Sets request's credentials. */
36
+ credentials?: 'include' | 'omit' | 'same-origin'
37
+
38
+ /** Controls how the request is cached. */
39
+ cache: 'no-store'
40
+
41
+ /** A string indicating whether request follows redirects, results in an error upon encountering a redirect, or returns the redirect (in an opaque fashion). Sets request's redirect. */
42
+ redirect: 'error' | 'follow' | 'manual'
43
+ }
44
+
45
+ /**
46
+ * A chunk read off a response body.
47
+ *
48
+ * Chunks are handed to a `TextDecoder`, which only accepts buffers, so this is what a reader has
49
+ * to yield to be usable. The union is spelled out because the node (`TypedArray | DataView`) and
50
+ * DOM (`ArrayBufferView`) typings describe "any buffer view" differently, and these three members
51
+ * are accepted by both.
52
+ */
53
+ type BodyChunk = Uint8Array | DataView | ArrayBuffer
54
+
55
+ /**
56
+ * Stripped down version of `ReadableStreamDefaultReader`, only defining the parts we care about.
57
+ *
58
+ * Note that the `done: true` result allows `value` to be missing _or_ explicitly `undefined`:
59
+ * TypeScript 5.9's DOM lib types `ReadableStreamDefaultReader.read()`'s done-result as
60
+ * `{done: true, value: T | undefined}`, so under `exactOptionalPropertyTypes` an optional
61
+ * property alone would reject standard readers.
62
+ *
63
+ * @public
64
+ */
65
+ export interface ReaderLike {
66
+ read(): Promise<{done: false; value: BodyChunk} | {done: true; value?: BodyChunk | undefined}>
67
+ cancel(): Promise<void>
68
+ }
69
+
70
+ /**
71
+ * Minimal version of the `Response` type returned by `fetch()`.
72
+ *
73
+ * @public
74
+ */
75
+ export interface FetchLikeResponse {
76
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
77
+ readonly body: {getReader(): ReaderLike} | Response['body'] | null
78
+ readonly url: string
79
+ readonly status: number
80
+ readonly redirected: boolean
81
+ readonly headers: {get(name: string): string | null}
82
+ }
83
+
84
+ /**
85
+ * Mirrors the official DOM typings, with the exception of the extended ErrorEvent.
86
+ *
87
+ * @public
88
+ */
89
+ export interface EventSourceEventMap {
90
+ error: ErrorEvent
91
+ message: MessageEvent
92
+ open: Event
93
+ }
94
+
95
+ /**
96
+ * Mirrors the official DOM typings (for the most part)
97
+ *
98
+ * @public
99
+ */
100
+ export interface EventSourceInit {
101
+ /**
102
+ * A boolean value, defaulting to `false`, indicating if CORS should be set to `include` credentials.
103
+ */
104
+ withCredentials?: boolean
105
+
106
+ /**
107
+ * Optional fetch implementation to use. Defaults to `globalThis.fetch`.
108
+ * Can also be used for advanced use cases like mocking, proxying, custom certs etc.
109
+ */
110
+ fetch?: FetchLike
111
+
112
+ /**
113
+ * Maximum number of characters to buffer while parsing an incomplete EventSource line.
114
+ * Defaults to 100 MB.
115
+ */
116
+ maxBufferSize?: number
117
+ }
118
+
119
+ /**
120
+ * Mirrors the official DOM typings (sorta).
121
+ *
122
+ * @public
123
+ */
124
+ export interface EventListenerOptions {
125
+ /** Not directly used by Node.js. Added for API completeness. Default: `false`. */
126
+ capture?: boolean
127
+ }
128
+
129
+ /**
130
+ * Mirrors the official DOM typings (sorta).
131
+ *
132
+ * @public
133
+ */
134
+ export interface AddEventListenerOptions extends EventListenerOptions {
135
+ /** When `true`, the listener is automatically removed when it is first invoked. Default: `false`. */
136
+ once?: boolean
137
+ /** When `true`, serves as a hint that the listener will not call the `Event` object's `preventDefault()` method. Default: false. */
138
+ passive?: boolean
139
+ /** The listener will be removed when the given AbortSignal object's `abort()` method is called. */
140
+ signal?: AbortSignal
141
+ }
142
+
143
+ /**
144
+ * Mirrors the official DOM typings.
145
+ *
146
+ * @public
147
+ */
148
+ export type EventListenerOrEventListenerObject = EventListener | EventListenerObject
149
+
150
+ /**
151
+ * Mirrors the official DOM typings.
152
+ *
153
+ * @public
154
+ */
155
+ export interface EventListener {
156
+ (evt: Event | MessageEvent): void
157
+ }
158
+
159
+ /**
160
+ * Mirrors the official DOM typings.
161
+ *
162
+ * @public
163
+ */
164
+ export interface EventListenerObject {
165
+ handleEvent(object: Event): void
166
+ }
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Espen Hovlandsdal <espen@hovlandsdal.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,157 @@
1
+ # eventsource-parser
2
+
3
+ [![npm version](https://img.shields.io/npm/v/eventsource-parser.svg?style=flat-square)](https://www.npmjs.com/package/eventsource-parser)[![npm bundle size](https://img.shields.io/bundlephobia/minzip/eventsource-parser?style=flat-square)](https://bundlephobia.com/result?p=eventsource-parser)[![npm weekly downloads](https://img.shields.io/npm/dw/eventsource-parser.svg?style=flat-square)](https://www.npmjs.com/package/eventsource-parser)
4
+
5
+ A streaming parser for [server-sent events/eventsource](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events), without any assumptions about how the actual stream of data is retrieved. It is intended to be a building block for [clients](https://github.com/rexxars/eventsource-client) and polyfills in javascript environments such as browsers, node.js and deno.
6
+
7
+ If you are looking for a modern client implementation, see [eventsource-client](https://github.com/rexxars/eventsource-client).
8
+
9
+ You create an instance of the parser, and _feed_ it chunks of data - partial or complete, and the parse emits parsed messages once it receives a complete message. A [TransformStream variant](#stream-usage) is also available for environments that support it (modern browsers, Node 18 and higher).
10
+
11
+ Other modules in the EventSource family:
12
+
13
+ - [eventsource-client](https://github.com/rexxars/eventsource-client): modern, feature rich eventsource client for browsers, node.js, bun, deno and other modern JavaScript environments.
14
+ - [eventsource-encoder](https://github.com/rexxars/eventsource-encoder): encodes messages in the EventSource/Server-Sent Events format.
15
+ - [eventsource](https://github.com/eventsource/eventsource): Node.js polyfill for the WhatWG EventSource API.
16
+
17
+ > [!NOTE]
18
+ > Migrating from eventsource-parser 1.x/2.x? See the [migration guide](./MIGRATE-v3.md).
19
+
20
+ ## Installation
21
+
22
+ ```bash
23
+ npm install --save eventsource-parser
24
+ ```
25
+
26
+ ## Usage
27
+
28
+ ```ts
29
+ import {createParser, type EventSourceMessage} from 'eventsource-parser'
30
+
31
+ function onEvent(event: EventSourceMessage) {
32
+ console.log('Received event!')
33
+ console.log('id: %s', event.id || '<none>')
34
+ console.log('event: %s', event.event || '<none>')
35
+ console.log('data: %s', event.data)
36
+ }
37
+
38
+ const parser = createParser({onEvent})
39
+ const sseStream = getSomeReadableStream()
40
+
41
+ for await (const chunk of sseStream) {
42
+ parser.feed(chunk)
43
+ }
44
+
45
+ // If you want to re-use the parser for a new stream of events, make sure to reset it!
46
+ parser.reset()
47
+ console.log('Done!')
48
+ ```
49
+
50
+ ### Retry intervals
51
+
52
+ If the server sends a `retry` field in the event stream, the parser will call any `onRetry` callback specified to the `createParser` function:
53
+
54
+ ```ts
55
+ const parser = createParser({
56
+ onRetry(retryInterval) {
57
+ console.log('Server requested retry interval of %dms', retryInterval)
58
+ },
59
+ onEvent(event) {
60
+ // …
61
+ },
62
+ })
63
+ ```
64
+
65
+ ### Parse errors
66
+
67
+ If the parser encounters an error while parsing, it will call any `onError` callback provided to the `createParser` function:
68
+
69
+ ```ts
70
+ import {type ParseError} from 'eventsource-parser'
71
+
72
+ const parser = createParser({
73
+ onError(error: ParseError) {
74
+ console.error('Error parsing event:', error)
75
+ if (error.type === 'invalid-field') {
76
+ console.error('Field name:', error.field)
77
+ console.error('Field value:', error.value)
78
+ console.error('Line:', error.line)
79
+ } else if (error.type === 'invalid-retry') {
80
+ console.error('Invalid retry interval:', error.value)
81
+ }
82
+ },
83
+ onEvent(event) {
84
+ // …
85
+ },
86
+ })
87
+ ```
88
+
89
+ Note that `invalid-field` errors will usually be called for any invalid data - not only data shaped as `field: value`. This is because the EventSource specification says to treat anything prior to a `:` as the field name. Use the `error.line` property to get the full line that caused the error.
90
+
91
+ > [!NOTE]
92
+ > When encountering the end of a stream, calling `.reset({consume: true})` on the parser to flush any remaining data and reset the parser state. This will trigger the `onError` callback if the pending data is not a valid event.
93
+
94
+ ### Comments
95
+
96
+ The parser will ignore comments (lines starting with `:`) by default. If you want to handle comments, you can provide an `onComment` callback to the `createParser` function:
97
+
98
+ ```ts
99
+ const parser = createParser({
100
+ onComment(comment) {
101
+ console.log('Received comment:', comment)
102
+ },
103
+ onEvent(event) {
104
+ // …
105
+ },
106
+ })
107
+ ```
108
+
109
+ > [!NOTE]
110
+ > Leading whitespace is not stripped from comments, eg `: comment` will give ` comment` as the comment value, not `comment` (note the leading space).
111
+
112
+ ### Limiting buffered memory (`maxBufferSize`)
113
+
114
+ By default the parser buffers data indefinitely until a server completes an event. A server (or proxy) that never terminates a line, or that keeps appending `data:` lines without ever sending a blank line to dispatch the event, can therefore grow the parser's buffers without bound.
115
+
116
+ Pass a `maxBufferSize` (in characters) to `createParser` to cap this. If the combined size of the pending line buffer and the in-progress event's data buffer exceeds the limit, the parser emits a `ParseError` with `type: 'max-buffer-size-exceeded'` and becomes terminated: subsequent calls to `feed()` will throw until `reset()` is called.
117
+
118
+ ```ts
119
+ const parser = createParser({
120
+ maxBufferSize: 1024 * 1024, // 1 MB
121
+ onEvent(event) {
122
+ // …
123
+ },
124
+ onError(error) {
125
+ if (error.type === 'max-buffer-size-exceeded') {
126
+ // Stream peer is misbehaving — typically you'd close the connection.
127
+ }
128
+ },
129
+ })
130
+ ```
131
+
132
+ The same option is available on the [stream variant](#stream-usage); the stream is always errored when this limit is exceeded, regardless of the `onError` setting (since the underlying parser is unrecoverable without a `reset()`).
133
+
134
+ ## Stream usage
135
+
136
+ ```ts
137
+ import {EventSourceParserStream} from 'eventsource-parser/stream'
138
+
139
+ const eventStream = response.body
140
+ .pipeThrough(new TextDecoderStream())
141
+ .pipeThrough(new EventSourceParserStream())
142
+ ```
143
+
144
+ The stream constructor accepts a subset of the `createParser` options (`onComment`, `onRetry`, `maxBufferSize`) plus an `onError` that can either be a function or set to `'terminate'` to error the stream on parse errors. Events are delivered through the stream itself rather than via an `onEvent` callback:
145
+
146
+ ```ts
147
+ new EventSourceParserStream({
148
+ maxBufferSize: 1024 * 1024,
149
+ onError: 'terminate',
150
+ })
151
+ ```
152
+
153
+ Note that the TransformStream is exposed under a separate export (`eventsource-parser/stream`), in order to maximize compatibility with environments that do not have the `TransformStream` constructor available.
154
+
155
+ ## License
156
+
157
+ MIT © [Espen Hovlandsdal](https://espen.codes/)
@@ -0,0 +1,177 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: !0 });
3
+ class ParseError extends Error {
4
+ constructor(message, options) {
5
+ super(message), this.name = "ParseError", this.type = options.type, this.field = options.field, this.value = options.value, this.line = options.line;
6
+ }
7
+ }
8
+ const LF = 10, CR = 13, SPACE = 32;
9
+ function noop(_arg) {
10
+ }
11
+ function createParser(config) {
12
+ if (typeof config == "function")
13
+ throw new TypeError(
14
+ "`config` must be an object, got a function instead. Did you mean `createParser({onEvent: fn})`?"
15
+ );
16
+ const { onEvent = noop, onError = noop, onRetry = noop, onComment, maxBufferSize } = config, pendingFragments = [];
17
+ let pendingFragmentsLength = 0, isFirstChunk = !0, id, data = "", dataLines = 0, eventType, terminated = !1;
18
+ function feed(chunk) {
19
+ if (terminated)
20
+ throw new Error(
21
+ "Cannot feed parser: it was terminated after exceeding the configured max buffer size. Call `reset()` to resume parsing."
22
+ );
23
+ if (isFirstChunk && (isFirstChunk = !1, chunk.charCodeAt(0) === 239 && chunk.charCodeAt(1) === 187 && chunk.charCodeAt(2) === 191 && (chunk = chunk.slice(3))), pendingFragments.length === 0) {
24
+ const trailing2 = processLines(chunk);
25
+ trailing2 !== "" && (pendingFragments.push(trailing2), pendingFragmentsLength = trailing2.length), checkBufferSize();
26
+ return;
27
+ }
28
+ if (chunk.indexOf(`
29
+ `) === -1 && chunk.indexOf("\r") === -1) {
30
+ pendingFragments.push(chunk), pendingFragmentsLength += chunk.length, checkBufferSize();
31
+ return;
32
+ }
33
+ pendingFragments.push(chunk);
34
+ const input = pendingFragments.join("");
35
+ pendingFragments.length = 0, pendingFragmentsLength = 0;
36
+ const trailing = processLines(input);
37
+ trailing !== "" && (pendingFragments.push(trailing), pendingFragmentsLength = trailing.length), checkBufferSize();
38
+ }
39
+ function checkBufferSize() {
40
+ maxBufferSize !== void 0 && (pendingFragmentsLength + data.length <= maxBufferSize || (terminated = !0, pendingFragments.length = 0, pendingFragmentsLength = 0, id = void 0, data = "", dataLines = 0, eventType = void 0, onError(
41
+ new ParseError(`Buffered data exceeded max buffer size of ${maxBufferSize} characters`, {
42
+ type: "max-buffer-size-exceeded"
43
+ })
44
+ )));
45
+ }
46
+ function processLines(chunk) {
47
+ let searchIndex = 0;
48
+ if (chunk.indexOf("\r") === -1) {
49
+ let lfIndex = chunk.indexOf(`
50
+ `, searchIndex);
51
+ for (; lfIndex !== -1; ) {
52
+ if (searchIndex === lfIndex) {
53
+ dataLines > 0 && onEvent({ id, event: eventType, data }), id = void 0, data = "", dataLines = 0, eventType = void 0, searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
54
+ `, searchIndex);
55
+ continue;
56
+ }
57
+ const firstCharCode = chunk.charCodeAt(searchIndex);
58
+ if (isDataPrefix(chunk, searchIndex, firstCharCode)) {
59
+ const valueStart = chunk.charCodeAt(searchIndex + 5) === SPACE ? searchIndex + 6 : searchIndex + 5, value = chunk.slice(valueStart, lfIndex);
60
+ if (dataLines === 0 && chunk.charCodeAt(lfIndex + 1) === LF) {
61
+ onEvent({ id, event: eventType, data: value }), id = void 0, data = "", eventType = void 0, searchIndex = lfIndex + 2, lfIndex = chunk.indexOf(`
62
+ `, searchIndex);
63
+ continue;
64
+ }
65
+ data = dataLines === 0 ? value : `${data}
66
+ ${value}`, dataLines++;
67
+ } else isEventPrefix(chunk, searchIndex, firstCharCode) ? eventType = chunk.slice(
68
+ chunk.charCodeAt(searchIndex + 6) === SPACE ? searchIndex + 7 : searchIndex + 6,
69
+ lfIndex
70
+ ) || void 0 : parseLine(chunk, searchIndex, lfIndex);
71
+ searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
72
+ `, searchIndex);
73
+ }
74
+ return chunk.slice(searchIndex);
75
+ }
76
+ for (; searchIndex < chunk.length; ) {
77
+ const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
78
+ `, searchIndex);
79
+ let lineEnd = -1;
80
+ if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = crIndex < lfIndex ? crIndex : lfIndex : crIndex !== -1 ? crIndex === chunk.length - 1 ? lineEnd = -1 : lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1)
81
+ break;
82
+ parseLine(chunk, searchIndex, lineEnd), searchIndex = lineEnd + 1, chunk.charCodeAt(searchIndex - 1) === CR && chunk.charCodeAt(searchIndex) === LF && searchIndex++;
83
+ }
84
+ return chunk.slice(searchIndex);
85
+ }
86
+ function parseLine(chunk, start, end) {
87
+ if (start === end) {
88
+ dispatchEvent();
89
+ return;
90
+ }
91
+ const firstCharCode = chunk.charCodeAt(start);
92
+ if (isDataPrefix(chunk, start, firstCharCode)) {
93
+ const valueStart = chunk.charCodeAt(start + 5) === SPACE ? start + 6 : start + 5, value2 = chunk.slice(valueStart, end);
94
+ data = dataLines === 0 ? value2 : `${data}
95
+ ${value2}`, dataLines++;
96
+ return;
97
+ }
98
+ if (isEventPrefix(chunk, start, firstCharCode)) {
99
+ eventType = chunk.slice(chunk.charCodeAt(start + 6) === SPACE ? start + 7 : start + 6, end) || void 0;
100
+ return;
101
+ }
102
+ if (firstCharCode === 105 && chunk.charCodeAt(start + 1) === 100 && chunk.charCodeAt(start + 2) === 58) {
103
+ const value2 = chunk.slice(chunk.charCodeAt(start + 3) === SPACE ? start + 4 : start + 3, end);
104
+ value2.includes("\0") || (id = value2);
105
+ return;
106
+ }
107
+ if (firstCharCode === 58) {
108
+ if (onComment) {
109
+ const line2 = chunk.slice(start, end);
110
+ onComment(line2.slice(chunk.charCodeAt(start + 1) === SPACE ? 2 : 1));
111
+ }
112
+ return;
113
+ }
114
+ const line = chunk.slice(start, end), fieldSeparatorIndex = line.indexOf(":");
115
+ if (fieldSeparatorIndex === -1) {
116
+ processField(line, "", line);
117
+ return;
118
+ }
119
+ const field = line.slice(0, fieldSeparatorIndex), offset = line.charCodeAt(fieldSeparatorIndex + 1) === SPACE ? 2 : 1, value = line.slice(fieldSeparatorIndex + offset);
120
+ processField(field, value, line);
121
+ }
122
+ function processField(field, value, line) {
123
+ switch (field) {
124
+ case "event":
125
+ eventType = value || void 0;
126
+ break;
127
+ case "data":
128
+ data = dataLines === 0 ? value : `${data}
129
+ ${value}`, dataLines++;
130
+ break;
131
+ case "id":
132
+ value.includes("\0") || (id = value);
133
+ break;
134
+ case "retry":
135
+ /^\d+$/.test(value) ? onRetry(parseInt(value, 10)) : onError(
136
+ new ParseError(`Invalid \`retry\` value: "${value}"`, {
137
+ type: "invalid-retry",
138
+ value,
139
+ line
140
+ })
141
+ );
142
+ break;
143
+ default:
144
+ onError(
145
+ new ParseError(
146
+ `Unknown field "${field.length > 20 ? `${field.slice(0, 20)}\u2026` : field}"`,
147
+ { type: "unknown-field", field, value, line }
148
+ )
149
+ );
150
+ break;
151
+ }
152
+ }
153
+ function dispatchEvent() {
154
+ dataLines > 0 && onEvent({
155
+ id,
156
+ event: eventType,
157
+ data
158
+ }), id = void 0, data = "", dataLines = 0, eventType = void 0;
159
+ }
160
+ function reset(options = {}) {
161
+ if (options.consume && pendingFragments.length > 0) {
162
+ const incompleteLine = pendingFragments.join("");
163
+ parseLine(incompleteLine, 0, incompleteLine.length);
164
+ }
165
+ isFirstChunk = !0, id = void 0, data = "", dataLines = 0, eventType = void 0, pendingFragments.length = 0, pendingFragmentsLength = 0, terminated = !1;
166
+ }
167
+ return { feed, reset };
168
+ }
169
+ function isDataPrefix(chunk, i, firstCharCode) {
170
+ return firstCharCode === 100 && chunk.charCodeAt(i + 1) === 97 && chunk.charCodeAt(i + 2) === 116 && chunk.charCodeAt(i + 3) === 97 && chunk.charCodeAt(i + 4) === 58;
171
+ }
172
+ function isEventPrefix(chunk, i, firstCharCode) {
173
+ return firstCharCode === 101 && chunk.charCodeAt(i + 1) === 118 && chunk.charCodeAt(i + 2) === 101 && chunk.charCodeAt(i + 3) === 110 && chunk.charCodeAt(i + 4) === 116 && chunk.charCodeAt(i + 5) === 58;
174
+ }
175
+ exports.ParseError = ParseError;
176
+ exports.createParser = createParser;
177
+ //# sourceMappingURL=index.cjs.map