@comapeo/core 1.0.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/LICENSE.md +9 -0
- package/README.md +31 -0
- package/dist/blob-api.d.ts +92 -0
- package/dist/blob-api.d.ts.map +1 -0
- package/dist/blob-store/index.d.ts +163 -0
- package/dist/blob-store/index.d.ts.map +1 -0
- package/dist/blob-store/live-download.d.ts +107 -0
- package/dist/blob-store/live-download.d.ts.map +1 -0
- package/dist/config-import.d.ts +74 -0
- package/dist/config-import.d.ts.map +1 -0
- package/dist/constants.d.ts +14 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/core-manager/bitfield-rle.d.ts +25 -0
- package/dist/core-manager/bitfield-rle.d.ts.map +1 -0
- package/dist/core-manager/core-index.d.ts +56 -0
- package/dist/core-manager/core-index.d.ts.map +1 -0
- package/dist/core-manager/index.d.ts +125 -0
- package/dist/core-manager/index.d.ts.map +1 -0
- package/dist/core-manager/random-access-file-pool.d.ts +17 -0
- package/dist/core-manager/random-access-file-pool.d.ts.map +1 -0
- package/dist/core-manager/remote-bitfield.d.ts +146 -0
- package/dist/core-manager/remote-bitfield.d.ts.map +1 -0
- package/dist/core-ownership.d.ts +112 -0
- package/dist/core-ownership.d.ts.map +1 -0
- package/dist/datastore/index.d.ts +91 -0
- package/dist/datastore/index.d.ts.map +1 -0
- package/dist/datatype/index.d.ts +108 -0
- package/dist/discovery/local-discovery.d.ts +64 -0
- package/dist/discovery/local-discovery.d.ts.map +1 -0
- package/dist/errors.d.ts +4 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/fastify-controller.d.ts +27 -0
- package/dist/fastify-controller.d.ts.map +1 -0
- package/dist/fastify-plugins/blobs.d.ts +6 -0
- package/dist/fastify-plugins/blobs.d.ts.map +1 -0
- package/dist/fastify-plugins/constants.d.ts +3 -0
- package/dist/fastify-plugins/constants.d.ts.map +1 -0
- package/dist/fastify-plugins/icons.d.ts +6 -0
- package/dist/fastify-plugins/icons.d.ts.map +1 -0
- package/dist/fastify-plugins/maps/index.d.ts +11 -0
- package/dist/fastify-plugins/maps/index.d.ts.map +1 -0
- package/dist/fastify-plugins/maps/offline-fallback-map.d.ts +12 -0
- package/dist/fastify-plugins/maps/offline-fallback-map.d.ts.map +1 -0
- package/dist/fastify-plugins/maps/static-maps.d.ts +11 -0
- package/dist/fastify-plugins/maps/static-maps.d.ts.map +1 -0
- package/dist/fastify-plugins/utils.d.ts +23 -0
- package/dist/fastify-plugins/utils.d.ts.map +1 -0
- package/dist/generated/extensions.d.ts +44 -0
- package/dist/generated/extensions.d.ts.map +1 -0
- package/dist/generated/keys.d.ts +36 -0
- package/dist/generated/keys.d.ts.map +1 -0
- package/dist/generated/rpc.d.ts +87 -0
- package/dist/generated/rpc.d.ts.map +1 -0
- package/dist/icon-api.d.ts +109 -0
- package/dist/icon-api.d.ts.map +1 -0
- package/dist/index-writer/index.d.ts +51 -0
- package/dist/index-writer/index.d.ts.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/invite-api.d.ts +70 -0
- package/dist/invite-api.d.ts.map +1 -0
- package/dist/lib/hashmap.d.ts +62 -0
- package/dist/lib/hashmap.d.ts.map +1 -0
- package/dist/lib/hypercore-helpers.d.ts +6 -0
- package/dist/lib/hypercore-helpers.d.ts.map +1 -0
- package/dist/lib/noise-secret-stream-helpers.d.ts +45 -0
- package/dist/lib/noise-secret-stream-helpers.d.ts.map +1 -0
- package/dist/lib/ponyfills.d.ts +10 -0
- package/dist/lib/ponyfills.d.ts.map +1 -0
- package/dist/lib/string.d.ts +2 -0
- package/dist/lib/string.d.ts.map +1 -0
- package/dist/lib/timing-safe-equal.d.ts +15 -0
- package/dist/lib/timing-safe-equal.d.ts.map +1 -0
- package/dist/local-peers.d.ts +151 -0
- package/dist/local-peers.d.ts.map +1 -0
- package/dist/logger.d.ts +32 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/mapeo-manager.d.ts +178 -0
- package/dist/mapeo-manager.d.ts.map +1 -0
- package/dist/mapeo-project.d.ts +3233 -0
- package/dist/mapeo-project.d.ts.map +1 -0
- package/dist/member-api.d.ts +114 -0
- package/dist/member-api.d.ts.map +1 -0
- package/dist/roles.d.ts +157 -0
- package/dist/roles.d.ts.map +1 -0
- package/dist/schema/client.d.ts +284 -0
- package/dist/schema/client.d.ts.map +1 -0
- package/dist/schema/project.d.ts +1812 -0
- package/dist/schema/project.d.ts.map +1 -0
- package/dist/schema/schema-to-drizzle.d.ts +20 -0
- package/dist/schema/schema-to-drizzle.d.ts.map +1 -0
- package/dist/schema/types.d.ts +98 -0
- package/dist/schema/types.d.ts.map +1 -0
- package/dist/schema/utils.d.ts +55 -0
- package/dist/schema/utils.d.ts.map +1 -0
- package/dist/sync/core-sync-state.d.ts +252 -0
- package/dist/sync/core-sync-state.d.ts.map +1 -0
- package/dist/sync/namespace-sync-state.d.ts +47 -0
- package/dist/sync/namespace-sync-state.d.ts.map +1 -0
- package/dist/sync/peer-sync-controller.d.ts +44 -0
- package/dist/sync/peer-sync-controller.d.ts.map +1 -0
- package/dist/sync/sync-api.d.ts +158 -0
- package/dist/sync/sync-api.d.ts.map +1 -0
- package/dist/sync/sync-state.d.ts +40 -0
- package/dist/sync/sync-state.d.ts.map +1 -0
- package/dist/translation-api.d.ts +288 -0
- package/dist/translation-api.d.ts.map +1 -0
- package/dist/types.d.ts +115 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils.d.ts +115 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils_types.d.ts +14 -0
- package/drizzle/client/0000_bumpy_carnage.sql +33 -0
- package/drizzle/client/meta/0000_snapshot.json +199 -0
- package/drizzle/client/meta/_journal.json +13 -0
- package/drizzle/project/0000_spooky_lady_ursula.sql +192 -0
- package/drizzle/project/meta/0000_snapshot.json +1137 -0
- package/drizzle/project/meta/_journal.json +13 -0
- package/package.json +202 -0
- package/src/blob-api.js +139 -0
- package/src/blob-store/index.js +325 -0
- package/src/blob-store/live-download.js +373 -0
- package/src/config-import.js +604 -0
- package/src/constants.js +34 -0
- package/src/core-manager/bitfield-rle.js +235 -0
- package/src/core-manager/core-index.js +87 -0
- package/src/core-manager/index.js +504 -0
- package/src/core-manager/random-access-file-pool.js +30 -0
- package/src/core-manager/remote-bitfield.js +416 -0
- package/src/core-ownership.js +235 -0
- package/src/datastore/README.md +46 -0
- package/src/datastore/index.js +234 -0
- package/src/datatype/README.md +33 -0
- package/src/datatype/index.d.ts +108 -0
- package/src/datatype/index.js +358 -0
- package/src/discovery/local-discovery.js +303 -0
- package/src/errors.js +5 -0
- package/src/fastify-controller.js +84 -0
- package/src/fastify-plugins/blobs.js +139 -0
- package/src/fastify-plugins/constants.js +5 -0
- package/src/fastify-plugins/icons.js +158 -0
- package/src/fastify-plugins/maps/index.js +173 -0
- package/src/fastify-plugins/maps/offline-fallback-map.js +114 -0
- package/src/fastify-plugins/maps/static-maps.js +271 -0
- package/src/fastify-plugins/utils.js +52 -0
- package/src/generated/README.md +3 -0
- package/src/generated/extensions.d.ts +44 -0
- package/src/generated/extensions.js +196 -0
- package/src/generated/extensions.ts +237 -0
- package/src/generated/keys.d.ts +36 -0
- package/src/generated/keys.js +148 -0
- package/src/generated/keys.ts +185 -0
- package/src/generated/rpc.d.ts +87 -0
- package/src/generated/rpc.js +389 -0
- package/src/generated/rpc.ts +463 -0
- package/src/icon-api.js +282 -0
- package/src/index-writer/README.md +38 -0
- package/src/index-writer/index.js +124 -0
- package/src/index.js +16 -0
- package/src/invite-api.js +450 -0
- package/src/lib/hashmap.js +91 -0
- package/src/lib/hypercore-helpers.js +18 -0
- package/src/lib/noise-secret-stream-helpers.js +37 -0
- package/src/lib/ponyfills.js +25 -0
- package/src/lib/string.js +7 -0
- package/src/lib/timing-safe-equal.js +34 -0
- package/src/local-peers.js +737 -0
- package/src/logger.js +99 -0
- package/src/mapeo-manager.js +914 -0
- package/src/mapeo-project.js +980 -0
- package/src/member-api.js +319 -0
- package/src/roles.js +412 -0
- package/src/schema/client.js +55 -0
- package/src/schema/project.js +44 -0
- package/src/schema/schema-to-drizzle.js +118 -0
- package/src/schema/types.ts +153 -0
- package/src/schema/utils.js +51 -0
- package/src/sync/core-sync-state.js +440 -0
- package/src/sync/namespace-sync-state.js +193 -0
- package/src/sync/peer-sync-controller.js +332 -0
- package/src/sync/sync-api.js +588 -0
- package/src/sync/sync-state.js +63 -0
- package/src/translation-api.js +141 -0
- package/src/types.ts +149 -0
- package/src/utils.js +210 -0
- package/src/utils_types.d.ts +14 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {Object} InviteApiEvents
|
|
3
|
+
* @property {(invite: Invite) => void} invite-received
|
|
4
|
+
* @property {(invite: Invite, removalReason: InviteRemovalReason) => void} invite-removed
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* @extends {TypedEmitter<InviteApiEvents>}
|
|
8
|
+
*/
|
|
9
|
+
export class InviteApi extends TypedEmitter<InviteApiEvents> {
|
|
10
|
+
/**
|
|
11
|
+
* @param {Object} options
|
|
12
|
+
* @param {import('./local-peers.js').LocalPeers} options.rpc
|
|
13
|
+
* @param {object} options.queries
|
|
14
|
+
* @param {(projectInviteId: Readonly<Buffer>) => undefined | { projectPublicId: string }} options.queries.getProjectByInviteId
|
|
15
|
+
* @param {(projectDetails: Pick<ProjectJoinDetails, 'projectKey' | 'encryptionKeys'> & { projectName: string }) => Promise<string>} options.queries.addProject
|
|
16
|
+
* @param {Logger} [options.logger]
|
|
17
|
+
*/
|
|
18
|
+
constructor({ rpc, queries, logger }: {
|
|
19
|
+
rpc: import("./local-peers.js").LocalPeers;
|
|
20
|
+
queries: {
|
|
21
|
+
getProjectByInviteId: (projectInviteId: Readonly<Buffer>) => undefined | {
|
|
22
|
+
projectPublicId: string;
|
|
23
|
+
};
|
|
24
|
+
addProject: (projectDetails: Pick<ProjectJoinDetails, "projectKey" | "encryptionKeys"> & {
|
|
25
|
+
projectName: string;
|
|
26
|
+
}) => Promise<string>;
|
|
27
|
+
};
|
|
28
|
+
logger?: Logger | undefined;
|
|
29
|
+
});
|
|
30
|
+
rpc: import("./local-peers.js").LocalPeers;
|
|
31
|
+
/**
|
|
32
|
+
* @returns {Array<Invite>}
|
|
33
|
+
*/
|
|
34
|
+
getPending(): Array<Invite>;
|
|
35
|
+
/**
|
|
36
|
+
* Attempt to accept the invite.
|
|
37
|
+
*
|
|
38
|
+
* This can fail if the invitor has canceled the invite or if you cannot
|
|
39
|
+
* connect to the invitor's device.
|
|
40
|
+
*
|
|
41
|
+
* If the invite is accepted and you had other invites to the same project,
|
|
42
|
+
* those invites are removed, and the invitors are told that you're already
|
|
43
|
+
* part of this project.
|
|
44
|
+
*
|
|
45
|
+
* @param {Pick<Invite, 'inviteId'>} invite
|
|
46
|
+
* @returns {Promise<string>}
|
|
47
|
+
*/
|
|
48
|
+
accept({ inviteId: inviteIdString }: Pick<Invite, "inviteId">): Promise<string>;
|
|
49
|
+
/**
|
|
50
|
+
* @param {Pick<Invite, 'inviteId'>} invite
|
|
51
|
+
* @returns {void}
|
|
52
|
+
*/
|
|
53
|
+
reject({ inviteId: inviteIdString }: Pick<Invite, "inviteId">): void;
|
|
54
|
+
#private;
|
|
55
|
+
}
|
|
56
|
+
export type InviteInternal = InviteRpcMessage & {
|
|
57
|
+
receivedAt: number;
|
|
58
|
+
};
|
|
59
|
+
export type Invite = MapBuffers<InviteInternal>;
|
|
60
|
+
export type InviteRemovalReason = ("accepted" | "rejected" | "canceled" | "accepted other" | "connection error" | "internal error");
|
|
61
|
+
export type InviteApiEvents = {
|
|
62
|
+
"invite-received": (invite: Invite) => void;
|
|
63
|
+
"invite-removed": (invite: Invite, removalReason: InviteRemovalReason) => void;
|
|
64
|
+
};
|
|
65
|
+
import { TypedEmitter } from 'tiny-typed-emitter';
|
|
66
|
+
import type { ProjectJoinDetails } from './generated/rpc.js';
|
|
67
|
+
import { Logger } from './logger.js';
|
|
68
|
+
import type { Invite as InviteRpcMessage } from './generated/rpc.js';
|
|
69
|
+
import type { MapBuffers } from './types.js';
|
|
70
|
+
//# sourceMappingURL=invite-api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invite-api.d.ts","sourceRoot":"","sources":["../src/invite-api.js"],"names":[],"mappings":"AAiJA;;;;GAIG;AAEH;;GAEG;AACH;IAME;;;;;;;OAOG;IACH,sCANG;QAAuD,GAAG,EAAlD,OAAO,kBAAkB,EAAE,UAAU;QACrB,OAAO,EAC/B;YAAwG,oBAAoB,EAApH,CAAC,eAAe,EAAE,QAAQ,CAAC,MAAM,CAAC,KAAK,SAAS,GAAG;gBAAE,eAAe,EAAE,MAAM,CAAA;aAAE;YAC4D,UAAU,EAApJ,CAAC,cAAc,EAAE,IAAI,CAAC,kBAAkB,EAAE,YAAY,GAAG,gBAAgB,CAAC,GAAG;gBAAE,WAAW,EAAE,MAAM,CAAA;aAAE,KAAK,OAAO,CAAC,MAAM,CAAC;SAChI;QAAyB,MAAM;KAAC,EA0BlC;IAnBC,2CAAc;IAsFhB;;OAEG;IACH,cAFa,KAAK,CAAC,MAAM,CAAC,CAMzB;IAED;;;;;;;;;;;;OAYG;IACH,qCAHW,IAAI,CAAC,MAAM,EAAE,UAAU,CAAC,GACtB,OAAO,CAAC,MAAM,CAAC,CAkI3B;IAED;;;OAGG;IACH,qCAHW,IAAI,CAAC,MAAM,EAAE,UAAU,CAAC,GACtB,IAAI,CAuBhB;;CACF;6BA7ZY,gBAAgB,GAAG;IAAE,UAAU,EAAE,MAAM,CAAA;CAAE;qBAGxC,WAAW,cAAc,CAAC;kCAG3B,CACZ,UAAa,GACb,UAAa,GACb,UAAa,GACb,gBAAmB,GACnB,kBAAqB,GACrB,gBAAmB,CAChB;;uBA8GU,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI;sBACxB,CAAC,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,mBAAmB,KAAK,IAAI;;6BApJ7C,oBAAoB;wCAavC,oBAAoB;uBAPP,aAAa;gDAO1B,oBAAoB;gCANE,YAAY"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/** @typedef {string | number | bigint | boolean | undefined | symbol | null} Primitive */
|
|
2
|
+
/**
|
|
3
|
+
* `Map` uses same-value-zero equality for keys, which makes it more difficult
|
|
4
|
+
* to use reference types like buffers.
|
|
5
|
+
*
|
|
6
|
+
* `HashMap` is very similar to `Map`, but accepts a hash function for keys.
|
|
7
|
+
* This function should return a primitive, such as a number or string, which
|
|
8
|
+
* will be used as the key.
|
|
9
|
+
*
|
|
10
|
+
* It doesn't contain all the functionality of `Map` because we don't need it,
|
|
11
|
+
* but it should be fairly easy to update as needed.
|
|
12
|
+
*
|
|
13
|
+
* @template K
|
|
14
|
+
* @template {unknown} V
|
|
15
|
+
* @example
|
|
16
|
+
* const join = (arr) => arr.join(' ')
|
|
17
|
+
*
|
|
18
|
+
* const map = new HashMap(join)
|
|
19
|
+
*
|
|
20
|
+
* map.set([1, 2], 3)
|
|
21
|
+
* map.get([1, 2])
|
|
22
|
+
* // => 3
|
|
23
|
+
*/
|
|
24
|
+
export default class HashMap<K, V extends unknown> {
|
|
25
|
+
/**
|
|
26
|
+
* @param {(key: K) => Primitive} hash
|
|
27
|
+
* @param {Iterable<[K, V]>} [iterable=[]]
|
|
28
|
+
*/
|
|
29
|
+
constructor(hash: (key: K) => Primitive, iterable?: Iterable<[K, V]> | undefined);
|
|
30
|
+
/**
|
|
31
|
+
* @returns {number}
|
|
32
|
+
*/
|
|
33
|
+
get size(): number;
|
|
34
|
+
/**
|
|
35
|
+
* @param {K} key The key to remove.
|
|
36
|
+
* @returns {boolean} `true` if the key was present and removed, `false` otherwise.
|
|
37
|
+
*/
|
|
38
|
+
delete(key: K): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* @param {K} key The key to look up.
|
|
41
|
+
* @returns {undefined | V} The element associated with `key`, or `undefined` if it's not present.
|
|
42
|
+
*/
|
|
43
|
+
get(key: K): undefined | V;
|
|
44
|
+
/**
|
|
45
|
+
* @param {K} key The key to look up.
|
|
46
|
+
* @returns {boolean} `true` if `key` is present in the map, `false` otherwise.
|
|
47
|
+
*/
|
|
48
|
+
has(key: K): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* @param {K} key The key to update.
|
|
51
|
+
* @param {V} value The value to add at `key`.
|
|
52
|
+
* @returns {this} The map.
|
|
53
|
+
*/
|
|
54
|
+
set(key: K, value: V): this;
|
|
55
|
+
/**
|
|
56
|
+
* @returns {IterableIterator<V>}
|
|
57
|
+
*/
|
|
58
|
+
values(): IterableIterator<V>;
|
|
59
|
+
#private;
|
|
60
|
+
}
|
|
61
|
+
export type Primitive = string | number | bigint | boolean | undefined | symbol | null;
|
|
62
|
+
//# sourceMappingURL=hashmap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hashmap.d.ts","sourceRoot":"","sources":["../../src/lib/hashmap.js"],"names":[],"mappings":"AAAA,0FAA0F;AAE1F;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,6BAXa,CAAC,EACS,CAAC,SAAX,OAAS;IAgBpB;;;OAGG;IACH,kBAHW,CAAC,GAAG,EAAE,CAAC,KAAK,SAAS,2CAM/B;IAED;;OAEG;IACH,mBAEC;IAED;;;OAGG;IACH,YAHW,CAAC,GACC,OAAO,CAKnB;IAED;;;OAGG;IACH,SAHW,CAAC,GACC,SAAS,GAAG,CAAC,CAKzB;IAED;;;OAGG;IACH,SAHW,CAAC,GACC,OAAO,CAKnB;IAED;;;;OAIG;IACH,SAJW,CAAC,SACD,CAAC,GACC,IAAI,CAMhB;IAED;;OAEG;IACH,UAFa,gBAAgB,CAAC,CAAC,CAAC,CAI/B;;CACF;wBA1Fa,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {import('hypercore')<'binary', any>} core Core to unreplicate. Must be ready.
|
|
3
|
+
* @param {import('protomux')} protomux
|
|
4
|
+
*/
|
|
5
|
+
export function unreplicate(core: import("hypercore")<"binary", any>, protomux: import("protomux")): void;
|
|
6
|
+
//# sourceMappingURL=hypercore-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hypercore-helpers.d.ts","sourceRoot":"","sources":["../../src/lib/hypercore-helpers.js"],"names":[],"mappings":"AAEA;;;GAGG;AACH,kCAHW,OAAO,WAAW,EAAE,QAAQ,EAAE,GAAG,CAAC,YAClC,OAAO,UAAU,CAAC,QAa5B"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/** @import { Duplex as NodeDuplex } from 'node:stream' */
|
|
2
|
+
/** @import { Duplex as StreamxDuplex } from 'streamx' */
|
|
3
|
+
/** @import NoiseSecretStream from '@hyperswarm/secret-stream' */
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
* @typedef {NodeDuplex | StreamxDuplex} RawStream
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* @template {RawStream} [T=RawStream]
|
|
10
|
+
* @typedef {NoiseSecretStream<T> & { destroyed: true }} DestroyedNoiseStream
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* @template {RawStream} [T=RawStream]
|
|
14
|
+
* @typedef {NoiseSecretStream<T> & {
|
|
15
|
+
* publicKey: Buffer,
|
|
16
|
+
* remotePublicKey: Buffer,
|
|
17
|
+
* handshake: Buffer,
|
|
18
|
+
* destroyed: false
|
|
19
|
+
* }} OpenedNoiseStream
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* Utility to await a NoiseSecretStream to open, that returns a stream with the
|
|
23
|
+
* correct types for publicKey and remotePublicKey (which can be null before
|
|
24
|
+
* stream is opened)
|
|
25
|
+
*
|
|
26
|
+
* @template {RawStream} T
|
|
27
|
+
* @param {NoiseSecretStream<T>} stream
|
|
28
|
+
* @returns {Promise<OpenedNoiseStream<T> | DestroyedNoiseStream<T>>}
|
|
29
|
+
*/
|
|
30
|
+
export function openedNoiseSecretStream<T extends RawStream>(stream: NoiseSecretStream<T>): Promise<OpenedNoiseStream<T> | DestroyedNoiseStream<T>>;
|
|
31
|
+
export type RawStream = NodeDuplex | StreamxDuplex;
|
|
32
|
+
export type DestroyedNoiseStream<T extends RawStream = RawStream> = NoiseSecretStream<T> & {
|
|
33
|
+
destroyed: true;
|
|
34
|
+
};
|
|
35
|
+
export type OpenedNoiseStream<T extends RawStream = RawStream> = NoiseSecretStream<T> & {
|
|
36
|
+
publicKey: Buffer;
|
|
37
|
+
remotePublicKey: Buffer;
|
|
38
|
+
handshake: Buffer;
|
|
39
|
+
destroyed: false;
|
|
40
|
+
};
|
|
41
|
+
import type NoiseSecretStream from '@hyperswarm/secret-stream';
|
|
42
|
+
import type { Duplex as NodeDuplex } from 'node:stream';
|
|
43
|
+
import type { Duplex as StreamxDuplex } from 'streamx';
|
|
44
|
+
import type NoiseSecretStream_1 from '@hyperswarm/secret-stream';
|
|
45
|
+
//# sourceMappingURL=noise-secret-stream-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"noise-secret-stream-helpers.d.ts","sourceRoot":"","sources":["../../src/lib/noise-secret-stream-helpers.js"],"names":[],"mappings":"AAAA,0DAA0D;AAC1D,yDAAyD;AACzD,iEAAiE;AAEjE;;;GAGG;AAEH;;;GAGG;AAEH;;;;;;;;GAQG;AAEH;;;;;;;;GAQG;AACH,wCAJyB,CAAC,SAAZ,SAAU,UACb,kBAAkB,CAAC,CAAC,GAClB,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAKnE;wBA9BY,UAAU,GAAG,aAAa;iCAIb,CAAC,SAAb,SAAU,gBACX,kBAAkB,CAAC,CAAC,GAAG;IAAE,SAAS,EAAE,IAAI,CAAA;CAAE;8BAI7B,CAAC,SAAb,SAAU,gBACX,kBAAkB,CAAC,CAAC,GAAG;IACnC,SAAa,EAAE,MAAM,CAAC;IACtB,eAAmB,EAAE,MAAM,CAAC;IAC5B,SAAa,EAAE,MAAM,CAAC;IACtB,SAAa,EAAE,KAAK,CAAA;CACjB;mCAnB+B,2BAA2B;0CAFpB,aAAa;6CACV,SAAS;qCACnB,2BAA2B"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ponyfill of `AbortSignal.any()`.
|
|
3
|
+
*
|
|
4
|
+
* [0]: https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/any_static
|
|
5
|
+
*
|
|
6
|
+
* @param {Iterable<AbortSignal>} iterable
|
|
7
|
+
* @returns {AbortSignal}
|
|
8
|
+
*/
|
|
9
|
+
export function abortSignalAny(iterable: Iterable<AbortSignal>): AbortSignal;
|
|
10
|
+
//# sourceMappingURL=ponyfills.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ponyfills.d.ts","sourceRoot":"","sources":["../../src/lib/ponyfills.js"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,yCAHW,QAAQ,CAAC,WAAW,CAAC,GACnB,WAAW,CAkBvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../../src/lib/string.js"],"names":[],"mappings":"AAMO,6BAHI,MAAM,GACJ,OAAO,CAEuB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compare two values in constant time.
|
|
3
|
+
*
|
|
4
|
+
* Useful when you want to avoid leaking data.
|
|
5
|
+
*
|
|
6
|
+
* Like `crypto.timingSafeEqual`, but works with strings and doesn't throw if
|
|
7
|
+
* lengths differ.
|
|
8
|
+
*
|
|
9
|
+
* @template {string | NodeJS.ArrayBufferView} T
|
|
10
|
+
* @param {T} a
|
|
11
|
+
* @param {T} b
|
|
12
|
+
* @returns {boolean}
|
|
13
|
+
*/
|
|
14
|
+
export default function timingSafeEqual<T extends string | NodeJS.ArrayBufferView>(a: T, b: T): boolean;
|
|
15
|
+
//# sourceMappingURL=timing-safe-equal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timing-safe-equal.d.ts","sourceRoot":"","sources":["../../src/lib/timing-safe-equal.js"],"names":[],"mappings":"AAaA;;;;;;;;;;;;GAYG;AACH,wCAL+C,CAAC,SAAlC,MAAM,GAAG,MAAM,CAAC,eAAgB,KACnC,CAAC,KACD,CAAC,GACC,OAAO,CASnB"}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
export const kTestOnlySendRawInvite: unique symbol;
|
|
2
|
+
/**
|
|
3
|
+
* @typedef {object} LocalPeersEvents
|
|
4
|
+
* @property {(peers: PeerInfo[]) => void} peers Emitted whenever the connection status of peers changes. An array of peerInfo objects with a peer id and the peer connection status
|
|
5
|
+
* @property {(peer: PeerInfoConnected) => void} peer-add Emitted when a new peer is connected
|
|
6
|
+
* @property {(peerId: string, invite: Invite) => void} invite Emitted when an invite is received
|
|
7
|
+
* @property {(peerId: string, invite: InviteCancel) => void} invite-cancel Emitted when we receive a cancelation for an invite
|
|
8
|
+
* @property {(peerId: string, inviteResponse: InviteResponse) => void} invite-response Emitted when an invite response is received
|
|
9
|
+
* @property {(peerId: string, details: ProjectJoinDetails) => void} got-project-details Emitted when project details are received
|
|
10
|
+
* @property {(discoveryKey: Buffer, protomux: Protomux<import('@hyperswarm/secret-stream')>) => void} discovery-key Emitted when a new hypercore is replicated (by a peer) to a peer protomux instance (passed as the second parameter)
|
|
11
|
+
* @property {(messageType: string, errorMessage?: string) => void} failed-to-handle-message Emitted when we received a message we couldn't handle for some reason. Primarily useful for testing
|
|
12
|
+
*/
|
|
13
|
+
/** @extends {TypedEmitter<LocalPeersEvents>} */
|
|
14
|
+
export class LocalPeers extends TypedEmitter<LocalPeersEvents> {
|
|
15
|
+
/**
|
|
16
|
+
*
|
|
17
|
+
* @param {object} [opts]
|
|
18
|
+
* @param {Logger} [opts.logger]
|
|
19
|
+
*/
|
|
20
|
+
constructor({ logger }?: {
|
|
21
|
+
logger?: Logger | undefined;
|
|
22
|
+
} | undefined);
|
|
23
|
+
get peers(): ((PeerInfoBase & {
|
|
24
|
+
status: "connected";
|
|
25
|
+
connectedAt: number;
|
|
26
|
+
protomux: Protomux<import("@hyperswarm/secret-stream")>;
|
|
27
|
+
}) | (PeerInfoBase & {
|
|
28
|
+
status: "disconnected";
|
|
29
|
+
disconnectedAt: number;
|
|
30
|
+
}))[];
|
|
31
|
+
/**
|
|
32
|
+
* @param {string} deviceId
|
|
33
|
+
* @param {Invite} invite
|
|
34
|
+
* @returns {Promise<void>}
|
|
35
|
+
*/
|
|
36
|
+
sendInvite(deviceId: string, invite: Invite): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* @param {string} deviceId
|
|
39
|
+
* @param {InviteCancel} inviteCancel
|
|
40
|
+
* @returns {Promise<void>}
|
|
41
|
+
*/
|
|
42
|
+
sendInviteCancel(deviceId: string, inviteCancel: InviteCancel): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Respond to an invite from a peer
|
|
45
|
+
*
|
|
46
|
+
* @param {string} deviceId id of the peer you want to respond to (publicKey of peer as hex string)
|
|
47
|
+
* @param {InviteResponse} inviteResponse
|
|
48
|
+
*/
|
|
49
|
+
sendInviteResponse(deviceId: string, inviteResponse: InviteResponse): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* @param {string} deviceId
|
|
52
|
+
* @param {ProjectJoinDetails} details
|
|
53
|
+
*/
|
|
54
|
+
sendProjectJoinDetails(deviceId: string, details: ProjectJoinDetails): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
*
|
|
57
|
+
* @param {string} deviceId id of the peer you want to send to (publicKey of peer as hex string)
|
|
58
|
+
* @param {DeviceInfo} deviceInfo device info to send
|
|
59
|
+
*/
|
|
60
|
+
sendDeviceInfo(deviceId: string, deviceInfo: DeviceInfo): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* Connect to a peer over an existing NoiseSecretStream
|
|
63
|
+
*
|
|
64
|
+
* @param {import('./types.js').NoiseStream<any>} stream a NoiseSecretStream from @hyperswarm/secret-stream
|
|
65
|
+
* @returns {import('./types.js').ReplicationStream}
|
|
66
|
+
*/
|
|
67
|
+
connect(stream: import("./types.js").NoiseStream<any>): import("./types.js").ReplicationStream;
|
|
68
|
+
/**
|
|
69
|
+
* @param {string} deviceId
|
|
70
|
+
* @param {Buffer} buf
|
|
71
|
+
*/
|
|
72
|
+
[kTestOnlySendRawInvite](deviceId: string, buf: Buffer): Promise<void>;
|
|
73
|
+
#private;
|
|
74
|
+
}
|
|
75
|
+
export { TimeoutError };
|
|
76
|
+
export class UnknownPeerError extends Error {
|
|
77
|
+
/** @param {string} [message] */
|
|
78
|
+
constructor(message?: string | undefined);
|
|
79
|
+
}
|
|
80
|
+
export class PeerDisconnectedError extends Error {
|
|
81
|
+
/** @param {string} [message] */
|
|
82
|
+
constructor(message?: string | undefined);
|
|
83
|
+
}
|
|
84
|
+
export class PeerFailedConnectionError extends Error {
|
|
85
|
+
/** @param {string} [message] */
|
|
86
|
+
constructor(message?: string | undefined);
|
|
87
|
+
}
|
|
88
|
+
export type PeerInfoBase = {
|
|
89
|
+
deviceId: string;
|
|
90
|
+
name: string | undefined;
|
|
91
|
+
deviceType: import("./generated/rpc.js").DeviceInfo["deviceType"];
|
|
92
|
+
};
|
|
93
|
+
export type PeerInfoConnecting = PeerInfoBase & {
|
|
94
|
+
status: "connecting";
|
|
95
|
+
};
|
|
96
|
+
export type PeerInfoConnected = PeerInfoBase & {
|
|
97
|
+
status: "connected";
|
|
98
|
+
connectedAt: number;
|
|
99
|
+
protomux: Protomux<import("@hyperswarm/secret-stream")>;
|
|
100
|
+
};
|
|
101
|
+
export type PeerInfoDisconnected = PeerInfoBase & {
|
|
102
|
+
status: "disconnected";
|
|
103
|
+
disconnectedAt: number;
|
|
104
|
+
};
|
|
105
|
+
export type PeerInfoInternal = PeerInfoConnecting | PeerInfoConnected | PeerInfoDisconnected;
|
|
106
|
+
export type PeerInfo = PeerInfoConnected | PeerInfoDisconnected;
|
|
107
|
+
export type PeerState = PeerInfoInternal["status"];
|
|
108
|
+
export type LocalPeersEvents = {
|
|
109
|
+
/**
|
|
110
|
+
* Emitted whenever the connection status of peers changes. An array of peerInfo objects with a peer id and the peer connection status
|
|
111
|
+
*/
|
|
112
|
+
peers: (peers: PeerInfo[]) => void;
|
|
113
|
+
/**
|
|
114
|
+
* Emitted when a new peer is connected
|
|
115
|
+
*/
|
|
116
|
+
"peer-add": (peer: PeerInfoConnected) => void;
|
|
117
|
+
/**
|
|
118
|
+
* Emitted when an invite is received
|
|
119
|
+
*/
|
|
120
|
+
invite: (peerId: string, invite: Invite) => void;
|
|
121
|
+
/**
|
|
122
|
+
* Emitted when we receive a cancelation for an invite
|
|
123
|
+
*/
|
|
124
|
+
"invite-cancel": (peerId: string, invite: InviteCancel) => void;
|
|
125
|
+
/**
|
|
126
|
+
* Emitted when an invite response is received
|
|
127
|
+
*/
|
|
128
|
+
"invite-response": (peerId: string, inviteResponse: InviteResponse) => void;
|
|
129
|
+
/**
|
|
130
|
+
* Emitted when project details are received
|
|
131
|
+
*/
|
|
132
|
+
"got-project-details": (peerId: string, details: ProjectJoinDetails) => void;
|
|
133
|
+
/**
|
|
134
|
+
* Emitted when a new hypercore is replicated (by a peer) to a peer protomux instance (passed as the second parameter)
|
|
135
|
+
*/
|
|
136
|
+
"discovery-key": (discoveryKey: Buffer, protomux: Protomux<import("@hyperswarm/secret-stream")>) => void;
|
|
137
|
+
/**
|
|
138
|
+
* Emitted when we received a message we couldn't handle for some reason. Primarily useful for testing
|
|
139
|
+
*/
|
|
140
|
+
"failed-to-handle-message": (messageType: string, errorMessage?: string) => void;
|
|
141
|
+
};
|
|
142
|
+
import { TypedEmitter } from 'tiny-typed-emitter';
|
|
143
|
+
import Protomux from 'protomux';
|
|
144
|
+
import { Invite } from './generated/rpc.js';
|
|
145
|
+
import { InviteCancel } from './generated/rpc.js';
|
|
146
|
+
import { InviteResponse } from './generated/rpc.js';
|
|
147
|
+
import { ProjectJoinDetails } from './generated/rpc.js';
|
|
148
|
+
import { DeviceInfo } from './generated/rpc.js';
|
|
149
|
+
import { Logger } from './logger.js';
|
|
150
|
+
import { TimeoutError } from 'p-timeout';
|
|
151
|
+
//# sourceMappingURL=local-peers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-peers.d.ts","sourceRoot":"","sources":["../src/local-peers.js"],"names":[],"mappings":"AAqCA,mDAAqE;AAuLrE;;;;;;;;;;GAUG;AAEH,gDAAgD;AAChD;IAYE;;;;OAIG;IACH;;mBAGC;IAED;gBAjNqC,WAAW;qBAAe,MAAM;kBAAY,QAAQ,CAAC,OAAO,2BAA2B,CAAC,CAAC;;gBACzF,cAAc;wBAAkB,MAAM;UAsN1E;IAED;;;;OAIG;IACH,qBAJW,MAAM,UACN,MAAM,GACJ,OAAO,CAAC,IAAI,CAAC,CAMzB;IAED;;;;OAIG;IACH,2BAJW,MAAM,gBACN,YAAY,GACV,OAAO,CAAC,IAAI,CAAC,CAMzB;IAED;;;;;OAKG;IACH,6BAHW,MAAM,kBACN,cAAc,iBAMxB;IAED;;;OAGG;IACH,iCAHW,MAAM,WACN,kBAAkB,iBAM5B;IAED;;;;OAIG;IACH,yBAHW,MAAM,cACN,UAAU,iBAMpB;IAYD;;;;;OAKG;IACH,gBAHW,OAAO,YAAY,EAAE,WAAW,CAAC,GAAG,CAAC,GACnC,OAAO,YAAY,EAAE,iBAAiB,CAuDlD;IArED;;;OAGG;IACH,mCAHW,MAAM,OACN,MAAM,iBAMhB;;CA2RF;;AAID;IACE,gCAAgC;IAChC,0CAGC;CACF;AAED;IACE,gCAAgC;IAChC,0CAGC;CACF;AAED;IACE,gCAAgC;IAChC,0CAGC;CACF;;cAllBa,MAAM;UACN,MAAM,GAAG,SAAS;gBAClB,OAAO,oBAAoB,EAAE,UAAU,CAAC,YAAY,CAAC;;iCAErD,YAAY,GAAG;IAAE,MAAM,EAAE,YAAY,CAAA;CAAE;gCACvC,YAAY,GAAG;IAAE,MAAM,EAAE,WAAW,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,QAAQ,CAAC,OAAO,2BAA2B,CAAC,CAAC,CAAA;CAAE;mCACpH,YAAY,GAAG;IAAE,MAAM,EAAE,cAAc,CAAC;IAAC,cAAc,EAAE,MAAM,CAAA;CAAE;+BAEjE,kBAAkB,GAAG,iBAAiB,GAAG,oBAAoB;uBAC7D,iBAAiB,GAAG,oBAAoB;wBACxC,gBAAgB,CAAC,QAAQ,CAAC;;;;;WA2K1B,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,IAAI;;;;gBAC3B,CAAC,IAAI,EAAE,iBAAiB,KAAK,IAAI;;;;YACjC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI;;;;qBACxC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,KAAK,IAAI;;;;uBAC9C,CAAC,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,cAAc,KAAK,IAAI;;;;2BACxD,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,kBAAkB,KAAK,IAAI;;;;qBACrD,CAAC,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC,OAAO,2BAA2B,CAAC,CAAC,KAAK,IAAI;;;;gCACvF,CAAC,WAAW,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,KAAK,IAAI;;6BArOrC,oBAAoB;qBAC5B,UAAU;uBAUxB,oBAAoB;6BAApB,oBAAoB;+BAApB,oBAAoB;mCAApB,oBAAoB;2BAApB,oBAAoB;uBAEJ,aAAa;6BACG,WAAW"}
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export class Logger {
|
|
2
|
+
/**
|
|
3
|
+
* @param {string} ns
|
|
4
|
+
* @param {Logger} [logger]
|
|
5
|
+
*/
|
|
6
|
+
static create(ns: string, logger?: Logger | undefined): Logger;
|
|
7
|
+
/**
|
|
8
|
+
* @param {object} opts
|
|
9
|
+
* @param {string} opts.deviceId
|
|
10
|
+
* @param {createDebug.Debugger} [opts.baseLogger]
|
|
11
|
+
* @param {string} [opts.ns]
|
|
12
|
+
*/
|
|
13
|
+
constructor({ deviceId, baseLogger, ns }: {
|
|
14
|
+
deviceId: string;
|
|
15
|
+
baseLogger?: createDebug.Debugger | undefined;
|
|
16
|
+
ns?: string | undefined;
|
|
17
|
+
});
|
|
18
|
+
deviceId: string;
|
|
19
|
+
get enabled(): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* @param {Parameters<createDebug.Debugger>} args
|
|
22
|
+
*/
|
|
23
|
+
log: (formatter: any, ...args: any[]) => void;
|
|
24
|
+
/**
|
|
25
|
+
*
|
|
26
|
+
* @param {string} ns
|
|
27
|
+
*/
|
|
28
|
+
extend(ns: string): Logger;
|
|
29
|
+
#private;
|
|
30
|
+
}
|
|
31
|
+
import createDebug from 'debug';
|
|
32
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.js"],"names":[],"mappings":"AAmDA;IAIE;;;OAGG;IACH,kBAHW,MAAM,uCAShB;IAED;;;;;OAKG;IACH,0CAJG;QAAqB,QAAQ,EAArB,MAAM;QACsB,UAAU;QACxB,EAAE;KAAC,EAM3B;IAHC,iBAAwB;IAI1B,uBAEC;IAED;;OAEG;IACH,8CAEC;IACD;;;OAGG;IACH,WAFW,MAAM,UAOhB;;CACF;wBAlGuB,OAAO"}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
export const kRPC: unique symbol;
|
|
2
|
+
export const kManagerReplicate: unique symbol;
|
|
3
|
+
/**
|
|
4
|
+
* @typedef {Omit<import('./local-peers.js').PeerInfo, 'protomux'>} PublicPeerInfo
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* @typedef {object} MapeoManagerEvents
|
|
8
|
+
* @property {(peers: PublicPeerInfo[]) => void} local-peers Emitted when the list of connected peers changes (new ones added, or connection status changes)
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* @extends {TypedEmitter<MapeoManagerEvents>}
|
|
12
|
+
*/
|
|
13
|
+
export class MapeoManager extends TypedEmitter<MapeoManagerEvents> {
|
|
14
|
+
/**
|
|
15
|
+
* @param {Object} opts
|
|
16
|
+
* @param {Buffer} opts.rootKey 16-bytes of random data that uniquely identify the device, used to derive a 32-byte master key, which is used to derive all the keypairs used for Mapeo
|
|
17
|
+
* @param {string} opts.dbFolder Folder for sqlite Dbs. Folder must exist. Use ':memory:' to store everything in-memory
|
|
18
|
+
* @param {string} opts.projectMigrationsFolder path for drizzle migrations folder for project database
|
|
19
|
+
* @param {string} opts.clientMigrationsFolder path for drizzle migrations folder for client database
|
|
20
|
+
* @param {string | CoreStorage} opts.coreStorage Folder for hypercore storage or a function that returns a RandomAccessStorage instance
|
|
21
|
+
* @param {import('fastify').FastifyInstance} opts.fastify Fastify server instance
|
|
22
|
+
* @param {String} [opts.defaultConfigPath]
|
|
23
|
+
*/
|
|
24
|
+
constructor({ rootKey, dbFolder, projectMigrationsFolder, clientMigrationsFolder, coreStorage, fastify, defaultConfigPath, }: {
|
|
25
|
+
rootKey: Buffer;
|
|
26
|
+
dbFolder: string;
|
|
27
|
+
projectMigrationsFolder: string;
|
|
28
|
+
clientMigrationsFolder: string;
|
|
29
|
+
coreStorage: string | CoreStorage;
|
|
30
|
+
fastify: import("fastify").FastifyInstance;
|
|
31
|
+
defaultConfigPath?: string | undefined;
|
|
32
|
+
});
|
|
33
|
+
get deviceId(): string;
|
|
34
|
+
/**
|
|
35
|
+
* Create a new project.
|
|
36
|
+
* @param {(
|
|
37
|
+
* import('type-fest').Simplify<(
|
|
38
|
+
* Partial<Pick<ProjectValue, 'name'>> &
|
|
39
|
+
* { configPath?: string }
|
|
40
|
+
* )>
|
|
41
|
+
* )} [options]
|
|
42
|
+
* @returns {Promise<string>} Project public id
|
|
43
|
+
*/
|
|
44
|
+
createProject({ name, configPath }?: {
|
|
45
|
+
name?: string | undefined;
|
|
46
|
+
configPath?: string | undefined;
|
|
47
|
+
} | undefined): Promise<string>;
|
|
48
|
+
/**
|
|
49
|
+
* @param {string} projectPublicId
|
|
50
|
+
* @returns {Promise<MapeoProject>}
|
|
51
|
+
*/
|
|
52
|
+
getProject(projectPublicId: string): Promise<MapeoProject>;
|
|
53
|
+
/**
|
|
54
|
+
* @returns {Promise<Array<Pick<ProjectValue, 'name'> & { projectId: string, createdAt?: string, updatedAt?: string}>>}
|
|
55
|
+
*/
|
|
56
|
+
listProjects(): Promise<Array<Pick<ProjectValue, "name"> & {
|
|
57
|
+
projectId: string;
|
|
58
|
+
createdAt?: string;
|
|
59
|
+
updatedAt?: string;
|
|
60
|
+
}>>;
|
|
61
|
+
/**
|
|
62
|
+
* Add a project to this device. After adding a project the client should
|
|
63
|
+
* await `project.$waitForInitialSync()` to ensure that the device has
|
|
64
|
+
* downloaded their proof of project membership and the project config.
|
|
65
|
+
*
|
|
66
|
+
* @param {Pick<import('./generated/rpc.js').ProjectJoinDetails, 'projectKey' | 'encryptionKeys'> & { projectName: string }} projectJoinDetails
|
|
67
|
+
* @param {{ waitForSync?: boolean }} [opts] For internal use in tests, set opts.waitForSync = false to not wait for sync during addProject()
|
|
68
|
+
* @returns {Promise<string>}
|
|
69
|
+
*/
|
|
70
|
+
addProject: ({ projectKey, encryptionKeys, projectName }: Pick<import("./generated/rpc.js").ProjectJoinDetails, "projectKey" | "encryptionKeys"> & {
|
|
71
|
+
projectName: string;
|
|
72
|
+
}, { waitForSync }?: {
|
|
73
|
+
waitForSync?: boolean;
|
|
74
|
+
} | undefined) => Promise<string>;
|
|
75
|
+
/**
|
|
76
|
+
* @typedef {Exclude<
|
|
77
|
+
* import('./schema/client.js').DeviceInfoParam['deviceType'],
|
|
78
|
+
* 'selfHostedServer'>} RPCDeviceType
|
|
79
|
+
*/
|
|
80
|
+
/**
|
|
81
|
+
* @template {import('type-fest').Exact<
|
|
82
|
+
* import('./schema/client.js').DeviceInfoParam & {deviceType?: RPCDeviceType}, T>} T
|
|
83
|
+
* @param {T} deviceInfo
|
|
84
|
+
*/
|
|
85
|
+
setDeviceInfo<T extends import("type-fest").Exact<import("./schema/client.js").DeviceInfoParam & {
|
|
86
|
+
deviceType?: "UNRECOGNIZED" | "device_type_unspecified" | "mobile" | "tablet" | "desktop";
|
|
87
|
+
}, T>>(deviceInfo: T): Promise<void>;
|
|
88
|
+
/**
|
|
89
|
+
* @returns {(
|
|
90
|
+
* {
|
|
91
|
+
* deviceId: string;
|
|
92
|
+
* deviceType: DeviceInfoParam['deviceType']
|
|
93
|
+
* } & Partial<DeviceInfoParam>
|
|
94
|
+
* )}
|
|
95
|
+
*/
|
|
96
|
+
getDeviceInfo(): ({
|
|
97
|
+
deviceId: string;
|
|
98
|
+
deviceType: DeviceInfoParam["deviceType"];
|
|
99
|
+
} & Partial<DeviceInfoParam>);
|
|
100
|
+
/**
|
|
101
|
+
* @returns {InviteApi}
|
|
102
|
+
*/
|
|
103
|
+
get invite(): InviteApi;
|
|
104
|
+
/** @returns {Promise<{ name: string, port: number }>} */
|
|
105
|
+
startLocalPeerDiscoveryServer(): Promise<{
|
|
106
|
+
name: string;
|
|
107
|
+
port: number;
|
|
108
|
+
}>;
|
|
109
|
+
stopLocalPeerDiscoveryServer(opts?: {
|
|
110
|
+
force?: boolean | undefined;
|
|
111
|
+
timeout?: number | undefined;
|
|
112
|
+
} | undefined): Promise<void>;
|
|
113
|
+
connectLocalPeer({ address, port, name }: {
|
|
114
|
+
address: string;
|
|
115
|
+
port: number;
|
|
116
|
+
name: string;
|
|
117
|
+
}): void;
|
|
118
|
+
/**
|
|
119
|
+
* @returns {Promise<PublicPeerInfo[]>}
|
|
120
|
+
*/
|
|
121
|
+
listLocalPeers(): Promise<PublicPeerInfo[]>;
|
|
122
|
+
/**
|
|
123
|
+
* Call this when the app goes into the background.
|
|
124
|
+
*
|
|
125
|
+
* Will gracefully shut down sync.
|
|
126
|
+
*
|
|
127
|
+
* @see {@link onForegrounded}
|
|
128
|
+
* @returns {void}
|
|
129
|
+
*/
|
|
130
|
+
onBackgrounded(): void;
|
|
131
|
+
/**
|
|
132
|
+
* Call this when the app goes into the foreground.
|
|
133
|
+
*
|
|
134
|
+
* Will undo the effects of `onBackgrounded`.
|
|
135
|
+
*
|
|
136
|
+
* @see {@link onBackgrounded}
|
|
137
|
+
* @returns {void}
|
|
138
|
+
*/
|
|
139
|
+
onForegrounded(): void;
|
|
140
|
+
/**
|
|
141
|
+
* @param {string} projectPublicId
|
|
142
|
+
*/
|
|
143
|
+
leaveProject(projectPublicId: string): Promise<void>;
|
|
144
|
+
getMapStyleJsonUrl(): Promise<string>;
|
|
145
|
+
/**
|
|
146
|
+
* MapeoRPC instance, used for tests
|
|
147
|
+
*/
|
|
148
|
+
get [kRPC](): LocalPeers;
|
|
149
|
+
/**
|
|
150
|
+
* Create a Mapeo replication stream. This replication connects the Mapeo RPC
|
|
151
|
+
* channel and allows invites. All active projects will sync automatically to
|
|
152
|
+
* this replication stream. Only use for local (trusted) connections, because
|
|
153
|
+
* the RPC channel key is public. To sync a specific project without
|
|
154
|
+
* connecting RPC, use project[kProjectReplication].
|
|
155
|
+
*
|
|
156
|
+
* @param {boolean} isInitiator
|
|
157
|
+
*/
|
|
158
|
+
[kManagerReplicate](isInitiator: boolean): import("./types.js").ReplicationStream;
|
|
159
|
+
#private;
|
|
160
|
+
}
|
|
161
|
+
export type ValidatedProjectKeys = SetNonNullable<ProjectKeys, "encryptionKeys">;
|
|
162
|
+
export type PublicPeerInfo = Omit<import("./local-peers.js").PeerInfo, "protomux">;
|
|
163
|
+
export type MapeoManagerEvents = {
|
|
164
|
+
/**
|
|
165
|
+
* Emitted when the list of connected peers changes (new ones added, or connection status changes)
|
|
166
|
+
*/
|
|
167
|
+
"local-peers": (peers: PublicPeerInfo[]) => void;
|
|
168
|
+
};
|
|
169
|
+
import { TypedEmitter } from 'tiny-typed-emitter';
|
|
170
|
+
import { MapeoProject } from './mapeo-project.js';
|
|
171
|
+
import type { ProjectSettingsValue as ProjectValue } from '@comapeo/schema';
|
|
172
|
+
import type { DeviceInfoParam } from './schema/client.js';
|
|
173
|
+
import { InviteApi } from './invite-api.js';
|
|
174
|
+
import { LocalPeers } from './local-peers.js';
|
|
175
|
+
import type { CoreStorage } from './types.js';
|
|
176
|
+
import { ProjectKeys } from './generated/keys.js';
|
|
177
|
+
import type { SetNonNullable } from 'type-fest';
|
|
178
|
+
//# sourceMappingURL=mapeo-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapeo-manager.d.ts","sourceRoot":"","sources":["../src/mapeo-manager.js"],"names":[],"mappings":"AAsEA,iCAAiC;AACjC,8CAA4D;AAE5D;;GAEG;AAEH;;;GAGG;AAEH;;GAEG;AACH;IAqBE;;;;;;;;;OASG;IACH,8HARG;QAAqB,OAAO,EAApB,MAAM;QACO,QAAQ,EAArB,MAAM;QACO,uBAAuB,EAApC,MAAM;QACO,sBAAsB,EAAnC,MAAM;QACqB,WAAW,EAAtC,MAAM,GAAG,WAAW;QACoB,OAAO,EAA/C,OAAO,SAAS,EAAE,eAAe;QACnB,iBAAiB;KAAC,EAoF1C;IASD,uBAEC;IA6ID;;;;;;;;;OASG;IACH;;qBALsB,MAAM;oBAGf,OAAO,CAAC,MAAM,CAAC,CA0E3B;IAED;;;OAGG;IACH,4BAHW,MAAM,GACJ,OAAO,CAAC,YAAY,CAAC,CAuCjC;IAqBD;;OAEG;IACH,gBAFa,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,YAAY,EAAE,MAAM,CAAC,GAAG;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAC,CAAC,CAAC,CAgDrH;IAED;;;;;;;;OAQG;IACH,0DAJW,IAAI,CAAC,OAAO,oBAAoB,EAAE,kBAAkB,EAAE,YAAY,GAAG,gBAAgB,CAAC,GAAG;QAAE,WAAW,EAAE,MAAM,CAAA;KAAE;sBAChG,OAAO;sBACrB,OAAO,CAAC,MAAM,CAAC,CAgF3B;IAgED;;;;OAIG;IAEH;;;;OAIG;IACH,cAHoF,CAAC,SADxE,OAAQ,WAAW,EAAE,KAAK,CACtC,OAAS,oBAAoB,EAAE,eAAe,GAAG;QAAC,UAAU,CAAC,+EAAe;KAAC,EAAE,CAAC,CAAE,cACxE,CAAC,iBA8BX;IAED;;;;;;;OAOG;IACH,iBAPa,CACZ;QACA,QAAc,EAAE,MAAM,CAAC;QACvB,UAAgB,EAAE,eAAe,CAAC,YAAY,CAAC,CAAA;KAC1C,GAAG,OAAO,CAAC,eAAe,CAAC,CAC7B,CAaH;IAED;;OAEG;IACH,wBAEC;IAED,yDAAyD;IACzD,iCADc,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAGpD;;;;;;;;;;IAYD;;OAEG;IACH,kBAFa,OAAO,CAAC,cAAc,EAAE,CAAC,CAIrC;IAED;;;;;;;OAOG;IACH,kBAFa,IAAI,CAKhB;IAED;;;;;;;OAOG;IACH,kBAFa,IAAI,CAKhB;IAED;;OAEG;IACH,8BAFW,MAAM,iBAgDhB;IAED,sCAGC;IA7pBD;;OAEG;IACH,yBAEC;IAMD;;;;;;;;OAQG;IACH,iCAFW,OAAO,0CAOjB;;CAqoBF;mCA9yBa,eAAe,WAAW,EAAE,gBAAgB,CAAC;6BAkB9C,IAAI,CAAC,OAAO,kBAAkB,EAAE,QAAQ,EAAE,UAAU,CAAC;;;;;mBAKpD,CAAC,KAAK,EAAE,cAAc,EAAE,KAAK,IAAI;;6BAvElB,oBAAoB;6BAU1C,oBAAoB;0DAgC+B,iBAAiB;qCAGtC,oBAAoB;0BAb/B,iBAAiB;2BADhB,kBAAkB;iCAaD,YAAY;4BA5B5B,qBAAqB;oCA2Bb,WAAW"}
|