@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.
- package/LICENSE +21 -0
- package/README.md +263 -2
- package/THIRD_PARTY_NOTICES.md +850 -0
- package/dist/aggregate.d.ts +63 -0
- package/dist/aggregate.js +147 -0
- package/dist/auth.d.ts +10 -0
- package/dist/auth.js +22 -0
- package/dist/bindings.d.ts +56 -0
- package/dist/bindings.js +277 -0
- package/dist/browser.d.ts +12 -0
- package/dist/browser.js +24 -0
- package/dist/callable.d.ts +48 -0
- package/dist/callable.js +142 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +65 -0
- package/dist/codec.d.ts +32 -0
- package/dist/codec.js +129 -0
- package/dist/codegen.d.ts +19 -0
- package/dist/codegen.js +275 -0
- package/dist/config.d.ts +70 -0
- package/dist/config.js +100 -0
- package/dist/contracts.d.ts +109 -0
- package/dist/contracts.js +1 -0
- package/dist/database-builder.d.ts +19 -0
- package/dist/database-builder.js +183 -0
- package/dist/database.d.ts +69 -0
- package/dist/database.js +128 -0
- package/dist/declarations.d.ts +91 -0
- package/dist/declarations.js +141 -0
- package/dist/dev-worker.d.ts +1 -0
- package/dist/dev-worker.js +47 -0
- package/dist/dev.d.ts +5 -0
- package/dist/dev.js +148 -0
- package/dist/error.d.ts +20 -0
- package/dist/error.js +82 -0
- package/dist/fields.d.ts +36 -0
- package/dist/fields.js +63 -0
- package/dist/filters.d.ts +93 -0
- package/dist/filters.js +220 -0
- package/dist/function-shapes.d.ts +7 -0
- package/dist/function-shapes.js +150 -0
- package/dist/handles.d.ts +27 -0
- package/dist/handles.js +387 -0
- package/dist/http/protocol.d.ts +64 -0
- package/dist/http/protocol.js +77 -0
- package/dist/http/sse.d.ts +7 -0
- package/dist/http/sse.js +70 -0
- package/dist/http.d.ts +44 -0
- package/dist/http.js +911 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +1 -0
- package/dist/internal/client.d.ts +6 -0
- package/dist/internal/client.js +5 -0
- package/dist/json-value.d.ts +21 -0
- package/dist/json-value.js +79 -0
- package/dist/names.d.ts +2 -0
- package/dist/names.js +10 -0
- package/dist/native.d.ts +3 -0
- package/dist/native.js +42 -0
- package/dist/notifications.d.ts +8 -0
- package/dist/notifications.js +70 -0
- package/dist/optimistic.d.ts +46 -0
- package/dist/optimistic.js +140 -0
- package/dist/page.d.ts +11 -0
- package/dist/page.js +1 -0
- package/dist/pagination.d.ts +17 -0
- package/dist/pagination.js +262 -0
- package/dist/project-codegen.d.ts +2 -0
- package/dist/project-codegen.js +68 -0
- package/dist/projection.d.ts +19 -0
- package/dist/projection.js +31 -0
- package/dist/runtime-conditions.d.ts +2 -0
- package/dist/runtime-conditions.js +10 -0
- package/dist/runtime.d.ts +13 -0
- package/dist/runtime.js +47 -0
- package/dist/schema-codegen.d.ts +16 -0
- package/dist/schema-codegen.js +212 -0
- package/dist/schema-contract.d.ts +4 -0
- package/dist/schema-contract.js +42 -0
- package/dist/schema.d.ts +356 -0
- package/dist/schema.js +720 -0
- package/dist/server-database.d.ts +14 -0
- package/dist/server-database.js +386 -0
- package/dist/server.d.ts +7 -0
- package/dist/server.js +1 -0
- package/dist/service.d.ts +13 -0
- package/dist/service.js +206 -0
- package/dist/sql-check.d.ts +28 -0
- package/dist/sql-check.js +59 -0
- package/dist/validation.d.ts +43 -0
- package/dist/validation.js +21 -0
- package/dist/worker-codegen.d.ts +3 -0
- package/dist/worker-codegen.js +44 -0
- package/dist/worker.d.ts +9 -0
- package/dist/worker.js +92 -0
- package/dist/write-expression.d.ts +72 -0
- package/dist/write-expression.js +122 -0
- package/dist/zod.d.ts +28 -0
- package/dist/zod.js +102 -0
- package/licenses/allocator-api2-0.2.21/LICENSE-APACHE +176 -0
- package/licenses/allocator-api2-0.2.21/LICENSE-MIT +23 -0
- package/licenses/async-trait-0.1.92/LICENSE-APACHE +176 -0
- package/licenses/async-trait-0.1.92/LICENSE-MIT +23 -0
- package/licenses/atomic-waker-1.1.2/LICENSE-APACHE +201 -0
- package/licenses/atomic-waker-1.1.2/LICENSE-MIT +23 -0
- package/licenses/atomic-waker-1.1.2/LICENSE-THIRD-PARTY +45 -0
- package/licenses/axum-0.8.9/LICENSE +25 -0
- package/licenses/axum-core-0.5.6/LICENSE +27 -0
- package/licenses/base64-0.22.1/LICENSE-APACHE +201 -0
- package/licenses/base64-0.22.1/LICENSE-MIT +21 -0
- package/licenses/bitflags-2.13.2/LICENSE-APACHE +201 -0
- package/licenses/bitflags-2.13.2/LICENSE-MIT +25 -0
- package/licenses/block-buffer-0.12.1/LICENSE-APACHE +201 -0
- package/licenses/block-buffer-0.12.1/LICENSE-MIT +25 -0
- package/licenses/byteorder-1.5.0/COPYING +3 -0
- package/licenses/byteorder-1.5.0/LICENSE-MIT +21 -0
- package/licenses/bytes-1.12.1/LICENSE +25 -0
- package/licenses/cc-1.6.0/LICENSE-APACHE +201 -0
- package/licenses/cc-1.6.0/LICENSE-MIT +25 -0
- package/licenses/cfg-if-1.0.5/LICENSE-APACHE +201 -0
- package/licenses/cfg-if-1.0.5/LICENSE-MIT +25 -0
- package/licenses/chacha20-0.10.2/LICENSE-APACHE +201 -0
- package/licenses/chacha20-0.10.2/LICENSE-MIT +25 -0
- package/licenses/cmov-0.5.4/LICENSE-APACHE +202 -0
- package/licenses/cmov-0.5.4/LICENSE-MIT +25 -0
- package/licenses/const-oid-0.10.2/LICENSE-APACHE +201 -0
- package/licenses/const-oid-0.10.2/LICENSE-MIT +25 -0
- package/licenses/const-oid-0.9.6/LICENSE-APACHE +201 -0
- package/licenses/const-oid-0.9.6/LICENSE-MIT +25 -0
- package/licenses/cpufeatures-0.3.1/LICENSE-APACHE +201 -0
- package/licenses/cpufeatures-0.3.1/LICENSE-MIT +25 -0
- package/licenses/crypto-common-0.2.2/LICENSE-APACHE +201 -0
- package/licenses/crypto-common-0.2.2/LICENSE-MIT +25 -0
- package/licenses/ctutils-0.4.2/LICENSE-APACHE +202 -0
- package/licenses/ctutils-0.4.2/LICENSE-MIT +25 -0
- package/licenses/der-0.7.10/LICENSE-APACHE +201 -0
- package/licenses/der-0.7.10/LICENSE-MIT +25 -0
- package/licenses/der_derive-0.7.3/LICENSE-APACHE +201 -0
- package/licenses/der_derive-0.7.3/LICENSE-MIT +25 -0
- package/licenses/deranged-0.5.8/LICENSE-Apache +202 -0
- package/licenses/deranged-0.5.8/LICENSE-MIT +19 -0
- package/licenses/digest-0.11.3/LICENSE-APACHE +201 -0
- package/licenses/digest-0.11.3/LICENSE-MIT +26 -0
- package/licenses/equivalent-1.0.3/LICENSE-APACHE +201 -0
- package/licenses/equivalent-1.0.3/LICENSE-MIT +25 -0
- package/licenses/errno-0.3.14/LICENSE-APACHE +201 -0
- package/licenses/errno-0.3.14/LICENSE-MIT +25 -0
- package/licenses/fallible-iterator-0.2.0/LICENSE-APACHE +202 -0
- package/licenses/fallible-iterator-0.2.0/LICENSE-MIT +19 -0
- package/licenses/find-msvc-tools-0.1.14/LICENSE-APACHE +201 -0
- package/licenses/find-msvc-tools-0.1.14/LICENSE-MIT +25 -0
- package/licenses/flagset-0.4.7/LICENSE +202 -0
- package/licenses/foldhash-0.2.0/LICENSE +19 -0
- package/licenses/futures-channel-0.3.34/LICENSE-APACHE +202 -0
- package/licenses/futures-channel-0.3.34/LICENSE-MIT +26 -0
- package/licenses/futures-core-0.3.34/LICENSE-APACHE +202 -0
- package/licenses/futures-core-0.3.34/LICENSE-MIT +26 -0
- package/licenses/futures-sink-0.3.34/LICENSE-APACHE +202 -0
- package/licenses/futures-sink-0.3.34/LICENSE-MIT +26 -0
- package/licenses/futures-task-0.3.34/LICENSE-APACHE +202 -0
- package/licenses/futures-task-0.3.34/LICENSE-MIT +26 -0
- package/licenses/futures-util-0.3.34/LICENSE-APACHE +202 -0
- package/licenses/futures-util-0.3.34/LICENSE-MIT +26 -0
- package/licenses/getrandom-0.2.17/LICENSE-APACHE +201 -0
- package/licenses/getrandom-0.2.17/LICENSE-MIT +26 -0
- package/licenses/getrandom-0.4.3/LICENSE-APACHE +201 -0
- package/licenses/getrandom-0.4.3/LICENSE-MIT +26 -0
- package/licenses/hashbrown-0.17.1/LICENSE-APACHE +201 -0
- package/licenses/hashbrown-0.17.1/LICENSE-MIT +25 -0
- package/licenses/hmac-0.13.0/LICENSE-APACHE +201 -0
- package/licenses/hmac-0.13.0/LICENSE-MIT +25 -0
- package/licenses/http-1.5.0/LICENSE-APACHE +201 -0
- package/licenses/http-1.5.0/LICENSE-MIT +25 -0
- package/licenses/http-body-1.1.0/LICENSE +25 -0
- package/licenses/http-body-util-0.1.5/LICENSE +25 -0
- package/licenses/httparse-1.10.1/LICENSE-APACHE +201 -0
- package/licenses/httparse-1.10.1/LICENSE-MIT +20 -0
- package/licenses/httpdate-1.0.3/LICENSE-APACHE +201 -0
- package/licenses/httpdate-1.0.3/LICENSE-MIT +19 -0
- package/licenses/hybrid-array-0.4.15/LICENSE-APACHE +201 -0
- package/licenses/hybrid-array-0.4.15/LICENSE-MIT +25 -0
- package/licenses/hyper-1.11.1/LICENSE +19 -0
- package/licenses/hyper-util-0.1.21/LICENSE +19 -0
- package/licenses/itoa-1.0.18/LICENSE-APACHE +176 -0
- package/licenses/itoa-1.0.18/LICENSE-MIT +23 -0
- package/licenses/libc-0.2.189/LICENSE-APACHE +176 -0
- package/licenses/libc-0.2.189/LICENSE-MIT +25 -0
- package/licenses/lock_api-0.4.14/LICENSE-APACHE +201 -0
- package/licenses/lock_api-0.4.14/LICENSE-MIT +25 -0
- package/licenses/log-0.4.34/LICENSE-APACHE +201 -0
- package/licenses/log-0.4.34/LICENSE-MIT +25 -0
- package/licenses/matchit-0.8.4/LICENSE +21 -0
- package/licenses/matchit-0.8.4/LICENSE.httprouter +29 -0
- package/licenses/md-5-0.11.0/LICENSE-APACHE +201 -0
- package/licenses/md-5-0.11.0/LICENSE-MIT +28 -0
- package/licenses/memchr-2.8.3/COPYING +3 -0
- package/licenses/memchr-2.8.3/LICENSE-MIT +21 -0
- package/licenses/mime-0.3.17/LICENSE-APACHE +201 -0
- package/licenses/mime-0.3.17/LICENSE-MIT +20 -0
- package/licenses/mio-1.2.3/LICENSE +19 -0
- package/licenses/num-conv-0.2.2/LICENSE-Apache +177 -0
- package/licenses/num-conv-0.2.2/LICENSE-MIT +19 -0
- package/licenses/objc2-core-foundation-0.3.2/LICENSE.md +34 -0
- package/licenses/objc2-system-configuration-0.3.2/LICENSE.md +34 -0
- package/licenses/once_cell-1.21.4/LICENSE-APACHE +201 -0
- package/licenses/once_cell-1.21.4/LICENSE-MIT +23 -0
- package/licenses/parking_lot-0.12.5/LICENSE-APACHE +201 -0
- package/licenses/parking_lot-0.12.5/LICENSE-MIT +25 -0
- package/licenses/parking_lot_core-0.9.12/LICENSE-APACHE +201 -0
- package/licenses/parking_lot_core-0.9.12/LICENSE-MIT +25 -0
- package/licenses/percent-encoding-2.3.2/LICENSE-APACHE +201 -0
- package/licenses/percent-encoding-2.3.2/LICENSE-MIT +25 -0
- package/licenses/phf-0.13.1/LICENSE +20 -0
- package/licenses/phf_shared-0.13.1/LICENSE +20 -0
- package/licenses/pin-project-lite-0.2.17/LICENSE-APACHE +177 -0
- package/licenses/pin-project-lite-0.2.17/LICENSE-MIT +23 -0
- package/licenses/postgres-protocol-0.6.12/LICENSE-APACHE +201 -0
- package/licenses/postgres-protocol-0.6.12/LICENSE-MIT +22 -0
- package/licenses/postgres-types-0.2.14/LICENSE-APACHE +201 -0
- package/licenses/postgres-types-0.2.14/LICENSE-MIT +22 -0
- package/licenses/powerfmt-0.2.1/LICENSE-Apache +202 -0
- package/licenses/powerfmt-0.2.1/LICENSE-MIT +19 -0
- package/licenses/proc-macro2-1.0.107/LICENSE-APACHE +176 -0
- package/licenses/proc-macro2-1.0.107/LICENSE-MIT +23 -0
- package/licenses/quote-1.0.47/LICENSE-APACHE +176 -0
- package/licenses/quote-1.0.47/LICENSE-MIT +23 -0
- package/licenses/rand-0.10.3/COPYRIGHT +12 -0
- package/licenses/rand-0.10.3/LICENSE-APACHE +176 -0
- package/licenses/rand-0.10.3/LICENSE-MIT +26 -0
- package/licenses/rand_core-0.10.1/COPYRIGHT +9 -0
- package/licenses/rand_core-0.10.1/LICENSE-APACHE +187 -0
- package/licenses/rand_core-0.10.1/LICENSE-MIT +25 -0
- package/licenses/ring-0.17.14/LICENSE +9 -0
- package/licenses/ring-0.17.14/LICENSE-BoringSSL +272 -0
- package/licenses/ring-0.17.14/LICENSE-other-bits +13 -0
- package/licenses/ring-0.17.14/src/polyfill/once_cell/LICENSE-APACHE +201 -0
- package/licenses/ring-0.17.14/src/polyfill/once_cell/LICENSE-MIT +23 -0
- package/licenses/ring-0.17.14/third_party/fiat/LICENSE +15 -0
- package/licenses/rquickjs-0.14.0/LICENSE +22 -0
- package/licenses/rquickjs-core-0.14.0/LICENSE +22 -0
- package/licenses/rquickjs-sys-0.14.0/quickjs/LICENSE +24 -0
- package/licenses/rquickjs-sys-0.14.0/vendor/wasi-libc/NOTICE.md +26 -0
- package/licenses/rustls-0.23.46/LICENSE-APACHE +201 -0
- package/licenses/rustls-0.23.46/LICENSE-ISC +15 -0
- package/licenses/rustls-0.23.46/LICENSE-MIT +25 -0
- package/licenses/rustls-pki-types-1.15.1/LICENSE-APACHE +201 -0
- package/licenses/rustls-pki-types-1.15.1/LICENSE-MIT +25 -0
- package/licenses/rustls-webpki-0.103.15/LICENSE +19 -0
- package/licenses/scopeguard-1.2.0/LICENSE-APACHE +201 -0
- package/licenses/scopeguard-1.2.0/LICENSE-MIT +25 -0
- package/licenses/serde-1.0.229/LICENSE-APACHE +176 -0
- package/licenses/serde-1.0.229/LICENSE-MIT +23 -0
- package/licenses/serde_core-1.0.229/LICENSE-APACHE +176 -0
- package/licenses/serde_core-1.0.229/LICENSE-MIT +23 -0
- package/licenses/serde_derive-1.0.229/LICENSE-APACHE +176 -0
- package/licenses/serde_derive-1.0.229/LICENSE-MIT +23 -0
- package/licenses/serde_json-1.0.151/LICENSE-APACHE +176 -0
- package/licenses/serde_json-1.0.151/LICENSE-MIT +23 -0
- package/licenses/serde_path_to_error-0.1.20/LICENSE-APACHE +176 -0
- package/licenses/serde_path_to_error-0.1.20/LICENSE-MIT +23 -0
- package/licenses/sha2-0.11.0/LICENSE-APACHE +201 -0
- package/licenses/sha2-0.11.0/LICENSE-MIT +28 -0
- package/licenses/shlex-2.0.1/LICENSE-APACHE +13 -0
- package/licenses/shlex-2.0.1/LICENSE-MIT +21 -0
- package/licenses/signal-hook-registry-1.4.8/LICENSE-APACHE +201 -0
- package/licenses/signal-hook-registry-1.4.8/LICENSE-MIT +25 -0
- package/licenses/siphasher-1.0.4/COPYING +7 -0
- package/licenses/siphasher-1.0.4/LICENSE-APACHE +202 -0
- package/licenses/siphasher-1.0.4/LICENSE-MIT +17 -0
- package/licenses/slab-0.4.12/LICENSE +25 -0
- package/licenses/smallvec-1.16.2/LICENSE-APACHE +201 -0
- package/licenses/smallvec-1.16.2/LICENSE-MIT +25 -0
- package/licenses/socket2-0.6.5/LICENSE-APACHE +201 -0
- package/licenses/socket2-0.6.5/LICENSE-MIT +25 -0
- package/licenses/spki-0.7.3/LICENSE-APACHE +201 -0
- package/licenses/spki-0.7.3/LICENSE-MIT +25 -0
- package/licenses/stringprep-0.1.5/LICENSE-APACHE +202 -0
- package/licenses/stringprep-0.1.5/LICENSE-MIT +19 -0
- package/licenses/subtle-2.6.1/LICENSE +29 -0
- package/licenses/syn-2.0.119/LICENSE-APACHE +176 -0
- package/licenses/syn-2.0.119/LICENSE-MIT +23 -0
- package/licenses/syn-3.0.6/LICENSE-APACHE +176 -0
- package/licenses/syn-3.0.6/LICENSE-MIT +23 -0
- package/licenses/sync_wrapper-1.0.2/LICENSE +177 -0
- package/licenses/time-0.3.55/LICENSE-Apache +177 -0
- package/licenses/time-0.3.55/LICENSE-MIT +19 -0
- package/licenses/time-core-0.1.9/LICENSE-Apache +177 -0
- package/licenses/time-core-0.1.9/LICENSE-MIT +19 -0
- package/licenses/time-macros-0.2.32/LICENSE-Apache +177 -0
- package/licenses/time-macros-0.2.32/LICENSE-MIT +19 -0
- package/licenses/tinyvec-1.13.3/LICENSE-APACHE.md +202 -0
- package/licenses/tinyvec-1.13.3/LICENSE-MIT.md +5 -0
- package/licenses/tinyvec-1.13.3/LICENSE-ZLIB.md +11 -0
- package/licenses/tokio-1.53.1/LICENSE +21 -0
- package/licenses/tokio-macros-2.7.2/LICENSE +22 -0
- package/licenses/tokio-postgres-0.7.18/LICENSE-APACHE +201 -0
- package/licenses/tokio-postgres-0.7.18/LICENSE-MIT +22 -0
- package/licenses/tokio-postgres-rustls-0.14.0/LICENSE +21 -0
- package/licenses/tokio-rustls-0.26.6/LICENSE-APACHE +201 -0
- package/licenses/tokio-rustls-0.26.6/LICENSE-MIT +25 -0
- package/licenses/tokio-util-0.7.19/LICENSE +21 -0
- package/licenses/tower-0.5.3/LICENSE +25 -0
- package/licenses/tower-layer-0.3.3/LICENSE +25 -0
- package/licenses/tower-service-0.3.3/LICENSE +25 -0
- package/licenses/typenum-1.20.1/LICENSE +1 -0
- package/licenses/typenum-1.20.1/LICENSE-APACHE +201 -0
- package/licenses/typenum-1.20.1/LICENSE-MIT +21 -0
- package/licenses/unicode-bidi-0.3.18/COPYRIGHT +8 -0
- package/licenses/unicode-bidi-0.3.18/LICENSE-APACHE +201 -0
- package/licenses/unicode-bidi-0.3.18/LICENSE-MIT +25 -0
- package/licenses/unicode-ident-1.0.26/LICENSE-APACHE +176 -0
- package/licenses/unicode-ident-1.0.26/LICENSE-MIT +23 -0
- package/licenses/unicode-ident-1.0.26/LICENSE-UNICODE +39 -0
- package/licenses/unicode-normalization-0.1.25/COPYRIGHT +7 -0
- package/licenses/unicode-normalization-0.1.25/LICENSE-APACHE +201 -0
- package/licenses/unicode-normalization-0.1.25/LICENSE-MIT +25 -0
- package/licenses/unicode-properties-0.1.4/COPYRIGHT +7 -0
- package/licenses/unicode-properties-0.1.4/LICENSE-APACHE +201 -0
- package/licenses/unicode-properties-0.1.4/LICENSE-MIT +25 -0
- package/licenses/untrusted-0.9.0/LICENSE.txt +13 -0
- package/licenses/uuid-1.26.1/LICENSE-APACHE +201 -0
- package/licenses/uuid-1.26.1/LICENSE-MIT +26 -0
- package/licenses/webpki-roots-1.0.9/LICENSE +61 -0
- package/licenses/whoami-2.1.3/LICENSE_APACHE +176 -0
- package/licenses/whoami-2.1.3/LICENSE_BOOST +23 -0
- package/licenses/whoami-2.1.3/LICENSE_MIT +19 -0
- package/licenses/x509-cert-0.2.5/LICENSE-APACHE +201 -0
- package/licenses/x509-cert-0.2.5/LICENSE-MIT +25 -0
- package/licenses/zeroize-1.9.1/LICENSE-APACHE +202 -0
- package/licenses/zeroize-1.9.1/LICENSE-MIT +25 -0
- package/licenses/zmij-1.0.23/LICENSE-MIT +23 -0
- package/native/darwin-arm64/hulladb-bridge +0 -0
- package/native/darwin-arm64/hulladb-js +0 -0
- package/native/darwin-arm64/hulladb-service +0 -0
- package/native/linux-x64/hulladb-bridge +0 -0
- package/native/linux-x64/hulladb-js +0 -0
- package/native/linux-x64/hulladb-service +0 -0
- package/package.json +90 -4
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
2
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
3
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
4
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
return path;
|
|
8
|
+
};
|
|
9
|
+
import { lstat, mkdir } from "node:fs/promises";
|
|
10
|
+
import { dirname, isAbsolute, relative, resolve, sep } from "node:path";
|
|
11
|
+
import { validExportName } from "./names.js";
|
|
12
|
+
import { compileSchema, } from "./schema.js";
|
|
13
|
+
const header = "// Generated schema by @hulla/db. Do not edit.\n";
|
|
14
|
+
const scalarNames = {
|
|
15
|
+
string: "String",
|
|
16
|
+
boolean: "Boolean",
|
|
17
|
+
int64: "Int64",
|
|
18
|
+
uuid: "Uuid",
|
|
19
|
+
float64: "Float64",
|
|
20
|
+
json: "Json",
|
|
21
|
+
date: "Date",
|
|
22
|
+
timestamp: "Timestamp",
|
|
23
|
+
localTimestamp: "LocalTimestamp",
|
|
24
|
+
};
|
|
25
|
+
function rustString(value) {
|
|
26
|
+
if (/[\uD800-\uDFFF]/u.test(value))
|
|
27
|
+
throw new TypeError("Rust schema strings must contain valid Unicode scalars");
|
|
28
|
+
return `"${[...value]
|
|
29
|
+
.map((char) => {
|
|
30
|
+
if (char === '"' || char === "\\")
|
|
31
|
+
return `\\${char}`;
|
|
32
|
+
const code = char.codePointAt(0);
|
|
33
|
+
return code < 32 || code === 127 ? `\\u{${code.toString(16)}}` : char;
|
|
34
|
+
})
|
|
35
|
+
.join("")}"`;
|
|
36
|
+
}
|
|
37
|
+
function rustValue(scalar, value) {
|
|
38
|
+
if (value === null)
|
|
39
|
+
return "hulladb_schema::Value::Null";
|
|
40
|
+
if (scalar === "json")
|
|
41
|
+
return `hulladb_schema::Value::json(${rustString(JSON.stringify(value))}).expect("validated JSON default")`;
|
|
42
|
+
if (scalar === "float64")
|
|
43
|
+
return `hulladb_schema::Value::float64(${value}f64).expect("finite number default")`;
|
|
44
|
+
if (["date", "timestamp", "localTimestamp"].includes(scalar))
|
|
45
|
+
return `hulladb_schema::Value::${scalarNames[scalar]}(${rustString(value)}.into())`;
|
|
46
|
+
if (scalar === "string")
|
|
47
|
+
return `hulladb_schema::Value::String(${rustString(value)}.into())`;
|
|
48
|
+
if (scalar === "boolean")
|
|
49
|
+
return `hulladb_schema::Value::Boolean(${value})`;
|
|
50
|
+
if (scalar === "int64")
|
|
51
|
+
return `hulladb_schema::Value::Int64(${value}i64)`;
|
|
52
|
+
const bytes = value.replaceAll("-", "").match(/../g);
|
|
53
|
+
return `hulladb_schema::Value::Uuid([${bytes.map((byte) => `0x${byte}`).join(", ")}])`;
|
|
54
|
+
}
|
|
55
|
+
function rustJsonShape(shape) {
|
|
56
|
+
const prefix = "hulladb_schema::JsonShape::";
|
|
57
|
+
switch (shape.kind) {
|
|
58
|
+
case "any": return prefix + "Any";
|
|
59
|
+
case "string": return prefix + "String";
|
|
60
|
+
case "boolean": return prefix + "Boolean";
|
|
61
|
+
case "number": return prefix + "Number";
|
|
62
|
+
case "array": return `${prefix}Array { item: Box::new(${rustJsonShape(shape.item)}) }`;
|
|
63
|
+
case "nullable": return `${prefix}Nullable { inner: Box::new(${rustJsonShape(shape.inner)}) }`;
|
|
64
|
+
case "object": return `${prefix}Object { fields: [${Object.entries(shape.fields).map(([key, field]) => `(${rustString(key)}.into(), hulladb_schema::JsonProperty { shape: ${rustJsonShape(field.shape)}, optional: ${field.optional} })`).join(", ")}].into() }`;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function rustGenerator(generation) {
|
|
68
|
+
if (typeof generation === "object")
|
|
69
|
+
return `hulladb_schema::KeyGeneration::Custom { handler: ${rustString(generation.handler)}.into(), output_type: hulladb_schema::ScalarType::${scalarNames[generation.outputType]} }`;
|
|
70
|
+
return `hulladb_schema::KeyGeneration::${generation === "none" ? "None" : generation === "uuidV4" ? "UuidV4" : "UuidV7"}`;
|
|
71
|
+
}
|
|
72
|
+
/** Emit native declarations, then let Rust normalize through its existing contract. */
|
|
73
|
+
export function generateRustSchema(schema) {
|
|
74
|
+
const tables = compileSchema(schema);
|
|
75
|
+
const lines = [
|
|
76
|
+
header.trimEnd(),
|
|
77
|
+
"",
|
|
78
|
+
"pub fn schema() -> Result<hulladb_schema::SchemaContract, hulladb_schema::SchemaError> {",
|
|
79
|
+
" let tables = vec![",
|
|
80
|
+
];
|
|
81
|
+
for (const table of tables) {
|
|
82
|
+
lines.push(" {", ` let mut table = hulladb_schema::TableDeclaration::new(${rustString(table.name)}, vec![`);
|
|
83
|
+
for (const [name, field] of Object.entries(table.fields)) {
|
|
84
|
+
const boundScalar = field.scalar === "string" ? "int64" : field.scalar;
|
|
85
|
+
const minimum = field.constraints?.min;
|
|
86
|
+
const maximum = field.constraints?.max;
|
|
87
|
+
const constraints = `hulladb_schema::FieldConstraints { min: ${minimum === undefined ? "None" : `Some(${rustValue(boundScalar, minimum)})`}, max: ${maximum === undefined ? "None" : `Some(${rustValue(boundScalar, maximum)})`}, one_of: vec![${(field.constraints?.oneOf ?? []).map(value => rustValue(field.scalar, value)).join(", ")}] }`;
|
|
88
|
+
lines.push(` hulladb_schema::FieldDefinition { name: ${rustString(name)}.into(), scalar_type: hulladb_schema::ScalarType::${scalarNames[field.scalar]}, nullable: ${field.allowsNull}, precision: ${field.precision === undefined ? "None" : `Some(${field.precision})`}, json_shape: ${field.jsonShape ? `Some(${rustJsonShape(field.jsonShape)})` : "None"}, default: ${field.hasDefault ? `Some(${rustValue(field.scalar, field.encode(field.defaultValue))})` : "None"}, constraints: ${constraints} },`);
|
|
89
|
+
}
|
|
90
|
+
lines.push(" ]);", ` table.primary_key = Some(${rustString(table.primaryKey)}.into());`, ` table.key_generation = Some(${rustGenerator(table.keyGeneration)});`, ` table.insert_key_policy = hulladb_schema::InsertKeyPolicy::${table.insertKeyPolicy === "generatedOnly" ? "GeneratedOnly" : "AllowExplicit"};`);
|
|
91
|
+
for (const [name, constraint] of Object.entries(table.unique)) {
|
|
92
|
+
lines.push(` table.unique_constraints.push(hulladb_schema::UniqueConstraintDeclaration { name: ${rustString(name)}.into(), fields: vec![${constraint.fields.map((field) => `${rustString(field)}.into()`).join(", ")}], null_policy: Some(hulladb_schema::UniqueNullPolicy::${constraint.nulls === "distinct" ? "Distinct" : "NotDistinct"}) });`);
|
|
93
|
+
}
|
|
94
|
+
for (const index of table.indexes)
|
|
95
|
+
lines.push(` table.indexes.push(hulladb_schema::IndexDeclaration { name: ${rustString(index.name)}.into(), fields: vec![${index.fields.map(field => `${rustString(field)}.into()`).join(", ")}] });`);
|
|
96
|
+
for (const check of table.checks)
|
|
97
|
+
lines.push(` table.checks.push(hulladb_schema::CheckDefinition { name: ${rustString(check.name)}.into(), parts: vec![${check.parts.map(part => `${rustString(part)}.into()`).join(", ")}], operands: vec![${check.operands.map(operand => "field" in operand ? `hulladb_schema::CheckOperand::Field(${rustString(operand.field)}.into())` : `hulladb_schema::CheckOperand::Value(${rustValue(typeof operand.value === "bigint" ? "int64" : typeof operand.value === "number" ? "float64" : typeof operand.value === "boolean" ? "boolean" : "string", operand.value)})`).join(", ")}] });`);
|
|
98
|
+
lines.push(" table", " },");
|
|
99
|
+
}
|
|
100
|
+
lines.push(" ];", " let mut schema = hulladb_schema::SchemaDeclaration::new(tables);", ` schema.default_uuid_generation = hulladb_schema::UuidGeneration::${schema.defaultUuidGeneration === "v4" ? "V4" : "V7"};`);
|
|
101
|
+
for (const table of tables)
|
|
102
|
+
for (const [name, field] of Object.entries(table.fields)) {
|
|
103
|
+
if (typeof field.target === "string")
|
|
104
|
+
lines.push(` { let mut reference = hulladb_schema::ReferenceDeclaration::new(${rustString(table.name)}, ${rustString(name)}, ${rustString(field.target)}); reference.on_delete = hulladb_schema::ReferenceOnDelete::${{ restrict: "Restrict", cascade: "Cascade", setNull: "SetNull" }[field.onDelete ?? "restrict"]}; schema.references.push(reference); }`);
|
|
105
|
+
}
|
|
106
|
+
lines.push(" schema.normalize()", "}", "");
|
|
107
|
+
return lines.join("\n");
|
|
108
|
+
}
|
|
109
|
+
export async function generateSchema(options) {
|
|
110
|
+
const source = resolve(options.schema);
|
|
111
|
+
const outDir = resolve(options.outDir);
|
|
112
|
+
const fromOutput = relative(outDir, source);
|
|
113
|
+
if (!fromOutput.startsWith(`..${sep}`) && !isAbsolute(fromOutput))
|
|
114
|
+
throw new Error("Schema definitions must be outside the generated output directory");
|
|
115
|
+
const { default: schema } = (await import(__rewriteRelativeImportExtension(Bun.pathToFileURL(source).href)));
|
|
116
|
+
const compiled = compileSchema(schema);
|
|
117
|
+
const rust = options.rustOutput === undefined ? undefined : generateRustSchema(schema);
|
|
118
|
+
let sourceImport = relative(outDir, source).split(sep).join("/");
|
|
119
|
+
if (!sourceImport.startsWith("."))
|
|
120
|
+
sourceImport = `./${sourceImport}`;
|
|
121
|
+
const referenceTargets = Object.fromEntries(compiled.map(table => [table.name, Object.fromEntries(Object.entries(table.fields).flatMap(([name, field]) => field.target === undefined ? [] : [[name, field.target]]))]));
|
|
122
|
+
const types = `${header}import type schema from ${JSON.stringify(sourceImport)}
|
|
123
|
+
import type { ResolveReferences, Row as SchemaRow, Insert as SchemaInsert, Patch as SchemaPatch, Id as SchemaId } from '@hulla/db/schema'
|
|
124
|
+
import type { ReadDatabase as SchemaReadDatabase, WriteDatabase as SchemaWriteDatabase, Database as SchemaDatabase } from '@hulla/db/server'
|
|
125
|
+
|
|
126
|
+
export type Schema = ResolveReferences<typeof schema, ${JSON.stringify(referenceTargets)}>
|
|
127
|
+
export type Database = SchemaDatabase<Schema>
|
|
128
|
+
export type ReadDatabase = SchemaReadDatabase<Schema>
|
|
129
|
+
export type WriteDatabase = SchemaWriteDatabase<Schema>
|
|
130
|
+
export type Tables = keyof Schema['tables']
|
|
131
|
+
export type Row<T extends Tables> = SchemaRow<Schema, T>
|
|
132
|
+
export type Insert<T extends Tables> = SchemaInsert<Schema, T>
|
|
133
|
+
export type Patch<T extends Tables> = SchemaPatch<Schema, T>
|
|
134
|
+
export type Id<T extends Tables> = SchemaId<Schema, T>
|
|
135
|
+
`;
|
|
136
|
+
let configImport;
|
|
137
|
+
if (options.config !== undefined) {
|
|
138
|
+
configImport = relative(outDir, resolve(options.config)).split(sep).join("/");
|
|
139
|
+
if (!configImport.startsWith("."))
|
|
140
|
+
configImport = `./${configImport}`;
|
|
141
|
+
}
|
|
142
|
+
const identityImports = configImport === undefined ? "" : `import type config from ${JSON.stringify(configImport)}\nimport type { ConfigIdentity } from '@hulla/db/config'\n`;
|
|
143
|
+
const functions = `${header}import type { Schema } from './types'
|
|
144
|
+
import type { QueryContext, MutationContext } from '@hulla/db/server'
|
|
145
|
+
import { defineFunctions } from '@hulla/db/internal/functions'
|
|
146
|
+
${identityImports}
|
|
147
|
+
export const { query, mutation } = defineFunctions<QueryContext<Schema${configImport === undefined ? "" : ", ConfigIdentity<typeof config>"}>, MutationContext<Schema${configImport === undefined ? "" : ", ConfigIdentity<typeof config>"}>>()
|
|
148
|
+
`;
|
|
149
|
+
const tableMetadata = `JSON.parse(${JSON.stringify(JSON.stringify(Object.fromEntries(compiled.map(table => [table.name, Object.fromEntries(Object.entries(table.fields).map(([name, field]) => [name, { ...(field.jsonShape ? { jsonShape: field.jsonShape } : {}) }]))]))))})`;
|
|
150
|
+
const tableReferences = `${header}import type { Schema } from './types'
|
|
151
|
+
import { createTables } from '@hulla/db/schema'
|
|
152
|
+
|
|
153
|
+
const $tables = createTables<Schema>(${tableMetadata})
|
|
154
|
+
export default $tables
|
|
155
|
+
${compiled.filter(table => validExportName(table.name)).map((table, index) => `const $table${index} = $tables[${JSON.stringify(table.name)}]\nexport { $table${index} as ${table.name} }`).join("\n")}
|
|
156
|
+
`;
|
|
157
|
+
const outputs = new Map([
|
|
158
|
+
[resolve(outDir, "types.ts"), types],
|
|
159
|
+
[resolve(outDir, "functions.ts"), functions],
|
|
160
|
+
[resolve(outDir, "tables.ts"), tableReferences],
|
|
161
|
+
]);
|
|
162
|
+
if (options.rustOutput !== undefined)
|
|
163
|
+
outputs.set(resolve(options.rustOutput), rust);
|
|
164
|
+
if (outputs.size !== (options.rustOutput === undefined ? 3 : 4))
|
|
165
|
+
throw new Error("Schema outputs must use distinct paths");
|
|
166
|
+
// Check every destination before writing; never replace authored code.
|
|
167
|
+
await checkGeneratedDirectory(outDir);
|
|
168
|
+
for (const path of outputs.keys()) {
|
|
169
|
+
await checkGeneratedDirectory(dirname(path));
|
|
170
|
+
const info = await lstat(path).catch((error) => {
|
|
171
|
+
if (error.code === "ENOENT")
|
|
172
|
+
return undefined;
|
|
173
|
+
throw error;
|
|
174
|
+
});
|
|
175
|
+
if (info && (!info.isFile() || info.isSymbolicLink()))
|
|
176
|
+
throw new Error(`Refusing to overwrite an authored path: ${path}`);
|
|
177
|
+
let existing;
|
|
178
|
+
try {
|
|
179
|
+
existing = await Bun.file(path).text();
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
if (error.code === "ENOENT")
|
|
183
|
+
continue;
|
|
184
|
+
throw error;
|
|
185
|
+
}
|
|
186
|
+
if (existing.startsWith("// Generated by @hulla/db. Do not edit.\n"))
|
|
187
|
+
throw new Error(`Schema output conflicts with a generated function file: ${path}`);
|
|
188
|
+
if (!existing.startsWith(header))
|
|
189
|
+
throw new Error(`Refusing to overwrite an authored file: ${path}`);
|
|
190
|
+
}
|
|
191
|
+
for (const [path, content] of outputs) {
|
|
192
|
+
await mkdir(dirname(path), { recursive: true });
|
|
193
|
+
await Bun.write(path, content);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
/** Check the requested directory and missing ancestors before recursive mkdir. */
|
|
197
|
+
export async function checkGeneratedDirectory(directory) {
|
|
198
|
+
const absolute = resolve(directory);
|
|
199
|
+
const info = await lstat(absolute).catch((error) => {
|
|
200
|
+
if (error.code === "ENOENT")
|
|
201
|
+
return undefined;
|
|
202
|
+
throw error;
|
|
203
|
+
});
|
|
204
|
+
if (info) {
|
|
205
|
+
if (!info.isDirectory() || info.isSymbolicLink())
|
|
206
|
+
throw new Error(`Refusing to overwrite an authored path: ${absolute}`);
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
const parent = dirname(absolute);
|
|
210
|
+
if (parent !== absolute)
|
|
211
|
+
await checkGeneratedDirectory(parent);
|
|
212
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type SchemaDefinition, type Scalar } from "./schema.ts";
|
|
2
|
+
export declare function scalarDescriptor(scalar: Scalar, value: unknown): unknown;
|
|
3
|
+
/** Exact logical contract used by the native installation/worker equality guard. */
|
|
4
|
+
export declare function schemaDescriptor(schema: SchemaDefinition): unknown;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { compileSchema } from "./schema.js";
|
|
2
|
+
const scalars = { string: "String", boolean: "Boolean", int64: "Int64", uuid: "Uuid", float64: "Float64", json: "Json", date: "Date", timestamp: "Timestamp", localTimestamp: "LocalTimestamp" };
|
|
3
|
+
export function scalarDescriptor(scalar, value) {
|
|
4
|
+
return value === null ? ["null"] : [scalar, typeof value === "bigint" ? String(value) : value];
|
|
5
|
+
}
|
|
6
|
+
/** Exact logical contract used by the native installation/worker equality guard. */
|
|
7
|
+
export function schemaDescriptor(schema) {
|
|
8
|
+
const tables = compileSchema(schema);
|
|
9
|
+
return {
|
|
10
|
+
uuid_default: schema.defaultUuidGeneration === "v4" ? "V4" : "V7",
|
|
11
|
+
tables: tables.map(table => ({
|
|
12
|
+
name: table.name, key: table.primaryKey,
|
|
13
|
+
generation: typeof table.keyGeneration === "object"
|
|
14
|
+
? { custom: table.keyGeneration.handler, output: scalars[table.keyGeneration.outputType] }
|
|
15
|
+
: { none: "None", uuidV4: "UuidV4", uuidV7: "UuidV7" }[table.keyGeneration],
|
|
16
|
+
insert_policy: table.insertKeyPolicy === "generatedOnly" ? "GeneratedOnly" : "AllowExplicit",
|
|
17
|
+
fields: Object.entries(table.fields).map(([name, field]) => {
|
|
18
|
+
const value = field.hasDefault ? field.encode(field.defaultValue) : undefined;
|
|
19
|
+
return {
|
|
20
|
+
name, scalar: scalars[field.scalar], nullable: field.allowsNull,
|
|
21
|
+
...(field.jsonShape ? { jsonShape: field.jsonShape } : {}),
|
|
22
|
+
...(field.precision === undefined ? {} : { precision: field.precision }),
|
|
23
|
+
default: !field.hasDefault ? null : scalarDescriptor(field.scalar, value),
|
|
24
|
+
constraints: {
|
|
25
|
+
...(field.constraints?.min === undefined ? {} : { min: scalarDescriptor(field.scalar === "string" ? "int64" : field.scalar, field.scalar === "string" ? BigInt(field.constraints.min) : field.constraints.min) }),
|
|
26
|
+
...(field.constraints?.max === undefined ? {} : { max: scalarDescriptor(field.scalar === "string" ? "int64" : field.scalar, field.scalar === "string" ? BigInt(field.constraints.max) : field.constraints.max) }),
|
|
27
|
+
oneOf: (field.constraints?.oneOf ?? []).map(value => scalarDescriptor(field.scalar, value)),
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}),
|
|
31
|
+
unique: Object.entries(table.unique).map(([name, unique]) => ({
|
|
32
|
+
name, fields: unique.fields, nulls: unique.nulls === "distinct" ? "Distinct" : "NotDistinct",
|
|
33
|
+
})),
|
|
34
|
+
indexes: table.indexes,
|
|
35
|
+
checks: table.checks.map(check => ({ name: check.name, parts: check.parts, operands: check.operands.map(operand => "field" in operand ? operand : { value: scalarDescriptor(typeof operand.value === "bigint" ? "int64" : typeof operand.value === "number" ? "float64" : typeof operand.value === "boolean" ? "boolean" : "string", operand.value) }),
|
|
36
|
+
})),
|
|
37
|
+
})),
|
|
38
|
+
references: tables.flatMap(table => Object.entries(table.fields).flatMap(([name, field]) => field.target === undefined ? [] : [{ table: table.name, field: name, target: field.target,
|
|
39
|
+
key: tables.find(table => table.name === field.target).primaryKey,
|
|
40
|
+
onDelete: { restrict: "Restrict", cascade: "Cascade", setNull: "SetNull" }[field.onDelete ?? "restrict"] }])),
|
|
41
|
+
};
|
|
42
|
+
}
|
package/dist/schema.d.ts
ADDED
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
import { type JsonShape, type JsonValue } from "./json-value.ts";
|
|
2
|
+
export type { JsonShape, JsonValue } from "./json-value.ts";
|
|
3
|
+
import type { Validator } from "./validation.ts";
|
|
4
|
+
import { type CheckFields, type SqlCheck, type CompiledCheck } from "./sql-check.ts";
|
|
5
|
+
export { sql } from "./sql-check.ts";
|
|
6
|
+
export { createTables } from "./fields.ts";
|
|
7
|
+
export type { TableReference, FieldReference } from "./fields.ts";
|
|
8
|
+
export type Scalar = "string" | "boolean" | "int64" | "uuid" | "float64" | "json" | "date" | "timestamp" | "localTimestamp";
|
|
9
|
+
type Nullable<T, N extends boolean> = N extends true ? T | null : T;
|
|
10
|
+
declare const fieldBrand: unique symbol;
|
|
11
|
+
export interface FieldCodec<App, Stored> {
|
|
12
|
+
readonly encode: (value: App) => Stored;
|
|
13
|
+
readonly decode: (value: Stored) => App;
|
|
14
|
+
}
|
|
15
|
+
type Representation = {
|
|
16
|
+
encode(value: unknown): unknown;
|
|
17
|
+
decode(value: unknown): unknown;
|
|
18
|
+
};
|
|
19
|
+
export interface FieldConstraints {
|
|
20
|
+
readonly min?: number | bigint;
|
|
21
|
+
readonly max?: number | bigint;
|
|
22
|
+
readonly oneOf?: readonly (string | number | bigint | boolean)[];
|
|
23
|
+
}
|
|
24
|
+
export interface TableShape {
|
|
25
|
+
readonly fields: Fields;
|
|
26
|
+
readonly options: TableOptions;
|
|
27
|
+
readonly [tableBrand]: true;
|
|
28
|
+
readonly indexes: readonly IndexDefinition[];
|
|
29
|
+
}
|
|
30
|
+
export type ReferenceTarget = string | TableShape;
|
|
31
|
+
export interface ReferenceOptions {
|
|
32
|
+
readonly onDelete?: "restrict" | "cascade" | "setNull";
|
|
33
|
+
}
|
|
34
|
+
type FieldOptions = {
|
|
35
|
+
precision?: number;
|
|
36
|
+
mode?: "number" | "bigint" | "string" | "date";
|
|
37
|
+
customCodec?: boolean;
|
|
38
|
+
constraints?: FieldConstraints;
|
|
39
|
+
onDelete?: ReferenceOptions["onDelete"];
|
|
40
|
+
};
|
|
41
|
+
/** Immutable application validator with an explicit storage representation. */
|
|
42
|
+
declare class Field<T, N extends boolean = false, D extends boolean = false, R extends ReferenceTarget | undefined = undefined, S extends Scalar = Scalar, B = T> implements Validator<Nullable<T, N>> {
|
|
43
|
+
readonly [fieldBrand] = true;
|
|
44
|
+
readonly $types: {
|
|
45
|
+
value: T;
|
|
46
|
+
nullable: N;
|
|
47
|
+
default: D;
|
|
48
|
+
reference: R;
|
|
49
|
+
base: B;
|
|
50
|
+
};
|
|
51
|
+
readonly scalar: S;
|
|
52
|
+
readonly allowsNull: N;
|
|
53
|
+
readonly hasDefault: D;
|
|
54
|
+
readonly defaultValue: Nullable<T, N> | undefined;
|
|
55
|
+
readonly target: R;
|
|
56
|
+
readonly jsonShape?: JsonShape;
|
|
57
|
+
readonly precision?: number;
|
|
58
|
+
readonly mode?: "number" | "bigint" | "string" | "date";
|
|
59
|
+
readonly customCodec: boolean;
|
|
60
|
+
readonly constraints?: FieldConstraints;
|
|
61
|
+
readonly onDelete?: ReferenceOptions["onDelete"];
|
|
62
|
+
constructor(scalar: S, allowsNull: N, hasDefault: D, defaultValue: Nullable<T, N> | undefined, target: R, jsonShape?: JsonShape, representation?: Representation, options?: FieldOptions);
|
|
63
|
+
private copy;
|
|
64
|
+
optional(): JsonValidator<Nullable<T, N>, true>;
|
|
65
|
+
nullable(): Field<T, true, D, R, S, B> & Pick<this, "customCodec">;
|
|
66
|
+
default(value: Nullable<T, N>): Field<T, N, true, R, S, B> & Pick<this, "customCodec">;
|
|
67
|
+
min(value: R extends undefined ? S extends "int64" ? number | bigint : S extends "string" | "float64" ? number : never : never): Field<T, N, D, R, S, B> & Pick<this, "customCodec">;
|
|
68
|
+
max(value: R extends undefined ? S extends "int64" ? number | bigint : S extends "string" | "float64" ? number : never : never): Field<T, N, D, R, S, B> & Pick<this, "customCodec">;
|
|
69
|
+
private bound;
|
|
70
|
+
oneOf<const Values extends readonly T[]>(values: R extends undefined ? S extends "json" ? never : Values : never): Field<Values[number], N, D, R, S, B> & Pick<this, "customCodec">;
|
|
71
|
+
private constrained;
|
|
72
|
+
private checkConstraints;
|
|
73
|
+
codec<App>(codec: FieldCodec<App, T>): Field<App, N, D, R, S, S extends "date" | "timestamp" | "localTimestamp" ? string : B> & {
|
|
74
|
+
readonly customCodec: true;
|
|
75
|
+
};
|
|
76
|
+
/** Validate and encode an application value to the database scalar (int64 uses bigint). */
|
|
77
|
+
encode(value: unknown): unknown;
|
|
78
|
+
/** Predicates and arithmetic operands validate representation, not stored-row constraints. */
|
|
79
|
+
encodeOperand(value: unknown): unknown;
|
|
80
|
+
/** Validate and decode a database wire value. */
|
|
81
|
+
decode(value: unknown): Nullable<T, N>;
|
|
82
|
+
/** Storage-level validation is also used by SQL arithmetic operands. */
|
|
83
|
+
storage(value: unknown): unknown;
|
|
84
|
+
encodeElement(value: unknown): unknown;
|
|
85
|
+
nested(parts: readonly string[]): {
|
|
86
|
+
scalar: string;
|
|
87
|
+
jsonShape: JsonShape;
|
|
88
|
+
parse(value: unknown): unknown;
|
|
89
|
+
encode(value: unknown): unknown;
|
|
90
|
+
encodeOperand(value: unknown): unknown;
|
|
91
|
+
encodeElement(value: unknown): unknown;
|
|
92
|
+
} | undefined;
|
|
93
|
+
parse(value: unknown): Nullable<T, N>;
|
|
94
|
+
}
|
|
95
|
+
type Precision = 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
96
|
+
type DatePrecision = 0 | 1 | 2 | 3;
|
|
97
|
+
type TimestampOptions = {
|
|
98
|
+
withTimezone?: true;
|
|
99
|
+
mode?: "date";
|
|
100
|
+
precision?: DatePrecision;
|
|
101
|
+
} | {
|
|
102
|
+
withTimezone?: false;
|
|
103
|
+
mode: "date";
|
|
104
|
+
precision?: DatePrecision;
|
|
105
|
+
} | {
|
|
106
|
+
withTimezone?: boolean;
|
|
107
|
+
mode: "string";
|
|
108
|
+
precision?: Precision;
|
|
109
|
+
} | {
|
|
110
|
+
withTimezone: false;
|
|
111
|
+
mode?: "string";
|
|
112
|
+
precision?: Precision;
|
|
113
|
+
};
|
|
114
|
+
declare function timestamp<O extends TimestampOptions = {}>(options?: O): Field<O extends {
|
|
115
|
+
mode: "string";
|
|
116
|
+
} ? string : O extends {
|
|
117
|
+
withTimezone: false;
|
|
118
|
+
mode?: "string";
|
|
119
|
+
} ? string : Date, false, false, undefined, O extends {
|
|
120
|
+
withTimezone: false;
|
|
121
|
+
} ? "localTimestamp" : "timestamp">;
|
|
122
|
+
declare function int64<O extends {
|
|
123
|
+
mode?: "number" | "bigint";
|
|
124
|
+
} = {}>(options?: O): Field<O extends {
|
|
125
|
+
mode: "bigint";
|
|
126
|
+
} ? bigint : number, false, false, undefined, "int64">;
|
|
127
|
+
declare function date<O extends {
|
|
128
|
+
mode?: "string" | "date";
|
|
129
|
+
} = {}>(options?: O): Field<O extends {
|
|
130
|
+
mode: "date";
|
|
131
|
+
} ? Date : string, false, false, undefined, "date">;
|
|
132
|
+
type ShapeInput = Field<any, any, any, any, any, any> | JsonValidator<any, any, any>;
|
|
133
|
+
type ShapeFields = Readonly<Record<string, ShapeInput>>;
|
|
134
|
+
type ShapeValue<S extends ShapeInput> = S extends Field<infer T, infer N, any, any, any, any> ? Nullable<T, N> : S extends JsonValidator<infer T, any, any> ? T : never;
|
|
135
|
+
type ObjectValue<F extends ShapeFields> = {
|
|
136
|
+
-readonly [K in keyof F as F[K] extends JsonValidator<any, true, any> ? never : K]: ShapeValue<F[K]>;
|
|
137
|
+
} & {
|
|
138
|
+
-readonly [K in keyof F as F[K] extends JsonValidator<any, true, any> ? K : never]?: ShapeValue<F[K]>;
|
|
139
|
+
};
|
|
140
|
+
type ShapeBase<S extends ShapeInput> = S extends Field<any, infer N, any, any, any, infer B> ? Nullable<B, N> : S extends JsonValidator<any, any, infer B> ? B : never;
|
|
141
|
+
type ObjectBase<F extends ShapeFields> = {
|
|
142
|
+
-readonly [K in keyof F as F[K] extends JsonValidator<any, true, any> ? never : K]: ShapeBase<F[K]>;
|
|
143
|
+
} & {
|
|
144
|
+
-readonly [K in keyof F as F[K] extends JsonValidator<any, true, any> ? K : never]?: ShapeBase<F[K]>;
|
|
145
|
+
};
|
|
146
|
+
declare class JsonValidator<T, O extends boolean = false, B = T> implements Validator<T> {
|
|
147
|
+
readonly $types: {
|
|
148
|
+
value: T;
|
|
149
|
+
base: B;
|
|
150
|
+
};
|
|
151
|
+
readonly shape: JsonShape;
|
|
152
|
+
readonly isOptional: O;
|
|
153
|
+
readonly customCodec: boolean;
|
|
154
|
+
readonly encode: (value: unknown, path?: string) => unknown;
|
|
155
|
+
readonly decode: (value: unknown, path?: string) => T;
|
|
156
|
+
constructor(shape: JsonShape, isOptional?: O, encode?: (value: unknown, path?: string) => unknown, decode?: (value: unknown, path?: string) => T, customCodec?: boolean);
|
|
157
|
+
nullable(): JsonValidator<T | null, O, B | null>;
|
|
158
|
+
optional(): JsonValidator<T, true, B>;
|
|
159
|
+
parse(value: unknown): T;
|
|
160
|
+
}
|
|
161
|
+
/** Internal adapter bridge; the immutable shape is the runtime validator identity. */
|
|
162
|
+
export declare function jsonValidatorForShape(shape: JsonShape): {
|
|
163
|
+
readonly customCodec: boolean;
|
|
164
|
+
parse(value: unknown): unknown;
|
|
165
|
+
} | undefined;
|
|
166
|
+
declare function objectShape<F extends ShapeFields>(fields: F): JsonValidator<ObjectValue<F>, false, ObjectBase<F>>;
|
|
167
|
+
declare function arrayShape<S extends ShapeInput>(item: S): JsonValidator<ShapeValue<S>[], false, ShapeBase<S>[]>;
|
|
168
|
+
declare function jsonField(): Field<JsonValue, false, false, undefined, "json">;
|
|
169
|
+
declare function jsonField<T>(): Field<T, false, false, undefined, "json">;
|
|
170
|
+
declare function jsonField<S extends ShapeInput>(shape: S): Field<ShapeValue<S>, false, false, undefined, "json", ShapeBase<S>>;
|
|
171
|
+
declare function jsonField<F extends ShapeFields>(fields: F): Field<ObjectValue<F>, false, false, undefined, "json", ObjectBase<F>>;
|
|
172
|
+
declare function id<const Target extends ReferenceTarget>(target: Target, options?: ReferenceOptions): Field<Target extends TableShape ? KeyValue<Target> : string | number | bigint, false, false, Target, Target extends TableShape ? TableFields<Target>[KeyName<Target>]["scalar"] : Scalar> & (Target extends TableShape ? Pick<TableFields<Target>[KeyName<Target>], "customCodec"> : {});
|
|
173
|
+
export declare const v: {
|
|
174
|
+
id: typeof id;
|
|
175
|
+
json: typeof jsonField;
|
|
176
|
+
object: typeof objectShape;
|
|
177
|
+
array: typeof arrayShape;
|
|
178
|
+
number: () => Field<number, false, false, undefined, "float64", number>;
|
|
179
|
+
string: () => Field<string, false, false, undefined, "string", string>;
|
|
180
|
+
boolean: () => Field<boolean, false, false, undefined, "boolean", boolean>;
|
|
181
|
+
int64: typeof int64;
|
|
182
|
+
date: typeof date;
|
|
183
|
+
timestamp: typeof timestamp;
|
|
184
|
+
uuid: () => Field<string, false, false, undefined, "uuid", string>;
|
|
185
|
+
};
|
|
186
|
+
type AnyField = Field<any, boolean, boolean, ReferenceTarget | undefined, Scalar, any>;
|
|
187
|
+
type Fields = Readonly<Record<string, AnyField>>;
|
|
188
|
+
type TableInputs = Readonly<Record<string, AnyField | JsonValidator<any, false, any>>>;
|
|
189
|
+
type ColumnField<V> = V extends JsonValidator<infer T, false, infer B> ? Field<Exclude<T, null>, null extends T ? true : false, false, undefined, "json", Exclude<B, null>> : V extends AnyField ? V : never;
|
|
190
|
+
type ColumnFields<F extends TableInputs> = {
|
|
191
|
+
readonly [K in keyof F]: ColumnField<F[K]>;
|
|
192
|
+
};
|
|
193
|
+
export type KeyGeneration = "none" | "uuidV4" | "uuidV7" | Readonly<{
|
|
194
|
+
handler: string;
|
|
195
|
+
outputType: Scalar;
|
|
196
|
+
}>;
|
|
197
|
+
export interface TableOptions {
|
|
198
|
+
readonly checks?: {
|
|
199
|
+
invoke(fields: CheckFields<string>): Readonly<Record<string, SqlCheck>>;
|
|
200
|
+
}["invoke"];
|
|
201
|
+
readonly primaryKey?: string;
|
|
202
|
+
readonly keyGeneration?: KeyGeneration;
|
|
203
|
+
readonly insertKeyPolicy?: "allowExplicit" | "generatedOnly";
|
|
204
|
+
readonly unique?: Readonly<Record<string, {
|
|
205
|
+
readonly fields: readonly string[];
|
|
206
|
+
readonly nulls?: "distinct" | "notDistinct";
|
|
207
|
+
}>>;
|
|
208
|
+
}
|
|
209
|
+
declare const tableBrand: unique symbol;
|
|
210
|
+
export interface TableDefinition<F extends Fields = Fields, O extends TableOptions = TableOptions> {
|
|
211
|
+
readonly fields: F;
|
|
212
|
+
readonly options: O;
|
|
213
|
+
readonly [tableBrand]: true;
|
|
214
|
+
readonly indexes: readonly IndexDefinition[];
|
|
215
|
+
readonly $inferSelect: StandaloneRow<TableDefinition<F, O>>;
|
|
216
|
+
readonly $inferInsert: StandaloneInsert<TableDefinition<F, O>>;
|
|
217
|
+
readonly $inferUpdate: StandaloneUpdate<TableDefinition<F, O>>;
|
|
218
|
+
index<const K extends Extract<keyof F, string> | (O extends {
|
|
219
|
+
readonly primaryKey: string;
|
|
220
|
+
} ? never : "id")>(fields: readonly K[], options?: {
|
|
221
|
+
readonly name?: string;
|
|
222
|
+
}): TableDefinition<F, O>;
|
|
223
|
+
}
|
|
224
|
+
export interface IndexDefinition {
|
|
225
|
+
readonly name?: string;
|
|
226
|
+
readonly fields: readonly string[];
|
|
227
|
+
}
|
|
228
|
+
export declare function defineTable<const F extends TableInputs, const O extends Omit<TableOptions, "checks"> = {}>(fields: F, options?: O & {
|
|
229
|
+
readonly checks?: (fields: CheckFields<Extract<keyof F, string> | "id">) => Readonly<Record<string, SqlCheck>>;
|
|
230
|
+
readonly primaryKey?: keyof F | "id";
|
|
231
|
+
readonly unique?: Readonly<Record<string, {
|
|
232
|
+
readonly fields: readonly (keyof F | "id")[];
|
|
233
|
+
readonly nulls?: "distinct" | "notDistinct";
|
|
234
|
+
}>>;
|
|
235
|
+
}): TableDefinition<ColumnFields<F>, O>;
|
|
236
|
+
type Tables = Readonly<Record<string, TableShape>>;
|
|
237
|
+
export declare function compiledTableForDefinition(table: TableShape): CompiledTable | undefined;
|
|
238
|
+
export interface SchemaDefinition<T extends Tables = Tables> {
|
|
239
|
+
readonly tables: T;
|
|
240
|
+
readonly defaultUuidGeneration: "v4" | "v7";
|
|
241
|
+
}
|
|
242
|
+
/** Validate authoring metadata immediately; storage enforcement belongs to the adapter. */
|
|
243
|
+
export declare function defineSchema<const T extends Tables>(tables: T, options?: {
|
|
244
|
+
readonly defaultUuidGeneration?: "v4" | "v7";
|
|
245
|
+
}): SchemaDefinition<T>;
|
|
246
|
+
type KeyName<D extends TableShape> = D["options"] extends {
|
|
247
|
+
readonly primaryKey: infer K extends string;
|
|
248
|
+
} ? K : "id";
|
|
249
|
+
type TableFields<D extends TableShape> = KeyName<D> extends keyof D["fields"] ? D["fields"] : D["fields"] & {
|
|
250
|
+
readonly id: ReturnType<typeof v.uuid>;
|
|
251
|
+
};
|
|
252
|
+
declare const idBrand: unique symbol;
|
|
253
|
+
type KeyValue<D extends TableShape> = TableFields<D>[KeyName<D>] extends AnyField ? TableFields<D>[KeyName<D>]["$types"]["value"] : never;
|
|
254
|
+
type TableSignature<D extends TableShape> = {
|
|
255
|
+
key: KeyName<D>;
|
|
256
|
+
fields: {
|
|
257
|
+
[K in keyof D["fields"]]: Pick<D["fields"][K]["$types"], "value" | "nullable" | "default"> & {
|
|
258
|
+
scalar: D["fields"][K]["scalar"];
|
|
259
|
+
};
|
|
260
|
+
};
|
|
261
|
+
};
|
|
262
|
+
type ReferenceName<S extends SchemaDefinition, R> = string extends keyof S["tables"] ? never : 0 extends 1 & R ? never : R extends keyof S["tables"] ? R : R extends TableShape ? {
|
|
263
|
+
[K in keyof S["tables"]]: TableSignature<S["tables"][K]> extends TableSignature<R> ? TableSignature<R> extends TableSignature<S["tables"][K]> ? K : never : never;
|
|
264
|
+
}[keyof S["tables"]] : never;
|
|
265
|
+
/** Code generation records object-reference identities that TypeScript cannot infer nominally. */
|
|
266
|
+
export type ResolveReferences<S extends SchemaDefinition, R extends Readonly<Record<string, Readonly<Record<string, string>>>>> = S & {
|
|
267
|
+
readonly $references: R;
|
|
268
|
+
};
|
|
269
|
+
type FieldReferenceName<S extends SchemaDefinition, T extends keyof S["tables"], K extends keyof TableFields<S["tables"][T]>> = S extends {
|
|
270
|
+
readonly $references: infer Refs;
|
|
271
|
+
} ? T extends keyof Refs ? K extends keyof Refs[T] ? Extract<Refs[T][K], keyof S["tables"]> : ReferenceName<S, TableFields<S["tables"][T]>[K]["$types"]["reference"]> : ReferenceName<S, TableFields<S["tables"][T]>[K]["$types"]["reference"]> : ReferenceName<S, TableFields<S["tables"][T]>[K]["$types"]["reference"]>;
|
|
272
|
+
type SchemaKeyValue<S extends SchemaDefinition, T extends keyof S["tables"], Seen = never> = T extends Seen ? never : FieldReferenceName<S, T, Extract<KeyName<S["tables"][T]>, keyof TableFields<S["tables"][T]>>> extends infer R extends keyof S["tables"] ? [R] extends [never] ? KeyValue<S["tables"][T]> : SchemaKeyValue<S, R, Seen | T> : never;
|
|
273
|
+
/** Accept validated scalar inputs while preserving the table provenance of known IDs. */
|
|
274
|
+
export type Id<S extends SchemaDefinition, T extends keyof S["tables"]> = SchemaKeyValue<S, T> & {
|
|
275
|
+
readonly [idBrand]?: T;
|
|
276
|
+
};
|
|
277
|
+
type FieldValue<S extends SchemaDefinition, F extends AnyField, Reference = ReferenceName<S, F["$types"]["reference"]>> = Nullable<[
|
|
278
|
+
Reference
|
|
279
|
+
] extends [infer R extends keyof S["tables"]] ? [R] extends [never] ? F["$types"]["value"] : Id<S, R> : F["$types"]["value"], F["$types"]["nullable"]>;
|
|
280
|
+
export type Row<S extends SchemaDefinition, T extends keyof S["tables"]> = {
|
|
281
|
+
-readonly [K in keyof TableFields<S["tables"][T]>]: K extends KeyName<S["tables"][T]> ? Id<S, T> : FieldValue<S, TableFields<S["tables"][T]>[K], FieldReferenceName<S, T, K>>;
|
|
282
|
+
};
|
|
283
|
+
/** Database operation capabilities before a custom application codec is applied. */
|
|
284
|
+
type StoredField<S extends SchemaDefinition, T extends keyof S["tables"], K extends keyof TableFields<S["tables"][T]>, Seen = never, Depth extends readonly unknown[] = []> = Depth["length"] extends 8 ? TableFields<S["tables"][T]>[K] : T extends Seen ? TableFields<S["tables"][T]>[K] : FieldReferenceName<S, T, K> extends infer R extends keyof S["tables"] ? [R] extends [never] ? TableFields<S["tables"][T]>[K] : StoredField<S, R, Extract<KeyName<S["tables"][R]>, keyof TableFields<S["tables"][R]>>, Seen | T, [...Depth, unknown]> : never;
|
|
285
|
+
export type StorageRow<S extends SchemaDefinition, T extends keyof S["tables"]> = {
|
|
286
|
+
-readonly [K in keyof TableFields<S["tables"][T]>]: Nullable<StoredField<S, T, K>["$types"]["base"], TableFields<S["tables"][T]>[K]["$types"]["nullable"]>;
|
|
287
|
+
};
|
|
288
|
+
/** Identity of SQL values used by atomic write references, independent of application modes. */
|
|
289
|
+
export type StorageIdentity<S extends SchemaDefinition, T extends keyof S["tables"]> = {
|
|
290
|
+
-readonly [K in keyof TableFields<S["tables"][T]>]: Nullable<{
|
|
291
|
+
readonly scalar: StoredField<S, T, K>["scalar"];
|
|
292
|
+
}, TableFields<S["tables"][T]>[K]["$types"]["nullable"]>;
|
|
293
|
+
};
|
|
294
|
+
type Generated<D extends TableShape> = D["options"] extends {
|
|
295
|
+
readonly keyGeneration: infer G;
|
|
296
|
+
} ? G extends "none" ? false : true : TableFields<D>[KeyName<D>]["$types"]["reference"] extends undefined ? KeyValue<D> extends string ? TableFields<D>[KeyName<D>]["scalar"] extends "uuid" ? true : false : false : false;
|
|
297
|
+
type OptionalInsert<S extends SchemaDefinition, T extends keyof S["tables"]> = {
|
|
298
|
+
[K in keyof TableFields<S["tables"][T]>]: K extends KeyName<S["tables"][T]> ? Generated<S["tables"][T]> extends true ? K : never : TableFields<S["tables"][T]>[K]["$types"]["default"] extends true ? K : never;
|
|
299
|
+
}[keyof TableFields<S["tables"][T]>];
|
|
300
|
+
type ForbiddenInsert<S extends SchemaDefinition, T extends keyof S["tables"]> = S["tables"][T]["options"] extends {
|
|
301
|
+
readonly insertKeyPolicy: "generatedOnly";
|
|
302
|
+
} ? KeyName<S["tables"][T]> : never;
|
|
303
|
+
export type Insert<S extends SchemaDefinition, T extends keyof S["tables"]> = Omit<InsertRow<S, T>, OptionalInsert<S, T> | ForbiddenInsert<S, T>> & {
|
|
304
|
+
[K in Extract<OptionalInsert<S, T>, keyof InsertRow<S, T>>]?: InsertRow<S, T>[K] | undefined;
|
|
305
|
+
} & {
|
|
306
|
+
[K in ForbiddenInsert<S, T>]?: never;
|
|
307
|
+
};
|
|
308
|
+
type InsertRow<S extends SchemaDefinition, T extends keyof S["tables"]> = Omit<Row<S, T>, KeyName<S["tables"][T]>> & {
|
|
309
|
+
[K in KeyName<S["tables"][T]>]: SchemaKeyValue<S, T>;
|
|
310
|
+
};
|
|
311
|
+
export type Patch<S extends SchemaDefinition, T extends keyof S["tables"]> = {
|
|
312
|
+
[K in Exclude<keyof Row<S, T>, KeyName<S["tables"][T]>>]?: Row<S, T>[K] | undefined;
|
|
313
|
+
} & {
|
|
314
|
+
[K in KeyName<S["tables"][T]>]?: never;
|
|
315
|
+
};
|
|
316
|
+
type StandaloneRow<D extends TableShape> = {
|
|
317
|
+
-readonly [K in keyof TableFields<D>]: Nullable<TableFields<D>[K]["$types"]["value"], TableFields<D>[K]["$types"]["nullable"]>;
|
|
318
|
+
};
|
|
319
|
+
type StandaloneOptional<D extends TableShape> = {
|
|
320
|
+
[K in keyof TableFields<D>]: K extends KeyName<D> ? Generated<D> extends true ? K : never : TableFields<D>[K]["$types"]["default"] extends true ? K : never;
|
|
321
|
+
}[keyof TableFields<D>];
|
|
322
|
+
type StandaloneForbidden<D extends TableShape> = D["options"] extends {
|
|
323
|
+
readonly insertKeyPolicy: "generatedOnly";
|
|
324
|
+
} ? KeyName<D> : never;
|
|
325
|
+
type StandaloneInsert<D extends TableShape> = Omit<StandaloneRow<D>, StandaloneOptional<D> | StandaloneForbidden<D>> & {
|
|
326
|
+
[K in Extract<StandaloneOptional<D>, keyof StandaloneRow<D>>]?: StandaloneRow<D>[K] | undefined;
|
|
327
|
+
} & {
|
|
328
|
+
[K in StandaloneForbidden<D>]?: never;
|
|
329
|
+
};
|
|
330
|
+
type StandaloneUpdate<D extends TableShape> = {
|
|
331
|
+
[K in Exclude<keyof StandaloneRow<D>, KeyName<D>>]?: StandaloneRow<D>[K] | undefined;
|
|
332
|
+
} & {
|
|
333
|
+
[K in KeyName<D>]?: never;
|
|
334
|
+
};
|
|
335
|
+
export interface CompiledTable {
|
|
336
|
+
readonly indexes: readonly {
|
|
337
|
+
readonly name: string;
|
|
338
|
+
readonly fields: readonly string[];
|
|
339
|
+
}[];
|
|
340
|
+
readonly checks: readonly CompiledCheck[];
|
|
341
|
+
readonly name: string;
|
|
342
|
+
readonly fields: Readonly<Record<string, AnyField>>;
|
|
343
|
+
readonly primaryKey: string;
|
|
344
|
+
readonly keyGeneration: KeyGeneration;
|
|
345
|
+
readonly insertKeyPolicy: "allowExplicit" | "generatedOnly";
|
|
346
|
+
readonly unique: Readonly<Record<string, {
|
|
347
|
+
readonly fields: readonly string[];
|
|
348
|
+
readonly nulls: "distinct" | "notDistinct";
|
|
349
|
+
}>>;
|
|
350
|
+
}
|
|
351
|
+
/** Normalize metadata with the same key/default/reference rules as hulladb_schema. */
|
|
352
|
+
export declare function compileSchema(schema: SchemaDefinition): readonly CompiledTable[];
|
|
353
|
+
export declare function parseRow<S extends SchemaDefinition, T extends Extract<keyof S["tables"], string>>(schema: S, table: T, input: unknown): Row<S, T>;
|
|
354
|
+
/** Fill literal defaults; an omitted generated key remains pending runtime execution. */
|
|
355
|
+
export declare function prepareInsert<S extends SchemaDefinition, T extends Extract<keyof S["tables"], string>>(schema: S, table: T, input: unknown, fillDefaults?: boolean): Insert<S, T>;
|
|
356
|
+
export declare function parsePatch<S extends SchemaDefinition, T extends Extract<keyof S["tables"], string>>(schema: S, table: T, input: unknown): Patch<S, T>;
|