How to use the @orbit/data.cloneRecordIdentity 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 / transform-requests.ts View on Github external
function replaceRecordHasOne(
  record: RecordIdentity,
  relationship: string,
  relatedRecord: RecordIdentity
) {
  deepSet(
    record,
    ['relationships', relationship, 'data'],
    relatedRecord ? cloneRecordIdentity(relatedRecord) : null
  );
}
github orbitjs / orbit / packages / @orbit / record-cache / src / operators / sync-patch-operators.ts View on Github external
addToRelatedRecords(
    cache: SyncRecordAccessor,
    op: AddToRelatedRecordsOperation
  ): PatchResultData {
    let currentRecord = cache.getRecordSync(op.record);
    let record: Record;
    const { relationship, relatedRecord } = op;

    if (currentRecord) {
      record = clone(currentRecord);
    } else {
      record = cloneRecordIdentity(op.record);
    }

    const relatedRecords: RecordIdentity[] =
      deepGet(record, ['relationships', relationship, 'data']) || [];

    if (!recordsInclude(relatedRecords, relatedRecord)) {
      relatedRecords.push(relatedRecord);

      deepSet(record, ['relationships', relationship, 'data'], relatedRecords);
      cache.setRecordSync(record);
    }

    return record;
  },
github orbitjs / orbit / packages / @orbit / local-storage / src / lib / transform-operators.ts View on Github external
replaceAttribute(source: Source, operation: ReplaceAttributeOperation) {
    let record: Record = source.getRecord(operation.record) || cloneRecordIdentity(operation.record);
    record.attributes = record.attributes || {};
    record.attributes[operation.attribute] = operation.value;
    source.putRecord(record);
  },
github orbitjs / orbit / packages / @orbit / store / src / cache / operation-processors / cache-integrity-processor.ts View on Github external
private clearInverseRelationshipOps(record: RecordIdentity): RecordOperation[] {
    const ops: RecordOperation[] = [];
    const inverseRels = this.cache.inverseRelationships.all(record);

    if (inverseRels.length > 0) {
      const recordIdentity = cloneRecordIdentity(record);
      inverseRels.forEach(rel => {
        const relationshipDef = this.cache.schema.getModel(rel.record.type).relationships[rel.relationship];
        if (relationshipDef.type === 'hasMany') {
          ops.push({
            op: 'removeFromRelatedRecords',
            record: rel.record,
            relationship: rel.relationship,
            relatedRecord: recordIdentity
          });
        } else {
          ops.push({
            op: 'replaceRelatedRecord',
            record: rel.record,
            relationship: rel.relationship,
            relatedRecord: null
          });
github orbitjs / orbit / packages / @orbit / jsonapi / src / lib / transform-requests.ts View on Github external
addToRelatedRecords(
    operation: AddToRelatedRecordsOperation
  ): TransformRecordRequest {
    return {
      op: 'addToRelatedRecords',
      record: cloneRecordIdentity(operation.record),
      relationship: operation.relationship,
      relatedRecords: [cloneRecordIdentity(operation.relatedRecord)]
    } as AddToRelatedRecordsRequest;
  },
github orbitjs / orbit / packages / @orbit / local-storage / src / lib / transform-operators.ts View on Github external
addToRelatedRecords(source: Source, operation: AddToRelatedRecordsOperation) {
    let record: Record = source.getRecord(operation.record) || cloneRecordIdentity(operation.record);
    let relationships = deepGet(record, ['relationships', operation.relationship, 'data']);
    if (relationships) {
      relationships.push(operation.relatedRecord);
    } else {
      deepSet(record, ['relationships', operation.relationship, 'data'], [operation.relatedRecord]);
    }
    source.putRecord(record);
  },
github orbitjs / orbit / packages / @orbit / record-cache / src / operation-processors / utils / schema-consistency-utils.ts View on Github external
export function recordRemoved(
  schema: Schema,
  record?: Record
): RecordOperation[] {
  const ops: RecordOperation[] = [];

  if (record && record.relationships) {
    const recordIdentity = cloneRecordIdentity(record);

    schema.eachRelationship(record.type, (relationship, relationshipDef) => {
      const relationshipData = deepGet(record, [
        'relationships',
        relationship,
        'data'
      ]) as RecordIdentity | RecordIdentity[] | null | undefined;

      if (relationshipData) {
        const relatedRecords = recordArrayFromData(
          relationshipData
        ) as RecordIdentity[];

        Array.prototype.push.apply(
          ops,
          removeRelatedRecordsOps(
github orbitjs / ember-orbit / addon / -private / model-factory.ts View on Github external
create(identity: RecordIdentity): Model {
    const modelFactory = this.modelFactoryFor(identity.type);
    return modelFactory.create({
      identity: cloneRecordIdentity(identity),
      _store: this._store
    });
  }
github orbitjs / ember-orbit / addon / -private / store.ts View on Github external
async removeRecord(record: RecordIdentity, options?: object): Promise {
    const identity = cloneRecordIdentity(record);
    await this.update(t => t.removeRecord(identity), options);
  }