diff --git a/package-lock.json b/package-lock.json index a7d53e23c9..7f77118832 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,11 +6,12 @@ "": { "name": "@waku/root", "workspaces": [ + "packages/proto", "packages/byte-utils", + "packages/enr", "packages/interfaces", "packages/libp2p-utils", "packages/core", - "packages/enr", "packages/dns-discovery", "packages/message-encryption", "packages/create", @@ -3219,6 +3220,10 @@ "resolved": "packages/message-encryption", "link": true }, + "node_modules/@waku/proto": { + "resolved": "packages/proto", + "link": true + }, "node_modules/@waku/tests": { "resolved": "packages/tests", "link": true @@ -5347,9 +5352,9 @@ } }, "node_modules/engine.io": { - "version": "6.2.0", - "resolved": "https://registry.npmjs.org/engine.io/-/engine.io-6.2.0.tgz", - "integrity": "sha512-4KzwW3F3bk+KlzSOY57fj/Jx6LyRQ1nbcyIadehl+AnXjKT7gDO0ORdRi/84ixvMKTym6ZKuxvbzN62HDDU1Lg==", + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/engine.io/-/engine.io-6.2.1.tgz", + "integrity": "sha512-ECceEFcAaNRybd3lsGQKas3ZlMVjN3cyWwMP25D2i0zWfyiytVbTpRPa34qrr+FHddtpBVOmq4H/DCv1O0lZRA==", "dev": true, "dependencies": { "@types/cookie": "^0.4.1", @@ -17232,7 +17237,6 @@ "it-pipe": "^2.0.4", "libp2p": "0.40.0", "p-event": "^5.0.1", - "protons-runtime": "^3.1.0", "uint8arraylist": "^2.3.2", "uint8arrays": "^4.0.2", "uuid": "^9.0.0" @@ -17275,7 +17279,6 @@ "portfinder": "^1.0.28", "prettier": "^2.1.1", "process": "^0.11.10", - "protons": "^5.1.0", "puppeteer": "^13.0.1", "rollup": "^2.75.0", "tail": "^2.2.0", @@ -17466,6 +17469,14 @@ "name": "@waku/libp2p-utils", "version": "0.0.2", "license": "MIT OR Apache-2.0", + "dependencies": { + "@libp2p/interface-connection": "^3.0.3", + "@libp2p/interface-peer-id": "^1.0.6", + "@libp2p/interface-peer-info": "^1.0.1", + "@libp2p/interface-peer-store": "^1.2.3", + "@libp2p/peer-id": "^1.1.10", + "@multiformats/multiaddr": "^11.0.6" + }, "devDependencies": { "@rollup/plugin-commonjs": "^22.0.0", "@rollup/plugin-json": "^4.1.0", @@ -17524,6 +17535,36 @@ "node": ">=16" } }, + "packages/proto": { + "name": "@waku/proto", + "version": "0.0.1", + "license": "MIT OR Apache-2.0", + "dependencies": { + "protons-runtime": "^3.1.0" + }, + "devDependencies": { + "@rollup/plugin-commonjs": "^22.0.0", + "@rollup/plugin-json": "^4.1.0", + "@rollup/plugin-node-resolve": "^13.3.0", + "@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", + "protons": "^5.1.0", + "rollup": "^2.75.0", + "typescript": "^4.6.3" + }, + "engines": { + "node": ">=16" + } + }, "packages/tests": { "name": "@waku/tests", "version": "0.0.1", @@ -20162,8 +20203,6 @@ "portfinder": "^1.0.28", "prettier": "^2.1.1", "process": "^0.11.10", - "protons": "^5.1.0", - "protons-runtime": "^3.1.0", "puppeteer": "^13.0.1", "rollup": "^2.75.0", "tail": "^2.2.0", @@ -20316,6 +20355,12 @@ "@waku/libp2p-utils": { "version": "file:packages/libp2p-utils", "requires": { + "@libp2p/interface-connection": "^3.0.3", + "@libp2p/interface-peer-id": "^1.0.6", + "@libp2p/interface-peer-info": "^1.0.1", + "@libp2p/interface-peer-store": "^1.2.3", + "@libp2p/peer-id": "^1.1.10", + "@multiformats/multiaddr": "^11.0.6", "@rollup/plugin-commonjs": "^22.0.0", "@rollup/plugin-json": "^4.1.0", "@rollup/plugin-node-resolve": "^13.3.0", @@ -20363,6 +20408,29 @@ "typescript": "^4.6.3" } }, + "@waku/proto": { + "version": "file:packages/proto", + "requires": { + "@rollup/plugin-commonjs": "^22.0.0", + "@rollup/plugin-json": "^4.1.0", + "@rollup/plugin-node-resolve": "^13.3.0", + "@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", + "protons": "^5.1.0", + "protons-runtime": "^3.1.0", + "rollup": "^2.75.0", + "typescript": "^4.6.3" + } + }, "@waku/tests": { "version": "file:packages/tests", "requires": { @@ -22054,9 +22122,9 @@ } }, "engine.io": { - "version": "6.2.0", - "resolved": "https://registry.npmjs.org/engine.io/-/engine.io-6.2.0.tgz", - "integrity": "sha512-4KzwW3F3bk+KlzSOY57fj/Jx6LyRQ1nbcyIadehl+AnXjKT7gDO0ORdRi/84ixvMKTym6ZKuxvbzN62HDDU1Lg==", + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/engine.io/-/engine.io-6.2.1.tgz", + "integrity": "sha512-ECceEFcAaNRybd3lsGQKas3ZlMVjN3cyWwMP25D2i0zWfyiytVbTpRPa34qrr+FHddtpBVOmq4H/DCv1O0lZRA==", "dev": true, "requires": { "@types/cookie": "^0.4.1", diff --git a/package.json b/package.json index 8d7139e4e4..342afb04c0 100644 --- a/package.json +++ b/package.json @@ -3,11 +3,12 @@ "private": true, "type": "module", "workspaces": [ + "packages/proto", "packages/byte-utils", + "packages/enr", "packages/interfaces", "packages/libp2p-utils", "packages/core", - "packages/enr", "packages/dns-discovery", "packages/message-encryption", "packages/create", diff --git a/packages/core/package.json b/packages/core/package.json index 5c83f5f243..e8322db6ec 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -67,7 +67,6 @@ "test": "run-s test:*", "test:node": "TS_NODE_PROJECT=./tsconfig.dev.json mocha", "test:browser": "karma start karma.conf.cjs", - "proto": "rimraf src/proto/*.ts; protons src/proto/*.proto", "watch:build": "tsc -p tsconfig.json -w", "watch:test": "mocha --watch", "prepublish": "npm run build", @@ -97,7 +96,6 @@ "it-pipe": "^2.0.4", "libp2p": "0.40.0", "p-event": "^5.0.1", - "protons-runtime": "^3.1.0", "uint8arraylist": "^2.3.2", "uint8arrays": "^4.0.2", "uuid": "^9.0.0" @@ -140,7 +138,6 @@ "portfinder": "^1.0.28", "prettier": "^2.1.1", "process": "^0.11.10", - "protons": "^5.1.0", "puppeteer": "^13.0.1", "rollup": "^2.75.0", "tail": "^2.2.0", @@ -164,7 +161,6 @@ "bundle", "src/*.ts", "src/lib/**/*.ts", - "src/proto/**/*.ts", "!**/*.spec.*", "!**/*.json", "CHANGELOG.md", diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 8fc48aaa5e..da0e7012b7 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -1,9 +1,6 @@ export { DefaultPubSubTopic } from "./lib/constants.js"; export { DefaultUserAgent } from "./lib/waku.js"; -export * as proto_message from "./proto/message.js"; -export * as proto_topic_only_message from "./proto/topic_only_message.js"; - export { createEncoder, createDecoder, diff --git a/packages/core/src/lib/to_proto_message.spec.ts b/packages/core/src/lib/to_proto_message.spec.ts index 1f45affb75..b86d92a713 100644 --- a/packages/core/src/lib/to_proto_message.spec.ts +++ b/packages/core/src/lib/to_proto_message.spec.ts @@ -1,7 +1,6 @@ +import { WakuMessage as WakuMessageProto } from "@waku/proto"; import { expect } from "chai"; -import { WakuMessage as WakuMessageProto } from "../proto/message.js"; - import { toProtoMessage } from "./to_proto_message.js"; describe("to proto message", () => { diff --git a/packages/core/src/lib/to_proto_message.ts b/packages/core/src/lib/to_proto_message.ts index f2c987c992..e9bc99aeaf 100644 --- a/packages/core/src/lib/to_proto_message.ts +++ b/packages/core/src/lib/to_proto_message.ts @@ -1,6 +1,5 @@ import { ProtoMessage } from "@waku/interfaces"; - -import { WakuMessage as WakuMessageProto } from "../proto/message.js"; +import { WakuMessage as WakuMessageProto } from "@waku/proto"; const EmptyMessage: ProtoMessage = { payload: undefined, diff --git a/packages/core/src/lib/waku_filter/filter_rpc.ts b/packages/core/src/lib/waku_filter/filter_rpc.ts index f3b771183e..cbbf6e1ca8 100644 --- a/packages/core/src/lib/waku_filter/filter_rpc.ts +++ b/packages/core/src/lib/waku_filter/filter_rpc.ts @@ -1,7 +1,6 @@ +import { proto_filter as proto } from "@waku/proto"; import { v4 as uuid } from "uuid"; -import * as proto from "../../proto/filter.js"; - export type ContentFilter = { contentTopic: string; }; diff --git a/packages/core/src/lib/waku_filter/index.ts b/packages/core/src/lib/waku_filter/index.ts index ca62470b24..7d7714a659 100644 --- a/packages/core/src/lib/waku_filter/index.ts +++ b/packages/core/src/lib/waku_filter/index.ts @@ -19,12 +19,12 @@ import { selectPeerForProtocol, selectRandomPeer, } from "@waku/libp2p-utils"; +import { WakuMessage as WakuMessageProto } from "@waku/proto"; import debug from "debug"; import all from "it-all"; import * as lp from "it-length-prefixed"; import { pipe } from "it-pipe"; -import { WakuMessage as WakuMessageProto } from "../../proto/message.js"; import { DefaultPubSubTopic } from "../constants.js"; import { groupByContentTopic } from "../group_by.js"; import { toProtoMessage } from "../to_proto_message.js"; diff --git a/packages/core/src/lib/waku_light_push/index.ts b/packages/core/src/lib/waku_light_push/index.ts index d94e4d29dd..88c166c652 100644 --- a/packages/core/src/lib/waku_light_push/index.ts +++ b/packages/core/src/lib/waku_light_push/index.ts @@ -15,13 +15,13 @@ import { selectPeerForProtocol, selectRandomPeer, } from "@waku/libp2p-utils"; +import { PushResponse } from "@waku/proto"; import debug from "debug"; import all from "it-all"; import * as lp from "it-length-prefixed"; import { pipe } from "it-pipe"; import { Uint8ArrayList } from "uint8arraylist"; -import { PushResponse } from "../../proto/light_push.js"; import { DefaultPubSubTopic } from "../constants.js"; import { PushRPC } from "./push_rpc.js"; diff --git a/packages/core/src/lib/waku_light_push/push_rpc.ts b/packages/core/src/lib/waku_light_push/push_rpc.ts index 84bd7d60fb..23a928f374 100644 --- a/packages/core/src/lib/waku_light_push/push_rpc.ts +++ b/packages/core/src/lib/waku_light_push/push_rpc.ts @@ -1,8 +1,7 @@ +import { proto_lightpush as proto } from "@waku/proto"; import type { Uint8ArrayList } from "uint8arraylist"; import { v4 as uuid } from "uuid"; -import * as proto from "../../proto/light_push.js"; - export class PushRPC { public constructor(public proto: proto.PushRPC) {} diff --git a/packages/core/src/lib/waku_message/topic_only_message.ts b/packages/core/src/lib/waku_message/topic_only_message.ts index cddc970ce1..42c89cc6b5 100644 --- a/packages/core/src/lib/waku_message/topic_only_message.ts +++ b/packages/core/src/lib/waku_message/topic_only_message.ts @@ -1,8 +1,7 @@ import type { DecodedMessage, Decoder, ProtoMessage } from "@waku/interfaces"; +import { proto_topic_only_message as proto } from "@waku/proto"; import debug from "debug"; -import * as proto from "../../proto/topic_only_message.js"; - const log = debug("waku:message:topic-only"); export class TopicOnlyMessage implements DecodedMessage { diff --git a/packages/core/src/lib/waku_message/version_0.ts b/packages/core/src/lib/waku_message/version_0.ts index b58251f7d5..469fe0be20 100644 --- a/packages/core/src/lib/waku_message/version_0.ts +++ b/packages/core/src/lib/waku_message/version_0.ts @@ -6,10 +6,9 @@ import type { ProtoMessage, RateLimitProof, } from "@waku/interfaces"; +import { proto_message as proto } from "@waku/proto"; import debug from "debug"; -import * as proto from "../../proto/message.js"; - const log = debug("waku:message:version-0"); const OneMillion = BigInt(1_000_000); diff --git a/packages/core/src/lib/waku_store/history_rpc.ts b/packages/core/src/lib/waku_store/history_rpc.ts index 212b546933..8f0a971f0e 100644 --- a/packages/core/src/lib/waku_store/history_rpc.ts +++ b/packages/core/src/lib/waku_store/history_rpc.ts @@ -1,8 +1,7 @@ +import { proto_store as proto } from "@waku/proto"; import type { Uint8ArrayList } from "uint8arraylist"; import { v4 as uuid } from "uuid"; -import * as proto from "../../proto/store.js"; - const OneMillion = BigInt(1_000_000); export enum PageDirection { diff --git a/packages/core/src/lib/waku_store/index.ts b/packages/core/src/lib/waku_store/index.ts index a1cbccbdb0..6d9e7545c1 100644 --- a/packages/core/src/lib/waku_store/index.ts +++ b/packages/core/src/lib/waku_store/index.ts @@ -16,13 +16,13 @@ import { selectConnection, selectPeerForProtocol, } from "@waku/libp2p-utils"; +import { proto_store as proto } from "@waku/proto"; import debug from "debug"; import all from "it-all"; import * as lp from "it-length-prefixed"; import { pipe } from "it-pipe"; import { Uint8ArrayList } from "uint8arraylist"; -import * as proto from "../../proto/store.js"; import { DefaultPubSubTopic } from "../constants.js"; import { toProtoMessage } from "../to_proto_message.js"; diff --git a/packages/proto/.eslintrc.cjs b/packages/proto/.eslintrc.cjs new file mode 100644 index 0000000000..324f1f526d --- /dev/null +++ b/packages/proto/.eslintrc.cjs @@ -0,0 +1,6 @@ +module.exports = { + parserOptions: { + tsconfigRootDir: __dirname, + project: "./tsconfig.dev.json", + }, +}; diff --git a/packages/proto/.prettierignore b/packages/proto/.prettierignore new file mode 100644 index 0000000000..fecb37a393 --- /dev/null +++ b/packages/proto/.prettierignore @@ -0,0 +1,4 @@ +build +bundle +dist +node_modules diff --git a/packages/proto/package.json b/packages/proto/package.json new file mode 100644 index 0000000000..3066c87495 --- /dev/null +++ b/packages/proto/package.json @@ -0,0 +1,85 @@ +{ + "name": "@waku/proto", + "version": "0.0.1", + "description": "Protobuf definitions for Waku", + "types": "./dist/index.d.ts", + "module": "./dist/index.js", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "import": "./dist/index.js" + } + }, + "type": "module", + "author": "Waku Team", + "homepage": "https://github.com/waku-org/js-waku/tree/master/packages/proto#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": "run-s build:**", + "build:esm": "tsc", + "build:bundle": "rollup --config rollup.config.js", + "proto": "rimraf src/lib/*.ts; protons src/lib/*.proto", + "check:tsc": "tsc -p tsconfig.dev.json", + "prepublish": "npm run build", + "reset-hard": "git clean -dfx -e .idea && git reset --hard && npm i && npm run build", + "fix": "run-s fix:*", + "fix:prettier": "prettier . --write", + "fix:lint": "eslint src/*.ts --fix" + }, + "engines": { + "node": ">=16" + }, + "dependencies": { + "protons-runtime": "^3.1.0" + }, + "devDependencies": { + "@rollup/plugin-commonjs": "^22.0.0", + "@rollup/plugin-json": "^4.1.0", + "@rollup/plugin-node-resolve": "^13.3.0", + "@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", + "rollup": "^2.75.0", + "typescript": "^4.6.3", + "protons": "^5.1.0" + }, + "typedoc": { + "entryPoint": "./src/index.ts" + }, + "files": [ + "dist", + "bundle", + "src/*.ts", + "src/**/*.ts", + "!**/*.spec.*", + "!**/*.json", + "CHANGELOG.md", + "LICENSE", + "README.md" + ] +} diff --git a/packages/proto/rollup.config.js b/packages/proto/rollup.config.js new file mode 100644 index 0000000000..d22d3d231e --- /dev/null +++ b/packages/proto/rollup.config.js @@ -0,0 +1,21 @@ +import commonjs from "@rollup/plugin-commonjs"; +import json from "@rollup/plugin-json"; +import { nodeResolve } from "@rollup/plugin-node-resolve"; + +export default { + input: { + index: "dist/index.js", + }, + output: { + dir: "bundle", + format: "esm", + }, + plugins: [ + commonjs(), + json(), + nodeResolve({ + browser: true, + preferBuiltins: false, + }), + ], +}; diff --git a/packages/proto/src/index.ts b/packages/proto/src/index.ts new file mode 100644 index 0000000000..2b58d0a63e --- /dev/null +++ b/packages/proto/src/index.ts @@ -0,0 +1,11 @@ +export * as proto_message from "./lib/message.js"; +export { WakuMessage } from "./lib/filter.js"; + +export * as proto_topic_only_message from "./lib/topic_only_message.js"; + +export * as proto_filter from "./lib/filter.js"; + +export * as proto_lightpush from "./lib/light_push.js"; +export { PushResponse } from "./lib/light_push.js"; + +export * as proto_store from "./lib/store.js"; diff --git a/packages/core/src/proto/filter.proto b/packages/proto/src/lib/filter.proto similarity index 100% rename from packages/core/src/proto/filter.proto rename to packages/proto/src/lib/filter.proto diff --git a/packages/core/src/proto/filter.ts b/packages/proto/src/lib/filter.ts similarity index 100% rename from packages/core/src/proto/filter.ts rename to packages/proto/src/lib/filter.ts diff --git a/packages/core/src/proto/light_push.proto b/packages/proto/src/lib/light_push.proto similarity index 100% rename from packages/core/src/proto/light_push.proto rename to packages/proto/src/lib/light_push.proto diff --git a/packages/core/src/proto/light_push.ts b/packages/proto/src/lib/light_push.ts similarity index 100% rename from packages/core/src/proto/light_push.ts rename to packages/proto/src/lib/light_push.ts diff --git a/packages/core/src/proto/message.proto b/packages/proto/src/lib/message.proto similarity index 100% rename from packages/core/src/proto/message.proto rename to packages/proto/src/lib/message.proto diff --git a/packages/core/src/proto/message.ts b/packages/proto/src/lib/message.ts similarity index 100% rename from packages/core/src/proto/message.ts rename to packages/proto/src/lib/message.ts diff --git a/packages/core/src/proto/store.proto b/packages/proto/src/lib/store.proto similarity index 100% rename from packages/core/src/proto/store.proto rename to packages/proto/src/lib/store.proto diff --git a/packages/core/src/proto/store.ts b/packages/proto/src/lib/store.ts similarity index 100% rename from packages/core/src/proto/store.ts rename to packages/proto/src/lib/store.ts diff --git a/packages/core/src/proto/topic_only_message.proto b/packages/proto/src/lib/topic_only_message.proto similarity index 100% rename from packages/core/src/proto/topic_only_message.proto rename to packages/proto/src/lib/topic_only_message.proto diff --git a/packages/core/src/proto/topic_only_message.ts b/packages/proto/src/lib/topic_only_message.ts similarity index 100% rename from packages/core/src/proto/topic_only_message.ts rename to packages/proto/src/lib/topic_only_message.ts diff --git a/packages/proto/tsconfig.dev.json b/packages/proto/tsconfig.dev.json new file mode 100644 index 0000000000..4f7c34af3c --- /dev/null +++ b/packages/proto/tsconfig.dev.json @@ -0,0 +1,3 @@ +{ + "extends": "../../tsconfig.dev" +} diff --git a/packages/proto/tsconfig.json b/packages/proto/tsconfig.json new file mode 100644 index 0000000000..eebbc51585 --- /dev/null +++ b/packages/proto/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig", + "compilerOptions": { + "outDir": "dist/", + "rootDir": "src", + "tsBuildInfoFile": "dist/.tsbuildinfo" + }, + "include": ["src"], + "exclude": ["src/**/*.spec.ts", "src/test_utils"] +}