@tstdl/base 0.85.24 → 0.85.26

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.
@@ -17,12 +17,34 @@ export type ElementControllerOptions = {
17
17
  };
18
18
  type LocatorOptions<K extends keyof Locator, I extends keyof Parameters<Locator[K]>> = NonUndefinable<Parameters<Locator[K]>[I]>;
19
19
  type Methods = 'isVisible' | 'isHidden' | 'isEnabled' | 'isDisabled' | 'isChecked' | 'isEditable' | 'fill' | 'type' | 'press' | 'check' | 'uncheck' | 'setChecked' | 'selectOption' | 'setInputFiles' | 'click' | 'hover' | 'focus' | 'tap' | 'selectText' | 'inputValue';
20
+ export type Filter = {
21
+ has?: ElementController;
22
+ hasNot?: ElementController;
23
+ hasText?: string | RegExp;
24
+ hasNotText?: string | RegExp;
25
+ };
20
26
  export declare class ElementController<T extends Locator | ElementHandle = Locator | ElementHandle> implements Pick<Locator, Methods> {
21
27
  readonly locatorOrHandle: T;
22
28
  readonly options: ElementControllerOptions;
23
29
  constructor(locatorOrHandle: T, options?: ElementControllerOptions);
24
30
  getAll(): Promise<ElementController<Locator>[]>;
25
31
  getAllHandles(): Promise<ElementController<ElementHandle>[]>;
32
+ /**
33
+ * Get an controller with elements contained in this and the provided controller.
34
+ * Requires locator based controller
35
+ * @param elementController
36
+ */
37
+ and(elementController: ElementController): ElementController<Locator>;
38
+ /**
39
+ * Filter out elements with by provided filter.
40
+ * Requires locator based controller.
41
+ */
42
+ filter(filter: Filter): ElementController<Locator>;
43
+ /**
44
+ * Locate elements in subtree with provided selector/controller and filter.
45
+ * Requires locator based controller.
46
+ */
47
+ locate(selectorOrController: string | ElementController, filter?: Filter): ElementController<Locator>;
26
48
  /**
27
49
  * Wait for element state
28
50
  * @param state some states may only be usable for either locator or handle
@@ -25,6 +25,7 @@ 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
27
  var import_utils = require("./utils.js");
28
+ const filterNonLocatorErrorMessage = "Requires a locator basesd controller";
28
29
  class ElementController {
29
30
  locatorOrHandle;
30
31
  options;
@@ -46,6 +47,37 @@ class ElementController {
46
47
  const handles = await this.locatorOrHandle.elementHandles();
47
48
  return handles.map((handle) => new ElementController(handle));
48
49
  }
50
+ /**
51
+ * Get an controller with elements contained in this and the provided controller.
52
+ * Requires locator based controller
53
+ * @param elementController
54
+ */
55
+ and(elementController) {
56
+ (0, import_utils.assertLocator)(this.locatorOrHandle, filterNonLocatorErrorMessage);
57
+ (0, import_utils.assertLocator)(elementController.locatorOrHandle, filterNonLocatorErrorMessage);
58
+ const locator = this.locatorOrHandle.and(elementController.locatorOrHandle);
59
+ return new ElementController(locator, this.options);
60
+ }
61
+ /**
62
+ * Filter out elements with by provided filter.
63
+ * Requires locator based controller.
64
+ */
65
+ filter(filter) {
66
+ (0, import_utils.assertLocator)(this.locatorOrHandle, filterNonLocatorErrorMessage);
67
+ const locator = this.locatorOrHandle.filter(convertFilter(filter));
68
+ return new ElementController(locator, this.options);
69
+ }
70
+ /**
71
+ * Locate elements in subtree with provided selector/controller and filter.
72
+ * Requires locator based controller.
73
+ */
74
+ locate(selectorOrController, filter) {
75
+ (0, import_utils.assertLocator)(this.locatorOrHandle, filterNonLocatorErrorMessage);
76
+ const selector = (0, import_type_guards.isString)(selectorOrController) ? selectorOrController : (0, import_utils.assertLocatorPass)(selectorOrController.locatorOrHandle, filterNonLocatorErrorMessage);
77
+ const convertedFilter = (0, import_type_guards.isDefined)(filter) ? convertFilter(filter) : void 0;
78
+ const locator = this.locatorOrHandle.locator(selector, convertedFilter);
79
+ return new ElementController(locator, this.options);
80
+ }
49
81
  /**
50
82
  * Wait for element state
51
83
  * @param state some states may only be usable for either locator or handle
@@ -178,3 +210,11 @@ async function delay(milliseconds) {
178
210
  }
179
211
  await (0, import_timing.timeout)((0, import_value_or_provider.resolveValueOrProvider)(milliseconds));
180
212
  }
213
+ function convertFilter(filter) {
214
+ return {
215
+ has: (0, import_type_guards.isDefined)(filter.has) ? (0, import_utils.assertLocatorPass)(filter.has.locatorOrHandle, filterNonLocatorErrorMessage) : void 0,
216
+ hasNot: (0, import_type_guards.isDefined)(filter.hasNot) ? (0, import_utils.assertLocatorPass)(filter.hasNot.locatorOrHandle, filterNonLocatorErrorMessage) : void 0,
217
+ hasText: filter.hasText,
218
+ hasNotText: filter.hasNotText
219
+ };
220
+ }
@@ -6,6 +6,8 @@ export declare function getLaunchOptions(options: NewBrowserOptions): LaunchOpti
6
6
  export declare function mergeNewBrowserContextOptions(a: NewBrowserContextOptions | undefined, b?: NewBrowserContextOptions, c?: NewBrowserContextOptions): NewBrowserContextOptions;
7
7
  export declare function attachLogger(loggable: Page | BrowserContext, logger: Logger): void;
8
8
  export declare function isLocator(locatorOrHandle: Locator | ElementHandle): locatorOrHandle is Locator;
9
+ export declare function assertLocator(locatorOrHandle: Locator | ElementHandle, message?: string): asserts locatorOrHandle is Locator;
10
+ export declare function assertLocatorPass(locatorOrHandle: Locator | ElementHandle, message?: string): Locator;
9
11
  export declare function isElementHandle(locatorOrHandle: Locator | ElementHandle): locatorOrHandle is ElementHandle;
10
12
  export declare function isPage(pageOrFrameOrContext: Page | Frame | BrowserContext): pageOrFrameOrContext is Page;
11
13
  export declare function isFrame(pageOrFrameOrContext: Page | Frame | BrowserContext): pageOrFrameOrContext is Frame;
package/browser/utils.js CHANGED
@@ -18,6 +18,8 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var utils_exports = {};
20
20
  __export(utils_exports, {
21
+ assertLocator: () => assertLocator,
22
+ assertLocatorPass: () => assertLocatorPass,
21
23
  attachLogger: () => attachLogger,
22
24
  getLaunchOptions: () => getLaunchOptions,
23
25
  isBrowserContext: () => isBrowserContext,
@@ -104,6 +106,13 @@ function attachLogger(loggable, logger) {
104
106
  function isLocator(locatorOrHandle) {
105
107
  return locatorOrHandle.constructor.name == "Locator";
106
108
  }
109
+ function assertLocator(locatorOrHandle, message = "Locator instead of ElementHandle required") {
110
+ (0, import_type_guards.assert)(isLocator(locatorOrHandle), message);
111
+ }
112
+ function assertLocatorPass(locatorOrHandle, message = "Locator instead of ElementHandle required") {
113
+ assertLocator(locatorOrHandle, message);
114
+ return locatorOrHandle;
115
+ }
107
116
  function isElementHandle(locatorOrHandle) {
108
117
  return locatorOrHandle.constructor.name == "ElementHandle";
109
118
  }
package/decorators/log.js CHANGED
@@ -25,27 +25,31 @@ var import_log = require("../function/log.js");
25
25
  var import_utils = require("../reflection/utils.js");
26
26
  var import_object = require("../utils/object/object.js");
27
27
  var import_type_guards = require("../utils/type-guards.js");
28
- const isLogWrapped = Symbol("log wrapped");
29
- function wrapLogTagged(fn, options) {
30
- const wrapped = (0, import_log.wrapLog)(fn, options);
31
- wrapped[isLogWrapped] = true;
32
- return wrapped;
28
+ const wrappedStaticMethods = /* @__PURE__ */ new WeakMap();
29
+ const wrappedInstanceMethods = /* @__PURE__ */ new WeakMap();
30
+ function isWrapped(constructor, property, isStatic) {
31
+ return (isStatic ? wrappedStaticMethods : wrappedInstanceMethods).get(constructor)?.has(property) ?? false;
33
32
  }
34
- function isWrapped(fn) {
35
- return fn[isLogWrapped] ?? false;
33
+ function setWrapped(constructor, property, isStatic) {
34
+ const map = isStatic ? wrappedStaticMethods : wrappedInstanceMethods;
35
+ if (!map.has(constructor)) {
36
+ map.set(constructor, /* @__PURE__ */ new Set());
37
+ }
38
+ map.get(constructor).add(property);
36
39
  }
37
40
  function Log() {
38
41
  return (0, import_utils.createDecorator)({ class: true, method: true }, (data) => {
39
42
  if (data.type == "method") {
40
- return { value: wrapLogTagged(data.descriptor.value) };
43
+ setWrapped(data.constructor, data.methodKey, data.static);
44
+ return { value: (0, import_log.wrapLog)(data.descriptor.value) };
41
45
  }
42
- const staticProperties = (0, import_object.objectKeys)(data.constructor).filter((property) => property != "length" && property != "name" && property != "prototype" && (0, import_type_guards.isFunction)(data.constructor[property]) && !isWrapped(data.constructor[property]));
43
- const instanceProperties = (0, import_object.objectKeys)(data.prototype).filter((property) => property != "constructor" && (0, import_type_guards.isFunction)(data.prototype[property]) && !isWrapped(data.prototype[property]));
46
+ const staticProperties = (0, import_object.objectKeys)(data.constructor).filter((property) => property != "length" && property != "name" && property != "prototype" && (0, import_type_guards.isFunction)(data.constructor[property]) && !isWrapped(data.constructor, property, true));
47
+ const instanceProperties = (0, import_object.objectKeys)(data.prototype).filter((property) => property != "constructor" && (0, import_type_guards.isFunction)(data.prototype[property]) && !isWrapped(data.constructor, property, false));
44
48
  for (const property of staticProperties) {
45
- data.constructor[property] = wrapLogTagged(data.constructor[property], property);
49
+ data.constructor[property] = (0, import_log.wrapLog)(data.constructor[property], property);
46
50
  }
47
51
  for (const property of instanceProperties) {
48
- data.prototype[property] = wrapLogTagged(data.prototype[property], property);
52
+ data.prototype[property] = (0, import_log.wrapLog)(data.prototype[property], property);
49
53
  }
50
54
  return void 0;
51
55
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.85.24",
3
+ "version": "0.85.26",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -58,7 +58,7 @@
58
58
  "koa": "^2.14",
59
59
  "minio": "^7.1",
60
60
  "mjml": "^4.14",
61
- "mongodb": "^5.7",
61
+ "mongodb": "^5.8",
62
62
  "nodemailer": "^6.9",
63
63
  "playwright": "^1.37",
64
64
  "preact": "^10.17",