@cero-base/core 0.8.10 → 1.0.1

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.
@@ -85,6 +85,8 @@ export class Storage extends ReadyResource {
85
85
  }
86
86
 
87
87
  if (this.backend === ROCKS) {
88
+ if (!this.root)
89
+ throw CeroError.INVALID('rocks backend requires a root storage, not store-only')
88
90
  const cf = this.root.rocks.columnFamily(this._cf)
89
91
  this.db = HyperDB.rocks(cf, this.spec.database)
90
92
  } else {
@@ -129,19 +131,24 @@ export class Storage extends ReadyResource {
129
131
  }
130
132
 
131
133
  /**
132
- * Upsert by merging with the existing row, preserving `createdAt`.
134
+ * Upsert by merging with the existing row, preserving `createdAt`. Pass
135
+ * `{ upsert: false }` to update-only — a missing row is left untouched
136
+ * (returns `null`) instead of created. Mirrors `Database.set`.
133
137
  *
134
138
  * @param {string} name
135
139
  * @param {Record<string, any>} row
136
- * @returns {Promise<SingleResult>}
140
+ * @param {{ upsert?: boolean }} [opts]
141
+ * @returns {Promise<SingleResult | null>}
137
142
  */
138
- async set(name, row) {
143
+ async set(name, row, { upsert = true } = {}) {
139
144
  this._guard()
140
145
  const ref = this._ref(name)
141
146
  const ts = Date.now()
142
147
  const existing = await this._read(ref, row?.id)
148
+ if (!upsert && !existing) return null
143
149
  /** @type {StoredRow} */
144
150
  const stored = {
151
+ ...existing,
145
152
  ...row,
146
153
  createdAt: existing?.createdAt ?? ts,
147
154
  updatedAt: ts
@@ -181,13 +188,16 @@ export class Storage extends ReadyResource {
181
188
 
182
189
  if (ref.kind === SINGLE) return { data: await this.db.findOne(col, {}) }
183
190
 
191
+ // keyed lookup, not a full scan + in-memory find
184
192
  if (typeof query === 'string') {
185
- const rows = await this.db.find(col, {}).toArray()
186
- return { data: rows.find((r) => r.id === query) ?? null }
193
+ return { data: (await this.db.get(col, { id: query })) ?? null }
187
194
  }
188
195
 
189
196
  const data = await this.db.find(col, query || {}).toArray()
190
- const total = (await this.db.find(col, {}).toArray()).length
197
+ // a filter (or limit) caps `data`, so `total` needs a full count; with no
198
+ // query `data` is already everything — skip the second scan.
199
+ const filtered = query && Object.keys(query).length > 0
200
+ const total = filtered ? (await this.db.find(col, {}).toArray()).length : data.length
191
201
  return { data, total, size: data.length }
192
202
  }
193
203
 
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Encode a coreKey + raw hyperblobs blobId + type into a durable string id.
3
+ *
4
+ * @param {Uint8Array} coreKey
5
+ * @param {RawBlobId} blobId
6
+ * @param {string} type
7
+ * @returns {string}
8
+ */
9
+ export function encodeId(coreKey: Uint8Array, blobId: RawBlobId, type: string): string;
10
+ /**
11
+ * Decode a string id back into its coreKey, raw blobId and type.
12
+ *
13
+ * @param {string} id
14
+ * @returns {{ coreKey: Uint8Array, blobId: RawBlobId, type: string }}
15
+ */
16
+ export function decodeId(id: string): {
17
+ coreKey: Uint8Array;
18
+ blobId: RawBlobId;
19
+ type: string;
20
+ };
21
+ export type RawBlobId = {
22
+ blockOffset: number;
23
+ blockLength: number;
24
+ byteOffset: number;
25
+ byteLength: number;
26
+ };
@@ -1,28 +1,14 @@
1
1
  /**
2
2
  * @typedef {object} BlobsOpts
3
- * @property {any} store Corestore (or compatible) used to host the blob core.
3
+ * @property {object} store Corestore (or compatible) used to host the blob core.
4
4
  * @property {import('../identity/index.js').Identity} [identity] Identity supplying the default encryption key.
5
5
  * @property {import('../network/index.js').Network} [network] Optional network used to announce + replicate the core.
6
6
  * @property {Uint8Array} [key] Pre-existing blob core key — joins an existing blob feed.
7
7
  * @property {Uint8Array} [encryptionKey] Explicit encryption key, overrides `identity.encryptionKey`.
8
8
  *
9
- * @typedef {object} BlobEntry
10
- * @property {string} id Opaque z32 id used by `get`/`info`/`delete`.
11
- * @property {string} hash Content hash (z32-encoded blake2b of the bytes).
12
- * @property {number} size Logical byte length recorded at put-time.
13
- * @property {any} meta Caller-provided metadata, stored verbatim.
14
- * @property {number} createdAt Wall-clock timestamp of the put.
15
- *
16
- * @typedef {object} PutOpts
17
- * @property {any} [meta] Arbitrary metadata persisted alongside the blob.
18
- * @property {number} [size] Override the recorded size (defaults to byte length).
19
- */
20
- /**
21
- * Content-addressable blob store backed by a single Hyperblobs core.
22
- * Writes dedupe locally by content hash, reads/streams are positional
23
- * descriptors, and the underlying core is attached to the supplied
24
- * network for replication.
9
+ * @typedef {import('./codec.js').RawBlobId} RawBlobId
25
10
  */
11
+ /** Thin wrapper over a single Hyperblobs core; deals only in raw blobIds. */
26
12
  export class Blobs extends ReadyResource {
27
13
  /** @param {BlobsOpts} [opts] */
28
14
  constructor({ store, identity, network, key, encryptionKey }?: BlobsOpts);
@@ -34,10 +20,6 @@ export class Blobs extends ReadyResource {
34
20
  core: any;
35
21
  hyperblobs: any;
36
22
  _discovery: import("../network/discovery.js").Discovery;
37
- /** @type {Map<string, BlobEntry>} contentHash → entry */
38
- _index: Map<string, BlobEntry>;
39
- /** @type {Map<string, BlobEntry>} id → entry (so info/has/delete by id work) */
40
- _byId: Map<string, BlobEntry>;
41
23
  /**
42
24
  * Canonical z32 id of the underlying core (null until ready).
43
25
  *
@@ -57,66 +39,47 @@ export class Blobs extends ReadyResource {
57
39
  */
58
40
  get discoveryKey(): Uint8Array | null;
59
41
  /**
60
- * Store a buffer or readable stream, returning its opaque id. Identical
61
- * content from the same writer is deduplicated locally.
42
+ * Store a buffer or readable stream, returning its raw hyperblobs blobId.
62
43
  *
63
44
  * @param {Uint8Array | import('streamx').Readable} input
64
- * @param {PutOpts} [opts]
65
- * @returns {Promise<string>}
45
+ * @returns {Promise<RawBlobId>}
66
46
  */
67
- put(input: Uint8Array | any, { meta, size }?: PutOpts): Promise<string>;
47
+ put(input: Uint8Array | import("streamx").Readable): Promise<RawBlobId>;
68
48
  /**
69
- * Delete the blob with the given id and forget its local index entry.
70
- *
71
- * @param {string} id
72
- * @returns {Promise<void>}
49
+ * @param {import('streamx').Readable} input
50
+ * @returns {Promise<RawBlobId>}
73
51
  */
74
- delete(id: string): Promise<void>;
52
+ _putStream(input: import("streamx").Readable): Promise<RawBlobId>;
75
53
  /**
76
- * Resolve the blob bytes for an id. Fetches from peers if not local.
54
+ * Resolve the blob bytes for a raw blobId. Fetches from peers if not local.
77
55
  *
78
- * @param {string} id
79
- * @param {any} [opts]
56
+ * @param {RawBlobId} blobId
57
+ * @param {object} [opts]
80
58
  * @returns {Promise<Uint8Array>}
81
59
  */
82
- get(id: string, opts?: any): Promise<Uint8Array>;
60
+ get(blobId: RawBlobId, opts?: object): Promise<Uint8Array>;
83
61
  /**
84
- * Streaming counterpart of `get` — returns a Readable over the blob bytes.
62
+ * Streaming counterpart of `get` — a Readable over the blob bytes.
85
63
  *
86
- * @param {string} id
87
- * @param {any} [opts]
64
+ * @param {RawBlobId} blobId
65
+ * @param {object} [opts]
88
66
  * @returns {import('streamx').Readable}
89
67
  */
90
- read(id: string, opts?: any): any;
91
- /**
92
- * Look up the locally-cached metadata for a blob id, or `null` if absent.
93
- *
94
- * @param {string} id
95
- * @returns {Promise<BlobEntry | null>}
96
- */
97
- info(id: string): Promise<BlobEntry | null>;
98
- /**
99
- * Whether the underlying blocks for the blob are present in the local core.
100
- *
101
- * @param {string} id
102
- * @returns {Promise<boolean>}
103
- */
104
- has(id: string): Promise<boolean>;
68
+ createReadStream(blobId: RawBlobId, opts?: object): import("streamx").Readable;
105
69
  /**
106
- * Pre-fetch the blocks for `id` from peers without reading the bytes.
70
+ * Clear the blocks backing a raw blobId from the local core.
107
71
  *
108
- * @param {string} id
109
- * @param {any} [opts]
72
+ * @param {RawBlobId} blobId
110
73
  * @returns {Promise<void>}
111
74
  */
112
- fetch(id: string, opts?: any): Promise<void>;
75
+ clear(blobId: RawBlobId): Promise<void>;
113
76
  _guard(): void;
114
77
  }
115
78
  export type BlobsOpts = {
116
79
  /**
117
80
  * Corestore (or compatible) used to host the blob core.
118
81
  */
119
- store: any;
82
+ store: object;
120
83
  /**
121
84
  * Identity supplying the default encryption key.
122
85
  */
@@ -134,36 +97,8 @@ export type BlobsOpts = {
134
97
  */
135
98
  encryptionKey?: Uint8Array;
136
99
  };
137
- export type BlobEntry = {
138
- /**
139
- * Opaque z32 id used by `get`/`info`/`delete`.
140
- */
141
- id: string;
142
- /**
143
- * Content hash (z32-encoded blake2b of the bytes).
144
- */
145
- hash: string;
146
- /**
147
- * Logical byte length recorded at put-time.
148
- */
149
- size: number;
150
- /**
151
- * Caller-provided metadata, stored verbatim.
152
- */
153
- meta: any;
154
- /**
155
- * Wall-clock timestamp of the put.
156
- */
157
- createdAt: number;
158
- };
159
- export type PutOpts = {
160
- /**
161
- * Arbitrary metadata persisted alongside the blob.
162
- */
163
- meta?: any;
164
- /**
165
- * Override the recorded size (defaults to byte length).
166
- */
167
- size?: number;
168
- };
100
+ export type RawBlobId = import("./codec.js").RawBlobId;
169
101
  import ReadyResource from 'ready-resource';
102
+ import { encodeId } from './codec.js';
103
+ import { decodeId } from './codec.js';
104
+ export { encodeId, decodeId };
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @typedef {{ key: Buffer, encryptionKey: Buffer | null }} Resolved
3
+ */
4
+ /**
5
+ * HTTP server that turns a string file id into a renderable localhost URL.
6
+ * Wraps hypercore-blob-server; the underlying store session is owned by
7
+ * BlobServer and closed when `close()` is called.
8
+ */
9
+ export class FileServer {
10
+ /**
11
+ * @param {object} opts
12
+ * @param {import('corestore')} opts.store
13
+ * @param {(coreKey: Buffer, info: object) => Resolved | null | Promise<Resolved | null>} opts.resolve
14
+ */
15
+ constructor({ store, resolve }: {
16
+ store: any;
17
+ resolve: (coreKey: Buffer, info: object) => Resolved | null | Promise<Resolved | null>;
18
+ });
19
+ resolve: (coreKey: Buffer, info: object) => Resolved | null | Promise<Resolved | null>;
20
+ server: any;
21
+ get port(): any;
22
+ listen(): Promise<void>;
23
+ /**
24
+ * Build a renderable localhost URL for a string file id.
25
+ *
26
+ * @param {string} id
27
+ * @returns {string}
28
+ */
29
+ getLink(id: string): string;
30
+ close(): Promise<void>;
31
+ }
32
+ export type Resolved = {
33
+ key: Buffer;
34
+ encryptionKey: Buffer | null;
35
+ };
@@ -7,7 +7,7 @@
7
7
  * @param {{ name?: string | null, isMobile?: boolean, recovering?: boolean }} [opts]
8
8
  * @returns {Promise<{ id: Uint8Array, writer: import('../identity/index.js').KeyPair }>}
9
9
  */
10
- export function bootstrap(db: import("./index.js").Database, { name, isMobile, recovering }?: {
10
+ export function bootstrap(db: import("./index.js").Database, { name, isMobile, recovering, timeout }?: {
11
11
  name?: string | null;
12
12
  isMobile?: boolean;
13
13
  recovering?: boolean;
@@ -1,6 +1,29 @@
1
- export function makeDispatcher(spec: any, ns: any, routes: any): {
2
- dispatcher: any;
3
- apply(nodes: any, view: any, host: any): Promise<void>;
1
+ /**
2
+ * Build the hyperdispatch router for a spec: wires membership, builtin, and
3
+ * spec-defined collection/action ops, returning the router plus an apply loop.
4
+ *
5
+ * @param {{ dispatch: { Router: Function }, meta?: { refs?: Record<string, { kind?: string, builtin?: boolean, verb?: string }> } }} spec Generated hyperdispatch spec.
6
+ * @param {string} ns Namespace prefix for collection and op names.
7
+ * @param {Record<string, Function>} routes Custom action handlers keyed by route name.
8
+ * @returns {{ dispatcher: object, apply: (nodes: Array<{ value: Buffer, key: Buffer }>, view: object, host: object) => Promise<void> }}
9
+ */
10
+ export function makeDispatcher(spec: {
11
+ dispatch: {
12
+ Router: Function;
13
+ };
14
+ meta?: {
15
+ refs?: Record<string, {
16
+ kind?: string;
17
+ builtin?: boolean;
18
+ verb?: string;
19
+ }>;
20
+ };
21
+ }, ns: string, routes: Record<string, Function>): {
22
+ dispatcher: object;
23
+ apply: (nodes: Array<{
24
+ value: Buffer;
25
+ key: Buffer;
26
+ }>, view: object, host: object) => Promise<void>;
4
27
  };
5
28
  export const BUILTINS: {
6
29
  name: string;
@@ -10,6 +10,7 @@
10
10
  * @property {(nodes: any, view: any, host: any) => Promise<void>} [apply] Override the default apply function.
11
11
  * @property {Uint8Array | null} [key] Existing autobee key to reopen.
12
12
  * @property {import('../identity/index.js').KeyPair} [keyPair] Device writer keypair; defaults to identity's keypair.
13
+ * @property {(err: Error) => void} [onerror] Called when a background after-hook or onApply callback fails.
13
14
  *
14
15
  * @typedef {{ data: any | null }} SingleResult
15
16
  * @typedef {{ data: any[], total: number, size: number }} ListResult
@@ -61,10 +62,14 @@ export class Database extends ReadyResource {
61
62
  publicKey: Uint8Array<ArrayBufferLike>;
62
63
  secretKey: Uint8Array<ArrayBufferLike>;
63
64
  };
65
+ _onerror: any;
64
66
  bee: any;
65
67
  dispatcher: {
66
- dispatcher: any;
67
- apply(nodes: any, view: any, host: any): Promise<void>;
68
+ dispatcher: object;
69
+ apply: (nodes: Array<{
70
+ value: Buffer;
71
+ key: Buffer;
72
+ }>, view: object, host: object) => Promise<void>;
68
73
  };
69
74
  beforeHooks: Map<any, any>;
70
75
  afterHooks: Map<any, any>;
@@ -75,11 +80,16 @@ export class Database extends ReadyResource {
75
80
  _discovery: import("../network/discovery.js").Discovery;
76
81
  /** Open the underlying autobee, wire dispatcher + apply, attach to network. */
77
82
  openBee(): Promise<void>;
78
- get discoveryKey(): any;
79
- get writerKey(): any;
83
+ /** @returns {Uint8Array | null} discovery key of the underlying bee */
84
+ get discoveryKey(): Uint8Array | null;
85
+ /** @returns {Uint8Array | null} this device's local writer key */
86
+ get writerKey(): Uint8Array | null;
87
+ /** @returns {boolean} whether the bee accepts local writes */
80
88
  get writable(): boolean;
81
- get length(): any;
82
- get view(): any;
89
+ /** @returns {number} number of ops in the local writer */
90
+ get length(): number;
91
+ /** @returns {object | null} the materialized HyperDB view */
92
+ get view(): object | null;
83
93
  /**
84
94
  * Register a pre-op hook. Returning `false` from `fn` aborts the op.
85
95
  *
@@ -182,6 +192,7 @@ export class Database extends ReadyResource {
182
192
  * @returns {Promise<T>}
183
193
  */
184
194
  tx<T>(fn: () => Promise<T> | T): Promise<T>;
195
+ _txChain: any;
185
196
  /**
186
197
  * Encode and append dispatch ops. Buffers into the active `tx` queue if one
187
198
  * is open.
@@ -217,7 +228,7 @@ export class Database extends ReadyResource {
217
228
  * @param {Query} [query]
218
229
  * @returns {import('streamx').Readable}
219
230
  */
220
- watch(name: string, query?: Query): any;
231
+ watch(name: string, query?: Query): import("streamx").Readable;
221
232
  /**
222
233
  * First-run bootstrap: create the device writer, save it, and swap into it.
223
234
  *
@@ -263,20 +274,41 @@ export class Database extends ReadyResource {
263
274
  * @returns {Promise<void>}
264
275
  */
265
276
  removeWriter(publicKey: Uint8Array): Promise<void>;
277
+ /**
278
+ * Throw if the handle is closing/closed or the bee isn't ready yet.
279
+ *
280
+ * @returns {void}
281
+ */
266
282
  guard(): void;
267
- ref(name: any): {
268
- name: string;
269
- kind: string;
270
- verb: string;
271
- };
272
- col(ref: any): string;
273
- matchIndex(name: any, query: any): {
283
+ /**
284
+ * Resolve a table name to its normalized `{ name, kind, verb }` ref.
285
+ *
286
+ * @param {string} name
287
+ * @returns {Ref}
288
+ */
289
+ ref(name: string): Ref;
290
+ /**
291
+ * Namespaced collection path for a ref.
292
+ *
293
+ * @param {Ref} ref
294
+ * @returns {string}
295
+ */
296
+ col(ref: Ref): string;
297
+ _checkFields(name: any, row: any): void;
298
+ /**
299
+ * Find a secondary index whose fields exactly match the query's equality keys.
300
+ *
301
+ * @param {string} name
302
+ * @param {Query} [query]
303
+ * @returns {{ path: string, range: { gte: object, lte: object } } | null}
304
+ */
305
+ matchIndex(name: string, query?: Query): {
274
306
  path: string;
275
307
  range: {
276
- gte: {};
277
- lte: {};
308
+ gte: object;
309
+ lte: object;
278
310
  };
279
- };
311
+ } | null;
280
312
  _addHook(map: any, op: any, fn: any): () => void;
281
313
  _write(verb: any, hook: any, publicKey: any): Promise<void>;
282
314
  }
@@ -331,6 +363,10 @@ export type DatabaseOpts = {
331
363
  * Device writer keypair; defaults to identity's keypair.
332
364
  */
333
365
  keyPair?: import("../identity/index.js").KeyPair;
366
+ /**
367
+ * Called when a background after-hook or onApply callback fails.
368
+ */
369
+ onerror?: (err: Error) => void;
334
370
  };
335
371
  export type SingleResult = {
336
372
  data: any | null;
package/types/index.d.ts CHANGED
@@ -1,11 +1,59 @@
1
1
  export * from "./identity/index.js";
2
- export * from "./storage/index.js";
3
2
  export * from "./network/index.js";
4
3
  export * from "./database/index.js";
5
4
  export * from "./blobs/index.js";
6
5
  export * from "./rpc/index.js";
7
6
  export * from "./pairing/index.js";
8
- export * from "./pairing/invite.js";
9
7
  export * from "./lib/schema.js";
10
8
  export * from "./lib/utils.js";
11
9
  export * from "./lib/errors.js";
10
+ export { Storage } from "./storage/index.js";
11
+ export { Invite } from "./pairing/invite.js";
12
+ /**
13
+ * `Ref` / `SingleResult` / `ListResult` are JSDoc typedefs (types, not runtime exports), so they
14
+ * are re-exported as namespaced type aliases — `export { Ref as StorageRef }` fails at import
15
+ * because the module provides no runtime `Ref` export.
16
+ */
17
+ export type StorageRef = import("./storage/index.js").Ref;
18
+ /**
19
+ * `Ref` / `SingleResult` / `ListResult` are JSDoc typedefs (types, not runtime exports), so they
20
+ * are re-exported as namespaced type aliases — `export { Ref as StorageRef }` fails at import
21
+ * because the module provides no runtime `Ref` export.
22
+ */
23
+ export type StorageSingleResult = import("./storage/index.js").SingleResult;
24
+ /**
25
+ * `Ref` / `SingleResult` / `ListResult` are JSDoc typedefs (types, not runtime exports), so they
26
+ * are re-exported as namespaced type aliases — `export { Ref as StorageRef }` fails at import
27
+ * because the module provides no runtime `Ref` export.
28
+ */
29
+ export type StorageListResult = import("./storage/index.js").ListResult;
30
+ /**
31
+ * `Ref` / `SingleResult` / `ListResult` are JSDoc typedefs (types, not runtime exports), so they
32
+ * are re-exported as namespaced type aliases — `export { Ref as StorageRef }` fails at import
33
+ * because the module provides no runtime `Ref` export.
34
+ */
35
+ export type StorageOpts = import("./storage/index.js").StorageOpts;
36
+ /**
37
+ * `Ref` / `SingleResult` / `ListResult` are JSDoc typedefs (types, not runtime exports), so they
38
+ * are re-exported as namespaced type aliases — `export { Ref as StorageRef }` fails at import
39
+ * because the module provides no runtime `Ref` export.
40
+ */
41
+ export type StoredRow = import("./storage/index.js").StoredRow;
42
+ /**
43
+ * `Ref` / `SingleResult` / `ListResult` are JSDoc typedefs (types, not runtime exports), so they
44
+ * are re-exported as namespaced type aliases — `export { Ref as StorageRef }` fails at import
45
+ * because the module provides no runtime `Ref` export.
46
+ */
47
+ export type GetByIdResult = import("./storage/index.js").GetByIdResult;
48
+ /**
49
+ * `CreateInviteOpts` is a typedef (not a runtime export); re-export it as a type alias.
50
+ */
51
+ export type MintInviteOpts = import("./pairing/invite.js").CreateInviteOpts;
52
+ /**
53
+ * `CreateInviteOpts` is a typedef (not a runtime export); re-export it as a type alias.
54
+ */
55
+ export type InviteFields = import("./pairing/invite.js").InviteFields;
56
+ /**
57
+ * `CreateInviteOpts` is a typedef (not a runtime export); re-export it as a type alias.
58
+ */
59
+ export type ParseInviteOpts = import("./pairing/invite.js").ParseInviteOpts;
@@ -7,7 +7,30 @@ export const PASSIVE: "passive";
7
7
  export const ROCKS: "rocks";
8
8
  export const BEE: "bee";
9
9
  export const OWNER: "owner";
10
- export const WRITE: "write";
10
+ export const ADMIN: "admin";
11
+ export const MEMBER: "member";
12
+ export const READER: "reader";
11
13
  export const READ: "read";
14
+ export const WRITE: "write";
15
+ export const DELETE: "delete";
16
+ export const INVITE: "invite";
17
+ export const REMOVE: "remove";
18
+ export const ASSIGN: "assign";
19
+ export namespace ROLE_PERMS {
20
+ let owner: string[];
21
+ let admin: string[];
22
+ let member: string[];
23
+ let reader: string[];
24
+ }
25
+ export namespace RANK {
26
+ let owner_1: number;
27
+ export { owner_1 as owner };
28
+ let admin_1: number;
29
+ export { admin_1 as admin };
30
+ let member_1: number;
31
+ export { member_1 as member };
32
+ let reader_1: number;
33
+ export { reader_1 as reader };
34
+ }
12
35
  export const NAMESPACE: "cero";
13
36
  export const COUNTERS: "counters";
@@ -14,6 +14,7 @@ export namespace t {
14
14
  let json: Prim;
15
15
  let fixed32: Prim;
16
16
  let fixed64: Prim;
17
+ let file: Prim;
17
18
  function required(marker: Prim): Prim;
18
19
  /**
19
20
  * Single-row table (one record, set/get by name).
@@ -2,15 +2,12 @@ export function resolveStruct(name: any, v?: number): {
2
2
  preencode(state: any, m: any): void;
3
3
  encode(state: any, m: any): void;
4
4
  decode(state: any): {
5
- hash: any;
6
5
  coreKey: any;
7
6
  blockOffset: any;
8
7
  blockLength: any;
9
8
  byteOffset: any;
10
9
  byteLength: any;
11
- size: any;
12
- createdAt: any;
13
- meta: any;
10
+ type: any;
14
11
  } | {
15
12
  status: any;
16
13
  reason: any;
@@ -22,21 +19,20 @@ export function resolveStruct(name: any, v?: number): {
22
19
  } | {
23
20
  id: any;
24
21
  name: any;
22
+ role: any;
23
+ noAccept: boolean;
25
24
  };
26
25
  };
27
26
  export function getStruct(name: any, v?: number): {
28
27
  preencode(state: any, m: any): void;
29
28
  encode(state: any, m: any): void;
30
29
  decode(state: any): {
31
- hash: any;
32
30
  coreKey: any;
33
31
  blockOffset: any;
34
32
  blockLength: any;
35
33
  byteOffset: any;
36
34
  byteLength: any;
37
- size: any;
38
- createdAt: any;
39
- meta: any;
35
+ type: any;
40
36
  } | {
41
37
  status: any;
42
38
  reason: any;
@@ -48,6 +44,8 @@ export function getStruct(name: any, v?: number): {
48
44
  } | {
49
45
  id: any;
50
46
  name: any;
47
+ role: any;
48
+ noAccept: boolean;
51
49
  };
52
50
  };
53
51
  export function getEnum(name: any): void;
@@ -73,20 +71,19 @@ export function getEncoding(name: any): {
73
71
  decode(state: any): {
74
72
  id: any;
75
73
  name: any;
74
+ role: any;
75
+ noAccept: boolean;
76
76
  };
77
77
  } | {
78
78
  preencode(state: any, m: any): void;
79
79
  encode(state: any, m: any): void;
80
80
  decode(state: any): {
81
- hash: any;
82
81
  coreKey: any;
83
82
  blockOffset: any;
84
83
  blockLength: any;
85
84
  byteOffset: any;
86
85
  byteLength: any;
87
- size: any;
88
- createdAt: any;
89
- meta: any;
86
+ type: any;
90
87
  };
91
88
  };
92
89
  export function encode(name: any, value: any, v?: number): any;
@@ -4,6 +4,14 @@
4
4
  * @returns {string}
5
5
  */
6
6
  export function genId(): string;
7
+ /**
8
+ * Whether `role` is granted `perm` under the default policy.
9
+ *
10
+ * @param {string} role
11
+ * @param {string} perm
12
+ * @returns {boolean}
13
+ */
14
+ export function can(role: string, perm: string): boolean;
7
15
  /**
8
16
  * Stream-of-snapshots primitive. Couples a `get` (returns the latest value)
9
17
  * with a `watch` (re-fires on change) and emits the newest snapshot every
@@ -12,13 +20,13 @@ export function genId(): string;
12
20
  * @template T
13
21
  * @param {object} args
14
22
  * @param {() => Promise<T> | T} args.get
15
- * @param {(fn: () => void) => (() => void) | void} args.watch Returns an unsubscribe.
23
+ * @param {(fn: () => void) => (() => void) | void} args.watch
16
24
  * @returns {import('streamx').Readable<T>}
17
25
  */
18
26
  export function subscribe<T>({ get, watch }: {
19
27
  get: () => Promise<T> | T;
20
28
  watch: (fn: () => void) => (() => void) | void;
21
- }): any;
29
+ }): import("streamx").Readable<T>;
22
30
  /**
23
31
  * z32-encode a 32-byte key into a canonical string id.
24
32
  *
@@ -37,3 +45,5 @@ export const toKey: (id: string) => Uint8Array;
37
45
  * @type {(id: string) => boolean}
38
46
  */
39
47
  export const isKeyId: (id: string) => boolean;
48
+ export function grants(a: any, b: any): boolean;
49
+ export function outranks(a: any, b: any): boolean;