@live-change/relations-plugin 0.9.61 → 0.9.62

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/boundToAny.js CHANGED
@@ -19,7 +19,7 @@ export default function(service, app) {
19
19
  context.reverseRelationWord = 'Bound'
20
20
  context.partialReverseRelationWord = 'Bound'
21
21
 
22
- defineAnyProperties(context.model, context.otherPropertyNames)
22
+ context.identifiers = defineAnyProperties(context.model, context.otherPropertyNames, config)
23
23
  defineAnyIndex(context.model, context.joinedOthersClassName, context.otherPropertyNames)
24
24
  defineAnyTypeIndexes(config, context, context.otherPropertyNames.length === 1)
25
25
 
package/entity.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  defineProperties, defineIndex,
3
3
  processModelsAnnotation, extractIdParts, extractIdentifiers, extractObjectData, prepareAccessControl,
4
- includeAccessRoles
4
+ includeAccessRoles, defineGlobalRangeView
5
5
  } from './utils.js'
6
6
  import { fireChangeTriggers } from "./changeTriggers.js"
7
7
  import App from '@live-change/framework'
@@ -47,31 +47,6 @@ function defineView(config, context, external) {
47
47
  })
48
48
  }
49
49
 
50
- function defineRangeView(config, context, external = true) {
51
- const { service, modelRuntime, modelPropertyName, modelName, model } = context
52
- const viewName = (config.prefix || '' ) + pluralize(config.prefix ? modelName : modelPropertyName) + (config.suffix || '')
53
- if(external) model.crud.range = viewName
54
- service.views[viewName] = new ViewDefinition({
55
- name: viewName,
56
- properties: {
57
- ...App.utils.rangeProperties
58
- },
59
- returns: {
60
- type: Array,
61
- of: {
62
- type: model
63
- }
64
- },
65
- internal: !external,
66
- global: config.globalView,
67
- access: external && config.readAllAccess,
68
- daoPath(properties, { client, context }) {
69
- const range = App.extractRange(properties)
70
- const path = modelRuntime().rangePath(range)
71
- return path
72
- }
73
- })
74
- }
75
50
 
76
51
  function defineCreatedEvent(config, context) {
77
52
  const {
@@ -392,7 +367,7 @@ export default function(service, app) {
392
367
  }
393
368
 
394
369
  defineView(config, context, config.readAccess || config.readAccessControl || config.writeAccessControl)
395
- defineRangeView(config, context, config.readAllAccess)
370
+ defineGlobalRangeView(config, context, config.readAllAccess)
396
371
  /// TODO: multiple views with limited fields
397
372
 
398
373
  defineCreatedEvent(config, context)
package/itemOf.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import {
2
2
  defineProperties, defineIndexes,
3
3
  processModelsAnnotation, addAccessControlParents,
4
- defineDeleteByOwnerEvents, defineParentDeleteTriggers, defineParentCopyTriggers
4
+ defineDeleteByOwnerEvents, defineParentDeleteTriggers, defineParentCopyTriggers,
5
+ defineGlobalRangeView
5
6
  } from './utils.js'
6
7
 
7
8
  import {
@@ -41,6 +42,8 @@ export default function(service, app) {
41
42
  config.readAccess || config.readAccessControl || config.writeAccessControl)
42
43
  /// TODO: multiple views with limited fields
43
44
 
45
+ defineGlobalRangeView(config, context, config.readAllAccess)
46
+
44
47
  defineCreatedEvent(config, context)
45
48
  defineUpdatedEvent(config, context)
46
49
  defineTransferredEvent(config, context)
package/itemOfAny.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { defineGlobalRangeView } from './utils.js'
2
+
1
3
  import {
2
4
  defineAnyProperties, defineAnyIndexes,
3
5
  processModelsAnyAnnotation, addAccessControlAnyParents, generateAnyId, defineDeleteByOwnerEvents,
@@ -21,7 +23,7 @@ export default function(service, app) {
21
23
  context.relationWord = 'Item'
22
24
  context.reverseRelationWord = 'Owned'
23
25
 
24
- context.identifiers = defineAnyProperties(context.model, context.otherPropertyNames)
26
+ context.identifiers = defineAnyProperties(context.model, context.otherPropertyNames, config)
25
27
  context.model.identifiers = [...Object.keys(context.identifiers), { name: context.modelPropertyName, field: 'id' }]
26
28
 
27
29
  addAccessControlAnyParents(context)
@@ -41,6 +43,8 @@ export default function(service, app) {
41
43
  /// TODO: multiple views with all properties combinations
42
44
  /// TODO: multiple views with limited fields
43
45
 
46
+ defineGlobalRangeView(config, context, config.readAllAccess)
47
+
44
48
  defineCreatedEvent(config, context)
45
49
  defineUpdatedEvent(config, context)
46
50
  defineTransferredEvent(config, context)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/relations-plugin",
3
- "version": "0.9.61",
3
+ "version": "0.9.62",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -22,8 +22,8 @@
22
22
  },
23
23
  "type": "module",
24
24
  "dependencies": {
25
- "@live-change/framework": "^0.9.61",
25
+ "@live-change/framework": "^0.9.62",
26
26
  "pluralize": "^8.0.0"
27
27
  },
28
- "gitHead": "f750f29f912b9a76b5ffa2bdf5c46954cc7e7a67"
28
+ "gitHead": "b1b605b7f1fa4fc3de4720afbb401e2cfff080cf"
29
29
  }
@@ -35,7 +35,7 @@ function defineRangeView(config, context, external = true) {
35
35
  const sourceAccessControl = external && (config.readAccessControl || config.writeAccessControl)
36
36
  const accessControl = cloneAndPrepareAccessControl(sourceAccessControl, otherPropertyNames)
37
37
  const viewName = joinedOthersPropertyName + context.reverseRelationWord + pluralize(modelName)
38
- model.crud.range = viewName
38
+ model.crud['rangeBy' + joinedOthersClassName] = viewName
39
39
  service.view({
40
40
  name: viewName,
41
41
  properties: {
@@ -24,7 +24,7 @@ function defineRangeView(config, context, external = true) {
24
24
  })
25
25
  }
26
26
  const viewName = joinedOthersPropertyName + context.reverseRelationWord + pluralize(modelName)
27
- model.crud.range = viewName
27
+ model.crud['rangeBy' + joinedOthersPropertyName[0].toUpperCase() + joinedOthersPropertyName.slice(1)] = viewName
28
28
  const sourceAccessControl = external && (config.readAccessControl || config.writeAccessControl)
29
29
  const accessControl = cloneAndPrepareAccessControl(sourceAccessControl, otherPropertyNames, others)
30
30
  if(viewName === 'companyOwnedProducts') {
package/propertyOf.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import {
2
2
  defineProperties, defineIndexes,
3
3
  processModelsAnnotation, generateId, addAccessControlParents,
4
- defineDeleteByOwnerEvents, defineParentDeleteTriggers
4
+ defineDeleteByOwnerEvents, defineParentDeleteTriggers,
5
+ defineGlobalRangeView
5
6
  } from './utils.js'
6
7
 
7
8
  import { defineSetEvent, defineUpdatedEvent, defineTransferredEvent, defineResetEvent } from './propertyEvents.js'
@@ -52,6 +53,9 @@ export default function(service, app) {
52
53
  }
53
54
  }
54
55
 
56
+ defineGlobalRangeView(config, context, config.readAllAccess)
57
+
58
+
55
59
  defineSetEvent(config, context, generateId)
56
60
  defineUpdatedEvent(config, context, generateId)
57
61
  defineTransferredEvent(config, context, generateId)
package/propertyOfAny.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { defineGlobalRangeView } from './utils.js'
2
+
1
3
  import {
2
4
  defineAnyProperties, defineAnyIndexes,
3
5
  processModelsAnyAnnotation, generateAnyId, addAccessControlAnyParents,
@@ -32,7 +34,7 @@ export default function(service, app) {
32
34
 
33
35
  context.sameIdAsParent = true
34
36
 
35
- context.identifiers = defineAnyProperties(context.model, context.otherPropertyNames)
37
+ context.identifiers = defineAnyProperties(context.model, context.otherPropertyNames, config)
36
38
  context.model.identifiers = Object.keys(context.identifiers)
37
39
 
38
40
  addAccessControlAnyParents(context)
@@ -42,6 +44,7 @@ export default function(service, app) {
42
44
  defineObjectView(config, context,
43
45
  config.singleAccess || config.readAccess || config.singleAccessControl || config.readAccessControl
44
46
  )
47
+
45
48
  defineRangeViews(config, context,
46
49
  config.listAccess || config.readAccess || config.listAccessControl || config.readAccessControl
47
50
  )
@@ -56,6 +59,8 @@ export default function(service, app) {
56
59
  }
57
60
  }
58
61
 
62
+ defineGlobalRangeView(config, context, config.readAllAccess)
63
+
59
64
  defineSetEvent(config, context, generateAnyId)
60
65
  defineUpdatedEvent(config, context, generateAnyId)
61
66
  defineTransferredEvent(config, context, generateAnyId)
package/relatedToAny.js CHANGED
@@ -19,7 +19,7 @@ export default function(service, app) {
19
19
  context.relationWord = 'Friend'
20
20
  context.reverseRelationWord = 'Related'
21
21
 
22
- context.identifiers = defineAnyProperties(context.model, context.otherPropertyNames)
22
+ context.identifiers = defineAnyProperties(context.model, context.otherPropertyNames, config)
23
23
  defineAnyIndex(context.model, context.joinedOthersClassName, context.otherPropertyNames)
24
24
  defineAnyTypeIndexes(config, context, false)
25
25
 
@@ -71,10 +71,11 @@ function defineRangeViews(config, context, external = true) {
71
71
  for(const combination of identifierCombinations) {
72
72
  const propsUpperCase = combination.map(prop => prop[0].toUpperCase() + prop.slice(1))
73
73
  const indexName = 'by' + combination.map(prop => prop[0].toUpperCase() + prop.slice(1))
74
- const viewName = combination[0][0].toLowerCase() + combination[0].slice(1) +
75
- propsUpperCase.slice(1).join('And') + context.partialReverseRelationWord + pluralize(modelName)
76
- console.log("DEFINE RANGE VIEW", viewName, combination)
74
+ const joinedCombinationName = combination[0][0].toLowerCase() + combination[0].slice(1) +
75
+ propsUpperCase.slice(1).join('And')
76
+ const viewName = joinedCombinationName + context.partialReverseRelationWord + pluralize(modelName)
77
77
  const identifiers = createIdentifiersProperties(combination)
78
+ model.crud['rangeBy' + joinedOthersClassName[0].toUpperCase() + joinedOthersClassName.slice(1)] = viewName
78
79
  service.view({
79
80
  name: viewName,
80
81
  properties: {
package/utils.js CHANGED
@@ -12,6 +12,8 @@ export {
12
12
  extractObjectData, extractIdentifiers
13
13
  } from './dataUtils.js'
14
14
 
15
+ import pluralize from 'pluralize'
16
+
15
17
  export function extractIdParts(otherPropertyNames, properties) {
16
18
  const idParts = []
17
19
  for (const propertyName of otherPropertyNames) {
@@ -146,7 +148,7 @@ export function processModelsAnnotation(service, app, annotation, multiple, cb)
146
148
 
147
149
  export function addAccessControlParents(context) {
148
150
  const { modelRuntime } = context
149
- context.model.accessControlParents = async (what) => {
151
+ context.model.accessControlParents = context.model.accessControlParents ?? (async (what) => {
150
152
  const id = what.object
151
153
  const data = await modelRuntime().get(id)
152
154
  return context.otherPropertyNames.map((otherPropertyName, i) => {
@@ -155,8 +157,8 @@ export function addAccessControlParents(context) {
155
157
  const object = data[otherPropertyName]
156
158
  return { objectType, object }
157
159
  }).filter(parent => parent.object && parent.objectType)
158
- }
159
- context.model.accessControlParentsSource = context.otherPropertyNames.map(
160
+ })
161
+ context.model.accessControlParentsSource = context.model.accessControlParentsSource ?? context.otherPropertyNames.map(
160
162
  (otherPropertyName, i) => {
161
163
  const other = context.others[i]
162
164
  return ({
@@ -244,4 +246,30 @@ export function includeAccessRoles(model, access) {
244
246
  if(access.roles) {
245
247
  includeAccessRoles(model, access.roles)
246
248
  }
249
+ }
250
+
251
+ export function defineGlobalRangeView(config, context, external = true) {
252
+ const { service, modelRuntime, modelPropertyName, modelName, model } = context
253
+ const viewName = (config.prefix || '' ) + pluralize(config.prefix ? modelName : modelPropertyName) + (config.suffix || '')
254
+ if(external) model.crud.range = viewName
255
+ service.views[viewName] = new ViewDefinition({
256
+ name: viewName,
257
+ properties: {
258
+ ...App.utils.rangeProperties
259
+ },
260
+ returns: {
261
+ type: Array,
262
+ of: {
263
+ type: model
264
+ }
265
+ },
266
+ internal: !external,
267
+ global: config.globalView,
268
+ access: external && config.readAllAccess,
269
+ daoPath(properties, { client, context }) {
270
+ const range = App.extractRange(properties)
271
+ const path = modelRuntime().rangePath(range)
272
+ return path
273
+ }
274
+ })
247
275
  }
package/utilsAny.js CHANGED
@@ -39,15 +39,19 @@ export function generateAnyId(otherPropertyNames, properties) {
39
39
  .map(p => JSON.stringify(properties[p])).join(':')
40
40
  }
41
41
 
42
- export function defineAnyProperties(model, names) {
42
+ export function defineAnyProperties(model, names, config) {
43
43
  const identifiers = {}
44
44
  for (let i = 0; i < names.length; i++) {
45
+ const possibleTypes = config[names[i]+'Types']
46
+ const possibleTypesNames = possibleTypes && possibleTypes.map(t => t.getTypeName ? t.getTypeName() : t)
45
47
  identifiers[names[i]+'Type'] = new PropertyDefinition({
46
- type: String,
47
- validation: ['nonEmpty']
48
+ type: 'type',
49
+ validation: ['nonEmpty'],
50
+ enum: possibleTypesNames
48
51
  })
49
52
  identifiers[names[i]] = new PropertyDefinition({
50
- type: String,
53
+ types: possibleTypesNames,
54
+ type: 'any',
51
55
  validation: ['nonEmpty']
52
56
  })
53
57
  }
@@ -152,7 +156,7 @@ export function processModelsAnyAnnotation(service, app, annotation, multiple, c
152
156
 
153
157
  export function addAccessControlAnyParents(context) {
154
158
  const { modelRuntime } = context
155
- context.model.accessControlParents = async (what) => {
159
+ context.model.accessControlParents = context.model.accessControlParents ?? (async (what) => {
156
160
  const id = what.object
157
161
  console.log("PROPERTY OF ANY ACCESS CONTROL PARENTS", context.model.name, '/', id)
158
162
  const data = await modelRuntime().get(id)
@@ -161,8 +165,8 @@ export function addAccessControlAnyParents(context) {
161
165
  const object = data[otherPropertyName]
162
166
  return { objectType, object }
163
167
  }).filter(parent => parent.object && parent.objectType)
164
- }
165
- context.model.accessControlParentsSource = context.otherPropertyNames.map(
168
+ })
169
+ context.model.accessControlParentsSource = context.model.accessControlParentsSource ?? context.otherPropertyNames.map(
166
170
  (otherPropertyName, index) => ({
167
171
  property: otherPropertyName,
168
172
  possibleTypes: context.otherPossibleTypes[index]