@live-change/session-service 0.1.10 → 0.1.11
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/package.json +2 -2
- package/sessionItem.js +26 -50
- package/sessionProperty.js +2 -2
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.11",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -22,6 +22,6 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@live-change/framework": "^0.5.7",
|
|
25
|
-
"@live-change/relations-plugin": "^0.1.
|
|
25
|
+
"@live-change/relations-plugin": "^0.1.10"
|
|
26
26
|
}
|
|
27
27
|
}
|
package/sessionItem.js
CHANGED
|
@@ -24,7 +24,7 @@ definition.processor(function(service, app) {
|
|
|
24
24
|
|
|
25
25
|
console.log("SESSION ITEM", model)
|
|
26
26
|
|
|
27
|
-
model.
|
|
27
|
+
model.itemOf = {
|
|
28
28
|
what: Session,
|
|
29
29
|
...config
|
|
30
30
|
}
|
|
@@ -33,7 +33,7 @@ definition.processor(function(service, app) {
|
|
|
33
33
|
const viewName = 'mySession' + modelName + 's'
|
|
34
34
|
service.views[viewName] = new ViewDefinition({
|
|
35
35
|
name: viewName,
|
|
36
|
-
access: config.
|
|
36
|
+
access: config.sessionReadAccess,
|
|
37
37
|
properties: App.rangeProperties,
|
|
38
38
|
daoPath(range, { client, context }) {
|
|
39
39
|
const path = modelRuntime().indexRangePath('bySession', [client.session], range )
|
|
@@ -55,26 +55,11 @@ definition.processor(function(service, app) {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
if(config.sessionCreateAccess || config.sessionWriteAccess) {
|
|
58
|
-
const eventName = '
|
|
59
|
-
service.events[eventName] = new EventDefinition({
|
|
60
|
-
name: eventName,
|
|
61
|
-
execute(properties) {
|
|
62
|
-
const session = properties.session
|
|
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)
|
|
71
|
-
return modelRuntime().create({ ...data, session, id })
|
|
72
|
-
}
|
|
73
|
-
})
|
|
58
|
+
const eventName = 'sessionOwned' + modelName + 'Created'
|
|
74
59
|
const actionName = 'createMySession' + modelName
|
|
75
60
|
service.actions[actionName] = new ActionDefinition({
|
|
76
61
|
name: actionName,
|
|
77
|
-
access: config.
|
|
62
|
+
access: config.sessionCreateAccess || config.sessionWriteAccess,
|
|
78
63
|
properties: {
|
|
79
64
|
...originalModelProperties,
|
|
80
65
|
[modelPropertyName]: {
|
|
@@ -82,14 +67,18 @@ definition.processor(function(service, app) {
|
|
|
82
67
|
validation: ['localId']
|
|
83
68
|
}
|
|
84
69
|
},
|
|
85
|
-
queuedBy: (command) => command.client.session,
|
|
70
|
+
//queuedBy: (command) => command.client.session,
|
|
86
71
|
waitForEvents: true,
|
|
87
72
|
async execute(properties, { client, service }, emit) {
|
|
88
73
|
const id = properties[modelPropertyName] || app.generateUid()
|
|
74
|
+
const entity = await modelRuntime().get(id)
|
|
75
|
+
if(entity) throw 'exists'
|
|
89
76
|
emit({
|
|
90
77
|
type: eventName,
|
|
91
78
|
[modelPropertyName]: id,
|
|
92
|
-
|
|
79
|
+
identifiers: {
|
|
80
|
+
session: client.session,
|
|
81
|
+
},
|
|
93
82
|
data: properties
|
|
94
83
|
})
|
|
95
84
|
return id
|
|
@@ -97,20 +86,11 @@ definition.processor(function(service, app) {
|
|
|
97
86
|
})
|
|
98
87
|
}
|
|
99
88
|
if(config.sessionUpdateAccess || config.sessionWriteAccess) {
|
|
100
|
-
const eventName = '
|
|
101
|
-
service.events[eventName] = new EventDefinition({
|
|
102
|
-
name: eventName,
|
|
103
|
-
execute(properties) {
|
|
104
|
-
const data = properties.data
|
|
105
|
-
const id = properties[modelPropertyName]
|
|
106
|
-
const session = properties.session
|
|
107
|
-
return modelRuntime().update(id, { ...data, id, session })
|
|
108
|
-
}
|
|
109
|
-
})
|
|
89
|
+
const eventName = 'sessionOwned' + modelName + 'Updated'
|
|
110
90
|
const actionName = 'updateMySession' + modelName
|
|
111
91
|
service.actions[actionName] = new ActionDefinition({
|
|
112
92
|
name: actionName,
|
|
113
|
-
access: config.
|
|
93
|
+
access: config.sessionUpdateAccess || config.sessionWriteAccess,
|
|
114
94
|
properties: {
|
|
115
95
|
...originalModelProperties,
|
|
116
96
|
[modelPropertyName]: {
|
|
@@ -123,8 +103,8 @@ definition.processor(function(service, app) {
|
|
|
123
103
|
waitForEvents: true,
|
|
124
104
|
async execute(properties, { client, service }, emit) {
|
|
125
105
|
const entity = await modelRuntime().get(properties[modelPropertyName])
|
|
126
|
-
if(!entity) throw
|
|
127
|
-
if(entity.session != client.session) throw
|
|
106
|
+
if(!entity) throw 'not_found'
|
|
107
|
+
if(entity.session != client.session) throw 'not_authorized'
|
|
128
108
|
let updateObject = {}
|
|
129
109
|
for(const propertyName of writeableProperties) {
|
|
130
110
|
if(properties.hasOwnProperty(propertyName)) {
|
|
@@ -132,12 +112,13 @@ definition.processor(function(service, app) {
|
|
|
132
112
|
}
|
|
133
113
|
}
|
|
134
114
|
const merged = App.utils.mergeDeep({}, entity, updateObject)
|
|
135
|
-
console.log("VALIDATE INTERNAL!!!!", merged)
|
|
136
115
|
await App.validation.validate(merged, validators, { source: action, action, service, app, client })
|
|
137
116
|
emit({
|
|
138
117
|
type: eventName,
|
|
139
118
|
[modelPropertyName]: entity.id,
|
|
140
|
-
|
|
119
|
+
identifiers: {
|
|
120
|
+
session: client.session,
|
|
121
|
+
},
|
|
141
122
|
data: properties
|
|
142
123
|
})
|
|
143
124
|
}
|
|
@@ -145,19 +126,12 @@ definition.processor(function(service, app) {
|
|
|
145
126
|
const action = service.actions[actionName]
|
|
146
127
|
const validators = App.validation.getValidators(action, service, action)
|
|
147
128
|
}
|
|
148
|
-
if(config.
|
|
149
|
-
const eventName = '
|
|
150
|
-
service.events[eventName] = new EventDefinition({
|
|
151
|
-
name: eventName,
|
|
152
|
-
execute(properties) {
|
|
153
|
-
const id = properties[modelPropertyName]
|
|
154
|
-
return modelRuntime().delete(id)
|
|
155
|
-
}
|
|
156
|
-
})
|
|
129
|
+
if(config.sessionDeleteAccess || config.sessionWriteAccess) {
|
|
130
|
+
const eventName = 'sessionOwned' + modelName + 'Deleted'
|
|
157
131
|
const actionName = 'deleteMySession' + modelName
|
|
158
132
|
service.actions[actionName] = new ActionDefinition({
|
|
159
133
|
name: actionName,
|
|
160
|
-
access: config.
|
|
134
|
+
access: config.sessionDeleteAccess || config.sessionWriteAccess,
|
|
161
135
|
properties: {
|
|
162
136
|
[modelPropertyName]: {
|
|
163
137
|
type: model,
|
|
@@ -168,12 +142,14 @@ definition.processor(function(service, app) {
|
|
|
168
142
|
waitForEvents: true,
|
|
169
143
|
async execute(properties, { client, service }, emit) {
|
|
170
144
|
const entity = await modelRuntime().get(properties[modelPropertyName])
|
|
171
|
-
if(!entity) throw
|
|
172
|
-
if(entity.session != client.session) throw
|
|
145
|
+
if(!entity) throw 'not_found'
|
|
146
|
+
if(entity.session != client.session) throw 'not_authorized'
|
|
173
147
|
emit({
|
|
174
148
|
type: eventName,
|
|
175
|
-
|
|
176
|
-
|
|
149
|
+
[modelPropertyName]: entity.id,
|
|
150
|
+
identifiers: {
|
|
151
|
+
session: client.session
|
|
152
|
+
}
|
|
177
153
|
})
|
|
178
154
|
}
|
|
179
155
|
})
|
package/sessionProperty.js
CHANGED
|
@@ -98,7 +98,7 @@ definition.processor(function(service, app) {
|
|
|
98
98
|
waitForEvents: true,
|
|
99
99
|
async execute(properties, { client, service }, emit) {
|
|
100
100
|
const entity = await modelRuntime().get(client.session)
|
|
101
|
-
if(!entity) throw
|
|
101
|
+
if(!entity) throw 'not_found'
|
|
102
102
|
let updateObject = {}
|
|
103
103
|
for(const propertyName of writeableProperties) {
|
|
104
104
|
if(properties.hasOwnProperty(propertyName)) {
|
|
@@ -130,7 +130,7 @@ definition.processor(function(service, app) {
|
|
|
130
130
|
waitForEvents: true,
|
|
131
131
|
async execute(properties, {client, service}, emit) {
|
|
132
132
|
const entity = await modelRuntime().indexObjectGet('bySession', client.session)
|
|
133
|
-
if (!entity) throw
|
|
133
|
+
if (!entity) throw 'not_found'
|
|
134
134
|
emit({
|
|
135
135
|
type: eventName,
|
|
136
136
|
identifiers: {
|