@live-change/framework 0.9.96 → 0.9.98
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.
|
@@ -16,6 +16,7 @@ export interface PropertyDefinitionSpecification {
|
|
|
16
16
|
items?: PropertyDefinitionSpecification
|
|
17
17
|
properties?: Record<string, PropertyDefinitionSpecification>,
|
|
18
18
|
validation?: ValidationSpecification[]
|
|
19
|
+
default?: any
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
class PropertyDefinition<T extends PropertyDefinitionSpecification> {
|
|
@@ -68,4 +68,27 @@ export default function(service, app) {
|
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
|
+
for(let triggerName in service.triggers) {
|
|
72
|
+
const triggers = service.triggers[triggerName]
|
|
73
|
+
for(let trigger of triggers) {
|
|
74
|
+
if(trigger.skipValidation && !trigger.validation) continue
|
|
75
|
+
const validators = getValidators(trigger, service, trigger)
|
|
76
|
+
if(Object.keys(validators).length > 0) {
|
|
77
|
+
console.log("T VALIDATION", trigger.name, validators)
|
|
78
|
+
const oldExecute = trigger.execute
|
|
79
|
+
trigger.execute = async (...args) => {
|
|
80
|
+
console.log("VALIDATION", trigger.name)
|
|
81
|
+
const context = args[1]
|
|
82
|
+
if(!trigger.skipValidation) {
|
|
83
|
+
await validate(args[0], validators, { source: trigger, trigger, service, app, ...context })
|
|
84
|
+
}
|
|
85
|
+
if(typeof trigger.validation === 'function') {
|
|
86
|
+
const result = await trigger.validation(args[0], { source: trigger, trigger, service, app, ...context })
|
|
87
|
+
if(result) throw result
|
|
88
|
+
}
|
|
89
|
+
return oldExecute.apply(trigger, args)
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
71
94
|
}
|
package/lib/runtime/params.js
CHANGED
|
@@ -43,6 +43,9 @@ async function prepareParameter(parameter, prop, service) {
|
|
|
43
43
|
return parameter
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
+
if(prop.default && typeof parameter === 'undefined') {
|
|
47
|
+
return prop.default
|
|
48
|
+
}
|
|
46
49
|
return parameter
|
|
47
50
|
}
|
|
48
51
|
|
|
@@ -54,6 +57,12 @@ async function prepareParameters(parameters, definition, service) {
|
|
|
54
57
|
out[propName] = prop ? await prepareParameter(parameters[propName], prop, service) : parameters[propName]
|
|
55
58
|
//console.log("PREP PROP", propName, prop, parameters[propName], out[propName])
|
|
56
59
|
}
|
|
60
|
+
for(let propName in definition) {
|
|
61
|
+
let prop = definition[propName]
|
|
62
|
+
if(prop.default && typeof out[propName] === 'undefined') {
|
|
63
|
+
out[propName] = prop.default
|
|
64
|
+
}
|
|
65
|
+
}
|
|
57
66
|
return out
|
|
58
67
|
}
|
|
59
68
|
|
|
@@ -84,8 +84,14 @@ class CommandQueue {
|
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
if(!handled) {
|
|
87
|
-
console.error(`Command handler ${this.tableName} for type ${command.type} not found`)
|
|
88
|
-
|
|
87
|
+
console.error(`Command handler ${this.tableName} for type ${command.type} not found`)
|
|
88
|
+
const result = await this.connection.request(['database', 'update'], this.database, this.tableName, command.id, [
|
|
89
|
+
{
|
|
90
|
+
op: 'merge', property: null,
|
|
91
|
+
value: { state: 'failed', error: `Command was not handled` }
|
|
92
|
+
}
|
|
93
|
+
])
|
|
94
|
+
return Promise.resolve(result)
|
|
89
95
|
}
|
|
90
96
|
return Promise.resolve(result).then(async result => {
|
|
91
97
|
const finished = new Date()
|
package/lib/utils/validation.js
CHANGED
|
@@ -69,14 +69,14 @@ async function validate(props, validators, context) {
|
|
|
69
69
|
}
|
|
70
70
|
propPromises[propNameAccumulator] = promises
|
|
71
71
|
} else {
|
|
72
|
+
if(data === null) return
|
|
72
73
|
if(path[pathIndex] === '#') {
|
|
73
74
|
for(let i = 0; i < data.length; i++) {
|
|
74
75
|
validateProperty(data[i], pathIndex + 1,
|
|
75
76
|
propNameAccumulator + (propNameAccumulator ? '.' : '') + i)
|
|
76
77
|
}
|
|
77
78
|
} else {
|
|
78
|
-
const deeper = data?.[path[pathIndex]]
|
|
79
|
-
if(deeper === null) return
|
|
79
|
+
const deeper = data?.[path[pathIndex]]
|
|
80
80
|
validateProperty(deeper, pathIndex + 1,
|
|
81
81
|
propNameAccumulator + (propNameAccumulator ? '.' : '') + path[pathIndex])
|
|
82
82
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/framework",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.98",
|
|
4
4
|
"description": "Live Change Framework - ultimate solution for real time mobile/web apps",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -22,11 +22,11 @@
|
|
|
22
22
|
},
|
|
23
23
|
"homepage": "https://github.com/live-change/live-change-stack",
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@live-change/dao": "^0.9.
|
|
26
|
-
"@live-change/uid": "^0.9.
|
|
25
|
+
"@live-change/dao": "^0.9.98",
|
|
26
|
+
"@live-change/uid": "^0.9.98",
|
|
27
27
|
"typedoc": "0.28.3",
|
|
28
28
|
"typedoc-plugin-markdown": "^4.6.3",
|
|
29
29
|
"typedoc-plugin-rename-defaults": "^0.7.3"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "a0e25c0ac835707d27763e56a2c20bd75d978583"
|
|
32
32
|
}
|