@cuboapp/api-backend 3.0.3 → 3.0.5

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cuboapp/api-backend",
3
- "version": "3.0.3",
3
+ "version": "3.0.5",
4
4
  "description": "Backend Api for CuboApp",
5
5
  "main": "src/index.ts",
6
6
  "repository": "git@github.com:cuboapp/api-backend.git",
@@ -14,7 +14,7 @@
14
14
  "@cuboapp/utils": "1.0.12"
15
15
  },
16
16
  "peerDependencies": {
17
- "@cuboapp/crdt": "1.0.16",
17
+ "@cuboapp/crdt": "1.0.18",
18
18
  "@cuboapp/ws": "1.0.10",
19
19
  "mysql2": "3.22.5",
20
20
  "pg": "8.22.0",
@@ -38,7 +38,7 @@
38
38
  }
39
39
  },
40
40
  "devDependencies": {
41
- "@cuboapp/crdt": "file:../crdt",
41
+ "@cuboapp/crdt": "1.0.18",
42
42
  "@cuboapp/ws": "1.0.10",
43
43
  "@types/node": "^26.0.0",
44
44
  "pg": "^8.22.0",
@@ -3,7 +3,6 @@ import { Database, createDatabase } from '@cuboapp/database'
3
3
  import { CuboApiEntitiesMap, CuboEntity, CuboEntityField, CuboEntityFieldExtra, CuboEntityFieldType } from '@cuboapp/types'
4
4
  import { cloneDeep } from '@cuboapp/utils'
5
5
 
6
- import type { CuboBackendApi } from '../core'
7
6
  import {
8
7
  CUBO_CRUD_DEFAULT_FIELDS,
9
8
  CUBO_CRUD_DEFAULT_PAGE_LIMIT,
@@ -12,6 +11,7 @@ import {
12
11
  CUBO_CRUD_QUERY_KEY_REGEX,
13
12
  CUBO_CRUD_QUERY_SYMBOL_NOT
14
13
  } from '../constants'
14
+ import type { CuboBackendApi } from '../core'
15
15
  import { CuboDialect, getDialect } from '../dialects'
16
16
  import { CuboBackendApiDbConnectionType, CuboCrudFindQuery, CuboCrudRequest, CuboDataFilter, CuboDataFiltersQuery } from '../types'
17
17
 
@@ -495,22 +495,24 @@ export class ApiHelpers<T extends CuboApiEntitiesMap<T>, A = unknown> {
495
495
  const conditionField = entity.fields?.find((f) => f.alias === parts[0])
496
496
  const defaultField = CUBO_CRUD_DEFAULT_FIELDS.find((f) => f.alias === parts[0])
497
497
 
498
- if (!conditionField && !defaultField) {
499
- throw new Error('condition field "' + parts[0] + '" not found in entity "' + entity.alias + '"')
498
+ // if (!conditionField && !defaultField) {
499
+ // throw new Error('condition field "' + parts[0] + '" not found in entity "' + entity.alias + '"')
500
+ // }
501
+
502
+ if (conditionField || defaultField) {
503
+ const fieldAlias = conditionField ? conditionField.alias : defaultField!.alias
504
+ const preparedCondition = this.clearFieldConditionValue(conditionField ? conditionField : defaultField!, query[key])
505
+ const prepared = this.prepareConditionSql(
506
+ `t1.${fieldAlias}`,
507
+ `c_1_${fieldAlias}_value`,
508
+ preparedCondition.value,
509
+ preparedCondition.condition,
510
+ preparedCondition.is_not
511
+ )
512
+
513
+ conditions.push(...(prepared.conditions || []))
514
+ Object.assign(replacements, prepared.replacements || {})
500
515
  }
501
-
502
- const fieldAlias = conditionField ? conditionField.alias : defaultField!.alias
503
- const preparedCondition = this.clearFieldConditionValue(conditionField ? conditionField : defaultField!, query[key])
504
- const prepared = this.prepareConditionSql(
505
- `t1.${fieldAlias}`,
506
- `c_1_${fieldAlias}_value`,
507
- preparedCondition.value,
508
- preparedCondition.condition,
509
- preparedCondition.is_not
510
- )
511
-
512
- conditions.push(...(prepared.conditions || []))
513
- Object.assign(replacements, prepared.replacements || {})
514
516
  }
515
517
  }
516
518
 
@@ -158,35 +158,38 @@ export class ApiHelpersWithes<T extends CuboApiEntitiesMap<T>> {
158
158
  const conditionField =
159
159
  lastEntity.fields?.find((f) => f.alias === conditionLastKey) || CUBO_CRUD_DEFAULT_FIELDS.find((f) => f.alias === conditionLastKey)
160
160
 
161
- if (!conditionField) {
162
- throw new Error('condition field "' + conditionKey + '" not found in entity "' + entity.alias + '"')
163
- }
161
+ // if (!conditionField) {
162
+ // throw new Error('condition field "' + conditionKey + '" not found in entity "' + entity.alias + '"')
163
+ // }
164
164
 
165
- let conditionTableAlias = 't1'
166
- if (conditionKeyParts.length > 0) {
167
- const exWith = withes.find((w) => (w.full_key = conditionKeyParts.join('.')))
165
+ if (conditionField) {
166
+ let conditionTableAlias = 't1'
168
167
 
169
- if (!exWith) {
170
- throw new Error('condition field relation "' + conditionKey + '" not found')
171
- }
168
+ if (conditionKeyParts.length > 0) {
169
+ const exWith = withes.find((w) => (w.full_key = conditionKeyParts.join('.')))
172
170
 
173
- conditionTableAlias = 't_' + exWith.table_name
174
- }
171
+ if (!exWith) {
172
+ throw new Error('condition field relation "' + conditionKey + '" not found')
173
+ }
174
+
175
+ conditionTableAlias = 't_' + exWith.table_name
176
+ }
175
177
 
176
- opts.conditions = opts.conditions || []
178
+ opts.conditions = opts.conditions || []
177
179
 
178
- const preparedCondition = this.helpers.clearFieldConditionValue(conditionField, opts.conditionValue)
180
+ const preparedCondition = this.helpers.clearFieldConditionValue(conditionField, opts.conditionValue)
179
181
 
180
- const prepared = this.helpers.prepareConditionSql(
181
- `${conditionTableAlias}.${conditionField.alias}`,
182
- `${conditionTableAlias}_${conditionField.alias}_value`,
183
- preparedCondition.value,
184
- preparedCondition.condition,
185
- preparedCondition.is_not
186
- )
182
+ const prepared = this.helpers.prepareConditionSql(
183
+ `${conditionTableAlias}.${conditionField.alias}`,
184
+ `${conditionTableAlias}_${conditionField.alias}_value`,
185
+ preparedCondition.value,
186
+ preparedCondition.condition,
187
+ preparedCondition.is_not
188
+ )
187
189
 
188
- opts.conditions.push(...(prepared.conditions || []))
189
- Object.assign(opts.replacements, prepared.replacements || {})
190
+ opts.conditions.push(...(prepared.conditions || []))
191
+ Object.assign(opts.replacements, prepared.replacements || {})
192
+ }
190
193
  }
191
194
 
192
195
  // сортировка