@nxtedition/lib 19.0.27 → 19.0.28
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/deepstream.js +22 -0
- package/http.js +5 -2
- package/package.json +1 -1
package/deepstream.js
CHANGED
|
@@ -119,6 +119,25 @@ function get(ds, name, ...args) {
|
|
|
119
119
|
)
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
+
function getRecord(ds, name, ...args) {
|
|
123
|
+
let query = null
|
|
124
|
+
|
|
125
|
+
if (args.length > 0 && (args[0] == null || typeof args[0] === 'object')) {
|
|
126
|
+
query = args.shift()
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
name = `${name}`
|
|
130
|
+
|
|
131
|
+
return ds.record.getRecord(
|
|
132
|
+
`${name}${
|
|
133
|
+
query && Object.keys(query).length > 0
|
|
134
|
+
? `${name.endsWith('?') ? '' : '?'}${qs.stringify(query, { skipNulls: true })}`
|
|
135
|
+
: ''
|
|
136
|
+
}`,
|
|
137
|
+
...args,
|
|
138
|
+
)
|
|
139
|
+
}
|
|
140
|
+
|
|
122
141
|
function query(ds, designId, options) {
|
|
123
142
|
const next = (startkey, prevRows, limit) =>
|
|
124
143
|
Number.isFinite(limit) && limit <= 0
|
|
@@ -164,6 +183,7 @@ export function makeDeepstream(ds) {
|
|
|
164
183
|
query: (...args) => query(ds, ...args),
|
|
165
184
|
set: (...args) => ds.record.set(...args),
|
|
166
185
|
get: (...args) => get(ds, ...args),
|
|
186
|
+
getRecord: (...args) => getRecord(ds, ...args),
|
|
167
187
|
update: (...args) => ds.record.update(...args),
|
|
168
188
|
},
|
|
169
189
|
}
|
|
@@ -177,11 +197,13 @@ Object.assign(makeDeepstream, {
|
|
|
177
197
|
observe2,
|
|
178
198
|
query,
|
|
179
199
|
get,
|
|
200
|
+
getRecord,
|
|
180
201
|
record: {
|
|
181
202
|
provide,
|
|
182
203
|
observe,
|
|
183
204
|
observe2,
|
|
184
205
|
query,
|
|
185
206
|
get,
|
|
207
|
+
getRecord,
|
|
186
208
|
},
|
|
187
209
|
})
|
package/http.js
CHANGED
|
@@ -23,6 +23,9 @@ function genReqId() {
|
|
|
23
23
|
return `req-${nextReqId.toString(36)}`
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
let reqTimeoutError
|
|
27
|
+
let resTimeoutError
|
|
28
|
+
|
|
26
29
|
export async function request(ctx, next) {
|
|
27
30
|
const { req, res, logger } = ctx
|
|
28
31
|
const startTime = performance.now()
|
|
@@ -62,14 +65,14 @@ export async function request(ctx, next) {
|
|
|
62
65
|
new Promise((resolve, reject) => {
|
|
63
66
|
req
|
|
64
67
|
.on('timeout', function () {
|
|
65
|
-
this.destroy(new createError.RequestTimeout())
|
|
68
|
+
this.destroy((reqTimeoutError ??= new createError.RequestTimeout()))
|
|
66
69
|
})
|
|
67
70
|
.on('error', function (err) {
|
|
68
71
|
this.log.error({ err }, 'request error')
|
|
69
72
|
})
|
|
70
73
|
res
|
|
71
74
|
.on('timeout', function () {
|
|
72
|
-
this.destroy(new createError.RequestTimeout())
|
|
75
|
+
this.destroy((resTimeoutError ??= new createError.RequestTimeout()))
|
|
73
76
|
})
|
|
74
77
|
.on('error', function (err) {
|
|
75
78
|
reject(err)
|