befly 3.20.0 → 3.20.4

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/LICENSE CHANGED
@@ -1,201 +1,201 @@
1
- Apache License
2
- Version 2.0, January 2004
3
- http://www.apache.org/licenses/
4
-
5
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
-
7
- 1. Definitions.
8
-
9
- "License" shall mean the terms and conditions for use, reproduction,
10
- and distribution as defined by Sections 1 through 9 of this document.
11
-
12
- "Licensor" shall mean the copyright owner or entity authorized by
13
- the copyright owner that is granting the License.
14
-
15
- "Legal Entity" shall mean the union of the acting entity and all
16
- other entities that control, are controlled by, or are under common
17
- control with that entity. For the purposes of this definition,
18
- "control" means (i) the power, direct or indirect, to cause the
19
- direction or management of such entity, whether by contract or
20
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
- outstanding shares, or (iii) beneficial ownership of such entity.
22
-
23
- "You" (or "Your") shall mean an individual or Legal Entity
24
- exercising permissions granted by this License.
25
-
26
- "Source" form shall mean the preferred form for making modifications,
27
- including but not limited to software source code, documentation
28
- source, and configuration files.
29
-
30
- "Object" form shall mean any form resulting from mechanical
31
- transformation or translation of a Source form, including but
32
- not limited to compiled object code, generated documentation,
33
- and conversions to other media types.
34
-
35
- "Work" shall mean the work of authorship, whether in Source or
36
- Object form, made available under the License, as indicated by a
37
- copyright notice that is included in or attached to the work
38
- (an example is provided in the Appendix below).
39
-
40
- "Derivative Works" shall mean any work, whether in Source or Object
41
- form, that is based on (or derived from) the Work and for which the
42
- editorial revisions, annotations, elaborations, or other modifications
43
- represent, as a whole, an original work of authorship. For the purposes
44
- of this License, Derivative Works shall not include works that remain
45
- separable from, or merely link (or bind by name) to the interfaces of,
46
- the Work and Derivative Works thereof.
47
-
48
- "Contribution" shall mean any work of authorship, including
49
- the original version of the Work and any modifications or additions
50
- to that Work or Derivative Works thereof, that is intentionally
51
- submitted to Licensor for inclusion in the Work by the copyright owner
52
- or by an individual or Legal Entity authorized to submit on behalf of
53
- the copyright owner. For the purposes of this definition, "submitted"
54
- means any form of electronic, verbal, or written communication sent
55
- to the Licensor or its representatives, including but not limited to
56
- communication on electronic mailing lists, source code control systems,
57
- and issue tracking systems that are managed by, or on behalf of, the
58
- Licensor for the purpose of discussing and improving the Work, but
59
- excluding communication that is conspicuously marked or otherwise
60
- designated in writing by the copyright owner as "Not a Contribution."
61
-
62
- "Contributor" shall mean Licensor and any individual or Legal Entity
63
- on behalf of whom a Contribution has been received by Licensor and
64
- subsequently incorporated within the Work.
65
-
66
- 2. Grant of Copyright License. Subject to the terms and conditions of
67
- this License, each Contributor hereby grants to You a perpetual,
68
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
- copyright license to reproduce, prepare Derivative Works of,
70
- publicly display, publicly perform, sublicense, and distribute the
71
- Work and such Derivative Works in Source or Object form.
72
-
73
- 3. Grant of Patent License. Subject to the terms and conditions of
74
- this License, each Contributor hereby grants to You a perpetual,
75
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
- (except as stated in this section) patent license to make, have made,
77
- use, offer to sell, sell, import, and otherwise transfer the Work,
78
- where such license applies only to those patent claims licensable
79
- by such Contributor that are necessarily infringed by their
80
- Contribution(s) alone or by combination of their Contribution(s)
81
- with the Work to which such Contribution(s) was submitted. If You
82
- institute patent litigation against any entity (including a
83
- cross-claim or counterclaim in a lawsuit) alleging that the Work
84
- or a Contribution incorporated within the Work constitutes direct
85
- or contributory patent infringement, then any patent licenses
86
- granted to You under this License for that Work shall terminate
87
- as of the date such litigation is filed.
88
-
89
- 4. Redistribution. You may reproduce and distribute copies of the
90
- Work or Derivative Works thereof in any medium, with or without
91
- modifications, and in Source or Object form, provided that You
92
- meet the following conditions:
93
-
94
- (a) You must give any other recipients of the Work or
95
- Derivative Works a copy of this License; and
96
-
97
- (b) You must cause any modified files to carry prominent notices
98
- stating that You changed the files; and
99
-
100
- (c) You must retain, in the Source form of any Derivative Works
101
- that You distribute, all copyright, patent, trademark, and
102
- attribution notices from the Source form of the Work,
103
- excluding those notices that do not pertain to any part of
104
- the Derivative Works; and
105
-
106
- (d) If the Work includes a "NOTICE" text file as part of its
107
- distribution, then any Derivative Works that You distribute must
108
- include a readable copy of the attribution notices contained
109
- within such NOTICE file, excluding those notices that do not
110
- pertain to any part of the Derivative Works, in at least one
111
- of the following places: within a NOTICE text file distributed
112
- as part of the Derivative Works; within the Source form or
113
- documentation, if provided along with the Derivative Works; or,
114
- within a display generated by the Derivative Works, if and
115
- wherever such third-party notices normally appear. The contents
116
- of the NOTICE file are for informational purposes only and
117
- do not modify the License. You may add Your own attribution
118
- notices within Derivative Works that You distribute, alongside
119
- or as an addendum to the NOTICE text from the Work, provided
120
- that such additional attribution notices cannot be construed
121
- as modifying the License.
122
-
123
- You may add Your own copyright statement to Your modifications and
124
- may provide additional or different license terms and conditions
125
- for use, reproduction, or distribution of Your modifications, or
126
- for any such Derivative Works as a whole, provided Your use,
127
- reproduction, and distribution of the Work otherwise complies with
128
- the conditions stated in this License.
129
-
130
- 5. Submission of Contributions. Unless You explicitly state otherwise,
131
- any Contribution intentionally submitted for inclusion in the Work
132
- by You to the Licensor shall be under the terms and conditions of
133
- this License, without any additional terms or conditions.
134
- Notwithstanding the above, nothing herein shall supersede or modify
135
- the terms of any separate license agreement you may have executed
136
- with Licensor regarding such Contributions.
137
-
138
- 6. Trademarks. This License does not grant permission to use the trade
139
- names, trademarks, service marks, or product names of the Licensor,
140
- except as required for reasonable and customary use in describing the
141
- origin of the Work and reproducing the content of the NOTICE file.
142
-
143
- 7. Disclaimer of Warranty. Unless required by applicable law or
144
- agreed to in writing, Licensor provides the Work (and each
145
- Contributor provides its Contributions) on an "AS IS" BASIS,
146
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
- implied, including, without limitation, any warranties or conditions
148
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
- PARTICULAR PURPOSE. You are solely responsible for determining the
150
- appropriateness of using or redistributing the Work and assume any
151
- risks associated with Your exercise of permissions under this License.
152
-
153
- 8. Limitation of Liability. In no event and under no legal theory,
154
- whether in tort (including negligence), contract, or otherwise,
155
- unless required by applicable law (such as deliberate and grossly
156
- negligent acts) or agreed to in writing, shall any Contributor be
157
- liable to You for damages, including any direct, indirect, special,
158
- incidental, or consequential damages of any character arising as a
159
- result of this License or out of the use or inability to use the
160
- Work (including but not limited to damages for loss of goodwill,
161
- work stoppage, computer failure or malfunction, or any and all
162
- other commercial damages or losses), even if such Contributor
163
- has been advised of the possibility of such damages.
164
-
165
- 9. Accepting Warranty or Additional Liability. While redistributing
166
- the Work or Derivative Works thereof, You may choose to offer,
167
- and charge a fee for, acceptance of support, warranty, indemnity,
168
- or other liability obligations and/or rights consistent with this
169
- License. However, in accepting such obligations, You may act only
170
- on Your own behalf and on Your sole responsibility, not on behalf
171
- of any other Contributor, and only if You agree to indemnify,
172
- defend, and hold each Contributor harmless for any liability
173
- incurred by, or claims asserted against, such Contributor by reason
174
- of your accepting any such warranty or additional liability.
175
-
176
- END OF TERMS AND CONDITIONS
177
-
178
- APPENDIX: How to apply the Apache License to your work.
179
-
180
- To apply the Apache License to your work, attach the following
181
- boilerplate notice, with the fields enclosed by brackets "[]"
182
- replaced with your own identifying information. (Don't include
183
- the brackets!) The text should be enclosed in the appropriate
184
- comment syntax for the file format. We also recommend that a
185
- file or class name and description of purpose be included on the
186
- same "printed page" as the copyright notice for easier
187
- identification within third-party archives.
188
-
189
- Copyright [yyyy] [name of copyright owner]
190
-
191
- Licensed under the Apache License, Version 2.0 (the "License");
192
- you may not use this file except in compliance with the License.
193
- You may obtain a copy of the License at
194
-
195
- http://www.apache.org/licenses/LICENSE-2.0
196
-
197
- Unless required by applicable law or agreed to in writing, software
198
- distributed under the License is distributed on an "AS IS" BASIS,
199
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
- See the License for the specific language governing permissions and
201
- limitations under the License.
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/lib/connect.js CHANGED
@@ -42,7 +42,8 @@ export class Connect {
42
42
  database: config.database,
43
43
  username: config.username,
44
44
  password: config.password,
45
- max: config.max
45
+ max: config.max,
46
+ bigint: true
46
47
  };
47
48
 
48
49
  this.mysqlClient = new SQL(sqlConfig);
@@ -2,9 +2,48 @@ import { fieldClear } from "../../utils/fieldClear.js";
2
2
  import { isFiniteNumber, isNonEmptyString, isNullable, isPlainObject, isString } from "../../utils/is.js";
3
3
  import { arrayKeysToCamel, keysToCamel, keysToSnake, snakeCase } from "../../utils/util.js";
4
4
  import { SqlBuilder } from "../sqlBuilder/index.js";
5
- import { convertBigIntFields, getJoinMainQualifier, normalizeTableRef, quoteIdentMySql } from "./util.js";
5
+ import { getJoinMainQualifier, normalizeBigIntValues, normalizeTableRef, quoteIdentMySql } from "./util.js";
6
6
  import { assertNoExprField, validateAndClassifyFields, validateExcludeFieldsResult, validateQueryOptions, validateTimeIdValue } from "./validate.js";
7
7
 
8
+ function shouldExcludeFieldValue(key, value, excludeValueMap) {
9
+ if (!isPlainObject(excludeValueMap)) {
10
+ return false;
11
+ }
12
+
13
+ const excludeValues = excludeValueMap[key];
14
+ if (!Array.isArray(excludeValues) || excludeValues.length === 0) {
15
+ return false;
16
+ }
17
+
18
+ for (const excludeValue of excludeValues) {
19
+ if (Object.is(value, excludeValue)) {
20
+ return true;
21
+ }
22
+ }
23
+
24
+ return false;
25
+ }
26
+
27
+ function mergeExcludeValueMap(parentMap, currentMap) {
28
+ if (!isPlainObject(parentMap) && !isPlainObject(currentMap)) {
29
+ return null;
30
+ }
31
+
32
+ const result = {};
33
+ if (isPlainObject(parentMap)) {
34
+ for (const [key, value] of Object.entries(parentMap)) {
35
+ result[key] = value;
36
+ }
37
+ }
38
+ if (isPlainObject(currentMap)) {
39
+ for (const [key, value] of Object.entries(currentMap)) {
40
+ result[key] = value;
41
+ }
42
+ }
43
+
44
+ return result;
45
+ }
46
+
8
47
  export function clearDeep(value, options) {
9
48
  const arrayObjectKeys = Array.isArray(options?.arrayObjectKeys) ? options.arrayObjectKeys : ["$or", "$and"];
10
49
  const arrayObjectKeySet = new Set();
@@ -15,7 +54,7 @@ export function clearDeep(value, options) {
15
54
  const depthRaw = isFiniteNumber(options?.depth) ? Math.floor(options.depth) : 0;
16
55
  const depth = depthRaw < 0 ? 0 : depthRaw;
17
56
 
18
- const clearInternal = (input, remainingDepth) => {
57
+ const clearInternal = (input, remainingDepth, inheritedExcludeValueMap) => {
19
58
  if (!input || typeof input !== "object") {
20
59
  return input;
21
60
  }
@@ -27,12 +66,21 @@ export function clearDeep(value, options) {
27
66
  const canRecurse = remainingDepth === 0 || remainingDepth > 1;
28
67
  const childDepth = remainingDepth === 0 ? 0 : remainingDepth - 1;
29
68
  const result = {};
69
+ const currentExcludeValueMap = mergeExcludeValueMap(inheritedExcludeValueMap, input.$exclude);
30
70
 
31
71
  for (const [key, item] of Object.entries(input)) {
72
+ if (key === "$exclude") {
73
+ continue;
74
+ }
75
+
32
76
  if (isNullable(item)) {
33
77
  continue;
34
78
  }
35
79
 
80
+ if (shouldExcludeFieldValue(key, item, currentExcludeValueMap)) {
81
+ continue;
82
+ }
83
+
36
84
  if (arrayObjectKeySet.has(key)) {
37
85
  if (!Array.isArray(item)) {
38
86
  continue;
@@ -43,7 +91,7 @@ export function clearDeep(value, options) {
43
91
  if (!child || typeof child !== "object" || Array.isArray(child)) {
44
92
  continue;
45
93
  }
46
- const cleaned = clearInternal(child, remainingDepth);
94
+ const cleaned = clearInternal(child, remainingDepth, currentExcludeValueMap);
47
95
  if (!cleaned || typeof cleaned !== "object" || Array.isArray(cleaned)) {
48
96
  continue;
49
97
  }
@@ -65,7 +113,7 @@ export function clearDeep(value, options) {
65
113
  continue;
66
114
  }
67
115
 
68
- const cleanedObj = clearInternal(item, childDepth);
116
+ const cleanedObj = clearInternal(item, childDepth, currentExcludeValueMap);
69
117
  if (!cleanedObj || typeof cleanedObj !== "object" || Array.isArray(cleanedObj)) {
70
118
  continue;
71
119
  }
@@ -82,7 +130,7 @@ export function clearDeep(value, options) {
82
130
  return result;
83
131
  };
84
132
 
85
- return clearInternal(value, depth);
133
+ return clearInternal(value, depth, options?.excludeValueMap);
86
134
  }
87
135
 
88
136
  export async function fieldsToSnake(table, fields, getTableColumns) {
@@ -542,14 +590,16 @@ export const builderMethods = {
542
590
  this.applyJoins(builder, prepared.joins);
543
591
  const result = builder.toSelectSql();
544
592
  const executeRes = await this.execute(result.sql, result.params);
545
- const total = executeRes.data?.[0]?.total || executeRes.data?.[0]?.count || 0;
593
+ const countRow = executeRes.data?.[0] || null;
594
+ const normalizedCountRow = countRow ? normalizeBigIntValues(countRow) : null;
595
+ const total = normalizedCountRow?.total ?? normalizedCountRow?.count ?? 0;
546
596
  return {
547
597
  total: total,
548
598
  sql: executeRes.sql
549
599
  };
550
600
  },
551
601
 
552
- normalizeRowData(row, bigintFields) {
602
+ normalizeRowData(row) {
553
603
  if (!row) {
554
604
  return {};
555
605
  }
@@ -560,7 +610,7 @@ export const builderMethods = {
560
610
  return {};
561
611
  }
562
612
 
563
- const convertedList = convertBigIntFields([deserialized], bigintFields);
613
+ const convertedList = normalizeBigIntValues([deserialized]);
564
614
  if (convertedList && convertedList.length > 0) {
565
615
  return convertedList[0];
566
616
  }
@@ -568,10 +618,10 @@ export const builderMethods = {
568
618
  return deserialized;
569
619
  },
570
620
 
571
- normalizeListData(list, bigintFields) {
621
+ normalizeListData(list) {
572
622
  const camelList = arrayKeysToCamel(list);
573
623
  const deserializedList = camelList.map((item) => deserializeArrayFields(item)).filter((item) => item !== null);
574
- return convertBigIntFields(deserializedList, bigintFields);
624
+ return normalizeBigIntValues(deserializedList);
575
625
  },
576
626
 
577
627
  normalizeJoinOptions(options, cleanWhere) {
@@ -615,7 +665,6 @@ export const builderMethods = {
615
665
  };
616
666
 
617
667
  if (options.fields !== undefined) output.fields = options.fields;
618
- if (options.bigint !== undefined) output.bigint = options.bigint;
619
668
  if (options.where !== undefined) output.where = options.where;
620
669
  if (options.joins !== undefined) output.joins = options.joins;
621
670
  if (options.orderBy !== undefined) output.orderBy = options.orderBy;
@@ -2,7 +2,7 @@ import { isNumber } from "../../utils/is.js";
2
2
  import { snakeCase } from "../../utils/util.js";
3
3
  import { Logger } from "../logger.js";
4
4
  import { SqlBuilder } from "../sqlBuilder/index.js";
5
- import { quoteIdentMySql, toNumberFromSql } from "./util.js";
5
+ import { normalizeSqlMetaNumber, quoteIdentMySql } from "./util.js";
6
6
  import { addDefaultStateFilter, buildInsertRow, buildPartialUpdateData, buildUpdateRow, clearDeep, whereKeysToSnake } from "./builders.js";
7
7
  import { assertBatchInsertRowsConsistent, assertNoUndefinedInRecord, validateGeneratedBatchId, validateIncrementOptions, validateInsertBatchSize, validateNoJoinReadOptions, validatePageLimitRange, validateSafeFieldName, validateTableBatchDataOptions, validateTableDataOptions, validateTableName, validateTableWhereOptions } from "./validate.js";
8
8
 
@@ -33,7 +33,7 @@ export const dataOpsMethods = {
33
33
  const executeRes = await this.execute(sql, params);
34
34
  const result = executeRes.data;
35
35
 
36
- const data = this.normalizeRowData(result?.[0] || null, options.bigint);
36
+ const data = this.normalizeRowData(result?.[0] || null);
37
37
  return {
38
38
  data: data,
39
39
  sql: executeRes.sql
@@ -81,7 +81,7 @@ export const dataOpsMethods = {
81
81
 
82
82
  return {
83
83
  data: {
84
- lists: this.normalizeListData(list, options.bigint),
84
+ lists: this.normalizeListData(list),
85
85
  total: total,
86
86
  page: prepared.page,
87
87
  limit: prepared.limit,
@@ -131,7 +131,7 @@ export const dataOpsMethods = {
131
131
  Logger.warn(`getAll 达到最大限制 ${MAX_LIMIT},实际总数 ${total},只返回前 ${MAX_LIMIT} 条`, { table: options.table, limit: MAX_LIMIT, total: total });
132
132
  }
133
133
 
134
- const lists = this.normalizeListData(result, options.bigint);
134
+ const lists = this.normalizeListData(result);
135
135
 
136
136
  return {
137
137
  data: {
@@ -227,7 +227,7 @@ export const dataOpsMethods = {
227
227
 
228
228
  const processedId = processed["id"];
229
229
  const processedIdNum = isNumber(processedId) ? processedId : 0;
230
- const lastInsertRowidNum = toNumberFromSql(executeRes.data?.lastInsertRowid);
230
+ const lastInsertRowidNum = normalizeSqlMetaNumber(executeRes.data?.lastInsertRowid);
231
231
 
232
232
  const insertedId = this.beflyMode === "manual" ? lastInsertRowidNum || 0 : processedIdNum || lastInsertRowidNum || 0;
233
233
  if (this.beflyMode === "manual" && insertedId <= 0) {
@@ -284,7 +284,7 @@ export const dataOpsMethods = {
284
284
  const executeRes = await this.execute(sql, params);
285
285
 
286
286
  if (this.beflyMode === "manual") {
287
- const firstId = toNumberFromSql(executeRes.data?.lastInsertRowid);
287
+ const firstId = normalizeSqlMetaNumber(executeRes.data?.lastInsertRowid);
288
288
  if (firstId <= 0) {
289
289
  throw new Error(`批量插入失败:beflyMode=manual 时无法获取 lastInsertRowid (table: ${table})`, {
290
290
  cause: null,
@@ -345,7 +345,7 @@ export const dataOpsMethods = {
345
345
  quoteIdent: quoteIdentMySql
346
346
  });
347
347
  const executeRes = await this.execute(query.sql, query.params);
348
- const changes = toNumberFromSql(executeRes.data?.changes);
348
+ const changes = normalizeSqlMetaNumber(executeRes.data?.affectedRows);
349
349
  return {
350
350
  data: changes,
351
351
  sql: executeRes.sql
@@ -398,7 +398,7 @@ export const dataOpsMethods = {
398
398
  });
399
399
 
400
400
  const executeRes = await this.execute(query.sql, query.params);
401
- const changes = toNumberFromSql(executeRes.data?.changes);
401
+ const changes = normalizeSqlMetaNumber(executeRes.data?.affectedRows);
402
402
  return {
403
403
  data: changes,
404
404
  sql: executeRes.sql
@@ -418,7 +418,7 @@ export const dataOpsMethods = {
418
418
  const { sql, params } = builder.toUpdateSql(snakeTable, processed);
419
419
 
420
420
  const executeRes = await this.execute(sql, params);
421
- const changes = toNumberFromSql(executeRes.data?.changes);
421
+ const changes = normalizeSqlMetaNumber(executeRes.data?.affectedRows);
422
422
  return {
423
423
  data: changes,
424
424
  sql: executeRes.sql
@@ -428,20 +428,28 @@ export const dataOpsMethods = {
428
428
  async delData(options) {
429
429
  validateTableWhereOptions(options, "delData", true);
430
430
  const { table, where } = options;
431
+ const snakeTable = snakeCase(table);
432
+ const snakeWhere = whereKeysToSnake(clearDeep(where));
433
+ const now = Date.now();
434
+ const processed = {
435
+ state: 0,
436
+ deleted_at: now
437
+ };
431
438
 
432
- // beflyMode=manual:关闭默认 state 软删语义,delData 直接走物理删除
433
- if (this.beflyMode === "manual") {
434
- return await this.delForce({
435
- table: table,
436
- where: where
437
- });
439
+ if (this.beflyMode === "auto") {
440
+ processed.updated_at = now;
438
441
  }
439
442
 
440
- return await this.updData({
441
- table: table,
442
- data: { state: 0, deleted_at: Date.now() },
443
- where: where
444
- });
443
+ const whereFiltered = addDefaultStateFilter(snakeWhere, snakeTable, false, this.beflyMode);
444
+ const builder = this.createSqlBuilder().where(whereFiltered);
445
+ const { sql, params } = builder.toUpdateSql(snakeTable, processed);
446
+ const executeRes = await this.execute(sql, params);
447
+ const changes = normalizeSqlMetaNumber(executeRes.data?.affectedRows);
448
+
449
+ return {
450
+ data: changes,
451
+ sql: executeRes.sql
452
+ };
445
453
  },
446
454
 
447
455
  async delForce(options) {
@@ -455,7 +463,7 @@ export const dataOpsMethods = {
455
463
  const { sql, params } = builder.toDeleteSql(snakeTable);
456
464
 
457
465
  const executeRes = await this.execute(sql, params);
458
- const changes = toNumberFromSql(executeRes.data?.changes);
466
+ const changes = normalizeSqlMetaNumber(executeRes.data?.affectedRows);
459
467
  return {
460
468
  data: changes,
461
469
  sql: executeRes.sql
@@ -508,7 +516,7 @@ export const dataOpsMethods = {
508
516
  }
509
517
 
510
518
  const executeRes = await this.execute(sql, params);
511
- const changes = toNumberFromSql(executeRes.data?.changes);
519
+ const changes = normalizeSqlMetaNumber(executeRes.data?.affectedRows);
512
520
  return {
513
521
  data: changes,
514
522
  sql: executeRes.sql
@@ -1,4 +1,4 @@
1
- import { isNonEmptyString, isNullable, isString } from "../../utils/is.js";
1
+ import { isNullable, isString } from "../../utils/is.js";
2
2
  import { canConvertToNumber, snakeCase } from "../../utils/util.js";
3
3
  import { parseTableRef } from "./validate.js";
4
4
 
@@ -41,101 +41,39 @@ export function getJoinMainQualifier(tableRef) {
41
41
  return snakeCase(parsed.table);
42
42
  }
43
43
 
44
- export function toNumberFromSql(value) {
44
+ export function normalizeSqlMetaNumber(value) {
45
45
  if (isNullable(value)) {
46
46
  return 0;
47
47
  }
48
48
 
49
- if (typeof value === "number") {
50
- if (!Number.isFinite(value)) {
51
- return 0;
52
- }
53
- return value;
54
- }
55
-
56
- if (typeof value === "bigint") {
57
- const maxSafe = BigInt(Number.MAX_SAFE_INTEGER);
58
- const minSafe = BigInt(Number.MIN_SAFE_INTEGER);
59
- if (value <= maxSafe && value >= minSafe) {
60
- return Number(value);
61
- }
49
+ if (typeof value !== "number") {
62
50
  return 0;
63
51
  }
64
52
 
65
- if (typeof value === "string") {
66
- if (!value.trim()) {
67
- return 0;
68
- }
69
- const parsed = Number(value);
70
- if (!Number.isFinite(parsed)) {
71
- return 0;
72
- }
73
- return parsed;
53
+ if (!Number.isFinite(value)) {
54
+ return 0;
74
55
  }
75
56
 
76
- return 0;
57
+ return value;
77
58
  }
78
59
 
79
- export function convertBigIntFields(arr, fields) {
60
+ export function normalizeBigIntValues(arr) {
80
61
  if (isNullable(arr)) {
81
62
  return arr;
82
63
  }
83
64
 
84
- const defaultFields = ["id", "pid", "sort"];
85
-
86
- const buildFields = (userFields) => {
87
- if (!userFields || userFields.length === 0) {
88
- return defaultFields;
89
- }
90
-
91
- const merged = ["id", "pid", "sort"];
92
- for (const f of userFields) {
93
- if (!isString(f)) {
94
- continue;
95
- }
96
- if (!isNonEmptyString(f)) {
97
- continue;
98
- }
99
- const trimmed = f.trim();
100
- if (!merged.includes(trimmed)) {
101
- merged.push(trimmed);
102
- }
103
- }
104
- return merged;
105
- };
106
-
107
- const effectiveFields = buildFields(fields);
108
- const fieldSet = new Set(effectiveFields);
109
-
110
65
  const convertRecord = (source) => {
111
66
  const converted = {};
112
67
 
113
68
  for (const [key, value] of Object.entries(source)) {
114
69
  let nextValue = value;
115
70
 
116
- if (!isNullable(value)) {
117
- const shouldConvert = fieldSet.has(key) || key.endsWith("Id") || key.endsWith("_id") || key.endsWith("At") || key.endsWith("_at");
118
-
119
- if (shouldConvert) {
120
- let bigintValue = null;
121
- if (typeof value === "bigint") {
122
- bigintValue = value;
123
- } else if (isString(value)) {
124
- if (/^-?\d+$/.test(value)) {
125
- try {
126
- bigintValue = BigInt(value);
127
- } catch {
128
- bigintValue = null;
129
- }
130
- }
131
- }
132
-
133
- if (bigintValue !== null) {
134
- const convertedNumber = canConvertToNumber(bigintValue);
135
- if (convertedNumber !== null) {
136
- nextValue = convertedNumber;
137
- }
138
- }
71
+ if (typeof value === "bigint") {
72
+ const convertedNumber = canConvertToNumber(value);
73
+ if (convertedNumber !== null) {
74
+ nextValue = convertedNumber;
75
+ } else {
76
+ nextValue = String(value);
139
77
  }
140
78
  }
141
79
 
@@ -36,6 +36,57 @@ export function validateWhereObject(where, label, required = false) {
36
36
  code: "validation"
37
37
  });
38
38
  }
39
+
40
+ validateWhereMeta(where, label);
41
+ }
42
+
43
+ function validateExcludeRules(excludeRules, label) {
44
+ if (isNullable(excludeRules)) {
45
+ return;
46
+ }
47
+
48
+ if (!isPlainObject(excludeRules)) {
49
+ throw new Error(`${label} 必须是对象`, {
50
+ cause: null,
51
+ code: "validation"
52
+ });
53
+ }
54
+
55
+ for (const [key, value] of Object.entries(excludeRules)) {
56
+ assertNonEmptyString(key, `${label} 的字段名`);
57
+ if (!Array.isArray(value)) {
58
+ throw new Error(`${label}.${key} 必须是数组`, {
59
+ cause: null,
60
+ code: "validation"
61
+ });
62
+ }
63
+ }
64
+ }
65
+
66
+ function validateWhereMeta(where, label) {
67
+ if (!isPlainObject(where)) {
68
+ return;
69
+ }
70
+
71
+ for (const [key, value] of Object.entries(where)) {
72
+ if (key === "$exclude") {
73
+ validateExcludeRules(value, `${label}.$exclude`);
74
+ continue;
75
+ }
76
+
77
+ if ((key === "$or" || key === "$and") && Array.isArray(value)) {
78
+ for (let i = 0; i < value.length; i++) {
79
+ if (isPlainObject(value[i])) {
80
+ validateWhereMeta(value[i], `${label}.${key}[${i}]`);
81
+ }
82
+ }
83
+ continue;
84
+ }
85
+
86
+ if (isPlainObject(value)) {
87
+ validateWhereMeta(value, `${label}.${key}`);
88
+ }
89
+ }
39
90
  }
40
91
 
41
92
  function validateOrderByItems(orderBy, label) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "befly",
3
- "version": "3.20.0",
4
- "gitHead": "218c4ffe07983e46bbb85f9e0a626a6b3b38c179",
3
+ "version": "3.20.4",
4
+ "gitHead": "96067cc5c780c97ab6eb8c37c54d938739f71bbd",
5
5
  "private": false,
6
6
  "description": "Befly - 为 Bun 专属打造的 JavaScript API 接口框架核心引擎",
7
7
  "keywords": [