@cuboapp/api-backend 1.0.28 → 1.0.30
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 +5 -5
- package/src/helpers/index.ts +23 -16
- package/src/index.ts +3 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cuboapp/api-backend",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.30",
|
|
4
4
|
"description": "Backend Api for CuboApp",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"repository": "git@github.com:cuboapp/api-backend.git",
|
|
@@ -8,12 +8,12 @@
|
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"type": "module",
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@cuboapp/constants": "2.0.
|
|
12
|
-
"@cuboapp/crdt": "1.0.
|
|
11
|
+
"@cuboapp/constants": "2.0.8",
|
|
12
|
+
"@cuboapp/crdt": "1.0.9",
|
|
13
13
|
"@cuboapp/database": "1.0.4",
|
|
14
|
-
"@cuboapp/types": "2.0.
|
|
14
|
+
"@cuboapp/types": "2.0.13",
|
|
15
15
|
"@cuboapp/utils": "1.0.10",
|
|
16
|
-
"@cuboapp/ws": "1.0.
|
|
16
|
+
"@cuboapp/ws": "1.0.6",
|
|
17
17
|
"pg": "^8.17.2",
|
|
18
18
|
"yjs": "^13.6.29"
|
|
19
19
|
},
|
package/src/helpers/index.ts
CHANGED
|
@@ -16,6 +16,7 @@ import { CuboBackendApiDbConnectionType, CuboCrudFindQuery, CuboCrudRequest } fr
|
|
|
16
16
|
import { ApiHelpersConvert } from './convert'
|
|
17
17
|
import { ApiHelpersData } from './data'
|
|
18
18
|
|
|
19
|
+
import { cloneDeep } from '@cuboapp/utils'
|
|
19
20
|
import { ApiHelpersWithes } from './withes'
|
|
20
21
|
|
|
21
22
|
export class ApiHelpers<T extends CuboApiEntitiesMap<T>, A> {
|
|
@@ -316,13 +317,17 @@ export class ApiHelpers<T extends CuboApiEntitiesMap<T>, A> {
|
|
|
316
317
|
}
|
|
317
318
|
|
|
318
319
|
this.connecting[type] = new Promise(async (success) => {
|
|
319
|
-
|
|
320
|
+
if (this.api.options.db.connection) {
|
|
321
|
+
this.connections[type] = this.api.options.db.connection
|
|
322
|
+
} else {
|
|
323
|
+
const { iaas, pk_key, pk_type, ...config } = this.api.options.db.options
|
|
320
324
|
|
|
321
|
-
|
|
322
|
-
|
|
325
|
+
this.connections[type] = createDatabase(config, JSON.parse(JSON.stringify({ iaas, pk_key, pk_type })))
|
|
326
|
+
await this.connections[type].connect()
|
|
323
327
|
|
|
324
|
-
|
|
325
|
-
|
|
328
|
+
if (config.dialect === 'postgres' && config.schema) {
|
|
329
|
+
await this.connections[type].connection.query(`SET schema '${config.schema}';`)
|
|
330
|
+
}
|
|
326
331
|
}
|
|
327
332
|
|
|
328
333
|
success(this.connections[type])
|
|
@@ -353,17 +358,18 @@ export class ApiHelpers<T extends CuboApiEntitiesMap<T>, A> {
|
|
|
353
358
|
queryDto?: Partial<CuboCrudFindQuery>,
|
|
354
359
|
isCount?: boolean
|
|
355
360
|
): Promise<Partial<CuboCrudFindQuery>> {
|
|
356
|
-
const
|
|
357
|
-
|
|
358
|
-
const
|
|
359
|
-
const
|
|
360
|
-
const
|
|
361
|
-
const
|
|
362
|
-
const
|
|
363
|
-
const
|
|
364
|
-
const
|
|
365
|
-
|
|
366
|
-
|
|
361
|
+
const dto: Partial<CuboCrudFindQuery> = cloneDeep(queryDto || {})
|
|
362
|
+
|
|
363
|
+
const withes = dto.withes ?? []
|
|
364
|
+
const selects = dto.selects ?? []
|
|
365
|
+
const joins = dto.joins ?? []
|
|
366
|
+
const conditions = dto.conditions ?? []
|
|
367
|
+
const havings = dto.havings ?? []
|
|
368
|
+
const sorts = dto.sorts ?? []
|
|
369
|
+
const replacements = dto.replacements ?? {}
|
|
370
|
+
const groupBy = dto.groupBy ?? undefined
|
|
371
|
+
|
|
372
|
+
const { sort, limit: _limit, page, with: _withes, ...query } = cloneDeep(req.query || {})
|
|
367
373
|
|
|
368
374
|
// plain conditions (nested are in withes.ts)
|
|
369
375
|
for (const key in query || {}) {
|
|
@@ -374,6 +380,7 @@ export class ApiHelpers<T extends CuboApiEntitiesMap<T>, A> {
|
|
|
374
380
|
const defaultField = CUBO_CRUD_DEFAULT_FIELDS.find((f) => f.alias === parts[0])
|
|
375
381
|
|
|
376
382
|
if (!conditionField && !defaultField) {
|
|
383
|
+
console.log(entity.alias, entity.fields)
|
|
377
384
|
throw new Error('condition field "' + parts[0] + '" not found in entity "' + entity.alias + '"')
|
|
378
385
|
}
|
|
379
386
|
|
package/src/index.ts
CHANGED
|
@@ -137,6 +137,9 @@ export class CuboBackendApi<T extends CuboApiEntitiesMap<T>, A extends unknown>
|
|
|
137
137
|
): Promise<CuboCrudGetManyResponse<T[K]>> {
|
|
138
138
|
opts = opts || {}
|
|
139
139
|
req = req || {}
|
|
140
|
+
|
|
141
|
+
req.query = cloneDeep(req.query || {})
|
|
142
|
+
|
|
140
143
|
const entity = await this.getEntity(entityAlias)
|
|
141
144
|
const augmentation = this.options?.augmentations?.[entityAlias]
|
|
142
145
|
|
|
@@ -147,7 +150,6 @@ export class CuboBackendApi<T extends CuboApiEntitiesMap<T>, A extends unknown>
|
|
|
147
150
|
// get all joins
|
|
148
151
|
const queryDto = await this.helpers.withes.prepare(req, entity, opts)
|
|
149
152
|
queryDto.withDeleted = opts.queryOptions?.withDeleted
|
|
150
|
-
// queryDto.withCrdt = opts.queryOptions?.withCrdt
|
|
151
153
|
|
|
152
154
|
// create find query
|
|
153
155
|
const regularQuery = await this.helpers.createFindQuery(req, entity, queryDto)
|
|
@@ -200,7 +202,6 @@ export class CuboBackendApi<T extends CuboApiEntitiesMap<T>, A extends unknown>
|
|
|
200
202
|
// get all joins
|
|
201
203
|
const queryDto = await this.helpers.withes.prepare(req, entity, opts)
|
|
202
204
|
queryDto.withDeleted = opts.queryOptions?.withDeleted
|
|
203
|
-
queryDto.withCrdt = opts.queryOptions?.withCrdt
|
|
204
205
|
queryDto.limit = 1
|
|
205
206
|
|
|
206
207
|
const query = await this.helpers.createFindQuery(req, entity, queryDto)
|
|
@@ -283,13 +284,11 @@ export class CuboBackendApi<T extends CuboApiEntitiesMap<T>, A extends unknown>
|
|
|
283
284
|
if (!req.query?.id) {
|
|
284
285
|
throw 'Debounce "updateOne" allowed only with "id"'
|
|
285
286
|
}
|
|
286
|
-
console.log('call debounced updateOne')
|
|
287
287
|
|
|
288
288
|
const key = `${entityAlias}:${+req.query.id}` as `${string}:${number}`
|
|
289
289
|
let ex = this.debounces.get(key)
|
|
290
290
|
if (ex) {
|
|
291
291
|
if (ex.started > +new Date() - opts.debounce) {
|
|
292
|
-
console.log('clear execution')
|
|
293
292
|
Promise.reject(ex.promise)
|
|
294
293
|
} else {
|
|
295
294
|
return ex.promise
|