This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Code compression - compresses given [A-Za-z0-9]+ string to hex, and/or to | |
* UUIDv5, and decopresses it back. | |
* Used by Rehau piece code compression, to generate unique product UUID based | |
* on code value. | |
* Can't use ordinary hex, as "16-bytes string".toString("hex") would result in | |
* 32 symbol hex string, which is too long to be encoded into UUID. | |
*/ | |
const char0 = '0'.charCodeAt(0); | |
const char9 = '9'.charCodeAt(0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import FSM from "./fsm"; | |
const instance = new FSM([ | |
// Start state, default state | |
{ state: "Green", from: "Red", to: ["Yellow", "Error"] }, | |
// from is allowed array list states | |
{ state: "Yellow", from: "Green", to: ["Red", "Error"] }, | |
// to is single, auto change state to Green | |
{ state: "Red", from: "Yellow", to: ["Green", "Error"] }, | |
// End state |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// file: middlewares/tracingMethods.js | |
const { AsyncLocalStorage } = require("async_hooks"); | |
const { Utils } = require("moleculer"); | |
const storage = new AsyncLocalStorage(); | |
module.exports = { | |
name: "tracingMethods", | |
localAction(next) { | |
return ctx => { | |
if (this.isTracingEnabled()) { | |
const { span } = ctx; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const _ = require("lodash"); | |
const { ServiceSchemaError } = require("moleculer").Errors; | |
const { PrismaClient } = require("@prisma/client"); | |
class PrismaDbAdapter { | |
/** | |
* Creates an instance of PrismaDbAdapter. | |
* @param {any} opts | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
name: "lock", | |
settings: { | |
lock: { | |
ttl: 10e3 | |
} | |
}, | |
methods: { | |
/** | |
* Try lock key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const StateMachine = require("fsm-async"); | |
const chalk = require("chalk"); | |
class Semaphore extends StateMachine { | |
constructor() { | |
const transitionTable = { | |
initial: "init", | |
transitions: [ | |
{ ev: "init", from: "init", to: "red" }, | |
{ ev: "_red", from: "red", to: "fromRed" }, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { monitorEventLoopDelay } = require("perf_hooks"); | |
const { humanize } = require("moleculer/src/utils"); | |
module.exports = { | |
name: "perfhook", | |
created() { | |
this.perfhook = monitorEventLoopDelay({ resolution: 20 }); | |
this.perfhook.enable(); | |
}, | |
stopped() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
name: "test", | |
version: 1, | |
actions: { | |
test: { | |
ws: { | |
name: "test" | |
}, | |
async handler(ctx) { | |
const { user } = ctx.meta; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// file: models/Base.js | |
const { Model } = require("objection"); | |
module.exports = class BaseModel extends Model { | |
static get modelPaths() { | |
return [__dirname]; | |
} | |
static get useLimitInFirst() { | |
return true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { callbackify } = require("util"); | |
const { GracefulStopTimeoutError } = require("moleculer").Errors; | |
const { Message, Producer, Consumer } = require("redis-smq"); | |
const events = require("redis-smq/src/events"); | |
module.exports = function QueueMiddleware() { | |
const producers = new Map(); | |
const consumers = new Map(); | |
function gracefulShutdown(broker, items) { |
NewerOlder