@live-change/relations-plugin 0.5.20 → 0.5.21

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/index.js CHANGED
@@ -14,4 +14,4 @@ module.exports = function(app, services) {
14
14
 
15
15
  }
16
16
 
17
- module.exports.processors = [ propertyOf, itemOf ]
17
+ module.exports.processors = [ propertyOf, itemOf, propertyOfAny, itemOfAny ]
package/itemOf.js CHANGED
@@ -6,6 +6,8 @@ const {
6
6
  processModelsAnnotation
7
7
  } = require('./utils.js')
8
8
 
9
+ const pluralize = require('pluralize')
10
+
9
11
  function defineView(config, context) {
10
12
  const { service, modelRuntime, otherPropertyNames, joinedOthersPropertyName, joinedOthersClassName,
11
13
  modelName, others, model } = context
@@ -17,7 +19,7 @@ function defineView(config, context) {
17
19
  validation: ['nonEmpty']
18
20
  })
19
21
  }
20
- const viewName = joinedOthersPropertyName + 'Owned' + modelName + 's'
22
+ const viewName = joinedOthersPropertyName + 'Owned' + pluralize(modelName)
21
23
  service.views[viewName] = new ViewDefinition({
22
24
  name: viewName,
23
25
  properties: {
@@ -184,7 +186,7 @@ module.exports = function(service, app) {
184
186
  defineTransferredEvent(config, context)
185
187
  defineDeletedEvent(config, context)
186
188
 
187
- if(config.setAccess || config.writeAccess) {
189
+ if(config.createAccess || config.writeAccess) {
188
190
  defineCreateAction(config, context)
189
191
  }
190
192
 
package/itemOfAny.js CHANGED
@@ -10,6 +10,8 @@ const {
10
10
  processModelsAnyAnnotation
11
11
  } = require('./utilsAny.js')
12
12
 
13
+ const pluralize = require('pluralize')
14
+
13
15
  function defineView(config, context) {
14
16
  const { service, modelRuntime, otherPropertyNames, joinedOthersPropertyName, joinedOthersClassName,
15
17
  modelName, others, model } = context
@@ -25,7 +27,7 @@ function defineView(config, context) {
25
27
  validation: ['nonEmpty']
26
28
  })
27
29
  }
28
- const viewName = joinedOthersPropertyName + 'Owned' + modelName + 's'
30
+ const viewName = joinedOthersPropertyName + 'Owned' + pluralize(modelName)
29
31
  service.views[viewName] = new ViewDefinition({
30
32
  name: viewName,
31
33
  properties: {
@@ -172,6 +174,7 @@ function defineSortIndex(context, sortFields) {
172
174
 
173
175
  module.exports = function(service, app) {
174
176
  processModelsAnyAnnotation(service, app, 'itemOfAny', (config, context) => {
177
+ console.log("ITEM OF ANY", config)
175
178
 
176
179
  defineAnyProperties(context.model, context.otherPropertyNames)
177
180
  defineAnyIndex(context.model, context.joinedOthersClassName, context.otherPropertyNames)
@@ -192,7 +195,7 @@ module.exports = function(service, app) {
192
195
  defineTransferredEvent(config, context)
193
196
  defineDeletedEvent(config, context)
194
197
 
195
- if(config.setAccess || config.writeAccess) {
198
+ if(config.createAccess || config.writeAccess) {
196
199
  defineCreateAction(config, context)
197
200
  }
198
201
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/relations-plugin",
3
- "version": "0.5.20",
3
+ "version": "0.5.21",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -21,7 +21,8 @@
21
21
  "url": "https://www.viamage.com/"
22
22
  },
23
23
  "dependencies": {
24
- "@live-change/framework": "^0.5.20"
24
+ "@live-change/framework": "^0.5.21",
25
+ "pluralize": "8.0.0"
25
26
  },
26
- "gitHead": "d37be156c4f76af3ead4ad0aae3f80281191bf57"
27
+ "gitHead": "00708b95082fc8c701e5ca32b9063c88a2c02a34"
27
28
  }
package/propertyOfAny.js CHANGED
@@ -52,6 +52,7 @@ function defineSetAction(config, context) {
52
52
  service, app, model, defaults,
53
53
  otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName
54
54
  } = context
55
+
55
56
  const eventName = joinedOthersPropertyName + 'Owned' + modelName + 'Set'
56
57
  const actionName = 'set' + joinedOthersClassName + 'Owned' + modelName
57
58
  service.actions[actionName] = new ActionDefinition({
@@ -144,7 +145,7 @@ function defineResetAction(config, context) {
144
145
 
145
146
 
146
147
  module.exports = function(service, app) {
147
- processModelsAnyAnnotation(service, app, 'propertyOf', (config, context) => {
148
+ processModelsAnyAnnotation(service, app, 'propertyOfAny', (config, context) => {
148
149
 
149
150
  defineAnyProperties(context.model, context.otherPropertyNames)
150
151
  defineAnyIndex(context.model, context.joinedOthersClassName, context.otherPropertyNames)
package/utilsAny.js CHANGED
@@ -27,7 +27,7 @@ function generateAnyId(otherPropertyNames, properties) {
27
27
  }
28
28
 
29
29
  function defineAnyProperties(model, names) {
30
- for (let i = 0; i < types.length; i++) {
30
+ for (let i = 0; i < names.length; i++) {
31
31
  model.properties[names[i]] = new PropertyDefinition({
32
32
  type: String,
33
33
  validation: ['nonEmpty']
@@ -70,15 +70,15 @@ function processModelsAnyAnnotation(service, app, annotation, cb) {
70
70
  if (!model.indexes) model.indexes = {}
71
71
 
72
72
  let config = model[annotation] // only single ownership is possible, but may be owned by objects set
73
- if (typeof config == 'string' || Array.isArray(config)) config = {what: config}
73
+ if (typeof config == 'string' || Array.isArray(config)) config = { what: config }
74
74
 
75
75
  console.log("MODEL " + modelName + " IS "+ annotation +" " + config.what)
76
76
 
77
- const otherPropertyNames = (Array.isArray(config.to) ? config.to : [config.to ?? 'owner'])
77
+ const otherPropertyNames = (Array.isArray(config.to) ? config.to : [ config.to ?? 'owner' ])
78
78
  .map(other => other.name ? other.name : other)
79
79
 
80
80
  const writeableProperties = modelProperties || config.writeableProperties
81
- const others = otherPropertyNames.map(other => other.slice(0, 1).toLowerCase() + other.slice(1))
81
+ const others = otherPropertyNames.map(other => other.slice(0, 1).toUpperCase() + other.slice(1))
82
82
  const joinedOthersPropertyName = otherPropertyNames[0] +
83
83
  (others.length > 1 ? ('And' + others.slice(1).join('And')) : '')
84
84
  const joinedOthersClassName = others.join('And')