@ruiapp/rapid-core 0.1.55 → 0.1.57

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.
@@ -6,11 +6,11 @@ export default class EntityManager<TEntity = any> {
6
6
  getModel(): RpdDataModel;
7
7
  findEntities(options: FindEntityOptions): Promise<TEntity[]>;
8
8
  findEntity(options: FindEntityOptions): Promise<TEntity | null>;
9
- findById(options: FindEntityByIdOptions): Promise<TEntity | null>;
9
+ findById(options: FindEntityByIdOptions | string | number): Promise<TEntity | null>;
10
10
  createEntity(options: CreateEntityOptions, plugin?: RapidPlugin): Promise<TEntity>;
11
11
  updateEntityById(options: UpdateEntityByIdOptions, plugin?: RapidPlugin): Promise<TEntity>;
12
12
  count(options: CountEntityOptions): Promise<CountEntityResult>;
13
- deleteById(options: DeleteEntityByIdOptions, plugin?: RapidPlugin): Promise<void>;
13
+ deleteById(options: DeleteEntityByIdOptions | string | number, plugin?: RapidPlugin): Promise<void>;
14
14
  addRelations(options: AddEntityRelationsOptions, plugin?: RapidPlugin): Promise<void>;
15
15
  removeRelations(options: RemoveEntityRelationsOptions, plugin?: RapidPlugin): Promise<void>;
16
16
  }
package/dist/index.js CHANGED
@@ -1999,10 +1999,10 @@ async function findEntities(server, dataAccessor, options) {
1999
1999
  }
2000
2000
  let propertiesToSlect;
2001
2001
  if (!options.properties || !options.properties.length) {
2002
- propertiesToSlect = getEntityPropertiesIncludingBase(server, model).filter(property => !isRelationProperty(property));
2002
+ propertiesToSlect = getEntityPropertiesIncludingBase(server, model).filter((property) => !isRelationProperty(property));
2003
2003
  }
2004
2004
  else {
2005
- propertiesToSlect = getEntityPropertiesIncludingBase(server, model).filter(property => options.properties.includes(property.code));
2005
+ propertiesToSlect = getEntityPropertiesIncludingBase(server, model).filter((property) => options.properties.includes(property.code));
2006
2006
  }
2007
2007
  const columnsToSelect = [];
2008
2008
  const relationPropertiesToSelect = [];
@@ -2044,7 +2044,7 @@ async function findEntities(server, dataAccessor, options) {
2044
2044
  });
2045
2045
  // if `keepNonPropertyFields` is true and `properties` are not specified, then select relation columns automatically.
2046
2046
  if (options.keepNonPropertyFields && (!options.properties || !options.properties.length)) {
2047
- const oneRelationPropertiesWithNoLinkTable = getEntityPropertiesIncludingBase(server, model).filter(property => property.relation === "one" && !property.linkTableName);
2047
+ const oneRelationPropertiesWithNoLinkTable = getEntityPropertiesIncludingBase(server, model).filter((property) => property.relation === "one" && !property.linkTableName);
2048
2048
  oneRelationPropertiesWithNoLinkTable.forEach((property) => {
2049
2049
  if (property.targetIdColumnName) {
2050
2050
  columnsToSelect.push({
@@ -2338,7 +2338,7 @@ async function convertEntityFiltersToRowFilters(server, model, baseModel, filter
2338
2338
  operator: filter.operator,
2339
2339
  field: {
2340
2340
  name: columnName,
2341
- tableName: (property && property.isBaseProperty) ? baseModel.tableName : model.tableName,
2341
+ tableName: property && property.isBaseProperty ? baseModel.tableName : model.tableName,
2342
2342
  },
2343
2343
  value: filter.value,
2344
2344
  itemType: filter.itemType,
@@ -2604,6 +2604,8 @@ async function updateEntityById(server, dataAccessor, options, plugin) {
2604
2604
  modelSingularCode: model.singularCode,
2605
2605
  before: entity,
2606
2606
  changes: options.entityToSave,
2607
+ operation: options.operation,
2608
+ stateProperties: options.stateProperties,
2607
2609
  },
2608
2610
  sender: plugin,
2609
2611
  routeContext: options.routeContext,
@@ -2766,6 +2768,8 @@ async function updateEntityById(server, dataAccessor, options, plugin) {
2766
2768
  before: entity,
2767
2769
  after: updatedEntity,
2768
2770
  changes: changes,
2771
+ operation: options.operation,
2772
+ stateProperties: options.stateProperties,
2769
2773
  },
2770
2774
  sender: plugin,
2771
2775
  routeContext: options.routeContext,
package/dist/types.d.ts CHANGED
@@ -84,6 +84,10 @@ export interface RpdEntityBeforeUpdateEventPayload {
84
84
  baseModelSingularCode?: string;
85
85
  before: any;
86
86
  changes: any;
87
+ operation?: {
88
+ type: string;
89
+ };
90
+ stateProperties?: string[];
87
91
  }
88
92
  export interface RpdEntityUpdateEventPayload {
89
93
  namespace: string;
@@ -92,6 +96,10 @@ export interface RpdEntityUpdateEventPayload {
92
96
  before: any;
93
97
  after: any;
94
98
  changes: any;
99
+ operation?: {
100
+ type: string;
101
+ };
102
+ stateProperties?: string[];
95
103
  }
96
104
  export interface RpdEntityBeforeDeleteEventPayload {
97
105
  namespace: string;
@@ -412,7 +420,9 @@ export interface UpdateEntityByIdOptions {
412
420
  routeContext?: RouteContext;
413
421
  id: any;
414
422
  entityToSave: any;
415
- operation?: any;
423
+ operation?: {
424
+ type: string;
425
+ };
416
426
  stateProperties?: string[];
417
427
  }
418
428
  export interface DeleteEntityOptions {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ruiapp/rapid-core",
3
- "version": "0.1.55",
3
+ "version": "0.1.57",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -68,9 +68,9 @@ async function findEntities(server: IRpdServer, dataAccessor: IRpdDataAccessor,
68
68
 
69
69
  let propertiesToSlect: RpdDataModelProperty[];
70
70
  if (!options.properties || !options.properties.length) {
71
- propertiesToSlect = getEntityPropertiesIncludingBase(server, model).filter(property => !isRelationProperty(property));
71
+ propertiesToSlect = getEntityPropertiesIncludingBase(server, model).filter((property) => !isRelationProperty(property));
72
72
  } else {
73
- propertiesToSlect = getEntityPropertiesIncludingBase(server, model).filter(property => options.properties.includes(property.code));
73
+ propertiesToSlect = getEntityPropertiesIncludingBase(server, model).filter((property) => options.properties.includes(property.code));
74
74
  }
75
75
 
76
76
  const columnsToSelect: ColumnQueryOptions[] = [];
@@ -114,7 +114,7 @@ async function findEntities(server: IRpdServer, dataAccessor: IRpdDataAccessor,
114
114
 
115
115
  // if `keepNonPropertyFields` is true and `properties` are not specified, then select relation columns automatically.
116
116
  if (options.keepNonPropertyFields && (!options.properties || !options.properties.length)) {
117
- const oneRelationPropertiesWithNoLinkTable = getEntityPropertiesIncludingBase(server, model).filter(property => property.relation === "one" && !property.linkTableName);
117
+ const oneRelationPropertiesWithNoLinkTable = getEntityPropertiesIncludingBase(server, model).filter((property) => property.relation === "one" && !property.linkTableName);
118
118
  oneRelationPropertiesWithNoLinkTable.forEach((property) => {
119
119
  if (property.targetIdColumnName) {
120
120
  columnsToSelect.push({
@@ -429,7 +429,7 @@ async function convertEntityFiltersToRowFilters(server: IRpdServer, model: RpdDa
429
429
  operator: filter.operator,
430
430
  field: {
431
431
  name: columnName,
432
- tableName: (property && property.isBaseProperty) ? baseModel.tableName : model.tableName,
432
+ tableName: property && property.isBaseProperty ? baseModel.tableName : model.tableName,
433
433
  },
434
434
  value: (filter as any).value,
435
435
  itemType: (filter as any).itemType,
@@ -721,6 +721,8 @@ async function updateEntityById(server: IRpdServer, dataAccessor: IRpdDataAccess
721
721
  modelSingularCode: model.singularCode,
722
722
  before: entity,
723
723
  changes: options.entityToSave,
724
+ operation: options.operation,
725
+ stateProperties: options.stateProperties,
724
726
  },
725
727
  sender: plugin,
726
728
  routeContext: options.routeContext,
@@ -789,7 +791,7 @@ async function updateEntityById(server: IRpdServer, dataAccessor: IRpdDataAccess
789
791
  updatedEntityOneRelationProps[property.code] = targetEntity;
790
792
  targetRow[property.targetIdColumnName!] = targetEntityId;
791
793
  }
792
- };
794
+ }
793
795
 
794
796
  let updatedRow = row;
795
797
  if (Object.keys(row).length) {
@@ -803,7 +805,7 @@ async function updateEntityById(server: IRpdServer, dataAccessor: IRpdDataAccess
803
805
  updatedBaseRow = await baseDataAccessor.updateById(id, updatedBaseRow);
804
806
  }
805
807
 
806
- let updatedEntity = mapDbRowToEntity(server, model, {...updatedRow, ...updatedBaseRow, ...updatedEntityOneRelationProps}, true);
808
+ let updatedEntity = mapDbRowToEntity(server, model, { ...updatedRow, ...updatedBaseRow, ...updatedEntityOneRelationProps }, true);
807
809
  updatedEntity = Object.assign({}, entity, updatedEntity);
808
810
 
809
811
  // save many-relation properties
@@ -894,6 +896,8 @@ async function updateEntityById(server: IRpdServer, dataAccessor: IRpdDataAccess
894
896
  before: entity,
895
897
  after: updatedEntity,
896
898
  changes: changes,
899
+ operation: options.operation,
900
+ stateProperties: options.stateProperties,
897
901
  },
898
902
  sender: plugin,
899
903
  routeContext: options.routeContext,
@@ -923,7 +927,7 @@ export default class EntityManager<TEntity = any> {
923
927
  return await findEntity(this.#server, this.#dataAccessor, options);
924
928
  }
925
929
 
926
- async findById(options: FindEntityByIdOptions): Promise<TEntity | null> {
930
+ async findById(options: FindEntityByIdOptions | string | number): Promise<TEntity | null> {
927
931
  // options is id
928
932
  if (!isObject(options)) {
929
933
  options = {
@@ -951,11 +955,11 @@ export default class EntityManager<TEntity = any> {
951
955
  }
952
956
  const countRowOptions: CountRowOptions = {
953
957
  filters: await convertEntityFiltersToRowFilters(this.#server, model, baseModel, options.filters),
954
- }
958
+ };
955
959
  return await this.#dataAccessor.count(countRowOptions);
956
960
  }
957
961
 
958
- async deleteById(options: DeleteEntityByIdOptions, plugin?: RapidPlugin): Promise<void> {
962
+ async deleteById(options: DeleteEntityByIdOptions | string | number, plugin?: RapidPlugin): Promise<void> {
959
963
  // options is id
960
964
  if (!isObject(options)) {
961
965
  options = {
package/src/types.ts CHANGED
@@ -99,6 +99,10 @@ export interface RpdEntityBeforeUpdateEventPayload {
99
99
  baseModelSingularCode?: string;
100
100
  before: any;
101
101
  changes: any;
102
+ operation?: {
103
+ type: string;
104
+ };
105
+ stateProperties?: string[];
102
106
  }
103
107
 
104
108
  export interface RpdEntityUpdateEventPayload {
@@ -108,6 +112,10 @@ export interface RpdEntityUpdateEventPayload {
108
112
  before: any;
109
113
  after: any;
110
114
  changes: any;
115
+ operation?: {
116
+ type: string;
117
+ };
118
+ stateProperties?: string[];
111
119
  }
112
120
 
113
121
  export interface RpdEntityBeforeDeleteEventPayload {
@@ -481,7 +489,9 @@ export interface UpdateEntityByIdOptions {
481
489
  routeContext?: RouteContext;
482
490
  id: any;
483
491
  entityToSave: any;
484
- operation?: any;
492
+ operation?: {
493
+ type: string;
494
+ };
485
495
  stateProperties?: string[];
486
496
  }
487
497