@ruiapp/rapid-core 0.2.7 → 0.2.8

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.
@@ -17,6 +17,6 @@ export default class DataAccessor<T = any> implements IRpdDataAccessor<T> {
17
17
  find(options: FindRowOptions): Promise<T[]>;
18
18
  findOne(options: FindRowOptions): Promise<T>;
19
19
  findById(id: any): Promise<T | null>;
20
- count(options: CountRowOptions): Promise<any>;
20
+ count(options: CountRowOptions): Promise<number>;
21
21
  deleteById(id: any): Promise<void>;
22
22
  }
@@ -1,4 +1,4 @@
1
- import { AddEntityRelationsOptions, CountEntityOptions, CountEntityResult, CreateEntityOptions, DeleteEntityByIdOptions, FindEntityByIdOptions, FindEntityOptions, IRpdDataAccessor, RemoveEntityRelationsOptions, RpdDataModel, RpdDataModelIndex, RpdDataModelProperty, UpdateEntityByIdOptions, FindEntityFindOneRelationEntitiesOptions, FindEntityFindManyRelationEntitiesOptions } from "../types";
1
+ import { AddEntityRelationsOptions, CountEntityOptions, 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 = {
@@ -30,7 +30,7 @@ export default class EntityManager<TEntity = any> {
30
30
  findById(options: FindEntityByIdOptions | string | number): Promise<TEntity | null>;
31
31
  createEntity(options: CreateEntityOptions, plugin?: RapidPlugin): Promise<TEntity>;
32
32
  updateEntityById(options: UpdateEntityByIdOptions, plugin?: RapidPlugin): Promise<TEntity>;
33
- count(options: CountEntityOptions): Promise<CountEntityResult>;
33
+ count(options: CountEntityOptions): Promise<number>;
34
34
  deleteById(options: DeleteEntityByIdOptions | string | number, plugin?: RapidPlugin): Promise<void>;
35
35
  addRelations(options: AddEntityRelationsOptions, plugin?: RapidPlugin): Promise<void>;
36
36
  removeRelations(options: RemoveEntityRelationsOptions, plugin?: RapidPlugin): Promise<void>;
package/dist/index.js CHANGED
@@ -159,11 +159,9 @@ class DataAccessor {
159
159
  const result = await this.#databaseAccessor.queryDatabaseObject(query.command, query.params);
160
160
  const row = lodash.first(result);
161
161
  if (row) {
162
- return row;
162
+ return row.count;
163
163
  }
164
- return {
165
- count: 0,
166
- };
164
+ return 0;
167
165
  }
168
166
  async deleteById(id) {
169
167
  const options = {
@@ -4790,8 +4788,8 @@ async function handler$q(plugin, ctx, options) {
4790
4788
  const result = { list: entities };
4791
4789
  if (input.pagination && !input.pagination.withoutTotal) {
4792
4790
  // TOOD: count entities when calling findEntities for performance.
4793
- const countResult = await entityManager.count(input);
4794
- result.total = countResult.count;
4791
+ const total = await entityManager.count(input);
4792
+ result.total = total;
4795
4793
  }
4796
4794
  return result;
4797
4795
  });
@@ -4827,10 +4825,11 @@ var findCollectionEntityById = /*#__PURE__*/Object.freeze({
4827
4825
 
4828
4826
  const code$o = "countCollectionEntities";
4829
4827
  async function handler$o(plugin, ctx, options) {
4830
- await runCollectionEntityActionHandler(ctx, options, code$o, (entityManager, input) => {
4828
+ await runCollectionEntityActionHandler(ctx, options, code$o, async (entityManager, input) => {
4831
4829
  input.filters = removeFiltersWithNullValue(input.filters);
4832
4830
  input.routeContext = ctx.routerContext;
4833
- return entityManager.count(input);
4831
+ const count = await entityManager.count(input);
4832
+ return { count };
4834
4833
  });
4835
4834
  }
4836
4835
 
package/dist/types.d.ts CHANGED
@@ -377,7 +377,7 @@ export interface IRpdDataAccessor<T = any> {
377
377
  find(options: FindRowOptions): Promise<T[]>;
378
378
  findOne(options: FindRowOptions): Promise<T | null>;
379
379
  findById(id: any): Promise<T | null>;
380
- count(options: CountRowOptions): Promise<any>;
380
+ count(options: CountRowOptions): Promise<number>;
381
381
  deleteById(id: any): Promise<void>;
382
382
  }
383
383
  export type EntityFilterRelationalOperators = "eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "contains" | "notContains" | "containsCS" | "notContainsCS" | "startsWith" | "notStartsWith" | "endsWith" | "notEndsWith";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ruiapp/rapid-core",
3
- "version": "0.2.7",
3
+ "version": "0.2.8",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -98,7 +98,7 @@ export default class DataAccessor<T = any> implements IRpdDataAccessor<T> {
98
98
  return result;
99
99
  }
100
100
 
101
- async count(options: CountRowOptions): Promise<any> {
101
+ async count(options: CountRowOptions): Promise<number> {
102
102
  let query: DatabaseQuery;
103
103
  if (this.#model.base) {
104
104
  const baseModel = this.#server.getModel({
@@ -112,11 +112,9 @@ export default class DataAccessor<T = any> implements IRpdDataAccessor<T> {
112
112
 
113
113
  const row = first(result);
114
114
  if (row) {
115
- return row;
115
+ return row.count;
116
116
  }
117
- return {
118
- count: 0,
119
- };
117
+ return 0;
120
118
  }
121
119
 
122
120
  async deleteById(id: any) {
@@ -1,7 +1,6 @@
1
1
  import {
2
2
  AddEntityRelationsOptions,
3
3
  CountEntityOptions,
4
- CountEntityResult,
5
4
  CreateEntityOptions,
6
5
  DeleteEntityByIdOptions,
7
6
  EntityFilterOperators,
@@ -1459,7 +1458,7 @@ export default class EntityManager<TEntity = any> {
1459
1458
  return await updateEntityById(this.#server, this.#dataAccessor, options, plugin);
1460
1459
  }
1461
1460
 
1462
- async count(options: CountEntityOptions): Promise<CountEntityResult> {
1461
+ async count(options: CountEntityOptions): Promise<number> {
1463
1462
  const model = this.#dataAccessor.getModel();
1464
1463
  let baseModel: RpdDataModel;
1465
1464
  if (model.base) {
@@ -1,4 +1,4 @@
1
- import { CountEntityOptions, RunEntityActionHandlerOptions } from "~/types";
1
+ import { CountEntityOptions, CountEntityResult, RunEntityActionHandlerOptions } from "~/types";
2
2
  import runCollectionEntityActionHandler from "~/helpers/runCollectionEntityActionHandler";
3
3
  import { removeFiltersWithNullValue } from "~/helpers/filterHelper";
4
4
  import { ActionHandlerContext } from "~/core/actionHandler";
@@ -7,9 +7,10 @@ import { RapidPlugin } from "~/core/server";
7
7
  export const code = "countCollectionEntities";
8
8
 
9
9
  export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: RunEntityActionHandlerOptions) {
10
- await runCollectionEntityActionHandler(ctx, options, code, (entityManager, input: CountEntityOptions) => {
10
+ await runCollectionEntityActionHandler(ctx, options, code, async (entityManager, input: CountEntityOptions): Promise<CountEntityResult> => {
11
11
  input.filters = removeFiltersWithNullValue(input.filters);
12
12
  input.routeContext = ctx.routerContext;
13
- return entityManager.count(input);
13
+ const count = await entityManager.count(input);
14
+ return { count };
14
15
  });
15
16
  }
@@ -18,8 +18,8 @@ export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, op
18
18
 
19
19
  if (input.pagination && !input.pagination.withoutTotal) {
20
20
  // TOOD: count entities when calling findEntities for performance.
21
- const countResult = await entityManager.count(input);
22
- result.total = countResult.count;
21
+ const total = await entityManager.count(input);
22
+ result.total = total;
23
23
  }
24
24
  return result;
25
25
  });
package/src/types.ts CHANGED
@@ -456,7 +456,7 @@ export interface IRpdDataAccessor<T = any> {
456
456
  find(options: FindRowOptions): Promise<T[]>;
457
457
  findOne(options: FindRowOptions): Promise<T | null>;
458
458
  findById(id: any): Promise<T | null>;
459
- count(options: CountRowOptions): Promise<any>;
459
+ count(options: CountRowOptions): Promise<number>;
460
460
  deleteById(id: any): Promise<void>;
461
461
  }
462
462