@live-change/session-service 0.1.8 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/session-service",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
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.8"
25
+ "@live-change/relations-plugin": "^0.1.9"
26
26
  }
27
27
  }
package/sessionItem.js CHANGED
@@ -22,24 +22,14 @@ definition.processor(function(service, app) {
22
22
  const config = model.sessionItem
23
23
  const writeableProperties = modelProperties || config.writableProperties
24
24
 
25
- console.log("SESSIONM ITEM", model)
25
+ console.log("SESSION ITEM", model)
26
26
 
27
- model.properties.session = new PropertyDefinition({
28
- type: Session,
29
- validation: ['nonEmpty']
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.readAccess) {
32
+ if(config.sessionReadAccess) {
43
33
  const viewName = 'mySession' + modelName + 's'
44
34
  service.views[viewName] = new ViewDefinition({
45
35
  name: viewName,
@@ -63,31 +53,8 @@ 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.createAccess || config.writeAccess) {
57
+ if(config.sessionCreateAccess || config.sessionWriteAccess) {
91
58
  const eventName = 'session' + modelName + 'Created'
92
59
  service.events[eventName] = new EventDefinition({
93
60
  name: eventName,
@@ -129,7 +96,7 @@ definition.processor(function(service, app) {
129
96
  }
130
97
  })
131
98
  }
132
- if(config.updateAccess || config.writeAccess) {
99
+ if(config.sessionUpdateAccess || config.sessionWriteAccess) {
133
100
  const eventName = 'session' + modelName + 'Updated'
134
101
  service.events[eventName] = new EventDefinition({
135
102
  name: eventName,
@@ -51,18 +51,7 @@ definition.processor(function(service, app) {
51
51
  }
52
52
 
53
53
  if(config.sessionSetAccess || config.sessionWriteAccess) {
54
- const eventName = 'session' + modelName + 'Set'
55
- service.events[eventName] = new EventDefinition({
56
- name: eventName,
57
- properties: {
58
- ...originalModelProperties
59
- },
60
- execute(properties) {
61
- const data = properties.data
62
- const session = properties.session
63
- return modelRuntime().create({...data, session, id: session})
64
- }
65
- })
54
+ const eventName = 'sessionOwned' + modelName + 'Set'
66
55
  const actionName = 'setMySession' + modelName
67
56
  service.actions[actionName] = new ActionDefinition({
68
57
  name: actionName,
@@ -84,7 +73,9 @@ definition.processor(function(service, app) {
84
73
  await App.validation.validate(data, validators, { source: action, action, service, app, client })
85
74
  emit({
86
75
  type: eventName,
87
- session: client.session,
76
+ identifiers: {
77
+ session: client.session
78
+ },
88
79
  data
89
80
  })
90
81
  }
@@ -94,15 +85,7 @@ definition.processor(function(service, app) {
94
85
  }
95
86
 
96
87
  if(config.sessionUpdateAccess || config.sessionWriteAccess) {
97
- const eventName = 'session' + modelName + 'Updated'
98
- service.events[eventName] = new EventDefinition({
99
- name: eventName,
100
- execute(properties) {
101
- const data = properties.data
102
- const session = properties.session
103
- return modelRuntime().update(session, { ...data, session, id: session })
104
- }
105
- })
88
+ const eventName = 'sessionOwned' + modelName + 'Updated'
106
89
  const actionName = 'updateMySession' + modelName
107
90
  service.actions[actionName] = new ActionDefinition({
108
91
  name: actionName,
@@ -126,7 +109,9 @@ definition.processor(function(service, app) {
126
109
  await App.validation.validate(merged, validators, { source: action, action, service, app, client })
127
110
  emit({
128
111
  type: eventName,
129
- session: client.session,
112
+ identifiers: {
113
+ session: client.session
114
+ },
130
115
  data: properties || {}
131
116
  })
132
117
  }
@@ -136,13 +121,7 @@ definition.processor(function(service, app) {
136
121
  }
137
122
 
138
123
  if(config.sessionResetAccess || config.sessionWriteAccess) {
139
- const eventName = 'session' + modelName + 'Reset'
140
- service.events[eventName] = new EventDefinition({
141
- name: eventName,
142
- execute({session}) {
143
- return modelRuntime().delete(session)
144
- }
145
- })
124
+ const eventName = 'sessionOwned' + modelName + 'Reset'
146
125
  const actionName = 'resetMySession' + modelName
147
126
  service.actions[actionName] = new ActionDefinition({
148
127
  name: actionName,
@@ -154,7 +133,9 @@ definition.processor(function(service, app) {
154
133
  if (!entity) throw new Error('not_found')
155
134
  emit({
156
135
  type: eventName,
157
- session: client.session,
136
+ identifiers: {
137
+ session: client.session
138
+ }
158
139
  })
159
140
  }
160
141
  })