js-bao-wss-client 2.2.0-alpha.12 → 2.2.0-alpha.14
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/README.md +60 -6
- package/dist/JsBaoClient.d.ts +510 -13
- package/dist/JsBaoClient.js +1189 -53
- package/dist/api/databaseTypeConfigsApi.d.ts +3 -5
- package/dist/api/databasesApi.d.ts +3 -0
- package/dist/api/documentsApi.d.ts +80 -4
- package/dist/api/documentsApi.js +35 -3
- package/dist/api/geminiApi.d.ts +5 -2
- package/dist/api/geminiApi.js +5 -2
- package/dist/api/invitationsApi.d.ts +7 -4
- package/dist/api/invitationsApi.js +3 -1
- package/dist/browser.umd.js +3187 -387
- package/dist/errors.d.ts +1 -1
- package/dist/internal/authController.d.ts +20 -1
- package/dist/internal/authController.js +24 -4
- package/dist/internal/documentManager.d.ts +500 -11
- package/dist/internal/documentManager.js +1055 -153
- package/dist/internal/functionRunStatus.js +4 -1
- package/dist/internal/large-documents/document-format.d.ts +19 -0
- package/dist/internal/large-documents/document-format.js +24 -0
- package/dist/internal/large-documents/persisted-naming.d.ts +45 -0
- package/dist/internal/large-documents/persisted-naming.js +70 -0
- package/dist/internal/offlineStore.d.ts +56 -0
- package/dist/internal/offlineStore.js +151 -18
- package/dist/internal/storage/indexedDbStorageProvider.d.ts +16 -0
- package/dist/internal/storage/indexedDbStorageProvider.js +71 -0
- package/dist/internal/storage/memoryStorageProvider.d.ts +9 -0
- package/dist/internal/storage/memoryStorageProvider.js +24 -0
- package/dist/internal/storage/sqliteStorageProvider.d.ts +16 -0
- package/dist/internal/storage/sqliteStorageProvider.js +59 -0
- package/dist/internal/storage/types.d.ts +64 -5
- package/dist/internal/y-indexeddb/src/y-indexeddb.d.ts +25 -2
- package/dist/internal/y-indexeddb/src/y-indexeddb.js +439 -80
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -123,9 +123,10 @@ const client = await initializeClient({
|
|
|
123
123
|
appId: "my-app",
|
|
124
124
|
models: [Task, Project],
|
|
125
125
|
|
|
126
|
-
// Yjs document persistence for Node.js
|
|
127
|
-
|
|
128
|
-
|
|
126
|
+
// Yjs document persistence for Node.js. The first argument is the store
|
|
127
|
+
// name — see "What the first argument is" below.
|
|
128
|
+
yjsPersistence: (storeName, ydoc, { appId, userId }) => {
|
|
129
|
+
return new SqlitePersistence(storeName, ydoc, {
|
|
129
130
|
dbPath: `${process.env.HOME}/.my-app/${appId}/${userId}/yjs.sqlite`
|
|
130
131
|
});
|
|
131
132
|
},
|
|
@@ -137,6 +138,34 @@ const { ydoc } = await client.documents.open("doc-123", {
|
|
|
137
138
|
});
|
|
138
139
|
```
|
|
139
140
|
|
|
141
|
+
**What the first argument is**
|
|
142
|
+
|
|
143
|
+
The factory's first argument is the **store name** to persist this Yjs state
|
|
144
|
+
under, not necessarily the document id. For an ordinary document, and for a
|
|
145
|
+
large document (`documentFormat: 2`) that has not rotated yet, the two are the
|
|
146
|
+
same value.
|
|
147
|
+
|
|
148
|
+
A large document's Yjs state is an epoch *overlay* rather than the document
|
|
149
|
+
itself, so once it rotates each epoch gets its own store name,
|
|
150
|
+
`{documentId}@{epoch}`. A rotation attaches a provider for the fresh epoch and
|
|
151
|
+
then clears the sealed one, so a factory that put both epochs under one name
|
|
152
|
+
would lose every write made since the rotation to that clear. Keying your
|
|
153
|
+
storage on the first argument — as the example above does — is correct for both
|
|
154
|
+
kinds of document, and needs no change when a document grows large.
|
|
155
|
+
|
|
156
|
+
The third argument carries the rest of what the store is for:
|
|
157
|
+
|
|
158
|
+
| Field | Meaning |
|
|
159
|
+
|-------|---------|
|
|
160
|
+
| `appId` | The application id |
|
|
161
|
+
| `userId` | The authenticated user, or `"anon"` |
|
|
162
|
+
| `documentId` | The plain document id, without the epoch suffix |
|
|
163
|
+
| `documentFormat` | `2` for a large document, `1` for an ordinary one — absent on the very first open of a document created elsewhere, whose format nothing local knows yet |
|
|
164
|
+
| `epoch` | The epoch the store name is scoped to, or `null` when the name is the plain document id |
|
|
165
|
+
|
|
166
|
+
Use `context.documentId` when you want to group every store belonging to one
|
|
167
|
+
document; use the first argument whenever you are naming storage.
|
|
168
|
+
|
|
140
169
|
**Why two storage systems?**
|
|
141
170
|
|
|
142
171
|
- `storageConfig` → General key-value data (auth, cache, metadata)
|
|
@@ -1251,15 +1280,19 @@ console.log(result.documentId); // The created document ID
|
|
|
1251
1280
|
console.log(result.alias.aliasKey); // "current-draft"
|
|
1252
1281
|
console.log(result.alias.documentId); // Same as documentId
|
|
1253
1282
|
|
|
1254
|
-
// The alias create takes
|
|
1255
|
-
//
|
|
1256
|
-
//
|
|
1283
|
+
// The alias create takes the whole create vocabulary — `tags`, `metadata` and
|
|
1284
|
+
// `documentFormat` — with the same meaning they have on `create()`: applied when
|
|
1285
|
+
// the call creates the document. The response echoes what it applied, and omits
|
|
1286
|
+
// `documentFormat` for an ordinary document.
|
|
1257
1287
|
const ledger = await client.documents.createWithAlias({
|
|
1258
1288
|
title: "Ledger",
|
|
1259
1289
|
alias: { scope: "user", aliasKey: "ledger" },
|
|
1290
|
+
tags: ["ledger", "q3"],
|
|
1291
|
+
metadata: { owner: "finance" },
|
|
1260
1292
|
documentFormat: 2,
|
|
1261
1293
|
});
|
|
1262
1294
|
console.log(ledger.documentFormat); // 2
|
|
1295
|
+
console.log(ledger.tags); // ["ledger", "q3"]
|
|
1263
1296
|
|
|
1264
1297
|
// Attempting to create with an existing alias throws HTTP 409
|
|
1265
1298
|
try {
|
|
@@ -1281,6 +1314,27 @@ try {
|
|
|
1281
1314
|
|
|
1282
1315
|
Use `createWithAlias()` when you need guaranteed uniqueness based on an alias (e.g., "only one home page per app"). Use regular `create()` + `aliases.set()` when offline support is needed or when the document should be created regardless of alias conflicts.
|
|
1283
1316
|
|
|
1317
|
+
#### Get-or-Create with Alias
|
|
1318
|
+
|
|
1319
|
+
When you want the document to exist rather than to be new — "this user's ledger" — `getOrCreateWithAlias()` is the idempotent form: the first call creates it, every later one returns the same document. It takes the same options, applied only when the call creates the document:
|
|
1320
|
+
|
|
1321
|
+
```typescript
|
|
1322
|
+
const ledger = await client.documents.getOrCreateWithAlias({
|
|
1323
|
+
title: "Ledger",
|
|
1324
|
+
alias: { scope: "user", aliasKey: "ledger" },
|
|
1325
|
+
tags: ["ledger"],
|
|
1326
|
+
documentFormat: 2,
|
|
1327
|
+
});
|
|
1328
|
+
|
|
1329
|
+
console.log(ledger.created); // true on the call that made it, false after
|
|
1330
|
+
console.log(ledger.documentFormat); // 2 either way
|
|
1331
|
+
console.log(ledger.tags); // ["ledger"] on the create; absent afterwards
|
|
1332
|
+
```
|
|
1333
|
+
|
|
1334
|
+
A stated `documentFormat` is also a statement about a document the alias already names. If the stored format **differs**, the call is refused with `DOCUMENT_FORMAT_MISMATCH` (409) naming the document and both formats, and nothing is created — being handed an ordinary document when you asked for a large one is the mistake this route exists to prevent. If it agrees, the format is echoed. Omit it and an existing binding is answered exactly as it always was.
|
|
1335
|
+
|
|
1336
|
+
> All three create routes refuse a top-level body key they do not read, with 400 `VALIDATION_FAILED` and a `details` entry naming it. The typed methods above send only keys the routes read; this reaches you only if you build a request body by hand.
|
|
1337
|
+
|
|
1284
1338
|
### Manage Permissions
|
|
1285
1339
|
|
|
1286
1340
|
```typescript
|