Skip to content

Commit

Permalink
Merge pull request #56 from jvega190/feature/5025
Browse files Browse the repository at this point in the history
[5025] Upgrade to rxjs@^7.0.0
  • Loading branch information
sumerjabri committed Oct 19, 2021
2 parents 5e91c79 + 8f8dd22 commit de8931b
Show file tree
Hide file tree
Showing 19 changed files with 132 additions and 270 deletions.
4 changes: 2 additions & 2 deletions packages/classes/src/SDKService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ import { LookupTable } from '@craftercms/models';
export function httpGet<T extends any = any>(requestURL: string, params: Object = {}, headers?: LookupTable): Observable<T> {
const searchParams = new URLSearchParams(params as URLSearchParams);
return ajax.get(`${requestURL}?${searchParams.toString()}`, headers).pipe(
pluck<AjaxResponse, T>('response')
pluck('response')
);
}

export function httpPost<T extends any = any>(requestURL: string, body: Object = {}, headers?: LookupTable): Observable<T> {
return ajax.post(requestURL, body, { 'Content-Type': 'application/json', ...headers }).pipe(
pluck<AjaxResponse, T>('response')
pluck('response')
);
}

Expand Down
1 change: 0 additions & 1 deletion packages/classes/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ const DEFAULTS: CrafterConfig = {
GET_NAV_TREE: '/api/1/site/navigation/tree.json',
GET_BREADCRUMB: '/api/1/site/navigation/breadcrumb.json',
TRANSFORM_URL: '/api/1/site/url/transform.json',
SEARCH: 'crafter-search/api/2/search/search.json',
ELASTICSEARCH: 'api/1/site/elasticsearch/search'
},
contentTypeRegistry: {},
Expand Down
2 changes: 1 addition & 1 deletion packages/content/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@craftercms/classes": "0.0.0-PLACEHOLDER",
"@craftercms/models": "0.0.0-PLACEHOLDER",
"@craftercms/utils": "0.0.0-PLACEHOLDER",
"rxjs": "^6.5.4"
"rxjs": "^7.0.0"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^11.0.2",
Expand Down
25 changes: 12 additions & 13 deletions packages/content/src/NavigationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,23 @@
import { Observable } from 'rxjs';

import { crafterConf, SDKService } from '@craftercms/classes';
import { CrafterConfig } from '@craftercms/models';
import { CrafterConfig, NavigationItem } from '@craftercms/models';
import { composeUrl } from '@craftercms/utils';

// TODO: Add correct return types
type ToDoGetNavTreeReturnType = Observable<any>;
type ToDoGetNavBreadcrumbReturnType = Observable<any>;
type NavTreeReturnType = Observable<NavigationItem>;
type NavBreadcrumbReturnType = Observable<NavigationItem[]>;

/**
* Returns the navigation tree with the specified depth for the specified store URL.
* @param {string} path - the root folder of the tree
* @param {int} depth - the depth of the tree
* @param {string} currentPageUrl - the URL of the current page
*/
export function getNavTree(path: string): ToDoGetNavTreeReturnType;
export function getNavTree(path: string, depth: number): ToDoGetNavTreeReturnType;
export function getNavTree(path: string, depth: number, currentPageUrl: string): ToDoGetNavTreeReturnType;
export function getNavTree(path: string, depth: number, currentPageUrl: string, config: CrafterConfig): ToDoGetNavTreeReturnType;
export function getNavTree(path: string, depth: number = 1, currentPageUrl: string = '', config?: CrafterConfig): ToDoGetNavTreeReturnType {
export function getNavTree(path: string): NavTreeReturnType;
export function getNavTree(path: string, depth: number): NavTreeReturnType;
export function getNavTree(path: string, depth: number, currentPageUrl: string): NavTreeReturnType;
export function getNavTree(path: string, depth: number, currentPageUrl: string, config: CrafterConfig): NavTreeReturnType;
export function getNavTree(path: string, depth: number = 1, currentPageUrl: string = '', config?: CrafterConfig): NavTreeReturnType {
config = crafterConf.mix(config);
const requestURL = composeUrl(config, config.endpoints.GET_NAV_TREE);
return SDKService.httpGet(requestURL, {
Expand All @@ -50,10 +49,10 @@ export function getNavTree(path: string, depth: number = 1, currentPageUrl: stri
* @param {string} path - the current URL used to build the breadcrumb
* @param {string} root - the root URL, basically the starting point of the breadcrumb
*/
export function getNavBreadcrumb(path: string): ToDoGetNavBreadcrumbReturnType;
export function getNavBreadcrumb(path: string, root: string): ToDoGetNavBreadcrumbReturnType;
export function getNavBreadcrumb(path: string, root: string, config: CrafterConfig): ToDoGetNavBreadcrumbReturnType;
export function getNavBreadcrumb(path: string, root: string = '', config?: CrafterConfig): ToDoGetNavBreadcrumbReturnType {
export function getNavBreadcrumb(path: string): NavBreadcrumbReturnType;
export function getNavBreadcrumb(path: string, root: string): NavBreadcrumbReturnType;
export function getNavBreadcrumb(path: string, root: string, config: CrafterConfig): NavBreadcrumbReturnType;
export function getNavBreadcrumb(path: string, root: string = '', config?: CrafterConfig): NavBreadcrumbReturnType {
config = crafterConf.mix(config);
const requestURL = composeUrl(config, config.endpoints.GET_BREADCRUMB);
return SDKService.httpGet(requestURL, {
Expand Down
1 change: 1 addition & 0 deletions packages/models/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ export * from './src/LookupTable';
export * from './src/ReduxStore';
export * from './src/message';
export * from './src/ContentInstance';
export * from './src/search';
1 change: 0 additions & 1 deletion packages/models/src/CrafterConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export interface Endpoints {
GET_NAV_TREE: string;
GET_BREADCRUMB: string;
TRANSFORM_URL: string;
SEARCH: string;
ELASTICSEARCH: string;
}

Expand Down
34 changes: 34 additions & 0 deletions packages/models/src/search.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (C) 2007-2021 Crafter Software Corporation. All Rights Reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/

import { LookupTable } from "@craftercms/models";

export interface SearchResultHit {
_id: string;
_index: string;
_score: string;
_source: LookupTable<any>;
_type: string;
}

export interface SearchResult {
hits: SearchResultHit[];
max_score: number;
total: {
relation: string;
value: number;
}
}
2 changes: 1 addition & 1 deletion packages/redux/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@craftercms/content": "0.0.0-PLACEHOLDER",
"redux": "^4.0.5",
"redux-observable": "^1.2.0",
"rxjs": "^6.5.4"
"rxjs": "^7.0.0"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^11.0.2",
Expand Down
11 changes: 6 additions & 5 deletions packages/redux/src/epics/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ import {
GET_NAV_BREADCRUMB,
getNavBreadcrumbComplete
} from '../actions/content';
import { Item, NavigationItem } from "@craftercms/models";

export const getItemEpic =
(action$: Observable<AnyAction>) => action$.pipe(
ofType(GET_ITEM),
mergeMap(({ payload }) =>
ContentStoreService.getItem(payload)
.pipe(
map(item => getItemComplete({
map((item: Item) => getItemComplete({
item,
url: payload
})),
Expand Down Expand Up @@ -74,7 +75,7 @@ export const getChildrenEpic =
mergeMap(({ payload }) =>
ContentStoreService.getChildren(payload)
.pipe(
map(children => getChildrenComplete({
map((children: Item[]) => getChildrenComplete({
children,
url: payload
})),
Expand All @@ -90,7 +91,7 @@ export const getTreeEpic =
mergeMap(({ payload }) =>
ContentStoreService.getTree(payload.url, payload.depth)
.pipe(
map(tree => getTreeComplete({
map((tree: Item) => getTreeComplete({
tree,
url: payload.url
})),
Expand All @@ -106,7 +107,7 @@ export const getNavEpic =
mergeMap(({ payload }) =>
NavigationService.getNavTree(payload.url, payload.depth, payload.currentPageUrl)
.pipe(
map(nav => getNavComplete({
map((nav: NavigationItem) => getNavComplete({
nav,
url: payload.url
})),
Expand All @@ -122,7 +123,7 @@ export const getNavBreadcrumbEpic =
mergeMap(({ payload }) =>
NavigationService.getNavBreadcrumb(payload.url, payload.root)
.pipe(
map(breadcrumb => getNavBreadcrumbComplete({
map((breadcrumb: NavigationItem[]) => getNavBreadcrumbComplete({
breadcrumb,
url: payload.url
})),
Expand Down
5 changes: 3 additions & 2 deletions packages/redux/src/epics/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@ import {
SEARCH,
searchComplete
} from '../actions/search';
import { SearchResult } from "@craftercms/models";

export const searchEpic =
(action$: Observable<AnyAction>) => action$.pipe(
ofType(SEARCH),
mergeMap(({ payload }) =>
SearchService.search(payload, crafterConf.getConfig())
.pipe(
map(response => searchComplete({
response: response.response ? response.response : response,
map((response: SearchResult) => searchComplete({
response,
queryId: payload.uuid
})),
catchError(() => of(searchComplete({
Expand Down
12 changes: 7 additions & 5 deletions packages/redux/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ export function createReduxStore(config: {
namespaceCrafterState: false
}, config);

const epicMiddleware = createEpicMiddleware(
config.epicsArray
? combineEpics(...allEpics.concat(config.epicsArray))
: combineEpics(...allEpics));
const epicMiddleware = createEpicMiddleware();

const enhancers = config.reduxDevTools
? ((typeof window !== "undefined" && window['__REDUX_DEVTOOLS_EXTENSION_COMPOSE__']) || compose)
Expand All @@ -68,13 +65,18 @@ export function createReduxStore(config: {
? [ epicMiddleware, ...config.additionalMiddleWare ]
: [ epicMiddleware ];

return createStore(
const store = createStore(
config.reducerMixin
? combineReducers({ ...reducer, ...config.reducerMixin })
: combineReducers(reducer),
enhancers(applyMiddleware(...middlewares))
);

epicMiddleware.run(config.epicsArray
? combineEpics(...allEpics.concat(config.epicsArray))
: combineEpics(...allEpics));

return store;
}

/**
Expand Down
34 changes: 5 additions & 29 deletions packages/search/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Map model

#### Examples

- Connect to Crafter Search to query for content with ELASTIC SEARCH (crafter version: 3.1.x):
- Connect to Crafter Search to query for content with ELASTIC SEARCH:

```typescript
import { crafterConf } from '@craftercms/classes';
Expand All @@ -103,7 +103,7 @@ Map model
const fields = ['headline_s', 'blurb_t'];
const contentTypes = ['/page/post', '/component/post'];
search(
createQuery('elasticsearch', {
createQuery({
query: {
'bool': {
'filter': [
Expand All @@ -129,41 +129,17 @@ Map model
});
```

- Connect to Crafter Search to query for content with SOLR (crafter version: 3.0.x):

```typescript
import { crafterConf } from '@craftercms/classes';
import { search, createQuery } from '@craftercms/search';

//First, set the Crafter configuration to _cache_ your config.
//All subsequent calls to `getConfig` will use that configuration.
crafterConf.configure({
baseUrl: 'http://localhost:8080',
site: 'editorial',
searchId: 'editorial' // if searchId is the same as site, this parameters is not needed
})

const query = createQuery('solr');
query.query = "*:*";
query.filterQueries = ['content-type:"/component/video"'];

search(query).subscribe((results) => {
// ...
});
```

You may alternatively use a different config by supplying the config object at the service call invoking time
You may use a different config by supplying the config object at the service call invoking time.

```typescript
import { search, createQuery } from '@craftercms/search';

//Create query
const query = createQuery('elasticsearch');
query.query = {
const query = createQuery({
"query" : {
"match_all" : {}
}
};
});

search(query, { baseUrl: 'http://localhost:8080', site: 'editorial' }).subscribe((results) => {
// ...
Expand Down
2 changes: 1 addition & 1 deletion packages/search/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@craftercms/classes": "0.0.0-PLACEHOLDER",
"@craftercms/models": "0.0.0-PLACEHOLDER",
"@craftercms/utils": "0.0.0-PLACEHOLDER",
"rxjs": "^6.5.4",
"rxjs": "^7.0.0",
"url-search-params-polyfill": "^5.0.0",
"uuid": "^3.4.0"
},
Expand Down
1 change: 0 additions & 1 deletion packages/search/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@
*/

export * from './src/query';
export * from './src/solr-query';
export * from './src/elastic-query';
export * from './src/SearchService';
Loading

0 comments on commit de8931b

Please sign in to comment.