diff --git a/package-lock.json b/package-lock.json index 4e7ba9968b..f84f11e353 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5279,6 +5279,10 @@ "resolved": "packages/create", "link": true }, + "node_modules/@waku/interfaces": { + "resolved": "packages/interfaces", + "link": true + }, "node_modules/@webassemblyjs/ast": { "version": "1.11.1", "resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.11.1.tgz", @@ -22391,6 +22395,7 @@ "@types/uuid": "^8.3.0", "@typescript-eslint/eslint-plugin": "^5.8.1", "@typescript-eslint/parser": "^5.8.1", + "@waku/create": "*", "app-root-path": "^3.0.0", "chai": "^4.3.4", "cspell": "^5.14.0", @@ -22488,6 +22493,7 @@ "@semantic-release/release-notes-generator": "^10.0.3", "@typescript-eslint/eslint-plugin": "^5.8.1", "@typescript-eslint/parser": "^5.8.1", + "@waku/interfaces": "*", "cspell": "^5.14.0", "eslint": "^8.6.0", "eslint-config-prettier": "^8.3.0", @@ -22506,6 +22512,37 @@ "engines": { "node": ">=16" } + }, + "packages/interfaces": { + "name": "@waku/interfaces", + "version": "0.0.1", + "license": "MIT OR Apache-2.0", + "devDependencies": { + "@semantic-release/changelog": "^6.0.1", + "@semantic-release/commit-analyzer": "^9.0.2", + "@semantic-release/git": "^10.0.1", + "@semantic-release/github": "^8.0.6", + "@semantic-release/npm": "^9.0.1", + "@semantic-release/release-notes-generator": "^10.0.3", + "@typescript-eslint/eslint-plugin": "^5.8.1", + "@typescript-eslint/parser": "^5.8.1", + "cspell": "^5.14.0", + "eslint": "^8.6.0", + "eslint-config-prettier": "^8.3.0", + "eslint-plugin-eslint-comments": "^3.2.0", + "eslint-plugin-functional": "^4.0.2", + "eslint-plugin-import": "^2.25.3", + "eslint-plugin-prettier": "^4.0.0", + "npm-run-all": "^4.1.5", + "prettier": "^2.1.1", + "semantic-release": "^19.0.5", + "semantic-release-monorepo": "^7.0.5", + "typedoc": "^0.23.10", + "typescript": "^4.6.3" + }, + "engines": { + "node": ">=16" + } } }, "dependencies": { @@ -26745,6 +26782,7 @@ "@types/uuid": "^8.3.0", "@typescript-eslint/eslint-plugin": "^5.8.1", "@typescript-eslint/parser": "^5.8.1", + "@waku/create": "*", "app-root-path": "^3.0.0", "chai": "^4.3.4", "cspell": "^5.14.0", @@ -26840,6 +26878,7 @@ "@typescript-eslint/eslint-plugin": "^5.8.1", "@typescript-eslint/parser": "^5.8.1", "@waku/core": "*", + "@waku/interfaces": "*", "cspell": "^5.14.0", "eslint": "^8.6.0", "eslint-config-prettier": "^8.3.0", @@ -26856,6 +26895,32 @@ "typescript": "^4.6.3" } }, + "@waku/interfaces": { + "version": "file:packages/interfaces", + "requires": { + "@semantic-release/changelog": "^6.0.1", + "@semantic-release/commit-analyzer": "^9.0.2", + "@semantic-release/git": "^10.0.1", + "@semantic-release/github": "^8.0.6", + "@semantic-release/npm": "^9.0.1", + "@semantic-release/release-notes-generator": "^10.0.3", + "@typescript-eslint/eslint-plugin": "^5.8.1", + "@typescript-eslint/parser": "^5.8.1", + "cspell": "^5.14.0", + "eslint": "^8.6.0", + "eslint-config-prettier": "^8.3.0", + "eslint-plugin-eslint-comments": "^3.2.0", + "eslint-plugin-functional": "^4.0.2", + "eslint-plugin-import": "^2.25.3", + "eslint-plugin-prettier": "^4.0.0", + "npm-run-all": "^4.1.5", + "prettier": "^2.1.1", + "semantic-release": "^19.0.5", + "semantic-release-monorepo": "^7.0.5", + "typedoc": "^0.23.10", + "typescript": "^4.6.3" + } + }, "@webassemblyjs/ast": { "version": "1.11.1", "resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.11.1.tgz", diff --git a/packages/core/package.json b/packages/core/package.json index c7b207f89a..35a156b0a2 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -135,6 +135,8 @@ "uuid": "^8.3.2" }, "devDependencies": { + "@waku/create": "*", + "@waku/interfaces": "*", "@libp2p/peer-id-factory": "^1.0.15", "@rollup/plugin-commonjs": "^22.0.0", "@rollup/plugin-json": "^4.1.0", diff --git a/packages/core/src/lib/enr/enr.node.spec.ts b/packages/core/src/lib/enr/enr.node.spec.ts index f8daa69747..3753582875 100644 --- a/packages/core/src/lib/enr/enr.node.spec.ts +++ b/packages/core/src/lib/enr/enr.node.spec.ts @@ -1,15 +1,15 @@ +import { createLightNode } from "@waku/create"; import { expect } from "chai"; import { makeLogFileName, NOISE_KEY_1, Nwaku } from "../../test_utils"; -import { createWaku } from "../create_waku"; -import type { Waku } from "../interfaces"; +import type { WakuLight } from "../interfaces"; import { waitForRemotePeer } from "../wait_for_remote_peer"; import { Protocols } from "../waku"; import { ENR } from "./enr"; describe("ENR Interop: nwaku", function () { - let waku: Waku; + let waku: WakuLight; let nwaku: Nwaku; afterEach(async function () { @@ -28,7 +28,7 @@ describe("ENR Interop: nwaku", function () { }); const multiAddrWithId = await nwaku.getMultiaddrWithId(); - waku = await createWaku({ + waku = await createLightNode({ staticNoiseKey: NOISE_KEY_1, }); await waku.start(); @@ -60,7 +60,7 @@ describe("ENR Interop: nwaku", function () { }); const multiAddrWithId = await nwaku.getMultiaddrWithId(); - waku = await createWaku({ + waku = await createLightNode({ staticNoiseKey: NOISE_KEY_1, }); await waku.start(); diff --git a/packages/core/src/lib/wait_for_remote_peer.node.spec.ts b/packages/core/src/lib/wait_for_remote_peer.node.spec.ts index 67793a890b..7c22b27d02 100644 --- a/packages/core/src/lib/wait_for_remote_peer.node.spec.ts +++ b/packages/core/src/lib/wait_for_remote_peer.node.spec.ts @@ -1,9 +1,9 @@ +import { createLightNode, createPrivacyNode } from "@waku/create"; import { expect } from "chai"; import { makeLogFileName, NOISE_KEY_1, Nwaku } from "../test_utils"; import { delay } from "../test_utils/delay"; -import { createLightNode, createPrivacyNode } from "./create_waku"; import type { WakuLight, WakuPrivacy } from "./interfaces"; import { waitForRemotePeer } from "./wait_for_remote_peer"; import { Protocols } from "./waku"; diff --git a/packages/core/src/lib/waku.node.spec.ts b/packages/core/src/lib/waku.node.spec.ts index 3418c80281..f1de32548d 100644 --- a/packages/core/src/lib/waku.node.spec.ts +++ b/packages/core/src/lib/waku.node.spec.ts @@ -1,4 +1,5 @@ import type { PeerId } from "@libp2p/interface-peer-id"; +import { createLightNode, createPrivacyNode } from "@waku/create"; import { expect } from "chai"; import { @@ -8,7 +9,6 @@ import { Nwaku, } from "../test_utils/"; -import { createLightNode, createPrivacyNode } from "./create_waku"; import { generateSymmetricKey } from "./crypto"; import type { Message, Waku, WakuLight, WakuPrivacy } from "./interfaces"; import { PeerDiscoveryStaticPeers } from "./peer_discovery_static_list"; diff --git a/packages/core/src/lib/waku.spec.ts b/packages/core/src/lib/waku.spec.ts index efde19c331..cd670ee90d 100644 --- a/packages/core/src/lib/waku.spec.ts +++ b/packages/core/src/lib/waku.spec.ts @@ -1,7 +1,7 @@ import type { PeerId } from "@libp2p/interface-peer-id"; +import { createWaku } from "@waku/create"; import { expect } from "chai"; -import { createWaku } from "./create_waku"; import type { Waku } from "./interfaces"; describe("Waku Dial", function () { diff --git a/packages/create/package.json b/packages/create/package.json index 28bab12f57..b094e5ea30 100644 --- a/packages/create/package.json +++ b/packages/create/package.json @@ -66,6 +66,7 @@ "@waku/core": "*" }, "devDependencies": { + "@waku/interfaces": "*", "@rollup/plugin-commonjs": "^22.0.0", "@rollup/plugin-json": "^4.1.0", "@rollup/plugin-node-resolve": "^13.3.0", diff --git a/packages/create/src/index.ts b/packages/create/src/index.ts index 49734a9b3d..76fb399a89 100644 --- a/packages/create/src/index.ts +++ b/packages/create/src/index.ts @@ -12,14 +12,9 @@ import { WakuRelay, WakuStore, } from "@waku/core"; -import type { - Waku, - WakuFull, - WakuLight, - WakuPrivacy, -} from "@waku/core/lib/interfaces"; import { PeerDiscoveryStaticPeers } from "@waku/core/lib/peer_discovery_static_list"; import { getPredefinedBootstrapNodes } from "@waku/core/lib/predefined_bootstrap_nodes"; +import type { WakuFull, WakuLight, WakuPrivacy } from "@waku/interfaces"; import type { Libp2p } from "libp2p"; import { createLibp2p, Libp2pOptions } from "libp2p"; @@ -150,35 +145,6 @@ export async function createFullNode( ) as WakuFull; } -/** - * @deprecated use { @link createLightNode }, { @link createPrivacyNode } or - * { @link index.waku.WakuNode.constructor } instead. - */ -export async function createWaku( - options?: CreateOptions & WakuOptions & Partial -): Promise { - const libp2pOptions = options?.libp2p ?? {}; - const peerDiscovery = libp2pOptions.peerDiscovery ?? []; - if (options?.defaultBootstrap) { - peerDiscovery.push(defaultPeerDiscovery()); - Object.assign(libp2pOptions, { peerDiscovery }); - } - - const libp2p = await defaultLibp2p(new WakuRelay(options), libp2pOptions); - - const wakuStore = new WakuStore(libp2p, options); - const wakuLightPush = new WakuLightPush(libp2p, options); - const wakuFilter = new WakuFilter(libp2p, options); - - return new WakuNode( - options ?? {}, - libp2p, - wakuStore, - wakuLightPush, - wakuFilter - ); -} - export function defaultPeerDiscovery(): PeerDiscovery { return new PeerDiscoveryStaticPeers(getPredefinedBootstrapNodes()); } diff --git a/packages/interfaces/.eslintrc.cjs b/packages/interfaces/.eslintrc.cjs new file mode 100644 index 0000000000..324f1f526d --- /dev/null +++ b/packages/interfaces/.eslintrc.cjs @@ -0,0 +1,6 @@ +module.exports = { + parserOptions: { + tsconfigRootDir: __dirname, + project: "./tsconfig.dev.json", + }, +}; diff --git a/packages/interfaces/.prettierignore b/packages/interfaces/.prettierignore new file mode 100644 index 0000000000..fecb37a393 --- /dev/null +++ b/packages/interfaces/.prettierignore @@ -0,0 +1,4 @@ +build +bundle +dist +node_modules diff --git a/packages/interfaces/package.json b/packages/interfaces/package.json new file mode 100644 index 0000000000..a77296e53b --- /dev/null +++ b/packages/interfaces/package.json @@ -0,0 +1,170 @@ +{ + "name": "@waku/interfaces", + "version": "0.0.1", + "description": "Definition of Waku interfaces", + "types": "./dist/index.d.ts", + "exports": { + ".": { + "types": "./dist/index.d.ts" + } + }, + "type": "module", + "author": "Waku Team", + "homepage": "https://github.com/waku-org/js-waku/tree/master/packages/interfaces#readme", + "repository": { + "type": "git", + "url": "https://github.com/waku-org/js-waku.git" + }, + "bugs": { + "url": "https://github.com/waku-org/js-waku/issues" + }, + "license": "MIT OR Apache-2.0", + "keywords": [ + "waku", + "decentralized", + "secure", + "communication", + "web3", + "ethereum", + "dapps", + "privacy" + ], + "scripts": { + "build": "exit 0", + "fix": "run-s fix:*", + "fix:prettier": "prettier . --write", + "fix:lint": "eslint src --ext .ts --ext .cjs --fix", + "check": "run-s check:*", + "check:lint": "eslint src --ext .ts", + "check:prettier": "prettier . --list-different", + "check:spelling": "cspell \"{README.md,src/**/*.ts}\"", + "check:tsc": "tsc -p tsconfig.dev.json", + "test": "exit 0 # Tested in @waku/core", + "proto": "exit 0 # no proto", + "doc": "run-s doc:*", + "doc:html": "typedoc --treatWarningsAsErrors", + "prepublish": "npm run build", + "reset-hard": "git clean -dfx -e .idea && git reset --hard && npm i && npm run build", + "release": "semantic-release" + }, + "engines": { + "node": ">=16" + }, + "devDependencies": { + "@semantic-release/changelog": "^6.0.1", + "@semantic-release/commit-analyzer": "^9.0.2", + "@semantic-release/git": "^10.0.1", + "@semantic-release/github": "^8.0.6", + "@semantic-release/npm": "^9.0.1", + "@semantic-release/release-notes-generator": "^10.0.3", + "@typescript-eslint/eslint-plugin": "^5.8.1", + "@typescript-eslint/parser": "^5.8.1", + "cspell": "^5.14.0", + "eslint": "^8.6.0", + "eslint-config-prettier": "^8.3.0", + "eslint-plugin-eslint-comments": "^3.2.0", + "eslint-plugin-functional": "^4.0.2", + "eslint-plugin-import": "^2.25.3", + "eslint-plugin-prettier": "^4.0.0", + "npm-run-all": "^4.1.5", + "prettier": "^2.1.1", + "semantic-release": "^19.0.5", + "semantic-release-monorepo": "^7.0.5", + "typedoc": "^0.23.10", + "typescript": "^4.6.3" + }, + "release": { + "branches": [ + "master" + ], + "extends": "semantic-release-monorepo", + "plugins": [ + [ + "@semantic-release/commit-analyzer", + { + "preset": "conventionalcommits", + "releaseRules": [ + { + "breaking": true, + "release": "major" + }, + { + "revert": true, + "release": "patch" + }, + { + "type": "feat", + "release": "minor" + }, + { + "type": "fix", + "release": "patch" + }, + { + "type": "doc", + "release": "patch" + }, + { + "type": "test", + "release": "patch" + }, + { + "scope": "deps", + "release": "patch" + }, + { + "scope": "no-release", + "release": false + } + ] + } + ], + [ + "@semantic-release/release-notes-generator", + { + "preset": "conventionalcommits", + "presetConfig": { + "types": [ + { + "type": "feat", + "section": "Features" + }, + { + "type": "fix", + "section": "Bug Fixes" + }, + { + "type": "chore", + "section": "Trivial Changes" + }, + { + "type": "doc", + "section": "Documentation" + }, + { + "type": "test", + "section": "Tests" + } + ] + } + } + ], + "@semantic-release/changelog", + "@semantic-release/npm", + "@semantic-release/github", + "@semantic-release/git" + ] + }, + "files": [ + "dist", + "bundle", + "src/*.ts", + "src/lib/**/*.ts", + "src/proto/**/*.ts", + "!**/*.spec.*", + "!**/*.json", + "CHANGELOG.md", + "LICENSE", + "README.md" + ] +} diff --git a/packages/core/src/lib/interfaces.ts b/packages/interfaces/src/index.d.ts similarity index 100% rename from packages/core/src/lib/interfaces.ts rename to packages/interfaces/src/index.d.ts diff --git a/packages/interfaces/tsconfig.dev.json b/packages/interfaces/tsconfig.dev.json new file mode 100644 index 0000000000..ffc27ef6ba --- /dev/null +++ b/packages/interfaces/tsconfig.dev.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig", + "compilerOptions": { + "module": "esnext", + "noEmit": true + }, + "exclude": [] +} diff --git a/packages/interfaces/tsconfig.json b/packages/interfaces/tsconfig.json new file mode 100644 index 0000000000..7b01b30897 --- /dev/null +++ b/packages/interfaces/tsconfig.json @@ -0,0 +1,54 @@ +{ + "compilerOptions": { + "incremental": true, + "target": "es2020", + "outDir": "dist/", + "rootDir": "src", + "moduleResolution": "node", + "module": "es2020", + "declaration": true, + "sourceMap": true, + "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */, + "resolveJsonModule": true /* Include modules imported with .json extension. */, + "tsBuildInfoFile": "dist/.tsbuildinfo", + "strict": true /* Enable all strict type-checking options. */, + + /* Strict Type-Checking Options */ + "noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */, + "strictNullChecks": true /* Enable strict null checks. */, + "strictFunctionTypes": true /* Enable strict checking of function types. */, + "strictPropertyInitialization": true /* Enable strict checking of property initialization in classes. */, + "noImplicitThis": true /* Raise error on 'this' expressions with an implied 'any' type. */, + "alwaysStrict": true /* Parse in strict mode and emit "use strict" for each source file. */, + + /* Additional Checks */ + "noUnusedLocals": true /* Report errors on unused locals. */, + "noUnusedParameters": true /* Report errors on unused parameters. */, + "noImplicitReturns": true /* Report error when not all code paths in function return a value. */, + "noFallthroughCasesInSwitch": true /* Report errors for fallthrough cases in switch statement. */, + "forceConsistentCasingInFileNames": true, + + /* Debugging Options */ + "traceResolution": false /* Report module resolution log messages. */, + "listEmittedFiles": false /* Print names of generated files part of the compilation. */, + "listFiles": false /* Print names of files part of the compilation. */, + "pretty": true /* Stylize errors and messages using color and context. */, + + // Due to broken types in indirect dependencies + "skipLibCheck": true, + + /* Experimental Options */ + // "experimentalDecorators": true /* Enables experimental support for ES7 decorators. */, + // "emitDecoratorMetadata": true /* Enables experimental support for emitting type metadata for decorators. */, + + "lib": ["es2020", "dom"], + "types": ["node", "mocha"], + "typeRoots": ["node_modules/@types", "src/types"] + }, + "include": ["src"], + "exclude": ["src/**/*.spec.ts", "src/test_utils"], + "compileOnSave": false, + "ts-node": { + "files": true + } +} diff --git a/packages/interfaces/typedoc.json b/packages/interfaces/typedoc.json new file mode 100644 index 0000000000..1b4aa6af86 --- /dev/null +++ b/packages/interfaces/typedoc.json @@ -0,0 +1,10 @@ +{ + "entryPoints": ["./src/index.ts"], + "out": "build/docs", + "exclude": ["**/*.spec.ts"], + "excludeInternal": true, + "validation": { + "invalidLink": true, + "notExported": true + } +}