@live-change/user-service
Advanced tools
Comparing version 0.3.31 to 0.3.32
{ | ||
"name": "@live-change/user-service", | ||
"version": "0.3.31", | ||
"version": "0.3.32", | ||
"description": "", | ||
@@ -24,7 +24,7 @@ "main": "index.js", | ||
"dependencies": { | ||
"@live-change/framework": "0.7.33", | ||
"@live-change/relations-plugin": "0.7.33", | ||
"@live-change/framework": "0.7.34", | ||
"@live-change/relations-plugin": "0.7.34", | ||
"pluralize": "^8.0.0" | ||
}, | ||
"gitHead": "b45ed0b2217963bb2525da610366322d9b404d9c" | ||
"gitHead": "2fc30f1d4be9c78de081c0e18b3c706ed094b8d4" | ||
} |
@@ -157,9 +157,10 @@ const definition = require("./definition.js") | ||
const extendedIdentifiersProperties = createIdentifiersProperties(extendedWith) | ||
if(config.ownerReadAccess) { // single item view | ||
const viewName = 'my' + modelName | ||
const identifiers = createIdentifiersProperties(extendedWith) | ||
service.views[viewName] = new ViewDefinition({ | ||
name: viewName, | ||
properties: { | ||
...identifiers | ||
...extendedIdentifiersProperties | ||
}, | ||
@@ -190,3 +191,3 @@ access(params, context) { | ||
properties: { | ||
...identifiers, | ||
...extendedIdentifiersProperties, | ||
...App.rangeProperties, | ||
@@ -237,3 +238,4 @@ }, | ||
properties: { | ||
...originalModelProperties | ||
...originalModelProperties, | ||
...extendedIdentifiersProperties, | ||
}, | ||
@@ -245,2 +247,7 @@ access: config.ownerSetAccess || config.ownerWriteAccess, | ||
async execute(properties, {client, service}, emit) { | ||
const owner = client.user ? ['user_User', client.user] : ['session_Session', client.session] | ||
for(const extension of extendedWith) owner.push(properties[extension+'Type'], properties[extension]) | ||
const id = owner.map(p => JSON.stringify(p)).join(':') | ||
const entity = await modelRuntime().get(id) | ||
if(entity) throw 'alerady_exists' | ||
let newObject = {} | ||
@@ -261,2 +268,6 @@ for(const propertyName of writeableProperties) { | ||
} | ||
for(const key of extendedWith) { | ||
identifiers[key+'Type'] = properties[key+'Type'] | ||
identifiers[key]=properties[key] | ||
} | ||
emit({ | ||
@@ -279,3 +290,4 @@ type: eventName, | ||
properties: { | ||
...originalModelProperties | ||
...originalModelProperties, | ||
...extendedIdentifiersProperties, | ||
}, | ||
@@ -288,2 +300,3 @@ access: config.ownerUpdateAccess || config.ownerWriteAccess, | ||
const owner = client.user ? ['user_User', client.user] : ['session_Session', client.session] | ||
for(const extension of extendedWith) owner.push(properties[extension+'Type'], properties[extension]) | ||
const id = owner.map(p => JSON.stringify(p)).join(':') | ||
@@ -307,2 +320,6 @@ const entity = await modelRuntime().get(id) | ||
} | ||
for(const key of extendedWith) { | ||
identifiers[key+'Type'] = properties[key+'Type'] | ||
identifiers[key]=properties[key] | ||
} | ||
emit({ | ||
@@ -319,2 +336,65 @@ type: eventName, | ||
if((config.ownerUpdateAccess && config.ownerSetAccess) || config.ownerWriteAccess) { | ||
const setEventName = eventPrefix + modelName + 'Set' | ||
const updatedEventName = eventPrefix + modelName + 'Updated' | ||
const actionName = 'setOrUpdateMy' + modelName | ||
service.actions[actionName] = new ActionDefinition({ | ||
name: actionName, | ||
properties: { | ||
...originalModelProperties, | ||
...extendedIdentifiersProperties, | ||
}, | ||
access: config.ownerSetAccess || config.ownerWriteAccess, | ||
skipValidation: true, | ||
queuedBy: (command) => command.client.user ? 'u:'+command.client.user : 's:'+command.client.session, | ||
waitForEvents: true, | ||
async execute(properties, { client, service }, emit) { | ||
const owner = client.user ? ['user_User', client.user] : ['session_Session', client.session] | ||
for(const extension of extendedWith) owner.push(properties[extension+'Type'], properties[extension]) | ||
const id = owner.map(p => JSON.stringify(p)).join(':') | ||
const entity = await modelRuntime().get(id) | ||
let updateObject = {} | ||
for(const propertyName of writeableProperties) { | ||
if(properties.hasOwnProperty(propertyName)) { | ||
updateObject[propertyName] = properties[propertyName] | ||
} | ||
} | ||
const identifiers = client.user ? { | ||
sessionOrUserType: 'user_User', | ||
sessionOrUser: client.user, | ||
} : { | ||
sessionOrUserType: 'session_Session', | ||
sessionOrUser: client.session, | ||
} | ||
for(const key of extendedWith) { | ||
identifiers[key+'Type'] = properties[key+'Type'] | ||
identifiers[key]=properties[key] | ||
} | ||
if(!entity) { | ||
const data = App.utils.mergeDeep({}, defaults, updateObject) | ||
//console.log('V', { ...identifiers, ...data}, validators) | ||
await App.validation.validate({ ...identifiers, ...data}, validators, | ||
{ source: action, action, service, app, client }) | ||
emit({ | ||
type: setEventName, | ||
identifiers, | ||
data | ||
}) | ||
} else { | ||
const merged = App.utils.mergeDeep({}, entity, updateObject) | ||
//console.log('V', { ...identifiers, ...merged}, validators) | ||
await App.validation.validate({ ...identifiers, ...merged}, validators, | ||
{ source: action, action, service, app, client }) | ||
emit({ | ||
type: updatedEventName, | ||
identifiers, | ||
data: updateObject || {} | ||
}) | ||
} | ||
} | ||
}) | ||
const action = service.actions[actionName] | ||
const validators = App.validation.getValidators(action, service, action) | ||
} | ||
if(config.ownerResetAccess || config.ownerWriteAccess) { | ||
@@ -328,4 +408,8 @@ const eventName = eventPrefix + modelName + 'Reset' | ||
waitForEvents: true, | ||
properties: { | ||
...extendedIdentifiersProperties, | ||
}, | ||
async execute(properties, {client, service}, emit) { | ||
const owner = client.user ? ['user_User', client.user] : ['session_Session', client.session] | ||
for(const extension of extendedWith) owner.push(properties[extension+'Type'], properties[extension]) | ||
const id = owner.map(p => JSON.stringify(p)).join(':') | ||
@@ -341,2 +425,6 @@ const entity = await modelRuntime().get(id) | ||
} | ||
for(const key of extendedWith) { | ||
identifiers[key+'Type'] = properties[key+'Type'] | ||
identifiers[key]=properties[key] | ||
} | ||
emit({ | ||
@@ -343,0 +431,0 @@ type: eventName, |
75091
1853
+ Added@live-change/framework@0.7.34(transitive)
+ Added@live-change/relations-plugin@0.7.34(transitive)
- Removed@live-change/framework@0.7.33(transitive)
- Removed@live-change/relations-plugin@0.7.33(transitive)