@celljs/core 3.2.0 → 3.4.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/lib/common/el/expression-compiler.d.ts +7 -5
- package/lib/common/el/expression-compiler.d.ts.map +1 -1
- package/lib/common/el/expression-compiler.js +37 -22
- package/lib/common/el/expression-compiler.js.map +1 -1
- package/lib/common/el/expression-handler.d.ts +3 -3
- package/lib/common/el/expression-handler.d.ts.map +1 -1
- package/lib/common/el/expression-handler.js +5 -5
- package/lib/common/el/expression-handler.js.map +1 -1
- package/lib/common/el/expression-protocol.d.ts +9 -2
- package/lib/common/el/expression-protocol.d.ts.map +1 -1
- package/lib/common/utils/byte-util.d.ts +11 -0
- package/lib/common/utils/byte-util.d.ts.map +1 -0
- package/lib/common/utils/byte-util.js +62 -0
- package/lib/common/utils/byte-util.js.map +1 -0
- package/lib/common/utils/index.d.ts +1 -0
- package/lib/common/utils/index.d.ts.map +1 -1
- package/lib/common/utils/index.js +1 -0
- package/lib/common/utils/index.js.map +1 -1
- package/lib/common/utils/types.d.ts +5 -0
- package/lib/common/utils/types.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/common/el/expression-compiler.ts +40 -23
- package/src/common/el/expression-handler.ts +6 -6
- package/src/common/el/expression-protocol.ts +10 -2
- package/src/common/utils/byte-util.ts +80 -0
- package/src/common/utils/index.ts +1 -0
- package/src/common/utils/types.ts +4 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ExpressionCompiler, JexlEngineProvider } from './expression-protocol';
|
|
1
|
+
import { ExpressionCompiler, ExpressionCompilerOptions, JexlEngineProvider } from './expression-protocol';
|
|
2
2
|
interface MiddleExpression {
|
|
3
3
|
expression: any;
|
|
4
4
|
nextText?: string;
|
|
@@ -9,10 +9,12 @@ export declare class ExpressionCompilerImpl implements ExpressionCompiler {
|
|
|
9
9
|
private BRACKET_BEGIN;
|
|
10
10
|
private BRACKET_END;
|
|
11
11
|
protected readonly jexlEngineProvider: JexlEngineProvider<any>;
|
|
12
|
-
|
|
13
|
-
protected
|
|
14
|
-
|
|
15
|
-
protected
|
|
12
|
+
protected getSpecialChar(opitons: Required<ExpressionCompilerOptions>): string;
|
|
13
|
+
protected equalsSpecialChar(opitons: Required<ExpressionCompilerOptions>, char: string): boolean;
|
|
14
|
+
compileSections(text: string, options: ExpressionCompilerOptions): any[];
|
|
15
|
+
protected middleCompile(text: string, options: Required<ExpressionCompilerOptions>): MiddleExpression | undefined;
|
|
16
|
+
protected nextMiddleExpression(text: string, bracketBeginCharNum: number | undefined, options: Required<ExpressionCompilerOptions>): MiddleExpression | undefined;
|
|
17
|
+
protected nextString(text: string, options: Required<ExpressionCompilerOptions>): MiddleExpression;
|
|
16
18
|
}
|
|
17
19
|
export {};
|
|
18
20
|
//# sourceMappingURL=expression-compiler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expression-compiler.d.ts","sourceRoot":"","sources":["../../../src/common/el/expression-compiler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"expression-compiler.d.ts","sourceRoot":"","sources":["../../../src/common/el/expression-compiler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAG1G,UAAU,gBAAgB;IACtB,UAAU,EAAE,GAAG,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,qBACa,sBAAuB,YAAW,kBAAkB;IAE7D,OAAO,CAAC,WAAW,CAAQ;IAC3B,OAAO,CAAC,YAAY,CAAO;IAC3B,OAAO,CAAC,aAAa,CAAO;IAC5B,OAAO,CAAC,WAAW,CAAO;IAG1B,SAAS,CAAC,QAAQ,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,GAAG,CAAC,CAAC;IAE/D,SAAS,CAAC,cAAc,CAAC,OAAO,EAAE,QAAQ,CAAC,yBAAyB,CAAC,GAAG,MAAM;IAO9E,SAAS,CAAC,iBAAiB,CAAC,OAAO,EAAE,QAAQ,CAAC,yBAAyB,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO;IAOhG,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,yBAAyB,GAAG,GAAG,EAAE;IAwBxE,SAAS,CAAC,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAC,yBAAyB,CAAC,GAAG,gBAAgB,GAAG,SAAS;IAYjH,SAAS,CAAC,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,mBAAmB,oBAAI,EAAE,OAAO,EAAE,QAAQ,CAAC,yBAAyB,CAAC,GAAG,gBAAgB,GAAG,SAAS;IAuDjJ,SAAS,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAC,yBAAyB,CAAC,GAAG,gBAAgB;CAiDrG"}
|
|
@@ -11,14 +11,29 @@ let ExpressionCompilerImpl = class ExpressionCompilerImpl {
|
|
|
11
11
|
this.BRACKET_BEGIN = '{';
|
|
12
12
|
this.BRACKET_END = '}';
|
|
13
13
|
}
|
|
14
|
-
|
|
15
|
-
if (
|
|
14
|
+
getSpecialChar(opitons) {
|
|
15
|
+
if (opitons.ignoreSpecialChar) {
|
|
16
|
+
return '';
|
|
17
|
+
}
|
|
18
|
+
return opitons.specialChar;
|
|
19
|
+
}
|
|
20
|
+
equalsSpecialChar(opitons, char) {
|
|
21
|
+
if (opitons.ignoreSpecialChar) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
return char === opitons.specialChar;
|
|
25
|
+
}
|
|
26
|
+
compileSections(text, options) {
|
|
27
|
+
const merged = {
|
|
28
|
+
...{ escapeChar: this.ESCAPE_CHAR, specialChar: this.SPECIAL_CHAR, bracketBegin: this.BRACKET_BEGIN, bracketEnd: this.BRACKET_END, ...options }
|
|
29
|
+
};
|
|
30
|
+
if (!text || text.indexOf(`${this.getSpecialChar(merged)}${merged.bracketBegin}`) < 0) {
|
|
16
31
|
return [];
|
|
17
32
|
}
|
|
18
33
|
const sections = [];
|
|
19
34
|
let middleText = text;
|
|
20
35
|
while (middleText) {
|
|
21
|
-
const me = this.middleCompile(middleText);
|
|
36
|
+
const me = this.middleCompile(middleText, merged);
|
|
22
37
|
if (!me) {
|
|
23
38
|
sections.push(middleText);
|
|
24
39
|
middleText = undefined;
|
|
@@ -30,20 +45,20 @@ let ExpressionCompilerImpl = class ExpressionCompilerImpl {
|
|
|
30
45
|
}
|
|
31
46
|
return sections;
|
|
32
47
|
}
|
|
33
|
-
middleCompile(text) {
|
|
48
|
+
middleCompile(text, options) {
|
|
34
49
|
let me;
|
|
35
|
-
if (text.startsWith(
|
|
36
|
-
me = this.nextMiddleExpression(text.substring(3), 2);
|
|
50
|
+
if (text.startsWith(`${this.getSpecialChar(options)}${options.bracketBegin}${options.bracketBegin}`)) {
|
|
51
|
+
me = this.nextMiddleExpression(text.substring(3), 2, options);
|
|
37
52
|
}
|
|
38
|
-
else if (text.startsWith(
|
|
39
|
-
me = this.nextMiddleExpression(text.substring(2));
|
|
53
|
+
else if (text.startsWith(`${this.getSpecialChar(options)}${options.bracketBegin}`)) {
|
|
54
|
+
me = this.nextMiddleExpression(text.substring(2), undefined, options);
|
|
40
55
|
}
|
|
41
56
|
else {
|
|
42
|
-
me = this.nextString(text);
|
|
57
|
+
me = this.nextString(text, options);
|
|
43
58
|
}
|
|
44
59
|
return me;
|
|
45
60
|
}
|
|
46
|
-
nextMiddleExpression(text, bracketBeginCharNum = 1) {
|
|
61
|
+
nextMiddleExpression(text, bracketBeginCharNum = 1, options) {
|
|
47
62
|
let stringed = false;
|
|
48
63
|
let escaped = false;
|
|
49
64
|
let bracketBeginCharFound = 0;
|
|
@@ -56,7 +71,7 @@ let ExpressionCompilerImpl = class ExpressionCompilerImpl {
|
|
|
56
71
|
section.push(c);
|
|
57
72
|
continue;
|
|
58
73
|
}
|
|
59
|
-
else if (c ===
|
|
74
|
+
else if (c === options.escapeChar) {
|
|
60
75
|
escaped = true;
|
|
61
76
|
continue;
|
|
62
77
|
}
|
|
@@ -66,20 +81,20 @@ let ExpressionCompilerImpl = class ExpressionCompilerImpl {
|
|
|
66
81
|
escaped = false;
|
|
67
82
|
}
|
|
68
83
|
else if (escaped) {
|
|
69
|
-
if (this.
|
|
84
|
+
if (this.equalsSpecialChar(options, c) || options.bracketBegin === c || options.bracketEnd === c) {
|
|
70
85
|
section.push(c);
|
|
71
86
|
}
|
|
72
87
|
else {
|
|
73
|
-
section.push(
|
|
88
|
+
section.push(options.escapeChar);
|
|
74
89
|
section.push(c);
|
|
75
90
|
}
|
|
76
91
|
escaped = false;
|
|
77
92
|
}
|
|
78
|
-
else if (
|
|
93
|
+
else if (options.bracketBegin === c) {
|
|
79
94
|
bracketBeginCharFound++;
|
|
80
95
|
section.push(c);
|
|
81
96
|
}
|
|
82
|
-
else if (
|
|
97
|
+
else if (options.bracketEnd === c) {
|
|
83
98
|
if (bracketBeginCharFound === 0 && bracketBeginCharNum === 1) {
|
|
84
99
|
const jexlEngine = this.jexlEngineProvider.provide();
|
|
85
100
|
const expression = jexlEngine.createExpression(section.join(''));
|
|
@@ -102,7 +117,7 @@ let ExpressionCompilerImpl = class ExpressionCompilerImpl {
|
|
|
102
117
|
}
|
|
103
118
|
}
|
|
104
119
|
}
|
|
105
|
-
nextString(text) {
|
|
120
|
+
nextString(text, options) {
|
|
106
121
|
let escaped = false;
|
|
107
122
|
let specialCharFound = false;
|
|
108
123
|
const section = [];
|
|
@@ -113,35 +128,35 @@ let ExpressionCompilerImpl = class ExpressionCompilerImpl {
|
|
|
113
128
|
section.push(c);
|
|
114
129
|
continue;
|
|
115
130
|
}
|
|
116
|
-
else if (c ===
|
|
131
|
+
else if (c === options.escapeChar) {
|
|
117
132
|
escaped = true;
|
|
118
133
|
continue;
|
|
119
134
|
}
|
|
120
135
|
}
|
|
121
136
|
if (escaped) {
|
|
122
|
-
if (this.
|
|
137
|
+
if (this.equalsSpecialChar(options, c) || options.bracketBegin === c || options.bracketEnd === c) {
|
|
123
138
|
section.push(c);
|
|
124
139
|
}
|
|
125
140
|
else {
|
|
126
|
-
section.push(
|
|
141
|
+
section.push(options.escapeChar);
|
|
127
142
|
section.push(c);
|
|
128
143
|
}
|
|
129
144
|
escaped = false;
|
|
130
145
|
}
|
|
131
146
|
else if (specialCharFound) {
|
|
132
|
-
if (
|
|
147
|
+
if (options.bracketBegin === c) {
|
|
133
148
|
const expression = section.join('');
|
|
134
149
|
const nextText = text.substring(i - 1);
|
|
135
150
|
return { expression, nextText };
|
|
136
151
|
}
|
|
137
152
|
else {
|
|
138
153
|
specialCharFound = false;
|
|
139
|
-
section.push(
|
|
154
|
+
section.push(options.specialChar);
|
|
140
155
|
section.push(c);
|
|
141
156
|
}
|
|
142
157
|
}
|
|
143
158
|
else {
|
|
144
|
-
if (this.
|
|
159
|
+
if (this.equalsSpecialChar(options, c)) {
|
|
145
160
|
specialCharFound = true;
|
|
146
161
|
}
|
|
147
162
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expression-compiler.js","sourceRoot":"","sources":["../../../src/common/el/expression-compiler.ts"],"names":[],"mappings":";;;;AAAA,+
|
|
1
|
+
{"version":3,"file":"expression-compiler.js","sourceRoot":"","sources":["../../../src/common/el/expression-compiler.ts"],"names":[],"mappings":";;;;AAAA,+DAA0G;AAC1G,8CAAqD;AAQ9C,IAAM,sBAAsB,GAA5B,MAAM,sBAAsB;IAA5B;QAEK,gBAAW,GAAG,IAAI,CAAC;QACnB,iBAAY,GAAG,GAAG,CAAC;QACnB,kBAAa,GAAG,GAAG,CAAC;QACpB,gBAAW,GAAG,GAAG,CAAC;IA+J9B,CAAC;IA1Ja,cAAc,CAAC,OAA4C;QACjE,IAAI,OAAO,CAAC,iBAAiB,EAAE;YAC3B,OA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,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;oBACpC,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;oBACvC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC;iBACnC;qBAAM;oBACH,gBAAgB,GAAG,KAAK,CAAC;oBACzB,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;oBAClC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;iBACnB;aACJ;iBAAM;gBACH,IAAI,IAAI,CAAC,iBAAiB,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE;oBACpC,gBAAgB,GAAG,IAAI,CAAC;iBAC3B;qBAAM;oBACH,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;iBACnB;aACJ;SACR;QAED,OAAO,EAAE,UAAU,EAAE,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC;IAC5C,CAAC;CAEJ,CAAA;AA7JG;IAAC,IAAA,sBAAS,EAAC,wCAAkB,CAAC;;kEACiC;AARtD,sBAAsB;IADlC,IAAA,sBAAS,EAAC,wCAAkB,CAAC;GACjB,sBAAsB,CAoKlC;AApKY,wDAAsB"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { JexlEngineProvider, ExpressionHandler, ExpressionContextProvider, ExpressionCompiler, ExpressionContext } from './expression-protocol';
|
|
1
|
+
import { JexlEngineProvider, ExpressionHandler, ExpressionContextProvider, ExpressionCompiler, ExpressionContext, ExpressionCompilerOptions } from './expression-protocol';
|
|
2
2
|
export declare class ExpressionHandlerImpl implements ExpressionHandler {
|
|
3
3
|
protected readonly jexlEngineProvider: JexlEngineProvider<any>;
|
|
4
4
|
protected readonly expressionContextProvider: ExpressionContextProvider;
|
|
5
5
|
protected readonly expressionCompiler: ExpressionCompiler;
|
|
6
6
|
protected _ctx: ExpressionContext;
|
|
7
7
|
protected getContext(ctx?: ExpressionContext): ExpressionContext;
|
|
8
|
-
handle(textOrObj: string | Object, ctx?: ExpressionContext): any;
|
|
9
|
-
protected doHandle(text: string, ctx?: ExpressionContext): any;
|
|
8
|
+
handle(textOrObj: string | Object, ctx?: ExpressionContext, expressionCompilerOptions?: ExpressionCompilerOptions): any;
|
|
9
|
+
protected doHandle(text: string, ctx?: ExpressionContext, expressionCompilerOptions?: ExpressionCompilerOptions): any;
|
|
10
10
|
protected hasExpression(sections: any[]): boolean;
|
|
11
11
|
}
|
|
12
12
|
//# sourceMappingURL=expression-handler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expression-handler.d.ts","sourceRoot":"","sources":["../../../src/common/el/expression-handler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"expression-handler.d.ts","sourceRoot":"","sources":["../../../src/common/el/expression-handler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAG3K,qBACa,qBAAsB,YAAW,iBAAiB;IAG3D,SAAS,CAAC,QAAQ,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,GAAG,CAAC,CAAC;IAG/D,SAAS,CAAC,QAAQ,CAAC,yBAAyB,EAAE,yBAAyB,CAAC;IAGxE,SAAS,CAAC,QAAQ,CAAC,kBAAkB,EAAE,kBAAkB,CAAC;IAE1D,SAAS,CAAC,IAAI,EAAE,iBAAiB,CAAC;IAElC,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,iBAAiB;IAU5C,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,EAAE,iBAAiB,EAAE,yBAAyB,CAAC,EAAE,yBAAyB,GAAG,GAAG;IAgBvH,SAAS,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,iBAAiB,EAAE,yBAAyB,CAAC,EAAE,yBAAyB,GAAG,GAAG;IA8BrH,SAAS,CAAC,aAAa,CAAC,QAAQ,EAAE,GAAG,EAAE;CAS1C"}
|
|
@@ -14,15 +14,15 @@ let ExpressionHandlerImpl = class ExpressionHandlerImpl {
|
|
|
14
14
|
}
|
|
15
15
|
return c;
|
|
16
16
|
}
|
|
17
|
-
handle(textOrObj, ctx) {
|
|
17
|
+
handle(textOrObj, ctx, expressionCompilerOptions) {
|
|
18
18
|
if (typeof textOrObj === 'string') {
|
|
19
|
-
return this.doHandle(textOrObj, ctx);
|
|
19
|
+
return this.doHandle(textOrObj, ctx, expressionCompilerOptions);
|
|
20
20
|
}
|
|
21
21
|
else {
|
|
22
22
|
const self = this;
|
|
23
23
|
traverse(textOrObj).forEach(function (value) {
|
|
24
24
|
if (typeof value === 'string') {
|
|
25
|
-
this.update(self.handle(value, ctx));
|
|
25
|
+
this.update(self.handle(value, ctx, expressionCompilerOptions));
|
|
26
26
|
}
|
|
27
27
|
else if (value && value._ignoreEl === true) {
|
|
28
28
|
this.update(value, true);
|
|
@@ -31,8 +31,8 @@ let ExpressionHandlerImpl = class ExpressionHandlerImpl {
|
|
|
31
31
|
return textOrObj;
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
-
doHandle(text, ctx) {
|
|
35
|
-
const sections = this.expressionCompiler.compileSections(text);
|
|
34
|
+
doHandle(text, ctx, expressionCompilerOptions) {
|
|
35
|
+
const sections = this.expressionCompiler.compileSections(text, expressionCompilerOptions);
|
|
36
36
|
if (sections.length > 0) {
|
|
37
37
|
if (this.hasExpression(sections)) {
|
|
38
38
|
const c = this.getContext(ctx);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expression-handler.js","sourceRoot":"","sources":["../../../src/common/el/expression-handler.ts"],"names":[],"mappings":";;;;AAAA,8CAAqD;AACrD,+
|
|
1
|
+
{"version":3,"file":"expression-handler.js","sourceRoot":"","sources":["../../../src/common/el/expression-handler.ts"],"names":[],"mappings":";;;;AAAA,8CAAqD;AACrD,+DAA2K;AAC3K,qCAAqC;AAG9B,IAAM,qBAAqB,GAA3B,MAAM,qBAAqB;IAapB,UAAU,CAAC,GAAuB;QACxC,MAAM,CAAC,GAAG,GAAG,IAAI,IAAI,CAAC,yBAAyB,CAAC,OAAO,EAAE,CAAC;QAE1D,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,IAAI,CAAC,IAAI,EAAE;YACzB,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC;YACd,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;SACrB;QACD,OAAO,CAAC,CAAC;IACb,CAAC;IAED,MAAM,CAAC,SAA0B,EAAE,GAAuB,EAAE,yBAAqD;QAC7G,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE;YAC/B,OAAO,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE,yBAAyB,CAAC,CAAC;SACnE;aAAM;YACH,MAAM,IAAI,GAAG,IAAI,CAAC;YAClB,QAAQ,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,UAAU,KAAU;gBAC5C,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;oBAC3B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,GAAG,EAAE,yBAAyB,CAAC,CAAC,CAAC;iBACnE;qBAAM,IAAI,KAAK,IAAK,KAAa,CAAC,SAAS,KAAK,IAAI,EAAE;oBACnD,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;iBAC5B;YACL,CAAC,CAAC,CAAC;YACH,OAAO,SAAS,CAAC;SACpB;IACL,CAAC;IAES,QAAQ,CAAC,IAAY,EAAE,GAAuB,EAAE,yBAAqD;QAC3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B,OAAO,IAAI,CAAC;aACf;SACJ;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;CAEJ,CAAA;AA5EG;IAAC,IAAA,sBAAS,EAAC,wCAAkB,CAAC;;iEACiC;AAE/D;IAAC,IAAA,sBAAS,EAAC,+CAAyB,CAAC;;wEACmC;AAExE;IAAC,IAAA,sBAAS,EAAC,wCAAkB,CAAC;;iEAC4B;AATjD,qBAAqB;IADjC,IAAA,sBAAS,EAAC,uCAAiB,CAAC;GAChB,qBAAqB,CA8EjC;AA9EY,sDAAqB"}
|
|
@@ -4,14 +4,21 @@ export declare const ContextInitializer: unique symbol;
|
|
|
4
4
|
export declare const ExpressionContextProvider: unique symbol;
|
|
5
5
|
export declare const JexlEngineProvider: unique symbol;
|
|
6
6
|
export interface ExpressionCompiler {
|
|
7
|
-
compileSections(text: string): any[];
|
|
7
|
+
compileSections(text: string, options?: ExpressionCompilerOptions): any[];
|
|
8
8
|
}
|
|
9
9
|
export interface ExpressionHandler {
|
|
10
|
-
handle(text: string | Object, ctx?: ExpressionContext): any;
|
|
10
|
+
handle(text: string | Object, ctx?: ExpressionContext, expressionCompilerOptions?: ExpressionCompilerOptions): any;
|
|
11
11
|
}
|
|
12
12
|
export interface ExpressionContext {
|
|
13
13
|
[key: string]: any;
|
|
14
14
|
}
|
|
15
|
+
export interface ExpressionCompilerOptions {
|
|
16
|
+
escapeChar?: string;
|
|
17
|
+
specialChar?: string;
|
|
18
|
+
bracketBegin?: string;
|
|
19
|
+
bracketEnd?: string;
|
|
20
|
+
ignoreSpecialChar?: boolean;
|
|
21
|
+
}
|
|
15
22
|
export interface ContextInitializer {
|
|
16
23
|
initialize(ctx: ExpressionContext): void;
|
|
17
24
|
readonly priority: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expression-protocol.d.ts","sourceRoot":"","sources":["../../../src/common/el/expression-protocol.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB,eAA+B,CAAC;AAC/D,eAAO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AAQ,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,WAAW,yBAAyB;IAEtC,OAAO,IAAI,iBAAiB,CAAC;CAChC;AAED,MAAM,WAAW,kBAAkB,CAAC,CAAC;IAEjC,OAAO,IAAI,CAAC,CAAA;CACf"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Bytes } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Byte utility class.
|
|
4
|
+
*/
|
|
5
|
+
export declare class ByteUtil {
|
|
6
|
+
private static isNode;
|
|
7
|
+
private static isBrowser;
|
|
8
|
+
static decode(bytes: Bytes): string;
|
|
9
|
+
static encodeBase64(bytes: Bytes): string;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=byte-util.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"byte-util.d.ts","sourceRoot":"","sources":["../../../src/common/utils/byte-util.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC;;GAEG;AACH,qBAAa,QAAQ;IACjB,OAAO,CAAC,MAAM,CAAC,MAAM;IAIrB,OAAO,CAAC,MAAM,CAAC,SAAS;IAIxB,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM;IA+BnC,MAAM,CAAC,YAAY,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM;CAiC5C"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ByteUtil = void 0;
|
|
4
|
+
const error_1 = require("../error");
|
|
5
|
+
/**
|
|
6
|
+
* Byte utility class.
|
|
7
|
+
*/
|
|
8
|
+
class ByteUtil {
|
|
9
|
+
static isNode() {
|
|
10
|
+
return typeof Buffer !== 'undefined';
|
|
11
|
+
}
|
|
12
|
+
static isBrowser() {
|
|
13
|
+
return typeof TextDecoder !== 'undefined';
|
|
14
|
+
}
|
|
15
|
+
static decode(bytes) {
|
|
16
|
+
if (!bytes) {
|
|
17
|
+
return '';
|
|
18
|
+
}
|
|
19
|
+
if (typeof bytes === 'string') {
|
|
20
|
+
return bytes;
|
|
21
|
+
}
|
|
22
|
+
if (this.isNode()) {
|
|
23
|
+
if (bytes instanceof Buffer || bytes instanceof Uint8Array) {
|
|
24
|
+
return Buffer.from(bytes).toString('utf8');
|
|
25
|
+
}
|
|
26
|
+
throw new error_1.IllegalArgumentError(`Unexpected type ${bytes.constructor.name} in Node environment.`);
|
|
27
|
+
}
|
|
28
|
+
if (this.isBrowser()) {
|
|
29
|
+
if (bytes instanceof Uint8Array || bytes instanceof ArrayBuffer) {
|
|
30
|
+
return new TextDecoder('utf8').decode(bytes);
|
|
31
|
+
}
|
|
32
|
+
throw new error_1.IllegalArgumentError(`Unexpected type ${bytes.constructor.name} in Browser environment.`);
|
|
33
|
+
}
|
|
34
|
+
throw new error_1.IllegalArgumentError('Neither Buffer nor TextDecoder are available.');
|
|
35
|
+
}
|
|
36
|
+
static encodeBase64(bytes) {
|
|
37
|
+
if (!bytes) {
|
|
38
|
+
return '';
|
|
39
|
+
}
|
|
40
|
+
if (this.isNode()) {
|
|
41
|
+
if (typeof bytes === 'string') {
|
|
42
|
+
return Buffer.from(bytes, 'utf8').toString('base64');
|
|
43
|
+
}
|
|
44
|
+
if (bytes instanceof Buffer || bytes instanceof Uint8Array) {
|
|
45
|
+
return Buffer.from(bytes).toString('base64');
|
|
46
|
+
}
|
|
47
|
+
throw new error_1.IllegalArgumentError(`Unexpected type ${bytes.constructor.name} in Node environment.`);
|
|
48
|
+
}
|
|
49
|
+
if (this.isBrowser()) {
|
|
50
|
+
if (typeof bytes === 'string') {
|
|
51
|
+
return btoa(new TextEncoder().encode(bytes).reduce((data, byte) => data + String.fromCharCode(byte), ''));
|
|
52
|
+
}
|
|
53
|
+
if (bytes instanceof Uint8Array || bytes instanceof ArrayBuffer) {
|
|
54
|
+
return btoa(String.fromCharCode(...new Uint8Array(bytes)));
|
|
55
|
+
}
|
|
56
|
+
throw new error_1.IllegalArgumentError(`Unexpected type ${bytes.constructor.name} in Browser environment.`);
|
|
57
|
+
}
|
|
58
|
+
throw new error_1.IllegalArgumentError('Neither Buffer nor TextEncoder are available.');
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.ByteUtil = ByteUtil;
|
|
62
|
+
//# sourceMappingURL=byte-util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"byte-util.js","sourceRoot":"","sources":["../../../src/common/utils/byte-util.ts"],"names":[],"mappings":";;;AAAA,oCAAgD;AAGhD;;GAEG;AACH,MAAa,QAAQ;IACT,MAAM,CAAC,MAAM;QACjB,OAAO,OAAO,MAAM,KAAK,WAAW,CAAC;IACzC,CAAC;IAEO,MAAM,CAAC,SAAS;QACpB,OAAO,OAAO,WAAW,KAAK,WAAW,CAAC;IAC9C,CAAC;IAED,MAAM,CAAC,MAAM,CAAC,KAAY;QACtB,IAAI,CAAC,KAAK,EAAE;YACR,OAAO,EAAE,CAAC;SACb;QACD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC3B,OAAO,KAAK,CAAC;SAChB;QAED,IAAI,IAAI,CAAC,MAAM,EAAE,EAAE;YACf,IAAI,KAAK,YAAY,MAAM,IAAI,KAAK,YAAY,UAAU,EAAE;gBACxD,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;aAC9C;YACD,MAAM,IAAI,4BAAoB,CAC1B,mBAAmB,KAAK,CAAC,WAAW,CAAC,IAAI,uBAAuB,CACnE,CAAC;SACL;QAED,IAAI,IAAI,CAAC,SAAS,EAAE,EAAE;YAClB,IAAI,KAAK,YAAY,UAAU,IAAI,KAAK,YAAY,WAAW,EAAE;gBAC7D,OAAO,IAAI,WAAW,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;aAChD;YACD,MAAM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BAA0B,CAC/E,CAAC;SACL;QAED,MAAM,IAAI,4BAAoB,CAC1B,+CAA+C,CAClD,CAAC;IACN,CAAC;CACJ;AAzED,4BAyEC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/common/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,MAAM,CAAC;AACrB,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/common/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,MAAM,CAAC;AACrB,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC"}
|
|
@@ -20,4 +20,5 @@ tslib_1.__exportStar(require("./uuid"), exports);
|
|
|
20
20
|
tslib_1.__exportStar(require("./assert"), exports);
|
|
21
21
|
tslib_1.__exportStar(require("./mime-type-util"), exports);
|
|
22
22
|
tslib_1.__exportStar(require("./mime-type"), exports);
|
|
23
|
+
tslib_1.__exportStar(require("./byte-util"), exports);
|
|
23
24
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/utils/index.ts"],"names":[],"mappings":";;;AAAA,2DAAiC;AACjC,yDAA+B;AAC/B,kDAAwB;AACxB,uDAA6B;AAC7B,0DAAgC;AAChC,uDAA6B;AAC7B,+CAAqB;AACrB,uDAA6B;AAC7B,4DAAkC;AAClC,yDAA+B;AAC/B,kDAAwB;AACxB,oDAA0B;AAC1B,wDAA8B;AAC9B,kDAAwB;AACxB,qDAA2B;AAC3B,iDAAuB;AACvB,mDAAyB;AACzB,2DAAiC;AACjC,sDAA4B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/utils/index.ts"],"names":[],"mappings":";;;AAAA,2DAAiC;AACjC,yDAA+B;AAC/B,kDAAwB;AACxB,uDAA6B;AAC7B,0DAAgC;AAChC,uDAA6B;AAC7B,+CAAqB;AACrB,uDAA6B;AAC7B,4DAAkC;AAClC,yDAA+B;AAC/B,kDAAwB;AACxB,oDAA0B;AAC1B,wDAA8B;AAC9B,kDAAwB;AACxB,qDAA2B;AAC3B,iDAAuB;AACvB,mDAAyB;AACzB,2DAAiC;AACjC,sDAA4B;AAC5B,sDAA4B"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
export interface Newable<T> {
|
|
2
3
|
new (...args: any[]): T;
|
|
3
4
|
}
|
|
@@ -10,4 +11,8 @@ export interface Type<T> extends Function {
|
|
|
10
11
|
export declare type Mutable<T> = {
|
|
11
12
|
-readonly [P in keyof T]: T[P];
|
|
12
13
|
};
|
|
14
|
+
/**
|
|
15
|
+
* A byte array type that can be used to represent binary data.
|
|
16
|
+
*/
|
|
17
|
+
export declare type Bytes = string | ArrayBuffer | Uint8Array | Buffer | null | undefined;
|
|
13
18
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/common/utils/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,OAAO,CAAC,CAAC;IACtB,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;CAC3B;AACD,MAAM,WAAW,QAAQ,CAAC,CAAC;IACvB,SAAS,EAAE,CAAC,CAAC;CAChB;AAED,MAAM,WAAW,IAAI,CAAC,CAAC,CAAE,SAAQ,QAAQ;IACrC,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;CAC3B;AAED,oBAAY,OAAO,CAAC,CAAC,IAAI;IAAE,CAAC,UAAU,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,CAAC"}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/common/utils/types.ts"],"names":[],"mappings":";AAAA,MAAM,WAAW,OAAO,CAAC,CAAC;IACtB,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;CAC3B;AACD,MAAM,WAAW,QAAQ,CAAC,CAAC;IACvB,SAAS,EAAE,CAAC,CAAC;CAChB;AAED,MAAM,WAAW,IAAI,CAAC,CAAC,CAAE,SAAQ,QAAQ;IACrC,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;CAC3B;AAED,oBAAY,OAAO,CAAC,CAAC,IAAI;IAAE,CAAC,UAAU,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,CAAC;AAE5D;;GAEG;AACH,oBAAY,KAAK,GAAG,MAAM,GAAG,WAAW,GAAG,UAAU,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@celljs/core",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/common/index.js",
|
|
6
6
|
"typings": "lib/common/index.d.ts",
|
|
@@ -48,9 +48,9 @@
|
|
|
48
48
|
"test": "cell-component test:js"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@celljs/component": "3.
|
|
51
|
+
"@celljs/component": "3.4.0",
|
|
52
52
|
"@types/jexl": "^2.2.0",
|
|
53
53
|
"@types/traverse": "^0.6.32"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "b114f353f7970576de97cc116e9a67a1a60cb686"
|
|
56
56
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ExpressionCompiler, JexlEngineProvider } from './expression-protocol';
|
|
1
|
+
import { ExpressionCompiler, ExpressionCompilerOptions, JexlEngineProvider } from './expression-protocol';
|
|
2
2
|
import { Component, Autowired } from '../annotation';
|
|
3
3
|
|
|
4
4
|
interface MiddleExpression {
|
|
@@ -17,15 +17,32 @@ export class ExpressionCompilerImpl implements ExpressionCompiler {
|
|
|
17
17
|
@Autowired(JexlEngineProvider)
|
|
18
18
|
protected readonly jexlEngineProvider: JexlEngineProvider<any>;
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
if (
|
|
20
|
+
protected getSpecialChar(opitons: Required<ExpressionCompilerOptions>): string {
|
|
21
|
+
if (opitons.ignoreSpecialChar) {
|
|
22
|
+
return '';
|
|
23
|
+
}
|
|
24
|
+
return opitons.specialChar;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
protected equalsSpecialChar(opitons: Required<ExpressionCompilerOptions>, char: string): boolean {
|
|
28
|
+
if (opitons.ignoreSpecialChar) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
return char === opitons.specialChar;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
compileSections(text: string, options: ExpressionCompilerOptions): any[] {
|
|
35
|
+
const merged = {
|
|
36
|
+
...{ escapeChar: this.ESCAPE_CHAR, specialChar: this.SPECIAL_CHAR, bracketBegin: this.BRACKET_BEGIN, bracketEnd: this.BRACKET_END, ...options }
|
|
37
|
+
} as Required<ExpressionCompilerOptions>;
|
|
38
|
+
if (!text || text.indexOf(`${this.getSpecialChar(merged)}${merged.bracketBegin}`) < 0) {
|
|
22
39
|
return [];
|
|
23
40
|
}
|
|
24
41
|
|
|
25
42
|
const sections: any[] = [];
|
|
26
43
|
let middleText: string | undefined = text;
|
|
27
44
|
while (middleText) {
|
|
28
|
-
const me: MiddleExpression | undefined = this.middleCompile(middleText);
|
|
45
|
+
const me: MiddleExpression | undefined = this.middleCompile(middleText, merged);
|
|
29
46
|
if (!me) {
|
|
30
47
|
sections.push(middleText);
|
|
31
48
|
middleText = undefined;
|
|
@@ -38,19 +55,19 @@ export class ExpressionCompilerImpl implements ExpressionCompiler {
|
|
|
38
55
|
return sections;
|
|
39
56
|
}
|
|
40
57
|
|
|
41
|
-
protected middleCompile(text: string): MiddleExpression | undefined {
|
|
58
|
+
protected middleCompile(text: string, options: Required<ExpressionCompilerOptions>): MiddleExpression | undefined {
|
|
42
59
|
let me: MiddleExpression | undefined;
|
|
43
|
-
if (text.startsWith(
|
|
44
|
-
me = this.nextMiddleExpression(text.substring(3), 2);
|
|
45
|
-
} else if (text.startsWith(
|
|
46
|
-
me = this.nextMiddleExpression(text.substring(2));
|
|
60
|
+
if (text.startsWith(`${this.getSpecialChar(options)}${options.bracketBegin}${options.bracketBegin}`)) {
|
|
61
|
+
me = this.nextMiddleExpression(text.substring(3), 2, options);
|
|
62
|
+
} else if (text.startsWith(`${this.getSpecialChar(options)}${options.bracketBegin}`)) {
|
|
63
|
+
me = this.nextMiddleExpression(text.substring(2), undefined, options);
|
|
47
64
|
} else {
|
|
48
|
-
me = this.nextString(text);
|
|
65
|
+
me = this.nextString(text, options);
|
|
49
66
|
}
|
|
50
67
|
return me;
|
|
51
68
|
}
|
|
52
69
|
|
|
53
|
-
protected nextMiddleExpression(text: string, bracketBeginCharNum = 1): MiddleExpression | undefined {
|
|
70
|
+
protected nextMiddleExpression(text: string, bracketBeginCharNum = 1, options: Required<ExpressionCompilerOptions>): MiddleExpression | undefined {
|
|
54
71
|
let stringed = false;
|
|
55
72
|
let escaped = false;
|
|
56
73
|
let bracketBeginCharFound = 0;
|
|
@@ -64,7 +81,7 @@ export class ExpressionCompilerImpl implements ExpressionCompiler {
|
|
|
64
81
|
section.push(c);
|
|
65
82
|
continue;
|
|
66
83
|
} else
|
|
67
|
-
if (c ===
|
|
84
|
+
if (c === options.escapeChar) {
|
|
68
85
|
escaped = true;
|
|
69
86
|
continue;
|
|
70
87
|
}
|
|
@@ -74,17 +91,17 @@ export class ExpressionCompilerImpl implements ExpressionCompiler {
|
|
|
74
91
|
section.push(c);
|
|
75
92
|
escaped = false;
|
|
76
93
|
} else if (escaped) {
|
|
77
|
-
if (this.
|
|
94
|
+
if (this.equalsSpecialChar(options, c) || options.bracketBegin === c || options.bracketEnd === c) {
|
|
78
95
|
section.push(c);
|
|
79
96
|
} else {
|
|
80
|
-
section.push(
|
|
97
|
+
section.push(options.escapeChar);
|
|
81
98
|
section.push(c);
|
|
82
99
|
}
|
|
83
100
|
escaped = false;
|
|
84
|
-
} else if (
|
|
101
|
+
} else if (options.bracketBegin === c) {
|
|
85
102
|
bracketBeginCharFound++;
|
|
86
103
|
section.push(c);
|
|
87
|
-
} else if (
|
|
104
|
+
} else if (options.bracketEnd === c) {
|
|
88
105
|
if (bracketBeginCharFound === 0 && bracketBeginCharNum === 1) {
|
|
89
106
|
const jexlEngine = this.jexlEngineProvider.provide();
|
|
90
107
|
const expression = jexlEngine.createExpression(section.join(''));
|
|
@@ -105,7 +122,7 @@ export class ExpressionCompilerImpl implements ExpressionCompiler {
|
|
|
105
122
|
}
|
|
106
123
|
}
|
|
107
124
|
|
|
108
|
-
protected nextString(text: string): MiddleExpression {
|
|
125
|
+
protected nextString(text: string, options: Required<ExpressionCompilerOptions>): MiddleExpression {
|
|
109
126
|
let escaped = false;
|
|
110
127
|
let specialCharFound = false;
|
|
111
128
|
|
|
@@ -117,33 +134,33 @@ export class ExpressionCompilerImpl implements ExpressionCompiler {
|
|
|
117
134
|
section.push(c);
|
|
118
135
|
continue;
|
|
119
136
|
} else
|
|
120
|
-
if (c ===
|
|
137
|
+
if (c === options.escapeChar) {
|
|
121
138
|
escaped = true;
|
|
122
139
|
continue;
|
|
123
140
|
}
|
|
124
141
|
}
|
|
125
142
|
|
|
126
143
|
if (escaped) {
|
|
127
|
-
if (this.
|
|
144
|
+
if (this.equalsSpecialChar(options, c) || options.bracketBegin === c || options.bracketEnd === c) {
|
|
128
145
|
section.push(c);
|
|
129
146
|
} else {
|
|
130
|
-
section.push(
|
|
147
|
+
section.push(options.escapeChar);
|
|
131
148
|
section.push(c);
|
|
132
149
|
}
|
|
133
150
|
escaped = false;
|
|
134
151
|
} else
|
|
135
152
|
if (specialCharFound) {
|
|
136
|
-
if (
|
|
153
|
+
if (options.bracketBegin === c) {
|
|
137
154
|
const expression = section.join('');
|
|
138
155
|
const nextText = text.substring(i - 1);
|
|
139
156
|
return { expression, nextText };
|
|
140
157
|
} else {
|
|
141
158
|
specialCharFound = false;
|
|
142
|
-
section.push(
|
|
159
|
+
section.push(options.specialChar);
|
|
143
160
|
section.push(c);
|
|
144
161
|
}
|
|
145
162
|
} else {
|
|
146
|
-
if (this.
|
|
163
|
+
if (this.equalsSpecialChar(options, c)) {
|
|
147
164
|
specialCharFound = true;
|
|
148
165
|
} else {
|
|
149
166
|
section.push(c);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Component, Autowired } from '../annotation';
|
|
2
|
-
import { JexlEngineProvider, ExpressionHandler, ExpressionContextProvider, ExpressionCompiler, ExpressionContext } from './expression-protocol';
|
|
2
|
+
import { JexlEngineProvider, ExpressionHandler, ExpressionContextProvider, ExpressionCompiler, ExpressionContext, ExpressionCompilerOptions } from './expression-protocol';
|
|
3
3
|
import * as traverse from 'traverse';
|
|
4
4
|
|
|
5
5
|
@Component(ExpressionHandler)
|
|
@@ -26,14 +26,14 @@ export class ExpressionHandlerImpl implements ExpressionHandler {
|
|
|
26
26
|
return c;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
handle(textOrObj: string | Object, ctx?: ExpressionContext): any {
|
|
29
|
+
handle(textOrObj: string | Object, ctx?: ExpressionContext, expressionCompilerOptions?: ExpressionCompilerOptions): any {
|
|
30
30
|
if (typeof textOrObj === 'string') {
|
|
31
|
-
return this.doHandle(textOrObj, ctx);
|
|
31
|
+
return this.doHandle(textOrObj, ctx, expressionCompilerOptions);
|
|
32
32
|
} else {
|
|
33
33
|
const self = this;
|
|
34
34
|
traverse(textOrObj).forEach(function (value: any) {
|
|
35
35
|
if (typeof value === 'string') {
|
|
36
|
-
this.update(self.handle(value, ctx));
|
|
36
|
+
this.update(self.handle(value, ctx, expressionCompilerOptions));
|
|
37
37
|
} else if (value && (value as any)._ignoreEl === true) {
|
|
38
38
|
this.update(value, true);
|
|
39
39
|
}
|
|
@@ -42,8 +42,8 @@ export class ExpressionHandlerImpl implements ExpressionHandler {
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
protected doHandle(text: string, ctx?: ExpressionContext): any {
|
|
46
|
-
const sections = this.expressionCompiler.compileSections(text);
|
|
45
|
+
protected doHandle(text: string, ctx?: ExpressionContext, expressionCompilerOptions?: ExpressionCompilerOptions): any {
|
|
46
|
+
const sections = this.expressionCompiler.compileSections(text, expressionCompilerOptions);
|
|
47
47
|
if (sections.length > 0) {
|
|
48
48
|
if (this.hasExpression(sections)) {
|
|
49
49
|
const c = this.getContext(ctx);
|
|
@@ -5,12 +5,12 @@ export const ExpressionContextProvider = Symbol('ExpressionContextProvider');
|
|
|
5
5
|
export const JexlEngineProvider = Symbol('JexlEngineProvider');
|
|
6
6
|
|
|
7
7
|
export interface ExpressionCompiler {
|
|
8
|
-
compileSections(text: string): any[]
|
|
8
|
+
compileSections(text: string, options?: ExpressionCompilerOptions): any[]
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export interface ExpressionHandler {
|
|
12
12
|
|
|
13
|
-
handle(text: string | Object, ctx?: ExpressionContext): any;
|
|
13
|
+
handle(text: string | Object, ctx?: ExpressionContext, expressionCompilerOptions?: ExpressionCompilerOptions): any;
|
|
14
14
|
|
|
15
15
|
}
|
|
16
16
|
|
|
@@ -18,6 +18,14 @@ export interface ExpressionContext {
|
|
|
18
18
|
[key: string]: any;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
export interface ExpressionCompilerOptions {
|
|
22
|
+
escapeChar?: string;
|
|
23
|
+
specialChar?: string;
|
|
24
|
+
bracketBegin?: string;
|
|
25
|
+
bracketEnd?: string;
|
|
26
|
+
ignoreSpecialChar?: boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
21
29
|
export interface ContextInitializer {
|
|
22
30
|
|
|
23
31
|
initialize(ctx: ExpressionContext): void;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { IllegalArgumentError } from '../error';
|
|
2
|
+
import { Bytes } from './types';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Byte utility class.
|
|
6
|
+
*/
|
|
7
|
+
export class ByteUtil {
|
|
8
|
+
private static isNode(): boolean {
|
|
9
|
+
return typeof Buffer !== 'undefined';
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
private static isBrowser(): boolean {
|
|
13
|
+
return typeof TextDecoder !== 'undefined';
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
static decode(bytes: Bytes): string {
|
|
17
|
+
if (!bytes) {
|
|
18
|
+
return '';
|
|
19
|
+
}
|
|
20
|
+
if (typeof bytes === 'string') {
|
|
21
|
+
return bytes;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (this.isNode()) {
|
|
25
|
+
if (bytes instanceof Buffer || bytes instanceof Uint8Array) {
|
|
26
|
+
return Buffer.from(bytes).toString('utf8');
|
|
27
|
+
}
|
|
28
|
+
throw new IllegalArgumentError(
|
|
29
|
+
`Unexpected type ${bytes.constructor.name} in Node environment.`
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (this.isBrowser()) {
|
|
34
|
+
if (bytes instanceof Uint8Array || bytes instanceof ArrayBuffer) {
|
|
35
|
+
return new TextDecoder('utf8').decode(bytes);
|
|
36
|
+
}
|
|
37
|
+
throw new IllegalArgumentError(
|
|
38
|
+
`Unexpected type ${(bytes as any).constructor.name} in Browser environment.`
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
throw new IllegalArgumentError(
|
|
43
|
+
'Neither Buffer nor TextDecoder are available.'
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
static encodeBase64(bytes: Bytes): string {
|
|
48
|
+
if (!bytes) {
|
|
49
|
+
return '';
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (this.isNode()) {
|
|
53
|
+
if (typeof bytes === 'string') {
|
|
54
|
+
return Buffer.from(bytes, 'utf8').toString('base64');
|
|
55
|
+
}
|
|
56
|
+
if (bytes instanceof Buffer || bytes instanceof Uint8Array) {
|
|
57
|
+
return Buffer.from(bytes).toString('base64');
|
|
58
|
+
}
|
|
59
|
+
throw new IllegalArgumentError(
|
|
60
|
+
`Unexpected type ${bytes.constructor.name} in Node environment.`
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (this.isBrowser()) {
|
|
65
|
+
if (typeof bytes === 'string') {
|
|
66
|
+
return btoa(new TextEncoder().encode(bytes).reduce((data, byte) => data + String.fromCharCode(byte), ''));
|
|
67
|
+
}
|
|
68
|
+
if (bytes instanceof Uint8Array || bytes instanceof ArrayBuffer) {
|
|
69
|
+
return btoa(String.fromCharCode(...new Uint8Array(bytes)));
|
|
70
|
+
}
|
|
71
|
+
throw new IllegalArgumentError(
|
|
72
|
+
`Unexpected type ${(bytes as any).constructor.name} in Browser environment.`
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
throw new IllegalArgumentError(
|
|
77
|
+
'Neither Buffer nor TextEncoder are available.'
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -11,3 +11,7 @@ export interface Type<T> extends Function {
|
|
|
11
11
|
|
|
12
12
|
export type Mutable<T> = { -readonly [P in keyof T]: T[P] };
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* A byte array type that can be used to represent binary data.
|
|
16
|
+
*/
|
|
17
|
+
export type Bytes = string | ArrayBuffer | Uint8Array | Buffer | null | undefined;
|