jitar 0.3.8 → 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.
Files changed (231) hide show
  1. package/CHANGELOG.md +1 -84
  2. package/dist/client.js +1 -24
  3. package/dist/globals-d516de70.js +1 -0
  4. package/dist/lib.d.ts +309 -35
  5. package/dist/lib.js +1 -29
  6. package/dist/server.js +1 -0
  7. package/package.json +19 -12
  8. package/LICENCE +0 -23
  9. package/dist/client.d.ts +0 -3
  10. package/dist/core/Context.d.ts +0 -5
  11. package/dist/core/Context.js +0 -7
  12. package/dist/core/ErrorManager.d.ts +0 -3
  13. package/dist/core/ErrorManager.js +0 -11
  14. package/dist/core/Implementation.d.ts +0 -10
  15. package/dist/core/Implementation.js +0 -44
  16. package/dist/core/Procedure.d.ts +0 -13
  17. package/dist/core/Procedure.js +0 -58
  18. package/dist/core/Segment.d.ts +0 -13
  19. package/dist/core/Segment.js +0 -36
  20. package/dist/core/SegmentBuilder.d.ts +0 -6
  21. package/dist/core/SegmentBuilder.js +0 -32
  22. package/dist/core/Version.d.ts +0 -13
  23. package/dist/core/Version.js +0 -50
  24. package/dist/core/definitions/AccessLevel.d.ts +0 -2
  25. package/dist/core/definitions/AccessLevel.js +0 -2
  26. package/dist/core/errors/BadRequest.d.ts +0 -3
  27. package/dist/core/errors/BadRequest.js +0 -6
  28. package/dist/core/errors/Forbidden.d.ts +0 -3
  29. package/dist/core/errors/Forbidden.js +0 -6
  30. package/dist/core/errors/ImplementationNotFound.d.ts +0 -4
  31. package/dist/core/errors/ImplementationNotFound.js +0 -7
  32. package/dist/core/errors/InvalidVersionNumber.d.ts +0 -4
  33. package/dist/core/errors/InvalidVersionNumber.js +0 -7
  34. package/dist/core/errors/MissingParameterValue.d.ts +0 -4
  35. package/dist/core/errors/MissingParameterValue.js +0 -7
  36. package/dist/core/errors/NotFound.d.ts +0 -3
  37. package/dist/core/errors/NotFound.js +0 -6
  38. package/dist/core/errors/NotImplemented.d.ts +0 -3
  39. package/dist/core/errors/NotImplemented.js +0 -6
  40. package/dist/core/errors/PaymentRequired.d.ts +0 -3
  41. package/dist/core/errors/PaymentRequired.js +0 -6
  42. package/dist/core/errors/ProcedureNotFound.d.ts +0 -4
  43. package/dist/core/errors/ProcedureNotFound.js +0 -7
  44. package/dist/core/errors/Teapot.d.ts +0 -3
  45. package/dist/core/errors/Teapot.js +0 -6
  46. package/dist/core/errors/Unauthorized.d.ts +0 -3
  47. package/dist/core/errors/Unauthorized.js +0 -6
  48. package/dist/core/errors/UnknownParameter.d.ts +0 -4
  49. package/dist/core/errors/UnknownParameter.js +0 -7
  50. package/dist/core/interfaces/Runner.d.ts +0 -4
  51. package/dist/core/interfaces/Runner.js +0 -1
  52. package/dist/core/reflection/ParameterParser.d.ts +0 -5
  53. package/dist/core/reflection/ParameterParser.js +0 -51
  54. package/dist/core/reflection/ReflectionHelper.d.ts +0 -13
  55. package/dist/core/reflection/ReflectionHelper.js +0 -69
  56. package/dist/core/reflection/models/ReflectionField.d.ts +0 -8
  57. package/dist/core/reflection/models/ReflectionField.js +0 -14
  58. package/dist/core/reflection/models/ReflectionParameter.d.ts +0 -7
  59. package/dist/core/reflection/models/ReflectionParameter.js +0 -11
  60. package/dist/core/types/Component.d.ts +0 -5
  61. package/dist/core/types/Component.js +0 -1
  62. package/dist/core/types/FlexObject.d.ts +0 -4
  63. package/dist/core/types/FlexObject.js +0 -1
  64. package/dist/core/types/Module.d.ts +0 -3
  65. package/dist/core/types/Module.js +0 -1
  66. package/dist/core/types/SegmentImplementation.d.ts +0 -6
  67. package/dist/core/types/SegmentImplementation.js +0 -1
  68. package/dist/core/types/SegmentModule.d.ts +0 -5
  69. package/dist/core/types/SegmentModule.js +0 -1
  70. package/dist/core/types/SegmentProcedure.d.ts +0 -7
  71. package/dist/core/types/SegmentProcedure.js +0 -1
  72. package/dist/core/utils/FqnBuilder.d.ts +0 -3
  73. package/dist/core/utils/FqnBuilder.js +0 -5
  74. package/dist/hooks.d.ts +0 -2
  75. package/dist/hooks.js +0 -2
  76. package/dist/runtime/ClientId.d.ts +0 -4
  77. package/dist/runtime/ClientId.js +0 -11
  78. package/dist/runtime/Gateway.d.ts +0 -5
  79. package/dist/runtime/Gateway.js +0 -3
  80. package/dist/runtime/LocalGateway.d.ts +0 -14
  81. package/dist/runtime/LocalGateway.js +0 -61
  82. package/dist/runtime/LocalNode.d.ts +0 -18
  83. package/dist/runtime/LocalNode.js +0 -75
  84. package/dist/runtime/LocalRepository.d.ts +0 -17
  85. package/dist/runtime/LocalRepository.js +0 -94
  86. package/dist/runtime/Node.d.ts +0 -3
  87. package/dist/runtime/Node.js +0 -3
  88. package/dist/runtime/NodeBalancer.d.ts +0 -9
  89. package/dist/runtime/NodeBalancer.js +0 -34
  90. package/dist/runtime/NodeMonitor.d.ts +0 -7
  91. package/dist/runtime/NodeMonitor.js +0 -38
  92. package/dist/runtime/ProcedureRunner.d.ts +0 -9
  93. package/dist/runtime/ProcedureRunner.js +0 -11
  94. package/dist/runtime/ProcedureRuntime.d.ts +0 -13
  95. package/dist/runtime/ProcedureRuntime.js +0 -25
  96. package/dist/runtime/Proxy.d.ts +0 -18
  97. package/dist/runtime/Proxy.js +0 -33
  98. package/dist/runtime/Remote.d.ts +0 -15
  99. package/dist/runtime/Remote.js +0 -102
  100. package/dist/runtime/RemoteGateway.d.ts +0 -11
  101. package/dist/runtime/RemoteGateway.js +0 -22
  102. package/dist/runtime/RemoteNode.d.ts +0 -12
  103. package/dist/runtime/RemoteNode.js +0 -29
  104. package/dist/runtime/RemoteRepository.d.ts +0 -14
  105. package/dist/runtime/RemoteRepository.js +0 -34
  106. package/dist/runtime/Repository.d.ts +0 -11
  107. package/dist/runtime/Repository.js +0 -3
  108. package/dist/runtime/Runtime.d.ts +0 -9
  109. package/dist/runtime/Runtime.js +0 -27
  110. package/dist/runtime/caching/CacheBuilder.d.ts +0 -6
  111. package/dist/runtime/caching/CacheBuilder.js +0 -246
  112. package/dist/runtime/caching/ImportRewriter.d.ts +0 -4
  113. package/dist/runtime/caching/ImportRewriter.js +0 -58
  114. package/dist/runtime/caching/RemoteBuilder.d.ts +0 -5
  115. package/dist/runtime/caching/RemoteBuilder.js +0 -31
  116. package/dist/runtime/caching/SourceAppender.d.ts +0 -5
  117. package/dist/runtime/caching/SourceAppender.js +0 -30
  118. package/dist/runtime/caching/definitions/Keywords.d.ts +0 -2
  119. package/dist/runtime/caching/definitions/Keywords.js +0 -2
  120. package/dist/runtime/caching/errors/InvalidSegmentFilename.d.ts +0 -3
  121. package/dist/runtime/caching/errors/InvalidSegmentFilename.js +0 -5
  122. package/dist/runtime/caching/errors/MissingModuleExport.d.ts +0 -3
  123. package/dist/runtime/caching/errors/MissingModuleExport.js +0 -5
  124. package/dist/runtime/caching/errors/SegmentFileNotLoaded.d.ts +0 -3
  125. package/dist/runtime/caching/errors/SegmentFileNotLoaded.js +0 -5
  126. package/dist/runtime/caching/errors/SegmentModuleNotLoaded.d.ts +0 -3
  127. package/dist/runtime/caching/errors/SegmentModuleNotLoaded.js +0 -5
  128. package/dist/runtime/caching/models/ApplicationModule.d.ts +0 -10
  129. package/dist/runtime/caching/models/ApplicationModule.js +0 -19
  130. package/dist/runtime/caching/models/Implementation.d.ts +0 -12
  131. package/dist/runtime/caching/models/Implementation.js +0 -27
  132. package/dist/runtime/caching/models/Procedure.d.ts +0 -9
  133. package/dist/runtime/caching/models/Procedure.js +0 -15
  134. package/dist/runtime/caching/models/Segment.d.ts +0 -10
  135. package/dist/runtime/caching/models/Segment.js +0 -16
  136. package/dist/runtime/caching/models/SegmentModule.d.ts +0 -10
  137. package/dist/runtime/caching/models/SegmentModule.js +0 -14
  138. package/dist/runtime/caching/types/SegmentFile.d.ts +0 -5
  139. package/dist/runtime/caching/types/SegmentFile.js +0 -1
  140. package/dist/runtime/caching/types/SegmentImportProperties.d.ts +0 -6
  141. package/dist/runtime/caching/types/SegmentImportProperties.js +0 -1
  142. package/dist/runtime/caching/types/SegmentImports.d.ts +0 -5
  143. package/dist/runtime/caching/types/SegmentImports.js +0 -1
  144. package/dist/runtime/errors/ClientNotFound.d.ts +0 -3
  145. package/dist/runtime/errors/ClientNotFound.js +0 -6
  146. package/dist/runtime/errors/FileNotFound.d.ts +0 -3
  147. package/dist/runtime/errors/FileNotFound.js +0 -6
  148. package/dist/runtime/errors/InvalidClientId.d.ts +0 -3
  149. package/dist/runtime/errors/InvalidClientId.js +0 -6
  150. package/dist/runtime/errors/InvalidJitarHooks.d.ts +0 -3
  151. package/dist/runtime/errors/InvalidJitarHooks.js +0 -6
  152. package/dist/runtime/errors/InvalidSegmentFile.d.ts +0 -3
  153. package/dist/runtime/errors/InvalidSegmentFile.js +0 -6
  154. package/dist/runtime/errors/ModuleNotLoaded.d.ts +0 -3
  155. package/dist/runtime/errors/ModuleNotLoaded.js +0 -6
  156. package/dist/runtime/errors/NoNodeAvailable.d.ts +0 -3
  157. package/dist/runtime/errors/NoNodeAvailable.js +0 -6
  158. package/dist/runtime/errors/RepositoryNotAvaiable.d.ts +0 -3
  159. package/dist/runtime/errors/RepositoryNotAvaiable.js +0 -6
  160. package/dist/runtime/errors/RuntimeNotAvailable.d.ts +0 -3
  161. package/dist/runtime/errors/RuntimeNotAvailable.js +0 -6
  162. package/dist/runtime/errors/SegmentNotFound.d.ts +0 -3
  163. package/dist/runtime/errors/SegmentNotFound.js +0 -6
  164. package/dist/runtime/hooks/dependencies.d.ts +0 -2
  165. package/dist/runtime/hooks/dependencies.js +0 -9
  166. package/dist/runtime/hooks/runtime.d.ts +0 -3
  167. package/dist/runtime/hooks/runtime.js +0 -16
  168. package/dist/runtime/interfaces/FileManager.d.ts +0 -11
  169. package/dist/runtime/interfaces/FileManager.js +0 -1
  170. package/dist/runtime/interfaces/HealthCheck.d.ts +0 -3
  171. package/dist/runtime/interfaces/HealthCheck.js +0 -1
  172. package/dist/runtime/interfaces/Middleware.d.ts +0 -5
  173. package/dist/runtime/interfaces/Middleware.js +0 -1
  174. package/dist/runtime/middleware/CorsMiddleware.d.ts +0 -8
  175. package/dist/runtime/middleware/CorsMiddleware.js +0 -19
  176. package/dist/runtime/models/File.d.ts +0 -9
  177. package/dist/runtime/models/File.js +0 -14
  178. package/dist/runtime/serialization/ArrayBufferSerializer.d.ts +0 -10
  179. package/dist/runtime/serialization/ArrayBufferSerializer.js +0 -54
  180. package/dist/runtime/serialization/ArraySerializer.d.ts +0 -7
  181. package/dist/runtime/serialization/ArraySerializer.js +0 -15
  182. package/dist/runtime/serialization/ClassSerializer.d.ts +0 -10
  183. package/dist/runtime/serialization/ClassSerializer.js +0 -74
  184. package/dist/runtime/serialization/DateSerializer.d.ts +0 -9
  185. package/dist/runtime/serialization/DateSerializer.js +0 -21
  186. package/dist/runtime/serialization/MapSerializer.d.ts +0 -9
  187. package/dist/runtime/serialization/MapSerializer.js +0 -35
  188. package/dist/runtime/serialization/ObjectSerializer.d.ts +0 -9
  189. package/dist/runtime/serialization/ObjectSerializer.js +0 -21
  190. package/dist/runtime/serialization/SetSerializer.d.ts +0 -9
  191. package/dist/runtime/serialization/SetSerializer.js +0 -23
  192. package/dist/runtime/serialization/ValueSerializer.d.ts +0 -8
  193. package/dist/runtime/serialization/ValueSerializer.js +0 -69
  194. package/dist/runtime/serialization/errors/ClassNotFound.d.ts +0 -3
  195. package/dist/runtime/serialization/errors/ClassNotFound.js +0 -6
  196. package/dist/runtime/serialization/errors/InvalidClass.d.ts +0 -3
  197. package/dist/runtime/serialization/errors/InvalidClass.js +0 -6
  198. package/dist/runtime/serialization/errors/InvalidPropertyType.d.ts +0 -4
  199. package/dist/runtime/serialization/errors/InvalidPropertyType.js +0 -7
  200. package/dist/runtime/serialization/interfaces/Serializer.d.ts +0 -4
  201. package/dist/runtime/serialization/interfaces/Serializer.js +0 -1
  202. package/dist/runtime/serialization/types/SerializableObject.d.ts +0 -3
  203. package/dist/runtime/serialization/types/SerializableObject.js +0 -1
  204. package/dist/runtime/serialization/types/Serialized.d.ts +0 -5
  205. package/dist/runtime/serialization/types/Serialized.js +0 -1
  206. package/dist/runtime/serialization/types/SerializedArrayBuffer.d.ts +0 -6
  207. package/dist/runtime/serialization/types/SerializedArrayBuffer.js +0 -1
  208. package/dist/runtime/serialization/types/SerializedClass.d.ts +0 -8
  209. package/dist/runtime/serialization/types/SerializedClass.js +0 -1
  210. package/dist/runtime/serialization/types/SerializedDate.d.ts +0 -5
  211. package/dist/runtime/serialization/types/SerializedDate.js +0 -1
  212. package/dist/runtime/serialization/types/SerializedMap.d.ts +0 -8
  213. package/dist/runtime/serialization/types/SerializedMap.js +0 -1
  214. package/dist/runtime/serialization/types/SerializedObject.d.ts +0 -4
  215. package/dist/runtime/serialization/types/SerializedObject.js +0 -1
  216. package/dist/runtime/serialization/types/SerializedSet.d.ts +0 -5
  217. package/dist/runtime/serialization/types/SerializedSet.js +0 -1
  218. package/dist/runtime/serialization/types/TypedArray.d.ts +0 -2
  219. package/dist/runtime/serialization/types/TypedArray.js +0 -1
  220. package/dist/runtime/types/JitarHooks.d.ts +0 -6
  221. package/dist/runtime/types/JitarHooks.js +0 -1
  222. package/dist/runtime/types/ModuleImporter.d.ts +0 -3
  223. package/dist/runtime/types/ModuleImporter.js +0 -1
  224. package/dist/runtime/types/NextHandler.d.ts +0 -2
  225. package/dist/runtime/types/NextHandler.js +0 -1
  226. package/dist/runtime/utils/ModuleAnalyser.d.ts +0 -7
  227. package/dist/runtime/utils/ModuleAnalyser.js +0 -23
  228. package/dist/runtime/utils/ModuleLoader.d.ts +0 -8
  229. package/dist/runtime/utils/ModuleLoader.js +0 -30
  230. package/dist/runtime/utils/UrlRewriter.d.ts +0 -4
  231. package/dist/runtime/utils/UrlRewriter.js +0 -36
@@ -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,4 +0,0 @@
1
- export default class ImportRewriter {
2
- #private;
3
- static rewrite(content: string): string;
4
- }
@@ -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,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 * 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
- }
@@ -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
- }
@@ -1,30 +0,0 @@
1
- import * as Keywords from './definitions/Keywords.js';
2
- export default class SourceAppender {
3
- static append(module, code, filename) {
4
- const classNames = this.#extractClassNames(module);
5
- if (classNames.length === 0) {
6
- return code;
7
- }
8
- const sourceCode = this.#createSourceCode(filename, classNames);
9
- return `${code}\n${sourceCode}`;
10
- }
11
- static #extractClassNames(module) {
12
- const classes = module.classes;
13
- const names = [];
14
- for (const key of classes.keys()) {
15
- const clazz = classes.get(key);
16
- if (clazz === undefined) {
17
- continue;
18
- }
19
- if (key !== Keywords.DEFAULT && key !== clazz.name) {
20
- continue;
21
- }
22
- names.push(clazz.name);
23
- }
24
- return names;
25
- }
26
- static #createSourceCode(filename, classNames) {
27
- const codes = classNames.map(className => `${className}.source = '${filename}';`);
28
- return codes.join('\n');
29
- }
30
- }
@@ -1,2 +0,0 @@
1
- export declare const DEFAULT = "default";
2
- export declare const JITAR = "jitar";
@@ -1,2 +0,0 @@
1
- export const DEFAULT = 'default';
2
- export const JITAR = 'jitar';
@@ -1,3 +0,0 @@
1
- export default class InvalidSegmentFilename extends Error {
2
- constructor(filename: string);
3
- }
@@ -1,5 +0,0 @@
1
- export default class InvalidSegmentFilename extends Error {
2
- constructor(filename) {
3
- super(`Segment filename '${filename}' is invalid`);
4
- }
5
- }
@@ -1,3 +0,0 @@
1
- export default class MissingModuleExport extends Error {
2
- constructor(filename: string, key: string);
3
- }
@@ -1,5 +0,0 @@
1
- export default class MissingModuleExport extends Error {
2
- constructor(filename, key) {
3
- super(`Module '${filename}' does not export '${key}'`);
4
- }
5
- }
@@ -1,3 +0,0 @@
1
- export default class SegmentFileNotLoaded extends Error {
2
- constructor(filename: string);
3
- }
@@ -1,5 +0,0 @@
1
- export default class SegmentFileNotLoaded extends Error {
2
- constructor(filename) {
3
- super(`Failed to load segment file '${filename}'`);
4
- }
5
- }
@@ -1,3 +0,0 @@
1
- export default class SegmentModuleNotLoaded extends Error {
2
- constructor(filename: string);
3
- }
@@ -1,5 +0,0 @@
1
- export default class SegmentModuleNotLoaded extends Error {
2
- constructor(filename) {
3
- super(`Segment module could not be loaded from '${filename}'`);
4
- }
5
- }
@@ -1,10 +0,0 @@
1
- import { ReflectionClass, ReflectionFunction } from 'jitar-reflection';
2
- export default class ApplicationModule {
3
- #private;
4
- constructor(filename: string, classes: Map<string, ReflectionClass>, functions: Map<string, ReflectionFunction>);
5
- get filename(): string;
6
- get classes(): Map<string, ReflectionClass>;
7
- get functions(): Map<string, ReflectionFunction>;
8
- hasClasses(): boolean;
9
- hasFunctions(): boolean;
10
- }
@@ -1,19 +0,0 @@
1
- export default class ApplicationModule {
2
- #filename;
3
- #classes;
4
- #functions;
5
- constructor(filename, classes, functions) {
6
- this.#filename = filename;
7
- this.#classes = classes;
8
- this.#functions = functions;
9
- }
10
- get filename() { return this.#filename; }
11
- get classes() { return this.#classes; }
12
- get functions() { return this.#functions; }
13
- hasClasses() {
14
- return this.#classes.size > 0;
15
- }
16
- hasFunctions() {
17
- return this.#functions.size > 0;
18
- }
19
- }
@@ -1,12 +0,0 @@
1
- import { ReflectionFunction } from 'jitar-reflection';
2
- export default class Implementation {
3
- #private;
4
- constructor(module: string, name: string, access: string, version: string, executable: ReflectionFunction);
5
- get id(): number;
6
- get module(): string;
7
- get name(): string;
8
- get fqn(): string;
9
- get access(): string;
10
- get version(): string;
11
- get executable(): ReflectionFunction;
12
- }
@@ -1,27 +0,0 @@
1
- import FqnBuilder from '../../../core/utils/FqnBuilder.js';
2
- let lastId = 0;
3
- export default class Implementation {
4
- #id;
5
- #module;
6
- #name;
7
- #fqn;
8
- #access;
9
- #version;
10
- #executable;
11
- constructor(module, name, access, version, executable) {
12
- this.#id = ++lastId;
13
- this.#module = module;
14
- this.#name = name;
15
- this.#fqn = FqnBuilder.build(module, name);
16
- this.#access = access;
17
- this.#version = version;
18
- this.#executable = executable;
19
- }
20
- get id() { return this.#id; }
21
- get module() { return this.#module; }
22
- get name() { return this.#name; }
23
- get fqn() { return this.#fqn; }
24
- get access() { return this.#access; }
25
- get version() { return this.#version; }
26
- get executable() { return this.#executable; }
27
- }
@@ -1,9 +0,0 @@
1
- import Implementation from './Implementation.js';
2
- export default class Procedure {
3
- #private;
4
- constructor(module: string, name: string);
5
- get module(): string;
6
- get name(): string;
7
- get implementations(): Implementation[];
8
- addImplementation(implementation: Implementation): void;
9
- }
@@ -1,15 +0,0 @@
1
- export default class Procedure {
2
- #module;
3
- #name;
4
- #implementations = [];
5
- constructor(module, name) {
6
- this.#module = module;
7
- this.#name = name;
8
- }
9
- get module() { return this.#module; }
10
- get name() { return this.#name; }
11
- get implementations() { return this.#implementations; }
12
- addImplementation(implementation) {
13
- this.#implementations.push(implementation);
14
- }
15
- }
@@ -1,10 +0,0 @@
1
- import Procedure from './Procedure.js';
2
- import SegmentModule from './SegmentModule.js';
3
- export default class Segment {
4
- #private;
5
- constructor(filename: string, modules: SegmentModule[], procedures: Map<string, Procedure>);
6
- get filename(): string;
7
- get modules(): SegmentModule[];
8
- get procedures(): Map<string, Procedure>;
9
- getFilenames(): string[];
10
- }
@@ -1,16 +0,0 @@
1
- export default class Segment {
2
- #filename;
3
- #modules;
4
- #procedures;
5
- constructor(filename, modules, procedures) {
6
- this.#filename = filename;
7
- this.#modules = modules;
8
- this.#procedures = procedures;
9
- }
10
- get filename() { return this.#filename; }
11
- get modules() { return this.#modules; }
12
- get procedures() { return this.#procedures; }
13
- getFilenames() {
14
- return this.#modules.map((module) => module.filename);
15
- }
16
- }
@@ -1,10 +0,0 @@
1
- import Implementation from './Implementation.js';
2
- import { ReflectionModule } from 'jitar-reflection';
3
- export default class SegmentModule {
4
- #private;
5
- constructor(filename: string, exports: ReflectionModule, implementations: Map<string, Implementation>);
6
- get filename(): string;
7
- get exports(): ReflectionModule;
8
- get implementations(): Map<string, Implementation>;
9
- getImportKeys(): string[];
10
- }
@@ -1,14 +0,0 @@
1
- export default class SegmentModule {
2
- #filename;
3
- #exports;
4
- #implementations;
5
- constructor(filename, exports, implementations) {
6
- this.#filename = filename;
7
- this.#exports = exports;
8
- this.#implementations = implementations;
9
- }
10
- get filename() { return this.#filename; }
11
- get exports() { return this.#exports; }
12
- get implementations() { return this.#implementations; }
13
- getImportKeys() { return [...this.#implementations.keys()]; }
14
- }
@@ -1,5 +0,0 @@
1
- import SegmentImports from './SegmentImports.js';
2
- type SegmentFile = {
3
- [key: string]: SegmentImports;
4
- };
5
- export default SegmentFile;
@@ -1 +0,0 @@
1
- export {};
@@ -1,6 +0,0 @@
1
- type SegmentImportProperties = {
2
- as?: string;
3
- access?: string;
4
- version?: string;
5
- };
6
- export default SegmentImportProperties;
@@ -1 +0,0 @@
1
- export {};
@@ -1,5 +0,0 @@
1
- import SegmentImportProperties from './SegmentImportProperties.js';
2
- type SegmentImports = {
3
- [key: string]: SegmentImportProperties;
4
- };
5
- export default SegmentImports;
@@ -1 +0,0 @@
1
- export {};
@@ -1,3 +0,0 @@
1
- export default class ClientNotFound extends Error {
2
- constructor(clientId: string);
3
- }
@@ -1,6 +0,0 @@
1
- export default class ClientNotFound extends Error {
2
- constructor(clientId) {
3
- super(`Client found for id '${clientId}'`);
4
- }
5
- }
6
- ClientNotFound.source = '/jitar/runtime/errors/ClientNotFound.js';
@@ -1,3 +0,0 @@
1
- export default class FileNotFound extends Error {
2
- constructor(filename: string);
3
- }