Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@borodindmitriy/base-code

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@borodindmitriy/base-code - npm Package Compare versions

Comparing version
4.2.3
to
4.3.0
+19
lib/interfaces/IValidateResult.d.ts
import { ILog } from "./ILog";
import { IValidate } from "./IValidate";
export interface IValidateResult<V extends IValidate = IValidate> {
results: V[];
isValid: boolean;
hasError: boolean;
hasWarn: boolean;
hasLog: boolean;
hasInfo: boolean;
messages: string[];
log: ILog[];
getFieldValidation(field: string): V | void;
getFieldMessage(a_field: string): string;
hasFieldError(field: string): boolean;
toValidate(): V[];
toJS(): {
[key: string]: any;
};
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
import { ILog } from "../interfaces/ILog";
import { ILogType } from "../interfaces/ILogType";
import { IValidate } from "../interfaces/IValidate";
import { Log } from "./Log";
export declare class Validate extends Log implements IValidate {
readonly field: string;
readonly title?: string;
constructor(data?: {
field?: string;
title?: string;
type?: ILogType;
message?: string;
});
readonly log: ILog;
toJS(): {
[key: string]: any;
};
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const isType_1 = require("../utils/isType");
const Log_1 = require("./Log");
// tslint:disable-next-line:max-classes-per-file
class Validate extends Log_1.Log {
constructor(data) {
super(data);
if (data) {
if (isType_1.isString(data.field)) {
this.field = data.field;
}
else {
throw new Error(`[ ${this.constructor.name} ][ field ][ MUST_BE_A_STRING ]`);
}
if (!isType_1.isUndefined(data.title)) {
if (isType_1.isString(data.title)) {
this.title = data.title;
}
else {
throw new Error(`[ ${this.constructor.name} ][ title ][ MUST_BE_A_STRING ]`);
}
}
}
Object.freeze(this);
}
get log() {
return new Log_1.Log({ type: this.type, message: this.message });
}
toJS() {
return Object.assign({}, super.toJS(), { field: this.field, title: this.title });
}
}
exports.Validate = Validate;
+1
-1
import { History } from "history";
import { IForm } from "../interfaces/IForm";
import { IPersist } from "../interfaces/IPersist";
import { IValidateResult } from "../interfaces/IValidate";
import { IValidateResult } from "../interfaces/IValidateResult";
import { IEditComposition } from "./interfaces/IEditComposition";

@@ -6,0 +6,0 @@ import { IRepository } from "./interfaces/IRepository";

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

import { IValidateResult } from "../../interfaces/IValidate";
import { IValidateResult } from "../../interfaces/IValidateResult";
import { IComposition } from "./IComposition";

@@ -3,0 +3,0 @@ export interface IEditComposition<CHANGE> extends IComposition {

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

import { IValidateResult } from "../../interfaces/IValidate";
import { IValidateResult } from "../../interfaces/IValidateResult";
/**

@@ -3,0 +3,0 @@ * IFormStore - для данных которые не имеют сущностей в системе.

@@ -5,3 +5,3 @@ import { IForm } from "../interfaces/IForm";

import { IUser } from "../interfaces/IUser";
import { IValidateResult } from "../interfaces/IValidate";
import { IValidateResult } from "../interfaces/IValidateResult";
import { IMediator } from "./interfaces/IMediator";

@@ -8,0 +8,0 @@ import { IRepository } from "./interfaces/IRepository";

@@ -67,3 +67,3 @@ "use strict";

this.form = this.openAssign(persist);
this.setIsValid(this.form.validate().isValid);
this.setIsValid(this.validate.isValid);
}

@@ -76,2 +76,3 @@ else {

this.form = this.openAssign();
this.setIsValid(false);
}

@@ -83,4 +84,3 @@ }

this.form = this.changeAssign(this.form, change);
const { isValid } = this.form.validate();
this.setIsValid(isValid);
this.setIsValid(this.validate.isValid);
}

@@ -94,2 +94,3 @@ else {

return tslib_1.__awaiter(this, void 0, void 0, function* () {
this.setIsValid(this.validate.isValid);
if (this.ACL.save.includes(this.group)) {

@@ -154,4 +155,22 @@ if (this.isValid) {

tslib_1.__decorate([
mobx_1.action
mobx_1.action("[ REPOSITORY_FORM_STORE ][ SET_IS_VALID ]")
], RepositoryFormStore.prototype, "setIsValid", null);
tslib_1.__decorate([
mobx_1.action("[ REPOSITORY_FORM_STORE ][ OPEN ]")
], RepositoryFormStore.prototype, "open", null);
tslib_1.__decorate([
mobx_1.action("[ REPOSITORY_FORM_STORE ][ CHANGE ]")
], RepositoryFormStore.prototype, "change", null);
tslib_1.__decorate([
mobx_1.action("[ REPOSITORY_FORM_STORE ][ SAVE ]")
], RepositoryFormStore.prototype, "save", null);
tslib_1.__decorate([
mobx_1.action("[ REPOSITORY_FORM_STORE ][ CANCEL ]")
], RepositoryFormStore.prototype, "cancel", null);
tslib_1.__decorate([
mobx_1.action("[ REPOSITORY_FORM_STORE ][ OPEN_ASSIGN ]")
], RepositoryFormStore.prototype, "openAssign", null);
tslib_1.__decorate([
mobx_1.action("[ REPOSITORY_FORM_STORE ][ CHANGE_ASSIGN ]")
], RepositoryFormStore.prototype, "changeAssign", null);
exports.RepositoryFormStore = RepositoryFormStore;

@@ -6,4 +6,5 @@ export { IPersist } from "./interfaces/IPersist";

export { IUserGroup } from "./interfaces/IUserGroup";
export { IValidateResult, IValidate } from "./interfaces/IValidate";
export { IValidate } from "./interfaces/IValidate";
export { IValidateResult } from "./interfaces/IValidateResult";
export { ILog } from "./interfaces/ILog";
export { ILogType } from "./interfaces/ILogType";
import { IInsert } from "./IInsert";
import { IValidateResult } from "./IValidate";
import { IValidateResult } from "./IValidateResult";
export interface IForm<VR extends IValidateResult = IValidateResult> extends IInsert {

@@ -4,0 +4,0 @@ id: string | void;

@@ -5,2 +5,5 @@ import { ILogType } from "../interface";

message: string;
toJS(): {
[key: string]: any;
};
}
import { ILog } from "./ILog";
export interface IValidateResult<V extends IValidate = IValidate> {
isValid: boolean;
messages: string[];
results: V[];
log: ILog[];
getFieldValidation(field: string): V | void;
getFieldMessage(a_field: string): string;
hasFieldError(field: string): boolean;
}
export interface IValidate extends ILog {

@@ -15,2 +6,5 @@ field: string;

log: ILog;
toJS(): {
[key: string]: any;
};
}
export { EventEmitter } from "./isomorphic/EventEmitter";
export { User } from "./isomorphic/user/User";
export { UserInsert } from "./isomorphic/user/UserInsert";
export { ValidateResult, Validate } from "./isomorphic/ValidateResult";
export { ValidateResult } from "./isomorphic/ValidateResult";
export { Validate } from "./isomorphic/Validate";
export { Log } from "./isomorphic/Log";

@@ -11,4 +11,5 @@ "use strict";

exports.ValidateResult = ValidateResult_1.ValidateResult;
exports.Validate = ValidateResult_1.Validate;
var Validate_1 = require("./isomorphic/Validate");
exports.Validate = Validate_1.Validate;
var Log_1 = require("./isomorphic/Log");
exports.Log = Log_1.Log;

@@ -6,3 +6,9 @@ import { ILog } from "../interfaces/ILog";

readonly message: string;
constructor(data: ILog);
constructor(data?: {
type?: ILogType;
message?: string;
});
toJS(): {
[key: string]: any;
};
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const isType_1 = require("../utils/isType");
class Log {
constructor(data) {
this.type = data.type;
this.message = data.message;
if (data) {
if (isType_1.isString(data.type)) {
this.type = data.type;
}
else {
throw new Error(`[ ${this.constructor.name} ][ type ][ MUST_BE_A_STRING ]`);
}
if (isType_1.isString(data.message)) {
this.message = data.message;
}
else {
throw new Error(`[ ${this.constructor.name} ][ message ][ MUST_BE_A_STRING ]`);
}
}
Object.freeze(this);
}
toJS() {
return {
message: this.message,
type: this.type,
};
}
}
exports.Log = Log;
import { ILog } from "../interfaces/ILog";
import { ILogType } from "../interfaces/ILogType";
import { IValidate, IValidateResult } from "../interfaces/IValidate";
import { Log } from "./Log";
import { IValidate } from "../interfaces/IValidate";
import { IValidateResult } from "../interfaces/IValidateResult";
export declare class ValidateResult<V extends IValidate = IValidate> implements IValidateResult<V> {
readonly results: V[];
constructor(results: V[]);
readonly isValid: boolean;
readonly hasError: boolean;
readonly hasWarn: boolean;
readonly hasLog: boolean;
readonly hasInfo: boolean;
readonly messages: string[];
readonly log: ILog[];
private readonly __CACHE__;
constructor(results: V[]);
getFieldValidation(a_field: string): V | void;
getFieldMessage(a_field: string): string;
hasFieldError(a_field: string): boolean;
toValidate(): V[];
toJS(): {
[key: string]: any;
};
}
export declare class Validate extends Log implements IValidate {
readonly field: string;
readonly title?: string;
constructor(data: {
field: string;
title?: string;
type: ILogType;
message: string;
});
readonly log: ILog;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Log_1 = require("./Log");
const logTypeEnum_1 = require("../enums/logTypeEnum");
const Validate_1 = require("./Validate");
// tslint:disable:object-literal-sort-keys
class ValidateResult {
constructor(results) {
this.results = results;
this.__CACHE__ = {};
let hasError = false;
let hasWarn = false;
let hasLog = false;
let hasInfo = false;
const messages = [];
const log = [];
for (const r of results) {
if (r.type === logTypeEnum_1.logTypeEnum.error) {
hasError = true;
}
if (r.type === logTypeEnum_1.logTypeEnum.warn) {
hasWarn = true;
}
if (r.type === logTypeEnum_1.logTypeEnum.log) {
hasLog = true;
}
if (r.type === logTypeEnum_1.logTypeEnum.info) {
hasInfo = true;
}
messages.push(r.message);
log.push(Object.freeze(r.log));
}
Object.defineProperties(this, {
results: {
value: results.map((r) => Object.freeze(r)),
},
isValid: {
value: results.length === 0,
},
hasError: {
value: hasError,
},
hasWarn: {
value: hasWarn,
},
hasLog: {
value: hasLog,
},
hasInfo: {
value: hasInfo,
},
messages: {
value: messages,
},
log: {
value: log,
},
});
}
get isValid() {
return this.results.length === 0;
}
get messages() {
return this.results.map(({ message }) => message);
}
get log() {
return this.results.map((v) => v.log);
}
getFieldValidation(a_field) {
return this.results.find(({ field }) => a_field === field);
let result = this.__CACHE__[a_field];
if (result) {
return result;
}
result = this.results.find(({ field }) => a_field === field);
this.__CACHE__[a_field] = result;
return result;
}
getFieldMessage(a_field) {
const v = this.getFieldValidation(a_field);
if (v instanceof Validate) {
if (v instanceof Validate_1.Validate) {
return v.message;

@@ -30,15 +77,9 @@ }

}
}
exports.ValidateResult = ValidateResult;
// tslint:disable-next-line:max-classes-per-file
class Validate extends Log_1.Log {
constructor(data) {
super(data);
this.field = data.field;
this.title = data.title;
toValidate() {
return this.results.map((r) => r);
}
get log() {
return new Log_1.Log({ type: this.type, message: this.message });
toJS() {
return this.results.map((r) => r.toJS());
}
}
exports.Validate = Validate;
exports.ValidateResult = ValidateResult;
{
"name": "@borodindmitriy/base-code",
"description": "Common classes's library.",
"version": "4.2.3",
"version": "4.3.0",
"engines": {

@@ -6,0 +6,0 @@ "node": ">=8",