jitar 0.1.2 → 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.
- package/dist/client.d.ts +1 -0
- package/dist/client.js +12 -0
- package/dist/lib.d.ts +27 -1
- package/dist/lib.js +24 -1
- package/dist/runtime/serialization/ArrayBufferSerializer.d.ts +10 -0
- package/dist/runtime/serialization/ArrayBufferSerializer.js +54 -0
- package/dist/runtime/serialization/DateSerializer.d.ts +9 -0
- package/dist/runtime/serialization/DateSerializer.js +21 -0
- package/dist/runtime/serialization/ValueSerializer.d.ts +1 -0
- package/dist/runtime/serialization/ValueSerializer.js +24 -1
- package/dist/runtime/serialization/types/SerializedArrayBuffer.d.ts +6 -0
- package/dist/runtime/serialization/types/SerializedArrayBuffer.js +1 -0
- package/dist/runtime/serialization/types/SerializedDate.d.ts +5 -0
- package/dist/runtime/serialization/types/SerializedDate.js +1 -0
- package/dist/runtime/serialization/types/TypedArray.d.ts +2 -0
- package/dist/runtime/serialization/types/TypedArray.js +1 -0
- package/package.json +5 -20
- package/dist/server/JitarServer.d.ts +0 -8
- package/dist/server/JitarServer.js +0 -109
- package/dist/server/configuration/GatewayConfiguration.d.ts +0 -3
- package/dist/server/configuration/GatewayConfiguration.js +0 -18
- package/dist/server/configuration/NodeConfiguration.d.ts +0 -5
- package/dist/server/configuration/NodeConfiguration.js +0 -28
- package/dist/server/configuration/ProxyConfiguration.d.ts +0 -5
- package/dist/server/configuration/ProxyConfiguration.js +0 -29
- package/dist/server/configuration/RepositoryConfiguration.d.ts +0 -6
- package/dist/server/configuration/RepositoryConfiguration.js +0 -36
- package/dist/server/configuration/RuntimeConfiguration.d.ts +0 -13
- package/dist/server/configuration/RuntimeConfiguration.js +0 -48
- package/dist/server/configuration/ServerOptions.d.ts +0 -4
- package/dist/server/configuration/ServerOptions.js +0 -25
- package/dist/server/configuration/StandaloneConfiguration.d.ts +0 -7
- package/dist/server/configuration/StandaloneConfiguration.js +0 -42
- package/dist/server/controllers/AssetsController.d.ts +0 -8
- package/dist/server/controllers/AssetsController.js +0 -50
- package/dist/server/controllers/HealthController.d.ts +0 -10
- package/dist/server/controllers/HealthController.js +0 -47
- package/dist/server/controllers/JitarController.d.ts +0 -4
- package/dist/server/controllers/JitarController.js +0 -26
- package/dist/server/controllers/ModulesController.d.ts +0 -10
- package/dist/server/controllers/ModulesController.js +0 -68
- package/dist/server/controllers/NodesController.d.ts +0 -9
- package/dist/server/controllers/NodesController.js +0 -60
- package/dist/server/controllers/ProceduresController.d.ts +0 -10
- package/dist/server/controllers/ProceduresController.js +0 -35
- package/dist/server/controllers/ProxyController.d.ts +0 -7
- package/dist/server/controllers/ProxyController.js +0 -37
- package/dist/server/controllers/RPCController.d.ts +0 -9
- package/dist/server/controllers/RPCController.js +0 -129
- package/dist/server/definitions/RuntimeDefaults.d.ts +0 -7
- package/dist/server/definitions/RuntimeDefaults.js +0 -8
- package/dist/server/errors/MissingConfigurationValue.d.ts +0 -3
- package/dist/server/errors/MissingConfigurationValue.js +0 -5
- package/dist/server/errors/RuntimeNotAvaiable.d.ts +0 -3
- package/dist/server/errors/RuntimeNotAvaiable.js +0 -5
- package/dist/server/errors/UnknownRuntimeMode.d.ts +0 -3
- package/dist/server/errors/UnknownRuntimeMode.js +0 -5
- package/dist/server/models/HealthDto.d.ts +0 -4
- package/dist/server/models/HealthDto.js +0 -22
- package/dist/server/models/NodeDto.d.ts +0 -4
- package/dist/server/models/NodeDto.js +0 -22
- package/dist/server/utils/DataConverter.d.ts +0 -4
- package/dist/server/utils/DataConverter.js +0 -9
- package/dist/server/utils/LocalFileManager.d.ts +0 -21
- package/dist/server/utils/LocalFileManager.js +0 -81
- package/dist/server/utils/RuntimeConfigurationLoader.d.ts +0 -4
- package/dist/server/utils/RuntimeConfigurationLoader.js +0 -11
- package/dist/server/utils/RuntimeConfigurator.d.ts +0 -6
- package/dist/server/utils/RuntimeConfigurator.js +0 -135
- package/dist/server/utils/ServerOptionsReader.d.ts +0 -4
- package/dist/server/utils/ServerOptionsReader.js +0 -10
- package/dist/server.d.ts +0 -3
- package/dist/server.js +0 -8
|
@@ -1,129 +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 { Controller, Get, Post } from '@overnightjs/core';
|
|
11
|
-
import { Logger } from 'tslog';
|
|
12
|
-
import Version from '../../core/Version.js';
|
|
13
|
-
import ValueSerializer from '../../runtime/serialization/ValueSerializer.js';
|
|
14
|
-
const RPC_PARAMETERS = ['version', 'serialize'];
|
|
15
|
-
let RPCController = class RPCController {
|
|
16
|
-
#runtime;
|
|
17
|
-
#logger;
|
|
18
|
-
#useSerializer;
|
|
19
|
-
constructor(runtime, logger, useSerializer) {
|
|
20
|
-
this.#runtime = runtime;
|
|
21
|
-
this.#logger = logger;
|
|
22
|
-
this.#useSerializer = useSerializer;
|
|
23
|
-
this.#showProcedureInfo();
|
|
24
|
-
}
|
|
25
|
-
#showProcedureInfo() {
|
|
26
|
-
const procedureNames = this.#runtime.getProcedureNames();
|
|
27
|
-
if (procedureNames.length === 0) {
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
procedureNames.sort();
|
|
31
|
-
this.#logger.info('Registered RPC entries', procedureNames);
|
|
32
|
-
}
|
|
33
|
-
async runGet(request, response) {
|
|
34
|
-
const fqn = this.#extractFqn(request);
|
|
35
|
-
const version = this.#extractVersion(request);
|
|
36
|
-
const args = this.#extractQueryArguments(request);
|
|
37
|
-
const serialize = this.#extractSerialize(request);
|
|
38
|
-
return this.#run(fqn, version, args, response, serialize);
|
|
39
|
-
}
|
|
40
|
-
async runPost(request, response) {
|
|
41
|
-
const fqn = this.#extractFqn(request);
|
|
42
|
-
const version = this.#extractVersion(request);
|
|
43
|
-
const args = await this.#extractBodyArguments(request);
|
|
44
|
-
const serialize = this.#extractSerialize(request);
|
|
45
|
-
return this.#run(fqn, version, args, response, serialize);
|
|
46
|
-
}
|
|
47
|
-
#extractFqn(request) {
|
|
48
|
-
return request.path.substring(1);
|
|
49
|
-
}
|
|
50
|
-
#extractVersion(request) {
|
|
51
|
-
return request.query.version !== undefined
|
|
52
|
-
? Version.parse(request.query.version.toString())
|
|
53
|
-
: Version.DEFAULT;
|
|
54
|
-
}
|
|
55
|
-
#extractSerialize(request) {
|
|
56
|
-
return request.query.serialize === 'true';
|
|
57
|
-
}
|
|
58
|
-
#extractQueryArguments(request) {
|
|
59
|
-
const args = new Map();
|
|
60
|
-
for (const [key, value] of Object.entries(request.query)) {
|
|
61
|
-
if (RPC_PARAMETERS.includes(key)) {
|
|
62
|
-
continue;
|
|
63
|
-
}
|
|
64
|
-
args.set(key, value);
|
|
65
|
-
}
|
|
66
|
-
return args;
|
|
67
|
-
}
|
|
68
|
-
async #extractBodyArguments(request) {
|
|
69
|
-
const args = this.#useSerializer
|
|
70
|
-
? await ValueSerializer.deserialize(request.body)
|
|
71
|
-
: request.body;
|
|
72
|
-
return new Map(Object.entries(args));
|
|
73
|
-
}
|
|
74
|
-
async #run(fqn, version, args, response, serialize) {
|
|
75
|
-
if (this.#runtime.hasProcedure(fqn) === false) {
|
|
76
|
-
return response.status(404).send(`Procedure not found -> ${fqn}`);
|
|
77
|
-
}
|
|
78
|
-
try {
|
|
79
|
-
const result = await this.#runtime.run(fqn, version, args);
|
|
80
|
-
this.#logger.info(`Ran procedure -> ${fqn} (${version.toString()})`);
|
|
81
|
-
return this.#createResultResponse(result, response, this.#useSerializer && serialize);
|
|
82
|
-
}
|
|
83
|
-
catch (error) {
|
|
84
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
85
|
-
const errorData = serialize ? error : message;
|
|
86
|
-
this.#logger.error(`Failed to run procedure -> ${fqn} (${version.toString()}) | ${message}`);
|
|
87
|
-
return this.#createErrorResponse(errorData, response, serialize);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
#createResultResponse(result, response, serialize) {
|
|
91
|
-
const content = this.#createResponseContent(result, serialize);
|
|
92
|
-
const contentType = this.#createResponseContentType(content);
|
|
93
|
-
response.setHeader('Content-Type', contentType);
|
|
94
|
-
return response.status(200).send(content);
|
|
95
|
-
}
|
|
96
|
-
#createErrorResponse(errorData, response, serialize) {
|
|
97
|
-
const content = this.#createResponseContent(errorData, serialize);
|
|
98
|
-
const contentType = this.#createResponseContentType(content);
|
|
99
|
-
response.setHeader('Content-Type', contentType);
|
|
100
|
-
return response.status(500).send(content);
|
|
101
|
-
}
|
|
102
|
-
#createResponseContent(data, serialize) {
|
|
103
|
-
return serialize
|
|
104
|
-
? ValueSerializer.serialize(data)
|
|
105
|
-
: data;
|
|
106
|
-
}
|
|
107
|
-
#createResponseContentType(content) {
|
|
108
|
-
return typeof content === 'object'
|
|
109
|
-
? 'application/json'
|
|
110
|
-
: 'text/plain';
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
__decorate([
|
|
114
|
-
Get('*'),
|
|
115
|
-
__metadata("design:type", Function),
|
|
116
|
-
__metadata("design:paramtypes", [Object, Object]),
|
|
117
|
-
__metadata("design:returntype", Promise)
|
|
118
|
-
], RPCController.prototype, "runGet", null);
|
|
119
|
-
__decorate([
|
|
120
|
-
Post('*'),
|
|
121
|
-
__metadata("design:type", Function),
|
|
122
|
-
__metadata("design:paramtypes", [Object, Object]),
|
|
123
|
-
__metadata("design:returntype", Promise)
|
|
124
|
-
], RPCController.prototype, "runPost", null);
|
|
125
|
-
RPCController = __decorate([
|
|
126
|
-
Controller('rpc'),
|
|
127
|
-
__metadata("design:paramtypes", [Object, Logger, Boolean])
|
|
128
|
-
], RPCController);
|
|
129
|
-
export default RPCController;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
var RuntimeDefaults;
|
|
2
|
-
(function (RuntimeDefaults) {
|
|
3
|
-
RuntimeDefaults["URL"] = "http://localhost:3000";
|
|
4
|
-
RuntimeDefaults["SOURCE"] = "./src";
|
|
5
|
-
RuntimeDefaults["CACHE"] = "./cache";
|
|
6
|
-
RuntimeDefaults["INDEX"] = "index.html";
|
|
7
|
-
})(RuntimeDefaults || (RuntimeDefaults = {}));
|
|
8
|
-
export default RuntimeDefaults;
|
|
@@ -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,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,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,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,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,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
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
|
-
}
|