Socket
Socket
Sign inDemoInstall

@hexancore/common

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hexancore/common - npm Package Compare versions

Comparing version 0.10.3 to 0.10.4

lib/Application/ApplicationErrors.d.ts

0

lib/Domain/Error/DomainError.d.ts

@@ -0,0 +0,0 @@ import { FilterNotStartsWith, FilterStartsWith, Result, StripPrefix } from '../../Util';

@@ -0,0 +0,0 @@ "use strict";

2

lib/Domain/index.d.ts

@@ -1,3 +0,3 @@

export * from './Error/DomainError';
export * from './Error/DomainErrors';
export * from './ValueObject';
//# sourceMappingURL=index.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
tslib_1.__exportStar(require("./Error/DomainError"), exports);
tslib_1.__exportStar(require("./Error/DomainErrors"), exports);
tslib_1.__exportStar(require("./ValueObject"), exports);

@@ -0,0 +0,0 @@ import { EmailHash } from './EmailHash';

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ import { StringValue } from './StringValue';

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ import { AbstractValueObject } from './ValueObject';

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ export * from './ValueObject';

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ import { AbstractValueObject } from './ValueObject';

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ import { Result } from '../../Util/Result';

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ import { Result } from '../../Util/Result';

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ import { SimpleValueObject } from './SimpleValueObject';

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ import { Result } from '../../Util';

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ import { Result } from '../../Util';

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ import { AppError, Result } from '../../Util';

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ export * from './Util';

@@ -0,0 +0,0 @@ "use strict";

import { AppError } from '../Util/AppError';
import { LogContext, Logger, LogLevel, LogMessage, LogTags } from './Logger';
import { LogContext, Logger, LogLevel, LogMessage, LogTags, LogTagsFactory } from './Logger';
export interface LoggerGlobalOptions {
debug: boolean;
silent: boolean;
}
export declare abstract class AbstractLogger implements Logger {
protected isDebug: boolean;
protected silent: boolean;
constructor(isDebug: boolean, silent: boolean);
protected channel: string;
protected tags: Exclude<LogTags, LogTagsFactory>;
constructor(channel: string, tags?: Exclude<LogTags, LogTagsFactory>);
private static globalOptions;
static setGlobalOptions(options: LoggerGlobalOptions): void;
log(levelOrAppError: LogLevel | AppError, messageOrTags?: LogMessage | LogTags, context?: LogContext, tags?: LogTags): void;

@@ -11,3 +17,3 @@ protected canLog(level: LogLevel): boolean;

protected processContext(context?: LogContext): Record<string, any>;
protected abstract pushRecord(level: LogLevel, message: string, context?: Record<string, any>, tags?: string[]): void;
protected abstract pushRecord(level: LogLevel, message: string, context: Record<string, any>, tags: string[]): void;
protected processMessage(message: LogMessage, context?: Record<string, any>): string;

@@ -14,0 +20,0 @@ protected processTags(context?: Record<string, any>, tags?: LogTags): string[];

@@ -7,10 +7,14 @@ "use strict";

class AbstractLogger {
isDebug;
silent;
constructor(isDebug, silent) {
this.isDebug = isDebug;
this.silent = silent;
channel;
tags;
constructor(channel, tags = []) {
this.channel = channel;
this.tags = tags;
}
log(levelOrAppError, messageOrTags, context, tags = []) {
if (this.silent) {
static globalOptions;
static setGlobalOptions(options) {
this.globalOptions = options;
}
log(levelOrAppError, messageOrTags, context, tags) {
if (AbstractLogger.globalOptions.silent) {
return;

@@ -35,5 +39,5 @@ }

canLog(level) {
return (level === 'debug' && this.isDebug) || true;
return (level === 'debug' && AbstractLogger.globalOptions.debug) || true;
}
logAppError(error, tags = []) {
logAppError(error, tags) {
const record = error.getLogRecord();

@@ -44,3 +48,3 @@ if (!this.canLog(record.level)) {

tags = this.processTags(record.context, tags);
this.pushRecord(record.level, record.message, record.context, tags);
this.pushRecord(record.level, record.message, { context: record.context, channel: this.channel }, tags);
}

@@ -52,3 +56,3 @@ processContext(context) {

}
return context;
return { context: context ?? {}, channel: this.channel };
}

@@ -59,3 +63,7 @@ processMessage(message, context) {

processTags(context, tags) {
return typeof tags === 'function' ? tags(context) : tags;
tags = typeof tags === 'function' ? tags(context) : tags;
if (tags) {
return [...this.tags, ...tags];
}
return this.tags;
}

@@ -62,0 +70,0 @@ debug(message, context, tags) {

@@ -1,11 +0,9 @@

/// <reference types="node" />
import { LambdaLog } from 'lambda-log';
import { AbstractLogger } from './AbstractLogger';
import { Logger, LogLevel, LogTags, LogTagsFactory } from './Logger';
export declare class ConsoleLogger extends AbstractLogger {
private w;
protected constructor(w: LambdaLog);
static create(name: string, tags: Exclude<LogTags, LogTagsFactory>, logHandler?: Console): Logger;
protected pushRecord(level: LogLevel, message: string, context?: Record<string, any>, tags?: string[]): void;
private static handler;
private static getHandler;
static create(channel: string, tags: Exclude<LogTags, LogTagsFactory>): Logger;
protected pushRecord(level: LogLevel, message: string, context: Record<string, any>, tags: string[]): void;
}
//# sourceMappingURL=ConsoleLogger.d.ts.map

@@ -8,31 +8,30 @@ "use strict";

class ConsoleLogger extends AbstractLogger_1.AbstractLogger {
w;
constructor(w) {
super(w.options.debug, w.options.silent);
this.w = w;
static handler;
static getHandler() {
if (this.handler === undefined) {
const appMeta = AppMeta_1.AppMeta.get();
this.handler = new lambda_log_1.LambdaLog({
dev: appMeta.logPretty,
debug: appMeta.debug,
silent: appMeta.logSilent,
meta: { app_id: appMeta.id, app_env: appMeta.env },
levelKey: 'level',
tagsKey: 'tags',
messageKey: 'message',
dynamicMeta: () => {
return {
timestamp: new Date().toISOString(),
};
},
});
}
return this.handler;
}
static create(name, tags, logHandler) {
const appMeta = AppMeta_1.AppMeta.get();
const native = new lambda_log_1.LambdaLog({
dev: appMeta.logPretty,
debug: appMeta.debug,
silent: appMeta.logSilent,
meta: { channel: name, app_id: appMeta.id, app_env: appMeta.env },
tags,
levelKey: 'level',
tagsKey: 'tags',
messageKey: 'message',
dynamicMeta: () => {
return {
timestamp: new Date().toISOString(),
};
},
logHandler,
});
return new this(native);
static create(channel, tags) {
return new this(channel, tags);
}
pushRecord(level, message, context, tags) {
this.w.log(level, message, { context }, tags);
ConsoleLogger.getHandler().log(level, message, context, tags);
}
}
exports.ConsoleLogger = ConsoleLogger;

@@ -0,0 +0,0 @@ export * from './Logger';

@@ -0,0 +0,0 @@ "use strict";

@@ -15,3 +15,3 @@ import { AppError } from '../Util/AppError';

context: Record<string, any>;
tags?: string[];
tags: string[];
}

@@ -18,0 +18,0 @@ export interface Logger {

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ import { Logger, LogTags } from './Logger';

@@ -9,2 +9,3 @@ "use strict";

const TestLogger_1 = require("./TestLogger");
const AbstractLogger_1 = require("./AbstractLogger");
class LoggerManager {

@@ -37,2 +38,3 @@ loggerProvider;

}
AbstractLogger_1.AbstractLogger.setGlobalOptions({ debug: appMeta.debug, silent: appMeta.logSilent });
switch (appMeta.env) {

@@ -39,0 +41,0 @@ case 'dev':

@@ -0,0 +0,0 @@ import { AppError } from '../Util/AppError';

@@ -0,0 +0,0 @@ "use strict";

import { LogLevel, LogRecord } from '../Util';
import { AbstractLogger } from './AbstractLogger';
export declare class TestLogger extends AbstractLogger {
readonly name: any;
readonly tags: string[];
records: Array<LogRecord>;
constructor(name: any, tags: string[]);
protected pushRecord(level: LogLevel, message: string, context?: Record<string, any>, tags?: string[]): void;
protected pushRecord(level: LogLevel, message: string, context: Record<string, any>, tags: string[]): void;
clear(): void;
}
//# sourceMappingURL=TestLogger.d.ts.map

@@ -6,12 +6,5 @@ "use strict";

class TestLogger extends AbstractLogger_1.AbstractLogger {
name;
tags;
records = [];
constructor(name, tags) {
super(true, false);
this.name = name;
this.tags = tags;
}
pushRecord(level, message, context, tags) {
this.records.push({ level, message, context, tags });
this.records.push({ level, message, context: context.context, tags });
}

@@ -18,0 +11,0 @@ clear() {

@@ -0,0 +0,0 @@ import { LogLevel, LogRecord } from '.';

@@ -0,0 +0,0 @@ "use strict";

@@ -14,7 +14,8 @@ export interface AppMetaProps {

export type EnvType = 'dev' | 'test' | 'prod';
export type AppMetaPropsProvider = () => AppMetaProps;
export type AppMetaProvider = () => AppMetaProps;
export declare class AppMeta implements AppMetaProps {
private props;
private static instance;
static propsProvider: AppMetaPropsProvider;
protected static instance: AppMeta;
protected static provider?: AppMetaProvider;
static setProvider(p: AppMetaProvider): void;
readonly env: EnvType;

@@ -29,3 +30,3 @@ readonly id: string;

readonly envFilePath: string;
readonly extra: Record<string, any>;
readonly extra: Readonly<Record<string, any>>;
private constructor();

@@ -37,4 +38,5 @@ static get(): AppMeta;

isProd(): boolean;
static checkEnvIsValid(env: string, errorMessage: string): void;
}
export declare const envAppMetaProvider: AppMetaPropsProvider;
export declare const EnvAppMetaProvider: AppMetaProvider;
//# sourceMappingURL=AppMeta.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.envAppMetaProvider = exports.AppMeta = void 0;
exports.EnvAppMetaProvider = exports.AppMeta = void 0;
const process_1 = require("process");
const Error_1 = require("./Error");
const functions_1 = require("./functions");

@@ -9,3 +10,13 @@ class AppMeta {

static instance;
static propsProvider;
static provider;
static setProvider(p) {
if (this.provider === undefined) {
this.provider = p;
}
else {
if (!this.get().isTest()) {
throw new Error_1.LogicError('AppMeta.provider can be sets once');
}
}
}
env;

@@ -36,6 +47,6 @@ id;

if (AppMeta.instance === undefined) {
if (AppMeta.propsProvider === undefined) {
if (AppMeta.provider === undefined) {
throw Error('AppMeta.instanceFactory is not sets before first get() call, check your code');
}
AppMeta.instance = new AppMeta(AppMeta.propsProvider());
AppMeta.instance = new AppMeta(AppMeta.provider());
}

@@ -56,11 +67,19 @@ return AppMeta.instance;

}
static checkEnvIsValid(env, errorMessage) {
if (['dev', 'test', 'prod'].indexOf(env) === -1) {
throw new Error(errorMessage);
}
}
}
exports.AppMeta = AppMeta;
const envAppMetaProvider = () => {
return {
env: process.env.NODE_ENV,
id: process.env.APP_ID ?? 'App',
version: process.env.APP_VERSION ?? 'latest',
debug: (0, functions_1.parseBoolean)(process.env.APP_DEBUG),
logPretty: (0, functions_1.parseBoolean)(process.env.APP_LOG_PRETTY),
const EnvAppMetaProvider = () => {
const env = (0, functions_1.getEnvOrError)('APP_ENV');
AppMeta.checkEnvIsValid(env, 'Invalid env.APP_ENV: ' + env);
const isProd = env === 'prod';
const props = {
env: env,
id: (0, functions_1.getEnvOrError)('APP_ID'),
version: isProd ? (0, functions_1.getEnvOrError)('APP_VERSION') : 'latest',
debug: (0, functions_1.parseBoolean)(process.env.APP_DEBUG, isProd ? false : true),
logPretty: (0, functions_1.parseBoolean)(process.env.APP_LOG_PRETTY, !isProd),
logSilent: (0, functions_1.parseBoolean)(process.env.APP_LOG_SILENT),

@@ -72,3 +91,4 @@ ci: (0, functions_1.parseBoolean)(process.env.CI),

};
return props;
};
exports.envAppMetaProvider = envAppMetaProvider;
exports.EnvAppMetaProvider = EnvAppMetaProvider;

@@ -33,3 +33,4 @@ import { AppError, AppErrorCode, AppErrorProps } from './AppError';

export declare const ERRA: <T>(error: AppError | AppErrorProps | string, code?: AppErrorCode, data?: any) => AR<T>;
export declare const ERRAP: <T>(error: AppError | AppErrorProps | string, code?: number, data?: any) => ARP<T>;
export declare const ERRAP: <T>(error: AppError | AppErrorProps | string, code?: AppErrorCode, data?: any) => ARP<T>;
export declare const INTERNAL_ERRA: <T>(error: Error) => AR<T>;
export declare const P: typeof AsyncResult.fromPromise;

@@ -36,0 +37,0 @@ export declare const PS: typeof AsyncResult.fromSafePromise;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PB = exports.PS = exports.P = exports.ERRAP = exports.ERRA = exports.OKAP = exports.OKA = exports.AsyncResult = void 0;
exports.PB = exports.PS = exports.P = exports.INTERNAL_ERRA = exports.ERRAP = exports.ERRA = exports.OKAP = exports.OKA = exports.AsyncResult = void 0;
const AppError_1 = require("./AppError");

@@ -129,16 +129,13 @@ const functions_1 = require("./functions");

const ERRA = (error, code = AppError_1.AppErrorCode.BAD_REQUEST, data) => {
let e;
if (typeof error === 'string') {
e = new AppError_1.AppError({ type: error, code, data });
}
else {
e = error instanceof AppError_1.AppError ? error : new AppError_1.AppError(error);
}
return new AsyncResult(Promise.resolve((0, Result_1.ERR)(error)));
return new AsyncResult(Promise.resolve((0, Result_1.ERR)(error, code, data)));
};
exports.ERRA = ERRA;
const ERRAP = (error, code = 400, data) => (0, exports.ERRA)(error, code, data).p;
const ERRAP = (error, code = AppError_1.AppErrorCode.BAD_REQUEST, data) => (0, exports.ERRA)(error, code, data).p;
exports.ERRAP = ERRAP;
const INTERNAL_ERRA = (error) => {
return new AsyncResult(Promise.resolve((0, Result_1.INTERNAL_ERR)(error)));
};
exports.INTERNAL_ERRA = INTERNAL_ERRA;
exports.P = AsyncResult.fromPromise;
exports.PS = AsyncResult.fromSafePromise;
exports.PB = AsyncResult.fromPromiseOkTrue;

@@ -0,0 +0,0 @@ import { ImmutableDate } from '../Domain';

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ import { AbstractValueObject } from '@/Domain';

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ export interface ErrorPlain {

@@ -0,0 +0,0 @@ "use strict";

export * from './ErrorHelper';
export * from './LogicError';
export * from './MissingError';
export * from './ErrorEnum';
//# sourceMappingURL=index.d.ts.map

@@ -6,1 +6,3 @@ "use strict";

tslib_1.__exportStar(require("./LogicError"), exports);
tslib_1.__exportStar(require("./MissingError"), exports);
tslib_1.__exportStar(require("./ErrorEnum"), exports);
export declare class LogicError extends Error {
}
//# sourceMappingURL=LogicError.d.ts.map

@@ -0,0 +0,0 @@ "use strict";

@@ -5,3 +5,5 @@ export declare function isIterable(obj: any): boolean;

export declare function pascalCaseToCamelCase(s: string): string;
export declare function parseBoolean(value: string | undefined): boolean;
export declare function parseBoolean(value: string | undefined, defaultValue?: boolean): boolean;
export declare function getEnvOrError(name: string): string;
export declare function wrapToArray<T>(value: T | T[]): T[];
//# sourceMappingURL=functions.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseBoolean = exports.pascalCaseToCamelCase = exports.pascalCaseToSnakeCase = exports.getClassMethods = exports.isIterable = void 0;
exports.wrapToArray = exports.getEnvOrError = exports.parseBoolean = exports.pascalCaseToCamelCase = exports.pascalCaseToSnakeCase = exports.getClassMethods = exports.isIterable = void 0;
const Error_1 = require("./Error");
function isIterable(obj) {

@@ -25,5 +26,5 @@ return typeof obj[Symbol.iterator] === 'function';

exports.pascalCaseToCamelCase = pascalCaseToCamelCase;
function parseBoolean(value) {
function parseBoolean(value, defaultValue = false) {
if (value === undefined) {
return false;
return defaultValue;
}

@@ -33,1 +34,13 @@ return new Boolean(parseInt(value)).valueOf();

exports.parseBoolean = parseBoolean;
function getEnvOrError(name) {
const value = process.env[name];
if (value === undefined) {
throw new Error_1.MissingError(`Missing env.${name}`);
}
return value;
}
exports.getEnvOrError = getEnvOrError;
function wrapToArray(value) {
return Array.isArray(value) ? value : [value];
}
exports.wrapToArray = wrapToArray;

@@ -0,0 +0,0 @@ export * from './AppError';

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ import { AppError, AppErrorProps } from './AppError';

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ export declare class SanitizeHelper {

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ export type DeepPartial<T> = Partial<{

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

@@ -0,0 +0,0 @@ import Validator from 'fastest-validator';

@@ -0,0 +0,0 @@ "use strict";

{
"name": "@hexancore/common",
"version": "0.10.3",
"version": "0.10.4",
"engines": {

@@ -44,3 +44,3 @@ "node": ">=18"

"devDependencies": {
"@hexcore/mocker": "*",
"@hexancore/mocker": "*",
"@types/jest": "27.0.*",

@@ -91,2 +91,2 @@ "@types/lambda-log": "^3.0.0",

}
}
}

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc