@miso.ai/client-sdk-algolia 1.11.6-beta.0 → 1.11.6-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/client.js +4 -5
- package/dist/cjs/data.js +33 -41
- package/dist/cjs/filter/index.js +24 -44
- package/dist/cjs/filter/shadow.js +2 -8
- package/dist/cjs/plugin.js +1 -2
- package/package.json +2 -2
package/dist/cjs/client.js
CHANGED
|
@@ -7,11 +7,10 @@ exports.default = void 0;
|
|
|
7
7
|
var _commons = require("@miso.ai/commons");
|
|
8
8
|
var _data = require("./data.js");
|
|
9
9
|
class AlgoliaClient extends _commons.Component {
|
|
10
|
-
constructor(algolia
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
10
|
+
constructor(algolia, {
|
|
11
|
+
api = _commons.API.NAME.SEARCH,
|
|
12
|
+
handleSearch
|
|
13
|
+
} = {}) {
|
|
15
14
|
super('client', algolia._plugin);
|
|
16
15
|
this._plugin = algolia._plugin;
|
|
17
16
|
this._client = algolia._client;
|
package/dist/cjs/data.js
CHANGED
|
@@ -11,12 +11,11 @@ const _excluded = ["payload", "query", "attributesToRetrieve"],
|
|
|
11
11
|
_excluded2 = ["attributesToSnippet", "snippetEllipsisText", "restrictHighlightAndSnippetArrays"];
|
|
12
12
|
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
13
13
|
const DEFAULT_ROWS = 5;
|
|
14
|
-
function buildPayload(algoliaClient, apiName,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
} = _ref;
|
|
14
|
+
function buildPayload(algoliaClient, apiName, {
|
|
15
|
+
indexName,
|
|
16
|
+
query,
|
|
17
|
+
params = {}
|
|
18
|
+
}) {
|
|
20
19
|
const {
|
|
21
20
|
payload,
|
|
22
21
|
query: queryFromParams,
|
|
@@ -30,8 +29,8 @@ function buildPayload(algoliaClient, apiName, _ref) {
|
|
|
30
29
|
fl: buildFl(algoliaClient, attributesToRetrieve)
|
|
31
30
|
}, buildPageInfo(params), (0, _index.buildFilters)(algoliaClient, params), buildFacets(params), buildForAutoComplete(apiName, params)));
|
|
32
31
|
}
|
|
33
|
-
function checkForUnsupportedParameters(
|
|
34
|
-
let params = _objectWithoutPropertiesLoose(
|
|
32
|
+
function checkForUnsupportedParameters(_ref) {
|
|
33
|
+
let params = _objectWithoutPropertiesLoose(_ref, _excluded2);
|
|
35
34
|
} // TODO
|
|
36
35
|
const CHAR_DASH = '-'.charCodeAt(0);
|
|
37
36
|
function buildFl(algoliaClient, attributesToRetrieve) {
|
|
@@ -55,24 +54,22 @@ function buildFl(algoliaClient, attributesToRetrieve) {
|
|
|
55
54
|
}
|
|
56
55
|
return fl;
|
|
57
56
|
}
|
|
58
|
-
function buildPageInfo(
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
} = _ref3;
|
|
57
|
+
function buildPageInfo({
|
|
58
|
+
hitsPerPage,
|
|
59
|
+
page,
|
|
60
|
+
offset,
|
|
61
|
+
length
|
|
62
|
+
}) {
|
|
65
63
|
// TODO: we may want to hack hitsPerPage if completion_fields is present
|
|
66
64
|
return {
|
|
67
65
|
rows: hitsPerPage || length || DEFAULT_ROWS,
|
|
68
66
|
start: page && (hitsPerPage || DEFAULT_ROWS) * page || offset || undefined
|
|
69
67
|
};
|
|
70
68
|
}
|
|
71
|
-
function buildFacets(
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
} = _ref4;
|
|
69
|
+
function buildFacets({
|
|
70
|
+
facets,
|
|
71
|
+
maxValuesPerFacet
|
|
72
|
+
}) {
|
|
76
73
|
facets = (0, _commons.asArray)(facets);
|
|
77
74
|
if (!facets.length) {
|
|
78
75
|
return undefined;
|
|
@@ -87,12 +84,11 @@ function buildFacets(_ref4) {
|
|
|
87
84
|
facets
|
|
88
85
|
};
|
|
89
86
|
}
|
|
90
|
-
function buildForAutoComplete(apiName,
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
} = _ref5;
|
|
87
|
+
function buildForAutoComplete(apiName, {
|
|
88
|
+
attributesToHighlight,
|
|
89
|
+
highlightPreTag,
|
|
90
|
+
highlightPostTag
|
|
91
|
+
}) {
|
|
96
92
|
if (apiName !== _commons.API.NAME.AUTOCOMPLETE) {
|
|
97
93
|
return {};
|
|
98
94
|
}
|
|
@@ -105,10 +101,9 @@ function buildForAutoComplete(apiName, _ref5) {
|
|
|
105
101
|
completion_fields: attributesToHighlight || undefined
|
|
106
102
|
};
|
|
107
103
|
}
|
|
108
|
-
function transformResponse(algoliaClient, apiName,
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
} = _ref6;
|
|
104
|
+
function transformResponse(algoliaClient, apiName, {
|
|
105
|
+
params = {}
|
|
106
|
+
}, response) {
|
|
112
107
|
const {
|
|
113
108
|
query,
|
|
114
109
|
page,
|
|
@@ -145,15 +140,13 @@ function transformHits(apiName, params, response) {
|
|
|
145
140
|
const MISO_MARK_PRE_TAG = '<mark>';
|
|
146
141
|
const MISO_MARK_POST_TAG = '</mark>';
|
|
147
142
|
const MISO_MARK_REGEXP = new RegExp(`${MISO_MARK_PRE_TAG}|${MISO_MARK_POST_TAG}`, 'g');
|
|
148
|
-
function transformCompletionsToHits(
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
completions
|
|
156
|
-
} = _ref8;
|
|
143
|
+
function transformCompletionsToHits({
|
|
144
|
+
query,
|
|
145
|
+
highlightPreTag = '<em>',
|
|
146
|
+
highlightPostTag = '</em>'
|
|
147
|
+
}, {
|
|
148
|
+
completions
|
|
149
|
+
}) {
|
|
157
150
|
const hits = [];
|
|
158
151
|
for (const _attribute in completions) {
|
|
159
152
|
for (const {
|
|
@@ -190,8 +183,7 @@ function transformResponseFacets(facet_counts) {
|
|
|
190
183
|
return (0, _commons.mapValues)(facet_fields, entriesToObj);
|
|
191
184
|
}
|
|
192
185
|
function entriesToObj(entries) {
|
|
193
|
-
return entries.reduce((acc,
|
|
194
|
-
let [key, value] = _ref9;
|
|
186
|
+
return entries.reduce((acc, [key, value]) => {
|
|
195
187
|
acc[key] = value;
|
|
196
188
|
return acc;
|
|
197
189
|
}, {});
|
package/dist/cjs/filter/index.js
CHANGED
|
@@ -37,50 +37,45 @@ const FACET_FILTER_REGEXP = new RegExp(`\\[(?<attr>${LITERAL_REGEXP.source}):(?<
|
|
|
37
37
|
// TODO: we can find AND|OR followed by NOT and then search for pairing ()
|
|
38
38
|
const BARE_NOT_REGEXP = new RegExp(`\\b(?<intro>AND|OR)\\s+NOT\\s+(?<expr>(?:${LITERAL_REGEXP.source}):(?:${LITERAL_REGEXP.source}))`, 'g');
|
|
39
39
|
const NOT_SOLR_FORMAT = '$<intro> (NOT $<expr>)';
|
|
40
|
-
function translateFilters(algoliaClient,
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
} = _ref;
|
|
40
|
+
function translateFilters(algoliaClient, {
|
|
41
|
+
filters
|
|
42
|
+
}) {
|
|
44
43
|
try {
|
|
45
44
|
return translateFiltersExpr(filters);
|
|
46
45
|
} catch (e) {
|
|
47
46
|
reportError(algoliaClient, 'filters', filters, e);
|
|
48
47
|
}
|
|
49
48
|
}
|
|
50
|
-
function translateNumericFilters(algoliaClient,
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
} = _ref2;
|
|
49
|
+
function translateNumericFilters(algoliaClient, {
|
|
50
|
+
numericFilters
|
|
51
|
+
}) {
|
|
54
52
|
try {
|
|
55
53
|
return translateConjunctiveFilters(numericFilters, translateNumericFilterExpr);
|
|
56
54
|
} catch (e) {
|
|
57
55
|
reportError(algoliaClient, 'numericFilters', numericFilters, e);
|
|
58
56
|
}
|
|
59
57
|
}
|
|
60
|
-
function translateTagFilters(algoliaClient,
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
} = _ref3;
|
|
58
|
+
function translateTagFilters(algoliaClient, {
|
|
59
|
+
tagFilters
|
|
60
|
+
}) {
|
|
64
61
|
try {
|
|
65
62
|
return translateConjunctiveFilters(tagFilters, translateTagFilterExpr);
|
|
66
63
|
} catch (e) {
|
|
67
64
|
reportError(algoliaClient, 'tagFilters', tagFilters, e);
|
|
68
65
|
}
|
|
69
66
|
}
|
|
70
|
-
function translateFacetFilters(algoliaClient,
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
} = _ref4;
|
|
67
|
+
function translateFacetFilters(algoliaClient, {
|
|
68
|
+
facetFilters
|
|
69
|
+
}) {
|
|
74
70
|
try {
|
|
75
71
|
return translateConjunctiveFilters(facetFilters, translateFacetFilterExpr);
|
|
76
72
|
} catch (e) {
|
|
77
73
|
reportError(algoliaClient, 'facetFilters', facetFilters, e);
|
|
78
74
|
}
|
|
79
75
|
}
|
|
80
|
-
function translateOptionalFilters(algoliaClient,
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
} = _ref5;
|
|
76
|
+
function translateOptionalFilters(algoliaClient, {
|
|
77
|
+
optionalFilters
|
|
78
|
+
}) {
|
|
84
79
|
try {
|
|
85
80
|
return translateConjunctiveFilters(optionalFilters);
|
|
86
81
|
} catch (e) {
|
|
@@ -99,22 +94,14 @@ function translateFiltersExpr(expr) {
|
|
|
99
94
|
// attr >= number -> attr:[number TO *]
|
|
100
95
|
// attr = number -> attr:number
|
|
101
96
|
// attr != number -> (NOT attr:number)
|
|
102
|
-
.replaceAll(NUMERIC_COMPARISON_REGEXP,
|
|
103
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
104
|
-
args[_key] = arguments[_key];
|
|
105
|
-
}
|
|
106
|
-
return buildNumericComparisonSolrExpr(group(args));
|
|
107
|
-
})
|
|
97
|
+
.replaceAll(NUMERIC_COMPARISON_REGEXP, (...args) => buildNumericComparisonSolrExpr(group(args)))
|
|
108
98
|
// attr:x TO y -> attr:[x TO y]
|
|
109
99
|
.replaceAll(NUMERIC_RANGE_REGEXP, NUMERIC_RANGE_SOLR_FORMAT)
|
|
110
100
|
// _tags:value -> tags:value
|
|
111
101
|
// value -> tags:value
|
|
112
102
|
.replaceAll(TAG_REGEXP, TAG_SOLR_FORMAT)
|
|
113
103
|
// [attr:value] -> attr:value
|
|
114
|
-
.replaceAll(FACET_FILTER_REGEXP,
|
|
115
|
-
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
116
|
-
args[_key2] = arguments[_key2];
|
|
117
|
-
}
|
|
104
|
+
.replaceAll(FACET_FILTER_REGEXP, (...args) => {
|
|
118
105
|
const {
|
|
119
106
|
attr,
|
|
120
107
|
value
|
|
@@ -127,8 +114,7 @@ function translateFiltersExpr(expr) {
|
|
|
127
114
|
function translateConjunctiveFilters(filters, translate) {
|
|
128
115
|
return filters && filters.length ? filters.map(f => translateDisjunctiveFilters(f, translate)).join(' AND ') : '';
|
|
129
116
|
}
|
|
130
|
-
function translateDisjunctiveFilters(filters) {
|
|
131
|
-
let translate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : v => v;
|
|
117
|
+
function translateDisjunctiveFilters(filters, translate = v => v) {
|
|
132
118
|
return !Array.isArray(filters) ? translate(filters) : !filters.length ? '' : filters.length === 1 ? translate(filters[0]) : `(${filters.map(translate).join(' OR ')})`;
|
|
133
119
|
}
|
|
134
120
|
function translateTagFilterExpr(expr) {
|
|
@@ -143,12 +129,7 @@ function translateNumericFilterExpr(expr) {
|
|
|
143
129
|
// attr >= number -> attr:[number TO *]
|
|
144
130
|
// attr = number -> attr:number
|
|
145
131
|
// attr != number -> (NOT attr:number)
|
|
146
|
-
.replaceAll(NUMERIC_COMPARISON_REGEXP,
|
|
147
|
-
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
148
|
-
args[_key3] = arguments[_key3];
|
|
149
|
-
}
|
|
150
|
-
return buildNumericComparisonSolrExpr(group(args));
|
|
151
|
-
})
|
|
132
|
+
.replaceAll(NUMERIC_COMPARISON_REGEXP, (...args) => buildNumericComparisonSolrExpr(group(args)))
|
|
152
133
|
// attr:x TO y -> attr:[x TO y]
|
|
153
134
|
.replaceAll(NUMERIC_RANGE_REGEXP, NUMERIC_RANGE_SOLR_FORMAT).unshadow();
|
|
154
135
|
}
|
|
@@ -160,12 +141,11 @@ function translateFacetFilterExpr(expr) {
|
|
|
160
141
|
return value.charCodeAt(0) === CHAR_MINUS ? `(NOT ${attr}:${quoteIfNecessary(value.substring(1))})` : value.startsWith('\\-') ? `${attr}:"${value.substring(1)}"` : `${attr}:${quoteIfNecessary(value)}`;
|
|
161
142
|
}).unshadow();
|
|
162
143
|
}
|
|
163
|
-
function buildNumericComparisonSolrExpr(
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
} = _ref6;
|
|
144
|
+
function buildNumericComparisonSolrExpr({
|
|
145
|
+
attr,
|
|
146
|
+
op,
|
|
147
|
+
value
|
|
148
|
+
}) {
|
|
169
149
|
switch (op) {
|
|
170
150
|
case '=':
|
|
171
151
|
return `${attr}:${value}`;
|
|
@@ -15,10 +15,7 @@ class ShadowString {
|
|
|
15
15
|
map(fn) {
|
|
16
16
|
return new ShadowString(undefined, fn(this._shadowed), this._contents);
|
|
17
17
|
}
|
|
18
|
-
apply(fn) {
|
|
19
|
-
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
20
|
-
args[_key - 1] = arguments[_key];
|
|
21
|
-
}
|
|
18
|
+
apply(fn, ...args) {
|
|
22
19
|
return new ShadowString(undefined, fn.apply(this._shadowed, args), this._contents);
|
|
23
20
|
}
|
|
24
21
|
unshadow() {
|
|
@@ -28,10 +25,7 @@ class ShadowString {
|
|
|
28
25
|
const SHORTCUTS = ['replace', 'replaceAll'];
|
|
29
26
|
const prototype = ShadowString.prototype;
|
|
30
27
|
for (const n of SHORTCUTS) {
|
|
31
|
-
prototype[n] = function () {
|
|
32
|
-
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
33
|
-
args[_key2] = arguments[_key2];
|
|
34
|
-
}
|
|
28
|
+
prototype[n] = function (...args) {
|
|
35
29
|
return this.apply(String.prototype[n], ...args);
|
|
36
30
|
};
|
|
37
31
|
}
|
package/dist/cjs/plugin.js
CHANGED
|
@@ -39,8 +39,7 @@ class Algolia {
|
|
|
39
39
|
autocompleteClient(options) {
|
|
40
40
|
return this._createClient(_commons.API.NAME.AUTOCOMPLETE, options);
|
|
41
41
|
}
|
|
42
|
-
_createClient(api) {
|
|
43
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
42
|
+
_createClient(api, options = {}) {
|
|
44
43
|
const client = new _client.default(this, Object.assign({}, options, {
|
|
45
44
|
api
|
|
46
45
|
}));
|
package/package.json
CHANGED