@ruiapp/rapid-core 0.2.0 → 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 +40 -2
- package/dist/types.d.ts +14 -4
- package/package.json +1 -1
- package/src/dataAccess/entityManager.ts +46 -7
- 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
|
@@ -2691,10 +2691,14 @@ async function convertEntityFiltersToRowFilters(server, model, baseModel, filter
|
|
|
2691
2691
|
else {
|
|
2692
2692
|
const filterField = filter.field;
|
|
2693
2693
|
let property = getEntityPropertyByCode(server, model, filterField);
|
|
2694
|
+
let filterValue = filter.value;
|
|
2694
2695
|
let columnName = "";
|
|
2695
2696
|
if (property) {
|
|
2696
2697
|
if (isOneRelationProperty(property)) {
|
|
2697
2698
|
columnName = property.targetIdColumnName;
|
|
2699
|
+
if (lodash.isPlainObject(filterValue)) {
|
|
2700
|
+
filterValue = filterValue.id;
|
|
2701
|
+
}
|
|
2698
2702
|
}
|
|
2699
2703
|
else if (isManyRelationProperty(property)) {
|
|
2700
2704
|
throw new Error(`Operator "${operator}" is not supported on many-relation property "${property.code}"`);
|
|
@@ -2716,6 +2720,9 @@ async function convertEntityFiltersToRowFilters(server, model, baseModel, filter
|
|
|
2716
2720
|
});
|
|
2717
2721
|
if (property) {
|
|
2718
2722
|
columnName = property.targetIdColumnName;
|
|
2723
|
+
if (lodash.isPlainObject(filterValue)) {
|
|
2724
|
+
filterValue = filterValue.id;
|
|
2725
|
+
}
|
|
2719
2726
|
}
|
|
2720
2727
|
else {
|
|
2721
2728
|
columnName = filterField;
|
|
@@ -2729,7 +2736,7 @@ async function convertEntityFiltersToRowFilters(server, model, baseModel, filter
|
|
|
2729
2736
|
name: columnName,
|
|
2730
2737
|
tableName: property && property.isBaseProperty ? baseModel.tableName : model.tableName,
|
|
2731
2738
|
},
|
|
2732
|
-
value:
|
|
2739
|
+
value: filterValue,
|
|
2733
2740
|
itemType: filter.itemType,
|
|
2734
2741
|
});
|
|
2735
2742
|
}
|
|
@@ -2741,7 +2748,9 @@ async function findManyRelationLinksViaLinkTable(options) {
|
|
|
2741
2748
|
const command = `SELECT * FROM ${server.queryBuilder.quoteTable({
|
|
2742
2749
|
schema: relationProperty.linkSchema,
|
|
2743
2750
|
tableName: relationProperty.linkTableName,
|
|
2744
|
-
})} WHERE ${server.queryBuilder.quoteObject(relationProperty.selfIdColumnName)} = ANY($1::int[])
|
|
2751
|
+
})} WHERE ${server.queryBuilder.quoteObject(relationProperty.selfIdColumnName)} = ANY($1::int[])
|
|
2752
|
+
ORDER BY id
|
|
2753
|
+
`;
|
|
2745
2754
|
const params = [mainEntityIds];
|
|
2746
2755
|
const links = await server.queryDatabaseObject(command, params);
|
|
2747
2756
|
const targetEntityIds = links.map((link) => link[relationProperty.targetIdColumnName]);
|
|
@@ -2767,6 +2776,18 @@ async function findManyRelationLinksViaLinkTable(options) {
|
|
|
2767
2776
|
if (selectRelationOptions.relations) {
|
|
2768
2777
|
findEntityOptions.relations = selectRelationOptions.relations;
|
|
2769
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
|
+
}
|
|
2770
2791
|
}
|
|
2771
2792
|
}
|
|
2772
2793
|
const targetEntities = await findEntities(server, dataAccessor, findEntityOptions);
|
|
@@ -2788,6 +2809,11 @@ async function findManyRelatedEntitiesViaIdPropertyCode(options) {
|
|
|
2788
2809
|
value: mainEntityIds,
|
|
2789
2810
|
},
|
|
2790
2811
|
],
|
|
2812
|
+
orderBy: [
|
|
2813
|
+
{
|
|
2814
|
+
field: "id",
|
|
2815
|
+
},
|
|
2816
|
+
],
|
|
2791
2817
|
extraColumnsToSelect: [relationProperty.selfIdColumnName],
|
|
2792
2818
|
keepNonPropertyFields: true,
|
|
2793
2819
|
};
|
|
@@ -2799,6 +2825,18 @@ async function findManyRelatedEntitiesViaIdPropertyCode(options) {
|
|
|
2799
2825
|
if (selectRelationOptions.relations) {
|
|
2800
2826
|
findEntityOptions.relations = selectRelationOptions.relations;
|
|
2801
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
|
+
}
|
|
2802
2840
|
}
|
|
2803
2841
|
}
|
|
2804
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, 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[]) {
|
|
@@ -526,10 +526,15 @@ async function convertEntityFiltersToRowFilters(
|
|
|
526
526
|
const filterField = (filter as EntityNonRelationPropertyFilterOptions).field;
|
|
527
527
|
let property: RpdDataModelProperty = getEntityPropertyByCode(server, model, filterField);
|
|
528
528
|
|
|
529
|
+
let filterValue = (filter as any).value;
|
|
530
|
+
|
|
529
531
|
let columnName = "";
|
|
530
532
|
if (property) {
|
|
531
533
|
if (isOneRelationProperty(property)) {
|
|
532
534
|
columnName = property.targetIdColumnName;
|
|
535
|
+
if (isPlainObject(filterValue)) {
|
|
536
|
+
filterValue = filterValue.id;
|
|
537
|
+
}
|
|
533
538
|
} else if (isManyRelationProperty(property)) {
|
|
534
539
|
throw new Error(`Operator "${operator}" is not supported on many-relation property "${property.code}"`);
|
|
535
540
|
} else {
|
|
@@ -549,6 +554,9 @@ async function convertEntityFiltersToRowFilters(
|
|
|
549
554
|
|
|
550
555
|
if (property) {
|
|
551
556
|
columnName = property.targetIdColumnName;
|
|
557
|
+
if (isPlainObject(filterValue)) {
|
|
558
|
+
filterValue = filterValue.id;
|
|
559
|
+
}
|
|
552
560
|
} else {
|
|
553
561
|
columnName = filterField;
|
|
554
562
|
}
|
|
@@ -562,7 +570,7 @@ async function convertEntityFiltersToRowFilters(
|
|
|
562
570
|
name: columnName,
|
|
563
571
|
tableName: property && property.isBaseProperty ? baseModel.tableName : model.tableName,
|
|
564
572
|
},
|
|
565
|
-
value:
|
|
573
|
+
value: filterValue,
|
|
566
574
|
itemType: (filter as any).itemType,
|
|
567
575
|
} as any);
|
|
568
576
|
}
|
|
@@ -575,7 +583,9 @@ async function findManyRelationLinksViaLinkTable(options: FindManyRelationEntiti
|
|
|
575
583
|
const command = `SELECT * FROM ${server.queryBuilder.quoteTable({
|
|
576
584
|
schema: relationProperty.linkSchema,
|
|
577
585
|
tableName: relationProperty.linkTableName!,
|
|
578
|
-
})} WHERE ${server.queryBuilder.quoteObject(relationProperty.selfIdColumnName!)} = ANY($1::int[])
|
|
586
|
+
})} WHERE ${server.queryBuilder.quoteObject(relationProperty.selfIdColumnName!)} = ANY($1::int[])
|
|
587
|
+
ORDER BY id
|
|
588
|
+
`;
|
|
579
589
|
const params = [mainEntityIds];
|
|
580
590
|
const links = await server.queryDatabaseObject(command, params);
|
|
581
591
|
const targetEntityIds = links.map((link) => link[relationProperty.targetIdColumnName!]);
|
|
@@ -604,6 +614,18 @@ async function findManyRelationLinksViaLinkTable(options: FindManyRelationEntiti
|
|
|
604
614
|
if (selectRelationOptions.relations) {
|
|
605
615
|
findEntityOptions.relations = selectRelationOptions.relations;
|
|
606
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
|
+
}
|
|
607
629
|
}
|
|
608
630
|
}
|
|
609
631
|
|
|
@@ -630,6 +652,11 @@ async function findManyRelatedEntitiesViaIdPropertyCode(options: FindManyRelatio
|
|
|
630
652
|
value: mainEntityIds,
|
|
631
653
|
},
|
|
632
654
|
],
|
|
655
|
+
orderBy: [
|
|
656
|
+
{
|
|
657
|
+
field: "id",
|
|
658
|
+
},
|
|
659
|
+
],
|
|
633
660
|
extraColumnsToSelect: [relationProperty.selfIdColumnName],
|
|
634
661
|
keepNonPropertyFields: true,
|
|
635
662
|
};
|
|
@@ -642,6 +669,18 @@ async function findManyRelatedEntitiesViaIdPropertyCode(options: FindManyRelatio
|
|
|
642
669
|
if (selectRelationOptions.relations) {
|
|
643
670
|
findEntityOptions.relations = selectRelationOptions.relations;
|
|
644
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
|
+
}
|
|
645
684
|
}
|
|
646
685
|
}
|
|
647
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 {
|