@tstdl/base 0.84.2 → 0.84.3
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/browser/page-controller.d.ts +4 -1
- package/browser/page-controller.js +22 -0
- package/core.d.ts +3 -0
- package/core.js +13 -1
- package/package.json +5 -5
- package/schema/coercers/uint8-array.coercer.js +1 -1
- package/schema/schema.d.ts +2 -1
- package/schema/schema.error.js +3 -2
- package/schema/schema.js +18 -18
- package/schema/utils/value-type.js +3 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Page } from 'playwright';
|
|
1
|
+
import type { ElementHandle, Page } from 'playwright';
|
|
2
2
|
import type { AsyncDisposable } from '../disposable/disposable.js';
|
|
3
3
|
import { disposeAsync } from '../disposable/disposable.js';
|
|
4
4
|
import type { NonUndefinable, SimplifyObject } from '../types.js';
|
|
@@ -24,6 +24,9 @@ export declare class PageController implements AsyncDisposable {
|
|
|
24
24
|
waitForClose(): Promise<void>;
|
|
25
25
|
waitForLoadState(...args: Parameters<Page['waitForLoadState']>): Promise<void>;
|
|
26
26
|
waitForUrl(...args: Parameters<Page['waitForURL']>): Promise<void>;
|
|
27
|
+
waitForElement(selector: string, options: Parameters<Page['waitForSelector']>[1]): Promise<ElementHandle>;
|
|
28
|
+
waitForFrame(selector: string, options: Parameters<Page['waitForSelector']>[1]): Promise<PageController>;
|
|
29
|
+
getFrame(selector: Parameters<Page['frame']>[0]): PageController;
|
|
27
30
|
getBySelector(selector: string, options?: SimplifyObject<Pick<NonUndefinable<Parameters<Page['locator']>[1]>, 'hasText' | 'hasNotText'>>): ElementController;
|
|
28
31
|
getByRole(role: Parameters<Page['getByRole']>[0], options?: Parameters<Page['getByRole']>[1]): ElementController;
|
|
29
32
|
getByLabel(text: Parameters<Page['getByLabel']>[0], options?: Parameters<Page['getByLabel']>[1]): ElementController;
|
|
@@ -67,6 +67,28 @@ class PageController {
|
|
|
67
67
|
async waitForUrl(...args) {
|
|
68
68
|
await this.page.waitForURL(...args);
|
|
69
69
|
}
|
|
70
|
+
async waitForElement(selector, options) {
|
|
71
|
+
const element = await this.page.waitForSelector(selector, options);
|
|
72
|
+
if ((0, import_type_guards.isNull)(element)) {
|
|
73
|
+
throw new Error("Element not found.");
|
|
74
|
+
}
|
|
75
|
+
return element;
|
|
76
|
+
}
|
|
77
|
+
async waitForFrame(selector, options) {
|
|
78
|
+
const element = await this.waitForElement(selector, options);
|
|
79
|
+
const frame = await element.contentFrame();
|
|
80
|
+
if ((0, import_type_guards.isNull)(frame)) {
|
|
81
|
+
throw new Error("Element is not a frame.");
|
|
82
|
+
}
|
|
83
|
+
return new PageController(frame.page(), this.options);
|
|
84
|
+
}
|
|
85
|
+
getFrame(selector) {
|
|
86
|
+
const frame = this.page.frame(selector);
|
|
87
|
+
if ((0, import_type_guards.isNull)(frame)) {
|
|
88
|
+
throw new Error("Frame not found.");
|
|
89
|
+
}
|
|
90
|
+
return new PageController(frame.page(), this.options);
|
|
91
|
+
}
|
|
70
92
|
getBySelector(selector, options) {
|
|
71
93
|
const locator = this.page.locator(selector, options);
|
|
72
94
|
return new import_element_controller.ElementController(locator, this, this.elementControllerOptions);
|
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.
|
|
3
|
+
"version": "0.84.3",
|
|
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.
|
|
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": "
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
}
|
package/schema/schema.d.ts
CHANGED
|
@@ -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
|
|
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;
|
package/schema/schema.error.js
CHANGED
|
@@ -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,
|
|
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] : `
|
|
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
|
-
|
|
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 =
|
|
58
|
+
const result = testSchema(schema, value, normalizedOptions, path);
|
|
58
59
|
if (result.valid) {
|
|
59
60
|
return result;
|
|
60
61
|
}
|
|
61
|
-
if (
|
|
62
|
-
|
|
62
|
+
if ((0, import_type_guards.isUndefined)(result.error.stack)) {
|
|
63
|
+
result.error.stack = new Error().stack;
|
|
63
64
|
}
|
|
64
|
-
return
|
|
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
|
|
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 (
|
|
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)
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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("
|
|
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
|
|
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 ? `
|
|
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(
|
|
54
|
+
return getSchemaValueTypes(schema).map(getValueTypeName);
|
|
54
55
|
}
|
|
55
56
|
function getSchemaValueTypes(schema) {
|
|
56
57
|
if ((0, import_types.isTypeSchema)(schema)) {
|