How to use the @orbit/data.QueryExpressionParseError 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 / queries.ts View on Github external
function parseSortExpression(source: JSONAPISource, sortExpression) {
  if (sortExpression.field.op === 'attribute') {
    const [attribute] = sortExpression.field.args;
    // Note: We don't know the `type` of the attribute here, so passing `null`
    const resourceAttribute = source.serializer.resourceAttribute(null, attribute);
    return (sortExpression.order === 'descending' ? '-' : '') + resourceAttribute;
  }
  throw new QueryExpressionParseError('Query expression could not be parsed.', sortExpression.field);
}
github orbitjs / orbit / packages / @orbit / jsonapi / src / lib / get-operators.ts View on Github external
return sortSpecifiers.map(sortSpecifier => {
    if (sortSpecifier.kind === 'attribute') {
      const attributeSort = sortSpecifier as AttributeSortSpecifier;

      // Note: We don't know the `type` of the attribute here, so passing `null`
      const resourceAttribute = source.serializer.resourceAttribute(null, attributeSort.attribute);
      return (sortSpecifier.order === 'descending' ? '-' : '') + resourceAttribute;
    }
    throw new QueryExpressionParseError(`Sort specifier ${sortSpecifier.kind} not recognized for JSONAPISource.`, sortSpecifier);
  }).join(',');
}
github orbitjs / orbit / packages / @orbit / jsonapi / src / jsonapi-url-builder.ts View on Github external
.map(sortSpecifier => {
        if (sortSpecifier.kind === 'attribute') {
          const attributeSort = sortSpecifier as AttributeSortSpecifier;

          // Note: We don't know the `type` of the attribute here, so passing `null`
          const resourceAttribute = this.serializer.resourceAttribute(
            null,
            attributeSort.attribute
          );
          return (
            (sortSpecifier.order === 'descending' ? '-' : '') +
            resourceAttribute
          );
        }
        throw new QueryExpressionParseError(
          `Sort specifier ${sortSpecifier.kind} not recognized for JSONAPISource.`,
          sortSpecifier
        );
      })
      .join(',');
github orbitjs / orbit / packages / @orbit / record-cache / src / operators / sync-query-operators.ts View on Github external
)
        );
      case 'all':
        return expected.every(e =>
          actual.some(a => a.id === e.id && a.type === e.type)
        );
      case 'some':
        return expected.some(e =>
          actual.some(a => a.id === e.id && a.type === e.type)
        );
      case 'none':
        return !expected.some(e =>
          actual.some(a => a.id === e.id && a.type === e.type)
        );
      default:
        throw new QueryExpressionParseError(
          'Filter operation ${filter.op} not recognized for Store.',
          filter
        );
    }
  } else if (filter.kind === 'relatedRecord') {
    let relation = deepGet(record, ['relationships', filter.relation]);
    let actual = relation === undefined ? undefined : relation.data;
    let expected = filter.record;
    switch (filter.op) {
      case 'equal':
        if (Array.isArray(expected)) {
          return (
            actual !== undefined &&
            expected.some(e => actual.type === e.type && actual.id === e.id)
          );
        } else {
github orbitjs / orbit / packages / @orbit / record-cache / src / operators / async-query-operators.ts View on Github external
switch (filter.op) {
      case 'equal':
        if (Array.isArray(expected)) {
          return (
            actual !== undefined &&
            expected.some(e => actual.type === e.type && actual.id === e.id)
          );
        } else {
          return (
            actual !== undefined &&
            actual.type === expected.type &&
            actual.id === expected.id
          );
        }
      default:
        throw new QueryExpressionParseError(
          'Filter operation ${filter.op} not recognized for Store.',
          filter
        );
    }
  }
  return false;
}
github orbitjs / orbit / packages / @orbit / record-cache / src / operators / sync-query-operators.ts View on Github external
function paginateRecords(records: Record[], paginationOptions: any) {
  if (paginationOptions.limit !== undefined) {
    let offset =
      paginationOptions.offset === undefined ? 0 : paginationOptions.offset;
    let limit = paginationOptions.limit;

    return records.slice(offset, offset + limit);
  } else {
    throw new QueryExpressionParseError(
      'Pagination options not recognized for Store. Please specify `offset` and `limit`.',
      paginationOptions
    );
  }
}
github orbitjs / orbit / packages / @orbit / record-cache / src / operators / async-query-operators.ts View on Github external
function paginateRecords(records: Record[], paginationOptions: any) {
  if (paginationOptions.limit !== undefined) {
    let offset =
      paginationOptions.offset === undefined ? 0 : paginationOptions.offset;
    let limit = paginationOptions.limit;

    return records.slice(offset, offset + limit);
  } else {
    throw new QueryExpressionParseError(
      'Pagination options not recognized for Store. Please specify `offset` and `limit`.',
      paginationOptions
    );
  }
}
github orbitjs / orbit / packages / @orbit / jsonapi / src / lib / queries.ts View on Github external
function buildRequestFromExpression(source: JSONAPISource, expression, request = {}): any {
  if (ExpressionToRequestMap[expression.op]) {
    ExpressionToRequestMap[expression.op](source, expression, request);
  } else {
    throw new QueryExpressionParseError('Query expression could not be parsed.', expression);
  }

  return request;
}