Files
klz-cables.com/.pnpm-store/v10/files/a2/dc7bc1c449b76a1f6d43c87423a981ba1ff647e53f8d31af6377626c1296f8aedd63926e5b0b8857adaeb11c9a6f3330f0f6c8b1bfcdf36f74767206b05e38
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

38 lines
1019 B
Plaintext

import {JSONSchema, Parent, LinkedJSONSchema} from './types/JSONSchema'
import {isPlainObject} from 'lodash'
import {JSONSchema4Type} from 'json-schema'
/**
* Traverses over the schema, giving each node a reference to its
* parent node. We need this for downstream operations.
*/
export function link(schema: JSONSchema4Type | JSONSchema, parent: JSONSchema4Type | null = null): LinkedJSONSchema {
if (!Array.isArray(schema) && !isPlainObject(schema)) {
return schema as LinkedJSONSchema
}
// Handle cycles
if ((schema as JSONSchema).hasOwnProperty(Parent)) {
return schema as LinkedJSONSchema
}
// Add a reference to this schema's parent
Object.defineProperty(schema, Parent, {
enumerable: false,
value: parent,
writable: false,
})
// Arrays
if (Array.isArray(schema)) {
schema.forEach(child => link(child, schema))
}
// Objects
for (const key in schema as JSONSchema) {
link((schema as JSONSchema)[key], schema)
}
return schema as LinkedJSONSchema
}