mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 18:25:24 +00:00
Changed Schemas type with a more detailed type Schema
This commit is contained in:
@@ -441,10 +441,7 @@ const personalizationDict = Joi.object().keys({
|
|||||||
|
|
||||||
// --------- UTILITIES ---------- //
|
// --------- UTILITIES ---------- //
|
||||||
|
|
||||||
type Schemas = {
|
const schemas = {
|
||||||
[index: string]: Joi.ObjectSchema | Joi.StringSchema;
|
|
||||||
};
|
|
||||||
const schemas: Schemas = {
|
|
||||||
instance,
|
instance,
|
||||||
certificatesSchema,
|
certificatesSchema,
|
||||||
barcode,
|
barcode,
|
||||||
@@ -458,7 +455,9 @@ const schemas: Schemas = {
|
|||||||
personalizationDict
|
personalizationDict
|
||||||
};
|
};
|
||||||
|
|
||||||
function resolveSchemaName(name: keyof Schemas) {
|
type Schema = keyof typeof schemas;
|
||||||
|
|
||||||
|
function resolveSchemaName(name: Schema) {
|
||||||
return schemas[name] || undefined;
|
return schemas[name] || undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -469,7 +468,7 @@ function resolveSchemaName(name: keyof Schemas) {
|
|||||||
* @returns {boolean} - result of the check
|
* @returns {boolean} - result of the check
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function isValid(opts: any, schemaName: keyof Schemas): boolean {
|
export function isValid(opts: any, schemaName: Schema): boolean {
|
||||||
const resolvedSchema = resolveSchemaName(schemaName);
|
const resolvedSchema = resolveSchemaName(schemaName);
|
||||||
|
|
||||||
if (!resolvedSchema) {
|
if (!resolvedSchema) {
|
||||||
@@ -493,7 +492,7 @@ export function isValid(opts: any, schemaName: keyof Schemas): boolean {
|
|||||||
* @returns {object} the filtered value or empty object
|
* @returns {object} the filtered value or empty object
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function getValidated<T extends Object>(opts: any, schemaName: keyof Schemas): T {
|
export function getValidated<T extends Object>(opts: any, schemaName: Schema): T {
|
||||||
let resolvedSchema = resolveSchemaName(schemaName);
|
let resolvedSchema = resolveSchemaName(schemaName);
|
||||||
let validation = Joi.validate(opts, resolvedSchema, { stripUnknown: true });
|
let validation = Joi.validate(opts, resolvedSchema, { stripUnknown: true });
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user