@empathyco/x-adapter-platform 1.0.0-alpha.16 → 1.0.0-alpha.17

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.
Files changed (42) hide show
  1. package/dist/cjs/mappers/responses/search-response.mapper.js +51 -2
  2. package/dist/cjs/mappers/responses/search-response.mapper.js.map +1 -1
  3. package/dist/cjs/schemas/facets/index.js +6 -0
  4. package/dist/cjs/schemas/facets/index.js.map +1 -0
  5. package/dist/cjs/schemas/facets/types.js +3 -0
  6. package/dist/cjs/schemas/facets/types.js.map +1 -0
  7. package/dist/cjs/schemas/facets/utils.js +16 -0
  8. package/dist/cjs/schemas/facets/utils.js.map +1 -0
  9. package/dist/cjs/schemas/filters/number-filter.schema.js +1 -1
  10. package/dist/cjs/schemas/filters/number-filter.schema.js.map +1 -1
  11. package/dist/cjs/schemas/filters/simple-filter.schema.js +1 -1
  12. package/dist/cjs/schemas/filters/simple-filter.schema.js.map +1 -1
  13. package/dist/cjs/schemas/index.js +1 -0
  14. package/dist/cjs/schemas/index.js.map +1 -1
  15. package/dist/cjs/schemas/models/facet.schema.js +27 -41
  16. package/dist/cjs/schemas/models/facet.schema.js.map +1 -1
  17. package/dist/cjs/types/models/facet.model.js.map +1 -1
  18. package/dist/esm/mappers/responses/search-response.mapper.js +50 -2
  19. package/dist/esm/mappers/responses/search-response.mapper.js.map +1 -1
  20. package/dist/esm/schemas/facets/index.js +3 -0
  21. package/dist/esm/schemas/facets/index.js.map +1 -0
  22. package/dist/esm/schemas/facets/types.js +2 -0
  23. package/dist/esm/schemas/facets/types.js.map +1 -0
  24. package/dist/esm/schemas/facets/utils.js +12 -0
  25. package/dist/esm/schemas/facets/utils.js.map +1 -0
  26. package/dist/esm/schemas/filters/number-filter.schema.js +1 -1
  27. package/dist/esm/schemas/filters/number-filter.schema.js.map +1 -1
  28. package/dist/esm/schemas/filters/simple-filter.schema.js +1 -1
  29. package/dist/esm/schemas/filters/simple-filter.schema.js.map +1 -1
  30. package/dist/esm/schemas/index.js +1 -0
  31. package/dist/esm/schemas/index.js.map +1 -1
  32. package/dist/esm/schemas/models/facet.schema.js +26 -40
  33. package/dist/esm/schemas/models/facet.schema.js.map +1 -1
  34. package/dist/esm/types/models/facet.model.js.map +1 -1
  35. package/dist/types/mappers/responses/search-response.mapper.d.ts +20 -1
  36. package/dist/types/schemas/facets/index.d.ts +2 -0
  37. package/dist/types/schemas/facets/types.d.ts +15 -0
  38. package/dist/types/schemas/facets/utils.d.ts +8 -0
  39. package/dist/types/schemas/index.d.ts +1 -0
  40. package/dist/types/schemas/models/facet.schema.d.ts +2 -0
  41. package/dist/types/types/models/facet.model.d.ts +25 -0
  42. package/package.json +2 -2
@@ -1,7 +1,56 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.searchResponseMapper = void 0;
3
+ exports.searchResponseFacetsMapper = exports.searchResponseMapper = void 0;
4
4
  const x_adapter_next_1 = require("@empathyco/x-adapter-next");
5
5
  const search_response_schema_1 = require("../../schemas/responses/search-response.schema");
6
- exports.searchResponseMapper = (0, x_adapter_next_1.schemaMapperFactory)(search_response_schema_1.searchResponseMutableSchema);
6
+ exports.searchResponseMapper = (0, x_adapter_next_1.combineMappers)((0, x_adapter_next_1.schemaMapperFactory)(search_response_schema_1.searchResponseMutableSchema), searchResponseFacetsMapper);
7
+ /**
8
+ * Mapper to flatten hierarchical facet filters.
9
+ *
10
+ * @param from - The Platform search response.
11
+ * @param context - The context from the mapper.
12
+ * @returns The mapped facets.
13
+ */
14
+ function searchResponseFacetsMapper(from, { mappedValue }) {
15
+ var _a;
16
+ const facets = (_a = mappedValue.facets) === null || _a === void 0 ? void 0 : _a.map(facet => facet.modelName === 'HierarchicalFacet'
17
+ ? flattenHierarchicalFacet(facet)
18
+ : facet);
19
+ return { facets };
20
+ }
21
+ exports.searchResponseFacetsMapper = searchResponseFacetsMapper;
22
+ /**
23
+ * Returns a hierarchical facet with its filters flattened.
24
+ *
25
+ * @param facet - The hierarchical facet.
26
+ * @returns The flattened hierarchical facet.
27
+ */
28
+ function flattenHierarchicalFacet(facet) {
29
+ const filters = facet.filters.reduce((flattenedFilters, filter) => {
30
+ return mapHierarchicalFilter(filter, flattenedFilters);
31
+ }, []);
32
+ return {
33
+ ...facet,
34
+ filters
35
+ };
36
+ }
37
+ /**
38
+ * Map recursively the hierarchical facet filters.
39
+ *
40
+ * @param rawFilter - The hierarchical filter to map.
41
+ * @param filters - The filters array to fill with the facet filters.
42
+ * @returns The filter id.
43
+ */
44
+ function mapHierarchicalFilter(rawFilter, filters) {
45
+ var _a;
46
+ const filter = {
47
+ ...rawFilter,
48
+ children: (_a = rawFilter.children) === null || _a === void 0 ? void 0 : _a.map(rawFilterChild => {
49
+ mapHierarchicalFilter(rawFilterChild, filters);
50
+ return rawFilterChild.id;
51
+ })
52
+ };
53
+ filters.push(filter);
54
+ return filters;
55
+ }
7
56
  //# sourceMappingURL=search-response.mapper.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"search-response.mapper.js","sourceRoot":"","sources":["../../../../src/mappers/responses/search-response.mapper.ts"],"names":[],"mappings":";;;AAAA,8DAAgE;AAGhE,2FAA6F;AAEhF,QAAA,oBAAoB,GAAG,IAAA,oCAAmB,EACrD,oDAA2B,CAC5B,CAAC","sourcesContent":["import { schemaMapperFactory } from '@empathyco/x-adapter-next';\nimport { SearchResponse } from '@empathyco/x-types';\nimport { PlatformSearchResponse } from '../../types/responses/search-response.model';\nimport { searchResponseMutableSchema } from '../../schemas/responses/search-response.schema';\n\nexport const searchResponseMapper = schemaMapperFactory<PlatformSearchResponse, SearchResponse>(\n searchResponseMutableSchema\n);\n"]}
1
+ {"version":3,"file":"search-response.mapper.js","sourceRoot":"","sources":["../../../../src/mappers/responses/search-response.mapper.ts"],"names":[],"mappings":";;;AAAA,8DAA+F;AAG/F,2FAA6F;AAMhF,QAAA,oBAAoB,GAAG,IAAA,+BAAc,EAChD,IAAA,oCAAmB,EAAyC,oDAA2B,CAAC,EACxF,0BAA0B,CAC3B,CAAC;AAEF;;;;;;GAMG;AACH,SAAgB,0BAA0B,CACxC,IAA4B,EAC5B,EAAE,WAAW,EAAiB;;IAE9B,MAAM,MAAM,GAAG,MAAC,WAA8B,CAAC,MAAM,0CAAE,GAAG,CAAC,KAAK,CAAC,EAAE,CACjE,KAAK,CAAC,SAAS,KAAK,mBAAmB;QACrC,CAAC,CAAC,wBAAwB,CAAC,KAAiC,CAAC;QAC7D,CAAC,CAAC,KAAK,CACV,CAAC;IACF,OAAO,EAAE,MAAM,EAAE,CAAC;AACpB,CAAC;AAVD,gEAUC;AAED;;;;;GAKG;AACH,SAAS,wBAAwB,CAAC,KAA+B;IAC/D,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,gBAAgB,EAAE,MAAM,EAAE,EAAE;QAChE,OAAO,qBAAqB,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IACzD,CAAC,EAAE,EAA0B,CAAC,CAAC;IAE/B,OAAO;QACL,GAAG,KAAK;QACR,OAAO;KACR,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,SAAS,qBAAqB,CAC5B,SAAoC,EACpC,OAA6B;;IAE7B,MAAM,MAAM,GAAuB;QACjC,GAAG,SAAS;QACZ,QAAQ,EAAE,MAAA,SAAS,CAAC,QAAQ,0CAAE,GAAG,CAAC,cAAc,CAAC,EAAE;YACjD,qBAAqB,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;YAC/C,OAAO,cAAc,CAAC,EAAE,CAAC;QAC3B,CAAC,CAAC;KACH,CAAC;IACF,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACrB,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import { schemaMapperFactory, combineMappers, MapperContext } from '@empathyco/x-adapter-next';\nimport { SearchResponse, HierarchicalFacet, HierarchicalFilter } from '@empathyco/x-types';\nimport { PlatformSearchResponse } from '../../types/responses/search-response.model';\nimport { searchResponseMutableSchema } from '../../schemas/responses/search-response.schema';\nimport {\n AdapterHierarchicalFacet,\n AdapterHierarchicalFilter\n} from '../../types/models/facet.model';\n\nexport const searchResponseMapper = combineMappers(\n schemaMapperFactory<PlatformSearchResponse, SearchResponse>(searchResponseMutableSchema),\n searchResponseFacetsMapper\n);\n\n/**\n * Mapper to flatten hierarchical facet filters.\n *\n * @param from - The Platform search response.\n * @param context - The context from the mapper.\n * @returns The mapped facets.\n */\nexport function searchResponseFacetsMapper(\n from: PlatformSearchResponse,\n { mappedValue }: MapperContext\n): Partial<SearchResponse> {\n const facets = (mappedValue as SearchResponse).facets?.map(facet =>\n facet.modelName === 'HierarchicalFacet'\n ? flattenHierarchicalFacet(facet as AdapterHierarchicalFacet)\n : facet\n );\n return { facets };\n}\n\n/**\n * Returns a hierarchical facet with its filters flattened.\n *\n * @param facet - The hierarchical facet.\n * @returns The flattened hierarchical facet.\n */\nfunction flattenHierarchicalFacet(facet: AdapterHierarchicalFacet): HierarchicalFacet {\n const filters = facet.filters.reduce((flattenedFilters, filter) => {\n return mapHierarchicalFilter(filter, flattenedFilters);\n }, [] as HierarchicalFilter[]);\n\n return {\n ...facet,\n filters\n };\n}\n\n/**\n * Map recursively the hierarchical facet filters.\n *\n * @param rawFilter - The hierarchical filter to map.\n * @param filters - The filters array to fill with the facet filters.\n * @returns The filter id.\n */\nfunction mapHierarchicalFilter(\n rawFilter: AdapterHierarchicalFilter,\n filters: HierarchicalFilter[]\n): HierarchicalFilter[] {\n const filter: HierarchicalFilter = {\n ...rawFilter,\n children: rawFilter.children?.map(rawFilterChild => {\n mapHierarchicalFilter(rawFilterChild, filters);\n return rawFilterChild.id;\n })\n };\n filters.push(filter);\n return filters;\n}\n"]}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./types"), exports);
5
+ tslib_1.__exportStar(require("./utils"), exports);
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/schemas/facets/index.ts"],"names":[],"mappings":";;;AAAA,kDAAwB;AACxB,kDAAwB","sourcesContent":["export * from './types';\nexport * from './utils';\n"]}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/schemas/facets/types.ts"],"names":[],"mappings":"","sourcesContent":["import { FacetModelName, Facet } from '@empathyco/x-types';\nimport { Schema } from '@empathyco/x-adapter-next';\n\n/**\n * Facet configuration containing the model name and the schema.\n */\nexport interface FacetConfig {\n modelName: FacetModelName;\n schema: Schema;\n}\n\n/**\n * Dictionary grouping facets configurations.\n */\nexport interface FacetsConfig {\n [key: Facet['id']]: FacetConfig;\n}\n"]}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getFacetConfig = void 0;
4
+ const facet_schema_1 = require("../models/facet.schema");
5
+ /**
6
+ * Returns the facet's config.
7
+ *
8
+ * @param facet - The facet to resolve the configuration.
9
+ * @returns The facet's config.
10
+ */
11
+ function getFacetConfig(facet) {
12
+ var _a;
13
+ return (_a = facet_schema_1.facetsConfig[facet]) !== null && _a !== void 0 ? _a : facet_schema_1.facetsConfig.default;
14
+ }
15
+ exports.getFacetConfig = getFacetConfig;
16
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/schemas/facets/utils.ts"],"names":[],"mappings":";;;AAAA,yDAAsD;AAGtD;;;;;GAKG;AACH,SAAgB,cAAc,CAAC,KAAa;;IAC1C,OAAO,MAAA,2BAAY,CAAC,KAAK,CAAC,mCAAI,2BAAY,CAAC,OAAO,CAAC;AACrD,CAAC;AAFD,wCAEC","sourcesContent":["import { facetsConfig } from '../models/facet.schema';\nimport { FacetConfig } from './types';\n\n/**\n * Returns the facet's config.\n *\n * @param facet - The facet to resolve the configuration.\n * @returns The facet's config.\n */\nexport function getFacetConfig(facet: string): FacetConfig {\n return facetsConfig[facet] ?? facetsConfig.default;\n}\n"]}
@@ -4,7 +4,7 @@ exports.numberFilterMutableSchema = void 0;
4
4
  const x_adapter_next_1 = require("@empathyco/x-adapter-next");
5
5
  exports.numberFilterMutableSchema = (0, x_adapter_next_1.createMutableSchema)({
6
6
  id: 'filter',
7
- facetId: 'id',
7
+ facetId: (_, $context) => $context === null || $context === void 0 ? void 0 : $context.facetId,
8
8
  label: 'value',
9
9
  totalResults: 'count',
10
10
  selected: () => false,
@@ -1 +1 @@
1
- {"version":3,"file":"number-filter.schema.js","sourceRoot":"","sources":["../../../../src/schemas/filters/number-filter.schema.ts"],"names":[],"mappings":";;;AAAA,8DAAwE;AAI3D,QAAA,yBAAyB,GAAG,IAAA,oCAAmB,EAE1D;IACA,EAAE,EAAE,QAAQ;IACZ,OAAO,EAAE,IAAI;IACb,KAAK,EAAE,OAAO;IACd,YAAY,EAAE,OAAO;IACrB,QAAQ,EAAE,GAAG,EAAE,CAAC,KAAK;IACrB,SAAS,EAAE,GAAG,EAAE,CAAC,mBAAmB;IACpC,KAAK,EAAE;QACL,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAC/C,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;KAChD;CACF,CAAC,CAAC","sourcesContent":["import { createMutableSchema, Schema } from '@empathyco/x-adapter-next';\nimport { NumberRangeFilter } from '@empathyco/x-types';\nimport { PlatformFilter } from '../../types/models/facet.model';\n\nexport const numberFilterMutableSchema = createMutableSchema<\n Schema<PlatformFilter, NumberRangeFilter>\n>({\n id: 'filter',\n facetId: 'id',\n label: 'value',\n totalResults: 'count',\n selected: () => false,\n modelName: () => 'NumberRangeFilter',\n range: {\n min: ({ value }) => Number(value.split('-')[0]),\n max: ({ value }) => Number(value.split('-')[1])\n }\n});\n"]}
1
+ {"version":3,"file":"number-filter.schema.js","sourceRoot":"","sources":["../../../../src/schemas/filters/number-filter.schema.ts"],"names":[],"mappings":";;;AAAA,8DAAwE;AAI3D,QAAA,yBAAyB,GAAG,IAAA,oCAAmB,EAE1D;IACA,EAAE,EAAE,QAAQ;IACZ,OAAO,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,CAAC,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,OAAiB;IACrD,KAAK,EAAE,OAAO;IACd,YAAY,EAAE,OAAO;IACrB,QAAQ,EAAE,GAAG,EAAE,CAAC,KAAK;IACrB,SAAS,EAAE,GAAG,EAAE,CAAC,mBAAmB;IACpC,KAAK,EAAE;QACL,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAC/C,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;KAChD;CACF,CAAC,CAAC","sourcesContent":["import { createMutableSchema, Schema } from '@empathyco/x-adapter-next';\nimport { NumberRangeFilter } from '@empathyco/x-types';\nimport { PlatformFilter } from '../../types/models/facet.model';\n\nexport const numberFilterMutableSchema = createMutableSchema<\n Schema<PlatformFilter, NumberRangeFilter>\n>({\n id: 'filter',\n facetId: (_, $context) => $context?.facetId as string,\n label: 'value',\n totalResults: 'count',\n selected: () => false,\n modelName: () => 'NumberRangeFilter',\n range: {\n min: ({ value }) => Number(value.split('-')[0]),\n max: ({ value }) => Number(value.split('-')[1])\n }\n});\n"]}
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.simpleFilterMutableSchema = void 0;
4
4
  const x_adapter_next_1 = require("@empathyco/x-adapter-next");
5
5
  exports.simpleFilterMutableSchema = (0, x_adapter_next_1.createMutableSchema)({
6
- facetId: 'filter',
6
+ facetId: (_, $context) => $context === null || $context === void 0 ? void 0 : $context.facetId,
7
7
  label: 'value',
8
8
  id: 'filter',
9
9
  totalResults: 'count',
@@ -1 +1 @@
1
- {"version":3,"file":"simple-filter.schema.js","sourceRoot":"","sources":["../../../../src/schemas/filters/simple-filter.schema.ts"],"names":[],"mappings":";;;AAAA,8DAAwE;AAI3D,QAAA,yBAAyB,GAAG,IAAA,oCAAmB,EAAuC;IACjG,OAAO,EAAE,QAAQ;IACjB,KAAK,EAAE,OAAO;IACd,EAAE,EAAE,QAAQ;IACZ,YAAY,EAAE,OAAO;IACrB,QAAQ,EAAE,GAAG,EAAE,CAAC,KAAK;IACrB,SAAS,EAAE,GAAG,EAAE,CAAC,cAAc;CAChC,CAAC,CAAC","sourcesContent":["import { createMutableSchema, Schema } from '@empathyco/x-adapter-next';\nimport { SimpleFilter } from '@empathyco/x-types';\nimport { PlatformFilter } from '../../types/models/facet.model';\n\nexport const simpleFilterMutableSchema = createMutableSchema<Schema<PlatformFilter, SimpleFilter>>({\n facetId: 'filter',\n label: 'value',\n id: 'filter',\n totalResults: 'count',\n selected: () => false,\n modelName: () => 'SimpleFilter'\n});\n"]}
1
+ {"version":3,"file":"simple-filter.schema.js","sourceRoot":"","sources":["../../../../src/schemas/filters/simple-filter.schema.ts"],"names":[],"mappings":";;;AAAA,8DAAwE;AAI3D,QAAA,yBAAyB,GAAG,IAAA,oCAAmB,EAAuC;IACjG,OAAO,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,CAAC,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,OAAiB;IACrD,KAAK,EAAE,OAAO;IACd,EAAE,EAAE,QAAQ;IACZ,YAAY,EAAE,OAAO;IACrB,QAAQ,EAAE,GAAG,EAAE,CAAC,KAAK;IACrB,SAAS,EAAE,GAAG,EAAE,CAAC,cAAc;CAChC,CAAC,CAAC","sourcesContent":["import { createMutableSchema, Schema } from '@empathyco/x-adapter-next';\nimport { SimpleFilter } from '@empathyco/x-types';\nimport { PlatformFilter } from '../../types/models/facet.model';\n\nexport const simpleFilterMutableSchema = createMutableSchema<Schema<PlatformFilter, SimpleFilter>>({\n facetId: (_, $context) => $context?.facetId as string,\n label: 'value',\n id: 'filter',\n totalResults: 'count',\n selected: () => false,\n modelName: () => 'SimpleFilter'\n});\n"]}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./facets"), exports);
4
5
  tslib_1.__exportStar(require("./filters"), exports);
5
6
  tslib_1.__exportStar(require("./models"), exports);
6
7
  tslib_1.__exportStar(require("./requests"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/schemas/index.ts"],"names":[],"mappings":";;;AAAA,oDAA0B;AAC1B,mDAAyB;AACzB,qDAA2B;AAC3B,sDAA4B","sourcesContent":["export * from './filters';\nexport * from './models';\nexport * from './requests';\nexport * from './responses';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/schemas/index.ts"],"names":[],"mappings":";;;AAAA,mDAAyB;AACzB,oDAA0B;AAC1B,mDAAyB;AACzB,qDAA2B;AAC3B,sDAA4B","sourcesContent":["export * from './facets';\nexport * from './filters';\nexport * from './models';\nexport * from './requests';\nexport * from './responses';\n"]}
@@ -1,66 +1,52 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hierarchicalFilterMutableSchema = exports.facetMutableSchema = void 0;
3
+ exports.facetsConfig = exports.hierarchicalFilterMutableSchema = exports.facetMutableSchema = void 0;
4
4
  const x_adapter_next_1 = require("@empathyco/x-adapter-next");
5
5
  const number_filter_schema_1 = require("../filters/number-filter.schema");
6
6
  const simple_filter_schema_1 = require("../filters/simple-filter.schema");
7
+ const utils_1 = require("../facets/utils");
7
8
  exports.facetMutableSchema = (0, x_adapter_next_1.createMutableSchema)({
8
9
  id: 'facet',
9
10
  label: 'facet',
10
- modelName: ({ facet }) => getFacetType(facet),
11
+ modelName: source => {
12
+ return (0, utils_1.getFacetConfig)(source.facet).modelName;
13
+ },
11
14
  filters: {
12
15
  $path: 'values',
13
- $subSchema: ({ facet }) => getFilterSchemaFromFacetType(facet),
16
+ $subSchema: ({ facet }) => (0, utils_1.getFacetConfig)(facet).schema,
14
17
  $context: {
15
- parentId: 'facet'
18
+ facetId: 'facet'
16
19
  }
17
20
  }
18
21
  });
19
22
  exports.hierarchicalFilterMutableSchema = (0, x_adapter_next_1.createMutableSchema)({
20
- facetId: 'filter',
23
+ facetId: (_, $context) => $context === null || $context === void 0 ? void 0 : $context.facetId,
21
24
  label: 'value',
22
25
  id: 'filter',
23
26
  totalResults: 'count',
24
- parentId: (_, $context) => $context === null || $context === void 0 ? void 0 : $context.parentId,
27
+ parentId: (_, $context) => { var _a; return (_a = $context === null || $context === void 0 ? void 0 : $context.parentId) !== null && _a !== void 0 ? _a : null; },
25
28
  selected: () => false,
26
29
  modelName: () => 'HierarchicalFilter',
27
30
  children: {
28
- $path: 'children',
29
- $subSchema: exports.facetMutableSchema
31
+ $path: 'children.values',
32
+ $subSchema: '$self',
33
+ $context: {
34
+ parentId: 'filter'
35
+ }
30
36
  }
31
37
  });
32
- /**
33
- * Resolves the proper facet model name.
34
- *
35
- * @param facet - The facet to resolve the model name.
36
- * @returns The facet's model name.
37
- */
38
- function getFacetType(facet) {
39
- const name = facet.split('_')[0];
40
- const hierarchicalFacet = ['categoryPaths'];
41
- const numberRangeFacet = ['price'];
42
- if (hierarchicalFacet.includes(name)) {
43
- return 'HierarchicalFacet';
44
- }
45
- if (numberRangeFacet.includes(name)) {
46
- return 'NumberRangeFacet';
47
- }
48
- return 'SimpleFacet';
49
- }
50
- /**
51
- * Returns the proper schema to apply to the given facet.
52
- *
53
- * @param facet - The facet to resolve the schema to apply.
54
- * @returns The schema to apply.
55
- */
56
- function getFilterSchemaFromFacetType(facet) {
57
- const facetType = getFacetType(facet);
58
- if (facetType === 'HierarchicalFacet') {
59
- return exports.hierarchicalFilterMutableSchema;
60
- }
61
- if (facetType === 'NumberRangeFacet') {
62
- return number_filter_schema_1.numberFilterMutableSchema;
38
+ exports.facetsConfig = {
39
+ categoryPaths: {
40
+ modelName: 'HierarchicalFacet',
41
+ schema: exports.hierarchicalFilterMutableSchema
42
+ },
43
+ price: {
44
+ modelName: 'NumberRangeFacet',
45
+ schema: number_filter_schema_1.numberFilterMutableSchema
46
+ },
47
+ default: {
48
+ modelName: 'SimpleFacet',
49
+ schema: simple_filter_schema_1.simpleFilterMutableSchema
63
50
  }
64
- return simple_filter_schema_1.simpleFilterMutableSchema;
65
- }
51
+ };
66
52
  //# sourceMappingURL=facet.schema.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"facet.schema.js","sourceRoot":"","sources":["../../../../src/schemas/models/facet.schema.ts"],"names":[],"mappings":";;;AAAA,8DAAwE;AASxE,0EAA4E;AAC5E,0EAA4E;AAG/D,QAAA,kBAAkB,GAAG,IAAA,oCAAmB,EAKnD;IACA,EAAE,EAAE,OAAO;IACX,KAAK,EAAE,OAAO;IACd,SAAS,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,YAAY,CAAC,KAAK,CAAQ;IACpD,OAAO,EAAE;QACP,KAAK,EAAE,QAAQ;QACf,UAAU,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,4BAA4B,CAAC,KAAK,CAAC;QAC9D,QAAQ,EAAE;YACR,QAAQ,EAAE,OAAO;SAClB;KACF;CACF,CAAC,CAAC;AAEU,QAAA,+BAA+B,GAAG,IAAA,oCAAmB,EAEhE;IACA,OAAO,EAAE,QAAQ;IACjB,KAAK,EAAE,OAAO;IACd,EAAE,EAAE,QAAQ;IACZ,YAAY,EAAE,OAAO;IACrB,QAAQ,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,CAAC,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,QAAkB;IACvD,QAAQ,EAAE,GAAG,EAAE,CAAC,KAAK;IACrB,SAAS,EAAE,GAAG,EAAE,CAAC,oBAAoB;IACrC,QAAQ,EAAE;QACR,KAAK,EAAE,UAAU;QACjB,UAAU,EAAE,0BAAyB;KACtC;CACF,CAAC,CAAC;AAEH;;;;;GAKG;AACH,SAAS,YAAY,CAAC,KAAa;IACjC,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACjC,MAAM,iBAAiB,GAAG,CAAC,eAAe,CAAC,CAAC;IAC5C,MAAM,gBAAgB,GAAG,CAAC,OAAO,CAAC,CAAC;IACnC,IAAI,iBAAiB,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;QACpC,OAAO,mBAAmB,CAAC;KAC5B;IACD,IAAI,gBAAgB,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;QACnC,OAAO,kBAAkB,CAAC;KAC3B;IACD,OAAO,aAAa,CAAC;AACvB,CAAC;AAED;;;;;GAKG;AACH,SAAS,4BAA4B,CAAC,KAAa;IACjD,MAAM,SAAS,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;IACtC,IAAI,SAAS,KAAK,mBAAmB,EAAE;QACrC,OAAO,uCAA+B,CAAC;KACxC;IACD,IAAI,SAAS,KAAK,kBAAkB,EAAE;QACpC,OAAO,gDAAyB,CAAC;KAClC;IACD,OAAO,gDAAyB,CAAC;AACnC,CAAC","sourcesContent":["import { createMutableSchema, Schema } from '@empathyco/x-adapter-next';\nimport {\n EditableNumberRangeFacet,\n FacetModelName,\n HierarchicalFacet,\n HierarchicalFilter,\n NumberRangeFacet,\n SimpleFacet\n} from '@empathyco/x-types';\nimport { numberFilterMutableSchema } from '../filters/number-filter.schema';\nimport { simpleFilterMutableSchema } from '../filters/simple-filter.schema';\nimport { PlatformFacet, PlatformHierarchicalFilter } from '../../types/models/facet.model';\n\nexport const facetMutableSchema = createMutableSchema<\n Schema<\n PlatformFacet,\n HierarchicalFacet | NumberRangeFacet | SimpleFacet | EditableNumberRangeFacet\n >\n>({\n id: 'facet',\n label: 'facet',\n modelName: ({ facet }) => getFacetType(facet) as any,\n filters: {\n $path: 'values',\n $subSchema: ({ facet }) => getFilterSchemaFromFacetType(facet),\n $context: {\n parentId: 'facet'\n }\n }\n});\n\nexport const hierarchicalFilterMutableSchema = createMutableSchema<\n Schema<PlatformHierarchicalFilter, HierarchicalFilter>\n>({\n facetId: 'filter',\n label: 'value',\n id: 'filter',\n totalResults: 'count',\n parentId: (_, $context) => $context?.parentId as string,\n selected: () => false,\n modelName: () => 'HierarchicalFilter',\n children: {\n $path: 'children',\n $subSchema: facetMutableSchema as any\n }\n});\n\n/**\n * Resolves the proper facet model name.\n *\n * @param facet - The facet to resolve the model name.\n * @returns The facet's model name.\n */\nfunction getFacetType(facet: string): FacetModelName {\n const name = facet.split('_')[0];\n const hierarchicalFacet = ['categoryPaths'];\n const numberRangeFacet = ['price'];\n if (hierarchicalFacet.includes(name)) {\n return 'HierarchicalFacet';\n }\n if (numberRangeFacet.includes(name)) {\n return 'NumberRangeFacet';\n }\n return 'SimpleFacet';\n}\n\n/**\n * Returns the proper schema to apply to the given facet.\n *\n * @param facet - The facet to resolve the schema to apply.\n * @returns The schema to apply.\n */\nfunction getFilterSchemaFromFacetType(facet: string): Schema {\n const facetType = getFacetType(facet);\n if (facetType === 'HierarchicalFacet') {\n return hierarchicalFilterMutableSchema;\n }\n if (facetType === 'NumberRangeFacet') {\n return numberFilterMutableSchema;\n }\n return simpleFilterMutableSchema;\n}\n"]}
1
+ {"version":3,"file":"facet.schema.js","sourceRoot":"","sources":["../../../../src/schemas/models/facet.schema.ts"],"names":[],"mappings":";;;AAAA,8DAAwE;AAQxE,0EAA4E;AAC5E,0EAA4E;AAE5E,2CAAiD;AAGpC,QAAA,kBAAkB,GAAG,IAAA,oCAAmB,EAKnD;IACA,EAAE,EAAE,OAAO;IACX,KAAK,EAAE,OAAO;IACd,SAAS,EAAE,MAAM,CAAC,EAAE;QAClB,OAAO,IAAA,sBAAc,EAAC,MAAM,CAAC,KAAK,CAAC,CAAC,SAAgB,CAAC;IACvD,CAAC;IACD,OAAO,EAAE;QACP,KAAK,EAAE,QAAQ;QACf,UAAU,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,IAAA,sBAAc,EAAC,KAAK,CAAC,CAAC,MAAa;QAC9D,QAAQ,EAAE;YACR,OAAO,EAAE,OAAO;SACjB;KACF;CACF,CAAC,CAAC;AAEU,QAAA,+BAA+B,GAAG,IAAA,oCAAmB,EAEhE;IACA,OAAO,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,CAAC,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,OAAiB;IACrD,KAAK,EAAE,OAAO;IACd,EAAE,EAAE,QAAQ;IACZ,YAAY,EAAE,OAAO;IACrB,QAAQ,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,WAAC,OAAA,MAAC,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,QAAmB,mCAAI,IAAI,CAAA,EAAA;IACjE,QAAQ,EAAE,GAAG,EAAE,CAAC,KAAK;IACrB,SAAS,EAAE,GAAG,EAAE,CAAC,oBAAoB;IACrC,QAAQ,EAAE;QACR,KAAK,EAAE,iBAAiB;QACxB,UAAU,EAAE,OAAO;QACnB,QAAQ,EAAE;YACR,QAAQ,EAAE,QAAQ;SACnB;KACF;CACF,CAAC,CAAC;AAEU,QAAA,YAAY,GAAiB;IACxC,aAAa,EAAE;QACb,SAAS,EAAE,mBAAmB;QAC9B,MAAM,EAAE,uCAA+B;KACxC;IACD,KAAK,EAAE;QACL,SAAS,EAAE,kBAAkB;QAC7B,MAAM,EAAE,gDAAyB;KAClC;IACD,OAAO,EAAE;QACP,SAAS,EAAE,aAAa;QACxB,MAAM,EAAE,gDAAyB;KAClC;CACF,CAAC","sourcesContent":["import { createMutableSchema, Schema } from '@empathyco/x-adapter-next';\nimport {\n EditableNumberRangeFacet,\n HierarchicalFacet,\n HierarchicalFilter,\n NumberRangeFacet,\n SimpleFacet\n} from '@empathyco/x-types';\nimport { numberFilterMutableSchema } from '../filters/number-filter.schema';\nimport { simpleFilterMutableSchema } from '../filters/simple-filter.schema';\nimport { PlatformFacet, PlatformHierarchicalFilter } from '../../types/models/facet.model';\nimport { getFacetConfig } from '../facets/utils';\nimport { FacetsConfig } from '../facets/types';\n\nexport const facetMutableSchema = createMutableSchema<\n Schema<\n PlatformFacet,\n HierarchicalFacet | NumberRangeFacet | SimpleFacet | EditableNumberRangeFacet\n >\n>({\n id: 'facet',\n label: 'facet',\n modelName: source => {\n return getFacetConfig(source.facet).modelName as any;\n },\n filters: {\n $path: 'values',\n $subSchema: ({ facet }) => getFacetConfig(facet).schema as any,\n $context: {\n facetId: 'facet'\n }\n }\n});\n\nexport const hierarchicalFilterMutableSchema = createMutableSchema<\n Schema<PlatformHierarchicalFilter, HierarchicalFilter>\n>({\n facetId: (_, $context) => $context?.facetId as string,\n label: 'value',\n id: 'filter',\n totalResults: 'count',\n parentId: (_, $context) => ($context?.parentId as string) ?? null,\n selected: () => false,\n modelName: () => 'HierarchicalFilter',\n children: {\n $path: 'children.values',\n $subSchema: '$self',\n $context: {\n parentId: 'filter'\n }\n }\n});\n\nexport const facetsConfig: FacetsConfig = {\n categoryPaths: {\n modelName: 'HierarchicalFacet',\n schema: hierarchicalFilterMutableSchema\n },\n price: {\n modelName: 'NumberRangeFacet',\n schema: numberFilterMutableSchema\n },\n default: {\n modelName: 'SimpleFacet',\n schema: simpleFilterMutableSchema\n }\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"facet.model.js","sourceRoot":"","sources":["../../../../src/types/models/facet.model.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Facet model for the `platform` API.\n *\n * @public\n */\nexport interface PlatformFacet {\n facet: string;\n values: PlatformFilter[];\n}\n\n/**\n * Filter model for the `platform` API.\n *\n * @public\n */\nexport interface PlatformFilter {\n count: number;\n filter: string;\n id: string;\n value: string;\n}\n\n/**\n * HierarchicalFilter model for the `platform` API.\n *\n * @public\n */\nexport interface PlatformHierarchicalFilter extends PlatformFilter {\n children: PlatformFacet;\n}\n"]}
1
+ {"version":3,"file":"facet.model.js","sourceRoot":"","sources":["../../../../src/types/models/facet.model.ts"],"names":[],"mappings":"","sourcesContent":["import { BooleanFilter, Facet, Filter } from '@empathyco/x-types';\n\n/**\n * Facet model for the `platform` API.\n *\n * @public\n */\nexport interface PlatformFacet {\n facet: string;\n values: PlatformFilter[];\n}\n\n/**\n * Filter model for the `platform` API.\n *\n * @public\n */\nexport interface PlatformFilter {\n count: number;\n filter: string;\n id: string;\n value: string;\n}\n\n/**\n * HierarchicalFilter model for the `platform` API.\n *\n * @public\n */\nexport interface PlatformHierarchicalFilter extends PlatformFilter {\n children: PlatformFacet;\n}\n\n/**\n * Hierarchical Facet model used when combining search response mappers.\n *\n * @internal\n */\nexport interface AdapterHierarchicalFacet extends Facet {\n /** Model name to indicate the facet type. */\n modelName: 'HierarchicalFacet';\n /** Filters available for the facet. */\n filters: AdapterHierarchicalFilter[];\n}\n\n/**\n * Hierarchical Filter model used when combining search response mappers.\n *\n * @internal\n */\nexport interface AdapterHierarchicalFilter extends BooleanFilter {\n /** Model name to indicate the filter type. */\n modelName: 'HierarchicalFilter';\n /** A unique id used to reference the parent filter or null if it hasn't. */\n parentId: Filter['id'] | null;\n /** Descendants filters. */\n children?: AdapterHierarchicalFilter[];\n}\n"]}
@@ -1,4 +1,52 @@
1
- import { schemaMapperFactory } from '@empathyco/x-adapter-next';
1
+ import { schemaMapperFactory, combineMappers } from '@empathyco/x-adapter-next';
2
2
  import { searchResponseMutableSchema } from '../../schemas/responses/search-response.schema';
3
- export const searchResponseMapper = schemaMapperFactory(searchResponseMutableSchema);
3
+ export const searchResponseMapper = combineMappers(schemaMapperFactory(searchResponseMutableSchema), searchResponseFacetsMapper);
4
+ /**
5
+ * Mapper to flatten hierarchical facet filters.
6
+ *
7
+ * @param from - The Platform search response.
8
+ * @param context - The context from the mapper.
9
+ * @returns The mapped facets.
10
+ */
11
+ export function searchResponseFacetsMapper(from, { mappedValue }) {
12
+ var _a;
13
+ const facets = (_a = mappedValue.facets) === null || _a === void 0 ? void 0 : _a.map(facet => facet.modelName === 'HierarchicalFacet'
14
+ ? flattenHierarchicalFacet(facet)
15
+ : facet);
16
+ return { facets };
17
+ }
18
+ /**
19
+ * Returns a hierarchical facet with its filters flattened.
20
+ *
21
+ * @param facet - The hierarchical facet.
22
+ * @returns The flattened hierarchical facet.
23
+ */
24
+ function flattenHierarchicalFacet(facet) {
25
+ const filters = facet.filters.reduce((flattenedFilters, filter) => {
26
+ return mapHierarchicalFilter(filter, flattenedFilters);
27
+ }, []);
28
+ return {
29
+ ...facet,
30
+ filters
31
+ };
32
+ }
33
+ /**
34
+ * Map recursively the hierarchical facet filters.
35
+ *
36
+ * @param rawFilter - The hierarchical filter to map.
37
+ * @param filters - The filters array to fill with the facet filters.
38
+ * @returns The filter id.
39
+ */
40
+ function mapHierarchicalFilter(rawFilter, filters) {
41
+ var _a;
42
+ const filter = {
43
+ ...rawFilter,
44
+ children: (_a = rawFilter.children) === null || _a === void 0 ? void 0 : _a.map(rawFilterChild => {
45
+ mapHierarchicalFilter(rawFilterChild, filters);
46
+ return rawFilterChild.id;
47
+ })
48
+ };
49
+ filters.push(filter);
50
+ return filters;
51
+ }
4
52
  //# sourceMappingURL=search-response.mapper.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"search-response.mapper.js","sourceRoot":"","sources":["../../../../src/mappers/responses/search-response.mapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAGhE,OAAO,EAAE,2BAA2B,EAAE,MAAM,gDAAgD,CAAC;AAE7F,MAAM,CAAC,MAAM,oBAAoB,GAAG,mBAAmB,CACrD,2BAA2B,CAC5B,CAAC","sourcesContent":["import { schemaMapperFactory } from '@empathyco/x-adapter-next';\nimport { SearchResponse } from '@empathyco/x-types';\nimport { PlatformSearchResponse } from '../../types/responses/search-response.model';\nimport { searchResponseMutableSchema } from '../../schemas/responses/search-response.schema';\n\nexport const searchResponseMapper = schemaMapperFactory<PlatformSearchResponse, SearchResponse>(\n searchResponseMutableSchema\n);\n"]}
1
+ {"version":3,"file":"search-response.mapper.js","sourceRoot":"","sources":["../../../../src/mappers/responses/search-response.mapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAiB,MAAM,2BAA2B,CAAC;AAG/F,OAAO,EAAE,2BAA2B,EAAE,MAAM,gDAAgD,CAAC;AAM7F,MAAM,CAAC,MAAM,oBAAoB,GAAG,cAAc,CAChD,mBAAmB,CAAyC,2BAA2B,CAAC,EACxF,0BAA0B,CAC3B,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,UAAU,0BAA0B,CACxC,IAA4B,EAC5B,EAAE,WAAW,EAAiB;;IAE9B,MAAM,MAAM,GAAG,MAAC,WAA8B,CAAC,MAAM,0CAAE,GAAG,CAAC,KAAK,CAAC,EAAE,CACjE,KAAK,CAAC,SAAS,KAAK,mBAAmB;QACrC,CAAC,CAAC,wBAAwB,CAAC,KAAiC,CAAC;QAC7D,CAAC,CAAC,KAAK,CACV,CAAC;IACF,OAAO,EAAE,MAAM,EAAE,CAAC;AACpB,CAAC;AAED;;;;;GAKG;AACH,SAAS,wBAAwB,CAAC,KAA+B;IAC/D,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,gBAAgB,EAAE,MAAM,EAAE,EAAE;QAChE,OAAO,qBAAqB,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IACzD,CAAC,EAAE,EAA0B,CAAC,CAAC;IAE/B,OAAO;QACL,GAAG,KAAK;QACR,OAAO;KACR,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,SAAS,qBAAqB,CAC5B,SAAoC,EACpC,OAA6B;;IAE7B,MAAM,MAAM,GAAuB;QACjC,GAAG,SAAS;QACZ,QAAQ,EAAE,MAAA,SAAS,CAAC,QAAQ,0CAAE,GAAG,CAAC,cAAc,CAAC,EAAE;YACjD,qBAAqB,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;YAC/C,OAAO,cAAc,CAAC,EAAE,CAAC;QAC3B,CAAC,CAAC;KACH,CAAC;IACF,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACrB,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import { schemaMapperFactory, combineMappers, MapperContext } from '@empathyco/x-adapter-next';\nimport { SearchResponse, HierarchicalFacet, HierarchicalFilter } from '@empathyco/x-types';\nimport { PlatformSearchResponse } from '../../types/responses/search-response.model';\nimport { searchResponseMutableSchema } from '../../schemas/responses/search-response.schema';\nimport {\n AdapterHierarchicalFacet,\n AdapterHierarchicalFilter\n} from '../../types/models/facet.model';\n\nexport const searchResponseMapper = combineMappers(\n schemaMapperFactory<PlatformSearchResponse, SearchResponse>(searchResponseMutableSchema),\n searchResponseFacetsMapper\n);\n\n/**\n * Mapper to flatten hierarchical facet filters.\n *\n * @param from - The Platform search response.\n * @param context - The context from the mapper.\n * @returns The mapped facets.\n */\nexport function searchResponseFacetsMapper(\n from: PlatformSearchResponse,\n { mappedValue }: MapperContext\n): Partial<SearchResponse> {\n const facets = (mappedValue as SearchResponse).facets?.map(facet =>\n facet.modelName === 'HierarchicalFacet'\n ? flattenHierarchicalFacet(facet as AdapterHierarchicalFacet)\n : facet\n );\n return { facets };\n}\n\n/**\n * Returns a hierarchical facet with its filters flattened.\n *\n * @param facet - The hierarchical facet.\n * @returns The flattened hierarchical facet.\n */\nfunction flattenHierarchicalFacet(facet: AdapterHierarchicalFacet): HierarchicalFacet {\n const filters = facet.filters.reduce((flattenedFilters, filter) => {\n return mapHierarchicalFilter(filter, flattenedFilters);\n }, [] as HierarchicalFilter[]);\n\n return {\n ...facet,\n filters\n };\n}\n\n/**\n * Map recursively the hierarchical facet filters.\n *\n * @param rawFilter - The hierarchical filter to map.\n * @param filters - The filters array to fill with the facet filters.\n * @returns The filter id.\n */\nfunction mapHierarchicalFilter(\n rawFilter: AdapterHierarchicalFilter,\n filters: HierarchicalFilter[]\n): HierarchicalFilter[] {\n const filter: HierarchicalFilter = {\n ...rawFilter,\n children: rawFilter.children?.map(rawFilterChild => {\n mapHierarchicalFilter(rawFilterChild, filters);\n return rawFilterChild.id;\n })\n };\n filters.push(filter);\n return filters;\n}\n"]}
@@ -0,0 +1,3 @@
1
+ export * from './types';
2
+ export * from './utils';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/schemas/facets/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC","sourcesContent":["export * from './types';\nexport * from './utils';\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/schemas/facets/types.ts"],"names":[],"mappings":"","sourcesContent":["import { FacetModelName, Facet } from '@empathyco/x-types';\nimport { Schema } from '@empathyco/x-adapter-next';\n\n/**\n * Facet configuration containing the model name and the schema.\n */\nexport interface FacetConfig {\n modelName: FacetModelName;\n schema: Schema;\n}\n\n/**\n * Dictionary grouping facets configurations.\n */\nexport interface FacetsConfig {\n [key: Facet['id']]: FacetConfig;\n}\n"]}
@@ -0,0 +1,12 @@
1
+ import { facetsConfig } from '../models/facet.schema';
2
+ /**
3
+ * Returns the facet's config.
4
+ *
5
+ * @param facet - The facet to resolve the configuration.
6
+ * @returns The facet's config.
7
+ */
8
+ export function getFacetConfig(facet) {
9
+ var _a;
10
+ return (_a = facetsConfig[facet]) !== null && _a !== void 0 ? _a : facetsConfig.default;
11
+ }
12
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/schemas/facets/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAGtD;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,KAAa;;IAC1C,OAAO,MAAA,YAAY,CAAC,KAAK,CAAC,mCAAI,YAAY,CAAC,OAAO,CAAC;AACrD,CAAC","sourcesContent":["import { facetsConfig } from '../models/facet.schema';\nimport { FacetConfig } from './types';\n\n/**\n * Returns the facet's config.\n *\n * @param facet - The facet to resolve the configuration.\n * @returns The facet's config.\n */\nexport function getFacetConfig(facet: string): FacetConfig {\n return facetsConfig[facet] ?? facetsConfig.default;\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  import { createMutableSchema } from '@empathyco/x-adapter-next';
2
2
  export const numberFilterMutableSchema = createMutableSchema({
3
3
  id: 'filter',
4
- facetId: 'id',
4
+ facetId: (_, $context) => $context === null || $context === void 0 ? void 0 : $context.facetId,
5
5
  label: 'value',
6
6
  totalResults: 'count',
7
7
  selected: () => false,
@@ -1 +1 @@
1
- {"version":3,"file":"number-filter.schema.js","sourceRoot":"","sources":["../../../../src/schemas/filters/number-filter.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAU,MAAM,2BAA2B,CAAC;AAIxE,MAAM,CAAC,MAAM,yBAAyB,GAAG,mBAAmB,CAE1D;IACA,EAAE,EAAE,QAAQ;IACZ,OAAO,EAAE,IAAI;IACb,KAAK,EAAE,OAAO;IACd,YAAY,EAAE,OAAO;IACrB,QAAQ,EAAE,GAAG,EAAE,CAAC,KAAK;IACrB,SAAS,EAAE,GAAG,EAAE,CAAC,mBAAmB;IACpC,KAAK,EAAE;QACL,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAC/C,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;KAChD;CACF,CAAC,CAAC","sourcesContent":["import { createMutableSchema, Schema } from '@empathyco/x-adapter-next';\nimport { NumberRangeFilter } from '@empathyco/x-types';\nimport { PlatformFilter } from '../../types/models/facet.model';\n\nexport const numberFilterMutableSchema = createMutableSchema<\n Schema<PlatformFilter, NumberRangeFilter>\n>({\n id: 'filter',\n facetId: 'id',\n label: 'value',\n totalResults: 'count',\n selected: () => false,\n modelName: () => 'NumberRangeFilter',\n range: {\n min: ({ value }) => Number(value.split('-')[0]),\n max: ({ value }) => Number(value.split('-')[1])\n }\n});\n"]}
1
+ {"version":3,"file":"number-filter.schema.js","sourceRoot":"","sources":["../../../../src/schemas/filters/number-filter.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAU,MAAM,2BAA2B,CAAC;AAIxE,MAAM,CAAC,MAAM,yBAAyB,GAAG,mBAAmB,CAE1D;IACA,EAAE,EAAE,QAAQ;IACZ,OAAO,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,CAAC,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,OAAiB;IACrD,KAAK,EAAE,OAAO;IACd,YAAY,EAAE,OAAO;IACrB,QAAQ,EAAE,GAAG,EAAE,CAAC,KAAK;IACrB,SAAS,EAAE,GAAG,EAAE,CAAC,mBAAmB;IACpC,KAAK,EAAE;QACL,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAC/C,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;KAChD;CACF,CAAC,CAAC","sourcesContent":["import { createMutableSchema, Schema } from '@empathyco/x-adapter-next';\nimport { NumberRangeFilter } from '@empathyco/x-types';\nimport { PlatformFilter } from '../../types/models/facet.model';\n\nexport const numberFilterMutableSchema = createMutableSchema<\n Schema<PlatformFilter, NumberRangeFilter>\n>({\n id: 'filter',\n facetId: (_, $context) => $context?.facetId as string,\n label: 'value',\n totalResults: 'count',\n selected: () => false,\n modelName: () => 'NumberRangeFilter',\n range: {\n min: ({ value }) => Number(value.split('-')[0]),\n max: ({ value }) => Number(value.split('-')[1])\n }\n});\n"]}
@@ -1,6 +1,6 @@
1
1
  import { createMutableSchema } from '@empathyco/x-adapter-next';
2
2
  export const simpleFilterMutableSchema = createMutableSchema({
3
- facetId: 'filter',
3
+ facetId: (_, $context) => $context === null || $context === void 0 ? void 0 : $context.facetId,
4
4
  label: 'value',
5
5
  id: 'filter',
6
6
  totalResults: 'count',
@@ -1 +1 @@
1
- {"version":3,"file":"simple-filter.schema.js","sourceRoot":"","sources":["../../../../src/schemas/filters/simple-filter.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAU,MAAM,2BAA2B,CAAC;AAIxE,MAAM,CAAC,MAAM,yBAAyB,GAAG,mBAAmB,CAAuC;IACjG,OAAO,EAAE,QAAQ;IACjB,KAAK,EAAE,OAAO;IACd,EAAE,EAAE,QAAQ;IACZ,YAAY,EAAE,OAAO;IACrB,QAAQ,EAAE,GAAG,EAAE,CAAC,KAAK;IACrB,SAAS,EAAE,GAAG,EAAE,CAAC,cAAc;CAChC,CAAC,CAAC","sourcesContent":["import { createMutableSchema, Schema } from '@empathyco/x-adapter-next';\nimport { SimpleFilter } from '@empathyco/x-types';\nimport { PlatformFilter } from '../../types/models/facet.model';\n\nexport const simpleFilterMutableSchema = createMutableSchema<Schema<PlatformFilter, SimpleFilter>>({\n facetId: 'filter',\n label: 'value',\n id: 'filter',\n totalResults: 'count',\n selected: () => false,\n modelName: () => 'SimpleFilter'\n});\n"]}
1
+ {"version":3,"file":"simple-filter.schema.js","sourceRoot":"","sources":["../../../../src/schemas/filters/simple-filter.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAU,MAAM,2BAA2B,CAAC;AAIxE,MAAM,CAAC,MAAM,yBAAyB,GAAG,mBAAmB,CAAuC;IACjG,OAAO,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,CAAC,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,OAAiB;IACrD,KAAK,EAAE,OAAO;IACd,EAAE,EAAE,QAAQ;IACZ,YAAY,EAAE,OAAO;IACrB,QAAQ,EAAE,GAAG,EAAE,CAAC,KAAK;IACrB,SAAS,EAAE,GAAG,EAAE,CAAC,cAAc;CAChC,CAAC,CAAC","sourcesContent":["import { createMutableSchema, Schema } from '@empathyco/x-adapter-next';\nimport { SimpleFilter } from '@empathyco/x-types';\nimport { PlatformFilter } from '../../types/models/facet.model';\n\nexport const simpleFilterMutableSchema = createMutableSchema<Schema<PlatformFilter, SimpleFilter>>({\n facetId: (_, $context) => $context?.facetId as string,\n label: 'value',\n id: 'filter',\n totalResults: 'count',\n selected: () => false,\n modelName: () => 'SimpleFilter'\n});\n"]}
@@ -1,3 +1,4 @@
1
+ export * from './facets';
1
2
  export * from './filters';
2
3
  export * from './models';
3
4
  export * from './requests';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/schemas/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC","sourcesContent":["export * from './filters';\nexport * from './models';\nexport * from './requests';\nexport * from './responses';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/schemas/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC","sourcesContent":["export * from './facets';\nexport * from './filters';\nexport * from './models';\nexport * from './requests';\nexport * from './responses';\n"]}
@@ -1,63 +1,49 @@
1
1
  import { createMutableSchema } from '@empathyco/x-adapter-next';
2
2
  import { numberFilterMutableSchema } from '../filters/number-filter.schema';
3
3
  import { simpleFilterMutableSchema } from '../filters/simple-filter.schema';
4
+ import { getFacetConfig } from '../facets/utils';
4
5
  export const facetMutableSchema = createMutableSchema({
5
6
  id: 'facet',
6
7
  label: 'facet',
7
- modelName: ({ facet }) => getFacetType(facet),
8
+ modelName: source => {
9
+ return getFacetConfig(source.facet).modelName;
10
+ },
8
11
  filters: {
9
12
  $path: 'values',
10
- $subSchema: ({ facet }) => getFilterSchemaFromFacetType(facet),
13
+ $subSchema: ({ facet }) => getFacetConfig(facet).schema,
11
14
  $context: {
12
- parentId: 'facet'
15
+ facetId: 'facet'
13
16
  }
14
17
  }
15
18
  });
16
19
  export const hierarchicalFilterMutableSchema = createMutableSchema({
17
- facetId: 'filter',
20
+ facetId: (_, $context) => $context === null || $context === void 0 ? void 0 : $context.facetId,
18
21
  label: 'value',
19
22
  id: 'filter',
20
23
  totalResults: 'count',
21
- parentId: (_, $context) => $context === null || $context === void 0 ? void 0 : $context.parentId,
24
+ parentId: (_, $context) => { var _a; return (_a = $context === null || $context === void 0 ? void 0 : $context.parentId) !== null && _a !== void 0 ? _a : null; },
22
25
  selected: () => false,
23
26
  modelName: () => 'HierarchicalFilter',
24
27
  children: {
25
- $path: 'children',
26
- $subSchema: facetMutableSchema
28
+ $path: 'children.values',
29
+ $subSchema: '$self',
30
+ $context: {
31
+ parentId: 'filter'
32
+ }
27
33
  }
28
34
  });
29
- /**
30
- * Resolves the proper facet model name.
31
- *
32
- * @param facet - The facet to resolve the model name.
33
- * @returns The facet's model name.
34
- */
35
- function getFacetType(facet) {
36
- const name = facet.split('_')[0];
37
- const hierarchicalFacet = ['categoryPaths'];
38
- const numberRangeFacet = ['price'];
39
- if (hierarchicalFacet.includes(name)) {
40
- return 'HierarchicalFacet';
41
- }
42
- if (numberRangeFacet.includes(name)) {
43
- return 'NumberRangeFacet';
44
- }
45
- return 'SimpleFacet';
46
- }
47
- /**
48
- * Returns the proper schema to apply to the given facet.
49
- *
50
- * @param facet - The facet to resolve the schema to apply.
51
- * @returns The schema to apply.
52
- */
53
- function getFilterSchemaFromFacetType(facet) {
54
- const facetType = getFacetType(facet);
55
- if (facetType === 'HierarchicalFacet') {
56
- return hierarchicalFilterMutableSchema;
57
- }
58
- if (facetType === 'NumberRangeFacet') {
59
- return numberFilterMutableSchema;
35
+ export const facetsConfig = {
36
+ categoryPaths: {
37
+ modelName: 'HierarchicalFacet',
38
+ schema: hierarchicalFilterMutableSchema
39
+ },
40
+ price: {
41
+ modelName: 'NumberRangeFacet',
42
+ schema: numberFilterMutableSchema
43
+ },
44
+ default: {
45
+ modelName: 'SimpleFacet',
46
+ schema: simpleFilterMutableSchema
60
47
  }
61
- return simpleFilterMutableSchema;
62
- }
48
+ };
63
49
  //# sourceMappingURL=facet.schema.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"facet.schema.js","sourceRoot":"","sources":["../../../../src/schemas/models/facet.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAU,MAAM,2BAA2B,CAAC;AASxE,OAAO,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAC;AAC5E,OAAO,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAC;AAG5E,MAAM,CAAC,MAAM,kBAAkB,GAAG,mBAAmB,CAKnD;IACA,EAAE,EAAE,OAAO;IACX,KAAK,EAAE,OAAO;IACd,SAAS,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,YAAY,CAAC,KAAK,CAAQ;IACpD,OAAO,EAAE;QACP,KAAK,EAAE,QAAQ;QACf,UAAU,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,4BAA4B,CAAC,KAAK,CAAC;QAC9D,QAAQ,EAAE;YACR,QAAQ,EAAE,OAAO;SAClB;KACF;CACF,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,+BAA+B,GAAG,mBAAmB,CAEhE;IACA,OAAO,EAAE,QAAQ;IACjB,KAAK,EAAE,OAAO;IACd,EAAE,EAAE,QAAQ;IACZ,YAAY,EAAE,OAAO;IACrB,QAAQ,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,CAAC,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,QAAkB;IACvD,QAAQ,EAAE,GAAG,EAAE,CAAC,KAAK;IACrB,SAAS,EAAE,GAAG,EAAE,CAAC,oBAAoB;IACrC,QAAQ,EAAE;QACR,KAAK,EAAE,UAAU;QACjB,UAAU,EAAE,kBAAyB;KACtC;CACF,CAAC,CAAC;AAEH;;;;;GAKG;AACH,SAAS,YAAY,CAAC,KAAa;IACjC,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACjC,MAAM,iBAAiB,GAAG,CAAC,eAAe,CAAC,CAAC;IAC5C,MAAM,gBAAgB,GAAG,CAAC,OAAO,CAAC,CAAC;IACnC,IAAI,iBAAiB,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;QACpC,OAAO,mBAAmB,CAAC;KAC5B;IACD,IAAI,gBAAgB,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;QACnC,OAAO,kBAAkB,CAAC;KAC3B;IACD,OAAO,aAAa,CAAC;AACvB,CAAC;AAED;;;;;GAKG;AACH,SAAS,4BAA4B,CAAC,KAAa;IACjD,MAAM,SAAS,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;IACtC,IAAI,SAAS,KAAK,mBAAmB,EAAE;QACrC,OAAO,+BAA+B,CAAC;KACxC;IACD,IAAI,SAAS,KAAK,kBAAkB,EAAE;QACpC,OAAO,yBAAyB,CAAC;KAClC;IACD,OAAO,yBAAyB,CAAC;AACnC,CAAC","sourcesContent":["import { createMutableSchema, Schema } from '@empathyco/x-adapter-next';\nimport {\n EditableNumberRangeFacet,\n FacetModelName,\n HierarchicalFacet,\n HierarchicalFilter,\n NumberRangeFacet,\n SimpleFacet\n} from '@empathyco/x-types';\nimport { numberFilterMutableSchema } from '../filters/number-filter.schema';\nimport { simpleFilterMutableSchema } from '../filters/simple-filter.schema';\nimport { PlatformFacet, PlatformHierarchicalFilter } from '../../types/models/facet.model';\n\nexport const facetMutableSchema = createMutableSchema<\n Schema<\n PlatformFacet,\n HierarchicalFacet | NumberRangeFacet | SimpleFacet | EditableNumberRangeFacet\n >\n>({\n id: 'facet',\n label: 'facet',\n modelName: ({ facet }) => getFacetType(facet) as any,\n filters: {\n $path: 'values',\n $subSchema: ({ facet }) => getFilterSchemaFromFacetType(facet),\n $context: {\n parentId: 'facet'\n }\n }\n});\n\nexport const hierarchicalFilterMutableSchema = createMutableSchema<\n Schema<PlatformHierarchicalFilter, HierarchicalFilter>\n>({\n facetId: 'filter',\n label: 'value',\n id: 'filter',\n totalResults: 'count',\n parentId: (_, $context) => $context?.parentId as string,\n selected: () => false,\n modelName: () => 'HierarchicalFilter',\n children: {\n $path: 'children',\n $subSchema: facetMutableSchema as any\n }\n});\n\n/**\n * Resolves the proper facet model name.\n *\n * @param facet - The facet to resolve the model name.\n * @returns The facet's model name.\n */\nfunction getFacetType(facet: string): FacetModelName {\n const name = facet.split('_')[0];\n const hierarchicalFacet = ['categoryPaths'];\n const numberRangeFacet = ['price'];\n if (hierarchicalFacet.includes(name)) {\n return 'HierarchicalFacet';\n }\n if (numberRangeFacet.includes(name)) {\n return 'NumberRangeFacet';\n }\n return 'SimpleFacet';\n}\n\n/**\n * Returns the proper schema to apply to the given facet.\n *\n * @param facet - The facet to resolve the schema to apply.\n * @returns The schema to apply.\n */\nfunction getFilterSchemaFromFacetType(facet: string): Schema {\n const facetType = getFacetType(facet);\n if (facetType === 'HierarchicalFacet') {\n return hierarchicalFilterMutableSchema;\n }\n if (facetType === 'NumberRangeFacet') {\n return numberFilterMutableSchema;\n }\n return simpleFilterMutableSchema;\n}\n"]}
1
+ {"version":3,"file":"facet.schema.js","sourceRoot":"","sources":["../../../../src/schemas/models/facet.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAU,MAAM,2BAA2B,CAAC;AAQxE,OAAO,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAC;AAC5E,OAAO,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAC;AAE5E,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAGjD,MAAM,CAAC,MAAM,kBAAkB,GAAG,mBAAmB,CAKnD;IACA,EAAE,EAAE,OAAO;IACX,KAAK,EAAE,OAAO;IACd,SAAS,EAAE,MAAM,CAAC,EAAE;QAClB,OAAO,cAAc,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,SAAgB,CAAC;IACvD,CAAC;IACD,OAAO,EAAE;QACP,KAAK,EAAE,QAAQ;QACf,UAAU,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,MAAa;QAC9D,QAAQ,EAAE;YACR,OAAO,EAAE,OAAO;SACjB;KACF;CACF,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,+BAA+B,GAAG,mBAAmB,CAEhE;IACA,OAAO,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,CAAC,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,OAAiB;IACrD,KAAK,EAAE,OAAO;IACd,EAAE,EAAE,QAAQ;IACZ,YAAY,EAAE,OAAO;IACrB,QAAQ,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,WAAC,OAAA,MAAC,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,QAAmB,mCAAI,IAAI,CAAA,EAAA;IACjE,QAAQ,EAAE,GAAG,EAAE,CAAC,KAAK;IACrB,SAAS,EAAE,GAAG,EAAE,CAAC,oBAAoB;IACrC,QAAQ,EAAE;QACR,KAAK,EAAE,iBAAiB;QACxB,UAAU,EAAE,OAAO;QACnB,QAAQ,EAAE;YACR,QAAQ,EAAE,QAAQ;SACnB;KACF;CACF,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,YAAY,GAAiB;IACxC,aAAa,EAAE;QACb,SAAS,EAAE,mBAAmB;QAC9B,MAAM,EAAE,+BAA+B;KACxC;IACD,KAAK,EAAE;QACL,SAAS,EAAE,kBAAkB;QAC7B,MAAM,EAAE,yBAAyB;KAClC;IACD,OAAO,EAAE;QACP,SAAS,EAAE,aAAa;QACxB,MAAM,EAAE,yBAAyB;KAClC;CACF,CAAC","sourcesContent":["import { createMutableSchema, Schema } from '@empathyco/x-adapter-next';\nimport {\n EditableNumberRangeFacet,\n HierarchicalFacet,\n HierarchicalFilter,\n NumberRangeFacet,\n SimpleFacet\n} from '@empathyco/x-types';\nimport { numberFilterMutableSchema } from '../filters/number-filter.schema';\nimport { simpleFilterMutableSchema } from '../filters/simple-filter.schema';\nimport { PlatformFacet, PlatformHierarchicalFilter } from '../../types/models/facet.model';\nimport { getFacetConfig } from '../facets/utils';\nimport { FacetsConfig } from '../facets/types';\n\nexport const facetMutableSchema = createMutableSchema<\n Schema<\n PlatformFacet,\n HierarchicalFacet | NumberRangeFacet | SimpleFacet | EditableNumberRangeFacet\n >\n>({\n id: 'facet',\n label: 'facet',\n modelName: source => {\n return getFacetConfig(source.facet).modelName as any;\n },\n filters: {\n $path: 'values',\n $subSchema: ({ facet }) => getFacetConfig(facet).schema as any,\n $context: {\n facetId: 'facet'\n }\n }\n});\n\nexport const hierarchicalFilterMutableSchema = createMutableSchema<\n Schema<PlatformHierarchicalFilter, HierarchicalFilter>\n>({\n facetId: (_, $context) => $context?.facetId as string,\n label: 'value',\n id: 'filter',\n totalResults: 'count',\n parentId: (_, $context) => ($context?.parentId as string) ?? null,\n selected: () => false,\n modelName: () => 'HierarchicalFilter',\n children: {\n $path: 'children.values',\n $subSchema: '$self',\n $context: {\n parentId: 'filter'\n }\n }\n});\n\nexport const facetsConfig: FacetsConfig = {\n categoryPaths: {\n modelName: 'HierarchicalFacet',\n schema: hierarchicalFilterMutableSchema\n },\n price: {\n modelName: 'NumberRangeFacet',\n schema: numberFilterMutableSchema\n },\n default: {\n modelName: 'SimpleFacet',\n schema: simpleFilterMutableSchema\n }\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"facet.model.js","sourceRoot":"","sources":["../../../../src/types/models/facet.model.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Facet model for the `platform` API.\n *\n * @public\n */\nexport interface PlatformFacet {\n facet: string;\n values: PlatformFilter[];\n}\n\n/**\n * Filter model for the `platform` API.\n *\n * @public\n */\nexport interface PlatformFilter {\n count: number;\n filter: string;\n id: string;\n value: string;\n}\n\n/**\n * HierarchicalFilter model for the `platform` API.\n *\n * @public\n */\nexport interface PlatformHierarchicalFilter extends PlatformFilter {\n children: PlatformFacet;\n}\n"]}
1
+ {"version":3,"file":"facet.model.js","sourceRoot":"","sources":["../../../../src/types/models/facet.model.ts"],"names":[],"mappings":"","sourcesContent":["import { BooleanFilter, Facet, Filter } from '@empathyco/x-types';\n\n/**\n * Facet model for the `platform` API.\n *\n * @public\n */\nexport interface PlatformFacet {\n facet: string;\n values: PlatformFilter[];\n}\n\n/**\n * Filter model for the `platform` API.\n *\n * @public\n */\nexport interface PlatformFilter {\n count: number;\n filter: string;\n id: string;\n value: string;\n}\n\n/**\n * HierarchicalFilter model for the `platform` API.\n *\n * @public\n */\nexport interface PlatformHierarchicalFilter extends PlatformFilter {\n children: PlatformFacet;\n}\n\n/**\n * Hierarchical Facet model used when combining search response mappers.\n *\n * @internal\n */\nexport interface AdapterHierarchicalFacet extends Facet {\n /** Model name to indicate the facet type. */\n modelName: 'HierarchicalFacet';\n /** Filters available for the facet. */\n filters: AdapterHierarchicalFilter[];\n}\n\n/**\n * Hierarchical Filter model used when combining search response mappers.\n *\n * @internal\n */\nexport interface AdapterHierarchicalFilter extends BooleanFilter {\n /** Model name to indicate the filter type. */\n modelName: 'HierarchicalFilter';\n /** A unique id used to reference the parent filter or null if it hasn't. */\n parentId: Filter['id'] | null;\n /** Descendants filters. */\n children?: AdapterHierarchicalFilter[];\n}\n"]}
@@ -1,3 +1,22 @@
1
+ import { MapperContext } from '@empathyco/x-adapter-next';
1
2
  import { SearchResponse } from '@empathyco/x-types';
2
3
  import { PlatformSearchResponse } from '../../types/responses/search-response.model';
3
- export declare const searchResponseMapper: import("@empathyco/x-adapter-next").Mapper<PlatformSearchResponse, SearchResponse>;
4
+ export declare const searchResponseMapper: import("@empathyco/x-adapter-next").Mapper<PlatformSearchResponse, {
5
+ banners: import("@empathyco/x-types").Banner[];
6
+ facets: import("@empathyco/x-types").Facet[];
7
+ partialResults: import("@empathyco/x-types").PartialResult[];
8
+ promoteds: import("@empathyco/x-types").Promoted[];
9
+ queryTagging: import("@empathyco/x-types").TaggingRequest;
10
+ redirections: import("@empathyco/x-types").Redirection[];
11
+ results: import("@empathyco/x-types").Result[];
12
+ spellcheck: string;
13
+ totalResults: number;
14
+ }>;
15
+ /**
16
+ * Mapper to flatten hierarchical facet filters.
17
+ *
18
+ * @param from - The Platform search response.
19
+ * @param context - The context from the mapper.
20
+ * @returns The mapped facets.
21
+ */
22
+ export declare function searchResponseFacetsMapper(from: PlatformSearchResponse, { mappedValue }: MapperContext): Partial<SearchResponse>;
@@ -0,0 +1,2 @@
1
+ export * from './types';
2
+ export * from './utils';
@@ -0,0 +1,15 @@
1
+ import { FacetModelName, Facet } from '@empathyco/x-types';
2
+ import { Schema } from '@empathyco/x-adapter-next';
3
+ /**
4
+ * Facet configuration containing the model name and the schema.
5
+ */
6
+ export interface FacetConfig {
7
+ modelName: FacetModelName;
8
+ schema: Schema;
9
+ }
10
+ /**
11
+ * Dictionary grouping facets configurations.
12
+ */
13
+ export interface FacetsConfig {
14
+ [key: Facet['id']]: FacetConfig;
15
+ }
@@ -0,0 +1,8 @@
1
+ import { FacetConfig } from './types';
2
+ /**
3
+ * Returns the facet's config.
4
+ *
5
+ * @param facet - The facet to resolve the configuration.
6
+ * @returns The facet's config.
7
+ */
8
+ export declare function getFacetConfig(facet: string): FacetConfig;
@@ -1,3 +1,4 @@
1
+ export * from './facets';
1
2
  export * from './filters';
2
3
  export * from './models';
3
4
  export * from './requests';
@@ -1,5 +1,7 @@
1
1
  import { Schema } from '@empathyco/x-adapter-next';
2
2
  import { EditableNumberRangeFacet, HierarchicalFacet, HierarchicalFilter, NumberRangeFacet, SimpleFacet } from '@empathyco/x-types';
3
3
  import { PlatformFacet, PlatformHierarchicalFilter } from '../../types/models/facet.model';
4
+ import { FacetsConfig } from '../facets/types';
4
5
  export declare const facetMutableSchema: import("@empathyco/x-adapter-next").MutableSchema<Schema<PlatformFacet, EditableNumberRangeFacet | HierarchicalFacet | NumberRangeFacet | SimpleFacet>>;
5
6
  export declare const hierarchicalFilterMutableSchema: import("@empathyco/x-adapter-next").MutableSchema<Schema<PlatformHierarchicalFilter, HierarchicalFilter>>;
7
+ export declare const facetsConfig: FacetsConfig;
@@ -1,3 +1,4 @@
1
+ import { BooleanFilter, Facet, Filter } from '@empathyco/x-types';
1
2
  /**
2
3
  * Facet model for the `platform` API.
3
4
  *
@@ -26,3 +27,27 @@ export interface PlatformFilter {
26
27
  export interface PlatformHierarchicalFilter extends PlatformFilter {
27
28
  children: PlatformFacet;
28
29
  }
30
+ /**
31
+ * Hierarchical Facet model used when combining search response mappers.
32
+ *
33
+ * @internal
34
+ */
35
+ export interface AdapterHierarchicalFacet extends Facet {
36
+ /** Model name to indicate the facet type. */
37
+ modelName: 'HierarchicalFacet';
38
+ /** Filters available for the facet. */
39
+ filters: AdapterHierarchicalFilter[];
40
+ }
41
+ /**
42
+ * Hierarchical Filter model used when combining search response mappers.
43
+ *
44
+ * @internal
45
+ */
46
+ export interface AdapterHierarchicalFilter extends BooleanFilter {
47
+ /** Model name to indicate the filter type. */
48
+ modelName: 'HierarchicalFilter';
49
+ /** A unique id used to reference the parent filter or null if it hasn't. */
50
+ parentId: Filter['id'] | null;
51
+ /** Descendants filters. */
52
+ children?: AdapterHierarchicalFilter[];
53
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@empathyco/x-adapter-platform",
3
- "version": "1.0.0-alpha.16",
3
+ "version": "1.0.0-alpha.17",
4
4
  "description": "A search client for the Empathy Platform API",
5
5
  "author": "Empathy Systems Corporation S.L.",
6
6
  "license": "Apache-2.0",
@@ -48,5 +48,5 @@
48
48
  "publishConfig": {
49
49
  "access": "public"
50
50
  },
51
- "gitHead": "d6bf56e356022a7c6aff4849ec93a1a69ef811bb"
51
+ "gitHead": "bd8c5afbe72d62b9fc2413116026752121bbb2dc"
52
52
  }