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
23 lines
1.3 KiB
Plaintext
23 lines
1.3 KiB
Plaintext
export function getFieldPaths({ field, index, parentIndexPath, parentPath = '', parentSchemaPath }) {
|
|
const parentPathSegments = parentPath.split('.');
|
|
const parentPathIsUnnamed = parentPathSegments?.[parentPathSegments.length - 1]?.startsWith('_index-');
|
|
const parentWithoutIndex = parentPathIsUnnamed ? parentPathSegments.slice(0, -1).join('.') : parentPath;
|
|
const parentPathToUse = parentPathIsUnnamed ? parentWithoutIndex : parentPath;
|
|
if ('name' in field) {
|
|
return {
|
|
indexPath: '',
|
|
path: `${parentPathToUse ? parentPathToUse + '.' : ''}${field.name}`,
|
|
schemaPath: `${parentSchemaPath ? parentSchemaPath + '.' : ''}${field.name}`
|
|
};
|
|
}
|
|
const indexSuffix = `_index-${`${parentIndexPath ? parentIndexPath + '-' : ''}${index}`}`;
|
|
const parentSchemaPathSegments = parentSchemaPath.split('.');
|
|
const parentSchemaPathIsUnnamed = parentSchemaPathSegments?.[parentSchemaPathSegments.length - 1]?.startsWith('_index-');
|
|
return {
|
|
indexPath: `${parentIndexPath ? parentIndexPath + '-' : ''}${index}`,
|
|
path: `${parentPathToUse ? parentPathToUse + '.' : ''}${indexSuffix}`,
|
|
schemaPath: parentSchemaPathIsUnnamed ? `${parentSchemaPath}-${index}` : `${parentSchemaPath ? parentSchemaPath + '.' : ''}${indexSuffix}`
|
|
};
|
|
}
|
|
|
|
//# sourceMappingURL=getFieldPaths.js.map |