@clairejs/server 3.19.6 → 3.20.0
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/README.md
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
## Change Log
|
|
2
2
|
|
|
3
|
-
#### 3.
|
|
3
|
+
#### 3.20.0:
|
|
4
4
|
|
|
5
|
+
- fix concurrent transactions in updateRecords
|
|
6
|
+
- update claire core, claire orm and fix returning
|
|
7
|
+
|
|
8
|
+
#### 3.19.7:
|
|
9
|
+
|
|
10
|
+
- public expose endpointMetadat in HttpRequest
|
|
5
11
|
- ModelRepository export uriHandling & beforeReturning
|
|
6
12
|
- fix uri mapper with vector props
|
|
7
13
|
- update claire orm and fix
|
|
@@ -3,7 +3,7 @@ import { EndpointMetadata } from "../../common/request/endpoint-metadata";
|
|
|
3
3
|
import { IPrincipal } from "../../common/auth/IPrincipal";
|
|
4
4
|
import { IServerSocket } from "../../socket/IServerSocket";
|
|
5
5
|
export declare class HttpRequest {
|
|
6
|
-
|
|
6
|
+
readonly endpointMetadata?: EndpointMetadata | undefined;
|
|
7
7
|
readonly valueHolder: Record<string, any>;
|
|
8
8
|
readonly clientIP?: string;
|
|
9
9
|
readonly headers: Record<string, string>;
|
|
@@ -182,12 +182,16 @@ export class CrudHttpController extends AbstractHttpController {
|
|
|
182
182
|
const principal = authProvider && (await authProvider.resolvePrincipal(req));
|
|
183
183
|
const body = req.getBody();
|
|
184
184
|
const queries = req.getQuery();
|
|
185
|
-
const updatedRecords =
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
185
|
+
const updatedRecords = [];
|
|
186
|
+
for (const record of body.records) {
|
|
187
|
+
const result = await this.crudRepository.updateMany({
|
|
188
|
+
principal,
|
|
189
|
+
queries: { ...queries, fields: { id: [record.id] } },
|
|
190
|
+
body: { update: omitData(record, ["id"]) },
|
|
191
|
+
tx,
|
|
192
|
+
});
|
|
193
|
+
updatedRecords.push(result);
|
|
194
|
+
}
|
|
191
195
|
const response = {
|
|
192
196
|
modified: updatedRecords.map((re) => re.modified[0]),
|
|
193
197
|
};
|
|
@@ -201,7 +201,6 @@ export class DtoRepository extends AbstractRepository {
|
|
|
201
201
|
const result = { id: queries.fields.id[0] };
|
|
202
202
|
await this.getMapValue(result, async () => [], this.dissolver(result), undefined, async (mapper) => {
|
|
203
203
|
const repo = new ModelRepository(mapper.modelClass, this.db);
|
|
204
|
-
//const nestedQueries = mapper.forwardQuery();
|
|
205
204
|
const nestedOps = mapper.forwardOps(ops);
|
|
206
205
|
const result = await repo.deleteMany({
|
|
207
206
|
queries: { returning: queries?.returning },
|
|
@@ -395,32 +395,39 @@ export class ModelRepository extends AbstractRepository {
|
|
|
395
395
|
if (nestedQueries.length) {
|
|
396
396
|
const tobeUpdated = await this.db
|
|
397
397
|
.use(this.model, tx)
|
|
398
|
-
.getMany(condition, { projection: ["id"] }, nestedQueries);
|
|
398
|
+
.getMany(condition, { projection: [...(queries?.returning || []), "id"] }, nestedQueries);
|
|
399
399
|
modified = tobeUpdated.records.map((r) => r.id);
|
|
400
400
|
if (modified.length) {
|
|
401
401
|
if (directUpdateFields.length) {
|
|
402
402
|
updatedRecords = await this.db
|
|
403
403
|
.use(this.model, tx)
|
|
404
|
-
.updateMany({ _in: { id: modified } }, directUpdate,
|
|
404
|
+
.updateMany({ _in: { id: modified } }, directUpdate, [
|
|
405
|
+
...(queries?.returning || []),
|
|
406
|
+
"id",
|
|
407
|
+
]);
|
|
405
408
|
}
|
|
406
409
|
else {
|
|
407
|
-
updatedRecords =
|
|
410
|
+
updatedRecords = tobeUpdated.records;
|
|
408
411
|
}
|
|
409
412
|
}
|
|
410
413
|
}
|
|
411
414
|
else {
|
|
412
415
|
if (directUpdateFields.length) {
|
|
413
|
-
updatedRecords = await this.db
|
|
416
|
+
updatedRecords = await this.db
|
|
417
|
+
.use(this.model, tx)
|
|
418
|
+
.updateMany(condition, directUpdate, [...(queries?.returning || []), "id"]);
|
|
414
419
|
modified = updatedRecords.map((re) => re.id);
|
|
415
420
|
}
|
|
416
421
|
else {
|
|
417
|
-
const tobeUpdated = await this.db
|
|
422
|
+
const tobeUpdated = await this.db
|
|
423
|
+
.use(this.model, tx)
|
|
424
|
+
.getMany(condition, { projection: [...(queries?.returning || []), "id"] });
|
|
418
425
|
modified = tobeUpdated.records.map((r) => r.id);
|
|
419
|
-
updatedRecords =
|
|
426
|
+
updatedRecords = tobeUpdated.records;
|
|
420
427
|
}
|
|
421
428
|
}
|
|
422
429
|
//-- body.update here had been modified by uri handling
|
|
423
|
-
const records = updatedRecords.map((re) => ({ ...body.update, ...directUpdate
|
|
430
|
+
const records = updatedRecords.map((re) => ({ ...re, ...body.update, ...directUpdate }));
|
|
424
431
|
//-- update translations
|
|
425
432
|
if (localeOfFields.length) {
|
|
426
433
|
//-- check if there is missing locale entry for localeFields
|
|
@@ -519,7 +526,7 @@ export class ModelRepository extends AbstractRepository {
|
|
|
519
526
|
const updatedToBeKept = await Promise.all(tobeKept
|
|
520
527
|
.filter((r) => Object.keys(r).length > 1)
|
|
521
528
|
.map((r) => modelService.updateMany({
|
|
522
|
-
queries: { returning:
|
|
529
|
+
queries: { returning: ["id"] },
|
|
523
530
|
principal,
|
|
524
531
|
ops: [{ _eq: { id: r.id } }],
|
|
525
532
|
tx,
|
|
@@ -658,13 +665,17 @@ export class ModelRepository extends AbstractRepository {
|
|
|
658
665
|
}
|
|
659
666
|
const condition = allConditions.length ? { _and: [...allConditions, ...(ops || [])] } : {};
|
|
660
667
|
const nestedQueries = this.getNestedQueries(queries);
|
|
661
|
-
let returning
|
|
668
|
+
let returning;
|
|
662
669
|
const uriMapperFields = this.modelMetadata.fields.filter((f) => f.uriMapper);
|
|
663
670
|
const localeOfFields = this.modelMetadata.fields.filter((f) => f.multiLocaleColumn);
|
|
664
671
|
if (nestedQueries.length || localeOfFields.length || uriMapperFields.length) {
|
|
665
|
-
const tobeRemoved = await this.db
|
|
666
|
-
|
|
667
|
-
|
|
672
|
+
const tobeRemoved = await this.db.use(this.model, tx).getRecords(condition, {
|
|
673
|
+
projection: [
|
|
674
|
+
...(queries?.returning || []),
|
|
675
|
+
"id",
|
|
676
|
+
...[...localeOfFields, ...uriMapperFields].map((f) => f.name),
|
|
677
|
+
],
|
|
678
|
+
}, nestedQueries);
|
|
668
679
|
await this.db.use(this.model, tx).deleteMany({
|
|
669
680
|
_in: { id: tobeRemoved.map((r) => r.id) },
|
|
670
681
|
});
|
|
@@ -718,8 +729,8 @@ export class ModelRepository extends AbstractRepository {
|
|
|
718
729
|
returning = tobeRemoved;
|
|
719
730
|
}
|
|
720
731
|
else {
|
|
721
|
-
returning = await this.db.use(this.model, tx).deleteMany(condition, queries?.returning);
|
|
732
|
+
returning = (await this.db.use(this.model, tx).deleteMany(condition, queries?.returning));
|
|
722
733
|
}
|
|
723
|
-
return { modified: returning };
|
|
734
|
+
return { modified: returning || [] };
|
|
724
735
|
}
|
|
725
736
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clairejs/server",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.20.0",
|
|
4
4
|
"description": "Claire server NodeJs framework written in Typescript.",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@clairejs/client": "^3.4.1",
|
|
19
19
|
"aws-sdk": "^2.841.0",
|
|
20
|
-
"axios": "^
|
|
20
|
+
"axios": "^1.6.2",
|
|
21
21
|
"cookie-parser": "^1.4.6",
|
|
22
22
|
"cors": "^2.8.5",
|
|
23
23
|
"express": "^4.17.1",
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"ws": "^7.5.5"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@clairejs/core": "^3.8.
|
|
38
|
-
"@clairejs/orm": "^3.
|
|
37
|
+
"@clairejs/core": "^3.8.4",
|
|
38
|
+
"@clairejs/orm": "^3.16.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/cookie-parser": "^1.4.3",
|