@@ -16,8 +16,8 @@ var Query_2 = require("./Query/Query");
16
16
var Query_3 = require ( "./Query/Query" ) ;
17
17
var SortBy_1 = require ( "./Query/SortBy" ) ;
18
18
var HttpRepository_1 = require ( "./Repository/HttpRepository" ) ;
19
- var ResultAggregations_1 = require ( "./Result/ResultAggregations" ) ;
20
19
var Result_1 = require ( "./Result/Result" ) ;
20
+ var ResultAggregations_1 = require ( "./Result/ResultAggregations" ) ;
21
21
var Transformer_1 = require ( "./Transformer/Transformer" ) ;
22
22
/**
23
23
* Apisearch class
@@ -30,16 +30,41 @@ var Apisearch = /** @class */ (function () {
30
30
*
31
31
* @param config
32
32
*
33
- * @returns { Repository }
33
+ * @return { HttpRepository }
34
34
*/
35
35
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 ) ;
37
38
/**
38
39
* Client
39
40
*/
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 ) ;
41
44
return new HttpRepository_1 . HttpRepository ( httpClient , config . app_id , config . index_id , config . token , new Transformer_1 . Transformer ( ) ) ;
42
45
} ;
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
+ } ;
43
68
/**
44
69
* Created located
45
70
*
@@ -51,9 +76,9 @@ var Apisearch = /** @class */ (function () {
51
76
* @returns {Query }
52
77
*/
53
78
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 ) ;
57
82
} ;
58
83
/**
59
84
* Create
@@ -65,17 +90,17 @@ var Apisearch = /** @class */ (function () {
65
90
* @returns {Query }
66
91
*/
67
92
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 ) ;
71
96
} ;
72
97
/**
73
98
* Create match all
74
99
*
75
100
* @return {Query }
76
101
*/
77
102
Apisearch . createQueryMatchAll = function ( ) {
78
- return Query_1 . Query . createMatchAll ( ) ;
103
+ return Query_3 . Query . createMatchAll ( ) ;
79
104
} ;
80
105
/**
81
106
* Create by UUID
@@ -85,7 +110,7 @@ var Apisearch = /** @class */ (function () {
85
110
* @return {Query }
86
111
*/
87
112
Apisearch . createQueryByUUID = function ( uuid ) {
88
- return Query_1 . Query . createByUUID ( uuid ) ;
113
+ return Query_3 . Query . createByUUID ( uuid ) ;
89
114
} ;
90
115
/**
91
116
* Create by UUIDs
@@ -99,7 +124,7 @@ var Apisearch = /** @class */ (function () {
99
124
for ( var _i = 0 ; _i < arguments . length ; _i ++ ) {
100
125
uuids [ _i ] = arguments [ _i ] ;
101
126
}
102
- return Query_1 . Query . createByUUIDs . apply ( Query_1 . Query , uuids ) ;
127
+ return Query_3 . Query . createByUUIDs . apply ( Query_3 . Query , uuids ) ;
103
128
} ;
104
129
/**
105
130
* Create empty result
0 commit comments