@live-change/framework 0.9.72 → 0.9.74
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/lib/definition/{ActionDefinition.js → ActionDefinition.ts} +20 -3
- package/lib/definition/{EventDefinition.js → EventDefinition.ts} +14 -3
- package/lib/definition/{ForeignIndexDefinition.js → ForeignIndexDefinition.ts} +3 -2
- package/lib/definition/{ForeignModelDefinition.js → ForeignModelDefinition.ts} +3 -1
- package/lib/definition/{IndexDefinition.js → IndexDefinition.ts} +14 -3
- package/lib/definition/{ModelDefinition.js → ModelDefinition.ts} +12 -2
- package/lib/definition/{PropertyDefinition.js → PropertyDefinition.ts} +13 -4
- package/lib/definition/{ServiceDefinition.js → ServiceDefinition.ts} +19 -10
- package/lib/definition/{TriggerDefinition.js → TriggerDefinition.ts} +11 -3
- package/lib/definition/ViewDefinition.ts +68 -0
- package/lib/definition/types.ts +12 -0
- package/package.json +4 -4
- package/lib/definition/ViewDefinition.js +0 -39
|
@@ -1,9 +1,26 @@
|
|
|
1
|
-
import PropertyDefinition from "./PropertyDefinition.js"
|
|
1
|
+
import PropertyDefinition, { PropertyDefinitionSpecification } from "./PropertyDefinition.js"
|
|
2
|
+
import { ExecutionContext } from "./types.js"
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
type ActionParameters = Record<string, any>
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
export interface ActionContext extends ExecutionContext {
|
|
7
|
+
action: any
|
|
8
|
+
emit: (event: any) => void
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface ActionDefinitionSpecification {
|
|
12
|
+
name: string
|
|
13
|
+
properties: Record<string, PropertyDefinitionSpecification>
|
|
14
|
+
returns: PropertyDefinitionSpecification,
|
|
15
|
+
execute: (parameters: ActionParameters, context: ActionContext, emit: (event: any) => void) => any
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
class ActionDefinition<T extends ActionDefinitionSpecification> {
|
|
19
|
+
[key: string]: any
|
|
20
|
+
|
|
21
|
+
constructor(definition: T) {
|
|
6
22
|
this.properties = {}
|
|
23
|
+
// @ts-ignore
|
|
7
24
|
for(let key in definition) this[key] = definition[key]
|
|
8
25
|
if(definition.properties) {
|
|
9
26
|
for (let propName in definition.properties) {
|
|
@@ -1,9 +1,20 @@
|
|
|
1
|
-
import PropertyDefinition from "./PropertyDefinition.js"
|
|
1
|
+
import PropertyDefinition, { PropertyDefinitionSpecification } from "./PropertyDefinition.js"
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
type EventParameters = Record<string, any>
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
export interface EventDefinitionSpecification {
|
|
6
|
+
name: string
|
|
7
|
+
properties: Record<string, PropertyDefinitionSpecification>
|
|
8
|
+
returns: PropertyDefinitionSpecification,
|
|
9
|
+
execute: (parameters: EventParameters) => any
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
class EventDefinition<T extends EventDefinitionSpecification> {
|
|
13
|
+
[key: string]: any
|
|
14
|
+
|
|
15
|
+
constructor(definition: T) {
|
|
6
16
|
this.properties = {}
|
|
17
|
+
// @ts-ignore
|
|
7
18
|
for(let key in definition) this[key] = definition[key]
|
|
8
19
|
if(definition.properties) {
|
|
9
20
|
for (let propName in definition.properties) {
|
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
|
|
2
|
-
|
|
2
|
+
export interface IndexDefinitionSpecification {
|
|
3
|
+
name: string
|
|
4
|
+
properties: Record<string, PropertyDefinition>
|
|
5
|
+
function: (...args: any[]) => any
|
|
6
|
+
search: boolean
|
|
7
|
+
storage: any
|
|
8
|
+
multi: boolean,
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
class IndexDefinition<T extends IndexDefinitionSpecification> {
|
|
12
|
+
[key: string]: any
|
|
3
13
|
|
|
4
|
-
constructor(definition) {
|
|
14
|
+
constructor(definition: T) {
|
|
5
15
|
this.properties = {}
|
|
16
|
+
// @ts-ignore
|
|
6
17
|
for(let key in definition) this[key] = definition[key]
|
|
7
18
|
}
|
|
8
19
|
|
|
@@ -16,7 +27,7 @@ class IndexDefinition {
|
|
|
16
27
|
computeChanges( oldIndexParam ) {
|
|
17
28
|
let oldIndex = JSON.parse(JSON.stringify(oldIndexParam))
|
|
18
29
|
oldIndex.indexes = oldIndex.indexes || {}
|
|
19
|
-
let changes = []
|
|
30
|
+
let changes: Record<string, any>[] = []
|
|
20
31
|
if(oldIndex.function !== `${this.function}`) {
|
|
21
32
|
changes.push({ operation: "deleteIndex", name: this.name })
|
|
22
33
|
changes.push({ operation: "createIndex", name: this.name, index: this.toJSON() })
|
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
import PropertyDefinition from "./PropertyDefinition.js"
|
|
2
|
+
import type { PropertyDefinitionSpecification } from "./PropertyDefinition.js"
|
|
3
|
+
import type { IndexDefinitionSpecification } from "./IndexDefinition.js"
|
|
2
4
|
import { crudChanges, definitionToJSON } from "../utils.js"
|
|
3
5
|
|
|
4
|
-
|
|
6
|
+
export interface ModelDefinitionSpecification {
|
|
7
|
+
name: string
|
|
8
|
+
properties: Record<string, PropertyDefinitionSpecification>
|
|
9
|
+
indexes: Record<string, IndexDefinitionSpecification>
|
|
10
|
+
onChange: (() => void)[]
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
class ModelDefinition<T extends ModelDefinitionSpecification> {
|
|
14
|
+
[key: string]: any
|
|
5
15
|
|
|
6
16
|
constructor(definition, serviceName) {
|
|
7
17
|
this.serviceName = serviceName
|
|
@@ -55,7 +65,7 @@ class ModelDefinition {
|
|
|
55
65
|
computeChanges( oldModelParam ) {
|
|
56
66
|
let oldModel = JSON.parse(JSON.stringify(oldModelParam))
|
|
57
67
|
oldModel.indexes = oldModel.indexes || {}
|
|
58
|
-
let changes = []
|
|
68
|
+
let changes: Record<string, any>[] = []
|
|
59
69
|
const json = this.toJSON()
|
|
60
70
|
changes.push(...crudChanges(oldModel.properties || {}, json.properties || {},
|
|
61
71
|
"Property", "property", { model: this.name }))
|
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
import { typeName, definitionToJSON } from "../utils.js"
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export interface PropertyDefinitionSpecification {
|
|
4
|
+
type: string
|
|
5
|
+
of?: PropertyDefinitionSpecification
|
|
6
|
+
items?: PropertyDefinitionSpecification
|
|
7
|
+
properties?: Record<string, PropertyDefinitionSpecification>
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
class PropertyDefinition<T extends PropertyDefinitionSpecification> {
|
|
11
|
+
[key: string]: any
|
|
4
12
|
|
|
5
|
-
constructor(definition) {
|
|
13
|
+
constructor(definition: T) {
|
|
14
|
+
// @ts-ignore
|
|
6
15
|
for(let key in definition) this[key] = definition[key]
|
|
7
16
|
if(definition.properties) {
|
|
8
17
|
for (let propName in definition.properties) {
|
|
@@ -24,7 +33,7 @@ class PropertyDefinition {
|
|
|
24
33
|
}
|
|
25
34
|
|
|
26
35
|
toJSON() {
|
|
27
|
-
let properties = undefined
|
|
36
|
+
let properties: Record<string, any> | undefined = undefined
|
|
28
37
|
if(this.properties) {
|
|
29
38
|
properties = {}
|
|
30
39
|
for (let propName in this.properties) {
|
|
@@ -47,7 +56,7 @@ class PropertyDefinition {
|
|
|
47
56
|
}
|
|
48
57
|
|
|
49
58
|
computeChanges( oldProperty, params, name) {
|
|
50
|
-
let changes = []
|
|
59
|
+
let changes: Record<string, any>[] = []
|
|
51
60
|
let typeChanged = false
|
|
52
61
|
if(typeName(this.type) !== typeName(oldProperty.type)) typeChanged = true
|
|
53
62
|
if((this.of && typeName(this.of.type)) !== (oldProperty.of && typeName(oldProperty.of.type)))
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import ModelDefinition from "./ModelDefinition.js"
|
|
1
|
+
import ModelDefinition, { ModelDefinitionSpecification } from "./ModelDefinition.js"
|
|
2
2
|
import ForeignModelDefinition from "./ForeignModelDefinition.js"
|
|
3
|
-
import IndexDefinition from "./IndexDefinition.js"
|
|
3
|
+
import IndexDefinition, { IndexDefinitionSpecification } from "./IndexDefinition.js"
|
|
4
4
|
import ForeignIndexDefinition from "./ForeignIndexDefinition.js"
|
|
5
5
|
import ActionDefinition from "./ActionDefinition.js"
|
|
6
|
-
import TriggerDefinition from "./TriggerDefinition.js"
|
|
7
|
-
import ViewDefinition from "./ViewDefinition.js"
|
|
6
|
+
import TriggerDefinition, { TriggerDefinitionSpecification } from "./TriggerDefinition.js"
|
|
7
|
+
import ViewDefinition, { ViewDefinitionSpecification } from "./ViewDefinition.js"
|
|
8
8
|
import EventDefinition from "./EventDefinition.js"
|
|
9
9
|
import defaultValidators from '../utils/validators.js'
|
|
10
10
|
import { crudChanges } from "../utils.js"
|
|
@@ -70,8 +70,16 @@ function createForeignIndexProxy(definition, model) {
|
|
|
70
70
|
})
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
interface ServiceDefinitionSpecification {
|
|
76
|
+
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
class ServiceDefinition<T extends ServiceDefinitionSpecification> {
|
|
80
|
+
[key: string]: any
|
|
81
|
+
|
|
82
|
+
constructor(definition: T) {
|
|
75
83
|
this.models = {}
|
|
76
84
|
this.foreignModels = {}
|
|
77
85
|
this.indexes = {}
|
|
@@ -89,10 +97,11 @@ class ServiceDefinition {
|
|
|
89
97
|
this.endpoints = []
|
|
90
98
|
this.validators = { ...defaultValidators }
|
|
91
99
|
this.clientSideFilters = []
|
|
100
|
+
// @ts-ignore
|
|
92
101
|
for(let key in definition) this[key] = definition[key]
|
|
93
102
|
}
|
|
94
103
|
|
|
95
|
-
model(definition) {
|
|
104
|
+
model<T extends ModelDefinitionSpecification>(definition: T) {
|
|
96
105
|
if(this.models[definition.name]) throw new Error('model ' + definition.name + ' already exists')
|
|
97
106
|
const model = new ModelDefinition(definition, this.name)
|
|
98
107
|
this.models[model.name] = model
|
|
@@ -132,14 +141,14 @@ class ServiceDefinition {
|
|
|
132
141
|
return event
|
|
133
142
|
}
|
|
134
143
|
|
|
135
|
-
view(definition) {
|
|
144
|
+
view<T extends ViewDefinitionSpecification>(definition: T) {
|
|
136
145
|
if(this.views[definition.name]) throw new Error('view ' + definition.name + ' already exists')
|
|
137
146
|
const view = new ViewDefinition(definition)
|
|
138
147
|
this.views[view.name] = view
|
|
139
148
|
return view
|
|
140
149
|
}
|
|
141
150
|
|
|
142
|
-
trigger(definition) {
|
|
151
|
+
trigger<T extends TriggerDefinitionSpecification>(definition: T) {
|
|
143
152
|
const trigger = new TriggerDefinition(definition)
|
|
144
153
|
//if(this.triggers[trigger.name]) throw new Error('trigger ' + trigger.name + ' already exists')
|
|
145
154
|
this.triggers[trigger.name] = [ ...(this.triggers[trigger.name] || []) , trigger ]
|
|
@@ -220,7 +229,7 @@ class ServiceDefinition {
|
|
|
220
229
|
|
|
221
230
|
computeChanges( oldModuleParam ) {
|
|
222
231
|
let oldModule = JSON.parse(JSON.stringify(oldModuleParam))
|
|
223
|
-
let changes = []
|
|
232
|
+
let changes: Record<string, any>[] = []
|
|
224
233
|
changes.push(...crudChanges(oldModule.models || {}, this.models || {},
|
|
225
234
|
"Model", "model", { }))
|
|
226
235
|
changes.push(...crudChanges(oldModule.indexes || {}, this.indexes || {},
|
|
@@ -1,9 +1,17 @@
|
|
|
1
|
-
import PropertyDefinition from "./PropertyDefinition.js"
|
|
1
|
+
import PropertyDefinition, { PropertyDefinitionSpecification } from "./PropertyDefinition.js"
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export interface TriggerDefinitionSpecification {
|
|
4
|
+
name: string
|
|
5
|
+
properties: Record<string, PropertyDefinitionSpecification>
|
|
6
|
+
returns: PropertyDefinitionSpecification
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
class TriggerDefinition<T extends TriggerDefinitionSpecification> {
|
|
10
|
+
[key: string]: any
|
|
4
11
|
|
|
5
|
-
constructor(definition) {
|
|
12
|
+
constructor(definition: T) {
|
|
6
13
|
this.properties = {}
|
|
14
|
+
// @ts-ignore
|
|
7
15
|
for(let key in definition) this[key] = definition[key]
|
|
8
16
|
if(definition.properties) {
|
|
9
17
|
for (let propName in definition.properties) {
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import PropertyDefinition, { PropertyDefinitionSpecification } from "./PropertyDefinition.js"
|
|
2
|
+
|
|
3
|
+
import type { ExecutionContext } from "./types.js"
|
|
4
|
+
|
|
5
|
+
export interface ViewDefinitionSpecificationBase {
|
|
6
|
+
name: string
|
|
7
|
+
properties: Record<string, PropertyDefinitionSpecification>
|
|
8
|
+
returns: PropertyDefinitionSpecification
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface ViewContext extends ExecutionContext {
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface ViewDefinitionSpecificationObservable extends ViewDefinitionSpecificationBase {
|
|
15
|
+
observable: (parameters: Record<string, any>, context: ViewContext) => any
|
|
16
|
+
get: (parameters: Record<string, any>, context: ViewContext) => Promise<any>
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface ViewDefinitionSpecificationDaoPath extends ViewDefinitionSpecificationBase {
|
|
20
|
+
daoPath: (parameters: Record<string, any>, context: ViewContext) => any[]
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface ViewDefinitionSpecificationFetch extends ViewDefinitionSpecificationBase {
|
|
24
|
+
fetch: (parameters: Record<string, any>, context: ViewContext) => Promise<any>
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type ViewDefinitionSpecification =
|
|
28
|
+
ViewDefinitionSpecificationObservable | ViewDefinitionSpecificationDaoPath | ViewDefinitionSpecificationFetch
|
|
29
|
+
|
|
30
|
+
class ViewDefinition<T extends ViewDefinitionSpecification> {
|
|
31
|
+
[key: string]: any
|
|
32
|
+
|
|
33
|
+
constructor(definition: T) {
|
|
34
|
+
this.properties = {}
|
|
35
|
+
// @ts-ignore
|
|
36
|
+
for(let key in definition) this[key] = definition[key]
|
|
37
|
+
if(definition.properties) {
|
|
38
|
+
for (let propName in definition.properties) {
|
|
39
|
+
const propDefn = definition.properties[propName]
|
|
40
|
+
this.createAndAddProperty(propName, propDefn)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if(definition.returns) {
|
|
44
|
+
this.returns = new PropertyDefinition(definition.returns)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
createAndAddProperty(name, definition) {
|
|
49
|
+
const property = new PropertyDefinition(definition)
|
|
50
|
+
this.properties[name] = property
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
toJSON() {
|
|
54
|
+
let properties = {}
|
|
55
|
+
for(let propName in this.properties) {
|
|
56
|
+
properties[propName] = this.properties[propName].toJSON()
|
|
57
|
+
}
|
|
58
|
+
let returns = this.returns ? this.returns.toJSON() : null
|
|
59
|
+
return {
|
|
60
|
+
... this,
|
|
61
|
+
properties,
|
|
62
|
+
returns
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export default ViewDefinition
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/framework",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.74",
|
|
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.9.
|
|
26
|
-
"@live-change/uid": "^0.9.
|
|
25
|
+
"@live-change/dao": "^0.9.74",
|
|
26
|
+
"@live-change/uid": "^0.9.74"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "cdb37d2051a08b4425fcb282dfd51a2c8f3112ba"
|
|
29
29
|
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import PropertyDefinition from "./PropertyDefinition.js"
|
|
2
|
-
|
|
3
|
-
class ViewDefinition {
|
|
4
|
-
|
|
5
|
-
constructor(definition) {
|
|
6
|
-
this.properties = {}
|
|
7
|
-
for(let key in definition) this[key] = definition[key]
|
|
8
|
-
if(definition.properties) {
|
|
9
|
-
for (let propName in definition.properties) {
|
|
10
|
-
const propDefn = definition.properties[propName]
|
|
11
|
-
this.createAndAddProperty(propName, propDefn)
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
if(definition.returns) {
|
|
15
|
-
this.returns = new PropertyDefinition(definition.returns)
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
createAndAddProperty(name, definition) {
|
|
20
|
-
const property = new PropertyDefinition(definition)
|
|
21
|
-
this.properties[name] = property
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
toJSON() {
|
|
25
|
-
let properties = {}
|
|
26
|
-
for(let propName in this.properties) {
|
|
27
|
-
properties[propName] = this.properties[propName].toJSON()
|
|
28
|
-
}
|
|
29
|
-
let returns = this.returns ? this.returns.toJSON() : null
|
|
30
|
-
return {
|
|
31
|
-
... this,
|
|
32
|
-
properties,
|
|
33
|
-
returns
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export default ViewDefinition
|