@terrascale/sdk 0.0.5 → 0.0.7

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/types/index.d.ts CHANGED
@@ -1,12 +1,15 @@
1
1
  export { v1Filter } from "./v1/filter.js";
2
2
  export { V1ShapeSubscription } from "./v1/shape-subscription.js";
3
+ export { indexedDbShapeReplica } from "./v1/shape-replica.js";
3
4
  export { ExactDecimal } from "./v1/json.js";
4
5
  export { staticBaseUrlResolver } from "./v1/transport.js";
5
6
  export { V1Databases } from "./v1/catalog.js";
6
7
  export { V1SavedQueries } from "./v1/saved-queries.js";
7
8
  export { V1DatabaseSchemaClient } from "./v1/database-schema.js";
8
9
  export { V1Indexes } from "./v1/indexes.js";
10
+ export { V1ChangeWebhooks } from "./v1/change-webhooks.js";
9
11
  export { V1Imports } from "./v1/imports.js";
12
+ export type V1ShapeReplicaStore = import("./v1/shape-subscription.js").V1ShapeReplicaStore;
10
13
  export type V1ShapeSubscribeOptions = import("./v1/shape-subscription.js").V1ShapeSubscribeOptions;
11
14
  export type V1ShapeDocument = import("./v1/shape-subscription.js").V1ShapeDocument;
12
15
  export type V1SealedShapePosition = import("./v1/shape-reader.js").V1SealedShapePosition;
@@ -22,6 +25,10 @@ export type V1PatchOp = import("./v1/terrabase-v1.js").V1PatchOp;
22
25
  export type V1Patch = import("./v1/terrabase-v1.js").V1Patch;
23
26
  export type V1SortKey = import("./v1/terrabase-v1.js").V1SortKey;
24
27
  export type V1NearSortKey = import("./v1/terrabase-v1.js").V1NearSortKey;
28
+ export type V1GeoNearSortKey = import("./v1/terrabase-v1.js").V1GeoNearSortKey;
29
+ export type V1Aggregate = import("./v1/terrabase-v1.js").V1Aggregate;
30
+ export type V1Group = import("./v1/terrabase-v1.js").V1Group;
31
+ export type V1ScoreSortKey = import("./v1/terrabase-v1.js").V1ScoreSortKey;
25
32
  export type V1Query = import("./v1/terrabase-v1.js").V1Query;
26
33
  export type V1Count = import("./v1/terrabase-v1.js").V1Count;
27
34
  export type V1QueryPage = import("./v1/terrabase-v1.js").V1QueryPage;
@@ -35,6 +42,8 @@ export type V1Durability = import("./v1/decode.js").V1Durability;
35
42
  export type V1Filter = import("./v1/filter.js").V1Filter;
36
43
  export type V1Path = import("./v1/filter.js").V1Path;
37
44
  export type V1Scalar = import("./v1/filter.js").V1Scalar;
45
+ export type V1GeoCircle = import("./v1/filter.js").V1GeoCircle;
46
+ export type V1GeoBox = import("./v1/filter.js").V1GeoBox;
38
47
  export type V1JsonValue = import("./v1/json.js").JsonValue;
39
48
  export type V1JsonObject = import("./v1/json.js").JsonObject;
40
49
  export type V1JsonInput = import("./v1/json.js").JsonInput;
@@ -56,6 +65,12 @@ export type V1SqlRow = import("./v1/sql.js").V1SqlRow;
56
65
  export type V1SqlResult = import("./v1/sql.js").V1SqlResult;
57
66
  export type V1SqlIndexSuggestion = import("./v1/sql.js").V1SqlIndexSuggestion;
58
67
  export type V1SqlCheck = import("./v1/sql.js").V1SqlCheck;
68
+ export type V1SqlArgument = import("./v1/sql-execute.js").V1SqlArgument;
69
+ export type V1SqlArguments = import("./v1/sql-execute.js").V1SqlArguments;
70
+ export type V1SqlStatement = import("./v1/sql-execute.js").V1SqlStatement;
71
+ export type V1SqlValue = import("./v1/sql-execute.js").V1SqlValue;
72
+ export type V1SqlColumn = import("./v1/sql-execute.js").V1SqlColumn;
73
+ export type V1SqlExecuteResult = import("./v1/sql-execute.js").V1SqlExecuteResult;
59
74
  export type V1ChangeStreamRequest = import("./v1/changes.js").V1ChangeStreamRequest;
60
75
  export type V1DatabaseChange = import("./v1/changes.js").V1DatabaseChange;
61
76
  export type V1DatabaseChangeCursor = import("./v1/changes.js").V1DatabaseChangeCursor;
@@ -75,6 +90,7 @@ export type V1UniqueSchema = import("./v1/database-schema.js").V1UniqueSchema;
75
90
  export type V1UniqueSchemaRequest = import("./v1/database-schema.js").V1UniqueSchemaRequest;
76
91
  export type V1QueryShapes = import("./v1/database-schema.js").V1QueryShapes;
77
92
  export type V1Index = import("./v1/indexes.js").V1Index;
93
+ export type V1IndexKind = import("./v1/indexes.js").V1IndexKind;
78
94
  export type V1IndexList = import("./v1/indexes.js").V1IndexList;
79
95
  export type V1AutoIndexPolicy = import("./v1/indexes.js").V1AutoIndexPolicy;
80
96
  export type V1IndexRecommendations = import("./v1/indexes.js").V1IndexRecommendations;
@@ -86,6 +102,10 @@ export type V1Analytics = import("./v1/usage.js").V1Analytics;
86
102
  export type V1Replication = import("./v1/usage.js").V1Replication;
87
103
  export type V1UsageRequest = import("./v1/usage.js").V1UsageRequest;
88
104
  export type V1AnalyticsRequest = import("./v1/usage.js").V1AnalyticsRequest;
105
+ export type V1ChangeWebhook = import("./v1/change-webhooks.js").V1ChangeWebhook;
106
+ export type V1CreatedChangeWebhook = import("./v1/change-webhooks.js").V1CreatedChangeWebhook;
107
+ export type V1ChangeWebhookDelivery = import("./v1/change-webhooks.js").V1ChangeWebhookDelivery;
108
+ export type V1ChangeWebhookListRequest = import("./v1/change-webhooks.js").V1ChangeWebhookListRequest;
89
109
  export type V1Backup = import("./v1/backups.js").V1Backup;
90
110
  export type V1BackupPage = import("./v1/backups.js").V1BackupPage;
91
111
  export type V1BackupPolicy = import("./v1/backups.js").V1BackupPolicy;
@@ -110,7 +130,7 @@ export type V1ShapeKeyRequest = import("./v1/shape-reader.js").V1ShapeKeyRequest
110
130
  export type V1ShapeKey = import("./v1/shape-reader.js").V1ShapeKey;
111
131
  export { createTerraBaseV1Client as createTerraBaseClient, TerraBaseV1Client as TerraBaseClient, createTerraBaseV1Client, TerraBaseV1Client, V1Database, V1Collection, V1Collections, V1Transaction } from "./v1/terrabase-v1.js";
112
132
  export { terraScaleReleaseBlockers, TerraScaleCapabilityUnavailableError } from "./management-contracts.js";
113
- export { TerraBaseV1Error, V1PreconditionFailedError, V1InvalidKeyError, V1ForbiddenScopeError, V1NotFoundError, V1ErrorCode, isTerraBaseV1Error } from "./v1/errors.js";
133
+ export { TerraBaseV1Error, V1PreconditionFailedError, V1InvalidKeyError, V1ForbiddenScopeError, V1NotFoundError, SqlError, V1ErrorCode, isTerraBaseV1Error } from "./v1/errors.js";
114
134
  export { generateId, isValidId, requireId } from "./ids.js";
115
135
  export { V1ProjectUsageClient, V1DatabaseUsageClient } from "./v1/usage.js";
116
136
  export { V1Backups, V1BackupDestinationClient } from "./v1/backups.js";
@@ -0,0 +1,59 @@
1
+ /** Collection change webhook registration and sanitized delivery history. Requests are never replayed. */
2
+ export class V1ChangeWebhooks {
3
+ /** @param {V1Transport} transport @param {string} database @param {string} collection */
4
+ constructor(transport: V1Transport, database: string, collection: string);
5
+ /**
6
+ * Registers from the current feed head. Requires documents:read and documents:write.
7
+ * Store secret immediately; it is non-enumerable to keep it out of JSON and ordinary diagnostics.
8
+ * @param {{ readonly url: string }} request @param {V1RequestOptions} [options] @returns {Promise<V1CreatedChangeWebhook>}
9
+ */
10
+ create(request: {
11
+ readonly url: string;
12
+ }, options?: V1RequestOptions): Promise<V1CreatedChangeWebhook>;
13
+ /**
14
+ * Requires documents:read. Ascending IDs; continue with the final ID until an empty array. No secrets.
15
+ * @param {V1ChangeWebhookListRequest} [request] @param {V1RequestOptions} [options] @returns {Promise<readonly V1ChangeWebhook[]>}
16
+ */
17
+ list(request?: V1ChangeWebhookListRequest, options?: V1RequestOptions): Promise<readonly V1ChangeWebhook[]>;
18
+ /**
19
+ * Requires documents:read and documents:write. An in-flight delivery may still complete. Unknown ID returns 404.
20
+ * @param {string} id @param {V1RequestOptions} [options] @returns {Promise<void>}
21
+ */
22
+ delete(id: string, options?: V1RequestOptions): Promise<void>;
23
+ /**
24
+ * Requires documents:read. Latest 100 retained records; paginate with the final ID until an empty array.
25
+ * @param {string} id @param {V1ChangeWebhookListRequest} [request] @param {V1RequestOptions} [options] @returns {Promise<readonly V1ChangeWebhookDelivery[]>}
26
+ */
27
+ deliveries(id: string, request?: V1ChangeWebhookListRequest, options?: V1RequestOptions): Promise<readonly V1ChangeWebhookDelivery[]>;
28
+ #private;
29
+ }
30
+ export type V1ChangeWebhook = ReturnType<typeof webhook>;
31
+ export type V1CreatedChangeWebhook = V1ChangeWebhook & {
32
+ readonly secret: string;
33
+ };
34
+ export type V1ChangeWebhookDelivery = ReturnType<typeof deliveries>[number];
35
+ export type V1ChangeWebhookListRequest = {
36
+ readonly after?: string;
37
+ readonly limit?: number;
38
+ };
39
+ import type { V1RequestOptions } from "./terrabase-v1.js";
40
+ import type { V1Transport } from "./transport.js";
41
+ /** @import { V1Transport } from "./transport.js" */
42
+ /** @import { V1RequestOptions } from "./terrabase-v1.js" */
43
+ declare const webhook: import("./management-decode.js").Decoder<Readonly<{
44
+ id: string;
45
+ url: string;
46
+ createdAt: string;
47
+ status: string;
48
+ }>>;
49
+ declare const deliveries: import("./management-decode.js").Decoder<readonly Readonly<{
50
+ id: string;
51
+ createdAt: string;
52
+ status: string;
53
+ attempts: number | import("./json.js").ExactDecimal;
54
+ lastAttemptAt: string | null;
55
+ nextAttemptAt: string | null;
56
+ httpStatus: number | import("./json.js").ExactDecimal | null;
57
+ errorCode: string | null;
58
+ }>[]>;
59
+ export {};
@@ -9,7 +9,8 @@
9
9
  * @property {"value" | "conflict" | (string & {})} state
10
10
  * @property {JsonObject} document
11
11
  * @property {readonly JsonValue[]} [siblings] Live versions and tombstones on a causal conflict.
12
- * @property {number} [distance] Distance to the query vector; present only on `near` query results.
12
+ * @property {number} [distance] Distance to the query vector, or meters to a geo `near` point; present only on `near` query results.
13
+ * @property {number} [score] Full-text relevance score on results sorted by `$score`.
13
14
  */
14
15
  /**
15
16
  * The result of a document write.
@@ -99,9 +100,13 @@ export type V1Document = {
99
100
  */
100
101
  siblings?: readonly JsonValue[];
101
102
  /**
102
- * Distance to the query vector; present only on `near` query results.
103
+ * Distance to the query vector, or meters to a geo `near` point; present only on `near` query results.
103
104
  */
104
105
  distance?: number;
106
+ /**
107
+ * Full-text relevance score on results sorted by `$score`.
108
+ */
109
+ score?: number;
105
110
  };
106
111
  /**
107
112
  * The result of a document write.
@@ -92,6 +92,9 @@ export const V1ErrorCode: Readonly<{
92
92
  internalError: "internal_error";
93
93
  capacity: "capacity";
94
94
  notModified: "not_modified";
95
+ sqlError: "sql_error";
96
+ sqlConflict: "sql_conflict";
97
+ sqlTooLarge: "sql_too_large";
95
98
  }>;
96
99
  /** `412 precondition_failed`: an If-Match, If-None-Match, assert or assert_count failed. */
97
100
  export class V1PreconditionFailedError extends TerraBaseV1Error {
@@ -105,6 +108,21 @@ export class V1ForbiddenScopeError extends TerraBaseV1Error {
105
108
  /** `404 not_found`: absent or deleted; `etag` carries a tombstone version. */
106
109
  export class V1NotFoundError extends TerraBaseV1Error {
107
110
  }
111
+ /**
112
+ * A refused relational SQL statement: `sql_error` (400), `forbidden_scope` (403, writes and DDL need
113
+ * documents:write), `sql_conflict` (409) or `sql_too_large` (413). The whole request rolled back.
114
+ */
115
+ export class SqlError extends TerraBaseV1Error {
116
+ /** @param {TerraBaseV1ErrorInit & { statement: number; sqliteCode?: string | undefined }} init */
117
+ constructor(init: TerraBaseV1ErrorInit & {
118
+ statement: number;
119
+ sqliteCode?: string | undefined;
120
+ });
121
+ /** @type {number} Zero-based index of the failing statement. */
122
+ statement: number;
123
+ /** @type {string | undefined} The SQLite error code, such as `SQLITE_CONSTRAINT_PRIMARYKEY`. */
124
+ sqliteCode: string | undefined;
125
+ }
108
126
  export type TerraBaseV1ErrorInit = {
109
127
  status: number;
110
128
  code: string;
@@ -10,6 +10,14 @@ export function isJsonPointer(pointer: unknown): pointer is string;
10
10
  * @returns {V1Path}
11
11
  */
12
12
  export function requirePath(path: V1Path): V1Path;
13
+ /** @param {V1Filter | null | undefined} filter @returns {number} */
14
+ export function searchCount(filter: V1Filter | null | undefined): number;
15
+ /**
16
+ * @param {unknown} lat
17
+ * @param {unknown} lon
18
+ * @returns {void}
19
+ */
20
+ export function requireGeoPoint(lat: unknown, lon: unknown): void;
13
21
  /**
14
22
  * Validates a filter against the query-v1 grammar (operators, arity, paths,
15
23
  * scalar operands, depth 8 and 256 nodes), so a malformed filter fails locally
@@ -100,6 +108,13 @@ export const v1Filter: Readonly<{
100
108
  * @returns {V1Filter}
101
109
  */
102
110
  prefix: (path: V1Path, prefix: string) => V1Filter;
111
+ /**
112
+ * Full-text search on a document member.
113
+ * @param {V1Path} path
114
+ * @param {string} terms
115
+ * @returns {V1Filter}
116
+ */
117
+ search: (path: V1Path, terms: string) => V1Filter;
103
118
  /**
104
119
  * The value is an array containing the scalar.
105
120
  * @param {V1Path} path
@@ -107,6 +122,20 @@ export const v1Filter: Readonly<{
107
122
  * @returns {V1Filter}
108
123
  */
109
124
  contains: (path: V1Path, value: V1Scalar) => V1Filter;
125
+ /**
126
+ * The `{lat, lon}` object at `path` lies within `meters` of the center (haversine, WGS 84 mean radius).
127
+ * @param {string} path JSON Pointer of a `{lat, lon}` point.
128
+ * @param {V1GeoCircle} circle `meters` is more than 0, at most 20000000.
129
+ * @returns {V1Filter}
130
+ */
131
+ withinRadius: (path: string, circle: V1GeoCircle) => V1Filter;
132
+ /**
133
+ * The `{lat, lon}` object at `path` lies in the box; `west > east` crosses the antimeridian.
134
+ * @param {string} path JSON Pointer of a `{lat, lon}` point.
135
+ * @param {V1GeoBox} box
136
+ * @returns {V1Filter}
137
+ */
138
+ withinBox: (path: string, box: V1GeoBox) => V1Filter;
110
139
  }>;
111
140
  /**
112
141
  * A filter or sort path: an RFC 6901 JSON Pointer or "$id".
@@ -144,5 +173,26 @@ export type V1Filter = {
144
173
  readonly prefix: readonly [V1Path, string];
145
174
  } | {
146
175
  readonly contains: readonly [V1Path, V1Scalar];
176
+ } | {
177
+ readonly within: readonly [string, V1GeoCircle | V1GeoBox];
178
+ } | {
179
+ readonly search: readonly [V1Path, string];
180
+ };
181
+ /**
182
+ * Points within `meters` (more than 0, at most 20000000) of a WGS 84 point, by haversine distance.
183
+ */
184
+ export type V1GeoCircle = {
185
+ readonly lat: number;
186
+ readonly lon: number;
187
+ readonly meters: number;
188
+ };
189
+ /**
190
+ * Points in a latitude/longitude box; `west > east` crosses the antimeridian.
191
+ */
192
+ export type V1GeoBox = {
193
+ readonly south: number;
194
+ readonly west: number;
195
+ readonly north: number;
196
+ readonly east: number;
147
197
  };
148
198
  import { ExactDecimal } from "./json.js";
package/types/v1/ids.d.ts CHANGED
@@ -10,8 +10,10 @@ 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
- /** A caller-supplied key is not a generated entity ID. @param {unknown} id @returns {string} */
13
+ /** Every document id is a canonical ULID. @param {unknown} id @returns {string} */
14
14
  export function requireDocumentId(id: unknown): string;
15
+ /** SQL-backed collections can return non-ULID primary keys. @param {unknown} id @returns {string} */
16
+ export function requireStoredId(id: unknown): string;
15
17
  /**
16
18
  * @param {unknown} version
17
19
  * @returns {string}
@@ -27,10 +27,12 @@ export type V1IndexList = ReturnType<typeof indexes>;
27
27
  export type V1AutoIndexPolicy = ReturnType<typeof policy>;
28
28
  export type V1IndexRecommendations = ReturnType<typeof recommendations>;
29
29
  export type V1AppliedIndexRecommendation = ReturnType<typeof applied>;
30
+ export type V1IndexKind = "btree" | "text";
30
31
  export type V1CreateIndexRequest = {
31
32
  readonly collection: string;
32
33
  readonly fields: readonly string[];
33
34
  readonly name?: string | null;
35
+ readonly kind?: V1IndexKind;
34
36
  };
35
37
  import type { V1RequestOptions } from "./terrabase-v1.js";
36
38
  import type { V1Transport } from "./transport.js";
@@ -41,6 +43,7 @@ declare const index: import("./management-decode.js").Decoder<Readonly<{
41
43
  collection: string;
42
44
  fields: readonly string[];
43
45
  state: string;
46
+ kind: string | undefined;
44
47
  }>>;
45
48
  declare const indexes: import("./management-decode.js").Decoder<Readonly<{
46
49
  items: readonly Readonly<{
@@ -48,6 +51,7 @@ declare const indexes: import("./management-decode.js").Decoder<Readonly<{
48
51
  collection: string;
49
52
  fields: readonly string[];
50
53
  state: string;
54
+ kind: string | undefined;
51
55
  }>[];
52
56
  }>>;
53
57
  declare const policy: import("./management-decode.js").Decoder<Readonly<{
@@ -70,6 +74,7 @@ declare const applied: import("./management-decode.js").Decoder<Readonly<{
70
74
  collection: string;
71
75
  fields: readonly string[];
72
76
  state: string;
77
+ kind: string | undefined;
73
78
  }>;
74
79
  }>>;
75
80
  export {};
@@ -1,3 +1,3 @@
1
1
  /** @type {readonly import("./routes.js").V1Route[]} */
2
2
  export const managementV1Routes: readonly import("./routes.js").V1Route[];
3
- export type ManagementOperation = "getShapeManifest" | "exportDatabase" | "putCollectionTtl" | "getCollectionTtl" | "deleteCollectionTtl" | "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";
3
+ export type ManagementOperation = "getShapeManifest" | "exportDatabase" | "executeSql" | "putCollectionTtl" | "getCollectionTtl" | "deleteCollectionTtl" | "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" | "createChangeWebhook" | "listChangeWebhooks" | "deleteChangeWebhook" | "listChangeWebhookDeliveries";
@@ -0,0 +1,8 @@
1
+ /** @import { V1ShapeReplicaStore } from "./shape-subscription.js" */
2
+ /**
3
+ * A V1ShapeReplicaStore kept in browser IndexedDB, one record per key.
4
+ * @param {string} key Names one subject's shape, e.g. `${userId}/notes/open`; clear it on sign-out.
5
+ * @returns {V1ShapeReplicaStore}
6
+ */
7
+ export function indexedDbShapeReplica(key: string): V1ShapeReplicaStore;
8
+ import type { V1ShapeReplicaStore } from "./shape-subscription.js";
@@ -25,6 +25,21 @@ export type V1ShapeSubscribeOptions = {
25
25
  * Runs after validated responses and freshness changes; throwing rejects `done` unless already closed or aborted.
26
26
  */
27
27
  onUpdate?: ((subscription: V1ShapeSubscription) => void) | undefined;
28
+ /**
29
+ * Keeps the last resumable state for reads across restarts and while offline; writes still go to the server.
30
+ */
31
+ replica?: V1ShapeReplicaStore | undefined;
32
+ };
33
+ /**
34
+ * Holds one subscription's state as exact JSON text, e.g. in IndexedDB or React Native storage. Scope one store
35
+ * to one signed-in subject: the replica holds that subject's authorized documents. A failing store rejects `done`.
36
+ */
37
+ export type V1ShapeReplicaStore = {
38
+ load: () => string | undefined | Promise<string | undefined>;
39
+ /**
40
+ * Receives undefined after must_refetch discards state.
41
+ */
42
+ save: (text: string | undefined) => void | Promise<void>;
28
43
  };
29
44
  export type V1ShapeDocument = {
30
45
  readonly version: string;
@@ -0,0 +1,61 @@
1
+ /** @param {string} sql @param {V1SqlArguments | undefined} args @returns {V1SqlStatement} */
2
+ export function sqlStatement(sql: string, args: V1SqlArguments | undefined): V1SqlStatement;
3
+ /**
4
+ * Runs 1 to 256 statements as one transaction: all commit or none do. BEGIN, COMMIT and ROLLBACK are refused.
5
+ * A refused statement throws SqlError with its index.
6
+ * @param {V1Transport} transport
7
+ * @param {string} database
8
+ * @param {readonly (string | V1SqlStatement)[]} statements
9
+ * @param {V1RequestOptions} [options]
10
+ * @returns {Promise<readonly V1SqlExecuteResult[]>}
11
+ */
12
+ export function executeSql(transport: V1Transport, database: string, statements: readonly (string | V1SqlStatement)[], options?: V1RequestOptions): Promise<readonly V1SqlExecuteResult[]>;
13
+ /**
14
+ * Rows as objects keyed by column name; a later duplicate column name wins.
15
+ * @template [T=Record<string, V1SqlValue>]
16
+ * @param {V1SqlExecuteResult} result
17
+ * @returns {T[]}
18
+ */
19
+ export function sqlRowObjects<T = Record<string, V1SqlValue>>(result: V1SqlExecuteResult): T[];
20
+ /**
21
+ * An argument: null, a finite number, an int64 `bigint` or ExactDecimal, a boolean (stored as 1 or 0) or a string.
22
+ */
23
+ export type V1SqlArgument = null | boolean | number | bigint | ExactDecimal | string;
24
+ /**
25
+ * Positional array, or named values keyed without their `:`, `@` or `$` prefix.
26
+ */
27
+ export type V1SqlArguments = readonly V1SqlArgument[] | Readonly<Record<string, V1SqlArgument>>;
28
+ export type V1SqlStatement = {
29
+ sql: string;
30
+ /**
31
+ * Positional arguments.
32
+ */
33
+ args?: readonly V1SqlArgument[] | undefined;
34
+ /**
35
+ * Named arguments, keys without their prefix.
36
+ */
37
+ named?: Readonly<Record<string, V1SqlArgument>> | undefined;
38
+ };
39
+ /**
40
+ * A result value. Integers beyond 2^53 decode as ExactDecimal, keeping every digit; `BigInt(String(value))` converts one.
41
+ */
42
+ export type V1SqlValue = null | number | ExactDecimal | string;
43
+ /**
44
+ * A column; `decltype` is null for an expression.
45
+ */
46
+ export type V1SqlColumn = {
47
+ readonly name: string;
48
+ readonly decltype: string | null;
49
+ };
50
+ export type V1SqlExecuteResult = {
51
+ columns: readonly V1SqlColumn[];
52
+ /**
53
+ * One value per column.
54
+ */
55
+ rows: readonly (readonly V1SqlValue[])[];
56
+ rowsAffected: number;
57
+ lastInsertRowid: number | ExactDecimal | null;
58
+ };
59
+ import type { V1Transport } from "./transport.js";
60
+ import type { V1RequestOptions } from "./terrabase-v1.js";
61
+ import { ExactDecimal } from "./json.js";
@@ -22,6 +22,8 @@ export class V1Collection {
22
22
  * @param {string} name
23
23
  */
24
24
  constructor(transport: V1Transport, database: string, name: string);
25
+ /** @type {V1ChangeWebhooks} */
26
+ webhooks: V1ChangeWebhooks;
25
27
  /** @type {string} */
26
28
  name: string;
27
29
  /** @type {string} */
@@ -293,6 +295,29 @@ export class V1Database {
293
295
  checkSql(statement: string, options?: V1RequestOptions): Promise<import("./sql.js").V1SqlCheck>;
294
296
  /** @param {string} statement @param {V1RequestOptions} [options] */
295
297
  explainSql(statement: string, options?: V1RequestOptions): Promise<import("./sql.js").V1SqlCheck>;
298
+ /**
299
+ * Runs one relational SQL statement as its own transaction. Reads need documents:read; writes and DDL need documents:write.
300
+ * @param {string} sql
301
+ * @param {import("./sql-execute.js").V1SqlArguments} [args] Positional array, or named values keyed without their prefix.
302
+ * @param {V1RequestOptions} [options]
303
+ * @returns {Promise<import("./sql-execute.js").V1SqlExecuteResult>}
304
+ */
305
+ execute(sql: string, args?: import("./sql-execute.js").V1SqlArguments, options?: V1RequestOptions): Promise<import("./sql-execute.js").V1SqlExecuteResult>;
306
+ /**
307
+ * Runs one statement and returns its rows as objects keyed by column name.
308
+ * @template [T=Record<string, import("./sql-execute.js").V1SqlValue>]
309
+ * @param {string} sql
310
+ * @param {import("./sql-execute.js").V1SqlArguments} [args]
311
+ * @param {V1RequestOptions} [options]
312
+ * @returns {Promise<T[]>}
313
+ */
314
+ query<T = Record<string, import("./sql-execute.js").V1SqlValue>>(sql: string, args?: import("./sql-execute.js").V1SqlArguments, options?: V1RequestOptions): Promise<T[]>;
315
+ /**
316
+ * Runs 1 to 256 statements as one transaction: all commit or none do. A refused statement throws SqlError.
317
+ * @param {readonly (string | import("./sql-execute.js").V1SqlStatement)[]} statements
318
+ * @param {V1RequestOptions} [options]
319
+ */
320
+ batch(statements: readonly (string | import("./sql-execute.js").V1SqlStatement)[], options?: V1RequestOptions): Promise<readonly import("./sql-execute.js").V1SqlExecuteResult[]>;
296
321
  /** @param {import("./changes.js").V1ChangeStreamRequest} [request] @param {V1RequestOptions} [options] */
297
322
  changes(request?: import("./changes.js").V1ChangeStreamRequest, options?: V1RequestOptions): AsyncGenerator<import("./changes.js").V1DatabaseChange | import("./changes.js").V1DatabaseChangeCursor, void, undefined>;
298
323
  /**
@@ -413,7 +438,67 @@ export type V1NearSortKey = {
413
438
  readonly metric?: "cosine" | "l2" | undefined;
414
439
  };
415
440
  };
416
- export type V1SortKey = V1FieldSortKey | V1NearSortKey;
441
+ /**
442
+ * Geo distance sort: meters from a WGS 84 point to each document's `{lat, lon}` object at `path`, nearest first,
443
+ * returned as `distance`. Like the vector `near`, it is the only sort key, limit is at most 100 and there is no cursor.
444
+ */
445
+ export type V1GeoNearSortKey = {
446
+ readonly near: {
447
+ readonly path: string;
448
+ readonly lat: number;
449
+ readonly lon: number;
450
+ };
451
+ };
452
+ /**
453
+ * Relevance order, only sort key with exactly one search predicate.
454
+ */
455
+ export type V1ScoreSortKey = {
456
+ readonly path: "$score";
457
+ readonly order: "desc";
458
+ };
459
+ export type V1SortKey = V1FieldSortKey | V1NearSortKey | V1GeoNearSortKey | V1ScoreSortKey;
460
+ /**
461
+ * Groups matches instead of returning documents. Summaries consider numbers only; at most 16 summary paths in total.
462
+ */
463
+ export type V1Aggregate = {
464
+ /**
465
+ * 0-4 paths; without it every match is one group.
466
+ */
467
+ groupBy?: readonly V1Path[] | undefined;
468
+ /**
469
+ * Distinct JSON Pointers.
470
+ */
471
+ sum?: readonly string[] | undefined;
472
+ /**
473
+ * Distinct JSON Pointers.
474
+ */
475
+ avg?: readonly string[] | undefined;
476
+ /**
477
+ * Distinct JSON Pointers.
478
+ */
479
+ min?: readonly string[] | undefined;
480
+ /**
481
+ * Distinct JSON Pointers.
482
+ */
483
+ max?: readonly string[] | undefined;
484
+ };
485
+ /**
486
+ * One aggregate group. Summaries are keyed by the requested JSON Pointer; `sum` is 0 and the others null without numbers.
487
+ */
488
+ export type V1Group = {
489
+ /**
490
+ * One value per `groupBy` path (missing members group as null).
491
+ */
492
+ key: readonly JsonValue[];
493
+ /**
494
+ * Matching documents in the group (decimal u64).
495
+ */
496
+ count: string;
497
+ sum?: Readonly<Record<string, number | null>> | undefined;
498
+ avg?: Readonly<Record<string, number | null>> | undefined;
499
+ min?: Readonly<Record<string, number | null>> | undefined;
500
+ max?: Readonly<Record<string, number | null>> | undefined;
501
+ };
417
502
  /**
418
503
  * A query-v1 request. Every member is optional.
419
504
  */
@@ -439,6 +524,10 @@ export type V1Query = {
439
524
  * Count every match (first page only).
440
525
  */
441
526
  count?: boolean | undefined;
527
+ /**
528
+ * Answer `groups` instead of items; `limit` bounds the groups. No sort, project, cursor or count.
529
+ */
530
+ aggregate?: V1Aggregate | undefined;
442
531
  };
443
532
  export type V1Count = {
444
533
  readonly value: string;
@@ -451,6 +540,10 @@ export type V1QueryPage = {
451
540
  items: readonly V1Document[];
452
541
  nextCursor: string | null;
453
542
  count: V1Count | undefined;
543
+ /**
544
+ * An aggregate query's groups in key order (`items` is then empty).
545
+ */
546
+ groups: readonly V1Group[] | undefined;
454
547
  };
455
548
  export type V1Precondition = {
456
549
  readonly ifMatch: string;
@@ -483,6 +576,7 @@ export type V1TransactionResult = {
483
576
  };
484
577
  import type { JsonValue } from "./json.js";
485
578
  import type { TerraBaseV1ClientConfig } from "./transport.js";
579
+ import { V1ChangeWebhooks } from "./change-webhooks.js";
486
580
  import type { V1Document } from "./decode.js";
487
581
  import type { JsonInputObject } from "./json.js";
488
582
  import type { V1WriteResult } from "./decode.js";
@@ -23,6 +23,15 @@ export class BodyTransportError extends Error {
23
23
  /** @param {unknown} cause */
24
24
  constructor(cause: unknown);
25
25
  }
26
+ /** A request that failed in transit before any response; the native failure is the cause. */
27
+ export class RequestTransportError extends TypeError {
28
+ /** @param {unknown} cause */
29
+ constructor(cause: unknown);
30
+ }
31
+ /** A browser hid a 307 behind an opaque redirect; only the shape bootstrap may follow it. */
32
+ export class OpaqueRedirectError extends TypeError {
33
+ constructor();
34
+ }
26
35
  /** Internal transport bound to one project credential. */
27
36
  export class V1Transport {
28
37
  /**
@@ -128,11 +137,19 @@ export type V1CallOptions = {
128
137
  * Authenticated shape epoch keys must bypass caches.
129
138
  */
130
139
  cache?: "no-store" | undefined;
140
+ /**
141
+ * Only the shape bootstrap, after a browser hides its 307 behind an opaque redirect.
142
+ */
143
+ redirect?: "follow" | undefined;
131
144
  };
132
145
  export type V1CallResult = {
133
146
  status: number;
134
147
  headers: Headers;
135
148
  value: JsonValue | undefined;
149
+ /**
150
+ * The final URL after a followed redirect.
151
+ */
152
+ redirectedTo?: string | undefined;
136
153
  };
137
154
  import type { V1Operation } from "./routes.js";
138
155
  import type { JsonValue } from "./json.js";