@live-change/relations-plugin 0.9.84 → 0.9.85

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/relations-plugin",
3
- "version": "0.9.84",
3
+ "version": "0.9.85",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -22,8 +22,13 @@
22
22
  },
23
23
  "type": "module",
24
24
  "dependencies": {
25
- "@live-change/framework": "^0.9.84",
25
+ "@live-change/framework": "^0.9.85",
26
26
  "pluralize": "^8.0.0"
27
27
  },
28
- "gitHead": "5881a5406e3a39e673034f172266409ddb306f2e"
28
+ "devDependencies": {
29
+ "typedoc": "0.28.3",
30
+ "typedoc-plugin-markdown": "^4.6.3",
31
+ "typedoc-plugin-rename-defaults": "^0.7.3"
32
+ },
33
+ "gitHead": "126afb0aad3ab6e03aa5742726f429c95c46783a"
29
34
  }
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  defineProperties, defineIndex,
3
- processModelsAnnotation, generateId
3
+ processModelsAnnotation, generateId,
4
+ RelationConfig
4
5
  } from './utils.js'
5
6
 
6
7
  import { defineSetEvent, defineUpdatedEvent, defineTransferredEvent, defineResetEvent } from './propertyEvents.js'
@@ -19,9 +20,37 @@ import {
19
20
  defineDeleteAction,
20
21
  defineDeleteTrigger
21
22
  } from './singularRelationUtils.js'
23
+ import { AccessSpecification } from '@live-change/framework'
24
+ import { AccessControlSettings } from './types.js'
25
+
26
+ export interface BoundToConfig extends RelationConfig {
27
+ readAccess?: AccessSpecification
28
+ writeAccess?: AccessSpecification
29
+ listAccess?: AccessSpecification
30
+ setAccess?: AccessSpecification
31
+ updateAccess?: AccessSpecification
32
+ setOrUpdateAccess?: AccessSpecification
33
+ resetAccess?: AccessSpecification
34
+ readAllAccess?: AccessSpecification
35
+
36
+ readAccessControl?: AccessControlSettings
37
+ writeAccessControl?: AccessControlSettings
38
+ listAccessControl?: AccessControlSettings
39
+ setAccessControl?: AccessControlSettings
40
+ updateAccessControl?: AccessControlSettings
41
+ resetAccessControl?: AccessControlSettings
42
+ setOrUpdateAccessControl?: AccessControlSettings
43
+ views?: {
44
+ type: 'range' | 'object'
45
+ internal?: boolean
46
+ readAccess?: AccessSpecification,
47
+ readAccessControl?: AccessControlSettings,
48
+ fields?: string[]
49
+ }[]
50
+ }
22
51
 
23
52
  export default function(service, app) {
24
- processModelsAnnotation(service, app, 'boundTo', false, (config, context) => {
53
+ processModelsAnnotation<BoundToConfig>(service, app, 'boundTo', false, (config, context) => {
25
54
 
26
55
  context.relationWord = 'Friend'
27
56
  context.reverseRelationWord = 'Bound'
@@ -31,10 +60,10 @@ export default function(service, app) {
31
60
  defineIndex(context.model, context.joinedOthersClassName, context.otherPropertyNames)
32
61
 
33
62
  defineObjectView({ ...config, access: config.readAccess }, context,
34
- config.readAccess || config.readAccessControl || config.writeAccessControl
63
+ !!(config.readAccess || config.readAccessControl || config.writeAccessControl)
35
64
  )
36
65
  defineRangeViews(config, context,
37
- config.listAccess || config.readAccess || config.listAccessControl
66
+ !!(config.listAccess || config.readAccess || config.listAccessControl)
38
67
  )
39
68
 
40
69
  if(config.views) {
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  defineAnyProperties, defineAnyIndex,
3
- processModelsAnyAnnotation, generateAnyId, defineAnyTypeIndexes
3
+ processModelsAnyAnnotation, generateAnyId, defineAnyTypeIndexes,
4
+ AnyRelationConfig
4
5
  } from './utilsAny.js'
5
6
 
6
7
  import { defineSetEvent, defineUpdatedEvent, defineTransferredEvent, defineResetEvent } from './propertyEvents.js'
@@ -11,9 +12,40 @@ import {
11
12
  defineSetTrigger, defineUpdateTrigger, defineSetOrUpdateTrigger, defineResetTrigger
12
13
  } from './singularRelationAnyUtils.js'
13
14
  import { defineDeleteAction, defineDeleteTrigger } from './singularRelationAnyUtils.js'
15
+ import { AccessSpecification } from '@live-change/framework'
16
+ import { AccessControlSettings } from './types.js'
17
+
18
+ export interface BoundToAnyConfig extends AnyRelationConfig {
19
+ readAccess?: AccessSpecification
20
+ writeAccess?: AccessSpecification
21
+ readAllAccess?: AccessSpecification
22
+ setAccess?: AccessSpecification
23
+ updateAccess?: AccessSpecification
24
+ setOrUpdateAccess?: AccessSpecification
25
+ resetAccess?: AccessSpecification
26
+ singleAccess?: AccessSpecification
27
+ listAccess?: AccessSpecification
28
+
29
+ readAccessControl?: AccessControlSettings
30
+ writeAccessControl?: AccessControlSettings
31
+ readAllAccessControl?: AccessControlSettings
32
+ setAccessControl?: AccessControlSettings
33
+ updateAccessControl?: AccessControlSettings
34
+ setOrUpdateAccessControl?: AccessControlSettings
35
+ resetAccessControl?: AccessControlSettings
36
+ singleAccessControl?: AccessControlSettings
37
+ listAccessControl?: AccessControlSettings
38
+
39
+ views?: {
40
+ type: 'range' | 'object'
41
+ internal?: boolean
42
+ fields?: string[]
43
+ }[]
44
+
45
+ }
14
46
 
15
47
  export default function(service, app) {
16
- processModelsAnyAnnotation(service, app, 'boundToAny', false, (config, context) => {
48
+ processModelsAnyAnnotation<BoundToAnyConfig>(service, app, 'boundToAny', false, (config, context) => {
17
49
 
18
50
  context.relationWord = 'Friend'
19
51
  context.reverseRelationWord = 'Bound'
@@ -24,10 +56,10 @@ export default function(service, app) {
24
56
  defineAnyTypeIndexes(config, context, context.otherPropertyNames.length === 1)
25
57
 
26
58
  defineObjectView(config, context,
27
- config.singleAccess || config.readAccess || config.singleAccessControl || config.readAccessControl
59
+ !!(config.singleAccess || config.readAccess || config.singleAccessControl || config.readAccessControl)
28
60
  )
29
61
  defineRangeViews(config, context,
30
- config.listAccess || config.readAccess || config.listAccessControl || config.readAccessControl
62
+ !!(config.listAccess || config.readAccess || config.listAccessControl || config.readAccessControl)
31
63
  )
32
64
 
33
65
  if(config.views) {
package/src/index.ts ADDED
@@ -0,0 +1,53 @@
1
+ import entity from './entity.js'
2
+
3
+ import propertyOf, { PropertyOfConfig } from './propertyOf.js'
4
+ import itemOf, { ItemOfConfig } from './itemOf.js'
5
+
6
+ import propertyOfAny, { PropertyOfAnyConfig } from './propertyOfAny.js'
7
+ import itemOfAny, { ItemOfAnyConfig } from './itemOfAny.js'
8
+
9
+ import relatedTo, { RelatedToConfig } from './relatedTo.js'
10
+ import relatedToAny, { RelatedToAnyConfig } from './relatedToAny.js'
11
+
12
+ import boundTo, { BoundToConfig } from './boundTo.js'
13
+ import boundToAny, { BoundToAnyConfig } from './boundToAny.js'
14
+ import saveAuthor from './saveAuthor.js'
15
+ import { ModelDefinitionSpecificationWithAccessControl } from './types.js'
16
+ import { SaveAuthorConfig } from './saveAuthor.js'
17
+
18
+ const processors = [
19
+ entity,
20
+ propertyOf, itemOf,
21
+ propertyOfAny, itemOfAny,
22
+ relatedTo, relatedToAny,
23
+ boundTo, boundToAny,
24
+ saveAuthor
25
+ ]
26
+
27
+ const plugin = function(app, services) {
28
+ app.defaultProcessors.push(...processors)
29
+ }
30
+ plugin.processors = processors
31
+
32
+ export default plugin
33
+
34
+ export { processors }
35
+
36
+ export interface MotelWithRelations extends ModelDefinitionSpecificationWithAccessControl {
37
+ propertyOf: PropertyOfConfig
38
+ itemOf: ItemOfConfig
39
+ propertyOfAny: PropertyOfAnyConfig
40
+ itemOfAny: ItemOfAnyConfig
41
+ relatedTo: RelatedToConfig
42
+ relatedToAny: RelatedToAnyConfig
43
+ boundTo: BoundToConfig
44
+ boundToAny: BoundToAnyConfig
45
+ saveAuthor: SaveAuthorConfig
46
+ }
47
+
48
+ export type {
49
+ PropertyOfConfig, ItemOfConfig, PropertyOfAnyConfig, ItemOfAnyConfig,
50
+ RelatedToConfig, RelatedToAnyConfig, BoundToConfig, BoundToAnyConfig,
51
+ SaveAuthorConfig
52
+ }
53
+
@@ -3,7 +3,8 @@ import { defineGlobalRangeView } from './utils.js'
3
3
  import {
4
4
  defineAnyProperties, defineAnyIndexes,
5
5
  processModelsAnyAnnotation, addAccessControlAnyParents, generateAnyId, defineDeleteByOwnerEvents,
6
- defineParentDeleteTrigger, defineAnyTypeIndexes
6
+ defineParentDeleteTrigger, defineAnyTypeIndexes,
7
+ AnyRelationConfig
7
8
  } from './utilsAny.js'
8
9
 
9
10
  import {
@@ -16,15 +17,37 @@ import {
16
17
  defineCreateTrigger, defineUpdateTrigger, defineDeleteTrigger,
17
18
  defineSortIndex
18
19
  } from './pluralRelationAnyUtils.js'
20
+ import { AccessSpecification } from '@live-change/framework'
21
+ import { AccessControlSettings } from './types.js'
22
+
23
+ export interface ItemOfAnyConfig extends AnyRelationConfig {
24
+ readAccess?: AccessSpecification
25
+ writeAccess?: AccessSpecification
26
+ createAccess?: AccessSpecification
27
+ updateAccess?: AccessSpecification
28
+ deleteAccess?: AccessSpecification
29
+ copyAccess?: AccessSpecification
30
+ readAllAccess?: AccessSpecification
31
+
32
+ readAccessControl?: AccessControlSettings
33
+ writeAccessControl?: AccessControlSettings
34
+ createAccessControl?: AccessControlSettings
35
+ updateAccessControl?: AccessControlSettings
36
+ deleteAccessControl?: AccessControlSettings
37
+ copyAccessControl?: AccessControlSettings
38
+ }
19
39
 
20
40
  export default function(service, app) {
21
- processModelsAnyAnnotation(service, app, 'itemOfAny',false, (config, context) => {
41
+ processModelsAnyAnnotation<ItemOfAnyConfig>(service, app, 'itemOfAny',false, (config, context) => {
22
42
 
23
43
  context.relationWord = 'Item'
24
44
  context.reverseRelationWord = 'Owned'
25
45
 
26
46
  context.identifiers = defineAnyProperties(context.model, context.otherPropertyNames, config)
27
- context.model.identifiers = [...Object.keys(context.identifiers), { name: context.modelPropertyName, field: 'id' }]
47
+ context.model.identifiers = [
48
+ ...Object.keys(context.identifiers).map(name => ({ name, field: name })),
49
+ { name: context.modelPropertyName, field: 'id' }
50
+ ]
28
51
 
29
52
  addAccessControlAnyParents(context)
30
53
  defineAnyIndexes(context.model, context.otherPropertyNames)
@@ -37,19 +60,19 @@ export default function(service, app) {
37
60
  }
38
61
 
39
62
  defineSingleView(config, context,
40
- config.readAccess || config.writeAccess || config.readAccessControl || config.writeAccessControl)
63
+ !!(config.readAccess || config.writeAccess || config.readAccessControl || config.writeAccessControl))
41
64
  defineRangeView(config, context,
42
- config.readAccess || config.writeAccess || config.readAccessControl || config.writeAccessControl)
65
+ !!(config.readAccess || config.writeAccess || config.readAccessControl || config.writeAccessControl))
43
66
  /// TODO: multiple views with all properties combinations
44
67
  /// TODO: multiple views with limited fields
45
68
 
46
- defineGlobalRangeView(config, context, config.readAllAccess)
69
+ defineGlobalRangeView(config, context, !!config.readAllAccess)
47
70
 
48
71
  defineCreatedEvent(config, context)
49
72
  defineUpdatedEvent(config, context)
50
73
  defineTransferredEvent(config, context)
51
74
  defineDeletedEvent(config, context)
52
- defineDeleteByOwnerEvents(config, context, generateAnyId)
75
+ defineDeleteByOwnerEvents(config, context)
53
76
 
54
77
  defineCreateTrigger(config, context)
55
78
  defineUpdateTrigger(config, context)
@@ -2,7 +2,8 @@ import {
2
2
  defineProperties, defineIndexes,
3
3
  processModelsAnnotation, generateId, addAccessControlParents,
4
4
  defineDeleteByOwnerEvents, defineParentDeleteTriggers,
5
- defineGlobalRangeView
5
+ defineGlobalRangeView,
6
+ RelationConfig
6
7
  } from './utils.js'
7
8
 
8
9
  import { defineSetEvent, defineUpdatedEvent, defineTransferredEvent, defineResetEvent } from './propertyEvents.js'
@@ -21,9 +22,37 @@ import {
21
22
  defineDeleteTrigger,
22
23
  defineDeleteAction
23
24
  } from './singularRelationUtils.js'
24
-
25
+ import { AccessSpecification } from '@live-change/framework'
26
+ import { AccessControlSettings } from './types.js'
27
+
28
+ export interface PropertyOfConfig extends RelationConfig {
29
+ readAccess?: AccessSpecification
30
+ writeAccess?: AccessSpecification
31
+ listAccess?: AccessSpecification
32
+ setAccess?: AccessSpecification
33
+ updateAccess?: AccessSpecification
34
+ setOrUpdateAccess?: AccessSpecification
35
+ resetAccess?: AccessSpecification
36
+ readAllAccess?: AccessSpecification
37
+
38
+ readAccessControl?: AccessControlSettings
39
+ writeAccessControl?: AccessControlSettings
40
+ listAccessControl?: AccessControlSettings
41
+ setAccessControl?: AccessControlSettings
42
+ updateAccessControl?: AccessControlSettings
43
+ resetAccessControl?: AccessControlSettings
44
+ setOrUpdateAccessControl?: AccessControlSettings
45
+ views?: {
46
+ type: 'range' | 'object'
47
+ internal?: boolean
48
+ readAccess?: AccessSpecification,
49
+ readAccessControl?: AccessControlSettings,
50
+ fields?: string[]
51
+ }[]
52
+ }
53
+
25
54
  export default function(service, app) {
26
- processModelsAnnotation(service, app, 'propertyOf', false, (config, context) => {
55
+ processModelsAnnotation<PropertyOfConfig>(service, app, 'propertyOf', false, (config, context) => {
27
56
 
28
57
  context.relationWord = 'Property'
29
58
  context.reverseRelationWord = 'Owned'
@@ -32,16 +61,18 @@ export default function(service, app) {
32
61
  context.sameIdAsParent = true
33
62
 
34
63
  context.identifiers = defineProperties(context.model, context.others, context.otherPropertyNames)
35
- context.model.identifiers = Object.keys(context.identifiers)
64
+ context.model.identifiers = [
65
+ ...Object.keys(context.identifiers).map(name => ({ name, field: name })),
66
+ { name: context.modelPropertyName, field: 'id' }
67
+ ]
36
68
 
37
69
  addAccessControlParents(context)
38
70
  defineIndexes(context.model, context.otherPropertyNames, context.others)
39
71
 
40
72
  defineObjectView({ ...config }, context,
41
- config.readAccess || config.writeAccess || config.readAccessControl || config.writeAccessControl)
73
+ !!(config.readAccess || config.writeAccess || config.readAccessControl || config.writeAccessControl))
42
74
  defineRangeViews(config, context,
43
- config.listAccess || config.readAccess || config.listAccessControl
44
- )
75
+ !!(config.listAccess || config.readAccess || config.listAccessControl))
45
76
 
46
77
  if(config.views) {
47
78
  for(const view of config.views) {
@@ -53,7 +84,7 @@ export default function(service, app) {
53
84
  }
54
85
  }
55
86
 
56
- defineGlobalRangeView(config, context, config.readAllAccess)
87
+ defineGlobalRangeView(config, context, !!config.readAllAccess)
57
88
 
58
89
  defineSetEvent(config, context, generateId)
59
90
  defineUpdatedEvent(config, context, generateId)
@@ -75,7 +106,7 @@ export default function(service, app) {
75
106
  defineUpdateAction(config, context)
76
107
  }
77
108
 
78
- if((config.setAccess && config.updateAccess) || config.writeAccess
109
+ if((config.setAccess && config.updateAccess && config.setOrUpdateAccess) || config.writeAccess
79
110
  || config.setOrUpdateAccessControl || config.writeAccessControl) {
80
111
  defineSetOrUpdateAction(config, context)
81
112
  }
@@ -24,9 +24,41 @@ import {
24
24
  defineDeleteTrigger,
25
25
  defineDeleteAction
26
26
  } from './singularRelationAnyUtils.js'
27
+ import { AccessSpecification } from '@live-change/framework'
28
+ import { AnyRelationConfig } from './utilsAny.js'
29
+ import { AccessControlSettings } from './types.js'
30
+
31
+ export interface PropertyOfAnyConfig extends AnyRelationConfig {
32
+ readAccess?: AccessSpecification
33
+ writeAccess?: AccessSpecification
34
+ readAllAccess?: AccessSpecification
35
+ setAccess?: AccessSpecification
36
+ updateAccess?: AccessSpecification
37
+ setOrUpdateAccess?: AccessSpecification
38
+ resetAccess?: AccessSpecification
39
+ singleAccess?: AccessSpecification
40
+ listAccess?: AccessSpecification
41
+
42
+ readAccessControl?: AccessControlSettings
43
+ writeAccessControl?: AccessControlSettings
44
+ readAllAccessControl?: AccessControlSettings
45
+ setAccessControl?: AccessControlSettings
46
+ updateAccessControl?: AccessControlSettings
47
+ setOrUpdateAccessControl?: AccessControlSettings
48
+ resetAccessControl?: AccessControlSettings
49
+ singleAccessControl?: AccessControlSettings
50
+ listAccessControl?: AccessControlSettings
51
+
52
+ views?: {
53
+ type: 'range' | 'object'
54
+ internal?: boolean
55
+ fields?: string[]
56
+ }[]
57
+
58
+ }
27
59
 
28
60
  export default function(service, app) {
29
- processModelsAnyAnnotation(service, app, 'propertyOfAny', false, (config, context) => {
61
+ processModelsAnyAnnotation<PropertyOfAnyConfig>(service, app, 'propertyOfAny', false, (config, context) => {
30
62
 
31
63
  context.relationWord = 'Property'
32
64
  context.reverseRelationWord = 'Owned'
@@ -35,18 +67,20 @@ export default function(service, app) {
35
67
  context.sameIdAsParent = true
36
68
 
37
69
  context.identifiers = defineAnyProperties(context.model, context.otherPropertyNames, config)
38
- context.model.identifiers = Object.keys(context.identifiers)
70
+ context.model.identifiers = [
71
+ ...Object.keys(context.identifiers).map(name => ({ name, field: name }))
72
+ ]
39
73
 
40
74
  addAccessControlAnyParents(context)
41
75
  defineAnyIndexes(context.model, context.otherPropertyNames, false)
42
76
  defineAnyTypeIndexes(config, context, context.otherPropertyNames.length === 1)
43
77
 
44
78
  defineObjectView(config, context,
45
- config.singleAccess || config.readAccess || config.singleAccessControl || config.readAccessControl
79
+ !!(config.singleAccess || config.readAccess || config.singleAccessControl || config.readAccessControl)
46
80
  )
47
81
 
48
82
  defineRangeViews(config, context,
49
- config.listAccess || config.readAccess || config.listAccessControl || config.readAccessControl
83
+ !!(config.listAccess || config.readAccess || config.listAccessControl || config.readAccessControl)
50
84
  )
51
85
 
52
86
  if(config.views) {
@@ -59,13 +93,13 @@ export default function(service, app) {
59
93
  }
60
94
  }
61
95
 
62
- defineGlobalRangeView(config, context, config.readAllAccess)
96
+ defineGlobalRangeView(config, context, !!config.readAllAccess)
63
97
 
64
98
  defineSetEvent(config, context, generateAnyId)
65
99
  defineUpdatedEvent(config, context, generateAnyId)
66
100
  defineTransferredEvent(config, context, generateAnyId)
67
101
  defineResetEvent(config, context, generateAnyId)
68
- defineDeleteByOwnerEvents(config, context, generateAnyId)
102
+ defineDeleteByOwnerEvents(config, context)
69
103
 
70
104
  defineSetTrigger(config, context)
71
105
  defineUpdateTrigger(config, context)
@@ -1,5 +1,6 @@
1
1
  import {
2
- defineProperties, defineIndex, processModelsAnnotation
2
+ defineProperties, defineIndex, processModelsAnnotation,
3
+ RelationConfig
3
4
  } from './utils.js'
4
5
 
5
6
  import {
@@ -12,9 +13,30 @@ import {
12
13
  defineCreateTrigger, defineUpdateTrigger, defineDeleteTrigger, defineCopyTrigger,
13
14
  defineSortIndex,
14
15
  } from './pluralRelationUtils.js'
16
+ import { AccessSpecification } from '@live-change/framework'
17
+ import { AccessControlSettings } from './types.js'
18
+
19
+ export interface RelatedToConfig extends RelationConfig {
20
+ readAccess?: AccessSpecification
21
+ writeAccess?: AccessSpecification
22
+ createAccess?: AccessSpecification
23
+ updateAccess?: AccessSpecification
24
+ deleteAccess?: AccessSpecification
25
+ copyAccess?: AccessSpecification
26
+ readAllAccess?: AccessSpecification
27
+
28
+ readAccessControl?: AccessControlSettings
29
+ writeAccessControl?: AccessControlSettings
30
+ createAccessControl?: AccessControlSettings
31
+ updateAccessControl?: AccessControlSettings
32
+ deleteAccessControl?: AccessControlSettings
33
+ copyAccessControl?: AccessControlSettings
34
+ readAllAccessControl?: AccessControlSettings
35
+ }
36
+
15
37
 
16
38
  export default function(service, app) {
17
- processModelsAnnotation(service, app, 'relatedTo', true, (config, context) => {
39
+ processModelsAnnotation<RelatedToConfig>(service, app, 'relatedTo', true, (config, context) => {
18
40
 
19
41
  context.relationWord = 'Friend'
20
42
  context.reverseRelationWord = 'Related'
@@ -29,10 +51,10 @@ export default function(service, app) {
29
51
  }
30
52
 
31
53
  defineSingleView(config, context,
32
- config.readAccess || config.readAccessControl || config.writeAccessControl
54
+ !!(config.readAccess || config.readAccessControl || config.writeAccessControl)
33
55
  )
34
56
  defineRangeView(config, context,
35
- config.readAccess || config.readAccessControl || config.writeAccessControl
57
+ !!(config.readAccess || config.readAccessControl || config.writeAccessControl)
36
58
  )
37
59
  /// TODO: multiple views with limited fields
38
60
 
@@ -1,5 +1,6 @@
1
1
  import {
2
- defineAnyProperties, defineAnyIndex, processModelsAnyAnnotation, defineAnyTypeIndexes
2
+ defineAnyProperties, defineAnyIndex, processModelsAnyAnnotation, defineAnyTypeIndexes,
3
+ AnyRelationConfig
3
4
  } from './utilsAny.js'
4
5
 
5
6
  import {
@@ -12,9 +13,28 @@ import {
12
13
  defineCreateTrigger, defineUpdateTrigger, defineDeleteTrigger,
13
14
  defineSortIndex
14
15
  } from './pluralRelationAnyUtils.js'
16
+ import { AccessSpecification } from '@live-change/framework'
17
+ import { AccessControlSettings } from './types.js'
18
+
19
+ export interface RelatedToAnyConfig extends AnyRelationConfig {
20
+ readAccess?: AccessSpecification
21
+ writeAccess?: AccessSpecification
22
+ createAccess?: AccessSpecification
23
+ updateAccess?: AccessSpecification
24
+ deleteAccess?: AccessSpecification
25
+ copyAccess?: AccessSpecification
26
+ readAllAccess?: AccessSpecification
27
+
28
+ readAccessControl?: AccessControlSettings
29
+ writeAccessControl?: AccessControlSettings
30
+ createAccessControl?: AccessControlSettings
31
+ updateAccessControl?: AccessControlSettings
32
+ deleteAccessControl?: AccessControlSettings
33
+ copyAccessControl?: AccessControlSettings
34
+ }
15
35
 
16
36
  export default function(service, app) {
17
- processModelsAnyAnnotation(service, app, 'relatedToAny',true, (config, context) => {
37
+ processModelsAnyAnnotation<RelatedToAnyConfig>(service, app, 'relatedToAny',true, (config, context) => {
18
38
 
19
39
  context.relationWord = 'Friend'
20
40
  context.reverseRelationWord = 'Related'
@@ -30,10 +50,10 @@ export default function(service, app) {
30
50
  }
31
51
 
32
52
  defineSingleView(config, context,
33
- config.readAccess || config.readAccessControl || config.writeAccessControl
53
+ !!(config.readAccess || config.readAccessControl || config.writeAccessControl)
34
54
  )
35
55
  defineRangeView(config, context,
36
- config.readAccess || config.readAccessControl || config.writeAccessControl
56
+ !!(config.readAccess || config.readAccessControl || config.writeAccessControl)
37
57
  )
38
58
  /// TODO: multiple views with limited fields
39
59
 
@@ -32,6 +32,11 @@ export function defineUpdaterProperties() {
32
32
  }
33
33
  }
34
34
 
35
+ export interface SaveAuthorConfig {
36
+ saveAuthor?: boolean
37
+ saveUpdater?: boolean
38
+ }
39
+
35
40
  export default function(service, app) {
36
41
  for(let modelName in service.models) {
37
42
  const model = service.models[modelName]
package/src/utils.ts CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  registerParentDeleteTriggers, registerParentCopyTriggers
6
6
  } from "./changeTriggers.js"
7
7
  import {
8
- PropertyDefinition, ViewDefinition, IndexDefinition, ActionDefinition, EventDefinition, TriggerDefinition,
8
+ PropertyDefinition, ViewDefinition, EventDefinition,
9
9
  ServiceDefinitionSpecification,
10
10
  PropertyDefinitionSpecification
11
11
  } from "@live-change/framework"
@@ -122,7 +122,9 @@ interface RelationContext {
122
122
  others: any[],
123
123
  reverseRelationWord?: string
124
124
  relationWord?: string,
125
+ partialReverseRelationWord?: string,
125
126
  identifiers?: Record<string, PropertyDefinition<PropertyDefinitionSpecification>>
127
+ sameIdAsParent?: boolean
126
128
  }
127
129
 
128
130
  export function processModelsAnnotation<PreparedConfig extends RelationConfig>
@@ -1,10 +1,11 @@
1
- import App from "@live-change/framework"
1
+ import App, { AccessSpecification, PropertyDefinitionSpecification, ServiceDefinition, ServiceDefinitionSpecification } from "@live-change/framework"
2
2
  const app = App.app()
3
3
  import {
4
- PropertyDefinition, ViewDefinition, IndexDefinition, ActionDefinition, EventDefinition, TriggerDefinition
4
+ PropertyDefinition, EventDefinition,
5
5
  } from "@live-change/framework"
6
6
  import { allCombinations } from "./combinations.js"
7
7
  import { registerParentDeleteTriggers } from "./changeTriggers.js"
8
+ import { ModelDefinitionSpecificationWithAccessControl } from "./types.js"
8
9
 
9
10
 
10
11
  export function extractTypeAndIdParts(otherPropertyNames, properties) {
@@ -62,10 +63,10 @@ export function defineAnyProperties(model, names, config) {
62
63
  }
63
64
 
64
65
  export function defineAnyIndex(model, what, props) {
65
- model.indexes['by' + what] = new IndexDefinition({
66
+ model.indexes['by' + what] = {
66
67
  property: props.map(prop => [prop+'Type', prop]).flat(),
67
68
  hash: true
68
- })
69
+ }
69
70
  }
70
71
 
71
72
  export function defineAnyIndexes(model, props, fullIndex = true) {
@@ -77,7 +78,50 @@ export function defineAnyIndexes(model, props, fullIndex = true) {
77
78
  }
78
79
  }
79
80
 
80
- export function processModelsAnyAnnotation(service, app, annotation, multiple, cb) {
81
+ export interface AnyRelationConfig {
82
+ what: string | string[]
83
+ propertyNames?: string[]
84
+ writeableProperties?: string[]
85
+ prefix?: string
86
+ suffix?: string
87
+ globalView?: boolean
88
+ readAllAccess?: AccessSpecification
89
+ sortBy?: string[],
90
+ customDeleteTrigger?: boolean, /// TODO: check if this is needed
91
+ customParentCopyTrigger?: boolean /// TODO: check if this is needed
92
+ }
93
+
94
+ export interface ModelDefinitionSpecificationWithAnyRelation extends ModelDefinitionSpecificationWithAccessControl {
95
+ }
96
+
97
+ interface AnyRelationContext {
98
+ service: ServiceDefinition<ServiceDefinitionSpecification>
99
+ app: App
100
+ model: ModelDefinitionSpecificationWithAnyRelation
101
+ originalModelProperties: Record<string, PropertyDefinitionSpecification>
102
+ modelProperties: string[]
103
+ modelPropertyName: string
104
+ modelName: string
105
+ modelRuntime: any
106
+ annotation: string,
107
+ otherPropertyNames: string[]
108
+ joinedOthersPropertyName: string
109
+ joinedOthersClassName: string
110
+ writeableProperties: string[]
111
+ others: any[],
112
+ objectType: string
113
+ parentsTypes: string[]
114
+ otherPossibleTypes: string[][],
115
+ reverseRelationWord?: string,
116
+ relationWord?: string,
117
+ partialReverseRelationWord?: string,
118
+ identifiers?: Record<string, PropertyDefinition<PropertyDefinitionSpecification>>
119
+ sameIdAsParent?: boolean
120
+ }
121
+
122
+ export function processModelsAnyAnnotation<PreparedConfig extends AnyRelationConfig>
123
+ (service: ServiceDefinition<ServiceDefinitionSpecification>, app: App, annotation: string, multiple: boolean,
124
+ cb: (config: PreparedConfig, context: AnyRelationContext) => void) {
81
125
  if (!service) throw new Error("no service")
82
126
  if (!app) throw new Error("no app")
83
127
 
@@ -137,12 +181,13 @@ export function processModelsAnyAnnotation(service, app, annotation, multiple, c
137
181
  const joinedOthersClassName = others.join('And')
138
182
  const objectType = service.name + '_' + modelName
139
183
 
140
- const parentsTypes = Array.from(new Set(
184
+ const parentsTypes: string[] = Array.from(new Set(
141
185
  (config.parentsTypes || [])
142
186
  .concat(otherPossibleTypes.filter(x => !!x).flat()
143
187
  )))
144
188
 
145
- const context = {
189
+ const context: AnyRelationContext = {
190
+ annotation,
146
191
  service, app, model, originalModelProperties, modelProperties, modelPropertyName, modelRuntime,
147
192
  otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName, others,
148
193
  objectType, parentsTypes, otherPossibleTypes
@@ -241,7 +286,7 @@ export function defineAnyTypeIndexes(config, context, useId = false) {
241
286
  const tableName = service.name + '_' + model.name
242
287
  if(useId) { // don't use indexes - only object id's - good for propertyOfAny with one parent
243
288
  if(context.otherPossibleTypes[0]?.length) return // types defined in definition - no need for index
244
- model.indexes[context.otherPropertyNames[0]+'Types'] = new IndexDefinition({
289
+ model.indexes[context.otherPropertyNames[0]+'Types'] = {
245
290
  //property: [propertyName+'Type'],
246
291
  function: async function(input, output, { tableName }) {
247
292
  const table = await input.table(tableName)
@@ -263,7 +308,7 @@ export function defineAnyTypeIndexes(config, context, useId = false) {
263
308
  })
264
309
  },
265
310
  parameters: { tableName: tableName }
266
- })
311
+ }
267
312
  return
268
313
  }
269
314
  for(let i = 0; i < context.otherPropertyNames.length; i++) {
@@ -272,7 +317,7 @@ export function defineAnyTypeIndexes(config, context, useId = false) {
272
317
  if(propertyTypes.length !== 0) continue // types defined in definition - no need for index
273
318
  const srcIndexName = 'by' + propertyName[0].toUpperCase() + propertyName.slice(1)
274
319
  if(!model.indexes[srcIndexName]) throw new Error("Parent index not defined: " + srcIndexName)
275
- model.indexes[propertyName+'Types'] = new IndexDefinition({
320
+ model.indexes[propertyName+'Types'] = {
276
321
  //property: [propertyName+'Type'],
277
322
  function: async function(input, output, { indexName }) {
278
323
  const index = await input.index(indexName)
@@ -294,6 +339,6 @@ export function defineAnyTypeIndexes(config, context, useId = false) {
294
339
  })
295
340
  },
296
341
  parameters: { indexName: tableName + '_' + srcIndexName }
297
- })
342
+ }
298
343
  }
299
344
  }
package/tsconfig.json CHANGED
@@ -21,7 +21,7 @@
21
21
  "skipLibCheck": true,
22
22
  "noImplicitAny": false
23
23
  },
24
- "files": ["src/index.js"],
24
+ "files": ["src/index.ts"],
25
25
  "include": ["src/**/*.ts", "src/**/*.js"],
26
26
  "exclude": ["node_modules/@types", "node_modules/**/*.d.ts", "**/*.test.js", "**/CMakeFiles/**"]
27
27
  }
package/typedoc.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "entryPoints": ["src/index.ts"],
3
+ "out": "../../docs/docs/relations",
4
+ "includeVersion": true,
5
+ "excludePrivate": true,
6
+ "excludeInternal": true,
7
+ "excludeProtected": true,
8
+ "tsconfig": "./tsconfig.json",
9
+ "plugin": [
10
+ "typedoc-plugin-markdown",
11
+ "typedoc-plugin-rename-defaults"
12
+ ],
13
+ "sourceLinkTemplate": "https://github.com/live-change/live-change-stack/blob/master/framework/relations-plugin/{path}#L{line}"
14
+ }
package/src/index.js DELETED
@@ -1,33 +0,0 @@
1
- import entity from './entity.js'
2
-
3
- import propertyOf from './propertyOf.js'
4
- import itemOf from './itemOf.js'
5
-
6
- import propertyOfAny from './propertyOfAny.js'
7
- import itemOfAny from './itemOfAny.js'
8
-
9
- import relatedTo from './relatedTo.js'
10
- import relatedToAny from './relatedToAny.js'
11
-
12
- import boundTo from './boundTo.js'
13
- import boundToAny from './boundToAny.js'
14
- import saveAuthor from './saveAuthor.js'
15
-
16
-
17
- const processors = [
18
- entity,
19
- propertyOf, itemOf,
20
- propertyOfAny, itemOfAny,
21
- relatedTo, relatedToAny,
22
- boundTo, boundToAny,
23
- saveAuthor
24
- ]
25
-
26
- const plugin = function(app, services) {
27
- app.defaultProcessors.push(...processors)
28
- }
29
- plugin.processors = processors
30
-
31
- export default plugin
32
-
33
- export { processors }