@live-change/relations-plugin 0.9.86 → 0.9.88
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.
|
|
3
|
+
"version": "0.9.88",
|
|
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.88",
|
|
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": "c042d36f63a6cc50158c3b3385f7f21ea98b847d"
|
|
34
34
|
}
|
|
@@ -204,6 +204,7 @@ function getUpdateFunction( validators, validationContext, config, context) {
|
|
|
204
204
|
identifiers,
|
|
205
205
|
data
|
|
206
206
|
})
|
|
207
|
+
return id
|
|
207
208
|
}
|
|
208
209
|
}
|
|
209
210
|
|
|
@@ -291,6 +292,7 @@ function getDeleteFunction(config, context) {
|
|
|
291
292
|
type: eventName,
|
|
292
293
|
[modelPropertyName]: id
|
|
293
294
|
})
|
|
295
|
+
return id
|
|
294
296
|
}
|
|
295
297
|
}
|
|
296
298
|
|
|
@@ -193,6 +193,7 @@ function getUpdateFunction( validators, validationContext, config, context) {
|
|
|
193
193
|
identifiers,
|
|
194
194
|
data
|
|
195
195
|
})
|
|
196
|
+
return id
|
|
196
197
|
}
|
|
197
198
|
}
|
|
198
199
|
|
|
@@ -278,6 +279,7 @@ function getDeleteFunction( validators, validationContext, config, context) {
|
|
|
278
279
|
type: eventName,
|
|
279
280
|
[modelPropertyName]: id
|
|
280
281
|
})
|
|
282
|
+
return id
|
|
281
283
|
}
|
|
282
284
|
}
|
|
283
285
|
|
|
@@ -190,6 +190,7 @@ function getUpdateFunction( validators, validationContext, config, context) {
|
|
|
190
190
|
type: eventName,
|
|
191
191
|
identifiers, data
|
|
192
192
|
})
|
|
193
|
+
return id
|
|
193
194
|
}
|
|
194
195
|
}
|
|
195
196
|
|
|
@@ -268,6 +269,7 @@ function getSetOrUpdateFunction( validators, validationContext, config, context)
|
|
|
268
269
|
type: eventName,
|
|
269
270
|
identifiers, data
|
|
270
271
|
})
|
|
272
|
+
return id
|
|
271
273
|
}
|
|
272
274
|
}
|
|
273
275
|
|
|
@@ -340,6 +342,7 @@ function getResetFunction(config, context) {
|
|
|
340
342
|
type: eventName,
|
|
341
343
|
identifiers
|
|
342
344
|
})
|
|
345
|
+
return id
|
|
343
346
|
}
|
|
344
347
|
}
|
|
345
348
|
|
|
@@ -16,27 +16,33 @@ import { extractTypeAndIdParts } from './utilsAny.js'
|
|
|
16
16
|
import { allCombinations } from './combinations.js'
|
|
17
17
|
import pluralize from 'pluralize'
|
|
18
18
|
|
|
19
|
-
export function createIdentifiersProperties(keys, types) {
|
|
19
|
+
export function createIdentifiersProperties(keys, types, idField) {
|
|
20
20
|
const identifiers = {}
|
|
21
21
|
if(keys) for(let i = 0; i < keys.length; i++) {
|
|
22
22
|
const key = keys[i]
|
|
23
23
|
identifiers[key] = {
|
|
24
24
|
type: types?.[i] || String,
|
|
25
|
-
validation: ['nonEmpty']
|
|
25
|
+
validation: idField ? [{ name: 'ifEmpty', prop: idField, then: ['nonEmpty'] }] : ['nonEmpty']
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
+
if(idField) identifiers[idField] = {
|
|
29
|
+
type: String,
|
|
30
|
+
validation: keys.map(key => ({ name: 'ifEmpty', prop: key, then: ['nonEmpty'] }))
|
|
31
|
+
}
|
|
28
32
|
return identifiers
|
|
29
33
|
}
|
|
30
34
|
|
|
31
35
|
export function defineObjectView(config, context, external = true) {
|
|
32
36
|
const { service, modelRuntime, otherPropertyNames, joinedOthersPropertyName, joinedOthersClassName,
|
|
33
|
-
modelName, others, model } = context
|
|
34
|
-
const viewProperties = createIdentifiersProperties(otherPropertyNames, others)
|
|
37
|
+
modelName, others, model, modelPropertyName } = context
|
|
38
|
+
const viewProperties = createIdentifiersProperties(otherPropertyNames, others, modelPropertyName)
|
|
35
39
|
const viewName = config.name
|
|
36
40
|
|| ((config.prefix ? config.prefix + modelName : modelName[0].toLowerCase() + modelName.slice(1)) + (config.suffix || ''))
|
|
37
41
|
model.crud.read = viewName
|
|
38
42
|
const sourceAccessControl = external && (config.readAccessControl || config.writeAccessControl)
|
|
39
|
-
const accessControl = cloneAndPrepareAccessControl(sourceAccessControl,
|
|
43
|
+
const accessControl = cloneAndPrepareAccessControl(sourceAccessControl,
|
|
44
|
+
otherPropertyNames.concat(modelPropertyName),
|
|
45
|
+
others.concat(model))
|
|
40
46
|
service.view({
|
|
41
47
|
name: viewName,
|
|
42
48
|
properties: {
|
|
@@ -50,8 +56,12 @@ export function defineObjectView(config, context, external = true) {
|
|
|
50
56
|
access: external && (config.readAccess || config.writeAccess),
|
|
51
57
|
accessControl,
|
|
52
58
|
daoPath(properties, { client, context }) {
|
|
53
|
-
const
|
|
54
|
-
|
|
59
|
+
const idProp = modelPropertyName ? properties[modelPropertyName] : null
|
|
60
|
+
if(idProp) {
|
|
61
|
+
const path = config.fields ? modelRuntime().limitedPath(idProp, config.fields) : modelRuntime().path(idProp)
|
|
62
|
+
return path
|
|
63
|
+
}
|
|
64
|
+
const id = idProp ? idProp : idParts.length > 1 ? idParts.map(p => JSON.stringify(p)).join(':') : idParts[0]
|
|
55
65
|
const path = config.fields ? modelRuntime().limitedPath(id, config.fields) : modelRuntime().path(id)
|
|
56
66
|
return path
|
|
57
67
|
}
|
|
@@ -86,7 +96,7 @@ export function defineRangeViews(config, context, external = true) {
|
|
|
86
96
|
accessControl,
|
|
87
97
|
daoPath(params, { client, context }) {
|
|
88
98
|
const owner = []
|
|
89
|
-
for (const key of combination) owner.push(params[
|
|
99
|
+
for (const key of combination) owner.push(params[otherPropertyNames[key]])
|
|
90
100
|
return modelRuntime().sortedIndexRangePath(indexName, owner, App.extractRange(params) )
|
|
91
101
|
}
|
|
92
102
|
})
|
|
@@ -109,7 +119,7 @@ export function defineRangeViews(config, context, external = true) {
|
|
|
109
119
|
.map(t => t.split('_').pop())
|
|
110
120
|
.map(t => t[0].toLowerCase() + t.slice(1))
|
|
111
121
|
const accessControl = cloneAndPrepareAccessControl(sourceAccessControl, parametersNames, typeCombination)
|
|
112
|
-
const indexName = '
|
|
122
|
+
const indexName = 'ownedBy'+typeNames.join('And')
|
|
113
123
|
const viewName = typeNames.join('And') + context.partialReverseRelationWord + pluralize(modelName)
|
|
114
124
|
model.crud['rangeBy_'+typeCombination.join('And')] = viewName
|
|
115
125
|
//console.log("DEFINE TYPE RANGE VIEW", viewName, typeCombination)
|
|
@@ -151,6 +161,7 @@ export function getSetFunction( validators, validationContext, config, context)
|
|
|
151
161
|
type: eventName,
|
|
152
162
|
identifiers, data
|
|
153
163
|
})
|
|
164
|
+
return id
|
|
154
165
|
}
|
|
155
166
|
return execute
|
|
156
167
|
}
|
|
@@ -227,6 +238,7 @@ export function getUpdateFunction( validators, validationContext, config, contex
|
|
|
227
238
|
type: eventName,
|
|
228
239
|
identifiers, data
|
|
229
240
|
})
|
|
241
|
+
return id
|
|
230
242
|
}
|
|
231
243
|
}
|
|
232
244
|
|
|
@@ -304,6 +316,7 @@ export function getSetOrUpdateFunction( validators, validationContext, config, c
|
|
|
304
316
|
type: eventName,
|
|
305
317
|
identifiers, data
|
|
306
318
|
})
|
|
319
|
+
return id
|
|
307
320
|
}
|
|
308
321
|
}
|
|
309
322
|
|
|
@@ -379,6 +392,7 @@ export function getResetFunction( validators, validationContext, config, context
|
|
|
379
392
|
[modelPropertyName]: id
|
|
380
393
|
}
|
|
381
394
|
})
|
|
395
|
+
return id
|
|
382
396
|
}
|
|
383
397
|
}
|
|
384
398
|
|
package/src/types.ts
CHANGED
package/src/utils.ts
CHANGED
|
@@ -50,13 +50,14 @@ export function defineProperties(model: ModelDefinitionSpecificationWithAccessCo
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
export function defineIndex(model: ModelDefinitionSpecificationWithAccessControl,
|
|
53
|
-
what: string, props: string[], multi = undefined) {
|
|
53
|
+
what: string, props: string[], multi = undefined, prefix = 'by') {
|
|
54
54
|
console.log("DEFINE INDEX", model.name, what, props)
|
|
55
|
-
model.indexes[
|
|
55
|
+
model.indexes[prefix + what] = {
|
|
56
56
|
property: props,
|
|
57
57
|
multi
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
|
+
|
|
60
61
|
export function defineIndexes(model: ModelDefinitionSpecificationWithAccessControl,
|
|
61
62
|
props: Record<string, any>, types: string[]) {
|
|
62
63
|
console.log("DEFINE INDEXES!", model.name, props, types)
|
|
@@ -77,13 +78,15 @@ export function defineIndexes(model: ModelDefinitionSpecificationWithAccessContr
|
|
|
77
78
|
}
|
|
78
79
|
const multiPropsTypes = Object.keys(propsByType).filter(type => propsByType[type].length > 1)
|
|
79
80
|
const typeCombinations = allCombinations(multiPropsTypes)
|
|
81
|
+
//console.log("TYPE COMBINATIONS", typeCombinations)
|
|
80
82
|
for(const typeCombination of typeCombinations) {
|
|
81
83
|
const typeNames = typeCombination.map(t => {
|
|
82
84
|
const type = t.split('_')[1]
|
|
83
85
|
return type[0].toUpperCase() + type.slice(1)
|
|
84
86
|
})
|
|
85
|
-
const typeProps = typeCombination.map(type => propsByType[type])
|
|
86
|
-
|
|
87
|
+
const typeProps = typeCombination.map(type => propsByType[type].map(prop => props[prop]))
|
|
88
|
+
// console.log("DEFINE TYPE INDEX", typeNames.join('And'), typeProps, props)
|
|
89
|
+
defineIndex(model, typeNames.join('And'), typeProps, true, 'ownedBy')
|
|
87
90
|
}
|
|
88
91
|
}
|
|
89
92
|
|
|
@@ -227,7 +230,7 @@ export function prepareAccessControl(accessControl: AccessControlSettings, names
|
|
|
227
230
|
ac.objects = ac.objects ?? ((params) => names.map((name, index) => ({
|
|
228
231
|
objectType: types[index],
|
|
229
232
|
object: params[name]
|
|
230
|
-
})))
|
|
233
|
+
})).filter(obj => obj.object))
|
|
231
234
|
ac.objParams = { names, types }
|
|
232
235
|
}
|
|
233
236
|
}
|