@terrascale/sdk 0.0.0-stage → 0.0.2
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 +62 -0
- package/LICENSE +202 -0
- package/README.md +202 -2
- package/package.json +152 -4
- package/sdk-v1-route-manifest.json +2330 -0
- package/src/admin.js +9 -0
- package/src/better-auth.js +14 -0
- package/src/config.js +121 -0
- package/src/database-codec.js +845 -0
- package/src/database-types.js +237 -0
- package/src/database-view.js +423 -0
- package/src/database.js +2 -0
- package/src/http.js +898 -0
- package/src/index.js +62 -0
- package/src/local/authentication.js +47 -0
- package/src/local/better-auth.js +517 -0
- package/src/local/cli.js +51 -0
- package/src/local/context.js +23 -0
- package/src/local/environment.js +109 -0
- package/src/local/index.js +206 -0
- package/src/local/legacy-client.js +411 -0
- package/src/local/router.js +999 -0
- package/src/local/server.js +664 -0
- package/src/local/store.js +530 -0
- package/src/local/test-environment.js +74 -0
- package/src/management-contracts.js +72 -0
- package/src/management.js +12 -0
- package/src/native-origin.js +75 -0
- package/src/postgres.js +496 -0
- package/src/react/core.js +743 -0
- package/src/react/index.js +99 -0
- package/src/result.js +251 -0
- package/src/schema.js +366 -0
- package/src/sql.js +996 -0
- package/src/svelte/index.js +129 -0
- package/src/tanstack/index.js +512 -0
- package/src/ts-auth-discovery.js +207 -0
- package/src/ts-auth.js +3498 -0
- package/src/v1/decode.js +118 -0
- package/src/v1/errors.js +185 -0
- package/src/v1/filter.js +230 -0
- package/src/v1/ids.js +119 -0
- package/src/v1/json.js +335 -0
- package/src/v1/routes.js +57 -0
- package/src/v1/shapes.js +145 -0
- package/src/v1/terrabase-v1.js +722 -0
- package/src/v1/transport.js +324 -0
- package/types/admin.d.ts +6 -0
- package/types/better-auth.d.ts +8 -0
- package/types/config.d.ts +58 -0
- package/types/database-codec.d.ts +111 -0
- package/types/database-types.d.ts +213 -0
- package/types/database-view.d.ts +184 -0
- package/types/database.d.ts +2 -0
- package/types/http.d.ts +47 -0
- package/types/index.d.ts +43 -0
- package/types/local/authentication.d.ts +11 -0
- package/types/local/better-auth.d.ts +33 -0
- package/types/local/cli.d.ts +2 -0
- package/types/local/context.d.ts +14 -0
- package/types/local/environment.d.ts +23 -0
- package/types/local/index.d.ts +96 -0
- package/types/local/legacy-client.d.ts +94 -0
- package/types/local/router.d.ts +66 -0
- package/types/local/server.d.ts +54 -0
- package/types/local/store.d.ts +106 -0
- package/types/local/test-environment.d.ts +25 -0
- package/types/management-contracts.d.ts +44 -0
- package/types/management.d.ts +6 -0
- package/types/native-origin.d.ts +23 -0
- package/types/postgres.d.ts +124 -0
- package/types/react/core.d.ts +366 -0
- package/types/react/index.d.ts +54 -0
- package/types/result.d.ts +161 -0
- package/types/schema.d.ts +145 -0
- package/types/sql.d.ts +288 -0
- package/types/svelte/index.d.ts +81 -0
- package/types/tanstack/index.d.ts +166 -0
- package/types/ts-auth-discovery.d.ts +19 -0
- package/types/ts-auth.d.ts +1826 -0
- package/types/v1/decode.d.ts +119 -0
- package/types/v1/errors.d.ts +107 -0
- package/types/v1/filter.d.ts +148 -0
- package/types/v1/ids.d.ts +44 -0
- package/types/v1/json.d.ts +92 -0
- package/types/v1/routes.d.ts +26 -0
- package/types/v1/shapes.d.ts +78 -0
- package/types/v1/terrabase-v1.d.ts +374 -0
- package/types/v1/transport.d.ts +117 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/** @import { JsonObject, JsonValue } from "./json.js" */
|
|
2
|
+
/** Unknown future labels pass through. @typedef {"local_durable" | (string & {})} V1Durability */
|
|
3
|
+
/**
|
|
4
|
+
* `document` is the value, or the LWW winner when a causal read answers `"conflict"` with `siblings`.
|
|
5
|
+
* Unknown future states pass through.
|
|
6
|
+
* @typedef {object} V1Document
|
|
7
|
+
* @property {string} id
|
|
8
|
+
* @property {string} version
|
|
9
|
+
* @property {"value" | "conflict" | (string & {})} state
|
|
10
|
+
* @property {JsonObject} document
|
|
11
|
+
* @property {readonly JsonValue[]} [siblings] Every live version, on a causal read with several.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* The result of a document write.
|
|
15
|
+
* @typedef {object} V1WriteResult
|
|
16
|
+
* @property {string} id
|
|
17
|
+
* @property {string} version For a delete, the tombstone's version.
|
|
18
|
+
* @property {string} offset The database commit offset (decimal u64), usable with shape `waitFor`.
|
|
19
|
+
* @property {V1Durability} durability
|
|
20
|
+
* @property {boolean} created True when a PUT or POST answered 201.
|
|
21
|
+
* @property {string | undefined} location The Location header of a POST create.
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* @param {string} what
|
|
25
|
+
* @returns {never}
|
|
26
|
+
*/
|
|
27
|
+
export function malformed(what: string): never;
|
|
28
|
+
/**
|
|
29
|
+
* @param {JsonValue | undefined} value
|
|
30
|
+
* @param {string} what
|
|
31
|
+
* @returns {JsonObject}
|
|
32
|
+
*/
|
|
33
|
+
export function object(value: JsonValue | undefined, what: string): JsonObject;
|
|
34
|
+
/**
|
|
35
|
+
* @param {JsonValue | undefined} value
|
|
36
|
+
* @param {string} what
|
|
37
|
+
* @returns {string}
|
|
38
|
+
*/
|
|
39
|
+
export function string(value: JsonValue | undefined, what: string): string;
|
|
40
|
+
/**
|
|
41
|
+
* @param {JsonValue | undefined} value
|
|
42
|
+
* @param {string} what
|
|
43
|
+
* @returns {string}
|
|
44
|
+
*/
|
|
45
|
+
export function u64(value: JsonValue | undefined, what: string): string;
|
|
46
|
+
/**
|
|
47
|
+
* @param {JsonValue | undefined} value
|
|
48
|
+
* @param {string} what
|
|
49
|
+
* @returns {boolean}
|
|
50
|
+
*/
|
|
51
|
+
export function boolean(value: JsonValue | undefined, what: string): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* @param {JsonValue | undefined} value
|
|
54
|
+
* @param {string} what
|
|
55
|
+
* @returns {JsonValue[]}
|
|
56
|
+
*/
|
|
57
|
+
export function array(value: JsonValue | undefined, what: string): JsonValue[];
|
|
58
|
+
/**
|
|
59
|
+
* @param {JsonValue | undefined} value
|
|
60
|
+
* @returns {V1Durability}
|
|
61
|
+
*/
|
|
62
|
+
export function durability(value: JsonValue | undefined): V1Durability;
|
|
63
|
+
/**
|
|
64
|
+
* @param {JsonValue | undefined} value
|
|
65
|
+
* @returns {V1Document}
|
|
66
|
+
*/
|
|
67
|
+
export function decodeDocument(value: JsonValue | undefined): V1Document;
|
|
68
|
+
/**
|
|
69
|
+
* @param {{ status: number; headers: Headers; value: JsonValue | undefined }} response
|
|
70
|
+
* @returns {V1WriteResult}
|
|
71
|
+
*/
|
|
72
|
+
export function decodeWrite(response: {
|
|
73
|
+
status: number;
|
|
74
|
+
headers: Headers;
|
|
75
|
+
value: JsonValue | undefined;
|
|
76
|
+
}): V1WriteResult;
|
|
77
|
+
/**
|
|
78
|
+
* Unknown future labels pass through.
|
|
79
|
+
*/
|
|
80
|
+
export type V1Durability = "local_durable" | (string & {});
|
|
81
|
+
/**
|
|
82
|
+
* `document` is the value, or the LWW winner when a causal read answers `"conflict"` with `siblings`.
|
|
83
|
+
* Unknown future states pass through.
|
|
84
|
+
*/
|
|
85
|
+
export type V1Document = {
|
|
86
|
+
id: string;
|
|
87
|
+
version: string;
|
|
88
|
+
state: "value" | "conflict" | (string & {});
|
|
89
|
+
document: JsonObject;
|
|
90
|
+
/**
|
|
91
|
+
* Every live version, on a causal read with several.
|
|
92
|
+
*/
|
|
93
|
+
siblings?: readonly JsonValue[];
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* The result of a document write.
|
|
97
|
+
*/
|
|
98
|
+
export type V1WriteResult = {
|
|
99
|
+
id: string;
|
|
100
|
+
/**
|
|
101
|
+
* For a delete, the tombstone's version.
|
|
102
|
+
*/
|
|
103
|
+
version: string;
|
|
104
|
+
/**
|
|
105
|
+
* The database commit offset (decimal u64), usable with shape `waitFor`.
|
|
106
|
+
*/
|
|
107
|
+
offset: string;
|
|
108
|
+
durability: V1Durability;
|
|
109
|
+
/**
|
|
110
|
+
* True when a PUT or POST answered 201.
|
|
111
|
+
*/
|
|
112
|
+
created: boolean;
|
|
113
|
+
/**
|
|
114
|
+
* The Location header of a POST create.
|
|
115
|
+
*/
|
|
116
|
+
location: string | undefined;
|
|
117
|
+
};
|
|
118
|
+
import type { JsonValue } from "./json.js";
|
|
119
|
+
import type { JsonObject } from "./json.js";
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {unknown} error
|
|
3
|
+
* @param {string} [code] Also require this `error.code`.
|
|
4
|
+
* @returns {error is TerraBaseV1Error}
|
|
5
|
+
*/
|
|
6
|
+
export function isTerraBaseV1Error(error: unknown, code?: string): error is TerraBaseV1Error;
|
|
7
|
+
/**
|
|
8
|
+
* @param {string | null} value
|
|
9
|
+
* @returns {string | undefined}
|
|
10
|
+
*/
|
|
11
|
+
export function unquoteEtag(value: string | null): string | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* @param {Headers} headers
|
|
14
|
+
* @returns {number | undefined} Seconds.
|
|
15
|
+
*/
|
|
16
|
+
export function parseRetryAfter(headers: Headers): number | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* @param {number} status
|
|
19
|
+
* @param {Headers} headers
|
|
20
|
+
* @param {string} text
|
|
21
|
+
* @returns {TerraBaseV1Error}
|
|
22
|
+
*/
|
|
23
|
+
export function parseV1Error(status: number, headers: Headers, text: string): TerraBaseV1Error;
|
|
24
|
+
/** @import { JsonObject } from "./json.js" */
|
|
25
|
+
/**
|
|
26
|
+
* @typedef {object} TerraBaseV1ErrorInit
|
|
27
|
+
* @property {number} status
|
|
28
|
+
* @property {string} code
|
|
29
|
+
* @property {string | undefined} [message]
|
|
30
|
+
* @property {number | undefined} [op]
|
|
31
|
+
* @property {string | undefined} [handle]
|
|
32
|
+
* @property {number | undefined} [retryAfter]
|
|
33
|
+
* @property {string | undefined} [etag]
|
|
34
|
+
* @property {JsonObject | undefined} [details]
|
|
35
|
+
*/
|
|
36
|
+
/**
|
|
37
|
+
* A non-2xx TerraBase v1 response. `code` is the contract's `error.code`, or
|
|
38
|
+
* `not_modified` for a 304 and `http_<status>` when the body carried no code.
|
|
39
|
+
*/
|
|
40
|
+
export class TerraBaseV1Error extends Error {
|
|
41
|
+
/** @param {TerraBaseV1ErrorInit} init */
|
|
42
|
+
constructor(init: TerraBaseV1ErrorInit);
|
|
43
|
+
/** @type {number} HTTP status. */
|
|
44
|
+
status: number;
|
|
45
|
+
/** @type {string} */
|
|
46
|
+
code: string;
|
|
47
|
+
/** @type {number | undefined} Failing transaction op index. */
|
|
48
|
+
op: number | undefined;
|
|
49
|
+
/** @type {string | undefined} New shape handle for `must_refetch`. */
|
|
50
|
+
handle: string | undefined;
|
|
51
|
+
/** @type {number | undefined} Parsed `Retry-After`, in seconds. */
|
|
52
|
+
retryAfter: number | undefined;
|
|
53
|
+
/** @type {string | undefined} Unquoted `ETag`; a deleted document's 404 carries its tombstone version. */
|
|
54
|
+
etag: string | undefined;
|
|
55
|
+
/** @type {JsonObject | undefined} The raw error object, for route-specific metadata. */
|
|
56
|
+
details: JsonObject | undefined;
|
|
57
|
+
}
|
|
58
|
+
/** Current document, collection and shape producer codes, plus client not_modified. */
|
|
59
|
+
export const V1ErrorCode: Readonly<{
|
|
60
|
+
invalidRequest: "invalid_request";
|
|
61
|
+
invalidQuery: "invalid_query";
|
|
62
|
+
invalidCursor: "invalid_cursor";
|
|
63
|
+
invalidPatch: "invalid_patch";
|
|
64
|
+
sortRequiresIndex: "sort_requires_index";
|
|
65
|
+
assertRequiresIndex: "assert_requires_index";
|
|
66
|
+
invalidKey: "invalid_key";
|
|
67
|
+
forbiddenScope: "forbidden_scope";
|
|
68
|
+
notFound: "not_found";
|
|
69
|
+
unknownDatabase: "unknown_database";
|
|
70
|
+
unknownCollection: "unknown_collection";
|
|
71
|
+
unknownRoute: "unknown_route";
|
|
72
|
+
methodNotAllowed: "method_not_allowed";
|
|
73
|
+
patchConflict: "patch_conflict";
|
|
74
|
+
nameTaken: "name_taken";
|
|
75
|
+
mustRefetch: "must_refetch";
|
|
76
|
+
preconditionFailed: "precondition_failed";
|
|
77
|
+
payloadTooLarge: "payload_too_large";
|
|
78
|
+
unsupportedMediaType: "unsupported_media_type";
|
|
79
|
+
uriTooLong: "uri_too_long";
|
|
80
|
+
shapeBusy: "shape_busy";
|
|
81
|
+
internalError: "internal_error";
|
|
82
|
+
capacity: "capacity";
|
|
83
|
+
notModified: "not_modified";
|
|
84
|
+
}>;
|
|
85
|
+
/** `412 precondition_failed`: an If-Match, If-None-Match, assert or assert_count failed. */
|
|
86
|
+
export class V1PreconditionFailedError extends TerraBaseV1Error {
|
|
87
|
+
}
|
|
88
|
+
/** `401 invalid_key`: the API key is unknown or revoked. */
|
|
89
|
+
export class V1InvalidKeyError extends TerraBaseV1Error {
|
|
90
|
+
}
|
|
91
|
+
/** `403 forbidden_scope`: the key's scopes do not cover the request. */
|
|
92
|
+
export class V1ForbiddenScopeError extends TerraBaseV1Error {
|
|
93
|
+
}
|
|
94
|
+
/** `404 not_found`: absent or deleted; `etag` carries a tombstone version. */
|
|
95
|
+
export class V1NotFoundError extends TerraBaseV1Error {
|
|
96
|
+
}
|
|
97
|
+
export type TerraBaseV1ErrorInit = {
|
|
98
|
+
status: number;
|
|
99
|
+
code: string;
|
|
100
|
+
message?: string | undefined;
|
|
101
|
+
op?: number | undefined;
|
|
102
|
+
handle?: string | undefined;
|
|
103
|
+
retryAfter?: number | undefined;
|
|
104
|
+
etag?: string | undefined;
|
|
105
|
+
details?: JsonObject | undefined;
|
|
106
|
+
};
|
|
107
|
+
import type { JsonObject } from "./json.js";
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An RFC 6901 JSON Pointer of at most 4 KiB with at least one segment: `~`
|
|
3
|
+
* only as the escapes `~0` and `~1`.
|
|
4
|
+
* @param {unknown} pointer
|
|
5
|
+
* @returns {pointer is string}
|
|
6
|
+
*/
|
|
7
|
+
export function isJsonPointer(pointer: unknown): pointer is string;
|
|
8
|
+
/**
|
|
9
|
+
* @param {V1Path} path
|
|
10
|
+
* @returns {V1Path}
|
|
11
|
+
*/
|
|
12
|
+
export function requirePath(path: V1Path): V1Path;
|
|
13
|
+
/**
|
|
14
|
+
* Validates a filter against the query-v1 grammar (operators, arity, paths,
|
|
15
|
+
* scalar operands, depth 8 and 256 nodes), so a malformed filter fails locally
|
|
16
|
+
* instead of as a server `invalid_query`. The v1Filter builders always pass.
|
|
17
|
+
* @param {unknown} filter
|
|
18
|
+
* @returns {V1Filter}
|
|
19
|
+
*/
|
|
20
|
+
export function requireFilter(filter: unknown): V1Filter;
|
|
21
|
+
/**
|
|
22
|
+
* Query v1 filter builders. `v1Filter.id` is the `"$id"` pseudo-path.
|
|
23
|
+
*/
|
|
24
|
+
export const v1Filter: Readonly<{
|
|
25
|
+
/** The document ID pseudo-path. */
|
|
26
|
+
id: "$id";
|
|
27
|
+
/**
|
|
28
|
+
* @param {...V1Filter} filters
|
|
29
|
+
* @returns {V1Filter}
|
|
30
|
+
*/
|
|
31
|
+
and: (...filters: V1Filter[]) => V1Filter;
|
|
32
|
+
/**
|
|
33
|
+
* @param {...V1Filter} filters
|
|
34
|
+
* @returns {V1Filter}
|
|
35
|
+
*/
|
|
36
|
+
or: (...filters: V1Filter[]) => V1Filter;
|
|
37
|
+
/**
|
|
38
|
+
* @param {V1Filter} filter
|
|
39
|
+
* @returns {V1Filter}
|
|
40
|
+
*/
|
|
41
|
+
not: (filter: V1Filter) => V1Filter;
|
|
42
|
+
/**
|
|
43
|
+
* @param {V1Path} path
|
|
44
|
+
* @param {V1Scalar} value
|
|
45
|
+
* @returns {V1Filter}
|
|
46
|
+
*/
|
|
47
|
+
eq: (path: V1Path, value: V1Scalar) => V1Filter;
|
|
48
|
+
/**
|
|
49
|
+
* Not equal; also matches a missing member.
|
|
50
|
+
* @param {V1Path} path
|
|
51
|
+
* @param {V1Scalar} value
|
|
52
|
+
* @returns {V1Filter}
|
|
53
|
+
*/
|
|
54
|
+
ne: (path: V1Path, value: V1Scalar) => V1Filter;
|
|
55
|
+
/**
|
|
56
|
+
* @param {V1Path} path
|
|
57
|
+
* @param {V1Scalar} value
|
|
58
|
+
* @returns {V1Filter}
|
|
59
|
+
*/
|
|
60
|
+
lt: (path: V1Path, value: V1Scalar) => V1Filter;
|
|
61
|
+
/**
|
|
62
|
+
* @param {V1Path} path
|
|
63
|
+
* @param {V1Scalar} value
|
|
64
|
+
* @returns {V1Filter}
|
|
65
|
+
*/
|
|
66
|
+
lte: (path: V1Path, value: V1Scalar) => V1Filter;
|
|
67
|
+
/**
|
|
68
|
+
* @param {V1Path} path
|
|
69
|
+
* @param {V1Scalar} value
|
|
70
|
+
* @returns {V1Filter}
|
|
71
|
+
*/
|
|
72
|
+
gt: (path: V1Path, value: V1Scalar) => V1Filter;
|
|
73
|
+
/**
|
|
74
|
+
* @param {V1Path} path
|
|
75
|
+
* @param {V1Scalar} value
|
|
76
|
+
* @returns {V1Filter}
|
|
77
|
+
*/
|
|
78
|
+
gte: (path: V1Path, value: V1Scalar) => V1Filter;
|
|
79
|
+
/**
|
|
80
|
+
* @param {V1Path} path
|
|
81
|
+
* @param {readonly V1Scalar[]} values 1-256 values.
|
|
82
|
+
* @returns {V1Filter}
|
|
83
|
+
*/
|
|
84
|
+
in: (path: V1Path, values: readonly V1Scalar[]) => V1Filter;
|
|
85
|
+
/**
|
|
86
|
+
* @param {V1Path} path
|
|
87
|
+
* @param {readonly V1Scalar[]} values 1-256 values.
|
|
88
|
+
* @returns {V1Filter}
|
|
89
|
+
*/
|
|
90
|
+
nin: (path: V1Path, values: readonly V1Scalar[]) => V1Filter;
|
|
91
|
+
/**
|
|
92
|
+
* The member is present (including null).
|
|
93
|
+
* @param {V1Path} path
|
|
94
|
+
* @returns {V1Filter}
|
|
95
|
+
*/
|
|
96
|
+
exists: (path: V1Path) => V1Filter;
|
|
97
|
+
/**
|
|
98
|
+
* @param {V1Path} path
|
|
99
|
+
* @param {string} prefix
|
|
100
|
+
* @returns {V1Filter}
|
|
101
|
+
*/
|
|
102
|
+
prefix: (path: V1Path, prefix: string) => V1Filter;
|
|
103
|
+
/**
|
|
104
|
+
* The value is an array containing the scalar.
|
|
105
|
+
* @param {V1Path} path
|
|
106
|
+
* @param {V1Scalar} value
|
|
107
|
+
* @returns {V1Filter}
|
|
108
|
+
*/
|
|
109
|
+
contains: (path: V1Path, value: V1Scalar) => V1Filter;
|
|
110
|
+
}>;
|
|
111
|
+
/**
|
|
112
|
+
* A filter or sort path: an RFC 6901 JSON Pointer or "$id".
|
|
113
|
+
*/
|
|
114
|
+
export type V1Path = string;
|
|
115
|
+
/**
|
|
116
|
+
* A filter operand: string, exact number, boolean or null.
|
|
117
|
+
*/
|
|
118
|
+
export type V1Scalar = null | boolean | string | number | bigint | ExactDecimal;
|
|
119
|
+
export type V1Filter = {
|
|
120
|
+
readonly and: readonly V1Filter[];
|
|
121
|
+
} | {
|
|
122
|
+
readonly or: readonly V1Filter[];
|
|
123
|
+
} | {
|
|
124
|
+
readonly not: V1Filter;
|
|
125
|
+
} | {
|
|
126
|
+
readonly eq: readonly [V1Path, V1Scalar];
|
|
127
|
+
} | {
|
|
128
|
+
readonly ne: readonly [V1Path, V1Scalar];
|
|
129
|
+
} | {
|
|
130
|
+
readonly lt: readonly [V1Path, V1Scalar];
|
|
131
|
+
} | {
|
|
132
|
+
readonly lte: readonly [V1Path, V1Scalar];
|
|
133
|
+
} | {
|
|
134
|
+
readonly gt: readonly [V1Path, V1Scalar];
|
|
135
|
+
} | {
|
|
136
|
+
readonly gte: readonly [V1Path, V1Scalar];
|
|
137
|
+
} | {
|
|
138
|
+
readonly in: readonly [V1Path, readonly V1Scalar[]];
|
|
139
|
+
} | {
|
|
140
|
+
readonly nin: readonly [V1Path, readonly V1Scalar[]];
|
|
141
|
+
} | {
|
|
142
|
+
readonly exists: V1Path;
|
|
143
|
+
} | {
|
|
144
|
+
readonly prefix: readonly [V1Path, string];
|
|
145
|
+
} | {
|
|
146
|
+
readonly contains: readonly [V1Path, V1Scalar];
|
|
147
|
+
};
|
|
148
|
+
import { ExactDecimal } from "./json.js";
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {"database" | "collection"} kind
|
|
3
|
+
* @param {unknown} name
|
|
4
|
+
* @returns {string}
|
|
5
|
+
*/
|
|
6
|
+
export function requireName(kind: "database" | "collection", name: unknown): string;
|
|
7
|
+
/**
|
|
8
|
+
* The producer resolves this opaque catalog project id (normally a UUID), not its display name.
|
|
9
|
+
* @param {unknown} project
|
|
10
|
+
* @returns {string}
|
|
11
|
+
*/
|
|
12
|
+
export function requireProject(project: unknown): string;
|
|
13
|
+
/**
|
|
14
|
+
* @param {unknown} id
|
|
15
|
+
* @returns {string}
|
|
16
|
+
*/
|
|
17
|
+
export function requireDocumentId(id: unknown): string;
|
|
18
|
+
/**
|
|
19
|
+
* @param {unknown} version
|
|
20
|
+
* @returns {string}
|
|
21
|
+
*/
|
|
22
|
+
export function requireVersion(version: unknown): string;
|
|
23
|
+
/**
|
|
24
|
+
* Parses a canonical decimal u64 (an offset), or returns undefined.
|
|
25
|
+
* @param {unknown} value
|
|
26
|
+
* @returns {bigint | undefined}
|
|
27
|
+
*/
|
|
28
|
+
export function parseU64(value: unknown): bigint | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* A caller-supplied u64 (a decimal string or bigint), as a bigint.
|
|
31
|
+
* @param {unknown} value
|
|
32
|
+
* @param {string} what
|
|
33
|
+
* @returns {bigint}
|
|
34
|
+
*/
|
|
35
|
+
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,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parses JSON text without losing number precision.
|
|
3
|
+
* @param {string} text
|
|
4
|
+
* @returns {JsonValue}
|
|
5
|
+
*/
|
|
6
|
+
export function parseExactJson(text: string): JsonValue;
|
|
7
|
+
/**
|
|
8
|
+
* Validates a document, merge patch or patch operand against C# RequestJson limits.
|
|
9
|
+
* @param {unknown} value
|
|
10
|
+
* @param {string} where
|
|
11
|
+
* @returns {void}
|
|
12
|
+
*/
|
|
13
|
+
export function assertJsonValue(value: unknown, where: string): void;
|
|
14
|
+
/**
|
|
15
|
+
* Encodes a request value exactly. bigint and ExactDecimal keep every digit.
|
|
16
|
+
* @param {unknown} value
|
|
17
|
+
* @param {string} where
|
|
18
|
+
* @returns {string}
|
|
19
|
+
*/
|
|
20
|
+
export function stringifyExactJson(value: unknown, where: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* @param {unknown} value
|
|
23
|
+
* @param {string} where
|
|
24
|
+
* @returns {void}
|
|
25
|
+
*/
|
|
26
|
+
export function assertJsonObject(value: unknown, where: string): void;
|
|
27
|
+
/**
|
|
28
|
+
* @param {unknown} value
|
|
29
|
+
* @returns {value is JsonObject}
|
|
30
|
+
*/
|
|
31
|
+
export function isJsonObject(value: unknown): value is JsonObject;
|
|
32
|
+
/**
|
|
33
|
+
* An exact decimal number as it travels on the wire. Values that a JavaScript
|
|
34
|
+
* number cannot represent exactly (large integers, long fractions) are
|
|
35
|
+
* returned as ExactDecimal; it serializes back to the identical JSON text.
|
|
36
|
+
*/
|
|
37
|
+
export class ExactDecimal {
|
|
38
|
+
/**
|
|
39
|
+
* @param {ExactDecimal | bigint | number | string} value
|
|
40
|
+
* @returns {ExactDecimal}
|
|
41
|
+
*/
|
|
42
|
+
static from(value: ExactDecimal | bigint | number | string): ExactDecimal;
|
|
43
|
+
/** @param {string} text A JSON number literal. */
|
|
44
|
+
constructor(text: string);
|
|
45
|
+
/** @returns {string} The exact JSON number text. */
|
|
46
|
+
toString(): string;
|
|
47
|
+
/** @returns {unknown} A raw JSON value that serializes as the exact text. */
|
|
48
|
+
toJSON(): unknown;
|
|
49
|
+
/** @returns {number} The nearest JavaScript number; may lose precision. */
|
|
50
|
+
toNumber(): number;
|
|
51
|
+
/** @returns {boolean} */
|
|
52
|
+
isInteger(): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* @returns {bigint} The exact integer value.
|
|
55
|
+
* @throws {RangeError} When the value is not an integer.
|
|
56
|
+
*/
|
|
57
|
+
toBigInt(): bigint;
|
|
58
|
+
/**
|
|
59
|
+
* Exact decimal equality: 1, 1.0 and 1e0 are equal.
|
|
60
|
+
* @param {ExactDecimal | bigint | number | string} other
|
|
61
|
+
* @returns {boolean}
|
|
62
|
+
*/
|
|
63
|
+
equals(other: ExactDecimal | bigint | number | string): boolean;
|
|
64
|
+
#private;
|
|
65
|
+
}
|
|
66
|
+
export type CanonicalDecimal = {
|
|
67
|
+
negative: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Significant digits without leading or trailing zeros; empty for zero.
|
|
70
|
+
*/
|
|
71
|
+
digits: string;
|
|
72
|
+
/**
|
|
73
|
+
* The value is digits × 10^exponent.
|
|
74
|
+
*/
|
|
75
|
+
exponent: bigint;
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* A decoded JSON value. Numbers are `number` when exact, else ExactDecimal.
|
|
79
|
+
*/
|
|
80
|
+
export type JsonValue = null | boolean | number | string | ExactDecimal | JsonArray | JsonObject;
|
|
81
|
+
export type JsonArray = JsonValue[];
|
|
82
|
+
export type JsonObject = {
|
|
83
|
+
[key: string]: JsonValue;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* A JSON value accepted in requests: bigint and ExactDecimal encode exactly.
|
|
87
|
+
*/
|
|
88
|
+
export type JsonInput = null | boolean | number | bigint | string | ExactDecimal | JsonInputArray | JsonInputObject;
|
|
89
|
+
export type JsonInputArray = readonly JsonInput[];
|
|
90
|
+
export type JsonInputObject = {
|
|
91
|
+
readonly [key: string]: JsonInput;
|
|
92
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** @param {V1Operation} operation @returns {V1Route} */
|
|
2
|
+
export function v1Route(operation: V1Operation): V1Route;
|
|
3
|
+
/** @param {V1Route} route @param {Readonly<Record<string, string>>} params @returns {string} */
|
|
4
|
+
export function v1RoutePath(route: V1Route, params: Readonly<Record<string, string>>): string;
|
|
5
|
+
/** @type {readonly V1Route[]} */
|
|
6
|
+
export const v1Routes: readonly V1Route[];
|
|
7
|
+
export type V1Operation = "getDocument" | "putDocument" | "createDocument" | "patchDocument" | "deleteDocument" | "commitTransaction" | "queryDocuments" | "createCollection" | "getCollection" | "listCollections" | "dropCollection" | "readShape";
|
|
8
|
+
export type V1Route = {
|
|
9
|
+
operation: V1Operation;
|
|
10
|
+
method: "GET" | "PUT" | "POST" | "PATCH" | "DELETE";
|
|
11
|
+
pathTemplate: string;
|
|
12
|
+
permission: "documents:read" | "documents:write" | "shapes:read";
|
|
13
|
+
requestMediaTypes: readonly string[];
|
|
14
|
+
responseMediaType: string;
|
|
15
|
+
successStatuses: readonly number[];
|
|
16
|
+
/**
|
|
17
|
+
* The producer rejects Idempotency-Key.
|
|
18
|
+
*/
|
|
19
|
+
idempotencyKey: "none";
|
|
20
|
+
/**
|
|
21
|
+
* Informational only; requests are never automatically replayed.
|
|
22
|
+
*/
|
|
23
|
+
replaySafe: boolean;
|
|
24
|
+
contract: string;
|
|
25
|
+
contractText: readonly string[];
|
|
26
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validates canonical C# offsets. Snapshot positions use a UTF-8/base64url keyset, not a page number.
|
|
3
|
+
* @param {unknown} value
|
|
4
|
+
* @returns {string}
|
|
5
|
+
*/
|
|
6
|
+
export function requireShapeOffset(value: unknown): string;
|
|
7
|
+
/** @param {V1ShapeRequest} request @returns {URLSearchParams} */
|
|
8
|
+
export function encodeShapeRequest(request: V1ShapeRequest): URLSearchParams;
|
|
9
|
+
/** @param {JsonValue | undefined} value @param {Headers} headers @returns {V1ShapePage} */
|
|
10
|
+
export function decodeShapePage(value: JsonValue | undefined, headers: Headers): V1ShapePage;
|
|
11
|
+
/**
|
|
12
|
+
* Bootstrap extracts continuation metadata from 307 but never forwards credentials to Location.
|
|
13
|
+
* The next request is rebuilt against the same named route and configured endpoint.
|
|
14
|
+
* @param {V1Transport} transport
|
|
15
|
+
* @param {Readonly<Record<string, string>>} params
|
|
16
|
+
* @param {V1ShapeRequest} request
|
|
17
|
+
* @param {AbortSignal | undefined} signal
|
|
18
|
+
* @returns {Promise<V1ShapePage>}
|
|
19
|
+
*/
|
|
20
|
+
export function readShape(transport: V1Transport, params: Readonly<Record<string, string>>, request: V1ShapeRequest, signal: AbortSignal | undefined): Promise<V1ShapePage>;
|
|
21
|
+
export type V1ShapeRequest = {
|
|
22
|
+
/**
|
|
23
|
+
* Filter using the current query grammar; projection is unsupported.
|
|
24
|
+
*/
|
|
25
|
+
where?: V1Filter | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* -1 (default, server bootstrap only), snap.<head>.<base64url-id>, or a decimal log position.
|
|
28
|
+
*/
|
|
29
|
+
offset?: string | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Required after bootstrap.
|
|
32
|
+
*/
|
|
33
|
+
handle?: string | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* True only for log positions; waits up to 20 seconds.
|
|
36
|
+
*/
|
|
37
|
+
live?: boolean | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* Previous live response's TB-Shape-Cursor.
|
|
40
|
+
*/
|
|
41
|
+
cursor?: string | undefined;
|
|
42
|
+
};
|
|
43
|
+
export type V1ShapeOp = {
|
|
44
|
+
readonly op: "upsert";
|
|
45
|
+
readonly id: string;
|
|
46
|
+
readonly version: string;
|
|
47
|
+
readonly document: JsonObject;
|
|
48
|
+
} | {
|
|
49
|
+
readonly op: "delete";
|
|
50
|
+
readonly id: string;
|
|
51
|
+
};
|
|
52
|
+
export type V1ShapeChange = {
|
|
53
|
+
readonly offset: string;
|
|
54
|
+
readonly ops: readonly V1ShapeOp[];
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* One snapshot page or log chunk. Only a fresh open tail/live response can report upToDate.
|
|
58
|
+
*/
|
|
59
|
+
export type V1ShapePage = {
|
|
60
|
+
shapeId: string;
|
|
61
|
+
handle: string;
|
|
62
|
+
offset: string;
|
|
63
|
+
nextOffset: string;
|
|
64
|
+
upToDate: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Apply commits and operations in their received order.
|
|
67
|
+
*/
|
|
68
|
+
changes: readonly V1ShapeChange[];
|
|
69
|
+
/**
|
|
70
|
+
* Echo this as cursor on the next live request.
|
|
71
|
+
*/
|
|
72
|
+
cursor: string | undefined;
|
|
73
|
+
etag: string | undefined;
|
|
74
|
+
};
|
|
75
|
+
import type { JsonValue } from "./json.js";
|
|
76
|
+
import type { V1Transport } from "./transport.js";
|
|
77
|
+
import type { V1Filter } from "./filter.js";
|
|
78
|
+
import type { JsonObject } from "./json.js";
|