@autofleet/sadot 0.7.0-beta.2 → 0.7.0-beta.2.1

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.
@@ -73,8 +73,11 @@ exports.findValuesByModelIds = findValuesByModelIds;
73
73
  */
74
74
  const updateValues = async (modelType, modelId, identifiers, valuesToUpdate, options = {}) => {
75
75
  const names = Object.keys(valuesToUpdate);
76
- logger_1.default.info(`custom-fields: updating values for ${modelType} ${modelId}`, {
77
- names, options, valuesToUpdate, identifiers,
76
+ logger_1.default.debug(`custom-fields: updating values for ${modelType} ${modelId}`, {
77
+ names,
78
+ optionsKeys: options ? Object.keys(options) : null,
79
+ valuesToUpdate,
80
+ identifiers,
78
81
  });
79
82
  const { modelOptions, transaction } = options;
80
83
  const where = {
@@ -87,7 +90,7 @@ const updateValues = async (modelType, modelId, identifiers, valuesToUpdate, opt
87
90
  const fieldDefinitions = await DefinitionRepo.findAll(where, { withDisabled: true, transaction, include: modelOptions.include?.(identifiers) }) || [];
88
91
  const disabledDefinitions = fieldDefinitions.filter((def) => def.disabled);
89
92
  if (fieldDefinitions.length !== names.length) {
90
- logger_1.default.info(`custom-fields: missing definitions for ${modelType} ${modelId}`, { names, fieldDefinitions });
93
+ logger_1.default.warn(`custom-fields: missing definitions for ${modelType} ${modelId}`, { names, fieldDefinitions });
91
94
  const missingDefinitions = names.filter((name) => !fieldDefinitions.some((def) => def.name === name));
92
95
  throw new errors_1.MissingDefinitionError(missingDefinitions);
93
96
  }
@@ -21,6 +21,12 @@ const castIfNeeded = (conditionValue) => {
21
21
  return '';
22
22
  };
23
23
  const AND_DELIMETER = ' AND ';
24
+ const OR_DELIMETER = ' OR ';
25
+ const CD_TABLE_ALIAS = 'cd';
26
+ const CD_NAME_COLUMN = `${CD_TABLE_ALIAS}.name`;
27
+ const CV_TABLE_ALIAS = 'cv';
28
+ const CV_VALUE_COLUMN = `(${CV_TABLE_ALIAS}.value)`;
29
+ const castValueToJsonb = (value) => `to_jsonb(${value}::text)`;
24
30
  /**
25
31
  * Helper function to build condition strings for the WHERE clause.
26
32
  */
@@ -41,7 +47,7 @@ const buildConditionString = (key, condition, replacements) => {
41
47
  return `(custom_fields->> :${replacementKey})${castIfNeeded(c.value)} ${c.operator} :${valRep}`;
42
48
  }).join(AND_DELIMETER);
43
49
  }
44
- if (typeof condition === 'string') {
50
+ if (typeof condition === 'string' || typeof condition === 'number') {
45
51
  const conditionRep = replacements[condition];
46
52
  return `(custom_fields->> :${replacementKey}) ${castIfNeeded(condition)} = :${conditionRep}`;
47
53
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/sadot",
3
- "version": "0.7.0-beta.2",
3
+ "version": "0.7.0-beta.2.1",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -62,6 +62,9 @@
62
62
  "peerDependencies": {
63
63
  "@autofleet/sheilta": ">=1.4.0-beta.2"
64
64
  },
65
+ "engines": {
66
+ "node": ">=16.0.0"
67
+ },
65
68
  "author": "Autofleet",
66
69
  "license": "ISC"
67
70
  }
@@ -55,8 +55,11 @@ export const updateValues = async (
55
55
  options: FindOptions & { modelOptions?: ModelOptions } = {},
56
56
  ): Promise<CustomFieldValue[]> => {
57
57
  const names = Object.keys(valuesToUpdate);
58
- logger.info(`custom-fields: updating values for ${modelType} ${modelId}`, {
59
- names, options, valuesToUpdate, identifiers,
58
+ logger.debug(`custom-fields: updating values for ${modelType} ${modelId}`, {
59
+ names,
60
+ optionsKeys: options ? Object.keys(options) : null,
61
+ valuesToUpdate,
62
+ identifiers,
60
63
  });
61
64
  const { modelOptions, transaction } = options;
62
65
 
@@ -72,7 +75,7 @@ export const updateValues = async (
72
75
 
73
76
  const disabledDefinitions = fieldDefinitions.filter((def) => def.disabled);
74
77
  if (fieldDefinitions.length !== names.length) {
75
- logger.info(`custom-fields: missing definitions for ${modelType} ${modelId}`, { names, fieldDefinitions });
78
+ logger.warn(`custom-fields: missing definitions for ${modelType} ${modelId}`, { names, fieldDefinitions });
76
79
  const missingDefinitions = names.filter((name) => !fieldDefinitions.some((def) => def.name === name));
77
80
  throw new MissingDefinitionError(missingDefinitions);
78
81
  }
@@ -38,6 +38,13 @@ const castIfNeeded = (conditionValue: string): string => {
38
38
  return '';
39
39
  };
40
40
  const AND_DELIMETER = ' AND ';
41
+ const OR_DELIMETER = ' OR ';
42
+
43
+ const CD_TABLE_ALIAS = 'cd';
44
+ const CD_NAME_COLUMN = `${CD_TABLE_ALIAS}.name`;
45
+ const CV_TABLE_ALIAS = 'cv';
46
+ const CV_VALUE_COLUMN = `(${CV_TABLE_ALIAS}.value)`;
47
+ const castValueToJsonb = (value) => `to_jsonb(${value}::text)`;
41
48
 
42
49
  /**
43
50
  * Helper function to build condition strings for the WHERE clause.
@@ -61,7 +68,7 @@ const buildConditionString = (key: string, condition: ConditionValue | Condition
61
68
  }).join(AND_DELIMETER);
62
69
  }
63
70
 
64
- if (typeof condition === 'string') {
71
+ if (typeof condition === 'string'|| typeof condition === 'number') {
65
72
  const conditionRep = replacements[condition];
66
73
  return `(custom_fields->> :${replacementKey}) ${castIfNeeded(condition)} = :${conditionRep}`;
67
74
  }
@@ -97,11 +104,9 @@ export const customFieldsFilterScope = (
97
104
  const conditionsStrings = Object.entries(conditions)
98
105
  .map(([key, condition]) => buildConditionString(key, condition, replacements))
99
106
  .filter(Boolean) as string[];
100
-
101
107
  if (conditionsStrings.length === 0) {
102
108
  return { replacements };
103
109
  }
104
-
105
110
  const customFieldConditions = conditionsStrings.join(AND_DELIMETER);
106
111
  const subQuery = `${'SELECT model_id FROM ('
107
112
  + 'SELECT cv.model_id, jsonb_object_agg(cd.name, cv.value) AS custom_fields '