@thzero/library_client_vue3_store_pinia 0.16.19 → 0.16.21
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 +4 -4
- package/service/store/index.js +26 -2
- package/store/index.js +80 -8
- package/store/user/index.js +39 -29
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thzero/library_client_vue3_store_pinia",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.21",
|
|
4
4
|
"version_major": 0,
|
|
5
5
|
"version_minor": 16,
|
|
6
|
-
"version_patch":
|
|
7
|
-
"version_date": "12/
|
|
6
|
+
"version_patch": 21,
|
|
7
|
+
"version_date": "12/19/2022",
|
|
8
8
|
"description": "An opinionated library for vue3 with pinia store for the library_client_vue3 using the https://prazdevs.github.io/pinia-plugin-persistedstate library.",
|
|
9
9
|
"author": "thZero",
|
|
10
10
|
"license": "MIT",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"@thzero/library_common": "^0.16",
|
|
26
26
|
"pinia": "^2.0.28",
|
|
27
27
|
"pinia-plugin-persistedstate": "^3.0.1",
|
|
28
|
-
"pinia-plugin-persistedstate-2": "^2.0.
|
|
28
|
+
"pinia-plugin-persistedstate-2": "^2.0.6",
|
|
29
29
|
"vue": "^3.2.45"
|
|
30
30
|
}
|
|
31
31
|
}
|
package/service/store/index.js
CHANGED
|
@@ -8,7 +8,7 @@ class PiniaStoreService extends Service {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
get getters() {
|
|
11
|
-
return GlobalUtility.$store;
|
|
11
|
+
return GlobalUtility.$store.getters;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
get state() {
|
|
@@ -16,7 +16,31 @@ class PiniaStoreService extends Service {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
get user() {
|
|
19
|
-
return GlobalUtility.$store.user;
|
|
19
|
+
return GlobalUtility.$store.user.user;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
get userClaims() {
|
|
23
|
+
return GlobalUtility.$store.user.claims;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
get userToken() {
|
|
27
|
+
return GlobalUtility.$store.user.token;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
get userAuthCompleted() {
|
|
31
|
+
return GlobalUtility.$store.user.authCompleted;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
get userAuthIsLoggedIn() {
|
|
35
|
+
return GlobalUtility.$store.user.isLoggedIn;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
get userTheme() {
|
|
39
|
+
return GlobalUtility.$store.user.theme;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
get userTokenResult() {
|
|
43
|
+
return GlobalUtility.$store.user.tokenResult;
|
|
20
44
|
}
|
|
21
45
|
}
|
|
22
46
|
|
package/store/index.js
CHANGED
|
@@ -25,11 +25,24 @@ class BaseStore {
|
|
|
25
25
|
|
|
26
26
|
setup() {
|
|
27
27
|
const logger = GlobalUtility.$injector.getService(LibraryConstants.InjectorKeys.SERVICE_LOGGER);
|
|
28
|
+
|
|
29
|
+
const initialStoreConfig = this._initStoreConfigBase();
|
|
30
|
+
const appStoreConfig = this._initStoreConfig();
|
|
31
|
+
initialStoreConfig.actions = Object.assign(initialStoreConfig.actions, appStoreConfig.actions);
|
|
32
|
+
initialStoreConfig.dispatcher = Object.assign(initialStoreConfig.dispatcher, appStoreConfig.dispatcher);
|
|
33
|
+
initialStoreConfig.getters = Object.assign(initialStoreConfig.getters, appStoreConfig.getters);
|
|
34
|
+
|
|
35
|
+
const initialState = initialStoreConfig.state();
|
|
36
|
+
const appState = appStoreConfig.state();
|
|
37
|
+
const state = Object.assign(initialState, appState);
|
|
38
|
+
initialStoreConfig.state = () => state;
|
|
39
|
+
|
|
28
40
|
return {
|
|
29
41
|
func: {
|
|
30
42
|
install(app, options) {
|
|
31
43
|
const storeConfig = options.storeConfig;
|
|
32
44
|
|
|
45
|
+
options.actionGetters = storeConfig.getters;
|
|
33
46
|
options.actionDispatcher = storeConfig.dispatcher;
|
|
34
47
|
if (!options.actionDispatcher)
|
|
35
48
|
options.actionDispatcher = {};
|
|
@@ -43,14 +56,16 @@ class BaseStore {
|
|
|
43
56
|
|
|
44
57
|
// options.addModule('adminNews', adminNews, options.actionDispatcher, options.pluginPersistType(), options.pluginPersistConfig, options.pinia, logger);
|
|
45
58
|
// options.addModule('adminUsers', adminUsers, options.actionDispatcher, options.pluginPersistType(), options.pluginPersistConfig, options.pinia, logger);
|
|
46
|
-
options.addModule('news', news, options.actionDispatcher, options.pluginPersistType(), options.pluginPersistSetup, options.pluginPersistConfig, options.pluginPersistSetupOverride, options.pinia, logger);
|
|
47
|
-
options.addModule('user', user, options.actionDispatcher, options.pluginPersistType(), options.pluginPersistSetup, options.pluginPersistConfig, options.pluginPersistSetupOverride, options.pinia, logger);
|
|
59
|
+
options.addModule('news', news, options.actionDispatcher, options.actionGetters, options.pluginPersistType(), options.pluginPersistSetup, options.pluginPersistConfig, options.pluginPersistSetupOverride, options.pinia, logger);
|
|
60
|
+
options.addModule('user', user, options.actionDispatcher, options.actionGetters, options.pluginPersistType(), options.pluginPersistSetup, options.pluginPersistConfig, options.pluginPersistSetupOverride, options.pinia, logger);
|
|
48
61
|
options.initModules();
|
|
49
62
|
GlobalUtility.$store.dispatcher = options.actionDispatcher;
|
|
63
|
+
GlobalUtility.$store.getters = options.actionGetters;
|
|
50
64
|
}
|
|
51
65
|
},
|
|
52
66
|
options: {
|
|
53
67
|
actionDispatcher: this.actionDispatcher,
|
|
68
|
+
actionGetters: this.actionGetters,
|
|
54
69
|
addModule: this._addModule,
|
|
55
70
|
initModules: this._initModules,
|
|
56
71
|
logger: logger,
|
|
@@ -59,25 +74,23 @@ class BaseStore {
|
|
|
59
74
|
pluginPersistSetupOverride: this._initPluginPersistConfigSetupOverride,
|
|
60
75
|
pluginPersistSetup: this._initPluginPersistConfigSetup,
|
|
61
76
|
pluginPersistType: this._initPluginPersistType,
|
|
62
|
-
storeConfig:
|
|
77
|
+
storeConfig: initialStoreConfig
|
|
63
78
|
}
|
|
64
79
|
};
|
|
65
80
|
}
|
|
66
81
|
|
|
67
|
-
_addModule(key, storeConfig, actionDispatcher, pluginPersistType, pluginPersistSetup, pluginPersistConfig, pluginPersistSetupOverride, pinia, logger) {
|
|
82
|
+
_addModule(key, storeConfig, actionDispatcher, actionGetters, pluginPersistType, pluginPersistSetup, pluginPersistConfig, pluginPersistSetupOverride, pinia, logger) {
|
|
68
83
|
if (pluginPersistType && pluginPersistSetup && pluginPersistConfig && pluginPersistConfig[key])
|
|
69
84
|
pluginPersistSetup(pluginPersistType, storeConfig, pluginPersistConfig['root'], pluginPersistSetupOverride);
|
|
70
85
|
actionDispatcher[key] = storeConfig.dispatcher;
|
|
71
86
|
delete storeConfig.dispatcher;
|
|
87
|
+
actionGetters[key] = storeConfig.getters;
|
|
88
|
+
delete storeConfig.getters;
|
|
72
89
|
const storeFunc = defineStore(key, storeConfig);
|
|
73
90
|
GlobalUtility.$store[key] = storeFunc(pinia);
|
|
74
91
|
GlobalUtility.$store[key].$logger = logger;
|
|
75
92
|
}
|
|
76
93
|
|
|
77
|
-
_init() {
|
|
78
|
-
throw new NotImplementedError();
|
|
79
|
-
}
|
|
80
|
-
|
|
81
94
|
_initModules() {
|
|
82
95
|
throw new NotImplementedError();
|
|
83
96
|
}
|
|
@@ -137,6 +150,65 @@ class BaseStore {
|
|
|
137
150
|
_initPluginPersistConfigSetupOverride(storeConfig, persistConfig) {
|
|
138
151
|
}
|
|
139
152
|
|
|
153
|
+
_initStoreConfig() {
|
|
154
|
+
throw new NotImplementedError();
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
_initStoreConfigBase() {
|
|
158
|
+
return {
|
|
159
|
+
state: () => ({
|
|
160
|
+
checksumLastUpdate: [],
|
|
161
|
+
plans: [],
|
|
162
|
+
version: null
|
|
163
|
+
}),
|
|
164
|
+
actions: {
|
|
165
|
+
async getPlans(correlationId) {
|
|
166
|
+
const service = GlobalUtility.$injector.getService(LibraryConstants.InjectorKeys.SERVICE_PLANS);
|
|
167
|
+
const response = await service.plans(correlationId);
|
|
168
|
+
this.$logger.debug('store', 'getPlans', 'response', response, correlationId);
|
|
169
|
+
if (Response.hasSucceeded(response)) {
|
|
170
|
+
this.setPlans(correlationId, response.results ? response.results.data : []);
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
async requestVersion(correlationId) {
|
|
174
|
+
const service = GlobalUtility.$injector.getService(LibraryConstants.InjectorKeys.SERVICE_VERSION);
|
|
175
|
+
const version = await service.version(correlationId);
|
|
176
|
+
this.setVersion(correlationId, version);
|
|
177
|
+
},
|
|
178
|
+
async setPlans(correlationId, plans) {
|
|
179
|
+
this.$logger.debug('store', 'setPlans', 'plans.a', plans, correlationId);
|
|
180
|
+
this.$logger.debug('store', 'setPlans', 'plans.b', this.plans, correlationId);
|
|
181
|
+
this.plans = plans;
|
|
182
|
+
this.$logger.debug('store', 'setPlans', 'plans.c', this.plans, correlationId);
|
|
183
|
+
},
|
|
184
|
+
async setVersion(correlationId, version) {
|
|
185
|
+
// this.$logger.debug('store', 'getVersion', 'version', version, correlationId);
|
|
186
|
+
// commit('setVersion', { correlationId: correlationId, version: version });
|
|
187
|
+
this.$logger.debug('store', 'setVersion', 'version', version, correlationId);
|
|
188
|
+
this.version = version;
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
getters: {
|
|
192
|
+
getPlan (correlationId, id) {
|
|
193
|
+
if (GlobalUtility.$store.plans == null)
|
|
194
|
+
return null;
|
|
195
|
+
return GlobalUtility.$store.plans.find(plan => plan.id === id);
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
dispatcher: {
|
|
199
|
+
async getPlans(correlationId) {
|
|
200
|
+
await GlobalUtility.$store.getPlans(correlationId);
|
|
201
|
+
},
|
|
202
|
+
async requestVersion(correlationId) {
|
|
203
|
+
await GlobalUtility.$store.requestVersion(correlationId);
|
|
204
|
+
},
|
|
205
|
+
async initialize(correlationId) {
|
|
206
|
+
await GlobalUtility.$store.initialize(correlationId);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
|
|
140
212
|
static PersistanceTypeOverride = 'override';
|
|
141
213
|
static PersistanceTypePersist = 'persist';
|
|
142
214
|
static PersistanceTypePersist2 = 'persist2';
|
package/store/user/index.js
CHANGED
|
@@ -10,6 +10,7 @@ const store = {
|
|
|
10
10
|
authCompleted: false,
|
|
11
11
|
claims: null,
|
|
12
12
|
isLoggedIn: false,
|
|
13
|
+
theme: 'defaultTheme',
|
|
13
14
|
token: null,
|
|
14
15
|
tokenResult: null,
|
|
15
16
|
user: null
|
|
@@ -41,27 +42,26 @@ const store = {
|
|
|
41
42
|
async setUserLoggedIn(correlationId, isLoggedIn) {
|
|
42
43
|
this.isLoggedIn = isLoggedIn;
|
|
43
44
|
},
|
|
45
|
+
// async setUserSettings(correlationId, settings) {
|
|
46
|
+
// const service = GlobalUtility.$injector.getService(LibraryConstants.InjectorKeys.SERVICE_USER);
|
|
47
|
+
// settings = VueUtility.settings().mergeUser(correlationId, settings);
|
|
48
|
+
// const response = await service.updateSettings(correlationId, this.user, settings);
|
|
49
|
+
// this.$logger.debug('store.user', 'setUserSettings', 'response', response);
|
|
50
|
+
// if (Response.hasSucceeded(response) && response.results)
|
|
51
|
+
// this.setUser(correlationId, response.results);
|
|
52
|
+
// return response;
|
|
53
|
+
// },
|
|
44
54
|
async setUserSettings(correlationId, settings) {
|
|
45
55
|
const service = GlobalUtility.$injector.getService(LibraryConstants.InjectorKeys.SERVICE_USER);
|
|
46
|
-
settings = VueUtility.settings().mergeUser(
|
|
47
|
-
const response = await service.updateSettings(
|
|
56
|
+
settings = VueUtility.settings().mergeUser(correlationId, settings);
|
|
57
|
+
const response = await service.updateSettings(correlationId, this.user, settings);
|
|
48
58
|
this.$logger.debug('store.user', 'setUserSettings', 'response', response);
|
|
49
59
|
if (Response.hasSucceeded(response) && response.results)
|
|
50
|
-
this.
|
|
60
|
+
this.user = response.results;
|
|
51
61
|
return response;
|
|
52
62
|
},
|
|
53
|
-
async
|
|
54
|
-
|
|
55
|
-
settings = VueUtility.settings().mergeUser(params.correlationId, settings);
|
|
56
|
-
const response = await service.updateSettings(params.correlationId, this.user, settings);
|
|
57
|
-
this.$logger.debug('store.user', 'setUserSettings', 'response', response);
|
|
58
|
-
if (Response.hasSucceeded(response) && response.results) {
|
|
59
|
-
// commit('setUserSettings', { correlationId: params.correlationId, user: response.results });
|
|
60
|
-
const user = response.results;
|
|
61
|
-
user.settings = VueUtility.settings().mergeUser(correlationId, user.settings);
|
|
62
|
-
this.user = user;
|
|
63
|
-
}
|
|
64
|
-
return response;
|
|
63
|
+
async setUserTheme(correlationId, isLoggedIn) {
|
|
64
|
+
this.theme = theme;
|
|
65
65
|
},
|
|
66
66
|
async setUserTokenResult(correlationId, tokenResult) {
|
|
67
67
|
this.$patch({
|
|
@@ -75,37 +75,47 @@ const store = {
|
|
|
75
75
|
this.user = user;
|
|
76
76
|
}
|
|
77
77
|
},
|
|
78
|
+
getters: {
|
|
79
|
+
getUser (correlationId) {
|
|
80
|
+
return GlobalUtility.$store.user.user;
|
|
81
|
+
},
|
|
82
|
+
getUserTheme (correlationId) {
|
|
83
|
+
return GlobalUtility.$store.theme;
|
|
84
|
+
},
|
|
85
|
+
getUserSettings(correlationId) {
|
|
86
|
+
if (GlobalUtility.$store.user.user && GlobalUtility.$store.user.user.settings)
|
|
87
|
+
return GlobalUtility.$store.user.user.settings;
|
|
88
|
+
|
|
89
|
+
const service = GlobalUtility.$injector.getService(LibraryConstants.InjectorKeys.SERVICE_USER);
|
|
90
|
+
return service.initializeSettings();
|
|
91
|
+
}
|
|
92
|
+
},
|
|
78
93
|
dispatcher: {
|
|
79
94
|
async refreshUserSettings(correlationId) {
|
|
80
|
-
|
|
81
|
-
await GlobalUtility.$store.user.refreshUserSettings(correlationId);
|
|
95
|
+
return await GlobalUtility.$store.user.refreshUserSettings(correlationId);
|
|
82
96
|
},
|
|
83
97
|
async resetUser(correlationId) {
|
|
84
|
-
// await GlobalUtility.$store.dispatch('resetUser', correlationId);
|
|
85
98
|
await GlobalUtility.$store.user.resetUser(correlationId);
|
|
86
99
|
},
|
|
87
|
-
async
|
|
88
|
-
// await GlobalUtility.$store.dispatch('setUserAuthCompleted', { correlationId: correlationId, authCompleted: authCompleted });
|
|
100
|
+
async setUserAuthCompleted(correlationId, authCompleted) {
|
|
89
101
|
await GlobalUtility.$store.user.setUserAuthCompleted(correlationId, authCompleted);
|
|
90
102
|
},
|
|
91
|
-
async
|
|
92
|
-
// await GlobalUtility.$store.dispatch('setUserClaims', { correlationId: correlationId, authCompleted: claims });
|
|
103
|
+
async setUserClaims(correlationId, claims) {
|
|
93
104
|
await GlobalUtility.$store.user.setUserClaims(correlationId, claims);
|
|
94
105
|
},
|
|
95
|
-
async
|
|
96
|
-
// await GlobalUtility.$store.dispatch('setUserLoggedIn', { correlationId: correlationId, isLoggedIn: isLoggedIn });
|
|
106
|
+
async setUserLoggedIn(correlationId, isLoggedIn) {
|
|
97
107
|
await GlobalUtility.$store.user.setUserLoggedIn(correlationId, isLoggedIn);
|
|
98
108
|
},
|
|
99
109
|
async setUserSettings(correlationId, settings) {
|
|
100
|
-
|
|
101
|
-
|
|
110
|
+
return await GlobalUtility.$store.user.setUserSettings(correlationId, settings);
|
|
111
|
+
},
|
|
112
|
+
async setUserTheme(correlationId, theme) {
|
|
113
|
+
await GlobalUtility.$store.user.setUserTheme(correlationId, theme);
|
|
102
114
|
},
|
|
103
|
-
async
|
|
104
|
-
// await GlobalUtility.$store.dispatch('setUserTokenResult', { correlationId: correlationId, tokenResult: tokenResult });
|
|
115
|
+
async setUserTokenResult(correlationId, tokenResult) {
|
|
105
116
|
await GlobalUtility.$store.user.setUserTokenResult(correlationId, tokenResult);
|
|
106
117
|
},
|
|
107
118
|
async setUser(correlationId, user) {
|
|
108
|
-
// await GlobalUtility.$store.dispatch('setUser', { correlationId: correlationId, user: user });
|
|
109
119
|
await GlobalUtility.$store.user.setUser(correlationId, user);
|
|
110
120
|
}
|
|
111
121
|
}
|