@objectstack/core 2.0.4 → 2.0.6
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/.turbo/turbo-build.log +10 -10
- package/CHANGELOG.md +15 -0
- package/dist/index.cjs +38 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +38 -0
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/kernel-base.ts +15 -0
- package/src/kernel.test.ts +87 -0
- package/src/kernel.ts +9 -0
- package/src/lite-kernel.test.ts +48 -0
- package/src/plugin-loader.ts +12 -0
- package/src/security/plugin-permission-enforcer.ts +6 -0
- package/src/types.ts +11 -0
package/dist/index.d.cts
CHANGED
|
@@ -133,6 +133,12 @@ declare class PluginLoader {
|
|
|
133
133
|
* Register a static service instance (legacy support)
|
|
134
134
|
*/
|
|
135
135
|
registerService(name: string, service: any): void;
|
|
136
|
+
/**
|
|
137
|
+
* Replace an existing service instance.
|
|
138
|
+
* Used by optimization plugins to swap kernel internals.
|
|
139
|
+
* @throws Error if service does not exist
|
|
140
|
+
*/
|
|
141
|
+
replaceService(name: string, service: any): void;
|
|
136
142
|
/**
|
|
137
143
|
* Check if a service is registered (either as instance or factory)
|
|
138
144
|
*/
|
|
@@ -300,6 +306,16 @@ interface PluginContext {
|
|
|
300
306
|
* @throws Error if service not found
|
|
301
307
|
*/
|
|
302
308
|
getService<T>(name: string): T;
|
|
309
|
+
/**
|
|
310
|
+
* Replace an existing service with a new implementation.
|
|
311
|
+
* Useful for optimization plugins that wrap or swap kernel internals
|
|
312
|
+
* (e.g., metadata registry, connection pooling).
|
|
313
|
+
*
|
|
314
|
+
* @param name - Service name to replace
|
|
315
|
+
* @param implementation - New service implementation
|
|
316
|
+
* @throws Error if the service does not exist
|
|
317
|
+
*/
|
|
318
|
+
replaceService<T>(name: string, implementation: T): void;
|
|
303
319
|
/**
|
|
304
320
|
* Get all registered services
|
|
305
321
|
*/
|
|
@@ -1252,6 +1268,7 @@ declare class SecurePluginContext implements PluginContext {
|
|
|
1252
1268
|
constructor(pluginName: string, permissionEnforcer: PluginPermissionEnforcer, baseContext: PluginContext);
|
|
1253
1269
|
registerService(name: string, service: any): void;
|
|
1254
1270
|
getService<T>(name: string): T;
|
|
1271
|
+
replaceService<T>(name: string, implementation: T): void;
|
|
1255
1272
|
getServices(): Map<string, any>;
|
|
1256
1273
|
hook(name: string, handler: (...args: any[]) => void | Promise<void>): void;
|
|
1257
1274
|
trigger(name: string, ...args: any[]): Promise<void>;
|
package/dist/index.d.ts
CHANGED
|
@@ -133,6 +133,12 @@ declare class PluginLoader {
|
|
|
133
133
|
* Register a static service instance (legacy support)
|
|
134
134
|
*/
|
|
135
135
|
registerService(name: string, service: any): void;
|
|
136
|
+
/**
|
|
137
|
+
* Replace an existing service instance.
|
|
138
|
+
* Used by optimization plugins to swap kernel internals.
|
|
139
|
+
* @throws Error if service does not exist
|
|
140
|
+
*/
|
|
141
|
+
replaceService(name: string, service: any): void;
|
|
136
142
|
/**
|
|
137
143
|
* Check if a service is registered (either as instance or factory)
|
|
138
144
|
*/
|
|
@@ -300,6 +306,16 @@ interface PluginContext {
|
|
|
300
306
|
* @throws Error if service not found
|
|
301
307
|
*/
|
|
302
308
|
getService<T>(name: string): T;
|
|
309
|
+
/**
|
|
310
|
+
* Replace an existing service with a new implementation.
|
|
311
|
+
* Useful for optimization plugins that wrap or swap kernel internals
|
|
312
|
+
* (e.g., metadata registry, connection pooling).
|
|
313
|
+
*
|
|
314
|
+
* @param name - Service name to replace
|
|
315
|
+
* @param implementation - New service implementation
|
|
316
|
+
* @throws Error if the service does not exist
|
|
317
|
+
*/
|
|
318
|
+
replaceService<T>(name: string, implementation: T): void;
|
|
303
319
|
/**
|
|
304
320
|
* Get all registered services
|
|
305
321
|
*/
|
|
@@ -1252,6 +1268,7 @@ declare class SecurePluginContext implements PluginContext {
|
|
|
1252
1268
|
constructor(pluginName: string, permissionEnforcer: PluginPermissionEnforcer, baseContext: PluginContext);
|
|
1253
1269
|
registerService(name: string, service: any): void;
|
|
1254
1270
|
getService<T>(name: string): T;
|
|
1271
|
+
replaceService<T>(name: string, implementation: T): void;
|
|
1255
1272
|
getServices(): Map<string, any>;
|
|
1256
1273
|
hook(name: string, handler: (...args: any[]) => void | Promise<void>): void;
|
|
1257
1274
|
trigger(name: string, ...args: any[]): Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -61,6 +61,20 @@ var ObjectKernelBase = class {
|
|
|
61
61
|
return this.services.get(name);
|
|
62
62
|
}
|
|
63
63
|
},
|
|
64
|
+
replaceService: (name, implementation) => {
|
|
65
|
+
if (this.services instanceof Map) {
|
|
66
|
+
if (!this.services.has(name)) {
|
|
67
|
+
throw new Error(`[Kernel] Service '${name}' not found. Use registerService() to add new services.`);
|
|
68
|
+
}
|
|
69
|
+
this.services.set(name, implementation);
|
|
70
|
+
} else {
|
|
71
|
+
if (!this.services.has(name)) {
|
|
72
|
+
throw new Error(`[Kernel] Service '${name}' not found. Use registerService() to add new services.`);
|
|
73
|
+
}
|
|
74
|
+
this.services.register(name, implementation);
|
|
75
|
+
}
|
|
76
|
+
this.logger.info(`Service '${name}' replaced`, { service: name });
|
|
77
|
+
},
|
|
64
78
|
hook: (name, handler) => {
|
|
65
79
|
if (!this.hooks.has(name)) {
|
|
66
80
|
this.hooks.set(name, []);
|
|
@@ -735,6 +749,17 @@ var PluginLoader = class {
|
|
|
735
749
|
}
|
|
736
750
|
this.serviceInstances.set(name, service);
|
|
737
751
|
}
|
|
752
|
+
/**
|
|
753
|
+
* Replace an existing service instance.
|
|
754
|
+
* Used by optimization plugins to swap kernel internals.
|
|
755
|
+
* @throws Error if service does not exist
|
|
756
|
+
*/
|
|
757
|
+
replaceService(name, service) {
|
|
758
|
+
if (!this.hasService(name)) {
|
|
759
|
+
throw new Error(`Service '${name}' not found`);
|
|
760
|
+
}
|
|
761
|
+
this.serviceInstances.set(name, service);
|
|
762
|
+
}
|
|
738
763
|
/**
|
|
739
764
|
* Check if a service is registered (either as instance or factory)
|
|
740
765
|
*/
|
|
@@ -970,6 +995,15 @@ var ObjectKernel = class {
|
|
|
970
995
|
throw new Error(`[Kernel] Service '${name}' not found`);
|
|
971
996
|
}
|
|
972
997
|
},
|
|
998
|
+
replaceService: (name, implementation) => {
|
|
999
|
+
const hasService = this.services.has(name) || this.pluginLoader.hasService(name);
|
|
1000
|
+
if (!hasService) {
|
|
1001
|
+
throw new Error(`[Kernel] Service '${name}' not found. Use registerService() to add new services.`);
|
|
1002
|
+
}
|
|
1003
|
+
this.services.set(name, implementation);
|
|
1004
|
+
this.pluginLoader.replaceService(name, implementation);
|
|
1005
|
+
this.logger.info(`Service '${name}' replaced`, { service: name });
|
|
1006
|
+
},
|
|
973
1007
|
hook: (name, handler) => {
|
|
974
1008
|
if (!this.hooks.has(name)) {
|
|
975
1009
|
this.hooks.set(name, []);
|
|
@@ -2738,6 +2772,10 @@ var SecurePluginContext = class {
|
|
|
2738
2772
|
this.permissionEnforcer.enforceServiceAccess(this.pluginName, name);
|
|
2739
2773
|
return this.baseContext.getService(name);
|
|
2740
2774
|
}
|
|
2775
|
+
replaceService(name, implementation) {
|
|
2776
|
+
this.permissionEnforcer.enforceServiceAccess(this.pluginName, name);
|
|
2777
|
+
this.baseContext.replaceService(name, implementation);
|
|
2778
|
+
}
|
|
2741
2779
|
getServices() {
|
|
2742
2780
|
return this.baseContext.getServices();
|
|
2743
2781
|
}
|