@live-change/relations-plugin 0.9.200 → 0.9.203
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 +3 -3
- package/src/index.ts +2 -2
- package/src/pluralRelationAnyUtils.js +12 -26
- package/src/pluralRelationUtils.js +5 -12
- package/src/utils.ts +3 -3
- package/src/utilsAny.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/relations-plugin",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.203",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
"type": "module",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@live-change/framework": "^0.9.
|
|
25
|
+
"@live-change/framework": "^0.9.203",
|
|
26
26
|
"pluralize": "^8.0.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
@@ -30,5 +30,5 @@
|
|
|
30
30
|
"typedoc-plugin-markdown": "^4.6.3",
|
|
31
31
|
"typedoc-plugin-rename-defaults": "^0.7.3"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "4d4ce413fe747da2c398eb4ad378e37cc81874b3"
|
|
34
34
|
}
|
package/src/index.ts
CHANGED
|
@@ -38,8 +38,8 @@ export interface ModelWithRelations extends ModelDefinitionSpecificationWithAcce
|
|
|
38
38
|
itemOf?: ItemOfConfig
|
|
39
39
|
propertyOfAny?: PropertyOfAnyConfig
|
|
40
40
|
itemOfAny?: ItemOfAnyConfig
|
|
41
|
-
relatedTo?: RelatedToConfig
|
|
42
|
-
relatedToAny?: RelatedToAnyConfig
|
|
41
|
+
relatedTo?: RelatedToConfig | RelatedToConfig[]
|
|
42
|
+
relatedToAny?: RelatedToAnyConfig | RelatedToAnyConfig[]
|
|
43
43
|
boundTo?: BoundToConfig
|
|
44
44
|
boundToAny?: BoundToAnyConfig
|
|
45
45
|
saveAuthor?: SaveAuthorConfig
|
|
@@ -185,9 +185,12 @@ function getUpdateFunction( validators, validationContext, config, context) {
|
|
|
185
185
|
if(!entity) throw app.logicError("not_found")
|
|
186
186
|
const entityTypeAndIdParts = extractTypeAndIdParts(otherPropertyNames, entity)
|
|
187
187
|
const typeAndIdParts = extractTypeAndIdParts(otherPropertyNames, properties)
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
188
|
+
/* console.log("EXISTING ENTITY:", entity)
|
|
189
|
+
console.log("PROP NAMES:", otherPropertyNames)
|
|
190
|
+
console.log("PROPERTIES:", properties)
|
|
191
|
+
console.log(modelName, "UPDATE MATCH", entityTypeAndIdParts, '===', typeAndIdParts,
|
|
192
|
+
'=>', JSON.stringify(entityTypeAndIdParts) === JSON.stringify(typeAndIdParts)) */
|
|
193
|
+
if(JSON.stringify(entityTypeAndIdParts) !== JSON.stringify(typeAndIdParts) && !config.allowMove) {
|
|
191
194
|
throw app.logicError("not_authorized")
|
|
192
195
|
}
|
|
193
196
|
const identifiers = extractIdentifiersWithTypes(otherPropertyNames, properties)
|
|
@@ -195,16 +198,6 @@ function getUpdateFunction( validators, validationContext, config, context) {
|
|
|
195
198
|
extractObjectData(writeableProperties, properties, entity),
|
|
196
199
|
App.computeUpdates(model, { ...entity, ...properties }, { client, service })
|
|
197
200
|
)
|
|
198
|
-
if(entityTypeAndIdParts[0] == 'task_Task' && data.retries.length == 0 && entity.retries.length > 0) {
|
|
199
|
-
console.log("TASK UPDATE!!!!!!!!")
|
|
200
|
-
console.log("CURRENT STATE:", entity)
|
|
201
|
-
console.log("UPDATE:", properties)
|
|
202
|
-
console.log("IDENTIFIERS:", identifiers)
|
|
203
|
-
console.log("EXTRACTED ENTITY DATA:", extractObjectData(writeableProperties, properties, entity))
|
|
204
|
-
console.log("COMPUTED UPDATES:", App.computeUpdates(model, { ...entity, ...properties }, { client, service }))
|
|
205
|
-
console.log("DATA:", data)
|
|
206
|
-
debugger
|
|
207
|
-
}
|
|
208
201
|
await App.validation.validate({ ...identifiers, ...data, [modelPropertyName]: id }, validators,
|
|
209
202
|
validationContext)
|
|
210
203
|
await fireChangeTriggers(context, objectType, identifiers, id,
|
|
@@ -277,7 +270,7 @@ function defineUpdateTrigger(config, context) {
|
|
|
277
270
|
})
|
|
278
271
|
const validators = App.validation.getValidators(trigger, service, trigger)
|
|
279
272
|
const validationContext = { source: trigger, trigger }
|
|
280
|
-
trigger.execute = getUpdateFunction( validators, validationContext, config, context)
|
|
273
|
+
trigger.execute = getUpdateFunction( validators, validationContext, {...config, allowMove: true }, context)
|
|
281
274
|
if(service.triggers[triggerName]) throw new Error('Trigger ' + triggerName + ' already defined')
|
|
282
275
|
service.triggers[triggerName] = [trigger]
|
|
283
276
|
}
|
|
@@ -292,11 +285,6 @@ function getDeleteFunction(config, context) {
|
|
|
292
285
|
const id = properties[modelPropertyName]
|
|
293
286
|
const entity = await modelRuntime().get(id)
|
|
294
287
|
if(!entity) throw app.logicError("not_found")
|
|
295
|
-
const entityTypeAndIdParts = extractTypeAndIdParts(otherPropertyNames, entity)
|
|
296
|
-
const typeAndIdParts = extractTypeAndIdParts(otherPropertyNames, properties)
|
|
297
|
-
if(JSON.stringify(entityTypeAndIdParts) !== JSON.stringify(typeAndIdParts)) {
|
|
298
|
-
throw app.logicError("not_authorized")
|
|
299
|
-
}
|
|
300
288
|
await fireChangeTriggers(context, objectType, extractIdentifiers(otherPropertyNames, entity), id,
|
|
301
289
|
extractObjectData(writeableProperties, entity, {}), null, trigger)
|
|
302
290
|
emit({
|
|
@@ -309,7 +297,7 @@ function getDeleteFunction(config, context) {
|
|
|
309
297
|
|
|
310
298
|
function defineDeleteAction(config, context) {
|
|
311
299
|
const {
|
|
312
|
-
service, app, model, modelRuntime, modelPropertyName,
|
|
300
|
+
service, app, model, modelRuntime, modelPropertyName, objectType,
|
|
313
301
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName
|
|
314
302
|
} = context
|
|
315
303
|
const actionName = 'delete' + modelName
|
|
@@ -324,8 +312,7 @@ function defineDeleteAction(config, context) {
|
|
|
324
312
|
[modelPropertyName]: {
|
|
325
313
|
type: model,
|
|
326
314
|
validation: ['nonEmpty']
|
|
327
|
-
}
|
|
328
|
-
...identifiers
|
|
315
|
+
}
|
|
329
316
|
},
|
|
330
317
|
access: config.deleteAccess || config.writeAccess,
|
|
331
318
|
accessControl,
|
|
@@ -341,7 +328,7 @@ function defineDeleteAction(config, context) {
|
|
|
341
328
|
|
|
342
329
|
function defineDeleteTrigger(config, context) {
|
|
343
330
|
const {
|
|
344
|
-
service, app, model, modelRuntime, modelPropertyName,
|
|
331
|
+
service, app, model, modelRuntime, modelPropertyName, objectType,
|
|
345
332
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName
|
|
346
333
|
} = context
|
|
347
334
|
const actionName = 'delete' + modelName
|
|
@@ -352,8 +339,7 @@ function defineDeleteTrigger(config, context) {
|
|
|
352
339
|
[modelPropertyName]: {
|
|
353
340
|
type: model,
|
|
354
341
|
validation: ['nonEmpty']
|
|
355
|
-
}
|
|
356
|
-
...identifiers
|
|
342
|
+
}
|
|
357
343
|
},
|
|
358
344
|
access: config.deleteAccess || config.writeAccess,
|
|
359
345
|
skipValidation: true,
|
|
@@ -371,7 +357,7 @@ function defineSortIndex(context, sortFields) {
|
|
|
371
357
|
const sortFieldsUc = sortFields.map(fd => fd.slice(0, 1).toUpperCase() + fd.slice(1))
|
|
372
358
|
const indexName = 'by' + context.joinedOthersClassName + 'And' + sortFieldsUc.join('And')
|
|
373
359
|
const property = [...(context.otherPropertyNames.map(prop => [prop + 'Type', prop]).flat()), ...sortFields]
|
|
374
|
-
console.log("DEFINE SORT INDEX", sortFields, "NAME", indexName, "PROP", property)
|
|
360
|
+
//console.log("DEFINE SORT INDEX", sortFields, "NAME", indexName, "PROP", property)
|
|
375
361
|
context.model.indexes[indexName] = new IndexDefinition({
|
|
376
362
|
property
|
|
377
363
|
})
|
|
@@ -176,7 +176,7 @@ function getUpdateFunction( validators, validationContext, config, context) {
|
|
|
176
176
|
if(!entity) throw app.logicError("not_found")
|
|
177
177
|
const entityIdParts = extractIdParts(otherPropertyNames, entity)
|
|
178
178
|
const idParts = extractIdParts(otherPropertyNames, properties)
|
|
179
|
-
if(JSON.stringify(entityIdParts) !== JSON.stringify(idParts)) {
|
|
179
|
+
if(JSON.stringify(entityIdParts) !== JSON.stringify(idParts) && !config.allowMove) {
|
|
180
180
|
throw app.logicError("not_authorized")
|
|
181
181
|
}
|
|
182
182
|
const identifiers = extractIdentifiers(otherPropertyNames, properties)
|
|
@@ -254,7 +254,7 @@ function defineUpdateTrigger(config, context) {
|
|
|
254
254
|
})
|
|
255
255
|
const validators = App.validation.getValidators(trigger, service, trigger)
|
|
256
256
|
const validationContext = { source: trigger, trigger }
|
|
257
|
-
trigger.execute = getUpdateFunction( validators, validationContext, config, context)
|
|
257
|
+
trigger.execute = getUpdateFunction( validators, validationContext, {...config, allowMove: true }, context)
|
|
258
258
|
service.triggers[triggerName] = [trigger]
|
|
259
259
|
}
|
|
260
260
|
|
|
@@ -268,11 +268,6 @@ function getDeleteFunction( validators, validationContext, config, context) {
|
|
|
268
268
|
const id = properties[modelPropertyName]
|
|
269
269
|
const entity = await modelRuntime().get(id)
|
|
270
270
|
if(!entity) throw app.logicError("not_found")
|
|
271
|
-
const entityIdParts = extractIdParts(otherPropertyNames, entity)
|
|
272
|
-
const idParts = extractIdParts(otherPropertyNames, properties)
|
|
273
|
-
if(JSON.stringify(entityIdParts) !== JSON.stringify(idParts)) {
|
|
274
|
-
throw app.logicError("not_authorized")
|
|
275
|
-
}
|
|
276
271
|
const identifiers = extractIdentifiers(otherPropertyNames, entity)
|
|
277
272
|
await fireChangeTriggers(context, objectType, identifiers, id,
|
|
278
273
|
extractObjectData(writeableProperties, entity, {}), null, trigger)
|
|
@@ -301,8 +296,7 @@ function defineDeleteAction(config, context) {
|
|
|
301
296
|
[modelPropertyName]: {
|
|
302
297
|
type: model,
|
|
303
298
|
validation: ['nonEmpty']
|
|
304
|
-
}
|
|
305
|
-
...(model.properties)
|
|
299
|
+
}
|
|
306
300
|
},
|
|
307
301
|
access: config.deleteAccess || config.writeAccess,
|
|
308
302
|
accessControl,
|
|
@@ -331,8 +325,7 @@ function defineDeleteTrigger(config, context) {
|
|
|
331
325
|
[modelPropertyName]: {
|
|
332
326
|
type: model,
|
|
333
327
|
validation: ['nonEmpty']
|
|
334
|
-
}
|
|
335
|
-
...(model.properties)
|
|
328
|
+
}
|
|
336
329
|
},
|
|
337
330
|
skipValidation: true,
|
|
338
331
|
//queuedBy: otherPropertyNames,
|
|
@@ -549,7 +542,7 @@ function defineCopyOnParentCopyTrigger(config, context) {
|
|
|
549
542
|
|
|
550
543
|
function defineSortIndex(context, sortFields) {
|
|
551
544
|
if(!Array.isArray(sortFields)) sortFields = [sortFields]
|
|
552
|
-
console.log("DEFINE SORT INDEX", sortFields)
|
|
545
|
+
//console.log("DEFINE SORT INDEX", sortFields)
|
|
553
546
|
const sortFieldsUc = sortFields.map(fd=>fd.slice(0, 1).toUpperCase() + fd.slice(1))
|
|
554
547
|
const indexName = 'by' + context.joinedOthersClassName + sortFieldsUc.join('')
|
|
555
548
|
context.model.indexes[indexName] = new IndexDefinition({
|
package/src/utils.ts
CHANGED
|
@@ -77,7 +77,7 @@ export function defineProperties(model: ModelDefinitionSpecificationWithAccessCo
|
|
|
77
77
|
|
|
78
78
|
export function defineIndex(model: ModelDefinitionSpecificationWithAccessControl,
|
|
79
79
|
what: string, props: string[], multi = undefined, prefix = 'by') {
|
|
80
|
-
console.log("DEFINE INDEX", model.name, what, props)
|
|
80
|
+
//console.log("DEFINE INDEX", model.name, what, props)
|
|
81
81
|
model.indexes[prefix + what] = {
|
|
82
82
|
property: props,
|
|
83
83
|
multi
|
|
@@ -86,7 +86,7 @@ export function defineIndex(model: ModelDefinitionSpecificationWithAccessControl
|
|
|
86
86
|
|
|
87
87
|
export function defineIndexes(model: ModelDefinitionSpecificationWithAccessControl,
|
|
88
88
|
props: Record<string, any>, types: string[]) {
|
|
89
|
-
console.log("DEFINE INDEXES!", model.name, props, types)
|
|
89
|
+
//console.log("DEFINE INDEXES!", model.name, props, types)
|
|
90
90
|
const propCombinations = allCombinations(Object.keys(props)) /// combinations of indexes
|
|
91
91
|
for(const propCombination of propCombinations) {
|
|
92
92
|
const upperCaseProps = propCombination.map(id => {
|
|
@@ -199,7 +199,7 @@ export function processModelsAnnotation<PreparedConfig extends RelationConfig>
|
|
|
199
199
|
}
|
|
200
200
|
|
|
201
201
|
// @ts-ignore
|
|
202
|
-
console.log("MODEL " + modelName + " IS " + annotation + " " + config.what ?? '')
|
|
202
|
+
//console.log("MODEL " + modelName + " IS " + annotation + " " + config.what ?? '')
|
|
203
203
|
|
|
204
204
|
const what = (Array.isArray(config.what) ? config.what : [config.what])
|
|
205
205
|
const others = what.map(other => other.getTypeName ? other.getTypeName() : (other.name ? other.name : other))
|
package/src/utilsAny.ts
CHANGED
|
@@ -160,7 +160,7 @@ export function processModelsAnyAnnotation<PreparedConfig extends AnyRelationCon
|
|
|
160
160
|
for(let config of configs) {
|
|
161
161
|
if (typeof config == 'string' || Array.isArray(config)) config = {what: config}
|
|
162
162
|
|
|
163
|
-
console.log("MODEL " + modelName + " IS " + annotation + " " + config.what)
|
|
163
|
+
//console.log("MODEL " + modelName + " IS " + annotation + " " + config.what)
|
|
164
164
|
|
|
165
165
|
const to = (Array.isArray(config.to) ? config.to : [config.to ?? 'owner'])
|
|
166
166
|
|