@nxtedition/lib 23.0.3 → 23.0.5
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/app.d.ts +62 -0
- package/app.js +0 -5
- package/couch.js +7 -13
- package/deepstream.d.ts +37 -4
- package/package.json +14 -13
- package/util/template/javascript.js +2 -3
package/app.d.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { DeepstreamClient } from '@nxtedition/deepstream.io-client-js'
|
|
2
|
+
import type { NxtDeepstreamClient } from './deepstream.js'
|
|
3
|
+
import type { Logger } from './logger.js'
|
|
4
|
+
import type { CouchClient } from './couch.js'
|
|
5
|
+
import type { Server } from 'http'
|
|
6
|
+
import type { BehaviorSubject } from 'rxjs'
|
|
7
|
+
|
|
8
|
+
export function makeApp<AC extends AppConfig, Records, RpcMethods>(
|
|
9
|
+
appConfig: AC,
|
|
10
|
+
onTerminate?: (logger: Logger) => Promise<void>,
|
|
11
|
+
): App<AC, Records, RpcMethods>
|
|
12
|
+
|
|
13
|
+
export interface AppConfig {
|
|
14
|
+
name: string
|
|
15
|
+
module?: string
|
|
16
|
+
version?: string
|
|
17
|
+
config: {
|
|
18
|
+
[key: string]: unknown
|
|
19
|
+
}
|
|
20
|
+
[key: string]: unknown
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface App<AC extends AppConfig, Records, RpcMethods> {
|
|
24
|
+
ds: DeepstreamClientWithNxt<Records, RpcMethods>
|
|
25
|
+
nxt: NxtDeepstreamClient<Records, RpcMethods>
|
|
26
|
+
couch: CouchClient
|
|
27
|
+
server: Server
|
|
28
|
+
compiler: unkonwn
|
|
29
|
+
config: AC['config']
|
|
30
|
+
logger: Logger
|
|
31
|
+
trace: unknown
|
|
32
|
+
trace: unknown
|
|
33
|
+
toobusy: TooBusy
|
|
34
|
+
destroyers: Array<
|
|
35
|
+
| rxjs.Subscription
|
|
36
|
+
| ((logger: Logger) => void)
|
|
37
|
+
| ((logger: Logger) => Promise<void>)
|
|
38
|
+
| Disposable
|
|
39
|
+
| AsyncDisposable
|
|
40
|
+
>
|
|
41
|
+
userAgent: string | null
|
|
42
|
+
serviceName: string
|
|
43
|
+
serviceModule: string
|
|
44
|
+
serviceVersion?: string
|
|
45
|
+
serviceInstanceId: string
|
|
46
|
+
serviceWorkerId: number
|
|
47
|
+
signal: AbortSignal
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface DeepstreamClientWithNxt<Records, RpcMethods>
|
|
51
|
+
extends DeepstreamClient<Records, RpcMethods> {
|
|
52
|
+
nxt: NxtDeepstreamClient<Records, RpcMethods>
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface TooBusy {
|
|
56
|
+
(): boolean
|
|
57
|
+
lag: () => number
|
|
58
|
+
lag$: BehaviorSubject<number>
|
|
59
|
+
appLag: () => number
|
|
60
|
+
appLag$: BehaviorSubject<number>
|
|
61
|
+
maxLag: number
|
|
62
|
+
}
|
package/app.js
CHANGED
|
@@ -33,7 +33,6 @@ import { json } from 'node:stream/consumers'
|
|
|
33
33
|
import { monitorEventLoopDelay } from 'node:perf_hooks'
|
|
34
34
|
import { LRUCache } from 'lru-cache'
|
|
35
35
|
import xuid from 'xuid'
|
|
36
|
-
import undici from 'undici'
|
|
37
36
|
import { isTimeBetween } from './time.js'
|
|
38
37
|
|
|
39
38
|
export function makeApp(appConfig, onTerminate) {
|
|
@@ -53,10 +52,6 @@ export function makeApp(appConfig, onTerminate) {
|
|
|
53
52
|
net.setDefaultAutoSelectFamily(false)
|
|
54
53
|
}
|
|
55
54
|
|
|
56
|
-
if (undici.setGlobalDispatcher) {
|
|
57
|
-
undici.setGlobalDispatcher(new undici.Agent({ connectTimeout: 2e3 }))
|
|
58
|
-
}
|
|
59
|
-
|
|
60
55
|
// Optimize some Node global defaults.
|
|
61
56
|
|
|
62
57
|
Buffer.poolSize = 128 * 1024
|
package/couch.js
CHANGED
|
@@ -6,13 +6,7 @@ import { makeWeakCache } from './weakCache.js'
|
|
|
6
6
|
import { defaultDelay as delay } from './http.js'
|
|
7
7
|
import urljoin from 'url-join'
|
|
8
8
|
import { AbortError } from './errors.js'
|
|
9
|
-
import {
|
|
10
|
-
dispatch,
|
|
11
|
-
Agent,
|
|
12
|
-
Pool,
|
|
13
|
-
parseHeaders,
|
|
14
|
-
request as undiciRequest,
|
|
15
|
-
} from '@nxtedition/nxt-undici'
|
|
9
|
+
import { dispatch, Agent, Pool, request as undiciRequest } from '@nxtedition/nxt-undici'
|
|
16
10
|
|
|
17
11
|
export function makeCouch(opts) {
|
|
18
12
|
let config
|
|
@@ -212,7 +206,7 @@ export function makeCouch(opts) {
|
|
|
212
206
|
const live = options.live == null || !!options.live
|
|
213
207
|
const retry =
|
|
214
208
|
options.retry ??
|
|
215
|
-
(async (err, retryCount, params, { signal }, next) => {
|
|
209
|
+
(async (err, retryCount, params, { signal, logger }, next) => {
|
|
216
210
|
logger?.error({ err, retryCount, params }, 'changes error')
|
|
217
211
|
return next()
|
|
218
212
|
})
|
|
@@ -391,13 +385,13 @@ export function makeCouch(opts) {
|
|
|
391
385
|
const retryState = { since: params.since }
|
|
392
386
|
Object.assign(
|
|
393
387
|
retryState,
|
|
394
|
-
await retry(err, retryCount++, retryState, { signal }, () =>
|
|
395
|
-
delay(err, retryCount, { signal }),
|
|
388
|
+
await retry(err, retryCount++, retryState, { signal, logger }, () =>
|
|
389
|
+
delay(err, retryCount, { signal, logger }),
|
|
396
390
|
),
|
|
397
391
|
)
|
|
398
392
|
params.since = retryState.since ?? 0
|
|
399
393
|
} else {
|
|
400
|
-
await delay(err, retryCount, { signal })
|
|
394
|
+
await delay(err, retryCount, { signal, logger })
|
|
401
395
|
}
|
|
402
396
|
} finally {
|
|
403
397
|
src?.on('error', () => {}).destroy()
|
|
@@ -484,7 +478,7 @@ export function makeCouch(opts) {
|
|
|
484
478
|
},
|
|
485
479
|
onHeaders(statusCode, headers) {
|
|
486
480
|
this.status = statusCode
|
|
487
|
-
this.headers =
|
|
481
|
+
this.headers = headers
|
|
488
482
|
},
|
|
489
483
|
onData(chunk) {
|
|
490
484
|
this.data += chunk
|
|
@@ -934,7 +928,7 @@ class StreamOutput extends stream.Readable {
|
|
|
934
928
|
}
|
|
935
929
|
}
|
|
936
930
|
|
|
937
|
-
onHeaders(statusCode,
|
|
931
|
+
onHeaders(statusCode, headers, resume) {
|
|
938
932
|
if (statusCode >= 300 || statusCode < 200) {
|
|
939
933
|
throw new Error('invalid status code: ' + statusCode)
|
|
940
934
|
}
|
package/deepstream.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { DeepstreamClient, RecordHandler } from '@nxtedition/deepstream.io-client-js'
|
|
2
2
|
|
|
3
|
+
type Paths<T> = keyof T & string
|
|
4
|
+
type Get<Data, Path extends string> = Path extends keyof Data ? Data[Path] : unknown
|
|
5
|
+
|
|
3
6
|
export function makeDeepstream<Records, RpcMethods>(
|
|
4
7
|
client: DeepstreamClient<Records, RpcMethods>,
|
|
5
8
|
): NxtDeepstreamClient<Records, RpcMethods>
|
|
@@ -8,12 +11,42 @@ export interface NxtDeepstreamClient<Records, RpcMethods> {
|
|
|
8
11
|
ds: DeepstreamClient<Records, RpcMethods> & { nxt: NxtDeepstreamClient<Records, RpcMethods> }
|
|
9
12
|
record: {
|
|
10
13
|
provide: RecordHandler<Records>['provide']
|
|
11
|
-
observe: RecordHandler<Records>['observe']
|
|
12
|
-
observe2: RecordHandler<Records>['observe2']
|
|
14
|
+
observe: RecordHandler<Records>['observe'] // TODO type with query
|
|
15
|
+
observe2: RecordHandler<Records>['observe2'] // TODO type with query
|
|
13
16
|
query: RecordHandler<Records>['query']
|
|
14
17
|
set: RecordHandler<Records>['set']
|
|
15
|
-
get:
|
|
16
|
-
|
|
18
|
+
get: {
|
|
19
|
+
// without query and path:
|
|
20
|
+
<Name extends keyof Records, Data extends Records[Name]>(
|
|
21
|
+
name: Name,
|
|
22
|
+
state?: number,
|
|
23
|
+
): Promise<Data>
|
|
24
|
+
|
|
25
|
+
// with path:
|
|
26
|
+
<Name extends keyof Records, Data extends Records[Name], Path extends Paths<Data> & string>(
|
|
27
|
+
name: Name,
|
|
28
|
+
path?: Path,
|
|
29
|
+
state?: number,
|
|
30
|
+
): Promise<Get<Data, Path>>
|
|
31
|
+
|
|
32
|
+
// with query:
|
|
33
|
+
<Name extends keyof Records, Data extends Records[Name]>(
|
|
34
|
+
name: Name,
|
|
35
|
+
query: Query,
|
|
36
|
+
state?: number,
|
|
37
|
+
): Promise<Data>
|
|
38
|
+
|
|
39
|
+
// with query and path:
|
|
40
|
+
<Name extends keyof Records, Data extends Records[Name], Path extends Paths<Data> & string>(
|
|
41
|
+
name: Name,
|
|
42
|
+
query: Query,
|
|
43
|
+
path?: Path,
|
|
44
|
+
state?: number,
|
|
45
|
+
): Promise<Get<Data, Path>>
|
|
46
|
+
}
|
|
47
|
+
getRecord: RecordHandler<Records>['getRecord'] // TODO type with query
|
|
17
48
|
update: RecordHandler<Records>['update']
|
|
18
49
|
}
|
|
19
50
|
}
|
|
51
|
+
|
|
52
|
+
type Query = Record<string, unknown>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nxtedition/lib",
|
|
3
|
-
"version": "23.0.
|
|
3
|
+
"version": "23.0.5",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Robert Nagy <robert.nagy@boffins.se>",
|
|
6
6
|
"type": "module",
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"couch.js",
|
|
34
34
|
"couch.d.ts",
|
|
35
35
|
"app.js",
|
|
36
|
+
"app.d.ts",
|
|
36
37
|
"errors.js",
|
|
37
38
|
"errors.d.ts",
|
|
38
39
|
"worker.js",
|
|
@@ -59,10 +60,10 @@
|
|
|
59
60
|
"singleQuote": true
|
|
60
61
|
},
|
|
61
62
|
"dependencies": {
|
|
62
|
-
"@aws-sdk/client-s3": "^3.
|
|
63
|
+
"@aws-sdk/client-s3": "^3.731.1",
|
|
63
64
|
"@elastic/elasticsearch": "^8.16.1",
|
|
64
|
-
"@elastic/transport": "^8.9.
|
|
65
|
-
"@nxtedition/nxt-undici": "^
|
|
65
|
+
"@elastic/transport": "^8.9.3",
|
|
66
|
+
"@nxtedition/nxt-undici": "^6.0.0",
|
|
66
67
|
"@swc/wasm-web": "^1.10.1",
|
|
67
68
|
"content-type": "^1.0.5",
|
|
68
69
|
"date-fns": "^3.6.0",
|
|
@@ -74,28 +75,28 @@
|
|
|
74
75
|
"lodash": "^4.17.21",
|
|
75
76
|
"lru-cache": "^11.0.2",
|
|
76
77
|
"mime": "^4.0.6",
|
|
77
|
-
"mitata": "^1.0.
|
|
78
|
+
"mitata": "^1.0.31",
|
|
78
79
|
"moment-timezone": "^0.5.46",
|
|
79
80
|
"nconf": "^0.12.1",
|
|
80
81
|
"nested-error-stacks": "^2.1.1",
|
|
81
82
|
"object-hash": "^3.0.0",
|
|
82
83
|
"p-queue": "^8.0.1",
|
|
83
84
|
"pino": "^9.6.0",
|
|
84
|
-
"qs": "^6.
|
|
85
|
+
"qs": "^6.14.0",
|
|
85
86
|
"request-target": "^1.0.2",
|
|
86
87
|
"smpte-timecode": "^1.3.6",
|
|
87
88
|
"split-string": "^6.0.0",
|
|
88
|
-
"undici": "^7.2.
|
|
89
|
+
"undici": "^7.2.3",
|
|
89
90
|
"url-join": "^5.0.0",
|
|
90
|
-
"xuid": "^4.1.
|
|
91
|
+
"xuid": "^4.1.5",
|
|
91
92
|
"yocto-queue": "^1.1.1"
|
|
92
93
|
},
|
|
93
94
|
"devDependencies": {
|
|
94
|
-
"@nxtedition/deepstream.io-client-js": ">=
|
|
95
|
+
"@nxtedition/deepstream.io-client-js": ">=28.1.5",
|
|
95
96
|
"@types/lodash": "^4.17.14",
|
|
96
|
-
"@types/node": "^22.10.
|
|
97
|
+
"@types/node": "^22.10.7",
|
|
97
98
|
"eslint": "^9.15.0",
|
|
98
|
-
"eslint-config-prettier": "^
|
|
99
|
+
"eslint-config-prettier": "^10.0.1",
|
|
99
100
|
"eslint-config-standard": "^17.0.0",
|
|
100
101
|
"eslint-plugin-import": "^2.31.0",
|
|
101
102
|
"eslint-plugin-n": "^17.15.1",
|
|
@@ -106,9 +107,9 @@
|
|
|
106
107
|
"pinst": "^3.0.0",
|
|
107
108
|
"prettier": "^3.4.2",
|
|
108
109
|
"rxjs": "^7.5.6",
|
|
109
|
-
"send": "^
|
|
110
|
+
"send": "^1.1.0",
|
|
110
111
|
"tap": "^21.0.1",
|
|
111
|
-
"typescript-eslint": "^8.
|
|
112
|
+
"typescript-eslint": "^8.20.0"
|
|
112
113
|
},
|
|
113
114
|
"peerDependencies": {
|
|
114
115
|
"@elastic/elasticsearch": "^8.6.0",
|
|
@@ -4,8 +4,7 @@ import * as rxjs from 'rxjs'
|
|
|
4
4
|
import objectHash from 'object-hash'
|
|
5
5
|
import * as datefns from 'date-fns'
|
|
6
6
|
import JSON5 from 'json5'
|
|
7
|
-
import { request } from '@nxtedition/nxt-undici'
|
|
8
|
-
import undici from 'undici'
|
|
7
|
+
import { request, Agent } from '@nxtedition/nxt-undici'
|
|
9
8
|
import fp from 'lodash/fp.js'
|
|
10
9
|
import moment from 'moment-timezone'
|
|
11
10
|
import Timecode from 'smpte-timecode'
|
|
@@ -31,7 +30,7 @@ class TimerEntry {
|
|
|
31
30
|
}
|
|
32
31
|
}
|
|
33
32
|
|
|
34
|
-
const fetchClient = new
|
|
33
|
+
const fetchClient = new Agent({
|
|
35
34
|
connections: 128,
|
|
36
35
|
})
|
|
37
36
|
|