@b613/utils
Advanced tools
Comparing version 1.0.0-beta4 to 1.0.0-beta5
@@ -1,5 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.findIndex = exports.remove = exports.identical = exports.include = exports.shuffle = exports.swapItems = exports.split = void 0; | ||
function split(array, limit) { | ||
export function split(array, limit) { | ||
const input = [...array]; | ||
@@ -15,8 +12,6 @@ if (limit <= 0) { | ||
} | ||
exports.split = split; | ||
function swapItems(array, from, to) { | ||
export function swapItems(array, from, to) { | ||
[array[from], array[to]] = [array[to], array[from]]; | ||
} | ||
exports.swapItems = swapItems; | ||
function shuffle(array) { | ||
export function shuffle(array) { | ||
for (let i = array.length - 1; i > 0; i--) { | ||
@@ -28,3 +23,2 @@ const j = Math.floor(Math.random() * (i + 1)); | ||
} | ||
exports.shuffle = shuffle; | ||
/** | ||
@@ -34,3 +28,3 @@ * Add `item` between array items | ||
*/ | ||
function include(array, item) { | ||
export function include(array, item) { | ||
return array.reduce((children, entry, index) => { | ||
@@ -44,4 +38,3 @@ children.push(entry); | ||
} | ||
exports.include = include; | ||
function identical(array1, array2) { | ||
export function identical(array1, array2) { | ||
if (!Array.isArray(array1) || !Array.isArray(array2)) { | ||
@@ -58,4 +51,3 @@ return false; | ||
} | ||
exports.identical = identical; | ||
function remove(array, itemToRemove) { | ||
export function remove(array, itemToRemove) { | ||
const index = array.findIndex((item) => item === itemToRemove); | ||
@@ -67,10 +59,8 @@ if (index > -1) { | ||
} | ||
exports.remove = remove; | ||
/** | ||
* Returns the index of the first element in the array, and -1 otherwise. | ||
*/ | ||
function findIndex(items, element) { | ||
export function findIndex(items, element) { | ||
return items.findIndex((currentItem) => currentItem === element); | ||
} | ||
exports.findIndex = findIndex; | ||
//# sourceMappingURL=array.js.map |
@@ -1,5 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.CircularList = void 0; | ||
class CircularList { | ||
export class CircularList { | ||
constructor(items) { | ||
@@ -29,3 +26,2 @@ this.index = 0; | ||
} | ||
exports.CircularList = CircularList; | ||
//# sourceMappingURL=CircularList.js.map |
@@ -1,12 +0,7 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createClient = void 0; | ||
const tslib_1 = require("tslib"); | ||
const axios_1 = tslib_1.__importDefault(require("axios")); | ||
const color_1 = tslib_1.__importDefault(require("./color")); | ||
const axios_cache_adapter_1 = require("axios-cache-adapter"); | ||
function createClient(baseURL, _a = {}) { | ||
var { headers = {}, logger, cache } = _a, options = tslib_1.__rest(_a, ["headers", "logger", "cache"]); | ||
const adapter = cache ? (0, axios_cache_adapter_1.setupCache)(cache).adapter : undefined; | ||
const instance = axios_1.default.create(Object.assign(Object.assign({}, options), { baseURL, headers, adapter })); | ||
import axios from 'axios'; | ||
import color from './color'; | ||
import { setupCache } from 'axios-cache-adapter'; | ||
export function createClient(baseURL, { headers = {}, logger, cache, ...options } = {}) { | ||
const adapter = cache ? setupCache(cache).adapter : undefined; | ||
const instance = axios.create({ ...options, baseURL, headers, adapter }); | ||
instance.interceptors.response.use((response) => { | ||
@@ -16,7 +11,7 @@ const method = response.request.method || 'GET'; | ||
if (response.status >= 400) { | ||
logger === null || logger === void 0 ? void 0 : logger.info(`${prefix} ${color_1.default.red(response.status)}`, 'HTTP'); | ||
logger === null || logger === void 0 ? void 0 : logger.info(`${prefix} ${color.red(response.status)}`, 'HTTP'); | ||
logger === null || logger === void 0 ? void 0 : logger.error(`Error ${response.status}: ${JSON.stringify(response.data, null, 2)}`); | ||
} | ||
else { | ||
logger === null || logger === void 0 ? void 0 : logger.info(`${prefix} ${color_1.default.green(response.status)}`, 'HTTP'); | ||
logger === null || logger === void 0 ? void 0 : logger.info(`${prefix} ${color.green(response.status)}`, 'HTTP'); | ||
} | ||
@@ -27,3 +22,2 @@ return response; | ||
} | ||
exports.createClient = createClient; | ||
//# sourceMappingURL=client.js.map |
@@ -1,6 +0,3 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
const cli_color_1 = tslib_1.__importDefault(require("cli-color")); | ||
exports.default = cli_color_1.default; | ||
import color from 'cli-color'; | ||
export default color; | ||
//# sourceMappingURL=color.node.js.map |
{ | ||
"name": "color", | ||
"main": "color.node", | ||
"browser": "color.browser" | ||
"type": "module", | ||
"exports": "./color.node.js", | ||
"browser": "./color.browser.js" | ||
} |
@@ -1,5 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.HTTP = exports.HttpError = exports.HttpStatus = void 0; | ||
class HttpStatus { | ||
export class HttpStatus { | ||
constructor(status, body = null) { | ||
@@ -13,4 +10,3 @@ this.statusCode = status; | ||
} | ||
exports.HttpStatus = HttpStatus; | ||
class HttpError extends Error { | ||
export class HttpError extends Error { | ||
constructor(status, body = null) { | ||
@@ -25,4 +21,3 @@ super(); | ||
} | ||
exports.HttpError = HttpError; | ||
exports.HTTP = { | ||
export const HTTP = { | ||
// 2xx success | ||
@@ -29,0 +24,0 @@ /** |
@@ -1,11 +0,7 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.resize = exports.pull = exports.parseBase64 = exports.parseMimeType = void 0; | ||
const tslib_1 = require("tslib"); | ||
const os_1 = tslib_1.__importDefault(require("os")); | ||
const promises_1 = tslib_1.__importDefault(require("fs/promises")); | ||
const jimp_1 = tslib_1.__importDefault(require("jimp")); | ||
const image_downloader_1 = tslib_1.__importDefault(require("image-downloader")); | ||
import os from 'node:os'; | ||
import fs from 'node:fs/promises'; | ||
import Jimp from 'jimp'; | ||
import download from 'image-downloader'; | ||
const REGEX = /^data:([a-zA-Z0-9]+\/[a-zA-Z0-9-.+]+);base64,(.+)/; | ||
function parseMimeType(base64) { | ||
export function parseMimeType(base64) { | ||
const matches = base64.match(REGEX); | ||
@@ -21,26 +17,17 @@ if (matches === null || matches === void 0 ? void 0 : matches.length) { | ||
} | ||
exports.parseMimeType = parseMimeType; | ||
function parseBase64(filename) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const image = yield promises_1.default.readFile(filename); | ||
return 'data:image/jpeg;base64,' + Buffer.from(image).toString('base64'); | ||
}); | ||
export async function parseBase64(filename) { | ||
const image = await fs.readFile(filename); | ||
return 'data:image/jpeg;base64,' + Buffer.from(image).toString('base64'); | ||
} | ||
exports.parseBase64 = parseBase64; | ||
function pull(_a) { | ||
var { dest = os_1.default.tmpdir(), extractFilename = true } = _a, options = tslib_1.__rest(_a, ["dest", "extractFilename"]); | ||
return image_downloader_1.default.image(Object.assign({ dest, extractFilename }, options)); | ||
export function pull({ dest = os.tmpdir(), extractFilename = true, ...options }) { | ||
return download.image({ dest, extractFilename, ...options }); | ||
} | ||
exports.pull = pull; | ||
function resize(filename, width, height = jimp_1.default.AUTO) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const image = yield jimp_1.default.read(filename); | ||
const newFilename = `${filename}.resized`; | ||
yield image.resize(width, height, jimp_1.default.RESIZE_BEZIER).writeAsync(newFilename); | ||
return { | ||
filename: newFilename, | ||
}; | ||
}); | ||
export async function resize(filename, width, height = Jimp.AUTO) { | ||
const image = await Jimp.read(filename); | ||
const newFilename = `${filename}.resized`; | ||
await image.resize(width, height, Jimp.RESIZE_BEZIER).writeAsync(newFilename); | ||
return { | ||
filename: newFilename, | ||
}; | ||
} | ||
exports.resize = resize; | ||
//# sourceMappingURL=image.node.js.map |
{ | ||
"name": "image", | ||
"main": "image.node", | ||
"browser": "image.browser" | ||
"type": "module", | ||
"exports": "./image.node.js", | ||
"browser": "./image.browser.js" | ||
} |
@@ -1,8 +0,4 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.random = void 0; | ||
function random(min, max) { | ||
export function random(min, max) { | ||
return Math.floor(Math.random() * (max - min + 1) + min); | ||
} | ||
exports.random = random; | ||
//# sourceMappingURL=number.js.map |
@@ -1,6 +0,3 @@ | ||
"use strict"; | ||
/* eslint-disable radar/cognitive-complexity */ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.toString = exports.del = exports.set = exports.get = exports.merge = exports.copy = exports.clear = exports.isEqual = exports.isEmpty = exports.isObject = exports.ToStringEscape = void 0; | ||
class ToStringEscape { | ||
export class ToStringEscape { | ||
constructor(value) { | ||
@@ -10,8 +7,6 @@ this.value = value; | ||
} | ||
exports.ToStringEscape = ToStringEscape; | ||
function isObject(object, strict = true) { | ||
export function isObject(object, strict = true) { | ||
return typeof object === 'object' && object !== null && (!strict || !Array.isArray(object)); | ||
} | ||
exports.isObject = isObject; | ||
function isEmpty(object) { | ||
export function isEmpty(object) { | ||
// eslint-disable-next-line no-unreachable-loop | ||
@@ -23,4 +18,3 @@ for (const key in object) { | ||
} | ||
exports.isEmpty = isEmpty; | ||
function isEqual(object1, object2) { | ||
export function isEqual(object1, object2) { | ||
if (object1 === object2) { | ||
@@ -47,7 +41,6 @@ return true; | ||
} | ||
exports.isEqual = isEqual; | ||
/** | ||
* Delete all object's properties | ||
*/ | ||
function clear(object) { | ||
export function clear(object) { | ||
for (const key in object) { | ||
@@ -57,4 +50,3 @@ delete object[key]; | ||
} | ||
exports.clear = clear; | ||
function copy(object) { | ||
export function copy(object) { | ||
if (typeof object !== 'object' || object === null) { | ||
@@ -83,7 +75,6 @@ return object; | ||
} | ||
exports.copy = copy; | ||
/** | ||
* Deep assign implementation (merge) | ||
*/ | ||
function merge(dest, src, strategy = 'append') { | ||
export function merge(dest, src, strategy = 'append') { | ||
if (isObject(dest) && isObject(src)) { | ||
@@ -112,4 +103,3 @@ for (const key in src) { | ||
} | ||
exports.merge = merge; | ||
function get(object, path) { | ||
export function get(object, path) { | ||
const paths = parsePath(path); | ||
@@ -120,4 +110,3 @@ return paths.length | ||
} | ||
exports.get = get; | ||
function set(object, path, value) { | ||
export function set(object, path, value) { | ||
return applyPaths(object, path, value, (result, o, key, val) => { | ||
@@ -130,4 +119,3 @@ if (result) { | ||
} | ||
exports.set = set; | ||
function del(object, path) { | ||
export function del(object, path) { | ||
return applyPaths(object, path, null, (result, o, key, val) => { | ||
@@ -140,3 +128,2 @@ if (result) { | ||
} | ||
exports.del = del; | ||
/** | ||
@@ -153,3 +140,3 @@ * Converts a JavaScript object or value to a JSON string with support of function value | ||
*/ | ||
function toString(object, space) { | ||
export function toString(object, space) { | ||
let index = 0; | ||
@@ -178,3 +165,2 @@ const cache = {}; | ||
} | ||
exports.toString = toString; | ||
function parsePath(path) { | ||
@@ -181,0 +167,0 @@ return path.split(/\./).filter((item) => item); |
@@ -1,6 +0,3 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ping = void 0; | ||
const net_1 = require("net"); | ||
function ping(urlString, { timeout = 30000, interval = 10000, retries = 3, logger } = {}) { | ||
import { createConnection } from 'node:net'; | ||
export function ping(urlString, { timeout = 30000, interval = 10000, retries = 3, logger } = {}) { | ||
let count = 1; | ||
@@ -26,3 +23,3 @@ let retrying = true; | ||
logger === null || logger === void 0 ? void 0 : logger.info(`Checking availability of service ${url.host} (${count})`); | ||
const socket = (0, net_1.createConnection)({ host: url.hostname, port, timeout }); | ||
const socket = createConnection({ host: url.hostname, port, timeout }); | ||
socket.on('connect', () => { | ||
@@ -49,3 +46,2 @@ retrying = false; | ||
} | ||
exports.ping = ping; | ||
//# sourceMappingURL=ping.js.map |
@@ -1,30 +0,20 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.all = exports.chain = void 0; | ||
const tslib_1 = require("tslib"); | ||
/** | ||
* Sequential promise execution | ||
*/ | ||
function chain(items, fn) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const results = []; | ||
yield items.reduce((task, item, index) => { | ||
return task | ||
.then(() => fn(item, index)) | ||
.then((result) => results.push(result)) | ||
.then(() => Promise.resolve()); | ||
}, Promise.resolve()); | ||
return results; | ||
}); | ||
export async function chain(items, fn) { | ||
const results = []; | ||
await items.reduce((task, item, index) => { | ||
return task | ||
.then(() => fn(item, index)) | ||
.then((result) => results.push(result)) | ||
.then(() => Promise.resolve()); | ||
}, Promise.resolve()); | ||
return results; | ||
} | ||
exports.chain = chain; | ||
/** | ||
* Parallel promise execution | ||
*/ | ||
function all(items, fn) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
return Promise.all(items.map((item, index) => fn(item, index))); | ||
}); | ||
export async function all(items, fn) { | ||
return Promise.all(items.map((item, index) => fn(item, index))); | ||
} | ||
exports.all = all; | ||
//# sourceMappingURL=promise.js.map |
@@ -1,4 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.stringify = void 0; | ||
function pushKeyPairs(items, keyPrefix, object) { | ||
@@ -36,3 +33,3 @@ for (const key in object) { | ||
*/ | ||
function stringify(object) { | ||
export function stringify(object) { | ||
const items = []; | ||
@@ -42,3 +39,2 @@ pushKeyPairs(items, '', object); | ||
} | ||
exports.stringify = stringify; | ||
//# sourceMappingURL=qs.js.map |
@@ -1,4 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.escapePattern = void 0; | ||
/** | ||
@@ -10,6 +7,5 @@ * Escape a pattern for a Regex | ||
*/ | ||
function escapePattern(pattern) { | ||
export function escapePattern(pattern) { | ||
return pattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); | ||
} | ||
exports.escapePattern = escapePattern; | ||
//# sourceMappingURL=regex.js.map |
@@ -1,10 +0,7 @@ | ||
"use strict"; | ||
/* eslint-disable radar/cognitive-complexity */ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.generateEmptyValue = void 0; | ||
const object_1 = require("./object"); | ||
import { isObject, merge } from './object.js'; | ||
const Filters = { | ||
object: (item) => typeof item === 'object' && item !== null, | ||
}; | ||
function generateEmptyValue(schema, useDefault = false) { | ||
export function generateEmptyValue(schema, useDefault = false) { | ||
var _a; | ||
@@ -25,3 +22,3 @@ if (useDefault) { | ||
.filter(Filters.object) | ||
.reduce((data, item) => (0, object_1.merge)(data, item), {}); | ||
.reduce((data, item) => merge(data, item), {}); | ||
} | ||
@@ -43,3 +40,3 @@ return dataItems[0]; | ||
const propSchema = schema.properties[prop]; | ||
if ((0, object_1.isObject)(propSchema) && (((_a = schema.required) === null || _a === void 0 ? void 0 : _a.includes(prop)) || 'default' in propSchema || 'const' in propSchema)) { | ||
if (isObject(propSchema) && (((_a = schema.required) === null || _a === void 0 ? void 0 : _a.includes(prop)) || 'default' in propSchema || 'const' in propSchema)) { | ||
object[prop] = generateEmptyValue(propSchema, useDefault); | ||
@@ -56,3 +53,2 @@ } | ||
} | ||
exports.generateEmptyValue = generateEmptyValue; | ||
//# sourceMappingURL=schema.js.map |
@@ -1,21 +0,17 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Server = exports.createApp = void 0; | ||
const tslib_1 = require("tslib"); | ||
const http_1 = tslib_1.__importDefault(require("http")); | ||
const https_1 = tslib_1.__importDefault(require("https")); | ||
const express_1 = tslib_1.__importDefault(require("express")); | ||
const morgan_1 = tslib_1.__importDefault(require("morgan")); | ||
const body_parser_1 = tslib_1.__importDefault(require("body-parser")); | ||
const ping_1 = require("./ping"); | ||
const Trace_1 = require("./Trace"); | ||
const http_2 = require("./http"); | ||
const promise_1 = require("./promise"); | ||
tslib_1.__exportStar(require("./http"), exports); | ||
exports.createApp = express_1.default; | ||
class Server { | ||
import http from 'node:http'; | ||
import https from 'node:https'; | ||
import express from 'express'; | ||
import logger from 'morgan'; | ||
import bodyParser from 'body-parser'; | ||
import { ping } from './ping.js'; | ||
import { Trace } from './Trace/trace.node.js'; | ||
import { HttpError } from './http.js'; | ||
import { all } from './promise.js'; | ||
export * from './http.js'; | ||
export const createApp = express; | ||
export class Server { | ||
constructor(options) { | ||
this.options = options; | ||
this.trace = new Trace_1.Trace(options.name); | ||
this.app = (0, exports.createApp)(); | ||
this.trace = new Trace(options.name); | ||
this.app = createApp(); | ||
this.app.disable('x-powered-by'); | ||
@@ -25,6 +21,6 @@ const loggerFormat = options.devMode | ||
: `:date[iso] ${options.name} HTTP - :remote-addr - :remote-user ":method :url HTTP/:http-version" :status :res[content-length] ":referrer" ":user-agent"`; | ||
this.app.use((0, morgan_1.default)(loggerFormat)); | ||
this.app.use(logger(loggerFormat)); | ||
} | ||
static createRouter() { | ||
return express_1.default.Router({ | ||
return express.Router({ | ||
strict: true, | ||
@@ -35,3 +31,3 @@ caseSensitive: false, | ||
static handleError(err, res, logger) { | ||
if (err instanceof http_2.HttpError) { | ||
if (err instanceof HttpError) { | ||
res.status(err.statusCode); | ||
@@ -63,86 +59,67 @@ if (err.body) { | ||
} | ||
_start() { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
this.trace.info(`Setting ${this.options.name} server...`); | ||
this.app.disable('x-powered-by'); | ||
this.app.route('/status') | ||
.head((req, res) => res.sendStatus(200)) | ||
.get((req, res) => res.json({ | ||
name: this.options.name, | ||
version: this.options.version, | ||
status: 'up', | ||
uptime: process.uptime(), | ||
})); | ||
this.app.set('port', this.options.port); | ||
yield this._prepare(); | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
this.app.use((err, req, res, next) => Server.handleError(err, res, this.trace)); | ||
this.server = this.options.certificat | ||
? https_1.default.createServer(this.options.certificat, this.app) | ||
: http_1.default.createServer(this.app); | ||
this.server.on('error', (error) => { | ||
if (error.syscall !== 'listen') { | ||
async _start() { | ||
this.trace.info(`Setting ${this.options.name} server...`); | ||
this.app.disable('x-powered-by'); | ||
this.app.route('/status') | ||
.head((req, res) => res.sendStatus(200)) | ||
.get((req, res) => res.json({ | ||
name: this.options.name, | ||
version: this.options.version, | ||
status: 'up', | ||
uptime: process.uptime(), | ||
})); | ||
this.app.set('port', this.options.port); | ||
await this._prepare(); | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
this.app.use((err, req, res, next) => Server.handleError(err, res, this.trace)); | ||
this.server = this.options.certificat | ||
? https.createServer(this.options.certificat, this.app) | ||
: http.createServer(this.app); | ||
this.server.on('error', (error) => { | ||
if (error.syscall !== 'listen') { | ||
throw error; | ||
} | ||
// handle specific listen errors with friendly messages | ||
switch (error.code) { | ||
case 'EACCES': | ||
this.trace.error(`${this.options.port} requires elevated privileges`); | ||
process.exit(-3); | ||
case 'EADDRINUSE': | ||
this.trace.error(`${this.options.port} is already in use`); | ||
process.exit(-4); | ||
default: | ||
throw error; | ||
} | ||
// handle specific listen errors with friendly messages | ||
switch (error.code) { | ||
case 'EACCES': | ||
this.trace.error(`${this.options.port} requires elevated privileges`); | ||
process.exit(-3); | ||
case 'EADDRINUSE': | ||
this.trace.error(`${this.options.port} is already in use`); | ||
process.exit(-4); | ||
default: | ||
throw error; | ||
} | ||
}); | ||
this.server.on('listening', () => this.trace.info(`Listening on ${this.options.port}`)); | ||
this.trace.info(`Starting ${this.options.name} server...`); | ||
this.server.listen(this.options.port, '0.0.0.0'); | ||
process.on('SIGINT', () => this.server.close(() => process.exit(0))); | ||
} | ||
}); | ||
this.server.on('listening', () => this.trace.info(`Listening on ${this.options.port}`)); | ||
this.trace.info(`Starting ${this.options.name} server...`); | ||
this.server.listen(this.options.port, '0.0.0.0'); | ||
process.on('SIGINT', () => this.server.close(() => process.exit(0))); | ||
} | ||
_prepare() { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { }); | ||
} | ||
start() { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
if (this.options.serviceDependencies instanceof Array) { | ||
try { | ||
yield (0, promise_1.all)(this.options.serviceDependencies, (dependency) => (0, ping_1.ping)(dependency, { | ||
timeout: 5000, | ||
interval: this.options.devMode ? 3000 : 5000, | ||
retries: this.options.devMode ? Number.MAX_SAFE_INTEGER : 10, | ||
logger: this.trace, | ||
})); | ||
} | ||
catch (err) { | ||
this.trace.error(err.message); | ||
this.trace.error('Starting aborted'); | ||
process.exit(-5); | ||
} | ||
async _prepare() { } | ||
async start() { | ||
if (this.options.serviceDependencies instanceof Array) { | ||
try { | ||
await all(this.options.serviceDependencies, (dependency) => ping(dependency, { | ||
timeout: 5000, | ||
interval: this.options.devMode ? 3000 : 5000, | ||
retries: this.options.devMode ? Number.MAX_SAFE_INTEGER : 10, | ||
logger: this.trace, | ||
})); | ||
} | ||
yield this._start(); | ||
}); | ||
catch (err) { | ||
this.trace.error(err.message); | ||
this.trace.error('Starting aborted'); | ||
process.exit(-5); | ||
} | ||
} | ||
await this._start(); | ||
} | ||
} | ||
exports.Server = Server; | ||
Server.parser = { | ||
/** | ||
* Parse incoming requests with JSON payloads and is based on body-parser | ||
*/ | ||
json: body_parser_1.default.json, | ||
/** | ||
* Parse incoming requests with Buffer payloads and is based on body-parser | ||
*/ | ||
raw: body_parser_1.default.raw, | ||
/** | ||
* Parse incoming requests with text payloads and is based on body-parser | ||
*/ | ||
text: body_parser_1.default.text, | ||
/** | ||
* Parse incoming requests with urlencoded payloads and is based on body-parser | ||
*/ | ||
urlencoded: body_parser_1.default.urlencoded, | ||
json: bodyParser.json, | ||
raw: bodyParser.raw, | ||
text: bodyParser.text, | ||
urlencoded: bodyParser.urlencoded, | ||
}; | ||
//# sourceMappingURL=Server.js.map |
@@ -1,4 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.unCamelCase = exports.toKebabCase = exports.trimlines = void 0; | ||
const RE_TRIMLINES = /(.+)(\n|\r\n)?/g; | ||
@@ -13,3 +10,3 @@ const CHAR_CODE_0 = '0'.charCodeAt(0); | ||
const CHAR_CODE_Z = 'Z'.charCodeAt(0); | ||
function trimlines(str, separator = '') { | ||
export function trimlines(str, separator = '') { | ||
let index = 0; | ||
@@ -27,4 +24,3 @@ const output = []; | ||
} | ||
exports.trimlines = trimlines; | ||
function toKebabCase(str) { | ||
export function toKebabCase(str) { | ||
const tokens = []; | ||
@@ -50,4 +46,3 @@ for (let index = 0; index < str.length; index++) { | ||
} | ||
exports.toKebabCase = toKebabCase; | ||
function unCamelCase(str, separator = ' ') { | ||
export function unCamelCase(str, separator = ' ') { | ||
const tokens = []; | ||
@@ -72,3 +67,2 @@ for (let index = 0; index < str.length; index++) { | ||
} | ||
exports.unCamelCase = unCamelCase; | ||
//# sourceMappingURL=string.js.map |
{ | ||
"name": "trace", | ||
"main": "trace.node", | ||
"browser": "trace.browser" | ||
"type": "module", | ||
"exports": "./trace.node.js", | ||
"browser": "./trace.browser.js" | ||
} |
@@ -1,7 +0,3 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Trace = void 0; | ||
const tslib_1 = require("tslib"); | ||
const color_1 = tslib_1.__importDefault(require("../color")); | ||
class Trace { | ||
import color from '../color/color.node.js'; | ||
export class Trace { | ||
constructor(name) { | ||
@@ -18,9 +14,8 @@ this.name = name; | ||
warn(msg, prefix = 'WARN') { | ||
process.stderr.write(this.parse(color_1.default.yellow(prefix), msg)); | ||
process.stderr.write(this.parse(color.yellow(prefix), msg)); | ||
} | ||
error(msg, prefix = 'ERROR') { | ||
process.stderr.write(this.parse(color_1.default.red(prefix), msg)); | ||
process.stderr.write(this.parse(color.red(prefix), msg)); | ||
} | ||
} | ||
exports.Trace = Trace; | ||
//# sourceMappingURL=trace.node.js.map |
{ | ||
"name": "@b613/utils", | ||
"version": "1.0.0-beta4", | ||
"version": "1.0.0-beta5", | ||
"description": "Set of utility methods for common operations", | ||
"license": "MIT", | ||
"exports": { | ||
"./array": "./lib/array.js", | ||
"./color": "./lib/color/color.node.js", | ||
"./CircularList": "./lib/CircularList.js", | ||
"./client": "./lib/client.js", | ||
"./image": "./lib/image/image.node.js", | ||
"./number": "./lib/number.js", | ||
"./object": "./lib/object.js", | ||
"./ping": "./lib/ping.js", | ||
"./promise": "./lib/promise.js", | ||
"./qs": "./lib/qs.js", | ||
"./regex": "./lib/regex.js", | ||
"./schema": "./lib/schema.js", | ||
"./Server": "./lib/Server.js", | ||
"./string": "./lib/string.js", | ||
"./Trace": "./lib/Trace/trace.node.js" | ||
}, | ||
"scripts": { | ||
"lint": "eslint .", | ||
"test": "jest --detectOpenHandles --coverage", | ||
"watch": "jest --detectOpenHandles --no-coverage --watchAll", | ||
"test": "NODE_OPTIONS=--experimental-vm-modules node_modules/.bin/jest --coverage", | ||
"watch": "NODE_OPTIONS=--experimental-vm-modules node_modules/.bin/jest --no-coverage --watchAll", | ||
"build": "rm -rf lib* && tsc && tsc -p tsconfig.browser.json && cp src/*.d.ts lib/ && mkdir -p libtmp && cp --parents src/*/package.json libtmp/ && cp -r libtmp/src/* lib/" | ||
@@ -34,3 +51,3 @@ }, | ||
"author": "Sébastien Demanou", | ||
"types": "typings.d.ts", | ||
"types": "./typings.d.ts", | ||
"dependencies": { | ||
@@ -60,5 +77,5 @@ "axios": "0.27.2", | ||
"eslint-plugin-radar": "^0.2.1", | ||
"jest": "28.0.3", | ||
"jest": "^28.1.0", | ||
"nock": "^13.2.4", | ||
"ts-jest": "28.0.1", | ||
"ts-jest": "28.0.3", | ||
"typescript": "^4.6.4" | ||
@@ -65,0 +82,0 @@ }, |
@@ -6,2 +6,3 @@ # Common Utils | ||
[![Test coverage](https://gitlab.com/demsking/xutils/badges/main/coverage.svg)](https://gitlab.com/demsking/xutils/pipelines) | ||
[![Buy me a beer](https://img.shields.io/badge/Buy%20me-a%20beer-1f425f.svg)](https://www.buymeacoffee.com/demsking) | ||
@@ -13,2 +14,5 @@ This package provides utility methods for common operations which cover a wide | ||
This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c) | ||
: Node 16+ is needed to use it and it must be imported instead of required. | ||
```sh | ||
@@ -20,20 +24,19 @@ npm install @b613/utils | ||
| Module | Documentation | | ||
| ------------------------------- | ----------------------------------------------------------------------------------------- | | ||
| `@b613/utils/lib/array` | [array.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/array.d.ts) | | ||
| `@b613/utils/lib/CircularList` | [CircularList.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/CircularList.d.ts) | | ||
| `@b613/utils/lib/client` | [client.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/client.d.ts) | | ||
| `@b613/utils/lib/color` | [color.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/color.d.ts) | | ||
| `@b613/utils/lib/http` | [http.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/http.d.ts) | | ||
| `@b613/utils/lib/image` | [image.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/image.d.ts) | | ||
| `@b613/utils/lib/number` | [number.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/number.d.ts) | | ||
| `@b613/utils/lib/object` | [object.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/object.d.ts) | | ||
| `@b613/utils/lib/ping` | [ping.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/ping.d.ts) | | ||
| `@b613/utils/lib/promise` | [promise.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/promise.d.ts) | | ||
| `@b613/utils/lib/qs` | [qs.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/qs.d.ts) | | ||
| `@b613/utils/lib/regex` | [regex.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/regex.d.ts) | | ||
| `@b613/utils/lib/schema` | [schema.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/schema.d.ts) | | ||
| `@b613/utils/lib/Server` | [Server.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/Server.d.ts) | | ||
| `@b613/utils/lib/string` | [string.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/string.d.ts) | | ||
| `@b613/utils/lib/Trace` | [Trace.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/Trace.d.ts) | | ||
| Module | Documentation | | ||
| --------------------------- | ----------------------------------------------------------------------------------------- | | ||
| `@b613/utils/array` | [array.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/array.d.ts) | | ||
| `@b613/utils/CircularList` | [CircularList.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/CircularList.d.ts) | | ||
| `@b613/utils/client` | [client.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/client.d.ts) | | ||
| `@b613/utils/color` | [color.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/color.d.ts) | | ||
| `@b613/utils/image` | [image.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/image.d.ts) | | ||
| `@b613/utils/number` | [number.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/number.d.ts) | | ||
| `@b613/utils/object` | [object.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/object.d.ts) | | ||
| `@b613/utils/ping` | [ping.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/ping.d.ts) | | ||
| `@b613/utils/promise` | [promise.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/promise.d.ts) | | ||
| `@b613/utils/qs` | [qs.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/qs.d.ts) | | ||
| `@b613/utils/regex` | [regex.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/regex.d.ts) | | ||
| `@b613/utils/schema` | [schema.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/schema.d.ts) | | ||
| `@b613/utils/Server` | [Server.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/Server.d.ts) | | ||
| `@b613/utils/string` | [string.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/string.d.ts) | | ||
| `@b613/utils/Trace` | [Trace.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/Trace.d.ts) | | ||
@@ -40,0 +43,0 @@ ## Development Setup |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 3 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
62
0
0
117541
1949