Skip to content

Commit

Permalink
chore: move PRESYNC_NAMESPACES into central constants file
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
EvanHahn committed Aug 26, 2024
1 parent 96dce64 commit 11baacd
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 11 deletions.
5 changes: 5 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/** @import { Namespace } from './types.js' */

// WARNING: Changing these will break things for existing apps, since namespaces
// are used for key derivation
export const NAMESPACES = /** @type {const} */ ([
Expand All @@ -8,6 +10,9 @@ export const NAMESPACES = /** @type {const} */ ([
'blob',
])

/** @type {ReadonlyArray<Namespace>} */
export const PRESYNC_NAMESPACES = ['auth', 'config', 'blobIndex']

export const NAMESPACE_SCHEMAS = /** @type {const} */ ({
data: ['observation', 'track'],
config: [
Expand Down
5 changes: 1 addition & 4 deletions src/sync/peer-sync-controller.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import mapObject from 'map-obj'
import { NAMESPACES } from '../constants.js'
import { NAMESPACES, PRESYNC_NAMESPACES } from '../constants.js'
import { Logger } from '../logger.js'
import { ExhaustivenessError, createMap } from '../utils.js'
/** @import { Namespace } from '../types.js' */
Expand All @@ -8,9 +8,6 @@ import { ExhaustivenessError, createMap } from '../utils.js'
* @typedef {import('../roles.js').Role['sync'][Namespace] | 'unknown'} SyncCapability
*/

/** @type {Namespace[]} */
export const PRESYNC_NAMESPACES = ['auth', 'config', 'blobIndex']

/**
* @internal
* @typedef {import('./sync-api.js').SyncEnabledState} SyncEnabledState
Expand Down
7 changes: 2 additions & 5 deletions src/sync/sync-api.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { TypedEmitter } from 'tiny-typed-emitter'
import { SyncState } from './sync-state.js'
import {
PeerSyncController,
PRESYNC_NAMESPACES,
} from './peer-sync-controller.js'
import { PeerSyncController } from './peer-sync-controller.js'
import { Logger } from '../logger.js'
import { NAMESPACES } from '../constants.js'
import { NAMESPACES, PRESYNC_NAMESPACES } from '../constants.js'
import { ExhaustivenessError, assert, keyToId } from '../utils.js'

export const kHandleDiscoveryKey = Symbol('handle discovery key')
Expand Down
3 changes: 1 addition & 2 deletions test-e2e/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ import {
} from './utils.js'
import { kCoreManager } from '../src/mapeo-project.js'
import { getKeys } from '../tests/helpers/core-manager.js'
import { NAMESPACES } from '../src/constants.js'
import { NAMESPACES, PRESYNC_NAMESPACES } from '../src/constants.js'
import { FastifyController } from '../src/fastify-controller.js'
import { PRESYNC_NAMESPACES } from '../src/sync/peer-sync-controller.js'
import { generate } from '@mapeo/mock-data'
import { valueOf } from '../src/utils.js'
import pTimeout from 'p-timeout'
Expand Down

0 comments on commit 11baacd

Please sign in to comment.