Skip to content

chore: move ts/ to src/ #250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ts/message/rpc*
src/message/rpc*
3 changes: 1 addition & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
src/
.nyc_output
dist/

# Don't format the auto-generated protobuf files
ts/message/rpc.ts
src/message/rpc.ts
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,20 @@
"description": "A typescript implementation of gossipsub",
"leadMaintainer": "Cayman Nava <[email protected]>",
"files": [
"src",
"dist"
],
"type": "module",
"types": "dist/ts/index.d.ts",
"types": "dist/src/index.d.ts",
"exports": {
".": {
"import": "./dist/ts/index.js"
"import": "./dist/src/index.js"
}
},
"scripts": {
"lint": "eslint --ext .ts ts",
"lint": "eslint --ext .ts src",
"release": "aegir release --no-types",
"build": "tsc -p tsconfig.build.json",
"generate": "protons ./ts/message/rpc.proto",
"generate": "protons ./src/message/rpc.proto",
"prepare": "npm run build",
"pretest": "npm run build",
"benchmark": "node ./node_modules/.bin/benchmark 'test/benchmark/time-cache.test.js' --local",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions test/2-nodes.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { expect } from 'aegir/utils/chai.js'
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
import type { GossipSub } from '../ts/index.js'
import type { GossipSub } from '../src/index.js'
import type { Message, SubscriptionChangeData } from '@libp2p/interfaces/pubsub'
import { FloodsubID, GossipsubIDv11 } from '../ts/constants.js'
import { FloodsubID, GossipsubIDv11 } from '../src/constants.js'
import { pEvent } from 'p-event'
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
import defer from 'p-defer'
Expand Down
2 changes: 1 addition & 1 deletion test/accept-from.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Components } from '@libp2p/interfaces/components'
import { expect } from 'aegir/utils/chai.js'
import sinon from 'sinon'
import { GossipSub } from '../ts/index.js'
import { GossipSub } from '../src/index.js'
import { createPeerId } from './utils/index.js'
import { fastMsgIdFn } from './utils/msgId.js'

Expand Down
2 changes: 1 addition & 1 deletion test/benchmark/time-cache.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { itBench, setBenchOpts } from '@dapplion/benchmark'
// @ts-expect-error no types
import TimeCache from 'time-cache'
import { SimpleTimeCache } from '../../ts/utils/time-cache.js'
import { SimpleTimeCache } from '../../src/utils/time-cache.js'

// TODO: errors with "Error: root suite not found"
describe('npm TimeCache vs SimpleTimeCache', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/compliance.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import tests from '@libp2p/interface-compliance-tests/pubsub'
import { GossipSub } from '../ts/index.js'
import { GossipSub } from '../src/index.js'

describe('interface compliance', function () {
this.timeout(3000)
Expand Down
2 changes: 1 addition & 1 deletion test/floodsub.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import pRetry from 'p-retry'
import { connectPubsubNodes, createComponents } from './utils/create-pubsub.js'
import { Components } from '@libp2p/interfaces/components'
import { FloodSub } from '@libp2p/floodsub'
import { FloodsubID, GossipsubIDv11 } from '../ts/constants.js'
import { FloodsubID, GossipsubIDv11 } from '../src/constants.js'
import { stop } from '@libp2p/interfaces/startable'
import { mockNetwork } from '@libp2p/interface-compliance-tests/mocks'

Expand Down
10 changes: 5 additions & 5 deletions test/go-gossipsub.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import pRetry from 'p-retry'
import type { EventEmitter } from '@libp2p/interfaces/events'
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
import type { GossipSub, GossipsubEvents } from '../ts/index.js'
import { MessageAcceptance } from '../ts/types.js'
import { GossipsubD } from '../ts/constants.js'
import type { GossipSub, GossipsubEvents } from '../src/index.js'
import { MessageAcceptance } from '../src/types.js'
import { GossipsubD } from '../src/constants.js'
import { fastMsgIdFn } from './utils/index.js'
import type { Message, SubscriptionChangeData } from '@libp2p/interfaces/pubsub'
import type { RPC } from '../ts/message/rpc.js'
import type { RPC } from '../src/message/rpc.js'
import type { ConnectionManagerEvents } from '@libp2p/interfaces/connection-manager'
import pWaitFor from 'p-wait-for'
import { Components } from '@libp2p/interfaces/components'
Expand All @@ -24,7 +24,7 @@ import {
import { FloodSub } from '@libp2p/floodsub'
import { mockNetwork } from '@libp2p/interface-compliance-tests/mocks'
import { stop } from '@libp2p/interfaces/startable'
import { TopicScoreParams } from '../ts/score/peer-score-params.js'
import { TopicScoreParams } from '../src/score/peer-score-params.js'

/**
* These tests were translated from:
Expand Down
4 changes: 2 additions & 2 deletions test/gossip.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { expect } from 'aegir/utils/chai.js'
import sinon, { SinonStubbedInstance } from 'sinon'
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
import { GossipsubDhi } from '../ts/constants.js'
import type { GossipSub } from '../ts/index.js'
import { GossipsubDhi } from '../src/constants.js'
import type { GossipSub } from '../src/index.js'
import { pEvent } from 'p-event'
import { connectAllPubSubNodes, createComponentsArray } from './utils/create-pubsub.js'
import { Components } from '@libp2p/interfaces/components'
Expand Down
2 changes: 1 addition & 1 deletion test/heartbeat.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from 'aegir/utils/chai.js'
import { GossipsubHeartbeatInterval } from '../ts/constants.js'
import { GossipsubHeartbeatInterval } from '../src/constants.js'
import { pEvent } from 'p-event'
import { Components } from '@libp2p/interfaces/components'
import { createComponents } from './utils/create-pubsub.js'
Expand Down
4 changes: 2 additions & 2 deletions test/mesh.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from 'aegir/utils/chai.js'
import delay from 'delay'
import { GossipsubDhi } from '../ts/constants.js'
import type { GossipSub } from '../ts/index.js'
import { GossipsubDhi } from '../src/constants.js'
import type { GossipSub } from '../src/index.js'
import { Components } from '@libp2p/interfaces/components'
import { connectAllPubSubNodes, createComponentsArray } from './utils/create-pubsub.js'
import { stop } from '@libp2p/interfaces/startable'
Expand Down
6 changes: 3 additions & 3 deletions test/message-cache.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { expect } from 'aegir/utils/chai.js'
import { messageIdToString } from '../ts/utils/messageIdToString.js'
import { messageIdToString } from '../src/utils/messageIdToString.js'
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
import { MessageCache } from '../ts/message-cache.js'
import { MessageCache } from '../src/message-cache.js'
import * as utils from '@libp2p/pubsub/utils'
import { getMsgId } from './utils/index.js'
import type { RPC } from '../ts/message/rpc.js'
import type { RPC } from '../src/message/rpc.js'

describe('Testing Message Cache Operations', () => {
const messageCache = new MessageCache(3, 5)
Expand Down
4 changes: 2 additions & 2 deletions test/peer-score-params.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
validateTopicScoreParams,
createPeerScoreParams,
validatePeerScoreParams
} from '../ts/score/index.js'
import * as constants from '../ts/constants.js'
} from '../src/score/index.js'
import * as constants from '../src/constants.js'

describe('TopicScoreParams validation', () => {
it('should not throw on default TopicScoreParams', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/peer-score-thresholds.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from 'aegir/utils/chai.js'
import { createPeerScoreThresholds, validatePeerScoreThresholds } from '../ts/score/index.js'
import { createPeerScoreThresholds, validatePeerScoreThresholds } from '../src/score/index.js'

describe('PeerScoreThresholds validation', () => {
it('should throw on invalid PeerScoreThresholds', () => {
Expand Down
10 changes: 5 additions & 5 deletions test/peer-score.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import sinon from 'sinon'
import { expect } from 'aegir/utils/chai.js'
import delay from 'delay'
import type { ConnectionManager } from '@libp2p/interfaces/connection-manager'
import { PeerScore, createPeerScoreParams, createTopicScoreParams } from '../ts/score/index.js'
import { PeerScore, createPeerScoreParams, createTopicScoreParams } from '../src/score/index.js'
import { getMsgIdStr, makeTestMessage } from './utils/index.js'
import { RejectReason } from '../ts/types.js'
import { ScorePenalty } from '../ts/metrics.js'
import { RejectReason } from '../src/types.js'
import { ScorePenalty } from '../src/metrics.js'
import { stubInterface } from 'ts-sinon'
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
import { Components } from '@libp2p/interfaces/components'
import { PeerStats } from '../ts/score/peer-stats.js'
import type { PeerScoreParams, TopicScoreParams } from '../ts/score/peer-score-params.js'
import { PeerStats } from '../src/score/peer-stats.js'
import type { PeerScoreParams, TopicScoreParams } from '../src/score/peer-score-params.js'

const connectionManager = stubInterface<ConnectionManager>()
connectionManager.getConnections.returns([])
Expand Down
6 changes: 3 additions & 3 deletions test/scoreMetrics.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ConnectionManager } from '@libp2p/interfaces/connection-manager'
import { computeAllPeersScoreWeights } from '../ts/score/scoreMetrics.js'
import { createPeerScoreParams, createTopicScoreParams, PeerScore } from '../ts/score/index.js'
import { ScorePenalty } from '../ts/metrics.js'
import { computeAllPeersScoreWeights } from '../src/score/scoreMetrics.js'
import { createPeerScoreParams, createTopicScoreParams, PeerScore } from '../src/score/index.js'
import { ScorePenalty } from '../src/metrics.js'
import { expect } from 'aegir/utils/chai.js'
import { stubInterface } from 'ts-sinon'
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
Expand Down
2 changes: 1 addition & 1 deletion test/time-cache.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from 'aegir/utils/chai.js'
import { SimpleTimeCache } from '../ts/utils/time-cache.js'
import { SimpleTimeCache } from '../src/utils/time-cache.js'
import sinon from 'sinon'

describe('SimpleTimeCache', () => {
Expand Down
4 changes: 2 additions & 2 deletions test/tracer.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from 'aegir/utils/chai.js'
import delay from 'delay'
import { IWantTracer } from '../ts/tracer.js'
import * as constants from '../ts/constants.js'
import { IWantTracer } from '../src/tracer.js'
import * as constants from '../src/constants.js'
import { makeTestMessage, getMsgId, getMsgIdStr } from './utils/index.js'
import { createEd25519PeerId } from '@libp2p/peer-id-factory'

Expand Down
2 changes: 1 addition & 1 deletion test/utils/create-pubsub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
mockNetwork
} from '@libp2p/interface-compliance-tests/mocks'
import { MemoryDatastore } from 'datastore-core'
import { GossipSub, GossipsubOpts } from '../../ts/index.js'
import { GossipSub, GossipsubOpts } from '../../src/index.js'
import { PubSub } from '@libp2p/interfaces/pubsub'
import { setMaxListeners } from 'events'
import { PersistentPeerStore } from '@libp2p/peer-store'
Expand Down
4 changes: 2 additions & 2 deletions test/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { TopicStr } from '../../ts/types.js'
import type { TopicStr } from '../../src/types.js'
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
import type { PeerId } from '@libp2p/interfaces/peer-id'
import type { RPC } from '../../ts/message/rpc.js'
import type { RPC } from '../../src/message/rpc.js'
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'

export * from './msgId.js'
Expand Down
4 changes: 2 additions & 2 deletions test/utils/msgId.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import SHA256 from '@chainsafe/as-sha256'
import type { RPC } from '../../ts/message/rpc.js'
import type { RPC } from '../../src/message/rpc.js'
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
import { messageIdToString } from '../../ts/utils/messageIdToString.js'
import { messageIdToString } from '../../src/utils/messageIdToString.js'

export const getMsgId = (msg: RPC.Message) => {
const from = (msg.from != null) ? msg.from : new Uint8Array(0)
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"include": ["./ts", "./test"],
"include": ["./src", "./test"],
"compilerOptions": {
"outDir": "./dist",
"lib": ["es2020", "dom"],
Expand Down