Repository: ViacomInc/data-point
Pull request #58 (2017-12-19 13:46:01)

Remove castAs, TransformExpression#context, and Fix typos


Patch:
diff --git a/packages/data-point-service/lib/factory.js b/packages/data-point-service/lib/factory.js
index b38bb3a..a47c9a6 100644
--- a/packages/data-point-service/lib/factory.js
+++ b/packages/data-point-service/lib/factory.js
@@ -29,7 +29,7 @@ function createServiceObject (options) {
     isCacheRequired,
     cachePrefix,
     settings,
-    isCacheAvaiable: false,
+    isCacheAvailable: false,
     cache: null,
     dataPoint: null
   }
@@ -46,12 +46,12 @@ function handleCacheError (err, Service) {
     )
   }
 
-  Service.isCacheAvaiable = false
+  Service.isCacheAvailable = false
   return Service
 }
 
 function successCreateCache (cache, service) {
-  service.isCacheAvaiable = true
+  service.isCacheAvailable = true
   service.cache = cache
   return service
 }
@@ -74,7 +74,7 @@ function createDataPoint (service) {
 }
 
 function bootstrapDataPoint (bootstrap, service) {
-  if (!service.isCacheAvaiable) {
+  if (!service.isCacheAvailable) {
     logger.warn(
       'REDIS is not availabe, there will be no cacheing mechanism for',
       'DataPoint - we wish you the best of luck in your adventure.'
diff --git a/packages/data-point/lib/core/normalize-entities.js b/packages/data-point/lib/core/normalize-entities.js
index 72a0e20..874708e 100644
--- a/packages/data-point/lib/core/normalize-entities.js
+++ b/packages/data-point/lib/core/normalize-entities.js
@@ -9,7 +9,7 @@ function getParentSpec (spec, specs) {
   const parentSpec = specs[parentId]
   if (!parentSpec) {
     throw new Error(
-      `Could not extend ${spec.id}, parent ${parentId} does not exists.`
+      `Could not extend ${spec.id}, parent ${parentId} does not exist.`
     )
   }
   return parentSpec
@@ -73,8 +73,8 @@ module.exports.normalizeSpec = normalizeSpec
 function normalizeEntitySpecs (source) {
   const specIds = Object.keys(source)
   return specIds.reduce((normSpecs, specItemId) => {
-    const nomralizedSpec = normalizeSpec(specItemId, source)
-    normSpecs[nomralizedSpec.id] = nomralizedSpec
+    const normalizedSpec = normalizeSpec(specItemId, source)
+    normSpecs[normalizedSpec.id] = normalizedSpec
     return normSpecs
   }, {})
 }
diff --git a/packages/data-point/lib/entity-types/resolve-entity/resolve-entity.js b/packages/data-point/lib/entity-types/resolve-entity/resolve-entity.js
index 95b621a..cc28024 100644
--- a/packages/data-point/lib/entity-types/resolve-entity/resolve-entity.js
+++ b/packages/data-point/lib/entity-types/resolve-entity/resolve-entity.js
@@ -107,14 +107,10 @@ function resolveEntity (
     console.time(timeId)
   }
   return Promise.resolve(accUid)
-    .then(acc => {
-      return resolveMiddleware(store, `before`, acc)
-    })
+    .then(acc => resolveMiddleware(store, `before`, acc))
     .then(acc => resolveMiddleware(store, `${reducer.entityType}:before`, acc))
     .then(acc => resolveTransform(acc, acc.reducer.spec.before))
-    .then(acc => {
-      return mainResolver(acc, resolveTransform)
-    })
+    .then(acc => mainResolver(acc, resolveTransform))
     .then(acc => resolveTransform(acc, acc.reducer.spec.after))
     .then(acc => middleware.resolve(store, `${reducer.entityType}:after`, acc))
     .then(acc => resolveMiddleware(store, `after`, acc))
@@ -143,10 +139,10 @@ module.exports.resolveEntity = resolveEntity
 
 function resolve (store, resolveReducer, accumulator, reducer, mainResolver) {
   const resolveTransform = _.partial(resolveReducer, store)
-  const shuouldMapCollection =
+  const shouldMapCollection =
     reducer.asCollection && accumulator.value instanceof Array
 
-  if (!shuouldMapCollection) {
+  if (!shouldMapCollection) {
     return resolveEntity(
       store,
       resolveTransform,
diff --git a/packages/data-point/lib/reducer-path/factory.js b/packages/data-point/lib/reducer-path/factory.js
index 058f113..e13e765 100644
--- a/packages/data-point/lib/reducer-path/factory.js
+++ b/packages/data-point/lib/reducer-path/factory.js
@@ -13,7 +13,6 @@ const REDUCER_PATH = (module.exports.type = 'ReducerPath')
 function ReducerPath () {
   this.type = REDUCER_PATH
   this.name = ''
-  this.castAs = []
   this.asCollection = false
 }
 
@@ -33,12 +32,8 @@ module.exports.isPath = isPath
 function create (source) {
   const reducer = new ReducerPath()
 
-  const parts = source.split(':')
-
   reducer.asCollection = source.slice(-2) === '[]'
-  reducer.name = _.defaultTo(parts[0].substr(1), '.').replace(/\[]$/, '')
-  reducer.castAs = _.defaultTo(parts[1], '*')
-  reducer.params = parts.slice(2)
+  reducer.name = _.defaultTo(source.substr(1), '.').replace(/\[]$/, '')
 
   return Object.freeze(reducer)
 }
diff --git a/packages/data-point/lib/stores/entities.js b/packages/data-point/lib/stores/entities.js
index 950da05..0c019fc 100644
--- a/packages/data-point/lib/stores/entities.js
+++ b/packages/data-point/lib/stores/entities.js
@@ -12,8 +12,8 @@ function createEntity (entityTypes, source, id) {
   const tokens = id.split(':')
   const entityType = tokens[0]
   const EntityType = entityTypes.get(entityType)
-  const entitiy = EntityType.create(source, id)
-  return entitiy
+  const entity = EntityType.create(source, id)
+  return entity
 }
 
 module.exports.createEntity = createEntity
diff --git a/packages/data-point/lib/transform-expression/factory.js b/packages/data-point/lib/transform-expression/factory.js
index 2c66732..316abfc 100644
--- a/packages/data-point/lib/transform-expression/factory.js
+++ b/packages/data-point/lib/transform-expression/factory.js
@@ -7,13 +7,9 @@ const util = require('util')
 /**
  * Describes the transform parts used to reduce a context
  * @class
- * @property {string} context - initial context that will be passed on to each
- *                             reducer
  * @property {Array} reducers - collection of reducers that will be applied
- *                              to the context.
  */
 function TransformExpression () {
-  this.context = undefined
   this.reducers = []
   this.typeOf = 'TransformExpression'
 }


Test patch:
diff --git a/packages/data-point-service/lib/factory.test.js b/packages/data-point-service/lib/factory.test.js
index 1b9e4e5..995b6e1 100644
--- a/packages/data-point-service/lib/factory.test.js
+++ b/packages/data-point-service/lib/factory.test.js
@@ -24,7 +24,7 @@ describe('createServiceObject', () => {
       cache: null,
       cachePrefix: os.hostname(),
       dataPoint: null,
-      isCacheAvaiable: false,
+      isCacheAvailable: false,
       isCacheRequired: false,
       settings: {
         cache: {
@@ -46,7 +46,7 @@ describe('createServiceObject', () => {
       cache: null,
       cachePrefix: os.hostname(),
       dataPoint: null,
-      isCacheAvaiable: false,
+      isCacheAvailable: false,
       isCacheRequired: true,
       settings: {
         cache: {
@@ -104,19 +104,19 @@ describe('handleCacheError', () => {
     }).toThrowError('error')
   })
 
-  test('It should set isCacheAvaiable as false if not error not thrown', () => {
+  test('It should set isCacheAvailable as false if not error not thrown', () => {
     expect(
       Factory.handleCacheError(new Error(), {
         settings: {}
       })
-    ).toHaveProperty('isCacheAvaiable', false)
+    ).toHaveProperty('isCacheAvailable', false)
   })
 })
 
 describe('successCreateCache', () => {
   test('It should set flag and instance', () => {
     const result = Factory.successCreateCache(1, {})
-    expect(result).toHaveProperty('isCacheAvaiable', true)
+    expect(result).toHaveProperty('isCacheAvailable', true)
     expect(result).toHaveProperty('cache', 1)
   })
 })
@@ -131,7 +131,7 @@ describe('createCache', () => {
     return Factory.createCache(service)
       .catch(error => error)
       .then(result => {
-        expect(result).toHaveProperty('isCacheAvaiable', true)
+        expect(result).toHaveProperty('isCacheAvailable', true)
         expect(result).toHaveProperty('cache', 'cache')
       })
   })
@@ -146,16 +146,16 @@ describe('successDataPoint', () => {
 
 describe('bootstrapDataPoint', () => {
   saveRestoreLogs()
-  test('It should exit if isCacheAvaiable is false', () => {
-    const boostrapp = jest.fn()
-    Factory.bootstrapDataPoint(boostrapp, {})
-    expect(boostrapp).not.toBeCalled()
+  test('It should exit if isCacheAvailable is false', () => {
+    const bootstrap = jest.fn()
+    Factory.bootstrapDataPoint(bootstrap, {})
+    expect(bootstrap).not.toBeCalled()
   })
-  test('It should set bootstrap if isCacheAvaiable is true', () => {
-    const boostrapp = jest.fn()
-    const service = { isCacheAvaiable: true }
-    Factory.bootstrapDataPoint(boostrapp, { isCacheAvaiable: true })
-    expect(boostrapp).toBeCalledWith(service)
+  test('It should set bootstrap if isCacheAvailable is true', () => {
+    const bootstrap = jest.fn()
+    const service = { isCacheAvailable: true }
+    Factory.bootstrapDataPoint(bootstrap, { isCacheAvailable: true })
+    expect(bootstrap).toBeCalledWith(service)
   })
 })
 
diff --git a/packages/data-point/lib/reducer-path/factory.test.js b/packages/data-point/lib/reducer-path/factory.test.js
index 1c14373..6e2af07 100644
--- a/packages/data-point/lib/reducer-path/factory.test.js
+++ b/packages/data-point/lib/reducer-path/factory.test.js
@@ -13,25 +13,23 @@ describe('reducer/reducer-path#create', () => {
     const reducer = factory.create('$a')
     expect(reducer.type).toBe('ReducerPath')
     expect(reducer.name).toBe('a')
-    expect(reducer.castAs).toBe('*')
   })
 
-  it('path with casting type', () => {
-    const reducer = factory.create('$a:boolean')
-    expect(reducer.name).toBe('a')
-    expect(reducer.castAs).toBe('boolean')
+  it('compound path', () => {
+    const reducer = factory.create('$foo.bar')
+    expect(reducer.name).toBe('foo.bar')
+    expect(reducer.asCollection).toBe(false)
   })
 
-  it('path with casting type', () => {
-    const reducer = factory.create('$a:foo.bar')
-    expect(reducer.name).toBe('a')
-    expect(reducer.castAs).toBe('foo.bar')
+  it('compound path', () => {
+    const reducer = factory.create('$foo.bar[0]')
+    expect(reducer.name).toBe('foo.bar[0]')
+    expect(reducer.asCollection).toBe(false)
   })
 
   it('path with asCollection', () => {
     const reducer = factory.create('$foo.bar[]')
     expect(reducer.name).toBe('foo.bar')
-    expect(reducer.castAs).toBe('*')
     expect(reducer.asCollection).toBe(true)
   })
 })
diff --git a/packages/data-point/lib/reducer/factory.test.js b/packages/data-point/lib/reducer/factory.test.js
index e68894c..9dcf890 100644
--- a/packages/data-point/lib/reducer/factory.test.js
+++ b/packages/data-point/lib/reducer/factory.test.js
@@ -9,10 +9,9 @@ const ReducerEntity = require('../reducer-entity')
 
 describe('reducer#create', () => {
   test('create path', () => {
-    const reducer = Factory.create('$foo.bar[2]:int')
+    const reducer = Factory.create('$foo.bar[2]')
     expect(reducer.type).toBe(ReducerPath.type)
     expect(reducer.name).toBe('foo.bar[2]')
-    expect(reducer.castAs).toBe('int')
   })
 
   test('create function', () => {