@tstdl/base 0.84.2 → 0.84.4

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/.eslintrc.json CHANGED
@@ -24,10 +24,6 @@
24
24
  },
25
25
  "plugins": ["@typescript-eslint"],
26
26
  "rules": {
27
- /** angular */
28
- "@angular-eslint/template/eqeqeq": "off",
29
- "@angular-eslint/no-host-metadata-property": ["error", { "allowStatic": true }],
30
-
31
27
  /** typescript */
32
28
  "@typescript-eslint/brace-style": ["error", "stroustrup", { "allowSingleLine": true }],
33
29
  "@typescript-eslint/consistent-type-definitions": "off",
@@ -0,0 +1,26 @@
1
+ import type { ElementHandle, Frame, Page } from 'playwright';
2
+ import type { Delay } from './element-controller.js';
3
+ import type { FrameController, FrameControllerOptions } from './frame-controller.js';
4
+ import { LocatorController } from './locator-controller.js';
5
+ import type { PageControllerOptions } from './page-controller.js';
6
+ export type DocumentControllerOptions = {
7
+ defaultActionDelay?: Delay;
8
+ defaultTypeDelay?: Delay;
9
+ };
10
+ export type DocumentControllerForwardOptions = {
11
+ pageControllerOptions: PageControllerOptions;
12
+ frameControllerOptions: FrameControllerOptions;
13
+ };
14
+ export declare class DocumentController extends LocatorController {
15
+ protected readonly forwardOptions: DocumentControllerForwardOptions;
16
+ /** @deprecated should be avoided */
17
+ readonly document: Page | Frame;
18
+ constructor(document: Page | Frame, options: DocumentControllerOptions, forwardOptions: DocumentControllerForwardOptions);
19
+ setContent(...args: Parameters<Page['setContent']>): Promise<void>;
20
+ navigate(...args: Parameters<Page['goto']>): Promise<void>;
21
+ waitForLoadState(...args: Parameters<Page['waitForLoadState']>): Promise<void>;
22
+ waitForUrl(...args: Parameters<Page['waitForURL']>): Promise<void>;
23
+ waitForElement(selector: string, options?: Parameters<Page['waitForSelector']>[1]): Promise<ElementHandle>;
24
+ getInFrame(frameSelector: string): LocatorController;
25
+ waitForFrame(selector: string, options?: Parameters<Page['waitForSelector']>[1]): Promise<FrameController>;
26
+ }
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
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
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var document_controller_exports = {};
30
+ __export(document_controller_exports, {
31
+ DocumentController: () => DocumentController
32
+ });
33
+ module.exports = __toCommonJS(document_controller_exports);
34
+ var import_type_guards = require("../utils/type-guards.js");
35
+ var import_locator_controller = require("./locator-controller.js");
36
+ class DocumentController extends import_locator_controller.LocatorController {
37
+ forwardOptions;
38
+ /** @deprecated should be avoided */
39
+ document;
40
+ constructor(document, options, forwardOptions) {
41
+ super(document, { actionDelay: options.defaultActionDelay, typeDelay: options.defaultTypeDelay });
42
+ this.document = document;
43
+ this.forwardOptions = forwardOptions;
44
+ }
45
+ async setContent(...args) {
46
+ await this.document.setContent(...args);
47
+ }
48
+ async navigate(...args) {
49
+ await this.document.goto(...args);
50
+ }
51
+ async waitForLoadState(...args) {
52
+ await this.document.waitForLoadState(...args);
53
+ }
54
+ async waitForUrl(...args) {
55
+ await this.document.waitForURL(...args);
56
+ }
57
+ async waitForElement(selector, options) {
58
+ const element = await this.document.waitForSelector(selector, options);
59
+ if ((0, import_type_guards.isNull)(element)) {
60
+ throw new Error("Element not found.");
61
+ }
62
+ return element;
63
+ }
64
+ getInFrame(frameSelector) {
65
+ const locator = this.document.frameLocator(frameSelector);
66
+ return new import_locator_controller.LocatorController(locator, this.elementControllerOptions);
67
+ }
68
+ async waitForFrame(selector, options) {
69
+ const element = await this.waitForElement(selector, options);
70
+ const frame = await element.contentFrame();
71
+ if ((0, import_type_guards.isNull)(frame)) {
72
+ throw new Error("Element is not a frame.");
73
+ }
74
+ return newFrameController(frame, this.forwardOptions.frameControllerOptions, { pageControllerOptions: this.forwardOptions.pageControllerOptions });
75
+ }
76
+ }
77
+ let frameControllerConstructor;
78
+ async function newFrameController(...args) {
79
+ if ((0, import_type_guards.isUndefined)(frameControllerConstructor)) {
80
+ frameControllerConstructor = importFrameController();
81
+ void frameControllerConstructor.then((constructor) => frameControllerConstructor = constructor);
82
+ }
83
+ return new (await frameControllerConstructor)(...args);
84
+ }
85
+ async function importFrameController() {
86
+ const module2 = await import("./frame-controller.js");
87
+ return module2.FrameController;
88
+ }
@@ -1,7 +1,6 @@
1
+ import type { ElementHandle, Locator } from 'playwright';
1
2
  import type { Merge, NonUndefinable, TypedOmit } from '../types.js';
2
3
  import type { ValueOrProvider } from '../utils/value-or-provider.js';
3
- import type { ElementHandle, Locator } from 'playwright';
4
- import { PageController } from './page-controller.js';
5
4
  export type Delay = ValueOrProvider<number>;
6
5
  export type ActionDelayOptions = {
7
6
  actionDelay?: Delay;
@@ -19,19 +18,14 @@ export type ElementControllerOptions = {
19
18
  type LocatorOptions<K extends keyof Locator, I extends keyof Parameters<Locator[K]>> = NonUndefinable<Parameters<Locator[K]>[I]>;
20
19
  export declare class ElementController {
21
20
  readonly locatorOrHandle: Locator | ElementHandle;
22
- readonly pageController: PageController;
23
21
  readonly options: ElementControllerOptions;
24
- constructor(locatorOrHandle: Locator | ElementHandle, pageController: PageController, options?: ElementControllerOptions);
22
+ constructor(locatorOrHandle: Locator | ElementHandle, options?: ElementControllerOptions);
25
23
  waitFor(options?: Parameters<Locator['waitFor']>[0]): Promise<void>;
26
24
  fill(text: string, options?: Merge<LocatorOptions<'fill', 1>, ActionDelayOptions>): Promise<void>;
27
25
  type(text: string, options?: Merge<TypedOmit<LocatorOptions<'type', 1>, 'delay'>, ActionDelayOptions & TypeDelayOptions>): Promise<void>;
28
26
  selectOption(value: string | string[], options?: Merge<LocatorOptions<'selectOption', 1>, ActionDelayOptions>): Promise<void>;
29
27
  click(options?: Merge<TypedOmit<LocatorOptions<'click', 0>, 'delay'>, ActionDelayOptions & ClickDelayOptions>): Promise<void>;
30
28
  getValue(options?: LocatorOptions<'inputValue', 0>): Promise<string>;
31
- /**
32
- * Get PageController for element. Element must be a frame.
33
- */
34
- getPage(options?: LocatorOptions<'elementHandle', 0>): Promise<PageController>;
35
29
  private prepareAction;
36
30
  }
37
31
  export {};
@@ -24,15 +24,11 @@ module.exports = __toCommonJS(element_controller_exports);
24
24
  var import_timing = require("../utils/timing.js");
25
25
  var import_type_guards = require("../utils/type-guards.js");
26
26
  var import_value_or_provider = require("../utils/value-or-provider.js");
27
- var import_page_controller = require("./page-controller.js");
28
- var import_utils = require("./utils.js");
29
27
  class ElementController {
30
28
  locatorOrHandle;
31
- pageController;
32
29
  options;
33
- constructor(locatorOrHandle, pageController, options = {}) {
30
+ constructor(locatorOrHandle, options = {}) {
34
31
  this.locatorOrHandle = locatorOrHandle;
35
- this.pageController = pageController;
36
32
  this.options = options;
37
33
  }
38
34
  async waitFor(options) {
@@ -67,18 +63,6 @@ class ElementController {
67
63
  async getValue(options) {
68
64
  return this.locatorOrHandle.inputValue(options);
69
65
  }
70
- /**
71
- * Get PageController for element. Element must be a frame.
72
- */
73
- async getPage(options) {
74
- const handle = (0, import_utils.isLocator)(this.locatorOrHandle) ? await this.locatorOrHandle.elementHandle(options) : this.locatorOrHandle;
75
- if ((0, import_type_guards.isNull)(handle)) {
76
- throw new Error("Could not get element handle.");
77
- }
78
- const frame = await this.locatorOrHandle.contentFrame();
79
- (0, import_type_guards.assertNotNull)(frame, "Could not get content frame for element handle.");
80
- return new import_page_controller.PageController(frame.page(), this.pageController.options);
81
- }
82
66
  async prepareAction(options) {
83
67
  await delay(options?.actionDelay ?? this.options.actionDelay);
84
68
  }
@@ -0,0 +1,23 @@
1
+ import type { Frame, Page } from 'playwright';
2
+ import type { DocumentControllerOptions } from './document-controller.js';
3
+ import { DocumentController } from './document-controller.js';
4
+ import type { PageControllerOptions } from './page-controller.js';
5
+ import { PageController } from './page-controller.js';
6
+ export type FrameControllerOptions = DocumentControllerOptions;
7
+ export type FrameControllerForwardOptions = {
8
+ pageControllerOptions: PageControllerOptions;
9
+ };
10
+ export declare class FrameController extends DocumentController {
11
+ private readonly frameControllerForwardOptions;
12
+ /** @deprecated should be avoided */
13
+ readonly frame: Frame;
14
+ readonly options: FrameControllerOptions;
15
+ constructor(frame: Frame, options: FrameControllerOptions, forwardOptions: FrameControllerForwardOptions);
16
+ /** Get the page containing this frame */
17
+ getPage(): PageController;
18
+ /**
19
+ * @param frameSelector frame name, url or url predicate
20
+ * @returns
21
+ */
22
+ getFrame(frameSelector: Parameters<Page['frame']>[0]): FrameController;
23
+ }
@@ -0,0 +1,52 @@
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 frame_controller_exports = {};
20
+ __export(frame_controller_exports, {
21
+ FrameController: () => FrameController
22
+ });
23
+ module.exports = __toCommonJS(frame_controller_exports);
24
+ var import_type_guards = require("../utils/type-guards.js");
25
+ var import_document_controller = require("./document-controller.js");
26
+ var import_page_controller = require("./page-controller.js");
27
+ class FrameController extends import_document_controller.DocumentController {
28
+ frameControllerForwardOptions;
29
+ /** @deprecated should be avoided */
30
+ frame;
31
+ options;
32
+ constructor(frame, options, forwardOptions) {
33
+ super(frame, options, { frameControllerOptions: options, pageControllerOptions: forwardOptions.pageControllerOptions });
34
+ this.options = options;
35
+ this.frameControllerForwardOptions = forwardOptions;
36
+ }
37
+ /** Get the page containing this frame */
38
+ getPage() {
39
+ return new import_page_controller.PageController(this.frame.page(), this.frameControllerForwardOptions.pageControllerOptions);
40
+ }
41
+ /**
42
+ * @param frameSelector frame name, url or url predicate
43
+ * @returns
44
+ */
45
+ getFrame(frameSelector) {
46
+ const frame = this.frame.page().frame(frameSelector);
47
+ if ((0, import_type_guards.isNull)(frame)) {
48
+ throw new Error("Frame not found.");
49
+ }
50
+ return new FrameController(frame, this.options, this.frameControllerForwardOptions);
51
+ }
52
+ }
@@ -1,6 +1,9 @@
1
1
  export * from './browser-context-controller.js';
2
2
  export * from './browser-controller.js';
3
3
  export * from './browser.service.js';
4
+ export * from './document-controller.js';
4
5
  export * from './element-controller.js';
6
+ export * from './frame-controller.js';
7
+ export * from './locator-controller.js';
5
8
  export * from './page-controller.js';
6
9
  export * from './types.js';
package/browser/index.js CHANGED
@@ -18,6 +18,9 @@ module.exports = __toCommonJS(browser_exports);
18
18
  __reExport(browser_exports, require("./browser-context-controller.js"), module.exports);
19
19
  __reExport(browser_exports, require("./browser-controller.js"), module.exports);
20
20
  __reExport(browser_exports, require("./browser.service.js"), module.exports);
21
+ __reExport(browser_exports, require("./document-controller.js"), module.exports);
21
22
  __reExport(browser_exports, require("./element-controller.js"), module.exports);
23
+ __reExport(browser_exports, require("./frame-controller.js"), module.exports);
24
+ __reExport(browser_exports, require("./locator-controller.js"), module.exports);
22
25
  __reExport(browser_exports, require("./page-controller.js"), module.exports);
23
26
  __reExport(browser_exports, require("./types.js"), module.exports);
@@ -0,0 +1,16 @@
1
+ import type { Frame, FrameLocator, Locator, Page } from 'playwright';
2
+ import type { NonUndefinable, SimplifyObject } from '../types.js';
3
+ import type { ElementControllerOptions } from './element-controller.js';
4
+ import { ElementController } from './element-controller.js';
5
+ export declare class LocatorController {
6
+ protected readonly elementControllerOptions: ElementControllerOptions;
7
+ readonly locatable: Page | Frame | Locator | FrameLocator;
8
+ constructor(locatable: Page | Frame | Locator | FrameLocator, elementControllerOptions: ElementControllerOptions);
9
+ getBySelector(selector: string, options?: SimplifyObject<Pick<NonUndefinable<Parameters<Page['locator']>[1]>, 'hasText' | 'hasNotText'>>): ElementController;
10
+ getByRole(role: Parameters<Page['getByRole']>[0], options?: Parameters<Page['getByRole']>[1]): ElementController;
11
+ getByLabel(text: Parameters<Page['getByLabel']>[0], options?: Parameters<Page['getByLabel']>[1]): ElementController;
12
+ getByAltText(text: Parameters<Page['getByAltText']>[0], options?: Parameters<Page['getByAltText']>[1]): ElementController;
13
+ getByPlaceholder(text: Parameters<Page['getByPlaceholder']>[0], options?: Parameters<Page['getByPlaceholder']>[1]): ElementController;
14
+ getByText(text: Parameters<Page['getByText']>[0], options?: Parameters<Page['getByText']>[1]): ElementController;
15
+ getByTitle(text: Parameters<Page['getByTitle']>[0], options?: Parameters<Page['getByTitle']>[1]): ElementController;
16
+ }
@@ -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 locator_controller_exports = {};
20
+ __export(locator_controller_exports, {
21
+ LocatorController: () => LocatorController
22
+ });
23
+ module.exports = __toCommonJS(locator_controller_exports);
24
+ var import_element_controller = require("./element-controller.js");
25
+ class LocatorController {
26
+ elementControllerOptions;
27
+ locatable;
28
+ constructor(locatable, elementControllerOptions) {
29
+ this.locatable = locatable;
30
+ this.elementControllerOptions = elementControllerOptions;
31
+ }
32
+ getBySelector(selector, options) {
33
+ const locator = this.locatable.locator(selector, options);
34
+ return new import_element_controller.ElementController(locator, this.elementControllerOptions);
35
+ }
36
+ getByRole(role, options) {
37
+ const locator = this.locatable.getByRole(role, options);
38
+ return new import_element_controller.ElementController(locator, this.elementControllerOptions);
39
+ }
40
+ getByLabel(text, options) {
41
+ const locator = this.locatable.getByLabel(text, options);
42
+ return new import_element_controller.ElementController(locator, this.elementControllerOptions);
43
+ }
44
+ getByAltText(text, options) {
45
+ const locator = this.locatable.getByAltText(text, options);
46
+ return new import_element_controller.ElementController(locator, this.elementControllerOptions);
47
+ }
48
+ getByPlaceholder(text, options) {
49
+ const locator = this.locatable.getByPlaceholder(text, options);
50
+ return new import_element_controller.ElementController(locator, this.elementControllerOptions);
51
+ }
52
+ getByText(text, options) {
53
+ const locator = this.locatable.getByText(text, options);
54
+ return new import_element_controller.ElementController(locator, this.elementControllerOptions);
55
+ }
56
+ getByTitle(text, options) {
57
+ const locator = this.locatable.getByTitle(text, options);
58
+ return new import_element_controller.ElementController(locator, this.elementControllerOptions);
59
+ }
60
+ }
@@ -1,36 +1,29 @@
1
1
  import type { Page } from 'playwright';
2
2
  import type { AsyncDisposable } from '../disposable/disposable.js';
3
3
  import { disposeAsync } from '../disposable/disposable.js';
4
- import type { NonUndefinable, SimplifyObject } from '../types.js';
5
- import type { Delay } from './element-controller.js';
6
- import { ElementController } from './element-controller.js';
4
+ import type { DocumentControllerOptions } from './document-controller.js';
5
+ import { DocumentController } from './document-controller.js';
6
+ import type { FrameControllerOptions } from './frame-controller.js';
7
+ import { FrameController } from './frame-controller.js';
7
8
  import type { PdfRenderOptions } from './pdf-options.js';
8
9
  import type { Abortable } from './types.js';
9
- export type PageControllerOptions = {
10
- defaultActionDelay?: Delay;
11
- defaultTypeDelay?: Delay;
10
+ export type PageControllerOptions = DocumentControllerOptions & {
11
+ defaultFrameControllerOptions?: FrameControllerOptions;
12
12
  };
13
- export declare class PageController implements AsyncDisposable {
14
- private readonly elementControllerOptions;
13
+ export declare class PageController extends DocumentController implements AsyncDisposable {
15
14
  /** @deprecated should be avoided */
16
15
  readonly page: Page;
17
16
  readonly options: PageControllerOptions;
18
17
  constructor(page: Page, options?: PageControllerOptions);
19
18
  [disposeAsync](): Promise<void>;
20
19
  close(): Promise<void>;
21
- setContent(...args: Parameters<Page['setContent']>): Promise<void>;
22
20
  setExtraHttpHeaders(headers: Record<string, string>): Promise<void>;
23
- navigate(...args: Parameters<Page['goto']>): Promise<void>;
24
21
  waitForClose(): Promise<void>;
25
- waitForLoadState(...args: Parameters<Page['waitForLoadState']>): Promise<void>;
26
- waitForUrl(...args: Parameters<Page['waitForURL']>): Promise<void>;
27
- getBySelector(selector: string, options?: SimplifyObject<Pick<NonUndefinable<Parameters<Page['locator']>[1]>, 'hasText' | 'hasNotText'>>): ElementController;
28
- getByRole(role: Parameters<Page['getByRole']>[0], options?: Parameters<Page['getByRole']>[1]): ElementController;
29
- getByLabel(text: Parameters<Page['getByLabel']>[0], options?: Parameters<Page['getByLabel']>[1]): ElementController;
30
- getByAltText(text: Parameters<Page['getByAltText']>[0], options?: Parameters<Page['getByAltText']>[1]): ElementController;
31
- getByPlaceholder(text: Parameters<Page['getByPlaceholder']>[0], options?: Parameters<Page['getByPlaceholder']>[1]): ElementController;
32
- getByText(text: Parameters<Page['getByText']>[0], options?: Parameters<Page['getByText']>[1]): ElementController;
33
- getByTitle(text: Parameters<Page['getByTitle']>[0], options?: Parameters<Page['getByTitle']>[1]): ElementController;
22
+ /**
23
+ * @param frameSelector frame name, url or url predicate
24
+ * @returns
25
+ */
26
+ getFrame(frameSelector: Parameters<Page['frame']>[0]): FrameController;
34
27
  renderPdf(options?: PdfRenderOptions & Abortable): Promise<Uint8Array>;
35
28
  renderPdfStream(options?: PdfRenderOptions & Abortable): ReadableStream<Uint8Array>;
36
29
  }
@@ -26,16 +26,16 @@ var import_readable_stream_from_promise = require("../utils/stream/readable-stre
26
26
  var import_timing = require("../utils/timing.js");
27
27
  var import_type_guards = require("../utils/type-guards.js");
28
28
  var import_units = require("../utils/units.js");
29
- var import_element_controller = require("./element-controller.js");
30
- class PageController {
31
- elementControllerOptions;
29
+ var import_document_controller = require("./document-controller.js");
30
+ var import_frame_controller = require("./frame-controller.js");
31
+ class PageController extends import_document_controller.DocumentController {
32
32
  /** @deprecated should be avoided */
33
33
  page;
34
34
  options;
35
35
  constructor(page, options = {}) {
36
+ super(page, options, { pageControllerOptions: options, frameControllerOptions: options.defaultFrameControllerOptions ?? options });
36
37
  this.page = page;
37
38
  this.options = options;
38
- this.elementControllerOptions = { actionDelay: this.options.defaultActionDelay, typeDelay: this.options.defaultTypeDelay };
39
39
  }
40
40
  async [import_disposable.disposeAsync]() {
41
41
  await this.close();
@@ -43,15 +43,9 @@ class PageController {
43
43
  async close() {
44
44
  await this.page.close();
45
45
  }
46
- async setContent(...args) {
47
- await this.page.setContent(...args);
48
- }
49
46
  async setExtraHttpHeaders(headers) {
50
47
  await this.page.setExtraHTTPHeaders(headers);
51
48
  }
52
- async navigate(...args) {
53
- await this.page.goto(...args);
54
- }
55
49
  async waitForClose() {
56
50
  return new Promise((resolve) => {
57
51
  if (this.page.isClosed()) {
@@ -61,39 +55,16 @@ class PageController {
61
55
  this.page.once("close", () => resolve());
62
56
  });
63
57
  }
64
- async waitForLoadState(...args) {
65
- await this.page.waitForLoadState(...args);
66
- }
67
- async waitForUrl(...args) {
68
- await this.page.waitForURL(...args);
69
- }
70
- getBySelector(selector, options) {
71
- const locator = this.page.locator(selector, options);
72
- return new import_element_controller.ElementController(locator, this, this.elementControllerOptions);
73
- }
74
- getByRole(role, options) {
75
- const locator = this.page.getByRole(role, options);
76
- return new import_element_controller.ElementController(locator, this, this.elementControllerOptions);
77
- }
78
- getByLabel(text, options) {
79
- const locator = this.page.getByLabel(text, options);
80
- return new import_element_controller.ElementController(locator, this, this.elementControllerOptions);
81
- }
82
- getByAltText(text, options) {
83
- const locator = this.page.getByAltText(text, options);
84
- return new import_element_controller.ElementController(locator, this, this.elementControllerOptions);
85
- }
86
- getByPlaceholder(text, options) {
87
- const locator = this.page.getByPlaceholder(text, options);
88
- return new import_element_controller.ElementController(locator, this, this.elementControllerOptions);
89
- }
90
- getByText(text, options) {
91
- const locator = this.page.getByText(text, options);
92
- return new import_element_controller.ElementController(locator, this, this.elementControllerOptions);
93
- }
94
- getByTitle(text, options) {
95
- const locator = this.page.getByTitle(text, options);
96
- return new import_element_controller.ElementController(locator, this, this.elementControllerOptions);
58
+ /**
59
+ * @param frameSelector frame name, url or url predicate
60
+ * @returns
61
+ */
62
+ getFrame(frameSelector) {
63
+ const frame = this.page.frame(frameSelector);
64
+ if ((0, import_type_guards.isNull)(frame)) {
65
+ throw new Error("Frame not found.");
66
+ }
67
+ return new import_frame_controller.FrameController(frame, this.options, this.forwardOptions);
97
68
  }
98
69
  async renderPdf(options = {}) {
99
70
  const createPdfOptions = convertPdfOptions(options);
package/core.d.ts CHANGED
@@ -4,9 +4,12 @@ import type { LoggerArgument } from './logger/index.js';
4
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
+ export declare function isDevMode(): boolean;
8
+ export declare function enableProductionMode(): void;
7
9
  export declare function connect(name: string, connectFunction: (() => Promise<any>), logger: Logger, maxTries?: number): Promise<void>;
8
10
  export declare function disposeInstances(): Promise<void>;
9
11
  export type CoreConfiguration = {
12
+ production?: boolean;
10
13
  logger?: InjectionToken<Logger, LoggerArgument>;
11
14
  logLevel?: LogLevel;
12
15
  coreLogPrefix?: string;
package/core.js CHANGED
@@ -22,7 +22,9 @@ __export(core_exports, {
22
22
  configureTstdl: () => configureTstdl,
23
23
  connect: () => connect,
24
24
  disposeInstances: () => disposeInstances,
25
- disposer: () => disposer
25
+ disposer: () => disposer,
26
+ enableProductionMode: () => enableProductionMode,
27
+ isDevMode: () => isDevMode
26
28
  });
27
29
  module.exports = __toCommonJS(core_exports);
28
30
  var import_container = require("./container/index.js");
@@ -33,6 +35,13 @@ var import_timing = require("./utils/timing.js");
33
35
  var import_type_guards = require("./utils/type-guards.js");
34
36
  const CORE_LOGGER = (0, import_container.injectionToken)("core logger");
35
37
  const disposer = new import_async_disposer.AsyncDisposer();
38
+ let _isDevMode = true;
39
+ function isDevMode() {
40
+ return _isDevMode;
41
+ }
42
+ function enableProductionMode() {
43
+ _isDevMode = false;
44
+ }
36
45
  async function connect(name, connectFunction, logger, maxTries = 5) {
37
46
  let triesLeft = maxTries;
38
47
  let success = false;
@@ -57,6 +66,9 @@ async function disposeInstances() {
57
66
  }
58
67
  let coreLogPrefix;
59
68
  function configureTstdl(config = {}) {
69
+ if (config.production == true) {
70
+ enableProductionMode();
71
+ }
60
72
  import_container.container.register(import_logger2.Logger, { useToken: config.logger ?? import_logger.ConsoleLogger });
61
73
  import_container.container.registerSingleton(import_logger2.LogLevel, { useFactory: (level) => (0, import_type_guards.assertDefinedPass)(level, "LogLevel argument not provided") }, { defaultArgumentProvider: () => config.logLevel ?? import_logger2.LogLevel.Trace });
62
74
  if ((0, import_type_guards.isDefined)(config.coreLogPrefix)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.84.2",
3
+ "version": "0.84.4",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -23,7 +23,7 @@
23
23
  "luxon": "^3.3",
24
24
  "reflect-metadata": "^0.1",
25
25
  "rxjs": "^7.8",
26
- "type-fest": "^3.9"
26
+ "type-fest": "^3.10"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@types/chroma-js": "2.4",
@@ -31,13 +31,13 @@
31
31
  "@types/luxon": "3.3",
32
32
  "@types/minio": "7.0",
33
33
  "@types/mjml": "4.7",
34
- "@types/node": "18",
34
+ "@types/node": "20",
35
35
  "@types/nodemailer": "6.4",
36
36
  "@typescript-eslint/eslint-plugin": "5.59",
37
37
  "@typescript-eslint/parser": "5.59",
38
38
  "concurrently": "8.0",
39
39
  "esbuild": "0.17",
40
- "eslint": "8.39",
40
+ "eslint": "8.40",
41
41
  "eslint-import-resolver-typescript": "3.5",
42
42
  "eslint-plugin-import": "2.27",
43
43
  "tsc-alias": "1.8",
@@ -58,7 +58,7 @@
58
58
  "koa": "^2.14",
59
59
  "minio": "^7.1",
60
60
  "mjml": "^4.14",
61
- "mongodb": "^5.3",
61
+ "mongodb": "^5.4",
62
62
  "nodemailer": "^6.9",
63
63
  "playwright": "^1.33",
64
64
  "preact": "^10.13",
@@ -32,7 +32,7 @@ class Uint8ArrayCoercer extends import_types.SchemaValueCoercer {
32
32
  sourceType = Array;
33
33
  targetType = Uint8Array;
34
34
  coerce(value, path, { options }) {
35
- const testResult = (0, import_schema.testWithFastError)(byteNumberArraySchema, value, options, path);
35
+ const testResult = (0, import_schema.testSchema)(byteNumberArraySchema, value, options, path);
36
36
  if (!testResult.valid) {
37
37
  return { success: false, error: import_schema_error.SchemaError.couldNotCoerce(Uint8Array, Array, path, { inner: testResult.error, fast: options.fastErrors }) };
38
38
  }
@@ -11,4 +11,5 @@ export declare const Schema: {
11
11
  function<T_3 extends readonly SchemaTestable<any>[], R extends SchemaTestable<any>, F extends (...args: TupleSchemaOutput<T_3>) => SchemaOutput<R>>(argumentSchemas: T_3, returnSchema: R, handler: F): F;
12
12
  asyncFunction<T_4 extends readonly SchemaTestable<any>[], R_1 extends SchemaTestable<any>, F_1 extends (...args: TupleSchemaOutput<T_4>) => Promise<SchemaOutput<R_1>>>(argumentSchemas: T_4, returnSchema: R_1, handler: F_1): F_1;
13
13
  };
14
- export declare function testWithFastError<T>(schema: Schema<T>, value: unknown, options?: SchemaTestOptions, path?: JsonPath): SchemaTestResult<T>;
14
+ export declare function testSchema<T>(schema: Schema<T>, value: unknown, options?: SchemaTestOptions, path?: JsonPath): SchemaTestResult<T>;
15
+ export declare function getExpectString(schema: SchemaTestable): string;
@@ -24,6 +24,7 @@ module.exports = __toCommonJS(schema_error_exports);
24
24
  var import_custom_error = require("../error/custom.error.js");
25
25
  var import_array = require("../utils/array/array.js");
26
26
  var import_type_guards = require("../utils/type-guards.js");
27
+ var import_schema = require("./schema.js");
27
28
  var import_utils = require("./utils/index.js");
28
29
  class SchemaError extends import_custom_error.CustomError {
29
30
  static errorName = "SchemaError";
@@ -42,9 +43,9 @@ class SchemaError extends import_custom_error.CustomError {
42
43
  }
43
44
  // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
44
45
  static expectedButGot(expected, got, path, options) {
45
- const expectedNames = (0, import_array.toArray)(expected).map((exp) => (0, import_type_guards.isString)(exp) ? exp : (0, import_utils.getValueTypeName)(exp));
46
+ const expectedNames = (0, import_array.toArray)(expected).map((exp) => (0, import_type_guards.isString)(exp) ? exp : (0, import_schema.getExpectString)(exp));
46
47
  const gotName = (0, import_type_guards.isString)(got) ? got : (0, import_utils.getValueTypeName)(got);
47
- const expectedString = expectedNames.length == 1 ? expectedNames[0] : `[${expectedNames.join(", ")}]`;
48
+ const expectedString = expectedNames.length == 1 ? expectedNames[0] : `(${expectedNames.join(" | ")})`;
48
49
  const customMessage = (0, import_type_guards.isDefined)(options.customMessage) ? `: ${options.customMessage}` : ".";
49
50
  const message = `Expected ${expectedString} but got ${gotName}${customMessage}`;
50
51
  return new SchemaError(message, { path, ...options });
package/schema/schema.js CHANGED
@@ -19,7 +19,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  var schema_exports = {};
20
20
  __export(schema_exports, {
21
21
  Schema: () => Schema,
22
- testWithFastError: () => testWithFastError
22
+ getExpectString: () => getExpectString,
23
+ testSchema: () => testSchema
23
24
  });
24
25
  module.exports = __toCommonJS(schema_exports);
25
26
  var import_json_path = require("../json-path/index.js");
@@ -54,14 +55,14 @@ const Schema = {
54
55
  test(schemaOrValueType, value, options, path = import_json_path.JsonPath.ROOT) {
55
56
  const normalizedOptions = { fastErrors: true, ...options };
56
57
  const schema = (0, import_types.schemaTestableToSchema)(schemaOrValueType);
57
- const result = testWithFastError(schema, value, normalizedOptions, path);
58
+ const result = testSchema(schema, value, normalizedOptions, path);
58
59
  if (result.valid) {
59
60
  return result;
60
61
  }
61
- if (options?.fastErrors == false) {
62
- return result;
62
+ if ((0, import_type_guards.isUndefined)(result.error.stack)) {
63
+ result.error.stack = new Error().stack;
63
64
  }
64
- return { valid: false, error: new import_schema_error.SchemaError(result.error.message, { ...result.error }) };
65
+ return result;
65
66
  },
66
67
  validate(schemaOrValueType, value, options) {
67
68
  const schema = (0, import_types.schemaTestableToSchema)(schemaOrValueType);
@@ -107,7 +108,7 @@ function getFunctionParametersSchema(argumentSchemas) {
107
108
  argumentSchemas.forEach((arg, index) => schema.properties[index] = arg);
108
109
  return schema;
109
110
  }
110
- function testWithFastError(schema, value, options, path = import_json_path.JsonPath.ROOT) {
111
+ function testSchema(schema, value, options, path = import_json_path.JsonPath.ROOT) {
111
112
  initialize();
112
113
  if ((0, import_types.isValueSchema)(schema)) {
113
114
  return testValue(schema, value, options, path);
@@ -122,9 +123,7 @@ function testWithFastError(schema, value, options, path = import_json_path.JsonP
122
123
  }
123
124
  function testType(schema, value, options = {}, path = import_json_path.JsonPath.ROOT) {
124
125
  const resolvedValueType = (0, import_types.resolveValueType)(schema.type);
125
- if (resolvedValueType == "any") {
126
- return { valid: true, value };
127
- } else if ((0, import_type_guards.isFunction)(resolvedValueType)) {
126
+ if ((0, import_type_guards.isFunction)(resolvedValueType)) {
128
127
  if (value instanceof resolvedValueType || (0, import_utils.getValueType)(value) == resolvedValueType) {
129
128
  return { valid: true, value };
130
129
  }
@@ -132,7 +131,7 @@ function testType(schema, value, options = {}, path = import_json_path.JsonPath.
132
131
  if ((0, import_type_guards.isNotNull)(objectSchema)) {
133
132
  return testObject(objectSchema, value, options, path);
134
133
  }
135
- } else if (resolvedValueType == "null" && (0, import_type_guards.isNull)(value) || resolvedValueType == "undefined" && (0, import_type_guards.isUndefined)(value) || resolvedValueType == "any") {
134
+ } else if (resolvedValueType == "any" || resolvedValueType == "null" && (0, import_type_guards.isNull)(value) || resolvedValueType == "undefined" && (0, import_type_guards.isUndefined)(value)) {
136
135
  return { valid: true, value };
137
136
  }
138
137
  return { valid: false, error: import_schema_error.SchemaError.expectedButGot(resolvedValueType, (0, import_utils.getValueType)(value), path, { fast: options.fastErrors }) };
@@ -151,7 +150,7 @@ function testObject(objectSchema, value, options = {}, path = import_json_path.J
151
150
  return { valid: false, error: new import_schema_error.SchemaError("Unknown property", { path: path.add(unknownValuePropertyKeys[0]), fast: options.fastErrors }) };
152
151
  }
153
152
  for (const key of schemaPropertyKeys) {
154
- const propertyResult = testWithFastError(schema.properties[key], value[key], options, path.add(key));
153
+ const propertyResult = testSchema(schema.properties[key], value[key], options, path.add(key));
155
154
  if (!propertyResult.valid) {
156
155
  return propertyResult;
157
156
  }
@@ -161,12 +160,12 @@ function testObject(objectSchema, value, options = {}, path = import_json_path.J
161
160
  for (const key of unknownValuePropertyKeys) {
162
161
  const propertyPath = path.add(key);
163
162
  if ((0, import_type_guards.isDefined)(schema.unknownPropertiesKey)) {
164
- const keyResult = testWithFastError(schema.unknownPropertiesKey, key, options);
163
+ const keyResult = testSchema(schema.unknownPropertiesKey, key, options);
165
164
  if (!keyResult.valid && !mask) {
166
165
  return { valid: false, error: new import_schema_error.SchemaError("Invalid property key.", { path: propertyPath, inner: keyResult.error, fast: options.fastErrors }) };
167
166
  }
168
167
  }
169
- const propertyResult = testWithFastError(schema.unknownProperties, value[key], options, path.add(key));
168
+ const propertyResult = testSchema(schema.unknownProperties, value[key], options, path.add(key));
170
169
  if (!propertyResult.valid && !mask) {
171
170
  return propertyResult;
172
171
  }
@@ -275,7 +274,7 @@ function testValue(schema, value, options = {}, path = import_json_path.JsonPath
275
274
  function isValidValue(validSchemas, value, options, path) {
276
275
  const errorResults = [];
277
276
  for (const schema of validSchemas) {
278
- const result = testWithFastError(schema, value, options, path);
277
+ const result = testSchema(schema, value, options, path);
279
278
  if (result.valid) {
280
279
  return result;
281
280
  }
@@ -287,15 +286,16 @@ function isValidValue(validSchemas, value, options, path) {
287
286
  const errors = errorResults.map((result) => result.error);
288
287
  const expectStrings = [];
289
288
  for (const schema of validSchemas) {
290
- getExpectString(schema);
289
+ expectStrings.push(getExpectString(schema));
291
290
  }
292
- const expectString = expectStrings.join("\n");
291
+ const expectString = expectStrings.length > 1 ? `(${expectStrings.join(" | ")})` : expectStrings[0];
293
292
  return { valid: false, error: import_schema_error.SchemaError.expectedButGot(expectString, (0, import_utils.getValueType)(value), path, { inner: errors, fast: options.fastErrors }) };
294
293
  }
295
294
  function getExpectString(schema) {
296
295
  const expectedNames = (0, import_utils.getSchemaTypeNames)(schema);
297
- const expectedTypeString = expectedNames.length == 1 ? expectedNames[0] : `[${expectedNames.join(", ")}]`;
296
+ const arraySuffix = (0, import_types.isValueSchema)(schema) && schema.array == true ? "[]" : "";
297
+ const expectedTypeString = expectedNames.length == 1 ? `${expectedNames[0]}${arraySuffix}` : `(${expectedNames.join(" | ")})${arraySuffix}`;
298
298
  const expects = (0, import_types.isValueSchema)(schema) ? (0, import_array.toArray)(schema.valueConstraints ?? []).map((constraint) => constraint.expects) : [];
299
- const expectsString = expects.length > 0 ? ` (${expects.join(", ")})` : "";
299
+ const expectsString = expects.length > 0 ? `[${expects.join(", ")}]` : "";
300
300
  return `${expectedTypeString}${expectsString}`;
301
301
  }
@@ -28,6 +28,7 @@ module.exports = __toCommonJS(value_type_exports);
28
28
  var import_array = require("../../utils/array/array.js");
29
29
  var import_type_guards = require("../../utils/type-guards.js");
30
30
  var import_types = require("../types/types.js");
31
+ const lowercaseTypesSet = /* @__PURE__ */ new Set([...import_types.primitiveConstructorSet, Object, Array]);
31
32
  function getValueType(value) {
32
33
  if ((0, import_type_guards.isUndefined)(value)) {
33
34
  return "undefined";
@@ -47,10 +48,10 @@ function includesValueType(valueType, valueTypes) {
47
48
  }
48
49
  function getValueTypeName(valueType) {
49
50
  const resolvedValueType = (0, import_types.resolveValueType)(valueType);
50
- return (0, import_type_guards.isString)(resolvedValueType) ? resolvedValueType : resolvedValueType.name;
51
+ return (0, import_type_guards.isString)(resolvedValueType) ? resolvedValueType : lowercaseTypesSet.has(resolvedValueType) ? resolvedValueType.name.toLowerCase() : resolvedValueType.name;
51
52
  }
52
53
  function getSchemaTypeNames(schema) {
53
- return getSchemaValueTypes(schema).map((valueType) => (0, import_type_guards.isString)(valueType) ? valueType : valueType.name);
54
+ return getSchemaValueTypes(schema).map(getValueTypeName);
54
55
  }
55
56
  function getSchemaValueTypes(schema) {
56
57
  if ((0, import_types.isTypeSchema)(schema)) {