Skip to content

Commit

Permalink
Improve LiveQuery typings
Browse files Browse the repository at this point in the history
* Don't allow fullResponse request options
* Use generics to allow more refined typing of return values
  • Loading branch information
dgeb committed Feb 8, 2021
1 parent 7b9e73b commit fc43302
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/@orbit/record-cache/src/async-record-cache.ts
Expand Up @@ -325,7 +325,7 @@ export abstract class AsyncRecordCache<

liveQuery(
queryOrExpressions: RecordQueryOrExpressions,
options?: RequestOptions,
options?: DefaultRequestOptions<QueryOptions>,
id?: string
): AsyncLiveQuery {
const query = buildQuery(
Expand Down
Expand Up @@ -16,7 +16,9 @@ export class AsyncLiveQueryUpdate {
this._query = settings.query;
}

query(): Promise<RecordQueryResult> {
query<Result extends RecordQueryResult = RecordQueryResult>(): Promise<
Result
> {
return this._cache.query(this._query);
}
}
Expand Down Expand Up @@ -44,7 +46,9 @@ export class AsyncLiveQuery extends LiveQuery {
this.cache = settings.cache;
}

async query(): Promise<RecordQueryResult> {
query<Result extends RecordQueryResult = RecordQueryResult>(): Promise<
Result
> {
return this._update.query();
}

Expand Down
Expand Up @@ -16,7 +16,7 @@ export class SyncLiveQueryUpdate {
this._query = settings.query;
}

query(): RecordQueryResult {
query<Result extends RecordQueryResult = RecordQueryResult>(): Result {
return this._cache.query(this._query);
}
}
Expand Down Expand Up @@ -44,8 +44,8 @@ export class SyncLiveQuery extends LiveQuery {
this.cache = settings.cache;
}

query(): RecordQueryResult {
return this._update.query();
query<Result extends RecordQueryResult = RecordQueryResult>(): Result {
return this._update.query<Result>();
}

subscribe(cb: (update: SyncLiveQueryUpdate) => void): () => void {
Expand Down
2 changes: 1 addition & 1 deletion packages/@orbit/record-cache/src/sync-record-cache.ts
Expand Up @@ -312,7 +312,7 @@ export abstract class SyncRecordCache<

liveQuery(
queryOrExpressions: RecordQueryOrExpressions,
options?: RequestOptions,
options?: DefaultRequestOptions<QueryOptions>,
id?: string
): SyncLiveQuery {
const query = buildQuery(
Expand Down

0 comments on commit fc43302

Please sign in to comment.