enonic-wizardry
Advanced tools
Comparing version 0.3.5 to 0.3.6
{ | ||
"name": "enonic-wizardry", | ||
"sideEffects": false, | ||
"version": "0.3.5", | ||
"version": "0.3.6", | ||
"description": "Functional utility library for Enonic XP", | ||
@@ -29,11 +29,11 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"enonic-fp": "^0.3.2", | ||
"enonic-fp": "^0.3.3", | ||
"enonic-types": "^0.1.4", | ||
"fp-ts": "^2.8.5", | ||
"fp-ts": "^2.8.6", | ||
"io-ts": "^2.2.12" | ||
}, | ||
"devDependencies": { | ||
"@typescript-eslint/eslint-plugin": "^4.6.1", | ||
"@typescript-eslint/parser": "^4.6.1", | ||
"eslint": "^7.12.1", | ||
"@typescript-eslint/eslint-plugin": "^4.8.0", | ||
"@typescript-eslint/parser": "^4.8.0", | ||
"eslint": "^7.13.0", | ||
"rimraf": "^3.0.2", | ||
@@ -40,0 +40,0 @@ "typescript": "^4.0.5" |
import { Reporter } from "io-ts/lib/Reporter"; | ||
import { ErrorDetail } from "enonic-fp/errors"; | ||
export declare function getErrorDetailReporter(i18nKey?: string): Reporter<Array<ErrorDetail>>; | ||
import { LocalizeParams } from "enonic-types/i18n"; | ||
export interface GetErrorDetailReporterParams { | ||
readonly i18nPrefix?: string; | ||
readonly localizeParams?: LocalizeParams; | ||
} | ||
export declare function getErrorDetailReporter(params?: GetErrorDetailReporterParams): Reporter<Array<ErrorDetail>>; |
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -8,12 +19,12 @@ exports.getErrorDetailReporter = void 0; | ||
var Option_1 = require("fp-ts/Option"); | ||
function getErrorDetailReporter(i18nKey) { | ||
function getErrorDetailReporter(params) { | ||
if (params === void 0) { params = {}; } | ||
return { | ||
report: Either_1.fold(function (es) { return es.map(function (err) { return validationErrorToErrorDetail(err, i18nKey); }); }, function () { return []; }) | ||
report: Either_1.fold(function (es) { return es.map(function (err) { return validationErrorToErrorDetail(err, params); }); }, function () { return []; }) | ||
}; | ||
} | ||
exports.getErrorDetailReporter = getErrorDetailReporter; | ||
function validationErrorToErrorDetail(err, i18nPrefix) { | ||
if (i18nPrefix === void 0) { i18nPrefix = "errors"; } | ||
function validationErrorToErrorDetail(err, params) { | ||
var key = getPathInInterface(err.context); | ||
return pipeable_1.pipe(getMessageKeys(key, isLastEmpty(err.context), i18nPrefix), i18n_1.localizeFirst, Option_1.getOrElse(function () { var _a; return (_a = err.message) !== null && _a !== void 0 ? _a : 'Invalid value'; }), function (message) { return ({ | ||
return pipeable_1.pipe(getMessageKeys(key, isLastEmpty(err.context), params), i18n_1.localizeFirst, Option_1.getOrElse(function () { var _a; return (_a = err.message) !== null && _a !== void 0 ? _a : 'Invalid value'; }), function (message) { return ({ | ||
key: key, | ||
@@ -23,3 +34,5 @@ message: message | ||
} | ||
function getMessageKeys(key, fieldIsEmpty, i18nPrefix) { | ||
function getMessageKeys(key, fieldIsEmpty, params) { | ||
var _a; | ||
var i18nPrefix = (_a = params.i18nPrefix) !== null && _a !== void 0 ? _a : "errors"; | ||
var keyedMessageKeys = [ | ||
@@ -42,3 +55,4 @@ i18nPrefix + ".bad-request-error." + key, | ||
.concat(fieldIsEmpty ? emptyMessageKeys : []) | ||
.concat(defaultMessageKeys); | ||
.concat(defaultMessageKeys) | ||
.map(function (key) { return (__assign(__assign({}, params.localizeParams), { key: key })); }); | ||
} | ||
@@ -45,0 +59,0 @@ /** |
import { Type } from 'io-ts'; | ||
import * as t from 'io-ts'; | ||
import { GetErrorDetailReporterParams } from "./reporters/ErrorDetailReporter"; | ||
import { EnonicError } from 'enonic-fp/errors'; | ||
import { IOEither } from "fp-ts/IOEither"; | ||
export declare function validate<A, O = A, I = unknown>(a: Type<A, O, I>, params?: ValidateParams): (i: I) => IOEither<EnonicError, A>; | ||
export interface ValidateParams { | ||
readonly i18nPrefix?: string; | ||
} | ||
export declare function validate<A, O = A, I = unknown>(a: Type<A, O, I>, params?: GetErrorDetailReporterParams): (i: I) => IOEither<EnonicError, A>; | ||
export interface RegexpValidatedStringProps<A extends boolean = false> { | ||
@@ -10,0 +8,0 @@ readonly regexp: RegExp; |
@@ -23,3 +23,3 @@ "use strict"; | ||
var decoded = a.decode(i); | ||
return pipeable_1.pipe(decoded, IOEither_1.fromEither, IOEither_1.mapLeft(function () { return (__assign(__assign({}, errors_1.badRequestError), { errors: ErrorDetailReporter_1.getErrorDetailReporter(params === null || params === void 0 ? void 0 : params.i18nPrefix).report(decoded) })); })); | ||
return pipeable_1.pipe(decoded, IOEither_1.fromEither, IOEither_1.mapLeft(function () { return (__assign(__assign({}, errors_1.badRequestError), { errors: ErrorDetailReporter_1.getErrorDetailReporter(params).report(decoded) })); })); | ||
}; | ||
@@ -26,0 +26,0 @@ } |
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
22688
354
Updatedenonic-fp@^0.3.3
Updatedfp-ts@^2.8.6