@autofleet/sadot 0.6.8-beta.1 → 0.6.8-beta.2

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.
@@ -25,14 +25,13 @@ const customFieldsFilterScope = (name) => (conditions) => {
25
25
  if (!conditions || Object.keys(conditions).length === 0) {
26
26
  return {};
27
27
  }
28
- const randomStr = (0, helpers_1.generateRandomString)();
29
- const replacementMapPrefix = `customFieldsFilterScopeConditionMap_${randomStr}`;
28
+ const ConditionNameRandomStr = (0, helpers_1.generateRandomString)();
30
29
  const replacements = {};
31
- replacements[`customFieldsFilterScopeConditionName_${randomStr}`] = `${name}`;
30
+ replacements[ConditionNameRandomStr] = `${name}`;
32
31
  // Build the WHERE clause for custom field filtering
33
32
  const conditionsStrings = Object.entries(conditions)
34
- .map(([key, condition], index) => {
35
- const replacemetKey = `${replacementMapPrefix}Key${index}`;
33
+ .map(([key, condition]) => {
34
+ const replacemetKey = (0, helpers_1.generateRandomString)();
36
35
  replacements[replacemetKey] = `${key}`;
37
36
  if (Array.isArray(condition)) {
38
37
  if (condition.length === 0) {
@@ -48,19 +47,19 @@ const customFieldsFilterScope = (name) => (conditions) => {
48
47
  return `(custom_fields->> :${replacemetKey} ) IN ( ${values} )`;
49
48
  }
50
49
  return condition
51
- .map((c, cIndex) => {
52
- const valRep = `${replacementMapPrefix}Values${index}${cIndex}`;
50
+ .map((c) => {
51
+ const valRep = (0, helpers_1.generateRandomString)();
53
52
  replacements[valRep] = `${c.value}`;
54
53
  return `(custom_fields->> :${replacemetKey} )${castIfNeeded(c.value)} ${c.operator} :${valRep}`;
55
54
  }).join(AND_DELIMETER);
56
55
  }
57
56
  if (typeof condition === 'string') {
58
- const conditionRep = `${replacementMapPrefix}Condition${index}`;
57
+ const conditionRep = (0, helpers_1.generateRandomString)();
59
58
  replacements[conditionRep] = `${condition}`;
60
59
  return `(custom_fields->> :${replacemetKey} ) ${castIfNeeded(condition)} = :${conditionRep}`;
61
60
  }
62
61
  if (condition?.operator) {
63
- const valueRep = `${replacementMapPrefix}Values${index}`;
62
+ const valueRep = (0, helpers_1.generateRandomString)();
64
63
  replacements[valueRep] = `${condition.value}`;
65
64
  return `(custom_fields->> :${replacemetKey} ) ${castIfNeeded(condition.value)} ${condition.operator} :${valueRep}`;
66
65
  }
@@ -75,7 +74,7 @@ const customFieldsFilterScope = (name) => (conditions) => {
75
74
  + 'SELECT cv.model_id, jsonb_object_agg(cd.name, cv.value) AS custom_fields '
76
75
  + 'FROM custom_field_values AS cv '
77
76
  + 'INNER JOIN custom_field_definitions AS cd ON cv.custom_field_definition_id = cd.id '
78
- + `AND cd.model_type = :${`customFieldsFilterScopeConditionName_${randomStr}`} `
77
+ + `AND cd.model_type = :${ConditionNameRandomStr} `
79
78
  + 'GROUP BY cv.model_id'
80
79
  + ') AS CustomFieldAggregation WHERE '} ${customFieldConditions}`;
81
80
  return {
@@ -95,10 +94,9 @@ const customFieldsSortScope = (name) => (sort) => {
95
94
  }
96
95
  const randomStr = (0, helpers_1.generateRandomString)();
97
96
  const replacements = {};
98
- const includes = Object.entries(sort).map(([key], index) => {
99
- const keyReplacement = `key_${randomStr}_${index}`;
100
- replacements[`keyCustomFields_${randomStr}_${index}`] = `customFields_${key}`;
101
- replacements[keyReplacement] = `${key}`;
97
+ const includes = Object.entries(sort).map(([key]) => {
98
+ const keyRandomReplacement = (0, helpers_1.generateRandomString)();
99
+ replacements[keyRandomReplacement] = `${key}`;
102
100
  return ([
103
101
  sequelize_typescript_1.Sequelize.literal(`(
104
102
  SELECT value
@@ -107,7 +105,7 @@ const customFieldsSortScope = (name) => (sort) => {
107
105
  ON cv.custom_field_definition_id = cd.id
108
106
  AND cd.model_type = '${name}'
109
107
  WHERE cv.model_id = "${name}"."id"
110
- AND cd.name = :${keyReplacement}
108
+ AND cd.name = :${keyRandomReplacement}
111
109
  ) AS CustomFieldAggregation
112
110
  )
113
111
  `), randomStr,
@@ -6,7 +6,7 @@ const sequelize_1 = require("sequelize");
6
6
  const sequelize_typescript_1 = require("sequelize-typescript");
7
7
  const constants_1 = require("../constants");
8
8
  const generateRandomString = (length = 5) => {
9
- const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
9
+ const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
10
10
  return Array.from({ length }, () => characters.charAt(Math.floor(Math.random() * characters.length))).join('');
11
11
  };
12
12
  exports.generateRandomString = generateRandomString;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/sadot",
3
- "version": "0.6.8-beta.1",
3
+ "version": "0.6.8-beta.2",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -44,16 +44,15 @@ export const customFieldsFilterScope = (
44
44
  if (!conditions || Object.keys(conditions).length === 0) {
45
45
  return {};
46
46
  }
47
- const randomStr = generateRandomString();
48
- const replacementMapPrefix = `customFieldsFilterScopeConditionMap_${randomStr}`;
47
+ const ConditionNameRandomStr = generateRandomString();
49
48
  const replacements: Record<string, string> = {};
50
- replacements[`customFieldsFilterScopeConditionName_${randomStr}`] = `${name}`;
49
+ replacements[ConditionNameRandomStr] = `${name}`;
51
50
 
52
51
  // Build the WHERE clause for custom field filtering
53
52
  const conditionsStrings = Object.entries(conditions)
54
53
  .map(
55
- ([key, condition], index) => {
56
- const replacemetKey = `${replacementMapPrefix}Key${index}`;
54
+ ([key, condition]) => {
55
+ const replacemetKey = generateRandomString();
57
56
  replacements[replacemetKey] = `${key}`;
58
57
  if (Array.isArray(condition)) {
59
58
  if (condition.length === 0) {
@@ -69,19 +68,19 @@ export const customFieldsFilterScope = (
69
68
  return `(custom_fields->> :${replacemetKey} ) IN ( ${values} )`;
70
69
  }
71
70
  return condition
72
- .map((c, cIndex) => {
73
- const valRep = `${replacementMapPrefix}Values${index}${cIndex}`;
71
+ .map((c) => {
72
+ const valRep = generateRandomString();
74
73
  replacements[valRep] = `${c.value}`;
75
74
  return `(custom_fields->> :${replacemetKey} )${castIfNeeded(c.value)} ${c.operator} :${valRep}`;
76
75
  }).join(AND_DELIMETER);
77
76
  }
78
77
  if (typeof condition === 'string') {
79
- const conditionRep = `${replacementMapPrefix}Condition${index}`;
78
+ const conditionRep = generateRandomString();
80
79
  replacements[conditionRep] = `${condition}`;
81
80
  return `(custom_fields->> :${replacemetKey} ) ${castIfNeeded(condition)} = :${conditionRep}`;
82
81
  }
83
82
  if (condition?.operator) {
84
- const valueRep = `${replacementMapPrefix}Values${index}`;
83
+ const valueRep = generateRandomString();
85
84
  replacements[valueRep] = `${condition.value}`;
86
85
  return `(custom_fields->> :${replacemetKey} ) ${castIfNeeded(condition.value)} ${condition.operator} :${valueRep}`;
87
86
  }
@@ -98,7 +97,7 @@ export const customFieldsFilterScope = (
98
97
  + 'SELECT cv.model_id, jsonb_object_agg(cd.name, cv.value) AS custom_fields '
99
98
  + 'FROM custom_field_values AS cv '
100
99
  + 'INNER JOIN custom_field_definitions AS cd ON cv.custom_field_definition_id = cd.id '
101
- + `AND cd.model_type = :${`customFieldsFilterScopeConditionName_${randomStr}`} `
100
+ + `AND cd.model_type = :${ConditionNameRandomStr} `
102
101
  + 'GROUP BY cv.model_id'
103
102
  + ') AS CustomFieldAggregation WHERE '} ${customFieldConditions}`;
104
103
  return {
@@ -121,10 +120,9 @@ export const customFieldsSortScope = (
121
120
  }
122
121
  const randomStr = generateRandomString();
123
122
  const replacements: Record<string, string> = {};
124
- const includes = Object.entries(sort).map(([key], index) => {
125
- const keyReplacement = `key_${randomStr}_${index}`;
126
- replacements[`keyCustomFields_${randomStr}_${index}`] = `customFields_${key}`;
127
- replacements[keyReplacement] = `${key}`;
123
+ const includes = Object.entries(sort).map(([key]) => {
124
+ const keyRandomReplacement = generateRandomString();
125
+ replacements[keyRandomReplacement] = `${key}`;
128
126
  return ([
129
127
  Sequelize.literal(`(
130
128
  SELECT value
@@ -133,7 +131,7 @@ export const customFieldsSortScope = (
133
131
  ON cv.custom_field_definition_id = cd.id
134
132
  AND cd.model_type = '${name}'
135
133
  WHERE cv.model_id = "${name}"."id"
136
- AND cd.name = :${keyReplacement}
134
+ AND cd.name = :${keyRandomReplacement}
137
135
  ) AS CustomFieldAggregation
138
136
  )
139
137
  `), randomStr,
@@ -26,7 +26,7 @@ interface CustomFieldsSearchPayload {
26
26
  }
27
27
 
28
28
  export const generateRandomString = (length = 5): string => {
29
- const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
29
+ const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
30
30
  return Array.from({ length }, () => characters.charAt(Math.floor(Math.random() * characters.length))).join('');
31
31
  };
32
32