An engine for building systems necessary for web production.
This project is currently under development. Please refrain from using it until release as it may undergo specification changes.
npm install @behemothjs/behemoth
The main object.
import {behemoth as app} from '@behemothjs/behemoth';
app.configure({
schema: SchemaConfig,
logger: LoggerConfig,
});
app.log(message);
app.warn(message);
app.error(message);
// Notify
app.notify(channel, topic, payload);
// Subscribe
const subscription = app.listen(channel, topic, (event) => {
app.log(event);
});
// Unsubscribe
subscription.remove();
A schema processing tool useful for creating model classes, etc.
import {Schema} from '@behemothjs/behemoth';
Schema.configure({
// [defaults]
allowAdditionalKeys: false,
allowUndefinedKeys: false,
idStrategy: () => crypto.randomUUID(),
timestampStrategy: () => new Date().toISOString(),
})
import {schema} from '@behemothjs/behemoth';
// Temporary Configuration
schema.configure({
// [defaults]
allowAdditionalKeys: false,
allowUndefinedKeys: false,
idStrategy: () => crypto.randomUUID(),
timestampStrategy: () => new Date().toISOString(),
})
class SampleSchema {
id;
name;
description;
/**
* @param {SampleSchema} data
*/
constructor(data) {
// Before: Input undefined key -> Throw Error
// After: not set keys -> Set undefined to null
schema.assign(this, data);
// If `id` is empty, set the UUID.
schema.autoId(this, 'id');
// If `createdAt/updatedAt` is empty, set the DateTime.
schema.autoTimestamp(this, 'createdAt');
schema.autoTimestamp(this, 'updatedAt');
}
}
const sampleSchema = new SampleSchema({
name: 'Behemoth',
description: 'This is web tool kit.'
})
console.log(sampleSchema)
SampleSchema {
id: '8481d7e4-478c-4233-b4a1-7ea6d7d63749',
name: 'Behemoth',
description: 'This is web tool kit.',
createdAt: '2024-03-21T07:15:45.092Z',
updatedAt: '2024-03-21T07:15:45.092Z',
}
PubSub Module
import {observer} from '@behemothjs/behemoth';
// Notify
observer.notify('channelName', 'topicName', payload);
// Subscribe
const subscription = observer.listen('channelName', 'topicName', (event) => {
console.log(event);
});
// Unsubscribe
subscription.remove();
Logging Tool
import {log} from '@behemothjs/behemoth';
// Configuration or Set environment variable: LOG_LEVEL
log.configure({logLevel: 'WARN'}); // LOG / INFO / WARN / ERROR / SILENT
log.log('LOG'); // console.log('LOG')
log.info('INFO'); // console.info('INFO')
log.warn('WARN'); // console.warn('WARN')
log.error('ERROR'); // console.error('ERROR')
Since this log is output via Observer, it is effective for streaming log collection processes.
const channel = 'Log';
const topic = 'ERROR'; // <-- "*" (wildcard) can be used.
observer.listen(channel, topic, async event => {
const {payload} = event;
await otherStreamingApi.push(payload);
});