2023-04-07 16:02:47 +00:00
|
|
|
import { isReactive, isRef, isShallow, toRaw } from 'vue'
|
2023-04-07 10:34:35 +00:00
|
|
|
import { definePayloadReducer } from '#app/composables/payload'
|
|
|
|
import { isNuxtError } from '#app/composables/error'
|
|
|
|
import { defineNuxtPlugin } from '#app/nuxt'
|
|
|
|
/* Defining a plugin that will be used by the Nuxt framework. */
|
|
|
|
|
|
|
|
const reducers = {
|
|
|
|
NuxtError: (data: any) => isNuxtError(data) && data.toJSON(),
|
2023-05-13 19:49:05 +00:00
|
|
|
EmptyShallowRef: (data: any) => isRef(data) && isShallow(data) && !data.value && (JSON.stringify(data.value) || '_'),
|
|
|
|
EmptyRef: (data: any) => isRef(data) && !data.value && (JSON.stringify(data.value) || '_'),
|
2023-04-07 10:34:35 +00:00
|
|
|
ShallowRef: (data: any) => isRef(data) && isShallow(data) && data.value,
|
|
|
|
ShallowReactive: (data: any) => isReactive(data) && isShallow(data) && toRaw(data),
|
|
|
|
Ref: (data: any) => isRef(data) && data.value,
|
|
|
|
Reactive: (data: any) => isReactive(data) && toRaw(data)
|
|
|
|
}
|
|
|
|
|
2023-04-11 11:58:43 +00:00
|
|
|
export default defineNuxtPlugin({
|
|
|
|
name: 'nuxt:revive-payload:server',
|
|
|
|
setup () {
|
|
|
|
for (const reducer in reducers) {
|
|
|
|
definePayloadReducer(reducer, reducers[reducer as keyof typeof reducers])
|
|
|
|
}
|
2023-04-07 10:34:35 +00:00
|
|
|
}
|
|
|
|
})
|