@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.
Files changed (89) hide show
  1. package/dist/client-common.cjs.js +803 -91
  2. package/dist/client-common.esm.node.js +774 -0
  3. package/dist/index.d.ts +10 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/src/cache/createBrowserLocalStorageCache.d.ts +3 -0
  6. package/dist/src/cache/createBrowserLocalStorageCache.d.ts.map +1 -0
  7. package/dist/src/cache/createFallbackableCache.d.ts +3 -0
  8. package/dist/src/cache/createFallbackableCache.d.ts.map +1 -0
  9. package/dist/src/cache/createMemoryCache.d.ts +3 -0
  10. package/dist/src/cache/createMemoryCache.d.ts.map +1 -0
  11. package/dist/src/cache/createNullCache.d.ts +3 -0
  12. package/dist/src/cache/createNullCache.d.ts.map +1 -0
  13. package/dist/src/cache/index.d.ts +5 -0
  14. package/dist/src/cache/index.d.ts.map +1 -0
  15. package/dist/src/constants.d.ts +7 -0
  16. package/dist/src/constants.d.ts.map +1 -0
  17. package/dist/src/createAlgoliaAgent.d.ts +3 -0
  18. package/dist/src/createAlgoliaAgent.d.ts.map +1 -0
  19. package/dist/src/createAuth.d.ts +6 -0
  20. package/dist/src/createAuth.d.ts.map +1 -0
  21. package/dist/src/createEchoRequester.d.ts +7 -0
  22. package/dist/src/createEchoRequester.d.ts.map +1 -0
  23. package/dist/src/createRetryablePromise.d.ts +14 -0
  24. package/dist/src/createRetryablePromise.d.ts.map +1 -0
  25. package/dist/src/getAlgoliaAgent.d.ts +8 -0
  26. package/dist/src/getAlgoliaAgent.d.ts.map +1 -0
  27. package/dist/src/transporter/createStatefulHost.d.ts +3 -0
  28. package/dist/src/transporter/createStatefulHost.d.ts.map +1 -0
  29. package/dist/src/transporter/createTransporter.d.ts +3 -0
  30. package/dist/src/transporter/createTransporter.d.ts.map +1 -0
  31. package/dist/src/transporter/errors.d.ts +21 -0
  32. package/dist/src/transporter/errors.d.ts.map +1 -0
  33. package/dist/src/transporter/helpers.d.ts +9 -0
  34. package/dist/src/transporter/helpers.d.ts.map +1 -0
  35. package/dist/src/transporter/index.d.ts +7 -0
  36. package/dist/src/transporter/index.d.ts.map +1 -0
  37. package/dist/src/transporter/responses.d.ts +5 -0
  38. package/dist/src/transporter/responses.d.ts.map +1 -0
  39. package/dist/src/transporter/stackTrace.d.ts +4 -0
  40. package/dist/src/transporter/stackTrace.d.ts.map +1 -0
  41. package/dist/src/types/Cache.d.ts +47 -0
  42. package/dist/src/types/Cache.d.ts.map +1 -0
  43. package/dist/src/types/CreateClient.d.ts +12 -0
  44. package/dist/src/types/CreateClient.d.ts.map +1 -0
  45. package/dist/src/types/CreateRetryablePromise.d.ts +19 -0
  46. package/dist/src/types/CreateRetryablePromise.d.ts.map +1 -0
  47. package/dist/src/types/Host.d.ts +33 -0
  48. package/dist/src/types/Host.d.ts.map +1 -0
  49. package/dist/src/types/Requester.d.ts +66 -0
  50. package/dist/src/types/Requester.d.ts.map +1 -0
  51. package/dist/src/types/Transporter.d.ts +128 -0
  52. package/dist/src/types/Transporter.d.ts.map +1 -0
  53. package/dist/src/types/index.d.ts +7 -0
  54. package/dist/src/types/index.d.ts.map +1 -0
  55. package/index.ts +9 -0
  56. package/package.json +24 -15
  57. package/src/__tests__/cache/browser-local-storage-cache.test.ts +134 -0
  58. package/src/__tests__/cache/fallbackable-cache.test.ts +126 -0
  59. package/src/__tests__/cache/memory-cache.test.ts +90 -0
  60. package/src/__tests__/cache/null-cache.test.ts +49 -0
  61. package/src/__tests__/create-retryable-promise.test.ts +86 -0
  62. package/src/cache/createBrowserLocalStorageCache.ts +74 -0
  63. package/src/cache/createFallbackableCache.ts +53 -0
  64. package/src/cache/createMemoryCache.ts +56 -0
  65. package/src/cache/createNullCache.ts +34 -0
  66. package/src/cache/index.ts +4 -0
  67. package/src/constants.ts +7 -0
  68. package/src/createAlgoliaAgent.ts +20 -0
  69. package/src/createAuth.ts +25 -0
  70. package/src/createEchoRequester.ts +59 -0
  71. package/src/createRetryablePromise.ts +52 -0
  72. package/src/getAlgoliaAgent.ts +25 -0
  73. package/src/transporter/createStatefulHost.ts +24 -0
  74. package/src/transporter/createTransporter.ts +347 -0
  75. package/src/transporter/errors.ts +51 -0
  76. package/src/transporter/helpers.ts +119 -0
  77. package/src/transporter/index.ts +6 -0
  78. package/src/transporter/responses.ts +23 -0
  79. package/src/transporter/stackTrace.ts +30 -0
  80. package/src/types/Cache.ts +61 -0
  81. package/src/types/CreateClient.ts +23 -0
  82. package/src/types/CreateRetryablePromise.ts +21 -0
  83. package/src/types/Host.ts +38 -0
  84. package/src/types/Requester.ts +72 -0
  85. package/src/types/Transporter.ts +153 -0
  86. package/src/types/index.ts +6 -0
  87. package/dist/client-common.d.ts +0 -102
  88. package/dist/client-common.esm.js +0 -89
  89. package/index.js +0 -2
@@ -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
@@ -1,2 +0,0 @@
1
- // eslint-disable-next-line functional/immutable-data, import/no-commonjs
2
- module.exports = require('./dist/client-common.cjs.js');