@logux/server 0.14.0 → 0.16.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/LICENSE +1 -1
- package/README.md +15 -18
- package/add-http-pages/hello.html +34 -26
- package/add-sync-map/index.d.ts +1 -3
- package/add-sync-map/index.js +4 -10
- package/base-server/index.d.ts +88 -30
- package/base-server/index.js +208 -114
- package/context/index.d.ts +35 -3
- package/context/index.js +17 -6
- package/create-reporter/index.js +40 -32
- package/human-formatter/index.js +12 -7
- package/human-formatter/utils.js +14 -0
- package/index.d.ts +8 -1
- package/index.js +1 -0
- package/package.json +20 -22
- package/postgres-store/index.d.ts +149 -0
- package/postgres-store/index.js +444 -0
- package/server/index.d.ts +9 -5
- package/server/index.js +16 -7
- package/server-client/index.d.ts +25 -1
- package/server-client/index.js +42 -9
- package/test-client/index.d.ts +5 -2
- package/test-client/index.js +8 -8
- package/test-server/index.d.ts +9 -6
- package/test-server/index.js +4 -3
- package/url-pattern/index.js +28 -0
package/test-client/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ClientNode, TestPair } from '@logux/core'
|
|
2
|
-
import
|
|
2
|
+
import { stringifyCookie } from 'cookie'
|
|
3
3
|
import { setTimeout } from 'node:timers/promises'
|
|
4
4
|
|
|
5
5
|
import { filterMeta } from '../filter-meta/index.js'
|
|
@@ -34,9 +34,9 @@ export class TestClient {
|
|
|
34
34
|
this.node.setLocalHeaders(opts.headers)
|
|
35
35
|
}
|
|
36
36
|
if (opts.cookie) {
|
|
37
|
-
this.pair.right.ws.upgradeReq.headers.cookie =
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
this.pair.right.ws.upgradeReq.headers.cookie = stringifyCookie(
|
|
38
|
+
opts.cookie
|
|
39
|
+
)
|
|
40
40
|
}
|
|
41
41
|
server.unbind.push(() => {
|
|
42
42
|
this.node.destroy()
|
|
@@ -46,7 +46,7 @@ export class TestClient {
|
|
|
46
46
|
async collect(test) {
|
|
47
47
|
let added = []
|
|
48
48
|
let unbind = this.node.log.on('add', (action, meta) => {
|
|
49
|
-
if (
|
|
49
|
+
if (meta.id.split(' ')[1] !== this.nodeId) {
|
|
50
50
|
added.push(action)
|
|
51
51
|
}
|
|
52
52
|
})
|
|
@@ -67,8 +67,8 @@ export class TestClient {
|
|
|
67
67
|
})
|
|
68
68
|
|
|
69
69
|
this.server.addClient(this.pair.right)
|
|
70
|
-
this.node.connection.connect()
|
|
71
|
-
this.node.waitFor('synchronized').then(() => {
|
|
70
|
+
void this.node.connection.connect()
|
|
71
|
+
void this.node.waitFor('synchronized').then(() => {
|
|
72
72
|
this.node.throwsError = true
|
|
73
73
|
unbind()
|
|
74
74
|
resolve()
|
|
@@ -136,7 +136,7 @@ export class TestClient {
|
|
|
136
136
|
async received(test) {
|
|
137
137
|
let actions = []
|
|
138
138
|
let unbind = this.log.on('add', (action, meta) => {
|
|
139
|
-
if (
|
|
139
|
+
if (meta.id.split(' ')[1] !== this.nodeId) {
|
|
140
140
|
actions.push(action)
|
|
141
141
|
}
|
|
142
142
|
})
|
package/test-server/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { TestLog, TestTime } from '@logux/core'
|
|
1
|
+
import type { Log, TestLog, TestTime } from '@logux/core'
|
|
2
2
|
|
|
3
|
-
import { BaseServer } from '../base-server/index.js'
|
|
4
3
|
import type {
|
|
4
|
+
BaseServer,
|
|
5
5
|
BaseServerOptions,
|
|
6
6
|
Logger,
|
|
7
7
|
ServerMeta
|
|
@@ -9,8 +9,10 @@ import type {
|
|
|
9
9
|
import type { LoggerOptions } from '../server/index.js'
|
|
10
10
|
import type { TestClient, TestClientOptions } from '../test-client/index.js'
|
|
11
11
|
|
|
12
|
-
export interface TestServerOptions
|
|
13
|
-
|
|
12
|
+
export interface TestServerOptions extends Omit<
|
|
13
|
+
BaseServerOptions,
|
|
14
|
+
'minSubprotocol' | 'subprotocol'
|
|
15
|
+
> {
|
|
14
16
|
/**
|
|
15
17
|
* Disable built-in auth.
|
|
16
18
|
*/
|
|
@@ -46,8 +48,9 @@ export interface TestServerOptions
|
|
|
46
48
|
* ```
|
|
47
49
|
*/
|
|
48
50
|
export class TestServer<
|
|
49
|
-
Headers extends object = unknown
|
|
50
|
-
|
|
51
|
+
Headers extends object = unknown,
|
|
52
|
+
ClientData extends object = unknown
|
|
53
|
+
> extends BaseServer<Headers, Log<ServerMeta>, ClientData> {
|
|
51
54
|
/**
|
|
52
55
|
* fetch() compatible API to test HTTP endpoints.
|
|
53
56
|
*
|
package/test-server/index.js
CHANGED
|
@@ -34,8 +34,8 @@ export class TestServer extends BaseServer {
|
|
|
34
34
|
|
|
35
35
|
this.fetch = this.fetch.bind(this)
|
|
36
36
|
|
|
37
|
-
this.on('fatal', () => {
|
|
38
|
-
this.destroy()
|
|
37
|
+
this.on('fatal', async () => {
|
|
38
|
+
await this.destroy()
|
|
39
39
|
})
|
|
40
40
|
}
|
|
41
41
|
|
|
@@ -72,7 +72,8 @@ export class TestServer extends BaseServer {
|
|
|
72
72
|
if (e.message === 'Server undid action') {
|
|
73
73
|
if (e.action.reason !== reason) {
|
|
74
74
|
throw new Error(
|
|
75
|
-
`Undo was with ${e.action.reason} reason, not ${reason}
|
|
75
|
+
`Undo was with ${e.action.reason} reason, not ${reason}`,
|
|
76
|
+
{ cause: e }
|
|
76
77
|
)
|
|
77
78
|
}
|
|
78
79
|
} else {
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const PARAM = /:(\w+)/g
|
|
2
|
+
const SPECIAL = /[.*+?^${}()|[\]\\]/g
|
|
3
|
+
|
|
4
|
+
function escape(text) {
|
|
5
|
+
return text.replace(SPECIAL, '\\$&')
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function createPattern(pattern) {
|
|
9
|
+
let names = []
|
|
10
|
+
let source = ''
|
|
11
|
+
let last = 0
|
|
12
|
+
for (let param of pattern.matchAll(PARAM)) {
|
|
13
|
+
source += escape(pattern.slice(last, param.index)) + '([^/]+)'
|
|
14
|
+
names.push(param[1])
|
|
15
|
+
last = param.index + param[0].length
|
|
16
|
+
}
|
|
17
|
+
let regexp = new RegExp('^' + source + escape(pattern.slice(last)) + '$')
|
|
18
|
+
|
|
19
|
+
return url => {
|
|
20
|
+
let match = regexp.exec(url)
|
|
21
|
+
if (!match) return null
|
|
22
|
+
let params = {}
|
|
23
|
+
for (let i = 0; i < names.length; i++) {
|
|
24
|
+
if (names[i] !== '__proto__') params[names[i]] = match[i + 1]
|
|
25
|
+
}
|
|
26
|
+
return params
|
|
27
|
+
}
|
|
28
|
+
}
|