@clairejs/server 3.17.9 → 3.18.0
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 +6 -1
- package/dist/common/ControllerMetadata.d.ts +1 -0
- package/dist/common/decorator.d.ts +1 -0
- package/dist/common/decorator.js +1 -0
- package/dist/controllers/FileManageController.d.ts +3 -3
- package/dist/controllers/FileManageController.js +2 -2
- package/dist/controllers/FileUploadController.d.ts +3 -3
- package/dist/controllers/FileUploadController.js +2 -2
- package/dist/http/controller/AbstractHttpController.js +1 -1
- package/dist/http/controller/AbstractHttpRequestHandler.js +2 -2
- package/dist/http/controller/CrudHttpController.js +1 -0
- package/dist/http/controller/DefaultHttpRequestHandler.d.ts +1 -0
- package/dist/http/controller/DefaultHttpRequestHandler.js +12 -9
- package/dist/job/AwsJobScheduler.d.ts +3 -3
- package/dist/job/AwsJobScheduler.js +2 -2
- package/dist/job/LocalJobScheduler.d.ts +3 -3
- package/dist/job/LocalJobScheduler.js +2 -2
- package/dist/socket/AbstractServerSocketManager.js +1 -1
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
## Change Log
|
|
2
2
|
|
|
3
|
-
#### 3.
|
|
3
|
+
#### 3.18.0:
|
|
4
4
|
|
|
5
|
+
- adapt claire core & clare orm
|
|
6
|
+
|
|
7
|
+
#### 3.17.10:
|
|
8
|
+
|
|
9
|
+
- fix socket manager & isEndpoint
|
|
5
10
|
- remove handlerFunctionName (using name & displayName instead)
|
|
6
11
|
- fix missing controller & handlerFunctionName in EndpointMetadata
|
|
7
12
|
- remove AbstractController
|
|
@@ -2,5 +2,6 @@ import { Constructor } from "@clairejs/core";
|
|
|
2
2
|
import { AbstractSocketController } from "../socket/AbstractSocketController";
|
|
3
3
|
import { AbstractHttpController } from "../http/controller/AbstractHttpController";
|
|
4
4
|
export declare const Controller: (config?: {
|
|
5
|
+
mount?: string;
|
|
5
6
|
permissionGroup?: string;
|
|
6
7
|
}) => <T extends AbstractSocketController | AbstractHttpController>(constructor: Constructor<T>) => void;
|
package/dist/common/decorator.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AbstractDbAdapter } from "@clairejs/orm";
|
|
2
2
|
import { AbstractHttpController } from "../http/controller/AbstractHttpController";
|
|
3
3
|
import { AbstractFileService } from "../services/AbstractFileService";
|
|
4
4
|
import { GetFileAccessUrlRequest, GetFileInfoRequest, GetFileInfoResponse, MoveFileRequest, RemoveFileRequest } from "./dto/upload";
|
|
5
5
|
export declare class FileManageController extends AbstractHttpController {
|
|
6
|
-
protected readonly db:
|
|
6
|
+
protected readonly db: AbstractDbAdapter;
|
|
7
7
|
protected readonly fileService: AbstractFileService;
|
|
8
|
-
constructor(db:
|
|
8
|
+
constructor(db: AbstractDbAdapter, fileService: AbstractFileService);
|
|
9
9
|
moveFile(body: MoveFileRequest): Promise<import("../http/common/HttpResponse").HttpResponse<unknown>>;
|
|
10
10
|
copyFile(body: MoveFileRequest): Promise<import("../http/common/HttpResponse").HttpResponse<unknown>>;
|
|
11
11
|
removeFile(body: RemoveFileRequest): Promise<import("../http/common/HttpResponse").HttpResponse<unknown>>;
|
|
@@ -11,7 +11,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
11
11
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
12
|
};
|
|
13
13
|
import { Injectable } from "@clairejs/core";
|
|
14
|
-
import {
|
|
14
|
+
import { AbstractDbAdapter } from "@clairejs/orm";
|
|
15
15
|
import { ResponseBuilder } from "../http/common/HttpResponse";
|
|
16
16
|
import { AbstractHttpController } from "../http/controller/AbstractHttpController";
|
|
17
17
|
import { ApiResponse, Body, Get, Post, Queries } from "../http/decorators";
|
|
@@ -88,6 +88,6 @@ __decorate([
|
|
|
88
88
|
], FileManageController.prototype, "getFileInfo", null);
|
|
89
89
|
FileManageController = __decorate([
|
|
90
90
|
Injectable(),
|
|
91
|
-
__metadata("design:paramtypes", [
|
|
91
|
+
__metadata("design:paramtypes", [AbstractDbAdapter, AbstractFileService])
|
|
92
92
|
], FileManageController);
|
|
93
93
|
export { FileManageController };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AbstractDbAdapter } from "@clairejs/orm";
|
|
2
2
|
import { AbstractHttpController } from "../http/controller/AbstractHttpController";
|
|
3
3
|
import { AbstractFileService } from "../services/AbstractFileService";
|
|
4
4
|
import { GetMultipleUploadUrlsQueries, GetUploadUrlQueries, GetUploadUrlResponseBody } from "./dto/upload";
|
|
5
5
|
export declare class FileUploadController extends AbstractHttpController {
|
|
6
|
-
protected readonly db:
|
|
6
|
+
protected readonly db: AbstractDbAdapter;
|
|
7
7
|
protected readonly fileService: AbstractFileService;
|
|
8
8
|
protected readonly allowedUploadExtensions: string[];
|
|
9
|
-
constructor(db:
|
|
9
|
+
constructor(db: AbstractDbAdapter, fileService: AbstractFileService, allowedUploadExtensions: string[]);
|
|
10
10
|
getUploadUrl(queries: GetUploadUrlQueries): Promise<import("../http/common/HttpResponse").HttpResponse<GetUploadUrlResponseBody>>;
|
|
11
11
|
getMultipleUploadUrls(queries: GetMultipleUploadUrlsQueries): Promise<import("../http/common/HttpResponse").HttpResponse<{
|
|
12
12
|
files: GetUploadUrlResponseBody[];
|
|
@@ -11,7 +11,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
11
11
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
12
|
};
|
|
13
13
|
import { Errors, Injectable } from "@clairejs/core";
|
|
14
|
-
import {
|
|
14
|
+
import { AbstractDbAdapter } from "@clairejs/orm";
|
|
15
15
|
import randomstring from "randomstring";
|
|
16
16
|
import { ResponseBuilder } from "../http/common/HttpResponse";
|
|
17
17
|
import { AbstractHttpController } from "../http/controller/AbstractHttpController";
|
|
@@ -62,7 +62,7 @@ __decorate([
|
|
|
62
62
|
], FileUploadController.prototype, "getMultipleUploadUrls", null);
|
|
63
63
|
FileUploadController = __decorate([
|
|
64
64
|
Injectable(),
|
|
65
|
-
__metadata("design:paramtypes", [
|
|
65
|
+
__metadata("design:paramtypes", [AbstractDbAdapter,
|
|
66
66
|
AbstractFileService, Array])
|
|
67
67
|
], FileUploadController);
|
|
68
68
|
export { FileUploadController };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getObjectMetadata } from "@clairejs/core";
|
|
2
2
|
import { Transactionable } from "../../common/Transactionable";
|
|
3
3
|
const isEndpoint = (metadata) => {
|
|
4
|
-
return !!metadata.method
|
|
4
|
+
return !!metadata.method;
|
|
5
5
|
};
|
|
6
6
|
export class AbstractHttpController extends Transactionable {
|
|
7
7
|
databaseAdapter;
|
|
@@ -13,9 +13,9 @@ export class AbstractHttpRequestHandler {
|
|
|
13
13
|
if (!controllerMetadata) {
|
|
14
14
|
return "";
|
|
15
15
|
}
|
|
16
|
-
const urlParts = [];
|
|
16
|
+
const urlParts = [controllerMetadata.mount || ""];
|
|
17
17
|
urlParts.push(...mappingUrls);
|
|
18
|
-
let finalUrl = urlParts.reduce((collector, part) => `${collector}/${part}`, "");
|
|
18
|
+
let finalUrl = urlParts.filter((part) => !!part).reduce((collector, part) => `${collector}/${part}`, "");
|
|
19
19
|
//-- replace double slashes
|
|
20
20
|
return finalUrl.replace(/(\/)\/+/g, "$1");
|
|
21
21
|
}
|
|
@@ -103,6 +103,7 @@ export class CrudHttpController extends AbstractHttpController {
|
|
|
103
103
|
endpointMetadata.bodyDto = getUpdateRecordsBodyValidator(this.modelMetadata);
|
|
104
104
|
//-- response dto ------------------------------------
|
|
105
105
|
endpointMetadata.responseDto = getUpdateManyResponseValidator(this.modelMetadata);
|
|
106
|
+
endpointMetadata.params = { 0: { source: "raw" } };
|
|
106
107
|
return endpointMetadata;
|
|
107
108
|
}
|
|
108
109
|
/**
|
|
@@ -15,6 +15,7 @@ export declare class DefaultHttpRequestHandler extends AbstractHttpRequestHandle
|
|
|
15
15
|
constructor(logger: AbstractLogger, authorizationProvider: AbstractRequestAuthorizer, principalResolver: AbstractPrincipalResolver);
|
|
16
16
|
protected handleRequest(endpoint: EndpointMetadata, req: HttpRequest): Promise<HttpResponse<any>>;
|
|
17
17
|
exit(): void;
|
|
18
|
+
private getMountedInfo;
|
|
18
19
|
private getResponse;
|
|
19
20
|
handle(httpData: HttpData): Promise<HttpResponse<any>>;
|
|
20
21
|
getMiddleware(): Promise<AbstractHttpMiddleware[]>;
|
|
@@ -7,7 +7,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
|
-
import { AbstractLogger, stripData, Injectable, getServiceProvider, Errors, LogContext } from "@clairejs/core";
|
|
10
|
+
import { AbstractLogger, stripData, Injectable, getServiceProvider, Errors, LogContext, } from "@clairejs/core";
|
|
11
11
|
import randomstring from "randomstring";
|
|
12
12
|
import parseurl from "parseurl";
|
|
13
13
|
import { match } from "path-to-regexp";
|
|
@@ -53,22 +53,25 @@ let DefaultHttpRequestHandler = class DefaultHttpRequestHandler extends Abstract
|
|
|
53
53
|
return response;
|
|
54
54
|
}
|
|
55
55
|
exit() { }
|
|
56
|
-
async
|
|
57
|
-
let response = new HttpResponse();
|
|
58
|
-
//-- match options with handler
|
|
59
|
-
const method = httpData.method;
|
|
60
|
-
const result = parseurl({ url: httpData.fullPath });
|
|
61
|
-
let params = {};
|
|
56
|
+
async getMountedInfo(method, pathname) {
|
|
62
57
|
const mountedEndpointInfo = await this.getMountedEndpointInfo();
|
|
58
|
+
let params = {};
|
|
63
59
|
const info = mountedEndpointInfo.find((info) => {
|
|
64
|
-
const parsedParams = info.method === method &&
|
|
65
|
-
match(info.mount, { decode: decodeURIComponent })(result.pathname || "/");
|
|
60
|
+
const parsedParams = info.method === method && match(info.mount, { decode: decodeURIComponent })(pathname);
|
|
66
61
|
if (!parsedParams) {
|
|
67
62
|
return false;
|
|
68
63
|
}
|
|
69
64
|
params = parsedParams;
|
|
70
65
|
return true;
|
|
71
66
|
});
|
|
67
|
+
return { info, params };
|
|
68
|
+
}
|
|
69
|
+
async getResponse(httpData) {
|
|
70
|
+
const response = new HttpResponse();
|
|
71
|
+
//-- match options with handler
|
|
72
|
+
const method = httpData.method;
|
|
73
|
+
const result = parseurl({ url: httpData.fullPath });
|
|
74
|
+
const { params, info } = await this.getMountedInfo(method, result.pathname || "/");
|
|
72
75
|
if (!info) {
|
|
73
76
|
this.logger.debug(httpData);
|
|
74
77
|
throw Errors.NOT_FOUND(`Handler not found`);
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { AbstractLogger } from "@clairejs/core";
|
|
2
|
-
import {
|
|
2
|
+
import { AbstractDbAdapter, ITransaction } from "@clairejs/orm";
|
|
3
3
|
import aws from "aws-sdk";
|
|
4
4
|
import Redis from "ioredis";
|
|
5
5
|
import { AbstractJobScheduler } from "./AbstractJobScheduler";
|
|
6
6
|
import { JobInfo, ScheduledJob } from "./interfaces";
|
|
7
7
|
export declare class AwsJobScheduler extends AbstractJobScheduler {
|
|
8
8
|
protected readonly logger: AbstractLogger;
|
|
9
|
-
protected readonly db:
|
|
9
|
+
protected readonly db: AbstractDbAdapter;
|
|
10
10
|
protected readonly redisClient: Redis;
|
|
11
11
|
protected readonly uniqueIdKey: string;
|
|
12
12
|
protected readonly apiLambdaFunctionArn: string;
|
|
@@ -26,7 +26,7 @@ export declare class AwsJobScheduler extends AbstractJobScheduler {
|
|
|
26
26
|
protected readonly oneMinuteRule: string;
|
|
27
27
|
protected readonly eventbridge: aws.EventBridge;
|
|
28
28
|
protected readonly stepfunctions: aws.StepFunctions;
|
|
29
|
-
constructor(logger: AbstractLogger, db:
|
|
29
|
+
constructor(logger: AbstractLogger, db: AbstractDbAdapter, redisClient: Redis, uniqueIdKey: string, apiLambdaFunctionArn: string, stepFunctionName: string,
|
|
30
30
|
/**
|
|
31
31
|
* This IAM role must have following permissions:
|
|
32
32
|
* - trigger any state machine (for one minute rule - as we don't now the state machine ARN until auto creation)
|
|
@@ -8,7 +8,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
10
|
import { AbstractLogger, Errors, LogContext } from "@clairejs/core";
|
|
11
|
-
import {
|
|
11
|
+
import { AbstractDbAdapter } from "@clairejs/orm";
|
|
12
12
|
import aws from "aws-sdk";
|
|
13
13
|
import Redis from "ioredis";
|
|
14
14
|
import { AbstractJobScheduler } from "./AbstractJobScheduler";
|
|
@@ -407,7 +407,7 @@ let AwsJobScheduler = class AwsJobScheduler extends AbstractJobScheduler {
|
|
|
407
407
|
AwsJobScheduler = __decorate([
|
|
408
408
|
LogContext(),
|
|
409
409
|
__metadata("design:paramtypes", [AbstractLogger,
|
|
410
|
-
|
|
410
|
+
AbstractDbAdapter,
|
|
411
411
|
Redis, String, String, String, String, Object, Object, Object])
|
|
412
412
|
], AwsJobScheduler);
|
|
413
413
|
export { AwsJobScheduler };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { AbstractLogger, IInit } from "@clairejs/core";
|
|
2
2
|
import Redis from "ioredis";
|
|
3
|
-
import {
|
|
3
|
+
import { AbstractDbAdapter, ITransaction } from "@clairejs/orm";
|
|
4
4
|
import { AbstractJobScheduler } from "./AbstractJobScheduler";
|
|
5
5
|
import { CustomJobInfo, JobInfo, ScheduledJob } from "./interfaces";
|
|
6
6
|
import { AbstractJobRepository } from "./AbstractJobRepository";
|
|
7
7
|
export declare class LocalJobScheduler extends AbstractJobScheduler implements IInit {
|
|
8
8
|
protected readonly logger: AbstractLogger;
|
|
9
|
-
protected readonly db:
|
|
9
|
+
protected readonly db: AbstractDbAdapter;
|
|
10
10
|
protected readonly redisClient: Redis;
|
|
11
11
|
protected readonly subscribeClient: Redis;
|
|
12
12
|
protected readonly jobRepo: AbstractJobRepository<CustomJobInfo>;
|
|
@@ -35,7 +35,7 @@ export declare class LocalJobScheduler extends AbstractJobScheduler implements I
|
|
|
35
35
|
private isActive;
|
|
36
36
|
private notifyResolver;
|
|
37
37
|
private jobHolder;
|
|
38
|
-
constructor(logger: AbstractLogger, db:
|
|
38
|
+
constructor(logger: AbstractLogger, db: AbstractDbAdapter, redisClient: Redis, subscribeClient: Redis, jobRepo: AbstractJobRepository<CustomJobInfo>,
|
|
39
39
|
/**
|
|
40
40
|
* Redis lock key to select active scheduler
|
|
41
41
|
*/
|
|
@@ -11,7 +11,7 @@ import { AbstractLogger, Errors, Initable, LogContext } from "@clairejs/core";
|
|
|
11
11
|
import Redis from "ioredis";
|
|
12
12
|
import Redlock from "redlock";
|
|
13
13
|
import scheduler from "node-schedule";
|
|
14
|
-
import {
|
|
14
|
+
import { AbstractDbAdapter } from "@clairejs/orm";
|
|
15
15
|
import assert from "assert";
|
|
16
16
|
import { AbstractJobScheduler } from "./AbstractJobScheduler";
|
|
17
17
|
import { AbstractJobRepository } from "./AbstractJobRepository";
|
|
@@ -272,7 +272,7 @@ LocalJobScheduler = __decorate([
|
|
|
272
272
|
LogContext(),
|
|
273
273
|
Initable(),
|
|
274
274
|
__metadata("design:paramtypes", [AbstractLogger,
|
|
275
|
-
|
|
275
|
+
AbstractDbAdapter,
|
|
276
276
|
Redis,
|
|
277
277
|
Redis,
|
|
278
278
|
AbstractJobRepository, String, String, String, String, Number])
|
|
@@ -288,7 +288,7 @@ export class AbstractServerSocketManager {
|
|
|
288
288
|
...getChannelNameMetadata,
|
|
289
289
|
id: `${SocketMethod.MESSAGE}:${controller.getChannelName()}`,
|
|
290
290
|
readOnly: false,
|
|
291
|
-
controller
|
|
291
|
+
controller,
|
|
292
292
|
apiGroup: controllerMetadata?.permissionGroup,
|
|
293
293
|
name: controller.onMessage.name,
|
|
294
294
|
method: SocketMethod.MESSAGE,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clairejs/server",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.18.0",
|
|
4
4
|
"description": "Claire server NodeJs framework written in Typescript.",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
"ws": "^7.5.5"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@clairejs/core": "^3.7.
|
|
37
|
-
"@clairejs/orm": "^3.
|
|
36
|
+
"@clairejs/core": "^3.7.9",
|
|
37
|
+
"@clairejs/orm": "^3.14.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@types/cookie-parser": "^1.4.3",
|
|
@@ -48,6 +48,7 @@
|
|
|
48
48
|
"@types/randomstring": "^1.1.8",
|
|
49
49
|
"@types/uuid": "^9.0.0",
|
|
50
50
|
"@types/ws": "^7.4.0",
|
|
51
|
+
"id-sdk": "^1.5.16",
|
|
51
52
|
"mocha": "^10.2.0",
|
|
52
53
|
"ts-node": "^10.9.1",
|
|
53
54
|
"typescript": "^5.0.4",
|