@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,14 @@
1
+ import { type InvocationLimits, type DatabaseConnection } from "./config.ts";
2
+ import { type WriteDatabase } from "./database.ts";
3
+ import type { SchemaDefinition } from "./schema.ts";
4
+ export interface TransactionOptions {
5
+ readonly retries?: number;
6
+ }
7
+ export interface Database<S extends SchemaDefinition> extends WriteDatabase<S> {
8
+ transaction<T>(handler: (tx: WriteDatabase<S>) => T | PromiseLike<T>, options?: TransactionOptions): Promise<T>;
9
+ close(): Promise<void>;
10
+ }
11
+ /** Internal factory called by the generated server entrypoint. Importing is inert. */
12
+ export declare function createDatabase<S extends SchemaDefinition>(schema: S, connection: DatabaseConnection, overrides?: InvocationLimits): Database<S>;
13
+ /** Explicit CLI provisioning. Importing a server database never calls this. */
14
+ export declare function initializeDatabase(schema: SchemaDefinition, connection: DatabaseConnection): Promise<void>;
@@ -0,0 +1,386 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+ import { spawn } from "node:child_process";
3
+ import { resolveNativeExecutable } from "./native.js";
4
+ import { defineConfig, resolveLimits } from "./config.js";
5
+ import { transactionDatabase } from "./database.js";
6
+ import { DatabaseError } from "./error.js";
7
+ import { schemaDescriptor } from "./schema-contract.js";
8
+ const transactionScope = new AsyncLocalStorage();
9
+ const retryable = new WeakSet();
10
+ const idleMilliseconds = 10_000;
11
+ const maxWaiting = 64;
12
+ const failure = (code, message) => new DatabaseError({ code, message });
13
+ /** Private process protocol. It is never exposed over the application's network. */
14
+ class Bridge {
15
+ child;
16
+ stopped = new AbortController();
17
+ exited;
18
+ #killTimer;
19
+ #buffer = Buffer.alloc(0);
20
+ #pending;
21
+ idleSince = 0;
22
+ idleTimer;
23
+ dead = false;
24
+ inTransaction = false;
25
+ #committing = false;
26
+ limits;
27
+ maxFrame;
28
+ constructor(limits = resolveLimits()) {
29
+ this.limits = limits;
30
+ this.maxFrame = Math.max(limits.inputBytes, limits.outputBytes, limits.readBytes) + 2 * 1024 * 1024;
31
+ const engine = resolveNativeExecutable("bridge");
32
+ this.child = spawn(engine, [], { stdio: ["pipe", "pipe", "pipe"], env: {} });
33
+ this.exited = new Promise(resolve => this.child.once("close", () => {
34
+ clearTimeout(this.#killTimer);
35
+ resolve();
36
+ }));
37
+ // The native bridge sanitizes protocol errors. Never echo driver stderr,
38
+ // which may contain connection or operator details.
39
+ let diagnostics = "";
40
+ this.child.stderr.on("data", (chunk) => {
41
+ diagnostics += chunk.toString("utf8");
42
+ const lines = diagnostics.split("\n");
43
+ diagnostics = lines.pop().slice(-4096);
44
+ for (const line of lines)
45
+ if (line.startsWith("[hulla/db] "))
46
+ console.warn(line);
47
+ });
48
+ this.child.on("error", () => this.destroy(failure("engine_unavailable", "Cannot start the database engine; install/build hulladb-bridge or set HULLADB_ENGINE")));
49
+ this.child.on("exit", () => this.destroy());
50
+ this.child.stdin.on("error", () => this.destroy());
51
+ this.child.stdout.on("data", (chunk) => {
52
+ this.#buffer = Buffer.concat([this.#buffer, chunk]);
53
+ if (this.#buffer.length > this.maxFrame) {
54
+ this.destroy(failure("execution_limit", "Database response exceeds the transport budget"));
55
+ return;
56
+ }
57
+ let newline;
58
+ while ((newline = this.#buffer.indexOf(10)) !== -1) {
59
+ const line = this.#buffer.subarray(0, newline);
60
+ this.#buffer = this.#buffer.subarray(newline + 1);
61
+ const pending = this.#pending;
62
+ if (!pending) {
63
+ this.destroy();
64
+ return;
65
+ }
66
+ this.#pending = undefined;
67
+ clearTimeout(pending.timer);
68
+ try {
69
+ const value = JSON.parse(line.toString("utf8"));
70
+ if (typeof value !== "object" || value === null || Array.isArray(value))
71
+ throw new Error();
72
+ pending.resolve(value);
73
+ }
74
+ catch {
75
+ pending.reject(this.protocolFailure("Invalid database engine response"));
76
+ this.destroy();
77
+ return;
78
+ }
79
+ }
80
+ });
81
+ }
82
+ protocolFailure(message) {
83
+ return this.#committing
84
+ ? failure("commit_outcome_unknown", "Commit confirmation was lost; the transaction may have committed")
85
+ : failure("engine_protocol", message);
86
+ }
87
+ destroy(error) {
88
+ if (this.dead)
89
+ return;
90
+ this.dead = true;
91
+ clearTimeout(this.idleTimer);
92
+ const pending = this.#pending;
93
+ this.#pending = undefined;
94
+ if (pending) {
95
+ clearTimeout(pending.timer);
96
+ pending.reject(this.#committing ? this.protocolFailure("") : error ?? failure("engine_disconnected", "Database engine disconnected"));
97
+ }
98
+ this.stopped.abort(error ?? failure("engine_disconnected", "Database engine disconnected"));
99
+ this.child.kill();
100
+ if (this.child.exitCode === null && this.child.signalCode === null) {
101
+ this.#killTimer = setTimeout(() => this.child.kill("SIGKILL"), 2000);
102
+ this.#killTimer.unref();
103
+ }
104
+ }
105
+ async command(frame, expected) {
106
+ if (this.dead)
107
+ throw failure("engine_disconnected", "Database engine is closed");
108
+ if (this.#pending)
109
+ throw failure("engine_protocol", "Concurrent engine command");
110
+ const encoded = JSON.stringify(frame) + "\n";
111
+ if (Buffer.byteLength(encoded) > this.maxFrame)
112
+ throw failure("execution_limit", "Database request exceeds the transport budget");
113
+ this.#committing = frame.type === "commit";
114
+ const response = await new Promise((resolve, reject) => {
115
+ const timer = setTimeout(() => this.destroy(failure(this.#committing ? "commit_outcome_unknown" : "engine_timeout", "Database engine did not respond in time")), this.limits.executionMs + 1000);
116
+ this.#pending = { resolve, reject, timer };
117
+ this.child.stdin.write(encoded);
118
+ });
119
+ if (response.type === "error") {
120
+ if (this.#committing && response.rolledBack !== true) {
121
+ const error = this.protocolFailure("");
122
+ this.destroy();
123
+ throw error;
124
+ }
125
+ this.#committing = false;
126
+ const info = response.error;
127
+ const error = failure(typeof info?.code === "string" ? info.code : "database_failed", typeof info?.message === "string" ? info.message : "Database operation failed");
128
+ this.inTransaction = false;
129
+ if (response.rolledBack === true && error.code === "serialization_conflict")
130
+ retryable.add(error);
131
+ if (response.rolledBack !== true)
132
+ this.destroy();
133
+ throw error;
134
+ }
135
+ if (response.type !== expected) {
136
+ const error = this.protocolFailure("Unexpected database engine response");
137
+ this.destroy();
138
+ throw error;
139
+ }
140
+ this.#committing = false;
141
+ if (expected === "begun")
142
+ this.inTransaction = true;
143
+ if (expected === "committed" || expected === "rolled_back")
144
+ this.inTransaction = false;
145
+ return response;
146
+ }
147
+ }
148
+ /** Internal factory called by the generated server entrypoint. Importing is inert. */
149
+ export function createDatabase(schema, connection, overrides) {
150
+ const config = defineConfig({ database: { server: connection } }).database.server;
151
+ const limits = resolveLimits(overrides);
152
+ const descriptor = schemaDescriptor(schema);
153
+ const idle = [], sessions = new Set();
154
+ const waiters = [];
155
+ let available = 4, closed = false;
156
+ const assertRoot = () => {
157
+ if (closed)
158
+ throw failure("database_closed", "Database is closed");
159
+ if (transactionScope.getStore())
160
+ throw failure("transaction_scope", "Use the supplied tx inside a transaction, not the root database");
161
+ };
162
+ const releasePermit = () => {
163
+ const next = waiters.shift();
164
+ if (next)
165
+ next.resolve();
166
+ else
167
+ available++;
168
+ };
169
+ async function acquire() {
170
+ if (available > 0)
171
+ available--;
172
+ else {
173
+ if (waiters.length >= maxWaiting)
174
+ throw failure("capacity", "Database connection queue is full");
175
+ await new Promise((resolve, reject) => {
176
+ const waiter = {
177
+ resolve: () => { clearTimeout(timer); resolve(); },
178
+ reject: (error) => { clearTimeout(timer); reject(error); },
179
+ };
180
+ const timer = setTimeout(() => {
181
+ const index = waiters.indexOf(waiter);
182
+ if (index !== -1)
183
+ waiters.splice(index, 1);
184
+ reject(failure("database_timeout", "Timed out waiting for a database connection"));
185
+ }, limits.executionMs);
186
+ waiters.push(waiter);
187
+ });
188
+ }
189
+ try {
190
+ if (closed)
191
+ throw failure("database_closed", "Database is closed");
192
+ let session;
193
+ while ((session = idle.pop())) {
194
+ clearTimeout(session.idleTimer);
195
+ if (!session.dead && Date.now() - session.idleSince < idleMilliseconds) {
196
+ try {
197
+ await session.command({ type: "ping" }, "pong");
198
+ return session;
199
+ }
200
+ catch {
201
+ session.destroy();
202
+ }
203
+ }
204
+ session.destroy();
205
+ await session.exited;
206
+ sessions.delete(session);
207
+ }
208
+ if (closed)
209
+ throw failure("database_closed", "Database is closed");
210
+ session = new Bridge(limits);
211
+ sessions.add(session);
212
+ try {
213
+ await session.command({ type: "init", url: config.url, namespace: config.namespace ?? "hulla", schema: descriptor, limits, development: process.env.NODE_ENV !== "production" }, "ready");
214
+ return session;
215
+ }
216
+ catch (error) {
217
+ session.destroy();
218
+ await session.exited;
219
+ sessions.delete(session);
220
+ throw error;
221
+ }
222
+ }
223
+ catch (error) {
224
+ releasePermit();
225
+ throw error;
226
+ }
227
+ }
228
+ async function release(session) {
229
+ if (!closed && !session.dead) {
230
+ session.idleSince = Date.now();
231
+ idle.push(session);
232
+ session.idleTimer = setTimeout(() => {
233
+ const index = idle.indexOf(session);
234
+ if (index === -1)
235
+ return;
236
+ idle.splice(index, 1);
237
+ session.destroy();
238
+ void session.exited.then(() => sessions.delete(session));
239
+ }, idleMilliseconds);
240
+ session.idleTimer.unref();
241
+ }
242
+ else {
243
+ session.destroy();
244
+ await session.exited;
245
+ sessions.delete(session);
246
+ }
247
+ releasePermit();
248
+ }
249
+ async function execute(writable, handler, scoped) {
250
+ assertRoot();
251
+ const session = await acquire();
252
+ let active = true, pending = 0, sequence = 0;
253
+ const token = {};
254
+ let tail = Promise.resolve();
255
+ let statementError;
256
+ let statementFailed = false;
257
+ const deadline = setTimeout(() => session.destroy(failure("transaction_timeout", "Database transaction exceeded its execution deadline")), limits.executionMs);
258
+ const request = (operation, validate) => {
259
+ if (!active || closed)
260
+ return Promise.reject(failure("transaction_closed", "Transaction handle is no longer active"));
261
+ if (scoped && transactionScope.getStore() !== token)
262
+ return Promise.reject(failure("transaction_scope", "Use the transaction handle only inside its callback"));
263
+ if (pending >= maxWaiting) {
264
+ statementError = failure("capacity", "Too many queued operations in one transaction");
265
+ statementFailed = true;
266
+ return Promise.reject(statementError);
267
+ }
268
+ pending++;
269
+ const result = tail.then(async () => {
270
+ if (!active || closed)
271
+ throw failure("transaction_closed", "Transaction handle is no longer active");
272
+ const id = ++sequence;
273
+ const response = await session.command({ type: "operation", id, operation }, "operation_result");
274
+ if (response.id !== id) {
275
+ session.destroy();
276
+ throw failure("engine_protocol", "Database operation response does not match its request");
277
+ }
278
+ // Validation belongs to the statement's queue entry, before commit. Its
279
+ // failure poisons the transaction even if the application catches it.
280
+ validate?.(response.result);
281
+ return response.result;
282
+ }).catch(error => { statementError = error; statementFailed = true; throw error; }).finally(() => { pending--; });
283
+ tail = result;
284
+ void result.catch(() => { });
285
+ return result;
286
+ };
287
+ try {
288
+ await session.command({ type: "begin", mode: writable ? "write" : "read" }, "begun");
289
+ const tx = transactionDatabase(schema, writable, request);
290
+ const signal = session.stopped.signal;
291
+ let stopped;
292
+ let result;
293
+ try {
294
+ signal.throwIfAborted();
295
+ result = await Promise.race([
296
+ Promise.resolve().then(() => { signal.throwIfAborted(); return transactionScope.run(token, () => handler(tx, request)); }),
297
+ new Promise((_, reject) => {
298
+ stopped = () => reject(signal.reason);
299
+ signal.addEventListener("abort", stopped, { once: true });
300
+ }),
301
+ ]);
302
+ }
303
+ finally {
304
+ if (stopped)
305
+ signal.removeEventListener("abort", stopped);
306
+ }
307
+ active = false;
308
+ if (pending) {
309
+ session.destroy();
310
+ throw failure("unawaited_operations", "Await all database operations before returning from a transaction");
311
+ }
312
+ if (statementFailed)
313
+ throw statementError;
314
+ await session.command({ type: "commit" }, "committed");
315
+ return result;
316
+ }
317
+ catch (error) {
318
+ active = false;
319
+ if (pending)
320
+ session.destroy();
321
+ if (session.inTransaction && !session.dead) {
322
+ try {
323
+ await session.command({ type: "rollback" }, "rolled_back");
324
+ }
325
+ catch {
326
+ session.destroy();
327
+ }
328
+ }
329
+ throw error;
330
+ }
331
+ finally {
332
+ clearTimeout(deadline);
333
+ active = false;
334
+ await release(session);
335
+ }
336
+ }
337
+ const root = transactionDatabase(schema, true, (operation, validate) => execute(!["select", "paginate", "aggregate"].includes(operation.method), (_tx, request) => request(operation, validate), false));
338
+ return Object.freeze({
339
+ ...root,
340
+ async transaction(handler, options = {}) {
341
+ assertRoot();
342
+ if (typeof handler !== "function" || typeof options !== "object" || options === null
343
+ || Reflect.ownKeys(options).some(key => key !== "retries")
344
+ || !Number.isInteger(options.retries ?? 0) || (options.retries ?? 0) < 0 || (options.retries ?? 0) > 100)
345
+ throw new TypeError("Invalid transaction options");
346
+ for (let attempt = 0;; attempt++) {
347
+ try {
348
+ return await execute(true, handler, true);
349
+ }
350
+ catch (error) {
351
+ if (!(error instanceof DatabaseError) || !retryable.has(error) || attempt >= (options.retries ?? 0))
352
+ throw error;
353
+ await new Promise(resolve => setTimeout(resolve, Math.min(5 * 2 ** attempt, 100) * Math.random()));
354
+ }
355
+ }
356
+ },
357
+ async close() {
358
+ if (transactionScope.getStore())
359
+ throw failure("transaction_scope", "Close the database outside its transaction callback");
360
+ if (closed)
361
+ return;
362
+ closed = true;
363
+ for (const waiter of waiters.splice(0))
364
+ waiter.reject(failure("database_closed", "Database is closed"));
365
+ const exiting = [...sessions].map(session => {
366
+ session.destroy(failure("database_closed", "Database is closed"));
367
+ return session.exited;
368
+ });
369
+ idle.length = 0;
370
+ sessions.clear();
371
+ await Promise.all(exiting);
372
+ },
373
+ });
374
+ }
375
+ /** Explicit CLI provisioning. Importing a server database never calls this. */
376
+ export async function initializeDatabase(schema, connection) {
377
+ const config = defineConfig({ database: { server: connection } }).database.server;
378
+ const session = new Bridge();
379
+ try {
380
+ await session.command({ type: "init", url: config.url, namespace: config.namespace ?? "hulla", schema: schemaDescriptor(schema), initialize: true }, "ready");
381
+ }
382
+ finally {
383
+ session.destroy();
384
+ await session.exited;
385
+ }
386
+ }
@@ -0,0 +1,7 @@
1
+ export { createDatabase } from "./server-database.ts";
2
+ export type { Database, TransactionOptions } from "./server-database.ts";
3
+ export type { ReadDatabase, WriteDatabase, QueryContext, MutationContext, DatabaseOperation, SelectQuery, WriteQuery, PendingWrite, InsertQuery, RowExpectation, ConflictSelector, ConflictPolicy, ConflictTargets, UpdateInput, WriteReferences, WriteReference, WriteValue, WritePatch } from "./database.ts";
4
+ export type { Projection, Projected } from "./projection.ts";
5
+ export type { Aggregates, AggregateValue, AggregateResult, GroupedQuery, GroupedAggregate } from "./aggregate.ts";
6
+ export type { Page, PageOptions } from "./page.ts";
7
+ export type { Expressions, Predicate } from "./filters.ts";
package/dist/server.js ADDED
@@ -0,0 +1 @@
1
+ export { createDatabase } from "./server-database.js";
@@ -0,0 +1,13 @@
1
+ import { type VerifyIdentity } from "./config.ts";
2
+ /** Private bridge context. Only a trusted verifier result can reach this function. */
3
+ export declare function verifyServiceIdentity(verify: VerifyIdentity | undefined, headers: Headers): Promise<{
4
+ principal: string;
5
+ authorizationScope: string;
6
+ identity: unknown;
7
+ }>;
8
+ /** Runtime-only launcher. The native host owns HTTP/SSE, transactions and revalidation. */
9
+ export declare function startService(configPath: string): Promise<{
10
+ url: string;
11
+ close(): Promise<void>;
12
+ closed: Promise<void>;
13
+ }>;
@@ -0,0 +1,206 @@
1
+ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
2
+ if (typeof path === "string" && /^\.\.?\//.test(path)) {
3
+ return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
4
+ return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
5
+ });
6
+ }
7
+ return path;
8
+ };
9
+ import { spawn } from "node:child_process";
10
+ import { createHash } from "node:crypto";
11
+ import { access, readFile } from "node:fs/promises";
12
+ import { constants } from "node:fs";
13
+ import { dirname, resolve } from "node:path";
14
+ import { pathToFileURL } from "node:url";
15
+ import { defineConfig } from "./config.js";
16
+ import { resolveNativeExecutable } from "./native.js";
17
+ import { schemaDescriptor } from "./schema-contract.js";
18
+ class VerificationTimeout extends Error {
19
+ }
20
+ function canonical(value, depth = 0) {
21
+ if (depth > 64)
22
+ throw new TypeError("Identity nesting exceeds the supported depth");
23
+ if (value === null || typeof value === "string" || typeof value === "boolean")
24
+ return value;
25
+ if (typeof value === "number" && Number.isFinite(value))
26
+ return value;
27
+ if (Array.isArray(value))
28
+ return value.map(item => canonical(item, depth + 1));
29
+ if (typeof value === "object" && value !== null && [Object.prototype, null].includes(Object.getPrototypeOf(value))) {
30
+ const result = Object.create(null);
31
+ for (const key of Reflect.ownKeys(value).sort()) {
32
+ if (typeof key !== "string")
33
+ throw new TypeError("Identity must be JSON data");
34
+ result[key] = canonical(value[key], depth + 1);
35
+ }
36
+ return result;
37
+ }
38
+ throw new TypeError("Identity must be JSON data");
39
+ }
40
+ function identityId(value) {
41
+ const hex = createHash("sha256").update(JSON.stringify(value)).digest("hex").slice(0, 32);
42
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
43
+ }
44
+ /** Private bridge context. Only a trusted verifier result can reach this function. */
45
+ export async function verifyServiceIdentity(verify, headers) {
46
+ let timer;
47
+ let verified;
48
+ try {
49
+ verified = verify ? await Promise.race([
50
+ Promise.resolve().then(() => verify(headers)),
51
+ new Promise((_, reject) => { timer = setTimeout(() => reject(new VerificationTimeout("Authentication verification timed out")), 5000); }),
52
+ ]) : null;
53
+ }
54
+ finally {
55
+ clearTimeout(timer);
56
+ }
57
+ if (verified !== null && (typeof verified !== "object" || typeof verified.key !== "string" || !verified.key.trim() || verified.key.length > 1024))
58
+ throw new TypeError("Auth verifier must return a key and JSON identity, or null");
59
+ const identity = verified === null ? null : canonical(verified.identity);
60
+ if (Buffer.byteLength(JSON.stringify(identity)) > 1024 * 1024)
61
+ throw new TypeError("Verified identity exceeds the transport budget");
62
+ const principal = verified === null ? ["anonymous"] : ["authenticated", verified.key];
63
+ return { principal: identityId(principal), authorizationScope: identityId([principal, identity]), identity };
64
+ }
65
+ /** Runtime-only launcher. The native host owns HTTP/SSE, transactions and revalidation. */
66
+ export async function startService(configPath) {
67
+ const config = defineConfig((await import(__rewriteRelativeImportExtension(pathToFileURL(resolve(configPath)).href))).default);
68
+ const schemaPath = resolve(dirname(resolve(configPath)), config.schema ?? "db/schema.ts");
69
+ const schema = (await import(__rewriteRelativeImportExtension(pathToFileURL(schemaPath).href))).default;
70
+ const generated = resolve(dirname(schemaPath), "_generated");
71
+ const bundle = resolve(generated, "worker.js");
72
+ let manifest;
73
+ try {
74
+ manifest = await readFile(resolve(generated, "client/functions.json"), "utf8");
75
+ await access(bundle, constants.R_OK);
76
+ }
77
+ catch {
78
+ throw new Error("Cannot read generated service artifacts; run hulla-db generate with Bun before serve and include the generated directory in your deployment");
79
+ }
80
+ const executable = resolveNativeExecutable("service");
81
+ const child = spawn(executable, [], { stdio: ["pipe", "pipe", "pipe"], env: {} });
82
+ let diagnostics = "";
83
+ child.stderr.on("data", (chunk) => {
84
+ diagnostics += chunk.toString("utf8");
85
+ const lines = diagnostics.split("\n");
86
+ diagnostics = lines.pop().slice(-4096);
87
+ for (const line of lines)
88
+ if (line.startsWith("[hulla/db] "))
89
+ console.warn(line);
90
+ });
91
+ let buffer = Buffer.alloc(0), stopping = false, settled = false, pendingAuth = 0;
92
+ let ready, startupFailed;
93
+ const startup = new Promise((resolve, reject) => { ready = resolve; startupFailed = reject; });
94
+ let exited, failed;
95
+ const closed = new Promise((resolve, reject) => { exited = resolve; failed = reject; });
96
+ void closed.catch(() => { });
97
+ const fail = (message) => {
98
+ const error = new Error(message);
99
+ startupFailed(error);
100
+ failed(error);
101
+ child.kill();
102
+ };
103
+ const send = (frame) => { if (!stopping && !child.stdin.destroyed)
104
+ child.stdin.write(JSON.stringify(frame) + "\n"); };
105
+ child.on("error", () => fail("Cannot start hulladb-service; build the native service or set HULLADB_SERVICE"));
106
+ child.stdin.on("error", () => { if (!stopping)
107
+ fail("Database service disconnected"); });
108
+ child.on("exit", code => {
109
+ settled = true;
110
+ startupFailed(new Error("Database service exited before startup completed"));
111
+ if (stopping || code === 0)
112
+ exited();
113
+ else
114
+ failed(new Error("Database service stopped unexpectedly"));
115
+ });
116
+ child.stdout.on("data", (chunk) => {
117
+ buffer = Buffer.concat([buffer, chunk]);
118
+ if (buffer.length > 66 * 1024 * 1024) {
119
+ fail("Database service frame exceeds its transport budget");
120
+ return;
121
+ }
122
+ let newline;
123
+ while ((newline = buffer.indexOf(10)) !== -1) {
124
+ const line = buffer.subarray(0, newline);
125
+ buffer = buffer.subarray(newline + 1);
126
+ let frame;
127
+ try {
128
+ frame = JSON.parse(line.toString("utf8"));
129
+ if (!frame || typeof frame !== "object")
130
+ throw new Error();
131
+ }
132
+ catch {
133
+ fail("Invalid database service response");
134
+ return;
135
+ }
136
+ if (frame.type === "ready" && typeof frame.url === "string")
137
+ ready(frame.url);
138
+ else if (frame.type === "authenticate" && Number.isSafeInteger(frame.id) && Array.isArray(frame.headers)) {
139
+ const { id, headers } = frame;
140
+ if (pendingAuth >= 64) {
141
+ send({ type: "authenticated", id, context: null, unavailable: true });
142
+ continue;
143
+ }
144
+ pendingAuth++;
145
+ void (async () => {
146
+ let context = null;
147
+ let unavailable = false;
148
+ try {
149
+ context = await verifyServiceIdentity(config.auth, new Headers(headers));
150
+ }
151
+ catch (error) {
152
+ unavailable = error instanceof VerificationTimeout;
153
+ }
154
+ finally {
155
+ pendingAuth--;
156
+ }
157
+ send({ type: "authenticated", id, context, unavailable });
158
+ })();
159
+ }
160
+ else if (frame.type === "error" && typeof frame.message === "string") {
161
+ // The supplied native binary emits only static, sanitized diagnostics.
162
+ fail(frame.message);
163
+ return;
164
+ }
165
+ else {
166
+ fail("Database service startup or protocol failed");
167
+ return;
168
+ }
169
+ }
170
+ });
171
+ async function close() {
172
+ if (!stopping) {
173
+ if (!settled)
174
+ send({ type: "shutdown" });
175
+ stopping = true;
176
+ child.stdin.end();
177
+ }
178
+ const timer = setTimeout(() => child.kill("SIGKILL"), 2000);
179
+ try {
180
+ await closed;
181
+ }
182
+ finally {
183
+ clearTimeout(timer);
184
+ }
185
+ }
186
+ const timer = setTimeout(() => fail("Database service startup timed out"), 30_000);
187
+ try {
188
+ send({ type: "init", url: config.database.server.url, namespace: config.database.server.namespace ?? "hulla",
189
+ schema: schemaDescriptor(schema), manifest, development: process.env.NODE_ENV !== "production",
190
+ worker: {
191
+ executable: resolveNativeExecutable("js"),
192
+ entrypoint: bundle,
193
+ },
194
+ host: config.service?.host ?? "127.0.0.1", port: config.service?.port ?? 3001,
195
+ origins: config.service?.origins ?? [],
196
+ });
197
+ return { url: await startup, close, closed };
198
+ }
199
+ catch (error) {
200
+ await close().catch(() => { });
201
+ throw error;
202
+ }
203
+ finally {
204
+ clearTimeout(timer);
205
+ }
206
+ }
@@ -0,0 +1,28 @@
1
+ declare const fieldBrand: unique symbol;
2
+ declare const checkBrand: unique symbol;
3
+ export interface CheckColumn {
4
+ readonly [fieldBrand]: string;
5
+ }
6
+ export type CheckFields<K extends string> = {
7
+ readonly [P in K]: CheckColumn;
8
+ };
9
+ export type CheckLiteral = string | number | bigint | boolean | null;
10
+ export type CheckOperand = {
11
+ readonly field: string;
12
+ } | {
13
+ readonly value: CheckLiteral;
14
+ };
15
+ export interface SqlCheck {
16
+ readonly [checkBrand]: true;
17
+ readonly parts: readonly string[];
18
+ readonly operands: readonly CheckOperand[];
19
+ }
20
+ export interface CompiledCheck {
21
+ readonly name: string;
22
+ readonly parts: readonly string[];
23
+ readonly operands: readonly CheckOperand[];
24
+ }
25
+ /** Trusted SQL expression text; interpolated fields and values are quoted separately. */
26
+ export declare function sql(parts: TemplateStringsArray, ...values: readonly (CheckColumn | SqlCheck | CheckLiteral)[]): SqlCheck;
27
+ export declare function compileChecks<const K extends string>(callback: ((fields: CheckFields<K>) => Readonly<Record<string, SqlCheck>>) | undefined, fields: readonly K[], _primaryKey: string): readonly CompiledCheck[];
28
+ export {};