How to use the @orbit/data.buildTransform function in @orbit/data

To help you get started, we’ve selected a few @orbit/data examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github orbitjs / orbit / packages / @orbit / jsonapi / src / lib / pull-operators.ts View on Github external
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)];
  }
};
github orbitjs / orbit / packages / @orbit / indexeddb / src / indexeddb-source.ts View on Github external
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;
  }
github sillsdev / web-languageforge / src / SIL.XForge.Scripture / ClientApp / src / xforge-common / strategies / remote-store-sync-strategy.ts View on Github external
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);
  }
}
github sillsdev / web-languageforge / src / SIL.XForge.Scripture / ClientApp / src / xforge-common / jsonapi / pull-operators.ts View on Github external
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];
}
github orbitjs / orbit / packages / @orbit / memory / src / memory-source.ts View on Github external
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);
  }
github orbitjs / orbit / packages / @orbit / jsonapi / src / lib / query-operators.ts View on Github external
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 };
  }
};
github orbitjs / orbit / packages / @orbit / jsonapi / src / lib / transform-requests.ts View on Github external
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 };
}
github orbitjs / orbit / packages / @orbit / jsonapi / src / lib / transform-requests.ts View on Github external
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 };
}