@live-change/framework 0.8.23 → 0.8.25
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/App.js +12 -12
- package/lib/processors/crudGenerator.js +1 -1
- package/lib/runtime/Service.js +5 -0
- package/lib/updaters/database.js +2 -1
- package/lib/utils.js +35 -12
- package/package.json +4 -4
package/index.js
CHANGED
package/lib/App.js
CHANGED
|
@@ -92,7 +92,7 @@ class App {
|
|
|
92
92
|
|
|
93
93
|
createServiceDefinition( definition ) {
|
|
94
94
|
const sourceConfig = this.config && this.config.services && this.config.services.find
|
|
95
|
-
&& this.config.services.find(c => c.name
|
|
95
|
+
&& this.config.services.find(c => c.name === definition.name)
|
|
96
96
|
const config = { ...sourceConfig, module: null }
|
|
97
97
|
return new ServiceDefinition({ ...definition, config })
|
|
98
98
|
}
|
|
@@ -111,7 +111,7 @@ class App {
|
|
|
111
111
|
processUse(sourceService)
|
|
112
112
|
//console.log("FOUND PROCESSORS", processors.length)
|
|
113
113
|
processors = processors.filter(function(item, pos, self) {
|
|
114
|
-
return self.indexOf(item)
|
|
114
|
+
return self.indexOf(item) === pos
|
|
115
115
|
})
|
|
116
116
|
processors = processors.map(p => {
|
|
117
117
|
if(typeof p == 'function') {
|
|
@@ -262,7 +262,7 @@ class App {
|
|
|
262
262
|
const triggers = service.triggers[data.type]
|
|
263
263
|
if(!triggers) return []
|
|
264
264
|
const result = await Promise.all(triggers.map(t => t.execute(data)))
|
|
265
|
-
if(!returnArray && Array.isArray(result) && result.length
|
|
265
|
+
if(!returnArray && Array.isArray(result) && result.length === 1) return result[0]
|
|
266
266
|
return result
|
|
267
267
|
}
|
|
268
268
|
if(!data.id) data.id = this.generateUid()
|
|
@@ -285,10 +285,10 @@ class App {
|
|
|
285
285
|
let observer
|
|
286
286
|
const promise = new Promise((resolve, reject) => {
|
|
287
287
|
observer = (signal, value) => {
|
|
288
|
-
if(signal
|
|
288
|
+
if(signal !== 'set') return reject('unknownSignal')
|
|
289
289
|
if(!value) return
|
|
290
|
-
if(value.state
|
|
291
|
-
if(value.state
|
|
290
|
+
if(value.state === 'done') return resolve(value.result)
|
|
291
|
+
if(value.state === 'failed') return reject(value.error)
|
|
292
292
|
}
|
|
293
293
|
objectObservable.observe(observer)
|
|
294
294
|
}).finally(() => {
|
|
@@ -297,7 +297,7 @@ class App {
|
|
|
297
297
|
await this.profileLog.endPromise(profileOp, promise)
|
|
298
298
|
|
|
299
299
|
const result = await promise
|
|
300
|
-
if(!returnArray && Array.isArray(result) && result.length
|
|
300
|
+
if(!returnArray && Array.isArray(result) && result.length === 1) return result[0]
|
|
301
301
|
return result
|
|
302
302
|
}
|
|
303
303
|
|
|
@@ -390,10 +390,10 @@ class App {
|
|
|
390
390
|
let observer
|
|
391
391
|
const promise = new Promise((resolve, reject) => {
|
|
392
392
|
observer = (signal, value) => {
|
|
393
|
-
if (signal
|
|
393
|
+
if (signal !== 'set') return reject('unknownSignal')
|
|
394
394
|
if (!value) return
|
|
395
|
-
if (value.state
|
|
396
|
-
if (value.state
|
|
395
|
+
if (value.state === 'done') return resolve(value.result)
|
|
396
|
+
if (value.state === 'failed') return reject(value.error)
|
|
397
397
|
}
|
|
398
398
|
objectObservable.observe(observer)
|
|
399
399
|
if (!requestTimeout) {
|
|
@@ -478,9 +478,9 @@ class App {
|
|
|
478
478
|
if(data.finished) {
|
|
479
479
|
finishedEvents = data.finished
|
|
480
480
|
if(finishedEvents.length >= events.length) {
|
|
481
|
-
const eventsNotDone = events.filter(event => data.finished.find(e => e.id
|
|
481
|
+
const eventsNotDone = events.filter(event => data.finished.find(e => e.id === event.id))
|
|
482
482
|
if(eventsNotDone.length !== 0) {
|
|
483
|
-
const eventsDone = events.filter(event => !data.finished.find(e => e.id
|
|
483
|
+
const eventsDone = events.filter(event => !data.finished.find(e => e.id === event.id))
|
|
484
484
|
console.error("waitForEvents - finished events does not match!")
|
|
485
485
|
console.error(" finished events:")
|
|
486
486
|
for(const event of eventsDone) {
|
|
@@ -48,7 +48,7 @@ export default function(service, app) {
|
|
|
48
48
|
return service._runtime.models[modelName]
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
const defaults = utils.
|
|
51
|
+
const defaults = utils.getDefaults(model.properties)
|
|
52
52
|
|
|
53
53
|
if(!service.events[genName("Created")]) { // Events:
|
|
54
54
|
service.event({
|
package/lib/runtime/Service.js
CHANGED
|
@@ -55,6 +55,11 @@ class Service {
|
|
|
55
55
|
|
|
56
56
|
this.triggers = {}
|
|
57
57
|
for(let triggerName in this.definition.triggers) {
|
|
58
|
+
if(!this.definition.triggers[triggerName].map) {
|
|
59
|
+
console.error("SERVICE", this.name,
|
|
60
|
+
"TRIGGER", triggerName, this.definition.triggers[triggerName])
|
|
61
|
+
process.exit(1)
|
|
62
|
+
}
|
|
58
63
|
this.triggers[triggerName] = this.definition.triggers[triggerName]
|
|
59
64
|
.map(trigger => new TriggerHandler( trigger, this ))
|
|
60
65
|
}
|
package/lib/updaters/database.js
CHANGED
|
@@ -211,7 +211,8 @@ async function update(changes, service, app, force) {
|
|
|
211
211
|
const table = generateTableName(change.model)
|
|
212
212
|
const property = change.property
|
|
213
213
|
let update = {}
|
|
214
|
-
|
|
214
|
+
const defaultValue = property.defaultValue ?? property.default
|
|
215
|
+
if(typeof defaultValue !== 'function') update[change.name] = defaultValue // functions not supported here
|
|
215
216
|
debug("CREATE PROPERTY UPDATE", update)
|
|
216
217
|
await dao.request(['database', 'query'], database, `(${
|
|
217
218
|
async (input, output, { table, update }) =>
|
package/lib/utils.js
CHANGED
|
@@ -177,17 +177,31 @@ function mergeDeep(target, ...sources) {
|
|
|
177
177
|
return mergeDeep(target, ...sources);
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
-
function
|
|
180
|
+
function getDefaults(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'))
|
|
185
184
|
if(property.hasOwnProperty('defaultValue')) {
|
|
186
185
|
result[propName] = property.defaultValue
|
|
187
186
|
} else if(property.hasOwnProperty('default')) {
|
|
188
187
|
result[propName] = property.default
|
|
189
188
|
} else if(property.type === Object) {
|
|
190
|
-
|
|
189
|
+
const defaults = getDefaults(property.properties)
|
|
190
|
+
if(Object.keys(defaults).length > 0) result[propName] = defaults
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return result
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function getUpdates(properties) {
|
|
197
|
+
let result = {}
|
|
198
|
+
for(const propName in properties) {
|
|
199
|
+
const property = properties[propName]
|
|
200
|
+
if(property.hasOwnProperty('updated')) {
|
|
201
|
+
result[propName] = property.updated
|
|
202
|
+
} else if(property.type === Object) {
|
|
203
|
+
const updates = getUpdates(property.properties)
|
|
204
|
+
if(Object.keys(updates).length > 0) result[propName] = updates
|
|
191
205
|
}
|
|
192
206
|
}
|
|
193
207
|
return result
|
|
@@ -286,30 +300,39 @@ function isomorphic( v ) {
|
|
|
286
300
|
}
|
|
287
301
|
}
|
|
288
302
|
|
|
289
|
-
function
|
|
290
|
-
const defaults = generateDefault(model.properties)
|
|
303
|
+
function computeValues(source, properties, context) {
|
|
291
304
|
const result = {}
|
|
292
|
-
for(const propName in
|
|
293
|
-
switch(typeof
|
|
305
|
+
for(const propName in source) {
|
|
306
|
+
switch(typeof source[propName]) {
|
|
294
307
|
case 'function': {
|
|
295
|
-
result[propName] =
|
|
308
|
+
result[propName] = source[propName](properties, context)
|
|
296
309
|
break
|
|
297
310
|
}
|
|
298
311
|
case 'object': {
|
|
299
|
-
result[propName] =
|
|
312
|
+
result[propName] = source[propName] && computeValues(source[propName], properties[propName], context)
|
|
300
313
|
break
|
|
301
314
|
}
|
|
302
315
|
default: {
|
|
303
|
-
result[propName] =
|
|
316
|
+
result[propName] = source[propName]
|
|
304
317
|
}
|
|
305
318
|
}
|
|
306
319
|
}
|
|
307
320
|
return JSON.parse(JSON.stringify(result))
|
|
308
321
|
}
|
|
309
322
|
|
|
323
|
+
function computeDefaults(model, properties, context) {
|
|
324
|
+
const defaults = getDefaults(model.properties)
|
|
325
|
+
return computeValues(defaults, properties, context)
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function computeUpdates(model, properties, context) {
|
|
329
|
+
const updates = getUpdates(model.properties)
|
|
330
|
+
return computeValues(updates, properties, context)
|
|
331
|
+
}
|
|
332
|
+
|
|
310
333
|
export {
|
|
311
334
|
typeName, toJSON, setDifference, mapDifference, crudChanges,
|
|
312
|
-
getProperty, setProperty, getField, setField, isObject, mergeDeep,
|
|
335
|
+
getProperty, setProperty, getField, setField, isObject, mergeDeep, getDefaults,
|
|
313
336
|
prefixRange, rangeProperties, fieldListToFieldsObject,
|
|
314
|
-
encodeIdentifier, extractRange, isomorphic, computeDefaults
|
|
337
|
+
encodeIdentifier, extractRange, isomorphic, computeDefaults, computeUpdates
|
|
315
338
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/framework",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.25",
|
|
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.25",
|
|
26
|
+
"@live-change/uid": "^0.8.25"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "1aa24b8ec3bfaa3576b72b514b2a97b061cb57fc"
|
|
29
29
|
}
|