Service Registry — Kernel Protocol reference
Zod schemas for service registry data structures. These schemas align with the IServiceRegistry contract interface.
Service Registry Protocol
Zod schemas for service registry data structures. These schemas align with the IServiceRegistry contract interface.
Following ObjectStack "Zod First" principle - all data structures must have Zod schemas for runtime validation and JSON Schema generation.
Note: IServiceRegistry itself is a runtime interface (methods only), so it correctly remains a TypeScript interface. This file contains schemas for configuration and metadata related to service registry.
Source: packages/spec/src/kernel/service-registry.zod.ts
TypeScript Usage
import { ScopeConfigSchema, ScopeInfoSchema, ServiceFactoryRegistrationSchema, ServiceMetadataSchema, ServiceRegistryConfigSchema, ServiceScopeType } from '@objectstack/spec/kernel';
import type { ScopeConfig, ScopeInfo, ServiceFactoryRegistration, ServiceMetadata, ServiceRegistryConfig, ServiceScopeType } from '@objectstack/spec/kernel';
// Validate data
const result = ScopeConfigSchema.parse(data);ScopeConfig
Properties
| Property | Type | Required | Description |
|---|---|---|---|
| scopeType | string | ✅ | Type of scope |
| scopeId | string | optional | Unique scope identifier |
| metadata | Record<string, any> | optional | Scope-specific context metadata |
ScopeInfo
Properties
| Property | Type | Required | Description |
|---|---|---|---|
| scopeId | string | ✅ | Unique scope identifier |
| scopeType | string | ✅ | Type of scope |
| createdAt | integer | ✅ | Unix timestamp in milliseconds when scope was created |
| serviceCount | integer | optional | Number of services registered in this scope |
| metadata | Record<string, any> | optional | Scope-specific context metadata |
ServiceFactoryRegistration
Properties
| Property | Type | Required | Description |
|---|---|---|---|
| name | string | ✅ | Unique service name identifier |
| scope | Enum<'singleton' | 'transient' | 'scoped'> | optional (default: "singleton") | Service scope type |
| factoryType | Enum<'sync' | 'async'> | optional (default: "sync") | Whether factory is synchronous or asynchronous |
| singleton | boolean | optional (default: true) | Whether to cache the factory result (singleton pattern) |
| cluster | { clusterScope?: Enum<'node' | 'cluster'>; leaderStrategy?: Enum<'leader-elected' | 'partitioned' | 'idempotent-broadcast'>; clusterId?: string } | optional | Cluster scope & leader strategy for this service. |
Nested Shape: ServiceFactoryRegistration.cluster
| Property | Type | Required | Description |
|---|---|---|---|
| clusterScope | Enum<'node' | 'cluster'> | optional (default: "node") | Per-node vs cluster-singleton presence. |
| leaderStrategy | Enum<'leader-elected' | 'partitioned' | 'idempotent-broadcast'> | optional | How the cluster-singleton invariant is maintained. |
| clusterId | string | optional | Logical cluster identity used for leader election (defaults to service name). |
ServiceMetadata
Properties
| Property | Type | Required | Description |
|---|---|---|---|
| name | string | ✅ | Unique service name identifier |
| scope | Enum<'singleton' | 'transient' | 'scoped'> | optional (default: "singleton") | Service scope type |
| type | string | optional | Service type or interface name |
| registeredAt | integer | optional | Unix timestamp in milliseconds when service was registered |
| metadata | Record<string, any> | optional | Additional service-specific metadata |
| cluster | { clusterScope?: Enum<'node' | 'cluster'>; leaderStrategy?: Enum<'leader-elected' | 'partitioned' | 'idempotent-broadcast'>; clusterId?: string } | optional | Cluster scope & leader strategy. See /docs/kernel/cluster §5. |
Nested Shape: ServiceMetadata.cluster
| Property | Type | Required | Description |
|---|---|---|---|
| clusterScope | Enum<'node' | 'cluster'> | optional (default: "node") | Per-node vs cluster-singleton presence. |
| leaderStrategy | Enum<'leader-elected' | 'partitioned' | 'idempotent-broadcast'> | optional | How the cluster-singleton invariant is maintained. |
| clusterId | string | optional | Logical cluster identity used for leader election (defaults to service name). |
ServiceRegistryConfig
Properties
| Property | Type | Required | Description |
|---|---|---|---|
| strictMode | boolean | optional (default: true) | Throw errors on invalid operations (duplicate registration, service not found, etc.) |
| allowOverwrite | boolean | optional (default: false) | Allow overwriting existing service registrations |
| enableLogging | boolean | optional (default: false) | Enable logging for service registration and retrieval |
| scopeTypes | string[] | optional | Supported scope types |
| maxServices | integer | optional | Maximum number of services that can be registered |
ServiceScopeType
Service scope type
Allowed Values
singletontransientscoped