@infrab4a/connect 3.9.0-beta.7 → 3.9.0-beta.8

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.
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('reflect-metadata'), require('class-transformer'), require('date-fns'), require('lodash'), require('ts-custom-error'), require('axios'), require('firebase'), require('gql-query-builder')) :
3
- typeof define === 'function' && define.amd ? define('@infrab4a/connect', ['exports', 'reflect-metadata', 'class-transformer', 'date-fns', 'lodash', 'ts-custom-error', 'axios', 'firebase', 'gql-query-builder'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.infrab4a = global.infrab4a || {}, global.infrab4a.connect = {}), null, global["class-transformer"], global["date-fns"], global.lodash, global["ts-custom-error"], global.axios, global.firebase, global["gql-query-builder"]));
5
- })(this, (function (exports, reflectMetadata, classTransformer, dateFns, lodash, tsCustomError, axios, firebase, gqlQueryBuilder) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('reflect-metadata'), require('class-transformer'), require('date-fns'), require('lodash'), require('ts-custom-error'), require('axios'), require('@elastic/elasticsearch'), require('firebase'), require('gql-query-builder')) :
3
+ typeof define === 'function' && define.amd ? define('@infrab4a/connect', ['exports', 'reflect-metadata', 'class-transformer', 'date-fns', 'lodash', 'ts-custom-error', 'axios', '@elastic/elasticsearch', 'firebase', 'gql-query-builder'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.infrab4a = global.infrab4a || {}, global.infrab4a.connect = {}), null, global["class-transformer"], global["date-fns"], global.lodash, global["ts-custom-error"], global.axios, global["@elastic/elasticsearch"], global.firebase, global["gql-query-builder"]));
5
+ })(this, (function (exports, reflectMetadata, classTransformer, dateFns, lodash, tsCustomError, axios, elasticsearch, firebase, gqlQueryBuilder) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -1856,7 +1856,81 @@
1856
1856
  return AxiosAdapter;
1857
1857
  }());
1858
1858
 
1859
- // export * from './elastic-search.adapter'
1859
+ var ElasticAdapter = /** @class */ (function () {
1860
+ function ElasticAdapter(config) {
1861
+ this.config = config;
1862
+ this.client = new elasticsearch.Client(config);
1863
+ }
1864
+ ElasticAdapter.prototype.get = function (index, id) {
1865
+ return __awaiter(this, void 0, void 0, function () {
1866
+ var data, erro_1;
1867
+ return __generator(this, function (_a) {
1868
+ switch (_a.label) {
1869
+ case 0:
1870
+ _a.trys.push([0, 2, , 3]);
1871
+ return [4 /*yield*/, this.client.get({ index: index, id: id })];
1872
+ case 1:
1873
+ data = _a.sent();
1874
+ return [2 /*return*/, data._source];
1875
+ case 2:
1876
+ erro_1 = _a.sent();
1877
+ throw new NotFoundError(erro_1.message);
1878
+ case 3: return [2 /*return*/];
1879
+ }
1880
+ });
1881
+ });
1882
+ };
1883
+ ElasticAdapter.prototype.query = function (index, query) {
1884
+ return __awaiter(this, void 0, void 0, function () {
1885
+ var result;
1886
+ return __generator(this, function (_a) {
1887
+ switch (_a.label) {
1888
+ case 0: return [4 /*yield*/, this.client.search({
1889
+ index: index,
1890
+ query: query,
1891
+ })];
1892
+ case 1:
1893
+ result = _a.sent();
1894
+ return [2 /*return*/, {
1895
+ total: result.hits.total,
1896
+ hits: result.hits.hits,
1897
+ }];
1898
+ }
1899
+ });
1900
+ });
1901
+ };
1902
+ ElasticAdapter.prototype.save = function (index, data) {
1903
+ return this.client.index({
1904
+ index: index,
1905
+ document: data,
1906
+ });
1907
+ };
1908
+ ElasticAdapter.prototype.update = function (index, id, data) {
1909
+ try {
1910
+ return this.client.update({
1911
+ index: index,
1912
+ id: id,
1913
+ doc: data,
1914
+ });
1915
+ }
1916
+ catch (error) {
1917
+ console.log(error);
1918
+ throw new Error(error.message);
1919
+ }
1920
+ };
1921
+ ElasticAdapter.prototype.delete = function (index, id) {
1922
+ try {
1923
+ this.client.delete({
1924
+ index: index,
1925
+ id: id,
1926
+ });
1927
+ }
1928
+ catch (error) {
1929
+ console.log(error);
1930
+ }
1931
+ };
1932
+ return ElasticAdapter;
1933
+ }());
1860
1934
 
1861
1935
  var ProductsIndex = /** @class */ (function () {
1862
1936
  function ProductsIndex(adapter) {
@@ -1936,7 +2010,18 @@
1936
2010
  must: {
1937
2011
  multi_match: {
1938
2012
  query: "" + searchTerm,
1939
- fields: ['name', 'name.folded', 'name.search', 'description', 'brand'],
2013
+ type: 'bool_prefix',
2014
+ fields: [
2015
+ 'name',
2016
+ 'name.folded',
2017
+ 'name.search',
2018
+ 'description',
2019
+ 'description.search',
2020
+ 'description.folded',
2021
+ 'brand',
2022
+ 'brand.search',
2023
+ 'brand.folded',
2024
+ ],
1940
2025
  fuzziness: 2,
1941
2026
  },
1942
2027
  },
@@ -5600,6 +5685,7 @@
5600
5685
  exports.CouponFirestoreRepository = CouponFirestoreRepository;
5601
5686
  exports.DuplicatedResultsError = DuplicatedResultsError;
5602
5687
  exports.Edition = Edition;
5688
+ exports.ElasticAdapter = ElasticAdapter;
5603
5689
  exports.Filter = Filter;
5604
5690
  exports.FilterHasuraGraphQLRepository = FilterHasuraGraphQLRepository;
5605
5691
  exports.FilterOption = FilterOption;