@depup/typesense 3.0.3-depup.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/LICENSE +201 -0
- package/README.md +31 -0
- package/changes.json +10 -0
- package/dist/typesense.js +13031 -0
- package/dist/typesense.js.map +1 -0
- package/dist/typesense.min.js +3 -0
- package/dist/typesense.min.js.LICENSE.txt +1 -0
- package/dist/typesense.min.js.map +1 -0
- package/lib/Typesense/Alias.d.ts +10 -0
- package/lib/Typesense/Alias.js +30 -0
- package/lib/Typesense/Alias.js.map +1 -0
- package/lib/Typesense/Aliases.d.ts +18 -0
- package/lib/Typesense/Aliases.js +36 -0
- package/lib/Typesense/Aliases.js.map +1 -0
- package/lib/Typesense/Analytics.d.ts +15 -0
- package/lib/Typesense/Analytics.js +40 -0
- package/lib/Typesense/Analytics.js.map +1 -0
- package/lib/Typesense/AnalyticsEvent.d.ts +5 -0
- package/lib/Typesense/AnalyticsEvent.js +3 -0
- package/lib/Typesense/AnalyticsEvent.js.map +1 -0
- package/lib/Typesense/AnalyticsEvents.d.ts +26 -0
- package/lib/Typesense/AnalyticsEvents.js +37 -0
- package/lib/Typesense/AnalyticsEvents.js.map +1 -0
- package/lib/Typesense/AnalyticsRule.d.ts +47 -0
- package/lib/Typesense/AnalyticsRule.js +30 -0
- package/lib/Typesense/AnalyticsRule.js.map +1 -0
- package/lib/Typesense/AnalyticsRuleV1.d.ts +35 -0
- package/lib/Typesense/AnalyticsRuleV1.js +30 -0
- package/lib/Typesense/AnalyticsRuleV1.js.map +1 -0
- package/lib/Typesense/AnalyticsRules.d.ts +16 -0
- package/lib/Typesense/AnalyticsRules.js +49 -0
- package/lib/Typesense/AnalyticsRules.js.map +1 -0
- package/lib/Typesense/AnalyticsRulesV1.d.ts +13 -0
- package/lib/Typesense/AnalyticsRulesV1.js +37 -0
- package/lib/Typesense/AnalyticsRulesV1.js.map +1 -0
- package/lib/Typesense/AnalyticsV1.d.ts +19 -0
- package/lib/Typesense/AnalyticsV1.js +49 -0
- package/lib/Typesense/AnalyticsV1.js.map +1 -0
- package/lib/Typesense/ApiCall.d.ts +99 -0
- package/lib/Typesense/ApiCall.js +777 -0
- package/lib/Typesense/ApiCall.js.map +1 -0
- package/lib/Typesense/Client.d.ts +79 -0
- package/lib/Typesense/Client.js +170 -0
- package/lib/Typesense/Client.js.map +1 -0
- package/lib/Typesense/Collection.d.ts +63 -0
- package/lib/Typesense/Collection.js +109 -0
- package/lib/Typesense/Collection.js.map +1 -0
- package/lib/Typesense/Collections.d.ts +42 -0
- package/lib/Typesense/Collections.js +34 -0
- package/lib/Typesense/Collections.js.map +1 -0
- package/lib/Typesense/Configuration.d.ts +143 -0
- package/lib/Typesense/Configuration.js +113 -0
- package/lib/Typesense/Configuration.js.map +1 -0
- package/lib/Typesense/Conversation.d.ts +22 -0
- package/lib/Typesense/Conversation.js +37 -0
- package/lib/Typesense/Conversation.js.map +1 -0
- package/lib/Typesense/ConversationModel.d.ts +30 -0
- package/lib/Typesense/ConversationModel.js +37 -0
- package/lib/Typesense/ConversationModel.js.map +1 -0
- package/lib/Typesense/ConversationModels.d.ts +10 -0
- package/lib/Typesense/ConversationModels.js +37 -0
- package/lib/Typesense/ConversationModels.js.map +1 -0
- package/lib/Typesense/Conversations.d.ts +17 -0
- package/lib/Typesense/Conversations.js +42 -0
- package/lib/Typesense/Conversations.js.map +1 -0
- package/lib/Typesense/CurationSet.d.ts +17 -0
- package/lib/Typesense/CurationSet.js +52 -0
- package/lib/Typesense/CurationSet.js.map +1 -0
- package/lib/Typesense/CurationSetItem.d.ts +15 -0
- package/lib/Typesense/CurationSetItem.js +38 -0
- package/lib/Typesense/CurationSetItem.js.map +1 -0
- package/lib/Typesense/CurationSetItems.d.ts +9 -0
- package/lib/Typesense/CurationSetItems.js +23 -0
- package/lib/Typesense/CurationSetItems.js.map +1 -0
- package/lib/Typesense/CurationSets.d.ts +56 -0
- package/lib/Typesense/CurationSets.js +19 -0
- package/lib/Typesense/CurationSets.js.map +1 -0
- package/lib/Typesense/Debug.d.ts +10 -0
- package/lib/Typesense/Debug.js +19 -0
- package/lib/Typesense/Debug.js.map +1 -0
- package/lib/Typesense/Document.d.ts +12 -0
- package/lib/Typesense/Document.js +41 -0
- package/lib/Typesense/Document.js.map +1 -0
- package/lib/Typesense/Documents.d.ts +196 -0
- package/lib/Typesense/Documents.js +204 -0
- package/lib/Typesense/Documents.js.map +1 -0
- package/lib/Typesense/Errors/HTTPError.d.ts +3 -0
- package/lib/Typesense/Errors/HTTPError.js +13 -0
- package/lib/Typesense/Errors/HTTPError.js.map +1 -0
- package/lib/Typesense/Errors/ImportError.d.ts +15 -0
- package/lib/Typesense/Errors/ImportError.js +16 -0
- package/lib/Typesense/Errors/ImportError.js.map +1 -0
- package/lib/Typesense/Errors/MissingConfigurationError.d.ts +3 -0
- package/lib/Typesense/Errors/MissingConfigurationError.js +13 -0
- package/lib/Typesense/Errors/MissingConfigurationError.js.map +1 -0
- package/lib/Typesense/Errors/ObjectAlreadyExists.d.ts +3 -0
- package/lib/Typesense/Errors/ObjectAlreadyExists.js +13 -0
- package/lib/Typesense/Errors/ObjectAlreadyExists.js.map +1 -0
- package/lib/Typesense/Errors/ObjectNotFound.d.ts +3 -0
- package/lib/Typesense/Errors/ObjectNotFound.js +13 -0
- package/lib/Typesense/Errors/ObjectNotFound.js.map +1 -0
- package/lib/Typesense/Errors/ObjectUnprocessable.d.ts +3 -0
- package/lib/Typesense/Errors/ObjectUnprocessable.js +13 -0
- package/lib/Typesense/Errors/ObjectUnprocessable.js.map +1 -0
- package/lib/Typesense/Errors/RequestMalformed.d.ts +3 -0
- package/lib/Typesense/Errors/RequestMalformed.js +13 -0
- package/lib/Typesense/Errors/RequestMalformed.js.map +1 -0
- package/lib/Typesense/Errors/RequestUnauthorized.d.ts +3 -0
- package/lib/Typesense/Errors/RequestUnauthorized.js +13 -0
- package/lib/Typesense/Errors/RequestUnauthorized.js.map +1 -0
- package/lib/Typesense/Errors/ServerError.d.ts +3 -0
- package/lib/Typesense/Errors/ServerError.js +13 -0
- package/lib/Typesense/Errors/ServerError.js.map +1 -0
- package/lib/Typesense/Errors/TypesenseError.d.ts +5 -0
- package/lib/Typesense/Errors/TypesenseError.js +19 -0
- package/lib/Typesense/Errors/TypesenseError.js.map +1 -0
- package/lib/Typesense/Errors/index.d.ts +11 -0
- package/lib/Typesense/Errors/index.js +25 -0
- package/lib/Typesense/Errors/index.js.map +1 -0
- package/lib/Typesense/Health.d.ts +9 -0
- package/lib/Typesense/Health.js +19 -0
- package/lib/Typesense/Health.js.map +1 -0
- package/lib/Typesense/Key.d.ts +33 -0
- package/lib/Typesense/Key.js +30 -0
- package/lib/Typesense/Key.js.map +1 -0
- package/lib/Typesense/Keys.d.ts +19 -0
- package/lib/Typesense/Keys.js +46 -0
- package/lib/Typesense/Keys.js.map +1 -0
- package/lib/Typesense/Metrics.d.ts +25 -0
- package/lib/Typesense/Metrics.js +19 -0
- package/lib/Typesense/Metrics.js.map +1 -0
- package/lib/Typesense/MultiSearch.d.ts +25 -0
- package/lib/Typesense/MultiSearch.js +63 -0
- package/lib/Typesense/MultiSearch.js.map +1 -0
- package/lib/Typesense/NLSearchModel.d.ts +16 -0
- package/lib/Typesense/NLSearchModel.js +37 -0
- package/lib/Typesense/NLSearchModel.js.map +1 -0
- package/lib/Typesense/NLSearchModels.d.ts +36 -0
- package/lib/Typesense/NLSearchModels.js +36 -0
- package/lib/Typesense/NLSearchModels.js.map +1 -0
- package/lib/Typesense/Operations.d.ts +12 -0
- package/lib/Typesense/Operations.js +27 -0
- package/lib/Typesense/Operations.js.map +1 -0
- package/lib/Typesense/Override.d.ts +17 -0
- package/lib/Typesense/Override.js +32 -0
- package/lib/Typesense/Override.js.map +1 -0
- package/lib/Typesense/Overrides.d.ts +43 -0
- package/lib/Typesense/Overrides.js +38 -0
- package/lib/Typesense/Overrides.js.map +1 -0
- package/lib/Typesense/Preset.d.ts +17 -0
- package/lib/Typesense/Preset.js +30 -0
- package/lib/Typesense/Preset.js.map +1 -0
- package/lib/Typesense/Presets.d.ts +18 -0
- package/lib/Typesense/Presets.js +49 -0
- package/lib/Typesense/Presets.js.map +1 -0
- package/lib/Typesense/RequestWithCache.d.ts +15 -0
- package/lib/Typesense/RequestWithCache.js +117 -0
- package/lib/Typesense/RequestWithCache.js.map +1 -0
- package/lib/Typesense/SearchClient.d.ts +13 -0
- package/lib/Typesense/SearchClient.js +45 -0
- package/lib/Typesense/SearchClient.js.map +1 -0
- package/lib/Typesense/SearchOnlyCollection.d.ts +11 -0
- package/lib/Typesense/SearchOnlyCollection.js +18 -0
- package/lib/Typesense/SearchOnlyCollection.js.map +1 -0
- package/lib/Typesense/SearchOnlyDocuments.d.ts +16 -0
- package/lib/Typesense/SearchOnlyDocuments.js +57 -0
- package/lib/Typesense/SearchOnlyDocuments.js.map +1 -0
- package/lib/Typesense/Stats.d.ts +24 -0
- package/lib/Typesense/Stats.js +19 -0
- package/lib/Typesense/Stats.js.map +1 -0
- package/lib/Typesense/Stemming.d.ts +12 -0
- package/lib/Typesense/Stemming.js +35 -0
- package/lib/Typesense/Stemming.js.map +1 -0
- package/lib/Typesense/StemmingDictionaries.d.ts +13 -0
- package/lib/Typesense/StemmingDictionaries.js +58 -0
- package/lib/Typesense/StemmingDictionaries.js.map +1 -0
- package/lib/Typesense/StemmingDictionary.d.ts +20 -0
- package/lib/Typesense/StemmingDictionary.js +30 -0
- package/lib/Typesense/StemmingDictionary.js.map +1 -0
- package/lib/Typesense/Stopword.d.ts +20 -0
- package/lib/Typesense/Stopword.js +30 -0
- package/lib/Typesense/Stopword.js.map +1 -0
- package/lib/Typesense/Stopwords.d.ts +17 -0
- package/lib/Typesense/Stopwords.js +36 -0
- package/lib/Typesense/Stopwords.js.map +1 -0
- package/lib/Typesense/Synonym.d.ts +21 -0
- package/lib/Typesense/Synonym.js +41 -0
- package/lib/Typesense/Synonym.js.map +1 -0
- package/lib/Typesense/SynonymSet.d.ts +21 -0
- package/lib/Typesense/SynonymSet.js +52 -0
- package/lib/Typesense/SynonymSet.js.map +1 -0
- package/lib/Typesense/SynonymSetItem.d.ts +14 -0
- package/lib/Typesense/SynonymSetItem.js +31 -0
- package/lib/Typesense/SynonymSetItem.js.map +1 -0
- package/lib/Typesense/SynonymSetItems.d.ts +10 -0
- package/lib/Typesense/SynonymSetItems.js +30 -0
- package/lib/Typesense/SynonymSetItems.js.map +1 -0
- package/lib/Typesense/SynonymSets.d.ts +23 -0
- package/lib/Typesense/SynonymSets.js +19 -0
- package/lib/Typesense/SynonymSets.js.map +1 -0
- package/lib/Typesense/Synonyms.d.ts +24 -0
- package/lib/Typesense/Synonyms.js +47 -0
- package/lib/Typesense/Synonyms.js.map +1 -0
- package/lib/Typesense/Types.d.ts +201 -0
- package/lib/Typesense/Types.js +22 -0
- package/lib/Typesense/Types.js.map +1 -0
- package/lib/Typesense/Utils.d.ts +11 -0
- package/lib/Typesense/Utils.js +50 -0
- package/lib/Typesense/Utils.js.map +1 -0
- package/lib/Typesense.d.ts +46 -0
- package/lib/Typesense.js +12 -0
- package/lib/Typesense.js.map +1 -0
- package/package.json +141 -0
- package/src/Typesense/Alias.ts +18 -0
- package/src/Typesense/Aliases.ts +41 -0
- package/src/Typesense/Analytics.ts +39 -0
- package/src/Typesense/AnalyticsEvent.ts +5 -0
- package/src/Typesense/AnalyticsEvents.ts +53 -0
- package/src/Typesense/AnalyticsRule.ts +63 -0
- package/src/Typesense/AnalyticsRuleV1.ts +52 -0
- package/src/Typesense/AnalyticsRules.ts +67 -0
- package/src/Typesense/AnalyticsRulesV1.ts +43 -0
- package/src/Typesense/AnalyticsV1.ts +52 -0
- package/src/Typesense/ApiCall.ts +1103 -0
- package/src/Typesense/Client.ts +225 -0
- package/src/Typesense/Collection.ts +179 -0
- package/src/Typesense/Collections.ts +68 -0
- package/src/Typesense/Configuration.ts +328 -0
- package/src/Typesense/Conversation.ts +45 -0
- package/src/Typesense/ConversationModel.ts +55 -0
- package/src/Typesense/ConversationModels.ts +38 -0
- package/src/Typesense/Conversations.ts +47 -0
- package/src/Typesense/CurationSet.ts +56 -0
- package/src/Typesense/CurationSetItem.ts +35 -0
- package/src/Typesense/CurationSetItems.ts +18 -0
- package/src/Typesense/CurationSets.ts +60 -0
- package/src/Typesense/Debug.ts +16 -0
- package/src/Typesense/Document.ts +34 -0
- package/src/Typesense/Documents.ts +445 -0
- package/src/Typesense/Errors/HTTPError.ts +3 -0
- package/src/Typesense/Errors/ImportError.ts +24 -0
- package/src/Typesense/Errors/MissingConfigurationError.ts +3 -0
- package/src/Typesense/Errors/ObjectAlreadyExists.ts +3 -0
- package/src/Typesense/Errors/ObjectNotFound.ts +3 -0
- package/src/Typesense/Errors/ObjectUnprocessable.ts +3 -0
- package/src/Typesense/Errors/RequestMalformed.ts +3 -0
- package/src/Typesense/Errors/RequestUnauthorized.ts +3 -0
- package/src/Typesense/Errors/ServerError.ts +3 -0
- package/src/Typesense/Errors/TypesenseError.ts +13 -0
- package/src/Typesense/Errors/index.ts +23 -0
- package/src/Typesense/Health.ts +15 -0
- package/src/Typesense/Key.ts +73 -0
- package/src/Typesense/Keys.ts +59 -0
- package/src/Typesense/Metrics.ts +31 -0
- package/src/Typesense/MultiSearch.ts +144 -0
- package/src/Typesense/NLSearchModel.ts +35 -0
- package/src/Typesense/NLSearchModels.ts +61 -0
- package/src/Typesense/Operations.ts +35 -0
- package/src/Typesense/Override.ts +31 -0
- package/src/Typesense/Overrides.ts +73 -0
- package/src/Typesense/Preset.ts +31 -0
- package/src/Typesense/Presets.ts +62 -0
- package/src/Typesense/RequestWithCache.ts +209 -0
- package/src/Typesense/SearchClient.ts +64 -0
- package/src/Typesense/SearchOnlyCollection.ts +24 -0
- package/src/Typesense/SearchOnlyDocuments.ts +87 -0
- package/src/Typesense/Stats.ts +31 -0
- package/src/Typesense/Stemming.ts +38 -0
- package/src/Typesense/StemmingDictionaries.ts +59 -0
- package/src/Typesense/StemmingDictionary.ts +37 -0
- package/src/Typesense/Stopword.ts +31 -0
- package/src/Typesense/Stopwords.ts +41 -0
- package/src/Typesense/Synonym.ts +42 -0
- package/src/Typesense/SynonymSet.ts +57 -0
- package/src/Typesense/SynonymSetItem.ts +28 -0
- package/src/Typesense/SynonymSetItems.ts +31 -0
- package/src/Typesense/SynonymSets.ts +30 -0
- package/src/Typesense/Synonyms.ts +55 -0
- package/src/Typesense/Types.ts +355 -0
- package/src/Typesense/Utils.ts +80 -0
- package/src/Typesense.ts +43 -0
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { AxiosRequestConfig } from "axios";
|
|
2
|
+
import type { DocumentSchema } from "./Documents";
|
|
3
|
+
import { HttpClient } from "./ApiCall";
|
|
4
|
+
import type { RequestParams } from "./Types";
|
|
5
|
+
|
|
6
|
+
const defaultCacheResponseForSeconds = 2 * 60;
|
|
7
|
+
const defaultMaxSize = 100;
|
|
8
|
+
|
|
9
|
+
interface CacheEntry<T> {
|
|
10
|
+
requestTimestamp: number;
|
|
11
|
+
response: T;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface PromiseCacheEntry<T> {
|
|
15
|
+
requestTimestamp: number;
|
|
16
|
+
responsePromise: Promise<T>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default class RequestWithCache {
|
|
20
|
+
private responseCache: Map<string, CacheEntry<unknown>> = new Map();
|
|
21
|
+
private responsePromiseCache: Map<string, PromiseCacheEntry<unknown>> =
|
|
22
|
+
new Map();
|
|
23
|
+
|
|
24
|
+
clearCache() {
|
|
25
|
+
this.responseCache = new Map();
|
|
26
|
+
this.responsePromiseCache = new Map();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async perform<
|
|
30
|
+
const TContext extends HttpClient,
|
|
31
|
+
const TMethod extends keyof HttpClient,
|
|
32
|
+
const TDoc extends DocumentSchema[],
|
|
33
|
+
TResult,
|
|
34
|
+
>(
|
|
35
|
+
requestContext: TContext,
|
|
36
|
+
methodName: TMethod,
|
|
37
|
+
requestParams: RequestParams<TDoc>,
|
|
38
|
+
cacheOptions: CacheOptions | undefined,
|
|
39
|
+
): Promise<TResult> {
|
|
40
|
+
const {
|
|
41
|
+
cacheResponseForSeconds = defaultCacheResponseForSeconds,
|
|
42
|
+
maxSize = defaultMaxSize,
|
|
43
|
+
} = cacheOptions || {};
|
|
44
|
+
const isCacheDisabled =
|
|
45
|
+
cacheOptions === undefined ||
|
|
46
|
+
cacheResponseForSeconds <= 0 ||
|
|
47
|
+
maxSize <= 0;
|
|
48
|
+
|
|
49
|
+
const {
|
|
50
|
+
path,
|
|
51
|
+
queryParams,
|
|
52
|
+
body,
|
|
53
|
+
headers,
|
|
54
|
+
streamConfig,
|
|
55
|
+
abortSignal,
|
|
56
|
+
responseType,
|
|
57
|
+
isStreamingRequest,
|
|
58
|
+
} = requestParams;
|
|
59
|
+
|
|
60
|
+
if (isCacheDisabled) {
|
|
61
|
+
return this.executeRequest<TResult>(
|
|
62
|
+
requestContext,
|
|
63
|
+
methodName,
|
|
64
|
+
path,
|
|
65
|
+
queryParams,
|
|
66
|
+
body,
|
|
67
|
+
headers,
|
|
68
|
+
{ abortSignal, responseType, streamConfig, isStreamingRequest },
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const requestParamsJSON = JSON.stringify(requestParams);
|
|
73
|
+
const cacheEntry = this.responseCache.get(requestParamsJSON);
|
|
74
|
+
const now = Date.now();
|
|
75
|
+
|
|
76
|
+
if (cacheEntry) {
|
|
77
|
+
const isEntryValid =
|
|
78
|
+
now - cacheEntry.requestTimestamp < cacheResponseForSeconds * 1000;
|
|
79
|
+
if (isEntryValid) {
|
|
80
|
+
this.responseCache.delete(requestParamsJSON);
|
|
81
|
+
this.responseCache.set(requestParamsJSON, cacheEntry);
|
|
82
|
+
return cacheEntry.response as TResult;
|
|
83
|
+
} else {
|
|
84
|
+
this.responseCache.delete(requestParamsJSON);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const cachePromiseEntry = this.responsePromiseCache.get(requestParamsJSON);
|
|
89
|
+
|
|
90
|
+
if (cachePromiseEntry) {
|
|
91
|
+
const isEntryValid =
|
|
92
|
+
now - cachePromiseEntry.requestTimestamp <
|
|
93
|
+
cacheResponseForSeconds * 1000;
|
|
94
|
+
if (isEntryValid) {
|
|
95
|
+
this.responsePromiseCache.delete(requestParamsJSON);
|
|
96
|
+
this.responsePromiseCache.set(requestParamsJSON, cachePromiseEntry);
|
|
97
|
+
return cachePromiseEntry.responsePromise as Promise<TResult>;
|
|
98
|
+
} else {
|
|
99
|
+
this.responsePromiseCache.delete(requestParamsJSON);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const responsePromise = this.executeRequest<TResult>(
|
|
104
|
+
requestContext,
|
|
105
|
+
methodName,
|
|
106
|
+
path,
|
|
107
|
+
queryParams,
|
|
108
|
+
body,
|
|
109
|
+
headers,
|
|
110
|
+
{ abortSignal, responseType, streamConfig, isStreamingRequest },
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
this.responsePromiseCache.set(requestParamsJSON, {
|
|
114
|
+
requestTimestamp: now,
|
|
115
|
+
responsePromise,
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
const response = await responsePromise;
|
|
119
|
+
this.responseCache.set(requestParamsJSON, {
|
|
120
|
+
requestTimestamp: now,
|
|
121
|
+
response: response,
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
const isCacheOverMaxSize = this.responseCache.size > maxSize;
|
|
125
|
+
if (isCacheOverMaxSize) {
|
|
126
|
+
const oldestEntry = this.responseCache.keys().next().value;
|
|
127
|
+
if (oldestEntry) {
|
|
128
|
+
this.responseCache.delete(oldestEntry);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const isResponsePromiseCacheOverMaxSize =
|
|
132
|
+
this.responsePromiseCache.size > maxSize;
|
|
133
|
+
if (isResponsePromiseCacheOverMaxSize) {
|
|
134
|
+
const oldestEntry = this.responsePromiseCache.keys().next().value;
|
|
135
|
+
if (oldestEntry) {
|
|
136
|
+
this.responsePromiseCache.delete(oldestEntry);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return response;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
private executeRequest<TResult>(
|
|
143
|
+
context: HttpClient,
|
|
144
|
+
methodName: keyof HttpClient,
|
|
145
|
+
path: string,
|
|
146
|
+
queryParams: Record<string, unknown> = {},
|
|
147
|
+
body?: unknown,
|
|
148
|
+
headers?: Record<string, string>,
|
|
149
|
+
options?: {
|
|
150
|
+
abortSignal?: AbortSignal | null;
|
|
151
|
+
responseType?: AxiosRequestConfig["responseType"];
|
|
152
|
+
streamConfig?: any;
|
|
153
|
+
isStreamingRequest: boolean | undefined;
|
|
154
|
+
},
|
|
155
|
+
): Promise<TResult> {
|
|
156
|
+
const method = context[methodName];
|
|
157
|
+
|
|
158
|
+
switch (methodName) {
|
|
159
|
+
case "get":
|
|
160
|
+
return (method as HttpClient["get"]).call(context, path, queryParams, {
|
|
161
|
+
abortSignal: options?.abortSignal,
|
|
162
|
+
responseType: options?.responseType,
|
|
163
|
+
streamConfig: options?.streamConfig,
|
|
164
|
+
isStreamingRequest: options?.isStreamingRequest,
|
|
165
|
+
}) as Promise<TResult>;
|
|
166
|
+
|
|
167
|
+
case "delete":
|
|
168
|
+
return (method as HttpClient["delete"]).call(
|
|
169
|
+
context,
|
|
170
|
+
path,
|
|
171
|
+
queryParams,
|
|
172
|
+
) as Promise<TResult>;
|
|
173
|
+
|
|
174
|
+
case "post":
|
|
175
|
+
return (method as HttpClient["post"]).call(
|
|
176
|
+
context,
|
|
177
|
+
path,
|
|
178
|
+
body,
|
|
179
|
+
queryParams,
|
|
180
|
+
headers || {},
|
|
181
|
+
{
|
|
182
|
+
abortSignal: options?.abortSignal,
|
|
183
|
+
responseType: options?.responseType,
|
|
184
|
+
streamConfig: options?.streamConfig,
|
|
185
|
+
isStreamingRequest: options?.isStreamingRequest,
|
|
186
|
+
},
|
|
187
|
+
) as Promise<TResult>;
|
|
188
|
+
|
|
189
|
+
case "put":
|
|
190
|
+
case "patch":
|
|
191
|
+
return (method as HttpClient[typeof methodName]).call(
|
|
192
|
+
context,
|
|
193
|
+
path,
|
|
194
|
+
body,
|
|
195
|
+
queryParams,
|
|
196
|
+
) as Promise<TResult>;
|
|
197
|
+
|
|
198
|
+
default:
|
|
199
|
+
throw new Error(`Unsupported method: ${String(methodName)}`);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
interface CacheOptions {
|
|
205
|
+
cacheResponseForSeconds?: number;
|
|
206
|
+
maxSize?: number;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export type { RequestParams } from "./Types";
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import Configuration, { ConfigurationOptions } from "./Configuration";
|
|
2
|
+
import ApiCall from "./ApiCall";
|
|
3
|
+
import MultiSearch from "./MultiSearch";
|
|
4
|
+
import { DocumentSchema } from "./Documents";
|
|
5
|
+
import { SearchOnlyCollection } from "./SearchOnlyCollection";
|
|
6
|
+
|
|
7
|
+
export default class SearchClient {
|
|
8
|
+
public readonly multiSearch: MultiSearch;
|
|
9
|
+
private readonly configuration: Configuration;
|
|
10
|
+
private readonly apiCall: ApiCall;
|
|
11
|
+
private readonly individualCollections: Record<
|
|
12
|
+
string,
|
|
13
|
+
SearchOnlyCollection<DocumentSchema>
|
|
14
|
+
>;
|
|
15
|
+
|
|
16
|
+
constructor(options: ConfigurationOptions) {
|
|
17
|
+
options.sendApiKeyAsQueryParam = options.sendApiKeyAsQueryParam ?? true;
|
|
18
|
+
if (
|
|
19
|
+
options.sendApiKeyAsQueryParam === true &&
|
|
20
|
+
(options.apiKey || "").length > 2000
|
|
21
|
+
) {
|
|
22
|
+
console.warn(
|
|
23
|
+
"[typesense] API Key is longer than 2000 characters which is over the allowed limit, so disabling sending it as a query parameter."
|
|
24
|
+
);
|
|
25
|
+
options.sendApiKeyAsQueryParam = false;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
this.configuration = new Configuration(options);
|
|
29
|
+
this.apiCall = new ApiCall(this.configuration);
|
|
30
|
+
this.multiSearch = new MultiSearch(this.apiCall, this.configuration, true);
|
|
31
|
+
this.individualCollections = {};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
clearCache() {
|
|
35
|
+
this.multiSearch.clearCache();
|
|
36
|
+
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
38
|
+
Object.entries(this.individualCollections).forEach(([_, collection]) => {
|
|
39
|
+
collection.documents().clearCache();
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
collections<TDocumentSchema extends DocumentSchema>(
|
|
44
|
+
collectionName: string,
|
|
45
|
+
): SearchOnlyCollection<TDocumentSchema> {
|
|
46
|
+
if (!collectionName) {
|
|
47
|
+
throw new Error(
|
|
48
|
+
"Typesense.SearchClient only supports search operations, so the collectionName that needs to " +
|
|
49
|
+
"be searched must be specified. Use Typesense.Client if you need to access the collection object."
|
|
50
|
+
);
|
|
51
|
+
} else {
|
|
52
|
+
if (this.individualCollections[collectionName] === undefined) {
|
|
53
|
+
this.individualCollections[collectionName] = new SearchOnlyCollection(
|
|
54
|
+
collectionName,
|
|
55
|
+
this.apiCall,
|
|
56
|
+
this.configuration
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
return this.individualCollections[
|
|
60
|
+
collectionName
|
|
61
|
+
] as SearchOnlyCollection<TDocumentSchema>;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { DocumentSchema } from "./Documents";
|
|
2
|
+
import ApiCall from "./ApiCall";
|
|
3
|
+
import { SearchOnlyDocuments } from "./SearchOnlyDocuments";
|
|
4
|
+
import type { SearchableDocuments } from "./Types";
|
|
5
|
+
|
|
6
|
+
export class SearchOnlyCollection<T extends DocumentSchema> {
|
|
7
|
+
private readonly _documents: SearchableDocuments<T>;
|
|
8
|
+
|
|
9
|
+
constructor(
|
|
10
|
+
private readonly name: string,
|
|
11
|
+
private readonly apiCall: ApiCall,
|
|
12
|
+
private readonly configuration: any
|
|
13
|
+
) {
|
|
14
|
+
this._documents = new SearchOnlyDocuments(
|
|
15
|
+
this.name,
|
|
16
|
+
this.apiCall,
|
|
17
|
+
this.configuration
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
documents(): SearchableDocuments<T> {
|
|
22
|
+
return this._documents;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import RequestWithCache from "./RequestWithCache";
|
|
2
|
+
import ApiCall from "./ApiCall";
|
|
3
|
+
import Configuration from "./Configuration";
|
|
4
|
+
import Collections from "./Collections";
|
|
5
|
+
import type {
|
|
6
|
+
DocumentSchema,
|
|
7
|
+
SearchOptions,
|
|
8
|
+
SearchParamsWithPreset,
|
|
9
|
+
SearchResponse,
|
|
10
|
+
} from "./Documents";
|
|
11
|
+
import { normalizeArrayableParams } from "./Utils";
|
|
12
|
+
import { SearchableDocuments, SearchParams } from "./Types";
|
|
13
|
+
|
|
14
|
+
const RESOURCEPATH = "/documents";
|
|
15
|
+
|
|
16
|
+
export class SearchOnlyDocuments<T extends DocumentSchema>
|
|
17
|
+
implements SearchableDocuments<T>
|
|
18
|
+
{
|
|
19
|
+
protected requestWithCache: RequestWithCache = new RequestWithCache();
|
|
20
|
+
|
|
21
|
+
constructor(
|
|
22
|
+
protected collectionName: string,
|
|
23
|
+
protected apiCall: ApiCall,
|
|
24
|
+
protected configuration: Configuration,
|
|
25
|
+
) {}
|
|
26
|
+
|
|
27
|
+
clearCache() {
|
|
28
|
+
this.requestWithCache.clearCache();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async search<const Infix extends string>(
|
|
32
|
+
searchParameters: SearchParams<T, Infix> | SearchParamsWithPreset<T, Infix>,
|
|
33
|
+
{
|
|
34
|
+
cacheSearchResultsForSeconds = this.configuration
|
|
35
|
+
.cacheSearchResultsForSeconds,
|
|
36
|
+
abortSignal = null,
|
|
37
|
+
}: SearchOptions = {},
|
|
38
|
+
): Promise<SearchResponse<T>> {
|
|
39
|
+
const additionalQueryParams = {};
|
|
40
|
+
if (this.configuration.useServerSideSearchCache === true) {
|
|
41
|
+
additionalQueryParams["use_cache"] = true;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const { streamConfig, ...rest } = normalizeArrayableParams<
|
|
45
|
+
T,
|
|
46
|
+
SearchParams<T, Infix>,
|
|
47
|
+
Infix
|
|
48
|
+
>(searchParameters);
|
|
49
|
+
|
|
50
|
+
const queryParams = {
|
|
51
|
+
...additionalQueryParams,
|
|
52
|
+
...rest,
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const isStreamingRequest = queryParams.conversation_stream === true;
|
|
56
|
+
|
|
57
|
+
return this.requestWithCache.perform<
|
|
58
|
+
ApiCall,
|
|
59
|
+
"get",
|
|
60
|
+
[T],
|
|
61
|
+
SearchResponse<T>
|
|
62
|
+
>(
|
|
63
|
+
this.apiCall,
|
|
64
|
+
"get",
|
|
65
|
+
{
|
|
66
|
+
path: this.endpointPath("search"),
|
|
67
|
+
queryParams,
|
|
68
|
+
streamConfig,
|
|
69
|
+
abortSignal,
|
|
70
|
+
isStreamingRequest,
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
cacheResponseForSeconds: cacheSearchResultsForSeconds,
|
|
74
|
+
},
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
protected endpointPath(operation?: string) {
|
|
79
|
+
return `${Collections.RESOURCEPATH}/${encodeURIComponent(this.collectionName)}${RESOURCEPATH}${
|
|
80
|
+
operation === undefined ? "" : "/" + operation
|
|
81
|
+
}`;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
static get RESOURCEPATH() {
|
|
85
|
+
return RESOURCEPATH;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import ApiCall from "./ApiCall";
|
|
2
|
+
|
|
3
|
+
const RESOURCEPATH = "/stats.json";
|
|
4
|
+
|
|
5
|
+
export interface EndpointStats {
|
|
6
|
+
[endpoint: string]: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface StatsResponse {
|
|
10
|
+
delete_latency_ms?: number;
|
|
11
|
+
delete_requests_per_second?: number;
|
|
12
|
+
import_latency_ms?: number;
|
|
13
|
+
import_requests_per_second?: number;
|
|
14
|
+
latency_ms?: EndpointStats;
|
|
15
|
+
overloaded_requests_per_second?: number;
|
|
16
|
+
pending_write_batches?: number;
|
|
17
|
+
requests_per_second?: EndpointStats;
|
|
18
|
+
search_latency_ms?: number;
|
|
19
|
+
search_requests_per_second?: number;
|
|
20
|
+
total_requests_per_second?: number;
|
|
21
|
+
write_latency_ms?: number;
|
|
22
|
+
write_requests_per_second?: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export default class Metrics {
|
|
26
|
+
constructor(private apiCall: ApiCall) {}
|
|
27
|
+
|
|
28
|
+
async retrieve(): Promise<StatsResponse> {
|
|
29
|
+
return this.apiCall.get(RESOURCEPATH);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type ApiCall from "./ApiCall";
|
|
2
|
+
import StemmingDictionaries from "./StemmingDictionaries";
|
|
3
|
+
import StemmingDictionary from "./StemmingDictionary";
|
|
4
|
+
|
|
5
|
+
const RESOURCEPATH = "/stemming";
|
|
6
|
+
|
|
7
|
+
export default class Stemming {
|
|
8
|
+
private readonly _stemmingDictionaries: StemmingDictionaries;
|
|
9
|
+
private readonly individualStemmingDictionaries: Record<
|
|
10
|
+
string,
|
|
11
|
+
StemmingDictionary
|
|
12
|
+
> = {};
|
|
13
|
+
|
|
14
|
+
constructor(private readonly apiCall: ApiCall) {
|
|
15
|
+
this.apiCall = apiCall;
|
|
16
|
+
this._stemmingDictionaries = new StemmingDictionaries(this.apiCall);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
dictionaries(): StemmingDictionaries;
|
|
20
|
+
dictionaries(id: string): StemmingDictionary;
|
|
21
|
+
dictionaries(id?: string): StemmingDictionaries | StemmingDictionary {
|
|
22
|
+
if (id === undefined) {
|
|
23
|
+
return this._stemmingDictionaries;
|
|
24
|
+
} else {
|
|
25
|
+
if (this.individualStemmingDictionaries[id] === undefined) {
|
|
26
|
+
this.individualStemmingDictionaries[id] = new StemmingDictionary(
|
|
27
|
+
id,
|
|
28
|
+
this.apiCall,
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
return this.individualStemmingDictionaries[id];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
static get RESOURCEPATH() {
|
|
36
|
+
return RESOURCEPATH;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import ApiCall from "./ApiCall";
|
|
2
|
+
import type { StemmingDictionaryCreateSchema } from "./StemmingDictionary";
|
|
3
|
+
|
|
4
|
+
const RESOURCEPATH = "/stemming/dictionaries";
|
|
5
|
+
|
|
6
|
+
export interface StemmingDictionariesRetrieveSchema {
|
|
7
|
+
dictionaries: string[];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export default class StemmingDictionaries {
|
|
11
|
+
constructor(private readonly apiCall: ApiCall) {
|
|
12
|
+
this.apiCall = apiCall;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async upsert(
|
|
16
|
+
id: string,
|
|
17
|
+
wordRootCombinations: StemmingDictionaryCreateSchema[] | string,
|
|
18
|
+
): Promise<StemmingDictionaryCreateSchema[] | string> {
|
|
19
|
+
const wordRootCombinationsInJSONLFormat = Array.isArray(
|
|
20
|
+
wordRootCombinations,
|
|
21
|
+
)
|
|
22
|
+
? wordRootCombinations.map((combo) => JSON.stringify(combo)).join("\n")
|
|
23
|
+
: wordRootCombinations;
|
|
24
|
+
|
|
25
|
+
const resultsInJSONLFormat = await this.apiCall.performRequest<string>(
|
|
26
|
+
|
|
27
|
+
"post",
|
|
28
|
+
this.endpointPath("import"),
|
|
29
|
+
{
|
|
30
|
+
queryParameters: {id},
|
|
31
|
+
bodyParameters: wordRootCombinationsInJSONLFormat,
|
|
32
|
+
additionalHeaders: {"Content-Type": "text/plain"},
|
|
33
|
+
skipConnectionTimeout: true,
|
|
34
|
+
}
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
return Array.isArray(wordRootCombinations)
|
|
38
|
+
? resultsInJSONLFormat
|
|
39
|
+
.split("\n")
|
|
40
|
+
.map((line) => JSON.parse(line) as StemmingDictionaryCreateSchema)
|
|
41
|
+
: resultsInJSONLFormat;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async retrieve(): Promise<StemmingDictionariesRetrieveSchema> {
|
|
45
|
+
return this.apiCall.get<StemmingDictionariesRetrieveSchema>(
|
|
46
|
+
this.endpointPath(),
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
private endpointPath(operation?: string): string {
|
|
51
|
+
return operation === undefined
|
|
52
|
+
? `${StemmingDictionaries.RESOURCEPATH}`
|
|
53
|
+
: `${StemmingDictionaries.RESOURCEPATH}/${encodeURIComponent(operation)}`;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
static get RESOURCEPATH() {
|
|
57
|
+
return RESOURCEPATH;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import ApiCall from "./ApiCall";
|
|
2
|
+
import StemmingDictionaries from "./StemmingDictionaries";
|
|
3
|
+
|
|
4
|
+
export interface StemmingDictionaryCreateSchema {
|
|
5
|
+
root: string;
|
|
6
|
+
word: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface StemmingDictionarySchema {
|
|
10
|
+
id: string;
|
|
11
|
+
words: StemmingDictionaryCreateSchema[];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface StemmingDictionaryDeleteSchema {
|
|
15
|
+
id: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default class StemmingDictionary {
|
|
19
|
+
constructor(
|
|
20
|
+
private id: string,
|
|
21
|
+
private apiCall: ApiCall,
|
|
22
|
+
) {}
|
|
23
|
+
|
|
24
|
+
async retrieve(): Promise<StemmingDictionarySchema> {
|
|
25
|
+
return this.apiCall.get<StemmingDictionarySchema>(this.endpointPath());
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async delete(): Promise<StemmingDictionaryDeleteSchema> {
|
|
29
|
+
return this.apiCall.delete<StemmingDictionaryDeleteSchema>(
|
|
30
|
+
this.endpointPath(),
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
private endpointPath(): string {
|
|
35
|
+
return `${StemmingDictionaries.RESOURCEPATH}/${encodeURIComponent(this.id)}`;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import ApiCall from "./ApiCall";
|
|
2
|
+
import Stopwords from "./Stopwords";
|
|
3
|
+
|
|
4
|
+
export interface StopwordSchema {
|
|
5
|
+
id: string;
|
|
6
|
+
stopwords: string[] | { id: string; stopwords: string[] };
|
|
7
|
+
locale?: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface StopwordDeleteSchema {
|
|
11
|
+
id: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default class Stopword {
|
|
15
|
+
constructor(
|
|
16
|
+
private stopwordId: string,
|
|
17
|
+
private apiCall: ApiCall,
|
|
18
|
+
) {}
|
|
19
|
+
|
|
20
|
+
async retrieve(): Promise<StopwordSchema> {
|
|
21
|
+
return this.apiCall.get<StopwordSchema>(this.endpointPath());
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async delete(): Promise<StopwordDeleteSchema> {
|
|
25
|
+
return this.apiCall.delete<StopwordDeleteSchema>(this.endpointPath());
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
private endpointPath(): string {
|
|
29
|
+
return `${Stopwords.RESOURCEPATH}/${encodeURIComponent(this.stopwordId)}`;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import ApiCall from "./ApiCall";
|
|
2
|
+
import { StopwordSchema } from "./Stopword";
|
|
3
|
+
|
|
4
|
+
const RESOURCEPATH = "/stopwords";
|
|
5
|
+
|
|
6
|
+
export interface StopwordCreateSchema {
|
|
7
|
+
stopwords: string[];
|
|
8
|
+
locale?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface StopwordsRetrieveSchema {
|
|
12
|
+
stopwords: StopwordSchema[];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default class Stopwords {
|
|
16
|
+
constructor(private apiCall: ApiCall) {}
|
|
17
|
+
|
|
18
|
+
async upsert(
|
|
19
|
+
stopwordId: string,
|
|
20
|
+
params: StopwordCreateSchema,
|
|
21
|
+
): Promise<StopwordSchema> {
|
|
22
|
+
return this.apiCall.put<StopwordSchema>(
|
|
23
|
+
this.endpointPath(stopwordId),
|
|
24
|
+
params,
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async retrieve(): Promise<StopwordsRetrieveSchema> {
|
|
29
|
+
return this.apiCall.get<StopwordsRetrieveSchema>(this.endpointPath());
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
private endpointPath(operation?: string): string {
|
|
33
|
+
return `${Stopwords.RESOURCEPATH}${
|
|
34
|
+
operation === undefined ? "" : "/" + encodeURIComponent(operation)
|
|
35
|
+
}`;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static get RESOURCEPATH(): string {
|
|
39
|
+
return RESOURCEPATH;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import ApiCall from "./ApiCall";
|
|
2
|
+
import Collections from "./Collections";
|
|
3
|
+
import Synonyms, { SynonymCreateSchema } from "./Synonyms";
|
|
4
|
+
|
|
5
|
+
export interface SynonymSchema extends SynonymCreateSchema {
|
|
6
|
+
id: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface SynonymDeleteSchema {
|
|
10
|
+
id: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated Deprecated starting with Typesense Server v30. Please migrate to `client.synonymSets` (new Synonym Sets APIs).
|
|
15
|
+
*/
|
|
16
|
+
export default class Synonym {
|
|
17
|
+
private static hasWarnedDeprecation = false;
|
|
18
|
+
constructor(
|
|
19
|
+
private collectionName: string,
|
|
20
|
+
private synonymId: string,
|
|
21
|
+
private apiCall: ApiCall
|
|
22
|
+
) {}
|
|
23
|
+
|
|
24
|
+
async retrieve(): Promise<SynonymSchema> {
|
|
25
|
+
return this.apiCall.get<SynonymSchema>(this.endpointPath());
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async delete(): Promise<SynonymDeleteSchema> {
|
|
29
|
+
return this.apiCall.delete<SynonymDeleteSchema>(this.endpointPath());
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
private endpointPath(): string {
|
|
33
|
+
if (!Synonym.hasWarnedDeprecation) {
|
|
34
|
+
// eslint-disable-next-line no-console
|
|
35
|
+
console.warn(
|
|
36
|
+
"[typesense] 'synonym' APIs are deprecated starting with Typesense Server v30. Please migrate to synonym sets 'synonym_sets'.",
|
|
37
|
+
);
|
|
38
|
+
Synonym.hasWarnedDeprecation = true;
|
|
39
|
+
}
|
|
40
|
+
return `${Collections.RESOURCEPATH}/${encodeURIComponent(this.collectionName)}${Synonyms.RESOURCEPATH}/${encodeURIComponent(this.synonymId)}`;
|
|
41
|
+
}
|
|
42
|
+
}
|