@clairejs/server 3.19.0 → 3.19.1

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/README.md CHANGED
@@ -1,7 +1,8 @@
1
1
  ## Change Log
2
2
 
3
- #### 3.19.0:
3
+ #### 3.19.1:
4
4
 
5
+ - fix ModelRepository getMany
5
6
  - adapt interface with new claire orm
6
7
 
7
8
  #### 3.18.2:
@@ -197,7 +197,6 @@ export class CrudHttpController extends AbstractHttpController {
197
197
  async getMany(req) {
198
198
  const result = await this.crudRepository.getMany({
199
199
  queries: req.getQuery(),
200
- queryProvider: this.db,
201
200
  });
202
201
  return ResponseBuilder.json(result).get();
203
202
  }
@@ -1,8 +1,8 @@
1
- import { AbstractLogger, AbstractModel, Constructor, CreateManyRequestBody, CreateManyResponseBody, DeepPartial, GetManyQueries, GetManyResponseBody, Identifiable, UpdateManyBody, UpdateManyQueries, UpdateManyResponse } from "@clairejs/core";
2
- import { AbstractDbAdapter, IQueryProvider, ITransaction, QueryCondition } from "@clairejs/orm";
3
- import { IPrincipal } from "../../common/auth/IPrincipal";
1
+ import { type Identifiable, type Constructor, type CreateManyRequestBody, type CreateManyResponseBody, type DeepPartial, type GetManyQueries, type GetManyResponseBody, type UpdateManyBody, type UpdateManyQueries, type UpdateManyResponse, AbstractLogger, AbstractModel } from "@clairejs/core";
2
+ import { type ITransaction, type QueryCondition, AbstractDbAdapter } from "@clairejs/orm";
3
+ import { type IPrincipal } from "../../common/auth/IPrincipal";
4
4
  import { AbstractRepository } from "./AbstractRepository";
5
- import { ICrudRepository } from "./ICrudRepository";
5
+ import { type ICrudRepository } from "./ICrudRepository";
6
6
  export type DtoDissolver<R extends Identifiable, K extends Identifiable> = (t: DeepPartial<K>) => MappingMetadata<R, any>[];
7
7
  export interface MappingMetadata<R extends Identifiable, K extends AbstractModel> {
8
8
  multiple: boolean;
@@ -37,7 +37,7 @@ export declare class DtoRepository<T extends Identifiable> extends AbstractRepos
37
37
  createMany({ principal, body, tx, logger, }: {
38
38
  principal?: IPrincipal | undefined;
39
39
  body: CreateManyRequestBody<T>;
40
- tx: ITransaction & IQueryProvider;
40
+ tx: ITransaction;
41
41
  logger?: AbstractLogger;
42
42
  }): Promise<CreateManyResponseBody<T>>;
43
43
  updateMany({ principal, queries, ops, body, tx, logger, }: {
@@ -45,13 +45,13 @@ export declare class DtoRepository<T extends Identifiable> extends AbstractRepos
45
45
  queries?: UpdateManyQueries<T>;
46
46
  ops?: QueryCondition<T>[];
47
47
  body: UpdateManyBody<T>;
48
- tx: ITransaction & IQueryProvider;
48
+ tx: ITransaction;
49
49
  logger?: AbstractLogger;
50
50
  }): Promise<UpdateManyResponse<T>>;
51
- getMany({ queries, ops, queryProvider, logger, }: {
51
+ getMany({ queries, ops, tx, logger, }: {
52
52
  queries?: GetManyQueries<T>;
53
53
  ops?: QueryCondition<T>[];
54
- queryProvider: IQueryProvider;
54
+ tx?: ITransaction;
55
55
  logger?: AbstractLogger;
56
56
  }): Promise<GetManyResponseBody<T>>;
57
57
  deleteMany({ queries, ops, tx, logger, }: {
@@ -61,7 +61,7 @@ export class DtoRepository extends AbstractRepository {
61
61
  const repo = new ModelRepository(mapper.modelClass, this.db);
62
62
  const currentInstances = await repo.getMany({
63
63
  ops: mapper.forwardOps(),
64
- queryProvider: tx,
64
+ tx,
65
65
  logger,
66
66
  });
67
67
  return currentInstances.records;
@@ -123,7 +123,7 @@ export class DtoRepository extends AbstractRepository {
123
123
  const repo = new ModelRepository(mapper.modelClass, this.db);
124
124
  const currentInstances = await repo.getMany({
125
125
  ops: mapper.forwardOps(ops),
126
- queryProvider: tx,
126
+ tx,
127
127
  logger,
128
128
  });
129
129
  return currentInstances.records;
@@ -173,7 +173,7 @@ export class DtoRepository extends AbstractRepository {
173
173
  }
174
174
  return { modified: result.id ? this.project([result], projection) : [] };
175
175
  }
176
- async getMany({ queries, ops, queryProvider, logger, }) {
176
+ async getMany({ queries, ops, tx, logger, }) {
177
177
  //-- check queries for id field
178
178
  if (!queries?.fields?.id || queries.fields.id.length !== 1) {
179
179
  throw Errors.VALIDATION_ERROR("Missing required id field in query");
@@ -184,7 +184,7 @@ export class DtoRepository extends AbstractRepository {
184
184
  //-- forward get
185
185
  const instances = await repo.getMany({
186
186
  ops: mapper.forwardOps(ops),
187
- queryProvider,
187
+ tx,
188
188
  logger,
189
189
  });
190
190
  return instances.records;
@@ -1,5 +1,5 @@
1
1
  import { type AbstractLogger, type CreateManyRequestBody, type CreateManyResponseBody, type GetManyQueries, type GetManyResponseBody, type UpdateManyBody, type UpdateManyQueries, type UpdateManyResponse } from "@clairejs/core";
2
- import { type IQueryProvider, type ITransaction, type QueryCondition } from "@clairejs/orm";
2
+ import { type ITransaction, type QueryCondition } from "@clairejs/orm";
3
3
  import { type IPrincipal } from "../../common/auth/IPrincipal";
4
4
  export interface ICrudRepository<T> {
5
5
  createMany({ principal, body, tx, logger, }: {
@@ -8,10 +8,10 @@ export interface ICrudRepository<T> {
8
8
  logger?: AbstractLogger;
9
9
  principal?: IPrincipal;
10
10
  }): Promise<CreateManyResponseBody<T>>;
11
- getMany({ queries, ops, queryProvider, logger, }: {
11
+ getMany({ queries, ops, tx, logger, }: {
12
12
  queries?: GetManyQueries<T>;
13
13
  ops?: QueryCondition<T>[];
14
- queryProvider: IQueryProvider;
14
+ tx?: ITransaction;
15
15
  logger?: AbstractLogger;
16
16
  }): Promise<GetManyResponseBody<T>>;
17
17
  updateMany({ principal, queries, ops, body, tx, logger, }: {
@@ -1,5 +1,5 @@
1
1
  import { AbstractModel, Constructor, CreateManyRequestBody, CreateManyResponseBody, GetManyQueries, GetManyResponseBody, UpdateManyBody, UpdateManyQueries, UpdateManyResponse, AbstractLogger } from "@clairejs/core";
2
- import { AbstractDbAdapter, IQueryProvider, ITransaction, QueryCondition } from "@clairejs/orm";
2
+ import { AbstractDbAdapter, ITransaction, QueryCondition } from "@clairejs/orm";
3
3
  import { IPrincipal } from "../../common/auth/IPrincipal";
4
4
  import { ICrudRepository } from "./ICrudRepository";
5
5
  import { AbstractRepository } from "./AbstractRepository";
@@ -27,10 +27,10 @@ export declare class ModelRepository<T extends AbstractModel> extends AbstractRe
27
27
  tx: ITransaction;
28
28
  logger?: AbstractLogger;
29
29
  }): Promise<UpdateManyResponse<T>>;
30
- getMany({ queries, ops, queryProvider, logger, }: {
30
+ getMany({ queries, ops, tx, logger, }: {
31
31
  queries?: GetManyQueries<T>;
32
32
  ops?: QueryCondition<T>[];
33
- queryProvider: IQueryProvider;
33
+ tx?: ITransaction;
34
34
  logger?: AbstractLogger;
35
35
  }): Promise<GetManyResponseBody<T>>;
36
36
  deleteMany({ queries, ops, tx, logger, }: {
@@ -1,5 +1,5 @@
1
1
  import { DataType, getModelById, getServiceProvider, RangeQueryDto, uniqueReducer, leanData, getSystemLocale, Errors, omitData, } from "@clairejs/core";
2
- import { getDirectFields } from "@clairejs/orm";
2
+ import { getDirectFields, } from "@clairejs/orm";
3
3
  import { AbstractFileUploadHandler } from "../file-upload/AbstractFileUploadHandler";
4
4
  import { AbstractRepository } from "./AbstractRepository";
5
5
  import { LocaleTranslation } from "../../system/locale/LocaleTranslation";
@@ -280,7 +280,9 @@ export class ModelRepository extends AbstractRepository {
280
280
  return data;
281
281
  });
282
282
  await this.beforeCreating(principal, body.records);
283
- let records = body.records.length ? await this.db.use(this.model, tx).createMany(body.records) : [];
283
+ let records = body.records.length
284
+ ? await this.db.use(this.model, tx).createMany(body.records)
285
+ : [];
284
286
  await this.beforeReturning(records);
285
287
  const projection = this.modelMetadata.fields
286
288
  .filter((field) => !field.multiLocaleColumn && (field.pk || field.serverValue || field.mimeProps))
@@ -364,7 +366,9 @@ export class ModelRepository extends AbstractRepository {
364
366
  let modified = [];
365
367
  let updatedRecords = [];
366
368
  if (nestedQueries.length) {
367
- const tobeUpdated = await this.db.use(this.model, tx).getMany(condition, { projection: ["id"] }, nestedQueries);
369
+ const tobeUpdated = await this.db
370
+ .use(this.model, tx)
371
+ .getMany(condition, { projection: ["id"] }, nestedQueries);
368
372
  modified = tobeUpdated.records.map((r) => r.id);
369
373
  if (modified.length) {
370
374
  if (directUpdateFields.length) {
@@ -405,7 +409,9 @@ export class ModelRepository extends AbstractRepository {
405
409
  field: field.name,
406
410
  })))
407
411
  .flatMap((arr) => arr);
408
- const missingEntries = !missing.length ? [] : await this.db.use(LocaleEntry, tx).createMany(missing.map(() => ({})));
412
+ const missingEntries = !missing.length
413
+ ? []
414
+ : await this.db.use(LocaleEntry, tx).createMany(missing.map(() => ({})));
409
415
  const updateEntryRecords = [];
410
416
  missingEntries.forEach((entry, index) => {
411
417
  const missingData = missing[index];
@@ -512,7 +518,7 @@ export class ModelRepository extends AbstractRepository {
512
518
  await this.beforeReturning(records);
513
519
  return { modified: this.project(records, projection) };
514
520
  }
515
- async getMany({ queries, ops, queryProvider, logger: _logger, }) {
521
+ async getMany({ queries, ops, tx, logger: _logger, }) {
516
522
  const conditions = ops || [];
517
523
  if (queries?.fields) {
518
524
  conditions.push(...this.getRequestQueryConditionFromQuery(queries.fields, this.modelMetadata));
@@ -535,7 +541,7 @@ export class ModelRepository extends AbstractRepository {
535
541
  ...queries.projection.filter((fieldName) => !this.modelMetadata.fields.find((f) => f.name === fieldName && !!f.hasMany)),
536
542
  ...localeOfFields.map((f) => f.name),
537
543
  ];
538
- const result = await queryProvider.use(this.model).getMany(conditions.length ? { _and: conditions } : {}, {
544
+ const result = await this.db.use(this.model, tx).getMany(conditions.length ? { _and: conditions } : {}, {
539
545
  limit: queries?.limit,
540
546
  page: queries?.page,
541
547
  projection: finalProjection,
@@ -553,12 +559,12 @@ export class ModelRepository extends AbstractRepository {
553
559
  ? []
554
560
  : !queries?.locale
555
561
  ? //-- if locale is not specified then get translation for all locales
556
- await queryProvider.use(LocaleTranslation).getRecords({
562
+ await this.db.use(LocaleTranslation, tx).getRecords({
557
563
  _in: { entryId: allLocaleEntries },
558
564
  }, { projection: ["entryId", "localeCode", "translation"] })
559
565
  : //-- if locale is specified then get only the translation of that locale
560
566
  queries.locale.toLowerCase() !== systemLocale
561
- ? await queryProvider.use(LocaleTranslation).getRecords({
567
+ ? await this.db.use(LocaleTranslation, tx).getRecords({
562
568
  _in: { entryId: allLocaleEntries },
563
569
  _eq: { localeCode: queries.locale },
564
570
  }, { projection: ["entryId", "localeCode", "translation"] })
@@ -600,7 +606,7 @@ export class ModelRepository extends AbstractRepository {
600
606
  ? { records: [] }
601
607
  : await service.getMany({
602
608
  queries: { fields: { [field.hasMany.column]: recordIds }, limit: field.hasMany.single ? 1 : 0 },
603
- queryProvider,
609
+ tx,
604
610
  });
605
611
  //-- filter corresponding inner records for each master record
606
612
  for (const record of result.records) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clairejs/server",
3
- "version": "3.19.0",
3
+ "version": "3.19.1",
4
4
  "description": "Claire server NodeJs framework written in Typescript.",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",