@iankibetsh/vue-streamline 1.2.2 → 1.2.3

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,30 +1,28 @@
1
1
  {
2
- "name": "@iankibetsh/vue-streamline",
3
- "version": "1.2.2",
4
- "description": "Vue library for streamlining laravel backend services with @iankibet/streamline composer package",
5
- "type": "module",
6
- "scripts": {
7
- "dev": "vite",
8
- "build": "vite build",
9
- "preview": "vite preview"
10
- },
11
- "exports": {
12
- ".": "./src/index.js"
13
- },
14
- "keywords": [],
15
- "author": "Iankibet",
16
- "license": "ISC",
17
- "peerDependencies": {
18
- },
19
- "dependencies": {
20
- "axios": "^1.7.3",
21
- "vue": "^3.2.4"
22
- },
23
- "devDependencies": {
24
- "@vitejs/plugin-vue": "^5.1.2",
25
- "vite": "^5.4.1"
26
- },
27
- "publishConfig": {
28
- "access": "public"
29
- }
30
- }
2
+ "name": "@iankibetsh/vue-streamline",
3
+ "version": "1.2.3",
4
+ "description": "Vue library for streamlining laravel backend services with @iankibet/streamline composer package",
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "vite",
8
+ "build": "vite build",
9
+ "preview": "vite preview"
10
+ },
11
+ "exports": {
12
+ ".": "./src/index.js"
13
+ },
14
+ "keywords": [],
15
+ "author": "Iankibet",
16
+ "license": "ISC",
17
+ "devDependencies": {
18
+ "@vitejs/plugin-vue": "^5.1.2",
19
+ "vite": "^5.4.1"
20
+ },
21
+ "peerDependencies": {
22
+ "@iankibetsh/shframework": "^5",
23
+ "vue": "^3"
24
+ },
25
+ "publishConfig": {
26
+ "access": "public"
27
+ }
28
+ }
@@ -1,131 +1,125 @@
1
- import Axios from 'axios';
2
- import { inject, onMounted, reactive, ref } from 'vue';
1
+ import { inject, onMounted, reactive, ref } from 'vue'
2
+ import { shApis } from '@iankibetsh/shframework'
3
3
 
4
4
  const useStreamline = (stream, ...initialArgs) => {
5
- let formData = {};
6
- const loading = ref(false);
7
- const propertiesFetched = ref(false);
8
- const fetching = ref(false);
5
+ let formData = {}
6
+ const loading = ref(false)
7
+ const propertiesFetched = ref(false)
8
+ const fetching = ref(false)
9
9
  // cache key for local storage, include initialArgs in the key
10
- const cacheKey = `streamline_${stream}_${initialArgs.join('_')}`;
10
+ const cacheKey = `streamline_${stream}_${initialArgs.join('_')}`
11
11
 
12
12
  // Inject headers and API endpoint
13
- const streamlineUrl = inject('streamlineUrl');
14
- const streamlineHeaders = inject('streamlineHeaders');
15
- const enableCache = inject('enableCache');
13
+ const streamlineUrl = inject('streamlineUrl')
14
+ const enableCache = inject('enableCache')
16
15
 
17
- const originalProps = reactive({});
16
+ const originalProps = reactive({})
18
17
 
19
18
  // Proxy to intercept access
20
19
  const props = new Proxy(originalProps, {
21
20
  get(target, property, receiver) {
22
- if(!propertiesFetched.value) {
23
- fetchServiceProperties().then(() => target[property]);
21
+ if (!propertiesFetched.value) {
22
+ fetchServiceProperties().then(() => target[property])
24
23
  }
25
- return Reflect.get(target, property, receiver); // Return the actual value
24
+ return Reflect.get(target, property, receiver) // Return the actual value
26
25
  },
27
26
  set(target, property, value, receiver) {
28
- return Reflect.set(target, property, value, receiver); // Update the value
27
+ return Reflect.set(target, property, value, receiver) // Update the value
29
28
  }
30
29
  })
31
- const axios = Axios.create({
32
- headers: {
33
- ...streamlineHeaders,
34
- },
35
- });
36
30
 
37
31
  const fetchServiceProperties = async () => {
38
- if (loading.value || fetching.value || propertiesFetched.value) return;
39
- fetching.value = true;
32
+ if (loading.value || fetching.value || propertiesFetched.value) return
33
+ fetching.value = true
40
34
 
41
35
  try {
42
- loading.value = true;
43
- const response = await axios.post(streamlineUrl, {
36
+ loading.value = true
37
+ const response = await shApis.doPost(streamlineUrl, {
44
38
  action: 'onMounted',
45
39
  stream,
46
- params: initialArgs,
47
- });
48
- assignProperties(response.data);
49
- enableCache && localStorage.setItem(cacheKey, JSON.stringify(response.data));
40
+ params: initialArgs
41
+ })
42
+ assignProperties(response.data)
43
+ enableCache && localStorage.setItem(cacheKey, JSON.stringify(response.data))
50
44
  } catch (error) {
51
- console.error(`Error fetching properties for stream ${stream}`, error);
52
- throw error;
45
+ console.error(`Error fetching properties for stream ${stream}`, error)
46
+ throw error
53
47
  } finally {
54
- propertiesFetched.value = true;
55
- fetching.value = false;
56
- loading.value = false;
48
+ propertiesFetched.value = true
49
+ fetching.value = false
50
+ loading.value = false
57
51
  }
58
- };
52
+ }
59
53
 
60
54
  const assignProperties = (data) => {
61
- Object.assign(service, data.properties); // Assign the properties to the reactive service object
62
- Object.assign(originalProps, data.properties); // Assign the properties to the reactive service object
63
- };
55
+ Object.assign(service, data.properties) // Assign the properties to the reactive service object
56
+ Object.assign(originalProps, data.properties) // Assign the properties to the reactive service object
57
+ }
64
58
 
65
59
  const handler = {
66
60
  get(target, prop, receiver) {
67
61
  // Fetch properties if not already fetched
68
62
  if (!propertiesFetched.value && !loading.value) {
69
- fetchServiceProperties().then(() => target[prop]);
63
+ fetchServiceProperties().then(() => target[prop])
70
64
  }
71
65
 
72
66
  // Handle existing properties
73
67
  if (prop in target) {
74
- return target[prop];
68
+ return target[prop]
75
69
  }
76
70
  // Handle nonexistent properties or dynamic methods
77
71
  return (...args) => {
78
- loading.value = true;
79
- return axios
80
- .post(streamlineUrl, {
72
+ loading.value = true
73
+ return shApis
74
+ .doPost(streamlineUrl, {
81
75
  action: prop,
82
76
  stream,
83
77
  ...formData,
84
- params: args,
78
+ params: args
85
79
  })
86
80
  .then((response) => {
87
- loading.value = false;
88
- return response.data;
81
+ loading.value = false
82
+ return response.data
89
83
  })
90
84
  .catch((error) => {
91
- loading.value = false;
92
- console.error(`Error calling ${prop} on stream ${stream}`, error);
93
- throw error;
94
- });
95
- };
96
- },
97
- };
85
+ loading.value = false
86
+ console.error(`Error calling ${prop} on stream ${stream}`, error)
87
+ throw error
88
+ })
89
+ }
90
+ }
91
+ }
98
92
 
99
93
  const getActionUrl = (action, ...args) => {
100
94
  // console.log('getActionUrl called with:', action, args);
101
95
  const post = {
102
96
  action,
103
97
  stream,
104
- params: args,
105
- };
106
- return `${streamlineUrl}?${new URLSearchParams(post).toString()}`;
107
- };
98
+ params: args
99
+ }
100
+ return `${streamlineUrl}?${new URLSearchParams(post).toString()}`
101
+ }
108
102
 
109
- const service = reactive({}); // Make the service object reactive
103
+ const service = reactive({}) // Make the service object reactive
110
104
 
111
105
  onMounted(() => {
112
- if (!enableCache) return;
113
- const cachedData = localStorage.getItem(cacheKey);
106
+ if (!enableCache) return
107
+ const cachedData = localStorage.getItem(cacheKey)
114
108
  if (cachedData) {
115
- assignProperties(JSON.parse(cachedData));
109
+ assignProperties(JSON.parse(cachedData))
116
110
  }
117
111
  if (initialArgs.length > 0) {
118
- fetchServiceProperties();
112
+ fetchServiceProperties()
119
113
  }
120
114
 
121
- });
115
+ })
122
116
 
123
117
  return {
124
118
  loading,
125
119
  service: new Proxy(service, handler),
126
120
  getActionUrl,
127
121
  props
128
- };
129
- };
122
+ }
123
+ }
130
124
 
131
- export default useStreamline;
125
+ export default useStreamline
@@ -1,7 +1,7 @@
1
1
  const streamline = {
2
2
  install(app, options) {
3
3
  app.provide('streamlineUrl', options.streamlineUrl)
4
- app.provide('streamlineHeaders', options.streamlineHeaders)
4
+ // app.provide('streamlineHeaders', options.streamlineHeaders)
5
5
  app.provide('enableCache', options.enableCache)
6
6
  }
7
7
  }