@live-change/vue3-ssr 0.2.28 → 0.2.30

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/Api.js +49 -7
  2. package/package.json +5 -5
package/Api.js CHANGED
@@ -132,14 +132,9 @@ class Api extends DaoProxy {
132
132
  let globalViews = {}
133
133
  let globalFetch = (...args) => new Path(...args)
134
134
  let globalActions = {}
135
+ let globalModels = {}
136
+ let globalServices = {}
135
137
  for(const serviceDefinition of definitions) {
136
- let views = { }
137
- globalViews[serviceDefinition.name] = views
138
- for(const viewName in serviceDefinition.views) {
139
- //console.log("GENERATE VIEW", serviceDefinition.name, viewName)
140
- views[viewName] = (params) => [serviceDefinition.name, viewName, params]
141
- views[viewName].definition = serviceDefinition.views[viewName]
142
- }
143
138
  let fetch = { }
144
139
  globalFetch[serviceDefinition.name] = fetch
145
140
  for(const actionName in serviceDefinition.actions) {
@@ -156,6 +151,21 @@ class Api extends DaoProxy {
156
151
  actions[actionName] = (params) => api.command([serviceDefinition.name, actionName], params)
157
152
  actions[actionName].definition = serviceDefinition.actions[actionName]
158
153
  }
154
+ let views = { }
155
+ globalViews[serviceDefinition.name] = views
156
+ for(const viewName in serviceDefinition.views) {
157
+ //console.log("GENERATE VIEW", serviceDefinition.name, viewName)
158
+ views[viewName] = (params) => [serviceDefinition.name, viewName, params]
159
+ views[viewName].definition = serviceDefinition.views[viewName]
160
+ }
161
+ let models = { }
162
+ globalModels[serviceDefinition.name] = models
163
+ for(const modelName in serviceDefinition.models) {
164
+ models[modelName] = serviceDefinition.models[modelName]
165
+ }
166
+ globalServices[serviceDefinition.name] = {
167
+ actions, views, models, definitions
168
+ }
159
169
  }
160
170
 
161
171
  api.views = globalViews
@@ -163,6 +173,7 @@ class Api extends DaoProxy {
163
173
  api.actions = globalActions
164
174
  api.client = this.metadata.client
165
175
  api.uid = api.uidGenerator
176
+ api.services = globalServices
166
177
 
167
178
  api.globals.$lc = api
168
179
 
@@ -171,6 +182,7 @@ class Api extends DaoProxy {
171
182
  api.globals.$views = this.views
172
183
  api.globals.$actions = this.actions
173
184
  api.globals.$fetch = this.fetch
185
+ api.globals.$services = this.services
174
186
 
175
187
  api.windowId = this.settings.windowId || api.uid()
176
188
 
@@ -268,6 +280,36 @@ class Api extends DaoProxy {
268
280
  getServiceDefinition(serviceName) {
269
281
  return this.metadata.api.value.services.find(s => s.name == serviceName)
270
282
  }
283
+
284
+ uploadFile(purpose, fileName, blob, id) {
285
+ if (!id) id = this.uidGenerator()
286
+ const xhr = new XMLHttpRequest()
287
+ const state = ref({ id, state: 'starting', transferred: 0, percent: 0, size: blob.size, xhr })
288
+ xhr.upload.addEventListener("progress", (evt) => {
289
+ const percent = evt.loaded / evt.total * 100;
290
+ state.value = { ...state.value, percent, transferred: evt.loaded }
291
+ }, false)
292
+ xhr.addEventListener("readystatechange", (evt) => {
293
+ if (xhr.readyState == 4) {
294
+ if (xhr.status == 200) {
295
+ state.value = { ...state.value, state: "done" }
296
+ } else {
297
+ state.value = { ...state.value, state: "failed", error: xhr.status + " " + xhr.responseText }
298
+ }
299
+ }
300
+ })
301
+ xhr.addEventListener("error", (evt) => {
302
+ state.value = { ...state.value, state: "failed", error: 'XHR error' }
303
+ })
304
+ xhr.addEventListener("abort", (evt) => {
305
+ state.value = { ...state.value, state: "failed", error: 'XHR aborted' }
306
+ })
307
+ const url = `${document.location.protocol}//${document.location.host}/upload/${purpose}/${fileName}/${id}`
308
+ xhr.open("POST", url, true)
309
+ xhr.send(blob)
310
+ return state
311
+ }
312
+
271
313
  }
272
314
 
273
315
  export default Api
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/vue3-ssr",
3
- "version": "0.2.28",
3
+ "version": "0.2.30",
4
4
  "description": "Live Change Framework - vue components",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -21,10 +21,10 @@
21
21
  },
22
22
  "homepage": "https://github.com/live-change/live-change-framework-vue3",
23
23
  "dependencies": {
24
- "@live-change/dao-vue3": "0.5.20",
25
- "@live-change/uid": "0.7.28",
26
- "@vueuse/core": "^9.1.0",
24
+ "@live-change/dao-vue3": "0.5.22",
25
+ "@live-change/uid": "0.7.34",
26
+ "@vueuse/core": "^10.4.1",
27
27
  "debug": "^4.3.4"
28
28
  },
29
- "gitHead": "180739742efd7ca315ed64b2bf2d45794a6fd4ac"
29
+ "gitHead": "623e5d40a7457b5a2a3f55783c59360396161ca8"
30
30
  }