@nxtedition/lib 22.1.3 → 22.2.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/couch.d.ts +69 -0
- package/deepstream.d.ts +19 -0
- package/errors.d.ts +48 -0
- package/logger.d.ts +18 -0
- package/package.json +6 -1
- package/rxjs/firstValueFrom.d.ts +12 -0
- package/scheduler.js +32 -0
- package/util/template/javascript.js +1 -6
package/couch.d.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
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
|
+
seq?: string
|
|
22
|
+
signal?: AbortSignal
|
|
23
|
+
logger?: Logger
|
|
24
|
+
stream?: Stream
|
|
25
|
+
// TODO add more or extend undicii type?
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface CouchResponse<T> {
|
|
29
|
+
rows: T[]
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function request<T, Stream extends boolean = false>(
|
|
33
|
+
url: string | URL | { origin: string; path?: string; pathname?: string },
|
|
34
|
+
opts?: CouchRequestOptions<Stream> | null,
|
|
35
|
+
): Stream extends true ? AsyncGenerator<T> & { length: number } : Promise<CouchResponse<T>>
|
|
36
|
+
|
|
37
|
+
interface ChangesOptions {
|
|
38
|
+
signal?: AbortSignal | null
|
|
39
|
+
descending?: boolean
|
|
40
|
+
include_docs?: boolean
|
|
41
|
+
seq_interval?: number | null
|
|
42
|
+
live?: boolean
|
|
43
|
+
heartbeat?: number
|
|
44
|
+
retry?: (
|
|
45
|
+
err: HttpError,
|
|
46
|
+
retryCount: number,
|
|
47
|
+
params: {
|
|
48
|
+
since?: string | 0 | null
|
|
49
|
+
},
|
|
50
|
+
ac: { signal: AbortSignal },
|
|
51
|
+
next: () => void,
|
|
52
|
+
) => void | null | Promise<void>
|
|
53
|
+
since?: string | 0 | null
|
|
54
|
+
selector?: object | null
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
interface ChangeItem {
|
|
58
|
+
id: string
|
|
59
|
+
seq?: string
|
|
60
|
+
doc?: object
|
|
61
|
+
deleted?: boolean
|
|
62
|
+
changes: Array<{ rev: string }>
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface CouchClient {
|
|
66
|
+
changes: (
|
|
67
|
+
options?: ChangesOptions & { client?: unknown; logger?: Logger },
|
|
68
|
+
) => AsyncGenerator<ChangeItem[] & { lastSeq?: string | 0 | null }, void, unknown>
|
|
69
|
+
}
|
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,48 @@
|
|
|
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
|
+
type SerializableError = null | undefined | Error | string | NxtError | SerializableError[]
|
|
21
|
+
|
|
22
|
+
export function serializeError(err: SerializableError): NxtError[] | null
|
|
23
|
+
|
|
24
|
+
export type Message = {
|
|
25
|
+
msg: string
|
|
26
|
+
title?: string
|
|
27
|
+
id: string
|
|
28
|
+
level: number
|
|
29
|
+
code?: string
|
|
30
|
+
data?: object
|
|
31
|
+
expose?: boolean | null
|
|
32
|
+
index?: object | null
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export type MessageOptions = {
|
|
36
|
+
id?: string
|
|
37
|
+
level?: number
|
|
38
|
+
code?: string
|
|
39
|
+
codes?: Record<string, string>
|
|
40
|
+
index?: boolean
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function makeMessages(
|
|
44
|
+
error: MessageError | MessageError[],
|
|
45
|
+
options?: MessageOptions,
|
|
46
|
+
): Message[]
|
|
47
|
+
|
|
48
|
+
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.
|
|
3
|
+
"version": "22.2.0",
|
|
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,9 +31,12 @@
|
|
|
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",
|
|
39
|
+
"scheduler.js",
|
|
35
40
|
"stream.js",
|
|
36
41
|
"timeline.js",
|
|
37
42
|
"docker-secrets.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>
|
package/scheduler.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { setImmediate } from 'timers/promises'
|
|
2
|
+
|
|
3
|
+
let yieldTime = performance.now()
|
|
4
|
+
let yieldPromise = undefined
|
|
5
|
+
|
|
6
|
+
function reset() {
|
|
7
|
+
yieldTime = performance.now()
|
|
8
|
+
yieldPromise = undefined
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
setInterval(reset, 100).unref()
|
|
12
|
+
|
|
13
|
+
export function shouldYield() {
|
|
14
|
+
if (yieldPromise === undefined) {
|
|
15
|
+
yieldPromise = performance.now() - yieldTime > 50 ? null : undefined
|
|
16
|
+
}
|
|
17
|
+
return yieldPromise !== undefined
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function maybeYield() {
|
|
21
|
+
if (yieldPromise === undefined) {
|
|
22
|
+
yieldPromise = performance.now() - yieldTime > 50 ? null : undefined
|
|
23
|
+
}
|
|
24
|
+
if (yieldPromise === null) {
|
|
25
|
+
yieldPromise = setImmediate().then(reset)
|
|
26
|
+
}
|
|
27
|
+
return yieldPromise ?? null
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function yield() {
|
|
31
|
+
return (yieldPromise ??= setImmediate().then(reset))
|
|
32
|
+
}
|
|
@@ -233,7 +233,6 @@ export default function ({ ds, proxify, compiler }) {
|
|
|
233
233
|
this._wrap = null
|
|
234
234
|
this._suspended = false
|
|
235
235
|
this._errored = false
|
|
236
|
-
this._refreshImpl = this._refreshImpl.bind(this)
|
|
237
236
|
|
|
238
237
|
if (rxjs.isObservable(args)) {
|
|
239
238
|
this._subscription = args.subscribe({
|
|
@@ -243,10 +242,6 @@ export default function ({ ds, proxify, compiler }) {
|
|
|
243
242
|
},
|
|
244
243
|
error: (err) => {
|
|
245
244
|
this._observer.error(err)
|
|
246
|
-
this._subscription = null
|
|
247
|
-
},
|
|
248
|
-
complete: () => {
|
|
249
|
-
this._subscription = null
|
|
250
245
|
},
|
|
251
246
|
})
|
|
252
247
|
} else {
|
|
@@ -338,7 +333,7 @@ export default function ({ ds, proxify, compiler }) {
|
|
|
338
333
|
this._entries.clear()
|
|
339
334
|
}
|
|
340
335
|
|
|
341
|
-
_refreshImpl() {
|
|
336
|
+
_refreshImpl = () => {
|
|
342
337
|
this._refreshing = false
|
|
343
338
|
|
|
344
339
|
if (this._destroyed || this._disposing || this._args === kEmpty) {
|