@tstdl/base 0.83.27 → 0.84.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.
Files changed (55) hide show
  1. package/application/application.d.ts +1 -1
  2. package/application/application.js +4 -4
  3. package/browser/browser-context-controller.d.ts +32 -0
  4. package/browser/browser-context-controller.js +88 -0
  5. package/browser/browser-controller.d.ts +45 -0
  6. package/browser/browser-controller.js +109 -0
  7. package/browser/browser.service.d.ts +34 -0
  8. package/browser/browser.service.js +107 -0
  9. package/browser/index.d.ts +4 -0
  10. package/browser/index.js +21 -0
  11. package/browser/page-controller.d.ts +54 -0
  12. package/browser/page-controller.js +166 -0
  13. package/browser/pdf-options.d.ts +36 -0
  14. package/browser/pdf-options.js +138 -0
  15. package/browser/utils.d.ts +6 -0
  16. package/browser/utils.js +60 -0
  17. package/core.d.ts +1 -1
  18. package/data-structures/cache.d.ts +11 -0
  19. package/data-structures/cache.js +69 -0
  20. package/data-structures/index.d.ts +1 -0
  21. package/data-structures/index.js +1 -0
  22. package/disposable/async-disposer.d.ts +2 -1
  23. package/error/index.d.ts +1 -0
  24. package/error/index.js +1 -0
  25. package/error/timeout.error.d.ts +5 -0
  26. package/error/timeout.error.js +30 -0
  27. package/examples/browser/basic.d.ts +1 -0
  28. package/examples/browser/basic.js +19 -0
  29. package/examples/mail/basic.js +11 -3
  30. package/examples/pdf/basic.js +33 -7
  31. package/examples/pdf/templates/hello-name.js +10 -2
  32. package/http/client/http-client-request.js +1 -1
  33. package/http/server/node/node-http-server.js +1 -1
  34. package/lock/web/web-lock.js +2 -2
  35. package/package.json +6 -6
  36. package/pdf/pdf.service.d.ts +23 -58
  37. package/pdf/pdf.service.js +33 -203
  38. package/pool/pool.d.ts +1 -0
  39. package/pool/pool.js +6 -0
  40. package/queue/mongo/queue.js +2 -2
  41. package/types.d.ts +3 -0
  42. package/utils/cancellation-token.d.ts +11 -16
  43. package/utils/cancellation-token.js +10 -39
  44. package/utils/index.d.ts +1 -0
  45. package/utils/index.js +1 -0
  46. package/utils/stream/finalize-stream.d.ts +22 -1
  47. package/utils/stream/finalize-stream.js +14 -4
  48. package/utils/stream/readable-stream-from-promise.d.ts +2 -1
  49. package/utils/stream/readable-stream-from-promise.js +3 -2
  50. package/utils/timing.d.ts +7 -1
  51. package/utils/timing.js +23 -3
  52. package/utils/type-guards.d.ts +6 -0
  53. package/utils/type-guards.js +26 -0
  54. package/utils/value-or-provider.d.ts +2 -0
  55. package/utils/value-or-provider.js +30 -0
@@ -0,0 +1,166 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var page_controller_exports = {};
20
+ __export(page_controller_exports, {
21
+ PageController: () => PageController
22
+ });
23
+ module.exports = __toCommonJS(page_controller_exports);
24
+ var import_disposable = require("../disposable/disposable.js");
25
+ var import_readable_stream_from_promise = require("../utils/stream/readable-stream-from-promise.js");
26
+ var import_timing = require("../utils/timing.js");
27
+ var import_type_guards = require("../utils/type-guards.js");
28
+ var import_units = require("../utils/units.js");
29
+ class PageController {
30
+ ownedContext;
31
+ /** @deprecated should be avoided */
32
+ page;
33
+ options;
34
+ constructor(page, options = {}) {
35
+ this.page = page;
36
+ this.options = options;
37
+ }
38
+ async [import_disposable.disposeAsync]() {
39
+ await this.close();
40
+ }
41
+ async close() {
42
+ if ((0, import_type_guards.isDefined)(this.ownedContext)) {
43
+ await this.ownedContext.close();
44
+ } else {
45
+ await this.page.close();
46
+ }
47
+ }
48
+ async setContent(html, options) {
49
+ await this.page.setContent(html, { timeout: options?.timeout, waitUntil: options?.waitUntil });
50
+ }
51
+ async setExtraHttpHeaders(headers) {
52
+ await this.page.setExtraHTTPHeaders(headers);
53
+ }
54
+ async navigate(url, options) {
55
+ await this.page.goto(url, { timeout: options?.timeout, waitUntil: options?.waitUntil });
56
+ }
57
+ async waitForClose() {
58
+ return new Promise((resolve) => {
59
+ if (this.page.isClosed()) {
60
+ resolve();
61
+ return;
62
+ }
63
+ this.page.once("close", () => resolve());
64
+ });
65
+ }
66
+ async waitForState(state, options) {
67
+ await this.page.waitForLoadState(state, { timeout: options?.timeout });
68
+ }
69
+ async waitForNetworkIdle(options) {
70
+ await this.page.waitForLoadState("networkidle", { timeout: options?.timeout });
71
+ }
72
+ async waitForUrl(urlOrPredicate, options) {
73
+ await this.page.waitForURL(urlOrPredicate, { timeout: options?.timeout });
74
+ }
75
+ async waitForFrame(selector, options) {
76
+ const handle = await this.page.waitForSelector(selector, { timeout: options?.timeout });
77
+ const frame = await handle.contentFrame();
78
+ (0, import_type_guards.assertNotNull)(frame, "Could not get frame for specified selector.");
79
+ return new PageController(frame.page());
80
+ }
81
+ async fill(selector, text, options) {
82
+ await this.prepareAction();
83
+ const locator = this.page.locator(selector);
84
+ await locator.fill(text, { timeout: options?.timeout });
85
+ }
86
+ async type(selector, text, options) {
87
+ await this.prepareAction();
88
+ const locator = this.page.locator(selector);
89
+ await locator.focus({ timeout: options?.timeout });
90
+ if ((0, import_type_guards.isUndefined)(this.options.typeDelay)) {
91
+ await locator.type(text, { timeout: options?.timeout });
92
+ } else {
93
+ for (const char of text) {
94
+ await locator.type(char, { timeout: options?.timeout });
95
+ await delay(options?.delay ?? this.options.typeDelay);
96
+ }
97
+ }
98
+ }
99
+ async selectOption(selector, value, options) {
100
+ await this.prepareAction();
101
+ const locator = this.page.locator(selector);
102
+ await locator.selectOption(value, { timeout: options?.timeout });
103
+ }
104
+ async click(selector, options) {
105
+ await this.prepareAction();
106
+ const locator = this.page.locator(selector);
107
+ await locator.click({ delay: 50, timeout: options?.timeout });
108
+ }
109
+ async getValue(selector, options) {
110
+ const locator = this.page.locator(selector);
111
+ return locator.inputValue({ timeout: options?.timeout });
112
+ }
113
+ async waitForElement(selector, options) {
114
+ const locator = this.page.locator(selector);
115
+ return locator.waitFor({ timeout: options?.timeout });
116
+ }
117
+ async renderPdf(options = {}) {
118
+ const createPdfOptions = convertPdfOptions(options);
119
+ return (0, import_timing.withTimeout)(options.timeout ?? 30 * import_units.millisecondsPerSecond, this.page.pdf(createPdfOptions), { errorMessage: "Rendering pdf timed out." });
120
+ }
121
+ renderPdfStream(options = {}) {
122
+ return (0, import_readable_stream_from_promise.readableStreamFromPromise)(async () => {
123
+ const buffer = await this.renderPdf(options);
124
+ return new ReadableStream({
125
+ pull(controller) {
126
+ controller.enqueue(buffer);
127
+ controller.close();
128
+ }
129
+ });
130
+ });
131
+ }
132
+ async prepareAction() {
133
+ await delay(this.options.actionDelay);
134
+ await this.waitForNetworkIdle();
135
+ }
136
+ }
137
+ async function delay(milliseconds) {
138
+ if ((0, import_type_guards.isUndefined)(milliseconds)) {
139
+ return;
140
+ }
141
+ if ((0, import_type_guards.isNumber)(milliseconds)) {
142
+ await (0, import_timing.timeout)(milliseconds);
143
+ } else {
144
+ await (0, import_timing.timeout)(milliseconds());
145
+ }
146
+ }
147
+ function convertPdfOptions(options) {
148
+ const margin = (0, import_type_guards.isUndefined)(options.margin) ? void 0 : (0, import_type_guards.isObject)(options.margin) ? options.margin : {
149
+ top: options.margin,
150
+ bottom: options.margin,
151
+ right: options.margin,
152
+ left: options.margin
153
+ };
154
+ return {
155
+ format: options.format ?? "a4",
156
+ scale: options.scale,
157
+ landscape: options.landscape,
158
+ width: options.width,
159
+ height: options.height,
160
+ printBackground: options.renderBackground,
161
+ margin,
162
+ displayHeaderFooter: options.displayHeaderFooter ?? ((0, import_type_guards.isDefined)(options.headerTemplate) || (0, import_type_guards.isDefined)(options.footerTemplate)),
163
+ headerTemplate: options.headerTemplate,
164
+ footerTemplate: options.footerTemplate
165
+ };
166
+ }
@@ -0,0 +1,36 @@
1
+ export declare enum PdfFormat {
2
+ Letter = "letter",
3
+ Legal = "legal",
4
+ Tabloid = "tabloid",
5
+ Ledger = "ledger",
6
+ A0 = "a0",
7
+ A1 = "a1",
8
+ A2 = "a2",
9
+ A3 = "a3",
10
+ A4 = "a4",
11
+ A5 = "a5",
12
+ A6 = "a6"
13
+ }
14
+ export declare class PdfMarginObject {
15
+ top?: number | string;
16
+ bottom?: number | string;
17
+ right?: number | string;
18
+ left?: number | string;
19
+ }
20
+ export declare class PdfRenderOptions {
21
+ renderBackground?: boolean;
22
+ landscape?: boolean;
23
+ format?: PdfFormat;
24
+ width?: string | number;
25
+ height?: string | number;
26
+ scale?: number;
27
+ margin?: string | number | PdfMarginObject;
28
+ displayHeaderFooter?: boolean;
29
+ headerTemplate?: string;
30
+ footerTemplate?: string;
31
+ /**
32
+ * Timeout for closing render context in case something went wrong.
33
+ * @default 60000 (1 minute)
34
+ */
35
+ timeout?: number;
36
+ }
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var pdf_options_exports = {};
20
+ __export(pdf_options_exports, {
21
+ PdfFormat: () => PdfFormat,
22
+ PdfMarginObject: () => PdfMarginObject,
23
+ PdfRenderOptions: () => PdfRenderOptions
24
+ });
25
+ module.exports = __toCommonJS(pdf_options_exports);
26
+ var import_enumeration = require("../schema/schemas/enumeration.js");
27
+ var import_optional = require("../schema/schemas/optional.js");
28
+ var __decorate = function(decorators, target, key, desc) {
29
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
30
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
31
+ r = Reflect.decorate(decorators, target, key, desc);
32
+ else
33
+ for (var i = decorators.length - 1; i >= 0; i--)
34
+ if (d = decorators[i])
35
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
36
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
37
+ };
38
+ var __metadata = function(k, v) {
39
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
40
+ return Reflect.metadata(k, v);
41
+ };
42
+ var PdfFormat;
43
+ (function(PdfFormat2) {
44
+ PdfFormat2["Letter"] = "letter";
45
+ PdfFormat2["Legal"] = "legal";
46
+ PdfFormat2["Tabloid"] = "tabloid";
47
+ PdfFormat2["Ledger"] = "ledger";
48
+ PdfFormat2["A0"] = "a0";
49
+ PdfFormat2["A1"] = "a1";
50
+ PdfFormat2["A2"] = "a2";
51
+ PdfFormat2["A3"] = "a3";
52
+ PdfFormat2["A4"] = "a4";
53
+ PdfFormat2["A5"] = "a5";
54
+ PdfFormat2["A6"] = "a6";
55
+ })(PdfFormat || (PdfFormat = {}));
56
+ class PdfMarginObject {
57
+ top;
58
+ bottom;
59
+ right;
60
+ left;
61
+ }
62
+ __decorate([
63
+ (0, import_optional.Optional)([Number, String]),
64
+ __metadata("design:type", Object)
65
+ ], PdfMarginObject.prototype, "top", void 0);
66
+ __decorate([
67
+ (0, import_optional.Optional)([Number, String]),
68
+ __metadata("design:type", Object)
69
+ ], PdfMarginObject.prototype, "bottom", void 0);
70
+ __decorate([
71
+ (0, import_optional.Optional)([Number, String]),
72
+ __metadata("design:type", Object)
73
+ ], PdfMarginObject.prototype, "right", void 0);
74
+ __decorate([
75
+ (0, import_optional.Optional)([Number, String]),
76
+ __metadata("design:type", Object)
77
+ ], PdfMarginObject.prototype, "left", void 0);
78
+ class PdfRenderOptions {
79
+ renderBackground;
80
+ landscape;
81
+ format;
82
+ width;
83
+ height;
84
+ scale;
85
+ margin;
86
+ displayHeaderFooter;
87
+ headerTemplate;
88
+ footerTemplate;
89
+ /**
90
+ * Timeout for closing render context in case something went wrong.
91
+ * @default 60000 (1 minute)
92
+ */
93
+ timeout;
94
+ }
95
+ __decorate([
96
+ (0, import_optional.Optional)(),
97
+ __metadata("design:type", Boolean)
98
+ ], PdfRenderOptions.prototype, "renderBackground", void 0);
99
+ __decorate([
100
+ (0, import_optional.Optional)(),
101
+ __metadata("design:type", Boolean)
102
+ ], PdfRenderOptions.prototype, "landscape", void 0);
103
+ __decorate([
104
+ (0, import_enumeration.Enumeration)(PdfFormat, { optional: true }),
105
+ __metadata("design:type", String)
106
+ ], PdfRenderOptions.prototype, "format", void 0);
107
+ __decorate([
108
+ (0, import_optional.Optional)([String, Number]),
109
+ __metadata("design:type", Object)
110
+ ], PdfRenderOptions.prototype, "width", void 0);
111
+ __decorate([
112
+ (0, import_optional.Optional)([String, Number]),
113
+ __metadata("design:type", Object)
114
+ ], PdfRenderOptions.prototype, "height", void 0);
115
+ __decorate([
116
+ (0, import_optional.Optional)(),
117
+ __metadata("design:type", Number)
118
+ ], PdfRenderOptions.prototype, "scale", void 0);
119
+ __decorate([
120
+ (0, import_optional.Optional)([String, Number, PdfMarginObject]),
121
+ __metadata("design:type", Object)
122
+ ], PdfRenderOptions.prototype, "margin", void 0);
123
+ __decorate([
124
+ (0, import_optional.Optional)(),
125
+ __metadata("design:type", Boolean)
126
+ ], PdfRenderOptions.prototype, "displayHeaderFooter", void 0);
127
+ __decorate([
128
+ (0, import_optional.Optional)(),
129
+ __metadata("design:type", String)
130
+ ], PdfRenderOptions.prototype, "headerTemplate", void 0);
131
+ __decorate([
132
+ (0, import_optional.Optional)(),
133
+ __metadata("design:type", String)
134
+ ], PdfRenderOptions.prototype, "footerTemplate", void 0);
135
+ __decorate([
136
+ (0, import_optional.Optional)(),
137
+ __metadata("design:type", Number)
138
+ ], PdfRenderOptions.prototype, "timeout", void 0);
@@ -0,0 +1,6 @@
1
+ import type { BrowserType, LaunchOptions } from 'playwright';
2
+ import type { NewBrowserContextOptions } from './browser-controller.js';
3
+ import type { NewBrowserOptions } from './browser.service.js';
4
+ export declare function getLaunchOptions(options: NewBrowserOptions): LaunchOptions;
5
+ export declare function mergeNewBrowserContextOptions(a: NewBrowserContextOptions | undefined, b?: NewBrowserContextOptions, c?: NewBrowserContextOptions): NewBrowserContextOptions;
6
+ export declare function getBrowserType(type: string | undefined): BrowserType;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var utils_exports = {};
20
+ __export(utils_exports, {
21
+ getBrowserType: () => getBrowserType,
22
+ getLaunchOptions: () => getLaunchOptions,
23
+ mergeNewBrowserContextOptions: () => mergeNewBrowserContextOptions
24
+ });
25
+ module.exports = __toCommonJS(utils_exports);
26
+ var import_not_supported_error = require("../error/not-supported.error.js");
27
+ var import_object = require("../utils/object/object.js");
28
+ var import_playwright = require("playwright");
29
+ function getLaunchOptions(options) {
30
+ const { windowSize, browserArguments, headless } = options;
31
+ const args = [`--window-size=${windowSize?.width ?? 1e3},${windowSize?.height ?? 1e3}`, ...browserArguments ?? []];
32
+ return { headless, args };
33
+ }
34
+ function mergeNewBrowserContextOptions(a, b, c) {
35
+ const mergedExtraHttpHeaders = { ...a?.extraHttpHeaders, ...b?.extraHttpHeaders, ...c?.extraHttpHeaders };
36
+ return {
37
+ ...a,
38
+ ...b,
39
+ ...c,
40
+ extraHttpHeaders: (0, import_object.objectKeys)(mergedExtraHttpHeaders).length > 0 ? mergedExtraHttpHeaders : void 0
41
+ };
42
+ }
43
+ function getBrowserType(type) {
44
+ let browserType;
45
+ switch (type) {
46
+ case "chromium":
47
+ case void 0:
48
+ browserType = import_playwright.chromium;
49
+ break;
50
+ case "firefox":
51
+ browserType = import_playwright.firefox;
52
+ break;
53
+ case "webkit":
54
+ browserType = import_playwright.webkit;
55
+ break;
56
+ default:
57
+ throw new import_not_supported_error.NotSupportedError(`Browser type ${type} is not supported.`);
58
+ }
59
+ return browserType;
60
+ }
package/core.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { InjectionToken } from './container/index.js';
2
2
  import { AsyncDisposer } from './disposable/async-disposer.js';
3
3
  import type { LoggerArgument } from './logger/index.js';
4
- import { Logger, LogLevel } from './logger/index.js';
4
+ import { LogLevel, Logger } from './logger/index.js';
5
5
  export declare const CORE_LOGGER: InjectionToken<Logger, any>;
6
6
  export declare const disposer: AsyncDisposer;
7
7
  export declare function connect(name: string, connectFunction: (() => Promise<any>), logger: Logger, maxTries?: number): Promise<void>;
@@ -0,0 +1,11 @@
1
+ export declare class Cache<K, V> {
2
+ private readonly cache;
3
+ private _capacity;
4
+ get capacity(): number;
5
+ set capacity(capacity: number);
6
+ constructor(capacity: number);
7
+ get(key: K): V | undefined;
8
+ set(key: K, value: V): void;
9
+ delete(key: K): void;
10
+ private removeEntries;
11
+ }
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var cache_exports = {};
20
+ __export(cache_exports, {
21
+ Cache: () => Cache
22
+ });
23
+ module.exports = __toCommonJS(cache_exports);
24
+ class Cache {
25
+ cache;
26
+ _capacity;
27
+ get capacity() {
28
+ return this._capacity;
29
+ }
30
+ set capacity(capacity) {
31
+ this.removeEntries(this._capacity - capacity);
32
+ this._capacity = capacity;
33
+ }
34
+ constructor(capacity) {
35
+ this._capacity = capacity;
36
+ this.cache = /* @__PURE__ */ new Map();
37
+ }
38
+ get(key) {
39
+ if (!this.cache.has(key)) {
40
+ return void 0;
41
+ }
42
+ const value = this.cache.get(key);
43
+ this.cache.delete(key);
44
+ this.cache.set(key, value);
45
+ return value;
46
+ }
47
+ set(key, value) {
48
+ const isNew = !this.cache.has(key);
49
+ if (isNew && this.cache.size >= this.capacity) {
50
+ this.removeEntries(1);
51
+ }
52
+ this.cache.set(key, value);
53
+ }
54
+ delete(key) {
55
+ this.delete(key);
56
+ }
57
+ removeEntries(count) {
58
+ if (count <= 0) {
59
+ return;
60
+ }
61
+ let left = count;
62
+ for (const key of this.cache.keys()) {
63
+ if (left-- <= 0) {
64
+ return;
65
+ }
66
+ this.cache.delete(key);
67
+ }
68
+ }
69
+ }
@@ -1,5 +1,6 @@
1
1
  export * from './array-dictionary.js';
2
2
  export * from './array-list.js';
3
+ export * from './cache.js';
3
4
  export * from './circular-buffer.js';
4
5
  export * from './collection.js';
5
6
  export * from './dictionary.js';
@@ -17,6 +17,7 @@ var data_structures_exports = {};
17
17
  module.exports = __toCommonJS(data_structures_exports);
18
18
  __reExport(data_structures_exports, require("./array-dictionary.js"), module.exports);
19
19
  __reExport(data_structures_exports, require("./array-list.js"), module.exports);
20
+ __reExport(data_structures_exports, require("./cache.js"), module.exports);
20
21
  __reExport(data_structures_exports, require("./circular-buffer.js"), module.exports);
21
22
  __reExport(data_structures_exports, require("./collection.js"), module.exports);
22
23
  __reExport(data_structures_exports, require("./dictionary.js"), module.exports);
@@ -4,6 +4,7 @@ import type { AsyncDisposable, Disposable } from './disposable.js';
4
4
  import { disposeAsync } from './disposable.js';
5
5
  declare const deferrerToken: unique symbol;
6
6
  export type TaskFunction = () => any;
7
+ export type AsyncDisposeHandler = TaskFunction | Disposable | AsyncDisposable;
7
8
  export type Task = {
8
9
  priority: number;
9
10
  taskFunction: TaskFunction;
@@ -29,7 +30,7 @@ export declare class AsyncDisposer implements AsyncDisposable {
29
30
  * @param fnOrDisposable
30
31
  * @param priority when it will be disposed in relation to other tasks (lower gets disposed first). When other tasks have the same priority, they will be disposed in parallel
31
32
  */
32
- add(fnOrDisposable: TaskFunction | Disposable | AsyncDisposable, priority?: number): void;
33
+ add(fnOrDisposable: AsyncDisposeHandler, priority?: number): void;
33
34
  dispose(): Promise<void>;
34
35
  [disposeAsync](): Promise<void>;
35
36
  }
package/error/index.d.ts CHANGED
@@ -11,5 +11,6 @@ export * from './multi.error.js';
11
11
  export * from './not-found.error.js';
12
12
  export * from './not-implemented.error.js';
13
13
  export * from './not-supported.error.js';
14
+ export * from './timeout.error.js';
14
15
  export * from './unauthorized.error.js';
15
16
  export * from './unsupported-media-type.error.js';
package/error/index.js CHANGED
@@ -28,5 +28,6 @@ __reExport(error_exports, require("./multi.error.js"), module.exports);
28
28
  __reExport(error_exports, require("./not-found.error.js"), module.exports);
29
29
  __reExport(error_exports, require("./not-implemented.error.js"), module.exports);
30
30
  __reExport(error_exports, require("./not-supported.error.js"), module.exports);
31
+ __reExport(error_exports, require("./timeout.error.js"), module.exports);
31
32
  __reExport(error_exports, require("./unauthorized.error.js"), module.exports);
32
33
  __reExport(error_exports, require("./unsupported-media-type.error.js"), module.exports);
@@ -0,0 +1,5 @@
1
+ import { CustomError } from './custom.error.js';
2
+ export declare class TimeoutError extends CustomError {
3
+ static readonly errorName = "TimeoutError";
4
+ constructor(message?: string);
5
+ }
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var timeout_error_exports = {};
20
+ __export(timeout_error_exports, {
21
+ TimeoutError: () => TimeoutError
22
+ });
23
+ module.exports = __toCommonJS(timeout_error_exports);
24
+ var import_custom_error = require("./custom.error.js");
25
+ class TimeoutError extends import_custom_error.CustomError {
26
+ static errorName = "TimeoutError";
27
+ constructor(message = "Operation timed out.") {
28
+ super({ message });
29
+ }
30
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var import_node_fs = require("node:fs");
3
+ var import_application = require("../../application/index.js");
4
+ var import_browser_service = require("../../browser/browser.service.js");
5
+ var import_container = require("../../container/container.js");
6
+ var import_timing = require("../../utils/timing.js");
7
+ async function main() {
8
+ const browserService = await import_container.container.resolveAsync(import_browser_service.BrowserService);
9
+ const browser = await browserService.newBrowser({ headless: false });
10
+ const page = await browser.newPage();
11
+ await page.navigate("https://google.com");
12
+ await page.click("//div[text() = 'Alle ablehnen']");
13
+ await (0, import_timing.timeout)(1e3);
14
+ const pdf = await page.renderPdf();
15
+ (0, import_node_fs.writeFileSync)("/tmp/pdf.pdf", pdf);
16
+ await page.navigate("file:///tmp/pdf.pdf");
17
+ await browser.waitForClose();
18
+ }
19
+ import_application.Application.run(main);
@@ -1,4 +1,6 @@
1
1
  "use strict";
2
+ var import_node_path = require("node:path");
3
+ var import_node_url = require("node:url");
2
4
  var import_container = require("../../container/index.js");
3
5
  var import_nodemailer_mail_client = require("../../mail/clients/nodemailer.mail-client.js");
4
6
  var import_mail = require("../../mail/index.js");
@@ -8,8 +10,14 @@ var import_handlebars_template_renderer = require("../../templates/renderers/han
8
10
  var import_mjml_template_renderer = require("../../templates/renderers/mjml.template-renderer.js");
9
11
  var import_file_template_resolver = require("../../templates/resolvers/file.template-resolver.js");
10
12
  var import_config_parser = require("../../utils/config-parser.js");
11
- var import_node_path = require("node:path");
12
13
  var import_core = require("../../core.js");
14
+ const import_meta = {};
15
+ let dirname;
16
+ try {
17
+ dirname = (0, import_node_url.fileURLToPath)(new URL(".", import_meta.url));
18
+ } catch {
19
+ dirname = __dirname;
20
+ }
13
21
  (0, import_core.configureTstdl)();
14
22
  (0, import_mail.configureMail)({
15
23
  clientConfig: {
@@ -26,8 +34,8 @@ var import_core = require("../../core.js");
26
34
  templateProvider: import_file_template_provider.FileTemplateProvider,
27
35
  templateRenderers: [import_mjml_template_renderer.MjmlTemplateRenderer, import_handlebars_template_renderer.HandlebarsTemplateRenderer]
28
36
  });
29
- (0, import_file_template_provider.configureFileTemplateProvider)({ basePath: (0, import_node_path.resolve)(__dirname, "templates") });
30
- (0, import_file_template_resolver.configureFileTemplateResolver)({ basePath: (0, import_node_path.resolve)(__dirname.replace("/dist", "/source"), "templates") });
37
+ (0, import_file_template_provider.configureFileTemplateProvider)({ basePath: (0, import_node_path.resolve)(dirname, "templates") });
38
+ (0, import_file_template_resolver.configureFileTemplateResolver)({ basePath: (0, import_node_path.resolve)(dirname.replace("/dist", "/source"), "templates") });
31
39
  async function test() {
32
40
  const service = await import_container.container.resolveAsync(import_mail.MailService);
33
41
  const result = await service.sendTemplate("hello-name", { from: (0, import_config_parser.string)("FROM", (0, import_config_parser.string)("USER", "user@example.com")), to: (0, import_config_parser.string)("TO", "user@example.com") }, { name: "Max Mustermann" });