Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function createObjectFromPath(path, payload, state, conf) {
var _a;
// edge cases
if (path === '*')
return payload;
if (!path.includes('.') && !path.includes('/'))
return _a = {}, _a[path] = payload, _a;
// start
var newValue = payload;
if (path.includes('*')) {
// only work with arrays
if (!isArray(payload))
payload = [payload];
var lastPayloadPiece = payload.pop();
var ids = payload;
// CASE: 'dex/pokemonById.*.tags'
if (!path.endsWith('*')) {
newValue = lastPayloadPiece;
}
// CASE: 'dex/pokemonById.*.tags.*'
if (path.endsWith('*')) {
var lastId = getId(lastPayloadPiece, conf, path);
ids.push(lastId);
newValue = getValueFromPayloadPiece(lastPayloadPiece);
if (isObject(newValue))
newValue.id = lastId;
}
ids = ids.map(function (_id) {
insertDoc: function insertDoc(_ref5) {
var state = _ref5.state,
getters = _ref5.getters,
commit = _ref5.commit,
dispatch = _ref5.dispatch;
var docs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
// 0. payload correction (only arrays)
if (!isArray(docs)) docs = [docs]; // 1. Prepare for patching
var syncStack = getters.prepareForInsert(docs); // 2. Push to syncStack
var inserts = state._sync.syncStack.inserts.concat(syncStack);
state._sync.syncStack.inserts = inserts; // 3. Create or refresh debounce
return dispatch('handleSyncStackDebounce');
},
insertInitialDoc: function insertInitialDoc(_ref6) {
function MUTATE_PROP_x_SUBPROP(state, payload, PROP_SUBPROP, conf) {
if (!isArray(payload))
payload = [payload];
var newValue = payload.pop();
var ids = getIdsFromPayload(payload, conf, PROP_SUBPROP);
if (!checkIdWildcardRatio(ids, PROP_SUBPROP, conf))
return;
var pathWithIds = fillinPathWildcards(ids, PROP_SUBPROP, state, conf);
return setDeepValue(state, pathWithIds, newValue);
}
// eslint-disable-next-line
insertDoc: function (_a, payload) {
var state = _a.state, getters = _a.getters, commit = _a.commit, dispatch = _a.dispatch;
if (payload === void 0) { payload = []; }
// 0. payload correction (only arrays)
var docs = !isArray(payload) ? [payload] : payload;
// 1. Prepare for patching
var syncStack = getters.prepareForInsert(docs);
// 2. Push to syncStack
var inserts = state._sync.syncStack.inserts.concat(syncStack);
state._sync.syncStack.inserts = inserts;
// 3. Create or refresh debounce & pass id to resolve
var payloadToResolve = isArray(payload)
? payload.map(function (doc) { return doc.id; })
: payload.id;
return dispatch('handleSyncStackDebounce', payloadToResolve);
},
insertInitialDoc: function (_a) {
test('store set up', async t => {
t.true(isPlainObject(box.pokemon))
t.true(isArray(char.items))
})
function shiftDeepValue (target, path) {
const deepRef = getDeepRef(target, path)
if (!isArray(deepRef)) return
return deepRef.shift()
}
function checkIdWildcardRatio(ids, path, conf) {
var match = path.match(/\*/g);
var idCount = (isWhat.isArray(match))
? match.length
: 0;
if (ids.length === idCount)
return true;
error('mutationSetterPropPathWildcardIdCount', conf);
return false;
}
/**
SET_SYNCCLAUSES (state, {where, orderBy}) {
if (where && isArray(where)) state._conf.sync.where = where
if (orderBy && isArray(orderBy)) state._conf.sync.orderBy = orderBy
},
SET_USER_ID (state, userId) {
function spliceDeepValue(target, path, index, deleteCount, value) {
if (index === void 0) { index = 0; }
if (deleteCount === void 0) { deleteCount = 0; }
var deepRef = getDeepRef(target, path);
if (!isWhat.isArray(deepRef))
return;
if (value === undefined)
return deepRef.splice(index, deleteCount);
return deepRef.splice(index, deleteCount, value);
}
export function spliceDeepValue (
target: object,
path: string,
index: number = 0,
deleteCount: number = 0,
value: any
): any[] {
const deepRef = getDeepRef(target, path)
if (!isArray(deepRef)) return
if (value === undefined) return deepRef.splice(index, deleteCount)
return deepRef.splice(index, deleteCount, value)
}