@cero-base/core 1.19.0 → 2.1.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.
- package/README.md +1 -1
- package/package.json +9 -6
- package/src/blobs/index.js +15 -15
- package/src/blobs/server.js +0 -2
- package/src/database/changes.js +4 -8
- package/src/database/dispatch.js +296 -227
- package/src/database/encryption.js +22 -52
- package/src/database/envelope.js +1 -3
- package/src/database/index.js +406 -476
- package/src/database/rotation.js +56 -70
- package/src/identity/index.js +5 -9
- package/src/index.js +5 -9
- package/src/lib/constants.js +3 -12
- package/src/lib/errors.js +6 -10
- package/src/lib/schema.js +2 -5
- package/src/lib/utils.js +9 -24
- package/src/network/index.js +144 -167
- package/src/network/presence.js +131 -0
- package/src/pairing/candidate.js +2 -4
- package/src/pairing/index.js +41 -55
- package/src/pairing/invite.js +3 -4
- package/src/pairing/request.js +3 -9
- package/src/rpc/index.js +4 -14
- package/src/rpc/peer.js +3 -7
- package/src/storage/index.js +29 -50
- package/types/blobs/index.d.ts +5 -5
- package/types/blobs/server.d.ts +0 -2
- package/types/database/changes.d.ts +2 -5
- package/types/database/dispatch.d.ts +11 -7
- package/types/database/encryption.d.ts +8 -20
- package/types/database/index.d.ts +164 -141
- package/types/database/rotation.d.ts +14 -20
- package/types/identity/index.d.ts +5 -9
- package/types/index.d.ts +4 -3
- package/types/lib/errors.d.ts +6 -10
- package/types/lib/schema.d.ts +2 -5
- package/types/lib/utils.d.ts +3 -7
- package/types/network/index.d.ts +28 -27
- package/types/network/presence.d.ts +50 -0
- package/types/pairing/candidate.d.ts +1 -2
- package/types/pairing/index.d.ts +22 -30
- package/types/pairing/invite.d.ts +3 -3
- package/types/pairing/request.d.ts +1 -3
- package/types/rpc/index.d.ts +1 -4
- package/types/rpc/peer.d.ts +2 -4
- package/types/storage/index.d.ts +17 -30
package/README.md
CHANGED
|
@@ -45,7 +45,7 @@ me.toPhrase() // back to words
|
|
|
45
45
|
|
|
46
46
|
## Storage
|
|
47
47
|
|
|
48
|
-
Hyperbee or Rocks-backed local table store with a uniform put/set/get/del/
|
|
48
|
+
Hyperbee or Rocks-backed local table store with a uniform put/set/get/del/watch surface.
|
|
49
49
|
|
|
50
50
|
```js
|
|
51
51
|
import { Storage } from '@cero-base/core/storage'
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cero-base/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "cero p2p primitives — identity, storage, network, database, blobs, rpc, pairing.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"engines": {
|
|
8
|
-
"node": ">=
|
|
8
|
+
"node": ">=22"
|
|
9
9
|
},
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
@@ -18,8 +18,7 @@
|
|
|
18
18
|
"src",
|
|
19
19
|
"types",
|
|
20
20
|
"README.md",
|
|
21
|
-
"LICENSE"
|
|
22
|
-
"!**/CLAUDE.md"
|
|
21
|
+
"LICENSE"
|
|
23
22
|
],
|
|
24
23
|
"publishConfig": {
|
|
25
24
|
"access": "public"
|
|
@@ -121,6 +120,10 @@
|
|
|
121
120
|
"events": {
|
|
122
121
|
"bare": "bare-events",
|
|
123
122
|
"default": "events"
|
|
123
|
+
},
|
|
124
|
+
"process": {
|
|
125
|
+
"bare": "bare-process",
|
|
126
|
+
"default": "process"
|
|
124
127
|
}
|
|
125
128
|
},
|
|
126
129
|
"scripts": {
|
|
@@ -130,13 +133,13 @@
|
|
|
130
133
|
"pretest": "npm run build:test",
|
|
131
134
|
"prepublishOnly": "npm run build:types",
|
|
132
135
|
"test": "npm run test:bare",
|
|
133
|
-
"test:bare": "brittle-bare
|
|
136
|
+
"test:bare": "brittle-bare $(find test -name '*.test.js' | sort)",
|
|
134
137
|
"pretest:bare": "npm run build:test",
|
|
135
138
|
"test:node": "brittle-node $(find test -name '*.test.js' | sort)"
|
|
136
139
|
},
|
|
137
140
|
"dependencies": {
|
|
138
141
|
"@hyperswarm/secret-stream": "^6.9.1",
|
|
139
|
-
"autobee": "^2.
|
|
142
|
+
"autobee": "^2.1.1",
|
|
140
143
|
"autobee-encryption": "0.1.3",
|
|
141
144
|
"b4a": "^1.8.1",
|
|
142
145
|
"bare-crypto": "^1.15.3",
|
package/src/blobs/index.js
CHANGED
|
@@ -109,21 +109,6 @@ export class Blobs extends ReadyResource {
|
|
|
109
109
|
throw CeroError.INVALID('input must be a buffer or a Readable stream')
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
/**
|
|
113
|
-
* @param {import('streamx').Readable} input
|
|
114
|
-
* @returns {Promise<RawBlobId>}
|
|
115
|
-
*/
|
|
116
|
-
async _putStream(input) {
|
|
117
|
-
const ws = this.hyperblobs.createWriteStream()
|
|
118
|
-
await new Promise((resolve, reject) => {
|
|
119
|
-
input.on('error', reject)
|
|
120
|
-
ws.on('error', reject)
|
|
121
|
-
ws.on('close', resolve)
|
|
122
|
-
input.pipe(ws)
|
|
123
|
-
})
|
|
124
|
-
return ws.id
|
|
125
|
-
}
|
|
126
|
-
|
|
127
112
|
/**
|
|
128
113
|
* Resolve the blob bytes for a raw blobId. Fetches from peers if not local.
|
|
129
114
|
*
|
|
@@ -159,6 +144,21 @@ export class Blobs extends ReadyResource {
|
|
|
159
144
|
await this.hyperblobs.clear(blobId)
|
|
160
145
|
}
|
|
161
146
|
|
|
147
|
+
/**
|
|
148
|
+
* @param {import('streamx').Readable} input
|
|
149
|
+
* @returns {Promise<RawBlobId>}
|
|
150
|
+
*/
|
|
151
|
+
async _putStream(input) {
|
|
152
|
+
const ws = this.hyperblobs.createWriteStream()
|
|
153
|
+
await new Promise((resolve, reject) => {
|
|
154
|
+
input.on('error', reject)
|
|
155
|
+
ws.on('error', reject)
|
|
156
|
+
ws.on('close', resolve)
|
|
157
|
+
input.pipe(ws)
|
|
158
|
+
})
|
|
159
|
+
return ws.id
|
|
160
|
+
}
|
|
161
|
+
|
|
162
162
|
_guard() {
|
|
163
163
|
if (this.closed) throw CeroError.CLOSED('Blobs')
|
|
164
164
|
if (!this.opened) throw CeroError.NOT_READY('Blobs', 'blobs')
|
package/src/blobs/server.js
CHANGED
|
@@ -7,8 +7,6 @@ import { decodeId } from './index.js'
|
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* HTTP server that turns a string file id into a renderable localhost URL.
|
|
10
|
-
* Wraps hypercore-blob-server; the underlying store session is owned by
|
|
11
|
-
* BlobServer and closed when `close()` is called.
|
|
12
10
|
*/
|
|
13
11
|
export class FileServer {
|
|
14
12
|
/**
|
package/src/database/changes.js
CHANGED
|
@@ -2,11 +2,8 @@ import { Readable } from 'streamx'
|
|
|
2
2
|
import b4a from 'b4a'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Pull-driven delta stream over a collection: batches of `{ prev, next }`
|
|
6
|
-
*
|
|
7
|
-
* mark the stream dirty, the diff runs when the reader asks, so bursts fold
|
|
8
|
-
* into one batch and nothing is dropped. The first batch, and any batch after
|
|
9
|
-
* the view moved to another core, is the full matching state with `reset: true`.
|
|
5
|
+
* Pull-driven delta stream over a collection: batches of `{ prev, next }` pairs diffed
|
|
6
|
+
* from the head this stream last reported.
|
|
10
7
|
*
|
|
11
8
|
* @param {import('./index.js').Database} db
|
|
12
9
|
* @param {string} name Ref name (scopes the update ticks).
|
|
@@ -23,7 +20,7 @@ export function makeChanges(db, name, col, matches) {
|
|
|
23
20
|
dirty = true
|
|
24
21
|
if (wake !== null) wake()
|
|
25
22
|
}
|
|
26
|
-
const off = db.onUpdate(
|
|
23
|
+
const off = db.onUpdate(name, mark)
|
|
27
24
|
|
|
28
25
|
const stream = new Readable({
|
|
29
26
|
async read(cb) {
|
|
@@ -48,8 +45,7 @@ export function makeChanges(db, name, col, matches) {
|
|
|
48
45
|
|
|
49
46
|
const diff = async () => {
|
|
50
47
|
const view = db.view
|
|
51
|
-
// snapshot() and head() are synchronous, so
|
|
52
|
-
// the same state and the cursor is exactly-once
|
|
48
|
+
// snapshot() and head() are synchronous, so the cursor is exactly-once
|
|
53
49
|
const snap = view.snapshot()
|
|
54
50
|
const head = view.engine.head()
|
|
55
51
|
const reset =
|