| 353 | validate<T>(schema: AsyncSchema, data: unknown | T): Promise<T> |
| 354 | validate<T>(schemaKeyRef: AnySchema | string, data: unknown): data is T | Promise<T> |
| 355 | validate<T>( |
| 356 | schemaKeyRef: AnySchema | string, // key, ref or schema object |
| 357 | // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents |
| 358 | data: unknown | T // to be validated |
| 359 | ): boolean | Promise<T> { |
| 360 | let v: AnyValidateFunction | undefined |
| 361 | if (typeof schemaKeyRef == "string") { |
| 362 | v = this.getSchema<T>(schemaKeyRef) |
| 363 | if (!v) throw new Error(`no schema with key or ref "${schemaKeyRef}"`) |
| 364 | } else { |
| 365 | v = this.compile<T>(schemaKeyRef) |
| 366 | } |
| 367 | |
| 368 | const valid = v(data) |
| 369 | if (!("$async" in v)) this.errors = v.errors |
| 370 | return valid |
| 371 | } |
| 372 | |
| 373 | // Create validation function for passed schema |
| 374 | // _meta: true if schema is a meta-schema. Used internally to compile meta schemas of user-defined keywords. |