@iankibetsh/vue-streamline 1.1.8 → 1.2.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iankibetsh/vue-streamline",
3
- "version": "1.1.8",
3
+ "version": "1.2.0",
4
4
  "description": "Vue library for streamlining laravel backend services with @iankibet/streamline composer package",
5
5
  "type": "module",
6
6
  "scripts": {
package/src/App.vue CHANGED
@@ -2,7 +2,7 @@
2
2
  import useStreamline from './composables/useStreamline.js'
3
3
  import { onMounted, ref, toRefs } from 'vue'
4
4
 
5
- const {loading, service:paybillService, getActionUrl} = useStreamline('mpesa/paybill',32)
5
+ const {loading, service:paybillService, getActionUrl,props} = useStreamline('mpesa/paybill')
6
6
 
7
7
 
8
8
  const foundPaybill = ref(null)
@@ -21,8 +21,9 @@ const findPaybill = async ()=>{
21
21
  <template>
22
22
  <div>
23
23
  <hr/>
24
+ <h3>Destructed: {{ testKey }}</h3>
25
+ <h3>Original: {{ props.testKey }}</h3>
24
26
  <h3 class="text-success" >Loading : {{ loading }}</h3>
25
- <h5>Found Paybill : {{ paybillService.paybill }}</h5>
26
27
  <h1 @click="findPaybill">Get Paybill</h1>
27
28
  {{ foundPaybill }}
28
29
  </div>
@@ -14,6 +14,20 @@ const useStreamline = (stream, ...initialArgs) => {
14
14
  const streamlineHeaders = inject('streamlineHeaders');
15
15
  const enableCache = inject('enableCache');
16
16
 
17
+ const originalProps = reactive({});
18
+
19
+ // Proxy to intercept access
20
+ const props = new Proxy(originalProps, {
21
+ get(target, property, receiver) {
22
+ if(!propertiesFetched.value) {
23
+ fetchServiceProperties().then(() => target[property]);
24
+ }
25
+ return Reflect.get(target, property, receiver); // Return the actual value
26
+ },
27
+ set(target, property, value, receiver) {
28
+ return Reflect.set(target, property, value, receiver); // Update the value
29
+ }
30
+ })
17
31
  const axios = Axios.create({
18
32
  headers: {
19
33
  ...streamlineHeaders,
@@ -31,7 +45,7 @@ const useStreamline = (stream, ...initialArgs) => {
31
45
  stream,
32
46
  params: initialArgs,
33
47
  });
34
- assignPropertiesAndMethods(response.data);
48
+ assignProperties(response.data);
35
49
  enableCache && localStorage.setItem(cacheKey, JSON.stringify(response.data));
36
50
  } catch (error) {
37
51
  console.error(`Error fetching properties for stream ${stream}`, error);
@@ -43,37 +57,13 @@ const useStreamline = (stream, ...initialArgs) => {
43
57
  }
44
58
  };
45
59
 
46
- const assignPropertiesAndMethods = (data) => {
60
+ const assignProperties = (data) => {
47
61
  Object.assign(service, data.properties); // Assign the properties to the reactive service object
48
- for (const method of data.methods) {
49
- const fn = async (...args) => {
50
- loading.value = true;
51
- try {
52
- const response = await axios.post(streamlineUrl, {
53
- action: method,
54
- stream,
55
- ...formData,
56
- params: args,
57
- });
58
- return response.data;
59
- } catch (error) {
60
- console.error(`Error calling ${method} on stream ${stream}`, error);
61
- throw error;
62
- } finally {
63
- loading.value = false;
64
- }
65
- };
66
- service[method] = fn;
67
- }
62
+ Object.assign(originalProps, data.properties); // Assign the properties to the reactive service object
68
63
  };
69
64
 
70
65
  const handler = {
71
66
  get(target, prop, receiver) {
72
- // Fetch properties if not already fetched
73
- if (!propertiesFetched.value && !loading.value) {
74
- fetchServiceProperties().then(() => target[prop]);
75
- }
76
-
77
67
  // Handle existing properties
78
68
  if (prop in target) {
79
69
  return target[prop];
@@ -102,7 +92,7 @@ const useStreamline = (stream, ...initialArgs) => {
102
92
  };
103
93
 
104
94
  const getActionUrl = (action, ...args) => {
105
- console.log('getActionUrl called with:', action, args);
95
+ // console.log('getActionUrl called with:', action, args);
106
96
  const post = {
107
97
  action,
108
98
  stream,
@@ -117,7 +107,7 @@ const useStreamline = (stream, ...initialArgs) => {
117
107
  if (!enableCache) return;
118
108
  const cachedData = localStorage.getItem(cacheKey);
119
109
  if (cachedData) {
120
- assignPropertiesAndMethods(JSON.parse(cachedData));
110
+ assignProperties(JSON.parse(cachedData));
121
111
  }
122
112
  if (initialArgs.length > 0) {
123
113
  fetchServiceProperties();
@@ -129,6 +119,7 @@ const useStreamline = (stream, ...initialArgs) => {
129
119
  loading,
130
120
  service: new Proxy(service, handler),
131
121
  getActionUrl,
122
+ props
132
123
  };
133
124
  };
134
125
 
package/src/main.js CHANGED
@@ -11,7 +11,7 @@ const app = createApp(App)
11
11
  app.use(streamline,{
12
12
  streamlineHeaders,
13
13
  streamlineUrl,
14
- enableCache: true
14
+ enableCache: false
15
15
  })
16
16
 
17
17
  app.mount('#app')