@yydb/light-db 0.0.12 → 0.0.15

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 (2) hide show
  1. package/package.json +29 -29
  2. package/readme.md +110 -110
package/package.json CHANGED
@@ -1,18 +1,23 @@
1
1
  {
2
- "name": "@yydb/light-db",
3
- "version": "0.0.12",
2
+ "author": "YYDB Contributors",
3
+ "bugs": {
4
+ "url": "https://github.com/yy-database/yydb.rs/issues"
5
+ },
6
+ "dependencies": {
7
+ "@voml/vos": "^0.0.1",
8
+ "@yydb/yydb-unknown-wasm32": "0.0.15"
9
+ },
4
10
  "description": "Light DB — browser-native YYDB database written in pure TypeScript",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
11
+ "devDependencies": {
12
+ "@types/node": "^20.19.43",
13
+ "playwright-core": "^1.64.1",
14
+ "tsx": "^4.23.15",
15
+ "typescript": "^5.3.0"
16
+ },
7
17
  "files": [
8
18
  "dist"
9
19
  ],
10
- "scripts": {
11
- "build": "tsc",
12
- "typecheck": "tsc --noEmit",
13
- "test": "tsx tests/index.ts",
14
- "test:browser": "tsx tests/browser/run.ts"
15
- },
20
+ "homepage": "https://github.com/yy-database/yydb.rs/tree/dev/projects/packages/light-db#readme",
16
21
  "keywords": [
17
22
  "yydb",
18
23
  "light-db",
@@ -23,27 +28,22 @@
23
28
  "typescript"
24
29
  ],
25
30
  "license": "MPL-2.0",
26
- "author": "YYDB Contributors",
27
- "repository": {
28
- "type": "git",
29
- "url": "git+https://github.com/yy-database/yydb.git",
30
- "directory": "projects/packages/light-db"
31
- },
32
- "homepage": "https://github.com/yy-database/yydb/tree/dev/projects/packages/light-db#readme",
33
- "bugs": {
34
- "url": "https://github.com/yy-database/yydb/issues"
35
- },
31
+ "main": "dist/index.js",
32
+ "name": "@yydb/light-db",
36
33
  "publishConfig": {
37
34
  "access": "public"
38
35
  },
39
- "devDependencies": {
40
- "@types/node": "^20.19.43",
41
- "playwright-core": "^1.64.1",
42
- "tsx": "^4.23.15",
43
- "typescript": "^5.3.0"
36
+ "repository": {
37
+ "directory": "projects/packages/light-db",
38
+ "type": "git",
39
+ "url": "git+https://github.com/yy-database/yydb.rs.git"
44
40
  },
45
- "dependencies": {
46
- "@voml/vos": "^0.0.1",
47
- "@yydb/yydb-unknown-wasm32": "workspace:*"
48
- }
41
+ "scripts": {
42
+ "build": "tsc",
43
+ "test": "tsx tests/index.ts",
44
+ "test:browser": "tsx tests/browser/run.ts",
45
+ "typecheck": "tsc --noEmit"
46
+ },
47
+ "types": "dist/index.d.ts",
48
+ "version": "0.0.15"
49
49
  }
package/readme.md CHANGED
@@ -1,110 +1,110 @@
1
- # `@yydb/light-db`
2
-
3
- **Light DB** is the browser edition of YYDB: a database written in pure TypeScript that stores `.yydb`-style
4
- snapshots, WAL records and checkpoints in browser storage. It has no Node built-ins, no N-API bindings and no WASM in
5
- its runtime path.
6
-
7
- ## Product relationship
8
-
9
- | Package | Role |
10
- |---------|------|
11
- | `@yydb/yydb` | Node product: native Rust engine, N-API, local `.yydb` / `.yydx` files and CLI |
12
- | `@yydb/light-db` | Browser product: pure TypeScript, OPFS / IndexedDB storage, Web APIs, same author surface |
13
- | `@yydb/yydb-client` | Remote wire client for a running `yydb serve` |
14
-
15
- ## Status
16
-
17
- Light DB is a migration of the original `LightDB.ts` engine, rebuilt around a browser-native architecture. The package
18
- ships as a pre-1.0 release of the browser product, so the author surface may still change between patch releases.
19
-
20
- Current coverage:
21
-
22
- - `pnpm test` runs the Node-side runner over codec, adapter and database logic (29 cases).
23
- - `pnpm test:browser` runs the conformance suite in an installed Chrome (16 cases): OPFS persistence across reopen, WAL
24
- recovery, checkpoint truncation, corruption detection, single-writer exclusion, transaction rollback and commit,
25
- schema and close notifications, and two-tab lease and broadcast behaviour.
26
-
27
- ## Usage
28
-
29
- ```ts
30
- import { LightDbError, openLightDatabase } from '@yydb/light-db';
31
-
32
- const db = await openLightDatabase('app');
33
-
34
- await db.ensureSchema('// @yydb-schema-version: 1\nkv users');
35
- await db.put('user:1', new TextEncoder().encode('Ada'));
36
-
37
- const value = await db.get('user:1');
38
- await db.checkpoint();
39
- await db.close();
40
- ```
41
-
42
- Public data types are browser-native: keys and values use `Uint8Array`, databases are addressed by name rather than by
43
- file path, and every lifecycle call is asynchronous.
44
-
45
- ## Author surface
46
-
47
- ```ts
48
- const db: LightDatabase = await openLightDatabase('app', options);
49
-
50
- await db.schema();
51
- await db.ensureSchema(document);
52
- await db.get(key);
53
- await db.put(key, value);
54
- await db.delete(key);
55
- await db.begin();
56
- await db.commit();
57
- await db.rollback();
58
- await db.checkpoint();
59
- db.stats();
60
- await db.close();
61
- ```
62
-
63
- `schema()` returns the persisted schema version and document. The document is the single source of truth: a second
64
- `ensureSchema` call must pass the identical document, otherwise it fails with `yydb.schema.conflict`. Keys starting with
65
- `__yydb__/` are reserved for the database.
66
-
67
- ## Storage backends
68
-
69
- | Adapter | Use |
70
- |---------|-----|
71
- | `OpfsStorageAdapterFactory` | Default. Origin Private File System, positional reads and writes, atomic snapshot publication |
72
- | `IndexedDbStorageAdapterFactory` | Compatibility backend for hosts without OPFS |
73
- | `MemoryStorageBackend` | Tests and throwaway sessions |
74
-
75
- `StorageAdapter` is the only platform boundary. Transactions, recovery and checkpoint semantics live in `core`, so
76
- backends implement files, not database behaviour.
77
-
78
- ## Concurrency
79
-
80
- A writer holds a session-scoped `Web Locks` lease. A second tab that opens the same database fails with
81
- `yydb.lease.unavailable` and `retryable: true` instead of silently writing alongside the first one. When a lock manager
82
- is missing the call fails the same way; it never degrades to multiple writers.
83
-
84
- `BroadcastChannel` carries `commit`, `schema` and `close` events so other same-origin contexts can discard stale views
85
- and retry after the lease is released. `listenDatabaseEvents(name, handler)` subscribes without opening the database.
86
-
87
- ## Layout
88
-
89
- | Path | Role |
90
- |------|------|
91
- | `src/api/` | Public database, transaction, schema and shared types |
92
- | `src/core/` | Records, WAL, checkpoint, recovery, writer lease and broadcast |
93
- | `src/storage/` | `StorageAdapter` plus OPFS, IndexedDB and memory backends |
94
- | `src/codec/` | Page, snapshot and WAL record encoding over `Uint8Array` |
95
- | `src/errors/` | Stable `yydb.*` error codes |
96
-
97
- ## Errors
98
-
99
- | Code | Meaning |
100
- |------|---------|
101
- | `yydb.io` | Storage operation failed |
102
- | `yydb.corrupt` | Persisted bytes failed validation |
103
- | `yydb.schema.conflict` | Schema document differs from the stored one |
104
- | `yydb.schema.invalid` | Schema document is not usable |
105
- | `yydb.unsupported` | Host or operation is not supported |
106
- | `yydb.session.closed` | Database or handle is closed |
107
- | `yydb.lease.unavailable` | Writer lease is held elsewhere or Web Locks is missing (retryable) |
108
- | `yydb.quota.exceeded` | Browser storage quota is exhausted |
109
-
110
- [YYDB overview](https://github.com/yy-database/yydb.rs)
1
+ # `@yydb/light-db`
2
+
3
+ **Light DB** is the browser edition of YYDB: a database written in pure TypeScript that stores `.yydb`-style
4
+ snapshots, WAL records and checkpoints in browser storage. It has no Node built-ins, no N-API bindings and no WASM in
5
+ its runtime path.
6
+
7
+ ## Product relationship
8
+
9
+ | Package | Role |
10
+ |---------|------|
11
+ | `@yydb/yydb` | Node product: native Rust engine, N-API, local `.yydb` / `.yydx` files and CLI |
12
+ | `@yydb/light-db` | Browser product: pure TypeScript, OPFS / IndexedDB storage, Web APIs, same author surface |
13
+ | `@yydb/yydb-client` | Remote wire client for a running `yydb serve` |
14
+
15
+ ## Status
16
+
17
+ Light DB is a migration of the original `LightDB.ts` engine, rebuilt around a browser-native architecture. The package
18
+ ships as a pre-1.0 release of the browser product, so the author surface may still change between patch releases.
19
+
20
+ Current coverage:
21
+
22
+ - `pnpm test` runs the Node-side runner over codec, adapter and database logic (29 cases).
23
+ - `pnpm test:browser` runs the conformance suite in an installed Chrome (16 cases): OPFS persistence across reopen, WAL
24
+ recovery, checkpoint truncation, corruption detection, single-writer exclusion, transaction rollback and commit,
25
+ schema and close notifications, and two-tab lease and broadcast behaviour.
26
+
27
+ ## Usage
28
+
29
+ ```ts
30
+ import { LightDbError, openLightDatabase } from '@yydb/light-db';
31
+
32
+ const db = await openLightDatabase('app');
33
+
34
+ await db.ensureSchema('// @yydb-schema-version: 1\nkv users');
35
+ await db.put('user:1', new TextEncoder().encode('Ada'));
36
+
37
+ const value = await db.get('user:1');
38
+ await db.checkpoint();
39
+ await db.close();
40
+ ```
41
+
42
+ Public data types are browser-native: keys and values use `Uint8Array`, databases are addressed by name rather than by
43
+ file path, and every lifecycle call is asynchronous.
44
+
45
+ ## Author surface
46
+
47
+ ```ts
48
+ const db: LightDatabase = await openLightDatabase('app', options);
49
+
50
+ await db.schema();
51
+ await db.ensureSchema(document);
52
+ await db.get(key);
53
+ await db.put(key, value);
54
+ await db.delete(key);
55
+ await db.begin();
56
+ await db.commit();
57
+ await db.rollback();
58
+ await db.checkpoint();
59
+ db.stats();
60
+ await db.close();
61
+ ```
62
+
63
+ `schema()` returns the persisted schema version and document. The document is the single source of truth: a second
64
+ `ensureSchema` call must pass the identical document, otherwise it fails with `yydb.schema.conflict`. Keys starting with
65
+ `__yydb__/` are reserved for the database.
66
+
67
+ ## Storage backends
68
+
69
+ | Adapter | Use |
70
+ |---------|-----|
71
+ | `OpfsStorageAdapterFactory` | Default. Origin Private File System, positional reads and writes, atomic snapshot publication |
72
+ | `IndexedDbStorageAdapterFactory` | Compatibility backend for hosts without OPFS |
73
+ | `MemoryStorageBackend` | Tests and throwaway sessions |
74
+
75
+ `StorageAdapter` is the only platform boundary. Transactions, recovery and checkpoint semantics live in `core`, so
76
+ backends implement files, not database behaviour.
77
+
78
+ ## Concurrency
79
+
80
+ A writer holds a session-scoped `Web Locks` lease. A second tab that opens the same database fails with
81
+ `yydb.lease.unavailable` and `retryable: true` instead of silently writing alongside the first one. When a lock manager
82
+ is missing the call fails the same way; it never degrades to multiple writers.
83
+
84
+ `BroadcastChannel` carries `commit`, `schema` and `close` events so other same-origin contexts can discard stale views
85
+ and retry after the lease is released. `listenDatabaseEvents(name, handler)` subscribes without opening the database.
86
+
87
+ ## Layout
88
+
89
+ | Path | Role |
90
+ |------|------|
91
+ | `src/api/` | Public database, transaction, schema and shared types |
92
+ | `src/core/` | Records, WAL, checkpoint, recovery, writer lease and broadcast |
93
+ | `src/storage/` | `StorageAdapter` plus OPFS, IndexedDB and memory backends |
94
+ | `src/codec/` | Page, snapshot and WAL record encoding over `Uint8Array` |
95
+ | `src/errors/` | Stable `yydb.*` error codes |
96
+
97
+ ## Errors
98
+
99
+ | Code | Meaning |
100
+ |------|---------|
101
+ | `yydb.io` | Storage operation failed |
102
+ | `yydb.corrupt` | Persisted bytes failed validation |
103
+ | `yydb.schema.conflict` | Schema document differs from the stored one |
104
+ | `yydb.schema.invalid` | Schema document is not usable |
105
+ | `yydb.unsupported` | Host or operation is not supported |
106
+ | `yydb.session.closed` | Database or handle is closed |
107
+ | `yydb.lease.unavailable` | Writer lease is held elsewhere or Web Locks is missing (retryable) |
108
+ | `yydb.quota.exceeded` | Browser storage quota is exhausted |
109
+
110
+ [YYDB overview](https://github.com/yy-database/yydb.rs)