UNPKG

@statezero/core

Version:

The type-safe frontend client for StateZero - connect directly to your backend models with zero boilerplate

33 lines (32 loc) 1.25 kB
import { isNil, isEqual } from 'lodash-es'; import { filter } from '../../filtering/localFiltering'; /** * Guarantees an array of operations, is an array of operations. Handles * the basic failure case of a single operation. */ export function validateOperationsArray(operationsArray) { // verify the operations list if (Array.isArray(operationsArray)) { if (operationsArray.length > 0) { if (!(operationsArray[0] instanceof Operation)) { throw new Error(`operationsArray must be Operations not ${typeof (operationsArray[0])}`); } } } else if (!isNil(operationsArray)) { if (!(operationsArray instanceof Operation)) { throw new Error(`operationsArray must be Operations not ${typeof (operationsArray)}`); } operationsArray = [operationsArray]; // coerce it to be an array } return operationsArray; } /** * Extract the minimal signature we're using for “direct‐match” comparison. */ export function getFingerprint(qs) { const { nodes } = qs; const initialQueryset = qs._initialQueryset; const { offset = null, limit = null } = qs._serializerOptions || {}; return { nodes, initialQueryset, offset, limit }; }