doc-detective-common 4.0.0-beta.0-dev.4 → 4.0.0-beta.0-dev.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (200) hide show
  1. package/package.json +1 -1
  2. package/.c8rc.json +0 -8
  3. package/.mocharc.yml +0 -1
  4. package/icon.png +0 -0
  5. package/scripts/check-coverage-ratchet.cjs +0 -123
  6. package/scripts/createCjsWrapper.js +0 -25
  7. package/scripts/generateTypes.cjs +0 -54
  8. package/src/detectTests.ts +0 -660
  9. package/src/index.ts +0 -3
  10. package/src/schemas/build/checkLink_v2.schema.json +0 -81
  11. package/src/schemas/build/checkLink_v3.schema.json +0 -92
  12. package/src/schemas/build/click_v3.schema.json +0 -145
  13. package/src/schemas/build/config_v2.schema.json +0 -1079
  14. package/src/schemas/build/config_v3.schema.json +0 -696
  15. package/src/schemas/build/context_v2.schema.json +0 -135
  16. package/src/schemas/build/context_v3.schema.json +0 -229
  17. package/src/schemas/build/dragAndDrop_v3.schema.json +0 -189
  18. package/src/schemas/build/find_v2.schema.json +0 -168
  19. package/src/schemas/build/find_v3.schema.json +0 -214
  20. package/src/schemas/build/goTo_v2.schema.json +0 -63
  21. package/src/schemas/build/goTo_v3.schema.json +0 -257
  22. package/src/schemas/build/httpRequest_v2.schema.json +0 -321
  23. package/src/schemas/build/httpRequest_v3.schema.json +0 -439
  24. package/src/schemas/build/loadCookie_v3.schema.json +0 -138
  25. package/src/schemas/build/loadVariables_v3.schema.json +0 -10
  26. package/src/schemas/build/moveTo_v2.schema.json +0 -99
  27. package/src/schemas/build/openApi_v2.schema.json +0 -76
  28. package/src/schemas/build/openApi_v3.schema.json +0 -161
  29. package/src/schemas/build/record_v3.schema.json +0 -70
  30. package/src/schemas/build/report_v3.schema.json +0 -53
  31. package/src/schemas/build/resolvedTests_v3.schema.json +0 -238
  32. package/src/schemas/build/runCode_v2.schema.json +0 -201
  33. package/src/schemas/build/runCode_v3.schema.json +0 -138
  34. package/src/schemas/build/runShell_v2.schema.json +0 -189
  35. package/src/schemas/build/runShell_v3.schema.json +0 -156
  36. package/src/schemas/build/saveCookie_v3.schema.json +0 -149
  37. package/src/schemas/build/saveScreenshot_v2.schema.json +0 -150
  38. package/src/schemas/build/screenshot_v3.schema.json +0 -250
  39. package/src/schemas/build/setVariables_v2.schema.json +0 -39
  40. package/src/schemas/build/sourceIntegration_v3.schema.json +0 -51
  41. package/src/schemas/build/spec_v2.schema.json +0 -199
  42. package/src/schemas/build/spec_v3.schema.json +0 -213
  43. package/src/schemas/build/startRecording_v2.schema.json +0 -57
  44. package/src/schemas/build/step_v3.schema.json +0 -669
  45. package/src/schemas/build/stopRecord_v3.schema.json +0 -13
  46. package/src/schemas/build/stopRecording_v2.schema.json +0 -33
  47. package/src/schemas/build/test_v2.schema.json +0 -244
  48. package/src/schemas/build/test_v3.schema.json +0 -292
  49. package/src/schemas/build/typeKeys_v2.schema.json +0 -72
  50. package/src/schemas/build/type_v3.schema.json +0 -131
  51. package/src/schemas/build/wait_v2.schema.json +0 -42
  52. package/src/schemas/build/wait_v3.schema.json +0 -37
  53. package/src/schemas/dereferenceSchemas.cjs +0 -208
  54. package/src/schemas/index.ts +0 -6
  55. package/src/schemas/output_schemas/analytics_v1.schema.json +0 -585
  56. package/src/schemas/output_schemas/checkLink_v1.schema.json +0 -42
  57. package/src/schemas/output_schemas/checkLink_v2.schema.json +0 -80
  58. package/src/schemas/output_schemas/checkLink_v3.schema.json +0 -145
  59. package/src/schemas/output_schemas/click_v1.schema.json +0 -60
  60. package/src/schemas/output_schemas/click_v3.schema.json +0 -252
  61. package/src/schemas/output_schemas/config_v2.schema.json +0 -2628
  62. package/src/schemas/output_schemas/config_v3.schema.json +0 -16470
  63. package/src/schemas/output_schemas/context_v2.schema.json +0 -134
  64. package/src/schemas/output_schemas/context_v3.schema.json +0 -374
  65. package/src/schemas/output_schemas/dragAndDrop_v3.schema.json +0 -496
  66. package/src/schemas/output_schemas/endRecord_v3.schema.json +0 -12
  67. package/src/schemas/output_schemas/find_v1.schema.json +0 -171
  68. package/src/schemas/output_schemas/find_v2.schema.json +0 -184
  69. package/src/schemas/output_schemas/find_v3.schema.json +0 -1349
  70. package/src/schemas/output_schemas/goTo_v1.schema.json +0 -30
  71. package/src/schemas/output_schemas/goTo_v2.schema.json +0 -62
  72. package/src/schemas/output_schemas/goTo_v3.schema.json +0 -419
  73. package/src/schemas/output_schemas/httpRequest_v1.schema.json +0 -115
  74. package/src/schemas/output_schemas/httpRequest_v2.schema.json +0 -392
  75. package/src/schemas/output_schemas/httpRequest_v3.schema.json +0 -994
  76. package/src/schemas/output_schemas/loadCookie_v3.schema.json +0 -228
  77. package/src/schemas/output_schemas/loadVariables_v3.schema.json +0 -9
  78. package/src/schemas/output_schemas/matchText_v1.schema.json +0 -32
  79. package/src/schemas/output_schemas/moveMouse_v1.schema.json +0 -60
  80. package/src/schemas/output_schemas/moveTo_v2.schema.json +0 -98
  81. package/src/schemas/output_schemas/openApi_v2.schema.json +0 -75
  82. package/src/schemas/output_schemas/openApi_v3.schema.json +0 -162
  83. package/src/schemas/output_schemas/record_v3.schema.json +0 -101
  84. package/src/schemas/output_schemas/report_v3.schema.json +0 -16826
  85. package/src/schemas/output_schemas/resolvedTests_v3.schema.json +0 -33331
  86. package/src/schemas/output_schemas/runCode_v2.schema.json +0 -200
  87. package/src/schemas/output_schemas/runCode_v3.schema.json +0 -222
  88. package/src/schemas/output_schemas/runShell_v1.schema.json +0 -35
  89. package/src/schemas/output_schemas/runShell_v2.schema.json +0 -188
  90. package/src/schemas/output_schemas/runShell_v3.schema.json +0 -236
  91. package/src/schemas/output_schemas/saveCookie_v3.schema.json +0 -245
  92. package/src/schemas/output_schemas/saveScreenshot_v2.schema.json +0 -149
  93. package/src/schemas/output_schemas/screenshot_v1.schema.json +0 -48
  94. package/src/schemas/output_schemas/screenshot_v3.schema.json +0 -681
  95. package/src/schemas/output_schemas/scroll_v1.schema.json +0 -50
  96. package/src/schemas/output_schemas/setVariables_v2.schema.json +0 -38
  97. package/src/schemas/output_schemas/sourceIntegration_v3.schema.json +0 -50
  98. package/src/schemas/output_schemas/spec_v2.schema.json +0 -2301
  99. package/src/schemas/output_schemas/spec_v3.schema.json +0 -16630
  100. package/src/schemas/output_schemas/startRecording_v1.schema.json +0 -55
  101. package/src/schemas/output_schemas/startRecording_v2.schema.json +0 -56
  102. package/src/schemas/output_schemas/step_v3.schema.json +0 -7317
  103. package/src/schemas/output_schemas/stopRecord_v3.schema.json +0 -12
  104. package/src/schemas/output_schemas/stopRecording_v1.schema.json +0 -20
  105. package/src/schemas/output_schemas/stopRecording_v2.schema.json +0 -32
  106. package/src/schemas/output_schemas/test_v2.schema.json +0 -1903
  107. package/src/schemas/output_schemas/test_v3.schema.json +0 -15863
  108. package/src/schemas/output_schemas/typeKeys_v2.schema.json +0 -71
  109. package/src/schemas/output_schemas/type_v1.schema.json +0 -62
  110. package/src/schemas/output_schemas/type_v3.schema.json +0 -244
  111. package/src/schemas/output_schemas/wait_v1.schema.json +0 -42
  112. package/src/schemas/output_schemas/wait_v2.schema.json +0 -41
  113. package/src/schemas/output_schemas/wait_v3.schema.json +0 -41
  114. package/src/schemas/schemas.json +0 -121331
  115. package/src/schemas/src_schemas/analytics_v1.schema.json +0 -585
  116. package/src/schemas/src_schemas/checkLink_v1.schema.json +0 -42
  117. package/src/schemas/src_schemas/checkLink_v2.schema.json +0 -65
  118. package/src/schemas/src_schemas/checkLink_v3.schema.json +0 -91
  119. package/src/schemas/src_schemas/click_v1.schema.json +0 -60
  120. package/src/schemas/src_schemas/click_v3.schema.json +0 -144
  121. package/src/schemas/src_schemas/config_v2.schema.json +0 -929
  122. package/src/schemas/src_schemas/config_v3.schema.json +0 -633
  123. package/src/schemas/src_schemas/context_v2.schema.json +0 -108
  124. package/src/schemas/src_schemas/context_v3.schema.json +0 -202
  125. package/src/schemas/src_schemas/dragAndDrop_v3.schema.json +0 -185
  126. package/src/schemas/src_schemas/find_v1.schema.json +0 -137
  127. package/src/schemas/src_schemas/find_v2.schema.json +0 -155
  128. package/src/schemas/src_schemas/find_v3.schema.json +0 -210
  129. package/src/schemas/src_schemas/goTo_v1.schema.json +0 -30
  130. package/src/schemas/src_schemas/goTo_v2.schema.json +0 -58
  131. package/src/schemas/src_schemas/goTo_v3.schema.json +0 -232
  132. package/src/schemas/src_schemas/httpRequest_v1.schema.json +0 -115
  133. package/src/schemas/src_schemas/httpRequest_v2.schema.json +0 -284
  134. package/src/schemas/src_schemas/httpRequest_v3.schema.json +0 -402
  135. package/src/schemas/src_schemas/loadCookie_v3.schema.json +0 -113
  136. package/src/schemas/src_schemas/loadVariables_v3.schema.json +0 -9
  137. package/src/schemas/src_schemas/matchText_v1.schema.json +0 -32
  138. package/src/schemas/src_schemas/moveMouse_v1.schema.json +0 -60
  139. package/src/schemas/src_schemas/moveTo_v2.schema.json +0 -89
  140. package/src/schemas/src_schemas/openApi_v2.schema.json +0 -64
  141. package/src/schemas/src_schemas/openApi_v3.schema.json +0 -161
  142. package/src/schemas/src_schemas/record_v3.schema.json +0 -69
  143. package/src/schemas/src_schemas/report_v3.schema.json +0 -52
  144. package/src/schemas/src_schemas/resolvedTests_v3.schema.json +0 -237
  145. package/src/schemas/src_schemas/runCode_v2.schema.json +0 -181
  146. package/src/schemas/src_schemas/runCode_v3.schema.json +0 -137
  147. package/src/schemas/src_schemas/runShell_v1.schema.json +0 -35
  148. package/src/schemas/src_schemas/runShell_v2.schema.json +0 -166
  149. package/src/schemas/src_schemas/runShell_v3.schema.json +0 -155
  150. package/src/schemas/src_schemas/saveCookie_v3.schema.json +0 -124
  151. package/src/schemas/src_schemas/saveScreenshot_v2.schema.json +0 -129
  152. package/src/schemas/src_schemas/screenshot_v1.schema.json +0 -48
  153. package/src/schemas/src_schemas/screenshot_v3.schema.json +0 -249
  154. package/src/schemas/src_schemas/scroll_v1.schema.json +0 -50
  155. package/src/schemas/src_schemas/setVariables_v2.schema.json +0 -38
  156. package/src/schemas/src_schemas/sourceIntegration_v3.schema.json +0 -45
  157. package/src/schemas/src_schemas/spec_v2.schema.json +0 -175
  158. package/src/schemas/src_schemas/spec_v3.schema.json +0 -212
  159. package/src/schemas/src_schemas/startRecording_v1.schema.json +0 -55
  160. package/src/schemas/src_schemas/startRecording_v2.schema.json +0 -54
  161. package/src/schemas/src_schemas/step_v3.schema.json +0 -632
  162. package/src/schemas/src_schemas/stopRecord_v3.schema.json +0 -9
  163. package/src/schemas/src_schemas/stopRecording_v1.schema.json +0 -20
  164. package/src/schemas/src_schemas/stopRecording_v2.schema.json +0 -32
  165. package/src/schemas/src_schemas/test_v2.schema.json +0 -200
  166. package/src/schemas/src_schemas/test_v3.schema.json +0 -268
  167. package/src/schemas/src_schemas/typeKeys_v2.schema.json +0 -63
  168. package/src/schemas/src_schemas/type_v1.schema.json +0 -62
  169. package/src/schemas/src_schemas/type_v3.schema.json +0 -118
  170. package/src/schemas/src_schemas/wait_v1.schema.json +0 -42
  171. package/src/schemas/src_schemas/wait_v2.schema.json +0 -41
  172. package/src/schemas/src_schemas/wait_v3.schema.json +0 -36
  173. package/src/types/generated/checkLink_v3.ts +0 -29
  174. package/src/types/generated/click_v3.ts +0 -17
  175. package/src/types/generated/config_v3.ts +0 -405
  176. package/src/types/generated/context_v3.ts +0 -112
  177. package/src/types/generated/dragAndDrop_v3.ts +0 -39
  178. package/src/types/generated/endRecord_v3.ts +0 -10
  179. package/src/types/generated/find_v3.ts +0 -17
  180. package/src/types/generated/goTo_v3.ts +0 -48
  181. package/src/types/generated/httpRequest_v3.ts +0 -17
  182. package/src/types/generated/loadCookie_v3.ts +0 -17
  183. package/src/types/generated/loadVariables_v3.ts +0 -10
  184. package/src/types/generated/openApi_v3.ts +0 -64
  185. package/src/types/generated/record_v3.ts +0 -34
  186. package/src/types/generated/report_v3.ts +0 -183
  187. package/src/types/generated/resolvedTests_v3.ts +0 -585
  188. package/src/types/generated/runCode_v3.ts +0 -59
  189. package/src/types/generated/runShell_v3.ts +0 -58
  190. package/src/types/generated/saveCookie_v3.ts +0 -17
  191. package/src/types/generated/screenshot_v3.ts +0 -76
  192. package/src/types/generated/sourceIntegration_v3.ts +0 -31
  193. package/src/types/generated/spec_v3.ts +0 -166
  194. package/src/types/generated/step_v3.ts +0 -1288
  195. package/src/types/generated/stopRecord_v3.ts +0 -10
  196. package/src/types/generated/test_v3.ts +0 -3048
  197. package/src/types/generated/type_v3.ts +0 -56
  198. package/src/types/generated/wait_v3.ts +0 -13
  199. package/src/validate.ts +0 -627
  200. package/tsconfig.json +0 -22
@@ -1,56 +0,0 @@
1
- /* eslint-disable */
2
- /**
3
- * Auto-generated from type_v3.schema.json
4
- * Do not edit manually
5
- */
6
-
7
- /**
8
- * Type keys. To type special keys, begin and end the string with `$` and use the special key's keyword. For example, to type the Escape key, enter `$ESCAPE$`.
9
- */
10
- export type TypeKeys = TypeKeysSimple | TypeKeysDetailed;
11
- /**
12
- * Sequence of keys to enter.
13
- */
14
- export type TypeKeysSimple = string | string[];
15
- /**
16
- * Sequence of keys to enter.
17
- */
18
- export type TypeKeysSimple1 = string | string[];
19
-
20
- export interface TypeKeysDetailed {
21
- keys: TypeKeysSimple1;
22
- /**
23
- * Delay in milliseconds between each key press during a recording
24
- */
25
- inputDelay?: number;
26
- /**
27
- * Selector for the element to type into. If not specified, the typing occurs in the active element.
28
- */
29
- selector?: string;
30
- /**
31
- * Display text of the element to type into. If combined with other element finding fields, the element must match all specified criteria.
32
- */
33
- elementText?: string;
34
- /**
35
- * ID attribute of the element to find. Supports exact match or regex pattern using /pattern/ syntax.
36
- */
37
- elementId?: string;
38
- /**
39
- * data-testid attribute of the element to find. Supports exact match or regex pattern using /pattern/ syntax.
40
- */
41
- elementTestId?: string;
42
- /**
43
- * Class or array of classes that the element must have. Each class supports exact match or regex pattern using /pattern/ syntax. Element must have all specified classes.
44
- */
45
- elementClass?: string | string[];
46
- /**
47
- * Object of attribute key-value pairs that the element must have. Values can be strings (supporting /pattern/ regex), numbers, or booleans. Boolean true matches attribute presence, false matches absence.
48
- */
49
- elementAttribute?: {
50
- [k: string]: string | number | boolean;
51
- };
52
- /**
53
- * Computed accessible name of the element per ARIA specification. Supports exact match or regex pattern using /pattern/ syntax.
54
- */
55
- elementAria?: string;
56
- }
@@ -1,13 +0,0 @@
1
- /* eslint-disable */
2
- /**
3
- * Auto-generated from wait_v3.schema.json
4
- * Do not edit manually
5
- */
6
-
7
- /**
8
- * Pause (in milliseconds) before performing the next action.
9
- */
10
- export type Wait = WaitSimple | WaitEnvironmentVariable | WaitBoolean;
11
- export type WaitSimple = number;
12
- export type WaitEnvironmentVariable = string;
13
- export type WaitBoolean = boolean;
package/src/validate.ts DELETED
@@ -1,627 +0,0 @@
1
- import { schemas, SchemaKey } from "./schemas/index.js";
2
- import Ajv, { ValidateFunction } from "ajv";
3
- // Ajv extra formats: https://ajv.js.org/packages/ajv-formats.html
4
- import addFormats from "ajv-formats";
5
- // Ajv extra keywords: https://ajv.js.org/packages/ajv-keywords.html
6
- import addKeywords from "ajv-keywords";
7
- // Ajv custom errors: https://ajv.js.org/packages/ajv-errors.html
8
- import addErrors from "ajv-errors";
9
- import dynamicDefaultsDef from "ajv-keywords/dist/definitions/dynamicDefaults.js";
10
-
11
- // Browser-compatible UUID function
12
- /* c8 ignore next 10 - crypto.randomUUID always available in Node.js; fallback is for browsers */
13
- function getRandomUUID(): string {
14
- if (typeof crypto !== 'undefined' && crypto.randomUUID) {
15
- return crypto.randomUUID();
16
- }
17
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
18
- const r = Math.random() * 16 | 0;
19
- const v = c === 'x' ? r : (r & 0x3 | 0x8);
20
- return v.toString(16);
21
- });
22
- }
23
-
24
- // Configure base Ajv
25
- // @ts-expect-error - CJS/ESM interop: Ajv constructor is callable at runtime
26
- const ajv = new Ajv({
27
- strictSchema: false,
28
- useDefaults: true,
29
- allErrors: true,
30
- allowUnionTypes: true,
31
- coerceTypes: true,
32
- });
33
-
34
- // Enable `uuid` dynamic default
35
- // @ts-expect-error - CJS/ESM interop: dynamicDefaultsDef.DEFAULTS exists at runtime
36
- dynamicDefaultsDef.DEFAULTS.uuid = (_args: any) => getRandomUUID;
37
-
38
- // Enhance Ajv
39
- // @ts-expect-error - CJS/ESM interop: ajv plugin functions are callable at runtime
40
- addFormats(ajv);
41
- // @ts-expect-error - CJS/ESM interop: ajv plugin functions are callable at runtime
42
- addKeywords(ajv);
43
- // @ts-expect-error - CJS/ESM interop: ajv plugin functions are callable at runtime
44
- addErrors(ajv);
45
-
46
- // Add all schemas from `schema` object.
47
- for (const [key, value] of Object.entries(schemas)) {
48
- ajv.addSchema(value, key);
49
- }
50
-
51
- // Define the specific schemas that have compatibility mappings
52
- const compatibleSchemas = {
53
- config_v3: ["config_v2"],
54
- context_v3: ["context_v2"],
55
- openApi_v3: ["openApi_v2"],
56
- spec_v3: ["spec_v2"],
57
- step_v3: [
58
- "checkLink_v2",
59
- "find_v2",
60
- "goTo_v2",
61
- "httpRequest_v2",
62
- "runShell_v2",
63
- "runCode_v2",
64
- "saveScreenshot_v2",
65
- "setVariables_v2",
66
- "startRecording_v2",
67
- "stopRecording_v2",
68
- "typeKeys_v2",
69
- "wait_v2",
70
- ],
71
- test_v3: ["test_v2"],
72
- } as const;
73
-
74
- type CompatibleSchemaKey = keyof typeof compatibleSchemas;
75
-
76
- export interface ValidateOptions {
77
- schemaKey: string;
78
- object: any;
79
- addDefaults?: boolean;
80
- }
81
-
82
- export interface ValidateResult {
83
- valid: boolean;
84
- errors: string;
85
- object: any;
86
- }
87
-
88
- export interface TransformOptions {
89
- currentSchema: string;
90
- targetSchema: string;
91
- object: any;
92
- }
93
-
94
- /**
95
- * Escapes special characters in a string for safe use in a regular expression pattern.
96
- *
97
- * @param string - The input string to escape.
98
- * @returns The escaped string, safe for use in regular expressions.
99
- */
100
- function escapeRegExp(string: string): string {
101
- return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); // $& means the whole matched string
102
- }
103
-
104
- /**
105
- * Validates an object against a specified JSON schema, supporting backward compatibility and automatic transformation from older schema versions if needed.
106
- *
107
- * If validation against the target schema fails and compatible older schemas are defined, attempts validation against each compatible schema. On a match, transforms the object to the target schema and revalidates. Returns the validation result, any errors, and the (possibly transformed) object.
108
- *
109
- * @param options - Validation options
110
- * @param options.schemaKey - The key identifying the target JSON schema.
111
- * @param options.object - The object to validate.
112
- * @param options.addDefaults - Whether to include default values in the returned object.
113
- * @returns Validation result, error messages, and the validated (and possibly transformed) object.
114
- *
115
- * @throws {Error} If {@link schemaKey} or {@link object} is missing.
116
- */
117
- export function validate({
118
- schemaKey,
119
- object,
120
- addDefaults = true,
121
- }: ValidateOptions): ValidateResult {
122
- if (!schemaKey) {
123
- throw new Error("Schema key is required.");
124
- }
125
- if (!object) {
126
- throw new Error("Object is required.");
127
- }
128
- const result: ValidateResult = {
129
- valid: false,
130
- errors: "",
131
- object: object,
132
- };
133
- let validationObject: any;
134
- let check: ValidateFunction | undefined = ajv.getSchema(schemaKey);
135
- if (!check) {
136
- result.valid = false;
137
- result.errors = `Schema not found: ${schemaKey}`;
138
- result.object = object;
139
- return result;
140
- }
141
-
142
- // Clone the object to avoid modifying the original object
143
- validationObject = JSON.parse(JSON.stringify(object));
144
-
145
- // Check if the object is compatible with the schema
146
- result.valid = check(validationObject);
147
- result.errors = "";
148
-
149
- if (check.errors) {
150
- // Check if the object is compatible with another schema
151
- const compatibleSchemasList =
152
- compatibleSchemas[schemaKey as keyof typeof compatibleSchemas];
153
- if (!compatibleSchemasList) {
154
- result.errors = check.errors
155
- .map(
156
- (error) =>
157
- `${error.instancePath} ${error.message} (${JSON.stringify(
158
- error.params,
159
- )})`,
160
- )
161
- .join(", ");
162
- result.object = object;
163
- result.valid = false;
164
- return result;
165
- }
166
- const matchedSchemaKey = compatibleSchemasList.find((key) => {
167
- validationObject = JSON.parse(JSON.stringify(object));
168
- const check = ajv.getSchema(key);
169
- if (check && check(validationObject)) return key;
170
- });
171
- if (!matchedSchemaKey) {
172
- result.errors = check.errors
173
- .map(
174
- (error) =>
175
- `${error.instancePath} ${error.message} (${JSON.stringify(
176
- error.params,
177
- )})`,
178
- )
179
- .join(", ");
180
- result.object = object;
181
- result.valid = false;
182
- return result;
183
- } else {
184
- const transformedObject = transformToSchemaKey({
185
- currentSchema: matchedSchemaKey,
186
- targetSchema: schemaKey,
187
- object: validationObject,
188
- });
189
-
190
- result.valid = check(transformedObject);
191
- if (result.valid) {
192
- validationObject = transformedObject;
193
- object = transformedObject;
194
- /* c8 ignore start - Defensive: transformToSchemaKey validates internally, so this is unreachable */
195
- } else if (check.errors) {
196
- const errors = check.errors.map(
197
- (error) =>
198
- `${error.instancePath} ${error.message} (${JSON.stringify(
199
- error.params,
200
- )})`,
201
- );
202
- result.errors = errors.join(", ");
203
- return result;
204
- }
205
- /* c8 ignore stop */
206
- }
207
- }
208
- if (addDefaults) {
209
- result.object = validationObject;
210
- } else {
211
- result.object = object;
212
- }
213
-
214
- return result;
215
- }
216
-
217
- /**
218
- * Transform an object from one schema key to another and return a validated instance of the target schema.
219
- *
220
- * @param params - Function parameters.
221
- * @param params.currentSchema - Schema key representing the object's current version.
222
- * @param params.targetSchema - Schema key to transform the object into.
223
- * @param params.object - The source object to transform.
224
- * @returns The transformed object conforming to the target schema.
225
- * @throws {Error} If transformation between the specified schemas is not supported or if the transformed object fails validation.
226
- */
227
- export function transformToSchemaKey({
228
- currentSchema = "",
229
- targetSchema = "",
230
- object = {},
231
- }: TransformOptions): any {
232
- // Check if the current schema is the same as the target schema
233
- if (currentSchema === targetSchema) {
234
- return object;
235
- }
236
- // Check if the current schema is compatible with the target schema
237
- const compatibleList = compatibleSchemas[targetSchema as CompatibleSchemaKey];
238
- if (
239
- !compatibleList ||
240
- !(compatibleList as readonly string[]).includes(currentSchema)
241
- ) {
242
- throw new Error(
243
- `Can't transform from ${currentSchema} to ${targetSchema}.`,
244
- );
245
- }
246
- // Transform the object
247
- if (targetSchema === "step_v3") {
248
- const transformedObject: any = {
249
- stepId: object.id,
250
- description: object.description,
251
- };
252
- if (currentSchema === "goTo_v2") {
253
- transformedObject.goTo = {
254
- url: object.url,
255
- origin: object.origin,
256
- };
257
- } else if (currentSchema === "checkLink_v2") {
258
- transformedObject.checkLink = {
259
- url: object.url,
260
- origin: object.origin,
261
- statusCodes: object.statusCodes,
262
- };
263
- } else if (currentSchema === "find_v2") {
264
- transformedObject.find = {
265
- selector: object.selector,
266
- elementText: object.matchText,
267
- timeout: object.timeout,
268
- moveTo: object.moveTo,
269
- click: object.click,
270
- type: object.typeKeys,
271
- };
272
- // Handle typeKeys.delay key change
273
- if (typeof object.typeKeys === "object" && object.typeKeys.keys) {
274
- transformedObject.find.type.inputDelay = object.typeKeys.delay;
275
- delete transformedObject.find.type.delay;
276
- }
277
- transformedObject.variables = {};
278
- object.setVariables?.forEach((variable: any) => {
279
- transformedObject.variables[variable.name] =
280
- `extract($$element.text, "${variable.regex}")`;
281
- });
282
- } else if (currentSchema === "httpRequest_v2") {
283
- transformedObject.httpRequest = {
284
- method: object.method,
285
- url: object.url,
286
- openApi: object.openApi,
287
- request: {
288
- body: object.requestData,
289
- headers: object.requestHeaders,
290
- parameters: object.requestParams,
291
- },
292
- response: {
293
- body: object.responseData,
294
- headers: object.responseHeaders,
295
- },
296
- statusCodes: object.statusCodes,
297
- allowAdditionalFields: object.allowAdditionalFields,
298
- timeout: object.timeout,
299
- path: object.savePath,
300
- directory: object.saveDirectory,
301
- maxVariation: object.maxVariation / 100,
302
- overwrite:
303
- object.overwrite === "byVariation"
304
- ? "aboveVariation"
305
- : object.overwrite,
306
- };
307
- // Handle openApi.requestHeaders key change
308
- if (object.openApi) {
309
- transformedObject.httpRequest.openApi = transformToSchemaKey({
310
- currentSchema: "openApi_v2",
311
- targetSchema: "openApi_v3",
312
- object: object.openApi,
313
- });
314
- }
315
- transformedObject.variables = {};
316
- object.envsFromResponseData?.forEach((variable: any) => {
317
- transformedObject.variables[variable.name] =
318
- `jq($$response.body, "${variable.jqFilter}")`;
319
- });
320
- } else if (currentSchema === "runShell_v2") {
321
- transformedObject.runShell = {
322
- command: object.command,
323
- args: object.args,
324
- workingDirectory: object.workingDirectory,
325
- exitCodes: object.exitCodes,
326
- stdio: object.output,
327
- path: object.savePath,
328
- directory: object.saveDirectory,
329
- maxVariation: object.maxVariation / 100,
330
- overwrite:
331
- object.overwrite === "byVariation"
332
- ? "aboveVariation"
333
- : object.overwrite,
334
- timeout: object.timeout,
335
- };
336
- transformedObject.variables = {};
337
- object.setVariables?.forEach((variable: any) => {
338
- transformedObject.variables[variable.name] =
339
- `extract($$stdio.stdout, "${variable.regex}")`;
340
- });
341
- } else if (currentSchema === "runCode_v2") {
342
- transformedObject.runCode = {
343
- language: object.language,
344
- code: object.code,
345
- args: object.args,
346
- workingDirectory: object.workingDirectory,
347
- exitCodes: object.exitCodes,
348
- stdio: object.output,
349
- path: object.savePath,
350
- directory: object.saveDirectory,
351
- maxVariation: object.maxVariation / 100,
352
- overwrite:
353
- object.overwrite === "byVariation"
354
- ? "aboveVariation"
355
- : object.overwrite,
356
- timeout: object.timeout,
357
- };
358
- transformedObject.variables = {};
359
- object?.setVariables?.forEach((variable: any) => {
360
- transformedObject.variables[variable.name] =
361
- `extract($$stdio.stdout, "${variable.regex}")`;
362
- });
363
- } else if (currentSchema === "setVariables_v2") {
364
- transformedObject.loadVariables = object.path;
365
- } else if (currentSchema === "typeKeys_v2") {
366
- transformedObject.type = {
367
- keys: object.keys,
368
- inputDelay: object.delay,
369
- };
370
- } else if (currentSchema === "saveScreenshot_v2") {
371
- transformedObject.screenshot = {
372
- path: object.path,
373
- directory: object.directory,
374
- maxVariation: object.maxVariation / 100,
375
- overwrite:
376
- object.overwrite === "byVariation"
377
- ? "aboveVariation"
378
- : object.overwrite,
379
- crop: object.crop,
380
- };
381
- } else if (currentSchema === "startRecording_v2") {
382
- transformedObject.record = {
383
- path: object.path,
384
- directory: object.directory,
385
- overwrite: object.overwrite,
386
- };
387
- } else if (currentSchema === "stopRecording_v2") {
388
- transformedObject.stopRecord = true;
389
- } else if (currentSchema === "wait_v2") {
390
- transformedObject.wait = object;
391
- }
392
- const result = validate({
393
- schemaKey: "step_v3",
394
- object: transformedObject,
395
- });
396
- if (!result.valid) {
397
- throw new Error(`Invalid object: ${result.errors}`);
398
- }
399
- return result.object;
400
- } else if (targetSchema === "config_v3") {
401
- // Handle config_v2 to config_v3 transformation
402
- const transformedObject: any = {
403
- loadVariables: object.envVariables,
404
- input: object?.runTests?.input || object.input,
405
- output: object?.runTests?.output || object.output,
406
- recursive: object?.runTests?.recursive || object.recursive,
407
- relativePathBase: object.relativePathBase,
408
- detectSteps: object?.runTests?.detectSteps,
409
- beforeAny: object?.runTests?.setup,
410
- afterAll: object?.runTests?.cleanup,
411
- logLevel: object.logLevel,
412
- telemetry: object.telemetry,
413
- };
414
- // Handle context transformation
415
- if (object?.runTests?.contexts)
416
- transformedObject.runOn = object.runTests.contexts.map((context: any) =>
417
- transformToSchemaKey({
418
- currentSchema: "context_v2",
419
- targetSchema: "context_v3",
420
- object: context,
421
- }),
422
- );
423
- // Handle openApi transformation
424
- if (object?.integrations?.openApi) {
425
- transformedObject.integrations = {};
426
- transformedObject.integrations.openApi = object.integrations.openApi.map(
427
- (description: any) =>
428
- transformToSchemaKey({
429
- currentSchema: "openApi_v2",
430
- targetSchema: "openApi_v3",
431
- object: description,
432
- }),
433
- );
434
- }
435
- // Handle fileTypes transformation
436
- if (object?.fileTypes)
437
- transformedObject.fileTypes = object.fileTypes.map((fileType: any) => {
438
- const transformedFileType: any = {
439
- name: fileType.name,
440
- extensions: fileType.extensions.map((extension: string) =>
441
- // Trim leading `.` from extension
442
- extension.replace(/^\./, ""),
443
- ),
444
- inlineStatements: {
445
- // Convert strings to regex, escaping special characters
446
- testStart: `${escapeRegExp(
447
- fileType.testStartStatementOpen,
448
- )}(.*?)${escapeRegExp(fileType.testStartStatementClose)}`,
449
- testEnd: escapeRegExp(fileType.testEndStatement),
450
- ignoreStart: escapeRegExp(fileType.testIgnoreStatement),
451
- step: `${escapeRegExp(
452
- fileType.stepStatementOpen,
453
- )}(.*?)${escapeRegExp(fileType.stepStatementClose)}`,
454
- },
455
- };
456
- if (fileType.markup)
457
- transformedFileType.markup = fileType.markup.map((markup: any) => {
458
- const transformedMarkup: any = {
459
- name: markup.name,
460
- regex: markup.regex,
461
- };
462
- if (markup.actions)
463
- transformedMarkup.actions = markup.actions.map((action: any) => {
464
- if (typeof action === "string") return action;
465
- if (typeof action === "object") {
466
- if (action.params) {
467
- action = {
468
- action: action.name,
469
- ...action.params,
470
- };
471
- }
472
- const transformedAction = transformToSchemaKey({
473
- currentSchema: `${action.action}_v2`,
474
- targetSchema: "step_v3",
475
- object: action,
476
- });
477
- return transformedAction;
478
- }
479
- });
480
-
481
- return transformedMarkup;
482
- });
483
- return transformedFileType;
484
- });
485
- const result = validate({
486
- schemaKey: "config_v3",
487
- object: transformedObject,
488
- });
489
- // Defensive: transformation always produces valid config_v3, unreachable
490
- /* c8 ignore next 3 */
491
- if (!result.valid) {
492
- throw new Error(`Invalid object: ${result.errors}`);
493
- }
494
- return result.object;
495
- } else if (targetSchema === "context_v3") {
496
- const transformedObject: any = {};
497
- // Handle context_v2 to context_v3 transformation
498
- transformedObject.platforms = object.platforms;
499
- if (object.app?.name) {
500
- const name = object.app.name === "edge" ? "chrome" : object.app?.name;
501
- transformedObject.browsers = [];
502
- transformedObject.browsers.push({
503
- name,
504
- headless: object.app?.options?.headless,
505
- window: {
506
- width: object.app?.options?.width,
507
- height: object.app?.options?.height,
508
- },
509
- viewport: {
510
- width: object.app?.options?.viewport_width,
511
- height: object.app?.options?.viewport_height,
512
- },
513
- });
514
- }
515
- const result = validate({
516
- schemaKey: "context_v3",
517
- object: transformedObject,
518
- });
519
- if (!result.valid) {
520
- throw new Error(`Invalid object: ${result.errors}`);
521
- }
522
- return result.object;
523
- } else if (targetSchema === "openApi_v3") {
524
- let transformedObject: any;
525
- // Handle openApi_v2 to openApi_v3 transformation
526
- const { name, requestHeaders, ...intermediaryObject } = object;
527
- intermediaryObject.name = object.name;
528
- intermediaryObject.headers = object.requestHeaders;
529
- transformedObject = { ...intermediaryObject };
530
-
531
- const result = validate({
532
- schemaKey: "openApi_v3",
533
- object: transformedObject,
534
- });
535
- if (!result.valid) {
536
- throw new Error(`Invalid object: ${result.errors}`);
537
- }
538
- return result.object;
539
- } else if (targetSchema === "spec_v3") {
540
- // Handle spec_v2 to spec_v3 transformation
541
- const transformedObject: any = {
542
- specId: object.id,
543
- description: object.description,
544
- contentPath: object.file,
545
- };
546
- if (object.contexts)
547
- transformedObject.runOn = object.contexts.map((context: any) =>
548
- transformToSchemaKey({
549
- currentSchema: "context_v2",
550
- targetSchema: "context_v3",
551
- object: context,
552
- }),
553
- );
554
- if (object.openApi)
555
- transformedObject.openApi = object.openApi.map((description: any) =>
556
- transformToSchemaKey({
557
- currentSchema: "openApi_v2",
558
- targetSchema: "openApi_v3",
559
- object: description,
560
- }),
561
- );
562
- transformedObject.tests = object.tests.map((test: any) =>
563
- transformToSchemaKey({
564
- currentSchema: "test_v2",
565
- targetSchema: "test_v3",
566
- object: test,
567
- }),
568
- );
569
-
570
- const result = validate({
571
- schemaKey: "spec_v3",
572
- object: transformedObject,
573
- });
574
- // Defensive: nested transforms validate; this is unreachable
575
- /* c8 ignore next 3 */
576
- if (!result.valid) {
577
- throw new Error(`Invalid object: ${result.errors}`);
578
- }
579
- return result.object;
580
- } else if (targetSchema === "test_v3") {
581
- // Handle test_v2 to test_v3 transformation
582
- const transformedObject: any = {
583
- testId: object.id,
584
- description: object.description,
585
- contentPath: object.file,
586
- detectSteps: object.detectSteps,
587
- before: object.setup,
588
- after: object.cleanup,
589
- };
590
- if (object.contexts)
591
- transformedObject.runOn = object.contexts.map((context: any) =>
592
- transformToSchemaKey({
593
- currentSchema: "context_v2",
594
- targetSchema: "context_v3",
595
- object: context,
596
- }),
597
- );
598
- if (object.openApi)
599
- transformedObject.openApi = object.openApi.map((description: any) =>
600
- transformToSchemaKey({
601
- currentSchema: "openApi_v2",
602
- targetSchema: "openApi_v3",
603
- object: description,
604
- }),
605
- );
606
- transformedObject.steps = object.steps.map((step: any) =>
607
- transformToSchemaKey({
608
- currentSchema: `${step.action}_v2`,
609
- targetSchema: "step_v3",
610
- object: step,
611
- }),
612
- );
613
-
614
- const result = validate({
615
- schemaKey: "test_v3",
616
- object: transformedObject,
617
- });
618
- // Defensive: nested transforms validate; this is unreachable
619
- /* c8 ignore next 3 */
620
- if (!result.valid) {
621
- throw new Error(`Invalid object: ${result.errors}`);
622
- }
623
- return result.object;
624
- }
625
- /* c8 ignore next 2 - Dead code: incompatible schemas throw at line 226-228 */
626
- return null;
627
- }