@0xobelisk/sui-client 1.0.7 → 1.0.8
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.
- package/dist/dubhe.d.ts +0 -1
- package/dist/index.js +71 -3755
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +50 -3756
- package/dist/index.mjs.map +1 -1
- package/dist/libs/http/http.d.ts +2 -2
- package/dist/libs/http/ws-adapter.d.ts +6 -0
- package/dist/libs/suiIndexerClient/index.d.ts +4 -1
- package/package.json +4 -4
- package/src/dubhe.ts +0 -1
- package/src/libs/http/http.ts +16 -16
- package/src/libs/http/ws-adapter.ts +36 -0
- package/src/libs/suiIndexerClient/index.ts +8 -1
package/dist/libs/http/http.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { WebSocketInstance } from './ws-adapter';
|
|
2
2
|
export type FetchOptions = RequestInit & {
|
|
3
3
|
next?: {
|
|
4
4
|
revalidate?: boolean | number;
|
|
@@ -17,5 +17,5 @@ export declare class Http {
|
|
|
17
17
|
query: string;
|
|
18
18
|
variables?: any;
|
|
19
19
|
}): Promise<T>;
|
|
20
|
-
subscribe(names: string[], handleData: (data: any) => void): Promise<
|
|
20
|
+
subscribe(names: string[], handleData: (data: any) => void): Promise<WebSocketInstance>;
|
|
21
21
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Http } from '../http';
|
|
2
|
-
import { WebSocket } from 'ws';
|
|
3
2
|
export interface OrderDirection {
|
|
4
3
|
ASC: 'ASC';
|
|
5
4
|
DESC: 'DESC';
|
|
@@ -18,6 +17,7 @@ export interface Transaction {
|
|
|
18
17
|
id: number;
|
|
19
18
|
checkpoint: number;
|
|
20
19
|
digest: string;
|
|
20
|
+
created_at: string;
|
|
21
21
|
}
|
|
22
22
|
export interface Schema {
|
|
23
23
|
id: number;
|
|
@@ -28,6 +28,8 @@ export interface Schema {
|
|
|
28
28
|
last_update_checkpoint: string;
|
|
29
29
|
last_update_digest: string;
|
|
30
30
|
is_removed: boolean;
|
|
31
|
+
created_at: string;
|
|
32
|
+
updated_at: string;
|
|
31
33
|
}
|
|
32
34
|
export interface Event {
|
|
33
35
|
id: number;
|
|
@@ -35,6 +37,7 @@ export interface Event {
|
|
|
35
37
|
digest: string;
|
|
36
38
|
name: string;
|
|
37
39
|
value: string;
|
|
40
|
+
created_at: string;
|
|
38
41
|
}
|
|
39
42
|
export interface ConnectionResponse<T> {
|
|
40
43
|
edges: Array<{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xobelisk/sui-client",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"description": "Tookit for interacting with move eps framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sui",
|
|
@@ -57,7 +57,8 @@
|
|
|
57
57
|
"tmp": "^0.2.1",
|
|
58
58
|
"ts-retry-promise": "^0.7.1",
|
|
59
59
|
"tweetnacl": "^1.0.3",
|
|
60
|
-
"valibot": "0.36.0"
|
|
60
|
+
"valibot": "0.36.0",
|
|
61
|
+
"ws": "^8.18.0"
|
|
61
62
|
},
|
|
62
63
|
"devDependencies": {
|
|
63
64
|
"@commitlint/cli": "^18.0.0",
|
|
@@ -66,7 +67,6 @@
|
|
|
66
67
|
"@types/jest": "^29.5.14",
|
|
67
68
|
"@types/node": "^20.8.7",
|
|
68
69
|
"@types/tmp": "^0.2.5",
|
|
69
|
-
"@types/ws": "^8.5.14",
|
|
70
70
|
"@typescript-eslint/eslint-plugin": "^6.8.0",
|
|
71
71
|
"@typescript-eslint/parser": "^6.8.0",
|
|
72
72
|
"dotenv": "^16.3.1",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"tsup": "^7.1.0",
|
|
83
83
|
"typedoc": "^0.25.2",
|
|
84
84
|
"typescript": "^5.2.2",
|
|
85
|
-
"ws": "^8.
|
|
85
|
+
"@types/ws": "^8.5.14"
|
|
86
86
|
},
|
|
87
87
|
"lint-staged": {
|
|
88
88
|
"**/*.ts": [
|
package/src/dubhe.ts
CHANGED
package/src/libs/http/http.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { WebSocket } from 'ws';
|
|
2
1
|
import { BaseError, HttpError, GraphQLError, ParseError } from './errors';
|
|
2
|
+
import { createWebSocketClient, WebSocketInstance } from './ws-adapter';
|
|
3
3
|
|
|
4
4
|
export type FetchOptions = RequestInit & {
|
|
5
5
|
next?: {
|
|
@@ -62,7 +62,6 @@ export class Http {
|
|
|
62
62
|
try {
|
|
63
63
|
const isFirstPage = variables?.after === 'first';
|
|
64
64
|
const fetchFn = this.getFetch();
|
|
65
|
-
console.log(query);
|
|
66
65
|
const response = await fetchFn(this.graphqlEndpoint, {
|
|
67
66
|
method: 'POST',
|
|
68
67
|
headers: {
|
|
@@ -109,7 +108,6 @@ export class Http {
|
|
|
109
108
|
|
|
110
109
|
return data.data;
|
|
111
110
|
} catch (error) {
|
|
112
|
-
console.log(error);
|
|
113
111
|
if (error instanceof BaseError) {
|
|
114
112
|
throw error;
|
|
115
113
|
}
|
|
@@ -123,30 +121,32 @@ export class Http {
|
|
|
123
121
|
}
|
|
124
122
|
}
|
|
125
123
|
|
|
126
|
-
async subscribe(
|
|
127
|
-
|
|
124
|
+
async subscribe(
|
|
125
|
+
names: string[],
|
|
126
|
+
handleData: (data: any) => void
|
|
127
|
+
): Promise<WebSocketInstance> {
|
|
128
|
+
const ws = createWebSocketClient(this.wsEndpoint);
|
|
128
129
|
|
|
129
|
-
ws.
|
|
130
|
+
ws.onopen = () => {
|
|
130
131
|
console.log('Connected to the WebSocket server');
|
|
131
|
-
// Subscribe to specific event names
|
|
132
132
|
const subscribeMessage = JSON.stringify({
|
|
133
133
|
type: 'subscribe',
|
|
134
134
|
names: names,
|
|
135
135
|
});
|
|
136
136
|
ws.send(subscribeMessage);
|
|
137
|
-
}
|
|
137
|
+
};
|
|
138
138
|
|
|
139
|
-
ws.
|
|
140
|
-
handleData(JSON.parse(data.toString()));
|
|
141
|
-
}
|
|
139
|
+
ws.onmessage = (event) => {
|
|
140
|
+
handleData(JSON.parse(event.data.toString()));
|
|
141
|
+
};
|
|
142
142
|
|
|
143
|
-
ws.
|
|
143
|
+
ws.onclose = () => {
|
|
144
144
|
console.log('Disconnected from the WebSocket server');
|
|
145
|
-
}
|
|
145
|
+
};
|
|
146
146
|
|
|
147
|
-
ws.
|
|
148
|
-
console.error(`WebSocket error
|
|
149
|
-
}
|
|
147
|
+
ws.onerror = (error) => {
|
|
148
|
+
console.error(`WebSocket error:`, error);
|
|
149
|
+
};
|
|
150
150
|
|
|
151
151
|
return ws;
|
|
152
152
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export type WebSocketInstance = WebSocket;
|
|
2
|
+
|
|
3
|
+
export interface WebSocketConstructor {
|
|
4
|
+
new (url: string): WebSocket;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function createWebSocketClient(url: string): WebSocketInstance {
|
|
8
|
+
if (typeof window !== 'undefined') {
|
|
9
|
+
// Browser Environment
|
|
10
|
+
return new WebSocket(url);
|
|
11
|
+
} else {
|
|
12
|
+
// Node.js Environment
|
|
13
|
+
try {
|
|
14
|
+
require.resolve('ws');
|
|
15
|
+
const WebSocket = require('ws');
|
|
16
|
+
return new WebSocket(url);
|
|
17
|
+
} catch (e) {
|
|
18
|
+
console.error('Failed to load WebSocket implementation:', e);
|
|
19
|
+
throw new Error(
|
|
20
|
+
'WebSocket implementation not available. Please install the "ws" package.'
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function isWebSocketSupported(): boolean {
|
|
27
|
+
if (typeof window !== 'undefined') {
|
|
28
|
+
return typeof WebSocket !== 'undefined';
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
require.resolve('ws');
|
|
32
|
+
return true;
|
|
33
|
+
} catch {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Http } from '../http';
|
|
2
|
-
import { WebSocket } from 'ws';
|
|
3
2
|
|
|
4
3
|
export interface OrderDirection {
|
|
5
4
|
ASC: 'ASC';
|
|
@@ -22,6 +21,7 @@ export interface Transaction {
|
|
|
22
21
|
id: number;
|
|
23
22
|
checkpoint: number;
|
|
24
23
|
digest: string;
|
|
24
|
+
created_at: string;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
export interface Schema {
|
|
@@ -33,6 +33,8 @@ export interface Schema {
|
|
|
33
33
|
last_update_checkpoint: string;
|
|
34
34
|
last_update_digest: string;
|
|
35
35
|
is_removed: boolean;
|
|
36
|
+
created_at: string;
|
|
37
|
+
updated_at: string;
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
export interface Event {
|
|
@@ -41,6 +43,7 @@ export interface Event {
|
|
|
41
43
|
digest: string;
|
|
42
44
|
name: string;
|
|
43
45
|
value: string;
|
|
46
|
+
created_at: string;
|
|
44
47
|
}
|
|
45
48
|
|
|
46
49
|
export interface ConnectionResponse<T> {
|
|
@@ -80,6 +83,7 @@ export class SuiIndexerClient {
|
|
|
80
83
|
id
|
|
81
84
|
checkpoint
|
|
82
85
|
digest
|
|
86
|
+
created_at
|
|
83
87
|
}
|
|
84
88
|
}
|
|
85
89
|
pageInfo {
|
|
@@ -123,6 +127,8 @@ export class SuiIndexerClient {
|
|
|
123
127
|
last_update_checkpoint
|
|
124
128
|
last_update_digest
|
|
125
129
|
is_removed
|
|
130
|
+
created_at
|
|
131
|
+
updated_at
|
|
126
132
|
}
|
|
127
133
|
}
|
|
128
134
|
pageInfo {
|
|
@@ -162,6 +168,7 @@ export class SuiIndexerClient {
|
|
|
162
168
|
digest
|
|
163
169
|
name
|
|
164
170
|
value
|
|
171
|
+
created_at
|
|
165
172
|
}
|
|
166
173
|
}
|
|
167
174
|
pageInfo {
|