-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add ws provider package (#2578)
- Loading branch information
1 parent
15c5a58
commit e6825af
Showing
10 changed files
with
207 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# @substrate/ws-provider |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
{ | ||
"name": "@substrate/ws-provider", | ||
"version": "0.3.6", | ||
"author": "Parity Technologies (https://github.com/paritytech)", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/paritytech/substrate-connect.git" | ||
}, | ||
"license": "MIT", | ||
"type": "module", | ||
"exports": { | ||
"./package.json": "./package.json", | ||
".": { | ||
"import": { | ||
"@substrate-connect/source": "./src/index.ts", | ||
"types": "./dist/esm/index.d.ts", | ||
"default": "./dist/esm/index.js" | ||
}, | ||
"require": { | ||
"types": "./dist/commonjs/index.d.ts", | ||
"default": "./dist/commonjs/index.js" | ||
} | ||
} | ||
}, | ||
"main": "./dist/commonjs/index.js", | ||
"types": "./dist/commonjs/index.d.ts", | ||
"module": "./dist/esm/index.js", | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"deep-clean": "rimraf dist node_modules", | ||
"build": "tsup", | ||
"typecheck": "tsc --noEmit", | ||
"dev": "pnpm build --watch", | ||
"lint": "prettier --check README.md \"src/**/*.{js,jsx,ts,tsx,json,md}\"" | ||
}, | ||
"prettier": { | ||
"printWidth": 80, | ||
"semi": false, | ||
"trailingComma": "all" | ||
}, | ||
"dependencies": { | ||
"@polkadot-api/ws-provider": "0.3.6", | ||
"@polkadot-api/json-rpc-provider-proxy": "0.2.4", | ||
"@polkadot-api/json-rpc-provider": "0.0.4" | ||
}, | ||
"devDependencies": { | ||
"typescript": "5.6.2", | ||
"vitest": "^2.1.4" | ||
}, | ||
"peerDependencies": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { | ||
getInternalWsProvider, | ||
type StatusChange, | ||
type WsJsonRpcProvider, | ||
} from "@polkadot-api/ws-provider/web" | ||
|
||
export namespace GetWsProvider { | ||
export type Options = { | ||
endpoints: Array< | ||
| string | ||
| { | ||
uri: string | ||
protocol: string[] | ||
} | ||
> | ||
onStatusChanged?: (status: StatusChange) => void | ||
timeout?: number | ||
websocketConstructor?: typeof globalThis.WebSocket | ||
} | ||
|
||
export type GetWsProvider = (options: Options) => WsJsonRpcProvider | ||
} | ||
|
||
export const getWsProvider: GetWsProvider.GetWsProvider = (options) => { | ||
const wsProvider = getInternalWsProvider( | ||
options.websocketConstructor ?? globalThis.WebSocket, | ||
) | ||
|
||
return wsProvider(options) | ||
} | ||
|
||
export { | ||
WsEvent, | ||
type WsConnecting, | ||
type WsConnected, | ||
type WsError, | ||
type WsClose, | ||
type StatusChange, | ||
type JsonRpcProvider, | ||
type WsJsonRpcProvider, | ||
} from "@polkadot-api/ws-provider/web" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"extends": "../../tsconfig.build.json", | ||
"include": ["src"], | ||
"compilerOptions": { | ||
"incremental": false, | ||
"composite": false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"include": ["src", "tests"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { defineConfig } from "tsup" | ||
|
||
export default defineConfig([ | ||
{ | ||
entry: { | ||
index: "src/mod.ts", | ||
}, | ||
outDir: "dist/esm", | ||
format: ["esm"], | ||
dts: true, | ||
sourcemap: true, | ||
clean: true, | ||
tsconfig: "./tsconfig.build.json", | ||
noExternal: ["@polkadot-api/ws-provider"], | ||
external: [ | ||
"@polkadot-api/json-rpc-provider-proxy", | ||
"@polkadot-api/json-rpc-provider", | ||
], | ||
}, | ||
{ | ||
entry: { | ||
index: "src/mod.ts", | ||
}, | ||
outDir: "dist/commonjs", | ||
format: ["cjs"], | ||
dts: true, | ||
sourcemap: true, | ||
clean: true, | ||
tsconfig: "./tsconfig.build.json", | ||
noExternal: ["@polkadot-api/ws-provider"], | ||
external: [ | ||
"@polkadot-api/json-rpc-provider-proxy", | ||
"@polkadot-api/json-rpc-provider", | ||
], | ||
}, | ||
]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
diff --git a/dist/web/esm/web.mjs b/dist/web/esm/web.mjs | ||
index 241ec3bf8ebec5d7cfee0dc98fd95309b1298135..6aa173d56ed6702387325974b4ef912a5168abe9 100644 | ||
--- a/dist/web/esm/web.mjs | ||
+++ b/dist/web/esm/web.mjs | ||
@@ -3,5 +3,5 @@ export { WsEvent } from './types.mjs'; | ||
|
||
const getWsProvider = getInternalWsProvider(WebSocket); | ||
|
||
-export { getWsProvider }; | ||
+export { getWsProvider, getInternalWsProvider }; | ||
//# sourceMappingURL=web.mjs.map | ||
diff --git a/dist/web/web.d.ts b/dist/web/web.d.ts | ||
index d426010c36aa1ef4696409cc81036597d15f43b3..dc525d2d35ee5011eaeb9c0519ebe3f91dbbd2fa 100644 | ||
--- a/dist/web/web.d.ts | ||
+++ b/dist/web/web.d.ts | ||
@@ -49,5 +49,6 @@ interface GetWsProviderInput { | ||
} | ||
|
||
declare const getWsProvider: GetWsProviderInput; | ||
+declare const getInternalWsProvider: (wsCtor: typeof globalThis.WebSocket) => GetWsProviderInput; | ||
|
||
-export { type GetWsProviderInput, type StatusChange, type WsClose, type WsConnected, type WsConnecting, type WsError, WsEvent, type WsJsonRpcProvider, type WsProviderConfig, getWsProvider }; | ||
+export { type GetWsProviderInput, type StatusChange, type WsClose, type WsConnected, type WsConnecting, type WsError, WsEvent, type WsJsonRpcProvider, type WsProviderConfig, getWsProvider, getInternalWsProvider }; | ||
diff --git a/dist/web/web.js b/dist/web/web.js | ||
index 0fa7cd8079fb1834bda11013eca4af81b3c12106..d533a1bd65deb63e7e3d1c5f690cacdf7ffbda15 100644 | ||
--- a/dist/web/web.js | ||
+++ b/dist/web/web.js | ||
@@ -227,4 +227,5 @@ const getWsProvider = getInternalWsProvider(WebSocket); | ||
|
||
exports.WsEvent = WsEvent; | ||
exports.getWsProvider = getWsProvider; | ||
+exports.getInternalWsProvider = getInternalWsProvider; | ||
//# sourceMappingURL=web.js.map |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.