@cero-base/cero 2.5.0 → 2.7.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.
@@ -46,6 +46,7 @@ declare const remote: {
46
46
  type: string;
47
47
  name: string | null;
48
48
  newer: boolean;
49
+ ref: string | null;
49
50
  } | null>;
50
51
  phrase(me: verbs.Context): Promise<string>;
51
52
  nearby(ctx: verbs.Context, on: boolean, opts?: {
@@ -75,6 +76,18 @@ export type Context = (Client | Handle) & Record<string, Ref>;
75
76
  * @returns {Promise<Client>}
76
77
  */
77
78
  export declare function restore(me: Client, phrase: string): Promise<Client>;
79
+ /**
80
+ * Link the app to the identity behind a device invite, as `cero.link` does in the worker: the
81
+ * client is then that identity. `onrequest` gets the request's id as it is sent.
82
+ *
83
+ * @param {Client} me
84
+ * @param {string} invite
85
+ * @param {{ onrequest?: (id: string) => void }} [opts]
86
+ * @returns {Promise<Client>}
87
+ */
88
+ export declare function link(me: Client, invite: string, { onrequest }?: {
89
+ onrequest?: (id: string) => void;
90
+ }): Promise<Client>;
78
91
  /**
79
92
  * Per-device `local`-namespace surface on a Client.
80
93
  */
@@ -122,10 +135,11 @@ export declare class Client extends RPCClient {
122
135
  /**
123
136
  * @param {import('streamx').Duplex} ipc Framed IPC stream (must be writable).
124
137
  * @param {Spec} spec Compiled cero spec (schema + rpc + handles).
125
- * @param {{ onerror?: (err: Error) => void }} [opts] Where the worker's background errors go; the console without one.
138
+ * @param {{ onerror?: (err: Error) => void, push?: import('./push.js').Messaging }} [opts] Where the worker's background errors go, the console without one; `push`: the platform's messaging service, to follow the handles' push topics.
126
139
  */
127
140
  constructor(ipc: import('streamx').Duplex, spec: Spec, { onerror, push }?: {
128
141
  onerror?: (err: Error) => void;
142
+ push?: import('./push.js').Messaging;
129
143
  });
130
144
  /** @private */
131
145
  private _pumpErrors;
@@ -191,11 +205,12 @@ declare class Handle {
191
205
  *
192
206
  * @param {import('streamx').Duplex} ipc
193
207
  * @param {Spec} spec
194
- * @param {{ onerror?: (err: Error) => void }} [opts]
208
+ * @param {{ onerror?: (err: Error) => void, push?: import('./push.js').Messaging }} [opts]
195
209
  * @returns {Promise<Client>}
196
210
  */
197
211
  export declare function connect(ipc: import('streamx').Duplex, spec: Spec, opts?: {
198
212
  onerror?: (err: Error) => void;
213
+ push?: import('./push.js').Messaging;
199
214
  }): Promise<Client>;
200
215
  /**
201
216
  * Symmetric client entry. Mirrors the main `cero`, but `cero(ipc, spec)` connects to a
@@ -203,16 +218,18 @@ export declare function connect(ipc: import('streamx').Duplex, spec: Spec, opts?
203
218
  *
204
219
  * @param {import('streamx').Duplex} ipc Framed IPC duplex stream.
205
220
  * @param {Spec} spec Built cero spec.
206
- * @param {{ onerror?: (err: Error) => void }} [opts]
221
+ * @param {{ onerror?: (err: Error) => void, push?: import('./push.js').Messaging }} [opts]
207
222
  * @returns {Promise<Context>}
208
223
  */
209
224
  declare function start(ipc: import('streamx').Duplex, spec: Spec, opts?: {
210
225
  onerror?: (err: Error) => void;
226
+ push?: import('./push.js').Messaging;
211
227
  }): Promise<Context>;
212
- /** @type {typeof start & typeof remote & { connect: typeof connect, restore: typeof restore, t: typeof t, schema: typeof schema }} */
228
+ /** @type {typeof start & typeof remote & { connect: typeof connect, restore: typeof restore, link: typeof link, t: typeof t, schema: typeof schema }} */
213
229
  export declare const cero: typeof start & typeof remote & {
214
230
  connect: typeof connect;
215
231
  restore: typeof restore;
232
+ link: typeof link;
216
233
  t: typeof t;
217
234
  schema: typeof schema;
218
235
  };
@@ -1,10 +1,10 @@
1
- export type Backend = {
1
+ export type Messaging = {
2
2
  subscribe: (topic: string) => Promise<void>;
3
3
  unsubscribe: (topic: string) => Promise<void>;
4
4
  on: (event: 'push', fn: (payload: Uint8Array) => void) => (() => void) | void;
5
5
  };
6
6
  /**
7
- * @typedef {object} Backend The platform's push service, as `connect` takes it.
7
+ * @typedef {object} Messaging The platform's messaging service, as `connect` takes it for push.
8
8
  * @property {(topic: string) => Promise<void>} subscribe
9
9
  * @property {(topic: string) => Promise<void>} unsubscribe
10
10
  * @property {(event: 'push', fn: (payload: Uint8Array) => void) => (() => void) | void} on
@@ -14,7 +14,7 @@ export type Backend = {
14
14
  * leaves; and act on a push: the handle it is about ranks first on the swarm.
15
15
  *
16
16
  * @param {import('./client.js').Client} me
17
- * @param {Backend} backend
17
+ * @param {Messaging} messaging
18
18
  * @returns {() => void}
19
19
  */
20
- export declare function follow(me: import('./client.js').Client, backend: Backend): () => void;
20
+ export declare function follow(me: import('./client.js').Client, messaging: Messaging): () => void;
@@ -131,6 +131,11 @@ export declare class Server extends RPCServer {
131
131
  * @private
132
132
  */
133
133
  private _wireRestore;
134
+ /**
135
+ * Wire the `link` handler: a stream, the request's id as it is sent, the identity once linked.
136
+ * @private
137
+ */
138
+ private _wireLink;
134
139
  /**
135
140
  * Register the row-level RPC handlers (put/set/get/del/watch/call).
136
141
  * @private