@clairejs/server 3.25.5 → 3.26.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,5 +1,15 @@
1
1
  ## Change Log
2
2
 
3
+ #### 3.26.1
4
+
5
+ - remove the resolve url function in file upload handler
6
+
7
+ #### 3.26.0
8
+
9
+ - update file upload handler
10
+
11
+ - update packages, remove exit code
12
+
3
13
  #### 3.25.5
4
14
 
5
15
  - update packages, remove exit code
@@ -2,6 +2,4 @@ export declare abstract class AbstractFileUploadHandler {
2
2
  abstract moveFile(fromUri: string, toUri: string): Promise<void>;
3
3
  abstract copyFile(fromUri: string, toUri: string): Promise<void>;
4
4
  abstract removeFile(uri: string): Promise<void>;
5
- abstract resolvePublicUrl(uri: string): Promise<string>;
6
- abstract resolvePrivateUrl(uri: string): Promise<string>;
7
5
  }
@@ -1,11 +1,11 @@
1
1
  import { AbstractFileService } from "../../services/AbstractFileService";
2
2
  import { AbstractFileUploadHandler } from "./AbstractFileUploadHandler";
3
3
  export declare class FileUploadHandler extends AbstractFileUploadHandler {
4
- readonly fileService: AbstractFileService;
5
- constructor(fileService: AbstractFileService);
4
+ private readonly fileService;
5
+ private readonly prefix;
6
+ constructor(fileService: AbstractFileService, prefix?: string);
7
+ protected getPath(uri: string): string;
6
8
  moveFile(fromURI: string, toURI: string): Promise<void>;
7
9
  copyFile(fromURI: string, toURI: string): Promise<void>;
8
10
  removeFile(uri: string): Promise<void>;
9
- resolvePublicUrl(uri: string): Promise<string>;
10
- resolvePrivateUrl(uri: string): Promise<string>;
11
11
  }
@@ -1,41 +1,22 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- var __metadata = (this && this.__metadata) || function (k, v) {
8
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
- };
10
- import { Injectable } from "@clairejs/core";
11
- import { AbstractFileService } from "../../services/AbstractFileService";
12
1
  import { AbstractFileUploadHandler } from "./AbstractFileUploadHandler";
13
- let FileUploadHandler = class FileUploadHandler extends AbstractFileUploadHandler {
2
+ export class FileUploadHandler extends AbstractFileUploadHandler {
14
3
  fileService;
15
- constructor(fileService) {
4
+ prefix;
5
+ constructor(fileService, prefix = "") {
16
6
  super();
17
7
  this.fileService = fileService;
8
+ this.prefix = prefix;
9
+ }
10
+ getPath(uri) {
11
+ return `${this.prefix}${uri}`;
18
12
  }
19
13
  async moveFile(fromURI, toURI) {
20
- await this.fileService.moveObject([{ fromURI, toURI }]);
14
+ await this.fileService.moveObject([{ fromURI: this.getPath(fromURI), toURI: this.getPath(toURI) }]);
21
15
  }
22
16
  async copyFile(fromURI, toURI) {
23
- await this.fileService.copyObject([{ fromURI, toURI }]);
17
+ await this.fileService.copyObject([{ fromURI: this.getPath(fromURI), toURI: this.getPath(toURI) }]);
24
18
  }
25
19
  async removeFile(uri) {
26
- await this.fileService.removeObject([uri]);
27
- }
28
- async resolvePublicUrl(uri) {
29
- const result = await this.fileService.getAccessUrls([uri], true);
30
- return result[0];
31
- }
32
- async resolvePrivateUrl(uri) {
33
- const result = await this.fileService.getAccessUrls([uri], false);
34
- return result[0];
20
+ await this.fileService.removeObject([this.getPath(uri)]);
35
21
  }
36
- };
37
- FileUploadHandler = __decorate([
38
- Injectable(),
39
- __metadata("design:paramtypes", [AbstractFileService])
40
- ], FileUploadHandler);
41
- export { FileUploadHandler };
22
+ }
@@ -1,15 +1,17 @@
1
- import { AbstractModel, Constructor, CreateManyRequestBody, CreateManyResponseBody, GetManyQueries, GetManyResponseBody, UpdateManyBody, UpdateManyQueries, UpdateManyResponse, AbstractLogger } from "@clairejs/core";
1
+ import { AbstractLogger, AbstractModel, Constructor, CreateManyRequestBody, CreateManyResponseBody, GetManyQueries, GetManyResponseBody, UpdateManyBody, UpdateManyQueries, UpdateManyResponse } from "@clairejs/core";
2
2
  import { AbstractDbAdapter, ITransaction, QueryCondition } from "@clairejs/orm";
3
3
  import { IPrincipal } from "../../common/auth/IPrincipal";
4
- import { ICrudRepository } from "./ICrudRepository";
5
4
  import { AbstractRepository } from "./AbstractRepository";
5
+ import { ICrudRepository } from "./ICrudRepository";
6
6
  export declare class ModelRepository<T extends AbstractModel> extends AbstractRepository<T> implements ICrudRepository<T> {
7
7
  protected readonly model: Constructor<T>;
8
8
  protected readonly db: AbstractDbAdapter;
9
9
  private fileUploadHandler?;
10
+ private fileService?;
10
11
  constructor(model: Constructor<T>, db: AbstractDbAdapter);
11
12
  private getNestedQueries;
12
13
  private getUploadHandler;
14
+ private getFileService;
13
15
  private getRequestQueryConditionFromQuery;
14
16
  uriHandling(records: Partial<T>[]): Promise<() => Promise<void>>;
15
17
  beforeReturning(records: Partial<T>[]): Promise<void>;
@@ -1,9 +1,10 @@
1
- import { DataType, getModelById, getServiceProvider, RangeQueryDto, uniqueReducer, leanData, getSystemLocale, Errors, omitData, MODEL_FIELD_SEPARATOR, } from "@clairejs/core";
1
+ import { DataType, Errors, getModelById, getServiceProvider, getSystemLocale, leanData, MODEL_FIELD_SEPARATOR, omitData, RangeQueryDto, uniqueReducer, } from "@clairejs/core";
2
2
  import { getDirectFields, getSafeUpdate, } from "@clairejs/orm";
3
+ import { AbstractFileService } from "../../services/AbstractFileService";
4
+ import { LocaleEntry } from "../../system/locale/LocaleEntry";
5
+ import { LocaleTranslation } from "../../system/locale/LocaleTranslation";
3
6
  import { AbstractFileUploadHandler } from "../file-upload/AbstractFileUploadHandler";
4
7
  import { AbstractRepository } from "./AbstractRepository";
5
- import { LocaleTranslation } from "../../system/locale/LocaleTranslation";
6
- import { LocaleEntry } from "../../system/locale/LocaleEntry";
7
8
  const resolveUris = (record, field) => {
8
9
  return field.vectorProps?.elementDataType === DataType.STRING ? record[field.name] : [record[field.name]];
9
10
  };
@@ -14,6 +15,7 @@ export class ModelRepository extends AbstractRepository {
14
15
  model;
15
16
  db;
16
17
  fileUploadHandler;
18
+ fileService;
17
19
  constructor(model, db) {
18
20
  super(model);
19
21
  this.model = model;
@@ -44,6 +46,14 @@ export class ModelRepository extends AbstractRepository {
44
46
  }
45
47
  return this.fileUploadHandler;
46
48
  }
49
+ async getFileService() {
50
+ if (this.fileService === undefined) {
51
+ const injector = getServiceProvider().getInjector();
52
+ this.fileService = injector.resolveOptional(AbstractFileService) || null;
53
+ await injector.initInstances();
54
+ }
55
+ return this.fileService;
56
+ }
47
57
  getRequestQueryConditionFromQuery(queries, modelMetadata) {
48
58
  const result = [];
49
59
  for (const fieldMetadata of getDirectFields(modelMetadata)) {
@@ -176,8 +186,8 @@ export class ModelRepository extends AbstractRepository {
176
186
  }
177
187
  async beforeReturning(records) {
178
188
  //-- resolve url
179
- const fileUploadHandler = await this.getUploadHandler();
180
- if (!fileUploadHandler) {
189
+ const fileService = await this.getFileService();
190
+ if (!fileService) {
181
191
  return;
182
192
  }
183
193
  const mappingOperations = [];
@@ -195,8 +205,8 @@ export class ModelRepository extends AbstractRepository {
195
205
  mappingOperations.push((async () => {
196
206
  const urls = await Promise.all(uris.map(async (uri) => {
197
207
  return field.mimeProps?.public
198
- ? await fileUploadHandler.resolvePublicUrl(uri)
199
- : await fileUploadHandler.resolvePrivateUrl(uri);
208
+ ? (await fileService.getAccessUrls([uri], true))[0]
209
+ : (await fileService.getAccessUrls([uri], false))[0];
200
210
  }));
201
211
  assignUrls(record, field, urls);
202
212
  })());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clairejs/server",
3
- "version": "3.25.5",
3
+ "version": "3.26.1",
4
4
  "description": "Claire server NodeJs framework written in Typescript.",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",