@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.
Files changed (64) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +177 -67
  3. package/package.json +10 -4
  4. package/sdk-public-v1-route-manifest.json +81 -0
  5. package/sdk-v1-route-manifest.json +896 -15
  6. package/src/http.js +3 -48
  7. package/src/index.js +75 -1
  8. package/src/local/environment.js +0 -1
  9. package/src/ts-auth.js +1 -5
  10. package/src/v1/backups.js +111 -0
  11. package/src/v1/catalog.js +210 -0
  12. package/src/v1/changes.js +225 -0
  13. package/src/v1/database-schema.js +45 -0
  14. package/src/v1/decode.js +5 -5
  15. package/src/v1/errors.js +23 -3
  16. package/src/v1/ids.js +5 -2
  17. package/src/v1/imports.js +72 -0
  18. package/src/v1/indexes.js +76 -0
  19. package/src/v1/json.js +4 -3
  20. package/src/v1/management-decode.js +24 -0
  21. package/src/v1/management-routes.js +67 -0
  22. package/src/v1/management-validation.js +25 -0
  23. package/src/v1/routes.js +32 -7
  24. package/src/v1/saved-queries.js +58 -0
  25. package/src/v1/shape-crypto.js +125 -0
  26. package/src/v1/shape-manifest.js +31 -0
  27. package/src/v1/shape-reader.js +212 -0
  28. package/src/v1/shape-subscription.js +208 -0
  29. package/src/v1/shapes.js +11 -5
  30. package/src/v1/sql.js +98 -0
  31. package/src/v1/system.js +80 -0
  32. package/src/v1/terrabase-v1.js +178 -27
  33. package/src/v1/transport.js +75 -31
  34. package/src/v1/usage.js +101 -0
  35. package/types/http.d.ts +2 -8
  36. package/types/index.d.ts +68 -0
  37. package/types/local/environment.d.ts +1 -1
  38. package/types/ts-auth.d.ts +0 -2
  39. package/types/v1/backups.d.ts +128 -0
  40. package/types/v1/catalog.d.ts +92 -0
  41. package/types/v1/changes.d.ts +53 -0
  42. package/types/v1/database-schema.d.ts +82 -0
  43. package/types/v1/decode.d.ts +15 -4
  44. package/types/v1/errors.d.ts +16 -1
  45. package/types/v1/ids.d.ts +2 -2
  46. package/types/v1/imports.d.ts +132 -0
  47. package/types/v1/indexes.d.ts +75 -0
  48. package/types/v1/management-decode.d.ts +15 -0
  49. package/types/v1/management-routes.d.ts +3 -0
  50. package/types/v1/management-validation.d.ts +8 -0
  51. package/types/v1/routes.d.ts +5 -2
  52. package/types/v1/saved-queries.d.ts +33 -0
  53. package/types/v1/shape-crypto.d.ts +39 -0
  54. package/types/v1/shape-manifest.d.ts +28 -0
  55. package/types/v1/shape-reader.d.ts +45 -0
  56. package/types/v1/shape-subscription.d.ts +35 -0
  57. package/types/v1/shapes.d.ts +16 -2
  58. package/types/v1/sql.d.ts +47 -0
  59. package/types/v1/system.d.ts +85 -0
  60. package/types/v1/terrabase-v1.d.ts +113 -4
  61. package/types/v1/transport.d.ts +25 -8
  62. package/types/v1/usage.d.ts +171 -0
  63. package/src/ts-auth-discovery.js +0 -207
  64. package/types/ts-auth-discovery.d.ts +0 -19
@@ -0,0 +1,101 @@
1
+ import { requireId } from "../ids.js";
2
+ import { requireName } from "./ids.js";
3
+ import { dictionary, flag, list, nullable, numeric, record, text } from "./management-decode.js";
4
+ import { members } from "./management-validation.js";
5
+ /** @import { V1Transport } from "./transport.js" */
6
+ /** @import { V1RequestOptions } from "./terrabase-v1.js" */
7
+ const period = record({ from: text, to: text, granularity: text, reads: numeric, writes: numeric });
8
+ const series = list(record({ start: text, reads: numeric, writes: numeric }));
9
+ const databaseUsage = record({ databaseId: requireId, storageBytes: numeric, logicalBytes: numeric, collections: numeric,
10
+ documents: numeric, reads: numeric, writes: numeric, period, series });
11
+ const projectUsage = record({ projectId: requireId, databases: numeric, storageBytes: numeric, logicalBytes: numeric,
12
+ documents: numeric, reads: numeric, writes: numeric, period, series, items: list(databaseUsage) });
13
+ const bandwidth = record({ bytesSent: numeric, bytesReceived: numeric });
14
+ const directedBandwidth = list(record({ sourceRegion: text, destinationRegion: text, kind: text, bytesSent: numeric, bytesReceived: numeric }));
15
+ const latency = record({ p50Ms: nullable(numeric), p95Ms: nullable(numeric), p99Ms: nullable(numeric) });
16
+ const analytics = record({ projectId: requireId, range: text, from: text, to: text, bucketSeconds: numeric,
17
+ items: list(record({ databaseId: requireId, databaseName: text, region: text,
18
+ series: list(record({ start: text, requests: dictionary(numeric), operations: dictionary(numeric), errors: numeric,
19
+ latency, storageBytes: nullable(numeric), clientBandwidth: bandwidth, replicationBandwidth: bandwidth })) })) });
20
+ const replication = record({ projectId: requireId, range: text, from: text, to: text, bucketSeconds: numeric,
21
+ items: list(record({ databaseId: requireId, databaseName: text, region: text, status: text, replicatedOps: numeric,
22
+ lagMs: nullable(numeric), divergence: nullable(flag), convergenceMs: nullable(numeric), lastApplied: nullable(text),
23
+ bandwidth: directedBandwidth, series: list(record({ start: text, replicatedOps: numeric, bandwidth: directedBandwidth })) })) });
24
+ /** @typedef {ReturnType<typeof databaseUsage>} V1DatabaseUsage */
25
+ /** @typedef {ReturnType<typeof projectUsage>} V1ProjectUsage */
26
+ /** @typedef {ReturnType<typeof analytics>} V1Analytics */
27
+ /** @typedef {ReturnType<typeof replication>} V1Replication */
28
+ /** @typedef {{ readonly granularity?: "hour" | "day"; readonly from?: string; readonly to?: string }} V1UsageRequest */
29
+ /** @typedef {{ readonly range?: "1h" | "24h" | "7d" | "30d"; readonly database?: string; readonly region?: string }} V1AnalyticsRequest */
30
+ /** @param {V1UsageRequest} request */
31
+ function usageQuery(request) {
32
+ members(request, ["granularity", "from", "to"]);
33
+ const query = new URLSearchParams();
34
+ if (request.granularity !== undefined) {
35
+ if (!["hour", "day"].includes(request.granularity)) throw new TypeError("granularity must be hour or day.");
36
+ query.set("granularity", request.granularity);
37
+ }
38
+ for (const name of /** @type {const} */ (["from", "to"])) {
39
+ const value = request[name];
40
+ if (value === undefined) continue;
41
+ if (typeof value !== "string" || !/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,7})?(?:Z|[+-]\d{2}:\d{2})$/u.test(value) || !Number.isFinite(Date.parse(value)))
42
+ throw new TypeError("from and to must be RFC 3339 instants.");
43
+ query.set(name, value);
44
+ }
45
+ return query;
46
+ }
47
+ /** @param {V1AnalyticsRequest} request @param {boolean} project */
48
+ function analyticsQuery(request, project) {
49
+ members(request, project ? ["range", "database", "region"] : ["range", "region"]);
50
+ const query = new URLSearchParams();
51
+ if (request.range !== undefined) {
52
+ if (!["1h", "24h", "7d", "30d"].includes(request.range)) throw new TypeError("Invalid analytics range.");
53
+ query.set("range", request.range);
54
+ }
55
+ if (request.database !== undefined) query.set("database", requireId(request.database));
56
+ if (request.region !== undefined) {
57
+ if (typeof request.region !== "string" || !/^[a-z][a-z0-9-]{0,62}$/u.test(request.region)) throw new TypeError("Invalid region.");
58
+ query.set("region", request.region);
59
+ }
60
+ return query;
61
+ }
62
+
63
+ /** Project and database usage retain the producer's separate response envelopes. */
64
+ export class V1ProjectUsageClient {
65
+ /** @type {V1Transport} */
66
+ #transport;
67
+ /** @param {V1Transport} transport */
68
+ constructor(transport) { this.#transport = transport; Object.freeze(this); }
69
+ /** @param {V1UsageRequest} [request] @param {V1RequestOptions} [options] @returns {Promise<V1ProjectUsage>} */
70
+ async usage(request = {}, options = {}) {
71
+ return projectUsage((await this.#transport.call("getProjectUsage", {}, { query: usageQuery(request), signal: options.signal })).value);
72
+ }
73
+ /** @param {V1AnalyticsRequest} [request] @param {V1RequestOptions} [options] @returns {Promise<V1Analytics>} */
74
+ async analytics(request = {}, options = {}) {
75
+ return analytics((await this.#transport.call("getProjectAnalytics", {}, { query: analyticsQuery(request, true), signal: options.signal })).value);
76
+ }
77
+ /** @param {V1AnalyticsRequest} [request] @param {V1RequestOptions} [options] @returns {Promise<V1Replication>} */
78
+ async replication(request = {}, options = {}) {
79
+ return replication((await this.#transport.call("getProjectReplication", {}, { query: analyticsQuery(request, true), signal: options.signal })).value);
80
+ }
81
+ }
82
+ export class V1DatabaseUsageClient {
83
+ /** @type {V1Transport} */
84
+ #transport;
85
+ /** @type {{database: string}} */
86
+ #params;
87
+ /** @param {V1Transport} transport @param {string} database */
88
+ constructor(transport, database) { this.#transport = transport; this.#params = { database: requireName("database", database) }; Object.freeze(this); }
89
+ /** @param {V1UsageRequest} [request] @param {V1RequestOptions} [options] @returns {Promise<V1DatabaseUsage>} */
90
+ async usage(request = {}, options = {}) {
91
+ return databaseUsage((await this.#transport.call("getDatabaseUsage", this.#params, { query: usageQuery(request), signal: options.signal })).value);
92
+ }
93
+ /** @param {Omit<V1AnalyticsRequest, "database">} [request] @param {V1RequestOptions} [options] @returns {Promise<V1Analytics>} */
94
+ async analytics(request = {}, options = {}) {
95
+ return analytics((await this.#transport.call("getDatabaseAnalytics", this.#params, { query: analyticsQuery(request, false), signal: options.signal })).value);
96
+ }
97
+ /** @param {Omit<V1AnalyticsRequest, "database">} [request] @param {V1RequestOptions} [options] @returns {Promise<V1Replication>} */
98
+ async replication(request = {}, options = {}) {
99
+ return replication((await this.#transport.call("getDatabaseReplication", this.#params, { query: analyticsQuery(request, false), signal: options.signal })).value);
100
+ }
101
+ }
package/types/http.d.ts CHANGED
@@ -1,12 +1,7 @@
1
1
  /** Private transport for the named hosted identity and OIDC operations. */
2
2
  export class TsAuthHttp {
3
- /**
4
- * @param {TsAuthRuntimeConfig} config
5
- * @param {{ readonly authReverseProxy?: boolean }} [options]
6
- */
7
- constructor(config: TsAuthRuntimeConfig, options?: {
8
- readonly authReverseProxy?: boolean;
9
- });
3
+ /** @param {TsAuthRuntimeConfig} config */
4
+ constructor(config: TsAuthRuntimeConfig);
10
5
  /**
11
6
  * @readonly
12
7
  * @type {ResolvedTsAuthRuntimeConfig}
@@ -39,7 +34,6 @@ export type TsAuthRequest<TBody> = {
39
34
  readonly formBody?: URLSearchParams | string | undefined;
40
35
  readonly userinfoAccessToken?: string | undefined;
41
36
  readonly resourceIntrospectionBasic?: string | undefined;
42
- readonly issuer?: string | undefined;
43
37
  readonly signal?: AbortSignal | undefined;
44
38
  };
45
39
  import type { ResolvedTsAuthRuntimeConfig } from "./config.js";
package/types/index.d.ts CHANGED
@@ -1,6 +1,15 @@
1
1
  export { v1Filter } from "./v1/filter.js";
2
+ export { V1ShapeSubscription } from "./v1/shape-subscription.js";
2
3
  export { ExactDecimal } from "./v1/json.js";
3
4
  export { staticBaseUrlResolver } from "./v1/transport.js";
5
+ export { V1Databases } from "./v1/catalog.js";
6
+ export { V1SavedQueries } from "./v1/saved-queries.js";
7
+ export { V1DatabaseSchemaClient } from "./v1/database-schema.js";
8
+ export { V1Indexes } from "./v1/indexes.js";
9
+ export { V1Imports } from "./v1/imports.js";
10
+ export type V1ShapeSubscribeOptions = import("./v1/shape-subscription.js").V1ShapeSubscribeOptions;
11
+ export type V1ShapeDocument = import("./v1/shape-subscription.js").V1ShapeDocument;
12
+ export type V1SealedShapePosition = import("./v1/shape-reader.js").V1SealedShapePosition;
4
13
  export type EntityId = import("./ids.js").EntityId;
5
14
  export type TerraBaseV1ClientConfig = import("./v1/transport.js").TerraBaseV1ClientConfig;
6
15
  export type V1RequestOptions = import("./v1/terrabase-v1.js").V1RequestOptions;
@@ -31,6 +40,9 @@ export type V1JsonInputObject = import("./v1/json.js").JsonInputObject;
31
40
  export type V1ShapeRequest = import("./v1/shapes.js").V1ShapeRequest;
32
41
  export type V1ShapeChange = import("./v1/shapes.js").V1ShapeChange;
33
42
  export type V1ShapeOp = import("./v1/shapes.js").V1ShapeOp;
43
+ export type V1SavedQuery = import("./v1/saved-queries.js").V1SavedQuery;
44
+ export type V1SavedQueryRequest = import("./v1/saved-queries.js").V1SavedQueryRequest;
45
+ export type V1SavedQueryPage = import("./v1/saved-queries.js").V1SavedQueryPage;
34
46
  export type TerraBaseClientConfig = import("./v1/transport.js").TerraBaseV1ClientConfig;
35
47
  export type V1EndpointContext = import("./v1/transport.js").V1EndpointContext;
36
48
  export type V1EndpointResolver = import("./v1/transport.js").V1EndpointResolver;
@@ -38,7 +50,63 @@ export type V1CollectionInfo = import("./v1/terrabase-v1.js").V1CollectionInfo;
38
50
  export type V1CollectionPage = import("./v1/terrabase-v1.js").V1CollectionPage;
39
51
  export type V1CollectionListOptions = import("./v1/terrabase-v1.js").V1CollectionListOptions;
40
52
  export type V1ShapePage = import("./v1/shapes.js").V1ShapePage;
53
+ export type V1SqlRow = import("./v1/sql.js").V1SqlRow;
54
+ export type V1SqlResult = import("./v1/sql.js").V1SqlResult;
55
+ export type V1SqlIndexSuggestion = import("./v1/sql.js").V1SqlIndexSuggestion;
56
+ export type V1SqlCheck = import("./v1/sql.js").V1SqlCheck;
57
+ export type V1ChangeStreamRequest = import("./v1/changes.js").V1ChangeStreamRequest;
58
+ export type V1DatabaseChange = import("./v1/changes.js").V1DatabaseChange;
59
+ export type V1DatabaseChangeCursor = import("./v1/changes.js").V1DatabaseChangeCursor;
60
+ export type V1ManagedDatabase = import("./v1/catalog.js").V1ManagedDatabase;
61
+ export type V1DatabaseCreateRequest = import("./v1/catalog.js").V1DatabaseCreateRequest;
62
+ export type V1DatabaseUpdateRequest = import("./v1/catalog.js").V1DatabaseUpdateRequest;
63
+ export type V1DatabaseBranchRequest = import("./v1/catalog.js").V1DatabaseBranchRequest;
64
+ export type V1DatabaseListRequest = import("./v1/catalog.js").V1DatabaseListRequest;
65
+ export type V1DatabasePage = import("./v1/catalog.js").V1DatabasePage;
66
+ export type V1CollectionSchema = import("./v1/catalog.js").V1CollectionSchema;
67
+ export type V1InferredSchema = import("./v1/database-schema.js").V1InferredSchema;
68
+ export type V1DatabaseSchema = import("./v1/database-schema.js").V1DatabaseSchema;
69
+ export type V1UniqueSchema = import("./v1/database-schema.js").V1UniqueSchema;
70
+ export type V1UniqueSchemaRequest = import("./v1/database-schema.js").V1UniqueSchemaRequest;
71
+ export type V1QueryShapes = import("./v1/database-schema.js").V1QueryShapes;
72
+ export type V1Index = import("./v1/indexes.js").V1Index;
73
+ export type V1IndexList = import("./v1/indexes.js").V1IndexList;
74
+ export type V1AutoIndexPolicy = import("./v1/indexes.js").V1AutoIndexPolicy;
75
+ export type V1IndexRecommendations = import("./v1/indexes.js").V1IndexRecommendations;
76
+ export type V1AppliedIndexRecommendation = import("./v1/indexes.js").V1AppliedIndexRecommendation;
77
+ export type V1CreateIndexRequest = import("./v1/indexes.js").V1CreateIndexRequest;
78
+ export type V1DatabaseUsage = import("./v1/usage.js").V1DatabaseUsage;
79
+ export type V1ProjectUsage = import("./v1/usage.js").V1ProjectUsage;
80
+ export type V1Analytics = import("./v1/usage.js").V1Analytics;
81
+ export type V1Replication = import("./v1/usage.js").V1Replication;
82
+ export type V1UsageRequest = import("./v1/usage.js").V1UsageRequest;
83
+ export type V1AnalyticsRequest = import("./v1/usage.js").V1AnalyticsRequest;
84
+ export type V1Backup = import("./v1/backups.js").V1Backup;
85
+ export type V1BackupPage = import("./v1/backups.js").V1BackupPage;
86
+ export type V1BackupPolicy = import("./v1/backups.js").V1BackupPolicy;
87
+ export type V1RestoreWindow = import("./v1/backups.js").V1RestoreWindow;
88
+ export type V1PointInTimePlan = import("./v1/backups.js").V1PointInTimePlan;
89
+ export type V1RestoredDatabase = import("./v1/backups.js").V1RestoredDatabase;
90
+ export type V1BackupDestination = import("./v1/backups.js").V1BackupDestination;
91
+ export type V1BackupPolicyRequest = import("./v1/backups.js").V1BackupPolicyRequest;
92
+ export type V1PointInTimeRequest = import("./v1/backups.js").V1PointInTimeRequest;
93
+ export type V1PointInTimeRestoreRequest = import("./v1/backups.js").V1PointInTimeRestoreRequest;
94
+ export type V1BackupDestinationRequest = import("./v1/backups.js").V1BackupDestinationRequest;
95
+ export type V1ImportJob = import("./v1/imports.js").V1ImportJob;
96
+ export type V1ImportOptions = import("./v1/imports.js").V1ImportOptions;
97
+ export type V1CreateImportRequest = import("./v1/imports.js").V1CreateImportRequest;
98
+ export type TerraBaseSystemClientConfig = import("./v1/system.js").TerraBaseSystemClientConfig;
99
+ export type V1ProbeStatus = import("./v1/system.js").V1ProbeStatus;
100
+ export type V1ReplicationHealth = import("./v1/system.js").V1ReplicationHealth;
101
+ export type V1PlatformDatabases = import("./v1/system.js").V1PlatformDatabases;
102
+ export type V1ShapeManifest = import("./v1/shape-manifest.js").V1ShapeManifest;
103
+ export type V1ShapeManifestRequest = import("./v1/shape-manifest.js").V1ShapeManifestRequest;
104
+ export type V1ShapeKeyRequest = import("./v1/shape-reader.js").V1ShapeKeyRequest;
105
+ export type V1ShapeKey = import("./v1/shape-reader.js").V1ShapeKey;
41
106
  export { createTerraBaseV1Client as createTerraBaseClient, TerraBaseV1Client as TerraBaseClient, createTerraBaseV1Client, TerraBaseV1Client, V1Database, V1Collection, V1Collections, V1Transaction } from "./v1/terrabase-v1.js";
42
107
  export { terraScaleReleaseBlockers, TerraScaleCapabilityUnavailableError } from "./management-contracts.js";
43
108
  export { TerraBaseV1Error, V1PreconditionFailedError, V1InvalidKeyError, V1ForbiddenScopeError, V1NotFoundError, V1ErrorCode, isTerraBaseV1Error } from "./v1/errors.js";
44
109
  export { generateId, isValidId, requireId } from "./ids.js";
110
+ export { V1ProjectUsageClient, V1DatabaseUsageClient } from "./v1/usage.js";
111
+ export { V1Backups, V1BackupDestinationClient } from "./v1/backups.js";
112
+ export { createTerraBaseSystemClient, V1Health, V1Platform } from "./v1/system.js";
@@ -3,7 +3,7 @@
3
3
  * @returns {void}
4
4
  */
5
5
  export function assertLocalSqliteEnvironment(environment?: Readonly<Record<string, string | undefined>>): void;
6
- export const localSqlitePresenceIndicators: readonly ["CI", "CONTINUOUS_INTEGRATION", "GITHUB_ACTIONS", "GITLAB_CI", "FORGEJO_ACTIONS", "GITEA_ACTIONS", "TF_BUILD", "BUILDKITE", "CIRCLECI", "JENKINS_URL", "TEAMCITY_VERSION", "VERCEL", "NETLIFY", "CF_PAGES", "RENDER", "FLY_APP_NAME", "K_SERVICE", "CLOUD_RUN_JOB", "KUBERNETES_SERVICE_HOST", "AWS_LAMBDA_FUNCTION_NAME", "AWS_EXECUTION_ENV", "ECS_CONTAINER_METADATA_URI", "ECS_CONTAINER_METADATA_URI_V4", "WEBSITE_INSTANCE_ID", "WEBSITE_SITE_NAME", "FUNCTIONS_WORKER_RUNTIME", "DYNO", "HEROKU_APP_NAME", "RAILWAY_ENVIRONMENT", "RAILWAY_SERVICE_ID", "NOMAD_ALLOC_ID", "TERRASCALE_DEPLOYMENT", "TERRASCALE_QUALIFICATION"];
6
+ export const localSqlitePresenceIndicators: readonly ["CI", "CONTINUOUS_INTEGRATION", "GITHUB_ACTIONS", "GITLAB_CI", "FORGEJO_ACTIONS", "GITEA_ACTIONS", "TF_BUILD", "BUILDKITE", "CIRCLECI", "JENKINS_URL", "TEAMCITY_VERSION", "VERCEL", "NETLIFY", "CF_PAGES", "RENDER", "K_SERVICE", "CLOUD_RUN_JOB", "KUBERNETES_SERVICE_HOST", "AWS_LAMBDA_FUNCTION_NAME", "AWS_EXECUTION_ENV", "ECS_CONTAINER_METADATA_URI", "ECS_CONTAINER_METADATA_URI_V4", "WEBSITE_INSTANCE_ID", "WEBSITE_SITE_NAME", "FUNCTIONS_WORKER_RUNTIME", "DYNO", "HEROKU_APP_NAME", "RAILWAY_ENVIRONMENT", "RAILWAY_SERVICE_ID", "NOMAD_ALLOC_ID", "TERRASCALE_DEPLOYMENT", "TERRASCALE_QUALIFICATION"];
7
7
  /**
8
8
  * Explicit opt-in for a hosted development environment.
9
9
  *
@@ -38,7 +38,6 @@ export function verifyTsAuthWebhookWithTolerance(signingSecret: string, timestam
38
38
  * @typedef {Omit<TsAuthRuntimeConfig, "apiBaseUrl"> & {
39
39
  * readonly apiBaseUrl: string; // The ts-auth deployment's public origin; there is no default.
40
40
  * readonly instanceSlug: string; // The instance the `sk_` key belongs to; it prefixes every route.
41
- * readonly useReverseProxy?: boolean; // Route public auth calls through the reverse proxy instead of regional discovery.
42
41
  * }} TsAuthClientConfig
43
42
  */
44
43
  /**
@@ -1335,7 +1334,6 @@ export type TsAuthRuntimeConfig = import("./config.js").TsAuthRuntimeConfig;
1335
1334
  export type TsAuthClientConfig = Omit<TsAuthRuntimeConfig, "apiBaseUrl"> & {
1336
1335
  readonly apiBaseUrl: string;
1337
1336
  readonly instanceSlug: string;
1338
- readonly useReverseProxy?: boolean;
1339
1337
  };
1340
1338
  export type TsAuthRequestOptions = {
1341
1339
  readonly signal?: AbortSignal | undefined;
@@ -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 {};