UNPKG

@eclipse-ditto/ditto-javascript-client-dom

Version:

DOM implementation of Eclipse Ditto JavaScript API to be used in browsers.

300 lines 10.8 kB
/*! * Copyright (c) 2019 Contributors to the Eclipse Foundation * * See the NOTICE file(s) distributed with this work for additional * information regarding copyright ownership. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0 * * SPDX-License-Identifier: EPL-2.0 */ import { Filter } from './filter.options'; export interface RequestOptions { /** * Provides the specified URL options. * * @returns The string to attach to the URL */ getOptions(): Map<string, string>; /** * Provides the specified header options. * * @returns The headers */ getHeaders(): Map<string, string>; } export interface AddRequestOptions<T extends AddRequestOptions<T>> extends RequestOptions { /** * Adds a URl option. * * @param id - The ID of the option to add. * @param value - The body of the option to add. */ addRequestParameter(id: string, value: string): T; /** * Adds a header option. * * @param name - The name of the header to add. * @param value - The body of the header to add. */ addHeader(name: string, value: string): T; } /** * Option provider for options. Options will be replaced if methods are called multiple times. */ export declare abstract class AbstractRequestOptions<T extends AbstractRequestOptions<T>> implements AddRequestOptions<T> { private readonly options; private readonly headers; protected constructor(); getOptions(): Map<string, string>; getHeaders(): Map<string, string>; addRequestParameter(id: string, value: string): T; addHeader(name: string, value: string): T; } export interface HasMatch<T extends HasMatch<T>> { /** * Sets an If-Match option. * * @param tag - The tags to match. * @returns This Options instance with the added option */ ifMatch(...tag: string[]): T; /** * Shortcut for If-Match: * * @returns This Options instance with the added option */ ifMatchAny(): T; /** * Sets an If-None-Match option. * * @param tag - The tags to match. * @returns This Options instance with the added option */ ifNoneMatch(...tag: string[]): T; /** * Shortcut for If-None-Match: * * @returns This Options instance with the added option */ ifNoneMatchAny(): T; } export interface HasFields<T extends HasFields<T>> { /** * Sets a fields option. * * @param fields - The fields to return. * @returns This Options instance with the added option */ withFields(...fields: string[]): T; } export interface HasFilterAndNamespace<T extends HasFilterAndNamespace<T>> { /** * Sets a filter option. * * @param rawFilterString - The string to filter by. * @returns This Options instance with the added option */ withRawFilter(rawFilterString: string): T; /** * Sets a filter option. * * @param filter - The instance of Filter to use. * @returns This Options instance with the added option */ withFilter(filter: Filter): T; /** * Sets a namespaces option. * * @param namespaces - The namespaces to set. * @returns This Options instance with the added option */ withNamespaces(...namespaces: string[]): T; } export interface RequestOptionsWithMatchOptions<T extends RequestOptionsWithMatchOptions<T>> extends AddRequestOptions<RequestOptionsWithMatchOptions<T>>, HasMatch<RequestOptionsWithMatchOptions<T>> { } export declare abstract class AbstractRequestOptionsWithMatchOptions<T extends AbstractRequestOptionsWithMatchOptions<T>> extends AbstractRequestOptions<AbstractRequestOptionsWithMatchOptions<T>> implements RequestOptionsWithMatchOptions<AbstractRequestOptionsWithMatchOptions<T>> { ifMatch(...tags: string[]): T; ifNoneMatch(...tags: string[]): T; ifMatchAny(): T; ifNoneMatchAny(): T; } /** * Option provider for If-Match / If-None-Match headers */ export interface MatchOptions extends RequestOptionsWithMatchOptions<MatchOptions> { } export declare class DefaultMatchOptions extends AbstractRequestOptionsWithMatchOptions<DefaultMatchOptions> implements MatchOptions { private constructor(); /** * Provides an instance of MatchOptions. * * @returns The MatchOptions */ static getInstance(): DefaultMatchOptions; } export declare class MatchOptionsHelper { static getWithMergeHeader(options?: MatchOptions): MatchOptions; } /** * Option provider for some get requests */ export interface FieldsOptions extends RequestOptionsWithMatchOptions<FieldsOptions>, HasFields<FieldsOptions> { withFields(...fields: string[]): FieldsOptions; } export declare class DefaultFieldsOptions extends AbstractRequestOptionsWithMatchOptions<DefaultFieldsOptions> implements FieldsOptions { private constructor(); /** * Provides an instance of FieldsOptions. * * @returns The FieldsOptions */ static getInstance(): DefaultFieldsOptions; withFields(...fields: string[]): DefaultFieldsOptions; } /** * Option provider for count requests */ export interface CountOptions extends AddRequestOptions<CountOptions>, HasFilterAndNamespace<CountOptions> { } export declare class DefaultCountOptions extends AbstractRequestOptions<DefaultCountOptions> implements CountOptions { protected constructor(); /** * Provides an instance of DefaultCountOptions. * * @returns The DefaultCountOptions */ static getInstance(): DefaultCountOptions; withRawFilter(rawFilterString: string): DefaultCountOptions; withFilter(filter: Filter): DefaultCountOptions; withNamespaces(...namespaces: string[]): DefaultCountOptions; } /** * Option provider for search requests */ export interface SearchOptions extends AddRequestOptions<SearchOptions>, HasFilterAndNamespace<SearchOptions>, HasFields<SearchOptions> { /** * @param offset - The index to start at. * @param count - The number of things to return. * @returns The instance of SearchOptions with the added option * * @Deprecated See {@link https://www.eclipse.dev/ditto/basic-search.html#rql-paging-deprecated} Use cursor pagination instead * Sets a limit option. */ withLimit(offset: number, count: number): SearchOptions; /** * Sets a sort option. * * @param sortOperation - The string to sort by. * @returns The instance of SearchOptions with the added option */ withSort(sortOperation: string): SearchOptions; /** * Sets a cursor option * * @param cursor - The cursor to use for pagination, returned by a previous search request */ withCursor(cursor: string): SearchOptions; /** * Sets the page size for pagination. * Only works with cursor pagination. * Maximum page size supported by ditto is 200. * @param pageSize Number of items to return per page */ withPageSize(pageSize: number): SearchOptions; } export declare class DefaultSearchOptions extends AbstractRequestOptions<DefaultSearchOptions> implements SearchOptions { /** * Map of name-value pairs to add to the request parameters as "option" */ private optionParameters; private constructor(); /** * Provides an instance of DefaultSearchOptions. * * @returns The DefaultSearchOptions */ static getInstance(): DefaultSearchOptions; withNamespaces(...namespaces: string[]): DefaultSearchOptions; withFields(...fields: string[]): DefaultSearchOptions; withRawFilter(rawFilterString: string): DefaultSearchOptions; withFilter(filter: Filter): DefaultSearchOptions; withLimit(offset: number, count: number): DefaultSearchOptions; withSort(sortOperation: string): DefaultSearchOptions; withCursor(cursor: string): DefaultSearchOptions; withPageSize(pageSize: number): DefaultSearchOptions; /** * Constructs the 'option' option out of the values of limit and sort. * * @returns The instance of DefaultSearchOptions with the constructed option */ private setOption; } /** * Option provider for get Things requests */ export interface GetThingsOptions extends AddRequestOptions<GetThingsOptions>, HasFields<GetThingsOptions> { setThingIds(ids: string[]): GetThingsOptions; } export declare class DefaultGetThingsOptions extends AbstractRequestOptions<DefaultGetThingsOptions> implements GetThingsOptions { private constructor(); /** * Provides an instance of GetThingsOptions. * * @returns The GetThingsOptions */ static getInstance(): DefaultGetThingsOptions; withFields(...fields: string[]): DefaultGetThingsOptions; setThingIds(ids: string[]): DefaultGetThingsOptions; } /** * Option provider for Messages requests */ export interface MessagesOptions extends AddRequestOptions<MessagesOptions> { /** * Sets a timeout option. * * @param timeout - The timeout in milliseconds to use. * @returns The instance of MessagesOptions with the added option */ withTimeout(timeout: number): MessagesOptions; } export declare class DefaultMessagesOptions extends AbstractRequestOptions<DefaultMessagesOptions> implements MessagesOptions { private constructor(); /** * Provides an instance of MessagesOptions. * * @returns The MessagesOptions */ static getInstance(): DefaultMessagesOptions; withTimeout(timeout: number): DefaultMessagesOptions; } /** * Option provider for post Connection requests */ export interface PostConnectionOptions extends AddRequestOptions<PostConnectionOptions> { /** * Sets a dry-run option to test a Connection. * * @param dryRun - If the connection should only be tested, but not already created. * @returns The instance of DefaultPostConnectionOptions with the added option */ asDryRun(dryRun: boolean): DefaultPostConnectionOptions; } export declare class DefaultPostConnectionOptions extends AbstractRequestOptions<DefaultPostConnectionOptions> implements PostConnectionOptions { private constructor(); /** * Provides an instance of DefaultPostConnectionOptions. * * @returns The DefaultPostConnectionOptions */ static getInstance(): DefaultPostConnectionOptions; /** * Gets an instance of DefaultPostConnectionOptions with the dry-run parameter set to true to test Connections. * * @returns The instance of MessagesOptions */ static getDryRunInstance(): DefaultPostConnectionOptions; asDryRun(dryRun: boolean): DefaultPostConnectionOptions; } //# sourceMappingURL=request.options.d.ts.map