@travetto/schema
Advanced tools
Comparing version 0.0.7 to 0.0.8
@@ -27,3 +27,3 @@ { | ||
}, | ||
"version": "0.0.7" | ||
"version": "0.0.8" | ||
} |
@@ -27,3 +27,3 @@ import { CommonRegExp, SchemaRegistry, ClassList } from '../service'; | ||
export const Enum = (vals: string[] | any, message?: string) => { | ||
let values = enumKeys(vals); | ||
const values = enumKeys(vals); | ||
message = message || `{path} is only allowed to be "${values.join('" or "')}"`; | ||
@@ -44,3 +44,3 @@ return prop({ enum: { values, message } }); | ||
return (f: any, p: string) => { | ||
for (let name of names) { | ||
for (const name of names) { | ||
SchemaRegistry.registerPendingFieldFacet(f.constructor, p, {}, name); | ||
@@ -53,3 +53,3 @@ } | ||
export function Ignore(): PropertyDecorator { | ||
return (target: any, property: string) => { } | ||
return (target: any, property: string | symbol) => { } | ||
} |
@@ -6,3 +6,3 @@ import { BindUtil } from '../util'; | ||
type DeepPartial<T> = { | ||
[p in keyof T]?: DeepPartial<T[p]> | ||
[P in keyof T]?: DeepPartial<T[P]> | ||
} | ||
@@ -9,0 +9,0 @@ |
@@ -26,3 +26,3 @@ import { ClassList, FieldConfig, ClassConfig, ViewConfig } from './types'; | ||
getParent(cls: Class): Class | null { | ||
let parent = Object.getPrototypeOf(cls) as Class; | ||
const parent = Object.getPrototypeOf(cls) as Class; | ||
return parent.name && (parent as any) !== Object ? parent : null; | ||
@@ -35,3 +35,3 @@ } | ||
if (cls.__id) { | ||
let conf = this.getOrCreatePending(cls); | ||
const conf = this.getOrCreatePending(cls); | ||
return conf.views![view].schema; | ||
@@ -50,3 +50,3 @@ } else { | ||
let conf = this.getOrCreatePending(target); | ||
const conf = this.getOrCreatePending(target); | ||
@@ -66,3 +66,3 @@ let viewConf = conf.views![view]; | ||
let defViewConf = this.getOrCreatePendingViewConfig(target); | ||
const defViewConf = this.getOrCreatePendingViewConfig(target); | ||
@@ -75,3 +75,3 @@ if (!defViewConf.schema[prop]) { | ||
if (view !== $SchemaRegistry.DEFAULT_VIEW) { | ||
let viewConf = this.getOrCreatePendingViewConfig(target, view); | ||
const viewConf = this.getOrCreatePendingViewConfig(target, view); | ||
if (!viewConf.schema[prop]) { | ||
@@ -109,4 +109,4 @@ viewConf.schema[prop] = defViewConf.schema[prop]; | ||
mergeConfigs(dest: ClassConfig, src: ClassConfig) { | ||
for (let v of Object.keys(src.views)) { | ||
let view = src.views[v]; | ||
for (const v of Object.keys(src.views)) { | ||
const view = src.views[v]; | ||
if (v in dest.views) { | ||
@@ -132,5 +132,5 @@ dest.views[v] = { | ||
// Merge parent | ||
let parent = this.getParent(cls) as Class; | ||
const parent = this.getParent(cls) as Class; | ||
if (parent) { | ||
let parentConfig = this.get(parent); | ||
const parentConfig = this.get(parent); | ||
if (parentConfig) { | ||
@@ -142,3 +142,3 @@ config = this.mergeConfigs(config, parentConfig); | ||
// Merge pending | ||
let pending = this.getOrCreatePending(cls); | ||
const pending = this.getOrCreatePending(cls); | ||
if (pending) { | ||
@@ -145,0 +145,0 @@ config = this.mergeConfigs(config, pending as ClassConfig); |
@@ -12,4 +12,4 @@ import { Messages } from './messages'; | ||
// Rebind regexes | ||
for (let k of Object.keys(CommonRegExp)) { | ||
for (const k of Object.keys(CommonRegExp)) { | ||
Messages.set((CommonRegExp as any)[k], Messages.get(k)!); | ||
} |
@@ -11,3 +11,3 @@ import { FieldConfig, SchemaConfig } from '../types'; | ||
static validateField(field: FieldConfig, value: any) { | ||
let criteria: string[] = []; | ||
const criteria: string[] = []; | ||
@@ -49,3 +49,3 @@ if ( | ||
} else { | ||
let date = field.min.n.getTime(); | ||
const date = field.min.n.getTime(); | ||
if (typeof value === 'string') { | ||
@@ -69,3 +69,3 @@ value = Date.parse(value); | ||
} else { | ||
let date = field.max.n.getTime(); | ||
const date = field.max.n.getTime(); | ||
if (typeof value === 'string') { | ||
@@ -80,5 +80,5 @@ value = Date.parse(value); | ||
let errors: ValidationError[] = []; | ||
for (let key of criteria) { | ||
let block = (field as any)[key]; | ||
const errors: ValidationError[] = []; | ||
for (const key of criteria) { | ||
const block = (field as any)[key]; | ||
errors.push({ ...block, kind: key, value }); | ||
@@ -90,5 +90,5 @@ } | ||
static prepareErrors(path: string, errs: any[]) { | ||
let out = []; | ||
for (let err of errs) { | ||
let message = err.message || (err.kind === 'match' ? Messages.get(err.re) : Messages.get(err.kind)) | ||
const out = []; | ||
for (const err of errs) { | ||
const message = err.message || (err.kind === 'match' ? Messages.get(err.re) : Messages.get(err.kind)) | ||
if (message) { | ||
@@ -106,8 +106,8 @@ err.path = path; | ||
for (let field of Object.keys(schema)) { | ||
let fieldSchema = schema[field]; | ||
let val = (o as any)[field]; | ||
let path = `${relative}${relative && '.'}${field}`; | ||
for (const field of Object.keys(schema)) { | ||
const fieldSchema = schema[field]; | ||
const val = (o as any)[field]; | ||
const path = `${relative}${relative && '.'}${field}`; | ||
let hasValue = !(val === undefined || val === null || val === '' || (Array.isArray(val) && val.length === 0)); | ||
const hasValue = !(val === undefined || val === null || val === '' || (Array.isArray(val) && val.length === 0)); | ||
@@ -121,3 +121,3 @@ if (!hasValue) { | ||
let { type, array } = fieldSchema.declared; | ||
const { type, array } = fieldSchema.declared; | ||
@@ -138,3 +138,3 @@ let sub: SchemaConfig | undefined; | ||
for (let i = 0; i < val.length; i++) { | ||
let subErrors = this.validateSchema(sub, val[i], view, `${path}[${i}]`); | ||
const subErrors = this.validateSchema(sub, val[i], view, `${path}[${i}]`); | ||
errors = errors.concat(subErrors); | ||
@@ -144,3 +144,3 @@ } | ||
for (let i = 0; i < val.length; i++) { | ||
let subErrors = this.validateField(fieldSchema, val[i]); | ||
const subErrors = this.validateField(fieldSchema, val[i]); | ||
errors.push(...this.prepareErrors(`${path}[${i}]`, subErrors)); | ||
@@ -150,6 +150,6 @@ } | ||
} else if (sub) { | ||
let subErrors = this.validateSchema(sub, val, view, path); | ||
const subErrors = this.validateSchema(sub, val, view, path); | ||
errors.push(...subErrors); | ||
} else { | ||
let fieldErrors = this.validateField(fieldSchema, val); | ||
const fieldErrors = this.validateField(fieldSchema, val); | ||
errors.push(...this.prepareErrors(path, fieldErrors)); | ||
@@ -163,6 +163,6 @@ } | ||
static async validate<T>(o: T, view?: string): Promise<T> { | ||
let cls = o.constructor as Class; | ||
let config = SchemaRegistry.getViewSchema(cls, view); | ||
const cls = o.constructor as Class; | ||
const config = SchemaRegistry.getViewSchema(cls, view); | ||
let errors = this.validateSchema(config.schema, o, view, ''); | ||
const errors = this.validateSchema(config.schema, o, view, ''); | ||
@@ -169,0 +169,0 @@ if (errors.length) { |
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
30279