UNPKG

@uisap/core

Version:

A modular Fastify-based framework inspired by Laravel

215 lines (172 loc) 4.84 kB
// uisap-core/src/facades.js import { setFastify, app } from "./helpers.js"; export class EventFacade { static setFastify(fastify) { setFastify(fastify); } static fire(event) { return app("events").fire(event); } static listen(eventName, listener, priority = 0) { return app("events").listen(eventName, listener, priority); } } export class QueueFacade { static setFastify(fastify) { setFastify(fastify); } static push(taskType, data) { return app("queue").push(taskType, data); } static addTo(queueName, taskType, data) { return app("queue").addTo(queueName, taskType, data); } } export class BroadcastFacade { static setFastify(fastify) { setFastify(fastify); } static toRoom(channel, event, data) { return app("broadcast").toRoom(channel, event, data); } static channel(pattern, callback) { return app("broadcast").channel(pattern, callback); } } export class ScheduleFacade { static setFastify(fastify) { setFastify(fastify); } // Mevcut metodlar static call(callback, cronExpression = "* * * * *") { const schedule = app("schedule"); return schedule.call(callback, cronExpression); } static queue(queueName, data, cronExpression = "* * * * *") { const schedule = app("schedule"); return schedule.queue(queueName, data, cronExpression); } static command(signature, cronExpression = "* * * * *", options = {}) { const schedule = app("schedule"); return schedule.command(signature, cronExpression, options); } static run() { const schedule = app("schedule"); return schedule.run(); } static stop() { const schedule = app("schedule"); return schedule.stop(); } // Yeni zamanlama yardımcıları static everySecond() { const schedule = app("schedule"); return schedule.everySecond(); } static everyTwoSeconds() { const schedule = app("schedule"); return schedule.everyTwoSeconds(); } static everyFiveSeconds() { const schedule = app("schedule"); return schedule.everyFiveSeconds(); } static everyTenSeconds() { const schedule = app("schedule"); return schedule.everyTenSeconds(); } static everyFifteenSeconds() { const schedule = app("schedule"); return schedule.everyFifteenSeconds(); } static everyThirtySeconds() { const schedule = app("schedule"); return schedule.everyThirtySeconds(); } static everyMinute() { const schedule = app("schedule"); return schedule.everyMinute(); } static everyTwoMinutes() { const schedule = app("schedule"); return schedule.everyTwoMinutes(); } static everyFiveMinutes() { const schedule = app("schedule"); return schedule.everyFiveMinutes(); } static everyTenMinutes() { const schedule = app("schedule"); return schedule.everyTenMinutes(); } static everyFifteenMinutes() { const schedule = app("schedule"); return schedule.everyFifteenMinutes(); } static hourly(minutes = 0) { const schedule = app("schedule"); return schedule.hourly(minutes); } static daily(time = "0:00") { const schedule = app("schedule"); return schedule.daily(time); } static twiceDaily(hour1, hour2, minute = 0) { const schedule = app("schedule"); return schedule.twiceDaily(hour1, hour2, minute); } static weekly(day = 0, time = "0:00") { const schedule = app("schedule"); return schedule.weekly(day, time); } static monthly(day = 1, time = "0:00") { const schedule = app("schedule"); return schedule.monthly(day, time); } static quarterly(day = 1, time = "0:00") { const schedule = app("schedule"); return schedule.quarterly(day, time); } static yearly(month = 1, day = 1, time = "0:00") { const schedule = app("schedule"); return schedule.yearly(month, day, time); } static setTimezone(timezone) { const schedule = app("schedule"); return schedule.setTimezone(timezone); } static listTasks() { const schedule = app("schedule"); return schedule.listTasks(); } } export class KeyValueFacade { static setFastify(fastify) { setFastify(fastify); } static async get(key) { return await app("keyValueStore").get(key); } static async set(key, value, ttl = null) { return await app("keyValueStore").set(key, value, ttl); } static async del(key) { return await app("keyValueStore").del(key); } static async has(key) { return await app("keyValueStore").has(key); } static async lpush(key, value) { return await app("keyValueStore").lpush(key, value); } static async ltrim(key, start, stop) { return await app("keyValueStore").ltrim(key, start, stop); } } export default { EventFacade, QueueFacade, BroadcastFacade, ScheduleFacade, KeyValueFacade };