adapt-schemas 2.0.1 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/Schema.js +8 -8
- package/package.json +1 -1
package/lib/Schema.js
CHANGED
|
@@ -379,22 +379,22 @@ class Schema extends EventEmitter {
|
|
|
379
379
|
* @param {Function} predicate - `(schemaField) => boolean`
|
|
380
380
|
* @param {Object} [schema] - Internal: schema properties to walk (defaults to built.properties)
|
|
381
381
|
* @param {string} [parentPath=''] - Internal: the slash-delimited path accumulated so far
|
|
382
|
-
* @returns {Array<Object>} Array of `{ path, key, data, value }` matches
|
|
382
|
+
* @returns {Array<Object>} Array of `{ path, key, data, value, schemaField }` matches
|
|
383
383
|
*/
|
|
384
384
|
walk (data, predicate, schema, parentPath = '') {
|
|
385
385
|
schema = schema ?? this.built.properties
|
|
386
386
|
const matches = []
|
|
387
|
-
for (const [key,
|
|
387
|
+
for (const [key, schemaField] of Object.entries(schema)) {
|
|
388
388
|
if (data[key] === undefined) continue
|
|
389
389
|
const currentPath = parentPath ? `${parentPath}/${key}` : key
|
|
390
|
-
if (
|
|
391
|
-
matches.push(...this.walk(data[key], predicate,
|
|
392
|
-
} else if (
|
|
390
|
+
if (schemaField.properties) {
|
|
391
|
+
matches.push(...this.walk(data[key], predicate, schemaField.properties, currentPath))
|
|
392
|
+
} else if (schemaField?.items?.properties) {
|
|
393
393
|
data[key].forEach((item, i) => {
|
|
394
|
-
matches.push(...this.walk(item, predicate,
|
|
394
|
+
matches.push(...this.walk(item, predicate, schemaField.items.properties, `${currentPath}/${i}`))
|
|
395
395
|
})
|
|
396
|
-
} else if (predicate(
|
|
397
|
-
matches.push({ path: currentPath, key, data, value: data[key] })
|
|
396
|
+
} else if (predicate(schemaField)) {
|
|
397
|
+
matches.push({ path: currentPath, key, data, value: data[key], schemaField })
|
|
398
398
|
}
|
|
399
399
|
}
|
|
400
400
|
return matches
|