1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const schema_1 = require("./schema");
|
4 | const jp = require('jsonpath');
|
5 | exports.schemaPath = (targetVal, opts, paths, otherValues) => {
|
6 | if (!targetVal || typeof targetVal !== 'object')
|
7 | return [];
|
8 | let object = targetVal;
|
9 | const { resolved } = otherValues;
|
10 | if (!resolved) {
|
11 | console.warn('schema-path expects a resolved object, but none was provided. Results may not be correct.');
|
12 | }
|
13 | else {
|
14 | object = jp.value(resolved, jp.stringify(['$', ...paths.given]));
|
15 | }
|
16 | const relevantObject = opts.field ? object[opts.field] : object;
|
17 | if (!relevantObject)
|
18 | return [];
|
19 | let schemaObject;
|
20 | try {
|
21 | schemaObject = jp.value(object, opts.schemaPath);
|
22 | }
|
23 | catch (error) {
|
24 | console.error(error);
|
25 | }
|
26 | return schema_1.schema(relevantObject, { schema: schemaObject }, paths, otherValues);
|
27 | };
|
28 |
|
\ | No newline at end of file |