jitar 0.3.9 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -94
- package/dist/client.js +1 -24
- package/dist/globals-9eff87d1.js +1 -0
- package/dist/lib.d.ts +340 -35
- package/dist/lib.js +1 -29
- package/dist/server.js +1 -0
- package/package.json +22 -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
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
|
-
}
|
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
import * as AccessLevel from '../../core/definitions/AccessLevel.js';
|
|
2
|
-
import Version from '../../core/Version.js';
|
|
3
|
-
import ModuleAnalyser from '../utils/ModuleAnalyser.js';
|
|
4
|
-
import SourceAppender from './SourceAppender.js';
|
|
5
|
-
import ImportRewriter from './ImportRewriter.js';
|
|
6
|
-
import RemoteBuilder from './RemoteBuilder.js';
|
|
7
|
-
import ApplicationModule from './models/ApplicationModule.js';
|
|
8
|
-
import Procedure from './models/Procedure.js';
|
|
9
|
-
import Segment from './models/Segment.js';
|
|
10
|
-
import SegmentModule from './models/SegmentModule.js';
|
|
11
|
-
import Implementation from './models/Implementation.js';
|
|
12
|
-
import SegmentFileNotLoaded from './errors/SegmentFileNotLoaded.js';
|
|
13
|
-
import SegmentModuleNotLoaded from './errors/SegmentModuleNotLoaded.js';
|
|
14
|
-
import MissingModuleExport from './errors/MissingModuleExport.js';
|
|
15
|
-
import InvalidSegmentFilename from './errors/InvalidSegmentFilename.js';
|
|
16
|
-
import { Reflector } from 'jitar-reflection';
|
|
17
|
-
const IGNORED_SOURCE_FILES = ['.min.js'];
|
|
18
|
-
const DEFAULT_ACCESS_LEVEL = AccessLevel.PRIVATE;
|
|
19
|
-
const DEFAULT_VERSION_NUMBER = Version.DEFAULT.toString();
|
|
20
|
-
const reflector = new Reflector();
|
|
21
|
-
export default class CacheBuilder {
|
|
22
|
-
#sourceManager;
|
|
23
|
-
#cacheManager;
|
|
24
|
-
constructor(sourceManager, cacheManager) {
|
|
25
|
-
this.#sourceManager = sourceManager;
|
|
26
|
-
this.#cacheManager = cacheManager;
|
|
27
|
-
}
|
|
28
|
-
async build(segmentFiles, moduleFiles) {
|
|
29
|
-
const applicationFiles = this.#filterApplicationFiles(moduleFiles);
|
|
30
|
-
const segments = await this.#createSegments(segmentFiles);
|
|
31
|
-
const applicationModules = await this.#createApplicationModules(applicationFiles);
|
|
32
|
-
await this.#buildSegmentCache(segments);
|
|
33
|
-
await this.#buildApplicationCache(applicationModules);
|
|
34
|
-
}
|
|
35
|
-
#filterApplicationFiles(fileNames) {
|
|
36
|
-
return fileNames.filter(filename => this.#mustIgnoreFile(filename) === false);
|
|
37
|
-
}
|
|
38
|
-
#mustIgnoreFile(filename) {
|
|
39
|
-
return IGNORED_SOURCE_FILES.some((ignored) => filename.endsWith(ignored));
|
|
40
|
-
}
|
|
41
|
-
async #createSegments(filenames) {
|
|
42
|
-
const promises = filenames.map(async (filename) => this.#createSegment(filename));
|
|
43
|
-
return Promise.all(promises).then(segments => segments);
|
|
44
|
-
}
|
|
45
|
-
async #createSegment(filename) {
|
|
46
|
-
const definition = await this.#loadSegmentDefinition(filename);
|
|
47
|
-
const modules = await this.#createSegmentModules(definition);
|
|
48
|
-
const procedures = this.#createSegmentProcedures(modules);
|
|
49
|
-
return new Segment(filename, modules, procedures);
|
|
50
|
-
}
|
|
51
|
-
async #loadSegmentDefinition(filename) {
|
|
52
|
-
try {
|
|
53
|
-
const content = await this.#sourceManager.getContent(filename);
|
|
54
|
-
return JSON.parse(content.toString());
|
|
55
|
-
}
|
|
56
|
-
catch (error) {
|
|
57
|
-
throw new SegmentFileNotLoaded(filename);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
async #createSegmentModules(definition) {
|
|
61
|
-
const modules = [];
|
|
62
|
-
for (const [moduleFilename, moduleImports] of Object.entries(definition)) {
|
|
63
|
-
const absoluteLocation = this.#sourceManager.getAbsoluteLocation(moduleFilename);
|
|
64
|
-
const module = await this.#createSegmentModule(absoluteLocation, moduleImports);
|
|
65
|
-
modules.push(module);
|
|
66
|
-
}
|
|
67
|
-
return modules;
|
|
68
|
-
}
|
|
69
|
-
async #createSegmentModule(absoluteLocation, imports) {
|
|
70
|
-
const exports = await this.#loadSegmentModule(absoluteLocation);
|
|
71
|
-
const implementations = await this.#createSegmentModuleImplementations(absoluteLocation, exports, imports);
|
|
72
|
-
return new SegmentModule(absoluteLocation, exports, implementations);
|
|
73
|
-
}
|
|
74
|
-
async #loadSegmentModule(absoluteLocation) {
|
|
75
|
-
const module = await this.#loadModule(absoluteLocation);
|
|
76
|
-
if (module === undefined) {
|
|
77
|
-
throw new SegmentModuleNotLoaded(absoluteLocation);
|
|
78
|
-
}
|
|
79
|
-
return module;
|
|
80
|
-
}
|
|
81
|
-
async #createSegmentModuleImplementations(absoluteLocation, exports, imports) {
|
|
82
|
-
const moduleName = this.#extractModuleName(absoluteLocation);
|
|
83
|
-
const implementations = new Map();
|
|
84
|
-
for (const [importKey, properties] of Object.entries(imports)) {
|
|
85
|
-
const executable = exports.getExported(importKey);
|
|
86
|
-
if (executable === undefined) {
|
|
87
|
-
throw new MissingModuleExport(moduleName, importKey);
|
|
88
|
-
}
|
|
89
|
-
const procedureName = properties.as ?? executable.name;
|
|
90
|
-
const access = properties.access ?? DEFAULT_ACCESS_LEVEL;
|
|
91
|
-
const version = properties.version ?? DEFAULT_VERSION_NUMBER;
|
|
92
|
-
const implementation = new Implementation(moduleName, procedureName, access, version, executable);
|
|
93
|
-
implementations.set(importKey, implementation);
|
|
94
|
-
}
|
|
95
|
-
return implementations;
|
|
96
|
-
}
|
|
97
|
-
#createSegmentProcedures(modules) {
|
|
98
|
-
const procedures = new Map();
|
|
99
|
-
for (const module of modules) {
|
|
100
|
-
for (const implementation of module.implementations.values()) {
|
|
101
|
-
let procedure = procedures.get(implementation.fqn);
|
|
102
|
-
if (procedure === undefined) {
|
|
103
|
-
procedure = new Procedure(implementation.module, implementation.name);
|
|
104
|
-
procedures.set(implementation.fqn, procedure);
|
|
105
|
-
}
|
|
106
|
-
procedure.addImplementation(implementation);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
return procedures;
|
|
110
|
-
}
|
|
111
|
-
#extractModuleName(absoluteLocation) {
|
|
112
|
-
const relativeLocation = this.#sourceManager.getRelativeLocation(absoluteLocation);
|
|
113
|
-
const moduleParts = relativeLocation.split('/');
|
|
114
|
-
moduleParts.pop();
|
|
115
|
-
return moduleParts.join('/');
|
|
116
|
-
}
|
|
117
|
-
async #createApplicationModules(filenames) {
|
|
118
|
-
const promises = filenames.map(async (filename) => this.#createApplicationModule(filename));
|
|
119
|
-
return Promise.all(promises).then(results => results);
|
|
120
|
-
}
|
|
121
|
-
async #createApplicationModule(filename) {
|
|
122
|
-
const module = await this.#loadModule(filename);
|
|
123
|
-
const relativeLocation = this.#sourceManager.getRelativeLocation(filename);
|
|
124
|
-
if (module === undefined) {
|
|
125
|
-
return new ApplicationModule(relativeLocation, new Map(), new Map());
|
|
126
|
-
}
|
|
127
|
-
const classes = ModuleAnalyser.filterClasses(module);
|
|
128
|
-
const functions = ModuleAnalyser.filterFunctions(module);
|
|
129
|
-
return new ApplicationModule(relativeLocation, classes, functions);
|
|
130
|
-
}
|
|
131
|
-
async #loadModule(filename) {
|
|
132
|
-
const code = await this.#sourceManager.getContent(filename);
|
|
133
|
-
return reflector.parse(code.toString());
|
|
134
|
-
}
|
|
135
|
-
async #buildSegmentCache(segments) {
|
|
136
|
-
const promises = segments.map(async (segment) => this.#buildSegmentModuleCache(segment));
|
|
137
|
-
return Promise.all(promises);
|
|
138
|
-
}
|
|
139
|
-
async #buildSegmentModuleCache(segment) {
|
|
140
|
-
await this.#buildSegmentCacheForRepository(segment);
|
|
141
|
-
await this.#buildSegmentCacheForNode(segment);
|
|
142
|
-
}
|
|
143
|
-
async #buildSegmentCacheForRepository(segment) {
|
|
144
|
-
return this.#buildSegmentDefinitionForRepository(segment);
|
|
145
|
-
}
|
|
146
|
-
async #buildSegmentDefinitionForRepository(segment) {
|
|
147
|
-
const code = this.#createSegmentRepositoryCode(segment);
|
|
148
|
-
const filename = this.#createSegmentRepositoryFilename(segment);
|
|
149
|
-
return this.#cacheManager.store(filename, code);
|
|
150
|
-
}
|
|
151
|
-
#createSegmentRepositoryCode(segment) {
|
|
152
|
-
const filenames = segment.getFilenames();
|
|
153
|
-
const relativeLocations = filenames.map(filename => this.#sourceManager.getRelativeLocation(filename));
|
|
154
|
-
return `export const files = [\n\t"${[...relativeLocations].join('",\n\t"')}"\n];`;
|
|
155
|
-
}
|
|
156
|
-
#createSegmentRepositoryFilename(segment) {
|
|
157
|
-
const filename = this.#extractSegmentFilename(segment);
|
|
158
|
-
return filename.replace('.json', '.repository.js');
|
|
159
|
-
}
|
|
160
|
-
async #buildSegmentCacheForNode(segment) {
|
|
161
|
-
await this.#buildSegmentDefinitionForNode(segment);
|
|
162
|
-
await this.#buildSegmentModulesForNode(segment);
|
|
163
|
-
}
|
|
164
|
-
async #buildSegmentDefinitionForNode(segment) {
|
|
165
|
-
const code = this.#createSegmentNodeCode(segment);
|
|
166
|
-
const filename = this.#createSegmentNodeFilename(segment);
|
|
167
|
-
return this.#cacheManager.store(filename, code);
|
|
168
|
-
}
|
|
169
|
-
#createSegmentNodeCode(segment) {
|
|
170
|
-
const importCode = this.#createSegmentImportCode(segment);
|
|
171
|
-
const modelCode = this.#createSegmentModelCode(segment);
|
|
172
|
-
return `${importCode}\n\n${modelCode}`;
|
|
173
|
-
}
|
|
174
|
-
#createSegmentImportCode(segment) {
|
|
175
|
-
const codes = [];
|
|
176
|
-
for (const module of segment.modules) {
|
|
177
|
-
const relativeLocation = this.#sourceManager.getRelativeLocation(module.filename);
|
|
178
|
-
const imports = [];
|
|
179
|
-
for (const [importKey, implementation] of module.implementations) {
|
|
180
|
-
imports.push(`${importKey} as $${implementation.id}`);
|
|
181
|
-
}
|
|
182
|
-
codes.push(`import { ${imports.join(',')} } from "./${relativeLocation}";`);
|
|
183
|
-
}
|
|
184
|
-
return codes.join('\n');
|
|
185
|
-
}
|
|
186
|
-
#createSegmentModelCode(segment) {
|
|
187
|
-
const procedureCode = [];
|
|
188
|
-
for (const procedure of segment.procedures.values()) {
|
|
189
|
-
const implementationCode = [];
|
|
190
|
-
for (const implementation of procedure.implementations) {
|
|
191
|
-
implementationCode.push(`{ access: "${implementation.access}", version: "${implementation.version}", executable: $${implementation.id} }`);
|
|
192
|
-
}
|
|
193
|
-
procedureCode.push(`{ module: "${procedure.module}", name: "${procedure.name}", implementations: [\n\t\t${implementationCode.join(',\n\t\t')}\n\t]}`);
|
|
194
|
-
}
|
|
195
|
-
return `export const procedures = [\n\t${procedureCode.join(',\n\t')}\n];`;
|
|
196
|
-
}
|
|
197
|
-
async #buildSegmentModulesForNode(segment) {
|
|
198
|
-
for (const module of segment.modules) {
|
|
199
|
-
const filename = module.filename;
|
|
200
|
-
const absoluteLocation = this.#sourceManager.getAbsoluteLocation(filename);
|
|
201
|
-
const relativeLocation = this.#sourceManager.getRelativeLocation(filename);
|
|
202
|
-
const file = await this.#sourceManager.load(absoluteLocation);
|
|
203
|
-
const code = file.content.toString();
|
|
204
|
-
await this.#buildSegmentModuleForLocal(code, relativeLocation);
|
|
205
|
-
await this.#buildSegmentModuleForRemote(module, relativeLocation);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
async #buildSegmentModuleForLocal(code, location) {
|
|
209
|
-
const importedCode = ImportRewriter.rewrite(code);
|
|
210
|
-
const nodeLocation = location.replace('.js', '.local.js');
|
|
211
|
-
return this.#cacheManager.store(nodeLocation, importedCode);
|
|
212
|
-
}
|
|
213
|
-
async #buildSegmentModuleForRemote(module, location) {
|
|
214
|
-
const remoteCode = RemoteBuilder.build(module);
|
|
215
|
-
const remoteLocation = location.replace('.js', '.remote.js');
|
|
216
|
-
return this.#cacheManager.store(remoteLocation, remoteCode);
|
|
217
|
-
}
|
|
218
|
-
#createSegmentNodeFilename(segment) {
|
|
219
|
-
const filename = this.#extractSegmentFilename(segment);
|
|
220
|
-
return filename.replace('.json', '.local.js');
|
|
221
|
-
}
|
|
222
|
-
#extractSegmentFilename(segment) {
|
|
223
|
-
const filename = segment.filename.split('/').pop();
|
|
224
|
-
if (filename === undefined) {
|
|
225
|
-
throw new InvalidSegmentFilename(segment.filename);
|
|
226
|
-
}
|
|
227
|
-
return filename;
|
|
228
|
-
}
|
|
229
|
-
async #buildApplicationCache(applicationModules) {
|
|
230
|
-
const promises = applicationModules.map(async (module) => this.#buildApplicationModuleCache(module));
|
|
231
|
-
return Promise.all(promises);
|
|
232
|
-
}
|
|
233
|
-
async #buildApplicationModuleCache(module) {
|
|
234
|
-
return this.#buildApplicationShareables(module);
|
|
235
|
-
}
|
|
236
|
-
async #buildApplicationShareables(module) {
|
|
237
|
-
if (module.hasClasses() === false) {
|
|
238
|
-
return;
|
|
239
|
-
}
|
|
240
|
-
const filename = module.filename;
|
|
241
|
-
const file = await this.#sourceManager.load(filename);
|
|
242
|
-
const code = file.content.toString();
|
|
243
|
-
const sourcedCode = SourceAppender.append(module, code, filename);
|
|
244
|
-
return this.#cacheManager.store(filename, sourcedCode);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { Reflector } from 'jitar-reflection';
|
|
2
|
-
import * as Keywords from './definitions/Keywords.js';
|
|
3
|
-
const IMPORT_PATTERN = /import(?:["'\s]*([\w*{}\n, ]+)from\s*)?["'\s]*([@\w/_-]+)["'\s].*/g;
|
|
4
|
-
const NON_SYSTEM_INDICATORS = ['.', '/', 'http:', 'https:'];
|
|
5
|
-
const reflector = new Reflector();
|
|
6
|
-
export default class ImportRewriter {
|
|
7
|
-
static rewrite(content) {
|
|
8
|
-
const replacer = (statement) => this.#replaceImport(statement);
|
|
9
|
-
const newContent = content.replaceAll(IMPORT_PATTERN, replacer);
|
|
10
|
-
return newContent !== content
|
|
11
|
-
? this.#insertGetDependency(newContent)
|
|
12
|
-
: newContent;
|
|
13
|
-
}
|
|
14
|
-
static #replaceImport(statement) {
|
|
15
|
-
const dependency = reflector.parseImport(statement);
|
|
16
|
-
return this.#isSystemDependency(dependency)
|
|
17
|
-
? this.#rewriteImport(dependency)
|
|
18
|
-
: statement;
|
|
19
|
-
}
|
|
20
|
-
static #isSystemDependency(dependency) {
|
|
21
|
-
return NON_SYSTEM_INDICATORS.some(indicator => dependency.from.startsWith(indicator, 1)) === false;
|
|
22
|
-
}
|
|
23
|
-
static #isJitarDependency(dependency) {
|
|
24
|
-
return dependency.from.includes(Keywords.JITAR);
|
|
25
|
-
}
|
|
26
|
-
static #rewriteImport(dependency) {
|
|
27
|
-
if (dependency.members.length === 0) {
|
|
28
|
-
return `await getDependency(${dependency.from});`;
|
|
29
|
-
}
|
|
30
|
-
const members = this.#rewriteImportMembers(dependency);
|
|
31
|
-
if (this.#isJitarDependency(dependency)) {
|
|
32
|
-
return `import ${members} from "/jitar/hooks.js";`;
|
|
33
|
-
}
|
|
34
|
-
return `const ${members} = await getDependency(${dependency.from});`;
|
|
35
|
-
}
|
|
36
|
-
static #rewriteImportMembers(dependency) {
|
|
37
|
-
if (this.#mustUseAs(dependency)) {
|
|
38
|
-
return dependency.members[0].as;
|
|
39
|
-
}
|
|
40
|
-
const members = dependency.members.map(member => member.name !== member.as ? `${member.name}: ${member.as}` : member.name);
|
|
41
|
-
return `{ ${members.join(', ')} }`;
|
|
42
|
-
}
|
|
43
|
-
static #mustUseAs(dependency) {
|
|
44
|
-
return this.#doesImportAll(dependency)
|
|
45
|
-
|| this.#doesImportDefault(dependency);
|
|
46
|
-
}
|
|
47
|
-
static #doesImportAll(dependency) {
|
|
48
|
-
return dependency.members.length === 1
|
|
49
|
-
&& dependency.members[0].name === '*';
|
|
50
|
-
}
|
|
51
|
-
static #doesImportDefault(dependency) {
|
|
52
|
-
return dependency.members.length === 1
|
|
53
|
-
&& dependency.members[0].name === 'default';
|
|
54
|
-
}
|
|
55
|
-
static #insertGetDependency(module) {
|
|
56
|
-
return `import { getDependency } from "/jitar/hooks.js";\n${module}`;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import * as AccessLevel from '../../core/definitions/AccessLevel.js';
|
|
2
|
-
import * as Keywords from './definitions/Keywords.js';
|
|
3
|
-
import { ReflectionField } from 'jitar-reflection';
|
|
4
|
-
export default class RemoteBuilder {
|
|
5
|
-
static build(module) {
|
|
6
|
-
let code = this.#createRemoteImports();
|
|
7
|
-
for (const [importKey, implementation] of module.implementations) {
|
|
8
|
-
if (implementation.access !== AccessLevel.PUBLIC) {
|
|
9
|
-
continue;
|
|
10
|
-
}
|
|
11
|
-
const asDefault = importKey === Keywords.DEFAULT;
|
|
12
|
-
code += this.#createRemoteCode(implementation, asDefault);
|
|
13
|
-
}
|
|
14
|
-
return code;
|
|
15
|
-
}
|
|
16
|
-
static #createRemoteImports() {
|
|
17
|
-
return `import { runProcedure } from "/jitar/hooks.js";\n`;
|
|
18
|
-
}
|
|
19
|
-
static #createRemoteCode(implementation, asDefault) {
|
|
20
|
-
const parameters = implementation.executable.parameters.filter(parameter => parameter instanceof ReflectionField);
|
|
21
|
-
const parameterNames = parameters.map(parameter => parameter.name);
|
|
22
|
-
const procedureName = implementation.executable.name;
|
|
23
|
-
const procedureFqn = implementation.fqn;
|
|
24
|
-
const procedureVersion = implementation.version;
|
|
25
|
-
const procedueParameters = parameterNames.join(', ');
|
|
26
|
-
const procedureArguments = parameterNames.map(name => `'${name}': ${name}`).join(', ');
|
|
27
|
-
const functionName = `\nexport ${asDefault ? `${Keywords.DEFAULT} ` : ''}async function ${procedureName}(${procedueParameters})`;
|
|
28
|
-
const functionBody = `return runProcedure('${procedureFqn}', '${procedureVersion}', { ${procedureArguments} }, this)`;
|
|
29
|
-
return `${functionName} {\n\t${functionBody}\n}\n`;
|
|
30
|
-
}
|
|
31
|
-
}
|