@data-fair/lib-vue 1.15.5 → 1.15.6

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/async-action.js CHANGED
@@ -1,9 +1,9 @@
1
1
  // similar to withUiNotif but more powerful
2
- import { ref } from 'vue'
2
+ import { ref, readonly, shallowReadonly, shallowRef } from 'vue'
3
3
  import { useUiNotif, getFullNotif, getErrorMsg } from './ui-notif.js'
4
4
  export function useAsyncAction (fn, options) {
5
5
  const { sendUiNotif } = useUiNotif()
6
- const notif = ref()
6
+ const notif = shallowRef()
7
7
  const loading = ref(false)
8
8
  const error = ref()
9
9
  const execute = async function (...args) {
@@ -31,6 +31,6 @@ export function useAsyncAction (fn, options) {
31
31
  loading.value = false
32
32
  }
33
33
  }
34
- return { execute, notif, loading, error }
34
+ return { execute, notif: shallowReadonly(notif), loading: readonly(loading), error: readonly(error) }
35
35
  }
36
36
  export default useAsyncAction
package/fetch.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ofetch } from 'ofetch'
2
2
  import { withQuery } from 'ufo'
3
- import { computed, isRef, watch, ref } from 'vue'
3
+ import { computed, isRef, watch, ref, shallowRef, readonly, shallowReadonly } from 'vue'
4
4
  import { useUiNotif } from '@data-fair/lib-vue/ui-notif.js'
5
5
  export function useFetch (url, options = {}) {
6
6
  const { sendUiNotif } = useUiNotif()
@@ -11,10 +11,10 @@ export function useFetch (url, options = {}) {
11
11
  if (query) { fullUrl = withQuery(fullUrl, query) }
12
12
  return fullUrl
13
13
  })
14
- const data = ref(null)
14
+ const data = shallowRef(null)
15
15
  const loading = ref(false)
16
16
  const initialized = ref(false)
17
- const error = ref(null)
17
+ const error = shallowRef(null)
18
18
  let abortController
19
19
  const refresh = async () => {
20
20
  initialized.value = true
@@ -38,6 +38,12 @@ export function useFetch (url, options = {}) {
38
38
  if (options.watch !== false) {
39
39
  watch(fullUrl, refresh, { immediate: true })
40
40
  }
41
- return { initialized, data, loading, refresh, error }
41
+ return {
42
+ initialized: readonly(initialized),
43
+ data: shallowReadonly(data),
44
+ loading: readonly(loading),
45
+ error: shallowReadonly(error),
46
+ refresh,
47
+ }
42
48
  }
43
49
  export default useFetch
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@data-fair/lib-vue",
3
- "version": "1.15.5",
3
+ "version": "1.15.6",
4
4
  "description": "Composables and other utilities for Vue applications in the data-fair stack.",
5
5
  "main": "index.js",
6
6
  "files": [
package/session.js CHANGED
@@ -1,5 +1,6 @@
1
+ import { shallowReadonly } from 'vue'
1
2
  import { FetchError } from 'ofetch'
2
- import { reactive, computed, watch, inject, ref } from 'vue'
3
+ import { reactive, computed, watch, inject, ref, shallowRef, readonly } from 'vue'
3
4
  import { ofetch } from 'ofetch'
4
5
  import { jwtDecode } from 'jwt-decode'
5
6
  import cookiesModule from 'universal-cookie'
@@ -66,8 +67,8 @@ export async function getSession (initOptions) {
66
67
  })
67
68
  // the core state of the session that is filled by reading cookies
68
69
  const state = reactive({})
69
- const fullSite = ref(null)
70
- const site = ref(null)
70
+ const fullSite = shallowRef(null)
71
+ const site = shallowRef(null)
71
72
  const theme = ref(null)
72
73
  // cookies are the source of truth and this information is transformed into the state reactive object
73
74
  const cookies = initOptions?.cookies ?? new Cookies(options.req?.headers.cookie)
@@ -283,9 +284,9 @@ export async function getSession (initOptions) {
283
284
  account: computed(() => state.account),
284
285
  accountRole: computed(() => state.accountRole),
285
286
  lang: computed(() => state.lang),
286
- theme,
287
- site,
288
- fullSite,
287
+ theme: readonly(theme),
288
+ site: shallowReadonly(site),
289
+ fullSite: shallowReadonly(fullSite),
289
290
  loginUrl,
290
291
  login,
291
292
  logout,
package/ui-notif.d.ts CHANGED
@@ -22,25 +22,25 @@ export declare function getErrorCode(error: any): number;
22
22
  export declare function getErrorMsg(error: any): string;
23
23
  export declare function getFullNotif(notif: PartialUiNotif, defaultType?: UiNotifBase['type']): UiNotif;
24
24
  export declare const getUiNotif: () => {
25
- notification: import("vue").Ref<{
26
- type?: ("default" | "info" | "success" | "warning") | undefined;
27
- msg: string;
25
+ notification: Readonly<import("vue").Ref<{
26
+ readonly type?: ("default" | "info" | "success" | "warning") | undefined;
27
+ readonly msg: string;
28
28
  } | {
29
- type: "error";
30
- msg: string;
31
- error?: any;
32
- errorMsg: string;
33
- clientError?: boolean | undefined;
34
- } | null, UiNotif | {
35
- type?: ("default" | "info" | "success" | "warning") | undefined;
36
- msg: string;
29
+ readonly type: "error";
30
+ readonly msg: string;
31
+ readonly error?: any;
32
+ readonly errorMsg: string;
33
+ readonly clientError?: boolean | undefined;
34
+ } | null, {
35
+ readonly type?: ("default" | "info" | "success" | "warning") | undefined;
36
+ readonly msg: string;
37
37
  } | {
38
- type: "error";
39
- msg: string;
40
- error?: any;
41
- errorMsg: string;
42
- clientError?: boolean | undefined;
43
- } | null>;
38
+ readonly type: "error";
39
+ readonly msg: string;
40
+ readonly error?: any;
41
+ readonly errorMsg: string;
42
+ readonly clientError?: boolean | undefined;
43
+ } | null>>;
44
44
  sendUiNotif: (partialNotif: PartialUiNotif) => void;
45
45
  };
46
46
  export declare const uiNotifKey: unique symbol;
package/ui-notif.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // simple composable to display store a UI notification
2
2
  // this will be transmitted to frame parent if available (compatible with v-iframe uiNotification message type)
3
3
  // or can be displayed locally by @data-fair/lib-vuetify/ui-notif.vue
4
- import { ref, inject } from 'vue'
4
+ import { shallowRef, readonly, inject } from 'vue'
5
5
  import inIframe from '@data-fair/lib-utils/in-iframe.js'
6
6
  export function getErrorCode (error) {
7
7
  if (typeof error === 'string') { return 500 }
@@ -37,7 +37,7 @@ export function getFullNotif (notif, defaultType = 'default') {
37
37
  }
38
38
  }
39
39
  export const getUiNotif = () => {
40
- const notification = ref(null)
40
+ const notification = shallowRef(null)
41
41
  function sendUiNotif (partialNotif) {
42
42
  const notif = notification.value = getFullNotif(partialNotif)
43
43
  if (inIframe) {
@@ -47,7 +47,7 @@ export const getUiNotif = () => {
47
47
  console.log('iframe notification', notif)
48
48
  }
49
49
  }
50
- return { notification, sendUiNotif }
50
+ return { notification: readonly(notification), sendUiNotif }
51
51
  }
52
52
  // uses pattern for SSR friendly plugin/composable, cf https://antfu.me/posts/composable-vue-vueday-2021#shared-state-ssr-friendly
53
53
  export const uiNotifKey = Symbol('uiNotif')