@live-change/vue-api 0.1.7 → 0.1.11

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.
Files changed (2) hide show
  1. package/lib/Api.js +23 -13
  2. package/package.json +3 -2
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.valdators = validators
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
- serviceDefinitions(definitions, oldDefinitions) {
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 definitions = api.metadata.api?.services
106
- console.log("GENERATE SERVICES API", api.metadata.api)
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) definitions = value?.services
116
+ if(daoPath == cachePath) apiInfo = value
114
117
  }
115
118
  }
116
119
  } else {
117
- definitions = this.prerenderCache.cache.get(cachePath)?.services
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.globals.$client = this.metadata.client
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
@@ -175,13 +187,11 @@ class Api extends DaoProxy {
175
187
  if(component.$options.reactivePreFetch) {
176
188
  const paths = component.$options.reactivePreFetch.apply(this.globals)
177
189
  console.log("PREFETCH PATHS", JSON.stringify(paths))
178
- const promise = this.get({ paths }).then(results => {
190
+ const promise = this.get({ paths })/*.then(results => {
179
191
  for(let { what, data } of results) {
180
- //console.log("PREFETCHED", JSON.stringify(what), ":", JSON.stringify(data, null, ' '))
181
- //console.log("SET", what, this.prerenderCache.set.toString())
182
192
  this.prerenderCache.set(what, data)
183
193
  }
184
- })
194
+ })*/// It's useless because DaoPrerenderCache support paths
185
195
  preFetchPromises.push(promise)
186
196
  }
187
197
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/vue-api",
3
- "version": "0.1.7",
3
+ "version": "0.1.11",
4
4
  "description": "Live Change Framework - vue api base",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -22,6 +22,7 @@
22
22
  "homepage": "https://github.com/live-change/vue-api",
23
23
  "dependencies": {
24
24
  "@live-change/dao": "^0.3.6",
25
- "debug": "^4.3.2"
25
+ "debug": "^4.3.2",
26
+ "@live-change/uid": "^0.1.3"
26
27
  }
27
28
  }