@live-change/framework 0.8.22 → 0.8.23
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 +1 -0
- package/lib/runtime/LiveDao.js +2 -2
- package/lib/runtime/params.js +3 -3
- package/lib/utils/validators.js +3 -3
- package/lib/utils.js +24 -2
- package/package.json +4 -4
package/index.js
CHANGED
package/lib/runtime/LiveDao.js
CHANGED
|
@@ -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)
|
|
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)
|
|
71
|
+
if(JSON.stringify(newCredentials) !== JSON.stringify(this.credentials)) {
|
|
72
72
|
this.credentials = newCredentials
|
|
73
73
|
}
|
|
74
74
|
this.buildDao()
|
package/lib/runtime/params.js
CHANGED
|
@@ -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
|
|
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
|
|
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
|
|
35
|
+
if(prop.type === Date && parameter) {
|
|
36
36
|
return new Date(parameter)
|
|
37
37
|
}
|
|
38
38
|
let modelName = getModelName(prop.type)
|
package/lib/utils/validators.js
CHANGED
|
@@ -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
|
|
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
|
|
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
|
-
|
|
85
|
+
!== JSON.stringify({ ...newElement, created: undefined })
|
|
86
86
|
) {
|
|
87
87
|
let change = {
|
|
88
88
|
operation: "delete"+elementName,
|
|
@@ -181,6 +181,7 @@ function generateDefault(properties) {
|
|
|
181
181
|
let result = {}
|
|
182
182
|
for(const propName in properties) {
|
|
183
183
|
const property = properties[propName]
|
|
184
|
+
console.log("GENERATE DEFAULT", propName, property, property.hasOwnProperty('defaultValue'), property.hasOwnProperty('default'))
|
|
184
185
|
if(property.hasOwnProperty('defaultValue')) {
|
|
185
186
|
result[propName] = property.defaultValue
|
|
186
187
|
} else if(property.hasOwnProperty('default')) {
|
|
@@ -285,9 +286,30 @@ function isomorphic( v ) {
|
|
|
285
286
|
}
|
|
286
287
|
}
|
|
287
288
|
|
|
289
|
+
function computeDefaults(model, properties, context) {
|
|
290
|
+
const defaults = generateDefault(model.properties)
|
|
291
|
+
const result = {}
|
|
292
|
+
for(const propName in defaults) {
|
|
293
|
+
switch(typeof defaults[propName]) {
|
|
294
|
+
case 'function': {
|
|
295
|
+
result[propName] = defaults[propName](properties, context)
|
|
296
|
+
break
|
|
297
|
+
}
|
|
298
|
+
case 'object': {
|
|
299
|
+
result[propName] = defaults[propName] && computeDefaults(defaults[propName], properties[propName])
|
|
300
|
+
break
|
|
301
|
+
}
|
|
302
|
+
default: {
|
|
303
|
+
result[propName] = defaults[propName]
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
return JSON.parse(JSON.stringify(result))
|
|
308
|
+
}
|
|
309
|
+
|
|
288
310
|
export {
|
|
289
311
|
typeName, toJSON, setDifference, mapDifference, crudChanges,
|
|
290
312
|
getProperty, setProperty, getField, setField, isObject, mergeDeep, generateDefault,
|
|
291
313
|
prefixRange, rangeProperties, fieldListToFieldsObject,
|
|
292
|
-
encodeIdentifier, extractRange, isomorphic
|
|
314
|
+
encodeIdentifier, extractRange, isomorphic, computeDefaults
|
|
293
315
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/framework",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.23",
|
|
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.
|
|
26
|
-
"@live-change/uid": "^0.8.
|
|
25
|
+
"@live-change/dao": "^0.8.23",
|
|
26
|
+
"@live-change/uid": "^0.8.23"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "581260523149a1e596f08e878b5f4fabeaba26ea"
|
|
29
29
|
}
|