@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,374 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a TerraBase v1 client for documents, transactions, queries and shapes.
|
|
3
|
+
* @param {TerraBaseV1ClientConfig} config
|
|
4
|
+
* @returns {TerraBaseV1Client}
|
|
5
|
+
*/
|
|
6
|
+
export function createTerraBaseV1Client(config: TerraBaseV1ClientConfig): TerraBaseV1Client;
|
|
7
|
+
/** A collection handle by name. It performs no I/O until an operation runs. */
|
|
8
|
+
export class V1Collection {
|
|
9
|
+
/**
|
|
10
|
+
* @param {V1Transport} transport
|
|
11
|
+
* @param {string} database
|
|
12
|
+
* @param {string} name
|
|
13
|
+
*/
|
|
14
|
+
constructor(transport: V1Transport, database: string, name: string);
|
|
15
|
+
/** @type {string} */
|
|
16
|
+
name: string;
|
|
17
|
+
/** @type {string} */
|
|
18
|
+
database: string;
|
|
19
|
+
/**
|
|
20
|
+
* Reads a document. Absent and deleted documents fail with
|
|
21
|
+
* `not_found`; a deleted document's error carries its tombstone `etag`.
|
|
22
|
+
* @param {string} id
|
|
23
|
+
* @param {V1ReadOptions} [options]
|
|
24
|
+
* @returns {Promise<V1Document>}
|
|
25
|
+
*/
|
|
26
|
+
get(id: string, options?: V1ReadOptions): Promise<V1Document>;
|
|
27
|
+
/**
|
|
28
|
+
* Writes the complete document. `created` reports a 201.
|
|
29
|
+
* @param {string} id
|
|
30
|
+
* @param {JsonInputObject} document
|
|
31
|
+
* @param {V1WriteOptions} [options]
|
|
32
|
+
* @returns {Promise<V1WriteResult>}
|
|
33
|
+
*/
|
|
34
|
+
put(id: string, document: JsonInputObject, options?: V1WriteOptions): Promise<V1WriteResult>;
|
|
35
|
+
/**
|
|
36
|
+
* Creates a document under a server-generated UUIDv7.
|
|
37
|
+
* @param {JsonInputObject} document
|
|
38
|
+
* @param {V1CreateOptions} [options]
|
|
39
|
+
* @returns {Promise<V1WriteResult>}
|
|
40
|
+
*/
|
|
41
|
+
create(document: JsonInputObject, options?: V1CreateOptions): Promise<V1WriteResult>;
|
|
42
|
+
/**
|
|
43
|
+
* Applies a merge patch or ops patch to an existing document.
|
|
44
|
+
* @param {string} id
|
|
45
|
+
* @param {V1Patch} patch
|
|
46
|
+
* @param {V1ConditionalWriteOptions} [options]
|
|
47
|
+
* @returns {Promise<V1WriteResult>}
|
|
48
|
+
*/
|
|
49
|
+
patch(id: string, patch: V1Patch, options?: V1ConditionalWriteOptions): Promise<V1WriteResult>;
|
|
50
|
+
/**
|
|
51
|
+
* Tombstones a document; `version` is the tombstone's.
|
|
52
|
+
* @param {string} id
|
|
53
|
+
* @param {V1ConditionalWriteOptions} [options]
|
|
54
|
+
* @returns {Promise<V1WriteResult>}
|
|
55
|
+
*/
|
|
56
|
+
delete(id: string, options?: V1ConditionalWriteOptions): Promise<V1WriteResult>;
|
|
57
|
+
/**
|
|
58
|
+
* Runs one page of a query.
|
|
59
|
+
* @param {V1Query} [query]
|
|
60
|
+
* @param {V1RequestOptions} [options]
|
|
61
|
+
* @returns {Promise<V1QueryPage>}
|
|
62
|
+
*/
|
|
63
|
+
query(query?: V1Query, options?: V1RequestOptions): Promise<V1QueryPage>;
|
|
64
|
+
/**
|
|
65
|
+
* Iterates over every page, following `nextCursor`. `count`
|
|
66
|
+
* is sent with the first page only.
|
|
67
|
+
* @param {V1Query} [query]
|
|
68
|
+
* @param {V1RequestOptions} [options]
|
|
69
|
+
* @returns {AsyncGenerator<V1QueryPage, void, undefined>}
|
|
70
|
+
*/
|
|
71
|
+
pages(query?: V1Query, options?: V1RequestOptions): AsyncGenerator<V1QueryPage, void, undefined>;
|
|
72
|
+
/**
|
|
73
|
+
* Iterates over every matching document across pages.
|
|
74
|
+
* @param {V1Query} [query]
|
|
75
|
+
* @param {V1RequestOptions} [options]
|
|
76
|
+
* @returns {AsyncGenerator<V1Document, void, undefined>}
|
|
77
|
+
*/
|
|
78
|
+
items(query?: V1Query, options?: V1RequestOptions): AsyncGenerator<V1Document, void, undefined>;
|
|
79
|
+
/**
|
|
80
|
+
* Reads one C# shape snapshot page or change-log chunk. Bootstrap defaults to offset -1.
|
|
81
|
+
* Echo handle, nextOffset and cursor on the following read; discard state on must_refetch.
|
|
82
|
+
* @param {V1ShapeRequest} [request]
|
|
83
|
+
* @param {V1RequestOptions} [options]
|
|
84
|
+
* @returns {Promise<V1ShapePage>}
|
|
85
|
+
*/
|
|
86
|
+
shape(request?: V1ShapeRequest, options?: V1RequestOptions): Promise<V1ShapePage>;
|
|
87
|
+
#private;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* An atomic transaction of up to 1024 ops across the collections of one
|
|
91
|
+
* database. No two ops may target the same document. Documents are encoded
|
|
92
|
+
* when an op is added, so later mutation of the input does not change it.
|
|
93
|
+
*/
|
|
94
|
+
export class V1Transaction {
|
|
95
|
+
/**
|
|
96
|
+
* @param {V1Precondition | undefined} precondition
|
|
97
|
+
* @param {boolean} allowNoneMatch
|
|
98
|
+
* @returns {Record<string, string>}
|
|
99
|
+
*/
|
|
100
|
+
static "__#private@#precondition"(precondition: V1Precondition | undefined, allowNoneMatch: boolean): Record<string, string>;
|
|
101
|
+
/**
|
|
102
|
+
* @param {V1Transport} transport
|
|
103
|
+
* @param {string} database
|
|
104
|
+
*/
|
|
105
|
+
constructor(transport: V1Transport, database: string);
|
|
106
|
+
/** @returns {number} The number of ops added. */
|
|
107
|
+
get size(): number;
|
|
108
|
+
/**
|
|
109
|
+
* Adds a create (a put requiring absence). Omit `id` to have the server
|
|
110
|
+
* generate a UUIDv7, returned in the op's result.
|
|
111
|
+
* @param {string} collection
|
|
112
|
+
* @param {JsonInputObject} document
|
|
113
|
+
* @param {string} [id]
|
|
114
|
+
* @returns {this}
|
|
115
|
+
*/
|
|
116
|
+
create(collection: string, document: JsonInputObject, id?: string): this;
|
|
117
|
+
/**
|
|
118
|
+
* @param {string} collection
|
|
119
|
+
* @param {string} id
|
|
120
|
+
* @param {JsonInputObject} document
|
|
121
|
+
* @param {V1Precondition} [precondition]
|
|
122
|
+
* @returns {this}
|
|
123
|
+
*/
|
|
124
|
+
put(collection: string, id: string, document: JsonInputObject, precondition?: V1Precondition): this;
|
|
125
|
+
/**
|
|
126
|
+
* @param {string} collection
|
|
127
|
+
* @param {string} id
|
|
128
|
+
* @param {V1Patch} patch
|
|
129
|
+
* @param {{ readonly ifMatch: string }} [precondition]
|
|
130
|
+
* @returns {this}
|
|
131
|
+
*/
|
|
132
|
+
patch(collection: string, id: string, patch: V1Patch, precondition?: {
|
|
133
|
+
readonly ifMatch: string;
|
|
134
|
+
}): this;
|
|
135
|
+
/**
|
|
136
|
+
* @param {string} collection
|
|
137
|
+
* @param {string} id
|
|
138
|
+
* @param {{ readonly ifMatch: string }} [precondition]
|
|
139
|
+
* @returns {this}
|
|
140
|
+
*/
|
|
141
|
+
delete(collection: string, id: string, precondition?: {
|
|
142
|
+
readonly ifMatch: string;
|
|
143
|
+
}): this;
|
|
144
|
+
/**
|
|
145
|
+
* Requires the document to exist and match the filter.
|
|
146
|
+
* @param {string} collection
|
|
147
|
+
* @param {string} id
|
|
148
|
+
* @param {V1Filter} filter
|
|
149
|
+
* @returns {this}
|
|
150
|
+
*/
|
|
151
|
+
assert(collection: string, id: string, filter: V1Filter): this;
|
|
152
|
+
/**
|
|
153
|
+
* Requires the document to be absent or deleted.
|
|
154
|
+
* @param {string} collection
|
|
155
|
+
* @param {string} id
|
|
156
|
+
* @returns {this}
|
|
157
|
+
*/
|
|
158
|
+
assertAbsent(collection: string, id: string): this;
|
|
159
|
+
/**
|
|
160
|
+
* Requires the number of the collection's documents matching `filter` to
|
|
161
|
+
* satisfy `gte` and/or `lte`. Omit the filter with null to count all documents. It is evaluated inside the commit, before
|
|
162
|
+
* this transaction's writes, so it is serializable with every other write.
|
|
163
|
+
* At most 16 per transaction; the result carries the `count`.
|
|
164
|
+
* @param {string} collection
|
|
165
|
+
* @param {V1Filter | null} filter
|
|
166
|
+
* @param {V1CountBounds} bounds
|
|
167
|
+
* @returns {this}
|
|
168
|
+
*/
|
|
169
|
+
assertCount(collection: string, filter: V1Filter | null, bounds: V1CountBounds): this;
|
|
170
|
+
/**
|
|
171
|
+
* Applies every op atomically. Failures are TerraBaseV1Error values whose
|
|
172
|
+
* `op` names the failing op index.
|
|
173
|
+
* @param {V1RequestOptions} [options]
|
|
174
|
+
* @returns {Promise<V1TransactionResult>}
|
|
175
|
+
*/
|
|
176
|
+
commit(options?: V1RequestOptions): Promise<V1TransactionResult>;
|
|
177
|
+
#private;
|
|
178
|
+
}
|
|
179
|
+
/** Collection management on the public client listener. */
|
|
180
|
+
export class V1Collections {
|
|
181
|
+
/** @param {V1Transport} transport @param {string} database */
|
|
182
|
+
constructor(transport: V1Transport, database: string);
|
|
183
|
+
/** @param {string} name @param {V1RequestOptions} [options] @returns {Promise<V1CollectionInfo>} */
|
|
184
|
+
create(name: string, options?: V1RequestOptions): Promise<V1CollectionInfo>;
|
|
185
|
+
/** @param {string} name @param {V1RequestOptions} [options] @returns {Promise<V1CollectionInfo>} */
|
|
186
|
+
get(name: string, options?: V1RequestOptions): Promise<V1CollectionInfo>;
|
|
187
|
+
/** @param {V1CollectionListOptions} [request] @param {V1RequestOptions} [options] @returns {Promise<V1CollectionPage>} */
|
|
188
|
+
list(request?: V1CollectionListOptions, options?: V1RequestOptions): Promise<V1CollectionPage>;
|
|
189
|
+
/** @param {string} name @param {V1RequestOptions} [options] @returns {Promise<V1CollectionInfo>} */
|
|
190
|
+
drop(name: string, options?: V1RequestOptions): Promise<V1CollectionInfo>;
|
|
191
|
+
#private;
|
|
192
|
+
}
|
|
193
|
+
/** A database handle by name. It performs no I/O until an operation runs. */
|
|
194
|
+
export class V1Database {
|
|
195
|
+
/**
|
|
196
|
+
* @param {V1Transport} transport
|
|
197
|
+
* @param {string} name
|
|
198
|
+
*/
|
|
199
|
+
constructor(transport: V1Transport, name: string);
|
|
200
|
+
/** @type {V1Collections} */
|
|
201
|
+
collections: V1Collections;
|
|
202
|
+
/** @type {string} */
|
|
203
|
+
name: string;
|
|
204
|
+
/**
|
|
205
|
+
* @param {string} name
|
|
206
|
+
* @returns {V1Collection}
|
|
207
|
+
*/
|
|
208
|
+
collection(name: string): V1Collection;
|
|
209
|
+
/** @returns {V1Transaction} */
|
|
210
|
+
transaction(): V1Transaction;
|
|
211
|
+
#private;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* A TerraBase v1 data-plane client for one project and `tb_` API key. The key is held
|
|
215
|
+
* privately; it is never serialized, logged or forwarded to redirects.
|
|
216
|
+
*/
|
|
217
|
+
export class TerraBaseV1Client {
|
|
218
|
+
/** @param {TerraBaseV1ClientConfig} config */
|
|
219
|
+
constructor(config: TerraBaseV1ClientConfig);
|
|
220
|
+
/**
|
|
221
|
+
* @param {string} name
|
|
222
|
+
* @returns {V1Database}
|
|
223
|
+
*/
|
|
224
|
+
database(name: string): V1Database;
|
|
225
|
+
#private;
|
|
226
|
+
}
|
|
227
|
+
export type V1CollectionInfo = {
|
|
228
|
+
readonly name: string;
|
|
229
|
+
readonly createdAt: string;
|
|
230
|
+
};
|
|
231
|
+
export type V1CollectionPage = {
|
|
232
|
+
readonly items: readonly V1CollectionInfo[];
|
|
233
|
+
readonly nextCursor: string | null;
|
|
234
|
+
};
|
|
235
|
+
export type V1CollectionListOptions = {
|
|
236
|
+
readonly limit?: number | undefined;
|
|
237
|
+
readonly cursor?: string | undefined;
|
|
238
|
+
};
|
|
239
|
+
export type V1RequestOptions = {
|
|
240
|
+
readonly signal?: AbortSignal | undefined;
|
|
241
|
+
};
|
|
242
|
+
export type V1ReadOptions = {
|
|
243
|
+
/**
|
|
244
|
+
* A version; an unchanged document fails with `not_modified` (304).
|
|
245
|
+
*/
|
|
246
|
+
ifNoneMatch?: string | undefined;
|
|
247
|
+
signal?: AbortSignal | undefined;
|
|
248
|
+
};
|
|
249
|
+
export type V1WriteOptions = {
|
|
250
|
+
/**
|
|
251
|
+
* Require the current version, or "*" for a live document.
|
|
252
|
+
*/
|
|
253
|
+
ifMatch?: string | undefined;
|
|
254
|
+
/**
|
|
255
|
+
* Require the document to be absent or deleted (`If-None-Match: *`).
|
|
256
|
+
*/
|
|
257
|
+
ifNoneMatchAny?: boolean | undefined;
|
|
258
|
+
signal?: AbortSignal | undefined;
|
|
259
|
+
};
|
|
260
|
+
export type V1CreateOptions = V1WriteOptions;
|
|
261
|
+
export type V1ConditionalWriteOptions = {
|
|
262
|
+
readonly ifMatch?: string | undefined;
|
|
263
|
+
readonly signal?: AbortSignal | undefined;
|
|
264
|
+
};
|
|
265
|
+
/**
|
|
266
|
+
* One operation of an `application/vnd.terrabase.ops+json` patch. Paths are
|
|
267
|
+
* RFC 6901 JSON Pointers without array indices.
|
|
268
|
+
*/
|
|
269
|
+
export type V1PatchOp = {
|
|
270
|
+
readonly op: "set";
|
|
271
|
+
readonly path: string;
|
|
272
|
+
readonly value: JsonInput;
|
|
273
|
+
} | {
|
|
274
|
+
readonly op: "unset";
|
|
275
|
+
readonly path: string;
|
|
276
|
+
} | {
|
|
277
|
+
readonly op: "inc";
|
|
278
|
+
readonly path: string;
|
|
279
|
+
readonly by: number | bigint | ExactDecimal;
|
|
280
|
+
} | {
|
|
281
|
+
readonly op: "append";
|
|
282
|
+
readonly path: string;
|
|
283
|
+
readonly value: JsonInput;
|
|
284
|
+
};
|
|
285
|
+
/**
|
|
286
|
+
* A patch: an RFC 7396 merge patch (`null` removes members) or 1-256 ops.
|
|
287
|
+
*/
|
|
288
|
+
export type V1Patch = {
|
|
289
|
+
readonly merge: JsonInputObject;
|
|
290
|
+
} | {
|
|
291
|
+
readonly ops: readonly V1PatchOp[];
|
|
292
|
+
};
|
|
293
|
+
export type V1SortKey = {
|
|
294
|
+
readonly path: V1Path;
|
|
295
|
+
readonly order?: "asc" | "desc" | undefined;
|
|
296
|
+
};
|
|
297
|
+
/**
|
|
298
|
+
* A query-v1 request. Every member is optional.
|
|
299
|
+
*/
|
|
300
|
+
export type V1Query = {
|
|
301
|
+
filter?: V1Filter | null | undefined;
|
|
302
|
+
/**
|
|
303
|
+
* At most 4 keys; results are finally ordered by `$id`.
|
|
304
|
+
*/
|
|
305
|
+
sort?: readonly V1SortKey[] | undefined;
|
|
306
|
+
/**
|
|
307
|
+
* At most 64 paths.
|
|
308
|
+
*/
|
|
309
|
+
project?: readonly string[] | undefined;
|
|
310
|
+
/**
|
|
311
|
+
* 1-1000 (server default 50).
|
|
312
|
+
*/
|
|
313
|
+
limit?: number | undefined;
|
|
314
|
+
/**
|
|
315
|
+
* A previous page's `nextCursor`.
|
|
316
|
+
*/
|
|
317
|
+
cursor?: string | null | undefined;
|
|
318
|
+
/**
|
|
319
|
+
* Count every match (first page only).
|
|
320
|
+
*/
|
|
321
|
+
count?: boolean | undefined;
|
|
322
|
+
};
|
|
323
|
+
export type V1Count = {
|
|
324
|
+
readonly value: string;
|
|
325
|
+
readonly exact: boolean;
|
|
326
|
+
};
|
|
327
|
+
export type V1QueryPage = {
|
|
328
|
+
/**
|
|
329
|
+
* Documents in query order.
|
|
330
|
+
*/
|
|
331
|
+
items: readonly V1Document[];
|
|
332
|
+
nextCursor: string | null;
|
|
333
|
+
count: V1Count | undefined;
|
|
334
|
+
};
|
|
335
|
+
export type V1Precondition = {
|
|
336
|
+
readonly ifMatch: string;
|
|
337
|
+
} | {
|
|
338
|
+
readonly ifNoneMatchAny: true;
|
|
339
|
+
};
|
|
340
|
+
/**
|
|
341
|
+
* One op's result: `id` and `version` for writes, `asserted` for asserts, and
|
|
342
|
+
* also `count` (decimal u64) for `assertCount`.
|
|
343
|
+
*/
|
|
344
|
+
export type V1TransactionOpResult = {
|
|
345
|
+
readonly id: string;
|
|
346
|
+
readonly version: string;
|
|
347
|
+
} | {
|
|
348
|
+
readonly asserted: true;
|
|
349
|
+
readonly count?: string;
|
|
350
|
+
};
|
|
351
|
+
export type V1CountBounds = {
|
|
352
|
+
readonly gte?: number | undefined;
|
|
353
|
+
readonly lte?: number | undefined;
|
|
354
|
+
};
|
|
355
|
+
export type V1TransactionResult = {
|
|
356
|
+
offset: string;
|
|
357
|
+
durability: V1Durability;
|
|
358
|
+
/**
|
|
359
|
+
* One per op, in order.
|
|
360
|
+
*/
|
|
361
|
+
results: readonly V1TransactionOpResult[];
|
|
362
|
+
};
|
|
363
|
+
import type { TerraBaseV1ClientConfig } from "./transport.js";
|
|
364
|
+
import type { V1Document } from "./decode.js";
|
|
365
|
+
import type { JsonInputObject } from "./json.js";
|
|
366
|
+
import type { V1WriteResult } from "./decode.js";
|
|
367
|
+
import type { V1ShapeRequest } from "./shapes.js";
|
|
368
|
+
import type { V1ShapePage } from "./shapes.js";
|
|
369
|
+
import { V1Transport } from "./transport.js";
|
|
370
|
+
import type { V1Filter } from "./filter.js";
|
|
371
|
+
import type { JsonInput } from "./json.js";
|
|
372
|
+
import { ExactDecimal } from "./json.js";
|
|
373
|
+
import type { V1Path } from "./filter.js";
|
|
374
|
+
import type { V1Durability } from "./decode.js";
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {string} raw
|
|
3
|
+
* @param {string} what
|
|
4
|
+
* @returns {URL}
|
|
5
|
+
*/
|
|
6
|
+
export function requireServiceUrl(raw: string, what: string): URL;
|
|
7
|
+
/**
|
|
8
|
+
* An explicitly configured endpoint, with no discovery or hardcoded hosts.
|
|
9
|
+
* @param {string} baseUrl
|
|
10
|
+
* @returns {V1EndpointResolver}
|
|
11
|
+
*/
|
|
12
|
+
export function staticBaseUrlResolver(baseUrl: string): V1EndpointResolver;
|
|
13
|
+
/**
|
|
14
|
+
* @import { FetchLike } from "../config.js"
|
|
15
|
+
* @import { TerraBaseV1Error } from "./errors.js"
|
|
16
|
+
* @import { JsonValue } from "./json.js"
|
|
17
|
+
* @import { V1Operation } from "./routes.js"
|
|
18
|
+
*/
|
|
19
|
+
/** Server request body limit (api-v1.md). */
|
|
20
|
+
export const maximumRequestBytes: number;
|
|
21
|
+
/** A response body that failed in transit after its headers arrived. */
|
|
22
|
+
export class BodyTransportError extends Error {
|
|
23
|
+
/** @param {unknown} cause */
|
|
24
|
+
constructor(cause: unknown);
|
|
25
|
+
}
|
|
26
|
+
/** Internal transport bound to one data key. */
|
|
27
|
+
export class V1Transport {
|
|
28
|
+
/**
|
|
29
|
+
* @param {Response} response
|
|
30
|
+
* @param {string} text
|
|
31
|
+
* @returns {JsonValue | undefined}
|
|
32
|
+
*/
|
|
33
|
+
static "__#private@#decodeJson"(response: Response, text: string): JsonValue | undefined;
|
|
34
|
+
/** @param {TerraBaseV1ClientConfig} config */
|
|
35
|
+
constructor(config: TerraBaseV1ClientConfig);
|
|
36
|
+
/**
|
|
37
|
+
* @param {V1Operation} operation
|
|
38
|
+
* @param {Readonly<Record<string, string>>} params
|
|
39
|
+
* @param {AbortSignal | undefined} [signal]
|
|
40
|
+
* @returns {Promise<string>}
|
|
41
|
+
*/
|
|
42
|
+
url(operation: V1Operation, params: Readonly<Record<string, string>>, signal?: AbortSignal | undefined): Promise<string>;
|
|
43
|
+
/**
|
|
44
|
+
* Reads a response body as UTF-8 text within the response byte bound. A
|
|
45
|
+
* connection failure while reading is a BodyTransportError.
|
|
46
|
+
* @param {Response} response
|
|
47
|
+
* @returns {Promise<string>}
|
|
48
|
+
*/
|
|
49
|
+
readText(response: Response): Promise<string>;
|
|
50
|
+
/**
|
|
51
|
+
* Parses a JSON response body exactly.
|
|
52
|
+
* @param {Response} response
|
|
53
|
+
* @returns {Promise<JsonValue | undefined>}
|
|
54
|
+
*/
|
|
55
|
+
readJson(response: Response): Promise<JsonValue | undefined>;
|
|
56
|
+
/**
|
|
57
|
+
* Converts a non-success response to a TerraBaseV1Error.
|
|
58
|
+
* @param {Response} response
|
|
59
|
+
* @returns {Promise<TerraBaseV1Error>}
|
|
60
|
+
*/
|
|
61
|
+
error(response: Response): Promise<TerraBaseV1Error>;
|
|
62
|
+
/**
|
|
63
|
+
* Calls only a named producer route. Redirects and failed mutations are never replayed.
|
|
64
|
+
* @param {V1Operation} operation
|
|
65
|
+
* @param {Readonly<Record<string, string>>} params
|
|
66
|
+
* @param {V1CallOptions} [options]
|
|
67
|
+
* @returns {Promise<V1CallResult>}
|
|
68
|
+
*/
|
|
69
|
+
call(operation: V1Operation, params: Readonly<Record<string, string>>, options?: V1CallOptions): Promise<V1CallResult>;
|
|
70
|
+
#private;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Resolver input contains no credential. A successful URL is cached for this client/database.
|
|
74
|
+
*/
|
|
75
|
+
export type V1EndpointContext = {
|
|
76
|
+
readonly project: string;
|
|
77
|
+
readonly database: string;
|
|
78
|
+
readonly signal?: AbortSignal | undefined;
|
|
79
|
+
};
|
|
80
|
+
export type V1EndpointResolver = (context: V1EndpointContext) => string | Promise<string>;
|
|
81
|
+
/**
|
|
82
|
+
* Project-scoped C# Documents API client. Supply exactly one of baseUrl or endpointResolver.
|
|
83
|
+
* URLs must use HTTPS or loopback HTTP. Mutations are never automatically replayed.
|
|
84
|
+
*/
|
|
85
|
+
export type TerraBaseV1ClientConfig = {
|
|
86
|
+
project: string;
|
|
87
|
+
/**
|
|
88
|
+
* A tb_ API key; held privately.
|
|
89
|
+
*/
|
|
90
|
+
token: string;
|
|
91
|
+
baseUrl?: string | undefined;
|
|
92
|
+
endpointResolver?: V1EndpointResolver | undefined;
|
|
93
|
+
fetch?: FetchLike | undefined;
|
|
94
|
+
/**
|
|
95
|
+
* Default 64 MiB, including query framing and escaping.
|
|
96
|
+
*/
|
|
97
|
+
maxResponseBytes?: number | undefined;
|
|
98
|
+
};
|
|
99
|
+
export type V1CallOptions = {
|
|
100
|
+
body?: string;
|
|
101
|
+
contentType?: string;
|
|
102
|
+
/**
|
|
103
|
+
* Contract headers only (If-Match, If-None-Match).
|
|
104
|
+
*/
|
|
105
|
+
headers?: Readonly<Record<string, string>>;
|
|
106
|
+
query?: URLSearchParams | undefined;
|
|
107
|
+
signal?: AbortSignal | undefined;
|
|
108
|
+
};
|
|
109
|
+
export type V1CallResult = {
|
|
110
|
+
status: number;
|
|
111
|
+
headers: Headers;
|
|
112
|
+
value: JsonValue | undefined;
|
|
113
|
+
};
|
|
114
|
+
import type { V1Operation } from "./routes.js";
|
|
115
|
+
import type { JsonValue } from "./json.js";
|
|
116
|
+
import type { TerraBaseV1Error } from "./errors.js";
|
|
117
|
+
import type { FetchLike } from "../config.js";
|