Skip to content

DataBank API

Central data storage system that decouples data producers from consumers.

typescript
import { start } from 'lucidlines';

const { databank } = start({
  commands: [
    { name: 'web', command: 'npm run dev' }
  ]
});

// see databank methods below

WARNING

DataBank is automatically created and managed by LucidLines regardless of configuration. The API documented here is for advanced use cases where you need direct access to log data programmatically. Most users won't need to interact with DataBank directly.

Note: In the example above, serverPort is not set, meaning the web interface isn't running. While DataBank still collects and stores all command output, nothing is consuming or displaying it. Add serverPort to enable the web dashboard, or use databank.subscribe() to process logs programmatically. We invite those who are adventurous to create their own interface.

addData(type, data)

Adds data to the DataBank storage. This is done internally by the node-stream.ts library. Users typically don't use this.

Parameters

  • type (string) - Data type/category
  • data (string) - The data content to store

Example

typescript
/* with:
commands: [
  { name: 'web', command: 'npm run dev' }
]
*/
databank.addData('web', 'log message');

getRecentMessages(limit?)

Gets recent messages for newly connected clients.

Parameters

  • limit (number, optional) - Maximum number of messages to return (default: 1000)

Returns

  • LogEntry[] - Array of recent log entries

Example

typescript
const recent = databank.getRecentMessages(50);

getMessageByType(type, lastTimestamp?, limit?)

Gets messages for a specific type.

Parameters

  • type (string) - Data type to filter by
  • lastTimestamp (number, optional) - Get messages before this timestamp
  • limit (number, optional) - Maximum number of messages to return (default: 20)

Returns

  • LogEntry[] - Array of log entries for the specified type

Example

typescript
/* with:
commands: [
  { name: 'web', command: 'npm run dev' }
]
*/
const appLogs = databank.getMessageByType('web', undefined, 100);

getAllMessages()

Gets all stored messages (use with caution for large datasets).

Returns

  • LogEntry[] - Array of all log entries

Example

typescript
const allMessages = databank.getAllMessages();

getTotalMessageCount()

Gets the total count of all stored messages.

Returns

  • number - Total message count

Example

typescript
const total = databank.getTotalMessageCount();

getMessageCountByType(type)

Gets the count of messages for a specific type.

Parameters

  • type (string) - Data type to count

Returns

  • number - Message count for the specified type

Example

typescript
/* with:
commands: [
  { name: 'web', command: 'npm run dev' }
]
*/
const appCount = databank.getMessageCountByType('web');

getAvailableTypes()

Gets all unique data types stored.

Returns

  • string[] - Array of available data types

Example

typescript
const types = databank.getAvailableTypes();

subscribe(callback)

Subscribes to real-time data updates.

Parameters

  • callback (function) - Function called when new data arrives

Returns

  • function - Unsubscribe function

Example

typescript
const unsubscribe = databank.subscribe((entry: LogEntry) => {
  console.log(`${entry.type}: ${entry.data}`);
});

// Later...
unsubscribe();

cleanup()

Cleans up DataBank resources (should be called on shutdown).

Example

typescript
databank.cleanup();

Types

LogEntry

typescript
interface LogEntry {
  type: string;      // Process name (e.g., "web-server")
  data: string;      // Output line
  timestamp: number; // Unix timestamp
}