@algolia/client-common 5.8.1 → 5.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/common.d.cts +562 -426
- package/dist/common.d.ts +562 -426
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +5 -5
- package/index.ts +0 -9
- package/src/__tests__/cache/browser-local-storage-cache.test.ts +0 -171
- package/src/__tests__/cache/fallbackable-cache.test.ts +0 -126
- package/src/__tests__/cache/memory-cache.test.ts +0 -82
- package/src/__tests__/cache/null-cache.test.ts +0 -47
- package/src/__tests__/create-iterable-promise.test.ts +0 -236
- package/src/__tests__/logger/null-logger.test.ts +0 -22
- package/src/cache/createBrowserLocalStorageCache.ts +0 -106
- package/src/cache/createFallbackableCache.ts +0 -43
- package/src/cache/createMemoryCache.ts +0 -43
- package/src/cache/createNullCache.ts +0 -29
- package/src/cache/index.ts +0 -4
- package/src/constants.ts +0 -7
- package/src/createAlgoliaAgent.ts +0 -18
- package/src/createAuth.ts +0 -25
- package/src/createIterablePromise.ts +0 -47
- package/src/getAlgoliaAgent.ts +0 -19
- package/src/logger/createNullLogger.ts +0 -15
- package/src/logger/index.ts +0 -1
- package/src/transporter/createStatefulHost.ts +0 -19
- package/src/transporter/createTransporter.ts +0 -315
- package/src/transporter/errors.ts +0 -77
- package/src/transporter/helpers.ts +0 -96
- package/src/transporter/index.ts +0 -6
- package/src/transporter/responses.ts +0 -13
- package/src/transporter/stackTrace.ts +0 -22
- package/src/types/cache.ts +0 -75
- package/src/types/createClient.ts +0 -15
- package/src/types/createIterablePromise.ts +0 -40
- package/src/types/host.ts +0 -43
- package/src/types/index.ts +0 -7
- package/src/types/logger.ts +0 -24
- package/src/types/requester.ts +0 -67
- package/src/types/transporter.ts +0 -153
package/src/types/host.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
export type Host = {
|
|
2
|
-
/**
|
|
3
|
-
* The host URL.
|
|
4
|
-
*/
|
|
5
|
-
url: string;
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* The accepted transporter.
|
|
9
|
-
*/
|
|
10
|
-
accept: 'read' | 'readWrite' | 'write';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* The protocol of the host URL.
|
|
14
|
-
*/
|
|
15
|
-
protocol: 'http' | 'https';
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* The port of the host URL.
|
|
19
|
-
*/
|
|
20
|
-
port?: number;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export type StatefulHost = Host & {
|
|
24
|
-
/**
|
|
25
|
-
* The status of the host.
|
|
26
|
-
*/
|
|
27
|
-
status: 'down' | 'timed out' | 'up';
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* The last update of the host status, used to compare with the expiration delay.
|
|
31
|
-
*/
|
|
32
|
-
lastUpdate: number;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Returns whether the host is up or not.
|
|
36
|
-
*/
|
|
37
|
-
isUp: () => boolean;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Returns whether the host is timed out or not.
|
|
41
|
-
*/
|
|
42
|
-
isTimedOut: () => boolean;
|
|
43
|
-
};
|
package/src/types/index.ts
DELETED
package/src/types/logger.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export const LogLevelEnum: Readonly<Record<string, LogLevelType>> = {
|
|
2
|
-
Debug: 1,
|
|
3
|
-
Info: 2,
|
|
4
|
-
Error: 3,
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
export type LogLevelType = 1 | 2 | 3;
|
|
8
|
-
|
|
9
|
-
export type Logger = {
|
|
10
|
-
/**
|
|
11
|
-
* Logs debug messages.
|
|
12
|
-
*/
|
|
13
|
-
debug: (message: string, args?: any) => Promise<void>;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Logs info messages.
|
|
17
|
-
*/
|
|
18
|
-
info: (message: string, args?: any) => Promise<void>;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Logs error messages.
|
|
22
|
-
*/
|
|
23
|
-
error: (message: string, args?: any) => Promise<void>;
|
|
24
|
-
};
|
package/src/types/requester.ts
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
export type Headers = Record<string, string>;
|
|
2
|
-
|
|
3
|
-
export type QueryParameters = Record<string, any>;
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* The method of the request.
|
|
7
|
-
*/
|
|
8
|
-
export type Method = 'DELETE' | 'GET' | 'PATCH' | 'POST' | 'PUT';
|
|
9
|
-
|
|
10
|
-
export type Request = {
|
|
11
|
-
method: Method;
|
|
12
|
-
/**
|
|
13
|
-
* The path of the REST API to send the request to.
|
|
14
|
-
*/
|
|
15
|
-
path: string;
|
|
16
|
-
queryParameters: QueryParameters;
|
|
17
|
-
data?: Array<Record<string, any>> | Record<string, any>;
|
|
18
|
-
headers: Headers;
|
|
19
|
-
/**
|
|
20
|
-
* If the given request should persist on the cache. Keep in mind,
|
|
21
|
-
* that some methods may have this option enabled by default.
|
|
22
|
-
*/
|
|
23
|
-
cacheable?: boolean;
|
|
24
|
-
/**
|
|
25
|
-
* Some POST methods in the Algolia REST API uses the `read` transporter.
|
|
26
|
-
* This information is defined at the spec level.
|
|
27
|
-
*/
|
|
28
|
-
useReadTransporter?: boolean;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export type EndRequest = Pick<Request, 'headers' | 'method'> & {
|
|
32
|
-
/**
|
|
33
|
-
* The full URL of the REST API.
|
|
34
|
-
*/
|
|
35
|
-
url: string;
|
|
36
|
-
/**
|
|
37
|
-
* The connection timeout, in milliseconds.
|
|
38
|
-
*/
|
|
39
|
-
connectTimeout: number;
|
|
40
|
-
/**
|
|
41
|
-
* The response timeout, in milliseconds.
|
|
42
|
-
*/
|
|
43
|
-
responseTimeout: number;
|
|
44
|
-
data?: string;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export type Response = {
|
|
48
|
-
/**
|
|
49
|
-
* The body of the response.
|
|
50
|
-
*/
|
|
51
|
-
content: string;
|
|
52
|
-
/**
|
|
53
|
-
* Whether the API call is timed out or not.
|
|
54
|
-
*/
|
|
55
|
-
isTimedOut: boolean;
|
|
56
|
-
/**
|
|
57
|
-
* The HTTP status code of the response.
|
|
58
|
-
*/
|
|
59
|
-
status: number;
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
export type Requester = {
|
|
63
|
-
/**
|
|
64
|
-
* Sends the given `request` to the server.
|
|
65
|
-
*/
|
|
66
|
-
send: (request: EndRequest) => Promise<Response>;
|
|
67
|
-
};
|
package/src/types/transporter.ts
DELETED
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
import type { Cache } from './cache';
|
|
2
|
-
import type { Host } from './host';
|
|
3
|
-
import type { Logger } from './logger';
|
|
4
|
-
import type { EndRequest, Headers, QueryParameters, Request, Requester, Response } from './requester';
|
|
5
|
-
|
|
6
|
-
export type RequestOptions = Pick<Request, 'cacheable'> & {
|
|
7
|
-
/**
|
|
8
|
-
* Custom timeout for the request. Note that, in normal situations
|
|
9
|
-
* the given timeout will be applied. But the transporter layer may
|
|
10
|
-
* increase this timeout if there is need for it.
|
|
11
|
-
*/
|
|
12
|
-
timeouts?: Partial<Timeouts>;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Custom headers for the request. This headers are
|
|
16
|
-
* going to be merged the transporter headers.
|
|
17
|
-
*/
|
|
18
|
-
headers?: Headers;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Custom query parameters for the request. This query parameters are
|
|
22
|
-
* going to be merged the transporter query parameters.
|
|
23
|
-
*/
|
|
24
|
-
queryParameters?: QueryParameters;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Custom data for the request. This data is
|
|
28
|
-
* going to be merged the transporter data.
|
|
29
|
-
*/
|
|
30
|
-
data?: Array<Record<string, any>> | Record<string, any>;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export type StackFrame = {
|
|
34
|
-
request: EndRequest;
|
|
35
|
-
response: Response;
|
|
36
|
-
host: Host;
|
|
37
|
-
triesLeft: number;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
export type AlgoliaAgentOptions = {
|
|
41
|
-
/**
|
|
42
|
-
* The segment. Usually the integration name.
|
|
43
|
-
*/
|
|
44
|
-
segment: string;
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* The version. Usually the integration version.
|
|
48
|
-
*/
|
|
49
|
-
version?: string;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
export type AlgoliaAgent = {
|
|
53
|
-
/**
|
|
54
|
-
* The raw value of the user agent.
|
|
55
|
-
*/
|
|
56
|
-
value: string;
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Mutates the current user agent adding the given user agent options.
|
|
60
|
-
*/
|
|
61
|
-
add: (options: AlgoliaAgentOptions) => AlgoliaAgent;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
export type Timeouts = {
|
|
65
|
-
/**
|
|
66
|
-
* Timeout in milliseconds before the connection is established.
|
|
67
|
-
*/
|
|
68
|
-
connect: number;
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Timeout in milliseconds before reading the response on a read request.
|
|
72
|
-
*/
|
|
73
|
-
read: number;
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Timeout in milliseconds before reading the response on a write request.
|
|
77
|
-
*/
|
|
78
|
-
write: number;
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
export type TransporterOptions = {
|
|
82
|
-
/**
|
|
83
|
-
* The cache of the hosts. Usually used to persist
|
|
84
|
-
* the state of the host when its down.
|
|
85
|
-
*/
|
|
86
|
-
hostsCache: Cache;
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* The logger instance to send events of the transporter.
|
|
90
|
-
*/
|
|
91
|
-
logger: Logger;
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* The underlying requester used. Should differ
|
|
95
|
-
* depending of the environment where the client
|
|
96
|
-
* will be used.
|
|
97
|
-
*/
|
|
98
|
-
requester: Requester;
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* The cache of the requests. When requests are
|
|
102
|
-
* `cacheable`, the returned promised persists
|
|
103
|
-
* in this cache to shared in similar requests
|
|
104
|
-
* before being resolved.
|
|
105
|
-
*/
|
|
106
|
-
requestsCache: Cache;
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* The cache of the responses. When requests are
|
|
110
|
-
* `cacheable`, the returned responses persists
|
|
111
|
-
* in this cache to shared in similar requests.
|
|
112
|
-
*/
|
|
113
|
-
responsesCache: Cache;
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* The timeouts used by the requester. The transporter
|
|
117
|
-
* layer may increase this timeouts as defined on the
|
|
118
|
-
* retry strategy.
|
|
119
|
-
*/
|
|
120
|
-
timeouts: Timeouts;
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* The hosts used by the requester.
|
|
124
|
-
*/
|
|
125
|
-
hosts: Host[];
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* The headers used by the requester. The transporter
|
|
129
|
-
* layer may add some extra headers during the request
|
|
130
|
-
* for the user agent, and others.
|
|
131
|
-
*/
|
|
132
|
-
baseHeaders: Headers;
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* The query parameters used by the requester. The transporter
|
|
136
|
-
* layer may add some extra headers during the request
|
|
137
|
-
* for the user agent, and others.
|
|
138
|
-
*/
|
|
139
|
-
baseQueryParameters: QueryParameters;
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* The user agent used. Sent on query parameters.
|
|
143
|
-
*/
|
|
144
|
-
algoliaAgent: AlgoliaAgent;
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
export type Transporter = TransporterOptions & {
|
|
148
|
-
/**
|
|
149
|
-
* Performs a request.
|
|
150
|
-
* The `baseRequest` and `baseRequestOptions` will be merged accordingly.
|
|
151
|
-
*/
|
|
152
|
-
request: <TResponse>(baseRequest: Request, baseRequestOptions?: RequestOptions) => Promise<TResponse>;
|
|
153
|
-
};
|