# @echelon-framework/core

Core types, interfaces, and contracts for the Echelon framework — Angular-based, config-driven dashboard & low-code platform.

## Installation

```bash
npm install @echelon-framework/core
```

## What's inside

### DataBus — reactive data layer

```ts
import type { DataBus, DataSource, DataSnapshot } from '@echelon-framework/core';

// DataSource — reactive stream per datasource ID
interface DataSource<T> {
  readonly id: DatasourceId;
  readonly value$: Observable<DataSnapshot<T>>;
  refresh(): void;
  snapshot(): DataSnapshot<T>;
}

// DataBus — singleton registry of all datasources
interface DataBus {
  source<T>(id: DatasourceId): DataSource<T>;
  invalidate(id?: DatasourceId): void;
}
```

### EventBus — pub/sub event layer

```ts
import type { EventBus, EchelonEvent } from '@echelon-framework/core';

interface EventBus {
  readonly stream$: Observable<EchelonEvent>;
  on<T>(typePattern: string): Observable<EchelonEvent<T>>;
  emit<T>(type: string, payload: T): void;
}
```

### PageConfig — declarative page configuration

```ts
import type {
  PageConfig,
  WidgetConfig,
  DatasourceConfig,
  EventHandlerConfig,
} from '@echelon-framework/core';

// PageConfig = { $schemaVersion, page: { id, title, datasources, widgets, layout, eventHandlers, lifecycle } }
```

### EventAction — declarative handler actions

```ts
type EventAction =
  | { call: string; with?: string } // call computed function
  | { emit: string; payload?: string } // emit event
  | { setDatasource: string; from: string } // overwrite DS value
  | { mergeDatasource: string; from: string } // shallow merge DS value (wizard steps)
  | { clearDatasource: string } // clear DS
  | { navigate: string | unknown[] } // router navigate
  | { fetch: string; into: string; with?: unknown }; // HTTP fetch → DS
```

### DatasourceConfig

```ts
interface DatasourceConfig {
  kind?: 'transport' | 'local' | 'computed' | 'stream';
  transport?: string; // 'http' | 'websocket' | 'mock'
  endpoint?: string; // URL path
  initial?: unknown; // for kind:'local'
  fn?: string; // for kind:'computed'
  inputs?: string[]; // computed dependencies
  cache?: CacheConfig;
  persistence?: PersistenceConfig;
}
```

## License

BUSL-1.1
