lonesome-js 0.1.0-beta-ee6d282

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/LICENSE.md ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2026 K024
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,84 @@
1
+ # lonesome-js
2
+
3
+ High-performance programmable reverse proxy bindings for Node.js, built on top of Pingora.
4
+
5
+ [中文文档 (README.zh.md)](./README.zh.md)
6
+
7
+ ## Why lonesome-js
8
+
9
+ - Built on Pingora for modern async proxy performance and reliability.
10
+ - Runtime route updates (`addOrUpdate`) with Node.js without process restarts.
11
+ - Request matching and middleware conditions powered by CEL expressions.
12
+ - `virtual_js` upstream mode for in-process Node.js service composition.
13
+
14
+ ## How It Differs From Traditional Reverse Proxies
15
+
16
+ Most reverse proxies focus on static config files and process-level reload workflows. `lonesome-js` is designed around a runtime API and programmable request flow.
17
+
18
+ ### CEL-Driven Routing and Middleware Logic
19
+
20
+ Instead of limiting logic to fixed directives, routes and middleware conditions can use CEL expressions for matching and value generation.
21
+
22
+ Examples:
23
+ - Route match: `"Method('POST') && PathPrefix('/api') && Query('debug', '1')"`
24
+ - Conditional middleware: `rule: "Header('x-env', 'prod')"`
25
+ - Dynamic value: `expression: "MethodValue() + '-' + QueryValue('id')"`
26
+
27
+ ### `virtual_js` Upstreams
28
+
29
+ Beyond TCP/Unix socket upstreams, `virtual_js` allows requests to be bridged into JavaScript handlers in-process. This makes it possible to build internal adapters and programmable backends without opening extra network ports.
30
+
31
+ ## Quick Start
32
+
33
+ ### 1. Install
34
+
35
+ ```bash
36
+ npm i lonesome-js
37
+ ```
38
+
39
+ ### 2. Start a proxy server
40
+
41
+ ```ts
42
+ import { LonesomeServer } from 'lonesome-js'
43
+
44
+ const server = new LonesomeServer()
45
+
46
+ server.start({
47
+ listeners: [{ kind: 'tcp', addr: '127.0.0.1:8080' }],
48
+ })
49
+ ```
50
+
51
+ ### 3. Add a basic route
52
+
53
+ ```ts
54
+ server.addOrUpdate({
55
+ id: 'basic-proxy',
56
+ matcher: { rule: "PathPrefix('/api')", priority: 50 },
57
+ middlewares: [],
58
+ upstreams: [
59
+ { kind: 'tcp', address: '127.0.0.1:9000' },
60
+ ],
61
+ loadBalancer: { algorithm: 'round_robin' },
62
+ })
63
+ ```
64
+
65
+ ### 4. Hot-update the route at runtime
66
+
67
+ ```ts
68
+ server.addOrUpdate({
69
+ id: 'basic-proxy',
70
+ matcher: { rule: "PathPrefix('/api')", priority: 50 },
71
+ middlewares: [{ type: 'respond', config: { status: 418, body: 'teapot' } }],
72
+ upstreams: [
73
+ { kind: 'tcp', address: '127.0.0.1:9000' },
74
+ ],
75
+ })
76
+ ```
77
+
78
+ ## Documentation
79
+
80
+ - Docs index and LonesomeServer control API: [docs/readme.md](./docs/readme.md)
81
+ - Route lifecycle and hot updates: [docs/route.md](./docs/route.md)
82
+ - CEL expressions: [docs/cel.md](./docs/cel.md)
83
+ - `virtual_js` upstreams: [docs/virtual_js.md](./docs/virtual_js.md)
84
+ - Middlewares: *TODO*
package/README.zh.md ADDED
@@ -0,0 +1,86 @@
1
+ # lonesome-js
2
+
3
+ 基于 Pingora 的 Node.js 高性能可编程反向代理绑定。
4
+
5
+ [English README](./README.md)
6
+
7
+ ## 为什么使用 lonesome-js
8
+
9
+ - 基于 Pingora,具备现代异步代理的性能与稳定性基础。
10
+ - 通过 `addOrUpdate` 支持 Node.js 运行时路由热更新,无需重启进程。
11
+ - 路由匹配与中间件条件由 CEL 表达式驱动。
12
+ - 提供 `virtual_js` upstream,可在进程内接入 Node.js 处理链路。
13
+
14
+ ## 与传统反向代理的设计差异
15
+
16
+ 多数传统反向代理偏向静态配置文件与 reload 流程;`lonesome-js` 更偏向运行时 API 与可编程流量编排。
17
+
18
+ ### 基于 CEL 的匹配与逻辑表达
19
+
20
+ 路由规则、中间件条件和动态值都可以通过 CEL 表达式描述,而不是只能依赖固定指令。
21
+
22
+ 示例:
23
+ - 路由匹配:`"Method('POST') && PathPrefix('/api') && Query('debug', '1')"`
24
+ - 条件中间件:`rule: "Header('x-env', 'prod')"`
25
+ - 动态值:`expression: "MethodValue() + '-' + QueryValue('id')"`
26
+
27
+ ### `virtual_js` 上游能力
28
+
29
+ 除 TCP/Unix socket upstream 外,`virtual_js` 可以把请求桥接到进程内 JavaScript handler。适合构建内部适配层或可编程后端,无需额外暴露网络端口。
30
+
31
+ ## 快速开始
32
+
33
+ ### 1. 安装
34
+
35
+ ```bash
36
+ npm i lonesome-js
37
+ ```
38
+
39
+ ### 2. 启动代理服务
40
+
41
+ ```ts
42
+ import { LonesomeServer } from 'lonesome-js'
43
+
44
+ const server = new LonesomeServer()
45
+
46
+ server.start({
47
+ listeners: [{ kind: 'tcp', addr: '127.0.0.1:8080' }],
48
+ })
49
+ ```
50
+
51
+ ### 3. 添加基础路由
52
+
53
+ ```ts
54
+ server.addOrUpdate({
55
+ id: 'basic-proxy',
56
+ matcher: { rule: "PathPrefix('/api')", priority: 50 },
57
+ middlewares: [],
58
+ upstreams: [
59
+ { kind: 'tcp', address: '127.0.0.1:9000', tls: false, sni: '', weight: 1 },
60
+ ],
61
+ loadBalancer: { algorithm: 'round_robin' },
62
+ })
63
+ ```
64
+
65
+ ### 4. 运行时热更新路由
66
+
67
+ ```ts
68
+ server.addOrUpdate({
69
+ id: 'basic-proxy',
70
+ matcher: { rule: "PathPrefix('/api')", priority: 50 },
71
+ middlewares: [{ type: 'respond', config: { status: 418, body: 'teapot' } }],
72
+ upstreams: [
73
+ { kind: 'tcp', address: '127.0.0.1:9000', tls: false, sni: '', weight: 1 },
74
+ ],
75
+ })
76
+ ```
77
+
78
+ ## 文档
79
+
80
+ 以下 `docs/` 文档当前为英文:
81
+
82
+ - 文档总览与 LonesomeServer 控制 API: [docs/readme.md](./docs/readme.md)
83
+ - 路由管理与热更新: [docs/route.md](./docs/route.md)
84
+ - CEL 表达式: [docs/cel.md](./docs/cel.md)
85
+ - `virtual_js` upstream: [docs/virtual_js.md](./docs/virtual_js.md)
86
+ - 中间件:*TODO*
@@ -0,0 +1,69 @@
1
+ /* auto-generated by NAPI-RS */
2
+ /* eslint-disable */
3
+ export declare class LonesomeServer {
4
+ constructor()
5
+ start(startup: StartupConfig): void
6
+ stop(): void
7
+ addOrUpdate(route: RouteConfig): void
8
+ remove(routeId: string): boolean
9
+ status(): ServerStatus
10
+ }
11
+
12
+ export interface LoadBalancerConfig {
13
+ algorithm?: string
14
+ maxIterations?: number
15
+ hashKeyRule?: string
16
+ }
17
+
18
+ export interface MiddlewareConfig {
19
+ type: string
20
+ config: any
21
+ }
22
+
23
+ export declare function purgeRouteCache(routeId: string): Promise<void>
24
+
25
+ export declare function registerVirtualListener(key: string, onEvent: (arg0: string, arg1: string, arg2: Buffer) => void): void
26
+
27
+ export interface RouteConfig {
28
+ id: string
29
+ matcher: RouteMatcherConfig
30
+ middlewares: Array<MiddlewareConfig>
31
+ upstreams: Array<UpstreamConfig>
32
+ loadBalancer?: LoadBalancerConfig
33
+ }
34
+
35
+ export interface RouteMatcherConfig {
36
+ rule: string
37
+ priority?: number
38
+ }
39
+
40
+ export interface ServerStatus {
41
+ running: boolean
42
+ routeCount: number
43
+ }
44
+
45
+ export interface StartupConfig {
46
+ threads?: number
47
+ workStealing?: boolean
48
+ listeners: StartupListenerConfig[]
49
+ }
50
+
51
+ export interface StartupListenerConfig {
52
+ kind: 'tcp' | 'tls' | 'unix'
53
+ addr: string
54
+ certPath?: string
55
+ keyPath?: string
56
+ }
57
+
58
+ export declare function unregisterVirtualListener(key: string): boolean
59
+
60
+ export interface UpstreamConfig {
61
+ kind?: 'tcp' | 'unix' | 'virtual_js'
62
+ address: string
63
+ tls?: boolean
64
+ h2c?: boolean
65
+ sni?: string
66
+ weight?: number
67
+ }
68
+
69
+ export declare function virtualPushEvent(kind: string, connId: string, data?: Buffer | undefined | null, message?: string | undefined | null): void
package/dist/index.js ADDED
@@ -0,0 +1,587 @@
1
+ // prettier-ignore
2
+ /* eslint-disable */
3
+ // @ts-nocheck
4
+ /* auto-generated by NAPI-RS */
5
+
6
+ import { createRequire } from 'node:module'
7
+ const require = createRequire(import.meta.url)
8
+ const __dirname = new URL('.', import.meta.url).pathname
9
+
10
+ const { readFileSync } = require('node:fs')
11
+ let nativeBinding = null
12
+ const loadErrors = []
13
+
14
+ const isMusl = () => {
15
+ let musl = false
16
+ if (process.platform === 'linux') {
17
+ musl = isMuslFromFilesystem()
18
+ if (musl === null) {
19
+ musl = isMuslFromReport()
20
+ }
21
+ if (musl === null) {
22
+ musl = isMuslFromChildProcess()
23
+ }
24
+ }
25
+ return musl
26
+ }
27
+
28
+ const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-')
29
+
30
+ const isMuslFromFilesystem = () => {
31
+ try {
32
+ return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl')
33
+ } catch {
34
+ return null
35
+ }
36
+ }
37
+
38
+ const isMuslFromReport = () => {
39
+ let report = null
40
+ if (typeof process.report?.getReport === 'function') {
41
+ process.report.excludeNetwork = true
42
+ report = process.report.getReport()
43
+ }
44
+ if (!report) {
45
+ return null
46
+ }
47
+ if (report.header && report.header.glibcVersionRuntime) {
48
+ return false
49
+ }
50
+ if (Array.isArray(report.sharedObjects)) {
51
+ if (report.sharedObjects.some(isFileMusl)) {
52
+ return true
53
+ }
54
+ }
55
+ return false
56
+ }
57
+
58
+ const isMuslFromChildProcess = () => {
59
+ try {
60
+ return require('child_process').execSync('ldd --version', { encoding: 'utf8' }).includes('musl')
61
+ } catch (e) {
62
+ // If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
63
+ return false
64
+ }
65
+ }
66
+
67
+ function requireNative() {
68
+ if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
69
+ try {
70
+ return require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
71
+ } catch (err) {
72
+ loadErrors.push(err)
73
+ }
74
+ } else if (process.platform === 'android') {
75
+ if (process.arch === 'arm64') {
76
+ try {
77
+ return require('./lonesome-js.android-arm64.node')
78
+ } catch (e) {
79
+ loadErrors.push(e)
80
+ }
81
+ try {
82
+ const binding = require('lonesome-js-android-arm64')
83
+ const bindingPackageVersion = require('lonesome-js-android-arm64/package.json').version
84
+ if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
85
+ throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
86
+ }
87
+ return binding
88
+ } catch (e) {
89
+ loadErrors.push(e)
90
+ }
91
+ } else if (process.arch === 'arm') {
92
+ try {
93
+ return require('./lonesome-js.android-arm-eabi.node')
94
+ } catch (e) {
95
+ loadErrors.push(e)
96
+ }
97
+ try {
98
+ const binding = require('lonesome-js-android-arm-eabi')
99
+ const bindingPackageVersion = require('lonesome-js-android-arm-eabi/package.json').version
100
+ if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
101
+ throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
102
+ }
103
+ return binding
104
+ } catch (e) {
105
+ loadErrors.push(e)
106
+ }
107
+ } else {
108
+ loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`))
109
+ }
110
+ } else if (process.platform === 'win32') {
111
+ if (process.arch === 'x64') {
112
+ if (process.config?.variables?.shlib_suffix === 'dll.a' || process.config?.variables?.node_target_type === 'shared_library') {
113
+ try {
114
+ return require('./lonesome-js.win32-x64-gnu.node')
115
+ } catch (e) {
116
+ loadErrors.push(e)
117
+ }
118
+ try {
119
+ const binding = require('lonesome-js-win32-x64-gnu')
120
+ const bindingPackageVersion = require('lonesome-js-win32-x64-gnu/package.json').version
121
+ if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
122
+ throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
123
+ }
124
+ return binding
125
+ } catch (e) {
126
+ loadErrors.push(e)
127
+ }
128
+ } else {
129
+ try {
130
+ return require('./lonesome-js.win32-x64-msvc.node')
131
+ } catch (e) {
132
+ loadErrors.push(e)
133
+ }
134
+ try {
135
+ const binding = require('lonesome-js-win32-x64-msvc')
136
+ const bindingPackageVersion = require('lonesome-js-win32-x64-msvc/package.json').version
137
+ if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
138
+ throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
139
+ }
140
+ return binding
141
+ } catch (e) {
142
+ loadErrors.push(e)
143
+ }
144
+ }
145
+ } else if (process.arch === 'ia32') {
146
+ try {
147
+ return require('./lonesome-js.win32-ia32-msvc.node')
148
+ } catch (e) {
149
+ loadErrors.push(e)
150
+ }
151
+ try {
152
+ const binding = require('lonesome-js-win32-ia32-msvc')
153
+ const bindingPackageVersion = require('lonesome-js-win32-ia32-msvc/package.json').version
154
+ if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
155
+ throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
156
+ }
157
+ return binding
158
+ } catch (e) {
159
+ loadErrors.push(e)
160
+ }
161
+ } else if (process.arch === 'arm64') {
162
+ try {
163
+ return require('./lonesome-js.win32-arm64-msvc.node')
164
+ } catch (e) {
165
+ loadErrors.push(e)
166
+ }
167
+ try {
168
+ const binding = require('lonesome-js-win32-arm64-msvc')
169
+ const bindingPackageVersion = require('lonesome-js-win32-arm64-msvc/package.json').version
170
+ if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
171
+ throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
172
+ }
173
+ return binding
174
+ } catch (e) {
175
+ loadErrors.push(e)
176
+ }
177
+ } else {
178
+ loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`))
179
+ }
180
+ } else if (process.platform === 'darwin') {
181
+ try {
182
+ return require('./lonesome-js.darwin-universal.node')
183
+ } catch (e) {
184
+ loadErrors.push(e)
185
+ }
186
+ try {
187
+ const binding = require('lonesome-js-darwin-universal')
188
+ const bindingPackageVersion = require('lonesome-js-darwin-universal/package.json').version
189
+ if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
190
+ throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
191
+ }
192
+ return binding
193
+ } catch (e) {
194
+ loadErrors.push(e)
195
+ }
196
+ if (process.arch === 'x64') {
197
+ try {
198
+ return require('./lonesome-js.darwin-x64.node')
199
+ } catch (e) {
200
+ loadErrors.push(e)
201
+ }
202
+ try {
203
+ const binding = require('lonesome-js-darwin-x64')
204
+ const bindingPackageVersion = require('lonesome-js-darwin-x64/package.json').version
205
+ if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
206
+ throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
207
+ }
208
+ return binding
209
+ } catch (e) {
210
+ loadErrors.push(e)
211
+ }
212
+ } else if (process.arch === 'arm64') {
213
+ try {
214
+ return require('./lonesome-js.darwin-arm64.node')
215
+ } catch (e) {
216
+ loadErrors.push(e)
217
+ }
218
+ try {
219
+ const binding = require('lonesome-js-darwin-arm64')
220
+ const bindingPackageVersion = require('lonesome-js-darwin-arm64/package.json').version
221
+ if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
222
+ throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
223
+ }
224
+ return binding
225
+ } catch (e) {
226
+ loadErrors.push(e)
227
+ }
228
+ } else {
229
+ loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`))
230
+ }
231
+ } else if (process.platform === 'freebsd') {
232
+ if (process.arch === 'x64') {
233
+ try {
234
+ return require('./lonesome-js.freebsd-x64.node')
235
+ } catch (e) {
236
+ loadErrors.push(e)
237
+ }
238
+ try {
239
+ const binding = require('lonesome-js-freebsd-x64')
240
+ const bindingPackageVersion = require('lonesome-js-freebsd-x64/package.json').version
241
+ if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
242
+ throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
243
+ }
244
+ return binding
245
+ } catch (e) {
246
+ loadErrors.push(e)
247
+ }
248
+ } else if (process.arch === 'arm64') {
249
+ try {
250
+ return require('./lonesome-js.freebsd-arm64.node')
251
+ } catch (e) {
252
+ loadErrors.push(e)
253
+ }
254
+ try {
255
+ const binding = require('lonesome-js-freebsd-arm64')
256
+ const bindingPackageVersion = require('lonesome-js-freebsd-arm64/package.json').version
257
+ if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
258
+ throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
259
+ }
260
+ return binding
261
+ } catch (e) {
262
+ loadErrors.push(e)
263
+ }
264
+ } else {
265
+ loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`))
266
+ }
267
+ } else if (process.platform === 'linux') {
268
+ if (process.arch === 'x64') {
269
+ if (isMusl()) {
270
+ try {
271
+ return require('./lonesome-js.linux-x64-musl.node')
272
+ } catch (e) {
273
+ loadErrors.push(e)
274
+ }
275
+ try {
276
+ const binding = require('lonesome-js-linux-x64-musl')
277
+ const bindingPackageVersion = require('lonesome-js-linux-x64-musl/package.json').version
278
+ if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
279
+ throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
280
+ }
281
+ return binding
282
+ } catch (e) {
283
+ loadErrors.push(e)
284
+ }
285
+ } else {
286
+ try {
287
+ return require('./lonesome-js.linux-x64-gnu.node')
288
+ } catch (e) {
289
+ loadErrors.push(e)
290
+ }
291
+ try {
292
+ const binding = require('lonesome-js-linux-x64-gnu')
293
+ const bindingPackageVersion = require('lonesome-js-linux-x64-gnu/package.json').version
294
+ if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
295
+ throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
296
+ }
297
+ return binding
298
+ } catch (e) {
299
+ loadErrors.push(e)
300
+ }
301
+ }
302
+ } else if (process.arch === 'arm64') {
303
+ if (isMusl()) {
304
+ try {
305
+ return require('./lonesome-js.linux-arm64-musl.node')
306
+ } catch (e) {
307
+ loadErrors.push(e)
308
+ }
309
+ try {
310
+ const binding = require('lonesome-js-linux-arm64-musl')
311
+ const bindingPackageVersion = require('lonesome-js-linux-arm64-musl/package.json').version
312
+ if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
313
+ throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
314
+ }
315
+ return binding
316
+ } catch (e) {
317
+ loadErrors.push(e)
318
+ }
319
+ } else {
320
+ try {
321
+ return require('./lonesome-js.linux-arm64-gnu.node')
322
+ } catch (e) {
323
+ loadErrors.push(e)
324
+ }
325
+ try {
326
+ const binding = require('lonesome-js-linux-arm64-gnu')
327
+ const bindingPackageVersion = require('lonesome-js-linux-arm64-gnu/package.json').version
328
+ if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
329
+ throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
330
+ }
331
+ return binding
332
+ } catch (e) {
333
+ loadErrors.push(e)
334
+ }
335
+ }
336
+ } else if (process.arch === 'arm') {
337
+ if (isMusl()) {
338
+ try {
339
+ return require('./lonesome-js.linux-arm-musleabihf.node')
340
+ } catch (e) {
341
+ loadErrors.push(e)
342
+ }
343
+ try {
344
+ const binding = require('lonesome-js-linux-arm-musleabihf')
345
+ const bindingPackageVersion = require('lonesome-js-linux-arm-musleabihf/package.json').version
346
+ if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
347
+ throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
348
+ }
349
+ return binding
350
+ } catch (e) {
351
+ loadErrors.push(e)
352
+ }
353
+ } else {
354
+ try {
355
+ return require('./lonesome-js.linux-arm-gnueabihf.node')
356
+ } catch (e) {
357
+ loadErrors.push(e)
358
+ }
359
+ try {
360
+ const binding = require('lonesome-js-linux-arm-gnueabihf')
361
+ const bindingPackageVersion = require('lonesome-js-linux-arm-gnueabihf/package.json').version
362
+ if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
363
+ throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
364
+ }
365
+ return binding
366
+ } catch (e) {
367
+ loadErrors.push(e)
368
+ }
369
+ }
370
+ } else if (process.arch === 'loong64') {
371
+ if (isMusl()) {
372
+ try {
373
+ return require('./lonesome-js.linux-loong64-musl.node')
374
+ } catch (e) {
375
+ loadErrors.push(e)
376
+ }
377
+ try {
378
+ const binding = require('lonesome-js-linux-loong64-musl')
379
+ const bindingPackageVersion = require('lonesome-js-linux-loong64-musl/package.json').version
380
+ if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
381
+ throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
382
+ }
383
+ return binding
384
+ } catch (e) {
385
+ loadErrors.push(e)
386
+ }
387
+ } else {
388
+ try {
389
+ return require('./lonesome-js.linux-loong64-gnu.node')
390
+ } catch (e) {
391
+ loadErrors.push(e)
392
+ }
393
+ try {
394
+ const binding = require('lonesome-js-linux-loong64-gnu')
395
+ const bindingPackageVersion = require('lonesome-js-linux-loong64-gnu/package.json').version
396
+ if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
397
+ throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
398
+ }
399
+ return binding
400
+ } catch (e) {
401
+ loadErrors.push(e)
402
+ }
403
+ }
404
+ } else if (process.arch === 'riscv64') {
405
+ if (isMusl()) {
406
+ try {
407
+ return require('./lonesome-js.linux-riscv64-musl.node')
408
+ } catch (e) {
409
+ loadErrors.push(e)
410
+ }
411
+ try {
412
+ const binding = require('lonesome-js-linux-riscv64-musl')
413
+ const bindingPackageVersion = require('lonesome-js-linux-riscv64-musl/package.json').version
414
+ if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
415
+ throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
416
+ }
417
+ return binding
418
+ } catch (e) {
419
+ loadErrors.push(e)
420
+ }
421
+ } else {
422
+ try {
423
+ return require('./lonesome-js.linux-riscv64-gnu.node')
424
+ } catch (e) {
425
+ loadErrors.push(e)
426
+ }
427
+ try {
428
+ const binding = require('lonesome-js-linux-riscv64-gnu')
429
+ const bindingPackageVersion = require('lonesome-js-linux-riscv64-gnu/package.json').version
430
+ if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
431
+ throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
432
+ }
433
+ return binding
434
+ } catch (e) {
435
+ loadErrors.push(e)
436
+ }
437
+ }
438
+ } else if (process.arch === 'ppc64') {
439
+ try {
440
+ return require('./lonesome-js.linux-ppc64-gnu.node')
441
+ } catch (e) {
442
+ loadErrors.push(e)
443
+ }
444
+ try {
445
+ const binding = require('lonesome-js-linux-ppc64-gnu')
446
+ const bindingPackageVersion = require('lonesome-js-linux-ppc64-gnu/package.json').version
447
+ if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
448
+ throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
449
+ }
450
+ return binding
451
+ } catch (e) {
452
+ loadErrors.push(e)
453
+ }
454
+ } else if (process.arch === 's390x') {
455
+ try {
456
+ return require('./lonesome-js.linux-s390x-gnu.node')
457
+ } catch (e) {
458
+ loadErrors.push(e)
459
+ }
460
+ try {
461
+ const binding = require('lonesome-js-linux-s390x-gnu')
462
+ const bindingPackageVersion = require('lonesome-js-linux-s390x-gnu/package.json').version
463
+ if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
464
+ throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
465
+ }
466
+ return binding
467
+ } catch (e) {
468
+ loadErrors.push(e)
469
+ }
470
+ } else {
471
+ loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`))
472
+ }
473
+ } else if (process.platform === 'openharmony') {
474
+ if (process.arch === 'arm64') {
475
+ try {
476
+ return require('./lonesome-js.openharmony-arm64.node')
477
+ } catch (e) {
478
+ loadErrors.push(e)
479
+ }
480
+ try {
481
+ const binding = require('lonesome-js-openharmony-arm64')
482
+ const bindingPackageVersion = require('lonesome-js-openharmony-arm64/package.json').version
483
+ if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
484
+ throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
485
+ }
486
+ return binding
487
+ } catch (e) {
488
+ loadErrors.push(e)
489
+ }
490
+ } else if (process.arch === 'x64') {
491
+ try {
492
+ return require('./lonesome-js.openharmony-x64.node')
493
+ } catch (e) {
494
+ loadErrors.push(e)
495
+ }
496
+ try {
497
+ const binding = require('lonesome-js-openharmony-x64')
498
+ const bindingPackageVersion = require('lonesome-js-openharmony-x64/package.json').version
499
+ if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
500
+ throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
501
+ }
502
+ return binding
503
+ } catch (e) {
504
+ loadErrors.push(e)
505
+ }
506
+ } else if (process.arch === 'arm') {
507
+ try {
508
+ return require('./lonesome-js.openharmony-arm.node')
509
+ } catch (e) {
510
+ loadErrors.push(e)
511
+ }
512
+ try {
513
+ const binding = require('lonesome-js-openharmony-arm')
514
+ const bindingPackageVersion = require('lonesome-js-openharmony-arm/package.json').version
515
+ if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
516
+ throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
517
+ }
518
+ return binding
519
+ } catch (e) {
520
+ loadErrors.push(e)
521
+ }
522
+ } else {
523
+ loadErrors.push(new Error(`Unsupported architecture on OpenHarmony: ${process.arch}`))
524
+ }
525
+ } else {
526
+ loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`))
527
+ }
528
+ }
529
+
530
+ nativeBinding = requireNative()
531
+
532
+ if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
533
+ let wasiBinding = null
534
+ let wasiBindingError = null
535
+ try {
536
+ wasiBinding = require('./lonesome-js.wasi.cjs')
537
+ nativeBinding = wasiBinding
538
+ } catch (err) {
539
+ if (process.env.NAPI_RS_FORCE_WASI) {
540
+ wasiBindingError = err
541
+ }
542
+ }
543
+ if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
544
+ try {
545
+ wasiBinding = require('lonesome-js-wasm32-wasi')
546
+ nativeBinding = wasiBinding
547
+ } catch (err) {
548
+ if (process.env.NAPI_RS_FORCE_WASI) {
549
+ if (!wasiBindingError) {
550
+ wasiBindingError = err
551
+ } else {
552
+ wasiBindingError.cause = err
553
+ }
554
+ loadErrors.push(err)
555
+ }
556
+ }
557
+ }
558
+ if (process.env.NAPI_RS_FORCE_WASI === 'error' && !wasiBinding) {
559
+ const error = new Error('WASI binding not found and NAPI_RS_FORCE_WASI is set to error')
560
+ error.cause = wasiBindingError
561
+ throw error
562
+ }
563
+ }
564
+
565
+ if (!nativeBinding) {
566
+ if (loadErrors.length > 0) {
567
+ throw new Error(
568
+ `Cannot find native binding. ` +
569
+ `npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` +
570
+ 'Please try `npm i` again after removing both package-lock.json and node_modules directory.',
571
+ {
572
+ cause: loadErrors.reduce((err, cur) => {
573
+ cur.cause = err
574
+ return cur
575
+ }),
576
+ },
577
+ )
578
+ }
579
+ throw new Error(`Failed to load native binding`)
580
+ }
581
+
582
+ const { LonesomeServer, purgeRouteCache, registerVirtualListener, unregisterVirtualListener, virtualPushEvent } = nativeBinding
583
+ export { LonesomeServer }
584
+ export { purgeRouteCache }
585
+ export { registerVirtualListener }
586
+ export { unregisterVirtualListener }
587
+ export { virtualPushEvent }
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "lonesome-js",
3
+ "version": "0.1.0-beta-ee6d282",
4
+ "type": "module",
5
+ "main": "dist/index.js",
6
+ "license": "MIT",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "default": "./dist/index.js"
11
+ }
12
+ },
13
+ "napi": {
14
+ "binaryName": "lonesome-js",
15
+ "targets": [
16
+ "aarch64-apple-darwin",
17
+ "x86_64-pc-windows-msvc",
18
+ "x86_64-unknown-linux-gnu"
19
+ ]
20
+ },
21
+ "files": [
22
+ "dist/"
23
+ ],
24
+ "engines": {
25
+ "node": ">= 12.22.0 < 13 || >= 14.17.0 < 15 || >= 15.12.0 < 16 || >= 16.0.0"
26
+ },
27
+ "scripts": {
28
+ "artifacts": "napi artifacts",
29
+ "build": "napi build --esm --output-dir dist --platform --release",
30
+ "build:debug": "napi build --esm --output-dir dist --platform",
31
+ "bench:list-suites": "tsx bench/index.ts list-suites",
32
+ "bench:setup": "tsx bench/setup.ts start",
33
+ "bench": "tsx bench/index.ts run",
34
+ "version": "napi version",
35
+ "lint": "tsc -b --noEmit",
36
+ "test": "tsx --test 'e2e-test/**/*.test.ts'"
37
+ },
38
+ "devDependencies": {
39
+ "@napi-rs/cli": "^3.6.0",
40
+ "@types/k6": "^1.7.0",
41
+ "@types/node": "^25.5.2",
42
+ "jose": "^6.2.2",
43
+ "tsx": "^4.21.0",
44
+ "typescript": "^5.9.3",
45
+ "zx": "^8.8.5"
46
+ }
47
+ }