Skip to content

Commit 57c6537

Browse files
committed
Move to number subprotocol
1 parent 8206576 commit 57c6537

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+339
-422
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ import { Server } from '@logux/server'
3636

3737
const server = new Server(
3838
Server.loadOptions(process, {
39-
subprotocol: '1.0.0',
40-
supports: '1.x',
39+
subprotocol: 1,
40+
minSubprotocol: 1,
4141
root: import.meta.dirname
4242
})
4343
)

add-http-pages/index.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import {
1010
} from '../index.js'
1111

1212
const DEFAULT_OPTIONS = {
13-
subprotocol: '0.0.0',
14-
supports: '0.x'
13+
minSubprotocol: 0,
14+
subprotocol: 0
1515
}
1616

1717
let lastPort = 9111

base-server/index.d.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ interface ChannelOptions {
4545
}
4646

4747
interface ConnectLoader<Headers extends object = unknown> {
48-
(ctx: ConnectContext<Headers>, lastSynced: number):
48+
(
49+
ctx: ConnectContext<Headers>,
50+
lastSynced: number
51+
):
4952
| [Action, ServerMeta][]
5053
| Promise<
5154
[
@@ -146,7 +149,8 @@ export interface BaseServerOptions {
146149
env?: 'development' | 'production'
147150

148151
/**
149-
* URL of main JS file in the root dir.
152+
* URL of main JS file in the root dir for the cases where you can’t use
153+
* `import.meta.dirname`.
150154
*
151155
* ```
152156
* fileUrl: import.meta.url
@@ -170,6 +174,11 @@ export interface BaseServerOptions {
170174
*/
171175
key?: { pem: string } | string
172176

177+
/**
178+
* The version requirements for client subprotocol version.
179+
*/
180+
minSubprotocol?: number
181+
173182
/**
174183
* Replace class for ServerNode.
175184
*/
@@ -221,14 +230,9 @@ export interface BaseServerOptions {
221230
store?: LogStore
222231

223232
/**
224-
* Server current application subprotocol version in SemVer format.
225-
*/
226-
subprotocol?: string
227-
228-
/**
229-
* npm’s version requirements for client subprotocol version.
233+
* Server current application subprotocol version.
230234
*/
231-
supports?: string
235+
subprotocol?: number
232236

233237
/**
234238
* Test time to test server.
@@ -561,13 +565,13 @@ interface ReportersArguments {
561565
environment: 'development' | 'production'
562566
host: string
563567
loguxServer: string
568+
minSubprotocol: number
564569
nodeId: string
565570
notes: object
566571
port: string
567572
redis: string
568573
server: boolean
569-
subprotocol: string
570-
supports: string
574+
subprotocol: number
571575
}
572576
processed: {
573577
actionId: ID

base-server/index.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ export class BaseServer {
9494
if (typeof this.options.subprotocol === 'undefined') {
9595
throw optionError('Missed `subprotocol` option in server constructor')
9696
}
97-
if (typeof this.options.supports === 'undefined') {
98-
throw optionError('Missed `supports` option in server constructor')
97+
if (typeof this.options.minSubprotocol === 'undefined') {
98+
throw optionError('Missed `minSubprotocol` option in server constructor')
9999
}
100100

101101
if (this.options.key && !this.options.cert) {
@@ -621,9 +621,7 @@ export class BaseServer {
621621
}
622622

623623
let pkg = JSON.parse(
624-
await readFile(
625-
join(fileURLToPath(import.meta.url), '..', '..', 'package.json')
626-
)
624+
await readFile(join(import.meta.dirname, '..', 'package.json'))
627625
)
628626

629627
this.ws.on('connection', (ws, req) => {
@@ -635,13 +633,13 @@ export class BaseServer {
635633
environment: this.env,
636634
host: this.options.host,
637635
loguxServer: pkg.version,
636+
minSubprotocol: this.options.minSubprotocol,
638637
nodeId: this.nodeId,
639638
notes: this.listenNotes,
640639
port: this.options.port,
641640
redis: this.options.redis,
642641
server: !!this.options.server,
643-
subprotocol: this.options.subprotocol,
644-
supports: this.options.supports
642+
subprotocol: this.options.subprotocol
645643
})
646644
}
647645

0 commit comments

Comments
 (0)