Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const expression = query.expression as FindRelatedRecords;
const { record, relationship } = expression;
const document = await GetOperators.findRelatedRecords(source, query);
const deserialized = source.serializer.deserializeDocument(document);
const relatedRecords = deserialized.data;
const operations = operationsFromDeserializedDocument(deserialized);
operations.push({
op: 'replaceRelatedRecords',
record,
relationship,
relatedRecords
} as ReplaceRelatedRecordsOperation);
return [buildTransform(operations)];
}
};
async _pull(query: Query): Promise {
let operations: Operation[];
const results = await this._cache.query(query);
if (query.expressions.length === 1) {
operations = this._operationsFromQueryResult(results);
} else {
for (let result of results as QueryResultData[]) {
operations.push(...this._operationsFromQueryResult(result));
}
}
const transforms = [buildTransform(operations)];
await this.transformed(transforms);
return transforms;
}
const deletedRecords: Record[] = [];
for (const cachedRecord of cachedRecords) {
if (!remoteRecordIds.has(cachedRecord.id)) {
deletedRecords.push(cachedRecord);
}
}
if (deletedRecords.length > 0) {
const operations = transform.operations.slice();
for (const deletedRecord of deletedRecords) {
operations.push({
op: 'removeRecord',
record: { type: deletedRecord.type, id: deletedRecord.id }
} as RemoveRecordOperation);
}
transform = buildTransform(operations, transform.options, transform.id);
}
}
}
}
return store.sync(transform);
}
}
function deserialize(source: JSONAPISource, document: JSONAPIDocument, query: Query): Transform[] {
const deserialized = source.serializer.deserializeDocument(document);
const records = toArray(deserialized.data);
if (deserialized.included) {
Array.prototype.push.apply(records, deserialized.included);
}
const operations = records.map(record => {
return {
op: 'replaceRecord',
record
};
});
const transform = buildTransform(operations, query.options);
query.options.transformId = transform.id;
if (document.meta != null) {
query.options.totalPagedCount = document.meta['total-records'];
}
return [transform];
}
transforms = forkedSource.transformsSince(options.sinceTransformId);
} else {
transforms = forkedSource.allTransforms();
}
let reducedTransform;
let ops: RecordOperation[] = [];
transforms.forEach(t => {
Array.prototype.push.apply(ops, t.operations);
});
if (options.coalesce !== false) {
ops = coalesceRecordOperations(ops);
}
reducedTransform = buildTransform(ops, options.transformOptions);
return this.update(reducedTransform);
}
.then(() => [buildTransform(operations)]);
},
op: 'addToRelatedRecords',
record,
relationship,
relatedRecord
} as AddToRelatedRecordsOperation);
}
} else {
operations.push({
op: 'replaceRelatedRecords',
record,
relationship,
relatedRecords
} as ReplaceRelatedRecordsOperation);
}
const transforms = [buildTransform(operations)];
const primaryData = relatedRecords;
return { transforms, primaryData, meta, links };
}
};
function handleChanges(
record: Record,
responseDoc: RecordDocument
): RequestProcessorResponse {
let updatedRecord: Record = responseDoc.data as Record;
let { meta, links } = responseDoc;
let transforms = [];
let updateOps = recordDiffs(record, updatedRecord);
if (updateOps.length > 0) {
transforms.push(buildTransform(updateOps));
}
if (responseDoc.included && responseDoc.included.length > 0) {
let includedOps = responseDoc.included.map(record => {
return { op: 'updateRecord', record };
});
transforms.push(buildTransform(includedOps));
}
return { transforms, primaryData: updatedRecord, meta, links };
}
function handleChanges(
record: Record,
responseDoc: RecordDocument
): RequestProcessorResponse {
let updatedRecord: Record = responseDoc.data as Record;
let { meta, links } = responseDoc;
let transforms = [];
let updateOps = recordDiffs(record, updatedRecord);
if (updateOps.length > 0) {
transforms.push(buildTransform(updateOps));
}
if (responseDoc.included && responseDoc.included.length > 0) {
let includedOps = responseDoc.included.map(record => {
return { op: 'updateRecord', record };
});
transforms.push(buildTransform(includedOps));
}
return { transforms, primaryData: updatedRecord, meta, links };
}