@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
package/dist/error.js ADDED
@@ -0,0 +1,82 @@
1
+ function validString(value) {
2
+ return !/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/u.test(value);
3
+ }
4
+ function copyDetails(value, ancestors = new Set(), depth = 0) {
5
+ const invalid = () => new TypeError("DatabaseError details must be JSON-safe data");
6
+ if (depth > 128)
7
+ throw new TypeError("DatabaseError details nesting exceeds budget");
8
+ if (value === null || typeof value === "boolean")
9
+ return value;
10
+ if (typeof value === "string") {
11
+ if (!validString(value))
12
+ throw invalid();
13
+ return value;
14
+ }
15
+ if (typeof value === "number") {
16
+ if (!Number.isFinite(value) || (Number.isInteger(value) && !Number.isSafeInteger(value)))
17
+ throw invalid();
18
+ return value;
19
+ }
20
+ if (typeof value !== "object" || ancestors.has(value))
21
+ throw invalid();
22
+ const array = Array.isArray(value);
23
+ const prototype = Object.getPrototypeOf(value);
24
+ if (array ? prototype !== Array.prototype : prototype !== Object.prototype && prototype !== null)
25
+ throw invalid();
26
+ ancestors.add(value);
27
+ try {
28
+ const result = {};
29
+ const items = [];
30
+ const keys = Reflect.ownKeys(value);
31
+ if (array && keys.length !== value.length + 1)
32
+ throw invalid();
33
+ for (const key of keys) {
34
+ if (array && key === "length")
35
+ continue;
36
+ if (typeof key !== "string" || !validString(key))
37
+ throw invalid();
38
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
39
+ if (!descriptor.enumerable || !Object.hasOwn(descriptor, "value"))
40
+ throw invalid();
41
+ if (array && (!/^(0|[1-9][0-9]*)$/.test(key) || Number(key) >= value.length))
42
+ throw invalid();
43
+ const copied = copyDetails(descriptor.value, ancestors, depth + 1);
44
+ if (array)
45
+ items[Number(key)] = copied;
46
+ else
47
+ Object.defineProperty(result, key, { value: copied, enumerable: true });
48
+ }
49
+ return Object.freeze(array ? items : result);
50
+ }
51
+ finally {
52
+ ancestors.delete(value);
53
+ }
54
+ }
55
+ /** An intentional caller-visible failure. Unexpected exceptions stay server-local. */
56
+ export class DatabaseError extends Error {
57
+ code;
58
+ details;
59
+ constructor({ code, message, details }) {
60
+ if (typeof code !== "string" || !code.length || !validString(code))
61
+ throw new TypeError("DatabaseError requires a nonempty code");
62
+ if (typeof message !== "string" || !validString(message))
63
+ throw new TypeError("DatabaseError requires a message");
64
+ super(message);
65
+ this.name = "DatabaseError";
66
+ this.code = code;
67
+ if (details !== undefined)
68
+ this.details = copyDetails(details);
69
+ }
70
+ /** Only intentionally declared fields cross a serialized error boundary. */
71
+ toJSON() {
72
+ return { code: this.code, message: this.message, ...(this.details === undefined ? {} : { details: this.details }) };
73
+ }
74
+ }
75
+ const applicationErrors = new WeakSet();
76
+ /** Internal provenance: caller-chosen codes cannot control the transport. */
77
+ export function applicationError(options) {
78
+ const error = new DatabaseError(options);
79
+ applicationErrors.add(error);
80
+ return error;
81
+ }
82
+ export function isApplicationError(error) { return error instanceof DatabaseError && applicationErrors.has(error); }
@@ -0,0 +1,36 @@
1
+ import type { Row, StorageRow, SchemaDefinition } from "./schema.ts";
2
+ declare const reference: unique symbol;
3
+ declare const field: unique symbol;
4
+ declare const valueType: unique symbol;
5
+ declare const storageType: unique symbol;
6
+ import type { JsonShape } from "./json-value.ts";
7
+ export interface FieldReference<Value, Table extends string = string, Stored = unknown> {
8
+ readonly [field]: {
9
+ readonly table: Table;
10
+ readonly name: string;
11
+ };
12
+ readonly [valueType]?: Value;
13
+ readonly [storageType]?: Stored;
14
+ }
15
+ export type NestedReference<V, T extends string, B = V> = FieldReference<V, T, B> & (NonNullable<B> extends readonly unknown[] | Date ? {} : NonNullable<B> extends object ? {
16
+ readonly [K in Extract<keyof NonNullable<V>, string>]: NestedReference<NonNullable<V>[K], T, K extends keyof NonNullable<B> ? NonNullable<B>[K] : NonNullable<V>[K]>;
17
+ } : {});
18
+ export type TableReference<S extends SchemaDefinition, T extends Extract<keyof S["tables"], string>> = {
19
+ readonly [reference]: T;
20
+ } & {
21
+ readonly [K in keyof Row<S, T>]: NestedReference<Row<S, T>[K], T, StorageRow<S, T>[K]>;
22
+ };
23
+ export declare function createTables<S extends SchemaDefinition>(metadata: Readonly<Record<string, Readonly<Record<string, {
24
+ jsonShape?: JsonShape;
25
+ }>>>>): {
26
+ readonly [T in Extract<keyof S["tables"], string>]: TableReference<S, T>;
27
+ };
28
+ export declare function tableName(value: unknown): string;
29
+ export declare function fieldName(value: unknown, table: string): string;
30
+ export declare function fieldMetadata(value: unknown): {
31
+ table: string;
32
+ name: string;
33
+ } | undefined;
34
+ /** Preserve literal JSON keys in generated references; string paths retain dotted syntax. */
35
+ export declare function fieldPath(value: unknown, table: string): string | readonly string[];
36
+ export {};
package/dist/fields.js ADDED
@@ -0,0 +1,63 @@
1
+ const reference = Symbol("Hulla table reference");
2
+ const field = Symbol("Hulla field reference");
3
+ const paths = new WeakMap();
4
+ const valueType = Symbol("Hulla field value type");
5
+ const storageType = Symbol("Hulla field storage type");
6
+ export function createTables(metadata) {
7
+ const tables = Object.entries(metadata).map(([name, fields]) => {
8
+ function nested(segments, shape) {
9
+ const key = segments.join(".");
10
+ const properties = Object.create(null);
11
+ properties[field] = Object.freeze({ table: name, name: key });
12
+ if (shape?.kind === "nullable")
13
+ shape = shape.inner;
14
+ if (shape?.kind === "object") {
15
+ for (const [child, descriptor] of Object.entries(shape.fields)) {
16
+ properties[child] = nested([...segments, child], descriptor.shape);
17
+ }
18
+ }
19
+ const result = new Proxy(Object.freeze(properties), {
20
+ get(target, property, receiver) {
21
+ if (typeof property === "string" && !Object.hasOwn(target, property) && shape?.kind === "any")
22
+ return nested([...segments, property], shape);
23
+ return Reflect.get(target, property, receiver);
24
+ },
25
+ });
26
+ paths.set(result, Object.freeze([...segments]));
27
+ return result;
28
+ }
29
+ const properties = Object.entries(fields)
30
+ .map(([key, descriptor]) => [key, nested([key], descriptor.jsonShape)]);
31
+ const table = Object.assign(Object.create(null), { [reference]: name }, Object.fromEntries(properties));
32
+ return [name, Object.freeze(table)];
33
+ });
34
+ return Object.freeze(Object.fromEntries(tables));
35
+ }
36
+ export function tableName(value) {
37
+ if (typeof value === "string")
38
+ return value;
39
+ if (typeof value === "object" && value !== null && reference in value) {
40
+ return value[reference];
41
+ }
42
+ throw new TypeError("Expected a table name or table reference");
43
+ }
44
+ export function fieldName(value, table) {
45
+ if (typeof value === "string")
46
+ return value;
47
+ const metadata = fieldMetadata(value);
48
+ if (!metadata || metadata.table !== table) {
49
+ throw new TypeError("Expected a field from the selected table");
50
+ }
51
+ return metadata.name;
52
+ }
53
+ export function fieldMetadata(value) {
54
+ return typeof value === "object" && value !== null && field in value
55
+ ? value[field]
56
+ : undefined;
57
+ }
58
+ /** Preserve literal JSON keys in generated references; string paths retain dotted syntax. */
59
+ export function fieldPath(value, table) {
60
+ const name = fieldName(value, table);
61
+ const segments = typeof value === "object" && value !== null ? paths.get(value) : undefined;
62
+ return segments && (segments.length > 1 || segments[0].includes(".")) ? segments : name;
63
+ }
@@ -0,0 +1,93 @@
1
+ import { type JsonShape } from "./json-value.ts";
2
+ import { type FieldReference } from "./fields.ts";
3
+ export type Predicate = {
4
+ kind: "constant";
5
+ value: boolean;
6
+ } | {
7
+ kind: "and" | "or";
8
+ predicates: Predicate[];
9
+ } | {
10
+ kind: "not";
11
+ predicate: Predicate;
12
+ } | {
13
+ kind: "compare";
14
+ field: string | readonly string[];
15
+ operator: string;
16
+ operand: {
17
+ kind: "value";
18
+ value: unknown;
19
+ } | {
20
+ kind: "field";
21
+ field: string | readonly string[];
22
+ transform?: "arrayLength";
23
+ };
24
+ transform?: "arrayLength";
25
+ caseSensitive?: boolean;
26
+ };
27
+ type Key<R> = Extract<keyof R, string>;
28
+ export type Paths<R, Depth extends unknown[] = []> = Depth["length"] extends 8 ? never : {
29
+ [K in Key<R>]: K | (NonNullable<R[K]> extends readonly unknown[] | Date ? never : NonNullable<R[K]> extends object ? `${K}.${Paths<NonNullable<R[K]>, [...Depth, unknown]>}` : never);
30
+ }[Key<R>];
31
+ export type FieldValue<R, F> = F extends FieldReference<infer V> ? V : F extends keyof R ? R[F] : F extends `${infer K}.${infer Rest}` ? K extends keyof R ? FieldValue<NonNullable<R[K]>, Rest> : never : never;
32
+ export type Field<R, T extends string, B = R> = Paths<B> | {
33
+ [K in Paths<B>]: FieldReference<FieldValue<R, K>, T, FieldValue<B, K>>;
34
+ }[Paths<B>];
35
+ type Value<R, F> = FieldValue<R, F>;
36
+ declare const numericExpression: unique symbol;
37
+ export interface NumericExpression<T extends string> extends FieldReference<number | null, T, number | null> {
38
+ readonly [numericExpression]: true;
39
+ }
40
+ type Operand<R, T extends string, F> = Exclude<Value<R, F>, undefined> | null | FieldReference<Value<R, F> | null, T> | (NonNullable<Value<R, F>> extends number ? NumericExpression<T> : never);
41
+ type StoredValue<B, F> = F extends FieldReference<unknown, string, infer V> ? V : FieldValue<B, F>;
42
+ type Orderable<B, F> = NonNullable<StoredValue<B, F>> extends string | number | bigint | Date ? unknown : never;
43
+ type Textual<B, F> = NonNullable<StoredValue<B, F>> extends string ? unknown : never;
44
+ type Compare<R, T extends string, B = R> = <F extends Field<R, T, B> | NumericExpression<T>>(field: F, value: Operand<R, T, NoInfer<F>>) => Predicate;
45
+ type Ordered<R, T extends string, B = R> = <F extends Field<R, T, B> | NumericExpression<T>>(field: F & Orderable<B, F>, value: Exclude<Operand<R, T, NoInfer<F>>, boolean | null>) => Predicate;
46
+ type Text<R, T extends string, B = R> = <F extends Field<R, T, B>>(field: F & Textual<B, F>, value: string, options?: {
47
+ caseSensitive?: boolean;
48
+ }) => Predicate;
49
+ type Pattern<R, T extends string, B = R> = <F extends Field<R, T, B>>(field: F & Textual<B, F>, value: string) => Predicate;
50
+ export interface Expressions<R, T extends string, B = R> {
51
+ eq: Compare<R, T, B>;
52
+ ne: Compare<R, T, B>;
53
+ gt: Ordered<R, T, B>;
54
+ gte: Ordered<R, T, B>;
55
+ lt: Ordered<R, T, B>;
56
+ lte: Ordered<R, T, B>;
57
+ inArray: <F extends Field<R, T, B>>(field: F, values: readonly (Value<R, NoInfer<F>> | null)[]) => Predicate;
58
+ notInArray: Expressions<R, T, B>["inArray"];
59
+ between: <F extends Field<R, T, B>>(field: F & Orderable<B, F>, values: readonly [
60
+ Exclude<Value<R, NoInfer<F>>, boolean | null>,
61
+ Exclude<Value<R, NoInfer<F>>, boolean | null>
62
+ ]) => Predicate;
63
+ isNull: (field: Field<R, T, B>) => Predicate;
64
+ isNotNull: (field: Field<R, T, B>) => Predicate;
65
+ contains: <F extends Field<R, T, B>>(field: F & (NonNullable<StoredValue<B, F>> extends string | readonly unknown[] ? unknown : never), value: NonNullable<Value<R, NoInfer<F>>> extends readonly (infer E)[] ? E : string, options?: NonNullable<StoredValue<B, F>> extends string ? {
66
+ caseSensitive?: boolean;
67
+ } : never) => Predicate;
68
+ containsAny: ArrayMembers<R, T, B>;
69
+ containsAll: ArrayMembers<R, T, B>;
70
+ containedBy: ArrayMembers<R, T, B>;
71
+ arrayLength: <F extends Field<R, T, B>>(field: F & (NonNullable<Value<R, F>> extends readonly unknown[] ? unknown : never)) => NumericExpression<T>;
72
+ exists: (field: Field<R, T, B>, present?: boolean) => Predicate;
73
+ startsWith: Text<R, T, B>;
74
+ endsWith: Text<R, T, B>;
75
+ like: Pattern<R, T, B>;
76
+ ilike: Pattern<R, T, B>;
77
+ and: (...predicates: Predicate[]) => Predicate;
78
+ or: (...predicates: Predicate[]) => Predicate;
79
+ not: (predicate: Predicate) => Predicate;
80
+ }
81
+ type ArrayMembers<R, T extends string, B = R> = <F extends Field<R, T, B>>(field: F & (NonNullable<Value<R, F>> extends readonly unknown[] ? unknown : never), values: NonNullable<Value<R, NoInfer<F>>> extends readonly (infer E)[] ? readonly E[] : never) => Predicate;
82
+ type FieldDescriptor = {
83
+ scalar: string;
84
+ jsonShape?: JsonShape | undefined;
85
+ parse(value: unknown): unknown;
86
+ encode?(value: unknown): unknown;
87
+ encodeOperand?(value: unknown): unknown;
88
+ encodeElement?(value: unknown): unknown;
89
+ nested?(parts: readonly string[]): FieldDescriptor | undefined;
90
+ precision?: number;
91
+ };
92
+ export declare function predicateParser(table: string, fields: Record<string, FieldDescriptor>): (args: readonly unknown[]) => Predicate[];
93
+ export {};
@@ -0,0 +1,220 @@
1
+ import { validateJson } from "./json-value.js";
2
+ import { fieldMetadata, fieldPath } from "./fields.js";
3
+ const predicateTables = new WeakMap();
4
+ const numericExpression = Symbol("arrayLength");
5
+ const comparisonOperators = ["=", "!=", ">", ">=", "<", "<="];
6
+ const rangeOperators = ["between", "not between"];
7
+ const listOperators = ["in", "not in", ...rangeOperators];
8
+ const literalText = /^(not )?(contains|startsWith|endsWith)$/;
9
+ const textOperator = /^(not )?(contains|startsWith|endsWith|like|ilike)$/;
10
+ const operators = [
11
+ ...comparisonOperators, ...listOperators, "is", "is not", "exists", "not exists", "containsAny", "not containsAny", "containsAll", "not containsAll", "containedBy", "not containedBy",
12
+ "contains", "not contains", "startsWith", "not startsWith",
13
+ "endsWith", "not endsWith", "like", "not like", "ilike", "not ilike",
14
+ ];
15
+ function validateOptions(options) {
16
+ if (options === undefined)
17
+ return;
18
+ if (!options || typeof options !== "object" || Array.isArray(options) ||
19
+ Object.keys(options).some(key => key !== "caseSensitive") ||
20
+ (options.caseSensitive !== undefined && typeof options.caseSensitive !== "boolean")) {
21
+ throw new TypeError("Invalid text comparison options");
22
+ }
23
+ }
24
+ export function predicateParser(table, fields) {
25
+ function mark(predicate) {
26
+ if (predicate.kind === "and" || predicate.kind === "or") {
27
+ Object.freeze(predicate.predicates);
28
+ }
29
+ else if (predicate.kind === "compare") {
30
+ if (predicate.operand.kind === "value" && Array.isArray(predicate.operand.value)) {
31
+ Object.freeze(predicate.operand.value);
32
+ }
33
+ Object.freeze(predicate.operand);
34
+ }
35
+ predicateTables.set(predicate, table);
36
+ return Object.freeze(predicate);
37
+ }
38
+ function compare(input, inputOperator, value, options) {
39
+ validateOptions(options);
40
+ const transformed = typeof input === "object" && input !== null && numericExpression in input;
41
+ if (transformed && input.table !== table)
42
+ throw new TypeError("Expected numeric expression from the selected table");
43
+ const name = transformed ? input.name : fieldPath(input, table);
44
+ function resolve(path) {
45
+ const [root, ...parts] = typeof path === "string" ? Object.hasOwn(fields, path) ? [path] : path.split(".") : path;
46
+ let descriptor = fields[root];
47
+ if (!descriptor)
48
+ return undefined;
49
+ if (parts.length && descriptor.nested)
50
+ return descriptor.nested(parts);
51
+ let shape = descriptor.jsonShape;
52
+ for (const part of parts) {
53
+ if (shape?.kind === "nullable")
54
+ shape = shape.inner;
55
+ if (shape?.kind === "any")
56
+ continue;
57
+ if (shape?.kind !== "object" || !Object.hasOwn(shape.fields, part))
58
+ return undefined;
59
+ shape = shape.fields[part].shape;
60
+ }
61
+ if (!parts.length)
62
+ return descriptor;
63
+ let scalarShape = shape;
64
+ if (scalarShape?.kind === "nullable")
65
+ scalarShape = scalarShape.inner;
66
+ return { scalar: scalarShape?.kind === "number" ? "float64" : scalarShape?.kind === "string" || scalarShape?.kind === "boolean" ? scalarShape.kind : "json", jsonShape: shape, parse: value => validateJson(value, shape) };
67
+ }
68
+ const descriptor = transformed ? { scalar: "float64", parse: (value) => { if (typeof value !== "number" || !Number.isFinite(value))
69
+ throw new TypeError("Expected finite number"); return value; } } : resolve(name);
70
+ if (!descriptor)
71
+ throw new TypeError(`Unknown field ${table}.${name}`);
72
+ if (typeof inputOperator !== "string" || !operators.includes(inputOperator)) {
73
+ throw new TypeError("Unsupported comparison operator");
74
+ }
75
+ let operator = inputOperator;
76
+ if (operator.startsWith("not ") && operator !== "not in" && operator !== "not exists")
77
+ return mark({ kind: "not", predicate: compare(input, operator.slice(4), value, options) });
78
+ if (operator === "not exists") {
79
+ operator = "exists";
80
+ value = false;
81
+ }
82
+ if (operator === "exists") {
83
+ if (typeof value !== "boolean")
84
+ throw new TypeError("Exists requires a boolean");
85
+ return mark({ kind: "compare", field: name, operator, operand: { kind: "value", value } });
86
+ }
87
+ let shape = descriptor.jsonShape;
88
+ if (shape?.kind === "nullable")
89
+ shape = shape.inner;
90
+ if (shape?.kind === "array" && ["contains", "containsAny", "containsAll", "containedBy"].includes(operator)) {
91
+ if (options !== undefined)
92
+ throw new TypeError("Array membership does not accept text options");
93
+ const itemShape = shape.item;
94
+ const encodeItem = (value) => descriptor.encodeElement ? descriptor.encodeElement(value) : validateJson(value, itemShape);
95
+ const parsed = operator === "contains" ? encodeItem(value) : Array.isArray(value) ? Array.from(value, encodeItem) : (() => { throw new TypeError("Expected array membership operand list"); })();
96
+ return mark({ kind: "compare", field: name, operator, operand: { kind: "value", value: parsed } });
97
+ }
98
+ if (["containsAny", "containsAll", "containedBy"].includes(operator))
99
+ throw new TypeError("Array membership requires an array field");
100
+ if (options !== undefined && !literalText.test(operator)) {
101
+ throw new TypeError("Options require a literal text comparison");
102
+ }
103
+ if (value === undefined)
104
+ throw new TypeError("Undefined predicate operand");
105
+ if (value === null && (operator === "=" || operator === "!=")) {
106
+ operator = operator === "=" ? "is" : "is not";
107
+ }
108
+ const parse = (item) => {
109
+ const parsed = descriptor.encodeOperand ? descriptor.encodeOperand(item) : descriptor.encode ? descriptor.encode(item) : descriptor.parse(item);
110
+ return typeof parsed === "bigint" ? parsed.toString() : parsed;
111
+ };
112
+ let operand;
113
+ const ref = fieldMetadata(value);
114
+ const rhsTransformed = typeof value === "object" && value !== null && numericExpression in value;
115
+ if (operator === "is" || operator === "is not") {
116
+ if (value !== null)
117
+ throw new TypeError("Null comparison requires null");
118
+ operand = { kind: "value", value: null };
119
+ }
120
+ else if (rhsTransformed) {
121
+ const rhs = value;
122
+ if (rhs.table !== table || descriptor.scalar !== "float64" || !comparisonOperators.includes(operator))
123
+ throw new TypeError("Incompatible numeric expression comparison");
124
+ operand = { kind: "field", field: rhs.name, transform: "arrayLength" };
125
+ }
126
+ else if (ref) {
127
+ const rhs = resolve(fieldPath(value, table));
128
+ if (!rhs || rhs.scalar !== descriptor.scalar || rhs.precision !== descriptor.precision || !comparisonOperators.includes(operator)) {
129
+ throw new TypeError("Incompatible field comparison");
130
+ }
131
+ operand = { kind: "field", field: fieldPath(value, table) };
132
+ }
133
+ else if (listOperators.includes(operator)) {
134
+ const range = rangeOperators.includes(operator);
135
+ if (!Array.isArray(value) || (range && value.length !== 2)) {
136
+ throw new TypeError("Expected predicate operand array");
137
+ }
138
+ const values = Array.from(value, item => {
139
+ if (item === null && range)
140
+ throw new TypeError("Range bounds cannot be null");
141
+ return item === null ? null : parse(item);
142
+ });
143
+ operand = { kind: "value", value: values };
144
+ }
145
+ else if (textOperator.test(operator)) {
146
+ if (descriptor.scalar !== "string" || typeof value !== "string") {
147
+ throw new TypeError("Text comparison requires a string field and operand");
148
+ }
149
+ operand = { kind: "value", value };
150
+ }
151
+ else {
152
+ if (value === null)
153
+ throw new TypeError("Ordered comparison cannot use null");
154
+ operand = { kind: "value", value: parse(value) };
155
+ }
156
+ if ([">", ">=", "<", "<=", ...rangeOperators].includes(operator) &&
157
+ !["string", "int64", "float64", "decimal", "date", "timestamp", "localTimestamp"].includes(descriptor.scalar)) {
158
+ throw new TypeError("Boolean fields do not support ordered comparisons");
159
+ }
160
+ return mark({
161
+ kind: "compare", field: name, operator, operand,
162
+ ...(transformed ? { transform: "arrayLength" } : {}),
163
+ ...(literalText.test(operator) ? { caseSensitive: options?.caseSensitive ?? true } : {}),
164
+ });
165
+ }
166
+ function valid(predicate) {
167
+ if (!predicate || typeof predicate !== "object")
168
+ throw new TypeError("Expected predicate");
169
+ if (predicateTables.get(predicate) !== table) {
170
+ throw new TypeError("Expected predicate from the selected table");
171
+ }
172
+ // All branded predicates and their children are immutable, so they can be
173
+ // reused without copying or recursively accepting mutable callback output.
174
+ return predicate;
175
+ }
176
+ const helpers = {};
177
+ const helperOperators = {
178
+ eq: "=", ne: "!=", gt: ">", gte: ">=", lt: "<", lte: "<=",
179
+ inArray: "in", notInArray: "not in", between: "between",
180
+ containsAny: "containsAny", containsAll: "containsAll", containedBy: "containedBy",
181
+ contains: "contains", startsWith: "startsWith", endsWith: "endsWith",
182
+ like: "like", ilike: "ilike",
183
+ };
184
+ for (const [name, operator] of Object.entries(helperOperators)) {
185
+ helpers[name] = (field, value, options) => compare(field, operator, value, options);
186
+ }
187
+ helpers.exists = (field, present = true) => compare(field, "exists", present);
188
+ helpers.arrayLength = (input) => {
189
+ const name = fieldPath(input, table);
190
+ // Reuse operand validation so non-array paths are rejected at construction.
191
+ compare(input, "containsAll", []);
192
+ return Object.freeze({ [numericExpression]: true, name, table });
193
+ };
194
+ helpers.isNull = (field) => compare(field, "is", null);
195
+ helpers.isNotNull = (field) => compare(field, "is not", null);
196
+ for (const kind of ["and", "or"]) {
197
+ helpers[kind] = (...predicates) => mark(predicates.length
198
+ ? { kind, predicates: predicates.map(valid) }
199
+ : { kind: "constant", value: kind === "and" });
200
+ }
201
+ helpers.not = (predicate) => mark({ kind: "not", predicate: valid(predicate) });
202
+ return (args) => {
203
+ if (args.length === 2 && (args[1] === "exists" || args[1] === "not exists"))
204
+ return [compare(args[0], args[1], true)];
205
+ if (args.length === 3 || args.length === 4) {
206
+ return [compare(args[0], args[1], args[2], args[3])];
207
+ }
208
+ if (args.length !== 1)
209
+ throw new TypeError("Expected where predicate");
210
+ const value = args[0];
211
+ if (value === true)
212
+ return [mark({ kind: "constant", value: true })];
213
+ if (typeof value === "function")
214
+ return [valid(value(helpers))];
215
+ if (!value || typeof value !== "object" || Array.isArray(value) || !Object.keys(value).length) {
216
+ throw new TypeError("An empty filter is ambiguous; use where(true) to select every row");
217
+ }
218
+ return Object.entries(value).map(([name, item]) => compare(name, "=", item));
219
+ };
220
+ }
@@ -0,0 +1,7 @@
1
+ import type { ValueShape } from "./codec.ts";
2
+ /** TypeScript's checker provides inferred contracts; applications need no second result schema. */
3
+ export declare function compileFunctionShapes(modules: Readonly<Record<string, string>>, declarations: Readonly<Record<string, readonly string[]>>): Promise<Map<string, {
4
+ input: ValueShape;
5
+ result: ValueShape;
6
+ paginated?: true;
7
+ }>>;
@@ -0,0 +1,150 @@
1
+ import { API, TypeFlags, SymbolFlags } from "typescript/unstable/async";
2
+ const canonicalPath = (path) => {
3
+ const normalized = path.replaceAll("\\", "/");
4
+ return process.platform === "win32" || process.platform === "darwin" ? normalized.toLowerCase() : normalized;
5
+ };
6
+ const pageSource = canonicalPath(Bun.fileURLToPath(new URL("./page.ts", import.meta.url)));
7
+ const pageDeclaration = canonicalPath(Bun.fileURLToPath(new URL("./page.d.ts", import.meta.url)));
8
+ async function pageBrand(checker, type) {
9
+ const fields = await checker.getPropertiesOfType(type);
10
+ if (fields.length !== 3 || !fields.some(field => field.name === "page") || !fields.some(field => field.name === "cursor"))
11
+ return;
12
+ const brand = fields.find(field => field.name.startsWith("__@pageEligibility@") && field.declarations.some(declaration => declaration.path === pageSource || declaration.path === pageDeclaration));
13
+ return brand?.name;
14
+ }
15
+ async function shape(checker, type, parents = new Set()) {
16
+ if (!type || type.isErrorType())
17
+ throw new TypeError("Cannot infer a function value contract");
18
+ const alias = await type.getAliasSymbol();
19
+ if (alias?.name === "JsonValue" && alias.declarations.some(declaration => ["json-value.ts", "json-value.d.ts"].some(file => canonicalPath(declaration.path) === canonicalPath(Bun.fileURLToPath(new URL(`./${file}`, import.meta.url))))))
20
+ return { kind: "json" };
21
+ if (parents.has(type.id))
22
+ throw new TypeError("Recursive function value types are not supported");
23
+ const nested = new Set(parents).add(type.id);
24
+ if (type.flags & (TypeFlags.Any | TypeFlags.Unknown | TypeFlags.Never | TypeFlags.TypeParameter)) {
25
+ const name = type.flags & TypeFlags.Any ? "any" : type.flags & TypeFlags.Unknown ? "unknown" : type.flags & TypeFlags.Never ? "never" : "type parameter";
26
+ throw new TypeError(`Unsupported function value type: ${name}`);
27
+ }
28
+ if (type.flags & TypeFlags.Void || type.flags & TypeFlags.Undefined)
29
+ return { kind: "undefined" };
30
+ if (type.flags & TypeFlags.Null)
31
+ return { kind: "null" };
32
+ if (type.isBigIntLiteralType())
33
+ throw new TypeError("Bigint literal signatures are not supported; use bigint");
34
+ if (type.flags & TypeFlags.BigInt)
35
+ return { kind: "bigint" };
36
+ if (type.isLiteralType())
37
+ return { kind: "literal", value: type.value };
38
+ if (type.flags & TypeFlags.String)
39
+ return { kind: "string" };
40
+ if (type.flags & TypeFlags.Number)
41
+ return { kind: "number" };
42
+ if (type.flags & TypeFlags.Boolean)
43
+ return { kind: "boolean" };
44
+ const symbol = await type.getSymbol();
45
+ if (symbol?.name === "Date" && symbol.declarations.some(declaration => /\/node_modules\/(?:typescript|@typescript\/typescript-[^/]+)\/lib\/lib\.[^/]+\.d\.ts$/i.test(canonicalPath(declaration.path))))
46
+ return { kind: "date" };
47
+ if (type.isUnionType())
48
+ return { kind: "union", choices: await Promise.all((await type.getTypes()).map(t => shape(checker, t, nested))) };
49
+ if (type.isIntersectionType()) {
50
+ // Phantom ID brands do not add wire fields to a primitive.
51
+ const parts = await type.getTypes();
52
+ const primitive = parts.find(t => t.flags & (TypeFlags.StringLike | TypeFlags.NumberLike | TypeFlags.BigIntLike | TypeFlags.BooleanLike));
53
+ if (primitive)
54
+ return shape(checker, primitive, nested);
55
+ // Standard Schema extension inputs intersect the original submitted shapes.
56
+ // Ask the checker for merged properties so overlapping fields retain their
57
+ // actual intersection type and required/optional status.
58
+ if (parts.some(part => !(part.flags & TypeFlags.Object) && !part.isIntersectionType())) {
59
+ throw new TypeError("Unsupported intersection value; use portable object fields");
60
+ }
61
+ }
62
+ if (await checker.isArrayType(type)) {
63
+ if (!type.isTypeReference())
64
+ throw new TypeError("Unsupported array value");
65
+ return { kind: "array", item: await shape(checker, (await checker.getTypeArguments(type))[0], nested) };
66
+ }
67
+ if (await checker.isTupleType(type)) {
68
+ if (!type.isTypeReference())
69
+ throw new TypeError("Unsupported tuple value");
70
+ const target = await type.getTarget();
71
+ if (!target.isTupleType() || target.elementFlags.some(flag => flag !== 1))
72
+ throw new TypeError("Only fixed required tuples are supported");
73
+ return { kind: "tuple", items: await Promise.all((await checker.getTypeArguments(type)).map(t => shape(checker, t, nested))) };
74
+ }
75
+ if (type.flags & TypeFlags.Object || type.isIntersectionType()) {
76
+ if ((await checker.getSignaturesOfType(type, 0)).length || (await checker.getIndexInfosOfType(type)).length) {
77
+ throw new TypeError("Functions and open index signatures are not portable function values");
78
+ }
79
+ const symbol = await type.getSymbol();
80
+ if (symbol && ["Date", "Map", "Set", "Promise", "Uint8Array"].includes(symbol.name))
81
+ throw new TypeError(`Unsupported function value: ${symbol.name}`);
82
+ const fields = Object.create(null);
83
+ const brand = await pageBrand(checker, type);
84
+ for (const field of await checker.getPropertiesOfType(type)) {
85
+ if (field.name === brand)
86
+ continue;
87
+ if (field.name.startsWith("__@"))
88
+ throw new TypeError("Symbol properties are not portable values");
89
+ fields[field.name] = { shape: await shape(checker, await checker.getTypeOfSymbol(field), nested), optional: !!(field.flags & SymbolFlags.Optional) };
90
+ }
91
+ return { kind: "object", fields };
92
+ }
93
+ throw new TypeError(`Unsupported function value type: ${await checker.typeToString(type)}`);
94
+ }
95
+ /** TypeScript's checker provides inferred contracts; applications need no second result schema. */
96
+ export async function compileFunctionShapes(modules, declarations) {
97
+ const api = new API();
98
+ try {
99
+ const snapshot = await api.updateSnapshot({ openFiles: Object.values(modules) });
100
+ try {
101
+ const shapes = new Map();
102
+ for (const [module, source] of Object.entries(modules)) {
103
+ const project = await snapshot.getDefaultProjectForFile(source);
104
+ if (!project)
105
+ throw new TypeError(`No TypeScript project for ${source}`);
106
+ const file = await project.program.getSourceFile(source);
107
+ if (!file)
108
+ throw new TypeError(`Cannot read ${source}`);
109
+ const checker = project.checker;
110
+ const symbol = await checker.getSymbolAtLocation(file);
111
+ if (!symbol)
112
+ throw new TypeError(`No module exports in ${source}`);
113
+ const names = new Set(declarations[module]);
114
+ for (const exported of await checker.getExportsOfModule(symbol)) {
115
+ if (!names.has(exported.name))
116
+ continue;
117
+ const definition = await checker.getTypeOfSymbol(exported);
118
+ if (!definition)
119
+ continue;
120
+ const types = await checker.getPropertyOfType(definition, "$types");
121
+ if (!types)
122
+ continue;
123
+ let metadata = await checker.getTypeOfSymbol(types);
124
+ if (metadata?.isUnionType())
125
+ metadata = (await metadata.getTypes()).find(type => type.flags & TypeFlags.Object);
126
+ if (!metadata)
127
+ throw new TypeError(`Cannot infer ${module}.${exported.name}`);
128
+ const input = await checker.getPropertyOfType(metadata, "input");
129
+ const output = await checker.getPropertyOfType(metadata, "output");
130
+ if (!input || !output)
131
+ throw new TypeError("Missing function signature metadata");
132
+ const outputType = await checker.getTypeOfSymbol(output);
133
+ const paginated = outputType && await pageBrand(checker, outputType);
134
+ shapes.set(`${module}.${exported.name}`, {
135
+ ...(paginated ? { paginated: true } : {}),
136
+ input: await shape(checker, await checker.getTypeOfSymbol(input)),
137
+ result: await shape(checker, outputType),
138
+ });
139
+ }
140
+ }
141
+ return shapes;
142
+ }
143
+ finally {
144
+ await snapshot.dispose();
145
+ }
146
+ }
147
+ finally {
148
+ await api.close();
149
+ }
150
+ }