@terrascale/sdk 0.0.0-stage → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/CHANGELOG.md +62 -0
  2. package/LICENSE +202 -0
  3. package/README.md +202 -2
  4. package/package.json +152 -4
  5. package/sdk-v1-route-manifest.json +2330 -0
  6. package/src/admin.js +9 -0
  7. package/src/better-auth.js +14 -0
  8. package/src/config.js +121 -0
  9. package/src/database-codec.js +845 -0
  10. package/src/database-types.js +237 -0
  11. package/src/database-view.js +423 -0
  12. package/src/database.js +2 -0
  13. package/src/http.js +898 -0
  14. package/src/index.js +62 -0
  15. package/src/local/authentication.js +47 -0
  16. package/src/local/better-auth.js +517 -0
  17. package/src/local/cli.js +51 -0
  18. package/src/local/context.js +23 -0
  19. package/src/local/environment.js +109 -0
  20. package/src/local/index.js +206 -0
  21. package/src/local/legacy-client.js +411 -0
  22. package/src/local/router.js +999 -0
  23. package/src/local/server.js +664 -0
  24. package/src/local/store.js +530 -0
  25. package/src/local/test-environment.js +74 -0
  26. package/src/management-contracts.js +72 -0
  27. package/src/management.js +12 -0
  28. package/src/native-origin.js +75 -0
  29. package/src/postgres.js +496 -0
  30. package/src/react/core.js +743 -0
  31. package/src/react/index.js +99 -0
  32. package/src/result.js +251 -0
  33. package/src/schema.js +366 -0
  34. package/src/sql.js +996 -0
  35. package/src/svelte/index.js +129 -0
  36. package/src/tanstack/index.js +512 -0
  37. package/src/ts-auth-discovery.js +207 -0
  38. package/src/ts-auth.js +3498 -0
  39. package/src/v1/decode.js +118 -0
  40. package/src/v1/errors.js +185 -0
  41. package/src/v1/filter.js +230 -0
  42. package/src/v1/ids.js +119 -0
  43. package/src/v1/json.js +335 -0
  44. package/src/v1/routes.js +57 -0
  45. package/src/v1/shapes.js +145 -0
  46. package/src/v1/terrabase-v1.js +722 -0
  47. package/src/v1/transport.js +324 -0
  48. package/types/admin.d.ts +6 -0
  49. package/types/better-auth.d.ts +8 -0
  50. package/types/config.d.ts +58 -0
  51. package/types/database-codec.d.ts +111 -0
  52. package/types/database-types.d.ts +213 -0
  53. package/types/database-view.d.ts +184 -0
  54. package/types/database.d.ts +2 -0
  55. package/types/http.d.ts +47 -0
  56. package/types/index.d.ts +43 -0
  57. package/types/local/authentication.d.ts +11 -0
  58. package/types/local/better-auth.d.ts +33 -0
  59. package/types/local/cli.d.ts +2 -0
  60. package/types/local/context.d.ts +14 -0
  61. package/types/local/environment.d.ts +23 -0
  62. package/types/local/index.d.ts +96 -0
  63. package/types/local/legacy-client.d.ts +94 -0
  64. package/types/local/router.d.ts +66 -0
  65. package/types/local/server.d.ts +54 -0
  66. package/types/local/store.d.ts +106 -0
  67. package/types/local/test-environment.d.ts +25 -0
  68. package/types/management-contracts.d.ts +44 -0
  69. package/types/management.d.ts +6 -0
  70. package/types/native-origin.d.ts +23 -0
  71. package/types/postgres.d.ts +124 -0
  72. package/types/react/core.d.ts +366 -0
  73. package/types/react/index.d.ts +54 -0
  74. package/types/result.d.ts +161 -0
  75. package/types/schema.d.ts +145 -0
  76. package/types/sql.d.ts +288 -0
  77. package/types/svelte/index.d.ts +81 -0
  78. package/types/tanstack/index.d.ts +166 -0
  79. package/types/ts-auth-discovery.d.ts +19 -0
  80. package/types/ts-auth.d.ts +1826 -0
  81. package/types/v1/decode.d.ts +119 -0
  82. package/types/v1/errors.d.ts +107 -0
  83. package/types/v1/filter.d.ts +148 -0
  84. package/types/v1/ids.d.ts +44 -0
  85. package/types/v1/json.d.ts +92 -0
  86. package/types/v1/routes.d.ts +26 -0
  87. package/types/v1/shapes.d.ts +78 -0
  88. package/types/v1/terrabase-v1.d.ts +374 -0
  89. package/types/v1/transport.d.ts +117 -0
@@ -0,0 +1,324 @@
1
+ // Internal typed transport for the TerraBase v1 client. It is not exported
2
+ // from any package entrypoint: callers reach it only through named operations.
3
+ import { parseV1Error } from "./errors.js";
4
+ import { requireName, requireProject } from "./ids.js";
5
+ import { parseExactJson } from "./json.js";
6
+ import { v1Route, v1RoutePath } from "./routes.js";
7
+ /**
8
+ * @import { FetchLike } from "../config.js"
9
+ * @import { TerraBaseV1Error } from "./errors.js"
10
+ * @import { JsonValue } from "./json.js"
11
+ * @import { V1Operation } from "./routes.js"
12
+ */
13
+
14
+ /** Server request body limit (api-v1.md). */
15
+ export const maximumRequestBytes = 4 * 1024 * 1024;
16
+ // Query budgets count stored JSON before wrappers and serializer escaping.
17
+ const defaultMaximumResponseBytes = 64 * 1024 * 1024;
18
+ const tokenPattern = /^tb_[A-Za-z0-9_-]{43}$/u;
19
+ /**
20
+ * Resolver input contains no credential. A successful URL is cached for this client/database.
21
+ * @typedef {{ readonly project: string; readonly database: string; readonly signal?: AbortSignal | undefined }} V1EndpointContext
22
+ */
23
+ /** @typedef {(context: V1EndpointContext) => string | Promise<string>} V1EndpointResolver */
24
+ /**
25
+ * Project-scoped C# Documents API client. Supply exactly one of baseUrl or endpointResolver.
26
+ * URLs must use HTTPS or loopback HTTP. Mutations are never automatically replayed.
27
+ * @typedef {object} TerraBaseV1ClientConfig
28
+ * @property {string} project
29
+ * @property {string} token A tb_ API key; held privately.
30
+ * @property {string | undefined} [baseUrl]
31
+ * @property {V1EndpointResolver | undefined} [endpointResolver]
32
+ * @property {FetchLike | undefined} [fetch]
33
+ * @property {number | undefined} [maxResponseBytes] Default 64 MiB, including query framing and escaping.
34
+ */
35
+
36
+ /**
37
+ * @typedef {object} V1CallOptions
38
+ * @property {string} [body]
39
+ * @property {string} [contentType]
40
+ * @property {Readonly<Record<string, string>>} [headers] Contract headers only (If-Match, If-None-Match).
41
+ * @property {URLSearchParams | undefined} [query]
42
+ * @property {AbortSignal | undefined} [signal]
43
+ */
44
+
45
+ /**
46
+ * @typedef {object} V1CallResult
47
+ * @property {number} status
48
+ * @property {Headers} headers
49
+ * @property {JsonValue | undefined} value
50
+ */
51
+
52
+ /**
53
+ * @param {string} host
54
+ * @returns {boolean}
55
+ */
56
+ function isLoopbackHost(host) {
57
+ const name = host.toLowerCase();
58
+ return (
59
+ name === "localhost" ||
60
+ name.endsWith(".localhost") ||
61
+ name === "[::1]" ||
62
+ isLoopbackIpv4(name)
63
+ );
64
+ }
65
+
66
+ /**
67
+ * A dotted-decimal address in 127.0.0.0/8 with every octet at most 255. An
68
+ * out-of-range octet would make the URL parser treat the host as a DNS name.
69
+ * @param {string} name
70
+ * @returns {boolean}
71
+ */
72
+ function isLoopbackIpv4(name) {
73
+ const octets = /^127\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/u.exec(name);
74
+ return octets !== null && octets.slice(1).every((octet) => Number(octet) <= 255);
75
+ }
76
+
77
+ /**
78
+ * @param {string} raw
79
+ * @param {string} what
80
+ * @returns {URL}
81
+ */
82
+ export function requireServiceUrl(raw, what) {
83
+ /** @type {URL} */
84
+ let url;
85
+ if (typeof raw !== "string") throw new TypeError(`${what} must be an absolute URL.`);
86
+ try {
87
+ url = new URL(raw);
88
+ } catch {
89
+ throw new TypeError(`${what} must be an absolute URL.`);
90
+ }
91
+ if (url.username !== "" || url.password !== "" || url.hash !== "")
92
+ throw new TypeError(`${what} must not carry credentials or a fragment.`);
93
+ if (
94
+ url.protocol !== "https:" &&
95
+ !(url.protocol === "http:" && isLoopbackHost(url.hostname))
96
+ )
97
+ throw new TypeError(`${what} must use HTTPS; plain HTTP is allowed only for loopback hosts.`);
98
+ return url;
99
+ }
100
+
101
+ /**
102
+ * An explicitly configured endpoint, with no discovery or hardcoded hosts.
103
+ * @param {string} baseUrl
104
+ * @returns {V1EndpointResolver}
105
+ */
106
+ export function staticBaseUrlResolver(baseUrl) {
107
+ const base = canonicalBaseUrl(baseUrl);
108
+ return () => base;
109
+ }
110
+ /** @param {string} raw @returns {string} */
111
+ function canonicalBaseUrl(raw) {
112
+ const url = requireServiceUrl(raw, "baseUrl");
113
+ if (url.search !== "") throw new TypeError("baseUrl must not carry a query.");
114
+ return `${url.origin}${url.pathname.replace(/\/+$/u, "")}`;
115
+ }
116
+
117
+ /** A response body that failed in transit after its headers arrived. */
118
+ export class BodyTransportError extends Error {
119
+ /** @param {unknown} cause */
120
+ constructor(cause) {
121
+ super("TerraBase response body failed in transit.", { cause });
122
+ this.name = "BodyTransportError";
123
+ }
124
+ }
125
+
126
+ /** Internal transport bound to one data key. */
127
+ export class V1Transport {
128
+ /** @type {string} */
129
+ #project;
130
+ /** @type {V1EndpointResolver} */
131
+ #resolver;
132
+ /** @type {Map<string, { promise: Promise<string>; timer: ReturnType<typeof setTimeout>; waiters: number }>} */
133
+ #bases = new Map();
134
+ /** @type {string} */
135
+ #token;
136
+ /** @type {FetchLike} */
137
+ #fetch;
138
+ /** @type {number} */
139
+ #maxResponseBytes;
140
+
141
+ /** @param {TerraBaseV1ClientConfig} config */
142
+ constructor(config) {
143
+ if (typeof config !== "object" || config === null) throw new TypeError("TerraBase v1 client config is required.");
144
+ this.#project = requireProject(config.project);
145
+ if ((config.baseUrl === undefined) === (config.endpointResolver === undefined))
146
+ throw new TypeError("Supply exactly one of baseUrl or endpointResolver.");
147
+ if (config.endpointResolver !== undefined && typeof config.endpointResolver !== "function")
148
+ throw new TypeError("endpointResolver must be a function.");
149
+ this.#resolver = config.endpointResolver ?? staticBaseUrlResolver(/** @type {string} */ (config.baseUrl));
150
+ if (typeof config.token !== "string" || !tokenPattern.test(config.token))
151
+ throw new TypeError("token must be a tb_ API key with 43 base64url characters.");
152
+ if ("autoIdempotencyKey" in config || "maxRetries" in config || "resolver" in config)
153
+ throw new TypeError("Unsupported client configuration member.");
154
+ const fetchHandler = config.fetch ?? globalThis.fetch?.bind(globalThis);
155
+ if (typeof fetchHandler !== "function") throw new TypeError("TerraBase v1 client requires a fetch implementation.");
156
+ const maxResponseBytes = config.maxResponseBytes ?? defaultMaximumResponseBytes;
157
+ if (!Number.isSafeInteger(maxResponseBytes) || maxResponseBytes < 1)
158
+ throw new TypeError("maxResponseBytes must be a positive integer.");
159
+ this.#token = config.token;
160
+ this.#fetch = fetchHandler;
161
+ this.#maxResponseBytes = maxResponseBytes;
162
+ }
163
+
164
+ /**
165
+ * @param {V1Operation} operation
166
+ * @param {Readonly<Record<string, string>>} params
167
+ * @param {AbortSignal | undefined} [signal]
168
+ * @returns {Promise<string>}
169
+ */
170
+ async url(operation, params, signal) {
171
+ signal?.throwIfAborted();
172
+ const database = requireName("database", params.database);
173
+ let base = this.#bases.get(database);
174
+ if (base === undefined) {
175
+ const controller = new AbortController();
176
+ const timer = setTimeout(() => controller.abort(new DOMException(
177
+ "TerraBase endpoint resolution timed out after 30 seconds.", "TimeoutError",
178
+ )), 30_000);
179
+ /** @type {Promise<string>} */
180
+ const promise = new Promise((resolve, reject) => {
181
+ controller.signal.addEventListener("abort", () => reject(controller.signal.reason), { once: true });
182
+ void Promise.resolve().then(() => this.#resolver(Object.freeze({
183
+ project: this.#project, database, signal: controller.signal,
184
+ }))).then(canonicalBaseUrl).then(resolve, reject).finally(() => clearTimeout(timer));
185
+ });
186
+ base = { promise, timer, waiters: 0 };
187
+ this.#bases.set(database, base);
188
+ // A failed resolution is not a session; a later operation may resolve again.
189
+ void promise.catch(() => { if (this.#bases.get(database) === base) this.#bases.delete(database); });
190
+ }
191
+ base.waiters++;
192
+ if (typeof base.timer === "object") base.timer.ref();
193
+ try {
194
+ // Each caller cancels its own wait; one caller cannot abort shared session resolution.
195
+ const resolved = signal === undefined ? await base.promise : await new Promise((resolve, reject) => {
196
+ const abort = () => reject(signal.reason);
197
+ signal.addEventListener("abort", abort, { once: true });
198
+ void base.promise.then(value => {
199
+ signal.removeEventListener("abort", abort);
200
+ resolve(value);
201
+ }, error => {
202
+ signal.removeEventListener("abort", abort);
203
+ reject(error);
204
+ });
205
+ });
206
+ signal?.throwIfAborted();
207
+ return `${resolved}${v1RoutePath(v1Route(operation), { ...params, project: this.#project })}`;
208
+ } finally {
209
+ // Keep Node alive only while callers are waiting for this resolution.
210
+ if (--base.waiters === 0 && typeof base.timer === "object") base.timer.unref();
211
+ }
212
+ }
213
+
214
+ /**
215
+ * Reads a response body as UTF-8 text within the response byte bound. A
216
+ * connection failure while reading is a BodyTransportError.
217
+ * @param {Response} response
218
+ * @returns {Promise<string>}
219
+ */
220
+ async readText(response) {
221
+ const reader = response.body?.getReader();
222
+ if (reader === undefined) return "";
223
+ /** @type {Uint8Array[]} */
224
+ const parts = [];
225
+ let size = 0;
226
+ try {
227
+ while (true) {
228
+ /** @type {ReadableStreamReadResult<Uint8Array>} */
229
+ let part;
230
+ try {
231
+ part = await reader.read();
232
+ } catch (error) {
233
+ throw new BodyTransportError(error);
234
+ }
235
+ if (part.done) break;
236
+ size += part.value.byteLength;
237
+ if (size > this.#maxResponseBytes)
238
+ throw new TypeError(`TerraBase response exceeds ${this.#maxResponseBytes} bytes.`);
239
+ parts.push(part.value);
240
+ }
241
+ } catch (error) {
242
+ void reader.cancel().catch(() => undefined);
243
+ throw error;
244
+ } finally {
245
+ reader.releaseLock();
246
+ }
247
+ const bytes = new Uint8Array(size);
248
+ let offset = 0;
249
+ for (const part of parts) {
250
+ bytes.set(part, offset);
251
+ offset += part.byteLength;
252
+ }
253
+ return new TextDecoder("utf-8", { fatal: true }).decode(bytes);
254
+ }
255
+
256
+ /**
257
+ * Parses a JSON response body exactly.
258
+ * @param {Response} response
259
+ * @returns {Promise<JsonValue | undefined>}
260
+ */
261
+ async readJson(response) {
262
+ return V1Transport.#decodeJson(response, await this.readText(response));
263
+ }
264
+
265
+ /**
266
+ * @param {Response} response
267
+ * @param {string} text
268
+ * @returns {JsonValue | undefined}
269
+ */
270
+ static #decodeJson(response, text) {
271
+ if (text === "") return undefined;
272
+ const mediaType = response.headers.get("content-type")?.split(";", 1)[0]?.trim().toLowerCase();
273
+ if (mediaType !== "application/json")
274
+ throw new TypeError(`TerraBase returned ${mediaType ?? "no media type"} instead of application/json.`);
275
+ return parseExactJson(text);
276
+ }
277
+
278
+ /**
279
+ * Converts a non-success response to a TerraBaseV1Error.
280
+ * @param {Response} response
281
+ * @returns {Promise<TerraBaseV1Error>}
282
+ */
283
+ async error(response) {
284
+ let text = "";
285
+ try {
286
+ text = await this.readText(response);
287
+ } catch {
288
+ text = "";
289
+ }
290
+ return parseV1Error(response.status, response.headers, text);
291
+ }
292
+
293
+ /**
294
+ * Calls only a named producer route. Redirects and failed mutations are never replayed.
295
+ * @param {V1Operation} operation
296
+ * @param {Readonly<Record<string, string>>} params
297
+ * @param {V1CallOptions} [options]
298
+ * @returns {Promise<V1CallResult>}
299
+ */
300
+ async call(operation, params, options = {}) {
301
+ const route = v1Route(operation);
302
+ if (options.body !== undefined && new TextEncoder().encode(options.body).byteLength > maximumRequestBytes)
303
+ throw new TypeError(`TerraBase request bodies are limited to ${maximumRequestBytes} bytes.`);
304
+ let url = await this.url(operation, params, options.signal);
305
+ if (options.query !== undefined && options.query.size > 0) url += `?${options.query}`;
306
+ const headers = new Headers(options.headers);
307
+ headers.set("authorization", `Bearer ${this.#token}`);
308
+ headers.set("accept", route.responseMediaType);
309
+ if (options.body !== undefined) headers.set("content-type", options.contentType ?? "application/json");
310
+ /** @type {RequestInit} */
311
+ const init = { method: route.method, headers, redirect: "manual" };
312
+ if (options.body !== undefined) init.body = options.body;
313
+ if (options.signal !== undefined) init.signal = options.signal;
314
+ const response = await this.#fetch(url, init);
315
+ if (response.type === "opaqueredirect")
316
+ throw new TypeError("Fresh shape bootstrap requires server fetch; obtain a handle and snapshot offset with collection.shape() on your server.");
317
+ if (!route.successStatuses.includes(response.status)) throw await this.error(response);
318
+ if (response.status === 307) {
319
+ await response.body?.cancel();
320
+ return { status: response.status, headers: response.headers, value: undefined };
321
+ }
322
+ return { status: response.status, headers: response.headers, value: await this.readJson(response) };
323
+ }
324
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Administrative operations require the admitted regional management contract.
3
+ * @returns {never}
4
+ */
5
+ export function requireTerraScaleAdministration(): never;
6
+ export { TerraScaleCapabilityUnavailableError } from "./management-contracts.js";
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Production Better Auth persistence is required but blocked by security authority
3
+ * and catalog/credential admission. Local development uses the explicit ./local
4
+ * SQLite factory pinned to Better Auth 1.7.2.
5
+ * @returns {never}
6
+ */
7
+ export function requireTerraScaleBetterAuth(): never;
8
+ export { terraScaleReleaseBlockers, TerraScaleCapabilityUnavailableError } from "./management-contracts.js";
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Shared fetch signature; native database and hosted identity credentials stay distinct.
3
+ * @typedef {(input: RequestInfo | URL, init?: RequestInit) => Promise<Response>} FetchLike
4
+ */
5
+ /**
6
+ * @typedef {string | (() => Promise<string | undefined> | string | undefined)} AccessTokenProvider
7
+ */
8
+ /**
9
+ * `requestTimeoutMs`: one deadline covers discovery, credentials, requests, bodies and retry delays.
10
+ * @typedef {{
11
+ * readonly apiBaseUrl: string;
12
+ * readonly accessToken?: AccessTokenProvider;
13
+ * readonly fetch?: FetchLike;
14
+ * readonly maxRetryAttempts?: number | undefined;
15
+ * readonly retryDelayMs?: number | undefined;
16
+ * readonly requestTimeoutMs?: number | undefined;
17
+ * }} TsAuthRuntimeConfig
18
+ */
19
+ /**
20
+ * @typedef {{
21
+ * readonly apiBaseUrl: string;
22
+ * readonly maxRetryAttempts: number;
23
+ * readonly retryDelayMs: number;
24
+ * readonly requestTimeoutMs: number;
25
+ * }} ResolvedTsAuthRuntimeConfig
26
+ */
27
+ /**
28
+ * @param {TsAuthRuntimeConfig} config
29
+ * @returns {ResolvedTsAuthRuntimeConfig}
30
+ */
31
+ export function resolveTsAuthRuntimeConfig(config: TsAuthRuntimeConfig): ResolvedTsAuthRuntimeConfig;
32
+ /**
33
+ * @param {AccessTokenProvider | undefined} provider
34
+ * @returns {Promise<string | undefined>}
35
+ */
36
+ export function resolveAccessToken(provider: AccessTokenProvider | undefined): Promise<string | undefined>;
37
+ /**
38
+ * Shared fetch signature; native database and hosted identity credentials stay distinct.
39
+ */
40
+ export type FetchLike = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
41
+ export type AccessTokenProvider = string | (() => Promise<string | undefined> | string | undefined);
42
+ /**
43
+ * `requestTimeoutMs`: one deadline covers discovery, credentials, requests, bodies and retry delays.
44
+ */
45
+ export type TsAuthRuntimeConfig = {
46
+ readonly apiBaseUrl: string;
47
+ readonly accessToken?: AccessTokenProvider;
48
+ readonly fetch?: FetchLike;
49
+ readonly maxRetryAttempts?: number | undefined;
50
+ readonly retryDelayMs?: number | undefined;
51
+ readonly requestTimeoutMs?: number | undefined;
52
+ };
53
+ export type ResolvedTsAuthRuntimeConfig = {
54
+ readonly apiBaseUrl: string;
55
+ readonly maxRetryAttempts: number;
56
+ readonly retryDelayMs: number;
57
+ readonly requestTimeoutMs: number;
58
+ };
@@ -0,0 +1,111 @@
1
+ /**
2
+ * @param {unknown} value
3
+ * @param {string} [name]
4
+ * @returns {string}
5
+ */
6
+ export function requireDatabaseUuid(value: unknown, name?: string): string;
7
+ /**
8
+ * @param {unknown} value
9
+ * @param {string} [name]
10
+ * @param {boolean} [positive]
11
+ * @returns {bigint}
12
+ */
13
+ export function requireDatabaseU64(value: unknown, name?: string, positive?: boolean): bigint;
14
+ /**
15
+ * Typed value encoding preserves numeric field IDs, arrays, bytes, and explicit null.
16
+ * @param {DatabaseValue} value
17
+ * @returns {JsonObject}
18
+ */
19
+ export function encodeDatabaseValue(value: DatabaseValue): JsonObject;
20
+ /**
21
+ * @param {unknown} value
22
+ * @returns {DatabaseValue}
23
+ */
24
+ export function decodeDatabaseValue(value: unknown): DatabaseValue;
25
+ /**
26
+ * @param {unknown} raw
27
+ * @returns {DatabasePoint}
28
+ */
29
+ export function decodeDatabasePoint(raw: unknown): DatabasePoint;
30
+ /**
31
+ * @param {DatabaseQuery} query
32
+ * @returns {string}
33
+ */
34
+ export function encodeDatabaseQuery(query: DatabaseQuery): string;
35
+ /**
36
+ * @param {unknown} raw
37
+ * @returns {DatabaseQueryPage}
38
+ */
39
+ export function decodeDatabaseQueryPage(raw: unknown): DatabaseQueryPage;
40
+ /**
41
+ * @param {DatabaseSubscriptionRequest} request
42
+ * @returns {string}
43
+ */
44
+ export function encodeDatabaseSubscription(request: DatabaseSubscriptionRequest): string;
45
+ /**
46
+ * @param {unknown} raw
47
+ * @returns {DatabaseSubscriptionResponse}
48
+ */
49
+ export function decodeDatabaseSubscription(raw: unknown): DatabaseSubscriptionResponse;
50
+ /**
51
+ * @param {DatabaseAuthority} authority
52
+ * @returns {JsonObject}
53
+ */
54
+ export function encodeDatabaseAuthority(authority: DatabaseAuthority): JsonObject;
55
+ /**
56
+ * @param {unknown} raw
57
+ * @returns {DatabaseAuthority}
58
+ */
59
+ export function decodeDatabaseAuthority(raw: unknown): DatabaseAuthority;
60
+ /**
61
+ * @param {unknown} raw
62
+ * @returns {DatabaseCommitReceipt}
63
+ */
64
+ export function decodeDatabaseCommitReceipt(raw: unknown): DatabaseCommitReceipt;
65
+ /**
66
+ * @param {DatabaseTransactionIdentity} identity
67
+ * @returns {string}
68
+ */
69
+ export function encodeDatabaseStatus(identity: DatabaseTransactionIdentity): string;
70
+ /**
71
+ * @param {unknown} raw
72
+ * @returns {DatabaseTransactionStatus}
73
+ */
74
+ export function decodeDatabaseStatus(raw: unknown): DatabaseTransactionStatus;
75
+ /**
76
+ * Reject duplicate JSON members and unbounded syntax before typed response decoding.
77
+ * @param {Uint8Array} bytes
78
+ * @returns {unknown}
79
+ */
80
+ export function parseDatabaseJson(bytes: Uint8Array): unknown;
81
+ /**
82
+ * Build and snapshot the exact logical effect before awaiting WebCrypto.
83
+ * @param {DatabaseScope} scope
84
+ * @param {DatabaseCommit} commit
85
+ * @returns {Promise<{ readonly body: string; readonly effect_digest: string }>}
86
+ */
87
+ export function encodeDatabaseCommit(scope: DatabaseScope, commit: DatabaseCommit): Promise<{
88
+ readonly body: string;
89
+ readonly effect_digest: string;
90
+ }>;
91
+ export type Budget = {
92
+ nodes: number;
93
+ };
94
+ export type Json = null | boolean | number | string | JsonArray | JsonObject;
95
+ export type JsonArray = readonly Json[];
96
+ export type JsonObject = {
97
+ readonly [key: string]: Json;
98
+ };
99
+ export type RecordValue = Record<string, unknown>;
100
+ import type { DatabaseValue } from "./database-types.js";
101
+ import type { DatabasePoint } from "./database-types.js";
102
+ import type { DatabaseQuery } from "./database-types.js";
103
+ import type { DatabaseQueryPage } from "./database-types.js";
104
+ import type { DatabaseSubscriptionRequest } from "./database-types.js";
105
+ import type { DatabaseSubscriptionResponse } from "./database-types.js";
106
+ import type { DatabaseAuthority } from "./database-types.js";
107
+ import type { DatabaseCommitReceipt } from "./database-types.js";
108
+ import type { DatabaseTransactionIdentity } from "./database-types.js";
109
+ import type { DatabaseTransactionStatus } from "./database-types.js";
110
+ import type { DatabaseScope } from "./database-types.js";
111
+ import type { DatabaseCommit } from "./database-types.js";