@ruiapp/rapid-core 0.2.1 → 0.2.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.
- package/dist/dataAccess/entityManager.d.ts +3 -3
- package/dist/index.js +32 -1
- package/dist/types.d.ts +14 -4
- package/package.json +1 -1
- package/src/dataAccess/entityManager.ts +37 -6
- package/src/types.ts +18 -4
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AddEntityRelationsOptions, CountEntityOptions, CountEntityResult, CreateEntityOptions, DeleteEntityByIdOptions, FindEntityByIdOptions, FindEntityOptions,
|
|
1
|
+
import { AddEntityRelationsOptions, CountEntityOptions, CountEntityResult, CreateEntityOptions, DeleteEntityByIdOptions, FindEntityByIdOptions, FindEntityOptions, IRpdDataAccessor, RemoveEntityRelationsOptions, RpdDataModel, RpdDataModelIndex, RpdDataModelProperty, UpdateEntityByIdOptions, FindEntityFindOneRelationEntitiesOptions, FindEntityFindManyRelationEntitiesOptions } from "../types";
|
|
2
2
|
import { IRpdServer, RapidPlugin } from "../core/server";
|
|
3
3
|
import { RouteContext } from "../core/routeContext";
|
|
4
4
|
export type FindOneRelationEntitiesOptions = {
|
|
@@ -6,14 +6,14 @@ export type FindOneRelationEntitiesOptions = {
|
|
|
6
6
|
mainModel: RpdDataModel;
|
|
7
7
|
relationProperty: RpdDataModelProperty;
|
|
8
8
|
relationEntityIds: any[];
|
|
9
|
-
selectRelationOptions?:
|
|
9
|
+
selectRelationOptions?: FindEntityFindOneRelationEntitiesOptions;
|
|
10
10
|
};
|
|
11
11
|
export type FindManyRelationEntitiesOptions = {
|
|
12
12
|
server: IRpdServer;
|
|
13
13
|
mainModel: RpdDataModel;
|
|
14
14
|
relationProperty: RpdDataModelProperty;
|
|
15
15
|
mainEntityIds: any[];
|
|
16
|
-
selectRelationOptions?:
|
|
16
|
+
selectRelationOptions?: FindEntityFindManyRelationEntitiesOptions;
|
|
17
17
|
};
|
|
18
18
|
export type CheckEntityDuplicatedOptions = {
|
|
19
19
|
routeContext?: RouteContext;
|
package/dist/index.js
CHANGED
|
@@ -2748,7 +2748,9 @@ async function findManyRelationLinksViaLinkTable(options) {
|
|
|
2748
2748
|
const command = `SELECT * FROM ${server.queryBuilder.quoteTable({
|
|
2749
2749
|
schema: relationProperty.linkSchema,
|
|
2750
2750
|
tableName: relationProperty.linkTableName,
|
|
2751
|
-
})} WHERE ${server.queryBuilder.quoteObject(relationProperty.selfIdColumnName)} = ANY($1::int[])
|
|
2751
|
+
})} WHERE ${server.queryBuilder.quoteObject(relationProperty.selfIdColumnName)} = ANY($1::int[])
|
|
2752
|
+
ORDER BY id
|
|
2753
|
+
`;
|
|
2752
2754
|
const params = [mainEntityIds];
|
|
2753
2755
|
const links = await server.queryDatabaseObject(command, params);
|
|
2754
2756
|
const targetEntityIds = links.map((link) => link[relationProperty.targetIdColumnName]);
|
|
@@ -2774,6 +2776,18 @@ async function findManyRelationLinksViaLinkTable(options) {
|
|
|
2774
2776
|
if (selectRelationOptions.relations) {
|
|
2775
2777
|
findEntityOptions.relations = selectRelationOptions.relations;
|
|
2776
2778
|
}
|
|
2779
|
+
if (selectRelationOptions.orderBy) {
|
|
2780
|
+
findEntityOptions.orderBy = selectRelationOptions.orderBy;
|
|
2781
|
+
}
|
|
2782
|
+
if (selectRelationOptions.pagination) {
|
|
2783
|
+
findEntityOptions.pagination = selectRelationOptions.pagination;
|
|
2784
|
+
}
|
|
2785
|
+
if (selectRelationOptions.filters) {
|
|
2786
|
+
findEntityOptions.filters = [...findEntityOptions.filters, ...selectRelationOptions.filters];
|
|
2787
|
+
}
|
|
2788
|
+
if (!lodash.isUndefined(selectRelationOptions.keepNonPropertyFields)) {
|
|
2789
|
+
findEntityOptions.keepNonPropertyFields = selectRelationOptions.keepNonPropertyFields;
|
|
2790
|
+
}
|
|
2777
2791
|
}
|
|
2778
2792
|
}
|
|
2779
2793
|
const targetEntities = await findEntities(server, dataAccessor, findEntityOptions);
|
|
@@ -2795,6 +2809,11 @@ async function findManyRelatedEntitiesViaIdPropertyCode(options) {
|
|
|
2795
2809
|
value: mainEntityIds,
|
|
2796
2810
|
},
|
|
2797
2811
|
],
|
|
2812
|
+
orderBy: [
|
|
2813
|
+
{
|
|
2814
|
+
field: "id",
|
|
2815
|
+
},
|
|
2816
|
+
],
|
|
2798
2817
|
extraColumnsToSelect: [relationProperty.selfIdColumnName],
|
|
2799
2818
|
keepNonPropertyFields: true,
|
|
2800
2819
|
};
|
|
@@ -2806,6 +2825,18 @@ async function findManyRelatedEntitiesViaIdPropertyCode(options) {
|
|
|
2806
2825
|
if (selectRelationOptions.relations) {
|
|
2807
2826
|
findEntityOptions.relations = selectRelationOptions.relations;
|
|
2808
2827
|
}
|
|
2828
|
+
if (selectRelationOptions.orderBy) {
|
|
2829
|
+
findEntityOptions.orderBy = selectRelationOptions.orderBy;
|
|
2830
|
+
}
|
|
2831
|
+
if (selectRelationOptions.pagination) {
|
|
2832
|
+
findEntityOptions.pagination = selectRelationOptions.pagination;
|
|
2833
|
+
}
|
|
2834
|
+
if (selectRelationOptions.filters) {
|
|
2835
|
+
findEntityOptions.filters = [...findEntityOptions.filters, ...selectRelationOptions.filters];
|
|
2836
|
+
}
|
|
2837
|
+
if (!lodash.isUndefined(selectRelationOptions.keepNonPropertyFields)) {
|
|
2838
|
+
findEntityOptions.keepNonPropertyFields = selectRelationOptions.keepNonPropertyFields;
|
|
2839
|
+
}
|
|
2809
2840
|
}
|
|
2810
2841
|
}
|
|
2811
2842
|
return await findEntities(server, dataAccessor, findEntityOptions);
|
package/dist/types.d.ts
CHANGED
|
@@ -391,7 +391,7 @@ export interface FindEntityOptions {
|
|
|
391
391
|
orderBy?: FindEntityOrderByOptions[];
|
|
392
392
|
pagination?: FindEntityPaginationOptions;
|
|
393
393
|
properties?: string[];
|
|
394
|
-
relations?: Record<string,
|
|
394
|
+
relations?: Record<string, FindEntityFindRelationEntitiesOptions>;
|
|
395
395
|
extraColumnsToSelect?: ColumnSelectOptions[];
|
|
396
396
|
keepNonPropertyFields?: boolean;
|
|
397
397
|
}
|
|
@@ -399,7 +399,7 @@ export interface FindEntityByIdOptions {
|
|
|
399
399
|
routeContext?: RouteContext;
|
|
400
400
|
id: any;
|
|
401
401
|
properties?: string[];
|
|
402
|
-
relations?: Record<string,
|
|
402
|
+
relations?: Record<string, FindEntityFindRelationEntitiesOptions>;
|
|
403
403
|
keepNonPropertyFields?: boolean;
|
|
404
404
|
}
|
|
405
405
|
export interface FindEntityRelationalFilterOptions {
|
|
@@ -437,9 +437,19 @@ export interface FindEntityPaginationOptions {
|
|
|
437
437
|
limit: number;
|
|
438
438
|
withoutTotal?: boolean;
|
|
439
439
|
}
|
|
440
|
-
export type
|
|
440
|
+
export type FindEntityFindRelationEntitiesOptions = FindEntityFindOneRelationEntitiesOptions | FindEntityFindManyRelationEntitiesOptions;
|
|
441
|
+
export type FindEntityFindOneRelationEntitiesOptions = true | {
|
|
441
442
|
properties?: string[];
|
|
442
|
-
relations?: Record<string,
|
|
443
|
+
relations?: Record<string, FindEntityFindRelationEntitiesOptions>;
|
|
444
|
+
keepNonPropertyFields?: boolean;
|
|
445
|
+
};
|
|
446
|
+
export type FindEntityFindManyRelationEntitiesOptions = true | {
|
|
447
|
+
properties?: string[];
|
|
448
|
+
relations?: Record<string, FindEntityFindRelationEntitiesOptions>;
|
|
449
|
+
filters?: EntityFilterOptions[];
|
|
450
|
+
orderBy?: FindEntityOrderByOptions[];
|
|
451
|
+
pagination?: FindEntityPaginationOptions;
|
|
452
|
+
keepNonPropertyFields?: boolean;
|
|
443
453
|
};
|
|
444
454
|
export interface FindEntityOrderByOptions {
|
|
445
455
|
field: string;
|
package/package.json
CHANGED
|
@@ -10,7 +10,6 @@ import {
|
|
|
10
10
|
FindEntityByIdOptions,
|
|
11
11
|
FindEntityOptions,
|
|
12
12
|
FindEntityOrderByOptions,
|
|
13
|
-
FindEntitySelectRelationOptions,
|
|
14
13
|
IRpdDataAccessor,
|
|
15
14
|
RemoveEntityRelationsOptions,
|
|
16
15
|
RpdDataModel,
|
|
@@ -18,13 +17,15 @@ import {
|
|
|
18
17
|
RpdDataModelIndexOptions,
|
|
19
18
|
RpdDataModelProperty,
|
|
20
19
|
UpdateEntityByIdOptions,
|
|
20
|
+
FindEntityFindOneRelationEntitiesOptions,
|
|
21
|
+
FindEntityFindManyRelationEntitiesOptions,
|
|
21
22
|
} from "~/types";
|
|
22
23
|
import { isNullOrUndefined } from "~/utilities/typeUtility";
|
|
23
24
|
import { mapDbRowToEntity, mapEntityToDbRow } from "./entityMapper";
|
|
24
25
|
import { mapPropertyNameToColumnName } from "./propertyMapper";
|
|
25
26
|
import { IRpdServer, RapidPlugin } from "~/core/server";
|
|
26
27
|
import { getEntityPartChanges } from "~/helpers/entityHelpers";
|
|
27
|
-
import { cloneDeep, filter, find, first, forEach, isArray, isNumber, isObject, isPlainObject, isString, keys, map, reject, uniq } from "lodash";
|
|
28
|
+
import { cloneDeep, filter, find, first, forEach, isArray, isNumber, isObject, isPlainObject, isString, isUndefined, keys, map, reject, uniq } from "lodash";
|
|
28
29
|
import {
|
|
29
30
|
getEntityPropertiesIncludingBase,
|
|
30
31
|
getEntityProperty,
|
|
@@ -37,7 +38,6 @@ import {
|
|
|
37
38
|
import { ColumnSelectOptions, CountRowOptions, FindRowOptions, FindRowOrderByOptions, RowFilterOptions } from "./dataAccessTypes";
|
|
38
39
|
import { newEntityOperationError } from "~/utilities/errorUtility";
|
|
39
40
|
import { getNowStringWithTimezone } from "~/utilities/timeUtility";
|
|
40
|
-
import { or } from "xstate";
|
|
41
41
|
import { RouteContext } from "~/core/routeContext";
|
|
42
42
|
|
|
43
43
|
export type FindOneRelationEntitiesOptions = {
|
|
@@ -45,7 +45,7 @@ export type FindOneRelationEntitiesOptions = {
|
|
|
45
45
|
mainModel: RpdDataModel;
|
|
46
46
|
relationProperty: RpdDataModelProperty;
|
|
47
47
|
relationEntityIds: any[];
|
|
48
|
-
selectRelationOptions?:
|
|
48
|
+
selectRelationOptions?: FindEntityFindOneRelationEntitiesOptions;
|
|
49
49
|
};
|
|
50
50
|
|
|
51
51
|
export type FindManyRelationEntitiesOptions = {
|
|
@@ -53,7 +53,7 @@ export type FindManyRelationEntitiesOptions = {
|
|
|
53
53
|
mainModel: RpdDataModel;
|
|
54
54
|
relationProperty: RpdDataModelProperty;
|
|
55
55
|
mainEntityIds: any[];
|
|
56
|
-
selectRelationOptions?:
|
|
56
|
+
selectRelationOptions?: FindEntityFindManyRelationEntitiesOptions;
|
|
57
57
|
};
|
|
58
58
|
|
|
59
59
|
function convertEntityOrderByToRowOrderBy(server: IRpdServer, model: RpdDataModel, baseModel?: RpdDataModel, orderByList?: FindEntityOrderByOptions[]) {
|
|
@@ -583,7 +583,9 @@ async function findManyRelationLinksViaLinkTable(options: FindManyRelationEntiti
|
|
|
583
583
|
const command = `SELECT * FROM ${server.queryBuilder.quoteTable({
|
|
584
584
|
schema: relationProperty.linkSchema,
|
|
585
585
|
tableName: relationProperty.linkTableName!,
|
|
586
|
-
})} WHERE ${server.queryBuilder.quoteObject(relationProperty.selfIdColumnName!)} = ANY($1::int[])
|
|
586
|
+
})} WHERE ${server.queryBuilder.quoteObject(relationProperty.selfIdColumnName!)} = ANY($1::int[])
|
|
587
|
+
ORDER BY id
|
|
588
|
+
`;
|
|
587
589
|
const params = [mainEntityIds];
|
|
588
590
|
const links = await server.queryDatabaseObject(command, params);
|
|
589
591
|
const targetEntityIds = links.map((link) => link[relationProperty.targetIdColumnName!]);
|
|
@@ -612,6 +614,18 @@ async function findManyRelationLinksViaLinkTable(options: FindManyRelationEntiti
|
|
|
612
614
|
if (selectRelationOptions.relations) {
|
|
613
615
|
findEntityOptions.relations = selectRelationOptions.relations;
|
|
614
616
|
}
|
|
617
|
+
if (selectRelationOptions.orderBy) {
|
|
618
|
+
findEntityOptions.orderBy = selectRelationOptions.orderBy;
|
|
619
|
+
}
|
|
620
|
+
if (selectRelationOptions.pagination) {
|
|
621
|
+
findEntityOptions.pagination = selectRelationOptions.pagination;
|
|
622
|
+
}
|
|
623
|
+
if (selectRelationOptions.filters) {
|
|
624
|
+
findEntityOptions.filters = [...findEntityOptions.filters, ...selectRelationOptions.filters];
|
|
625
|
+
}
|
|
626
|
+
if (!isUndefined(selectRelationOptions.keepNonPropertyFields)) {
|
|
627
|
+
findEntityOptions.keepNonPropertyFields = selectRelationOptions.keepNonPropertyFields;
|
|
628
|
+
}
|
|
615
629
|
}
|
|
616
630
|
}
|
|
617
631
|
|
|
@@ -638,6 +652,11 @@ async function findManyRelatedEntitiesViaIdPropertyCode(options: FindManyRelatio
|
|
|
638
652
|
value: mainEntityIds,
|
|
639
653
|
},
|
|
640
654
|
],
|
|
655
|
+
orderBy: [
|
|
656
|
+
{
|
|
657
|
+
field: "id",
|
|
658
|
+
},
|
|
659
|
+
],
|
|
641
660
|
extraColumnsToSelect: [relationProperty.selfIdColumnName],
|
|
642
661
|
keepNonPropertyFields: true,
|
|
643
662
|
};
|
|
@@ -650,6 +669,18 @@ async function findManyRelatedEntitiesViaIdPropertyCode(options: FindManyRelatio
|
|
|
650
669
|
if (selectRelationOptions.relations) {
|
|
651
670
|
findEntityOptions.relations = selectRelationOptions.relations;
|
|
652
671
|
}
|
|
672
|
+
if (selectRelationOptions.orderBy) {
|
|
673
|
+
findEntityOptions.orderBy = selectRelationOptions.orderBy;
|
|
674
|
+
}
|
|
675
|
+
if (selectRelationOptions.pagination) {
|
|
676
|
+
findEntityOptions.pagination = selectRelationOptions.pagination;
|
|
677
|
+
}
|
|
678
|
+
if (selectRelationOptions.filters) {
|
|
679
|
+
findEntityOptions.filters = [...findEntityOptions.filters, ...selectRelationOptions.filters];
|
|
680
|
+
}
|
|
681
|
+
if (!isUndefined(selectRelationOptions.keepNonPropertyFields)) {
|
|
682
|
+
findEntityOptions.keepNonPropertyFields = selectRelationOptions.keepNonPropertyFields;
|
|
683
|
+
}
|
|
653
684
|
}
|
|
654
685
|
}
|
|
655
686
|
|
package/src/types.ts
CHANGED
|
@@ -509,7 +509,7 @@ export interface FindEntityOptions {
|
|
|
509
509
|
orderBy?: FindEntityOrderByOptions[];
|
|
510
510
|
pagination?: FindEntityPaginationOptions;
|
|
511
511
|
properties?: string[];
|
|
512
|
-
relations?: Record<string,
|
|
512
|
+
relations?: Record<string, FindEntityFindRelationEntitiesOptions>;
|
|
513
513
|
extraColumnsToSelect?: ColumnSelectOptions[];
|
|
514
514
|
keepNonPropertyFields?: boolean;
|
|
515
515
|
}
|
|
@@ -518,7 +518,7 @@ export interface FindEntityByIdOptions {
|
|
|
518
518
|
routeContext?: RouteContext;
|
|
519
519
|
id: any;
|
|
520
520
|
properties?: string[];
|
|
521
|
-
relations?: Record<string,
|
|
521
|
+
relations?: Record<string, FindEntityFindRelationEntitiesOptions>;
|
|
522
522
|
keepNonPropertyFields?: boolean;
|
|
523
523
|
}
|
|
524
524
|
|
|
@@ -564,11 +564,25 @@ export interface FindEntityPaginationOptions {
|
|
|
564
564
|
withoutTotal?: boolean;
|
|
565
565
|
}
|
|
566
566
|
|
|
567
|
-
export type
|
|
567
|
+
export type FindEntityFindRelationEntitiesOptions = FindEntityFindOneRelationEntitiesOptions | FindEntityFindManyRelationEntitiesOptions;
|
|
568
|
+
|
|
569
|
+
export type FindEntityFindOneRelationEntitiesOptions =
|
|
570
|
+
| true
|
|
571
|
+
| {
|
|
572
|
+
properties?: string[];
|
|
573
|
+
relations?: Record<string, FindEntityFindRelationEntitiesOptions>;
|
|
574
|
+
keepNonPropertyFields?: boolean;
|
|
575
|
+
};
|
|
576
|
+
|
|
577
|
+
export type FindEntityFindManyRelationEntitiesOptions =
|
|
568
578
|
| true
|
|
569
579
|
| {
|
|
570
580
|
properties?: string[];
|
|
571
|
-
relations?: Record<string,
|
|
581
|
+
relations?: Record<string, FindEntityFindRelationEntitiesOptions>;
|
|
582
|
+
filters?: EntityFilterOptions[];
|
|
583
|
+
orderBy?: FindEntityOrderByOptions[];
|
|
584
|
+
pagination?: FindEntityPaginationOptions;
|
|
585
|
+
keepNonPropertyFields?: boolean;
|
|
572
586
|
};
|
|
573
587
|
|
|
574
588
|
export interface FindEntityOrderByOptions {
|