jitar 0.3.9 → 0.4.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/CHANGELOG.md +1 -94
- package/dist/client.js +1 -24
- package/dist/globals-d516de70.js +1 -0
- package/dist/lib.d.ts +309 -35
- package/dist/lib.js +1 -29
- package/dist/server.js +1 -0
- package/package.json +19 -12
- package/LICENCE +0 -23
- package/dist/client.d.ts +0 -3
- package/dist/core/Context.d.ts +0 -5
- package/dist/core/Context.js +0 -7
- package/dist/core/ErrorManager.d.ts +0 -3
- package/dist/core/ErrorManager.js +0 -11
- package/dist/core/Implementation.d.ts +0 -10
- package/dist/core/Implementation.js +0 -44
- package/dist/core/Procedure.d.ts +0 -13
- package/dist/core/Procedure.js +0 -58
- package/dist/core/Segment.d.ts +0 -13
- package/dist/core/Segment.js +0 -36
- package/dist/core/SegmentBuilder.d.ts +0 -6
- package/dist/core/SegmentBuilder.js +0 -32
- package/dist/core/Version.d.ts +0 -13
- package/dist/core/Version.js +0 -50
- package/dist/core/definitions/AccessLevel.d.ts +0 -2
- package/dist/core/definitions/AccessLevel.js +0 -2
- package/dist/core/errors/BadRequest.d.ts +0 -3
- package/dist/core/errors/BadRequest.js +0 -6
- package/dist/core/errors/Forbidden.d.ts +0 -3
- package/dist/core/errors/Forbidden.js +0 -6
- package/dist/core/errors/ImplementationNotFound.d.ts +0 -4
- package/dist/core/errors/ImplementationNotFound.js +0 -7
- package/dist/core/errors/InvalidVersionNumber.d.ts +0 -4
- package/dist/core/errors/InvalidVersionNumber.js +0 -7
- package/dist/core/errors/MissingParameterValue.d.ts +0 -4
- package/dist/core/errors/MissingParameterValue.js +0 -7
- package/dist/core/errors/NotFound.d.ts +0 -3
- package/dist/core/errors/NotFound.js +0 -6
- package/dist/core/errors/NotImplemented.d.ts +0 -3
- package/dist/core/errors/NotImplemented.js +0 -6
- package/dist/core/errors/PaymentRequired.d.ts +0 -3
- package/dist/core/errors/PaymentRequired.js +0 -6
- package/dist/core/errors/ProcedureNotFound.d.ts +0 -4
- package/dist/core/errors/ProcedureNotFound.js +0 -7
- package/dist/core/errors/Teapot.d.ts +0 -3
- package/dist/core/errors/Teapot.js +0 -6
- package/dist/core/errors/Unauthorized.d.ts +0 -3
- package/dist/core/errors/Unauthorized.js +0 -6
- package/dist/core/errors/UnknownParameter.d.ts +0 -4
- package/dist/core/errors/UnknownParameter.js +0 -7
- package/dist/core/interfaces/Runner.d.ts +0 -4
- package/dist/core/interfaces/Runner.js +0 -1
- package/dist/core/reflection/ParameterParser.d.ts +0 -5
- package/dist/core/reflection/ParameterParser.js +0 -51
- package/dist/core/reflection/ReflectionHelper.d.ts +0 -13
- package/dist/core/reflection/ReflectionHelper.js +0 -69
- package/dist/core/reflection/models/ReflectionField.d.ts +0 -8
- package/dist/core/reflection/models/ReflectionField.js +0 -14
- package/dist/core/reflection/models/ReflectionParameter.d.ts +0 -7
- package/dist/core/reflection/models/ReflectionParameter.js +0 -11
- package/dist/core/types/Component.d.ts +0 -5
- package/dist/core/types/Component.js +0 -1
- package/dist/core/types/FlexObject.d.ts +0 -4
- package/dist/core/types/FlexObject.js +0 -1
- package/dist/core/types/Module.d.ts +0 -3
- package/dist/core/types/Module.js +0 -1
- package/dist/core/types/SegmentImplementation.d.ts +0 -6
- package/dist/core/types/SegmentImplementation.js +0 -1
- package/dist/core/types/SegmentModule.d.ts +0 -5
- package/dist/core/types/SegmentModule.js +0 -1
- package/dist/core/types/SegmentProcedure.d.ts +0 -7
- package/dist/core/types/SegmentProcedure.js +0 -1
- package/dist/core/utils/FqnBuilder.d.ts +0 -3
- package/dist/core/utils/FqnBuilder.js +0 -5
- package/dist/hooks.d.ts +0 -2
- package/dist/hooks.js +0 -2
- package/dist/runtime/ClientId.d.ts +0 -4
- package/dist/runtime/ClientId.js +0 -11
- package/dist/runtime/Gateway.d.ts +0 -5
- package/dist/runtime/Gateway.js +0 -3
- package/dist/runtime/LocalGateway.d.ts +0 -14
- package/dist/runtime/LocalGateway.js +0 -61
- package/dist/runtime/LocalNode.d.ts +0 -18
- package/dist/runtime/LocalNode.js +0 -75
- package/dist/runtime/LocalRepository.d.ts +0 -17
- package/dist/runtime/LocalRepository.js +0 -94
- package/dist/runtime/Node.d.ts +0 -3
- package/dist/runtime/Node.js +0 -3
- package/dist/runtime/NodeBalancer.d.ts +0 -9
- package/dist/runtime/NodeBalancer.js +0 -34
- package/dist/runtime/NodeMonitor.d.ts +0 -7
- package/dist/runtime/NodeMonitor.js +0 -38
- package/dist/runtime/ProcedureRunner.d.ts +0 -9
- package/dist/runtime/ProcedureRunner.js +0 -11
- package/dist/runtime/ProcedureRuntime.d.ts +0 -14
- package/dist/runtime/ProcedureRuntime.js +0 -28
- package/dist/runtime/Proxy.d.ts +0 -18
- package/dist/runtime/Proxy.js +0 -33
- package/dist/runtime/Remote.d.ts +0 -15
- package/dist/runtime/Remote.js +0 -102
- package/dist/runtime/RemoteGateway.d.ts +0 -11
- package/dist/runtime/RemoteGateway.js +0 -22
- package/dist/runtime/RemoteNode.d.ts +0 -12
- package/dist/runtime/RemoteNode.js +0 -29
- package/dist/runtime/RemoteRepository.d.ts +0 -14
- package/dist/runtime/RemoteRepository.js +0 -34
- package/dist/runtime/Repository.d.ts +0 -11
- package/dist/runtime/Repository.js +0 -3
- package/dist/runtime/Runtime.d.ts +0 -9
- package/dist/runtime/Runtime.js +0 -27
- package/dist/runtime/caching/CacheBuilder.d.ts +0 -6
- package/dist/runtime/caching/CacheBuilder.js +0 -246
- package/dist/runtime/caching/ImportRewriter.d.ts +0 -4
- package/dist/runtime/caching/ImportRewriter.js +0 -58
- package/dist/runtime/caching/RemoteBuilder.d.ts +0 -5
- package/dist/runtime/caching/RemoteBuilder.js +0 -31
- package/dist/runtime/caching/SourceAppender.d.ts +0 -5
- package/dist/runtime/caching/SourceAppender.js +0 -30
- package/dist/runtime/caching/definitions/Keywords.d.ts +0 -2
- package/dist/runtime/caching/definitions/Keywords.js +0 -2
- package/dist/runtime/caching/errors/InvalidSegmentFilename.d.ts +0 -3
- package/dist/runtime/caching/errors/InvalidSegmentFilename.js +0 -5
- package/dist/runtime/caching/errors/MissingModuleExport.d.ts +0 -3
- package/dist/runtime/caching/errors/MissingModuleExport.js +0 -5
- package/dist/runtime/caching/errors/SegmentFileNotLoaded.d.ts +0 -3
- package/dist/runtime/caching/errors/SegmentFileNotLoaded.js +0 -5
- package/dist/runtime/caching/errors/SegmentModuleNotLoaded.d.ts +0 -3
- package/dist/runtime/caching/errors/SegmentModuleNotLoaded.js +0 -5
- package/dist/runtime/caching/models/ApplicationModule.d.ts +0 -10
- package/dist/runtime/caching/models/ApplicationModule.js +0 -19
- package/dist/runtime/caching/models/Implementation.d.ts +0 -12
- package/dist/runtime/caching/models/Implementation.js +0 -27
- package/dist/runtime/caching/models/Procedure.d.ts +0 -9
- package/dist/runtime/caching/models/Procedure.js +0 -15
- package/dist/runtime/caching/models/Segment.d.ts +0 -10
- package/dist/runtime/caching/models/Segment.js +0 -16
- package/dist/runtime/caching/models/SegmentModule.d.ts +0 -10
- package/dist/runtime/caching/models/SegmentModule.js +0 -14
- package/dist/runtime/caching/types/SegmentFile.d.ts +0 -5
- package/dist/runtime/caching/types/SegmentFile.js +0 -1
- package/dist/runtime/caching/types/SegmentImportProperties.d.ts +0 -6
- package/dist/runtime/caching/types/SegmentImportProperties.js +0 -1
- package/dist/runtime/caching/types/SegmentImports.d.ts +0 -5
- package/dist/runtime/caching/types/SegmentImports.js +0 -1
- package/dist/runtime/errors/ClientNotFound.d.ts +0 -3
- package/dist/runtime/errors/ClientNotFound.js +0 -6
- package/dist/runtime/errors/FileNotFound.d.ts +0 -3
- package/dist/runtime/errors/FileNotFound.js +0 -6
- package/dist/runtime/errors/InvalidClientId.d.ts +0 -3
- package/dist/runtime/errors/InvalidClientId.js +0 -6
- package/dist/runtime/errors/InvalidJitarHooks.d.ts +0 -3
- package/dist/runtime/errors/InvalidJitarHooks.js +0 -6
- package/dist/runtime/errors/InvalidSegmentFile.d.ts +0 -3
- package/dist/runtime/errors/InvalidSegmentFile.js +0 -6
- package/dist/runtime/errors/ModuleNotLoaded.d.ts +0 -3
- package/dist/runtime/errors/ModuleNotLoaded.js +0 -6
- package/dist/runtime/errors/NoNodeAvailable.d.ts +0 -3
- package/dist/runtime/errors/NoNodeAvailable.js +0 -6
- package/dist/runtime/errors/RepositoryNotAvaiable.d.ts +0 -3
- package/dist/runtime/errors/RepositoryNotAvaiable.js +0 -6
- package/dist/runtime/errors/RuntimeNotAvailable.d.ts +0 -3
- package/dist/runtime/errors/RuntimeNotAvailable.js +0 -6
- package/dist/runtime/errors/SegmentNotFound.d.ts +0 -3
- package/dist/runtime/errors/SegmentNotFound.js +0 -6
- package/dist/runtime/hooks/dependencies.d.ts +0 -2
- package/dist/runtime/hooks/dependencies.js +0 -9
- package/dist/runtime/hooks/runtime.d.ts +0 -3
- package/dist/runtime/hooks/runtime.js +0 -16
- package/dist/runtime/interfaces/FileManager.d.ts +0 -11
- package/dist/runtime/interfaces/FileManager.js +0 -1
- package/dist/runtime/interfaces/HealthCheck.d.ts +0 -3
- package/dist/runtime/interfaces/HealthCheck.js +0 -1
- package/dist/runtime/interfaces/Middleware.d.ts +0 -5
- package/dist/runtime/interfaces/Middleware.js +0 -1
- package/dist/runtime/middleware/CorsMiddleware.d.ts +0 -11
- package/dist/runtime/middleware/CorsMiddleware.js +0 -22
- package/dist/runtime/models/File.d.ts +0 -9
- package/dist/runtime/models/File.js +0 -14
- package/dist/runtime/serialization/ArrayBufferSerializer.d.ts +0 -10
- package/dist/runtime/serialization/ArrayBufferSerializer.js +0 -54
- package/dist/runtime/serialization/ArraySerializer.d.ts +0 -7
- package/dist/runtime/serialization/ArraySerializer.js +0 -15
- package/dist/runtime/serialization/ClassSerializer.d.ts +0 -10
- package/dist/runtime/serialization/ClassSerializer.js +0 -74
- package/dist/runtime/serialization/DateSerializer.d.ts +0 -9
- package/dist/runtime/serialization/DateSerializer.js +0 -21
- package/dist/runtime/serialization/MapSerializer.d.ts +0 -9
- package/dist/runtime/serialization/MapSerializer.js +0 -35
- package/dist/runtime/serialization/ObjectSerializer.d.ts +0 -9
- package/dist/runtime/serialization/ObjectSerializer.js +0 -21
- package/dist/runtime/serialization/SetSerializer.d.ts +0 -9
- package/dist/runtime/serialization/SetSerializer.js +0 -23
- package/dist/runtime/serialization/ValueSerializer.d.ts +0 -8
- package/dist/runtime/serialization/ValueSerializer.js +0 -69
- package/dist/runtime/serialization/errors/ClassNotFound.d.ts +0 -3
- package/dist/runtime/serialization/errors/ClassNotFound.js +0 -6
- package/dist/runtime/serialization/errors/InvalidClass.d.ts +0 -3
- package/dist/runtime/serialization/errors/InvalidClass.js +0 -6
- package/dist/runtime/serialization/errors/InvalidPropertyType.d.ts +0 -4
- package/dist/runtime/serialization/errors/InvalidPropertyType.js +0 -7
- package/dist/runtime/serialization/interfaces/Serializer.d.ts +0 -4
- package/dist/runtime/serialization/interfaces/Serializer.js +0 -1
- package/dist/runtime/serialization/types/SerializableObject.d.ts +0 -3
- package/dist/runtime/serialization/types/SerializableObject.js +0 -1
- package/dist/runtime/serialization/types/Serialized.d.ts +0 -5
- package/dist/runtime/serialization/types/Serialized.js +0 -1
- package/dist/runtime/serialization/types/SerializedArrayBuffer.d.ts +0 -6
- package/dist/runtime/serialization/types/SerializedArrayBuffer.js +0 -1
- package/dist/runtime/serialization/types/SerializedClass.d.ts +0 -8
- package/dist/runtime/serialization/types/SerializedClass.js +0 -1
- package/dist/runtime/serialization/types/SerializedDate.d.ts +0 -5
- package/dist/runtime/serialization/types/SerializedDate.js +0 -1
- package/dist/runtime/serialization/types/SerializedMap.d.ts +0 -8
- package/dist/runtime/serialization/types/SerializedMap.js +0 -1
- package/dist/runtime/serialization/types/SerializedObject.d.ts +0 -4
- package/dist/runtime/serialization/types/SerializedObject.js +0 -1
- package/dist/runtime/serialization/types/SerializedSet.d.ts +0 -5
- package/dist/runtime/serialization/types/SerializedSet.js +0 -1
- package/dist/runtime/serialization/types/TypedArray.d.ts +0 -2
- package/dist/runtime/serialization/types/TypedArray.js +0 -1
- package/dist/runtime/types/JitarHooks.d.ts +0 -6
- package/dist/runtime/types/JitarHooks.js +0 -1
- package/dist/runtime/types/ModuleImporter.d.ts +0 -3
- package/dist/runtime/types/ModuleImporter.js +0 -1
- package/dist/runtime/types/NextHandler.d.ts +0 -2
- package/dist/runtime/types/NextHandler.js +0 -1
- package/dist/runtime/utils/ModuleAnalyser.d.ts +0 -7
- package/dist/runtime/utils/ModuleAnalyser.js +0 -23
- package/dist/runtime/utils/ModuleLoader.d.ts +0 -8
- package/dist/runtime/utils/ModuleLoader.js +0 -30
- package/dist/runtime/utils/UrlRewriter.d.ts +0 -4
- package/dist/runtime/utils/UrlRewriter.js +0 -36
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import ClientId from './ClientId.js';
|
|
2
|
-
import Repository from './Repository.js';
|
|
3
|
-
import File from './models/File.js';
|
|
4
|
-
import ModuleLoader from './utils/ModuleLoader.js';
|
|
5
|
-
import ClientNotFound from './errors/ClientNotFound.js';
|
|
6
|
-
import FileNotFound from './errors/FileNotFound.js';
|
|
7
|
-
import InvalidClientId from './errors/InvalidClientId.js';
|
|
8
|
-
import InvalidSegmentFile from './errors/InvalidSegmentFile.js';
|
|
9
|
-
import { setRuntime } from '../hooks.js';
|
|
10
|
-
export default class LocalRepository extends Repository {
|
|
11
|
-
#fileManager;
|
|
12
|
-
#segments = new Map();
|
|
13
|
-
#clients = new Map();
|
|
14
|
-
#assets;
|
|
15
|
-
constructor(fileManager, assets, url) {
|
|
16
|
-
super(url);
|
|
17
|
-
this.#fileManager = fileManager;
|
|
18
|
-
this.#assets = assets;
|
|
19
|
-
}
|
|
20
|
-
async loadSegment(name) {
|
|
21
|
-
const filename = `./${name}.segment.repository.js`;
|
|
22
|
-
const location = this.#fileManager.getAbsoluteLocation(filename);
|
|
23
|
-
const module = await ModuleLoader.load(location);
|
|
24
|
-
const files = module.files;
|
|
25
|
-
if (files === undefined) {
|
|
26
|
-
throw new InvalidSegmentFile(location);
|
|
27
|
-
}
|
|
28
|
-
this.registerSegment(name, files);
|
|
29
|
-
}
|
|
30
|
-
async registerSegment(name, files) {
|
|
31
|
-
files.forEach((file) => this.#segments.set(file, name));
|
|
32
|
-
}
|
|
33
|
-
async registerClient(segmentFilenames) {
|
|
34
|
-
const clientId = ClientId.generate();
|
|
35
|
-
this.#clients.set(clientId, segmentFilenames);
|
|
36
|
-
return clientId;
|
|
37
|
-
}
|
|
38
|
-
async setRuntime(runtime) {
|
|
39
|
-
setRuntime(runtime);
|
|
40
|
-
}
|
|
41
|
-
async loadAsset(filename) {
|
|
42
|
-
if (this.#assets.includes(filename) === false) {
|
|
43
|
-
throw new FileNotFound(filename);
|
|
44
|
-
}
|
|
45
|
-
return this.#loadFile(filename);
|
|
46
|
-
}
|
|
47
|
-
async getModuleLocation(clientId) {
|
|
48
|
-
return this.#fileManager.getRootLocation();
|
|
49
|
-
}
|
|
50
|
-
async loadModule(clientId, filename) {
|
|
51
|
-
this.#validateClientId(clientId);
|
|
52
|
-
const segmentFilename = this.#segments.get(filename);
|
|
53
|
-
if (segmentFilename === undefined) {
|
|
54
|
-
return this.#getNodeModule(filename, false);
|
|
55
|
-
}
|
|
56
|
-
return this.#hasClientSegmentFile(clientId, segmentFilename)
|
|
57
|
-
? this.#getNodeModule(filename, true)
|
|
58
|
-
: this.#getRemoteModule(filename);
|
|
59
|
-
}
|
|
60
|
-
async importModule(clientId, filename) {
|
|
61
|
-
const location = this.#fileManager.getAbsoluteLocation(filename);
|
|
62
|
-
return ModuleLoader.import(location);
|
|
63
|
-
}
|
|
64
|
-
#validateClientId(clientId) {
|
|
65
|
-
if (ClientId.validate(clientId) === false) {
|
|
66
|
-
throw new InvalidClientId(clientId);
|
|
67
|
-
}
|
|
68
|
-
if (this.#clients.has(clientId) === false) {
|
|
69
|
-
throw new ClientNotFound(clientId);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
#hasClientSegmentFile(clientId, segmentFilename) {
|
|
73
|
-
const clientSegmentFiles = this.#clients.get(clientId);
|
|
74
|
-
if (clientSegmentFiles === undefined) {
|
|
75
|
-
throw new ClientNotFound(clientId);
|
|
76
|
-
}
|
|
77
|
-
return clientSegmentFiles.some(clientSegmentFilename => segmentFilename.endsWith(clientSegmentFilename));
|
|
78
|
-
}
|
|
79
|
-
async #getNodeModule(filename, isSegmented) {
|
|
80
|
-
if (isSegmented) {
|
|
81
|
-
filename = filename.replace('.js', '.local.js');
|
|
82
|
-
}
|
|
83
|
-
const file = await this.#loadFile(filename);
|
|
84
|
-
const code = file.content.toString();
|
|
85
|
-
return new File(filename, 'application/javascript', code);
|
|
86
|
-
}
|
|
87
|
-
async #getRemoteModule(filename) {
|
|
88
|
-
const remoteFilename = filename.replace('.js', '.remote.js');
|
|
89
|
-
return this.#loadFile(remoteFilename);
|
|
90
|
-
}
|
|
91
|
-
async #loadFile(filename) {
|
|
92
|
-
return this.#fileManager.load(filename);
|
|
93
|
-
}
|
|
94
|
-
}
|
package/dist/runtime/Node.d.ts
DELETED
package/dist/runtime/Node.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import Version from '../core/Version.js';
|
|
2
|
-
import Node from './Node.js';
|
|
3
|
-
export default class NodeBalancer {
|
|
4
|
-
#private;
|
|
5
|
-
addNode(node: Node): void;
|
|
6
|
-
removeNode(node: Node): void;
|
|
7
|
-
getNextNode(): Node | undefined;
|
|
8
|
-
run(fqn: string, version: Version, args: Map<string, unknown>, headers: Map<string, string>): Promise<unknown>;
|
|
9
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import NoNodeAvailable from './errors/NoNodeAvailable.js';
|
|
2
|
-
export default class NodeBalancer {
|
|
3
|
-
#nodes = [];
|
|
4
|
-
#currentIndex = 0;
|
|
5
|
-
addNode(node) {
|
|
6
|
-
if (this.#nodes.includes(node)) {
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
this.#nodes.push(node);
|
|
10
|
-
}
|
|
11
|
-
removeNode(node) {
|
|
12
|
-
const index = this.#nodes.indexOf(node);
|
|
13
|
-
if (index === -1) {
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
this.#nodes.splice(index, 1);
|
|
17
|
-
}
|
|
18
|
-
getNextNode() {
|
|
19
|
-
if (this.#nodes.length === 0) {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
if (this.#currentIndex >= this.#nodes.length) {
|
|
23
|
-
this.#currentIndex = 0;
|
|
24
|
-
}
|
|
25
|
-
return this.#nodes[this.#currentIndex++];
|
|
26
|
-
}
|
|
27
|
-
async run(fqn, version, args, headers) {
|
|
28
|
-
const node = this.getNextNode();
|
|
29
|
-
if (node === undefined) {
|
|
30
|
-
throw new NoNodeAvailable(fqn);
|
|
31
|
-
}
|
|
32
|
-
return node.run(fqn, version, args, headers);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
const DEFAULT_FREQUENCY = 5000;
|
|
2
|
-
export default class NodeMonitor {
|
|
3
|
-
#gateway;
|
|
4
|
-
#frequency;
|
|
5
|
-
#interval = null;
|
|
6
|
-
constructor(gateway, frequency = DEFAULT_FREQUENCY) {
|
|
7
|
-
this.#gateway = gateway;
|
|
8
|
-
this.#frequency = frequency;
|
|
9
|
-
}
|
|
10
|
-
start() {
|
|
11
|
-
this.#interval = setInterval(async () => await this.#monitor(), this.#frequency);
|
|
12
|
-
}
|
|
13
|
-
stop() {
|
|
14
|
-
if (this.#interval === null) {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
clearInterval(this.#interval);
|
|
18
|
-
}
|
|
19
|
-
async #monitor() {
|
|
20
|
-
const nodes = this.#gateway.nodes;
|
|
21
|
-
const promises = nodes.map(async (node) => await this.#monitorNode(node));
|
|
22
|
-
await Promise.all(promises);
|
|
23
|
-
}
|
|
24
|
-
async #monitorNode(node) {
|
|
25
|
-
const available = await this.#checkNodeAvailable(node);
|
|
26
|
-
if (available === false) {
|
|
27
|
-
this.#gateway.removeNode(node);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
async #checkNodeAvailable(node) {
|
|
31
|
-
try {
|
|
32
|
-
return await node.isHealthy();
|
|
33
|
-
}
|
|
34
|
-
catch (error) {
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import Version from '../core/Version.js';
|
|
2
|
-
import Middleware from './interfaces/Middleware.js';
|
|
3
|
-
import ProcedureRuntime from './ProcedureRuntime.js';
|
|
4
|
-
import NextHandler from './types/NextHandler.js';
|
|
5
|
-
export default class ProcedureRunner implements Middleware {
|
|
6
|
-
#private;
|
|
7
|
-
constructor(runner: ProcedureRuntime);
|
|
8
|
-
handle(fqn: string, version: Version, args: Map<string, unknown>, headers: Map<string, string>, next: NextHandler): Promise<unknown>;
|
|
9
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import Version from '../core/Version.js';
|
|
2
|
-
import Runner from '../core/interfaces/Runner.js';
|
|
3
|
-
import Runtime from './Runtime.js';
|
|
4
|
-
import Middleware from './interfaces/Middleware.js';
|
|
5
|
-
export default abstract class ProcedureRuntime extends Runtime implements Runner {
|
|
6
|
-
#private;
|
|
7
|
-
constructor(url?: string);
|
|
8
|
-
abstract getProcedureNames(): string[];
|
|
9
|
-
abstract hasProcedure(name: string): boolean;
|
|
10
|
-
abstract run(fqn: string, version: Version, args: Map<string, unknown>, headers: Map<string, string>): Promise<unknown>;
|
|
11
|
-
addMiddleware(middleware: Middleware): void;
|
|
12
|
-
getMiddleware(type: Function): Middleware | undefined;
|
|
13
|
-
handle(fqn: string, version: Version, args: Map<string, unknown>, headers: Map<string, string>): Promise<unknown>;
|
|
14
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import Runtime from './Runtime.js';
|
|
2
|
-
import ProcedureRunner from './ProcedureRunner.js';
|
|
3
|
-
export default class ProcedureRuntime extends Runtime {
|
|
4
|
-
#middlewares = [];
|
|
5
|
-
constructor(url) {
|
|
6
|
-
super(url);
|
|
7
|
-
this.addMiddleware(new ProcedureRunner(this));
|
|
8
|
-
}
|
|
9
|
-
addMiddleware(middleware) {
|
|
10
|
-
this.#middlewares.push(middleware);
|
|
11
|
-
}
|
|
12
|
-
getMiddleware(type) {
|
|
13
|
-
return this.#middlewares.find(middleware => middleware instanceof type);
|
|
14
|
-
}
|
|
15
|
-
handle(fqn, version, args, headers) {
|
|
16
|
-
const startHandler = this.#getNextHandler(fqn, version, args, headers, 0);
|
|
17
|
-
return startHandler();
|
|
18
|
-
}
|
|
19
|
-
#getNextHandler(fqn, version, args, headers, index) {
|
|
20
|
-
const indexFromEnd = this.#middlewares.length - index - 1;
|
|
21
|
-
const next = this.#middlewares[indexFromEnd];
|
|
22
|
-
if (next === undefined) {
|
|
23
|
-
return async () => { };
|
|
24
|
-
}
|
|
25
|
-
const nextHandler = this.#getNextHandler(fqn, version, args, headers, index + 1);
|
|
26
|
-
return async () => { return next.handle(fqn, version, args, headers, nextHandler); };
|
|
27
|
-
}
|
|
28
|
-
}
|
package/dist/runtime/Proxy.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import Version from '../core/Version.js';
|
|
2
|
-
import Gateway from './Gateway.js';
|
|
3
|
-
import File from './models/File.js';
|
|
4
|
-
import Node from './Node.js';
|
|
5
|
-
import Repository from './Repository.js';
|
|
6
|
-
import ProcedureRuntime from './ProcedureRuntime.js';
|
|
7
|
-
export default class Proxy extends ProcedureRuntime {
|
|
8
|
-
#private;
|
|
9
|
-
constructor(repository: Repository, runner: Gateway | Node, url?: string);
|
|
10
|
-
get repository(): Repository;
|
|
11
|
-
get runner(): Node | Gateway;
|
|
12
|
-
getProcedureNames(): string[];
|
|
13
|
-
hasProcedure(fqn: string): boolean;
|
|
14
|
-
loadAsset(filename: string): Promise<File>;
|
|
15
|
-
registerClient(segmentFiles: string[]): Promise<string>;
|
|
16
|
-
loadModule(clientId: string, filename: string): Promise<File>;
|
|
17
|
-
run(name: string, version: Version, args: Map<string, unknown>, headers: Map<string, string>): Promise<unknown>;
|
|
18
|
-
}
|
package/dist/runtime/Proxy.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import ProcedureRunner from './ProcedureRunner.js';
|
|
2
|
-
import ProcedureRuntime from './ProcedureRuntime.js';
|
|
3
|
-
export default class Proxy extends ProcedureRuntime {
|
|
4
|
-
#repository;
|
|
5
|
-
#runner;
|
|
6
|
-
constructor(repository, runner, url) {
|
|
7
|
-
super(url);
|
|
8
|
-
this.#repository = repository;
|
|
9
|
-
this.#runner = runner;
|
|
10
|
-
this.addMiddleware(new ProcedureRunner(this));
|
|
11
|
-
}
|
|
12
|
-
get repository() { return this.#repository; }
|
|
13
|
-
get runner() { return this.#runner; }
|
|
14
|
-
getProcedureNames() {
|
|
15
|
-
return this.#runner.getProcedureNames();
|
|
16
|
-
}
|
|
17
|
-
hasProcedure(fqn) {
|
|
18
|
-
const procedureNames = this.getProcedureNames();
|
|
19
|
-
return procedureNames.includes(fqn);
|
|
20
|
-
}
|
|
21
|
-
async loadAsset(filename) {
|
|
22
|
-
return this.#repository.loadAsset(filename);
|
|
23
|
-
}
|
|
24
|
-
async registerClient(segmentFiles) {
|
|
25
|
-
return this.#repository.registerClient(segmentFiles);
|
|
26
|
-
}
|
|
27
|
-
async loadModule(clientId, filename) {
|
|
28
|
-
return this.#repository.loadModule(clientId, filename);
|
|
29
|
-
}
|
|
30
|
-
async run(name, version, args, headers) {
|
|
31
|
-
return this.#runner.run(name, version, args, headers);
|
|
32
|
-
}
|
|
33
|
-
}
|
package/dist/runtime/Remote.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import Module from '../core/types/Module.js';
|
|
2
|
-
import Version from '../core/Version.js';
|
|
3
|
-
import File from './models/File.js';
|
|
4
|
-
import Node from './Node.js';
|
|
5
|
-
export default class Remote {
|
|
6
|
-
#private;
|
|
7
|
-
constructor(url: string, useSerializer: boolean);
|
|
8
|
-
registerClient(segmentFiles: string[]): Promise<string>;
|
|
9
|
-
loadFile(filename: string): Promise<File>;
|
|
10
|
-
importFile(filename: string): Promise<Module>;
|
|
11
|
-
isHealthy(): Promise<boolean>;
|
|
12
|
-
getHealth(): Promise<Map<string, boolean>>;
|
|
13
|
-
addNode(node: Node): Promise<void>;
|
|
14
|
-
run(fqn: string, version: Version, args: Map<string, unknown>, headers: Map<string, string>): Promise<unknown>;
|
|
15
|
-
}
|
package/dist/runtime/Remote.js
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import File from './models/File.js';
|
|
2
|
-
import ValueSerializer from './serialization/ValueSerializer.js';
|
|
3
|
-
import ModuleLoader from './utils/ModuleLoader.js';
|
|
4
|
-
export default class Remote {
|
|
5
|
-
#url;
|
|
6
|
-
#useSerializer;
|
|
7
|
-
constructor(url, useSerializer) {
|
|
8
|
-
this.#url = url;
|
|
9
|
-
this.#useSerializer = useSerializer;
|
|
10
|
-
}
|
|
11
|
-
async registerClient(segmentFiles) {
|
|
12
|
-
const url = `${this.#url}/modules`;
|
|
13
|
-
const options = {
|
|
14
|
-
method: 'POST',
|
|
15
|
-
headers: { 'Content-Type': 'application/json' },
|
|
16
|
-
body: JSON.stringify(segmentFiles)
|
|
17
|
-
};
|
|
18
|
-
const response = await this.#callRemote(url, options, 200);
|
|
19
|
-
const clientId = await response.text();
|
|
20
|
-
return clientId;
|
|
21
|
-
}
|
|
22
|
-
async loadFile(filename) {
|
|
23
|
-
const url = `${this.#url}/${filename}`;
|
|
24
|
-
const options = { method: 'GET' };
|
|
25
|
-
const response = await this.#callRemote(url, options, 200);
|
|
26
|
-
const type = response.headers.get('Content-Type') || 'application/octet-stream';
|
|
27
|
-
const content = await response.text();
|
|
28
|
-
return new File(filename, type, content);
|
|
29
|
-
}
|
|
30
|
-
async importFile(filename) {
|
|
31
|
-
const url = `${this.#url}/${filename}`;
|
|
32
|
-
return ModuleLoader.load(url);
|
|
33
|
-
}
|
|
34
|
-
async isHealthy() {
|
|
35
|
-
const url = `${this.#url}/health/status`;
|
|
36
|
-
const options = { method: 'GET' };
|
|
37
|
-
const response = await this.#callRemote(url, options, 200);
|
|
38
|
-
const healthy = await response.text();
|
|
39
|
-
return Boolean(healthy);
|
|
40
|
-
}
|
|
41
|
-
async getHealth() {
|
|
42
|
-
const url = `${this.#url}/health`;
|
|
43
|
-
const options = { method: 'GET' };
|
|
44
|
-
const response = await this.#callRemote(url, options, 200);
|
|
45
|
-
const health = await response.json();
|
|
46
|
-
return new Map(Object.entries(health));
|
|
47
|
-
}
|
|
48
|
-
async addNode(node) {
|
|
49
|
-
const url = `${this.#url}/nodes`;
|
|
50
|
-
const body = {
|
|
51
|
-
url: node.url,
|
|
52
|
-
procedureNames: node.getProcedureNames()
|
|
53
|
-
};
|
|
54
|
-
const options = {
|
|
55
|
-
method: 'POST',
|
|
56
|
-
headers: { 'Content-Type': 'application/json' },
|
|
57
|
-
body: JSON.stringify(body)
|
|
58
|
-
};
|
|
59
|
-
await this.#callRemote(url, options, 201);
|
|
60
|
-
}
|
|
61
|
-
async run(fqn, version, args, headers) {
|
|
62
|
-
headers.set('content-type', 'application/json');
|
|
63
|
-
const versionString = version.toString();
|
|
64
|
-
const argsObject = Object.fromEntries(args);
|
|
65
|
-
const headersObject = Object.fromEntries(headers);
|
|
66
|
-
const url = `${this.#url}/rpc/${fqn}?version=${versionString}&serialize=true`;
|
|
67
|
-
const options = {
|
|
68
|
-
method: 'POST',
|
|
69
|
-
headers: headersObject,
|
|
70
|
-
body: this.#createRequestBody(argsObject, this.#useSerializer)
|
|
71
|
-
};
|
|
72
|
-
const response = await this.#callRemote(url, options, 200);
|
|
73
|
-
return this.#createResponseResult(response, this.#useSerializer);
|
|
74
|
-
}
|
|
75
|
-
async #callRemote(url, options, expectedStatus) {
|
|
76
|
-
const response = await fetch(url, options);
|
|
77
|
-
if (response.status !== expectedStatus) {
|
|
78
|
-
const error = await this.#createResponseResult(response, true);
|
|
79
|
-
throw error;
|
|
80
|
-
}
|
|
81
|
-
return response;
|
|
82
|
-
}
|
|
83
|
-
#createRequestBody(body, serialize) {
|
|
84
|
-
const data = serialize
|
|
85
|
-
? ValueSerializer.serialize(body)
|
|
86
|
-
: body;
|
|
87
|
-
return JSON.stringify(data);
|
|
88
|
-
}
|
|
89
|
-
async #createResponseResult(response, serialize) {
|
|
90
|
-
const result = await this.#getResponseResult(response);
|
|
91
|
-
return serialize
|
|
92
|
-
? ValueSerializer.deserialize(result)
|
|
93
|
-
: result;
|
|
94
|
-
}
|
|
95
|
-
async #getResponseResult(response) {
|
|
96
|
-
const contentType = response.headers.get('Content-Type');
|
|
97
|
-
if (contentType !== null && contentType.includes('json')) {
|
|
98
|
-
return response.json();
|
|
99
|
-
}
|
|
100
|
-
return response.text();
|
|
101
|
-
}
|
|
102
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import Version from '../core/Version.js';
|
|
2
|
-
import Gateway from './Gateway.js';
|
|
3
|
-
import Node from './Node.js';
|
|
4
|
-
export default class RemoteGateway extends Gateway {
|
|
5
|
-
#private;
|
|
6
|
-
constructor(url: string);
|
|
7
|
-
getProcedureNames(): string[];
|
|
8
|
-
hasProcedure(name: string): boolean;
|
|
9
|
-
addNode(node: Node): Promise<void>;
|
|
10
|
-
run(fqn: string, version: Version, args: Map<string, unknown>, headers: Map<string, string>): Promise<unknown>;
|
|
11
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import NotImplemented from '../core/errors/NotImplemented.js';
|
|
2
|
-
import Gateway from './Gateway.js';
|
|
3
|
-
import Remote from './Remote.js';
|
|
4
|
-
export default class RemoteGateway extends Gateway {
|
|
5
|
-
#remote;
|
|
6
|
-
constructor(url) {
|
|
7
|
-
super(url);
|
|
8
|
-
this.#remote = new Remote(url, true);
|
|
9
|
-
}
|
|
10
|
-
getProcedureNames() {
|
|
11
|
-
throw new NotImplemented();
|
|
12
|
-
}
|
|
13
|
-
hasProcedure(name) {
|
|
14
|
-
throw new NotImplemented();
|
|
15
|
-
}
|
|
16
|
-
async addNode(node) {
|
|
17
|
-
return this.#remote.addNode(node);
|
|
18
|
-
}
|
|
19
|
-
async run(fqn, version, args, headers) {
|
|
20
|
-
return this.#remote.run(fqn, version, args, headers);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import Version from '../core/Version.js';
|
|
2
|
-
import Node from './Node.js';
|
|
3
|
-
export default class RemoteNode extends Node {
|
|
4
|
-
#private;
|
|
5
|
-
constructor(url: string, procedureNames: string[]);
|
|
6
|
-
getProcedureNames(): string[];
|
|
7
|
-
registerProcedures(procedureNames: string[]): void;
|
|
8
|
-
hasProcedure(name: string): boolean;
|
|
9
|
-
isHealthy(): Promise<boolean>;
|
|
10
|
-
getHealth(): Promise<Map<string, boolean>>;
|
|
11
|
-
run(fqn: string, version: Version, args: Map<string, unknown>, headers: Map<string, string>): Promise<unknown>;
|
|
12
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import Node from './Node.js';
|
|
2
|
-
import Remote from './Remote.js';
|
|
3
|
-
export default class RemoteNode extends Node {
|
|
4
|
-
#remote;
|
|
5
|
-
#procedureNames = new Set();
|
|
6
|
-
constructor(url, procedureNames) {
|
|
7
|
-
super(url);
|
|
8
|
-
this.#remote = new Remote(url, false);
|
|
9
|
-
this.registerProcedures(procedureNames);
|
|
10
|
-
}
|
|
11
|
-
getProcedureNames() {
|
|
12
|
-
return [...this.#procedureNames.values()];
|
|
13
|
-
}
|
|
14
|
-
registerProcedures(procedureNames) {
|
|
15
|
-
procedureNames.forEach(procedureName => this.#procedureNames.add(procedureName));
|
|
16
|
-
}
|
|
17
|
-
hasProcedure(name) {
|
|
18
|
-
return this.#procedureNames.has(name);
|
|
19
|
-
}
|
|
20
|
-
async isHealthy() {
|
|
21
|
-
return this.#remote.isHealthy();
|
|
22
|
-
}
|
|
23
|
-
async getHealth() {
|
|
24
|
-
return this.#remote.getHealth();
|
|
25
|
-
}
|
|
26
|
-
async run(fqn, version, args, headers) {
|
|
27
|
-
return this.#remote.run(fqn, version, args, headers);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import Module from '../core/types/Module.js';
|
|
2
|
-
import File from './models/File.js';
|
|
3
|
-
import Repository from './Repository.js';
|
|
4
|
-
import Runtime from './Runtime.js';
|
|
5
|
-
export default class RemoteRepository extends Repository {
|
|
6
|
-
#private;
|
|
7
|
-
constructor(url: string);
|
|
8
|
-
registerClient(segmentFiles: string[]): Promise<string>;
|
|
9
|
-
setRuntime(runtime: Runtime): Promise<void>;
|
|
10
|
-
loadAsset(filename: string): Promise<File>;
|
|
11
|
-
getModuleLocation(clientId: string): Promise<string>;
|
|
12
|
-
loadModule(clientId: string, filename: string): Promise<File>;
|
|
13
|
-
importModule(clientId: string, filename: string): Promise<Module>;
|
|
14
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import InvalidJitarHooks from './errors/InvalidJitarHooks.js';
|
|
2
|
-
import Remote from './Remote.js';
|
|
3
|
-
import Repository from './Repository.js';
|
|
4
|
-
import ModuleLoader from './utils/ModuleLoader.js';
|
|
5
|
-
export default class RemoteRepository extends Repository {
|
|
6
|
-
#remote;
|
|
7
|
-
constructor(url) {
|
|
8
|
-
super(url);
|
|
9
|
-
this.#remote = new Remote(url, true);
|
|
10
|
-
}
|
|
11
|
-
async registerClient(segmentFiles) {
|
|
12
|
-
return this.#remote.registerClient(segmentFiles);
|
|
13
|
-
}
|
|
14
|
-
async setRuntime(runtime) {
|
|
15
|
-
const jitar = await this.#remote.importFile('jitar/hooks.js');
|
|
16
|
-
if (jitar?.setRuntime === undefined || jitar?.setDependencyLoader === undefined) {
|
|
17
|
-
throw new InvalidJitarHooks();
|
|
18
|
-
}
|
|
19
|
-
jitar.setRuntime(runtime);
|
|
20
|
-
jitar.setDependencyLoader(ModuleLoader.import);
|
|
21
|
-
}
|
|
22
|
-
async loadAsset(filename) {
|
|
23
|
-
return this.#remote.loadFile(filename);
|
|
24
|
-
}
|
|
25
|
-
async getModuleLocation(clientId) {
|
|
26
|
-
return `${this.url}/modules/${clientId}`;
|
|
27
|
-
}
|
|
28
|
-
async loadModule(clientId, filename) {
|
|
29
|
-
return this.#remote.loadFile(`modules/${clientId}/${filename}`);
|
|
30
|
-
}
|
|
31
|
-
async importModule(clientId, filename) {
|
|
32
|
-
return this.#remote.importFile(`modules/${clientId}/${filename}`);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import Module from '../core/types/Module.js';
|
|
2
|
-
import File from './models/File.js';
|
|
3
|
-
import Runtime from './Runtime.js';
|
|
4
|
-
export default abstract class Repository extends Runtime {
|
|
5
|
-
abstract registerClient(segmentFiles: string[]): Promise<string>;
|
|
6
|
-
abstract setRuntime(runtime: Runtime): Promise<void>;
|
|
7
|
-
abstract loadAsset(filename: string): Promise<File>;
|
|
8
|
-
abstract getModuleLocation(clientId: string): Promise<string>;
|
|
9
|
-
abstract loadModule(clientId: string, filename: string): Promise<File>;
|
|
10
|
-
abstract importModule(clientId: string, filename: string): Promise<Module>;
|
|
11
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import HealthCheck from './interfaces/HealthCheck.js';
|
|
2
|
-
export default abstract class Runtime {
|
|
3
|
-
#private;
|
|
4
|
-
constructor(url?: string);
|
|
5
|
-
get url(): string | undefined;
|
|
6
|
-
addHealthCheck(name: string, healthCheck: HealthCheck): void;
|
|
7
|
-
isHealthy(): Promise<boolean>;
|
|
8
|
-
getHealth(): Promise<Map<string, boolean>>;
|
|
9
|
-
}
|
package/dist/runtime/Runtime.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export default class Runtime {
|
|
2
|
-
#url;
|
|
3
|
-
#healthChecks = new Map();
|
|
4
|
-
constructor(url) {
|
|
5
|
-
this.#url = url;
|
|
6
|
-
}
|
|
7
|
-
get url() { return this.#url; }
|
|
8
|
-
addHealthCheck(name, healthCheck) {
|
|
9
|
-
this.#healthChecks.set(name, healthCheck);
|
|
10
|
-
}
|
|
11
|
-
async isHealthy() {
|
|
12
|
-
for (const healthCheck of this.#healthChecks.values()) {
|
|
13
|
-
if (await healthCheck.isHealthy() === false) {
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
return true;
|
|
18
|
-
}
|
|
19
|
-
async getHealth() {
|
|
20
|
-
const health = new Map();
|
|
21
|
-
for (const [name, healthCheck] of this.#healthChecks) {
|
|
22
|
-
const healthy = await healthCheck.isHealthy();
|
|
23
|
-
health.set(name, healthy);
|
|
24
|
-
}
|
|
25
|
-
return health;
|
|
26
|
-
}
|
|
27
|
-
}
|