ObjectStackObjectStack

Service Registry

Service Registry protocol schemas

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

PropertyTypeRequiredDescription
scopeTypestringType of scope
scopeIdstringoptionalUnique scope identifier
metadataRecord<string, any>optionalScope-specific context metadata

ScopeInfo

Properties

PropertyTypeRequiredDescription
scopeIdstringUnique scope identifier
scopeTypestringType of scope
createdAtintegerUnix timestamp in milliseconds when scope was created
serviceCountintegeroptionalNumber of services registered in this scope
metadataRecord<string, any>optionalScope-specific context metadata

ServiceFactoryRegistration

Properties

PropertyTypeRequiredDescription
namestringUnique service name identifier
scopeEnum<'singleton' | 'transient' | 'scoped'>optional (default: "singleton")Service scope type
factoryTypeEnum<'sync' | 'async'>optional (default: "sync")Whether factory is synchronous or asynchronous
singletonbooleanoptional (default: true)Whether to cache the factory result (singleton pattern)
cluster{ clusterScope: Enum<'node' | 'cluster'>; leaderStrategy?: Enum<'leader-elected' | 'partitioned' | 'idempotent-broadcast'>; clusterId?: string }optionalCluster scope & leader strategy for this service.

Nested Shape: ServiceFactoryRegistration.cluster

PropertyTypeRequiredDescription
clusterScopeEnum<'node' | 'cluster'>optional (default: "node")Per-node vs cluster-singleton presence.
leaderStrategyEnum<'leader-elected' | 'partitioned' | 'idempotent-broadcast'>optionalHow the cluster-singleton invariant is maintained.
clusterIdstringoptionalLogical cluster identity used for leader election (defaults to service name).

ServiceMetadata

Properties

PropertyTypeRequiredDescription
namestringUnique service name identifier
scopeEnum<'singleton' | 'transient' | 'scoped'>optional (default: "singleton")Service scope type
typestringoptionalService type or interface name
registeredAtintegeroptionalUnix timestamp in milliseconds when service was registered
metadataRecord<string, any>optionalAdditional service-specific metadata
cluster{ clusterScope: Enum<'node' | 'cluster'>; leaderStrategy?: Enum<'leader-elected' | 'partitioned' | 'idempotent-broadcast'>; clusterId?: string }optionalCluster scope & leader strategy. See cluster-semantics.mdx §5.

Nested Shape: ServiceMetadata.cluster

PropertyTypeRequiredDescription
clusterScopeEnum<'node' | 'cluster'>optional (default: "node")Per-node vs cluster-singleton presence.
leaderStrategyEnum<'leader-elected' | 'partitioned' | 'idempotent-broadcast'>optionalHow the cluster-singleton invariant is maintained.
clusterIdstringoptionalLogical cluster identity used for leader election (defaults to service name).

ServiceRegistryConfig

Properties

PropertyTypeRequiredDescription
strictModebooleanoptional (default: true)Throw errors on invalid operations (duplicate registration, service not found, etc.)
allowOverwritebooleanoptional (default: false)Allow overwriting existing service registrations
enableLoggingbooleanoptional (default: false)Enable logging for service registration and retrieval
scopeTypesstring[]optionalSupported scope types
maxServicesintegeroptionalMaximum number of services that can be registered

ServiceScopeType

Service scope type

Allowed Values

  • singleton
  • transient
  • scoped

On this page