Skip to content

Commit 4b02546

Browse files
authored
chore: move PRESYNC_NAMESPACES into central constants file (#767)
This change should have no impact. The `PRESYNC_NAMESPACES` array is pretty central, but was stuffed away in `sync/peer-sync-controller.js`; that doesn't quite feel like where it belongs. Now it's in a more central spot: `constants.js`. I think this is useful on its own, but it should make a future change easier.
1 parent e8e1d7a commit 4b02546

File tree

4 files changed

+9
-11
lines changed

4 files changed

+9
-11
lines changed

src/constants.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/** @import { Namespace } from './types.js' */
2+
13
// WARNING: Changing these will break things for existing apps, since namespaces
24
// are used for key derivation
35
export const NAMESPACES = /** @type {const} */ ([
@@ -8,6 +10,9 @@ export const NAMESPACES = /** @type {const} */ ([
810
'blob',
911
])
1012

13+
/** @type {ReadonlyArray<Namespace>} */
14+
export const PRESYNC_NAMESPACES = ['auth', 'config', 'blobIndex']
15+
1116
export const NAMESPACE_SCHEMAS = /** @type {const} */ ({
1217
data: ['observation', 'track'],
1318
config: [

src/sync/peer-sync-controller.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import mapObject from 'map-obj'
2-
import { NAMESPACES } from '../constants.js'
2+
import { NAMESPACES, PRESYNC_NAMESPACES } from '../constants.js'
33
import { Logger } from '../logger.js'
44
import { ExhaustivenessError, createMap } from '../utils.js'
55
/** @import { CoreRecord } from '../core-manager/index.js' */
@@ -11,9 +11,6 @@ import { ExhaustivenessError, createMap } from '../utils.js'
1111
* @typedef {Role['sync'][Namespace] | 'unknown'} SyncCapability
1212
*/
1313

14-
/** @type {Namespace[]} */
15-
export const PRESYNC_NAMESPACES = ['auth', 'config', 'blobIndex']
16-
1714
export class PeerSyncController {
1815
#replicatingCores = new Set()
1916
/** @type {Set<Namespace>} */

src/sync/sync-api.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import { TypedEmitter } from 'tiny-typed-emitter'
22
import { SyncState } from './sync-state.js'
3-
import {
4-
PeerSyncController,
5-
PRESYNC_NAMESPACES,
6-
} from './peer-sync-controller.js'
3+
import { PeerSyncController } from './peer-sync-controller.js'
74
import { Logger } from '../logger.js'
8-
import { NAMESPACES } from '../constants.js'
5+
import { NAMESPACES, PRESYNC_NAMESPACES } from '../constants.js'
96
import { ExhaustivenessError, assert, keyToId } from '../utils.js'
107

118
export const kHandleDiscoveryKey = Symbol('handle discovery key')

test-e2e/sync.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ import {
1919
} from './utils.js'
2020
import { kCoreManager } from '../src/mapeo-project.js'
2121
import { getKeys } from '../tests/helpers/core-manager.js'
22-
import { NAMESPACES } from '../src/constants.js'
22+
import { NAMESPACES, PRESYNC_NAMESPACES } from '../src/constants.js'
2323
import { FastifyController } from '../src/fastify-controller.js'
24-
import { PRESYNC_NAMESPACES } from '../src/sync/peer-sync-controller.js'
2524
import { generate } from '@mapeo/mock-data'
2625
import { valueOf } from '../src/utils.js'
2726
import pTimeout from 'p-timeout'

0 commit comments

Comments
 (0)