@openctx/client
Advanced tools
Comparing version 0.0.21 to 0.0.22
@@ -1,2 +0,2 @@ | ||
import { catchError, combineLatest, defer, from, map, mergeMap, of, startWith, tap, } from 'rxjs'; | ||
import { catchError, combineLatest, defer, distinctUntilChanged, from, map, mergeMap, of, startWith, tap, } from 'rxjs'; | ||
function observeProviderCall(providerClients, fn, { emitPartial, errorHook, logger }) { | ||
@@ -16,3 +16,3 @@ return providerClients.pipe(mergeMap(providerClients => providerClients && providerClients.length > 0 | ||
.pipe(map(items => (items || []).map(item => ({ ...item, providerUri: uri })))))) | ||
: of([])), map(result => result.filter((v) => v !== null).flat()), tap(items => { | ||
: of([])), map(result => result.filter((v) => v !== null).flat()), distinctUntilChanged((a, b) => JSON.stringify(a) === JSON.stringify(b)), tap(items => { | ||
if (LOG_VERBOSE) { | ||
@@ -19,0 +19,0 @@ logger?.(`got ${items.length} results: ${JSON.stringify(items)}`); |
@@ -125,7 +125,16 @@ import type { AnnotationsParams, ItemsParams, ItemsResult, MentionsParams, MentionsResult, MetaParams, MetaResult } from '@openctx/protocol'; | ||
/** | ||
* Get the candidate items returned by the configured providers. | ||
* Observe information about the configured providers using an async generator. | ||
* | ||
* The returned generator streams information as it is received from the providers and continues | ||
* passing along any updates until {@link signal} is aborted. | ||
* | ||
* @internal | ||
*/ | ||
metaChanges__asyncGenerator(params: MetaParams, opts?: ProviderMethodOptions, signal?: AbortSignal): AsyncGenerator<EachWithProviderUri<MetaResult[]>>; | ||
/** | ||
* Get the mentions returned by the configured providers. | ||
* | ||
* It does not continue to listen for changes, as {@link Client.mentionsChanges} does. Using | ||
* {@link Client.Mentions} is simpler and does not require use of observables (with a library | ||
* like RxJS), but it means that the client needs to manually poll for updated items if | ||
* like RxJS), but it means that the client needs to manually poll for updated mentions if | ||
* freshness is important. | ||
@@ -135,5 +144,5 @@ */ | ||
/** | ||
* Observe OpenCtx candidate items from the configured providers. | ||
* Observe OpenCtx mentions from the configured providers. | ||
* | ||
* The returned observable streams candidate items as they are received from the providers and | ||
* The returned observable streams mentions as they are received from the providers and | ||
* continues passing along any updates until unsubscribed. | ||
@@ -143,2 +152,11 @@ */ | ||
/** | ||
* Observe OpenCtx mentions from the configured providers using an async generator. | ||
* | ||
* The returned generator streams mentions as they are received from the providers and continues | ||
* passing along any updates until {@link signal} is aborted. | ||
* | ||
* @internal | ||
*/ | ||
mentionsChanges__asyncGenerator(params: MentionsParams, opts?: ProviderMethodOptions, signal?: AbortSignal): AsyncGenerator<EachWithProviderUri<MentionsResult>>; | ||
/** | ||
* Get the items returned by the configured providers. | ||
@@ -160,2 +178,12 @@ * | ||
/** | ||
* Observe OpenCtx items from the configured providers for the given resource using an async | ||
* generator. | ||
* | ||
* The returned generator streams items as they are received from the providers and continues | ||
* passing along any updates until {@link signal} is aborted. | ||
* | ||
* @internal | ||
*/ | ||
itemsChanges__asyncGenerator(params: ItemsParams, opts?: ProviderMethodOptions, signal?: AbortSignal): AsyncGenerator<EachWithProviderUri<ItemsResult>>; | ||
/** | ||
* Get the annotations returned by the configured providers for the given resource. | ||
@@ -177,2 +205,12 @@ * | ||
/** | ||
* Observe OpenCtx annotations from the configured providers for the given resource using an | ||
* async generator. | ||
* | ||
* The returned generator streams annotations as they are received from the providers and | ||
* continues passing along any updates until {@link signal} is aborted. | ||
* | ||
* @internal | ||
*/ | ||
annotationsChanges__asyncGenerator(params: AnnotationsParams, opts?: ProviderMethodOptions, signal?: AbortSignal): AsyncGenerator<EachWithProviderUri<Annotation<R>[]>>; | ||
/** | ||
* Dispose of the client and release all resources. | ||
@@ -179,0 +217,0 @@ */ |
@@ -6,2 +6,3 @@ import { LRUCache } from 'lru-cache'; | ||
import { createProviderClient } from '../providerClient/createProviderClient.js'; | ||
import { observableToAsyncGenerator } from './util.js'; | ||
/** | ||
@@ -97,2 +98,3 @@ * Create a new OpenCtx client. | ||
metaChanges: (params, opts) => metaChanges(params, { ...opts, emitPartial: true }), | ||
metaChanges__asyncGenerator: (params, opts, signal) => observableToAsyncGenerator(metaChanges(params, { ...opts, emitPartial: true }), signal), | ||
mentions: (params, opts) => firstValueFrom(mentionsChanges(params, { ...opts, emitPartial: false }), { | ||
@@ -102,2 +104,3 @@ defaultValue: [], | ||
mentionsChanges: (params, opts) => mentionsChanges(params, { ...opts, emitPartial: true }), | ||
mentionsChanges__asyncGenerator: (params, opts, signal) => observableToAsyncGenerator(mentionsChanges(params, { ...opts, emitPartial: true }), signal), | ||
items: (params, opts) => firstValueFrom(itemsChanges(params, { ...opts, emitPartial: false }), { | ||
@@ -107,2 +110,3 @@ defaultValue: [], | ||
itemsChanges: (params, opts) => itemsChanges(params, { ...opts, emitPartial: true }), | ||
itemsChanges__asyncGenerator: (params, opts, signal) => observableToAsyncGenerator(itemsChanges(params, { ...opts, emitPartial: true }), signal), | ||
annotations: (params, opts) => firstValueFrom(annotationsChanges(params, { ...opts, emitPartial: false }), { | ||
@@ -112,2 +116,3 @@ defaultValue: [], | ||
annotationsChanges: (params, opts) => annotationsChanges(params, { ...opts, emitPartial: true }), | ||
annotationsChanges__asyncGenerator: (params, opts, signal) => observableToAsyncGenerator(annotationsChanges(params, { ...opts, emitPartial: true }), signal), | ||
dispose() { | ||
@@ -114,0 +119,0 @@ for (const sub of subscriptions) { |
{ | ||
"name": "@openctx/client", | ||
"version": "0.0.21", | ||
"version": "0.0.22", | ||
"description": "OpenCtx client library", | ||
@@ -25,5 +25,5 @@ "license": "Apache-2.0", | ||
"rxjs": "^7.8.1", | ||
"@openctx/schema": "0.0.12", | ||
"@openctx/protocol": "0.0.16", | ||
"@openctx/provider": "0.0.15" | ||
"@openctx/provider": "0.0.15", | ||
"@openctx/schema": "0.0.12" | ||
}, | ||
@@ -30,0 +30,0 @@ "devDependencies": { |
@@ -18,2 +18,3 @@ import type { | ||
defer, | ||
distinctUntilChanged, | ||
from, | ||
@@ -103,2 +104,3 @@ map, | ||
map(result => result.filter((v): v is EachWithProviderUri<R[]> => v !== null).flat()), | ||
distinctUntilChanged((a, b) => JSON.stringify(a) === JSON.stringify(b)), | ||
tap(items => { | ||
@@ -105,0 +107,0 @@ if (LOG_VERBOSE) { |
@@ -48,2 +48,3 @@ import type { | ||
import { type ProviderClient, createProviderClient } from '../providerClient/createProviderClient.js' | ||
import { observableToAsyncGenerator } from './util.js' | ||
@@ -180,7 +181,21 @@ /** | ||
/** | ||
* Get the candidate items returned by the configured providers. | ||
* Observe information about the configured providers using an async generator. | ||
* | ||
* The returned generator streams information as it is received from the providers and continues | ||
* passing along any updates until {@link signal} is aborted. | ||
* | ||
* @internal | ||
*/ | ||
metaChanges__asyncGenerator( | ||
params: MetaParams, | ||
opts?: ProviderMethodOptions, | ||
signal?: AbortSignal, | ||
): AsyncGenerator<EachWithProviderUri<MetaResult[]>> | ||
/** | ||
* Get the mentions returned by the configured providers. | ||
* | ||
* It does not continue to listen for changes, as {@link Client.mentionsChanges} does. Using | ||
* {@link Client.Mentions} is simpler and does not require use of observables (with a library | ||
* like RxJS), but it means that the client needs to manually poll for updated items if | ||
* like RxJS), but it means that the client needs to manually poll for updated mentions if | ||
* freshness is important. | ||
@@ -194,5 +209,5 @@ */ | ||
/** | ||
* Observe OpenCtx candidate items from the configured providers. | ||
* Observe OpenCtx mentions from the configured providers. | ||
* | ||
* The returned observable streams candidate items as they are received from the providers and | ||
* The returned observable streams mentions as they are received from the providers and | ||
* continues passing along any updates until unsubscribed. | ||
@@ -206,2 +221,16 @@ */ | ||
/** | ||
* Observe OpenCtx mentions from the configured providers using an async generator. | ||
* | ||
* The returned generator streams mentions as they are received from the providers and continues | ||
* passing along any updates until {@link signal} is aborted. | ||
* | ||
* @internal | ||
*/ | ||
mentionsChanges__asyncGenerator( | ||
params: MentionsParams, | ||
opts?: ProviderMethodOptions, | ||
signal?: AbortSignal, | ||
): AsyncGenerator<EachWithProviderUri<MentionsResult>> | ||
/** | ||
* Get the items returned by the configured providers. | ||
@@ -228,2 +257,17 @@ * | ||
/** | ||
* Observe OpenCtx items from the configured providers for the given resource using an async | ||
* generator. | ||
* | ||
* The returned generator streams items as they are received from the providers and continues | ||
* passing along any updates until {@link signal} is aborted. | ||
* | ||
* @internal | ||
*/ | ||
itemsChanges__asyncGenerator( | ||
params: ItemsParams, | ||
opts?: ProviderMethodOptions, | ||
signal?: AbortSignal, | ||
): AsyncGenerator<EachWithProviderUri<ItemsResult>> | ||
/** | ||
* Get the annotations returned by the configured providers for the given resource. | ||
@@ -253,2 +297,17 @@ * | ||
/** | ||
* Observe OpenCtx annotations from the configured providers for the given resource using an | ||
* async generator. | ||
* | ||
* The returned generator streams annotations as they are received from the providers and | ||
* continues passing along any updates until {@link signal} is aborted. | ||
* | ||
* @internal | ||
*/ | ||
annotationsChanges__asyncGenerator( | ||
params: AnnotationsParams, | ||
opts?: ProviderMethodOptions, | ||
signal?: AbortSignal, | ||
): AsyncGenerator<EachWithProviderUri<Annotation<R>[]>> | ||
/** | ||
* Dispose of the client and release all resources. | ||
@@ -415,2 +474,4 @@ */ | ||
metaChanges: (params, opts) => metaChanges(params, { ...opts, emitPartial: true }), | ||
metaChanges__asyncGenerator: (params, opts, signal) => | ||
observableToAsyncGenerator(metaChanges(params, { ...opts, emitPartial: true }), signal), | ||
mentions: (params, opts) => | ||
@@ -421,2 +482,4 @@ firstValueFrom(mentionsChanges(params, { ...opts, emitPartial: false }), { | ||
mentionsChanges: (params, opts) => mentionsChanges(params, { ...opts, emitPartial: true }), | ||
mentionsChanges__asyncGenerator: (params, opts, signal) => | ||
observableToAsyncGenerator(mentionsChanges(params, { ...opts, emitPartial: true }), signal), | ||
items: (params, opts) => | ||
@@ -427,2 +490,4 @@ firstValueFrom(itemsChanges(params, { ...opts, emitPartial: false }), { | ||
itemsChanges: (params, opts) => itemsChanges(params, { ...opts, emitPartial: true }), | ||
itemsChanges__asyncGenerator: (params, opts, signal) => | ||
observableToAsyncGenerator(itemsChanges(params, { ...opts, emitPartial: true }), signal), | ||
annotations: (params, opts) => | ||
@@ -433,2 +498,7 @@ firstValueFrom(annotationsChanges(params, { ...opts, emitPartial: false }), { | ||
annotationsChanges: (params, opts) => annotationsChanges(params, { ...opts, emitPartial: true }), | ||
annotationsChanges__asyncGenerator: (params, opts, signal) => | ||
observableToAsyncGenerator( | ||
annotationsChanges(params, { ...opts, emitPartial: true }), | ||
signal, | ||
), | ||
dispose() { | ||
@@ -435,0 +505,0 @@ for (const sub of subscriptions) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
138845
63
2224