@cero-base/cero 0.8.7 → 0.8.8
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/package.json +2 -2
- package/src/lib/operators.js +8 -3
- package/src/rpc/client.js +34 -2
- package/types/rpc/client.d.ts +43 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cero-base/cero",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.8",
|
|
4
4
|
"description": "The ideal p2p API — everything is a handle, handles contain refs, refs contain rows.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
"test": "ls test/*.test.js | xargs -P1 -n1 brittle-node"
|
|
79
79
|
},
|
|
80
80
|
"dependencies": {
|
|
81
|
-
"@cero-base/core": "^0.8.
|
|
81
|
+
"@cero-base/core": "^0.8.8",
|
|
82
82
|
"b4a": "^1.8.1",
|
|
83
83
|
"bare-abort-controller": "^1.1.2",
|
|
84
84
|
"bare-crypto": "^1.14.1",
|
package/src/lib/operators.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { Readable } from 'streamx'
|
|
2
|
-
import HypercoreStorage from 'hypercore-storage'
|
|
3
|
-
import Corestore from 'corestore'
|
|
4
2
|
|
|
5
3
|
import { CeroError } from '@cero-base/core/errors'
|
|
6
4
|
|
|
7
5
|
import { onAbort } from './utils.js'
|
|
8
|
-
|
|
6
|
+
|
|
7
|
+
// `peek` (below) lazy-imports hypercore-storage / corestore / local so this
|
|
8
|
+
// module — which the lightweight RPC client re-exports — stays free of native
|
|
9
|
+
// deps. A client never calls `peek`, so the heavy imports load only on the core.
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* @typedef {import('./utils.js').Ref} Ref
|
|
@@ -205,6 +206,10 @@ export async function peek(dir, spec) {
|
|
|
205
206
|
if (typeof dir !== 'string' || !dir) throw CeroError.INVALID('dir must be a non-empty string')
|
|
206
207
|
if (!spec) throw CeroError.REQUIRED('spec')
|
|
207
208
|
|
|
209
|
+
const { default: HypercoreStorage } = await import('hypercore-storage')
|
|
210
|
+
const { default: Corestore } = await import('corestore')
|
|
211
|
+
const { Local } = await import('../local/index.js')
|
|
212
|
+
|
|
208
213
|
const root = new HypercoreStorage(`${dir}/main`)
|
|
209
214
|
await root.ready()
|
|
210
215
|
const store = new Corestore(root, { manifestVersion: 2 })
|
package/src/rpc/client.js
CHANGED
|
@@ -2,9 +2,10 @@ import { Readable } from 'streamx'
|
|
|
2
2
|
import { RPCClient, bindCodec } from '@cero-base/core/rpc'
|
|
3
3
|
|
|
4
4
|
import { attachRefs } from '../lib/utils.js'
|
|
5
|
-
import { bind } from '../lib/operators.js'
|
|
5
|
+
import { put, set, get, del, count, watch, call, open, bind, define } from '../lib/operators.js'
|
|
6
|
+
import { t, schema } from '../lib/spec.js'
|
|
6
7
|
|
|
7
|
-
export { put, set, get, del, count, watch, call, open
|
|
8
|
+
export { put, set, get, del, count, watch, call, open, bind, define, t, schema }
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* @typedef {import('@cero-base/core/rpc').RPCClient} BaseRPCClient
|
|
@@ -397,3 +398,34 @@ export async function connect(ipc, spec) {
|
|
|
397
398
|
await client.ready()
|
|
398
399
|
return client
|
|
399
400
|
}
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Symmetric client entry. Mirrors the main `cero`, but `cero(ipc, spec)` connects
|
|
404
|
+
* to a server (via `connect`) instead of opening a local store. The same operator
|
|
405
|
+
* surface is attached, so `import { cero } from '@cero-base/cero/client'` works
|
|
406
|
+
* just like `import { cero } from '@cero-base/cero'`.
|
|
407
|
+
*
|
|
408
|
+
* Note: `before`/`after`/`peek` are intentionally not exposed here — they hook the
|
|
409
|
+
* local write path / probe a local store, which a client proxy has no notion of.
|
|
410
|
+
*
|
|
411
|
+
* @param {any} ipc Framed IPC duplex stream.
|
|
412
|
+
* @param {any} spec Built cero spec.
|
|
413
|
+
* @returns {Promise<Client>}
|
|
414
|
+
*/
|
|
415
|
+
export function cero(ipc, spec) {
|
|
416
|
+
return connect(ipc, spec)
|
|
417
|
+
}
|
|
418
|
+
cero.connect = connect
|
|
419
|
+
cero.restore = restore
|
|
420
|
+
cero.t = t
|
|
421
|
+
cero.put = put
|
|
422
|
+
cero.set = set
|
|
423
|
+
cero.get = get
|
|
424
|
+
cero.del = del
|
|
425
|
+
cero.count = count
|
|
426
|
+
cero.watch = watch
|
|
427
|
+
cero.call = call
|
|
428
|
+
cero.open = open
|
|
429
|
+
cero.bind = bind
|
|
430
|
+
cero.define = define
|
|
431
|
+
cero.schema = schema
|
package/types/rpc/client.d.ts
CHANGED
|
@@ -15,6 +15,36 @@ export function restore(me: Client, phrase: string): Promise<Client>;
|
|
|
15
15
|
* @returns {Promise<Client>}
|
|
16
16
|
*/
|
|
17
17
|
export function connect(ipc: any, spec: object): Promise<Client>;
|
|
18
|
+
/**
|
|
19
|
+
* Symmetric client entry. Mirrors the main `cero`, but `cero(ipc, spec)` connects
|
|
20
|
+
* to a server (via `connect`) instead of opening a local store. The same operator
|
|
21
|
+
* surface is attached, so `import { cero } from '@cero-base/cero/client'` works
|
|
22
|
+
* just like `import { cero } from '@cero-base/cero'`.
|
|
23
|
+
*
|
|
24
|
+
* Note: `before`/`after`/`peek` are intentionally not exposed here — they hook the
|
|
25
|
+
* local write path / probe a local store, which a client proxy has no notion of.
|
|
26
|
+
*
|
|
27
|
+
* @param {any} ipc Framed IPC duplex stream.
|
|
28
|
+
* @param {any} spec Built cero spec.
|
|
29
|
+
* @returns {Promise<Client>}
|
|
30
|
+
*/
|
|
31
|
+
export function cero(ipc: any, spec: any): Promise<Client>;
|
|
32
|
+
export namespace cero {
|
|
33
|
+
export { connect };
|
|
34
|
+
export { restore };
|
|
35
|
+
export { t };
|
|
36
|
+
export { put };
|
|
37
|
+
export { set };
|
|
38
|
+
export { get };
|
|
39
|
+
export { del };
|
|
40
|
+
export { count };
|
|
41
|
+
export { watch };
|
|
42
|
+
export { call };
|
|
43
|
+
export { open };
|
|
44
|
+
export { bind };
|
|
45
|
+
export { define };
|
|
46
|
+
export { schema };
|
|
47
|
+
}
|
|
18
48
|
/**
|
|
19
49
|
* IPC-side RPC client for cero. Wraps an `hrpc` channel and exposes the
|
|
20
50
|
* same handle/ref/row API as a local cero instance, transparently
|
|
@@ -100,6 +130,18 @@ export type HandleStub = {
|
|
|
100
130
|
type: string;
|
|
101
131
|
name: string | null;
|
|
102
132
|
};
|
|
133
|
+
import { t } from '../lib/spec.js';
|
|
134
|
+
import { put } from '../lib/operators.js';
|
|
135
|
+
import { set } from '../lib/operators.js';
|
|
136
|
+
import { get } from '../lib/operators.js';
|
|
137
|
+
import { del } from '../lib/operators.js';
|
|
138
|
+
import { count } from '../lib/operators.js';
|
|
139
|
+
import { watch } from '../lib/operators.js';
|
|
140
|
+
import { call } from '../lib/operators.js';
|
|
141
|
+
import { open } from '../lib/operators.js';
|
|
142
|
+
import { bind } from '../lib/operators.js';
|
|
143
|
+
import { define } from '../lib/operators.js';
|
|
144
|
+
import { schema } from '../lib/spec.js';
|
|
103
145
|
import { RPCClient } from '@cero-base/core/rpc';
|
|
104
146
|
/**
|
|
105
147
|
* Per-device `local`-namespace surface on a Client. Exposes each app-defined
|
|
@@ -145,4 +187,4 @@ declare class Handle {
|
|
|
145
187
|
/** Tear down the remote handle and drop membership. */
|
|
146
188
|
leave(): any;
|
|
147
189
|
}
|
|
148
|
-
export { put, set, get, del, count, watch, call, open
|
|
190
|
+
export { put, set, get, del, count, watch, call, open, bind, define, t, schema };
|