@ahoo-wang/fetcher-wow
Version:
Support for Wow(https://github.com/Ahoo-Wang/Wow) in Fetcher
138 lines • 6.28 kB
TypeScript
import { EventStreamQueryApi } from './eventStreamQueryApi';
import { Condition } from '../condition';
import { ListQuery, PagedList, PagedQuery } from '../queryable';
import { DomainEventStream } from './domainEventStream';
import { JsonServerSentEvent } from '@ahoo-wang/fetcher-eventstream';
import { ApiMetadata, ApiMetadataCapable } from '@ahoo-wang/fetcher-decorator';
/**
* Client for querying event streams through HTTP endpoints.
* Extends QueryClient and implements EventStreamQueryApi to provide methods
* for querying domain event streams with different query patterns.
* This client supports counting, listing, streaming, and paging operations on event streams.
*
* @example
* ```typescript
* // Create client options configuration
* const clientOptions: ClientOptions = {
* fetcher: new Fetcher({ baseURL: 'http://localhost:8080/' }),
* basePath: 'owner/{ownerId}/cart'
* };
*
* // Create an event stream query client instance
* const eventStreamQueryClient = new EventStreamQueryClient(clientOptions);
*
* // Count event streams
* const count = await eventStreamQueryClient.count(all());
*
* // List event streams
* const listQuery: ListQuery = {
* condition: all()
* };
* const list = await eventStreamQueryClient.list(listQuery);
*
* // List event streams as stream
* const listStream = await eventStreamQueryClient.listStream(listQuery);
* for await (const event of listStream) {
* const domainEventStream = event.data;
* console.log('Received:', domainEventStream);
* }
*
* // Paged event streams
* const pagedQuery: PagedQuery = {
* condition: all()
* };
* const paged = await eventStreamQueryClient.paged(pagedQuery);
* ```
*/
export declare class EventStreamQueryClient<DomainEventBody = any, FIELDS extends string = string> implements EventStreamQueryApi<DomainEventBody, FIELDS>, ApiMetadataCapable {
readonly apiMetadata?: ApiMetadata | undefined;
/**
* Creates a new EventStreamQueryClient instance.
*/
constructor(apiMetadata?: ApiMetadata | undefined);
/**
* Counts the number of domain event streams that match the given condition.
*
* @param condition - The condition to filter event streams
* @param attributes - Optional shared attributes that can be accessed by interceptors
* throughout the request lifecycle. These attributes allow passing
* custom data between different interceptors.
* @returns A promise that resolves to the count of matching event streams
*
* @example
* ```typescript
* const count = await eventStreamQueryClient.count(all());
* console.log('Total event streams:', count);
* ```
*/
count(condition: Condition<FIELDS>, attributes?: Record<string, any>): Promise<number>;
/**
* Retrieves a list of domain event streams based on the provided query parameters.
*
* @param listQuery - The query parameters for listing event streams
* @param attributes - Optional shared attributes that can be accessed by interceptors
* throughout the request lifecycle. These attributes allow passing
* custom data between different interceptors.
* @returns A promise that resolves to an array of partial domain event streams
*
* @example
* ```typescript
* const listQuery: ListQuery = {
* condition: all()
* };
* const list = await eventStreamQueryClient.list(listQuery);
* for (const domainEventStream of list) {
* console.log('Event stream:', domainEventStream);
* }
* ```
*/
list<T extends Partial<DomainEventStream<DomainEventBody>> = DomainEventStream<DomainEventBody>>(listQuery: ListQuery<FIELDS>, attributes?: Record<string, any>): Promise<T[]>;
/**
* Retrieves a stream of domain event streams based on the provided query parameters.
* Sets the Accept header to text/event-stream to indicate that the response should be streamed.
*
* @param listQuery - The query parameters for listing event streams
* @param attributes - Optional shared attributes that can be accessed by interceptors
* throughout the request lifecycle. These attributes allow passing
* custom data between different interceptors.
* @returns A promise that resolves to a readable stream of JSON server-sent events containing partial domain event streams
*
* @example
* ```typescript
* const listQuery: ListQuery = {
* condition: all()
* };
* const listStream = await eventStreamQueryClient.listStream(listQuery);
* for await (const event of listStream) {
* const domainEventStream = event.data;
* console.log('Received event stream:', domainEventStream);
* }
* ```
*/
listStream<T extends Partial<DomainEventStream<DomainEventBody>> = DomainEventStream<DomainEventBody>>(listQuery: ListQuery<FIELDS>, attributes?: Record<string, any>): Promise<ReadableStream<JsonServerSentEvent<T>>>;
/**
* Retrieves a paged list of domain event streams based on the provided query parameters.
*
* @param pagedQuery - The query parameters for paging event streams
* @param attributes - Optional shared attributes that can be accessed by interceptors
* throughout the request lifecycle. These attributes allow passing
* custom data between different interceptors.
* @returns A promise that resolves to a paged list of partial domain event streams
*
* @example
* ```typescript
* const pagedQuery: PagedQuery = {
* condition: all(),
* limit: 10,
* offset: 0
* };
* const paged = await eventStreamQueryClient.paged(pagedQuery);
* console.log('Total:', paged.total);
* for (const domainEventStream of paged.list) {
* console.log('Event stream:', domainEventStream);
* }
* ```
*/
paged<T extends Partial<DomainEventStream<DomainEventBody>> = DomainEventStream<DomainEventBody>>(pagedQuery: PagedQuery<FIELDS>, attributes?: Record<string, any>): Promise<PagedList<T>>;
}
//# sourceMappingURL=eventStreamQueryClient.d.ts.map