@objectstack/runtime 0.9.2 → 1.0.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 +16 -0
- package/dist/api-registry-plugin.d.ts +16 -0
- package/dist/api-registry-plugin.js +42 -0
- package/dist/app-plugin.d.ts +2 -2
- package/dist/app-plugin.js +61 -61
- package/dist/app-plugin.test.d.ts +1 -0
- package/dist/app-plugin.test.js +80 -0
- package/dist/driver-plugin.d.ts +2 -2
- package/dist/driver-plugin.js +14 -14
- package/dist/http-dispatcher.d.ts +106 -0
- package/dist/http-dispatcher.js +515 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +4 -0
- package/dist/runtime.d.ts +45 -0
- package/dist/runtime.js +50 -0
- package/dist/runtime.test.d.ts +1 -0
- package/dist/runtime.test.js +57 -0
- package/package.json +9 -6
- package/src/api-registry-plugin.ts +58 -0
- package/src/app-plugin.test.ts +102 -0
- package/src/app-plugin.ts +2 -2
- package/src/driver-plugin.ts +2 -2
- package/src/http-dispatcher.ts +600 -0
- package/src/index.ts +8 -0
- package/src/runtime.test.ts +65 -0
- package/src/runtime.ts +78 -0
package/src/runtime.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { ObjectKernel, Plugin, IHttpServer, ObjectKernelConfig } from '@objectstack/core';
|
|
2
|
+
import { HttpServer } from './http-server.js';
|
|
3
|
+
import { createApiRegistryPlugin, ApiRegistryConfig } from './api-registry-plugin.js';
|
|
4
|
+
|
|
5
|
+
export interface RuntimeConfig {
|
|
6
|
+
/**
|
|
7
|
+
* Optional existing server instance (e.g. Hono, Express app)
|
|
8
|
+
* If provided, Runtime will use it as the 'http.server' service.
|
|
9
|
+
* If not provided, Runtime expects a server plugin (like HonoServerPlugin) to be registered manually.
|
|
10
|
+
*/
|
|
11
|
+
server?: IHttpServer;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* API Registry Configuration
|
|
15
|
+
*/
|
|
16
|
+
api?: ApiRegistryConfig;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Kernel Configuration
|
|
20
|
+
*/
|
|
21
|
+
kernel?: ObjectKernelConfig;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* ObjectStack Runtime
|
|
26
|
+
*
|
|
27
|
+
* High-level entry point for bootstrapping an ObjectStack application.
|
|
28
|
+
* Wraps ObjectKernel and provides standard orchestration for:
|
|
29
|
+
* - HTTP Server binding
|
|
30
|
+
* - API Registry (REST Routes)
|
|
31
|
+
* - Plugin Management
|
|
32
|
+
*/
|
|
33
|
+
export class Runtime {
|
|
34
|
+
readonly kernel: ObjectKernel;
|
|
35
|
+
|
|
36
|
+
constructor(config: RuntimeConfig = {}) {
|
|
37
|
+
this.kernel = new ObjectKernel(config.kernel);
|
|
38
|
+
|
|
39
|
+
// If external server provided, register it immediately
|
|
40
|
+
if (config.server) {
|
|
41
|
+
// If the provided server is not already an HttpServer wrapper, wrap it?
|
|
42
|
+
// Since IHttpServer is the interface, we assume it complies.
|
|
43
|
+
// But HttpServer class in runtime is an adapter.
|
|
44
|
+
// If user passes raw Hono, it won't work unless they wrapped it.
|
|
45
|
+
// We'll assume they pass a compliant IHttpServer.
|
|
46
|
+
this.kernel.registerService('http.server', config.server);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Register API Registry by default
|
|
50
|
+
// This plugin is passive (wait for services) so it's safe to add early.
|
|
51
|
+
this.kernel.use(createApiRegistryPlugin(config.api));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Register a plugin
|
|
56
|
+
*/
|
|
57
|
+
use(plugin: Plugin) {
|
|
58
|
+
this.kernel.use(plugin);
|
|
59
|
+
return this;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Start the runtime
|
|
64
|
+
* 1. Initializes all plugins (init phase)
|
|
65
|
+
* 2. Starts all plugins (start phase)
|
|
66
|
+
*/
|
|
67
|
+
async start() {
|
|
68
|
+
await this.kernel.bootstrap();
|
|
69
|
+
return this;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Get the kernel instance
|
|
74
|
+
*/
|
|
75
|
+
getKernel() {
|
|
76
|
+
return this.kernel;
|
|
77
|
+
}
|
|
78
|
+
}
|