@live-change/relations-plugin 0.1.13 → 0.1.16
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 +7 -0
- package/itemEvents.js +16 -1
- package/itemOf.js +4 -2
- package/itemOfAny.js +7 -5
- package/package.json +1 -1
- package/propertyEvents.js +29 -6
- package/propertyOf.js +5 -4
- package/propertyOfAny.js +5 -4
package/index.js
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
const propertyOf = require('./propertyOf.js')
|
|
2
2
|
const itemOf = require('./itemOf.js')
|
|
3
3
|
|
|
4
|
+
const propertyOfAny = require('./propertyOfAny.js')
|
|
5
|
+
const itemOfAny = require('./itemOfAny.js')
|
|
6
|
+
|
|
4
7
|
module.exports = function(app, services) {
|
|
5
8
|
|
|
6
9
|
app.defaultProcessors.push(propertyOf)
|
|
7
10
|
app.defaultProcessors.push(itemOf)
|
|
11
|
+
|
|
12
|
+
app.defaultProcessors.push(propertyOfAny)
|
|
13
|
+
app.defaultProcessors.push(itemOfAny)
|
|
14
|
+
|
|
8
15
|
}
|
|
9
16
|
|
|
10
17
|
module.exports.processors = [ propertyOf, itemOf ]
|
package/itemEvents.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const App = require("@live-change/framework")
|
|
2
|
+
const { PropertyDefinition, ViewDefinition, IndexDefinition, ActionDefinition, EventDefinition } = App
|
|
1
3
|
|
|
2
4
|
function defineCreatedEvent(config, context) {
|
|
3
5
|
const {
|
|
@@ -27,6 +29,19 @@ function defineUpdatedEvent(config, context) {
|
|
|
27
29
|
})
|
|
28
30
|
}
|
|
29
31
|
|
|
32
|
+
function defineTransferredEvent(config, context) {
|
|
33
|
+
const {
|
|
34
|
+
service, modelRuntime, joinedOthersPropertyName, modelName, modelPropertyName
|
|
35
|
+
} = context
|
|
36
|
+
const eventName = joinedOthersPropertyName + 'Owned' + modelName + 'Transferred'
|
|
37
|
+
service.events[eventName] = new EventDefinition({
|
|
38
|
+
name: eventName,
|
|
39
|
+
execute(properties) {
|
|
40
|
+
const id = properties[modelPropertyName]
|
|
41
|
+
return modelRuntime().update(id, { ...properties.to, id })
|
|
42
|
+
}
|
|
43
|
+
})
|
|
44
|
+
}
|
|
30
45
|
|
|
31
46
|
function defineDeletedEvent(config, context) {
|
|
32
47
|
const {
|
|
@@ -42,4 +57,4 @@ function defineDeletedEvent(config, context) {
|
|
|
42
57
|
})
|
|
43
58
|
}
|
|
44
59
|
|
|
45
|
-
module.exports = { defineCreatedEvent, defineUpdatedEvent, defineDeletedEvent }
|
|
60
|
+
module.exports = { defineCreatedEvent, defineUpdatedEvent, defineTransferredEvent, defineDeletedEvent }
|
package/itemOf.js
CHANGED
|
@@ -41,8 +41,9 @@ function defineView(config, context) {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
const {
|
|
44
|
-
defineCreatedEvent, defineUpdatedEvent, defineDeletedEvent
|
|
45
|
-
} = require('itemEvents.js')
|
|
44
|
+
defineCreatedEvent, defineUpdatedEvent, defineDeletedEvent, defineTransferredEvent,
|
|
45
|
+
} = require('./itemEvents.js')
|
|
46
|
+
const {defineTransferEvent} = require("./itemEvents");
|
|
46
47
|
|
|
47
48
|
function defineCreateAction(config, context) {
|
|
48
49
|
const {
|
|
@@ -180,6 +181,7 @@ module.exports = function(service, app) {
|
|
|
180
181
|
|
|
181
182
|
defineCreatedEvent(config, context)
|
|
182
183
|
defineUpdatedEvent(config, context)
|
|
184
|
+
defineTransferredEvent(config, context)
|
|
183
185
|
defineDeletedEvent(config, context)
|
|
184
186
|
|
|
185
187
|
if(config.setAccess || config.writeAccess) {
|
package/itemOfAny.js
CHANGED
|
@@ -49,8 +49,9 @@ function defineView(config, context) {
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
const {
|
|
52
|
-
defineCreatedEvent, defineUpdatedEvent, defineDeletedEvent
|
|
53
|
-
} = require('itemEvents.js')
|
|
52
|
+
defineCreatedEvent, defineUpdatedEvent, defineDeletedEvent, defineTransferredEvent,
|
|
53
|
+
} = require('./itemEvents.js')
|
|
54
|
+
const {defineTransferEvent} = require("./itemEvents");
|
|
54
55
|
|
|
55
56
|
function defineCreateAction(config, context) {
|
|
56
57
|
const {
|
|
@@ -102,7 +103,7 @@ function defineUpdateAction(config, context) {
|
|
|
102
103
|
skipValidation: true,
|
|
103
104
|
//queuedBy: otherPropertyNames,
|
|
104
105
|
waitForEvents: true,
|
|
105
|
-
async execute(properties, {client, service}, emit) {
|
|
106
|
+
async execute(properties, { client, service }, emit) {
|
|
106
107
|
const id = properties[modelPropertyName]
|
|
107
108
|
const entity = await modelRuntime().get(id)
|
|
108
109
|
if(!entity) throw 'not_found'
|
|
@@ -142,7 +143,7 @@ function defineDeleteAction(config, context) {
|
|
|
142
143
|
skipValidation: true,
|
|
143
144
|
//queuedBy: otherPropertyNames,
|
|
144
145
|
waitForEvents: true,
|
|
145
|
-
async execute(properties, {client, service}, emit) {
|
|
146
|
+
async execute(properties, { client, service }, emit) {
|
|
146
147
|
const id = properties[modelPropertyName]
|
|
147
148
|
const entity = await modelRuntime().get(id)
|
|
148
149
|
if(!entity) throw new Error('not_found')
|
|
@@ -162,7 +163,7 @@ function defineDeleteAction(config, context) {
|
|
|
162
163
|
function defineSortIndex(context, sortFields) {
|
|
163
164
|
if(!Array.isArray(sortFields)) sortFields = [sortFields]
|
|
164
165
|
console.log("DEFINE SORT INDEX", sortFields)
|
|
165
|
-
const sortFieldsUc = sortFields.map(fd=>fd.slice(0, 1).toUpperCase() + fd.slice(1))
|
|
166
|
+
const sortFieldsUc = sortFields.map(fd => fd.slice(0, 1).toUpperCase() + fd.slice(1))
|
|
166
167
|
const indexName = 'by' + context.joinedOthersClassName + sortFieldsUc.join('')
|
|
167
168
|
context.model.indexes[indexName] = new IndexDefinition({
|
|
168
169
|
property: [...(context.otherPropertyNames.map(prop => [prop + 'Type', prop])), ...sortFields]
|
|
@@ -188,6 +189,7 @@ module.exports = function(service, app) {
|
|
|
188
189
|
|
|
189
190
|
defineCreatedEvent(config, context)
|
|
190
191
|
defineUpdatedEvent(config, context)
|
|
192
|
+
defineTransferredEvent(config, context)
|
|
191
193
|
defineDeletedEvent(config, context)
|
|
192
194
|
|
|
193
195
|
if(config.setAccess || config.writeAccess) {
|
package/package.json
CHANGED
package/propertyEvents.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
const
|
|
1
|
+
const App = require("@live-change/framework")
|
|
2
|
+
const { PropertyDefinition, ViewDefinition, IndexDefinition, ActionDefinition, EventDefinition } = App
|
|
2
3
|
|
|
3
|
-
function defineSetEvent(config, context) {
|
|
4
|
+
function defineSetEvent(config, context, generateId) {
|
|
4
5
|
const {
|
|
5
6
|
service, modelRuntime, joinedOthersPropertyName, modelName, otherPropertyNames
|
|
6
7
|
} = context
|
|
@@ -14,7 +15,7 @@ function defineSetEvent(config, context) {
|
|
|
14
15
|
})
|
|
15
16
|
}
|
|
16
17
|
|
|
17
|
-
function
|
|
18
|
+
function defineUpdatedEvent(config, context, generateId) {
|
|
18
19
|
const {
|
|
19
20
|
service, modelRuntime, joinedOthersPropertyName, modelName, otherPropertyNames
|
|
20
21
|
} = context
|
|
@@ -23,12 +24,34 @@ function defineUpdateEvent(config, context) {
|
|
|
23
24
|
name: eventName,
|
|
24
25
|
execute(properties) {
|
|
25
26
|
const id = generateId(otherPropertyNames, properties.identifiers)
|
|
26
|
-
return modelRuntime().update(id, { ...properties.data,
|
|
27
|
+
return modelRuntime().update(id, { ...properties.data, /*...properties.identifiers*/ })
|
|
27
28
|
}
|
|
28
29
|
})
|
|
29
30
|
}
|
|
30
31
|
|
|
31
|
-
function
|
|
32
|
+
function defineTransferredEvent(config, context, generateId) {
|
|
33
|
+
const {
|
|
34
|
+
service, modelRuntime, joinedOthersPropertyName, modelName, otherPropertyNames
|
|
35
|
+
} = context
|
|
36
|
+
const eventName = joinedOthersPropertyName + 'Owned' + modelName + 'Transferred'
|
|
37
|
+
service.events[eventName] = new EventDefinition({
|
|
38
|
+
name: eventName,
|
|
39
|
+
async execute(properties) {
|
|
40
|
+
const fromId = generateId(otherPropertyNames, properties.from)
|
|
41
|
+
const toId = generateId(otherPropertyNames, properties.to)
|
|
42
|
+
const data = await modelRuntime().get(fromId)
|
|
43
|
+
await modelRuntime().create({
|
|
44
|
+
...data,
|
|
45
|
+
...properties.to,
|
|
46
|
+
id: toId
|
|
47
|
+
})
|
|
48
|
+
await modelRunntime().delete(fromId)
|
|
49
|
+
return toId
|
|
50
|
+
}
|
|
51
|
+
})
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function defineResetEvent(config, context, generateId) {
|
|
32
55
|
const {
|
|
33
56
|
service, modelRuntime, joinedOthersPropertyName, modelName, otherPropertyNames
|
|
34
57
|
} = context
|
|
@@ -42,4 +65,4 @@ function defineResetEvent(config, context) {
|
|
|
42
65
|
})
|
|
43
66
|
}
|
|
44
67
|
|
|
45
|
-
module.exports = { defineSetEvent,
|
|
68
|
+
module.exports = { defineSetEvent, defineUpdatedEvent, defineTransferredEvent, defineResetEvent }
|
package/propertyOf.js
CHANGED
|
@@ -37,7 +37,7 @@ function defineView(config, context) {
|
|
|
37
37
|
})
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
const { defineSetEvent,
|
|
40
|
+
const { defineSetEvent, defineUpdatedEvent, defineTransferredEvent, defineResetEvent } = require('./propertyEvents.js')
|
|
41
41
|
|
|
42
42
|
function defineSetAction(config, context) {
|
|
43
43
|
const {
|
|
@@ -150,9 +150,10 @@ module.exports = function(service, app) {
|
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
-
defineSetEvent(config, context)
|
|
154
|
-
defineUpdateEvent(config, context)
|
|
155
|
-
|
|
153
|
+
defineSetEvent(config, context, generateId)
|
|
154
|
+
defineUpdateEvent(config, context, generateId)
|
|
155
|
+
defineTransferEvent(config, context, generateId)
|
|
156
|
+
defineResetEvent(config, context, generateId)
|
|
156
157
|
|
|
157
158
|
if(config.setAccess || config.writeAccess) {
|
|
158
159
|
defineSetAction(config, context)
|
package/propertyOfAny.js
CHANGED
|
@@ -45,7 +45,7 @@ function defineView(config, context) {
|
|
|
45
45
|
})
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
const { defineSetEvent,
|
|
48
|
+
const { defineSetEvent, defineUpdatedEvent, defineTransferredEvent, defineResetEvent } = require('./propertyEvents.js')
|
|
49
49
|
|
|
50
50
|
function defineSetAction(config, context) {
|
|
51
51
|
const {
|
|
@@ -158,9 +158,10 @@ module.exports = function(service, app) {
|
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
160
|
|
|
161
|
-
defineSetEvent(config, context)
|
|
162
|
-
|
|
163
|
-
|
|
161
|
+
defineSetEvent(config, context, generateAnyId)
|
|
162
|
+
defineUpdatedEvent(config, context, generateAnyId)
|
|
163
|
+
defineTransferredEvent(config, context, generateAnyId)
|
|
164
|
+
defineResetEvent(config, context, generateAnyId)
|
|
164
165
|
|
|
165
166
|
if(config.setAccess || config.writeAccess) {
|
|
166
167
|
defineSetAction(config, context)
|