@live-change/frontend-auto-form 0.8.114 → 0.8.116

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 CHANGED
@@ -10,6 +10,8 @@ export { inputConfig }
10
10
  import editorData from './logic/editorData.js'
11
11
  export { editorData }
12
12
 
13
+ export * from './logic/relations.js'
14
+
13
15
  import en from "./locales/en.json"
14
16
  const locales = { en }
15
17
  export { locales }
@@ -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.114",
3
+ "version": "0.8.116",
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.114",
26
- "@live-change/dao": "^0.8.114",
27
- "@live-change/dao-vue3": "^0.8.114",
28
- "@live-change/dao-websocket": "^0.8.114",
29
- "@live-change/framework": "^0.8.114",
30
- "@live-change/image-frontend": "^0.8.114",
31
- "@live-change/image-service": "^0.8.114",
32
- "@live-change/session-service": "^0.8.114",
33
- "@live-change/vue3-components": "^0.8.114",
34
- "@live-change/vue3-ssr": "^0.8.114",
25
+ "@live-change/cli": "^0.8.116",
26
+ "@live-change/dao": "^0.8.116",
27
+ "@live-change/dao-vue3": "^0.8.116",
28
+ "@live-change/dao-websocket": "^0.8.116",
29
+ "@live-change/framework": "^0.8.116",
30
+ "@live-change/image-frontend": "^0.8.116",
31
+ "@live-change/image-service": "^0.8.116",
32
+ "@live-change/session-service": "^0.8.116",
33
+ "@live-change/vue3-components": "^0.8.116",
34
+ "@live-change/vue3-ssr": "^0.8.116",
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.114",
55
+ "@live-change/codeceptjs-helper": "^0.8.116",
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": "1a5a437aae382d766c2806a11f805370ee8cc40a"
66
+ "gitHead": "32131af3707ec744c9d314035676d09512483799"
67
67
  }