@@ -16,8 +16,8 @@ var Query_2 = require("./Query/Query");
1616var Query_3 = require ( "./Query/Query" ) ;
1717var SortBy_1 = require ( "./Query/SortBy" ) ;
1818var HttpRepository_1 = require ( "./Repository/HttpRepository" ) ;
19- var ResultAggregations_1 = require ( "./Result/ResultAggregations" ) ;
2019var Result_1 = require ( "./Result/Result" ) ;
20+ var ResultAggregations_1 = require ( "./Result/ResultAggregations" ) ;
2121var Transformer_1 = require ( "./Transformer/Transformer" ) ;
2222/**
2323 * Apisearch class
@@ -30,16 +30,41 @@ var Apisearch = /** @class */ (function () {
3030 *
3131 * @param config
3232 *
33- * @returns { Repository }
33+ * @return { HttpRepository }
3434 */
3535 Apisearch . createRepository = function ( config ) {
36- config . options = __assign ( { api_version : "v1" , cache : new NoCache_1 . NoCache ( ) , timeout : 10000 , override_queries : true } , config . options ) ;
36+ Apisearch . ensureRepositoryConfigIsValid ( config ) ;
37+ config . options = __assign ( { api_version : "v1" , cache : new NoCache_1 . NoCache ( ) , timeout : 5000 , override_queries : true } , config . options ) ;
3738 /**
3839 * Client
3940 */
40- 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 ) ;
41+ var httpClient = typeof config . options . http_client !== "undefined"
42+ ? config . options . http_client
43+ : 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 ) ;
4144 return new HttpRepository_1 . HttpRepository ( httpClient , config . app_id , config . index_id , config . token , new Transformer_1 . Transformer ( ) ) ;
4245 } ;
46+ /**
47+ * Ensure the Repository configuration is valid
48+ *
49+ * @param config
50+ */
51+ Apisearch . ensureRepositoryConfigIsValid = function ( config ) {
52+ Apisearch . ensureIsDefined ( config . app_id , "app_id" ) ;
53+ Apisearch . ensureIsDefined ( config . index_id , "index_id" ) ;
54+ Apisearch . ensureIsDefined ( config . token , "token" ) ;
55+ Apisearch . ensureIsDefined ( config . options . endpoint , "options.endpoint" ) ;
56+ } ;
57+ /**
58+ * Ensure the value is not undefined
59+ *
60+ * @param param
61+ * @param name
62+ */
63+ Apisearch . ensureIsDefined = function ( param , name ) {
64+ if ( typeof param === "undefined" ) {
65+ throw new TypeError ( name + " parameter must be defined." ) ;
66+ }
67+ } ;
4368 /**
4469 * Created located
4570 *
@@ -51,9 +76,9 @@ var Apisearch = /** @class */ (function () {
5176 * @returns {Query }
5277 */
5378 Apisearch . createQueryLocated = function ( coordinate , queryText , page , size ) {
54- if ( page === void 0 ) { page = Query_2 . QUERY_DEFAULT_PAGE ; }
55- if ( size === void 0 ) { size = Query_3 . QUERY_DEFAULT_SIZE ; }
56- return Query_1 . Query . createLocated ( coordinate , queryText , page , size ) ;
79+ if ( page === void 0 ) { page = Query_1 . QUERY_DEFAULT_PAGE ; }
80+ if ( size === void 0 ) { size = Query_2 . QUERY_DEFAULT_SIZE ; }
81+ return Query_3 . Query . createLocated ( coordinate , queryText , page , size ) ;
5782 } ;
5883 /**
5984 * Create
@@ -65,17 +90,17 @@ var Apisearch = /** @class */ (function () {
6590 * @returns {Query }
6691 */
6792 Apisearch . createQuery = function ( queryText , page , size ) {
68- if ( page === void 0 ) { page = Query_2 . QUERY_DEFAULT_PAGE ; }
69- if ( size === void 0 ) { size = Query_3 . QUERY_DEFAULT_SIZE ; }
70- return Query_1 . Query . create ( queryText , page , size ) ;
93+ if ( page === void 0 ) { page = Query_1 . QUERY_DEFAULT_PAGE ; }
94+ if ( size === void 0 ) { size = Query_2 . QUERY_DEFAULT_SIZE ; }
95+ return Query_3 . Query . create ( queryText , page , size ) ;
7196 } ;
7297 /**
7398 * Create match all
7499 *
75100 * @return {Query }
76101 */
77102 Apisearch . createQueryMatchAll = function ( ) {
78- return Query_1 . Query . createMatchAll ( ) ;
103+ return Query_3 . Query . createMatchAll ( ) ;
79104 } ;
80105 /**
81106 * Create by UUID
@@ -85,7 +110,7 @@ var Apisearch = /** @class */ (function () {
85110 * @return {Query }
86111 */
87112 Apisearch . createQueryByUUID = function ( uuid ) {
88- return Query_1 . Query . createByUUID ( uuid ) ;
113+ return Query_3 . Query . createByUUID ( uuid ) ;
89114 } ;
90115 /**
91116 * Create by UUIDs
@@ -99,7 +124,7 @@ var Apisearch = /** @class */ (function () {
99124 for ( var _i = 0 ; _i < arguments . length ; _i ++ ) {
100125 uuids [ _i ] = arguments [ _i ] ;
101126 }
102- return Query_1 . Query . createByUUIDs . apply ( Query_1 . Query , uuids ) ;
127+ return Query_3 . Query . createByUUIDs . apply ( Query_3 . Query , uuids ) ;
103128 } ;
104129 /**
105130 * Create empty result
0 commit comments