jitar 0.3.9 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -94
- package/dist/client.js +1 -24
- package/dist/globals-d516de70.js +1 -0
- package/dist/lib.d.ts +309 -35
- package/dist/lib.js +1 -29
- package/dist/server.js +1 -0
- package/package.json +19 -12
- package/LICENCE +0 -23
- package/dist/client.d.ts +0 -3
- package/dist/core/Context.d.ts +0 -5
- package/dist/core/Context.js +0 -7
- package/dist/core/ErrorManager.d.ts +0 -3
- package/dist/core/ErrorManager.js +0 -11
- package/dist/core/Implementation.d.ts +0 -10
- package/dist/core/Implementation.js +0 -44
- package/dist/core/Procedure.d.ts +0 -13
- package/dist/core/Procedure.js +0 -58
- package/dist/core/Segment.d.ts +0 -13
- package/dist/core/Segment.js +0 -36
- package/dist/core/SegmentBuilder.d.ts +0 -6
- package/dist/core/SegmentBuilder.js +0 -32
- package/dist/core/Version.d.ts +0 -13
- package/dist/core/Version.js +0 -50
- package/dist/core/definitions/AccessLevel.d.ts +0 -2
- package/dist/core/definitions/AccessLevel.js +0 -2
- package/dist/core/errors/BadRequest.d.ts +0 -3
- package/dist/core/errors/BadRequest.js +0 -6
- package/dist/core/errors/Forbidden.d.ts +0 -3
- package/dist/core/errors/Forbidden.js +0 -6
- package/dist/core/errors/ImplementationNotFound.d.ts +0 -4
- package/dist/core/errors/ImplementationNotFound.js +0 -7
- package/dist/core/errors/InvalidVersionNumber.d.ts +0 -4
- package/dist/core/errors/InvalidVersionNumber.js +0 -7
- package/dist/core/errors/MissingParameterValue.d.ts +0 -4
- package/dist/core/errors/MissingParameterValue.js +0 -7
- package/dist/core/errors/NotFound.d.ts +0 -3
- package/dist/core/errors/NotFound.js +0 -6
- package/dist/core/errors/NotImplemented.d.ts +0 -3
- package/dist/core/errors/NotImplemented.js +0 -6
- package/dist/core/errors/PaymentRequired.d.ts +0 -3
- package/dist/core/errors/PaymentRequired.js +0 -6
- package/dist/core/errors/ProcedureNotFound.d.ts +0 -4
- package/dist/core/errors/ProcedureNotFound.js +0 -7
- package/dist/core/errors/Teapot.d.ts +0 -3
- package/dist/core/errors/Teapot.js +0 -6
- package/dist/core/errors/Unauthorized.d.ts +0 -3
- package/dist/core/errors/Unauthorized.js +0 -6
- package/dist/core/errors/UnknownParameter.d.ts +0 -4
- package/dist/core/errors/UnknownParameter.js +0 -7
- package/dist/core/interfaces/Runner.d.ts +0 -4
- package/dist/core/interfaces/Runner.js +0 -1
- package/dist/core/reflection/ParameterParser.d.ts +0 -5
- package/dist/core/reflection/ParameterParser.js +0 -51
- package/dist/core/reflection/ReflectionHelper.d.ts +0 -13
- package/dist/core/reflection/ReflectionHelper.js +0 -69
- package/dist/core/reflection/models/ReflectionField.d.ts +0 -8
- package/dist/core/reflection/models/ReflectionField.js +0 -14
- package/dist/core/reflection/models/ReflectionParameter.d.ts +0 -7
- package/dist/core/reflection/models/ReflectionParameter.js +0 -11
- package/dist/core/types/Component.d.ts +0 -5
- package/dist/core/types/Component.js +0 -1
- package/dist/core/types/FlexObject.d.ts +0 -4
- package/dist/core/types/FlexObject.js +0 -1
- package/dist/core/types/Module.d.ts +0 -3
- package/dist/core/types/Module.js +0 -1
- package/dist/core/types/SegmentImplementation.d.ts +0 -6
- package/dist/core/types/SegmentImplementation.js +0 -1
- package/dist/core/types/SegmentModule.d.ts +0 -5
- package/dist/core/types/SegmentModule.js +0 -1
- package/dist/core/types/SegmentProcedure.d.ts +0 -7
- package/dist/core/types/SegmentProcedure.js +0 -1
- package/dist/core/utils/FqnBuilder.d.ts +0 -3
- package/dist/core/utils/FqnBuilder.js +0 -5
- package/dist/hooks.d.ts +0 -2
- package/dist/hooks.js +0 -2
- package/dist/runtime/ClientId.d.ts +0 -4
- package/dist/runtime/ClientId.js +0 -11
- package/dist/runtime/Gateway.d.ts +0 -5
- package/dist/runtime/Gateway.js +0 -3
- package/dist/runtime/LocalGateway.d.ts +0 -14
- package/dist/runtime/LocalGateway.js +0 -61
- package/dist/runtime/LocalNode.d.ts +0 -18
- package/dist/runtime/LocalNode.js +0 -75
- package/dist/runtime/LocalRepository.d.ts +0 -17
- package/dist/runtime/LocalRepository.js +0 -94
- package/dist/runtime/Node.d.ts +0 -3
- package/dist/runtime/Node.js +0 -3
- package/dist/runtime/NodeBalancer.d.ts +0 -9
- package/dist/runtime/NodeBalancer.js +0 -34
- package/dist/runtime/NodeMonitor.d.ts +0 -7
- package/dist/runtime/NodeMonitor.js +0 -38
- package/dist/runtime/ProcedureRunner.d.ts +0 -9
- package/dist/runtime/ProcedureRunner.js +0 -11
- package/dist/runtime/ProcedureRuntime.d.ts +0 -14
- package/dist/runtime/ProcedureRuntime.js +0 -28
- package/dist/runtime/Proxy.d.ts +0 -18
- package/dist/runtime/Proxy.js +0 -33
- package/dist/runtime/Remote.d.ts +0 -15
- package/dist/runtime/Remote.js +0 -102
- package/dist/runtime/RemoteGateway.d.ts +0 -11
- package/dist/runtime/RemoteGateway.js +0 -22
- package/dist/runtime/RemoteNode.d.ts +0 -12
- package/dist/runtime/RemoteNode.js +0 -29
- package/dist/runtime/RemoteRepository.d.ts +0 -14
- package/dist/runtime/RemoteRepository.js +0 -34
- package/dist/runtime/Repository.d.ts +0 -11
- package/dist/runtime/Repository.js +0 -3
- package/dist/runtime/Runtime.d.ts +0 -9
- package/dist/runtime/Runtime.js +0 -27
- package/dist/runtime/caching/CacheBuilder.d.ts +0 -6
- package/dist/runtime/caching/CacheBuilder.js +0 -246
- package/dist/runtime/caching/ImportRewriter.d.ts +0 -4
- package/dist/runtime/caching/ImportRewriter.js +0 -58
- package/dist/runtime/caching/RemoteBuilder.d.ts +0 -5
- package/dist/runtime/caching/RemoteBuilder.js +0 -31
- package/dist/runtime/caching/SourceAppender.d.ts +0 -5
- package/dist/runtime/caching/SourceAppender.js +0 -30
- package/dist/runtime/caching/definitions/Keywords.d.ts +0 -2
- package/dist/runtime/caching/definitions/Keywords.js +0 -2
- package/dist/runtime/caching/errors/InvalidSegmentFilename.d.ts +0 -3
- package/dist/runtime/caching/errors/InvalidSegmentFilename.js +0 -5
- package/dist/runtime/caching/errors/MissingModuleExport.d.ts +0 -3
- package/dist/runtime/caching/errors/MissingModuleExport.js +0 -5
- package/dist/runtime/caching/errors/SegmentFileNotLoaded.d.ts +0 -3
- package/dist/runtime/caching/errors/SegmentFileNotLoaded.js +0 -5
- package/dist/runtime/caching/errors/SegmentModuleNotLoaded.d.ts +0 -3
- package/dist/runtime/caching/errors/SegmentModuleNotLoaded.js +0 -5
- package/dist/runtime/caching/models/ApplicationModule.d.ts +0 -10
- package/dist/runtime/caching/models/ApplicationModule.js +0 -19
- package/dist/runtime/caching/models/Implementation.d.ts +0 -12
- package/dist/runtime/caching/models/Implementation.js +0 -27
- package/dist/runtime/caching/models/Procedure.d.ts +0 -9
- package/dist/runtime/caching/models/Procedure.js +0 -15
- package/dist/runtime/caching/models/Segment.d.ts +0 -10
- package/dist/runtime/caching/models/Segment.js +0 -16
- package/dist/runtime/caching/models/SegmentModule.d.ts +0 -10
- package/dist/runtime/caching/models/SegmentModule.js +0 -14
- package/dist/runtime/caching/types/SegmentFile.d.ts +0 -5
- package/dist/runtime/caching/types/SegmentFile.js +0 -1
- package/dist/runtime/caching/types/SegmentImportProperties.d.ts +0 -6
- package/dist/runtime/caching/types/SegmentImportProperties.js +0 -1
- package/dist/runtime/caching/types/SegmentImports.d.ts +0 -5
- package/dist/runtime/caching/types/SegmentImports.js +0 -1
- package/dist/runtime/errors/ClientNotFound.d.ts +0 -3
- package/dist/runtime/errors/ClientNotFound.js +0 -6
- package/dist/runtime/errors/FileNotFound.d.ts +0 -3
- package/dist/runtime/errors/FileNotFound.js +0 -6
- package/dist/runtime/errors/InvalidClientId.d.ts +0 -3
- package/dist/runtime/errors/InvalidClientId.js +0 -6
- package/dist/runtime/errors/InvalidJitarHooks.d.ts +0 -3
- package/dist/runtime/errors/InvalidJitarHooks.js +0 -6
- package/dist/runtime/errors/InvalidSegmentFile.d.ts +0 -3
- package/dist/runtime/errors/InvalidSegmentFile.js +0 -6
- package/dist/runtime/errors/ModuleNotLoaded.d.ts +0 -3
- package/dist/runtime/errors/ModuleNotLoaded.js +0 -6
- package/dist/runtime/errors/NoNodeAvailable.d.ts +0 -3
- package/dist/runtime/errors/NoNodeAvailable.js +0 -6
- package/dist/runtime/errors/RepositoryNotAvaiable.d.ts +0 -3
- package/dist/runtime/errors/RepositoryNotAvaiable.js +0 -6
- package/dist/runtime/errors/RuntimeNotAvailable.d.ts +0 -3
- package/dist/runtime/errors/RuntimeNotAvailable.js +0 -6
- package/dist/runtime/errors/SegmentNotFound.d.ts +0 -3
- package/dist/runtime/errors/SegmentNotFound.js +0 -6
- package/dist/runtime/hooks/dependencies.d.ts +0 -2
- package/dist/runtime/hooks/dependencies.js +0 -9
- package/dist/runtime/hooks/runtime.d.ts +0 -3
- package/dist/runtime/hooks/runtime.js +0 -16
- package/dist/runtime/interfaces/FileManager.d.ts +0 -11
- package/dist/runtime/interfaces/FileManager.js +0 -1
- package/dist/runtime/interfaces/HealthCheck.d.ts +0 -3
- package/dist/runtime/interfaces/HealthCheck.js +0 -1
- package/dist/runtime/interfaces/Middleware.d.ts +0 -5
- package/dist/runtime/interfaces/Middleware.js +0 -1
- package/dist/runtime/middleware/CorsMiddleware.d.ts +0 -11
- package/dist/runtime/middleware/CorsMiddleware.js +0 -22
- package/dist/runtime/models/File.d.ts +0 -9
- package/dist/runtime/models/File.js +0 -14
- package/dist/runtime/serialization/ArrayBufferSerializer.d.ts +0 -10
- package/dist/runtime/serialization/ArrayBufferSerializer.js +0 -54
- package/dist/runtime/serialization/ArraySerializer.d.ts +0 -7
- package/dist/runtime/serialization/ArraySerializer.js +0 -15
- package/dist/runtime/serialization/ClassSerializer.d.ts +0 -10
- package/dist/runtime/serialization/ClassSerializer.js +0 -74
- package/dist/runtime/serialization/DateSerializer.d.ts +0 -9
- package/dist/runtime/serialization/DateSerializer.js +0 -21
- package/dist/runtime/serialization/MapSerializer.d.ts +0 -9
- package/dist/runtime/serialization/MapSerializer.js +0 -35
- package/dist/runtime/serialization/ObjectSerializer.d.ts +0 -9
- package/dist/runtime/serialization/ObjectSerializer.js +0 -21
- package/dist/runtime/serialization/SetSerializer.d.ts +0 -9
- package/dist/runtime/serialization/SetSerializer.js +0 -23
- package/dist/runtime/serialization/ValueSerializer.d.ts +0 -8
- package/dist/runtime/serialization/ValueSerializer.js +0 -69
- package/dist/runtime/serialization/errors/ClassNotFound.d.ts +0 -3
- package/dist/runtime/serialization/errors/ClassNotFound.js +0 -6
- package/dist/runtime/serialization/errors/InvalidClass.d.ts +0 -3
- package/dist/runtime/serialization/errors/InvalidClass.js +0 -6
- package/dist/runtime/serialization/errors/InvalidPropertyType.d.ts +0 -4
- package/dist/runtime/serialization/errors/InvalidPropertyType.js +0 -7
- package/dist/runtime/serialization/interfaces/Serializer.d.ts +0 -4
- package/dist/runtime/serialization/interfaces/Serializer.js +0 -1
- package/dist/runtime/serialization/types/SerializableObject.d.ts +0 -3
- package/dist/runtime/serialization/types/SerializableObject.js +0 -1
- package/dist/runtime/serialization/types/Serialized.d.ts +0 -5
- package/dist/runtime/serialization/types/Serialized.js +0 -1
- package/dist/runtime/serialization/types/SerializedArrayBuffer.d.ts +0 -6
- package/dist/runtime/serialization/types/SerializedArrayBuffer.js +0 -1
- package/dist/runtime/serialization/types/SerializedClass.d.ts +0 -8
- package/dist/runtime/serialization/types/SerializedClass.js +0 -1
- package/dist/runtime/serialization/types/SerializedDate.d.ts +0 -5
- package/dist/runtime/serialization/types/SerializedDate.js +0 -1
- package/dist/runtime/serialization/types/SerializedMap.d.ts +0 -8
- package/dist/runtime/serialization/types/SerializedMap.js +0 -1
- package/dist/runtime/serialization/types/SerializedObject.d.ts +0 -4
- package/dist/runtime/serialization/types/SerializedObject.js +0 -1
- package/dist/runtime/serialization/types/SerializedSet.d.ts +0 -5
- package/dist/runtime/serialization/types/SerializedSet.js +0 -1
- package/dist/runtime/serialization/types/TypedArray.d.ts +0 -2
- package/dist/runtime/serialization/types/TypedArray.js +0 -1
- package/dist/runtime/types/JitarHooks.d.ts +0 -6
- package/dist/runtime/types/JitarHooks.js +0 -1
- package/dist/runtime/types/ModuleImporter.d.ts +0 -3
- package/dist/runtime/types/ModuleImporter.js +0 -1
- package/dist/runtime/types/NextHandler.d.ts +0 -2
- package/dist/runtime/types/NextHandler.js +0 -1
- package/dist/runtime/utils/ModuleAnalyser.d.ts +0 -7
- package/dist/runtime/utils/ModuleAnalyser.js +0 -23
- package/dist/runtime/utils/ModuleLoader.d.ts +0 -8
- package/dist/runtime/utils/ModuleLoader.js +0 -30
- package/dist/runtime/utils/UrlRewriter.d.ts +0 -4
- package/dist/runtime/utils/UrlRewriter.js +0 -36
package/CHANGELOG.md
CHANGED
|
@@ -1,97 +1,4 @@
|
|
|
1
1
|
|
|
2
2
|
# Changelog
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
New features:
|
|
7
|
-
- \[[`ccd0d50`](https://github.com/MaskingTechnology/jitar/commit/ccd0d50)] Added support for preflight requests [basmasking](https://github.com/MaskingTechnology/jitar/pull/204)
|
|
8
|
-
|
|
9
|
-
## 0.3.8 (March 04, 2023)
|
|
10
|
-
|
|
11
|
-
Fixes:
|
|
12
|
-
- \[[`5ce818e`](https://github.com/MaskingTechnology/jitar/commit/5ce818e)] Fixed importing commonJS modules [petermasking](https://github.com/MaskingTechnology/jitar/pull/195)
|
|
13
|
-
|
|
14
|
-
## 0.3.7 (February 26, 2023)
|
|
15
|
-
|
|
16
|
-
Fixes:
|
|
17
|
-
- \[[`b9c9db3`](https://github.com/MaskingTechnology/jitar/commit/b9c9db3)] Fixed importing commonJS modules [petermasking](https://github.com/MaskingTechnology/jitar/pull/182)
|
|
18
|
-
|
|
19
|
-
## 0.3.6 (February 26, 2023)
|
|
20
|
-
|
|
21
|
-
- Bump dependency for the latest version of jitar-reflection.
|
|
22
|
-
|
|
23
|
-
## 0.3.4 (February 23, 2023)
|
|
24
|
-
|
|
25
|
-
New features:
|
|
26
|
-
- \[[`00a1f4f`](https://github.com/MaskingTechnology/jitar/commit/00a1f4f)] Use the advanced reflection library [basmasking](https://github.com/MaskingTechnology/jitar/pull/168)
|
|
27
|
-
|
|
28
|
-
## 0.3.3 (February 13, 2023)
|
|
29
|
-
|
|
30
|
-
New features:
|
|
31
|
-
- \[[`18d6a4a`](https://github.com/MaskingTechnology/jitar/commit/18d6a4a)] Extended options for CORS middleware [petermasking](https://github.com/MaskingTechnology/jitar/pull/133)
|
|
32
|
-
|
|
33
|
-
## 0.3.2 (February 10, 2023)
|
|
34
|
-
|
|
35
|
-
Fixes:
|
|
36
|
-
- \[[`f9c43a2`](https://github.com/MaskingTechnology/jitar/commit/f9c43a2)] Fixed 0.3.1 releases (did not contain code) [basmasking](https://github.com/MaskingTechnology/jitar/commit/f9c43a2)
|
|
37
|
-
|
|
38
|
-
## 0.3.1 (February 08, 2023)
|
|
39
|
-
|
|
40
|
-
New features:
|
|
41
|
-
- \[[`56164ee`](https://github.com/MaskingTechnology/jitar/commit/56164ee)] Implemented CORS middleware [basmasking](https://github.com/MaskingTechnology/jitar/pull/131)
|
|
42
|
-
|
|
43
|
-
## 0.3.0 (January 25, 2023)
|
|
44
|
-
|
|
45
|
-
New features:
|
|
46
|
-
- \[[`e842d81`](https://github.com/MaskingTechnology/jitar/commit/e842d81)] Implemented middleware support [petermasking](https://github.com/MaskingTechnology/jitar/pull/117)
|
|
47
|
-
- \[[`9d29d31`](https://github.com/MaskingTechnology/jitar/commit/9d29d31)] Extended exceptions to status codes mappings [petermasking](https://github.com/MaskingTechnology/jitar/pull/118)
|
|
48
|
-
|
|
49
|
-
## 0.2.2 (December 16, 2022)
|
|
50
|
-
|
|
51
|
-
Changes:
|
|
52
|
-
- \[[`4891db6`](https://github.com/MaskingTechnology/jitar/commit/4891db6)] Bumped dev dependencies [basmasking](https://github.com/MaskingTechnology/jitar/pull/89)
|
|
53
|
-
|
|
54
|
-
## 0.2.1 (December 02, 2022)
|
|
55
|
-
|
|
56
|
-
Fixes:
|
|
57
|
-
- \[[`fb04f99`](https://github.com/MaskingTechnology/jitar/commit/fb04f99)] Fixed error deserialization at gateway [basmasking](https://github.com/MaskingTechnology/jitar/pull/69)
|
|
58
|
-
|
|
59
|
-
## 0.2.0 (November 18, 2022)
|
|
60
|
-
|
|
61
|
-
New features:
|
|
62
|
-
- \[[`0c115e1`](https://github.com/MaskingTechnology/jitar/commit/0c115e1)] Added binary data serialization [basmasking](https://github.com/MaskingTechnology/jitar/pull/56)
|
|
63
|
-
- \[[`38b90da`](https://github.com/MaskingTechnology/jitar/commit/38b90da)] Added date serialization [basmasking](https://github.com/MaskingTechnology/jitar/pull/58)
|
|
64
|
-
- \[[`b27f571`](https://github.com/MaskingTechnology/jitar/commit/b27f571)] Split jitar into multiple packages [basmasking](https://github.com/MaskingTechnology/jitar/pull/60)
|
|
65
|
-
|
|
66
|
-
## 0.1.3 (November 11, 2022)
|
|
67
|
-
|
|
68
|
-
Fixes:
|
|
69
|
-
- \[[`4b7a8d0`](https://github.com/MaskingTechnology/jitar/commit/4b7a8d0)] Added release script and released to npm [basmasking](https://github.com/BasMasking)
|
|
70
|
-
|
|
71
|
-
## 0.1.2 (November 11, 2022)
|
|
72
|
-
|
|
73
|
-
New features:
|
|
74
|
-
- \[[`a842fb0`](https://github.com/MaskingTechnology/jitar/commit/a842fb0)] Data type validation on RPC calls [Yusuf-YENICERI](https://github.com/MaskingTechnology/jitar/pull/44)
|
|
75
|
-
- \[[`265a5f5`](https://github.com/MaskingTechnology/jitar/commit/265a5f5)] Asset protection (public/private assets) [basmasking](https://github.com/MaskingTechnology/jitar/pull/48)
|
|
76
|
-
- \[[`0b0cf57`](https://github.com/MaskingTechnology/jitar/commit/0b0cf57)] Extended error handling [basmeeuwissen](https://github.com/MaskingTechnology/jitar/pull/53)
|
|
77
|
-
- \[[`ec63abd`](https://github.com/MaskingTechnology/jitar/commit/ec63abd)] Fixed segment in startClient documentation [pvvliet](https://github.com/MaskingTechnology/jitar/pull/54)
|
|
78
|
-
|
|
79
|
-
## 0.1.1 (October 28, 2022)
|
|
80
|
-
|
|
81
|
-
Fixes:
|
|
82
|
-
- Linting issues (typing, code improvements, etc.)
|
|
83
|
-
- \[[`e85db81`](https://github.com/MaskingTechnology/jitar/commit/e85db81)] Extended deserialization data validation [petermasking](https://github.com/MaskingTechnology/jitar/pull/24)
|
|
84
|
-
- \[[`468d92c`](https://github.com/MaskingTechnology/jitar/commit/468d92c)] Improved the client id generation and validation [petermasking](https://github.com/MaskingTechnology/jitar/pull/22)
|
|
85
|
-
|
|
86
|
-
## 0.1.0 (October 21, 2022)
|
|
87
|
-
|
|
88
|
-
New features:
|
|
89
|
-
- Segmentation (configurable)
|
|
90
|
-
- Orchestration (automatic)
|
|
91
|
-
- Load belancing (round robin)
|
|
92
|
-
- Access protection (public/private)
|
|
93
|
-
- Multi-version (procedures)
|
|
94
|
-
- Data transportation (serialization)
|
|
95
|
-
- Error handling
|
|
96
|
-
- Health checks
|
|
97
|
-
- RPC API (HTTP)
|
|
4
|
+
This package doesn't keep a changelog. See the changelog in the [github repository](https://github.com/MaskingTechnology/jitar/blob/main/CHANGELOG.md)
|
package/dist/client.js
CHANGED
|
@@ -1,24 +1 @@
|
|
|
1
|
-
import LocalNode from
|
|
2
|
-
import RemoteGateway from './runtime/RemoteGateway.js';
|
|
3
|
-
import RemoteRepository from './runtime/RemoteRepository.js';
|
|
4
|
-
let client = undefined;
|
|
5
|
-
const resolvers = [];
|
|
6
|
-
export async function startClient(...segmentFiles) {
|
|
7
|
-
const remoteUrl = document.location.origin;
|
|
8
|
-
const node = new LocalNode();
|
|
9
|
-
const gateway = new RemoteGateway(remoteUrl);
|
|
10
|
-
const repository = new RemoteRepository(remoteUrl);
|
|
11
|
-
await node.setGateway(gateway);
|
|
12
|
-
await node.setRepository(repository, segmentFiles);
|
|
13
|
-
client = node;
|
|
14
|
-
resolvers.forEach((resolve) => resolve(node));
|
|
15
|
-
return node;
|
|
16
|
-
}
|
|
17
|
-
export async function getClient() {
|
|
18
|
-
if (client === undefined) {
|
|
19
|
-
return new Promise((resolve) => {
|
|
20
|
-
resolvers.push(resolve);
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
return client;
|
|
24
|
-
}
|
|
1
|
+
import{A as AccessLevel,x as Version,q as LocalNode,s as RemoteGateway,r as RemoteRepository}from"./globals-d516de70.js";export{D as ArrayParameter,B as BadRequest,C as ClientNotFound,F as FileNotFound,u as Forbidden,G as ImplementationNotFound,a as InvalidClientId,H as InvalidParameterValue,I as InvalidSegmentFile,J as InvalidVersionNumber,K as MissingParameterValue,Q as ModuleNotAccessible,W as ModuleNotLoaded,z as NamedParameter,X as NoNodeAvailable,v as NotFound,w as NotImplemented,O as ObjectParameter,t as PaymentRequired,Y as ProcedureNotAccessible,Z as ProcedureNotFound,_ as RepositoryNotAvailable,$ as RuntimeNotAvailable,a0 as SegmentNotFound,E as ServerError,T as Teapot,U as Unauthorized,a1 as UnknownParameter}from"./globals-d516de70.js";class Implementation{#version;#access;#parameters;#executable;constructor(version,access,parameters,executable){this.#version=version,this.#access=access,this.#parameters=parameters,this.#executable=executable}get version(){return this.#version}get public(){return this.#access===AccessLevel.PUBLIC}get parameters(){return this.#parameters}get executable(){return this.#executable}}class Procedure{#fqn;#implementations=new Map;#latestImplementation;constructor(fqn){this.#fqn=fqn}get fqn(){return this.#fqn}get public(){return[...this.#implementations.values()].some((implementation=>implementation.public))}addImplementation(implementation){return this.#implementations.set(implementation.version,implementation),this.#isNewLatestImplementation(implementation)&&(this.#latestImplementation=implementation),this}#isNewLatestImplementation(implementation){return void 0===this.#latestImplementation||implementation.version.greater(this.#latestImplementation.version)}getImplementation(version){const selectedVersion=this.#selectAvailableVersion(version);return this.#implementations.get(selectedVersion)}#selectAvailableVersion(version){let selectedVersion=Version.DEFAULT;for(const implementationVersion of this.#implementations.keys()){if(implementationVersion.equals(version))return implementationVersion;implementationVersion.greater(version)||selectedVersion.less(implementationVersion)&&(selectedVersion=implementationVersion)}return selectedVersion}}class Segment{#id;#procedures=new Map;constructor(id){this.#id=id}get id(){return this.#id}addProcedure(procedure){return this.#procedures.set(procedure.fqn,procedure),this}hasProcedure(fqn){return void 0!==this.getProcedure(fqn)}getProcedure(fqn){return this.#procedures.get(fqn)}getPublicProcedures(){return[...this.#procedures.values()].filter((procedure=>procedure.public))}}let client;const resolvers=[];async function startClient(remoteUrl,segmentNames=[]){const node=new LocalNode,gateway=new RemoteGateway(remoteUrl),repository=new RemoteRepository(remoteUrl);return await node.setGateway(gateway),await node.setRepository(repository,segmentNames),client=node,resolvers.forEach((resolve=>resolve(node))),node}async function getClient(){return void 0===client?new Promise((resolve=>{resolvers.push(resolve)})):client}export{Implementation,Procedure,Segment,Version,getClient,startClient};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const AccessLevel={PRIVATE:"private",PUBLIC:"public"};Object.freeze(AccessLevel);const AccessLevels=Object.values(AccessLevel);Object.freeze(AccessLevels);const Files={MODULE_PATTERN:"**/*.js",SEGMENT_PATTERN:"**/*.segment.json",NODE_SEGMENT_PATTERN:"**/*.segment.node.js",REPOSITORY_SEGMENT_PATTERN:"**/*.segment.repository.js"};function convertToLocalFilename(filename){return filename.replace(".js",".local.js")}function convertToRemoteFilename(filename){return filename.replace(".js",".remote.js")}function createNodeFilename(name){return`${name}.segment.node.js`}function createRepositoryFilename(name){return`${name}.segment.repository.js`}function isSegmentFilename(filename){return filename.includes(".segment.")}Object.freeze(Files);class BadRequest extends Error{constructor(message="Invalid request"){super(message)}}BadRequest.source="/jitar/client.js";class Forbidden extends Error{constructor(message="Forbidden"){super(message)}}Forbidden.source="/jitar/client.js";class NotFound extends Error{constructor(message="Not found"){super(message)}}NotFound.source="/jitar/client.js";class NotImplemented extends Error{constructor(message="Not implemented"){super(message)}}NotImplemented.source="/jitar/client.js";class PaymentRequired extends Error{constructor(message="Payment required"){super(message)}}PaymentRequired.source="/jitar/client.js";class ServerError extends Error{constructor(message="Server error"){super(message)}}ServerError.source="/jitar/client.js";class Teapot extends Error{constructor(){super("I'm a teapot")}}Teapot.source="/jitar/client.js";class Unauthorized extends Error{constructor(message="Unauthorized"){super(message)}}Unauthorized.source="/jitar/client.js";class ClientNotFound extends BadRequest{#clientId;constructor(clientId){super(`Client not found for id '${clientId}'`),this.#clientId=clientId}get clientId(){return this.#clientId}}ClientNotFound.source="/jitar/client.js";class FileNotFound extends NotFound{#filename;constructor(filename){super(`The file '${filename} could not be found'`),this.#filename=filename}get filename(){return this.#filename}}FileNotFound.source="/jitar/client.js";class ImplementationNotFound extends NotFound{#fqn;#version;constructor(fqn,version){super(`No implementation found for procedure '${fqn}' with version '${version}'`),this.#fqn=fqn,this.#version=version}get fqn(){return this.#fqn}get version(){return this.#version}}ImplementationNotFound.source="/jitar/client.js";class InvalidClientId extends BadRequest{#clientId;constructor(clientId){super(`Invalid client id '${clientId}'`),this.#clientId=clientId}get clientId(){return this.#clientId}}InvalidClientId.source="/jitar/client.js";class InvalidParameterValue extends BadRequest{#parameterName;constructor(parameterName){super(`Invalid value for parameter '${parameterName}'`),this.#parameterName=parameterName}get parameterName(){return this.#parameterName}}InvalidParameterValue.source="/jitar/client.js";class InvalidSegmentFile extends ServerError{#filename;constructor(filename){super(`Missing files array in segment file '${filename}'`),this.#filename=filename}get filename(){return this.#filename}}InvalidSegmentFile.source="/jitar/client.js";class InvalidVersionNumber extends BadRequest{#number;constructor(number){super(`Invalid version number '${number}'`),this.#number=number}get number(){return this.#number}}InvalidVersionNumber.source="/jitar/client.js";class MissingParameterValue extends BadRequest{#parameterName;constructor(parameterName){super(`Missing value for parameter '${parameterName}'`),this.#parameterName=parameterName}get parameterName(){return this.#parameterName}}MissingParameterValue.source="/jitar/client.js";class ModuleNotAccessible extends Forbidden{#url;constructor(url){super(`Module '${url}' is not accessible`),this.#url=url}get url(){return this.#url}}ModuleNotAccessible.source="/jitar/client.js";class ModuleNotLoaded extends ServerError{#url;#reason;constructor(url,reason){super(`Module '${url}' could not be loaded${void 0!==reason?` | ${reason}`:""}`),this.#url=url,this.#reason=reason}get url(){return this.#url}get reason(){return this.#reason}}ModuleNotLoaded.source="/jitar/client.js";class NoNodeAvailable extends ServerError{#name;constructor(name){super(`No node available for procedure '${name}'`),this.#name=name}get name(){return this.#name}}NoNodeAvailable.source="/jitar/client.js";class ProcedureNotAccessible extends Forbidden{#fqn;#versionNumber;constructor(fqn,versionNumber){super(`Procedure '${fqn}' (v${versionNumber}) is not accessible`),this.#fqn=fqn,this.#versionNumber=versionNumber}get fqn(){return this.#fqn}get versionNumber(){return this.#versionNumber}}ProcedureNotAccessible.source="/jitar/client.js";class ProcedureNotFound extends NotFound{#fqn;constructor(fqn){super(`Procedure '${fqn}' not found`),this.#fqn=fqn}get fqn(){return this.#fqn}}ProcedureNotFound.source="/jitar/client.js";class RepositoryNotAvailable extends ServerError{constructor(){super("Repository not available")}}RepositoryNotAvailable.source="/jitar/client.js";class RuntimeNotAvailable extends ServerError{constructor(){super("Runtime not available")}}RuntimeNotAvailable.source="/jitar/client.js";class SegmentNotFound extends ServerError{#source;constructor(source){super(`Segment found for '${source}'`),this.#source=source}get source(){return this.#source}}SegmentNotFound.source="/jitar/client.js";class UnknownParameter extends BadRequest{#parameterName;constructor(parameterName){super(`Unknown parameter ${parameterName}`),this.#parameterName=parameterName}get parameterName(){return this.#parameterName}}UnknownParameter.source="/jitar/client.js";class Parameter{#name;#isOptional;constructor(name,isOptional=!1){this.#name=name,this.#isOptional=isOptional}get name(){return this.#name}get isOptional(){return this.#isOptional}}class DestructuredParameter extends Parameter{#variables;constructor(variables,name,isOptional){super(name??"(anonymous)",isOptional),this.#variables=variables}get variables(){return this.#variables}}class ArrayParameter extends DestructuredParameter{}class File{#location;#type;#content;constructor(location,type,content){this.#location=location,this.#type=type,this.#content=content}get location(){return this.#location}get type(){return this.#type}get content(){return this.#content}get size(){return this.#content.length}}class NamedParameter extends Parameter{}class ObjectParameter extends DestructuredParameter{}class Version{static get DEFAULT(){return new Version(0,0,0)}#major;#minor;#patch;constructor(major=0,minor=0,patch=0){this.#major=major,this.#minor=minor,this.#patch=patch}get major(){return this.#major}get minor(){return this.#minor}get patch(){return this.#patch}equals(version){return this.#major===version.major&&this.#minor===version.minor&&this.#patch===version.patch}greater(version){return this.#major!==version.major?this.#major>version.major:this.#minor!==version.minor?this.#minor>version.minor:this.#patch!==version.patch&&this.#patch>version.patch}less(version){return this.#major!==version.major?this.#major<version.major:this.#minor!==version.minor?this.#minor<version.minor:this.#patch!==version.patch&&this.#patch<version.patch}toString(){return`${this.#major}.${this.#minor}.${this.#patch}`}}class Runtime{#url;#healthChecks=new Map;constructor(url){this.#url=url}get url(){return this.#url}addHealthCheck(name,healthCheck){this.#healthChecks.set(name,healthCheck)}async isHealthy(){for(const healthCheck of this.#healthChecks.values())if(!1===await healthCheck.isHealthy())return!1;return!0}async getHealth(){const health=new Map;for(const[name,healthCheck]of this.#healthChecks){const healthy=await healthCheck.isHealthy();health.set(name,healthy)}return health}}class ProcedureRunner{#runner;constructor(runner){this.#runner=runner}async handle(fqn,version,args,headers,next){const result=await this.#runner.run(fqn,version,args,headers);return headers.clear(),result}}class ProcedureRuntime extends Runtime{#middlewares=[];constructor(url){super(url),this.#middlewares.push(new ProcedureRunner(this))}addMiddleware(middleware){const index=this.#middlewares.length-1;this.#middlewares.splice(index,0,middleware)}getMiddleware(type){return this.#middlewares.find((middleware=>middleware instanceof type))}handle(fqn,version,args,headers){return this.#getNextHandler(fqn,version,args,headers,0)()}#getNextHandler(fqn,version,args,headers,index){const next=this.#middlewares[index];if(void 0===next)return async()=>{};const nextHandler=this.#getNextHandler(fqn,version,args,headers,index+1);return async()=>next.handle(fqn,version,args,headers,nextHandler)}}class Gateway extends ProcedureRuntime{}class UrlRewriter{static addBase(url,base){return url=this.#ensureStartsWithoutSlash(url),base=this.#assureEndWithSlash(base),this.#translateRelativeParts(`${base}${url}`)}static#ensureStartsWithoutSlash(url){return url.startsWith("/")?url.substring(1):url}static#assureEndWithSlash(base){return base.endsWith("/")?base:`${base}/`}static#translateRelativeParts(url){const parts=url.split("/"),translated=[];translated.push(parts[0]);for(let index=1;index<parts.length;index++){const part=parts[index].trim();"."!==part&&(".."!==part?translated.push(part):translated.pop())}return translated.join("/")}}const NON_SYSTEM_INDICATORS=[".","/","http:","https:"];let _baseUrl,_import=async name=>import(name);class ModuleLoader{static setBaseUrl(baseUrl){_baseUrl=baseUrl}static setImporter(importer){_import=importer}static assureExtension(specifier){return this.#isSystemModule(specifier)||specifier.endsWith(".js")?specifier:`${specifier}.js`}static async load(specifier){let url=this.assureExtension(specifier);if(url.startsWith("/jitar"))return specifier="jitar",this.#import(specifier,specifier);if(void 0!==_baseUrl&&!1===url.startsWith(_baseUrl)&&(url=UrlRewriter.addBase(url,_baseUrl),!1===url.startsWith(_baseUrl)))throw new ModuleNotAccessible(specifier);return this.#import(url,specifier)}static async import(specifier){return this.#import(specifier,specifier)}static async#import(absolute,relative){try{return await _import(absolute)}catch(error){const message=error instanceof Error?error.message:String(error);throw new ModuleNotLoaded(relative,message)}}static#isSystemModule(specifier){return!1===NON_SYSTEM_INDICATORS.some((indicator=>specifier.startsWith(indicator)))}}class NodeBalancer{#nodes=[];#currentIndex=0;addNode(node){this.#nodes.includes(node)||this.#nodes.push(node)}removeNode(node){const index=this.#nodes.indexOf(node);-1!==index&&this.#nodes.splice(index,1)}getNextNode(){if(0!==this.#nodes.length)return this.#currentIndex>=this.#nodes.length&&(this.#currentIndex=0),this.#nodes[this.#currentIndex++]}run(fqn,version,args,headers){const node=this.getNextNode();if(void 0===node)throw new NoNodeAvailable(fqn);return node.run(fqn,version,args,headers)}}const NO_SEGMENTS=[];class LocalGateway extends Gateway{#nodes=new Set;#balancers=new Map;get nodes(){return[...this.#nodes.values()]}getProcedureNames(){const procedureNames=this.nodes.map((node=>node.getProcedureNames()));return[...new Set(procedureNames.flat()).values()]}hasProcedure(fqn){return this.getProcedureNames().includes(fqn)}async addNode(node){this.#nodes.add(node);for(const name of node.getProcedureNames()){this.#getOrCreateBalancer(name).addNode(node)}}removeNode(node){this.#nodes.delete(node);for(const name of node.getProcedureNames()){const balancer=this.#getBalancer(name);void 0!==balancer&&balancer.removeNode(node)}}async setBaseUrl(repository){const clientId=await repository.registerClient(NO_SEGMENTS),moduleLocation=await repository.getModuleLocation(clientId);ModuleLoader.setBaseUrl(moduleLocation)}#getBalancer(fqn){return this.#balancers.get(fqn)}#getOrCreateBalancer(fqn){let balancer=this.#getBalancer(fqn);return void 0===balancer&&(balancer=new NodeBalancer,this.#balancers.set(fqn,balancer)),balancer}run(fqn,version,args,headers){const balancer=this.#getBalancer(fqn);if(void 0===balancer)throw new ProcedureNotFound(fqn);return balancer.run(fqn,version,args,headers)}}class Context{#headers=new Map;constructor(headers){this.#headers=headers}get headers(){return this.#headers}}class ArgumentExtractor{extract(parameters,args){const argsCopy=new Map(args),values=[];for(const parameter of parameters){const value=this.#extractArgumentValue(parameter,argsCopy);values.push(value)}if(argsCopy.size>0){const name=argsCopy.keys().next().value;throw new UnknownParameter(name)}return values}#extractArgumentValue(parameter,args,parent){return parameter instanceof NamedParameter?this.#extractNamedArgumentValue(parameter,args,parent):this.#extractDestructedArgumentValue(parameter,args)}#extractNamedArgumentValue(parameter,args,parent){const value=args.get(parameter.name);if(this.#isMissingParameterValue(parameter,value,parent))throw new MissingParameterValue(parameter.name);if(this.#isInvalidRestParameter(parameter,value,parent))throw new InvalidParameterValue(parameter.name);return args.delete(parameter.name),value}#extractDestructedArgumentValue(parameter,args){return parameter instanceof ArrayParameter?this.#extractArrayArgumentValue(parameter,args):this.#extractObjectArgumentValue(parameter,args)}#extractArrayArgumentValue(parameter,args){const values=this.#extractVariableValues(parameter,args);return void 0!==values?Object.values(values):void 0}#extractObjectArgumentValue(parameter,args){return this.#extractVariableValues(parameter,args)}#extractVariableValues(parameter,args){const useIndex=parameter instanceof ArrayParameter,values={},missingValues=[];let containsValues=!1,index=0;for(const variable of parameter.variables){const key=useIndex?index++:variable.name,value=this.#extractArgumentValue(variable,args,parameter);void 0!==value?containsValues=!0:!1===variable.isOptional&&missingValues.push(variable.name),values[key]=value}if(!0===containsValues&&missingValues.length>0)throw new MissingParameterValue(missingValues[0]);return containsValues?values:void 0}#isMissingParameterValue(parameter,value,parent){return void 0===value&&(!0!==parameter.isOptional&&!0!==parent?.isOptional)}#isInvalidRestParameter(parameter,value,parent){return!1!==parameter.name.startsWith("...")&&(void 0===parent&&value instanceof Array==!1||parent instanceof ArrayParameter&&value instanceof Array==!1||parent instanceof ObjectParameter&&value instanceof Object==!1)}}class Node extends ProcedureRuntime{}const RUNS_IN_BROWSER="undefined"!=typeof window;let _runtime,_loader=name=>ModuleLoader.import(name);class VersionParser{static parse(number){if(0===number.trim().length)return Version.DEFAULT;const parts=number.split(".");switch(parts.length){case 1:return new Version(Number.parseInt(parts[0]));case 2:return new Version(Number.parseInt(parts[0]),Number.parseInt(parts[1]));case 3:return new Version(Number.parseInt(parts[0]),Number.parseInt(parts[1]),Number.parseInt(parts[2]));default:throw new InvalidVersionNumber(number)}}}class LocalNode extends Node{#argumentConstructor;#segments=new Map;#gateway;#repository;#clientId="";constructor(url,argumentConstructor=new ArgumentExtractor){super(url),this.#argumentConstructor=argumentConstructor}getProcedureNames(){const names=new Set;for(const segment of this.#segments.values()){segment.getPublicProcedures().forEach((procedure=>names.add(procedure.fqn)))}return[...names.values()]}async loadSegment(name){const filename=createNodeFilename(name),segment=(await this.import(filename)).segment;this.addSegment(segment)}addSegment(segment){this.#segments.set(segment.id,segment)}hasProcedure(fqn){return this.getProcedureNames().includes(fqn)}#getProcedure(fqn){for(const segment of this.#segments.values())if(segment.hasProcedure(fqn))return segment.getProcedure(fqn)}async setGateway(gateway){(gateway instanceof LocalGateway||void 0!==this.url)&&await gateway.addNode(this),this.#gateway=gateway}async setRepository(repository,segmentNames){this.#clientId=await repository.registerClient(segmentNames),_runtime=this,_loader=name=>ModuleLoader.import(name);const moduleLocation=await repository.getModuleLocation(this.#clientId);ModuleLoader.setBaseUrl(moduleLocation),this.#repository=repository}import(url,base){if(void 0===this.#repository)throw new RepositoryNotAvailable;return void 0!==base&&(url=UrlRewriter.addBase(url,base)),this.#repository.importModule(this.#clientId,url)}run(fqn,version,args,headers){const procedure=this.#getProcedure(fqn);return void 0===procedure?this.#runGateway(fqn,version,args,headers):this.#runProcedure(procedure,version,args,headers)}#runGateway(fqn,version,args,headers){if(void 0===this.#gateway)throw new ProcedureNotFound(fqn);return this.#gateway.run(fqn,version,args,headers)}#runProcedure(procedure,version,args,headers){const implementation=procedure.getImplementation(version);if(void 0===implementation)throw new ImplementationNotFound(procedure.fqn,version.toString());const context=new Context(headers),values=this.#argumentConstructor.extract(implementation.parameters,args);return implementation.executable.call(context,...values)}}class Repository extends Runtime{}class ClassNotFound extends Error{constructor(name){super(`The class '${name}' could not be found`)}}class InvalidClass extends Error{constructor(name){super(`The class '${name}' is invalid`)}}class NoDeserializerFound extends Error{constructor(type){super(`No deserializer found for value of type '${type}'`)}}class NoSerializerFound extends Error{constructor(type){super(`No serializer found for value of type '${type}'`)}}class Serializer{#serializers=[];addSerializer(serializer){serializer.parent=this,this.#serializers.unshift(serializer)}async serialize(value){const serializer=this.#serializers.find((serializer=>serializer.canSerialize(value)));if(void 0===serializer)throw new NoSerializerFound(typeof value);return serializer.serialize(value)}async deserialize(value){const serializer=this.#serializers.find((serializer=>serializer.canDeserialize(value)));if(void 0===serializer)throw new NoDeserializerFound(typeof value);return serializer.deserialize(value)}}class ParentSerializerNotSet extends Error{constructor(){super("Parent serializer not set")}}class ValueSerializer{#parent;set parent(parent){this.#parent=parent}serializeOther(value){if(void 0===this.#parent)throw new ParentSerializerNotSet;return this.#parent.serialize(value)}deserializeOther(value){if(void 0===this.#parent)throw new ParentSerializerNotSet;return this.#parent.deserialize(value)}}class ArraySerializer extends ValueSerializer{canSerialize(value){return value instanceof Array}canDeserialize(value){return value instanceof Array}async serialize(array){const values=[];for(const value of array)values.push(await this.serializeOther(value));return values}async deserialize(array){return await Promise.all(array.map((async value=>await this.deserializeOther(value))))}}class ReflectionAlias{#name;#as;constructor(name,as){this.#name=name,this.#as=as}get name(){return this.#name}get as(){return this.#as}toString(){return`${this.#name} as ${this.#as}`}}class ReflectionValue{#definition;constructor(definition){this.#definition=definition}get definition(){return this.#definition}toString(){return this.#definition}}class ReflectionArray extends ReflectionValue{}class ReflectionMember{#name;#isStatic;#isPrivate;constructor(name,isStatic=!1,isPrivate=!1){this.#name=name,this.#isStatic=isStatic,this.#isPrivate=isPrivate}get name(){return this.#name}get isStatic(){return this.#isStatic}get isPrivate(){return this.#isPrivate}get isPublic(){return!1===this.#isPrivate}}class ReflectionClass extends ReflectionMember{#parentName;#scope;constructor(name,parentName,scope){super(name),this.#parentName=parentName,this.#scope=scope}get parentName(){return this.#parentName}get scope(){return this.#scope}get members(){return this.#scope.members}get declarations(){return this.#scope.declarations}get functions(){return this.#scope.functions}get getters(){return this.#scope.getters}get setters(){return this.#scope.setters}get generators(){return this.#scope.generators}get readable(){const members=new Map;return this.getters.forEach((getter=>{members.set(getter.name,getter)})),this.declarations.forEach((declaration=>{declaration.isPublic&&members.set(declaration.name,declaration)})),[...members.values()]}get writable(){const members=new Map;return this.setters.forEach((setter=>{members.set(setter.name,setter)})),this.declarations.forEach((declaration=>{declaration.isPublic&&members.set(declaration.name,declaration)})),[...members.values()]}get callable(){return this.functions.filter((funktion=>funktion.isPublic))}getMember(name){return this.#scope.getMember(name)}getDeclaration(name){return this.#scope.getDeclaration(name)}getFunction(name){return this.#scope.getFunction(name)}getGetter(name){return this.#scope.getGetter(name)}getSetter(name){return this.#scope.getSetter(name)}getGenerator(name){return this.#scope.getGenerator(name)}hasMember(name){return this.#scope.hasMember(name)}hasDeclaration(name){return this.#scope.hasDeclaration(name)}hasFunction(name){return this.#scope.hasFunction(name)}hasGetter(name){return this.#scope.hasGetter(name)}hasSetter(name){return this.#scope.hasSetter(name)}hasGenerator(name){return this.#scope.hasGenerator(name)}canRead(name){const declaration=this.getDeclaration(name);return void 0!==declaration&&declaration.isPublic||this.hasGetter(name)}canWrite(name){const declaration=this.getDeclaration(name);return void 0!==declaration&&declaration.isPublic||this.hasSetter(name)}canCall(name){const funktion=this.getFunction(name);return void 0!==funktion&&funktion.isPublic}toString(){return`class ${this.name}${void 0!==this.#parentName?` extends ${this.#parentName}`:""} { ${this.#scope.toString()} }`}}class ReflectionDeclaration extends ReflectionMember{#identifier;#value;constructor(identifier,value,isStatic=!1,isPrivate=!1){super(identifier.toString(),isStatic,isPrivate),this.#identifier=identifier,this.#value=value}get identifier(){return this.#identifier}get value(){return this.#value}toString(){return`${this.name}${this.value?" = "+this.value.toString():""}`}}class ReflectionDestructuredValue{#members;constructor(members){this.#members=members}get members(){return this.#members}toString(){return this.#members.map((member=>member.toString())).join(" , ")}}class ReflectionDestructuredArray extends ReflectionDestructuredValue{toString(){return`[ ${super.toString()} ]`}}class ReflectionDestructuredObject extends ReflectionDestructuredValue{toString(){return`{ ${super.toString()} }`}}class ReflectionExport extends ReflectionMember{#members;#from;constructor(members,from){super(""),this.#members=members,this.#from=from}get members(){return this.#members}get from(){return this.#from}toString(){return`export { ${this.#members.join(", ")} }${this.#from?` from '${this.#from}'`:""}`}}class ReflectionExpression extends ReflectionValue{}class ReflectionField{#name;#value;constructor(name,value){this.#name=name,this.#value=value}get name(){return this.#name}get value(){return this.#value}toString(){return`${this.name}${this.value?" = "+this.value.toString():""}`}}class ReflectionFunction extends ReflectionMember{#parameters;#body;#isAsync;constructor(name,parameters,body,isStatic=!1,isAsync=!1,isPrivate=!1){super(name,isStatic,isPrivate),this.#parameters=parameters,this.#body=body,this.#isAsync=isAsync}get parameters(){return this.#parameters}get body(){return this.#body}get isAsync(){return this.#isAsync}toString(){const parameters=this.parameters.map((parameter=>parameter.toString()));return`${this.isAsync?"async ":""}${this.name}(${parameters.join(", ")}) { ${this.body} }`}}class ReflectionGenerator extends ReflectionFunction{toString(){const parameters=this.parameters.map((parameter=>parameter.toString()));return`${this.isAsync?"async ":""}${this.name}*(${parameters.join(", ")}) { ${this.body} }`}}class ReflectionGetter extends ReflectionFunction{toString(){return`get ${super.toString()}`}}class ReflectionImport extends ReflectionMember{#members;#from;constructor(members,from){super(""),this.#members=members,this.#from=from}get members(){return this.#members}get from(){return this.#from}toString(){return`import { ${this.#members.map((member=>member.toString())).join(", ")} } from '${this.#from}';`}}class ReflectionModule{#scope;constructor(scope){this.#scope=scope}get scope(){return this.#scope}get members(){return this.#scope.members}get exportedMembers(){return this.#filterExported(this.#scope.members)}get imports(){return this.#scope.imports}get exports(){return this.#scope.exports}get declarations(){return this.#scope.declarations}get exportedDeclarations(){return this.#filterExported(this.#scope.declarations)}get functions(){return this.#scope.functions}get exportedFunctions(){return this.#filterExported(this.#scope.functions)}get generators(){return this.#scope.generators}get exportedGenerators(){return this.#filterExported(this.#scope.generators)}get classes(){return this.#scope.classes}get exportedClasses(){return this.#filterExported(this.#scope.classes)}get exported(){const exported=new Map;for(const exportItem of this.exports)for(const alias of exportItem.members){const member=this.getMember(alias.name);void 0!==member&&exported.set(alias.as,member)}return exported}getMember(name){return this.#scope.getMember(name)}getDeclaration(name){return this.#scope.getDeclaration(name)}getFunction(name){return this.#scope.getFunction(name)}getGenerator(name){return this.#scope.getGenerator(name)}getClass(name){return this.#scope.getClass(name)}hasMember(name){return this.#scope.hasMember(name)}hasDeclaration(name){return this.#scope.hasDeclaration(name)}hasFunction(name){return this.#scope.hasFunction(name)}hasGenerator(name){return this.#scope.hasGenerator(name)}hasClass(name){return this.#scope.hasClass(name)}isExported(member){for(const exportItem of this.exports)for(const alias of exportItem.members)if(alias.name===member.name)return!0;return!1}getExported(name){for(const exportItem of this.exports)for(const alias of exportItem.members)if(alias.as===name)return this.getMember(alias.name)}#filterExported(members){return members.filter((member=>this.isExported(member)))}}class ReflectionObject extends ReflectionValue{}class ReflectionSetter extends ReflectionFunction{toString(){return`set ${super.toString()}`}}class ItemList{#items;#position;constructor(items){this.#items=items,this.#position=0}get items(){return this.#items}get position(){return this.#position}get size(){return this.#items.length}get eol(){return this.#position>=this.#items.length}get current(){return this.#items[this.#position]}get next(){return this.#items[this.#position+1]}get previous(){return this.#items[this.#position-1]}notAtEnd(){return!1===this.eol}get(index){return this.#items[index]}step(amount=1){return this.#position+=amount,this.current}stepBack(amount=1){return this.#position-=amount,this.current}hasNext(){return this.#position+1<this.#items.length}}class CharList extends ItemList{constructor(code){super(code.split(""))}}class Token{#type;#value;#start;#end;constructor(type,value,start,end){this.#type=type,this.#value=value,this.#start=start,this.#end=end}get type(){return this.#type}get value(){return this.#value}get start(){return this.#start}get end(){return this.#end}isType(type){return this.#type===type}hasValue(value){return this.#value===value}toString(){return`${this.#value}`}}class TokenList extends ItemList{}const Comment={SINGLE:"//",MULTI_START:"/*",MULTI_END:"*/"},Comments=Object.values(Comment);const Punctuation={COMMA:",",COLON:":",SEMICOLON:";",DOT:".",QUESTION_MARK:"?",EXCLAMATION_MARK:"!",LEFT_PARENTHESIS:"(",RIGHT_PARENTHESIS:")",LEFT_BRACKET:"[",RIGHT_BRACKET:"]",LEFT_BRACE:"{",RIGHT_BRACE:"}",SINGLE_QUOTE:"'",DOUBLE_QUOTE:'"',BACKTICK:"`"};Object.values(Punctuation);const Divider={SCOPE:Punctuation.COLON,SEPARATOR:Punctuation.COMMA,TERMINATOR:Punctuation.SEMICOLON},Divisions=Object.values(Divider);function isDivider(value){return Divisions.includes(value)}const Empty={UNDEFINED:void 0,NULL:null,STRING:""},Empties=Object.values(Empty);function isEmpty(value){return Empties.includes(value)}const Group={OPEN:Punctuation.LEFT_PARENTHESIS,CLOSE:Punctuation.RIGHT_PARENTHESIS};function isGroup(value){return value===Group.OPEN||value===Group.CLOSE}const Keyword={EXPORT:"export",DEFAULT:"default",CLASS:"class",FUNCTION:"function",CONST:"const",LET:"let",VAR:"var",AS:"as",FROM:"from",IMPORT:"import",GET:"get",SET:"set",EXTENDS:"extends",STATIC:"static",ASYNC:"async",RETURN:"return"},Keywords=Object.values(Keyword);function isKeyword(value){return Keywords.includes(value)}const List={OPEN:Punctuation.LEFT_BRACKET,CLOSE:Punctuation.RIGHT_BRACKET};function isList(value){return value===List.OPEN||value===List.CLOSE}const Literals=Object.values({SINGLE:"'",DOUBLE:'"',BACKTICK:"`"});function isLiteral(value){return Literals.includes(value)}const Operator={ADD:"+",ARROW:"=>",ASSIGN:"=",ASSIGN_ADD:"+=",ASSIGN_BITWISE_AND:"&=",ASSIGN_BITWISE_OR:"|=",ASSIGN_DIVIDE:"/=",ASSIGN_LEFT_SHIFT:"<<=",ASSIGN_LOGICAL_AND:"&&=",ASSIGN_LOGICAL_OR:"||=",ASSIGN_MODULO:"%=",ASSIGN_MULTIPLY:"*=",ASSIGN_RIGHT_SHIFT:">>=",ASSIGN_SUBTRACT:"-=",ASSIGN_XOR:"^=",BITWISE_AND:"&",BITWISE_OR:"|",DECREMENT:"--",DIVIDE:"/",EQUAL:"==",EQUAL_STRICT:"===",GREATER:">",GREATER_EQUAL:">=",INCREMENT:"++",LEFT_SHIFT:"<<",LESS:"<",LESS_EQUAL:"<=",LOGICAL_AND:"&&",LOGICAL_OR:"||",MODULO:"%",MULTIPLY:"*",NOT:"!",NOT_EQUAL:"!=",NOT_EQUAL_STRICT:"!==",RIGHT_SHIFT:">>",SUBTRACT:"-",TERNARY:"?",XOR:"^"},Operators=Object.values(Operator);function isOperator(value){return Operators.includes(value)}const Scope={OPEN:Punctuation.LEFT_BRACE,CLOSE:Punctuation.RIGHT_BRACE};function isScope(value){return value===Scope.OPEN||value===Scope.CLOSE}const TokenType={COMMENT:"comment",DIVIDER:"divider",GROUP:"group",IDENTIFIER:"identifier",KEYWORD:"keyword",LIST:"list",LITERAL:"literal",OPERATOR:"operator",REGEX:"regex",SCOPE:"scope",WHITESPACE:"whitespace"},Whitespace={SPACE:" ",TAB:"\t",NEWLINE:"\n",CARRIAGE_RETURN:"\r"},Whitespaces=Object.values(Whitespace);function isWhitespace(value){return Whitespaces.includes(value)}class Lexer{tokenize(code,omitWhitespace=!0,omitComments=!0){const charList=new CharList(code),tokens=[];let last;for(;charList.notAtEnd();){const token=this.#getNextToken(charList,last);if(void 0===token)break;omitWhitespace&&token.isType(TokenType.WHITESPACE)?charList.step():(omitComments&&token.isType(TokenType.COMMENT)||(tokens.push(token),this.#isCodeToken(token)&&(last=token)),charList.step())}return new TokenList(tokens)}#isCodeToken(token){return!1===[TokenType.WHITESPACE,TokenType.COMMENT].includes(token.type)}#getNextToken(charList,lastToken){const char=charList.current,start=charList.position;if(isWhitespace(char)){const end=charList.position;return new Token(TokenType.WHITESPACE,char,start,end)}if(function(value){return Comments.includes(value)}(char+charList.next)){const value=this.#readComment(charList),end=charList.position;return new Token(TokenType.COMMENT,value,start,end)}if(this.#startsRegex(char,lastToken)){const value=this.#readRegex(charList),end=charList.position;return new Token(TokenType.REGEX,value,start,end)}if(isLiteral(char)){const value=this.#readLiteral(charList),end=charList.position;return new Token(TokenType.LITERAL,value,start,end)}if(isOperator(char)){const value=this.#readOperation(charList),end=charList.position;return new Token(TokenType.OPERATOR,value,start,end)}if(isDivider(char)){const end=charList.position;return new Token(TokenType.DIVIDER,char,start,end)}if(isGroup(char)){const end=charList.position;return new Token(TokenType.GROUP,char,start,end)}if(isScope(char)){const end=charList.position;return new Token(TokenType.SCOPE,char,start,end)}if(isList(char)){const end=charList.position;return new Token(TokenType.LIST,char,start,end)}if(isEmpty(char))return;const value=this.#readIdentifier(charList),type=isKeyword(value)?TokenType.KEYWORD:TokenType.IDENTIFIER,end=charList.position;return new Token(type,value,start,end)}#readComment(charList){const isMulti=charList.current+charList.next===Comment.MULTI_START,terminator=isMulti?Comment.MULTI_END:Whitespace.NEWLINE;let value=isMulti?Comment.MULTI_START:Comment.SINGLE;for(charList.step(2);charList.notAtEnd();){const char=charList.current;if((isMulti?char+charList.next:char)===terminator){charList.step(terminator.length-1);break}value+=char,charList.step()}return isMulti?value+Comment.MULTI_END:value.trim()}#startsRegex(char,lastToken){return char===Operator.DIVIDE&&(void 0===lastToken||([TokenType.OPERATOR,TokenType.DIVIDER,TokenType.KEYWORD].includes(lastToken.type)||[Group.OPEN,List.OPEN].includes(lastToken.value)))}#endsRegex(char){return isWhitespace(char)||char==Punctuation.DOT||!1===this.#isIdentifier(char)}#readRegex(charList){let value=charList.current,closed=!1;for(charList.step();charList.notAtEnd();){const current=charList.current,previous=charList.previous;if(current===Operator.DIVIDE&&"\\"!==previous)closed=!0;else if(!0===closed&&this.#endsRegex(current)){charList.stepBack();break}value+=current,charList.step()}return value}#readLiteral(charList){const identifier=charList.current;let value=identifier,escaped=!1;for(charList.step();charList.notAtEnd();){const char=charList.current;if(!1===escaped){if(char===identifier){value+=char;break}"\\"===char&&(escaped=!0)}else escaped=!1;value+=char,charList.step()}return value}#isIdentifier(char){return!1===(isEmpty(char)||isWhitespace(char)||isOperator(char)||isLiteral(char)||isDivider(char)||isGroup(char)||isScope(char)||isList(char))}#readIdentifier(charList){let value="";for(;charList.notAtEnd();){const char=charList.current;if(!1===this.#isIdentifier(char)){charList.stepBack();break}value+=char,charList.step()}return value}#readOperation(charList){let value=charList.current;for(charList.step();charList.notAtEnd();){const char=charList.current;if(!1===isOperator(char)||!1===isOperator(value+char)){charList.stepBack();break}value+=char,charList.step()}return value}}class ExpectedKeyword extends Error{constructor(value,position){super(`Expected keyword '${value}' at position ${position}`)}}class ExpectedToken extends Error{constructor(value,position){super(`Expected token '${value}' at position ${position}`)}}class UnexpectedKeyword extends Error{constructor(keyword,position){super(`Unexpected keyword '${keyword}' at position ${position}`)}}class UnexpectedParseResult extends Error{constructor(expected){super(`The given code does not contain ${expected}`)}}class UnexpectedToken extends Error{constructor(value,position){super(`Unexpected token '${value}' at position ${position}`)}}const IMPORT_NAME=ReflectionImport.name,EXPORT_NAME=ReflectionExport.name,DECLARATION_NAME=ReflectionDeclaration.name,FUNCTION_NAME=ReflectionFunction.name,GETTER_NAME=ReflectionGetter.name,SETTER_NAME=ReflectionSetter.name,GENERATOR_NAME=ReflectionGenerator.name,CLASS_NAME=ReflectionClass.name;class ReflectionScope{#members;constructor(members){this.#members=members}get members(){return this.#members}get imports(){return this.#members.filter((member=>member.constructor.name===IMPORT_NAME))}get exports(){return this.#members.filter((member=>member.constructor.name===EXPORT_NAME))}get declarations(){return this.#members.filter((member=>member.constructor.name===DECLARATION_NAME))}get functions(){return this.#members.filter((member=>member.constructor.name===FUNCTION_NAME))}get getters(){return this.#members.filter((member=>member.constructor.name===GETTER_NAME))}get setters(){return this.#members.filter((member=>member.constructor.name===SETTER_NAME))}get generators(){return this.#members.filter((member=>member.constructor.name===GENERATOR_NAME))}get classes(){return this.#members.filter((member=>member.constructor.name===CLASS_NAME))}getMember(name){return this.#members.find((member=>member.name===name))}getDeclaration(name){return this.declarations.find((member=>member.name===name))}getFunction(name){return this.functions.find((member=>member.name===name))}getGetter(name){return this.getters.find((member=>member.name===name))}getSetter(name){return this.setters.find((member=>member.name===name))}getGenerator(name){return this.generators.find((member=>member.name===name))}getClass(name){return this.classes.find((member=>member.name===name))}hasMember(name){return void 0!==this.getMember(name)}hasDeclaration(name){return void 0!==this.getDeclaration(name)}hasFunction(name){return void 0!==this.getFunction(name)}hasGetter(name){return void 0!==this.getGetter(name)}hasSetter(name){return void 0!==this.getSetter(name)}hasGenerator(name){return void 0!==this.getGenerator(name)}hasClass(name){return void 0!==this.getClass(name)}toString(){return this.#members.map((member=>member.toString())).join("\n")}}class Parser{#lexer;constructor(lexer=new Lexer){this.#lexer=lexer}parse(code){const tokenList=this.#lexer.tokenize(code),scope=this.#parseScope(tokenList);return new ReflectionModule(scope)}parseFirst(code){const tokenList=this.#lexer.tokenize(code);return this.#parseNext(tokenList)}parseValue(code){const model=this.parseFirst(code);if(model instanceof ReflectionValue==!1)throw new UnexpectedParseResult("a value definition");return model}parseImport(code){const model=this.parseFirst(code);if(model instanceof ReflectionImport==!1)throw new UnexpectedParseResult("an import definition");return model}parseExport(code){const model=this.parseFirst(code);if(model instanceof ReflectionExport==!1)throw new UnexpectedParseResult("an export definition");return model}parseDeclaration(code){const model=this.parseFirst(code);if(model instanceof ReflectionDeclaration==!1)throw new UnexpectedParseResult("a declaration definition");return model}parseFunction(code){const tokenList=this.#lexer.tokenize(code),model=this.#parseMember(tokenList);if(model instanceof ReflectionFunction==!1)throw new UnexpectedParseResult("a function definition");return model}parseClass(code){const tokenList=this.#lexer.tokenize(code),model=this.#parseMember(tokenList);if(model instanceof ReflectionClass==!1)throw new UnexpectedParseResult("a class definition");return model}#parseScope(tokenList){const members=[];for(;tokenList.notAtEnd();){const member=this.#parseNext(tokenList);member instanceof ReflectionMember&&members.push(member)}return new ReflectionScope(members)}#parseNext(tokenList,isAsync=!1){const token=tokenList.current;if(token.isType(TokenType.LITERAL))return this.#parseExpression(tokenList);if(token.isType(TokenType.IDENTIFIER)){const next=tokenList.next;return void 0!==next&&next.hasValue(Operator.ARROW)?this.#parseArrowFunction(tokenList,isAsync):this.#parseExpression(tokenList)}if(token.isType(TokenType.KEYWORD))return token.hasValue(Keyword.ASYNC)?(tokenList.step(),this.#parseNext(tokenList,!0)):token.hasValue(Keyword.RETURN)?this.#parseExpression(tokenList):this.#parseMember(tokenList,isAsync);if(token.isType(TokenType.REGEX))return this.#parseExpression(tokenList);if(token.hasValue(Group.OPEN)){const next=this.#peekAfterBlock(tokenList,Group.OPEN,Group.CLOSE);return void 0!==next&&next.hasValue(Operator.ARROW)?this.#parseArrowFunction(tokenList,isAsync):this.#parseExpression(tokenList)}if(token.hasValue(Scope.OPEN))return this.#parseObject(tokenList);if(token.hasValue(List.OPEN))return this.#parseArray(tokenList);if(token.hasValue(Operator.NOT)||token.hasValue(Operator.SUBTRACT))return this.#parseExpression(tokenList);if(!isDivider(token.value))throw new UnexpectedToken(token.value,token.start);tokenList.step()}#parseMember(tokenList,isAsync=!1){const token=tokenList.current;switch(tokenList.step(),token.value){case Keyword.IMPORT:return this.#parseImport(tokenList);case Keyword.EXPORT:return this.#parseExport(tokenList);case Keyword.CLASS:return this.#parseClass(tokenList);case Keyword.FUNCTION:return this.#parseFunction(tokenList,isAsync);case Keyword.VAR:case Keyword.LET:case Keyword.CONST:return this.#parseDeclaration(tokenList,!1,!0);case Keyword.ASYNC:return this.#parseMember(tokenList,!0);default:throw new UnexpectedKeyword(token.value,token.start)}}#parseImport(tokenList){const members=[];let token=tokenList.current;if(token.isType(TokenType.LITERAL))return new ReflectionImport(members,token.value);if(token.hasValue(Group.OPEN)){token=tokenList.step();const from=token.value;return tokenList.step(2),new ReflectionImport(members,from)}if(!1===token.hasValue(Scope.OPEN)){const name=token.hasValue(Operator.MULTIPLY)?Operator.MULTIPLY:"default";let as=token.value;token=tokenList.step(),token.hasValue(Keyword.AS)&&(token=tokenList.step(),as=token.value,token=tokenList.step()),members.push(new ReflectionAlias(name,as))}if(token.hasValue(Divider.SEPARATOR)&&(token=tokenList.step()),token.hasValue(Scope.OPEN)){const aliases=this.#parseAliasList(tokenList);members.push(...aliases),token=tokenList.current}if(!1===token.hasValue(Keyword.FROM))throw new ExpectedKeyword(Keyword.FROM,token.start);token=tokenList.step();const from=token.value;return tokenList.step(),new ReflectionImport(members,from)}#parseExport(tokenList){switch(tokenList.current.value){case Keyword.DEFAULT:return tokenList.step(),this.#parseSingleExport(tokenList,!0);case Scope.OPEN:return this.#parseMultiExport(tokenList);default:return this.#parseSingleExport(tokenList,!1)}}#parseSingleExport(tokenList,isDefault){let token=tokenList.current,stepSize=0;var value;token.hasValue(Keyword.ASYNC)&&(token=tokenList.step(),stepSize++),((value=token.value)===Keyword.CLASS||value===Keyword.FUNCTION||value===Keyword.CONST||value===Keyword.LET||value===Keyword.VAR)&&(token=tokenList.step(),stepSize++);const name=token.isType(TokenType.IDENTIFIER)?token.value:"",as=isDefault?"default":name;let from;token=tokenList.step(),void 0!==token&&token.hasValue(Keyword.FROM)&&(token=tokenList.step(),from=token.value),stepSize>0&&(stepSize++,tokenList.stepBack(stepSize));const alias=new ReflectionAlias(name,as);return new ReflectionExport([alias],from)}#parseMultiExport(tokenList){const members=this.#parseAliasList(tokenList);let from,token=tokenList.current;return void 0!==token&&token.hasValue(Keyword.FROM)&&(token=tokenList.step(),from=token.value),tokenList.step(),new ReflectionExport(members,from)}#parseAliasList(tokenList){const aliases=[];let token=tokenList.step();for(;tokenList.notAtEnd();){if(token.hasValue(Scope.CLOSE)){tokenList.step();break}if(token.hasValue(Divider.SEPARATOR)){token=tokenList.step();continue}const alias=this.#parseAlias(tokenList);aliases.push(alias),token=tokenList.step()}return aliases}#parseAlias(tokenList){let token=tokenList.current;const name=token.value;let as=name;return tokenList.next.hasValue(Keyword.AS)&&(token=tokenList.step(2),as=token.value),new ReflectionAlias(name,as)}#parseDeclaration(tokenList,isStatic,parseMultiple=!1){let value,token=tokenList.current,identifier="",isPrivate=!1;return token.hasValue(List.OPEN)?(identifier=this.#parseDestructuredArray(tokenList),token=tokenList.current):token.hasValue(Scope.OPEN)?(identifier=this.#parseDestructuredObject(tokenList),token=tokenList.current):(isPrivate=token.value.startsWith("#"),identifier=isPrivate?token.value.substring(1):token.value,token=tokenList.step()),token.hasValue(Operator.ASSIGN)&&(tokenList.step(),value=this.#parseNext(tokenList,!1),token=tokenList.current),void 0!==token&&(token.hasValue(Divider.TERMINATOR)?tokenList.step():!0===parseMultiple&&token.hasValue(Divider.SEPARATOR)&&(tokenList.step(),this.#parseDeclaration(tokenList,isStatic,!0))),value instanceof ReflectionGenerator?new ReflectionGenerator(identifier.toString(),value.parameters,value.body,isStatic,value.isAsync,isPrivate):value instanceof ReflectionFunction?new ReflectionFunction(identifier.toString(),value.parameters,value.body,isStatic,value.isAsync,isPrivate):value instanceof ReflectionClass?new ReflectionClass(identifier.toString(),value.parentName,value.scope):new ReflectionDeclaration(identifier,value,isStatic,isPrivate)}#parseFunction(tokenList,isAsync,isStatic=!1,isGetter=!1,isSetter=!1){let token=tokenList.current,name="",isGenerator=!1,isPrivate=!1;token.hasValue(Operator.MULTIPLY)&&(isGenerator=!0,token=tokenList.step()),token.isType(TokenType.IDENTIFIER)&&(isPrivate=token.value.startsWith("#"),name=isPrivate?token.value.substring(1):token.value,token=tokenList.step());const parameters=this.#parseParameters(tokenList,Group.CLOSE);if(token=tokenList.current,!1===token.hasValue(Scope.OPEN))throw new ExpectedToken(Scope.OPEN,token.start);const body=this.#parseBlock(tokenList,Scope.OPEN,Scope.CLOSE);return isGenerator?new ReflectionGenerator(name,parameters,body,isStatic,isAsync,isPrivate):isGetter?new ReflectionGetter(name,parameters,body,isStatic,isAsync,isPrivate):isSetter?new ReflectionSetter(name,parameters,body,isStatic,isAsync,isPrivate):new ReflectionFunction(name,parameters,body,isStatic,isAsync,isPrivate)}#parseArrowFunction(tokenList,isAsync){let parameters,token=tokenList.current;if(token.hasValue(Group.OPEN)?(parameters=this.#parseParameters(tokenList,Group.CLOSE),token=tokenList.current):(parameters=[new ReflectionField(token.value,void 0)],token=tokenList.step()),!1===token.hasValue(Operator.ARROW))throw new ExpectedToken(Operator.ARROW,token.start);token=tokenList.step();const body=token.hasValue(Scope.OPEN)?this.#parseBlock(tokenList,Scope.OPEN,Scope.CLOSE):this.#parseExpression(tokenList).definition;return new ReflectionFunction("",parameters,body,!1,isAsync,!1)}#parseParameters(tokenList,closeId){const parameters=[];for(tokenList.step();tokenList.notAtEnd();){const token=tokenList.current;if(token.hasValue(closeId)){tokenList.step();break}if(token.hasValue(Divider.SEPARATOR)){tokenList.step();continue}let parameter;parameter=token.hasValue(Scope.OPEN)?this.#parseDestructuredObject(tokenList):token.hasValue(List.OPEN)?this.#parseDestructuredArray(tokenList):this.#parseField(tokenList),parameters.push(parameter)}return parameters}#parseClass(tokenList){let parent,token=tokenList.current,name="";if(token.isType(TokenType.IDENTIFIER)&&(name=token.value,token=tokenList.step()),token.hasValue(Keyword.EXTENDS)&&(token=tokenList.step(),parent=token.value,token=tokenList.step()),!1===token.hasValue(Scope.OPEN))throw new ExpectedToken(Scope.OPEN,token.start);const scope=this.#parseClassScope(tokenList);return new ReflectionClass(name,parent,scope)}#parseClassScope(tokenList){let token=tokenList.step();const members=[];for(;tokenList.notAtEnd();){if(token.hasValue(Scope.CLOSE)){tokenList.step();break}const member=this.#parseClassMember(tokenList);members.push(member),token=tokenList.current}return new ReflectionScope(members)}#parseClassMember(tokenList){let token=tokenList.current,isAsync=!1,isStatic=!1,isGetter=!1,isSetter=!1;for(;tokenList.notAtEnd();){if(token.hasValue(Keyword.STATIC))isStatic=!0;else if(token.hasValue(Keyword.ASYNC))isAsync=!0;else if(token.hasValue(Keyword.GET))isGetter=!0;else{if(!token.hasValue(Keyword.SET)){if(token.hasValue(Operator.MULTIPLY))return this.#parseFunction(tokenList,isAsync,isStatic,!1,!1);break}isSetter=!0}token=tokenList.step()}return tokenList.next.hasValue(Group.OPEN)?this.#parseFunction(tokenList,isAsync,isStatic,isGetter,isSetter):this.#parseDeclaration(tokenList,isStatic)}#parseArray(tokenList){const items=this.#parseBlock(tokenList,List.OPEN,List.CLOSE);return new ReflectionArray(items)}#parseDestructuredArray(tokenList){const fields=this.#parseParameters(tokenList,List.CLOSE);return new ReflectionDestructuredArray(fields)}#parseObject(tokenList){const fields=this.#parseBlock(tokenList,Scope.OPEN,Scope.CLOSE);return new ReflectionObject(fields)}#parseDestructuredObject(tokenList){const fields=this.#parseParameters(tokenList,Scope.CLOSE);return new ReflectionDestructuredObject(fields)}#parseField(tokenList){let token=tokenList.current;const name=token.value;let value;return token=tokenList.step(),token.hasValue(Operator.ASSIGN)&&(tokenList.step(),value=this.#parseNext(tokenList,!1)),new ReflectionField(name,value)}#parseExpression(tokenList){let token=tokenList.current,code="";for(;tokenList.notAtEnd();){if(token.hasValue(List.OPEN)){code+=this.#parseBlock(tokenList,List.OPEN,List.CLOSE)+" ",token=tokenList.current}else if(token.hasValue(Group.OPEN)){code+=this.#parseBlock(tokenList,Group.OPEN,Group.CLOSE)+" ",token=tokenList.current}else if(token.hasValue(Scope.OPEN)){code+=this.#parseBlock(tokenList,Scope.OPEN,Scope.CLOSE)+" ",token=tokenList.current}else code+=token.toString()+" ",token=tokenList.step();if(void 0===token||this.#atEndOfStatement(token))break}return new ReflectionExpression(code.trim())}#parseBlock(tokenList,openId,closeId){let token=tokenList.step(),code=openId+" ";for(;tokenList.notAtEnd();)if(token.hasValue(openId))code+=this.#parseBlock(tokenList,openId,closeId)+" ",token=tokenList.current;else{if(token.hasValue(closeId))return tokenList.step(),code+=closeId,code;code+=token.toString()+" ",token=tokenList.step()}return code}#peekAfterBlock(tokenList,openId,closeId){const start=tokenList.position;this.#parseBlock(tokenList,openId,closeId);const token=tokenList.current,end=tokenList.position;return tokenList.stepBack(end-start),token}#atEndOfStatement(token){return[Divider.TERMINATOR,Divider.SEPARATOR].includes(token.value)||[List.CLOSE,Group.CLOSE,Scope.CLOSE].includes(token.value)||isKeyword(token.value)}}class ClassMerger{merge(model,parent){const declarations=this.#mergeDeclarations(model.declarations,parent.declarations),functions=this.#mergeFunctions(model.functions,parent.functions),getters=this.#mergeFunctions(model.getters,parent.getters),setters=this.#mergeFunctions(model.setters,parent.setters),members=[...declarations.values(),...functions.values(),...getters.values(),...setters.values()];return new ReflectionClass(model.name,parent.name,new ReflectionScope(members))}#mergeDeclarations(model,parent){const declarations=new Map;return parent.forEach((declaration=>declarations.set(declaration.name,declaration))),model.forEach((declaration=>declarations.set(declaration.name,declaration))),[...declarations.values()]}#mergeFunctions(model,parent){const functions=new Map;return parent.forEach((funktion=>functions.set(funktion.name,funktion))),model.forEach((funktion=>functions.set(funktion.name,funktion))),[...functions.values()]}}class Reflector{#parser;#merger;constructor(parser=new Parser,merger=new ClassMerger){this.#parser=parser,this.#merger=merger}parse(code){return this.#parser.parse(code)}parseClass(code){return this.#parser.parseClass(code)}parseFunction(code){return this.#parser.parseFunction(code)}parseDeclaration(code){return this.#parser.parseDeclaration(code)}parseImport(code){return this.#parser.parseImport(code)}parseExport(code){return this.#parser.parseExport(code)}fromModule(module,inherit=!1){const entries=Object.entries(module),members=[];for(const[key,member]of entries){if("function"!=typeof member.toString)continue;const code=member.toString();if(code.startsWith("class"))members.push(this.fromClass(member,inherit));else if(code.startsWith("function"))members.push(this.fromFunction(member));else{const expression=new ReflectionExpression(code);members.push(new ReflectionDeclaration(key,expression))}}return new ReflectionModule(new ReflectionScope(members))}fromClass(clazz,inherit=!1){const model=this.isClass(clazz)?this.#reflectStatic(clazz):this.#reflectDynamic(clazz);if(!1===inherit)return model;const parentClazz=this.getParentClass(clazz);if(""===parentClazz.name)return model;const parentModel=this.fromClass(parentClazz,!0);return this.#merger.merge(model,parentModel)}fromObject(object,inherit=!0){const clazz=this.getClass(object);return this.fromClass(clazz,inherit)}fromFunction(funktion){const code=funktion.toString();return this.parseFunction(code)}createInstance(clazz,args=[]){return new clazz(...args)}getClass(object){return object.constructor}getParentClass(clazz){return Object.getPrototypeOf(clazz)}isClassObject(object){return this.isClass(object.constructor)}isFunctionObject(object){return this.isFunction(object.constructor)}isClass(clazz){return clazz.toString().startsWith("class")}isFunction(clazz){return clazz.toString().startsWith("function")||clazz.toString().startsWith("async function")}#reflectStatic(clazz){const code=clazz.toString();return this.parseClass(code)}#reflectDynamic(clazz){const object=this.createInstance(clazz),members=this.#getMembers(clazz,object),scope=new ReflectionScope(members);return new ReflectionClass(clazz.name,void 0,scope)}#getMembers(clazz,object){return[...this.#getDeclarations(object),...this.#getFunctions(clazz)]}#getDeclarations(object){const fieldNames=Object.getOwnPropertyNames(object),values=object,models=[];for(const fieldName of fieldNames){const content=values[fieldName],value=void 0!==content?new ReflectionValue(String(content)):void 0,model=new ReflectionDeclaration(fieldName,value);models.push(model)}return models}#getFunctions(clazz){const functionDescriptions=Object.getOwnPropertyDescriptors(clazz.prototype),models=[];for(const functionName in functionDescriptions){const description=functionDescriptions[functionName],funktion=description.value;if(funktion instanceof Function==!1)continue;const model=this.fromFunction(funktion);void 0!==description.get?models.push(new ReflectionGetter(model.name,model.parameters,model.body,model.isStatic,model.isAsync,model.isPrivate)):void 0!==description.set?models.push(new ReflectionSetter(model.name,model.parameters,model.body,model.isStatic,model.isAsync,model.isPrivate)):models.push(model)}return models}}const reflector$1=new Reflector;class ClassSerializer extends ValueSerializer{#classLoader;constructor(classLoader){super(),this.#classLoader=classLoader}canSerialize(value){return value instanceof Object&&reflector$1.isClassObject(value)}canDeserialize(value){const object=value;return object instanceof Object&&!0===object.serialized&&"string"==typeof object.name&&object.args instanceof Array&&object.fields instanceof Object&&object.fields.constructor===Object}async serialize(object){const clazz=reflector$1.getClass(object),model=reflector$1.fromClass(clazz,!0),parameterNames=this.#extractParameterNames(model);return{serialized:!0,name:clazz.name,source:clazz.source,args:await this.#extractArguments(model,parameterNames,object),fields:await this.#extractFields(model,parameterNames,object)}}#extractParameterNames(model){const constructor=model.getFunction("constructor");return(constructor?.parameters??[]).map((parameter=>parameter.name))}async#extractArguments(model,includeNames,object){const args=[];for(const name of includeNames){const objectValue=model.canRead(name)?await this.serializeOther(object[name]):void 0;args.push(objectValue)}return args}async#extractFields(model,excludeNames,object){const fields={};for(const property of model.writable){const name=property.name;excludeNames.includes(name)||!1===model.canRead(name)||(fields[name]=await this.serializeOther(object[name]))}return fields}async deserialize(object){const clazz=await this.#getClass(object);if(void 0===clazz)throw new ClassNotFound(object.name);if(clazz instanceof Function==!1)throw new InvalidClass(object.name);const args=await Promise.all(object.args.map((async value=>await this.deserializeOther(value)))),instance=reflector$1.createInstance(clazz,args);for(const name in object.fields){const fieldValue=object.fields[name];instance[name]=await this.deserializeOther(fieldValue)}return instance}async#getClass(clazz){return void 0===clazz.source?globalThis[clazz.name]:this.#classLoader.loadClass(clazz)}}class InvalidDateString extends Error{constructor(dateString){super(`Invalid date string '${dateString}'`)}}class DateSerializer extends ValueSerializer{canSerialize(value){return value instanceof Date}canDeserialize(value){const date=value;return date instanceof Object&&!0===date.serialized&&"Date"===date.name&&"string"==typeof date.value}async serialize(date){return{serialized:!0,name:"Date",value:date.toISOString()}}async deserialize(object){const date=new Date(object.value);if("Invalid Date"===date.toString())throw new InvalidDateString(object.value);return date}}class ErrorSerializer extends ValueSerializer{canSerialize(value){if(value instanceof Object==!1)return!1;const error=value;return error.constructor===Error||error.constructor===EvalError||error.constructor===RangeError||error.constructor===ReferenceError||error.constructor===SyntaxError||error.constructor===TypeError||error.constructor===URIError||error.constructor===AggregateError}canDeserialize(value){const error=value;return error instanceof Object&&!0===error.serialized&&"Error"===error.name&&error.type in globalThis}async serialize(error){return{serialized:!0,name:"Error",type:error.constructor.name,stack:error.stack,message:error.message,cause:error.cause}}async deserialize(object){const error=new(0,globalThis[object.type]);return error.stack=object.stack,error.message=object.message,error.cause=object.cause,error}}class MapSerializer extends ValueSerializer{canSerialize(value){return value instanceof Map}canDeserialize(value){const map=value;return map instanceof Object&&!0===map.serialized&&"Map"===map.name&&map.entries instanceof Object&&map.entries.keys instanceof Array&&map.entries.values instanceof Array}async serialize(map){const keys=[],values=[];for(const[key,value]of map)keys.push(await this.serializeOther(key)),values.push(await this.serializeOther(value));return{serialized:!0,name:"Map",entries:{keys:keys,values:values}}}async deserialize(object){const keys=object.entries.keys,values=object.entries.values,result=new Map;for(let index=0;index<keys.length;index++){const key=await this.deserializeOther(keys[index]),value=await this.deserializeOther(values[index]);result.set(key,value)}return result}}class ObjectSerializer extends ValueSerializer{canSerialize(value){return value instanceof Object&&value.constructor===Object}canDeserialize(value){return value instanceof Object&&value.constructor===Object}async serialize(object){const result={};for(const key in object){const value=object[key];result[key]=await this.serializeOther(value)}return result}async deserialize(object){const result={};for(const key in object){const value=object[key];result[key]=await this.deserializeOther(value)}return result}}class PrimitiveSerializer extends ValueSerializer{canSerialize(value){return value instanceof Object==!1}canDeserialize(value){return value instanceof Object==!1}async serialize(primitive){return primitive}async deserialize(primitive){return primitive}}class SetSerializer extends ValueSerializer{canSerialize(value){return value instanceof Set}canDeserialize(value){const set=value;return set instanceof Object&&!0===set.serialized&&"Set"===set.name&&set.values instanceof Array}async serialize(set){const values=[];for(const value of set.values())values.push(await this.serializeOther(value));return{serialized:!0,name:"Set",values:values}}async deserialize(object){const values=await Promise.all(object.values.map((async value=>await this.deserializeOther(value))));return new Set([...values])}}const reflector=new Reflector;class ArrayBufferSerializer extends ValueSerializer{canSerialize(value){return value instanceof Int8Array||value instanceof Uint8Array||value instanceof Uint8ClampedArray||value instanceof Int16Array||value instanceof Uint16Array||value instanceof Int32Array||value instanceof Uint32Array||value instanceof Float32Array||value instanceof Float64Array||value instanceof BigInt64Array||value instanceof BigUint64Array}canDeserialize(value){const array=value;return array instanceof Object&&!0===array.serialized&&"TypedArray"===array.name&&array.type in globalThis&&array.bytes instanceof Array}async serialize(array){const type=array.constructor.name,view=new DataView(array.buffer),bytes=[];for(let index=0;index<view.byteLength;index++)bytes.push(view.getUint8(index));return{serialized:!0,name:"TypedArray",type:type,bytes:bytes}}async deserialize(object){const type=object.type,bytes=object.bytes,buffer=new ArrayBuffer(bytes.length),view=new DataView(buffer);for(let index=0;index<bytes.length;index++)view.setUint8(index,bytes[index]);const clazz=globalThis[type];return reflector.createInstance(clazz,[buffer])}}class InvalidUrlString extends Error{constructor(urlString){super(`Invalid url string '${urlString}'`)}}class UrlSerializer extends ValueSerializer{canSerialize(value){return value instanceof URL}canDeserialize(value){const url=value;return url instanceof Object&&!0===url.serialized&&"Url"===url.name&&"string"==typeof url.value}async serialize(url){return{serialized:!0,name:"Url",value:url.toString()}}async deserialize(object){try{return new URL(object.value)}catch(error){throw new InvalidUrlString(object.value)}}}const defaultClassLoader=new class{async loadClass(loadable){if("string"!=typeof loadable.source)throw new ClassNotFound(loadable.name);const module=await import(loadable.source),clazz=module[loadable.name]??module.default;if(void 0===clazz)throw new ClassNotFound(loadable.name);if(clazz instanceof Function==!1)throw new InvalidClass(loadable.name);return clazz}};class SerializerBuilder{static build(loader=defaultClassLoader){const serializer=new Serializer;return serializer.addSerializer(new PrimitiveSerializer),serializer.addSerializer(new ObjectSerializer),serializer.addSerializer(new ClassSerializer(loader)),serializer.addSerializer(new ErrorSerializer),serializer.addSerializer(new UrlSerializer),serializer.addSerializer(new DateSerializer),serializer.addSerializer(new SetSerializer),serializer.addSerializer(new MapSerializer),serializer.addSerializer(new ArraySerializer),serializer.addSerializer(new ArrayBufferSerializer),serializer}}class RemoteClassLoader{async loadClass(loadable){if("string"!=typeof loadable.source)throw new ClassNotFound(loadable.name);const module=await ModuleLoader.load(loadable.source),clazz=module[loadable.name]??module.default;if(void 0===clazz)throw new ClassNotFound(loadable.name);if(clazz instanceof Function==!1)throw new InvalidClass(loadable.name);return clazz}}const remoteClassLoader=new RemoteClassLoader,defaultSerializer=SerializerBuilder.build(remoteClassLoader);class Remote{#url;#useSerializer;#serializer;constructor(url,useSerializer,serializer=defaultSerializer){this.#url=url,this.#useSerializer=useSerializer,this.#serializer=serializer}async registerClient(segmentFiles){const url=`${this.#url}/modules`,options={method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(segmentFiles)},response=await this.#callRemote(url,options,200);return await response.text()}async loadFile(filename){const url=`${this.#url}/${filename}`,response=await this.#callRemote(url,{method:"GET"},200),type=response.headers.get("Content-Type")||"application/octet-stream",content=await response.text();return new File(filename,type,content)}importFile(filename){const url=`${this.#url}/${filename}`;return ModuleLoader.load(url)}async isHealthy(){const url=`${this.#url}/health/status`,response=await this.#callRemote(url,{method:"GET"},200),healthy=await response.text();return Boolean(healthy)}async getHealth(){const url=`${this.#url}/health`,response=await this.#callRemote(url,{method:"GET"},200),health=await response.json();return new Map(Object.entries(health))}async addNode(node){const url=`${this.#url}/nodes`,body={url:node.url,procedureNames:node.getProcedureNames()},options={method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(body)};await this.#callRemote(url,options,201)}async run(fqn,version,args,headers){headers.set("content-type","application/json");const versionString=version.toString(),argsObject=Object.fromEntries(args),headersObject=Object.fromEntries(headers),url=`${this.#url}/rpc/${fqn}?version=${versionString}&serialize=true`,options={method:"POST",headers:headersObject,body:await this.#createRequestBody(argsObject,this.#useSerializer)},response=await this.#callRemote(url,options,200);return this.#createResponseResult(response,this.#useSerializer)}async#callRemote(url,options,expectedStatus){const response=await fetch(url,options);if(response.status!==expectedStatus){throw await this.#createResponseResult(response,!0)}return response}async#createRequestBody(body,serialize){const data=serialize?await this.#serializer.serialize(body):body;return JSON.stringify(data)}async#createResponseResult(response,serialize){const result=await this.#getResponseResult(response);return serialize?this.#serializer.deserialize(result):result}#getResponseResult(response){const contentType=response.headers.get("Content-Type");return null!==contentType&&contentType.includes("json")?response.json():response.text()}}class RemoteGateway extends Gateway{#remote;constructor(url){super(url),this.#remote=new Remote(url,!0)}getProcedureNames(){throw new NotImplemented}hasProcedure(name){throw new NotImplemented}addNode(node){return this.#remote.addNode(node)}run(fqn,version,args,headers){return this.#remote.run(fqn,version,args,headers)}}class RemoteRepository extends Repository{#remote;constructor(url){super(url),this.#remote=new Remote(url,!0)}registerClient(segmentFiles){return this.#remote.registerClient(segmentFiles)}loadAsset(filename){return this.#remote.loadFile(filename)}async getModuleLocation(clientId){return`${this.url}/modules/${clientId}`}async loadModule(clientId,filename){return this.#remote.loadFile(`modules/${clientId}/${filename}`)}async importModule(clientId,filename){return this.#remote.importFile(`modules/${clientId}/${filename}`)}}const globals=globalThis;globals.__getDependency=async function(name){RUNS_IN_BROWSER&&"jitar"===name&&(name="/jitar/client.js");const module=await _loader(name);return void 0!==module.default?module.default:module},globals.__runProcedure=async function(fqn,versionNumber,args,context){if(void 0===_runtime)throw new RuntimeNotAvailable;const version=VersionParser.parse(versionNumber),argsMap=new Map(Object.entries(args)),headersMap=context instanceof Context?context.headers:new Map;return _runtime.run(fqn,version,argsMap,headersMap)},globals.ProcedureNotAccessible=ProcedureNotAccessible;export{RuntimeNotAvailable as $,AccessLevel as A,BadRequest as B,ClientNotFound as C,ArrayParameter as D,ServerError as E,FileNotFound as F,ImplementationNotFound as G,InvalidParameterValue as H,InvalidSegmentFile as I,InvalidVersionNumber as J,MissingParameterValue as K,LocalGateway as L,ModuleLoader as M,Node as N,ObjectParameter as O,ProcedureRuntime as P,ModuleNotAccessible as Q,Repository as R,SerializerBuilder as S,Teapot as T,Unauthorized as U,VersionParser as V,ModuleNotLoaded as W,NoNodeAvailable as X,ProcedureNotAccessible as Y,ProcedureNotFound as Z,RepositoryNotAvailable as _,InvalidClientId as a,SegmentNotFound as a0,UnknownParameter as a1,File as b,convertToLocalFilename as c,convertToRemoteFilename as d,createRepositoryFilename as e,ProcedureRunner as f,Remote as g,Reflector as h,isSegmentFilename as i,ReflectionField as j,ReflectionDestructuredArray as k,ReflectionDestructuredObject as l,ReflectionDestructuredValue as m,createNodeFilename as n,ReflectionFunction as o,Files as p,LocalNode as q,RemoteRepository as r,RemoteGateway as s,PaymentRequired as t,Forbidden as u,NotFound as v,NotImplemented as w,Version as x,RemoteClassLoader as y,NamedParameter as z};
|
package/dist/lib.d.ts
CHANGED
|
@@ -1,35 +1,309 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
declare class BadRequest extends Error {
|
|
3
|
+
constructor(message?: string);
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
declare class Forbidden extends Error {
|
|
7
|
+
constructor(message?: string);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
declare class NotFound extends Error {
|
|
11
|
+
constructor(message?: string);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
declare class NotImplemented extends Error {
|
|
15
|
+
constructor(message?: string);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
declare class PaymentRequired extends Error {
|
|
19
|
+
constructor(message?: string);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
declare class ServerError extends Error {
|
|
23
|
+
constructor(message?: string);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
declare class Teapot extends Error {
|
|
27
|
+
constructor();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
declare class Unauthorized extends Error {
|
|
31
|
+
constructor(message?: string);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
declare class ClientNotFound extends BadRequest {
|
|
35
|
+
#private;
|
|
36
|
+
constructor(clientId: string);
|
|
37
|
+
get clientId(): string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
declare class FileNotFound extends NotFound {
|
|
41
|
+
#private;
|
|
42
|
+
constructor(filename: string);
|
|
43
|
+
get filename(): string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
declare class ImplementationNotFound extends NotFound {
|
|
47
|
+
#private;
|
|
48
|
+
constructor(fqn: string, version: string);
|
|
49
|
+
get fqn(): string;
|
|
50
|
+
get version(): string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
declare class InvalidClientId extends BadRequest {
|
|
54
|
+
#private;
|
|
55
|
+
constructor(clientId: string);
|
|
56
|
+
get clientId(): string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
declare class InvalidParameterValue extends BadRequest {
|
|
60
|
+
#private;
|
|
61
|
+
constructor(parameterName: string);
|
|
62
|
+
get parameterName(): string;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
declare class InvalidSegmentFile extends ServerError {
|
|
66
|
+
#private;
|
|
67
|
+
constructor(filename: string);
|
|
68
|
+
get filename(): string;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
declare class InvalidVersionNumber extends BadRequest {
|
|
72
|
+
#private;
|
|
73
|
+
constructor(number: string);
|
|
74
|
+
get number(): string;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
declare class MissingParameterValue extends BadRequest {
|
|
78
|
+
#private;
|
|
79
|
+
constructor(parameterName: string);
|
|
80
|
+
get parameterName(): string;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
declare class ModuleNotAccessible extends Forbidden {
|
|
84
|
+
#private;
|
|
85
|
+
constructor(url: string);
|
|
86
|
+
get url(): string;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
declare class ModuleNotLoaded extends ServerError {
|
|
90
|
+
#private;
|
|
91
|
+
constructor(url: string, reason?: string);
|
|
92
|
+
get url(): string;
|
|
93
|
+
get reason(): string | undefined;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
declare class NoNodeAvailable extends ServerError {
|
|
97
|
+
#private;
|
|
98
|
+
constructor(name: string);
|
|
99
|
+
get name(): string;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
declare class ProcedureNotAccessible extends Forbidden {
|
|
103
|
+
#private;
|
|
104
|
+
constructor(fqn: string, versionNumber: string);
|
|
105
|
+
get fqn(): string;
|
|
106
|
+
get versionNumber(): string;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
declare class ProcedureNotFound extends NotFound {
|
|
110
|
+
#private;
|
|
111
|
+
constructor(fqn: string);
|
|
112
|
+
get fqn(): string;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
declare class RepositoryNotAvailable extends ServerError {
|
|
116
|
+
constructor();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
declare class RuntimeNotAvailable extends ServerError {
|
|
120
|
+
constructor();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
declare class SegmentNotFound extends ServerError {
|
|
124
|
+
#private;
|
|
125
|
+
constructor(source: string);
|
|
126
|
+
get source(): string;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
declare class UnknownParameter extends BadRequest {
|
|
130
|
+
#private;
|
|
131
|
+
constructor(parameterName: string);
|
|
132
|
+
get parameterName(): string;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
declare class File {
|
|
136
|
+
#private;
|
|
137
|
+
constructor(location: string, type: string, content: Buffer | string);
|
|
138
|
+
get location(): string;
|
|
139
|
+
get type(): string;
|
|
140
|
+
get content(): string | Buffer;
|
|
141
|
+
get size(): number;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
interface HealthCheck {
|
|
145
|
+
isHealthy(): Promise<boolean>;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
declare class Version {
|
|
149
|
+
#private;
|
|
150
|
+
static get DEFAULT(): Version;
|
|
151
|
+
constructor(major?: number, minor?: number, patch?: number);
|
|
152
|
+
get major(): number;
|
|
153
|
+
get minor(): number;
|
|
154
|
+
get patch(): number;
|
|
155
|
+
equals(version: Version): boolean;
|
|
156
|
+
greater(version: Version): boolean;
|
|
157
|
+
less(version: Version): boolean;
|
|
158
|
+
toString(): string;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
type NextHandler = () => Promise<unknown>;
|
|
162
|
+
|
|
163
|
+
interface Middleware {
|
|
164
|
+
handle(fqn: string, version: Version, args: Map<string, unknown>, headers: Map<string, string>, next: NextHandler): Promise<unknown>;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
declare class Parameter {
|
|
168
|
+
#private;
|
|
169
|
+
constructor(name: string, isOptional?: boolean);
|
|
170
|
+
get name(): string;
|
|
171
|
+
get isOptional(): boolean;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
declare class DestructuredParameter extends Parameter {
|
|
175
|
+
#private;
|
|
176
|
+
constructor(variables: Parameter[], name?: string, isOptional?: boolean);
|
|
177
|
+
get variables(): Parameter[];
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
declare class ArrayParameter extends DestructuredParameter {
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
declare class Implementation {
|
|
184
|
+
#private;
|
|
185
|
+
constructor(version: Version, access: string, parameters: Parameter[], executable: Function);
|
|
186
|
+
get version(): Version;
|
|
187
|
+
get public(): boolean;
|
|
188
|
+
get parameters(): Parameter[];
|
|
189
|
+
get executable(): Function;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
declare class NamedParameter extends Parameter {
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
declare class ObjectParameter extends DestructuredParameter {
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
declare class Procedure {
|
|
199
|
+
#private;
|
|
200
|
+
constructor(fqn: string);
|
|
201
|
+
get fqn(): string;
|
|
202
|
+
get public(): boolean;
|
|
203
|
+
addImplementation(implementation: Implementation): Procedure;
|
|
204
|
+
getImplementation(version: Version): Implementation | undefined;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
declare class Segment {
|
|
208
|
+
#private;
|
|
209
|
+
constructor(id: string);
|
|
210
|
+
get id(): string;
|
|
211
|
+
addProcedure(procedure: Procedure): Segment;
|
|
212
|
+
hasProcedure(fqn: string): boolean;
|
|
213
|
+
getProcedure(fqn: string): Procedure | undefined;
|
|
214
|
+
getPublicProcedures(): Procedure[];
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
interface Runner {
|
|
218
|
+
run(fqn: string, version: Version, args: Map<string, unknown>, headers: Map<string, string>): Promise<unknown>;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
declare abstract class Runtime {
|
|
222
|
+
#private;
|
|
223
|
+
constructor(url?: string);
|
|
224
|
+
get url(): string | undefined;
|
|
225
|
+
addHealthCheck(name: string, healthCheck: HealthCheck): void;
|
|
226
|
+
isHealthy(): Promise<boolean>;
|
|
227
|
+
getHealth(): Promise<Map<string, boolean>>;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
declare abstract class ProcedureRuntime extends Runtime implements Runner {
|
|
231
|
+
#private;
|
|
232
|
+
constructor(url?: string);
|
|
233
|
+
abstract getProcedureNames(): string[];
|
|
234
|
+
abstract hasProcedure(name: string): boolean;
|
|
235
|
+
abstract run(fqn: string, version: Version, args: Map<string, unknown>, headers: Map<string, string>): Promise<unknown>;
|
|
236
|
+
addMiddleware(middleware: Middleware): void;
|
|
237
|
+
getMiddleware(type: Function): Middleware | undefined;
|
|
238
|
+
handle(fqn: string, version: Version, args: Map<string, unknown>, headers: Map<string, string>): Promise<unknown>;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
declare abstract class Node extends ProcedureRuntime {
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
declare abstract class Gateway extends ProcedureRuntime {
|
|
245
|
+
abstract addNode(node: Node): Promise<void>;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
type Module = Record<string, unknown>;
|
|
249
|
+
|
|
250
|
+
declare abstract class Repository extends Runtime {
|
|
251
|
+
abstract registerClient(segmentFiles: string[]): Promise<string>;
|
|
252
|
+
abstract loadAsset(filename: string): Promise<File>;
|
|
253
|
+
abstract getModuleLocation(clientId: string): Promise<string>;
|
|
254
|
+
abstract loadModule(clientId: string, filename: string): Promise<File>;
|
|
255
|
+
abstract importModule(clientId: string, filename: string): Promise<Module>;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
declare class ArgumentExtractor {
|
|
259
|
+
#private;
|
|
260
|
+
extract(parameters: Parameter[], args: Map<string, unknown>): unknown[];
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
declare class LocalNode extends Node {
|
|
264
|
+
#private;
|
|
265
|
+
constructor(url?: string, argumentConstructor?: ArgumentExtractor);
|
|
266
|
+
getProcedureNames(): string[];
|
|
267
|
+
loadSegment(name: string): Promise<void>;
|
|
268
|
+
addSegment(segment: Segment): void;
|
|
269
|
+
hasProcedure(fqn: string): boolean;
|
|
270
|
+
setGateway(gateway: Gateway): Promise<void>;
|
|
271
|
+
setRepository(repository: Repository, segmentNames: string[]): Promise<void>;
|
|
272
|
+
import(url: string, base?: string): Promise<Module>;
|
|
273
|
+
run(fqn: string, version: Version, args: Map<string, unknown>, headers: Map<string, string>): Promise<unknown>;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
type ModuleImporter = (name: string) => Promise<Module>;
|
|
277
|
+
|
|
278
|
+
declare function startClient(remoteUrl: string, segmentNames?: string[]): Promise<LocalNode>;
|
|
279
|
+
declare function getClient(): Promise<LocalNode>;
|
|
280
|
+
|
|
281
|
+
declare function getDependency(name: string): Promise<unknown>;
|
|
282
|
+
|
|
283
|
+
declare function runProcedure(fqn: string, versionNumber: string, args: object, context?: object): Promise<unknown>;
|
|
284
|
+
|
|
285
|
+
declare global {
|
|
286
|
+
const __getDependency: typeof getDependency;
|
|
287
|
+
const __runProcedure: typeof runProcedure;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
declare class CorsMiddleware implements Middleware {
|
|
291
|
+
#private;
|
|
292
|
+
constructor(origin?: string, headers?: string);
|
|
293
|
+
get allowOrigin(): string;
|
|
294
|
+
get allowMethods(): string;
|
|
295
|
+
get allowHeaders(): string;
|
|
296
|
+
handle(fqn: string, version: Version, args: Map<string, unknown>, headers: Map<string, string>, next: NextHandler): Promise<unknown>;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
declare class JitarServer {
|
|
300
|
+
#private;
|
|
301
|
+
constructor();
|
|
302
|
+
start(): Promise<void>;
|
|
303
|
+
addHealthCheck(name: string, healthCheck: HealthCheck): void;
|
|
304
|
+
addMiddleware(middleware: Middleware): void;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
declare function startServer(moduleImporter: ModuleImporter): Promise<JitarServer>;
|
|
308
|
+
|
|
309
|
+
export { ArrayParameter, BadRequest, ClientNotFound, CorsMiddleware, FileNotFound, Forbidden, HealthCheck, Implementation, ImplementationNotFound, InvalidClientId, InvalidParameterValue, InvalidSegmentFile, InvalidVersionNumber, Middleware, MissingParameterValue, ModuleNotAccessible, ModuleNotLoaded, NamedParameter, NextHandler, NoNodeAvailable, NotFound, NotImplemented, ObjectParameter, PaymentRequired, Procedure, ProcedureNotAccessible, ProcedureNotFound, RepositoryNotAvailable, RuntimeNotAvailable, Segment, SegmentNotFound, ServerError, Teapot, Unauthorized, UnknownParameter, Version, getClient, startClient, startServer };
|