@live-change/relations-plugin 0.6.9 → 0.6.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/LICENSE.md ADDED
@@ -0,0 +1,11 @@
1
+ Copyright 2019-2022 Michał Łaszczewski
2
+
3
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
+
5
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6
+
7
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8
+
9
+ 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10
+
11
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/boundTo.js CHANGED
@@ -16,7 +16,7 @@ module.exports = function(service, app) {
16
16
  defineProperties(context.model, context.others, context.otherPropertyNames)
17
17
  defineIndex(context.model, context.joinedOthersClassName, context.otherPropertyNames)
18
18
 
19
- if(config.readAccess) {
19
+ if(config.readAccess || config.readAccessControl || config.writeAccessControl) {
20
20
  defineView({ ...config, access: config.readAccess }, context)
21
21
  }
22
22
  if(config.views) {
@@ -30,16 +30,16 @@ module.exports = function(service, app) {
30
30
  defineTransferredEvent(config, context, generateId)
31
31
  defineResetEvent(config, context, generateId)
32
32
 
33
- if(config.setAccess || config.writeAccess) {
33
+ if(config.setAccess || config.writeAccess || config.setAccessControl || config.writeAccessControl) {
34
34
  defineSetAction(config, context)
35
35
  }
36
36
 
37
- if(config.updateAccess || config.writeAccess) {
37
+ if(config.updateAccess || config.writeAccess || config.updateAccessControl || config.writeAccessControl) {
38
38
  defineUpdateAction(config, context)
39
39
  }
40
40
 
41
- if(config.resetAccess || config.writeAccess) {
41
+ if(config.resetAccess || config.writeAccess || config.resetAccessControl || config.writeAccessControl) {
42
42
  defineResetAction(config, context);
43
43
  }
44
44
  })
45
- }
45
+ }
package/boundToAny.js CHANGED
@@ -16,7 +16,7 @@ module.exports = function(service, app) {
16
16
  defineAnyProperties(context.model, context.otherPropertyNames)
17
17
  defineAnyIndex(context.model, context.joinedOthersClassName, context.otherPropertyNames)
18
18
 
19
- if(config.readAccess) {
19
+ if(config.readAccess || config.readAccessControl || config.writeAccessControl) {
20
20
  defineView({ ...config, access: config.readAccess }, context)
21
21
  }
22
22
  if(config.views) {
@@ -30,17 +30,17 @@ module.exports = function(service, app) {
30
30
  defineTransferredEvent(config, context, generateAnyId)
31
31
  defineResetEvent(config, context, generateAnyId)
32
32
 
33
- if(config.setAccess || config.writeAccess) {
33
+ if(config.setAccess || config.writeAccess || config.setAccessControl || config.writeAccessControl) {
34
34
  defineSetAction(config, context)
35
35
  }
36
36
 
37
- if(config.updateAccess || config.writeAccess) {
37
+ if(config.updateAccess || config.writeAccess || config.updateAccessControl || config.writeAccessControl) {
38
38
  defineUpdateAction(config, context)
39
39
  }
40
40
 
41
- if(config.resetAccess || config.writeAccess) {
41
+ if(config.resetAccess || config.writeAccess || config.resetAccessControl || config.writeAccessControl) {
42
42
  defineResetAction(config, context);
43
43
  }
44
44
 
45
45
  })
46
- }
46
+ }
package/entity.js CHANGED
@@ -118,7 +118,10 @@ function defineUpdateAction(config, context) {
118
118
  service.actions[actionName] = new ActionDefinition({
119
119
  name: actionName,
120
120
  properties: {
121
- ...(model.properties)
121
+ ...(model.properties),
122
+ [modelPropertyName]: {
123
+ type: modelPropertyName
124
+ }
122
125
  },
123
126
  access: config.updateAccess || config.writeAccess,
124
127
  accessControl: config.updateAccessControl || config.writeAccessControl,
@@ -153,7 +156,10 @@ function defineDeleteAction(config, context) {
153
156
  service.actions[actionName] = new ActionDefinition({
154
157
  name: actionName,
155
158
  properties: {
156
- ...(model.properties)
159
+ ...(model.properties),
160
+ [modelPropertyName]: {
161
+ type: modelPropertyName
162
+ }
157
163
  },
158
164
  access: config.deleteAccess || config.writeAccess,
159
165
  accessControl: config.deleteAccessControl || config.writeAccessControl,
@@ -205,7 +211,7 @@ module.exports = function(service, app) {
205
211
  otherPropertyNames, modelName, writeableProperties, annotation
206
212
  }
207
213
 
208
- if (config.readAccess) {
214
+ if (config.readAccess || config.readAccessControl || config.writeAccessControl) {
209
215
  defineView(config, context)
210
216
  }
211
217
  /// TODO: multiple views with limited fields
@@ -214,15 +220,15 @@ module.exports = function(service, app) {
214
220
  defineUpdatedEvent(config, context)
215
221
  defineDeletedEvent(config, context)
216
222
 
217
- if (config.createAccess || config.writeAccess) {
223
+ if (config.createAccess || config.writeAccess || config.createAccessControl || config.writeAccessControl) {
218
224
  defineCreateAction(config, context)
219
225
  }
220
226
 
221
- if (config.updateAccess || config.writeAccess) {
227
+ if (config.updateAccess || config.writeAccess || config.updateAccessControl || config.writeAccessControl) {
222
228
  defineUpdateAction(config, context)
223
229
  }
224
230
 
225
- if (config.deleteAccess || config.writeAccess) {
231
+ if (config.deleteAccess || config.writeAccess || config.deleteAccessControl || config.writeAccessControl) {
226
232
  defineDeleteAction(config, context)
227
233
  }
228
234
 
package/itemOf.js CHANGED
@@ -27,7 +27,7 @@ module.exports = function(service, app) {
27
27
  }
28
28
  }
29
29
 
30
- if(config.readAccess) {
30
+ if(config.readAccess || config.readAccessControl || config.writeAccessControl) {
31
31
  defineView(config, context)
32
32
  }
33
33
  /// TODO: multiple views with limited fields
@@ -37,15 +37,15 @@ module.exports = function(service, app) {
37
37
  defineTransferredEvent(config, context)
38
38
  defineDeletedEvent(config, context)
39
39
 
40
- if(config.createAccess || config.writeAccess) {
40
+ if(config.createAccess || config.writeAccess || config.createAccessControl || config.writeAccessControl) {
41
41
  defineCreateAction(config, context)
42
42
  }
43
43
 
44
- if(config.updateAccess || config.writeAccess) {
44
+ if(config.updateAccess || config.writeAccess || config.updateAccessControl || config.writeAccessControl) {
45
45
  defineUpdateAction(config, context)
46
46
  }
47
47
 
48
- if(config.deleteAccess || config.writeAccess) {
48
+ if(config.deleteAccess || config.writeAccess || config.deleteAccessControl || config.writeAccessControl) {
49
49
  defineDeleteAction(config, context)
50
50
  }
51
51
  })
package/itemOfAny.js CHANGED
@@ -27,7 +27,7 @@ module.exports = function(service, app) {
27
27
  }
28
28
  }
29
29
 
30
- if(config.readAccess) {
30
+ if(config.readAccess || config.writeAccess || config.readAccessControl || config.writeAccessControl) {
31
31
  defineView(config, context)
32
32
  // TODO: multiple views with all properties combinations
33
33
  }
@@ -38,15 +38,15 @@ module.exports = function(service, app) {
38
38
  defineTransferredEvent(config, context)
39
39
  defineDeletedEvent(config, context)
40
40
 
41
- if(config.createAccess || config.writeAccess) {
41
+ if(config.createAccess || config.writeAccess || config.createAccessControl || config.writeAccessControl) {
42
42
  defineCreateAction(config, context)
43
43
  }
44
44
 
45
- if(config.updateAccess || config.writeAccess) {
45
+ if(config.updateAccess || config.writeAccess || config.updateAccessControl || config.writeAccessControl) {
46
46
  defineUpdateAction(config, context)
47
47
  }
48
48
 
49
- if(config.deleteAccess || config.writeAccess) {
49
+ if(config.deleteAccess || config.writeAccess || config.deleteAccessControl || config.writeAccessControl) {
50
50
  defineDeleteAction(config, context)
51
51
  }
52
52
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/relations-plugin",
3
- "version": "0.6.9",
3
+ "version": "0.6.11",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -10,7 +10,7 @@
10
10
  "type": "git",
11
11
  "url": "git+https://github.com/live-change/live-change-framework.git"
12
12
  },
13
- "license": "MIT",
13
+ "license": "BSD-3-Clause",
14
14
  "bugs": {
15
15
  "url": "https://github.com/live-change/live-change-framework/issues"
16
16
  },
@@ -21,8 +21,8 @@
21
21
  "url": "https://www.viamage.com/"
22
22
  },
23
23
  "dependencies": {
24
- "@live-change/framework": "^0.6.9",
24
+ "@live-change/framework": "^0.6.11",
25
25
  "pluralize": "8.0.0"
26
26
  },
27
- "gitHead": "d3d3afb0342113502281c3ab0e362a3c76519df5"
27
+ "gitHead": "99d448214c2df44f42e5d25a08fa50ae79e5bdbe"
28
28
  }
@@ -21,6 +21,13 @@ function defineView(config, context) {
21
21
  validation: ['nonEmpty']
22
22
  })
23
23
  }
24
+ const accessControl = config.readAccessControl || config.writeAccessControl
25
+ if(typeof accessControl == 'object') {
26
+ accessControl.objects = accessControl.objects ?? ((params) => otherPropertyNames.map(name => ({
27
+ objectType: params[name + 'Type'],
28
+ object: params[name]
29
+ })))
30
+ }
24
31
  const viewName = joinedOthersPropertyName + context.reverseRelationWord + pluralize(modelName)
25
32
  service.views[viewName] = new ViewDefinition({
26
33
  name: viewName,
@@ -34,8 +41,8 @@ function defineView(config, context) {
34
41
  type: model
35
42
  }
36
43
  },
37
- access: config.readAccess,
38
- accessControl: config.readAccessControl || config.writeAccessControl,
44
+ access: config.readAccess || config.writeAccess,
45
+ accessControl,
39
46
  daoPath(properties, { client, context }) {
40
47
  const typeAndIdParts = extractTypeAndIdParts(otherPropertyNames, properties)
41
48
  const range = extractRange(properties)
package/propertyOf.js CHANGED
@@ -19,7 +19,7 @@ module.exports = function(service, app) {
19
19
  addAccessControlParents(context)
20
20
  defineIndex(context.model, context.joinedOthersClassName, context.otherPropertyNames)
21
21
 
22
- if(config.readAccess) {
22
+ if(config.readAccess || config.readAccessControl || config.writeAccessControl) {
23
23
  defineView({ ...config, access: config.readAccess }, context)
24
24
  }
25
25
  if(config.views) {
@@ -33,19 +33,20 @@ module.exports = function(service, app) {
33
33
  defineTransferredEvent(config, context, generateId)
34
34
  defineResetEvent(config, context, generateId)
35
35
 
36
- if(config.setAccess || config.writeAccess) {
36
+ if(config.setAccess || config.writeAccess || config.setAccessControl || config.writeAccessControl) {
37
37
  defineSetAction(config, context)
38
38
  }
39
39
 
40
- if(config.updateAccess || config.writeAccess) {
40
+ if(config.updateAccess || config.writeAccess || config.updateAccessControl || config.writeAccessControl) {
41
41
  defineUpdateAction(config, context)
42
42
  }
43
43
 
44
- if((config.setAccess && config.updateAccess) || config.writeAccess) {
44
+ if((config.setAccess && config.updateAccess) || config.writeAccess
45
+ || config.setOrUpdateAccessControl || config.writeAccessControl) {
45
46
  defineSetOrUpdateAction(config, context)
46
47
  }
47
48
 
48
- if(config.resetAccess || config.writeAccess) {
49
+ if(config.resetAccess || config.writeAccess || config.resetAccessControl || config.writeAccessControl) {
49
50
  defineResetAction(config, context);
50
51
  }
51
52
  })
package/propertyOfAny.js CHANGED
@@ -22,9 +22,11 @@ module.exports = function(service, app) {
22
22
  addAccessControlAnyParents(context)
23
23
  defineAnyIndexes(context.model, context.otherPropertyNames)
24
24
 
25
- if(config.readAccess) {
26
- defineObjectView({ ...config, access: config.readAccess }, context)
27
- defineRangeViews({ ...config, access: config.readAccess }, context)
25
+ if(config.singleAccess || config.readAccess || config.singleAccessControl || config.readAccessControl) {
26
+ defineObjectView(config, context)
27
+ }
28
+ if(config.listAccess || config.readAccess || config.listAccessControl || config.readAccessControl) {
29
+ defineRangeViews(config, context)
28
30
  }
29
31
  if(config.views) {
30
32
  for(const view of config.views) {
@@ -37,19 +39,20 @@ module.exports = function(service, app) {
37
39
  defineTransferredEvent(config, context, generateAnyId)
38
40
  defineResetEvent(config, context, generateAnyId)
39
41
 
40
- if(config.setAccess || config.writeAccess) {
42
+ if(config.setAccess || config.writeAccess || config.setAccessControl || config.writeAccessControl) {
41
43
  defineSetAction(config, context)
42
44
  }
43
45
 
44
- if(config.updateAccess || config.writeAccess) {
46
+ if(config.updateAccess || config.writeAccess || config.updateAccessControl || config.writeAccessControl) {
45
47
  defineUpdateAction(config, context)
46
48
  }
47
49
 
48
- if((config.setAccess && config.updateAccess) || config.writeAccess) {
50
+ if((config.setAccess && config.updateAccess) || config.writeAccess
51
+ || config.setOrUpdateAccessControl || config.writeAccessControl) {
49
52
  defineSetOrUpdateAction(config, context)
50
53
  }
51
54
 
52
- if(config.resetAccess || config.writeAccess) {
55
+ if(config.resetAccess || config.writeAccess || config.resetAccessControl || config.writeAccessControl) {
53
56
  defineResetAction(config, context);
54
57
  }
55
58
 
package/relatedTo.js CHANGED
@@ -26,7 +26,7 @@ module.exports = function(service, app) {
26
26
  }
27
27
  }
28
28
 
29
- if(config.readAccess) {
29
+ if(config.readAccess || config.readAccessControl || config.writeAccessControl) {
30
30
  defineView(config, context)
31
31
  }
32
32
  /// TODO: multiple views with limited fields
@@ -36,16 +36,16 @@ module.exports = function(service, app) {
36
36
  defineTransferredEvent(config, context)
37
37
  defineDeletedEvent(config, context)
38
38
 
39
- if(config.createAccess || config.writeAccess) {
39
+ if(config.createAccess || config.writeAccess || config.createAccessControl || config.writeAccessControl) {
40
40
  defineCreateAction(config, context)
41
41
  }
42
42
 
43
- if(config.updateAccess || config.writeAccess) {
43
+ if(config.updateAccess || config.writeAccess || config.updateAccessControl || config.writeAccessControl) {
44
44
  defineUpdateAction(config, context)
45
45
  }
46
46
 
47
- if(config.deleteAccess || config.writeAccess) {
47
+ if(config.deleteAccess || config.writeAccess || config.deleteAccessControl || config.writeAccessControl) {
48
48
  defineDeleteAction(config, context)
49
49
  }
50
50
  })
51
- }
51
+ }
package/relatedToAny.js CHANGED
@@ -26,7 +26,7 @@ module.exports = function(service, app) {
26
26
  }
27
27
  }
28
28
 
29
- if(config.readAccess) {
29
+ if(config.readAccess || config.readAccessControl || config.writeAccessControl) {
30
30
  defineView(config, context)
31
31
  }
32
32
  /// TODO: multiple views with limited fields
@@ -36,16 +36,16 @@ module.exports = function(service, app) {
36
36
  defineTransferredEvent(config, context)
37
37
  defineDeletedEvent(config, context)
38
38
 
39
- if(config.createAccess || config.writeAccess) {
39
+ if(config.createAccess || config.writeAccess || config.createAccessControl || config.writeAccessControl) {
40
40
  defineCreateAction(config, context)
41
41
  }
42
42
 
43
- if(config.updateAccess || config.writeAccess) {
43
+ if(config.updateAccess || config.writeAccess || config.updateAccessControl || config.writeAccessControl) {
44
44
  defineUpdateAction(config, context)
45
45
  }
46
46
 
47
- if(config.deleteAccess || config.writeAccess) {
47
+ if(config.deleteAccess || config.writeAccess || config.deleteAccessControl || config.writeAccessControl) {
48
48
  defineDeleteAction(config, context)
49
49
  }
50
50
  })
51
- }
51
+ }
@@ -35,6 +35,13 @@ function defineObjectView(config, context) {
35
35
  validation: ['nonEmpty']
36
36
  })
37
37
  }
38
+ const accessControl = config.singleAccessControl || config.readAccessControl || config.writeAccessControl
39
+ if(typeof accessControl == 'object') {
40
+ accessControl.objects = accessControl.objects ?? ((params) => otherPropertyNames.map(name => ({
41
+ objectType: params[name + 'Type'],
42
+ object: params[name]
43
+ })))
44
+ }
38
45
  const viewName = config.name || ((config.prefix ? (config.prefix + joinedOthersClassName) : joinedOthersPropertyName) +
39
46
  context.reverseRelationWord + modelName + (config.suffix || ''))
40
47
  service.views[viewName] = new ViewDefinition({
@@ -45,8 +52,8 @@ function defineObjectView(config, context) {
45
52
  returns: {
46
53
  type: model,
47
54
  },
48
- access: config.readAccess,
49
- accessControl: config.readAccessControl || config.writeAccessControl,
55
+ access: config.singleAccess || config.readAccess,
56
+ accessControl,
50
57
  daoPath(properties, { client, context }) {
51
58
  const typeAndIdParts = extractTypeAndIdParts(otherPropertyNames, properties)
52
59
  const id = typeAndIdParts.length > 1 ? typeAndIdParts.map(p => JSON.stringify(p)).join(':') : idParts[0]
@@ -73,9 +80,8 @@ function defineRangeViews(config, context) {
73
80
  ...identifiers,
74
81
  ...App.rangeProperties,
75
82
  },
76
- access(params, context) {
77
- return config.access ? config.access(params, context) : true
78
- },
83
+ access: config.listAccess || config.readAccess,
84
+ accessControl: config.listAccessControl || config.readAccessControl || config.writeAccessControl,
79
85
  daoPath(params, { client, context }) {
80
86
  const owner = []
81
87
  for (const key of combination) {
@@ -46,6 +46,7 @@ function defineSetAction(config, context) {
46
46
  ...(model.properties)
47
47
  },
48
48
  access: config.setAccess || config.writeAccess,
49
+ accessControl: config.setAccessControl || config.writeAccessControl,
49
50
  skipValidation: true,
50
51
  queuedBy: otherPropertyNames,
51
52
  waitForEvents: true,
@@ -77,6 +78,7 @@ function defineUpdateAction(config, context) {
77
78
  ...(model.properties)
78
79
  },
79
80
  access: config.updateAccess || config.writeAccess,
81
+ accessControl: config.updateAccessControl || config.writeAccessControl,
80
82
  skipValidation: true,
81
83
  queuedBy: otherPropertyNames,
82
84
  waitForEvents: true,
@@ -111,6 +113,7 @@ function defineSetOrUpdateAction(config, context) {
111
113
  ...(model.properties)
112
114
  },
113
115
  access: config.updateAccess || config.writeAccess,
116
+ accessControl: config.updateAccessControl || config.writeAccessControl,
114
117
  skipValidation: true,
115
118
  queuedBy: otherPropertyNames,
116
119
  waitForEvents: true,
@@ -147,6 +150,7 @@ function defineResetAction(config, context) {
147
150
  }
148
151
  },
149
152
  access: config.resetAccess || config.writeAccess,
153
+ accessControl: config.resetAccessControl || config.writeAccessControl,
150
154
  queuedBy: otherPropertyNames,
151
155
  waitForEvents: true,
152
156
  async execute(properties, { client, service }, emit) {