Skip to content

Improved the way to check configuration #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 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.

4 changes: 2 additions & 2 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.

23 changes: 19 additions & 4 deletions lib/Apisearch.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { KeyValueCache } from "./Cache/KeyValueCache";
import { HttpClient } from "./Http/HttpClient";
import { Coordinate } from "./Model/Coordinate";
import { ItemUUID } from "./Model/ItemUUID";
import { Query } from "./Query/Query";
import { SortBy } from "./Query/SortBy";
import { Repository } from "./Repository/Repository";
import { HttpRepository } from "./Repository/HttpRepository";
import { Result } from "./Result/Result";
/**
* Apisearch class
Expand All @@ -14,20 +15,34 @@ export default class Apisearch {
*
* @param config
*
* @returns {Repository}
* @return {HttpRepository}
*/
static createRepository(config: {
app_id: string;
index_id: string;
token: string;
options: {
endpoint?: string;
endpoint: string;
api_version?: string;
timeout?: number;
override_queries?: boolean;
cache?: KeyValueCache;
http_client?: HttpClient;
};
}): Repository;
}): HttpRepository;
/**
* Ensure the Repository configuration is valid
*
* @param config
*/
static ensureRepositoryConfigIsValid(config: any): void;
/**
* Ensure the value is not undefined
*
* @param param
* @param name
*/
static ensureIsDefined(param: any, name: string): void;
/**
* Created located
*
Expand Down
51 changes: 38 additions & 13 deletions lib/Apisearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ var Query_2 = require("./Query/Query");
var Query_3 = require("./Query/Query");
var SortBy_1 = require("./Query/SortBy");
var HttpRepository_1 = require("./Repository/HttpRepository");
var ResultAggregations_1 = require("./Result/ResultAggregations");
var Result_1 = require("./Result/Result");
var ResultAggregations_1 = require("./Result/ResultAggregations");
var Transformer_1 = require("./Transformer/Transformer");
/**
* Apisearch class
Expand All @@ -30,16 +30,41 @@ var Apisearch = /** @class */ (function () {
*
* @param config
*
* @returns {Repository}
* @return {HttpRepository}
*/
Apisearch.createRepository = function (config) {
config.options = __assign({ api_version: "v1", cache: new NoCache_1.NoCache(), timeout: 10000, override_queries: true }, config.options);
Apisearch.ensureRepositoryConfigIsValid(config);
config.options = __assign({ api_version: "v1", cache: new NoCache_1.NoCache(), timeout: 5000, override_queries: true }, config.options);
/**
* Client
*/
var httpClient = new AxiosClient_1.AxiosClient(config.options.endpoint, config.options.api_version, config.options.timeout, new RetryMap_1.RetryMap(), config.options.override_queries, config.options.cache);
var httpClient = typeof config.options.http_client !== "undefined"
? config.options.http_client
: new AxiosClient_1.AxiosClient(config.options.endpoint, config.options.api_version, config.options.timeout, new RetryMap_1.RetryMap(), config.options.override_queries, config.options.cache);
return new HttpRepository_1.HttpRepository(httpClient, config.app_id, config.index_id, config.token, new Transformer_1.Transformer());
};
/**
* Ensure the Repository configuration is valid
*
* @param config
*/
Apisearch.ensureRepositoryConfigIsValid = function (config) {
Apisearch.ensureIsDefined(config.app_id, "app_id");
Apisearch.ensureIsDefined(config.index_id, "index_id");
Apisearch.ensureIsDefined(config.token, "token");
Apisearch.ensureIsDefined(config.options.endpoint, "options.endpoint");
};
/**
* Ensure the value is not undefined
*
* @param param
* @param name
*/
Apisearch.ensureIsDefined = function (param, name) {
if (typeof param === "undefined") {
throw new TypeError(name + " parameter must be defined.");
}
};
/**
* Created located
*
Expand All @@ -51,9 +76,9 @@ var Apisearch = /** @class */ (function () {
* @returns {Query}
*/
Apisearch.createQueryLocated = function (coordinate, queryText, page, size) {
if (page === void 0) { page = Query_2.QUERY_DEFAULT_PAGE; }
if (size === void 0) { size = Query_3.QUERY_DEFAULT_SIZE; }
return Query_1.Query.createLocated(coordinate, queryText, page, size);
if (page === void 0) { page = Query_1.QUERY_DEFAULT_PAGE; }
if (size === void 0) { size = Query_2.QUERY_DEFAULT_SIZE; }
return Query_3.Query.createLocated(coordinate, queryText, page, size);
};
/**
* Create
Expand All @@ -65,17 +90,17 @@ var Apisearch = /** @class */ (function () {
* @returns {Query}
*/
Apisearch.createQuery = function (queryText, page, size) {
if (page === void 0) { page = Query_2.QUERY_DEFAULT_PAGE; }
if (size === void 0) { size = Query_3.QUERY_DEFAULT_SIZE; }
return Query_1.Query.create(queryText, page, size);
if (page === void 0) { page = Query_1.QUERY_DEFAULT_PAGE; }
if (size === void 0) { size = Query_2.QUERY_DEFAULT_SIZE; }
return Query_3.Query.create(queryText, page, size);
};
/**
* Create match all
*
* @return {Query}
*/
Apisearch.createQueryMatchAll = function () {
return Query_1.Query.createMatchAll();
return Query_3.Query.createMatchAll();
};
/**
* Create by UUID
Expand All @@ -85,7 +110,7 @@ var Apisearch = /** @class */ (function () {
* @return {Query}
*/
Apisearch.createQueryByUUID = function (uuid) {
return Query_1.Query.createByUUID(uuid);
return Query_3.Query.createByUUID(uuid);
};
/**
* Create by UUIDs
Expand All @@ -99,7 +124,7 @@ var Apisearch = /** @class */ (function () {
for (var _i = 0; _i < arguments.length; _i++) {
uuids[_i] = arguments[_i];
}
return Query_1.Query.createByUUIDs.apply(Query_1.Query, uuids);
return Query_3.Query.createByUUIDs.apply(Query_3.Query, uuids);
};
/**
* Create empty result
Expand Down
2 changes: 1 addition & 1 deletion lib/Cache/InMemoryCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ var InMemoryCache = /** @class */ (function () {
* @returns {void}
*/
InMemoryCache.prototype.set = function (key, value) {
var _a;
this.cache = __assign({}, this.cache, (_a = {}, _a[key] = value, _a));
this.size = this.size + 1;
var _a;
};
/**
* Get element from cache
Expand Down
6 changes: 3 additions & 3 deletions lib/Http/AxiosClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [0, t.value];
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
Expand Down Expand Up @@ -95,8 +95,8 @@ var AxiosClient = /** @class */ (function (_super) {
if (parameters === void 0) { parameters = {}; }
if (data === void 0) { data = {}; }
return __awaiter(this, void 0, void 0, function () {
var _this = this;
var that;
var _this = this;
return __generator(this, function (_a) {
that = this;
url = url.replace(/^\/*|\/*$/g, "");
Expand Down
4 changes: 2 additions & 2 deletions lib/Http/TestClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [0, t.value];
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
Expand Down
Loading