@xcitedbs/client 0.2.20 → 0.2.21

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/dist/client.d.ts CHANGED
@@ -410,6 +410,36 @@ export declare class XCiteDBClient {
410
410
  message?: string;
411
411
  autoResolve?: 'none' | 'source' | 'target';
412
412
  }): Promise<MergeResult>;
413
+ /** List app-user draft workspaces visible to the caller (`GET /api/v1/user-workspaces`). */
414
+ listUserWorkspaces(): Promise<{
415
+ user_workspaces: Record<string, unknown>[];
416
+ }>;
417
+ /** Create a user workspace (`POST /api/v1/user-workspaces`). Returns the workspace record (top-level JSON). */
418
+ createUserWorkspace(name: string, options?: {
419
+ sourceBranch?: string;
420
+ sourceDate?: string;
421
+ }): Promise<Record<string, unknown>>;
422
+ getUserWorkspace(id: string): Promise<{
423
+ user_workspace: Record<string, unknown>;
424
+ }>;
425
+ deleteUserWorkspace(id: string): Promise<void>;
426
+ addUserWorkspaceGrant(id: string, body: {
427
+ user_id?: string;
428
+ group?: string;
429
+ mode: string;
430
+ }): Promise<{
431
+ user_workspace: Record<string, unknown>;
432
+ }>;
433
+ removeUserWorkspaceGrant(id: string, body: {
434
+ user_id?: string;
435
+ group?: string;
436
+ }): Promise<{
437
+ user_workspace: Record<string, unknown>;
438
+ }>;
439
+ publishUserWorkspace(id: string, options?: {
440
+ message?: string;
441
+ autoResolve?: string;
442
+ }): Promise<Record<string, unknown>>;
413
443
  /**
414
444
  * Create `workspaceName` from {@link options.fromBranch} (or current context), run `fn` scoped to that workspace,
415
445
  * create a checkpoint, then publish back unless {@link options.autoMerge} is `false`.
package/dist/client.js CHANGED
@@ -1246,6 +1246,37 @@ class XCiteDBClient {
1246
1246
  async mergeBranch(targetBranch, sourceBranch, options) {
1247
1247
  return this.publishWorkspace(targetBranch, sourceBranch, options);
1248
1248
  }
1249
+ /** List app-user draft workspaces visible to the caller (`GET /api/v1/user-workspaces`). */
1250
+ async listUserWorkspaces() {
1251
+ return this.request('GET', '/api/v1/user-workspaces');
1252
+ }
1253
+ /** Create a user workspace (`POST /api/v1/user-workspaces`). Returns the workspace record (top-level JSON). */
1254
+ async createUserWorkspace(name, options) {
1255
+ const body = { name };
1256
+ if (options?.sourceBranch)
1257
+ body.source_branch = options.sourceBranch;
1258
+ if (options?.sourceDate)
1259
+ body.source_date = options.sourceDate;
1260
+ return this.request('POST', '/api/v1/user-workspaces', body);
1261
+ }
1262
+ async getUserWorkspace(id) {
1263
+ return this.request('GET', `/api/v1/user-workspaces/${encodeURIComponent(id)}`);
1264
+ }
1265
+ async deleteUserWorkspace(id) {
1266
+ await this.request('DELETE', `/api/v1/user-workspaces/${encodeURIComponent(id)}`);
1267
+ }
1268
+ async addUserWorkspaceGrant(id, body) {
1269
+ return this.request('POST', `/api/v1/user-workspaces/${encodeURIComponent(id)}/grants`, body);
1270
+ }
1271
+ async removeUserWorkspaceGrant(id, body) {
1272
+ return this.request('DELETE', `/api/v1/user-workspaces/${encodeURIComponent(id)}/grants`, body);
1273
+ }
1274
+ async publishUserWorkspace(id, options) {
1275
+ const body = { auto_resolve: options?.autoResolve ?? 'none' };
1276
+ if (options?.message)
1277
+ body.message = options.message;
1278
+ return this.request('POST', `/api/v1/user-workspaces/${encodeURIComponent(id)}/publish`, body);
1279
+ }
1249
1280
  /**
1250
1281
  * Create `workspaceName` from {@link options.fromBranch} (or current context), run `fn` scoped to that workspace,
1251
1282
  * create a checkpoint, then publish back unless {@link options.autoMerge} is `false`.
package/llms-full.txt CHANGED
@@ -35,10 +35,11 @@ Before reading the full reference, note these critical differences from typical
35
35
  - **Write at a specific date:** Set `X-Date` / `context.date` and write — every dated write is a **temporal revision**; no workspace or checkpoint required.
36
36
  - **Read as-of a date:** Set `X-Date` and read; the engine returns the revision at or before that instant.
37
37
  - **Isolated editing (draft → publish):** Create a **workspace**, edit, then **publish** to the target timeline; optional **checkpoints** for named snapshots.
38
+ - **App-user user workspaces (`_uw/<owner>/<slug>`):** **`GET/POST /api/v1/user-workspaces`**, grants, publish — see repository **`web/src/docs/content/user-workspaces.md`**.
38
39
  - **Audit trail:** Checkpoints carry messages and affected identifiers; **bookmarks** name a checkpoint.
39
40
  - **Undo a batch:** **Revert** to a prior checkpoint on that workspace.
40
41
 
41
- Legacy REST paths under `/api/v1/branches`, `/commits`, `/tags`, `/diff` remain **deprecated** aliases; prefer **`/api/v1/workspaces`**, **`/checkpoints`**, **`/bookmarks`**, **`/compare`**.
42
+ Legacy REST paths under `/api/v1/branches`, `/commits`, `/tags`, `/diff` remain **deprecated** aliases; prefer **`/api/v1/workspaces`**, **`/api/v1/user-workspaces`**, **`/checkpoints`**, **`/bookmarks`**, **`/compare`**.
42
43
 
43
44
  ## Common Pitfalls
44
45
 
package/llms.txt CHANGED
@@ -10,7 +10,7 @@ These are the most common sources of confusion for developers and AI assistants:
10
10
 
11
11
  2. **Identifiers are hierarchical, path-like strings** — e.g. `/us/bills/hr1`, `/manual/v2/chapter3`. They are NOT auto-generated UUIDs. The leading `/` is part of the identifier. Parent/child relationships are derived from the path structure (like a filesystem). The server indexes this hierarchy natively.
12
12
 
13
- 3. **Documents are XML or JSON, not arbitrary blobs.** XML documents are the primary document type, stored with structural shredding. JSON documents are a parallel store keyed by identifier string. Both are fully versioned.
13
+ 3. **Shredding vs sharding (do not confuse them).** **Shredding** breaks **XML and JSON** hierarchically into small **fragments** (elements, attributes, objects, fields, array slots, and similar structural pieces) so each fragment can live under its **own LMDB key/value**. That is **not** “sharding” in the usual distributed-database sense. **Sharding** in XCiteDB means **per-tenant** isolation (each **project** is its own shard of data); **finer-grain sharding** is planned separately. Sharding and shredding are unrelated axes. **Documents are XML or JSON, not arbitrary blobs.** XML documents are the primary document type; JSON documents are a parallel store keyed by identifier string. Both are fully versioned.
14
14
 
15
15
  4. **`X-Date` and temporal revision (not “only now”).** Workspace and date context travel as HTTP headers (`X-Workspace` preferred, `X-Branch` alias, `X-Date`), or the SDK `context` option — not as URL path segments. **`X-Date` is not limited to the current server time.** Pass any instant you need as **ISO 8601** (e.g. `2024-01-15T00:00:00`) or **`mm/dd/yyyy`** (optional **`:HH:MM:SS`**) — for example an **official publication or approval date**, or any historical “as of” moment. When **`X-Date` is set**, that value applies to **both** **reads** (query as-of that instant) **and** **writes** (the new revision is stored under that revision instant). When **`X-Date` is omitted** and you do **not** send **`X-Unversioned: true`**, **writes** use **flat** keys (no date suffix on that write); **reads** still resolve **as of the current time**. **`X-Unversioned: true`** requests explicit flat keys and must **not** be combined with **`X-Date`** (the server returns 400).
16
16
 
@@ -32,11 +32,13 @@ These are the most common sources of confusion for developers and AI assistants:
32
32
 
33
33
  - **Isolated editing** (draft/review/publish): Create a **workspace**, make changes, then **publish** to the main timeline. Optionally create **checkpoints** for named snapshots within the workspace.
34
34
 
35
+ - **App-user draft workspaces (`_uw/<owner>/<slug>`):** REST **`/api/v1/user-workspaces`**; SDK: `listUserWorkspaces`, `createUserWorkspace`, `getUserWorkspace`, `deleteUserWorkspace`, `addUserWorkspaceGrant`, `removeUserWorkspaceGrant`, `publishUserWorkspace`.
36
+
35
37
  - **Audit trail with named snapshots:** Create checkpoints with messages. List/inspect checkpoints for history.
36
38
 
37
39
  - **Undo a batch of changes:** **Revert** to a prior checkpoint (removes all changes after that point on the workspace).
38
40
 
39
- Legacy REST paths (`/api/v1/branches`, `/commits`, `/tags`, `/diff`) remain as **deprecated** aliases; prefer **`/api/v1/workspaces`**, **`/checkpoints`**, **`/bookmarks`**, **`/compare`**.
41
+ Legacy REST paths (`/api/v1/branches`, `/commits`, `/tags`, `/diff`) remain as **deprecated** aliases; prefer **`/api/v1/workspaces`**, **`/api/v1/user-workspaces`**, **`/checkpoints`**, **`/bookmarks`**, **`/compare`**.
40
42
 
41
43
  ## Glossary: Project id, display name, and groups
42
44
 
@@ -154,7 +156,7 @@ When you build a backend that calls XCiteDB on behalf of users:
154
156
 
155
157
  - **JSON documents merge by default.** `POST /api/v1/json-documents` merges the posted `data` into the existing document (object fields combined per XCiteDB meta merge rules). Send **`overwrite: true`** to clear all stored JSON under that document root first, then write only the new payload. SDKs accept the same flag (e.g. `writeJsonDocument(id, data, { overwrite: true })` in JavaScript).
156
158
  - **Metadata `mode` and arrays.** **`POST /api/v1/meta`** uses **`mode`**: default **`set`** writes or replaces at `path` (arrays are replaced in range; excess old indices cleared); **`append`** appends array elements after existing ones at `path`. Optional **`overwrite: true`** clears metadata under `path` before writing. JavaScript: **`appendMeta`** or **`addMeta(..., { mode: 'append' })`**; Python/C++: **`append_meta`** or **`add_meta`** with **`mode`** / **`overwrite`** (see SDK sections below).
157
- - **Prefer dictionary-style objects.** Shredded JSON metadata is keyed by field names. **Object maps** get per-field storage; when an object accumulates enough distinct field names (server default threshold **32**), XCiteDB switches automatically to **dictionary storage** (`{*}` plus per-field keys) for efficient indexed access. For lookup-heavy or wide records, use **`{ "key": value, ... }`** shapes (or one document per logical row) rather than opaque arrays when you need keyed reads.
159
+ - **Prefer dictionary-style objects.** **Shredded** JSON metadata is stored in **fragment-level** keys (e.g. per field name). **Object maps** get per-field storage; when an object accumulates enough distinct field names (server default threshold **32**), XCiteDB switches automatically to **dictionary storage** (`{*}` plus per-field keys) for efficient indexed access. For lookup-heavy or wide records, use **`{ "key": value, ... }`** shapes (or one document per logical row) rather than opaque arrays when you need keyed reads.
158
160
 
159
161
  ## JavaScript/TypeScript SDK (`@xcitedbs/client`)
160
162
 
@@ -297,6 +299,7 @@ interface XCiteDBClientOptions {
297
299
  - `listWorkspaces()` — List workspaces
298
300
  - `publishWorkspace(target, source, options?)` — Publish workspace changes to a target timeline
299
301
  - `deleteWorkspace(name)` — Delete workspace
302
+ - `listUserWorkspaces()` / `createUserWorkspace(name, options?)` / `getUserWorkspace(id)` / `deleteUserWorkspace(id)` / `addUserWorkspaceGrant(id, body)` / `removeUserWorkspaceGrant(id, body)` / `publishUserWorkspace(id, options?)` — App-user **`_uw/…`** workspaces
300
303
  - `createCheckpoint(message, author?)` — Named snapshot of current state
301
304
  - `listCheckpoints(options?)` — List checkpoints
302
305
  - `revertToCheckpoint(checkpointId)` — Revert workspace to a prior checkpoint
@@ -417,6 +420,7 @@ auto ids = client.query_documents(q);
417
420
  ## Architecture Notes
418
421
 
419
422
  - **Multi-tenant**: Each project is an isolated tenant with its own data, users, keys, and policies.
423
+ - **Sharding vs shredding**: **Sharding** partitions the **tenant plane** (today, one isolated dataset per project; finer-grain sharding is on the roadmap). **Shredding** splits **individual documents** into **fragments** with their own keys—see convention 3.
420
424
  - **LMDB engine**: Data is memory-mapped; reads are microsecond-class on warm data.
421
425
  - **Versioning**: **Temporal revisions** are always on when using dates. **Workspaces** isolate draft work; **checkpoints** are optional named snapshots; **publish** merges a workspace into a target timeline. **`X-Date`** selects an instant for **as-of reads** and, when set, for **writes** under that revision (any calendar time you choose — e.g. publication date — not only “now”). Omit **`X-Date`** for **flat** writes on that request, or use **`X-Unversioned: true`** to state that explicitly.
422
426
  - **Two user tiers**: Platform operators manage infrastructure; App users are end-users of applications built on XciteDB.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xcitedbs/client",
3
- "version": "0.2.20",
3
+ "version": "0.2.21",
4
4
  "description": "XCiteDB BaaS client SDK",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",