
Security News
Frontier AI Is Now Critical Infrastructure
The Fable shutdown shows how quickly model access can become a business continuity risk for AI-dependent engineering teams.
@nldoc/baseworker
Advanced tools
This repository contains a foundational worker implementation for Typescript projects.
A foundational worker implementation for TypeScript projects in the NLdoc ecosystem. This library provides a robust base class for creating workers that handle AMQP message processing with built-in file storage capabilities.
The Base Worker provides a complete foundation for building distributed document processing workers. It handles:
Install the package via npm:
npm install @nldoc/baseworker
Or using yarn:
yarn add @nldoc/baseworker
import { logger } from '@nldoc/logger'
import { Worker, WorkerConfig, WorkerMessageHandler } from '@nldoc/baseworker'
try {
if (!process.env.EXCHANGE) {
throw new Error('No exchange prefix defined')
}
const config: WorkerConfig = {
name: 'your-awesome-worker-name',
amqpHost: process.env.AMQP_HOST ?? 'localhost',
amqpPass: process.env.AMQP_PASS,
amqpPort: process.env.AMQP_PORT ?? '5672',
amqpProtocol: process.env.AMQP_PROTOCOL ?? 'amqp',
amqpUser: process.env.AMQP_USER,
exchangePrefix: process.env.EXCHANGE,
workerInstanceName: process.env.HOSTNAME ?? '',
prefetchLimit: 10,
}
const handler: WorkerMessageHandler = async ({ job, storage }) => {
// Get files from storage
const fileBuffer = await storage.getFileBuffer({
bucketName: job.bucketName,
filePath: job.filePath
})
// Process the document
// Your document processing logic here...
return {
success: true,
result: 'Processing completed successfully',
confidence: 100,
}
}
const worker = new Worker({
logger,
messageHandler: handler,
config,
})
await worker.start()
} catch (error) {
if (error instanceof Error) {
logger.error('Worker failed to start', { error: error.message })
}
throw error
}
For all available configuration options, see the WorkerConfig type definition in src/types/WorkerConfig.ts.
Common environment variables for configuration:
AMQP_HOST=localhost
AMQP_PORT=5672
AMQP_PROTOCOL=amqp
AMQP_USER=guest
AMQP_PASS=guest
EXCHANGE=your-exchange-prefix
HOSTNAME=worker-instance-01
Your message handler receives a context object with:
job: The parsed job data (type: WorkerJob)storage: File storage interface for accessing assetslogger: Structured logger instanceconst handler: WorkerMessageHandler = async ({ job, storage, logger }) => {
logger.info('Processing job', { jobId: job.id })
// Access job properties
const { bucketName, filePath, metadata } = job
// Get file from storage
const fileBuffer = await storage.getFileBuffer({ bucketName, filePath })
// Process and return result
return {
success: true,
result: { processedData: 'example' },
confidence: 95,
metadata: { processingTime: Date.now() }
}
}
Workers automatically report their availability status and handle graceful shutdowns.
Built-in MinIO integration provides seamless file access:
// Get file as buffer
const buffer = await storage.getFileBuffer({ bucketName, filePath })
// Store result files
await storage.putFile({ bucketName: 'output', filePath: 'result.json', data: resultBuffer })
The library includes comprehensive error types:
ConnectionError: AMQP connection issuesInvalidJob: Malformed job dataWorkerError: General worker errorsExternalFileStorageNotReadyError: Storage unavailableClone the repository:
git clone https://gitlab.com/logius/nldoc/lib/typescript/baseworker.git
cd baseworker
Install dependencies:
npm install
Build the project:
npm run build
npm run test - Run the test suite with Vitestnpm run build - Build TypeScript to JavaScriptnpm run check - Type check without emitting filesnpm run lint - Lint the codebase using ESLintnpm run format - Format code using Prettiernpm run format:check - Check code formattingnpm run fix - Auto-fix linting and formatting issuesRun the test suite:
npm test
We welcome contributions! Please ensure:
npm test)npm run format:check)npm run lint)npm run check)This project is licensed under the European Union Public License 1.2 - see LICENSE for details.
FAQs
This repository contains a foundational worker implementation for Typescript projects.
We found that @nldoc/baseworker demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
The Fable shutdown shows how quickly model access can become a business continuity risk for AI-dependent engineering teams.

Security News
AI agents are pulling packages into environments no scanner is watching, creating exposure before security teams can see it.

Security News
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.