@pulzar/core
Version:
Next-generation Node.js framework for ultra-fast web applications with zero-reflection DI, GraphQL, WebSockets, events, and edge runtime support
83 lines • 2.66 kB
JavaScript
// Core framework tokens (immutable)
export const CORE_TOKENS = {
// Application tokens
APP_CONFIG: Symbol("APP_CONFIG"),
APP_LOGGER: Symbol("APP_LOGGER"),
// HTTP tokens
HTTP_SERVER: Symbol("HTTP_SERVER"),
HTTP_ROUTER: Symbol("HTTP_ROUTER"),
HTTP_MIDDLEWARE: Symbol("HTTP_MIDDLEWARE"),
// Database tokens
DATABASE_CONNECTION: Symbol("DATABASE_CONNECTION"),
DATABASE_CLIENT: Symbol("DATABASE_CLIENT"),
// Cache tokens
CACHE_CLIENT: Symbol("CACHE_CLIENT"),
REDIS_CLIENT: Symbol("REDIS_CLIENT"),
// Event tokens
EVENT_BUS: Symbol("EVENT_BUS"),
EVENT_PUBLISHER: Symbol("EVENT_PUBLISHER"),
EVENT_SUBSCRIBER: Symbol("EVENT_SUBSCRIBER"),
// Task tokens
TASK_SCHEDULER: Symbol("TASK_SCHEDULER"),
TASK_QUEUE: Symbol("TASK_QUEUE"),
// WebSocket tokens
WS_GATEWAY: Symbol("WS_GATEWAY"),
WS_SERVER: Symbol("WS_SERVER"),
// GraphQL tokens
GRAPHQL_SCHEMA: Symbol("GRAPHQL_SCHEMA"),
GRAPHQL_RESOLVERS: Symbol("GRAPHQL_RESOLVERS"),
// Tracing tokens
TRACER: Symbol("TRACER"),
METRICS: Symbol("METRICS"),
// Auth tokens
AUTH_SERVICE: Symbol("AUTH_SERVICE"),
AUTH_GUARD: Symbol("AUTH_GUARD"),
// I18n tokens
I18N_SERVICE: Symbol("I18N_SERVICE"),
// Plugin tokens
PLUGIN_MANAGER: Symbol("PLUGIN_MANAGER"),
PLUGIN_REGISTRY: Symbol("PLUGIN_REGISTRY"),
};
// Extensible token registry for plugins
class TokenRegistry {
customTokens = new Map();
// Create new token for plugins
create(description) {
if (this.customTokens.has(description)) {
return this.customTokens.get(description);
}
const token = Symbol(description);
this.customTokens.set(description, token);
return token;
}
// Check if token exists
has(description) {
return this.customTokens.has(description);
}
// Get existing token
get(description) {
return this.customTokens.get(description);
}
// List all custom tokens
list() {
return Array.from(this.customTokens.entries()).map(([description, token]) => ({
description,
token,
}));
}
// Clear all custom tokens (for testing)
clear() {
this.customTokens.clear();
}
}
// Global token registry
export const tokenRegistry = new TokenRegistry();
// Unified DI_TOKENS with extensibility
export const DI_TOKENS = {
...CORE_TOKENS,
// Plugin token factory
create: tokenRegistry.create.bind(tokenRegistry),
has: tokenRegistry.has.bind(tokenRegistry),
get: tokenRegistry.get.bind(tokenRegistry),
};
//# sourceMappingURL=tokens.js.map