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

Commit 9c0d539

Browse files
committed
refactoring(Apisearch): changed index param to indexId + changed order of a composed uuid
1 parent 62477d9 commit 9c0d539

11 files changed

+47
-83
lines changed

dist/apisearch.js

Lines changed: 12 additions & 24 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: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/apisearch.node.js

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

dist/apisearch.node.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.node.min.js

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

src/Apisearch.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Apisearch {
1212
*/
1313
constructor({
1414
appId,
15-
index,
15+
indexId,
1616
token,
1717
options: {
1818
endpoint,
@@ -27,7 +27,7 @@ class Apisearch {
2727
* Api
2828
*/
2929
this.appId = appId;
30-
this.index = index;
30+
this.indexId = indexId;
3131
this.token = token;
3232
this.apiVersion = apiVersion;
3333
this.endpoint = endpoint;
@@ -61,7 +61,7 @@ class Apisearch {
6161
JSON.stringify(query)
6262
);
6363
let composedQuery = {
64-
url: `${this.protocol}://${this.endpoint}/${this.apiVersion}?app_id=${this.appId}&index=${this.index}&token=${this.token}&query=${encodedQuery}`,
64+
url: `${this.protocol}://${this.endpoint}/${this.apiVersion}?app_id=${this.appId}&indexId=${this.indexId}&token=${this.token}&query=${encodedQuery}`,
6565
options: {
6666
timeout: this.timeout
6767
}

src/Query/ItemUUID.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ export default class ItemUUID {
88
}
99

1010
composedUUID() {
11-
return `${this.type}~${this.id}`;
11+
return `${this.id}~${this.type}`;
1212
}
1313
}

src/index.js

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ import Apisearch from "./Apisearch";
1212

1313
module.exports = function({
1414
appId,
15-
index,
15+
indexId,
1616
token,
1717
options = {}
1818
}) {
19-
checkAppId(appId);
20-
checkIndex(index);
21-
checkApiKey(token);
19+
ensureIsDefined(appId, 'appId');
20+
ensureIsDefined(indexId, 'indexId');
21+
ensureIsDefined(token, 'token');
2222

2323
options = {
2424
endpoint: 'api.apisear.ch',
@@ -32,26 +32,14 @@ module.exports = function({
3232

3333
return new Apisearch({
3434
appId,
35-
index,
35+
indexId,
3636
token,
3737
options
3838
});
3939
};
4040

41-
function checkAppId(appId) {
42-
if (typeof appId === 'undefined') {
43-
throw new TypeError(`appId parameter must be defined.`)
44-
}
45-
}
46-
47-
function checkIndex(index) {
48-
if (typeof index === 'undefined') {
49-
throw new TypeError(`index parameter must be defined.`)
50-
}
51-
}
52-
53-
function checkApiKey(token) {
54-
if (typeof token === 'undefined') {
55-
throw new TypeError(`token parameter must be defined.`)
41+
function ensureIsDefined(param, name) {
42+
if (typeof param === 'undefined') {
43+
throw new TypeError(`${name} parameter must be defined.`)
5644
}
5745
}

test/Query.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ describe('Query()', () => {
518518
});
519519

520520
it('should exclude one uuid when calling excludeUUID()', () => {
521-
expect(query.filters['excluded_ids'].values).to.include('marvel~hulk');
521+
expect(query.filters['excluded_ids'].values).to.include('hulk~marvel');
522522
});
523523

524524
it('should exclude many uuids when calling excludeUUIDs()', () => {
@@ -527,8 +527,8 @@ describe('Query()', () => {
527527
new ItemUUID('daredevil', 'marvel')
528528
);
529529
expect(query.filters['excluded_ids'].values).to.deep.equal([
530-
'marvel~captain-america',
531-
'marvel~daredevil'
530+
'captain-america~marvel',
531+
'daredevil~marvel'
532532
]);
533533
});
534534
});

0 commit comments

Comments
 (0)