jitar 0.1.1 → 0.1.2
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/dist/core/Implementation.js +7 -0
- package/dist/core/errors/UnknownParameter.d.ts +3 -0
- package/dist/core/errors/UnknownParameter.js +6 -0
- package/dist/runtime/LocalRepository.d.ts +1 -1
- package/dist/runtime/LocalRepository.js +13 -4
- package/dist/server/configuration/RepositoryConfiguration.d.ts +1 -0
- package/dist/server/configuration/RepositoryConfiguration.js +7 -1
- package/dist/server/configuration/StandaloneConfiguration.d.ts +1 -0
- package/dist/server/configuration/StandaloneConfiguration.js +6 -0
- package/dist/server/utils/LocalFileManager.d.ts +1 -0
- package/dist/server/utils/LocalFileManager.js +19 -11
- package/dist/server/utils/RuntimeConfigurator.js +9 -4
- package/package.json +4 -1
- package/.eslintignore +0 -3
- package/.eslintrc +0 -16
- package/jest.config.js +0 -20
- package/src/client.ts +0 -18
- package/src/core/ErrorManager.ts +0 -18
- package/src/core/Implementation.ts +0 -53
- package/src/core/Procedure.ts +0 -98
- package/src/core/Segment.ts +0 -62
- package/src/core/SegmentBuilder.ts +0 -55
- package/src/core/Version.ts +0 -68
- package/src/core/definitions/AccessLevel.ts +0 -3
- package/src/core/errors/ImplementationNotFound.ts +0 -12
- package/src/core/errors/InvalidVersionNumber.ts +0 -12
- package/src/core/errors/MissingParameterValue.ts +0 -12
- package/src/core/errors/NotImplemented.ts +0 -12
- package/src/core/errors/ProcedureNotFound.ts +0 -12
- package/src/core/interfaces/Runner.ts +0 -7
- package/src/core/reflection/ParameterParser.ts +0 -74
- package/src/core/reflection/ReflectionHelper.ts +0 -118
- package/src/core/reflection/models/ReflectionField.ts +0 -22
- package/src/core/reflection/models/ReflectionParameter.ts +0 -18
- package/src/core/types/Component.ts +0 -8
- package/src/core/types/FlexObject.ts +0 -4
- package/src/core/types/Module.ts +0 -6
- package/src/core/types/SegmentImplementation.ts +0 -9
- package/src/core/types/SegmentModule.ts +0 -9
- package/src/core/types/SegmentProcedure.ts +0 -11
- package/src/core/utils/FqnBuilder.ts +0 -11
- package/src/hooks.ts +0 -2
- package/src/lib.ts +0 -7
- package/src/runtime/ClientId.ts +0 -18
- package/src/runtime/Gateway.ts +0 -18
- package/src/runtime/LocalGateway.ts +0 -93
- package/src/runtime/LocalNode.ts +0 -130
- package/src/runtime/LocalRepository.ts +0 -154
- package/src/runtime/Node.ts +0 -15
- package/src/runtime/NodeBalancer.ts +0 -61
- package/src/runtime/NodeMonitor.ts +0 -63
- package/src/runtime/Proxy.ts +0 -60
- package/src/runtime/Remote.ts +0 -157
- package/src/runtime/RemoteGateway.ts +0 -40
- package/src/runtime/RemoteNode.ts +0 -49
- package/src/runtime/RemoteRepository.ts +0 -60
- package/src/runtime/Repository.ts +0 -20
- package/src/runtime/Runtime.ts +0 -47
- package/src/runtime/caching/CacheBuilder.ts +0 -424
- package/src/runtime/caching/ImportRewriter.ts +0 -76
- package/src/runtime/caching/RemoteBuilder.ts +0 -51
- package/src/runtime/caching/SourceAppender.ts +0 -57
- package/src/runtime/caching/definitions/Keywords.ts +0 -3
- package/src/runtime/caching/errors/InvalidSegmentFilename.ts +0 -8
- package/src/runtime/caching/errors/MissingModuleExport.ts +0 -8
- package/src/runtime/caching/errors/SegmentFileNotLoaded.ts +0 -8
- package/src/runtime/caching/errors/SegmentModuleNotLoaded.ts +0 -8
- package/src/runtime/caching/models/ApplicationModule.ts +0 -30
- package/src/runtime/caching/models/Implementation.ts +0 -41
- package/src/runtime/caching/models/Procedure.ts +0 -26
- package/src/runtime/caching/models/Segment.ts +0 -28
- package/src/runtime/caching/models/SegmentModule.ts +0 -26
- package/src/runtime/caching/types/SegmentFile.ts +0 -6
- package/src/runtime/caching/types/SegmentImportProperties.ts +0 -9
- package/src/runtime/caching/types/SegmentImports.ts +0 -6
- package/src/runtime/errors/ClientNotFound.ts +0 -12
- package/src/runtime/errors/FileNotFound.ts +0 -12
- package/src/runtime/errors/InvalidClientId.ts +0 -12
- package/src/runtime/errors/InvalidJitarHooks.ts +0 -12
- package/src/runtime/errors/InvalidSegmentFile.ts +0 -12
- package/src/runtime/errors/ModuleNotLoaded.ts +0 -12
- package/src/runtime/errors/NoNodeAvailable.ts +0 -12
- package/src/runtime/errors/RepositoryNotAvaiable.ts +0 -12
- package/src/runtime/errors/RuntimeNotAvailable.ts +0 -12
- package/src/runtime/errors/SegmentNotFound.ts +0 -12
- package/src/runtime/hooks/dependencies.ts +0 -19
- package/src/runtime/hooks/runtime.ts +0 -25
- package/src/runtime/interfaces/FileManager.ts +0 -19
- package/src/runtime/interfaces/HealthCheck.ts +0 -5
- package/src/runtime/interfaces/ProcedureContainer.ts +0 -9
- package/src/runtime/models/File.ts +0 -22
- package/src/runtime/serialization/ArraySerializer.ts +0 -27
- package/src/runtime/serialization/ClassSerializer.ts +0 -133
- package/src/runtime/serialization/MapSerializer.ts +0 -60
- package/src/runtime/serialization/ObjectSerializer.ts +0 -42
- package/src/runtime/serialization/SetSerializer.ts +0 -42
- package/src/runtime/serialization/ValueSerializer.ts +0 -81
- package/src/runtime/serialization/errors/ClassNotFound.ts +0 -12
- package/src/runtime/serialization/errors/InvalidClass.ts +0 -12
- package/src/runtime/serialization/errors/InvalidPropertyType.ts +0 -12
- package/src/runtime/serialization/interfaces/Serializer.ts +0 -10
- package/src/runtime/serialization/types/SerializableObject.ts +0 -6
- package/src/runtime/serialization/types/Serialized.ts +0 -8
- package/src/runtime/serialization/types/SerializedClass.ts +0 -13
- package/src/runtime/serialization/types/SerializedMap.ts +0 -13
- package/src/runtime/serialization/types/SerializedObject.ts +0 -4
- package/src/runtime/serialization/types/SerializedSet.ts +0 -9
- package/src/runtime/types/JitarHooks.ts +0 -10
- package/src/runtime/types/ModuleImporter.ts +0 -6
- package/src/runtime/utils/ModuleAnalyser.ts +0 -60
- package/src/runtime/utils/ModuleLoader.ts +0 -51
- package/src/runtime/utils/UrlRewriter.ts +0 -59
- package/src/server/JitarServer.ts +0 -161
- package/src/server/configuration/GatewayConfiguration.ts +0 -9
- package/src/server/configuration/NodeConfiguration.ts +0 -15
- package/src/server/configuration/ProxyConfiguration.ts +0 -16
- package/src/server/configuration/RepositoryConfiguration.ts +0 -17
- package/src/server/configuration/RuntimeConfiguration.ts +0 -30
- package/src/server/configuration/ServerOptions.ts +0 -14
- package/src/server/configuration/StandaloneConfiguration.ts +0 -21
- package/src/server/controllers/AssetsController.ts +0 -59
- package/src/server/controllers/HealthController.ts +0 -41
- package/src/server/controllers/JitarController.ts +0 -18
- package/src/server/controllers/ModulesController.ts +0 -77
- package/src/server/controllers/NodesController.ts +0 -58
- package/src/server/controllers/ProceduresController.ts +0 -31
- package/src/server/controllers/ProxyController.ts +0 -38
- package/src/server/controllers/RPCController.ts +0 -173
- package/src/server/definitions/RuntimeDefaults.ts +0 -10
- package/src/server/errors/MissingConfigurationValue.ts +0 -8
- package/src/server/errors/RuntimeNotAvaiable.ts +0 -8
- package/src/server/errors/UnknownRuntimeMode.ts +0 -8
- package/src/server/models/HealthDto.ts +0 -11
- package/src/server/models/NodeDto.ts +0 -11
- package/src/server/utils/DataConverter.ts +0 -15
- package/src/server/utils/LocalFileManager.ts +0 -122
- package/src/server/utils/RuntimeConfigurationLoader.ts +0 -19
- package/src/server/utils/RuntimeConfigurator.ts +0 -207
- package/src/server/utils/ServerOptionsReader.ts +0 -17
- package/src/server.ts +0 -16
- package/test/_fixtures/core/Implementation.fixture.ts +0 -33
- package/test/_fixtures/core/Procedure.fixture.ts +0 -33
- package/test/_fixtures/core/Segment.fixture.ts +0 -36
- package/test/_fixtures/core/SegmentBuilder.fixture.ts +0 -45
- package/test/_fixtures/core/Version.fixture.ts +0 -18
- package/test/_fixtures/core/reflection/ReflectionHelper.fixture.ts +0 -56
- package/test/_fixtures/runtime/LocalGateway.fixture.ts +0 -24
- package/test/_fixtures/runtime/LocalNode.fixture.ts +0 -16
- package/test/_fixtures/runtime/LocalRepository.fixture.ts +0 -73
- package/test/_fixtures/runtime/NodeBalancer.fixture.ts +0 -19
- package/test/_fixtures/runtime/NodeMonitor.fixture.ts +0 -34
- package/test/_fixtures/runtime/RemoteNode.fixture.ts +0 -8
- package/test/_fixtures/runtime/caching/ImportRewriter.fixture.ts +0 -81
- package/test/_fixtures/runtime/caching/RemoteBuilder.fixture.ts +0 -50
- package/test/_fixtures/runtime/caching/SourceAppender.fixture.ts +0 -35
- package/test/_fixtures/runtime/segments.ts +0 -78
- package/test/_fixtures/runtime/serialization/ValueSerializer.fixture.ts +0 -134
- package/test/_fixtures/runtime/utils/ModuleAnaliser.fixture.ts +0 -26
- package/test/core/Implementation.spec.ts +0 -89
- package/test/core/Procedure.spec.ts +0 -108
- package/test/core/Segment.spec.ts +0 -74
- package/test/core/SegmentBuilder.spec.ts +0 -39
- package/test/core/Version.spec.ts +0 -103
- package/test/core/errors/ErrorManager.spec.ts +0 -32
- package/test/core/reflection/ReflectionHelper.spec.ts +0 -128
- package/test/core/utils/FqnBuilder.spec.ts +0 -22
- package/test/runtime/ClientId.spec.ts +0 -43
- package/test/runtime/LocalGateway.spec.ts +0 -40
- package/test/runtime/LocalNode.spec.ts +0 -87
- package/test/runtime/LocalRepository.spec.ts +0 -50
- package/test/runtime/NodeBalancer.spec.ts +0 -39
- package/test/runtime/NodeMonitor.spec.ts +0 -31
- package/test/runtime/RemoteNode.spec.ts +0 -43
- package/test/runtime/caching/ImportRewriter.spec.ts +0 -68
- package/test/runtime/caching/RemoteBuilder.spec.ts +0 -21
- package/test/runtime/caching/SourceAppender.spec.ts +0 -31
- package/test/runtime/serialization/ValueSerializer.spec.ts +0 -203
- package/test/runtime/utils/ModuleAnalyser.spec.ts +0 -54
- package/test/runtime/utils/UrlRewriter.spec.ts +0 -57
- package/tsconfig.json +0 -23
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { IsOptional, IsString } from 'class-validator';
|
|
3
|
-
|
|
4
|
-
export default class RepositoryConfiguration
|
|
5
|
-
{
|
|
6
|
-
@IsString()
|
|
7
|
-
@IsOptional()
|
|
8
|
-
source?: string;
|
|
9
|
-
|
|
10
|
-
@IsString()
|
|
11
|
-
@IsOptional()
|
|
12
|
-
cache?: string;
|
|
13
|
-
|
|
14
|
-
@IsString()
|
|
15
|
-
@IsOptional()
|
|
16
|
-
index?: string;
|
|
17
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { IsOptional, IsUrl } from 'class-validator';
|
|
3
|
-
|
|
4
|
-
import GatewayConfiguration from './GatewayConfiguration.js';
|
|
5
|
-
import NodeConfiguration from './NodeConfiguration.js';
|
|
6
|
-
import ProxyConfiguration from './ProxyConfiguration.js';
|
|
7
|
-
import RepositoryConfiguration from './RepositoryConfiguration.js';
|
|
8
|
-
import StandaloneConfiguration from './StandaloneConfiguration.js';
|
|
9
|
-
|
|
10
|
-
export default class RuntimeConfiguration
|
|
11
|
-
{
|
|
12
|
-
@IsUrl()
|
|
13
|
-
@IsOptional()
|
|
14
|
-
url?: string;
|
|
15
|
-
|
|
16
|
-
@IsOptional()
|
|
17
|
-
standalone?: StandaloneConfiguration;
|
|
18
|
-
|
|
19
|
-
@IsOptional()
|
|
20
|
-
repository?: RepositoryConfiguration;
|
|
21
|
-
|
|
22
|
-
@IsOptional()
|
|
23
|
-
gateway?: GatewayConfiguration;
|
|
24
|
-
|
|
25
|
-
@IsOptional()
|
|
26
|
-
node?: NodeConfiguration;
|
|
27
|
-
|
|
28
|
-
@IsOptional()
|
|
29
|
-
proxy?: ProxyConfiguration;
|
|
30
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { IsArray, IsOptional, IsString } from 'class-validator';
|
|
3
|
-
|
|
4
|
-
export default class StandaloneConfiguration
|
|
5
|
-
{
|
|
6
|
-
@IsString()
|
|
7
|
-
@IsOptional()
|
|
8
|
-
source?: string;
|
|
9
|
-
|
|
10
|
-
@IsString()
|
|
11
|
-
@IsOptional()
|
|
12
|
-
cache?: string;
|
|
13
|
-
|
|
14
|
-
@IsString()
|
|
15
|
-
@IsOptional()
|
|
16
|
-
index?: string;
|
|
17
|
-
|
|
18
|
-
@IsArray()
|
|
19
|
-
@IsOptional()
|
|
20
|
-
segments?: string[];
|
|
21
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { Controller } from '@overnightjs/core';
|
|
3
|
-
import express, { Request, Response } from 'express';
|
|
4
|
-
import { Logger } from 'tslog';
|
|
5
|
-
|
|
6
|
-
import FileNotFound from '../../runtime/errors/FileNotFound.js';
|
|
7
|
-
import LocalRepository from '../../runtime/LocalRepository.js';
|
|
8
|
-
import Proxy from '../../runtime/Proxy.js';
|
|
9
|
-
|
|
10
|
-
@Controller('')
|
|
11
|
-
export default class AssetsController
|
|
12
|
-
{
|
|
13
|
-
#repository: LocalRepository | Proxy;
|
|
14
|
-
#indexFile: string;
|
|
15
|
-
#logger: Logger;
|
|
16
|
-
|
|
17
|
-
constructor(app: express.Application, repository: LocalRepository | Proxy, indexFile: string, logger: Logger)
|
|
18
|
-
{
|
|
19
|
-
this.#repository = repository;
|
|
20
|
-
this.#indexFile = indexFile;
|
|
21
|
-
this.#logger = logger;
|
|
22
|
-
|
|
23
|
-
app.get('*', (request: Request, response: Response) => { this.#getContent(request, response) })
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
async #getContent(request: Request, response: Response): Promise<void>
|
|
27
|
-
{
|
|
28
|
-
this.#logger.info(`Got asset -> '${request.path}'`);
|
|
29
|
-
|
|
30
|
-
const path = request.path.substring(1).trim();
|
|
31
|
-
const filename = path.length === 0 ? this.#indexFile : path;
|
|
32
|
-
|
|
33
|
-
try
|
|
34
|
-
{
|
|
35
|
-
const file = await this.#repository.loadAsset(filename);
|
|
36
|
-
|
|
37
|
-
response.set('Content-Type', file.type);
|
|
38
|
-
response.set('Content-Length', String(file.size));
|
|
39
|
-
response.status(200).send(file.content);
|
|
40
|
-
}
|
|
41
|
-
catch (error: unknown)
|
|
42
|
-
{
|
|
43
|
-
if (error instanceof FileNotFound)
|
|
44
|
-
{
|
|
45
|
-
this.#logger.warn(`Failed to get asset -> '${filename}' | ${error.message}`);
|
|
46
|
-
|
|
47
|
-
response.status(404).send(error.message);
|
|
48
|
-
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
53
|
-
|
|
54
|
-
this.#logger.error(`Failed to get file content -> '${filename}' | ${message}`);
|
|
55
|
-
|
|
56
|
-
response.status(500).send(message);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { Controller, Get } from '@overnightjs/core';
|
|
3
|
-
import { Request, Response } from 'express';
|
|
4
|
-
import { Logger } from 'tslog';
|
|
5
|
-
|
|
6
|
-
import LocalNode from '../../runtime/LocalNode.js';
|
|
7
|
-
import Proxy from '../../runtime/Proxy.js';
|
|
8
|
-
|
|
9
|
-
@Controller('health')
|
|
10
|
-
export default class HealthController
|
|
11
|
-
{
|
|
12
|
-
#node: LocalNode | Proxy;
|
|
13
|
-
#logger: Logger;
|
|
14
|
-
|
|
15
|
-
constructor(node: LocalNode | Proxy, logger: Logger)
|
|
16
|
-
{
|
|
17
|
-
this.#node = node;
|
|
18
|
-
this.#logger = logger;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
@Get()
|
|
22
|
-
async getHealth(request: Request, response: Response): Promise<Response>
|
|
23
|
-
{
|
|
24
|
-
const health = await this.#node.getHealth();
|
|
25
|
-
const data = Object.fromEntries(health);
|
|
26
|
-
|
|
27
|
-
this.#logger.debug('Got health');
|
|
28
|
-
|
|
29
|
-
return response.status(200).send(data);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
@Get('status')
|
|
33
|
-
async isHealthy(request: Request, response: Response): Promise<Response>
|
|
34
|
-
{
|
|
35
|
-
const healthy = await this.#node.isHealthy();
|
|
36
|
-
|
|
37
|
-
this.#logger.debug('Got health status');
|
|
38
|
-
|
|
39
|
-
return response.status(200).send(healthy);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { Controller } from '@overnightjs/core';
|
|
3
|
-
import express from 'express';
|
|
4
|
-
import path from 'path';
|
|
5
|
-
import { fileURLToPath } from 'url';
|
|
6
|
-
|
|
7
|
-
const filePath = fileURLToPath(import.meta.url);
|
|
8
|
-
const fileLocation = path.dirname(filePath);
|
|
9
|
-
const rootLocation = path.join(fileLocation, '../../')
|
|
10
|
-
|
|
11
|
-
@Controller('')
|
|
12
|
-
export default class JitarController
|
|
13
|
-
{
|
|
14
|
-
constructor(app: express.Application)
|
|
15
|
-
{
|
|
16
|
-
app.use('/jitar', express.static(rootLocation));
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { Controller, Get, Post } from '@overnightjs/core';
|
|
3
|
-
import { Request, Response } from 'express';
|
|
4
|
-
import { Logger } from 'tslog';
|
|
5
|
-
|
|
6
|
-
import ClientId from '../../runtime/ClientId.js';
|
|
7
|
-
import LocalRepository from '../../runtime/LocalRepository.js';
|
|
8
|
-
import Proxy from '../../runtime/Proxy.js';
|
|
9
|
-
import ValueSerializer from '../../runtime/serialization/ValueSerializer.js';
|
|
10
|
-
|
|
11
|
-
@Controller('modules')
|
|
12
|
-
export default class ModulesController
|
|
13
|
-
{
|
|
14
|
-
#repository: LocalRepository | Proxy;
|
|
15
|
-
#logger: Logger;
|
|
16
|
-
|
|
17
|
-
constructor(repository: LocalRepository | Proxy, logger: Logger)
|
|
18
|
-
{
|
|
19
|
-
this.#repository = repository;
|
|
20
|
-
this.#logger = logger;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
@Post()
|
|
24
|
-
async registerClient(request: Request, response: Response): Promise<Response>
|
|
25
|
-
{
|
|
26
|
-
if ((request.body instanceof Array) === false)
|
|
27
|
-
{
|
|
28
|
-
// TODO: Throw error.
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const segmentFiles = request.body as string[];
|
|
32
|
-
|
|
33
|
-
const clientId = await this.#repository.registerClient(segmentFiles);
|
|
34
|
-
|
|
35
|
-
this.#logger.info(`Registered client -> ${clientId} [${segmentFiles.join(',')}]`);
|
|
36
|
-
|
|
37
|
-
return response.status(200).send(clientId);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
@Get(':clientId/*')
|
|
41
|
-
async getModule(request: Request, response: Response): Promise<Response>
|
|
42
|
-
{
|
|
43
|
-
const clientId = request.params.clientId;
|
|
44
|
-
|
|
45
|
-
if (typeof clientId !== 'string' || ClientId.validate(clientId) === false)
|
|
46
|
-
{
|
|
47
|
-
return response.status(400).send('Invalid client id.');
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const pathKey = `/${clientId}/`;
|
|
51
|
-
const pathIndex = request.path.indexOf(pathKey) + pathKey.length;
|
|
52
|
-
const filename = request.path.substring(pathIndex);
|
|
53
|
-
|
|
54
|
-
try
|
|
55
|
-
{
|
|
56
|
-
const file = await this.#repository.loadModule(clientId, filename);
|
|
57
|
-
|
|
58
|
-
this.#logger.info(`Got module -> '${filename}' (${clientId})`);
|
|
59
|
-
|
|
60
|
-
response.set('Content-Type', file.type);
|
|
61
|
-
|
|
62
|
-
return response.status(200).send(file.content);
|
|
63
|
-
}
|
|
64
|
-
catch (error: unknown)
|
|
65
|
-
{
|
|
66
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
67
|
-
|
|
68
|
-
this.#logger.error(`Failed to get module -> '${filename}' (${clientId}) | ${message}`);
|
|
69
|
-
|
|
70
|
-
const data = ValueSerializer.serialize(error);
|
|
71
|
-
|
|
72
|
-
response.setHeader('Content-Type', 'application/json');
|
|
73
|
-
|
|
74
|
-
return response.status(500).send(data);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { Controller, Get, Post } from '@overnightjs/core';
|
|
3
|
-
import { Request, Response } from 'express';
|
|
4
|
-
import { Logger } from 'tslog';
|
|
5
|
-
|
|
6
|
-
import LocalGateway from '../../runtime/LocalGateway.js';
|
|
7
|
-
import RemoteNode from '../../runtime/RemoteNode.js';
|
|
8
|
-
|
|
9
|
-
import NodeDto from '../models/NodeDto.js';
|
|
10
|
-
import DataConverter from '../utils/DataConverter.js';
|
|
11
|
-
|
|
12
|
-
@Controller('nodes')
|
|
13
|
-
export default class NodesController
|
|
14
|
-
{
|
|
15
|
-
#gateway: LocalGateway;
|
|
16
|
-
#logger: Logger;
|
|
17
|
-
|
|
18
|
-
constructor(gateway: LocalGateway, logger: Logger)
|
|
19
|
-
{
|
|
20
|
-
this.#gateway = gateway;
|
|
21
|
-
this.#logger = logger;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
@Get()
|
|
25
|
-
async getNodes(request: Request, response: Response): Promise<Response>
|
|
26
|
-
{
|
|
27
|
-
const nodes = this.#gateway.nodes.map(node => { return { url: node.url, procedureNames: node.getProcedureNames() }; });
|
|
28
|
-
|
|
29
|
-
this.#logger.info('Got nodes');
|
|
30
|
-
|
|
31
|
-
return response.status(200).send(nodes);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
@Post()
|
|
35
|
-
async add(request: Request, response: Response): Promise<Response>
|
|
36
|
-
{
|
|
37
|
-
try
|
|
38
|
-
{
|
|
39
|
-
const nodeDto = await DataConverter.convert(NodeDto, request.body);
|
|
40
|
-
const node = new RemoteNode(nodeDto.url, nodeDto.procedureNames);
|
|
41
|
-
|
|
42
|
-
this.#gateway.addNode(node);
|
|
43
|
-
|
|
44
|
-
this.#logger.info(`Added node -> ${node.url}`);
|
|
45
|
-
|
|
46
|
-
return response.status(201).send();
|
|
47
|
-
}
|
|
48
|
-
catch (error: unknown)
|
|
49
|
-
{
|
|
50
|
-
const status = error instanceof Array ? 400 : 500;
|
|
51
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
52
|
-
|
|
53
|
-
this.#logger.error(`Failed to add node | ${message}`);
|
|
54
|
-
|
|
55
|
-
return response.status(status).send(error);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { Controller, Get } from '@overnightjs/core';
|
|
3
|
-
import { Request, Response } from 'express';
|
|
4
|
-
import { Logger } from 'tslog';
|
|
5
|
-
|
|
6
|
-
import LocalGateway from '../../runtime/LocalGateway.js';
|
|
7
|
-
import LocalNode from '../../runtime/LocalNode.js';
|
|
8
|
-
import Proxy from '../../runtime/Proxy.js';
|
|
9
|
-
|
|
10
|
-
@Controller('procedures')
|
|
11
|
-
export default class ProceduresController
|
|
12
|
-
{
|
|
13
|
-
#runtime: LocalGateway | LocalNode | Proxy;
|
|
14
|
-
#logger: Logger;
|
|
15
|
-
|
|
16
|
-
constructor(runtime: LocalGateway | LocalNode | Proxy, logger: Logger)
|
|
17
|
-
{
|
|
18
|
-
this.#runtime = runtime;
|
|
19
|
-
this.#logger = logger;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
@Get()
|
|
23
|
-
async getProcedureNames(request: Request, response: Response): Promise<Response>
|
|
24
|
-
{
|
|
25
|
-
const names = this.#runtime.getProcedureNames();
|
|
26
|
-
|
|
27
|
-
this.#logger.info('Got procedure names');
|
|
28
|
-
|
|
29
|
-
return response.status(200).send(names);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { Controller } from '@overnightjs/core';
|
|
3
|
-
import express from 'express';
|
|
4
|
-
import expressProxy from 'express-http-proxy';
|
|
5
|
-
import { IncomingMessage } from 'http';
|
|
6
|
-
import { Logger } from 'tslog';
|
|
7
|
-
|
|
8
|
-
import Proxy from '../../runtime/Proxy.js';
|
|
9
|
-
|
|
10
|
-
@Controller('')
|
|
11
|
-
export default class ProxyController
|
|
12
|
-
{
|
|
13
|
-
#logger: Logger;
|
|
14
|
-
|
|
15
|
-
#repositoryUrl: string;
|
|
16
|
-
#runnerUrl: string;
|
|
17
|
-
|
|
18
|
-
constructor(app: express.Application, proxy: Proxy, logger: Logger)
|
|
19
|
-
{
|
|
20
|
-
this.#logger = logger;
|
|
21
|
-
|
|
22
|
-
this.#repositoryUrl = proxy.repository.url ?? '';
|
|
23
|
-
this.#runnerUrl = proxy.runner.url ?? '';
|
|
24
|
-
|
|
25
|
-
app.use('/', expressProxy((message: IncomingMessage): string => this.#selectProxy(message)));
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
#selectProxy(message: IncomingMessage): string
|
|
29
|
-
{
|
|
30
|
-
const url = message.url ?? '';
|
|
31
|
-
|
|
32
|
-
this.#logger.info(`Forwarding -> ${url}`);
|
|
33
|
-
|
|
34
|
-
return url.startsWith('/rpc')
|
|
35
|
-
? this.#runnerUrl
|
|
36
|
-
: this.#repositoryUrl;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { Controller, Get, Post } from '@overnightjs/core';
|
|
3
|
-
import { Request, Response } from 'express';
|
|
4
|
-
import { Logger } from 'tslog';
|
|
5
|
-
|
|
6
|
-
import Version from '../../core/Version.js';
|
|
7
|
-
|
|
8
|
-
import ProcedureContainer from '../../runtime/interfaces/ProcedureContainer.js';
|
|
9
|
-
import ValueSerializer from '../../runtime/serialization/ValueSerializer.js';
|
|
10
|
-
|
|
11
|
-
const RPC_PARAMETERS = ['version', 'serialize'];
|
|
12
|
-
|
|
13
|
-
@Controller('rpc')
|
|
14
|
-
export default class RPCController
|
|
15
|
-
{
|
|
16
|
-
#runtime: ProcedureContainer;
|
|
17
|
-
#logger: Logger;
|
|
18
|
-
#useSerializer: boolean;
|
|
19
|
-
|
|
20
|
-
constructor(runtime: ProcedureContainer, logger: Logger, useSerializer: boolean)
|
|
21
|
-
{
|
|
22
|
-
this.#runtime = runtime;
|
|
23
|
-
this.#logger = logger;
|
|
24
|
-
this.#useSerializer = useSerializer;
|
|
25
|
-
|
|
26
|
-
this.#showProcedureInfo();
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
#showProcedureInfo()
|
|
30
|
-
{
|
|
31
|
-
const procedureNames = this.#runtime.getProcedureNames();
|
|
32
|
-
|
|
33
|
-
if (procedureNames.length === 0)
|
|
34
|
-
{
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
procedureNames.sort();
|
|
39
|
-
|
|
40
|
-
this.#logger.info('Registered RPC entries', procedureNames);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
@Get('*')
|
|
44
|
-
async runGet(request: Request, response: Response): Promise<Response>
|
|
45
|
-
{
|
|
46
|
-
const fqn = this.#extractFqn(request);
|
|
47
|
-
const version = this.#extractVersion(request);
|
|
48
|
-
const args = this.#extractQueryArguments(request);
|
|
49
|
-
const serialize = this.#extractSerialize(request);
|
|
50
|
-
|
|
51
|
-
return this.#run(fqn, version, args, response, serialize);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
@Post('*')
|
|
55
|
-
async runPost(request: Request, response: Response): Promise<Response>
|
|
56
|
-
{
|
|
57
|
-
const fqn = this.#extractFqn(request);
|
|
58
|
-
const version = this.#extractVersion(request);
|
|
59
|
-
const args = await this.#extractBodyArguments(request);
|
|
60
|
-
const serialize = this.#extractSerialize(request);
|
|
61
|
-
|
|
62
|
-
return this.#run(fqn, version, args, response, serialize);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
#extractFqn(request: Request): string
|
|
66
|
-
{
|
|
67
|
-
return request.path.substring(1);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
#extractVersion(request: Request): Version
|
|
71
|
-
{
|
|
72
|
-
return request.query.version !== undefined
|
|
73
|
-
? Version.parse(request.query.version.toString())
|
|
74
|
-
: Version.DEFAULT;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
#extractSerialize(request: Request): boolean
|
|
78
|
-
{
|
|
79
|
-
return request.query.serialize === 'true';
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
#extractQueryArguments(request: Request): Map<string, unknown>
|
|
83
|
-
{
|
|
84
|
-
const args = new Map<string, unknown>();
|
|
85
|
-
|
|
86
|
-
for (const [key, value] of Object.entries(request.query))
|
|
87
|
-
{
|
|
88
|
-
if (RPC_PARAMETERS.includes(key))
|
|
89
|
-
{
|
|
90
|
-
// We need to filter out the PRC parameters,
|
|
91
|
-
// because they are not a proceure argument.
|
|
92
|
-
|
|
93
|
-
continue;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
args.set(key, value);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
return args;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
async #extractBodyArguments(request: Request): Promise<Map<string, unknown>>
|
|
103
|
-
{
|
|
104
|
-
const args = this.#useSerializer
|
|
105
|
-
? await ValueSerializer.deserialize(request.body) as unknown
|
|
106
|
-
: request.body;
|
|
107
|
-
|
|
108
|
-
return new Map<string, unknown>(Object.entries(args));
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
async #run(fqn: string, version: Version, args: Map<string, unknown>, response: Response, serialize: boolean): Promise<Response>
|
|
112
|
-
{
|
|
113
|
-
if (this.#runtime.hasProcedure(fqn) === false)
|
|
114
|
-
{
|
|
115
|
-
return response.status(404).send(`Procedure not found -> ${fqn}`);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
try
|
|
119
|
-
{
|
|
120
|
-
const result = await this.#runtime.run(fqn, version, args);
|
|
121
|
-
|
|
122
|
-
this.#logger.info(`Ran procedure -> ${fqn} (${version.toString()})`);
|
|
123
|
-
|
|
124
|
-
return this.#createResultResponse(result, response, this.#useSerializer && serialize);
|
|
125
|
-
}
|
|
126
|
-
catch (error: unknown)
|
|
127
|
-
{
|
|
128
|
-
// When using the RPC API we need to return a human readable error message by default.
|
|
129
|
-
// Only when a serialized result is requested we can return the error object (used by the remote).
|
|
130
|
-
|
|
131
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
132
|
-
const errorData = serialize ? error : message;
|
|
133
|
-
|
|
134
|
-
this.#logger.error(`Failed to run procedure -> ${fqn} (${version.toString()}) | ${message}`);
|
|
135
|
-
|
|
136
|
-
return this.#createErrorResponse(errorData, response, serialize);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
#createResultResponse(result: unknown, response: Response, serialize: boolean): Response
|
|
141
|
-
{
|
|
142
|
-
const content = this.#createResponseContent(result, serialize);
|
|
143
|
-
const contentType = this.#createResponseContentType(content);
|
|
144
|
-
|
|
145
|
-
response.setHeader('Content-Type', contentType);
|
|
146
|
-
|
|
147
|
-
return response.status(200).send(content);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
#createErrorResponse(errorData: unknown, response: Response, serialize: boolean): Response
|
|
151
|
-
{
|
|
152
|
-
const content = this.#createResponseContent(errorData, serialize);
|
|
153
|
-
const contentType = this.#createResponseContentType(content);
|
|
154
|
-
|
|
155
|
-
response.setHeader('Content-Type', contentType);
|
|
156
|
-
|
|
157
|
-
return response.status(500).send(content);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
#createResponseContent(data: unknown, serialize: boolean): unknown
|
|
161
|
-
{
|
|
162
|
-
return serialize
|
|
163
|
-
? ValueSerializer.serialize(data)
|
|
164
|
-
: data;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
#createResponseContentType(content: unknown): string
|
|
168
|
-
{
|
|
169
|
-
return typeof content === 'object'
|
|
170
|
-
? 'application/json'
|
|
171
|
-
: 'text/plain';
|
|
172
|
-
}
|
|
173
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { ClassConstructor, plainToClass } from 'class-transformer';
|
|
3
|
-
import { validateOrReject } from 'class-validator';
|
|
4
|
-
|
|
5
|
-
export default class DataConverter
|
|
6
|
-
{
|
|
7
|
-
static async convert<Type extends Object>(targetClass: ClassConstructor<Type>, dataObject: object): Promise<Type>
|
|
8
|
-
{
|
|
9
|
-
const createdObject: Type = plainToClass(targetClass, dataObject);
|
|
10
|
-
|
|
11
|
-
await validateOrReject(createdObject);
|
|
12
|
-
|
|
13
|
-
return createdObject;
|
|
14
|
-
}
|
|
15
|
-
}
|