@live-change/vue-api 0.1.9 → 0.2.4
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/lib/Api.js +21 -9
- package/package.json +8 -6
package/lib/Api.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const { DaoProxy, DaoPrerenderCache, DaoCache, Path } = require("@live-change/dao")
|
|
2
2
|
const validators = require('@live-change/framework/lib/utils/validators.js')
|
|
3
|
+
const { hashCode, encodeNumber, uidGenerator } = require('@live-change/uid')
|
|
3
4
|
|
|
4
5
|
function guid() {
|
|
5
6
|
function s4() {
|
|
@@ -15,12 +16,14 @@ class Api extends DaoProxy {
|
|
|
15
16
|
this.source = source
|
|
16
17
|
this.settings = settings
|
|
17
18
|
|
|
19
|
+
this.uidGenerator = () => { throw new Error("uid generator not initialized yet") }
|
|
20
|
+
|
|
18
21
|
this.createReactiveObject = this.settings.createReactiveObject
|
|
19
22
|
|
|
20
23
|
this.preFetchComponents = []
|
|
21
24
|
this.afterPreFetch = []
|
|
22
25
|
|
|
23
|
-
this.
|
|
26
|
+
this.validators = validators
|
|
24
27
|
|
|
25
28
|
this.globals = {
|
|
26
29
|
$validators: validators
|
|
@@ -91,34 +94,37 @@ class Api extends DaoProxy {
|
|
|
91
94
|
]
|
|
92
95
|
},
|
|
93
96
|
watch: {
|
|
94
|
-
|
|
97
|
+
api(api) {
|
|
98
|
+
if(!api) return
|
|
95
99
|
api.generateServicesApi()
|
|
96
100
|
}
|
|
97
101
|
}
|
|
98
|
-
}
|
|
102
|
+
})
|
|
99
103
|
this.preFetchComponents.push(api.metadata)
|
|
100
104
|
this.afterPreFetch.push(() => api.generateServicesApi())
|
|
101
105
|
}
|
|
102
106
|
|
|
103
107
|
generateServicesApi() {
|
|
104
108
|
const api = this
|
|
105
|
-
let
|
|
106
|
-
|
|
107
|
-
if(!definitions) {
|
|
109
|
+
let apiInfo = api.metadata.api
|
|
110
|
+
if(!apiInfo) {
|
|
108
111
|
const cachePath = '["metadata","api"]'
|
|
109
112
|
if(typeof window != 'undefined') {
|
|
110
113
|
const ssrCache = window[this.settings.ssrCacheGlobal || '__DAO_CACHE__']
|
|
111
114
|
if(ssrCache) {
|
|
112
115
|
for(const [daoPath, value] of ssrCache) {
|
|
113
|
-
if(daoPath == cachePath)
|
|
116
|
+
if(daoPath == cachePath) apiInfo = value
|
|
114
117
|
}
|
|
115
118
|
}
|
|
116
119
|
} else {
|
|
117
|
-
|
|
120
|
+
apiInfo = this.prerenderCache.cache.get(cachePath)
|
|
118
121
|
}
|
|
119
122
|
}
|
|
123
|
+
console.log("GENERATE SERVICES API", apiInfo)
|
|
124
|
+
const definitions = apiInfo?.services
|
|
120
125
|
if(JSON.stringify(definitions) == JSON.stringify(api.servicesApiDefinitions)) return
|
|
121
126
|
if(!definitions) throw new Error("API DEFINITIONS NOT FOUND! UNABLE TO GENERATE API!")
|
|
127
|
+
api.uidGenerator = uidGenerator(apiInfo.client.user || apiInfo.client.session.slice(0, 16), 1)
|
|
122
128
|
//console.log("GENERATE API DEFINITIONS", definitions)
|
|
123
129
|
api.servicesApiDefinitions = definitions
|
|
124
130
|
let globalViews = {}
|
|
@@ -144,10 +150,16 @@ class Api extends DaoProxy {
|
|
|
144
150
|
actions[actionName].definition = serviceDefinition.actions[actionName]
|
|
145
151
|
}
|
|
146
152
|
}
|
|
153
|
+
|
|
147
154
|
api.views = globalViews
|
|
148
155
|
api.fetch = globalFetch
|
|
149
156
|
api.actions = globalActions
|
|
150
|
-
api.
|
|
157
|
+
api.client = this.metadata.client
|
|
158
|
+
api.uid = api.uidGenerator
|
|
159
|
+
|
|
160
|
+
api.globals.$lc = api
|
|
161
|
+
|
|
162
|
+
/// Deprecated:
|
|
151
163
|
api.globals.$api = this
|
|
152
164
|
api.globals.$views = this.views
|
|
153
165
|
api.globals.$actions = this.actions
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/vue-api",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "Live Change Framework - vue api base",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
},
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "git+https://github.com/live-change/
|
|
11
|
+
"url": "git+https://github.com/live-change/live-change-framework-vue3.git"
|
|
12
12
|
},
|
|
13
13
|
"author": {
|
|
14
14
|
"email": "m8@em8.pl",
|
|
@@ -17,11 +17,13 @@
|
|
|
17
17
|
},
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"bugs": {
|
|
20
|
-
"url": "https://github.com/live-change/
|
|
20
|
+
"url": "https://github.com/live-change/live-change-framework-vue3/issues"
|
|
21
21
|
},
|
|
22
|
-
"homepage": "https://github.com/live-change/
|
|
22
|
+
"homepage": "https://github.com/live-change/live-change-framework-vue3",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@live-change/dao": "
|
|
24
|
+
"@live-change/dao": "0.4.2",
|
|
25
|
+
"@live-change/uid": "0.5.20",
|
|
25
26
|
"debug": "^4.3.2"
|
|
26
|
-
}
|
|
27
|
+
},
|
|
28
|
+
"gitHead": "fc932e431ba4a6bde00e4e9f24f56c47e8fff33b"
|
|
27
29
|
}
|