miyavsanto 0.0.0-stage → 1.0.0

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/README.md CHANGED
@@ -1,3 +1,91 @@
1
- # Temporary Holding Version
1
+ # miyavsanto
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ High performance native Rust TLS, HTTP/2, WebSocket, Gateway and Request Cache client for Node.js.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install miyavsanto
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```javascript
14
+ const client = require('miyavsanto');
15
+
16
+ async function run() {
17
+ const res = await client.get('https://httpbin.org/get', {
18
+ cache: true,
19
+ tcp_nodelay: true,
20
+ });
21
+ console.log(res.status, res.version, res.cached);
22
+ }
23
+
24
+ run();
25
+ ```
26
+
27
+ ## API
28
+
29
+ ### HTTP Requests
30
+
31
+ ```javascript
32
+ const client = require('miyavsanto');
33
+
34
+ const res = await client.get('https://api.site.com/data');
35
+ const json = await client.getJson('https://api.site.com/user');
36
+ const postRes = await client.postJson('https://api.site.com/submit', { key: 'value' });
37
+
38
+ const batchResults = await client.batch([
39
+ { url: 'https://httpbin.org/uuid' },
40
+ { url: 'https://httpbin.org/ip' }
41
+ ]);
42
+ ```
43
+
44
+ ### Request Cache
45
+
46
+ ```javascript
47
+ const client = require('miyavsanto');
48
+
49
+ const r1 = await client.get('https://api.site.com/items', { cache: true });
50
+ const r2 = await client.get('https://api.site.com/items', { cache: true });
51
+
52
+ console.log(client.cache.stats());
53
+ client.cache.clear();
54
+ ```
55
+
56
+ ### WebSocket with Custom Settings & No Delay
57
+
58
+ ```javascript
59
+ const client = require('miyavsanto');
60
+
61
+ const ws = await client.ws('wss://echo.websocket.org', {
62
+ tcp_nodelay: true,
63
+ max_message_size: 16777216,
64
+ headers: [['user-agent', 'CustomClient']],
65
+ }, (msg) => {
66
+ if (msg.kind === 'text') {
67
+ const data = JSON.parse(msg.text);
68
+ console.log(data);
69
+ }
70
+ });
71
+
72
+ ws.sendText(JSON.stringify({ hello: 'world' }));
73
+ ```
74
+
75
+ ### Gateway & Self Token
76
+
77
+ ```javascript
78
+ const client = require('miyavsanto');
79
+
80
+ const gw = await client.gateway({
81
+ tokenSource: 'file',
82
+ socketOptions: {
83
+ tcp_nodelay: true,
84
+ },
85
+ }, (msg) => {
86
+ if (msg.kind === 'text') {
87
+ const packet = JSON.parse(msg.text);
88
+ console.log('Opcode:', packet.op);
89
+ }
90
+ });
91
+ ```
package/client.js ADDED
@@ -0,0 +1,265 @@
1
+ 'use strict';
2
+
3
+ const native = require('./index.js');
4
+ const config = require('./config.js');
5
+
6
+ function normalizeResponse(res) {
7
+ if (!res) return res;
8
+ if (res.elapsed_ms === undefined && res.elapsedMs !== undefined) {
9
+ res.elapsed_ms = res.elapsedMs;
10
+ }
11
+ if (res.body_bytes === undefined && res.bodyBytes !== undefined) {
12
+ res.body_bytes = res.bodyBytes;
13
+ }
14
+ return res;
15
+ }
16
+
17
+ function parseHeaders(response) {
18
+ if (!response || !response.headers) return {};
19
+ try {
20
+ return typeof response.headers === 'string'
21
+ ? JSON.parse(response.headers)
22
+ : response.headers;
23
+ } catch {
24
+ return {};
25
+ }
26
+ }
27
+
28
+ function parseJson(response) {
29
+ if (!response || response.body == null) return null;
30
+ try {
31
+ return JSON.parse(response.body);
32
+ } catch {
33
+ return null;
34
+ }
35
+ }
36
+
37
+ function isOk(response) {
38
+ return response && response.status >= 200 && response.status < 300;
39
+ }
40
+
41
+ async function request(url, opts = {}) {
42
+ const res = await native.httpRequest(url, opts);
43
+ return normalizeResponse(res);
44
+ }
45
+
46
+ function get(url, opts = {}) {
47
+ return request(url, { ...opts, method: 'GET' });
48
+ }
49
+
50
+ function post(url, body = '', opts = {}) {
51
+ return request(url, {
52
+ ...opts,
53
+ method: 'POST',
54
+ body: typeof body === 'object' ? JSON.stringify(body) : String(body),
55
+ });
56
+ }
57
+
58
+ function put(url, body = '', opts = {}) {
59
+ return request(url, {
60
+ ...opts,
61
+ method: 'PUT',
62
+ body: typeof body === 'object' ? JSON.stringify(body) : String(body),
63
+ });
64
+ }
65
+
66
+ function patch(url, body = '', opts = {}) {
67
+ return request(url, {
68
+ ...opts,
69
+ method: 'PATCH',
70
+ body: typeof body === 'object' ? JSON.stringify(body) : String(body),
71
+ });
72
+ }
73
+
74
+ function del(url, opts = {}) {
75
+ return request(url, { ...opts, method: 'DELETE' });
76
+ }
77
+
78
+ async function getJson(url, opts = {}) {
79
+ const headers = [...(opts.headers || [])];
80
+ if (!headers.some(([k]) => k.toLowerCase() === 'accept')) {
81
+ headers.push(['Accept', 'application/json']);
82
+ }
83
+
84
+ const res = await get(url, { ...opts, headers });
85
+ return parseJson(res);
86
+ }
87
+
88
+ async function postJson(url, data = {}, opts = {}) {
89
+ const headers = [...(opts.headers || [])];
90
+ if (!headers.some(([k]) => k.toLowerCase() === 'content-type')) {
91
+ headers.push(['Content-Type', 'application/json']);
92
+ }
93
+ if (!headers.some(([k]) => k.toLowerCase() === 'accept')) {
94
+ headers.push(['Accept', 'application/json']);
95
+ }
96
+
97
+ const bodyStr = typeof data === 'string' ? data : JSON.stringify(data);
98
+ const res = await request(url, {
99
+ ...opts,
100
+ method: 'POST',
101
+ body: bodyStr,
102
+ headers,
103
+ });
104
+
105
+ return parseJson(res);
106
+ }
107
+
108
+ async function batch(items) {
109
+ const results = await native.httpRequestBatch(items);
110
+ for (const r of results) {
111
+ if (r.response) normalizeResponse(r.response);
112
+ }
113
+ return results;
114
+ }
115
+
116
+ function ws(url, opts = {}, onMessage) {
117
+ let options = opts;
118
+ let callback = onMessage;
119
+
120
+ if (typeof opts === 'function') {
121
+ callback = opts;
122
+ options = {};
123
+ }
124
+
125
+ return native.wsConnect(url, options, (arg1, arg2) => {
126
+ const payload = arg2 !== undefined ? arg2 : arg1;
127
+ if (typeof callback === 'function') {
128
+ callback(payload);
129
+ }
130
+ });
131
+ }
132
+
133
+ const cache = {
134
+ stats() {
135
+ const s = native.httpCacheStats();
136
+ if (s.hitRate !== undefined && s.hit_rate === undefined) {
137
+ s.hit_rate = s.hitRate;
138
+ }
139
+ return s;
140
+ },
141
+ clear() {
142
+ native.httpCacheClear();
143
+ },
144
+ invalidate(key) {
145
+ return native.httpCacheInvalidate(key);
146
+ },
147
+ get(key) {
148
+ const r = native.httpCacheGet(key);
149
+ return normalizeResponse(r);
150
+ },
151
+ set(key, response) {
152
+ native.httpCacheSet(key, response);
153
+ },
154
+ };
155
+
156
+ async function gateway(options = {}, onMessage) {
157
+ const token =
158
+ options.token ||
159
+ config.getToken(options.tokenSource || config.tokenSource);
160
+
161
+ const gatewayUrl = options.gatewayUrl || config.gatewayUrl;
162
+ const socketOptions = options.socketOptions || {};
163
+ const autoHeartbeat = options.autoHeartbeat !== false;
164
+ const autoIdentify = options.autoIdentify !== false;
165
+
166
+ let heartbeatTimer = null;
167
+ let lastSequence = null;
168
+
169
+ function sendJson(conn, data) {
170
+ conn.sendText(JSON.stringify(data));
171
+ }
172
+
173
+ function identify(conn) {
174
+ if (!token) return;
175
+ const identifyPayload = {
176
+ op: 2,
177
+ d: {
178
+ token: token,
179
+ capabilities: 16381,
180
+ properties: options.properties || {
181
+ os: 'Windows',
182
+ browser: 'Chrome',
183
+ device: '',
184
+ },
185
+ presence: options.presence || {
186
+ status: 'online',
187
+ since: 0,
188
+ activities: [],
189
+ afk: false,
190
+ },
191
+ compress: false,
192
+ },
193
+ };
194
+ sendJson(conn, identifyPayload);
195
+ }
196
+
197
+ let connection = null;
198
+
199
+ connection = await ws(gatewayUrl, socketOptions, (msg) => {
200
+ if (msg && msg.kind === 'text' && msg.text) {
201
+ try {
202
+ const payload = JSON.parse(msg.text);
203
+ if (payload.s !== null && payload.s !== undefined) {
204
+ lastSequence = payload.s;
205
+ }
206
+
207
+ if (payload.op === 10) {
208
+ const interval = payload.d?.heartbeat_interval;
209
+ if (interval && autoHeartbeat && connection) {
210
+ if (heartbeatTimer) clearInterval(heartbeatTimer);
211
+ heartbeatTimer = setInterval(() => {
212
+ if (connection) {
213
+ sendJson(connection, { op: 1, d: lastSequence });
214
+ }
215
+ }, interval);
216
+ }
217
+ if (autoIdentify && connection) {
218
+ identify(connection);
219
+ }
220
+ }
221
+ } catch {}
222
+ }
223
+
224
+ if (typeof onMessage === 'function') {
225
+ onMessage(msg, connection);
226
+ }
227
+ });
228
+
229
+ return {
230
+ connection,
231
+ sendText: (text) => connection.sendText(text),
232
+ sendJson: (data) => sendJson(connection, data),
233
+ sendBinary: (buf) => connection.sendBinary(buf),
234
+ ping: () => connection.ping(),
235
+ identify: () => identify(connection),
236
+ close: () => {
237
+ if (heartbeatTimer) clearInterval(heartbeatTimer);
238
+ return connection.close();
239
+ },
240
+ };
241
+ }
242
+
243
+ const client = {
244
+ request,
245
+ get,
246
+ post,
247
+ put,
248
+ patch,
249
+ delete: del,
250
+ del,
251
+ getJson,
252
+ postJson,
253
+ batch,
254
+ ws,
255
+ wsConnect: ws,
256
+ gateway,
257
+ connectGateway: gateway,
258
+ cache,
259
+ config,
260
+ parseJson,
261
+ parseHeaders,
262
+ isOk,
263
+ };
264
+
265
+ module.exports = client;
package/config.js ADDED
@@ -0,0 +1,42 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
4
+ const config = {
5
+ token: '',
6
+ tokenSource: 'config',
7
+ tokenFile: 'list.txt',
8
+ gatewayUrl: 'wss://gateway.discord.gg/?v=10&encoding=json',
9
+ getToken(source) {
10
+ const selectedSource = source || config.tokenSource;
11
+ if (selectedSource === 'file') {
12
+ const filePath = path.resolve(process.cwd(), config.tokenFile);
13
+ if (fs.existsSync(filePath)) {
14
+ const lines = fs
15
+ .readFileSync(filePath, 'utf-8')
16
+ .split(/\r?\n/)
17
+ .map((line) => line.trim())
18
+ .filter(Boolean);
19
+ if (lines.length > 0) {
20
+ return lines[0];
21
+ }
22
+ }
23
+ }
24
+ return config.token;
25
+ },
26
+ getTokens(source) {
27
+ const selectedSource = source || config.tokenSource;
28
+ if (selectedSource === 'file') {
29
+ const filePath = path.resolve(process.cwd(), config.tokenFile);
30
+ if (fs.existsSync(filePath)) {
31
+ return fs
32
+ .readFileSync(filePath, 'utf-8')
33
+ .split(/\r?\n/)
34
+ .map((line) => line.trim())
35
+ .filter(Boolean);
36
+ }
37
+ }
38
+ return config.token ? [config.token] : [];
39
+ },
40
+ };
41
+
42
+ module.exports = config;
package/index.d.ts ADDED
@@ -0,0 +1,74 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /* auto-generated by NAPI-RS */
5
+
6
+ export declare function httpCacheStats(): CacheStats
7
+ export declare function httpCacheClear(): void
8
+ export declare function httpCacheInvalidate(key: string): boolean
9
+ export declare function httpCacheGet(key: string): HttpResponse | null
10
+ export declare function httpCacheSet(key: string, response: HttpResponse): void
11
+ export declare function httpRequest(url: string, opts?: RequestOptions | undefined | null): Promise<HttpResponse>
12
+ export interface BatchItem {
13
+ url: string
14
+ opts?: RequestOptions
15
+ }
16
+ export interface BatchResult {
17
+ url: string
18
+ response?: HttpResponse
19
+ error?: string
20
+ }
21
+ export declare function httpRequestBatch(items: Array<BatchItem>): Promise<Array<BatchResult>>
22
+ export interface RequestOptions {
23
+ method?: string
24
+ body?: string
25
+ headers?: Array<Array<string>>
26
+ timeoutMs?: number
27
+ forceHttp2?: boolean
28
+ dangerSkipVerify?: boolean
29
+ cache?: boolean
30
+ cacheKey?: string
31
+ forceRefresh?: boolean
32
+ caCert?: string
33
+ tcpNodelay?: boolean
34
+ }
35
+ export interface HttpResponse {
36
+ status: number
37
+ version: string
38
+ headers: string
39
+ body: string
40
+ bodyBytes: number
41
+ elapsedMs: number
42
+ cached: boolean
43
+ }
44
+ export interface CacheStats {
45
+ size: number
46
+ hits: number
47
+ misses: number
48
+ hitRate: number
49
+ }
50
+ export interface WsMessage {
51
+ kind: string
52
+ text?: string
53
+ binary?: string
54
+ }
55
+ export interface WsOptions {
56
+ headers?: Array<Array<string>>
57
+ protocols?: Array<string>
58
+ dangerSkipVerify?: boolean
59
+ maxMessageSize?: number
60
+ maxFrameSize?: number
61
+ writeBufferSize?: number
62
+ maxWriteBufferSize?: number
63
+ acceptUnmaskedFrames?: boolean
64
+ caCert?: string
65
+ tcpNodelay?: boolean
66
+ }
67
+ export declare function wsConnect(url: string, opts: WsOptions | undefined | null, onMessage: (msg: import('./types').WsMessage) => void): Promise<WsConnection>
68
+ export declare class WsConnection {
69
+ sendText(text: string): void
70
+ sendBinary(data: Buffer): void
71
+ ping(): void
72
+ close(): void
73
+ get url(): string
74
+ }
package/index.js ADDED
@@ -0,0 +1,323 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /* prettier-ignore */
4
+
5
+ /* auto-generated by NAPI-RS */
6
+
7
+ const { existsSync, readFileSync } = require('fs')
8
+ const { join } = require('path')
9
+
10
+ const { platform, arch } = process
11
+
12
+ let nativeBinding = null
13
+ let localFileExisted = false
14
+ let loadError = null
15
+
16
+ function isMusl() {
17
+ // For Node 10
18
+ if (!process.report || typeof process.report.getReport !== 'function') {
19
+ try {
20
+ const lddPath = require('child_process').execSync('which ldd').toString().trim()
21
+ return readFileSync(lddPath, 'utf8').includes('musl')
22
+ } catch (e) {
23
+ return true
24
+ }
25
+ } else {
26
+ const { glibcVersionRuntime } = process.report.getReport().header
27
+ return !glibcVersionRuntime
28
+ }
29
+ }
30
+
31
+ switch (platform) {
32
+ case 'android':
33
+ switch (arch) {
34
+ case 'arm64':
35
+ localFileExisted = existsSync(join(__dirname, 'index.android-arm64.node'))
36
+ try {
37
+ if (localFileExisted) {
38
+ nativeBinding = require('./index.android-arm64.node')
39
+ } else {
40
+ nativeBinding = require('miyavsanto-android-arm64')
41
+ }
42
+ } catch (e) {
43
+ loadError = e
44
+ }
45
+ break
46
+ case 'arm':
47
+ localFileExisted = existsSync(join(__dirname, 'index.android-arm-eabi.node'))
48
+ try {
49
+ if (localFileExisted) {
50
+ nativeBinding = require('./index.android-arm-eabi.node')
51
+ } else {
52
+ nativeBinding = require('miyavsanto-android-arm-eabi')
53
+ }
54
+ } catch (e) {
55
+ loadError = e
56
+ }
57
+ break
58
+ default:
59
+ throw new Error(`Unsupported architecture on Android ${arch}`)
60
+ }
61
+ break
62
+ case 'win32':
63
+ switch (arch) {
64
+ case 'x64':
65
+ localFileExisted = existsSync(
66
+ join(__dirname, 'index.win32-x64-msvc.node')
67
+ )
68
+ try {
69
+ if (localFileExisted) {
70
+ nativeBinding = require('./index.win32-x64-msvc.node')
71
+ } else {
72
+ nativeBinding = require('miyavsanto-win32-x64-msvc')
73
+ }
74
+ } catch (e) {
75
+ loadError = e
76
+ }
77
+ break
78
+ case 'ia32':
79
+ localFileExisted = existsSync(
80
+ join(__dirname, 'index.win32-ia32-msvc.node')
81
+ )
82
+ try {
83
+ if (localFileExisted) {
84
+ nativeBinding = require('./index.win32-ia32-msvc.node')
85
+ } else {
86
+ nativeBinding = require('miyavsanto-win32-ia32-msvc')
87
+ }
88
+ } catch (e) {
89
+ loadError = e
90
+ }
91
+ break
92
+ case 'arm64':
93
+ localFileExisted = existsSync(
94
+ join(__dirname, 'index.win32-arm64-msvc.node')
95
+ )
96
+ try {
97
+ if (localFileExisted) {
98
+ nativeBinding = require('./index.win32-arm64-msvc.node')
99
+ } else {
100
+ nativeBinding = require('miyavsanto-win32-arm64-msvc')
101
+ }
102
+ } catch (e) {
103
+ loadError = e
104
+ }
105
+ break
106
+ default:
107
+ throw new Error(`Unsupported architecture on Windows: ${arch}`)
108
+ }
109
+ break
110
+ case 'darwin':
111
+ localFileExisted = existsSync(join(__dirname, 'index.darwin-universal.node'))
112
+ try {
113
+ if (localFileExisted) {
114
+ nativeBinding = require('./index.darwin-universal.node')
115
+ } else {
116
+ nativeBinding = require('miyavsanto-darwin-universal')
117
+ }
118
+ break
119
+ } catch {}
120
+ switch (arch) {
121
+ case 'x64':
122
+ localFileExisted = existsSync(join(__dirname, 'index.darwin-x64.node'))
123
+ try {
124
+ if (localFileExisted) {
125
+ nativeBinding = require('./index.darwin-x64.node')
126
+ } else {
127
+ nativeBinding = require('miyavsanto-darwin-x64')
128
+ }
129
+ } catch (e) {
130
+ loadError = e
131
+ }
132
+ break
133
+ case 'arm64':
134
+ localFileExisted = existsSync(
135
+ join(__dirname, 'index.darwin-arm64.node')
136
+ )
137
+ try {
138
+ if (localFileExisted) {
139
+ nativeBinding = require('./index.darwin-arm64.node')
140
+ } else {
141
+ nativeBinding = require('miyavsanto-darwin-arm64')
142
+ }
143
+ } catch (e) {
144
+ loadError = e
145
+ }
146
+ break
147
+ default:
148
+ throw new Error(`Unsupported architecture on macOS: ${arch}`)
149
+ }
150
+ break
151
+ case 'freebsd':
152
+ if (arch !== 'x64') {
153
+ throw new Error(`Unsupported architecture on FreeBSD: ${arch}`)
154
+ }
155
+ localFileExisted = existsSync(join(__dirname, 'index.freebsd-x64.node'))
156
+ try {
157
+ if (localFileExisted) {
158
+ nativeBinding = require('./index.freebsd-x64.node')
159
+ } else {
160
+ nativeBinding = require('miyavsanto-freebsd-x64')
161
+ }
162
+ } catch (e) {
163
+ loadError = e
164
+ }
165
+ break
166
+ case 'linux':
167
+ switch (arch) {
168
+ case 'x64':
169
+ if (isMusl()) {
170
+ localFileExisted = existsSync(
171
+ join(__dirname, 'index.linux-x64-musl.node')
172
+ )
173
+ try {
174
+ if (localFileExisted) {
175
+ nativeBinding = require('./index.linux-x64-musl.node')
176
+ } else {
177
+ nativeBinding = require('miyavsanto-linux-x64-musl')
178
+ }
179
+ } catch (e) {
180
+ loadError = e
181
+ }
182
+ } else {
183
+ localFileExisted = existsSync(
184
+ join(__dirname, 'index.linux-x64-gnu.node')
185
+ )
186
+ try {
187
+ if (localFileExisted) {
188
+ nativeBinding = require('./index.linux-x64-gnu.node')
189
+ } else {
190
+ nativeBinding = require('miyavsanto-linux-x64-gnu')
191
+ }
192
+ } catch (e) {
193
+ loadError = e
194
+ }
195
+ }
196
+ break
197
+ case 'arm64':
198
+ if (isMusl()) {
199
+ localFileExisted = existsSync(
200
+ join(__dirname, 'index.linux-arm64-musl.node')
201
+ )
202
+ try {
203
+ if (localFileExisted) {
204
+ nativeBinding = require('./index.linux-arm64-musl.node')
205
+ } else {
206
+ nativeBinding = require('miyavsanto-linux-arm64-musl')
207
+ }
208
+ } catch (e) {
209
+ loadError = e
210
+ }
211
+ } else {
212
+ localFileExisted = existsSync(
213
+ join(__dirname, 'index.linux-arm64-gnu.node')
214
+ )
215
+ try {
216
+ if (localFileExisted) {
217
+ nativeBinding = require('./index.linux-arm64-gnu.node')
218
+ } else {
219
+ nativeBinding = require('miyavsanto-linux-arm64-gnu')
220
+ }
221
+ } catch (e) {
222
+ loadError = e
223
+ }
224
+ }
225
+ break
226
+ case 'arm':
227
+ if (isMusl()) {
228
+ localFileExisted = existsSync(
229
+ join(__dirname, 'index.linux-arm-musleabihf.node')
230
+ )
231
+ try {
232
+ if (localFileExisted) {
233
+ nativeBinding = require('./index.linux-arm-musleabihf.node')
234
+ } else {
235
+ nativeBinding = require('miyavsanto-linux-arm-musleabihf')
236
+ }
237
+ } catch (e) {
238
+ loadError = e
239
+ }
240
+ } else {
241
+ localFileExisted = existsSync(
242
+ join(__dirname, 'index.linux-arm-gnueabihf.node')
243
+ )
244
+ try {
245
+ if (localFileExisted) {
246
+ nativeBinding = require('./index.linux-arm-gnueabihf.node')
247
+ } else {
248
+ nativeBinding = require('miyavsanto-linux-arm-gnueabihf')
249
+ }
250
+ } catch (e) {
251
+ loadError = e
252
+ }
253
+ }
254
+ break
255
+ case 'riscv64':
256
+ if (isMusl()) {
257
+ localFileExisted = existsSync(
258
+ join(__dirname, 'index.linux-riscv64-musl.node')
259
+ )
260
+ try {
261
+ if (localFileExisted) {
262
+ nativeBinding = require('./index.linux-riscv64-musl.node')
263
+ } else {
264
+ nativeBinding = require('miyavsanto-linux-riscv64-musl')
265
+ }
266
+ } catch (e) {
267
+ loadError = e
268
+ }
269
+ } else {
270
+ localFileExisted = existsSync(
271
+ join(__dirname, 'index.linux-riscv64-gnu.node')
272
+ )
273
+ try {
274
+ if (localFileExisted) {
275
+ nativeBinding = require('./index.linux-riscv64-gnu.node')
276
+ } else {
277
+ nativeBinding = require('miyavsanto-linux-riscv64-gnu')
278
+ }
279
+ } catch (e) {
280
+ loadError = e
281
+ }
282
+ }
283
+ break
284
+ case 's390x':
285
+ localFileExisted = existsSync(
286
+ join(__dirname, 'index.linux-s390x-gnu.node')
287
+ )
288
+ try {
289
+ if (localFileExisted) {
290
+ nativeBinding = require('./index.linux-s390x-gnu.node')
291
+ } else {
292
+ nativeBinding = require('miyavsanto-linux-s390x-gnu')
293
+ }
294
+ } catch (e) {
295
+ loadError = e
296
+ }
297
+ break
298
+ default:
299
+ throw new Error(`Unsupported architecture on Linux: ${arch}`)
300
+ }
301
+ break
302
+ default:
303
+ throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`)
304
+ }
305
+
306
+ if (!nativeBinding) {
307
+ if (loadError) {
308
+ throw loadError
309
+ }
310
+ throw new Error(`Failed to load native binding`)
311
+ }
312
+
313
+ const { httpCacheStats, httpCacheClear, httpCacheInvalidate, httpCacheGet, httpCacheSet, httpRequest, httpRequestBatch, WsConnection, wsConnect } = nativeBinding
314
+
315
+ module.exports.httpCacheStats = httpCacheStats
316
+ module.exports.httpCacheClear = httpCacheClear
317
+ module.exports.httpCacheInvalidate = httpCacheInvalidate
318
+ module.exports.httpCacheGet = httpCacheGet
319
+ module.exports.httpCacheSet = httpCacheSet
320
+ module.exports.httpRequest = httpRequest
321
+ module.exports.httpRequestBatch = httpRequestBatch
322
+ module.exports.WsConnection = WsConnection
323
+ module.exports.wsConnect = wsConnect
Binary file
package/package.json CHANGED
@@ -1,6 +1,35 @@
1
1
  {
2
2
  "name": "miyavsanto",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "High performance Rust TLS, HTTP/2, WebSocket and Gateway Client for Node.js",
5
+ "main": "client.js",
6
+ "types": "index.d.ts",
7
+ "files": [
8
+ "client.js",
9
+ "config.js",
10
+ "index.js",
11
+ "index.d.ts",
12
+ "README.md",
13
+ "*.node"
14
+ ],
15
+ "scripts": {
16
+ "build": "napi build --platform --release",
17
+ "build:debug": "napi build --platform",
18
+ "prepublishOnly": "napi build --platform --release",
19
+ "test": "node test.js"
20
+ },
21
+ "keywords": [
22
+ "rust",
23
+ "http2",
24
+ "tls",
25
+ "rustls",
26
+ "websocket",
27
+ "gateway",
28
+ "cache",
29
+ "napi"
30
+ ],
31
+ "license": "MIT",
32
+ "devDependencies": {
33
+ "@napi-rs/cli": "^2"
34
+ }
35
+ }