@objectstack/core 1.0.4 → 1.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.
Files changed (127) hide show
  1. package/.turbo/turbo-build.log +22 -0
  2. package/CHANGELOG.md +19 -0
  3. package/dist/index.cjs +4304 -0
  4. package/dist/index.cjs.map +1 -0
  5. package/dist/index.d.cts +1777 -0
  6. package/dist/index.d.ts +1776 -21
  7. package/dist/index.js +4246 -23
  8. package/dist/index.js.map +1 -0
  9. package/package.json +5 -5
  10. package/src/logger.ts +2 -2
  11. package/src/security/plugin-signature-verifier.ts +12 -11
  12. package/tsconfig.json +1 -3
  13. package/dist/api-registry-plugin.d.ts +0 -54
  14. package/dist/api-registry-plugin.d.ts.map +0 -1
  15. package/dist/api-registry-plugin.js +0 -53
  16. package/dist/api-registry-plugin.test.d.ts +0 -2
  17. package/dist/api-registry-plugin.test.d.ts.map +0 -1
  18. package/dist/api-registry-plugin.test.js +0 -334
  19. package/dist/api-registry.d.ts +0 -259
  20. package/dist/api-registry.d.ts.map +0 -1
  21. package/dist/api-registry.js +0 -600
  22. package/dist/api-registry.test.d.ts +0 -2
  23. package/dist/api-registry.test.d.ts.map +0 -1
  24. package/dist/api-registry.test.js +0 -957
  25. package/dist/contracts/data-engine.d.ts +0 -62
  26. package/dist/contracts/data-engine.d.ts.map +0 -1
  27. package/dist/contracts/data-engine.js +0 -1
  28. package/dist/contracts/http-server.d.ts +0 -119
  29. package/dist/contracts/http-server.d.ts.map +0 -1
  30. package/dist/contracts/http-server.js +0 -11
  31. package/dist/contracts/logger.d.ts +0 -63
  32. package/dist/contracts/logger.d.ts.map +0 -1
  33. package/dist/contracts/logger.js +0 -1
  34. package/dist/dependency-resolver.d.ts +0 -62
  35. package/dist/dependency-resolver.d.ts.map +0 -1
  36. package/dist/dependency-resolver.js +0 -317
  37. package/dist/dependency-resolver.test.d.ts +0 -2
  38. package/dist/dependency-resolver.test.d.ts.map +0 -1
  39. package/dist/dependency-resolver.test.js +0 -241
  40. package/dist/health-monitor.d.ts +0 -65
  41. package/dist/health-monitor.d.ts.map +0 -1
  42. package/dist/health-monitor.js +0 -269
  43. package/dist/health-monitor.test.d.ts +0 -2
  44. package/dist/health-monitor.test.d.ts.map +0 -1
  45. package/dist/health-monitor.test.js +0 -68
  46. package/dist/hot-reload.d.ts +0 -79
  47. package/dist/hot-reload.d.ts.map +0 -1
  48. package/dist/hot-reload.js +0 -313
  49. package/dist/index.d.ts.map +0 -1
  50. package/dist/kernel-base.d.ts +0 -84
  51. package/dist/kernel-base.d.ts.map +0 -1
  52. package/dist/kernel-base.js +0 -219
  53. package/dist/kernel.d.ts +0 -113
  54. package/dist/kernel.d.ts.map +0 -1
  55. package/dist/kernel.js +0 -472
  56. package/dist/kernel.test.d.ts +0 -2
  57. package/dist/kernel.test.d.ts.map +0 -1
  58. package/dist/kernel.test.js +0 -414
  59. package/dist/lite-kernel.d.ts +0 -55
  60. package/dist/lite-kernel.d.ts.map +0 -1
  61. package/dist/lite-kernel.js +0 -112
  62. package/dist/lite-kernel.test.d.ts +0 -2
  63. package/dist/lite-kernel.test.d.ts.map +0 -1
  64. package/dist/lite-kernel.test.js +0 -161
  65. package/dist/logger.d.ts +0 -71
  66. package/dist/logger.d.ts.map +0 -1
  67. package/dist/logger.js +0 -312
  68. package/dist/logger.test.d.ts +0 -2
  69. package/dist/logger.test.d.ts.map +0 -1
  70. package/dist/logger.test.js +0 -92
  71. package/dist/plugin-loader.d.ts +0 -164
  72. package/dist/plugin-loader.d.ts.map +0 -1
  73. package/dist/plugin-loader.js +0 -319
  74. package/dist/plugin-loader.test.d.ts +0 -2
  75. package/dist/plugin-loader.test.d.ts.map +0 -1
  76. package/dist/plugin-loader.test.js +0 -348
  77. package/dist/qa/adapter.d.ts +0 -14
  78. package/dist/qa/adapter.d.ts.map +0 -1
  79. package/dist/qa/adapter.js +0 -1
  80. package/dist/qa/http-adapter.d.ts +0 -16
  81. package/dist/qa/http-adapter.d.ts.map +0 -1
  82. package/dist/qa/http-adapter.js +0 -107
  83. package/dist/qa/index.d.ts +0 -4
  84. package/dist/qa/index.d.ts.map +0 -1
  85. package/dist/qa/index.js +0 -3
  86. package/dist/qa/runner.d.ts +0 -27
  87. package/dist/qa/runner.d.ts.map +0 -1
  88. package/dist/qa/runner.js +0 -157
  89. package/dist/security/index.d.ts +0 -17
  90. package/dist/security/index.d.ts.map +0 -1
  91. package/dist/security/index.js +0 -17
  92. package/dist/security/permission-manager.d.ts +0 -96
  93. package/dist/security/permission-manager.d.ts.map +0 -1
  94. package/dist/security/permission-manager.js +0 -235
  95. package/dist/security/permission-manager.test.d.ts +0 -2
  96. package/dist/security/permission-manager.test.d.ts.map +0 -1
  97. package/dist/security/permission-manager.test.js +0 -220
  98. package/dist/security/plugin-config-validator.d.ts +0 -79
  99. package/dist/security/plugin-config-validator.d.ts.map +0 -1
  100. package/dist/security/plugin-config-validator.js +0 -166
  101. package/dist/security/plugin-config-validator.test.d.ts +0 -2
  102. package/dist/security/plugin-config-validator.test.d.ts.map +0 -1
  103. package/dist/security/plugin-config-validator.test.js +0 -223
  104. package/dist/security/plugin-permission-enforcer.d.ts +0 -154
  105. package/dist/security/plugin-permission-enforcer.d.ts.map +0 -1
  106. package/dist/security/plugin-permission-enforcer.js +0 -323
  107. package/dist/security/plugin-permission-enforcer.test.d.ts +0 -2
  108. package/dist/security/plugin-permission-enforcer.test.d.ts.map +0 -1
  109. package/dist/security/plugin-permission-enforcer.test.js +0 -205
  110. package/dist/security/plugin-signature-verifier.d.ts +0 -96
  111. package/dist/security/plugin-signature-verifier.d.ts.map +0 -1
  112. package/dist/security/plugin-signature-verifier.js +0 -250
  113. package/dist/security/sandbox-runtime.d.ts +0 -115
  114. package/dist/security/sandbox-runtime.d.ts.map +0 -1
  115. package/dist/security/sandbox-runtime.js +0 -311
  116. package/dist/security/security-scanner.d.ts +0 -92
  117. package/dist/security/security-scanner.d.ts.map +0 -1
  118. package/dist/security/security-scanner.js +0 -273
  119. package/dist/types.d.ts +0 -89
  120. package/dist/types.d.ts.map +0 -1
  121. package/dist/types.js +0 -1
  122. package/dist/utils/env.d.ts +0 -20
  123. package/dist/utils/env.d.ts.map +0 -1
  124. package/dist/utils/env.js +0 -46
  125. package/dist/utils/env.test.d.ts +0 -2
  126. package/dist/utils/env.test.d.ts.map +0 -1
  127. package/dist/utils/env.test.js +0 -52
@@ -1,164 +0,0 @@
1
- import { Plugin, PluginContext } from './types.js';
2
- import type { Logger } from '@objectstack/spec/contracts';
3
- import { z } from 'zod';
4
- /**
5
- * Service Lifecycle Types
6
- * Defines how services are instantiated and managed
7
- */
8
- export declare enum ServiceLifecycle {
9
- /** Single instance shared across all requests */
10
- SINGLETON = "singleton",
11
- /** New instance created for each request */
12
- TRANSIENT = "transient",
13
- /** New instance per scope (e.g., per HTTP request) */
14
- SCOPED = "scoped"
15
- }
16
- /**
17
- * Service Factory
18
- * Function that creates a service instance
19
- */
20
- export type ServiceFactory<T = any> = (ctx: PluginContext) => T | Promise<T>;
21
- /**
22
- * Service Registration Options
23
- */
24
- export interface ServiceRegistration {
25
- name: string;
26
- factory: ServiceFactory;
27
- lifecycle: ServiceLifecycle;
28
- dependencies?: string[];
29
- }
30
- /**
31
- * Plugin Configuration Validator Interface
32
- * Uses Zod for runtime validation of plugin configurations
33
- * @deprecated Use the PluginConfigValidator class from security module instead
34
- */
35
- export interface IPluginConfigValidator {
36
- schema: z.ZodSchema;
37
- validate(config: any): any;
38
- }
39
- /**
40
- * Plugin Metadata with Enhanced Features
41
- */
42
- export interface PluginMetadata extends Plugin {
43
- /** Semantic version (e.g., "1.0.0") */
44
- version: string;
45
- /** Configuration schema for validation */
46
- configSchema?: z.ZodSchema;
47
- /** Plugin signature for security verification */
48
- signature?: string;
49
- /** Plugin health check function */
50
- healthCheck?(): Promise<PluginHealthStatus>;
51
- /** Startup timeout in milliseconds (default: 30000) */
52
- startupTimeout?: number;
53
- /** Whether plugin supports hot reload */
54
- hotReloadable?: boolean;
55
- }
56
- /**
57
- * Plugin Health Status
58
- */
59
- export interface PluginHealthStatus {
60
- healthy: boolean;
61
- message?: string;
62
- details?: Record<string, any>;
63
- lastCheck?: Date;
64
- }
65
- /**
66
- * Plugin Load Result
67
- */
68
- export interface PluginLoadResult {
69
- success: boolean;
70
- plugin?: PluginMetadata;
71
- error?: Error;
72
- loadTime?: number;
73
- }
74
- /**
75
- * Plugin Startup Result
76
- */
77
- export interface PluginStartupResult {
78
- success: boolean;
79
- pluginName: string;
80
- startTime?: number;
81
- error?: Error;
82
- timedOut?: boolean;
83
- }
84
- /**
85
- * Version Compatibility Result
86
- */
87
- export interface VersionCompatibility {
88
- compatible: boolean;
89
- pluginVersion: string;
90
- requiredVersion?: string;
91
- message?: string;
92
- }
93
- /**
94
- * Enhanced Plugin Loader
95
- * Provides advanced plugin loading capabilities with validation, security, and lifecycle management
96
- */
97
- export declare class PluginLoader {
98
- private logger;
99
- private context?;
100
- private configValidator;
101
- private loadedPlugins;
102
- private serviceFactories;
103
- private serviceInstances;
104
- private scopedServices;
105
- private creating;
106
- constructor(logger: Logger);
107
- /**
108
- * Set the plugin context for service factories
109
- */
110
- setContext(context: PluginContext): void;
111
- /**
112
- * Get a synchronous service instance if it exists (Sync Helper)
113
- */
114
- getServiceInstance<T>(name: string): T | undefined;
115
- /**
116
- * Load a plugin asynchronously with validation
117
- */
118
- loadPlugin(plugin: Plugin): Promise<PluginLoadResult>;
119
- /**
120
- * Register a service with factory function
121
- */
122
- registerServiceFactory(registration: ServiceRegistration): void;
123
- /**
124
- * Get or create a service instance based on lifecycle type
125
- */
126
- getService<T>(name: string, scopeId?: string): Promise<T>;
127
- /**
128
- * Register a static service instance (legacy support)
129
- */
130
- registerService(name: string, service: any): void;
131
- /**
132
- * Check if a service is registered (either as instance or factory)
133
- */
134
- hasService(name: string): boolean;
135
- /**
136
- * Detect circular dependencies in service factories
137
- * Note: This only detects cycles in service dependencies, not plugin dependencies.
138
- * Plugin dependency cycles are detected in the kernel's resolveDependencies method.
139
- */
140
- detectCircularDependencies(): string[];
141
- /**
142
- * Check plugin health
143
- */
144
- checkPluginHealth(pluginName: string): Promise<PluginHealthStatus>;
145
- /**
146
- * Clear scoped services for a scope
147
- */
148
- clearScope(scopeId: string): void;
149
- /**
150
- * Get all loaded plugins
151
- */
152
- getLoadedPlugins(): Map<string, PluginMetadata>;
153
- private toPluginMetadata;
154
- private validatePluginStructure;
155
- private checkVersionCompatibility;
156
- private isValidSemanticVersion;
157
- private validatePluginConfig;
158
- private verifyPluginSignature;
159
- private getSingletonService;
160
- private createTransientService;
161
- private getScopedService;
162
- private createServiceInstance;
163
- }
164
- //# sourceMappingURL=plugin-loader.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"plugin-loader.d.ts","sourceRoot":"","sources":["../src/plugin-loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB;;;GAGG;AACH,oBAAY,gBAAgB;IACxB,iDAAiD;IACjD,SAAS,cAAc;IACvB,4CAA4C;IAC5C,SAAS,cAAc;IACvB,sDAAsD;IACtD,MAAM,WAAW;CACpB;AAED;;;GAGG;AACH,MAAM,MAAM,cAAc,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,aAAa,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAE7E;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,cAAc,CAAC;IACxB,SAAS,EAAE,gBAAgB,CAAC;IAC5B,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CAC3B;AAED;;;;GAIG;AACH,MAAM,WAAW,sBAAsB;IACnC,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC;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AAC,yBAAyB;IAmBjC,OAAO,CAAC,sBAAsB;IAK9B,OAAO,CAAC,oBAAoB;YAgBd,qBAAqB;YAWrB,mBAAmB;YAanB,sBAAsB;YAMtB,gBAAgB;YAiBhB,qBAAqB;CAgBtC"}
@@ -1,319 +0,0 @@
1
- import { PluginConfigValidator } from './security/plugin-config-validator.js';
2
- /**
3
- * Service Lifecycle Types
4
- * Defines how services are instantiated and managed
5
- */
6
- export var ServiceLifecycle;
7
- (function (ServiceLifecycle) {
8
- /** Single instance shared across all requests */
9
- ServiceLifecycle["SINGLETON"] = "singleton";
10
- /** New instance created for each request */
11
- ServiceLifecycle["TRANSIENT"] = "transient";
12
- /** New instance per scope (e.g., per HTTP request) */
13
- ServiceLifecycle["SCOPED"] = "scoped";
14
- })(ServiceLifecycle || (ServiceLifecycle = {}));
15
- /**
16
- * Enhanced Plugin Loader
17
- * Provides advanced plugin loading capabilities with validation, security, and lifecycle management
18
- */
19
- export class PluginLoader {
20
- constructor(logger) {
21
- this.loadedPlugins = new Map();
22
- this.serviceFactories = new Map();
23
- this.serviceInstances = new Map();
24
- this.scopedServices = new Map();
25
- this.creating = new Set();
26
- this.logger = logger;
27
- this.configValidator = new PluginConfigValidator(logger);
28
- }
29
- /**
30
- * Set the plugin context for service factories
31
- */
32
- setContext(context) {
33
- this.context = context;
34
- }
35
- /**
36
- * Get a synchronous service instance if it exists (Sync Helper)
37
- */
38
- getServiceInstance(name) {
39
- return this.serviceInstances.get(name);
40
- }
41
- /**
42
- * Load a plugin asynchronously with validation
43
- */
44
- async loadPlugin(plugin) {
45
- const startTime = Date.now();
46
- try {
47
- this.logger.info(`Loading plugin: ${plugin.name}`);
48
- // Convert to PluginMetadata
49
- const metadata = this.toPluginMetadata(plugin);
50
- // Validate plugin structure
51
- this.validatePluginStructure(metadata);
52
- // Check version compatibility
53
- const versionCheck = this.checkVersionCompatibility(metadata);
54
- if (!versionCheck.compatible) {
55
- throw new Error(`Version incompatible: ${versionCheck.message}`);
56
- }
57
- // Validate configuration if schema is provided
58
- if (metadata.configSchema) {
59
- this.validatePluginConfig(metadata);
60
- }
61
- // Verify signature if provided
62
- if (metadata.signature) {
63
- await this.verifyPluginSignature(metadata);
64
- }
65
- // Store loaded plugin
66
- this.loadedPlugins.set(metadata.name, metadata);
67
- const loadTime = Date.now() - startTime;
68
- this.logger.info(`Plugin loaded: ${plugin.name} (${loadTime}ms)`);
69
- return {
70
- success: true,
71
- plugin: metadata,
72
- loadTime,
73
- };
74
- }
75
- catch (error) {
76
- this.logger.error(`Failed to load plugin: ${plugin.name}`, error);
77
- return {
78
- success: false,
79
- error: error,
80
- loadTime: Date.now() - startTime,
81
- };
82
- }
83
- }
84
- /**
85
- * Register a service with factory function
86
- */
87
- registerServiceFactory(registration) {
88
- if (this.serviceFactories.has(registration.name)) {
89
- throw new Error(`Service factory '${registration.name}' already registered`);
90
- }
91
- this.serviceFactories.set(registration.name, registration);
92
- this.logger.debug(`Service factory registered: ${registration.name} (${registration.lifecycle})`);
93
- }
94
- /**
95
- * Get or create a service instance based on lifecycle type
96
- */
97
- async getService(name, scopeId) {
98
- const registration = this.serviceFactories.get(name);
99
- if (!registration) {
100
- // Fall back to static service instances
101
- const instance = this.serviceInstances.get(name);
102
- if (!instance) {
103
- throw new Error(`Service '${name}' not found`);
104
- }
105
- return instance;
106
- }
107
- switch (registration.lifecycle) {
108
- case ServiceLifecycle.SINGLETON:
109
- return await this.getSingletonService(registration);
110
- case ServiceLifecycle.TRANSIENT:
111
- return await this.createTransientService(registration);
112
- case ServiceLifecycle.SCOPED:
113
- if (!scopeId) {
114
- throw new Error(`Scope ID required for scoped service '${name}'`);
115
- }
116
- return await this.getScopedService(registration, scopeId);
117
- default:
118
- throw new Error(`Unknown service lifecycle: ${registration.lifecycle}`);
119
- }
120
- }
121
- /**
122
- * Register a static service instance (legacy support)
123
- */
124
- registerService(name, service) {
125
- if (this.serviceInstances.has(name)) {
126
- throw new Error(`Service '${name}' already registered`);
127
- }
128
- this.serviceInstances.set(name, service);
129
- }
130
- /**
131
- * Check if a service is registered (either as instance or factory)
132
- */
133
- hasService(name) {
134
- return this.serviceInstances.has(name) || this.serviceFactories.has(name);
135
- }
136
- /**
137
- * Detect circular dependencies in service factories
138
- * Note: This only detects cycles in service dependencies, not plugin dependencies.
139
- * Plugin dependency cycles are detected in the kernel's resolveDependencies method.
140
- */
141
- detectCircularDependencies() {
142
- const cycles = [];
143
- const visited = new Set();
144
- const visiting = new Set();
145
- const visit = (serviceName, path = []) => {
146
- if (visiting.has(serviceName)) {
147
- const cycle = [...path, serviceName].join(' -> ');
148
- cycles.push(cycle);
149
- return;
150
- }
151
- if (visited.has(serviceName)) {
152
- return;
153
- }
154
- visiting.add(serviceName);
155
- const registration = this.serviceFactories.get(serviceName);
156
- if (registration?.dependencies) {
157
- for (const dep of registration.dependencies) {
158
- visit(dep, [...path, serviceName]);
159
- }
160
- }
161
- visiting.delete(serviceName);
162
- visited.add(serviceName);
163
- };
164
- for (const serviceName of this.serviceFactories.keys()) {
165
- visit(serviceName);
166
- }
167
- return cycles;
168
- }
169
- /**
170
- * Check plugin health
171
- */
172
- async checkPluginHealth(pluginName) {
173
- const plugin = this.loadedPlugins.get(pluginName);
174
- if (!plugin) {
175
- return {
176
- healthy: false,
177
- message: 'Plugin not found',
178
- lastCheck: new Date(),
179
- };
180
- }
181
- if (!plugin.healthCheck) {
182
- return {
183
- healthy: true,
184
- message: 'No health check defined',
185
- lastCheck: new Date(),
186
- };
187
- }
188
- try {
189
- const status = await plugin.healthCheck();
190
- return {
191
- ...status,
192
- lastCheck: new Date(),
193
- };
194
- }
195
- catch (error) {
196
- return {
197
- healthy: false,
198
- message: `Health check failed: ${error.message}`,
199
- lastCheck: new Date(),
200
- };
201
- }
202
- }
203
- /**
204
- * Clear scoped services for a scope
205
- */
206
- clearScope(scopeId) {
207
- this.scopedServices.delete(scopeId);
208
- this.logger.debug(`Cleared scope: ${scopeId}`);
209
- }
210
- /**
211
- * Get all loaded plugins
212
- */
213
- getLoadedPlugins() {
214
- return new Map(this.loadedPlugins);
215
- }
216
- // Private helper methods
217
- toPluginMetadata(plugin) {
218
- return {
219
- ...plugin,
220
- version: plugin.version || '0.0.0',
221
- };
222
- }
223
- validatePluginStructure(plugin) {
224
- if (!plugin.name) {
225
- throw new Error('Plugin name is required');
226
- }
227
- if (!plugin.init) {
228
- throw new Error('Plugin init function is required');
229
- }
230
- if (!this.isValidSemanticVersion(plugin.version)) {
231
- throw new Error(`Invalid semantic version: ${plugin.version}`);
232
- }
233
- }
234
- checkVersionCompatibility(plugin) {
235
- // Basic semantic version compatibility check
236
- // In a real implementation, this would check against kernel version
237
- const version = plugin.version;
238
- if (!this.isValidSemanticVersion(version)) {
239
- return {
240
- compatible: false,
241
- pluginVersion: version,
242
- message: 'Invalid semantic version format',
243
- };
244
- }
245
- return {
246
- compatible: true,
247
- pluginVersion: version,
248
- };
249
- }
250
- isValidSemanticVersion(version) {
251
- const semverRegex = /^\d+\.\d+\.\d+(-[a-zA-Z0-9.-]+)?(\+[a-zA-Z0-9.-]+)?$/;
252
- return semverRegex.test(version);
253
- }
254
- validatePluginConfig(plugin, config) {
255
- if (!plugin.configSchema) {
256
- return;
257
- }
258
- if (config === undefined) {
259
- // In loadPlugin, we often don't have the config yet.
260
- // We skip validation here or valid against empty object if schema allows?
261
- // For now, let's keep the logging behavior but note it's delegating
262
- this.logger.debug(`Plugin ${plugin.name} has configuration schema (config validation postponed)`);
263
- return;
264
- }
265
- this.configValidator.validatePluginConfig(plugin, config);
266
- }
267
- async verifyPluginSignature(plugin) {
268
- if (!plugin.signature) {
269
- return;
270
- }
271
- // Plugin signature verification is now implemented in PluginSignatureVerifier
272
- // This is a placeholder that logs the verification would happen
273
- // The actual verification should be done by the caller with proper security config
274
- this.logger.debug(`Plugin ${plugin.name} has signature (use PluginSignatureVerifier for verification)`);
275
- }
276
- async getSingletonService(registration) {
277
- let instance = this.serviceInstances.get(registration.name);
278
- if (!instance) {
279
- // Create instance (would need context)
280
- instance = await this.createServiceInstance(registration);
281
- this.serviceInstances.set(registration.name, instance);
282
- this.logger.debug(`Singleton service created: ${registration.name}`);
283
- }
284
- return instance;
285
- }
286
- async createTransientService(registration) {
287
- const instance = await this.createServiceInstance(registration);
288
- this.logger.debug(`Transient service created: ${registration.name}`);
289
- return instance;
290
- }
291
- async getScopedService(registration, scopeId) {
292
- if (!this.scopedServices.has(scopeId)) {
293
- this.scopedServices.set(scopeId, new Map());
294
- }
295
- const scope = this.scopedServices.get(scopeId);
296
- let instance = scope.get(registration.name);
297
- if (!instance) {
298
- instance = await this.createServiceInstance(registration);
299
- scope.set(registration.name, instance);
300
- this.logger.debug(`Scoped service created: ${registration.name} (scope: ${scopeId})`);
301
- }
302
- return instance;
303
- }
304
- async createServiceInstance(registration) {
305
- if (!this.context) {
306
- throw new Error(`[PluginLoader] Context not set - cannot create service '${registration.name}'`);
307
- }
308
- if (this.creating.has(registration.name)) {
309
- throw new Error(`Circular dependency detected: ${Array.from(this.creating).join(' -> ')} -> ${registration.name}`);
310
- }
311
- this.creating.add(registration.name);
312
- try {
313
- return await registration.factory(this.context);
314
- }
315
- finally {
316
- this.creating.delete(registration.name);
317
- }
318
- }
319
- }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=plugin-loader.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"plugin-loader.test.d.ts","sourceRoot":"","sources":["../src/plugin-loader.test.ts"],"names":[],"mappings":""}