@live-change/frontend-auto-form 0.8.115 → 0.8.117
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 +2 -0
- package/logic/relations.js +51 -0
- package/package.json +13 -13
package/index.js
CHANGED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { useApi } from '@live-change/vue3-ssr'
|
|
2
|
+
|
|
3
|
+
function getWhat(relation) {
|
|
4
|
+
if(typeof relation === 'string') return relation
|
|
5
|
+
return relation.what
|
|
6
|
+
}
|
|
7
|
+
function getWhats(relations) {
|
|
8
|
+
if(!Array.isArray(relations)) relations = [relations]
|
|
9
|
+
return relations.map(getWhat)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const typedRelationsTypes = ['propertyOf', 'itemOf', 'boundTo', 'relatedTo']
|
|
13
|
+
export const anyRelationsTypes = typedRelationsTypes.map(relation => relation + 'Any')
|
|
14
|
+
|
|
15
|
+
export function getModelByTypeName(model, api = useApi()) {
|
|
16
|
+
if(typeof model === 'string') {
|
|
17
|
+
const [serviceName, modelName] = model.split('_')
|
|
18
|
+
return api.services[serviceName].models[modelName]
|
|
19
|
+
}
|
|
20
|
+
return model
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function getForwardRelations(model, filter = () => true, api = useApi()) {
|
|
24
|
+
model = getModelByTypeName(model, api)
|
|
25
|
+
const results = []
|
|
26
|
+
for(const type of typedRelationsTypes) {
|
|
27
|
+
let relations = model[type]
|
|
28
|
+
if(!relations) continue
|
|
29
|
+
if(!Array.isArray(relations)) relations = [relations]
|
|
30
|
+
for(const relation of relations) {
|
|
31
|
+
const result = {
|
|
32
|
+
from: model,
|
|
33
|
+
relation: type,
|
|
34
|
+
what: getWhat(relation),
|
|
35
|
+
}
|
|
36
|
+
if(filter(result)) results.push(result)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return results
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function getBackwardRelations(model, api = useApi()) {
|
|
43
|
+
model = getModelByTypeName(model, api)
|
|
44
|
+
const key = `${model.serviceName}_${model.name}`
|
|
45
|
+
console.log("KEY", key)
|
|
46
|
+
return Object.values(api.services).map(
|
|
47
|
+
service => Object.values(service.models).map(
|
|
48
|
+
model => getForwardRelations(model, ({ what }) => what === key, api)
|
|
49
|
+
).flat()
|
|
50
|
+
).flat()
|
|
51
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/frontend-auto-form",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.117",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"memDev": "node server/start.js memDev --enableSessions --initScript ./init.js --dbAccess",
|
|
6
6
|
"localDevInit": "rm tmp.db; lcli localDev --enableSessions --initScript ./init.js",
|
|
@@ -22,16 +22,16 @@
|
|
|
22
22
|
"type": "module",
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@fortawesome/fontawesome-free": "^6.5.2",
|
|
25
|
-
"@live-change/cli": "^0.8.
|
|
26
|
-
"@live-change/dao": "^0.8.
|
|
27
|
-
"@live-change/dao-vue3": "^0.8.
|
|
28
|
-
"@live-change/dao-websocket": "^0.8.
|
|
29
|
-
"@live-change/framework": "^0.8.
|
|
30
|
-
"@live-change/image-frontend": "^0.8.
|
|
31
|
-
"@live-change/image-service": "^0.8.
|
|
32
|
-
"@live-change/session-service": "^0.8.
|
|
33
|
-
"@live-change/vue3-components": "^0.8.
|
|
34
|
-
"@live-change/vue3-ssr": "^0.8.
|
|
25
|
+
"@live-change/cli": "^0.8.117",
|
|
26
|
+
"@live-change/dao": "^0.8.117",
|
|
27
|
+
"@live-change/dao-vue3": "^0.8.117",
|
|
28
|
+
"@live-change/dao-websocket": "^0.8.117",
|
|
29
|
+
"@live-change/framework": "^0.8.117",
|
|
30
|
+
"@live-change/image-frontend": "^0.8.117",
|
|
31
|
+
"@live-change/image-service": "^0.8.117",
|
|
32
|
+
"@live-change/session-service": "^0.8.117",
|
|
33
|
+
"@live-change/vue3-components": "^0.8.117",
|
|
34
|
+
"@live-change/vue3-ssr": "^0.8.117",
|
|
35
35
|
"@vueuse/core": "^10.11.0",
|
|
36
36
|
"codeceptjs-assert": "^0.0.5",
|
|
37
37
|
"compression": "^1.7.4",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"vue3-scroll-border": "0.1.6"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@live-change/codeceptjs-helper": "^0.8.
|
|
55
|
+
"@live-change/codeceptjs-helper": "^0.8.117",
|
|
56
56
|
"codeceptjs": "^3.6.5",
|
|
57
57
|
"generate-password": "1.7.1",
|
|
58
58
|
"playwright": "^1.41.2",
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"author": "Michał Łaszczewski <michal@laszczewski.pl>",
|
|
64
64
|
"license": "ISC",
|
|
65
65
|
"description": "",
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "10546047b3799e2dae072c9270b9469af92ea48f"
|
|
67
67
|
}
|