@terrascale/sdk 0.0.4 → 0.0.6

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.
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Streams every live document of a database as NDJSON, in collection then id order, from one read snapshot.
3
+ * A stream that ends inside a line is incomplete and throws; resume with `after` set to the last document received.
4
+ * @param {V1Transport} transport
5
+ * @param {string} database
6
+ * @param {V1ExportOptions} [options]
7
+ * @returns {AsyncGenerator<V1ExportedDocument, void, undefined>}
8
+ */
9
+ export function exportDocuments(transport: V1Transport, database: string, options?: V1ExportOptions): AsyncGenerator<V1ExportedDocument, void, undefined>;
10
+ export type V1ExportedDocument = {
11
+ readonly collection: string;
12
+ readonly id: string;
13
+ readonly document: JsonObject;
14
+ };
15
+ export type V1ExportOptions = {
16
+ /**
17
+ * Resume after this document; the resumed part reads a new snapshot.
18
+ */
19
+ after?: {
20
+ readonly collection: string;
21
+ readonly id: string;
22
+ } | undefined;
23
+ signal?: AbortSignal | undefined;
24
+ };
25
+ import type { V1Transport } from "./transport.js";
26
+ import type { JsonObject } from "./json.js";
@@ -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" | "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";
@@ -9,7 +9,7 @@ export function decodeFreeShapePage(value: import("./json.js").JsonValue | undef
9
9
  */
10
10
  export function readShapePage(transport: V1Transport, params: Readonly<Record<string, string>>, request: V1ShapeRequest, signal: AbortSignal | undefined, ifNoneMatch?: string | undefined): Promise<V1ShapePage>;
11
11
  /**
12
- * Reuse process-memory keys for this handle/epoch/KID; fetch misses without HTTP cache reuse.
12
+ * Reuse keys only for static credentials; callback tokens authorize every decrypt with no-store.
13
13
  * @param {V1Transport} transport @param {Readonly<Record<string,string>>} params
14
14
  * @param {Uint8Array} bytes @param {V1SealedShapePosition} position @param {AbortSignal | undefined} signal
15
15
  * @returns {Promise<V1ShapePage>}
@@ -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} */
@@ -82,6 +84,15 @@ export class V1Collection {
82
84
  putSchema(schema: import("./json.js").JsonInputObject | boolean, options?: V1RequestOptions): Promise<import("./catalog.js").V1CollectionSchema>;
83
85
  /** @param {V1RequestOptions} [options] */
84
86
  deleteSchema(options?: V1RequestOptions): Promise<import("./catalog.js").V1CollectionSchema>;
87
+ /** @param {V1RequestOptions} [options] */
88
+ getTtl(options?: V1RequestOptions): Promise<import("./catalog.js").V1CollectionTtl>;
89
+ /**
90
+ * Documents whose member at `path` holds a past RFC 3339 UTC time are deleted by an hourly sweep (up to about an hour late).
91
+ * @param {string} path JSON Pointer such as `/expiresAt`. @param {V1RequestOptions} [options]
92
+ */
93
+ putTtl(path: string, options?: V1RequestOptions): Promise<import("./catalog.js").V1CollectionTtl>;
94
+ /** @param {V1RequestOptions} [options] */
95
+ deleteTtl(options?: V1RequestOptions): Promise<import("./catalog.js").V1CollectionTtl>;
85
96
  /**
86
97
  * Iterates over every page, following `nextCursor`. `count`
87
98
  * is sent with the first page only.
@@ -284,8 +295,36 @@ export class V1Database {
284
295
  checkSql(statement: string, options?: V1RequestOptions): Promise<import("./sql.js").V1SqlCheck>;
285
296
  /** @param {string} statement @param {V1RequestOptions} [options] */
286
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[]>;
287
321
  /** @param {import("./changes.js").V1ChangeStreamRequest} [request] @param {V1RequestOptions} [options] */
288
322
  changes(request?: import("./changes.js").V1ChangeStreamRequest, options?: V1RequestOptions): AsyncGenerator<import("./changes.js").V1DatabaseChange | import("./changes.js").V1DatabaseChangeCursor, void, undefined>;
323
+ /**
324
+ * Streams every live document as `{ collection, id, document }`, in collection then id order, from one snapshot.
325
+ * @param {import("./export.js").V1ExportOptions} [options]
326
+ */
327
+ export(options?: import("./export.js").V1ExportOptions): AsyncGenerator<import("./export.js").V1ExportedDocument, void, undefined>;
289
328
  #private;
290
329
  }
291
330
  /**
@@ -385,17 +424,28 @@ export type V1Patch = {
385
424
  } | {
386
425
  readonly ops: readonly V1PatchOp[];
387
426
  };
388
- export type V1SortKey = {
427
+ export type V1FieldSortKey = {
389
428
  readonly path: V1Path;
390
429
  readonly order?: "asc" | "desc" | undefined;
391
430
  };
431
+ /**
432
+ * Vector similarity sort, nearest first. It must be the only sort key; limit is at most 100 and there is no cursor.
433
+ */
434
+ export type V1NearSortKey = {
435
+ readonly near: {
436
+ readonly path: V1Path;
437
+ readonly vector: readonly number[];
438
+ readonly metric?: "cosine" | "l2" | undefined;
439
+ };
440
+ };
441
+ export type V1SortKey = V1FieldSortKey | V1NearSortKey;
392
442
  /**
393
443
  * A query-v1 request. Every member is optional.
394
444
  */
395
445
  export type V1Query = {
396
446
  filter?: V1Filter | null | undefined;
397
447
  /**
398
- * At most 4 keys; results are finally ordered by `$id`.
448
+ * At most 4 keys, or one `near` key; results are finally ordered by `$id`.
399
449
  */
400
450
  sort?: readonly V1SortKey[] | undefined;
401
451
  /**
@@ -458,6 +508,7 @@ export type V1TransactionResult = {
458
508
  };
459
509
  import type { JsonValue } from "./json.js";
460
510
  import type { TerraBaseV1ClientConfig } from "./transport.js";
511
+ import { V1ChangeWebhooks } from "./change-webhooks.js";
461
512
  import type { V1Document } from "./decode.js";
462
513
  import type { JsonInputObject } from "./json.js";
463
514
  import type { V1WriteResult } from "./decode.js";
@@ -36,6 +36,8 @@ export class V1Transport {
36
36
  project?: undefined;
37
37
  endpointResolver?: undefined;
38
38
  }));
39
+ /** Internal credential lifetime metadata; never exposes the bearer value. */
40
+ get hasTokenProvider(): boolean;
39
41
  /**
40
42
  * @param {V1Operation} operation
41
43
  * @param {Readonly<Record<string, string>>} params
@@ -74,12 +76,12 @@ export class V1Transport {
74
76
  */
75
77
  call(operation: V1Operation, params: Readonly<Record<string, string>>, options?: V1CallOptions): Promise<V1CallResult>;
76
78
  /**
77
- * @param {"streamDatabaseChanges"} operation
79
+ * @param {"streamDatabaseChanges" | "exportDatabase"} operation
78
80
  * @param {Readonly<Record<string, string>>} params
79
81
  * @param {V1CallOptions} [options]
80
82
  * @returns {Promise<Response>}
81
83
  */
82
- openStream(operation: "streamDatabaseChanges", params: Readonly<Record<string, string>>, options?: V1CallOptions): Promise<Response>;
84
+ openStream(operation: "streamDatabaseChanges" | "exportDatabase", params: Readonly<Record<string, string>>, options?: V1CallOptions): Promise<Response>;
83
85
  #private;
84
86
  }
85
87
  /**
@@ -91,6 +93,10 @@ export type V1EndpointContext = {
91
93
  readonly signal?: AbortSignal | undefined;
92
94
  };
93
95
  export type V1EndpointResolver = (context: V1EndpointContext) => string | Promise<string>;
96
+ /**
97
+ * A fresh access token for each authenticated request, including stream reconnects.
98
+ */
99
+ export type V1TokenProvider = () => string | Promise<string>;
94
100
  /**
95
101
  * Project-scoped C# Documents API client. Supply exactly one of baseUrl or endpointResolver.
96
102
  * URLs must use HTTPS or loopback HTTP. Mutations are never automatically replayed.
@@ -98,9 +104,9 @@ export type V1EndpointResolver = (context: V1EndpointContext) => string | Promis
98
104
  export type TerraBaseV1ClientConfig = {
99
105
  project: string;
100
106
  /**
101
- * A ts-auth project access JWT (or a legacy C# tb_ key); held privately.
107
+ * An access JWT (or a legacy C# tb_ key), or a provider resolved per authenticated request; held privately. Browser callers must use end-user tokens, never project credentials.
102
108
  */
103
- token: string;
109
+ token: string | V1TokenProvider;
104
110
  baseUrl?: string | undefined;
105
111
  endpointResolver?: V1EndpointResolver | undefined;
106
112
  fetch?: FetchLike | undefined;