@terrascale/sdk 0.0.3 → 0.0.4
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 +17 -0
- package/README.md +177 -67
- package/package.json +10 -4
- package/sdk-public-v1-route-manifest.json +81 -0
- package/sdk-v1-route-manifest.json +896 -15
- package/src/http.js +3 -48
- package/src/index.js +75 -1
- package/src/local/environment.js +0 -1
- package/src/ts-auth.js +1 -5
- package/src/v1/backups.js +111 -0
- package/src/v1/catalog.js +210 -0
- package/src/v1/changes.js +225 -0
- package/src/v1/database-schema.js +45 -0
- package/src/v1/decode.js +5 -5
- package/src/v1/errors.js +23 -3
- package/src/v1/ids.js +5 -2
- package/src/v1/imports.js +72 -0
- package/src/v1/indexes.js +76 -0
- package/src/v1/json.js +4 -3
- package/src/v1/management-decode.js +24 -0
- package/src/v1/management-routes.js +67 -0
- package/src/v1/management-validation.js +25 -0
- package/src/v1/routes.js +32 -7
- package/src/v1/saved-queries.js +58 -0
- package/src/v1/shape-crypto.js +125 -0
- package/src/v1/shape-manifest.js +31 -0
- package/src/v1/shape-reader.js +212 -0
- package/src/v1/shape-subscription.js +208 -0
- package/src/v1/shapes.js +11 -5
- package/src/v1/sql.js +98 -0
- package/src/v1/system.js +80 -0
- package/src/v1/terrabase-v1.js +178 -27
- package/src/v1/transport.js +75 -31
- package/src/v1/usage.js +101 -0
- package/types/http.d.ts +2 -8
- package/types/index.d.ts +68 -0
- package/types/local/environment.d.ts +1 -1
- package/types/ts-auth.d.ts +0 -2
- package/types/v1/backups.d.ts +128 -0
- package/types/v1/catalog.d.ts +92 -0
- package/types/v1/changes.d.ts +53 -0
- package/types/v1/database-schema.d.ts +82 -0
- package/types/v1/decode.d.ts +15 -4
- package/types/v1/errors.d.ts +16 -1
- package/types/v1/ids.d.ts +2 -2
- package/types/v1/imports.d.ts +132 -0
- package/types/v1/indexes.d.ts +75 -0
- package/types/v1/management-decode.d.ts +15 -0
- package/types/v1/management-routes.d.ts +3 -0
- package/types/v1/management-validation.d.ts +8 -0
- package/types/v1/routes.d.ts +5 -2
- package/types/v1/saved-queries.d.ts +33 -0
- package/types/v1/shape-crypto.d.ts +39 -0
- package/types/v1/shape-manifest.d.ts +28 -0
- package/types/v1/shape-reader.d.ts +45 -0
- package/types/v1/shape-subscription.d.ts +35 -0
- package/types/v1/shapes.d.ts +16 -2
- package/types/v1/sql.d.ts +47 -0
- package/types/v1/system.d.ts +85 -0
- package/types/v1/terrabase-v1.d.ts +113 -4
- package/types/v1/transport.d.ts +25 -8
- package/types/v1/usage.d.ts +171 -0
- package/src/ts-auth-discovery.js +0 -207
- package/types/ts-auth-discovery.d.ts +0 -19
package/types/v1/decode.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* `document` is the value, or the LWW winner when a causal read answers `"conflict"` with `siblings`.
|
|
5
5
|
* Unknown future states pass through.
|
|
6
6
|
* @typedef {object} V1Document
|
|
7
|
-
* @property {
|
|
7
|
+
* @property {string} id Caller-supplied key or server-generated ULID.
|
|
8
8
|
* @property {string} version
|
|
9
9
|
* @property {"value" | "conflict" | (string & {})} state
|
|
10
10
|
* @property {JsonObject} document
|
|
@@ -13,12 +13,13 @@
|
|
|
13
13
|
/**
|
|
14
14
|
* The result of a document write.
|
|
15
15
|
* @typedef {object} V1WriteResult
|
|
16
|
-
* @property {
|
|
16
|
+
* @property {string} id Caller-supplied key or server-generated ULID.
|
|
17
17
|
* @property {string} version For a delete, the tombstone's version.
|
|
18
18
|
* @property {string} offset The database commit offset (decimal u64), usable with shape `waitFor`.
|
|
19
19
|
* @property {V1Durability} durability
|
|
20
20
|
* @property {boolean} created True when a PUT or POST answered 201.
|
|
21
21
|
* @property {string | undefined} location The Location header of a POST create.
|
|
22
|
+
* @property {JsonObject} [document] Stored document returned by PATCH.
|
|
22
23
|
*/
|
|
23
24
|
/**
|
|
24
25
|
* @param {string} what
|
|
@@ -85,7 +86,10 @@ export type V1Durability = "local_durable" | (string & {});
|
|
|
85
86
|
* Unknown future states pass through.
|
|
86
87
|
*/
|
|
87
88
|
export type V1Document = {
|
|
88
|
-
|
|
89
|
+
/**
|
|
90
|
+
* Caller-supplied key or server-generated ULID.
|
|
91
|
+
*/
|
|
92
|
+
id: string;
|
|
89
93
|
version: string;
|
|
90
94
|
state: "value" | "conflict" | (string & {});
|
|
91
95
|
document: JsonObject;
|
|
@@ -98,7 +102,10 @@ export type V1Document = {
|
|
|
98
102
|
* The result of a document write.
|
|
99
103
|
*/
|
|
100
104
|
export type V1WriteResult = {
|
|
101
|
-
|
|
105
|
+
/**
|
|
106
|
+
* Caller-supplied key or server-generated ULID.
|
|
107
|
+
*/
|
|
108
|
+
id: string;
|
|
102
109
|
/**
|
|
103
110
|
* For a delete, the tombstone's version.
|
|
104
111
|
*/
|
|
@@ -116,6 +123,10 @@ export type V1WriteResult = {
|
|
|
116
123
|
* The Location header of a POST create.
|
|
117
124
|
*/
|
|
118
125
|
location: string | undefined;
|
|
126
|
+
/**
|
|
127
|
+
* Stored document returned by PATCH.
|
|
128
|
+
*/
|
|
129
|
+
document?: JsonObject;
|
|
119
130
|
};
|
|
120
131
|
import type { JsonValue } from "./json.js";
|
|
121
132
|
import type { JsonObject } from "./json.js";
|
package/types/v1/errors.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export function parseRetryAfter(headers: Headers): number | undefined;
|
|
|
21
21
|
* @returns {TerraBaseV1Error}
|
|
22
22
|
*/
|
|
23
23
|
export function parseV1Error(status: number, headers: Headers, text: string): TerraBaseV1Error;
|
|
24
|
-
/** @import { JsonObject } from "./json.js" */
|
|
24
|
+
/** @import { JsonObject, JsonValue } from "./json.js" */
|
|
25
25
|
/**
|
|
26
26
|
* @typedef {object} TerraBaseV1ErrorInit
|
|
27
27
|
* @property {number} status
|
|
@@ -32,6 +32,9 @@ export function parseV1Error(status: number, headers: Headers, text: string): Te
|
|
|
32
32
|
* @property {number | undefined} [retryAfter]
|
|
33
33
|
* @property {string | undefined} [etag]
|
|
34
34
|
* @property {JsonObject | undefined} [details]
|
|
35
|
+
* @property {JsonValue | undefined} [body]
|
|
36
|
+
* @property {string | undefined} [responseText]
|
|
37
|
+
* @property {Headers | undefined} [headers]
|
|
35
38
|
*/
|
|
36
39
|
/**
|
|
37
40
|
* A non-2xx TerraBase v1 response. `code` is the contract's `error.code`, or
|
|
@@ -54,6 +57,14 @@ export class TerraBaseV1Error extends Error {
|
|
|
54
57
|
etag: string | undefined;
|
|
55
58
|
/** @type {JsonObject | undefined} The raw error object, for route-specific metadata. */
|
|
56
59
|
details: JsonObject | undefined;
|
|
60
|
+
/** @type {JsonValue | undefined} Complete parsed response body, including unknown fields. */
|
|
61
|
+
body: JsonValue | undefined;
|
|
62
|
+
/** @type {string} Original response text; empty when absent or unreadable. */
|
|
63
|
+
responseText: string;
|
|
64
|
+
/** @type {Headers} Response headers, including authentication challenges and retry metadata. */
|
|
65
|
+
headers: Headers;
|
|
66
|
+
/** @type {string | undefined} Diagnostic X-Request-ID, when supplied by the responder. */
|
|
67
|
+
requestId: string | undefined;
|
|
57
68
|
}
|
|
58
69
|
/** Current document, collection and shape producer codes, plus client not_modified. */
|
|
59
70
|
export const V1ErrorCode: Readonly<{
|
|
@@ -103,5 +114,9 @@ export type TerraBaseV1ErrorInit = {
|
|
|
103
114
|
retryAfter?: number | undefined;
|
|
104
115
|
etag?: string | undefined;
|
|
105
116
|
details?: JsonObject | undefined;
|
|
117
|
+
body?: JsonValue | undefined;
|
|
118
|
+
responseText?: string | undefined;
|
|
119
|
+
headers?: Headers | undefined;
|
|
106
120
|
};
|
|
107
121
|
import type { JsonObject } from "./json.js";
|
|
122
|
+
import type { JsonValue } from "./json.js";
|
package/types/v1/ids.d.ts
CHANGED
|
@@ -10,8 +10,8 @@ export function requireName(kind: "database" | "collection", name: unknown): str
|
|
|
10
10
|
* @returns {import("../ids.js").EntityId}
|
|
11
11
|
*/
|
|
12
12
|
export function requireProject(project: unknown): import("../ids.js").EntityId;
|
|
13
|
-
/** @param {unknown} id @returns {
|
|
14
|
-
export function requireDocumentId(id: unknown):
|
|
13
|
+
/** A caller-supplied key is not a generated entity ID. @param {unknown} id @returns {string} */
|
|
14
|
+
export function requireDocumentId(id: unknown): string;
|
|
15
15
|
/**
|
|
16
16
|
* @param {unknown} version
|
|
17
17
|
* @returns {string}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/** @typedef {ReturnType<typeof job>} V1ImportJob */
|
|
2
|
+
/** @typedef {{ readonly missingPrimaryKey?: "reject" | "generate" | null; readonly exclude?: readonly string[] | null }} V1ImportOptions */
|
|
3
|
+
/** @typedef {{ readonly format: "postgres_plain" | "sqlite"; readonly sourceBytes: number; readonly sourceSha256: string; readonly options?: V1ImportOptions | null }} V1CreateImportRequest */
|
|
4
|
+
/** One import job belongs to its destination database; preview confirmation is explicit. */
|
|
5
|
+
export class V1Imports {
|
|
6
|
+
/** @param {V1Transport} transport @param {string} database */
|
|
7
|
+
constructor(transport: V1Transport, database: string);
|
|
8
|
+
/** @param {V1CreateImportRequest} request @param {V1RequestOptions} [options] @returns {Promise<V1ImportJob>} */
|
|
9
|
+
create(request: V1CreateImportRequest, options?: V1RequestOptions): Promise<V1ImportJob>;
|
|
10
|
+
/** @param {V1RequestOptions} [options] @returns {Promise<V1ImportJob>} */
|
|
11
|
+
get(options?: V1RequestOptions): Promise<V1ImportJob>;
|
|
12
|
+
/** @param {number | bigint} offset @param {Uint8Array} bytes @param {V1RequestOptions} [options] @returns {Promise<V1ImportJob>} */
|
|
13
|
+
uploadSource(offset: number | bigint, bytes: Uint8Array, options?: V1RequestOptions): Promise<V1ImportJob>;
|
|
14
|
+
/** @param {{readonly options?: V1ImportOptions | null}} request @param {V1RequestOptions} [options] @returns {Promise<V1ImportJob>} */
|
|
15
|
+
update(request: {
|
|
16
|
+
readonly options?: V1ImportOptions | null;
|
|
17
|
+
}, options?: V1RequestOptions): Promise<V1ImportJob>;
|
|
18
|
+
/** @param {{readonly previewId: string}} request @param {V1RequestOptions} [options] @returns {Promise<V1ImportJob>} */
|
|
19
|
+
start(request: {
|
|
20
|
+
readonly previewId: string;
|
|
21
|
+
}, options?: V1RequestOptions): Promise<V1ImportJob>;
|
|
22
|
+
/** @param {V1RequestOptions} [options] @returns {Promise<V1ImportJob>} */
|
|
23
|
+
cancel(options?: V1RequestOptions): Promise<V1ImportJob>;
|
|
24
|
+
/** @param {V1RequestOptions} [options] @returns {Promise<V1ImportJob>} */
|
|
25
|
+
resume(options?: V1RequestOptions): Promise<V1ImportJob>;
|
|
26
|
+
#private;
|
|
27
|
+
}
|
|
28
|
+
export type V1ImportJob = ReturnType<typeof job>;
|
|
29
|
+
export type V1ImportOptions = {
|
|
30
|
+
readonly missingPrimaryKey?: "reject" | "generate" | null;
|
|
31
|
+
readonly exclude?: readonly string[] | null;
|
|
32
|
+
};
|
|
33
|
+
export type V1CreateImportRequest = {
|
|
34
|
+
readonly format: "postgres_plain" | "sqlite";
|
|
35
|
+
readonly sourceBytes: number;
|
|
36
|
+
readonly sourceSha256: string;
|
|
37
|
+
readonly options?: V1ImportOptions | null;
|
|
38
|
+
};
|
|
39
|
+
import type { V1RequestOptions } from "./terrabase-v1.js";
|
|
40
|
+
import type { V1Transport } from "./transport.js";
|
|
41
|
+
declare const job: import("./management-decode.js").Decoder<Readonly<{
|
|
42
|
+
id: string;
|
|
43
|
+
project: string;
|
|
44
|
+
database: string;
|
|
45
|
+
region: string;
|
|
46
|
+
state: string;
|
|
47
|
+
cancelRequested: boolean;
|
|
48
|
+
options: Readonly<{
|
|
49
|
+
missingPrimaryKey: string | null;
|
|
50
|
+
exclude: readonly string[] | null;
|
|
51
|
+
}>;
|
|
52
|
+
source: Readonly<{
|
|
53
|
+
format: string;
|
|
54
|
+
bytes: number | import("./json.js").ExactDecimal;
|
|
55
|
+
sha256: string;
|
|
56
|
+
receivedBytes: number | import("./json.js").ExactDecimal;
|
|
57
|
+
staged: boolean;
|
|
58
|
+
retainedUntil: string | null;
|
|
59
|
+
}>;
|
|
60
|
+
preview: Readonly<{
|
|
61
|
+
id: string;
|
|
62
|
+
tables: readonly Readonly<{
|
|
63
|
+
source: string;
|
|
64
|
+
collection: string;
|
|
65
|
+
excluded: boolean;
|
|
66
|
+
rows: number | import("./json.js").ExactDecimal;
|
|
67
|
+
idPolicy: string;
|
|
68
|
+
primaryKey: readonly string[];
|
|
69
|
+
columns: readonly Readonly<{
|
|
70
|
+
name: /*elided*/ any;
|
|
71
|
+
sourceType: /*elided*/ any;
|
|
72
|
+
mapping: /*elided*/ any;
|
|
73
|
+
nullable: /*elided*/ any;
|
|
74
|
+
excluded: /*elided*/ any;
|
|
75
|
+
}>[];
|
|
76
|
+
constraints: readonly Readonly<{
|
|
77
|
+
kind: /*elided*/ any;
|
|
78
|
+
name: /*elided*/ any;
|
|
79
|
+
columns: /*elided*/ any;
|
|
80
|
+
references: /*elided*/ any;
|
|
81
|
+
enforced: /*elided*/ any;
|
|
82
|
+
}>[];
|
|
83
|
+
issues: readonly Readonly<{
|
|
84
|
+
severity: /*elided*/ any;
|
|
85
|
+
code: /*elided*/ any;
|
|
86
|
+
column: /*elided*/ any;
|
|
87
|
+
row: /*elided*/ any;
|
|
88
|
+
message: /*elided*/ any;
|
|
89
|
+
}>[];
|
|
90
|
+
}>[];
|
|
91
|
+
skipped: readonly Readonly<{
|
|
92
|
+
kind: string;
|
|
93
|
+
name: string;
|
|
94
|
+
}>[];
|
|
95
|
+
skippedTruncated: boolean;
|
|
96
|
+
blocking: number | import("./json.js").ExactDecimal;
|
|
97
|
+
warnings: number | import("./json.js").ExactDecimal;
|
|
98
|
+
}> | null;
|
|
99
|
+
confirmedPreviewId: string | null;
|
|
100
|
+
progress: Readonly<{
|
|
101
|
+
tablesDone: number | import("./json.js").ExactDecimal;
|
|
102
|
+
tablesTotal: number | import("./json.js").ExactDecimal;
|
|
103
|
+
rowsWritten: number | import("./json.js").ExactDecimal;
|
|
104
|
+
rowsTotal: number | import("./json.js").ExactDecimal;
|
|
105
|
+
currentTable: string | null;
|
|
106
|
+
}> | null;
|
|
107
|
+
validation: Readonly<{
|
|
108
|
+
passed: boolean;
|
|
109
|
+
tables: readonly Readonly<{
|
|
110
|
+
source: string;
|
|
111
|
+
collection: string;
|
|
112
|
+
sourceRows: number | import("./json.js").ExactDecimal;
|
|
113
|
+
documents: number | import("./json.js").ExactDecimal;
|
|
114
|
+
sourceChecksum: string;
|
|
115
|
+
documentChecksum: string;
|
|
116
|
+
match: boolean;
|
|
117
|
+
}>[];
|
|
118
|
+
}> | null;
|
|
119
|
+
error: Readonly<{
|
|
120
|
+
code: string;
|
|
121
|
+
message: string;
|
|
122
|
+
retryable: boolean;
|
|
123
|
+
table: string | null;
|
|
124
|
+
row: number | import("./json.js").ExactDecimal | null;
|
|
125
|
+
column: string | null;
|
|
126
|
+
}> | null;
|
|
127
|
+
createdAt: string;
|
|
128
|
+
updatedAt: string;
|
|
129
|
+
startedAt: string | null;
|
|
130
|
+
finishedAt: string | null;
|
|
131
|
+
}>>;
|
|
132
|
+
export {};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/** Secondary indexes, automatic policies and workload recommendations for one database. */
|
|
2
|
+
export class V1Indexes {
|
|
3
|
+
/** @param {V1Transport} transport @param {string} database */
|
|
4
|
+
constructor(transport: V1Transport, database: string);
|
|
5
|
+
/** @param {V1CreateIndexRequest} request @param {V1RequestOptions} [options] @returns {Promise<V1Index>} */
|
|
6
|
+
create(request: V1CreateIndexRequest, options?: V1RequestOptions): Promise<V1Index>;
|
|
7
|
+
/** @param {{ readonly collection?: string }} [request] @param {V1RequestOptions} [options] @returns {Promise<V1IndexList>} */
|
|
8
|
+
list(request?: {
|
|
9
|
+
readonly collection?: string;
|
|
10
|
+
}, options?: V1RequestOptions): Promise<V1IndexList>;
|
|
11
|
+
/** @param {string} name @param {V1RequestOptions} [options] @returns {Promise<void>} */
|
|
12
|
+
drop(name: string, options?: V1RequestOptions): Promise<void>;
|
|
13
|
+
/** @param {string} collection @param {V1RequestOptions} [options] @returns {Promise<V1AutoIndexPolicy>} */
|
|
14
|
+
getAutoPolicy(collection: string, options?: V1RequestOptions): Promise<V1AutoIndexPolicy>;
|
|
15
|
+
/** @param {string} collection @param {{ readonly enabled: boolean }} request @param {V1RequestOptions} [options] @returns {Promise<V1AutoIndexPolicy>} */
|
|
16
|
+
setAutoPolicy(collection: string, request: {
|
|
17
|
+
readonly enabled: boolean;
|
|
18
|
+
}, options?: V1RequestOptions): Promise<V1AutoIndexPolicy>;
|
|
19
|
+
/** @param {V1RequestOptions} [options] @returns {Promise<V1IndexRecommendations>} */
|
|
20
|
+
recommendations(options?: V1RequestOptions): Promise<V1IndexRecommendations>;
|
|
21
|
+
/** @param {string} id Opaque producer recommendation identifier. @param {V1RequestOptions} [options] @returns {Promise<V1AppliedIndexRecommendation>} */
|
|
22
|
+
applyRecommendation(id: string, options?: V1RequestOptions): Promise<V1AppliedIndexRecommendation>;
|
|
23
|
+
#private;
|
|
24
|
+
}
|
|
25
|
+
export type V1Index = ReturnType<typeof index>;
|
|
26
|
+
export type V1IndexList = ReturnType<typeof indexes>;
|
|
27
|
+
export type V1AutoIndexPolicy = ReturnType<typeof policy>;
|
|
28
|
+
export type V1IndexRecommendations = ReturnType<typeof recommendations>;
|
|
29
|
+
export type V1AppliedIndexRecommendation = ReturnType<typeof applied>;
|
|
30
|
+
export type V1CreateIndexRequest = {
|
|
31
|
+
readonly collection: string;
|
|
32
|
+
readonly fields: readonly string[];
|
|
33
|
+
readonly name?: string | null;
|
|
34
|
+
};
|
|
35
|
+
import type { V1RequestOptions } from "./terrabase-v1.js";
|
|
36
|
+
import type { V1Transport } from "./transport.js";
|
|
37
|
+
/** @import { V1Transport } from "./transport.js" */
|
|
38
|
+
/** @import { V1RequestOptions } from "./terrabase-v1.js" */
|
|
39
|
+
declare const index: import("./management-decode.js").Decoder<Readonly<{
|
|
40
|
+
name: string;
|
|
41
|
+
collection: string;
|
|
42
|
+
fields: readonly string[];
|
|
43
|
+
state: string;
|
|
44
|
+
}>>;
|
|
45
|
+
declare const indexes: import("./management-decode.js").Decoder<Readonly<{
|
|
46
|
+
items: readonly Readonly<{
|
|
47
|
+
name: string;
|
|
48
|
+
collection: string;
|
|
49
|
+
fields: readonly string[];
|
|
50
|
+
state: string;
|
|
51
|
+
}>[];
|
|
52
|
+
}>>;
|
|
53
|
+
declare const policy: import("./management-decode.js").Decoder<Readonly<{
|
|
54
|
+
collection: string;
|
|
55
|
+
enabled: boolean;
|
|
56
|
+
}>>;
|
|
57
|
+
declare const recommendations: import("./management-decode.js").Decoder<Readonly<{
|
|
58
|
+
items: readonly Readonly<{
|
|
59
|
+
id: string;
|
|
60
|
+
collection: string;
|
|
61
|
+
fields: readonly string[];
|
|
62
|
+
reason: string;
|
|
63
|
+
queries: number | import("./json.js").ExactDecimal;
|
|
64
|
+
}>[];
|
|
65
|
+
}>>;
|
|
66
|
+
declare const applied: import("./management-decode.js").Decoder<Readonly<{
|
|
67
|
+
status: string;
|
|
68
|
+
index: Readonly<{
|
|
69
|
+
name: string;
|
|
70
|
+
collection: string;
|
|
71
|
+
fields: readonly string[];
|
|
72
|
+
state: string;
|
|
73
|
+
}>;
|
|
74
|
+
}>>;
|
|
75
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** @template T @param {{ [K in keyof T]: Decoder<T[K]> }} fields @returns {Decoder<Readonly<T>>} */
|
|
2
|
+
export function record<T>(fields: { [K in keyof T]: Decoder<T[K]>; }): Decoder<Readonly<T>>;
|
|
3
|
+
/** @import { JsonValue } from "./json.js" */
|
|
4
|
+
/** @template T @typedef {(value: JsonValue | undefined) => T} Decoder */
|
|
5
|
+
export const text: Decoder<string>;
|
|
6
|
+
export const flag: Decoder<boolean>;
|
|
7
|
+
/** @type {Decoder<number | ExactDecimal>} */
|
|
8
|
+
export const numeric: Decoder<number | ExactDecimal>;
|
|
9
|
+
export function nullable<T>(decode: Decoder<T>): Decoder<T | null>;
|
|
10
|
+
export function optional<T>(decode: Decoder<T>): Decoder<T | undefined>;
|
|
11
|
+
export function list<T>(decode: Decoder<T>): Decoder<readonly T[]>;
|
|
12
|
+
export function dictionary<T>(decode: Decoder<T>): Decoder<Readonly<Record<string, T>>>;
|
|
13
|
+
export type Decoder<T> = (value: JsonValue | undefined) => T;
|
|
14
|
+
import { ExactDecimal } from "./json.js";
|
|
15
|
+
import type { JsonValue } from "./json.js";
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/** @type {readonly import("./routes.js").V1Route[]} */
|
|
2
|
+
export const managementV1Routes: readonly import("./routes.js").V1Route[];
|
|
3
|
+
export type ManagementOperation = "getShapeManifest" | "healthz" | "readyz" | "backupz" | "replicationHealth" | "listPlatformDatabases" | "listPlatformCollections" | "listPlatformDocuments" | "getPlatformDocument" | "createImport" | "getImport" | "uploadImportSource" | "updateImport" | "startImport" | "cancelImport" | "resumeImport" | "createBackup" | "listBackups" | "restoreBackup" | "getBackupPolicy" | "setBackupPolicy" | "getRestoreWindow" | "planPointInTime" | "restorePointInTime" | "getBackupDestination" | "setBackupDestination" | "deleteBackupDestination" | "getProjectUsage" | "getProjectAnalytics" | "getProjectReplication" | "getDatabaseUsage" | "getDatabaseAnalytics" | "getDatabaseReplication" | "createIndex" | "listIndexes" | "dropIndex" | "getAutoIndexPolicy" | "setAutoIndexPolicy" | "listIndexRecommendations" | "applyIndexRecommendation" | "getDatabaseSchema" | "inferCollectionSchema" | "declareCollectionSchema" | "listQueryShapes" | "createSavedQuery" | "listSavedQueries" | "getSavedQuery" | "updateSavedQuery" | "deleteSavedQuery";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** @import { V1DatabaseListRequest } from "./catalog.js" */
|
|
2
|
+
/** @param {unknown} request @param {readonly string[]} allowed */
|
|
3
|
+
export function members(request: unknown, allowed: readonly string[]): void;
|
|
4
|
+
/** @param {object} options */
|
|
5
|
+
export function mutationOptions(options: object): void;
|
|
6
|
+
/** @param {V1DatabaseListRequest} request */
|
|
7
|
+
export function pageQuery(request: V1DatabaseListRequest): URLSearchParams;
|
|
8
|
+
import type { V1DatabaseListRequest } from "./catalog.js";
|
package/types/v1/routes.d.ts
CHANGED
|
@@ -4,12 +4,15 @@ export function v1Route(operation: V1Operation): V1Route;
|
|
|
4
4
|
export function v1RoutePath(route: V1Route, params: Readonly<Record<string, string>>): string;
|
|
5
5
|
/** @type {readonly V1Route[]} */
|
|
6
6
|
export const v1Routes: readonly V1Route[];
|
|
7
|
-
|
|
7
|
+
/** @type {readonly V1Route[]} */
|
|
8
|
+
export const shapeV1Routes: readonly V1Route[];
|
|
9
|
+
export type V1Operation = import("./management-routes.js").ManagementOperation | "readFreeShape" | "getShapeKey" | "getDocument" | "putDocument" | "createDocument" | "patchDocument" | "deleteDocument" | "commitTransaction" | "queryDocuments" | "createCollection" | "getCollection" | "listCollections" | "dropCollection" | "readShape" | "runSql" | "checkSql" | "explainSql" | "streamDatabaseChanges" | "listDocuments" | "getCollectionSchema" | "putCollectionSchema" | "deleteCollectionSchema" | "createDatabase" | "listDatabases" | "getDatabase" | "updateDatabase" | "deleteDatabase" | "branchDatabase";
|
|
8
10
|
export type V1Route = {
|
|
9
11
|
operation: V1Operation;
|
|
10
12
|
method: "GET" | "PUT" | "POST" | "PATCH" | "DELETE";
|
|
11
13
|
pathTemplate: string;
|
|
12
|
-
permission: "documents:read" | "documents:write" | "shapes:read";
|
|
14
|
+
permission: "documents:read" | "documents:write" | "shapes:read" | "databases:read" | "databases:write" | "anonymous" | "platform-admin";
|
|
15
|
+
additionalPermissions?: readonly string[];
|
|
13
16
|
requestMediaTypes: readonly string[];
|
|
14
17
|
responseMediaType: string;
|
|
15
18
|
successStatuses: readonly number[];
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** Saved queries belong to the authorized project, independently of database handles. */
|
|
2
|
+
export class V1SavedQueries {
|
|
3
|
+
/** @param {V1Transport} transport */
|
|
4
|
+
constructor(transport: V1Transport);
|
|
5
|
+
/** @param {V1SavedQueryRequest} request @param {V1RequestOptions} [options] @returns {Promise<V1SavedQuery>} */
|
|
6
|
+
create(request: V1SavedQueryRequest, options?: V1RequestOptions): Promise<V1SavedQuery>;
|
|
7
|
+
/** @param {import("./catalog.js").V1DatabaseListRequest} [request] @param {V1RequestOptions} [options] @returns {Promise<V1SavedQueryPage>} */
|
|
8
|
+
list(request?: import("./catalog.js").V1DatabaseListRequest, options?: V1RequestOptions): Promise<V1SavedQueryPage>;
|
|
9
|
+
/** @param {string} id @param {V1RequestOptions} [options] @returns {Promise<V1SavedQuery>} */
|
|
10
|
+
get(id: string, options?: V1RequestOptions): Promise<V1SavedQuery>;
|
|
11
|
+
/** @param {string} id @param {V1SavedQueryRequest} request @param {V1RequestOptions} [options] @returns {Promise<V1SavedQuery>} */
|
|
12
|
+
update(id: string, request: V1SavedQueryRequest, options?: V1RequestOptions): Promise<V1SavedQuery>;
|
|
13
|
+
/** @param {string} id @param {V1RequestOptions} [options] @returns {Promise<void>} */
|
|
14
|
+
delete(id: string, options?: V1RequestOptions): Promise<void>;
|
|
15
|
+
#private;
|
|
16
|
+
}
|
|
17
|
+
export type V1SavedQuery = {
|
|
18
|
+
readonly id: string;
|
|
19
|
+
readonly name: string;
|
|
20
|
+
readonly sql: string;
|
|
21
|
+
readonly createdAt: string;
|
|
22
|
+
readonly updatedAt: string | null;
|
|
23
|
+
};
|
|
24
|
+
export type V1SavedQueryRequest = {
|
|
25
|
+
readonly name: string;
|
|
26
|
+
readonly sql: string;
|
|
27
|
+
};
|
|
28
|
+
export type V1SavedQueryPage = {
|
|
29
|
+
readonly items: readonly V1SavedQuery[];
|
|
30
|
+
readonly next: string | null;
|
|
31
|
+
};
|
|
32
|
+
import type { V1RequestOptions } from "./terrabase-v1.js";
|
|
33
|
+
import type { V1Transport } from "./transport.js";
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {object} ShapeObjectRequest
|
|
3
|
+
* @property {string} handle The shape handle this client requested, e.g. `h1-…`.
|
|
4
|
+
* @property {string} offset Canonical offset of the object's URL, e.g. `2` or `snap.0.0`.
|
|
5
|
+
* @property {string} epoch Decimal epoch the client expects in the header.
|
|
6
|
+
* @property {string} keyId The 26-character project data key id the client expects in the header.
|
|
7
|
+
* @property {Uint8Array} key Raw 32-byte epoch key `K_e`.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Verifies and decrypts one TBS1 sealed shape object. The plaintext is returned only when the
|
|
11
|
+
* header, every frame tag and the framing rules pass. Any failure throws and yields no bytes.
|
|
12
|
+
*
|
|
13
|
+
* @param {Uint8Array} input Exact TBS1 object bytes.
|
|
14
|
+
* @param {ShapeObjectRequest} request
|
|
15
|
+
* @returns {Promise<Uint8Array>}
|
|
16
|
+
*/
|
|
17
|
+
export function decryptShapeObject(input: Uint8Array, { handle, offset, epoch, keyId, key: keyInput }: ShapeObjectRequest): Promise<Uint8Array>;
|
|
18
|
+
export type ShapeObjectRequest = {
|
|
19
|
+
/**
|
|
20
|
+
* The shape handle this client requested, e.g. `h1-…`.
|
|
21
|
+
*/
|
|
22
|
+
handle: string;
|
|
23
|
+
/**
|
|
24
|
+
* Canonical offset of the object's URL, e.g. `2` or `snap.0.0`.
|
|
25
|
+
*/
|
|
26
|
+
offset: string;
|
|
27
|
+
/**
|
|
28
|
+
* Decimal epoch the client expects in the header.
|
|
29
|
+
*/
|
|
30
|
+
epoch: string;
|
|
31
|
+
/**
|
|
32
|
+
* The 26-character project data key id the client expects in the header.
|
|
33
|
+
*/
|
|
34
|
+
keyId: string;
|
|
35
|
+
/**
|
|
36
|
+
* Raw 32-byte epoch key `K_e`.
|
|
37
|
+
*/
|
|
38
|
+
key: Uint8Array;
|
|
39
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** @typedef {ReturnType<typeof manifest>} V1ShapeManifest */
|
|
2
|
+
/** @typedef {{readonly handle: string; readonly offset: string; readonly where?: import("./filter.js").V1Filter}} V1ShapeManifestRequest */
|
|
3
|
+
/** @param {V1Transport} transport @param {Readonly<Record<string, string>>} params @param {V1ShapeManifestRequest} request @param {AbortSignal | undefined} signal @returns {Promise<V1ShapeManifest>} */
|
|
4
|
+
export function readShapeManifest(transport: V1Transport, params: Readonly<Record<string, string>>, request: V1ShapeManifestRequest, signal: AbortSignal | undefined): Promise<V1ShapeManifest>;
|
|
5
|
+
export type V1ShapeManifest = ReturnType<typeof manifest>;
|
|
6
|
+
export type V1ShapeManifestRequest = {
|
|
7
|
+
readonly handle: string;
|
|
8
|
+
readonly offset: string;
|
|
9
|
+
readonly where?: import("./filter.js").V1Filter;
|
|
10
|
+
};
|
|
11
|
+
import type { V1Transport } from "./transport.js";
|
|
12
|
+
/** @import { V1Transport } from "./transport.js" */
|
|
13
|
+
declare const manifest: import("./management-decode.js").Decoder<Readonly<{
|
|
14
|
+
handle: string;
|
|
15
|
+
objects: readonly Readonly<{
|
|
16
|
+
offset: string;
|
|
17
|
+
next_offset: string;
|
|
18
|
+
binding: string;
|
|
19
|
+
object: string;
|
|
20
|
+
url: string;
|
|
21
|
+
expires_at: string;
|
|
22
|
+
epoch: string;
|
|
23
|
+
key_id: string;
|
|
24
|
+
sha256: string;
|
|
25
|
+
size: number | import("./json.js").ExactDecimal;
|
|
26
|
+
}>[];
|
|
27
|
+
}>>;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/** @param {import("./json.js").JsonValue | undefined} value @param {Headers} headers @returns {V1ShapePage} */
|
|
2
|
+
export function decodeFreeShapePage(value: import("./json.js").JsonValue | undefined, headers: Headers): V1ShapePage;
|
|
3
|
+
/**
|
|
4
|
+
* Follows exactly one authorized same-route 307; credentials never follow an arbitrary Location.
|
|
5
|
+
* @param {V1Transport} transport @param {Readonly<Record<string,string>>} params
|
|
6
|
+
* @param {V1ShapeRequest} request @param {AbortSignal | undefined} signal
|
|
7
|
+
* @param {string | undefined} [ifNoneMatch] A complete entity-tag list or *; 304 throws not_modified with response headers.
|
|
8
|
+
* @returns {Promise<V1ShapePage>}
|
|
9
|
+
*/
|
|
10
|
+
export function readShapePage(transport: V1Transport, params: Readonly<Record<string, string>>, request: V1ShapeRequest, signal: AbortSignal | undefined, ifNoneMatch?: string | undefined): Promise<V1ShapePage>;
|
|
11
|
+
/**
|
|
12
|
+
* Reuse process-memory keys for this handle/epoch/KID; fetch misses without HTTP cache reuse.
|
|
13
|
+
* @param {V1Transport} transport @param {Readonly<Record<string,string>>} params
|
|
14
|
+
* @param {Uint8Array} bytes @param {V1SealedShapePosition} position @param {AbortSignal | undefined} signal
|
|
15
|
+
* @returns {Promise<V1ShapePage>}
|
|
16
|
+
*/
|
|
17
|
+
export function decryptSealedShapePage(transport: V1Transport, params: Readonly<Record<string, string>>, bytes: Uint8Array, position: V1SealedShapePosition, signal: AbortSignal | undefined): Promise<V1ShapePage>;
|
|
18
|
+
/** @typedef {{readonly handle: string; readonly epoch: string; readonly keyId: string}} V1ShapeKeyRequest */
|
|
19
|
+
/** @typedef {V1ShapeKeyRequest & {readonly key: Uint8Array}} V1ShapeKey */
|
|
20
|
+
/** @param {V1Transport} transport @param {Readonly<Record<string, string>>} params @param {V1ShapeKeyRequest} request @param {AbortSignal | undefined} signal @returns {Promise<V1ShapeKey>} */
|
|
21
|
+
export function readShapeKey(transport: V1Transport, params: Readonly<Record<string, string>>, request: V1ShapeKeyRequest, signal: AbortSignal | undefined): Promise<V1ShapeKey>;
|
|
22
|
+
export type V1ShapeKeyRequest = {
|
|
23
|
+
readonly handle: string;
|
|
24
|
+
readonly epoch: string;
|
|
25
|
+
readonly keyId: string;
|
|
26
|
+
};
|
|
27
|
+
export type V1ShapeKey = V1ShapeKeyRequest & {
|
|
28
|
+
readonly key: Uint8Array;
|
|
29
|
+
};
|
|
30
|
+
export type V1SealedShapePosition = {
|
|
31
|
+
handle: string;
|
|
32
|
+
offset: string;
|
|
33
|
+
epoch: string;
|
|
34
|
+
keyId: string;
|
|
35
|
+
};
|
|
36
|
+
export type ShapeKeys = {
|
|
37
|
+
latestEpoch: bigint;
|
|
38
|
+
keys: Map<string, {
|
|
39
|
+
epoch: bigint;
|
|
40
|
+
key: Uint8Array;
|
|
41
|
+
}>;
|
|
42
|
+
};
|
|
43
|
+
import type { V1ShapePage } from "./shapes.js";
|
|
44
|
+
import type { V1Transport } from "./transport.js";
|
|
45
|
+
import type { V1ShapeRequest } from "./shapes.js";
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export class V1ShapeSubscription {
|
|
2
|
+
/**
|
|
3
|
+
* @param {V1Transport} transport
|
|
4
|
+
* @param {Readonly<Record<string, string>>} params
|
|
5
|
+
* @param {{ where?: V1Filter | undefined }} [shape]
|
|
6
|
+
* @param {V1ShapeSubscribeOptions} [options]
|
|
7
|
+
*/
|
|
8
|
+
constructor(transport: V1Transport, params: Readonly<Record<string, string>>, shape?: {
|
|
9
|
+
where?: V1Filter | undefined;
|
|
10
|
+
}, options?: V1ShapeSubscribeOptions);
|
|
11
|
+
/** A copy per read: callers cannot change the documents this subscription holds. */
|
|
12
|
+
get state(): Map<string, V1ShapeDocument>;
|
|
13
|
+
get upToDate(): boolean;
|
|
14
|
+
/** Settles when the run ends: resolves on close, rejects on a terminal failure. */
|
|
15
|
+
get done(): Promise<void>;
|
|
16
|
+
close(): void;
|
|
17
|
+
#private;
|
|
18
|
+
}
|
|
19
|
+
export type V1ShapeSubscribeOptions = {
|
|
20
|
+
/**
|
|
21
|
+
* Closes the subscription when aborted; cancellation settles `done`.
|
|
22
|
+
*/
|
|
23
|
+
signal?: AbortSignal | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Runs after validated responses and freshness changes; throwing rejects `done` unless already closed or aborted.
|
|
26
|
+
*/
|
|
27
|
+
onUpdate?: ((subscription: V1ShapeSubscription) => void) | undefined;
|
|
28
|
+
};
|
|
29
|
+
export type V1ShapeDocument = {
|
|
30
|
+
readonly version: string;
|
|
31
|
+
readonly document: JsonObject;
|
|
32
|
+
};
|
|
33
|
+
import type { V1Transport } from "./transport.js";
|
|
34
|
+
import type { V1Filter } from "./filter.js";
|
|
35
|
+
import type { JsonObject } from "./json.js";
|
package/types/v1/shapes.d.ts
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
* @returns {string}
|
|
5
5
|
*/
|
|
6
6
|
export function requireShapeOffset(value: unknown): string;
|
|
7
|
+
/** @param {unknown} value @returns {string} */
|
|
8
|
+
export function requireShapeHandle(value: unknown): string;
|
|
7
9
|
/** @param {V1ShapeRequest} request @returns {URLSearchParams} */
|
|
8
10
|
export function encodeShapeRequest(request: V1ShapeRequest): URLSearchParams;
|
|
9
11
|
/** @param {JsonValue | undefined} value @param {Headers} headers @returns {V1ShapePage} */
|
|
@@ -42,12 +44,12 @@ export type V1ShapeRequest = {
|
|
|
42
44
|
};
|
|
43
45
|
export type V1ShapeOp = {
|
|
44
46
|
readonly op: "upsert";
|
|
45
|
-
readonly id:
|
|
47
|
+
readonly id: string;
|
|
46
48
|
readonly version: string;
|
|
47
49
|
readonly document: JsonObject;
|
|
48
50
|
} | {
|
|
49
51
|
readonly op: "delete";
|
|
50
|
-
readonly id:
|
|
52
|
+
readonly id: string;
|
|
51
53
|
};
|
|
52
54
|
export type V1ShapeChange = {
|
|
53
55
|
readonly offset: string;
|
|
@@ -71,6 +73,18 @@ export type V1ShapePage = {
|
|
|
71
73
|
*/
|
|
72
74
|
cursor: string | undefined;
|
|
73
75
|
etag: string | undefined;
|
|
76
|
+
/**
|
|
77
|
+
* Free-read protocol coverage (feed sequence, not write offset).
|
|
78
|
+
*/
|
|
79
|
+
coveredOffset?: string | undefined;
|
|
80
|
+
/**
|
|
81
|
+
* Free-read materialization position.
|
|
82
|
+
*/
|
|
83
|
+
valuesAt?: string | undefined;
|
|
84
|
+
/**
|
|
85
|
+
* Opaque free-read resume token.
|
|
86
|
+
*/
|
|
87
|
+
cursorResume?: string | undefined;
|
|
74
88
|
};
|
|
75
89
|
import type { JsonValue } from "./json.js";
|
|
76
90
|
import type { V1Transport } from "./transport.js";
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runs the producer's read-only SQL subset; it never converts a legacy SQL builder.
|
|
3
|
+
* @param {V1Transport} transport
|
|
4
|
+
* @param {string} database
|
|
5
|
+
* @param {string} sql
|
|
6
|
+
* @param {V1RequestOptions} [options]
|
|
7
|
+
* @returns {Promise<V1SqlResult>}
|
|
8
|
+
*/
|
|
9
|
+
export function runSql(transport: V1Transport, database: string, sql: string, options?: V1RequestOptions): Promise<V1SqlResult>;
|
|
10
|
+
/**
|
|
11
|
+
* Check reports invalid SQL in a successful body; explain reports a producer HTTP error.
|
|
12
|
+
* @param {V1Transport} transport
|
|
13
|
+
* @param {string} database
|
|
14
|
+
* @param {string} sql
|
|
15
|
+
* @param {V1RequestOptions} [options]
|
|
16
|
+
* @param {"checkSql" | "explainSql"} [operation]
|
|
17
|
+
* @returns {Promise<V1SqlCheck>}
|
|
18
|
+
*/
|
|
19
|
+
export function checkSql(transport: V1Transport, database: string, sql: string, options?: V1RequestOptions, operation?: "checkSql" | "explainSql"): Promise<V1SqlCheck>;
|
|
20
|
+
export type V1SqlRow = {
|
|
21
|
+
readonly id: string;
|
|
22
|
+
readonly value: JsonObject;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* SQL returns one bounded result, without a pagination cursor.
|
|
26
|
+
*/
|
|
27
|
+
export type V1SqlResult = {
|
|
28
|
+
readonly matched: number;
|
|
29
|
+
readonly truncated: boolean;
|
|
30
|
+
readonly rows: readonly V1SqlRow[];
|
|
31
|
+
};
|
|
32
|
+
export type V1SqlIndexSuggestion = {
|
|
33
|
+
readonly field: string;
|
|
34
|
+
readonly reason: string;
|
|
35
|
+
};
|
|
36
|
+
export type V1SqlCheck = {
|
|
37
|
+
readonly ok: boolean;
|
|
38
|
+
readonly error: string | null;
|
|
39
|
+
readonly collection: string | null;
|
|
40
|
+
readonly hasLimit: boolean;
|
|
41
|
+
readonly plan: readonly string[];
|
|
42
|
+
readonly indexes: readonly string[];
|
|
43
|
+
readonly suggestions: readonly V1SqlIndexSuggestion[];
|
|
44
|
+
};
|
|
45
|
+
import type { V1Transport } from "./transport.js";
|
|
46
|
+
import type { V1RequestOptions } from "./terrabase-v1.js";
|
|
47
|
+
import type { JsonObject } from "./json.js";
|