@pezkuwi/rpc-provider 16.5.5 → 16.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +10 -10
  3. package/bizinikiwi-connect/Health.js +259 -0
  4. package/{build/substrate-connect → bizinikiwi-connect}/index.d.ts +3 -3
  5. package/bizinikiwi-connect/index.js +319 -0
  6. package/{build/bundle.d.ts → bundle.d.ts} +1 -1
  7. package/{src/bundle.ts → bundle.js} +1 -4
  8. package/cjs/bizinikiwi-connect/Health.d.ts +7 -0
  9. package/cjs/bizinikiwi-connect/Health.js +264 -0
  10. package/cjs/bizinikiwi-connect/index.d.ts +22 -0
  11. package/cjs/bizinikiwi-connect/index.js +323 -0
  12. package/cjs/bizinikiwi-connect/types.d.ts +12 -0
  13. package/cjs/bizinikiwi-connect/types.js +2 -0
  14. package/cjs/bundle.d.ts +5 -0
  15. package/cjs/bundle.js +14 -0
  16. package/cjs/coder/error.js +53 -0
  17. package/cjs/coder/index.js +63 -0
  18. package/cjs/defaults.js +8 -0
  19. package/{build → cjs}/http/index.d.ts +1 -1
  20. package/cjs/http/index.js +196 -0
  21. package/cjs/http/types.js +2 -0
  22. package/cjs/index.js +5 -0
  23. package/cjs/lru.js +150 -0
  24. package/cjs/mock/index.js +196 -0
  25. package/cjs/mock/mockHttp.js +17 -0
  26. package/cjs/mock/mockWs.js +47 -0
  27. package/cjs/mock/types.js +2 -0
  28. package/cjs/package.json +3 -0
  29. package/cjs/packageDetect.d.ts +1 -0
  30. package/cjs/packageDetect.js +6 -0
  31. package/cjs/packageInfo.js +4 -0
  32. package/cjs/types.js +2 -0
  33. package/cjs/ws/errors.js +41 -0
  34. package/{build → cjs}/ws/index.d.ts +1 -1
  35. package/cjs/ws/index.js +529 -0
  36. package/coder/error.d.ts +29 -0
  37. package/coder/error.js +50 -0
  38. package/coder/index.d.ts +8 -0
  39. package/coder/index.js +58 -0
  40. package/defaults.d.ts +5 -0
  41. package/defaults.js +6 -0
  42. package/http/index.d.ts +81 -0
  43. package/http/index.js +191 -0
  44. package/http/types.d.ts +7 -0
  45. package/http/types.js +1 -0
  46. package/index.d.ts +2 -0
  47. package/index.js +2 -0
  48. package/lru.d.ts +15 -0
  49. package/lru.js +146 -0
  50. package/mock/index.d.ts +35 -0
  51. package/mock/index.js +191 -0
  52. package/mock/mockHttp.d.ts +9 -0
  53. package/mock/mockHttp.js +12 -0
  54. package/mock/mockWs.d.ts +26 -0
  55. package/mock/mockWs.js +43 -0
  56. package/mock/types.d.ts +23 -0
  57. package/mock/types.js +1 -0
  58. package/package.json +316 -15
  59. package/packageDetect.d.ts +1 -0
  60. package/packageDetect.js +4 -0
  61. package/packageInfo.d.ts +6 -0
  62. package/packageInfo.js +1 -0
  63. package/types.d.ts +85 -0
  64. package/types.js +1 -0
  65. package/ws/errors.d.ts +1 -0
  66. package/ws/errors.js +38 -0
  67. package/ws/index.d.ts +121 -0
  68. package/ws/index.js +524 -0
  69. package/src/coder/decodeResponse.spec.ts +0 -70
  70. package/src/coder/encodeJson.spec.ts +0 -20
  71. package/src/coder/encodeObject.spec.ts +0 -25
  72. package/src/coder/error.spec.ts +0 -111
  73. package/src/coder/error.ts +0 -66
  74. package/src/coder/index.ts +0 -88
  75. package/src/defaults.ts +0 -10
  76. package/src/http/index.spec.ts +0 -72
  77. package/src/http/index.ts +0 -238
  78. package/src/http/send.spec.ts +0 -61
  79. package/src/http/types.ts +0 -11
  80. package/src/index.ts +0 -6
  81. package/src/lru.spec.ts +0 -74
  82. package/src/lru.ts +0 -197
  83. package/src/mock/index.ts +0 -259
  84. package/src/mock/mockHttp.ts +0 -35
  85. package/src/mock/mockWs.ts +0 -92
  86. package/src/mock/on.spec.ts +0 -43
  87. package/src/mock/send.spec.ts +0 -38
  88. package/src/mock/subscribe.spec.ts +0 -81
  89. package/src/mock/types.ts +0 -36
  90. package/src/mock/unsubscribe.spec.ts +0 -57
  91. package/src/mod.ts +0 -4
  92. package/src/packageDetect.ts +0 -12
  93. package/src/packageInfo.ts +0 -6
  94. package/src/substrate-connect/Health.ts +0 -325
  95. package/src/substrate-connect/index.spec.ts +0 -638
  96. package/src/substrate-connect/index.ts +0 -415
  97. package/src/substrate-connect/types.ts +0 -16
  98. package/src/types.ts +0 -101
  99. package/src/ws/connect.spec.ts +0 -167
  100. package/src/ws/errors.ts +0 -41
  101. package/src/ws/index.spec.ts +0 -97
  102. package/src/ws/index.ts +0 -652
  103. package/src/ws/send.spec.ts +0 -126
  104. package/src/ws/state.spec.ts +0 -20
  105. package/src/ws/subscribe.spec.ts +0 -68
  106. package/src/ws/unsubscribe.spec.ts +0 -100
  107. package/tsconfig.build.json +0 -17
  108. package/tsconfig.build.tsbuildinfo +0 -1
  109. package/tsconfig.spec.json +0 -18
  110. /package/{build/substrate-connect → bizinikiwi-connect}/Health.d.ts +0 -0
  111. /package/{build/substrate-connect → bizinikiwi-connect}/types.d.ts +0 -0
  112. /package/{build/packageDetect.d.ts → bizinikiwi-connect/types.js} +0 -0
  113. /package/{build → cjs}/coder/error.d.ts +0 -0
  114. /package/{build → cjs}/coder/index.d.ts +0 -0
  115. /package/{build → cjs}/defaults.d.ts +0 -0
  116. /package/{build → cjs}/http/types.d.ts +0 -0
  117. /package/{build → cjs}/index.d.ts +0 -0
  118. /package/{build → cjs}/lru.d.ts +0 -0
  119. /package/{build → cjs}/mock/index.d.ts +0 -0
  120. /package/{build → cjs}/mock/mockHttp.d.ts +0 -0
  121. /package/{build → cjs}/mock/mockWs.d.ts +0 -0
  122. /package/{build → cjs}/mock/types.d.ts +0 -0
  123. /package/{build → cjs}/packageInfo.d.ts +0 -0
  124. /package/{build → cjs}/types.d.ts +0 -0
  125. /package/{build → cjs}/ws/errors.d.ts +0 -0
@@ -1,126 +0,0 @@
1
- // Copyright 2017-2025 @polkadot/rpc-provider authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- /// <reference types="@pezkuwi/dev-test/globals.d.ts" />
5
-
6
- import type { Request } from '../mock/mockWs.js';
7
- import type { Global, Mock } from '../mock/types.js';
8
-
9
- import { mockWs } from '../mock/mockWs.js';
10
- import { WsProvider } from './index.js';
11
-
12
- declare const global: Global;
13
-
14
- const TEST_WS_URL = 'ws://localhost-send.spec.ts:9965';
15
-
16
- let provider: WsProvider | null;
17
- let mock: Mock;
18
-
19
- function createMock (requests: Request[]): void {
20
- mock = mockWs(requests, TEST_WS_URL);
21
- }
22
-
23
- function createWs (autoConnect = 1000): Promise<WsProvider> {
24
- provider = new WsProvider(TEST_WS_URL, autoConnect);
25
-
26
- return provider.isReady;
27
- }
28
-
29
- describe('send', (): void => {
30
- let globalWs: typeof WebSocket;
31
-
32
- beforeEach((): void => {
33
- globalWs = global.WebSocket;
34
- });
35
-
36
- afterEach(async () => {
37
- global.WebSocket = globalWs;
38
-
39
- if (mock) {
40
- await mock.done();
41
- }
42
-
43
- if (provider) {
44
- await provider.disconnect();
45
- provider = null;
46
- }
47
- });
48
-
49
- it('handles internal errors', (): Promise<any> => {
50
- createMock([{
51
- id: 1,
52
- method: 'test_body',
53
- reply: {
54
- result: 'ok'
55
- }
56
- }]);
57
-
58
- return createWs().then((ws) =>
59
- ws
60
- .send('test_encoding', [{ error: 'send error' }])
61
- .catch((error): void => {
62
- // eslint-disable-next-line jest/no-conditional-expect
63
- expect((error as Error).message).toEqual('send error');
64
- })
65
- );
66
- });
67
-
68
- it('passes the body through correctly', (): Promise<void> => {
69
- createMock([{
70
- id: 1,
71
- method: 'test_body',
72
- reply: {
73
- result: 'ok'
74
- }
75
- }]);
76
-
77
- return createWs().then((ws) =>
78
- ws
79
- .send('test_body', ['param'])
80
- .then((): void => {
81
- expect(
82
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
83
- (mock.body as any).test_body
84
- ).toEqual('{"id":1,"jsonrpc":"2.0","method":"test_body","params":["param"]}');
85
- })
86
- );
87
- });
88
-
89
- it('throws error when !response.ok', (): Promise<any> => {
90
- createMock([{
91
- error: {
92
- code: 666,
93
- message: 'error'
94
- },
95
- id: 1,
96
- method: 'something'
97
- }]);
98
-
99
- return createWs().then((ws) =>
100
- ws
101
- .send('test_error', [])
102
- .catch((error): void => {
103
- // eslint-disable-next-line jest/no-conditional-expect
104
- expect((error as Error).message).toMatch(/666: error/);
105
- })
106
- );
107
- });
108
-
109
- it('adds subscriptions', (): Promise<void> => {
110
- createMock([{
111
- id: 1,
112
- method: 'test_sub',
113
- reply: {
114
- result: 1
115
- }
116
- }]);
117
-
118
- return createWs().then((ws) =>
119
- ws
120
- .send('test_sub', [])
121
- .then((id): void => {
122
- expect(id).toEqual(1);
123
- })
124
- );
125
- });
126
- });
@@ -1,20 +0,0 @@
1
- // Copyright 2017-2025 @polkadot/rpc-provider authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- /// <reference types="@pezkuwi/dev-test/globals.d.ts" />
5
-
6
- import { WsProvider } from './index.js';
7
-
8
- describe('state', (): void => {
9
- it('requires an ws:// prefixed endpoint', (): void => {
10
- expect(
11
- () => new WsProvider('http://', 0)
12
- ).toThrow(/with 'ws/);
13
- });
14
-
15
- it('allows wss:// endpoints', (): void => {
16
- expect(
17
- () => new WsProvider('wss://', 0)
18
- ).not.toThrow();
19
- });
20
- });
@@ -1,68 +0,0 @@
1
- // Copyright 2017-2025 @polkadot/rpc-provider authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- /// <reference types="@pezkuwi/dev-test/globals.d.ts" />
5
-
6
- import type { Request } from '../mock/mockWs.js';
7
- import type { Global, Mock } from './../mock/types.js';
8
-
9
- import { mockWs } from '../mock/mockWs.js';
10
- import { WsProvider } from './index.js';
11
-
12
- declare const global: Global;
13
-
14
- const TEST_WS_URL = 'ws://localhost-subscribe.test.ts:9933';
15
-
16
- let provider: WsProvider | null;
17
- let mock: Mock;
18
-
19
- function createMock (requests: Request[]): void {
20
- mock = mockWs(requests, TEST_WS_URL);
21
- }
22
-
23
- function createWs (autoConnect = 1000): Promise<WsProvider> {
24
- provider = new WsProvider(TEST_WS_URL, autoConnect);
25
-
26
- return provider.isReady;
27
- }
28
-
29
- describe('subscribe', (): void => {
30
- let globalWs: typeof WebSocket;
31
-
32
- beforeEach((): void => {
33
- globalWs = global.WebSocket;
34
- });
35
-
36
- afterEach(async () => {
37
- global.WebSocket = globalWs;
38
-
39
- if (mock) {
40
- await mock.done();
41
- }
42
-
43
- if (provider) {
44
- await provider.disconnect();
45
- provider = null;
46
- }
47
- });
48
-
49
- it('adds subscriptions', (): Promise<void> => {
50
- createMock([{
51
- id: 1,
52
- method: 'test_sub',
53
- reply: {
54
- result: 1
55
- }
56
- }]);
57
-
58
- return createWs().then((ws) =>
59
- ws
60
- .subscribe('type', 'test_sub', [], (cb): void => {
61
- expect(cb).toEqual(expect.anything());
62
- })
63
- .then((id): void => {
64
- expect(id).toEqual(1);
65
- })
66
- );
67
- });
68
- });
@@ -1,100 +0,0 @@
1
- // Copyright 2017-2025 @polkadot/rpc-provider authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- /// <reference types="@pezkuwi/dev-test/globals.d.ts" />
5
-
6
- import type { Request } from '../mock/mockWs.js';
7
- import type { Global, Mock } from './../mock/types.js';
8
-
9
- import { mockWs } from '../mock/mockWs.js';
10
- import { WsProvider } from './index.js';
11
-
12
- declare const global: Global;
13
-
14
- const TEST_WS_URL = 'ws://localhost-unsubscribe.test.ts:9933';
15
-
16
- let provider: WsProvider | null;
17
- let mock: Mock;
18
-
19
- function createMock (requests: Request[]): void {
20
- mock = mockWs(requests, TEST_WS_URL);
21
- }
22
-
23
- function createWs (autoConnect = 1000): Promise<WsProvider> {
24
- provider = new WsProvider(TEST_WS_URL, autoConnect);
25
-
26
- return provider.isReady;
27
- }
28
-
29
- describe('subscribe', (): void => {
30
- let globalWs: typeof WebSocket;
31
-
32
- beforeEach((): void => {
33
- globalWs = global.WebSocket;
34
- });
35
-
36
- afterEach(async () => {
37
- global.WebSocket = globalWs;
38
-
39
- if (mock) {
40
- await mock.done();
41
- }
42
-
43
- if (provider) {
44
- await provider.disconnect();
45
- provider = null;
46
- }
47
- });
48
-
49
- it('removes subscriptions', async (): Promise<void> => {
50
- createMock([
51
- {
52
- id: 1,
53
- method: 'subscribe_test',
54
- reply: {
55
- result: 1
56
- }
57
- },
58
- {
59
- id: 2,
60
- method: 'unsubscribe_test',
61
- reply: {
62
- result: true
63
- }
64
- }
65
- ]);
66
-
67
- await createWs().then((ws) =>
68
- ws
69
- .subscribe('test', 'subscribe_test', [], (cb): void => {
70
- expect(cb).toEqual(expect.anything());
71
- })
72
- .then((id): Promise<boolean> => {
73
- return ws.unsubscribe('test', 'subscribe_test', id);
74
- })
75
- );
76
- });
77
-
78
- it('fails when sub not found', (): Promise<void> => {
79
- createMock([{
80
- id: 1,
81
- method: 'subscribe_test',
82
- reply: {
83
- result: 1
84
- }
85
- }]);
86
-
87
- return createWs().then((ws) =>
88
- ws
89
- .subscribe('test', 'subscribe_test', [], (cb): void => {
90
- expect(cb).toEqual(expect.anything());
91
- })
92
- .then((): Promise<boolean> => {
93
- return ws.unsubscribe('test', 'subscribe_test', 111);
94
- })
95
- .then((result): void => {
96
- expect(result).toBe(false);
97
- })
98
- );
99
- });
100
- });
@@ -1,17 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- "compilerOptions": {
4
- "baseUrl": "..",
5
- "outDir": "./build",
6
- "rootDir": "./src",
7
- "resolveJsonModule": true
8
- },
9
- "exclude": [
10
- "**/*.spec.ts",
11
- "**/mod.ts"
12
- ],
13
- "references": [
14
- { "path": "../types/tsconfig.build.json" },
15
- { "path": "../types-support/tsconfig.build.json" }
16
- ]
17
- }