universe-lib
v0.1.0
Published
Shared infrastructure library: event system, lifecycle, IPC, DI, URI utilities. Extracted from VS Code architecture.
Downloads
122
Maintainers
Readme
universe-lib
Shared infrastructure library providing event system, lifecycle management, IPC communication, dependency injection, and URI utilities. Extracted from VS Code architecture.
Install
npm install universe-libEntry Points
| Import path | Description |
| ----------------------------------- | --------------------------------------------------------------------------- |
| universe-lib | Stable common API (event, lifecycle, async, buffer, URI, IPC protocol) |
| universe-lib/common | Explicit common exports (same as root) |
| universe-lib/node | Common + Node.js IPC (connect(), serve(), named pipe support) |
| universe-lib/platform | DI & platform services (createDecorator, InstantiationService, logging) |
Usage
import { Emitter, Event, Disposable } from 'universe-lib';
// Event system
const emitter = new Emitter<string>();
const disposable = emitter.event((msg) => console.log(msg));
emitter.fire('hello');
disposable.dispose();import { ProxyChannel } from 'universe-lib';
import { connect, serve } from 'universe-lib/node';
// IPC server
const server = await serve('\\\\.\\pipe\\my-app');
server.registerChannel('myChannel', ProxyChannel.fromService(myService));
// IPC client
const client = await connect('\\\\.\\pipe\\my-app', 'my-client');
const channel = client.getChannel('myChannel');
const proxy = ProxyChannel.toService(channel);import { createDecorator, InstantiationService, ServiceCollection, SyncDescriptor } from 'universe-lib/platform';
// Dependency injection
const IMyService = createDecorator<IMyService>('myService');
const services = new ServiceCollection();
services.set(IMyService, new SyncDescriptor(MyServiceImpl));API Overview
Event System (Emitter, Event)
Emitter<T>— Core event emitter withfire(),event,dispose()Eventnamespace — Composition operators:map,filter,debounce,buffer,chain,reduce,once
Lifecycle (IDisposable, Disposable, DisposableStore)
- Deterministic resource cleanup via
IDisposablepattern DisposableStorefor managing multiple disposables
IPC Communication
ChannelClient/ChannelServer— RPC protocol abstractionProtocol— Message-based network transportProxyChannel— Automatic service proxy generationconnect()/serve()— Node.js named pipe connections
Dependency Injection
createDecorator<T>(id)— Create service identifier & parameter decoratorInstantiationService— Service container with lazy instantiationSyncDescriptor/AsyncDescriptor— Deferred service creation
Utilities
URI— Cross-platform URI parsing and manipulationVSBuffer— Buffer abstractionCancellationToken— Cooperative cancellation- Async helpers, string utilities, path abstraction, hash functions
Requirements
- Node.js >= 18
- TypeScript >= 5.0 (for type definitions)
License
This library is derived from the VS Code codebase, which is also MIT licensed.
