@thzero/library_client_vue3_store_pinia 0.18.34 → 0.18.35

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/store/index.js CHANGED
@@ -1,316 +1,323 @@
1
- import { createPinia, defineStore } from 'pinia';
2
- import piniaPluginPersistedState from 'pinia-plugin-persistedstate';
3
- import { createPersistedStatePlugin } from 'pinia-plugin-persistedstate-2';
4
-
5
- import LibraryClientConstants from '@thzero/library_client/constants';
6
-
7
- import LibraryClientUtility from '@thzero/library_client/utility/index';
8
- import LibraryCommonUtility from '@thzero/library_common/utility/index';
9
-
10
- import Response from '@thzero/library_common/response';
11
-
12
- import NotImplementedError from '@thzero/library_common/errors/notImplemented';
13
-
14
- // import adminNews from './admin/news/pinia';
15
- // import adminUsers from './admin/users/pinia';
16
-
17
- import news from './news';
18
- import user from './user';
19
-
20
- class BaseStore {
21
- async initialize() {
22
- this.pinia = createPinia();
23
-
24
- this._initPluginPersist();
25
-
26
- return this.pinia;
27
- }
28
-
29
- setup() {
30
- // const logger = LibraryClientUtility.$injector.getService(LibraryClientConstants.InjectorKeys.SERVICE_LOGGER);
31
-
32
- const initialStoreConfig = this._initStoreConfigBase();
33
- const appStoreConfig = this._initStoreConfig();
34
- initialStoreConfig.actions = Object.assign(initialStoreConfig.actions, appStoreConfig.actions);
35
- initialStoreConfig.dispatcher = Object.assign(initialStoreConfig.dispatcher, appStoreConfig.dispatcher);
36
- initialStoreConfig.getters = Object.assign(initialStoreConfig.getters, appStoreConfig.getters);
37
-
38
- const initialState = initialStoreConfig.state();
39
- const appState = appStoreConfig.state();
40
- const state = Object.assign(initialState, appState);
41
- initialStoreConfig.state = () => state;
42
-
43
- return {
44
- func: {
45
- install(app, options) {
46
- const storeConfig = options.storeConfig;
47
-
48
- options.actionGetters = storeConfig.getters;
49
- options.actionDispatcher = storeConfig.dispatcher;
50
- if (!options.actionDispatcher)
51
- options.actionDispatcher = {};
52
-
53
- const pluginPersistType = options.pluginPersistType();
54
- const additionalPaths = storeConfig.pluginPersistPaths ? storeConfig.pluginPersistPaths[pluginPersistType] : null;
55
-
56
- if (options.pluginPersistSetup && options.pluginPersistType && options.pluginPersistConfig && options.pluginPersistConfig && options.pluginPersistConfig[pluginPersistType])
57
- options.pluginPersistSetup(pluginPersistType, storeConfig, options.pluginPersistConfig[pluginPersistType], options.pluginPersistSetupOverride, {
58
- additionalPaths: additionalPaths
59
- });
60
-
61
- // if (storeConfig.pluginPersistPaths && storeConfig.pluginPersistPaths[pluginPersistType])
62
- // storeConfig[pluginPersistType].paths = [ ...storeConfig[pluginPersistType].paths, ...storeConfig.pluginPersistPaths[pluginPersistType] ];
63
- delete storeConfig.pluginPersistPaths;
64
-
65
- const storeFunc = defineStore('main', storeConfig);
66
- LibraryClientUtility.$store = storeFunc(options.pinia);
67
- //LibraryClientUtility.$store.$logger = options.logger;
68
- Object.defineProperty(LibraryClientUtility.$store, '$logger', {
69
- get() {
70
- if (!this._logger)
71
- this._logger = LibraryClientUtility.$injector.getService(LibraryClientConstants.InjectorKeys.SERVICE_LOGGER);
72
- return this._logger;
73
- },
74
- });
75
-
76
- const storeFuncModules = [];
77
- // options.addModule('adminNews', adminNews, options.actionDispatcher, pluginPersistType, options.pluginPersistConfig, options.pinia, logger);
78
- // options.addModule('adminUsers', adminUsers, options.actionDispatcher, pluginPersistType, options.pluginPersistConfig, options.pinia, logger);
79
- // storeFuncModules.push(options.addModule('news', news, options.actionDispatcher, options.actionGetters, storeConfig.persist, pluginPersistType, options.pluginPersistSetup, options.pluginPersistSetupOverride, options.pinia, logger));
80
- // storeFuncModules.push(options.addModule('user', user, options.actionDispatcher, options.actionGetters, storeConfig.persist, pluginPersistType, options.pluginPersistSetup, options.pluginPersistSetupOverride, options.pinia, logger));
81
- storeFuncModules.push(options.addModule('news', news, options.actionDispatcher, options.actionGetters, storeConfig.persist, pluginPersistType, options.pluginPersistSetup, options.pluginPersistSetupOverride, options.pinia));
82
- storeFuncModules.push(options.addModule('user', user, options.actionDispatcher, options.actionGetters, storeConfig.persist, pluginPersistType, options.pluginPersistSetup, options.pluginPersistSetupOverride, options.pinia));
83
-
84
- storeFuncModules.push(...options.initModules());
85
-
86
- LibraryClientUtility.$store.dispatcher = options.actionDispatcher;
87
- LibraryClientUtility.$store.getters = options.actionGetters;
88
- }
89
- },
90
- options: {
91
- actionDispatcher: this.actionDispatcher,
92
- actionGetters: this.actionGetters,
93
- addModule: this._addModule,
94
- initModules: this._initModules,
95
- // logger: logger,
96
- pinia: this.pinia,
97
- pluginPersistConfig: this._initPluginPersistConfig(),
98
- pluginPersistSetupOverride: this._initPluginPersistConfigSetupOverride,
99
- pluginPersistSetup: this._initPluginPersistConfigSetup,
100
- pluginPersistType: this._initPluginPersistType,
101
- storeConfig: initialStoreConfig
102
- }
103
- };
104
- }
105
-
106
- // _addModule(key, storeConfig, actionDispatcher, actionGetters, pluginPersistConfig, pluginPersistType, pluginPersistSetup, pluginPersistSetupOverride, pinia, logger) {
107
- _addModule(key, storeConfig, actionDispatcher, actionGetters, pluginPersistConfig, pluginPersistType, pluginPersistSetup, pluginPersistSetupOverride, pinia) {
108
- if (pluginPersistType && pluginPersistSetup && storeConfig.pluginPersistPaths && storeConfig.pluginPersistPaths[pluginPersistType]) {
109
- pluginPersistConfig = LibraryCommonUtility.cloneDeep(pluginPersistConfig);
110
- pluginPersistSetup(pluginPersistType, storeConfig, pluginPersistConfig, pluginPersistSetupOverride, {
111
- additionalPaths: storeConfig.pluginPersistPaths[pluginPersistType],
112
- keySuffix: `_${key}`
113
- });
114
- }
115
- actionDispatcher[key] = storeConfig.dispatcher;
116
- delete storeConfig.dispatcher;
117
- actionGetters[key] = storeConfig.getters;
118
- delete storeConfig.getters;
119
- delete storeConfig.pluginPersistPaths;
120
- const storeFunc = defineStore(key, storeConfig);
121
- LibraryClientUtility.$store[key] = storeFunc(pinia);
122
- // LibraryClientUtility.$store[key].$logger = logger;
123
- Object.defineProperty(LibraryClientUtility.$store[key], '$logger', {
124
- get() {
125
- if (!this._logger)
126
- this._logger = LibraryClientUtility.$injector.getService(LibraryClientConstants.InjectorKeys.SERVICE_LOGGER);
127
- return this._logger;
128
- },
129
- });
130
- return { key: key, storeFunc: storeFunc };
131
- }
132
-
133
- _initModules() {
134
- return [];
135
- }
136
-
137
- _initPluginPersist() {
138
- if (this._initPluginPersistType() === BaseStore.PersistanceTypePersist) {
139
- this.pinia.use(piniaPluginPersistedState);
140
- return;
141
- }
142
- if (this._initPluginPersistType() === BaseStore.PersistanceTypePersist2) {
143
- const installPersistedStatePlugin = createPersistedStatePlugin();
144
- this.pinia.use((context) => installPersistedStatePlugin(context));
145
- return;
146
- }
147
- if (this._initPluginPersistType() === BaseStore.PersistanceTypeOverride) {
148
- const override = this._initPluginPersistOverride();
149
- if (override) {
150
- override(this.pinia);
151
- return;
152
- }
153
- }
154
-
155
- throw Error('Unknown persistance engine for Pinia store.');
156
- }
157
-
158
- _initPluginPersistConfig() {
159
- return null;
160
- }
161
-
162
- _initPluginPersistOverride() {
163
- return null;
164
- }
165
-
166
- _initPluginPersistType() {
167
- return BaseStore.PersistanceTypePersist;
168
- }
169
-
170
- _initPluginPersistConfigSetup(type, storeConfig, persistConfig, override, options) {
171
- if (type === BaseStore.PersistanceTypePersist) {
172
- if (options && !String.isNullOrEmpty(options.keyOverride))
173
- persistConfig.key = options.keyOverride;
174
- if (options && !String.isNullOrEmpty(options.keySuffix))
175
- persistConfig.key += options.keySuffix;
176
- if (options && options.additionalPaths)
177
- persistConfig.pick = [ ...persistConfig.paths, ...options.additionalPaths ];
178
- storeConfig.persist = persistConfig;
179
- return;
180
- }
181
- if (type === BaseStore.PersistanceTypePersist2) {
182
- if (options && !String.isNullOrEmpty(options.keyOverride))
183
- persistConfig.key = options.keyOverride;
184
- if (options && !String.isNullOrEmpty(options.keySuffix))
185
- persistConfig.key += options.keySuffix;
186
- if (options && options.additionalPaths)
187
- persistConfig.includePaths = [ ...persistConfig.includePaths, ...options.additionalPaths ];
188
- storeConfig.persistedState = persistConfig;
189
- return;
190
- }
191
- if (type === BaseStore.PersistanceTypeOverride) {
192
- if (override) {
193
- override(storeConfig, persistConfig);
194
- return;
195
- }
196
- }
197
-
198
- throw Error('Unknown persistance engine for Pinia store.');
199
- }
200
-
201
- _initPluginPersistConfigSetupOverride(storeConfig, persistConfig) {
202
- }
203
-
204
- _initStoreConfig() {
205
- throw new NotImplementedError();
206
- }
207
-
208
- _initStoreConfigBase() {
209
- return {
210
- pluginPersistPaths: {
211
- persist: [
212
- 'openSource',
213
- 'plans',
214
- 'version'
215
- ]
216
- },
217
- state: () => ({
218
- checksumLastUpdate: [],
219
- openSource: [],
220
- plans: [],
221
- version: null
222
- }),
223
- actions: {
224
- async initialize(correlationId) {
225
- const service = LibraryClientUtility.$injector.getService(LibraryClientConstants.InjectorKeys.SERVICE_UTILITY);
226
- const response = await service.initialize(correlationId);
227
- if (Response.hasSucceeded(response)) {
228
- await this.setPlans(correlationId, response.results.plans);
229
- await this.setVersion(correlationId, response.results.version);
230
- if (this._initialize)
231
- await this._initialize(correlationId, response.results);
232
- }
233
- },
234
- async requestOpenSource(correlationId) {
235
- const openSourceCheck = LibraryClientUtility.$store.openSource;
236
- if (openSourceCheck && Array.isArray(openSourceCheck) && openSourceCheck.length > 0)
237
- return Response.success(correlationId, openSourceCheck);
238
-
239
- const service = LibraryClientUtility.$injector.getService(LibraryClientConstants.InjectorKeys.SERVICE_UTILITY);
240
- const response = await service.openSource(correlationId);
241
- this.$logger.debug('store', 'requestOpenSource', 'response', response, correlationId);
242
- const openSource = response.results ? response.results : null;
243
- if (Response.hasFailed(response))
244
- return response;
245
- await this.setOpenSource(correlationId, openSource);
246
- return Response.success(correlationId, openSource);
247
- },
248
- async requestPlans(correlationId) {
249
- const service = LibraryClientUtility.$injector.getService(LibraryClientConstants.InjectorKeys.SERVICE_PLANS);
250
- const response = await service.plans(correlationId);
251
- this.$logger.debug('store', 'requestPlans', 'response', response, correlationId);
252
- const plans = response.results ? response.results.data : [];
253
- if (Response.hasFailed(response))
254
- return response;
255
- await this.setPlans(correlationId, plans);
256
- return Response.success(plans);
257
- },
258
- async requestVersion(correlationId) {
259
- const service = LibraryClientUtility.$injector.getService(LibraryClientConstants.InjectorKeys.SERVICE_VERSION);
260
- const version = await service.version(correlationId);
261
- await this.setVersion(correlationId, version);
262
- },
263
- async setOpenSource(correlationId, openSource) {
264
- this.$logger.debug('store', 'setOpenSource', 'openSource.a', openSource, correlationId);
265
- this.$logger.debug('store', 'setOpenSource', 'openSource.b', this.openSource, correlationId);
266
- this.openSource = openSource;
267
- this.$logger.debug('store', 'setOpenSource', 'openSource.c', this.openSource, correlationId);
268
- },
269
- async setPlans(correlationId, plans) {
270
- this.$logger.debug('store', 'setPlans', 'plans.a', plans, correlationId);
271
- this.$logger.debug('store', 'setPlans', 'plans.b', this.plans, correlationId);
272
- this.plans = plans;
273
- this.$logger.debug('store', 'setPlans', 'plans.c', this.plans, correlationId);
274
- },
275
- async setVersion(correlationId, version) {
276
- if (!version)
277
- return;
278
- // this.$logger.debug('store', 'getVersion', 'version', version, correlationId);
279
- // commit('setVersion', { correlationId: correlationId, version: version });
280
- this.$logger.debug('store', 'setVersion', 'version', version, correlationId);
281
- this.version = version;
282
- }
283
- },
284
- getters: {
285
- getOpenSource(correlationId) {
286
- return LibraryClientUtility.$store.openSource;
287
- },
288
- getPlan(correlationId, id) {
289
- if (LibraryClientUtility.$store.plans == null)
290
- return null;
291
- return LibraryClientUtility.$store.plans.find(plan => plan.id === id);
292
- }
293
- },
294
- dispatcher: {
295
- async requestOpenSource(correlationId) {
296
- return await LibraryClientUtility.$store.requestOpenSource(correlationId);
297
- },
298
- async requestPlans(correlationId) {
299
- return await LibraryClientUtility.$store.requestPlans(correlationId);
300
- },
301
- async requestVersion(correlationId) {
302
- await LibraryClientUtility.$store.requestVersion(correlationId);
303
- },
304
- async initialize(correlationId) {
305
- await LibraryClientUtility.$store.initialize(correlationId);
306
- }
307
- }
308
- };
309
- }
310
-
311
- static PersistanceTypeOverride = 'override';
312
- static PersistanceTypePersist = 'persist';
313
- static PersistanceTypePersist2 = 'persist2';
314
- }
315
-
316
- export default BaseStore;
1
+ import { createPinia, defineStore } from 'pinia';
2
+ import piniaPluginPersistedState from 'pinia-plugin-persistedstate';
3
+ import { createPersistedStatePlugin } from 'pinia-plugin-persistedstate-2';
4
+
5
+ import LibraryClientConstants from '@thzero/library_client/constants';
6
+
7
+ import LibraryClientUtility from '@thzero/library_client/utility/index';
8
+ import LibraryCommonUtility from '@thzero/library_common/utility/index';
9
+
10
+ import Response from '@thzero/library_common/response';
11
+
12
+ import NotImplementedError from '@thzero/library_common/errors/notImplemented';
13
+
14
+ // import adminNews from './admin/news/pinia';
15
+ // import adminUsers from './admin/users/pinia';
16
+
17
+ import news from './news';
18
+ import user from './user';
19
+
20
+ class BaseStore {
21
+ async initialize() {
22
+ this.pinia = createPinia();
23
+
24
+ this._initPluginPersist();
25
+
26
+ return this.pinia;
27
+ }
28
+
29
+ setup() {
30
+ // const logger = LibraryClientUtility.$injector.getService(LibraryClientConstants.InjectorKeys.SERVICE_LOGGER);
31
+
32
+ const initialStoreConfig = this._initStoreConfigBase();
33
+ const appStoreConfig = this._initStoreConfig();
34
+ initialStoreConfig.actions = Object.assign(initialStoreConfig.actions, appStoreConfig.actions);
35
+ initialStoreConfig.dispatcher = Object.assign(initialStoreConfig.dispatcher, appStoreConfig.dispatcher);
36
+ initialStoreConfig.getters = Object.assign(initialStoreConfig.getters, appStoreConfig.getters);
37
+
38
+ const initialState = initialStoreConfig.state();
39
+ const appState = appStoreConfig.state();
40
+ const state = Object.assign(initialState, appState);
41
+ initialStoreConfig.state = () => state;
42
+
43
+ return {
44
+ func: {
45
+ install(app, options) {
46
+ const storeConfig = options.storeConfig;
47
+
48
+ options.actionGetters = storeConfig.getters;
49
+ options.actionDispatcher = storeConfig.dispatcher;
50
+ if (!options.actionDispatcher)
51
+ options.actionDispatcher = {};
52
+
53
+ const pluginPersistType = options.pluginPersistType();
54
+ const additionalPaths = storeConfig.pluginPersistPaths ? storeConfig.pluginPersistPaths[pluginPersistType] : null;
55
+
56
+ if (options.pluginPersistSetup && options.pluginPersistType && options.pluginPersistConfig && options.pluginPersistConfig && options.pluginPersistConfig[pluginPersistType])
57
+ options.pluginPersistSetup(pluginPersistType, storeConfig, options.pluginPersistConfig[pluginPersistType], options.pluginPersistSetupOverride, {
58
+ additionalPaths: additionalPaths
59
+ });
60
+
61
+ // if (storeConfig.pluginPersistPaths && storeConfig.pluginPersistPaths[pluginPersistType])
62
+ // storeConfig[pluginPersistType].paths = [ ...storeConfig[pluginPersistType].paths, ...storeConfig.pluginPersistPaths[pluginPersistType] ];
63
+ delete storeConfig.pluginPersistPaths;
64
+
65
+ const storeFunc = defineStore('main', storeConfig);
66
+ LibraryClientUtility.$store = storeFunc(options.pinia);
67
+ //LibraryClientUtility.$store.$logger = options.logger;
68
+ Object.defineProperty(LibraryClientUtility.$store, '$logger', {
69
+ get() {
70
+ if (!this._logger)
71
+ this._logger = LibraryClientUtility.$injector.getService(LibraryClientConstants.InjectorKeys.SERVICE_LOGGER);
72
+ return this._logger;
73
+ },
74
+ });
75
+
76
+ const storeFuncModules = [];
77
+ // options.addModule('adminNews', adminNews, options.actionDispatcher, pluginPersistType, options.pluginPersistConfig, options.pinia, logger);
78
+ // options.addModule('adminUsers', adminUsers, options.actionDispatcher, pluginPersistType, options.pluginPersistConfig, options.pinia, logger);
79
+ // storeFuncModules.push(options.addModule('news', news, options.actionDispatcher, options.actionGetters, storeConfig.persist, pluginPersistType, options.pluginPersistSetup, options.pluginPersistSetupOverride, options.pinia, logger));
80
+ // storeFuncModules.push(options.addModule('user', user, options.actionDispatcher, options.actionGetters, storeConfig.persist, pluginPersistType, options.pluginPersistSetup, options.pluginPersistSetupOverride, options.pinia, logger));
81
+ storeFuncModules.push(options.initModule('news', news, options.actionDispatcher, options.actionGetters, storeConfig.persist, pluginPersistType, options.pluginPersistSetup, options.pluginPersistSetupOverride, options.pinia));
82
+ storeFuncModules.push(options.initModule('user', user, options.actionDispatcher, options.actionGetters, storeConfig.persist, pluginPersistType, options.pluginPersistSetup, options.pluginPersistSetupOverride, options.pinia));
83
+
84
+ const modules = options.initModules(options.addModule);
85
+ for(const module of modules)
86
+ storeFuncModules.push(options.initModule(module.key, module.storeConfig, options.actionDispatcher, options.actionGetters, storeConfig.persist, pluginPersistType, options.pluginPersistSetup, options.pluginPersistSetupOverride, options.pinia));
87
+
88
+ LibraryClientUtility.$store.dispatcher = options.actionDispatcher;
89
+ LibraryClientUtility.$store.getters = options.actionGetters;
90
+ }
91
+ },
92
+ options: {
93
+ actionDispatcher: this.actionDispatcher,
94
+ actionGetters: this.actionGetters,
95
+ addModule: this._addModule,
96
+ initModule: this._initModule,
97
+ initModules: this._initModules,
98
+ // logger: logger,
99
+ pinia: this.pinia,
100
+ pluginPersistConfig: this._initPluginPersistConfig(),
101
+ pluginPersistSetupOverride: this._initPluginPersistConfigSetupOverride,
102
+ pluginPersistSetup: this._initPluginPersistConfigSetup,
103
+ pluginPersistType: this._initPluginPersistType,
104
+ storeConfig: initialStoreConfig
105
+ }
106
+ };
107
+ }
108
+
109
+ _addModule(key, storeConfig) {
110
+ return { key: key, storeConfig: storeConfig };
111
+ }
112
+
113
+ // _addModule(key, storeConfig, actionDispatcher, actionGetters, pluginPersistConfig, pluginPersistType, pluginPersistSetup, pluginPersistSetupOverride, pinia, logger) {
114
+ _initModule(key, storeConfig, actionDispatcher, actionGetters, pluginPersistConfig, pluginPersistType, pluginPersistSetup, pluginPersistSetupOverride, pinia) {
115
+ if (pluginPersistType && pluginPersistSetup && storeConfig.pluginPersistPaths && storeConfig.pluginPersistPaths[pluginPersistType]) {
116
+ pluginPersistConfig = LibraryCommonUtility.cloneDeep(pluginPersistConfig);
117
+ pluginPersistSetup(pluginPersistType, storeConfig, pluginPersistConfig, pluginPersistSetupOverride, {
118
+ additionalPaths: storeConfig.pluginPersistPaths[pluginPersistType],
119
+ keySuffix: `_${key}`
120
+ });
121
+ }
122
+ actionDispatcher[key] = storeConfig.dispatcher;
123
+ delete storeConfig.dispatcher;
124
+ actionGetters[key] = storeConfig.getters;
125
+ delete storeConfig.getters;
126
+ delete storeConfig.pluginPersistPaths;
127
+ const storeFunc = defineStore(key, storeConfig);
128
+ LibraryClientUtility.$store[key] = storeFunc(pinia);
129
+ // LibraryClientUtility.$store[key].$logger = logger;
130
+ Object.defineProperty(LibraryClientUtility.$store[key], '$logger', {
131
+ get() {
132
+ if (!this._logger)
133
+ this._logger = LibraryClientUtility.$injector.getService(LibraryClientConstants.InjectorKeys.SERVICE_LOGGER);
134
+ return this._logger;
135
+ },
136
+ });
137
+ return { key: key, storeFunc: storeFunc };
138
+ }
139
+
140
+ _initPluginPersist() {
141
+ if (this._initPluginPersistType() === BaseStore.PersistanceTypePersist) {
142
+ this.pinia.use(piniaPluginPersistedState);
143
+ return;
144
+ }
145
+ if (this._initPluginPersistType() === BaseStore.PersistanceTypePersist2) {
146
+ const installPersistedStatePlugin = createPersistedStatePlugin();
147
+ this.pinia.use((context) => installPersistedStatePlugin(context));
148
+ return;
149
+ }
150
+ if (this._initPluginPersistType() === BaseStore.PersistanceTypeOverride) {
151
+ const override = this._initPluginPersistOverride();
152
+ if (override) {
153
+ override(this.pinia);
154
+ return;
155
+ }
156
+ }
157
+
158
+ throw Error('Unknown persistance engine for Pinia store.');
159
+ }
160
+
161
+ _initModules() {
162
+ return null;
163
+ }
164
+
165
+ _initPluginPersistConfig() {
166
+ return null;
167
+ }
168
+
169
+ _initPluginPersistOverride() {
170
+ return null;
171
+ }
172
+
173
+ _initPluginPersistType() {
174
+ return BaseStore.PersistanceTypePersist;
175
+ }
176
+
177
+ _initPluginPersistConfigSetup(type, storeConfig, persistConfig, override, options) {
178
+ if (type === BaseStore.PersistanceTypePersist) {
179
+ if (options && !String.isNullOrEmpty(options.keyOverride))
180
+ persistConfig.key = options.keyOverride;
181
+ if (options && !String.isNullOrEmpty(options.keySuffix))
182
+ persistConfig.key += options.keySuffix;
183
+ if (options && options.additionalPaths)
184
+ persistConfig.pick = [ ...persistConfig.paths, ...options.additionalPaths ];
185
+ storeConfig.persist = persistConfig;
186
+ return;
187
+ }
188
+ if (type === BaseStore.PersistanceTypePersist2) {
189
+ if (options && !String.isNullOrEmpty(options.keyOverride))
190
+ persistConfig.key = options.keyOverride;
191
+ if (options && !String.isNullOrEmpty(options.keySuffix))
192
+ persistConfig.key += options.keySuffix;
193
+ if (options && options.additionalPaths)
194
+ persistConfig.includePaths = [ ...persistConfig.includePaths, ...options.additionalPaths ];
195
+ storeConfig.persistedState = persistConfig;
196
+ return;
197
+ }
198
+ if (type === BaseStore.PersistanceTypeOverride) {
199
+ if (override) {
200
+ override(storeConfig, persistConfig);
201
+ return;
202
+ }
203
+ }
204
+
205
+ throw Error('Unknown persistance engine for Pinia store.');
206
+ }
207
+
208
+ _initPluginPersistConfigSetupOverride(storeConfig, persistConfig) {
209
+ }
210
+
211
+ _initStoreConfig() {
212
+ throw new NotImplementedError();
213
+ }
214
+
215
+ _initStoreConfigBase() {
216
+ return {
217
+ pluginPersistPaths: {
218
+ persist: [
219
+ 'openSource',
220
+ 'plans',
221
+ 'version'
222
+ ]
223
+ },
224
+ state: () => ({
225
+ checksumLastUpdate: [],
226
+ openSource: [],
227
+ plans: [],
228
+ version: null
229
+ }),
230
+ actions: {
231
+ async initialize(correlationId) {
232
+ const service = LibraryClientUtility.$injector.getService(LibraryClientConstants.InjectorKeys.SERVICE_UTILITY);
233
+ const response = await service.initialize(correlationId);
234
+ if (Response.hasSucceeded(response)) {
235
+ await this.setPlans(correlationId, response.results.plans);
236
+ await this.setVersion(correlationId, response.results.version);
237
+ if (this._initialize)
238
+ await this._initialize(correlationId, response.results);
239
+ }
240
+ },
241
+ async requestOpenSource(correlationId) {
242
+ const openSourceCheck = LibraryClientUtility.$store.openSource;
243
+ if (openSourceCheck && Array.isArray(openSourceCheck) && openSourceCheck.length > 0)
244
+ return Response.success(correlationId, openSourceCheck);
245
+
246
+ const service = LibraryClientUtility.$injector.getService(LibraryClientConstants.InjectorKeys.SERVICE_UTILITY);
247
+ const response = await service.openSource(correlationId);
248
+ this.$logger.debug('store', 'requestOpenSource', 'response', response, correlationId);
249
+ const openSource = response.results ? response.results : null;
250
+ if (Response.hasFailed(response))
251
+ return response;
252
+ await this.setOpenSource(correlationId, openSource);
253
+ return Response.success(correlationId, openSource);
254
+ },
255
+ async requestPlans(correlationId) {
256
+ const service = LibraryClientUtility.$injector.getService(LibraryClientConstants.InjectorKeys.SERVICE_PLANS);
257
+ const response = await service.plans(correlationId);
258
+ this.$logger.debug('store', 'requestPlans', 'response', response, correlationId);
259
+ const plans = response.results ? response.results.data : [];
260
+ if (Response.hasFailed(response))
261
+ return response;
262
+ await this.setPlans(correlationId, plans);
263
+ return Response.success(plans);
264
+ },
265
+ async requestVersion(correlationId) {
266
+ const service = LibraryClientUtility.$injector.getService(LibraryClientConstants.InjectorKeys.SERVICE_VERSION);
267
+ const version = await service.version(correlationId);
268
+ await this.setVersion(correlationId, version);
269
+ },
270
+ async setOpenSource(correlationId, openSource) {
271
+ this.$logger.debug('store', 'setOpenSource', 'openSource.a', openSource, correlationId);
272
+ this.$logger.debug('store', 'setOpenSource', 'openSource.b', this.openSource, correlationId);
273
+ this.openSource = openSource;
274
+ this.$logger.debug('store', 'setOpenSource', 'openSource.c', this.openSource, correlationId);
275
+ },
276
+ async setPlans(correlationId, plans) {
277
+ this.$logger.debug('store', 'setPlans', 'plans.a', plans, correlationId);
278
+ this.$logger.debug('store', 'setPlans', 'plans.b', this.plans, correlationId);
279
+ this.plans = plans;
280
+ this.$logger.debug('store', 'setPlans', 'plans.c', this.plans, correlationId);
281
+ },
282
+ async setVersion(correlationId, version) {
283
+ if (!version)
284
+ return;
285
+ // this.$logger.debug('store', 'getVersion', 'version', version, correlationId);
286
+ // commit('setVersion', { correlationId: correlationId, version: version });
287
+ this.$logger.debug('store', 'setVersion', 'version', version, correlationId);
288
+ this.version = version;
289
+ }
290
+ },
291
+ getters: {
292
+ getOpenSource(correlationId) {
293
+ return LibraryClientUtility.$store.openSource;
294
+ },
295
+ getPlan(correlationId, id) {
296
+ if (LibraryClientUtility.$store.plans == null)
297
+ return null;
298
+ return LibraryClientUtility.$store.plans.find(plan => plan.id === id);
299
+ }
300
+ },
301
+ dispatcher: {
302
+ async requestOpenSource(correlationId) {
303
+ return await LibraryClientUtility.$store.requestOpenSource(correlationId);
304
+ },
305
+ async requestPlans(correlationId) {
306
+ return await LibraryClientUtility.$store.requestPlans(correlationId);
307
+ },
308
+ async requestVersion(correlationId) {
309
+ await LibraryClientUtility.$store.requestVersion(correlationId);
310
+ },
311
+ async initialize(correlationId) {
312
+ await LibraryClientUtility.$store.initialize(correlationId);
313
+ }
314
+ }
315
+ };
316
+ }
317
+
318
+ static PersistanceTypeOverride = 'override';
319
+ static PersistanceTypePersist = 'persist';
320
+ static PersistanceTypePersist2 = 'persist2';
321
+ }
322
+
323
+ export default BaseStore;