@wagmi/vue 0.0.0-vue-20240513033839
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/LICENSE +21 -0
- package/actions/package.json +5 -0
- package/chains/package.json +5 -0
- package/connectors/package.json +5 -0
- package/dist/esm/composables/useAccount.js +18 -0
- package/dist/esm/composables/useAccount.js.map +1 -0
- package/dist/esm/composables/useAccountEffect.js +37 -0
- package/dist/esm/composables/useAccountEffect.js.map +1 -0
- package/dist/esm/composables/useBlockNumber.js +46 -0
- package/dist/esm/composables/useBlockNumber.js.map +1 -0
- package/dist/esm/composables/useChainId.js +17 -0
- package/dist/esm/composables/useChainId.js.map +1 -0
- package/dist/esm/composables/useChains.js +17 -0
- package/dist/esm/composables/useChains.js.map +1 -0
- package/dist/esm/composables/useClient.js +23 -0
- package/dist/esm/composables/useClient.js.map +1 -0
- package/dist/esm/composables/useConfig.js +19 -0
- package/dist/esm/composables/useConfig.js.map +1 -0
- package/dist/esm/composables/useConnect.js +29 -0
- package/dist/esm/composables/useConnect.js.map +1 -0
- package/dist/esm/composables/useConnections.js +16 -0
- package/dist/esm/composables/useConnections.js.map +1 -0
- package/dist/esm/composables/useConnectorClient.js +49 -0
- package/dist/esm/composables/useConnectorClient.js.map +1 -0
- package/dist/esm/composables/useConnectors.js +16 -0
- package/dist/esm/composables/useConnectors.js.map +1 -0
- package/dist/esm/composables/useDisconnect.js +24 -0
- package/dist/esm/composables/useDisconnect.js.map +1 -0
- package/dist/esm/composables/useReconnect.js +21 -0
- package/dist/esm/composables/useReconnect.js.map +1 -0
- package/dist/esm/composables/useSwitchAccount.js +23 -0
- package/dist/esm/composables/useSwitchAccount.js.map +1 -0
- package/dist/esm/composables/useSwitchChain.js +25 -0
- package/dist/esm/composables/useSwitchChain.js.map +1 -0
- package/dist/esm/composables/useWatchBlockNumber.js +27 -0
- package/dist/esm/composables/useWatchBlockNumber.js.map +1 -0
- package/dist/esm/errors/base.js +20 -0
- package/dist/esm/errors/base.js.map +1 -0
- package/dist/esm/errors/plugin.js +28 -0
- package/dist/esm/errors/plugin.js.map +1 -0
- package/dist/esm/exports/actions.js +5 -0
- package/dist/esm/exports/actions.js.map +1 -0
- package/dist/esm/exports/chains.js +5 -0
- package/dist/esm/exports/chains.js.map +1 -0
- package/dist/esm/exports/connectors.js +5 -0
- package/dist/esm/exports/connectors.js.map +1 -0
- package/dist/esm/exports/index.js +41 -0
- package/dist/esm/exports/index.js.map +1 -0
- package/dist/esm/exports/nuxt.js +4 -0
- package/dist/esm/exports/nuxt.js.map +1 -0
- package/dist/esm/exports/query.js +7 -0
- package/dist/esm/exports/query.js.map +1 -0
- package/dist/esm/nuxt/module.js +19 -0
- package/dist/esm/nuxt/module.js.map +1 -0
- package/dist/esm/plugin.js +14 -0
- package/dist/esm/plugin.js.map +1 -0
- package/dist/esm/tsconfig.build.tsbuildinfo +1 -0
- package/dist/esm/types/properties.js +2 -0
- package/dist/esm/types/properties.js.map +1 -0
- package/dist/esm/types/ref.js +3 -0
- package/dist/esm/types/ref.js.map +1 -0
- package/dist/esm/utils/cloneDeep.js +36 -0
- package/dist/esm/utils/cloneDeep.js.map +1 -0
- package/dist/esm/utils/getVersion.js +3 -0
- package/dist/esm/utils/getVersion.js.map +1 -0
- package/dist/esm/utils/query.js +73 -0
- package/dist/esm/utils/query.js.map +1 -0
- package/dist/esm/utils/updateState.js +7 -0
- package/dist/esm/utils/updateState.js.map +1 -0
- package/dist/esm/version.js +2 -0
- package/dist/esm/version.js.map +1 -0
- package/dist/types/composables/useAccount.d.ts +8 -0
- package/dist/types/composables/useAccount.d.ts.map +1 -0
- package/dist/types/composables/useAccountEffect.d.ts +15 -0
- package/dist/types/composables/useAccountEffect.d.ts.map +1 -0
- package/dist/types/composables/useBlockNumber.d.ts +14 -0
- package/dist/types/composables/useBlockNumber.d.ts.map +1 -0
- package/dist/types/composables/useChainId.d.ts +8 -0
- package/dist/types/composables/useChainId.d.ts.map +1 -0
- package/dist/types/composables/useChains.d.ts +9 -0
- package/dist/types/composables/useChains.d.ts.map +1 -0
- package/dist/types/composables/useClient.d.ts +10 -0
- package/dist/types/composables/useClient.d.ts.map +1 -0
- package/dist/types/composables/useConfig.d.ts +8 -0
- package/dist/types/composables/useConfig.d.ts.map +1 -0
- package/dist/types/composables/useConnect.d.ts +16 -0
- package/dist/types/composables/useConnect.d.ts.map +1 -0
- package/dist/types/composables/useConnections.d.ts +8 -0
- package/dist/types/composables/useConnections.d.ts.map +1 -0
- package/dist/types/composables/useConnectorClient.d.ts +13 -0
- package/dist/types/composables/useConnectorClient.d.ts.map +1 -0
- package/dist/types/composables/useConnectors.d.ts +8 -0
- package/dist/types/composables/useConnectors.d.ts.map +1 -0
- package/dist/types/composables/useDisconnect.d.ts +17 -0
- package/dist/types/composables/useDisconnect.d.ts.map +1 -0
- package/dist/types/composables/useReconnect.d.ts +16 -0
- package/dist/types/composables/useReconnect.d.ts.map +1 -0
- package/dist/types/composables/useSwitchAccount.d.ts +17 -0
- package/dist/types/composables/useSwitchAccount.d.ts.map +1 -0
- package/dist/types/composables/useSwitchChain.d.ts +17 -0
- package/dist/types/composables/useSwitchChain.d.ts.map +1 -0
- package/dist/types/composables/useWatchBlockNumber.d.ts +9 -0
- package/dist/types/composables/useWatchBlockNumber.d.ts.map +1 -0
- package/dist/types/errors/base.d.ts +10 -0
- package/dist/types/errors/base.d.ts.map +1 -0
- package/dist/types/errors/plugin.d.ts +16 -0
- package/dist/types/errors/plugin.d.ts.map +1 -0
- package/dist/types/exports/actions.d.ts +2 -0
- package/dist/types/exports/actions.d.ts.map +1 -0
- package/dist/types/exports/chains.d.ts +2 -0
- package/dist/types/exports/chains.d.ts.map +1 -0
- package/dist/types/exports/connectors.d.ts +2 -0
- package/dist/types/exports/connectors.d.ts.map +1 -0
- package/dist/types/exports/index.d.ts +22 -0
- package/dist/types/exports/index.d.ts.map +1 -0
- package/dist/types/exports/nuxt.d.ts +4 -0
- package/dist/types/exports/nuxt.d.ts.map +1 -0
- package/dist/types/exports/query.d.ts +4 -0
- package/dist/types/exports/query.d.ts.map +1 -0
- package/dist/types/nuxt/module.d.ts +4 -0
- package/dist/types/nuxt/module.d.ts.map +1 -0
- package/dist/types/plugin.d.ts +11 -0
- package/dist/types/plugin.d.ts.map +1 -0
- package/dist/types/types/properties.d.ts +15 -0
- package/dist/types/types/properties.d.ts.map +1 -0
- package/dist/types/types/ref.d.ts +12 -0
- package/dist/types/types/ref.d.ts.map +1 -0
- package/dist/types/utils/cloneDeep.d.ts +3 -0
- package/dist/types/utils/cloneDeep.d.ts.map +1 -0
- package/dist/types/utils/getVersion.d.ts +2 -0
- package/dist/types/utils/getVersion.d.ts.map +1 -0
- package/dist/types/utils/query.d.ts +17 -0
- package/dist/types/utils/query.d.ts.map +1 -0
- package/dist/types/utils/updateState.d.ts +2 -0
- package/dist/types/utils/updateState.d.ts.map +1 -0
- package/dist/types/version.d.ts +2 -0
- package/dist/types/version.d.ts.map +1 -0
- package/nuxt/package.json +5 -0
- package/package.json +108 -0
- package/query/package.json +5 -0
- package/src/composables/useAccount.ts +37 -0
- package/src/composables/useAccountEffect.ts +66 -0
- package/src/composables/useBlockNumber.ts +118 -0
- package/src/composables/useChainId.ts +35 -0
- package/src/composables/useChains.ts +38 -0
- package/src/composables/useClient.ts +66 -0
- package/src/composables/useConfig.ts +34 -0
- package/src/composables/useConnect.ts +91 -0
- package/src/composables/useConnections.ts +30 -0
- package/src/composables/useConnectorClient.ts +127 -0
- package/src/composables/useConnectors.ts +30 -0
- package/src/composables/useDisconnect.ts +70 -0
- package/src/composables/useReconnect.ts +65 -0
- package/src/composables/useSwitchAccount.ts +84 -0
- package/src/composables/useSwitchChain.ts +80 -0
- package/src/composables/useWatchBlockNumber.ts +61 -0
- package/src/errors/base.ts +14 -0
- package/src/errors/plugin.ts +31 -0
- package/src/exports/actions.ts +5 -0
- package/src/exports/chains.ts +5 -0
- package/src/exports/connectors.ts +5 -0
- package/src/exports/index.ts +176 -0
- package/src/exports/nuxt.ts +4 -0
- package/src/exports/query.ts +17 -0
- package/src/nuxt/module.ts +25 -0
- package/src/plugin.ts +22 -0
- package/src/types/properties.ts +27 -0
- package/src/types/ref.ts +36 -0
- package/src/utils/cloneDeep.ts +43 -0
- package/src/utils/getVersion.ts +3 -0
- package/src/utils/query.ts +159 -0
- package/src/utils/updateState.ts +10 -0
- package/src/version.ts +1 -0
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Plugin
|
|
3
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
4
|
+
|
|
5
|
+
export { configKey, type WagmiPluginOptions, WagmiPlugin } from '../plugin.js'
|
|
6
|
+
|
|
7
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
8
|
+
// Errors
|
|
9
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
10
|
+
|
|
11
|
+
export { type BaseErrorType, BaseError } from '../errors/base.js'
|
|
12
|
+
|
|
13
|
+
export {
|
|
14
|
+
type WagmiPluginNotFoundErrorType,
|
|
15
|
+
WagmiPluginNotFoundError,
|
|
16
|
+
type WagmiInjectionContextErrorType,
|
|
17
|
+
WagmiInjectionContextError,
|
|
18
|
+
} from '../errors/plugin.js'
|
|
19
|
+
|
|
20
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
21
|
+
// Composables
|
|
22
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
23
|
+
|
|
24
|
+
export {
|
|
25
|
+
type UseAccountParameters,
|
|
26
|
+
type UseAccountReturnType,
|
|
27
|
+
useAccount,
|
|
28
|
+
} from '../composables/useAccount.js'
|
|
29
|
+
|
|
30
|
+
export {
|
|
31
|
+
type UseAccountEffectParameters,
|
|
32
|
+
useAccountEffect,
|
|
33
|
+
} from '../composables/useAccountEffect.js'
|
|
34
|
+
|
|
35
|
+
export {
|
|
36
|
+
type UseBlockNumberParameters,
|
|
37
|
+
type UseBlockNumberReturnType,
|
|
38
|
+
useBlockNumber,
|
|
39
|
+
} from '../composables/useBlockNumber.js'
|
|
40
|
+
|
|
41
|
+
export {
|
|
42
|
+
type UseChainIdParameters,
|
|
43
|
+
type UseChainIdReturnType,
|
|
44
|
+
useChainId,
|
|
45
|
+
} from '../composables/useChainId.js'
|
|
46
|
+
|
|
47
|
+
export {
|
|
48
|
+
type UseClientParameters,
|
|
49
|
+
type UseClientReturnType,
|
|
50
|
+
useClient,
|
|
51
|
+
} from '../composables/useClient.js'
|
|
52
|
+
|
|
53
|
+
export {
|
|
54
|
+
type UseConnectorClientParameters,
|
|
55
|
+
type UseConnectorClientReturnType,
|
|
56
|
+
useConnectorClient,
|
|
57
|
+
} from '../composables/useConnectorClient.js'
|
|
58
|
+
|
|
59
|
+
export {
|
|
60
|
+
type UseChainsParameters,
|
|
61
|
+
type UseChainsReturnType,
|
|
62
|
+
useChains,
|
|
63
|
+
} from '../composables/useChains.js'
|
|
64
|
+
|
|
65
|
+
export {
|
|
66
|
+
type UseConfigParameters,
|
|
67
|
+
type UseConfigReturnType,
|
|
68
|
+
useConfig,
|
|
69
|
+
} from '../composables/useConfig.js'
|
|
70
|
+
|
|
71
|
+
export {
|
|
72
|
+
type UseConnectParameters,
|
|
73
|
+
type UseConnectReturnType,
|
|
74
|
+
useConnect,
|
|
75
|
+
} from '../composables/useConnect.js'
|
|
76
|
+
|
|
77
|
+
export {
|
|
78
|
+
type UseConnectionsParameters,
|
|
79
|
+
type UseConnectionsReturnType,
|
|
80
|
+
useConnections,
|
|
81
|
+
} from '../composables/useConnections.js'
|
|
82
|
+
|
|
83
|
+
export {
|
|
84
|
+
type UseConnectorsParameters,
|
|
85
|
+
type UseConnectorsReturnType,
|
|
86
|
+
useConnectors,
|
|
87
|
+
} from '../composables/useConnectors.js'
|
|
88
|
+
|
|
89
|
+
export {
|
|
90
|
+
type UseDisconnectParameters,
|
|
91
|
+
type UseDisconnectReturnType,
|
|
92
|
+
useDisconnect,
|
|
93
|
+
} from '../composables/useDisconnect.js'
|
|
94
|
+
|
|
95
|
+
export {
|
|
96
|
+
type UseReconnectParameters,
|
|
97
|
+
type UseReconnectReturnType,
|
|
98
|
+
useReconnect,
|
|
99
|
+
} from '../composables/useReconnect.js'
|
|
100
|
+
|
|
101
|
+
export {
|
|
102
|
+
type UseSwitchAccountParameters,
|
|
103
|
+
type UseSwitchAccountReturnType,
|
|
104
|
+
useSwitchAccount,
|
|
105
|
+
} from '../composables/useSwitchAccount.js'
|
|
106
|
+
|
|
107
|
+
export {
|
|
108
|
+
type UseSwitchChainParameters,
|
|
109
|
+
type UseSwitchChainReturnType,
|
|
110
|
+
useSwitchChain,
|
|
111
|
+
} from '../composables/useSwitchChain.js'
|
|
112
|
+
|
|
113
|
+
export {
|
|
114
|
+
type UseWatchBlockNumberParameters,
|
|
115
|
+
type UseWatchBlockNumberReturnType,
|
|
116
|
+
useWatchBlockNumber,
|
|
117
|
+
} from '../composables/useWatchBlockNumber.js'
|
|
118
|
+
|
|
119
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
120
|
+
// @wagmi/core
|
|
121
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
122
|
+
|
|
123
|
+
export {
|
|
124
|
+
// Config
|
|
125
|
+
type Connection,
|
|
126
|
+
type Connector,
|
|
127
|
+
type Config,
|
|
128
|
+
type CreateConfigParameters,
|
|
129
|
+
type State,
|
|
130
|
+
createConfig,
|
|
131
|
+
// Connector
|
|
132
|
+
type ConnectorEventMap,
|
|
133
|
+
type CreateConnectorFn,
|
|
134
|
+
createConnector,
|
|
135
|
+
// Errors
|
|
136
|
+
type ChainNotConfiguredErrorType,
|
|
137
|
+
ChainNotConfiguredError,
|
|
138
|
+
type ConnectorAlreadyConnectedErrorType,
|
|
139
|
+
ConnectorAlreadyConnectedError,
|
|
140
|
+
type ConnectorNotFoundErrorType,
|
|
141
|
+
ConnectorNotFoundError,
|
|
142
|
+
type ConnectorAccountNotFoundErrorType,
|
|
143
|
+
ConnectorAccountNotFoundError,
|
|
144
|
+
type ProviderNotFoundErrorType,
|
|
145
|
+
ProviderNotFoundError,
|
|
146
|
+
type SwitchChainNotSupportedErrorType,
|
|
147
|
+
SwitchChainNotSupportedError,
|
|
148
|
+
// Storage
|
|
149
|
+
type CreateStorageParameters,
|
|
150
|
+
type Storage,
|
|
151
|
+
createStorage,
|
|
152
|
+
noopStorage,
|
|
153
|
+
// Transports
|
|
154
|
+
custom,
|
|
155
|
+
fallback,
|
|
156
|
+
http,
|
|
157
|
+
webSocket,
|
|
158
|
+
unstable_connector,
|
|
159
|
+
// Types
|
|
160
|
+
type Register,
|
|
161
|
+
type ResolvedRegister,
|
|
162
|
+
// Utilities
|
|
163
|
+
cookieStorage,
|
|
164
|
+
cookieToInitialState,
|
|
165
|
+
deepEqual,
|
|
166
|
+
deserialize,
|
|
167
|
+
normalizeChainId,
|
|
168
|
+
parseCookie,
|
|
169
|
+
serialize,
|
|
170
|
+
} from '@wagmi/core'
|
|
171
|
+
|
|
172
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
173
|
+
// Version
|
|
174
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
175
|
+
|
|
176
|
+
export { version } from '../version.js'
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// @wagmi/core/query
|
|
3
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
4
|
+
|
|
5
|
+
export * from '@wagmi/core/query'
|
|
6
|
+
|
|
7
|
+
export {
|
|
8
|
+
type UseMutationParameters,
|
|
9
|
+
type UseMutationReturnType,
|
|
10
|
+
useMutation,
|
|
11
|
+
} from '../utils/query.js'
|
|
12
|
+
|
|
13
|
+
export {
|
|
14
|
+
type UseQueryParameters,
|
|
15
|
+
type UseQueryReturnType,
|
|
16
|
+
useQuery,
|
|
17
|
+
} from '../utils/query.js'
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { fileURLToPath } from 'node:url'
|
|
2
|
+
import type { NuxtModule } from '@nuxt/schema'
|
|
3
|
+
import { defineNuxtModule } from 'nuxt/kit'
|
|
4
|
+
|
|
5
|
+
// TODO: createConfig parameters to options?
|
|
6
|
+
export type WagmiModuleOptions = {}
|
|
7
|
+
|
|
8
|
+
export const wagmiModule: NuxtModule<WagmiModuleOptions> =
|
|
9
|
+
defineNuxtModule<WagmiModuleOptions>({
|
|
10
|
+
meta: {
|
|
11
|
+
name: '@wagmi/vue',
|
|
12
|
+
configKey: 'wagmi',
|
|
13
|
+
compatibility: {
|
|
14
|
+
nuxt: '^3.0.0',
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
setup(_options, nuxt) {
|
|
18
|
+
// Transpile runtime
|
|
19
|
+
const runtimeDir = fileURLToPath(new URL('./runtime', import.meta.url))
|
|
20
|
+
nuxt.options.build.transpile.push(runtimeDir)
|
|
21
|
+
|
|
22
|
+
// TODO: Add client and server plugins
|
|
23
|
+
// TODO: Auto import composables
|
|
24
|
+
},
|
|
25
|
+
})
|
package/src/plugin.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type ResolvedRegister, type State, hydrate } from '@wagmi/core'
|
|
2
|
+
import type { Plugin } from 'vue'
|
|
3
|
+
|
|
4
|
+
export const configKey = Symbol()
|
|
5
|
+
|
|
6
|
+
export type WagmiPluginOptions = {
|
|
7
|
+
config: ResolvedRegister['config']
|
|
8
|
+
initialState?: State | undefined
|
|
9
|
+
reconnectOnMount?: boolean | undefined
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const WagmiPlugin = {
|
|
13
|
+
install(app, options) {
|
|
14
|
+
const { config, reconnectOnMount = true } = options
|
|
15
|
+
app.provide(configKey, config)
|
|
16
|
+
// TODO: check this works in SSR env.
|
|
17
|
+
// - reconnect on mount.
|
|
18
|
+
// - hydrate initial state.
|
|
19
|
+
const { onMount } = hydrate(config, { ...options, reconnectOnMount })
|
|
20
|
+
onMount()
|
|
21
|
+
},
|
|
22
|
+
} satisfies Plugin<WagmiPluginOptions>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { DefaultError, QueryKey } from '@tanstack/vue-query'
|
|
2
|
+
import type { Config } from '@wagmi/core'
|
|
3
|
+
import type { MaybeRef } from 'vue'
|
|
4
|
+
import type { UseQueryParameters } from '../utils/query.js'
|
|
5
|
+
import type { DeepUnwrapRef } from './ref.js'
|
|
6
|
+
|
|
7
|
+
export type ConfigParameter<config extends Config = Config> = {
|
|
8
|
+
config?: Config | config | undefined
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type EnabledParameter = {
|
|
12
|
+
enabled?: MaybeRef<boolean> | undefined
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type QueryParameter<
|
|
16
|
+
queryFnData = unknown,
|
|
17
|
+
error = DefaultError,
|
|
18
|
+
data = queryFnData,
|
|
19
|
+
queryKey extends QueryKey = QueryKey,
|
|
20
|
+
> = {
|
|
21
|
+
query?:
|
|
22
|
+
| Omit<
|
|
23
|
+
DeepUnwrapRef<UseQueryParameters<queryFnData, error, data, queryKey>>,
|
|
24
|
+
'queryFn' | 'queryHash' | 'queryKey' | 'queryKeyHashFn' | 'throwOnError'
|
|
25
|
+
>
|
|
26
|
+
| undefined
|
|
27
|
+
}
|
package/src/types/ref.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Credit: https://github.com/TanStack/query/blob/01ce023826b81e6c41e354f27691f65c9725af67/packages/vue-query/src/types.ts
|
|
2
|
+
|
|
3
|
+
import type { Config } from '@wagmi/core'
|
|
4
|
+
import type { MaybeRef, Ref, UnwrapRef } from 'vue'
|
|
5
|
+
|
|
6
|
+
type Primitive = string | number | boolean | bigint | symbol | undefined | null
|
|
7
|
+
type UnwrapLeaf =
|
|
8
|
+
| Primitive
|
|
9
|
+
| Function
|
|
10
|
+
| Date
|
|
11
|
+
| Error
|
|
12
|
+
| RegExp
|
|
13
|
+
| Map<any, any>
|
|
14
|
+
| WeakMap<any, any>
|
|
15
|
+
| Set<any>
|
|
16
|
+
| WeakSet<any>
|
|
17
|
+
|
|
18
|
+
export type DeepMaybeRef<value> = MaybeRef<
|
|
19
|
+
value extends Function | Config
|
|
20
|
+
? value
|
|
21
|
+
: value extends object
|
|
22
|
+
? {
|
|
23
|
+
[key in keyof value]: DeepMaybeRef<value[key]>
|
|
24
|
+
}
|
|
25
|
+
: value
|
|
26
|
+
>
|
|
27
|
+
|
|
28
|
+
export type DeepUnwrapRef<T> = T extends UnwrapLeaf
|
|
29
|
+
? T
|
|
30
|
+
: T extends Ref<infer U>
|
|
31
|
+
? DeepUnwrapRef<U>
|
|
32
|
+
: T extends {}
|
|
33
|
+
? {
|
|
34
|
+
[Property in keyof T]: DeepUnwrapRef<T[Property]>
|
|
35
|
+
}
|
|
36
|
+
: UnwrapRef<T>
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Credit: https://github.com/TanStack/query/blob/01ce023826b81e6c41e354f27691f65c9725af67/packages/vue-query/src/utils.ts
|
|
2
|
+
|
|
3
|
+
import { isRef, unref } from 'vue'
|
|
4
|
+
|
|
5
|
+
import type { DeepMaybeRef, DeepUnwrapRef } from '../types/ref.js'
|
|
6
|
+
|
|
7
|
+
function cloneDeep<value>(
|
|
8
|
+
value: DeepMaybeRef<value>,
|
|
9
|
+
customize?: (val: DeepMaybeRef<value>) => value | undefined,
|
|
10
|
+
): value {
|
|
11
|
+
if (customize) {
|
|
12
|
+
const result = customize(value)
|
|
13
|
+
// If it's a ref of undefined, return undefined
|
|
14
|
+
if (result === undefined && isRef(value)) return result as value
|
|
15
|
+
if (result !== undefined) return result
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (Array.isArray(value))
|
|
19
|
+
return value.map((val) => cloneDeep(val, customize)) as unknown as value
|
|
20
|
+
|
|
21
|
+
if (typeof value === 'object' && isPlainObject(value)) {
|
|
22
|
+
const entries = Object.entries(value).map(([key, val]) => [
|
|
23
|
+
key,
|
|
24
|
+
cloneDeep(val, customize),
|
|
25
|
+
])
|
|
26
|
+
return Object.fromEntries(entries)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return value as value
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function deepUnref<value>(value: value): DeepUnwrapRef<value> {
|
|
33
|
+
return cloneDeep(value as any, (val) => {
|
|
34
|
+
if (isRef(val)) return deepUnref(unref(val))
|
|
35
|
+
return undefined
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function isPlainObject(value: unknown): value is Object {
|
|
40
|
+
if (Object.prototype.toString.call(value) !== '[object Object]') return false
|
|
41
|
+
const prototype = Object.getPrototypeOf(value)
|
|
42
|
+
return prototype === null || prototype === Object.prototype
|
|
43
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type DefaultError,
|
|
3
|
+
type MutationObserverOptions,
|
|
4
|
+
type QueryKey,
|
|
5
|
+
type QueryObserverOptions,
|
|
6
|
+
type UseMutationReturnType as tanstack_UseMutationReturnType,
|
|
7
|
+
type UseQueryReturnType as tanstack_UseQueryReturnType,
|
|
8
|
+
useMutation,
|
|
9
|
+
useQuery as tanstack_useQuery,
|
|
10
|
+
} from '@tanstack/vue-query'
|
|
11
|
+
import {
|
|
12
|
+
type Evaluate,
|
|
13
|
+
type ExactPartial,
|
|
14
|
+
type Omit,
|
|
15
|
+
type UnionOmit,
|
|
16
|
+
} from '@wagmi/core/internal'
|
|
17
|
+
import { hashFn } from '@wagmi/core/query'
|
|
18
|
+
import { type MaybeRef, computed, unref } from 'vue'
|
|
19
|
+
|
|
20
|
+
import type { DeepMaybeRef, DeepUnwrapRef } from '../types/ref.js'
|
|
21
|
+
|
|
22
|
+
export type UseMutationParameters<
|
|
23
|
+
data = unknown,
|
|
24
|
+
error = Error,
|
|
25
|
+
variables = void,
|
|
26
|
+
context = unknown,
|
|
27
|
+
> = Evaluate<
|
|
28
|
+
DeepMaybeRef<
|
|
29
|
+
Omit<
|
|
30
|
+
DeepUnwrapRef<
|
|
31
|
+
MutationObserverOptions<data, error, Evaluate<variables>, context>
|
|
32
|
+
>,
|
|
33
|
+
'mutationFn' | 'mutationKey' | 'throwOnError'
|
|
34
|
+
>
|
|
35
|
+
>
|
|
36
|
+
>
|
|
37
|
+
|
|
38
|
+
export type UseMutationReturnType<
|
|
39
|
+
data = unknown,
|
|
40
|
+
error = Error,
|
|
41
|
+
variables = void,
|
|
42
|
+
context = unknown,
|
|
43
|
+
> = Evaluate<
|
|
44
|
+
UnionOmit<
|
|
45
|
+
tanstack_UseMutationReturnType<data, error, variables, context>,
|
|
46
|
+
'mutate' | 'mutateAsync'
|
|
47
|
+
>
|
|
48
|
+
>
|
|
49
|
+
|
|
50
|
+
export { useMutation }
|
|
51
|
+
|
|
52
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
53
|
+
|
|
54
|
+
export type UseQueryParameters<
|
|
55
|
+
queryFnData = unknown,
|
|
56
|
+
error = DefaultError,
|
|
57
|
+
data = queryFnData,
|
|
58
|
+
queryKey extends QueryKey = QueryKey,
|
|
59
|
+
> = Evaluate<
|
|
60
|
+
DeepMaybeRef<
|
|
61
|
+
ExactPartial<
|
|
62
|
+
Omit<
|
|
63
|
+
DeepUnwrapRef<QueryObserverOptions<queryFnData, error, data, queryKey>>,
|
|
64
|
+
'initialData'
|
|
65
|
+
>
|
|
66
|
+
> & {
|
|
67
|
+
// Fix `initialData` type
|
|
68
|
+
initialData?:
|
|
69
|
+
| DeepUnwrapRef<
|
|
70
|
+
QueryObserverOptions<queryFnData, error, data, queryKey>
|
|
71
|
+
>['initialData']
|
|
72
|
+
| undefined
|
|
73
|
+
}
|
|
74
|
+
>
|
|
75
|
+
>
|
|
76
|
+
|
|
77
|
+
export type UseQueryReturnType<data = unknown, error = DefaultError> = Evaluate<
|
|
78
|
+
tanstack_UseQueryReturnType<data, error> & {
|
|
79
|
+
queryKey: QueryKey
|
|
80
|
+
}
|
|
81
|
+
>
|
|
82
|
+
|
|
83
|
+
// Adding some basic customization.
|
|
84
|
+
// Ideally we don't have this function, but `import('@tanstack/vue-query').useQuery` currently has some quirks where it is super hard to
|
|
85
|
+
// pass down the inferred `initialData` type because of it's discriminated overload in the on `useQuery`.
|
|
86
|
+
export function useQuery<queryFnData, error, data, queryKey extends QueryKey>(
|
|
87
|
+
parameters: MaybeRef<
|
|
88
|
+
UseQueryParameters<queryFnData, error, data, queryKey> & {
|
|
89
|
+
queryKey: QueryKey
|
|
90
|
+
}
|
|
91
|
+
>,
|
|
92
|
+
): UseQueryReturnType<data, error> {
|
|
93
|
+
const options = computed(() => ({
|
|
94
|
+
...(unref(parameters) as any),
|
|
95
|
+
queryKeyHashFn: hashFn,
|
|
96
|
+
}))
|
|
97
|
+
const result = tanstack_useQuery(options) as UseQueryReturnType<data, error>
|
|
98
|
+
result.queryKey = unref(options).queryKey as QueryKey
|
|
99
|
+
return result
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
103
|
+
|
|
104
|
+
// export type UseInfiniteQueryParameters<
|
|
105
|
+
// queryFnData = unknown,
|
|
106
|
+
// error = DefaultError,
|
|
107
|
+
// data = queryFnData,
|
|
108
|
+
// queryData = queryFnData,
|
|
109
|
+
// queryKey extends QueryKey = QueryKey,
|
|
110
|
+
// pageParam = unknown,
|
|
111
|
+
// > = Evaluate<
|
|
112
|
+
// Omit<
|
|
113
|
+
// UseInfiniteQueryOptions<
|
|
114
|
+
// queryFnData,
|
|
115
|
+
// error,
|
|
116
|
+
// data,
|
|
117
|
+
// queryData,
|
|
118
|
+
// queryKey,
|
|
119
|
+
// pageParam
|
|
120
|
+
// >,
|
|
121
|
+
// 'initialData'
|
|
122
|
+
// > & {
|
|
123
|
+
// // Fix `initialData` type
|
|
124
|
+
// initialData?:
|
|
125
|
+
// | UseInfiniteQueryOptions<
|
|
126
|
+
// queryFnData,
|
|
127
|
+
// error,
|
|
128
|
+
// data,
|
|
129
|
+
// queryKey
|
|
130
|
+
// >['initialData']
|
|
131
|
+
// | undefined
|
|
132
|
+
// }
|
|
133
|
+
// >
|
|
134
|
+
|
|
135
|
+
// export type UseInfiniteQueryReturnType<
|
|
136
|
+
// data = unknown,
|
|
137
|
+
// error = DefaultError,
|
|
138
|
+
// > = import('@tanstack/vue-query').UseInfiniteQueryReturnType<data, error> & {
|
|
139
|
+
// queryKey: QueryKey
|
|
140
|
+
// }
|
|
141
|
+
|
|
142
|
+
// // Adding some basic customization.
|
|
143
|
+
// export function useInfiniteQuery<
|
|
144
|
+
// queryFnData,
|
|
145
|
+
// error,
|
|
146
|
+
// data,
|
|
147
|
+
// queryKey extends QueryKey,
|
|
148
|
+
// >(
|
|
149
|
+
// parameters: UseInfiniteQueryParameters<queryFnData, error, data, queryKey> & {
|
|
150
|
+
// queryKey: QueryKey
|
|
151
|
+
// },
|
|
152
|
+
// ): UseInfiniteQueryReturnType<data, error> {
|
|
153
|
+
// const result = tanstack_useInfiniteQuery({
|
|
154
|
+
// ...(parameters as any),
|
|
155
|
+
// queryKeyHashFn: hashFn, // for bigint support
|
|
156
|
+
// }) as UseInfiniteQueryReturnType<data, error>
|
|
157
|
+
// result.queryKey = parameters.queryKey
|
|
158
|
+
// return result
|
|
159
|
+
// }
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Credit: https://github.com/TanStack/query/blob/01ce023826b81e6c41e354f27691f65c9725af67/packages/vue-query/src/utils.ts#L11-L18
|
|
2
|
+
|
|
3
|
+
export function updateState(
|
|
4
|
+
state: Record<string, unknown>,
|
|
5
|
+
update: Record<string, any>,
|
|
6
|
+
): void {
|
|
7
|
+
Object.keys(state).forEach((key) => {
|
|
8
|
+
state[key] = update[key]
|
|
9
|
+
})
|
|
10
|
+
}
|
package/src/version.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const version = '0.0.0-vue-20240513033839'
|