@live-change/user-service 0.3.31 → 0.3.33

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/user-service",
3
- "version": "0.3.31",
3
+ "version": "0.3.33",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -21,9 +21,9 @@
21
21
  "url": "https://www.viamage.com/"
22
22
  },
23
23
  "dependencies": {
24
- "@live-change/framework": "0.7.33",
25
- "@live-change/relations-plugin": "0.7.33",
24
+ "@live-change/framework": "0.7.34",
25
+ "@live-change/relations-plugin": "0.7.34",
26
26
  "pluralize": "^8.0.0"
27
27
  },
28
- "gitHead": "b45ed0b2217963bb2525da610366322d9b404d9c"
28
+ "gitHead": "1e4c745cd39f0be282de95b0c936d49d4dc6363a"
29
29
  }
@@ -154,13 +154,14 @@ definition.processor(function(service, app) {
154
154
  }
155
155
  })
156
156
 
157
+ const extendedIdentifiersProperties = createIdentifiersProperties(extendedWith)
158
+
157
159
  if(config.ownerReadAccess) { // single item view
158
160
  const viewName = 'my' + modelName
159
- const identifiers = createIdentifiersProperties(extendedWith)
160
161
  service.views[viewName] = new ViewDefinition({
161
162
  name: viewName,
162
163
  properties: {
163
- ...identifiers
164
+ ...extendedIdentifiersProperties
164
165
  },
165
166
  access(params, context) {
166
167
  return config.ownerReadAccess ? config.ownerReadAccess(params, context) : true
@@ -186,7 +187,7 @@ definition.processor(function(service, app) {
186
187
  service.views[viewName] = new ViewDefinition({
187
188
  name: viewName,
188
189
  properties: {
189
- ...identifiers,
190
+ ...extendedIdentifiersProperties,
190
191
  ...App.rangeProperties,
191
192
  },
192
193
  access(params, context) {
@@ -232,13 +233,19 @@ definition.processor(function(service, app) {
232
233
  service.actions[actionName] = new ActionDefinition({
233
234
  name: actionName,
234
235
  properties: {
235
- ...originalModelProperties
236
+ ...originalModelProperties,
237
+ ...extendedIdentifiersProperties,
236
238
  },
237
239
  access: config.ownerSetAccess || config.ownerWriteAccess,
238
240
  skipValidation: true,
239
241
  queuedBy: (command) => command.client.user ? 'u:'+command.client.user : 's:'+command.client.session,
240
242
  waitForEvents: true,
241
243
  async execute(properties, {client, service}, emit) {
244
+ const owner = client.user ? ['user_User', client.user] : ['session_Session', client.session]
245
+ for(const extension of extendedWith) owner.push(properties[extension+'Type'], properties[extension])
246
+ const id = owner.map(p => JSON.stringify(p)).join(':')
247
+ const entity = await modelRuntime().get(id)
248
+ if(entity) throw 'alerady_exists'
242
249
  let newObject = {}
243
250
  for(const propertyName of writeableProperties) {
244
251
  if(properties.hasOwnProperty(propertyName)) {
@@ -254,6 +261,10 @@ definition.processor(function(service, app) {
254
261
  sessionOrUserType: 'session_Session',
255
262
  sessionOrUser: client.session,
256
263
  }
264
+ for(const key of extendedWith) {
265
+ identifiers[key+'Type'] = properties[key+'Type']
266
+ identifiers[key]=properties[key]
267
+ }
257
268
  emit({
258
269
  type: eventName,
259
270
  identifiers,
@@ -271,7 +282,8 @@ definition.processor(function(service, app) {
271
282
  service.actions[actionName] = new ActionDefinition({
272
283
  name: actionName,
273
284
  properties: {
274
- ...originalModelProperties
285
+ ...originalModelProperties,
286
+ ...extendedIdentifiersProperties,
275
287
  },
276
288
  access: config.ownerUpdateAccess || config.ownerWriteAccess,
277
289
  skipValidation: true,
@@ -279,6 +291,7 @@ definition.processor(function(service, app) {
279
291
  waitForEvents: true,
280
292
  async execute(properties, { client, service }, emit) {
281
293
  const owner = client.user ? ['user_User', client.user] : ['session_Session', client.session]
294
+ for(const extension of extendedWith) owner.push(properties[extension+'Type'], properties[extension])
282
295
  const id = owner.map(p => JSON.stringify(p)).join(':')
283
296
  const entity = await modelRuntime().get(id)
284
297
  if(!entity) throw 'not_found'
@@ -297,6 +310,10 @@ definition.processor(function(service, app) {
297
310
  sessionOrUserType: 'session_Session',
298
311
  sessionOrUser: client.session,
299
312
  }
313
+ for(const key of extendedWith) {
314
+ identifiers[key+'Type'] = properties[key+'Type']
315
+ identifiers[key]=properties[key]
316
+ }
300
317
  emit({
301
318
  type: eventName,
302
319
  identifiers,
@@ -308,6 +325,69 @@ definition.processor(function(service, app) {
308
325
  const validators = App.validation.getValidators(action, service, action)
309
326
  }
310
327
 
328
+ if((config.ownerUpdateAccess && config.ownerSetAccess) || config.ownerWriteAccess) {
329
+ const setEventName = eventPrefix + modelName + 'Set'
330
+ const updatedEventName = eventPrefix + modelName + 'Updated'
331
+ const actionName = 'setOrUpdateMy' + modelName
332
+ service.actions[actionName] = new ActionDefinition({
333
+ name: actionName,
334
+ properties: {
335
+ ...originalModelProperties,
336
+ ...extendedIdentifiersProperties,
337
+ },
338
+ access: config.ownerSetAccess || config.ownerWriteAccess,
339
+ skipValidation: true,
340
+ queuedBy: (command) => command.client.user ? 'u:'+command.client.user : 's:'+command.client.session,
341
+ waitForEvents: true,
342
+ async execute(properties, { client, service }, emit) {
343
+ const owner = client.user ? ['user_User', client.user] : ['session_Session', client.session]
344
+ for(const extension of extendedWith) owner.push(properties[extension+'Type'], properties[extension])
345
+ const id = owner.map(p => JSON.stringify(p)).join(':')
346
+ const entity = await modelRuntime().get(id)
347
+ let updateObject = {}
348
+ for(const propertyName of writeableProperties) {
349
+ if(properties.hasOwnProperty(propertyName)) {
350
+ updateObject[propertyName] = properties[propertyName]
351
+ }
352
+ }
353
+ const identifiers = client.user ? {
354
+ sessionOrUserType: 'user_User',
355
+ sessionOrUser: client.user,
356
+ } : {
357
+ sessionOrUserType: 'session_Session',
358
+ sessionOrUser: client.session,
359
+ }
360
+ for(const key of extendedWith) {
361
+ identifiers[key+'Type'] = properties[key+'Type']
362
+ identifiers[key]=properties[key]
363
+ }
364
+ if(!entity) {
365
+ const data = App.utils.mergeDeep({}, defaults, updateObject)
366
+ //console.log('V', { ...identifiers, ...data}, validators)
367
+ await App.validation.validate({ ...identifiers, ...data}, validators,
368
+ { source: action, action, service, app, client })
369
+ emit({
370
+ type: setEventName,
371
+ identifiers,
372
+ data
373
+ })
374
+ } else {
375
+ const merged = App.utils.mergeDeep({}, entity, updateObject)
376
+ //console.log('V', { ...identifiers, ...merged}, validators)
377
+ await App.validation.validate({ ...identifiers, ...merged}, validators,
378
+ { source: action, action, service, app, client })
379
+ emit({
380
+ type: updatedEventName,
381
+ identifiers,
382
+ data: updateObject || {}
383
+ })
384
+ }
385
+ }
386
+ })
387
+ const action = service.actions[actionName]
388
+ const validators = App.validation.getValidators(action, service, action)
389
+ }
390
+
311
391
  if(config.ownerResetAccess || config.ownerWriteAccess) {
312
392
  const eventName = eventPrefix + modelName + 'Reset'
313
393
  const actionName = 'resetMy' + modelName
@@ -316,8 +396,12 @@ definition.processor(function(service, app) {
316
396
  access: config.ownerResetAccess || config.ownerWriteAccess,
317
397
  queuedBy: (command) => command.client.user ? 'u:'+command.client.user : 's:'+command.client.session,
318
398
  waitForEvents: true,
399
+ properties: {
400
+ ...extendedIdentifiersProperties,
401
+ },
319
402
  async execute(properties, {client, service}, emit) {
320
403
  const owner = client.user ? ['user_User', client.user] : ['session_Session', client.session]
404
+ for(const extension of extendedWith) owner.push(properties[extension+'Type'], properties[extension])
321
405
  const id = owner.map(p => JSON.stringify(p)).join(':')
322
406
  const entity = await modelRuntime().get(id)
323
407
  if (!entity) throw 'not_found'
@@ -328,6 +412,10 @@ definition.processor(function(service, app) {
328
412
  sessionOrUserType: 'session_Session',
329
413
  sessionOrUser: client.session,
330
414
  }
415
+ for(const key of extendedWith) {
416
+ identifiers[key+'Type'] = properties[key+'Type']
417
+ identifiers[key]=properties[key]
418
+ }
331
419
  emit({
332
420
  type: eventName,
333
421
  identifiers