@nsshunt/stsutils 1.5.16 → 1.6.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/index.js +2 -1
- package/package.json +6 -5
- package/stsoptionsbase.js +13 -1
- package/validate.js +27 -0
package/index.js
CHANGED
|
@@ -2,5 +2,6 @@ let sleep = require('./sleep.js');
|
|
|
2
2
|
let status = require('./status.js');
|
|
3
3
|
const AuthUtilsBrowser = require('./authutilsbrowser.js');
|
|
4
4
|
const STSOptionsBase = require('./stsoptionsbase.js');
|
|
5
|
+
const { AddSchema, Validate } = require('./validate.js');
|
|
5
6
|
|
|
6
|
-
module.exports = { sleep, status, STSOptionsBase, AuthUtilsBrowser };
|
|
7
|
+
module.exports = { sleep, status, STSOptionsBase, AuthUtilsBrowser, AddSchema, Validate };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nsshunt/stsutils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -22,14 +22,15 @@
|
|
|
22
22
|
"parser": "@babel/eslint-parser"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@babel/core": "^7.
|
|
26
|
-
"@babel/eslint-parser": "^7.
|
|
25
|
+
"@babel/core": "^7.17.0",
|
|
26
|
+
"@babel/eslint-parser": "^7.17.0",
|
|
27
27
|
"@babel/plugin-proposal-class-properties": "^7.16.7",
|
|
28
|
-
"@babel/plugin-proposal-private-methods": "^7.16.
|
|
29
|
-
"eslint": "^8.
|
|
28
|
+
"@babel/plugin-proposal-private-methods": "^7.16.11",
|
|
29
|
+
"eslint": "^8.8.0",
|
|
30
30
|
"jest": "^27.4.7"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
+
"ajv": "^8.9.0",
|
|
33
34
|
"axios": "^0.25.0",
|
|
34
35
|
"colors": "^1.4.0",
|
|
35
36
|
"debug": "^4.3.3"
|
package/stsoptionsbase.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const { Validate } = require('./validate.js');
|
|
2
|
+
|
|
1
3
|
class STSOptionsBase
|
|
2
4
|
{
|
|
3
5
|
#options = null;
|
|
@@ -5,6 +7,15 @@ class STSOptionsBase
|
|
|
5
7
|
constructor(options = null)
|
|
6
8
|
{
|
|
7
9
|
this.#options = options;
|
|
10
|
+
|
|
11
|
+
if (options !== null) {
|
|
12
|
+
if (typeof options.validator === 'undefined') {
|
|
13
|
+
console.log(JSON.stringify(options));
|
|
14
|
+
console.trace("Options Here ------------------------------------------------------------------------------------------")
|
|
15
|
+
} else {
|
|
16
|
+
Validate(options.validator, options);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
8
19
|
}
|
|
9
20
|
|
|
10
21
|
/**
|
|
@@ -12,7 +23,8 @@ class STSOptionsBase
|
|
|
12
23
|
*/
|
|
13
24
|
get Options()
|
|
14
25
|
{
|
|
15
|
-
|
|
26
|
+
console.trace("Use of Options Here <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<----------------------------------------")
|
|
27
|
+
return this.#options;
|
|
16
28
|
}
|
|
17
29
|
|
|
18
30
|
get options()
|
package/validate.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const Ajv = require('ajv/dist/jtd');
|
|
2
|
+
|
|
3
|
+
const ajv = new Ajv();
|
|
4
|
+
|
|
5
|
+
const _Validate = (validator, payload) => {
|
|
6
|
+
const valid = validator(payload);
|
|
7
|
+
if (!valid) {
|
|
8
|
+
console.error(validator.errors);
|
|
9
|
+
console.trace('Invalid Schema');
|
|
10
|
+
process.exit(1);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const AddSchema = (name, schema) => {
|
|
15
|
+
ajv.addSchema(schema, name);
|
|
16
|
+
return (payload) => {
|
|
17
|
+
const validator = ajv.getSchema(name)
|
|
18
|
+
_Validate(validator, payload)
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const Validate = (name, payload) => {
|
|
23
|
+
const validator = ajv.getSchema(name)
|
|
24
|
+
_Validate(validator, payload);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
module.exports = { AddSchema, Validate };
|