@live-change/session-service 0.1.5 → 0.1.10
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/definition.js +4 -1
- package/package.json +3 -2
- package/sessionItem.js +21 -48
- package/sessionProperty.js +55 -57
package/definition.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
const App = require("@live-change/framework")
|
|
2
2
|
const app = App.app()
|
|
3
3
|
|
|
4
|
+
const relationsPlugin = require('@live-change/relations-plugin')
|
|
5
|
+
|
|
4
6
|
const definition = app.createServiceDefinition({
|
|
5
|
-
name: "session"
|
|
7
|
+
name: "session",
|
|
8
|
+
use: [ relationsPlugin ]
|
|
6
9
|
})
|
|
7
10
|
|
|
8
11
|
module.exports = definition
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/session-service",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.10",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"url": "https://www.viamage.com/"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"
|
|
24
|
+
"@live-change/framework": "^0.5.7",
|
|
25
|
+
"@live-change/relations-plugin": "^0.1.9"
|
|
25
26
|
}
|
|
26
27
|
}
|
package/sessionItem.js
CHANGED
|
@@ -12,7 +12,7 @@ definition.processor(function(service, app) {
|
|
|
12
12
|
if (model.properties.session) throw new Error('session property already exists!!!')
|
|
13
13
|
const originalModelProperties = {...model.properties}
|
|
14
14
|
const modelProperties = Object.keys(model.properties)
|
|
15
|
-
const defaults = App.utils.generateDefault(
|
|
15
|
+
const defaults = App.utils.generateDefault(model.properties)
|
|
16
16
|
const modelPropertyName = modelName.slice(0, 1).toLowerCase() + modelName.slice(1)
|
|
17
17
|
|
|
18
18
|
function modelRuntime() {
|
|
@@ -22,25 +22,15 @@ definition.processor(function(service, app) {
|
|
|
22
22
|
const config = model.sessionItem
|
|
23
23
|
const writeableProperties = modelProperties || config.writableProperties
|
|
24
24
|
|
|
25
|
-
console.log("
|
|
25
|
+
console.log("SESSION ITEM", model)
|
|
26
26
|
|
|
27
|
-
model.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
})
|
|
31
|
-
if(!model.indexes) model.indexes = {}
|
|
32
|
-
model.indexes.bySession = new IndexDefinition({
|
|
33
|
-
property: 'session'
|
|
34
|
-
})
|
|
35
|
-
for(const sortField of config.sortBy) {
|
|
36
|
-
const sortFieldUc = sortField.slice(0, 1).toUpperCase() + sortField.slice(1)
|
|
37
|
-
model.indexes['bySession' + sortFieldUc] = new IndexDefinition({
|
|
38
|
-
property: ['session', sortField]
|
|
39
|
-
})
|
|
27
|
+
model.propertyOf = {
|
|
28
|
+
what: Session,
|
|
29
|
+
...config
|
|
40
30
|
}
|
|
41
31
|
|
|
42
|
-
if(config.
|
|
43
|
-
const viewName = '
|
|
32
|
+
if(config.sessionReadAccess) {
|
|
33
|
+
const viewName = 'mySession' + modelName + 's'
|
|
44
34
|
service.views[viewName] = new ViewDefinition({
|
|
45
35
|
name: viewName,
|
|
46
36
|
access: config.readAccess,
|
|
@@ -52,7 +42,7 @@ definition.processor(function(service, app) {
|
|
|
52
42
|
})
|
|
53
43
|
for(const sortField of config.sortBy) {
|
|
54
44
|
const sortFieldUc = sortField.slice(0, 1).toUpperCase() + sortField.slice(1)
|
|
55
|
-
const viewName = '
|
|
45
|
+
const viewName = 'mySession' + modelName + 'sBy' + sortFieldUc
|
|
56
46
|
service.views[viewName] = new ViewDefinition({
|
|
57
47
|
name: viewName,
|
|
58
48
|
access: config.readAccess,
|
|
@@ -63,42 +53,25 @@ definition.processor(function(service, app) {
|
|
|
63
53
|
})
|
|
64
54
|
}
|
|
65
55
|
}
|
|
66
|
-
if(config.publicAccess) {
|
|
67
|
-
const viewName = 'publicSession' + modelName + 's'
|
|
68
|
-
service.views[viewName] = new ViewDefinition({
|
|
69
|
-
name: viewName,
|
|
70
|
-
access: config.publicAccess,
|
|
71
|
-
properties: App.rangeProperties,
|
|
72
|
-
daoPath(range, { client, context }) {
|
|
73
|
-
return modelRuntime().sortedIndexRangePath('bySession', [range.session], { ...range, session: undefined } )
|
|
74
|
-
}
|
|
75
|
-
})
|
|
76
|
-
for(const sorfField of config.sortBy) {
|
|
77
|
-
const sortFieldUc = sorfField.slice(0, 1).toUpperCase() + sortField.slice(1)
|
|
78
|
-
const viewName = 'publicSession' + modelName + 'sBy' + sortFieldUc
|
|
79
|
-
service.views[viewName] = new ViewDefinition({
|
|
80
|
-
name: viewName,
|
|
81
|
-
access: config.publicAccess,
|
|
82
|
-
properties: App.rangeProperties,
|
|
83
|
-
daoPath(range, { client, context }) {
|
|
84
|
-
return modelRuntime().sortedIndexRangePath('bySession' + sortFieldUc, [client.session], range )
|
|
85
|
-
}
|
|
86
|
-
})
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
56
|
|
|
90
|
-
if(config.
|
|
57
|
+
if(config.sessionCreateAccess || config.sessionWriteAccess) {
|
|
91
58
|
const eventName = 'session' + modelName + 'Created'
|
|
92
59
|
service.events[eventName] = new EventDefinition({
|
|
93
60
|
name: eventName,
|
|
94
61
|
execute(properties) {
|
|
95
|
-
const data = properties.data
|
|
96
62
|
const session = properties.session
|
|
97
63
|
const id = properties[modelPropertyName]
|
|
64
|
+
let newObject = {}
|
|
65
|
+
for(const propertyName of writeableProperties) {
|
|
66
|
+
if(properties.hasOwnProperty(propertyName)) {
|
|
67
|
+
newObject[propertyName] = properties[propertyName]
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const data = utils.mergeDeep({}, defaults, newObject)
|
|
98
71
|
return modelRuntime().create({ ...data, session, id })
|
|
99
72
|
}
|
|
100
73
|
})
|
|
101
|
-
const actionName = '
|
|
74
|
+
const actionName = 'createMySession' + modelName
|
|
102
75
|
service.actions[actionName] = new ActionDefinition({
|
|
103
76
|
name: actionName,
|
|
104
77
|
access: config.createAccess || config.writeAccess,
|
|
@@ -123,7 +96,7 @@ definition.processor(function(service, app) {
|
|
|
123
96
|
}
|
|
124
97
|
})
|
|
125
98
|
}
|
|
126
|
-
if(config.
|
|
99
|
+
if(config.sessionUpdateAccess || config.sessionWriteAccess) {
|
|
127
100
|
const eventName = 'session' + modelName + 'Updated'
|
|
128
101
|
service.events[eventName] = new EventDefinition({
|
|
129
102
|
name: eventName,
|
|
@@ -134,7 +107,7 @@ definition.processor(function(service, app) {
|
|
|
134
107
|
return modelRuntime().update(id, { ...data, id, session })
|
|
135
108
|
}
|
|
136
109
|
})
|
|
137
|
-
const actionName = '
|
|
110
|
+
const actionName = 'updateMySession' + modelName
|
|
138
111
|
service.actions[actionName] = new ActionDefinition({
|
|
139
112
|
name: actionName,
|
|
140
113
|
access: config.updateAccess || config.writeAccess,
|
|
@@ -181,10 +154,10 @@ definition.processor(function(service, app) {
|
|
|
181
154
|
return modelRuntime().delete(id)
|
|
182
155
|
}
|
|
183
156
|
})
|
|
184
|
-
const actionName = '
|
|
157
|
+
const actionName = 'deleteMySession' + modelName
|
|
185
158
|
service.actions[actionName] = new ActionDefinition({
|
|
186
159
|
name: actionName,
|
|
187
|
-
access: config.
|
|
160
|
+
access: config.deleteAccess || config.writeAccess,
|
|
188
161
|
properties: {
|
|
189
162
|
[modelPropertyName]: {
|
|
190
163
|
type: model,
|
package/sessionProperty.js
CHANGED
|
@@ -7,13 +7,15 @@ definition.processor(function(service, app) {
|
|
|
7
7
|
|
|
8
8
|
for(let modelName in service.models) {
|
|
9
9
|
const model = service.models[modelName]
|
|
10
|
+
console.log("SP", modelName)
|
|
10
11
|
|
|
11
12
|
if(model.sessionProperty) {
|
|
12
|
-
console.
|
|
13
|
+
console.log("MODEL " + modelName + " IS SESSION PROPERTY, CONFIG:", model.sessionProperty)
|
|
13
14
|
if (model.properties.session) throw new Error('session property already exists!!!')
|
|
15
|
+
|
|
14
16
|
const originalModelProperties = {...model.properties}
|
|
15
17
|
const modelProperties = Object.keys(model.properties)
|
|
16
|
-
const defaults = App.utils.generateDefault(
|
|
18
|
+
const defaults = App.utils.generateDefault(model.properties)
|
|
17
19
|
const modelPropertyName = modelName.slice(0, 1).toLowerCase() + modelName.slice(1)
|
|
18
20
|
|
|
19
21
|
function modelRuntime() {
|
|
@@ -21,6 +23,13 @@ definition.processor(function(service, app) {
|
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
const config = model.sessionProperty
|
|
26
|
+
const writeableProperties = modelProperties || config.writableProperties
|
|
27
|
+
|
|
28
|
+
model.propertyOf = {
|
|
29
|
+
what: Session,
|
|
30
|
+
...config
|
|
31
|
+
}
|
|
32
|
+
|
|
24
33
|
model.properties.session = new PropertyDefinition({
|
|
25
34
|
type: Session,
|
|
26
35
|
validation: ['nonEmpty']
|
|
@@ -29,72 +38,61 @@ definition.processor(function(service, app) {
|
|
|
29
38
|
model.indexes.bySession = new IndexDefinition({
|
|
30
39
|
property: 'session'
|
|
31
40
|
})
|
|
32
|
-
if(config.
|
|
33
|
-
const viewName = '
|
|
34
|
-
service.views[viewName] = new ViewDefinition({
|
|
35
|
-
name: viewName,
|
|
36
|
-
access: config.readAccess,
|
|
37
|
-
daoPath(params, {client, context}) {
|
|
38
|
-
return modelRuntime().indexObjectPath('bySession', client.session)
|
|
39
|
-
}
|
|
40
|
-
})
|
|
41
|
-
}
|
|
42
|
-
if(config.publicAccess) {
|
|
43
|
-
const viewName = 'publicSession' + modelName
|
|
41
|
+
if(config.sessionReadAccess) {
|
|
42
|
+
const viewName = 'mySession' + modelName
|
|
44
43
|
service.views[viewName] = new ViewDefinition({
|
|
45
44
|
name: viewName,
|
|
46
|
-
access: config.
|
|
47
|
-
daoPath(
|
|
48
|
-
return modelRuntime().
|
|
45
|
+
access: config.sessionReadAccess,
|
|
46
|
+
daoPath(params, { client, context }) {
|
|
47
|
+
return modelRuntime().path(client.session)
|
|
48
|
+
//return modelRuntime().indexObjectPath('bySession', client.session)
|
|
49
49
|
}
|
|
50
50
|
})
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
if(config.
|
|
54
|
-
const eventName = '
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
if(config.sessionSetAccess || config.sessionWriteAccess) {
|
|
54
|
+
const eventName = 'sessionOwned' + modelName + 'Set'
|
|
55
|
+
const actionName = 'setMySession' + modelName
|
|
56
|
+
service.actions[actionName] = new ActionDefinition({
|
|
57
|
+
name: actionName,
|
|
57
58
|
properties: {
|
|
58
59
|
...originalModelProperties
|
|
59
60
|
},
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const session = properties.session
|
|
63
|
-
return modelRuntime().create({...data, session, id: session})
|
|
64
|
-
}
|
|
65
|
-
})
|
|
66
|
-
const actionName = 'setSession' + modelName
|
|
67
|
-
service.actions[actionName] = new ActionDefinition({
|
|
68
|
-
name: actionName,
|
|
69
|
-
access: config.createAccess || config.writeAccess,
|
|
61
|
+
access: config.sessionSetAccess || config.sessionWriteAccess,
|
|
62
|
+
skipValidation: true,
|
|
70
63
|
queuedBy: (command) => command.client.session,
|
|
71
64
|
waitForEvents: true,
|
|
72
65
|
async execute(properties, {client, service}, emit) {
|
|
66
|
+
let newObject = {}
|
|
67
|
+
for(const propertyName of writeableProperties) {
|
|
68
|
+
if(properties.hasOwnProperty(propertyName)) {
|
|
69
|
+
newObject[propertyName] = properties[propertyName]
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const data = App.utils.mergeDeep({}, defaults, newObject)
|
|
73
|
+
await App.validation.validate(data, validators, { source: action, action, service, app, client })
|
|
73
74
|
emit({
|
|
74
75
|
type: eventName,
|
|
75
|
-
|
|
76
|
-
|
|
76
|
+
identifiers: {
|
|
77
|
+
session: client.session
|
|
78
|
+
},
|
|
79
|
+
data
|
|
77
80
|
})
|
|
78
81
|
}
|
|
79
82
|
})
|
|
83
|
+
const action = service.actions[actionName]
|
|
84
|
+
const validators = App.validation.getValidators(action, service, action)
|
|
80
85
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
execute(properties) {
|
|
86
|
-
const data = properties.data
|
|
87
|
-
const session = properties.session
|
|
88
|
-
return modelRuntime().update(session, { ...data, session, id: session })
|
|
89
|
-
}
|
|
90
|
-
})
|
|
91
|
-
const actionName = 'updateSession' + modelName
|
|
86
|
+
|
|
87
|
+
if(config.sessionUpdateAccess || config.sessionWriteAccess) {
|
|
88
|
+
const eventName = 'sessionOwned' + modelName + 'Updated'
|
|
89
|
+
const actionName = 'updateMySession' + modelName
|
|
92
90
|
service.actions[actionName] = new ActionDefinition({
|
|
93
91
|
name: actionName,
|
|
94
92
|
properties: {
|
|
95
93
|
...originalModelProperties
|
|
96
94
|
},
|
|
97
|
-
access: config.
|
|
95
|
+
access: config.sessionUpdateAccess || config.sessionWriteAccess,
|
|
98
96
|
skipValidation: true,
|
|
99
97
|
queuedBy: (command) => command.client.session,
|
|
100
98
|
waitForEvents: true,
|
|
@@ -111,7 +109,9 @@ definition.processor(function(service, app) {
|
|
|
111
109
|
await App.validation.validate(merged, validators, { source: action, action, service, app, client })
|
|
112
110
|
emit({
|
|
113
111
|
type: eventName,
|
|
114
|
-
|
|
112
|
+
identifiers: {
|
|
113
|
+
session: client.session
|
|
114
|
+
},
|
|
115
115
|
data: properties || {}
|
|
116
116
|
})
|
|
117
117
|
}
|
|
@@ -119,18 +119,13 @@ definition.processor(function(service, app) {
|
|
|
119
119
|
const action = service.actions[actionName]
|
|
120
120
|
const validators = App.validation.getValidators(action, service, action)
|
|
121
121
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
execute({session}) {
|
|
127
|
-
return modelRuntime().delete(session)
|
|
128
|
-
}
|
|
129
|
-
})
|
|
130
|
-
const actionName = 'resetSession' + modelName
|
|
122
|
+
|
|
123
|
+
if(config.sessionResetAccess || config.sessionWriteAccess) {
|
|
124
|
+
const eventName = 'sessionOwned' + modelName + 'Reset'
|
|
125
|
+
const actionName = 'resetMySession' + modelName
|
|
131
126
|
service.actions[actionName] = new ActionDefinition({
|
|
132
127
|
name: actionName,
|
|
133
|
-
access: config.
|
|
128
|
+
access: config.sessionResetAccess || config.sessionWriteAccess,
|
|
134
129
|
queuedBy: (command) => command.client.session,
|
|
135
130
|
waitForEvents: true,
|
|
136
131
|
async execute(properties, {client, service}, emit) {
|
|
@@ -138,11 +133,14 @@ definition.processor(function(service, app) {
|
|
|
138
133
|
if (!entity) throw new Error('not_found')
|
|
139
134
|
emit({
|
|
140
135
|
type: eventName,
|
|
141
|
-
|
|
136
|
+
identifiers: {
|
|
137
|
+
session: client.session
|
|
138
|
+
}
|
|
142
139
|
})
|
|
143
140
|
}
|
|
144
141
|
})
|
|
145
142
|
}
|
|
143
|
+
|
|
146
144
|
}
|
|
147
145
|
}
|
|
148
146
|
|