@triproject/nestjs-core 1.0.49 → 1.0.50

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.
@@ -19,12 +19,9 @@ export declare class Repository<M extends Model<M, Partial<M>> & {
19
19
  label: string;
20
20
  value: string | number;
21
21
  }>(params: PaginateRequest<M>, mapInto: (data: M) => P): Promise<P[]>;
22
- protected _paginate<P>(params: PaginateRequest<M>): Promise<PaginateResponse<M>>;
23
- protected _paginate<P>(params: PaginateRequest<M>, mapInto: new (data: M) => P): Promise<PaginateResponse<P>>;
24
- protected _paginateCursor(params: PaginateCursorRequest<M>): Promise<PaginateCursorResponse<M>>;
25
- protected _paginateCursor<P>(params: PaginateCursorRequest<M>, mapInto: new (data: M) => P): Promise<PaginateCursorResponse<P>>;
22
+ protected _paginate(params: PaginateRequest<M>): Promise<PaginateResponse<M>>;
23
+ protected _paginateCursor<P>(params: PaginateCursorRequest<M>): Promise<PaginateCursorResponse<P | M>>;
26
24
  protected _export(params: PaginateRequest<M>): Promise<M[]>;
27
- protected _export(params: PaginateRequest<M>, mapInto: new (data: M) => string[]): Promise<string[][]>;
28
25
  protected _updateOrCreate(values: CreationAttributes<M>, whereOptions: WhereOptions<M>, options?: CreateOptions<M> | UpdateOptions<M>): Promise<M>;
29
26
  protected _findAll(options?: FindOptions<M>): Promise<M[]>;
30
27
  protected _findAndCountAll(options: FindAndCountOptions<M>): Promise<{
@@ -126,7 +126,7 @@ let Repository = class Repository {
126
126
  limit
127
127
  })).map((d)=>mapInto(d));
128
128
  }
129
- async _paginate(params, mapInto) {
129
+ async _paginate(params) {
130
130
  let options = this._getOptions(params), limit = +(params?.perPage ?? 20), page = +(params?.page ?? 1), data = await this._findAndCountAll({
131
131
  limit,
132
132
  offset: page > 1 ? limit * (page - 1) : 0,
@@ -136,7 +136,7 @@ let Repository = class Repository {
136
136
  data.count = Array.isArray(data.count) ? data.count.length : data.count;
137
137
  let totalPage = Math.ceil(data.count / limit);
138
138
  return {
139
- data: mapInto ? data.rows.map((d)=>new mapInto(d)) : data.rows,
139
+ data: data.rows,
140
140
  timestamp: (0, _helpers.dateUtil)().utc().toISOString(),
141
141
  meta: {
142
142
  perPage: limit,
@@ -148,7 +148,7 @@ let Repository = class Repository {
148
148
  }
149
149
  };
150
150
  }
151
- async _paginateCursor(params, mapInto) {
151
+ async _paginateCursor(params) {
152
152
  if (!this.FIELDS?.includes('id')) throw new _common.UnprocessableEntityException('Entity must have id attribute for cursor pagination');
153
153
  params.attributes = (0, _helpers.uniqueArray)([
154
154
  ...params.attributes || [],
@@ -166,7 +166,7 @@ let Repository = class Repository {
166
166
  limit
167
167
  }), lastId = data[data.length - 1]?.id, nextCursor = data.length > 0 && lastId ? String(lastId) : null;
168
168
  return {
169
- data: mapInto ? data.map((d)=>new mapInto(d)) : data,
169
+ data,
170
170
  timestamp: (0, _helpers.dateUtil)().utc().toISOString(),
171
171
  meta: {
172
172
  perPage: limit,
@@ -174,9 +174,9 @@ let Repository = class Repository {
174
174
  }
175
175
  };
176
176
  }
177
- async _export(params, mapInto) {
178
- let options = this._getOptions(params), data = await this._findAll(options);
179
- return mapInto ? data.map((d)=>new mapInto(d)) : data;
177
+ async _export(params) {
178
+ let options = this._getOptions(params);
179
+ return await this._findAll(options);
180
180
  }
181
181
  async _updateOrCreate(values, whereOptions, options) {
182
182
  let data = await this._findOne({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@triproject/nestjs-core",
3
- "version": "1.0.49",
3
+ "version": "1.0.50",
4
4
  "author": "",
5
5
  "license": "ISC",
6
6
  "description": "A collection of NestJS modules and utilities to speed up development.",