amis-formula 3.0.0 → 3.1.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/esm/doc.js +1 -1
- package/esm/error.js +1 -1
- package/esm/evalutor.js +1 -1
- package/esm/evalutorForAsync.js +31 -36
- package/esm/filter.js +1 -1
- package/esm/function.d.ts +3 -1
- package/esm/function.js +11 -2
- package/esm/index.d.ts +2 -2
- package/esm/index.js +2 -2
- package/esm/lexer.js +1 -1
- package/esm/parser.js +1 -1
- package/esm/types.d.ts +9 -0
- package/lib/doc.js +1 -1
- package/lib/error.js +1 -1
- package/lib/evalutor.js +1 -1
- package/lib/evalutorForAsync.js +31 -36
- package/lib/filter.js +1 -1
- package/lib/function.d.ts +3 -1
- package/lib/function.js +12 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.js +3 -1
- package/lib/lexer.js +1 -1
- package/lib/parser.js +1 -1
- package/lib/types.d.ts +9 -0
- package/package.json +2 -2
package/esm/doc.js
CHANGED
package/esm/error.js
CHANGED
package/esm/evalutor.js
CHANGED
package/esm/evalutorForAsync.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* amis-formula v3.
|
|
2
|
+
* amis-formula v3.1.0
|
|
3
3
|
* Copyright 2021-2023 fex
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -73,7 +73,7 @@ var AsyncEvaluator = /** @class */ (function (_super) {
|
|
|
73
73
|
};
|
|
74
74
|
AsyncEvaluator.prototype.filter = function (ast) {
|
|
75
75
|
return __awaiter(this, void 0, void 0, function () {
|
|
76
|
-
var input, filters, context,
|
|
76
|
+
var input, filters, context, filter, fn, argsRes;
|
|
77
77
|
var _this = this;
|
|
78
78
|
return __generator(this, function (_a) {
|
|
79
79
|
switch (_a.label) {
|
|
@@ -86,47 +86,42 @@ var AsyncEvaluator = /** @class */ (function (_super) {
|
|
|
86
86
|
data: this.context,
|
|
87
87
|
restFilters: filters
|
|
88
88
|
};
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
_a.label = 2;
|
|
90
|
+
case 2:
|
|
91
|
+
if (!filters.length) return [3 /*break*/, 4];
|
|
92
|
+
filter = filters.shift();
|
|
93
|
+
fn = this.filters[filter.name];
|
|
94
|
+
if (!fn) {
|
|
95
|
+
throw new Error("filter `".concat(filter.name, "` not exists."));
|
|
96
|
+
}
|
|
97
|
+
context.filter = filter;
|
|
98
|
+
return [4 /*yield*/, runSequence(filter.args, function (item) { return __awaiter(_this, void 0, void 0, function () {
|
|
99
|
+
var res;
|
|
91
100
|
var _this = this;
|
|
92
101
|
return __generator(this, function (_a) {
|
|
93
102
|
switch (_a.label) {
|
|
94
|
-
case 0:
|
|
103
|
+
case 0:
|
|
104
|
+
if (!((item === null || item === void 0 ? void 0 : item.type) === 'mixed')) return [3 /*break*/, 2];
|
|
105
|
+
return [4 /*yield*/, runSequence(item.body, function (item) {
|
|
106
|
+
return typeof item === 'string' ? item : _this.evalute(item);
|
|
107
|
+
})];
|
|
95
108
|
case 1:
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
if (!fn) {
|
|
99
|
-
throw new Error("filter `".concat(filter.name, "` not exists."));
|
|
100
|
-
}
|
|
101
|
-
context.filter = filter;
|
|
102
|
-
return [4 /*yield*/, filter.args.reduce(function (promise, item) { return __awaiter(_this, void 0, void 0, function () {
|
|
103
|
-
var _this = this;
|
|
104
|
-
return __generator(this, function (_a) {
|
|
105
|
-
switch (_a.label) {
|
|
106
|
-
case 0: return [4 /*yield*/, promise];
|
|
107
|
-
case 1:
|
|
108
|
-
_a.sent();
|
|
109
|
-
if ((item === null || item === void 0 ? void 0 : item.type) === 'mixed') {
|
|
110
|
-
return [2 /*return*/, runSequence(item.body, function (item) {
|
|
111
|
-
return typeof item === 'string' ? item : _this.evalute(item);
|
|
112
|
-
})];
|
|
113
|
-
}
|
|
114
|
-
else if (item.type) {
|
|
115
|
-
return [2 /*return*/, this.evalute(item)];
|
|
116
|
-
}
|
|
117
|
-
return [2 /*return*/, item];
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
}); }, Promise.resolve([]))];
|
|
109
|
+
res = _a.sent();
|
|
110
|
+
return [2 /*return*/, res.join('')];
|
|
121
111
|
case 2:
|
|
122
|
-
|
|
123
|
-
|
|
112
|
+
if (item.type) {
|
|
113
|
+
return [2 /*return*/, this.evalute(item)];
|
|
114
|
+
}
|
|
115
|
+
_a.label = 3;
|
|
116
|
+
case 3: return [2 /*return*/, item];
|
|
124
117
|
}
|
|
125
118
|
});
|
|
126
|
-
}); }
|
|
127
|
-
case
|
|
128
|
-
|
|
129
|
-
|
|
119
|
+
}); })];
|
|
120
|
+
case 3:
|
|
121
|
+
argsRes = _a.sent();
|
|
122
|
+
input = fn.apply(context, [input].concat(argsRes));
|
|
123
|
+
return [3 /*break*/, 2];
|
|
124
|
+
case 4: return [2 /*return*/, input];
|
|
130
125
|
}
|
|
131
126
|
});
|
|
132
127
|
});
|
package/esm/filter.js
CHANGED
package/esm/function.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
import { FunctionMap } from './types';
|
|
1
|
+
import { FunctionMap, FunctionDocMap, FunctionDocItem } from './types';
|
|
2
2
|
export declare const functions: FunctionMap;
|
|
3
3
|
export declare function registerFunction(name: string, fn: (input: any, ...args: any[]) => any): void;
|
|
4
|
+
export declare let functionDocs: FunctionDocMap;
|
|
5
|
+
export declare function registerFunctionDoc(groupName: string, item: FunctionDocItem): void;
|
package/esm/function.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* amis-formula v3.
|
|
2
|
+
* amis-formula v3.1.0
|
|
3
3
|
* Copyright 2021-2023 fex
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -10,5 +10,14 @@ function registerFunction(name, fn) {
|
|
|
10
10
|
functions["fn".concat(name)] = fn;
|
|
11
11
|
Evaluator.setDefaultFunctions(functions);
|
|
12
12
|
}
|
|
13
|
+
var functionDocs = {};
|
|
14
|
+
function registerFunctionDoc(groupName, item) {
|
|
15
|
+
if (functionDocs[groupName]) {
|
|
16
|
+
functionDocs[groupName].push(item);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
functionDocs[groupName] = [item];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
13
22
|
|
|
14
|
-
export { functions, registerFunction };
|
|
23
|
+
export { functionDocs, functions, registerFunction, registerFunctionDoc };
|
package/esm/index.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ import { AsyncEvaluator } from './evalutorForAsync';
|
|
|
3
3
|
import { parse } from './parser';
|
|
4
4
|
import { lexer } from './lexer';
|
|
5
5
|
import { registerFilter, filters, getFilters, extendsFilters } from './filter';
|
|
6
|
-
import { registerFunction } from './function';
|
|
6
|
+
import { registerFunction, registerFunctionDoc, functionDocs } from './function';
|
|
7
7
|
import type { FilterContext, ASTNode, ParserOptions, EvaluatorOptions } from './types';
|
|
8
|
-
export { parse, lexer, Evaluator, AsyncEvaluator, FilterContext, filters, getFilters, registerFilter, registerFunction, extendsFilters };
|
|
8
|
+
export { parse, lexer, Evaluator, AsyncEvaluator, FilterContext, filters, getFilters, registerFilter, registerFunction, registerFunctionDoc, functionDocs, extendsFilters };
|
|
9
9
|
export declare function evaluate(astOrString: string | ASTNode, data: any, options?: ParserOptions & EvaluatorOptions): any;
|
|
10
10
|
export declare function evaluateForAsync(astOrString: string | ASTNode, data: any, options?: ParserOptions & EvaluatorOptions): Promise<any>;
|
package/esm/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* amis-formula v3.
|
|
2
|
+
* amis-formula v3.1.0
|
|
3
3
|
* Copyright 2021-2023 fex
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -13,7 +13,7 @@ export { parse } from './parser.js';
|
|
|
13
13
|
export { lexer } from './lexer.js';
|
|
14
14
|
import { getFilters } from './filter.js';
|
|
15
15
|
export { extendsFilters, filters, getFilters, registerFilter } from './filter.js';
|
|
16
|
-
export { registerFunction } from './function.js';
|
|
16
|
+
export { functionDocs, registerFunction, registerFunctionDoc } from './function.js';
|
|
17
17
|
|
|
18
18
|
function evaluate(astOrString, data, options) {
|
|
19
19
|
var ast = astOrString;
|
package/esm/lexer.js
CHANGED
package/esm/parser.js
CHANGED
package/esm/types.d.ts
CHANGED
|
@@ -5,6 +5,15 @@ export interface FilterMap {
|
|
|
5
5
|
export interface FunctionMap {
|
|
6
6
|
[propName: string]: (this: Evaluator, ast: Object, data: any) => any;
|
|
7
7
|
}
|
|
8
|
+
export interface FunctionDocItem {
|
|
9
|
+
name: string;
|
|
10
|
+
example?: string;
|
|
11
|
+
description?: string;
|
|
12
|
+
[propName: string]: any;
|
|
13
|
+
}
|
|
14
|
+
export interface FunctionDocMap {
|
|
15
|
+
[propName: string]: FunctionDocItem[];
|
|
16
|
+
}
|
|
8
17
|
export interface FilterContext {
|
|
9
18
|
data: Object;
|
|
10
19
|
filter?: {
|
package/lib/doc.js
CHANGED
package/lib/error.js
CHANGED
package/lib/evalutor.js
CHANGED
package/lib/evalutorForAsync.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* amis-formula v3.
|
|
2
|
+
* amis-formula v3.1.0
|
|
3
3
|
* Copyright 2021-2023 fex
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -77,7 +77,7 @@ var AsyncEvaluator = /** @class */ (function (_super) {
|
|
|
77
77
|
};
|
|
78
78
|
AsyncEvaluator.prototype.filter = function (ast) {
|
|
79
79
|
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
80
|
-
var input, filters, context,
|
|
80
|
+
var input, filters, context, filter, fn, argsRes;
|
|
81
81
|
var _this = this;
|
|
82
82
|
return tslib.__generator(this, function (_a) {
|
|
83
83
|
switch (_a.label) {
|
|
@@ -90,47 +90,42 @@ var AsyncEvaluator = /** @class */ (function (_super) {
|
|
|
90
90
|
data: this.context,
|
|
91
91
|
restFilters: filters
|
|
92
92
|
};
|
|
93
|
-
|
|
94
|
-
|
|
93
|
+
_a.label = 2;
|
|
94
|
+
case 2:
|
|
95
|
+
if (!filters.length) return [3 /*break*/, 4];
|
|
96
|
+
filter = filters.shift();
|
|
97
|
+
fn = this.filters[filter.name];
|
|
98
|
+
if (!fn) {
|
|
99
|
+
throw new Error("filter `".concat(filter.name, "` not exists."));
|
|
100
|
+
}
|
|
101
|
+
context.filter = filter;
|
|
102
|
+
return [4 /*yield*/, runSequence(filter.args, function (item) { return tslib.__awaiter(_this, void 0, void 0, function () {
|
|
103
|
+
var res;
|
|
95
104
|
var _this = this;
|
|
96
105
|
return tslib.__generator(this, function (_a) {
|
|
97
106
|
switch (_a.label) {
|
|
98
|
-
case 0:
|
|
107
|
+
case 0:
|
|
108
|
+
if (!((item === null || item === void 0 ? void 0 : item.type) === 'mixed')) return [3 /*break*/, 2];
|
|
109
|
+
return [4 /*yield*/, runSequence(item.body, function (item) {
|
|
110
|
+
return typeof item === 'string' ? item : _this.evalute(item);
|
|
111
|
+
})];
|
|
99
112
|
case 1:
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
if (!fn) {
|
|
103
|
-
throw new Error("filter `".concat(filter.name, "` not exists."));
|
|
104
|
-
}
|
|
105
|
-
context.filter = filter;
|
|
106
|
-
return [4 /*yield*/, filter.args.reduce(function (promise, item) { return tslib.__awaiter(_this, void 0, void 0, function () {
|
|
107
|
-
var _this = this;
|
|
108
|
-
return tslib.__generator(this, function (_a) {
|
|
109
|
-
switch (_a.label) {
|
|
110
|
-
case 0: return [4 /*yield*/, promise];
|
|
111
|
-
case 1:
|
|
112
|
-
_a.sent();
|
|
113
|
-
if ((item === null || item === void 0 ? void 0 : item.type) === 'mixed') {
|
|
114
|
-
return [2 /*return*/, runSequence(item.body, function (item) {
|
|
115
|
-
return typeof item === 'string' ? item : _this.evalute(item);
|
|
116
|
-
})];
|
|
117
|
-
}
|
|
118
|
-
else if (item.type) {
|
|
119
|
-
return [2 /*return*/, this.evalute(item)];
|
|
120
|
-
}
|
|
121
|
-
return [2 /*return*/, item];
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
}); }, Promise.resolve([]))];
|
|
113
|
+
res = _a.sent();
|
|
114
|
+
return [2 /*return*/, res.join('')];
|
|
125
115
|
case 2:
|
|
126
|
-
|
|
127
|
-
|
|
116
|
+
if (item.type) {
|
|
117
|
+
return [2 /*return*/, this.evalute(item)];
|
|
118
|
+
}
|
|
119
|
+
_a.label = 3;
|
|
120
|
+
case 3: return [2 /*return*/, item];
|
|
128
121
|
}
|
|
129
122
|
});
|
|
130
|
-
}); }
|
|
131
|
-
case
|
|
132
|
-
|
|
133
|
-
|
|
123
|
+
}); })];
|
|
124
|
+
case 3:
|
|
125
|
+
argsRes = _a.sent();
|
|
126
|
+
input = fn.apply(context, [input].concat(argsRes));
|
|
127
|
+
return [3 /*break*/, 2];
|
|
128
|
+
case 4: return [2 /*return*/, input];
|
|
134
129
|
}
|
|
135
130
|
});
|
|
136
131
|
});
|
package/lib/filter.js
CHANGED
package/lib/function.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
import { FunctionMap } from './types';
|
|
1
|
+
import { FunctionMap, FunctionDocMap, FunctionDocItem } from './types';
|
|
2
2
|
export declare const functions: FunctionMap;
|
|
3
3
|
export declare function registerFunction(name: string, fn: (input: any, ...args: any[]) => any): void;
|
|
4
|
+
export declare let functionDocs: FunctionDocMap;
|
|
5
|
+
export declare function registerFunctionDoc(groupName: string, item: FunctionDocItem): void;
|
package/lib/function.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* amis-formula v3.
|
|
2
|
+
* amis-formula v3.1.0
|
|
3
3
|
* Copyright 2021-2023 fex
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -14,6 +14,17 @@ function registerFunction(name, fn) {
|
|
|
14
14
|
functions["fn".concat(name)] = fn;
|
|
15
15
|
evalutor.Evaluator.setDefaultFunctions(functions);
|
|
16
16
|
}
|
|
17
|
+
var functionDocs = {};
|
|
18
|
+
function registerFunctionDoc(groupName, item) {
|
|
19
|
+
if (functionDocs[groupName]) {
|
|
20
|
+
functionDocs[groupName].push(item);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
functionDocs[groupName] = [item];
|
|
24
|
+
}
|
|
25
|
+
}
|
|
17
26
|
|
|
27
|
+
exports.functionDocs = functionDocs;
|
|
18
28
|
exports.functions = functions;
|
|
19
29
|
exports.registerFunction = registerFunction;
|
|
30
|
+
exports.registerFunctionDoc = registerFunctionDoc;
|
package/lib/index.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ import { AsyncEvaluator } from './evalutorForAsync';
|
|
|
3
3
|
import { parse } from './parser';
|
|
4
4
|
import { lexer } from './lexer';
|
|
5
5
|
import { registerFilter, filters, getFilters, extendsFilters } from './filter';
|
|
6
|
-
import { registerFunction } from './function';
|
|
6
|
+
import { registerFunction, registerFunctionDoc, functionDocs } from './function';
|
|
7
7
|
import type { FilterContext, ASTNode, ParserOptions, EvaluatorOptions } from './types';
|
|
8
|
-
export { parse, lexer, Evaluator, AsyncEvaluator, FilterContext, filters, getFilters, registerFilter, registerFunction, extendsFilters };
|
|
8
|
+
export { parse, lexer, Evaluator, AsyncEvaluator, FilterContext, filters, getFilters, registerFilter, registerFunction, registerFunctionDoc, functionDocs, extendsFilters };
|
|
9
9
|
export declare function evaluate(astOrString: string | ASTNode, data: any, options?: ParserOptions & EvaluatorOptions): any;
|
|
10
10
|
export declare function evaluateForAsync(astOrString: string | ASTNode, data: any, options?: ParserOptions & EvaluatorOptions): Promise<any>;
|
package/lib/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* amis-formula v3.
|
|
2
|
+
* amis-formula v3.1.0
|
|
3
3
|
* Copyright 2021-2023 fex
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -45,6 +45,8 @@ exports.extendsFilters = filter.extendsFilters;
|
|
|
45
45
|
exports.filters = filter.filters;
|
|
46
46
|
exports.getFilters = filter.getFilters;
|
|
47
47
|
exports.registerFilter = filter.registerFilter;
|
|
48
|
+
exports.functionDocs = _function.functionDocs;
|
|
48
49
|
exports.registerFunction = _function.registerFunction;
|
|
50
|
+
exports.registerFunctionDoc = _function.registerFunctionDoc;
|
|
49
51
|
exports.evaluate = evaluate;
|
|
50
52
|
exports.evaluateForAsync = evaluateForAsync;
|
package/lib/lexer.js
CHANGED
package/lib/parser.js
CHANGED
package/lib/types.d.ts
CHANGED
|
@@ -5,6 +5,15 @@ export interface FilterMap {
|
|
|
5
5
|
export interface FunctionMap {
|
|
6
6
|
[propName: string]: (this: Evaluator, ast: Object, data: any) => any;
|
|
7
7
|
}
|
|
8
|
+
export interface FunctionDocItem {
|
|
9
|
+
name: string;
|
|
10
|
+
example?: string;
|
|
11
|
+
description?: string;
|
|
12
|
+
[propName: string]: any;
|
|
13
|
+
}
|
|
14
|
+
export interface FunctionDocMap {
|
|
15
|
+
[propName: string]: FunctionDocItem[];
|
|
16
|
+
}
|
|
8
17
|
export interface FilterContext {
|
|
9
18
|
data: Object;
|
|
10
19
|
filter?: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "amis-formula",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "负责 amis 里面的表达式实现,内置公式,编辑器等",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "esm/index.js",
|
|
@@ -113,5 +113,5 @@
|
|
|
113
113
|
"printBasicPrototype": false
|
|
114
114
|
}
|
|
115
115
|
},
|
|
116
|
-
"gitHead": "
|
|
116
|
+
"gitHead": "020b12d0be43215664e0c0e53cd33486c43fde86"
|
|
117
117
|
}
|