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.0 to 0.10.1

10

lib/Domain/Error/DomainError.d.ts
import { FilterNotStartsWith, FilterStartsWith, Result, StripPrefix } from '../../Util';
export declare function formatEntityErrorType(module: string, entityType: string, type: string): string;
export declare type standard_entity_error_types = 'duplicate' | 'not_found';
export type standard_entity_error_types = 'duplicate' | 'not_found';
export declare class EntityErrorTypeObject<ErrorTypes> {

@@ -16,14 +16,14 @@ private readonly typePrefix;

}
declare type EntityErrorTypes<T> = {
type EntityErrorTypes<T> = {
readonly [P in FilterStartsWith<keyof T, 'entity_'> as StripPrefix<P, 'entity_'>]: EntityErrorTypeObject<T[P]>;
};
declare type EntityErrorType<T extends DomainErrorsRaw> = {
type EntityErrorType<T extends DomainErrorsRaw> = {
readonly entity: EntityErrorTypes<T>;
};
declare type ErrorType<T extends DomainErrorsRaw> = {
type ErrorType<T extends DomainErrorsRaw> = {
readonly [P in FilterNotStartsWith<keyof T, 'entity_'>]: ErrorTypeObject & string;
};
declare type DomainErrorsRaw = Record<string, any>;
type DomainErrorsRaw = Record<string, any>;
export declare function DefineDomainErrors<T>(module: string, obj: T): ErrorType<T> & EntityErrorType<T>;
export {};
//# sourceMappingURL=DomainError.d.ts.map

@@ -1,7 +0,11 @@

import { ERR } from '../../Util';
import { pascalCaseToSnakeCase } from '../../Util/functions';
export function formatEntityErrorType(module, entityType, type) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DefineDomainErrors = exports.ErrorTypeObject = exports.EntityErrorTypeObject = exports.formatEntityErrorType = void 0;
const Util_1 = require("../../Util");
const functions_1 = require("../../Util/functions");
function formatEntityErrorType(module, entityType, type) {
return `${module}.domain.entity.${entityType}${type ? '_' + type : ''}`;
}
export class EntityErrorTypeObject {
exports.formatEntityErrorType = formatEntityErrorType;
class EntityErrorTypeObject {
typePrefix;

@@ -12,3 +16,3 @@ constructor(typePrefix) {

err(type, data) {
return ERR(this.t(type), type == 'not_found' ? 404 : 400, data);
return (0, Util_1.ERR)(this.t(type), type == 'not_found' ? 404 : 400, data);
}

@@ -19,3 +23,4 @@ t(type) {

}
export class ErrorTypeObject {
exports.EntityErrorTypeObject = EntityErrorTypeObject;
class ErrorTypeObject {
t;

@@ -29,7 +34,8 @@ constructor(t) {

err(data) {
return ERR(this.t, 400, data);
return (0, Util_1.ERR)(this.t, 400, data);
}
}
export function DefineDomainErrors(module, obj) {
module = pascalCaseToSnakeCase(module);
exports.ErrorTypeObject = ErrorTypeObject;
function DefineDomainErrors(module, obj) {
module = (0, functions_1.pascalCaseToSnakeCase)(module);
const moduleErrorTypePrefix = module + '.domain.';

@@ -51,1 +57,2 @@ const entityModuleErrorTypePrefix = module + '.domain.entity.';

}
exports.DefineDomainErrors = DefineDomainErrors;

@@ -1,2 +0,5 @@

export * from './Error/DomainError';
export * from './ValueObject';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
tslib_1.__exportStar(require("./Error/DomainError"), exports);
tslib_1.__exportStar(require("./ValueObject"), exports);
import { EmailHash } from './EmailHash';
import { RegexStringIdRawType, RegexStringValue } from './RegexStringValue';
export declare type EmailRawType = RegexStringIdRawType;
export type EmailRawType = RegexStringIdRawType;
export declare class Email extends RegexStringValue<Email> {

@@ -5,0 +5,0 @@ protected static getRegex(): RegExp;

@@ -1,7 +0,10 @@

import { __decorate } from "tslib";
import { ValueObject } from './ValueObject';
import { EmailHash } from './EmailHash';
import { RegexStringValue } from './RegexStringValue';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Email = void 0;
const tslib_1 = require("tslib");
const ValueObject_1 = require("./ValueObject");
const EmailHash_1 = require("./EmailHash");
const RegexStringValue_1 = require("./RegexStringValue");
const EMAIL_REGEX = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/i;
let Email = class Email extends RegexStringValue {
let Email = class Email extends RegexStringValue_1.RegexStringValue {
static getRegex() {

@@ -17,8 +20,8 @@ return EMAIL_REGEX;

get hash() {
return EmailHash.createFromEmail(this);
return EmailHash_1.EmailHash.createFromEmail(this);
}
};
Email = __decorate([
ValueObject('Core')
Email = tslib_1.__decorate([
(0, ValueObject_1.ValueObject)('Core')
], Email);
export { Email };
exports.Email = Email;
import { StringValue } from './StringValue';
import { Email } from './Email';
import { RegexStringIdRawType } from './RegexStringValue';
export declare type EmailHashRawType = RegexStringIdRawType;
export type EmailHashRawType = RegexStringIdRawType;
export declare class EmailHash extends StringValue<EmailHash> {

@@ -6,0 +6,0 @@ static createFromEmail(email: Email): EmailHash;

@@ -0,7 +1,10 @@

"use strict";
var EmailHash_1;
import { __decorate } from "tslib";
import { StringValue } from './StringValue';
import * as crypto from 'crypto';
import { ValueObject } from './ValueObject';
let EmailHash = EmailHash_1 = class EmailHash extends StringValue {
Object.defineProperty(exports, "__esModule", { value: true });
exports.EmailHash = void 0;
const tslib_1 = require("tslib");
const StringValue_1 = require("./StringValue");
const crypto = tslib_1.__importStar(require("crypto"));
const ValueObject_1 = require("./ValueObject");
let EmailHash = EmailHash_1 = class EmailHash extends StringValue_1.StringValue {
static createFromEmail(email) {

@@ -11,5 +14,5 @@ return new EmailHash_1(crypto.createHash('sha1').update(email.v).digest('hex'));

};
EmailHash = EmailHash_1 = __decorate([
ValueObject('Core')
EmailHash = EmailHash_1 = tslib_1.__decorate([
(0, ValueObject_1.ValueObject)('Core')
], EmailHash);
export { EmailHash };
exports.EmailHash = EmailHash;
import { AbstractValueObject } from './ValueObject';
import { Result } from '../../Util/Result';
export declare type ImmutableDateRawType = number;
export type ImmutableDateRawType = number;
export declare class ImmutableDate extends AbstractValueObject<ImmutableDate> {

@@ -5,0 +5,0 @@ private value;

@@ -0,6 +1,9 @@

"use strict";
var ImmutableDate_1;
import { __decorate, __metadata } from "tslib";
import { AbstractValueObject, ValueObject } from './ValueObject';
import { OK } from '../../Util/Result';
let ImmutableDate = ImmutableDate_1 = class ImmutableDate extends AbstractValueObject {
Object.defineProperty(exports, "__esModule", { value: true });
exports.ImmutableDate = void 0;
const tslib_1 = require("tslib");
const ValueObject_1 = require("./ValueObject");
const Result_1 = require("../../Util/Result");
let ImmutableDate = ImmutableDate_1 = class ImmutableDate extends ValueObject_1.AbstractValueObject {
value;

@@ -20,9 +23,9 @@ constructor(value) {

if (v instanceof Date) {
return OK(new this(new Date(v.getTime())));
return (0, Result_1.OK)(new this(new Date(v.getTime())));
}
try {
return OK(new this(new Date(v)));
return (0, Result_1.OK)(new this(new Date(v)));
}
catch (e) {
return AbstractValueObject.invalidRaw(ImmutableDate_1, {
return ValueObject_1.AbstractValueObject.invalidRaw(ImmutableDate_1, {
raw: v,

@@ -44,3 +47,3 @@ msg: 'invalid datetime format: ' + e.message,

if (timestamp < 0) {
return AbstractValueObject.invalidRaw(ImmutableDate_1, {
return ValueObject_1.AbstractValueObject.invalidRaw(ImmutableDate_1, {
raw: timestamp,

@@ -50,3 +53,3 @@ msg: 'invalid timestamp',

}
return OK(new this(new Date(timestamp * 1000)));
return (0, Result_1.OK)(new this(new Date(timestamp * 1000)));
}

@@ -69,6 +72,6 @@ get v() {

};
ImmutableDate = ImmutableDate_1 = __decorate([
ValueObject('Core'),
__metadata("design:paramtypes", [Date])
ImmutableDate = ImmutableDate_1 = tslib_1.__decorate([
(0, ValueObject_1.ValueObject)('Core'),
tslib_1.__metadata("design:paramtypes", [Date])
], ImmutableDate);
export { ImmutableDate };
exports.ImmutableDate = ImmutableDate;

@@ -1,10 +0,13 @@

export * from './ValueObject';
export * from './SimpleValueObject';
export * from './Email';
export * from './EmailHash';
export * from './MailContent';
export * from './ImmutableDate';
export * from './StringValue';
export * from './UBigIntValue';
export * from './UIntValue';
export * from './RegexStringValue';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
tslib_1.__exportStar(require("./ValueObject"), exports);
tslib_1.__exportStar(require("./SimpleValueObject"), exports);
tslib_1.__exportStar(require("./Email"), exports);
tslib_1.__exportStar(require("./EmailHash"), exports);
tslib_1.__exportStar(require("./MailContent"), exports);
tslib_1.__exportStar(require("./ImmutableDate"), exports);
tslib_1.__exportStar(require("./StringValue"), exports);
tslib_1.__exportStar(require("./UBigIntValue"), exports);
tslib_1.__exportStar(require("./UIntValue"), exports);
tslib_1.__exportStar(require("./RegexStringValue"), exports);

@@ -0,7 +1,10 @@

"use strict";
var MailContent_1;
import { __decorate, __metadata } from "tslib";
import { AbstractValueObject, ValueObject } from './ValueObject';
import V from '../../Util/Validator';
import { OK } from '../../Util/Result';
const checkValue = V.compile({
Object.defineProperty(exports, "__esModule", { value: true });
exports.MailContent = void 0;
const tslib_1 = require("tslib");
const ValueObject_1 = require("./ValueObject");
const Validator_1 = tslib_1.__importDefault(require("../../Util/Validator"));
const Result_1 = require("../../Util/Result");
const checkValue = Validator_1.default.compile({
subject: { type: 'string', min: 5, max: 100 },

@@ -11,3 +14,3 @@ html: { type: 'string', min: 100, max: 32000 },

});
let MailContent = MailContent_1 = class MailContent extends AbstractValueObject {
let MailContent = MailContent_1 = class MailContent extends ValueObject_1.AbstractValueObject {
subject;

@@ -25,5 +28,5 @@ html;

if (checkResult !== true) {
return AbstractValueObject.invalidRaw(this, checkResult.map((value) => value.message));
return ValueObject_1.AbstractValueObject.invalidRaw(this, checkResult.map((value) => value.message));
}
return OK(new MailContent_1(subject, html, text));
return (0, Result_1.OK)(new MailContent_1(subject, html, text));
}

@@ -40,6 +43,6 @@ equals(o) {

};
MailContent = MailContent_1 = __decorate([
ValueObject('Core'),
__metadata("design:paramtypes", [String, String, String])
MailContent = MailContent_1 = tslib_1.__decorate([
(0, ValueObject_1.ValueObject)('Core'),
tslib_1.__metadata("design:paramtypes", [String, String, String])
], MailContent);
export { MailContent };
exports.MailContent = MailContent;
import { Result } from '../../Util/Result';
import { StringValue } from './StringValue';
export declare type RegexStringIdRawType = string;
export declare type RegexStringSubtype<T> = {
export type RegexStringIdRawType = string;
export type RegexStringSubtype<T> = {
new (value: string): T;

@@ -6,0 +6,0 @@ getRegex(): RegExp;

@@ -1,8 +0,12 @@

import { OK } from '../../Util/Result';
import { AbstractValueObject } from './ValueObject';
import { StringValue } from './StringValue';
export class RegexStringValue extends StringValue {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RegexStringValue = void 0;
const Result_1 = require("../../Util/Result");
const ValueObject_1 = require("./ValueObject");
const StringValue_1 = require("./StringValue");
class RegexStringValue extends StringValue_1.StringValue {
static checkRawValue(value) {
return this.getRegex().test(value) ? OK(true) : AbstractValueObject.invalidRaw(this, { raw: value });
return this.getRegex().test(value) ? (0, Result_1.OK)(true) : ValueObject_1.AbstractValueObject.invalidRaw(this, { raw: value });
}
}
exports.RegexStringValue = RegexStringValue;
import { Result } from '../../Util/Result';
import { AbstractValueObject } from './ValueObject';
export declare type SimpleValueObjectConstructor<T, VT> = {
export type SimpleValueObjectConstructor<T, VT> = {
new (v: VT): T;

@@ -5,0 +5,0 @@ c<T extends SimpleValueObject<T, VT>>(this: SimpleValueObjectConstructor<T, VT>, value: any): Result<T>;

@@ -1,4 +0,7 @@

import { ERR, OK } from '../../Util/Result';
import { AbstractValueObject } from './ValueObject';
export class SimpleValueObject extends AbstractValueObject {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SimpleValueObject = void 0;
const Result_1 = require("../../Util/Result");
const ValueObject_1 = require("./ValueObject");
class SimpleValueObject extends ValueObject_1.AbstractValueObject {
v;

@@ -11,3 +14,3 @@ constructor(value) {

const checkResult = this.checkRawValue(value);
return checkResult.isError() ? ERR(checkResult.e) : OK(new this(value));
return checkResult.isError() ? (0, Result_1.ERR)(checkResult.e) : (0, Result_1.OK)(new this(value));
}

@@ -18,3 +21,3 @@ static cs(value) {

static checkRawValue(value) {
return OK(true);
return (0, Result_1.OK)(true);
}

@@ -31,1 +34,2 @@ equals(other) {

}
exports.SimpleValueObject = SimpleValueObject;

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

import { SimpleValueObject } from './SimpleValueObject';
export class StringValue extends SimpleValueObject {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.StringValue = void 0;
const SimpleValueObject_1 = require("./SimpleValueObject");
class StringValue extends SimpleValueObject_1.SimpleValueObject {
}
exports.StringValue = StringValue;
import { Result } from '../../Util';
import { SimpleValueObject, SimpleValueObjectConstructor } from './SimpleValueObject';
export declare type UBigIntValueConstructor<T> = SimpleValueObjectConstructor<T, bigint>;
export type UBigIntValueConstructor<T> = SimpleValueObjectConstructor<T, bigint>;
export declare class UBigIntValue<T extends UBigIntValue<any> = any> extends SimpleValueObject<T, bigint> {

@@ -5,0 +5,0 @@ static c<T extends SimpleValueObject<T, bigint>>(this: UBigIntValueConstructor<T>, value: any): Result<T>;

@@ -1,6 +0,9 @@

import { __decorate } from "tslib";
import { ERR, OK } from '../../Util';
import { SimpleValueObject } from './SimpleValueObject';
import { AbstractValueObject, ValueObject } from './ValueObject';
let UBigIntValue = class UBigIntValue extends SimpleValueObject {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.UBigIntValue = void 0;
const tslib_1 = require("tslib");
const Util_1 = require("../../Util");
const SimpleValueObject_1 = require("./SimpleValueObject");
const ValueObject_1 = require("./ValueObject");
let UBigIntValue = class UBigIntValue extends SimpleValueObject_1.SimpleValueObject {
static c(value) {

@@ -12,7 +15,7 @@ if (typeof value === 'string') {

catch (e) {
return AbstractValueObject.invalidRaw(this, { raw: value });
return ValueObject_1.AbstractValueObject.invalidRaw(this, { raw: value });
}
}
const checkResult = this.checkRawValue(value);
return checkResult.isError() ? ERR(checkResult.e) : OK(new this(value));
return checkResult.isError() ? (0, Util_1.ERR)(checkResult.e) : (0, Util_1.OK)(new this(value));
}

@@ -24,3 +27,3 @@ static cs(value) {

static checkRawValue(value) {
return value >= 0n ? OK(true) : AbstractValueObject.invalidRaw(this, { raw: value });
return value >= 0n ? (0, Util_1.OK)(true) : ValueObject_1.AbstractValueObject.invalidRaw(this, { raw: value });
}

@@ -34,5 +37,5 @@ toString() {

};
UBigIntValue = __decorate([
ValueObject('Core')
UBigIntValue = tslib_1.__decorate([
(0, ValueObject_1.ValueObject)('Core')
], UBigIntValue);
export { UBigIntValue };
exports.UBigIntValue = UBigIntValue;
import { Result } from '../../Util';
import { SimpleValueObject, SimpleValueObjectConstructor } from './SimpleValueObject';
export declare type UIntValueConstructor<T> = SimpleValueObjectConstructor<T, number>;
export type UIntValueConstructor<T> = SimpleValueObjectConstructor<T, number>;
export declare class UIntValue<T extends UIntValue<any> = any> extends SimpleValueObject<T, number> {

@@ -5,0 +5,0 @@ static c<T extends SimpleValueObject<T, number>>(this: UIntValueConstructor<T>, value: any): Result<T>;

@@ -1,6 +0,9 @@

import { __decorate } from "tslib";
import { ERR, OK } from '../../Util';
import { SimpleValueObject } from './SimpleValueObject';
import { AbstractValueObject, ValueObject } from './ValueObject';
let UIntValue = class UIntValue extends SimpleValueObject {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.UIntValue = void 0;
const tslib_1 = require("tslib");
const Util_1 = require("../../Util");
const SimpleValueObject_1 = require("./SimpleValueObject");
const ValueObject_1 = require("./ValueObject");
let UIntValue = class UIntValue extends SimpleValueObject_1.SimpleValueObject {
static c(value) {

@@ -12,7 +15,7 @@ if (typeof value === 'string') {

catch (e) {
return AbstractValueObject.invalidRaw(this, { raw: value });
return ValueObject_1.AbstractValueObject.invalidRaw(this, { raw: value });
}
}
const checkResult = this.checkRawValue(value);
return checkResult.isError() ? ERR(checkResult.e) : OK(new this(value));
return checkResult.isError() ? (0, Util_1.ERR)(checkResult.e) : (0, Util_1.OK)(new this(value));
}

@@ -26,3 +29,3 @@ static cs(value) {

static checkRawValue(value) {
return value >= 0 ? OK(true) : AbstractValueObject.invalidRaw(this, { raw: value });
return value >= 0 ? (0, Util_1.OK)(true) : ValueObject_1.AbstractValueObject.invalidRaw(this, { raw: value });
}

@@ -36,5 +39,5 @@ toString() {

};
UIntValue = __decorate([
ValueObject('Core')
UIntValue = tslib_1.__decorate([
(0, ValueObject_1.ValueObject)('Core')
], UIntValue);
export { UIntValue };
exports.UIntValue = UIntValue;

@@ -1,6 +0,9 @@

import { AppError, ERR, pascalCaseToSnakeCase } from '../../Util';
export const VALUE_OBJECT_META_PROPERTY = '__VOMETA';
export function ValueObject(moduleName) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AbstractValueObject = exports.checkEnumValueObject = exports.ValueObjectInvalidRawValueError = exports.ValueObject = exports.VALUE_OBJECT_META_PROPERTY = void 0;
const Util_1 = require("../../Util");
exports.VALUE_OBJECT_META_PROPERTY = '__VOMETA';
function ValueObject(moduleName) {
return function (constructor) {
constructor.prototype[VALUE_OBJECT_META_PROPERTY] = {
constructor.prototype[exports.VALUE_OBJECT_META_PROPERTY] = {
module: moduleName,

@@ -11,5 +14,6 @@ class: constructor.name,

}
export function ValueObjectInvalidRawValueError(meta, data = null) {
return new AppError({
type: pascalCaseToSnakeCase(meta.module) + '.domain.value_object.' + pascalCaseToSnakeCase(meta.class) + '.invalid_raw_value',
exports.ValueObject = ValueObject;
function ValueObjectInvalidRawValueError(meta, data = null) {
return new Util_1.AppError({
type: (0, Util_1.pascalCaseToSnakeCase)(meta.module) + '.domain.value_object.' + (0, Util_1.pascalCaseToSnakeCase)(meta.class) + '.invalid_raw_value',
data,

@@ -19,3 +23,4 @@ code: 400,

}
export function checkEnumValueObject(value, enumType, meta, data = null) {
exports.ValueObjectInvalidRawValueError = ValueObjectInvalidRawValueError;
function checkEnumValueObject(value, enumType, meta, data = null) {
if (!(value in enumType)) {

@@ -26,13 +31,15 @@ return ValueObjectInvalidRawValueError(meta, data);

}
export class AbstractValueObject {
exports.checkEnumValueObject = checkEnumValueObject;
class AbstractValueObject {
static createInvalidRawValueError(meta, data = null) {
return ValueObjectInvalidRawValueError(this.prototype[VALUE_OBJECT_META_PROPERTY], data);
return ValueObjectInvalidRawValueError(this.prototype[exports.VALUE_OBJECT_META_PROPERTY], data);
}
static invalidRaw(valueObjectClass, data = null) {
const meta = valueObjectClass.prototype[VALUE_OBJECT_META_PROPERTY];
const meta = valueObjectClass.prototype[exports.VALUE_OBJECT_META_PROPERTY];
if (!meta) {
throw new Error(VALUE_OBJECT_META_PROPERTY + " property isn't defined, add @ValueObject decorator to " + valueObjectClass.name);
throw new Error(exports.VALUE_OBJECT_META_PROPERTY + " property isn't defined, add @ValueObject decorator to " + valueObjectClass.name);
}
return ERR(ValueObjectInvalidRawValueError(meta, data));
return (0, Util_1.ERR)(ValueObjectInvalidRawValueError(meta, data));
}
}
exports.AbstractValueObject = AbstractValueObject;

@@ -1,2 +0,5 @@

export * from './Util';
export * from './Domain';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
tslib_1.__exportStar(require("./Util"), exports);
tslib_1.__exportStar(require("./Domain"), exports);

@@ -1,2 +0,2 @@

export declare type AppErrorProps = {
export type AppErrorProps = {
[P in keyof AppError]?: AppError[P];

@@ -3,0 +3,0 @@ };

@@ -0,4 +1,7 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isInternalError = exports.INTERNAL_ERROR = exports.isIgnoreError = exports.IGNORE_ERROR = exports.isAppError = exports.AppError = void 0;
const IGNORE_ERROR_TYPE = 'core.ignore_error';
const INTERNAL_ERROR_TYPE = 'core.internal_error';
export class AppError {
class AppError {
type;

@@ -34,12 +37,16 @@ code;

}
export function isAppError(value) {
exports.AppError = AppError;
function isAppError(value) {
return value instanceof AppError;
}
export function IGNORE_ERROR() {
exports.isAppError = isAppError;
function IGNORE_ERROR() {
return new AppError({ type: IGNORE_ERROR_TYPE });
}
export function isIgnoreError(e) {
exports.IGNORE_ERROR = IGNORE_ERROR;
function isIgnoreError(e) {
return e.type === IGNORE_ERROR_TYPE;
}
export function INTERNAL_ERROR(error) {
exports.isIgnoreError = isIgnoreError;
function INTERNAL_ERROR(error) {
return new AppError({

@@ -52,4 +59,6 @@ type: INTERNAL_ERROR_TYPE,

}
export function isInternalError(e) {
exports.INTERNAL_ERROR = INTERNAL_ERROR;
function isInternalError(e) {
return e.type === INTERNAL_ERROR_TYPE;
}
exports.isInternalError = isInternalError;
import { AppError, AppErrorProps } from './AppError';
import { Result } from './Result';
import { DropLastParam, ExtractIterableType } from './types';
export declare type ARP<T> = Promise<Result<T>>;
export declare type BoolAsyncResultPromise = Promise<Result<boolean>>;
export declare type SAR<U> = Result<U> | AsyncResult<U> | ARP<U>;
export declare type AR<T> = AsyncResult<T>;
declare type CastToIterable<T> = T extends Iterable<any> ? ExtractIterableType<T> : never;
export type ARP<T> = Promise<Result<T>>;
export type BoolAsyncResultPromise = Promise<Result<boolean>>;
export type SAR<U> = Result<U> | AsyncResult<U> | ARP<U>;
export type AR<T> = AsyncResult<T>;
type CastToIterable<T> = T extends Iterable<any> ? ExtractIterableType<T> : never;
export declare class AsyncResult<T> implements PromiseLike<Result<T>> {

@@ -10,0 +10,0 @@ readonly p: ARP<T>;

@@ -1,5 +0,8 @@

import { AppError, INTERNAL_ERROR } from './AppError';
import { isIterable } from './functions';
import { ERR, INTERNAL_ERR, OK } from './Result';
export class AsyncResult {
"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;
const AppError_1 = require("./AppError");
const functions_1 = require("./functions");
const Result_1 = require("./Result");
class AsyncResult {
p;

@@ -11,11 +14,11 @@ callbackThis;

static fromSafePromise(promise) {
const newPromise = promise.then((value) => OK(value));
const newPromise = promise.then((value) => (0, Result_1.OK)(value));
return new AsyncResult(newPromise);
}
static fromPromise(promise, errorFn) {
errorFn = errorFn ?? ((e) => INTERNAL_ERROR(e));
errorFn = errorFn ?? ((e) => (0, AppError_1.INTERNAL_ERROR)(e));
const newPromise = promise
.then((value) => OK(value))
.then((value) => (0, Result_1.OK)(value))
.catch((e) => {
return ERR(errorFn(e));
return (0, Result_1.ERR)(errorFn(e));
});

@@ -25,7 +28,7 @@ return new AsyncResult(newPromise);

static fromPromiseOkTrue(promise, errorFn) {
errorFn = errorFn ?? ((e) => INTERNAL_ERROR(e));
errorFn = errorFn ?? ((e) => (0, AppError_1.INTERNAL_ERROR)(e));
const newPromise = promise
.then(() => OK(true))
.then(() => (0, Result_1.OK)(true))
.catch((e) => {
return ERR(errorFn(e));
return (0, Result_1.ERR)(errorFn(e));
});

@@ -44,5 +47,5 @@ return new AsyncResult(newPromise).mapToTrue();

if (res.isError()) {
return ERR(res.e);
return (0, Result_1.ERR)(res.e);
}
return OK(await f(res.v));
return (0, Result_1.OK)(await f(res.v));
}));

@@ -56,5 +59,5 @@ }

if (res.isSuccess()) {
return OK(res.v);
return (0, Result_1.OK)(res.v);
}
return ERR(await f(res.e));
return (0, Result_1.ERR)(await f(res.e));
}));

@@ -65,7 +68,7 @@ }

if (res.isError()) {
return ERR(res.e);
return (0, Result_1.ERR)(res.e);
}
const newValue = f(res.v);
if (!newValue) {
return INTERNAL_ERR(new Error('Callback must always return some Result: ' + f.toString()));
return (0, Result_1.INTERNAL_ERR)(new Error('Callback must always return some Result: ' + f.toString()));
}

@@ -77,4 +80,4 @@ return newValue instanceof AsyncResult ? newValue.p : newValue;

return this.onOk(async (it) => {
if (!isIterable(it)) {
return INTERNAL_ERR(new Error('Result value is not Iterable'));
if (!(0, functions_1.isIterable)(it)) {
return (0, Result_1.INTERNAL_ERR)(new Error('Result value is not Iterable'));
}

@@ -95,3 +98,3 @@ const list = [];

}
return OK(list);
return (0, Result_1.OK)(list);
});

@@ -114,3 +117,3 @@ }

}
return OK(res.v);
return (0, Result_1.OK)(res.v);
}));

@@ -128,17 +131,22 @@ }

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

@@ -1,7 +0,10 @@

import { ImmutableDate } from '../Domain';
export class CurrentTime {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CurrentTime = void 0;
const Domain_1 = require("../Domain");
class CurrentTime {
static i;
constNow;
get now() {
return this.constNow ?? ImmutableDate.now();
return this.constNow ?? Domain_1.ImmutableDate.now();
}

@@ -12,2 +15,3 @@ set now(now) {

}
exports.CurrentTime = CurrentTime;
CurrentTime.i = new CurrentTime();

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

export declare const INVALID_PLAIN_OBJECT_ERROR_TYPE = "core.dto.invalid_plain_object";
export declare type DtoBaseConstructor<T extends DtoBase> = {
export type DtoBaseConstructor<T extends DtoBase> = {
new (props?: Partial<T>): T;

@@ -8,0 +8,0 @@ };

@@ -1,11 +0,15 @@

import { instanceToPlain, plainToInstance, Transform, TransformationType } from 'class-transformer';
import { INTERNAL_ERROR } from './AppError';
import { ERR, OK, Result } from './Result';
export const INVALID_PLAIN_OBJECT_ERROR_TYPE = 'core.dto.invalid_plain_object';
export const TT = TransformationType;
export const isPT = (type) => type === TransformationType.CLASS_TO_PLAIN;
export function ValueObjectTransformer(t) {
return Transform(({ value, type }) => {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DtoBase = exports.BigIntTransformer = exports.DtoTransformer = exports.ValueObjectTransformer = exports.isPT = exports.TT = exports.INVALID_PLAIN_OBJECT_ERROR_TYPE = void 0;
const class_transformer_1 = require("class-transformer");
const AppError_1 = require("./AppError");
const Result_1 = require("./Result");
exports.INVALID_PLAIN_OBJECT_ERROR_TYPE = 'core.dto.invalid_plain_object';
exports.TT = class_transformer_1.TransformationType;
const isPT = (type) => type === class_transformer_1.TransformationType.CLASS_TO_PLAIN;
exports.isPT = isPT;
function ValueObjectTransformer(t) {
return (0, class_transformer_1.Transform)(({ value, type }) => {
if (value) {
if (isPT(type)) {
if ((0, exports.isPT)(type)) {
return Array.isArray(value) ? value.map((v) => v.toJSON()) : value.toJSON();

@@ -20,6 +24,7 @@ }

}
export function DtoTransformer(t) {
return Transform(({ value, type }) => {
exports.ValueObjectTransformer = ValueObjectTransformer;
function DtoTransformer(t) {
return (0, class_transformer_1.Transform)(({ value, type }) => {
if (value) {
if (isPT(type)) {
if ((0, exports.isPT)(type)) {
return Array.isArray(value) ? value.map((v) => v.toJSON()) : value.toJSON();

@@ -34,6 +39,7 @@ }

}
export function BigIntTransformer() {
return Transform(({ value, type }) => {
exports.DtoTransformer = DtoTransformer;
function BigIntTransformer() {
return (0, class_transformer_1.Transform)(({ value, type }) => {
if (value) {
if (isPT(type)) {
if ((0, exports.isPT)(type)) {
return Array.isArray(value) ? value.map((v) => v.toString()) : value.toString();

@@ -48,3 +54,4 @@ }

}
export class DtoBase {
exports.BigIntTransformer = BigIntTransformer;
class DtoBase {
static cs(props) {

@@ -57,7 +64,7 @@ const i = new this();

try {
const i = plainToInstance(this, plain);
const i = (0, class_transformer_1.plainToInstance)(this, plain);
return this.processFromPlain(i);
}
catch (e) {
return ERR(INTERNAL_ERROR(e));
return (0, Result_1.ERR)((0, AppError_1.INTERNAL_ERROR)(e));
}

@@ -69,3 +76,3 @@ }

const v = i[p];
if (v instanceof Result) {
if (v instanceof Result_1.Result) {
if (v.isError()) {

@@ -80,3 +87,3 @@ errors.push(v.e);

if (errors.length > 0) {
return ERR(INVALID_PLAIN_OBJECT_ERROR_TYPE, 400, {
return (0, Result_1.ERR)(exports.INVALID_PLAIN_OBJECT_ERROR_TYPE, 400, {
className: this.name,

@@ -86,7 +93,8 @@ errors,

}
return OK(i);
return (0, Result_1.OK)(i);
}
toJSON() {
return instanceToPlain(this);
return (0, class_transformer_1.instanceToPlain)(this);
}
}
exports.DtoBase = DtoBase;

@@ -1,5 +0,9 @@

export function isIterable(obj) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.pascalCaseToCamelCase = exports.pascalCaseToSnakeCase = exports.getClassMethods = exports.isIterable = void 0;
function isIterable(obj) {
return typeof obj[Symbol.iterator] === 'function';
}
export function getClassMethods(obj) {
exports.isIterable = isIterable;
function getClassMethods(obj) {
const properties = new Set();

@@ -12,7 +16,10 @@ let currentObj = obj;

}
export function pascalCaseToSnakeCase(s) {
exports.getClassMethods = getClassMethods;
function pascalCaseToSnakeCase(s) {
return s.replace(/(?:^|\.?)([A-Z])/g, (_x, y) => '_' + y.toLowerCase()).replace(/^_/, '');
}
export function pascalCaseToCamelCase(s) {
exports.pascalCaseToSnakeCase = pascalCaseToSnakeCase;
function pascalCaseToCamelCase(s) {
return s.charAt(0).toLowerCase() + s.slice(1);
}
exports.pascalCaseToCamelCase = pascalCaseToCamelCase;

@@ -1,9 +0,12 @@

export * from './AppError';
export * from './Result';
export * from './AsyncResult';
export * from './Validator';
export * from './SanitizeHelper';
export * from './functions';
export * from './types';
export * from './CurrentTime';
export * from './DtoBase';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
tslib_1.__exportStar(require("./AppError"), exports);
tslib_1.__exportStar(require("./Result"), exports);
tslib_1.__exportStar(require("./AsyncResult"), exports);
tslib_1.__exportStar(require("./Validator"), exports);
tslib_1.__exportStar(require("./SanitizeHelper"), exports);
tslib_1.__exportStar(require("./functions"), exports);
tslib_1.__exportStar(require("./types"), exports);
tslib_1.__exportStar(require("./CurrentTime"), exports);
tslib_1.__exportStar(require("./DtoBase"), exports);
import { AppError, AppErrorProps } from './AppError';
import { AR } from './AsyncResult';
export declare type R<T> = Result<T>;
export declare type ExtractInnerResultType<P> = P extends Result<infer T> ? T : never;
export type R<T> = Result<T>;
export type ExtractInnerResultType<P> = P extends Result<infer T> ? T : never;
export declare class Result<T> {

@@ -6,0 +6,0 @@ private readonly value;

@@ -1,4 +0,7 @@

import { AppError, INTERNAL_ERROR } from './AppError';
import { ERRA } from './AsyncResult';
export class Result {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.INTERNAL_ERR = exports.ERR = exports.OK = exports.Result = void 0;
const AppError_1 = require("./AppError");
const AsyncResult_1 = require("./AsyncResult");
class Result {
value;

@@ -21,3 +24,3 @@ constructor(value) {

}
return OK(fn(this.value));
return (0, exports.OK)(fn(this.value));
}

@@ -32,3 +35,3 @@ onOk(fn) {

if (this.isError()) {
return ERRA(this.value);
return (0, AsyncResult_1.ERRA)(this.value);
}

@@ -38,3 +41,3 @@ return fn(this.value);

isError() {
return this.value instanceof AppError;
return this.value instanceof AppError_1.AppError;
}

@@ -51,3 +54,3 @@ get e() {

}
return ERR(fn(this.value));
return (0, exports.ERR)(fn(this.value));
}

@@ -72,6 +75,7 @@ onErr(fn) {

}
return OK(values);
return (0, exports.OK)(values);
}
}
export const OK = (v) => {
exports.Result = Result;
const OK = (v) => {
if (v instanceof Result) {

@@ -82,14 +86,17 @@ return v;

};
export const ERR = (error, code = 400, data) => {
exports.OK = OK;
const ERR = (error, code = 400, data) => {
let e;
if (typeof error === 'string') {
e = new AppError({ type: error, code, data });
e = new AppError_1.AppError({ type: error, code, data });
}
else {
e = error instanceof AppError ? error : new AppError(error);
e = error instanceof AppError_1.AppError ? error : new AppError_1.AppError(error);
}
return new Result(e);
};
export const INTERNAL_ERR = (error) => {
return ERR(INTERNAL_ERROR(error));
exports.ERR = ERR;
const INTERNAL_ERR = (error) => {
return (0, exports.ERR)((0, AppError_1.INTERNAL_ERROR)(error));
};
exports.INTERNAL_ERR = INTERNAL_ERR;

@@ -1,6 +0,11 @@

import xss from 'xss';
export class SanitizeHelper {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SanitizeHelper = void 0;
const tslib_1 = require("tslib");
const xss_1 = tslib_1.__importDefault(require("xss"));
class SanitizeHelper {
static sanitizeText(dirty) {
return xss(dirty);
return (0, xss_1.default)(dirty);
}
}
exports.SanitizeHelper = SanitizeHelper;

@@ -1,10 +0,10 @@

export declare type DeepPartial<T> = Partial<{
export type DeepPartial<T> = Partial<{
[P in keyof T]: DeepPartial<T[P]>;
}>;
export declare type Head<T extends any[]> = T extends [...infer Head, any] ? Head : any[];
export declare type DropLastParam<F extends (...args: any) => any> = Head<Parameters<F>>;
export declare type FilterNotStartsWith<Set, Needle extends string> = Set extends `${Needle}${infer _X}` ? never : Set;
export declare type FilterStartsWith<Set, Needle extends string> = Set extends `${Needle}${infer _X}` ? Set : never;
export declare type StripPrefix<T extends string, prefix extends string> = T extends `${prefix}${infer Prefix}` ? Prefix : never;
export declare type ExtractIterableType<T extends Iterable<any>> = T extends Iterable<infer U> ? U : T;
export type Head<T extends any[]> = T extends [...infer Head, any] ? Head : any[];
export type DropLastParam<F extends (...args: any) => any> = Head<Parameters<F>>;
export type FilterNotStartsWith<Set, Needle extends string> = Set extends `${Needle}${infer _X}` ? never : Set;
export type FilterStartsWith<Set, Needle extends string> = Set extends `${Needle}${infer _X}` ? Set : never;
export type StripPrefix<T extends string, prefix extends string> = T extends `${prefix}${infer Prefix}` ? Prefix : never;
export type ExtractIterableType<T extends Iterable<any>> = T extends Iterable<infer U> ? U : T;
//# sourceMappingURL=types.d.ts.map

@@ -1,1 +0,2 @@

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

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

import Validator from 'fastest-validator';
const V = new Validator();
export default V;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const fastest_validator_1 = tslib_1.__importDefault(require("fastest-validator"));
const V = new fastest_validator_1.default();
exports.default = V;
{
"name": "@hexancore/common",
"version": "0.10.0",
"version": "0.10.1",
"engines": {
"node": ">=16"
"node": ">=18"
},

@@ -38,2 +38,3 @@ "engine-strict": true,

"nanoid": "^3.1.28",
"tslib": "^2.5.0",
"uuid": "^8.3.1",

@@ -45,3 +46,3 @@ "xss": "^1.0.10"

"@types/jest": "27.0.*",
"@types/node": "^16.0",
"@types/node": "^18.0",
"@typescript-eslint/eslint-plugin": "^5.5.0",

@@ -56,3 +57,3 @@ "@typescript-eslint/parser": "^5.5.0",

"ts-jest": "27.0.*",
"typescript": "4.3.5"
"typescript": "4.9.5"
},

@@ -59,0 +60,0 @@ "jest": {

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

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