@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.
- package/CHANGELOG.md +62 -0
- package/LICENSE +202 -0
- package/README.md +202 -2
- package/package.json +152 -4
- package/sdk-v1-route-manifest.json +2330 -0
- package/src/admin.js +9 -0
- package/src/better-auth.js +14 -0
- package/src/config.js +121 -0
- package/src/database-codec.js +845 -0
- package/src/database-types.js +237 -0
- package/src/database-view.js +423 -0
- package/src/database.js +2 -0
- package/src/http.js +898 -0
- package/src/index.js +62 -0
- package/src/local/authentication.js +47 -0
- package/src/local/better-auth.js +517 -0
- package/src/local/cli.js +51 -0
- package/src/local/context.js +23 -0
- package/src/local/environment.js +109 -0
- package/src/local/index.js +206 -0
- package/src/local/legacy-client.js +411 -0
- package/src/local/router.js +999 -0
- package/src/local/server.js +664 -0
- package/src/local/store.js +530 -0
- package/src/local/test-environment.js +74 -0
- package/src/management-contracts.js +72 -0
- package/src/management.js +12 -0
- package/src/native-origin.js +75 -0
- package/src/postgres.js +496 -0
- package/src/react/core.js +743 -0
- package/src/react/index.js +99 -0
- package/src/result.js +251 -0
- package/src/schema.js +366 -0
- package/src/sql.js +996 -0
- package/src/svelte/index.js +129 -0
- package/src/tanstack/index.js +512 -0
- package/src/ts-auth-discovery.js +207 -0
- package/src/ts-auth.js +3498 -0
- package/src/v1/decode.js +118 -0
- package/src/v1/errors.js +185 -0
- package/src/v1/filter.js +230 -0
- package/src/v1/ids.js +119 -0
- package/src/v1/json.js +335 -0
- package/src/v1/routes.js +57 -0
- package/src/v1/shapes.js +145 -0
- package/src/v1/terrabase-v1.js +722 -0
- package/src/v1/transport.js +324 -0
- package/types/admin.d.ts +6 -0
- package/types/better-auth.d.ts +8 -0
- package/types/config.d.ts +58 -0
- package/types/database-codec.d.ts +111 -0
- package/types/database-types.d.ts +213 -0
- package/types/database-view.d.ts +184 -0
- package/types/database.d.ts +2 -0
- package/types/http.d.ts +47 -0
- package/types/index.d.ts +43 -0
- package/types/local/authentication.d.ts +11 -0
- package/types/local/better-auth.d.ts +33 -0
- package/types/local/cli.d.ts +2 -0
- package/types/local/context.d.ts +14 -0
- package/types/local/environment.d.ts +23 -0
- package/types/local/index.d.ts +96 -0
- package/types/local/legacy-client.d.ts +94 -0
- package/types/local/router.d.ts +66 -0
- package/types/local/server.d.ts +54 -0
- package/types/local/store.d.ts +106 -0
- package/types/local/test-environment.d.ts +25 -0
- package/types/management-contracts.d.ts +44 -0
- package/types/management.d.ts +6 -0
- package/types/native-origin.d.ts +23 -0
- package/types/postgres.d.ts +124 -0
- package/types/react/core.d.ts +366 -0
- package/types/react/index.d.ts +54 -0
- package/types/result.d.ts +161 -0
- package/types/schema.d.ts +145 -0
- package/types/sql.d.ts +288 -0
- package/types/svelte/index.d.ts +81 -0
- package/types/tanstack/index.d.ts +166 -0
- package/types/ts-auth-discovery.d.ts +19 -0
- package/types/ts-auth.d.ts +1826 -0
- package/types/v1/decode.d.ts +119 -0
- package/types/v1/errors.d.ts +107 -0
- package/types/v1/filter.d.ts +148 -0
- package/types/v1/ids.d.ts +44 -0
- package/types/v1/json.d.ts +92 -0
- package/types/v1/routes.d.ts +26 -0
- package/types/v1/shapes.d.ts +78 -0
- package/types/v1/terrabase-v1.d.ts +374 -0
- package/types/v1/transport.d.ts +117 -0
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The current TerraBase document protocol uses canonical UUID entity IDs.
|
|
3
|
+
*/
|
|
4
|
+
export type CanonicalUuid = string;
|
|
5
|
+
/**
|
|
6
|
+
* All 64-bit quantities stay bigint in JavaScript and decimal strings on the wire.
|
|
7
|
+
*/
|
|
8
|
+
export type DatabaseScope = {
|
|
9
|
+
readonly tenant: CanonicalUuid;
|
|
10
|
+
readonly database: CanonicalUuid;
|
|
11
|
+
readonly shard: bigint;
|
|
12
|
+
};
|
|
13
|
+
export type CollectionBinding = {
|
|
14
|
+
readonly collection: CanonicalUuid;
|
|
15
|
+
readonly schema_generation: bigint;
|
|
16
|
+
readonly schema_digest: string;
|
|
17
|
+
};
|
|
18
|
+
export type DatabaseValue = ({
|
|
19
|
+
readonly type: "null";
|
|
20
|
+
} | {
|
|
21
|
+
readonly type: "bool";
|
|
22
|
+
readonly value: boolean;
|
|
23
|
+
} | {
|
|
24
|
+
readonly type: "i64";
|
|
25
|
+
readonly value: bigint;
|
|
26
|
+
} | {
|
|
27
|
+
readonly type: "utf8";
|
|
28
|
+
readonly value: string;
|
|
29
|
+
} | {
|
|
30
|
+
readonly type: "bytes";
|
|
31
|
+
readonly value: Uint8Array;
|
|
32
|
+
} | {
|
|
33
|
+
readonly type: "map";
|
|
34
|
+
readonly fields: readonly DatabaseField[];
|
|
35
|
+
} | {
|
|
36
|
+
readonly type: "array";
|
|
37
|
+
readonly items: readonly DatabaseValue[];
|
|
38
|
+
});
|
|
39
|
+
/**
|
|
40
|
+
* Missing fields are omitted; an explicit null remains a typed null value.
|
|
41
|
+
*/
|
|
42
|
+
export type DatabaseField = {
|
|
43
|
+
readonly id: number;
|
|
44
|
+
readonly value: DatabaseValue;
|
|
45
|
+
};
|
|
46
|
+
export type DatabaseObserved = {
|
|
47
|
+
readonly replica: CanonicalUuid;
|
|
48
|
+
readonly incarnation: string;
|
|
49
|
+
readonly sequence: bigint;
|
|
50
|
+
};
|
|
51
|
+
export type DatabaseEvent = DatabaseObserved & {
|
|
52
|
+
readonly database: CanonicalUuid;
|
|
53
|
+
readonly shard: bigint;
|
|
54
|
+
};
|
|
55
|
+
export type DatabaseAuthority = ({
|
|
56
|
+
readonly mode: "leaderless";
|
|
57
|
+
} | {
|
|
58
|
+
readonly mode: "single_writer";
|
|
59
|
+
readonly generation: bigint;
|
|
60
|
+
readonly writer: {
|
|
61
|
+
readonly replica: CanonicalUuid;
|
|
62
|
+
readonly incarnation: string;
|
|
63
|
+
};
|
|
64
|
+
});
|
|
65
|
+
export type DatabaseCondition = ({
|
|
66
|
+
readonly kind: "none";
|
|
67
|
+
} | {
|
|
68
|
+
readonly kind: "absent";
|
|
69
|
+
} | {
|
|
70
|
+
readonly kind: "version";
|
|
71
|
+
readonly version: string;
|
|
72
|
+
});
|
|
73
|
+
export type DatabaseWriteValue = ({
|
|
74
|
+
readonly kind: "live";
|
|
75
|
+
readonly fields: readonly DatabaseField[];
|
|
76
|
+
} | {
|
|
77
|
+
readonly kind: "tombstone";
|
|
78
|
+
});
|
|
79
|
+
export type DatabaseWrite = CollectionBinding & {
|
|
80
|
+
readonly document: CanonicalUuid;
|
|
81
|
+
readonly condition: DatabaseCondition;
|
|
82
|
+
readonly observed: readonly DatabaseObserved[];
|
|
83
|
+
readonly value: DatabaseWriteValue;
|
|
84
|
+
};
|
|
85
|
+
export type DatabaseTransactionId = {
|
|
86
|
+
readonly expires_at_unix_ms: bigint;
|
|
87
|
+
readonly nonce: string;
|
|
88
|
+
};
|
|
89
|
+
export type DatabaseCommit = {
|
|
90
|
+
readonly transaction_id: DatabaseTransactionId;
|
|
91
|
+
readonly authority: DatabaseAuthority;
|
|
92
|
+
readonly writes: readonly DatabaseWrite[];
|
|
93
|
+
};
|
|
94
|
+
export type DatabaseSibling = Omit<CollectionBinding, "collection"> & {
|
|
95
|
+
readonly event: DatabaseEvent;
|
|
96
|
+
} & DatabaseWriteValue;
|
|
97
|
+
/**
|
|
98
|
+
* `state_version`: only a unique live or deleted state carries an atomic condition token.
|
|
99
|
+
*/
|
|
100
|
+
export type DatabasePoint = {
|
|
101
|
+
readonly version: 1;
|
|
102
|
+
readonly state: "absent" | "deleted" | "value" | "conflict";
|
|
103
|
+
readonly state_version: string | null;
|
|
104
|
+
readonly context: readonly DatabaseObserved[];
|
|
105
|
+
readonly siblings: readonly DatabaseSibling[];
|
|
106
|
+
};
|
|
107
|
+
export type DatabaseQueryValue = Extract<DatabaseValue, {
|
|
108
|
+
readonly type: "bool" | "i64" | "utf8" | "bytes";
|
|
109
|
+
}>;
|
|
110
|
+
export type DatabaseQueryPredicate = ({
|
|
111
|
+
readonly op: "equal" | "less_than" | "less_than_or_equal" | "greater_than" | "greater_than_or_equal";
|
|
112
|
+
readonly path: readonly number[];
|
|
113
|
+
readonly value: DatabaseQueryValue;
|
|
114
|
+
} | {
|
|
115
|
+
readonly op: "is_null" | "is_missing";
|
|
116
|
+
readonly path: readonly number[];
|
|
117
|
+
});
|
|
118
|
+
export type DatabaseQuery = {
|
|
119
|
+
readonly predicate: DatabaseQueryPredicate;
|
|
120
|
+
readonly limit: number;
|
|
121
|
+
readonly cursor?: string;
|
|
122
|
+
};
|
|
123
|
+
export type DatabaseQueryRow = {
|
|
124
|
+
readonly document: CanonicalUuid;
|
|
125
|
+
readonly point: DatabasePoint;
|
|
126
|
+
};
|
|
127
|
+
export type DatabaseQueryPage = {
|
|
128
|
+
readonly version: 1;
|
|
129
|
+
readonly rows: readonly DatabaseQueryRow[];
|
|
130
|
+
readonly next_cursor?: string;
|
|
131
|
+
};
|
|
132
|
+
export type DatabaseCommitReceipt = {
|
|
133
|
+
readonly version: 1;
|
|
134
|
+
readonly durability: "local_durable" | "object_durable";
|
|
135
|
+
readonly transaction_id: DatabaseTransactionId;
|
|
136
|
+
readonly event: DatabaseEvent;
|
|
137
|
+
readonly commit_sequence: bigint;
|
|
138
|
+
readonly effect_digest: string;
|
|
139
|
+
readonly authority: DatabaseAuthority;
|
|
140
|
+
};
|
|
141
|
+
export type DatabaseTransactionIdentity = {
|
|
142
|
+
readonly transaction_id: DatabaseTransactionId;
|
|
143
|
+
readonly authority: DatabaseAuthority;
|
|
144
|
+
readonly effect_digest: string;
|
|
145
|
+
};
|
|
146
|
+
export type DatabaseTransactionStatus = DatabaseTransactionIdentity & {
|
|
147
|
+
readonly version: 1;
|
|
148
|
+
} & ({
|
|
149
|
+
readonly state: "committed";
|
|
150
|
+
readonly outcome: {
|
|
151
|
+
readonly receipt: DatabaseCommitReceipt;
|
|
152
|
+
};
|
|
153
|
+
} | {
|
|
154
|
+
readonly state: "rejected";
|
|
155
|
+
readonly outcome: {
|
|
156
|
+
readonly error: {
|
|
157
|
+
readonly code: "precondition_failed";
|
|
158
|
+
};
|
|
159
|
+
};
|
|
160
|
+
} | {
|
|
161
|
+
readonly state: "pending" | "unknown" | "expired";
|
|
162
|
+
readonly outcome: null;
|
|
163
|
+
});
|
|
164
|
+
/**
|
|
165
|
+
* An uncertain request needs status resolution; it is never an aborted transaction.
|
|
166
|
+
*/
|
|
167
|
+
export type DatabaseResult<T> = ({
|
|
168
|
+
readonly ok: true;
|
|
169
|
+
readonly status: number;
|
|
170
|
+
readonly value: T;
|
|
171
|
+
} | {
|
|
172
|
+
readonly ok: false;
|
|
173
|
+
readonly error: {
|
|
174
|
+
readonly code: string;
|
|
175
|
+
readonly status?: number;
|
|
176
|
+
readonly mutation_outcome?: "rejected" | "uncertain" | "unknown";
|
|
177
|
+
readonly transaction?: DatabaseTransactionIdentity;
|
|
178
|
+
};
|
|
179
|
+
});
|
|
180
|
+
export type DatabaseSubscriptionRequest = ({
|
|
181
|
+
readonly phase: "snapshot";
|
|
182
|
+
readonly predicate: DatabaseQueryPredicate;
|
|
183
|
+
readonly limit: number;
|
|
184
|
+
readonly snapshot_cursor?: string;
|
|
185
|
+
} | {
|
|
186
|
+
readonly phase: "poll";
|
|
187
|
+
readonly predicate: DatabaseQueryPredicate;
|
|
188
|
+
readonly poll_cursor: string;
|
|
189
|
+
});
|
|
190
|
+
export type DatabaseSubscriptionEffect = {
|
|
191
|
+
readonly document: CanonicalUuid;
|
|
192
|
+
readonly point: DatabasePoint | null;
|
|
193
|
+
};
|
|
194
|
+
export type DatabaseSubscriptionGroup = {
|
|
195
|
+
readonly sequence: bigint;
|
|
196
|
+
readonly effects: readonly DatabaseSubscriptionEffect[];
|
|
197
|
+
};
|
|
198
|
+
export type DatabaseSubscriptionResponse = ({
|
|
199
|
+
readonly version: 1;
|
|
200
|
+
readonly phase: "snapshot";
|
|
201
|
+
readonly rows: readonly DatabaseQueryRow[];
|
|
202
|
+
readonly next_snapshot_cursor: string;
|
|
203
|
+
} | {
|
|
204
|
+
readonly version: 1;
|
|
205
|
+
readonly phase: "snapshot";
|
|
206
|
+
readonly rows: readonly DatabaseQueryRow[];
|
|
207
|
+
readonly poll_cursor: string;
|
|
208
|
+
} | {
|
|
209
|
+
readonly version: 1;
|
|
210
|
+
readonly phase: "poll";
|
|
211
|
+
readonly groups: readonly DatabaseSubscriptionGroup[];
|
|
212
|
+
readonly poll_cursor: string;
|
|
213
|
+
});
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @deprecated Retired SQLite/Rust subscriptions; use the C# client.
|
|
3
|
+
* Native snapshot/poll source shared by React, Svelte and TanStack.
|
|
4
|
+
* @param {TerraBaseClient} client
|
|
5
|
+
* @param {DatabaseQueryOptions} options
|
|
6
|
+
* @returns {DatabaseQuerySource}
|
|
7
|
+
*/
|
|
8
|
+
export function createDatabaseQuery(client: TerraBaseClient, options: DatabaseQueryOptions): DatabaseQuerySource;
|
|
9
|
+
/**
|
|
10
|
+
* @import { TerraBaseClient } from "./local/legacy-client.js"
|
|
11
|
+
* @import {
|
|
12
|
+
* DatabaseField, DatabasePoint, DatabaseQueryPredicate, DatabaseQueryRow,
|
|
13
|
+
* DatabaseResult, DatabaseScope, DatabaseSubscriptionRequest,
|
|
14
|
+
* DatabaseSubscriptionResponse, DatabaseValue,
|
|
15
|
+
* } from "./database-types.js"
|
|
16
|
+
* @import { ReactiveReset, ReactiveSubscriptionContext } from "./react/core.js"
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* - `limit`: snapshot page size, between 1 and 128.
|
|
20
|
+
* - `maximumRows`: client memory bound, including all snapshot pages and later inserts.
|
|
21
|
+
* - `retryLimit`: bounded retries of read transport failures with the identical cursor.
|
|
22
|
+
* @typedef {{
|
|
23
|
+
* readonly collection: string;
|
|
24
|
+
* readonly predicate: DatabaseQueryPredicate;
|
|
25
|
+
* readonly limit?: number;
|
|
26
|
+
* readonly maximumRows?: number;
|
|
27
|
+
* readonly pollIntervalMs?: number;
|
|
28
|
+
* readonly retryLimit?: number;
|
|
29
|
+
* readonly retryDelayMs?: number;
|
|
30
|
+
* }} DatabaseQueryOptions
|
|
31
|
+
*/
|
|
32
|
+
/**
|
|
33
|
+
* @typedef {{
|
|
34
|
+
* readonly scope: DatabaseScope;
|
|
35
|
+
* readonly collection: string;
|
|
36
|
+
* readonly predicate: DatabaseQueryPredicate;
|
|
37
|
+
* readonly limit: number;
|
|
38
|
+
* }} DatabaseViewBinding
|
|
39
|
+
*/
|
|
40
|
+
/**
|
|
41
|
+
* Local generation and server position of one complete authorized cut.
|
|
42
|
+
* @typedef {{
|
|
43
|
+
* readonly generation: number;
|
|
44
|
+
* readonly poll_cursor: string;
|
|
45
|
+
* readonly sequence?: bigint;
|
|
46
|
+
* }} DatabaseViewPosition
|
|
47
|
+
*/
|
|
48
|
+
/**
|
|
49
|
+
* @typedef {{
|
|
50
|
+
* readonly rows: readonly DatabaseQueryRow[];
|
|
51
|
+
* readonly position: DatabaseViewPosition;
|
|
52
|
+
* }} DatabaseViewSnapshot
|
|
53
|
+
*/
|
|
54
|
+
/**
|
|
55
|
+
* `next`: an async consumer can acknowledge publication before the next poll.
|
|
56
|
+
* @typedef {{
|
|
57
|
+
* readonly next: (rows: readonly DatabaseQueryRow[], position: DatabaseViewPosition) => void | Promise<void>;
|
|
58
|
+
* readonly error: (error: unknown) => void;
|
|
59
|
+
* readonly reset: (reset: ReactiveReset<readonly DatabaseQueryRow[]>) => void;
|
|
60
|
+
* }} DatabaseQueryCallbacks
|
|
61
|
+
*/
|
|
62
|
+
/**
|
|
63
|
+
* @typedef {{
|
|
64
|
+
* readonly key?: string | readonly unknown[];
|
|
65
|
+
* readonly binding: DatabaseViewBinding;
|
|
66
|
+
* readonly subscribe: (
|
|
67
|
+
* observer: DatabaseQueryCallbacks,
|
|
68
|
+
* context: ReactiveSubscriptionContext,
|
|
69
|
+
* ) => () => void;
|
|
70
|
+
* }} DatabaseQuerySource
|
|
71
|
+
*/
|
|
72
|
+
export class DatabaseSubscriptionError extends Error {
|
|
73
|
+
/**
|
|
74
|
+
* @param {string} code
|
|
75
|
+
* @param {Extract<DatabaseResult<never>, { readonly ok: false }>["error"]} [detail]
|
|
76
|
+
*/
|
|
77
|
+
constructor(code: string, detail?: Extract<DatabaseResult<never>, {
|
|
78
|
+
readonly ok: false;
|
|
79
|
+
}>["error"]);
|
|
80
|
+
/**
|
|
81
|
+
* @override
|
|
82
|
+
* @readonly
|
|
83
|
+
* @type {"DatabaseSubscriptionError"}
|
|
84
|
+
*/
|
|
85
|
+
override readonly name: "DatabaseSubscriptionError";
|
|
86
|
+
/**
|
|
87
|
+
* @readonly
|
|
88
|
+
* @type {string}
|
|
89
|
+
*/
|
|
90
|
+
readonly code: string;
|
|
91
|
+
/**
|
|
92
|
+
* @readonly
|
|
93
|
+
* @type {Extract<DatabaseResult<never>, { readonly ok: false }>["error"] | undefined}
|
|
94
|
+
*/
|
|
95
|
+
readonly detail: Extract<DatabaseResult<never>, {
|
|
96
|
+
readonly ok: false;
|
|
97
|
+
}>["error"] | undefined;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Pure native result reducer. A paged snapshot stays private until its
|
|
101
|
+
* terminal poll cursor. Poll groups are staged in order and published as one
|
|
102
|
+
* complete response; invalid input cannot partially replace the prior cut.
|
|
103
|
+
*/
|
|
104
|
+
export class DatabaseSubscriptionView {
|
|
105
|
+
/**
|
|
106
|
+
* @param {DatabaseScope} scope
|
|
107
|
+
* @param {Pick<DatabaseQueryOptions, "collection" | "predicate" | "limit" | "maximumRows">} options
|
|
108
|
+
*/
|
|
109
|
+
constructor(scope: DatabaseScope, options: Pick<DatabaseQueryOptions, "collection" | "predicate" | "limit" | "maximumRows">);
|
|
110
|
+
/**
|
|
111
|
+
* @readonly
|
|
112
|
+
* @type {DatabaseViewBinding}
|
|
113
|
+
*/
|
|
114
|
+
readonly binding: DatabaseViewBinding;
|
|
115
|
+
/** @returns {DatabaseViewSnapshot | undefined} */
|
|
116
|
+
getSnapshot(): DatabaseViewSnapshot | undefined;
|
|
117
|
+
/** @returns {DatabaseSubscriptionRequest} */
|
|
118
|
+
getRequest(): DatabaseSubscriptionRequest;
|
|
119
|
+
/**
|
|
120
|
+
* Discard every opaque position; the next request starts a fresh cut.
|
|
121
|
+
* @returns {void}
|
|
122
|
+
*/
|
|
123
|
+
restart(): void;
|
|
124
|
+
/**
|
|
125
|
+
* @param {DatabaseSubscriptionResponse} response
|
|
126
|
+
* @returns {DatabaseViewSnapshot | undefined}
|
|
127
|
+
*/
|
|
128
|
+
apply(response: DatabaseSubscriptionResponse): DatabaseViewSnapshot | undefined;
|
|
129
|
+
#private;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* - `limit`: snapshot page size, between 1 and 128.
|
|
133
|
+
* - `maximumRows`: client memory bound, including all snapshot pages and later inserts.
|
|
134
|
+
* - `retryLimit`: bounded retries of read transport failures with the identical cursor.
|
|
135
|
+
*/
|
|
136
|
+
export type DatabaseQueryOptions = {
|
|
137
|
+
readonly collection: string;
|
|
138
|
+
readonly predicate: DatabaseQueryPredicate;
|
|
139
|
+
readonly limit?: number;
|
|
140
|
+
readonly maximumRows?: number;
|
|
141
|
+
readonly pollIntervalMs?: number;
|
|
142
|
+
readonly retryLimit?: number;
|
|
143
|
+
readonly retryDelayMs?: number;
|
|
144
|
+
};
|
|
145
|
+
export type DatabaseViewBinding = {
|
|
146
|
+
readonly scope: DatabaseScope;
|
|
147
|
+
readonly collection: string;
|
|
148
|
+
readonly predicate: DatabaseQueryPredicate;
|
|
149
|
+
readonly limit: number;
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* Local generation and server position of one complete authorized cut.
|
|
153
|
+
*/
|
|
154
|
+
export type DatabaseViewPosition = {
|
|
155
|
+
readonly generation: number;
|
|
156
|
+
readonly poll_cursor: string;
|
|
157
|
+
readonly sequence?: bigint;
|
|
158
|
+
};
|
|
159
|
+
export type DatabaseViewSnapshot = {
|
|
160
|
+
readonly rows: readonly DatabaseQueryRow[];
|
|
161
|
+
readonly position: DatabaseViewPosition;
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* `next`: an async consumer can acknowledge publication before the next poll.
|
|
165
|
+
*/
|
|
166
|
+
export type DatabaseQueryCallbacks = {
|
|
167
|
+
readonly next: (rows: readonly DatabaseQueryRow[], position: DatabaseViewPosition) => void | Promise<void>;
|
|
168
|
+
readonly error: (error: unknown) => void;
|
|
169
|
+
readonly reset: (reset: ReactiveReset<readonly DatabaseQueryRow[]>) => void;
|
|
170
|
+
};
|
|
171
|
+
export type DatabaseQuerySource = {
|
|
172
|
+
readonly key?: string | readonly unknown[];
|
|
173
|
+
readonly binding: DatabaseViewBinding;
|
|
174
|
+
readonly subscribe: (observer: DatabaseQueryCallbacks, context: ReactiveSubscriptionContext) => () => void;
|
|
175
|
+
};
|
|
176
|
+
import type { TerraBaseClient } from "./local/legacy-client.js";
|
|
177
|
+
import type { DatabaseResult } from "./database-types.js";
|
|
178
|
+
import type { DatabaseSubscriptionRequest } from "./database-types.js";
|
|
179
|
+
import type { DatabaseSubscriptionResponse } from "./database-types.js";
|
|
180
|
+
import type { DatabaseScope } from "./database-types.js";
|
|
181
|
+
import type { DatabaseQueryPredicate } from "./database-types.js";
|
|
182
|
+
import type { DatabaseQueryRow } from "./database-types.js";
|
|
183
|
+
import type { ReactiveReset } from "./react/core.js";
|
|
184
|
+
import type { ReactiveSubscriptionContext } from "./react/core.js";
|
package/types/http.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** Private transport for the named hosted identity and OIDC operations. */
|
|
2
|
+
export class TsAuthHttp {
|
|
3
|
+
/**
|
|
4
|
+
* @param {TsAuthRuntimeConfig} config
|
|
5
|
+
* @param {{ readonly authReverseProxy?: boolean }} [options]
|
|
6
|
+
*/
|
|
7
|
+
constructor(config: TsAuthRuntimeConfig, options?: {
|
|
8
|
+
readonly authReverseProxy?: boolean;
|
|
9
|
+
});
|
|
10
|
+
/**
|
|
11
|
+
* @readonly
|
|
12
|
+
* @type {ResolvedTsAuthRuntimeConfig}
|
|
13
|
+
*/
|
|
14
|
+
readonly config: ResolvedTsAuthRuntimeConfig;
|
|
15
|
+
/**
|
|
16
|
+
* @template TResponse
|
|
17
|
+
* @template [TBody=unknown]
|
|
18
|
+
* @param {TsAuthRequest<TBody>} options
|
|
19
|
+
* @returns {Promise<TerraScaleResult<TResponse>>}
|
|
20
|
+
*/
|
|
21
|
+
request<TResponse, TBody = unknown>(options: TsAuthRequest<TBody>): Promise<TerraScaleResult<TResponse>>;
|
|
22
|
+
#private;
|
|
23
|
+
}
|
|
24
|
+
export type ParsedBody = {
|
|
25
|
+
readonly ok: true;
|
|
26
|
+
readonly value: unknown;
|
|
27
|
+
} | {
|
|
28
|
+
readonly ok: false;
|
|
29
|
+
readonly errorMessage: string;
|
|
30
|
+
};
|
|
31
|
+
export type TsAuthRouteName = `tsauth.${string}`;
|
|
32
|
+
export type TsAuthHttpMethod = "DELETE" | "GET" | "PATCH" | "POST" | "PUT";
|
|
33
|
+
export type TsAuthRequest<TBody> = {
|
|
34
|
+
readonly method: TsAuthHttpMethod;
|
|
35
|
+
readonly path: string;
|
|
36
|
+
readonly routeName: TsAuthRouteName;
|
|
37
|
+
readonly query?: object | undefined;
|
|
38
|
+
readonly body?: TBody | undefined;
|
|
39
|
+
readonly formBody?: URLSearchParams | string | undefined;
|
|
40
|
+
readonly userinfoAccessToken?: string | undefined;
|
|
41
|
+
readonly resourceIntrospectionBasic?: string | undefined;
|
|
42
|
+
readonly issuer?: string | undefined;
|
|
43
|
+
readonly signal?: AbortSignal | undefined;
|
|
44
|
+
};
|
|
45
|
+
import type { ResolvedTsAuthRuntimeConfig } from "./config.js";
|
|
46
|
+
import type { TerraScaleResult } from "./result.js";
|
|
47
|
+
import type { TsAuthRuntimeConfig } from "./config.js";
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export { v1Filter } from "./v1/filter.js";
|
|
2
|
+
export { documentIdFor } from "./v1/ids.js";
|
|
3
|
+
export { ExactDecimal } from "./v1/json.js";
|
|
4
|
+
export { staticBaseUrlResolver } from "./v1/transport.js";
|
|
5
|
+
export type TerraBaseV1ClientConfig = import("./v1/transport.js").TerraBaseV1ClientConfig;
|
|
6
|
+
export type V1RequestOptions = import("./v1/terrabase-v1.js").V1RequestOptions;
|
|
7
|
+
export type V1ReadOptions = import("./v1/terrabase-v1.js").V1ReadOptions;
|
|
8
|
+
export type V1WriteOptions = import("./v1/terrabase-v1.js").V1WriteOptions;
|
|
9
|
+
export type V1CreateOptions = import("./v1/terrabase-v1.js").V1CreateOptions;
|
|
10
|
+
export type V1ConditionalWriteOptions = import("./v1/terrabase-v1.js").V1ConditionalWriteOptions;
|
|
11
|
+
export type V1PatchOp = import("./v1/terrabase-v1.js").V1PatchOp;
|
|
12
|
+
export type V1Patch = import("./v1/terrabase-v1.js").V1Patch;
|
|
13
|
+
export type V1SortKey = import("./v1/terrabase-v1.js").V1SortKey;
|
|
14
|
+
export type V1Query = import("./v1/terrabase-v1.js").V1Query;
|
|
15
|
+
export type V1Count = import("./v1/terrabase-v1.js").V1Count;
|
|
16
|
+
export type V1QueryPage = import("./v1/terrabase-v1.js").V1QueryPage;
|
|
17
|
+
export type V1Precondition = import("./v1/terrabase-v1.js").V1Precondition;
|
|
18
|
+
export type V1TransactionOpResult = import("./v1/terrabase-v1.js").V1TransactionOpResult;
|
|
19
|
+
export type V1CountBounds = import("./v1/terrabase-v1.js").V1CountBounds;
|
|
20
|
+
export type V1TransactionResult = import("./v1/terrabase-v1.js").V1TransactionResult;
|
|
21
|
+
export type V1Document = import("./v1/decode.js").V1Document;
|
|
22
|
+
export type V1WriteResult = import("./v1/decode.js").V1WriteResult;
|
|
23
|
+
export type V1Durability = import("./v1/decode.js").V1Durability;
|
|
24
|
+
export type V1Filter = import("./v1/filter.js").V1Filter;
|
|
25
|
+
export type V1Path = import("./v1/filter.js").V1Path;
|
|
26
|
+
export type V1Scalar = import("./v1/filter.js").V1Scalar;
|
|
27
|
+
export type V1JsonValue = import("./v1/json.js").JsonValue;
|
|
28
|
+
export type V1JsonObject = import("./v1/json.js").JsonObject;
|
|
29
|
+
export type V1JsonInput = import("./v1/json.js").JsonInput;
|
|
30
|
+
export type V1JsonInputObject = import("./v1/json.js").JsonInputObject;
|
|
31
|
+
export type V1ShapeRequest = import("./v1/shapes.js").V1ShapeRequest;
|
|
32
|
+
export type V1ShapeChange = import("./v1/shapes.js").V1ShapeChange;
|
|
33
|
+
export type V1ShapeOp = import("./v1/shapes.js").V1ShapeOp;
|
|
34
|
+
export type TerraBaseClientConfig = import("./v1/transport.js").TerraBaseV1ClientConfig;
|
|
35
|
+
export type V1EndpointContext = import("./v1/transport.js").V1EndpointContext;
|
|
36
|
+
export type V1EndpointResolver = import("./v1/transport.js").V1EndpointResolver;
|
|
37
|
+
export type V1CollectionInfo = import("./v1/terrabase-v1.js").V1CollectionInfo;
|
|
38
|
+
export type V1CollectionPage = import("./v1/terrabase-v1.js").V1CollectionPage;
|
|
39
|
+
export type V1CollectionListOptions = import("./v1/terrabase-v1.js").V1CollectionListOptions;
|
|
40
|
+
export type V1ShapePage = import("./v1/shapes.js").V1ShapePage;
|
|
41
|
+
export { createTerraBaseV1Client as createTerraBaseClient, TerraBaseV1Client as TerraBaseClient, createTerraBaseV1Client, TerraBaseV1Client, V1Database, V1Collection, V1Collections, V1Transaction } from "./v1/terrabase-v1.js";
|
|
42
|
+
export { terraScaleReleaseBlockers, TerraScaleCapabilityUnavailableError } from "./management-contracts.js";
|
|
43
|
+
export { TerraBaseV1Error, V1PreconditionFailedError, V1InvalidKeyError, V1ForbiddenScopeError, V1NotFoundError, V1ErrorCode, isTerraBaseV1Error } from "./v1/errors.js";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {unknown} value
|
|
3
|
+
* @returns {string}
|
|
4
|
+
*/
|
|
5
|
+
export function normalizeLocalBearerToken(value: unknown): string;
|
|
6
|
+
/**
|
|
7
|
+
* @param {string | null} authorization
|
|
8
|
+
* @param {string} expectedToken
|
|
9
|
+
* @returns {boolean}
|
|
10
|
+
*/
|
|
11
|
+
export function matchesLocalBearerAuthorization(authorization: string | null, expectedToken: string): boolean;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** @import { CleanedWhere, CustomAdapter, DBAdapter, JoinConfig } from "@better-auth/core/db/adapter" */
|
|
2
|
+
/** @import { BetterAuthOptions } from "@better-auth/core" */
|
|
3
|
+
/** @import { TerraScaleSqliteStore } from "./store.js" */
|
|
4
|
+
/** @typedef {Record<string, unknown>} Row */
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {Parameters<
|
|
7
|
+
* NonNullable<Parameters<typeof createAdapterFactory>[0]["adapter"]>
|
|
8
|
+
* >[0]} FactoryConfig
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* @typedef {(
|
|
12
|
+
* options: BetterAuthOptions,
|
|
13
|
+
* ) => DBAdapter<BetterAuthOptions>} LocalBetterAuthAdapterFactory
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Better Auth 1.7.2 over explicitly enabled development SQLite only.
|
|
17
|
+
*
|
|
18
|
+
* @param {TerraScaleSqliteStore} store
|
|
19
|
+
* @returns {LocalBetterAuthAdapterFactory}
|
|
20
|
+
*/
|
|
21
|
+
export function createLocalBetterAuthAdapter(store: TerraScaleSqliteStore): LocalBetterAuthAdapterFactory;
|
|
22
|
+
export class LocalAuthConstraintError extends Error {
|
|
23
|
+
constructor();
|
|
24
|
+
/** @readonly */
|
|
25
|
+
readonly code: "unique_conflict";
|
|
26
|
+
}
|
|
27
|
+
export type Row = Record<string, unknown>;
|
|
28
|
+
export type FactoryConfig = Parameters<NonNullable<Parameters<typeof createAdapterFactory>[0]["adapter"]>>[0];
|
|
29
|
+
export type LocalBetterAuthAdapterFactory = (options: BetterAuthOptions) => DBAdapter<BetterAuthOptions>;
|
|
30
|
+
import type { TerraScaleSqliteStore } from "./store.js";
|
|
31
|
+
import { createAdapterFactory } from "@better-auth/core/db/adapter";
|
|
32
|
+
import type { BetterAuthOptions } from "@better-auth/core";
|
|
33
|
+
import type { DBAdapter } from "@better-auth/core/db/adapter";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** @typedef {"permissive" | "required"} LocalAuthenticationMode */
|
|
2
|
+
/**
|
|
3
|
+
* @param {unknown} value
|
|
4
|
+
* @param {number} [status]
|
|
5
|
+
* @returns {Response}
|
|
6
|
+
*/
|
|
7
|
+
export function jsonResponse(value: unknown, status?: number): Response;
|
|
8
|
+
/**
|
|
9
|
+
* @param {number} status
|
|
10
|
+
* @param {string} code
|
|
11
|
+
* @returns {Response}
|
|
12
|
+
*/
|
|
13
|
+
export function problemResponse(status: number, code: string): Response;
|
|
14
|
+
export type LocalAuthenticationMode = "permissive" | "required";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {Readonly<Record<string, string | undefined>>} [environment]
|
|
3
|
+
* @returns {void}
|
|
4
|
+
*/
|
|
5
|
+
export function assertLocalSqliteEnvironment(environment?: Readonly<Record<string, string | undefined>>): void;
|
|
6
|
+
export const localSqlitePresenceIndicators: readonly ["CI", "CONTINUOUS_INTEGRATION", "GITHUB_ACTIONS", "GITLAB_CI", "FORGEJO_ACTIONS", "GITEA_ACTIONS", "TF_BUILD", "BUILDKITE", "CIRCLECI", "JENKINS_URL", "TEAMCITY_VERSION", "VERCEL", "NETLIFY", "CF_PAGES", "RENDER", "FLY_APP_NAME", "K_SERVICE", "CLOUD_RUN_JOB", "KUBERNETES_SERVICE_HOST", "AWS_LAMBDA_FUNCTION_NAME", "AWS_EXECUTION_ENV", "ECS_CONTAINER_METADATA_URI", "ECS_CONTAINER_METADATA_URI_V4", "WEBSITE_INSTANCE_ID", "WEBSITE_SITE_NAME", "FUNCTIONS_WORKER_RUNTIME", "DYNO", "HEROKU_APP_NAME", "RAILWAY_ENVIRONMENT", "RAILWAY_SERVICE_ID", "NOMAD_ALLOC_ID", "TERRASCALE_DEPLOYMENT", "TERRASCALE_QUALIFICATION"];
|
|
7
|
+
/**
|
|
8
|
+
* Explicit opt-in for a hosted development environment.
|
|
9
|
+
*
|
|
10
|
+
* Hosting platforms set a presence indicator on every workload, including
|
|
11
|
+
* development environments, so the SDK cannot tell a hosted dev environment
|
|
12
|
+
* from production by presence alone. Setting this variable to a true value
|
|
13
|
+
* relaxes *platform* indicators only: CI, qualification, and every stage
|
|
14
|
+
* indicator (`NODE_ENV=production`, `STAGE=staging`, …) still refuse.
|
|
15
|
+
*/
|
|
16
|
+
export const localSqliteHostedOptIn: "TERRASCALE_LOCAL_SQLITE_ALLOW_HOSTED";
|
|
17
|
+
/**
|
|
18
|
+
* Presence indicators the opt-in never relaxes.
|
|
19
|
+
*
|
|
20
|
+
* @type {ReadonlySet<string>}
|
|
21
|
+
*/
|
|
22
|
+
export const localSqliteUnrelaxableIndicators: ReadonlySet<string>;
|
|
23
|
+
export const localSqliteStageIndicators: readonly ["NODE_ENV", "APP_ENV", "ENVIRONMENT", "STAGE", "DEPLOY_ENV", "DEPLOYMENT_ENVIRONMENT", "TERRASCALE_ENV", "TERRASCALE_ENVIRONMENT", "VERCEL_ENV"];
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @deprecated Retired Rust emulator; use a local TerraBase release.
|
|
3
|
+
* @param {TerraScaleSqliteRuntimeOptions} options
|
|
4
|
+
* @returns {TerraScaleSqliteRuntime}
|
|
5
|
+
*/
|
|
6
|
+
export function createTerraScaleSqliteRuntime(options: TerraScaleSqliteRuntimeOptions): TerraScaleSqliteRuntime;
|
|
7
|
+
/** @import { TerraBaseClient, TerraBaseClientConfig } from "./legacy-client.js" */
|
|
8
|
+
/** @import { CollectionBinding, DatabaseScope } from "../database-types.js" */
|
|
9
|
+
/** @typedef {import("./context.js").LocalAuthenticationMode} LocalAuthenticationMode */
|
|
10
|
+
/** @typedef {import("./server.js").LocalServerAddress} LocalServerAddress */
|
|
11
|
+
/** @typedef {import("./better-auth.js").LocalBetterAuthAdapterFactory} LocalBetterAuthAdapterFactory */
|
|
12
|
+
/**
|
|
13
|
+
* @typedef {{
|
|
14
|
+
* readonly sqlite: { readonly enabled: true; readonly databasePath: string };
|
|
15
|
+
* readonly scope?: DatabaseScope;
|
|
16
|
+
* readonly authentication?: LocalAuthenticationMode;
|
|
17
|
+
* readonly bearerToken?: string;
|
|
18
|
+
* readonly allowRemote?: boolean;
|
|
19
|
+
* }} TerraScaleSqliteRuntimeOptions
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* @typedef {{
|
|
23
|
+
* readonly host?: string;
|
|
24
|
+
* readonly port?: number;
|
|
25
|
+
* }} TerraScaleLocalListenOptions
|
|
26
|
+
*/
|
|
27
|
+
/** @deprecated Retired Rust SQLite emulator; use a local TerraBase release binary.
|
|
28
|
+
* Explicit Node development backend. Never load this entrypoint in deployment or qualification. */
|
|
29
|
+
export class TerraScaleSqliteRuntime {
|
|
30
|
+
/**
|
|
31
|
+
* @param {TerraScaleSqliteRuntimeOptions} options
|
|
32
|
+
*/
|
|
33
|
+
constructor(options: TerraScaleSqliteRuntimeOptions);
|
|
34
|
+
/**
|
|
35
|
+
* @readonly
|
|
36
|
+
* @type {DatabaseScope}
|
|
37
|
+
*/
|
|
38
|
+
readonly scope: DatabaseScope;
|
|
39
|
+
/** @returns {string} */
|
|
40
|
+
get databasePath(): string;
|
|
41
|
+
/** @returns {LocalServerAddress | undefined} */
|
|
42
|
+
get address(): LocalServerAddress | undefined;
|
|
43
|
+
get authority(): Readonly<{
|
|
44
|
+
mode: "single_writer";
|
|
45
|
+
generation: 1n;
|
|
46
|
+
writer: {
|
|
47
|
+
readonly replica: string;
|
|
48
|
+
readonly incarnation: string;
|
|
49
|
+
};
|
|
50
|
+
}>;
|
|
51
|
+
/**
|
|
52
|
+
* @param {CollectionBinding} binding
|
|
53
|
+
* @returns {Promise<void>}
|
|
54
|
+
*/
|
|
55
|
+
bindCollection(binding: CollectionBinding): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* @param {Pick<TerraBaseClientConfig, "requestTimeoutMs">} [options]
|
|
58
|
+
* @returns {TerraBaseClient}
|
|
59
|
+
*/
|
|
60
|
+
createClient(options?: Pick<TerraBaseClientConfig, "requestTimeoutMs">): TerraBaseClient;
|
|
61
|
+
/** @returns {Promise<LocalBetterAuthAdapterFactory>} */
|
|
62
|
+
createBetterAuthAdapter(): Promise<LocalBetterAuthAdapterFactory>;
|
|
63
|
+
/**
|
|
64
|
+
* @param {TerraScaleLocalListenOptions} [options]
|
|
65
|
+
* @returns {Promise<LocalServerAddress>}
|
|
66
|
+
*/
|
|
67
|
+
start(options?: TerraScaleLocalListenOptions): Promise<LocalServerAddress>;
|
|
68
|
+
/** @returns {Promise<void>} */
|
|
69
|
+
stop(): Promise<void>;
|
|
70
|
+
/** @returns {Promise<void>} */
|
|
71
|
+
reset(): Promise<void>;
|
|
72
|
+
/** @returns {Promise<void>} */
|
|
73
|
+
close(): Promise<void>;
|
|
74
|
+
#private;
|
|
75
|
+
}
|
|
76
|
+
export type LocalAuthenticationMode = import("./context.js").LocalAuthenticationMode;
|
|
77
|
+
export type LocalServerAddress = import("./server.js").LocalServerAddress;
|
|
78
|
+
export type LocalBetterAuthAdapterFactory = import("./better-auth.js").LocalBetterAuthAdapterFactory;
|
|
79
|
+
export type TerraScaleSqliteRuntimeOptions = {
|
|
80
|
+
readonly sqlite: {
|
|
81
|
+
readonly enabled: true;
|
|
82
|
+
readonly databasePath: string;
|
|
83
|
+
};
|
|
84
|
+
readonly scope?: DatabaseScope;
|
|
85
|
+
readonly authentication?: LocalAuthenticationMode;
|
|
86
|
+
readonly bearerToken?: string;
|
|
87
|
+
readonly allowRemote?: boolean;
|
|
88
|
+
};
|
|
89
|
+
export type TerraScaleLocalListenOptions = {
|
|
90
|
+
readonly host?: string;
|
|
91
|
+
readonly port?: number;
|
|
92
|
+
};
|
|
93
|
+
import type { DatabaseScope } from "../database-types.js";
|
|
94
|
+
import type { CollectionBinding } from "../database-types.js";
|
|
95
|
+
import type { TerraBaseClientConfig } from "./legacy-client.js";
|
|
96
|
+
import type { TerraBaseClient } from "./legacy-client.js";
|