|
6 | 6 | * found in the LICENSE file at https://angular.io/license
|
7 | 7 | */
|
8 | 8 |
|
9 |
| -import Ajv, { ValidateFunction } from 'ajv'; |
| 9 | +import Ajv, { SchemaObjCxt, ValidateFunction } from 'ajv'; |
10 | 10 | import ajvAddFormats from 'ajv-formats';
|
11 | 11 | import * as http from 'http';
|
12 | 12 | import * as https from 'https';
|
@@ -305,6 +305,8 @@ export class CoreSchemaRegistry implements SchemaRegistry {
|
305 | 305 | try {
|
306 | 306 | this._currentCompilationSchemaInfo = schemaInfo;
|
307 | 307 | validator = this._ajv.compile(schema);
|
| 308 | + } catch { |
| 309 | + validator = await this._ajv.compileAsync(schema); |
308 | 310 | } finally {
|
309 | 311 | this._currentCompilationSchemaInfo = undefined;
|
310 | 312 | }
|
@@ -406,10 +408,7 @@ export class CoreSchemaRegistry implements SchemaRegistry {
|
406 | 408 | }
|
407 | 409 |
|
408 | 410 | // We cheat, heavily.
|
409 |
| - const pathArray = it.dataPathArr |
410 |
| - .slice(1, it.dataLevel + 1) |
411 |
| - .map((p) => (typeof p === 'number' ? p : p.str.slice(1, -1))); |
412 |
| - |
| 411 | + const pathArray = this.normalizeDataPathArr(it); |
413 | 412 | compilationSchemInfo.smartDefaultRecord.set(JSON.stringify(pathArray), schema);
|
414 | 413 |
|
415 | 414 | return () => true;
|
@@ -449,12 +448,7 @@ export class CoreSchemaRegistry implements SchemaRegistry {
|
449 | 448 | return () => true;
|
450 | 449 | }
|
451 | 450 |
|
452 |
| - const path = |
453 |
| - '/' + |
454 |
| - it.dataPathArr |
455 |
| - .slice(1, it.dataLevel + 1) |
456 |
| - .map((p) => (typeof p === 'number' ? p : p.str.slice(1, -1))) |
457 |
| - .join('/'); |
| 451 | + const path = '/' + this.normalizeDataPathArr(it).join('/'); |
458 | 452 |
|
459 | 453 | let type: string | undefined;
|
460 | 454 | let items: Array<string | { label: string; value: string | number | boolean }> | undefined;
|
@@ -593,11 +587,31 @@ export class CoreSchemaRegistry implements SchemaRegistry {
|
593 | 587 | data: any,
|
594 | 588 | fragments: string[],
|
595 | 589 | value: unknown,
|
596 |
| - parent: Record<string, unknown> | null = null, |
| 590 | + // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 591 | + parent: any = null, |
597 | 592 | parentProperty?: string,
|
598 | 593 | force?: boolean,
|
599 | 594 | ): void {
|
600 |
| - for (const fragment of fragments) { |
| 595 | + for (let index = 0; index < fragments.length; index++) { |
| 596 | + const fragment = fragments[index]; |
| 597 | + if (/^i\d+$/.test(fragment)) { |
| 598 | + if (!Array.isArray(data)) { |
| 599 | + return; |
| 600 | + } |
| 601 | + |
| 602 | + for (let dataIndex = 0; dataIndex < data.length; dataIndex++) { |
| 603 | + CoreSchemaRegistry._set( |
| 604 | + data[dataIndex], |
| 605 | + fragments.slice(index + 1), |
| 606 | + value, |
| 607 | + data, |
| 608 | + `${dataIndex}`, |
| 609 | + ); |
| 610 | + } |
| 611 | + |
| 612 | + return; |
| 613 | + } |
| 614 | + |
601 | 615 | if (!data && parent !== null && parentProperty) {
|
602 | 616 | data = parent[parentProperty] = {};
|
603 | 617 | }
|
@@ -665,4 +679,10 @@ export class CoreSchemaRegistry implements SchemaRegistry {
|
665 | 679 | );
|
666 | 680 | }
|
667 | 681 | }
|
| 682 | + |
| 683 | + private normalizeDataPathArr(it: SchemaObjCxt): (number | string)[] { |
| 684 | + return it.dataPathArr |
| 685 | + .slice(1, it.dataLevel + 1) |
| 686 | + .map((p) => (typeof p === 'number' ? p : p.str.replace(/\"/g, ''))); |
| 687 | + } |
668 | 688 | }
|
0 commit comments