Skip to content

Commit

Permalink
chore: migrate search-types develop branch
Browse files Browse the repository at this point in the history
  • Loading branch information
tiborux authored Jul 21, 2021
1 parent 1c52a6a commit f736add
Show file tree
Hide file tree
Showing 20 changed files with 130 additions and 56 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"scripts": {
"postinstall": "lerna bootstrap --hoist && npm run build",
"build": "lerna run build",
"lint": "lerna run lint",
"test": "lerna run test",
"lint": "lerna run lint --parallel",
"test": "lerna run test --parallel",
"prepare-release:stable": "lerna version --conventional-commits --conventional-graduate --no-git-tag-version --yes",
"release:alpha": "lerna publish --conventional-commits --conventional-prerelease --yes --no-push",
"publish-release": "node scripts/publish-release"
Expand Down
3 changes: 2 additions & 1 deletion packages/search-adapter/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ module.exports = {
preset: 'ts-jest',
testEnvironment: 'jsdom',
setupFilesAfterEnv: ['./src/__tests__/tests.setup.ts'],
testMatch: ['<rootDir>/**/*.spec.ts']
testMatch: ['<rootDir>/**/*.spec.ts'],
modulePaths: ["node_modules"] //TODO: Delete this when the facets refactor is done [EX-3505]
};
2 changes: 1 addition & 1 deletion packages/search-adapter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@empathyco/x-get-safe-property-chain": "^1.2.1-alpha.2",
"@empathyco/x-logger": "^1.1.0",
"@empathyco/x-storage-service": "^1.3.1-alpha.2",
"@empathyco/x-types": "^9.1.0-alpha.2",
"@empathyco/x-types": "npm:@empathyco/x-types@9.1.0-alpha.2",
"inversify": "~5.0.1",
"reflect-metadata": "~0.1.13",
"tslib": "~1.11.1"
Expand Down
2 changes: 1 addition & 1 deletion packages/search-types/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/search-types/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@empathyco/x-types",
"version": "9.1.0-alpha.2",
"version": "10.0.0-alpha.1",
"description": "Empathy search types",
"author": "Empathy Systems Corporation S.L.",
"license": "Apache-2.0",
Expand Down
3 changes: 1 addition & 2 deletions packages/search-types/src/banner.model.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { CallbackInfo } from './callback-info.model';
import { Identifiable } from './identifiable.model';
import { NamedModel } from './named-model.model';
import { Tagging } from './tagging.model';
Expand All @@ -10,7 +9,7 @@ import { Tagging } from './tagging.model';
*
* @public
*/
export interface Banner extends NamedModel, CallbackInfo, Identifiable {
export interface Banner extends NamedModel, Identifiable {
/** Banner title. */
title: string;
/** URL to redirect. */
Expand Down
11 changes: 0 additions & 11 deletions packages/search-types/src/callback-info.model.ts

This file was deleted.

24 changes: 14 additions & 10 deletions packages/search-types/src/facet/filter/boolean-filter.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@ import { BooleanFilterModelName } from '../../named-model.model';
import { Filter } from './filter.model';

/**
* A boolean filter used in {@link Facet}, which status can be selected or not.
* A boolean filter used in a {@link Facet}, which status can be selected or not and
* it may contains the total results number that the filter should return.
*
* @remarks It is like an "abstract" interface because it is not going to be implemented
* but it is extended by other interfaces. There will never be an object with this type.
*
* @public
*/
export interface BooleanFilter extends Filter {
/** Type to narrow {@link ModelNameType} from the extended Filter for the known subtypes */
modelName: BooleanFilterModelName;
/** Flag if the filter is selected or not. */
selected: boolean;
/** Filter value to use with the API. */
value: string;
/** Number of items for the filter. **/
totalResults?: number;
/** Type to narrow {@link ModelNameType} from the extended Filter for the known subtypes. */
modelName: BooleanFilterModelName;
/** Text to render the filter label. */
label: string;
/** Value to be sent to the backend. */
value: string;
/** Amount of matching results. **/
totalResults?: number;
}

/**
Expand All @@ -25,5 +29,5 @@ export interface BooleanFilter extends Filter {
* @public
*/
export function isBooleanFilter(filter: Filter): filter is BooleanFilter {
return typeof (filter as BooleanFilter).selected === 'boolean';
return 'label' in filter && 'value' in filter;
}
29 changes: 29 additions & 0 deletions packages/search-types/src/facet/filter/facet-filter.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { FilterModelName } from '../../named-model.model';
import { Facet } from '../facet.model';
import { Filter } from './filter.model';

/**
* A filter which is associated with a {@link Facet}.
*
* @remarks It is like an "abstract" interface because it is not going to be implemented
* but it is extended by other interfaces. There will never be an object with this type.
*
* @public
*/
export interface FacetFilter extends Filter {
/** The filter {@link ModelNameType | model name} excluding {@link RawFilter#modelName | RawFilter} model name. */
modelName: Exclude<FilterModelName, 'RawFilter'>;
/** An unique ID that identifies the facet that uses this filter */
facetId: Facet['id'];
}

/**
* Type guard to check if a filter is a {@link FacetFilter}.
*
* @param filter - The filter to check.
*
* @public
*/
export function isFacetFilter(filter: Filter): filter is FacetFilter {
return 'facetId' in filter;
}
15 changes: 7 additions & 8 deletions packages/search-types/src/facet/filter/filter.model.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { CallbackInfo } from '../../callback-info.model';
import { Identifiable } from '../../identifiable.model';
import { FilterModelName, NamedModel } from '../../named-model.model';
import { Facet } from '../facet.model';

/**
* A basic filter used in {@link Facet}, which is used to sift the results.
* A basic filter.
*
* @remarks It is like an "abstract" interface because it is not going to be implemented
* but it is extended by other interfaces. There will never be an object with this type.
*
* @public
*/
export interface Filter extends NamedModel<FilterModelName>, CallbackInfo, Identifiable {
/** An unique ID that identifies the facet that uses this filter */
facetId: Facet['id'];
/** Label that represents the filter text. */
label: string;
export interface Filter extends NamedModel<FilterModelName>, Identifiable {
/** Flag if the filter is selected or not. */
selected: boolean;
}
2 changes: 2 additions & 0 deletions packages/search-types/src/facet/filter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ export * from './range-value.model';
export * from './simple-filter.model';
export * from './boolean-filter.model';
export * from './editable-number-range-filter.model';
export * from './raw-filter.model';
export * from './facet-filter.model';
26 changes: 26 additions & 0 deletions packages/search-types/src/facet/filter/raw-filter.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Filter } from './filter.model';

/**
* A filter which id is the value of the filter. It can be selected or not.
*
* @public
*/
export interface RawFilter extends Filter {
/** Model name to indicate the filter type. */
modelName: 'RawFilter';
/** The value of the filter. */
id: string;
/** Force {@link Filter#selected | Filter selected} property to true */
selected: true;
}

/**
* Type guard to check if a filter is a {@link RawFilter}.
*
* @param filter - The filter to check.
*
* @public
*/
export function isRawFilter(filter: Filter): filter is RawFilter {
return filter.modelName === 'RawFilter';
}
1 change: 0 additions & 1 deletion packages/search-types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ export * from './facet';
export * from './query-signals';
export * from './result';
export * from './banner.model';
export * from './callback-info.model';
export * from './identifiable.model';
export * from './history-query.model';
export * from './named-model.model';
Expand Down
4 changes: 2 additions & 2 deletions packages/search-types/src/named-model.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ export interface NamedModel<T extends ModelNameType = ModelNameType> {
export type FacetModelName = 'SimpleFacet' | 'HierarchicalFacet' | 'NumberRangeFacet' | 'EditableNumberRangeFacet';

/**
* Filters model names type. It can be: {@link BooleanFilterModelName} or EditableNumberRangeFilter.
* Filters model names type. It can be: {@link BooleanFilterModelName}, RawFilter or EditableNumberRangeFilter.
*
* @public
*/
export type FilterModelName = BooleanFilterModelName | 'EditableNumberRangeFilter';
export type FilterModelName = BooleanFilterModelName | 'EditableNumberRangeFilter' | 'RawFilter';

/**
* Type to ease the usage of a model name in a {@link BooleanFilter} with autocomplete suggestions.
Expand Down
3 changes: 1 addition & 2 deletions packages/search-types/src/promoted.model.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { CallbackInfo } from './callback-info.model';
import { Identifiable } from './identifiable.model';
import { NamedModel } from './named-model.model';
import { Tagging } from './tagging.model';
Expand All @@ -9,7 +8,7 @@ import { Tagging } from './tagging.model';
*
* @public
*/
export interface Promoted extends NamedModel, CallbackInfo, Identifiable {
export interface Promoted extends NamedModel, Identifiable {
/** Promoted title. */
title: string;
/** URL to redirect. */
Expand Down
3 changes: 1 addition & 2 deletions packages/search-types/src/result/result.model.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { CallbackInfo } from '../callback-info.model';
import { Identifiable } from '../identifiable.model';
import { NamedModel } from '../named-model.model';
import { ResultIdentifier } from './result-identifier.model';
Expand All @@ -11,7 +10,7 @@ import { ResultTagging } from './result-tagging.model';
*
* @public
*/
export interface Result extends NamedModel, CallbackInfo, Identifiable {
export interface Result extends NamedModel, Identifiable {
/** The type of the result. i.e. product, article, pack... */
type: string;
/** Images of the result. It should be the URLs. */
Expand Down
38 changes: 30 additions & 8 deletions packages/search-types/src/schemas/filter.schema.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { EditableNumberRangeFilter } from '../facet/filter';
import { EditableNumberRangeFilter, FacetFilter } from '../facet/filter';
import { BooleanFilter } from '../facet/filter/boolean-filter.model';
import { Filter } from '../facet/filter/filter.model';
import { HierarchicalFilter } from '../facet/filter/hierarchical-filter.model';
import { NumberRangeFilter } from '../facet/filter/number-range-filter.model';
import { RawFilter } from '../facet/filter/raw-filter.model';
import { SimpleFilter } from '../facet/filter/simple-filter.model';
import { IdentifiableSchema } from './identifiable.schema';

Expand All @@ -13,10 +14,31 @@ import { IdentifiableSchema } from './identifiable.schema';
*/
export const FilterSchema: Filter = {
...IdentifiableSchema,
modelName: expect.any(String),
selected: expect.any(Boolean),
};

/**
* Jest schema for validating {@link FacetFilter} entities.
*
* @public
*/
export const FacetFilterSchema: FacetFilter = {
...FilterSchema,
facetId: expect.anyOf([Number, String]),
label: expect.any(String),
callbackInfo: expect.any(Object),
modelName: expect.any(String)
modelName: expect.any(String) && expect.not.stringMatching('RawFilter')
};

/**
* Jest schema for validating RawFilter entities.
*
* @public
*/
export const RawFilterSchema: RawFilter = {
...FilterSchema,
modelName: 'RawFilter',
id: expect.any(String),
selected: true
};

/**
Expand All @@ -25,10 +47,10 @@ export const FilterSchema: Filter = {
* @public
*/
export const BooleanFilterSchema: BooleanFilter = {
...FilterSchema,
modelName: expect.any(String),
selected: expect.any(Boolean),
value: expect.any(String)
...FacetFilterSchema,
label: expect.any(String),
value: expect.any(String),
totalResults: expect.undefinedOr(Number)
};

/**
Expand Down
2 changes: 0 additions & 2 deletions packages/search-types/src/schemas/result.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { TaggingSchema } from './tagging.schema';
*/
export const ResultSchema: Result = {
...IdentifiableSchema,
callbackInfo: expect.any(Object),
identifier: {
value: expect.any(String)
},
Expand Down Expand Up @@ -41,7 +40,6 @@ export const ResultSchema: Result = {
* @public
*/
export const RecommendationSchema: Result = {
callbackInfo: expect.any(Object),
...IdentifiableSchema,
identifier: {
value: expect.any(String)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,18 @@ export function apiDocumentation(options: APIDocumentationPluginOptions): Plugin
*/
function copyThirdPartyDocModel(buildPath: string, packageName: string): void {
const docModelName = `${packageName}.api.json`;
const originalLocationPath = path.join(

let originalLocationPath = path.join(
rootDir,
`node_modules/@empathyco/${packageName}/report/${docModelName}`
);
if (!fs.existsSync(originalLocationPath)) {
originalLocationPath = path.join(
rootDir,
'../../',
`node_modules/@empathyco/${packageName}/report/${docModelName}`
);
}
const destinationLocationPath = path.join(buildPath, docModelName);
fs.copyFileSync(originalLocationPath, destinationLocationPath);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/x-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"@empathyco/x-deep-merge": "^1.2.2-alpha.2",
"@empathyco/x-logger": "^1.1.0",
"@empathyco/x-storage-service": "^1.3.1-alpha.2",
"@empathyco/x-types": "^9.1.0-alpha.2",
"@empathyco/x-types": "npm:@empathyco/x-types@9.1.0-alpha.2",
"@types/resize-observer-browser": "~0.1.5",
"magic-string": "~0.25.7",
"reflect-metadata": "~0.1.13",
Expand Down

0 comments on commit f736add

Please sign in to comment.