@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,70 @@
1
+ import type { BrowserOptions } from "./browser.ts";
2
+ /** Per-invocation budgets. Encoded byte budgets exclude protocol envelopes. */
3
+ export interface InvocationLimits {
4
+ readonly executionMs?: number;
5
+ readonly inputBytes?: number;
6
+ readonly outputBytes?: number;
7
+ readonly memoryBytes?: number;
8
+ readonly stackBytes?: number;
9
+ readonly operations?: number;
10
+ /** Rows actually returned by database operations, not rows scanned by SQL. */
11
+ readonly readRows?: number;
12
+ /** Fetched PostgreSQL binary column payloads, excluding transport framing. */
13
+ readonly readBytes?: number;
14
+ }
15
+ export declare const defaultLimits: Readonly<{
16
+ executionMs: 5000;
17
+ inputBytes: number;
18
+ outputBytes: number;
19
+ memoryBytes: number;
20
+ stackBytes: number;
21
+ operations: 1000;
22
+ readRows: 100000;
23
+ readBytes: number;
24
+ }>;
25
+ export type ResolvedLimits = Readonly<Required<InvocationLimits>>;
26
+ export declare function validateLimits(value: InvocationLimits): Readonly<InvocationLimits>;
27
+ export declare function resolveLimits(value?: InvocationLimits): ResolvedLimits;
28
+ /** Ordinary server connection settings. Never included in generated client code. */
29
+ export interface DatabaseConnection {
30
+ readonly url: string;
31
+ readonly namespace?: string;
32
+ }
33
+ /** Verified provider data; never accepted as proof from a browser payload. */
34
+ export interface VerifiedIdentity {
35
+ readonly key: string;
36
+ readonly identity: unknown;
37
+ }
38
+ export type VerifyIdentity = (headers: Headers) => VerifiedIdentity | null | PromiseLike<VerifiedIdentity | null>;
39
+ export interface ServiceOptions {
40
+ readonly host?: string;
41
+ readonly port?: number;
42
+ /** Browser application origins allowed to call the service. */
43
+ readonly origins?: readonly string[];
44
+ }
45
+ /** Public build-time settings copied into generated browser modules. */
46
+ export type ClientConnection = Omit<BrowserOptions, "auth" | "headers">;
47
+ export declare function clientConnection(value: ClientConnection): Readonly<ClientConnection>;
48
+ export interface DatabaseConfig {
49
+ readonly database: {
50
+ readonly server: DatabaseConnection;
51
+ readonly client?: ClientConnection;
52
+ };
53
+ readonly limits?: InvocationLimits;
54
+ /** Resolved relative to this config file. Defaults to ./db/schema.ts. */
55
+ readonly schema?: string;
56
+ /** Optional discovery root. Defaults to the schema's directory. */
57
+ readonly functions?: string;
58
+ /** Return null for anonymous access; throw for invalid/expired credentials. */
59
+ readonly auth?: VerifyIdentity;
60
+ readonly service?: ServiceOptions;
61
+ }
62
+ export type ConfigIdentity<C> = C extends {
63
+ readonly auth?: infer Verify;
64
+ } ? NonNullable<Verify> extends (...args: never[]) => infer Result ? [Exclude<Awaited<Result>, null>] extends [never] ? null : Exclude<Awaited<Result>, null> extends {
65
+ readonly identity: infer Identity;
66
+ } ? Identity | null : null : null : null;
67
+ /** Validate configuration without opening connections, reading files, or starting a listener. */
68
+ export declare function defineConfig<C extends DatabaseConfig>(config: C): Readonly<C & {
69
+ readonly limits?: InvocationLimits;
70
+ }>;
package/dist/config.js ADDED
@@ -0,0 +1,100 @@
1
+ export const defaultLimits = Object.freeze({ executionMs: 5000, inputBytes: 16 * 1024 * 1024,
2
+ outputBytes: 16 * 1024 * 1024, memoryBytes: 64 * 1024 * 1024, stackBytes: 512 * 1024,
3
+ operations: 1000, readRows: 100_000, readBytes: 64 * 1024 * 1024 });
4
+ const ceilings = { executionMs: 60_000, inputBytes: 64 * 1024 * 1024,
5
+ outputBytes: 64 * 1024 * 1024, memoryBytes: 1024 * 1024 * 1024, stackBytes: 16 * 1024 * 1024,
6
+ operations: 1_000_000, readRows: 1_000_000, readBytes: 64 * 1024 * 1024 };
7
+ export function validateLimits(value) {
8
+ record(value, Object.keys(defaultLimits), "limits");
9
+ for (const [key, setting] of Object.entries(value)) {
10
+ const ceiling = ceilings[key];
11
+ if (typeof setting !== "number" || !Number.isSafeInteger(setting) || setting < 1 || setting > ceiling)
12
+ throw new TypeError(`limits.${key} must be an integer from 1 to ${ceiling}`);
13
+ }
14
+ return Object.freeze({ ...value });
15
+ }
16
+ export function resolveLimits(value) {
17
+ return Object.freeze({ ...defaultLimits, ...(value === undefined ? {} : validateLimits(value)) });
18
+ }
19
+ export function clientConnection(value) {
20
+ record(value, ["url", "credentials", "operationTimeoutMs", "queryTimeoutMs", "streamIdleTimeoutMs", "confirmationTimeoutMs"], "database.client");
21
+ if (typeof value.url !== "string")
22
+ throw new TypeError("database.client.url must be an HTTP endpoint or root-relative path");
23
+ const relative = value.url.startsWith("/") && !value.url.startsWith("//");
24
+ let url;
25
+ try {
26
+ url = new URL(value.url, relative ? "https://client.invalid" : undefined);
27
+ }
28
+ catch {
29
+ throw new TypeError("Invalid database.client.url");
30
+ }
31
+ if (url.username || url.password || url.search || url.hash || /[\\\s]/.test(value.url)
32
+ || !(url.protocol === "https:" || (url.protocol === "http:" && ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname))))
33
+ throw new TypeError("Use HTTPS or loopback HTTP without URL credentials for database.client.url");
34
+ if (value.credentials !== undefined && !["omit", "same-origin", "include"].includes(value.credentials))
35
+ throw new TypeError("Invalid database.client.credentials");
36
+ for (const key of ["operationTimeoutMs", "queryTimeoutMs", "streamIdleTimeoutMs", "confirmationTimeoutMs"])
37
+ if (value[key] !== undefined && (!Number.isSafeInteger(value[key]) || value[key] < 1 || value[key] > 2_147_483_647))
38
+ throw new TypeError(`Invalid database.client.${key}`);
39
+ return Object.freeze({ ...value });
40
+ }
41
+ function record(value, keys, name) {
42
+ if (typeof value !== "object" || value === null || Array.isArray(value)
43
+ || ![Object.prototype, null].includes(Object.getPrototypeOf(value))
44
+ || Reflect.ownKeys(value).some(key => typeof key !== "string" || !keys.includes(key)))
45
+ throw new TypeError(`Invalid ${name} configuration`);
46
+ }
47
+ /** Validate configuration without opening connections, reading files, or starting a listener. */
48
+ export function defineConfig(config) {
49
+ record(config, ["database", "schema", "functions", "auth", "service", "limits"], "database");
50
+ record(config.database, ["server", "client"], "database connection");
51
+ record(config.database.server, ["url", "namespace"], "database.server");
52
+ const { url, namespace } = config.database.server;
53
+ if (typeof url !== "string" || !url.trim())
54
+ throw new TypeError("database.server.url must be a PostgreSQL connection URL");
55
+ try {
56
+ const parsed = new URL(url);
57
+ if (!["postgres:", "postgresql:"].includes(parsed.protocol))
58
+ throw new Error();
59
+ }
60
+ catch {
61
+ throw new TypeError("database.server.url must be a PostgreSQL connection URL");
62
+ }
63
+ if (namespace !== undefined && (typeof namespace !== "string" || !/^[a-z_][a-z0-9_]{0,62}$/.test(namespace)))
64
+ throw new TypeError("database.server.namespace must be a PostgreSQL identifier of at most 63 characters");
65
+ for (const key of ["schema", "functions"])
66
+ if (config[key] !== undefined && (typeof config[key] !== "string" || !config[key].trim()))
67
+ throw new TypeError(`${key} must be a nonempty path`);
68
+ if (config.auth !== undefined && typeof config.auth !== "function")
69
+ throw new TypeError("auth must verify credentials with a callback");
70
+ if (config.service !== undefined) {
71
+ record(config.service, ["host", "port", "origins"], "service");
72
+ const { host, port, origins } = config.service;
73
+ if (host !== undefined && (typeof host !== "string" || !host.trim() || /[\s/]/.test(host)))
74
+ throw new TypeError("service.host must be a hostname or IP address");
75
+ if (port !== undefined && (!Number.isInteger(port) || port < 0 || port > 65535))
76
+ throw new TypeError("service.port must be an integer from 0 to 65535");
77
+ if (origins !== undefined && (!Array.isArray(origins) || origins.some(origin => {
78
+ try {
79
+ const value = new URL(origin);
80
+ return typeof origin !== "string" || value.origin !== origin || !["http:", "https:"].includes(value.protocol);
81
+ }
82
+ catch {
83
+ return true;
84
+ }
85
+ })))
86
+ throw new TypeError("service.origins must contain exact HTTP(S) origins");
87
+ }
88
+ const limits = config.limits === undefined ? undefined : validateLimits(config.limits);
89
+ return Object.freeze({
90
+ ...(limits === undefined ? {} : { limits }),
91
+ database: Object.freeze({ server: Object.freeze({ url, ...(namespace === undefined ? {} : { namespace }) }),
92
+ ...(config.database.client === undefined ? {} : { client: clientConnection(config.database.client) }) }),
93
+ ...(config.schema === undefined ? {} : { schema: config.schema }),
94
+ ...(config.functions === undefined ? {} : { functions: config.functions }),
95
+ ...(config.auth === undefined ? {} : { auth: config.auth }),
96
+ ...(config.service === undefined ? {} : { service: Object.freeze({ ...config.service,
97
+ ...(config.service.origins === undefined ? {} : { origins: Object.freeze([...config.service.origins]) }),
98
+ }) }),
99
+ });
100
+ }
@@ -0,0 +1,109 @@
1
+ export type FunctionKind = "query" | "mutation";
2
+ /** Signature metadata is type-only; browser modules never import handlers. */
3
+ export interface FunctionSignature {
4
+ readonly kind: FunctionKind;
5
+ readonly $types?: {
6
+ readonly input: unknown;
7
+ readonly output: unknown;
8
+ };
9
+ }
10
+ /** Shared type-only metadata for generated query and mutation callables. */
11
+ export declare const functionSignature: unique symbol;
12
+ export interface FunctionReference<D extends FunctionSignature = FunctionSignature> {
13
+ readonly [functionSignature]?: D;
14
+ }
15
+ type DefinitionOf<T extends FunctionSignature | FunctionReference> = T extends FunctionSignature ? T : T extends FunctionReference<infer D> ? D : never;
16
+ /** Submitted input, before schema transforms. No-input functions use undefined. */
17
+ export type Input<T extends FunctionSignature | FunctionReference> = NonNullable<DefinitionOf<T>["$types"]>["input"];
18
+ /** Public result after schema transforms; query results are shared and readonly. */
19
+ export type Output<T extends FunctionSignature | FunctionReference> = DefinitionOf<T>["kind"] extends "query" ? ReadonlyResult<NonNullable<DefinitionOf<T>["$types"]>["output"]> : NonNullable<DefinitionOf<T>["$types"]>["output"];
20
+ /** Ordinary query result objects and arrays are shared, and must be copied before editing.
21
+ * Built-ins such as Date retain their methods; readonly properties do not freeze their internals. */
22
+ export type ReadonlyResult<T> = T extends string | number | bigint | boolean | symbol | null | undefined | Date | ((...args: never[]) => unknown) ? T : T extends object ? {
23
+ readonly [K in keyof T]: ReadonlyResult<T[K]>;
24
+ } : T;
25
+ export interface Operation {
26
+ readonly name: string;
27
+ readonly kind: FunctionKind;
28
+ readonly input: unknown;
29
+ readonly codecs?: import("./codec.ts").FunctionCodecs;
30
+ /** Internal pagination ownership; range is learned from a complete live round. */
31
+ readonly page?: {
32
+ readonly owner: string;
33
+ range?: string;
34
+ };
35
+ }
36
+ /** Internal adapter options. Mutation signals are deliberately absent from generated bindings. */
37
+ export interface CallOptions {
38
+ readonly signal?: AbortSignal;
39
+ readonly optimistic?: import("./optimistic.ts").Predictor;
40
+ }
41
+ export type QueryOptions = Pick<CallOptions, "signal">;
42
+ export interface QuerySubscriptionOptions extends QueryOptions {
43
+ readonly keepPreviousDataOnError?: boolean;
44
+ }
45
+ type QueryIndicators = {
46
+ readonly isStale?: boolean;
47
+ readonly isOptimistic?: boolean;
48
+ };
49
+ export type QueryState<T> = ({
50
+ readonly status: "pending";
51
+ readonly data?: ReadonlyResult<T>;
52
+ } & QueryIndicators) | {
53
+ readonly status: "success";
54
+ readonly data: ReadonlyResult<T>;
55
+ readonly isStale: boolean;
56
+ readonly isOptimistic: boolean;
57
+ } | ({
58
+ readonly status: "error";
59
+ readonly error: unknown;
60
+ readonly data?: ReadonlyResult<T>;
61
+ } & QueryIndicators);
62
+ export type MutationState<T> = {
63
+ readonly status: "pending" | "recovering";
64
+ } | {
65
+ readonly status: "success";
66
+ readonly data: T;
67
+ } | {
68
+ readonly status: "error";
69
+ readonly error: unknown;
70
+ };
71
+ export interface QueryHandle<T> extends PromiseLike<ReadonlyResult<T>> {
72
+ readonly status: QueryState<T>["status"];
73
+ readonly data: ReadonlyResult<T> | undefined;
74
+ readonly error: unknown;
75
+ readonly isStale: boolean;
76
+ readonly isOptimistic: boolean;
77
+ subscribe(listener: (state: QueryState<T>) => void, options?: QuerySubscriptionOptions): () => void;
78
+ }
79
+ export interface MutationHandle<T> extends PromiseLike<T> {
80
+ readonly status: MutationState<T>["status"];
81
+ readonly data: T | undefined;
82
+ readonly error: unknown;
83
+ subscribe(listener: (state: MutationState<T>) => void): () => void;
84
+ }
85
+ /** Adapter boundary. The host, not a callable wrapper, owns retries and state. */
86
+ export interface FunctionRuntime {
87
+ /** Local cache context for UI bindings, never proof of server identity. */
88
+ readonly clientAuth?: {
89
+ readonly key: string | null;
90
+ readonly pending: boolean;
91
+ readonly error?: unknown;
92
+ };
93
+ /** Changes whenever an adapter retires its authorization/cache scope. */
94
+ readonly identityEpoch?: unknown;
95
+ /** Aborts when the current cache/authorization scope is retired. */
96
+ readonly identitySignal?: AbortSignal;
97
+ /** App-owned auth notifications; never a credential or proof of identity. */
98
+ setAuth?(state: import("./auth.ts").ClientAuthInput): void | Promise<void>;
99
+ call(operation: Operation, options: CallOptions, onStatus?: (status: "recovering") => void): Promise<unknown>;
100
+ watch?(operation: Operation & {
101
+ readonly kind: "query";
102
+ }, observer: (state: QueryState<unknown>) => void, options: QueryOptions): () => void;
103
+ }
104
+ export interface PageHandle<T> extends QueryHandle<readonly T[]> {
105
+ readonly hasMore: boolean;
106
+ next(pages?: number): Promise<void>;
107
+ dispose(): void;
108
+ }
109
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,19 @@
1
+ import type { DatabaseOperation, InsertQuery, PendingWrite, SelectQuery } from "./database.ts";
2
+ import type { CompiledConflict, RowExpectation } from "./write-expression.ts";
3
+ import type { Page, PageOptions } from "./page.ts";
4
+ import type { Predicate } from "./filters.ts";
5
+ import type { AggregatePlan } from "./aggregate.ts";
6
+ type Filter = Predicate;
7
+ type Order = {
8
+ field: string;
9
+ direction: "asc" | "desc";
10
+ };
11
+ type ParseFilter = (args: readonly unknown[]) => Filter[];
12
+ type ParseProjection = (input: unknown) => readonly string[];
13
+ export declare function operation<T>(execute: () => Promise<T>): DatabaseOperation<T>;
14
+ type CheckRows = (result: unknown) => void;
15
+ type ParseExpectation = (input: RowExpectation) => CheckRows;
16
+ export declare function insertion<R, Bulk extends boolean>(parseProjection: ParseProjection, parseConflict: (input: unknown) => CompiledConflict, parseExpectation: ParseExpectation, execute: (projection?: readonly string[], conflict?: CompiledConflict, check?: CheckRows) => Promise<Bulk extends true ? R[] : R | null>): InsertQuery<R, Bulk>;
17
+ export declare function selection<R>(parse: ParseFilter, execute: (filters: Filter[], limit: number | null, unique: boolean, order: Order[]) => Promise<R[] | R | null>, parseOrder: (field: unknown) => string, paginate: (filters: Filter[], order: Order[], options: Required<PageOptions>) => Promise<Page<R>>, prepareAggregate: (groups: readonly unknown[], select: unknown) => AggregatePlan, executeAggregate: (filters: Filter[], plan: AggregatePlan, having: Filter[], order: Order[], limit: number | null) => Promise<unknown>): SelectQuery<R>;
18
+ export declare function write<R>(parse: ParseFilter, parseProjection: ParseProjection, parseExpectation: ParseExpectation, execute: (filters: Filter[], projection?: readonly string[], check?: CheckRows) => Promise<R[]>): PendingWrite<R>;
19
+ export {};
@@ -0,0 +1,183 @@
1
+ /** Private memoized execution shared by all database builders. */
2
+ class Operation {
3
+ #result;
4
+ execute;
5
+ constructor(execute) { this.execute = execute; }
6
+ assertUnstarted() {
7
+ if (this.#result)
8
+ throw new TypeError("Cannot modify a database operation after execution starts");
9
+ }
10
+ start() {
11
+ if (!this.#result) {
12
+ try {
13
+ this.#result = Promise.resolve(this.execute());
14
+ }
15
+ catch (error) {
16
+ this.#result = Promise.reject(error);
17
+ }
18
+ }
19
+ return this.#result;
20
+ }
21
+ then(fulfilled, rejected) {
22
+ return this.start().then(fulfilled, rejected);
23
+ }
24
+ catch(rejected) { return this.start().catch(rejected); }
25
+ finally(finallyCallback) { return this.start().finally(finallyCallback); }
26
+ }
27
+ export function operation(execute) { return new Operation(execute); }
28
+ export function insertion(parseProjection, parseConflict, parseExpectation, execute) {
29
+ class Insertion extends Operation {
30
+ projection;
31
+ conflict;
32
+ check;
33
+ constructor(projection, conflict, check) {
34
+ super(() => execute(projection, conflict, check));
35
+ this.projection = projection;
36
+ this.conflict = conflict;
37
+ this.check = check;
38
+ }
39
+ returning(input) {
40
+ this.assertUnstarted();
41
+ return new Insertion(parseProjection(input), this.conflict, this.check);
42
+ }
43
+ onConflict(input) {
44
+ this.assertUnstarted();
45
+ if (this.conflict)
46
+ throw new TypeError("Only one conflict policy may be declared");
47
+ return new Insertion(this.projection, parseConflict(input), this.check);
48
+ }
49
+ expectRows(input) {
50
+ this.assertUnstarted();
51
+ if (this.check)
52
+ throw new TypeError("Only one row expectation may be declared");
53
+ return new Insertion(this.projection, this.conflict, parseExpectation(input));
54
+ }
55
+ }
56
+ return new Insertion();
57
+ }
58
+ export function selection(parse, execute, parseOrder, paginate, prepareAggregate, executeAggregate) {
59
+ function grouped(filters, plan) {
60
+ class Grouped extends Operation {
61
+ havingFilters;
62
+ order;
63
+ constructor(havingFilters = [], order = []) {
64
+ super(async () => await executeAggregate(filters, plan, havingFilters, order, null));
65
+ this.havingFilters = havingFilters;
66
+ this.order = order;
67
+ }
68
+ having = predicate => {
69
+ this.assertUnstarted();
70
+ if (typeof predicate !== "function")
71
+ throw new TypeError("Having requires a predicate callback");
72
+ return new Grouped([...this.havingFilters, ...plan.parseHaving([predicate])], this.order);
73
+ };
74
+ orderBy(field, direction = "asc") {
75
+ this.assertUnstarted();
76
+ if (direction !== "asc" && direction !== "desc")
77
+ throw new TypeError("Invalid order direction");
78
+ return new Grouped(this.havingFilters, [...this.order, { field: plan.parseOrder(field), direction }]);
79
+ }
80
+ limit(count) {
81
+ this.assertUnstarted();
82
+ if (!Number.isSafeInteger(count) || count < 1)
83
+ throw new TypeError("Group limit must be a positive safe integer");
84
+ return operation(async () => await executeAggregate(filters, plan, this.havingFilters, this.order, count));
85
+ }
86
+ }
87
+ return new Grouped();
88
+ }
89
+ class Selection extends Operation {
90
+ filters;
91
+ order;
92
+ constructor(filters = [], order = []) {
93
+ super(async () => await execute(filters, null, false, order));
94
+ this.filters = filters;
95
+ this.order = order;
96
+ }
97
+ where(...args) {
98
+ this.assertUnstarted();
99
+ return new Selection([...this.filters, ...parse(args)], this.order);
100
+ }
101
+ orderBy(field, direction = "asc") {
102
+ this.assertUnstarted();
103
+ if (direction !== "asc" && direction !== "desc")
104
+ throw new TypeError("Invalid order direction");
105
+ return new Selection(this.filters, [...this.order, { field: parseOrder(field), direction }]);
106
+ }
107
+ limit(count) {
108
+ this.assertUnstarted();
109
+ if (!Number.isSafeInteger(count) || count < 1)
110
+ throw new TypeError("Query limit must be a positive safe integer");
111
+ return operation(async () => await execute(this.filters, count, false, this.order));
112
+ }
113
+ paginate(options) {
114
+ this.assertUnstarted();
115
+ if (!options || !Number.isSafeInteger(options.limit) || options.limit < 1 || options.limit > 1000)
116
+ throw new TypeError("Page limit must be a positive safe integer at most 1000");
117
+ if (options.cursor !== undefined && options.cursor !== null && typeof options.cursor !== "string")
118
+ throw new TypeError("Page cursor must be a string or null");
119
+ const parsed = { limit: options.limit, cursor: options.cursor ?? null };
120
+ return operation(() => paginate(this.filters, this.order, parsed));
121
+ }
122
+ unique() {
123
+ this.assertUnstarted();
124
+ return operation(async () => await execute(this.filters, 2, true, this.order));
125
+ }
126
+ assertAggregate() {
127
+ this.assertUnstarted();
128
+ if (this.order.length)
129
+ throw new TypeError("Apply ordering after grouped aggregate(), not to its input rows");
130
+ }
131
+ aggregate = select => {
132
+ this.assertAggregate();
133
+ const plan = prepareAggregate([], select);
134
+ return operation(() => executeAggregate(this.filters, plan, [], [], null));
135
+ };
136
+ groupBy = (...groups) => {
137
+ this.assertAggregate();
138
+ if (!groups.length)
139
+ throw new TypeError("GroupBy requires at least one field");
140
+ return Object.freeze({
141
+ aggregate: (select) => {
142
+ this.assertAggregate();
143
+ return grouped(this.filters, prepareAggregate(groups, select));
144
+ },
145
+ });
146
+ };
147
+ }
148
+ return new Selection();
149
+ }
150
+ export function write(parse, parseProjection, parseExpectation, execute) {
151
+ class Write extends Operation {
152
+ filters;
153
+ scoped;
154
+ projection;
155
+ check;
156
+ constructor(filters = [], scoped = false, projection, check) {
157
+ super(async () => {
158
+ if (!scoped)
159
+ throw new TypeError("Update and delete require where(); use where(true) to select every row");
160
+ return execute(filters, projection, check);
161
+ });
162
+ this.filters = filters;
163
+ this.scoped = scoped;
164
+ this.projection = projection;
165
+ this.check = check;
166
+ }
167
+ where(...args) {
168
+ this.assertUnstarted();
169
+ return new Write([...this.filters, ...parse(args)], true, this.projection, this.check);
170
+ }
171
+ expectRows(input) {
172
+ this.assertUnstarted();
173
+ if (this.check)
174
+ throw new TypeError("Only one row expectation may be declared");
175
+ return new Write(this.filters, this.scoped, this.projection, parseExpectation(input));
176
+ }
177
+ returning = input => {
178
+ this.assertUnstarted();
179
+ return new Write(this.filters, this.scoped, parseProjection(input), this.check);
180
+ };
181
+ }
182
+ return new Write();
183
+ }
@@ -0,0 +1,69 @@
1
+ import type { Page, PageOptions } from "./page.ts";
2
+ import { type SchemaDefinition, type Row, type StorageRow, type StorageIdentity, type Insert, type Patch } from "./schema.ts";
3
+ import { type TableReference, type FieldReference } from "./fields.ts";
4
+ import { type Expressions, type Predicate, type Field, type FieldValue, type Paths } from "./filters.ts";
5
+ import { type RowExpectation, type ConflictSelector, type ConflictPolicy, type ConflictTargets, type UpdateInput } from "./write-expression.ts";
6
+ export type { RowExpectation, ConflictSelector, ConflictPolicy, ConflictTargets, UpdateInput, WriteReferences, WriteReference, WriteValue, WritePatch } from "./write-expression.ts";
7
+ import { type Projection, type Projected, type ValidProjection } from "./projection.ts";
8
+ import { type Aggregates, type AggregateSelection, type AggregateResult, type GroupedQuery, type GroupKey } from "./aggregate.ts";
9
+ export type { Aggregates, AggregateValue, AggregateResult, GroupedQuery, GroupedAggregate } from "./aggregate.ts";
10
+ type Tables<S extends SchemaDefinition> = Extract<keyof S["tables"], string>;
11
+ export interface DatabaseOperation<T> extends PromiseLike<T> {
12
+ catch<TResult = never>(onRejected: (reason: unknown) => TResult | PromiseLike<TResult>): Promise<T | TResult>;
13
+ finally(onFinally: () => void): Promise<T>;
14
+ }
15
+ type TableInput<S extends SchemaDefinition, T extends Tables<S>> = T | TableReference<S, T>;
16
+ type LiteralTextOperator = "contains" | "not contains" | "startsWith" | "not startsWith" | "endsWith" | "not endsWith";
17
+ type TextOperator = LiteralTextOperator | "like" | "not like" | "ilike" | "not ilike";
18
+ type Operator<V> = "=" | "!=" | "in" | "not in" | "is" | "is not" | "exists" | "not exists" | (NonNullable<V> extends readonly unknown[] ? "contains" | "not contains" | "containsAny" | "not containsAny" | "containsAll" | "not containsAll" | "containedBy" | "not containedBy" : never) | (NonNullable<V> extends string | number | bigint | Date ? ">" | ">=" | "<" | "<=" | "between" | "not between" : never) | (NonNullable<V> extends string ? TextOperator : never);
19
+ type Operand<V, O, T extends string> = O extends "exists" | "not exists" ? boolean : O extends "contains" | "not contains" ? NonNullable<V> extends readonly (infer E)[] ? E : string : O extends "containsAny" | "not containsAny" | "containsAll" | "not containsAll" | "containedBy" | "not containedBy" ? NonNullable<V> extends readonly (infer E)[] ? readonly E[] : never : O extends "is" | "is not" ? null : O extends "in" | "not in" ? readonly (V | null)[] : O extends "between" | "not between" ? readonly [NonNullable<V>, NonNullable<V>] : O extends TextOperator ? string : O extends "=" | "!=" ? Exclude<V, undefined> | null | FieldReference<V | null, T> : NonNullable<V> | FieldReference<V | null, T>;
20
+ export interface Where<R, Result, T extends string = string, B = R> {
21
+ where(filter: Partial<{
22
+ [P in Paths<B>]: Exclude<FieldValue<R, P>, undefined> | null;
23
+ }> | true | ((expressions: Expressions<R, T, B>) => Predicate)): Result;
24
+ where(field: Field<R, T, B>, operator: "exists" | "not exists"): Result;
25
+ where<F extends Field<R, T, B>, O extends Operator<F extends FieldReference<unknown, string, infer V> ? V : FieldValue<B, NoInfer<F>>>>(field: F, operator: O, value: Operand<FieldValue<R, NoInfer<F>>, NoInfer<O>, T>, options?: O extends LiteralTextOperator ? NonNullable<F extends FieldReference<unknown, string, infer V> ? V : FieldValue<B, F>> extends string ? {
26
+ caseSensitive?: boolean;
27
+ } : never : never): Result;
28
+ }
29
+ export interface SelectQuery<R, T extends string = string, O = R, B = R> extends DatabaseOperation<O[]>, Where<R, SelectQuery<R, T, O, B>, T, B> {
30
+ orderBy(field: Field<R, T, B>, direction?: "asc" | "desc"): SelectQuery<R, T, O, B>;
31
+ limit(count: number): DatabaseOperation<O[]>;
32
+ unique(): DatabaseOperation<O | null>;
33
+ paginate(options: PageOptions): DatabaseOperation<Page<O>>;
34
+ aggregate<A extends AggregateSelection>(select: (aggregates: Aggregates<R, T, B>) => A): DatabaseOperation<AggregateResult<A>>;
35
+ groupBy<const G extends readonly [GroupKey<B> & keyof R, ...(GroupKey<B> & keyof R)[]]>(...fields: G): GroupedQuery<R, G[number], T, B>;
36
+ }
37
+ export interface WriteQuery<R, T extends string = string, O = R, B = R> extends DatabaseOperation<O[]>, Where<R, WriteQuery<R, T, O, B>, T, B> {
38
+ returning<const P extends Projection<R>>(projection: P & ValidProjection<R, P>): WriteQuery<R, T, Projected<R, P>, B>;
39
+ expectRows(expectation: RowExpectation): WriteQuery<R, T, O, B>;
40
+ }
41
+ export interface PendingWrite<R, T extends string = string, O = R, B = R> extends Where<R, WriteQuery<R, T, O, B>, T, B> {
42
+ returning<const P extends Projection<R>>(projection: P & ValidProjection<R, P>): PendingWrite<R, T, Projected<R, P>, B>;
43
+ expectRows(expectation: RowExpectation): PendingWrite<R, T, O, B>;
44
+ }
45
+ export interface InsertQuery<R, Bulk extends boolean = false, O = R, Targets extends readonly string[] = readonly string[], P = Partial<R>, Skip extends boolean = false, B = R, Stored = B> extends DatabaseOperation<Bulk extends true ? O[] : Skip extends true ? O | null : O> {
46
+ returning<const Selection extends Projection<R>>(projection: Selection & ValidProjection<R, Selection>): InsertQuery<R, Bulk, Projected<R, Selection>, Targets, P, Skip, B, Stored>;
47
+ onConflict<S extends boolean>(policy: (selector: ConflictSelector<R, P, Targets, B, Stored>) => ConflictPolicy<S>): InsertQuery<R, Bulk, O, Targets, P, S, B, Stored>;
48
+ expectRows(expectation: RowExpectation): InsertQuery<R, Bulk, O, Targets, P, Skip, B, Stored>;
49
+ }
50
+ export interface ReadDatabase<S extends SchemaDefinition> {
51
+ select<T extends Tables<S>>(table: TableInput<S, T>): SelectQuery<Row<S, T>, T, Row<S, T>, StorageRow<S, T>>;
52
+ select<T extends Tables<S>, const P extends Projection<Row<S, NoInfer<T>>>>(table: TableInput<S, T>, projection: P & ValidProjection<Row<S, NoInfer<T>>, P>): SelectQuery<Row<S, T>, T, Projected<Row<S, T>, P>, StorageRow<S, T>>;
53
+ }
54
+ export interface WriteDatabase<S extends SchemaDefinition> extends ReadDatabase<S> {
55
+ insert<T extends Tables<S>>(table: TableInput<S, T>, input: Insert<S, NoInfer<T>>): InsertQuery<Row<S, T>, false, Row<S, T>, ConflictTargets<S["tables"][T]>, Patch<S, T>, false, StorageRow<S, T>, StorageIdentity<S, T>>;
56
+ insert<T extends Tables<S>>(table: TableInput<S, T>, input: readonly Insert<S, NoInfer<T>>[]): InsertQuery<Row<S, T>, true, Row<S, T>, ConflictTargets<S["tables"][T]>, Patch<S, T>, false, StorageRow<S, T>, StorageIdentity<S, T>>;
57
+ update<T extends Tables<S>>(table: TableInput<S, T>, patch: UpdateInput<Row<S, NoInfer<T>>, Patch<S, NoInfer<T>>, StorageRow<S, NoInfer<T>>, StorageIdentity<S, NoInfer<T>>>): PendingWrite<Row<S, T>, T, Row<S, T>, StorageRow<S, T>>;
58
+ delete<T extends Tables<S>>(table: TableInput<S, T>): PendingWrite<Row<S, T>, T, Row<S, T>, StorageRow<S, T>>;
59
+ }
60
+ export interface QueryContext<S extends SchemaDefinition, I = unknown> {
61
+ readonly db: ReadDatabase<S>;
62
+ readonly identity: I;
63
+ }
64
+ export interface MutationContext<S extends SchemaDefinition, I = unknown> {
65
+ readonly db: WriteDatabase<S>;
66
+ readonly identity: I;
67
+ }
68
+ /** Private transaction transport. Applications receive typed databases, never this channel. */
69
+ export declare function transactionDatabase<S extends SchemaDefinition>(schema: S, writable: boolean, request: (operation: Record<string, unknown>, validate?: (result: unknown) => void) => Promise<unknown>): ReadDatabase<S> | WriteDatabase<S>;