@objectstack/core 0.6.1 → 0.7.2
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 +15 -0
- package/ENHANCED_FEATURES.md +380 -0
- package/README.md +299 -12
- package/dist/contracts/data-engine.d.ts +39 -22
- package/dist/contracts/data-engine.d.ts.map +1 -1
- package/dist/contracts/logger.d.ts +63 -0
- package/dist/contracts/logger.d.ts.map +1 -0
- package/dist/contracts/logger.js +1 -0
- package/dist/enhanced-kernel.d.ts +103 -0
- package/dist/enhanced-kernel.d.ts.map +1 -0
- package/dist/enhanced-kernel.js +403 -0
- package/dist/enhanced-kernel.test.d.ts +2 -0
- package/dist/enhanced-kernel.test.d.ts.map +1 -0
- package/dist/enhanced-kernel.test.js +412 -0
- package/dist/index.d.ts +11 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -2
- package/dist/kernel-base.d.ts +84 -0
- package/dist/kernel-base.d.ts.map +1 -0
- package/dist/kernel-base.js +219 -0
- package/dist/kernel.d.ts +11 -18
- package/dist/kernel.d.ts.map +1 -1
- package/dist/kernel.js +43 -114
- package/dist/kernel.test.d.ts +2 -0
- package/dist/kernel.test.d.ts.map +1 -0
- package/dist/kernel.test.js +161 -0
- package/dist/logger.d.ts +70 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +268 -0
- package/dist/logger.test.d.ts +2 -0
- package/dist/logger.test.d.ts.map +1 -0
- package/dist/logger.test.js +92 -0
- package/dist/plugin-loader.d.ts +148 -0
- package/dist/plugin-loader.d.ts.map +1 -0
- package/dist/plugin-loader.js +287 -0
- package/dist/plugin-loader.test.d.ts +2 -0
- package/dist/plugin-loader.test.d.ts.map +1 -0
- package/dist/plugin-loader.test.js +339 -0
- package/dist/types.d.ts +2 -1
- package/dist/types.d.ts.map +1 -1
- package/examples/enhanced-kernel-example.ts +309 -0
- package/package.json +19 -4
- package/src/contracts/data-engine.ts +46 -24
- package/src/contracts/logger.ts +70 -0
- package/src/enhanced-kernel.test.ts +535 -0
- package/src/enhanced-kernel.ts +496 -0
- package/src/index.ts +23 -2
- package/src/kernel-base.ts +256 -0
- package/src/kernel.test.ts +200 -0
- package/src/kernel.ts +55 -129
- package/src/logger.test.ts +116 -0
- package/src/logger.ts +306 -0
- package/src/plugin-loader.test.ts +412 -0
- package/src/plugin-loader.ts +435 -0
- package/src/types.ts +2 -1
- package/vitest.config.ts +8 -0
package/README.md
CHANGED
|
@@ -1,41 +1,328 @@
|
|
|
1
1
|
# @objectstack/core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Microkernel Core for ObjectStack - A lightweight, plugin-based architecture with enterprise-grade features.
|
|
4
4
|
|
|
5
5
|
## Overview
|
|
6
6
|
|
|
7
7
|
This package defines the fundamental runtime mechanics of the ObjectStack architecture:
|
|
8
|
-
1.
|
|
9
|
-
2.
|
|
10
|
-
3.
|
|
8
|
+
1. **Dependency Injection (DI)**: Advanced service registry with factory functions and lifecycle management
|
|
9
|
+
2. **Plugin Lifecycle**: `init` (Registration) -> `start` (Execution) -> `destroy` (Cleanup)
|
|
10
|
+
3. **Event Bus**: Simple hook system (`hook`, `trigger`) for event-driven communication
|
|
11
|
+
4. **Configurable Logging**: Universal logger using [Pino](https://github.com/pinojs/pino) for Node.js and simple console for browsers
|
|
12
|
+
5. **Enhanced Features**: Version compatibility, health checks, timeout control, graceful shutdown, and more
|
|
11
13
|
|
|
12
14
|
It is completely agnostic of "Data", "HTTP", or "Apps". It only knows `Plugin` and `Service`.
|
|
13
15
|
|
|
16
|
+
## Features
|
|
17
|
+
|
|
18
|
+
### Core Features
|
|
19
|
+
- **Plugin-based Architecture**: Modular microkernel that manages plugin lifecycle
|
|
20
|
+
- **Service Registry**: Dependency injection for inter-plugin communication
|
|
21
|
+
- **Event/Hook System**: Flexible event-driven communication
|
|
22
|
+
- **High-Performance Logging**:
|
|
23
|
+
- Node.js: Powered by [Pino](https://github.com/pinojs/pino) - extremely fast, low-overhead structured logging
|
|
24
|
+
- Browser: Lightweight console-based logger
|
|
25
|
+
- **Environment Detection**: Automatic runtime detection (Node.js/browser)
|
|
26
|
+
- **Dependency Resolution**: Automatic topological sorting of plugin dependencies
|
|
27
|
+
- **Security**: Automatic sensitive data redaction in logs
|
|
28
|
+
|
|
29
|
+
### Enhanced Features (EnhancedObjectKernel)
|
|
30
|
+
- **Async Plugin Loading**: Load plugins asynchronously with validation
|
|
31
|
+
- **Version Compatibility**: Semantic versioning support and validation
|
|
32
|
+
- **Plugin Signatures**: Security verification (extensible)
|
|
33
|
+
- **Configuration Validation**: Zod-based schema validation for plugin configs
|
|
34
|
+
- **Service Factories**: Factory-based service instantiation with lifecycle control
|
|
35
|
+
- **Service Lifecycles**: Singleton, Transient, and Scoped service management
|
|
36
|
+
- **Circular Dependency Detection**: Automatic detection and reporting
|
|
37
|
+
- **Lazy Loading**: Services created on-demand
|
|
38
|
+
- **Timeout Control**: Configurable timeouts for plugin initialization
|
|
39
|
+
- **Failure Rollback**: Automatic rollback on startup failures
|
|
40
|
+
- **Health Checks**: Monitor plugin health at runtime
|
|
41
|
+
- **Performance Metrics**: Track plugin startup times
|
|
42
|
+
- **Graceful Shutdown**: Proper cleanup with timeout control
|
|
43
|
+
|
|
14
44
|
## Installation
|
|
15
45
|
|
|
16
46
|
```bash
|
|
17
47
|
npm install @objectstack/core
|
|
48
|
+
# or
|
|
49
|
+
pnpm add @objectstack/core
|
|
18
50
|
```
|
|
19
51
|
|
|
20
|
-
##
|
|
52
|
+
## Quick Start
|
|
21
53
|
|
|
22
54
|
```typescript
|
|
23
55
|
import { ObjectKernel, Plugin, PluginContext } from '@objectstack/core';
|
|
24
56
|
|
|
25
57
|
// 1. Define a Plugin
|
|
26
|
-
|
|
27
|
-
name
|
|
58
|
+
const myPlugin: Plugin = {
|
|
59
|
+
name: 'my-plugin',
|
|
28
60
|
|
|
29
61
|
async init(ctx: PluginContext) {
|
|
62
|
+
ctx.logger.info('Initializing plugin');
|
|
30
63
|
ctx.registerService('my-service', { hello: 'world' });
|
|
31
64
|
}
|
|
32
|
-
}
|
|
65
|
+
};
|
|
33
66
|
|
|
34
|
-
// 2. Boot Kernel
|
|
35
|
-
const kernel = new ObjectKernel(
|
|
36
|
-
|
|
67
|
+
// 2. Boot Kernel with logging config
|
|
68
|
+
const kernel = new ObjectKernel({
|
|
69
|
+
logger: {
|
|
70
|
+
level: 'info',
|
|
71
|
+
format: 'pretty'
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
kernel.use(myPlugin);
|
|
37
76
|
await kernel.bootstrap();
|
|
38
77
|
|
|
39
78
|
// 3. Use Service
|
|
40
|
-
const service = kernel.
|
|
79
|
+
const service = kernel.getService('my-service');
|
|
80
|
+
|
|
81
|
+
// 4. Cleanup
|
|
82
|
+
await kernel.shutdown();
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Configurable Logger
|
|
86
|
+
|
|
87
|
+
The logger uses **[Pino](https://github.com/pinojs/pino)** for Node.js environments (high-performance, low-overhead) and a simple console-based logger for browsers. It automatically detects the runtime environment.
|
|
88
|
+
|
|
89
|
+
### Why Pino?
|
|
90
|
+
|
|
91
|
+
- **Fast**: One of the fastest Node.js loggers available
|
|
92
|
+
- **Low Overhead**: Minimal performance impact on your application
|
|
93
|
+
- **Structured Logging**: Native JSON output for log aggregation tools
|
|
94
|
+
- **Production Ready**: Battle-tested in production environments
|
|
95
|
+
- **Feature Rich**: Automatic log rotation, transports, child loggers, and more
|
|
96
|
+
|
|
97
|
+
### Logger Configuration
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
const kernel = new ObjectKernel({
|
|
101
|
+
logger: {
|
|
102
|
+
level: 'debug', // 'debug' | 'info' | 'warn' | 'error' | 'fatal'
|
|
103
|
+
format: 'pretty', // 'json' | 'text' | 'pretty'
|
|
104
|
+
sourceLocation: true, // Include file/line numbers
|
|
105
|
+
redact: ['password', 'token', 'apiKey'], // Keys to redact
|
|
106
|
+
file: './logs/app.log', // Node.js only
|
|
107
|
+
rotation: { // File rotation (Node.js only)
|
|
108
|
+
maxSize: '10m',
|
|
109
|
+
maxFiles: 5
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Using Logger in Plugins
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
const myPlugin: Plugin = {
|
|
119
|
+
name: 'my-plugin',
|
|
120
|
+
|
|
121
|
+
init: async (ctx: PluginContext) => {
|
|
122
|
+
// Basic logging
|
|
123
|
+
ctx.logger.info('Plugin initialized');
|
|
124
|
+
ctx.logger.debug('Debug info', { details: 'data' });
|
|
125
|
+
ctx.logger.warn('Warning message');
|
|
126
|
+
ctx.logger.error('Error occurred', new Error('Oops'));
|
|
127
|
+
|
|
128
|
+
// Sensitive data is automatically redacted
|
|
129
|
+
ctx.logger.info('User login', {
|
|
130
|
+
username: 'john',
|
|
131
|
+
password: 'secret123' // Logged as '***REDACTED***'
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Standalone Logger
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
import { createLogger } from '@objectstack/core';
|
|
141
|
+
|
|
142
|
+
const logger = createLogger({
|
|
143
|
+
level: 'info',
|
|
144
|
+
format: 'json'
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
logger.info('Application started');
|
|
148
|
+
|
|
149
|
+
// Child logger with context
|
|
150
|
+
const requestLogger = logger.child({
|
|
151
|
+
requestId: '123',
|
|
152
|
+
userId: 'user-456'
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
requestLogger.info('Processing request');
|
|
156
|
+
|
|
157
|
+
// Distributed tracing
|
|
158
|
+
const tracedLogger = logger.withTrace('trace-id-123', 'span-id-456');
|
|
159
|
+
|
|
160
|
+
// Cleanup
|
|
161
|
+
await logger.destroy();
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## Log Formats
|
|
165
|
+
|
|
166
|
+
### JSON (default for Node.js)
|
|
167
|
+
```json
|
|
168
|
+
{"timestamp":"2026-01-29T22:47:36.441Z","level":"info","message":"User action","context":{"userId":"123"}}
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### Text
|
|
172
|
+
```
|
|
173
|
+
2026-01-29T22:47:36.441Z | INFO | User action | {"userId":"123"}
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### Pretty (default for browser)
|
|
41
177
|
```
|
|
178
|
+
[INFO] User action { userId: '123' }
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## Plugin Development
|
|
182
|
+
|
|
183
|
+
```typescript
|
|
184
|
+
import { Plugin, PluginContext } from '@objectstack/core';
|
|
185
|
+
|
|
186
|
+
const databasePlugin: Plugin = {
|
|
187
|
+
name: 'database',
|
|
188
|
+
version: '1.0.0',
|
|
189
|
+
|
|
190
|
+
init: async (ctx: PluginContext) => {
|
|
191
|
+
const db = await connectToDatabase();
|
|
192
|
+
ctx.registerService('db', db);
|
|
193
|
+
ctx.logger.info('Database connected');
|
|
194
|
+
},
|
|
195
|
+
|
|
196
|
+
start: async (ctx: PluginContext) => {
|
|
197
|
+
ctx.logger.info('Database ready');
|
|
198
|
+
},
|
|
199
|
+
|
|
200
|
+
destroy: async () => {
|
|
201
|
+
await db.close();
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
const apiPlugin: Plugin = {
|
|
206
|
+
name: 'api',
|
|
207
|
+
dependencies: ['database'], // Load after database
|
|
208
|
+
|
|
209
|
+
init: async (ctx: PluginContext) => {
|
|
210
|
+
const db = ctx.getService('db');
|
|
211
|
+
const server = createServer(db);
|
|
212
|
+
ctx.registerService('api', server);
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
kernel.use(databasePlugin);
|
|
217
|
+
kernel.use(apiPlugin);
|
|
218
|
+
await kernel.bootstrap();
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
## Enhanced Kernel Usage
|
|
222
|
+
|
|
223
|
+
For production applications, use `EnhancedObjectKernel` for advanced features:
|
|
224
|
+
|
|
225
|
+
```typescript
|
|
226
|
+
import { EnhancedObjectKernel, PluginMetadata, ServiceLifecycle } from '@objectstack/core';
|
|
227
|
+
|
|
228
|
+
// Create enhanced kernel
|
|
229
|
+
const kernel = new EnhancedObjectKernel({
|
|
230
|
+
logger: { level: 'info', format: 'pretty' },
|
|
231
|
+
defaultStartupTimeout: 30000, // 30 seconds
|
|
232
|
+
gracefulShutdown: true,
|
|
233
|
+
shutdownTimeout: 60000, // 60 seconds
|
|
234
|
+
rollbackOnFailure: true, // Rollback on failures
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
// Plugin with version and health check
|
|
238
|
+
const plugin: PluginMetadata = {
|
|
239
|
+
name: 'my-plugin',
|
|
240
|
+
version: '1.2.3',
|
|
241
|
+
startupTimeout: 10000,
|
|
242
|
+
|
|
243
|
+
async init(ctx) {
|
|
244
|
+
ctx.registerService('my-service', serviceInstance);
|
|
245
|
+
},
|
|
246
|
+
|
|
247
|
+
async healthCheck() {
|
|
248
|
+
return {
|
|
249
|
+
healthy: true,
|
|
250
|
+
message: 'Service is operational'
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
// Register service factory with lifecycle
|
|
256
|
+
kernel.registerServiceFactory(
|
|
257
|
+
'database',
|
|
258
|
+
async (ctx) => await connectToDatabase(),
|
|
259
|
+
ServiceLifecycle.SINGLETON
|
|
260
|
+
);
|
|
261
|
+
|
|
262
|
+
await kernel.use(plugin);
|
|
263
|
+
await kernel.bootstrap();
|
|
264
|
+
|
|
265
|
+
// Check health
|
|
266
|
+
const health = await kernel.checkPluginHealth('my-plugin');
|
|
267
|
+
console.log(health);
|
|
268
|
+
|
|
269
|
+
// Get metrics
|
|
270
|
+
const metrics = kernel.getPluginMetrics();
|
|
271
|
+
console.log(metrics);
|
|
272
|
+
|
|
273
|
+
// Graceful shutdown
|
|
274
|
+
await kernel.shutdown();
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
See [ENHANCED_FEATURES.md](./ENHANCED_FEATURES.md) for comprehensive documentation.
|
|
278
|
+
See [examples/enhanced-kernel-example.ts](./examples/enhanced-kernel-example.ts) for a complete example.
|
|
279
|
+
|
|
280
|
+
## Environment Support
|
|
281
|
+
|
|
282
|
+
### Node.js Features (via Pino)
|
|
283
|
+
- High-performance structured logging
|
|
284
|
+
- Automatic file logging with rotation
|
|
285
|
+
- JSON format for log aggregation tools (Elasticsearch, Splunk, etc.)
|
|
286
|
+
- Pretty printing for development (via pino-pretty)
|
|
287
|
+
- Child loggers with inherited context
|
|
288
|
+
- Minimal performance overhead
|
|
289
|
+
|
|
290
|
+
### Browser Features
|
|
291
|
+
- Pretty console output with colors
|
|
292
|
+
- DevTools integration
|
|
293
|
+
- Lightweight implementation
|
|
294
|
+
- No external dependencies
|
|
295
|
+
|
|
296
|
+
## Security
|
|
297
|
+
|
|
298
|
+
Automatic sensitive data redaction:
|
|
299
|
+
- Default keys: `password`, `token`, `secret`, `key`
|
|
300
|
+
- Configurable via `redact` option
|
|
301
|
+
- Recursive through nested objects
|
|
302
|
+
|
|
303
|
+
## API Reference
|
|
304
|
+
|
|
305
|
+
### ObjectKernel (Basic)
|
|
306
|
+
- `ObjectKernel` - Basic microkernel class
|
|
307
|
+
- `createLogger(config)` - Create standalone logger
|
|
308
|
+
- `Plugin` - Plugin interface
|
|
309
|
+
- `PluginContext` - Runtime context for plugins
|
|
310
|
+
- `Logger` - Logger interface
|
|
311
|
+
|
|
312
|
+
### EnhancedObjectKernel (Advanced)
|
|
313
|
+
- `EnhancedObjectKernel` - Enhanced microkernel with production features
|
|
314
|
+
- `PluginLoader` - Plugin loading and validation
|
|
315
|
+
- `ServiceLifecycle` - Service lifecycle management (SINGLETON, TRANSIENT, SCOPED)
|
|
316
|
+
- `PluginMetadata` - Extended plugin interface with metadata
|
|
317
|
+
- `PluginHealthStatus` - Health check result interface
|
|
318
|
+
|
|
319
|
+
See [TypeScript definitions](./src/types.ts) for complete API.
|
|
320
|
+
|
|
321
|
+
## Documentation
|
|
322
|
+
|
|
323
|
+
- [ENHANCED_FEATURES.md](./ENHANCED_FEATURES.md) - Comprehensive guide to enhanced features
|
|
324
|
+
- [examples/enhanced-kernel-example.ts](./examples/enhanced-kernel-example.ts) - Complete working example
|
|
325
|
+
|
|
326
|
+
## License
|
|
327
|
+
|
|
328
|
+
Apache-2.0
|
|
@@ -1,34 +1,41 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { DataEngineQueryOptions, DataEngineInsertOptions, DataEngineUpdateOptions, DataEngineDeleteOptions, DataEngineAggregateOptions, DataEngineCountOptions, DataEngineRequest, // Added Request type for batch
|
|
2
|
+
QueryAST, DriverOptions } from '@objectstack/spec/data';
|
|
3
3
|
/**
|
|
4
4
|
* IDataEngine - Standard Data Engine Interface
|
|
5
5
|
*
|
|
6
6
|
* Abstract interface for data persistence capabilities.
|
|
7
7
|
* Following the Dependency Inversion Principle - plugins depend on this interface,
|
|
8
8
|
* not on concrete database implementations.
|
|
9
|
+
*
|
|
10
|
+
* Aligned with 'src/data/data-engine.zod.ts' in @objectstack/spec.
|
|
9
11
|
*/
|
|
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
12
|
export interface IDataEngine {
|
|
28
|
-
insert(objectName: string, data: any): Promise<any>;
|
|
29
13
|
find(objectName: string, query?: DataEngineQueryOptions): Promise<any[]>;
|
|
30
|
-
|
|
31
|
-
|
|
14
|
+
findOne(objectName: string, query?: DataEngineQueryOptions): Promise<any>;
|
|
15
|
+
insert(objectName: string, data: any | any[], options?: DataEngineInsertOptions): Promise<any>;
|
|
16
|
+
update(objectName: string, data: any, options?: DataEngineUpdateOptions): Promise<any>;
|
|
17
|
+
delete(objectName: string, options?: DataEngineDeleteOptions): Promise<any>;
|
|
18
|
+
count(objectName: string, query?: DataEngineCountOptions): Promise<number>;
|
|
19
|
+
aggregate(objectName: string, query: DataEngineAggregateOptions): Promise<any[]>;
|
|
20
|
+
/**
|
|
21
|
+
* Vector Search (AI/RAG)
|
|
22
|
+
*/
|
|
23
|
+
vectorFind?(objectName: string, vector: number[], options?: {
|
|
24
|
+
filter?: any;
|
|
25
|
+
limit?: number;
|
|
26
|
+
select?: string[];
|
|
27
|
+
threshold?: number;
|
|
28
|
+
}): Promise<any[]>;
|
|
29
|
+
/**
|
|
30
|
+
* Batch Operations (Transactional)
|
|
31
|
+
*/
|
|
32
|
+
batch?(requests: DataEngineRequest[], options?: {
|
|
33
|
+
transaction?: boolean;
|
|
34
|
+
}): Promise<any[]>;
|
|
35
|
+
/**
|
|
36
|
+
* Execute raw command (Escape hatch)
|
|
37
|
+
*/
|
|
38
|
+
execute?(command: any, options?: Record<string, any>): Promise<any>;
|
|
32
39
|
}
|
|
33
40
|
export interface DriverInterface {
|
|
34
41
|
name: string;
|
|
@@ -40,6 +47,16 @@ export interface DriverInterface {
|
|
|
40
47
|
create(object: string, data: any, options?: DriverOptions): Promise<any>;
|
|
41
48
|
update(object: string, id: any, data: any, options?: DriverOptions): Promise<any>;
|
|
42
49
|
delete(object: string, id: any, options?: DriverOptions): Promise<any>;
|
|
50
|
+
/**
|
|
51
|
+
* Bulk & Batch Operations
|
|
52
|
+
*/
|
|
53
|
+
bulkCreate?(object: string, data: any[], options?: DriverOptions): Promise<any>;
|
|
54
|
+
updateMany?(object: string, query: QueryAST, data: any, options?: DriverOptions): Promise<any>;
|
|
55
|
+
deleteMany?(object: string, query: QueryAST, options?: DriverOptions): Promise<any>;
|
|
43
56
|
count?(object: string, query: QueryAST, options?: DriverOptions): Promise<number>;
|
|
57
|
+
/**
|
|
58
|
+
* Raw Execution
|
|
59
|
+
*/
|
|
60
|
+
execute?(command: any, params?: any, options?: DriverOptions): Promise<any>;
|
|
44
61
|
}
|
|
45
62
|
//# sourceMappingURL=data-engine.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-engine.d.ts","sourceRoot":"","sources":["../../src/contracts/data-engine.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"data-engine.d.ts","sourceRoot":"","sources":["../../src/contracts/data-engine.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,0BAA0B,EAC1B,sBAAsB,EACtB,iBAAiB,EAAE,+BAA+B;AAClD,QAAQ,EACR,aAAa,EACd,MAAM,wBAAwB,CAAC;AAEhC;;;;;;;;GAQG;AAEH,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,sBAAsB,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IACzE,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,sBAAsB,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IAC1E,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,GAAG,EAAE,EAAE,OAAO,CAAC,EAAE,uBAAuB,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IAC/F,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EA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;OAEG;IACH,OAAO,CAAC,CAAC,OAAO,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;CAC7E"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Logger Contract
|
|
3
|
+
*
|
|
4
|
+
* Defines the interface for logging in ObjectStack.
|
|
5
|
+
* Compatible with both browser console and structured logging systems.
|
|
6
|
+
*/
|
|
7
|
+
export interface Logger {
|
|
8
|
+
/**
|
|
9
|
+
* Log a debug message
|
|
10
|
+
* @param message - The message to log
|
|
11
|
+
* @param meta - Optional metadata to include
|
|
12
|
+
*/
|
|
13
|
+
debug(message: string, meta?: Record<string, any>): void;
|
|
14
|
+
/**
|
|
15
|
+
* Log an informational message
|
|
16
|
+
* @param message - The message to log
|
|
17
|
+
* @param meta - Optional metadata to include
|
|
18
|
+
*/
|
|
19
|
+
info(message: string, meta?: Record<string, any>): void;
|
|
20
|
+
/**
|
|
21
|
+
* Log a warning message
|
|
22
|
+
* @param message - The message to log
|
|
23
|
+
* @param meta - Optional metadata to include
|
|
24
|
+
*/
|
|
25
|
+
warn(message: string, meta?: Record<string, any>): void;
|
|
26
|
+
/**
|
|
27
|
+
* Log an error message
|
|
28
|
+
* @param message - The message to log
|
|
29
|
+
* @param error - Optional error object
|
|
30
|
+
* @param meta - Optional metadata to include
|
|
31
|
+
*/
|
|
32
|
+
error(message: string, error?: Error, meta?: Record<string, any>): void;
|
|
33
|
+
/**
|
|
34
|
+
* Log a fatal error message
|
|
35
|
+
* @param message - The message to log
|
|
36
|
+
* @param error - Optional error object
|
|
37
|
+
* @param meta - Optional metadata to include
|
|
38
|
+
*/
|
|
39
|
+
fatal?(message: string, error?: Error, meta?: Record<string, any>): void;
|
|
40
|
+
/**
|
|
41
|
+
* Create a child logger with additional context
|
|
42
|
+
* @param context - Context to add to all logs from this child
|
|
43
|
+
*/
|
|
44
|
+
child?(context: Record<string, any>): Logger;
|
|
45
|
+
/**
|
|
46
|
+
* Set trace context for distributed tracing
|
|
47
|
+
* @param traceId - Trace identifier
|
|
48
|
+
* @param spanId - Span identifier
|
|
49
|
+
*/
|
|
50
|
+
withTrace?(traceId: string, spanId?: string): Logger;
|
|
51
|
+
/**
|
|
52
|
+
* Compatibility method for console.log usage
|
|
53
|
+
* @param message - The message to log
|
|
54
|
+
* @param args - Additional arguments
|
|
55
|
+
*/
|
|
56
|
+
log?(message: string, ...args: any[]): void;
|
|
57
|
+
/**
|
|
58
|
+
* Cleanup resources (close file streams, etc.)
|
|
59
|
+
* Should be called when the logger is no longer needed
|
|
60
|
+
*/
|
|
61
|
+
destroy?(): Promise<void>;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/contracts/logger.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,WAAW,MAAM;IACnB;;;;OAIG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC;IAEzD;;;;OAIG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC;IAExD;;;;OAIG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC;IAExD;;;;;OAKG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC;IAExE;;;;;OAKG;IACH,KAAK,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC;IAEzE;;;OAGG;IACH,KAAK,CAAC,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC;IAE7C;;;;OAIG;IACH,SAAS,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAErD;;;;OAIG;IACH,GAAG,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAE5C;;;OAGG;IACH,OAAO,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { Plugin } from './types.js';
|
|
2
|
+
import type { LoggerConfig } from '@objectstack/spec/system';
|
|
3
|
+
import { ServiceLifecycle, ServiceFactory } from './plugin-loader.js';
|
|
4
|
+
/**
|
|
5
|
+
* Enhanced Kernel Configuration
|
|
6
|
+
*/
|
|
7
|
+
export interface EnhancedKernelConfig {
|
|
8
|
+
logger?: Partial<LoggerConfig>;
|
|
9
|
+
/** Default plugin startup timeout in milliseconds */
|
|
10
|
+
defaultStartupTimeout?: number;
|
|
11
|
+
/** Whether to enable graceful shutdown */
|
|
12
|
+
gracefulShutdown?: boolean;
|
|
13
|
+
/** Graceful shutdown timeout in milliseconds */
|
|
14
|
+
shutdownTimeout?: number;
|
|
15
|
+
/** Whether to rollback on startup failure */
|
|
16
|
+
rollbackOnFailure?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Enhanced ObjectKernel with Advanced Plugin Management
|
|
20
|
+
*
|
|
21
|
+
* Extends the basic ObjectKernel with:
|
|
22
|
+
* - Async plugin loading with validation
|
|
23
|
+
* - Version compatibility checking
|
|
24
|
+
* - Plugin signature verification
|
|
25
|
+
* - Configuration validation (Zod)
|
|
26
|
+
* - Factory-based dependency injection
|
|
27
|
+
* - Service lifecycle management (singleton/transient/scoped)
|
|
28
|
+
* - Circular dependency detection
|
|
29
|
+
* - Lazy loading services
|
|
30
|
+
* - Graceful shutdown
|
|
31
|
+
* - Plugin startup timeout control
|
|
32
|
+
* - Startup failure rollback
|
|
33
|
+
* - Plugin health checks
|
|
34
|
+
*/
|
|
35
|
+
export declare class EnhancedObjectKernel {
|
|
36
|
+
private plugins;
|
|
37
|
+
private services;
|
|
38
|
+
private hooks;
|
|
39
|
+
private state;
|
|
40
|
+
private logger;
|
|
41
|
+
private context;
|
|
42
|
+
private pluginLoader;
|
|
43
|
+
private config;
|
|
44
|
+
private startedPlugins;
|
|
45
|
+
private pluginStartTimes;
|
|
46
|
+
private shutdownHandlers;
|
|
47
|
+
constructor(config?: EnhancedKernelConfig);
|
|
48
|
+
/**
|
|
49
|
+
* Register a plugin with enhanced validation
|
|
50
|
+
*/
|
|
51
|
+
use(plugin: Plugin): Promise<this>;
|
|
52
|
+
/**
|
|
53
|
+
* Register a service factory with lifecycle management
|
|
54
|
+
*/
|
|
55
|
+
registerServiceFactory<T>(name: string, factory: ServiceFactory<T>, lifecycle?: ServiceLifecycle, dependencies?: string[]): this;
|
|
56
|
+
/**
|
|
57
|
+
* Bootstrap the kernel with enhanced features
|
|
58
|
+
*/
|
|
59
|
+
bootstrap(): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Graceful shutdown with timeout
|
|
62
|
+
*/
|
|
63
|
+
shutdown(): Promise<void>;
|
|
64
|
+
/**
|
|
65
|
+
* Check health of a specific plugin
|
|
66
|
+
*/
|
|
67
|
+
checkPluginHealth(pluginName: string): Promise<any>;
|
|
68
|
+
/**
|
|
69
|
+
* Check health of all plugins
|
|
70
|
+
*/
|
|
71
|
+
checkAllPluginsHealth(): Promise<Map<string, any>>;
|
|
72
|
+
/**
|
|
73
|
+
* Get plugin startup metrics
|
|
74
|
+
*/
|
|
75
|
+
getPluginMetrics(): Map<string, number>;
|
|
76
|
+
/**
|
|
77
|
+
* Get a service (sync helper)
|
|
78
|
+
*/
|
|
79
|
+
getService<T>(name: string): T;
|
|
80
|
+
/**
|
|
81
|
+
* Get a service asynchronously (supports factories)
|
|
82
|
+
*/
|
|
83
|
+
getServiceAsync<T>(name: string, scopeId?: string): Promise<T>;
|
|
84
|
+
/**
|
|
85
|
+
* Check if kernel is running
|
|
86
|
+
*/
|
|
87
|
+
isRunning(): boolean;
|
|
88
|
+
/**
|
|
89
|
+
* Get kernel state
|
|
90
|
+
*/
|
|
91
|
+
getState(): string;
|
|
92
|
+
private initPluginWithTimeout;
|
|
93
|
+
private startPluginWithTimeout;
|
|
94
|
+
private rollbackStartedPlugins;
|
|
95
|
+
private performShutdown;
|
|
96
|
+
private resolveDependencies;
|
|
97
|
+
private registerShutdownSignals;
|
|
98
|
+
/**
|
|
99
|
+
* Register a custom shutdown handler
|
|
100
|
+
*/
|
|
101
|
+
onShutdown(handler: () => Promise<void>): void;
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=enhanced-kernel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enhanced-kernel.d.ts","sourceRoot":"","sources":["../src/enhanced-kernel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAiB,MAAM,YAAY,CAAC;AAEnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAgC,gBAAgB,EAAE,cAAc,EAAuB,MAAM,oBAAoB,CAAC;AAEzH;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACjC,MAAM,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC;IAE/B,qDAAqD;IACrD,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAE/B,0CAA0C;IAC1C,gBA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