@thzero/library_client_svelte 0.15.7 → 0.15.9
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/boot/baseServices.js +4 -4
- package/boot/baseValidation.js +54 -0
- package/boot/basei18n.js +3 -3
- package/boot/main.js +2 -6
- package/package.json +5 -4
- package/service/baseUser.js +49 -0
- package/service/event.js +2 -2
- package/service/router.js +4 -4
- package/service/store.js +2 -2
- package/service/translate.js +2 -2
package/boot/baseServices.js
CHANGED
|
@@ -13,19 +13,19 @@ class SvelteBaseServices extends BaseServices {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
_initializeEvent(injector) {
|
|
16
|
-
return new eventService(
|
|
16
|
+
return new eventService();
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
_initializeRouter(injector) {
|
|
20
|
-
return new routerService(
|
|
20
|
+
return new routerService();
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
_initializeStore(injector) {
|
|
24
|
-
return new storeService(
|
|
24
|
+
return new storeService();
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
_initializeTranslate(injector) {
|
|
28
|
-
return new translateService(
|
|
28
|
+
return new translateService();
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
class BaseValidate {
|
|
2
|
+
// eslint-disable-next-line
|
|
3
|
+
async execute(framework, app, store) {
|
|
4
|
+
// extend('decimal', {
|
|
5
|
+
// validate: (value, { decimals = '*', separator = '.' } = {}) => {
|
|
6
|
+
// if (value === null || value === undefined || value === '') {
|
|
7
|
+
// return {
|
|
8
|
+
// valid: false
|
|
9
|
+
// };
|
|
10
|
+
// }
|
|
11
|
+
// if (Number(decimals) === 0) {
|
|
12
|
+
// return {
|
|
13
|
+
// valid: /^-?\d*$/.test(value)
|
|
14
|
+
// };
|
|
15
|
+
// }
|
|
16
|
+
// const regexPart = decimals === '*' ? '+' : `{1,${decimals}}`;
|
|
17
|
+
// const regex = new RegExp(`^[-+]?\\d*(\\${separator}\\d${regexPart})?([eE]{1}[-]?\\d+)?$`);
|
|
18
|
+
// return {
|
|
19
|
+
// valid: regex.test(value),
|
|
20
|
+
// data: {
|
|
21
|
+
// serverMessage: 'Only decimal values are available'
|
|
22
|
+
// }
|
|
23
|
+
// };
|
|
24
|
+
// },
|
|
25
|
+
// message: '{serverMessage}'
|
|
26
|
+
// });
|
|
27
|
+
|
|
28
|
+
// extend('name', {
|
|
29
|
+
// getMessage: field => 'The ' + field + ' field may only contain alphanumeric and space characters',
|
|
30
|
+
// // eslint-disable-next-line
|
|
31
|
+
// validate(value, args) {
|
|
32
|
+
// const regEx = /^[a-zA-Z0-9]+(['\-a-zA-Z0-9 ]*)*$/;
|
|
33
|
+
// return regEx.test(value);
|
|
34
|
+
// }
|
|
35
|
+
// });
|
|
36
|
+
|
|
37
|
+
// extend('tagLine', {
|
|
38
|
+
// getMessage: field => 'The ' + field + ' field may only contain alphanumeric, space, and punctuation characters',
|
|
39
|
+
// // eslint-disable-next-line
|
|
40
|
+
// validate(value, args) {
|
|
41
|
+
// const regEx = /^[a-zA-Z0-9]+([',.!& \-a-zA-Z0-9 ]*)*$/;
|
|
42
|
+
// return regEx.test(value);
|
|
43
|
+
// }
|
|
44
|
+
// });
|
|
45
|
+
|
|
46
|
+
this._initialize();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// eslint-disable-next-line
|
|
50
|
+
_initialize(extend) {
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export default BaseValidate;
|
package/boot/basei18n.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { init, getLocaleFromNavigator, register,
|
|
1
|
+
import { init, getLocaleFromNavigator, register, format, addMessages, unwrapFunctionStore } from 'svelte-i18n';
|
|
2
2
|
|
|
3
3
|
import GlobalUtility from '@thzero/library_client/utility/global';
|
|
4
4
|
|
|
@@ -8,14 +8,14 @@ import NotImplementedError from '@thzero/library_common/errors/notImplemented';
|
|
|
8
8
|
|
|
9
9
|
class SvelteBasei18n extends Basei18n {
|
|
10
10
|
// eslint-disable-next-line
|
|
11
|
-
async execute(framework, app,
|
|
11
|
+
async execute(framework, app, store) {
|
|
12
12
|
this._initMessages(register, addMessages);
|
|
13
13
|
|
|
14
14
|
init({
|
|
15
15
|
fallbackLocale: 'en',
|
|
16
16
|
initialLocale: getLocaleFromNavigator()
|
|
17
17
|
});
|
|
18
|
-
GlobalUtility.$trans = { t:
|
|
18
|
+
GlobalUtility.$trans = { t: unwrapFunctionStore(format) };
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
_initMessages(register) {
|
package/boot/main.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import GlobalUtility from '@thzero/library_client/utility/global';
|
|
2
2
|
|
|
3
|
+
// @ts-ignore
|
|
3
4
|
import {} from '@thzero/library_common/utility/string';
|
|
4
5
|
|
|
5
6
|
// eslint-disable-next-line
|
|
6
|
-
async function start(app,
|
|
7
|
+
async function start(app, storeRequest, bootFiles, starter) {
|
|
7
8
|
let store = null;
|
|
8
9
|
if (storeRequest) {
|
|
9
10
|
try {
|
|
@@ -18,8 +19,6 @@ async function start(app, router, storeRequest, bootFiles, starter) {
|
|
|
18
19
|
if (!store)
|
|
19
20
|
throw Error('Unable to create store.');
|
|
20
21
|
GlobalUtility.$store = store;
|
|
21
|
-
|
|
22
|
-
GlobalUtility.$navRouter = router;
|
|
23
22
|
|
|
24
23
|
if (bootFiles && (bootFiles.length > 0)) {
|
|
25
24
|
let obj;
|
|
@@ -30,7 +29,6 @@ async function start(app, router, storeRequest, bootFiles, starter) {
|
|
|
30
29
|
try {
|
|
31
30
|
try {
|
|
32
31
|
await bootFile({
|
|
33
|
-
router,
|
|
34
32
|
store
|
|
35
33
|
});
|
|
36
34
|
continue;
|
|
@@ -38,7 +36,6 @@ async function start(app, router, storeRequest, bootFiles, starter) {
|
|
|
38
36
|
catch (err) {
|
|
39
37
|
obj = new bootFile();
|
|
40
38
|
await obj.execute(
|
|
41
|
-
router,
|
|
42
39
|
store
|
|
43
40
|
);
|
|
44
41
|
continue;
|
|
@@ -65,7 +62,6 @@ async function start(app, router, storeRequest, bootFiles, starter) {
|
|
|
65
62
|
|
|
66
63
|
try {
|
|
67
64
|
const result = starter({
|
|
68
|
-
router,
|
|
69
65
|
store
|
|
70
66
|
});
|
|
71
67
|
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thzero/library_client_svelte",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.9",
|
|
4
4
|
"version_major": 0,
|
|
5
5
|
"version_minor": 15,
|
|
6
|
-
"version_patch":
|
|
7
|
-
"version_date": "12/
|
|
6
|
+
"version_patch": 9,
|
|
7
|
+
"version_date": "12/15/2022",
|
|
8
8
|
"description": "An opinionated library of common functionality to bootstrap a Svelte based SPA application.",
|
|
9
9
|
"author": "thZero",
|
|
10
10
|
"license": "MIT",
|
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
"@thzero/library_client": "^0.16",
|
|
25
25
|
"@thzero/library_common": "^0.16",
|
|
26
26
|
"mitt": "^3.0.0",
|
|
27
|
-
"svelte-i18n": "^3.6.0"
|
|
27
|
+
"svelte-i18n": "^3.6.0",
|
|
28
|
+
"svelte-spa-router": "^3.3.0"
|
|
28
29
|
},
|
|
29
30
|
"peerDependencies": {
|
|
30
31
|
"svelte": "^3"
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import LibraryConstants from '@thzero/library_client/constants';
|
|
2
|
+
|
|
3
|
+
import BaseUserService from '@thzero/library_client/service/baseUser';
|
|
4
|
+
|
|
5
|
+
class VueBaseUserService extends BaseUserService {
|
|
6
|
+
constructor() {
|
|
7
|
+
super();
|
|
8
|
+
|
|
9
|
+
this._serviceStore = null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async init(injector) {
|
|
13
|
+
await super.init(injector);
|
|
14
|
+
|
|
15
|
+
this._serviceStore = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_STORE);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async resetUser(correlationId) {
|
|
19
|
+
await this._serviceStore.dispatcher.user.resetUser(correlationId);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async setAuthCompleted(correlationId) {
|
|
23
|
+
await this._serviceStore.dispatcher.user.setAuthCompleted(correlationId, true);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async setClaims(correlationId, claims) {
|
|
27
|
+
await this._serviceStore.dispatcher.user.setClaims(correlationId, claims);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async setLoggedIn(correlationId, value) {
|
|
31
|
+
await this._serviceStore.dispatcher.user.setLoggedIn(correlationId, value);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async setTokenResult(correlationId, tokenResult) {
|
|
35
|
+
await this._serviceStore.dispatcher.user.setTokenResult(correlationId, tokenResult);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async setUser(correlationId, user) {
|
|
39
|
+
await this._serviceStore.dispatcher.user.setUser(correlationId, user);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
get token() {
|
|
43
|
+
if (this._serviceStore.state.user)
|
|
44
|
+
return this._serviceStore.state.user.token;
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export default VueBaseUserService;
|
package/service/event.js
CHANGED
|
@@ -2,11 +2,11 @@ import GlobalUtility from '@thzero/library_client/utility/global';
|
|
|
2
2
|
|
|
3
3
|
import EventService from '@thzero/library_client/service/event';
|
|
4
4
|
|
|
5
|
-
class
|
|
5
|
+
class SvelteEventService extends EventService {
|
|
6
6
|
// eslint-disable-next-line
|
|
7
7
|
emit(channel, value) {
|
|
8
8
|
GlobalUtility.$EventBus.emit(channel, value);
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
export default
|
|
12
|
+
export default SvelteEventService;
|
package/service/router.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { navigateTo } from 'svelte-router-spa';
|
|
2
2
|
|
|
3
3
|
import RouterService from '@thzero/library_client/service/router';
|
|
4
4
|
|
|
5
|
-
class
|
|
5
|
+
class SvelteRouterService extends RouterService {
|
|
6
6
|
// eslint-disable-next-line
|
|
7
7
|
route(path, options) {
|
|
8
|
-
|
|
8
|
+
navigateTo(path);
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
export default
|
|
12
|
+
export default SvelteRouterService;
|
package/service/store.js
CHANGED
|
@@ -2,10 +2,10 @@ import GlobalUtility from '@thzero/library_client/utility/global';
|
|
|
2
2
|
|
|
3
3
|
import Service from '@thzero/library_client/service/index';
|
|
4
4
|
|
|
5
|
-
class
|
|
5
|
+
class SvelteStoreService extends Service {
|
|
6
6
|
get store() {
|
|
7
7
|
return GlobalUtility.$store;
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
export default
|
|
11
|
+
export default SvelteStoreService;
|
package/service/translate.js
CHANGED
|
@@ -2,11 +2,11 @@ import GlobalUtility from '@thzero/library_client/utility/global';
|
|
|
2
2
|
|
|
3
3
|
import TranslateService from '@thzero/library_client/service/translate';
|
|
4
4
|
|
|
5
|
-
class
|
|
5
|
+
class SvelteTranslateService extends TranslateService {
|
|
6
6
|
// eslint-disable-next-line
|
|
7
7
|
translate(correlationId, id) {
|
|
8
8
|
return GlobalUtility.$trans.t(id);
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
export default
|
|
12
|
+
export default SvelteTranslateService;
|