jitar 0.1.3 → 0.2.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 (71) hide show
  1. package/dist/lib.d.ts +27 -1
  2. package/dist/lib.js +24 -1
  3. package/dist/runtime/serialization/ArrayBufferSerializer.d.ts +10 -0
  4. package/dist/runtime/serialization/ArrayBufferSerializer.js +54 -0
  5. package/dist/runtime/serialization/DateSerializer.d.ts +9 -0
  6. package/dist/runtime/serialization/DateSerializer.js +21 -0
  7. package/dist/runtime/serialization/ValueSerializer.d.ts +1 -0
  8. package/dist/runtime/serialization/ValueSerializer.js +24 -1
  9. package/dist/runtime/serialization/types/SerializedArrayBuffer.d.ts +6 -0
  10. package/dist/runtime/serialization/types/SerializedArrayBuffer.js +1 -0
  11. package/dist/runtime/serialization/types/SerializedDate.d.ts +5 -0
  12. package/dist/runtime/serialization/types/SerializedDate.js +1 -0
  13. package/dist/runtime/serialization/types/TypedArray.d.ts +2 -0
  14. package/dist/runtime/serialization/types/TypedArray.js +1 -0
  15. package/package.json +3 -19
  16. package/dist/server/JitarServer.d.ts +0 -8
  17. package/dist/server/JitarServer.js +0 -109
  18. package/dist/server/configuration/GatewayConfiguration.d.ts +0 -3
  19. package/dist/server/configuration/GatewayConfiguration.js +0 -18
  20. package/dist/server/configuration/NodeConfiguration.d.ts +0 -5
  21. package/dist/server/configuration/NodeConfiguration.js +0 -28
  22. package/dist/server/configuration/ProxyConfiguration.d.ts +0 -5
  23. package/dist/server/configuration/ProxyConfiguration.js +0 -29
  24. package/dist/server/configuration/RepositoryConfiguration.d.ts +0 -6
  25. package/dist/server/configuration/RepositoryConfiguration.js +0 -36
  26. package/dist/server/configuration/RuntimeConfiguration.d.ts +0 -13
  27. package/dist/server/configuration/RuntimeConfiguration.js +0 -48
  28. package/dist/server/configuration/ServerOptions.d.ts +0 -4
  29. package/dist/server/configuration/ServerOptions.js +0 -25
  30. package/dist/server/configuration/StandaloneConfiguration.d.ts +0 -7
  31. package/dist/server/configuration/StandaloneConfiguration.js +0 -42
  32. package/dist/server/controllers/AssetsController.d.ts +0 -8
  33. package/dist/server/controllers/AssetsController.js +0 -50
  34. package/dist/server/controllers/HealthController.d.ts +0 -10
  35. package/dist/server/controllers/HealthController.js +0 -47
  36. package/dist/server/controllers/JitarController.d.ts +0 -4
  37. package/dist/server/controllers/JitarController.js +0 -26
  38. package/dist/server/controllers/ModulesController.d.ts +0 -10
  39. package/dist/server/controllers/ModulesController.js +0 -68
  40. package/dist/server/controllers/NodesController.d.ts +0 -9
  41. package/dist/server/controllers/NodesController.js +0 -60
  42. package/dist/server/controllers/ProceduresController.d.ts +0 -10
  43. package/dist/server/controllers/ProceduresController.js +0 -35
  44. package/dist/server/controllers/ProxyController.d.ts +0 -7
  45. package/dist/server/controllers/ProxyController.js +0 -37
  46. package/dist/server/controllers/RPCController.d.ts +0 -9
  47. package/dist/server/controllers/RPCController.js +0 -146
  48. package/dist/server/definitions/RuntimeDefaults.d.ts +0 -7
  49. package/dist/server/definitions/RuntimeDefaults.js +0 -8
  50. package/dist/server/errors/MissingConfigurationValue.d.ts +0 -3
  51. package/dist/server/errors/MissingConfigurationValue.js +0 -5
  52. package/dist/server/errors/RuntimeNotAvaiable.d.ts +0 -3
  53. package/dist/server/errors/RuntimeNotAvaiable.js +0 -5
  54. package/dist/server/errors/UnknownRuntimeMode.d.ts +0 -3
  55. package/dist/server/errors/UnknownRuntimeMode.js +0 -5
  56. package/dist/server/models/HealthDto.d.ts +0 -4
  57. package/dist/server/models/HealthDto.js +0 -22
  58. package/dist/server/models/NodeDto.d.ts +0 -4
  59. package/dist/server/models/NodeDto.js +0 -22
  60. package/dist/server/utils/DataConverter.d.ts +0 -4
  61. package/dist/server/utils/DataConverter.js +0 -9
  62. package/dist/server/utils/LocalFileManager.d.ts +0 -21
  63. package/dist/server/utils/LocalFileManager.js +0 -81
  64. package/dist/server/utils/RuntimeConfigurationLoader.d.ts +0 -4
  65. package/dist/server/utils/RuntimeConfigurationLoader.js +0 -11
  66. package/dist/server/utils/RuntimeConfigurator.d.ts +0 -6
  67. package/dist/server/utils/RuntimeConfigurator.js +0 -135
  68. package/dist/server/utils/ServerOptionsReader.d.ts +0 -4
  69. package/dist/server/utils/ServerOptionsReader.js +0 -10
  70. package/dist/server.d.ts +0 -3
  71. package/dist/server.js +0 -8
@@ -1,5 +0,0 @@
1
- export default class MissingConfigurationValue extends Error {
2
- constructor(propertyName) {
3
- super(`Missing configuration value for '${propertyName}'`);
4
- }
5
- }
@@ -1,3 +0,0 @@
1
- export default class RuntimeNotAvaiable extends Error {
2
- constructor();
3
- }
@@ -1,5 +0,0 @@
1
- export default class RuntimeNotAvaiable extends Error {
2
- constructor() {
3
- super('Runtime is not available');
4
- }
5
- }
@@ -1,3 +0,0 @@
1
- export default class UnknownRuntimeMode extends Error {
2
- constructor();
3
- }
@@ -1,5 +0,0 @@
1
- export default class UnknownRuntimeMode extends Error {
2
- constructor() {
3
- super(`Unknown runtime mode`);
4
- }
5
- }
@@ -1,4 +0,0 @@
1
- export default class HealthDto {
2
- healthy: boolean;
3
- checks: Map<string, boolean>;
4
- }
@@ -1,22 +0,0 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- var __metadata = (this && this.__metadata) || function (k, v) {
8
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
- };
10
- import { IsBoolean } from 'class-validator';
11
- export default class HealthDto {
12
- healthy = false;
13
- checks = new Map();
14
- }
15
- __decorate([
16
- IsBoolean(),
17
- __metadata("design:type", Object)
18
- ], HealthDto.prototype, "healthy", void 0);
19
- __decorate([
20
- IsBoolean({ each: true }),
21
- __metadata("design:type", Map)
22
- ], HealthDto.prototype, "checks", void 0);
@@ -1,4 +0,0 @@
1
- export default class NodeDto {
2
- url: string;
3
- procedureNames: string[];
4
- }
@@ -1,22 +0,0 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- var __metadata = (this && this.__metadata) || function (k, v) {
8
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
- };
10
- import { ArrayNotEmpty, IsUrl } from 'class-validator';
11
- export default class NodeDto {
12
- url = '';
13
- procedureNames = [];
14
- }
15
- __decorate([
16
- IsUrl(),
17
- __metadata("design:type", Object)
18
- ], NodeDto.prototype, "url", void 0);
19
- __decorate([
20
- ArrayNotEmpty(),
21
- __metadata("design:type", Array)
22
- ], NodeDto.prototype, "procedureNames", void 0);
@@ -1,4 +0,0 @@
1
- import { ClassConstructor } from 'class-transformer';
2
- export default class DataConverter {
3
- static convert<Type extends Object>(targetClass: ClassConstructor<Type>, dataObject: object): Promise<Type>;
4
- }
@@ -1,9 +0,0 @@
1
- import { plainToClass } from 'class-transformer';
2
- import { validateOrReject } from 'class-validator';
3
- export default class DataConverter {
4
- static async convert(targetClass, dataObject) {
5
- const createdObject = plainToClass(targetClass, dataObject);
6
- await validateOrReject(createdObject);
7
- return createdObject;
8
- }
9
- }
@@ -1,21 +0,0 @@
1
- /// <reference types="node" />
2
- import FileManager from '../../runtime/interfaces/FileManager.js';
3
- import File from '../../runtime/models/File.js';
4
- export default class LocalFileManager implements FileManager {
5
- #private;
6
- constructor(location: string);
7
- getRootLocation(): string;
8
- getAbsoluteLocation(filename: string): string;
9
- getRelativeLocation(filename: string): string;
10
- getType(filename: string): Promise<string>;
11
- getContent(filename: string): Promise<Buffer>;
12
- load(filename: string): Promise<File>;
13
- store(filename: string, content: string): Promise<void>;
14
- copy(source: string, destination: string): Promise<void>;
15
- remove(filename: string): Promise<void>;
16
- getModuleFileNames(): Promise<string[]>;
17
- getSegmentFiles(): Promise<string[]>;
18
- getNodeSegmentFiles(): Promise<string[]>;
19
- getRepositorySegmentFiles(): Promise<string[]>;
20
- getAssetFiles(patterns: string[]): Promise<string[]>;
21
- }
@@ -1,81 +0,0 @@
1
- import fs from 'fs-extra';
2
- import glob from 'glob-promise';
3
- import mime from 'mime-types';
4
- import path from 'path';
5
- import FileNotFound from '../../runtime/errors/FileNotFound.js';
6
- import File from '../../runtime/models/File.js';
7
- export default class LocalFileManager {
8
- #location;
9
- constructor(location) {
10
- this.#location = location;
11
- }
12
- getRootLocation() {
13
- return path.resolve(this.#location);
14
- }
15
- getAbsoluteLocation(filename) {
16
- const location = filename.startsWith('/') ? filename : path.join(this.#location, filename);
17
- return path.resolve(location);
18
- }
19
- getRelativeLocation(filename) {
20
- return path.relative(this.#location, filename);
21
- }
22
- async getType(filename) {
23
- const location = this.getAbsoluteLocation(filename);
24
- return mime.lookup(location) || 'application/octet-stream';
25
- }
26
- async getContent(filename) {
27
- const location = this.getAbsoluteLocation(filename);
28
- if (fs.existsSync(location) === false) {
29
- throw new FileNotFound(filename);
30
- }
31
- return fs.readFile(location);
32
- }
33
- async load(filename) {
34
- const type = await this.getType(filename);
35
- const content = await this.getContent(filename);
36
- return new File(filename, type, content);
37
- }
38
- async store(filename, content) {
39
- const location = this.getAbsoluteLocation(filename);
40
- const directory = path.dirname(location);
41
- await fs.mkdir(directory, { recursive: true });
42
- return fs.writeFile(location, content);
43
- }
44
- async copy(source, destination) {
45
- const sourceLocation = this.getAbsoluteLocation(source);
46
- const destinationLocation = this.getAbsoluteLocation(destination);
47
- return fs.copy(sourceLocation, destinationLocation, { overwrite: true });
48
- }
49
- async remove(filename) {
50
- const location = this.getAbsoluteLocation(filename);
51
- return fs.remove(location);
52
- }
53
- async getModuleFileNames() {
54
- return this.#filterFiles('**/*.js');
55
- }
56
- async getSegmentFiles() {
57
- return this.#filterFiles('**/*.segment.json');
58
- }
59
- async getNodeSegmentFiles() {
60
- return this.#filterFiles('**/*.segment.local.js');
61
- }
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) {
73
- const location = this.getAbsoluteLocation('./');
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');
80
- }
81
- }
@@ -1,4 +0,0 @@
1
- import RuntimeConfiguration from '../configuration/RuntimeConfiguration.js';
2
- export default class RuntimeConfigurationLoader {
3
- static load(filename: string): Promise<RuntimeConfiguration>;
4
- }
@@ -1,11 +0,0 @@
1
- import { readFileSync } from 'fs';
2
- import RuntimeConfiguration from '../configuration/RuntimeConfiguration.js';
3
- import DataConverter from './DataConverter.js';
4
- export default class RuntimeConfigurationLoader {
5
- static async load(filename) {
6
- const plainContents = readFileSync(filename, 'utf-8');
7
- const parsedContents = JSON.parse(plainContents);
8
- const configuration = await DataConverter.convert(RuntimeConfiguration, parsedContents);
9
- return configuration;
10
- }
11
- }
@@ -1,6 +0,0 @@
1
- import Runtime from '../../runtime/Runtime.js';
2
- import RuntimeConfiguration from '../configuration/RuntimeConfiguration.js';
3
- export default class RuntimeConfigurator {
4
- #private;
5
- static configure(configuration: RuntimeConfiguration): Promise<Runtime>;
6
- }
@@ -1,135 +0,0 @@
1
- import CacheBuilder from '../../runtime/caching/CacheBuilder.js';
2
- import LocalGateway from '../../runtime/LocalGateway.js';
3
- import LocalNode from '../../runtime/LocalNode.js';
4
- import LocalRepository from '../../runtime/LocalRepository.js';
5
- import NodeMonitor from '../../runtime/NodeMonitor.js';
6
- import Proxy from '../../runtime/Proxy.js';
7
- import RemoteGateway from '../../runtime/RemoteGateway.js';
8
- import RemoteNode from '../../runtime/RemoteNode.js';
9
- import RemoteRepository from '../../runtime/RemoteRepository.js';
10
- import LocalFileManager from './LocalFileManager.js';
11
- import RuntimeDefaults from '../definitions/RuntimeDefaults.js';
12
- import MissingConfigurationValue from '../errors/MissingConfigurationValue.js';
13
- import UnknownRuntimeMode from '../errors/UnknownRuntimeMode.js';
14
- export default class RuntimeConfigurator {
15
- static async configure(configuration) {
16
- const url = configuration.url ?? RuntimeDefaults.URL;
17
- if (configuration.standalone !== undefined)
18
- return this.#configureStandAlone(url, configuration.standalone);
19
- if (configuration.repository !== undefined)
20
- return this.#configureRepository(url, configuration.repository);
21
- if (configuration.gateway !== undefined)
22
- return this.#configureGateway(url, configuration.gateway);
23
- if (configuration.node !== undefined)
24
- return this.#configureNode(url, configuration.node);
25
- if (configuration.proxy !== undefined)
26
- return this.#configureProxy(url, configuration.proxy);
27
- throw new UnknownRuntimeMode();
28
- }
29
- static async #configureStandAlone(url, configuration) {
30
- const sourceLocation = configuration.source ?? RuntimeDefaults.SOURCE;
31
- const cacheLocation = configuration.cache ?? RuntimeDefaults.CACHE;
32
- const assetFilePatterns = configuration.assets;
33
- await this.#buildCache(sourceLocation, cacheLocation);
34
- const segmentNames = configuration.segments === undefined
35
- ? await this.#getSegmentNames(cacheLocation)
36
- : configuration.segments;
37
- const repository = await this.#buildRepository(url, cacheLocation, assetFilePatterns);
38
- const node = await this.#buildNode(url, segmentNames, repository);
39
- return this.#buildProxy(url, repository, node);
40
- }
41
- static async #configureRepository(url, configuration) {
42
- const sourceLocation = configuration.source ?? RuntimeDefaults.SOURCE;
43
- const cacheLocation = configuration.cache ?? RuntimeDefaults.CACHE;
44
- const assetFilePatterns = configuration.assets ?? [];
45
- await this.#buildCache(sourceLocation, cacheLocation);
46
- return this.#buildRepository(url, cacheLocation, assetFilePatterns);
47
- }
48
- static async #configureGateway(url, configuration) {
49
- return this.#buildGateway(url, configuration.monitor);
50
- }
51
- static async #configureNode(url, configuration) {
52
- const segmentNames = configuration.segments ?? [];
53
- const repository = configuration.repository !== undefined
54
- ? new RemoteRepository(configuration.repository)
55
- : undefined;
56
- const gateway = configuration.gateway !== undefined
57
- ? new RemoteGateway(configuration.gateway)
58
- : undefined;
59
- return this.#buildNode(url, segmentNames, repository, gateway);
60
- }
61
- static async #configureProxy(url, configuration) {
62
- if (configuration.repository === undefined) {
63
- throw new MissingConfigurationValue('proxy.repository');
64
- }
65
- const repository = new RemoteRepository(configuration.repository);
66
- const gateway = configuration.gateway !== undefined
67
- ? new RemoteGateway(configuration.gateway)
68
- : undefined;
69
- const node = configuration.node !== undefined
70
- ? new RemoteNode(configuration.node, [])
71
- : undefined;
72
- const runner = gateway ?? node;
73
- if (runner === undefined) {
74
- throw new MissingConfigurationValue('proxy.gateway or proxy.node');
75
- }
76
- return this.#buildProxy(url, repository, runner);
77
- }
78
- static async #buildCache(sourceLocation, cacheLocation) {
79
- const rootManager = new LocalFileManager('./');
80
- await rootManager.remove(cacheLocation);
81
- await rootManager.copy(sourceLocation, cacheLocation);
82
- const sourceManager = new LocalFileManager(sourceLocation);
83
- const cacheManager = new LocalFileManager(cacheLocation);
84
- const segmentFiles = await rootManager.getSegmentFiles();
85
- const moduleFiles = await sourceManager.getModuleFileNames();
86
- const cacheBuilder = new CacheBuilder(sourceManager, cacheManager);
87
- await cacheBuilder.build(segmentFiles, moduleFiles);
88
- return cacheManager;
89
- }
90
- static async #getSegmentNames(cacheLocation) {
91
- const fileManager = new LocalFileManager(cacheLocation);
92
- const segmentFilenames = await fileManager.getNodeSegmentFiles();
93
- return segmentFilenames.map(filename => this.#extractSegmentName(filename));
94
- }
95
- static #extractSegmentName(filename) {
96
- const name = filename.split('/').pop() ?? '';
97
- const endIndex = name.indexOf('.segment');
98
- return name.substring(0, endIndex);
99
- }
100
- static async #buildRepository(url, cacheLocation, assetFilePatterns) {
101
- const fileManager = new LocalFileManager(cacheLocation);
102
- const assetFiles = assetFilePatterns !== undefined
103
- ? await fileManager.getAssetFiles(assetFilePatterns)
104
- : [];
105
- const repository = new LocalRepository(fileManager, assetFiles, url);
106
- const segmentFilenames = await fileManager.getRepositorySegmentFiles();
107
- const segmentNames = segmentFilenames.map(filename => this.#extractSegmentName(filename));
108
- for (const name of segmentNames) {
109
- await repository.loadSegment(name);
110
- }
111
- return repository;
112
- }
113
- static async #buildGateway(url, monitorInterval) {
114
- const gateway = new LocalGateway(url);
115
- const monitor = new NodeMonitor(gateway, monitorInterval);
116
- monitor.start();
117
- return gateway;
118
- }
119
- static async #buildNode(url, segmentNames, repository, gateway) {
120
- const node = new LocalNode(url);
121
- if (repository !== undefined) {
122
- await node.setRepository(repository, segmentNames);
123
- }
124
- for (const segmentName of segmentNames) {
125
- await node.loadSegment(segmentName);
126
- }
127
- if (gateway !== undefined) {
128
- node.setGateway(gateway);
129
- }
130
- return node;
131
- }
132
- static async #buildProxy(url, repository, runner) {
133
- return new Proxy(repository, runner, url);
134
- }
135
- }
@@ -1,4 +0,0 @@
1
- import ServerOptions from '../configuration/ServerOptions.js';
2
- export default class ServerOptionsReader {
3
- static read(): Promise<ServerOptions>;
4
- }
@@ -1,10 +0,0 @@
1
- import yargs from 'yargs';
2
- import ServerOptions from '../configuration/ServerOptions.js';
3
- import DataConverter from './DataConverter.js';
4
- export default class ServerOptionsReader {
5
- static async read() {
6
- const args = yargs(process.argv).argv;
7
- const options = await DataConverter.convert(ServerOptions, args);
8
- return options;
9
- }
10
- }
package/dist/server.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import ModuleImporter from './runtime/types/ModuleImporter.js';
2
- import JitarServer from './server/JitarServer.js';
3
- export declare function startServer(moduleImporter: ModuleImporter): Promise<JitarServer>;
package/dist/server.js DELETED
@@ -1,8 +0,0 @@
1
- import ModuleLoader from './runtime/utils/ModuleLoader.js';
2
- import JitarServer from './server/JitarServer.js';
3
- export async function startServer(moduleImporter) {
4
- ModuleLoader.setImporter(moduleImporter);
5
- const server = new JitarServer();
6
- await server.start();
7
- return server;
8
- }