@terrascale/sdk 0.0.2 → 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 +43 -0
- package/README.md +193 -56
- package/package.json +14 -5
- package/sdk-public-v1-route-manifest.json +81 -0
- package/sdk-v1-route-manifest.json +8996 -1697
- package/src/database-codec.js +21 -26
- package/src/database-types.js +11 -11
- package/src/database-view.js +6 -6
- package/src/http.js +13 -48
- package/src/ids.js +22 -0
- package/src/index.js +77 -2
- package/src/local/better-auth.js +17 -6
- package/src/local/environment.js +0 -1
- package/src/local/index.js +2 -2
- package/src/local/legacy-client.js +5 -5
- package/src/local/router.js +12 -12
- package/src/local/store.js +29 -28
- package/src/local/test-environment.js +3 -2
- package/src/postgres.js +5 -4
- package/src/react/core.js +2 -2
- package/src/ts-auth-ids.js +122 -0
- package/src/ts-auth.js +75 -77
- 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 +20 -8
- package/src/v1/errors.js +23 -3
- package/src/v1/ids.js +9 -59
- 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 +36 -11
- 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 +15 -10
- package/src/v1/sql.js +98 -0
- package/src/v1/system.js +80 -0
- package/src/v1/terrabase-v1.js +192 -33
- package/src/v1/transport.js +80 -34
- package/src/v1/usage.js +101 -0
- package/types/database-codec.d.ts +1 -6
- package/types/database-types.d.ts +11 -11
- package/types/http.d.ts +2 -8
- package/types/ids.d.ts +10 -0
- package/types/index.d.ts +70 -1
- package/types/local/environment.d.ts +1 -1
- package/types/local/store.d.ts +10 -0
- package/types/local/test-environment.d.ts +2 -2
- package/types/postgres.d.ts +4 -4
- package/types/ts-auth-ids.d.ts +14 -0
- package/types/ts-auth.d.ts +99 -101
- 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 +17 -4
- package/types/v1/errors.d.ts +16 -1
- package/types/v1/ids.d.ts +4 -16
- 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 +14 -0
- package/types/v1/sql.d.ts +47 -0
- package/types/v1/system.d.ts +85 -0
- package/types/v1/terrabase-v1.d.ts +116 -7
- package/types/v1/transport.d.ts +27 -10
- 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
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/** Backups and explicit point-in-time restore sources for one database. */
|
|
2
|
+
export class V1Backups {
|
|
3
|
+
/** @param {V1Transport} transport @param {string} database */
|
|
4
|
+
constructor(transport: V1Transport, database: string);
|
|
5
|
+
/** @param {V1RequestOptions} [options] @returns {Promise<V1Backup>} */
|
|
6
|
+
create(options?: V1RequestOptions): Promise<V1Backup>;
|
|
7
|
+
/** @param {import("./catalog.js").V1DatabaseListRequest} [request] @param {V1RequestOptions} [options] @returns {Promise<V1BackupPage>} */
|
|
8
|
+
list(request?: import("./catalog.js").V1DatabaseListRequest, options?: V1RequestOptions): Promise<V1BackupPage>;
|
|
9
|
+
/** @param {string} id @param {{readonly name?: string | null}} [request] @param {V1RequestOptions} [options] @returns {Promise<V1RestoredDatabase>} */
|
|
10
|
+
restore(id: string, request?: {
|
|
11
|
+
readonly name?: string | null;
|
|
12
|
+
}, options?: V1RequestOptions): Promise<V1RestoredDatabase>;
|
|
13
|
+
/** @param {V1RequestOptions} [options] @returns {Promise<V1BackupPolicy>} */
|
|
14
|
+
getPolicy(options?: V1RequestOptions): Promise<V1BackupPolicy>;
|
|
15
|
+
/** @param {V1BackupPolicyRequest} request @param {V1RequestOptions} [options] @returns {Promise<V1BackupPolicy>} */
|
|
16
|
+
setPolicy(request: V1BackupPolicyRequest, options?: V1RequestOptions): Promise<V1BackupPolicy>;
|
|
17
|
+
/** @param {{readonly destination?: "platform" | "customer"}} [request] @param {V1RequestOptions} [options] @returns {Promise<V1RestoreWindow>} */
|
|
18
|
+
window(request?: {
|
|
19
|
+
readonly destination?: "platform" | "customer";
|
|
20
|
+
}, options?: V1RequestOptions): Promise<V1RestoreWindow>;
|
|
21
|
+
/** @param {V1PointInTimeRequest} request @param {V1RequestOptions} [options] @returns {Promise<V1PointInTimePlan>} */
|
|
22
|
+
plan(request: V1PointInTimeRequest, options?: V1RequestOptions): Promise<V1PointInTimePlan>;
|
|
23
|
+
/** @param {V1PointInTimeRestoreRequest} request @param {V1RequestOptions} [options] @returns {Promise<V1RestoredDatabase>} */
|
|
24
|
+
restorePointInTime(request: V1PointInTimeRestoreRequest, options?: V1RequestOptions): Promise<V1RestoredDatabase>;
|
|
25
|
+
#private;
|
|
26
|
+
}
|
|
27
|
+
/** Write-only destination credentials are sent only to the configured API, never retained in the client. */
|
|
28
|
+
export class V1BackupDestinationClient {
|
|
29
|
+
/** @param {V1Transport} transport */
|
|
30
|
+
constructor(transport: V1Transport);
|
|
31
|
+
/** @param {V1RequestOptions} [options] @returns {Promise<V1BackupDestination>} */
|
|
32
|
+
get(options?: V1RequestOptions): Promise<V1BackupDestination>;
|
|
33
|
+
/** @param {V1BackupDestinationRequest} request @param {V1RequestOptions} [options] @returns {Promise<V1BackupDestination>} */
|
|
34
|
+
set(request: V1BackupDestinationRequest, options?: V1RequestOptions): Promise<V1BackupDestination>;
|
|
35
|
+
/** @param {V1RequestOptions} [options] @returns {Promise<void>} */
|
|
36
|
+
delete(options?: V1RequestOptions): Promise<void>;
|
|
37
|
+
#private;
|
|
38
|
+
}
|
|
39
|
+
export type V1Backup = ReturnType<typeof backup>;
|
|
40
|
+
export type V1BackupPage = ReturnType<typeof backupPage>;
|
|
41
|
+
export type V1BackupPolicy = ReturnType<typeof policy>;
|
|
42
|
+
export type V1RestoreWindow = ReturnType<typeof window>;
|
|
43
|
+
export type V1PointInTimePlan = ReturnType<typeof plan>;
|
|
44
|
+
export type V1RestoredDatabase = ReturnType<typeof restored>;
|
|
45
|
+
export type V1BackupDestination = ReturnType<typeof destination>;
|
|
46
|
+
export type V1BackupPolicyRequest = {
|
|
47
|
+
readonly fullBackupCron?: string | null;
|
|
48
|
+
readonly retentionDays?: number | null;
|
|
49
|
+
readonly disabled?: boolean | null;
|
|
50
|
+
};
|
|
51
|
+
export type V1PointInTimeRequest = {
|
|
52
|
+
readonly pointInTime: string;
|
|
53
|
+
readonly destination?: "platform" | "customer" | null;
|
|
54
|
+
};
|
|
55
|
+
export type V1PointInTimeRestoreRequest = V1PointInTimeRequest & {
|
|
56
|
+
readonly name?: string | null;
|
|
57
|
+
};
|
|
58
|
+
export type V1BackupDestinationRequest = {
|
|
59
|
+
readonly endpoint: string;
|
|
60
|
+
readonly region: string;
|
|
61
|
+
readonly bucket: string;
|
|
62
|
+
readonly accessKeyId: string;
|
|
63
|
+
readonly secretKey: string;
|
|
64
|
+
readonly mode: "both" | "customer";
|
|
65
|
+
};
|
|
66
|
+
import type { V1RequestOptions } from "./terrabase-v1.js";
|
|
67
|
+
import type { V1Transport } from "./transport.js";
|
|
68
|
+
/** @import { V1Transport } from "./transport.js" */
|
|
69
|
+
/** @import { V1RequestOptions } from "./terrabase-v1.js" */
|
|
70
|
+
declare const backup: import("./management-decode.js").Decoder<Readonly<{
|
|
71
|
+
id: string;
|
|
72
|
+
databaseId: string;
|
|
73
|
+
status: string;
|
|
74
|
+
trigger: string;
|
|
75
|
+
sizeBytes: number | import("./json.js").ExactDecimal;
|
|
76
|
+
createdAt: string;
|
|
77
|
+
}>>;
|
|
78
|
+
declare const backupPage: import("./management-decode.js").Decoder<Readonly<{
|
|
79
|
+
items: readonly Readonly<{
|
|
80
|
+
id: string;
|
|
81
|
+
databaseId: string;
|
|
82
|
+
status: string;
|
|
83
|
+
trigger: string;
|
|
84
|
+
sizeBytes: number | import("./json.js").ExactDecimal;
|
|
85
|
+
createdAt: string;
|
|
86
|
+
}>[];
|
|
87
|
+
next: string | null;
|
|
88
|
+
}>>;
|
|
89
|
+
declare const policy: import("./management-decode.js").Decoder<Readonly<{
|
|
90
|
+
fullBackupCron: string | null;
|
|
91
|
+
retentionDays: number | import("./json.js").ExactDecimal;
|
|
92
|
+
disabled: boolean;
|
|
93
|
+
updatedAt: string | null;
|
|
94
|
+
}>>;
|
|
95
|
+
declare const window: import("./management-decode.js").Decoder<Readonly<{
|
|
96
|
+
earliest: string;
|
|
97
|
+
latest: string;
|
|
98
|
+
}>>;
|
|
99
|
+
declare const plan: import("./management-decode.js").Decoder<Readonly<{
|
|
100
|
+
window: Readonly<{
|
|
101
|
+
earliest: string;
|
|
102
|
+
latest: string;
|
|
103
|
+
}>;
|
|
104
|
+
pointInTime: string;
|
|
105
|
+
snapshotAt: string;
|
|
106
|
+
latestSegmentAt: string | null;
|
|
107
|
+
segmentCount: number | import("./json.js").ExactDecimal;
|
|
108
|
+
historyCheck: string;
|
|
109
|
+
}>>;
|
|
110
|
+
declare const restored: import("./management-decode.js").Decoder<Readonly<{
|
|
111
|
+
id: string;
|
|
112
|
+
projectId: string;
|
|
113
|
+
name: string;
|
|
114
|
+
branchedFrom: string | null;
|
|
115
|
+
createdAt: string;
|
|
116
|
+
homeRegion: string | null | undefined;
|
|
117
|
+
replicaRegions: readonly string[] | null | undefined;
|
|
118
|
+
placementVersion: number | import("./json.js").ExactDecimal | undefined;
|
|
119
|
+
replicas: readonly string[];
|
|
120
|
+
}>>;
|
|
121
|
+
declare const destination: import("./management-decode.js").Decoder<Readonly<{
|
|
122
|
+
endpoint: string;
|
|
123
|
+
region: string;
|
|
124
|
+
bucket: string;
|
|
125
|
+
mode: string;
|
|
126
|
+
updatedAt: string;
|
|
127
|
+
}>>;
|
|
128
|
+
export {};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/** @param {V1Transport} transport @param {Readonly<Record<string, string>>} params @param {V1RequestOptions} [options] @returns {Promise<V1CollectionSchema>} */
|
|
2
|
+
export function getCollectionSchema(transport: V1Transport, params: Readonly<Record<string, string>>, options?: V1RequestOptions): Promise<V1CollectionSchema>;
|
|
3
|
+
/** @param {V1Transport} transport @param {Readonly<Record<string, string>>} params @param {boolean | JsonInputObject} schema @param {V1RequestOptions} [options] @returns {Promise<V1CollectionSchema>} */
|
|
4
|
+
export function putCollectionSchema(transport: V1Transport, params: Readonly<Record<string, string>>, schema: boolean | JsonInputObject, options?: V1RequestOptions): Promise<V1CollectionSchema>;
|
|
5
|
+
/** @param {V1Transport} transport @param {Readonly<Record<string, string>>} params @param {V1RequestOptions} [options] @returns {Promise<V1CollectionSchema>} */
|
|
6
|
+
export function deleteCollectionSchema(transport: V1Transport, params: Readonly<Record<string, string>>, options?: V1RequestOptions): Promise<V1CollectionSchema>;
|
|
7
|
+
/** Public database catalog operations, bound to the transport's authorized project. */
|
|
8
|
+
export class V1Databases {
|
|
9
|
+
/** @param {V1Transport} transport */
|
|
10
|
+
constructor(transport: V1Transport);
|
|
11
|
+
/** @param {V1DatabaseCreateRequest} request @param {V1RequestOptions} [options] @returns {Promise<V1ManagedDatabase>} */
|
|
12
|
+
create(request: V1DatabaseCreateRequest, options?: V1RequestOptions): Promise<V1ManagedDatabase>;
|
|
13
|
+
/** @param {V1DatabaseListRequest} [request] @param {V1RequestOptions} [options] @returns {Promise<V1DatabasePage>} */
|
|
14
|
+
list(request?: V1DatabaseListRequest, options?: V1RequestOptions): Promise<V1DatabasePage>;
|
|
15
|
+
/** @param {string} name @param {V1RequestOptions} [options] @returns {Promise<V1ManagedDatabase>} */
|
|
16
|
+
get(name: string, options?: V1RequestOptions): Promise<V1ManagedDatabase>;
|
|
17
|
+
/** @param {string} name @param {V1DatabaseUpdateRequest} request @param {V1RequestOptions} [options] @returns {Promise<V1ManagedDatabase>} */
|
|
18
|
+
update(name: string, request: V1DatabaseUpdateRequest, options?: V1RequestOptions): Promise<V1ManagedDatabase>;
|
|
19
|
+
/** @param {string} name @param {V1RequestOptions} [options] @returns {Promise<void>} */
|
|
20
|
+
delete(name: string, options?: V1RequestOptions): Promise<void>;
|
|
21
|
+
/** @param {string} name @param {V1DatabaseBranchRequest} request @param {V1RequestOptions} [options] @returns {Promise<V1ManagedDatabase>} */
|
|
22
|
+
branch(name: string, request: V1DatabaseBranchRequest, options?: V1RequestOptions): Promise<V1ManagedDatabase>;
|
|
23
|
+
#private;
|
|
24
|
+
}
|
|
25
|
+
export type V1ManagedDatabase = {
|
|
26
|
+
/**
|
|
27
|
+
* Canonical database ULID.
|
|
28
|
+
*/
|
|
29
|
+
id: string;
|
|
30
|
+
/**
|
|
31
|
+
* Canonical owning-project ULID.
|
|
32
|
+
*/
|
|
33
|
+
projectId: string;
|
|
34
|
+
/**
|
|
35
|
+
* Database name used in data routes.
|
|
36
|
+
*/
|
|
37
|
+
name: string;
|
|
38
|
+
/**
|
|
39
|
+
* Source database ULID, or null.
|
|
40
|
+
*/
|
|
41
|
+
branchedFrom: string | null;
|
|
42
|
+
/**
|
|
43
|
+
* ISO date-time returned by the producer.
|
|
44
|
+
*/
|
|
45
|
+
createdAt: string;
|
|
46
|
+
/**
|
|
47
|
+
* Serving region.
|
|
48
|
+
*/
|
|
49
|
+
region: string;
|
|
50
|
+
/**
|
|
51
|
+
* Management region.
|
|
52
|
+
*/
|
|
53
|
+
homeRegion: string;
|
|
54
|
+
/**
|
|
55
|
+
* Other serving regions; empty when allRegions is true.
|
|
56
|
+
*/
|
|
57
|
+
replicaRegions: readonly string[];
|
|
58
|
+
/**
|
|
59
|
+
* True when a full copy is served in every serving region, including later ones.
|
|
60
|
+
*/
|
|
61
|
+
allRegions: boolean;
|
|
62
|
+
};
|
|
63
|
+
export type V1DatabaseCreateRequest = {
|
|
64
|
+
readonly name: string;
|
|
65
|
+
readonly homeRegion?: string | null | undefined;
|
|
66
|
+
readonly replicaRegions?: readonly string[] | null | undefined;
|
|
67
|
+
readonly allRegions?: boolean | undefined;
|
|
68
|
+
};
|
|
69
|
+
export type V1DatabaseUpdateRequest = {
|
|
70
|
+
readonly replicaRegions?: readonly string[] | undefined;
|
|
71
|
+
readonly allRegions?: true | undefined;
|
|
72
|
+
readonly homeRegion?: string | null | undefined;
|
|
73
|
+
};
|
|
74
|
+
export type V1DatabaseBranchRequest = {
|
|
75
|
+
readonly name: string;
|
|
76
|
+
};
|
|
77
|
+
export type V1DatabaseListRequest = {
|
|
78
|
+
readonly after?: string | undefined;
|
|
79
|
+
readonly limit?: number | undefined;
|
|
80
|
+
};
|
|
81
|
+
export type V1DatabasePage = {
|
|
82
|
+
readonly items: readonly V1ManagedDatabase[];
|
|
83
|
+
readonly next: string | null;
|
|
84
|
+
};
|
|
85
|
+
export type V1CollectionSchema = {
|
|
86
|
+
readonly schema: JsonObject | boolean | null;
|
|
87
|
+
readonly dialect?: string | null | undefined;
|
|
88
|
+
};
|
|
89
|
+
import type { V1Transport } from "./transport.js";
|
|
90
|
+
import type { V1RequestOptions } from "./terrabase-v1.js";
|
|
91
|
+
import type { JsonInputObject } from "./json.js";
|
|
92
|
+
import type { JsonObject } from "./json.js";
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reconnects only a normally completed, valid stream, with the latest issued cursor.
|
|
3
|
+
* Denials, terminal errors, malformed data and lost connections are returned to the caller.
|
|
4
|
+
* @param {V1Transport} transport
|
|
5
|
+
* @param {string} database
|
|
6
|
+
* @param {V1ChangeStreamRequest} [request]
|
|
7
|
+
* @param {AbortSignal | undefined} [signal]
|
|
8
|
+
* @returns {AsyncGenerator<V1DatabaseChange | V1DatabaseChangeCursor, void, undefined>}
|
|
9
|
+
*/
|
|
10
|
+
export function streamChanges(transport: V1Transport, database: string, request?: V1ChangeStreamRequest, signal?: AbortSignal | undefined): AsyncGenerator<V1DatabaseChange | V1DatabaseChangeCursor, void, undefined>;
|
|
11
|
+
/**
|
|
12
|
+
* Cursors are opaque and must be resumed with the identical collection filter.
|
|
13
|
+
*/
|
|
14
|
+
export type V1ChangeStreamRequest = {
|
|
15
|
+
/**
|
|
16
|
+
* An issued cursor, or `now`; omitted starts at retention.
|
|
17
|
+
*/
|
|
18
|
+
cursor?: string | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* One to 64 collection names.
|
|
21
|
+
*/
|
|
22
|
+
collections?: readonly string[] | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Overrides cursor, as the producer's Last-Event-ID header.
|
|
25
|
+
*/
|
|
26
|
+
lastEventId?: string | undefined;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* At-least-once delivery: callers deduplicate by origin, version, collection and id.
|
|
30
|
+
* The document is its current serving value, including null, rather than a historical value.
|
|
31
|
+
* Only the last change of an origin/version carries a resumable cursor.
|
|
32
|
+
*/
|
|
33
|
+
export type V1DatabaseChange = {
|
|
34
|
+
readonly type: "change";
|
|
35
|
+
readonly cursor: string | undefined;
|
|
36
|
+
readonly collection: string;
|
|
37
|
+
readonly id: string;
|
|
38
|
+
readonly op: "upsert" | "delete";
|
|
39
|
+
readonly version: string;
|
|
40
|
+
readonly origin: string;
|
|
41
|
+
readonly document: JsonObject | null;
|
|
42
|
+
};
|
|
43
|
+
export type V1DatabaseChangeCursor = {
|
|
44
|
+
readonly type: "cursor";
|
|
45
|
+
readonly cursor: string;
|
|
46
|
+
};
|
|
47
|
+
export type WireEvent = {
|
|
48
|
+
type: string | undefined;
|
|
49
|
+
id: string | undefined;
|
|
50
|
+
data: string;
|
|
51
|
+
};
|
|
52
|
+
import type { V1Transport } from "./transport.js";
|
|
53
|
+
import type { JsonObject } from "./json.js";
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/** @typedef {ReturnType<typeof schema>} V1InferredSchema */
|
|
2
|
+
/** @typedef {ReturnType<typeof collections>} V1DatabaseSchema */
|
|
3
|
+
/** @typedef {ReturnType<typeof unique>} V1UniqueSchema */
|
|
4
|
+
/** @typedef {ReturnType<typeof shapes>} V1QueryShapes */
|
|
5
|
+
/** @typedef {"none" | "lowercase" | "trim_lowercase"} V1Normalization */
|
|
6
|
+
/** @typedef {{ readonly fields?: readonly { readonly name: string; readonly unique?: boolean; readonly normalization?: V1Normalization | null }[] | null; readonly indexes?: readonly { readonly name: string; readonly fields: readonly string[]; readonly unique?: boolean; readonly normalization?: V1Normalization | null }[] | null }} V1UniqueSchemaRequest */
|
|
7
|
+
/** Inferred collection fields, declared uniqueness, and observed query statistics. */
|
|
8
|
+
export class V1DatabaseSchemaClient {
|
|
9
|
+
/** @param {V1Transport} transport @param {string} database */
|
|
10
|
+
constructor(transport: V1Transport, database: string);
|
|
11
|
+
/** @param {V1RequestOptions} [options] @returns {Promise<V1DatabaseSchema>} */
|
|
12
|
+
list(options?: V1RequestOptions): Promise<V1DatabaseSchema>;
|
|
13
|
+
/** @param {string} collection @param {V1RequestOptions} [options] @returns {Promise<V1InferredSchema>} */
|
|
14
|
+
infer(collection: string, options?: V1RequestOptions): Promise<V1InferredSchema>;
|
|
15
|
+
/** @param {string} collection @param {V1UniqueSchemaRequest} request @param {V1RequestOptions} [options] @returns {Promise<V1UniqueSchema>} */
|
|
16
|
+
declare(collection: string, request: V1UniqueSchemaRequest, options?: V1RequestOptions): Promise<V1UniqueSchema>;
|
|
17
|
+
/** @param {V1RequestOptions} [options] @returns {Promise<V1QueryShapes>} */
|
|
18
|
+
queryShapes(options?: V1RequestOptions): Promise<V1QueryShapes>;
|
|
19
|
+
#private;
|
|
20
|
+
}
|
|
21
|
+
export type V1InferredSchema = ReturnType<typeof schema>;
|
|
22
|
+
export type V1DatabaseSchema = ReturnType<typeof collections>;
|
|
23
|
+
export type V1UniqueSchema = ReturnType<typeof unique>;
|
|
24
|
+
export type V1QueryShapes = ReturnType<typeof shapes>;
|
|
25
|
+
export type V1Normalization = "none" | "lowercase" | "trim_lowercase";
|
|
26
|
+
export type V1UniqueSchemaRequest = {
|
|
27
|
+
readonly fields?: readonly {
|
|
28
|
+
readonly name: string;
|
|
29
|
+
readonly unique?: boolean;
|
|
30
|
+
readonly normalization?: V1Normalization | null;
|
|
31
|
+
}[] | null;
|
|
32
|
+
readonly indexes?: readonly {
|
|
33
|
+
readonly name: string;
|
|
34
|
+
readonly fields: readonly string[];
|
|
35
|
+
readonly unique?: boolean;
|
|
36
|
+
readonly normalization?: V1Normalization | null;
|
|
37
|
+
}[] | null;
|
|
38
|
+
};
|
|
39
|
+
import type { V1RequestOptions } from "./terrabase-v1.js";
|
|
40
|
+
import type { V1Transport } from "./transport.js";
|
|
41
|
+
declare const schema: import("./management-decode.js").Decoder<Readonly<{
|
|
42
|
+
collection: string;
|
|
43
|
+
documents: number | import("./json.js").ExactDecimal;
|
|
44
|
+
sampledDocuments: number | import("./json.js").ExactDecimal;
|
|
45
|
+
fields: readonly Readonly<{
|
|
46
|
+
path: string;
|
|
47
|
+
present: number | import("./json.js").ExactDecimal;
|
|
48
|
+
types: Readonly<Record<string, number | import("./json.js").ExactDecimal>>;
|
|
49
|
+
}>[];
|
|
50
|
+
uniqueConstraints: readonly Readonly<{
|
|
51
|
+
name: string;
|
|
52
|
+
fields: readonly string[];
|
|
53
|
+
normalization: string;
|
|
54
|
+
}>[] | null | undefined;
|
|
55
|
+
}>>;
|
|
56
|
+
declare const collections: import("./management-decode.js").Decoder<Readonly<{
|
|
57
|
+
items: readonly Readonly<{
|
|
58
|
+
name: string;
|
|
59
|
+
documents: number | import("./json.js").ExactDecimal;
|
|
60
|
+
bytes: number | import("./json.js").ExactDecimal;
|
|
61
|
+
}>[];
|
|
62
|
+
}>>;
|
|
63
|
+
declare const unique: import("./management-decode.js").Decoder<Readonly<{
|
|
64
|
+
constraints: readonly Readonly<{
|
|
65
|
+
name: string;
|
|
66
|
+
fields: readonly string[];
|
|
67
|
+
normalization: string;
|
|
68
|
+
}>[];
|
|
69
|
+
}>>;
|
|
70
|
+
declare const shapes: import("./management-decode.js").Decoder<Readonly<{
|
|
71
|
+
items: readonly Readonly<{
|
|
72
|
+
id: string;
|
|
73
|
+
collection: string;
|
|
74
|
+
shape: string;
|
|
75
|
+
queries: number | import("./json.js").ExactDecimal;
|
|
76
|
+
totalLatencyMs: number | import("./json.js").ExactDecimal;
|
|
77
|
+
maxLatencyMs: number | import("./json.js").ExactDecimal;
|
|
78
|
+
rowsScanned: number | import("./json.js").ExactDecimal;
|
|
79
|
+
lastSeenAt: string;
|
|
80
|
+
}>[];
|
|
81
|
+
}>>;
|
|
82
|
+
export {};
|
package/types/v1/decode.d.ts
CHANGED
|
@@ -4,21 +4,22 @@
|
|
|
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 {string} id
|
|
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
|
|
11
|
-
* @property {readonly JsonValue[]} [siblings]
|
|
11
|
+
* @property {readonly JsonValue[]} [siblings] Live versions and tombstones on a causal conflict.
|
|
12
12
|
*/
|
|
13
13
|
/**
|
|
14
14
|
* The result of a document write.
|
|
15
15
|
* @typedef {object} V1WriteResult
|
|
16
|
-
* @property {string} id
|
|
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
|
|
@@ -31,6 +32,8 @@ export function malformed(what: string): never;
|
|
|
31
32
|
* @returns {JsonObject}
|
|
32
33
|
*/
|
|
33
34
|
export function object(value: JsonValue | undefined, what: string): JsonObject;
|
|
35
|
+
/** @param {JsonValue | undefined} value @returns {JsonObject} */
|
|
36
|
+
export function documentObject(value: JsonValue | undefined): JsonObject;
|
|
34
37
|
/**
|
|
35
38
|
* @param {JsonValue | undefined} value
|
|
36
39
|
* @param {string} what
|
|
@@ -83,12 +86,15 @@ export type V1Durability = "local_durable" | (string & {});
|
|
|
83
86
|
* Unknown future states pass through.
|
|
84
87
|
*/
|
|
85
88
|
export type V1Document = {
|
|
89
|
+
/**
|
|
90
|
+
* Caller-supplied key or server-generated ULID.
|
|
91
|
+
*/
|
|
86
92
|
id: string;
|
|
87
93
|
version: string;
|
|
88
94
|
state: "value" | "conflict" | (string & {});
|
|
89
95
|
document: JsonObject;
|
|
90
96
|
/**
|
|
91
|
-
*
|
|
97
|
+
* Live versions and tombstones on a causal conflict.
|
|
92
98
|
*/
|
|
93
99
|
siblings?: readonly JsonValue[];
|
|
94
100
|
};
|
|
@@ -96,6 +102,9 @@ export type V1Document = {
|
|
|
96
102
|
* The result of a document write.
|
|
97
103
|
*/
|
|
98
104
|
export type V1WriteResult = {
|
|
105
|
+
/**
|
|
106
|
+
* Caller-supplied key or server-generated ULID.
|
|
107
|
+
*/
|
|
99
108
|
id: string;
|
|
100
109
|
/**
|
|
101
110
|
* For a delete, the tombstone's version.
|
|
@@ -114,6 +123,10 @@ export type V1WriteResult = {
|
|
|
114
123
|
* The Location header of a POST create.
|
|
115
124
|
*/
|
|
116
125
|
location: string | undefined;
|
|
126
|
+
/**
|
|
127
|
+
* Stored document returned by PATCH.
|
|
128
|
+
*/
|
|
129
|
+
document?: JsonObject;
|
|
117
130
|
};
|
|
118
131
|
import type { JsonValue } from "./json.js";
|
|
119
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
|
@@ -5,15 +5,12 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export function requireName(kind: "database" | "collection", name: unknown): string;
|
|
7
7
|
/**
|
|
8
|
-
* The
|
|
8
|
+
* The catalog project ID is a canonical ULID; database and collection routes use names.
|
|
9
9
|
* @param {unknown} project
|
|
10
|
-
* @returns {
|
|
11
|
-
*/
|
|
12
|
-
export function requireProject(project: unknown): string;
|
|
13
|
-
/**
|
|
14
|
-
* @param {unknown} id
|
|
15
|
-
* @returns {string}
|
|
10
|
+
* @returns {import("../ids.js").EntityId}
|
|
16
11
|
*/
|
|
12
|
+
export function requireProject(project: unknown): import("../ids.js").EntityId;
|
|
13
|
+
/** A caller-supplied key is not a generated entity ID. @param {unknown} id @returns {string} */
|
|
17
14
|
export function requireDocumentId(id: unknown): string;
|
|
18
15
|
/**
|
|
19
16
|
* @param {unknown} version
|
|
@@ -33,12 +30,3 @@ export function parseU64(value: unknown): bigint | undefined;
|
|
|
33
30
|
* @returns {bigint}
|
|
34
31
|
*/
|
|
35
32
|
export function requireU64(value: unknown, what: string): bigint;
|
|
36
|
-
/**
|
|
37
|
-
* The deterministic document ID for a natural key in a collection:
|
|
38
|
-
* `uuidv5(uuidv5(NAMESPACE_URL, "terrabase:collection:" + collection), key)`.
|
|
39
|
-
* Uses WebCrypto, so it works in Node.js, browsers and workers.
|
|
40
|
-
* @param {string} collection
|
|
41
|
-
* @param {string} key
|
|
42
|
-
* @returns {Promise<string>}
|
|
43
|
-
*/
|
|
44
|
-
export function documentIdFor(collection: string, key: string): Promise<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 {};
|