@xcitedbs/client 0.1.0 → 0.2.0

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.
Files changed (3) hide show
  1. package/llms-full.txt +1158 -0
  2. package/llms.txt +251 -0
  3. package/package.json +4 -2
package/llms.txt ADDED
@@ -0,0 +1,251 @@
1
+ # XciteDB
2
+
3
+ > XciteDB is a versioned XML and JSON document database delivered as a Backend-as-a-Service (BaaS). It provides Git-like branching, commits, time-travel, and hierarchical document identifiers over a high-performance embedded LMDB engine, exposed through a REST + WebSocket API.
4
+
5
+ ## Important: Non-Standard Conventions
6
+
7
+ These are the most common sources of confusion for developers and AI assistants:
8
+
9
+ 1. **The default branch is the empty string `""`, not `"main"`.** When no `X-Branch` header is sent (or `context.branch` is omitted/empty in the SDK), the server operates on the root timeline. A branch named `"main"` may exist as a user-created branch, but it is not required or special.
10
+
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
+
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.
14
+
15
+ 4. **Context (branch + date) travels as HTTP headers**, not URL path segments. Use `X-Branch` and `X-Date` headers (or the SDK `context` option) to select which branch and point-in-time you are reading/writing.
16
+
17
+ 5. **XML documents carry their identifier inside the XML** — specifically via a `db:identifier` attribute on the root element (e.g. `<chapter db:identifier="/book/ch1">...</chapter>`). When writing XML, the server extracts the identifier from the document body.
18
+
19
+ 6. **Authentication has two tiers.** Platform operators (site admins) log in via `/api/v1/platform/auth/*` and use `X-Project-Id` to select a tenant project. Application end-users log in via `/api/v1/app/auth/*` and are scoped to a single project. API keys bypass login for server-to-server use.
20
+
21
+ 7. **The query model is NOT SQL.** Listing/filtering documents uses query parameters on REST endpoints (`match`, `match_start`, `contains`, `regex`, `prefix`). Advanced analytics use **Unquery**, a JSON-defined declarative DSL posted to `POST /api/v1/unquery`.
22
+
23
+ ## JavaScript/TypeScript SDK (`@xcitedbs/client`)
24
+
25
+ Install: `npm install @xcitedbs/client`
26
+
27
+ ### Quick Start
28
+
29
+ ```typescript
30
+ import { XCiteDBClient } from '@xcitedbs/client';
31
+
32
+ const client = new XCiteDBClient({
33
+ baseUrl: 'http://localhost:8080',
34
+ apiKey: 'your-api-key',
35
+ // branch: '' means root timeline (the default); omit or use '' for default
36
+ context: { branch: '', date: '' },
37
+ });
38
+
39
+ // Health check (no auth required)
40
+ await client.health();
41
+
42
+ // List all branches
43
+ const branches = await client.listBranches();
44
+
45
+ // Query documents by identifier prefix
46
+ const docs = await client.queryDocuments({ match_start: '/manual/' });
47
+
48
+ // Read a single document by exact identifier
49
+ const xml = await client.queryByIdentifier('/manual/v1/intro', 'FirstMatch');
50
+
51
+ // Write an XML document (identifier is inside the XML body)
52
+ await client.writeDocumentJson(
53
+ '<chapter db:identifier="/manual/v1/intro"><title>Introduction</title></chapter>'
54
+ );
55
+
56
+ // Write a JSON document
57
+ await client.writeJsonDocument('app.settings', { theme: 'dark', locale: 'en' });
58
+
59
+ // Read a JSON document
60
+ const settings = await client.readJsonDocument('app.settings');
61
+
62
+ // Create a branch, make changes, commit, merge
63
+ await client.createBranch('feature-x');
64
+ client.setContext({ branch: 'feature-x' });
65
+ await client.writeJsonDocument('app.settings', { theme: 'light' });
66
+ const commit = await client.createCommit('Switch to light theme');
67
+ await client.mergeBranch('', 'feature-x'); // merge into root (default) branch
68
+
69
+ // Attach JSON metadata to a document
70
+ await client.addMeta('/manual/v1/intro', { status: 'draft', owner: 'alice' });
71
+
72
+ // Acquire a cooperative lock
73
+ const lock = await client.acquireLock('/manual/v1/intro');
74
+ // ... edit ...
75
+ await client.releaseLock('/manual/v1/intro', lock.lock_id);
76
+
77
+ // Full-text search (requires Meilisearch or Elasticsearch backend)
78
+ const results = await client.search({ query: 'installation guide', limit: 20 });
79
+
80
+ // Subscribe to real-time changes via WebSocket
81
+ const sub = client.subscribe(
82
+ { pattern: '/manual/*', event_type: '*' },
83
+ (event) => console.log('Change:', event)
84
+ );
85
+ ```
86
+
87
+ ### Constructor Options
88
+
89
+ ```typescript
90
+ interface XCiteDBClientOptions {
91
+ baseUrl: string; // Server URL, e.g. 'http://localhost:8080'
92
+ apiKey?: string; // Project API key (secret or public)
93
+ accessToken?: string; // Platform JWT (from platformLogin)
94
+ appUserAccessToken?: string; // End-user JWT (from loginAppUser)
95
+ context?: {
96
+ branch?: string; // Branch name; '' = default/root timeline
97
+ date?: string; // Point-in-time (ISO-like or internal date key)
98
+ prefix?: string; // Optional identifier prefix filter
99
+ tenant_id?: string; // Project/tenant ID for app-user auth
100
+ };
101
+ platformConsole?: boolean; // true = use X-Project-Id header
102
+ projectId?: string; // Active project for platform console mode
103
+ }
104
+ ```
105
+
106
+ ### Key Methods Reference
107
+
108
+ **Health & Auth:**
109
+ - `health()` — Liveness check (no auth)
110
+ - `version()` — Server version info
111
+ - `platformLogin(email, password)` — Platform operator sign-in
112
+ - `loginAppUser(email, password)` — App end-user sign-in
113
+ - `setContext(ctx)` — Update branch/date context
114
+ - `setProjectId(id)` — Switch active project (platform console)
115
+
116
+ **XML Documents:**
117
+ - `writeDocumentJson(xml, options?)` — Store XML (identifier inside XML body)
118
+ - `writeXML(xml)` — Store raw XML with `Content-Type: application/xml`
119
+ - `queryByIdentifier(id, flags?, filter?)` — Get document(s) by identifier
120
+ - `queryDocuments(query, flags?)` — List/filter documents
121
+ - `deleteDocument(identifier)` — Delete by identifier
122
+ - `listIdentifiers(query)` — List known identifiers with pagination
123
+ - `listIdentifierChildren(parentPath?)` — Navigate identifier hierarchy
124
+
125
+ **JSON Documents:**
126
+ - `writeJsonDocument(identifier, data)` — Store a JSON document
127
+ - `readJsonDocument(identifier)` — Read a JSON document
128
+ - `deleteJsonDocument(identifier)` — Delete a JSON document
129
+ - `listJsonDocuments(match?, limit?, offset?)` — List JSON document keys
130
+
131
+ **Metadata (JSON on XML):**
132
+ - `addMeta(identifier, value, path?)` — Set metadata on a document
133
+ - `appendMeta(identifier, value, path?)` — Append to metadata
134
+ - `queryMeta(identifier, path?)` — Read metadata
135
+ - `clearMeta(query)` — Remove metadata
136
+
137
+ **Versioning:**
138
+ - `createBranch(name, fromBranch?, fromDate?)` — Create branch
139
+ - `listBranches()` — List all branches
140
+ - `mergeBranch(target, source, options?)` — Merge branches
141
+ - `deleteBranch(name)` — Delete branch
142
+ - `createCommit(message, author?)` — Commit current state
143
+ - `listCommits(options?)` — List commits
144
+ - `rollbackToCommit(commitId)` — Rollback to prior commit
145
+ - `cherryPick(commitId, message?)` — Cherry-pick a commit
146
+ - `diff(from, to, includeContent?)` — Diff between revisions
147
+ - `createTag(name, commitId, message?)` — Tag a commit
148
+ - `listTags()` / `deleteTag(name)` — Manage tags
149
+
150
+ **Locks:**
151
+ - `acquireLock(identifier, expires?)` — Acquire cooperative lock
152
+ - `releaseLock(identifier, lockId)` — Release lock
153
+ - `findLocks(identifier)` — Query active locks
154
+
155
+ **Search & Analytics:**
156
+ - `search(query)` — Full-text search
157
+ - `reindex()` — Rebuild search index
158
+ - `unquery(query, unqueryDoc)` — Execute Unquery DSL
159
+
160
+ **Security & Policies:**
161
+ - `createPolicy(id, policy)` / `listPolicies()` / `updatePolicy()` / `deletePolicy()` — ABAC policies
162
+ - `checkAccess(subject, identifier, action)` — Dry-run access check
163
+ - `getSecurityConfig()` / `updateSecurityConfig()` — Security settings
164
+
165
+ **Triggers:**
166
+ - `upsertTrigger(id, trigger)` / `listTriggers()` / `deleteTrigger(name)` — Automation triggers
167
+
168
+ **App Users (admin):**
169
+ - `listAppUsers()` / `createAppUser()` / `deleteAppUser()` — Manage end-user accounts
170
+ - `registerAppUser()` — Self-registration
171
+ - `getAppAuthConfig()` — Auth configuration
172
+
173
+ **WebSocket:**
174
+ - `subscribe(options, callback, onError?)` — Real-time document change notifications
175
+
176
+ ### Query Flags
177
+
178
+ When calling `queryByIdentifier` or `queryDocuments`, the `flags` parameter controls matching:
179
+ - `'FirstMatch'` — Return only the first matching document
180
+ - `'IncludeChildren'` — Include child identifiers in results
181
+ - `'NoChildren'` — Exclude children
182
+ - `'KeepIndexNodes'` — Include index/structural nodes
183
+
184
+ ### Errors
185
+
186
+ All API errors throw `XCiteDBError` with `.status` (HTTP code) and `.body` (parsed response). Common codes: `401` unauthenticated, `403` forbidden by policy, `404` not found, `409` conflict (lock), `422` validation, `423` project encrypted and locked, `429` rate limited.
187
+
188
+ ## Python SDK (`xcitedb`)
189
+
190
+ Install: `pip install xcitedb`
191
+
192
+ ```python
193
+ import asyncio
194
+ from xcitedb import XCiteDBClient, XCiteQuery, DatabaseContext
195
+
196
+ async def main():
197
+ async with XCiteDBClient(
198
+ "http://localhost:8080",
199
+ api_key="your-key",
200
+ context=DatabaseContext(branch="", date=""),
201
+ ) as client:
202
+ print(await client.health())
203
+ ids = await client.query_documents(XCiteQuery(match_start="/manual/"))
204
+ print(ids)
205
+
206
+ asyncio.run(main())
207
+ ```
208
+
209
+ ## C++ SDK (`xcitedb`)
210
+
211
+ ```cpp
212
+ #include <xcitedb/xcitedb.hpp>
213
+
214
+ xcitedb::XCiteDBClientOptions opt;
215
+ opt.base_url = "http://127.0.0.1:8080";
216
+ opt.api_key = "your-key";
217
+ opt.context.branch = ""; // root timeline
218
+
219
+ xcitedb::XCiteDBClient client(opt);
220
+ auto health = client.health();
221
+ xcitedb::XCiteQuery q;
222
+ q.match_start = "/manual/";
223
+ auto ids = client.query_documents(q);
224
+ ```
225
+
226
+ ## Architecture Notes
227
+
228
+ - **Multi-tenant**: Each project is an isolated tenant with its own data, users, keys, and policies.
229
+ - **LMDB engine**: Data is memory-mapped; reads are microsecond-class on warm data.
230
+ - **Versioning**: Every write is versioned. Branches isolate work. Commits snapshot state. Time-travel reads any historical state via `X-Date`.
231
+ - **Two user tiers**: Platform operators manage infrastructure; App users are end-users of applications built on XciteDB.
232
+ - **Security policies (ABAC)**: Fine-grained allow/deny rules on actions, resources, roles, and branches.
233
+ - **WebSocket**: Real-time notifications for document changes at `/api/v1/ws`.
234
+
235
+ ## Documentation
236
+
237
+ Full API reference is available at your XciteDB server's `/docs` path. Key sections:
238
+ - Getting started — Base URL, headers, errors, pagination
239
+ - Documents — XML document CRUD, identifiers, hierarchy
240
+ - JSON documents — JSON document CRUD
241
+ - Metadata — JSON metadata on documents
242
+ - Search — Full-text search
243
+ - Unquery — Declarative query DSL
244
+ - Branches — Branch management
245
+ - Commits & tags — Version snapshots
246
+ - Locks — Cooperative editing locks
247
+ - Authentication — JWT, API keys, platform vs app users
248
+ - Security policies — ABAC access control
249
+ - Triggers — Automated webhooks on metadata changes
250
+ - App authentication — End-user registration, login, OAuth
251
+ - Project & API keys — Key management
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xcitedbs/client",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "XCiteDB BaaS client SDK",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -37,7 +37,9 @@
37
37
  "typescript": "^5.0.0"
38
38
  },
39
39
  "files": [
40
- "dist"
40
+ "dist",
41
+ "llms.txt",
42
+ "llms-full.txt"
41
43
  ],
42
44
  "license": "MIT"
43
45
  }