Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
(data as JSONAPIOperationsPayload).operations.forEach((operation) => {
let removedRecords = [];
let transforms = [];
let operationData;
switch (operation.op) {
case 'get':
case 'update':
case 'add':
pushPayload(store, { ...operation });
break;
case 'remove':
operationData = operation.data || operation.ref;
removedRecords = Array.isArray(operationData) ? operationData : [operationData];
removedRecords.forEach((record) => {
let recordIdentity = recordIdentityFrom(
store,
record.id,
toOrbitType(store, record.type)
);
// was this record already removed from the cache?
// maybe we are receiving an operations payload that is telling us
// to remove something that we've already removed.
let exists = false;
const pollCallback = useCallback(async () => {
if (workflowProjectUrl) {
return true;
}
try {
const url = `projects/${idFromRecordIdentity(dataStore, project)}`;
const response = await authenticatedGet(`/api/${url}`);
const json = await response.json();
await pushPayload(dataStore, json);
const fromCache = dataStore.cache.query((q) => q.findRecord(project));
const { workflowProjectUrl } = attributesFor(fromCache);
return workflowProjectUrl;
} catch (e) {
return false;
}
}, [dataStore, project, workflowProjectUrl]);
(async () => {
const response = await fetch('/api/organizations', {
headers: defaultHeaders(),
});
const json = await response.json();
await pushPayload(dataStore, json);
setNeedsSuperAdminData(false);
})();
}
export function dataToLocalCache(store: Store, data: JSONAPIOperationsPayload | JSONAPIDocument) {
if ((data as JSONAPIDocument).data) {
return pushPayload(store, data);
}
if ((data as JSONAPIOperationsPayload).operations) {
(data as JSONAPIOperationsPayload).operations.forEach((operation) => {
let removedRecords = [];
let transforms = [];
let operationData;
switch (operation.op) {
case 'get':
case 'update':
case 'add':
pushPayload(store, { ...operation });
break;
case 'remove':
useEffect(() => {
if (!data) return;
pushPayload(dataStore, data);
}, [data, dataStore]);