@fluojs/websockets 1.0.3 → 1.0.4
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.ko.md +1 -1
- package/README.md +1 -1
- package/dist/bun/bun-service.d.ts +1 -2
- package/dist/bun/bun-service.d.ts.map +1 -1
- package/dist/bun/bun-service.js +7 -23
- package/dist/cloudflare-workers/cloudflare-workers-service.d.ts +1 -2
- package/dist/cloudflare-workers/cloudflare-workers-service.d.ts.map +1 -1
- package/dist/cloudflare-workers/cloudflare-workers-service.js +7 -23
- package/dist/deno/deno-service.d.ts +1 -2
- package/dist/deno/deno-service.d.ts.map +1 -1
- package/dist/deno/deno-service.js +7 -23
- package/dist/internal/shared.d.ts +22 -0
- package/dist/internal/shared.d.ts.map +1 -1
- package/dist/internal/shared.js +37 -0
- package/dist/node/node-service.d.ts.map +1 -1
- package/dist/node/node-service.js +13 -6
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +7 -7
package/README.ko.md
CHANGED
|
@@ -67,7 +67,7 @@ class MetricsGateway {
|
|
|
67
67
|
```
|
|
68
68
|
|
|
69
69
|
### Server-Backed Node adapter
|
|
70
|
-
Server-backed Node adapter(Node.js, Express, Fastify)에서는 전용 listener port를 사용할 수 있습니다. Fetch-style runtime(`@fluojs/websockets/bun`, `@fluojs/websockets/deno`, `@fluojs/websockets/cloudflare-workers`)은 `serverBacked`를 거부합니다.
|
|
70
|
+
Server-backed Node adapter(Node.js, Express, Fastify)에서는 전용 listener port를 사용할 수 있습니다. 테스트나 동적 host에서 운영체제가 ephemeral listener port를 원자적으로 할당하게 하려면 `serverBacked.port: 0`을 사용합니다. Fetch-style runtime(`@fluojs/websockets/bun`, `@fluojs/websockets/deno`, `@fluojs/websockets/cloudflare-workers`)은 `serverBacked`를 거부합니다.
|
|
71
71
|
|
|
72
72
|
```typescript
|
|
73
73
|
@WebSocketGateway({
|
package/README.md
CHANGED
|
@@ -67,7 +67,7 @@ class MetricsGateway {
|
|
|
67
67
|
```
|
|
68
68
|
|
|
69
69
|
### Server-Backed Node Adapters
|
|
70
|
-
For server-backed Node adapters (Node.js, Express, Fastify), you can opt into a dedicated listener port. Fetch-style runtimes (`@fluojs/websockets/bun`, `@fluojs/websockets/deno`, and `@fluojs/websockets/cloudflare-workers`) reject `serverBacked`.
|
|
70
|
+
For server-backed Node adapters (Node.js, Express, Fastify), you can opt into a dedicated listener port. Use `serverBacked.port: 0` when tests or dynamic hosts should let the operating system allocate an ephemeral listener port atomically. Fetch-style runtimes (`@fluojs/websockets/bun`, `@fluojs/websockets/deno`, and `@fluojs/websockets/cloudflare-workers`) reject `serverBacked`.
|
|
71
71
|
|
|
72
72
|
```typescript
|
|
73
73
|
@WebSocketGateway({
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Container } from '@fluojs/di';
|
|
2
|
-
import type { ApplicationLogger, CompiledModule, OnApplicationBootstrap, OnApplicationShutdown, OnModuleDestroy } from '@fluojs/runtime';
|
|
3
2
|
import type { HttpApplicationAdapter } from '@fluojs/http';
|
|
3
|
+
import type { ApplicationLogger, CompiledModule, OnApplicationBootstrap, OnApplicationShutdown, OnModuleDestroy } from '@fluojs/runtime';
|
|
4
4
|
import type { WebSocketRoomService } from '../types.js';
|
|
5
5
|
import type { WebSocketModuleOptions } from './bun-types.js';
|
|
6
6
|
/**
|
|
@@ -22,7 +22,6 @@ export declare class BunWebSocketGatewayLifecycleService implements OnApplicatio
|
|
|
22
22
|
private readonly socketStates;
|
|
23
23
|
constructor(runtimeContainer: Container, compiledModules: readonly CompiledModule[], logger: ApplicationLogger, adapter: HttpApplicationAdapter, moduleOptions: WebSocketModuleOptions);
|
|
24
24
|
onApplicationBootstrap(): Promise<void>;
|
|
25
|
-
private assertNoServerBackedGatewayOptIn;
|
|
26
25
|
onApplicationShutdown(): Promise<void>;
|
|
27
26
|
onModuleDestroy(): Promise<void>;
|
|
28
27
|
private createBinding;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bun-service.d.ts","sourceRoot":"","sources":["../../src/bun/bun-service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"bun-service.d.ts","sourceRoot":"","sources":["../../src/bun/bun-service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAezI,OAAO,KAAK,EAEV,oBAAoB,EAErB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAKU,sBAAsB,EAC3C,MAAM,gBAAgB,CAAC;AAyExB;;GAEG;AACH,qBACa,mCACX,YAAW,sBAAsB,EAAE,qBAAqB,EAAE,eAAe,EAAE,oBAAoB;IAY7F,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IACjC,OAAO,CAAC,QAAQ,CAAC,eAAe;IAChC,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,aAAa;IAdhC,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAC,wBAAwB,CAA4B;IACrE,OAAO,CAAC,0BAA0B,CAAK;IACvC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAkC;IAC9D,OAAO,CAAC,eAAe,CAA4B;IACnD,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAwD;IACvF,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAkC;IAC9D,OAAO,CAAC,QAAQ,CAAC,YAAY,CAA6C;gBAGvD,gBAAgB,EAAE,SAAS,EAC3B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C,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI;IAmB9C,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI;IAc/C,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI;IA4BjE,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC;IAU/C,OAAO,CAAC,gBAAgB;CAiBzB"}
|
package/dist/bun/bun-service.js
CHANGED
|
@@ -6,7 +6,7 @@ function _setFunctionName(e, t, n) { "symbol" == typeof t && (t = (t = t.descrip
|
|
|
6
6
|
function _checkInRHS(e) { if (Object(e) !== e) throw TypeError("right-hand side of 'in' should be an object, got " + (null !== e ? typeof e : "null")); return e; }
|
|
7
7
|
import { Inject } from '@fluojs/core';
|
|
8
8
|
import { APPLICATION_LOGGER, COMPILED_MODULES, HTTP_APPLICATION_ADAPTER, RUNTIME_CONTAINER } from '@fluojs/runtime/internal';
|
|
9
|
-
import { dispatchGatewayDisconnect, dispatchGatewayMessage,
|
|
9
|
+
import { assertNoFetchStyleServerBackedGatewayOptIn, discoverGatewayDescriptors, dispatchGatewayDisconnect, dispatchGatewayMessage, isFinitePositiveInteger, normalizeGatewayPath, resolveGatewayInstance, resolveSupportedFetchStyleRealtimeCapability, runGatewayHandlers } from '../internal/shared.js';
|
|
10
10
|
import { WEBSOCKET_OPTIONS_INTERNAL } from '../options-token.internal.js';
|
|
11
11
|
const DEFAULT_MAX_PENDING_MESSAGES_PER_SOCKET = 256;
|
|
12
12
|
const DEFAULT_MAX_WEBSOCKET_CONNECTIONS = 1_000;
|
|
@@ -16,19 +16,6 @@ const LIFECYCLE_LOG_CONTEXT = 'WebSocketGatewayLifecycleService';
|
|
|
16
16
|
function hasBunWebSocketBindingHost(adapter) {
|
|
17
17
|
return 'configureWebSocketBinding' in adapter && typeof adapter.configureWebSocketBinding === 'function';
|
|
18
18
|
}
|
|
19
|
-
function resolveSupportedFetchStyleRealtimeCapability(adapter) {
|
|
20
|
-
if (typeof adapter.getRealtimeCapability !== 'function') {
|
|
21
|
-
throw new Error('Bun WebSocket gateway bootstrap requires an HTTP adapter with getRealtimeCapability(). Use @fluojs/platform-bun together with @fluojs/websockets/bun.');
|
|
22
|
-
}
|
|
23
|
-
const capability = adapter.getRealtimeCapability();
|
|
24
|
-
if (capability.kind !== 'fetch-style' || capability.contract !== 'raw-websocket-expansion') {
|
|
25
|
-
throw new Error('Bun WebSocket gateway bootstrap requires a fetch-style raw-websocket-expansion realtime capability from the selected HTTP adapter.');
|
|
26
|
-
}
|
|
27
|
-
if (capability.support !== 'supported') {
|
|
28
|
-
throw new Error(`Bun WebSocket gateway bootstrap requires supported fetch-style websocket hosting. ${capability.reason}`);
|
|
29
|
-
}
|
|
30
|
-
return capability;
|
|
31
|
-
}
|
|
32
19
|
function isHttpExceptionLike(error) {
|
|
33
20
|
return typeof error === 'object' && error !== null && 'message' in error && 'status' in error;
|
|
34
21
|
}
|
|
@@ -80,21 +67,18 @@ class BunWebSocketGatewayLifecycleService {
|
|
|
80
67
|
if (descriptors.length === 0) {
|
|
81
68
|
return;
|
|
82
69
|
}
|
|
83
|
-
|
|
84
|
-
resolveSupportedFetchStyleRealtimeCapability(this.adapter
|
|
70
|
+
assertNoFetchStyleServerBackedGatewayOptIn(descriptors, 'bun');
|
|
71
|
+
resolveSupportedFetchStyleRealtimeCapability(this.adapter, {
|
|
72
|
+
packageSubpath: 'bun',
|
|
73
|
+
platformPackage: '@fluojs/platform-bun',
|
|
74
|
+
runtimeName: 'Bun'
|
|
75
|
+
});
|
|
85
76
|
if (!hasBunWebSocketBindingHost(this.adapter)) {
|
|
86
77
|
throw new Error('Bun WebSocket gateway bootstrap requires the selected adapter to expose Bun websocket binding configuration. Use @fluojs/platform-bun with @fluojs/websockets/bun.');
|
|
87
78
|
}
|
|
88
79
|
const bunAdapter = this.adapter;
|
|
89
80
|
bunAdapter.configureWebSocketBinding(this.createBinding(descriptors));
|
|
90
81
|
}
|
|
91
|
-
assertNoServerBackedGatewayOptIn(descriptors) {
|
|
92
|
-
const descriptor = descriptors.find(entry => entry.serverBacked !== undefined);
|
|
93
|
-
if (!descriptor) {
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
throw new Error(`@WebSocketGateway({ serverBacked }) is not supported on @fluojs/websockets/bun. Gateway path ${descriptor.path} must use the default fetch-style request-upgrade host instead.`);
|
|
97
|
-
}
|
|
98
82
|
async onApplicationShutdown() {
|
|
99
83
|
await this.shutdown();
|
|
100
84
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Container } from '@fluojs/di';
|
|
2
|
-
import type { ApplicationLogger, CompiledModule, OnApplicationBootstrap, OnApplicationShutdown, OnModuleDestroy } from '@fluojs/runtime';
|
|
3
2
|
import type { HttpApplicationAdapter } from '@fluojs/http';
|
|
3
|
+
import type { ApplicationLogger, CompiledModule, OnApplicationBootstrap, OnApplicationShutdown, OnModuleDestroy } from '@fluojs/runtime';
|
|
4
4
|
import type { WebSocketRoomService } from '../types.js';
|
|
5
5
|
import type { WebSocketModuleOptions } from './cloudflare-workers-types.js';
|
|
6
6
|
/**
|
|
@@ -22,7 +22,6 @@ export declare class CloudflareWorkersWebSocketGatewayLifecycleService implement
|
|
|
22
22
|
private readonly socketStates;
|
|
23
23
|
constructor(runtimeContainer: Container, compiledModules: readonly CompiledModule[], logger: ApplicationLogger, adapter: HttpApplicationAdapter, moduleOptions: WebSocketModuleOptions);
|
|
24
24
|
onApplicationBootstrap(): Promise<void>;
|
|
25
|
-
private assertNoServerBackedGatewayOptIn;
|
|
26
25
|
onApplicationShutdown(): Promise<void>;
|
|
27
26
|
onModuleDestroy(): Promise<void>;
|
|
28
27
|
private createBinding;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cloudflare-workers-service.d.ts","sourceRoot":"","sources":["../../src/cloudflare-workers/cloudflare-workers-service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"cloudflare-workers-service.d.ts","sourceRoot":"","sources":["../../src/cloudflare-workers/cloudflare-workers-service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAgBzI,OAAO,KAAK,EAA8B,oBAAoB,EAA6B,MAAM,aAAa,CAAC;AAC/G,OAAO,KAAK,EAKV,sBAAsB,EACvB,MAAM,+BAA+B,CAAC;AAuEvC;;GAEG;AACH,qBACa,iDACX,YAAW,sBAAsB,EAAE,qBAAqB,EAAE,eAAe,EAAE,oBAAoB;IAY7F,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IACjC,OAAO,CAAC,QAAQ,CAAC,eAAe;IAChC,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,aAAa;IAdhC,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAC,wBAAwB,CAA4B;IACrE,OAAO,CAAC,0BAA0B,CAAK;IACvC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAkC;IAC9D,OAAO,CAAC,eAAe,CAA4B;IACnD,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAgD;IAC/E,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAkC;IAC9D,OAAO,CAAC,QAAQ,CAAC,YAAY,CAA6C;gBAGvD,gBAAgB,EAAE,SAAS,EAC3B,eAAe,EAAE,SAAS,cAAc,E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AAI,EAAE,MAAM,GAAG,IAAI;IAc/C,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI;IA4BjE,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC;IAU/C,OAAO,CAAC,gBAAgB;CAqBzB"}
|
|
@@ -6,7 +6,7 @@ function _setFunctionName(e, t, n) { "symbol" == typeof t && (t = (t = t.descrip
|
|
|
6
6
|
function _checkInRHS(e) { if (Object(e) !== e) throw TypeError("right-hand side of 'in' should be an object, got " + (null !== e ? typeof e : "null")); return e; }
|
|
7
7
|
import { Inject } from '@fluojs/core';
|
|
8
8
|
import { APPLICATION_LOGGER, COMPILED_MODULES, HTTP_APPLICATION_ADAPTER, RUNTIME_CONTAINER } from '@fluojs/runtime/internal';
|
|
9
|
-
import { dispatchGatewayDisconnect, dispatchGatewayMessage,
|
|
9
|
+
import { assertNoFetchStyleServerBackedGatewayOptIn, discoverGatewayDescriptors, dispatchGatewayDisconnect, dispatchGatewayMessage, isFinitePositiveInteger, normalizeGatewayPath, resolveGatewayInstance, resolveSupportedFetchStyleRealtimeCapability, runGatewayHandlers } from '../internal/shared.js';
|
|
10
10
|
import { WEBSOCKET_OPTIONS_INTERNAL } from '../options-token.internal.js';
|
|
11
11
|
const DEFAULT_MAX_PENDING_MESSAGES_PER_SOCKET = 256;
|
|
12
12
|
const DEFAULT_MAX_WEBSOCKET_CONNECTIONS = 1_000;
|
|
@@ -17,19 +17,6 @@ const WEBSOCKET_OPEN_READY_STATE = 1;
|
|
|
17
17
|
function hasCloudflareWorkerWebSocketBindingHost(adapter) {
|
|
18
18
|
return 'configureWebSocketBinding' in adapter && typeof adapter.configureWebSocketBinding === 'function';
|
|
19
19
|
}
|
|
20
|
-
function resolveSupportedFetchStyleRealtimeCapability(adapter) {
|
|
21
|
-
if (typeof adapter.getRealtimeCapability !== 'function') {
|
|
22
|
-
throw new Error('Cloudflare Workers WebSocket gateway bootstrap requires an HTTP adapter with getRealtimeCapability(). Use @fluojs/platform-cloudflare-workers together with @fluojs/websockets/cloudflare-workers.');
|
|
23
|
-
}
|
|
24
|
-
const capability = adapter.getRealtimeCapability();
|
|
25
|
-
if (capability.kind !== 'fetch-style' || capability.contract !== 'raw-websocket-expansion') {
|
|
26
|
-
throw new Error('Cloudflare Workers WebSocket gateway bootstrap requires a fetch-style raw-websocket-expansion realtime capability from the selected HTTP adapter.');
|
|
27
|
-
}
|
|
28
|
-
if (capability.support !== 'supported') {
|
|
29
|
-
throw new Error(`Cloudflare Workers WebSocket gateway bootstrap requires supported fetch-style websocket hosting. ${capability.reason}`);
|
|
30
|
-
}
|
|
31
|
-
return capability;
|
|
32
|
-
}
|
|
33
20
|
function isWebSocketUpgradeRequest(request) {
|
|
34
21
|
return request.headers.get('upgrade')?.toLowerCase() === 'websocket';
|
|
35
22
|
}
|
|
@@ -84,20 +71,17 @@ class CloudflareWorkersWebSocketGatewayLifecycleService {
|
|
|
84
71
|
if (descriptors.length === 0) {
|
|
85
72
|
return;
|
|
86
73
|
}
|
|
87
|
-
|
|
88
|
-
resolveSupportedFetchStyleRealtimeCapability(this.adapter
|
|
74
|
+
assertNoFetchStyleServerBackedGatewayOptIn(descriptors, 'cloudflare-workers');
|
|
75
|
+
resolveSupportedFetchStyleRealtimeCapability(this.adapter, {
|
|
76
|
+
packageSubpath: 'cloudflare-workers',
|
|
77
|
+
platformPackage: '@fluojs/platform-cloudflare-workers',
|
|
78
|
+
runtimeName: 'Cloudflare Workers'
|
|
79
|
+
});
|
|
89
80
|
if (!hasCloudflareWorkerWebSocketBindingHost(this.adapter)) {
|
|
90
81
|
throw new Error('Cloudflare Workers WebSocket gateway bootstrap requires the selected adapter to expose Cloudflare websocket binding configuration. Use @fluojs/platform-cloudflare-workers with @fluojs/websockets/cloudflare-workers.');
|
|
91
82
|
}
|
|
92
83
|
this.adapter.configureWebSocketBinding(this.createBinding(descriptors));
|
|
93
84
|
}
|
|
94
|
-
assertNoServerBackedGatewayOptIn(descriptors) {
|
|
95
|
-
const descriptor = descriptors.find(entry => entry.serverBacked !== undefined);
|
|
96
|
-
if (!descriptor) {
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
throw new Error(`@WebSocketGateway({ serverBacked }) is not supported on @fluojs/websockets/cloudflare-workers. Gateway path ${descriptor.path} must use the default fetch-style request-upgrade host instead.`);
|
|
100
|
-
}
|
|
101
85
|
async onApplicationShutdown() {
|
|
102
86
|
await this.shutdown();
|
|
103
87
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Container } from '@fluojs/di';
|
|
2
|
-
import type { ApplicationLogger, CompiledModule, OnApplicationBootstrap, OnApplicationShutdown, OnModuleDestroy } from '@fluojs/runtime';
|
|
3
2
|
import type { HttpApplicationAdapter } from '@fluojs/http';
|
|
3
|
+
import type { ApplicationLogger, CompiledModule, OnApplicationBootstrap, OnApplicationShutdown, OnModuleDestroy } from '@fluojs/runtime';
|
|
4
4
|
import type { WebSocketRoomService } from '../types.js';
|
|
5
5
|
import type { WebSocketModuleOptions } from './deno-types.js';
|
|
6
6
|
/**
|
|
@@ -22,7 +22,6 @@ export declare class DenoWebSocketGatewayLifecycleService implements OnApplicati
|
|
|
22
22
|
private readonly socketStates;
|
|
23
23
|
constructor(runtimeContainer: Container, compiledModules: readonly CompiledModule[], logger: ApplicationLogger, adapter: HttpApplicationAdapter, moduleOptions: WebSocketModuleOptions);
|
|
24
24
|
onApplicationBootstrap(): Promise<void>;
|
|
25
|
-
private assertNoServerBackedGatewayOptIn;
|
|
26
25
|
onApplicationShutdown(): Promise<void>;
|
|
27
26
|
onModuleDestroy(): Promise<void>;
|
|
28
27
|
private createBinding;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deno-service.d.ts","sourceRoot":"","sources":["../../src/deno/deno-service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YA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EAAE,OAAO,GAAG,IAAI;IA4BjE,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC;IAU/C,OAAO,CAAC,gBAAgB;CAqBzB"}
|
|
@@ -6,7 +6,7 @@ function _setFunctionName(e, t, n) { "symbol" == typeof t && (t = (t = t.descrip
|
|
|
6
6
|
function _checkInRHS(e) { if (Object(e) !== e) throw TypeError("right-hand side of 'in' should be an object, got " + (null !== e ? typeof e : "null")); return e; }
|
|
7
7
|
import { Inject } from '@fluojs/core';
|
|
8
8
|
import { APPLICATION_LOGGER, COMPILED_MODULES, HTTP_APPLICATION_ADAPTER, RUNTIME_CONTAINER } from '@fluojs/runtime/internal';
|
|
9
|
-
import { dispatchGatewayDisconnect, dispatchGatewayMessage,
|
|
9
|
+
import { assertNoFetchStyleServerBackedGatewayOptIn, discoverGatewayDescriptors, dispatchGatewayDisconnect, dispatchGatewayMessage, isFinitePositiveInteger, normalizeGatewayPath, resolveGatewayInstance, resolveSupportedFetchStyleRealtimeCapability, runGatewayHandlers } from '../internal/shared.js';
|
|
10
10
|
import { WEBSOCKET_OPTIONS_INTERNAL } from '../options-token.internal.js';
|
|
11
11
|
const DEFAULT_MAX_PENDING_MESSAGES_PER_SOCKET = 256;
|
|
12
12
|
const DEFAULT_MAX_WEBSOCKET_CONNECTIONS = 1_000;
|
|
@@ -17,19 +17,6 @@ const WEBSOCKET_OPEN_READY_STATE = 1;
|
|
|
17
17
|
function hasDenoWebSocketBindingHost(adapter) {
|
|
18
18
|
return 'configureWebSocketBinding' in adapter && typeof adapter.configureWebSocketBinding === 'function';
|
|
19
19
|
}
|
|
20
|
-
function resolveSupportedFetchStyleRealtimeCapability(adapter) {
|
|
21
|
-
if (typeof adapter.getRealtimeCapability !== 'function') {
|
|
22
|
-
throw new Error('Deno WebSocket gateway bootstrap requires an HTTP adapter with getRealtimeCapability(). Use @fluojs/platform-deno together with @fluojs/websockets/deno.');
|
|
23
|
-
}
|
|
24
|
-
const capability = adapter.getRealtimeCapability();
|
|
25
|
-
if (capability.kind !== 'fetch-style' || capability.contract !== 'raw-websocket-expansion') {
|
|
26
|
-
throw new Error('Deno WebSocket gateway bootstrap requires a fetch-style raw-websocket-expansion realtime capability from the selected HTTP adapter.');
|
|
27
|
-
}
|
|
28
|
-
if (capability.support !== 'supported') {
|
|
29
|
-
throw new Error(`Deno WebSocket gateway bootstrap requires supported fetch-style websocket hosting. ${capability.reason}`);
|
|
30
|
-
}
|
|
31
|
-
return capability;
|
|
32
|
-
}
|
|
33
20
|
function isWebSocketUpgradeRequest(request) {
|
|
34
21
|
return request.headers.get('upgrade')?.toLowerCase() === 'websocket';
|
|
35
22
|
}
|
|
@@ -91,20 +78,17 @@ class DenoWebSocketGatewayLifecycleService {
|
|
|
91
78
|
if (descriptors.length === 0) {
|
|
92
79
|
return;
|
|
93
80
|
}
|
|
94
|
-
|
|
95
|
-
resolveSupportedFetchStyleRealtimeCapability(this.adapter
|
|
81
|
+
assertNoFetchStyleServerBackedGatewayOptIn(descriptors, 'deno');
|
|
82
|
+
resolveSupportedFetchStyleRealtimeCapability(this.adapter, {
|
|
83
|
+
packageSubpath: 'deno',
|
|
84
|
+
platformPackage: '@fluojs/platform-deno',
|
|
85
|
+
runtimeName: 'Deno'
|
|
86
|
+
});
|
|
96
87
|
if (!hasDenoWebSocketBindingHost(this.adapter)) {
|
|
97
88
|
throw new Error('Deno WebSocket gateway bootstrap requires the selected adapter to expose Deno websocket binding configuration. Use @fluojs/platform-deno with @fluojs/websockets/deno.');
|
|
98
89
|
}
|
|
99
90
|
this.adapter.configureWebSocketBinding(this.createBinding(descriptors));
|
|
100
91
|
}
|
|
101
|
-
assertNoServerBackedGatewayOptIn(descriptors) {
|
|
102
|
-
const descriptor = descriptors.find(entry => entry.serverBacked !== undefined);
|
|
103
|
-
if (!descriptor) {
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
throw new Error(`@WebSocketGateway({ serverBacked }) is not supported on @fluojs/websockets/deno. Gateway path ${descriptor.path} must use the default fetch-style request-upgrade host instead.`);
|
|
107
|
-
}
|
|
108
92
|
async onApplicationShutdown() {
|
|
109
93
|
await this.shutdown();
|
|
110
94
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Token } from '@fluojs/core';
|
|
2
2
|
import type { Container } from '@fluojs/di';
|
|
3
|
+
import type { FetchStyleHttpAdapterRealtimeCapability, HttpApplicationAdapter } from '@fluojs/http';
|
|
3
4
|
import type { ApplicationLogger, CompiledModule } from '@fluojs/runtime';
|
|
4
5
|
import type { WebSocketGatewayDescriptor, WebSocketGatewayHandlerDescriptor } from '../types.js';
|
|
5
6
|
/**
|
|
@@ -29,6 +30,12 @@ export type ParsedWebSocketMessage = {
|
|
|
29
30
|
* Defines the shared web socket incoming message type.
|
|
30
31
|
*/
|
|
31
32
|
export type SharedWebSocketIncomingMessage = ArrayBuffer | ArrayBufferView | Uint8Array[] | string;
|
|
33
|
+
/** Runtime metadata used to validate fetch-style websocket adapter boundaries. */
|
|
34
|
+
export interface FetchStyleRealtimeBoundaryOptions {
|
|
35
|
+
packageSubpath: string;
|
|
36
|
+
platformPackage: string;
|
|
37
|
+
runtimeName: string;
|
|
38
|
+
}
|
|
32
39
|
/**
|
|
33
40
|
* Is finite positive integer.
|
|
34
41
|
*
|
|
@@ -43,6 +50,21 @@ export declare function isFinitePositiveInteger(value: unknown): value is number
|
|
|
43
50
|
* @returns The normalize gateway path result.
|
|
44
51
|
*/
|
|
45
52
|
export declare function normalizeGatewayPath(path: string): string;
|
|
53
|
+
/**
|
|
54
|
+
* Ensures a fetch-style websocket module is paired with the matching HTTP platform adapter capability.
|
|
55
|
+
*
|
|
56
|
+
* @param adapter The HTTP adapter selected by the application runtime.
|
|
57
|
+
* @param options Runtime-specific package names used in actionable diagnostics.
|
|
58
|
+
* @returns The supported fetch-style realtime capability exposed by the adapter.
|
|
59
|
+
*/
|
|
60
|
+
export declare function resolveSupportedFetchStyleRealtimeCapability(adapter: HttpApplicationAdapter, options: FetchStyleRealtimeBoundaryOptions): FetchStyleHttpAdapterRealtimeCapability;
|
|
61
|
+
/**
|
|
62
|
+
* Rejects server-backed gateway opt-in on fetch-style websocket runtime modules.
|
|
63
|
+
*
|
|
64
|
+
* @param descriptors Discovered gateway descriptors for the application.
|
|
65
|
+
* @param packageSubpath Runtime subpath used in diagnostics.
|
|
66
|
+
*/
|
|
67
|
+
export declare function assertNoFetchStyleServerBackedGatewayOptIn(descriptors: readonly WebSocketGatewayDescriptor[], packageSubpath: string): void;
|
|
46
68
|
/**
|
|
47
69
|
* Parse incoming message.
|
|
48
70
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/internal/shared.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAuB,KAAK,EAAE,MAAM,cAAc,CAAC;AAE/D,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/internal/shared.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAuB,KAAK,EAAE,MAAM,cAAc,CAAC;AAE/D,OAAO,KAAK,EAAE,SAAS,EAAY,MAAM,YAAY,CAAC;AACtD,OAAO,KAAK,EAAE,uCAAuC,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AACpG,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAGzE,OAAO,KAAK,EACV,0BAA0B,EAC1B,iCAAiC,EAClC,MAAM,aAAa,CAAC;AAIrB;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,SAAS,GAAG,WAAW,GAAG,WAAW,CAAC;IAC7C,UAAU,EAAE,QAAQ,CAAC;IACrB,KAAK,EAAE,KAAK,CAAC;CACd;AAQD;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,UAAU,EAAE,0BAA0B,CAAC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CAW9B;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,sBAAsB,CAAC,OAAO,EAAE,QAAQ,EAC5D,QAAQ,EAAE,SAAS,uBAAuB,EAAE,EAC5C,MAAM,EAAE,OAAO,EACf,OAAO,EAAE,QAAQ,EACjB,IAAI,EAAE,8BAA8B,EACpC,MAAM,EAAE,iBAAiB,EACzB,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,IAAI,CAAC,CAcf;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,yBAAyB,CAAC,OAAO,EACrD,QAAQ,EAAE,SAAS,uBAAuB,EAAE,EAC5C,MAAM,EAAE,OAAO,EACf,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,iBAAiB,EACzB,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,IAAI,CAAC,CAIf;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,kBAAkB,CACtC,QAAQ,EAAE,OAAO,EACjB,UAAU,EAAE,0BAA0B,EACtC,IAAI,EAAE,iCAAiC,CAAC,MAAM,CAAC,EAC/C,IAAI,EAAE,OAAO,EAAE,EACf,MAAM,EAAE,iBAAiB,EACzB,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,IAAI,CAAC,CAMf"}
|
package/dist/internal/shared.js
CHANGED
|
@@ -18,6 +18,8 @@ const textDecoder = new TextDecoder();
|
|
|
18
18
|
* Defines the shared web socket incoming message type.
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
+
/** Runtime metadata used to validate fetch-style websocket adapter boundaries. */
|
|
22
|
+
|
|
21
23
|
/**
|
|
22
24
|
* Is finite positive integer.
|
|
23
25
|
*
|
|
@@ -42,6 +44,41 @@ export function normalizeGatewayPath(path) {
|
|
|
42
44
|
return normalized === '' ? '/' : normalized;
|
|
43
45
|
}
|
|
44
46
|
|
|
47
|
+
/**
|
|
48
|
+
* Ensures a fetch-style websocket module is paired with the matching HTTP platform adapter capability.
|
|
49
|
+
*
|
|
50
|
+
* @param adapter The HTTP adapter selected by the application runtime.
|
|
51
|
+
* @param options Runtime-specific package names used in actionable diagnostics.
|
|
52
|
+
* @returns The supported fetch-style realtime capability exposed by the adapter.
|
|
53
|
+
*/
|
|
54
|
+
export function resolveSupportedFetchStyleRealtimeCapability(adapter, options) {
|
|
55
|
+
if (typeof adapter.getRealtimeCapability !== 'function') {
|
|
56
|
+
throw new Error(`${options.runtimeName} WebSocket gateway bootstrap requires an HTTP adapter with getRealtimeCapability(). Use ${options.platformPackage} together with @fluojs/websockets/${options.packageSubpath}.`);
|
|
57
|
+
}
|
|
58
|
+
const capability = adapter.getRealtimeCapability();
|
|
59
|
+
if (capability.kind !== 'fetch-style' || capability.contract !== 'raw-websocket-expansion') {
|
|
60
|
+
throw new Error(`${options.runtimeName} WebSocket gateway bootstrap requires a fetch-style raw-websocket-expansion realtime capability from the selected HTTP adapter.`);
|
|
61
|
+
}
|
|
62
|
+
if (capability.support !== 'supported') {
|
|
63
|
+
throw new Error(`${options.runtimeName} WebSocket gateway bootstrap requires supported fetch-style websocket hosting. ${capability.reason}`);
|
|
64
|
+
}
|
|
65
|
+
return capability;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Rejects server-backed gateway opt-in on fetch-style websocket runtime modules.
|
|
70
|
+
*
|
|
71
|
+
* @param descriptors Discovered gateway descriptors for the application.
|
|
72
|
+
* @param packageSubpath Runtime subpath used in diagnostics.
|
|
73
|
+
*/
|
|
74
|
+
export function assertNoFetchStyleServerBackedGatewayOptIn(descriptors, packageSubpath) {
|
|
75
|
+
const descriptor = descriptors.find(entry => entry.serverBacked !== undefined);
|
|
76
|
+
if (!descriptor) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
throw new Error(`@WebSocketGateway({ serverBacked }) is not supported on @fluojs/websockets/${packageSubpath}. Gateway path ${descriptor.path} must use the default fetch-style request-upgrade host instead.`);
|
|
80
|
+
}
|
|
81
|
+
|
|
45
82
|
/**
|
|
46
83
|
* Parse incoming message.
|
|
47
84
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-service.d.ts","sourceRoot":"","sources":["../../src/node/node-service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"node-service.d.ts","sourceRoot":"","sources":["../../src/node/node-service.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEzI,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAc3D,OAAO,KAAK,EAIV,oBAAoB,EACrB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAgO9D;;;;;;GAMG;AACH,qBACa,oCACX,YAAW,sBAAsB,EAAE,qBAAqB,EAAE,eAAe,EAAE,oBAAoB;IAmB7F,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IACjC,OAAO,CAAC,QAAQ,CAAC,eAAe;IAChC,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,aAAa;IArBhC,OAAO,CAAC,WAAW,CAA2B;IAC9C,OAAO,CAAC,cAAc,CAA6C;IACnE,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,mBAAmB,CAAwC;IACnE,OAAO,CAAC,QAAQ,CAAC,wBAAwB,CAA4B;IACrE,OAAO,CAAC,0BAA0B,CAAK;IACvC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAqB;IACjD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA6B;IACxD,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAkC;IAC9D,OAAO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ageByteLength(data) {
|
|
|
53
53
|
}
|
|
54
54
|
return data.byteLength;
|
|
55
55
|
}
|
|
56
|
+
function resolveBoundGatewayPort(address, fallbackPort) {
|
|
57
|
+
if (!address || typeof address === 'string') {
|
|
58
|
+
return fallbackPort;
|
|
59
|
+
}
|
|
60
|
+
return address.port;
|
|
61
|
+
}
|
|
56
62
|
const DEFAULT_WEBSOCKET_SHUTDOWN_TIMEOUT_MS = 5_000;
|
|
57
63
|
const DEFAULT_MAX_PENDING_MESSAGES_PER_SOCKET = 256;
|
|
58
64
|
const DEFAULT_MAX_BUFFERED_AMOUNT_BYTES = 1_048_576;
|
|
@@ -208,10 +214,10 @@ class NodeWebSocketGatewayLifecycleService {
|
|
|
208
214
|
const server = createOwnedGatewayServer();
|
|
209
215
|
const listener = this.createUpgradeListener(server, group.attachmentsByPath);
|
|
210
216
|
server.on('upgrade', listener);
|
|
211
|
-
await this.listenOwnedGatewayServer(server, group.target.port);
|
|
217
|
+
const port = await this.listenOwnedGatewayServer(server, group.target.port);
|
|
212
218
|
this.ownedUpgradeServers.push({
|
|
213
219
|
listener,
|
|
214
|
-
port
|
|
220
|
+
port,
|
|
215
221
|
server
|
|
216
222
|
});
|
|
217
223
|
}
|
|
@@ -263,15 +269,16 @@ class NodeWebSocketGatewayLifecycleService {
|
|
|
263
269
|
};
|
|
264
270
|
}
|
|
265
271
|
const port = this.resolveServerBackedPort(descriptor.path, serverBacked);
|
|
272
|
+
const key = port === 0 ? `owned-server:ephemeral:${descriptor.path}` : `owned-server:${String(port)}`;
|
|
266
273
|
return {
|
|
267
|
-
key
|
|
274
|
+
key,
|
|
268
275
|
kind: 'owned-server',
|
|
269
276
|
port
|
|
270
277
|
};
|
|
271
278
|
}
|
|
272
279
|
resolveServerBackedPort(path, options) {
|
|
273
|
-
if (!isFinitePositiveInteger(options.port)) {
|
|
274
|
-
throw new Error(`WebSocket gateway serverBacked.port for path ${path} must be a finite positive integer.`);
|
|
280
|
+
if (options.port !== 0 && !isFinitePositiveInteger(options.port)) {
|
|
281
|
+
throw new Error(`WebSocket gateway serverBacked.port for path ${path} must be 0 or a finite positive integer.`);
|
|
275
282
|
}
|
|
276
283
|
return options.port;
|
|
277
284
|
}
|
|
@@ -833,7 +840,7 @@ class NodeWebSocketGatewayLifecycleService {
|
|
|
833
840
|
httpServer.once('error', onError);
|
|
834
841
|
server.listen(port, () => {
|
|
835
842
|
httpServer.off('error', onError);
|
|
836
|
-
resolve();
|
|
843
|
+
resolve(resolveBoundGatewayPort(httpServer.address(), port));
|
|
837
844
|
});
|
|
838
845
|
});
|
|
839
846
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export type TypedOnMessageHandler<TEvents extends WebSocketEventMap, K extends k
|
|
|
12
12
|
* Dedicated listener configuration for runtimes that can host a standalone WebSocket server.
|
|
13
13
|
*/
|
|
14
14
|
export interface WebSocketGatewayServerBackedOptions {
|
|
15
|
-
/** TCP port used by the dedicated listener. */
|
|
15
|
+
/** TCP port used by the dedicated listener. Use `0` to let the host allocate an ephemeral port. */
|
|
16
16
|
port: number;
|
|
17
17
|
}
|
|
18
18
|
/**
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,KAAK,EACV,qBAAqB,IAAI,yBAAyB,EAClD,uBAAuB,IAAI,2BAA2B,EACtD,sBAAsB,IAAI,0BAA0B,EACpD,uBAAuB,IAAI,2BAA2B,EACtD,qBAAqB,IAAI,yBAAyB,EAClD,yBAAyB,IAAI,6BAA6B,EAC3D,MAAM,sBAAsB,CAAC;AAE9B;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAExD;;GAEG;AACH,MAAM,MAAM,qBA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AAM,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI,CAAC;IAElE;;;;;OAKG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;CACjD;AAED;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG,0BAA0B,CAAC"}
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"realtime",
|
|
10
10
|
"upgrade"
|
|
11
11
|
],
|
|
12
|
-
"version": "1.0.
|
|
12
|
+
"version": "1.0.4",
|
|
13
13
|
"private": false,
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"repository": {
|
|
@@ -69,18 +69,18 @@
|
|
|
69
69
|
],
|
|
70
70
|
"dependencies": {
|
|
71
71
|
"ws": "^8.18.3",
|
|
72
|
-
"@fluojs/core": "^1.0.3",
|
|
73
72
|
"@fluojs/di": "^1.0.3",
|
|
74
|
-
"@fluojs/
|
|
73
|
+
"@fluojs/core": "^1.0.3",
|
|
74
|
+
"@fluojs/runtime": "^1.1.2",
|
|
75
75
|
"@fluojs/http": "^1.1.0"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
78
|
"@types/ws": "^8.18.1",
|
|
79
79
|
"vitest": "^3.2.4",
|
|
80
|
-
"@fluojs/platform-
|
|
81
|
-
"@fluojs/platform-
|
|
82
|
-
"@fluojs/platform-fastify": "^1.0.
|
|
83
|
-
"@fluojs/testing": "^1.0.
|
|
80
|
+
"@fluojs/platform-express": "^1.0.3",
|
|
81
|
+
"@fluojs/platform-bun": "^1.0.3",
|
|
82
|
+
"@fluojs/platform-fastify": "^1.0.4",
|
|
83
|
+
"@fluojs/testing": "^1.0.4"
|
|
84
84
|
},
|
|
85
85
|
"scripts": {
|
|
86
86
|
"prebuild": "node ../../tooling/scripts/clean-dist.mjs",
|