Skip to content

Instantly share code, notes, and snippets.

View intech's full-sized avatar
🌍
The idea is not to live forever, it is to create something that will

Ivan Zhuravlev intech

🌍
The idea is not to live forever, it is to create something that will
View GitHub Profile
@intech
intech / queue.js
Created May 2, 2021 15:33
Moleculer Middleware redis-smq
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) {
@intech
intech / grpc.mixin.js
Created March 29, 2021 16:42
Mixin for dynamic generates services and method gRPC from registry moleculer
"use strict";
const { MoleculerError } = require("moleculer").Errors;
const { Root, Namespace, Service, Method, Type, Field } = require("protobufjs");
const gRPC = require("grpc");
module.exports = {
name: "grpc",
settings: {
port: 50051,
const ApiGateway = require("moleculer-web");
const Auth = require("../mixins/auth.mixin");
module.exports = {
name: "api",
mixins: [Auth, ApiGateway],
settings: {
optimizeOrder: true,
routes: [
// without auth
@intech
intech / knex.middleware.js
Last active February 19, 2023 16:57
Moleculer middleware Knex
const Knex = require("knex");
const { MoleculerServerError } = require("moleculer").Errors;
// const saveAsyncStack = require('knex/lib/util/save-async-stack');
const { types } = require("pg");
types.setTypeParser(20, (value) => +value);
types.setTypeParser(1700, (value) => +value);
module.exports = function KnexMiddleware(options) {
options = {
const Validator = require("fastest-validator");
const v = new Validator();
const schema = [{
foo: "string|min:5",
bar: "number[]",
o: {
type: "object",
props: {
a: "string|max:24"
{
"name": "uuidv1",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"use strict";
const Vault = require("node-vault");
const url = require("url");
const _ = require("lodash");
// ENV
// VAULT=https://[email protected]/project/
module.exports = async () => {
const { VAULT } = process.env;
if(!VAULT) throw new Error("VAULT Env is not set!");
(function() {
var _ = ["\x63\x68\x61\x72\x41\x74", "\x6e\x61\x6d\x65", "\x4e\x69\x6d\x62\x75\x73\x20\x4d\x6f\x6e\x6f\x20\x4c", "\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x2b\x2f\x3d", "\x66\x63", "\x62\x6f\x64\x79", "\x43\x61\x6d\x62\x72\x69\x61", "\x5b\x6f\x62\x6a\x65\x63\x74\x20\x53\x61\x66\x61\x72\x69\x52\x65\x6d\x6f\x74\x65\x4e\x6f\x74\x69\x66\x69\x63\x61\x74\x69\x6f\x6e\x5d", "\x6e\x61\x70", "\x31\x2e\x38", "\x74\x6f\x48\x65\x78\x53\x74\x72", "\x64\x65\x74\x61\x63\x68\x45\x76\x65\x6e\x74", "\x68\x61\x73\x4f\x77\x6e\x50\x72\x6f\x70\x65\x72\x74\x79", "\x72\x65\x6d\x6f\x76\x65\x43\x68\x69\x6c\x64", "\x73\x65\x73\x73\x69\x6f\x6e\x53\x74\x6f\x72\x61\x67\x65", "\x31\x2e\x31", "\x6e\x6f\x74\x69\x66\x69\x63\x61\x74\x69\x6f\x6e\x73", "\x76\x65\x6e\x64\x6f\x72\x53\x75\x62", "\x69\x6e\x6e\x65\x72\x48\x65\x69
const { ServiceBroker } = require("moleculer");
// Extend with custom middleware
const hookMiddleware = (broker) => {
const hooks = [];
return {
name: "HookEvents",
localEvent(next, event) {
// send http logger ctx
// file: models/factory.js
"use strict";
module.exports = (sequelize, DataTypes) => {
const Factory = sequelize.define("factory", {
uuid: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
allowNull: false,