jexp 0.2.1 → 0.2.2
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/README.md +3 -2
- package/manager/expressions.d.ts +5 -0
- package/manager/expressions.js +22 -0
- package/manager/expressions.js.map +1 -0
- package/manager/jexp.d.ts +2 -1
- package/manager/jexp.js +3 -2
- package/manager/jexp.js.map +1 -1
- package/manager/schema.d.ts +4 -7
- package/manager/schema.js +26 -26
- package/manager/schema.js.map +1 -1
- package/model/schema.d.ts +1 -4
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -31,13 +31,13 @@ npm install jexp -g
|
|
|
31
31
|
| eval | returns the result of the expression on the source |
|
|
32
32
|
| validate | validate the source from a schema |
|
|
33
33
|
|
|
34
|
-
Eval
|
|
34
|
+
**Eval:**
|
|
35
35
|
|
|
36
36
|
```sh
|
|
37
37
|
jexp eval <expression> <source> [options]
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
-
Validate
|
|
40
|
+
**Validate:**
|
|
41
41
|
|
|
42
42
|
```sh
|
|
43
43
|
jexp validate <schema> <source> [options]
|
|
@@ -737,6 +737,7 @@ curl -s https://raw.githubusercontent.com/FlavioLionelRita/jexp/main/data/orders
|
|
|
737
737
|
- [Conversion](https://github.com/FlavioLionelRita/js-expressions/wiki/Conversion)
|
|
738
738
|
- [Assignment](https://github.com/FlavioLionelRita/js-expressions/wiki/Assignment)
|
|
739
739
|
- [Array](https://github.com/FlavioLionelRita/js-expressions/wiki/Array)
|
|
740
|
+
- [Access](https://github.com/FlavioLionelRita/js-expressions/wiki/Access)
|
|
740
741
|
- [Arrow](https://github.com/FlavioLionelRita/js-expressions/wiki/Arrow)
|
|
741
742
|
- [Group](https://github.com/FlavioLionelRita/js-expressions/wiki/Group)
|
|
742
743
|
- [Sets](https://github.com/FlavioLionelRita/js-expressions/wiki/Sets)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JexpExtensionLib = void 0;
|
|
4
|
+
const js_expressions_1 = require("js-expressions");
|
|
5
|
+
const CryptoJS = require('crypto-js');
|
|
6
|
+
class JexpExtensionLib extends js_expressions_1.Library {
|
|
7
|
+
constructor() {
|
|
8
|
+
super('jexp');
|
|
9
|
+
this.initFunctions();
|
|
10
|
+
}
|
|
11
|
+
initFunctions() {
|
|
12
|
+
this.addFunction('toBase64', (value) => CryptoJS.enc.Base64.parse(value));
|
|
13
|
+
this.addFunction('getBase64', (value) => CryptoJS.enc.Base64.stringify(value));
|
|
14
|
+
this.addFunction('encrypt', (value, key) => CryptoJS.AES.encrypt(value, key).toString());
|
|
15
|
+
this.addFunction('decrypt', (value, key) => {
|
|
16
|
+
const bytes = CryptoJS.AES.decrypt(value, key);
|
|
17
|
+
return bytes.toString(CryptoJS.enc.Utf8);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.JexpExtensionLib = JexpExtensionLib;
|
|
22
|
+
//# sourceMappingURL=expressions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expressions.js","sourceRoot":"","sources":["../../../src/lib/manager/expressions.ts"],"names":[],"mappings":";;;AAAA,mDAAwC;AACxC,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC,CAAA;AAErC,MAAa,gBAAiB,SAAQ,wBAAO;IAC5C;QACC,KAAK,CAAC,MAAM,CAAC,CAAA;QACb,IAAI,CAAC,aAAa,EAAE,CAAA;IACrB,CAAC;IAEO,aAAa;QACpB,IAAI,CAAC,WAAW,CAAC,UAAU,EAAE,CAAC,KAAa,EAAS,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAA;QACxF,IAAI,CAAC,WAAW,CAAC,WAAW,EAAE,CAAC,KAAa,EAAU,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAA;QAC9F,IAAI,CAAC,WAAW,CAAC,SAAS,EAAE,CAAC,KAAa,EAAE,GAAU,EAAS,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAA;QAC9G,IAAI,CAAC,WAAW,CAAC,SAAS,EAAE,CAAC,KAAa,EAAE,GAAU,EAAS,EAAE;YAChE,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;YAC9C,OAAO,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;QACzC,CAAC,CAAC,CAAA;IACH,CAAC;CACD;AAfD,4CAeC"}
|
package/manager/jexp.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ValidationResult } from 'jemv';
|
|
1
2
|
export declare class Jexp {
|
|
2
3
|
private exp;
|
|
3
4
|
private jemv;
|
|
@@ -5,5 +6,5 @@ export declare class Jexp {
|
|
|
5
6
|
private static _instance;
|
|
6
7
|
static get instance(): Jexp;
|
|
7
8
|
eval(expression: string, data: any): Promise<any>;
|
|
8
|
-
validate(schema: string, data: any): Promise<
|
|
9
|
+
validate(schema: string, data: any): Promise<ValidationResult>;
|
|
9
10
|
}
|
package/manager/jexp.js
CHANGED
|
@@ -13,12 +13,13 @@ exports.Jexp = void 0;
|
|
|
13
13
|
const js_expressions_1 = require("js-expressions");
|
|
14
14
|
const jemv_1 = require("jemv");
|
|
15
15
|
const schema_1 = require("./schema");
|
|
16
|
+
const expressions_1 = require("./expressions");
|
|
16
17
|
class Jexp {
|
|
17
18
|
constructor() {
|
|
18
19
|
this.exp = js_expressions_1.expressions;
|
|
20
|
+
this.exp.config.addLibrary(new expressions_1.JexpExtensionLib());
|
|
19
21
|
this.jemv = jemv_1.jemv;
|
|
20
|
-
this.jemv.addConstraintBuilder(new schema_1.ExpressionConstraintBuilder());
|
|
21
|
-
this.jemv.addConstraintValidator(new schema_1.ExpressionConstraintValidator(this.exp));
|
|
22
|
+
this.jemv.addConstraintBuilder(new schema_1.ExpressionConstraintBuilder(this.exp));
|
|
22
23
|
}
|
|
23
24
|
static get instance() {
|
|
24
25
|
if (!this._instance) {
|
package/manager/jexp.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jexp.js","sourceRoot":"","sources":["../../../src/lib/manager/jexp.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mDAAgE;AAChE,+
|
|
1
|
+
{"version":3,"file":"jexp.js","sourceRoot":"","sources":["../../../src/lib/manager/jexp.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mDAAgE;AAChE,+BAAmD;AACnD,qCAAsD;AACtD,+CAAgD;AAEhD,MAAa,IAAI;IAGhB;QACC,IAAI,CAAC,GAAG,GAAG,4BAAG,CAAA;QACd,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,8BAAgB,EAAE,CAAC,CAAA;QAClD,IAAI,CAAC,IAAI,GAAG,WAAI,CAAA;QAChB,IAAI,CAAC,IAAI,CAAC,oBAAoB,CAAC,IAAI,oCAA2B,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAA;IAC1E,CAAC;IAGM,MAAM,KAAK,QAAQ;QACzB,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;YACpB,IAAI,CAAC,SAAS,GAAG,IAAI,IAAI,EAAE,CAAA;SAC3B;QACD,OAAO,IAAI,CAAC,SAAS,CAAA;IACtB,CAAC;IAEY,IAAI,CAAE,UAAiB,EAAE,IAAQ;;YAC7C,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAA;QAChD,CAAC;KAAA;IAEY,QAAQ,CAAE,MAAa,EAAE,IAAQ;;YAC7C,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;QACxC,CAAC;KAAA;CACD;AAzBD,oBAyBC"}
|
package/manager/schema.d.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Schema, IConstraint, IConstraintBuilder } from 'jemv';
|
|
2
2
|
import { Expressions } from 'js-expressions';
|
|
3
|
-
export declare class ExpressionConstraintBuilder implements
|
|
4
|
-
build(property: Schema): Constraint[];
|
|
5
|
-
}
|
|
6
|
-
export declare class ExpressionConstraintValidator implements ConstraintValidator {
|
|
3
|
+
export declare class ExpressionConstraintBuilder implements IConstraintBuilder {
|
|
7
4
|
private expressions;
|
|
8
5
|
constructor(expressions: Expressions);
|
|
9
|
-
apply(
|
|
10
|
-
|
|
6
|
+
apply(rule: Schema): boolean;
|
|
7
|
+
build(schema: Schema, rule: Schema): Promise<IConstraint>;
|
|
11
8
|
}
|
package/manager/schema.js
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
12
|
+
exports.ExpressionConstraintBuilder = void 0;
|
|
13
|
+
const jemv_1 = require("jemv");
|
|
4
14
|
class ExpressionConstraintBuilder {
|
|
5
|
-
build(property) {
|
|
6
|
-
const constraints = [];
|
|
7
|
-
const _property = property;
|
|
8
|
-
if (_property && _property.expression) {
|
|
9
|
-
constraints.push({
|
|
10
|
-
message: `Does not meet the expression ${_property.expression}`,
|
|
11
|
-
expression: _property.expression
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
return constraints;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
exports.ExpressionConstraintBuilder = ExpressionConstraintBuilder;
|
|
18
|
-
class ExpressionConstraintValidator {
|
|
19
15
|
constructor(expressions) {
|
|
20
16
|
this.expressions = expressions;
|
|
21
17
|
}
|
|
22
|
-
apply(
|
|
23
|
-
return
|
|
18
|
+
apply(rule) {
|
|
19
|
+
return rule.expression !== undefined;
|
|
24
20
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
21
|
+
build(schema, rule) {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
const _rule = rule;
|
|
24
|
+
if (_rule.expression === undefined) {
|
|
25
|
+
throw new Error('Expression not define');
|
|
26
|
+
}
|
|
27
|
+
const expression = _rule.expression;
|
|
28
|
+
return new jemv_1.FunctionConstraint((value, path) => __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
const result = this.expressions.eval(expression, value);
|
|
30
|
+
return result ? [] : [{ path: path, message: `does not meet the expression ${expression}` }];
|
|
31
|
+
}));
|
|
32
|
+
});
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
exports.
|
|
35
|
+
exports.ExpressionConstraintBuilder = ExpressionConstraintBuilder;
|
|
36
36
|
//# sourceMappingURL=schema.js.map
|
package/manager/schema.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/lib/manager/schema.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/lib/manager/schema.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+BAA6F;AAG7F,MAAa,2BAA2B;IAEvC,YAAa,WAAwB;QACpC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;IAC/B,CAAC;IAEM,KAAK,CAAE,IAAY;QACzB,OAAQ,IAAyB,CAAC,UAAU,KAAK,SAAS,CAAA;IAC3D,CAAC;IAEY,KAAK,CAAE,MAAa,EAAE,IAAY;;YAC9C,MAAM,KAAK,GAAG,IAAwB,CAAA;YACtC,IAAI,KAAK,CAAC,UAAU,KAAK,SAAS,EAAE;gBACnC,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAA;aACxC;YACD,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,CAAA;YACnC,OAAO,IAAI,yBAAkB,CAC5B,CAAO,KAAS,EAAE,IAAW,EAAyB,EAAE;gBACvD,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,EAAE,KAAK,CAAC,CAAA;gBACvD,OAAO,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,gCAAgC,UAAU,EAAE,EAAE,CAAC,CAAA;YAC7F,CAAC,CAAA,CACD,CAAA;QACF,CAAC;KAAA;CACD;AAvBD,kEAuBC"}
|
package/model/schema.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jexp",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Parser and evaluator of expressions by line of commands. The expressions correspond to the package js-expressions",
|
|
5
5
|
"author": "Flavio Lionel Rita <flaviolrita@hotmail.com>",
|
|
6
6
|
"license": "Apache-2.0 License",
|
|
@@ -18,9 +18,10 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"commander": "^9.4.0",
|
|
21
|
-
"jemv": "0.
|
|
22
|
-
"js-expressions": "1.1.
|
|
23
|
-
"js-yaml": "^4.1.0"
|
|
21
|
+
"jemv": "0.1.2",
|
|
22
|
+
"js-expressions": "1.1.11",
|
|
23
|
+
"js-yaml": "^4.1.0",
|
|
24
|
+
"crypto-js": "^4.1.1"
|
|
24
25
|
},
|
|
25
26
|
"keywords": [
|
|
26
27
|
"cli",
|