@tachybase/plugin-field-formula 0.23.8
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/.turbo/turbo-build.log +5 -0
- package/LICENSE +201 -0
- package/README.md +9 -0
- package/README.zh-CN.md +9 -0
- package/client.d.ts +2 -0
- package/client.js +1 -0
- package/dist/client/components/Formula/Expression.d.ts +3 -0
- package/dist/client/components/Formula/Result.d.ts +3 -0
- package/dist/client/components/Formula/index.d.ts +6 -0
- package/dist/client/components/index.d.ts +1 -0
- package/dist/client/index.d.ts +5 -0
- package/dist/client/index.js +8 -0
- package/dist/client/interfaces/formula.d.ts +645 -0
- package/dist/client/locale/index.d.ts +3 -0
- package/dist/client/scopes.d.ts +2 -0
- package/dist/externalVersion.js +10 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +39 -0
- package/dist/locale/en-US.json +8 -0
- package/dist/locale/ko_KR.json +8 -0
- package/dist/locale/zh-CN.json +8 -0
- package/dist/server/field-formula.d.ts +19 -0
- package/dist/server/field-formula.js +118 -0
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +33 -0
- package/dist/server/migrations/20230213161904-alter-field.d.ts +5 -0
- package/dist/server/migrations/20230213161904-alter-field.js +62 -0
- package/dist/server/plugin.d.ts +11 -0
- package/dist/server/plugin.js +57 -0
- package/dist/utils/index.d.ts +45 -0
- package/dist/utils/index.js +188 -0
- package/package.json +30 -0
- package/server.d.ts +2 -0
- package/server.js +1 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var src_exports = {};
|
|
30
|
+
__export(src_exports, {
|
|
31
|
+
default: () => import_server.default
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(src_exports);
|
|
34
|
+
__reExport(src_exports, require("./server"), module.exports);
|
|
35
|
+
var import_server = __toESM(require("./server"));
|
|
36
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
37
|
+
0 && (module.exports = {
|
|
38
|
+
...require("./server")
|
|
39
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Calculation engine": "Calculation engine",
|
|
3
|
+
"Compute a value based on the other fields": "Compute a value based on the other fields",
|
|
4
|
+
"Expression": "Expression",
|
|
5
|
+
"Expression syntax error": "Expression syntax error",
|
|
6
|
+
"Formula": "Formula",
|
|
7
|
+
"Syntax references": "Syntax references"
|
|
8
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Calculation engine": "计算引擎",
|
|
3
|
+
"Configure and store the results of calculations between multiple field values in the same record, supporting both Math.js and Excel formula functions.": "可以配置并存储同一条记录的多字段值之间的计算结果,支持 Math.js 和 Excel formula functions 两种引擎。",
|
|
4
|
+
"Expression": "表达式",
|
|
5
|
+
"Expression syntax error": "表达式语法错误",
|
|
6
|
+
"Formula": "公式",
|
|
7
|
+
"Syntax references": "语法参考"
|
|
8
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BaseFieldOptions, Field } from '@tachybase/database';
|
|
2
|
+
export interface FormulaFieldOptions extends BaseFieldOptions {
|
|
3
|
+
type: 'formula';
|
|
4
|
+
engine: string;
|
|
5
|
+
expression: string;
|
|
6
|
+
}
|
|
7
|
+
export declare class FormulaField extends Field {
|
|
8
|
+
get dataType(): any;
|
|
9
|
+
calculate(scope: any): any;
|
|
10
|
+
initFieldData: ({ transaction }: {
|
|
11
|
+
transaction: any;
|
|
12
|
+
}) => Promise<void>;
|
|
13
|
+
calculateField: (instance: any) => Promise<void>;
|
|
14
|
+
updateFieldData: (instance: any, { transaction }: {
|
|
15
|
+
transaction: any;
|
|
16
|
+
}) => Promise<void>;
|
|
17
|
+
bind(): void;
|
|
18
|
+
unbind(): void;
|
|
19
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var field_formula_exports = {};
|
|
19
|
+
__export(field_formula_exports, {
|
|
20
|
+
FormulaField: () => FormulaField
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(field_formula_exports);
|
|
23
|
+
var import_database = require("@tachybase/database");
|
|
24
|
+
var import_evaluators = require("@tachybase/evaluators");
|
|
25
|
+
var import_utils = require("../utils");
|
|
26
|
+
const DataTypeMap = {
|
|
27
|
+
boolean: import_database.DataTypes.BOOLEAN,
|
|
28
|
+
integer: import_database.DataTypes.INTEGER,
|
|
29
|
+
bigInt: import_database.DataTypes.BIGINT,
|
|
30
|
+
double: import_database.DataTypes.DOUBLE,
|
|
31
|
+
decimal: import_database.DataTypes.DECIMAL,
|
|
32
|
+
string: import_database.DataTypes.STRING,
|
|
33
|
+
date: import_database.DataTypes.DATE(3)
|
|
34
|
+
};
|
|
35
|
+
class FormulaField extends import_database.Field {
|
|
36
|
+
get dataType() {
|
|
37
|
+
const { dataType } = this.options;
|
|
38
|
+
return DataTypeMap[dataType] ?? import_database.DataTypes.DOUBLE;
|
|
39
|
+
}
|
|
40
|
+
calculate(scope) {
|
|
41
|
+
const { expression, engine = "math.js", dataType = "double" } = this.options;
|
|
42
|
+
const evaluate = import_evaluators.evaluators.get(engine);
|
|
43
|
+
try {
|
|
44
|
+
const result = evaluate(expression, scope);
|
|
45
|
+
return (0, import_utils.toDbType)(result, dataType);
|
|
46
|
+
} catch (e) {
|
|
47
|
+
console.error(e);
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
initFieldData = async ({ transaction }) => {
|
|
52
|
+
const { name } = this.options;
|
|
53
|
+
const records = await this.collection.repository.find({
|
|
54
|
+
order: [this.collection.model.primaryKeyAttribute],
|
|
55
|
+
transaction
|
|
56
|
+
});
|
|
57
|
+
for (const record of records) {
|
|
58
|
+
const scope = record.toJSON();
|
|
59
|
+
const result = this.calculate(scope);
|
|
60
|
+
if (result != null) {
|
|
61
|
+
await record.update(
|
|
62
|
+
{
|
|
63
|
+
[name]: result
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
transaction,
|
|
67
|
+
silent: true,
|
|
68
|
+
hooks: false
|
|
69
|
+
}
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
calculateField = async (instance) => {
|
|
75
|
+
const { name } = this.options;
|
|
76
|
+
const result = this.calculate(instance.toJSON());
|
|
77
|
+
instance.set(name, result);
|
|
78
|
+
};
|
|
79
|
+
updateFieldData = async (instance, { transaction }) => {
|
|
80
|
+
if (this.collection.name !== instance.collectionName || instance.name !== this.options.name) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
this.options = Object.assign(this.options, instance.options);
|
|
84
|
+
const { name } = this.options;
|
|
85
|
+
const records = await this.collection.repository.find({
|
|
86
|
+
order: [this.collection.model.primaryKeyAttribute],
|
|
87
|
+
transaction
|
|
88
|
+
});
|
|
89
|
+
for (const record of records) {
|
|
90
|
+
const scope = record.toJSON();
|
|
91
|
+
const result = this.calculate(scope);
|
|
92
|
+
await record.update(
|
|
93
|
+
{
|
|
94
|
+
[name]: result
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
transaction,
|
|
98
|
+
silent: true,
|
|
99
|
+
hooks: false
|
|
100
|
+
}
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
bind() {
|
|
105
|
+
super.bind();
|
|
106
|
+
this.database.on("fields.afterUpdate", this.updateFieldData);
|
|
107
|
+
this.on("beforeSave", this.calculateField);
|
|
108
|
+
}
|
|
109
|
+
unbind() {
|
|
110
|
+
super.unbind();
|
|
111
|
+
this.off("beforeSave", this.calculateField);
|
|
112
|
+
this.database.off("fields.afterUpdate", this.updateFieldData);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
116
|
+
0 && (module.exports = {
|
|
117
|
+
FormulaField
|
|
118
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './plugin';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var server_exports = {};
|
|
29
|
+
__export(server_exports, {
|
|
30
|
+
default: () => import_plugin.default
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(server_exports);
|
|
33
|
+
var import_plugin = __toESM(require("./plugin"));
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var alter_field_exports = {};
|
|
19
|
+
__export(alter_field_exports, {
|
|
20
|
+
default: () => alter_field_default
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(alter_field_exports);
|
|
23
|
+
var import_server = require("@tachybase/server");
|
|
24
|
+
class alter_field_default extends import_server.Migration {
|
|
25
|
+
appVersion = "<=0.9.0-alpha.3";
|
|
26
|
+
async up() {
|
|
27
|
+
const result = await this.app.version.satisfies("<=0.9.0-alpha.3");
|
|
28
|
+
if (!result) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const { db } = this.context;
|
|
32
|
+
await db.sequelize.transaction(async (transaction) => {
|
|
33
|
+
const Field = db.getRepository("fields");
|
|
34
|
+
const fields = await Field.find({ transaction });
|
|
35
|
+
for (const field of fields) {
|
|
36
|
+
if (["mathFormula", "excelFormula"].includes(field.get("type"))) {
|
|
37
|
+
const { options } = field;
|
|
38
|
+
field.set({
|
|
39
|
+
type: "formula",
|
|
40
|
+
interface: "formula",
|
|
41
|
+
options: {
|
|
42
|
+
...options,
|
|
43
|
+
engine: field.get("type") === "mathFormula" ? "math.js" : "formula.js",
|
|
44
|
+
dataType: options.dataType === "number" ? "double" : "string"
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
await field.save({ transaction });
|
|
48
|
+
const schema = await field.getUiSchema({ transaction });
|
|
49
|
+
schema.set("x-component", "Formula.Result");
|
|
50
|
+
await schema.save({ transaction });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const repository = db.getRepository("applicationPlugins");
|
|
54
|
+
await repository.destroy({
|
|
55
|
+
filter: {
|
|
56
|
+
name: ["math-formula-field", "excel-formula-field"]
|
|
57
|
+
},
|
|
58
|
+
transaction
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { InstallOptions, Plugin } from '@tachybase/server';
|
|
2
|
+
export declare class FormulaFieldPlugin extends Plugin {
|
|
3
|
+
afterAdd(): void;
|
|
4
|
+
beforeLoad(): void;
|
|
5
|
+
load(): Promise<void>;
|
|
6
|
+
install(options?: InstallOptions): Promise<void>;
|
|
7
|
+
afterEnable(): Promise<void>;
|
|
8
|
+
afterDisable(): Promise<void>;
|
|
9
|
+
remove(): Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
export default FormulaFieldPlugin;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var plugin_exports = {};
|
|
19
|
+
__export(plugin_exports, {
|
|
20
|
+
FormulaFieldPlugin: () => FormulaFieldPlugin,
|
|
21
|
+
default: () => plugin_default
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(plugin_exports);
|
|
24
|
+
var import_path = require("path");
|
|
25
|
+
var import_server = require("@tachybase/server");
|
|
26
|
+
var import_field_formula = require("./field-formula");
|
|
27
|
+
class FormulaFieldPlugin extends import_server.Plugin {
|
|
28
|
+
afterAdd() {
|
|
29
|
+
}
|
|
30
|
+
beforeLoad() {
|
|
31
|
+
this.db.registerFieldTypes({
|
|
32
|
+
formula: import_field_formula.FormulaField
|
|
33
|
+
});
|
|
34
|
+
this.db.addMigrations({
|
|
35
|
+
namespace: this.name,
|
|
36
|
+
directory: (0, import_path.resolve)(__dirname, "./migrations"),
|
|
37
|
+
context: {
|
|
38
|
+
plugin: this
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
async load() {
|
|
43
|
+
}
|
|
44
|
+
async install(options) {
|
|
45
|
+
}
|
|
46
|
+
async afterEnable() {
|
|
47
|
+
}
|
|
48
|
+
async afterDisable() {
|
|
49
|
+
}
|
|
50
|
+
async remove() {
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
var plugin_default = FormulaFieldPlugin;
|
|
54
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
55
|
+
0 && (module.exports = {
|
|
56
|
+
FormulaFieldPlugin
|
|
57
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export declare const DataTypeTransformers: {
|
|
2
|
+
boolean: BooleanConstructor;
|
|
3
|
+
integer: {
|
|
4
|
+
boolean(value: boolean): number;
|
|
5
|
+
number(value: number): number;
|
|
6
|
+
bigint(value: bigint): number;
|
|
7
|
+
string(value: string): number;
|
|
8
|
+
date(value: Date): number;
|
|
9
|
+
};
|
|
10
|
+
bigInt: {
|
|
11
|
+
boolean(value: boolean): number;
|
|
12
|
+
number(value: number): number;
|
|
13
|
+
bigint(value: bigint): number;
|
|
14
|
+
string(value: string): number;
|
|
15
|
+
date(value: Date): number;
|
|
16
|
+
};
|
|
17
|
+
double: {
|
|
18
|
+
boolean(value: boolean): number;
|
|
19
|
+
number(value: number): number;
|
|
20
|
+
bigint(value: bigint): number;
|
|
21
|
+
string(value: string): number;
|
|
22
|
+
date(value: Date): number;
|
|
23
|
+
};
|
|
24
|
+
decimal: {
|
|
25
|
+
boolean(value: boolean): number;
|
|
26
|
+
number(value: number): number;
|
|
27
|
+
bigint(value: bigint): bigint;
|
|
28
|
+
date(value: Date): number;
|
|
29
|
+
};
|
|
30
|
+
string: {
|
|
31
|
+
boolean(value: boolean): string;
|
|
32
|
+
number(value: number): string;
|
|
33
|
+
bigint(value: bigint): string;
|
|
34
|
+
string(value: string): string;
|
|
35
|
+
date(value: Date): string;
|
|
36
|
+
};
|
|
37
|
+
date: {
|
|
38
|
+
boolean(value: boolean): any;
|
|
39
|
+
number(value: number): Date;
|
|
40
|
+
bigint(value: bigint): Date;
|
|
41
|
+
string(value: string): Date;
|
|
42
|
+
date(value: Date): Date;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
export declare function toDbType(value: any, type: string): any;
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var utils_exports = {};
|
|
19
|
+
__export(utils_exports, {
|
|
20
|
+
DataTypeTransformers: () => DataTypeTransformers,
|
|
21
|
+
toDbType: () => toDbType
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(utils_exports);
|
|
24
|
+
const DataTypeTransformers = {
|
|
25
|
+
boolean: Boolean,
|
|
26
|
+
integer: {
|
|
27
|
+
boolean(value) {
|
|
28
|
+
return Number(value);
|
|
29
|
+
},
|
|
30
|
+
number(value) {
|
|
31
|
+
return value >= 0 ? Math.floor(value) : Math.ceil(value);
|
|
32
|
+
},
|
|
33
|
+
bigint(value) {
|
|
34
|
+
return Number(value);
|
|
35
|
+
},
|
|
36
|
+
string(value) {
|
|
37
|
+
const result = Number.parseInt(value, 10);
|
|
38
|
+
if (Number.isNaN(result) || !Number.isFinite(result)) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
return result;
|
|
42
|
+
},
|
|
43
|
+
date(value) {
|
|
44
|
+
const result = value.valueOf();
|
|
45
|
+
if (Number.isNaN(result)) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
bigInt: {
|
|
52
|
+
boolean(value) {
|
|
53
|
+
return Number(value);
|
|
54
|
+
},
|
|
55
|
+
number(value) {
|
|
56
|
+
return Math.floor(value >= 0 ? Math.floor(value) : Math.ceil(value));
|
|
57
|
+
},
|
|
58
|
+
bigint(value) {
|
|
59
|
+
return Number(value);
|
|
60
|
+
},
|
|
61
|
+
string(value) {
|
|
62
|
+
const result = Number.parseInt(value, 10);
|
|
63
|
+
if (Number.isNaN(result) || !Number.isFinite(result)) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
return result;
|
|
67
|
+
},
|
|
68
|
+
date(value) {
|
|
69
|
+
const result = value.valueOf();
|
|
70
|
+
if (Number.isNaN(result)) {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
double: {
|
|
77
|
+
boolean(value) {
|
|
78
|
+
return Number(value);
|
|
79
|
+
},
|
|
80
|
+
number(value) {
|
|
81
|
+
return value;
|
|
82
|
+
},
|
|
83
|
+
bigint(value) {
|
|
84
|
+
return Number(value);
|
|
85
|
+
},
|
|
86
|
+
string(value) {
|
|
87
|
+
const result = Number.parseFloat(value);
|
|
88
|
+
if (Number.isNaN(result) || !Number.isFinite(result)) {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
return result;
|
|
92
|
+
},
|
|
93
|
+
date(value) {
|
|
94
|
+
const result = value.valueOf();
|
|
95
|
+
if (Number.isNaN(result)) {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
return result;
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
decimal: {
|
|
102
|
+
boolean(value) {
|
|
103
|
+
return Number(value);
|
|
104
|
+
},
|
|
105
|
+
number(value) {
|
|
106
|
+
return value;
|
|
107
|
+
},
|
|
108
|
+
bigint(value) {
|
|
109
|
+
return value;
|
|
110
|
+
},
|
|
111
|
+
date(value) {
|
|
112
|
+
const result = value.valueOf();
|
|
113
|
+
if (Number.isNaN(result)) {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
return result;
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
string: {
|
|
120
|
+
boolean(value) {
|
|
121
|
+
return value.toString();
|
|
122
|
+
},
|
|
123
|
+
number(value) {
|
|
124
|
+
return value.toString();
|
|
125
|
+
},
|
|
126
|
+
bigint(value) {
|
|
127
|
+
return value.toString();
|
|
128
|
+
},
|
|
129
|
+
string(value) {
|
|
130
|
+
return value;
|
|
131
|
+
},
|
|
132
|
+
date(value) {
|
|
133
|
+
return value.toISOString();
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
date: {
|
|
137
|
+
boolean(value) {
|
|
138
|
+
return null;
|
|
139
|
+
},
|
|
140
|
+
number(value) {
|
|
141
|
+
const result = new Date(value);
|
|
142
|
+
if (Number.isNaN(result.valueOf())) {
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
return result;
|
|
146
|
+
},
|
|
147
|
+
bigint(value) {
|
|
148
|
+
const result = new Date(Number(value));
|
|
149
|
+
if (Number.isNaN(result.valueOf())) {
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
return result;
|
|
153
|
+
},
|
|
154
|
+
string(value) {
|
|
155
|
+
const ts = Date.parse(value);
|
|
156
|
+
if (Number.isNaN(ts)) {
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
return new Date(ts);
|
|
160
|
+
},
|
|
161
|
+
date(value) {
|
|
162
|
+
return new Date(value);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
function toDbType(value, type) {
|
|
167
|
+
if (value == null) {
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
let jsType = typeof value;
|
|
171
|
+
if (jsType == "object" && value instanceof Date) {
|
|
172
|
+
jsType = "date";
|
|
173
|
+
}
|
|
174
|
+
const transformers = DataTypeTransformers[type];
|
|
175
|
+
if (!transformers) {
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
if (typeof transformers === "function") {
|
|
179
|
+
return transformers(value);
|
|
180
|
+
}
|
|
181
|
+
const transformer = transformers[jsType];
|
|
182
|
+
return transformer ? transformer(value) : null;
|
|
183
|
+
}
|
|
184
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
185
|
+
0 && (module.exports = {
|
|
186
|
+
DataTypeTransformers,
|
|
187
|
+
toDbType
|
|
188
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tachybase/plugin-field-formula",
|
|
3
|
+
"displayName": "Field: Formula",
|
|
4
|
+
"version": "0.23.8",
|
|
5
|
+
"description": "Configure and store the results of calculations between multiple field values in the same record, supporting both Math.js and Excel formula functions.",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"Collection fields"
|
|
8
|
+
],
|
|
9
|
+
"license": "Apache-2.0",
|
|
10
|
+
"main": "./dist/server/index.js",
|
|
11
|
+
"devDependencies": {
|
|
12
|
+
"react": "^18.3.1",
|
|
13
|
+
"react-i18next": "^15.2.0",
|
|
14
|
+
"@tachybase/schema": "0.23.8",
|
|
15
|
+
"@tachybase/components": "0.23.8"
|
|
16
|
+
},
|
|
17
|
+
"peerDependencies": {
|
|
18
|
+
"@tachybase/client": "0.23.8",
|
|
19
|
+
"@tachybase/database": "0.23.8",
|
|
20
|
+
"@tachybase/evaluators": "0.23.8",
|
|
21
|
+
"@tachybase/server": "0.23.8",
|
|
22
|
+
"@tachybase/test": "0.23.8",
|
|
23
|
+
"@tachybase/utils": "0.23.8"
|
|
24
|
+
},
|
|
25
|
+
"description.zh-CN": "可以配置并存储同一条记录的多字段值之间的计算结果,支持 Math.js 和 Excel formula functions 两种引擎",
|
|
26
|
+
"displayName.zh-CN": "数据表字段:公式",
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tachybase-build --no-dts @tachybase/plugin-field-formula"
|
|
29
|
+
}
|
|
30
|
+
}
|
package/server.d.ts
ADDED
package/server.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/server/index.js');
|