@ruiapp/rapid-core 0.1.15 → 0.1.17

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,7 +6,7 @@ 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(id: any): Promise<TEntity | null>;
9
+ findById(id: any, keepNonPropertyFields?: boolean): 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>;
@@ -1,3 +1,3 @@
1
1
  import { RpdDataModel } from "../types";
2
- export declare function mapDbRowToEntity(model: RpdDataModel, row: any): any;
2
+ export declare function mapDbRowToEntity(model: RpdDataModel, row: any, keepNonPropertyFields: boolean): any;
3
3
  export declare function mapEntityToDbRow(model: RpdDataModel, entity: any): any;
package/dist/index.js CHANGED
@@ -1616,7 +1616,7 @@ function isRelationProperty(property) {
1616
1616
  }
1617
1617
 
1618
1618
  // TODO Generate mapper and cache it.
1619
- function mapDbRowToEntity(model, row) {
1619
+ function mapDbRowToEntity(model, row, keepNonPropertyFields) {
1620
1620
  if (!row) {
1621
1621
  return null;
1622
1622
  }
@@ -1638,6 +1638,9 @@ function mapDbRowToEntity(model, row) {
1638
1638
  isRelationProp = true;
1639
1639
  propertyName = property.code;
1640
1640
  }
1641
+ else if (keepNonPropertyFields) {
1642
+ propertyName = columnName;
1643
+ }
1641
1644
  }
1642
1645
  if (isRelationProp) {
1643
1646
  if (row[propertyName] && !result[propertyName]) {
@@ -1775,7 +1778,7 @@ async function findEntities(server, dataAccessor, options) {
1775
1778
  ___namespace.forEach(entities, (entity) => {
1776
1779
  entity[relationProperty.code] = ___namespace.filter(relationLinks, (link) => {
1777
1780
  return link[relationProperty.selfIdColumnName] == entity["id"];
1778
- }).map(link => mapDbRowToEntity(targetModel, link.targetEntity));
1781
+ }).map(link => mapDbRowToEntity(targetModel, link.targetEntity, false));
1779
1782
  });
1780
1783
  }
1781
1784
  }
@@ -1795,25 +1798,25 @@ async function findEntities(server, dataAccessor, options) {
1795
1798
  if (isManyRelation) {
1796
1799
  entity[relationProperty.code] = ___namespace.filter(relatedEntities, (relatedEntity) => {
1797
1800
  return relatedEntity[relationProperty.selfIdColumnName] == entity.id;
1798
- }).map(item => mapDbRowToEntity(targetModel, item));
1801
+ }).map(item => mapDbRowToEntity(targetModel, item, false));
1799
1802
  }
1800
1803
  else {
1801
1804
  entity[relationProperty.code] = mapDbRowToEntity(targetModel, ___namespace.find(relatedEntities, (relatedEntity) => {
1802
1805
  // TODO: id property code should be configurable.
1803
1806
  return relatedEntity["id"] == entity[relationProperty.targetIdColumnName];
1804
- }));
1807
+ }), false);
1805
1808
  }
1806
1809
  });
1807
1810
  }
1808
1811
  }
1809
1812
  }
1810
- return entities.map(item => mapDbRowToEntity(model, item));
1813
+ return entities.map(item => mapDbRowToEntity(model, item, options.keepNonPropertyFields));
1811
1814
  }
1812
1815
  async function findEntity(server, dataAccessor, options) {
1813
1816
  const entities = await findEntities(server, dataAccessor, options);
1814
1817
  return ___namespace.first(entities);
1815
1818
  }
1816
- async function findById(server, dataAccessor, id) {
1819
+ async function findById(server, dataAccessor, id, keepNonPropertyFields = false) {
1817
1820
  return await findEntity(server, dataAccessor, {
1818
1821
  filters: [
1819
1822
  {
@@ -1821,7 +1824,8 @@ async function findById(server, dataAccessor, id) {
1821
1824
  field: "id",
1822
1825
  value: id,
1823
1826
  }
1824
- ]
1827
+ ],
1828
+ keepNonPropertyFields,
1825
1829
  });
1826
1830
  }
1827
1831
  async function replaceFiltersWithFiltersOperator(server, model, filters) {
@@ -2042,7 +2046,7 @@ async function createEntity(server, dataAccessor, options) {
2042
2046
  }
2043
2047
  }
2044
2048
  const newRow = await dataAccessor.create(row);
2045
- const newEntity = mapDbRowToEntity(model, newRow);
2049
+ const newEntity = mapDbRowToEntity(model, newRow, false);
2046
2050
  // save many-relation properties
2047
2051
  for (const property of manyRelationPropertiesToCreate) {
2048
2052
  newEntity[property.code] = [];
@@ -2257,8 +2261,8 @@ class EntityManager {
2257
2261
  async findEntity(options) {
2258
2262
  return await findEntity(this.#server, this.#dataAccessor, options);
2259
2263
  }
2260
- async findById(id) {
2261
- return await findById(this.#server, this.#dataAccessor, id);
2264
+ async findById(id, keepNonPropertyFields = false) {
2265
+ return await findById(this.#server, this.#dataAccessor, id, keepNonPropertyFields);
2262
2266
  }
2263
2267
  async createEntity(options, plugin) {
2264
2268
  const model = this.getModel();
@@ -2278,7 +2282,7 @@ class EntityManager {
2278
2282
  }
2279
2283
  async deleteById(id, plugin) {
2280
2284
  const model = this.getModel();
2281
- const entity = await this.findById(id);
2285
+ const entity = await this.findById(id, true);
2282
2286
  if (!entity) {
2283
2287
  return;
2284
2288
  }
@@ -3231,6 +3235,7 @@ async function handler$b(plugin, ctx, options) {
3231
3235
  const entityManager = server.getEntityManager(options.singularCode);
3232
3236
  await entityManager.deleteById(input.id, plugin);
3233
3237
  ctx.status = 200;
3238
+ ctx.output = {};
3234
3239
  }
3235
3240
 
3236
3241
  var deleteCollectionEntityById = /*#__PURE__*/Object.freeze({
package/dist/types.d.ts CHANGED
@@ -272,6 +272,7 @@ export interface FindEntityOptions {
272
272
  orderBy?: FindEntityOrderByOptions[];
273
273
  pagination?: FindEntityPaginationOptions;
274
274
  properties?: string[] | Record<string, any>;
275
+ keepNonPropertyFields?: boolean;
275
276
  }
276
277
  export interface FindEntityRelationalFilterOptions {
277
278
  field: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ruiapp/rapid-core",
3
- "version": "0.1.15",
3
+ "version": "0.1.17",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "keywords": [],
@@ -107,7 +107,7 @@ async function findEntities(
107
107
  _.forEach(entities, (entity: any) => {
108
108
  entity[relationProperty.code] = _.filter(relationLinks, (link: any) => {
109
109
  return link[relationProperty.selfIdColumnName!] == entity["id"];
110
- }).map(link => mapDbRowToEntity(targetModel, link.targetEntity));
110
+ }).map(link => mapDbRowToEntity(targetModel, link.targetEntity, false));
111
111
  });
112
112
  }
113
113
  } else {
@@ -147,7 +147,7 @@ async function findEntities(
147
147
  (relatedEntity: any) => {
148
148
  return relatedEntity[relationProperty.selfIdColumnName!] == entity.id;
149
149
  },
150
- ).map(item => mapDbRowToEntity(targetModel!, item));
150
+ ).map(item => mapDbRowToEntity(targetModel!, item, false));
151
151
  } else {
152
152
  entity[relationProperty.code] = mapDbRowToEntity(targetModel!, _.find(
153
153
  relatedEntities,
@@ -155,13 +155,13 @@ async function findEntities(
155
155
  // TODO: id property code should be configurable.
156
156
  return relatedEntity["id"] == entity[relationProperty.targetIdColumnName!];
157
157
  },
158
- ));
158
+ ), false);
159
159
  }
160
160
  });
161
161
  }
162
162
  }
163
163
  }
164
- return entities.map(item => mapDbRowToEntity(model, item));
164
+ return entities.map(item => mapDbRowToEntity(model, item, options.keepNonPropertyFields));
165
165
  }
166
166
 
167
167
  async function findEntity(
@@ -177,6 +177,7 @@ async function findById(
177
177
  server: IRpdServer,
178
178
  dataAccessor: IRpdDataAccessor,
179
179
  id: any,
180
+ keepNonPropertyFields: boolean = false
180
181
  ): Promise<any> {
181
182
  return await findEntity(server, dataAccessor, {
182
183
  filters: [
@@ -185,7 +186,8 @@ async function findById(
185
186
  field: "id",
186
187
  value: id,
187
188
  }
188
- ]
189
+ ],
190
+ keepNonPropertyFields,
189
191
  });
190
192
  }
191
193
 
@@ -468,8 +470,7 @@ async function createEntity(
468
470
  }
469
471
 
470
472
  const newRow = await dataAccessor.create(row);
471
- const newEntity = mapDbRowToEntity(model, newRow);
472
-
473
+ const newEntity = mapDbRowToEntity(model, newRow, false);
473
474
 
474
475
  // save many-relation properties
475
476
  for (const property of manyRelationPropertiesToCreate) {
@@ -717,8 +718,8 @@ export default class EntityManager<TEntity=any> {
717
718
  return await findEntity(this.#server, this.#dataAccessor, options);
718
719
  }
719
720
 
720
- async findById(id: any): Promise<TEntity | null> {
721
- return await findById(this.#server, this.#dataAccessor, id);
721
+ async findById(id: any, keepNonPropertyFields: boolean = false): Promise<TEntity | null> {
722
+ return await findById(this.#server, this.#dataAccessor, id, keepNonPropertyFields);
722
723
  }
723
724
 
724
725
  async createEntity(options: CreateEntityOptions, plugin: RapidPlugin): Promise<TEntity> {
@@ -748,7 +749,7 @@ export default class EntityManager<TEntity=any> {
748
749
 
749
750
  async deleteById(id: any, plugin: RapidPlugin): Promise<void> {
750
751
  const model = this.getModel();
751
- const entity = await this.findById(id);
752
+ const entity = await this.findById(id, true);
752
753
  if (!entity) {
753
754
  return;
754
755
  }
@@ -3,7 +3,7 @@ import { isRelationProperty } from "~/utilities/rapidUtility";
3
3
 
4
4
  // TODO Generate mapper and cache it.
5
5
 
6
- export function mapDbRowToEntity(model: RpdDataModel, row: any) {
6
+ export function mapDbRowToEntity(model: RpdDataModel, row: any, keepNonPropertyFields: boolean) {
7
7
  if (!row) {
8
8
  return null;
9
9
  }
@@ -25,6 +25,8 @@ export function mapDbRowToEntity(model: RpdDataModel, row: any) {
25
25
  if (property) {
26
26
  isRelationProp = true;
27
27
  propertyName = property.code;
28
+ } else if (keepNonPropertyFields) {
29
+ propertyName = columnName;
28
30
  }
29
31
  }
30
32
 
@@ -1,5 +1,4 @@
1
1
  import { RunEntityActionHandlerOptions } from "~/types";
2
- import { mapDbRowToEntity } from "~/dataAccess/entityMapper";
3
2
  import { ActionHandlerContext } from "~/core/actionHandler";
4
3
  import { RapidPlugin } from "~/core/server";
5
4
 
@@ -17,4 +16,5 @@ export async function handler(
17
16
  await entityManager.deleteById(input.id, plugin);
18
17
 
19
18
  ctx.status = 200;
19
+ ctx.output = {};
20
20
  }
@@ -1,7 +1,5 @@
1
1
  import { RunEntityActionHandlerOptions } from "~/types";
2
- import { getEntityPartChanges } from "~/helpers/entityHelpers";
3
2
  import { mergeInput } from "~/helpers/inputHelper";
4
- import { mapDbRowToEntity } from "~/dataAccess/entityMapper";
5
3
  import { ActionHandlerContext } from "~/core/actionHandler";
6
4
  import { RapidPlugin } from "~/core/server";
7
5
 
package/src/types.ts CHANGED
@@ -370,6 +370,7 @@ export interface FindEntityOptions {
370
370
  orderBy?: FindEntityOrderByOptions[];
371
371
  pagination?: FindEntityPaginationOptions;
372
372
  properties?: string[] | Record<string, any>;
373
+ keepNonPropertyFields?: boolean;
373
374
  }
374
375
 
375
376
  export interface FindEntityRelationalFilterOptions {