@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,262 @@
|
|
|
1
|
+
import { DatabaseError, isApplicationError } from "./error.js";
|
|
2
|
+
import { queryListener, querySnapshot, subscriptionOptions } from "./handles.js";
|
|
3
|
+
import { afterBatch, notification, notifyObserver, stagedObserver } from "./notifications.js";
|
|
4
|
+
import { canonical } from "./http/protocol.js";
|
|
5
|
+
function protectedFailure(error) {
|
|
6
|
+
return typeof error === "object" && error !== null && "code" in error
|
|
7
|
+
&& !isApplicationError(error) && ["unauthorized", "forbidden", "reset_required", "context_changed", "disposed", "authentication", "authorization"].includes(String(error.code));
|
|
8
|
+
}
|
|
9
|
+
/** A list owns its ranges and publishes only complete adapter rounds. */
|
|
10
|
+
export class PaginationOperation {
|
|
11
|
+
#state = { status: "pending" };
|
|
12
|
+
#slots = [];
|
|
13
|
+
#listeners = new Set();
|
|
14
|
+
#runtime;
|
|
15
|
+
#mapper;
|
|
16
|
+
#baseline;
|
|
17
|
+
#name;
|
|
18
|
+
#codecs;
|
|
19
|
+
#owner = crypto.randomUUID();
|
|
20
|
+
#disposed = false;
|
|
21
|
+
#queued = false;
|
|
22
|
+
#loading;
|
|
23
|
+
#appending;
|
|
24
|
+
#appendPrevious;
|
|
25
|
+
#first;
|
|
26
|
+
#waiters = new Set();
|
|
27
|
+
#identitySignal;
|
|
28
|
+
#identityEpoch;
|
|
29
|
+
#abort = () => this.#retire(new DatabaseError({ code: "context_changed", message: "Pagination authorization scope changed" }));
|
|
30
|
+
constructor(runtime, name, mapper, codecs) {
|
|
31
|
+
if (typeof mapper !== "function")
|
|
32
|
+
throw new TypeError("Pagination requires an input mapper");
|
|
33
|
+
if (!runtime.watch)
|
|
34
|
+
throw new Error("The configured runtime does not support query subscriptions");
|
|
35
|
+
this.#runtime = runtime;
|
|
36
|
+
this.#name = name;
|
|
37
|
+
this.#mapper = mapper;
|
|
38
|
+
this.#codecs = codecs;
|
|
39
|
+
this.#baseline = this.#encode(mapper(null));
|
|
40
|
+
this.#identityEpoch = runtime.identityEpoch;
|
|
41
|
+
this.#identitySignal = runtime.identitySignal;
|
|
42
|
+
this.#identitySignal?.addEventListener("abort", this.#abort, { once: true });
|
|
43
|
+
this.#checkIdentity();
|
|
44
|
+
this.#first = this.next().then(() => {
|
|
45
|
+
this.#checkIdentity();
|
|
46
|
+
if (this.#state.status === "error")
|
|
47
|
+
throw this.#state.error;
|
|
48
|
+
return this.data;
|
|
49
|
+
});
|
|
50
|
+
void this.#first.catch(() => { });
|
|
51
|
+
}
|
|
52
|
+
#encode(input) { return canonical(this.#codecs ? this.#codecs.input.encode(input) : input); }
|
|
53
|
+
#checkIdentity() {
|
|
54
|
+
if (!this.#disposed && (this.#runtime.identityEpoch !== this.#identityEpoch || this.#identitySignal?.aborted))
|
|
55
|
+
this.#abort();
|
|
56
|
+
}
|
|
57
|
+
get status() { this.#checkIdentity(); return this.#state.status; }
|
|
58
|
+
get data() { this.#checkIdentity(); return "data" in this.#state ? this.#state.data : undefined; }
|
|
59
|
+
get error() { this.#checkIdentity(); return this.#state.status === "error" ? this.#state.error : undefined; }
|
|
60
|
+
get isStale() { this.#checkIdentity(); return this.#state.isStale ?? false; }
|
|
61
|
+
get isOptimistic() { this.#checkIdentity(); return this.#state.isOptimistic ?? false; }
|
|
62
|
+
get hasMore() { this.#checkIdentity(); const last = this.#slots.at(-1)?.state; return last?.status === "success" && last.data.cursor !== null; }
|
|
63
|
+
then(fulfilled, rejected) {
|
|
64
|
+
return this.#first.then(value => {
|
|
65
|
+
this.#checkIdentity();
|
|
66
|
+
if (this.#disposed)
|
|
67
|
+
throw this.error;
|
|
68
|
+
return value;
|
|
69
|
+
}).then(fulfilled, rejected);
|
|
70
|
+
}
|
|
71
|
+
#publish(state) {
|
|
72
|
+
this.#state = state;
|
|
73
|
+
for (const listener of [...this.#listeners]) {
|
|
74
|
+
this.#checkIdentity();
|
|
75
|
+
if (this.#state !== state)
|
|
76
|
+
break;
|
|
77
|
+
this.#deliver(listener, state);
|
|
78
|
+
}
|
|
79
|
+
for (const wake of [...this.#waiters])
|
|
80
|
+
wake();
|
|
81
|
+
}
|
|
82
|
+
#deliver(listener, state) {
|
|
83
|
+
notifyObserver(listener, () => {
|
|
84
|
+
this.#checkIdentity();
|
|
85
|
+
if (this.#state === state && this.#listeners.has(listener))
|
|
86
|
+
listener(state);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
#schedule() {
|
|
90
|
+
if (this.#queued)
|
|
91
|
+
return;
|
|
92
|
+
this.#queued = true;
|
|
93
|
+
afterBatch(() => { this.#queued = false; this.#recompute(); });
|
|
94
|
+
}
|
|
95
|
+
#recompute() {
|
|
96
|
+
if (this.#disposed)
|
|
97
|
+
return;
|
|
98
|
+
const failed = this.#slots.find(slot => slot.state.status === "error" && protectedFailure(slot.state.error))
|
|
99
|
+
?? this.#slots.find(slot => slot.state.status === "error");
|
|
100
|
+
if (failed) {
|
|
101
|
+
const error = failed.state.error;
|
|
102
|
+
const retained = failed === this.#appending && !protectedFailure(error) ? this.#appendPrevious : undefined;
|
|
103
|
+
this.#publish({ status: "error", error: failed.state.error, ...(retained === undefined ? {} : { data: retained, isStale: true }) });
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
if (this.#slots.some(slot => slot.state.status !== "success")) {
|
|
107
|
+
this.#publish({ status: "pending", ...(this.data === undefined ? {} : { data: this.data }), isStale: this.isStale, isOptimistic: this.isOptimistic });
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const rows = this.#slots.flatMap(slot => slot.state.data.page);
|
|
111
|
+
if (rows.length > 10000 || new TextEncoder().encode(JSON.stringify(rows, (_, value) => typeof value === "bigint" ? String(value) : value)).byteLength > 16 * 1024 * 1024) {
|
|
112
|
+
this.#publish({ status: "error", error: new DatabaseError({ code: "execution_limit", message: "Paginated list exceeds its row or byte budget" }) });
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
Object.freeze(rows);
|
|
116
|
+
this.#publish({ status: "success", data: rows, isStale: this.#slots.some(slot => slot.state.isStale), isOptimistic: this.#slots.some(slot => slot.state.isOptimistic) });
|
|
117
|
+
}
|
|
118
|
+
next(pages = 1) {
|
|
119
|
+
this.#checkIdentity();
|
|
120
|
+
if (!Number.isSafeInteger(pages) || pages < 1 || pages > 128)
|
|
121
|
+
return Promise.reject(new TypeError("pages must be an integer from 1 to 128"));
|
|
122
|
+
if (this.#loading)
|
|
123
|
+
return this.#loading;
|
|
124
|
+
if (this.#disposed)
|
|
125
|
+
return Promise.reject(this.error ?? new DatabaseError({ code: "disposed", message: "Pagination handle is disposed" }));
|
|
126
|
+
const load = async () => {
|
|
127
|
+
for (let count = 0; count < pages; count++) {
|
|
128
|
+
if (this.#disposed)
|
|
129
|
+
throw this.error;
|
|
130
|
+
if (this.#encode(this.#mapper(null)) !== this.#baseline)
|
|
131
|
+
throw new TypeError("Pagination inputs changed; create a fresh handle");
|
|
132
|
+
if (this.#slots.length && !this.hasMore)
|
|
133
|
+
return;
|
|
134
|
+
if (this.#slots.length >= 128)
|
|
135
|
+
throw new DatabaseError({ code: "capacity", message: "Pagination exceeds 128 pages" });
|
|
136
|
+
const previous = this.data;
|
|
137
|
+
const last = this.#slots.at(-1)?.state;
|
|
138
|
+
const cursor = last?.status === "success" ? last.data.cursor : null;
|
|
139
|
+
const input = this.#mapper(cursor);
|
|
140
|
+
const inputKey = this.#encode(input);
|
|
141
|
+
if (this.#slots.some(loaded => loaded.inputKey === inputKey)) {
|
|
142
|
+
throw new TypeError("Pagination mapper must forward the continuation cursor to a new page input");
|
|
143
|
+
}
|
|
144
|
+
const slot = { inputKey, operation: { name: this.#name, kind: "query", input, ...(this.#codecs ? { codecs: this.#codecs } : {}), page: { owner: `${this.#owner}:${this.#slots.length}` } }, state: { status: "pending" } };
|
|
145
|
+
this.#appending = slot;
|
|
146
|
+
this.#appendPrevious = previous;
|
|
147
|
+
this.#slots.push(slot);
|
|
148
|
+
this.#publish({ status: "pending", ...(previous === undefined ? {} : { data: previous }) });
|
|
149
|
+
try {
|
|
150
|
+
const outcome = new Promise((resolve, reject) => {
|
|
151
|
+
const check = () => {
|
|
152
|
+
if (this.#disposed || slot.state.status === "error") {
|
|
153
|
+
this.#waiters.delete(check);
|
|
154
|
+
reject(this.#disposed ? this.error : slot.state.error);
|
|
155
|
+
}
|
|
156
|
+
else if (slot.state.status === "success") {
|
|
157
|
+
this.#waiters.delete(check);
|
|
158
|
+
resolve();
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
this.#waiters.add(check);
|
|
162
|
+
try {
|
|
163
|
+
let discovered = false;
|
|
164
|
+
const stopWatch = this.#runtime.watch(slot.operation, stagedObserver(state => {
|
|
165
|
+
let next = querySnapshot(state, this.#codecs);
|
|
166
|
+
if (!discovered && next.status === "success") {
|
|
167
|
+
discovered = true;
|
|
168
|
+
if (next.data.cursor !== null && next.data.cursor === cursor) {
|
|
169
|
+
next = { status: "error", error: new TypeError("Pagination result cursor did not advance") };
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
slot.state = next;
|
|
173
|
+
this.#schedule();
|
|
174
|
+
}), {});
|
|
175
|
+
if (this.#disposed)
|
|
176
|
+
stopWatch();
|
|
177
|
+
else
|
|
178
|
+
slot.stop = stopWatch;
|
|
179
|
+
}
|
|
180
|
+
catch (error) {
|
|
181
|
+
this.#waiters.delete(check);
|
|
182
|
+
reject(error);
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
await outcome;
|
|
186
|
+
if (this.#state.status === "error")
|
|
187
|
+
throw this.#state.error;
|
|
188
|
+
}
|
|
189
|
+
catch (error) {
|
|
190
|
+
const stopWatch = slot.stop;
|
|
191
|
+
delete slot.stop;
|
|
192
|
+
stopWatch?.();
|
|
193
|
+
this.#slots.pop();
|
|
194
|
+
const refreshFailure = this.#slots.find(loaded => loaded.state.status === "error");
|
|
195
|
+
if (!this.#disposed) {
|
|
196
|
+
if (protectedFailure(error))
|
|
197
|
+
this.#publish({ status: "error", error });
|
|
198
|
+
else if (refreshFailure)
|
|
199
|
+
this.#recompute();
|
|
200
|
+
else
|
|
201
|
+
this.#publish({ status: "error", error, ...(previous === undefined || protectedFailure(error) ? {} : { data: previous, isStale: true }) });
|
|
202
|
+
}
|
|
203
|
+
throw error;
|
|
204
|
+
}
|
|
205
|
+
finally {
|
|
206
|
+
this.#appending = undefined;
|
|
207
|
+
this.#appendPrevious = undefined;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
this.#loading = Promise.resolve().then(load).catch(error => {
|
|
212
|
+
if (!this.#disposed && !(this.#state.status === "error" && (this.#state.error === error || protectedFailure(this.#state.error)))) {
|
|
213
|
+
const previous = this.data;
|
|
214
|
+
this.#publish({ status: "error", error, ...(previous === undefined ? {} : { data: previous, isStale: true }) });
|
|
215
|
+
}
|
|
216
|
+
throw error;
|
|
217
|
+
}).finally(() => { this.#loading = undefined; });
|
|
218
|
+
return this.#loading;
|
|
219
|
+
}
|
|
220
|
+
subscribe(listener, options = {}) {
|
|
221
|
+
options = subscriptionOptions(options);
|
|
222
|
+
options.signal?.throwIfAborted();
|
|
223
|
+
if (typeof listener !== "function")
|
|
224
|
+
throw new TypeError("Pagination subscription needs a listener");
|
|
225
|
+
this.#checkIdentity();
|
|
226
|
+
const deliver = queryListener(listener, options);
|
|
227
|
+
if (this.#disposed) {
|
|
228
|
+
deliver(this.#state);
|
|
229
|
+
return () => { };
|
|
230
|
+
}
|
|
231
|
+
this.#listeners.add(deliver);
|
|
232
|
+
this.#deliver(deliver, this.#state);
|
|
233
|
+
const stop = () => {
|
|
234
|
+
options.signal?.removeEventListener("abort", stop);
|
|
235
|
+
this.#listeners.delete(deliver);
|
|
236
|
+
if (!this.#listeners.size)
|
|
237
|
+
this.dispose();
|
|
238
|
+
};
|
|
239
|
+
options.signal?.addEventListener("abort", stop, { once: true });
|
|
240
|
+
// The initial callback may abort or dispose synchronously before registration.
|
|
241
|
+
if (options.signal?.aborted || this.#disposed)
|
|
242
|
+
stop();
|
|
243
|
+
return stop;
|
|
244
|
+
}
|
|
245
|
+
#retire(error) {
|
|
246
|
+
if (this.#disposed)
|
|
247
|
+
return;
|
|
248
|
+
this.#disposed = true;
|
|
249
|
+
this.#identitySignal?.removeEventListener("abort", this.#abort);
|
|
250
|
+
for (const slot of this.#slots) {
|
|
251
|
+
const stopWatch = slot.stop;
|
|
252
|
+
delete slot.stop;
|
|
253
|
+
stopWatch?.();
|
|
254
|
+
}
|
|
255
|
+
this.#slots = [];
|
|
256
|
+
this.#publish({ status: "error", error });
|
|
257
|
+
// Terminal delivery must finish before membership is retired, including
|
|
258
|
+
// when auth changes inside an adapter notification transaction.
|
|
259
|
+
notification(() => this.#listeners.clear());
|
|
260
|
+
}
|
|
261
|
+
dispose() { this.#retire(new DatabaseError({ code: "disposed", message: "Pagination handle is disposed" })); }
|
|
262
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
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 } from "node:fs/promises";
|
|
10
|
+
import { dirname, relative, resolve, sep } from "node:path";
|
|
11
|
+
import { defineConfig } from "./config.js";
|
|
12
|
+
import { discoverFunctions, generateFunctions } from "./codegen.js";
|
|
13
|
+
import { checkGeneratedDirectory, generateSchema } from "./schema-codegen.js";
|
|
14
|
+
import { compileWorker, workerBundleHeader } from "./worker-codegen.js";
|
|
15
|
+
const header = "// Generated server by @hulla/db. Do not edit.\n";
|
|
16
|
+
const workerHeader = "// Generated worker by @hulla/db. Do not edit.\n";
|
|
17
|
+
function importPath(directory, path) {
|
|
18
|
+
const value = relative(directory, path).split(sep).join("/");
|
|
19
|
+
return value.startsWith(".") ? value : `./${value}`;
|
|
20
|
+
}
|
|
21
|
+
/** Generate a project from its trusted config without opening a database or listener. */
|
|
22
|
+
export async function generateProject(configPath = "db.config.ts") {
|
|
23
|
+
const source = resolve(configPath);
|
|
24
|
+
const config = defineConfig((await import(__rewriteRelativeImportExtension(Bun.pathToFileURL(source).href))).default);
|
|
25
|
+
const root = dirname(source);
|
|
26
|
+
const schema = resolve(root, config.schema ?? "db/schema.ts");
|
|
27
|
+
const outDir = resolve(dirname(schema), "_generated");
|
|
28
|
+
const client = resolve(outDir, "client");
|
|
29
|
+
await checkGeneratedDirectory(outDir);
|
|
30
|
+
await checkGeneratedDirectory(client);
|
|
31
|
+
const server = resolve(outDir, "server.ts");
|
|
32
|
+
const worker = resolve(outDir, "worker.ts");
|
|
33
|
+
const bundle = resolve(outDir, "worker.js");
|
|
34
|
+
for (const [path, generatedHeader] of [[server, header], [worker, workerHeader], [bundle, workerBundleHeader]]) {
|
|
35
|
+
const info = await lstat(path).catch((error) => {
|
|
36
|
+
if (error.code === "ENOENT")
|
|
37
|
+
return undefined;
|
|
38
|
+
throw error;
|
|
39
|
+
});
|
|
40
|
+
if (info && (!info.isFile() || info.isSymbolicLink() || !(await Bun.file(path).text()).startsWith(generatedHeader)))
|
|
41
|
+
throw new Error(`Refusing to overwrite an authored file: ${path}`);
|
|
42
|
+
}
|
|
43
|
+
await generateSchema({ schema, outDir, config: source });
|
|
44
|
+
const modules = await discoverFunctions({ schema, outDir: client,
|
|
45
|
+
...(config.functions === undefined ? {} : { functions: resolve(root, config.functions) }),
|
|
46
|
+
});
|
|
47
|
+
const entries = Object.entries(modules);
|
|
48
|
+
await Bun.write(worker, `${workerHeader}import schema from ${JSON.stringify(importPath(outDir, schema))}
|
|
49
|
+
import { installWorker } from '@hulla/db/internal/worker'
|
|
50
|
+
${entries.map(([, path], index) => `import * as module${index} from ${JSON.stringify(importPath(outDir, path))}`).join("\n")}
|
|
51
|
+
|
|
52
|
+
installWorker({ schema, modules: {
|
|
53
|
+
${entries.map(([name], index) => ` ${JSON.stringify(name)}: module${index},`).join("\n")}
|
|
54
|
+
} })
|
|
55
|
+
`);
|
|
56
|
+
// Diagnose statically resolved unsupported imports before generation evaluates
|
|
57
|
+
// selected declaration modules in its trusted build process.
|
|
58
|
+
const compiled = await compileWorker(worker);
|
|
59
|
+
await generateFunctions({ schema, outDir: client, modules, ...(config.database.client === undefined ? {} : { client: config.database.client }), ...(config.limits === undefined ? {} : { limits: config.limits }) });
|
|
60
|
+
await Bun.write(bundle, compiled);
|
|
61
|
+
await Bun.write(server, `${header}import config from ${JSON.stringify(importPath(outDir, source))}
|
|
62
|
+
import schema from ${JSON.stringify(importPath(outDir, schema))}
|
|
63
|
+
import type { Schema } from './types'
|
|
64
|
+
import { createDatabase, type Database } from '@hulla/db/server'
|
|
65
|
+
|
|
66
|
+
export const db: Database<Schema> = createDatabase(schema as Schema, config.database.server, config.limits)
|
|
67
|
+
`);
|
|
68
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Inclusion-only selections. Nullish values and false support conditional fields. */
|
|
2
|
+
export type Projection<R> = readonly (Extract<keyof R, string> | false | null | undefined)[] | {
|
|
3
|
+
readonly [K in keyof R]?: boolean | null | undefined;
|
|
4
|
+
};
|
|
5
|
+
export type ValidProjection<R, P> = P extends readonly unknown[] ? unknown : Record<Exclude<keyof P, keyof R>, never>;
|
|
6
|
+
type IsUnion<T, U = T> = T extends U ? [U] extends [T] ? false : true : never;
|
|
7
|
+
type GuaranteedEntry<R, V> = [V] extends [keyof R] ? true extends IsUnion<V> ? never : V : never;
|
|
8
|
+
type RequiredKeys<R, P> = P extends readonly unknown[] ? number extends P["length"] ? never : {
|
|
9
|
+
[I in keyof P]: GuaranteedEntry<R, P[I]>;
|
|
10
|
+
}[number] : {
|
|
11
|
+
[K in keyof P]: [P[K]] extends [true] ? K : never;
|
|
12
|
+
}[keyof P];
|
|
13
|
+
type IncludedKeys<R, P> = P extends readonly unknown[] ? Extract<P[number], keyof R> : {
|
|
14
|
+
[K in keyof P]: true extends P[K] ? K : never;
|
|
15
|
+
}[keyof P];
|
|
16
|
+
export type Projected<R, P> = Pick<R, Extract<RequiredKeys<R, P>, keyof R>> & Partial<Pick<R, Exclude<Extract<IncludedKeys<R, P>, keyof R>, RequiredKeys<R, P>>>>;
|
|
17
|
+
/** Capture the effective selection now, independently of subsequent application changes. */
|
|
18
|
+
export declare function parseProjection(fields: Readonly<Record<string, unknown>>, input: unknown): readonly string[];
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** Capture the effective selection now, independently of subsequent application changes. */
|
|
2
|
+
export function parseProjection(fields, input) {
|
|
3
|
+
const selected = new Set();
|
|
4
|
+
function field(key) {
|
|
5
|
+
if (typeof key !== "string" || !Object.hasOwn(fields, key))
|
|
6
|
+
throw new TypeError(`Unknown projection field ${String(key)}`);
|
|
7
|
+
selected.add(key);
|
|
8
|
+
}
|
|
9
|
+
if (Array.isArray(input)) {
|
|
10
|
+
for (const key of input) {
|
|
11
|
+
if (key !== false && key !== null && key !== undefined)
|
|
12
|
+
field(key);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
if (!input || typeof input !== "object" || ![null, Object.prototype].includes(Object.getPrototypeOf(input)))
|
|
17
|
+
throw new TypeError("Expected field selection array or inclusion object");
|
|
18
|
+
for (const key of Reflect.ownKeys(input)) {
|
|
19
|
+
if (typeof key !== "string" || !Object.hasOwn(fields, key))
|
|
20
|
+
throw new TypeError(`Unknown projection field ${String(key)}`);
|
|
21
|
+
const value = input[key];
|
|
22
|
+
if (value === true)
|
|
23
|
+
field(key);
|
|
24
|
+
else if (value !== false && value !== null && value !== undefined)
|
|
25
|
+
throw new TypeError(`Invalid selection value for ${key}`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (!selected.size)
|
|
29
|
+
throw new TypeError("Field selection must include at least one field");
|
|
30
|
+
return Object.freeze([...selected]);
|
|
31
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Keep spawned workers and bundled declarations on the parent's package exports. */
|
|
2
|
+
export function runtimeExportConditions() {
|
|
3
|
+
return process.execArgv.flatMap((argument, index, args) => {
|
|
4
|
+
if (argument.startsWith("--conditions="))
|
|
5
|
+
return [argument.slice("--conditions=".length)];
|
|
6
|
+
if ((argument === "--conditions" || argument === "-C") && args[index + 1])
|
|
7
|
+
return [args[index + 1]];
|
|
8
|
+
return [];
|
|
9
|
+
});
|
|
10
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { FunctionRuntime } from "./contracts.ts";
|
|
2
|
+
import type { ClientAuthInput } from "./auth.ts";
|
|
3
|
+
/** One generated application module owns one scope; no global current user. */
|
|
4
|
+
export declare class RuntimeScope {
|
|
5
|
+
#private;
|
|
6
|
+
/** Local lifecycle notifications used by UI bindings, not authentication proof. */
|
|
7
|
+
subscribe(listener: () => void): () => void;
|
|
8
|
+
/** Install once in bootstrap. Server resolvers must use current-request scope. */
|
|
9
|
+
configure(resolve: () => FunctionRuntime): () => void;
|
|
10
|
+
current(): FunctionRuntime;
|
|
11
|
+
setAuth(state: ClientAuthInput): void | Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
export declare function createRuntimeScope(): RuntimeScope;
|
package/dist/runtime.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** One generated application module owns one scope; no global current user. */
|
|
2
|
+
export class RuntimeScope {
|
|
3
|
+
#resolver;
|
|
4
|
+
#listeners = new Set();
|
|
5
|
+
/** Local lifecycle notifications used by UI bindings, not authentication proof. */
|
|
6
|
+
subscribe(listener) {
|
|
7
|
+
this.#listeners.add(listener);
|
|
8
|
+
return () => { this.#listeners.delete(listener); };
|
|
9
|
+
}
|
|
10
|
+
#notify() {
|
|
11
|
+
for (const listener of [...this.#listeners])
|
|
12
|
+
listener();
|
|
13
|
+
}
|
|
14
|
+
/** Install once in bootstrap. Server resolvers must use current-request scope. */
|
|
15
|
+
configure(resolve) {
|
|
16
|
+
if (this.#resolver)
|
|
17
|
+
throw new Error("The function runtime scope is already configured");
|
|
18
|
+
this.#resolver = resolve;
|
|
19
|
+
this.#notify();
|
|
20
|
+
return () => {
|
|
21
|
+
if (this.#resolver === resolve) {
|
|
22
|
+
this.#resolver = undefined;
|
|
23
|
+
this.#notify();
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
current() {
|
|
28
|
+
if (!this.#resolver)
|
|
29
|
+
throw new Error("No function runtime is configured for this application");
|
|
30
|
+
return this.#resolver();
|
|
31
|
+
}
|
|
32
|
+
setAuth(state) {
|
|
33
|
+
const runtime = this.current();
|
|
34
|
+
if (!runtime.setAuth)
|
|
35
|
+
throw new Error("The configured runtime does not support client auth updates");
|
|
36
|
+
const result = runtime.setAuth(state);
|
|
37
|
+
this.#notify();
|
|
38
|
+
if (result) {
|
|
39
|
+
const resolution = Promise.resolve(result).finally(() => this.#notify());
|
|
40
|
+
void resolution.catch(() => { });
|
|
41
|
+
return resolution;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export function createRuntimeScope() {
|
|
46
|
+
return new RuntimeScope();
|
|
47
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type SchemaDefinition } from "./schema.ts";
|
|
2
|
+
/** Emit native declarations, then let Rust normalize through its existing contract. */
|
|
3
|
+
export declare function generateRustSchema(schema: SchemaDefinition): string;
|
|
4
|
+
export interface SchemaGenerationOptions {
|
|
5
|
+
/** Trusted authored module with a default defineSchema export. Executes at build time. */
|
|
6
|
+
readonly schema: string;
|
|
7
|
+
/** Schema types, declarations and query-facing table references are written here. */
|
|
8
|
+
readonly outDir: string;
|
|
9
|
+
/** Optional config module used only to infer the verified identity type. */
|
|
10
|
+
readonly config?: string;
|
|
11
|
+
/** Optional native Rust fixture output; ordinary projects do not need this. */
|
|
12
|
+
readonly rustOutput?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare function generateSchema(options: SchemaGenerationOptions): Promise<void>;
|
|
15
|
+
/** Check the requested directory and missing ancestors before recursive mkdir. */
|
|
16
|
+
export declare function checkGeneratedDirectory(directory: string): Promise<void>;
|