Skip to content

Commit

Permalink
rename and re-organize
Browse files Browse the repository at this point in the history
  • Loading branch information
gmaclennan committed Oct 26, 2023
1 parent 50698e6 commit ae35e9c
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/invite-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class InviteApi extends TypedEmitter {

/**
* @param {Object} options
* @param {import('./rpc/index.js').LocalPeers} options.rpc
* @param {import('./local-peers.js').LocalPeers} options.rpc
* @param {object} options.queries
* @param {(projectId: string) => Promise<boolean>} options.queries.isMember
* @param {(invite: import('./generated/rpc.js').Invite) => Promise<void>} options.queries.addProject
Expand Down
12 changes: 6 additions & 6 deletions src/rpc/index.js → src/local-peers.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
// @ts-check
import { TypedEmitter } from 'tiny-typed-emitter'
import Protomux from 'protomux'
import { openedNoiseSecretStream, keyToId } from '../utils.js'
import { openedNoiseSecretStream, keyToId } from './utils.js'
import cenc from 'compact-encoding'
import {
DeviceInfo,
Invite,
InviteResponse,
InviteResponse_Decision,
} from '../generated/rpc.js'
} from './generated/rpc.js'
import pDefer from 'p-defer'

const PROTOCOL_NAME = 'mapeo/rpc'

// Protomux message types depend on the order that messages are added to a
// channel (this needs to remain consistent). To avoid breaking changes, the
// types here should not change.
/** @satisfies {{ [k in keyof typeof import('../generated/rpc.js')]?: number }} */
/** @satisfies {{ [k in keyof typeof import('./generated/rpc.js')]?: number }} */
const MESSAGE_TYPES = {
Invite: 0,
InviteResponse: 1,
Expand All @@ -36,7 +36,7 @@ const MESSAGES_MAX_ID = Math.max.apply(null, [...Object.values(MESSAGE_TYPES)])
/** @typedef {PeerInfoConnecting | PeerInfoConnected | PeerInfoDisconnected} PeerInfoInternal */
/** @typedef {PeerInfoConnected | PeerInfoDisconnected} PeerInfo */
/** @typedef {PeerInfoInternal['status']} PeerState */
/** @typedef {import('type-fest').SetNonNullable<import('../generated/rpc.js').Invite, 'encryptionKeys'>} InviteWithKeys */
/** @typedef {import('type-fest').SetNonNullable<import('./generated/rpc.js').Invite, 'encryptionKeys'>} InviteWithKeys */

/**
* @template ValueType
Expand Down Expand Up @@ -260,8 +260,8 @@ export class LocalPeers extends TypedEmitter {
/**
* Connect to a peer over an existing NoiseSecretStream
*
* @param {import('../types.js').NoiseStream<any>} stream a NoiseSecretStream from @hyperswarm/secret-stream
* @returns {import('../types.js').ReplicationStream}
* @param {import('./types.js').NoiseStream<any>} stream a NoiseSecretStream from @hyperswarm/secret-stream
* @returns {import('./types.js').ReplicationStream}
*/
connect(stream) {
if (!stream.noiseStream) throw new Error('Invalid stream')
Expand Down
2 changes: 1 addition & 1 deletion src/mapeo-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
projectKeyToPublicId,
} from './utils.js'
import { RandomAccessFilePool } from './core-manager/random-access-file-pool.js'
import { LocalPeers } from './rpc/index.js'
import { LocalPeers } from './local-peers.js'
import { InviteApi } from './invite-api.js'
import { LocalDiscovery } from './discovery/local-discovery.js'

Expand Down
2 changes: 1 addition & 1 deletion src/mapeo-project.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class MapeoProject {
* @param {import('drizzle-orm/better-sqlite3').BetterSQLite3Database} opts.sharedDb
* @param {IndexWriter} opts.sharedIndexWriter
* @param {import('./types.js').CoreStorage} opts.coreStorage Folder to store all hypercore data
* @param {import('./rpc/index.js').LocalPeers} opts.rpc
* @param {import('./local-peers.js').LocalPeers} opts.rpc
*
*/
constructor({
Expand Down
2 changes: 1 addition & 1 deletion src/member-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class MemberApi extends TypedEmitter {
* @param {import('./core-ownership.js').CoreOwnership} opts.coreOwnership
* @param {import('./generated/keys.js').EncryptionKeys} opts.encryptionKeys
* @param {Buffer} opts.projectKey
* @param {import('./rpc/index.js').LocalPeers} opts.rpc
* @param {import('./local-peers.js').LocalPeers} opts.rpc
* @param {Object} opts.dataTypes
* @param {Pick<DeviceInfoDataType, 'getByDocId' | 'getMany'>} opts.dataTypes.deviceInfo
* @param {Pick<ProjectDataType, 'getByDocId'>} opts.dataTypes.project
Expand Down
2 changes: 1 addition & 1 deletion test-e2e/manager-invite.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import RAM from 'random-access-memory'
import { MEMBER_ROLE_ID } from '../src/capabilities.js'
import { InviteResponse_Decision } from '../src/generated/rpc.js'
import { MapeoManager, kRPC } from '../src/mapeo-manager.js'
import { replicate } from '../tests/helpers/rpc.js'
import { replicate } from '../tests/helpers/local-peers.js'

test('member invite accepted', async (t) => {
t.plan(10)
Expand Down
2 changes: 1 addition & 1 deletion test-e2e/members.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
MEMBER_ROLE_ID,
NO_ROLE_CAPABILITIES,
} from '../src/capabilities.js'
import { replicate } from '../tests/helpers/rpc.js'
import { replicate } from '../tests/helpers/local-peers.js'

test('getting yourself after creating project', async (t) => {
const { manager } = setup()
Expand Down
2 changes: 1 addition & 1 deletion test-types/data-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { drizzle } from 'drizzle-orm/better-sqlite3'
import RAM from 'random-access-memory'
import { IndexWriter } from '../dist/index-writer/index.js'
import { projectSettingsTable } from '../dist/schema/client.js'
import { LocalPeers } from '../dist/rpc/index.js'
import { LocalPeers } from '../dist/local-peers.js'
import { Expect, type Equal } from './utils.js'

type Forks = { forks: string[] }
Expand Down
4 changes: 2 additions & 2 deletions tests/helpers/rpc.js → tests/helpers/local-peers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import NoiseSecretStream from '@hyperswarm/secret-stream'
*/

/**
* @param {import('../../src/rpc/index.js').LocalPeers} rpc1
* @param {import('../../src/rpc/index.js').LocalPeers} rpc2
* @param {import('../../src/local-peers.js').LocalPeers} rpc1
* @param {import('../../src/local-peers.js').LocalPeers} rpc2
* @param { {kp1?: KeyPair, kp2?: KeyPair} } [keyPairs]
*/
export function replicate(
Expand Down
4 changes: 2 additions & 2 deletions tests/invite-api.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import test from 'brittle'
import { randomBytes } from 'crypto'
import { KeyManager } from '@mapeo/crypto'
import { LocalPeers } from '../src/rpc/index.js'
import { LocalPeers } from '../src/local-peers.js'
import { InviteApi } from '../src/invite-api.js'
import { projectKeyToPublicId } from '../src/utils.js'
import { replicate } from './helpers/rpc.js'
import { replicate } from './helpers/local-peers.js'
import NoiseSecretStream from '@hyperswarm/secret-stream'
import pDefer from 'p-defer'

Expand Down
4 changes: 2 additions & 2 deletions tests/rpc.js → tests/local-peers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import {
PeerDisconnectedError,
TimeoutError,
UnknownPeerError,
} from '../src/rpc/index.js'
} from '../src/local-peers.js'
import FakeTimers from '@sinonjs/fake-timers'
import { once } from 'events'
import { Duplex } from 'streamx'
import { replicate } from './helpers/rpc.js'
import { replicate } from './helpers/local-peers.js'
import { randomBytes } from 'node:crypto'
import NoiseSecretStream from '@hyperswarm/secret-stream'
import Protomux from 'protomux'
Expand Down

0 comments on commit ae35e9c

Please sign in to comment.