From 0cd9b48eaa46f8dcc87496674932e025ec4b19a1 Mon Sep 17 00:00:00 2001 From: kube-js Date: Wed, 28 Aug 2019 23:25:17 +0100 Subject: [PATCH] fix: fixed facade inteface --- dist/FactoryConfig.d.ts | 1 - src/FactoryConfig.ts | 15 ++++++------- src/factory.ts | 49 ++++++++++++++++++----------------------- 3 files changed, 28 insertions(+), 37 deletions(-) diff --git a/dist/FactoryConfig.d.ts b/dist/FactoryConfig.d.ts index 1cb237a..f70d714 100644 --- a/dist/FactoryConfig.d.ts +++ b/dist/FactoryConfig.d.ts @@ -39,5 +39,4 @@ export default interface FactoryConfig { readonly createItemOptions?: ConvertItemIntoOptions; readonly defaultPaginationLimit?: number; readonly itemName: string; - readonly service: Facade; } diff --git a/src/FactoryConfig.ts b/src/FactoryConfig.ts index 2c29020..5b58aed 100644 --- a/src/FactoryConfig.ts +++ b/src/FactoryConfig.ts @@ -1,6 +1,7 @@ // tslint:disable:no-any import { CreateItem, + DeleteItem, DeleteItems, Filter, GetItem, @@ -10,7 +11,6 @@ import { Sort, UpdateItem, } from '@js-items/foundation'; -import Facade from '@js-items/foundation/dist/Facade'; import ky from 'ky'; import { ConvertItemIntoOptions } from './types/convertItemIntoOptions'; import { Handler } from './types/handler'; @@ -32,24 +32,23 @@ export default interface FactoryConfig { readonly envelopParamName?: string; readonly prettyParamName?: string; readonly createFilter: (filter?: Filter) => any; - readonly convertDocumentIntoItem: (document: Document) => I; - readonly convertItemIntoOptions: ConvertItemIntoOptions; - readonly createSort: (sort: Sort) => any; + readonly convertDocumentIntoItem?: (document: Document) => I; + readonly convertItemIntoOptions?: ConvertItemIntoOptions; + readonly createSort?: (sort: Sort) => any; readonly updateItem?: Handler>; readonly updateItemOptions?: ConvertItemIntoOptions; readonly replaceItem?: Handler>; readonly replaceItemOptions?: ConvertItemIntoOptions; - readonly deleteItem?: Handler>; + readonly deleteItem?: Handler>; readonly deleteItemOptions?: ConvertItemIntoOptions; - readonly deleteItems?: Handler>; + readonly deleteItems?: Handler>; readonly deleteItemsOptions?: ConvertItemIntoOptions; readonly getItem?: Handler>; readonly getItemOptions?: ConvertItemIntoOptions; readonly getItems?: Handler>; readonly getItemsOptions?: ConvertItemIntoOptions; - readonly createItem?: Handler>; + readonly createItem?: Handler>; readonly createItemOptions?: ConvertItemIntoOptions; readonly defaultPaginationLimit?: number; readonly itemName: string; - readonly service: Facade; } diff --git a/src/factory.ts b/src/factory.ts index addba57..8639c63 100644 --- a/src/factory.ts +++ b/src/factory.ts @@ -1,19 +1,16 @@ // tslint:disable:no-any -// TODO: uncomment all commented lines -import { /* DeleteItem, */ Item } from '@js-items/foundation'; -// import Facade from '@js-items/foundation/dist/Facade'; -// import Facade from '@js-items/foundation/dist/Facade'; +import { Item } from '@js-items/foundation'; +import Facade from '@js-items/foundation/dist/Facade'; import _defaultTo from 'ramda/src/defaultTo'; import FacadeConfig from './FacadeConfig'; import FactoryConfig from './FactoryConfig'; import defaultCreateItem from './functions/createItem'; -// import defaultDeleteItem from './functions/deleteItem'; -// import defaultDeleteItems from './functions/deleteItems'; -// import defaultGetItem from './functions/getItem'; -// import defaultGetItems from './functions/getItems'; -// import defaultReplaceItem from './functions/replaceItem'; -// import defaultUpdateItem from './functions/updateItem'; -// import { Handler } from './types/handler'; +import defaultDeleteItem from './functions/deleteItem'; +import defaultDeleteItems from './functions/deleteItems'; +import defaultGetItem from './functions/getItem'; +import defaultGetItems from './functions/getItems'; +import defaultReplaceItem from './functions/replaceItem'; +import defaultUpdateItem from './functions/updateItem'; import defaultConvertItemToOptions from './utils/defaultConvertItemToOptions'; import { emptyOptions } from './utils/emptyOptions'; @@ -27,9 +24,7 @@ export default ({ createItem, convertItemIntoOptions, ...config -}: FactoryConfig< - I ->): any /* uncomment when finished entirely: Facade */ => { +}: FactoryConfig): Facade => { const itemIntoOptions = _defaultTo(defaultConvertItemToOptions)( convertItemIntoOptions ); @@ -51,22 +46,20 @@ export default ({ }; const createItemFactory = _defaultTo(defaultCreateItem)(createItem); - // const deleteItemFactory = _defaultTo( - // defaultDeleteItem - // )(deleteItem); - // const getItemFactory = _defaultTo(defaultGetItem)(getItem); - // const updateItemFactory = _defaultTo(defaultUpdateItem)(updateItem); - // const replaceItemFactory = _defaultTo(defaultReplaceItem)(replaceItem); - // const deleteItemsFactory = _defaultTo(defaultDeleteItems)(deleteItems); - // const getItemsFactory = _defaultTo(defaultGetItems)(getItems); + const deleteItemFactory = _defaultTo(defaultDeleteItem)(deleteItem); + const getItemFactory = _defaultTo(defaultGetItem)(getItem); + const updateItemFactory = _defaultTo(defaultUpdateItem)(updateItem); + const replaceItemFactory = _defaultTo(defaultReplaceItem)(replaceItem); + const deleteItemsFactory = _defaultTo(defaultDeleteItems)(deleteItems); + const getItemsFactory = _defaultTo(defaultGetItems)(getItems); return { createItem: createItemFactory(facadeConfig), - // deleteItem: deleteItemFactory(facadeConfig), - // deleteItems: deleteItemsFactory(facadeConfig), - // getItem: getItemFactory(facadeConfig), - // getItems: getItemsFactory(facadeConfig), - // replaceItem: replaceItemFactory(facadeConfig), - // updateItem: updateItemFactory(facadeConfig), + deleteItem: deleteItemFactory(facadeConfig), + deleteItems: deleteItemsFactory(facadeConfig), + getItem: getItemFactory(facadeConfig), + getItems: getItemsFactory(facadeConfig), + replaceItem: replaceItemFactory(facadeConfig), + updateItem: updateItemFactory(facadeConfig), }; };