@objectstack/core 0.4.2 → 0.6.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/README.md +41 -0
- package/dist/contracts/data-engine.d.ts +45 -0
- package/dist/contracts/data-engine.d.ts.map +1 -0
- package/dist/contracts/data-engine.js +1 -0
- package/dist/contracts/http-server.d.ts +119 -0
- package/dist/contracts/http-server.d.ts.map +1 -0
- package/dist/contracts/http-server.js +11 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -18
- package/dist/kernel.d.ts.map +1 -1
- package/dist/kernel.js +4 -5
- package/dist/types.d.ts +4 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -2
- package/package.json +4 -1
- package/src/contracts/data-engine.ts +52 -0
- package/src/contracts/http-server.ts +142 -0
- package/src/index.ts +2 -0
- package/src/kernel.ts +3 -0
- package/src/types.ts +5 -0
- package/tsconfig.json +3 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# @objectstack/core
|
|
2
|
+
|
|
3
|
+
## 0.6.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- b2df5f7: Unified version bump to 0.5.0
|
|
8
|
+
|
|
9
|
+
- Standardized all package versions to 0.5.0 across the monorepo
|
|
10
|
+
- Fixed driver-memory package.json paths for proper module resolution
|
|
11
|
+
- Ensured all packages are in sync for the 0.5.0 release
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [b2df5f7]
|
|
16
|
+
- @objectstack/spec@0.6.0
|
package/README.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# @objectstack/core
|
|
2
|
+
|
|
3
|
+
The Microkernel for the ObjectStack Operating System.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This package defines the fundamental runtime mechanics of the ObjectStack architecture:
|
|
8
|
+
1. **Dependency Injection (DI)**: A `services` registry.
|
|
9
|
+
2. **Plugin Lifecycle**: `init` (Registration) -> `start` (Execution).
|
|
10
|
+
3. **Event Bus**: Simple hook system (`hook`, `trigger`).
|
|
11
|
+
|
|
12
|
+
It is completely agnostic of "Data", "HTTP", or "Apps". It only knows `Plugin` and `Service`.
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @objectstack/core
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import { ObjectKernel, Plugin, PluginContext } from '@objectstack/core';
|
|
24
|
+
|
|
25
|
+
// 1. Define a Plugin
|
|
26
|
+
class MyPlugin implements Plugin {
|
|
27
|
+
name = 'my-plugin';
|
|
28
|
+
|
|
29
|
+
async init(ctx: PluginContext) {
|
|
30
|
+
ctx.registerService('my-service', { hello: 'world' });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// 2. Boot Kernel
|
|
35
|
+
const kernel = new ObjectKernel();
|
|
36
|
+
kernel.use(new MyPlugin());
|
|
37
|
+
await kernel.bootstrap();
|
|
38
|
+
|
|
39
|
+
// 3. Use Service
|
|
40
|
+
const service = kernel.context.getService('my-service');
|
|
41
|
+
```
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { QueryAST } from '@objectstack/spec/data';
|
|
2
|
+
import { DriverOptions } from '@objectstack/spec/system';
|
|
3
|
+
/**
|
|
4
|
+
* IDataEngine - Standard Data Engine Interface
|
|
5
|
+
*
|
|
6
|
+
* Abstract interface for data persistence capabilities.
|
|
7
|
+
* Following the Dependency Inversion Principle - plugins depend on this interface,
|
|
8
|
+
* not on concrete database implementations.
|
|
9
|
+
*/
|
|
10
|
+
export interface DataEngineFilter {
|
|
11
|
+
[key: string]: any;
|
|
12
|
+
}
|
|
13
|
+
export interface DataEngineQueryOptions {
|
|
14
|
+
/** Filter conditions */
|
|
15
|
+
filter?: DataEngineFilter;
|
|
16
|
+
/** Fields to select */
|
|
17
|
+
select?: string[];
|
|
18
|
+
/** Sort order */
|
|
19
|
+
sort?: Record<string, 1 | -1 | 'asc' | 'desc'>;
|
|
20
|
+
/** Limit number of results */
|
|
21
|
+
limit?: number;
|
|
22
|
+
/** Skip number of results */
|
|
23
|
+
skip?: number;
|
|
24
|
+
/** Maximum number of results */
|
|
25
|
+
top?: number;
|
|
26
|
+
}
|
|
27
|
+
export interface IDataEngine {
|
|
28
|
+
insert(objectName: string, data: any): Promise<any>;
|
|
29
|
+
find(objectName: string, query?: DataEngineQueryOptions): Promise<any[]>;
|
|
30
|
+
update(objectName: string, id: any, data: any): Promise<any>;
|
|
31
|
+
delete(objectName: string, id: any): Promise<boolean>;
|
|
32
|
+
}
|
|
33
|
+
export interface DriverInterface {
|
|
34
|
+
name: string;
|
|
35
|
+
version: string;
|
|
36
|
+
connect(): Promise<void>;
|
|
37
|
+
disconnect(): Promise<void>;
|
|
38
|
+
find(object: string, query: QueryAST, options?: DriverOptions): Promise<any[]>;
|
|
39
|
+
findOne(object: string, query: QueryAST, options?: DriverOptions): Promise<any>;
|
|
40
|
+
create(object: string, data: any, options?: DriverOptions): Promise<any>;
|
|
41
|
+
update(object: string, id: any, data: any, options?: DriverOptions): Promise<any>;
|
|
42
|
+
delete(object: string, id: any, options?: DriverOptions): Promise<any>;
|
|
43
|
+
count?(object: string, query: QueryAST, options?: DriverOptions): Promise<number>;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=data-engine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-engine.d.ts","sourceRoot":"","sources":["../../src/contracts/data-engine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AA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AE,aAAa,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IAC/E,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IAChF,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IACzE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IAClF,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IAEvE,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACnF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IHttpServer - Standard HTTP Server Interface
|
|
3
|
+
*
|
|
4
|
+
* Abstract interface for HTTP server capabilities.
|
|
5
|
+
* This allows plugins to interact with HTTP servers without knowing
|
|
6
|
+
* the underlying implementation (Express, Fastify, Hono, etc.).
|
|
7
|
+
*
|
|
8
|
+
* Follows Dependency Inversion Principle - plugins depend on this interface,
|
|
9
|
+
* not on concrete HTTP framework implementations.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Generic HTTP Request type
|
|
13
|
+
* Abstraction over framework-specific request objects
|
|
14
|
+
*/
|
|
15
|
+
export interface IHttpRequest {
|
|
16
|
+
/** Request path parameters */
|
|
17
|
+
params: Record<string, string>;
|
|
18
|
+
/** Request query parameters */
|
|
19
|
+
query: Record<string, string | string[]>;
|
|
20
|
+
/** Request body */
|
|
21
|
+
body?: any;
|
|
22
|
+
/** Request headers */
|
|
23
|
+
headers: Record<string, string | string[]>;
|
|
24
|
+
/** HTTP method */
|
|
25
|
+
method: string;
|
|
26
|
+
/** Request path */
|
|
27
|
+
path: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Generic HTTP Response type
|
|
31
|
+
* Abstraction over framework-specific response objects
|
|
32
|
+
*/
|
|
33
|
+
export interface IHttpResponse {
|
|
34
|
+
/**
|
|
35
|
+
* Send a JSON response
|
|
36
|
+
* @param data - Data to send
|
|
37
|
+
*/
|
|
38
|
+
json(data: any): void | Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Send a text/html response
|
|
41
|
+
* @param data - Data to send
|
|
42
|
+
*/
|
|
43
|
+
send(data: string): void | Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Set HTTP status code
|
|
46
|
+
* @param code - HTTP status code
|
|
47
|
+
*/
|
|
48
|
+
status(code: number): IHttpResponse;
|
|
49
|
+
/**
|
|
50
|
+
* Set response header
|
|
51
|
+
* @param name - Header name
|
|
52
|
+
* @param value - Header value (string or array of strings for multi-value headers)
|
|
53
|
+
*/
|
|
54
|
+
header(name: string, value: string | string[]): IHttpResponse;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Route handler function
|
|
58
|
+
*/
|
|
59
|
+
export type RouteHandler = (req: IHttpRequest, res: IHttpResponse) => void | Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Middleware function
|
|
62
|
+
*/
|
|
63
|
+
export type Middleware = (req: IHttpRequest, res: IHttpResponse, next: () => void | Promise<void>) => void | Promise<void>;
|
|
64
|
+
/**
|
|
65
|
+
* IHttpServer - HTTP Server capability interface
|
|
66
|
+
*
|
|
67
|
+
* Defines the contract for HTTP server implementations.
|
|
68
|
+
* Concrete implementations (Express, Fastify, Hono) should implement this interface.
|
|
69
|
+
*/
|
|
70
|
+
export interface IHttpServer {
|
|
71
|
+
/**
|
|
72
|
+
* Register a GET route handler
|
|
73
|
+
* @param path - Route path (e.g., '/api/users/:id')
|
|
74
|
+
* @param handler - Route handler function
|
|
75
|
+
*/
|
|
76
|
+
get(path: string, handler: RouteHandler): void;
|
|
77
|
+
/**
|
|
78
|
+
* Register a POST route handler
|
|
79
|
+
* @param path - Route path
|
|
80
|
+
* @param handler - Route handler function
|
|
81
|
+
*/
|
|
82
|
+
post(path: string, handler: RouteHandler): void;
|
|
83
|
+
/**
|
|
84
|
+
* Register a PUT route handler
|
|
85
|
+
* @param path - Route path
|
|
86
|
+
* @param handler - Route handler function
|
|
87
|
+
*/
|
|
88
|
+
put(path: string, handler: RouteHandler): void;
|
|
89
|
+
/**
|
|
90
|
+
* Register a DELETE route handler
|
|
91
|
+
* @param path - Route path
|
|
92
|
+
* @param handler - Route handler function
|
|
93
|
+
*/
|
|
94
|
+
delete(path: string, handler: RouteHandler): void;
|
|
95
|
+
/**
|
|
96
|
+
* Register a PATCH route handler
|
|
97
|
+
* @param path - Route path
|
|
98
|
+
* @param handler - Route handler function
|
|
99
|
+
*/
|
|
100
|
+
patch(path: string, handler: RouteHandler): void;
|
|
101
|
+
/**
|
|
102
|
+
* Register middleware
|
|
103
|
+
* @param path - Optional path to apply middleware to (if omitted, applies globally)
|
|
104
|
+
* @param handler - Middleware function
|
|
105
|
+
*/
|
|
106
|
+
use(path: string | Middleware, handler?: Middleware): void;
|
|
107
|
+
/**
|
|
108
|
+
* Start the HTTP server
|
|
109
|
+
* @param port - Port number to listen on
|
|
110
|
+
* @returns Promise that resolves when server is ready
|
|
111
|
+
*/
|
|
112
|
+
listen(port: number): Promise<void>;
|
|
113
|
+
/**
|
|
114
|
+
* Stop the HTTP server
|
|
115
|
+
* @returns Promise that resolves when server is stopped
|
|
116
|
+
*/
|
|
117
|
+
close?(): Promise<void>;
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=http-server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-server.d.ts","sourceRoot":"","sources":["../../src/contracts/http-server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH;;;GAGG;AACH,MAAM,WAAW,YAAY;IACzB,8BAA8B;IAC9B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,+BAA+B;IAC/B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;IACzC,mBAAmB;IACnB,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,sBAAsB;IACtB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;IAC3C,kBAAkB;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,mBAAmB;IACnB,IAAI,EAAE,MAAM,CAAC;CAChB;AAED;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC1B;;;OAGG;IACH,IAAI,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtC;;;OAGG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzC;;;OAGG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,CAAC;IAEpC;;;;OAIG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,aAAa,CAAC;CACjE;AAED;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,CACvB,GAAG,EAAE,YAAY,EACjB,GAAG,EAAE,aAAa,KACjB,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAE1B;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,CACrB,GAAG,EAAE,YAAY,EACjB,GAAG,EAAE,aAAa,EAClB,IAAI,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAC/B,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAE1B;;;;;GAKG;AACH,MAAM,WAAW,WAAW;IACxB;;;;OAIG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI,CAAC;IAE/C;;;;OAIG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI,CAAC;IAEhD;;;;OAIG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI,CAAC;IAE/C;;;;OAIG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI,CAAC;IAElD;;;;OAIG;IACH,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI,CAAC;IAEjD;;;;OAIG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,IAAI,CAAC;IAE3D;;;;OAIG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEpC;;;OAGG;IACH,KAAK,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3B"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IHttpServer - Standard HTTP Server Interface
|
|
3
|
+
*
|
|
4
|
+
* Abstract interface for HTTP server capabilities.
|
|
5
|
+
* This allows plugins to interact with HTTP servers without knowing
|
|
6
|
+
* the underlying implementation (Express, Fastify, Hono, etc.).
|
|
7
|
+
*
|
|
8
|
+
* Follows Dependency Inversion Principle - plugins depend on this interface,
|
|
9
|
+
* not on concrete HTTP framework implementations.
|
|
10
|
+
*/
|
|
11
|
+
export {};
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,18 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./kernel.js"), exports);
|
|
18
|
-
__exportStar(require("./types.js"), exports);
|
|
1
|
+
export * from './kernel.js';
|
|
2
|
+
export * from './types.js';
|
|
3
|
+
export * from './contracts/http-server.js';
|
|
4
|
+
export * from './contracts/data-engine.js';
|
package/dist/kernel.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kernel.d.ts","sourceRoot":"","sources":["../src/kernel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAiB,MAAM,YAAY,CAAC;AAEnD;;;;;;;;;;;;;GAaG;AACH,qBAAa,YAAY;IACrB,OAAO,CAAC,OAAO,CAAkC;IACjD,OAAO,CAAC,QAAQ,CAA+B;IAC/C,OAAO,CAAC,KAAK,CAA2E;IACxF,OAAO,CAAC,KAAK,CAA2D;IAExE;;OAEG;IACH,OAAO,CAAC,OAAO,
|
|
1
|
+
{"version":3,"file":"kernel.d.ts","sourceRoot":"","sources":["../src/kernel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAiB,MAAM,YAAY,CAAC;AAEnD;;;;;;;;;;;;;GAaG;AACH,qBAAa,YAAY;IACrB,OAAO,CAAC,OAAO,CAAkC;IACjD,OAAO,CAAC,QAAQ,CAA+B;IAC/C,OAAO,CAAC,KAAK,CAA2E;IACxF,OAAO,CAAC,KAAK,CAA2D;IAExE;;OAEG;IACH,OAAO,CAAC,OAAO,CAgCb;IAEF;;;OAGG;IACH,GAAG,CAAC,MAAM,EAAE,MAAM;IAclB;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAyC3B;;;;;;OAMG;IACG,SAAS;IAmCf;;;OAGG;IACG,QAAQ;IAmBd;;;OAGG;IACH,UAAU,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC;IAI9B;;OAEG;IACH,SAAS,IAAI,OAAO;IAIpB;;OAEG;IACH,QAAQ,IAAI,MAAM;CAGrB"}
|
package/dist/kernel.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ObjectKernel = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* ObjectKernel - MiniKernel Architecture
|
|
6
3
|
*
|
|
@@ -15,7 +12,7 @@ exports.ObjectKernel = void 0;
|
|
|
15
12
|
* - Kernel only manages lifecycle, DI, and hooks
|
|
16
13
|
* - Plugins are loaded as equal building blocks
|
|
17
14
|
*/
|
|
18
|
-
class ObjectKernel {
|
|
15
|
+
export class ObjectKernel {
|
|
19
16
|
constructor() {
|
|
20
17
|
this.plugins = new Map();
|
|
21
18
|
this.services = new Map();
|
|
@@ -51,6 +48,9 @@ class ObjectKernel {
|
|
|
51
48
|
await handler(...args);
|
|
52
49
|
}
|
|
53
50
|
},
|
|
51
|
+
getServices: () => {
|
|
52
|
+
return new Map(this.services);
|
|
53
|
+
},
|
|
54
54
|
logger: console,
|
|
55
55
|
getKernel: () => this,
|
|
56
56
|
};
|
|
@@ -181,4 +181,3 @@ class ObjectKernel {
|
|
|
181
181
|
return this.state;
|
|
182
182
|
}
|
|
183
183
|
}
|
|
184
|
-
exports.ObjectKernel = ObjectKernel;
|
package/dist/types.d.ts
CHANGED
|
@@ -22,6 +22,10 @@ export interface PluginContext {
|
|
|
22
22
|
* @throws Error if service not found
|
|
23
23
|
*/
|
|
24
24
|
getService<T>(name: string): T;
|
|
25
|
+
/**
|
|
26
|
+
* Get all registered services
|
|
27
|
+
*/
|
|
28
|
+
getServices(): Map<string, any>;
|
|
25
29
|
/**
|
|
26
30
|
* Register a hook handler
|
|
27
31
|
* @param name - Hook name (e.g., 'kernel:ready', 'data:beforeInsert')
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C;;;;;;;;GAQG;AACH,MAAM,WAAW,aAAa;IAC1B;;;;OAIG;IACH,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,GAAG,IAAI,CAAC;IAElD;;;;;OAKG;IACH,UAAU,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,CAAC;IAE/B;;;;OAIG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,GAAG,IA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AAE,MAAM,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAE5E;;;;OAIG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAErD;;OAEG;IACH,MAAM,EAAE,OAAO,CAAC;IAEhB;;;OAGG;IACH,SAAS,IAAI,YAAY,CAAC;CAC7B;AAED;;;;GAIG;AACH,MAAM,WAAW,MAAM;IACnB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IAExB;;;;OAIG;IACH,IAAI,CAAC,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAE/C;;;;OAIG;IACH,KAAK,CAAC,CAAC,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAEjD;;;OAGG;IACH,OAAO,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CACpC"}
|
package/dist/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@objectstack/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Microkernel Core for ObjectStack",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -8,6 +8,9 @@
|
|
|
8
8
|
"devDependencies": {
|
|
9
9
|
"typescript": "^5.0.0"
|
|
10
10
|
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@objectstack/spec": "0.6.0"
|
|
13
|
+
},
|
|
11
14
|
"scripts": {
|
|
12
15
|
"build": "tsc"
|
|
13
16
|
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { QueryAST } from '@objectstack/spec/data';
|
|
2
|
+
import { DriverOptions } from '@objectstack/spec/system';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* IDataEngine - Standard Data Engine Interface
|
|
6
|
+
*
|
|
7
|
+
* Abstract interface for data persistence capabilities.
|
|
8
|
+
* Following the Dependency Inversion Principle - plugins depend on this interface,
|
|
9
|
+
* not on concrete database implementations.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export interface DataEngineFilter {
|
|
13
|
+
[key: string]: any;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface DataEngineQueryOptions {
|
|
17
|
+
/** Filter conditions */
|
|
18
|
+
filter?: DataEngineFilter;
|
|
19
|
+
/** Fields to select */
|
|
20
|
+
select?: string[];
|
|
21
|
+
/** Sort order */
|
|
22
|
+
sort?: Record<string, 1 | -1 | 'asc' | 'desc'>;
|
|
23
|
+
/** Limit number of results */
|
|
24
|
+
limit?: number;
|
|
25
|
+
/** Skip number of results */
|
|
26
|
+
skip?: number;
|
|
27
|
+
/** Maximum number of results */
|
|
28
|
+
top?: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface IDataEngine {
|
|
32
|
+
insert(objectName: string, data: any): Promise<any>;
|
|
33
|
+
find(objectName: string, query?: DataEngineQueryOptions): Promise<any[]>;
|
|
34
|
+
update(objectName: string, id: any, data: any): Promise<any>;
|
|
35
|
+
delete(objectName: string, id: any): Promise<boolean>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface DriverInterface {
|
|
39
|
+
name: string;
|
|
40
|
+
version: string;
|
|
41
|
+
connect(): Promise<void>;
|
|
42
|
+
disconnect(): Promise<void>;
|
|
43
|
+
|
|
44
|
+
find(object: string, query: QueryAST, options?: DriverOptions): Promise<any[]>;
|
|
45
|
+
findOne(object: string, query: QueryAST, options?: DriverOptions): Promise<any>;
|
|
46
|
+
create(object: string, data: any, options?: DriverOptions): Promise<any>;
|
|
47
|
+
update(object: string, id: any, data: any, options?: DriverOptions): Promise<any>;
|
|
48
|
+
delete(object: string, id: any, options?: DriverOptions): Promise<any>;
|
|
49
|
+
|
|
50
|
+
count?(object: string, query: QueryAST, options?: DriverOptions): Promise<number>;
|
|
51
|
+
}
|
|
52
|
+
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IHttpServer - Standard HTTP Server Interface
|
|
3
|
+
*
|
|
4
|
+
* Abstract interface for HTTP server capabilities.
|
|
5
|
+
* This allows plugins to interact with HTTP servers without knowing
|
|
6
|
+
* the underlying implementation (Express, Fastify, Hono, etc.).
|
|
7
|
+
*
|
|
8
|
+
* Follows Dependency Inversion Principle - plugins depend on this interface,
|
|
9
|
+
* not on concrete HTTP framework implementations.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
// We use Zod for validation but export interfaces for internal implementation
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Generic HTTP Request type
|
|
16
|
+
* Abstraction over framework-specific request objects
|
|
17
|
+
*/
|
|
18
|
+
export interface IHttpRequest {
|
|
19
|
+
/** Request path parameters */
|
|
20
|
+
params: Record<string, string>;
|
|
21
|
+
/** Request query parameters */
|
|
22
|
+
query: Record<string, string | string[]>;
|
|
23
|
+
/** Request body */
|
|
24
|
+
body?: any;
|
|
25
|
+
/** Request headers */
|
|
26
|
+
headers: Record<string, string | string[]>;
|
|
27
|
+
/** HTTP method */
|
|
28
|
+
method: string;
|
|
29
|
+
/** Request path */
|
|
30
|
+
path: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Generic HTTP Response type
|
|
35
|
+
* Abstraction over framework-specific response objects
|
|
36
|
+
*/
|
|
37
|
+
export interface IHttpResponse {
|
|
38
|
+
/**
|
|
39
|
+
* Send a JSON response
|
|
40
|
+
* @param data - Data to send
|
|
41
|
+
*/
|
|
42
|
+
json(data: any): void | Promise<void>;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Send a text/html response
|
|
46
|
+
* @param data - Data to send
|
|
47
|
+
*/
|
|
48
|
+
send(data: string): void | Promise<void>;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Set HTTP status code
|
|
52
|
+
* @param code - HTTP status code
|
|
53
|
+
*/
|
|
54
|
+
status(code: number): IHttpResponse;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Set response header
|
|
58
|
+
* @param name - Header name
|
|
59
|
+
* @param value - Header value (string or array of strings for multi-value headers)
|
|
60
|
+
*/
|
|
61
|
+
header(name: string, value: string | string[]): IHttpResponse;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Route handler function
|
|
66
|
+
*/
|
|
67
|
+
export type RouteHandler = (
|
|
68
|
+
req: IHttpRequest,
|
|
69
|
+
res: IHttpResponse
|
|
70
|
+
) => void | Promise<void>;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Middleware function
|
|
74
|
+
*/
|
|
75
|
+
export type Middleware = (
|
|
76
|
+
req: IHttpRequest,
|
|
77
|
+
res: IHttpResponse,
|
|
78
|
+
next: () => void | Promise<void>
|
|
79
|
+
) => void | Promise<void>;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* IHttpServer - HTTP Server capability interface
|
|
83
|
+
*
|
|
84
|
+
* Defines the contract for HTTP server implementations.
|
|
85
|
+
* Concrete implementations (Express, Fastify, Hono) should implement this interface.
|
|
86
|
+
*/
|
|
87
|
+
export interface IHttpServer {
|
|
88
|
+
/**
|
|
89
|
+
* Register a GET route handler
|
|
90
|
+
* @param path - Route path (e.g., '/api/users/:id')
|
|
91
|
+
* @param handler - Route handler function
|
|
92
|
+
*/
|
|
93
|
+
get(path: string, handler: RouteHandler): void;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Register a POST route handler
|
|
97
|
+
* @param path - Route path
|
|
98
|
+
* @param handler - Route handler function
|
|
99
|
+
*/
|
|
100
|
+
post(path: string, handler: RouteHandler): void;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Register a PUT route handler
|
|
104
|
+
* @param path - Route path
|
|
105
|
+
* @param handler - Route handler function
|
|
106
|
+
*/
|
|
107
|
+
put(path: string, handler: RouteHandler): void;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Register a DELETE route handler
|
|
111
|
+
* @param path - Route path
|
|
112
|
+
* @param handler - Route handler function
|
|
113
|
+
*/
|
|
114
|
+
delete(path: string, handler: RouteHandler): void;
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Register a PATCH route handler
|
|
118
|
+
* @param path - Route path
|
|
119
|
+
* @param handler - Route handler function
|
|
120
|
+
*/
|
|
121
|
+
patch(path: string, handler: RouteHandler): void;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Register middleware
|
|
125
|
+
* @param path - Optional path to apply middleware to (if omitted, applies globally)
|
|
126
|
+
* @param handler - Middleware function
|
|
127
|
+
*/
|
|
128
|
+
use(path: string | Middleware, handler?: Middleware): void;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Start the HTTP server
|
|
132
|
+
* @param port - Port number to listen on
|
|
133
|
+
* @returns Promise that resolves when server is ready
|
|
134
|
+
*/
|
|
135
|
+
listen(port: number): Promise<void>;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Stop the HTTP server
|
|
139
|
+
* @returns Promise that resolves when server is stopped
|
|
140
|
+
*/
|
|
141
|
+
close?(): Promise<void>;
|
|
142
|
+
}
|
package/src/index.ts
CHANGED
package/src/kernel.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -25,6 +25,11 @@ export interface PluginContext {
|
|
|
25
25
|
*/
|
|
26
26
|
getService<T>(name: string): T;
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Get all registered services
|
|
30
|
+
*/
|
|
31
|
+
getServices(): Map<string, any>;
|
|
32
|
+
|
|
28
33
|
/**
|
|
29
34
|
* Register a hook handler
|
|
30
35
|
* @param name - Hook name (e.g., 'kernel:ready', 'data:beforeInsert')
|