jazz-tools 2.0.0-alpha.6 → 2.0.0-alpha.60

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 (1660) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +178 -2
  3. package/bin/jazz-tools.js +91 -45
  4. package/dist/_dev/inspector-cache-runtime.d.ts +8 -0
  5. package/dist/_dev/inspector-cache-runtime.d.ts.map +1 -0
  6. package/dist/_dev/inspector-cache-runtime.js +237 -0
  7. package/dist/_dev/inspector-cache-runtime.js.map +1 -0
  8. package/dist/_dev/inspector-client.d.ts +15 -0
  9. package/dist/_dev/inspector-client.d.ts.map +1 -0
  10. package/dist/_dev/inspector-client.js +134 -0
  11. package/dist/_dev/inspector-client.js.map +1 -0
  12. package/dist/_dev/native-account-session.d.ts +16 -0
  13. package/dist/_dev/native-account-session.d.ts.map +1 -0
  14. package/dist/_dev/native-account-session.js +51 -0
  15. package/dist/_dev/native-account-session.js.map +1 -0
  16. package/dist/_dev/native-binding-codec.d.ts +9 -0
  17. package/dist/_dev/native-binding-codec.d.ts.map +1 -0
  18. package/dist/_dev/native-binding-codec.js +9 -0
  19. package/dist/_dev/native-binding-codec.js.map +1 -0
  20. package/dist/accounts/account-manager-core.d.ts +28 -0
  21. package/dist/accounts/account-manager-core.d.ts.map +1 -0
  22. package/dist/accounts/account-manager-core.js +179 -0
  23. package/dist/accounts/account-manager-core.js.map +1 -0
  24. package/dist/accounts/browser-host.d.ts +8 -0
  25. package/dist/accounts/browser-host.d.ts.map +1 -0
  26. package/dist/accounts/browser-host.js +16 -0
  27. package/dist/accounts/browser-host.js.map +1 -0
  28. package/dist/accounts/config-capability.d.ts +26 -0
  29. package/dist/accounts/config-capability.d.ts.map +1 -0
  30. package/dist/accounts/config-capability.js +58 -0
  31. package/dist/accounts/config-capability.js.map +1 -0
  32. package/dist/accounts/context.d.ts +14 -0
  33. package/dist/accounts/context.d.ts.map +1 -0
  34. package/dist/accounts/context.js +214 -0
  35. package/dist/accounts/context.js.map +1 -0
  36. package/dist/accounts/create-account-manager.d.ts +52 -0
  37. package/dist/accounts/create-account-manager.d.ts.map +1 -0
  38. package/dist/accounts/create-account-manager.js +17 -0
  39. package/dist/accounts/create-account-manager.js.map +1 -0
  40. package/dist/accounts/enrollment.d.ts +87 -0
  41. package/dist/accounts/enrollment.d.ts.map +1 -0
  42. package/dist/accounts/enrollment.js +305 -0
  43. package/dist/accounts/enrollment.js.map +1 -0
  44. package/dist/accounts/exports.d.ts +4 -0
  45. package/dist/accounts/exports.d.ts.map +1 -0
  46. package/dist/accounts/exports.js +2 -0
  47. package/dist/accounts/exports.js.map +1 -0
  48. package/dist/accounts/local-first.d.ts +14 -0
  49. package/dist/accounts/local-first.d.ts.map +1 -0
  50. package/dist/accounts/local-first.js +62 -0
  51. package/dist/accounts/local-first.js.map +1 -0
  52. package/dist/accounts/persistence.d.ts +34 -0
  53. package/dist/accounts/persistence.d.ts.map +1 -0
  54. package/dist/accounts/persistence.js +299 -0
  55. package/dist/accounts/persistence.js.map +1 -0
  56. package/dist/accounts/registry-client.d.ts +50 -0
  57. package/dist/accounts/registry-client.d.ts.map +1 -0
  58. package/dist/accounts/registry-client.js +108 -0
  59. package/dist/accounts/registry-client.js.map +1 -0
  60. package/dist/accounts/state.d.ts +76 -0
  61. package/dist/accounts/state.d.ts.map +1 -0
  62. package/dist/accounts/state.js +171 -0
  63. package/dist/accounts/state.js.map +1 -0
  64. package/dist/backend/admission.d.ts +18 -0
  65. package/dist/backend/admission.d.ts.map +1 -0
  66. package/dist/backend/admission.js +139 -0
  67. package/dist/backend/admission.js.map +1 -0
  68. package/dist/backend/backend-clients.d.ts +76 -0
  69. package/dist/backend/backend-clients.d.ts.map +1 -0
  70. package/dist/backend/backend-clients.js +237 -0
  71. package/dist/backend/backend-clients.js.map +1 -0
  72. package/dist/backend/backend-issuer.d.ts +6 -0
  73. package/dist/backend/backend-issuer.d.ts.map +1 -0
  74. package/dist/backend/backend-issuer.js +6 -0
  75. package/dist/backend/backend-issuer.js.map +1 -0
  76. package/dist/backend/blobs.d.ts +121 -0
  77. package/dist/backend/blobs.d.ts.map +1 -0
  78. package/dist/backend/blobs.js +123 -0
  79. package/dist/backend/blobs.js.map +1 -0
  80. package/dist/backend/create-jazz-context.d.ts +116 -0
  81. package/dist/backend/create-jazz-context.d.ts.map +1 -0
  82. package/dist/backend/create-jazz-context.js +607 -0
  83. package/dist/backend/create-jazz-context.js.map +1 -0
  84. package/dist/backend/create-jazz-session.d.ts +105 -0
  85. package/dist/backend/create-jazz-session.d.ts.map +1 -0
  86. package/dist/backend/create-jazz-session.js +467 -0
  87. package/dist/backend/create-jazz-session.js.map +1 -0
  88. package/dist/backend/create-jazz.d.ts +405 -0
  89. package/dist/backend/create-jazz.d.ts.map +1 -0
  90. package/dist/backend/create-jazz.js +2731 -0
  91. package/dist/backend/create-jazz.js.map +1 -0
  92. package/dist/backend/early-db.d.ts +29 -0
  93. package/dist/backend/early-db.d.ts.map +1 -0
  94. package/dist/backend/early-db.js +202 -0
  95. package/dist/backend/early-db.js.map +1 -0
  96. package/dist/backend/external-jwt.d.ts +27 -0
  97. package/dist/backend/external-jwt.d.ts.map +1 -0
  98. package/dist/backend/external-jwt.js +380 -0
  99. package/dist/backend/external-jwt.js.map +1 -0
  100. package/dist/backend/from-jwt.d.ts +62 -0
  101. package/dist/backend/from-jwt.d.ts.map +1 -0
  102. package/dist/backend/from-jwt.js +96 -0
  103. package/dist/backend/from-jwt.js.map +1 -0
  104. package/dist/backend/index.d.ts +11 -1
  105. package/dist/backend/index.d.ts.map +1 -1
  106. package/dist/backend/index.js +8 -1
  107. package/dist/backend/index.js.map +1 -1
  108. package/dist/backend/no-account-error.d.ts +23 -0
  109. package/dist/backend/no-account-error.d.ts.map +1 -0
  110. package/dist/backend/no-account-error.js +30 -0
  111. package/dist/backend/no-account-error.js.map +1 -0
  112. package/dist/backend/optional-peer.d.ts +9 -0
  113. package/dist/backend/optional-peer.d.ts.map +1 -0
  114. package/dist/backend/optional-peer.js +24 -0
  115. package/dist/backend/optional-peer.js.map +1 -0
  116. package/dist/backend/request-auth.d.ts +39 -0
  117. package/dist/backend/request-auth.d.ts.map +1 -0
  118. package/dist/backend/request-auth.js +77 -0
  119. package/dist/backend/request-auth.js.map +1 -0
  120. package/dist/backend/session-recheck.d.ts +18 -0
  121. package/dist/backend/session-recheck.d.ts.map +1 -0
  122. package/dist/backend/session-recheck.js +57 -0
  123. package/dist/backend/session-recheck.js.map +1 -0
  124. package/dist/backend/socket-deadline.d.ts +23 -0
  125. package/dist/backend/socket-deadline.d.ts.map +1 -0
  126. package/dist/backend/socket-deadline.js +70 -0
  127. package/dist/backend/socket-deadline.js.map +1 -0
  128. package/dist/backend/vercel-store.d.ts +223 -0
  129. package/dist/backend/vercel-store.d.ts.map +1 -0
  130. package/dist/backend/vercel-store.js +932 -0
  131. package/dist/backend/vercel-store.js.map +1 -0
  132. package/dist/better-auth-adapter/fixtures/permissions.d.ts +2 -0
  133. package/dist/better-auth-adapter/fixtures/permissions.d.ts.map +1 -0
  134. package/dist/better-auth-adapter/fixtures/permissions.js +2 -0
  135. package/dist/better-auth-adapter/fixtures/permissions.js.map +1 -0
  136. package/dist/better-auth-adapter/fixtures/schema.d.ts +69 -0
  137. package/dist/better-auth-adapter/fixtures/schema.d.ts.map +1 -0
  138. package/dist/better-auth-adapter/fixtures/schema.js +84 -0
  139. package/dist/better-auth-adapter/fixtures/schema.js.map +1 -0
  140. package/dist/better-auth-adapter/index.d.ts +13 -0
  141. package/dist/better-auth-adapter/index.d.ts.map +1 -0
  142. package/dist/better-auth-adapter/index.js +366 -0
  143. package/dist/better-auth-adapter/index.js.map +1 -0
  144. package/dist/better-auth-adapter/indexes.d.ts +9 -0
  145. package/dist/better-auth-adapter/indexes.d.ts.map +1 -0
  146. package/dist/better-auth-adapter/indexes.js +40 -0
  147. package/dist/better-auth-adapter/indexes.js.map +1 -0
  148. package/dist/better-auth-adapter/schema.d.ts +49 -0
  149. package/dist/better-auth-adapter/schema.d.ts.map +1 -0
  150. package/dist/better-auth-adapter/schema.js +300 -0
  151. package/dist/better-auth-adapter/schema.js.map +1 -0
  152. package/dist/better-auth-adapter/types.d.ts +13 -0
  153. package/dist/better-auth-adapter/types.d.ts.map +1 -0
  154. package/dist/better-auth-adapter/types.js +2 -0
  155. package/dist/better-auth-adapter/types.js.map +1 -0
  156. package/dist/better-auth-adapter/utils.d.ts +27 -0
  157. package/dist/better-auth-adapter/utils.d.ts.map +1 -0
  158. package/dist/better-auth-adapter/utils.js +189 -0
  159. package/dist/better-auth-adapter/utils.js.map +1 -0
  160. package/dist/browser-benchmark-mode.d.ts +6 -0
  161. package/dist/browser-benchmark-mode.d.ts.map +1 -0
  162. package/dist/browser-benchmark-mode.js +13 -0
  163. package/dist/browser-benchmark-mode.js.map +1 -0
  164. package/dist/classic-api.d.ts +59 -0
  165. package/dist/classic-api.d.ts.map +1 -0
  166. package/dist/classic-api.js +86 -0
  167. package/dist/classic-api.js.map +1 -0
  168. package/dist/cli.d.ts +29 -2
  169. package/dist/cli.d.ts.map +1 -1
  170. package/dist/cli.js +358 -268
  171. package/dist/cli.js.map +1 -1
  172. package/dist/client/index.d.ts +14 -0
  173. package/dist/client/index.d.ts.map +1 -0
  174. package/dist/client/index.js +8 -0
  175. package/dist/client/index.js.map +1 -0
  176. package/dist/cloud/api.d.ts +11 -0
  177. package/dist/cloud/api.d.ts.map +1 -0
  178. package/dist/cloud/api.js +46 -0
  179. package/dist/cloud/api.js.map +1 -0
  180. package/dist/cloud/commands.d.ts +13 -0
  181. package/dist/cloud/commands.d.ts.map +1 -0
  182. package/dist/cloud/commands.js +413 -0
  183. package/dist/cloud/commands.js.map +1 -0
  184. package/dist/cloud/credentials.d.ts +49 -0
  185. package/dist/cloud/credentials.d.ts.map +1 -0
  186. package/dist/cloud/credentials.js +219 -0
  187. package/dist/cloud/credentials.js.map +1 -0
  188. package/dist/cloud/session.d.ts +57 -0
  189. package/dist/cloud/session.d.ts.map +1 -0
  190. package/dist/cloud/session.js +269 -0
  191. package/dist/cloud/session.js.map +1 -0
  192. package/dist/codegen/relation-analyzer.d.ts +5 -12
  193. package/dist/codegen/relation-analyzer.d.ts.map +1 -1
  194. package/dist/codegen/relation-analyzer.js +54 -65
  195. package/dist/codegen/relation-analyzer.js.map +1 -1
  196. package/dist/codegen/schema-reader.d.ts +6 -2
  197. package/dist/codegen/schema-reader.d.ts.map +1 -1
  198. package/dist/codegen/schema-reader.js +129 -98
  199. package/dist/codegen/schema-reader.js.map +1 -1
  200. package/dist/dev/catalogue-api.d.ts +157 -0
  201. package/dist/dev/catalogue-api.d.ts.map +1 -0
  202. package/dist/dev/catalogue-api.js +145 -0
  203. package/dist/dev/catalogue-api.js.map +1 -0
  204. package/dist/dev/catalogue-project.d.ts +150 -0
  205. package/dist/dev/catalogue-project.d.ts.map +1 -0
  206. package/dist/dev/catalogue-project.js +1466 -0
  207. package/dist/dev/catalogue-project.js.map +1 -0
  208. package/dist/dev/catalogue.d.ts +72 -0
  209. package/dist/dev/catalogue.d.ts.map +1 -0
  210. package/dist/dev/catalogue.js +279 -0
  211. package/dist/dev/catalogue.js.map +1 -0
  212. package/dist/dev/dev-server.d.ts +57 -0
  213. package/dist/dev/dev-server.d.ts.map +1 -0
  214. package/dist/dev/dev-server.js +122 -0
  215. package/dist/dev/dev-server.js.map +1 -0
  216. package/dist/dev/index.d.ts +3 -0
  217. package/dist/dev/index.d.ts.map +1 -0
  218. package/dist/dev/index.js +3 -0
  219. package/dist/dev/index.js.map +1 -0
  220. package/dist/dev/inspector-overlay/browser-control-registry.d.ts +10 -0
  221. package/dist/dev/inspector-overlay/browser-control-registry.d.ts.map +1 -0
  222. package/dist/dev/inspector-overlay/browser-control-registry.js +188 -0
  223. package/dist/dev/inspector-overlay/browser-control-registry.js.map +1 -0
  224. package/dist/dev/inspector-overlay/embedded/assets/create-legacy-browser-delegate-X_T_QKCN.js +1 -0
  225. package/dist/dev/inspector-overlay/embedded/assets/esm-7mP3GQX4.js +1 -0
  226. package/dist/dev/inspector-overlay/embedded/assets/esm-BX6IY2Mv.js +1 -0
  227. package/dist/dev/inspector-overlay/embedded/assets/esm-CH5eVyQQ.js +1 -0
  228. package/dist/dev/inspector-overlay/embedded/assets/esm-aRzpnC3u.js +1 -0
  229. package/dist/dev/inspector-overlay/embedded/assets/esm-ezD5H765.js +1 -0
  230. package/dist/dev/inspector-overlay/embedded/assets/esm-k3rsq4Gn.js +1 -0
  231. package/dist/dev/inspector-overlay/embedded/assets/index-C-btvLcw.js +20 -0
  232. package/dist/dev/inspector-overlay/embedded/assets/index-C78Pprka.css +1 -0
  233. package/dist/dev/inspector-overlay/embedded/assets/jazz-broker-worker-CAMcDeUa.js +3 -0
  234. package/dist/dev/inspector-overlay/embedded/assets/jazz-broker-worker-XRRxJUcx.js +23997 -0
  235. package/dist/dev/inspector-overlay/embedded/assets/jazz_wasm-Cc71x_6y.js +1 -0
  236. package/dist/dev/inspector-overlay/embedded/assets/jazz_wasm_bg-KR7h3v27.wasm +0 -0
  237. package/dist/dev/inspector-overlay/embedded/assets/node-foreground-node-lease.browser-Bm3gYjlT.js +1 -0
  238. package/dist/dev/inspector-overlay/embedded/assets/trace-api-B5CaetI0.js +1 -0
  239. package/dist/dev/inspector-overlay/embedded/embedded.html +13 -0
  240. package/dist/dev/inspector-overlay/embedded/favicon.ico +0 -0
  241. package/dist/dev/inspector-overlay/host-bridge.d.ts +8 -0
  242. package/dist/dev/inspector-overlay/host-bridge.d.ts.map +1 -0
  243. package/dist/dev/inspector-overlay/host-bridge.js +136 -0
  244. package/dist/dev/inspector-overlay/host-bridge.js.map +1 -0
  245. package/dist/dev/inspector-overlay/inspector-host-types.d.ts +35 -0
  246. package/dist/dev/inspector-overlay/inspector-host-types.d.ts.map +1 -0
  247. package/dist/dev/inspector-overlay/inspector-host-types.js +10 -0
  248. package/dist/dev/inspector-overlay/inspector-host-types.js.map +1 -0
  249. package/dist/dev/inspector-overlay/loader.d.ts +13 -0
  250. package/dist/dev/inspector-overlay/loader.d.ts.map +1 -0
  251. package/dist/dev/inspector-overlay/loader.js +506 -0
  252. package/dist/dev/inspector-overlay/loader.js.map +1 -0
  253. package/dist/dev/inspector-overlay/serve.d.ts +46 -0
  254. package/dist/dev/inspector-overlay/serve.d.ts.map +1 -0
  255. package/dist/dev/inspector-overlay/serve.js +131 -0
  256. package/dist/dev/inspector-overlay/serve.js.map +1 -0
  257. package/dist/dev/legacy-schema-hash.d.ts +4 -0
  258. package/dist/dev/legacy-schema-hash.d.ts.map +1 -0
  259. package/dist/dev/legacy-schema-hash.js +12 -0
  260. package/dist/dev/legacy-schema-hash.js.map +1 -0
  261. package/dist/dev/migration-graph.d.ts +32 -0
  262. package/dist/dev/migration-graph.d.ts.map +1 -0
  263. package/dist/dev/migration-graph.js +136 -0
  264. package/dist/dev/migration-graph.js.map +1 -0
  265. package/dist/dev/migrations.d.ts +14 -0
  266. package/dist/dev/migrations.d.ts.map +1 -0
  267. package/dist/dev/migrations.js +441 -0
  268. package/dist/dev/migrations.js.map +1 -0
  269. package/dist/dev/schema-utils.d.ts +18 -0
  270. package/dist/dev/schema-utils.d.ts.map +1 -0
  271. package/dist/dev/schema-utils.js +365 -0
  272. package/dist/dev/schema-utils.js.map +1 -0
  273. package/dist/dev/schema-validation.d.ts +5 -0
  274. package/dist/dev/schema-validation.d.ts.map +1 -0
  275. package/dist/dev/schema-validation.js +11 -0
  276. package/dist/dev/schema-validation.js.map +1 -0
  277. package/dist/dev-tools/auto-attach.d.ts +11 -0
  278. package/dist/dev-tools/auto-attach.d.ts.map +1 -0
  279. package/dist/dev-tools/auto-attach.js +26 -0
  280. package/dist/dev-tools/auto-attach.js.map +1 -0
  281. package/dist/drivers/index.d.ts +1 -1
  282. package/dist/drivers/index.d.ts.map +1 -1
  283. package/dist/drivers/index.js.map +1 -1
  284. package/dist/drivers/schema-wire.d.ts +18 -0
  285. package/dist/drivers/schema-wire.d.ts.map +1 -0
  286. package/dist/drivers/schema-wire.js +66 -0
  287. package/dist/drivers/schema-wire.js.map +1 -0
  288. package/dist/drivers/types.d.ts +322 -45
  289. package/dist/drivers/types.d.ts.map +1 -1
  290. package/dist/drivers/types.js +5 -4
  291. package/dist/drivers/types.js.map +1 -1
  292. package/dist/dsl.d.ts +291 -101
  293. package/dist/dsl.d.ts.map +1 -1
  294. package/dist/dsl.js +244 -113
  295. package/dist/dsl.js.map +1 -1
  296. package/dist/e2ee/SODIUM-LICENSE.txt +36 -0
  297. package/dist/e2ee/SODIUM-SOURCES.json +4 -0
  298. package/dist/e2ee/browser.d.ts +18 -0
  299. package/dist/e2ee/browser.d.ts.map +1 -0
  300. package/dist/e2ee/browser.js +111 -0
  301. package/dist/e2ee/browser.js.map +1 -0
  302. package/dist/e2ee/context.d.ts +23 -0
  303. package/dist/e2ee/context.d.ts.map +1 -0
  304. package/dist/e2ee/context.js +49 -0
  305. package/dist/e2ee/context.js.map +1 -0
  306. package/dist/e2ee/crypto.d.ts +10 -0
  307. package/dist/e2ee/crypto.d.ts.map +1 -0
  308. package/dist/e2ee/crypto.js +22 -0
  309. package/dist/e2ee/crypto.js.map +1 -0
  310. package/dist/e2ee/envelope.d.ts +22 -0
  311. package/dist/e2ee/envelope.d.ts.map +1 -0
  312. package/dist/e2ee/envelope.js +52 -0
  313. package/dist/e2ee/envelope.js.map +1 -0
  314. package/dist/e2ee/index.d.ts +14 -0
  315. package/dist/e2ee/index.d.ts.map +1 -0
  316. package/dist/e2ee/index.js +3 -0
  317. package/dist/e2ee/index.js.map +1 -0
  318. package/dist/e2ee/large-value.d.ts +20 -0
  319. package/dist/e2ee/large-value.d.ts.map +1 -0
  320. package/dist/e2ee/large-value.js +204 -0
  321. package/dist/e2ee/large-value.js.map +1 -0
  322. package/dist/e2ee/native.d.ts +18 -0
  323. package/dist/e2ee/native.d.ts.map +1 -0
  324. package/dist/e2ee/native.js +91 -0
  325. package/dist/e2ee/native.js.map +1 -0
  326. package/dist/e2ee/record-frame.d.ts +3 -0
  327. package/dist/e2ee/record-frame.d.ts.map +1 -0
  328. package/dist/e2ee/record-frame.js +18 -0
  329. package/dist/e2ee/record-frame.js.map +1 -0
  330. package/dist/e2ee/signer.d.ts +10 -0
  331. package/dist/e2ee/signer.d.ts.map +1 -0
  332. package/dist/e2ee/signer.js +54 -0
  333. package/dist/e2ee/signer.js.map +1 -0
  334. package/dist/e2ee/sodium-browser.d.ts +2 -0
  335. package/dist/e2ee/sodium-browser.d.ts.map +1 -0
  336. package/dist/e2ee/sodium-browser.js +3432 -0
  337. package/dist/e2ee/sodium.d.ts +20 -0
  338. package/dist/e2ee/sodium.d.ts.map +1 -0
  339. package/dist/e2ee/sodium.js +165 -0
  340. package/dist/e2ee/sodium.js.map +1 -0
  341. package/dist/e2ee/types.d.ts +92 -0
  342. package/dist/e2ee/types.d.ts.map +1 -0
  343. package/dist/e2ee/types.js +2 -0
  344. package/dist/e2ee/types.js.map +1 -0
  345. package/dist/effect/backend/index.d.ts +8 -0
  346. package/dist/effect/backend/index.d.ts.map +1 -0
  347. package/dist/effect/backend/index.js +8 -0
  348. package/dist/effect/backend/index.js.map +1 -0
  349. package/dist/effect/errors.d.ts +53 -0
  350. package/dist/effect/errors.d.ts.map +1 -0
  351. package/dist/effect/errors.js +61 -0
  352. package/dist/effect/errors.js.map +1 -0
  353. package/dist/effect/index.d.ts +9 -0
  354. package/dist/effect/index.d.ts.map +1 -0
  355. package/dist/effect/index.js +9 -0
  356. package/dist/effect/index.js.map +1 -0
  357. package/dist/effect/jazz-backend.d.ts +69 -0
  358. package/dist/effect/jazz-backend.d.ts.map +1 -0
  359. package/dist/effect/jazz-backend.js +92 -0
  360. package/dist/effect/jazz-backend.js.map +1 -0
  361. package/dist/effect/jazz.d.ts +122 -0
  362. package/dist/effect/jazz.d.ts.map +1 -0
  363. package/dist/effect/jazz.js +159 -0
  364. package/dist/effect/jazz.js.map +1 -0
  365. package/dist/expo/auth-secret-store.d.ts +37 -0
  366. package/dist/expo/auth-secret-store.d.ts.map +1 -0
  367. package/dist/expo/auth-secret-store.js +139 -0
  368. package/dist/expo/auth-secret-store.js.map +1 -0
  369. package/dist/expo/create-account-manager.d.ts +28 -0
  370. package/dist/expo/create-account-manager.d.ts.map +1 -0
  371. package/dist/expo/create-account-manager.js +35 -0
  372. package/dist/expo/create-account-manager.js.map +1 -0
  373. package/dist/expo/create-jazz-session.d.ts +35 -0
  374. package/dist/expo/create-jazz-session.d.ts.map +1 -0
  375. package/dist/expo/create-jazz-session.js +39 -0
  376. package/dist/expo/create-jazz-session.js.map +1 -0
  377. package/dist/expo/index.d.ts +16 -0
  378. package/dist/expo/index.d.ts.map +1 -0
  379. package/dist/expo/index.js +14 -0
  380. package/dist/expo/index.js.map +1 -0
  381. package/dist/expo/polyfills.d.ts +2 -0
  382. package/dist/expo/polyfills.d.ts.map +1 -0
  383. package/dist/expo/polyfills.js +5 -0
  384. package/dist/expo/polyfills.js.map +1 -0
  385. package/dist/expo/provider.d.ts +7 -0
  386. package/dist/expo/provider.d.ts.map +1 -0
  387. package/dist/expo/provider.js +10 -0
  388. package/dist/expo/provider.js.map +1 -0
  389. package/dist/expo/session.d.ts +10 -0
  390. package/dist/expo/session.d.ts.map +1 -0
  391. package/dist/expo/session.js +5 -0
  392. package/dist/expo/session.js.map +1 -0
  393. package/dist/expo/use-local-first-auth.d.ts +12 -0
  394. package/dist/expo/use-local-first-auth.d.ts.map +1 -0
  395. package/dist/expo/use-local-first-auth.js +13 -0
  396. package/dist/expo/use-local-first-auth.js.map +1 -0
  397. package/dist/index.d.ts +24 -7
  398. package/dist/index.d.ts.map +1 -1
  399. package/dist/index.js +19 -8
  400. package/dist/index.js.map +1 -1
  401. package/dist/internal/inspector-query.d.ts +6 -0
  402. package/dist/internal/inspector-query.d.ts.map +1 -0
  403. package/dist/internal/inspector-query.js +20 -0
  404. package/dist/internal/inspector-query.js.map +1 -0
  405. package/dist/ir.d.ts +139 -115
  406. package/dist/ir.d.ts.map +1 -1
  407. package/dist/ir.js +496 -1
  408. package/dist/ir.js.map +1 -1
  409. package/dist/local-first/index.d.ts +16 -0
  410. package/dist/local-first/index.d.ts.map +1 -0
  411. package/dist/local-first/index.js +15 -0
  412. package/dist/local-first/index.js.map +1 -0
  413. package/dist/local-first-auth/browser.d.ts +18 -0
  414. package/dist/local-first-auth/browser.d.ts.map +1 -0
  415. package/dist/local-first-auth/browser.js +26 -0
  416. package/dist/local-first-auth/browser.js.map +1 -0
  417. package/dist/local-first-auth/encoding.d.ts +10 -0
  418. package/dist/local-first-auth/encoding.d.ts.map +1 -0
  419. package/dist/local-first-auth/encoding.js +38 -0
  420. package/dist/local-first-auth/encoding.js.map +1 -0
  421. package/dist/local-first-auth/identity.d.ts +73 -0
  422. package/dist/local-first-auth/identity.d.ts.map +1 -0
  423. package/dist/local-first-auth/identity.js +258 -0
  424. package/dist/local-first-auth/identity.js.map +1 -0
  425. package/dist/local-first-auth/index.d.ts +6 -0
  426. package/dist/local-first-auth/index.d.ts.map +1 -0
  427. package/dist/local-first-auth/index.js +4 -0
  428. package/dist/local-first-auth/index.js.map +1 -0
  429. package/dist/local-first-auth/passkey.d.ts +22 -0
  430. package/dist/local-first-auth/passkey.d.ts.map +1 -0
  431. package/dist/local-first-auth/passkey.js +116 -0
  432. package/dist/local-first-auth/passkey.js.map +1 -0
  433. package/dist/local-first-auth/recovery-phrase.d.ts +10 -0
  434. package/dist/local-first-auth/recovery-phrase.d.ts.map +1 -0
  435. package/dist/local-first-auth/recovery-phrase.js +59 -0
  436. package/dist/local-first-auth/recovery-phrase.js.map +1 -0
  437. package/dist/local-first-auth/secret.d.ts +25 -0
  438. package/dist/local-first-auth/secret.d.ts.map +1 -0
  439. package/dist/local-first-auth/secret.js +68 -0
  440. package/dist/local-first-auth/secret.js.map +1 -0
  441. package/dist/local-first-auth/server.d.ts +13 -0
  442. package/dist/local-first-auth/server.d.ts.map +1 -0
  443. package/dist/local-first-auth/server.js +32 -0
  444. package/dist/local-first-auth/server.js.map +1 -0
  445. package/dist/local-first-auth/store.d.ts +51 -0
  446. package/dist/local-first-auth/store.d.ts.map +1 -0
  447. package/dist/local-first-auth/store.js +112 -0
  448. package/dist/local-first-auth/store.js.map +1 -0
  449. package/dist/magic-columns.d.ts +34 -0
  450. package/dist/magic-columns.d.ts.map +1 -0
  451. package/dist/magic-columns.js +86 -0
  452. package/dist/magic-columns.js.map +1 -0
  453. package/dist/migration-namespace.d.ts +8 -0
  454. package/dist/migration-namespace.d.ts.map +1 -0
  455. package/dist/migration-namespace.js +9 -0
  456. package/dist/migration-namespace.js.map +1 -0
  457. package/dist/migrations.d.ts +229 -0
  458. package/dist/migrations.d.ts.map +1 -0
  459. package/dist/migrations.js +383 -0
  460. package/dist/migrations.js.map +1 -0
  461. package/dist/observed-jazz-client.d.ts +15 -0
  462. package/dist/observed-jazz-client.d.ts.map +1 -0
  463. package/dist/observed-jazz-client.js +38 -0
  464. package/dist/observed-jazz-client.js.map +1 -0
  465. package/dist/passkey-backup.d.ts +3 -0
  466. package/dist/passkey-backup.d.ts.map +1 -0
  467. package/dist/passkey-backup.js +2 -0
  468. package/dist/passkey-backup.js.map +1 -0
  469. package/dist/passphrase.d.ts +2 -0
  470. package/dist/passphrase.d.ts.map +1 -0
  471. package/dist/passphrase.js +2 -0
  472. package/dist/passphrase.js.map +1 -0
  473. package/dist/permissions/index.d.ts +149 -41
  474. package/dist/permissions/index.d.ts.map +1 -1
  475. package/dist/permissions/index.js +1209 -423
  476. package/dist/permissions/index.js.map +1 -1
  477. package/dist/policy-expr-map.d.ts +15 -0
  478. package/dist/policy-expr-map.d.ts.map +1 -0
  479. package/dist/policy-expr-map.js +45 -0
  480. package/dist/policy-expr-map.js.map +1 -0
  481. package/dist/prosemirror/anchors.d.ts +30 -0
  482. package/dist/prosemirror/anchors.d.ts.map +1 -0
  483. package/dist/prosemirror/anchors.js +28 -0
  484. package/dist/prosemirror/anchors.js.map +1 -0
  485. package/dist/prosemirror/index.d.ts +7 -0
  486. package/dist/prosemirror/index.d.ts.map +1 -0
  487. package/dist/prosemirror/index.js +7 -0
  488. package/dist/prosemirror/index.js.map +1 -0
  489. package/dist/prosemirror/markdown.d.ts +95 -0
  490. package/dist/prosemirror/markdown.d.ts.map +1 -0
  491. package/dist/prosemirror/markdown.js +428 -0
  492. package/dist/prosemirror/markdown.js.map +1 -0
  493. package/dist/prosemirror/overlays.d.ts +69 -0
  494. package/dist/prosemirror/overlays.d.ts.map +1 -0
  495. package/dist/prosemirror/overlays.js +143 -0
  496. package/dist/prosemirror/overlays.js.map +1 -0
  497. package/dist/prosemirror/presence.d.ts +39 -0
  498. package/dist/prosemirror/presence.d.ts.map +1 -0
  499. package/dist/prosemirror/presence.js +88 -0
  500. package/dist/prosemirror/presence.js.map +1 -0
  501. package/dist/prosemirror/sync.d.ts +60 -0
  502. package/dist/prosemirror/sync.d.ts.map +1 -0
  503. package/dist/prosemirror/sync.js +174 -0
  504. package/dist/prosemirror/sync.js.map +1 -0
  505. package/dist/prosemirror/text-map.d.ts +21 -0
  506. package/dist/prosemirror/text-map.d.ts.map +1 -0
  507. package/dist/prosemirror/text-map.js +85 -0
  508. package/dist/prosemirror/text-map.js.map +1 -0
  509. package/dist/provenance-guidance.d.ts +3 -0
  510. package/dist/provenance-guidance.d.ts.map +1 -0
  511. package/dist/provenance-guidance.js +19 -0
  512. package/dist/provenance-guidance.js.map +1 -0
  513. package/dist/react/create-jazz-client.d.ts +2 -10
  514. package/dist/react/create-jazz-client.d.ts.map +1 -1
  515. package/dist/react/create-jazz-client.js +1 -25
  516. package/dist/react/create-jazz-client.js.map +1 -1
  517. package/dist/react/devtools-auto-attach.d.ts +2 -0
  518. package/dist/react/devtools-auto-attach.d.ts.map +1 -0
  519. package/dist/react/devtools-auto-attach.js +11 -0
  520. package/dist/react/devtools-auto-attach.js.map +1 -0
  521. package/dist/react/index.d.ts +20 -6
  522. package/dist/react/index.d.ts.map +1 -1
  523. package/dist/react/index.js +12 -5
  524. package/dist/react/index.js.map +1 -1
  525. package/dist/react/provider.d.ts +23 -11
  526. package/dist/react/provider.d.ts.map +1 -1
  527. package/dist/react/provider.js +43 -3
  528. package/dist/react/provider.js.map +1 -1
  529. package/dist/react/session.d.ts +18 -0
  530. package/dist/react/session.d.ts.map +1 -0
  531. package/dist/react/session.js +28 -0
  532. package/dist/react/session.js.map +1 -0
  533. package/dist/react/use-all.d.ts +1 -1
  534. package/dist/react/use-all.d.ts.map +1 -1
  535. package/dist/react/use-all.js +1 -1
  536. package/dist/react/use-all.js.map +1 -1
  537. package/dist/react/use-local-first-auth.d.ts +11 -0
  538. package/dist/react/use-local-first-auth.d.ts.map +1 -0
  539. package/dist/react/use-local-first-auth.js +13 -0
  540. package/dist/react/use-local-first-auth.js.map +1 -0
  541. package/dist/react/use-one.d.ts +2 -0
  542. package/dist/react/use-one.d.ts.map +1 -0
  543. package/dist/react/use-one.js +2 -0
  544. package/dist/react/use-one.js.map +1 -0
  545. package/dist/react-core/app.d.ts +31 -0
  546. package/dist/react-core/app.d.ts.map +1 -0
  547. package/dist/react-core/app.js +65 -0
  548. package/dist/react-core/app.js.map +1 -0
  549. package/dist/react-core/index.d.ts +11 -4
  550. package/dist/react-core/index.d.ts.map +1 -1
  551. package/dist/react-core/index.js +8 -2
  552. package/dist/react-core/index.js.map +1 -1
  553. package/dist/react-core/provider.d.ts +44 -12
  554. package/dist/react-core/provider.d.ts.map +1 -1
  555. package/dist/react-core/provider.js +110 -10
  556. package/dist/react-core/provider.js.map +1 -1
  557. package/dist/react-core/session.d.ts +45 -0
  558. package/dist/react-core/session.d.ts.map +1 -0
  559. package/dist/react-core/session.js +130 -0
  560. package/dist/react-core/session.js.map +1 -0
  561. package/dist/react-core/use-account-state.d.ts +4 -0
  562. package/dist/react-core/use-account-state.d.ts.map +1 -0
  563. package/dist/react-core/use-account-state.js +6 -0
  564. package/dist/react-core/use-account-state.js.map +1 -0
  565. package/dist/react-core/use-all.d.ts +95 -3
  566. package/dist/react-core/use-all.d.ts.map +1 -1
  567. package/dist/react-core/use-all.js +126 -52
  568. package/dist/react-core/use-all.js.map +1 -1
  569. package/dist/react-core/use-auth-state.d.ts +13 -0
  570. package/dist/react-core/use-auth-state.d.ts.map +1 -0
  571. package/dist/react-core/use-auth-state.js +15 -0
  572. package/dist/react-core/use-auth-state.js.map +1 -0
  573. package/dist/react-core/use-local-first-auth.d.ts +12 -0
  574. package/dist/react-core/use-local-first-auth.d.ts.map +1 -0
  575. package/dist/react-core/use-local-first-auth.js +14 -0
  576. package/dist/react-core/use-local-first-auth.js.map +1 -0
  577. package/dist/react-core/use-one.d.ts +58 -0
  578. package/dist/react-core/use-one.d.ts.map +1 -0
  579. package/dist/react-core/use-one.js +19 -0
  580. package/dist/react-core/use-one.js.map +1 -0
  581. package/dist/react-core/use-sync-status.d.ts +8 -0
  582. package/dist/react-core/use-sync-status.d.ts.map +1 -0
  583. package/dist/react-core/use-sync-status.js +12 -0
  584. package/dist/react-core/use-sync-status.js.map +1 -0
  585. package/dist/react-native/abort-signal.d.ts +9 -0
  586. package/dist/react-native/abort-signal.d.ts.map +1 -0
  587. package/dist/react-native/abort-signal.js +51 -0
  588. package/dist/react-native/abort-signal.js.map +1 -0
  589. package/dist/react-native/account-session.d.ts +11 -0
  590. package/dist/react-native/account-session.d.ts.map +1 -0
  591. package/dist/react-native/account-session.js +59 -0
  592. package/dist/react-native/account-session.js.map +1 -0
  593. package/dist/react-native/create-account-manager.d.ts +28 -0
  594. package/dist/react-native/create-account-manager.d.ts.map +1 -0
  595. package/dist/react-native/create-account-manager.js +30 -0
  596. package/dist/react-native/create-account-manager.js.map +1 -0
  597. package/dist/react-native/create-db.d.ts +8 -0
  598. package/dist/react-native/create-db.d.ts.map +1 -0
  599. package/dist/react-native/create-db.js +9 -0
  600. package/dist/react-native/create-db.js.map +1 -0
  601. package/dist/react-native/create-jazz-client.d.ts +12 -10
  602. package/dist/react-native/create-jazz-client.d.ts.map +1 -1
  603. package/dist/react-native/create-jazz-client.js +6 -21
  604. package/dist/react-native/create-jazz-client.js.map +1 -1
  605. package/dist/react-native/create-jazz-session.d.ts +35 -0
  606. package/dist/react-native/create-jazz-session.d.ts.map +1 -0
  607. package/dist/react-native/create-jazz-session.js +39 -0
  608. package/dist/react-native/create-jazz-session.js.map +1 -0
  609. package/dist/react-native/errors.d.ts +6 -0
  610. package/dist/react-native/errors.d.ts.map +1 -0
  611. package/dist/react-native/errors.js +6 -0
  612. package/dist/react-native/errors.js.map +1 -0
  613. package/dist/react-native/index.d.ts +25 -9
  614. package/dist/react-native/index.d.ts.map +1 -1
  615. package/dist/react-native/index.js +17 -7
  616. package/dist/react-native/index.js.map +1 -1
  617. package/dist/react-native/native-foreground-db.d.ts +192 -0
  618. package/dist/react-native/native-foreground-db.d.ts.map +1 -0
  619. package/dist/react-native/native-foreground-db.js +801 -0
  620. package/dist/react-native/native-foreground-db.js.map +1 -0
  621. package/dist/react-native/native-relay.d.ts +7 -0
  622. package/dist/react-native/native-relay.d.ts.map +1 -0
  623. package/dist/react-native/native-relay.js +14 -0
  624. package/dist/react-native/native-relay.js.map +1 -0
  625. package/dist/react-native/provider.d.ts +23 -10
  626. package/dist/react-native/provider.d.ts.map +1 -1
  627. package/dist/react-native/provider.js +23 -3
  628. package/dist/react-native/provider.js.map +1 -1
  629. package/dist/react-native/runtime-source.d.ts +40 -0
  630. package/dist/react-native/runtime-source.d.ts.map +1 -0
  631. package/dist/react-native/runtime-source.js +250 -0
  632. package/dist/react-native/runtime-source.js.map +1 -0
  633. package/dist/react-native/session.d.ts +10 -0
  634. package/dist/react-native/session.d.ts.map +1 -0
  635. package/dist/react-native/session.js +5 -0
  636. package/dist/react-native/session.js.map +1 -0
  637. package/dist/react-native/use-all.d.ts +1 -1
  638. package/dist/react-native/use-all.d.ts.map +1 -1
  639. package/dist/react-native/use-all.js +1 -1
  640. package/dist/react-native/use-all.js.map +1 -1
  641. package/dist/react-native/use-local-first-auth.d.ts +15 -0
  642. package/dist/react-native/use-local-first-auth.d.ts.map +1 -0
  643. package/dist/react-native/use-local-first-auth.js +14 -0
  644. package/dist/react-native/use-local-first-auth.js.map +1 -0
  645. package/dist/react-native/use-one.d.ts +2 -0
  646. package/dist/react-native/use-one.d.ts.map +1 -0
  647. package/dist/react-native/use-one.js +2 -0
  648. package/dist/react-native/use-one.js.map +1 -0
  649. package/dist/reconcile-array.d.ts +45 -0
  650. package/dist/reconcile-array.d.ts.map +1 -0
  651. package/dist/reconcile-array.js +252 -0
  652. package/dist/reconcile-array.js.map +1 -0
  653. package/dist/relationships.d.ts +18 -0
  654. package/dist/relationships.d.ts.map +1 -0
  655. package/dist/relationships.js +28 -0
  656. package/dist/relationships.js.map +1 -0
  657. package/dist/runtime/anonymous-write-denied-error.d.ts +13 -0
  658. package/dist/runtime/anonymous-write-denied-error.d.ts.map +1 -0
  659. package/dist/runtime/anonymous-write-denied-error.js +58 -0
  660. package/dist/runtime/anonymous-write-denied-error.js.map +1 -0
  661. package/dist/runtime/auth-renewal-backoff.d.ts +14 -0
  662. package/dist/runtime/auth-renewal-backoff.d.ts.map +1 -0
  663. package/dist/runtime/auth-renewal-backoff.js +23 -0
  664. package/dist/runtime/auth-renewal-backoff.js.map +1 -0
  665. package/dist/runtime/auth-request-deadline.d.ts +3 -0
  666. package/dist/runtime/auth-request-deadline.d.ts.map +1 -0
  667. package/dist/runtime/auth-request-deadline.js +24 -0
  668. package/dist/runtime/auth-request-deadline.js.map +1 -0
  669. package/dist/runtime/auth-secret-codec.d.ts +21 -0
  670. package/dist/runtime/auth-secret-codec.d.ts.map +1 -0
  671. package/dist/runtime/auth-secret-codec.js +32 -0
  672. package/dist/runtime/auth-secret-codec.js.map +1 -0
  673. package/dist/runtime/auth-secret-store.d.ts +51 -0
  674. package/dist/runtime/auth-secret-store.d.ts.map +1 -0
  675. package/dist/runtime/auth-secret-store.js +114 -0
  676. package/dist/runtime/auth-secret-store.js.map +1 -0
  677. package/dist/runtime/auth-state.d.ts +40 -0
  678. package/dist/runtime/auth-state.d.ts.map +1 -0
  679. package/dist/runtime/auth-state.js +145 -0
  680. package/dist/runtime/auth-state.js.map +1 -0
  681. package/dist/runtime/author-id.d.ts +42 -0
  682. package/dist/runtime/author-id.d.ts.map +1 -0
  683. package/dist/runtime/author-id.js +172 -0
  684. package/dist/runtime/author-id.js.map +1 -0
  685. package/dist/runtime/authority-changed-error.d.ts +54 -0
  686. package/dist/runtime/authority-changed-error.d.ts.map +1 -0
  687. package/dist/runtime/authority-changed-error.js +72 -0
  688. package/dist/runtime/authority-changed-error.js.map +1 -0
  689. package/dist/runtime/browser-physical-database-epoch.d.ts +37 -0
  690. package/dist/runtime/browser-physical-database-epoch.d.ts.map +1 -0
  691. package/dist/runtime/browser-physical-database-epoch.js +89 -0
  692. package/dist/runtime/browser-physical-database-epoch.js.map +1 -0
  693. package/dist/runtime/browser-storage-invalidation.d.ts +8 -0
  694. package/dist/runtime/browser-storage-invalidation.d.ts.map +1 -0
  695. package/dist/runtime/browser-storage-invalidation.js +20 -0
  696. package/dist/runtime/browser-storage-invalidation.js.map +1 -0
  697. package/dist/runtime/browser-worker-assets.d.ts +4 -0
  698. package/dist/runtime/browser-worker-assets.d.ts.map +1 -0
  699. package/dist/runtime/browser-worker-assets.js +8 -0
  700. package/dist/runtime/browser-worker-assets.js.map +1 -0
  701. package/dist/runtime/browser-worker-assets.native.d.ts +5 -0
  702. package/dist/runtime/browser-worker-assets.native.d.ts.map +1 -0
  703. package/dist/runtime/browser-worker-assets.native.js +6 -0
  704. package/dist/runtime/browser-worker-assets.native.js.map +1 -0
  705. package/dist/runtime/browser-worker-config.d.ts +55 -0
  706. package/dist/runtime/browser-worker-config.d.ts.map +1 -0
  707. package/dist/runtime/browser-worker-config.js +222 -0
  708. package/dist/runtime/browser-worker-config.js.map +1 -0
  709. package/dist/runtime/client-config-key.d.ts +6 -0
  710. package/dist/runtime/client-config-key.d.ts.map +1 -0
  711. package/dist/runtime/client-config-key.js +83 -0
  712. package/dist/runtime/client-config-key.js.map +1 -0
  713. package/dist/runtime/client-migrations.d.ts +33 -0
  714. package/dist/runtime/client-migrations.d.ts.map +1 -0
  715. package/dist/runtime/client-migrations.js +30 -0
  716. package/dist/runtime/client-migrations.js.map +1 -0
  717. package/dist/runtime/client-registry.d.ts +21 -0
  718. package/dist/runtime/client-registry.d.ts.map +1 -0
  719. package/dist/runtime/client-registry.js +169 -0
  720. package/dist/runtime/client-registry.js.map +1 -0
  721. package/dist/runtime/client-scope.d.ts +38 -0
  722. package/dist/runtime/client-scope.d.ts.map +1 -0
  723. package/dist/runtime/client-scope.js +64 -0
  724. package/dist/runtime/client-scope.js.map +1 -0
  725. package/dist/runtime/client-session.d.ts +56 -13
  726. package/dist/runtime/client-session.d.ts.map +1 -1
  727. package/dist/runtime/client-session.js +212 -196
  728. package/dist/runtime/client-session.js.map +1 -1
  729. package/dist/runtime/client.d.ts +624 -191
  730. package/dist/runtime/client.d.ts.map +1 -1
  731. package/dist/runtime/client.js +1105 -425
  732. package/dist/runtime/client.js.map +1 -1
  733. package/dist/runtime/column-transforms.d.ts +40 -0
  734. package/dist/runtime/column-transforms.d.ts.map +1 -0
  735. package/dist/runtime/column-transforms.js +279 -0
  736. package/dist/runtime/column-transforms.js.map +1 -0
  737. package/dist/runtime/connection-manager/browser-connection-manager.d.ts +119 -0
  738. package/dist/runtime/connection-manager/browser-connection-manager.d.ts.map +1 -0
  739. package/dist/runtime/connection-manager/browser-connection-manager.js +836 -0
  740. package/dist/runtime/connection-manager/browser-connection-manager.js.map +1 -0
  741. package/dist/runtime/connection-manager/direct-connection-manager.d.ts +26 -0
  742. package/dist/runtime/connection-manager/direct-connection-manager.d.ts.map +1 -0
  743. package/dist/runtime/connection-manager/direct-connection-manager.js +198 -0
  744. package/dist/runtime/connection-manager/direct-connection-manager.js.map +1 -0
  745. package/dist/runtime/connection-manager/index.d.ts +5 -0
  746. package/dist/runtime/connection-manager/index.d.ts.map +1 -0
  747. package/dist/runtime/connection-manager/index.js +4 -0
  748. package/dist/runtime/connection-manager/index.js.map +1 -0
  749. package/dist/runtime/connection-manager/types.d.ts +136 -0
  750. package/dist/runtime/connection-manager/types.d.ts.map +1 -0
  751. package/dist/runtime/connection-manager/types.js +340 -0
  752. package/dist/runtime/connection-manager/types.js.map +1 -0
  753. package/dist/runtime/context.d.ts +90 -30
  754. package/dist/runtime/context.d.ts.map +1 -1
  755. package/dist/runtime/context.js.map +1 -1
  756. package/dist/runtime/credentialed-transport.d.ts +27 -0
  757. package/dist/runtime/credentialed-transport.d.ts.map +1 -0
  758. package/dist/runtime/credentialed-transport.js +155 -0
  759. package/dist/runtime/credentialed-transport.js.map +1 -0
  760. package/dist/runtime/db-access-context.d.ts +14 -0
  761. package/dist/runtime/db-access-context.d.ts.map +1 -0
  762. package/dist/runtime/db-access-context.js +26 -0
  763. package/dist/runtime/db-access-context.js.map +1 -0
  764. package/dist/runtime/db-internal-session.d.ts +7 -0
  765. package/dist/runtime/db-internal-session.d.ts.map +1 -0
  766. package/dist/runtime/db-internal-session.js +21 -0
  767. package/dist/runtime/db-internal-session.js.map +1 -0
  768. package/dist/runtime/db-replaced-error.d.ts +19 -0
  769. package/dist/runtime/db-replaced-error.d.ts.map +1 -0
  770. package/dist/runtime/db-replaced-error.js +20 -0
  771. package/dist/runtime/db-replaced-error.js.map +1 -0
  772. package/dist/runtime/db.d.ts +735 -201
  773. package/dist/runtime/db.d.ts.map +1 -1
  774. package/dist/runtime/db.js +3287 -727
  775. package/dist/runtime/db.js.map +1 -1
  776. package/dist/runtime/default-create-db.d.ts +5 -0
  777. package/dist/runtime/default-create-db.d.ts.map +1 -0
  778. package/dist/runtime/default-create-db.js +7 -0
  779. package/dist/runtime/default-create-db.js.map +1 -0
  780. package/dist/runtime/default-runtime-source.d.ts +41 -0
  781. package/dist/runtime/default-runtime-source.d.ts.map +1 -0
  782. package/dist/runtime/default-runtime-source.js +315 -0
  783. package/dist/runtime/default-runtime-source.js.map +1 -0
  784. package/dist/runtime/deterministic-bytes.d.ts +6 -0
  785. package/dist/runtime/deterministic-bytes.d.ts.map +1 -0
  786. package/dist/runtime/deterministic-bytes.js +18 -0
  787. package/dist/runtime/deterministic-bytes.js.map +1 -0
  788. package/dist/runtime/graceful-shutdown-error.d.ts +9 -0
  789. package/dist/runtime/graceful-shutdown-error.d.ts.map +1 -0
  790. package/dist/runtime/graceful-shutdown-error.js +17 -0
  791. package/dist/runtime/graceful-shutdown-error.js.map +1 -0
  792. package/dist/runtime/hex.d.ts +17 -0
  793. package/dist/runtime/hex.d.ts.map +1 -0
  794. package/dist/runtime/hex.js +56 -0
  795. package/dist/runtime/hex.js.map +1 -0
  796. package/dist/runtime/history-relation.d.ts +8 -0
  797. package/dist/runtime/history-relation.d.ts.map +1 -0
  798. package/dist/runtime/history-relation.js +44 -0
  799. package/dist/runtime/history-relation.js.map +1 -0
  800. package/dist/runtime/in-process-transport.d.ts +18 -0
  801. package/dist/runtime/in-process-transport.d.ts.map +1 -0
  802. package/dist/runtime/in-process-transport.js +32 -0
  803. package/dist/runtime/in-process-transport.js.map +1 -0
  804. package/dist/runtime/index.d.ts +22 -11
  805. package/dist/runtime/index.d.ts.map +1 -1
  806. package/dist/runtime/index.js +14 -10
  807. package/dist/runtime/index.js.map +1 -1
  808. package/dist/runtime/indexeddb-page-store.d.ts +214 -0
  809. package/dist/runtime/indexeddb-page-store.d.ts.map +1 -0
  810. package/dist/runtime/indexeddb-page-store.js +848 -0
  811. package/dist/runtime/indexeddb-page-store.js.map +1 -0
  812. package/dist/runtime/introspection-fetch.d.ts +18 -0
  813. package/dist/runtime/introspection-fetch.d.ts.map +1 -0
  814. package/dist/runtime/introspection-fetch.js +12 -0
  815. package/dist/runtime/introspection-fetch.js.map +1 -0
  816. package/dist/runtime/json-schema-evaluate.d.ts +55 -0
  817. package/dist/runtime/json-schema-evaluate.d.ts.map +1 -0
  818. package/dist/runtime/json-schema-evaluate.js +946 -0
  819. package/dist/runtime/json-schema-evaluate.js.map +1 -0
  820. package/dist/runtime/json-schema-formats.d.ts +14 -0
  821. package/dist/runtime/json-schema-formats.d.ts.map +1 -0
  822. package/dist/runtime/json-schema-formats.js +555 -0
  823. package/dist/runtime/json-schema-formats.js.map +1 -0
  824. package/dist/runtime/json-schema-json.d.ts +41 -0
  825. package/dist/runtime/json-schema-json.d.ts.map +1 -0
  826. package/dist/runtime/json-schema-json.js +309 -0
  827. package/dist/runtime/json-schema-json.js.map +1 -0
  828. package/dist/runtime/json-schema-metaschemas.d.ts +1403 -0
  829. package/dist/runtime/json-schema-metaschemas.d.ts.map +1 -0
  830. package/dist/runtime/json-schema-metaschemas.js +64 -0
  831. package/dist/runtime/json-schema-metaschemas.js.map +1 -0
  832. package/dist/runtime/json-schema-regex.d.ts +32 -0
  833. package/dist/runtime/json-schema-regex.d.ts.map +1 -0
  834. package/dist/runtime/json-schema-regex.js +895 -0
  835. package/dist/runtime/json-schema-regex.js.map +1 -0
  836. package/dist/runtime/json-schema-validator.d.ts +47 -0
  837. package/dist/runtime/json-schema-validator.d.ts.map +1 -0
  838. package/dist/runtime/json-schema-validator.js +404 -0
  839. package/dist/runtime/json-schema-validator.js.map +1 -0
  840. package/dist/runtime/json-text.d.ts +2 -0
  841. package/dist/runtime/json-text.d.ts.map +1 -0
  842. package/dist/runtime/json-text.js +17 -0
  843. package/dist/runtime/json-text.js.map +1 -0
  844. package/dist/runtime/local-first-auth-controller.d.ts +29 -0
  845. package/dist/runtime/local-first-auth-controller.d.ts.map +1 -0
  846. package/dist/runtime/local-first-auth-controller.js +101 -0
  847. package/dist/runtime/local-first-auth-controller.js.map +1 -0
  848. package/dist/runtime/local-first-token.d.ts +11 -0
  849. package/dist/runtime/local-first-token.d.ts.map +1 -0
  850. package/dist/runtime/local-first-token.js +20 -0
  851. package/dist/runtime/local-first-token.js.map +1 -0
  852. package/dist/runtime/local-first-upgrade.d.ts +27 -0
  853. package/dist/runtime/local-first-upgrade.d.ts.map +1 -0
  854. package/dist/runtime/local-first-upgrade.js +31 -0
  855. package/dist/runtime/local-first-upgrade.js.map +1 -0
  856. package/dist/runtime/local-write-observer.d.ts +5 -0
  857. package/dist/runtime/local-write-observer.d.ts.map +1 -0
  858. package/dist/runtime/local-write-observer.js +31 -0
  859. package/dist/runtime/local-write-observer.js.map +1 -0
  860. package/dist/runtime/native-artifact-compatibility.d.ts +12 -0
  861. package/dist/runtime/native-artifact-compatibility.d.ts.map +1 -0
  862. package/dist/runtime/native-artifact-compatibility.js +24 -0
  863. package/dist/runtime/native-artifact-compatibility.js.map +1 -0
  864. package/dist/runtime/native-artifact-fingerprint-napi.d.ts +2 -0
  865. package/dist/runtime/native-artifact-fingerprint-napi.d.ts.map +1 -0
  866. package/dist/runtime/native-artifact-fingerprint-napi.js +3 -0
  867. package/dist/runtime/native-artifact-fingerprint-napi.js.map +1 -0
  868. package/dist/runtime/native-artifact-fingerprint-wasm.d.ts +2 -0
  869. package/dist/runtime/native-artifact-fingerprint-wasm.d.ts.map +1 -0
  870. package/dist/runtime/native-artifact-fingerprint-wasm.js +3 -0
  871. package/dist/runtime/native-artifact-fingerprint-wasm.js.map +1 -0
  872. package/dist/runtime/native-artifact-fingerprints.d.ts +5 -0
  873. package/dist/runtime/native-artifact-fingerprints.d.ts.map +1 -0
  874. package/dist/runtime/native-artifact-fingerprints.js +7 -0
  875. package/dist/runtime/native-artifact-fingerprints.js.map +1 -0
  876. package/dist/runtime/native-runtime/attached-browser-worker-connection.d.ts +20 -0
  877. package/dist/runtime/native-runtime/attached-browser-worker-connection.d.ts.map +1 -0
  878. package/dist/runtime/native-runtime/attached-browser-worker-connection.js +42 -0
  879. package/dist/runtime/native-runtime/attached-browser-worker-connection.js.map +1 -0
  880. package/dist/runtime/native-runtime/auxiliary-receive-deadline.d.ts +15 -0
  881. package/dist/runtime/native-runtime/auxiliary-receive-deadline.d.ts.map +1 -0
  882. package/dist/runtime/native-runtime/auxiliary-receive-deadline.js +64 -0
  883. package/dist/runtime/native-runtime/auxiliary-receive-deadline.js.map +1 -0
  884. package/dist/runtime/native-runtime/browser-follower-connection.d.ts +78 -0
  885. package/dist/runtime/native-runtime/browser-follower-connection.d.ts.map +1 -0
  886. package/dist/runtime/native-runtime/browser-follower-connection.js +494 -0
  887. package/dist/runtime/native-runtime/browser-follower-connection.js.map +1 -0
  888. package/dist/runtime/native-runtime/browser-shared-worker-connection.d.ts +96 -0
  889. package/dist/runtime/native-runtime/browser-shared-worker-connection.d.ts.map +1 -0
  890. package/dist/runtime/native-runtime/browser-shared-worker-connection.js +780 -0
  891. package/dist/runtime/native-runtime/browser-shared-worker-connection.js.map +1 -0
  892. package/dist/runtime/native-runtime/browser-worker-protocol.d.ts +455 -0
  893. package/dist/runtime/native-runtime/browser-worker-protocol.d.ts.map +1 -0
  894. package/dist/runtime/native-runtime/browser-worker-protocol.js +281 -0
  895. package/dist/runtime/native-runtime/browser-worker-protocol.js.map +1 -0
  896. package/dist/runtime/native-runtime/browser-worker-transport.d.ts +53 -0
  897. package/dist/runtime/native-runtime/browser-worker-transport.d.ts.map +1 -0
  898. package/dist/runtime/native-runtime/browser-worker-transport.js +252 -0
  899. package/dist/runtime/native-runtime/browser-worker-transport.js.map +1 -0
  900. package/dist/runtime/native-runtime/exact-integer.d.ts +7 -0
  901. package/dist/runtime/native-runtime/exact-integer.d.ts.map +1 -0
  902. package/dist/runtime/native-runtime/exact-integer.js +18 -0
  903. package/dist/runtime/native-runtime/exact-integer.js.map +1 -0
  904. package/dist/runtime/native-runtime/http-stream-socket.d.ts +85 -0
  905. package/dist/runtime/native-runtime/http-stream-socket.d.ts.map +1 -0
  906. package/dist/runtime/native-runtime/http-stream-socket.js +433 -0
  907. package/dist/runtime/native-runtime/http-stream-socket.js.map +1 -0
  908. package/dist/runtime/native-runtime/inspector-control-lifecycle.d.ts +4 -0
  909. package/dist/runtime/native-runtime/inspector-control-lifecycle.d.ts.map +1 -0
  910. package/dist/runtime/native-runtime/inspector-control-lifecycle.js +33 -0
  911. package/dist/runtime/native-runtime/inspector-control-lifecycle.js.map +1 -0
  912. package/dist/runtime/native-runtime/native-codec.d.ts +177 -0
  913. package/dist/runtime/native-runtime/native-codec.d.ts.map +1 -0
  914. package/dist/runtime/native-runtime/native-codec.js +627 -0
  915. package/dist/runtime/native-runtime/native-codec.js.map +1 -0
  916. package/dist/runtime/native-runtime/native-error-code.d.ts +39 -0
  917. package/dist/runtime/native-runtime/native-error-code.d.ts.map +1 -0
  918. package/dist/runtime/native-runtime/native-error-code.js +62 -0
  919. package/dist/runtime/native-runtime/native-error-code.js.map +1 -0
  920. package/dist/runtime/native-runtime/native-row-codec.d.ts +161 -0
  921. package/dist/runtime/native-runtime/native-row-codec.d.ts.map +1 -0
  922. package/dist/runtime/native-runtime/native-row-codec.js +942 -0
  923. package/dist/runtime/native-runtime/native-row-codec.js.map +1 -0
  924. package/dist/runtime/native-runtime/native-row-descriptor-key.d.ts +15 -0
  925. package/dist/runtime/native-runtime/native-row-descriptor-key.d.ts.map +1 -0
  926. package/dist/runtime/native-runtime/native-row-descriptor-key.js +25 -0
  927. package/dist/runtime/native-runtime/native-row-descriptor-key.js.map +1 -0
  928. package/dist/runtime/native-runtime/native-runtime-adapter.d.ts +728 -0
  929. package/dist/runtime/native-runtime/native-runtime-adapter.d.ts.map +1 -0
  930. package/dist/runtime/native-runtime/native-runtime-adapter.js +5705 -0
  931. package/dist/runtime/native-runtime/native-runtime-adapter.js.map +1 -0
  932. package/dist/runtime/native-runtime/node-foreground-node-lease.browser.d.ts +17 -0
  933. package/dist/runtime/native-runtime/node-foreground-node-lease.browser.d.ts.map +1 -0
  934. package/dist/runtime/native-runtime/node-foreground-node-lease.browser.js +4 -0
  935. package/dist/runtime/native-runtime/node-foreground-node-lease.browser.js.map +1 -0
  936. package/dist/runtime/native-runtime/node-foreground-node-lease.d.ts +19 -0
  937. package/dist/runtime/native-runtime/node-foreground-node-lease.d.ts.map +1 -0
  938. package/dist/runtime/native-runtime/node-foreground-node-lease.js +297 -0
  939. package/dist/runtime/native-runtime/node-foreground-node-lease.js.map +1 -0
  940. package/dist/runtime/native-runtime/row-values-transport.d.ts +2 -0
  941. package/dist/runtime/native-runtime/row-values-transport.d.ts.map +1 -0
  942. package/dist/runtime/native-runtime/row-values-transport.js +21 -0
  943. package/dist/runtime/native-runtime/row-values-transport.js.map +1 -0
  944. package/dist/runtime/native-runtime/schema-codec.d.ts +10 -0
  945. package/dist/runtime/native-runtime/schema-codec.d.ts.map +1 -0
  946. package/dist/runtime/native-runtime/schema-codec.js +13 -0
  947. package/dist/runtime/native-runtime/schema-codec.js.map +1 -0
  948. package/dist/runtime/native-runtime/websocket.d.ts +165 -0
  949. package/dist/runtime/native-runtime/websocket.d.ts.map +1 -0
  950. package/dist/runtime/native-runtime/websocket.js +713 -0
  951. package/dist/runtime/native-runtime/websocket.js.map +1 -0
  952. package/dist/runtime/passkey-backup.d.ts +3 -0
  953. package/dist/runtime/passkey-backup.d.ts.map +1 -0
  954. package/dist/runtime/passkey-backup.js +2 -0
  955. package/dist/runtime/passkey-backup.js.map +1 -0
  956. package/dist/runtime/platform-url.d.ts +10 -0
  957. package/dist/runtime/platform-url.d.ts.map +1 -0
  958. package/dist/runtime/platform-url.js +3 -0
  959. package/dist/runtime/platform-url.js.map +1 -0
  960. package/dist/runtime/platform-url.native.d.ts +6 -0
  961. package/dist/runtime/platform-url.native.d.ts.map +1 -0
  962. package/dist/runtime/platform-url.native.js +37 -0
  963. package/dist/runtime/platform-url.native.js.map +1 -0
  964. package/dist/runtime/query-adapter.d.ts +7 -15
  965. package/dist/runtime/query-adapter.d.ts.map +1 -1
  966. package/dist/runtime/query-adapter.js +554 -167
  967. package/dist/runtime/query-adapter.js.map +1 -1
  968. package/dist/runtime/query-builder-shape.d.ts +75 -0
  969. package/dist/runtime/query-builder-shape.d.ts.map +1 -0
  970. package/dist/runtime/query-builder-shape.js +225 -0
  971. package/dist/runtime/query-builder-shape.js.map +1 -0
  972. package/dist/runtime/query-column-name.d.ts +3 -0
  973. package/dist/runtime/query-column-name.d.ts.map +1 -0
  974. package/dist/runtime/query-column-name.js +10 -0
  975. package/dist/runtime/query-column-name.js.map +1 -0
  976. package/dist/runtime/query-output-table.d.ts +5 -0
  977. package/dist/runtime/query-output-table.d.ts.map +1 -0
  978. package/dist/runtime/query-output-table.js +30 -0
  979. package/dist/runtime/query-output-table.js.map +1 -0
  980. package/dist/runtime/recovery-phrase.d.ts +3 -0
  981. package/dist/runtime/recovery-phrase.d.ts.map +1 -0
  982. package/dist/runtime/recovery-phrase.js +2 -0
  983. package/dist/runtime/recovery-phrase.js.map +1 -0
  984. package/dist/runtime/remote-link-state.d.ts +20 -0
  985. package/dist/runtime/remote-link-state.d.ts.map +1 -0
  986. package/dist/runtime/remote-link-state.js +5 -0
  987. package/dist/runtime/remote-link-state.js.map +1 -0
  988. package/dist/runtime/row-transformer.d.ts +18 -6
  989. package/dist/runtime/row-transformer.d.ts.map +1 -1
  990. package/dist/runtime/row-transformer.js +195 -41
  991. package/dist/runtime/row-transformer.js.map +1 -1
  992. package/dist/runtime/run-cleanup-steps.d.ts +5 -0
  993. package/dist/runtime/run-cleanup-steps.d.ts.map +1 -0
  994. package/dist/runtime/run-cleanup-steps.js +19 -0
  995. package/dist/runtime/run-cleanup-steps.js.map +1 -0
  996. package/dist/runtime/runtime-closed-error.d.ts +9 -0
  997. package/dist/runtime/runtime-closed-error.d.ts.map +1 -0
  998. package/dist/runtime/runtime-closed-error.js +12 -0
  999. package/dist/runtime/runtime-closed-error.js.map +1 -0
  1000. package/dist/runtime/runtime-config.d.ts +9 -0
  1001. package/dist/runtime/runtime-config.d.ts.map +1 -0
  1002. package/dist/runtime/runtime-config.js +111 -0
  1003. package/dist/runtime/runtime-config.js.map +1 -0
  1004. package/dist/runtime/runtime-entropy.d.ts +14 -0
  1005. package/dist/runtime/runtime-entropy.d.ts.map +1 -0
  1006. package/dist/runtime/runtime-entropy.js +43 -0
  1007. package/dist/runtime/runtime-entropy.js.map +1 -0
  1008. package/dist/runtime/runtime-source.d.ts +167 -0
  1009. package/dist/runtime/runtime-source.d.ts.map +1 -0
  1010. package/dist/runtime/runtime-source.js +64 -0
  1011. package/dist/runtime/runtime-source.js.map +1 -0
  1012. package/dist/runtime/schema-metadata.d.ts +5 -0
  1013. package/dist/runtime/schema-metadata.d.ts.map +1 -0
  1014. package/dist/runtime/schema-metadata.js +34 -0
  1015. package/dist/runtime/schema-metadata.js.map +1 -0
  1016. package/dist/runtime/select-projection.d.ts +5 -0
  1017. package/dist/runtime/select-projection.d.ts.map +1 -0
  1018. package/dist/runtime/select-projection.js +47 -0
  1019. package/dist/runtime/select-projection.js.map +1 -0
  1020. package/dist/runtime/snapshot-ref.d.ts +24 -0
  1021. package/dist/runtime/snapshot-ref.d.ts.map +1 -0
  1022. package/dist/runtime/snapshot-ref.js +43 -0
  1023. package/dist/runtime/snapshot-ref.js.map +1 -0
  1024. package/dist/runtime/store-held-by-another-tab-error.d.ts +36 -0
  1025. package/dist/runtime/store-held-by-another-tab-error.d.ts.map +1 -0
  1026. package/dist/runtime/store-held-by-another-tab-error.js +38 -0
  1027. package/dist/runtime/store-held-by-another-tab-error.js.map +1 -0
  1028. package/dist/runtime/streaming-source.d.ts +4 -0
  1029. package/dist/runtime/streaming-source.d.ts.map +1 -0
  1030. package/dist/runtime/streaming-source.js +53 -0
  1031. package/dist/runtime/streaming-source.js.map +1 -0
  1032. package/dist/runtime/structural-values.d.ts +6 -0
  1033. package/dist/runtime/structural-values.d.ts.map +1 -0
  1034. package/dist/runtime/structural-values.js +55 -0
  1035. package/dist/runtime/structural-values.js.map +1 -0
  1036. package/dist/runtime/subscription-manager.d.ts +98 -14
  1037. package/dist/runtime/subscription-manager.d.ts.map +1 -1
  1038. package/dist/runtime/subscription-manager.js +1049 -25
  1039. package/dist/runtime/subscription-manager.js.map +1 -1
  1040. package/dist/runtime/sync-status.d.ts +98 -0
  1041. package/dist/runtime/sync-status.d.ts.map +1 -0
  1042. package/dist/runtime/sync-status.js +93 -0
  1043. package/dist/runtime/sync-status.js.map +1 -0
  1044. package/dist/runtime/sync-telemetry.d.ts +35 -0
  1045. package/dist/runtime/sync-telemetry.d.ts.map +1 -0
  1046. package/dist/runtime/sync-telemetry.js +354 -0
  1047. package/dist/runtime/sync-telemetry.js.map +1 -0
  1048. package/dist/runtime/system-identity.d.ts +5 -0
  1049. package/dist/runtime/system-identity.d.ts.map +1 -0
  1050. package/dist/runtime/system-identity.js +10 -0
  1051. package/dist/runtime/system-identity.js.map +1 -0
  1052. package/dist/runtime/telemetry-env.d.ts +2 -0
  1053. package/dist/runtime/telemetry-env.d.ts.map +1 -0
  1054. package/dist/runtime/telemetry-env.js +16 -0
  1055. package/dist/runtime/telemetry-env.js.map +1 -0
  1056. package/dist/runtime/telemetry-env.native.d.ts +3 -0
  1057. package/dist/runtime/telemetry-env.native.d.ts.map +1 -0
  1058. package/dist/runtime/telemetry-env.native.js +7 -0
  1059. package/dist/runtime/telemetry-env.native.js.map +1 -0
  1060. package/dist/runtime/text-anchors.d.ts +58 -0
  1061. package/dist/runtime/text-anchors.d.ts.map +1 -0
  1062. package/dist/runtime/text-anchors.js +9 -0
  1063. package/dist/runtime/text-anchors.js.map +1 -0
  1064. package/dist/runtime/unsupported-storage-codecs-error.d.ts +53 -0
  1065. package/dist/runtime/unsupported-storage-codecs-error.d.ts.map +1 -0
  1066. package/dist/runtime/unsupported-storage-codecs-error.js +74 -0
  1067. package/dist/runtime/unsupported-storage-codecs-error.js.map +1 -0
  1068. package/dist/runtime/url.d.ts +32 -0
  1069. package/dist/runtime/url.d.ts.map +1 -0
  1070. package/dist/runtime/url.js +96 -0
  1071. package/dist/runtime/url.js.map +1 -0
  1072. package/dist/runtime/utf8.d.ts +10 -0
  1073. package/dist/runtime/utf8.d.ts.map +1 -0
  1074. package/dist/runtime/utf8.js +93 -0
  1075. package/dist/runtime/utf8.js.map +1 -0
  1076. package/dist/runtime/util.d.ts +18 -0
  1077. package/dist/runtime/util.d.ts.map +1 -0
  1078. package/dist/runtime/util.js +59 -0
  1079. package/dist/runtime/util.js.map +1 -0
  1080. package/dist/runtime/value-converter.d.ts +9 -17
  1081. package/dist/runtime/value-converter.d.ts.map +1 -1
  1082. package/dist/runtime/value-converter.js +196 -43
  1083. package/dist/runtime/value-converter.js.map +1 -1
  1084. package/dist/runtime/wasm-loader.d.ts +6 -0
  1085. package/dist/runtime/wasm-loader.d.ts.map +1 -0
  1086. package/dist/runtime/wasm-loader.js +120 -0
  1087. package/dist/runtime/wasm-loader.js.map +1 -0
  1088. package/dist/runtime/write-preparation.d.ts +24 -0
  1089. package/dist/runtime/write-preparation.d.ts.map +1 -0
  1090. package/dist/runtime/write-preparation.js +63 -0
  1091. package/dist/runtime/write-preparation.js.map +1 -0
  1092. package/dist/runtime/write-row.d.ts +8 -0
  1093. package/dist/runtime/write-row.d.ts.map +1 -0
  1094. package/dist/runtime/write-row.js +17 -0
  1095. package/dist/runtime/write-row.js.map +1 -0
  1096. package/dist/schema-hash.d.ts +3 -0
  1097. package/dist/schema-hash.d.ts.map +1 -0
  1098. package/dist/schema-hash.js +5 -0
  1099. package/dist/schema-hash.js.map +1 -0
  1100. package/dist/schema-loader.d.ts +31 -0
  1101. package/dist/schema-loader.d.ts.map +1 -0
  1102. package/dist/schema-loader.js +501 -0
  1103. package/dist/schema-loader.js.map +1 -0
  1104. package/dist/schema-name.d.ts +2 -0
  1105. package/dist/schema-name.d.ts.map +1 -0
  1106. package/dist/schema-name.js +19 -0
  1107. package/dist/schema-name.js.map +1 -0
  1108. package/dist/schema-namespace.d.ts +35 -0
  1109. package/dist/schema-namespace.d.ts.map +1 -0
  1110. package/dist/schema-namespace.js +17 -0
  1111. package/dist/schema-namespace.js.map +1 -0
  1112. package/dist/schema-permissions.d.ts +16 -0
  1113. package/dist/schema-permissions.d.ts.map +1 -0
  1114. package/dist/schema-permissions.js +405 -0
  1115. package/dist/schema-permissions.js.map +1 -0
  1116. package/dist/schema-source.d.ts +11 -0
  1117. package/dist/schema-source.d.ts.map +1 -0
  1118. package/dist/schema-source.js +39 -0
  1119. package/dist/schema-source.js.map +1 -0
  1120. package/dist/schema.d.ts +108 -36
  1121. package/dist/schema.d.ts.map +1 -1
  1122. package/dist/schema.js +1 -10
  1123. package/dist/schema.js.map +1 -1
  1124. package/dist/session/app.d.ts +58 -0
  1125. package/dist/session/app.d.ts.map +1 -0
  1126. package/dist/session/app.js +325 -0
  1127. package/dist/session/app.js.map +1 -0
  1128. package/dist/session/backend-watch.d.ts +138 -0
  1129. package/dist/session/backend-watch.d.ts.map +1 -0
  1130. package/dist/session/backend-watch.js +576 -0
  1131. package/dist/session/backend-watch.js.map +1 -0
  1132. package/dist/session/consumer.d.ts +3 -0
  1133. package/dist/session/consumer.d.ts.map +1 -0
  1134. package/dist/session/consumer.js +3 -0
  1135. package/dist/session/consumer.js.map +1 -0
  1136. package/dist/session/create-jazz-app.d.ts +11 -0
  1137. package/dist/session/create-jazz-app.d.ts.map +1 -0
  1138. package/dist/session/create-jazz-app.js +11 -0
  1139. package/dist/session/create-jazz-app.js.map +1 -0
  1140. package/dist/session/create-jazz-session.d.ts +68 -0
  1141. package/dist/session/create-jazz-session.d.ts.map +1 -0
  1142. package/dist/session/create-jazz-session.js +448 -0
  1143. package/dist/session/create-jazz-session.js.map +1 -0
  1144. package/dist/session/follow-user.d.ts +53 -0
  1145. package/dist/session/follow-user.d.ts.map +1 -0
  1146. package/dist/session/follow-user.js +107 -0
  1147. package/dist/session/follow-user.js.map +1 -0
  1148. package/dist/session/left-behind-replicas.d.ts +62 -0
  1149. package/dist/session/left-behind-replicas.d.ts.map +1 -0
  1150. package/dist/session/left-behind-replicas.js +146 -0
  1151. package/dist/session/left-behind-replicas.js.map +1 -0
  1152. package/dist/session/native-backend-watch.d.ts +4 -0
  1153. package/dist/session/native-backend-watch.d.ts.map +1 -0
  1154. package/dist/session/native-backend-watch.js +14 -0
  1155. package/dist/session/native-backend-watch.js.map +1 -0
  1156. package/dist/session/state.d.ts +93 -0
  1157. package/dist/session/state.d.ts.map +1 -0
  1158. package/dist/session/state.js +383 -0
  1159. package/dist/session/state.js.map +1 -0
  1160. package/dist/shared/index.d.ts +20 -0
  1161. package/dist/shared/index.d.ts.map +1 -0
  1162. package/dist/shared/index.js +17 -0
  1163. package/dist/shared/index.js.map +1 -0
  1164. package/dist/solid/app.d.ts +30 -0
  1165. package/dist/solid/app.d.ts.map +1 -0
  1166. package/dist/solid/app.js +95 -0
  1167. package/dist/solid/app.js.map +1 -0
  1168. package/dist/solid/app.ssr.js +109 -0
  1169. package/dist/solid/app.ssr.js.map +1 -0
  1170. package/dist/solid/create-account-state.d.ts +4 -0
  1171. package/dist/solid/create-account-state.d.ts.map +1 -0
  1172. package/dist/solid/create-account-state.js +10 -0
  1173. package/dist/solid/create-account-state.js.map +1 -0
  1174. package/dist/solid/create-account-state.ssr.js +12 -0
  1175. package/dist/solid/create-account-state.ssr.js.map +1 -0
  1176. package/dist/solid/create-solid-jazz-client-internal.d.ts +13 -0
  1177. package/dist/solid/create-solid-jazz-client-internal.d.ts.map +1 -0
  1178. package/dist/solid/create-solid-jazz-client-internal.js +83 -0
  1179. package/dist/solid/create-solid-jazz-client-internal.js.map +1 -0
  1180. package/dist/solid/create-solid-jazz-client-internal.ssr.js +101 -0
  1181. package/dist/solid/create-solid-jazz-client-internal.ssr.js.map +1 -0
  1182. package/dist/solid/create-solid-jazz-client.d.ts +24 -0
  1183. package/dist/solid/create-solid-jazz-client.d.ts.map +1 -0
  1184. package/dist/solid/create-solid-jazz-client.js +43 -0
  1185. package/dist/solid/create-solid-jazz-client.js.map +1 -0
  1186. package/dist/solid/create-solid-jazz-client.ssr.js +46 -0
  1187. package/dist/solid/create-solid-jazz-client.ssr.js.map +1 -0
  1188. package/dist/solid/index.d.ts +20 -0
  1189. package/dist/solid/index.d.ts.map +1 -0
  1190. package/dist/solid/index.js +13 -0
  1191. package/dist/solid/index.ssr.js +13 -0
  1192. package/dist/solid/provider.d.ts +32 -0
  1193. package/dist/solid/provider.d.ts.map +1 -0
  1194. package/dist/solid/provider.js +63 -0
  1195. package/dist/solid/provider.js.map +1 -0
  1196. package/dist/solid/provider.ssr.js +64 -0
  1197. package/dist/solid/provider.ssr.js.map +1 -0
  1198. package/dist/solid/session.d.ts +22 -0
  1199. package/dist/solid/session.d.ts.map +1 -0
  1200. package/dist/solid/session.js +76 -0
  1201. package/dist/solid/session.js.map +1 -0
  1202. package/dist/solid/session.ssr.js +85 -0
  1203. package/dist/solid/session.ssr.js.map +1 -0
  1204. package/dist/solid/solid-jazz-client-store.d.ts +11 -0
  1205. package/dist/solid/solid-jazz-client-store.d.ts.map +1 -0
  1206. package/dist/solid/solid-jazz-client-store.js +37 -0
  1207. package/dist/solid/solid-jazz-client-store.js.map +1 -0
  1208. package/dist/solid/solid-jazz-client-store.ssr.js +39 -0
  1209. package/dist/solid/solid-jazz-client-store.ssr.js.map +1 -0
  1210. package/dist/solid/use-all.d.ts +18 -0
  1211. package/dist/solid/use-all.d.ts.map +1 -0
  1212. package/dist/solid/use-all.js +73 -0
  1213. package/dist/solid/use-all.js.map +1 -0
  1214. package/dist/solid/use-all.ssr.js +84 -0
  1215. package/dist/solid/use-all.ssr.js.map +1 -0
  1216. package/dist/solid/use-local-first-auth.d.ts +11 -0
  1217. package/dist/solid/use-local-first-auth.d.ts.map +1 -0
  1218. package/dist/solid/use-local-first-auth.js +30 -0
  1219. package/dist/solid/use-local-first-auth.js.map +1 -0
  1220. package/dist/solid/use-local-first-auth.ssr.js +31 -0
  1221. package/dist/solid/use-local-first-auth.ssr.js.map +1 -0
  1222. package/dist/solid/use-one.d.ts +18 -0
  1223. package/dist/solid/use-one.d.ts.map +1 -0
  1224. package/dist/solid/use-one.js +28 -0
  1225. package/dist/solid/use-one.js.map +1 -0
  1226. package/dist/solid/use-one.ssr.js +28 -0
  1227. package/dist/solid/use-one.ssr.js.map +1 -0
  1228. package/dist/solid/use-sync-status.d.ts +8 -0
  1229. package/dist/solid/use-sync-status.d.ts.map +1 -0
  1230. package/dist/solid/use-sync-status.js +14 -0
  1231. package/dist/solid/use-sync-status.js.map +1 -0
  1232. package/dist/solid/use-sync-status.ssr.js +21 -0
  1233. package/dist/solid/use-sync-status.ssr.js.map +1 -0
  1234. package/dist/subscription-store-internal.d.ts +11 -0
  1235. package/dist/subscription-store-internal.d.ts.map +1 -0
  1236. package/dist/subscription-store-internal.js +18 -0
  1237. package/dist/subscription-store-internal.js.map +1 -0
  1238. package/dist/subscriptions-orchestrator.d.ts +53 -13
  1239. package/dist/subscriptions-orchestrator.d.ts.map +1 -1
  1240. package/dist/subscriptions-orchestrator.js +295 -74
  1241. package/dist/subscriptions-orchestrator.js.map +1 -1
  1242. package/dist/svelte/JazzProvider.svelte +62 -0
  1243. package/dist/svelte/JazzProvider.svelte.d.ts +13 -0
  1244. package/dist/svelte/JazzProvider.svelte.d.ts.map +1 -0
  1245. package/dist/svelte/JazzSessionClientProvider.svelte +42 -0
  1246. package/dist/svelte/JazzSessionClientProvider.svelte.d.ts +13 -0
  1247. package/dist/svelte/JazzSessionClientProvider.svelte.d.ts.map +1 -0
  1248. package/dist/svelte/JazzSessionProvider.svelte +68 -0
  1249. package/dist/svelte/JazzSessionProvider.svelte.d.ts +19 -0
  1250. package/dist/svelte/JazzSessionProvider.svelte.d.ts.map +1 -0
  1251. package/dist/svelte/JazzSvelteClientProvider.svelte +79 -0
  1252. package/dist/svelte/JazzSvelteClientProvider.svelte.d.ts +14 -0
  1253. package/dist/svelte/JazzSvelteClientProvider.svelte.d.ts.map +1 -0
  1254. package/dist/svelte/JazzSvelteProvider.svelte +158 -27
  1255. package/dist/svelte/JazzSvelteProvider.svelte.d.ts +3 -2
  1256. package/dist/svelte/JazzSvelteProvider.svelte.d.ts.map +1 -1
  1257. package/dist/svelte/account-state.d.ts +5 -0
  1258. package/dist/svelte/account-state.d.ts.map +1 -0
  1259. package/dist/svelte/account-state.js +9 -0
  1260. package/dist/svelte/auth-state.d.ts +23 -0
  1261. package/dist/svelte/auth-state.d.ts.map +1 -0
  1262. package/dist/svelte/auth-state.js +16 -0
  1263. package/dist/svelte/context.svelte.d.ts +23 -3
  1264. package/dist/svelte/context.svelte.d.ts.map +1 -1
  1265. package/dist/svelte/context.svelte.js +23 -3
  1266. package/dist/svelte/create-jazz-client.d.ts +2 -8
  1267. package/dist/svelte/create-jazz-client.d.ts.map +1 -1
  1268. package/dist/svelte/create-jazz-client.js +1 -17
  1269. package/dist/svelte/index.d.ts +21 -5
  1270. package/dist/svelte/index.d.ts.map +1 -1
  1271. package/dist/svelte/index.js +14 -5
  1272. package/dist/svelte/local-first-auth.svelte.d.ts +50 -0
  1273. package/dist/svelte/local-first-auth.svelte.d.ts.map +1 -0
  1274. package/dist/svelte/local-first-auth.svelte.js +58 -0
  1275. package/dist/svelte/query-subscription.svelte.d.ts +60 -0
  1276. package/dist/svelte/query-subscription.svelte.d.ts.map +1 -0
  1277. package/dist/svelte/query-subscription.svelte.js +135 -0
  1278. package/dist/svelte/session-state.d.ts +11 -0
  1279. package/dist/svelte/session-state.d.ts.map +1 -0
  1280. package/dist/svelte/session-state.js +23 -0
  1281. package/dist/svelte/sync-status.d.ts +11 -0
  1282. package/dist/svelte/sync-status.d.ts.map +1 -0
  1283. package/dist/svelte/sync-status.js +15 -0
  1284. package/dist/testing/client-migrations.d.ts +29 -0
  1285. package/dist/testing/client-migrations.d.ts.map +1 -0
  1286. package/dist/testing/client-migrations.js +34 -0
  1287. package/dist/testing/client-migrations.js.map +1 -0
  1288. package/dist/testing/fixtures/basic/schema.d.ts +11 -0
  1289. package/dist/testing/fixtures/basic/schema.d.ts.map +1 -0
  1290. package/dist/testing/fixtures/basic/schema.js +10 -0
  1291. package/dist/testing/fixtures/basic/schema.js.map +1 -0
  1292. package/dist/testing/fixtures/with-bigint/schema.d.ts +18 -0
  1293. package/dist/testing/fixtures/with-bigint/schema.d.ts.map +1 -0
  1294. package/dist/testing/fixtures/with-bigint/schema.js +15 -0
  1295. package/dist/testing/fixtures/with-bigint/schema.js.map +1 -0
  1296. package/dist/testing/fixtures/with-defaults/schema.d.ts +385 -0
  1297. package/dist/testing/fixtures/with-defaults/schema.d.ts.map +1 -0
  1298. package/dist/testing/fixtures/with-defaults/schema.js +15 -0
  1299. package/dist/testing/fixtures/with-defaults/schema.js.map +1 -0
  1300. package/dist/testing/fixtures/with-enum-payload-defaults/schema.d.ts +4 -0
  1301. package/dist/testing/fixtures/with-enum-payload-defaults/schema.d.ts.map +1 -0
  1302. package/dist/testing/fixtures/with-enum-payload-defaults/schema.js +22 -0
  1303. package/dist/testing/fixtures/with-enum-payload-defaults/schema.js.map +1 -0
  1304. package/dist/testing/fixtures/with-enum-payload-required-null/schema.d.ts +4 -0
  1305. package/dist/testing/fixtures/with-enum-payload-required-null/schema.d.ts.map +1 -0
  1306. package/dist/testing/fixtures/with-enum-payload-required-null/schema.js +14 -0
  1307. package/dist/testing/fixtures/with-enum-payload-required-null/schema.js.map +1 -0
  1308. package/dist/testing/fixtures/with-enum-payload-wrong-tag/schema.d.ts +4 -0
  1309. package/dist/testing/fixtures/with-enum-payload-wrong-tag/schema.d.ts.map +1 -0
  1310. package/dist/testing/fixtures/with-enum-payload-wrong-tag/schema.js +14 -0
  1311. package/dist/testing/fixtures/with-enum-payload-wrong-tag/schema.js.map +1 -0
  1312. package/dist/testing/index.d.ts +6 -1
  1313. package/dist/testing/index.d.ts.map +1 -1
  1314. package/dist/testing/index.js +5 -1
  1315. package/dist/testing/index.js.map +1 -1
  1316. package/dist/testing/policy-test-app.d.ts +123 -0
  1317. package/dist/testing/policy-test-app.d.ts.map +1 -0
  1318. package/dist/testing/policy-test-app.js +215 -0
  1319. package/dist/testing/policy-test-app.js.map +1 -0
  1320. package/dist/testing/test-jazz.d.ts +106 -0
  1321. package/dist/testing/test-jazz.d.ts.map +1 -0
  1322. package/dist/testing/test-jazz.js +154 -0
  1323. package/dist/testing/test-jazz.js.map +1 -0
  1324. package/dist/testing/test-jwt-issuer.d.ts +19 -0
  1325. package/dist/testing/test-jwt-issuer.d.ts.map +1 -0
  1326. package/dist/testing/test-jwt-issuer.js +40 -0
  1327. package/dist/testing/test-jwt-issuer.js.map +1 -0
  1328. package/dist/text-field/index.d.ts +40 -0
  1329. package/dist/text-field/index.d.ts.map +1 -0
  1330. package/dist/text-field/index.js +129 -0
  1331. package/dist/text-field/index.js.map +1 -0
  1332. package/dist/thin/index.d.ts +84 -0
  1333. package/dist/thin/index.d.ts.map +1 -0
  1334. package/dist/thin/index.js +204 -0
  1335. package/dist/thin/index.js.map +1 -0
  1336. package/dist/thin/self-signed-token.d.ts +13 -0
  1337. package/dist/thin/self-signed-token.d.ts.map +1 -0
  1338. package/dist/thin/self-signed-token.js +84 -0
  1339. package/dist/thin/self-signed-token.js.map +1 -0
  1340. package/dist/thin/thin-runtime-source.d.ts +19 -0
  1341. package/dist/thin/thin-runtime-source.d.ts.map +1 -0
  1342. package/dist/thin/thin-runtime-source.js +66 -0
  1343. package/dist/thin/thin-runtime-source.js.map +1 -0
  1344. package/dist/thin/thin-runtime.d.ts +224 -0
  1345. package/dist/thin/thin-runtime.d.ts.map +1 -0
  1346. package/dist/thin/thin-runtime.js +1190 -0
  1347. package/dist/thin/thin-runtime.js.map +1 -0
  1348. package/dist/thin/wire.d.ts +160 -0
  1349. package/dist/thin/wire.d.ts.map +1 -0
  1350. package/dist/thin/wire.js +304 -0
  1351. package/dist/thin/wire.js.map +1 -0
  1352. package/dist/typed-app.d.ts +729 -0
  1353. package/dist/typed-app.d.ts.map +1 -0
  1354. package/dist/typed-app.js +789 -0
  1355. package/dist/typed-app.js.map +1 -0
  1356. package/dist/vue/app.d.ts +76 -0
  1357. package/dist/vue/app.d.ts.map +1 -0
  1358. package/dist/vue/app.js +100 -0
  1359. package/dist/vue/app.js.map +1 -0
  1360. package/dist/vue/create-jazz-client.d.ts +3 -0
  1361. package/dist/vue/create-jazz-client.d.ts.map +1 -0
  1362. package/dist/vue/create-jazz-client.js +2 -0
  1363. package/dist/vue/create-jazz-client.js.map +1 -0
  1364. package/dist/vue/index.d.ts +19 -0
  1365. package/dist/vue/index.d.ts.map +1 -0
  1366. package/dist/vue/index.js +13 -0
  1367. package/dist/vue/index.js.map +1 -0
  1368. package/dist/vue/provider.d.ts +87 -0
  1369. package/dist/vue/provider.d.ts.map +1 -0
  1370. package/dist/vue/provider.js +225 -0
  1371. package/dist/vue/provider.js.map +1 -0
  1372. package/dist/vue/session.d.ts +39 -0
  1373. package/dist/vue/session.d.ts.map +1 -0
  1374. package/dist/vue/session.js +42 -0
  1375. package/dist/vue/session.js.map +1 -0
  1376. package/dist/vue/use-account-state.d.ts +5 -0
  1377. package/dist/vue/use-account-state.d.ts.map +1 -0
  1378. package/dist/vue/use-account-state.js +10 -0
  1379. package/dist/vue/use-account-state.js.map +1 -0
  1380. package/dist/vue/use-all.d.ts +61 -0
  1381. package/dist/vue/use-all.d.ts.map +1 -0
  1382. package/dist/vue/use-all.js +104 -0
  1383. package/dist/vue/use-all.js.map +1 -0
  1384. package/dist/vue/use-local-first-auth.d.ts +53 -0
  1385. package/dist/vue/use-local-first-auth.d.ts.map +1 -0
  1386. package/dist/vue/use-local-first-auth.js +67 -0
  1387. package/dist/vue/use-local-first-auth.js.map +1 -0
  1388. package/dist/vue/use-one.d.ts +24 -0
  1389. package/dist/vue/use-one.d.ts.map +1 -0
  1390. package/dist/vue/use-one.js +17 -0
  1391. package/dist/vue/use-one.js.map +1 -0
  1392. package/dist/vue/use-sync-status.d.ts +9 -0
  1393. package/dist/vue/use-sync-status.d.ts.map +1 -0
  1394. package/dist/vue/use-sync-status.js +16 -0
  1395. package/dist/vue/use-sync-status.js.map +1 -0
  1396. package/dist/web/create-jazz-client.d.ts +8 -0
  1397. package/dist/web/create-jazz-client.d.ts.map +1 -0
  1398. package/dist/web/create-jazz-client.js +8 -0
  1399. package/dist/web/create-jazz-client.js.map +1 -0
  1400. package/dist/web/lazy-local-first.d.ts +8 -0
  1401. package/dist/web/lazy-local-first.d.ts.map +1 -0
  1402. package/dist/web/lazy-local-first.js +13 -0
  1403. package/dist/web/lazy-local-first.js.map +1 -0
  1404. package/dist/web/registered-jazz-client.d.ts +15 -0
  1405. package/dist/web/registered-jazz-client.d.ts.map +1 -0
  1406. package/dist/web/registered-jazz-client.js +35 -0
  1407. package/dist/web/registered-jazz-client.js.map +1 -0
  1408. package/dist/where-operators.d.ts +13 -0
  1409. package/dist/where-operators.d.ts.map +1 -0
  1410. package/dist/where-operators.js +70 -0
  1411. package/dist/where-operators.js.map +1 -0
  1412. package/dist/window-client-storage.d.ts +33 -0
  1413. package/dist/window-client-storage.d.ts.map +1 -0
  1414. package/dist/window-client-storage.js +88 -0
  1415. package/dist/window-client-storage.js.map +1 -0
  1416. package/dist/worker/jazz-broker-worker-core.d.ts +34 -0
  1417. package/dist/worker/jazz-broker-worker-core.d.ts.map +1 -0
  1418. package/dist/worker/jazz-broker-worker-core.js +2033 -0
  1419. package/dist/worker/jazz-broker-worker-core.js.map +1 -0
  1420. package/dist/worker/jazz-broker-worker.d.ts +2 -0
  1421. package/dist/worker/jazz-broker-worker.d.ts.map +1 -0
  1422. package/dist/worker/jazz-broker-worker.js +23997 -0
  1423. package/dist/worker/jazz_wasm_bg.wasm +0 -0
  1424. package/dist/worker/mutation-error-delivery.d.ts +8 -0
  1425. package/dist/worker/mutation-error-delivery.d.ts.map +1 -0
  1426. package/dist/worker/mutation-error-delivery.js +10 -0
  1427. package/dist/worker/mutation-error-delivery.js.map +1 -0
  1428. package/package.json +248 -30
  1429. package/bin/native/.gitkeep +0 -0
  1430. package/bin/native/jazz-tools-darwin-arm64 +0 -0
  1431. package/bin/native/jazz-tools-darwin-x64 +0 -0
  1432. package/bin/native/jazz-tools-linux-arm64 +0 -0
  1433. package/bin/native/jazz-tools-linux-x64 +0 -0
  1434. package/bin/native/jazz-tools-windows-x64.exe +0 -0
  1435. package/dist/cli.test.d.ts +0 -2
  1436. package/dist/cli.test.d.ts.map +0 -1
  1437. package/dist/cli.test.js +0 -154
  1438. package/dist/cli.test.js.map +0 -1
  1439. package/dist/codegen/codegen.test.d.ts +0 -2
  1440. package/dist/codegen/codegen.test.d.ts.map +0 -1
  1441. package/dist/codegen/codegen.test.js +0 -844
  1442. package/dist/codegen/codegen.test.js.map +0 -1
  1443. package/dist/codegen/index.d.ts +0 -18
  1444. package/dist/codegen/index.d.ts.map +0 -1
  1445. package/dist/codegen/index.js +0 -22
  1446. package/dist/codegen/index.js.map +0 -1
  1447. package/dist/codegen/query-builder-generator.d.ts +0 -23
  1448. package/dist/codegen/query-builder-generator.d.ts.map +0 -1
  1449. package/dist/codegen/query-builder-generator.js +0 -325
  1450. package/dist/codegen/query-builder-generator.js.map +0 -1
  1451. package/dist/codegen/type-generator.d.ts +0 -29
  1452. package/dist/codegen/type-generator.d.ts.map +0 -1
  1453. package/dist/codegen/type-generator.js +0 -226
  1454. package/dist/codegen/type-generator.js.map +0 -1
  1455. package/dist/dsl.test.d.ts +0 -2
  1456. package/dist/dsl.test.d.ts.map +0 -1
  1457. package/dist/dsl.test.js +0 -51
  1458. package/dist/dsl.test.js.map +0 -1
  1459. package/dist/permissions/index.test.d.ts +0 -2
  1460. package/dist/permissions/index.test.d.ts.map +0 -1
  1461. package/dist/permissions/index.test.js +0 -830
  1462. package/dist/permissions/index.test.js.map +0 -1
  1463. package/dist/permissions/type-inference.test.d.ts +0 -2
  1464. package/dist/permissions/type-inference.test.d.ts.map +0 -1
  1465. package/dist/permissions/type-inference.test.js +0 -151
  1466. package/dist/permissions/type-inference.test.js.map +0 -1
  1467. package/dist/react/create-jazz-client.integration.test.d.ts +0 -2
  1468. package/dist/react/create-jazz-client.integration.test.d.ts.map +0 -1
  1469. package/dist/react/create-jazz-client.integration.test.js +0 -84
  1470. package/dist/react/create-jazz-client.integration.test.js.map +0 -1
  1471. package/dist/react/create-jazz-client.test.d.ts +0 -2
  1472. package/dist/react/create-jazz-client.test.d.ts.map +0 -1
  1473. package/dist/react/create-jazz-client.test.js +0 -133
  1474. package/dist/react/create-jazz-client.test.js.map +0 -1
  1475. package/dist/react/synthetic-user-switcher.d.ts +0 -9
  1476. package/dist/react/synthetic-user-switcher.d.ts.map +0 -1
  1477. package/dist/react/synthetic-user-switcher.js +0 -65
  1478. package/dist/react/synthetic-user-switcher.js.map +0 -1
  1479. package/dist/react/synthetic-users.d.ts +0 -2
  1480. package/dist/react/synthetic-users.d.ts.map +0 -1
  1481. package/dist/react/synthetic-users.js +0 -2
  1482. package/dist/react/synthetic-users.js.map +0 -1
  1483. package/dist/react/synthetic-users.test.d.ts +0 -2
  1484. package/dist/react/synthetic-users.test.d.ts.map +0 -1
  1485. package/dist/react/synthetic-users.test.js +0 -43
  1486. package/dist/react/synthetic-users.test.js.map +0 -1
  1487. package/dist/react/use-link-external-identity.d.ts +0 -25
  1488. package/dist/react/use-link-external-identity.d.ts.map +0 -1
  1489. package/dist/react/use-link-external-identity.js +0 -45
  1490. package/dist/react/use-link-external-identity.js.map +0 -1
  1491. package/dist/react-native/create-jazz-client.test.d.ts +0 -2
  1492. package/dist/react-native/create-jazz-client.test.d.ts.map +0 -1
  1493. package/dist/react-native/create-jazz-client.test.js +0 -162
  1494. package/dist/react-native/create-jazz-client.test.js.map +0 -1
  1495. package/dist/react-native/create-jazz-rn-runtime.d.ts +0 -13
  1496. package/dist/react-native/create-jazz-rn-runtime.d.ts.map +0 -1
  1497. package/dist/react-native/create-jazz-rn-runtime.js +0 -7
  1498. package/dist/react-native/create-jazz-rn-runtime.js.map +0 -1
  1499. package/dist/react-native/db.d.ts +0 -16
  1500. package/dist/react-native/db.d.ts.map +0 -1
  1501. package/dist/react-native/db.js +0 -50
  1502. package/dist/react-native/db.js.map +0 -1
  1503. package/dist/react-native/db.test.d.ts +0 -2
  1504. package/dist/react-native/db.test.d.ts.map +0 -1
  1505. package/dist/react-native/db.test.js +0 -150
  1506. package/dist/react-native/db.test.js.map +0 -1
  1507. package/dist/react-native/jazz-rn-runtime-adapter.d.ts +0 -56
  1508. package/dist/react-native/jazz-rn-runtime-adapter.d.ts.map +0 -1
  1509. package/dist/react-native/jazz-rn-runtime-adapter.js +0 -192
  1510. package/dist/react-native/jazz-rn-runtime-adapter.js.map +0 -1
  1511. package/dist/react-native/jazz-rn-runtime-adapter.test.d.ts +0 -2
  1512. package/dist/react-native/jazz-rn-runtime-adapter.test.d.ts.map +0 -1
  1513. package/dist/react-native/jazz-rn-runtime-adapter.test.js +0 -165
  1514. package/dist/react-native/jazz-rn-runtime-adapter.test.js.map +0 -1
  1515. package/dist/runtime/client-session.test.d.ts +0 -2
  1516. package/dist/runtime/client-session.test.d.ts.map +0 -1
  1517. package/dist/runtime/client-session.test.js +0 -84
  1518. package/dist/runtime/client-session.test.js.map +0 -1
  1519. package/dist/runtime/client.for-request.test.d.ts +0 -2
  1520. package/dist/runtime/client.for-request.test.d.ts.map +0 -1
  1521. package/dist/runtime/client.for-request.test.js +0 -171
  1522. package/dist/runtime/client.for-request.test.js.map +0 -1
  1523. package/dist/runtime/cloud-server.integration.test.d.ts +0 -2
  1524. package/dist/runtime/cloud-server.integration.test.d.ts.map +0 -1
  1525. package/dist/runtime/cloud-server.integration.test.js +0 -985
  1526. package/dist/runtime/cloud-server.integration.test.js.map +0 -1
  1527. package/dist/runtime/leader-lock.d.ts +0 -15
  1528. package/dist/runtime/leader-lock.d.ts.map +0 -1
  1529. package/dist/runtime/leader-lock.js +0 -49
  1530. package/dist/runtime/leader-lock.js.map +0 -1
  1531. package/dist/runtime/local-auth.d.ts +0 -32
  1532. package/dist/runtime/local-auth.d.ts.map +0 -1
  1533. package/dist/runtime/local-auth.js +0 -93
  1534. package/dist/runtime/local-auth.js.map +0 -1
  1535. package/dist/runtime/local-auth.test.d.ts +0 -2
  1536. package/dist/runtime/local-auth.test.d.ts.map +0 -1
  1537. package/dist/runtime/local-auth.test.js +0 -50
  1538. package/dist/runtime/local-auth.test.js.map +0 -1
  1539. package/dist/runtime/query-adapter.test.d.ts +0 -5
  1540. package/dist/runtime/query-adapter.test.d.ts.map +0 -1
  1541. package/dist/runtime/query-adapter.test.js +0 -1209
  1542. package/dist/runtime/query-adapter.test.js.map +0 -1
  1543. package/dist/runtime/row-transformer.test.d.ts +0 -5
  1544. package/dist/runtime/row-transformer.test.d.ts.map +0 -1
  1545. package/dist/runtime/row-transformer.test.js +0 -364
  1546. package/dist/runtime/row-transformer.test.js.map +0 -1
  1547. package/dist/runtime/subscription-manager.test.d.ts +0 -5
  1548. package/dist/runtime/subscription-manager.test.d.ts.map +0 -1
  1549. package/dist/runtime/subscription-manager.test.js +0 -120
  1550. package/dist/runtime/subscription-manager.test.js.map +0 -1
  1551. package/dist/runtime/sync-transport.d.ts +0 -163
  1552. package/dist/runtime/sync-transport.d.ts.map +0 -1
  1553. package/dist/runtime/sync-transport.js +0 -477
  1554. package/dist/runtime/sync-transport.js.map +0 -1
  1555. package/dist/runtime/sync-transport.test.d.ts +0 -2
  1556. package/dist/runtime/sync-transport.test.d.ts.map +0 -1
  1557. package/dist/runtime/sync-transport.test.js +0 -310
  1558. package/dist/runtime/sync-transport.test.js.map +0 -1
  1559. package/dist/runtime/tab-leader-election.d.ts +0 -97
  1560. package/dist/runtime/tab-leader-election.d.ts.map +0 -1
  1561. package/dist/runtime/tab-leader-election.js +0 -339
  1562. package/dist/runtime/tab-leader-election.js.map +0 -1
  1563. package/dist/runtime/tab-leader-election.test.d.ts +0 -2
  1564. package/dist/runtime/tab-leader-election.test.d.ts.map +0 -1
  1565. package/dist/runtime/tab-leader-election.test.js +0 -278
  1566. package/dist/runtime/tab-leader-election.test.js.map +0 -1
  1567. package/dist/runtime/testing/wasm-runtime-test-utils.d.ts +0 -13
  1568. package/dist/runtime/testing/wasm-runtime-test-utils.d.ts.map +0 -1
  1569. package/dist/runtime/testing/wasm-runtime-test-utils.js +0 -75
  1570. package/dist/runtime/testing/wasm-runtime-test-utils.js.map +0 -1
  1571. package/dist/runtime/utils.d.ts +0 -2
  1572. package/dist/runtime/utils.d.ts.map +0 -1
  1573. package/dist/runtime/utils.js +0 -16
  1574. package/dist/runtime/utils.js.map +0 -1
  1575. package/dist/runtime/value-converter.test.d.ts +0 -5
  1576. package/dist/runtime/value-converter.test.d.ts.map +0 -1
  1577. package/dist/runtime/value-converter.test.js +0 -212
  1578. package/dist/runtime/value-converter.test.js.map +0 -1
  1579. package/dist/runtime/worker-bridge.d.ts +0 -86
  1580. package/dist/runtime/worker-bridge.d.ts.map +0 -1
  1581. package/dist/runtime/worker-bridge.js +0 -250
  1582. package/dist/runtime/worker-bridge.js.map +0 -1
  1583. package/dist/runtime/worker-bridge.race-harness.test.d.ts +0 -2
  1584. package/dist/runtime/worker-bridge.race-harness.test.d.ts.map +0 -1
  1585. package/dist/runtime/worker-bridge.race-harness.test.js +0 -265
  1586. package/dist/runtime/worker-bridge.race-harness.test.js.map +0 -1
  1587. package/dist/runtime/worker-bridge.test.d.ts +0 -2
  1588. package/dist/runtime/worker-bridge.test.d.ts.map +0 -1
  1589. package/dist/runtime/worker-bridge.test.js +0 -233
  1590. package/dist/runtime/worker-bridge.test.js.map +0 -1
  1591. package/dist/sql-gen.d.ts +0 -4
  1592. package/dist/sql-gen.d.ts.map +0 -1
  1593. package/dist/sql-gen.js +0 -163
  1594. package/dist/sql-gen.js.map +0 -1
  1595. package/dist/sql-gen.test.d.ts +0 -2
  1596. package/dist/sql-gen.test.d.ts.map +0 -1
  1597. package/dist/sql-gen.test.js +0 -412
  1598. package/dist/sql-gen.test.js.map +0 -1
  1599. package/dist/subscriptions-orchestrator.integration.test.d.ts +0 -2
  1600. package/dist/subscriptions-orchestrator.integration.test.d.ts.map +0 -1
  1601. package/dist/subscriptions-orchestrator.integration.test.js +0 -194
  1602. package/dist/subscriptions-orchestrator.integration.test.js.map +0 -1
  1603. package/dist/subscriptions-orchestrator.test.d.ts +0 -2
  1604. package/dist/subscriptions-orchestrator.test.d.ts.map +0 -1
  1605. package/dist/subscriptions-orchestrator.test.js +0 -367
  1606. package/dist/subscriptions-orchestrator.test.js.map +0 -1
  1607. package/dist/svelte/SyntheticUserSwitcher.svelte +0 -121
  1608. package/dist/svelte/SyntheticUserSwitcher.svelte.d.ts +0 -11
  1609. package/dist/svelte/SyntheticUserSwitcher.svelte.d.ts.map +0 -1
  1610. package/dist/svelte/context.test.d.ts +0 -2
  1611. package/dist/svelte/context.test.d.ts.map +0 -1
  1612. package/dist/svelte/context.test.js +0 -51
  1613. package/dist/svelte/create-jazz-client.test.d.ts +0 -2
  1614. package/dist/svelte/create-jazz-client.test.d.ts.map +0 -1
  1615. package/dist/svelte/create-jazz-client.test.js +0 -50
  1616. package/dist/svelte/use-all.svelte.d.ts +0 -32
  1617. package/dist/svelte/use-all.svelte.d.ts.map +0 -1
  1618. package/dist/svelte/use-all.svelte.js +0 -61
  1619. package/dist/svelte/use-all.test.d.ts +0 -2
  1620. package/dist/svelte/use-all.test.d.ts.map +0 -1
  1621. package/dist/svelte/use-all.test.js +0 -154
  1622. package/dist/svelte/use-link-external-identity.d.ts +0 -25
  1623. package/dist/svelte/use-link-external-identity.d.ts.map +0 -1
  1624. package/dist/svelte/use-link-external-identity.js +0 -33
  1625. package/dist/svelte/use-link-external-identity.test.d.ts +0 -2
  1626. package/dist/svelte/use-link-external-identity.test.d.ts.map +0 -1
  1627. package/dist/svelte/use-link-external-identity.test.js +0 -97
  1628. package/dist/synthetic-user-switcher.d.ts +0 -16
  1629. package/dist/synthetic-user-switcher.d.ts.map +0 -1
  1630. package/dist/synthetic-user-switcher.js +0 -134
  1631. package/dist/synthetic-user-switcher.js.map +0 -1
  1632. package/dist/synthetic-users.d.ts +0 -32
  1633. package/dist/synthetic-users.d.ts.map +0 -1
  1634. package/dist/synthetic-users.js +0 -124
  1635. package/dist/synthetic-users.js.map +0 -1
  1636. package/dist/testing/fixtures/basic/app.d.ts +0 -55
  1637. package/dist/testing/fixtures/basic/app.d.ts.map +0 -1
  1638. package/dist/testing/fixtures/basic/app.js +0 -176
  1639. package/dist/testing/fixtures/basic/app.js.map +0 -1
  1640. package/dist/testing/fixtures/basic/current.d.ts +0 -2
  1641. package/dist/testing/fixtures/basic/current.d.ts.map +0 -1
  1642. package/dist/testing/fixtures/basic/current.js +0 -6
  1643. package/dist/testing/fixtures/basic/current.js.map +0 -1
  1644. package/dist/testing/index.test.d.ts +0 -2
  1645. package/dist/testing/index.test.d.ts.map +0 -1
  1646. package/dist/testing/index.test.js +0 -234
  1647. package/dist/testing/index.test.js.map +0 -1
  1648. package/dist/testing/local-jazz-server.d.ts +0 -34
  1649. package/dist/testing/local-jazz-server.d.ts.map +0 -1
  1650. package/dist/testing/local-jazz-server.js +0 -313
  1651. package/dist/testing/local-jazz-server.js.map +0 -1
  1652. package/dist/worker/jazz-worker.d.ts +0 -9
  1653. package/dist/worker/jazz-worker.d.ts.map +0 -1
  1654. package/dist/worker/jazz-worker.js +0 -516
  1655. package/dist/worker/jazz-worker.js.map +0 -1
  1656. package/dist/worker/jazz-worker.ts +0 -581
  1657. package/dist/worker/worker-protocol.d.ts +0 -136
  1658. package/dist/worker/worker-protocol.d.ts.map +0 -1
  1659. package/dist/worker/worker-protocol.js +0 -7
  1660. package/dist/worker/worker-protocol.js.map +0 -1
@@ -0,0 +1,2731 @@
1
+ import { createHmac, randomBytes, randomUUID, timingSafeEqual } from "node:crypto";
2
+ import { verifyChallenge } from "../local-first-auth/server.js";
3
+ import { mkdir, readFile, writeFile } from "node:fs/promises";
4
+ import { join, resolve } from "node:path";
5
+ import { JazzCore } from "jazz-napi";
6
+ import { registerInProcessTransport } from "../runtime/in-process-transport.js";
7
+ import { accountAppId, localFirstAccountId } from "../accounts/local-first.js";
8
+ import { LOCAL_FIRST_JWT_ISSUER, parseJwtPayload } from "../runtime/client-session.js";
9
+ import { verifyLocalFirstToken } from "../runtime/local-first-token.js";
10
+ import { endpointScope } from "../runtime/client-scope.js";
11
+ import { PostcardWriter } from "../runtime/native-runtime/native-codec.js";
12
+ import { encodeWebSocketFrameBatch } from "../runtime/native-runtime/websocket.js";
13
+ import { STREAM_RECORD_MESSAGE, STREAM_RECORD_SESSION, StreamRecordReader, encodeStreamClose, encodeStreamRecord, } from "../runtime/native-runtime/http-stream-socket.js";
14
+ import { resolveSchemaSource } from "../schema-source.js";
15
+ import { mergePermissionsIntoWasmSchema, } from "../schema-permissions.js";
16
+ import { shippedMigrations } from "../runtime/client-migrations.js";
17
+ import { computeSchemaHash } from "../schema-hash.js";
18
+ import { validateSchemaAndPermissions } from "../dev/schema-validation.js";
19
+ import { deployArtifacts } from "../dev/catalogue.js";
20
+ import { fetchMigrationGraph } from "../dev/migration-graph.js";
21
+ import { DeploymentError } from "../dev/catalogue-api.js";
22
+ import { backendDbAttributedTo, backendDbForSession, openJazzSession, } from "./create-jazz-session.js";
23
+ import { BackendClientsUnavailable, backendClientVerifier, } from "./backend-clients.js";
24
+ import { BACKEND_USER_ISSUER } from "./backend-issuer.js";
25
+ import { earlyDb } from "./early-db.js";
26
+ import { defaultCoreName, onVercelDeployment, onVercelHost, openVercelCore, refuseVercelAppId, } from "./vercel-store.js";
27
+ import { files } from "./blobs.js";
28
+ export { files, s3, vercelBlob, } from "./blobs.js";
29
+ import { isSameAdmission, recheckEvery } from "./session-recheck.js";
30
+ import { NoJazzAccountError } from "./no-account-error.js";
31
+ import { RequestAuthenticationError } from "./request-auth.js";
32
+ import { optionalPeerImportError } from "./optional-peer.js";
33
+ import { closingBeforeDeadline } from "./socket-deadline.js";
34
+ /**
35
+ * A SQLite core in this process, kept in the directory `path`. It generates
36
+ * its app id on first start and keeps it beside its data, in `<path>/app-id`
37
+ * (`jazz-alpha59-alpha60-import` writes an alpha.59 app's id there). Large
38
+ * values' bytes go to `blobs`, by default `files()` in `<path>/blobs`.
39
+ *
40
+ * Only one process can open `path` at a time (it holds `<path>/jazz.lock`
41
+ * while the core is open); a second one fails with "already open". It
42
+ * refuses to start on serverless hosts with no lasting disk (Vercel, AWS
43
+ * Lambda, Netlify): use `vercel()` or `remote()` there.
44
+ */
45
+ export function sqlite(options) {
46
+ refuseStoreAppId("sqlite", options);
47
+ const blobs = options.blobs ?? files();
48
+ if (blobs !== "sqlite" &&
49
+ (typeof blobs !== "object" || (blobs.kind !== "files" && blobs.kind !== "s3"))) {
50
+ throw new Error('sqlite(): blobs must be files(), s3() or "sqlite"');
51
+ }
52
+ return { kind: "sqlite", path: options.path, blobs };
53
+ }
54
+ /**
55
+ * An in-memory core in this process: for tests and throwaway previews. Each
56
+ * one is its own store, with a new app id.
57
+ */
58
+ export function memory(options) {
59
+ refuseStoreAppId("memory", options);
60
+ return { kind: "memory" };
61
+ }
62
+ /** Stores keep their own app id; one passed from JavaScript is refused, not ignored. */
63
+ function refuseStoreAppId(store, options) {
64
+ if (typeof options === "object" && options !== null && "appId" in options) {
65
+ throw new Error(`${store}(): appId is not an option: the store keeps its own app id. To keep an alpha.59 app's id, import its data with \`jazz-alpha59-alpha60-import import --app-id\`.`);
66
+ }
67
+ }
68
+ /**
69
+ * A core running elsewhere (Jazz Cloud, or a sync server you run), serving
70
+ * the app `appId`, reached from this backend with the app's one secret (its
71
+ * admin secret), or with a `backendCredential` of your own. Browsers still
72
+ * talk only to your backend: it decides who each user is, and the core
73
+ * trusts it to say so. The secret never leaves your server.
74
+ */
75
+ export function remote(options) {
76
+ const appId = options.appId;
77
+ if (typeof appId !== "string" || !appId.trim()) {
78
+ throw new Error("remote(): appId must name the app the core serves (it is empty)");
79
+ }
80
+ let backendCredential;
81
+ if ("backendCredential" in options) {
82
+ backendCredential = options.backendCredential;
83
+ }
84
+ else {
85
+ const secret = options.secret;
86
+ if (secret === undefined && "adminSecret" in options) {
87
+ throw new Error("remote(): `adminSecret` and `backendSecret` were replaced by one `secret`, the app's admin secret");
88
+ }
89
+ if (typeof secret !== "string" || !secret.trim()) {
90
+ throw new Error("remote(): secret must be the app's admin secret (it is empty)");
91
+ }
92
+ backendCredential = () => secret;
93
+ }
94
+ return { kind: "remote", url: options.url.replace(/\/+$/, ""), appId, backendCredential };
95
+ }
96
+ /**
97
+ * The store for apps deployed on Vercel. Use it in dev too: outside a
98
+ * production or preview deployment (`next dev`, `vercel dev`, tests) it runs
99
+ * `local`, by default `sqlite({ path: ".jazz/local" })`.
100
+ *
101
+ * Deployed, it runs a core in a persistent Vercel Sandbox in your own Vercel
102
+ * project, with its data on a Drive: one for production and one per Git
103
+ * branch for previews.
104
+ * It is created on first use, wakes when a request needs it (about a second)
105
+ * and stops after `idleMs` without requests or sockets. The function's Vercel
106
+ * OIDC token is its only credential, so there are no secrets and no env vars:
107
+ * the core admits only tokens naming the workload its first start pinned
108
+ * (team, project and environment by name), and a deployment of another
109
+ * environment refuses to start or retarget it. All previews share one
110
+ * workload, so preview branches' cores are kept apart, not secured from each
111
+ * other. Anyone with Sandbox access to the project controls its cores. The
112
+ * token comes with each request (it can't be read at module scope), so the
113
+ * core opens on the first request, not when `createJazz` is called; work
114
+ * between requests uses the freshest one seen, and open sockets outlive its
115
+ * expiry. A team or project rename (or
116
+ * a change of OIDC issuer mode) changes the workload: delete `/data/trust` in
117
+ * the Sandbox to re-pin the core. Install `@vercel/sandbox` and
118
+ * `@vercel/functions` next to `jazz-tools`. A deployment of a newer jazz-tools
119
+ * restarts the core on its version, and an older deployment never moves it
120
+ * back. Branch cores are not deleted when a branch merges yet: each keeps its
121
+ * Sandbox and a Drive of up to `maxDriveBytes` until you remove them.
122
+ */
123
+ export function vercel(options = {}) {
124
+ // Refused here, not on the first deployed request: in dev the local
125
+ // store runs and would never read it.
126
+ refuseVercelAppId(options);
127
+ const { local, ...rest } = options;
128
+ return { kind: "vercel", options: rest, local: local ?? sqlite({ path: ".jazz/local" }) };
129
+ }
130
+ function blobOptions(blobs) {
131
+ if (blobs === "sqlite")
132
+ return { blobs: "sqlite" };
133
+ if (blobs.kind === "s3") {
134
+ return {
135
+ blobs: "s3",
136
+ ...(blobs.bucket === undefined ? {} : { s3Bucket: blobs.bucket }),
137
+ ...(blobs.region === undefined ? {} : { s3Region: blobs.region }),
138
+ ...(blobs.endpoint === undefined ? {} : { s3Endpoint: blobs.endpoint }),
139
+ ...(blobs.prefix === undefined ? {} : { s3Prefix: blobs.prefix }),
140
+ };
141
+ }
142
+ return { blobs: "files", ...(blobs.dir === undefined ? {} : { blobsDir: blobs.dir }) };
143
+ }
144
+ const LOCAL_FIRST_GUEST = Object.freeze({
145
+ kind: "jazz:local-first-guest",
146
+ });
147
+ /** `request` without the credentials a browser sends with it (its cookies, an `Authorization` header). */
148
+ function withoutCredentials(request) {
149
+ const headers = new Headers(request.headers);
150
+ headers.delete("cookie");
151
+ headers.delete("authorization");
152
+ return new Request(request.url, { method: request.method, headers });
153
+ }
154
+ /**
155
+ * Let this request through as a local-first guest, when it comes from one.
156
+ * Guests are refused unless `authenticate` returns this: a guest has no user
157
+ * in your auth, so only your permissions stand between it and your data.
158
+ *
159
+ * ```ts
160
+ * authenticate: async (request) => {
161
+ * const session = await auth.api.getSession({ headers: request.headers });
162
+ * return session ? { userId: session.user.id } : acceptLocalFirstAuth(request);
163
+ * },
164
+ * ```
165
+ *
166
+ * An app with no sign-in of its own, where every browser is a guest, passes
167
+ * it as is: `authenticate: acceptLocalFirstAuth`.
168
+ *
169
+ * For a request that is not a guest's, it means the same as `null`: no one
170
+ * is signed in.
171
+ *
172
+ * A guest's request may also carry a user's cookie: someone signed in (or
173
+ * up) on that browser, and the guest still uploads its writes before it
174
+ * links to them. Jazz then asks `authenticate` about the request without its
175
+ * cookies and `Authorization` header, so the guest is let in as it would be
176
+ * on its own.
177
+ */
178
+ export function acceptLocalFirstAuth(_request) {
179
+ return LOCAL_FIRST_GUEST;
180
+ }
181
+ const DEFAULT_BASE_PATH = "/jazz";
182
+ // Routes a browser may reach. Everything else (admin, backend admission,
183
+ // shutdown) stays behind this backend.
184
+ /** How long a sync session may take to send its sign-in (its first message). */
185
+ const PRELUDE_DEADLINE_MS = 30_000;
186
+ /** On createJazz's 426 for a socket path: this endpoint serves the HTTP stream. */
187
+ const STREAM_AVAILABLE_HEADER = "x-jazz-stream";
188
+ /** The stream session's key, on each send and close (see `openStream`). */
189
+ const STREAM_KEY_HEADER = "x-jazz-stream-key";
190
+ const PUBLIC_APP_ROUTES = /^\/apps\/[^/]+\/(schemas|schema\/[^/]+)$/;
191
+ // What a browser can't hand the core: secrets, a backend credential or the
192
+ // access it states, or the core's own mark for sockets a credential vouched for.
193
+ // Nor a bearer token: this backend decides who a request is (`authenticate`,
194
+ // backend clients), never the core.
195
+ const STRIPPED_HEADERS = [
196
+ "authorization",
197
+ "x-jazz-backend-secret",
198
+ "x-jazz-admin-secret",
199
+ "x-jazz-session",
200
+ "x-jazz-backend-credential",
201
+ "x-jazz-backend-access",
202
+ "x-jazz-internal-workload-vouched",
203
+ ];
204
+ const CREDENTIAL_HEADER = "x-jazz-backend-credential";
205
+ const ACCESS_HEADER = "x-jazz-backend-access";
206
+ // What the secret slots carry to a remote core: the access stated next to
207
+ // the backend credential decides what a request gets, not these.
208
+ const STAND_IN_SECRET = "stated-by-backend-credential";
209
+ // What a browser's request to a public route carries on to a remote core:
210
+ // never its cookies or its app session.
211
+ const REMOTE_FORWARDED_HEADERS = ["accept", "content-type", "if-none-match"];
212
+ const MAX_STREAM_MESSAGE_BYTES = 2 * 1024 * 1024;
213
+ /**
214
+ * Bytes a session's client may have sent that the core has not taken yet.
215
+ * A transport that waits for the core stays well under it; past it, the
216
+ * client ignored flow control and its session ends.
217
+ */
218
+ const MAX_WAITING_SESSION_BYTES = 32 * 1024 * 1024;
219
+ function headerPairs(headers) {
220
+ const pairs = [];
221
+ headers.forEach((value, name) => {
222
+ if (!STRIPPED_HEADERS.includes(name.toLowerCase()))
223
+ pairs.push([name, value]);
224
+ });
225
+ return pairs;
226
+ }
227
+ function coreResponse(response) {
228
+ const headers = new Headers();
229
+ for (const [name, value] of response.headers)
230
+ headers.append(name, value);
231
+ const nullBody = response.status === 204 || response.status === 304;
232
+ return new Response(nullBody ? null : response.body, {
233
+ status: response.status,
234
+ headers,
235
+ });
236
+ }
237
+ function toBytes(data) {
238
+ if (data instanceof Uint8Array)
239
+ return data;
240
+ if (data instanceof ArrayBuffer)
241
+ return new Uint8Array(data);
242
+ if (Array.isArray(data))
243
+ return Buffer.concat(data);
244
+ if (typeof data === "string")
245
+ return new TextEncoder().encode(data);
246
+ throw new Error("unsupported socket message");
247
+ }
248
+ function arrayBufferOf(bytes) {
249
+ return bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
250
+ }
251
+ /** A WebSocket-shaped session on the core, for clients in this process. */
252
+ function inProcessWebSocket(open) {
253
+ return class InProcessSocket {
254
+ binaryType = "arraybuffer";
255
+ readyState = 0;
256
+ listeners = new Map();
257
+ session;
258
+ constructor(url) {
259
+ queueMicrotask(() => {
260
+ if (this.readyState !== 0)
261
+ return;
262
+ try {
263
+ this.session = open(url, (error, event) => this.onCoreEvent(error, event));
264
+ }
265
+ catch (error) {
266
+ this.emit("error", error);
267
+ this.finish(1011, error instanceof Error ? error.message : String(error));
268
+ return;
269
+ }
270
+ this.readyState = 1;
271
+ this.emit("open");
272
+ });
273
+ }
274
+ addEventListener(type, listener) {
275
+ const list = this.listeners.get(type) ?? [];
276
+ list.push(listener);
277
+ this.listeners.set(type, list);
278
+ }
279
+ send(data) {
280
+ if (this.readyState !== 1 || !this.session)
281
+ throw new Error("socket is not open");
282
+ // Like a socket's own buffer: messages wait here, in order, until the
283
+ // core has room, so this client's pace is the core's.
284
+ this.outbox.push(toBytes(data));
285
+ void this.drain();
286
+ }
287
+ outbox = [];
288
+ draining = false;
289
+ async drain() {
290
+ if (this.draining)
291
+ return;
292
+ this.draining = true;
293
+ try {
294
+ while (this.outbox.length > 0 && this.readyState === 1 && this.session) {
295
+ const data = this.outbox.shift();
296
+ const sent = this.session.sendWithRoom
297
+ ? await this.session.sendWithRoom(data)
298
+ : this.session.send(data);
299
+ if (!sent)
300
+ break;
301
+ }
302
+ }
303
+ catch (error) {
304
+ this.emit("error", error);
305
+ this.close();
306
+ }
307
+ finally {
308
+ this.draining = false;
309
+ }
310
+ }
311
+ close() {
312
+ if (this.readyState >= 2)
313
+ return;
314
+ this.session?.close();
315
+ this.finish(1000, "client closed");
316
+ }
317
+ onCoreEvent(error, event) {
318
+ if (error) {
319
+ this.emit("error", error);
320
+ this.finish(1011, error.message);
321
+ }
322
+ else if (event.kind === "message" && event.data) {
323
+ this.emit("message", { data: arrayBufferOf(event.data) });
324
+ }
325
+ else if (event.kind === "close") {
326
+ this.finish(event.code ?? 1000, event.reason ?? "");
327
+ }
328
+ }
329
+ emit(type, event) {
330
+ for (const listener of this.listeners.get(type) ?? [])
331
+ listener(event);
332
+ }
333
+ finish(code, reason) {
334
+ if (this.readyState >= 2)
335
+ return;
336
+ this.readyState = 3;
337
+ this.emit("close", { code, reason });
338
+ }
339
+ };
340
+ }
341
+ /** The app's schema versions, migrations and permissions, as its code declares them. */
342
+ async function applyBundle(origin, options) {
343
+ const declared = resolveSchemaSource(options.app);
344
+ const schema = mergePermissionsIntoWasmSchema(declared, {});
345
+ await validateSchemaAndPermissions(schema, options.permissions);
346
+ const targetSchemaHash = await computeSchemaHash(schema);
347
+ const shipped = shippedMigrations(declared);
348
+ const schemas = new Map();
349
+ for (const version of shipped?.schemas ?? []) {
350
+ schemas.set(version.hash, version.schema.tables);
351
+ }
352
+ schemas.set(targetSchemaHash, schema);
353
+ const server = { appId: options.appId, serverUrl: origin, adminSecret: options.adminSecret };
354
+ const graph = await fetchMigrationGraph(server);
355
+ const confirm = { ...server, allowDroppingHistory: options.allowDroppingHistory };
356
+ // Published, never activated: this backend's sessions are pinned to its
357
+ // bundle, so deployments of the app serve side by side and a rollback is
358
+ // publishing the older bundle again.
359
+ const deployed = await deployArtifacts(confirm, graph, {
360
+ targetSchemaHash,
361
+ schemas: [...schemas].map(([hash, schema]) => ({ hash, schema })),
362
+ migrations: (shipped?.migrations ?? []).map((edge) => ({
363
+ fromHash: edge.fromHash,
364
+ toHash: edge.toHash,
365
+ forward: edge.forward,
366
+ })),
367
+ permissions: options.permissions,
368
+ }).catch((error) => {
369
+ // A core without `/bundles` predates per-deployment permissions; it
370
+ // must not be handed a deployment it would activate for every backend.
371
+ if (error instanceof DeploymentError && (error.status === 404 || error.status === 405)) {
372
+ throw new Error("createJazz: the sync server predates per-deployment permissions bundles; upgrade it before this backend", { cause: error });
373
+ }
374
+ throw error;
375
+ });
376
+ // An older core answers a publish without the bundle it made.
377
+ if (!deployed.bundle) {
378
+ throw new Error("createJazz: the core did not publish a permissions bundle; upgrade it");
379
+ }
380
+ return deployed.bundle;
381
+ }
382
+ /**
383
+ * `socket`, its first frame (the prelude) pinned to the published bundle
384
+ * this backend serves with. The core honours the pin only on this backend's
385
+ * word, so whatever bundle a browser stated is replaced.
386
+ */
387
+ export function pinnedSocket(socket, bundle) {
388
+ let first = true;
389
+ /** `data`, with the pin stamped into the prelude; null if it can't be. */
390
+ const pin = (data) => {
391
+ if (!first)
392
+ return data;
393
+ first = false;
394
+ const pinned = withBundle(data, bundle());
395
+ // A prelude the pin cannot be stamped into would open unpinned.
396
+ if (pinned === null)
397
+ socket.close();
398
+ return pinned;
399
+ };
400
+ return {
401
+ send(data) {
402
+ const pinned = pin(data);
403
+ return pinned !== null && socket.send(pinned);
404
+ },
405
+ async sendWithRoom(data) {
406
+ const pinned = pin(data);
407
+ if (pinned === null)
408
+ return false;
409
+ return socket.sendWithRoom ? socket.sendWithRoom(pinned) : socket.send(pinned);
410
+ },
411
+ close: () => socket.close(),
412
+ };
413
+ }
414
+ /**
415
+ * `prelude` pinned to `bundle`, or with no pin while none is published yet
416
+ * (the backend's own sockets while it boots): a bundle a browser stated
417
+ * never reaches the core. `null` when the prelude is not a JSON object.
418
+ */
419
+ function withBundle(prelude, bundle) {
420
+ let parsed;
421
+ try {
422
+ parsed = JSON.parse(new TextDecoder().decode(prelude));
423
+ }
424
+ catch {
425
+ return null;
426
+ }
427
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
428
+ return null;
429
+ const { bundle: _stated, ...rest } = parsed;
430
+ return new TextEncoder().encode(JSON.stringify(bundle === undefined ? rest : { ...rest, bundle }));
431
+ }
432
+ /** `bundle` is the published bundle every socket the core opens is pinned to. */
433
+ async function openInProcessCore(store, bundle) {
434
+ const backendSecret = randomBytes(32).toString("base64url");
435
+ const adminSecret = randomBytes(32).toString("base64url");
436
+ // The core holds `<path>/jazz.lock` with an OS lock while it's open.
437
+ if (store.kind === "sqlite")
438
+ refuseServerlessDisk(store.path);
439
+ const appId = store.kind === "sqlite" ? await keptAppId(store.path) : randomUUID();
440
+ const core = await JazzCore.open({
441
+ appId,
442
+ backendSecret,
443
+ adminSecret,
444
+ ...(store.kind === "sqlite"
445
+ ? { dataDir: store.path, ...blobOptions(store.blobs) }
446
+ : { inMemory: true }),
447
+ });
448
+ const handle = async (method, path, headers, body) => core.handle(method, path, headers, Buffer.from(body));
449
+ const serverUrl = `http://jazz-${randomUUID()}.invalid`;
450
+ const unregister = registerInProcessTransport(serverUrl, {
451
+ fetch: async (input, init) => {
452
+ const request = new Request(input, init);
453
+ const url = new URL(request.url);
454
+ return coreResponse(await handle(request.method, url.pathname + url.search, [...request.headers].map(([name, value]) => [name, value]), new Uint8Array(await request.arrayBuffer())));
455
+ },
456
+ // This process's own clients: no handshake deadline, as a burst of
457
+ // synchronous writes right after one opens holds its Hello back.
458
+ WebSocket: inProcessWebSocket((_url, onEvent) => pinnedSocket(core.openInProcessSocket(onEvent), bundle)),
459
+ });
460
+ const opened = {
461
+ appId,
462
+ serverUrl,
463
+ adminSecret,
464
+ backendSecret,
465
+ handle,
466
+ openSocket: (headers, onEvent) => pinnedSocket(core.openSocket(headers, onEvent), bundle),
467
+ async close() {
468
+ unregister();
469
+ await core.close();
470
+ },
471
+ };
472
+ return opened;
473
+ }
474
+ /**
475
+ * The app id an in-process SQLite core keeps beside its data, in
476
+ * `<path>/app-id`: a new one on first start, so the app's identities stay
477
+ * the same across restarts without the app naming an id.
478
+ */
479
+ async function keptAppId(dir) {
480
+ const file = join(dir, "app-id");
481
+ const kept = async () => {
482
+ try {
483
+ return (await readFile(file, "utf8")).trim() || undefined;
484
+ }
485
+ catch (error) {
486
+ if (error.code !== "ENOENT")
487
+ throw error;
488
+ return undefined;
489
+ }
490
+ };
491
+ let appId = await kept();
492
+ if (appId === undefined) {
493
+ await mkdir(dir, { recursive: true });
494
+ // `wx`: two processes starting the same store at once agree on one id.
495
+ try {
496
+ appId = randomUUID();
497
+ await writeFile(file, `${appId}\n`, { flag: "wx" });
498
+ }
499
+ catch (error) {
500
+ if (error.code !== "EEXIST")
501
+ throw error;
502
+ appId = (await kept());
503
+ }
504
+ }
505
+ return appId;
506
+ }
507
+ /**
508
+ * Serverless functions have no disk that outlives an instance (or none
509
+ * writable at all), so a sqlite store there loses data silently.
510
+ */
511
+ function refuseServerlessDisk(dir) {
512
+ const host = onVercelHost()
513
+ ? "Vercel"
514
+ : process.env.AWS_LAMBDA_FUNCTION_NAME
515
+ ? "AWS Lambda"
516
+ : process.env.NETLIFY
517
+ ? "Netlify"
518
+ : undefined;
519
+ if (!host)
520
+ return;
521
+ throw new Error(`sqlite({ path: ${JSON.stringify(dir)} }) can't keep data on ${host}: its functions have no lasting disk. ` +
522
+ (host === "Vercel" ? "Use vercel(), whose local store runs sqlite() in dev, or " : "Use ") +
523
+ "remote({ url, appId, secret }) to a sync server or Jazz Cloud.");
524
+ }
525
+ /** The access a request from this process's own clients asks for, by the secret slot it fills. */
526
+ function accessOffered(headers) {
527
+ if (headers.has("x-jazz-admin-secret"))
528
+ return "admin";
529
+ if (headers.has("x-jazz-backend-secret"))
530
+ return "backend";
531
+ return "session";
532
+ }
533
+ /**
534
+ * A core reached over the network. Every request and socket carries the
535
+ * backend credential and the access it states; a core that trusts a workload
536
+ * admits nothing else, and either way the secrets a request offers itself
537
+ * never count next to it. `secrets` fill the secret slots (stand-ins unless
538
+ * the caller holds the real ones).
539
+ */
540
+ function openRemoteCore(appId, target, bundle) {
541
+ const socketUrl = `${target.url.replace(/^http/, "ws")}/apps/${encodeURIComponent(appId)}/ws`;
542
+ if (!globalThis.WebSocket) {
543
+ throw new Error("remote() needs a global WebSocket (Node 22 or newer)");
544
+ }
545
+ // Node's WebSocket (undici) takes upgrade headers as a second argument.
546
+ const NativeWebSocket = globalThis.WebSocket;
547
+ const credentialHeaders = async (access) => {
548
+ const credential = await target.backendCredential();
549
+ if (typeof credential !== "string" || !credential) {
550
+ throw new Error("backendCredential() returned no credential");
551
+ }
552
+ return access === "session"
553
+ ? [[CREDENTIAL_HEADER, credential]]
554
+ : [
555
+ [CREDENTIAL_HEADER, credential],
556
+ [ACCESS_HEADER, access],
557
+ ];
558
+ };
559
+ const withoutStated = (headers) => headers.filter(([name]) => {
560
+ const lower = name.toLowerCase();
561
+ return lower !== CREDENTIAL_HEADER && lower !== ACCESS_HEADER;
562
+ });
563
+ const core = {
564
+ appId,
565
+ serverUrl: `http://jazz-remote-${randomUUID()}.invalid`,
566
+ adminSecret: target.secrets?.adminSecret ?? STAND_IN_SECRET,
567
+ backendSecret: target.secrets?.backendSecret ?? STAND_IN_SECRET,
568
+ async handle(method, path, headers, body, access = "session") {
569
+ const response = await fetch(`${target.url}${path}`, {
570
+ method,
571
+ headers: [...withoutStated(headers), ...(await credentialHeaders(access))].map(([name, value]) => [name, value]),
572
+ ...(method === "GET" || method === "HEAD" ? {} : { body: body }),
573
+ });
574
+ const replyHeaders = [];
575
+ response.headers.forEach((value, name) => {
576
+ // fetch already decoded the body.
577
+ if (name !== "content-encoding" && name !== "content-length") {
578
+ replyHeaders.push([name, value]);
579
+ }
580
+ });
581
+ return {
582
+ status: response.status,
583
+ headers: replyHeaders,
584
+ body: new Uint8Array(await response.arrayBuffer()),
585
+ };
586
+ },
587
+ openSocket: (_headers, onEvent, access = "session") => pinnedSocket(connect(socketUrl, onEvent, access), bundle),
588
+ async close() {
589
+ unregister();
590
+ },
591
+ };
592
+ // Browsers' own headers stay here: the core sees only this backend.
593
+ function connect(url, onEvent, access) {
594
+ let ws;
595
+ const queued = [];
596
+ let ended = false;
597
+ const finish = (code, reason) => {
598
+ if (ended)
599
+ return;
600
+ ended = true;
601
+ onEvent(null, { kind: "close", code, reason });
602
+ };
603
+ credentialHeaders(access)
604
+ .then((headers) => {
605
+ if (ended)
606
+ return;
607
+ ws = new NativeWebSocket(url, { headers: Object.fromEntries(headers) });
608
+ ws.binaryType = "arraybuffer";
609
+ ws.addEventListener("open", () => {
610
+ for (const data of queued.splice(0))
611
+ ws.send(data);
612
+ });
613
+ ws.addEventListener("message", (event) => {
614
+ const data = typeof event.data === "string"
615
+ ? new TextEncoder().encode(event.data)
616
+ : new Uint8Array(event.data);
617
+ onEvent(null, { kind: "message", data });
618
+ });
619
+ ws.addEventListener("close", (event) => finish(event.code, event.reason));
620
+ // A socket that never connects (the core is down or restarting) can
621
+ // report only the error, and stay CONNECTING: without this, the link
622
+ // waits on it forever instead of retrying.
623
+ ws.addEventListener("error", () => {
624
+ finish(1006, "connection to the core failed");
625
+ try {
626
+ ws?.close();
627
+ }
628
+ catch {
629
+ // Already closing.
630
+ }
631
+ });
632
+ })
633
+ // A failing credential hook, or a socket that can't even be created.
634
+ .catch((error) => finish(1011, error instanceof Error ? error.message : "no backend credential"));
635
+ return {
636
+ send(data) {
637
+ if (ended)
638
+ return false;
639
+ if (ws?.readyState === 1)
640
+ ws.send(data);
641
+ else
642
+ queued.push(data);
643
+ return true;
644
+ },
645
+ close() {
646
+ ended = true;
647
+ ws?.close();
648
+ },
649
+ };
650
+ }
651
+ // This process's own clients (the backend's session) reach the core
652
+ // through an in-process origin, so they present the credential too.
653
+ const unregister = registerInProcessTransport(core.serverUrl, {
654
+ fetch: async (input, init) => {
655
+ const request = new Request(input, init);
656
+ const url = new URL(request.url);
657
+ const headers = [];
658
+ request.headers.forEach((value, name) => headers.push([name, value]));
659
+ return coreResponse(await core.handle(request.method, url.pathname + url.search, headers, new Uint8Array(await request.arrayBuffer()), accessOffered(request.headers)));
660
+ },
661
+ WebSocket: inProcessWebSocket((url, onEvent) => {
662
+ const { pathname, search } = new URL(url);
663
+ return pinnedSocket(connect(`${target.url.replace(/^http/, "ws")}${pathname}${search}`, onEvent, "backend"), bundle);
664
+ }),
665
+ });
666
+ return core;
667
+ }
668
+ /**
669
+ * A request `authenticate` names no user for: what an app answers with 401.
670
+ * (A throwing `authenticate` passes its own error through instead.)
671
+ */
672
+ function signedOut(operation) {
673
+ return new RequestAuthenticationError(`${operation}: the request has no signed-in user`, {
674
+ code: "signed_out",
675
+ });
676
+ }
677
+ /** How long `close()` waits for pending writes to reach the core. */
678
+ const CLOSE_SYNC_TIMEOUT_MS = 10_000;
679
+ function jazzSettings(options) {
680
+ const basePath = (options.basePath ?? DEFAULT_BASE_PATH).replace(/\/+$/, "");
681
+ const publicUrls = [options.publicUrl ?? []].flat().map((value) => {
682
+ try {
683
+ // The same form a browser client scopes itself by (`clientScope`).
684
+ if (!/^(https?|wss?):\/\//.test(value))
685
+ throw new Error("relative");
686
+ return endpointScope(value);
687
+ }
688
+ catch {
689
+ throw new Error(`createJazz: publicUrl ${JSON.stringify(value)} is not an absolute URL like "https://app.example.com/jazz"`);
690
+ }
691
+ });
692
+ const allowedOrigins = new Set((options.allowedOrigins ?? []).map((origin) => {
693
+ let parsed;
694
+ try {
695
+ parsed = new URL(origin).origin;
696
+ }
697
+ catch {
698
+ // Not a URL: refused below.
699
+ }
700
+ // "localhost:3000" parses with an opaque "null" origin, which would let
701
+ // sandboxed iframes and file:// pages through.
702
+ if (!parsed || parsed === "null") {
703
+ throw new Error(`createJazz: allowedOrigins entry ${JSON.stringify(origin)} is not an origin like "https://app.example.com"`);
704
+ }
705
+ return parsed;
706
+ }));
707
+ if ("appId" in options) {
708
+ throw new Error("createJazz(): appId moved to the store: remote({ url, appId, secret }) names the app it serves, and sqlite(), memory() and vercel() keep their own id.");
709
+ }
710
+ return { basePath, publicUrls, allowedOrigins };
711
+ }
712
+ /** The store this process runs: `vercel()` outside a Vercel deployment runs its `local` store. */
713
+ function runningStore(store) {
714
+ return store.kind === "vercel" && !onVercelDeployment() ? store.local : store;
715
+ }
716
+ /**
717
+ * Open `store` and apply the schema, migrations and permissions `options`
718
+ * declare to its core.
719
+ */
720
+ async function openJazz(initial, store) {
721
+ let options = initial;
722
+ let { basePath, publicUrls, allowedOrigins } = jazzSettings(options);
723
+ // The bundle this backend published: every socket to the core carries it,
724
+ // and the core governs this backend's sessions by its permissions alone.
725
+ let pin;
726
+ const bundle = () => pin;
727
+ const core = store.kind === "remote"
728
+ ? openRemoteCore(store.appId, store, bundle)
729
+ : store.kind === "vercel"
730
+ ? await openVercelCore({
731
+ options: store.options,
732
+ // The function's OIDC token is the core's only credential.
733
+ openRemote: ({ appId, url, backendCredential }) => openRemoteCore(appId, { url, backendCredential }, bundle),
734
+ })
735
+ : await openInProcessCore(store, bundle);
736
+ const appId = core.appId;
737
+ const issuer = BACKEND_USER_ISSUER;
738
+ /** Publish `next`'s bundle: what it is pinned by. Publishing one already published changes nothing. */
739
+ const publish = (next) => applyBundle(core.serverUrl, { ...next, appId, adminSecret: core.adminSecret });
740
+ /** Publish `next`'s bundle and open the backend's own session on it. */
741
+ async function backendSession(next, published) {
742
+ pin = published ?? (await publish(next));
743
+ const session = await openJazzSession({
744
+ appId,
745
+ app: next.app,
746
+ permissions: next.permissions,
747
+ serverUrl: core.serverUrl,
748
+ driver: { type: "memory" },
749
+ initial: { backendSecret: core.backendSecret },
750
+ });
751
+ const opened = session.getSnapshot();
752
+ if (opened.status !== "ready" || !opened.client) {
753
+ await session.close();
754
+ throw opened.error ?? new Error(`Jazz backend session did not open (${opened.status})`);
755
+ }
756
+ return { session, client: opened.client };
757
+ }
758
+ let session;
759
+ let backend;
760
+ try {
761
+ ({ session, client: backend } = await backendSession(options));
762
+ }
763
+ catch (error) {
764
+ await core.close();
765
+ throw store.kind === "remote" ? unreachableCore(store.url, error) : error;
766
+ }
767
+ let backendClients = backendClientVerifier(options.backendClients ?? []);
768
+ /**
769
+ * A later `createJazz` for this store (a dev server's hot reload): publish
770
+ * its bundle, move the backend's own database to it, and read its options
771
+ * from now on. Open sync sessions stay; the core reconnects those pinned
772
+ * to the old bundle.
773
+ */
774
+ async function reload(next) {
775
+ const settings = jazzSettings(next);
776
+ // The same app and permissions (a reload of a module that imports them
777
+ // unchanged, or a hot reload that rebuilt equal ones): the bundle, and
778
+ // the backend's session with its writes and `forReqUser` dbs, stay.
779
+ if (next.app !== options.app || next.permissions !== options.permissions) {
780
+ const published = await publish(next);
781
+ if (published !== pin) {
782
+ const previousPin = pin;
783
+ let fresh;
784
+ try {
785
+ fresh = await backendSession(next, published);
786
+ }
787
+ catch (error) {
788
+ pin = previousPin;
789
+ throw error;
790
+ }
791
+ retire(session);
792
+ ({ session, client: backend } = fresh);
793
+ }
794
+ }
795
+ options = next;
796
+ ({ basePath, publicUrls, allowedOrigins } = settings);
797
+ backendClients = backendClientVerifier(next.backendClients ?? []);
798
+ upgradesSockets = attached || (next.upgradesSockets ?? false);
799
+ }
800
+ /**
801
+ * Sessions a reload replaced. Each stays open for
802
+ * `RETIRED_SESSION_GRACE_MS`, so the writes it has in flight and the
803
+ * `forReqUser` dbs requests still hold finish, then closes (draining its
804
+ * writes); a close of this Jazz closes those left.
805
+ */
806
+ const retiring = new Set();
807
+ function retire(old) {
808
+ let closed;
809
+ const closeOld = () => {
810
+ clearTimeout(timer);
811
+ return (closed ??= old
812
+ .close()
813
+ .catch((error) => console.error("jazz: a retired session did not close", error))
814
+ .finally(() => retiring.delete(closeOld)));
815
+ };
816
+ const timer = setTimeout(closeOld, RETIRED_SESSION_GRACE_MS);
817
+ timer.unref?.();
818
+ retiring.add(closeOld);
819
+ }
820
+ /**
821
+ * Who sent `request`: a scoped backend client's user, or the user the
822
+ * app's own `authenticate` names. A trusted backend client has no user.
823
+ */
824
+ async function authenticate(request) {
825
+ const client = await backendClients.resolve(request);
826
+ if (client !== null)
827
+ return client !== "refused" && client.kind === "user" ? client.user : null;
828
+ const answer = await askAuthenticate(request);
829
+ return answer === LOCAL_FIRST_GUEST ? null : answer;
830
+ }
831
+ async function askAuthenticate(request) {
832
+ if (!options.authenticate)
833
+ return null;
834
+ return (await options.authenticate(request)) ?? null;
835
+ }
836
+ /** Whether the app lets `request` in as a local-first guest (`acceptLocalFirstAuth`). */
837
+ let warnedGuestsOff = false;
838
+ async function acceptsGuest(request) {
839
+ const answer = await askAuthenticate(request);
840
+ if (answer === LOCAL_FIRST_GUEST)
841
+ return true;
842
+ // A user is signed in on this browser too: one who just signed up, whose
843
+ // guest still uploads its writes before it links to them. A guest is
844
+ // bound to its own key, never to that user, and whether the app lets
845
+ // guests in doesn't depend on who else is signed in: ask as the request
846
+ // would be without the user's credentials.
847
+ if (answer && (await askAuthenticate(withoutCredentials(request))) === LOCAL_FIRST_GUEST)
848
+ return true;
849
+ if (!warnedGuestsOff) {
850
+ warnedGuestsOff = true;
851
+ console.warn("createJazz: refused a local-first guest. To let guests sync, return acceptLocalFirstAuth(request) from authenticate for them.");
852
+ }
853
+ return false;
854
+ }
855
+ /** One admin account request to the core: this backend vouches for the identities. */
856
+ async function adminAccounts(operation, body) {
857
+ const response = await core.handle("POST", `/apps/${encodeURIComponent(accountAppId(appId))}/admin/accounts/${operation}`, [
858
+ ["x-jazz-admin-secret", core.adminSecret],
859
+ ["content-type", "application/json"],
860
+ ], new TextEncoder().encode(JSON.stringify(body)), "admin");
861
+ const text = new TextDecoder().decode(response.body);
862
+ if (response.status !== 200) {
863
+ throw Object.assign(new Error(`Jazz account ${operation} failed (${response.status}): ${text}`), {
864
+ status: response.status,
865
+ code: text.trim(),
866
+ });
867
+ }
868
+ const parsed = JSON.parse(text);
869
+ return { ...parsed, account: String(parsed.account) };
870
+ }
871
+ const identity = (userId) => ({ issuer, subject: userId });
872
+ // A user's account never changes once assigned (linking only adds
873
+ // identities to an account), so the core is asked once per user for a
874
+ // while, not on every sign-in, socket and request. Only assignments are
875
+ // cached: a user without an account may get one at any moment.
876
+ const accounts = new Map();
877
+ const ACCOUNT_CACHE_LIMIT = 10_000;
878
+ function remember(userId, account) {
879
+ if (accounts.size >= ACCOUNT_CACHE_LIMIT) {
880
+ accounts.delete(accounts.keys().next().value);
881
+ }
882
+ accounts.set(userId, {
883
+ account,
884
+ until: Date.now() + (options.sessionTtlSeconds ?? 3600) * 1000,
885
+ });
886
+ return account;
887
+ }
888
+ /**
889
+ * The user's account, or null while they have none. Never creates one:
890
+ * only a client's sign-in (`backend-sign-in`), a guest's link
891
+ * (`backend-link`) and `createAccountFor` do, so a local-first guest can
892
+ * still link to a user the backend has only looked up or acted for (V9).
893
+ */
894
+ async function existingAccountOf(userId) {
895
+ const cached = accounts.get(userId);
896
+ if (cached && cached.until > Date.now())
897
+ return cached.account;
898
+ try {
899
+ const { account } = await adminAccounts("resolve", { identity: identity(userId) });
900
+ return remember(userId, account);
901
+ }
902
+ catch (error) {
903
+ // Only the core's own "no account for this identity" answer: any other
904
+ // 404 (an unknown app, a missing route) is a server error, not a user
905
+ // without an account.
906
+ const { status, code } = error;
907
+ if (status === 404 && code === "identity_not_assigned")
908
+ return null;
909
+ throw error;
910
+ }
911
+ }
912
+ /** The user's account, created if they have none (a sign-in, or `createAccountFor`). */
913
+ async function accountOf(userId) {
914
+ const cached = accounts.get(userId);
915
+ if (cached && cached.until > Date.now())
916
+ return cached.account;
917
+ const { account } = await adminAccounts("login-or-register", { identity: identity(userId) });
918
+ return remember(userId, account);
919
+ }
920
+ /** The user's session, on the account they already have. */
921
+ async function sessionFor(user, caller) {
922
+ const account = await existingAccountOf(user.userId);
923
+ if (account === null)
924
+ throw new NoJazzAccountError(user.userId, caller);
925
+ return {
926
+ account_id: account,
927
+ issuer,
928
+ user_id: user.userId,
929
+ claims: user.claims ?? {},
930
+ authMode: "external",
931
+ };
932
+ }
933
+ async function linkIdentity(link) {
934
+ if (link.from === link.to)
935
+ throw new Error("linkIdentity: from and to are the same identity");
936
+ const { account } = await adminAccounts("link", {
937
+ from: identity(link.from),
938
+ to: identity(link.to),
939
+ });
940
+ return { account };
941
+ }
942
+ /**
943
+ * The account sign-in a browser makes with only the app's own session: the
944
+ * backend's `authenticate` names the user, and the core resolves (or
945
+ * creates) their account.
946
+ */
947
+ async function backendSignIn(request) {
948
+ if (request.method !== "POST")
949
+ return new Response(null, { status: 405 });
950
+ const user = await authenticate(request);
951
+ if (!user)
952
+ return new Response("signed_out", { status: 401 });
953
+ const account = await accountOf(user.userId);
954
+ const expiresAt = Math.floor(Date.now() / 1000) + (options.sessionTtlSeconds ?? 3600);
955
+ return Response.json({ account, identity: identity(user.userId), claims: user.claims ?? {}, expiresAt }, { headers: { "Cache-Control": "no-store" } });
956
+ }
957
+ /**
958
+ * Who `request`'s user is, without changing anything: the user
959
+ * `authenticate` names, and whether the core already holds an account for
960
+ * them. A browser's session asks this to follow the backend; only a sign-in
961
+ * (`backend-sign-in`) or a link (`backend-link`) assigns an account, so a
962
+ * local-first guest whose user has none yet can still link to them.
963
+ */
964
+ async function backendUser(request) {
965
+ if (request.method !== "POST")
966
+ return new Response(null, { status: 405 });
967
+ const user = await authenticate(request);
968
+ if (!user)
969
+ return new Response("signed_out", { status: 401 });
970
+ let account;
971
+ try {
972
+ account = await existingAccountOf(user.userId);
973
+ }
974
+ catch (error) {
975
+ // The core refuses this identity (it was revoked): say so, as the
976
+ // core does, rather than fail as a server error.
977
+ if (error.status === 403)
978
+ return new Response("identity_not_authorized", { status: 403 });
979
+ throw error;
980
+ }
981
+ return Response.json({ account, identity: identity(user.userId), claims: user.claims ?? {} }, { headers: { "Cache-Control": "no-store" } });
982
+ }
983
+ /**
984
+ * Link challenges: a guest links only on a proof made for one challenge,
985
+ * never on its sync token, so a leaked token can't link it to someone
986
+ * else. A challenge names the user it links to and expires quickly; it is
987
+ * signed with a key only this app's backend instances share (derived from
988
+ * the core's admin secret), and its nonce becomes the link's single-use
989
+ * intent id at the core, so a proof works once.
990
+ */
991
+ const challengeKey = createHmac("sha256", core.adminSecret)
992
+ .update(`jazz-link-challenge-v1\0${accountAppId(appId)}`)
993
+ .digest();
994
+ const LINK_CHALLENGE_TTL_SECONDS = 120;
995
+ const challengeMac = (payload) => createHmac("sha256", challengeKey).update(payload).digest("base64url");
996
+ function issueLinkChallenge(userId) {
997
+ const expiresAt = Math.floor(Date.now() / 1000) + LINK_CHALLENGE_TTL_SECONDS;
998
+ const payload = Buffer.from(JSON.stringify({ v: 1, sub: userId, nonce: randomUUID(), exp: expiresAt })).toString("base64url");
999
+ return { challenge: `${payload}.${challengeMac(payload)}`, expiresAt };
1000
+ }
1001
+ /** The nonce of a challenge this backend issued for `userId`, still fresh; else null. */
1002
+ function readLinkChallenge(challenge, userId) {
1003
+ if (typeof challenge !== "string" || challenge.length > 1024)
1004
+ return null;
1005
+ const [payload, mac, extra] = challenge.split(".");
1006
+ if (!payload || !mac || extra !== undefined)
1007
+ return null;
1008
+ const expected = Buffer.from(challengeMac(payload));
1009
+ const given = Buffer.from(mac);
1010
+ if (expected.length !== given.length || !timingSafeEqual(expected, given))
1011
+ return null;
1012
+ let claims;
1013
+ try {
1014
+ claims = JSON.parse(Buffer.from(payload, "base64url").toString("utf8"));
1015
+ }
1016
+ catch {
1017
+ return null;
1018
+ }
1019
+ if (claims.v !== 1 ||
1020
+ claims.sub !== userId ||
1021
+ typeof claims.nonce !== "string" ||
1022
+ typeof claims.exp !== "number" ||
1023
+ claims.exp <= Date.now() / 1000) {
1024
+ return null;
1025
+ }
1026
+ return claims.nonce;
1027
+ }
1028
+ /** A challenge for the guest to sign before it links to the signed-in user. */
1029
+ async function backendLinkChallenge(request) {
1030
+ if (request.method !== "POST")
1031
+ return new Response(null, { status: 405 });
1032
+ const user = await authenticate(request);
1033
+ if (!user)
1034
+ return new Response("signed_out", { status: 401 });
1035
+ return Response.json(issueLinkChallenge(user.userId), {
1036
+ headers: { "Cache-Control": "no-store" },
1037
+ });
1038
+ }
1039
+ /**
1040
+ * A local-first guest who just signed up: link the guest's identity to the
1041
+ * user `authenticate` now names, so the account and its data carry over.
1042
+ * The guest proves itself by signing a challenge issued for this user
1043
+ * (see {@link issueLinkChallenge}).
1044
+ */
1045
+ async function backendLink(request) {
1046
+ if (request.method !== "POST")
1047
+ return new Response(null, { status: 405 });
1048
+ const user = await authenticate(request);
1049
+ if (!user)
1050
+ return new Response("signed_out", { status: 401 });
1051
+ let body;
1052
+ try {
1053
+ body = (await request.json());
1054
+ }
1055
+ catch {
1056
+ return new Response("local_first_proof_required", { status: 400 });
1057
+ }
1058
+ const nonce = readLinkChallenge(body?.challenge, user.userId);
1059
+ if (!nonce)
1060
+ return new Response("invalid_link_challenge", { status: 400 });
1061
+ let guest;
1062
+ try {
1063
+ const proven = verifyChallenge(String(body.proof ?? ""), body.challenge);
1064
+ guest = { issuer: proven.issuer, subject: proven.subject };
1065
+ }
1066
+ catch {
1067
+ return new Response("invalid_local_first_proof", { status: 401 });
1068
+ }
1069
+ // The guest's account follows from its key and the namespace it was
1070
+ // founded in: this app's id, or one of this endpoint's URLs for an
1071
+ // app-less client. Any other namespace is another app's guest.
1072
+ const founding = linkAudience(request, body.audience);
1073
+ if (!founding)
1074
+ return new Response("invalid_local_first_proof", { status: 401 });
1075
+ const account = localFirstAccountId(founding.endpoint ?? appId, guest.subject);
1076
+ const userIs = async (expected) => (await adminAccounts("resolve", { identity: identity(user.userId) })).account === expected;
1077
+ let guestRevoked = false;
1078
+ try {
1079
+ try {
1080
+ await adminAccounts("found-local-first", {
1081
+ identity: guest,
1082
+ ...(founding.endpoint !== undefined ? { audience: founding.endpoint } : {}),
1083
+ });
1084
+ }
1085
+ catch (error) {
1086
+ // A guest key an earlier link retired: only that link's own user
1087
+ // gets an answer (the retry of a link whose response was lost).
1088
+ if (error.status !== 403 || !(await userIs(account)))
1089
+ throw error;
1090
+ guestRevoked = true;
1091
+ }
1092
+ if (!guestRevoked) {
1093
+ try {
1094
+ await adminAccounts("link", { from: guest, to: identity(user.userId), nonce });
1095
+ }
1096
+ catch (error) {
1097
+ // Linking is idempotent for this guest and this user: when the user
1098
+ // already belongs to the guest's account (an earlier link went
1099
+ // through, then perhaps its revoke failed, or another tab's link
1100
+ // won the race and revoked the key since), this link is done. A
1101
+ // used challenge (the core refuses its nonce first) and a user of
1102
+ // another account are still refused.
1103
+ const status = error.status;
1104
+ if ((status !== 409 && status !== 403) || !(await userIs(account)))
1105
+ throw error;
1106
+ // Refused for a retired key: the link that won already retired it.
1107
+ if (status === 403)
1108
+ guestRevoked = true;
1109
+ }
1110
+ }
1111
+ }
1112
+ catch (error) {
1113
+ const status = error.status;
1114
+ // Only the core's own refusals refuse the link for good: an invalid
1115
+ // link intent (400), a retired or foreign identity (403), a user with
1116
+ // no account to check (404), an identity of another account (409).
1117
+ // Its reason stays on the backend.
1118
+ if (status === 400 || status === 403 || status === 404 || status === 409)
1119
+ return new Response("link_refused", { status: 409 });
1120
+ // Anything else (the core down or failing, its credential check
1121
+ // refusing this backend mid-rotation, a proxy's 408 or 429) may pass on
1122
+ // a retry, so say so rather than strand the guest.
1123
+ console.error("Jazz: linking a guest failed on the core", error);
1124
+ return new Response("account_registry_unavailable", { status: 503 });
1125
+ }
1126
+ if (options.guestKeyAfterLink === "revoke" && !guestRevoked) {
1127
+ // The link already stands. If the revoke fails, the guest key stays
1128
+ // usable until the browser retries the link, which is idempotent and
1129
+ // revokes then: a server error, logged here, not a silent success.
1130
+ const revoked = await core.handle("POST", `/apps/${encodeURIComponent(accountAppId(appId))}/admin/accounts/revoke`, [
1131
+ ["x-jazz-admin-secret", core.adminSecret],
1132
+ ["content-type", "application/json"],
1133
+ ], new TextEncoder().encode(JSON.stringify({ approver: identity(user.userId), target: guest })), "admin");
1134
+ if (revoked.status !== 204) {
1135
+ console.error(`Jazz: revoking the guest key after a link failed (${revoked.status}): ${new TextDecoder().decode(revoked.body)}`);
1136
+ return new Response("guest_key_revoke_failed", { status: 500 });
1137
+ }
1138
+ }
1139
+ const expiresAt = Math.floor(Date.now() / 1000) + (options.sessionTtlSeconds ?? 3600);
1140
+ return Response.json({ account, identity: identity(user.userId), claims: user.claims ?? {}, expiresAt }, { headers: { "Cache-Control": "no-store" } });
1141
+ }
1142
+ function openClientSession(request, onEvent) {
1143
+ // The core socket opens once the prelude is admitted, with the access
1144
+ // that admission needs: a vouched user's session is the backend's, and
1145
+ // so is the endpoint it vouches for on a guest's behalf; a guest signed
1146
+ // for the app itself rides on its own token alone.
1147
+ let socket;
1148
+ let ended = false;
1149
+ let userId;
1150
+ let trusted = false;
1151
+ let recheck;
1152
+ // A session that never sends its prelude ends too.
1153
+ let expiry = setTimeout(() => {
1154
+ onEvent(null, { kind: "close", code: 1008, reason: "no sign-in in time" });
1155
+ end();
1156
+ }, PRELUDE_DEADLINE_MS);
1157
+ expiry.unref?.();
1158
+ const end = () => {
1159
+ if (ended)
1160
+ return;
1161
+ ended = true;
1162
+ if (expiry)
1163
+ clearTimeout(expiry);
1164
+ recheck?.();
1165
+ socket?.close();
1166
+ };
1167
+ const admit = async (prelude) => {
1168
+ const admitted = await admitPrelude(request, prelude);
1169
+ if (!admitted || ended) {
1170
+ // An auth failure, not a dropped link: the client stops retrying and
1171
+ // reports `offline: auth`, and its session asks the backend whether
1172
+ // anyone is still signed in.
1173
+ if (!ended)
1174
+ onEvent(null, {
1175
+ kind: "message",
1176
+ data: authFailedBatch("session missing: not signed in"),
1177
+ });
1178
+ onEvent(null, { kind: "close", code: 1008, reason: "not signed in" });
1179
+ end();
1180
+ return false;
1181
+ }
1182
+ userId = admitted.userId;
1183
+ trusted = admitted.trusted;
1184
+ if (expiry)
1185
+ clearTimeout(expiry);
1186
+ // A backend client's session ends with its token, so it reconnects
1187
+ // with a fresh one.
1188
+ const ttl = Math.min((options.sessionTtlSeconds ?? 3600) * 1000, admitted.expiresAt === undefined ? Infinity : admitted.expiresAt * 1000 - Date.now());
1189
+ expiry = setTimeout(end, Math.max(ttl, 0));
1190
+ expiry.unref?.();
1191
+ const every = (options.recheckSeconds ?? 60) * 1000;
1192
+ // The socket's request carries the cookies it opened with, so a
1193
+ // refusal may only mean they expired. The client reconnects with fresh
1194
+ // ones; if no one is signed in, that admission fails as an auth
1195
+ // failure (above), and otherwise it carries the user's claims now.
1196
+ const authenticateAgain = () => {
1197
+ if (ended)
1198
+ return;
1199
+ onEvent(null, { kind: "close", code: 1008, reason: "authenticate again" });
1200
+ end();
1201
+ };
1202
+ const admittedUser = admitted.user;
1203
+ if (admittedUser && every > 0) {
1204
+ // Signed out, someone else, or the same user with other claims.
1205
+ recheck = recheckEvery(every, async () => isSameAdmission(admittedUser, await authenticate(request)), authenticateAgain);
1206
+ }
1207
+ else if (admitted.guest && every > 0) {
1208
+ // The app may stop letting guests in (or this one): ask again, as for users.
1209
+ recheck = recheckEvery(every, () => acceptsGuest(request), authenticateAgain);
1210
+ }
1211
+ socket = core.openSocket(headerPairs(request.headers), onEvent, admitted.access);
1212
+ return socket.send(admitted.prelude);
1213
+ };
1214
+ // Messages after the prelude wait for its admission, in order.
1215
+ let chain;
1216
+ // Bytes handed to `deliver` the core has not taken yet: a host that
1217
+ // doesn't wait for it (a socket that can't pause) is cut off past the
1218
+ // limit, as the core cuts off a peer that ignores flow control.
1219
+ let waitingBytes = 0;
1220
+ const deliver = (data) => {
1221
+ if (ended)
1222
+ return Promise.resolve(false);
1223
+ if (waitingBytes + data.byteLength > MAX_WAITING_SESSION_BYTES) {
1224
+ // 1013 (try again later): the client may come back and send at the
1225
+ // pace this host takes.
1226
+ onEvent(null, {
1227
+ kind: "close",
1228
+ code: 1013,
1229
+ reason: "client sent faster than the server takes",
1230
+ });
1231
+ end();
1232
+ return Promise.resolve(false);
1233
+ }
1234
+ waitingBytes += data.byteLength;
1235
+ const taken = (ok) => {
1236
+ waitingBytes -= data.byteLength;
1237
+ return ok;
1238
+ };
1239
+ chain = chain
1240
+ ? chain
1241
+ .then(async (ok) => {
1242
+ if (!ok || ended || !socket)
1243
+ return false;
1244
+ return socket.sendWithRoom ? socket.sendWithRoom(data) : socket.send(data);
1245
+ })
1246
+ .catch(() => {
1247
+ // A core that failed to take a message ends the session.
1248
+ onEvent(null, { kind: "close", code: 1011, reason: "session failed" });
1249
+ end();
1250
+ return false;
1251
+ })
1252
+ .then(taken)
1253
+ : admit(data)
1254
+ .catch((error) => {
1255
+ if (!ended && isRefusal(error)) {
1256
+ // The core refused this identity (revoked, local-first auth
1257
+ // disabled, invalid): an auth failure the client must not
1258
+ // retry, reported as a sign-in refusal is.
1259
+ onEvent(null, {
1260
+ kind: "message",
1261
+ data: authFailedBatch(`session refused: ${refusalCode(error)}`),
1262
+ });
1263
+ onEvent(null, { kind: "close", code: 1008, reason: "sign-in refused" });
1264
+ }
1265
+ else {
1266
+ // The core is unreachable or failed (5xx), or the app's own
1267
+ // `authenticate` threw: the client tries again later.
1268
+ onEvent(null, { kind: "close", code: 1011, reason: "admission failed" });
1269
+ }
1270
+ end();
1271
+ return false;
1272
+ })
1273
+ .then(taken);
1274
+ return chain;
1275
+ };
1276
+ return {
1277
+ send(data) {
1278
+ if (ended)
1279
+ return false;
1280
+ void deliver(data);
1281
+ return true;
1282
+ },
1283
+ deliver,
1284
+ close: end,
1285
+ get userId() {
1286
+ return userId;
1287
+ },
1288
+ get trusted() {
1289
+ return trusted;
1290
+ },
1291
+ };
1292
+ }
1293
+ /**
1294
+ * Turn a browser prelude into one the core admits on this backend's word:
1295
+ * the user `authenticate` finds on this request, with their account and
1296
+ * claims, vouched for with the backend secret. A local-first guest's
1297
+ * prelude passes through: the core verifies its self-signed token. Any
1298
+ * other credential, or a prelude naming another user, is refused.
1299
+ */
1300
+ async function admitPrelude(request, prelude) {
1301
+ let parsed;
1302
+ try {
1303
+ parsed = JSON.parse(new TextDecoder().decode(prelude));
1304
+ }
1305
+ catch {
1306
+ return null;
1307
+ }
1308
+ const auth = (parsed.auth && typeof parsed.auth === "object" ? parsed.auth : parsed);
1309
+ const client = await backendClients.resolve(request);
1310
+ if (client === "refused")
1311
+ return null;
1312
+ if (client?.kind === "backend") {
1313
+ // A trusted backend client syncs with this backend's authority: it
1314
+ // states a backend secret (any stand-in) and, to act for a user, that
1315
+ // user's session, as the main backend's own client does (the user's
1316
+ // policies then apply to those writes at the core). Never an admin
1317
+ // secret or a token of its own.
1318
+ for (const key of ["admin_secret", "jwt_token"]) {
1319
+ if (parsed[key] != null || auth[key] != null)
1320
+ return null;
1321
+ }
1322
+ if (parsed.backend_secret == null && auth.backend_secret == null)
1323
+ return null;
1324
+ const vouched = { backend_secret: core.backendSecret };
1325
+ const rewritten = { ...parsed, ...vouched, auth: { ...auth, ...vouched } };
1326
+ return {
1327
+ prelude: new TextEncoder().encode(JSON.stringify(rewritten)),
1328
+ userId: undefined,
1329
+ access: "backend",
1330
+ trusted: true,
1331
+ expiresAt: client.expiresAt,
1332
+ };
1333
+ }
1334
+ const others = ["backend_secret", "admin_secret", "backend_session"];
1335
+ // Browser worker transports send `jwt_token: null` alongside a backend
1336
+ // session; only a real token counts as one.
1337
+ const token = auth.jwt_token ?? parsed.jwt_token;
1338
+ if (token !== undefined && token !== null) {
1339
+ const localFirst = typeof token === "string" && parseJwtPayload(token)?.iss === LOCAL_FIRST_JWT_ISSUER;
1340
+ const alone = others.every((key) => parsed[key] == null && auth[key] == null);
1341
+ if (!localFirst || !alone || parsed.local_first_audience != null)
1342
+ return null;
1343
+ // A guest has no user here: its session is bound to its own key.
1344
+ if (client)
1345
+ return null;
1346
+ const audience = guestAudience(request, token);
1347
+ if (!audience)
1348
+ return null;
1349
+ // Guests are off unless the app's `authenticate` lets this one in.
1350
+ if (!(await acceptsGuest(request)))
1351
+ return null;
1352
+ if (audience.endpoint === undefined) {
1353
+ // Its own token decides who it is; the backend's secret only vouches
1354
+ // for the bundle this socket is pinned to (see `pinnedSocket`).
1355
+ const pinned = { ...parsed, auth: { ...auth, backend_secret: core.backendSecret } };
1356
+ return {
1357
+ prelude: new TextEncoder().encode(JSON.stringify(pinned)),
1358
+ userId: undefined,
1359
+ access: "session",
1360
+ trusted: false,
1361
+ guest: true,
1362
+ };
1363
+ }
1364
+ // Signed for this endpoint, which the core can't know: vouch for it.
1365
+ const vouched = {
1366
+ ...parsed,
1367
+ local_first_audience: audience.endpoint,
1368
+ auth: { ...auth, backend_secret: core.backendSecret },
1369
+ };
1370
+ // The backend's word on the endpoint needs backend access; the
1371
+ // guest's own token still decides who it is.
1372
+ return {
1373
+ prelude: new TextEncoder().encode(JSON.stringify(vouched)),
1374
+ userId: undefined,
1375
+ access: "backend",
1376
+ trusted: false,
1377
+ guest: true,
1378
+ };
1379
+ }
1380
+ const stated = auth.backend_session;
1381
+ if (!stated || typeof stated !== "object")
1382
+ return null;
1383
+ for (const credential of ["backend_secret", "admin_secret"]) {
1384
+ if (parsed[credential] != null || auth[credential] != null)
1385
+ return null;
1386
+ }
1387
+ const user = await authenticate(request);
1388
+ if (!user || user.userId !== stated.user_id)
1389
+ return null;
1390
+ // A browser states a user's session only once its sign-in (or link)
1391
+ // gave them an account; this never makes one.
1392
+ let session;
1393
+ try {
1394
+ session = await sessionFor(user, "a sync session");
1395
+ }
1396
+ catch (error) {
1397
+ if (error instanceof NoJazzAccountError)
1398
+ return null;
1399
+ throw error;
1400
+ }
1401
+ const vouched = { backend_secret: core.backendSecret, backend_session: session };
1402
+ const rewritten = { ...parsed, ...vouched, auth: { ...auth, ...vouched } };
1403
+ return {
1404
+ prelude: new TextEncoder().encode(JSON.stringify(rewritten)),
1405
+ userId: user.userId,
1406
+ user,
1407
+ access: "backend",
1408
+ trusted: false,
1409
+ expiresAt: client?.expiresAt,
1410
+ };
1411
+ }
1412
+ // HTTP stream sessions, by id, with the key that proves a request comes
1413
+ // from the client that opened them.
1414
+ const streams = new Map();
1415
+ // Sockets accepted for clients, so close() can end them.
1416
+ const clientSockets = new Set();
1417
+ function openStream(request) {
1418
+ const id = randomUUID();
1419
+ // The id goes in URLs (and so in logs); the key only in a header.
1420
+ const key = randomBytes(32);
1421
+ let controller;
1422
+ let closed = false;
1423
+ const end = (code, reason) => {
1424
+ if (closed)
1425
+ return;
1426
+ closed = true;
1427
+ streams.delete(id);
1428
+ try {
1429
+ controller.enqueue(encodeStreamClose(code, reason));
1430
+ controller.close();
1431
+ }
1432
+ catch {
1433
+ // The client already went away.
1434
+ }
1435
+ };
1436
+ const body = new ReadableStream({
1437
+ start(c) {
1438
+ controller = c;
1439
+ },
1440
+ cancel() {
1441
+ streams.get(id)?.session.close();
1442
+ end(1001, "client went away");
1443
+ },
1444
+ });
1445
+ let socket;
1446
+ try {
1447
+ socket = openClientSession(request, (error, event) => {
1448
+ if (error)
1449
+ return end(1011, error.message);
1450
+ if (event.kind === "message" && event.data) {
1451
+ if (!closed)
1452
+ controller.enqueue(encodeStreamRecord(STREAM_RECORD_MESSAGE, event.data));
1453
+ }
1454
+ else if (event.kind === "close") {
1455
+ end(event.code ?? 1000, event.reason ?? "");
1456
+ }
1457
+ });
1458
+ }
1459
+ catch (error) {
1460
+ return new Response(error instanceof Error ? error.message : String(error), { status: 503 });
1461
+ }
1462
+ streams.set(id, { session: socket, key, end });
1463
+ controller.enqueue(encodeStreamRecord(STREAM_RECORD_SESSION, new TextEncoder().encode(JSON.stringify({ id, key: key.toString("base64url") }))));
1464
+ return new Response(body, {
1465
+ headers: {
1466
+ "Content-Type": "application/octet-stream",
1467
+ "Cache-Control": "no-store",
1468
+ "X-Accel-Buffering": "no",
1469
+ },
1470
+ });
1471
+ }
1472
+ /**
1473
+ * The stream session `id`, when `request` comes from the client that
1474
+ * opened it (it carries the session's key) and, once the session is
1475
+ * admitted as a user, from that user still: a session id alone (which
1476
+ * can end up in logs) doesn't let anyone act in it, before admission or
1477
+ * for a guest either.
1478
+ */
1479
+ async function ownStream(id, request) {
1480
+ const entry = streams.get(id);
1481
+ if (!entry) {
1482
+ // Sessions live in the process that opened them.
1483
+ return new Response("unknown stream session: HTTP stream sessions need a single backend instance or sticky routing", { status: 404 });
1484
+ }
1485
+ const given = Buffer.from(request.headers.get(STREAM_KEY_HEADER) ?? "", "base64url");
1486
+ if (given.length !== entry.key.length || !timingSafeEqual(given, entry.key)) {
1487
+ return new Response("not this stream's client", { status: 403 });
1488
+ }
1489
+ const socket = entry.session;
1490
+ if (socket.trusted) {
1491
+ const client = await backendClients.resolve(request);
1492
+ if (client === null || client === "refused" || client.kind !== "backend") {
1493
+ return new Response("not this backend client", { status: 403 });
1494
+ }
1495
+ }
1496
+ else if (socket.userId !== undefined) {
1497
+ const user = await authenticate(request);
1498
+ if (user?.userId !== socket.userId)
1499
+ return new Response("not signed in", { status: 403 });
1500
+ }
1501
+ return socket;
1502
+ }
1503
+ /**
1504
+ * Pass a send's records to the session as they arrive, each once the core
1505
+ * has room for it: the body is not read ahead of the core, so a client
1506
+ * sending faster than the core takes is held back by the request itself.
1507
+ */
1508
+ async function streamSend(id, request) {
1509
+ const socket = await ownStream(id, request);
1510
+ if (socket instanceof Response)
1511
+ return socket;
1512
+ // A send's records go in whole and in order: one send at a time.
1513
+ if (sendingStreams.has(id)) {
1514
+ return new Response("a send to this stream is in progress", { status: 409 });
1515
+ }
1516
+ sendingStreams.add(id);
1517
+ try {
1518
+ return await passStreamRecords(socket, request);
1519
+ }
1520
+ finally {
1521
+ sendingStreams.delete(id);
1522
+ }
1523
+ }
1524
+ /** Stream sessions with a send in progress. */
1525
+ const sendingStreams = new Set();
1526
+ async function passStreamRecords(socket, request) {
1527
+ const refuse = (reason) => {
1528
+ socket.close();
1529
+ return new Response(reason, { status: 400 });
1530
+ };
1531
+ const records = new StreamRecordReader();
1532
+ const body = request.body?.getReader();
1533
+ for (;;) {
1534
+ const chunk = body ? await body.read() : { done: true, value: undefined };
1535
+ if (chunk.done)
1536
+ break;
1537
+ for (const record of records.push(chunk.value)) {
1538
+ if (record.kind !== STREAM_RECORD_MESSAGE ||
1539
+ record.payload.byteLength > MAX_STREAM_MESSAGE_BYTES) {
1540
+ void body?.cancel().catch(() => undefined);
1541
+ return refuse("invalid record");
1542
+ }
1543
+ if (!(await socket.deliver(record.payload))) {
1544
+ void body?.cancel().catch(() => undefined);
1545
+ return new Response("session ended", { status: 410 });
1546
+ }
1547
+ }
1548
+ // A record no message may be: refused before it is buffered.
1549
+ if (records.pending > 5 + MAX_STREAM_MESSAGE_BYTES) {
1550
+ void body?.cancel().catch(() => undefined);
1551
+ return refuse("invalid record");
1552
+ }
1553
+ }
1554
+ if (records.pending > 0)
1555
+ return refuse("truncated record");
1556
+ return new Response(null, { status: 204 });
1557
+ }
1558
+ /** Close codes a socket may send: 1005/1006/1015 only describe a close. */
1559
+ function sendableCloseCode(code) {
1560
+ if (code === undefined || code === 1005)
1561
+ return 1000;
1562
+ if (code === 1006 || code === 1015)
1563
+ return 1011;
1564
+ return code;
1565
+ }
1566
+ function acceptSocket(request, ws) {
1567
+ if (!originAllowed(request)) {
1568
+ ws.close(1008, "origin not allowed");
1569
+ return;
1570
+ }
1571
+ // A paused socket reads no close handshake: resume it to close.
1572
+ const close = (code, reason) => {
1573
+ ws.resume?.();
1574
+ ws.close(code, reason);
1575
+ };
1576
+ let socket;
1577
+ try {
1578
+ socket = openClientSession(request, (error, event) => {
1579
+ if (error)
1580
+ return close(1011, error.message);
1581
+ if (event.kind === "message" && event.data)
1582
+ ws.send(event.data);
1583
+ else if (event.kind === "close") {
1584
+ close(sendableCloseCode(event.code), event.reason ?? "");
1585
+ }
1586
+ });
1587
+ }
1588
+ catch (error) {
1589
+ close(1013, error instanceof Error ? error.message : String(error));
1590
+ return;
1591
+ }
1592
+ clientSockets.add(ws);
1593
+ // Messages go to the core in order, each once it has room; the socket
1594
+ // is not read while one waits, so a fast client is held back.
1595
+ let waiting = 0;
1596
+ ws.on("message", (data) => {
1597
+ waiting += 1;
1598
+ ws.pause?.();
1599
+ // `deliver` resolves false, never rejects, when the session fails.
1600
+ void socket.deliver(toBytes(data)).then((ok) => {
1601
+ waiting -= 1;
1602
+ if (!ok)
1603
+ close(1000, "session ended");
1604
+ else if (waiting === 0)
1605
+ ws.resume?.();
1606
+ });
1607
+ });
1608
+ ws.on("close", () => {
1609
+ clientSockets.delete(ws);
1610
+ socket.close();
1611
+ });
1612
+ ws.on("error", () => socket.close());
1613
+ }
1614
+ /**
1615
+ * Whether a browser on the request's origin may act as its user here.
1616
+ * Sign-in and sync ride the app's own session (usually a cookie), which a
1617
+ * browser also attaches to requests that other pages start, so a request
1618
+ * from another origin is refused: one with no Origin (a non-browser
1619
+ * client, which holds no ambient cookie) passes. The backend's own origin
1620
+ * is the host the request was sent to, as a proxy forwards it.
1621
+ */
1622
+ /** This process upgrades sockets for handle() and nodeHandler (set by attach()). */
1623
+ let upgradesSockets = options.upgradesSockets ?? false;
1624
+ let attached = false;
1625
+ function originAllowed(request) {
1626
+ const origin = request.headers.get("origin");
1627
+ if (origin === null) {
1628
+ const site = request.headers.get("sec-fetch-site");
1629
+ return site === null || site === "same-origin" || site === "none";
1630
+ }
1631
+ if (allowedOrigins.has(origin))
1632
+ return true;
1633
+ let parsed;
1634
+ try {
1635
+ parsed = new URL(origin);
1636
+ }
1637
+ catch {
1638
+ return false; // "null" (a sandboxed or opaque origin) or garbage
1639
+ }
1640
+ const requestHost = request.headers.get("x-forwarded-host")?.split(",")[0]?.trim() ||
1641
+ request.headers.get("host") ||
1642
+ new URL(request.url).host;
1643
+ if (parsed.host !== requestHost)
1644
+ return false;
1645
+ // A page over plain http may not act on a backend reached over https. The
1646
+ // other way round is allowed: a proxy that ends TLS may hand us plain http.
1647
+ const requestScheme = request.headers.get("x-forwarded-proto")?.split(",")[0]?.trim().toLowerCase() ||
1648
+ new URL(request.url).protocol.replace(/:$/, "");
1649
+ return !(requestScheme === "https" && parsed.protocol === "http:");
1650
+ }
1651
+ /**
1652
+ * A trusted backend client asks to sync as a backend (what a backend's
1653
+ * own client asks its core first). Only its token admits it: the core is
1654
+ * asked with this backend's secret. Anyone else gets the 404 this route
1655
+ * has without backend clients.
1656
+ */
1657
+ async function admitBackendClient(request) {
1658
+ const client = await backendClients.resolve(request);
1659
+ if (client === null)
1660
+ return new Response("Not found", { status: 404 });
1661
+ if (client === "refused" || client.kind !== "backend") {
1662
+ return new Response("not a trusted backend client", { status: 401 });
1663
+ }
1664
+ if (request.method !== "POST")
1665
+ return new Response(null, { status: 405 });
1666
+ const response = await core.handle("POST", `/apps/${encodeURIComponent(accountAppId(appId))}/backend/admit`, [["x-jazz-backend-secret", core.backendSecret]], new Uint8Array(0), "backend");
1667
+ return new Response(null, { status: response.status === 204 ? 204 : 502 });
1668
+ }
1669
+ /**
1670
+ * A trusted backend client asks for a user's session, to act for them
1671
+ * (`client.forUser`): the account `forReqUser` would act as for a request
1672
+ * of theirs. Never creates an account (see `createAccountFor`). Anyone but
1673
+ * a trusted machine gets what `admitBackendClient` gives them.
1674
+ */
1675
+ async function backendClientUserSession(request) {
1676
+ const client = await backendClients.resolve(request);
1677
+ if (client === null)
1678
+ return new Response("Not found", { status: 404 });
1679
+ if (client === "refused" || client.kind !== "backend") {
1680
+ return new Response("not a trusted backend client", { status: 401 });
1681
+ }
1682
+ if (request.method !== "POST")
1683
+ return new Response(null, { status: 405 });
1684
+ let userId;
1685
+ try {
1686
+ ({ userId } = (await request.json()));
1687
+ }
1688
+ catch {
1689
+ return new Response("expected a JSON body", { status: 400 });
1690
+ }
1691
+ if (typeof userId !== "string" || userId === "") {
1692
+ return new Response("userId must be a non-empty string", { status: 400 });
1693
+ }
1694
+ let account;
1695
+ try {
1696
+ account = await existingAccountOf(userId);
1697
+ }
1698
+ catch (error) {
1699
+ // The core refuses this identity (it was revoked): say so, as
1700
+ // `backendUser` does, rather than fail as a server error.
1701
+ if (error.status === 403)
1702
+ return Response.json({ code: "identity_not_authorized" }, { status: 403 });
1703
+ throw error;
1704
+ }
1705
+ const noStore = { "Cache-Control": "no-store" };
1706
+ if (account === null)
1707
+ return Response.json({ code: "no_account" }, { status: 404, headers: noStore });
1708
+ return Response.json({ account, issuer }, { headers: noStore });
1709
+ }
1710
+ /**
1711
+ * The endpoint URLs a browser may have named this backend by, as its client
1712
+ * scope (see `clientScope`): the page's origin when it is one this backend
1713
+ * serves, and this request's own host, each with `basePath`.
1714
+ */
1715
+ function endpointAudiences(request) {
1716
+ if (publicUrls.length)
1717
+ return publicUrls;
1718
+ const audiences = new Set();
1719
+ // The page origin when it is this Host or an allowed origin, and this
1720
+ // Host. A browser can't forge Host, but a caller reaching this backend
1721
+ // directly can, so production backends should set `publicUrl`.
1722
+ // X-Forwarded-Host is never read here.
1723
+ const url = new URL(request.url);
1724
+ const host = request.headers.get("host") || url.host;
1725
+ const forwardedProto = request.headers
1726
+ .get("x-forwarded-proto")
1727
+ ?.split(",")[0]
1728
+ ?.trim()
1729
+ .toLowerCase();
1730
+ const scheme = forwardedProto === "https" || url.protocol === "https:" ? "https" : "http";
1731
+ const origin = request.headers.get("origin");
1732
+ if (origin) {
1733
+ try {
1734
+ const parsed = new URL(origin);
1735
+ if (allowedOrigins.has(parsed.origin) || parsed.host === host)
1736
+ audiences.add(`${parsed.origin}${basePath}`);
1737
+ }
1738
+ catch {
1739
+ // Not an origin a page has.
1740
+ }
1741
+ }
1742
+ try {
1743
+ audiences.add(`${new URL(`${scheme}://${host}`).origin}${basePath}`);
1744
+ }
1745
+ catch {
1746
+ // A host header no URL takes.
1747
+ }
1748
+ return [...audiences];
1749
+ }
1750
+ const warnedAudiences = new Set();
1751
+ let warnedHeaderAudience = false;
1752
+ /** Say once per audience why a guest's proof was refused, so a proxy mismatch is visible. */
1753
+ function warnUnknownAudience(token, accepted, isAudience = false) {
1754
+ const audience = isAudience ? token : parseJwtPayload(token)?.aud;
1755
+ const named = typeof audience === "string" ? audience : JSON.stringify(audience);
1756
+ if (warnedAudiences.has(named) || warnedAudiences.size > 100)
1757
+ return;
1758
+ warnedAudiences.add(named);
1759
+ console.warn(`createJazz: refused a local-first guest whose proof is for ${named}; this endpoint accepts ${JSON.stringify([appId, ...accepted])}. If browsers reach Jazz through a proxy that changes the host or path, set publicUrl to the URL they use.`);
1760
+ }
1761
+ /**
1762
+ * What a guest's local-first proof is for: this app (an app whose browser
1763
+ * clients still name its id, or carry it as their `scope`), one of this
1764
+ * endpoint's URLs, or neither (null).
1765
+ */
1766
+ function guestAudience(request, token) {
1767
+ try {
1768
+ verifyLocalFirstToken(token, appId);
1769
+ return {};
1770
+ }
1771
+ catch {
1772
+ // Not this app's id; try the endpoint.
1773
+ }
1774
+ const endpoints = endpointAudiences(request);
1775
+ for (const endpoint of endpoints) {
1776
+ try {
1777
+ verifyLocalFirstToken(token, endpoint);
1778
+ if (!publicUrls.length && !warnedHeaderAudience && !isLocalEndpoint(endpoint)) {
1779
+ warnedHeaderAudience = true;
1780
+ console.warn(`createJazz: vouched for a local-first guest of ${endpoint}, taken from the request's headers. Set publicUrl to the URL browsers use so a caller can't name another host.`);
1781
+ }
1782
+ return { endpoint };
1783
+ }
1784
+ catch {
1785
+ // Not this one.
1786
+ }
1787
+ }
1788
+ warnUnknownAudience(token, endpoints);
1789
+ return null;
1790
+ }
1791
+ /**
1792
+ * The namespace a linking guest names for its account: this app (no
1793
+ * audience, or the app's id), one of this endpoint's URLs, or neither (null).
1794
+ */
1795
+ function linkAudience(request, audience) {
1796
+ // Tokens name their audience as given or as its app id (a UUID).
1797
+ const names = (value) => audience === value || audience === accountAppId(value);
1798
+ if (audience === undefined || (typeof audience === "string" && names(appId)))
1799
+ return {};
1800
+ if (typeof audience !== "string")
1801
+ return null;
1802
+ const endpoints = endpointAudiences(request);
1803
+ const endpoint = endpoints.find(names);
1804
+ if (endpoint !== undefined)
1805
+ return { endpoint };
1806
+ warnUnknownAudience(audience, endpoints, true);
1807
+ return null;
1808
+ }
1809
+ /** The path below `basePath`, or null for a request Jazz doesn't serve. */
1810
+ function innerPath(request) {
1811
+ const { pathname } = new URL(request.url);
1812
+ if (pathname === basePath)
1813
+ return "/";
1814
+ if (!pathname.startsWith(`${basePath}/`))
1815
+ return null;
1816
+ return pathname.slice(basePath.length);
1817
+ }
1818
+ /**
1819
+ * Answer `request`. `upgrades`: whether the handler it came through
1820
+ * upgrades sockets on this host, which decides what a plain request for
1821
+ * the socket path is told.
1822
+ */
1823
+ async function handle(request, upgrades = upgradesSockets) {
1824
+ try {
1825
+ return await route(request, upgrades);
1826
+ }
1827
+ catch (error) {
1828
+ if (!(error instanceof BackendClientsUnavailable))
1829
+ throw error;
1830
+ // The reason stays in the backend's logs.
1831
+ console.error(error);
1832
+ return new Response("backend client keys unavailable", {
1833
+ status: 503,
1834
+ headers: { "Retry-After": "5" },
1835
+ });
1836
+ }
1837
+ }
1838
+ async function route(request, upgrades) {
1839
+ const path = innerPath(request);
1840
+ if (path === null)
1841
+ return new Response("Not found", { status: 404 });
1842
+ if (request.method !== "GET" && request.method !== "HEAD" && !originAllowed(request)) {
1843
+ return new Response("origin not allowed", { status: 403 });
1844
+ }
1845
+ if (/^\/apps\/[^/]+\/accounts\/backend-sign-in$/.test(path)) {
1846
+ return backendSignIn(request);
1847
+ }
1848
+ if (/^\/apps\/[^/]+\/accounts\/backend-user$/.test(path)) {
1849
+ return backendUser(request);
1850
+ }
1851
+ if (/^\/apps\/[^/]+\/backend\/admit$/.test(path)) {
1852
+ return admitBackendClient(request);
1853
+ }
1854
+ if (/^\/apps\/[^/]+\/backend\/user-session$/.test(path)) {
1855
+ return backendClientUserSession(request);
1856
+ }
1857
+ if (/^\/apps\/[^/]+\/accounts\/backend-link$/.test(path)) {
1858
+ return backendLink(request);
1859
+ }
1860
+ if (/^\/apps\/[^/]+\/accounts\/backend-link\/challenge$/.test(path)) {
1861
+ return backendLinkChallenge(request);
1862
+ }
1863
+ const stream = /^\/apps\/[^/]+\/stream(?:\/([^/]+))?$/.exec(path);
1864
+ if (stream) {
1865
+ const id = stream[1] && decodeURIComponent(stream[1]);
1866
+ if (!id && request.method === "POST")
1867
+ return openStream(request);
1868
+ if (id && request.method === "POST")
1869
+ return streamSend(id, request);
1870
+ if (id && request.method === "DELETE") {
1871
+ const socket = await ownStream(id, request);
1872
+ if (socket instanceof Response)
1873
+ return socket;
1874
+ socket.close();
1875
+ return new Response(null, { status: 204 });
1876
+ }
1877
+ return new Response(null, { status: 405 });
1878
+ }
1879
+ if (path.endsWith("/ws")) {
1880
+ // A plain request for the socket path: the browser client asks this
1881
+ // after a socket failed before it opened. Where this host upgrades
1882
+ // sockets (attach(), or Vercel), that failure was transient (a
1883
+ // restart, a draining instance) and the client should retry the
1884
+ // socket. Only where it can't does the marker send it to the stream
1885
+ // at once; the client also switches after several failed sockets in
1886
+ // a row, when something in between doesn't pass upgrades on. It asks
1887
+ // with a POST, so a page origin the socket was refused for is refused
1888
+ // here too (403, above), and not taken for a proxy's doing.
1889
+ if (upgrades) {
1890
+ return new Response("Upgrade to a WebSocket", { status: 426 });
1891
+ }
1892
+ return new Response("WebSocket upgrade not available here; use the HTTP stream", {
1893
+ status: 426,
1894
+ headers: { [STREAM_AVAILABLE_HEADER]: "1" },
1895
+ });
1896
+ }
1897
+ if (!PUBLIC_APP_ROUTES.test(path))
1898
+ return new Response("Not found", { status: 404 });
1899
+ const url = new URL(request.url);
1900
+ const body = request.method === "GET" || request.method === "HEAD"
1901
+ ? Buffer.alloc(0)
1902
+ : Buffer.from(await request.arrayBuffer());
1903
+ const headers = headerPairs(request.headers);
1904
+ // A browser names the app however its scope does; the core knows it by id.
1905
+ const corePath = path.replace(/^\/apps\/[^/]+/, `/apps/${encodeURIComponent(appId)}`);
1906
+ return coreResponse(await core.handle(request.method, corePath + url.search, store.kind === "remote" || store.kind === "vercel"
1907
+ ? headers.filter(([name]) => REMOTE_FORWARDED_HEADERS.includes(name.toLowerCase()))
1908
+ : headers, body));
1909
+ }
1910
+ async function nextHandler(request) {
1911
+ const path = innerPath(request);
1912
+ if (request.method === "GET" &&
1913
+ path?.endsWith("/ws") &&
1914
+ request.headers.get("upgrade")?.toLowerCase() === "websocket" &&
1915
+ onVercelHost()) {
1916
+ if (!originAllowed(request))
1917
+ return new Response("origin not allowed", { status: 403 });
1918
+ // An optional peer: a literal import inside `try`, so bundlers report
1919
+ // a missing one at runtime, not on every route (see importSandboxSdk).
1920
+ let vercelFunctions;
1921
+ try {
1922
+ vercelFunctions = (await import(
1923
+ /* @vite-ignore */ "@vercel/functions"));
1924
+ }
1925
+ catch (error) {
1926
+ throw optionalPeerImportError("Jazz on Vercel", "@vercel/functions", error);
1927
+ }
1928
+ const { upgradeWebSocket } = vercelFunctions;
1929
+ // The socket ends with this invocation, at the route's maxDuration:
1930
+ // close it just before, so the client reconnects without a stall.
1931
+ const deadline = vercelFunctions.getDeadline?.()?.getTime();
1932
+ return upgradeWebSocket((ws) => acceptSocket(request, deadline === undefined ? ws : closingBeforeDeadline(ws, deadline)), { maxPayload: MAX_STREAM_MESSAGE_BYTES });
1933
+ }
1934
+ // On Vercel this handler upgrades sockets (above); elsewhere (next dev)
1935
+ // only if attach() runs on the same server.
1936
+ return handle(request, upgradesSockets || onVercelHost());
1937
+ }
1938
+ function nodeRequest(req) {
1939
+ const host = req.headers.host ?? "localhost";
1940
+ const headers = new Headers();
1941
+ for (const [name, value] of Object.entries(req.headers)) {
1942
+ if (value === undefined)
1943
+ continue;
1944
+ for (const item of Array.isArray(value) ? value : [value])
1945
+ headers.append(name, item);
1946
+ }
1947
+ const hasBody = req.method !== "GET" && req.method !== "HEAD";
1948
+ // A body parser mounted before nodeHandler (express.json(), express.raw())
1949
+ // has read the stream already: its buffer is the body, or nothing is.
1950
+ const parsed = req.body;
1951
+ // No bytes to read: what a parser made of nothing (`{}`) doesn't matter.
1952
+ const empty = req.headers["content-length"] === "0" ||
1953
+ (req.headers["content-length"] === undefined &&
1954
+ req.headers["transfer-encoding"] === undefined);
1955
+ const json = /^application\/json\b/i.test(req.headers["content-type"] ?? "");
1956
+ let body;
1957
+ if (hasBody && req.readableEnded) {
1958
+ if (parsed instanceof Uint8Array) {
1959
+ body = parsed;
1960
+ }
1961
+ else if (empty) {
1962
+ body = undefined;
1963
+ }
1964
+ else if (json && parsed !== null && typeof parsed === "object") {
1965
+ // express.json()'s result: Jazz's JSON routes read it as JSON again
1966
+ // (none signs its bytes), so it serves as the body.
1967
+ body = JSON.stringify(parsed);
1968
+ headers.delete("content-length");
1969
+ }
1970
+ else {
1971
+ throw new Error("jazz: the request body was already read by another handler; mount jazz.nodeHandler before body parsers such as express.json()");
1972
+ }
1973
+ }
1974
+ else if (hasBody) {
1975
+ body = req;
1976
+ }
1977
+ return new Request(`http://${host}${req.url ?? "/"}`, {
1978
+ method: req.method,
1979
+ headers,
1980
+ ...(body === undefined ? {} : { body, duplex: "half" }),
1981
+ });
1982
+ }
1983
+ function nodeHandler(req, res, next) {
1984
+ // Only Jazz's own paths: a request for the app passes on untouched, its
1985
+ // body unread, whatever read it before.
1986
+ const pathname = requestPathname(req.url);
1987
+ if (pathname === null || (pathname !== basePath && !pathname.startsWith(`${basePath}/`))) {
1988
+ if (next)
1989
+ return next();
1990
+ res.statusCode = 404;
1991
+ res.end();
1992
+ return;
1993
+ }
1994
+ let request;
1995
+ try {
1996
+ request = nodeRequest(req);
1997
+ }
1998
+ catch (error) {
1999
+ console.error(error instanceof Error ? error.message : error);
2000
+ // A code the client reports, so the browser doesn't fail silently.
2001
+ res.statusCode = 500;
2002
+ res.end("request_body_already_read");
2003
+ return;
2004
+ }
2005
+ void handle(request).then(async (response) => {
2006
+ res.statusCode = response.status;
2007
+ response.headers.forEach((value, name) => res.setHeader(name, value));
2008
+ if (!response.body)
2009
+ return void res.end();
2010
+ res.flushHeaders();
2011
+ const reader = response.body.getReader();
2012
+ res.on("close", () => void reader.cancel().catch(() => undefined));
2013
+ for (;;) {
2014
+ const { done, value } = await reader.read();
2015
+ if (done)
2016
+ break;
2017
+ res.write(value);
2018
+ }
2019
+ res.end();
2020
+ }, (error) => {
2021
+ // The reason stays in the backend's logs, not in the response.
2022
+ console.error("jazz: request failed", error);
2023
+ res.statusCode = 500;
2024
+ res.end("Internal error");
2025
+ });
2026
+ }
2027
+ function upgrade(wss, req, socket, head) {
2028
+ let request;
2029
+ try {
2030
+ request = nodeRequest(req);
2031
+ }
2032
+ catch {
2033
+ // A request no URL can be made of (a bad Host header).
2034
+ socket.end(BAD_UPGRADE);
2035
+ return;
2036
+ }
2037
+ const path = innerPath(request);
2038
+ if (path === null || !SOCKET_PATH.test(path))
2039
+ return void socket.end(BAD_UPGRADE);
2040
+ if (!originAllowed(request)) {
2041
+ socket.end("HTTP/1.1 403 Forbidden\r\nConnection: close\r\n\r\n");
2042
+ return;
2043
+ }
2044
+ wss.handleUpgrade(req, socket, head, (ws) => acceptSocket(request, ws));
2045
+ }
2046
+ function markAttached() {
2047
+ upgradesSockets = true;
2048
+ attached = true;
2049
+ }
2050
+ let closing;
2051
+ return {
2052
+ appId,
2053
+ get basePath() {
2054
+ return basePath;
2055
+ },
2056
+ reload,
2057
+ handle: (request) => handle(request),
2058
+ next: () => ({ GET: nextHandler, POST: nextHandler, DELETE: nextHandler }),
2059
+ upgrade,
2060
+ markAttached,
2061
+ nodeHandler,
2062
+ acceptSocket,
2063
+ get db() {
2064
+ return backend.db;
2065
+ },
2066
+ linkIdentity,
2067
+ async forReqUser(request) {
2068
+ const user = await authenticate(request);
2069
+ if (!user)
2070
+ throw signedOut("forReqUser");
2071
+ return backendDbForSession(backend, await sessionFor(user, "forReqUser"));
2072
+ },
2073
+ async withAttribution(request) {
2074
+ const user = await authenticate(request);
2075
+ if (!user)
2076
+ throw signedOut("withAttribution");
2077
+ return backendDbAttributedTo(backend, await sessionFor(user, "withAttribution"));
2078
+ },
2079
+ async accountFor(request) {
2080
+ const user = await authenticate(request);
2081
+ return user ? await existingAccountOf(user.userId) : null;
2082
+ },
2083
+ async createAccountFor(userId) {
2084
+ if (typeof userId !== "string" || userId === "")
2085
+ throw new Error("createAccountFor: pass the user's id, as your authenticate names it");
2086
+ return accountOf(userId);
2087
+ },
2088
+ close() {
2089
+ closing ??= (async () => {
2090
+ // Every client connection ends, so the host's own shutdown (which
2091
+ // waits for the connections it serves) can finish, and the clients
2092
+ // reconnect to whichever instance serves next.
2093
+ for (const stream of [...streams.values()]) {
2094
+ stream.session.close();
2095
+ stream.end(1012, "server shutting down");
2096
+ }
2097
+ streams.clear();
2098
+ for (const ws of [...clientSockets]) {
2099
+ ws.resume?.();
2100
+ ws.close(1012, "server shutting down");
2101
+ }
2102
+ clientSockets.clear();
2103
+ await Promise.all([...retiring].map((close) => close()));
2104
+ // Writes that resolved at the "local" tier may still be on their way
2105
+ // to the core. Hand them over before closing it, so a close right
2106
+ // after a write never loses it.
2107
+ const timer = setTimeout(() => backend.db.abortGracefulShutdown(), CLOSE_SYNC_TIMEOUT_MS);
2108
+ await backend
2109
+ .shutdown({ waitForSync: true })
2110
+ .catch((error) => {
2111
+ console.warn("Jazz backend closed before every write reached the core.", error);
2112
+ })
2113
+ .finally(() => clearTimeout(timer));
2114
+ await session.close();
2115
+ await core.close();
2116
+ })();
2117
+ return closing;
2118
+ },
2119
+ };
2120
+ }
2121
+ /**
2122
+ * Run Jazz inside your backend. It applies the schema, migrations and
2123
+ * permissions your code declares to its core (in this process, or a remote
2124
+ * one), and serves sync on your own origin under `basePath`. There is no
2125
+ * separate deploy step: a rollback of your backend rolls Jazz back with it.
2126
+ *
2127
+ * It opens nothing when called, so a module can export it at its top level:
2128
+ * the store opens on first use (a request, a `db` call, `ready()`). A process
2129
+ * runs one Jazz per store (a `sqlite()` directory, a `vercel()` core): a
2130
+ * later `createJazz` for it (a dev server's hot reload, another module
2131
+ * graph) returns that same Jazz with the later
2132
+ * call's app, permissions and options. Each `remote()` and `memory()` store
2133
+ * is its own: a module that hot reloads keeps that Jazz across reloads
2134
+ * itself, or closes it.
2135
+ */
2136
+ export function createJazz(options) {
2137
+ jazzSettings(options);
2138
+ const store = runningStore(options.store);
2139
+ const key = storeKey(store);
2140
+ const entries = registry();
2141
+ const shared = key === undefined ? undefined : entries.get(key);
2142
+ if (shared && !shared.closing) {
2143
+ adoptStore(shared, store);
2144
+ shared.options = options;
2145
+ return shared.jazz;
2146
+ }
2147
+ // A Jazz for this store still closing: the new one opens once it let go.
2148
+ const entry = newEntry(options, store, key, shared?.released);
2149
+ if (key !== undefined)
2150
+ entries.set(key, entry);
2151
+ return entry.jazz;
2152
+ }
2153
+ /** How long a session a reload replaced stays open for the requests still using it. */
2154
+ const RETIRED_SESSION_GRACE_MS = 60_000;
2155
+ /** How long `close()` waits for a store still opening before it gives up on it. */
2156
+ export const CLOSE_WAITS_FOR_OPEN_MS = 30_000;
2157
+ /** A failed open is tried again after this, doubling up to `MAX_OPEN_RETRY_MS`. */
2158
+ const FIRST_OPEN_RETRY_MS = 1_000;
2159
+ const MAX_OPEN_RETRY_MS = 30_000;
2160
+ /** At most this many sockets wait for the store to open, each holding at most this much. */
2161
+ export const MAX_HELD_SOCKETS = 1_000;
2162
+ export const MAX_HELD_SOCKET_BYTES = 4 * 1024 * 1024;
2163
+ const REGISTRY = Symbol.for("jazz-tools.createJazz.stores");
2164
+ /**
2165
+ * Open stores by key, on `globalThis` so that two copies of this module
2166
+ * (a bundler's server and route chunks, a hot reload) share them.
2167
+ */
2168
+ function registry() {
2169
+ const scope = globalThis;
2170
+ return (scope[REGISTRY] ??= new Map());
2171
+ }
2172
+ /**
2173
+ * The store's identity in this process: one Jazz runs per store, so a hot
2174
+ * reload finds the one it opened. A `remote()` store has none: two
2175
+ * backends (deployments, tests) may each run their own Jazz on one remote
2176
+ * app, with their own permissions. Nor has a `memory()` store, a new,
2177
+ * empty database each time. A module that hot reloads keeps such a Jazz
2178
+ * across reloads itself (on `globalThis`), or closes it.
2179
+ */
2180
+ function storeKey(store) {
2181
+ if (store.kind === "sqlite")
2182
+ return `sqlite:${resolve(store.path)}`;
2183
+ if (store.kind === "vercel") {
2184
+ const project = store.options.credentials?.projectId ?? process.env.VERCEL_PROJECT_ID;
2185
+ let name = store.options.name;
2186
+ try {
2187
+ name ??= project ? defaultCoreName(project, process.env) : undefined;
2188
+ }
2189
+ catch {
2190
+ // A preview without a branch: its open reports that, not createJazz.
2191
+ }
2192
+ // Without a name the core is unknown: its open reports that.
2193
+ return name ? `vercel:${name}` : undefined;
2194
+ }
2195
+ return undefined;
2196
+ }
2197
+ /**
2198
+ * What a store's settings are. The functions it holds (a credential hook)
2199
+ * are not settings: the open store calls the latest call's. A Sandbox SDK
2200
+ * is: another one is another setting.
2201
+ */
2202
+ function storeSettings(store) {
2203
+ return JSON.stringify(store, (name, value) => {
2204
+ if (name === "sdk" && value !== undefined)
2205
+ return `sdk#${identity(value)}`;
2206
+ return typeof value === "function" ? "function" : value;
2207
+ });
2208
+ }
2209
+ const identities = new WeakMap();
2210
+ let lastIdentity = 0;
2211
+ function identity(value) {
2212
+ let id = identities.get(value);
2213
+ if (id === undefined)
2214
+ identities.set(value, (id = ++lastIdentity));
2215
+ return id;
2216
+ }
2217
+ /**
2218
+ * The entry's store, its function settings (a credential hook) calling
2219
+ * through to the latest `createJazz` call's, so a reload applies them.
2220
+ */
2221
+ function liveStore(entry) {
2222
+ const through = (value, current) => {
2223
+ const out = { ...value };
2224
+ for (const [name, field] of Object.entries(value)) {
2225
+ if (typeof field !== "function")
2226
+ continue;
2227
+ out[name] = (...args) => {
2228
+ const latest = current()?.[name];
2229
+ return (typeof latest === "function" ? latest : field)(...args);
2230
+ };
2231
+ }
2232
+ return out;
2233
+ };
2234
+ const store = entry.store;
2235
+ if (store.kind === "vercel") {
2236
+ return {
2237
+ ...store,
2238
+ options: through(store.options, () => entry.store.kind === "vercel" ? entry.store.options : undefined),
2239
+ };
2240
+ }
2241
+ return through(store, () => entry.store);
2242
+ }
2243
+ /**
2244
+ * A later `createJazz` for an entry's store. Before the store opens it takes
2245
+ * the new settings; once open, settings that would need another core are
2246
+ * refused, so a change never silently goes unapplied.
2247
+ */
2248
+ function adoptStore(entry, store) {
2249
+ if (!entry.opening && !entry.opened) {
2250
+ entry.store = store;
2251
+ // A later call (a hot reload after a fix) tries the open again at once.
2252
+ entry.failure = undefined;
2253
+ return;
2254
+ }
2255
+ if (storeSettings(store) !== storeSettings(entry.store)) {
2256
+ throw new Error(`createJazz(): ${entry.key} is already open in this process with other store settings; restart the process to change them`);
2257
+ }
2258
+ // The same settings: its function settings are the latest call's now.
2259
+ entry.store = store;
2260
+ }
2261
+ function newEntry(options, store, key, after) {
2262
+ const entry = { key, store, options, after };
2263
+ entry.jazz = facade(entry);
2264
+ return entry;
2265
+ }
2266
+ /**
2267
+ * The entry's open Jazz, with the latest call's options applied. Once it is
2268
+ * closing, only `draining` (the writes made before the close) still gets it.
2269
+ */
2270
+ async function settled(entry, draining = false) {
2271
+ for (;;) {
2272
+ if (entry.closing && !draining)
2273
+ throw new Error("createJazz: this Jazz was closed");
2274
+ const opened = await (entry.opening ?? openEntry(entry));
2275
+ if (entry.closing && !draining)
2276
+ throw new Error("createJazz: this Jazz was closed");
2277
+ if (entry.applied === entry.options)
2278
+ return opened;
2279
+ await (entry.reloading ??= reloadEntry(entry, opened));
2280
+ }
2281
+ }
2282
+ /**
2283
+ * Open the entry's store. A failed open is not tried again at once: until
2284
+ * its backoff has passed, every use fails with the same error, so a store
2285
+ * that is down is not asked again on every request.
2286
+ */
2287
+ function openEntry(entry) {
2288
+ const failed = entry.failure;
2289
+ if (failed && Date.now() < failed.retryAt)
2290
+ return Promise.reject(failed.error);
2291
+ const options = entry.options;
2292
+ const opening = (async () => {
2293
+ await entry.after;
2294
+ return openJazz(options, liveStore(entry));
2295
+ })().then((opened) => {
2296
+ entry.failure = undefined;
2297
+ if (entry.attached)
2298
+ opened.markAttached();
2299
+ entry.opened = opened;
2300
+ entry.applied = options;
2301
+ drainOnSignal(entry);
2302
+ return opened;
2303
+ }, (error) => {
2304
+ const delayMs = failed
2305
+ ? Math.min(failed.delayMs * 2, MAX_OPEN_RETRY_MS)
2306
+ : FIRST_OPEN_RETRY_MS;
2307
+ entry.failure = { error, retryAt: Date.now() + delayMs, delayMs };
2308
+ if (entry.opening === opening)
2309
+ entry.opening = undefined;
2310
+ throw error;
2311
+ });
2312
+ entry.opening = opening;
2313
+ return opening;
2314
+ }
2315
+ /** The signals a host stops a server with (a deploy, a rolling restart, Ctrl-C). */
2316
+ const SHUTDOWN_SIGNALS = ["SIGTERM", "SIGINT"];
2317
+ /** Every open Jazz in this process, closed when the process is asked to stop. */
2318
+ const drained = new Set();
2319
+ const onShutdownSignal = (signal) => void shutDownOnSignal(signal);
2320
+ /**
2321
+ * Close every open Jazz when the process is asked to stop. A host's own
2322
+ * shutdown (`next start`, an Effect runtime, `server.close()`) waits for the
2323
+ * connections it serves, and Jazz's sync sockets and streams last until Jazz
2324
+ * ends them: without this, the process lingers and keeps its store locked
2325
+ * for as long as a browser stays connected. The clients reconnect to
2326
+ * whichever instance serves next. With no other handler for the signal the
2327
+ * process then stops as it would have; otherwise that handler decides.
2328
+ */
2329
+ function drainOnSignal(entry) {
2330
+ if (typeof process === "undefined" || typeof process.on !== "function")
2331
+ return;
2332
+ if (drained.size === 0) {
2333
+ for (const signal of SHUTDOWN_SIGNALS)
2334
+ process.on(signal, onShutdownSignal);
2335
+ }
2336
+ drained.add(entry);
2337
+ }
2338
+ function undrain(entry) {
2339
+ if (!drained.delete(entry) || drained.size > 0)
2340
+ return;
2341
+ for (const signal of SHUTDOWN_SIGNALS)
2342
+ process.off(signal, onShutdownSignal);
2343
+ }
2344
+ async function shutDownOnSignal(signal) {
2345
+ for (const each of SHUTDOWN_SIGNALS)
2346
+ process.off(each, onShutdownSignal);
2347
+ const open = [...drained];
2348
+ drained.clear();
2349
+ await Promise.allSettled(open.map((entry) => entry.jazz.close()));
2350
+ // Nobody else asked to handle it: stop the way the signal would have.
2351
+ if (process.listenerCount(signal) === 0)
2352
+ process.kill(process.pid, signal);
2353
+ }
2354
+ /**
2355
+ * Close the entry: apply the writes made before the close, then close its
2356
+ * store. A store still opening is waited for at most
2357
+ * `CLOSE_WAITS_FOR_OPEN_MS`; past that the writes still waiting fail and
2358
+ * the store closes once it has opened. Until it has, a new `createJazz` for
2359
+ * the store waits for it rather than finding the store held.
2360
+ */
2361
+ async function closeEntry(entry, early) {
2362
+ let release;
2363
+ entry.released = new Promise((resolve) => (release = resolve));
2364
+ const stopped = (async () => {
2365
+ await early.drain();
2366
+ const opened = await entry.opening?.catch(() => undefined);
2367
+ await entry.reloading?.catch(() => undefined);
2368
+ await opened?.close();
2369
+ })();
2370
+ void stopped
2371
+ .catch(() => undefined)
2372
+ .finally(() => {
2373
+ if (entry.key !== undefined && registry().get(entry.key) === entry) {
2374
+ registry().delete(entry.key);
2375
+ }
2376
+ undrain(entry);
2377
+ release();
2378
+ });
2379
+ let timer;
2380
+ const gaveUp = new Promise((resolve) => {
2381
+ timer = setTimeout(() => resolve(true), CLOSE_WAITS_FOR_OPEN_MS);
2382
+ });
2383
+ const late = await Promise.race([stopped.then(() => false), gaveUp]);
2384
+ clearTimeout(timer);
2385
+ if (!late)
2386
+ return;
2387
+ early.abandon(new Error("createJazz: closed before its store opened"));
2388
+ console.warn(`jazz: close() gave up after ${CLOSE_WAITS_FOR_OPEN_MS / 1000}s waiting for ${entry.key ?? "its store"} to open; it closes once it has`);
2389
+ }
2390
+ async function reloadEntry(entry, opened) {
2391
+ const options = entry.options;
2392
+ try {
2393
+ await opened.reload(options);
2394
+ entry.applied = options;
2395
+ }
2396
+ finally {
2397
+ entry.reloading = undefined;
2398
+ }
2399
+ }
2400
+ /** The entry's open Jazz when nothing is left to apply, without waiting. */
2401
+ function settledNow(entry) {
2402
+ return !entry.closing && entry.applied === entry.options ? entry.opened : undefined;
2403
+ }
2404
+ /**
2405
+ * A socket handed over before the store opened: it keeps what arrives until
2406
+ * the session takes it over, so no message is lost while it waits. Past
2407
+ * `MAX_HELD_SOCKET_BYTES` held, it is closed (1013, try again later).
2408
+ */
2409
+ function heldSocket(ws) {
2410
+ const held = [];
2411
+ let heldBytes = 0;
2412
+ let listeners = null;
2413
+ const deliver = (event) => {
2414
+ if (!listeners) {
2415
+ if (event[0] === "message") {
2416
+ heldBytes += byteLength(event[1]);
2417
+ if (heldBytes > MAX_HELD_SOCKET_BYTES) {
2418
+ held.length = 0;
2419
+ ws.close(1013, "store still opening");
2420
+ return;
2421
+ }
2422
+ }
2423
+ return void held.push(event);
2424
+ }
2425
+ if (event[0] === "message")
2426
+ listeners.message?.(event[1], event[2]);
2427
+ else if (event[0] === "close")
2428
+ listeners.close?.();
2429
+ else
2430
+ listeners.error?.(event[1]);
2431
+ };
2432
+ ws.on("message", (data, isBinary) => deliver(["message", data, isBinary]));
2433
+ ws.on("close", () => deliver(["close"]));
2434
+ ws.on("error", (error) => deliver(["error", error]));
2435
+ const socket = {
2436
+ send: (data) => ws.send(data),
2437
+ close: (code, reason) => ws.close(code, reason),
2438
+ pause: () => ws.pause?.(),
2439
+ resume: () => ws.resume?.(),
2440
+ on(event, listener) {
2441
+ const first = listeners === null;
2442
+ listeners ??= {};
2443
+ listeners[event] = listener;
2444
+ // The session adds its listeners in one go: replay once it has.
2445
+ if (first) {
2446
+ queueMicrotask(() => {
2447
+ for (const event of held.splice(0))
2448
+ deliver(event);
2449
+ });
2450
+ }
2451
+ return socket;
2452
+ },
2453
+ };
2454
+ return { socket, refuse: (reason) => ws.close(1011, reason) };
2455
+ }
2456
+ function byteLength(data) {
2457
+ if (typeof data === "string")
2458
+ return data.length * 3;
2459
+ if (Array.isArray(data))
2460
+ return data.reduce((sum, part) => sum + byteLength(part), 0);
2461
+ const sized = data;
2462
+ return typeof sized?.byteLength === "number" ? sized.byteLength : 0;
2463
+ }
2464
+ /**
2465
+ * A remote core that could not be reached, named, instead of the bare
2466
+ * `fetch failed` the request saw. The next use of this Jazz tries again.
2467
+ */
2468
+ function unreachableCore(url, error) {
2469
+ const cause = error?.cause;
2470
+ if (!(error instanceof TypeError) || !cause)
2471
+ return error;
2472
+ const why = typeof cause.code === "string" ? cause.code : String(cause.message ?? error.message);
2473
+ return new Error(`createJazz: could not reach the Jazz core at ${url} (${why}); this Jazz tries again on its next use`, { cause: error });
2474
+ }
2475
+ async function socketUpgrader() {
2476
+ const { WebSocketServer } = (await import("ws"));
2477
+ return new WebSocketServer({ noServer: true, maxPayload: MAX_STREAM_MESSAGE_BYTES });
2478
+ }
2479
+ /** A sync socket's path below `basePath`. */
2480
+ const SOCKET_PATH = /^\/apps\/[^/]+\/ws$/;
2481
+ /** Whether an upgrade's URL is a sync socket of this Jazz (`<basePath>/apps/<app>/ws`). */
2482
+ function isSocketUpgrade(url, basePath) {
2483
+ const pathname = requestPathname(url);
2484
+ return (pathname !== null &&
2485
+ pathname.startsWith(`${basePath}/`) &&
2486
+ SOCKET_PATH.test(pathname.slice(basePath.length)));
2487
+ }
2488
+ /** A Node request's path, or null for one no URL can be made of: not Jazz's. */
2489
+ function requestPathname(url) {
2490
+ try {
2491
+ return new URL(url ?? "/", "http://localhost").pathname;
2492
+ }
2493
+ catch {
2494
+ return null;
2495
+ }
2496
+ }
2497
+ /**
2498
+ * Whether `server` is an HTTP/2 server that can't serve HTTP/1: one without
2499
+ * upgrades (h2c, or TLS without `allowHTTP1`). Node keeps the options under
2500
+ * a symbol; a server that hides them is taken as able.
2501
+ */
2502
+ function http2Only(server) {
2503
+ const name = server.constructor?.name;
2504
+ if (name === "Http2Server")
2505
+ return true;
2506
+ if (name !== "Http2SecureServer")
2507
+ return false;
2508
+ const key = Object.getOwnPropertySymbols(server).find((symbol) => symbol.description === "options");
2509
+ const options = key
2510
+ ? server[key]
2511
+ : undefined;
2512
+ return options !== undefined && options.allowHTTP1 !== true;
2513
+ }
2514
+ /**
2515
+ * What a 503 tells the client to wait: until the store is tried again. The
2516
+ * reason stays in the backend's logs; it can name internal hosts.
2517
+ */
2518
+ function retryAfterSeconds(entry) {
2519
+ const at = entry.failure?.retryAt;
2520
+ return at === undefined ? 1 : Math.max(1, Math.ceil((at - Date.now()) / 1000));
2521
+ }
2522
+ const UNAVAILABLE_BODY = "Jazz is unavailable; try again shortly";
2523
+ /**
2524
+ * The 503 a Jazz route answers while its store can't open, or after it
2525
+ * closed. After a close it also closes the connection: a host shutting down
2526
+ * (`next start` on SIGTERM) waits for its keep-alive connections, and a
2527
+ * client re-opening its sync stream over one would keep it, and the
2528
+ * process, alive. (A Fetch response can't tell an HTTP/2 host, which drops
2529
+ * the header with a warning; nodeHandler leaves it off there.)
2530
+ */
2531
+ function storeUnavailable(retryAfter, closed) {
2532
+ return new Response(UNAVAILABLE_BODY, {
2533
+ status: 503,
2534
+ headers: {
2535
+ "content-type": "text/plain",
2536
+ "retry-after": String(retryAfter),
2537
+ ...(closed ? { connection: "close" } : {}),
2538
+ },
2539
+ });
2540
+ }
2541
+ const storeUnavailableUpgrade = (retryAfter) => `HTTP/1.1 503 Service Unavailable\r\nRetry-After: ${retryAfter}\r\nConnection: close\r\n\r\n`;
2542
+ const BAD_UPGRADE = "HTTP/1.1 400 Bad Request\r\nConnection: close\r\n\r\n";
2543
+ /** The `Jazz` every `createJazz` for one store returns. */
2544
+ function facade(entry) {
2545
+ const use = () => settled(entry);
2546
+ const basePath = () => jazzSettings(entry.options).basePath;
2547
+ // After close() its routes answer 503 as the host shuts down: no news.
2548
+ const logUnavailable = (error) => {
2549
+ if (!entry.closing)
2550
+ console.error("jazz: the store did not open", error);
2551
+ };
2552
+ /** The open Jazz, or the 503 a Jazz route answers while its store can't open. */
2553
+ const useOr503 = async () => {
2554
+ try {
2555
+ return await use();
2556
+ }
2557
+ catch (error) {
2558
+ logUnavailable(error);
2559
+ return storeUnavailable(retryAfterSeconds(entry), entry.closing !== undefined);
2560
+ }
2561
+ };
2562
+ const handle = async (request) => {
2563
+ const opened = await useOr503();
2564
+ return opened instanceof Response ? opened : opened.handle(request);
2565
+ };
2566
+ const nextHandler = async (request) => {
2567
+ const opened = await useOr503();
2568
+ return opened instanceof Response ? opened : opened.next().GET(request);
2569
+ };
2570
+ // The writes made before a close still apply as it drains them.
2571
+ const early = earlyDb(async () => (await settled(entry, true)).db, () => settledNow(entry)?.db);
2572
+ const db = early.db;
2573
+ let heldSockets = 0;
2574
+ /** The servers `attach()` took the upgrades of: a second call changes nothing. */
2575
+ const attachedTo = new WeakSet();
2576
+ const jazz = {
2577
+ get basePath() {
2578
+ return basePath();
2579
+ },
2580
+ handle,
2581
+ next: () => ({ GET: nextHandler, POST: nextHandler, DELETE: nextHandler }),
2582
+ async attach(server) {
2583
+ // An HTTP/2 server without HTTP/1 never sees a WebSocket upgrade.
2584
+ if (http2Only(server)) {
2585
+ throw new Error("attach(): an HTTP/2 server has no WebSocket upgrades; pass an HTTP/1 server (or an HTTPS one with allowHTTP1), or serve Jazz with handle() alone, over its HTTP stream");
2586
+ }
2587
+ if (attachedTo.has(server))
2588
+ return;
2589
+ attachedTo.add(server);
2590
+ const wss = await socketUpgrader();
2591
+ // Upgrades work from now on, opened or not: the store opens on the
2592
+ // first socket (or request), and one that can't open is refused with
2593
+ // a 503 the client retries, instead of failing the host's startup.
2594
+ entry.attached = true;
2595
+ entry.opened?.markAttached();
2596
+ const take = (opened, req, socket, head) => {
2597
+ try {
2598
+ opened.upgrade(wss, req, socket, head);
2599
+ }
2600
+ catch (error) {
2601
+ console.error("jazz: a socket upgrade failed", error);
2602
+ socket.destroy();
2603
+ }
2604
+ };
2605
+ const upgradeJazz = (req, socket, head) => {
2606
+ const now = settledNow(entry);
2607
+ if (now)
2608
+ return take(now, req, socket, head);
2609
+ use().then((opened) => take(opened, req, socket, head), (error) => {
2610
+ logUnavailable(error);
2611
+ socket.end(storeUnavailableUpgrade(retryAfterSeconds(entry)));
2612
+ });
2613
+ };
2614
+ const events = server;
2615
+ // Jazz's own sync sockets go to Jazz alone: another upgrade listener
2616
+ // on the server (a custom Next.js server adds one on its first
2617
+ // request) would take the same socket too, and close it. The listener
2618
+ // is there because Node only emits upgrades to a server that has one.
2619
+ events.on("upgrade", () => undefined);
2620
+ const emit = events.emit;
2621
+ events.emit = function (event, ...args) {
2622
+ if (event === "upgrade" && isSocketUpgrade(args[0].url, basePath())) {
2623
+ upgradeJazz(...args);
2624
+ return true;
2625
+ }
2626
+ return emit.call(this, event, ...args);
2627
+ };
2628
+ events.on("close", () => wss.close());
2629
+ },
2630
+ nodeHandler(req, res, next) {
2631
+ const now = settledNow(entry);
2632
+ if (now)
2633
+ return now.nodeHandler(req, res, next);
2634
+ const prefix = basePath();
2635
+ const pathname = requestPathname(req.url);
2636
+ // Requests Jazz doesn't serve pass on without opening the store.
2637
+ if (pathname === null || (pathname !== prefix && !pathname.startsWith(`${prefix}/`))) {
2638
+ if (next)
2639
+ return next();
2640
+ res.statusCode = 404;
2641
+ res.end();
2642
+ return;
2643
+ }
2644
+ use().then((opened) => opened.nodeHandler(req, res, next), (error) => {
2645
+ logUnavailable(error);
2646
+ res.statusCode = 503;
2647
+ res.setHeader("retry-after", String(retryAfterSeconds(entry)));
2648
+ // HTTP/2 has no Connection header (Node warns and drops it).
2649
+ if (entry.closing && req.httpVersionMajor < 2)
2650
+ res.setHeader("connection", "close");
2651
+ res.setHeader("content-type", "text/plain");
2652
+ res.end(UNAVAILABLE_BODY);
2653
+ });
2654
+ },
2655
+ acceptSocket(request, ws) {
2656
+ const now = settledNow(entry);
2657
+ if (now)
2658
+ return now.acceptSocket(request, ws);
2659
+ if (heldSockets >= MAX_HELD_SOCKETS)
2660
+ return ws.close(1013, "store still opening");
2661
+ heldSockets++;
2662
+ const { socket, refuse } = heldSocket(ws);
2663
+ use()
2664
+ .then((opened) => opened.acceptSocket(request, socket), (error) => {
2665
+ logUnavailable(error);
2666
+ refuse("store unavailable");
2667
+ })
2668
+ .finally(() => heldSockets--);
2669
+ },
2670
+ db,
2671
+ forReqUser: async (request) => (await use()).forReqUser(request),
2672
+ withAttribution: async (request) => (await use()).withAttribution(request),
2673
+ accountFor: async (request) => (await use()).accountFor(request),
2674
+ createAccountFor: async (userId) => (await use()).createAccountFor(userId),
2675
+ linkIdentity: async (link) => (await use()).linkIdentity(link),
2676
+ async ready() {
2677
+ await use();
2678
+ return jazz;
2679
+ },
2680
+ close() {
2681
+ return (entry.closing ??= closeEntry(entry, early));
2682
+ },
2683
+ };
2684
+ // Not enumerable, so printing or comparing a Jazz before it opens reads it not.
2685
+ Object.defineProperty(jazz, "appId", {
2686
+ get() {
2687
+ const opened = entry.opened;
2688
+ if (!opened) {
2689
+ throw new Error("jazz.appId is known once the store has opened: `await jazz.ready()` first");
2690
+ }
2691
+ return opened.appId;
2692
+ },
2693
+ });
2694
+ return jazz;
2695
+ }
2696
+ /** An account request the core answered with a 4xx: a refusal, not an outage. */
2697
+ function isRefusal(error) {
2698
+ const status = error?.status;
2699
+ // Timeouts and throttling are 4xx too, but pass.
2700
+ if (status === 408 || status === 425 || status === 429)
2701
+ return false;
2702
+ return typeof status === "number" && status >= 400 && status < 500;
2703
+ }
2704
+ function refusalCode(error) {
2705
+ const message = error instanceof Error ? error.message : "";
2706
+ const code = /: ([a-z_]{1,80})$/.exec(message)?.[1];
2707
+ return code ?? "refused";
2708
+ }
2709
+ /** A WireFrame::Error batch with code AuthFailed and retry Never. */
2710
+ function authFailedBatch(message) {
2711
+ const frame = new PostcardWriter();
2712
+ frame.u64(1); // WireFrame::Error
2713
+ frame.u64(3); // WireErrorCode::AuthFailed
2714
+ frame.u64(0); // WireRetry::Never
2715
+ frame.string(message);
2716
+ return Buffer.from(encodeWebSocketFrameBatch([frame.finish()]));
2717
+ }
2718
+ /** A development endpoint on this machine, where header-derived audiences are fine. */
2719
+ function isLocalEndpoint(endpoint) {
2720
+ try {
2721
+ const host = new URL(endpoint).hostname;
2722
+ return (host === "localhost" ||
2723
+ host.endsWith(".localhost") ||
2724
+ host === "127.0.0.1" ||
2725
+ host === "[::1]");
2726
+ }
2727
+ catch {
2728
+ return false;
2729
+ }
2730
+ }
2731
+ //# sourceMappingURL=create-jazz.js.map