@hulla/db 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (338) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +263 -2
  3. package/THIRD_PARTY_NOTICES.md +850 -0
  4. package/dist/aggregate.d.ts +63 -0
  5. package/dist/aggregate.js +147 -0
  6. package/dist/auth.d.ts +10 -0
  7. package/dist/auth.js +22 -0
  8. package/dist/bindings.d.ts +56 -0
  9. package/dist/bindings.js +277 -0
  10. package/dist/browser.d.ts +12 -0
  11. package/dist/browser.js +24 -0
  12. package/dist/callable.d.ts +48 -0
  13. package/dist/callable.js +142 -0
  14. package/dist/cli.d.ts +2 -0
  15. package/dist/cli.js +65 -0
  16. package/dist/codec.d.ts +32 -0
  17. package/dist/codec.js +129 -0
  18. package/dist/codegen.d.ts +19 -0
  19. package/dist/codegen.js +275 -0
  20. package/dist/config.d.ts +70 -0
  21. package/dist/config.js +100 -0
  22. package/dist/contracts.d.ts +109 -0
  23. package/dist/contracts.js +1 -0
  24. package/dist/database-builder.d.ts +19 -0
  25. package/dist/database-builder.js +183 -0
  26. package/dist/database.d.ts +69 -0
  27. package/dist/database.js +128 -0
  28. package/dist/declarations.d.ts +91 -0
  29. package/dist/declarations.js +141 -0
  30. package/dist/dev-worker.d.ts +1 -0
  31. package/dist/dev-worker.js +47 -0
  32. package/dist/dev.d.ts +5 -0
  33. package/dist/dev.js +148 -0
  34. package/dist/error.d.ts +20 -0
  35. package/dist/error.js +82 -0
  36. package/dist/fields.d.ts +36 -0
  37. package/dist/fields.js +63 -0
  38. package/dist/filters.d.ts +93 -0
  39. package/dist/filters.js +220 -0
  40. package/dist/function-shapes.d.ts +7 -0
  41. package/dist/function-shapes.js +150 -0
  42. package/dist/handles.d.ts +27 -0
  43. package/dist/handles.js +387 -0
  44. package/dist/http/protocol.d.ts +64 -0
  45. package/dist/http/protocol.js +77 -0
  46. package/dist/http/sse.d.ts +7 -0
  47. package/dist/http/sse.js +70 -0
  48. package/dist/http.d.ts +44 -0
  49. package/dist/http.js +911 -0
  50. package/dist/index.d.ts +6 -0
  51. package/dist/index.js +1 -0
  52. package/dist/internal/client.d.ts +6 -0
  53. package/dist/internal/client.js +5 -0
  54. package/dist/json-value.d.ts +21 -0
  55. package/dist/json-value.js +79 -0
  56. package/dist/names.d.ts +2 -0
  57. package/dist/names.js +10 -0
  58. package/dist/native.d.ts +3 -0
  59. package/dist/native.js +42 -0
  60. package/dist/notifications.d.ts +8 -0
  61. package/dist/notifications.js +70 -0
  62. package/dist/optimistic.d.ts +46 -0
  63. package/dist/optimistic.js +140 -0
  64. package/dist/page.d.ts +11 -0
  65. package/dist/page.js +1 -0
  66. package/dist/pagination.d.ts +17 -0
  67. package/dist/pagination.js +262 -0
  68. package/dist/project-codegen.d.ts +2 -0
  69. package/dist/project-codegen.js +68 -0
  70. package/dist/projection.d.ts +19 -0
  71. package/dist/projection.js +31 -0
  72. package/dist/runtime-conditions.d.ts +2 -0
  73. package/dist/runtime-conditions.js +10 -0
  74. package/dist/runtime.d.ts +13 -0
  75. package/dist/runtime.js +47 -0
  76. package/dist/schema-codegen.d.ts +16 -0
  77. package/dist/schema-codegen.js +212 -0
  78. package/dist/schema-contract.d.ts +4 -0
  79. package/dist/schema-contract.js +42 -0
  80. package/dist/schema.d.ts +356 -0
  81. package/dist/schema.js +720 -0
  82. package/dist/server-database.d.ts +14 -0
  83. package/dist/server-database.js +386 -0
  84. package/dist/server.d.ts +7 -0
  85. package/dist/server.js +1 -0
  86. package/dist/service.d.ts +13 -0
  87. package/dist/service.js +206 -0
  88. package/dist/sql-check.d.ts +28 -0
  89. package/dist/sql-check.js +59 -0
  90. package/dist/validation.d.ts +43 -0
  91. package/dist/validation.js +21 -0
  92. package/dist/worker-codegen.d.ts +3 -0
  93. package/dist/worker-codegen.js +44 -0
  94. package/dist/worker.d.ts +9 -0
  95. package/dist/worker.js +92 -0
  96. package/dist/write-expression.d.ts +72 -0
  97. package/dist/write-expression.js +122 -0
  98. package/dist/zod.d.ts +28 -0
  99. package/dist/zod.js +102 -0
  100. package/licenses/allocator-api2-0.2.21/LICENSE-APACHE +176 -0
  101. package/licenses/allocator-api2-0.2.21/LICENSE-MIT +23 -0
  102. package/licenses/async-trait-0.1.92/LICENSE-APACHE +176 -0
  103. package/licenses/async-trait-0.1.92/LICENSE-MIT +23 -0
  104. package/licenses/atomic-waker-1.1.2/LICENSE-APACHE +201 -0
  105. package/licenses/atomic-waker-1.1.2/LICENSE-MIT +23 -0
  106. package/licenses/atomic-waker-1.1.2/LICENSE-THIRD-PARTY +45 -0
  107. package/licenses/axum-0.8.9/LICENSE +25 -0
  108. package/licenses/axum-core-0.5.6/LICENSE +27 -0
  109. package/licenses/base64-0.22.1/LICENSE-APACHE +201 -0
  110. package/licenses/base64-0.22.1/LICENSE-MIT +21 -0
  111. package/licenses/bitflags-2.13.2/LICENSE-APACHE +201 -0
  112. package/licenses/bitflags-2.13.2/LICENSE-MIT +25 -0
  113. package/licenses/block-buffer-0.12.1/LICENSE-APACHE +201 -0
  114. package/licenses/block-buffer-0.12.1/LICENSE-MIT +25 -0
  115. package/licenses/byteorder-1.5.0/COPYING +3 -0
  116. package/licenses/byteorder-1.5.0/LICENSE-MIT +21 -0
  117. package/licenses/bytes-1.12.1/LICENSE +25 -0
  118. package/licenses/cc-1.6.0/LICENSE-APACHE +201 -0
  119. package/licenses/cc-1.6.0/LICENSE-MIT +25 -0
  120. package/licenses/cfg-if-1.0.5/LICENSE-APACHE +201 -0
  121. package/licenses/cfg-if-1.0.5/LICENSE-MIT +25 -0
  122. package/licenses/chacha20-0.10.2/LICENSE-APACHE +201 -0
  123. package/licenses/chacha20-0.10.2/LICENSE-MIT +25 -0
  124. package/licenses/cmov-0.5.4/LICENSE-APACHE +202 -0
  125. package/licenses/cmov-0.5.4/LICENSE-MIT +25 -0
  126. package/licenses/const-oid-0.10.2/LICENSE-APACHE +201 -0
  127. package/licenses/const-oid-0.10.2/LICENSE-MIT +25 -0
  128. package/licenses/const-oid-0.9.6/LICENSE-APACHE +201 -0
  129. package/licenses/const-oid-0.9.6/LICENSE-MIT +25 -0
  130. package/licenses/cpufeatures-0.3.1/LICENSE-APACHE +201 -0
  131. package/licenses/cpufeatures-0.3.1/LICENSE-MIT +25 -0
  132. package/licenses/crypto-common-0.2.2/LICENSE-APACHE +201 -0
  133. package/licenses/crypto-common-0.2.2/LICENSE-MIT +25 -0
  134. package/licenses/ctutils-0.4.2/LICENSE-APACHE +202 -0
  135. package/licenses/ctutils-0.4.2/LICENSE-MIT +25 -0
  136. package/licenses/der-0.7.10/LICENSE-APACHE +201 -0
  137. package/licenses/der-0.7.10/LICENSE-MIT +25 -0
  138. package/licenses/der_derive-0.7.3/LICENSE-APACHE +201 -0
  139. package/licenses/der_derive-0.7.3/LICENSE-MIT +25 -0
  140. package/licenses/deranged-0.5.8/LICENSE-Apache +202 -0
  141. package/licenses/deranged-0.5.8/LICENSE-MIT +19 -0
  142. package/licenses/digest-0.11.3/LICENSE-APACHE +201 -0
  143. package/licenses/digest-0.11.3/LICENSE-MIT +26 -0
  144. package/licenses/equivalent-1.0.3/LICENSE-APACHE +201 -0
  145. package/licenses/equivalent-1.0.3/LICENSE-MIT +25 -0
  146. package/licenses/errno-0.3.14/LICENSE-APACHE +201 -0
  147. package/licenses/errno-0.3.14/LICENSE-MIT +25 -0
  148. package/licenses/fallible-iterator-0.2.0/LICENSE-APACHE +202 -0
  149. package/licenses/fallible-iterator-0.2.0/LICENSE-MIT +19 -0
  150. package/licenses/find-msvc-tools-0.1.14/LICENSE-APACHE +201 -0
  151. package/licenses/find-msvc-tools-0.1.14/LICENSE-MIT +25 -0
  152. package/licenses/flagset-0.4.7/LICENSE +202 -0
  153. package/licenses/foldhash-0.2.0/LICENSE +19 -0
  154. package/licenses/futures-channel-0.3.34/LICENSE-APACHE +202 -0
  155. package/licenses/futures-channel-0.3.34/LICENSE-MIT +26 -0
  156. package/licenses/futures-core-0.3.34/LICENSE-APACHE +202 -0
  157. package/licenses/futures-core-0.3.34/LICENSE-MIT +26 -0
  158. package/licenses/futures-sink-0.3.34/LICENSE-APACHE +202 -0
  159. package/licenses/futures-sink-0.3.34/LICENSE-MIT +26 -0
  160. package/licenses/futures-task-0.3.34/LICENSE-APACHE +202 -0
  161. package/licenses/futures-task-0.3.34/LICENSE-MIT +26 -0
  162. package/licenses/futures-util-0.3.34/LICENSE-APACHE +202 -0
  163. package/licenses/futures-util-0.3.34/LICENSE-MIT +26 -0
  164. package/licenses/getrandom-0.2.17/LICENSE-APACHE +201 -0
  165. package/licenses/getrandom-0.2.17/LICENSE-MIT +26 -0
  166. package/licenses/getrandom-0.4.3/LICENSE-APACHE +201 -0
  167. package/licenses/getrandom-0.4.3/LICENSE-MIT +26 -0
  168. package/licenses/hashbrown-0.17.1/LICENSE-APACHE +201 -0
  169. package/licenses/hashbrown-0.17.1/LICENSE-MIT +25 -0
  170. package/licenses/hmac-0.13.0/LICENSE-APACHE +201 -0
  171. package/licenses/hmac-0.13.0/LICENSE-MIT +25 -0
  172. package/licenses/http-1.5.0/LICENSE-APACHE +201 -0
  173. package/licenses/http-1.5.0/LICENSE-MIT +25 -0
  174. package/licenses/http-body-1.1.0/LICENSE +25 -0
  175. package/licenses/http-body-util-0.1.5/LICENSE +25 -0
  176. package/licenses/httparse-1.10.1/LICENSE-APACHE +201 -0
  177. package/licenses/httparse-1.10.1/LICENSE-MIT +20 -0
  178. package/licenses/httpdate-1.0.3/LICENSE-APACHE +201 -0
  179. package/licenses/httpdate-1.0.3/LICENSE-MIT +19 -0
  180. package/licenses/hybrid-array-0.4.15/LICENSE-APACHE +201 -0
  181. package/licenses/hybrid-array-0.4.15/LICENSE-MIT +25 -0
  182. package/licenses/hyper-1.11.1/LICENSE +19 -0
  183. package/licenses/hyper-util-0.1.21/LICENSE +19 -0
  184. package/licenses/itoa-1.0.18/LICENSE-APACHE +176 -0
  185. package/licenses/itoa-1.0.18/LICENSE-MIT +23 -0
  186. package/licenses/libc-0.2.189/LICENSE-APACHE +176 -0
  187. package/licenses/libc-0.2.189/LICENSE-MIT +25 -0
  188. package/licenses/lock_api-0.4.14/LICENSE-APACHE +201 -0
  189. package/licenses/lock_api-0.4.14/LICENSE-MIT +25 -0
  190. package/licenses/log-0.4.34/LICENSE-APACHE +201 -0
  191. package/licenses/log-0.4.34/LICENSE-MIT +25 -0
  192. package/licenses/matchit-0.8.4/LICENSE +21 -0
  193. package/licenses/matchit-0.8.4/LICENSE.httprouter +29 -0
  194. package/licenses/md-5-0.11.0/LICENSE-APACHE +201 -0
  195. package/licenses/md-5-0.11.0/LICENSE-MIT +28 -0
  196. package/licenses/memchr-2.8.3/COPYING +3 -0
  197. package/licenses/memchr-2.8.3/LICENSE-MIT +21 -0
  198. package/licenses/mime-0.3.17/LICENSE-APACHE +201 -0
  199. package/licenses/mime-0.3.17/LICENSE-MIT +20 -0
  200. package/licenses/mio-1.2.3/LICENSE +19 -0
  201. package/licenses/num-conv-0.2.2/LICENSE-Apache +177 -0
  202. package/licenses/num-conv-0.2.2/LICENSE-MIT +19 -0
  203. package/licenses/objc2-core-foundation-0.3.2/LICENSE.md +34 -0
  204. package/licenses/objc2-system-configuration-0.3.2/LICENSE.md +34 -0
  205. package/licenses/once_cell-1.21.4/LICENSE-APACHE +201 -0
  206. package/licenses/once_cell-1.21.4/LICENSE-MIT +23 -0
  207. package/licenses/parking_lot-0.12.5/LICENSE-APACHE +201 -0
  208. package/licenses/parking_lot-0.12.5/LICENSE-MIT +25 -0
  209. package/licenses/parking_lot_core-0.9.12/LICENSE-APACHE +201 -0
  210. package/licenses/parking_lot_core-0.9.12/LICENSE-MIT +25 -0
  211. package/licenses/percent-encoding-2.3.2/LICENSE-APACHE +201 -0
  212. package/licenses/percent-encoding-2.3.2/LICENSE-MIT +25 -0
  213. package/licenses/phf-0.13.1/LICENSE +20 -0
  214. package/licenses/phf_shared-0.13.1/LICENSE +20 -0
  215. package/licenses/pin-project-lite-0.2.17/LICENSE-APACHE +177 -0
  216. package/licenses/pin-project-lite-0.2.17/LICENSE-MIT +23 -0
  217. package/licenses/postgres-protocol-0.6.12/LICENSE-APACHE +201 -0
  218. package/licenses/postgres-protocol-0.6.12/LICENSE-MIT +22 -0
  219. package/licenses/postgres-types-0.2.14/LICENSE-APACHE +201 -0
  220. package/licenses/postgres-types-0.2.14/LICENSE-MIT +22 -0
  221. package/licenses/powerfmt-0.2.1/LICENSE-Apache +202 -0
  222. package/licenses/powerfmt-0.2.1/LICENSE-MIT +19 -0
  223. package/licenses/proc-macro2-1.0.107/LICENSE-APACHE +176 -0
  224. package/licenses/proc-macro2-1.0.107/LICENSE-MIT +23 -0
  225. package/licenses/quote-1.0.47/LICENSE-APACHE +176 -0
  226. package/licenses/quote-1.0.47/LICENSE-MIT +23 -0
  227. package/licenses/rand-0.10.3/COPYRIGHT +12 -0
  228. package/licenses/rand-0.10.3/LICENSE-APACHE +176 -0
  229. package/licenses/rand-0.10.3/LICENSE-MIT +26 -0
  230. package/licenses/rand_core-0.10.1/COPYRIGHT +9 -0
  231. package/licenses/rand_core-0.10.1/LICENSE-APACHE +187 -0
  232. package/licenses/rand_core-0.10.1/LICENSE-MIT +25 -0
  233. package/licenses/ring-0.17.14/LICENSE +9 -0
  234. package/licenses/ring-0.17.14/LICENSE-BoringSSL +272 -0
  235. package/licenses/ring-0.17.14/LICENSE-other-bits +13 -0
  236. package/licenses/ring-0.17.14/src/polyfill/once_cell/LICENSE-APACHE +201 -0
  237. package/licenses/ring-0.17.14/src/polyfill/once_cell/LICENSE-MIT +23 -0
  238. package/licenses/ring-0.17.14/third_party/fiat/LICENSE +15 -0
  239. package/licenses/rquickjs-0.14.0/LICENSE +22 -0
  240. package/licenses/rquickjs-core-0.14.0/LICENSE +22 -0
  241. package/licenses/rquickjs-sys-0.14.0/quickjs/LICENSE +24 -0
  242. package/licenses/rquickjs-sys-0.14.0/vendor/wasi-libc/NOTICE.md +26 -0
  243. package/licenses/rustls-0.23.46/LICENSE-APACHE +201 -0
  244. package/licenses/rustls-0.23.46/LICENSE-ISC +15 -0
  245. package/licenses/rustls-0.23.46/LICENSE-MIT +25 -0
  246. package/licenses/rustls-pki-types-1.15.1/LICENSE-APACHE +201 -0
  247. package/licenses/rustls-pki-types-1.15.1/LICENSE-MIT +25 -0
  248. package/licenses/rustls-webpki-0.103.15/LICENSE +19 -0
  249. package/licenses/scopeguard-1.2.0/LICENSE-APACHE +201 -0
  250. package/licenses/scopeguard-1.2.0/LICENSE-MIT +25 -0
  251. package/licenses/serde-1.0.229/LICENSE-APACHE +176 -0
  252. package/licenses/serde-1.0.229/LICENSE-MIT +23 -0
  253. package/licenses/serde_core-1.0.229/LICENSE-APACHE +176 -0
  254. package/licenses/serde_core-1.0.229/LICENSE-MIT +23 -0
  255. package/licenses/serde_derive-1.0.229/LICENSE-APACHE +176 -0
  256. package/licenses/serde_derive-1.0.229/LICENSE-MIT +23 -0
  257. package/licenses/serde_json-1.0.151/LICENSE-APACHE +176 -0
  258. package/licenses/serde_json-1.0.151/LICENSE-MIT +23 -0
  259. package/licenses/serde_path_to_error-0.1.20/LICENSE-APACHE +176 -0
  260. package/licenses/serde_path_to_error-0.1.20/LICENSE-MIT +23 -0
  261. package/licenses/sha2-0.11.0/LICENSE-APACHE +201 -0
  262. package/licenses/sha2-0.11.0/LICENSE-MIT +28 -0
  263. package/licenses/shlex-2.0.1/LICENSE-APACHE +13 -0
  264. package/licenses/shlex-2.0.1/LICENSE-MIT +21 -0
  265. package/licenses/signal-hook-registry-1.4.8/LICENSE-APACHE +201 -0
  266. package/licenses/signal-hook-registry-1.4.8/LICENSE-MIT +25 -0
  267. package/licenses/siphasher-1.0.4/COPYING +7 -0
  268. package/licenses/siphasher-1.0.4/LICENSE-APACHE +202 -0
  269. package/licenses/siphasher-1.0.4/LICENSE-MIT +17 -0
  270. package/licenses/slab-0.4.12/LICENSE +25 -0
  271. package/licenses/smallvec-1.16.2/LICENSE-APACHE +201 -0
  272. package/licenses/smallvec-1.16.2/LICENSE-MIT +25 -0
  273. package/licenses/socket2-0.6.5/LICENSE-APACHE +201 -0
  274. package/licenses/socket2-0.6.5/LICENSE-MIT +25 -0
  275. package/licenses/spki-0.7.3/LICENSE-APACHE +201 -0
  276. package/licenses/spki-0.7.3/LICENSE-MIT +25 -0
  277. package/licenses/stringprep-0.1.5/LICENSE-APACHE +202 -0
  278. package/licenses/stringprep-0.1.5/LICENSE-MIT +19 -0
  279. package/licenses/subtle-2.6.1/LICENSE +29 -0
  280. package/licenses/syn-2.0.119/LICENSE-APACHE +176 -0
  281. package/licenses/syn-2.0.119/LICENSE-MIT +23 -0
  282. package/licenses/syn-3.0.6/LICENSE-APACHE +176 -0
  283. package/licenses/syn-3.0.6/LICENSE-MIT +23 -0
  284. package/licenses/sync_wrapper-1.0.2/LICENSE +177 -0
  285. package/licenses/time-0.3.55/LICENSE-Apache +177 -0
  286. package/licenses/time-0.3.55/LICENSE-MIT +19 -0
  287. package/licenses/time-core-0.1.9/LICENSE-Apache +177 -0
  288. package/licenses/time-core-0.1.9/LICENSE-MIT +19 -0
  289. package/licenses/time-macros-0.2.32/LICENSE-Apache +177 -0
  290. package/licenses/time-macros-0.2.32/LICENSE-MIT +19 -0
  291. package/licenses/tinyvec-1.13.3/LICENSE-APACHE.md +202 -0
  292. package/licenses/tinyvec-1.13.3/LICENSE-MIT.md +5 -0
  293. package/licenses/tinyvec-1.13.3/LICENSE-ZLIB.md +11 -0
  294. package/licenses/tokio-1.53.1/LICENSE +21 -0
  295. package/licenses/tokio-macros-2.7.2/LICENSE +22 -0
  296. package/licenses/tokio-postgres-0.7.18/LICENSE-APACHE +201 -0
  297. package/licenses/tokio-postgres-0.7.18/LICENSE-MIT +22 -0
  298. package/licenses/tokio-postgres-rustls-0.14.0/LICENSE +21 -0
  299. package/licenses/tokio-rustls-0.26.6/LICENSE-APACHE +201 -0
  300. package/licenses/tokio-rustls-0.26.6/LICENSE-MIT +25 -0
  301. package/licenses/tokio-util-0.7.19/LICENSE +21 -0
  302. package/licenses/tower-0.5.3/LICENSE +25 -0
  303. package/licenses/tower-layer-0.3.3/LICENSE +25 -0
  304. package/licenses/tower-service-0.3.3/LICENSE +25 -0
  305. package/licenses/typenum-1.20.1/LICENSE +1 -0
  306. package/licenses/typenum-1.20.1/LICENSE-APACHE +201 -0
  307. package/licenses/typenum-1.20.1/LICENSE-MIT +21 -0
  308. package/licenses/unicode-bidi-0.3.18/COPYRIGHT +8 -0
  309. package/licenses/unicode-bidi-0.3.18/LICENSE-APACHE +201 -0
  310. package/licenses/unicode-bidi-0.3.18/LICENSE-MIT +25 -0
  311. package/licenses/unicode-ident-1.0.26/LICENSE-APACHE +176 -0
  312. package/licenses/unicode-ident-1.0.26/LICENSE-MIT +23 -0
  313. package/licenses/unicode-ident-1.0.26/LICENSE-UNICODE +39 -0
  314. package/licenses/unicode-normalization-0.1.25/COPYRIGHT +7 -0
  315. package/licenses/unicode-normalization-0.1.25/LICENSE-APACHE +201 -0
  316. package/licenses/unicode-normalization-0.1.25/LICENSE-MIT +25 -0
  317. package/licenses/unicode-properties-0.1.4/COPYRIGHT +7 -0
  318. package/licenses/unicode-properties-0.1.4/LICENSE-APACHE +201 -0
  319. package/licenses/unicode-properties-0.1.4/LICENSE-MIT +25 -0
  320. package/licenses/untrusted-0.9.0/LICENSE.txt +13 -0
  321. package/licenses/uuid-1.26.1/LICENSE-APACHE +201 -0
  322. package/licenses/uuid-1.26.1/LICENSE-MIT +26 -0
  323. package/licenses/webpki-roots-1.0.9/LICENSE +61 -0
  324. package/licenses/whoami-2.1.3/LICENSE_APACHE +176 -0
  325. package/licenses/whoami-2.1.3/LICENSE_BOOST +23 -0
  326. package/licenses/whoami-2.1.3/LICENSE_MIT +19 -0
  327. package/licenses/x509-cert-0.2.5/LICENSE-APACHE +201 -0
  328. package/licenses/x509-cert-0.2.5/LICENSE-MIT +25 -0
  329. package/licenses/zeroize-1.9.1/LICENSE-APACHE +202 -0
  330. package/licenses/zeroize-1.9.1/LICENSE-MIT +25 -0
  331. package/licenses/zmij-1.0.23/LICENSE-MIT +23 -0
  332. package/native/darwin-arm64/hulladb-bridge +0 -0
  333. package/native/darwin-arm64/hulladb-js +0 -0
  334. package/native/darwin-arm64/hulladb-service +0 -0
  335. package/native/linux-x64/hulladb-bridge +0 -0
  336. package/native/linux-x64/hulladb-js +0 -0
  337. package/native/linux-x64/hulladb-service +0 -0
  338. package/package.json +90 -4
@@ -0,0 +1,27 @@
1
+ import type { FunctionCodecs } from "./codec.ts";
2
+ import type { MutationHandle, MutationState, QueryHandle, QueryState, QuerySubscriptionOptions, ReadonlyResult } from "./contracts.ts";
3
+ export declare function querySnapshot<T>(state: QueryState<unknown>, codecs?: FunctionCodecs): QueryState<T>;
4
+ export declare function subscriptionOptions(value: unknown): QuerySubscriptionOptions;
5
+ export declare function clearsPrevious(error: unknown): boolean;
6
+ /** Retention belongs to each subscriber; the authoritative handle/cache still receives the error. */
7
+ export declare function queryListener<T>(listener: (state: QueryState<T>) => void, options: QuerySubscriptionOptions): (state: QueryState<T>) => void;
8
+ export declare class QueryOperation<T> implements QueryHandle<T> {
9
+ #private;
10
+ constructor(start: () => Promise<unknown>, watch?: (listener: (state: QueryState<T>) => void) => () => void, codecs?: FunctionCodecs, assertScope?: () => void, signal?: () => AbortSignal | undefined, scopeSignal?: () => AbortSignal | undefined);
11
+ get status(): "error" | "pending" | "success";
12
+ get data(): ReadonlyResult<T> | undefined;
13
+ get error(): unknown;
14
+ get isStale(): boolean;
15
+ get isOptimistic(): boolean;
16
+ then<A = ReadonlyResult<T>, B = never>(fulfilled?: ((value: ReadonlyResult<T>) => A | PromiseLike<A>) | null, rejected?: ((reason: unknown) => B | PromiseLike<B>) | null): Promise<A | B>;
17
+ subscribe(listener: (state: QueryState<T>) => void, options?: QuerySubscriptionOptions): () => void;
18
+ }
19
+ export declare class MutationOperation<T> implements MutationHandle<T> {
20
+ #private;
21
+ constructor(start: (onStatus: (status: "recovering") => void) => Promise<unknown>, codecs?: FunctionCodecs, assertScope?: () => void, scopeSignal?: () => AbortSignal | undefined);
22
+ get status(): "error" | "pending" | "recovering" | "success";
23
+ get data(): T | undefined;
24
+ get error(): unknown;
25
+ then<A = T, B = never>(fulfilled?: ((value: T) => A | PromiseLike<A>) | null, rejected?: ((reason: unknown) => B | PromiseLike<B>) | null): Promise<A | B>;
26
+ subscribe(listener: (state: MutationState<T>) => void): () => void;
27
+ }
@@ -0,0 +1,387 @@
1
+ import { derivedObserver, notification, notifyObserver } from "./notifications.js";
2
+ import { DatabaseError, isApplicationError } from "./error.js";
3
+ function notify(listener, state) {
4
+ notifyObserver(listener, () => { try {
5
+ listener(state);
6
+ }
7
+ catch { /* Listener failures belong to the application. */ } });
8
+ }
9
+ /** Observed handles follow auth retirement without retaining unobserved completed operations. */
10
+ function observeScope(signal, checkScope) {
11
+ if (!signal)
12
+ return () => { };
13
+ if (signal.aborted) {
14
+ checkScope();
15
+ return () => { };
16
+ }
17
+ signal.addEventListener("abort", checkScope, { once: true });
18
+ return () => { signal.removeEventListener("abort", checkScope); };
19
+ }
20
+ function assertScopeSignal(signal) {
21
+ if (signal?.aborted)
22
+ throw new DatabaseError({ code: "context_changed", message: "Operation authorization scope changed" });
23
+ }
24
+ /** Check ordinary shared values in development. Date methods are intentionally unaffected. */
25
+ function readonly(value, seen = new WeakSet()) {
26
+ if (typeof process !== "undefined" && process.env.NODE_ENV === "production")
27
+ return value;
28
+ if (value !== null && typeof value === "object" && !seen.has(value)
29
+ && (Array.isArray(value) || [Object.prototype, null].includes(Object.getPrototypeOf(value)))) {
30
+ seen.add(value);
31
+ for (const item of Object.values(value))
32
+ readonly(item, seen);
33
+ Object.freeze(value);
34
+ }
35
+ return value;
36
+ }
37
+ export function querySnapshot(state, codecs) {
38
+ try {
39
+ if (state.status === "success" || ("data" in state && state.data !== undefined)) {
40
+ const data = readonly(codecs ? codecs.result.parse(state.data) : state.data);
41
+ return { ...state, data };
42
+ }
43
+ return state;
44
+ }
45
+ catch (error) {
46
+ return { status: "error", error };
47
+ }
48
+ }
49
+ export function subscriptionOptions(value) {
50
+ if (value === undefined)
51
+ return {};
52
+ if (typeof value !== "object" || value === null || Array.isArray(value))
53
+ throw new TypeError("Subscription options must be an object");
54
+ if (Object.keys(value).some(key => key !== "signal" && key !== "keepPreviousDataOnError"))
55
+ throw new TypeError("Unknown subscription option");
56
+ const options = value;
57
+ if (options.signal !== undefined && !(options.signal instanceof AbortSignal))
58
+ throw new TypeError("signal must be an AbortSignal");
59
+ if (options.keepPreviousDataOnError !== undefined && typeof options.keepPreviousDataOnError !== "boolean")
60
+ throw new TypeError("keepPreviousDataOnError must be a boolean");
61
+ return options;
62
+ }
63
+ export function clearsPrevious(error) {
64
+ if (typeof error !== "object" || error === null || !("code" in error))
65
+ return false;
66
+ return !isApplicationError(error) && ["unauthorized", "forbidden", "reset_required", "context_changed", "disposed", "authentication", "authorization", "authentication_failed"]
67
+ .includes(String(error.code));
68
+ }
69
+ /** Retention belongs to each subscriber; the authoritative handle/cache still receives the error. */
70
+ export function queryListener(listener, options) {
71
+ let previous;
72
+ let hasPrevious = false;
73
+ return derivedObserver(listener, (state) => {
74
+ if (state.status === "success") {
75
+ previous = state.data;
76
+ hasPrevious = true;
77
+ }
78
+ if (state.status === "error" && clearsPrevious(state.error)) {
79
+ previous = undefined;
80
+ hasPrevious = false;
81
+ }
82
+ if (state.status === "error" && options.keepPreviousDataOnError && hasPrevious) {
83
+ notify(listener, { ...state, data: previous, isStale: true, isOptimistic: false });
84
+ }
85
+ else
86
+ notify(listener, state);
87
+ });
88
+ }
89
+ export class QueryOperation {
90
+ #state = { status: "pending" };
91
+ #outcome;
92
+ #listeners = new Set();
93
+ #subscriptions = new Set();
94
+ #watch;
95
+ #stop;
96
+ #observed = false;
97
+ #assertScope;
98
+ #scopeSignal;
99
+ #stopScope;
100
+ #retired = false;
101
+ #scopeError;
102
+ #signal;
103
+ #cancelled = false;
104
+ constructor(start, watch, codecs, assertScope, signal, scopeSignal) {
105
+ this.#watch = watch;
106
+ this.#assertScope = assertScope;
107
+ this.#scopeSignal = scopeSignal;
108
+ this.#signal = signal;
109
+ let execution;
110
+ try {
111
+ execution = Promise.resolve(start());
112
+ }
113
+ catch (error) {
114
+ execution = Promise.reject(error);
115
+ }
116
+ this.#outcome = execution.then((result) => {
117
+ this.#checkScope();
118
+ if (this.#retired)
119
+ throw this.#scopeError;
120
+ this.#signal?.()?.throwIfAborted();
121
+ const data = readonly(codecs ? codecs.result.parse(result) : result);
122
+ if (!this.#observed)
123
+ this.#publish({ status: "success", data, isStale: false, isOptimistic: false });
124
+ this.#checkScope();
125
+ if (this.#retired)
126
+ throw this.#scopeError;
127
+ return data;
128
+ }).catch((error) => {
129
+ this.#checkScope();
130
+ if (this.#retired)
131
+ throw this.#scopeError;
132
+ const signal = this.#signal?.();
133
+ if (signal?.aborted) {
134
+ this.#cancelled = true;
135
+ const stop = this.#stop;
136
+ this.#stop = undefined;
137
+ stop?.();
138
+ error = signal.reason ?? error;
139
+ this.#publish({ status: "error", error });
140
+ for (const unsubscribe of [...this.#subscriptions])
141
+ unsubscribe();
142
+ }
143
+ else if (!this.#observed)
144
+ this.#publish({ status: "error", error });
145
+ throw error;
146
+ });
147
+ // Non-awaited operations are supported: errors remain inspectable and later awaits still reject.
148
+ void this.#outcome.catch(() => { });
149
+ }
150
+ #checkScope() {
151
+ if (this.#retired)
152
+ return;
153
+ try {
154
+ this.#assertScope?.();
155
+ assertScopeSignal(this.#scopeSignal?.());
156
+ }
157
+ catch (error) {
158
+ this.#retired = true;
159
+ this.#scopeError = error;
160
+ this.#stopScope?.();
161
+ this.#stopScope = undefined;
162
+ const stop = this.#stop;
163
+ this.#stop = undefined;
164
+ stop?.();
165
+ this.#publish({ status: "error", error });
166
+ for (const unsubscribe of [...this.#subscriptions])
167
+ unsubscribe();
168
+ }
169
+ }
170
+ get status() { this.#checkScope(); return this.#state.status; }
171
+ get data() { this.#checkScope(); return "data" in this.#state ? this.#state.data : undefined; }
172
+ get error() { this.#checkScope(); return this.#state.status === "error" ? this.#state.error : undefined; }
173
+ get isStale() { this.#checkScope(); return this.#state.isStale ?? false; }
174
+ get isOptimistic() { this.#checkScope(); return this.#state.isOptimistic ?? false; }
175
+ then(fulfilled, rejected) {
176
+ this.#checkScope();
177
+ const outcome = this.#retired ? Promise.reject(this.#scopeError) : this.#outcome.then(value => {
178
+ this.#checkScope();
179
+ if (this.#retired)
180
+ throw this.#scopeError;
181
+ return value;
182
+ });
183
+ return outcome.then(fulfilled, rejected);
184
+ }
185
+ #publish(state) {
186
+ this.#checkScope();
187
+ if (this.#retired && !(state.status === "error" && state.error === this.#scopeError))
188
+ return;
189
+ this.#state = state;
190
+ for (const listener of [...this.#listeners]) {
191
+ this.#checkScope();
192
+ if (this.#state !== state)
193
+ break;
194
+ notification(() => { if (this.#state === state && this.#listeners.has(listener))
195
+ notify(listener, state); });
196
+ }
197
+ this.#checkScope();
198
+ }
199
+ subscribe(listener, options = {}) {
200
+ if (typeof listener !== "function")
201
+ throw new TypeError("A query subscription needs a listener");
202
+ options = subscriptionOptions(options);
203
+ options.signal?.throwIfAborted();
204
+ this.#checkScope();
205
+ if (this.#retired || this.#cancelled) {
206
+ notify(listener, this.#state);
207
+ return () => { };
208
+ }
209
+ if (!this.#watch)
210
+ throw new Error("The configured runtime does not support query subscriptions");
211
+ const deliver = queryListener(listener, options);
212
+ const first = this.#listeners.size === 0;
213
+ this.#listeners.add(deliver);
214
+ let active = true;
215
+ const stop = () => {
216
+ if (!active)
217
+ return;
218
+ active = false;
219
+ options.signal?.removeEventListener("abort", stop);
220
+ this.#listeners.delete(deliver);
221
+ this.#subscriptions.delete(stop);
222
+ if (!this.#listeners.size) {
223
+ this.#stopScope?.();
224
+ this.#stopScope = undefined;
225
+ const stopWatch = this.#stop;
226
+ this.#stop = undefined;
227
+ stopWatch?.();
228
+ }
229
+ };
230
+ this.#subscriptions.add(stop);
231
+ options.signal?.addEventListener("abort", stop, { once: true });
232
+ if (first)
233
+ this.#stopScope = observeScope(this.#scopeSignal?.(), () => this.#checkScope());
234
+ if (this.#retired) {
235
+ stop();
236
+ return stop;
237
+ }
238
+ deliver(this.#state);
239
+ this.#checkScope();
240
+ if (this.#retired) {
241
+ stop();
242
+ return stop;
243
+ }
244
+ if (first && active) {
245
+ const previouslyObserved = this.#observed;
246
+ // Once attached, live delivery owns handle state even before its first
247
+ // round. The independent one-shot still resolves the awaitable outcome.
248
+ this.#observed = true;
249
+ try {
250
+ const stopWatch = this.#watch((state) => {
251
+ this.#checkScope();
252
+ if (this.#retired || this.#cancelled)
253
+ return;
254
+ if (state.status !== "pending")
255
+ this.#observed = true;
256
+ this.#publish(state);
257
+ });
258
+ if (!this.#listeners.size)
259
+ stopWatch();
260
+ else
261
+ this.#stop = stopWatch;
262
+ }
263
+ catch (error) {
264
+ this.#observed = previouslyObserved;
265
+ stop();
266
+ throw error;
267
+ }
268
+ }
269
+ return stop;
270
+ }
271
+ }
272
+ export class MutationOperation {
273
+ #state = { status: "pending" };
274
+ #outcome;
275
+ #listeners = new Set();
276
+ #assertScope;
277
+ #scopeSignal;
278
+ #stopScope;
279
+ #retired = false;
280
+ #scopeError;
281
+ constructor(start, codecs, assertScope, scopeSignal) {
282
+ this.#assertScope = assertScope;
283
+ this.#scopeSignal = scopeSignal;
284
+ let execution;
285
+ try {
286
+ execution = Promise.resolve(start(() => {
287
+ this.#checkScope();
288
+ if (this.#state.status === "pending")
289
+ this.#publish({ status: "recovering" });
290
+ }));
291
+ }
292
+ catch (error) {
293
+ execution = Promise.reject(error);
294
+ }
295
+ this.#outcome = execution.then((result) => {
296
+ this.#checkScope();
297
+ if (this.#retired)
298
+ throw this.#scopeError;
299
+ const data = (codecs ? codecs.result.parse(result) : result);
300
+ this.#publish({ status: "success", data });
301
+ this.#checkScope();
302
+ if (this.#retired)
303
+ throw this.#scopeError;
304
+ return data;
305
+ }).catch((error) => {
306
+ this.#checkScope();
307
+ if (this.#retired)
308
+ throw this.#scopeError;
309
+ this.#publish({ status: "error", error });
310
+ if (this.#retired)
311
+ throw this.#scopeError;
312
+ throw error;
313
+ });
314
+ void this.#outcome.catch(() => { });
315
+ }
316
+ #checkScope() {
317
+ if (this.#retired)
318
+ return;
319
+ try {
320
+ this.#assertScope?.();
321
+ assertScopeSignal(this.#scopeSignal?.());
322
+ }
323
+ catch (error) {
324
+ this.#retired = true;
325
+ this.#scopeError = error;
326
+ this.#stopScope?.();
327
+ this.#stopScope = undefined;
328
+ this.#publish({ status: "error", error });
329
+ this.#listeners.clear();
330
+ }
331
+ }
332
+ get status() { this.#checkScope(); return this.#state.status; }
333
+ get data() { this.#checkScope(); return this.#state.status === "success" ? this.#state.data : undefined; }
334
+ get error() { this.#checkScope(); return this.#state.status === "error" ? this.#state.error : undefined; }
335
+ then(fulfilled, rejected) {
336
+ this.#checkScope();
337
+ const outcome = this.#retired ? Promise.reject(this.#scopeError) : this.#outcome.then(value => {
338
+ this.#checkScope();
339
+ if (this.#retired)
340
+ throw this.#scopeError;
341
+ return value;
342
+ });
343
+ return outcome.then(fulfilled, rejected);
344
+ }
345
+ #publish(state) {
346
+ this.#checkScope();
347
+ if (this.#retired && !(state.status === "error" && state.error === this.#scopeError))
348
+ return;
349
+ this.#state = state;
350
+ for (const listener of [...this.#listeners]) {
351
+ this.#checkScope();
352
+ if (this.#state !== state)
353
+ break;
354
+ notification(() => { if (this.#state === state && this.#listeners.has(listener))
355
+ notify(listener, state); });
356
+ }
357
+ this.#checkScope();
358
+ }
359
+ subscribe(listener) {
360
+ if (typeof listener !== "function")
361
+ throw new TypeError("A mutation subscription needs a listener");
362
+ this.#checkScope();
363
+ if (this.#retired) {
364
+ notify(listener, this.#state);
365
+ return () => { };
366
+ }
367
+ const deliver = (state) => notify(listener, state);
368
+ const first = this.#listeners.size === 0;
369
+ this.#listeners.add(deliver);
370
+ const stop = () => {
371
+ this.#listeners.delete(deliver);
372
+ if (!this.#listeners.size) {
373
+ this.#stopScope?.();
374
+ this.#stopScope = undefined;
375
+ }
376
+ };
377
+ if (first)
378
+ this.#stopScope = observeScope(this.#scopeSignal?.(), () => this.#checkScope());
379
+ if (this.#retired) {
380
+ stop();
381
+ return stop;
382
+ }
383
+ deliver(this.#state);
384
+ this.#checkScope();
385
+ return stop;
386
+ }
387
+ }
@@ -0,0 +1,64 @@
1
+ import type { Operation } from "../contracts.ts";
2
+ import { DatabaseError } from "../error.ts";
3
+ export interface Session {
4
+ readonly scope: string;
5
+ readonly principal: string;
6
+ readonly authorizationScope: string;
7
+ }
8
+ export interface Snapshot {
9
+ readonly source: string;
10
+ readonly scope: string;
11
+ readonly principal: string;
12
+ readonly authorization_scope: string;
13
+ readonly revision: string;
14
+ readonly result: unknown;
15
+ readonly page?: {
16
+ readonly range: string;
17
+ };
18
+ }
19
+ export interface Head extends Omit<Snapshot, "result"> {
20
+ }
21
+ export interface Receipt {
22
+ readonly request_id: string;
23
+ readonly source: string;
24
+ readonly scope: string;
25
+ readonly revision: string;
26
+ readonly result: unknown;
27
+ }
28
+ export interface Round extends Head {
29
+ readonly results: readonly ({
30
+ readonly key: string;
31
+ readonly result: unknown;
32
+ } | {
33
+ readonly key: string;
34
+ readonly error: {
35
+ readonly code: string;
36
+ };
37
+ })[];
38
+ }
39
+ export interface Delivery {
40
+ readonly subscription: string;
41
+ readonly sequence: string;
42
+ readonly round: Round;
43
+ }
44
+ export declare const uuidPattern: RegExp;
45
+ export declare function uuid(value: unknown): string;
46
+ export declare function sequence(value: unknown): string;
47
+ export declare function record(value: unknown, keys: readonly string[]): Record<string, unknown>;
48
+ export declare function parseHead(value: unknown): Head;
49
+ export interface Ticket {
50
+ readonly id: string;
51
+ readonly expires_in_ms: number;
52
+ readonly renew_after_ms: number;
53
+ }
54
+ export declare function parseSession(value: unknown): Head & {
55
+ readonly ticket: Ticket;
56
+ };
57
+ export declare function parseSnapshot(value: unknown): Snapshot;
58
+ export declare function parseReceipt(value: unknown, requestId: string, session: Session, source: string): Receipt;
59
+ export declare function parseError(value: unknown): DatabaseError;
60
+ export declare function canonical(value: unknown): string;
61
+ export declare function operationKey(operation: Operation): string;
62
+ export declare function parsePage(value: unknown): {
63
+ range: string;
64
+ };
@@ -0,0 +1,77 @@
1
+ import { DatabaseError, applicationError } from "../error.js";
2
+ export const uuidPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
3
+ export function uuid(value) { if (typeof value !== "string" || !uuidPattern.test(value))
4
+ throw new TypeError("Invalid UUID"); return value; }
5
+ export function sequence(value) {
6
+ if (typeof value !== "string" || !/^(0|[1-9][0-9]*)$/.test(value) || BigInt(value) > (1n << 63n) - 1n)
7
+ throw new TypeError("Invalid sequence");
8
+ return value;
9
+ }
10
+ export function record(value, keys) {
11
+ if (typeof value !== "object" || value === null || Array.isArray(value)
12
+ || Object.keys(value).some(key => !keys.includes(key)) || keys.some(key => !Object.hasOwn(value, key)))
13
+ throw new TypeError("Invalid response envelope");
14
+ return value;
15
+ }
16
+ export function parseHead(value) {
17
+ const h = record(value, ["source", "scope", "principal", "authorization_scope", "revision"]);
18
+ return { source: uuid(h.source), scope: uuid(h.scope), principal: uuid(h.principal), authorization_scope: uuid(h.authorization_scope), revision: sequence(h.revision) };
19
+ }
20
+ export function parseSession(value) {
21
+ const { ticket, ...head } = record(value, ["source", "scope", "principal", "authorization_scope", "revision", "ticket"]);
22
+ const t = record(ticket, ["id", "expires_in_ms", "renew_after_ms"]);
23
+ if (!Number.isSafeInteger(t.expires_in_ms) || !Number.isSafeInteger(t.renew_after_ms)
24
+ || t.renew_after_ms < 1 || t.expires_in_ms <= t.renew_after_ms)
25
+ throw new TypeError("Invalid ticket duration");
26
+ return { ...parseHead(head), ticket: { id: uuid(t.id), expires_in_ms: t.expires_in_ms, renew_after_ms: t.renew_after_ms } };
27
+ }
28
+ export function parseSnapshot(value) {
29
+ const s = record(value, ["source", "scope", "principal", "authorization_scope", "revision", "result", ...(typeof value === "object" && value !== null && Object.hasOwn(value, "page") ? ["page"] : [])]);
30
+ const { result, page, ...head } = s;
31
+ return { ...parseHead(head), result, ...(page === undefined ? {} : { page: parsePage(page) }) };
32
+ }
33
+ export function parseReceipt(value, requestId, session, source) {
34
+ const r = record(value, ["request_id", "source", "scope", "revision", "result"]);
35
+ if (uuid(r.request_id) !== requestId || uuid(r.scope) !== session.scope || uuid(r.source) !== source)
36
+ throw new DatabaseError({ code: "reset_required", message: "reset_required" });
37
+ return { request_id: requestId, scope: session.scope, source, revision: sequence(r.revision), result: r.result };
38
+ }
39
+ export function parseError(value) {
40
+ const hasApplication = typeof value === "object" && value !== null && Object.hasOwn(value, "application");
41
+ const r = record(value, hasApplication ? ["code", "application"] : ["code"]);
42
+ if (hasApplication) {
43
+ if (r.code !== "execution_failed")
44
+ throw new TypeError("Invalid application error envelope");
45
+ const raw = r.application;
46
+ const payload = record(raw, ["code", "message", ...(typeof raw === "object" && raw !== null && Object.hasOwn(raw, "details") ? ["details"] : [])]);
47
+ const error = applicationError(payload);
48
+ if (new TextEncoder().encode(JSON.stringify(error)).length > 16 * 1024)
49
+ throw new TypeError("Application error exceeds budget");
50
+ return error;
51
+ }
52
+ const codes = ["unauthorized", "forbidden", "invalid_request", "not_found", "conflict", "execution_limit", "execution_failed", "row_expectation_failed", "quota_exceeded", "ticket_expired", "request_id_reused", "receipt_expired", "capacity", "unavailable", "reset_required", "outcome_unknown"];
53
+ if (typeof r.code !== "string" || !codes.includes(r.code))
54
+ throw new TypeError("Invalid remote error");
55
+ return new DatabaseError({ code: r.code, message: r.code });
56
+ }
57
+ export function canonical(value) {
58
+ if (Array.isArray(value))
59
+ return `[${value.map(canonical).join(",")}]`;
60
+ if (typeof value === "object" && value !== null)
61
+ return `{${Object.entries(value).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([key, v]) => `${JSON.stringify(key)}:${canonical(v)}`).join(",")}}`;
62
+ const encoded = JSON.stringify(value);
63
+ if (encoded === undefined)
64
+ throw new TypeError("Value is not a wire value");
65
+ return encoded;
66
+ }
67
+ export function operationKey(operation) {
68
+ if (!operation.codecs)
69
+ throw new TypeError("HTTP functions require generated value codecs");
70
+ return canonical([operation.name, operation.codecs.input.encode(operation.input), ...(operation.page ? [operation.page.owner] : [])]);
71
+ }
72
+ export function parsePage(value) {
73
+ const page = record(value, ["range"]);
74
+ if (typeof page.range !== "string" || !page.range || page.range.length > 65536)
75
+ throw new TypeError("Invalid page range");
76
+ return { range: page.range };
77
+ }
@@ -0,0 +1,7 @@
1
+ export interface SseEvent {
2
+ readonly event: string;
3
+ readonly id: string;
4
+ readonly data: string;
5
+ }
6
+ /** Incremental UTF-8 SSE parsing with bounded frames and native stream backpressure. */
7
+ export declare function sseEvents(body: ReadableStream<Uint8Array>, maxBytes: number, activity?: () => void, signal?: AbortSignal): AsyncGenerator<SseEvent>;
@@ -0,0 +1,70 @@
1
+ /** Incremental UTF-8 SSE parsing with bounded frames and native stream backpressure. */
2
+ export async function* sseEvents(body, maxBytes, activity = () => { }, signal) {
3
+ const reader = body.getReader();
4
+ const cancel = () => { void reader.cancel().catch(() => { }); };
5
+ signal?.addEventListener("abort", cancel, { once: true });
6
+ const decoder = new TextDecoder("utf-8", { fatal: true });
7
+ let line = "", event = "message", id = "", data = [], bytes = 0, pendingCR = false;
8
+ function consume(text) {
9
+ if (!text) {
10
+ const frame = data.length ? { event, id, data: data.join("\n") } : undefined;
11
+ event = "message";
12
+ id = "";
13
+ data = [];
14
+ bytes = 0;
15
+ return frame;
16
+ }
17
+ if (text.startsWith(":"))
18
+ return;
19
+ const colon = text.indexOf(":");
20
+ const field = colon < 0 ? text : text.slice(0, colon);
21
+ const value = colon < 0 ? "" : text.slice(colon + 1).replace(/^ /, "");
22
+ if (field === "event")
23
+ event = value;
24
+ if (field === "id") {
25
+ if (value.includes("\0"))
26
+ throw new TypeError("Invalid SSE ID");
27
+ id = value;
28
+ }
29
+ if (field === "data")
30
+ data.push(value);
31
+ }
32
+ try {
33
+ signal?.throwIfAborted();
34
+ while (true) {
35
+ const chunk = await reader.read();
36
+ signal?.throwIfAborted();
37
+ activity();
38
+ if (chunk.done) {
39
+ decoder.decode();
40
+ if (line || data.length)
41
+ throw new TypeError("Truncated SSE frame");
42
+ return;
43
+ }
44
+ for (const character of decoder.decode(chunk.value, { stream: true })) {
45
+ if (pendingCR && character === "\n") {
46
+ pendingCR = false;
47
+ continue;
48
+ }
49
+ pendingCR = character === "\r";
50
+ bytes += new TextEncoder().encode(character).length;
51
+ if (bytes > maxBytes)
52
+ throw new TypeError("SSE frame exceeds budget");
53
+ if (character === "\n" || character === "\r") {
54
+ const frame = consume(line);
55
+ line = "";
56
+ if (frame)
57
+ yield frame;
58
+ }
59
+ else {
60
+ line += character;
61
+ }
62
+ }
63
+ }
64
+ }
65
+ finally {
66
+ signal?.removeEventListener("abort", cancel);
67
+ cancel();
68
+ reader.releaseLock();
69
+ }
70
+ }
package/dist/http.d.ts ADDED
@@ -0,0 +1,44 @@
1
+ import type { CallOptions, FunctionRuntime, Operation, QueryState } from "./contracts.ts";
2
+ import type { FunctionCodecs } from "./codec.ts";
3
+ import { DatabaseError } from "./error.ts";
4
+ import { type ClientAuthInput } from "./auth.ts";
5
+ export interface HttpRuntimeOptions {
6
+ readonly baseUrl: string;
7
+ /** App-owned cache namespace. Never sent as identity or credentials. */
8
+ readonly auth?: ClientAuthInput;
9
+ /** Read current credentials for each request, independently of setAuth. */
10
+ readonly headers?: HeadersInit | (() => HeadersInit | Promise<HeadersInit>);
11
+ readonly credentials?: RequestCredentials;
12
+ readonly contracts: Readonly<Record<string, FunctionCodecs & {
13
+ readonly kind: "query" | "mutation";
14
+ }>>;
15
+ readonly fetch?: typeof globalThis.fetch;
16
+ readonly operationTimeoutMs?: number;
17
+ /** Overall deadline for one-shot reads, including connection recovery. */
18
+ readonly queryTimeoutMs?: number;
19
+ readonly streamIdleTimeoutMs?: number;
20
+ readonly maxResponseBytes?: number;
21
+ readonly reconnectDelayMs?: number;
22
+ /** Overall mutation confirmation budget, including submission and all receipt checks. */
23
+ readonly confirmationTimeoutMs?: number;
24
+ readonly maxOptimisticLayers?: number;
25
+ }
26
+ /** Generated function runtime. One owner coordinates in-memory exact-query subscriptions and receipt confirmation. */
27
+ export declare class HttpRuntime implements FunctionRuntime {
28
+ #private;
29
+ constructor(options: HttpRuntimeOptions);
30
+ get identityEpoch(): number;
31
+ get identitySignal(): AbortSignal;
32
+ get clientAuth(): {
33
+ key: string | null;
34
+ pending: boolean;
35
+ error?: DatabaseError;
36
+ };
37
+ call(raw: Operation, options?: CallOptions, onStatus?: (status: "recovering") => void): Promise<unknown>;
38
+ watch(raw: Operation & {
39
+ readonly kind: "query";
40
+ }, observer: (state: QueryState<unknown>) => void, options?: CallOptions): () => void;
41
+ /** Object/null updates apply immediately; promises infer loading until resolved. */
42
+ setAuth(state: ClientAuthInput): void | Promise<void>;
43
+ dispose(): Promise<void>;
44
+ }