jitar 0.1.1 → 0.1.3
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/client.d.ts +1 -0
- package/dist/client.js +12 -0
- 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/controllers/RPCController.js +20 -3
- 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 +6 -2
- 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
package/dist/client.d.ts
CHANGED
package/dist/client.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import LocalNode from './runtime/LocalNode.js';
|
|
2
2
|
import RemoteGateway from './runtime/RemoteGateway.js';
|
|
3
3
|
import RemoteRepository from './runtime/RemoteRepository.js';
|
|
4
|
+
let client = undefined;
|
|
5
|
+
const resolvers = [];
|
|
4
6
|
export async function startClient(...segmentFiles) {
|
|
5
7
|
const remoteUrl = document.location.origin;
|
|
6
8
|
const node = new LocalNode();
|
|
@@ -8,5 +10,15 @@ export async function startClient(...segmentFiles) {
|
|
|
8
10
|
const repository = new RemoteRepository(remoteUrl);
|
|
9
11
|
await node.setGateway(gateway);
|
|
10
12
|
await node.setRepository(repository, segmentFiles);
|
|
13
|
+
client = node;
|
|
14
|
+
resolvers.forEach((resolve) => resolve(node));
|
|
11
15
|
return node;
|
|
12
16
|
}
|
|
17
|
+
export async function getClient() {
|
|
18
|
+
if (client === undefined) {
|
|
19
|
+
return new Promise((resolve) => {
|
|
20
|
+
resolvers.push(resolve);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return client;
|
|
24
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import MissingParameterValue from './errors/MissingParameterValue.js';
|
|
2
|
+
import UnknownParameter from './errors/UnknownParameter.js';
|
|
2
3
|
import * as AccessLevel from './definitions/AccessLevel.js';
|
|
3
4
|
export default class Implementation {
|
|
4
5
|
#version;
|
|
@@ -20,6 +21,12 @@ export default class Implementation {
|
|
|
20
21
|
}
|
|
21
22
|
#extractParameterValues(parameters) {
|
|
22
23
|
const values = [];
|
|
24
|
+
const incommingKeys = Array.from(parameters.keys());
|
|
25
|
+
const knownKeys = this.#parameters.map(parameter => parameter.name);
|
|
26
|
+
const additionalKeys = incommingKeys.filter(key => knownKeys.includes(key) === false);
|
|
27
|
+
if (additionalKeys.length !== 0) {
|
|
28
|
+
throw new UnknownParameter(additionalKeys[0]);
|
|
29
|
+
}
|
|
23
30
|
for (const parameter of this.#parameters) {
|
|
24
31
|
const value = parameters.get(parameter.name);
|
|
25
32
|
if (value === undefined && parameter.isOptional === false) {
|
|
@@ -5,7 +5,7 @@ import FileManager from './interfaces/FileManager.js';
|
|
|
5
5
|
import File from './models/File.js';
|
|
6
6
|
export default class LocalRepository extends Repository {
|
|
7
7
|
#private;
|
|
8
|
-
constructor(fileManager: FileManager, url?: string);
|
|
8
|
+
constructor(fileManager: FileManager, assets: string[], url?: string);
|
|
9
9
|
loadSegment(name: string): Promise<void>;
|
|
10
10
|
registerSegment(name: string, files: string[]): Promise<void>;
|
|
11
11
|
registerClient(segmentFilenames: string[]): Promise<string>;
|
|
@@ -3,6 +3,7 @@ import Repository from './Repository.js';
|
|
|
3
3
|
import File from './models/File.js';
|
|
4
4
|
import ModuleLoader from './utils/ModuleLoader.js';
|
|
5
5
|
import ClientNotFound from './errors/ClientNotFound.js';
|
|
6
|
+
import FileNotFound from './errors/FileNotFound.js';
|
|
6
7
|
import InvalidClientId from './errors/InvalidClientId.js';
|
|
7
8
|
import InvalidSegmentFile from './errors/InvalidSegmentFile.js';
|
|
8
9
|
import { setRuntime } from '../hooks.js';
|
|
@@ -10,9 +11,11 @@ export default class LocalRepository extends Repository {
|
|
|
10
11
|
#fileManager;
|
|
11
12
|
#segments = new Map();
|
|
12
13
|
#clients = new Map();
|
|
13
|
-
|
|
14
|
+
#assets;
|
|
15
|
+
constructor(fileManager, assets, url) {
|
|
14
16
|
super(url);
|
|
15
17
|
this.#fileManager = fileManager;
|
|
18
|
+
this.#assets = assets;
|
|
16
19
|
}
|
|
17
20
|
async loadSegment(name) {
|
|
18
21
|
const filename = `./${name}.segment.repository.js`;
|
|
@@ -36,7 +39,10 @@ export default class LocalRepository extends Repository {
|
|
|
36
39
|
setRuntime(runtime);
|
|
37
40
|
}
|
|
38
41
|
async loadAsset(filename) {
|
|
39
|
-
|
|
42
|
+
if (this.#assets.includes(filename) === false) {
|
|
43
|
+
throw new FileNotFound(filename);
|
|
44
|
+
}
|
|
45
|
+
return this.#loadFile(filename);
|
|
40
46
|
}
|
|
41
47
|
async getModuleLocation(clientId) {
|
|
42
48
|
return this.#fileManager.getRootLocation();
|
|
@@ -74,12 +80,15 @@ export default class LocalRepository extends Repository {
|
|
|
74
80
|
if (isSegmented) {
|
|
75
81
|
filename = filename.replace('.js', '.local.js');
|
|
76
82
|
}
|
|
77
|
-
const file = await this
|
|
83
|
+
const file = await this.#loadFile(filename);
|
|
78
84
|
const code = file.content.toString();
|
|
79
85
|
return new File(filename, 'application/javascript', code);
|
|
80
86
|
}
|
|
81
87
|
async #getRemoteModule(filename) {
|
|
82
88
|
const remoteFilename = filename.replace('.js', '.remote.js');
|
|
83
|
-
return this
|
|
89
|
+
return this.#loadFile(remoteFilename);
|
|
90
|
+
}
|
|
91
|
+
async #loadFile(filename) {
|
|
92
|
+
return this.#fileManager.load(filename);
|
|
84
93
|
}
|
|
85
94
|
}
|
|
@@ -7,11 +7,12 @@ 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 { IsOptional, IsString } from 'class-validator';
|
|
10
|
+
import { IsArray, IsOptional, IsString } from 'class-validator';
|
|
11
11
|
export default class RepositoryConfiguration {
|
|
12
12
|
source;
|
|
13
13
|
cache;
|
|
14
14
|
index;
|
|
15
|
+
assets;
|
|
15
16
|
}
|
|
16
17
|
__decorate([
|
|
17
18
|
IsString(),
|
|
@@ -28,3 +29,8 @@ __decorate([
|
|
|
28
29
|
IsOptional(),
|
|
29
30
|
__metadata("design:type", String)
|
|
30
31
|
], RepositoryConfiguration.prototype, "index", void 0);
|
|
32
|
+
__decorate([
|
|
33
|
+
IsArray(),
|
|
34
|
+
IsOptional(),
|
|
35
|
+
__metadata("design:type", Array)
|
|
36
|
+
], RepositoryConfiguration.prototype, "assets", void 0);
|
|
@@ -13,6 +13,7 @@ export default class StandaloneConfiguration {
|
|
|
13
13
|
cache;
|
|
14
14
|
index;
|
|
15
15
|
segments;
|
|
16
|
+
assets;
|
|
16
17
|
}
|
|
17
18
|
__decorate([
|
|
18
19
|
IsString(),
|
|
@@ -34,3 +35,8 @@ __decorate([
|
|
|
34
35
|
IsOptional(),
|
|
35
36
|
__metadata("design:type", Array)
|
|
36
37
|
], StandaloneConfiguration.prototype, "segments", void 0);
|
|
38
|
+
__decorate([
|
|
39
|
+
IsArray(),
|
|
40
|
+
IsOptional(),
|
|
41
|
+
__metadata("design:type", Array)
|
|
42
|
+
], StandaloneConfiguration.prototype, "assets", void 0);
|
|
@@ -10,8 +10,15 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
10
10
|
import { Controller, Get, Post } from '@overnightjs/core';
|
|
11
11
|
import { Logger } from 'tslog';
|
|
12
12
|
import Version from '../../core/Version.js';
|
|
13
|
+
import ImplementationNotFound from '../../core/errors/ImplementationNotFound.js';
|
|
14
|
+
import InvalidVersionNumber from '../../core/errors/InvalidVersionNumber.js';
|
|
15
|
+
import MissingParameterValue from '../../core/errors/MissingParameterValue.js';
|
|
16
|
+
import ProcedureNotFound from '../../core/errors/ProcedureNotFound.js';
|
|
17
|
+
import UnknownParameter from '../../core/errors/UnknownParameter.js';
|
|
13
18
|
import ValueSerializer from '../../runtime/serialization/ValueSerializer.js';
|
|
14
19
|
const RPC_PARAMETERS = ['version', 'serialize'];
|
|
20
|
+
const INVALID_REQUEST_ERRORS = [InvalidVersionNumber, MissingParameterValue, UnknownParameter];
|
|
21
|
+
const NOT_FOUND_ERRORS = [ImplementationNotFound, ProcedureNotFound];
|
|
15
22
|
let RPCController = class RPCController {
|
|
16
23
|
#runtime;
|
|
17
24
|
#logger;
|
|
@@ -84,7 +91,7 @@ let RPCController = class RPCController {
|
|
|
84
91
|
const message = error instanceof Error ? error.message : String(error);
|
|
85
92
|
const errorData = serialize ? error : message;
|
|
86
93
|
this.#logger.error(`Failed to run procedure -> ${fqn} (${version.toString()}) | ${message}`);
|
|
87
|
-
return this.#createErrorResponse(errorData, response, serialize);
|
|
94
|
+
return this.#createErrorResponse(error, errorData, response, serialize);
|
|
88
95
|
}
|
|
89
96
|
}
|
|
90
97
|
#createResultResponse(result, response, serialize) {
|
|
@@ -93,11 +100,12 @@ let RPCController = class RPCController {
|
|
|
93
100
|
response.setHeader('Content-Type', contentType);
|
|
94
101
|
return response.status(200).send(content);
|
|
95
102
|
}
|
|
96
|
-
#createErrorResponse(errorData, response, serialize) {
|
|
103
|
+
#createErrorResponse(error, errorData, response, serialize) {
|
|
97
104
|
const content = this.#createResponseContent(errorData, serialize);
|
|
98
105
|
const contentType = this.#createResponseContentType(content);
|
|
106
|
+
const statusCode = this.#createResponseStatusCode(error);
|
|
99
107
|
response.setHeader('Content-Type', contentType);
|
|
100
|
-
return response.status(
|
|
108
|
+
return response.status(statusCode).send(content);
|
|
101
109
|
}
|
|
102
110
|
#createResponseContent(data, serialize) {
|
|
103
111
|
return serialize
|
|
@@ -109,6 +117,15 @@ let RPCController = class RPCController {
|
|
|
109
117
|
? 'application/json'
|
|
110
118
|
: 'text/plain';
|
|
111
119
|
}
|
|
120
|
+
#createResponseStatusCode(error) {
|
|
121
|
+
if (INVALID_REQUEST_ERRORS.some(invalidError => error instanceof invalidError)) {
|
|
122
|
+
return 400;
|
|
123
|
+
}
|
|
124
|
+
if (NOT_FOUND_ERRORS.some(notFoundError => error instanceof notFoundError)) {
|
|
125
|
+
return 404;
|
|
126
|
+
}
|
|
127
|
+
return 500;
|
|
128
|
+
}
|
|
112
129
|
};
|
|
113
130
|
__decorate([
|
|
114
131
|
Get('*'),
|
|
@@ -51,23 +51,31 @@ export default class LocalFileManager {
|
|
|
51
51
|
return fs.remove(location);
|
|
52
52
|
}
|
|
53
53
|
async getModuleFileNames() {
|
|
54
|
-
|
|
55
|
-
const filenames = await glob(`${location}/**/*.js`);
|
|
56
|
-
return filenames;
|
|
54
|
+
return this.#filterFiles('**/*.js');
|
|
57
55
|
}
|
|
58
56
|
async getSegmentFiles() {
|
|
59
|
-
|
|
60
|
-
const filenames = await glob(`${location}/**/*.segment.json`);
|
|
61
|
-
return filenames;
|
|
57
|
+
return this.#filterFiles('**/*.segment.json');
|
|
62
58
|
}
|
|
63
59
|
async getNodeSegmentFiles() {
|
|
64
|
-
|
|
65
|
-
const filenames = await glob(`${location}/**/*.segment.local.js`);
|
|
66
|
-
return filenames;
|
|
60
|
+
return this.#filterFiles('**/*.segment.local.js');
|
|
67
61
|
}
|
|
68
62
|
async getRepositorySegmentFiles() {
|
|
63
|
+
return this.#filterFiles('**/*.segment.repository.js');
|
|
64
|
+
}
|
|
65
|
+
async getAssetFiles(patterns) {
|
|
66
|
+
const promises = patterns.map(pattern => this.#filterFiles(pattern));
|
|
67
|
+
const assetFiles = (await Promise.all(promises)).flat();
|
|
68
|
+
return assetFiles
|
|
69
|
+
.map(filename => this.getRelativeLocation(filename))
|
|
70
|
+
.filter(filename => this.#isGeneratedFile(filename) === false);
|
|
71
|
+
}
|
|
72
|
+
async #filterFiles(pattern) {
|
|
69
73
|
const location = this.getAbsoluteLocation('./');
|
|
70
|
-
|
|
71
|
-
|
|
74
|
+
return await glob(`${location}/${pattern}`);
|
|
75
|
+
}
|
|
76
|
+
#isGeneratedFile(filename) {
|
|
77
|
+
return filename.endsWith('.local.js')
|
|
78
|
+
|| filename.endsWith('.repository.js')
|
|
79
|
+
|| filename.endsWith('.remote.js');
|
|
72
80
|
}
|
|
73
81
|
}
|
|
@@ -29,19 +29,21 @@ export default class RuntimeConfigurator {
|
|
|
29
29
|
static async #configureStandAlone(url, configuration) {
|
|
30
30
|
const sourceLocation = configuration.source ?? RuntimeDefaults.SOURCE;
|
|
31
31
|
const cacheLocation = configuration.cache ?? RuntimeDefaults.CACHE;
|
|
32
|
+
const assetFilePatterns = configuration.assets;
|
|
32
33
|
await this.#buildCache(sourceLocation, cacheLocation);
|
|
33
34
|
const segmentNames = configuration.segments === undefined
|
|
34
35
|
? await this.#getSegmentNames(cacheLocation)
|
|
35
36
|
: configuration.segments;
|
|
36
|
-
const repository = await this.#buildRepository(url, cacheLocation);
|
|
37
|
+
const repository = await this.#buildRepository(url, cacheLocation, assetFilePatterns);
|
|
37
38
|
const node = await this.#buildNode(url, segmentNames, repository);
|
|
38
39
|
return this.#buildProxy(url, repository, node);
|
|
39
40
|
}
|
|
40
41
|
static async #configureRepository(url, configuration) {
|
|
41
42
|
const sourceLocation = configuration.source ?? RuntimeDefaults.SOURCE;
|
|
42
43
|
const cacheLocation = configuration.cache ?? RuntimeDefaults.CACHE;
|
|
44
|
+
const assetFilePatterns = configuration.assets ?? [];
|
|
43
45
|
await this.#buildCache(sourceLocation, cacheLocation);
|
|
44
|
-
return this.#buildRepository(url, cacheLocation);
|
|
46
|
+
return this.#buildRepository(url, cacheLocation, assetFilePatterns);
|
|
45
47
|
}
|
|
46
48
|
static async #configureGateway(url, configuration) {
|
|
47
49
|
return this.#buildGateway(url, configuration.monitor);
|
|
@@ -95,9 +97,12 @@ export default class RuntimeConfigurator {
|
|
|
95
97
|
const endIndex = name.indexOf('.segment');
|
|
96
98
|
return name.substring(0, endIndex);
|
|
97
99
|
}
|
|
98
|
-
static async #buildRepository(url, cacheLocation) {
|
|
100
|
+
static async #buildRepository(url, cacheLocation, assetFilePatterns) {
|
|
99
101
|
const fileManager = new LocalFileManager(cacheLocation);
|
|
100
|
-
const
|
|
102
|
+
const assetFiles = assetFilePatterns !== undefined
|
|
103
|
+
? await fileManager.getAssetFiles(assetFilePatterns)
|
|
104
|
+
: [];
|
|
105
|
+
const repository = new LocalRepository(fileManager, assetFiles, url);
|
|
101
106
|
const segmentFilenames = await fileManager.getRepositorySegmentFiles();
|
|
102
107
|
const segmentNames = segmentFilenames.map(filename => this.#extractSegmentName(filename));
|
|
103
108
|
for (const name of segmentNames) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jitar",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Distributed runtime for JavaScript and TypeScript to chop monolithic applications into micros.",
|
|
5
5
|
"author": "Masking Technology <info@masking.tech> (https://jitar.dev)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
"test-coverage": "jest --coverage",
|
|
19
19
|
"lint": "eslint . --ext .ts",
|
|
20
20
|
"build": "tsc -p tsconfig.json",
|
|
21
|
-
"clean": "rm -rf dist build"
|
|
21
|
+
"clean": "rm -rf dist build",
|
|
22
|
+
"release": "npm run clean && npm run build && npm publish"
|
|
22
23
|
},
|
|
23
24
|
"dependencies": {
|
|
24
25
|
"@overnightjs/core": "^1.7.6",
|
|
@@ -46,6 +47,9 @@
|
|
|
46
47
|
"jest": "^28.1.3",
|
|
47
48
|
"ts-jest": "^28.0.8"
|
|
48
49
|
},
|
|
50
|
+
"engines": {
|
|
51
|
+
"node": ">=18.7"
|
|
52
|
+
},
|
|
49
53
|
"repository": {
|
|
50
54
|
"type": "git",
|
|
51
55
|
"url": "https://github.com/MaskingTechnology/jitar"
|
package/.eslintignore
DELETED
package/.eslintrc
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"root": true,
|
|
3
|
-
"parser": "@typescript-eslint/parser",
|
|
4
|
-
"plugins": [
|
|
5
|
-
"@typescript-eslint"
|
|
6
|
-
],
|
|
7
|
-
"extends": [
|
|
8
|
-
"eslint:recommended",
|
|
9
|
-
"plugin:@typescript-eslint/eslint-recommended",
|
|
10
|
-
"plugin:@typescript-eslint/recommended"
|
|
11
|
-
],
|
|
12
|
-
"rules":
|
|
13
|
-
{
|
|
14
|
-
"@typescript-eslint/ban-types": "off"
|
|
15
|
-
}
|
|
16
|
-
}
|
package/jest.config.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
|
|
2
|
-
export default {
|
|
3
|
-
preset: 'ts-jest',
|
|
4
|
-
testEnvironment: 'node',
|
|
5
|
-
coverageProvider: 'v8',
|
|
6
|
-
extensionsToTreatAsEsm: ['.ts'],
|
|
7
|
-
globals: {
|
|
8
|
-
'ts-jest': {
|
|
9
|
-
useESM: true
|
|
10
|
-
}
|
|
11
|
-
},
|
|
12
|
-
moduleNameMapper: {
|
|
13
|
-
'^(\\.{1,2}/.*)\\.js$': '$1',
|
|
14
|
-
},
|
|
15
|
-
coveragePathIgnorePatterns: [
|
|
16
|
-
'<rootDir>/node_modules/',
|
|
17
|
-
'<rootDir>/test/_fixtures/',
|
|
18
|
-
'<rootDir>/src/runtime/Remote.ts',
|
|
19
|
-
]
|
|
20
|
-
};
|
package/src/client.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import LocalNode from './runtime/LocalNode.js';
|
|
3
|
-
import RemoteGateway from './runtime/RemoteGateway.js';
|
|
4
|
-
import RemoteRepository from './runtime/RemoteRepository.js';
|
|
5
|
-
|
|
6
|
-
export async function startClient(...segmentFiles: string[]): Promise<LocalNode>
|
|
7
|
-
{
|
|
8
|
-
const remoteUrl = document.location.origin;
|
|
9
|
-
|
|
10
|
-
const node = new LocalNode();
|
|
11
|
-
const gateway = new RemoteGateway(remoteUrl);
|
|
12
|
-
const repository = new RemoteRepository(remoteUrl);
|
|
13
|
-
|
|
14
|
-
await node.setGateway(gateway);
|
|
15
|
-
await node.setRepository(repository, segmentFiles);
|
|
16
|
-
|
|
17
|
-
return node;
|
|
18
|
-
}
|
package/src/core/ErrorManager.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
export default class ErrorManager
|
|
3
|
-
{
|
|
4
|
-
static handle(error: unknown, name: string, version: string): Error
|
|
5
|
-
{
|
|
6
|
-
const parentMessage = error instanceof Error ? error.message : String(error);
|
|
7
|
-
const newMessage = `${parentMessage}\n[${name} | v${version}]`;
|
|
8
|
-
|
|
9
|
-
if (error instanceof Error)
|
|
10
|
-
{
|
|
11
|
-
error.message = newMessage;
|
|
12
|
-
|
|
13
|
-
return error;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
return new Error(newMessage);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import MissingParameterValue from './errors/MissingParameterValue.js';
|
|
3
|
-
import ReflectionParameter from './reflection/models/ReflectionParameter.js';
|
|
4
|
-
import * as AccessLevel from './definitions/AccessLevel.js';
|
|
5
|
-
import Version from './Version.js';
|
|
6
|
-
|
|
7
|
-
export default class Implementation
|
|
8
|
-
{
|
|
9
|
-
#version: Version;
|
|
10
|
-
#access: string;
|
|
11
|
-
#parameters: ReflectionParameter[];
|
|
12
|
-
#executable: Function;
|
|
13
|
-
|
|
14
|
-
constructor(version: Version, access: string, parameters: ReflectionParameter[], executable: Function)
|
|
15
|
-
{
|
|
16
|
-
this.#version = version;
|
|
17
|
-
this.#access = access;
|
|
18
|
-
this.#parameters = parameters;
|
|
19
|
-
this.#executable = executable;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
get version() { return this.#version; }
|
|
23
|
-
|
|
24
|
-
get public() { return this.#access === AccessLevel.PUBLIC; }
|
|
25
|
-
|
|
26
|
-
get parameters() { return this.#parameters; }
|
|
27
|
-
|
|
28
|
-
async run(args: Map<string, unknown>): Promise<unknown>
|
|
29
|
-
{
|
|
30
|
-
const values = this.#extractParameterValues(args);
|
|
31
|
-
|
|
32
|
-
return await this.#executable.call(this.#executable, ...values);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
#extractParameterValues(parameters: Map<string, unknown>): unknown[]
|
|
36
|
-
{
|
|
37
|
-
const values: unknown[] = [];
|
|
38
|
-
|
|
39
|
-
for (const parameter of this.#parameters)
|
|
40
|
-
{
|
|
41
|
-
const value = parameters.get(parameter.name);
|
|
42
|
-
|
|
43
|
-
if (value === undefined && parameter.isOptional === false)
|
|
44
|
-
{
|
|
45
|
-
throw new MissingParameterValue(parameter.name);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
values.push(value);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return values;
|
|
52
|
-
}
|
|
53
|
-
}
|
package/src/core/Procedure.ts
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import ImplementationNotFound from './errors/ImplementationNotFound.js';
|
|
3
|
-
import Implementation from './Implementation.js';
|
|
4
|
-
import FqnBuilder from './utils/FqnBuilder.js';
|
|
5
|
-
import Version from './Version.js';
|
|
6
|
-
|
|
7
|
-
export default class Procedure
|
|
8
|
-
{
|
|
9
|
-
#module: string;
|
|
10
|
-
#name: string;
|
|
11
|
-
#fqn: string;
|
|
12
|
-
#implementations: Map<Version, Implementation> = new Map();
|
|
13
|
-
#latestImplementation?: Implementation;
|
|
14
|
-
|
|
15
|
-
constructor(module: string, name: string)
|
|
16
|
-
{
|
|
17
|
-
this.#module = module;
|
|
18
|
-
this.#name = name;
|
|
19
|
-
|
|
20
|
-
this.#fqn = FqnBuilder.build(module, name);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
get module() { return this.#module; }
|
|
24
|
-
|
|
25
|
-
get name() { return this.#name; }
|
|
26
|
-
|
|
27
|
-
get fqn() { return this.#fqn; }
|
|
28
|
-
|
|
29
|
-
get public()
|
|
30
|
-
{
|
|
31
|
-
// If at least one implementation is public, the procedure is public
|
|
32
|
-
// Public procedures can be called from outside the segment
|
|
33
|
-
|
|
34
|
-
const implementations = [...this.#implementations.values()];
|
|
35
|
-
|
|
36
|
-
return implementations.some(implementation => implementation.public);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
addImplementation(implementation: Implementation): void
|
|
40
|
-
{
|
|
41
|
-
this.#implementations.set(implementation.version, implementation);
|
|
42
|
-
|
|
43
|
-
if (this.#isNewLatestImplementation(implementation))
|
|
44
|
-
{
|
|
45
|
-
this.#latestImplementation = implementation;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
#isNewLatestImplementation(implementation: Implementation): boolean
|
|
50
|
-
{
|
|
51
|
-
return this.#latestImplementation === undefined
|
|
52
|
-
|| implementation.version.greater(this.#latestImplementation.version);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
getImplementation(version: Version): Implementation | undefined
|
|
56
|
-
{
|
|
57
|
-
const selectedVersion = this.#selectAvailableVersion(version);
|
|
58
|
-
|
|
59
|
-
return this.#implementations.get(selectedVersion);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
#selectAvailableVersion(version: Version): Version
|
|
63
|
-
{
|
|
64
|
-
let selectedVersion = Version.DEFAULT;
|
|
65
|
-
|
|
66
|
-
for (const implementationVersion of this.#implementations.keys())
|
|
67
|
-
{
|
|
68
|
-
if (implementationVersion.equals(version))
|
|
69
|
-
{
|
|
70
|
-
return implementationVersion;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (implementationVersion.greater(version))
|
|
74
|
-
{
|
|
75
|
-
continue;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (selectedVersion.less(implementationVersion))
|
|
79
|
-
{
|
|
80
|
-
selectedVersion = implementationVersion;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return selectedVersion;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
async run(version: Version, args: Map<string, unknown>): Promise<unknown>
|
|
88
|
-
{
|
|
89
|
-
const implementation = this.getImplementation(version);
|
|
90
|
-
|
|
91
|
-
if (implementation === undefined)
|
|
92
|
-
{
|
|
93
|
-
throw new ImplementationNotFound(this.fqn, version.toString());
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return implementation.run(args);
|
|
97
|
-
}
|
|
98
|
-
}
|
package/src/core/Segment.ts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import ErrorManager from './ErrorManager.js';
|
|
3
|
-
import ProcedureNotFound from './errors/ProcedureNotFound.js';
|
|
4
|
-
import Runner from './interfaces/Runner.js';
|
|
5
|
-
import Procedure from './Procedure.js';
|
|
6
|
-
import Version from './Version.js';
|
|
7
|
-
|
|
8
|
-
export default class Segment implements Runner
|
|
9
|
-
{
|
|
10
|
-
#id: string;
|
|
11
|
-
#procedures: Map<string, Procedure> = new Map();
|
|
12
|
-
|
|
13
|
-
constructor(id: string)
|
|
14
|
-
{
|
|
15
|
-
this.#id = id;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
get id() { return this.#id; }
|
|
19
|
-
|
|
20
|
-
addProcedure(procedure: Procedure): void
|
|
21
|
-
{
|
|
22
|
-
this.#procedures.set(procedure.fqn, procedure);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
hasProcedure(fqn: string): boolean
|
|
26
|
-
{
|
|
27
|
-
const procedure = this.getProcedure(fqn);
|
|
28
|
-
|
|
29
|
-
return procedure !== undefined;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
getProcedure(fqn: string): Procedure | undefined
|
|
33
|
-
{
|
|
34
|
-
return this.#procedures.get(fqn);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
getPublicProcedures()
|
|
38
|
-
{
|
|
39
|
-
const procedures = [...this.#procedures.values()];
|
|
40
|
-
|
|
41
|
-
return procedures.filter(procedure => procedure.public);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async run(fqn: string, version: Version, args: Map<string, unknown>): Promise<unknown>
|
|
45
|
-
{
|
|
46
|
-
const procedure = this.getProcedure(fqn);
|
|
47
|
-
|
|
48
|
-
if (procedure === undefined)
|
|
49
|
-
{
|
|
50
|
-
throw new ProcedureNotFound(fqn);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
try
|
|
54
|
-
{
|
|
55
|
-
return await procedure.run(version, args);
|
|
56
|
-
}
|
|
57
|
-
catch (error: unknown)
|
|
58
|
-
{
|
|
59
|
-
throw ErrorManager.handle(error, fqn, version.toString());
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|