fix(ci): Update CI workflows and build config; bump dependencies; code style and TS config fixes
This commit is contained in:
337
readme.md
337
readme.md
@@ -1,48 +1,317 @@
|
||||
# @mojoio/elasticsearch
|
||||
log to elasticsearch in a kibana compatible format
|
||||
# @apiclient.xyz/elasticsearch
|
||||
|
||||
## Availabililty and Links
|
||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@mojoio/elasticsearch)
|
||||
* [gitlab.com (source)](https://gitlab.com/mojoio/elasticsearch)
|
||||
* [github.com (source mirror)](https://github.com/mojoio/elasticsearch)
|
||||
* [docs (typedoc)](https://mojoio.gitlab.io/elasticsearch/)
|
||||
> 🔍 **Modern TypeScript client for Elasticsearch with built-in Kibana compatibility and advanced logging features**
|
||||
|
||||
## Status for master
|
||||
A powerful, type-safe wrapper around the official Elasticsearch client that provides intelligent log management, document handling, key-value storage, and fast data ingestion - all optimized for production use.
|
||||
|
||||
Status Category | Status Badge
|
||||
-- | --
|
||||
GitLab Pipelines | [](https://lossless.cloud)
|
||||
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||
npm | [](https://lossless.cloud)
|
||||
Snyk | [](https://lossless.cloud)
|
||||
TypeScript Support | [](https://lossless.cloud)
|
||||
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
Code Style | [](https://lossless.cloud)
|
||||
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||
## Issue Reporting and Security
|
||||
|
||||
## Usage
|
||||
For reporting bugs, issues, or security vulnerabilities, please visit [community.foss.global/](https://community.foss.global/). This is the central community hub for all issue reporting. Developers who sign and comply with our contribution agreement and go through identification can also get a [code.foss.global/](https://code.foss.global/) account to submit Pull Requests directly.
|
||||
|
||||
Use TypeScript for best in class instellisense.
|
||||
## Features ✨
|
||||
|
||||
For further information read the linked docs at the top of this README.
|
||||
- **🎯 SmartLog Destination** - Full-featured logging destination compatible with Kibana, automatic index rotation, and retention management
|
||||
- **📦 ElasticDoc** - Advanced document management with piping sessions, snapshots, and automatic cleanup
|
||||
- **🚀 FastPush** - High-performance bulk document insertion with automatic index management
|
||||
- **💾 KVStore** - Simple key-value storage interface backed by Elasticsearch
|
||||
- **🔧 TypeScript First** - Complete type safety with full TypeScript support
|
||||
- **🌊 Data Streams** - Built-in support for Elasticsearch data streams
|
||||
- **⚡ Production Ready** - Designed for high-throughput production environments
|
||||
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
||||
## Installation 📦
|
||||
|
||||
[](https://push.rocks)
|
||||
```bash
|
||||
npm install @apiclient.xyz/elasticsearch
|
||||
# or
|
||||
pnpm install @apiclient.xyz/elasticsearch
|
||||
```
|
||||
|
||||
## Contribute
|
||||
## Quick Start 🚀
|
||||
|
||||
We are always happy for code contributions. If you are not the code contributing type that is ok. + Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: [Contribute monthly :)](https://lossless.link/contribute)
|
||||
### SmartLog Destination
|
||||
|
||||
## Contribution
|
||||
Perfect for application logging with automatic index rotation and Kibana compatibility:
|
||||
|
||||
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
||||
```typescript
|
||||
import { ElsSmartlogDestination } from '@apiclient.xyz/elasticsearch';
|
||||
|
||||
For further information read the linked docs at the top of this readme.
|
||||
const logger = new ElsSmartlogDestination({
|
||||
indexPrefix: 'app-logs',
|
||||
indexRetention: 7, // Keep logs for 7 days
|
||||
node: 'http://localhost:9200',
|
||||
auth: {
|
||||
username: 'elastic',
|
||||
password: 'your-password',
|
||||
},
|
||||
});
|
||||
|
||||
## Legal
|
||||
> MIT licensed | **©** [Task Venture Capital GmbH](https://task.vc)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||
// Log messages that automatically appear in Kibana
|
||||
await logger.log({
|
||||
timestamp: Date.now(),
|
||||
type: 'increment',
|
||||
level: 'info',
|
||||
context: {
|
||||
company: 'YourCompany',
|
||||
companyunit: 'api-service',
|
||||
containerName: 'web-server',
|
||||
environment: 'production',
|
||||
runtime: 'node',
|
||||
zone: 'us-east-1',
|
||||
},
|
||||
message: 'User authentication successful',
|
||||
correlation: null,
|
||||
});
|
||||
```
|
||||
|
||||
### ElasticDoc - Document Management
|
||||
|
||||
Handle documents with advanced features like piping sessions and snapshots:
|
||||
|
||||
```typescript
|
||||
import { ElasticDoc } from '@apiclient.xyz/elasticsearch';
|
||||
|
||||
const docManager = new ElasticDoc({
|
||||
index: 'products',
|
||||
node: 'http://localhost:9200',
|
||||
auth: {
|
||||
username: 'elastic',
|
||||
password: 'your-password',
|
||||
},
|
||||
});
|
||||
|
||||
// Start a piping session to manage document lifecycle
|
||||
await docManager.startPipingSession({});
|
||||
|
||||
// Add or update documents
|
||||
await docManager.pipeDocument({
|
||||
docId: 'product-001',
|
||||
timestamp: new Date().toISOString(),
|
||||
doc: {
|
||||
name: 'Premium Widget',
|
||||
price: 99.99,
|
||||
inStock: true
|
||||
},
|
||||
});
|
||||
|
||||
await docManager.pipeDocument({
|
||||
docId: 'product-002',
|
||||
timestamp: new Date().toISOString(),
|
||||
doc: {
|
||||
name: 'Deluxe Gadget',
|
||||
price: 149.99,
|
||||
inStock: false
|
||||
},
|
||||
});
|
||||
|
||||
// End session - automatically removes documents not in this session
|
||||
await docManager.endPipingSession();
|
||||
|
||||
// Take and store snapshots with custom aggregations
|
||||
await docManager.takeSnapshot(async (iterator, prevSnapshot) => {
|
||||
const aggregationData = [];
|
||||
for await (const doc of iterator) {
|
||||
aggregationData.push(doc);
|
||||
}
|
||||
return {
|
||||
date: new Date().toISOString(),
|
||||
aggregationData,
|
||||
};
|
||||
});
|
||||
```
|
||||
|
||||
### FastPush - Bulk Data Ingestion
|
||||
|
||||
Efficiently push large datasets with automatic index management:
|
||||
|
||||
```typescript
|
||||
import { FastPush } from '@apiclient.xyz/elasticsearch';
|
||||
|
||||
const fastPush = new FastPush({
|
||||
node: 'http://localhost:9200',
|
||||
auth: {
|
||||
username: 'elastic',
|
||||
password: 'your-password',
|
||||
},
|
||||
});
|
||||
|
||||
const documents = [
|
||||
{ id: 1, name: 'Document 1', data: 'Some data' },
|
||||
{ id: 2, name: 'Document 2', data: 'More data' },
|
||||
// ... thousands more documents
|
||||
];
|
||||
|
||||
// Push all documents with automatic batching
|
||||
await fastPush.pushDocuments('bulk-data', documents, {
|
||||
deleteOldData: true, // Clear old data before inserting
|
||||
});
|
||||
```
|
||||
|
||||
### KVStore - Key-Value Storage
|
||||
|
||||
Simple key-value storage backed by the power of Elasticsearch:
|
||||
|
||||
```typescript
|
||||
import { KVStore } from '@apiclient.xyz/elasticsearch';
|
||||
|
||||
const kvStore = new KVStore({
|
||||
index: 'app-config',
|
||||
node: 'http://localhost:9200',
|
||||
auth: {
|
||||
username: 'elastic',
|
||||
password: 'your-password',
|
||||
},
|
||||
});
|
||||
|
||||
// Set values
|
||||
await kvStore.set('api-key', 'sk-1234567890');
|
||||
await kvStore.set('feature-flags', JSON.stringify({ newUI: true }));
|
||||
|
||||
// Get values
|
||||
const apiKey = await kvStore.get('api-key');
|
||||
console.log(apiKey); // 'sk-1234567890'
|
||||
|
||||
// Clear all data
|
||||
await kvStore.clear();
|
||||
```
|
||||
|
||||
## Core Classes 🏗️
|
||||
|
||||
### ElsSmartlogDestination
|
||||
|
||||
The main logging destination class that provides:
|
||||
- Automatic index rotation based on date
|
||||
- Configurable retention policies
|
||||
- Kibana-compatible log format
|
||||
- Data stream support
|
||||
- Built-in scheduler for maintenance tasks
|
||||
|
||||
### ElasticDoc
|
||||
|
||||
Advanced document management with:
|
||||
- Piping sessions for tracking document lifecycles
|
||||
- Automatic cleanup of stale documents
|
||||
- Snapshot functionality with custom processors
|
||||
- Iterator-based document access
|
||||
- Fast-forward mode for incremental processing
|
||||
|
||||
### FastPush
|
||||
|
||||
High-performance bulk operations:
|
||||
- Automatic batching for optimal performance
|
||||
- Index management (create, delete, clear)
|
||||
- Dynamic mapping support
|
||||
- Efficient bulk API usage
|
||||
|
||||
### KVStore
|
||||
|
||||
Simple key-value interface:
|
||||
- Elasticsearch-backed storage
|
||||
- Async/await API
|
||||
- Automatic index initialization
|
||||
- Clear and get operations
|
||||
|
||||
## Advanced Usage 🎓
|
||||
|
||||
### Index Rotation and Retention
|
||||
|
||||
```typescript
|
||||
const logger = new ElsSmartlogDestination({
|
||||
indexPrefix: 'myapp',
|
||||
indexRetention: 30, // Keep 30 days of logs
|
||||
node: 'http://localhost:9200',
|
||||
});
|
||||
|
||||
// Indices are automatically created as: myapp-2025-01-22
|
||||
// Old indices are automatically deleted after 30 days
|
||||
```
|
||||
|
||||
### Document Iteration
|
||||
|
||||
```typescript
|
||||
// Iterate over all documents in an index
|
||||
const iterator = docManager.getDocumentIterator();
|
||||
for await (const doc of iterator) {
|
||||
console.log(doc);
|
||||
}
|
||||
|
||||
// Only process new documents since last run
|
||||
docManager.fastForward = true;
|
||||
await docManager.startPipingSession({ onlyNew: true });
|
||||
```
|
||||
|
||||
### Custom Snapshots
|
||||
|
||||
```typescript
|
||||
await docManager.takeSnapshot(async (iterator, prevSnapshot) => {
|
||||
let totalValue = 0;
|
||||
let count = 0;
|
||||
|
||||
for await (const doc of iterator) {
|
||||
totalValue += doc._source.price;
|
||||
count++;
|
||||
}
|
||||
|
||||
return {
|
||||
date: new Date().toISOString(),
|
||||
aggregationData: {
|
||||
totalValue,
|
||||
averagePrice: totalValue / count,
|
||||
count,
|
||||
previousSnapshot: prevSnapshot,
|
||||
},
|
||||
};
|
||||
});
|
||||
```
|
||||
|
||||
## API Compatibility 🔄
|
||||
|
||||
This module is built on top of `@elastic/elasticsearch` v9.x and is compatible with:
|
||||
- Elasticsearch 8.x and 9.x clusters
|
||||
- Kibana 8.x and 9.x for log visualization
|
||||
- OpenSearch (with some limitations)
|
||||
|
||||
## TypeScript Support 💙
|
||||
|
||||
Full TypeScript support with comprehensive type definitions:
|
||||
|
||||
```typescript
|
||||
import type {
|
||||
IElasticDocConstructorOptions,
|
||||
ISnapshot,
|
||||
SnapshotProcessor
|
||||
} from '@apiclient.xyz/elasticsearch';
|
||||
```
|
||||
|
||||
## Performance Considerations ⚡
|
||||
|
||||
- **Bulk Operations**: FastPush uses 1000-document batches by default
|
||||
- **Connection Pooling**: Reuses Elasticsearch client connections
|
||||
- **Index Management**: Automatic index creation and deletion
|
||||
- **Data Streams**: Built-in support for efficient log ingestion
|
||||
|
||||
## Best Practices 💡
|
||||
|
||||
1. **Always use authentication** in production environments
|
||||
2. **Set appropriate retention policies** to manage storage costs
|
||||
3. **Use piping sessions** to automatically clean up stale documents
|
||||
4. **Leverage snapshots** for point-in-time analytics
|
||||
5. **Configure index templates** for consistent mappings
|
||||
|
||||
## License and Legal Information
|
||||
|
||||
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
|
||||
|
||||
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
||||
|
||||
### Trademarks
|
||||
|
||||
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
|
||||
|
||||
### Company Information
|
||||
|
||||
Task Venture Capital GmbH
|
||||
Registered at District court Bremen HRB 35230 HB, Germany
|
||||
|
||||
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
|
||||
|
||||
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
|
||||
|
||||
Reference in New Issue
Block a user