@comapeo/core 4.1.1 → 4.1.3-prerelease.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.
Files changed (34) hide show
  1. package/dist/blob-store/live-download.d.ts +107 -0
  2. package/dist/blob-store/live-download.d.ts.map +1 -0
  3. package/dist/capabilities.d.ts +121 -0
  4. package/dist/capabilities.d.ts.map +1 -0
  5. package/dist/core-manager/compat.d.ts +4 -0
  6. package/dist/core-manager/compat.d.ts.map +1 -0
  7. package/dist/discovery/dns-sd.d.ts +54 -0
  8. package/dist/discovery/dns-sd.d.ts.map +1 -0
  9. package/dist/discovery/local-discovery.d.ts.map +1 -1
  10. package/dist/fastify-plugins/maps/index.d.ts +11 -0
  11. package/dist/fastify-plugins/maps/index.d.ts.map +1 -0
  12. package/dist/fastify-plugins/maps/offline-fallback-map.d.ts +12 -0
  13. package/dist/fastify-plugins/maps/offline-fallback-map.d.ts.map +1 -0
  14. package/dist/fastify-plugins/maps/static-maps.d.ts +11 -0
  15. package/dist/fastify-plugins/maps/static-maps.d.ts.map +1 -0
  16. package/dist/index-writer/index.d.ts.map +1 -1
  17. package/dist/index.d.ts +20 -2
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/invite-api.d.ts +70 -0
  20. package/dist/invite-api.d.ts.map +1 -0
  21. package/dist/lib/timing-safe-equal.d.ts +15 -0
  22. package/dist/lib/timing-safe-equal.d.ts.map +1 -0
  23. package/dist/media-server.d.ts +36 -0
  24. package/dist/media-server.d.ts.map +1 -0
  25. package/dist/server/ws-core-replicator.d.ts +6 -0
  26. package/dist/server/ws-core-replicator.d.ts.map +1 -0
  27. package/dist/sync/peer-sync-controller.d.ts.map +1 -1
  28. package/package.json +1 -1
  29. package/src/discovery/local-discovery.js +6 -2
  30. package/src/index-writer/index.js +12 -10
  31. package/src/index.js +36 -5
  32. package/src/invite/invite-state-machine.js +2 -2
  33. package/src/mapeo-manager.js +2 -2
  34. package/src/sync/peer-sync-controller.js +3 -1
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Reduce multiple states into one. Factored out for unit testing because I
3
+ * don't trust my coding. Probably a smarter way to do this, but this works.
4
+ *
5
+ * @param {Iterable<{ state: BlobDownloadState | BlobDownloadStateError }>} liveDownloads
6
+ * @param {{ signal?: AbortSignal }} options
7
+ * @returns {BlobDownloadState | BlobDownloadStateError}
8
+ */
9
+ export function combineStates(liveDownloads: Iterable<{
10
+ state: BlobDownloadState | BlobDownloadStateError;
11
+ }>, { signal }?: {
12
+ signal?: AbortSignal;
13
+ }): BlobDownloadState | BlobDownloadStateError;
14
+ /**
15
+ * @typedef {object} BlobDownloadState
16
+ * @property {number} haveCount The number of files already downloaded
17
+ * @property {number} haveBytes The bytes already downloaded
18
+ * @property {number} wantCount The number of files pending download
19
+ * @property {number} wantBytes The bytes pending download
20
+ * @property {null} error If status = 'error' then this will be an Error object
21
+ * @property {'checking' | 'downloading' | 'downloaded' | 'aborted'} status
22
+ */
23
+ /** @typedef {Omit<BlobDownloadState, 'error' | 'status'> & { status: 'error', error: Error }} BlobDownloadStateError */
24
+ /**
25
+ * @typedef {object} BlobDownloadEvents
26
+ * @property {(state: BlobDownloadState | BlobDownloadStateError ) => void} state Emitted with the current download state whenever it changes (not emitted during initial 'checking' status)
27
+ */
28
+ /**
29
+ * LiveDownload class
30
+ * @extends {TypedEmitter<BlobDownloadEvents>}
31
+ */
32
+ export class LiveDownload extends TypedEmitter<BlobDownloadEvents> {
33
+ /**
34
+ * Like drive.download() but 'live', and for multiple drives
35
+ * @param {Iterable<import('hyperdrive')>} drives
36
+ * @param {import('./index.js').InternalDriveEmitter} emitter
37
+ * @param {object} options
38
+ * @param {import('../types.js').BlobFilter} [options.filter] Filter blobs of specific types and/or sizes to download
39
+ * @param {AbortSignal} [options.signal]
40
+ */
41
+ constructor(drives: Iterable<import("hyperdrive")>, emitter: import("./index.js").InternalDriveEmitter, { filter, signal }: {
42
+ filter?: import("../types.js").BlobFilter | undefined;
43
+ signal?: AbortSignal | undefined;
44
+ });
45
+ /**
46
+ * @returns {BlobDownloadState | BlobDownloadStateError}
47
+ */
48
+ get state(): BlobDownloadState | BlobDownloadStateError;
49
+ #private;
50
+ }
51
+ /**
52
+ * LiveDownload class
53
+ * @extends {TypedEmitter<BlobDownloadEvents>}
54
+ */
55
+ export class DriveLiveDownload extends TypedEmitter<BlobDownloadEvents> {
56
+ /**
57
+ * Like drive.download() but 'live',
58
+ * @param {import('hyperdrive')} drive
59
+ * @param {object} options
60
+ * @param {import('../types.js').BlobFilter} [options.filter] Filter blobs of specific types and/or sizes to download
61
+ * @param {AbortSignal} [options.signal]
62
+ */
63
+ constructor(drive: import("hyperdrive"), { filter, signal }?: {
64
+ filter?: import("../types.js").BlobFilter | undefined;
65
+ signal?: AbortSignal | undefined;
66
+ });
67
+ /**
68
+ * @returns {BlobDownloadState | BlobDownloadStateError}
69
+ */
70
+ get state(): BlobDownloadState | BlobDownloadStateError;
71
+ #private;
72
+ }
73
+ export type BlobDownloadState = {
74
+ /**
75
+ * The number of files already downloaded
76
+ */
77
+ haveCount: number;
78
+ /**
79
+ * The bytes already downloaded
80
+ */
81
+ haveBytes: number;
82
+ /**
83
+ * The number of files pending download
84
+ */
85
+ wantCount: number;
86
+ /**
87
+ * The bytes pending download
88
+ */
89
+ wantBytes: number;
90
+ /**
91
+ * If status = 'error' then this will be an Error object
92
+ */
93
+ error: null;
94
+ status: "checking" | "downloading" | "downloaded" | "aborted";
95
+ };
96
+ export type BlobDownloadStateError = Omit<BlobDownloadState, "error" | "status"> & {
97
+ status: "error";
98
+ error: Error;
99
+ };
100
+ export type BlobDownloadEvents = {
101
+ /**
102
+ * Emitted with the current download state whenever it changes (not emitted during initial 'checking' status)
103
+ */
104
+ state: (state: BlobDownloadState | BlobDownloadStateError) => void;
105
+ };
106
+ import { TypedEmitter } from 'tiny-typed-emitter';
107
+ //# sourceMappingURL=live-download.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"live-download.d.ts","sourceRoot":"","sources":["../../src/blob-store/live-download.js"],"names":[],"mappings":"AA+RA;;;;;;;GAOG;AACH,6CAJW,QAAQ,CAAC;IAAE,KAAK,EAAE,iBAAiB,GAAG,sBAAsB,CAAA;CAAE,CAAC,eAC/D;IAAE,MAAM,CAAC,EAAE,WAAW,CAAA;CAAE,GACtB,iBAAiB,GAAG,sBAAsB,CAqCtD;AApUD;;;;;;;;GAQG;AAEH,wHAAwH;AAExH;;;GAGG;AAEH;;;GAGG;AACH;IAKE;;;;;;;OAOG;IACH,oBANW,QAAQ,CAAC,OAAO,YAAY,CAAC,CAAC,WAC9B,OAAO,YAAY,EAAE,oBAAoB,sBAEjD;QAAmD,MAAM;QAC3B,MAAM;KAAC,EAiCvC;IAED;;OAEG;IACH,wDAEC;;CACF;AAED;;;GAGG;AACH;IAaE;;;;;;OAMG;IACH,mBALW,OAAO,YAAY,CAAC,uBAE5B;QAAmD,MAAM;QAC3B,MAAM;KAAC,EAmBvC;IAED;;OAEG;IACH,wDAyBC;;CAqIF;;;;;eArRa,MAAM;;;;eACN,MAAM;;;;eACN,MAAM;;;;eACN,MAAM;;;;WACN,IAAI;YACJ,UAAU,GAAG,aAAa,GAAG,YAAY,GAAG,SAAS;;qCAGrD,IAAI,CAAC,iBAAiB,EAAE,OAAO,GAAG,QAAQ,CAAC,GAAG;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE;;;;;WAI/E,CAAC,KAAK,EAAE,iBAAiB,GAAG,sBAAsB,KAAM,IAAI;;6BApB7C,oBAAoB"}
@@ -0,0 +1,121 @@
1
+ export const COORDINATOR_ROLE_ID: "f7c150f5a3a9a855";
2
+ export const MEMBER_ROLE_ID: "012fd2d431c0bf60";
3
+ export const BLOCKED_ROLE_ID: "9e6d29263cba36c9";
4
+ export const LEFT_ROLE_ID: "8ced989b1904606b";
5
+ /**
6
+ * @typedef {object} DocCapability
7
+ * @property {boolean} readOwn - can read own data
8
+ * @property {boolean} writeOwn - can write own data
9
+ * @property {boolean} readOthers - can read other's data
10
+ * @property {boolean} writeOthers - can edit or delete other's data
11
+ */
12
+ /**
13
+ * @typedef {object} Capability
14
+ * @property {string} name
15
+ * @property {Record<import('@mapeo/schema').MapeoDoc['schemaName'], DocCapability>} docs
16
+ * @property {RoleId[]} roleAssignment
17
+ * @property {Record<import('./core-manager/core-index.js').Namespace, 'allowed' | 'blocked'>} sync
18
+ */
19
+ /**
20
+ * @typedef {typeof COORDINATOR_ROLE_ID | typeof MEMBER_ROLE_ID | typeof BLOCKED_ROLE_ID | typeof LEFT_ROLE_ID} RoleId
21
+ */
22
+ /**
23
+ * This is currently the same as 'Coordinator' capabilities, but defined
24
+ * separately because the creator should always have ALL capabilities, but we
25
+ * could edit 'Coordinator' capabilities in the future
26
+ *
27
+ * @type {Capability}
28
+ */
29
+ export const CREATOR_CAPABILITIES: Capability;
30
+ /**
31
+ * These are the capabilities assumed for a device when no capability record can
32
+ * be found. This can happen when an invited device did not manage to sync with
33
+ * the device that invited them, and they then try to sync with someone else. We
34
+ * want them to be able to sync the auth and config store, because that way they
35
+ * may be able to receive their role record, and they can get the project config
36
+ * so that they can start collecting data.
37
+ *
38
+ * @type {Capability}
39
+ */
40
+ export const NO_ROLE_CAPABILITIES: Capability;
41
+ /** @type {Record<RoleId, Capability>} */
42
+ export const DEFAULT_CAPABILITIES: Record<RoleId, Capability>;
43
+ export class Capabilities {
44
+ static NO_ROLE_CAPABILITIES: Capability;
45
+ /**
46
+ *
47
+ * @param {object} opts
48
+ * @param {import('./datatype/index.js').DataType<
49
+ * import('./datastore/index.js').DataStore<'auth'>,
50
+ * typeof import('./schema/project.js').roleTable,
51
+ * 'role',
52
+ * import('@mapeo/schema').Role,
53
+ * import('@mapeo/schema').RoleValue
54
+ * >} opts.dataType
55
+ * @param {import('./core-ownership.js').CoreOwnership} opts.coreOwnership
56
+ * @param {import('./core-manager/index.js').CoreManager} opts.coreManager
57
+ * @param {Buffer} opts.projectKey
58
+ * @param {Buffer} opts.deviceKey public key of this device
59
+ */
60
+ constructor({ dataType, coreOwnership, coreManager, projectKey, deviceKey }: {
61
+ dataType: import('./datatype/index.js').DataType<import('./datastore/index.js').DataStore<'auth'>, typeof import('./schema/project.js').roleTable, 'role', import('@mapeo/schema').Role, import('@mapeo/schema').RoleValue>;
62
+ coreOwnership: import('./core-ownership.js').CoreOwnership;
63
+ coreManager: import('./core-manager/index.js').CoreManager;
64
+ projectKey: Buffer;
65
+ deviceKey: Buffer;
66
+ });
67
+ /**
68
+ * Get the capabilities for device `deviceId`.
69
+ *
70
+ * @param {string} deviceId
71
+ * @returns {Promise<Capability>}
72
+ */
73
+ getCapabilities(deviceId: string): Promise<Capability>;
74
+ /**
75
+ * Get capabilities of all devices in the project. For your own device, if you
76
+ * have not yet synced your own role record, the "no role" capabilties is
77
+ * returned. The project creator will have `CREATOR_CAPABILITIES` unless a
78
+ * different role has been assigned.
79
+ *
80
+ * @returns {Promise<Record<string, Capability>>} Map of deviceId to Capability
81
+ */
82
+ getAll(): Promise<Record<string, Capability>>;
83
+ /**
84
+ * Assign a role to the specified `deviceId`. Devices without an assigned role
85
+ * are unable to sync, except the project creator that defaults to having all
86
+ * capabilities. Only the project creator can assign their own role. Will
87
+ * throw if the device trying to assign the role lacks the `roleAssignment`
88
+ * capability for the given roleId
89
+ *
90
+ * @param {string} deviceId
91
+ * @param {keyof typeof DEFAULT_CAPABILITIES} roleId
92
+ */
93
+ assignRole(deviceId: string, roleId: keyof typeof DEFAULT_CAPABILITIES): Promise<void>;
94
+ #private;
95
+ }
96
+ export type DocCapability = {
97
+ /**
98
+ * - can read own data
99
+ */
100
+ readOwn: boolean;
101
+ /**
102
+ * - can write own data
103
+ */
104
+ writeOwn: boolean;
105
+ /**
106
+ * - can read other's data
107
+ */
108
+ readOthers: boolean;
109
+ /**
110
+ * - can edit or delete other's data
111
+ */
112
+ writeOthers: boolean;
113
+ };
114
+ export type Capability = {
115
+ name: string;
116
+ docs: Record<import('@mapeo/schema').MapeoDoc['schemaName'], DocCapability>;
117
+ roleAssignment: RoleId[];
118
+ sync: Record<import('./core-manager/core-index.js').Namespace, 'allowed' | 'blocked'>;
119
+ };
120
+ export type RoleId = typeof COORDINATOR_ROLE_ID | typeof MEMBER_ROLE_ID | typeof BLOCKED_ROLE_ID | typeof LEFT_ROLE_ID;
121
+ //# sourceMappingURL=capabilities.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capabilities.d.ts","sourceRoot":"","sources":["../src/capabilities.js"],"names":[],"mappings":"AAKA,qDAAqD;AACrD,gDAAgD;AAChD,iDAAiD;AACjD,8CAA8C;AAE9C;;;;;;GAMG;AAEH;;;;;;GAMG;AAEH;;GAEG;AAEH;;;;;;GAMG;AACH,mCAFU,UAAU,CAkBnB;AAED;;;;;;;;;GASG;AACH,mCAFU,UAAU,CAkBnB;AAED,yCAAyC;AACzC,mCADW,OAAO,MAAM,EAAE,UAAU,CAAC,CAgFpC;AAED;IAOE,wCAAkD;IAElD;;;;;;;;;;;;;;OAcG;IACH;QANW,QAAQ,EANR,OAAO,qBAAqB,EAAE,QAAQ,CAChD,OAAW,sBAAsB,EAAE,SAAS,CAAC,MAAM,CAAC,EACpD,cAAkB,qBAAqB,EAAE,SAAS,EAClD,MAAU,EACV,OAAW,eAAe,EAAE,IAAI,EAChC,OAAW,eAAe,EAAE,SAAS,CAClC;QACyD,aAAa,EAA/D,OAAO,qBAAqB,EAAE,aAAa;QACS,WAAW,EAA/D,OAAO,yBAAyB,EAAE,WAAW;QAChC,UAAU,EAAvB,MAAM;QACO,SAAS,EAAtB,MAAM;OAQhB;IAED;;;;;OAKG;IACH,0BAHW,MAAM,GACJ,QAAQ,UAAU,CAAC,CAuB/B;IAED;;;;;;;OAOG;IACH,UAFa,QAAQ,OAAO,MAAM,EAAE,UAAU,CAAC,CAAC,CAkC/C;IAED;;;;;;;;;OASG;IACH,qBAHW,MAAM,UACN,MAAM,2BAA2B,iBAyD3C;;CAQF;;;;;aAzUa,OAAO;;;;cACP,OAAO;;;;gBACP,OAAO;;;;iBACP,OAAO;;;UAKP,MAAM;UACN,OAAO,OAAO,eAAe,EAAE,QAAQ,CAAC,YAAY,CAAC,EAAE,aAAa,CAAC;oBACrE,MAAM,EAAE;UACR,OAAO,OAAO,8BAA8B,EAAE,SAAS,EAAE,SAAS,GAAG,SAAS,CAAC;;qBAIhF,0BAA0B,GAAG,qBAAqB,GAAG,sBAAsB,GAAG,mBAAmB"}
@@ -0,0 +1,4 @@
1
+ /// <reference path="../../types/quickbit-universal.d.ts" />
2
+ export let quickbit: typeof universal;
3
+ import universal = require("quickbit-universal");
4
+ //# sourceMappingURL=compat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compat.d.ts","sourceRoot":"","sources":["../../src/core-manager/compat.js"],"names":[],"mappings":";AAOA,sCAAwB"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * @typedef {object} MapeoService
3
+ * @property {string} address IPv4 address of service
4
+ * @property {number} port
5
+ * @property {string} name Instance name
6
+ */
7
+ /**
8
+ * @typedef {object} DnsSdEvents
9
+ * @property {(service: MapeoService) => void} up
10
+ * @property {(service: MapeoService) => void} down
11
+ */
12
+ /**
13
+ * @extends {TypedEmitter<DnsSdEvents>}
14
+ */
15
+ export class DnsSd extends TypedEmitter<DnsSdEvents> {
16
+ /**
17
+ *
18
+ * @param {object} [opts]
19
+ * @param {string} [opts.name]
20
+ * @param {boolean} [opts.disableIpv6]
21
+ * @param {Logger} [opts.logger]
22
+ */
23
+ constructor({ name, disableIpv6, logger }?: {
24
+ name?: string | undefined;
25
+ disableIpv6?: boolean | undefined;
26
+ logger?: Logger | undefined;
27
+ } | undefined);
28
+ get name(): string;
29
+ /** @param {number} port */
30
+ advertise(port: number): Promise<void>;
31
+ browse(): void;
32
+ stopAdvertising(): Promise<void>;
33
+ stopBrowsing(): void;
34
+ destroy(): Promise<void>;
35
+ #private;
36
+ }
37
+ export type MapeoService = {
38
+ /**
39
+ * IPv4 address of service
40
+ */
41
+ address: string;
42
+ port: number;
43
+ /**
44
+ * Instance name
45
+ */
46
+ name: string;
47
+ };
48
+ export type DnsSdEvents = {
49
+ up: (service: MapeoService) => void;
50
+ down: (service: MapeoService) => void;
51
+ };
52
+ import { TypedEmitter } from 'tiny-typed-emitter';
53
+ import { Logger } from '../logger.js';
54
+ //# sourceMappingURL=dns-sd.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dns-sd.d.ts","sourceRoot":"","sources":["../../src/discovery/dns-sd.js"],"names":[],"mappings":"AAUA;;;;;GAKG;AAEH;;;;GAIG;AAEH;;GAEG;AACH;IAoDE;;;;;;OAMG;IACH;;;;mBAMC;IAED,mBAEC;IAED,2BAA2B;IAC3B,gBADY,MAAM,iBA+BjB;IAED,eAiBC;IAED,iCAeC;IAED,qBAKC;IAED,yBA0BC;;CA+BF;;;;;aA1Na,MAAM;UACN,MAAM;;;;UACN,MAAM;;;kBAKI,YAAY,KAAK,IAAI;oBACrB,YAAY,KAAK,IAAI;;6BApBhB,oBAAoB;uBAM1B,cAAc"}
@@ -1 +1 @@
1
- {"version":3,"file":"local-discovery.d.ts","sourceRoot":"","sources":["../../src/discovery/local-discovery.js"],"names":[],"mappings":"AAqBA,mDAAmD;AAEnD;;;GAGG;AAEH;;GAEG;AACH;IAaE;;;;OAIG;IACH,yCAHG;QAAsB,eAAe,EAA7B,OAAO;QACO,MAAM;KAAC,EAqB/B;IAED,yDAAyD;IACzD,SADc,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAIpD;IAqBD;;;;;;OAMG;IACH,qCALG;QAAqB,OAAO,EAApB,MAAM;QACO,IAAI,EAAjB,MAAM;QACO,IAAI,EAAjB,MAAM;KACd,GAAU,IAAI,CAkBhB;IAqJD;;;;;;;;;OASG;IACH;;;oBAFa,OAAO,CAAC,IAAI,CAAC,CAIzB;;CA+BF;sBAxSa;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE;mCACxC,kBAAkB,GAAG,CAAC,MAAM,CAAC;;gBAU7B,CAAC,UAAU,EAAE,oBAAoB,KAAK,IAAI;;6BAzB3B,oBAAoB;uBAU1B,cAAc;gBATrB,UAAU;uCAWa,uCAAuC"}
1
+ {"version":3,"file":"local-discovery.d.ts","sourceRoot":"","sources":["../../src/discovery/local-discovery.js"],"names":[],"mappings":"AAyBA,mDAAmD;AAEnD;;;GAGG;AAEH;;GAEG;AACH;IAaE;;;;OAIG;IACH,yCAHG;QAAsB,eAAe,EAA7B,OAAO;QACO,MAAM;KAAC,EAqB/B;IAED,yDAAyD;IACzD,SADc,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAIpD;IAqBD;;;;;;OAMG;IACH,qCALG;QAAqB,OAAO,EAApB,MAAM;QACO,IAAI,EAAjB,MAAM;QACO,IAAI,EAAjB,MAAM;KACd,GAAU,IAAI,CAkBhB;IAqJD;;;;;;;;;OASG;IACH;;;oBAFa,OAAO,CAAC,IAAI,CAAC,CAIzB;;CA+BF;sBA5Sa;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE;mCACxC,kBAAkB,GAAG,CAAC,MAAM,CAAC;;gBAc7B,CAAC,UAAU,EAAE,oBAAoB,KAAK,IAAI;;6BA7B3B,oBAAoB;uBAU1B,cAAc;gBATrB,UAAU;uCAWa,uCAAuC"}
@@ -0,0 +1,11 @@
1
+ export const PLUGIN_NAME: "mapeo-maps";
2
+ export const DEFAULT_MAPBOX_STYLE_URL: "https://api.mapbox.com/styles/v1/mapbox/outdoors-v12";
3
+ export function plugin(instance: import("fastify").FastifyInstance<import("fastify").RawServerDefault, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>, opts: MapsPluginOpts): Promise<void>;
4
+ export type MapsPluginOpts = {
5
+ prefix?: string | undefined;
6
+ defaultOnlineStyleUrl?: string | undefined;
7
+ };
8
+ export type MapsPluginContext = {
9
+ getStyleJsonUrl: () => Promise<string>;
10
+ };
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fastify-plugins/maps/index.js"],"names":[],"mappings":"AAYA,uCAAuC;AACvC,8FACwD;;;;;;;qBA8B1C,MAAM,OAAO,CAAC,MAAM,CAAC"}
@@ -0,0 +1,12 @@
1
+ export const PLUGIN_NAME: "mapeo-static-maps";
2
+ export function plugin(instance: import("fastify").FastifyInstance<import("fastify").RawServerDefault, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>, opts: OfflineFallbackMapPluginOpts): Promise<void>;
3
+ export type OfflineFallbackMapPluginOpts = {
4
+ prefix?: string | undefined;
5
+ styleJsonPath: string;
6
+ sourcesDir: string;
7
+ };
8
+ export type FallbackMapPluginDecorator = {
9
+ getResolvedStyleJson: (serverAddress: string) => Promise<any>;
10
+ getStyleJsonStats: () => Promise<import("node:fs").Stats>;
11
+ };
12
+ //# sourceMappingURL=offline-fallback-map.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"offline-fallback-map.d.ts","sourceRoot":"","sources":["../../../src/fastify-plugins/maps/offline-fallback-map.js"],"names":[],"mappings":"AAWA,8CAA8C;;;;mBAUhC,MAAM;gBACN,MAAM;;;0BAKN,CAAC,aAAa,EAAE,MAAM,KAAK,OAAO,CAAC,GAAG,CAAC;uBACvC,MAAM,OAAO,CAAC,OAAO,SAAS,EAAE,KAAK,CAAC"}
@@ -0,0 +1,11 @@
1
+ export const PLUGIN_NAME: "mapeo-static-maps";
2
+ export function plugin(instance: import("fastify").FastifyInstance<import("fastify").RawServerDefault, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>, opts: StaticMapsPluginOpts): Promise<void>;
3
+ export type StaticMapsPluginOpts = {
4
+ prefix?: string | undefined;
5
+ staticRootDir: string;
6
+ };
7
+ export type StaticMapsPluginDecorator = {
8
+ getResolvedStyleJson: (styleId: string, serverAddress: string) => Promise<string>;
9
+ getStyleJsonStats: (styleId: string) => Promise<import("node:fs").Stats>;
10
+ };
11
+ //# sourceMappingURL=static-maps.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"static-maps.d.ts","sourceRoot":"","sources":["../../../src/fastify-plugins/maps/static-maps.js"],"names":[],"mappings":"AAeA,8CAA8C;;;;mBAUhC,MAAM;;;0BAKN,CAAC,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC;uBAC3D,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,SAAS,EAAE,KAAK,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index-writer/index.js"],"names":[],"mappings":"AAMA,mEAAmE;AACnE,6DAA6D;AAE7D;;GAEG;AACH;;GAEG;AAEH;;GAEG;AACH,yBAF+B,OAAO,SAAzB,cAAgB;IAY3B;;;;;;;;OAQG;IACH,2DANG;QAAgD,MAAM,EAA9C,OAAO,gBAAgB,EAAE,QAAQ;QACjB,MAAM,EAAtB,OAAO,EAAE;QAC4D,MAAM,UAArE,gBAAgB,WAAW,eAAe,KAAK,QAAQ;QACE,SAAS;QAC1D,MAAM;KAAC,EAiB/B;IAED;;OAEG;IACH,8CAEC;IAED;;;OAGG;IACH,eAHW,OAAO,oBAAoB,EAAE,KAAK,EAAE,GAClC,OAAO,CAAC,aAAa,CAAC,CA+ClC;IAED;;OAEG;IACH,qDAMC;;CACF;4BAjHY,GAAG,CAA2B,IAAtB,QAAQ,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,GAAE;+BAG5C,UAAU,CAAC,OAAO,MAAM,CAAC;oCANF,sBAAsB;qCADX,iBAAiB;8BAAjB,iBAAiB;uBADzC,cAAc;uBALd,iBAAiB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index-writer/index.js"],"names":[],"mappings":"AAMA,mEAAmE;AACnE,6DAA6D;AAE7D;;GAEG;AACH;;GAEG;AAEH;;GAEG;AACH,yBAF+B,OAAO,SAAzB,cAAgB;IAY3B;;;;;;;;OAQG;IACH,2DANG;QAAgD,MAAM,EAA9C,OAAO,gBAAgB,EAAE,QAAQ;QACjB,MAAM,EAAtB,OAAO,EAAE;QAC4D,MAAM,UAArE,gBAAgB,WAAW,eAAe,KAAK,QAAQ;QACE,SAAS;QAC1D,MAAM;KAAC,EAiB/B;IAED;;OAEG;IACH,8CAEC;IAED;;;OAGG;IACH,eAHW,OAAO,oBAAoB,EAAE,KAAK,EAAE,GAClC,OAAO,CAAC,aAAa,CAAC,CAiDlC;IAED;;OAEG;IACH,qDAMC;;CACF;4BAnHY,GAAG,CAA2B,IAAtB,QAAQ,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,GAAE;+BAG5C,UAAU,CAAC,OAAO,MAAM,CAAC;oCANF,sBAAsB;qCADX,iBAAiB;8BAAjB,iBAAiB;uBADzC,cAAc;uBALd,iBAAiB"}
package/dist/index.d.ts CHANGED
@@ -1,13 +1,31 @@
1
1
  export { plugin as CoMapeoMapsFastifyPlugin } from "./fastify-plugins/maps.js";
2
2
  export { FastifyController } from "./fastify-controller.js";
3
3
  export { MapeoManager } from "./mapeo-manager.js";
4
- export function replicateProject(project: MapeoProject, isInitiatorOrStream: boolean | import("streamx").Duplex<any, any, any, any, true, true, import("streamx").DuplexEvents<any, any>> | import("stream").Duplex): ReturnType<(isInitiatorOrStream: (boolean | import("stream").Duplex | import("streamx").Duplex)) => import("./types.js").ReplicationStream>;
4
+ export function replicateProject(project: MapeoProject, isInitiatorOrStream: (boolean | import("stream").Duplex | import("streamx").Duplex)): import("./types.js").ReplicationStream;
5
5
  export namespace roles {
6
6
  export { CREATOR_ROLE_ID };
7
7
  export { COORDINATOR_ROLE_ID };
8
8
  export { MEMBER_ROLE_ID };
9
9
  }
10
- import type { MapeoProject } from './mapeo-project.js';
10
+ export type MapeoProject = import("./mapeo-project.js").MapeoProject;
11
+ export type EditableProjectSettings = import("./mapeo-project.js").EditableProjectSettings;
12
+ export namespace IconApi {
13
+ type BitmapOpts = import("./icon-api.js").BitmapOpts;
14
+ type SvgOpts = import("./icon-api.js").SvgOpts;
15
+ }
16
+ export namespace BlobApi {
17
+ type BlobId = import("./types.js").BlobId;
18
+ type Metadata = import("./blob-api.js").Metadata;
19
+ type BlobVariant<TBlobType extends import("./types.js").BlobType> = import("./types.js").BlobVariant<TBlobType>;
20
+ }
21
+ export namespace InviteApi {
22
+ type Invite = import("./invite/invite-api.js").Invite;
23
+ }
24
+ export namespace MemberApi {
25
+ type MemberInfo = import("./member-api.js").MemberInfo;
26
+ type RoleId = import("./roles.js").RoleId;
27
+ type RoleIdForNewInvite = import("./roles.js").RoleIdForNewInvite;
28
+ }
11
29
  import { CREATOR_ROLE_ID } from './roles.js';
12
30
  import { COORDINATOR_ROLE_ID } from './roles.js';
13
31
  import { MEMBER_ROLE_ID } from './roles.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":";;;AAgBO,0CAJI,YAAY,gKAEV,UAAU,yCAU4kmB,QAAQ,kBAAyB,SAAS,qDAV3kmB,CAG7B;;;;;;kCARH,oBAAoB;gCAL/C,YAAY;oCAAZ,YAAY;+BAAZ,YAAY"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":";;;AA+CO,0CARI,YAAY,uBACZ,CACV,OAAW,GACX,OAAW,QAAQ,EAAE,MAAM,GAC3B,OAAW,SAAS,EAAE,MAAM,CACzB,GACS,OAAO,YAAY,EAAE,iBAAiB,CAGF;;;;;;2BArCnC,OAAO,oBAAoB,EAAE,YAAY;sCACzC,OAAO,oBAAoB,EAAE,uBAAuB;;sBAGrD,OAAO,eAAe,EAAE,UAAU;mBAClC,OAAO,eAAe,EAAE,OAAO;;;kBAI/B,OAAO,YAAY,EAAE,MAAM;oBAC3B,OAAO,eAAe,EAAE,QAAQ;qBAIA,SAAS,SAAzC,OAAQ,YAAY,EAAE,QAAS,IAC/B,OAAO,YAAY,EAAE,WAAW,CAAC,SAAS,CAAC;;;kBAI3C,OAAO,wBAAwB,EAAE,MAAM;;;sBAIvC,OAAO,iBAAiB,EAAE,UAAU;kBACpC,OAAO,YAAY,EAAE,MAAM;8BAC3B,OAAO,YAAY,EAAE,kBAAkB;;gCAhC7C,YAAY;oCAAZ,YAAY;+BAAZ,YAAY"}
@@ -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,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 | Uint8Array} T
10
+ * @param {T} a
11
+ * @param {T} b
12
+ * @returns {boolean}
13
+ */
14
+ export default function timingSafeEqual<T extends string | Uint8Array>(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,wCALmC,CAAC,SAAtB,MAAM,GAAG,UAAW,KACvB,CAAC,KACD,CAAC,GACC,OAAO,CASnB"}
@@ -0,0 +1,36 @@
1
+ export const BLOBS_PREFIX: "blobs";
2
+ export const ICONS_PREFIX: "icons";
3
+ /**
4
+ * @typedef {Object} StartOpts
5
+ *
6
+ * @property {string} [host]
7
+ * @property {number} [port]
8
+ */
9
+ export class MediaServer {
10
+ /**
11
+ * @param {object} params
12
+ * @param {(projectPublicId: string) => Promise<import('./mapeo-project.js').MapeoProject>} params.getProject
13
+ * @param {import('fastify').FastifyServerOptions['logger']} [params.logger]
14
+ */
15
+ constructor({ getProject, logger }: {
16
+ getProject: (projectPublicId: string) => Promise<import('./mapeo-project.js').MapeoProject>;
17
+ logger?: import('fastify').FastifyServerOptions['logger'];
18
+ });
19
+ /**
20
+ * @param {StartOpts} [opts]
21
+ */
22
+ start(opts?: StartOpts | undefined): Promise<void>;
23
+ started(): Promise<void>;
24
+ stop(): Promise<void>;
25
+ /**
26
+ * @param {'blobs' | 'icons'} mediaType
27
+ * @returns {Promise<string>}
28
+ */
29
+ getMediaAddress(mediaType: 'blobs' | 'icons'): Promise<string>;
30
+ #private;
31
+ }
32
+ export type StartOpts = {
33
+ host?: string | undefined;
34
+ port?: number | undefined;
35
+ };
36
+ //# sourceMappingURL=media-server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"media-server.d.ts","sourceRoot":"","sources":["../src/media-server.js"],"names":[],"mappings":"AAWA,mCAAmC;AACnC,mCAAmC;AAEnC;;;;;GAKG;AAEH;IAOE;;;;OAIG;IACH;sCAH6B,MAAM,KAAK,QAAQ,OAAO,oBAAoB,EAAE,YAAY,CAAC;iBAC/E,OAAO,SAAS,EAAE,oBAAoB,CAAC,QAAQ,CAAC;OA0B1D;IAoDD;;OAEG;IACH,mDAEC;IAED,yBAEC;IAED,sBAEC;IAED;;;OAGG;IACH,2BAHW,OAAO,GAAG,OAAO,GACf,QAAQ,MAAM,CAAC,CAuB3B;;CACF"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @param {import('ws').WebSocket} ws
3
+ * @param {import('../types.js').ReplicationStream} replicationStream
4
+ */
5
+ export function wsCoreReplicator(ws: import("ws").WebSocket, replicationStream: import("../types.js").ReplicationStream): Promise<void>;
6
+ //# sourceMappingURL=ws-core-replicator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ws-core-replicator.d.ts","sourceRoot":"","sources":["../../src/server/ws-core-replicator.js"],"names":[],"mappings":"AAIA;;;GAGG;AACH,qCAHW,OAAO,IAAI,EAAE,SAAS,qBACtB,OAAO,aAAa,EAAE,iBAAiB,iBAmBjD"}
@@ -1 +1 @@
1
- {"version":3,"file":"peer-sync-controller.d.ts","sourceRoot":"","sources":["../../src/sync/peer-sync-controller.js"],"names":[],"mappings":"AAKA,6DAA6D;AAC7D,0CAA0C;AAC1C,wDAAwD;AACxD,+CAA+C;AAC/C,iFAAiF;AAEjF;;GAEG;AAEH;IAsBE;;;;;;;OAOG;IACH,iEANG;QAAoD,QAAQ,EAApD,OAAO,UAAU,EAAE,iBAAiB,CAAC;QACgB,WAAW,EAAhE,OAAO,0BAA0B,EAAE,WAAW;QACJ,SAAS,EAAnD,OAAO,iBAAiB,EAAE,SAAS;QACD,KAAK,EAAvC,OAAO,aAAa,EAAE,KAAK;QACb,MAAM;KAAC,EAkB/B;IAED,sBAEC;IAED,qBAEC;IAED,gGAEC;IAED,iDAAiD;IACjD,sCADY,gBAAgB,QAO3B;IAED;;OAEG;IACH,iCAFW,MAAM,QAoBhB;;CAqMF;wBAGY,GAAG,SAAsB,IAAT,SAAS,CAAC,CAAC,EAAE,OAAO,sBAAsB,EAAE,kBAAkB,GAAE;yBAG/E,MAAM,CAAC,SAAS,EAAE,SAAS,GAAG,SAAS,GAAG,QAAQ,CAAC;6BAxSpD,IAAI,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,GAAG,SAAS;sCALV,eAAe;uCAEd,uCAAuC;uBAPvD,cAAc;+BAMN,aAAa;0BAFlB,aAAa"}
1
+ {"version":3,"file":"peer-sync-controller.d.ts","sourceRoot":"","sources":["../../src/sync/peer-sync-controller.js"],"names":[],"mappings":"AAKA,6DAA6D;AAC7D,0CAA0C;AAC1C,wDAAwD;AACxD,+CAA+C;AAC/C,iFAAiF;AAEjF;;GAEG;AAEH;IAsBE;;;;;;;OAOG;IACH,iEANG;QAAoD,QAAQ,EAApD,OAAO,UAAU,EAAE,iBAAiB,CAAC;QACgB,WAAW,EAAhE,OAAO,0BAA0B,EAAE,WAAW;QACJ,SAAS,EAAnD,OAAO,iBAAiB,EAAE,SAAS;QACD,KAAK,EAAvC,OAAO,aAAa,EAAE,KAAK;QACb,MAAM;KAAC,EAkB/B;IAED,sBAEC;IAED,qBAEC;IAED,gGAEC;IAED,iDAAiD;IACjD,sCADY,gBAAgB,QAO3B;IAED;;OAEG;IACH,iCAFW,MAAM,QAoBhB;;CAuMF;wBAGY,GAAG,SAAsB,IAAT,SAAS,CAAC,CAAC,EAAE,OAAO,sBAAsB,EAAE,kBAAkB,GAAE;yBAG/E,MAAM,CAAC,SAAS,EAAE,SAAS,GAAG,SAAS,GAAG,QAAQ,CAAC;6BA1SpD,IAAI,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,GAAG,SAAS;sCALV,eAAe;uCAEd,uCAAuC;uBAPvD,cAAc;+BAMN,aAAa;0BAFlB,aAAa"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@comapeo/core",
3
- "version": "4.1.1",
3
+ "version": "4.1.3-prerelease.0",
4
4
  "description": "Offline p2p mapping library",
5
5
  "main": "src/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -15,9 +15,13 @@ import { getErrorCode } from '../lib/error.js'
15
15
  /** @typedef {{ publicKey: Buffer, secretKey: Buffer }} Keypair */
16
16
  /** @typedef {OpenedNoiseStream<net.Socket>} OpenedNetNoiseStream */
17
17
 
18
+ /** @satisfies {import('node:net').ServerOpts | import('node:net').TcpNetConnectOpts} */
18
19
  const TCP_KEEP_ALIVE_OPTIONS = {
19
20
  keepAlive: true,
20
- keepAliveInitialDelay: 10_000,
21
+ keepAliveInitialDelay: 30_000,
22
+ // Turn off Nagle's algorythm, to reduce latency
23
+ // https://github.com/digidem/comapeo-core/issues/1070
24
+ noDelay: true,
21
25
  }
22
26
  export const ERR_DUPLICATE = 'Duplicate connection'
23
27
 
@@ -108,9 +112,9 @@ export class LocalDiscovery extends TypedEmitter {
108
112
  return
109
113
  }
110
114
  const socket = net.connect({
115
+ ...TCP_KEEP_ALIVE_OPTIONS,
111
116
  host: address,
112
117
  port,
113
- ...TCP_KEEP_ALIVE_OPTIONS,
114
118
  })
115
119
  socket.on('error', this.#handleSocketError)
116
120
  socket.once('connect', () => {
@@ -97,16 +97,18 @@ export class IndexWriter {
97
97
  const indexer = this.#indexers.get(schemaName)
98
98
  if (!indexer) continue // Won't happen, but TS doesn't know that
99
99
  indexer.batch(docs)
100
- if (this.#l.log.enabled) {
101
- for (const doc of docs) {
102
- this.#l.log(
103
- 'Indexed %s %S @ %S',
104
- doc.schemaName,
105
- doc.docId,
106
- doc.versionId
107
- )
108
- }
109
- }
100
+ // TODO: selectively turn this on when log level is 'trace' or 'debug'
101
+ // Otherwise this has a big performance overhead because this is all synchronous
102
+ // if (this.#l.log.enabled) {
103
+ // for (const doc of docs) {
104
+ // this.#l.log(
105
+ // 'Indexed %s %S @ %S',
106
+ // doc.schemaName,
107
+ // doc.docId,
108
+ // doc.versionId
109
+ // )
110
+ // }
111
+ // }
110
112
  }
111
113
  return indexed
112
114
  }
package/src/index.js CHANGED
@@ -7,15 +7,46 @@ import { kProjectReplicate } from './mapeo-project.js'
7
7
  export { plugin as CoMapeoMapsFastifyPlugin } from './fastify-plugins/maps.js'
8
8
  export { FastifyController } from './fastify-controller.js'
9
9
  export { MapeoManager } from './mapeo-manager.js'
10
- /** @import { MapeoProject } from './mapeo-project.js' */
11
10
 
11
+ // Type exports
12
+ /** @typedef {import('./mapeo-project.js').MapeoProject} MapeoProject */
13
+ /** @typedef {import('./mapeo-project.js').EditableProjectSettings} EditableProjectSettings */
14
+ /**
15
+ * @namespace IconApi
16
+ * @typedef {import('./icon-api.js').BitmapOpts} IconApi.BitmapOpts
17
+ * @typedef {import('./icon-api.js').SvgOpts} IconApi.SvgOpts
18
+ */
19
+ /**
20
+ * @namespace BlobApi
21
+ * @typedef {import('./types.js').BlobId} BlobApi.BlobId
22
+ * @typedef {import('./blob-api.js').Metadata} BlobApi.Metadata
23
+ */
24
+ // This needs to be defined in a separate comment block so that the @template definition works.
25
+ /**
26
+ * @template {import('./types.js').BlobType} TBlobType
27
+ * @typedef {import('./types.js').BlobVariant<TBlobType>} BlobApi.BlobVariant
28
+ */
29
+ /**
30
+ * @namespace InviteApi
31
+ * @typedef {import('./invite/invite-api.js').Invite} InviteApi.Invite
32
+ */
33
+ /**
34
+ * @namespace MemberApi
35
+ * @typedef {import('./member-api.js').MemberInfo} MemberApi.MemberInfo
36
+ * @typedef {import('./roles.js').RoleId} MemberApi.RoleId
37
+ * @typedef {import('./roles.js').RoleIdForNewInvite} MemberApi.RoleIdForNewInvite
38
+ */
12
39
  /**
13
40
  * @param {MapeoProject} project
14
- * @param {Parameters<MapeoProject.prototype[kProjectReplicate]>} args
15
- * @returns {ReturnType<MapeoProject.prototype[kProjectReplicate]>}
41
+ * @param {(
42
+ * boolean |
43
+ * import('stream').Duplex |
44
+ * import('streamx').Duplex
45
+ * )} isInitiatorOrStream
46
+ * @returns {import('./types.js').ReplicationStream}
16
47
  */
17
- export const replicateProject = (project, ...args) =>
18
- project[kProjectReplicate](...args)
48
+ export const replicateProject = (project, isInitiatorOrStream) =>
49
+ project[kProjectReplicate](isInitiatorOrStream)
19
50
 
20
51
  export const roles = /** @type {const} */ ({
21
52
  CREATOR_ROLE_ID,
@@ -4,8 +4,8 @@ import { InviteResponse_Decision } from '../generated/rpc.js'
4
4
  import ensureError from 'ensure-error'
5
5
  import { TimeoutError } from '../errors.js'
6
6
 
7
- const RECEIVE_PROJECT_DETAILS_TIMEOUT_MS = 10_000
8
- const ADD_PROJECT_TIMEOUT_MS = 10_000
7
+ const RECEIVE_PROJECT_DETAILS_TIMEOUT_MS = 45_000
8
+ const ADD_PROJECT_TIMEOUT_MS = 45_000
9
9
 
10
10
  /** @import { StringToTaggedUnion } from '../types.js' */
11
11
  /** @import { ProjectJoinDetails } from '../generated/rpc.js' */
@@ -708,14 +708,14 @@ export class MapeoManager extends TypedEmitter {
708
708
  *
709
709
  * @param {MapeoProject} project
710
710
  * @param {object} [opts]
711
- * @param {number} [opts.timeoutMs=5000] Timeout in milliseconds for max time
711
+ * @param {number} [opts.timeoutMs=300_000] Timeout in milliseconds for max time
712
712
  * to wait between sync status updates before giving up. As long as syncing is
713
713
  * happening, this will never timeout, but if more than timeoutMs passes
714
714
  * without any sync activity, then this will resolve `false` e.g. data has not
715
715
  * synced
716
716
  * @returns {Promise<boolean>}
717
717
  */
718
- async #waitForInitialSync(project, { timeoutMs = 5000 } = {}) {
718
+ async #waitForInitialSync(project, { timeoutMs = 300_000 } = {}) {
719
719
  const [ownRole, isProjectSettingsSynced] = await Promise.all([
720
720
  project.$getOwnRole(),
721
721
  project.$hasSyncedProjectSettings(),
@@ -132,7 +132,9 @@ export class PeerSyncController {
132
132
  const localState = mapObject(state, (ns, nsState) => {
133
133
  return [ns, nsState.localState]
134
134
  })
135
- this.#log('state %X', state)
135
+ // TODO: Turn this on when log level is 'trace' or 'debug'
136
+ // This logs _a lot_ of data, which has a performance overhead
137
+ // this.#log('state %X', state)
136
138
 
137
139
  // Map of which namespaces have received new data since last sync change
138
140
  const didUpdate = mapObject(state, (ns) => {