doc-detective-common 1.2.11 → 1.3.0
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/.devcontainer/devcontainer.json +37 -37
- package/.github/workflows/npm-publish.yml +58 -34
- package/.github/workflows/npm-test.yml +44 -0
- package/LICENSE +21 -21
- package/README.md +81 -81
- package/dev/dev.js +2 -2
- package/package.json +34 -33
- package/src/index.js +4 -4
- package/src/schemas/dereferenceSchemas.js +100 -48
- package/src/schemas/index.js +32 -22
- package/src/schemas/output_schemas/checkLink_v2.schema.json +1 -2
- package/src/schemas/output_schemas/goTo_v2.schema.json +1 -1
- package/src/schemas/output_schemas/httpRequest_v2.schema.json +1 -2
- package/src/schemas/output_schemas/saveScreenshot_v2.schema.json +1 -1
- package/src/schemas/output_schemas/spec_v2.schema.json +4 -6
- package/src/schemas/output_schemas/startRecording_v2.schema.json +46 -46
- package/src/schemas/output_schemas/test_v2.schema.json +4 -6
- package/src/schemas/src_schemas/analytics_v1.schema.json +584 -584
- package/src/schemas/src_schemas/checkLink_v1.schema.json +41 -41
- package/src/schemas/src_schemas/checkLink_v2.schema.json +54 -55
- package/src/schemas/src_schemas/click_v1.schema.json +59 -59
- package/src/schemas/src_schemas/config_v2.schema.json +775 -775
- package/src/schemas/src_schemas/context_v2.schema.json +55 -55
- package/src/schemas/src_schemas/find_v1.schema.json +136 -136
- package/src/schemas/src_schemas/find_v2.schema.json +78 -78
- package/src/schemas/src_schemas/goTo_v1.schema.json +29 -29
- package/src/schemas/src_schemas/goTo_v2.schema.json +45 -45
- package/src/schemas/src_schemas/httpRequest_v1.schema.json +114 -114
- package/src/schemas/src_schemas/httpRequest_v2.schema.json +166 -167
- package/src/schemas/src_schemas/matchText_v1.schema.json +31 -31
- package/src/schemas/src_schemas/moveMouse_v1.schema.json +59 -59
- package/src/schemas/src_schemas/runShell_v1.schema.json +34 -34
- package/src/schemas/src_schemas/runShell_v2.schema.json +55 -55
- package/src/schemas/src_schemas/saveScreenshot_v2.schema.json +40 -40
- package/src/schemas/src_schemas/screenshot_v1.schema.json +47 -47
- package/src/schemas/src_schemas/scroll_v1.schema.json +49 -49
- package/src/schemas/src_schemas/setVariables_v2.schema.json +37 -37
- package/src/schemas/src_schemas/spec_v2.schema.json +130 -130
- package/src/schemas/src_schemas/startRecording_v1.schema.json +54 -54
- package/src/schemas/src_schemas/startRecording_v2.schema.json +46 -46
- package/src/schemas/src_schemas/stopRecording_v1.schema.json +19 -19
- package/src/schemas/src_schemas/test_v2.schema.json +143 -143
- package/src/schemas/src_schemas/typeKeys_v2.schema.json +50 -50
- package/src/schemas/src_schemas/type_v1.schema.json +61 -61
- package/src/schemas/src_schemas/wait_v1.schema.json +41 -41
- package/src/schemas/src_schemas/wait_v2.schema.json +40 -40
- package/src/validate.js +43 -43
- package/test/schema.test.js +21 -21
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
|
|
2
|
-
// README at: https://github.com/devcontainers/templates/tree/main/src/ubuntu
|
|
3
|
-
{
|
|
4
|
-
"name": "Ubuntu",
|
|
5
|
-
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
|
|
6
|
-
"image": "mcr.microsoft.com/devcontainers/base:jammy",
|
|
7
|
-
"features": {
|
|
8
|
-
"ghcr.io/devcontainers/features/node:1": {}
|
|
9
|
-
},
|
|
10
|
-
|
|
11
|
-
// Features to add to the dev container. More info: https://containers.dev/features.
|
|
12
|
-
// "features": {},
|
|
13
|
-
|
|
14
|
-
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
|
15
|
-
// "forwardPorts": [],
|
|
16
|
-
|
|
17
|
-
// Use 'postCreateCommand' to run commands after the container is created.
|
|
18
|
-
"postCreateCommand": "npm i",
|
|
19
|
-
|
|
20
|
-
// Configure tool-specific properties.
|
|
21
|
-
"customizations": {
|
|
22
|
-
// Configure properties specific to VS Code.
|
|
23
|
-
"vscode": {
|
|
24
|
-
// Add the IDs of extensions you want installed when the container is created.
|
|
25
|
-
"extensions": [
|
|
26
|
-
"github.copilot",
|
|
27
|
-
"aaron-bond.better-comments",
|
|
28
|
-
"esbenp.prettier-vscode",
|
|
29
|
-
"GitHub.vscode-pull-request-github",
|
|
30
|
-
"streetsidesoftware.code-spell-checker"
|
|
31
|
-
]
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
|
|
36
|
-
// "remoteUser": "root"
|
|
37
|
-
}
|
|
1
|
+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
|
|
2
|
+
// README at: https://github.com/devcontainers/templates/tree/main/src/ubuntu
|
|
3
|
+
{
|
|
4
|
+
"name": "Ubuntu",
|
|
5
|
+
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
|
|
6
|
+
"image": "mcr.microsoft.com/devcontainers/base:jammy",
|
|
7
|
+
"features": {
|
|
8
|
+
"ghcr.io/devcontainers/features/node:1": {}
|
|
9
|
+
},
|
|
10
|
+
|
|
11
|
+
// Features to add to the dev container. More info: https://containers.dev/features.
|
|
12
|
+
// "features": {},
|
|
13
|
+
|
|
14
|
+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
|
15
|
+
// "forwardPorts": [],
|
|
16
|
+
|
|
17
|
+
// Use 'postCreateCommand' to run commands after the container is created.
|
|
18
|
+
"postCreateCommand": "npm i",
|
|
19
|
+
|
|
20
|
+
// Configure tool-specific properties.
|
|
21
|
+
"customizations": {
|
|
22
|
+
// Configure properties specific to VS Code.
|
|
23
|
+
"vscode": {
|
|
24
|
+
// Add the IDs of extensions you want installed when the container is created.
|
|
25
|
+
"extensions": [
|
|
26
|
+
"github.copilot",
|
|
27
|
+
"aaron-bond.better-comments",
|
|
28
|
+
"esbenp.prettier-vscode",
|
|
29
|
+
"GitHub.vscode-pull-request-github",
|
|
30
|
+
"streetsidesoftware.code-spell-checker"
|
|
31
|
+
]
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
|
|
36
|
+
// "remoteUser": "root"
|
|
37
|
+
}
|
|
@@ -1,34 +1,58 @@
|
|
|
1
|
-
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
|
|
2
|
-
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
|
|
3
|
-
|
|
4
|
-
name: Node.js Package
|
|
5
|
-
|
|
6
|
-
on:
|
|
7
|
-
release:
|
|
8
|
-
types: [created]
|
|
9
|
-
workflow_dispatch:
|
|
10
|
-
|
|
11
|
-
jobs:
|
|
12
|
-
|
|
13
|
-
runs-on:
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
-
|
|
27
|
-
|
|
28
|
-
with:
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
1
|
+
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
|
|
2
|
+
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
|
|
3
|
+
|
|
4
|
+
name: Node.js Package
|
|
5
|
+
|
|
6
|
+
on:
|
|
7
|
+
release:
|
|
8
|
+
types: [created]
|
|
9
|
+
workflow_dispatch:
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
test:
|
|
13
|
+
runs-on: ${{ matrix.os }}
|
|
14
|
+
strategy:
|
|
15
|
+
matrix:
|
|
16
|
+
os: [ubuntu-latest]
|
|
17
|
+
node: [18]
|
|
18
|
+
|
|
19
|
+
steps:
|
|
20
|
+
- uses: actions/checkout@v3
|
|
21
|
+
|
|
22
|
+
- uses: actions/setup-node@v3
|
|
23
|
+
with:
|
|
24
|
+
node-version: ${{ matrix.node }}
|
|
25
|
+
|
|
26
|
+
- name: Cache node_modules
|
|
27
|
+
uses: actions/cache@v3
|
|
28
|
+
with:
|
|
29
|
+
# Cache key uses the contents of `package-lock.json` to identify unique cache
|
|
30
|
+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
|
|
31
|
+
restore-keys: |
|
|
32
|
+
${{ runner.OS }}-node-
|
|
33
|
+
path: |
|
|
34
|
+
node_modules
|
|
35
|
+
|
|
36
|
+
- run: npm ci
|
|
37
|
+
|
|
38
|
+
- run: npm test
|
|
39
|
+
|
|
40
|
+
publish-npm:
|
|
41
|
+
needs: test
|
|
42
|
+
runs-on: ubuntu-latest
|
|
43
|
+
steps:
|
|
44
|
+
- uses: actions/checkout@v3
|
|
45
|
+
- uses: actions/setup-node@v3
|
|
46
|
+
- name: Cache node_modules
|
|
47
|
+
uses: actions/cache@v3
|
|
48
|
+
with:
|
|
49
|
+
# Cache key uses the contents of `package-lock.json` to identify unique cache
|
|
50
|
+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
|
|
51
|
+
restore-keys: |
|
|
52
|
+
${{ runner.OS }}-node-
|
|
53
|
+
path: |
|
|
54
|
+
node_modules
|
|
55
|
+
- run: npm ci
|
|
56
|
+
- run: npm publish
|
|
57
|
+
env:
|
|
58
|
+
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
name: Run tests
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
pull_request:
|
|
8
|
+
types: [opened, reopened, synchronize]
|
|
9
|
+
workflow_dispatch:
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
test:
|
|
13
|
+
runs-on: ${{ matrix.os }}
|
|
14
|
+
strategy:
|
|
15
|
+
matrix:
|
|
16
|
+
os:
|
|
17
|
+
- ubuntu-latest
|
|
18
|
+
- windows-latest
|
|
19
|
+
- macos-latest
|
|
20
|
+
node:
|
|
21
|
+
- 16
|
|
22
|
+
- 18
|
|
23
|
+
- 20
|
|
24
|
+
|
|
25
|
+
steps:
|
|
26
|
+
- uses: actions/checkout@v3
|
|
27
|
+
|
|
28
|
+
- uses: actions/setup-node@v3
|
|
29
|
+
with:
|
|
30
|
+
node-version: ${{ matrix.node }}
|
|
31
|
+
|
|
32
|
+
- name: Cache node_modules
|
|
33
|
+
uses: actions/cache@v3
|
|
34
|
+
with:
|
|
35
|
+
# Cache key uses the contents of `package-lock.json` to identify unique cache
|
|
36
|
+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
|
|
37
|
+
restore-keys: |
|
|
38
|
+
${{ runner.OS }}-node-
|
|
39
|
+
path: |
|
|
40
|
+
node_modules
|
|
41
|
+
|
|
42
|
+
- run: npm ci
|
|
43
|
+
|
|
44
|
+
- run: npm test
|
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2023 doc-detective
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 doc-detective
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,81 +1,81 @@
|
|
|
1
|
-
# Doc Detective Common
|
|
2
|
-
|
|
3
|
-

|
|
4
|
-
[](https://www.npmjs.com/package/doc-detective-common)
|
|
5
|
-
[](https://discord.gg/mSCCRAhH)
|
|
6
|
-
|
|
7
|
-
Shared resources for Doc Detective projects.
|
|
8
|
-
|
|
9
|
-
## Install
|
|
10
|
-
|
|
11
|
-
```bash
|
|
12
|
-
npm i doc-detective-common
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
## Init
|
|
16
|
-
|
|
17
|
-
```javascript
|
|
18
|
-
const common = require("doc-detective-common");
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
## Methods
|
|
22
|
-
|
|
23
|
-
### `.validate(schemaKey: string, object: object)`
|
|
24
|
-
|
|
25
|
-
Validate that `object` matches the specified [schema](#.schemas) definition.
|
|
26
|
-
|
|
27
|
-
Returns an object with the following schema:
|
|
28
|
-
|
|
29
|
-
```json
|
|
30
|
-
{
|
|
31
|
-
"valid": boolean,
|
|
32
|
-
"errors": [
|
|
33
|
-
{
|
|
34
|
-
"instancePath": string,
|
|
35
|
-
"schemaPath": string,
|
|
36
|
-
"keyword": string,
|
|
37
|
-
"params": [{Object}],
|
|
38
|
-
"message": string
|
|
39
|
-
}
|
|
40
|
-
]
|
|
41
|
-
}
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
#### Usage
|
|
45
|
-
|
|
46
|
-
```js
|
|
47
|
-
const schemaKey = "runShell_v1";
|
|
48
|
-
const object = {
|
|
49
|
-
action: "runShell",
|
|
50
|
-
command: "echo $username",
|
|
51
|
-
};
|
|
52
|
-
console.log(common.validate(schemaKey, object));
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
## Objects
|
|
56
|
-
|
|
57
|
-
### `.schemas`
|
|
58
|
-
|
|
59
|
-
JSON schema definitions for various objects used throughout Doc Detective.
|
|
60
|
-
|
|
61
|
-
Schema objects are located in the [`/schemas`](https://github.com/doc-detective/doc-detective-common/tree/schema/schemas) directory and made available through the `.schemas` object.
|
|
62
|
-
|
|
63
|
-
```json
|
|
64
|
-
{
|
|
65
|
-
"analytics_v1": {Object},
|
|
66
|
-
"checkLink_v1": {Object},
|
|
67
|
-
"click_v1": {Object},
|
|
68
|
-
"find_v1": {Object},
|
|
69
|
-
"goTo_v1": {Object},
|
|
70
|
-
"httpRequest_v1": {Object},
|
|
71
|
-
"matchText_v1": {Object},
|
|
72
|
-
"moveMouse_v1": {Object},
|
|
73
|
-
"runShell_v1": {Object},
|
|
74
|
-
"screenshot_v1": {Object},
|
|
75
|
-
"scroll_v1": {Object},
|
|
76
|
-
"startRecording_v1": {Object},
|
|
77
|
-
"stopRecording_v1": {Object},
|
|
78
|
-
"type_v1": {Object},
|
|
79
|
-
"wait_v1": {Object}
|
|
80
|
-
}
|
|
81
|
-
```
|
|
1
|
+
# Doc Detective Common
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
[](https://www.npmjs.com/package/doc-detective-common)
|
|
5
|
+
[](https://discord.gg/mSCCRAhH)
|
|
6
|
+
|
|
7
|
+
Shared resources for Doc Detective projects.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm i doc-detective-common
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Init
|
|
16
|
+
|
|
17
|
+
```javascript
|
|
18
|
+
const common = require("doc-detective-common");
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Methods
|
|
22
|
+
|
|
23
|
+
### `.validate(schemaKey: string, object: object)`
|
|
24
|
+
|
|
25
|
+
Validate that `object` matches the specified [schema](#.schemas) definition.
|
|
26
|
+
|
|
27
|
+
Returns an object with the following schema:
|
|
28
|
+
|
|
29
|
+
```json
|
|
30
|
+
{
|
|
31
|
+
"valid": boolean,
|
|
32
|
+
"errors": [
|
|
33
|
+
{
|
|
34
|
+
"instancePath": string,
|
|
35
|
+
"schemaPath": string,
|
|
36
|
+
"keyword": string,
|
|
37
|
+
"params": [{Object}],
|
|
38
|
+
"message": string
|
|
39
|
+
}
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
#### Usage
|
|
45
|
+
|
|
46
|
+
```js
|
|
47
|
+
const schemaKey = "runShell_v1";
|
|
48
|
+
const object = {
|
|
49
|
+
action: "runShell",
|
|
50
|
+
command: "echo $username",
|
|
51
|
+
};
|
|
52
|
+
console.log(common.validate(schemaKey, object));
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Objects
|
|
56
|
+
|
|
57
|
+
### `.schemas`
|
|
58
|
+
|
|
59
|
+
JSON schema definitions for various objects used throughout Doc Detective.
|
|
60
|
+
|
|
61
|
+
Schema objects are located in the [`/schemas`](https://github.com/doc-detective/doc-detective-common/tree/schema/schemas) directory and made available through the `.schemas` object.
|
|
62
|
+
|
|
63
|
+
```json
|
|
64
|
+
{
|
|
65
|
+
"analytics_v1": {Object},
|
|
66
|
+
"checkLink_v1": {Object},
|
|
67
|
+
"click_v1": {Object},
|
|
68
|
+
"find_v1": {Object},
|
|
69
|
+
"goTo_v1": {Object},
|
|
70
|
+
"httpRequest_v1": {Object},
|
|
71
|
+
"matchText_v1": {Object},
|
|
72
|
+
"moveMouse_v1": {Object},
|
|
73
|
+
"runShell_v1": {Object},
|
|
74
|
+
"screenshot_v1": {Object},
|
|
75
|
+
"scroll_v1": {Object},
|
|
76
|
+
"startRecording_v1": {Object},
|
|
77
|
+
"stopRecording_v1": {Object},
|
|
78
|
+
"type_v1": {Object},
|
|
79
|
+
"wait_v1": {Object}
|
|
80
|
+
}
|
|
81
|
+
```
|
package/dev/dev.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
const { validate, schemas } = require("../src/index");
|
|
2
|
-
|
|
1
|
+
const { validate, schemas } = require("../src/index");
|
|
2
|
+
|
|
3
3
|
console.log(validate("find_v2",schemas.find_v2.examples[0]))
|
package/package.json
CHANGED
|
@@ -1,33 +1,34 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "doc-detective-common",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Shared components for Doc Detective projects.",
|
|
5
|
-
"main": "src/index.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"dereferenceSchemas": "node ./src/schemas/dereferenceSchemas.js",
|
|
8
|
-
"test": "npm run dereferenceSchemas && jest"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
"
|
|
27
|
-
"ajv
|
|
28
|
-
"ajv-
|
|
29
|
-
"ajv-
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "doc-detective-common",
|
|
3
|
+
"version": "1.3.0",
|
|
4
|
+
"description": "Shared components for Doc Detective projects. ",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dereferenceSchemas": "node ./src/schemas/dereferenceSchemas.js",
|
|
8
|
+
"test:full": "npm run dereferenceSchemas && jest",
|
|
9
|
+
"test": "jest"
|
|
10
|
+
},
|
|
11
|
+
"precommit": "test:full",
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/doc-detective/doc-detective-common.git"
|
|
15
|
+
},
|
|
16
|
+
"author": "Manny Silva",
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/doc-detective/doc-detective-common/issues"
|
|
20
|
+
},
|
|
21
|
+
"homepage": "https://github.com/doc-detective/doc-detective-common#readme",
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"jest": "^29.6.4"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@apidevtools/json-schema-ref-parser": "^10.1.0",
|
|
27
|
+
"ajv": "^8.12.0",
|
|
28
|
+
"ajv-errors": "^3.0.0",
|
|
29
|
+
"ajv-formats": "^2.1.1",
|
|
30
|
+
"ajv-keywords": "^5.1.0",
|
|
31
|
+
"pre-commit": "^1.2.2",
|
|
32
|
+
"uuid": "^9.0.0"
|
|
33
|
+
}
|
|
34
|
+
}
|
package/src/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const { schemas } = require("./schemas");
|
|
2
|
-
const { validate } = require("./validate");
|
|
3
|
-
|
|
4
|
-
exports.schemas = schemas;
|
|
1
|
+
const { schemas } = require("./schemas");
|
|
2
|
+
const { validate } = require("./validate");
|
|
3
|
+
|
|
4
|
+
exports.schemas = schemas;
|
|
5
5
|
exports.validate = validate;
|
|
@@ -1,48 +1,100 @@
|
|
|
1
|
-
const parser = require("@apidevtools/json-schema-ref-parser");
|
|
2
|
-
const path = require("path");
|
|
3
|
-
const fs = require("fs");
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
*
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
schema
|
|
24
|
-
|
|
25
|
-
schema
|
|
26
|
-
|
|
27
|
-
schema
|
|
28
|
-
|
|
29
|
-
schema
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
//
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
1
|
+
const parser = require("@apidevtools/json-schema-ref-parser");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
|
|
5
|
+
(async () => {
|
|
6
|
+
await dereferenceSchemas();
|
|
7
|
+
})();
|
|
8
|
+
|
|
9
|
+
/*
|
|
10
|
+
* Walks through all schema in src/src_schema
|
|
11
|
+
* For each schema, dereferences it and writes it to src/schema
|
|
12
|
+
*/
|
|
13
|
+
async function dereferenceSchemas() {
|
|
14
|
+
const inputDir = path.resolve(`${__dirname}/src_schemas`);
|
|
15
|
+
const buildDir = path.resolve(`${__dirname}/build`);
|
|
16
|
+
fs.mkdir(buildDir, { recursive: true }, (err) => {
|
|
17
|
+
if (err) throw err;
|
|
18
|
+
});
|
|
19
|
+
const outputDir = path.resolve(`${__dirname}/output_schemas`);
|
|
20
|
+
var files = [
|
|
21
|
+
"checkLink_v2.schema.json",
|
|
22
|
+
"config_v2.schema.json",
|
|
23
|
+
"context_v2.schema.json",
|
|
24
|
+
"find_v2.schema.json",
|
|
25
|
+
"goTo_v2.schema.json",
|
|
26
|
+
"httpRequest_v2.schema.json",
|
|
27
|
+
"runShell_v2.schema.json",
|
|
28
|
+
"saveScreenshot_v2.schema.json",
|
|
29
|
+
"setVariables_v2.schema.json",
|
|
30
|
+
"spec_v2.schema.json",
|
|
31
|
+
"test_v2.schema.json",
|
|
32
|
+
"typeKeys_v2.schema.json",
|
|
33
|
+
"wait_v2.schema.json",
|
|
34
|
+
];
|
|
35
|
+
// Update schema reference paths
|
|
36
|
+
for (const file of files) {
|
|
37
|
+
// console.log(`File: ${file}`)
|
|
38
|
+
const filePath = path.resolve(`${inputDir}/${file}`);
|
|
39
|
+
// Load from file
|
|
40
|
+
let schema = fs.readFileSync(filePath).toString();
|
|
41
|
+
// Convert to JSON
|
|
42
|
+
schema = JSON.parse(schema);
|
|
43
|
+
// Set ID
|
|
44
|
+
schema.$id = `${filePath}`;
|
|
45
|
+
// Update references to current relative path
|
|
46
|
+
schema = updateRefPaths(schema);
|
|
47
|
+
// Write to file
|
|
48
|
+
fs.writeFileSync(`${buildDir}/${file}`, JSON.stringify(schema, null, 2));
|
|
49
|
+
}
|
|
50
|
+
// Dereference schemas
|
|
51
|
+
for await (const file of files) {
|
|
52
|
+
const filePath = path.resolve(`${buildDir}/${file}`);
|
|
53
|
+
// Load from file
|
|
54
|
+
let schema = fs.readFileSync(filePath).toString();
|
|
55
|
+
// Convert to JSON
|
|
56
|
+
schema = JSON.parse(schema);
|
|
57
|
+
// Dereference schema
|
|
58
|
+
schema = await parser.dereference(schema);
|
|
59
|
+
// Delete $id attributes
|
|
60
|
+
schema = deleteDollarIds(schema);
|
|
61
|
+
// Write to file
|
|
62
|
+
fs.writeFileSync(`${outputDir}/${file}`, JSON.stringify(schema, null, 2));
|
|
63
|
+
}
|
|
64
|
+
// Clean up build dir
|
|
65
|
+
// fs.rm(buildDir, { recursive: true }, (err) => {
|
|
66
|
+
// if (err) throw err;
|
|
67
|
+
// });
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Prepend app-root path to referenced relative paths
|
|
71
|
+
function updateRefPaths(schema) {
|
|
72
|
+
for (let [key, value] of Object.entries(schema)) {
|
|
73
|
+
if (typeof value === "object") {
|
|
74
|
+
updateRefPaths(value);
|
|
75
|
+
}
|
|
76
|
+
if (key === "$ref" && !value.startsWith("#")) {
|
|
77
|
+
// File name of the referenced schema
|
|
78
|
+
valueFile = value.split("#")[0];
|
|
79
|
+
// Attribute path in the referenced schema
|
|
80
|
+
valueAttribute = value.split("#")[1];
|
|
81
|
+
valuePath = path.resolve(`${__dirname}/build/${valueFile}`);
|
|
82
|
+
schema[key] = `${valuePath}#${valueAttribute}`;
|
|
83
|
+
// console.log({value, valueFile, valueAttribute, final: schema[key]})
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return schema;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Prepend app-root path to referenced relative paths
|
|
90
|
+
function deleteDollarIds(schema) {
|
|
91
|
+
for (let [key, value] of Object.entries(schema)) {
|
|
92
|
+
if (typeof value === "object") {
|
|
93
|
+
deleteDollarIds(value);
|
|
94
|
+
}
|
|
95
|
+
if (key === "$id") {
|
|
96
|
+
delete schema[key]
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return schema;
|
|
100
|
+
}
|