jitar 0.1.1 → 0.1.2

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 (180) hide show
  1. package/dist/core/Implementation.js +7 -0
  2. package/dist/core/errors/UnknownParameter.d.ts +3 -0
  3. package/dist/core/errors/UnknownParameter.js +6 -0
  4. package/dist/runtime/LocalRepository.d.ts +1 -1
  5. package/dist/runtime/LocalRepository.js +13 -4
  6. package/dist/server/configuration/RepositoryConfiguration.d.ts +1 -0
  7. package/dist/server/configuration/RepositoryConfiguration.js +7 -1
  8. package/dist/server/configuration/StandaloneConfiguration.d.ts +1 -0
  9. package/dist/server/configuration/StandaloneConfiguration.js +6 -0
  10. package/dist/server/utils/LocalFileManager.d.ts +1 -0
  11. package/dist/server/utils/LocalFileManager.js +19 -11
  12. package/dist/server/utils/RuntimeConfigurator.js +9 -4
  13. package/package.json +4 -1
  14. package/.eslintignore +0 -3
  15. package/.eslintrc +0 -16
  16. package/jest.config.js +0 -20
  17. package/src/client.ts +0 -18
  18. package/src/core/ErrorManager.ts +0 -18
  19. package/src/core/Implementation.ts +0 -53
  20. package/src/core/Procedure.ts +0 -98
  21. package/src/core/Segment.ts +0 -62
  22. package/src/core/SegmentBuilder.ts +0 -55
  23. package/src/core/Version.ts +0 -68
  24. package/src/core/definitions/AccessLevel.ts +0 -3
  25. package/src/core/errors/ImplementationNotFound.ts +0 -12
  26. package/src/core/errors/InvalidVersionNumber.ts +0 -12
  27. package/src/core/errors/MissingParameterValue.ts +0 -12
  28. package/src/core/errors/NotImplemented.ts +0 -12
  29. package/src/core/errors/ProcedureNotFound.ts +0 -12
  30. package/src/core/interfaces/Runner.ts +0 -7
  31. package/src/core/reflection/ParameterParser.ts +0 -74
  32. package/src/core/reflection/ReflectionHelper.ts +0 -118
  33. package/src/core/reflection/models/ReflectionField.ts +0 -22
  34. package/src/core/reflection/models/ReflectionParameter.ts +0 -18
  35. package/src/core/types/Component.ts +0 -8
  36. package/src/core/types/FlexObject.ts +0 -4
  37. package/src/core/types/Module.ts +0 -6
  38. package/src/core/types/SegmentImplementation.ts +0 -9
  39. package/src/core/types/SegmentModule.ts +0 -9
  40. package/src/core/types/SegmentProcedure.ts +0 -11
  41. package/src/core/utils/FqnBuilder.ts +0 -11
  42. package/src/hooks.ts +0 -2
  43. package/src/lib.ts +0 -7
  44. package/src/runtime/ClientId.ts +0 -18
  45. package/src/runtime/Gateway.ts +0 -18
  46. package/src/runtime/LocalGateway.ts +0 -93
  47. package/src/runtime/LocalNode.ts +0 -130
  48. package/src/runtime/LocalRepository.ts +0 -154
  49. package/src/runtime/Node.ts +0 -15
  50. package/src/runtime/NodeBalancer.ts +0 -61
  51. package/src/runtime/NodeMonitor.ts +0 -63
  52. package/src/runtime/Proxy.ts +0 -60
  53. package/src/runtime/Remote.ts +0 -157
  54. package/src/runtime/RemoteGateway.ts +0 -40
  55. package/src/runtime/RemoteNode.ts +0 -49
  56. package/src/runtime/RemoteRepository.ts +0 -60
  57. package/src/runtime/Repository.ts +0 -20
  58. package/src/runtime/Runtime.ts +0 -47
  59. package/src/runtime/caching/CacheBuilder.ts +0 -424
  60. package/src/runtime/caching/ImportRewriter.ts +0 -76
  61. package/src/runtime/caching/RemoteBuilder.ts +0 -51
  62. package/src/runtime/caching/SourceAppender.ts +0 -57
  63. package/src/runtime/caching/definitions/Keywords.ts +0 -3
  64. package/src/runtime/caching/errors/InvalidSegmentFilename.ts +0 -8
  65. package/src/runtime/caching/errors/MissingModuleExport.ts +0 -8
  66. package/src/runtime/caching/errors/SegmentFileNotLoaded.ts +0 -8
  67. package/src/runtime/caching/errors/SegmentModuleNotLoaded.ts +0 -8
  68. package/src/runtime/caching/models/ApplicationModule.ts +0 -30
  69. package/src/runtime/caching/models/Implementation.ts +0 -41
  70. package/src/runtime/caching/models/Procedure.ts +0 -26
  71. package/src/runtime/caching/models/Segment.ts +0 -28
  72. package/src/runtime/caching/models/SegmentModule.ts +0 -26
  73. package/src/runtime/caching/types/SegmentFile.ts +0 -6
  74. package/src/runtime/caching/types/SegmentImportProperties.ts +0 -9
  75. package/src/runtime/caching/types/SegmentImports.ts +0 -6
  76. package/src/runtime/errors/ClientNotFound.ts +0 -12
  77. package/src/runtime/errors/FileNotFound.ts +0 -12
  78. package/src/runtime/errors/InvalidClientId.ts +0 -12
  79. package/src/runtime/errors/InvalidJitarHooks.ts +0 -12
  80. package/src/runtime/errors/InvalidSegmentFile.ts +0 -12
  81. package/src/runtime/errors/ModuleNotLoaded.ts +0 -12
  82. package/src/runtime/errors/NoNodeAvailable.ts +0 -12
  83. package/src/runtime/errors/RepositoryNotAvaiable.ts +0 -12
  84. package/src/runtime/errors/RuntimeNotAvailable.ts +0 -12
  85. package/src/runtime/errors/SegmentNotFound.ts +0 -12
  86. package/src/runtime/hooks/dependencies.ts +0 -19
  87. package/src/runtime/hooks/runtime.ts +0 -25
  88. package/src/runtime/interfaces/FileManager.ts +0 -19
  89. package/src/runtime/interfaces/HealthCheck.ts +0 -5
  90. package/src/runtime/interfaces/ProcedureContainer.ts +0 -9
  91. package/src/runtime/models/File.ts +0 -22
  92. package/src/runtime/serialization/ArraySerializer.ts +0 -27
  93. package/src/runtime/serialization/ClassSerializer.ts +0 -133
  94. package/src/runtime/serialization/MapSerializer.ts +0 -60
  95. package/src/runtime/serialization/ObjectSerializer.ts +0 -42
  96. package/src/runtime/serialization/SetSerializer.ts +0 -42
  97. package/src/runtime/serialization/ValueSerializer.ts +0 -81
  98. package/src/runtime/serialization/errors/ClassNotFound.ts +0 -12
  99. package/src/runtime/serialization/errors/InvalidClass.ts +0 -12
  100. package/src/runtime/serialization/errors/InvalidPropertyType.ts +0 -12
  101. package/src/runtime/serialization/interfaces/Serializer.ts +0 -10
  102. package/src/runtime/serialization/types/SerializableObject.ts +0 -6
  103. package/src/runtime/serialization/types/Serialized.ts +0 -8
  104. package/src/runtime/serialization/types/SerializedClass.ts +0 -13
  105. package/src/runtime/serialization/types/SerializedMap.ts +0 -13
  106. package/src/runtime/serialization/types/SerializedObject.ts +0 -4
  107. package/src/runtime/serialization/types/SerializedSet.ts +0 -9
  108. package/src/runtime/types/JitarHooks.ts +0 -10
  109. package/src/runtime/types/ModuleImporter.ts +0 -6
  110. package/src/runtime/utils/ModuleAnalyser.ts +0 -60
  111. package/src/runtime/utils/ModuleLoader.ts +0 -51
  112. package/src/runtime/utils/UrlRewriter.ts +0 -59
  113. package/src/server/JitarServer.ts +0 -161
  114. package/src/server/configuration/GatewayConfiguration.ts +0 -9
  115. package/src/server/configuration/NodeConfiguration.ts +0 -15
  116. package/src/server/configuration/ProxyConfiguration.ts +0 -16
  117. package/src/server/configuration/RepositoryConfiguration.ts +0 -17
  118. package/src/server/configuration/RuntimeConfiguration.ts +0 -30
  119. package/src/server/configuration/ServerOptions.ts +0 -14
  120. package/src/server/configuration/StandaloneConfiguration.ts +0 -21
  121. package/src/server/controllers/AssetsController.ts +0 -59
  122. package/src/server/controllers/HealthController.ts +0 -41
  123. package/src/server/controllers/JitarController.ts +0 -18
  124. package/src/server/controllers/ModulesController.ts +0 -77
  125. package/src/server/controllers/NodesController.ts +0 -58
  126. package/src/server/controllers/ProceduresController.ts +0 -31
  127. package/src/server/controllers/ProxyController.ts +0 -38
  128. package/src/server/controllers/RPCController.ts +0 -173
  129. package/src/server/definitions/RuntimeDefaults.ts +0 -10
  130. package/src/server/errors/MissingConfigurationValue.ts +0 -8
  131. package/src/server/errors/RuntimeNotAvaiable.ts +0 -8
  132. package/src/server/errors/UnknownRuntimeMode.ts +0 -8
  133. package/src/server/models/HealthDto.ts +0 -11
  134. package/src/server/models/NodeDto.ts +0 -11
  135. package/src/server/utils/DataConverter.ts +0 -15
  136. package/src/server/utils/LocalFileManager.ts +0 -122
  137. package/src/server/utils/RuntimeConfigurationLoader.ts +0 -19
  138. package/src/server/utils/RuntimeConfigurator.ts +0 -207
  139. package/src/server/utils/ServerOptionsReader.ts +0 -17
  140. package/src/server.ts +0 -16
  141. package/test/_fixtures/core/Implementation.fixture.ts +0 -33
  142. package/test/_fixtures/core/Procedure.fixture.ts +0 -33
  143. package/test/_fixtures/core/Segment.fixture.ts +0 -36
  144. package/test/_fixtures/core/SegmentBuilder.fixture.ts +0 -45
  145. package/test/_fixtures/core/Version.fixture.ts +0 -18
  146. package/test/_fixtures/core/reflection/ReflectionHelper.fixture.ts +0 -56
  147. package/test/_fixtures/runtime/LocalGateway.fixture.ts +0 -24
  148. package/test/_fixtures/runtime/LocalNode.fixture.ts +0 -16
  149. package/test/_fixtures/runtime/LocalRepository.fixture.ts +0 -73
  150. package/test/_fixtures/runtime/NodeBalancer.fixture.ts +0 -19
  151. package/test/_fixtures/runtime/NodeMonitor.fixture.ts +0 -34
  152. package/test/_fixtures/runtime/RemoteNode.fixture.ts +0 -8
  153. package/test/_fixtures/runtime/caching/ImportRewriter.fixture.ts +0 -81
  154. package/test/_fixtures/runtime/caching/RemoteBuilder.fixture.ts +0 -50
  155. package/test/_fixtures/runtime/caching/SourceAppender.fixture.ts +0 -35
  156. package/test/_fixtures/runtime/segments.ts +0 -78
  157. package/test/_fixtures/runtime/serialization/ValueSerializer.fixture.ts +0 -134
  158. package/test/_fixtures/runtime/utils/ModuleAnaliser.fixture.ts +0 -26
  159. package/test/core/Implementation.spec.ts +0 -89
  160. package/test/core/Procedure.spec.ts +0 -108
  161. package/test/core/Segment.spec.ts +0 -74
  162. package/test/core/SegmentBuilder.spec.ts +0 -39
  163. package/test/core/Version.spec.ts +0 -103
  164. package/test/core/errors/ErrorManager.spec.ts +0 -32
  165. package/test/core/reflection/ReflectionHelper.spec.ts +0 -128
  166. package/test/core/utils/FqnBuilder.spec.ts +0 -22
  167. package/test/runtime/ClientId.spec.ts +0 -43
  168. package/test/runtime/LocalGateway.spec.ts +0 -40
  169. package/test/runtime/LocalNode.spec.ts +0 -87
  170. package/test/runtime/LocalRepository.spec.ts +0 -50
  171. package/test/runtime/NodeBalancer.spec.ts +0 -39
  172. package/test/runtime/NodeMonitor.spec.ts +0 -31
  173. package/test/runtime/RemoteNode.spec.ts +0 -43
  174. package/test/runtime/caching/ImportRewriter.spec.ts +0 -68
  175. package/test/runtime/caching/RemoteBuilder.spec.ts +0 -21
  176. package/test/runtime/caching/SourceAppender.spec.ts +0 -31
  177. package/test/runtime/serialization/ValueSerializer.spec.ts +0 -203
  178. package/test/runtime/utils/ModuleAnalyser.spec.ts +0 -54
  179. package/test/runtime/utils/UrlRewriter.spec.ts +0 -57
  180. package/tsconfig.json +0 -23
@@ -1,4 +1,5 @@
1
1
  import MissingParameterValue from './errors/MissingParameterValue.js';
2
+ import UnknownParameter from './errors/UnknownParameter.js';
2
3
  import * as AccessLevel from './definitions/AccessLevel.js';
3
4
  export default class Implementation {
4
5
  #version;
@@ -20,6 +21,12 @@ export default class Implementation {
20
21
  }
21
22
  #extractParameterValues(parameters) {
22
23
  const values = [];
24
+ const incommingKeys = Array.from(parameters.keys());
25
+ const knownKeys = this.#parameters.map(parameter => parameter.name);
26
+ const additionalKeys = incommingKeys.filter(key => knownKeys.includes(key) === false);
27
+ if (additionalKeys.length !== 0) {
28
+ throw new UnknownParameter(additionalKeys[0]);
29
+ }
23
30
  for (const parameter of this.#parameters) {
24
31
  const value = parameters.get(parameter.name);
25
32
  if (value === undefined && parameter.isOptional === false) {
@@ -0,0 +1,3 @@
1
+ export default class UnknownParameter extends Error {
2
+ constructor(parameterName: string);
3
+ }
@@ -0,0 +1,6 @@
1
+ export default class UnknownParameter extends Error {
2
+ constructor(parameterName) {
3
+ super(`Unknown parameter ${parameterName}`);
4
+ }
5
+ }
6
+ UnknownParameter.source = '/jitar/core/errors/UnknownParameter.js';
@@ -5,7 +5,7 @@ import FileManager from './interfaces/FileManager.js';
5
5
  import File from './models/File.js';
6
6
  export default class LocalRepository extends Repository {
7
7
  #private;
8
- constructor(fileManager: FileManager, url?: string);
8
+ constructor(fileManager: FileManager, assets: string[], url?: string);
9
9
  loadSegment(name: string): Promise<void>;
10
10
  registerSegment(name: string, files: string[]): Promise<void>;
11
11
  registerClient(segmentFilenames: string[]): Promise<string>;
@@ -3,6 +3,7 @@ import Repository from './Repository.js';
3
3
  import File from './models/File.js';
4
4
  import ModuleLoader from './utils/ModuleLoader.js';
5
5
  import ClientNotFound from './errors/ClientNotFound.js';
6
+ import FileNotFound from './errors/FileNotFound.js';
6
7
  import InvalidClientId from './errors/InvalidClientId.js';
7
8
  import InvalidSegmentFile from './errors/InvalidSegmentFile.js';
8
9
  import { setRuntime } from '../hooks.js';
@@ -10,9 +11,11 @@ export default class LocalRepository extends Repository {
10
11
  #fileManager;
11
12
  #segments = new Map();
12
13
  #clients = new Map();
13
- constructor(fileManager, url) {
14
+ #assets;
15
+ constructor(fileManager, assets, url) {
14
16
  super(url);
15
17
  this.#fileManager = fileManager;
18
+ this.#assets = assets;
16
19
  }
17
20
  async loadSegment(name) {
18
21
  const filename = `./${name}.segment.repository.js`;
@@ -36,7 +39,10 @@ export default class LocalRepository extends Repository {
36
39
  setRuntime(runtime);
37
40
  }
38
41
  async loadAsset(filename) {
39
- return this.#fileManager.load(filename);
42
+ if (this.#assets.includes(filename) === false) {
43
+ throw new FileNotFound(filename);
44
+ }
45
+ return this.#loadFile(filename);
40
46
  }
41
47
  async getModuleLocation(clientId) {
42
48
  return this.#fileManager.getRootLocation();
@@ -74,12 +80,15 @@ export default class LocalRepository extends Repository {
74
80
  if (isSegmented) {
75
81
  filename = filename.replace('.js', '.local.js');
76
82
  }
77
- const file = await this.loadAsset(filename);
83
+ const file = await this.#loadFile(filename);
78
84
  const code = file.content.toString();
79
85
  return new File(filename, 'application/javascript', code);
80
86
  }
81
87
  async #getRemoteModule(filename) {
82
88
  const remoteFilename = filename.replace('.js', '.remote.js');
83
- return this.loadAsset(remoteFilename);
89
+ return this.#loadFile(remoteFilename);
90
+ }
91
+ async #loadFile(filename) {
92
+ return this.#fileManager.load(filename);
84
93
  }
85
94
  }
@@ -2,4 +2,5 @@ export default class RepositoryConfiguration {
2
2
  source?: string;
3
3
  cache?: string;
4
4
  index?: string;
5
+ assets?: string[];
5
6
  }
@@ -7,11 +7,12 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  var __metadata = (this && this.__metadata) || function (k, v) {
8
8
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
9
  };
10
- import { IsOptional, IsString } from 'class-validator';
10
+ import { IsArray, IsOptional, IsString } from 'class-validator';
11
11
  export default class RepositoryConfiguration {
12
12
  source;
13
13
  cache;
14
14
  index;
15
+ assets;
15
16
  }
16
17
  __decorate([
17
18
  IsString(),
@@ -28,3 +29,8 @@ __decorate([
28
29
  IsOptional(),
29
30
  __metadata("design:type", String)
30
31
  ], RepositoryConfiguration.prototype, "index", void 0);
32
+ __decorate([
33
+ IsArray(),
34
+ IsOptional(),
35
+ __metadata("design:type", Array)
36
+ ], RepositoryConfiguration.prototype, "assets", void 0);
@@ -3,4 +3,5 @@ export default class StandaloneConfiguration {
3
3
  cache?: string;
4
4
  index?: string;
5
5
  segments?: string[];
6
+ assets?: string[];
6
7
  }
@@ -13,6 +13,7 @@ export default class StandaloneConfiguration {
13
13
  cache;
14
14
  index;
15
15
  segments;
16
+ assets;
16
17
  }
17
18
  __decorate([
18
19
  IsString(),
@@ -34,3 +35,8 @@ __decorate([
34
35
  IsOptional(),
35
36
  __metadata("design:type", Array)
36
37
  ], StandaloneConfiguration.prototype, "segments", void 0);
38
+ __decorate([
39
+ IsArray(),
40
+ IsOptional(),
41
+ __metadata("design:type", Array)
42
+ ], StandaloneConfiguration.prototype, "assets", void 0);
@@ -17,4 +17,5 @@ export default class LocalFileManager implements FileManager {
17
17
  getSegmentFiles(): Promise<string[]>;
18
18
  getNodeSegmentFiles(): Promise<string[]>;
19
19
  getRepositorySegmentFiles(): Promise<string[]>;
20
+ getAssetFiles(patterns: string[]): Promise<string[]>;
20
21
  }
@@ -51,23 +51,31 @@ export default class LocalFileManager {
51
51
  return fs.remove(location);
52
52
  }
53
53
  async getModuleFileNames() {
54
- const location = this.getAbsoluteLocation('./');
55
- const filenames = await glob(`${location}/**/*.js`);
56
- return filenames;
54
+ return this.#filterFiles('**/*.js');
57
55
  }
58
56
  async getSegmentFiles() {
59
- const location = this.getAbsoluteLocation('./');
60
- const filenames = await glob(`${location}/**/*.segment.json`);
61
- return filenames;
57
+ return this.#filterFiles('**/*.segment.json');
62
58
  }
63
59
  async getNodeSegmentFiles() {
64
- const location = this.getAbsoluteLocation('./');
65
- const filenames = await glob(`${location}/**/*.segment.local.js`);
66
- return filenames;
60
+ return this.#filterFiles('**/*.segment.local.js');
67
61
  }
68
62
  async getRepositorySegmentFiles() {
63
+ return this.#filterFiles('**/*.segment.repository.js');
64
+ }
65
+ async getAssetFiles(patterns) {
66
+ const promises = patterns.map(pattern => this.#filterFiles(pattern));
67
+ const assetFiles = (await Promise.all(promises)).flat();
68
+ return assetFiles
69
+ .map(filename => this.getRelativeLocation(filename))
70
+ .filter(filename => this.#isGeneratedFile(filename) === false);
71
+ }
72
+ async #filterFiles(pattern) {
69
73
  const location = this.getAbsoluteLocation('./');
70
- const filenames = await glob(`${location}/**/*.segment.repository.js`);
71
- return filenames;
74
+ return await glob(`${location}/${pattern}`);
75
+ }
76
+ #isGeneratedFile(filename) {
77
+ return filename.endsWith('.local.js')
78
+ || filename.endsWith('.repository.js')
79
+ || filename.endsWith('.remote.js');
72
80
  }
73
81
  }
@@ -29,19 +29,21 @@ export default class RuntimeConfigurator {
29
29
  static async #configureStandAlone(url, configuration) {
30
30
  const sourceLocation = configuration.source ?? RuntimeDefaults.SOURCE;
31
31
  const cacheLocation = configuration.cache ?? RuntimeDefaults.CACHE;
32
+ const assetFilePatterns = configuration.assets;
32
33
  await this.#buildCache(sourceLocation, cacheLocation);
33
34
  const segmentNames = configuration.segments === undefined
34
35
  ? await this.#getSegmentNames(cacheLocation)
35
36
  : configuration.segments;
36
- const repository = await this.#buildRepository(url, cacheLocation);
37
+ const repository = await this.#buildRepository(url, cacheLocation, assetFilePatterns);
37
38
  const node = await this.#buildNode(url, segmentNames, repository);
38
39
  return this.#buildProxy(url, repository, node);
39
40
  }
40
41
  static async #configureRepository(url, configuration) {
41
42
  const sourceLocation = configuration.source ?? RuntimeDefaults.SOURCE;
42
43
  const cacheLocation = configuration.cache ?? RuntimeDefaults.CACHE;
44
+ const assetFilePatterns = configuration.assets ?? [];
43
45
  await this.#buildCache(sourceLocation, cacheLocation);
44
- return this.#buildRepository(url, cacheLocation);
46
+ return this.#buildRepository(url, cacheLocation, assetFilePatterns);
45
47
  }
46
48
  static async #configureGateway(url, configuration) {
47
49
  return this.#buildGateway(url, configuration.monitor);
@@ -95,9 +97,12 @@ export default class RuntimeConfigurator {
95
97
  const endIndex = name.indexOf('.segment');
96
98
  return name.substring(0, endIndex);
97
99
  }
98
- static async #buildRepository(url, cacheLocation) {
100
+ static async #buildRepository(url, cacheLocation, assetFilePatterns) {
99
101
  const fileManager = new LocalFileManager(cacheLocation);
100
- const repository = new LocalRepository(fileManager, url);
102
+ const assetFiles = assetFilePatterns !== undefined
103
+ ? await fileManager.getAssetFiles(assetFilePatterns)
104
+ : [];
105
+ const repository = new LocalRepository(fileManager, assetFiles, url);
101
106
  const segmentFilenames = await fileManager.getRepositorySegmentFiles();
102
107
  const segmentNames = segmentFilenames.map(filename => this.#extractSegmentName(filename));
103
108
  for (const name of segmentNames) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jitar",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Distributed runtime for JavaScript and TypeScript to chop monolithic applications into micros.",
5
5
  "author": "Masking Technology <info@masking.tech> (https://jitar.dev)",
6
6
  "license": "MIT",
@@ -46,6 +46,9 @@
46
46
  "jest": "^28.1.3",
47
47
  "ts-jest": "^28.0.8"
48
48
  },
49
+ "engines": {
50
+ "node": ">=18.7"
51
+ },
49
52
  "repository": {
50
53
  "type": "git",
51
54
  "url": "https://github.com/MaskingTechnology/jitar"
package/.eslintignore DELETED
@@ -1,3 +0,0 @@
1
- coverage
2
- dist
3
- node_modules
package/.eslintrc DELETED
@@ -1,16 +0,0 @@
1
- {
2
- "root": true,
3
- "parser": "@typescript-eslint/parser",
4
- "plugins": [
5
- "@typescript-eslint"
6
- ],
7
- "extends": [
8
- "eslint:recommended",
9
- "plugin:@typescript-eslint/eslint-recommended",
10
- "plugin:@typescript-eslint/recommended"
11
- ],
12
- "rules":
13
- {
14
- "@typescript-eslint/ban-types": "off"
15
- }
16
- }
package/jest.config.js DELETED
@@ -1,20 +0,0 @@
1
- /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
2
- export default {
3
- preset: 'ts-jest',
4
- testEnvironment: 'node',
5
- coverageProvider: 'v8',
6
- extensionsToTreatAsEsm: ['.ts'],
7
- globals: {
8
- 'ts-jest': {
9
- useESM: true
10
- }
11
- },
12
- moduleNameMapper: {
13
- '^(\\.{1,2}/.*)\\.js$': '$1',
14
- },
15
- coveragePathIgnorePatterns: [
16
- '<rootDir>/node_modules/',
17
- '<rootDir>/test/_fixtures/',
18
- '<rootDir>/src/runtime/Remote.ts',
19
- ]
20
- };
package/src/client.ts DELETED
@@ -1,18 +0,0 @@
1
-
2
- import LocalNode from './runtime/LocalNode.js';
3
- import RemoteGateway from './runtime/RemoteGateway.js';
4
- import RemoteRepository from './runtime/RemoteRepository.js';
5
-
6
- export async function startClient(...segmentFiles: string[]): Promise<LocalNode>
7
- {
8
- const remoteUrl = document.location.origin;
9
-
10
- const node = new LocalNode();
11
- const gateway = new RemoteGateway(remoteUrl);
12
- const repository = new RemoteRepository(remoteUrl);
13
-
14
- await node.setGateway(gateway);
15
- await node.setRepository(repository, segmentFiles);
16
-
17
- return node;
18
- }
@@ -1,18 +0,0 @@
1
-
2
- export default class ErrorManager
3
- {
4
- static handle(error: unknown, name: string, version: string): Error
5
- {
6
- const parentMessage = error instanceof Error ? error.message : String(error);
7
- const newMessage = `${parentMessage}\n[${name} | v${version}]`;
8
-
9
- if (error instanceof Error)
10
- {
11
- error.message = newMessage;
12
-
13
- return error;
14
- }
15
-
16
- return new Error(newMessage);
17
- }
18
- }
@@ -1,53 +0,0 @@
1
-
2
- import MissingParameterValue from './errors/MissingParameterValue.js';
3
- import ReflectionParameter from './reflection/models/ReflectionParameter.js';
4
- import * as AccessLevel from './definitions/AccessLevel.js';
5
- import Version from './Version.js';
6
-
7
- export default class Implementation
8
- {
9
- #version: Version;
10
- #access: string;
11
- #parameters: ReflectionParameter[];
12
- #executable: Function;
13
-
14
- constructor(version: Version, access: string, parameters: ReflectionParameter[], executable: Function)
15
- {
16
- this.#version = version;
17
- this.#access = access;
18
- this.#parameters = parameters;
19
- this.#executable = executable;
20
- }
21
-
22
- get version() { return this.#version; }
23
-
24
- get public() { return this.#access === AccessLevel.PUBLIC; }
25
-
26
- get parameters() { return this.#parameters; }
27
-
28
- async run(args: Map<string, unknown>): Promise<unknown>
29
- {
30
- const values = this.#extractParameterValues(args);
31
-
32
- return await this.#executable.call(this.#executable, ...values);
33
- }
34
-
35
- #extractParameterValues(parameters: Map<string, unknown>): unknown[]
36
- {
37
- const values: unknown[] = [];
38
-
39
- for (const parameter of this.#parameters)
40
- {
41
- const value = parameters.get(parameter.name);
42
-
43
- if (value === undefined && parameter.isOptional === false)
44
- {
45
- throw new MissingParameterValue(parameter.name);
46
- }
47
-
48
- values.push(value);
49
- }
50
-
51
- return values;
52
- }
53
- }
@@ -1,98 +0,0 @@
1
-
2
- import ImplementationNotFound from './errors/ImplementationNotFound.js';
3
- import Implementation from './Implementation.js';
4
- import FqnBuilder from './utils/FqnBuilder.js';
5
- import Version from './Version.js';
6
-
7
- export default class Procedure
8
- {
9
- #module: string;
10
- #name: string;
11
- #fqn: string;
12
- #implementations: Map<Version, Implementation> = new Map();
13
- #latestImplementation?: Implementation;
14
-
15
- constructor(module: string, name: string)
16
- {
17
- this.#module = module;
18
- this.#name = name;
19
-
20
- this.#fqn = FqnBuilder.build(module, name);
21
- }
22
-
23
- get module() { return this.#module; }
24
-
25
- get name() { return this.#name; }
26
-
27
- get fqn() { return this.#fqn; }
28
-
29
- get public()
30
- {
31
- // If at least one implementation is public, the procedure is public
32
- // Public procedures can be called from outside the segment
33
-
34
- const implementations = [...this.#implementations.values()];
35
-
36
- return implementations.some(implementation => implementation.public);
37
- }
38
-
39
- addImplementation(implementation: Implementation): void
40
- {
41
- this.#implementations.set(implementation.version, implementation);
42
-
43
- if (this.#isNewLatestImplementation(implementation))
44
- {
45
- this.#latestImplementation = implementation;
46
- }
47
- }
48
-
49
- #isNewLatestImplementation(implementation: Implementation): boolean
50
- {
51
- return this.#latestImplementation === undefined
52
- || implementation.version.greater(this.#latestImplementation.version);
53
- }
54
-
55
- getImplementation(version: Version): Implementation | undefined
56
- {
57
- const selectedVersion = this.#selectAvailableVersion(version);
58
-
59
- return this.#implementations.get(selectedVersion);
60
- }
61
-
62
- #selectAvailableVersion(version: Version): Version
63
- {
64
- let selectedVersion = Version.DEFAULT;
65
-
66
- for (const implementationVersion of this.#implementations.keys())
67
- {
68
- if (implementationVersion.equals(version))
69
- {
70
- return implementationVersion;
71
- }
72
-
73
- if (implementationVersion.greater(version))
74
- {
75
- continue;
76
- }
77
-
78
- if (selectedVersion.less(implementationVersion))
79
- {
80
- selectedVersion = implementationVersion;
81
- }
82
- }
83
-
84
- return selectedVersion;
85
- }
86
-
87
- async run(version: Version, args: Map<string, unknown>): Promise<unknown>
88
- {
89
- const implementation = this.getImplementation(version);
90
-
91
- if (implementation === undefined)
92
- {
93
- throw new ImplementationNotFound(this.fqn, version.toString());
94
- }
95
-
96
- return implementation.run(args);
97
- }
98
- }
@@ -1,62 +0,0 @@
1
-
2
- import ErrorManager from './ErrorManager.js';
3
- import ProcedureNotFound from './errors/ProcedureNotFound.js';
4
- import Runner from './interfaces/Runner.js';
5
- import Procedure from './Procedure.js';
6
- import Version from './Version.js';
7
-
8
- export default class Segment implements Runner
9
- {
10
- #id: string;
11
- #procedures: Map<string, Procedure> = new Map();
12
-
13
- constructor(id: string)
14
- {
15
- this.#id = id;
16
- }
17
-
18
- get id() { return this.#id; }
19
-
20
- addProcedure(procedure: Procedure): void
21
- {
22
- this.#procedures.set(procedure.fqn, procedure);
23
- }
24
-
25
- hasProcedure(fqn: string): boolean
26
- {
27
- const procedure = this.getProcedure(fqn);
28
-
29
- return procedure !== undefined;
30
- }
31
-
32
- getProcedure(fqn: string): Procedure | undefined
33
- {
34
- return this.#procedures.get(fqn);
35
- }
36
-
37
- getPublicProcedures()
38
- {
39
- const procedures = [...this.#procedures.values()];
40
-
41
- return procedures.filter(procedure => procedure.public);
42
- }
43
-
44
- async run(fqn: string, version: Version, args: Map<string, unknown>): Promise<unknown>
45
- {
46
- const procedure = this.getProcedure(fqn);
47
-
48
- if (procedure === undefined)
49
- {
50
- throw new ProcedureNotFound(fqn);
51
- }
52
-
53
- try
54
- {
55
- return await procedure.run(version, args);
56
- }
57
- catch (error: unknown)
58
- {
59
- throw ErrorManager.handle(error, fqn, version.toString());
60
- }
61
- }
62
- }
@@ -1,55 +0,0 @@
1
-
2
- import SegmentModule from './types/SegmentModule.js';
3
- import SegmentProcedure from './types/SegmentProcedure.js';
4
- import SegmentImplementation from './types/SegmentImplementation.js';
5
-
6
- import ReflectionHelper from './reflection/ReflectionHelper.js';
7
-
8
- import Implementation from './Implementation.js';
9
- import Procedure from './Procedure.js';
10
- import Segment from './Segment.js';
11
- import Version from './Version.js';
12
-
13
- export default class SegmentBuilder
14
- {
15
- static build(id: string, module: SegmentModule): Segment
16
- {
17
- const segment = new Segment(id);
18
-
19
- for (const definition of module.procedures)
20
- {
21
- const procedure = this.#buildProcedure(definition);
22
-
23
- segment.addProcedure(procedure);
24
- }
25
-
26
- return segment;
27
- }
28
-
29
- static #buildProcedure(definition: SegmentProcedure): Procedure
30
- {
31
- const module = definition.module;
32
- const name = definition.name;
33
-
34
- const procedure = new Procedure(module, name);
35
-
36
- for (const implementationDefinition of definition.implementations)
37
- {
38
- const implementation = this.#buildImplementation(implementationDefinition);
39
-
40
- procedure.addImplementation(implementation);
41
- }
42
-
43
- return procedure;
44
- }
45
-
46
- static #buildImplementation(definition: SegmentImplementation): Implementation
47
- {
48
- const version = Version.parse(definition.version);
49
- const access = definition.access;
50
- const executable = definition.executable;
51
- const parameters = ReflectionHelper.getFunctionParameters(executable);
52
-
53
- return new Implementation(version, access, parameters, executable);
54
- }
55
- }
@@ -1,68 +0,0 @@
1
-
2
- import InvalidVersionNumber from './errors/InvalidVersionNumber.js';
3
-
4
- export default class Version
5
- {
6
- static get DEFAULT(): Version { return new Version(0, 0, 0); }
7
-
8
- #major: number;
9
- #minor: number;
10
- #patch: number;
11
-
12
- constructor(major = 0, minor = 0, patch = 0)
13
- {
14
- this.#major = major;
15
- this.#minor = minor;
16
- this.#patch = patch;
17
- }
18
-
19
- get major() { return this.#major; }
20
-
21
- get minor() { return this.#minor; }
22
-
23
- get patch() { return this.#patch; }
24
-
25
- equals(version: Version): boolean
26
- {
27
- return this.#major === version.major
28
- && this.#minor === version.minor
29
- && this.#patch === version.patch;
30
- }
31
-
32
- greater(version: Version): boolean
33
- {
34
- if (this.#major !== version.major) return this.#major > version.major;
35
- if (this.#minor !== version.minor) return this.#minor > version.minor;
36
- if (this.#patch !== version.patch) return this.#patch > version.patch;
37
-
38
- return false;
39
- }
40
-
41
- less(version: Version): boolean
42
- {
43
- if (this.#major !== version.major) return this.#major < version.major;
44
- if (this.#minor !== version.minor) return this.#minor < version.minor;
45
- if (this.#patch !== version.patch) return this.#patch < version.patch;
46
-
47
- return false;
48
- }
49
-
50
- toString(): string
51
- {
52
- return `${this.#major}.${this.#minor}.${this.#patch}`;
53
- }
54
-
55
- static parse(number: string): Version
56
- {
57
- const parts = number.split('.');
58
-
59
- switch (parts.length)
60
- {
61
- case 1: return new Version(Number.parseInt(parts[0]));
62
- case 2: return new Version(Number.parseInt(parts[0]), Number.parseInt(parts[1]));
63
- case 3: return new Version(Number.parseInt(parts[0]), Number.parseInt(parts[1]), Number.parseInt(parts[2]));
64
-
65
- default: throw new InvalidVersionNumber(number);
66
- }
67
- }
68
- }