@live-change/relations-plugin 0.9.42 → 0.9.44

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/changeTriggers.js CHANGED
@@ -3,23 +3,24 @@ import {
3
3
  TriggerDefinition
4
4
  } from "@live-change/framework"
5
5
 
6
- async function fireChangeTriggers(context, objectType, identifiers, object, oldData, data) {
6
+ async function fireChangeTriggers(context, objectType, identifiers, object, oldData, data,
7
+ trigger = (...args) => app.trigger(...args)) {
7
8
  const { service, modelName, app } = context
8
9
  const changeType = data ? (oldData ? 'update' : 'create') : 'delete'
9
10
  //console.log("FIRE CHANGE TRIGGERS", { context, objectType, identifiers, object, oldData, data })
10
11
  //console.trace()
11
12
  const triggerParameters = { objectType, object, identifiers, data, oldData, changeType }
12
13
  await Promise.all([
13
- app.trigger({
14
+ trigger({
14
15
  type: changeType + service.name[0].toUpperCase() + service.name.slice(1) + '_' + modelName,
15
16
  }, triggerParameters),
16
- app.trigger({
17
+ trigger({
17
18
  type: changeType + 'Object',
18
19
  }, triggerParameters),
19
- app.trigger({
20
+ trigger({
20
21
  type: 'change' + service.name[0].toUpperCase() + service.name.slice(1) + '_' + modelName,
21
22
  }, triggerParameters),
22
- app.trigger({
23
+ trigger({
23
24
  type: 'changeObject',
24
25
  }, triggerParameters)
25
26
  ])
package/entity.js CHANGED
@@ -142,7 +142,7 @@ function getCreateFunction( validators, validationContext, config, context) {
142
142
  modelName, writeableProperties
143
143
  } = context
144
144
  const eventName = modelName + 'Created'
145
- async function execute(properties, { client, service }, emit) {
145
+ async function execute(properties, { client, service, trigger }, emit) {
146
146
  const id = properties[modelPropertyName] || app.generateUid()
147
147
  const entity = await modelRuntime().get(id)
148
148
  if(entity) throw 'exists'
@@ -153,7 +153,7 @@ function getCreateFunction( validators, validationContext, config, context) {
153
153
  validationContext)
154
154
 
155
155
  await fireChangeTriggers(context, objectType, null, id,
156
- entity ? extractObjectData(writeableProperties, entity, {}) : null, data)
156
+ entity ? extractObjectData(writeableProperties, entity, {}) : null, data, trigger)
157
157
  emit({
158
158
  type: eventName,
159
159
  [modelPropertyName]: id,
@@ -213,7 +213,7 @@ function getUpdateFunction( validators, validationContext, config, context) {
213
213
  modelName, writeableProperties
214
214
  } = context
215
215
  const eventName = modelName + 'Updated'
216
- async function execute(properties, { client, service }, emit) {
216
+ async function execute(properties, { client, service, trigger }, emit) {
217
217
  const id = properties[modelPropertyName]
218
218
  const entity = await modelRuntime().get(id)
219
219
  if(!entity) throw 'not_found'
@@ -224,7 +224,7 @@ function getUpdateFunction( validators, validationContext, config, context) {
224
224
  await App.validation.validate({ ...data }, validators,
225
225
  validationContext)
226
226
  await fireChangeTriggers(context, objectType, null, id,
227
- entity ? extractObjectData(writeableProperties, entity, {}) : null, data)
227
+ entity ? extractObjectData(writeableProperties, entity, {}) : null, data, trigger)
228
228
  emit({
229
229
  type: eventName,
230
230
  [modelPropertyName]: id,
@@ -293,12 +293,12 @@ function getDeleteFunction(config, context) {
293
293
  otherPropertyNames, modelName, writeableProperties,
294
294
  } = context
295
295
  const eventName = modelName + 'Deleted'
296
- async function execute(properties, { client, service }, emit) {
296
+ async function execute(properties, { client, service, trigger }, emit) {
297
297
  const id = properties[modelPropertyName]
298
298
  const entity = await modelRuntime().get(id)
299
299
  if(!entity) throw new Error('not_found')
300
300
  await fireChangeTriggers(context, objectType, null, id,
301
- entity ? extractObjectData(writeableProperties, entity, {}) : null, null)
301
+ entity ? extractObjectData(writeableProperties, entity, {}) : null, null, trigger)
302
302
  emit({
303
303
  type: eventName,
304
304
  [modelPropertyName]: id
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/relations-plugin",
3
- "version": "0.9.42",
3
+ "version": "0.9.44",
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.42",
25
+ "@live-change/framework": "^0.9.44",
26
26
  "pluralize": "^8.0.0"
27
27
  },
28
- "gitHead": "6571e1434eed33df905a7708aad783e9339968f1"
28
+ "gitHead": "6e9cf980b2ac6e4e7d78955cbf97ae1c2963bcab"
29
29
  }
@@ -99,7 +99,7 @@ function getCreateFunction( validators, validationContext, config, context) {
99
99
  otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName
100
100
  } = context
101
101
  const eventName = modelName + 'Created'
102
- return async function execute(properties, { client, service }, emit) {
102
+ return async function execute(properties, { client, service, trigger }, emit) {
103
103
  const id = properties[modelPropertyName] || app.generateUid()
104
104
  const entity = await modelRuntime().get(id)
105
105
  if(entity) throw 'exists'
@@ -108,7 +108,7 @@ function getCreateFunction( validators, validationContext, config, context) {
108
108
  App.computeDefaults(model, properties, { client, service } ))
109
109
  await App.validation.validate({ ...identifiers, ...data }, validators,
110
110
  validationContext)
111
- await fireChangeTriggers(context, objectType, identifiers, id, null, data)
111
+ await fireChangeTriggers(context, objectType, identifiers, id, null, data, trigger)
112
112
  emit({
113
113
  type: eventName,
114
114
  [modelPropertyName]: id,
@@ -177,7 +177,7 @@ function getUpdateFunction( validators, validationContext, config, context) {
177
177
  otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName
178
178
  } = context
179
179
  const eventName = modelName + 'Updated'
180
- return async function execute(properties, { client, service }, emit) {
180
+ return async function execute(properties, { client, service, trigger }, emit) {
181
181
  const id = properties[modelPropertyName]
182
182
  if(!id) throw new Error('no_id')
183
183
  const entity = await modelRuntime().get(id)
@@ -197,7 +197,7 @@ function getUpdateFunction( validators, validationContext, config, context) {
197
197
  await App.validation.validate({ ...identifiers, ...data, [modelPropertyName]: id }, validators,
198
198
  validationContext)
199
199
  await fireChangeTriggers(context, objectType, identifiers, id,
200
- extractObjectData(writeableProperties, entity, {}), data)
200
+ extractObjectData(writeableProperties, entity, {}), data, trigger)
201
201
  emit({
202
202
  type: eventName,
203
203
  [modelPropertyName]: id,
@@ -276,7 +276,7 @@ function getDeleteFunction(config, context) {
276
276
  otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName
277
277
  } = context
278
278
  const eventName = modelName + 'Deleted'
279
- return async function execute(properties, { client, service }, emit) {
279
+ return async function execute(properties, { client, service, trigger }, emit) {
280
280
  const id = properties[modelPropertyName]
281
281
  const entity = await modelRuntime().get(id)
282
282
  if(!entity) throw 'not_found'
@@ -286,7 +286,7 @@ function getDeleteFunction(config, context) {
286
286
  throw 'not_authorized'
287
287
  }
288
288
  await fireChangeTriggers(context, objectType, extractIdentifiers(otherPropertyNames, entity), id,
289
- extractObjectData(writeableProperties, entity, {}), null)
289
+ extractObjectData(writeableProperties, entity, {}), null, trigger)
290
290
  emit({
291
291
  type: eventName,
292
292
  [modelPropertyName]: id
@@ -94,7 +94,7 @@ function getCreateFunction( validators, validationContext, config, context) {
94
94
  otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName, others
95
95
  } = context
96
96
  const eventName = modelName + 'Created'
97
- return async function execute(properties, { client, service }, emit) {
97
+ return async function execute(properties, { client, service, trigger }, emit) {
98
98
  const id = properties[modelPropertyName] || app.generateUid()
99
99
  const entity = await modelRuntime().get(id)
100
100
  if(entity) throw 'exists'
@@ -103,7 +103,7 @@ function getCreateFunction( validators, validationContext, config, context) {
103
103
  App.computeDefaults(model, properties, { client, service } ))
104
104
  await App.validation.validate({ ...identifiers, ...data }, validators,
105
105
  validationContext)
106
- await fireChangeTriggers(context, objectType, identifiers, id, null, data)
106
+ await fireChangeTriggers(context, objectType, identifiers, id, null, data, trigger)
107
107
  emit({
108
108
  type: eventName,
109
109
  [modelPropertyName]: id,
@@ -169,7 +169,7 @@ function getUpdateFunction( validators, validationContext, config, context) {
169
169
  otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName, others
170
170
  } = context
171
171
  const eventName = modelName + 'Updated'
172
- return async function execute(properties, { client, service }, emit) {
172
+ return async function execute(properties, { client, service, trigger }, emit) {
173
173
  const id = properties[modelPropertyName]
174
174
  const entity = await modelRuntime().get(id)
175
175
  if(!entity) throw 'not_found'
@@ -186,7 +186,7 @@ function getUpdateFunction( validators, validationContext, config, context) {
186
186
  await App.validation.validate({ ...identifiers, ...data, [modelPropertyName]: id }, validators,
187
187
  validationContext)
188
188
  await fireChangeTriggers(context, objectType, identifiers, id,
189
- extractObjectData(writeableProperties, entity, {}), data)
189
+ extractObjectData(writeableProperties, entity, {}), data, trigger)
190
190
  emit({
191
191
  type: eventName,
192
192
  [modelPropertyName]: id,
@@ -262,7 +262,7 @@ function getDeleteFunction( validators, validationContext, config, context) {
262
262
  otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName, others
263
263
  } = context
264
264
  const eventName = modelName + 'Deleted'
265
- return async function execute(properties, { client, service }, emit) {
265
+ return async function execute(properties, { client, service, trigger }, emit) {
266
266
  const id = properties[modelPropertyName]
267
267
  const entity = await modelRuntime().get(id)
268
268
  if(!entity) throw 'not_found'
@@ -273,7 +273,7 @@ function getDeleteFunction( validators, validationContext, config, context) {
273
273
  }
274
274
  const identifiers = extractIdentifiers(otherPropertyNames, entity)
275
275
  await fireChangeTriggers(context, objectType, identifiers, id,
276
- extractObjectData(writeableProperties, entity, {}), null)
276
+ extractObjectData(writeableProperties, entity, {}), null, trigger)
277
277
  emit({
278
278
  type: eventName,
279
279
  [modelPropertyName]: id
@@ -348,7 +348,7 @@ function getCopyFunction( validators, validationContext, config, context) {
348
348
  otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName, others
349
349
  } = context
350
350
  const eventName = modelName + 'Copied'
351
- return async function execute(properties, { client, service }, emit) {
351
+ return async function execute(properties, { client, service, trigger }, emit) {
352
352
  const id = properties[modelPropertyName]
353
353
  const entity = await modelRuntime().get(id)
354
354
  if(!entity) throw new Error('not_found')
@@ -382,7 +382,7 @@ function getCopyFunction( validators, validationContext, config, context) {
382
382
  identifiers,
383
383
  data: updatedData
384
384
  })
385
- await fireChangeTriggers(context, objectType, identifiers, newId, null, updatedData)
385
+ await fireChangeTriggers(context, objectType, identifiers, newId, null, updatedData, trigger)
386
386
  emit({
387
387
  type: eventName,
388
388
  [modelPropertyName]: newId,
@@ -502,7 +502,8 @@ function defineCopyOnParentCopyTrigger(config, context) {
502
502
  type: Object,
503
503
  }
504
504
  },
505
- async execute({ objectType, object, parentType, parent, fromParent, identifiers, data }, {client, service}, emit) {
505
+ async execute({ objectType, object, parentType, parent, fromParent, identifiers, data },
506
+ { client, service, trigger }, emit) {
506
507
  const newIdentifiers = {
507
508
  ...identifiers
508
509
  }
@@ -531,7 +532,7 @@ function defineCopyOnParentCopyTrigger(config, context) {
531
532
  identifiers: newIdentifiers,
532
533
  data
533
534
  })
534
- await fireChangeTriggers(context, objectType, newIdentifiers, newId, null, data)
535
+ await fireChangeTriggers(context, objectType, newIdentifiers, newId, null, data, trigger)
535
536
  emit({
536
537
  type: eventName,
537
538
  [modelPropertyName]: newId,
@@ -101,7 +101,7 @@ function getSetFunction( validators, validationContext, config, context) {
101
101
  otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName
102
102
  } = context
103
103
  const eventName = modelName + 'Set'
104
- return async function execute(properties, { client, service }, emit) {
104
+ return async function execute(properties, { client, service, trigger }, emit) {
105
105
  const identifiers = extractIdentifiersWithTypes(otherPropertyNames, properties)
106
106
  const id = generateAnyId(otherPropertyNames, properties)
107
107
  const entity = await modelRuntime().get(id)
@@ -109,7 +109,7 @@ function getSetFunction( validators, validationContext, config, context) {
109
109
  App.computeDefaults(model, properties, { client, service } ))
110
110
  await App.validation.validate({ ...identifiers, ...data }, validators,
111
111
  validationContext)
112
- await fireChangeTriggers(context, objectType, identifiers, id, null, data)
112
+ await fireChangeTriggers(context, objectType, identifiers, id, null, data, trigger)
113
113
  emit({
114
114
  type: eventName,
115
115
  identifiers, data
@@ -172,7 +172,7 @@ function getUpdateFunction( validators, validationContext, config, context) {
172
172
  otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName
173
173
  } = context
174
174
  const eventName = modelName + 'Updated'
175
- return async function execute(properties, {client, service}, emit) {
175
+ return async function execute(properties, { client, service, trigger }, emit) {
176
176
  const identifiers = extractIdentifiersWithTypes(otherPropertyNames, properties)
177
177
  const id = generateAnyId(otherPropertyNames, properties)
178
178
  const entity = await modelRuntime().get(id)
@@ -184,7 +184,7 @@ function getUpdateFunction( validators, validationContext, config, context) {
184
184
  await App.validation.validate({ ...identifiers, ...data }, validators,
185
185
  validationContext)
186
186
  await fireChangeTriggers(context, objectType, identifiers, id,
187
- entity ? extractObjectData(writeableProperties, entity, {}) : null, data)
187
+ entity ? extractObjectData(writeableProperties, entity, {}) : null, data, trigger)
188
188
  emit({
189
189
  type: eventName,
190
190
  identifiers, data
@@ -250,7 +250,7 @@ function getSetOrUpdateFunction( validators, validationContext, config, context)
250
250
  otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName
251
251
  } = context
252
252
  const eventName = modelName + 'Updated'
253
- return async function execute(properties, { client, service }, emit) {
253
+ return async function execute(properties, { client, service, trigger }, emit) {
254
254
  const identifiers = extractIdentifiersWithTypes(otherPropertyNames, properties)
255
255
  const id = generateAnyId(otherPropertyNames, properties)
256
256
  const entity = await modelRuntime().get(id)
@@ -262,7 +262,7 @@ function getSetOrUpdateFunction( validators, validationContext, config, context)
262
262
  await App.validation.validate({ ...identifiers, ...data }, validators,
263
263
  validationContext)
264
264
  await fireChangeTriggers(context, objectType, identifiers, id,
265
- entity ? extractObjectData(writeableProperties, entity, {}) : null, data)
265
+ entity ? extractObjectData(writeableProperties, entity, {}) : null, data, trigger)
266
266
  emit({
267
267
  type: eventName,
268
268
  identifiers, data
@@ -328,13 +328,13 @@ function getResetFunction(config, context) {
328
328
  otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName
329
329
  } = context
330
330
  const eventName = modelName + 'Reset'
331
- return async function execute(properties, {client, service}, emit) {
331
+ return async function execute(properties, { client, service, trigger }, emit) {
332
332
  const identifiers = extractIdentifiersWithTypes(otherPropertyNames, properties)
333
333
  const id = properties[modelPropertyName] ?? generateAnyId(otherPropertyNames, properties)
334
334
  const entity = await modelRuntime().get(id)
335
335
  if (!entity) throw new Error('not_found')
336
336
  await fireChangeTriggers(context, objectType, identifiers, id,
337
- entity ? extractObjectData(writeableProperties, entity, {}) : null, null)
337
+ entity ? extractObjectData(writeableProperties, entity, {}) : null, null, trigger)
338
338
  emit({
339
339
  type: eventName,
340
340
  identifiers
@@ -143,10 +143,10 @@ export function getSetFunction( validators, validationContext, config, context)
143
143
  const id = idParts.length > 1 ? idParts.map(p => JSON.stringify(p)).join(':') : idParts[0]
144
144
  const identifiers = extractIdentifiers(otherPropertyNames, properties)
145
145
  const data = extractObjectData(writeableProperties, properties,
146
- App.computeDefaults(model, properties, { client, service } ))
146
+ App.computeDefaults(model, properties, { client, service, trigger } ))
147
147
  await App.validation.validate({ ...identifiers, ...data }, validators,
148
148
  validationContext)
149
- await fireChangeTriggers(context, objectType, identifiers, id, null, data)
149
+ await fireChangeTriggers(context, objectType, identifiers, id, null, data, trigger)
150
150
  emit({
151
151
  type: eventName,
152
152
  identifiers, data
@@ -209,7 +209,7 @@ export function getUpdateFunction( validators, validationContext, config, contex
209
209
  otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName, others
210
210
  } = context
211
211
  const eventName = modelName + 'Updated'
212
- return async function execute(properties, { client, service }, emit) {
212
+ return async function execute(properties, { client, service, trigger }, emit) {
213
213
  const identifiers = extractIdentifiers(otherPropertyNames, properties)
214
214
  const id = generateId(otherPropertyNames, properties)
215
215
  const entity = await modelRuntime().get(id)
@@ -222,7 +222,7 @@ export function getUpdateFunction( validators, validationContext, config, contex
222
222
  validationContext)
223
223
  const oldData = extractObjectData(writeableProperties, entity, {})
224
224
  await fireChangeTriggers(context, objectType, identifiers, id,
225
- entity ? extractObjectData(writeableProperties, entity, {}) : null, data)
225
+ entity ? extractObjectData(writeableProperties, entity, {}) : null, data, trigger)
226
226
  emit({
227
227
  type: eventName,
228
228
  identifiers, data
@@ -288,7 +288,7 @@ export function getSetOrUpdateFunction( validators, validationContext, config, c
288
288
  otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName, others
289
289
  } = context
290
290
  const eventName = modelName + 'Updated'
291
- return async function execute(properties, { client, service }, emit) {
291
+ return async function execute(properties, { client, service, trigger }, emit) {
292
292
  const identifiers = extractIdentifiers(otherPropertyNames, properties)
293
293
  const id = generateId(otherPropertyNames, properties)
294
294
  const entity = await modelRuntime().get(id)
@@ -299,7 +299,7 @@ export function getSetOrUpdateFunction( validators, validationContext, config, c
299
299
  )
300
300
  await App.validation.validate({ ...identifiers, ...data }, validators, { ...validationContext, service, app, client })
301
301
  await fireChangeTriggers(context, objectType, identifiers, id,
302
- entity ? extractObjectData(writeableProperties, entity, {}) : null, data)
302
+ entity ? extractObjectData(writeableProperties, entity, {}) : null, data, trigger)
303
303
  emit({
304
304
  type: eventName,
305
305
  identifiers, data
@@ -365,13 +365,13 @@ export function getResetFunction( validators, validationContext, config, context
365
365
  otherPropertyNames, joinedOthersPropertyName, modelName, joinedOthersClassName, model, others, writeableProperties
366
366
  } = context
367
367
  const eventName = modelName + 'Reset'
368
- return async function execute(properties, { client, service }, emit) {
368
+ return async function execute(properties, { client, service, trigger }, emit) {
369
369
  const identifiers = extractIdentifiers(otherPropertyNames, properties)
370
370
  const id = properties[modelPropertyName] ?? generateId(otherPropertyNames, properties)
371
371
  const entity = await modelRuntime().get(id)
372
372
  if (!entity) throw new Error('not_found')
373
373
  await fireChangeTriggers(context, objectType, identifiers, id,
374
- entity ? extractObjectData(writeableProperties, entity, {}) : null, null)
374
+ entity ? extractObjectData(writeableProperties, entity, {}) : null, null, trigger)
375
375
  emit({
376
376
  type: eventName,
377
377
  identifiers: {
package/utils.js CHANGED
@@ -2,7 +2,7 @@ import App from "@live-change/framework"
2
2
  const app = App.app()
3
3
  import { allCombinations } from "./combinations.js"
4
4
  import {
5
- fireChangeTriggers, registerParentDeleteTriggers, registerParentCopyTriggers
5
+ registerParentDeleteTriggers, registerParentCopyTriggers
6
6
  } from "./changeTriggers.js"
7
7
  import {
8
8
  PropertyDefinition, ViewDefinition, IndexDefinition, ActionDefinition, EventDefinition, TriggerDefinition
package/utilsAny.js CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  PropertyDefinition, ViewDefinition, IndexDefinition, ActionDefinition, EventDefinition, TriggerDefinition
5
5
  } from "@live-change/framework"
6
6
  import { allCombinations } from "./combinations.js"
7
- import { fireChangeTriggers, registerParentDeleteTriggers } from "./changeTriggers.js"
7
+ import { registerParentDeleteTriggers } from "./changeTriggers.js"
8
8
 
9
9
 
10
10
  export function extractTypeAndIdParts(otherPropertyNames, properties) {