jitar 0.1.1 → 0.1.3

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 (183) hide show
  1. package/dist/client.d.ts +1 -0
  2. package/dist/client.js +12 -0
  3. package/dist/core/Implementation.js +7 -0
  4. package/dist/core/errors/UnknownParameter.d.ts +3 -0
  5. package/dist/core/errors/UnknownParameter.js +6 -0
  6. package/dist/runtime/LocalRepository.d.ts +1 -1
  7. package/dist/runtime/LocalRepository.js +13 -4
  8. package/dist/server/configuration/RepositoryConfiguration.d.ts +1 -0
  9. package/dist/server/configuration/RepositoryConfiguration.js +7 -1
  10. package/dist/server/configuration/StandaloneConfiguration.d.ts +1 -0
  11. package/dist/server/configuration/StandaloneConfiguration.js +6 -0
  12. package/dist/server/controllers/RPCController.js +20 -3
  13. package/dist/server/utils/LocalFileManager.d.ts +1 -0
  14. package/dist/server/utils/LocalFileManager.js +19 -11
  15. package/dist/server/utils/RuntimeConfigurator.js +9 -4
  16. package/package.json +6 -2
  17. package/.eslintignore +0 -3
  18. package/.eslintrc +0 -16
  19. package/jest.config.js +0 -20
  20. package/src/client.ts +0 -18
  21. package/src/core/ErrorManager.ts +0 -18
  22. package/src/core/Implementation.ts +0 -53
  23. package/src/core/Procedure.ts +0 -98
  24. package/src/core/Segment.ts +0 -62
  25. package/src/core/SegmentBuilder.ts +0 -55
  26. package/src/core/Version.ts +0 -68
  27. package/src/core/definitions/AccessLevel.ts +0 -3
  28. package/src/core/errors/ImplementationNotFound.ts +0 -12
  29. package/src/core/errors/InvalidVersionNumber.ts +0 -12
  30. package/src/core/errors/MissingParameterValue.ts +0 -12
  31. package/src/core/errors/NotImplemented.ts +0 -12
  32. package/src/core/errors/ProcedureNotFound.ts +0 -12
  33. package/src/core/interfaces/Runner.ts +0 -7
  34. package/src/core/reflection/ParameterParser.ts +0 -74
  35. package/src/core/reflection/ReflectionHelper.ts +0 -118
  36. package/src/core/reflection/models/ReflectionField.ts +0 -22
  37. package/src/core/reflection/models/ReflectionParameter.ts +0 -18
  38. package/src/core/types/Component.ts +0 -8
  39. package/src/core/types/FlexObject.ts +0 -4
  40. package/src/core/types/Module.ts +0 -6
  41. package/src/core/types/SegmentImplementation.ts +0 -9
  42. package/src/core/types/SegmentModule.ts +0 -9
  43. package/src/core/types/SegmentProcedure.ts +0 -11
  44. package/src/core/utils/FqnBuilder.ts +0 -11
  45. package/src/hooks.ts +0 -2
  46. package/src/lib.ts +0 -7
  47. package/src/runtime/ClientId.ts +0 -18
  48. package/src/runtime/Gateway.ts +0 -18
  49. package/src/runtime/LocalGateway.ts +0 -93
  50. package/src/runtime/LocalNode.ts +0 -130
  51. package/src/runtime/LocalRepository.ts +0 -154
  52. package/src/runtime/Node.ts +0 -15
  53. package/src/runtime/NodeBalancer.ts +0 -61
  54. package/src/runtime/NodeMonitor.ts +0 -63
  55. package/src/runtime/Proxy.ts +0 -60
  56. package/src/runtime/Remote.ts +0 -157
  57. package/src/runtime/RemoteGateway.ts +0 -40
  58. package/src/runtime/RemoteNode.ts +0 -49
  59. package/src/runtime/RemoteRepository.ts +0 -60
  60. package/src/runtime/Repository.ts +0 -20
  61. package/src/runtime/Runtime.ts +0 -47
  62. package/src/runtime/caching/CacheBuilder.ts +0 -424
  63. package/src/runtime/caching/ImportRewriter.ts +0 -76
  64. package/src/runtime/caching/RemoteBuilder.ts +0 -51
  65. package/src/runtime/caching/SourceAppender.ts +0 -57
  66. package/src/runtime/caching/definitions/Keywords.ts +0 -3
  67. package/src/runtime/caching/errors/InvalidSegmentFilename.ts +0 -8
  68. package/src/runtime/caching/errors/MissingModuleExport.ts +0 -8
  69. package/src/runtime/caching/errors/SegmentFileNotLoaded.ts +0 -8
  70. package/src/runtime/caching/errors/SegmentModuleNotLoaded.ts +0 -8
  71. package/src/runtime/caching/models/ApplicationModule.ts +0 -30
  72. package/src/runtime/caching/models/Implementation.ts +0 -41
  73. package/src/runtime/caching/models/Procedure.ts +0 -26
  74. package/src/runtime/caching/models/Segment.ts +0 -28
  75. package/src/runtime/caching/models/SegmentModule.ts +0 -26
  76. package/src/runtime/caching/types/SegmentFile.ts +0 -6
  77. package/src/runtime/caching/types/SegmentImportProperties.ts +0 -9
  78. package/src/runtime/caching/types/SegmentImports.ts +0 -6
  79. package/src/runtime/errors/ClientNotFound.ts +0 -12
  80. package/src/runtime/errors/FileNotFound.ts +0 -12
  81. package/src/runtime/errors/InvalidClientId.ts +0 -12
  82. package/src/runtime/errors/InvalidJitarHooks.ts +0 -12
  83. package/src/runtime/errors/InvalidSegmentFile.ts +0 -12
  84. package/src/runtime/errors/ModuleNotLoaded.ts +0 -12
  85. package/src/runtime/errors/NoNodeAvailable.ts +0 -12
  86. package/src/runtime/errors/RepositoryNotAvaiable.ts +0 -12
  87. package/src/runtime/errors/RuntimeNotAvailable.ts +0 -12
  88. package/src/runtime/errors/SegmentNotFound.ts +0 -12
  89. package/src/runtime/hooks/dependencies.ts +0 -19
  90. package/src/runtime/hooks/runtime.ts +0 -25
  91. package/src/runtime/interfaces/FileManager.ts +0 -19
  92. package/src/runtime/interfaces/HealthCheck.ts +0 -5
  93. package/src/runtime/interfaces/ProcedureContainer.ts +0 -9
  94. package/src/runtime/models/File.ts +0 -22
  95. package/src/runtime/serialization/ArraySerializer.ts +0 -27
  96. package/src/runtime/serialization/ClassSerializer.ts +0 -133
  97. package/src/runtime/serialization/MapSerializer.ts +0 -60
  98. package/src/runtime/serialization/ObjectSerializer.ts +0 -42
  99. package/src/runtime/serialization/SetSerializer.ts +0 -42
  100. package/src/runtime/serialization/ValueSerializer.ts +0 -81
  101. package/src/runtime/serialization/errors/ClassNotFound.ts +0 -12
  102. package/src/runtime/serialization/errors/InvalidClass.ts +0 -12
  103. package/src/runtime/serialization/errors/InvalidPropertyType.ts +0 -12
  104. package/src/runtime/serialization/interfaces/Serializer.ts +0 -10
  105. package/src/runtime/serialization/types/SerializableObject.ts +0 -6
  106. package/src/runtime/serialization/types/Serialized.ts +0 -8
  107. package/src/runtime/serialization/types/SerializedClass.ts +0 -13
  108. package/src/runtime/serialization/types/SerializedMap.ts +0 -13
  109. package/src/runtime/serialization/types/SerializedObject.ts +0 -4
  110. package/src/runtime/serialization/types/SerializedSet.ts +0 -9
  111. package/src/runtime/types/JitarHooks.ts +0 -10
  112. package/src/runtime/types/ModuleImporter.ts +0 -6
  113. package/src/runtime/utils/ModuleAnalyser.ts +0 -60
  114. package/src/runtime/utils/ModuleLoader.ts +0 -51
  115. package/src/runtime/utils/UrlRewriter.ts +0 -59
  116. package/src/server/JitarServer.ts +0 -161
  117. package/src/server/configuration/GatewayConfiguration.ts +0 -9
  118. package/src/server/configuration/NodeConfiguration.ts +0 -15
  119. package/src/server/configuration/ProxyConfiguration.ts +0 -16
  120. package/src/server/configuration/RepositoryConfiguration.ts +0 -17
  121. package/src/server/configuration/RuntimeConfiguration.ts +0 -30
  122. package/src/server/configuration/ServerOptions.ts +0 -14
  123. package/src/server/configuration/StandaloneConfiguration.ts +0 -21
  124. package/src/server/controllers/AssetsController.ts +0 -59
  125. package/src/server/controllers/HealthController.ts +0 -41
  126. package/src/server/controllers/JitarController.ts +0 -18
  127. package/src/server/controllers/ModulesController.ts +0 -77
  128. package/src/server/controllers/NodesController.ts +0 -58
  129. package/src/server/controllers/ProceduresController.ts +0 -31
  130. package/src/server/controllers/ProxyController.ts +0 -38
  131. package/src/server/controllers/RPCController.ts +0 -173
  132. package/src/server/definitions/RuntimeDefaults.ts +0 -10
  133. package/src/server/errors/MissingConfigurationValue.ts +0 -8
  134. package/src/server/errors/RuntimeNotAvaiable.ts +0 -8
  135. package/src/server/errors/UnknownRuntimeMode.ts +0 -8
  136. package/src/server/models/HealthDto.ts +0 -11
  137. package/src/server/models/NodeDto.ts +0 -11
  138. package/src/server/utils/DataConverter.ts +0 -15
  139. package/src/server/utils/LocalFileManager.ts +0 -122
  140. package/src/server/utils/RuntimeConfigurationLoader.ts +0 -19
  141. package/src/server/utils/RuntimeConfigurator.ts +0 -207
  142. package/src/server/utils/ServerOptionsReader.ts +0 -17
  143. package/src/server.ts +0 -16
  144. package/test/_fixtures/core/Implementation.fixture.ts +0 -33
  145. package/test/_fixtures/core/Procedure.fixture.ts +0 -33
  146. package/test/_fixtures/core/Segment.fixture.ts +0 -36
  147. package/test/_fixtures/core/SegmentBuilder.fixture.ts +0 -45
  148. package/test/_fixtures/core/Version.fixture.ts +0 -18
  149. package/test/_fixtures/core/reflection/ReflectionHelper.fixture.ts +0 -56
  150. package/test/_fixtures/runtime/LocalGateway.fixture.ts +0 -24
  151. package/test/_fixtures/runtime/LocalNode.fixture.ts +0 -16
  152. package/test/_fixtures/runtime/LocalRepository.fixture.ts +0 -73
  153. package/test/_fixtures/runtime/NodeBalancer.fixture.ts +0 -19
  154. package/test/_fixtures/runtime/NodeMonitor.fixture.ts +0 -34
  155. package/test/_fixtures/runtime/RemoteNode.fixture.ts +0 -8
  156. package/test/_fixtures/runtime/caching/ImportRewriter.fixture.ts +0 -81
  157. package/test/_fixtures/runtime/caching/RemoteBuilder.fixture.ts +0 -50
  158. package/test/_fixtures/runtime/caching/SourceAppender.fixture.ts +0 -35
  159. package/test/_fixtures/runtime/segments.ts +0 -78
  160. package/test/_fixtures/runtime/serialization/ValueSerializer.fixture.ts +0 -134
  161. package/test/_fixtures/runtime/utils/ModuleAnaliser.fixture.ts +0 -26
  162. package/test/core/Implementation.spec.ts +0 -89
  163. package/test/core/Procedure.spec.ts +0 -108
  164. package/test/core/Segment.spec.ts +0 -74
  165. package/test/core/SegmentBuilder.spec.ts +0 -39
  166. package/test/core/Version.spec.ts +0 -103
  167. package/test/core/errors/ErrorManager.spec.ts +0 -32
  168. package/test/core/reflection/ReflectionHelper.spec.ts +0 -128
  169. package/test/core/utils/FqnBuilder.spec.ts +0 -22
  170. package/test/runtime/ClientId.spec.ts +0 -43
  171. package/test/runtime/LocalGateway.spec.ts +0 -40
  172. package/test/runtime/LocalNode.spec.ts +0 -87
  173. package/test/runtime/LocalRepository.spec.ts +0 -50
  174. package/test/runtime/NodeBalancer.spec.ts +0 -39
  175. package/test/runtime/NodeMonitor.spec.ts +0 -31
  176. package/test/runtime/RemoteNode.spec.ts +0 -43
  177. package/test/runtime/caching/ImportRewriter.spec.ts +0 -68
  178. package/test/runtime/caching/RemoteBuilder.spec.ts +0 -21
  179. package/test/runtime/caching/SourceAppender.spec.ts +0 -31
  180. package/test/runtime/serialization/ValueSerializer.spec.ts +0 -203
  181. package/test/runtime/utils/ModuleAnalyser.spec.ts +0 -54
  182. package/test/runtime/utils/UrlRewriter.spec.ts +0 -57
  183. package/tsconfig.json +0 -23
@@ -1,133 +0,0 @@
1
-
2
- import ReflectionHelper from '../../core/reflection/ReflectionHelper.js';
3
- import Component from '../../core/types/Component.js';
4
- import FlexObject from '../../core/types/FlexObject.js';
5
- import Module from '../../core/types/Module.js';
6
-
7
- import ModuleLoader from '../utils/ModuleLoader.js';
8
- import ClassNotFound from './errors/ClassNotFound.js';
9
- import InvalidClass from './errors/InvalidClass.js';
10
- import InvalidPropertyType from './errors/InvalidPropertyType.js';
11
-
12
- import Serializer from './interfaces/Serializer.js';
13
-
14
- import SerializableObject from './types/SerializableObject.js';
15
- import SerializedClass from './types/SerializedClass.js';
16
-
17
- import ValueSerializer from './ValueSerializer.js';
18
-
19
- class ClassSerializer implements Serializer
20
- {
21
- serialize(object: SerializableObject): SerializedClass
22
- {
23
- const clazz = ReflectionHelper.getObjectClass(object);
24
- const classFields = ReflectionHelper.getObjectFields(object);
25
- const constructParameters = ReflectionHelper.getConstructorParameters(clazz);
26
-
27
- const name = clazz.name;
28
- const source = (clazz as Component).source || null;
29
- const args: unknown[] = [];
30
- const fields: FlexObject = {};
31
-
32
- for (const parameter of constructParameters)
33
- {
34
- const objectValue = object[parameter.name];
35
- const classFieldIndex = classFields.findIndex(field => field.name === parameter.name);
36
-
37
- if (classFieldIndex !== -1)
38
- {
39
- classFields.splice(classFieldIndex, 1);
40
- }
41
-
42
- args.push(ValueSerializer.serialize(objectValue));
43
- }
44
-
45
- for (const field of classFields)
46
- {
47
- if (field.canGetAndSet === false)
48
- {
49
- // Fields that can't be accessed or updated are ignored.
50
- // This is to prevent the serialization of fields that are only used for internal purposes.
51
-
52
- continue;
53
- }
54
-
55
- const objectValue = object[field.name];
56
-
57
- fields[field.name] = ValueSerializer.serialize(objectValue);
58
- }
59
-
60
- return { serialized: true, name: name, source: source, args: args, fields: fields };
61
- }
62
-
63
- async deserialize(object: SerializedClass): Promise<SerializableObject>
64
- {
65
- this.#validateSerializedClass(object);
66
-
67
- const clazz = await this.#loadClass(object.source, object.name);
68
-
69
- if (clazz === undefined)
70
- {
71
- throw new ClassNotFound(object.name);
72
- }
73
-
74
- if ((clazz instanceof Function) === false)
75
- {
76
- throw new InvalidClass(object.name);
77
- }
78
-
79
- const args = await Promise.all(object.args.map(async (value) => await ValueSerializer.deserialize(value)));
80
-
81
- const instance = ReflectionHelper.createInstance(clazz as Function, args) as SerializableObject;
82
-
83
- for (const name in object.fields)
84
- {
85
- const fieldValue = object.fields[name];
86
-
87
- instance[name] = await ValueSerializer.deserialize(fieldValue);
88
- }
89
-
90
- return instance;
91
- }
92
-
93
- #validateSerializedClass(object: SerializedClass): void
94
- {
95
- if (typeof object.name !== 'string')
96
- {
97
- throw new InvalidPropertyType('class', 'name', 'string');
98
- }
99
-
100
- if (object.source !== null && typeof object.source !== 'string')
101
- {
102
- throw new InvalidPropertyType(`class '${object.name}'`, 'source', 'string | null');
103
- }
104
-
105
- if ((object.args instanceof Array) === false)
106
- {
107
- throw new InvalidPropertyType(`class '${object.name}'`, 'args', 'Array');
108
- }
109
-
110
- if ((object.fields instanceof Object) === false)
111
- {
112
- throw new InvalidPropertyType(`class '${object.name}'`, 'fields', 'Object');
113
- }
114
- }
115
-
116
- async #loadClass(source: string | null, name: string): Promise<unknown>
117
- {
118
- if (source === null)
119
- {
120
- const system: unknown = typeof window !== 'undefined' ? window : global;
121
-
122
- return (system as Module)[name];
123
- }
124
-
125
- const module = await ModuleLoader.load(source);
126
-
127
- return module[name] ?? module.default;
128
- }
129
- }
130
-
131
- const instance = new ClassSerializer();
132
-
133
- export default instance;
@@ -1,60 +0,0 @@
1
-
2
- import InvalidPropertyType from './errors/InvalidPropertyType.js';
3
- import Serializer from './interfaces/Serializer.js';
4
- import SerializedMap from './types/SerializedMap.js';
5
-
6
- import ValueSerializer from './ValueSerializer.js';
7
-
8
- class MapSerializer implements Serializer
9
- {
10
- serialize(map: Map<unknown, unknown>): SerializedMap
11
- {
12
- const keys: unknown[] = [];
13
- const values: unknown[] = [];
14
-
15
- for (const [key, value] of map)
16
- {
17
- keys.push(ValueSerializer.serialize(key));
18
- values.push(ValueSerializer.serialize(value));
19
- }
20
-
21
- return { serialized: true, name: 'Map', entries: { keys: keys, values: values } };
22
- }
23
-
24
- async deserialize(object: SerializedMap): Promise<Map<unknown, unknown>>
25
- {
26
- this.#validateSerializedMap(object);
27
-
28
- const keys = object.entries.keys;
29
- const values = object.entries.values;
30
-
31
- const result = new Map();
32
-
33
- for (let index = 0; index < keys.length; index++)
34
- {
35
- const key = await ValueSerializer.deserialize(keys[index]);
36
- const value = await ValueSerializer.deserialize(values[index]);
37
-
38
- result.set(key, value);
39
- }
40
-
41
- return result;
42
- }
43
-
44
- #validateSerializedMap(object: SerializedMap): void
45
- {
46
- if ((object.entries?.keys instanceof Array) === false)
47
- {
48
- throw new InvalidPropertyType('map', 'entries.keys', 'Array');
49
- }
50
-
51
- if ((object.entries?.values instanceof Array) === false)
52
- {
53
- throw new InvalidPropertyType('map', 'entries.values', 'Array');
54
- }
55
- }
56
- }
57
-
58
- const instance = new MapSerializer();
59
-
60
- export default instance;
@@ -1,42 +0,0 @@
1
-
2
- import Serializer from './interfaces/Serializer.js';
3
-
4
- import SerializableObject from './types/SerializableObject.js';
5
- import SerializedObject from './types/SerializedObject.js';
6
-
7
- import ValueSerializer from './ValueSerializer.js';
8
-
9
- class ObjectSerializer implements Serializer
10
- {
11
- serialize(object: SerializableObject): SerializedObject
12
- {
13
- const result: SerializedObject = {};
14
-
15
- for (const key in object)
16
- {
17
- const value = object[key];
18
-
19
- result[key] = ValueSerializer.serialize(value);
20
- }
21
-
22
- return result;
23
- }
24
-
25
- async deserialize(object: SerializedObject): Promise<SerializableObject>
26
- {
27
- const result: SerializableObject = {};
28
-
29
- for (const key in object)
30
- {
31
- const value = object[key];
32
-
33
- result[key] = await ValueSerializer.deserialize(value);
34
- }
35
-
36
- return result;
37
- }
38
- }
39
-
40
- const instance = new ObjectSerializer();
41
-
42
- export default instance;
@@ -1,42 +0,0 @@
1
-
2
- import InvalidPropertyType from './errors/InvalidPropertyType.js';
3
- import Serializer from './interfaces/Serializer.js';
4
- import SerializedSet from './types/SerializedSet.js';
5
-
6
- import ValueSerializer from './ValueSerializer.js';
7
-
8
- class SetSerializer implements Serializer
9
- {
10
- serialize(set: Set<unknown>): SerializedSet
11
- {
12
- const values: unknown[] = [];
13
-
14
- for (const value of set.values())
15
- {
16
- values.push(ValueSerializer.serialize(value));
17
- }
18
-
19
- return { serialized: true, name: 'Set', values: values };
20
- }
21
-
22
- async deserialize(object: SerializedSet): Promise<Set<unknown>>
23
- {
24
- this.#validateSerializedSet(object);
25
-
26
- const values = await Promise.all(object.values.map(async (value: unknown) => await ValueSerializer.deserialize(value)));
27
-
28
- return new Set([...values]);
29
- }
30
-
31
- #validateSerializedSet(object: SerializedSet): void
32
- {
33
- if ((object.values instanceof Array) === false)
34
- {
35
- throw new InvalidPropertyType('set', 'values', 'Array');
36
- }
37
- }
38
- }
39
-
40
- const instance = new SetSerializer();
41
-
42
- export default instance;
@@ -1,81 +0,0 @@
1
-
2
- import ReflectionHelper from '../../core/reflection/ReflectionHelper.js';
3
-
4
- import ArraySerializer from './ArraySerializer.js';
5
- import ClassSerializer from './ClassSerializer.js';
6
- import Serializer from './interfaces/Serializer.js';
7
- import MapSerializer from './MapSerializer.js';
8
- import ObjectSerializer from './ObjectSerializer.js';
9
- import SetSerializer from './SetSerializer.js';
10
-
11
- import SerializableObject from './types/SerializableObject.js';
12
- import Serialized from './types/Serialized.js';
13
- import SerializedClass from './types/SerializedClass.js';
14
- import SerializedMap from './types/SerializedMap.js';
15
- import SerializedObject from './types/SerializedObject.js';
16
- import SerializedSet from './types/SerializedSet.js';
17
-
18
- class ValueSerializer implements Serializer
19
- {
20
- serialize(value: unknown): unknown
21
- {
22
- if (value instanceof Array)
23
- {
24
- return ArraySerializer.serialize(value);
25
- }
26
- else if (value instanceof Map)
27
- {
28
- return MapSerializer.serialize(value);
29
- }
30
- else if (value instanceof Set)
31
- {
32
- return SetSerializer.serialize(value);
33
- }
34
- else if (value instanceof Error)
35
- {
36
- // The error class is like Array, Map and Set in that it's a native class.
37
- // Native classes cannot be defined as a class object by the reflection helper.
38
- // Unlike Array, Map and Set, the error class can be serialized by the class serializer.
39
-
40
- // The type casting below isn't pretty, but works for now...
41
- return ClassSerializer.serialize(value as unknown as SerializableObject);
42
- }
43
- else if (value instanceof Object)
44
- {
45
- return ReflectionHelper.isClassObject(value)
46
- ? ClassSerializer.serialize(value as SerializableObject)
47
- : ObjectSerializer.serialize(value as SerializableObject);
48
- }
49
-
50
- return value;
51
- }
52
-
53
- async deserialize(value: unknown): Promise<unknown>
54
- {
55
- if ((value instanceof Object) === false)
56
- {
57
- return value;
58
- }
59
-
60
- if (value instanceof Array)
61
- {
62
- return await ArraySerializer.deserialize(value);
63
- }
64
-
65
- if ((value as Serialized).serialized !== true)
66
- {
67
- return await ObjectSerializer.deserialize(value as SerializedObject);
68
- }
69
-
70
- switch ((value as Serialized).name)
71
- {
72
- case 'Map': return await MapSerializer.deserialize(value as SerializedMap);
73
- case 'Set': return await SetSerializer.deserialize(value as SerializedSet);
74
- default: return await ClassSerializer.deserialize(value as SerializedClass);
75
- }
76
- }
77
- }
78
-
79
- const instance = new ValueSerializer();
80
-
81
- export default instance;
@@ -1,12 +0,0 @@
1
-
2
- import Component from '../../../core/types/Component.js';
3
-
4
- export default class ClassNotFound extends Error
5
- {
6
- constructor(name: string)
7
- {
8
- super(`The class '${name}' could not be found`);
9
- }
10
- }
11
-
12
- (ClassNotFound as Component).source = '/jitar/runtime/serialization/errors/ClassNotFound.js';
@@ -1,12 +0,0 @@
1
-
2
- import Component from '../../../core/types/Component.js';
3
-
4
- export default class InvalidClass extends Error
5
- {
6
- constructor(name: string)
7
- {
8
- super(`The class '${name}' is invalid`);
9
- }
10
- }
11
-
12
- (InvalidClass as Component).source = '/jitar/runtime/serialization/errors/InvalidClass.js';
@@ -1,12 +0,0 @@
1
-
2
- import Component from '../../../core/types/Component.js';
3
-
4
- export default class InvalidPropertyType extends Error
5
- {
6
- constructor(typeName: string, propertyName: string, expectedType: string)
7
- {
8
- super(`The ${typeName} property '${propertyName}' has an invalid type (expected '${expectedType}')`);
9
- }
10
- }
11
-
12
- (InvalidPropertyType as Component).source = '/jitar/runtime/serialization/errors/InvalidPropertyType.js';
@@ -1,10 +0,0 @@
1
-
2
- // Static functions are not supported in typescript.
3
- // Therefore all implementations need to export a singleton instance.
4
-
5
- export default interface Serializer
6
- {
7
- serialize(value: unknown): unknown;
8
-
9
- deserialize(value: unknown): Promise<unknown>;
10
- }
@@ -1,6 +0,0 @@
1
-
2
- import FlexObject from '../../../core/types/FlexObject.js';
3
-
4
- type SerializableObject = FlexObject;
5
-
6
- export default SerializableObject;
@@ -1,8 +0,0 @@
1
-
2
- type Serialized =
3
- {
4
- serialized: boolean,
5
- name: string
6
- };
7
-
8
- export default Serialized;
@@ -1,13 +0,0 @@
1
-
2
- import FlexObject from '../../../core/types/FlexObject.js';
3
-
4
- import Serialized from './Serialized.js';
5
-
6
- type SerializedClass = Serialized &
7
- {
8
- source: string | null,
9
- args: unknown[],
10
- fields: FlexObject
11
- }
12
-
13
- export default SerializedClass;
@@ -1,13 +0,0 @@
1
-
2
- import Serialized from './Serialized.js';
3
-
4
- type SerializedMap = Serialized &
5
- {
6
- entries:
7
- {
8
- keys: unknown[],
9
- values: unknown[]
10
- }
11
- }
12
-
13
- export default SerializedMap;
@@ -1,4 +0,0 @@
1
-
2
- type SerializedObject = { [key: string]: unknown };
3
-
4
- export default SerializedObject;
@@ -1,9 +0,0 @@
1
-
2
- import Serialized from './Serialized.js';
3
-
4
- type SerializedSet = Serialized &
5
- {
6
- values: unknown[]
7
- }
8
-
9
- export default SerializedSet;
@@ -1,10 +0,0 @@
1
-
2
- import Runtime from '../Runtime.js';
3
-
4
- type JitarHooks =
5
- {
6
- setRuntime: (runtime: Runtime) => void;
7
- setDependencyLoader: (loader: Function) => void;
8
- }
9
-
10
- export default JitarHooks;
@@ -1,6 +0,0 @@
1
-
2
- import Module from '../../core/types/Module.js';
3
-
4
- type ModuleImporter = (name: string) => Promise<Module>;
5
-
6
- export default ModuleImporter;
@@ -1,60 +0,0 @@
1
-
2
- import Module from '../../core/types/Module.js';
3
-
4
- export default class ModuleAnalyser
5
- {
6
- static filterObjects(module: Module): Map<string, Object>
7
- {
8
- return this.#filterexported(module, Object);
9
- }
10
-
11
- static filterFunctions(module: Module): Map<string, Function>
12
- {
13
- const functions = this.#filterexported(module, Function);
14
-
15
- return this.#filterFunctionTypes(functions, false);
16
- }
17
-
18
- static filterClasses(module: Module): Map<string, Function>
19
- {
20
- const functions = this.#filterexported(module, Function);
21
-
22
- return this.#filterFunctionTypes(functions, true);
23
- }
24
-
25
- static #filterexported(module: Module, type: ReturnType<typeof Function>): Map<string, typeof Function>
26
- {
27
- const keys = Object.keys(module);
28
-
29
- const filtered = new Map();
30
-
31
- for (const key of keys)
32
- {
33
- const exported = module[key];
34
-
35
- if (exported instanceof type)
36
- {
37
- filtered.set(key, exported);
38
- }
39
- }
40
-
41
- return filtered;
42
- }
43
-
44
- static #filterFunctionTypes(functions: Map<string, Function>, filterClasses: boolean): Map<string, Function>
45
- {
46
- const filtered = new Map();
47
-
48
- for (const [key, value] of functions)
49
- {
50
- const code = value.toString();
51
-
52
- if (code.startsWith('class') === filterClasses)
53
- {
54
- filtered.set(key, value);
55
- }
56
- }
57
-
58
- return filtered;
59
- }
60
- }
@@ -1,51 +0,0 @@
1
-
2
- import Module from '../../core/types/Module.js';
3
-
4
- import ModuleNotLoaded from '../errors/ModuleNotLoaded.js';
5
- import ModuleImporter from '../types/ModuleImporter.js';
6
- import UrlRewriter from './UrlRewriter.js';
7
-
8
- let _baseUrl: string | undefined;
9
- let _import = async (name: string): Promise<Module> => { return import(name); };
10
-
11
- export default class ModuleLoader
12
- {
13
- static setBaseUrl(baseUrl: string): void
14
- {
15
- _baseUrl = baseUrl;
16
- }
17
-
18
- static setImporter(importer: ModuleImporter): void
19
- {
20
- _import = importer;
21
- }
22
-
23
- static async load(url: string): Promise<Module>
24
- {
25
- if (url.startsWith('/jitar'))
26
- {
27
- url = `../../${url}`;
28
- }
29
-
30
- if (_baseUrl !== undefined && url.startsWith(_baseUrl) === false)
31
- {
32
- url = UrlRewriter.addBase(url, _baseUrl);
33
- }
34
-
35
- return this.import(url) as Promise<Module>;
36
- }
37
-
38
- static async import(specifier: string)
39
- {
40
- try
41
- {
42
- return await _import(specifier);
43
- }
44
- catch (error: unknown)
45
- {
46
- const message = error instanceof Error ? error.message : String(error);
47
-
48
- throw new ModuleNotLoaded(specifier, message);
49
- }
50
- }
51
- }
@@ -1,59 +0,0 @@
1
-
2
- export default class UrlRewriter
3
- {
4
- static addBase(url: string, base: string): string
5
- {
6
- url = this.#ensureStartsWithoutSlash(url);
7
- base = this.#assureEndWithSlash(base);
8
-
9
- return this.#translateRelativeParts(`${base}${url}`);
10
- }
11
-
12
- static #ensureStartsWithoutSlash(url: string): string
13
- {
14
- if (url.startsWith('/'))
15
- {
16
- return url.substring(1);
17
- }
18
-
19
- return url;
20
- }
21
-
22
- static #assureEndWithSlash(base: string): string
23
- {
24
- if (base.endsWith('/'))
25
- {
26
- return base;
27
- }
28
-
29
- return `${base}/`;
30
- }
31
-
32
- static #translateRelativeParts(url: string)
33
- {
34
- const parts = url.split('/');
35
- const translated = [];
36
-
37
- translated.push(parts[0]);
38
-
39
- for (let index = 1; index < parts.length; index++)
40
- {
41
- const part = parts[index].trim();
42
-
43
- if (part === '.' || part === '')
44
- {
45
- continue;
46
- }
47
- else if (part === '..')
48
- {
49
- translated.pop();
50
-
51
- continue;
52
- }
53
-
54
- translated.push(part);
55
- }
56
-
57
- return translated.join('/');
58
- }
59
- }