@nocobase/plugin-field-formula 1.2.12-alpha → 1.3.0-alpha.20240710084543

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/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "displayName.zh-CN": "数据表字段:公式",
5
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
6
  "description.zh-CN": "可以配置并存储同一条记录的多字段值之间的计算结果,支持 Math.js 和 Excel formula functions 两种引擎",
7
- "version": "1.2.12-alpha",
7
+ "version": "1.3.0-alpha.20240710084543",
8
8
  "license": "AGPL-3.0",
9
9
  "main": "./dist/server/index.js",
10
10
  "homepage": "https://docs.nocobase.com/handbook/field-formula",
@@ -25,7 +25,7 @@
25
25
  "@nocobase/test": "1.x",
26
26
  "@nocobase/utils": "1.x"
27
27
  },
28
- "gitHead": "553231d4882496cb7f1f17fa7541899ce82a27ab",
28
+ "gitHead": "07a8b596fc64a9779a194cb9b0dc2ca7570ed9d4",
29
29
  "keywords": [
30
30
  "Collection fields"
31
31
  ]
@@ -1,10 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
- import { SchemaSettings } from '@nocobase/client';
10
- export declare const FormulaComponentFieldSettings: SchemaSettings<{}>;
@@ -1,11 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
- import React from 'react';
10
- export declare const Expression: (props: any) => React.JSX.Element;
11
- export default Expression;
@@ -1,12 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
- import React from 'react';
10
- export declare function useTargetCollectionField(schema?: any): any;
11
- export declare function Result(props: any): React.JSX.Element;
12
- export default Result;
@@ -1,15 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
- /// <reference types="react" />
10
- export declare const Formula: {
11
- (): any;
12
- Expression: (props: any) => import("react").JSX.Element;
13
- Result: import("react").ForwardRefExoticComponent<Omit<Partial<any>, "ref"> & import("react").RefAttributes<unknown>>;
14
- };
15
- export default Formula;
@@ -1,9 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
- export { Formula } from './Formula';
@@ -1,13 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
- import { Plugin } from '@nocobase/client';
10
- export declare class PluginFieldFormulaClient extends Plugin {
11
- load(): Promise<void>;
12
- }
13
- export default PluginFieldFormulaClient;
@@ -1,17 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- (function(n,r){typeof exports=="object"&&typeof module!="undefined"?r(exports,require("@nocobase/client"),require("@formily/react"),require("react/jsx-runtime"),require("@formily/core"),require("@formily/reactive"),require("@nocobase/evaluators/client"),require("@nocobase/utils/client"),require("react"),require("react-i18next")):typeof define=="function"&&define.amd?define(["exports","@nocobase/client","@formily/react","react/jsx-runtime","@formily/core","@formily/reactive","@nocobase/evaluators/client","@nocobase/utils/client","react","react-i18next"],r):(n=typeof globalThis!="undefined"?globalThis:n||self,r(n["@nocobase/plugin-field-formula"]={},n["@nocobase/client"],n["@formily/react"],n.jsxRuntime,n["@formily/core"],n["@formily/reactive"],n["@nocobase/evaluators"],n["@nocobase/utils"],n.react))})(this,function(n,r,o,s,I,E,x,b,c){"use strict";var ce=Object.defineProperty,me=Object.defineProperties;var de=Object.getOwnPropertyDescriptors;var D=Object.getOwnPropertySymbols;var J=Object.prototype.hasOwnProperty,U=Object.prototype.propertyIsEnumerable;var R=(n,r,o)=>r in n?ce(n,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[r]=o,y=(n,r)=>{for(var o in r||(r={}))J.call(r,o)&&R(n,o,r[o]);if(D)for(var o of D(r))U.call(r,o)&&R(n,o,r[o]);return n},v=(n,r)=>me(n,de(r));var z=(n,r)=>{var o={};for(var s in n)J.call(n,s)&&r.indexOf(s)<0&&(o[s]=n[s]);if(n!=null&&D)for(var s of D(n))r.indexOf(s)<0&&U.call(n,s)&&(o[s]=n[s]);return o};var l=(n,r,o)=>(R(n,typeof r!="symbol"?r+"":r,o),o);var H=(n,r,o)=>new Promise((s,I)=>{var E=c=>{try{b(o.next(c))}catch(C){I(C)}},x=c=>{try{b(o.throw(c))}catch(C){I(C)}},b=c=>c.done?s(c.value):Promise.resolve(c.value).then(E,x);b((o=o.apply(n,r)).next())});const C=e=>{var S;const{value:t="",supports:i=[],useCurrentFields:a,onChange:u}=e,h=r.useCompile(),{interfaces:d}=r.useCollectionManager_deprecated(),f=((S=a==null?void 0:a())!=null?S:[]).filter(m=>i.includes(m.interface)).map(m=>{var q,F;return{label:h(m.uiSchema.title),value:m.name,children:(F=(q=d[m.interface]).usePathOptions)==null?void 0:F.call(q,m)}});return s.jsx(r.Variable.TextArea,{value:t,onChange:u,scope:f})},K={boolean:Boolean,integer:{boolean(e){return Number(e)},number(e){return e>=0?Math.floor(e):Math.ceil(e)},bigint(e){return Number(e)},string(e){const t=Number.parseInt(e,10);return Number.isNaN(t)||!Number.isFinite(t)?null:t},date(e){const t=e.valueOf();return Number.isNaN(t)?null:t}},bigInt:{boolean(e){return Number(e)},number(e){return Math.floor(e>=0?Math.floor(e):Math.ceil(e))},bigint(e){return Number(e)},string(e){const t=Number.parseInt(e,10);return Number.isNaN(t)||!Number.isFinite(t)?null:t},date(e){const t=e.valueOf();return Number.isNaN(t)?null:t}},double:{boolean(e){return Number(e)},number(e){return e},bigint(e){return Number(e)},string(e){const t=Number.parseFloat(e);return Number.isNaN(t)||!Number.isFinite(t)?null:t},date(e){const t=e.valueOf();return Number.isNaN(t)?null:t}},decimal:{boolean(e){return Number(e)},number(e){return e},bigint(e){return e},date(e){const t=e.valueOf();return Number.isNaN(t)?null:t}},string:{boolean(e){return e.toString()},number(e){return e.toString()},bigint(e){return e.toString()},string(e){return e},date(e){return e.toISOString()}},date:{boolean(e){return null},number(e){const t=new Date(e);return Number.isNaN(t.valueOf())?null:t},bigint(e){const t=new Date(Number(e));return Number.isNaN(t.valueOf())?null:t},string(e){const t=Date.parse(e);return Number.isNaN(t)?null:new Date(t)},date(e){return new Date(e)}}};function L(e,t){if(e==null)return null;let i=typeof e;i=="object"&&e instanceof Date&&(i="date");const a=K[t];if(!a)return null;if(typeof a=="function")return a(e);const u=a[i];return u?u(e):null}const Q={boolean:r.Checkbox.ReadPretty,integer:r.InputNumber.ReadPretty,bigInt:r.InputNumber.ReadPretty,double:r.InputNumber.ReadPretty,decimal:r.InputNumber.ReadPretty,date:r.DatePicker.ReadPretty,string:r.Input.ReadPretty};function j(e){const t=o.useFieldSchema(),i=e||t,a=r.useCollection_deprecated(),{getCollection:u,getCollectionField:h}=r.useCollectionManager_deprecated(),d=i.name.split(".");let p=a;for(let f=0;f<d.length-1;f++){const S=p.getField(d[f]);p=u(S.target)}return h(`${p.name}.${d[d.length-1]}`)}function W(e,t,i){const a=e[t];return Array.isArray(a)?a[i]:a&&typeof a=="object"?a:e}function X(e){var k,_,B;const V=e,{value:t}=V,i=z(V,["value"]),a=o.useFieldSchema(),{dataType:u,expression:h,engine:d="math.js"}=(k=j())!=null?k:{},[p,f]=c.useState(t),{evaluate:S}=x.evaluators.get(d),m=r.useFormBlockContext(),F=o.useField().path.entire,A=F==null?void 0:F.replace(`.${a.name}`,""),ae=A.split(".")[0],se=parseInt((_=A.split("."))==null?void 0:_[1]),P=c.useContext(r.ActionContext);c.useEffect(()=>{f(t)},[t]),o.useFormEffects(()=>{I.onFormValuesChange(ue=>{var G,$;if(a.name.indexOf(".")>=0||!(m!=null&&m.form)||(G=m.form)!=null&&G.readPretty||a["x-decorator"]!=="FormItem")return;const le=E.toJS(W(ue.values,ae,se));let g;try{g=S(h,le),g=L(g,u)}catch(pe){g=null}g==null&&p==null&&f(g),f(g),e.onChange(g),($=P==null?void 0:P.setFormValueChanged)==null||$.call(P,!1)})});const ie=(B=Q[u])!=null?B:r.Input;return s.jsx(ie,v(y({},i),{value:u==="double"?b.toFixedByStep(p,e.step):p}))}const M=()=>null;M.Expression=C,M.Result=o.connect(X);const N="field-formula";function Y(e){const t=x.evaluators.get(e);return t!=null&&t.link?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:r.css`
11
- &:after {
12
- content: ':';
13
- }
14
- & + a {
15
- margin-left: 0.25em;
16
- }
17
- `,children:r.i18n.t("Syntax references",{ns:N})}),s.jsx("a",{href:t.link,target:"_blank",rel:"noreferrer",children:t.label})]}):null}const Z=[{dependencies:["dataType"],fulfill:{state:{display:'{{["double", "decimal"].includes($deps[0]) ? "visible" : "none"}}'}}}],O=[{dependencies:["dataType"],fulfill:{state:{display:'{{$deps[0] === "date" ? "visible" : "none"}}'}}}],{defaultProps:ee,dateTimeProps:T,operators:te}=r.interfacesProperties,re={"uiSchema.x-component-props.dateFormat":v(y({},b.lodash.cloneDeep(T["uiSchema.x-component-props.dateFormat"])),{"x-reactions":O}),"uiSchema.x-component-props.showTime":v(y({},b.lodash.cloneDeep(T["uiSchema.x-component-props.showTime"])),{"x-reactions":[...T["uiSchema.x-component-props.showTime"]["x-reactions"],...O]}),"uiSchema.x-component-props.timeFormat":y({},b.lodash.cloneDeep(T["uiSchema.x-component-props.timeFormat"]))};class ne extends r.CollectionFieldInterface{constructor(){super(...arguments);l(this,"name","formula");l(this,"type","object");l(this,"group","advanced");l(this,"order",1);l(this,"title",`{{t("Formula", { ns: "${N}" })}}`);l(this,"description",`{{t("Configure and store the results of calculations between multiple field values in the same record, supporting both Math.js and Excel formula functions.", { ns: "${N}" })}}`);l(this,"sortable",!0);l(this,"default",{type:"formula",uiSchema:{type:"string","x-component":"Formula.Result","x-component-props":{stringMode:!0,step:"1"},"x-read-pretty":!0}});l(this,"properties",v(y(v(y({},ee),{dataType:{type:"string",title:'{{t("Storage type")}}',"x-decorator":"FormItem","x-component":"Select","x-disabled":"{{ !createOnly }}",enum:[{value:"boolean",label:"Boolean"},{value:"integer",label:"Integer"},{value:"bigInt",label:"Big integer"},{value:"double",label:"Double"},{value:"string",label:"String"},{value:"date",label:"Datetime"}],required:!0,default:"double"},"uiSchema.x-component-props.step":{type:"string",title:'{{t("Precision")}}',"x-component":"Select","x-decorator":"FormItem",required:!0,default:"0",enum:[{value:"0",label:"1"},{value:"0.1",label:"1.0"},{value:"0.01",label:"1.00"},{value:"0.001",label:"1.000"},{value:"0.0001",label:"1.0000"},{value:"0.00001",label:"1.00000"}],"x-reactions":Z}}),re),{engine:{type:"string",title:`{{t("Calculation engine", { ns: "${N}" })}}`,"x-decorator":"FormItem","x-component":"Radio.Group",enum:Array.from(x.evaluators.getEntities()).reduce((i,[a,u])=>i.concat(y({value:a},u)),[]),required:!0,default:"math.js"},expression:{type:"string",title:`{{t("Expression", { ns: "${N}" })}}`,required:!0,"x-component":"Formula.Expression","x-decorator":"FormItem","x-component-props":{supports:["checkbox","number","percent","integer","number","percent","input","textarea","email","phone","datetime","createdAt","updatedAt","radioGroup","checkboxGroup","select","multipleSelect"],useCurrentFields:"{{ useCurrentFields }}"},"x-reactions":{dependencies:["engine"],fulfill:{schema:{description:"{{renderExpressionDescription($deps[0])}}"}}},"x-validator"(i,a,{form:u}){const{values:h}=u,{evaluate:d}=x.evaluators.get(h.engine),p=i.trim().replace(/{{\s*([^{}]+)\s*}}/g,"1");try{return d(p),""}catch(f){return r.i18n.t("Expression syntax error",{ns:N})}}}}));l(this,"filterable",{operators:te.number});l(this,"titleUsable",!0)}}const oe=new r.SchemaSettings({name:"fieldSettings:component:Formula.Result",items:[{name:"displayFormat",Component:r.SchemaSettingsNumberFormat,useComponentProps(){const e=o.useFieldSchema(),{fieldSchema:t}=r.useColumnSchema();return{fieldSchema:t||e}},useVisible(){const e=o.useFieldSchema(),{fieldSchema:t}=r.useColumnSchema(),i=t||e,{dataType:a}=j(i)||{},u=["integer","bigInt","double","decimal"].includes(a);return r.useIsFieldReadPretty()&&u}}]});class w extends r.Plugin{load(){return H(this,null,function*(){this.app.addComponents({Formula:M}),this.app.addScopes({renderExpressionDescription:Y}),this.app.dataSourceManager.addFieldInterfaces([ne]),this.app.schemaSettingsManager.add(oe)})}}n.PluginFieldFormulaClient=w,n.default=w,Object.defineProperties(n,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -1,135 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
- import { CollectionFieldInterface } from '@nocobase/client';
10
- export declare class FormulaFieldInterface extends CollectionFieldInterface {
11
- name: string;
12
- type: string;
13
- group: string;
14
- order: number;
15
- title: string;
16
- description: string;
17
- sortable: boolean;
18
- default: {
19
- type: string;
20
- uiSchema: {
21
- type: string;
22
- 'x-component': string;
23
- 'x-component-props': {
24
- stringMode: boolean;
25
- step: string;
26
- };
27
- 'x-read-pretty': boolean;
28
- };
29
- };
30
- properties: {
31
- engine: {
32
- type: string;
33
- title: string;
34
- 'x-decorator': string;
35
- 'x-component': string;
36
- enum: unknown;
37
- required: boolean;
38
- default: string;
39
- };
40
- expression: {
41
- type: string;
42
- title: string;
43
- required: boolean;
44
- 'x-component': string;
45
- 'x-decorator': string;
46
- 'x-component-props': {
47
- supports: string[];
48
- useCurrentFields: string;
49
- };
50
- 'x-reactions': {
51
- dependencies: string[];
52
- fulfill: {
53
- schema: {
54
- description: string;
55
- };
56
- };
57
- };
58
- "x-validator"(value: any, rules: any, { form }: {
59
- form: any;
60
- }): string;
61
- };
62
- 'uiSchema.x-component-props.dateFormat': any;
63
- 'uiSchema.x-component-props.showTime': any;
64
- 'uiSchema.x-component-props.timeFormat': any;
65
- dataType: {
66
- type: string;
67
- title: string;
68
- 'x-decorator': string;
69
- 'x-component': string;
70
- 'x-disabled': string;
71
- enum: {
72
- value: string;
73
- label: string;
74
- }[];
75
- required: boolean;
76
- default: string;
77
- };
78
- 'uiSchema.x-component-props.step': {
79
- type: string;
80
- title: string;
81
- 'x-component': string;
82
- 'x-decorator': string;
83
- required: boolean;
84
- default: string;
85
- enum: {
86
- value: string;
87
- label: string;
88
- }[];
89
- 'x-reactions': {
90
- dependencies: string[];
91
- fulfill: {
92
- state: {
93
- display: string;
94
- };
95
- };
96
- }[];
97
- };
98
- 'uiSchema.title': {
99
- type: string;
100
- title: string;
101
- required: boolean;
102
- 'x-decorator': string;
103
- 'x-component': string;
104
- };
105
- name: {
106
- type: string;
107
- title: string;
108
- required: boolean;
109
- 'x-disabled': string;
110
- 'x-decorator': string;
111
- 'x-component': string;
112
- 'x-validator': string;
113
- description: string;
114
- };
115
- };
116
- filterable: {
117
- operators: ({
118
- label: string;
119
- value: string;
120
- selected: boolean;
121
- noValue?: undefined;
122
- } | {
123
- label: string;
124
- value: string;
125
- selected?: undefined;
126
- noValue?: undefined;
127
- } | {
128
- label: string;
129
- value: string;
130
- noValue: boolean;
131
- selected?: undefined;
132
- })[];
133
- };
134
- titleUsable: boolean;
135
- }
@@ -1,11 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
- export declare const NAMESPACE = "field-formula";
10
- export declare function lang(key: string, options?: {}): string;
11
- export declare function usePluginTranslation(): import("react-i18next").UseTranslationResponse<"field-formula", undefined>;
@@ -1,10 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
- import React from 'react';
10
- export declare function renderExpressionDescription(key: string): React.JSX.Element;
@@ -1,22 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- module.exports = {
11
- "@formily/react": "2.3.0",
12
- "@nocobase/client": "1.2.12-alpha",
13
- "@nocobase/evaluators": "1.2.12-alpha",
14
- "@nocobase/utils": "1.2.12-alpha",
15
- "react": "18.2.0",
16
- "@nocobase/database": "1.2.12-alpha",
17
- "@nocobase/server": "1.2.12-alpha",
18
- "@nocobase/test": "1.2.12-alpha",
19
- "react-i18next": "11.18.6",
20
- "@formily/core": "2.3.0",
21
- "@formily/reactive": "2.3.0"
22
- };
package/dist/index.d.ts DELETED
@@ -1,10 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
- export * from './server';
10
- export { default } from './server';
package/dist/index.js DELETED
@@ -1,48 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- var __create = Object.create;
11
- var __defProp = Object.defineProperty;
12
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
- var __getOwnPropNames = Object.getOwnPropertyNames;
14
- var __getProtoOf = Object.getPrototypeOf;
15
- var __hasOwnProp = Object.prototype.hasOwnProperty;
16
- var __export = (target, all) => {
17
- for (var name in all)
18
- __defProp(target, name, { get: all[name], enumerable: true });
19
- };
20
- var __copyProps = (to, from, except, desc) => {
21
- if (from && typeof from === "object" || typeof from === "function") {
22
- for (let key of __getOwnPropNames(from))
23
- if (!__hasOwnProp.call(to, key) && key !== except)
24
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
25
- }
26
- return to;
27
- };
28
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
29
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
30
- // If the importer is in node compatibility mode or this is not an ESM
31
- // file that has been converted to a CommonJS file using a Babel-
32
- // compatible transform (i.e. "__esModule" has not been set), then set
33
- // "default" to the CommonJS "module.exports" for node compatibility.
34
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
35
- mod
36
- ));
37
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
- var src_exports = {};
39
- __export(src_exports, {
40
- default: () => import_server.default
41
- });
42
- module.exports = __toCommonJS(src_exports);
43
- __reExport(src_exports, require("./server"), module.exports);
44
- var import_server = __toESM(require("./server"));
45
- // Annotate the CommonJS export names for ESM import in node:
46
- 0 && (module.exports = {
47
- ...require("./server")
48
- });
@@ -1,8 +0,0 @@
1
- {
2
- "Formula": "Formula",
3
- "Calculation engine": "Calculation engine",
4
- "Expression": "Expression",
5
- "Expression syntax error": "Expression syntax error",
6
- "Syntax references": "Syntax references",
7
- "Compute a value based on the other fields": "Compute a value based on the other fields"
8
- }
@@ -1,8 +0,0 @@
1
- {
2
- "Formula": "수식",
3
- "Calculation engine": "계산 엔진",
4
- "Expression": "표현식",
5
- "Expression syntax error": "표현식 구문 오류",
6
- "Syntax references": "구문 참조",
7
- "Compute a value based on the other fields": "다른 필드를 기반으로 값 계산"
8
- }
@@ -1,8 +0,0 @@
1
- {
2
- "Formula": "公式",
3
- "Calculation engine": "计算引擎",
4
- "Expression": "表达式",
5
- "Expression syntax error": "表达式语法错误",
6
- "Syntax references": "语法参考",
7
- "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 两种引擎。"
8
- }
@@ -1,27 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
- import { BaseFieldOptions, Field } from '@nocobase/database';
10
- export interface FormulaFieldOptions extends BaseFieldOptions {
11
- type: 'formula';
12
- engine: string;
13
- expression: string;
14
- }
15
- export declare class FormulaField extends Field {
16
- get dataType(): any;
17
- calculate(scope: any): any;
18
- initFieldData: ({ transaction }: {
19
- transaction: any;
20
- }) => Promise<void>;
21
- calculateField: (instance: any) => Promise<void>;
22
- updateFieldData: (instance: any, { transaction }: {
23
- transaction: any;
24
- }) => Promise<void>;
25
- bind(): void;
26
- unbind(): void;
27
- }
@@ -1,127 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- var __defProp = Object.defineProperty;
11
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
- var __getOwnPropNames = Object.getOwnPropertyNames;
13
- var __hasOwnProp = Object.prototype.hasOwnProperty;
14
- var __export = (target, all) => {
15
- for (var name in all)
16
- __defProp(target, name, { get: all[name], enumerable: true });
17
- };
18
- var __copyProps = (to, from, except, desc) => {
19
- if (from && typeof from === "object" || typeof from === "function") {
20
- for (let key of __getOwnPropNames(from))
21
- if (!__hasOwnProp.call(to, key) && key !== except)
22
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
- }
24
- return to;
25
- };
26
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
- var formula_field_exports = {};
28
- __export(formula_field_exports, {
29
- FormulaField: () => FormulaField
30
- });
31
- module.exports = __toCommonJS(formula_field_exports);
32
- var import_database = require("@nocobase/database");
33
- var import_evaluators = require("@nocobase/evaluators");
34
- var import_utils = require("../utils");
35
- const DataTypeMap = {
36
- boolean: import_database.DataTypes.BOOLEAN,
37
- integer: import_database.DataTypes.INTEGER,
38
- bigInt: import_database.DataTypes.BIGINT,
39
- double: import_database.DataTypes.DOUBLE,
40
- decimal: import_database.DataTypes.DECIMAL,
41
- string: import_database.DataTypes.STRING,
42
- date: import_database.DataTypes.DATE(3)
43
- };
44
- class FormulaField extends import_database.Field {
45
- get dataType() {
46
- const { dataType } = this.options;
47
- return DataTypeMap[dataType] ?? import_database.DataTypes.DOUBLE;
48
- }
49
- calculate(scope) {
50
- const { expression, engine = "math.js", dataType = "double" } = this.options;
51
- const evaluate = import_evaluators.evaluators.get(engine);
52
- try {
53
- const result = evaluate(expression, scope);
54
- return (0, import_utils.toDbType)(result, dataType);
55
- } catch (e) {
56
- console.error(e);
57
- }
58
- return null;
59
- }
60
- initFieldData = async ({ transaction }) => {
61
- const { name } = this.options;
62
- const records = await this.collection.repository.find({
63
- order: [this.collection.model.primaryKeyAttribute],
64
- transaction
65
- });
66
- for (const record of records) {
67
- const scope = record.toJSON();
68
- const result = this.calculate(scope);
69
- if (result != null) {
70
- await record.update(
71
- {
72
- [name]: result
73
- },
74
- {
75
- transaction,
76
- silent: true,
77
- hooks: false
78
- }
79
- );
80
- }
81
- }
82
- };
83
- calculateField = async (instance) => {
84
- const { name } = this.options;
85
- const result = this.calculate(instance.toJSON());
86
- instance.set(name, result);
87
- };
88
- updateFieldData = async (instance, { transaction }) => {
89
- if (this.collection.name !== instance.collectionName || instance.name !== this.options.name) {
90
- return;
91
- }
92
- this.options = Object.assign(this.options, instance.options);
93
- const { name } = this.options;
94
- const records = await this.collection.repository.find({
95
- order: [this.collection.model.primaryKeyAttribute],
96
- transaction
97
- });
98
- for (const record of records) {
99
- const scope = record.toJSON();
100
- const result = this.calculate(scope);
101
- await record.update(
102
- {
103
- [name]: result
104
- },
105
- {
106
- transaction,
107
- silent: true,
108
- hooks: false
109
- }
110
- );
111
- }
112
- };
113
- bind() {
114
- super.bind();
115
- this.database.on("fields.afterUpdate", this.updateFieldData);
116
- this.on("beforeSave", this.calculateField);
117
- }
118
- unbind() {
119
- super.unbind();
120
- this.off("beforeSave", this.calculateField);
121
- this.database.off("fields.afterUpdate", this.updateFieldData);
122
- }
123
- }
124
- // Annotate the CommonJS export names for ESM import in node:
125
- 0 && (module.exports = {
126
- FormulaField
127
- });
@@ -1,9 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
- export { default } from './plugin';
@@ -1,42 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- var __create = Object.create;
11
- var __defProp = Object.defineProperty;
12
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
- var __getOwnPropNames = Object.getOwnPropertyNames;
14
- var __getProtoOf = Object.getPrototypeOf;
15
- var __hasOwnProp = Object.prototype.hasOwnProperty;
16
- var __export = (target, all) => {
17
- for (var name in all)
18
- __defProp(target, name, { get: all[name], enumerable: true });
19
- };
20
- var __copyProps = (to, from, except, desc) => {
21
- if (from && typeof from === "object" || typeof from === "function") {
22
- for (let key of __getOwnPropNames(from))
23
- if (!__hasOwnProp.call(to, key) && key !== except)
24
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
25
- }
26
- return to;
27
- };
28
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
29
- // If the importer is in node compatibility mode or this is not an ESM
30
- // file that has been converted to a CommonJS file using a Babel-
31
- // compatible transform (i.e. "__esModule" has not been set), then set
32
- // "default" to the CommonJS "module.exports" for node compatibility.
33
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
34
- mod
35
- ));
36
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
37
- var server_exports = {};
38
- __export(server_exports, {
39
- default: () => import_plugin.default
40
- });
41
- module.exports = __toCommonJS(server_exports);
42
- var import_plugin = __toESM(require("./plugin"));
@@ -1,13 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
- import { Migration } from '@nocobase/server';
10
- export default class extends Migration {
11
- appVersion: string;
12
- up(): Promise<void>;
13
- }
@@ -1,71 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- var __defProp = Object.defineProperty;
11
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
- var __getOwnPropNames = Object.getOwnPropertyNames;
13
- var __hasOwnProp = Object.prototype.hasOwnProperty;
14
- var __export = (target, all) => {
15
- for (var name in all)
16
- __defProp(target, name, { get: all[name], enumerable: true });
17
- };
18
- var __copyProps = (to, from, except, desc) => {
19
- if (from && typeof from === "object" || typeof from === "function") {
20
- for (let key of __getOwnPropNames(from))
21
- if (!__hasOwnProp.call(to, key) && key !== except)
22
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
- }
24
- return to;
25
- };
26
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
- var alter_field_exports = {};
28
- __export(alter_field_exports, {
29
- default: () => alter_field_default
30
- });
31
- module.exports = __toCommonJS(alter_field_exports);
32
- var import_server = require("@nocobase/server");
33
- class alter_field_default extends import_server.Migration {
34
- appVersion = "<=0.9.0-alpha.3";
35
- async up() {
36
- const result = await this.app.version.satisfies("<=0.9.0-alpha.3");
37
- if (!result) {
38
- return;
39
- }
40
- const { db } = this.context;
41
- await db.sequelize.transaction(async (transaction) => {
42
- const Field = db.getRepository("fields");
43
- const fields = await Field.find({ transaction });
44
- for (const field of fields) {
45
- if (["mathFormula", "excelFormula"].includes(field.get("type"))) {
46
- const { options } = field;
47
- field.set({
48
- type: "formula",
49
- interface: "formula",
50
- options: {
51
- ...options,
52
- engine: field.get("type") === "mathFormula" ? "math.js" : "formula.js",
53
- dataType: options.dataType === "number" ? "double" : "string"
54
- }
55
- });
56
- await field.save({ transaction });
57
- const schema = await field.getUiSchema({ transaction });
58
- schema.set("x-component", "Formula.Result");
59
- await schema.save({ transaction });
60
- }
61
- }
62
- const repository = db.getRepository("applicationPlugins");
63
- await repository.destroy({
64
- filter: {
65
- name: ["math-formula-field", "excel-formula-field"]
66
- },
67
- transaction
68
- });
69
- });
70
- }
71
- }
@@ -1,14 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
- import { Migration } from '@nocobase/server';
10
- export default class extends Migration {
11
- on: string;
12
- appVersion: string;
13
- up(): Promise<void>;
14
- }
@@ -1,51 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- var __defProp = Object.defineProperty;
11
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
- var __getOwnPropNames = Object.getOwnPropertyNames;
13
- var __hasOwnProp = Object.prototype.hasOwnProperty;
14
- var __export = (target, all) => {
15
- for (var name in all)
16
- __defProp(target, name, { get: all[name], enumerable: true });
17
- };
18
- var __copyProps = (to, from, except, desc) => {
19
- if (from && typeof from === "object" || typeof from === "function") {
20
- for (let key of __getOwnPropNames(from))
21
- if (!__hasOwnProp.call(to, key) && key !== except)
22
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
- }
24
- return to;
25
- };
26
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
- var change_locale_module_exports = {};
28
- __export(change_locale_module_exports, {
29
- default: () => change_locale_module_default
30
- });
31
- module.exports = __toCommonJS(change_locale_module_exports);
32
- var import_server = require("@nocobase/server");
33
- class change_locale_module_default extends import_server.Migration {
34
- on = "afterLoad";
35
- // 'beforeLoad' or 'afterLoad'
36
- appVersion = "<1.0.0-alpha.1";
37
- async up() {
38
- const repo = this.db.getRepository("localizationTexts");
39
- if (!repo) {
40
- return;
41
- }
42
- await repo.update({
43
- filter: {
44
- module: "resources.formula-field"
45
- },
46
- values: {
47
- module: "resources.field-formula"
48
- }
49
- });
50
- }
51
- }
@@ -1,19 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
- import { InstallOptions, Plugin } from '@nocobase/server';
10
- export declare class PluginFieldFormulaServer extends Plugin {
11
- afterAdd(): void;
12
- beforeLoad(): void;
13
- load(): Promise<void>;
14
- install(options?: InstallOptions): Promise<void>;
15
- afterEnable(): Promise<void>;
16
- afterDisable(): Promise<void>;
17
- remove(): Promise<void>;
18
- }
19
- export default PluginFieldFormulaServer;
@@ -1,66 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- var __defProp = Object.defineProperty;
11
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
- var __getOwnPropNames = Object.getOwnPropertyNames;
13
- var __hasOwnProp = Object.prototype.hasOwnProperty;
14
- var __export = (target, all) => {
15
- for (var name in all)
16
- __defProp(target, name, { get: all[name], enumerable: true });
17
- };
18
- var __copyProps = (to, from, except, desc) => {
19
- if (from && typeof from === "object" || typeof from === "function") {
20
- for (let key of __getOwnPropNames(from))
21
- if (!__hasOwnProp.call(to, key) && key !== except)
22
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
- }
24
- return to;
25
- };
26
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
- var plugin_exports = {};
28
- __export(plugin_exports, {
29
- PluginFieldFormulaServer: () => PluginFieldFormulaServer,
30
- default: () => plugin_default
31
- });
32
- module.exports = __toCommonJS(plugin_exports);
33
- var import_server = require("@nocobase/server");
34
- var import_path = require("path");
35
- var import_formula_field = require("./formula-field");
36
- class PluginFieldFormulaServer extends import_server.Plugin {
37
- afterAdd() {
38
- }
39
- beforeLoad() {
40
- this.db.registerFieldTypes({
41
- formula: import_formula_field.FormulaField
42
- });
43
- this.db.addMigrations({
44
- namespace: this.name,
45
- directory: (0, import_path.resolve)(__dirname, "./migrations"),
46
- context: {
47
- plugin: this
48
- }
49
- });
50
- }
51
- async load() {
52
- }
53
- async install(options) {
54
- }
55
- async afterEnable() {
56
- }
57
- async afterDisable() {
58
- }
59
- async remove() {
60
- }
61
- }
62
- var plugin_default = PluginFieldFormulaServer;
63
- // Annotate the CommonJS export names for ESM import in node:
64
- 0 && (module.exports = {
65
- PluginFieldFormulaServer
66
- });
@@ -1,53 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
- export declare const DataTypeTransformers: {
10
- boolean: BooleanConstructor;
11
- integer: {
12
- boolean(value: boolean): number;
13
- number(value: number): number;
14
- bigint(value: bigint): number;
15
- string(value: string): number;
16
- date(value: Date): number;
17
- };
18
- bigInt: {
19
- boolean(value: boolean): number;
20
- number(value: number): number;
21
- bigint(value: bigint): number;
22
- string(value: string): number;
23
- date(value: Date): number;
24
- };
25
- double: {
26
- boolean(value: boolean): number;
27
- number(value: number): number;
28
- bigint(value: bigint): number;
29
- string(value: string): number;
30
- date(value: Date): number;
31
- };
32
- decimal: {
33
- boolean(value: boolean): number;
34
- number(value: number): number;
35
- bigint(value: bigint): bigint;
36
- date(value: Date): number;
37
- };
38
- string: {
39
- boolean(value: boolean): string;
40
- number(value: number): string;
41
- bigint(value: bigint): string;
42
- string(value: string): string;
43
- date(value: Date): string;
44
- };
45
- date: {
46
- boolean(value: boolean): any;
47
- number(value: number): Date;
48
- bigint(value: bigint): Date;
49
- string(value: string): Date;
50
- date(value: Date): Date;
51
- };
52
- };
53
- export declare function toDbType(value: any, type: string): any;
@@ -1,197 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- var __defProp = Object.defineProperty;
11
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
- var __getOwnPropNames = Object.getOwnPropertyNames;
13
- var __hasOwnProp = Object.prototype.hasOwnProperty;
14
- var __export = (target, all) => {
15
- for (var name in all)
16
- __defProp(target, name, { get: all[name], enumerable: true });
17
- };
18
- var __copyProps = (to, from, except, desc) => {
19
- if (from && typeof from === "object" || typeof from === "function") {
20
- for (let key of __getOwnPropNames(from))
21
- if (!__hasOwnProp.call(to, key) && key !== except)
22
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
- }
24
- return to;
25
- };
26
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
- var utils_exports = {};
28
- __export(utils_exports, {
29
- DataTypeTransformers: () => DataTypeTransformers,
30
- toDbType: () => toDbType
31
- });
32
- module.exports = __toCommonJS(utils_exports);
33
- const DataTypeTransformers = {
34
- boolean: Boolean,
35
- integer: {
36
- boolean(value) {
37
- return Number(value);
38
- },
39
- number(value) {
40
- return value >= 0 ? Math.floor(value) : Math.ceil(value);
41
- },
42
- bigint(value) {
43
- return Number(value);
44
- },
45
- string(value) {
46
- const result = Number.parseInt(value, 10);
47
- if (Number.isNaN(result) || !Number.isFinite(result)) {
48
- return null;
49
- }
50
- return result;
51
- },
52
- date(value) {
53
- const result = value.valueOf();
54
- if (Number.isNaN(result)) {
55
- return null;
56
- }
57
- return result;
58
- }
59
- },
60
- bigInt: {
61
- boolean(value) {
62
- return Number(value);
63
- },
64
- number(value) {
65
- return Math.floor(value >= 0 ? Math.floor(value) : Math.ceil(value));
66
- },
67
- bigint(value) {
68
- return Number(value);
69
- },
70
- string(value) {
71
- const result = Number.parseInt(value, 10);
72
- if (Number.isNaN(result) || !Number.isFinite(result)) {
73
- return null;
74
- }
75
- return result;
76
- },
77
- date(value) {
78
- const result = value.valueOf();
79
- if (Number.isNaN(result)) {
80
- return null;
81
- }
82
- return result;
83
- }
84
- },
85
- double: {
86
- boolean(value) {
87
- return Number(value);
88
- },
89
- number(value) {
90
- return value;
91
- },
92
- bigint(value) {
93
- return Number(value);
94
- },
95
- string(value) {
96
- const result = Number.parseFloat(value);
97
- if (Number.isNaN(result) || !Number.isFinite(result)) {
98
- return null;
99
- }
100
- return result;
101
- },
102
- date(value) {
103
- const result = value.valueOf();
104
- if (Number.isNaN(result)) {
105
- return null;
106
- }
107
- return result;
108
- }
109
- },
110
- decimal: {
111
- boolean(value) {
112
- return Number(value);
113
- },
114
- number(value) {
115
- return value;
116
- },
117
- bigint(value) {
118
- return value;
119
- },
120
- date(value) {
121
- const result = value.valueOf();
122
- if (Number.isNaN(result)) {
123
- return null;
124
- }
125
- return result;
126
- }
127
- },
128
- string: {
129
- boolean(value) {
130
- return value.toString();
131
- },
132
- number(value) {
133
- return value.toString();
134
- },
135
- bigint(value) {
136
- return value.toString();
137
- },
138
- string(value) {
139
- return value;
140
- },
141
- date(value) {
142
- return value.toISOString();
143
- }
144
- },
145
- date: {
146
- boolean(value) {
147
- return null;
148
- },
149
- number(value) {
150
- const result = new Date(value);
151
- if (Number.isNaN(result.valueOf())) {
152
- return null;
153
- }
154
- return result;
155
- },
156
- bigint(value) {
157
- const result = new Date(Number(value));
158
- if (Number.isNaN(result.valueOf())) {
159
- return null;
160
- }
161
- return result;
162
- },
163
- string(value) {
164
- const ts = Date.parse(value);
165
- if (Number.isNaN(ts)) {
166
- return null;
167
- }
168
- return new Date(ts);
169
- },
170
- date(value) {
171
- return new Date(value);
172
- }
173
- }
174
- };
175
- function toDbType(value, type) {
176
- if (value == null) {
177
- return null;
178
- }
179
- let jsType = typeof value;
180
- if (jsType == "object" && value instanceof Date) {
181
- jsType = "date";
182
- }
183
- const transformers = DataTypeTransformers[type];
184
- if (!transformers) {
185
- return null;
186
- }
187
- if (typeof transformers === "function") {
188
- return transformers(value);
189
- }
190
- const transformer = transformers[jsType];
191
- return transformer ? transformer(value) : null;
192
- }
193
- // Annotate the CommonJS export names for ESM import in node:
194
- 0 && (module.exports = {
195
- DataTypeTransformers,
196
- toDbType
197
- });