@objectstack/core 4.0.4 → 4.0.5
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/README.md +95 -10
- package/dist/index.cjs +169 -507
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +24 -223
- package/dist/index.d.ts +24 -223
- package/dist/index.js +175 -505
- package/dist/index.js.map +1 -1
- package/dist/logger.cjs +177 -0
- package/dist/logger.cjs.map +1 -0
- package/dist/logger.d.cts +26 -0
- package/dist/logger.d.ts +26 -0
- package/dist/logger.js +158 -0
- package/dist/logger.js.map +1 -0
- package/package.json +36 -15
- package/.turbo/turbo-build.log +0 -22
- package/ADVANCED_FEATURES.md +0 -380
- package/API_REGISTRY.md +0 -392
- package/CHANGELOG.md +0 -472
- package/PHASE2_IMPLEMENTATION.md +0 -388
- package/REFACTORING_SUMMARY.md +0 -40
- package/examples/api-registry-example.ts +0 -559
- package/examples/kernel-features-example.ts +0 -311
- package/examples/phase2-integration.ts +0 -357
- package/src/api-registry-plugin.test.ts +0 -393
- package/src/api-registry-plugin.ts +0 -89
- package/src/api-registry.test.ts +0 -1089
- package/src/api-registry.ts +0 -739
- package/src/contracts/data-engine.ts +0 -57
- package/src/contracts/http-server.ts +0 -151
- package/src/contracts/logger.ts +0 -72
- package/src/dependency-resolver.test.ts +0 -287
- package/src/dependency-resolver.ts +0 -390
- package/src/fallbacks/fallbacks.test.ts +0 -281
- package/src/fallbacks/index.ts +0 -26
- package/src/fallbacks/memory-cache.ts +0 -34
- package/src/fallbacks/memory-i18n.ts +0 -112
- package/src/fallbacks/memory-job.ts +0 -23
- package/src/fallbacks/memory-metadata.ts +0 -50
- package/src/fallbacks/memory-queue.ts +0 -28
- package/src/health-monitor.test.ts +0 -81
- package/src/health-monitor.ts +0 -318
- package/src/hot-reload.ts +0 -382
- package/src/index.ts +0 -50
- package/src/kernel-base.ts +0 -273
- package/src/kernel.test.ts +0 -624
- package/src/kernel.ts +0 -631
- package/src/lite-kernel.test.ts +0 -248
- package/src/lite-kernel.ts +0 -137
- package/src/logger.test.ts +0 -116
- package/src/logger.ts +0 -355
- package/src/namespace-resolver.test.ts +0 -130
- package/src/namespace-resolver.ts +0 -188
- package/src/package-manager.test.ts +0 -225
- package/src/package-manager.ts +0 -428
- package/src/plugin-loader.test.ts +0 -421
- package/src/plugin-loader.ts +0 -484
- package/src/qa/adapter.ts +0 -16
- package/src/qa/http-adapter.ts +0 -116
- package/src/qa/index.ts +0 -5
- package/src/qa/runner.ts +0 -189
- package/src/security/index.ts +0 -50
- package/src/security/permission-manager.test.ts +0 -256
- package/src/security/permission-manager.ts +0 -338
- package/src/security/plugin-config-validator.test.ts +0 -276
- package/src/security/plugin-config-validator.ts +0 -193
- package/src/security/plugin-permission-enforcer.test.ts +0 -251
- package/src/security/plugin-permission-enforcer.ts +0 -436
- package/src/security/plugin-signature-verifier.ts +0 -403
- package/src/security/sandbox-runtime.ts +0 -462
- package/src/security/security-scanner.ts +0 -367
- package/src/types.ts +0 -120
- package/src/utils/env.test.ts +0 -62
- package/src/utils/env.ts +0 -53
- package/tsconfig.json +0 -10
- package/vitest.config.ts +0 -10
package/dist/index.d.cts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { LoggerConfig } from '@objectstack/spec/system';
|
|
2
1
|
import { Logger, IServiceRegistry } from '@objectstack/spec/contracts';
|
|
3
2
|
export { DriverInterface, IDataDriver, IDataEngine, IHttpRequest, IHttpResponse, IHttpServer, Logger, Middleware, RouteHandler } from '@objectstack/spec/contracts';
|
|
4
3
|
import { z } from 'zod';
|
|
4
|
+
import { LoggerConfig } from '@objectstack/spec/system';
|
|
5
|
+
import { ObjectLogger } from './logger.cjs';
|
|
6
|
+
export { createLogger } from './logger.cjs';
|
|
5
7
|
import { ConflictResolutionStrategy, ApiRegistryEntryInput, ApiRegistryEntry, ApiDiscoveryQuery, ApiDiscoveryResponse, ApiEndpointRegistration, ApiRegistry as ApiRegistry$1 } from '@objectstack/spec/api';
|
|
6
|
-
import
|
|
8
|
+
import * as QA from '@objectstack/spec/qa';
|
|
7
9
|
import { PluginCapability, PermissionSet, ResourceType, PermissionAction, Permission, SandboxConfig, KernelSecurityScanResult, KernelSecurityVulnerability, PluginHealthCheck, PluginHealthStatus as PluginHealthStatus$1, PluginHealthReport, HotReloadConfig, VersionConstraint, DependencyConflict, SemanticVersion, CompatibilityLevel } from '@objectstack/spec/kernel';
|
|
8
10
|
|
|
9
11
|
/**
|
|
@@ -22,7 +24,7 @@ declare enum ServiceLifecycle {
|
|
|
22
24
|
* Service Factory
|
|
23
25
|
* Function that creates a service instance
|
|
24
26
|
*/
|
|
25
|
-
type ServiceFactory<T = any> = (ctx: PluginContext) => T | Promise<T>;
|
|
27
|
+
type ServiceFactory<T = any> = (ctx: PluginContext, scopeId?: string) => T | Promise<T>;
|
|
26
28
|
/**
|
|
27
29
|
* Service Registration Options
|
|
28
30
|
*/
|
|
@@ -261,6 +263,11 @@ declare class ObjectKernel {
|
|
|
261
263
|
* Get a service asynchronously (supports factories)
|
|
262
264
|
*/
|
|
263
265
|
getServiceAsync<T>(name: string, scopeId?: string): Promise<T>;
|
|
266
|
+
/**
|
|
267
|
+
* Clear all scoped service instances for a given scope (e.g., projectId).
|
|
268
|
+
* Releases driver connections and metadata caches for idle projects.
|
|
269
|
+
*/
|
|
270
|
+
clearScope(scopeId: string): void;
|
|
264
271
|
/**
|
|
265
272
|
* Check if kernel is running
|
|
266
273
|
*/
|
|
@@ -297,6 +304,12 @@ interface PluginContext {
|
|
|
297
304
|
* @param service - Service instance
|
|
298
305
|
*/
|
|
299
306
|
registerService(name: string, service: any): void;
|
|
307
|
+
/**
|
|
308
|
+
* Register a service factory with lifecycle management.
|
|
309
|
+
* Use `ServiceLifecycle.SCOPED` for per-project services — the factory
|
|
310
|
+
* receives `(ctx, scopeId)` where `scopeId` is the project ID.
|
|
311
|
+
*/
|
|
312
|
+
registerServiceFactory(name: string, factory: (ctx: PluginContext, scopeId?: string) => any, lifecycle?: ServiceLifecycle, dependencies?: string[]): void;
|
|
300
313
|
/**
|
|
301
314
|
* Get a service registered by another plugin
|
|
302
315
|
* @param name - Service name
|
|
@@ -314,6 +327,11 @@ interface PluginContext {
|
|
|
314
327
|
* @throws Error if the service does not exist
|
|
315
328
|
*/
|
|
316
329
|
replaceService<T>(name: string, implementation: T): void;
|
|
330
|
+
/**
|
|
331
|
+
* Get a scoped service instance for a given scope (e.g., projectId).
|
|
332
|
+
* Creates the instance on first access; reuses on subsequent calls within the same scope.
|
|
333
|
+
*/
|
|
334
|
+
getServiceScoped<T>(name: string, scopeId: string): Promise<T>;
|
|
317
335
|
/**
|
|
318
336
|
* Get all registered services
|
|
319
337
|
*/
|
|
@@ -516,75 +534,6 @@ declare class LiteKernel extends ObjectKernelBase {
|
|
|
516
534
|
isRunning(): boolean;
|
|
517
535
|
}
|
|
518
536
|
|
|
519
|
-
/**
|
|
520
|
-
* Universal Logger Implementation
|
|
521
|
-
*
|
|
522
|
-
* A configurable logger that works in both browser and Node.js environments.
|
|
523
|
-
* - Node.js: Uses Pino for high-performance structured logging
|
|
524
|
-
* - Browser: Simple console-based implementation
|
|
525
|
-
*
|
|
526
|
-
* Features:
|
|
527
|
-
* - Structured logging with multiple formats (json, text, pretty)
|
|
528
|
-
* - Log level filtering
|
|
529
|
-
* - Sensitive data redaction
|
|
530
|
-
* - File logging with rotation (Node.js only via Pino)
|
|
531
|
-
* - Browser console integration
|
|
532
|
-
* - Distributed tracing support (traceId, spanId)
|
|
533
|
-
*/
|
|
534
|
-
declare class ObjectLogger implements Logger {
|
|
535
|
-
private config;
|
|
536
|
-
private isNode;
|
|
537
|
-
private pinoLogger?;
|
|
538
|
-
private pinoInstance?;
|
|
539
|
-
private require?;
|
|
540
|
-
constructor(config?: Partial<LoggerConfig>);
|
|
541
|
-
/**
|
|
542
|
-
* Initialize Pino logger for Node.js
|
|
543
|
-
*/
|
|
544
|
-
private initPinoLogger;
|
|
545
|
-
/**
|
|
546
|
-
* Redact sensitive keys from context object (for browser)
|
|
547
|
-
*/
|
|
548
|
-
private redactSensitive;
|
|
549
|
-
/**
|
|
550
|
-
* Format log entry for browser
|
|
551
|
-
*/
|
|
552
|
-
private formatBrowserLog;
|
|
553
|
-
/**
|
|
554
|
-
* Log using browser console
|
|
555
|
-
*/
|
|
556
|
-
private logBrowser;
|
|
557
|
-
/**
|
|
558
|
-
* Public logging methods
|
|
559
|
-
*/
|
|
560
|
-
debug(message: string, meta?: Record<string, any>): void;
|
|
561
|
-
info(message: string, meta?: Record<string, any>): void;
|
|
562
|
-
warn(message: string, meta?: Record<string, any>): void;
|
|
563
|
-
error(message: string, errorOrMeta?: Error | Record<string, any>, meta?: Record<string, any>): void;
|
|
564
|
-
fatal(message: string, errorOrMeta?: Error | Record<string, any>, meta?: Record<string, any>): void;
|
|
565
|
-
/**
|
|
566
|
-
* Create a child logger with additional context
|
|
567
|
-
* Note: Child loggers share the parent's Pino instance
|
|
568
|
-
*/
|
|
569
|
-
child(context: Record<string, any>): ObjectLogger;
|
|
570
|
-
/**
|
|
571
|
-
* Set trace context for distributed tracing
|
|
572
|
-
*/
|
|
573
|
-
withTrace(traceId: string, spanId?: string): ObjectLogger;
|
|
574
|
-
/**
|
|
575
|
-
* Cleanup resources
|
|
576
|
-
*/
|
|
577
|
-
destroy(): Promise<void>;
|
|
578
|
-
/**
|
|
579
|
-
* Compatibility method for console.log usage
|
|
580
|
-
*/
|
|
581
|
-
log(message: string, ...args: any[]): void;
|
|
582
|
-
}
|
|
583
|
-
/**
|
|
584
|
-
* Create a logger instance
|
|
585
|
-
*/
|
|
586
|
-
declare function createLogger(config?: Partial<LoggerConfig>): ObjectLogger;
|
|
587
|
-
|
|
588
537
|
/**
|
|
589
538
|
* API Registry Service
|
|
590
539
|
*
|
|
@@ -1272,6 +1221,8 @@ declare class SecurePluginContext implements PluginContext {
|
|
|
1272
1221
|
trigger(name: string, ...args: any[]): Promise<void>;
|
|
1273
1222
|
get logger(): Logger;
|
|
1274
1223
|
getKernel(): ObjectKernel;
|
|
1224
|
+
registerServiceFactory(name: string, factory: (ctx: PluginContext, scopeId?: string) => any, lifecycle?: ServiceLifecycle, dependencies?: string[]): void;
|
|
1225
|
+
getServiceScoped<T>(name: string, scopeId: string): Promise<T>;
|
|
1275
1226
|
}
|
|
1276
1227
|
/**
|
|
1277
1228
|
* Create a plugin permission enforcer
|
|
@@ -1990,154 +1941,4 @@ declare class NamespaceResolver {
|
|
|
1990
1941
|
private suggestAlternative;
|
|
1991
1942
|
}
|
|
1992
1943
|
|
|
1993
|
-
|
|
1994
|
-
* Installed package record in the runtime registry.
|
|
1995
|
-
*/
|
|
1996
|
-
interface InstalledPackageRecord {
|
|
1997
|
-
/** Package identifier */
|
|
1998
|
-
packageId: string;
|
|
1999
|
-
/** Package version */
|
|
2000
|
-
version: string;
|
|
2001
|
-
/** Package manifest */
|
|
2002
|
-
manifest: Record<string, unknown>;
|
|
2003
|
-
/** Installation timestamp */
|
|
2004
|
-
installedAt: string;
|
|
2005
|
-
/** Current status */
|
|
2006
|
-
status: 'installed' | 'disabled' | 'installing' | 'upgrading' | 'uninstalling' | 'error';
|
|
2007
|
-
/** Namespaces registered by this package */
|
|
2008
|
-
namespaces: string[];
|
|
2009
|
-
/** Dependencies of this package */
|
|
2010
|
-
dependencies: string[];
|
|
2011
|
-
}
|
|
2012
|
-
/**
|
|
2013
|
-
* Snapshot of a package's state before upgrade (for rollback).
|
|
2014
|
-
*/
|
|
2015
|
-
interface PackageSnapshot {
|
|
2016
|
-
/** Package identifier */
|
|
2017
|
-
packageId: string;
|
|
2018
|
-
/** Version before upgrade */
|
|
2019
|
-
previousVersion: string;
|
|
2020
|
-
/** Full manifest before upgrade */
|
|
2021
|
-
previousManifest: Record<string, unknown>;
|
|
2022
|
-
/** Namespaces before upgrade */
|
|
2023
|
-
previousNamespaces: string[];
|
|
2024
|
-
/** Original installation timestamp */
|
|
2025
|
-
installedAt: string;
|
|
2026
|
-
/** Snapshot timestamp */
|
|
2027
|
-
createdAt: string;
|
|
2028
|
-
}
|
|
2029
|
-
/**
|
|
2030
|
-
* Result of a package installation attempt.
|
|
2031
|
-
*/
|
|
2032
|
-
interface InstallResult {
|
|
2033
|
-
success: boolean;
|
|
2034
|
-
packageId: string;
|
|
2035
|
-
version: string;
|
|
2036
|
-
installedDependencies: string[];
|
|
2037
|
-
namespaceConflicts: Array<{
|
|
2038
|
-
namespace: string;
|
|
2039
|
-
existingPackageId: string;
|
|
2040
|
-
}>;
|
|
2041
|
-
errorMessage?: string;
|
|
2042
|
-
}
|
|
2043
|
-
/**
|
|
2044
|
-
* Result of an upgrade attempt.
|
|
2045
|
-
*/
|
|
2046
|
-
interface UpgradeResult {
|
|
2047
|
-
success: boolean;
|
|
2048
|
-
packageId: string;
|
|
2049
|
-
fromVersion: string;
|
|
2050
|
-
toVersion: string;
|
|
2051
|
-
snapshot: PackageSnapshot;
|
|
2052
|
-
errorMessage?: string;
|
|
2053
|
-
}
|
|
2054
|
-
/**
|
|
2055
|
-
* Result of a rollback attempt.
|
|
2056
|
-
*/
|
|
2057
|
-
interface RollbackResult {
|
|
2058
|
-
success: boolean;
|
|
2059
|
-
packageId: string;
|
|
2060
|
-
restoredVersion: string;
|
|
2061
|
-
errorMessage?: string;
|
|
2062
|
-
}
|
|
2063
|
-
/**
|
|
2064
|
-
* Package Manager
|
|
2065
|
-
*
|
|
2066
|
-
* Runtime implementation for the full package lifecycle:
|
|
2067
|
-
* install → upgrade → rollback → uninstall.
|
|
2068
|
-
*
|
|
2069
|
-
* Consumes the protocol schemas defined in @objectstack/spec:
|
|
2070
|
-
* - DependencyResolutionResultSchema
|
|
2071
|
-
* - NamespaceConflictErrorSchema
|
|
2072
|
-
* - UpgradePlanSchema / UpgradeSnapshotSchema
|
|
2073
|
-
* - PackageArtifactSchema
|
|
2074
|
-
*
|
|
2075
|
-
* Coordinates with:
|
|
2076
|
-
* - DependencyResolver for topological ordering and conflict detection
|
|
2077
|
-
* - NamespaceResolver for metadata collision prevention
|
|
2078
|
-
*/
|
|
2079
|
-
declare class PackageManager {
|
|
2080
|
-
private logger;
|
|
2081
|
-
private packages;
|
|
2082
|
-
private snapshots;
|
|
2083
|
-
private dependencyResolver;
|
|
2084
|
-
private namespaceResolver;
|
|
2085
|
-
private platformVersion;
|
|
2086
|
-
constructor(logger: ObjectLogger, options?: {
|
|
2087
|
-
platformVersion?: string;
|
|
2088
|
-
});
|
|
2089
|
-
/**
|
|
2090
|
-
* Install a package with full dependency resolution and namespace checking.
|
|
2091
|
-
*/
|
|
2092
|
-
install(packageId: string, version: string, manifest: Record<string, unknown>): Promise<InstallResult>;
|
|
2093
|
-
/**
|
|
2094
|
-
* Uninstall a package, checking for dependents first.
|
|
2095
|
-
*/
|
|
2096
|
-
uninstall(packageId: string): Promise<{
|
|
2097
|
-
success: boolean;
|
|
2098
|
-
errorMessage?: string;
|
|
2099
|
-
}>;
|
|
2100
|
-
/**
|
|
2101
|
-
* Upgrade a package: snapshot → update → register.
|
|
2102
|
-
*/
|
|
2103
|
-
upgrade(packageId: string, newVersion: string, newManifest: Record<string, unknown>): Promise<UpgradeResult>;
|
|
2104
|
-
/**
|
|
2105
|
-
* Rollback a package to its pre-upgrade snapshot.
|
|
2106
|
-
*/
|
|
2107
|
-
rollback(packageId: string): Promise<RollbackResult>;
|
|
2108
|
-
/**
|
|
2109
|
-
* Get an installed package record.
|
|
2110
|
-
*/
|
|
2111
|
-
getPackage(packageId: string): InstalledPackageRecord | undefined;
|
|
2112
|
-
/**
|
|
2113
|
-
* List all installed packages.
|
|
2114
|
-
*/
|
|
2115
|
-
listPackages(): InstalledPackageRecord[];
|
|
2116
|
-
/**
|
|
2117
|
-
* Resolve dependencies for a set of packages.
|
|
2118
|
-
*/
|
|
2119
|
-
resolveDependencies(packages: Map<string, {
|
|
2120
|
-
version?: string;
|
|
2121
|
-
dependencies?: string[];
|
|
2122
|
-
}>): string[];
|
|
2123
|
-
/**
|
|
2124
|
-
* Check namespace availability for a package's metadata.
|
|
2125
|
-
*/
|
|
2126
|
-
checkNamespaces(packageId: string, config: Record<string, unknown>): {
|
|
2127
|
-
available: boolean;
|
|
2128
|
-
conflicts: Array<{
|
|
2129
|
-
namespace: string;
|
|
2130
|
-
existingPackageId: string;
|
|
2131
|
-
}>;
|
|
2132
|
-
};
|
|
2133
|
-
/**
|
|
2134
|
-
* Get the namespace resolver instance.
|
|
2135
|
-
*/
|
|
2136
|
-
getNamespaceResolver(): NamespaceResolver;
|
|
2137
|
-
/**
|
|
2138
|
-
* Get a snapshot for a given package (if available).
|
|
2139
|
-
*/
|
|
2140
|
-
getSnapshot(packageId: string): PackageSnapshot | undefined;
|
|
2141
|
-
}
|
|
2142
|
-
|
|
2143
|
-
export { ApiRegistry, type ApiRegistryPluginConfig, CORE_FALLBACK_FACTORIES, DependencyResolver, HotReloadManager, type InstallResult, type InstalledPackageRecord, type KernelState, LiteKernel, type NamespaceCheckResult, type NamespaceConflict, type NamespaceEntry, NamespaceResolver, ObjectKernel, ObjectKernelBase, type ObjectKernelConfig, ObjectLogger, PackageManager, type PackageSnapshot, type PermissionCheckResult$1 as PermissionCheckResult, type PermissionGrant, type Plugin, PluginConfigValidator, type PluginContext, PluginHealthMonitor, type PluginHealthStatus, type PluginLoadResult, PluginLoader, type PluginMetadata, type PermissionCheckResult as PluginPermissionCheckResult, PluginPermissionEnforcer, PluginPermissionManager, type PluginPermissions, PluginSandboxRuntime, PluginSecurityScanner, type PluginSignatureConfig, PluginSignatureVerifier, type PluginStartupResult, index as QA, type ResourceUsage, type RollbackResult, type SandboxContext, type ScanTarget, SecurePluginContext, type SecurityIssue, SemanticVersionManager, type ServiceFactory, ServiceLifecycle, type ServiceRegistration, type SignatureVerificationResult, type UpgradeResult, type VersionCompatibility, createApiRegistryPlugin, createLogger, createMemoryCache, createMemoryI18n, createMemoryJob, createMemoryMetadata, createMemoryQueue, createPluginConfigValidator, createPluginPermissionEnforcer, getEnv, getMemoryUsage, isNode, resolveLocale, safeExit };
|
|
1944
|
+
export { ApiRegistry, type ApiRegistryPluginConfig, CORE_FALLBACK_FACTORIES, DependencyResolver, HotReloadManager, type KernelState, LiteKernel, type NamespaceCheckResult, type NamespaceConflict, type NamespaceEntry, NamespaceResolver, ObjectKernel, ObjectKernelBase, type ObjectKernelConfig, ObjectLogger, type PermissionCheckResult$1 as PermissionCheckResult, type PermissionGrant, type Plugin, PluginConfigValidator, type PluginContext, PluginHealthMonitor, type PluginHealthStatus, type PluginLoadResult, PluginLoader, type PluginMetadata, type PermissionCheckResult as PluginPermissionCheckResult, PluginPermissionEnforcer, PluginPermissionManager, type PluginPermissions, PluginSandboxRuntime, PluginSecurityScanner, type PluginSignatureConfig, PluginSignatureVerifier, type PluginStartupResult, index as QA, type ResourceUsage, type SandboxContext, type ScanTarget, SecurePluginContext, type SecurityIssue, SemanticVersionManager, type ServiceFactory, ServiceLifecycle, type ServiceRegistration, type SignatureVerificationResult, type VersionCompatibility, createApiRegistryPlugin, createMemoryCache, createMemoryI18n, createMemoryJob, createMemoryMetadata, createMemoryQueue, createPluginConfigValidator, createPluginPermissionEnforcer, getEnv, getMemoryUsage, isNode, resolveLocale, safeExit };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { LoggerConfig } from '@objectstack/spec/system';
|
|
2
1
|
import { Logger, IServiceRegistry } from '@objectstack/spec/contracts';
|
|
3
2
|
export { DriverInterface, IDataDriver, IDataEngine, IHttpRequest, IHttpResponse, IHttpServer, Logger, Middleware, RouteHandler } from '@objectstack/spec/contracts';
|
|
4
3
|
import { z } from 'zod';
|
|
4
|
+
import { LoggerConfig } from '@objectstack/spec/system';
|
|
5
|
+
import { ObjectLogger } from './logger.js';
|
|
6
|
+
export { createLogger } from './logger.js';
|
|
5
7
|
import { ConflictResolutionStrategy, ApiRegistryEntryInput, ApiRegistryEntry, ApiDiscoveryQuery, ApiDiscoveryResponse, ApiEndpointRegistration, ApiRegistry as ApiRegistry$1 } from '@objectstack/spec/api';
|
|
6
|
-
import
|
|
8
|
+
import * as QA from '@objectstack/spec/qa';
|
|
7
9
|
import { PluginCapability, PermissionSet, ResourceType, PermissionAction, Permission, SandboxConfig, KernelSecurityScanResult, KernelSecurityVulnerability, PluginHealthCheck, PluginHealthStatus as PluginHealthStatus$1, PluginHealthReport, HotReloadConfig, VersionConstraint, DependencyConflict, SemanticVersion, CompatibilityLevel } from '@objectstack/spec/kernel';
|
|
8
10
|
|
|
9
11
|
/**
|
|
@@ -22,7 +24,7 @@ declare enum ServiceLifecycle {
|
|
|
22
24
|
* Service Factory
|
|
23
25
|
* Function that creates a service instance
|
|
24
26
|
*/
|
|
25
|
-
type ServiceFactory<T = any> = (ctx: PluginContext) => T | Promise<T>;
|
|
27
|
+
type ServiceFactory<T = any> = (ctx: PluginContext, scopeId?: string) => T | Promise<T>;
|
|
26
28
|
/**
|
|
27
29
|
* Service Registration Options
|
|
28
30
|
*/
|
|
@@ -261,6 +263,11 @@ declare class ObjectKernel {
|
|
|
261
263
|
* Get a service asynchronously (supports factories)
|
|
262
264
|
*/
|
|
263
265
|
getServiceAsync<T>(name: string, scopeId?: string): Promise<T>;
|
|
266
|
+
/**
|
|
267
|
+
* Clear all scoped service instances for a given scope (e.g., projectId).
|
|
268
|
+
* Releases driver connections and metadata caches for idle projects.
|
|
269
|
+
*/
|
|
270
|
+
clearScope(scopeId: string): void;
|
|
264
271
|
/**
|
|
265
272
|
* Check if kernel is running
|
|
266
273
|
*/
|
|
@@ -297,6 +304,12 @@ interface PluginContext {
|
|
|
297
304
|
* @param service - Service instance
|
|
298
305
|
*/
|
|
299
306
|
registerService(name: string, service: any): void;
|
|
307
|
+
/**
|
|
308
|
+
* Register a service factory with lifecycle management.
|
|
309
|
+
* Use `ServiceLifecycle.SCOPED` for per-project services — the factory
|
|
310
|
+
* receives `(ctx, scopeId)` where `scopeId` is the project ID.
|
|
311
|
+
*/
|
|
312
|
+
registerServiceFactory(name: string, factory: (ctx: PluginContext, scopeId?: string) => any, lifecycle?: ServiceLifecycle, dependencies?: string[]): void;
|
|
300
313
|
/**
|
|
301
314
|
* Get a service registered by another plugin
|
|
302
315
|
* @param name - Service name
|
|
@@ -314,6 +327,11 @@ interface PluginContext {
|
|
|
314
327
|
* @throws Error if the service does not exist
|
|
315
328
|
*/
|
|
316
329
|
replaceService<T>(name: string, implementation: T): void;
|
|
330
|
+
/**
|
|
331
|
+
* Get a scoped service instance for a given scope (e.g., projectId).
|
|
332
|
+
* Creates the instance on first access; reuses on subsequent calls within the same scope.
|
|
333
|
+
*/
|
|
334
|
+
getServiceScoped<T>(name: string, scopeId: string): Promise<T>;
|
|
317
335
|
/**
|
|
318
336
|
* Get all registered services
|
|
319
337
|
*/
|
|
@@ -516,75 +534,6 @@ declare class LiteKernel extends ObjectKernelBase {
|
|
|
516
534
|
isRunning(): boolean;
|
|
517
535
|
}
|
|
518
536
|
|
|
519
|
-
/**
|
|
520
|
-
* Universal Logger Implementation
|
|
521
|
-
*
|
|
522
|
-
* A configurable logger that works in both browser and Node.js environments.
|
|
523
|
-
* - Node.js: Uses Pino for high-performance structured logging
|
|
524
|
-
* - Browser: Simple console-based implementation
|
|
525
|
-
*
|
|
526
|
-
* Features:
|
|
527
|
-
* - Structured logging with multiple formats (json, text, pretty)
|
|
528
|
-
* - Log level filtering
|
|
529
|
-
* - Sensitive data redaction
|
|
530
|
-
* - File logging with rotation (Node.js only via Pino)
|
|
531
|
-
* - Browser console integration
|
|
532
|
-
* - Distributed tracing support (traceId, spanId)
|
|
533
|
-
*/
|
|
534
|
-
declare class ObjectLogger implements Logger {
|
|
535
|
-
private config;
|
|
536
|
-
private isNode;
|
|
537
|
-
private pinoLogger?;
|
|
538
|
-
private pinoInstance?;
|
|
539
|
-
private require?;
|
|
540
|
-
constructor(config?: Partial<LoggerConfig>);
|
|
541
|
-
/**
|
|
542
|
-
* Initialize Pino logger for Node.js
|
|
543
|
-
*/
|
|
544
|
-
private initPinoLogger;
|
|
545
|
-
/**
|
|
546
|
-
* Redact sensitive keys from context object (for browser)
|
|
547
|
-
*/
|
|
548
|
-
private redactSensitive;
|
|
549
|
-
/**
|
|
550
|
-
* Format log entry for browser
|
|
551
|
-
*/
|
|
552
|
-
private formatBrowserLog;
|
|
553
|
-
/**
|
|
554
|
-
* Log using browser console
|
|
555
|
-
*/
|
|
556
|
-
private logBrowser;
|
|
557
|
-
/**
|
|
558
|
-
* Public logging methods
|
|
559
|
-
*/
|
|
560
|
-
debug(message: string, meta?: Record<string, any>): void;
|
|
561
|
-
info(message: string, meta?: Record<string, any>): void;
|
|
562
|
-
warn(message: string, meta?: Record<string, any>): void;
|
|
563
|
-
error(message: string, errorOrMeta?: Error | Record<string, any>, meta?: Record<string, any>): void;
|
|
564
|
-
fatal(message: string, errorOrMeta?: Error | Record<string, any>, meta?: Record<string, any>): void;
|
|
565
|
-
/**
|
|
566
|
-
* Create a child logger with additional context
|
|
567
|
-
* Note: Child loggers share the parent's Pino instance
|
|
568
|
-
*/
|
|
569
|
-
child(context: Record<string, any>): ObjectLogger;
|
|
570
|
-
/**
|
|
571
|
-
* Set trace context for distributed tracing
|
|
572
|
-
*/
|
|
573
|
-
withTrace(traceId: string, spanId?: string): ObjectLogger;
|
|
574
|
-
/**
|
|
575
|
-
* Cleanup resources
|
|
576
|
-
*/
|
|
577
|
-
destroy(): Promise<void>;
|
|
578
|
-
/**
|
|
579
|
-
* Compatibility method for console.log usage
|
|
580
|
-
*/
|
|
581
|
-
log(message: string, ...args: any[]): void;
|
|
582
|
-
}
|
|
583
|
-
/**
|
|
584
|
-
* Create a logger instance
|
|
585
|
-
*/
|
|
586
|
-
declare function createLogger(config?: Partial<LoggerConfig>): ObjectLogger;
|
|
587
|
-
|
|
588
537
|
/**
|
|
589
538
|
* API Registry Service
|
|
590
539
|
*
|
|
@@ -1272,6 +1221,8 @@ declare class SecurePluginContext implements PluginContext {
|
|
|
1272
1221
|
trigger(name: string, ...args: any[]): Promise<void>;
|
|
1273
1222
|
get logger(): Logger;
|
|
1274
1223
|
getKernel(): ObjectKernel;
|
|
1224
|
+
registerServiceFactory(name: string, factory: (ctx: PluginContext, scopeId?: string) => any, lifecycle?: ServiceLifecycle, dependencies?: string[]): void;
|
|
1225
|
+
getServiceScoped<T>(name: string, scopeId: string): Promise<T>;
|
|
1275
1226
|
}
|
|
1276
1227
|
/**
|
|
1277
1228
|
* Create a plugin permission enforcer
|
|
@@ -1990,154 +1941,4 @@ declare class NamespaceResolver {
|
|
|
1990
1941
|
private suggestAlternative;
|
|
1991
1942
|
}
|
|
1992
1943
|
|
|
1993
|
-
|
|
1994
|
-
* Installed package record in the runtime registry.
|
|
1995
|
-
*/
|
|
1996
|
-
interface InstalledPackageRecord {
|
|
1997
|
-
/** Package identifier */
|
|
1998
|
-
packageId: string;
|
|
1999
|
-
/** Package version */
|
|
2000
|
-
version: string;
|
|
2001
|
-
/** Package manifest */
|
|
2002
|
-
manifest: Record<string, unknown>;
|
|
2003
|
-
/** Installation timestamp */
|
|
2004
|
-
installedAt: string;
|
|
2005
|
-
/** Current status */
|
|
2006
|
-
status: 'installed' | 'disabled' | 'installing' | 'upgrading' | 'uninstalling' | 'error';
|
|
2007
|
-
/** Namespaces registered by this package */
|
|
2008
|
-
namespaces: string[];
|
|
2009
|
-
/** Dependencies of this package */
|
|
2010
|
-
dependencies: string[];
|
|
2011
|
-
}
|
|
2012
|
-
/**
|
|
2013
|
-
* Snapshot of a package's state before upgrade (for rollback).
|
|
2014
|
-
*/
|
|
2015
|
-
interface PackageSnapshot {
|
|
2016
|
-
/** Package identifier */
|
|
2017
|
-
packageId: string;
|
|
2018
|
-
/** Version before upgrade */
|
|
2019
|
-
previousVersion: string;
|
|
2020
|
-
/** Full manifest before upgrade */
|
|
2021
|
-
previousManifest: Record<string, unknown>;
|
|
2022
|
-
/** Namespaces before upgrade */
|
|
2023
|
-
previousNamespaces: string[];
|
|
2024
|
-
/** Original installation timestamp */
|
|
2025
|
-
installedAt: string;
|
|
2026
|
-
/** Snapshot timestamp */
|
|
2027
|
-
createdAt: string;
|
|
2028
|
-
}
|
|
2029
|
-
/**
|
|
2030
|
-
* Result of a package installation attempt.
|
|
2031
|
-
*/
|
|
2032
|
-
interface InstallResult {
|
|
2033
|
-
success: boolean;
|
|
2034
|
-
packageId: string;
|
|
2035
|
-
version: string;
|
|
2036
|
-
installedDependencies: string[];
|
|
2037
|
-
namespaceConflicts: Array<{
|
|
2038
|
-
namespace: string;
|
|
2039
|
-
existingPackageId: string;
|
|
2040
|
-
}>;
|
|
2041
|
-
errorMessage?: string;
|
|
2042
|
-
}
|
|
2043
|
-
/**
|
|
2044
|
-
* Result of an upgrade attempt.
|
|
2045
|
-
*/
|
|
2046
|
-
interface UpgradeResult {
|
|
2047
|
-
success: boolean;
|
|
2048
|
-
packageId: string;
|
|
2049
|
-
fromVersion: string;
|
|
2050
|
-
toVersion: string;
|
|
2051
|
-
snapshot: PackageSnapshot;
|
|
2052
|
-
errorMessage?: string;
|
|
2053
|
-
}
|
|
2054
|
-
/**
|
|
2055
|
-
* Result of a rollback attempt.
|
|
2056
|
-
*/
|
|
2057
|
-
interface RollbackResult {
|
|
2058
|
-
success: boolean;
|
|
2059
|
-
packageId: string;
|
|
2060
|
-
restoredVersion: string;
|
|
2061
|
-
errorMessage?: string;
|
|
2062
|
-
}
|
|
2063
|
-
/**
|
|
2064
|
-
* Package Manager
|
|
2065
|
-
*
|
|
2066
|
-
* Runtime implementation for the full package lifecycle:
|
|
2067
|
-
* install → upgrade → rollback → uninstall.
|
|
2068
|
-
*
|
|
2069
|
-
* Consumes the protocol schemas defined in @objectstack/spec:
|
|
2070
|
-
* - DependencyResolutionResultSchema
|
|
2071
|
-
* - NamespaceConflictErrorSchema
|
|
2072
|
-
* - UpgradePlanSchema / UpgradeSnapshotSchema
|
|
2073
|
-
* - PackageArtifactSchema
|
|
2074
|
-
*
|
|
2075
|
-
* Coordinates with:
|
|
2076
|
-
* - DependencyResolver for topological ordering and conflict detection
|
|
2077
|
-
* - NamespaceResolver for metadata collision prevention
|
|
2078
|
-
*/
|
|
2079
|
-
declare class PackageManager {
|
|
2080
|
-
private logger;
|
|
2081
|
-
private packages;
|
|
2082
|
-
private snapshots;
|
|
2083
|
-
private dependencyResolver;
|
|
2084
|
-
private namespaceResolver;
|
|
2085
|
-
private platformVersion;
|
|
2086
|
-
constructor(logger: ObjectLogger, options?: {
|
|
2087
|
-
platformVersion?: string;
|
|
2088
|
-
});
|
|
2089
|
-
/**
|
|
2090
|
-
* Install a package with full dependency resolution and namespace checking.
|
|
2091
|
-
*/
|
|
2092
|
-
install(packageId: string, version: string, manifest: Record<string, unknown>): Promise<InstallResult>;
|
|
2093
|
-
/**
|
|
2094
|
-
* Uninstall a package, checking for dependents first.
|
|
2095
|
-
*/
|
|
2096
|
-
uninstall(packageId: string): Promise<{
|
|
2097
|
-
success: boolean;
|
|
2098
|
-
errorMessage?: string;
|
|
2099
|
-
}>;
|
|
2100
|
-
/**
|
|
2101
|
-
* Upgrade a package: snapshot → update → register.
|
|
2102
|
-
*/
|
|
2103
|
-
upgrade(packageId: string, newVersion: string, newManifest: Record<string, unknown>): Promise<UpgradeResult>;
|
|
2104
|
-
/**
|
|
2105
|
-
* Rollback a package to its pre-upgrade snapshot.
|
|
2106
|
-
*/
|
|
2107
|
-
rollback(packageId: string): Promise<RollbackResult>;
|
|
2108
|
-
/**
|
|
2109
|
-
* Get an installed package record.
|
|
2110
|
-
*/
|
|
2111
|
-
getPackage(packageId: string): InstalledPackageRecord | undefined;
|
|
2112
|
-
/**
|
|
2113
|
-
* List all installed packages.
|
|
2114
|
-
*/
|
|
2115
|
-
listPackages(): InstalledPackageRecord[];
|
|
2116
|
-
/**
|
|
2117
|
-
* Resolve dependencies for a set of packages.
|
|
2118
|
-
*/
|
|
2119
|
-
resolveDependencies(packages: Map<string, {
|
|
2120
|
-
version?: string;
|
|
2121
|
-
dependencies?: string[];
|
|
2122
|
-
}>): string[];
|
|
2123
|
-
/**
|
|
2124
|
-
* Check namespace availability for a package's metadata.
|
|
2125
|
-
*/
|
|
2126
|
-
checkNamespaces(packageId: string, config: Record<string, unknown>): {
|
|
2127
|
-
available: boolean;
|
|
2128
|
-
conflicts: Array<{
|
|
2129
|
-
namespace: string;
|
|
2130
|
-
existingPackageId: string;
|
|
2131
|
-
}>;
|
|
2132
|
-
};
|
|
2133
|
-
/**
|
|
2134
|
-
* Get the namespace resolver instance.
|
|
2135
|
-
*/
|
|
2136
|
-
getNamespaceResolver(): NamespaceResolver;
|
|
2137
|
-
/**
|
|
2138
|
-
* Get a snapshot for a given package (if available).
|
|
2139
|
-
*/
|
|
2140
|
-
getSnapshot(packageId: string): PackageSnapshot | undefined;
|
|
2141
|
-
}
|
|
2142
|
-
|
|
2143
|
-
export { ApiRegistry, type ApiRegistryPluginConfig, CORE_FALLBACK_FACTORIES, DependencyResolver, HotReloadManager, type InstallResult, type InstalledPackageRecord, type KernelState, LiteKernel, type NamespaceCheckResult, type NamespaceConflict, type NamespaceEntry, NamespaceResolver, ObjectKernel, ObjectKernelBase, type ObjectKernelConfig, ObjectLogger, PackageManager, type PackageSnapshot, type PermissionCheckResult$1 as PermissionCheckResult, type PermissionGrant, type Plugin, PluginConfigValidator, type PluginContext, PluginHealthMonitor, type PluginHealthStatus, type PluginLoadResult, PluginLoader, type PluginMetadata, type PermissionCheckResult as PluginPermissionCheckResult, PluginPermissionEnforcer, PluginPermissionManager, type PluginPermissions, PluginSandboxRuntime, PluginSecurityScanner, type PluginSignatureConfig, PluginSignatureVerifier, type PluginStartupResult, index as QA, type ResourceUsage, type RollbackResult, type SandboxContext, type ScanTarget, SecurePluginContext, type SecurityIssue, SemanticVersionManager, type ServiceFactory, ServiceLifecycle, type ServiceRegistration, type SignatureVerificationResult, type UpgradeResult, type VersionCompatibility, createApiRegistryPlugin, createLogger, createMemoryCache, createMemoryI18n, createMemoryJob, createMemoryMetadata, createMemoryQueue, createPluginConfigValidator, createPluginPermissionEnforcer, getEnv, getMemoryUsage, isNode, resolveLocale, safeExit };
|
|
1944
|
+
export { ApiRegistry, type ApiRegistryPluginConfig, CORE_FALLBACK_FACTORIES, DependencyResolver, HotReloadManager, type KernelState, LiteKernel, type NamespaceCheckResult, type NamespaceConflict, type NamespaceEntry, NamespaceResolver, ObjectKernel, ObjectKernelBase, type ObjectKernelConfig, ObjectLogger, type PermissionCheckResult$1 as PermissionCheckResult, type PermissionGrant, type Plugin, PluginConfigValidator, type PluginContext, PluginHealthMonitor, type PluginHealthStatus, type PluginLoadResult, PluginLoader, type PluginMetadata, type PermissionCheckResult as PluginPermissionCheckResult, PluginPermissionEnforcer, PluginPermissionManager, type PluginPermissions, PluginSandboxRuntime, PluginSecurityScanner, type PluginSignatureConfig, PluginSignatureVerifier, type PluginStartupResult, index as QA, type ResourceUsage, type SandboxContext, type ScanTarget, SecurePluginContext, type SecurityIssue, SemanticVersionManager, type ServiceFactory, ServiceLifecycle, type ServiceRegistration, type SignatureVerificationResult, type VersionCompatibility, createApiRegistryPlugin, createMemoryCache, createMemoryI18n, createMemoryJob, createMemoryMetadata, createMemoryQueue, createPluginConfigValidator, createPluginPermissionEnforcer, getEnv, getMemoryUsage, isNode, resolveLocale, safeExit };
|