inibase 1.5.2 → 1.5.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/dist/index.js CHANGED
@@ -1041,16 +1041,6 @@ export default class Inibase {
1041
1041
  delete value[logic];
1042
1042
  }
1043
1043
  }
1044
- else if (Array.isArray(value)) {
1045
- const crit = value
1046
- .map((v) => typeof v === "string"
1047
- ? Utils.FormatObjectCriteriaValue(v)
1048
- : ["=", v])
1049
- .filter(Boolean);
1050
- searchOperator = crit.map((c) => c[0]);
1051
- searchComparedAtValue = crit.map((c) => c[1]);
1052
- searchLogicalOperator = "or";
1053
- }
1054
1044
  else if (typeof value === "string") {
1055
1045
  const [op, val] = Utils.FormatObjectCriteriaValue(value);
1056
1046
  searchOperator = op;
@@ -38,14 +38,6 @@ export declare const hashString: (str: string) => string;
38
38
  * Note: Handles various data types and comparison logic, including special handling for passwords and regex patterns.
39
39
  */
40
40
  export declare const compare: (operator: ComparisonOperator, originalValue: string | number | boolean | null | (string | number | boolean | null)[], comparedValue: string | number | boolean | null | (string | number | boolean | null)[], fieldType?: FieldType | FieldType[]) => boolean;
41
- /**
42
- * Helper function to check equality based on the field type.
43
- *
44
- * @param originalValue - The original value.
45
- * @param comparedValue - The value to compare against.
46
- * @param field - Field object config.
47
- * @returns boolean - Result of the equality check.
48
- */
49
41
  export declare const isEqual: (originalValue: string | number | boolean | null | (string | number | boolean | null)[], comparedValue: string | number | boolean | null | (string | number | boolean | null)[], fieldType?: FieldType) => boolean;
50
42
  /**
51
43
  * Helper function to check array equality.
@@ -137,19 +137,41 @@ export const compare = (operator, originalValue, comparedValue, fieldType) => {
137
137
  /**
138
138
  * Helper function to handle non-null comparisons.
139
139
  */
140
- const compareNonNullValues = (originalValue, comparedValue, comparator) => {
141
- return (originalValue !== null &&
142
- comparedValue !== null &&
143
- comparator(originalValue, comparedValue));
140
+ const isComparablePrimitive = (value) => typeof value === "string" ||
141
+ typeof value === "number" ||
142
+ typeof value === "boolean";
143
+ const compareNonNullValues = (originalValue, comparedValue, comparator) => originalValue !== null &&
144
+ comparedValue !== null &&
145
+ isComparablePrimitive(originalValue) &&
146
+ isComparablePrimitive(comparedValue) &&
147
+ comparator(originalValue, comparedValue);
148
+ const serializeArrayItem = (value) => {
149
+ if (Array.isArray(value))
150
+ return `array:${Inison.stringify(value)}`;
151
+ const type = value === null ? "null" : typeof value;
152
+ const valueStr = value === null ? "null" : String(value);
153
+ return `${type}:${valueStr}`;
154
+ };
155
+ const haveSameArrayValues = (first, second) => {
156
+ if (first.length !== second.length)
157
+ return false;
158
+ const counts = new Map();
159
+ for (const value of first) {
160
+ const key = serializeArrayItem(value);
161
+ counts.set(key, (counts.get(key) ?? 0) + 1);
162
+ }
163
+ for (const value of second) {
164
+ const key = serializeArrayItem(value);
165
+ const remaining = (counts.get(key) ?? 0) - 1;
166
+ if (remaining < 0)
167
+ return false;
168
+ if (remaining === 0)
169
+ counts.delete(key);
170
+ else
171
+ counts.set(key, remaining);
172
+ }
173
+ return counts.size === 0;
144
174
  };
145
- /**
146
- * Helper function to check equality based on the field type.
147
- *
148
- * @param originalValue - The original value.
149
- * @param comparedValue - The value to compare against.
150
- * @param field - Field object config.
151
- * @returns boolean - Result of the equality check.
152
- */
153
175
  export const isEqual = (originalValue, comparedValue, fieldType) => {
154
176
  switch (fieldType) {
155
177
  case "password":
@@ -170,11 +192,8 @@ export const isEqual = (originalValue, comparedValue, fieldType) => {
170
192
  if (isOriginalNullLike && isComparedNullLike)
171
193
  return true;
172
194
  // If both are arrays
173
- if (Array.isArray(originalValue)) {
174
- if (Array.isArray(comparedValue))
175
- return (JSON.stringify(originalValue) === JSON.stringify(comparedValue));
176
- return Inison.stringify(originalValue) === comparedValue;
177
- }
195
+ if (Array.isArray(originalValue) && Array.isArray(comparedValue))
196
+ return haveSameArrayValues(originalValue, comparedValue);
178
197
  // If both are number-like
179
198
  if (isNumber(originalValue) && isNumber(comparedValue))
180
199
  return Number(originalValue) === Number(comparedValue);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inibase",
3
- "version": "1.5.2",
3
+ "version": "1.5.4",
4
4
  "type": "module",
5
5
  "author": {
6
6
  "name": "Karim Amahtil",