Skip to content
This repository was archived by the owner on Jun 25, 2025. It is now read-only.

Commit 3f94903

Browse files
authored
Fixed endpoints for index configuration (#22)
- Added some model classes - Tested new features - Increased all functional tests
1 parent f9d55d3 commit 3f94903

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+3014
-2100
lines changed

dist/apisearch.js

Lines changed: 400 additions & 71 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/apisearch.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/apisearch.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/apisearch.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/Config/Config.d.ts

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,54 @@
1+
import { Synonym } from "./Synonym";
12
/**
23
* Result class
34
*/
45
export declare class Config {
6+
private language;
7+
private storeSearchableMetadata;
8+
private synonyms;
59
/**
6-
* To array
10+
* Constructor
711
*
8-
* @returns {any}
12+
* @param language
13+
* @param storeSearchableMetadata
914
*/
10-
toArray(): any;
15+
constructor(language?: string, storeSearchableMetadata?: boolean);
16+
/**
17+
* Get language
18+
*
19+
* @return {string}
20+
*/
21+
getLanguage(): string;
22+
/**
23+
* Should searchable metadata be stored
24+
*
25+
* @return {boolean}
26+
*/
27+
shouldSearchableMetadataBeStored(): boolean;
28+
/**
29+
* Add synonym
30+
*
31+
* @param synonym
32+
*/
33+
addSynonym(synonym: Synonym): void;
34+
/**
35+
* Get synonyms
36+
*
37+
* @return {Synonym[]}
38+
*/
39+
getSynonyms(): Synonym[];
40+
/**
41+
* to array
42+
*/
43+
toArray(): {
44+
language: string;
45+
store_searchable_metadata: boolean;
46+
synonyms: {
47+
words: string[];
48+
}[];
49+
};
50+
/**
51+
* Create from array
52+
*/
53+
static createFromArray(array: any): Config;
1154
}

lib/Config/Config.js

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,77 @@
11
"use strict";
22
exports.__esModule = true;
3+
var Synonym_1 = require("./Synonym");
34
/**
45
* Result class
56
*/
67
var Config = /** @class */ (function () {
7-
function Config() {
8+
/**
9+
* Constructor
10+
*
11+
* @param language
12+
* @param storeSearchableMetadata
13+
*/
14+
function Config(language, storeSearchableMetadata) {
15+
if (language === void 0) { language = null; }
16+
if (storeSearchableMetadata === void 0) { storeSearchableMetadata = true; }
17+
this.synonyms = [];
18+
this.language = language;
19+
this.storeSearchableMetadata = storeSearchableMetadata;
820
}
921
/**
10-
* To array
22+
* Get language
23+
*
24+
* @return {string}
25+
*/
26+
Config.prototype.getLanguage = function () {
27+
return this.language;
28+
};
29+
/**
30+
* Should searchable metadata be stored
31+
*
32+
* @return {boolean}
33+
*/
34+
Config.prototype.shouldSearchableMetadataBeStored = function () {
35+
return this.storeSearchableMetadata;
36+
};
37+
/**
38+
* Add synonym
1139
*
12-
* @returns {any}
40+
* @param synonym
41+
*/
42+
Config.prototype.addSynonym = function (synonym) {
43+
this.synonyms.push(synonym);
44+
};
45+
/**
46+
* Get synonyms
47+
*
48+
* @return {Synonym[]}
49+
*/
50+
Config.prototype.getSynonyms = function () {
51+
return this.synonyms;
52+
};
53+
/**
54+
* to array
1355
*/
1456
Config.prototype.toArray = function () {
15-
return {};
57+
return {
58+
language: this.language,
59+
store_searchable_metadata: this.storeSearchableMetadata,
60+
synonyms: this.synonyms.map(function (synonym) { return synonym.toArray(); })
61+
};
62+
};
63+
/**
64+
* Create from array
65+
*/
66+
Config.createFromArray = function (array) {
67+
var immutableConfig = new Config(array.language ? array.language : null, typeof array.store_searchable_metadata == "boolean"
68+
? array.store_searchable_metadata
69+
: true);
70+
if (array.synonyms instanceof Array &&
71+
array.synonyms.length > 0) {
72+
immutableConfig.synonyms = array.synonyms.map(function (synonym) { return Synonym_1.Synonym.createFromArray(synonym); });
73+
}
74+
return immutableConfig;
1675
};
1776
return Config;
1877
}());

lib/Error/InvalidFormatError.d.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,24 @@ export declare class InvalidFormatError extends ErrorWithMessage {
5757
* @return {InvalidFormatError}
5858
*/
5959
static tokenFormatNotValid(): InvalidFormatError;
60+
/**
61+
* Index format not valid.
62+
*
63+
* @return {InvalidFormatError}
64+
*/
65+
static indexFormatNotValid(): InvalidFormatError;
66+
/**
67+
* IndexUUI format not valid.
68+
*
69+
* @return {InvalidFormatError}
70+
*/
71+
static indexUUIDFormatNotValid(): InvalidFormatError;
72+
/**
73+
* App format not valid.
74+
*
75+
* @return {InvalidFormatError}
76+
*/
77+
static appUUIDFormatNotValid(): InvalidFormatError;
6078
/**
6179
* Campaign representation not valid
6280
*

lib/Error/InvalidFormatError.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,30 @@ var InvalidFormatError = /** @class */ (function (_super) {
8282
InvalidFormatError.tokenFormatNotValid = function () {
8383
return new InvalidFormatError("Token Format not valid. Expecting a Token serialized but found malformed data");
8484
};
85+
/**
86+
* Index format not valid.
87+
*
88+
* @return {InvalidFormatError}
89+
*/
90+
InvalidFormatError.indexFormatNotValid = function () {
91+
return new InvalidFormatError('Index Format not valid. Expecting an Index serialized but found malformed data');
92+
};
93+
/**
94+
* IndexUUI format not valid.
95+
*
96+
* @return {InvalidFormatError}
97+
*/
98+
InvalidFormatError.indexUUIDFormatNotValid = function () {
99+
return new InvalidFormatError('IndexUUID Format not valid. Expecting an IndexUUID serialized but found malformed data');
100+
};
101+
/**
102+
* App format not valid.
103+
*
104+
* @return {InvalidFormatError}
105+
*/
106+
InvalidFormatError.appUUIDFormatNotValid = function () {
107+
return new InvalidFormatError('AppUUID Format not valid. Expecting an AppUUID serialized but found malformed data');
108+
};
85109
/**
86110
* Campaign representation not valid
87111
*

lib/Http/AxiosClient.d.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ export declare class AxiosClient extends Client implements HttpClient {
3838
/**
3939
* Abort current request
4040
* And regenerate the cancellation token
41+
*
42+
* @param url
43+
*/
44+
abort(url: string): void;
45+
/**
46+
* Generate a new cancellation token for a query
47+
*
48+
* @param url
4149
*/
42-
abort(): void;
50+
generateCancelToken(url: string): void;
4351
}

lib/Http/AxiosClient.js

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var AxiosClient = /** @class */ (function (_super) {
2525
_this.timeout = timeout;
2626
_this.cache = cache;
2727
_this.overrideQueries = overrideQueries;
28-
_this.cancelToken = axios_1["default"].CancelToken.source();
28+
_this.cancelToken = {};
2929
return _this;
3030
}
3131
/**
@@ -52,7 +52,7 @@ var AxiosClient = /** @class */ (function (_super) {
5252
method = method.toLowerCase();
5353
if ("get" === method &&
5454
this.overrideQueries) {
55-
this.abort();
55+
this.abort(url);
5656
}
5757
return [2 /*return*/, new Promise(function (resolve, reject) {
5858
var headers = "get" == method
@@ -61,33 +61,50 @@ var AxiosClient = /** @class */ (function (_super) {
6161
"Content-Encoding": "gzip",
6262
"Content-Type": "application/json"
6363
};
64-
//noinspection TypeScriptValidateTypes
65-
axios_1["default"]
66-
.request({
64+
var axiosRequestConfig = {
6765
url: url + "?" + Client_1.Client.objectToUrlParameters(tslib_1.__assign({}, credentials, parameters)),
6866
data: data,
6967
headers: headers,
7068
method: method,
7169
baseURL: that.host.replace(/\/*$/g, ""),
7270
timeout: that.timeout,
73-
cancelToken: _this.cancelToken.token,
7471
transformRequest: [function (data) { return JSON.stringify(data); }]
75-
})
72+
};
73+
if (typeof _this.cancelToken[url] != 'undefined') {
74+
axiosRequestConfig.cancelToken = _this.cancelToken[url].token;
75+
}
76+
axios_1["default"]
77+
.request(axiosRequestConfig)
7678
.then(function (axiosResponse) {
7779
var response = new Response_1.Response(axiosResponse.status, axiosResponse.data);
7880
return resolve(response);
79-
})["catch"](function (thrown) { return reject(thrown); });
81+
})["catch"](function (error) {
82+
var response = new Response_1.Response(error.response.status, error.response.data);
83+
return reject(response);
84+
});
8085
})];
8186
});
8287
});
8388
};
8489
/**
8590
* Abort current request
8691
* And regenerate the cancellation token
92+
*
93+
* @param url
94+
*/
95+
AxiosClient.prototype.abort = function (url) {
96+
if (typeof this.cancelToken[url] != 'undefined') {
97+
this.cancelToken[url].cancel();
98+
}
99+
this.generateCancelToken(url);
100+
};
101+
/**
102+
* Generate a new cancellation token for a query
103+
*
104+
* @param url
87105
*/
88-
AxiosClient.prototype.abort = function () {
89-
this.cancelToken.cancel();
90-
this.cancelToken = axios_1["default"].CancelToken.source();
106+
AxiosClient.prototype.generateCancelToken = function (url) {
107+
this.cancelToken[url] = axios_1["default"].CancelToken.source();
91108
};
92109
return AxiosClient;
93110
}(Client_1.Client));

0 commit comments

Comments
 (0)