@tstdl/base 0.83.28 → 0.84.1
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/application/application.d.ts +1 -1
- package/application/application.js +3 -3
- package/browser/browser-context-controller.d.ts +32 -0
- package/browser/browser-context-controller.js +88 -0
- package/browser/browser-controller.d.ts +30 -11
- package/browser/browser-controller.js +40 -30
- package/browser/browser.service.d.ts +9 -7
- package/browser/browser.service.js +31 -34
- package/browser/index.d.ts +1 -1
- package/browser/index.js +1 -1
- package/browser/page-controller.d.ts +33 -35
- package/browser/page-controller.js +58 -81
- package/browser/pdf-options.d.ts +5 -1
- package/browser/pdf-options.js +9 -5
- package/browser/utils.d.ts +6 -0
- package/browser/utils.js +60 -0
- package/data-structures/cache.d.ts +11 -0
- package/data-structures/cache.js +69 -0
- package/data-structures/index.d.ts +1 -0
- package/data-structures/index.js +1 -0
- package/disposable/async-disposer.d.ts +2 -1
- package/error/index.d.ts +1 -0
- package/error/index.js +1 -0
- package/error/timeout.error.d.ts +5 -0
- package/{browser/types.js → error/timeout.error.js} +16 -2
- package/examples/browser/basic.js +2 -2
- package/examples/pdf/basic.js +10 -6
- package/http/client/adapters/undici-http-client.adapter.js +1 -1
- package/http/client/http-client-request.js +1 -1
- package/http/server/node/node-http-server.js +1 -1
- package/lock/web/web-lock.js +2 -2
- package/package.json +8 -6
- package/pdf/pdf.service.d.ts +15 -21
- package/pdf/pdf.service.js +23 -62
- package/pool/pool.d.ts +1 -0
- package/pool/pool.js +3 -0
- package/queue/mongo/queue.js +2 -2
- package/types.d.ts +2 -2
- package/utils/cancellation-token.d.ts +11 -16
- package/utils/cancellation-token.js +10 -39
- package/utils/timing.d.ts +7 -1
- package/utils/timing.js +23 -3
- package/browser/types.d.ts +0 -3
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,143 +15,123 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
var page_controller_exports = {};
|
|
30
20
|
__export(page_controller_exports, {
|
|
31
21
|
PageController: () => PageController
|
|
32
22
|
});
|
|
33
23
|
module.exports = __toCommonJS(page_controller_exports);
|
|
34
|
-
var import_node_stream = require("node:stream");
|
|
35
|
-
var puppeteer = __toESM(require("puppeteer"), 1);
|
|
36
24
|
var import_disposable = require("../disposable/disposable.js");
|
|
37
25
|
var import_readable_stream_from_promise = require("../utils/stream/readable-stream-from-promise.js");
|
|
38
26
|
var import_timing = require("../utils/timing.js");
|
|
39
27
|
var import_type_guards = require("../utils/type-guards.js");
|
|
28
|
+
var import_units = require("../utils/units.js");
|
|
40
29
|
class PageController {
|
|
30
|
+
ownedContext;
|
|
41
31
|
/** @deprecated should be avoided */
|
|
42
32
|
page;
|
|
43
33
|
options;
|
|
44
|
-
constructor(
|
|
45
|
-
this.page =
|
|
34
|
+
constructor(page, options = {}) {
|
|
35
|
+
this.page = page;
|
|
46
36
|
this.options = options;
|
|
47
37
|
}
|
|
48
38
|
async [import_disposable.disposeAsync]() {
|
|
49
|
-
|
|
39
|
+
await this.close();
|
|
50
40
|
}
|
|
51
41
|
async close() {
|
|
52
|
-
|
|
42
|
+
if ((0, import_type_guards.isDefined)(this.ownedContext)) {
|
|
43
|
+
await this.ownedContext.close();
|
|
44
|
+
} else {
|
|
45
|
+
await this.page.close();
|
|
46
|
+
}
|
|
53
47
|
}
|
|
54
48
|
async setContent(html, options) {
|
|
55
|
-
await this.page.setContent(html, options);
|
|
49
|
+
await this.page.setContent(html, { timeout: options?.timeout, waitUntil: options?.waitUntil });
|
|
56
50
|
}
|
|
57
51
|
async setExtraHttpHeaders(headers) {
|
|
58
52
|
await this.page.setExtraHTTPHeaders(headers);
|
|
59
53
|
}
|
|
60
|
-
async authenticate(username, password) {
|
|
61
|
-
await this.page.authenticate({ username, password });
|
|
62
|
-
}
|
|
63
54
|
async navigate(url, options) {
|
|
64
|
-
await this.page.goto(url, options);
|
|
55
|
+
await this.page.goto(url, { timeout: options?.timeout, waitUntil: options?.waitUntil });
|
|
65
56
|
}
|
|
66
57
|
async waitForClose() {
|
|
67
|
-
return new Promise((resolve) =>
|
|
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
68
|
}
|
|
69
|
-
async
|
|
70
|
-
await this.page.
|
|
69
|
+
async waitForNetworkIdle(options) {
|
|
70
|
+
await this.page.waitForLoadState("networkidle", { timeout: options?.timeout });
|
|
71
71
|
}
|
|
72
72
|
async waitForUrl(urlOrPredicate, options) {
|
|
73
|
-
|
|
74
|
-
await this.page.waitForFrame(async (frame) => {
|
|
75
|
-
if (frame != pageFrame) {
|
|
76
|
-
return false;
|
|
77
|
-
}
|
|
78
|
-
if ((0, import_type_guards.isString)(urlOrPredicate)) {
|
|
79
|
-
return frame.url().includes(urlOrPredicate);
|
|
80
|
-
}
|
|
81
|
-
return urlOrPredicate(frame.url());
|
|
82
|
-
}, { timeout: options?.timeout });
|
|
73
|
+
await this.page.waitForURL(urlOrPredicate, { timeout: options?.timeout });
|
|
83
74
|
}
|
|
84
75
|
async waitForFrame(selector, options) {
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
async waitForFrameByUrl(urlOrPredicate, options) {
|
|
89
|
-
const frame = await this.page.waitForFrame(urlOrPredicate, 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.");
|
|
90
79
|
return new PageController(frame.page());
|
|
91
80
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
if (children.length > 1) {
|
|
97
|
-
throw new Error("Multiple frames found. Only works with single frame.");
|
|
98
|
-
}
|
|
99
|
-
if (children.length == 0) {
|
|
100
|
-
break;
|
|
101
|
-
}
|
|
102
|
-
frame = children[0];
|
|
103
|
-
}
|
|
104
|
-
return new PageController(frame);
|
|
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 });
|
|
105
85
|
}
|
|
106
|
-
async type(
|
|
86
|
+
async type(selector, text, options) {
|
|
107
87
|
await this.prepareAction();
|
|
108
|
-
const
|
|
109
|
-
await
|
|
88
|
+
const locator = this.page.locator(selector);
|
|
89
|
+
await locator.focus({ timeout: options?.timeout });
|
|
110
90
|
if ((0, import_type_guards.isUndefined)(this.options.typeDelay)) {
|
|
111
|
-
await
|
|
91
|
+
await locator.type(text, { timeout: options?.timeout });
|
|
112
92
|
} else {
|
|
113
93
|
for (const char of text) {
|
|
114
|
-
await
|
|
115
|
-
await delay(this.options.typeDelay);
|
|
94
|
+
await locator.type(char, { timeout: options?.timeout });
|
|
95
|
+
await delay(options?.delay ?? this.options.typeDelay);
|
|
116
96
|
}
|
|
117
97
|
}
|
|
118
98
|
}
|
|
119
|
-
async
|
|
99
|
+
async selectOption(selector, value, options) {
|
|
120
100
|
await this.prepareAction();
|
|
121
|
-
const
|
|
122
|
-
await
|
|
101
|
+
const locator = this.page.locator(selector);
|
|
102
|
+
await locator.selectOption(value, { timeout: options?.timeout });
|
|
123
103
|
}
|
|
124
|
-
async click(
|
|
104
|
+
async click(selector, options) {
|
|
125
105
|
await this.prepareAction();
|
|
126
|
-
const
|
|
127
|
-
await
|
|
106
|
+
const locator = this.page.locator(selector);
|
|
107
|
+
await locator.click({ delay: 50, timeout: options?.timeout });
|
|
128
108
|
}
|
|
129
|
-
async getValue(
|
|
130
|
-
const
|
|
131
|
-
return
|
|
109
|
+
async getValue(selector, options) {
|
|
110
|
+
const locator = this.page.locator(selector);
|
|
111
|
+
return locator.inputValue({ timeout: options?.timeout });
|
|
132
112
|
}
|
|
133
113
|
async waitForElement(selector, options) {
|
|
134
|
-
|
|
114
|
+
const locator = this.page.locator(selector);
|
|
115
|
+
return locator.waitFor({ timeout: options?.timeout });
|
|
135
116
|
}
|
|
136
117
|
async renderPdf(options = {}) {
|
|
137
118
|
const createPdfOptions = convertPdfOptions(options);
|
|
138
|
-
return this.page.pdf(createPdfOptions);
|
|
119
|
+
return (0, import_timing.withTimeout)(options.timeout ?? 30 * import_units.millisecondsPerSecond, this.page.pdf(createPdfOptions), { errorMessage: "Rendering pdf timed out." });
|
|
139
120
|
}
|
|
140
121
|
renderPdfStream(options = {}) {
|
|
141
122
|
return (0, import_readable_stream_from_promise.readableStreamFromPromise)(async () => {
|
|
142
|
-
const
|
|
143
|
-
|
|
144
|
-
|
|
123
|
+
const buffer = await this.renderPdf(options);
|
|
124
|
+
return new ReadableStream({
|
|
125
|
+
pull(controller) {
|
|
126
|
+
controller.enqueue(buffer);
|
|
127
|
+
controller.close();
|
|
128
|
+
}
|
|
129
|
+
});
|
|
145
130
|
});
|
|
146
131
|
}
|
|
147
|
-
async waitForElementHandle(selector, { timeout: waitTimeout = 5e3, xpath = false } = {}) {
|
|
148
|
-
const handle = xpath ? await this.page.waitForXPath(selector, { timeout: waitTimeout }) : await this.page.waitForSelector(selector, { timeout: waitTimeout });
|
|
149
|
-
if ((0, import_type_guards.isNull)(handle)) {
|
|
150
|
-
throw new Error("Element not found");
|
|
151
|
-
}
|
|
152
|
-
return handle;
|
|
153
|
-
}
|
|
154
132
|
async prepareAction() {
|
|
155
133
|
await delay(this.options.actionDelay);
|
|
156
|
-
await this.
|
|
134
|
+
await this.waitForNetworkIdle();
|
|
157
135
|
}
|
|
158
136
|
}
|
|
159
137
|
async function delay(milliseconds) {
|
|
@@ -179,7 +157,6 @@ function convertPdfOptions(options) {
|
|
|
179
157
|
landscape: options.landscape,
|
|
180
158
|
width: options.width,
|
|
181
159
|
height: options.height,
|
|
182
|
-
omitBackground: options.omitDefaultBackground,
|
|
183
160
|
printBackground: options.renderBackground,
|
|
184
161
|
margin,
|
|
185
162
|
displayHeaderFooter: options.displayHeaderFooter ?? ((0, import_type_guards.isDefined)(options.headerTemplate) || (0, import_type_guards.isDefined)(options.footerTemplate)),
|
package/browser/pdf-options.d.ts
CHANGED
|
@@ -18,7 +18,6 @@ export declare class PdfMarginObject {
|
|
|
18
18
|
left?: number | string;
|
|
19
19
|
}
|
|
20
20
|
export declare class PdfRenderOptions {
|
|
21
|
-
omitDefaultBackground?: boolean;
|
|
22
21
|
renderBackground?: boolean;
|
|
23
22
|
landscape?: boolean;
|
|
24
23
|
format?: PdfFormat;
|
|
@@ -29,4 +28,9 @@ export declare class PdfRenderOptions {
|
|
|
29
28
|
displayHeaderFooter?: boolean;
|
|
30
29
|
headerTemplate?: string;
|
|
31
30
|
footerTemplate?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Timeout for closing render context in case something went wrong.
|
|
33
|
+
* @default 60000 (1 minute)
|
|
34
|
+
*/
|
|
35
|
+
timeout?: number;
|
|
32
36
|
}
|
package/browser/pdf-options.js
CHANGED
|
@@ -76,7 +76,6 @@ __decorate([
|
|
|
76
76
|
__metadata("design:type", Object)
|
|
77
77
|
], PdfMarginObject.prototype, "left", void 0);
|
|
78
78
|
class PdfRenderOptions {
|
|
79
|
-
omitDefaultBackground;
|
|
80
79
|
renderBackground;
|
|
81
80
|
landscape;
|
|
82
81
|
format;
|
|
@@ -87,11 +86,12 @@ class PdfRenderOptions {
|
|
|
87
86
|
displayHeaderFooter;
|
|
88
87
|
headerTemplate;
|
|
89
88
|
footerTemplate;
|
|
89
|
+
/**
|
|
90
|
+
* Timeout for closing render context in case something went wrong.
|
|
91
|
+
* @default 60000 (1 minute)
|
|
92
|
+
*/
|
|
93
|
+
timeout;
|
|
90
94
|
}
|
|
91
|
-
__decorate([
|
|
92
|
-
(0, import_optional.Optional)(),
|
|
93
|
-
__metadata("design:type", Boolean)
|
|
94
|
-
], PdfRenderOptions.prototype, "omitDefaultBackground", void 0);
|
|
95
95
|
__decorate([
|
|
96
96
|
(0, import_optional.Optional)(),
|
|
97
97
|
__metadata("design:type", Boolean)
|
|
@@ -132,3 +132,7 @@ __decorate([
|
|
|
132
132
|
(0, import_optional.Optional)(),
|
|
133
133
|
__metadata("design:type", String)
|
|
134
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;
|
package/browser/utils.js
ADDED
|
@@ -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
|
+
}
|
|
@@ -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
|
+
}
|
package/data-structures/index.js
CHANGED
|
@@ -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:
|
|
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);
|
|
@@ -3,6 +3,10 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
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
|
+
};
|
|
6
10
|
var __copyProps = (to, from, except, desc) => {
|
|
7
11
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
12
|
for (let key of __getOwnPropNames(from))
|
|
@@ -12,5 +16,15 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
12
16
|
return to;
|
|
13
17
|
};
|
|
14
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
-
var
|
|
16
|
-
|
|
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
|
+
}
|
|
@@ -6,10 +6,10 @@ var import_container = require("../../container/container.js");
|
|
|
6
6
|
var import_timing = require("../../utils/timing.js");
|
|
7
7
|
async function main() {
|
|
8
8
|
const browserService = await import_container.container.resolveAsync(import_browser_service.BrowserService);
|
|
9
|
-
const browser = await browserService.newBrowser();
|
|
9
|
+
const browser = await browserService.newBrowser({ headless: false });
|
|
10
10
|
const page = await browser.newPage();
|
|
11
11
|
await page.navigate("https://google.com");
|
|
12
|
-
await page.click("//div[text() = 'Alle ablehnen']"
|
|
12
|
+
await page.click("//div[text() = 'Alle ablehnen']");
|
|
13
13
|
await (0, import_timing.timeout)(1e3);
|
|
14
14
|
const pdf = await page.renderPdf();
|
|
15
15
|
(0, import_node_fs.writeFileSync)("/tmp/pdf.pdf", pdf);
|
package/examples/pdf/basic.js
CHANGED
|
@@ -30,18 +30,22 @@ try {
|
|
|
30
30
|
async function main() {
|
|
31
31
|
const browserService = await import_container.container.resolveAsync(import_browser_service.BrowserService);
|
|
32
32
|
const pdfService = await import_container.container.resolveAsync(import_pdf_service.PdfService);
|
|
33
|
-
const result1 = await
|
|
34
|
-
|
|
33
|
+
const [result1, result2] = await Promise.all([
|
|
34
|
+
pdfService.renderTemplate("hello-name", { name: "Max Mustermann" }),
|
|
35
|
+
pdfService.renderUrl("https://google.de")
|
|
36
|
+
]);
|
|
35
37
|
console.log(`Resulting PDFs have ${result1.length} and ${result2.length} bytes.`);
|
|
36
38
|
(0, import_node_fs.writeFileSync)("/tmp/template.pdf", result1);
|
|
37
39
|
(0, import_node_fs.writeFileSync)("/tmp/page.pdf", result2);
|
|
38
|
-
const browser = await browserService.newBrowser();
|
|
39
|
-
const
|
|
40
|
-
const
|
|
40
|
+
const browser = await browserService.newBrowser({ headless: false });
|
|
41
|
+
const context = await browser.newContext();
|
|
42
|
+
const page1 = await context.newPage();
|
|
43
|
+
const page2 = await context.newPage();
|
|
41
44
|
await Promise.all([
|
|
42
45
|
page1.navigate("file:///tmp/template.pdf"),
|
|
43
46
|
page2.navigate("file:///tmp/page.pdf")
|
|
44
47
|
]);
|
|
45
|
-
await
|
|
48
|
+
await page1.waitForClose();
|
|
49
|
+
await page2.waitForClose();
|
|
46
50
|
}
|
|
47
51
|
import_application.Application.run(main);
|
|
@@ -82,7 +82,7 @@ let UndiciHttpClientAdapter = class UndiciHttpClientAdapter2 extends import_http
|
|
|
82
82
|
try {
|
|
83
83
|
const response = await (0, import_undici.request)(httpClientRequest.url, {
|
|
84
84
|
method: httpClientRequest.method,
|
|
85
|
-
signal: httpClientRequest.abortToken.asAbortSignal,
|
|
85
|
+
signal: httpClientRequest.abortToken.asAbortSignal(),
|
|
86
86
|
headers: httpClientRequest.headers.asNormalizedObject(),
|
|
87
87
|
body,
|
|
88
88
|
headersTimeout: httpClientRequest.timeout,
|
|
@@ -97,7 +97,7 @@ class HttpClientRequest {
|
|
|
97
97
|
* can be used to cancel the request. Throws HttpError
|
|
98
98
|
*/
|
|
99
99
|
get abortToken() {
|
|
100
|
-
return this._abortToken.asReadonly;
|
|
100
|
+
return this._abortToken.asReadonly();
|
|
101
101
|
}
|
|
102
102
|
constructor(urlOrObject, method, options = {}) {
|
|
103
103
|
if ((0, import_type_guards.isString)(urlOrObject)) {
|
|
@@ -133,7 +133,7 @@ let NodeHttpServer = class NodeHttpServer2 extends import_http_server.HttpServer
|
|
|
133
133
|
}
|
|
134
134
|
if (connections > 0) {
|
|
135
135
|
this.logger.info(`Waiting for ${connections} connections to end`);
|
|
136
|
-
await (0, import_timing.cancelableTimeout)(250, import_cancellation_token.CancellationToken.
|
|
136
|
+
await (0, import_timing.cancelableTimeout)(250, import_cancellation_token.CancellationToken.from(close$));
|
|
137
137
|
}
|
|
138
138
|
}
|
|
139
139
|
this.untrackConnectedSockets?.();
|
package/lock/web/web-lock.js
CHANGED
|
@@ -55,9 +55,9 @@ let WebLock = class WebLock2 extends import_lock.Lock {
|
|
|
55
55
|
releasePromise.resolve();
|
|
56
56
|
}
|
|
57
57
|
};
|
|
58
|
-
const timeoutToken = (0, import_type_guards.isDefined)(timeout) && timeout > 0 ? import_cancellation_token.CancellationToken.
|
|
58
|
+
const timeoutToken = (0, import_type_guards.isDefined)(timeout) && timeout > 0 ? import_cancellation_token.CancellationToken.from((0, import_rxjs.timer)(timeout).pipe((0, import_rxjs.map)(() => true))) : void 0;
|
|
59
59
|
void navigator.locks.request(this.resource, {
|
|
60
|
-
signal: (0, import_type_guards.isDefined)(timeoutToken) ? timeoutToken.asAbortSignal : void 0,
|
|
60
|
+
signal: (0, import_type_guards.isDefined)(timeoutToken) ? timeoutToken.asAbortSignal() : void 0,
|
|
61
61
|
ifAvailable: (0, import_type_guards.isDefined)(timeout) && timeout <= 0
|
|
62
62
|
}, async (lock) => {
|
|
63
63
|
if ((0, import_type_guards.isNull)(lock)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tstdl/base",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.84.1",
|
|
4
4
|
"author": "Patrick Hein",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -8,14 +8,16 @@
|
|
|
8
8
|
"type": "commonjs",
|
|
9
9
|
"scripts": {
|
|
10
10
|
"build": "tsc && tsc-alias",
|
|
11
|
-
"build:watch": "
|
|
11
|
+
"build:watch": "concurrently --raw --kill-others npm:tsc:watch npm:tsc-alias:watch",
|
|
12
12
|
"build:production": "rm -rf dist && npm run build && npm run build:production:cjs && npm run build:production:copy-files",
|
|
13
13
|
"build:production:cjs": "esbuild `find dist \\( -name '*.js' -o -name '*.jsx' \\)` --outdir=dist --allow-overwrite --format=cjs",
|
|
14
14
|
"build:production:copy-files": "cp package.json .eslintrc.json tsconfig.server.json dist/ && cp tsconfig.base.json dist/tsconfig.json && sed -i 's/\"type\": \"module\",/\"type\": \"commonjs\",/g' dist/package.json",
|
|
15
15
|
"build:docs": "typedoc",
|
|
16
16
|
"build:docs-watch": "typedoc --watch",
|
|
17
17
|
"lint": "eslint -c .eslintrc.json --ext .ts .",
|
|
18
|
-
"pub": "npm run build:production && rm -vf dist/test* && npm publish dist/"
|
|
18
|
+
"pub": "npm run build:production && rm -vf dist/test* && npm publish dist/",
|
|
19
|
+
"tsc:watch": "tsc --watch",
|
|
20
|
+
"tsc-alias:watch": "tsc-alias --watch"
|
|
19
21
|
},
|
|
20
22
|
"dependencies": {
|
|
21
23
|
"luxon": "^3.3",
|
|
@@ -45,7 +47,7 @@
|
|
|
45
47
|
"peerDependencies": {
|
|
46
48
|
"@elastic/elasticsearch": "^8.7",
|
|
47
49
|
"@koa/router": "^12.0",
|
|
48
|
-
"@tstdl/angular": "^0.
|
|
50
|
+
"@tstdl/angular": "^0.84",
|
|
49
51
|
"@zxcvbn-ts/core": "^2.2",
|
|
50
52
|
"@zxcvbn-ts/language-common": "^2.0",
|
|
51
53
|
"@zxcvbn-ts/language-de": "^2.1",
|
|
@@ -54,13 +56,13 @@
|
|
|
54
56
|
"handlebars": "^4.7",
|
|
55
57
|
"knex": "^2.4",
|
|
56
58
|
"koa": "^2.14",
|
|
57
|
-
"minio": "^7.
|
|
59
|
+
"minio": "^7.1",
|
|
58
60
|
"mjml": "^4.14",
|
|
59
61
|
"mongodb": "^5.3",
|
|
60
62
|
"nodemailer": "^6.9",
|
|
63
|
+
"playwright": "^1.33",
|
|
61
64
|
"preact": "^10.13",
|
|
62
65
|
"preact-render-to-string": "^6.0",
|
|
63
|
-
"puppeteer": "^19.11",
|
|
64
66
|
"undici": "^5.22",
|
|
65
67
|
"urlpattern-polyfill": "^8.0"
|
|
66
68
|
},
|