@event-driven-io/emmett-expressjs 0.38.6 → 0.39.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/dist/index.cjs +1 -240
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -240
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/index.ts
|
|
2
2
|
require('express-async-errors');
|
|
3
3
|
|
|
4
4
|
// src/application.ts
|
|
@@ -8,49 +8,12 @@ var _http = require('http'); var _http2 = _interopRequireDefault(_http);
|
|
|
8
8
|
|
|
9
9
|
// ../emmett/dist/chunk-O2VMBOV4.js
|
|
10
10
|
var isNumber = (val) => typeof val === "number" && val === val;
|
|
11
|
-
var isString = (val) => typeof val === "string";
|
|
12
|
-
var EmmettError = class _EmmettError extends Error {
|
|
13
|
-
|
|
14
|
-
constructor(options) {
|
|
15
|
-
const errorCode = options && typeof options === "object" && "errorCode" in options ? options.errorCode : isNumber(options) ? options : 500;
|
|
16
|
-
const message = options && typeof options === "object" && "message" in options ? options.message : isString(options) ? options : `Error with status code '${errorCode}' ocurred during Emmett processing`;
|
|
17
|
-
super(message);
|
|
18
|
-
this.errorCode = errorCode;
|
|
19
|
-
Object.setPrototypeOf(this, _EmmettError.prototype);
|
|
20
|
-
}
|
|
21
|
-
static mapFrom(error) {
|
|
22
|
-
if (error instanceof _EmmettError) {
|
|
23
|
-
return error;
|
|
24
|
-
}
|
|
25
|
-
return new _EmmettError({
|
|
26
|
-
errorCode: "errorCode" in error && error.errorCode !== void 0 && error.errorCode !== null ? error.errorCode : 500,
|
|
27
|
-
message: _nullishCoalesce(error.message, () => ( "An unknown error occurred"))
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
11
|
|
|
32
12
|
// ../emmett/dist/index.js
|
|
33
13
|
var _uuid = require('uuid');
|
|
34
14
|
|
|
35
15
|
var _asyncretry = require('async-retry'); var _asyncretry2 = _interopRequireDefault(_asyncretry);
|
|
36
16
|
|
|
37
|
-
var _webstreamspolyfill = require('web-streams-polyfill');
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
17
|
var ParseError = class extends Error {
|
|
55
18
|
constructor(text) {
|
|
56
19
|
super(`Cannot parse! ${text}`);
|
|
@@ -72,29 +35,6 @@ var JSONParser = {
|
|
|
72
35
|
return _optionalChain([options, 'optionalAccess', _7 => _7.map]) ? options.map(parsed) : parsed;
|
|
73
36
|
}
|
|
74
37
|
};
|
|
75
|
-
var asyncRetry = async (fn, opts) => {
|
|
76
|
-
if (opts === void 0 || opts.retries === 0) return fn();
|
|
77
|
-
return _asyncretry2.default.call(void 0,
|
|
78
|
-
async (bail) => {
|
|
79
|
-
try {
|
|
80
|
-
const result = await fn();
|
|
81
|
-
if (_optionalChain([opts, 'optionalAccess', _8 => _8.shouldRetryResult]) && opts.shouldRetryResult(result)) {
|
|
82
|
-
throw new EmmettError(
|
|
83
|
-
`Retrying because of result: ${JSONParser.stringify(result)}`
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
return result;
|
|
87
|
-
} catch (error2) {
|
|
88
|
-
if (_optionalChain([opts, 'optionalAccess', _9 => _9.shouldRetryError]) && !opts.shouldRetryError(error2)) {
|
|
89
|
-
bail(error2);
|
|
90
|
-
return void 0;
|
|
91
|
-
}
|
|
92
|
-
throw error2;
|
|
93
|
-
}
|
|
94
|
-
},
|
|
95
|
-
_nullishCoalesce(opts, () => ( { retries: 0 }))
|
|
96
|
-
);
|
|
97
|
-
};
|
|
98
38
|
var AssertionError = class extends Error {
|
|
99
39
|
constructor(message2) {
|
|
100
40
|
super(message2);
|
|
@@ -174,185 +114,6 @@ var WrapEventStore = (eventStore) => {
|
|
|
174
114
|
};
|
|
175
115
|
return wrapped;
|
|
176
116
|
};
|
|
177
|
-
var notifyAboutNoActiveReadersStream = (onNoActiveReaderCallback, options = {}) => new NotifyAboutNoActiveReadersStream(onNoActiveReaderCallback, options);
|
|
178
|
-
var NotifyAboutNoActiveReadersStream = (_class = class extends _webstreamspolyfill.TransformStream {
|
|
179
|
-
constructor(onNoActiveReaderCallback, options = {}) {
|
|
180
|
-
super({
|
|
181
|
-
cancel: (reason) => {
|
|
182
|
-
console.log("Stream was canceled. Reason:", reason);
|
|
183
|
-
this.stopChecking();
|
|
184
|
-
}
|
|
185
|
-
});_class.prototype.__init.call(this);_class.prototype.__init2.call(this);;
|
|
186
|
-
this.onNoActiveReaderCallback = onNoActiveReaderCallback;
|
|
187
|
-
this.streamId = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _10 => _10.streamId]), () => ( _uuid.v4.call(void 0, )));
|
|
188
|
-
this.onNoActiveReaderCallback = onNoActiveReaderCallback;
|
|
189
|
-
this.startChecking(_nullishCoalesce(_optionalChain([options, 'optionalAccess', _11 => _11.intervalCheckInMs]), () => ( 20)));
|
|
190
|
-
}
|
|
191
|
-
__init() {this.checkInterval = null}
|
|
192
|
-
|
|
193
|
-
__init2() {this._isStopped = false}
|
|
194
|
-
get hasActiveSubscribers() {
|
|
195
|
-
return !this._isStopped;
|
|
196
|
-
}
|
|
197
|
-
startChecking(interval) {
|
|
198
|
-
this.checkInterval = setInterval(() => {
|
|
199
|
-
this.checkNoActiveReader();
|
|
200
|
-
}, interval);
|
|
201
|
-
}
|
|
202
|
-
stopChecking() {
|
|
203
|
-
if (!this.checkInterval) return;
|
|
204
|
-
clearInterval(this.checkInterval);
|
|
205
|
-
this.checkInterval = null;
|
|
206
|
-
this._isStopped = true;
|
|
207
|
-
this.onNoActiveReaderCallback(this);
|
|
208
|
-
}
|
|
209
|
-
checkNoActiveReader() {
|
|
210
|
-
if (!this.readable.locked && !this._isStopped) {
|
|
211
|
-
this.stopChecking();
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
}, _class);
|
|
215
|
-
var filter = (filter2) => new (0, _webstreamspolyfill.TransformStream)({
|
|
216
|
-
transform(chunk, controller) {
|
|
217
|
-
if (filter2(chunk)) {
|
|
218
|
-
controller.enqueue(chunk);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
});
|
|
222
|
-
var map = (map2) => new (0, _webstreamspolyfill.TransformStream)({
|
|
223
|
-
transform(chunk, controller) {
|
|
224
|
-
controller.enqueue(map2(chunk));
|
|
225
|
-
}
|
|
226
|
-
});
|
|
227
|
-
var reduce = (reducer, initialValue) => new ReduceTransformStream(reducer, initialValue);
|
|
228
|
-
var ReduceTransformStream = class extends _webstreamspolyfill.TransformStream {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
constructor(reducer, initialValue) {
|
|
232
|
-
super({
|
|
233
|
-
transform: (chunk) => {
|
|
234
|
-
this.accumulator = this.reducer(this.accumulator, chunk);
|
|
235
|
-
},
|
|
236
|
-
flush: (controller) => {
|
|
237
|
-
controller.enqueue(this.accumulator);
|
|
238
|
-
controller.terminate();
|
|
239
|
-
}
|
|
240
|
-
});
|
|
241
|
-
this.accumulator = initialValue;
|
|
242
|
-
this.reducer = reducer;
|
|
243
|
-
}
|
|
244
|
-
};
|
|
245
|
-
var retryStream = (createSourceStream, handleChunk2, retryOptions = { forever: true, minTimeout: 25 }) => new (0, _webstreamspolyfill.TransformStream)({
|
|
246
|
-
start(controller) {
|
|
247
|
-
asyncRetry(
|
|
248
|
-
() => onRestream(createSourceStream, handleChunk2, controller),
|
|
249
|
-
retryOptions
|
|
250
|
-
).catch((error2) => {
|
|
251
|
-
controller.error(error2);
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
});
|
|
255
|
-
var onRestream = async (createSourceStream, handleChunk2, controller) => {
|
|
256
|
-
const sourceStream = createSourceStream();
|
|
257
|
-
const reader = sourceStream.getReader();
|
|
258
|
-
try {
|
|
259
|
-
let done;
|
|
260
|
-
do {
|
|
261
|
-
const result = await reader.read();
|
|
262
|
-
done = result.done;
|
|
263
|
-
await handleChunk2(result, controller);
|
|
264
|
-
if (done) {
|
|
265
|
-
controller.terminate();
|
|
266
|
-
}
|
|
267
|
-
} while (!done);
|
|
268
|
-
} finally {
|
|
269
|
-
reader.releaseLock();
|
|
270
|
-
}
|
|
271
|
-
};
|
|
272
|
-
var skip = (limit) => new SkipTransformStream(limit);
|
|
273
|
-
var SkipTransformStream = (_class2 = class extends _webstreamspolyfill.TransformStream {
|
|
274
|
-
__init3() {this.count = 0}
|
|
275
|
-
|
|
276
|
-
constructor(skip2) {
|
|
277
|
-
super({
|
|
278
|
-
transform: (chunk, controller) => {
|
|
279
|
-
this.count++;
|
|
280
|
-
if (this.count > this.skip) {
|
|
281
|
-
controller.enqueue(chunk);
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
});_class2.prototype.__init3.call(this);;
|
|
285
|
-
this.skip = skip2;
|
|
286
|
-
}
|
|
287
|
-
}, _class2);
|
|
288
|
-
var stopAfter = (stopCondition) => new (0, _webstreamspolyfill.TransformStream)({
|
|
289
|
-
transform(chunk, controller) {
|
|
290
|
-
controller.enqueue(chunk);
|
|
291
|
-
if (stopCondition(chunk)) {
|
|
292
|
-
controller.terminate();
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
});
|
|
296
|
-
var stopOn = (stopCondition) => new (0, _webstreamspolyfill.TransformStream)({
|
|
297
|
-
async transform(chunk, controller) {
|
|
298
|
-
if (!stopCondition(chunk)) {
|
|
299
|
-
controller.enqueue(chunk);
|
|
300
|
-
return;
|
|
301
|
-
}
|
|
302
|
-
await Promise.resolve();
|
|
303
|
-
controller.terminate();
|
|
304
|
-
}
|
|
305
|
-
});
|
|
306
|
-
var take = (limit) => new TakeTransformStream(limit);
|
|
307
|
-
var TakeTransformStream = (_class3 = class extends _webstreamspolyfill.TransformStream {
|
|
308
|
-
__init4() {this.count = 0}
|
|
309
|
-
|
|
310
|
-
constructor(limit) {
|
|
311
|
-
super({
|
|
312
|
-
transform: (chunk, controller) => {
|
|
313
|
-
if (this.count < this.limit) {
|
|
314
|
-
this.count++;
|
|
315
|
-
controller.enqueue(chunk);
|
|
316
|
-
} else {
|
|
317
|
-
controller.terminate();
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
});_class3.prototype.__init4.call(this);;
|
|
321
|
-
this.limit = limit;
|
|
322
|
-
}
|
|
323
|
-
}, _class3);
|
|
324
|
-
var waitAtMost = (waitTimeInMs) => new (0, _webstreamspolyfill.TransformStream)({
|
|
325
|
-
start(controller) {
|
|
326
|
-
const timeoutId = setTimeout(() => {
|
|
327
|
-
controller.terminate();
|
|
328
|
-
}, waitTimeInMs);
|
|
329
|
-
const originalTerminate = controller.terminate.bind(controller);
|
|
330
|
-
controller.terminate = () => {
|
|
331
|
-
clearTimeout(timeoutId);
|
|
332
|
-
originalTerminate();
|
|
333
|
-
};
|
|
334
|
-
},
|
|
335
|
-
transform(chunk, controller) {
|
|
336
|
-
controller.enqueue(chunk);
|
|
337
|
-
}
|
|
338
|
-
});
|
|
339
|
-
var streamTransformations = {
|
|
340
|
-
filter,
|
|
341
|
-
take,
|
|
342
|
-
TakeTransformStream,
|
|
343
|
-
skip,
|
|
344
|
-
SkipTransformStream,
|
|
345
|
-
map,
|
|
346
|
-
notifyAboutNoActiveReadersStream,
|
|
347
|
-
NotifyAboutNoActiveReadersStream,
|
|
348
|
-
reduce,
|
|
349
|
-
ReduceTransformStream,
|
|
350
|
-
retry: retryStream,
|
|
351
|
-
stopAfter,
|
|
352
|
-
stopOn,
|
|
353
|
-
waitAtMost
|
|
354
|
-
};
|
|
355
|
-
var { retry: retry2 } = streamTransformations;
|
|
356
117
|
|
|
357
118
|
// src/middlewares/problemDetailsMiddleware.ts
|
|
358
119
|
var _httpproblemdetails = require('http-problem-details');
|