@live-change/relations-plugin 0.5.26 → 0.6.1

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.
@@ -0,0 +1,17 @@
1
+ function combinations(x, n ,p=[]) {
2
+ if(x.length == 0 || n > x.length) return []
3
+ if(n == 1 || x.length == 1) return x.map(e=>p.concat([e]))
4
+ let acc = []
5
+ for(let i = 0; i < x.length; i++) acc.push(
6
+ ...combinations(x.slice(i+1), n - 1, p.concat([x[i]]))
7
+ )
8
+ return acc
9
+ }
10
+
11
+ function allCombinations(x) {
12
+ let acc = []
13
+ for(let i = 1; i<=x.length; i++) acc.push(...combinations(x,i))
14
+ return acc
15
+ }
16
+
17
+ module.exports = { combinations, allCombinations }
package/itemEvents.js CHANGED
@@ -3,9 +3,9 @@ const { PropertyDefinition, ViewDefinition, IndexDefinition, ActionDefinition, E
3
3
 
4
4
  function defineCreatedEvent(config, context) {
5
5
  const {
6
- service, modelRuntime, joinedOthersPropertyName, modelName, modelPropertyName
6
+ service, modelRuntime, joinedOthersPropertyName, modelName, modelPropertyName, reverseRelationWord
7
7
  } = context
8
- const eventName = joinedOthersPropertyName + 'Owned' + modelName + 'Created'
8
+ const eventName = joinedOthersPropertyName + reverseRelationWord + modelName + 'Created'
9
9
  service.events[eventName] = new EventDefinition({
10
10
  name: eventName,
11
11
  execute(properties) {
@@ -17,9 +17,9 @@ function defineCreatedEvent(config, context) {
17
17
 
18
18
  function defineUpdatedEvent(config, context) {
19
19
  const {
20
- service, modelRuntime, joinedOthersPropertyName, modelName, modelPropertyName
20
+ service, modelRuntime, joinedOthersPropertyName, modelName, modelPropertyName, reverseRelationWord
21
21
  } = context
22
- const eventName = joinedOthersPropertyName + 'Owned' + modelName + 'Updated'
22
+ const eventName = joinedOthersPropertyName + reverseRelationWord + modelName + 'Updated'
23
23
  service.events[eventName] = new EventDefinition({
24
24
  name: eventName,
25
25
  execute(properties) {
@@ -31,9 +31,9 @@ function defineUpdatedEvent(config, context) {
31
31
 
32
32
  function defineTransferredEvent(config, context) {
33
33
  const {
34
- service, modelRuntime, joinedOthersPropertyName, modelName, modelPropertyName
34
+ service, modelRuntime, joinedOthersPropertyName, modelName, modelPropertyName, reverseRelationWord
35
35
  } = context
36
- const eventName = joinedOthersPropertyName + 'Owned' + modelName + 'Transferred'
36
+ const eventName = joinedOthersPropertyName + reverseRelationWord + modelName + 'Transferred'
37
37
  service.events[eventName] = new EventDefinition({
38
38
  name: eventName,
39
39
  execute(properties) {
@@ -45,9 +45,9 @@ function defineTransferredEvent(config, context) {
45
45
 
46
46
  function defineDeletedEvent(config, context) {
47
47
  const {
48
- service, modelRuntime, joinedOthersPropertyName, modelName, modelPropertyName
48
+ service, modelRuntime, joinedOthersPropertyName, modelName, modelPropertyName, reverseRelationWord
49
49
  } = context
50
- const eventName = joinedOthersPropertyName + 'Owned' + modelName + 'Deleted'
50
+ const eventName = joinedOthersPropertyName + reverseRelationWord + modelName + 'Deleted'
51
51
  service.events[eventName] = new EventDefinition({
52
52
  name: eventName,
53
53
  execute(properties) {
package/itemOf.js CHANGED
@@ -17,7 +17,7 @@ module.exports = function(service, app) {
17
17
  context.relationWord = 'Item'
18
18
  context.reverseRelationWord = 'Owned'
19
19
 
20
- defineProperties(context.model, context.others, context.otherPropertyNames)
20
+ context.identifiers = defineProperties(context.model, context.others, context.otherPropertyNames)
21
21
  defineIndex(context.model, context.joinedOthersClassName, context.otherPropertyNames)
22
22
 
23
23
  if(config.sortBy) {
@@ -44,7 +44,7 @@ module.exports = function(service, app) {
44
44
  defineUpdateAction(config, context)
45
45
  }
46
46
 
47
- if(config.resetAccess || config.writeAccess) {
47
+ if(config.deleteAccess || config.writeAccess) {
48
48
  defineDeleteAction(config, context)
49
49
  }
50
50
  })
package/itemOfAny.js CHANGED
@@ -17,7 +17,7 @@ module.exports = function(service, app) {
17
17
  context.relationWord = 'Item'
18
18
  context.reverseRelationWord = 'Owned'
19
19
 
20
- defineAnyProperties(context.model, context.otherPropertyNames)
20
+ context.identifiers = defineAnyProperties(context.model, context.otherPropertyNames)
21
21
  defineAnyIndex(context.model, context.joinedOthersClassName, context.otherPropertyNames)
22
22
 
23
23
  if(config.sortBy) {
@@ -44,7 +44,7 @@ module.exports = function(service, app) {
44
44
  defineUpdateAction(config, context)
45
45
  }
46
46
 
47
- if(config.resetAccess || config.writeAccess) {
47
+ if(config.deleteAccess || config.writeAccess) {
48
48
  defineDeleteAction(config, context)
49
49
  }
50
50
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/relations-plugin",
3
- "version": "0.5.26",
3
+ "version": "0.6.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -21,8 +21,8 @@
21
21
  "url": "https://www.viamage.com/"
22
22
  },
23
23
  "dependencies": {
24
- "@live-change/framework": "^0.5.25",
24
+ "@live-change/framework": "^0.6.1",
25
25
  "pluralize": "8.0.0"
26
26
  },
27
- "gitHead": "84d05fde7850ebac621da35ada9c19590a728741"
27
+ "gitHead": "64a9e476bdeec727ff5b8bedbaef65078f1b32f2"
28
28
  }
@@ -1,7 +1,8 @@
1
1
  const App = require("@live-change/framework")
2
2
  const { PropertyDefinition, ViewDefinition, IndexDefinition, ActionDefinition, EventDefinition } = App
3
3
  const { extractTypeAndIdParts, extractIdentifiersWithTypes } = require("./utilsAny.js")
4
- const { extractRange, extractObjectData } = require("./utils.js")
4
+ const { extractObjectData } = require("./utils.js")
5
+ const { extractRange } = App
5
6
 
6
7
  const pluralize = require('pluralize')
7
8
 
@@ -88,6 +89,10 @@ function defineUpdateAction(config, context) {
88
89
  service.actions[actionName] = new ActionDefinition({
89
90
  name: actionName,
90
91
  properties: {
92
+ [modelPropertyName]: {
93
+ type: model,
94
+ validation: ['nonEmpty']
95
+ },
91
96
  ...(model.properties)
92
97
  },
93
98
  access: config.updateAccess || config.writeAccess,
@@ -96,6 +101,7 @@ function defineUpdateAction(config, context) {
96
101
  waitForEvents: true,
97
102
  async execute(properties, { client, service }, emit) {
98
103
  const id = properties[modelPropertyName]
104
+ if(!id) throw 'no_id'
99
105
  const entity = await modelRuntime().get(id)
100
106
  if(!entity) throw 'not_found'
101
107
  const entityTypeAndIdParts = extractTypeAndIdParts(otherPropertyNames, entity)
@@ -121,7 +127,7 @@ function defineUpdateAction(config, context) {
121
127
 
122
128
  function defineDeleteAction(config, context) {
123
129
  const {
124
- service, app, model, modelRuntime, modelPropertyName,
130
+ service, app, model, modelRuntime, modelPropertyName, identifiers,
125
131
  otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName
126
132
  } = context
127
133
  const eventName = joinedOthersPropertyName + context.reverseRelationWord + modelName + 'Deleted'
@@ -129,7 +135,11 @@ function defineDeleteAction(config, context) {
129
135
  service.actions[actionName] = new ActionDefinition({
130
136
  name: actionName,
131
137
  properties: {
132
- ...(model.properties)
138
+ [modelPropertyName]: {
139
+ type: model,
140
+ validation: ['nonEmpty']
141
+ },
142
+ ...identifiers
133
143
  },
134
144
  access: config.deleteAccess || config.writeAccess,
135
145
  skipValidation: true,
@@ -89,7 +89,7 @@ function defineUpdateAction(config, context) {
89
89
  skipValidation: true,
90
90
  //queuedBy: otherPropertyNames,
91
91
  waitForEvents: true,
92
- async execute(properties, {client, service}, emit) {
92
+ async execute(properties, { client, service }, emit) {
93
93
  const id = properties[modelPropertyName]
94
94
  const entity = await modelRuntime().get(id)
95
95
  if(!entity) throw 'not_found'
@@ -130,7 +130,7 @@ function defineDeleteAction(config, context) {
130
130
  skipValidation: true,
131
131
  //queuedBy: otherPropertyNames,
132
132
  waitForEvents: true,
133
- async execute(properties, {client, service}, emit) {
133
+ async execute(properties, { client, service }, emit) {
134
134
  const id = properties[modelPropertyName]
135
135
  const entity = await modelRuntime().get(id)
136
136
  if(!entity) throw new Error('not_found')
package/propertyEvents.js CHANGED
@@ -3,9 +3,9 @@ const { PropertyDefinition, ViewDefinition, IndexDefinition, ActionDefinition, E
3
3
 
4
4
  function defineSetEvent(config, context, generateId) {
5
5
  const {
6
- service, modelRuntime, joinedOthersPropertyName, modelName, otherPropertyNames
6
+ service, modelRuntime, joinedOthersPropertyName, modelName, otherPropertyNames, reverseRelationWord
7
7
  } = context
8
- const eventName = joinedOthersPropertyName + 'Owned' + modelName + 'Set'
8
+ const eventName = joinedOthersPropertyName + reverseRelationWord + modelName + 'Set'
9
9
  service.events[eventName] = new EventDefinition({
10
10
  name: eventName,
11
11
  execute(properties) {
@@ -17,9 +17,9 @@ function defineSetEvent(config, context, generateId) {
17
17
 
18
18
  function defineUpdatedEvent(config, context, generateId) {
19
19
  const {
20
- service, modelRuntime, joinedOthersPropertyName, modelName, otherPropertyNames
20
+ service, modelRuntime, joinedOthersPropertyName, modelName, otherPropertyNames, reverseRelationWord
21
21
  } = context
22
- const eventName = joinedOthersPropertyName + 'Owned' + modelName + 'Updated'
22
+ const eventName = joinedOthersPropertyName + reverseRelationWord + modelName + 'Updated'
23
23
  service.events[eventName] = new EventDefinition({
24
24
  name: eventName,
25
25
  execute(properties) {
@@ -31,9 +31,9 @@ function defineUpdatedEvent(config, context, generateId) {
31
31
 
32
32
  function defineTransferredEvent(config, context, generateId) {
33
33
  const {
34
- service, modelRuntime, joinedOthersPropertyName, modelName, otherPropertyNames
34
+ service, modelRuntime, joinedOthersPropertyName, modelName, otherPropertyNames, reverseRelationWord
35
35
  } = context
36
- const eventName = joinedOthersPropertyName + 'Owned' + modelName + 'Transferred'
36
+ const eventName = joinedOthersPropertyName + reverseRelationWord + modelName + 'Transferred'
37
37
  service.events[eventName] = new EventDefinition({
38
38
  name: eventName,
39
39
  async execute(properties) {
@@ -53,9 +53,9 @@ function defineTransferredEvent(config, context, generateId) {
53
53
 
54
54
  function defineResetEvent(config, context, generateId) {
55
55
  const {
56
- service, modelRuntime, joinedOthersPropertyName, modelName, otherPropertyNames
56
+ service, modelRuntime, joinedOthersPropertyName, modelName, otherPropertyNames, reverseRelationWord
57
57
  } = context
58
- const eventName = joinedOthersPropertyName + 'Owned' + modelName + 'Reset'
58
+ const eventName = joinedOthersPropertyName + reverseRelationWord + modelName + 'Reset'
59
59
  service.events[eventName] = new EventDefinition({
60
60
  name: eventName,
61
61
  execute({ identifiers }) {
package/propertyOf.js CHANGED
@@ -15,7 +15,7 @@ module.exports = function(service, app) {
15
15
  context.relationWord = 'Property'
16
16
  context.reverseRelationWord = 'Owned'
17
17
 
18
- defineProperties(context.model, context.others, context.otherPropertyNames)
18
+ context.identifiers = defineProperties(context.model, context.others, context.otherPropertyNames)
19
19
  defineIndex(context.model, context.joinedOthersClassName, context.otherPropertyNames)
20
20
 
21
21
  if(config.readAccess) {
package/propertyOfAny.js CHANGED
@@ -1,5 +1,5 @@
1
1
  const {
2
- defineAnyProperties, defineAnyIndex,
2
+ defineAnyProperties, defineAnyIndex, defineAnyIndexes,
3
3
  processModelsAnyAnnotation, generateAnyId
4
4
  } = require('./utilsAny.js')
5
5
 
@@ -8,7 +8,7 @@ const {
8
8
  } = require('./propertyEvents.js')
9
9
 
10
10
  const {
11
- defineView, defineSetAction, defineUpdateAction, defineSetOrUpdateAction, defineResetAction
11
+ defineObjectView, defineRangeViews, defineSetAction, defineUpdateAction, defineSetOrUpdateAction, defineResetAction
12
12
  } = require('./singularRelationAnyUtils.js')
13
13
 
14
14
  module.exports = function(service, app) {
@@ -16,16 +16,18 @@ module.exports = function(service, app) {
16
16
 
17
17
  context.relationWord = 'Property'
18
18
  context.reverseRelationWord = 'Owned'
19
+ context.partialReverseRelationWord = 'Owned'
19
20
 
20
- defineAnyProperties(context.model, context.otherPropertyNames)
21
- defineAnyIndex(context.model, context.joinedOthersClassName, context.otherPropertyNames)
21
+ context.identifiers = defineAnyProperties(context.model, context.otherPropertyNames)
22
+ defineAnyIndexes(context.model, context.otherPropertyNames)
22
23
 
23
24
  if(config.readAccess) {
24
- defineView({ ...config, access: config.readAccess }, context)
25
+ defineObjectView({ ...config, access: config.readAccess }, context)
26
+ defineRangeViews({ ...config, access: config.readAccess }, context)
25
27
  }
26
28
  if(config.views) {
27
29
  for(const view of config.views) {
28
- defineView({ ...config, ...view }, context)
30
+ defineObjectView({ ...config, ...view }, context)
29
31
  }
30
32
  }
31
33
 
package/relatedTo.js CHANGED
@@ -17,7 +17,7 @@ module.exports = function(service, app) {
17
17
  context.relationWord = 'Friend'
18
18
  context.reverseRelationWord = 'Related'
19
19
 
20
- defineProperties(context.model, context.others, context.otherPropertyNames)
20
+ context.identifiers = defineProperties(context.model, context.others, context.otherPropertyNames)
21
21
  defineIndex(context.model, context.joinedOthersClassName, context.otherPropertyNames)
22
22
 
23
23
  if(config.sortBy) {
@@ -44,7 +44,7 @@ module.exports = function(service, app) {
44
44
  defineUpdateAction(config, context)
45
45
  }
46
46
 
47
- if(config.resetAccess || config.writeAccess) {
47
+ if(config.deleteAccess || config.writeAccess) {
48
48
  defineDeleteAction(config, context)
49
49
  }
50
50
  })
package/relatedToAny.js CHANGED
@@ -17,7 +17,7 @@ module.exports = function(service, app) {
17
17
  context.relationWord = 'Friend'
18
18
  context.reverseRelationWord = 'Related'
19
19
 
20
- defineAnyProperties(context.model, context.otherPropertyNames)
20
+ context.identifiers = defineAnyProperties(context.model, context.otherPropertyNames)
21
21
  defineAnyIndex(context.model, context.joinedOthersClassName, context.otherPropertyNames)
22
22
 
23
23
  if(config.sortBy) {
@@ -44,7 +44,7 @@ module.exports = function(service, app) {
44
44
  defineUpdateAction(config, context)
45
45
  }
46
46
 
47
- if(config.resetAccess || config.writeAccess) {
47
+ if(config.deleteAccess || config.writeAccess) {
48
48
  defineDeleteAction(config, context)
49
49
  }
50
50
  })
@@ -2,9 +2,26 @@ const App = require("@live-change/framework")
2
2
  const { PropertyDefinition, ViewDefinition, IndexDefinition, ActionDefinition } = App
3
3
  const { extractTypeAndIdParts, extractIdentifiersWithTypes, generateAnyId } = require("./utilsAny.js")
4
4
  const { extractObjectData } = require("./utils.js")
5
+ const { allCombinations } = require("./combinations.js")
5
6
 
7
+ const pluralize = require('pluralize')
6
8
 
7
- function defineView(config, context) {
9
+ function createIdentifiersProperties(keys) {
10
+ const identifiers = {}
11
+ if(keys) for(const key of keys) {
12
+ identifiers[key] = {
13
+ type: String,
14
+ validation: ['nonEmpty']
15
+ }
16
+ identifiers[key + 'Type'] = {
17
+ type: String,
18
+ validation: ['nonEmpty']
19
+ }
20
+ }
21
+ return identifiers
22
+ }
23
+
24
+ function defineObjectView(config, context) {
8
25
  const { service, modelRuntime, otherPropertyNames, joinedOthersPropertyName, joinedOthersClassName,
9
26
  modelName, others, model } = context
10
27
  const viewProperties = {}
@@ -38,6 +55,37 @@ function defineView(config, context) {
38
55
  })
39
56
  }
40
57
 
58
+ function defineRangeViews(config, context) {
59
+ const { service, modelRuntime, otherPropertyNames, joinedOthersPropertyName, joinedOthersClassName,
60
+ modelName, others, model } = context
61
+ const identifierCombinations = allCombinations(otherPropertyNames).slice(0, -1)
62
+ for(const combination of identifierCombinations) {
63
+ const propsUpperCase = combination.map(prop => prop[0].toUpperCase() + prop.slice(1))
64
+ const indexName = 'by' + combination.map(prop => prop[0].toUpperCase() + prop.slice(1))
65
+ const viewName = combination[0][0].toLowerCase() + combination[0].slice(1) +
66
+ propsUpperCase.slice(1).join('And') + context.partialReverseRelationWord + pluralize(modelName)
67
+ console.log("DEFINE RANGE VIEW", viewName, combination)
68
+ const identifiers = createIdentifiersProperties(combination)
69
+ service.views[viewName] = new ViewDefinition({
70
+ name: viewName,
71
+ properties: {
72
+ ...identifiers,
73
+ ...App.rangeProperties,
74
+ },
75
+ access(params, context) {
76
+ return config.access ? config.access(params, context) : true
77
+ },
78
+ daoPath(params, { client, context }) {
79
+ const owner = []
80
+ for (const key of combination) {
81
+ owner.push(params[key + 'Type'], params[key])
82
+ }
83
+ return modelRuntime().sortedIndexRangePath(indexName, owner, App.extractRange(params) )
84
+ }
85
+ })
86
+ }
87
+ }
88
+
41
89
  function defineSetAction(config, context) {
42
90
  const {
43
91
  service, app, model, defaults,
@@ -120,13 +168,13 @@ function defineSetOrUpdateAction(config, context) {
120
168
  skipValidation: true,
121
169
  queuedBy: otherPropertyNames,
122
170
  waitForEvents: true,
123
- async execute(properties, {client, service}, emit) {
171
+ async execute(properties, { client, service }, emit) {
124
172
  const identifiers = extractIdentifiersWithTypes(otherPropertyNames, properties)
125
173
  const id = generateAnyId(otherPropertyNames, properties)
126
174
  const entity = await modelRuntime().get(id)
127
175
  const data = extractObjectData(writeableProperties, properties, { ...defaults, ...entity } )
128
176
  await App.validation.validate({ ...identifiers, ...data }, validators,
129
- {source: action, action, service, app, client})
177
+ { source: action, action, service, app, client })
130
178
  emit({
131
179
  type: eventName,
132
180
  identifiers, data
@@ -139,7 +187,7 @@ function defineSetOrUpdateAction(config, context) {
139
187
 
140
188
  function defineResetAction(config, context) {
141
189
  const {
142
- service, modelRuntime, modelPropertyName,
190
+ service, modelRuntime, modelPropertyName, identifiers,
143
191
  otherPropertyNames, joinedOthersPropertyName, modelName, joinedOthersClassName, model
144
192
  } = context
145
193
  const eventName = joinedOthersPropertyName + context.reverseRelationWord + modelName + 'Reset'
@@ -150,7 +198,8 @@ function defineResetAction(config, context) {
150
198
  [modelPropertyName]: {
151
199
  type: model,
152
200
  validation: ['nonEmpty']
153
- }
201
+ },
202
+ ...identifiers
154
203
  },
155
204
  access: config.resetAccess || config.writeAccess,
156
205
  queuedBy: otherPropertyNames,
@@ -168,4 +217,7 @@ function defineResetAction(config, context) {
168
217
  })
169
218
  }
170
219
 
171
- module.exports = { defineView, defineSetAction, defineUpdateAction, defineSetOrUpdateAction, defineResetAction }
220
+ module.exports = {
221
+ defineObjectView, defineRangeViews,
222
+ defineSetAction, defineUpdateAction, defineSetOrUpdateAction, defineResetAction
223
+ }
package/utils.js CHANGED
@@ -9,17 +9,6 @@ function extractIdParts(otherPropertyNames, properties) {
9
9
  return idParts
10
10
  }
11
11
 
12
- function extractRange(properties) {
13
- return {
14
- gt: properties.gt,
15
- gte: properties.gte,
16
- lt: properties.lt,
17
- lte: properties.lte,
18
- reverse: properties.reverse,
19
- limit: properties.limit
20
- }
21
- }
22
-
23
12
  function extractIdentifiers(otherPropertyNames, properties) {
24
13
  const identifiers = {}
25
14
  for (const propertyName of otherPropertyNames) {
@@ -41,16 +30,21 @@ function extractObjectData(writeableProperties, properties, defaults) {
41
30
  objectData[propertyName] = properties[propertyName]
42
31
  }
43
32
  }
44
- return App.utils.mergeDeep({}, defaults, objectData)
33
+ return App.utils.mergeDeep({}, defaults, JSON.parse(JSON.stringify(objectData)))
45
34
  }
46
35
 
47
36
  function defineProperties(model, types, names) {
37
+ const identifiers = {}
48
38
  for (let i = 0; i < types.length; i++) {
49
- model.properties[names[i]] = new PropertyDefinition({
39
+ identifiers[names[i]] = new PropertyDefinition({
50
40
  type: types[i],
51
41
  validation: ['nonEmpty']
52
42
  })
53
43
  }
44
+ for(const key in identifiers) {
45
+ model.properties[key] = identifiers[key]
46
+ }
47
+ return identifiers
54
48
  }
55
49
 
56
50
  function defineIndex(model, what, props) {
@@ -123,5 +117,5 @@ function processModelsAnnotation(service, app, annotation, multiple, cb) {
123
117
 
124
118
  module.exports = {
125
119
  extractIdParts, extractIdentifiers, extractObjectData, defineProperties, defineIndex,
126
- processModelsAnnotation, extractRange, generateId
120
+ processModelsAnnotation, generateId
127
121
  }
package/utilsAny.js CHANGED
@@ -1,5 +1,6 @@
1
1
  const App = require("@live-change/framework")
2
2
  const { PropertyDefinition, ViewDefinition, IndexDefinition, ActionDefinition, EventDefinition } = App
3
+ const { allCombinations } = require("./combinations.js")
3
4
 
4
5
  function extractTypeAndIdParts(otherPropertyNames, properties) {
5
6
  const typeAndIdParts = []
@@ -27,16 +28,21 @@ function generateAnyId(otherPropertyNames, properties) {
27
28
  }
28
29
 
29
30
  function defineAnyProperties(model, names) {
31
+ const identifiers = {}
30
32
  for (let i = 0; i < names.length; i++) {
31
- model.properties[names[i]] = new PropertyDefinition({
33
+ identifiers[names[i]] = new PropertyDefinition({
32
34
  type: String,
33
35
  validation: ['nonEmpty']
34
36
  })
35
- model.properties[names[i]+'Type'] = new PropertyDefinition({
37
+ identifiers[names[i]+'Type'] = new PropertyDefinition({
36
38
  type: String,
37
39
  validation: ['nonEmpty']
38
40
  })
39
41
  }
42
+ for(const key in identifiers) {
43
+ model.properties[key] = identifiers[key]
44
+ }
45
+ return identifiers
40
46
  }
41
47
 
42
48
  function defineAnyIndex(model, what, props) {
@@ -45,6 +51,14 @@ function defineAnyIndex(model, what, props) {
45
51
  })
46
52
  }
47
53
 
54
+ function defineAnyIndexes(model, props) {
55
+ const propCombinations = allCombinations(props)
56
+ for(const propCombination of propCombinations) {
57
+ const upperCaseProps = propCombination.map(prop => prop[0].toUpperCase() + prop.slice(1))
58
+ defineAnyIndex(model, upperCaseProps.join('And'), propCombination)
59
+ }
60
+ }
61
+
48
62
  function processModelsAnyAnnotation(service, app, annotation, multiple, cb) {
49
63
  if (!service) throw new Error("no service")
50
64
  if (!app) throw new Error("no app")
@@ -104,6 +118,7 @@ function processModelsAnyAnnotation(service, app, annotation, multiple, cb) {
104
118
  }
105
119
 
106
120
  module.exports = {
107
- extractTypeAndIdParts, extractIdentifiersWithTypes, defineAnyProperties, defineAnyIndex,
121
+ extractTypeAndIdParts, extractIdentifiersWithTypes, defineAnyProperties,
122
+ defineAnyIndex, defineAnyIndexes,
108
123
  processModelsAnyAnnotation, generateAnyId
109
124
  }