Commit 4480e2c5 by Vladislav Lagunov

Исправления во время рефакторинга Кабинета Оператора

parent 1ce33da2
...@@ -14,10 +14,10 @@ ...@@ -14,10 +14,10 @@
следующим образом следующим образом
``` ```
- import { Eff, eff, ... } from '@bitmaster/core'; - import { Eff, eff, ... } from '~/common/core';
+ import { Eff, eff, ... } from './src/common/core'; + import { Eff, eff, ... } from './src/common/core';
- import { pgettxt, Gettext, ... } from '@bitmaster/utils/gettext'; - import { pgettxt, Gettext, ... } from '~/common/utils/gettext';
+ import { pgettxt, Gettext, ... } from './src/common/utils/gettext; + import { pgettxt, Gettext, ... } from './src/common/utils/gettext;
- import Pagination from '@bitmaster/components/Pagination'; - import Pagination from '@bitmaster/components/Pagination';
......
import * as t from '../decoder'; import * as t from '../decoder';
import * as camelCase from 'lodash/camelCase'; import { camelCase } from 'lodash';
import { absurd } from '../types'; import { absurd } from '../types';
import { WithDefault, RecordDecoder, Decoder } from '../decoder'; import { WithDefault, RecordDecoder, Decoder } from '../decoder';
import { Either } from '../either'; import { Either } from '../either';
......
...@@ -412,8 +412,8 @@ export const literals = variants; ...@@ -412,8 +412,8 @@ export const literals = variants;
* Кортежи разных размеров. Проверяемое значение необязательно должно * Кортежи разных размеров. Проверяемое значение необязательно должно
* быть массивом * быть массивом
* ```ts * ```ts
* const pair = t.tuple(t.string, t.number); * const pair = t.tuple(t.string, t.float);
* const pair_2 = t.record({ '0': t.string, '1': t.number }); // тоже самое * const pair_2 = t.record({ '0': t.string, '1': t.float }); // тоже самое
* ``` * ```
*/ */
// @ts-ignore // @ts-ignore
...@@ -513,7 +513,7 @@ export function doValidate<A>(decoder: Decoder<A>, value: unknown): Either<Probl ...@@ -513,7 +513,7 @@ export function doValidate<A>(decoder: Decoder<A>, value: unknown): Either<Probl
let iter = value as any; let iter = value as any;
decoder._path.forEach(k => DecoderBase.path.push(k + '')); decoder._path.forEach(k => DecoderBase.path.push(k + ''));
for (let i in decoder._path) { for (let i in decoder._path) {
if (iter === undefined || !iter.hasOwnProperty(decoder._path[i])) { if (!iter || !iter.hasOwnProperty(decoder._path[i])) {
iter = undefined; iter = undefined;
break; break;
} }
...@@ -525,10 +525,10 @@ export function doValidate<A>(decoder: Decoder<A>, value: unknown): Either<Probl ...@@ -525,10 +525,10 @@ export function doValidate<A>(decoder: Decoder<A>, value: unknown): Either<Probl
if (decoder instanceof Primitive) { if (decoder instanceof Primitive) {
switch (decoder._type) { switch (decoder._type) {
case 'null': return value === null ? Either.of(value as A) : Either.failure(projectProblem(`expected null, got ${fancyTypeOf(value)}`)); case 'null': return value === null ? Either.of<any>(value) : Either.failure(projectProblem(`expected null, got ${fancyTypeOf(value)}`));
case 'undefined': return value === undefined ? Either.of(value as A) : Either.failure(projectProblem(`expected undefined, got ${fancyTypeOf(value)}`)); case 'undefined': return value === undefined ? Either.of<any>(value) : Either.failure(projectProblem(`expected undefined, got ${fancyTypeOf(value)}`));
case 'string': return typeof(value) === 'string' ? Either.of(value as any) : Either.failure(projectProblem(`expected a string, got ${fancyTypeOf(value)}`)); case 'string': return typeof(value) === 'string' ? Either.of<any>(value) : Either.failure(projectProblem(`expected a string, got ${fancyTypeOf(value)}`));
case 'boolean': return typeof(value) === 'boolean' ? Either.of(value as any) : Either.failure(projectProblem(`expected a boolean, got ${fancyTypeOf(value)}`)); case 'boolean': return typeof(value) === 'boolean' ? Either.of<any>(value) : Either.failure(projectProblem(`expected a boolean, got ${fancyTypeOf(value)}`));
case 'any': return Either.of(value as A); case 'any': return Either.of(value as A);
case 'nat': return typeof (value) !== 'number' ? Either.failure(projectProblem('not a number')) : (value|0) === value && value >= 0 ? Either.of(value as any) : Either.failure(projectProblem('not a natural number')); case 'nat': return typeof (value) !== 'number' ? Either.failure(projectProblem('not a number')) : (value|0) === value && value >= 0 ? Either.of(value as any) : Either.failure(projectProblem('not a natural number'));
case 'int': return typeof (value) !== 'number' ? Either.failure(projectProblem('not a number')) : (value|0) === value ? Either.of(value as any) : Either.failure(projectProblem('not an integer')) case 'int': return typeof (value) !== 'number' ? Either.failure(projectProblem('not a number')) : (value|0) === value ? Either.of(value as any) : Either.failure(projectProblem('not an integer'))
......
...@@ -152,6 +152,11 @@ export function ap(): Eff<any, any> { ...@@ -152,6 +152,11 @@ export function ap(): Eff<any, any> {
return Rx.combineLatest(Array.apply(undefined, Array(arguments.length - 1)).map((_, idx) => _arguments[idx]), (...inputs) => either.traverse(inputs, x => x as any).map(inputs => _arguments[_arguments.length - 1].apply(undefined, inputs))); return Rx.combineLatest(Array.apply(undefined, Array(arguments.length - 1)).map((_, idx) => _arguments[idx]), (...inputs) => either.traverse(inputs, x => x as any).map(inputs => _arguments[_arguments.length - 1].apply(undefined, inputs)));
} }
export function record<R extends Record<string, Eff<any, any>>>(rec: R): Eff<{ [K in keyof R]: R[K]['_T']['_L'] }[keyof R], { [K in keyof R]: R[K]['_T']['_R'] }> {
const keys = Object.keys(rec);
return ap.apply(undefined, [...keys.map(k => rec[k]), (...values) => values.reduce((acc, v, idx) => (acc[keys[idx]] = v, acc), {})]);
}
/** traverse an array */ /** traverse an array */
export function traverse<ERR, A, B>(array: A[], f: (a: A, idx: number) => Eff<ERR, B>): Eff<ERR, B[]> { export function traverse<ERR, A, B>(array: A[], f: (a: A, idx: number) => Eff<ERR, B>): Eff<ERR, B[]> {
......
...@@ -30,7 +30,7 @@ export type JsonApi<A> = ...@@ -30,7 +30,7 @@ export type JsonApi<A> =
| RelatedMany<A> | RelatedMany<A>
| WithName<A> | WithName<A>
| WithDefault<A> | WithDefault<A>
; ;
// Базовый класс для наследования методов // Базовый класс для наследования методов
......
export * from '../../jsonapi/resources'; export * from '../../jsonapi/resources';
// // Без этого экспорта TS видит JsonApiBase только как тип
// import { JsonApiBase } from '../../jsonapi/resources';
// export { JsonApiBase };
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment