@live-change/framework 0.8.24 → 0.8.26
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 -11
- 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,7 +177,7 @@ 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]
|
|
@@ -186,7 +186,22 @@ function generateDefault(properties) {
|
|
|
186
186
|
} else if(property.hasOwnProperty('default')) {
|
|
187
187
|
result[propName] = property.default
|
|
188
188
|
} else if(property.type === Object) {
|
|
189
|
-
|
|
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
|
|
190
205
|
}
|
|
191
206
|
}
|
|
192
207
|
return result
|
|
@@ -285,30 +300,39 @@ function isomorphic( v ) {
|
|
|
285
300
|
}
|
|
286
301
|
}
|
|
287
302
|
|
|
288
|
-
function
|
|
289
|
-
const defaults = generateDefault(model.properties)
|
|
303
|
+
function computeValues(source, properties, context) {
|
|
290
304
|
const result = {}
|
|
291
|
-
for(const propName in
|
|
292
|
-
switch(typeof
|
|
305
|
+
for(const propName in source) {
|
|
306
|
+
switch(typeof source[propName]) {
|
|
293
307
|
case 'function': {
|
|
294
|
-
result[propName] =
|
|
308
|
+
result[propName] = source[propName](properties, context)
|
|
295
309
|
break
|
|
296
310
|
}
|
|
297
311
|
case 'object': {
|
|
298
|
-
result[propName] =
|
|
312
|
+
result[propName] = source[propName] && computeValues(source[propName], properties[propName], context)
|
|
299
313
|
break
|
|
300
314
|
}
|
|
301
315
|
default: {
|
|
302
|
-
result[propName] =
|
|
316
|
+
result[propName] = source[propName]
|
|
303
317
|
}
|
|
304
318
|
}
|
|
305
319
|
}
|
|
306
320
|
return JSON.parse(JSON.stringify(result))
|
|
307
321
|
}
|
|
308
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
|
+
|
|
309
333
|
export {
|
|
310
334
|
typeName, toJSON, setDifference, mapDifference, crudChanges,
|
|
311
|
-
getProperty, setProperty, getField, setField, isObject, mergeDeep,
|
|
335
|
+
getProperty, setProperty, getField, setField, isObject, mergeDeep, getDefaults,
|
|
312
336
|
prefixRange, rangeProperties, fieldListToFieldsObject,
|
|
313
|
-
encodeIdentifier, extractRange, isomorphic, computeDefaults
|
|
337
|
+
encodeIdentifier, extractRange, isomorphic, computeDefaults, computeUpdates
|
|
314
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.26",
|
|
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.26",
|
|
26
|
+
"@live-change/uid": "^0.8.26"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "e62696aa9fa6e5b86312dfb64c97efa300d41147"
|
|
29
29
|
}
|