jitar 0.2.2 → 0.3.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.
Files changed (206) hide show
  1. package/CHANGELOG.md +11 -2
  2. package/package.json +7 -7
  3. package/dist/client.d.ts +0 -3
  4. package/dist/client.js +0 -24
  5. package/dist/core/ErrorManager.d.ts +0 -3
  6. package/dist/core/ErrorManager.js +0 -11
  7. package/dist/core/Implementation.d.ts +0 -10
  8. package/dist/core/Implementation.js +0 -39
  9. package/dist/core/Procedure.d.ts +0 -13
  10. package/dist/core/Procedure.js +0 -58
  11. package/dist/core/Segment.d.ts +0 -13
  12. package/dist/core/Segment.js +0 -36
  13. package/dist/core/SegmentBuilder.d.ts +0 -6
  14. package/dist/core/SegmentBuilder.js +0 -32
  15. package/dist/core/Version.d.ts +0 -13
  16. package/dist/core/Version.js +0 -50
  17. package/dist/core/definitions/AccessLevel.d.ts +0 -2
  18. package/dist/core/definitions/AccessLevel.js +0 -2
  19. package/dist/core/errors/ImplementationNotFound.d.ts +0 -3
  20. package/dist/core/errors/ImplementationNotFound.js +0 -6
  21. package/dist/core/errors/InvalidVersionNumber.d.ts +0 -3
  22. package/dist/core/errors/InvalidVersionNumber.js +0 -6
  23. package/dist/core/errors/MissingParameterValue.d.ts +0 -3
  24. package/dist/core/errors/MissingParameterValue.js +0 -6
  25. package/dist/core/errors/NotImplemented.d.ts +0 -3
  26. package/dist/core/errors/NotImplemented.js +0 -6
  27. package/dist/core/errors/ProcedureNotFound.d.ts +0 -3
  28. package/dist/core/errors/ProcedureNotFound.js +0 -6
  29. package/dist/core/errors/UnknownParameter.d.ts +0 -3
  30. package/dist/core/errors/UnknownParameter.js +0 -6
  31. package/dist/core/interfaces/Runner.d.ts +0 -4
  32. package/dist/core/interfaces/Runner.js +0 -1
  33. package/dist/core/reflection/ParameterParser.d.ts +0 -5
  34. package/dist/core/reflection/ParameterParser.js +0 -51
  35. package/dist/core/reflection/ReflectionHelper.d.ts +0 -13
  36. package/dist/core/reflection/ReflectionHelper.js +0 -69
  37. package/dist/core/reflection/models/ReflectionField.d.ts +0 -8
  38. package/dist/core/reflection/models/ReflectionField.js +0 -14
  39. package/dist/core/reflection/models/ReflectionParameter.d.ts +0 -7
  40. package/dist/core/reflection/models/ReflectionParameter.js +0 -11
  41. package/dist/core/types/Component.d.ts +0 -5
  42. package/dist/core/types/Component.js +0 -1
  43. package/dist/core/types/FlexObject.d.ts +0 -4
  44. package/dist/core/types/FlexObject.js +0 -1
  45. package/dist/core/types/Module.d.ts +0 -3
  46. package/dist/core/types/Module.js +0 -1
  47. package/dist/core/types/SegmentImplementation.d.ts +0 -6
  48. package/dist/core/types/SegmentImplementation.js +0 -1
  49. package/dist/core/types/SegmentModule.d.ts +0 -5
  50. package/dist/core/types/SegmentModule.js +0 -1
  51. package/dist/core/types/SegmentProcedure.d.ts +0 -7
  52. package/dist/core/types/SegmentProcedure.js +0 -1
  53. package/dist/core/utils/FqnBuilder.d.ts +0 -3
  54. package/dist/core/utils/FqnBuilder.js +0 -5
  55. package/dist/hooks.d.ts +0 -2
  56. package/dist/hooks.js +0 -2
  57. package/dist/lib.d.ts +0 -31
  58. package/dist/lib.js +0 -27
  59. package/dist/runtime/ClientId.d.ts +0 -4
  60. package/dist/runtime/ClientId.js +0 -11
  61. package/dist/runtime/Gateway.d.ts +0 -10
  62. package/dist/runtime/Gateway.js +0 -3
  63. package/dist/runtime/LocalGateway.d.ts +0 -14
  64. package/dist/runtime/LocalGateway.js +0 -61
  65. package/dist/runtime/LocalNode.d.ts +0 -18
  66. package/dist/runtime/LocalNode.js +0 -75
  67. package/dist/runtime/LocalRepository.d.ts +0 -17
  68. package/dist/runtime/LocalRepository.js +0 -94
  69. package/dist/runtime/Node.d.ts +0 -8
  70. package/dist/runtime/Node.js +0 -3
  71. package/dist/runtime/NodeBalancer.d.ts +0 -10
  72. package/dist/runtime/NodeBalancer.js +0 -34
  73. package/dist/runtime/NodeMonitor.d.ts +0 -7
  74. package/dist/runtime/NodeMonitor.js +0 -38
  75. package/dist/runtime/Proxy.d.ts +0 -19
  76. package/dist/runtime/Proxy.js +0 -31
  77. package/dist/runtime/Remote.d.ts +0 -15
  78. package/dist/runtime/Remote.js +0 -100
  79. package/dist/runtime/RemoteGateway.d.ts +0 -11
  80. package/dist/runtime/RemoteGateway.js +0 -22
  81. package/dist/runtime/RemoteNode.d.ts +0 -12
  82. package/dist/runtime/RemoteNode.js +0 -29
  83. package/dist/runtime/RemoteRepository.d.ts +0 -14
  84. package/dist/runtime/RemoteRepository.js +0 -34
  85. package/dist/runtime/Repository.d.ts +0 -11
  86. package/dist/runtime/Repository.js +0 -3
  87. package/dist/runtime/Runtime.d.ts +0 -9
  88. package/dist/runtime/Runtime.js +0 -27
  89. package/dist/runtime/caching/CacheBuilder.d.ts +0 -6
  90. package/dist/runtime/caching/CacheBuilder.js +0 -249
  91. package/dist/runtime/caching/ImportRewriter.d.ts +0 -4
  92. package/dist/runtime/caching/ImportRewriter.js +0 -49
  93. package/dist/runtime/caching/RemoteBuilder.d.ts +0 -5
  94. package/dist/runtime/caching/RemoteBuilder.js +0 -31
  95. package/dist/runtime/caching/SourceAppender.d.ts +0 -5
  96. package/dist/runtime/caching/SourceAppender.js +0 -30
  97. package/dist/runtime/caching/definitions/Keywords.d.ts +0 -2
  98. package/dist/runtime/caching/definitions/Keywords.js +0 -2
  99. package/dist/runtime/caching/errors/InvalidSegmentFilename.d.ts +0 -3
  100. package/dist/runtime/caching/errors/InvalidSegmentFilename.js +0 -5
  101. package/dist/runtime/caching/errors/MissingModuleExport.d.ts +0 -3
  102. package/dist/runtime/caching/errors/MissingModuleExport.js +0 -5
  103. package/dist/runtime/caching/errors/SegmentFileNotLoaded.d.ts +0 -3
  104. package/dist/runtime/caching/errors/SegmentFileNotLoaded.js +0 -5
  105. package/dist/runtime/caching/errors/SegmentModuleNotLoaded.d.ts +0 -3
  106. package/dist/runtime/caching/errors/SegmentModuleNotLoaded.js +0 -5
  107. package/dist/runtime/caching/models/ApplicationModule.d.ts +0 -9
  108. package/dist/runtime/caching/models/ApplicationModule.js +0 -19
  109. package/dist/runtime/caching/models/Implementation.d.ts +0 -12
  110. package/dist/runtime/caching/models/Implementation.js +0 -27
  111. package/dist/runtime/caching/models/Procedure.d.ts +0 -9
  112. package/dist/runtime/caching/models/Procedure.js +0 -15
  113. package/dist/runtime/caching/models/Segment.d.ts +0 -10
  114. package/dist/runtime/caching/models/Segment.js +0 -16
  115. package/dist/runtime/caching/models/SegmentModule.d.ts +0 -10
  116. package/dist/runtime/caching/models/SegmentModule.js +0 -14
  117. package/dist/runtime/caching/types/SegmentFile.d.ts +0 -5
  118. package/dist/runtime/caching/types/SegmentFile.js +0 -1
  119. package/dist/runtime/caching/types/SegmentImportProperties.d.ts +0 -6
  120. package/dist/runtime/caching/types/SegmentImportProperties.js +0 -1
  121. package/dist/runtime/caching/types/SegmentImports.d.ts +0 -5
  122. package/dist/runtime/caching/types/SegmentImports.js +0 -1
  123. package/dist/runtime/errors/ClientNotFound.d.ts +0 -3
  124. package/dist/runtime/errors/ClientNotFound.js +0 -6
  125. package/dist/runtime/errors/FileNotFound.d.ts +0 -3
  126. package/dist/runtime/errors/FileNotFound.js +0 -6
  127. package/dist/runtime/errors/InvalidClientId.d.ts +0 -3
  128. package/dist/runtime/errors/InvalidClientId.js +0 -6
  129. package/dist/runtime/errors/InvalidJitarHooks.d.ts +0 -3
  130. package/dist/runtime/errors/InvalidJitarHooks.js +0 -6
  131. package/dist/runtime/errors/InvalidSegmentFile.d.ts +0 -3
  132. package/dist/runtime/errors/InvalidSegmentFile.js +0 -6
  133. package/dist/runtime/errors/ModuleNotLoaded.d.ts +0 -3
  134. package/dist/runtime/errors/ModuleNotLoaded.js +0 -6
  135. package/dist/runtime/errors/NoNodeAvailable.d.ts +0 -3
  136. package/dist/runtime/errors/NoNodeAvailable.js +0 -6
  137. package/dist/runtime/errors/RepositoryNotAvaiable.d.ts +0 -3
  138. package/dist/runtime/errors/RepositoryNotAvaiable.js +0 -6
  139. package/dist/runtime/errors/RuntimeNotAvailable.d.ts +0 -3
  140. package/dist/runtime/errors/RuntimeNotAvailable.js +0 -6
  141. package/dist/runtime/errors/SegmentNotFound.d.ts +0 -3
  142. package/dist/runtime/errors/SegmentNotFound.js +0 -6
  143. package/dist/runtime/hooks/dependencies.d.ts +0 -2
  144. package/dist/runtime/hooks/dependencies.js +0 -9
  145. package/dist/runtime/hooks/runtime.d.ts +0 -3
  146. package/dist/runtime/hooks/runtime.js +0 -14
  147. package/dist/runtime/interfaces/FileManager.d.ts +0 -11
  148. package/dist/runtime/interfaces/FileManager.js +0 -1
  149. package/dist/runtime/interfaces/HealthCheck.d.ts +0 -3
  150. package/dist/runtime/interfaces/HealthCheck.js +0 -1
  151. package/dist/runtime/interfaces/ProcedureContainer.d.ts +0 -5
  152. package/dist/runtime/interfaces/ProcedureContainer.js +0 -1
  153. package/dist/runtime/models/File.d.ts +0 -9
  154. package/dist/runtime/models/File.js +0 -14
  155. package/dist/runtime/serialization/ArrayBufferSerializer.d.ts +0 -10
  156. package/dist/runtime/serialization/ArrayBufferSerializer.js +0 -54
  157. package/dist/runtime/serialization/ArraySerializer.d.ts +0 -7
  158. package/dist/runtime/serialization/ArraySerializer.js +0 -15
  159. package/dist/runtime/serialization/ClassSerializer.d.ts +0 -10
  160. package/dist/runtime/serialization/ClassSerializer.js +0 -74
  161. package/dist/runtime/serialization/DateSerializer.d.ts +0 -9
  162. package/dist/runtime/serialization/DateSerializer.js +0 -21
  163. package/dist/runtime/serialization/MapSerializer.d.ts +0 -9
  164. package/dist/runtime/serialization/MapSerializer.js +0 -35
  165. package/dist/runtime/serialization/ObjectSerializer.d.ts +0 -9
  166. package/dist/runtime/serialization/ObjectSerializer.js +0 -21
  167. package/dist/runtime/serialization/SetSerializer.d.ts +0 -9
  168. package/dist/runtime/serialization/SetSerializer.js +0 -23
  169. package/dist/runtime/serialization/ValueSerializer.d.ts +0 -8
  170. package/dist/runtime/serialization/ValueSerializer.js +0 -69
  171. package/dist/runtime/serialization/errors/ClassNotFound.d.ts +0 -3
  172. package/dist/runtime/serialization/errors/ClassNotFound.js +0 -6
  173. package/dist/runtime/serialization/errors/InvalidClass.d.ts +0 -3
  174. package/dist/runtime/serialization/errors/InvalidClass.js +0 -6
  175. package/dist/runtime/serialization/errors/InvalidPropertyType.d.ts +0 -3
  176. package/dist/runtime/serialization/errors/InvalidPropertyType.js +0 -6
  177. package/dist/runtime/serialization/interfaces/Serializer.d.ts +0 -4
  178. package/dist/runtime/serialization/interfaces/Serializer.js +0 -1
  179. package/dist/runtime/serialization/types/SerializableObject.d.ts +0 -3
  180. package/dist/runtime/serialization/types/SerializableObject.js +0 -1
  181. package/dist/runtime/serialization/types/Serialized.d.ts +0 -5
  182. package/dist/runtime/serialization/types/Serialized.js +0 -1
  183. package/dist/runtime/serialization/types/SerializedArrayBuffer.d.ts +0 -6
  184. package/dist/runtime/serialization/types/SerializedArrayBuffer.js +0 -1
  185. package/dist/runtime/serialization/types/SerializedClass.d.ts +0 -8
  186. package/dist/runtime/serialization/types/SerializedClass.js +0 -1
  187. package/dist/runtime/serialization/types/SerializedDate.d.ts +0 -5
  188. package/dist/runtime/serialization/types/SerializedDate.js +0 -1
  189. package/dist/runtime/serialization/types/SerializedMap.d.ts +0 -8
  190. package/dist/runtime/serialization/types/SerializedMap.js +0 -1
  191. package/dist/runtime/serialization/types/SerializedObject.d.ts +0 -4
  192. package/dist/runtime/serialization/types/SerializedObject.js +0 -1
  193. package/dist/runtime/serialization/types/SerializedSet.d.ts +0 -5
  194. package/dist/runtime/serialization/types/SerializedSet.js +0 -1
  195. package/dist/runtime/serialization/types/TypedArray.d.ts +0 -2
  196. package/dist/runtime/serialization/types/TypedArray.js +0 -1
  197. package/dist/runtime/types/JitarHooks.d.ts +0 -6
  198. package/dist/runtime/types/JitarHooks.js +0 -1
  199. package/dist/runtime/types/ModuleImporter.d.ts +0 -3
  200. package/dist/runtime/types/ModuleImporter.js +0 -1
  201. package/dist/runtime/utils/ModuleAnalyser.d.ts +0 -7
  202. package/dist/runtime/utils/ModuleAnalyser.js +0 -34
  203. package/dist/runtime/utils/ModuleLoader.d.ts +0 -8
  204. package/dist/runtime/utils/ModuleLoader.js +0 -30
  205. package/dist/runtime/utils/UrlRewriter.d.ts +0 -4
  206. package/dist/runtime/utils/UrlRewriter.js +0 -36
@@ -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>): Promise<unknown>;
15
- }
@@ -1,100 +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) {
62
- const versionString = version.toString();
63
- const argsObject = Object.fromEntries(args);
64
- const url = `${this.#url}/rpc/${fqn}?version=${versionString}&serialize=true`;
65
- const options = {
66
- method: 'POST',
67
- headers: { 'Content-Type': 'application/json' },
68
- body: this.#createRequestBody(argsObject, this.#useSerializer)
69
- };
70
- const response = await this.#callRemote(url, options, 200);
71
- return this.#createResponseResult(response, this.#useSerializer);
72
- }
73
- async #callRemote(url, options, expectedStatus) {
74
- const response = await fetch(url, options);
75
- if (response.status !== expectedStatus) {
76
- const error = await this.#createResponseResult(response, true);
77
- throw error;
78
- }
79
- return response;
80
- }
81
- #createRequestBody(body, serialize) {
82
- const data = serialize
83
- ? ValueSerializer.serialize(body)
84
- : body;
85
- return JSON.stringify(data);
86
- }
87
- async #createResponseResult(response, serialize) {
88
- const result = await this.#getResponseResult(response);
89
- return serialize
90
- ? ValueSerializer.deserialize(result)
91
- : result;
92
- }
93
- async #getResponseResult(response) {
94
- const contentType = response.headers.get('Content-Type');
95
- if (contentType !== null && contentType.includes('json')) {
96
- return response.json();
97
- }
98
- return response.text();
99
- }
100
- }
@@ -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>): 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) {
20
- return this.#remote.run(fqn, version, args);
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>): 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) {
27
- return this.#remote.run(fqn, version, args);
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,3 +0,0 @@
1
- import Runtime from './Runtime.js';
2
- export default class Repository extends Runtime {
3
- }
@@ -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
- }
@@ -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,6 +0,0 @@
1
- import FileManager from '../interfaces/FileManager.js';
2
- export default class CacheBuilder {
3
- #private;
4
- constructor(sourceManager: FileManager, cacheManager: FileManager);
5
- build(segmentFiles: string[], moduleFiles: string[]): Promise<void>;
6
- }
@@ -1,249 +0,0 @@
1
- import * as AccessLevel from '../../core/definitions/AccessLevel.js';
2
- import Version from '../../core/Version.js';
3
- import ModuleLoader from '../utils/ModuleLoader.js';
4
- import ModuleAnalyser from '../utils/ModuleAnalyser.js';
5
- import SourceAppender from './SourceAppender.js';
6
- import ImportRewriter from './ImportRewriter.js';
7
- import RemoteBuilder from './RemoteBuilder.js';
8
- import ApplicationModule from './models/ApplicationModule.js';
9
- import Procedure from './models/Procedure.js';
10
- import Segment from './models/Segment.js';
11
- import SegmentModule from './models/SegmentModule.js';
12
- import Implementation from './models/Implementation.js';
13
- import SegmentFileNotLoaded from './errors/SegmentFileNotLoaded.js';
14
- import SegmentModuleNotLoaded from './errors/SegmentModuleNotLoaded.js';
15
- import MissingModuleExport from './errors/MissingModuleExport.js';
16
- import InvalidSegmentFilename from './errors/InvalidSegmentFilename.js';
17
- const IGNORED_SOURCE_FILES = ['.min.js'];
18
- const DEFAULT_ACCESS_LEVEL = AccessLevel.PRIVATE;
19
- const DEFAULT_VERSION_NUMBER = Version.DEFAULT.toString();
20
- export default class CacheBuilder {
21
- #sourceManager;
22
- #cacheManager;
23
- constructor(sourceManager, cacheManager) {
24
- this.#sourceManager = sourceManager;
25
- this.#cacheManager = cacheManager;
26
- }
27
- async build(segmentFiles, moduleFiles) {
28
- const applicationFiles = this.#filterApplicationFiles(moduleFiles);
29
- const segments = await this.#createSegments(segmentFiles);
30
- const applicationModules = await this.#createApplicationModules(applicationFiles);
31
- await this.#buildSegmentCache(segments);
32
- await this.#buildApplicationCache(applicationModules);
33
- }
34
- #filterApplicationFiles(fileNames) {
35
- return fileNames.filter(filename => this.#mustIgnoreFile(filename) === false);
36
- }
37
- #mustIgnoreFile(filename) {
38
- return IGNORED_SOURCE_FILES.some((ignored) => filename.endsWith(ignored));
39
- }
40
- async #createSegments(filenames) {
41
- const promises = filenames.map(async (filename) => this.#createSegment(filename));
42
- return Promise.all(promises).then(segments => segments);
43
- }
44
- async #createSegment(filename) {
45
- const definition = await this.#loadSegmentDefinition(filename);
46
- const modules = await this.#createSegmentModules(definition);
47
- const procedures = this.#createSegmentProcedures(modules);
48
- return new Segment(filename, modules, procedures);
49
- }
50
- async #loadSegmentDefinition(filename) {
51
- try {
52
- const content = await this.#sourceManager.getContent(filename);
53
- return JSON.parse(content.toString());
54
- }
55
- catch (error) {
56
- throw new SegmentFileNotLoaded(filename);
57
- }
58
- }
59
- async #createSegmentModules(definition) {
60
- const modules = [];
61
- for (const [moduleFilename, moduleImports] of Object.entries(definition)) {
62
- const absoluteLocation = this.#sourceManager.getAbsoluteLocation(moduleFilename);
63
- const module = await this.#createSegmentModule(absoluteLocation, moduleImports);
64
- modules.push(module);
65
- }
66
- return modules;
67
- }
68
- async #createSegmentModule(absoluteLocation, imports) {
69
- const exports = await this.#loadSegmentModule(absoluteLocation);
70
- const implementations = await this.#createSegmentModuleImplementations(absoluteLocation, exports, imports);
71
- return new SegmentModule(absoluteLocation, exports, implementations);
72
- }
73
- async #loadSegmentModule(absoluteLocation) {
74
- const module = await this.#loadModule(absoluteLocation);
75
- if (module === undefined) {
76
- throw new SegmentModuleNotLoaded(absoluteLocation);
77
- }
78
- return module;
79
- }
80
- async #createSegmentModuleImplementations(absoluteLocation, exports, imports) {
81
- const moduleName = this.#extractModuleName(absoluteLocation);
82
- const implementations = new Map();
83
- for (const [importKey, properties] of Object.entries(imports)) {
84
- const executable = exports[importKey];
85
- if (executable === undefined) {
86
- throw new MissingModuleExport(moduleName, importKey);
87
- }
88
- const procedureName = properties.as ?? executable.name;
89
- const access = properties.access ?? DEFAULT_ACCESS_LEVEL;
90
- const version = properties.version ?? DEFAULT_VERSION_NUMBER;
91
- const implementation = new Implementation(moduleName, procedureName, access, version, executable);
92
- implementations.set(importKey, implementation);
93
- }
94
- return implementations;
95
- }
96
- #createSegmentProcedures(modules) {
97
- const procedures = new Map();
98
- for (const module of modules) {
99
- for (const implementation of module.implementations.values()) {
100
- let procedure = procedures.get(implementation.fqn);
101
- if (procedure === undefined) {
102
- procedure = new Procedure(implementation.module, implementation.name);
103
- procedures.set(implementation.fqn, procedure);
104
- }
105
- procedure.addImplementation(implementation);
106
- }
107
- }
108
- return procedures;
109
- }
110
- #extractModuleName(absoluteLocation) {
111
- const relativeLocation = this.#sourceManager.getRelativeLocation(absoluteLocation);
112
- const moduleParts = relativeLocation.split('/');
113
- moduleParts.pop();
114
- return moduleParts.join('/');
115
- }
116
- async #createApplicationModules(filenames) {
117
- const promises = filenames.map(async (filename) => this.#createApplicationModule(filename));
118
- return Promise.all(promises).then(results => results);
119
- }
120
- async #createApplicationModule(filename) {
121
- const module = await this.#loadModule(filename);
122
- const relativeLocation = this.#sourceManager.getRelativeLocation(filename);
123
- if (module === undefined) {
124
- return new ApplicationModule(relativeLocation, new Map(), new Map());
125
- }
126
- const classes = ModuleAnalyser.filterClasses(module);
127
- const functions = ModuleAnalyser.filterFunctions(module);
128
- return new ApplicationModule(relativeLocation, classes, functions);
129
- }
130
- async #loadModule(filename) {
131
- try {
132
- return await ModuleLoader.load(filename);
133
- }
134
- catch (error) {
135
- return undefined;
136
- }
137
- }
138
- async #buildSegmentCache(segments) {
139
- const promises = segments.map(async (segment) => this.#buildSegmentModuleCache(segment));
140
- return Promise.all(promises);
141
- }
142
- async #buildSegmentModuleCache(segment) {
143
- await this.#buildSegmentCacheForRepository(segment);
144
- await this.#buildSegmentCacheForNode(segment);
145
- }
146
- async #buildSegmentCacheForRepository(segment) {
147
- return this.#buildSegmentDefinitionForRepository(segment);
148
- }
149
- async #buildSegmentDefinitionForRepository(segment) {
150
- const code = this.#createSegmentRepositoryCode(segment);
151
- const filename = this.#createSegmentRepositoryFilename(segment);
152
- return this.#cacheManager.store(filename, code);
153
- }
154
- #createSegmentRepositoryCode(segment) {
155
- const filenames = segment.getFilenames();
156
- const relativeLocations = filenames.map(filename => this.#sourceManager.getRelativeLocation(filename));
157
- return `export const files = [\n\t"${[...relativeLocations].join('",\n\t"')}"\n];`;
158
- }
159
- #createSegmentRepositoryFilename(segment) {
160
- const filename = this.#extractSegmentFilename(segment);
161
- return filename.replace('.json', '.repository.js');
162
- }
163
- async #buildSegmentCacheForNode(segment) {
164
- await this.#buildSegmentDefinitionForNode(segment);
165
- await this.#buildSegmentModulesForNode(segment);
166
- }
167
- async #buildSegmentDefinitionForNode(segment) {
168
- const code = this.#createSegmentNodeCode(segment);
169
- const filename = this.#createSegmentNodeFilename(segment);
170
- return this.#cacheManager.store(filename, code);
171
- }
172
- #createSegmentNodeCode(segment) {
173
- const importCode = this.#createSegmentImportCode(segment);
174
- const modelCode = this.#createSegmentModelCode(segment);
175
- return `${importCode}\n\n${modelCode}`;
176
- }
177
- #createSegmentImportCode(segment) {
178
- const codes = [];
179
- for (const module of segment.modules) {
180
- const relativeLocation = this.#sourceManager.getRelativeLocation(module.filename);
181
- const imports = [];
182
- for (const [importKey, implementation] of module.implementations) {
183
- imports.push(`${importKey} as $${implementation.id}`);
184
- }
185
- codes.push(`import { ${imports.join(',')} } from "./${relativeLocation}";`);
186
- }
187
- return codes.join('\n');
188
- }
189
- #createSegmentModelCode(segment) {
190
- const procedureCode = [];
191
- for (const procedure of segment.procedures.values()) {
192
- const implementationCode = [];
193
- for (const implementation of procedure.implementations) {
194
- implementationCode.push(`{ access: "${implementation.access}", version: "${implementation.version}", executable: $${implementation.id} }`);
195
- }
196
- procedureCode.push(`{ module: "${procedure.module}", name: "${procedure.name}", implementations: [\n\t\t${implementationCode.join(',\n\t\t')}\n\t]}`);
197
- }
198
- return `export const procedures = [\n\t${procedureCode.join(',\n\t')}\n];`;
199
- }
200
- async #buildSegmentModulesForNode(segment) {
201
- for (const module of segment.modules) {
202
- const filename = module.filename;
203
- const absoluteLocation = this.#sourceManager.getAbsoluteLocation(filename);
204
- const relativeLocation = this.#sourceManager.getRelativeLocation(filename);
205
- const file = await this.#sourceManager.load(absoluteLocation);
206
- const code = file.content.toString();
207
- await this.#buildSegmentModuleForLocal(code, relativeLocation);
208
- await this.#buildSegmentModuleForRemote(module, relativeLocation);
209
- }
210
- }
211
- async #buildSegmentModuleForLocal(code, location) {
212
- const importedCode = ImportRewriter.rewrite(code);
213
- const nodeLocation = location.replace('.js', '.local.js');
214
- return this.#cacheManager.store(nodeLocation, importedCode);
215
- }
216
- async #buildSegmentModuleForRemote(module, location) {
217
- const remoteCode = RemoteBuilder.build(module);
218
- const remoteLocation = location.replace('.js', '.remote.js');
219
- return this.#cacheManager.store(remoteLocation, remoteCode);
220
- }
221
- #createSegmentNodeFilename(segment) {
222
- const filename = this.#extractSegmentFilename(segment);
223
- return filename.replace('.json', '.local.js');
224
- }
225
- #extractSegmentFilename(segment) {
226
- const filename = segment.filename.split('/').pop();
227
- if (filename === undefined) {
228
- throw new InvalidSegmentFilename(segment.filename);
229
- }
230
- return filename;
231
- }
232
- async #buildApplicationCache(applicationModules) {
233
- const promises = applicationModules.map(async (module) => this.#buildApplicationModuleCache(module));
234
- return Promise.all(promises);
235
- }
236
- async #buildApplicationModuleCache(module) {
237
- return this.#buildApplicationShareables(module);
238
- }
239
- async #buildApplicationShareables(module) {
240
- if (module.hasClasses() === false) {
241
- return;
242
- }
243
- const filename = module.filename;
244
- const file = await this.#sourceManager.load(filename);
245
- const code = file.content.toString();
246
- const sourcedCode = SourceAppender.append(module, code, filename);
247
- return this.#cacheManager.store(filename, sourcedCode);
248
- }
249
- }
@@ -1,4 +0,0 @@
1
- export default class ImportRewriter {
2
- #private;
3
- static rewrite(content: string): string;
4
- }
@@ -1,49 +0,0 @@
1
- import * as Keywords from './definitions/Keywords.js';
2
- const IMPORT_PATTERN = /import(?:["'\s]*([\w*{}\n, ]+)from\s*)?["'\s]*([@\w/_-]+)["'\s].*/g;
3
- const NON_SYSTEM_INDICATORS = ['.', '/', 'http:', 'https:'];
4
- class Dependency {
5
- items;
6
- from;
7
- constructor(items, from) {
8
- this.items = items;
9
- this.from = from;
10
- }
11
- }
12
- export default class ImportRewriter {
13
- static rewrite(content) {
14
- const replacer = (statement) => this.#replaceImport(statement);
15
- const newContent = content.replaceAll(IMPORT_PATTERN, replacer);
16
- return newContent !== content
17
- ? this.#insertGetDependency(newContent)
18
- : newContent;
19
- }
20
- static #replaceImport(statement) {
21
- const dependency = this.#parseImport(statement);
22
- return this.#isSystemDependency(dependency)
23
- ? this.#rewriteImport(dependency)
24
- : statement;
25
- }
26
- static #parseImport(statement) {
27
- const hasSemicolon = statement.endsWith(';');
28
- const fromIndex = statement.indexOf('from');
29
- const endIndex = statement.length - (hasSemicolon ? 1 : 0);
30
- const items = statement.substring(6, fromIndex).trim();
31
- const from = statement.substring(fromIndex + 4, endIndex).trim().slice(1, -1);
32
- return new Dependency(items, from);
33
- }
34
- static #isSystemDependency(dependency) {
35
- return NON_SYSTEM_INDICATORS.some(indicator => dependency.from.startsWith(indicator)) === false;
36
- }
37
- static #isJitarDependency(dependency) {
38
- return dependency.from === Keywords.JITAR;
39
- }
40
- static #rewriteImport(dependency) {
41
- if (this.#isJitarDependency(dependency)) {
42
- return `import ${dependency.items} from "/jitar/hooks.js";`;
43
- }
44
- return `const ${dependency.items} = await getDependency('${dependency.from}');`;
45
- }
46
- static #insertGetDependency(module) {
47
- return `import { getDependency } from "/jitar/hooks.js";\n${module}`;
48
- }
49
- }
@@ -1,5 +0,0 @@
1
- import SegmentModule from './models/SegmentModule.js';
2
- export default class RemoteBuilder {
3
- #private;
4
- static build(module: SegmentModule): string;
5
- }
@@ -1,31 +0,0 @@
1
- import * as AccessLevel from '../../core/definitions/AccessLevel.js';
2
- import ReflectionHelper from '../../core/reflection/ReflectionHelper.js';
3
- import * as Keywords from './definitions/Keywords.js';
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 = ReflectionHelper.getFunctionParameters(implementation.executable);
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} })`;
29
- return `${functionName} {\n\t${functionBody}\n}\n`;
30
- }
31
- }
@@ -1,5 +0,0 @@
1
- import ApplicationModule from './models/ApplicationModule.js';
2
- export default class SourceAppender {
3
- #private;
4
- static append(module: ApplicationModule, code: string, filename: string): string;
5
- }