@algolia/client-common 4.14.2 → 5.0.0-alpha.3
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/client-common.cjs.js +803 -91
- package/dist/client-common.esm.node.js +774 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/src/cache/createBrowserLocalStorageCache.d.ts +3 -0
- package/dist/src/cache/createBrowserLocalStorageCache.d.ts.map +1 -0
- package/dist/src/cache/createFallbackableCache.d.ts +3 -0
- package/dist/src/cache/createFallbackableCache.d.ts.map +1 -0
- package/dist/src/cache/createMemoryCache.d.ts +3 -0
- package/dist/src/cache/createMemoryCache.d.ts.map +1 -0
- package/dist/src/cache/createNullCache.d.ts +3 -0
- package/dist/src/cache/createNullCache.d.ts.map +1 -0
- package/dist/src/cache/index.d.ts +5 -0
- package/dist/src/cache/index.d.ts.map +1 -0
- package/dist/src/constants.d.ts +7 -0
- package/dist/src/constants.d.ts.map +1 -0
- package/dist/src/createAlgoliaAgent.d.ts +3 -0
- package/dist/src/createAlgoliaAgent.d.ts.map +1 -0
- package/dist/src/createAuth.d.ts +6 -0
- package/dist/src/createAuth.d.ts.map +1 -0
- package/dist/src/createEchoRequester.d.ts +7 -0
- package/dist/src/createEchoRequester.d.ts.map +1 -0
- package/dist/src/createRetryablePromise.d.ts +14 -0
- package/dist/src/createRetryablePromise.d.ts.map +1 -0
- package/dist/src/getAlgoliaAgent.d.ts +8 -0
- package/dist/src/getAlgoliaAgent.d.ts.map +1 -0
- package/dist/src/transporter/createStatefulHost.d.ts +3 -0
- package/dist/src/transporter/createStatefulHost.d.ts.map +1 -0
- package/dist/src/transporter/createTransporter.d.ts +3 -0
- package/dist/src/transporter/createTransporter.d.ts.map +1 -0
- package/dist/src/transporter/errors.d.ts +21 -0
- package/dist/src/transporter/errors.d.ts.map +1 -0
- package/dist/src/transporter/helpers.d.ts +9 -0
- package/dist/src/transporter/helpers.d.ts.map +1 -0
- package/dist/src/transporter/index.d.ts +7 -0
- package/dist/src/transporter/index.d.ts.map +1 -0
- package/dist/src/transporter/responses.d.ts +5 -0
- package/dist/src/transporter/responses.d.ts.map +1 -0
- package/dist/src/transporter/stackTrace.d.ts +4 -0
- package/dist/src/transporter/stackTrace.d.ts.map +1 -0
- package/dist/src/types/Cache.d.ts +47 -0
- package/dist/src/types/Cache.d.ts.map +1 -0
- package/dist/src/types/CreateClient.d.ts +12 -0
- package/dist/src/types/CreateClient.d.ts.map +1 -0
- package/dist/src/types/CreateRetryablePromise.d.ts +19 -0
- package/dist/src/types/CreateRetryablePromise.d.ts.map +1 -0
- package/dist/src/types/Host.d.ts +33 -0
- package/dist/src/types/Host.d.ts.map +1 -0
- package/dist/src/types/Requester.d.ts +66 -0
- package/dist/src/types/Requester.d.ts.map +1 -0
- package/dist/src/types/Transporter.d.ts +128 -0
- package/dist/src/types/Transporter.d.ts.map +1 -0
- package/dist/src/types/index.d.ts +7 -0
- package/dist/src/types/index.d.ts.map +1 -0
- package/index.ts +9 -0
- package/package.json +24 -15
- package/src/__tests__/cache/browser-local-storage-cache.test.ts +134 -0
- package/src/__tests__/cache/fallbackable-cache.test.ts +126 -0
- package/src/__tests__/cache/memory-cache.test.ts +90 -0
- package/src/__tests__/cache/null-cache.test.ts +49 -0
- package/src/__tests__/create-retryable-promise.test.ts +86 -0
- package/src/cache/createBrowserLocalStorageCache.ts +74 -0
- package/src/cache/createFallbackableCache.ts +53 -0
- package/src/cache/createMemoryCache.ts +56 -0
- package/src/cache/createNullCache.ts +34 -0
- package/src/cache/index.ts +4 -0
- package/src/constants.ts +7 -0
- package/src/createAlgoliaAgent.ts +20 -0
- package/src/createAuth.ts +25 -0
- package/src/createEchoRequester.ts +59 -0
- package/src/createRetryablePromise.ts +52 -0
- package/src/getAlgoliaAgent.ts +25 -0
- package/src/transporter/createStatefulHost.ts +24 -0
- package/src/transporter/createTransporter.ts +347 -0
- package/src/transporter/errors.ts +51 -0
- package/src/transporter/helpers.ts +119 -0
- package/src/transporter/index.ts +6 -0
- package/src/transporter/responses.ts +23 -0
- package/src/transporter/stackTrace.ts +30 -0
- package/src/types/Cache.ts +61 -0
- package/src/types/CreateClient.ts +23 -0
- package/src/types/CreateRetryablePromise.ts +21 -0
- package/src/types/Host.ts +38 -0
- package/src/types/Requester.ts +72 -0
- package/src/types/Transporter.ts +153 -0
- package/src/types/index.ts +6 -0
- package/dist/client-common.d.ts +0 -102
- package/dist/client-common.esm.js +0 -89
- package/index.js +0 -2
package/dist/client-common.d.ts
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { Headers } from '@algolia/transporter';
|
|
2
|
-
import { HostOptions } from '@algolia/transporter';
|
|
3
|
-
import { QueryParameters } from '@algolia/transporter';
|
|
4
|
-
import { RequestOptions } from '@algolia/transporter';
|
|
5
|
-
import { Transporter } from '@algolia/transporter';
|
|
6
|
-
import { TransporterOptions } from '@algolia/transporter';
|
|
7
|
-
|
|
8
|
-
declare type AddedMethods<TBase, TMethods extends Methods<TBase>> = TBase & {
|
|
9
|
-
[TKey in keyof TMethods extends string ? keyof TMethods : never]: ReturnType<TMethods[TKey]>;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export declare function addMethods<TBase extends {}, TMethods extends Methods<TBase>>(base: TBase, methods?: TMethods): AddedMethods<TBase, TMethods>;
|
|
13
|
-
|
|
14
|
-
export declare type Auth = {
|
|
15
|
-
/**
|
|
16
|
-
* Returns the headers related to auth. Should be
|
|
17
|
-
* merged to the transporter headers.
|
|
18
|
-
*/
|
|
19
|
-
readonly headers: () => Readonly<Record<string, string>>;
|
|
20
|
-
/**
|
|
21
|
-
* Returns the query parameters related to auth. Should be
|
|
22
|
-
* merged to the query parameters headers.
|
|
23
|
-
*/
|
|
24
|
-
readonly queryParameters: () => Readonly<Record<string, string>>;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export declare const AuthMode: Readonly<Record<string, AuthModeType>>;
|
|
28
|
-
|
|
29
|
-
export declare type AuthModeType = 0 | 1;
|
|
30
|
-
|
|
31
|
-
export declare type ClientTransporterOptions = Pick<TransporterOptions, Exclude<keyof TransporterOptions, 'headers'> & Exclude<keyof TransporterOptions, 'queryParameters'> & Exclude<keyof TransporterOptions, 'hosts'>> & {
|
|
32
|
-
/**
|
|
33
|
-
* The hosts used by the requester.
|
|
34
|
-
*/
|
|
35
|
-
readonly hosts?: readonly HostOptions[];
|
|
36
|
-
/**
|
|
37
|
-
* The headers used by the requester. The transporter
|
|
38
|
-
* layer may add some extra headers during the request
|
|
39
|
-
* for the user agent, and others.
|
|
40
|
-
*/
|
|
41
|
-
readonly headers?: Headers;
|
|
42
|
-
/**
|
|
43
|
-
* The query parameters used by the requester. The transporter
|
|
44
|
-
* layer may add some extra headers during the request
|
|
45
|
-
* for the user agent, and others.
|
|
46
|
-
*/
|
|
47
|
-
readonly queryParameters?: QueryParameters;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
export declare function createAuth(authMode: AuthModeType, appId: string, apiKey: string): Auth;
|
|
51
|
-
|
|
52
|
-
export declare type CreateClient<TClient, TOptions> = <TMethods extends {
|
|
53
|
-
readonly [key: string]: (base: TClient) => (...args: any) => any;
|
|
54
|
-
}>(options: TOptions & {
|
|
55
|
-
readonly methods?: TMethods;
|
|
56
|
-
}) => TClient & {
|
|
57
|
-
[key in keyof TMethods extends string ? keyof TMethods : never]: ReturnType<TMethods[key]>;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
export declare function createRetryablePromise<TResponse>(callback: (retry: () => Promise<TResponse>) => Promise<TResponse>): Promise<TResponse>;
|
|
61
|
-
|
|
62
|
-
export declare function createWaitablePromise<TResponse>(promise: Readonly<Promise<TResponse>>, wait?: Wait<TResponse>): Readonly<WaitablePromise<TResponse>>;
|
|
63
|
-
|
|
64
|
-
export declare const destroy: (base: {
|
|
65
|
-
readonly transporter: Transporter;
|
|
66
|
-
}) => () => Readonly<Promise<void>>;
|
|
67
|
-
|
|
68
|
-
export declare function encode(format: string, ...args: readonly any[]): string;
|
|
69
|
-
|
|
70
|
-
declare type Methods<TBase> = {
|
|
71
|
-
readonly [key: string]: (base: TBase) => (...args: any[]) => any;
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
export declare function shuffle<TData>(array: TData[]): TData[];
|
|
75
|
-
|
|
76
|
-
export declare const version = "4.14.2";
|
|
77
|
-
|
|
78
|
-
export declare type Wait<TResponse> = (
|
|
79
|
-
/**
|
|
80
|
-
* The original response.
|
|
81
|
-
*/
|
|
82
|
-
response: TResponse,
|
|
83
|
-
/**
|
|
84
|
-
* The custom request options.
|
|
85
|
-
*/
|
|
86
|
-
requestOptions?: RequestOptions) => Readonly<Promise<any>>;
|
|
87
|
-
|
|
88
|
-
export declare type WaitablePromise<TResponse> = Readonly<Promise<TResponse>> & {
|
|
89
|
-
/**
|
|
90
|
-
* Wait for a task to complete before executing the next line of code, to synchronize index updates.
|
|
91
|
-
*
|
|
92
|
-
* All write operations in Algolia are asynchronous by design. It means that when you add or
|
|
93
|
-
* update an object to your index, our servers will reply to your request with a taskID as
|
|
94
|
-
* soon as they understood the write operation. The actual insert and indexing will be
|
|
95
|
-
* done after replying to your code.
|
|
96
|
-
*
|
|
97
|
-
* You can wait for a task to complete by using this method.
|
|
98
|
-
*/
|
|
99
|
-
readonly wait: (requestOptions?: RequestOptions) => Readonly<WaitablePromise<TResponse>>;
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
export { }
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
function createAuth(authMode, appId, apiKey) {
|
|
2
|
-
const credentials = {
|
|
3
|
-
'x-algolia-api-key': apiKey,
|
|
4
|
-
'x-algolia-application-id': appId,
|
|
5
|
-
};
|
|
6
|
-
return {
|
|
7
|
-
headers() {
|
|
8
|
-
return authMode === AuthMode.WithinHeaders ? credentials : {};
|
|
9
|
-
},
|
|
10
|
-
queryParameters() {
|
|
11
|
-
return authMode === AuthMode.WithinQueryParameters ? credentials : {};
|
|
12
|
-
},
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function createRetryablePromise(callback) {
|
|
17
|
-
let retriesCount = 0; // eslint-disable-line functional/no-let
|
|
18
|
-
const retry = () => {
|
|
19
|
-
retriesCount++;
|
|
20
|
-
return new Promise((resolve) => {
|
|
21
|
-
setTimeout(() => {
|
|
22
|
-
resolve(callback(retry));
|
|
23
|
-
}, Math.min(100 * retriesCount, 1000));
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
return callback(retry);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function createWaitablePromise(promise, wait = (_response, _requestOptions) => {
|
|
30
|
-
return Promise.resolve();
|
|
31
|
-
}) {
|
|
32
|
-
// eslint-disable-next-line functional/immutable-data
|
|
33
|
-
return Object.assign(promise, {
|
|
34
|
-
wait(requestOptions) {
|
|
35
|
-
return createWaitablePromise(promise
|
|
36
|
-
.then(response => Promise.all([wait(response, requestOptions), response]))
|
|
37
|
-
.then(promiseResults => promiseResults[1]));
|
|
38
|
-
},
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// eslint-disable-next-line functional/prefer-readonly-type
|
|
43
|
-
function shuffle(array) {
|
|
44
|
-
let c = array.length - 1; // eslint-disable-line functional/no-let
|
|
45
|
-
// eslint-disable-next-line functional/no-loop-statement
|
|
46
|
-
for (c; c > 0; c--) {
|
|
47
|
-
const b = Math.floor(Math.random() * (c + 1));
|
|
48
|
-
const a = array[c];
|
|
49
|
-
array[c] = array[b]; // eslint-disable-line functional/immutable-data, no-param-reassign
|
|
50
|
-
array[b] = a; // eslint-disable-line functional/immutable-data, no-param-reassign
|
|
51
|
-
}
|
|
52
|
-
return array;
|
|
53
|
-
}
|
|
54
|
-
function addMethods(base, methods) {
|
|
55
|
-
if (!methods) {
|
|
56
|
-
return base;
|
|
57
|
-
}
|
|
58
|
-
Object.keys(methods).forEach(key => {
|
|
59
|
-
// eslint-disable-next-line functional/immutable-data, no-param-reassign
|
|
60
|
-
base[key] = methods[key](base);
|
|
61
|
-
});
|
|
62
|
-
return base;
|
|
63
|
-
}
|
|
64
|
-
function encode(format, ...args) {
|
|
65
|
-
// eslint-disable-next-line functional/no-let
|
|
66
|
-
let i = 0;
|
|
67
|
-
return format.replace(/%s/g, () => encodeURIComponent(args[i++]));
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const version = '4.14.2';
|
|
71
|
-
|
|
72
|
-
const destroy = (base) => {
|
|
73
|
-
return () => {
|
|
74
|
-
return base.transporter.requester.destroy();
|
|
75
|
-
};
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
const AuthMode = {
|
|
79
|
-
/**
|
|
80
|
-
* If auth credentials should be in query parameters.
|
|
81
|
-
*/
|
|
82
|
-
WithinQueryParameters: 0,
|
|
83
|
-
/**
|
|
84
|
-
* If auth credentials should be in headers.
|
|
85
|
-
*/
|
|
86
|
-
WithinHeaders: 1,
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
export { AuthMode, addMethods, createAuth, createRetryablePromise, createWaitablePromise, destroy, encode, shuffle, version };
|
package/index.js
DELETED