@nxtedition/lib 22.1.1 → 22.1.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/app.js +51 -41
- package/couch.d.ts +68 -0
- package/deepstream.d.ts +19 -0
- package/errors.d.ts +46 -0
- package/logger.d.ts +18 -0
- package/package.json +5 -1
- package/rxjs/firstValueFrom.d.ts +12 -0
package/app.js
CHANGED
|
@@ -818,61 +818,46 @@ export function makeApp(appConfig, onTerminate) {
|
|
|
818
818
|
inspectBC.onmessage = ({ data }) => {
|
|
819
819
|
const { type, id } = data
|
|
820
820
|
|
|
821
|
-
if (id
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
inspectOpen
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
inspector.close()
|
|
834
|
-
inspectOpen = false
|
|
821
|
+
if (id === threadId) {
|
|
822
|
+
if (type === 'inspect:open') {
|
|
823
|
+
// TODO (fix): What happens if you call inspect:open multiple times?
|
|
824
|
+
if (!inspectOpen) {
|
|
825
|
+
inspector.open(data.port, data.hostname)
|
|
826
|
+
inspectOpen = true
|
|
827
|
+
}
|
|
828
|
+
} else if (type === 'inspect:close') {
|
|
829
|
+
if (inspectOpen) {
|
|
830
|
+
inspector.close()
|
|
831
|
+
inspectOpen = false
|
|
832
|
+
}
|
|
835
833
|
}
|
|
836
834
|
}
|
|
837
835
|
}
|
|
838
|
-
|
|
839
|
-
inspectBC.postMessage({
|
|
840
|
-
type: 'inspect:register',
|
|
841
|
-
id: threadId,
|
|
842
|
-
worker: {
|
|
843
|
-
id: threadId,
|
|
844
|
-
name: serviceName,
|
|
845
|
-
module: serviceModule,
|
|
846
|
-
version: serviceVersion,
|
|
847
|
-
workerId: serviceWorkerId,
|
|
848
|
-
instanceId: serviceInstanceId,
|
|
849
|
-
threadId,
|
|
850
|
-
processId: process.pid,
|
|
851
|
-
},
|
|
852
|
-
})
|
|
853
|
-
destroyers.unshift(() => {
|
|
854
|
-
if (inspectOpen) {
|
|
855
|
-
inspector.close()
|
|
856
|
-
inspectOpen = false
|
|
857
|
-
}
|
|
858
|
-
inspectBC.postMessage({ type: 'inspect:unregister', id: threadId })
|
|
859
|
-
setTimeout(() => {
|
|
860
|
-
inspectBC.close()
|
|
861
|
-
}, 100)
|
|
862
|
-
})
|
|
863
836
|
} else {
|
|
864
837
|
const inspectMap = new Map()
|
|
865
838
|
|
|
866
839
|
inspectBC.onmessage = ({ data }) => {
|
|
867
|
-
const { type, worker } = data
|
|
840
|
+
const { type, worker, id } = data
|
|
868
841
|
|
|
869
842
|
if (type === 'inspect:register') {
|
|
870
843
|
inspectMap.set(data.id, worker)
|
|
871
844
|
} else if (type === 'inspect:unregister') {
|
|
872
845
|
inspectMap.delete(data.id)
|
|
846
|
+
} else if (id === threadId) {
|
|
847
|
+
if (type === 'inspect:open') {
|
|
848
|
+
// TODO (fix): What happens if you call inspect:open multiple times?
|
|
849
|
+
if (!inspectOpen) {
|
|
850
|
+
inspector.open(data.port, data.hostname)
|
|
851
|
+
inspectOpen = true
|
|
852
|
+
}
|
|
853
|
+
} else if (type === 'inspect:close') {
|
|
854
|
+
if (inspectOpen) {
|
|
855
|
+
inspector.close()
|
|
856
|
+
inspectOpen = false
|
|
857
|
+
}
|
|
858
|
+
}
|
|
873
859
|
}
|
|
874
860
|
}
|
|
875
|
-
destroyers.unshift(() => inspectBC.close())
|
|
876
861
|
|
|
877
862
|
// TODO (fix): Determinisitc port also in dev mode... hash of something?
|
|
878
863
|
const port =
|
|
@@ -938,6 +923,31 @@ export function makeApp(appConfig, onTerminate) {
|
|
|
938
923
|
|
|
939
924
|
destroyers.unshift(() => new Promise((resolve) => server.close(resolve)))
|
|
940
925
|
}
|
|
926
|
+
|
|
927
|
+
inspectBC.postMessage({
|
|
928
|
+
type: 'inspect:register',
|
|
929
|
+
id: threadId,
|
|
930
|
+
worker: {
|
|
931
|
+
id: threadId,
|
|
932
|
+
name: serviceName,
|
|
933
|
+
module: serviceModule,
|
|
934
|
+
version: serviceVersion,
|
|
935
|
+
workerId: serviceWorkerId,
|
|
936
|
+
instanceId: serviceInstanceId,
|
|
937
|
+
threadId,
|
|
938
|
+
processId: process.pid,
|
|
939
|
+
},
|
|
940
|
+
})
|
|
941
|
+
destroyers.unshift(() => {
|
|
942
|
+
if (inspectOpen) {
|
|
943
|
+
inspector.close()
|
|
944
|
+
inspectOpen = false
|
|
945
|
+
}
|
|
946
|
+
inspectBC.postMessage({ type: 'inspect:unregister', id: threadId })
|
|
947
|
+
setTimeout(() => {
|
|
948
|
+
inspectBC.close()
|
|
949
|
+
}, 100)
|
|
950
|
+
})
|
|
941
951
|
}
|
|
942
952
|
|
|
943
953
|
if (appConfig.utils !== false && !cluster.isWorker) {
|
package/couch.d.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { Logger } from './logger.js'
|
|
2
|
+
import { HttpError } from 'http-errors'
|
|
3
|
+
|
|
4
|
+
export interface CouchOptions {
|
|
5
|
+
url?: string
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function makeCouch(opts: string | CouchOptions): CouchClient
|
|
9
|
+
|
|
10
|
+
export interface CouchRequestOptions<Stream extends boolean = false> {
|
|
11
|
+
url?: URL
|
|
12
|
+
pathname?: string
|
|
13
|
+
path?: string
|
|
14
|
+
method?: string
|
|
15
|
+
body?: unknown
|
|
16
|
+
query?: {
|
|
17
|
+
startkey?: string
|
|
18
|
+
endkey?: string
|
|
19
|
+
update?: boolean
|
|
20
|
+
}
|
|
21
|
+
signal?: AbortSignal
|
|
22
|
+
logger?: Logger
|
|
23
|
+
stream?: Stream
|
|
24
|
+
// TODO add more or extend undicii type?
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface CouchResponse<T> {
|
|
28
|
+
rows: T[]
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function request<T, Stream extends boolean = false>(
|
|
32
|
+
url: string | URL | { origin: string; path?: string; pathname?: string },
|
|
33
|
+
opts?: CouchRequestOptions<Stream> | null,
|
|
34
|
+
): Stream extends true ? AsyncGenerator<T> & { length: number } : Promise<CouchResponse<T>>
|
|
35
|
+
|
|
36
|
+
interface ChangesOptions {
|
|
37
|
+
signal?: AbortSignal | null
|
|
38
|
+
descending?: boolean
|
|
39
|
+
include_docs?: boolean
|
|
40
|
+
seq_interval?: number | null
|
|
41
|
+
live?: boolean
|
|
42
|
+
heartbeat?: number
|
|
43
|
+
retry?: (
|
|
44
|
+
err: HttpError,
|
|
45
|
+
retryCount: number,
|
|
46
|
+
params: {
|
|
47
|
+
since?: string | 0 | null
|
|
48
|
+
},
|
|
49
|
+
ac: { signal: AbortSignal },
|
|
50
|
+
next: () => void,
|
|
51
|
+
) => void | null | Promise<void>
|
|
52
|
+
since?: string | 0 | null
|
|
53
|
+
selector?: object | null
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
interface ChangeItem {
|
|
57
|
+
id: string
|
|
58
|
+
seq?: string
|
|
59
|
+
doc?: object
|
|
60
|
+
deleted?: boolean
|
|
61
|
+
changes: Array<{ rev: string }>
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface CouchClient {
|
|
65
|
+
changes: (
|
|
66
|
+
options?: ChangesOptions & { client?: unknown; logger?: Logger },
|
|
67
|
+
) => AsyncGenerator<ChangeItem[] & { lastSeq?: string | 0 | null }, void, unknown>
|
|
68
|
+
}
|
package/deepstream.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { DeepstreamClient, RecordHandler } from '@nxtedition/deepstream.io-client-js'
|
|
2
|
+
|
|
3
|
+
export function makeDeepstream<Records, RpcMethods>(
|
|
4
|
+
client: DeepstreamClient<Records, RpcMethods>,
|
|
5
|
+
): NxtDeepstreamClient<Records, RpcMethods>
|
|
6
|
+
|
|
7
|
+
export interface NxtDeepstreamClient<Records, RpcMethods> {
|
|
8
|
+
ds: DeepstreamClient<Records, RpcMethods> & { nxt: NxtDeepstreamClient<Records, RpcMethods> }
|
|
9
|
+
record: {
|
|
10
|
+
provide: RecordHandler<Records>['provide']
|
|
11
|
+
observe: RecordHandler<Records>['observe']
|
|
12
|
+
observe2: RecordHandler<Records>['observe2']
|
|
13
|
+
query: RecordHandler<Records>['query']
|
|
14
|
+
set: RecordHandler<Records>['set']
|
|
15
|
+
get: RecordHandler<Records>['get']
|
|
16
|
+
getRecord: RecordHandler<Records>['getRecord']
|
|
17
|
+
update: RecordHandler<Records>['update']
|
|
18
|
+
}
|
|
19
|
+
}
|
package/errors.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export class AbortError extends Error {
|
|
2
|
+
constructor(message: string)
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function parseError(err: unknown): Error | null
|
|
6
|
+
|
|
7
|
+
export interface NxtError {
|
|
8
|
+
message: string
|
|
9
|
+
type?: string
|
|
10
|
+
code?: string
|
|
11
|
+
exitCode?: number
|
|
12
|
+
signalCode?: number
|
|
13
|
+
statusCode?: number
|
|
14
|
+
headers?: Record<string, string>
|
|
15
|
+
data?: object
|
|
16
|
+
cause?: NxtError | null
|
|
17
|
+
errors?: NxtError[] | null
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function serializeError(err: Error | string): NxtError[] | null
|
|
21
|
+
|
|
22
|
+
export type Message = {
|
|
23
|
+
msg: string
|
|
24
|
+
title?: string
|
|
25
|
+
id: string
|
|
26
|
+
level: number
|
|
27
|
+
code?: string
|
|
28
|
+
data?: object
|
|
29
|
+
expose?: boolean | null
|
|
30
|
+
index?: object | null
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type MessageOptions = {
|
|
34
|
+
id?: string
|
|
35
|
+
level?: number
|
|
36
|
+
code?: string
|
|
37
|
+
codes?: Record<string, string>
|
|
38
|
+
index?: boolean
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function makeMessages(
|
|
42
|
+
error: MessageError | MessageError[],
|
|
43
|
+
options?: MessageOptions,
|
|
44
|
+
): Message[]
|
|
45
|
+
|
|
46
|
+
export function makeErrorString(err: unknown): string
|
package/logger.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { pino } from 'pino'
|
|
2
|
+
|
|
3
|
+
export type Logger = pino.Logger
|
|
4
|
+
|
|
5
|
+
interface LoggerOptions extends pino.LoggerOptions {
|
|
6
|
+
flushInterval?: number
|
|
7
|
+
stream?: ReturnType<(typeof pino)['destination']> | (typeof process)['stdout'] | null
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function createLogger(
|
|
11
|
+
{
|
|
12
|
+
level = isProduction ? 'debug' : 'trace',
|
|
13
|
+
flushInterval = 1e3,
|
|
14
|
+
stream = null,
|
|
15
|
+
...options
|
|
16
|
+
}: LoggerOptions = {},
|
|
17
|
+
onTerminate: unknown,
|
|
18
|
+
): Logger
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nxtedition/lib",
|
|
3
|
-
"version": "22.1.
|
|
3
|
+
"version": "22.1.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Robert Nagy <robert.nagy@boffins.se>",
|
|
6
6
|
"type": "module",
|
|
@@ -20,8 +20,10 @@
|
|
|
20
20
|
"time.js",
|
|
21
21
|
"mutex.js",
|
|
22
22
|
"deepstream.js",
|
|
23
|
+
"deepstream.d.ts",
|
|
23
24
|
"sequence.js",
|
|
24
25
|
"logger.js",
|
|
26
|
+
"logger.d.ts",
|
|
25
27
|
"mime.js",
|
|
26
28
|
"proxy.js",
|
|
27
29
|
"timers.js",
|
|
@@ -29,8 +31,10 @@
|
|
|
29
31
|
"weakCache.js",
|
|
30
32
|
"weakCache.d.ts",
|
|
31
33
|
"couch.js",
|
|
34
|
+
"couch.d.ts",
|
|
32
35
|
"app.js",
|
|
33
36
|
"errors.js",
|
|
37
|
+
"errors.d.ts",
|
|
34
38
|
"worker.js",
|
|
35
39
|
"stream.js",
|
|
36
40
|
"timeline.js",
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Observable } from 'rxjs'
|
|
2
|
+
|
|
3
|
+
interface FirstValueFromConfig<T> {
|
|
4
|
+
signal?: AbortSignal
|
|
5
|
+
timeout?: number
|
|
6
|
+
defaultValue?: T
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export default function firstValueFrom<T>(
|
|
10
|
+
source: Observable<T>,
|
|
11
|
+
config?: FirstValueFromConfig<T>,
|
|
12
|
+
): Promise<T>
|