@terrascale/sdk 0.0.2 → 0.0.3
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 +26 -0
- package/README.md +42 -15
- package/package.json +5 -2
- package/sdk-v1-route-manifest.json +7593 -1175
- package/src/database-codec.js +21 -26
- package/src/database-types.js +11 -11
- package/src/database-view.js +6 -6
- package/src/http.js +10 -0
- package/src/ids.js +22 -0
- package/src/index.js +2 -1
- package/src/local/better-auth.js +17 -6
- package/src/local/index.js +2 -2
- package/src/local/legacy-client.js +5 -5
- package/src/local/router.js +12 -12
- package/src/local/store.js +29 -28
- package/src/local/test-environment.js +3 -2
- package/src/postgres.js +5 -4
- package/src/react/core.js +2 -2
- package/src/ts-auth-ids.js +122 -0
- package/src/ts-auth.js +74 -72
- package/src/v1/decode.js +20 -8
- package/src/v1/ids.js +7 -60
- package/src/v1/routes.js +5 -5
- package/src/v1/shapes.js +6 -7
- package/src/v1/terrabase-v1.js +24 -16
- package/src/v1/transport.js +6 -4
- package/types/database-codec.d.ts +1 -6
- package/types/database-types.d.ts +11 -11
- package/types/ids.d.ts +10 -0
- package/types/index.d.ts +2 -1
- package/types/local/store.d.ts +10 -0
- package/types/local/test-environment.d.ts +2 -2
- package/types/postgres.d.ts +4 -4
- package/types/ts-auth-ids.d.ts +14 -0
- package/types/ts-auth.d.ts +99 -99
- package/types/v1/decode.d.ts +8 -6
- package/types/v1/ids.d.ts +5 -17
- package/types/v1/shapes.d.ts +2 -2
- package/types/v1/terrabase-v1.d.ts +3 -3
- package/types/v1/transport.d.ts +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## Unreleased — TS-754
|
|
4
|
+
|
|
5
|
+
Entity IDs are plain uppercase Crockford ULIDs. `generateId()` uses the maintained
|
|
6
|
+
`ulid` library with monotonic generation; `isValidId()` and `requireId()` validate
|
|
7
|
+
the canonical 26-character, 128-bit form. UUIDs, prefixes, lowercase and legacy
|
|
8
|
+
keys fail validation. Project IDs, document requests/responses, snapshot keys,
|
|
9
|
+
hosted identity DTOs and explicit development storage use this contract.
|
|
10
|
+
|
|
11
|
+
The document key is the entity ID; document JSON and patches cannot duplicate it
|
|
12
|
+
in a top-level `id` field. The deterministic UUIDv5 `documentIdFor` helper is
|
|
13
|
+
removed. Store natural keys in indexed fields. Local Better Auth generates ULIDs
|
|
14
|
+
and stores the ID only in the record key, reconstructing its adapter view on read.
|
|
15
|
+
|
|
16
|
+
This is a greenfield cutover: there is no migration, ID rewrite, compatibility
|
|
17
|
+
shim or legacy fallback. Service owners wipe their verified affected stores and
|
|
18
|
+
recreate bootstrap state; this stateless SDK has no production data to delete.
|
|
19
|
+
Release qualification requires the matching immutable C# ULID producer release.
|
|
20
|
+
|
|
21
|
+
## Unreleased — TS-592
|
|
22
|
+
|
|
23
|
+
The project-scoped data client accepts a ts-auth access JWT as `token`, while
|
|
24
|
+
retaining legacy C# `tb_` keys for the existing producer release. Header injection
|
|
25
|
+
and malformed credentials fail before I/O. TS-589 keeps data paths unchanged;
|
|
26
|
+
Management and Admin remain closed and make no retired route calls.
|
|
27
|
+
JWT producer qualification awaits the server implementation of `docs/api.md`.
|
|
28
|
+
|
|
3
29
|
## 0.0.2 — TS-650
|
|
4
30
|
|
|
5
31
|
TerraBase version tokens are opaque: `tbv1-<32 hex>` and the coming `tbv2-…`
|
package/README.md
CHANGED
|
@@ -11,17 +11,17 @@ npm install @terrascale/sdk
|
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
```js
|
|
14
|
-
import { createTerraBaseV1Client,
|
|
14
|
+
import { createTerraBaseV1Client, generateId, v1Filter } from "@terrascale/sdk";
|
|
15
15
|
|
|
16
16
|
const client = createTerraBaseV1Client({
|
|
17
17
|
project: process.env.TERRABASE_PROJECT,
|
|
18
|
-
token: process.env.
|
|
18
|
+
token: process.env.TERRABASE_ACCESS_TOKEN,
|
|
19
19
|
baseUrl: process.env.TERRABASE_BASE_URL,
|
|
20
20
|
});
|
|
21
21
|
const db = client.database("app");
|
|
22
22
|
const todos = db.collection("todos");
|
|
23
23
|
|
|
24
|
-
const id =
|
|
24
|
+
const id = generateId();
|
|
25
25
|
await todos.put(id, { title: "Use TerraBase", done: false }, { ifNoneMatchAny: true });
|
|
26
26
|
const doc = await todos.get(id);
|
|
27
27
|
await todos.patch(id, { merge: { done: true } }, { ifMatch: doc.version });
|
|
@@ -32,10 +32,14 @@ for await (const page of todos.pages({ filter: v1Filter.eq("/done", true), limit
|
|
|
32
32
|
```
|
|
33
33
|
|
|
34
34
|
Provision the project, database and collection before using their handles.
|
|
35
|
-
|
|
35
|
+
The pinned producer still requires a C# `tb_` key as `token`. The example also
|
|
36
|
+
accepts a ts-auth project access JWT for the published TS-589 target, whose
|
|
37
|
+
server implementation remains pending. Credentials travel as
|
|
38
|
+
`Authorization: Bearer <token>` and are held privately. The SDK validates
|
|
39
|
+
header-safe syntax; authentication and authorization belong to the producer.
|
|
36
40
|
Reads and queries require `documents:read`; writes and transactions require
|
|
37
41
|
`documents:write`. Transaction assertions additionally require `documents:read`.
|
|
38
|
-
Keep
|
|
42
|
+
Keep service credentials private and out of logs and browser bundles. `createTerraBaseClient`
|
|
39
43
|
is an alias of `createTerraBaseV1Client`; it no longer accepts tenant/shard options.
|
|
40
44
|
|
|
41
45
|
## Atlas and endpoint selection
|
|
@@ -54,7 +58,7 @@ import { createTerraBaseV1Client, staticBaseUrlResolver } from "@terrascale/sdk"
|
|
|
54
58
|
|
|
55
59
|
const client = createTerraBaseV1Client({
|
|
56
60
|
project: process.env.TERRABASE_PROJECT,
|
|
57
|
-
token: process.env.
|
|
61
|
+
token: process.env.TERRABASE_ACCESS_TOKEN,
|
|
58
62
|
endpointResolver: staticBaseUrlResolver(process.env.TERRABASE_BASE_URL),
|
|
59
63
|
});
|
|
60
64
|
const db = client.database("app");
|
|
@@ -67,6 +71,19 @@ to TS-507; this release requires an explicit URL or caller-supplied resolver.
|
|
|
67
71
|
|
|
68
72
|
## Documents, queries, transactions and shapes
|
|
69
73
|
|
|
74
|
+
The published TS-589 route table (`terrabase/docs/api.md`) keeps these data
|
|
75
|
+
paths unchanged. Management moves to project-scoped paths using database names;
|
|
76
|
+
this SDK's Management and Admin entrypoints still make no HTTP calls.
|
|
77
|
+
Database creation belongs to Management (`POST /v1/projects/{project}/databases`)
|
|
78
|
+
in that target contract.
|
|
79
|
+
|
|
80
|
+
The current immutable producer release implements the renamed `TerraBase`
|
|
81
|
+
assembly, but still authenticates data calls with `tb_` keys and exposes the old
|
|
82
|
+
Management routes. Its real-release integration harness uses those existing
|
|
83
|
+
bootstrap operations. JWT server compatibility and the new Management routes
|
|
84
|
+
remain unqualified until the producer publishes their implementation; accepting
|
|
85
|
+
a JWT in SDK configuration does not establish server compatibility.
|
|
86
|
+
|
|
70
87
|
The C# producer owns these routes:
|
|
71
88
|
|
|
72
89
|
| Operation | Method and path |
|
|
@@ -77,8 +94,12 @@ The C# producer owns these routes:
|
|
|
77
94
|
| Shape | `GET /v1/projects/{project}/databases/{db}/collections/{c}/shape` |
|
|
78
95
|
|
|
79
96
|
Collection methods are `get`, `put`, `create`, `patch`, `delete`, `query`,
|
|
80
|
-
`pages` and `items`.
|
|
81
|
-
|
|
97
|
+
`pages` and `items`. Every entity ID is a plain 26-character Crockford ULID,
|
|
98
|
+
canonical uppercase, without a prefix. `generateId()` uses the maintained
|
|
99
|
+
`ulid` library and increases monotonically within a millisecond. `isValidId`
|
|
100
|
+
checks IDs; `requireId` throws for invalid IDs. UUIDs and legacy IDs are rejected.
|
|
101
|
+
The document key is the entity ID: keep it out of the JSON payload. Natural
|
|
102
|
+
keys belong in indexed document fields, not deterministic UUID IDs. Documents return
|
|
82
103
|
`{ id, version, state: "value", document }`; a causal read can answer
|
|
83
104
|
`state: "conflict"` with `siblings`, and unknown states pass through. Versions
|
|
84
105
|
(`tbv1-…`, `tbv2-…`) are opaque tokens. Writes return the version and a
|
|
@@ -140,14 +161,13 @@ Never commit keys, cookies, environment files or real tenant data.
|
|
|
140
161
|
|
|
141
162
|
The immutable release pin is
|
|
142
163
|
[`scripts/ci/terrabase-release.json`](scripts/ci/terrabase-release.json): C#
|
|
143
|
-
TerraBase 0.1.0, release `ci-
|
|
164
|
+
TerraBase 0.1.0, release `ci-6cb97456b9b52a92a61856601cc025c4f2833518-run-16729`,
|
|
144
165
|
with binary SHA-256
|
|
145
|
-
`
|
|
146
|
-
This official
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
SHA-256 are verified
|
|
150
|
-
that the producer's source qualification passed.
|
|
166
|
+
`cc2db35b18c385c6d58036c6c94e59460b0e12b0d5616da2222713efbe666700`.
|
|
167
|
+
This official prerelease contains the qualified TS-754 ULID producer, the renamed
|
|
168
|
+
`TerraBase` assembly and `src/TerraBase` sources. Its asset name remains `terrabase-linux-amd64`.
|
|
169
|
+
The SDK integration harness consumes its official asset read-only when the
|
|
170
|
+
version, source revision, size and SHA-256 are verified.
|
|
151
171
|
The acquisition script verifies the official release, revision, asset size and
|
|
152
172
|
digest. Private downloads require `FORGEJO_TOKEN`. Missing or mismatched official
|
|
153
173
|
assets block qualification rather than selecting older bytes.
|
|
@@ -187,11 +207,18 @@ See [CHANGELOG.md](CHANGELOG.md) for the 0.0.1 migration and breaking changes.
|
|
|
187
207
|
client, with its own origin, instance and credentials. Management,
|
|
188
208
|
administration and production Better Auth capabilities remain subject to their
|
|
189
209
|
explicit admission errors; they are not a shortcut into the database transport.
|
|
210
|
+
Webhook dead-letter replay uses the documented `endpointId:eventId` delivery
|
|
211
|
+
selector; both references must be canonical ULIDs. Entity pages reject null and
|
|
212
|
+
primitive records; recovery-code pages contain strings.
|
|
190
213
|
|
|
191
214
|
`@terrascale/sdk/local` (including `terrascale-local`) and `@terrascale/sdk/postgres` are
|
|
192
215
|
**deprecated legacy entrypoints**. SQLite stays opt-in for development only and
|
|
193
216
|
refuses CI, production, staging, qualification and deployment environments.
|
|
194
217
|
It is no longer the required Dashboard backend and does not qualify the C# API.
|
|
218
|
+
Local SQLite uses fresh format 2. Older stores are refused before records are
|
|
219
|
+
read: stop the runtime, delete the exact configured `databasePath` and its
|
|
220
|
+
`-wal`/`-shm` files, then restart. Startup recreates bootstrap state; old auth
|
|
221
|
+
records and references are discarded together. There is no migration.
|
|
195
222
|
The PostgreSQL listener and retired tenant/shard client are outside the default
|
|
196
223
|
v1 API. Existing framework, schema and SQL entrypoints are separate legacy
|
|
197
224
|
surfaces; the root entrypoint exposes the C# v1 client API.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@terrascale/sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "JavaScript SDK, typed with JSDoc, for project-scoped C# TerraBase v1 and hosted TerraScale identity.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -150,5 +150,8 @@
|
|
|
150
150
|
"last 1 Edge major version"
|
|
151
151
|
]
|
|
152
152
|
},
|
|
153
|
-
"packageManager": "npm@11.18.0"
|
|
153
|
+
"packageManager": "npm@11.18.0",
|
|
154
|
+
"dependencies": {
|
|
155
|
+
"ulid": "3.0.2"
|
|
156
|
+
}
|
|
154
157
|
}
|