Skip to content

Commit 78fd5bb

Browse files
authored
Improved methods in flush (#18)
1 parent d01429f commit 78fd5bb

10 files changed

+94
-212
lines changed

dist/apisearch.js

+24-61
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/apisearch.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/apisearch.min.js

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/apisearch.min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/Repository/HttpRepository.d.ts

-9
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,6 @@ export declare class HttpRepository extends Repository {
4343
* @param object
4444
*/
4545
deleteObject(object: any): void;
46-
/**
47-
* flush items
48-
*
49-
* @param itemsToUpdate
50-
* @param itemsToDelete
51-
*
52-
* @Returns {Promise<void>}
53-
*/
54-
flushItems(itemsToUpdate: Item[], itemsToDelete: ItemUUID[]): Promise<void>;
5546
/**
5647
* Flush update items
5748
*

lib/Repository/HttpRepository.js

+24-61
Original file line numberDiff line numberDiff line change
@@ -64,39 +64,6 @@ var HttpRepository = /** @class */ (function (_super) {
6464
this.deleteItem(itemUUID);
6565
}
6666
};
67-
/**
68-
* flush items
69-
*
70-
* @param itemsToUpdate
71-
* @param itemsToDelete
72-
*
73-
* @Returns {Promise<void>}
74-
*/
75-
HttpRepository.prototype.flushItems = function (itemsToUpdate, itemsToDelete) {
76-
return tslib_1.__awaiter(this, void 0, void 0, function () {
77-
var _a, _b, _c;
78-
return tslib_1.__generator(this, function (_d) {
79-
switch (_d.label) {
80-
case 0:
81-
_b = (_a = Promise).all;
82-
return [4 /*yield*/, this.flushUpdateItems(itemsToUpdate)];
83-
case 1:
84-
_c = [
85-
_d.sent()
86-
];
87-
return [4 /*yield*/, this.flushDeleteItems(itemsToDelete)];
88-
case 2: return [4 /*yield*/, _b.apply(_a, [_c.concat([
89-
_d.sent()
90-
])]).then(function (_) {
91-
return;
92-
})];
93-
case 3:
94-
_d.sent();
95-
return [2 /*return*/];
96-
}
97-
});
98-
});
99-
};
10067
/**
10168
* Flush update items
10269
*
@@ -107,21 +74,19 @@ var HttpRepository = /** @class */ (function (_super) {
10774
HttpRepository.prototype.flushUpdateItems = function (itemsToUpdate) {
10875
return tslib_1.__awaiter(this, void 0, void 0, function () {
10976
return tslib_1.__generator(this, function (_a) {
110-
switch (_a.label) {
111-
case 0: return [4 /*yield*/, (itemsToUpdate.length > 0)];
112-
case 1: return [2 /*return*/, (_a.sent())
113-
? this
114-
.httpClient
115-
.get("/items", "post", this.getCredentials(), {}, {
116-
items: itemsToUpdate.map(function (item) {
117-
return item.toArray();
118-
})
119-
})
120-
.then(function (response) {
121-
HttpRepository.throwTransportableExceptionIfNeeded(response);
122-
})
123-
: null];
77+
if (itemsToUpdate.length === 0) {
78+
return [2 /*return*/];
12479
}
80+
return [2 /*return*/, this
81+
.httpClient
82+
.get("/items", "post", this.getCredentials(), {}, {
83+
items: itemsToUpdate.map(function (item) {
84+
return item.toArray();
85+
})
86+
})
87+
.then(function (response) {
88+
HttpRepository.throwTransportableExceptionIfNeeded(response);
89+
})];
12590
});
12691
});
12792
};
@@ -135,21 +100,19 @@ var HttpRepository = /** @class */ (function (_super) {
135100
HttpRepository.prototype.flushDeleteItems = function (itemsToDelete) {
136101
return tslib_1.__awaiter(this, void 0, void 0, function () {
137102
return tslib_1.__generator(this, function (_a) {
138-
switch (_a.label) {
139-
case 0: return [4 /*yield*/, (itemsToDelete.length > 0)];
140-
case 1: return [2 /*return*/, (_a.sent())
141-
? this
142-
.httpClient
143-
.get("/items", "delete", this.getCredentials(), {}, {
144-
items: itemsToDelete.map(function (itemUUID) {
145-
return itemUUID.toArray();
146-
})
147-
})
148-
.then(function (response) {
149-
HttpRepository.throwTransportableExceptionIfNeeded(response);
150-
})
151-
: null];
103+
if (itemsToDelete.length === 0) {
104+
return [2 /*return*/];
152105
}
106+
return [2 /*return*/, this
107+
.httpClient
108+
.get("/items", "delete", this.getCredentials(), {}, {
109+
items: itemsToDelete.map(function (itemUUID) {
110+
return itemUUID.toArray();
111+
})
112+
})
113+
.then(function (response) {
114+
HttpRepository.throwTransportableExceptionIfNeeded(response);
115+
})];
153116
});
154117
});
155118
};

lib/Repository/Repository.d.ts

-7
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,6 @@ export declare abstract class Repository {
8484
* @return {Promise<void>}
8585
*/
8686
abstract flushDeleteItems(itemsToDelete: ItemUUID[]): Promise<void>;
87-
/**
88-
* flush items
89-
*
90-
* @param itemsToUpdate
91-
* @param itemsToDelete
92-
*/
93-
abstract flushItems(itemsToUpdate: Item[], itemsToDelete: ItemUUID[]): Promise<void>;
9487
/**
9588
* Query
9689
*

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "apisearch",
3-
"version": "0.2.9",
3+
"version": "0.2.10",
44
"description": "Javascript client for Apisearch.",
55
"main": "lib/index.js",
66
"types": "lib/index.d.ts",

src/Repository/HttpRepository.ts

+40-57
Original file line numberDiff line numberDiff line change
@@ -82,27 +82,6 @@ export class HttpRepository extends Repository {
8282
}
8383
}
8484

85-
/**
86-
* flush items
87-
*
88-
* @param itemsToUpdate
89-
* @param itemsToDelete
90-
*
91-
* @Returns {Promise<void>}
92-
*/
93-
public async flushItems(
94-
itemsToUpdate: Item[],
95-
itemsToDelete: ItemUUID[],
96-
): Promise<void> {
97-
98-
await Promise.all([
99-
await this.flushUpdateItems(itemsToUpdate),
100-
await this.flushDeleteItems(itemsToDelete),
101-
]).then((_) => {
102-
return;
103-
});
104-
}
105-
10685
/**
10786
* Flush update items
10887
*
@@ -112,24 +91,26 @@ export class HttpRepository extends Repository {
11291
*/
11392
public async flushUpdateItems(itemsToUpdate: Item[]): Promise<void> {
11493

115-
return await (itemsToUpdate.length > 0)
116-
? this
117-
.httpClient
118-
.get(
119-
"/items",
120-
"post",
121-
this.getCredentials(),
122-
{},
123-
{
124-
items: itemsToUpdate.map((item) => {
125-
return item.toArray();
126-
}),
127-
},
128-
)
129-
.then((response) => {
130-
HttpRepository.throwTransportableExceptionIfNeeded(response);
131-
})
132-
: null;
94+
if (itemsToUpdate.length === 0) {
95+
return;
96+
}
97+
98+
return this
99+
.httpClient
100+
.get(
101+
"/items",
102+
"post",
103+
this.getCredentials(),
104+
{},
105+
{
106+
items: itemsToUpdate.map((item) => {
107+
return item.toArray();
108+
}),
109+
},
110+
)
111+
.then((response) => {
112+
HttpRepository.throwTransportableExceptionIfNeeded(response);
113+
});
133114
}
134115

135116
/**
@@ -141,24 +122,26 @@ export class HttpRepository extends Repository {
141122
*/
142123
public async flushDeleteItems(itemsToDelete: ItemUUID[]): Promise<void> {
143124

144-
return await (itemsToDelete.length > 0)
145-
? this
146-
.httpClient
147-
.get(
148-
"/items",
149-
"delete",
150-
this.getCredentials(),
151-
{},
152-
{
153-
items: itemsToDelete.map((itemUUID) => {
154-
return itemUUID.toArray();
155-
}),
156-
},
157-
)
158-
.then((response) => {
159-
HttpRepository.throwTransportableExceptionIfNeeded(response);
160-
})
161-
: null;
125+
if (itemsToDelete.length === 0) {
126+
return;
127+
}
128+
129+
return this
130+
.httpClient
131+
.get(
132+
"/items",
133+
"delete",
134+
this.getCredentials(),
135+
{},
136+
{
137+
items: itemsToDelete.map((itemUUID) => {
138+
return itemUUID.toArray();
139+
}),
140+
},
141+
)
142+
.then((response) => {
143+
HttpRepository.throwTransportableExceptionIfNeeded(response);
144+
});
162145
}
163146

164147
/**

src/Repository/Repository.ts

-11
Original file line numberDiff line numberDiff line change
@@ -172,17 +172,6 @@ export abstract class Repository {
172172
*/
173173
public abstract async flushDeleteItems(itemsToDelete: ItemUUID[]): Promise<void>;
174174

175-
/**
176-
* flush items
177-
*
178-
* @param itemsToUpdate
179-
* @param itemsToDelete
180-
*/
181-
public abstract async flushItems(
182-
itemsToUpdate: Item[],
183-
itemsToDelete: ItemUUID[],
184-
): Promise<void>;
185-
186175
/**
187176
* Query
188177
*

0 commit comments

Comments
 (0)