Skip to content

Commit

Permalink
Improved methods in flush (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmoreram authored Jul 17, 2018
1 parent d01429f commit 78fd5bb
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 212 deletions.
85 changes: 24 additions & 61 deletions dist/apisearch.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/apisearch.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/apisearch.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/apisearch.min.js.map

Large diffs are not rendered by default.

9 changes: 0 additions & 9 deletions lib/Repository/HttpRepository.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,6 @@ export declare class HttpRepository extends Repository {
* @param object
*/
deleteObject(object: any): void;
/**
* flush items
*
* @param itemsToUpdate
* @param itemsToDelete
*
* @Returns {Promise<void>}
*/
flushItems(itemsToUpdate: Item[], itemsToDelete: ItemUUID[]): Promise<void>;
/**
* Flush update items
*
Expand Down
85 changes: 24 additions & 61 deletions lib/Repository/HttpRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,39 +64,6 @@ var HttpRepository = /** @class */ (function (_super) {
this.deleteItem(itemUUID);
}
};
/**
* flush items
*
* @param itemsToUpdate
* @param itemsToDelete
*
* @Returns {Promise<void>}
*/
HttpRepository.prototype.flushItems = function (itemsToUpdate, itemsToDelete) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var _a, _b, _c;
return tslib_1.__generator(this, function (_d) {
switch (_d.label) {
case 0:
_b = (_a = Promise).all;
return [4 /*yield*/, this.flushUpdateItems(itemsToUpdate)];
case 1:
_c = [
_d.sent()
];
return [4 /*yield*/, this.flushDeleteItems(itemsToDelete)];
case 2: return [4 /*yield*/, _b.apply(_a, [_c.concat([
_d.sent()
])]).then(function (_) {
return;
})];
case 3:
_d.sent();
return [2 /*return*/];
}
});
});
};
/**
* Flush update items
*
Expand All @@ -107,21 +74,19 @@ var HttpRepository = /** @class */ (function (_super) {
HttpRepository.prototype.flushUpdateItems = function (itemsToUpdate) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, (itemsToUpdate.length > 0)];
case 1: return [2 /*return*/, (_a.sent())
? this
.httpClient
.get("/items", "post", this.getCredentials(), {}, {
items: itemsToUpdate.map(function (item) {
return item.toArray();
})
})
.then(function (response) {
HttpRepository.throwTransportableExceptionIfNeeded(response);
})
: null];
if (itemsToUpdate.length === 0) {
return [2 /*return*/];
}
return [2 /*return*/, this
.httpClient
.get("/items", "post", this.getCredentials(), {}, {
items: itemsToUpdate.map(function (item) {
return item.toArray();
})
})
.then(function (response) {
HttpRepository.throwTransportableExceptionIfNeeded(response);
})];
});
});
};
Expand All @@ -135,21 +100,19 @@ var HttpRepository = /** @class */ (function (_super) {
HttpRepository.prototype.flushDeleteItems = function (itemsToDelete) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, (itemsToDelete.length > 0)];
case 1: return [2 /*return*/, (_a.sent())
? this
.httpClient
.get("/items", "delete", this.getCredentials(), {}, {
items: itemsToDelete.map(function (itemUUID) {
return itemUUID.toArray();
})
})
.then(function (response) {
HttpRepository.throwTransportableExceptionIfNeeded(response);
})
: null];
if (itemsToDelete.length === 0) {
return [2 /*return*/];
}
return [2 /*return*/, this
.httpClient
.get("/items", "delete", this.getCredentials(), {}, {
items: itemsToDelete.map(function (itemUUID) {
return itemUUID.toArray();
})
})
.then(function (response) {
HttpRepository.throwTransportableExceptionIfNeeded(response);
})];
});
});
};
Expand Down
7 changes: 0 additions & 7 deletions lib/Repository/Repository.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,6 @@ export declare abstract class Repository {
* @return {Promise<void>}
*/
abstract flushDeleteItems(itemsToDelete: ItemUUID[]): Promise<void>;
/**
* flush items
*
* @param itemsToUpdate
* @param itemsToDelete
*/
abstract flushItems(itemsToUpdate: Item[], itemsToDelete: ItemUUID[]): Promise<void>;
/**
* Query
*
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apisearch",
"version": "0.2.9",
"version": "0.2.10",
"description": "Javascript client for Apisearch.",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
97 changes: 40 additions & 57 deletions src/Repository/HttpRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,27 +82,6 @@ export class HttpRepository extends Repository {
}
}

/**
* flush items
*
* @param itemsToUpdate
* @param itemsToDelete
*
* @Returns {Promise<void>}
*/
public async flushItems(
itemsToUpdate: Item[],
itemsToDelete: ItemUUID[],
): Promise<void> {

await Promise.all([
await this.flushUpdateItems(itemsToUpdate),
await this.flushDeleteItems(itemsToDelete),
]).then((_) => {
return;
});
}

/**
* Flush update items
*
Expand All @@ -112,24 +91,26 @@ export class HttpRepository extends Repository {
*/
public async flushUpdateItems(itemsToUpdate: Item[]): Promise<void> {

return await (itemsToUpdate.length > 0)
? this
.httpClient
.get(
"/items",
"post",
this.getCredentials(),
{},
{
items: itemsToUpdate.map((item) => {
return item.toArray();
}),
},
)
.then((response) => {
HttpRepository.throwTransportableExceptionIfNeeded(response);
})
: null;
if (itemsToUpdate.length === 0) {
return;
}

return this
.httpClient
.get(
"/items",
"post",
this.getCredentials(),
{},
{
items: itemsToUpdate.map((item) => {
return item.toArray();
}),
},
)
.then((response) => {
HttpRepository.throwTransportableExceptionIfNeeded(response);
});
}

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

return await (itemsToDelete.length > 0)
? this
.httpClient
.get(
"/items",
"delete",
this.getCredentials(),
{},
{
items: itemsToDelete.map((itemUUID) => {
return itemUUID.toArray();
}),
},
)
.then((response) => {
HttpRepository.throwTransportableExceptionIfNeeded(response);
})
: null;
if (itemsToDelete.length === 0) {
return;
}

return this
.httpClient
.get(
"/items",
"delete",
this.getCredentials(),
{},
{
items: itemsToDelete.map((itemUUID) => {
return itemUUID.toArray();
}),
},
)
.then((response) => {
HttpRepository.throwTransportableExceptionIfNeeded(response);
});
}

/**
Expand Down
11 changes: 0 additions & 11 deletions src/Repository/Repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,17 +172,6 @@ export abstract class Repository {
*/
public abstract async flushDeleteItems(itemsToDelete: ItemUUID[]): Promise<void>;

/**
* flush items
*
* @param itemsToUpdate
* @param itemsToDelete
*/
public abstract async flushItems(
itemsToUpdate: Item[],
itemsToDelete: ItemUUID[],
): Promise<void>;

/**
* Query
*
Expand Down

0 comments on commit 78fd5bb

Please sign in to comment.