UNPKG

synapse-react-client

Version:

[![npm version](https://badge.fury.io/js/synapse-react-client.svg)](https://badge.fury.io/js/synapse-react-client) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettie

49 lines (48 loc) 1.46 kB
import { useCreateEntity as d, useGetEntityLookupQueryOptions as l, useGetEntityQueryOptions as m } from "../../../synapse-queries/entity/useEntity.js"; import { useQueryClient as f, useMutation as E } from "@tanstack/react-query"; import { convertToEntityType as g, entityTypeToFriendlyName as h } from "../../functions/EntityTypeUtils.js"; function C() { const { mutateAsync: i } = d(), r = f(), s = l(), y = m(); return E({ mutationFn: async (a) => { const { rootContainerId: c, path: u } = a; let t = c; for (const o of u) { const n = await r.fetchQuery( s({ parentId: t, entityName: o }) ); if (n) { const e = await r.fetchQuery( y(n) ); if (e.concreteType != "org.sagebionetworks.repo.model.Folder") { const p = g( e.concreteType ); throw new Error( `A(n) ${h( p )} named "${o}" already exists in this location (${t}). A folder could not be created.` ); } t = n; } else { const { id: e } = await i({ concreteType: "org.sagebionetworks.repo.model.Folder", name: o, parentId: t }); t = e; } } return t; } }); } export { C as useCreateFolderPath }; //# sourceMappingURL=useCreateFolderPath.js.map