How to use the @orbit/data.recordsInclude 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 / record-cache / src / operators / sync-inverse-patch-operators.ts View on Github external
addToRelatedRecords(
    cache: SyncRecordAccessor,
    op: AddToRelatedRecordsOperation
  ): RecordOperation | undefined {
    const { record, relationship, relatedRecord } = op;
    const currentRelatedRecords = cache.getRelatedRecordsSync(
      record,
      relationship
    );

    if (
      currentRelatedRecords === undefined ||
      !recordsInclude(currentRelatedRecords, relatedRecord)
    ) {
      return {
        op: 'removeFromRelatedRecords',
        record,
        relationship,
        relatedRecord
      };
    }
    return;
  },
github orbitjs / orbit / packages / @orbit / record-cache / src / operators / async-patch-operators.ts View on Github external
op: AddToRelatedRecordsOperation
  ): Promise {
    let currentRecord = await cache.getRecordAsync(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);
      await cache.setRecordAsync(record);
    }

    return record;
  },
github orbitjs / orbit / packages / @orbit / record-cache / src / operators / async-inverse-patch-operators.ts View on Github external
async removeFromRelatedRecords(
    cache: AsyncRecordAccessor,
    op: RemoveFromRelatedRecordsOperation
  ): Promise {
    const { record, relationship, relatedRecord } = op;
    const currentRelatedRecords = await cache.getRelatedRecordsAsync(
      record,
      relationship
    );

    if (
      currentRelatedRecords !== undefined &&
      recordsInclude(currentRelatedRecords, relatedRecord)
    ) {
      return {
        op: 'addToRelatedRecords',
        record,
        relationship,
        relatedRecord
      };
    }
    return;
  },
github orbitjs / orbit / packages / @orbit / record-cache / src / operators / sync-patch-operators.ts View on Github external
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 / record-cache / src / operators / async-inverse-patch-operators.ts View on Github external
async addToRelatedRecords(
    cache: AsyncRecordAccessor,
    op: AddToRelatedRecordsOperation
  ): Promise {
    const { record, relationship, relatedRecord } = op;
    const currentRelatedRecords = await cache.getRelatedRecordsAsync(
      record,
      relationship
    );

    if (
      currentRelatedRecords === undefined ||
      !recordsInclude(currentRelatedRecords, relatedRecord)
    ) {
      return {
        op: 'removeFromRelatedRecords',
        record,
        relationship,
        relatedRecord
      };
    }
    return;
  },
github orbitjs / orbit / packages / @orbit / record-cache / src / operators / sync-inverse-patch-operators.ts View on Github external
removeFromRelatedRecords(
    cache: SyncRecordAccessor,
    op: RemoveFromRelatedRecordsOperation
  ): RecordOperation | undefined {
    const { record, relationship, relatedRecord } = op;
    const currentRelatedRecords = cache.getRelatedRecordsSync(
      record,
      relationship
    );

    if (
      currentRelatedRecords !== undefined &&
      recordsInclude(currentRelatedRecords, relatedRecord)
    ) {
      return {
        op: 'addToRelatedRecords',
        record,
        relationship,
        relatedRecord
      };
    }
    return;
  },