@composy/store-vue 0.0.1
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/README.md +154 -0
- package/dist/index.js +1536 -0
- package/dist/index.js.map +1 -0
- package/dist/index.min.js +1008 -0
- package/dist/index.min.js.map +1 -0
- package/es/composables/defineSetupStore.d.ts +120 -0
- package/es/composables/defineSetupStore.d.ts.map +1 -0
- package/es/composables/defineSetupStore.js +29 -0
- package/es/composables/defineSetupStore.js.map +1 -0
- package/es/composables/index.d.ts +24 -0
- package/es/composables/index.d.ts.map +1 -0
- package/es/composables/index.js +21 -0
- package/es/composables/useFormStore.d.ts +131 -0
- package/es/composables/useFormStore.d.ts.map +1 -0
- package/es/composables/useFormStore.js +189 -0
- package/es/composables/useFormStore.js.map +1 -0
- package/es/composables/useOptimistic.d.ts +67 -0
- package/es/composables/useOptimistic.d.ts.map +1 -0
- package/es/composables/useOptimistic.js +64 -0
- package/es/composables/useOptimistic.js.map +1 -0
- package/es/composables/usePersist.d.ts +68 -0
- package/es/composables/usePersist.d.ts.map +1 -0
- package/es/composables/usePersist.js +96 -0
- package/es/composables/usePersist.js.map +1 -0
- package/es/composables/usePersistedState.d.ts +59 -0
- package/es/composables/usePersistedState.d.ts.map +1 -0
- package/es/composables/usePersistedState.js +121 -0
- package/es/composables/usePersistedState.js.map +1 -0
- package/es/composables/useSharedState.d.ts +62 -0
- package/es/composables/useSharedState.d.ts.map +1 -0
- package/es/composables/useSharedState.js +94 -0
- package/es/composables/useSharedState.js.map +1 -0
- package/es/composables/useStore.d.ts +99 -0
- package/es/composables/useStore.d.ts.map +1 -0
- package/es/composables/useStore.js +61 -0
- package/es/composables/useStore.js.map +1 -0
- package/es/composables/useStoreDevtools.d.ts +31 -0
- package/es/composables/useStoreDevtools.d.ts.map +1 -0
- package/es/composables/useStoreDevtools.js +112 -0
- package/es/composables/useStoreDevtools.js.map +1 -0
- package/es/composables/useStoreSnapshot.d.ts +122 -0
- package/es/composables/useStoreSnapshot.d.ts.map +1 -0
- package/es/composables/useStoreSnapshot.js +209 -0
- package/es/composables/useStoreSnapshot.js.map +1 -0
- package/es/composables/useSubscribe.d.ts +90 -0
- package/es/composables/useSubscribe.d.ts.map +1 -0
- package/es/composables/useSubscribe.js +53 -0
- package/es/composables/useSubscribe.js.map +1 -0
- package/es/context/injection-keys.d.ts +8 -0
- package/es/context/injection-keys.d.ts.map +1 -0
- package/es/context/injection-keys.js +17 -0
- package/es/context/injection-keys.js.map +1 -0
- package/es/index.d.ts +24 -0
- package/es/index.d.ts.map +1 -0
- package/es/index.js +32 -0
- package/es/index.js.map +1 -0
- package/es/plugins/engine-plugin.d.ts +36 -0
- package/es/plugins/engine-plugin.d.ts.map +1 -0
- package/es/plugins/engine-plugin.js +83 -0
- package/es/plugins/engine-plugin.js.map +1 -0
- package/es/plugins/enhanced-persist-plugin.d.ts +3 -0
- package/es/plugins/enhanced-persist-plugin.d.ts.map +1 -0
- package/es/plugins/enhanced-persist-plugin.js +12 -0
- package/es/plugins/index.d.ts +7 -0
- package/es/plugins/index.d.ts.map +1 -0
- package/es/plugins/index.js +15 -0
- package/es/plugins/pinia-plugin.d.ts +68 -0
- package/es/plugins/pinia-plugin.d.ts.map +1 -0
- package/es/plugins/pinia-plugin.js +172 -0
- package/es/plugins/pinia-plugin.js.map +1 -0
- package/es/plugins/registry-plugin.d.ts +2 -0
- package/es/plugins/registry-plugin.d.ts.map +1 -0
- package/es/plugins/registry-plugin.js +12 -0
- package/es/plugins/vue-plugin.d.ts +10 -0
- package/es/plugins/vue-plugin.d.ts.map +1 -0
- package/es/plugins/vue-plugin.js +24 -0
- package/es/plugins/vue-plugin.js.map +1 -0
- package/es/runtime/install-store-app.d.ts +23 -0
- package/es/runtime/install-store-app.d.ts.map +1 -0
- package/es/runtime/install-store-app.js +54 -0
- package/es/runtime/install-store-app.js.map +1 -0
- package/es/runtime/store-plugin-options.d.ts +40 -0
- package/es/runtime/store-plugin-options.d.ts.map +1 -0
- package/es/runtime/store-plugin-options.js +24 -0
- package/es/runtime/store-plugin-options.js.map +1 -0
- package/es/runtime/store-registry.d.ts +64 -0
- package/es/runtime/store-registry.d.ts.map +1 -0
- package/es/runtime/store-registry.js +102 -0
- package/es/runtime/store-registry.js.map +1 -0
- package/es/runtime/store-runtime.d.ts +46 -0
- package/es/runtime/store-runtime.d.ts.map +1 -0
- package/es/runtime/store-runtime.js +58 -0
- package/es/runtime/store-runtime.js.map +1 -0
- package/es/types.d.ts +167 -0
- package/es/types.d.ts.map +1 -0
- package/es/types.js +10 -0
- package/esm/composables/defineSetupStore.d.ts +120 -0
- package/esm/composables/defineSetupStore.d.ts.map +1 -0
- package/esm/composables/defineSetupStore.js +29 -0
- package/esm/composables/defineSetupStore.js.map +1 -0
- package/esm/composables/index.d.ts +24 -0
- package/esm/composables/index.d.ts.map +1 -0
- package/esm/composables/index.js +21 -0
- package/esm/composables/useFormStore.d.ts +131 -0
- package/esm/composables/useFormStore.d.ts.map +1 -0
- package/esm/composables/useFormStore.js +189 -0
- package/esm/composables/useFormStore.js.map +1 -0
- package/esm/composables/useOptimistic.d.ts +67 -0
- package/esm/composables/useOptimistic.d.ts.map +1 -0
- package/esm/composables/useOptimistic.js +64 -0
- package/esm/composables/useOptimistic.js.map +1 -0
- package/esm/composables/usePersist.d.ts +68 -0
- package/esm/composables/usePersist.d.ts.map +1 -0
- package/esm/composables/usePersist.js +96 -0
- package/esm/composables/usePersist.js.map +1 -0
- package/esm/composables/usePersistedState.d.ts +59 -0
- package/esm/composables/usePersistedState.d.ts.map +1 -0
- package/esm/composables/usePersistedState.js +121 -0
- package/esm/composables/usePersistedState.js.map +1 -0
- package/esm/composables/useSharedState.d.ts +62 -0
- package/esm/composables/useSharedState.d.ts.map +1 -0
- package/esm/composables/useSharedState.js +94 -0
- package/esm/composables/useSharedState.js.map +1 -0
- package/esm/composables/useStore.d.ts +99 -0
- package/esm/composables/useStore.d.ts.map +1 -0
- package/esm/composables/useStore.js +61 -0
- package/esm/composables/useStore.js.map +1 -0
- package/esm/composables/useStoreDevtools.d.ts +31 -0
- package/esm/composables/useStoreDevtools.d.ts.map +1 -0
- package/esm/composables/useStoreDevtools.js +112 -0
- package/esm/composables/useStoreDevtools.js.map +1 -0
- package/esm/composables/useStoreSnapshot.d.ts +122 -0
- package/esm/composables/useStoreSnapshot.d.ts.map +1 -0
- package/esm/composables/useStoreSnapshot.js +209 -0
- package/esm/composables/useStoreSnapshot.js.map +1 -0
- package/esm/composables/useSubscribe.d.ts +90 -0
- package/esm/composables/useSubscribe.d.ts.map +1 -0
- package/esm/composables/useSubscribe.js +53 -0
- package/esm/composables/useSubscribe.js.map +1 -0
- package/esm/context/injection-keys.d.ts +8 -0
- package/esm/context/injection-keys.d.ts.map +1 -0
- package/esm/context/injection-keys.js +17 -0
- package/esm/context/injection-keys.js.map +1 -0
- package/esm/index.d.ts +24 -0
- package/esm/index.d.ts.map +1 -0
- package/esm/index.js +34 -0
- package/esm/index.js.map +1 -0
- package/esm/plugins/engine-plugin.d.ts +36 -0
- package/esm/plugins/engine-plugin.d.ts.map +1 -0
- package/esm/plugins/engine-plugin.js +83 -0
- package/esm/plugins/engine-plugin.js.map +1 -0
- package/esm/plugins/enhanced-persist-plugin.d.ts +3 -0
- package/esm/plugins/enhanced-persist-plugin.d.ts.map +1 -0
- package/esm/plugins/enhanced-persist-plugin.js +12 -0
- package/esm/plugins/index.d.ts +7 -0
- package/esm/plugins/index.d.ts.map +1 -0
- package/esm/plugins/index.js +16 -0
- package/esm/plugins/pinia-plugin.d.ts +68 -0
- package/esm/plugins/pinia-plugin.d.ts.map +1 -0
- package/esm/plugins/pinia-plugin.js +172 -0
- package/esm/plugins/pinia-plugin.js.map +1 -0
- package/esm/plugins/registry-plugin.d.ts +2 -0
- package/esm/plugins/registry-plugin.d.ts.map +1 -0
- package/esm/plugins/registry-plugin.js +12 -0
- package/esm/plugins/vue-plugin.d.ts +10 -0
- package/esm/plugins/vue-plugin.d.ts.map +1 -0
- package/esm/plugins/vue-plugin.js +24 -0
- package/esm/plugins/vue-plugin.js.map +1 -0
- package/esm/runtime/install-store-app.d.ts +23 -0
- package/esm/runtime/install-store-app.d.ts.map +1 -0
- package/esm/runtime/install-store-app.js +54 -0
- package/esm/runtime/install-store-app.js.map +1 -0
- package/esm/runtime/store-plugin-options.d.ts +40 -0
- package/esm/runtime/store-plugin-options.d.ts.map +1 -0
- package/esm/runtime/store-plugin-options.js +24 -0
- package/esm/runtime/store-plugin-options.js.map +1 -0
- package/esm/runtime/store-registry.d.ts +64 -0
- package/esm/runtime/store-registry.d.ts.map +1 -0
- package/esm/runtime/store-registry.js +94 -0
- package/esm/runtime/store-registry.js.map +1 -0
- package/esm/runtime/store-runtime.d.ts +46 -0
- package/esm/runtime/store-runtime.d.ts.map +1 -0
- package/esm/runtime/store-runtime.js +58 -0
- package/esm/runtime/store-runtime.js.map +1 -0
- package/esm/types.d.ts +167 -0
- package/esm/types.d.ts.map +1 -0
- package/esm/types.js +10 -0
- package/lib/composables/defineSetupStore.cjs +33 -0
- package/lib/composables/defineSetupStore.cjs.map +1 -0
- package/lib/composables/defineSetupStore.d.ts +120 -0
- package/lib/composables/index.cjs +46 -0
- package/lib/composables/index.d.ts +24 -0
- package/lib/composables/useFormStore.cjs +197 -0
- package/lib/composables/useFormStore.cjs.map +1 -0
- package/lib/composables/useFormStore.d.ts +131 -0
- package/lib/composables/useOptimistic.cjs +66 -0
- package/lib/composables/useOptimistic.cjs.map +1 -0
- package/lib/composables/useOptimistic.d.ts +67 -0
- package/lib/composables/usePersist.cjs +100 -0
- package/lib/composables/usePersist.cjs.map +1 -0
- package/lib/composables/usePersist.d.ts +68 -0
- package/lib/composables/usePersistedState.cjs +123 -0
- package/lib/composables/usePersistedState.cjs.map +1 -0
- package/lib/composables/usePersistedState.d.ts +59 -0
- package/lib/composables/useSharedState.cjs +96 -0
- package/lib/composables/useSharedState.cjs.map +1 -0
- package/lib/composables/useSharedState.d.ts +62 -0
- package/lib/composables/useStore.cjs +65 -0
- package/lib/composables/useStore.cjs.map +1 -0
- package/lib/composables/useStore.d.ts +99 -0
- package/lib/composables/useStoreDevtools.cjs +114 -0
- package/lib/composables/useStoreDevtools.cjs.map +1 -0
- package/lib/composables/useStoreDevtools.d.ts +31 -0
- package/lib/composables/useStoreSnapshot.cjs +211 -0
- package/lib/composables/useStoreSnapshot.cjs.map +1 -0
- package/lib/composables/useStoreSnapshot.d.ts +122 -0
- package/lib/composables/useSubscribe.cjs +57 -0
- package/lib/composables/useSubscribe.cjs.map +1 -0
- package/lib/composables/useSubscribe.d.ts +90 -0
- package/lib/context/injection-keys.cjs +21 -0
- package/lib/context/injection-keys.cjs.map +1 -0
- package/lib/context/injection-keys.d.ts +8 -0
- package/lib/index.cjs +235 -0
- package/lib/index.cjs.map +1 -0
- package/lib/index.d.ts +24 -0
- package/lib/package.json +3 -0
- package/lib/plugins/engine-plugin.cjs +90 -0
- package/lib/plugins/engine-plugin.cjs.map +1 -0
- package/lib/plugins/engine-plugin.d.ts +36 -0
- package/lib/plugins/enhanced-persist-plugin.cjs +15 -0
- package/lib/plugins/enhanced-persist-plugin.d.ts +3 -0
- package/lib/plugins/index.cjs +28 -0
- package/lib/plugins/index.d.ts +7 -0
- package/lib/plugins/pinia-plugin.cjs +177 -0
- package/lib/plugins/pinia-plugin.cjs.map +1 -0
- package/lib/plugins/pinia-plugin.d.ts +68 -0
- package/lib/plugins/registry-plugin.cjs +18 -0
- package/lib/plugins/registry-plugin.d.ts +2 -0
- package/lib/plugins/vue-plugin.cjs +26 -0
- package/lib/plugins/vue-plugin.cjs.map +1 -0
- package/lib/plugins/vue-plugin.d.ts +10 -0
- package/lib/runtime/install-store-app.cjs +57 -0
- package/lib/runtime/install-store-app.cjs.map +1 -0
- package/lib/runtime/install-store-app.d.ts +23 -0
- package/lib/runtime/store-plugin-options.cjs +26 -0
- package/lib/runtime/store-plugin-options.cjs.map +1 -0
- package/lib/runtime/store-plugin-options.d.ts +40 -0
- package/lib/runtime/store-registry.cjs +108 -0
- package/lib/runtime/store-registry.cjs.map +1 -0
- package/lib/runtime/store-registry.d.ts +64 -0
- package/lib/runtime/store-runtime.cjs +62 -0
- package/lib/runtime/store-runtime.cjs.map +1 -0
- package/lib/runtime/store-runtime.d.ts +46 -0
- package/lib/types.cjs +12 -0
- package/lib/types.d.ts +167 -0
- package/package.json +115 -0
package/README.md
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
# @composy/store-vue
|
|
2
|
+
|
|
3
|
+
`@composy/store-vue` 是 `packages/store` 的 Vue 3 适配层。
|
|
4
|
+
|
|
5
|
+
它保留现有定位不变:
|
|
6
|
+
|
|
7
|
+
- 基于 Pinia 提供 Vue 侧接入能力
|
|
8
|
+
- 提供一组围绕 Store 的 composables
|
|
9
|
+
- 提供持久化、注册表和调试相关插件能力
|
|
10
|
+
- 同时支持原生 Vue Plugin 用法和 `@composy/engine-core` plugin 用法
|
|
11
|
+
|
|
12
|
+
## 目录结构
|
|
13
|
+
|
|
14
|
+
```text
|
|
15
|
+
src/
|
|
16
|
+
├─ composables/ # Vue 侧组合式 API
|
|
17
|
+
├─ context/ # 注入 key
|
|
18
|
+
├─ plugins/ # 对外公开的插件入口与兼容导出
|
|
19
|
+
├─ runtime/ # 运行时、注册表、安装链
|
|
20
|
+
├─ index.ts # 包入口
|
|
21
|
+
└─ types.ts # Vue 侧公开类型
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
当前实现中,真正的安装与生命周期逻辑已经收敛到 `runtime/`:
|
|
25
|
+
|
|
26
|
+
- `runtime/store-plugin-options.ts`
|
|
27
|
+
- 统一运行时配置和默认值
|
|
28
|
+
- `runtime/store-registry.ts`
|
|
29
|
+
- 统一 Store 注册、查询、批量重置和运行时 API
|
|
30
|
+
- `runtime/store-runtime.ts`
|
|
31
|
+
- 统一创建 Pinia、注册 registry、挂接 persist plugin
|
|
32
|
+
- `runtime/install-store-app.ts`
|
|
33
|
+
- 统一把 runtime 安装到 Vue app,并处理 `provide`、`globalProperties` 和卸载清理
|
|
34
|
+
|
|
35
|
+
`plugins/` 只保留明确职责的公开入口:
|
|
36
|
+
|
|
37
|
+
- `vue-plugin.ts`
|
|
38
|
+
- 原生 Vue Plugin 入口
|
|
39
|
+
- `engine-plugin.ts`
|
|
40
|
+
- `@composy/engine-core` plugin 入口,内部委托 `@composy/store-core/engine` 的 `createStoreEngineBridge()`
|
|
41
|
+
- `pinia-plugin.ts`
|
|
42
|
+
- 持久化插件与控制器
|
|
43
|
+
- `registry-plugin.ts`
|
|
44
|
+
- registry 能力导出
|
|
45
|
+
- `enhanced-persist-plugin.ts`
|
|
46
|
+
- 旧子路径兼容导出
|
|
47
|
+
|
|
48
|
+
## 推荐用法
|
|
49
|
+
|
|
50
|
+
### 原生 Vue Plugin
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
import {
|
|
54
|
+
createStoreVuePlugin,
|
|
55
|
+
defineStore,
|
|
56
|
+
} from '@composy/store-vue'
|
|
57
|
+
import { createApp } from 'vue'
|
|
58
|
+
import App from './App.vue'
|
|
59
|
+
|
|
60
|
+
const app = createApp(App)
|
|
61
|
+
|
|
62
|
+
app.use(createStoreVuePlugin({
|
|
63
|
+
persist: true,
|
|
64
|
+
persistOptions: {
|
|
65
|
+
keyPrefix: 'demo:',
|
|
66
|
+
syncTabs: true,
|
|
67
|
+
},
|
|
68
|
+
}))
|
|
69
|
+
|
|
70
|
+
app.mount('#app')
|
|
71
|
+
|
|
72
|
+
export const useCounterStore = defineStore('counter', {
|
|
73
|
+
state: () => ({
|
|
74
|
+
count: 0,
|
|
75
|
+
}),
|
|
76
|
+
})
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### `@composy/engine-core` Plugin
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
import { createStoreEnginePlugin } from '@composy/store-vue'
|
|
83
|
+
|
|
84
|
+
export const storePlugin = createStoreEnginePlugin({
|
|
85
|
+
name: 'store',
|
|
86
|
+
version: '1.0.0',
|
|
87
|
+
persist: true,
|
|
88
|
+
provide: true,
|
|
89
|
+
globalProperties: true,
|
|
90
|
+
})
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
设计要点:
|
|
94
|
+
|
|
95
|
+
- 如果 engine 已拿到 Vue app,插件会直接复用同一条 runtime 安装链。
|
|
96
|
+
- 如果 app 还没创建,插件会先准备 runtime,再在 `app:created` 时接入。
|
|
97
|
+
- 如果外部 app 已安装过 store runtime,engine plugin 会复用已有 runtime,而不是重复创建第二套 Pinia/registry。
|
|
98
|
+
- engine state/API/container/events 的同步逻辑由 core bridge 统一处理,Vue 包只传入 `createStoreRuntime()`、`installStoreRuntime()` 和 Vue App 识别函数。
|
|
99
|
+
|
|
100
|
+
## 持久化能力
|
|
101
|
+
|
|
102
|
+
`createPersistPlugin()` 和 `createEnhancedPersistPlugin()` 现在共享同一套实现,统一支持:
|
|
103
|
+
|
|
104
|
+
- `paths`
|
|
105
|
+
- `excludePaths`
|
|
106
|
+
- `debounce`
|
|
107
|
+
- `syncTabs`
|
|
108
|
+
- `ttl`
|
|
109
|
+
- `serializer.serialize`
|
|
110
|
+
- `serializer.deserialize`
|
|
111
|
+
|
|
112
|
+
示例:
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
import { defineStore } from 'pinia'
|
|
116
|
+
|
|
117
|
+
export const useUserStore = defineStore('user', {
|
|
118
|
+
state: () => ({
|
|
119
|
+
profile: null,
|
|
120
|
+
token: '',
|
|
121
|
+
session: {
|
|
122
|
+
lastSeenAt: 0,
|
|
123
|
+
},
|
|
124
|
+
}),
|
|
125
|
+
persist: {
|
|
126
|
+
paths: ['profile', 'token'],
|
|
127
|
+
excludePaths: ['session.lastSeenAt'],
|
|
128
|
+
syncTabs: true,
|
|
129
|
+
ttl: 1000 * 60 * 60 * 24,
|
|
130
|
+
},
|
|
131
|
+
})
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## 本轮整理结果
|
|
135
|
+
|
|
136
|
+
- 原生 Vue Plugin 和 engine plugin 已统一复用同一条 runtime/install 链
|
|
137
|
+
- engine plugin 已收口为 core bridge 的 Vue 薄封装,不再复制 engine state/API 生命周期逻辑
|
|
138
|
+
- registry、persist、Pinia 安装和 app 卸载清理都集中在 `runtime/`
|
|
139
|
+
- `plugins/` 目录不再承载重复 runtime 逻辑,只保留公开入口和兼容层
|
|
140
|
+
- `useFormStore`、`useStoreDevtools`、`usePersistedState` 等 composable 的实现更清晰,避免继续堆叠历史写法
|
|
141
|
+
- 持久化、Store registry 的 `$dispose` 补丁逻辑已支持重复挂载/运行时重建场景,避免残留旧清理回调
|
|
142
|
+
|
|
143
|
+
## 开发校验
|
|
144
|
+
|
|
145
|
+
当前包建议优先使用:
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
pnpm -C packages/store/packages/vue run lint:check
|
|
149
|
+
pnpm -C packages/store/packages/vue run type-check
|
|
150
|
+
pnpm -C packages/store/packages/vue run test:run
|
|
151
|
+
pnpm -C packages/store/packages/vue run build
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
完整构建后必须同时存在 `dist`、`es`、`esm`、`lib` 四类产物目录。
|