@live-change/framework 0.8.22 → 0.8.24

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.
package/index.js CHANGED
@@ -16,6 +16,7 @@ App.rangeProperties = utils.rangeProperties
16
16
  App.encodeIdentifier = utils.encodeIdentifier
17
17
  App.extractRange = utils.extractRange
18
18
  App.isomorphic = utils.isomorphic
19
+ App.computeDefaults = utils.computeDefaults
19
20
 
20
21
  export default App
21
22
 
@@ -23,7 +23,7 @@ class LiveDao extends LcDao.DaoProxy {
23
23
  async refreshCredentials() {
24
24
  if(!this.started) return /// waiting for start
25
25
  const newCredentials = this.computeCredentials()
26
- if(JSON.stringify(newCredentials) != JSON.stringify(this.credentials)) {
26
+ if(JSON.stringify(newCredentials) !== JSON.stringify(this.credentials)) {
27
27
  this.credentials = newCredentials
28
28
  this.buildDao()
29
29
  }
@@ -68,7 +68,7 @@ class LiveDao extends LcDao.DaoProxy {
68
68
  await Promise.all(this.credentialsObservations.map(observation => observation.promise))
69
69
 
70
70
  const newCredentials = this.computeCredentials()
71
- if(JSON.stringify(newCredentials) != JSON.stringify(this.credentials)) {
71
+ if(JSON.stringify(newCredentials) !== JSON.stringify(this.credentials)) {
72
72
  this.credentials = newCredentials
73
73
  }
74
74
  this.buildDao()
@@ -23,16 +23,16 @@ async function preFilterParameters(parameters, definition) {
23
23
  }
24
24
 
25
25
  async function prepareParameter(parameter, prop, service) {
26
- if(prop.type == Object) {
26
+ if(prop.type === Object) {
27
27
  if(!parameter) return null
28
28
  return await prepareParameters(parameter, prop.properties)
29
29
  }
30
- if(prop.type == Array) {
30
+ if(prop.type === Array) {
31
31
  if(!parameter) return parameter
32
32
  if(!prop.of) return parameter
33
33
  return await Promise.all(parameter.map(item => prepareParameter(item, prop.of, service)))
34
34
  }
35
- if(prop.type == Date) {
35
+ if(prop.type === Date && parameter) {
36
36
  return new Date(parameter)
37
37
  }
38
38
  let modelName = getModelName(prop.type)
@@ -6,11 +6,11 @@ function nonEmpty(value) {
6
6
  if(!value.trim()) return 'empty'
7
7
  }
8
8
  if(Array.isArray(value)) {
9
- if(value.length == 0) return 'empty'
9
+ if(value.length === 0) return 'empty'
10
10
  } else if(value instanceof Date) {
11
11
  return
12
12
  } if(typeof value == 'object') {
13
- if(Object.keys(value).length == 0) return 'empty'
13
+ if(Object.keys(value).length === 0) return 'empty'
14
14
  }
15
15
  }
16
16
 
@@ -18,7 +18,7 @@ function getField(context, fieldName) {
18
18
  const propPath = context.propName ? context.propName.split('.') : []
19
19
  propPath.pop()
20
20
  let path
21
- if(fieldName[0] == '/') {
21
+ if(fieldName[0] === '/') {
22
22
  path = fieldName.slice(1).split('.')
23
23
  } else {
24
24
  path = propPath.concat(fieldName.split('.'))
package/lib/utils.js CHANGED
@@ -82,7 +82,7 @@ function crudChanges(oldElements, newElements, elementName, newParamName, params
82
82
  changes.push(...newElement.computeChanges(oldElement, params, newElementName))
83
83
  } else if(
84
84
  JSON.stringify({ ...oldElement, created: undefined })
85
- != JSON.stringify({ ...newElement, created: undefined })
85
+ !== JSON.stringify({ ...newElement, created: undefined })
86
86
  ) {
87
87
  let change = {
88
88
  operation: "delete"+elementName,
@@ -285,9 +285,30 @@ function isomorphic( v ) {
285
285
  }
286
286
  }
287
287
 
288
+ function computeDefaults(model, properties, context) {
289
+ const defaults = generateDefault(model.properties)
290
+ const result = {}
291
+ for(const propName in defaults) {
292
+ switch(typeof defaults[propName]) {
293
+ case 'function': {
294
+ result[propName] = defaults[propName](properties, context)
295
+ break
296
+ }
297
+ case 'object': {
298
+ result[propName] = defaults[propName] && computeDefaults(defaults[propName], properties[propName])
299
+ break
300
+ }
301
+ default: {
302
+ result[propName] = defaults[propName]
303
+ }
304
+ }
305
+ }
306
+ return JSON.parse(JSON.stringify(result))
307
+ }
308
+
288
309
  export {
289
310
  typeName, toJSON, setDifference, mapDifference, crudChanges,
290
311
  getProperty, setProperty, getField, setField, isObject, mergeDeep, generateDefault,
291
312
  prefixRange, rangeProperties, fieldListToFieldsObject,
292
- encodeIdentifier, extractRange, isomorphic
313
+ encodeIdentifier, extractRange, isomorphic, computeDefaults
293
314
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/framework",
3
- "version": "0.8.22",
3
+ "version": "0.8.24",
4
4
  "description": "Live Change Framework - ultimate solution for real time mobile/web apps",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -22,8 +22,8 @@
22
22
  },
23
23
  "homepage": "https://github.com/live-change/live-change-stack",
24
24
  "devDependencies": {
25
- "@live-change/dao": "^0.8.22",
26
- "@live-change/uid": "^0.8.22"
25
+ "@live-change/dao": "^0.8.24",
26
+ "@live-change/uid": "^0.8.24"
27
27
  },
28
- "gitHead": "70a56ac3dc54167a2d32ce47a00150e7a94bd04d"
28
+ "gitHead": "63e942caccbcb1c9bfbd1a3ef1d097124514c5a7"
29
29
  }