@live-change/relations-plugin 0.9.96 → 0.9.98
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/entityUtils.ts +4 -3
- package/src/pluralRelationAnyUtils.js +18 -7
- package/src/pluralRelationUtils.js +4 -3
- package/src/singularRelationAnyUtils.js +4 -4
- package/src/singularRelationUtils.js +6 -5
- package/src/utils.ts +26 -0
- package/src/utilsAny.ts +7 -7
- package/tsconfig.json +1 -0
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.98",
|
|
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.98",
|
|
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": "a0e25c0ac835707d27763e56a2c20bd75d978583"
|
|
34
34
|
}
|
package/src/entityUtils.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
defineProperties, defineIndex,
|
|
3
3
|
extractIdParts, extractIdentifiers, extractObjectData, prepareAccessControl,
|
|
4
|
-
includeAccessRoles, defineGlobalRangeView
|
|
4
|
+
includeAccessRoles, defineGlobalRangeView,
|
|
5
|
+
propertiesWithoutDefaults
|
|
5
6
|
} from './utils.js'
|
|
6
7
|
import { fireChangeTriggers } from "./changeTriggers.js"
|
|
7
8
|
import App, { AccessSpecification, ModelDefinitionSpecification, PropertyDefinitionSpecification, ServiceDefinition } from '@live-change/framework'
|
|
@@ -258,7 +259,7 @@ export function defineUpdateAction(config, context) {
|
|
|
258
259
|
const action = new ActionDefinition({
|
|
259
260
|
name: actionName,
|
|
260
261
|
properties: {
|
|
261
|
-
...(model.properties),
|
|
262
|
+
...propertiesWithoutDefaults(model.properties),
|
|
262
263
|
[modelPropertyName]: {
|
|
263
264
|
type: modelPropertyName
|
|
264
265
|
}
|
|
@@ -286,7 +287,7 @@ export function defineUpdateTrigger(config, context) {
|
|
|
286
287
|
const trigger = new TriggerDefinition({
|
|
287
288
|
name: triggerName,
|
|
288
289
|
properties: {
|
|
289
|
-
...(model.properties),
|
|
290
|
+
...propertiesWithoutDefaults(model.properties),
|
|
290
291
|
[modelPropertyName]: {
|
|
291
292
|
type: modelPropertyName
|
|
292
293
|
}
|
|
@@ -11,7 +11,8 @@ import {
|
|
|
11
11
|
} from './utilsAny.js'
|
|
12
12
|
import {
|
|
13
13
|
extractObjectData, extractIdentifiers, extractIdParts,
|
|
14
|
-
cloneAndPrepareAccessControl as cloneAndPrepareSingleAccessControl
|
|
14
|
+
cloneAndPrepareAccessControl as cloneAndPrepareSingleAccessControl,
|
|
15
|
+
propertiesWithoutDefaults
|
|
15
16
|
} from './utils.js'
|
|
16
17
|
import { fireChangeTriggers } from "./changeTriggers.js"
|
|
17
18
|
|
|
@@ -106,7 +107,7 @@ function getCreateFunction( validators, validationContext, config, context) {
|
|
|
106
107
|
const identifiers = extractIdentifiersWithTypes(otherPropertyNames, properties)
|
|
107
108
|
const data = extractObjectData(writeableProperties, properties,
|
|
108
109
|
App.computeDefaults(model, properties, { client, service } ))
|
|
109
|
-
await App.validation.validate({ ...identifiers, ...data }, validators,
|
|
110
|
+
const result = await App.validation.validate({ ...identifiers, ...data }, validators,
|
|
110
111
|
validationContext)
|
|
111
112
|
await fireChangeTriggers(context, objectType, identifiers, id, null, data, trigger)
|
|
112
113
|
emit({
|
|
@@ -183,9 +184,9 @@ function getUpdateFunction( validators, validationContext, config, context) {
|
|
|
183
184
|
const entity = await modelRuntime().get(id)
|
|
184
185
|
if(!entity) throw 'not_found'
|
|
185
186
|
const entityTypeAndIdParts = extractTypeAndIdParts(otherPropertyNames, entity)
|
|
186
|
-
const typeAndIdParts = extractTypeAndIdParts(otherPropertyNames, properties)
|
|
187
|
-
console.log("UPDATE MATCH", entityTypeAndIdParts, '===', typeAndIdParts,
|
|
188
|
-
'=>', JSON.stringify(entityTypeAndIdParts) === JSON.stringify(typeAndIdParts))
|
|
187
|
+
const typeAndIdParts = extractTypeAndIdParts(otherPropertyNames, properties)
|
|
188
|
+
/* console.log("UPDATE MATCH", entityTypeAndIdParts, '===', typeAndIdParts,
|
|
189
|
+
'=>', JSON.stringify(entityTypeAndIdParts) === JSON.stringify(typeAndIdParts)) */
|
|
189
190
|
if(JSON.stringify(entityTypeAndIdParts) !== JSON.stringify(typeAndIdParts)) {
|
|
190
191
|
throw 'not_authorized'
|
|
191
192
|
}
|
|
@@ -194,6 +195,16 @@ function getUpdateFunction( validators, validationContext, config, context) {
|
|
|
194
195
|
extractObjectData(writeableProperties, properties, entity),
|
|
195
196
|
App.computeUpdates(model, { ...entity, ...properties }, { client, service })
|
|
196
197
|
)
|
|
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
|
+
}
|
|
197
208
|
await App.validation.validate({ ...identifiers, ...data, [modelPropertyName]: id }, validators,
|
|
198
209
|
validationContext)
|
|
199
210
|
await fireChangeTriggers(context, objectType, identifiers, id,
|
|
@@ -226,7 +237,7 @@ function defineUpdateAction(config, context) {
|
|
|
226
237
|
type: model,
|
|
227
238
|
validation: ['nonEmpty']
|
|
228
239
|
},
|
|
229
|
-
...(model.properties)
|
|
240
|
+
...propertiesWithoutDefaults(model.properties)
|
|
230
241
|
},
|
|
231
242
|
access: config.updateAccess || config.writeAccess,
|
|
232
243
|
accessControl,
|
|
@@ -256,7 +267,7 @@ function defineUpdateTrigger(config, context) {
|
|
|
256
267
|
type: model,
|
|
257
268
|
validation: ['nonEmpty']
|
|
258
269
|
},
|
|
259
|
-
...(model.properties)
|
|
270
|
+
...propertiesWithoutDefaults(model.properties)
|
|
260
271
|
},
|
|
261
272
|
access: config.updateAccess || config.writeAccess,
|
|
262
273
|
skipValidation: true,
|
|
@@ -7,7 +7,8 @@ import {
|
|
|
7
7
|
extractIdentifiers,
|
|
8
8
|
extractObjectData,
|
|
9
9
|
prepareAccessControl,
|
|
10
|
-
cloneAndPrepareAccessControl
|
|
10
|
+
cloneAndPrepareAccessControl,
|
|
11
|
+
propertiesWithoutDefaults
|
|
11
12
|
} from './utils.js'
|
|
12
13
|
import { fireChangeTriggers } from "./changeTriggers.js"
|
|
13
14
|
import pluralize from 'pluralize'
|
|
@@ -215,7 +216,7 @@ function defineUpdateAction(config, context) {
|
|
|
215
216
|
type: model,
|
|
216
217
|
validation: ['nonEmpty']
|
|
217
218
|
},
|
|
218
|
-
...(model.properties)
|
|
219
|
+
...propertiesWithoutDefaults(model.properties)
|
|
219
220
|
},
|
|
220
221
|
access: config.updateAccess || config.writeAccess,
|
|
221
222
|
accessControl,
|
|
@@ -244,7 +245,7 @@ function defineUpdateTrigger(config, context) {
|
|
|
244
245
|
type: model,
|
|
245
246
|
validation: ['nonEmpty']
|
|
246
247
|
},
|
|
247
|
-
|
|
248
|
+
propertiesWithoutDefaults
|
|
248
249
|
},
|
|
249
250
|
skipValidation: true,
|
|
250
251
|
//queuedBy: otherPropertyNames,
|
|
@@ -206,7 +206,7 @@ function defineUpdateAction(config, context) {
|
|
|
206
206
|
const action = new ActionDefinition({
|
|
207
207
|
name: actionName,
|
|
208
208
|
properties: {
|
|
209
|
-
...(model.properties)
|
|
209
|
+
...propertiesWithoutDefaults(model.properties)
|
|
210
210
|
},
|
|
211
211
|
access: config.updateAccess || config.writeAccess,
|
|
212
212
|
accessControl,
|
|
@@ -232,7 +232,7 @@ function defineUpdateTrigger(config, context) {
|
|
|
232
232
|
const trigger = new TriggerDefinition({
|
|
233
233
|
name: triggerName,
|
|
234
234
|
properties: {
|
|
235
|
-
...(model.properties)
|
|
235
|
+
...propertiesWithoutDefaults(model.properties)
|
|
236
236
|
},
|
|
237
237
|
skipValidation: true,
|
|
238
238
|
queuedBy: otherPropertyNames,
|
|
@@ -285,7 +285,7 @@ function defineSetOrUpdateAction(config, context) {
|
|
|
285
285
|
const action = new ActionDefinition({
|
|
286
286
|
name: actionName,
|
|
287
287
|
properties: {
|
|
288
|
-
...(model.properties)
|
|
288
|
+
...propertiesWithoutDefaults(model.properties)
|
|
289
289
|
},
|
|
290
290
|
access: config.updateAccess || config.writeAccess,
|
|
291
291
|
accessControl,
|
|
@@ -311,7 +311,7 @@ function defineSetOrUpdateTrigger(config, context) {
|
|
|
311
311
|
const trigger = new TriggerDefinition({
|
|
312
312
|
name: triggerName,
|
|
313
313
|
properties: {
|
|
314
|
-
...(model.properties)
|
|
314
|
+
...propertiesWithoutDefaults(model.properties)
|
|
315
315
|
},
|
|
316
316
|
skipValidation: true,
|
|
317
317
|
queuedBy: otherPropertyNames,
|
|
@@ -9,7 +9,8 @@ import {
|
|
|
9
9
|
extractIdParts,
|
|
10
10
|
prepareAccessControl,
|
|
11
11
|
cloneAndPrepareAccessControl,
|
|
12
|
-
defineIndex
|
|
12
|
+
defineIndex,
|
|
13
|
+
propertiesWithoutDefaults
|
|
13
14
|
} from './utils.js'
|
|
14
15
|
import { fireChangeTriggers } from "./changeTriggers.js"
|
|
15
16
|
import { extractTypeAndIdParts } from './utilsAny.js'
|
|
@@ -254,7 +255,7 @@ export function defineUpdateAction(config, context) {
|
|
|
254
255
|
const action = new ActionDefinition({
|
|
255
256
|
name: actionName,
|
|
256
257
|
properties: {
|
|
257
|
-
...(model.properties)
|
|
258
|
+
...propertiesWithoutDefaults(model.properties)
|
|
258
259
|
},
|
|
259
260
|
access: config.updateAccess || config.writeAccess,
|
|
260
261
|
accessControl,
|
|
@@ -280,7 +281,7 @@ export function defineUpdateTrigger(config, context) {
|
|
|
280
281
|
const trigger = new TriggerDefinition({
|
|
281
282
|
name: triggerName,
|
|
282
283
|
properties: {
|
|
283
|
-
...(model.properties)
|
|
284
|
+
...propertiesWithoutDefaults(model.properties)
|
|
284
285
|
},
|
|
285
286
|
skipValidation: true,
|
|
286
287
|
queuedBy: otherPropertyNames,
|
|
@@ -332,7 +333,7 @@ export function defineSetOrUpdateAction(config, context) {
|
|
|
332
333
|
const action = new ActionDefinition({
|
|
333
334
|
name: actionName,
|
|
334
335
|
properties: {
|
|
335
|
-
...(model.properties)
|
|
336
|
+
...propertiesWithoutDefaults(model.properties)
|
|
336
337
|
},
|
|
337
338
|
access: config.updateAccess || config.writeAccess,
|
|
338
339
|
accessControl,
|
|
@@ -358,7 +359,7 @@ export function defineSetOrUpdateTrigger(config, context) {
|
|
|
358
359
|
const trigger = new TriggerDefinition({
|
|
359
360
|
name: triggerName,
|
|
360
361
|
properties: {
|
|
361
|
-
...(model.properties)
|
|
362
|
+
...propertiesWithoutDefaults(model.properties)
|
|
362
363
|
},
|
|
363
364
|
skipValidation: true,
|
|
364
365
|
queuedBy: otherPropertyNames,
|
package/src/utils.ts
CHANGED
|
@@ -18,6 +18,32 @@ import pluralize from 'pluralize'
|
|
|
18
18
|
import { ModelDefinitionSpecificationWithEntity } from "./entityUtils.js"
|
|
19
19
|
import { AccessControlSettings, ModelDefinitionSpecificationWithAccessControl, PreparedAccessControlSettings } from "./types.js"
|
|
20
20
|
|
|
21
|
+
export function definitionWithoutDefaults(definition: PropertyDefinitionSpecification) {
|
|
22
|
+
const newDefinition = { ...definition }
|
|
23
|
+
if(newDefinition.default) {
|
|
24
|
+
delete newDefinition.default
|
|
25
|
+
}
|
|
26
|
+
if(newDefinition.of) {
|
|
27
|
+
newDefinition.of = definitionWithoutDefaults(newDefinition.of)
|
|
28
|
+
}
|
|
29
|
+
if(newDefinition.items) {
|
|
30
|
+
newDefinition.items = definitionWithoutDefaults(newDefinition.items)
|
|
31
|
+
}
|
|
32
|
+
if(newDefinition.properties) {
|
|
33
|
+
newDefinition.properties = propertiesWithoutDefaults(newDefinition.properties)
|
|
34
|
+
}
|
|
35
|
+
return newDefinition
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function propertiesWithoutDefaults(properties: Record<string, any>) {
|
|
39
|
+
const newProperties = {}
|
|
40
|
+
for(const key in properties) {
|
|
41
|
+
const property = properties[key]
|
|
42
|
+
newProperties[key] = definitionWithoutDefaults(property)
|
|
43
|
+
}
|
|
44
|
+
return newProperties
|
|
45
|
+
}
|
|
46
|
+
|
|
21
47
|
export function extractIdParts(otherPropertyNames: string[], properties: Record<string, any>) {
|
|
22
48
|
const idParts = []
|
|
23
49
|
for (const propertyName of otherPropertyNames) {
|
package/src/utilsAny.ts
CHANGED
|
@@ -302,12 +302,12 @@ export function defineAnyTypeIndexes(config, context, useId = false) {
|
|
|
302
302
|
await output.delete({ id: type })
|
|
303
303
|
}
|
|
304
304
|
} catch(e) {
|
|
305
|
-
|
|
306
|
-
console.error("Error parsing typeJson", typeJson, e)
|
|
305
|
+
console.debug("Error parsing typeJson", typeJson, e, 'in id', id, "from table", tableName)
|
|
306
|
+
console.error("Error parsing typeJson", typeJson, e, 'in id', id, "from table", tableName)
|
|
307
307
|
}
|
|
308
308
|
})
|
|
309
309
|
},
|
|
310
|
-
parameters: { tableName: tableName }
|
|
310
|
+
parameters: { tableName: tableName, }
|
|
311
311
|
}
|
|
312
312
|
return
|
|
313
313
|
}
|
|
@@ -324,17 +324,17 @@ export function defineAnyTypeIndexes(config, context, useId = false) {
|
|
|
324
324
|
await index.onChange(async (obj, oldObj) => {
|
|
325
325
|
const id = obj?.id ?? oldObj?.id
|
|
326
326
|
const typeJson = id.slice(0, id.indexOf(':'))
|
|
327
|
-
try {
|
|
327
|
+
try {
|
|
328
328
|
const type = JSON.parse(typeJson)
|
|
329
|
-
const count = await index.count({ gte:
|
|
329
|
+
const count = await index.count({ gte: typeJson+':', lte: typeJson+'_\xFF\xFF\xFF\xFF', limit: 1 })
|
|
330
330
|
if(count > 0) {
|
|
331
331
|
await output.put({ id: type })
|
|
332
332
|
} else {
|
|
333
333
|
await output.delete({ id: type })
|
|
334
334
|
}
|
|
335
335
|
} catch(e) {
|
|
336
|
-
output.debug(
|
|
337
|
-
console.error("Error parsing typeJson", typeJson, e)
|
|
336
|
+
output.debug("Error parsing typeJson", typeJson, e, 'in id', id, "from index", indexName)
|
|
337
|
+
console.error("Error parsing typeJson", typeJson, e, 'in id', id, "from index", indexName)
|
|
338
338
|
}
|
|
339
339
|
})
|
|
340
340
|
},
|