@live-change/framework 0.9.162 → 0.9.164
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.ts +5 -2
- package/lib/App.js +4 -2
- package/lib/definition/QueryDefinition.ts +3 -2
- package/lib/definition/ViewDefinition.ts +1 -1
- package/lib/processors/queryExtensions.js +65 -0
- package/lib/runtime/Query.js +14 -39
- package/lib/runtime/Service.js +1 -0
- package/lib/updaters/database.js +5 -4
- package/package.json +4 -4
package/index.ts
CHANGED
|
@@ -12,6 +12,7 @@ import PropertyDefinition from './lib/definition/PropertyDefinition.js'
|
|
|
12
12
|
import ServiceDefinition from './lib/definition/ServiceDefinition.js'
|
|
13
13
|
import TriggerDefinition from './lib/definition/TriggerDefinition.js'
|
|
14
14
|
import ViewDefinition from './lib/definition/ViewDefinition.js'
|
|
15
|
+
import QueryDefinition from './lib/definition/QueryDefinition.js'
|
|
15
16
|
|
|
16
17
|
export {
|
|
17
18
|
ActionDefinition,
|
|
@@ -23,7 +24,8 @@ export {
|
|
|
23
24
|
PropertyDefinition,
|
|
24
25
|
ServiceDefinition,
|
|
25
26
|
TriggerDefinition,
|
|
26
|
-
ViewDefinition
|
|
27
|
+
ViewDefinition,
|
|
28
|
+
QueryDefinition
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
// Export all types from definition files
|
|
@@ -38,4 +40,5 @@ export type { ClientContext, ContextBase, ViewContext, ActionContext } from './l
|
|
|
38
40
|
export type { ServiceDefinitionSpecification } from './lib/definition/ServiceDefinition.js'
|
|
39
41
|
export type { AccessSpecification, AccessFunction } from './lib/processors/accessMethod.js'
|
|
40
42
|
export type { EventDefinitionSpecification as EventDefinitionSpecificationAC } from './lib/definition/EventDefinition.js'
|
|
41
|
-
export type
|
|
43
|
+
export type { QueryDefinitionSpecification } from './lib/definition/QueryDefinition.js'
|
|
44
|
+
export type * from './lib/definition/types.js'
|
package/lib/App.js
CHANGED
|
@@ -19,6 +19,7 @@ import fetchView from "./processors/fetchView.js"
|
|
|
19
19
|
import accessControl from "./processors/accessControl.js"
|
|
20
20
|
import autoValidation from "./processors/autoValidation.js"
|
|
21
21
|
import indexCode from "./processors/indexCode.js"
|
|
22
|
+
import queryExtensions from "./processors/queryExtensions.js"
|
|
22
23
|
|
|
23
24
|
import databaseUpdater from "./updaters/database.js"
|
|
24
25
|
|
|
@@ -53,11 +54,12 @@ class App {
|
|
|
53
54
|
|
|
54
55
|
this.defaultProcessors = [
|
|
55
56
|
indexListProcessor,
|
|
57
|
+
queryExtensions,
|
|
56
58
|
daoPathView,
|
|
57
|
-
fetchView,
|
|
59
|
+
fetchView,
|
|
58
60
|
accessControl,
|
|
59
61
|
autoValidation,
|
|
60
|
-
indexCode
|
|
62
|
+
indexCode
|
|
61
63
|
]
|
|
62
64
|
this.defaultUpdaters = [
|
|
63
65
|
databaseUpdater
|
|
@@ -13,9 +13,10 @@ export interface QueryDefinitionSpecification {
|
|
|
13
13
|
update: boolean,
|
|
14
14
|
|
|
15
15
|
validation?: (parameters: QueryParameters, context: ContextBase) => Promise<any>
|
|
16
|
-
waitForEvents?: boolean,
|
|
17
16
|
timeout?: number,
|
|
18
|
-
requestTimeout?: number
|
|
17
|
+
requestTimeout?: number,
|
|
18
|
+
|
|
19
|
+
config?: Record<string, any>
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
class QueryDefinition<T extends QueryDefinitionSpecification> {
|
|
@@ -12,7 +12,7 @@ export interface ViewDefinitionSpecificationBase {
|
|
|
12
12
|
global?: boolean,
|
|
13
13
|
access?: AccessSpecification,
|
|
14
14
|
skipValidation?: boolean,
|
|
15
|
-
validation? : (parameters: Record<string, any>, context: ViewContext) => Promise<any>
|
|
15
|
+
validation? : (parameters: Record<string, any>, context: ViewContext) => Promise<any>
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export interface ViewDefinitionSpecificationObservable extends ViewDefinitionSpecificationBase {
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
|
|
2
|
+
import * as utils from "../utils.js"
|
|
3
|
+
|
|
4
|
+
export default function(module, app) {
|
|
5
|
+
for(let queryName in module.queries) {
|
|
6
|
+
const query = module.queries[queryName]
|
|
7
|
+
if(query.view) {
|
|
8
|
+
if(query.update) throw new Error("Only non-update queries can have views")
|
|
9
|
+
module.view({
|
|
10
|
+
name: query.view?.name || queryName,
|
|
11
|
+
properties: query.properties,
|
|
12
|
+
returns: query.returns,
|
|
13
|
+
...query.view,
|
|
14
|
+
daoPath: (properties, { client }) => {
|
|
15
|
+
const runtime = module._runtime.queries[queryName]
|
|
16
|
+
return runtime.daoPath(properties)
|
|
17
|
+
}
|
|
18
|
+
})
|
|
19
|
+
}
|
|
20
|
+
if(query.trigger) {
|
|
21
|
+
if(query.update) throw new Error("Only non-update queries can have triggers")
|
|
22
|
+
module.trigger({
|
|
23
|
+
name: query.trigger?.name || queryName,
|
|
24
|
+
properties: query.properties,
|
|
25
|
+
returns: query.returns,
|
|
26
|
+
...query.trigger,
|
|
27
|
+
execute: (properties, { client, service, trigger }, emit) => {
|
|
28
|
+
emit({
|
|
29
|
+
type: query.event?.name || queryName,
|
|
30
|
+
properties
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
if(query.action) {
|
|
36
|
+
if(query.update) throw new Error("Only non-update queries can have actions")
|
|
37
|
+
module.action({
|
|
38
|
+
name: query.action?.name || queryName,
|
|
39
|
+
properties: query.properties,
|
|
40
|
+
returns: query.returns,
|
|
41
|
+
...query.action,
|
|
42
|
+
execute: (properties, { client, service, action }, emit) => {
|
|
43
|
+
emit({
|
|
44
|
+
type: query.event?.name || queryName,
|
|
45
|
+
properties
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
if(query.event || query.trigger || query.action) {
|
|
51
|
+
if(!query.update) throw new Error("Only update queries can have events")
|
|
52
|
+
module.event({
|
|
53
|
+
name: query.event?.name || queryName,
|
|
54
|
+
properties: query.properties,
|
|
55
|
+
returns: query.returns,
|
|
56
|
+
...query.event,
|
|
57
|
+
execute: (properties) => {
|
|
58
|
+
const runtime = module._runtime.queries[queryName]
|
|
59
|
+
return runtime.run(properties)
|
|
60
|
+
}
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
package/lib/runtime/Query.js
CHANGED
|
@@ -11,19 +11,10 @@ class Query {
|
|
|
11
11
|
this.codeString = typeof definition.code === 'function' ? `(${definition.code.toString()})` : definition.code
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
async run(parameters
|
|
14
|
+
async run(parameters) {
|
|
15
15
|
if(!this.definition.update) throw new Error("Only update queries can be run")
|
|
16
16
|
|
|
17
17
|
if(!parameters) parameters = {}
|
|
18
|
-
if(!context) context = {
|
|
19
|
-
client: {
|
|
20
|
-
session: null,
|
|
21
|
-
user: null,
|
|
22
|
-
ip: null,
|
|
23
|
-
roles: []
|
|
24
|
-
},
|
|
25
|
-
service: this.service,
|
|
26
|
-
}
|
|
27
18
|
|
|
28
19
|
let preparedParams = await prepareParameters(parameters, this.definition.properties, this.service)
|
|
29
20
|
|
|
@@ -37,47 +28,31 @@ class Query {
|
|
|
37
28
|
return resultPromise
|
|
38
29
|
}
|
|
39
30
|
|
|
40
|
-
|
|
41
|
-
if(this.definition.update) throw new Error("Only non-update queries can be get")
|
|
31
|
+
daoPath(parameters) {
|
|
32
|
+
if(this.definition.update) throw new Error("Only non-update queries can be get or observed")
|
|
42
33
|
|
|
43
34
|
if(!parameters) parameters = {}
|
|
44
|
-
if(!context) context = {
|
|
45
|
-
client: {
|
|
46
|
-
session: null,
|
|
47
|
-
user: null,
|
|
48
|
-
ip: null,
|
|
49
|
-
roles: []
|
|
50
|
-
},
|
|
51
|
-
service: this.service,
|
|
52
|
-
}
|
|
53
35
|
|
|
54
|
-
|
|
36
|
+
return [
|
|
55
37
|
'database', this.definition.isObjectQuery ? 'runQueryObject' : 'runQuery',
|
|
56
38
|
this.service.app.databaseName, 'queries', this.queryKey, parameters
|
|
57
|
-
]
|
|
39
|
+
]
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
get(parameters) {
|
|
43
|
+
if(this.definition.update) throw new Error("Only non-update queries can be get")
|
|
44
|
+
|
|
45
|
+
const resultPromise = this.service.app.dao.get(this.daoPath(parameters))
|
|
58
46
|
resultPromise.catch(error => {
|
|
59
47
|
console.error(`Query ${this.definition.name} error `, error.stack || error)
|
|
60
48
|
})
|
|
61
49
|
return resultPromise
|
|
62
50
|
}
|
|
63
51
|
|
|
64
|
-
observable(parameters
|
|
65
|
-
if(this.definition.update) throw new Error("Only non-update queries can be
|
|
66
|
-
if(!parameters) parameters = {}
|
|
67
|
-
if(!context) context = {
|
|
68
|
-
client: {
|
|
69
|
-
session: null,
|
|
70
|
-
user: null,
|
|
71
|
-
ip: null,
|
|
72
|
-
roles: []
|
|
73
|
-
},
|
|
74
|
-
service: this.service,
|
|
75
|
-
}
|
|
52
|
+
observable(parameters) {
|
|
53
|
+
if(this.definition.update) throw new Error("Only non-update queries can be observed")
|
|
76
54
|
|
|
77
|
-
const resultPromise = this.service.app.dao.observable(
|
|
78
|
-
'database', this.definition.isObjectQuery ? 'runQueryObject' : 'runQuery',
|
|
79
|
-
this.service.app.databaseName, 'queries', this.queryKey, parameters
|
|
80
|
-
])
|
|
55
|
+
const resultPromise = this.service.app.dao.observable(this.daoPath(parameters))
|
|
81
56
|
resultPromise.catch(error => {
|
|
82
57
|
console.error(`Query ${this.definition.name} error `, error.stack || error)
|
|
83
58
|
})
|
package/lib/runtime/Service.js
CHANGED
package/lib/updaters/database.js
CHANGED
|
@@ -180,7 +180,7 @@ async function update(changes, service, app, force) {
|
|
|
180
180
|
}).join(':')+'_'+(hash ? sha1(obj.id, 'base64') : obj.id),
|
|
181
181
|
to: obj.id
|
|
182
182
|
})
|
|
183
|
-
await input.table(table).onChange((obj, oldObj) =>
|
|
183
|
+
await input.table(table).onChange((obj, oldObj) =>
|
|
184
184
|
output.change(obj && mapper(obj), oldObj && mapper(oldObj)) )
|
|
185
185
|
}
|
|
186
186
|
const functionCode = `(${func})`
|
|
@@ -334,12 +334,13 @@ async function update(changes, service, app, force) {
|
|
|
334
334
|
const queryKey = service.name + '.' + query.name
|
|
335
335
|
await dao.requestWithSettings(updaterRequestSettings, ['database', 'put'], database, 'queries', {
|
|
336
336
|
id: queryKey,
|
|
337
|
-
code:
|
|
337
|
+
code: `(${query.code.toString()})`,
|
|
338
338
|
sourceName: query.sourceName,
|
|
339
339
|
update: query.update,
|
|
340
340
|
timeout: query.timeout,
|
|
341
341
|
properties: query.properties,
|
|
342
|
-
returns: query.returns
|
|
342
|
+
returns: query.returns,
|
|
343
|
+
...query.config
|
|
343
344
|
})
|
|
344
345
|
debug("QUERY CREATED!", query.name)
|
|
345
346
|
} break;
|
|
@@ -350,7 +351,7 @@ async function update(changes, service, app, force) {
|
|
|
350
351
|
const oldQuery = await dao.get(['database', 'get', database, 'queries', oldQueryKey])
|
|
351
352
|
await dao.requestWithSettings(updaterRequestSettings, ['database', 'put'], database, 'queries', {
|
|
352
353
|
id: queryKey,
|
|
353
|
-
code:
|
|
354
|
+
code: `(${oldQuery.code.toString()})`,
|
|
354
355
|
sourceName: oldQuery.sourceName,
|
|
355
356
|
update: oldQuery.update,
|
|
356
357
|
timeout: oldQuery.timeout,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/framework",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.164",
|
|
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.164",
|
|
26
|
+
"@live-change/uid": "^0.9.164",
|
|
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": "38f9fb8b01a9527d8f6036e174edd1fa41443301"
|
|
32
32
|
}
|