@thzero/library_client_svelte 0.17.7 → 0.17.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/README.md +65 -65
- package/boot/baseServices.js +32 -32
- package/boot/baseValidation.js +56 -56
- package/boot/basei18n.js +26 -26
- package/boot/eventBus.js +9 -9
- package/boot/main.js +104 -90
- package/boot/webcomponent.js +7 -7
- package/constants.js +9 -9
- package/license.md +8 -8
- package/openSource.js +45 -45
- package/package.json +32 -32
- package/service/baseUser.js +49 -49
- package/service/event.js +12 -12
- package/service/router.js +12 -12
- package/service/store.js +11 -11
- package/service/translate.js +12 -12
- package/utility/index.js +77 -77
package/README.md
CHANGED
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
[](https://opensource.org/licenses/MIT)
|
|
2
|
-
|
|
3
|
-
# library_client_svelte
|
|
4
|
-
|
|
5
|
-
## Requirements
|
|
6
|
-
|
|
7
|
-
### NodeJs
|
|
8
|
-
|
|
9
|
-
[NodeJs](https://nodejs.org) version 18+
|
|
10
|
-
|
|
11
|
-
### Svelte Application
|
|
12
|
-
|
|
13
|
-
npm create vite@latest myapp -- --template svelte
|
|
14
|
-
cd myapp
|
|
15
|
-
npm install
|
|
16
|
-
npm run dev
|
|
17
|
-
|
|
18
|
-
### Installation
|
|
19
|
-
|
|
20
|
-
[](https://npmjs.org/package/@thzero/library_client_svelte)
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
```js
|
|
24
|
-
// store.js
|
|
25
|
-
// An extremely simple external store
|
|
26
|
-
import { writable } from 'svelte/store'
|
|
27
|
-
export default writable(0)
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
jsconfig.json
|
|
31
|
-
```js
|
|
32
|
-
"baseUrl": ".",
|
|
33
|
-
"paths": {
|
|
34
|
-
"@/*": ["src/*"]
|
|
35
|
-
}
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
vite.config.js
|
|
39
|
-
```js
|
|
40
|
-
import path from 'path'
|
|
41
|
-
```
|
|
42
|
-
```js
|
|
43
|
-
let configEnv = process.env.NODE_ENV
|
|
44
|
-
console.log('svelte.config.NODE_ENV', configEnv)
|
|
45
|
-
const config = process.env._CONFIG
|
|
46
|
-
console.log('svelte.config._CONFIG', config)
|
|
47
|
-
if (config) {
|
|
48
|
-
const filename = path.join(__dirname, `./src/config/${configEnv}.json`)
|
|
49
|
-
console.log('svelte.config.filename', filename)
|
|
50
|
-
fs.writeFileSync(filename, config)
|
|
51
|
-
const contents = fs.readFileSync(filename, 'utf8')
|
|
52
|
-
console.log('svelte.config.file', contents)
|
|
53
|
-
}
|
|
54
|
-
else
|
|
55
|
-
configEnv = 'development'
|
|
56
|
-
console.log('svelte.config.NODE_ENV', configEnv)
|
|
57
|
-
```
|
|
58
|
-
```js
|
|
59
|
-
resolve:{
|
|
60
|
-
alias:{
|
|
61
|
-
'@/': `${path.resolve(__dirname, 'src')}/`,
|
|
62
|
-
'local-config': `${path.join(__dirname, `./src/config/${configEnv}.json`)}`
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
```
|
|
1
|
+
[](https://opensource.org/licenses/MIT)
|
|
2
|
+
|
|
3
|
+
# library_client_svelte
|
|
4
|
+
|
|
5
|
+
## Requirements
|
|
6
|
+
|
|
7
|
+
### NodeJs
|
|
8
|
+
|
|
9
|
+
[NodeJs](https://nodejs.org) version 18+
|
|
10
|
+
|
|
11
|
+
### Svelte Application
|
|
12
|
+
|
|
13
|
+
npm create vite@latest myapp -- --template svelte
|
|
14
|
+
cd myapp
|
|
15
|
+
npm install
|
|
16
|
+
npm run dev
|
|
17
|
+
|
|
18
|
+
### Installation
|
|
19
|
+
|
|
20
|
+
[](https://npmjs.org/package/@thzero/library_client_svelte)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
```js
|
|
24
|
+
// store.js
|
|
25
|
+
// An extremely simple external store
|
|
26
|
+
import { writable } from 'svelte/store'
|
|
27
|
+
export default writable(0)
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
jsconfig.json
|
|
31
|
+
```js
|
|
32
|
+
"baseUrl": ".",
|
|
33
|
+
"paths": {
|
|
34
|
+
"@/*": ["src/*"]
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
vite.config.js
|
|
39
|
+
```js
|
|
40
|
+
import path from 'path'
|
|
41
|
+
```
|
|
42
|
+
```js
|
|
43
|
+
let configEnv = process.env.NODE_ENV
|
|
44
|
+
console.log('svelte.config.NODE_ENV', configEnv)
|
|
45
|
+
const config = process.env._CONFIG
|
|
46
|
+
console.log('svelte.config._CONFIG', config)
|
|
47
|
+
if (config) {
|
|
48
|
+
const filename = path.join(__dirname, `./src/config/${configEnv}.json`)
|
|
49
|
+
console.log('svelte.config.filename', filename)
|
|
50
|
+
fs.writeFileSync(filename, config)
|
|
51
|
+
const contents = fs.readFileSync(filename, 'utf8')
|
|
52
|
+
console.log('svelte.config.file', contents)
|
|
53
|
+
}
|
|
54
|
+
else
|
|
55
|
+
configEnv = 'development'
|
|
56
|
+
console.log('svelte.config.NODE_ENV', configEnv)
|
|
57
|
+
```
|
|
58
|
+
```js
|
|
59
|
+
resolve:{
|
|
60
|
+
alias:{
|
|
61
|
+
'@/': `${path.resolve(__dirname, 'src')}/`,
|
|
62
|
+
'local-config': `${path.join(__dirname, `./src/config/${configEnv}.json`)}`
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
```
|
package/boot/baseServices.js
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import LibraryClientUtility from '@thzero/library_client/utility/index';
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
import eventService from '../service/event';
|
|
6
|
-
import routerService from '../service/router';
|
|
7
|
-
import storeService from '../service/store';
|
|
8
|
-
import translateService from '../service/translate';
|
|
9
|
-
|
|
10
|
-
class
|
|
11
|
-
_initializeInjector(framework, injector) {
|
|
12
|
-
LibraryClientUtility.$injector = injector;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
_initializeEvent(injector) {
|
|
16
|
-
return new eventService();
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
_initializeRouter(injector) {
|
|
20
|
-
return new routerService();
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
_initializeStore(injector) {
|
|
24
|
-
return new storeService();
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
_initializeTranslate(injector) {
|
|
28
|
-
return new translateService();
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export default
|
|
1
|
+
import LibraryClientUtility from '@thzero/library_client/utility/index';
|
|
2
|
+
|
|
3
|
+
import RootServicesBaseBoot from '@thzero/library_client/boot/rootServices';
|
|
4
|
+
|
|
5
|
+
import eventService from '../service/event';
|
|
6
|
+
import routerService from '../service/router';
|
|
7
|
+
import storeService from '../service/store';
|
|
8
|
+
import translateService from '../service/translate';
|
|
9
|
+
|
|
10
|
+
class SveleteRootServicesBaseBoot extends RootServicesBaseBoot {
|
|
11
|
+
_initializeInjector(framework, injector) {
|
|
12
|
+
LibraryClientUtility.$injector = injector;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
_initializeEvent(injector) {
|
|
16
|
+
return new eventService();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
_initializeRouter(injector) {
|
|
20
|
+
return new routerService();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
_initializeStore(injector) {
|
|
24
|
+
return new storeService();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
_initializeTranslate(injector) {
|
|
28
|
+
return new translateService();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export default SveleteRootServicesBaseBoot;
|
package/boot/baseValidation.js
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
import BaseBoot from '@thzero/library_client/boot/base';
|
|
2
|
-
|
|
3
|
-
class ValidateBaseBoot extends BaseBoot {
|
|
4
|
-
// eslint-disable-next-line
|
|
5
|
-
async execute(framework, app, store) {
|
|
6
|
-
// extend('decimal', {
|
|
7
|
-
// validate: (value, { decimals = '*', separator = '.' } = {}) => {
|
|
8
|
-
// if (value === null || value === undefined || value === '') {
|
|
9
|
-
// return {
|
|
10
|
-
// valid: false
|
|
11
|
-
// };
|
|
12
|
-
// }
|
|
13
|
-
// if (Number(decimals) === 0) {
|
|
14
|
-
// return {
|
|
15
|
-
// valid: /^-?\d*$/.test(value)
|
|
16
|
-
// };
|
|
17
|
-
// }
|
|
18
|
-
// const regexPart = decimals === '*' ? '+' : `{1,${decimals}}`;
|
|
19
|
-
// const regex = new RegExp(`^[-+]?\\d*(\\${separator}\\d${regexPart})?([eE]{1}[-]?\\d+)?$`);
|
|
20
|
-
// return {
|
|
21
|
-
// valid: regex.test(value),
|
|
22
|
-
// data: {
|
|
23
|
-
// serverMessage: 'Only decimal values are available'
|
|
24
|
-
// }
|
|
25
|
-
// };
|
|
26
|
-
// },
|
|
27
|
-
// message: '{serverMessage}'
|
|
28
|
-
// });
|
|
29
|
-
|
|
30
|
-
// extend('name', {
|
|
31
|
-
// getMessage: field => 'The ' + field + ' field may only contain alphanumeric and space characters',
|
|
32
|
-
// // eslint-disable-next-line
|
|
33
|
-
// validate(value, args) {
|
|
34
|
-
// const regEx = /^[a-zA-Z0-9]+(['\-a-zA-Z0-9 ]*)*$/;
|
|
35
|
-
// return regEx.test(value);
|
|
36
|
-
// }
|
|
37
|
-
// });
|
|
38
|
-
|
|
39
|
-
// extend('tagLine', {
|
|
40
|
-
// getMessage: field => 'The ' + field + ' field may only contain alphanumeric, space, and punctuation characters',
|
|
41
|
-
// // eslint-disable-next-line
|
|
42
|
-
// validate(value, args) {
|
|
43
|
-
// const regEx = /^[a-zA-Z0-9]+([',.!& \-a-zA-Z0-9 ]*)*$/;
|
|
44
|
-
// return regEx.test(value);
|
|
45
|
-
// }
|
|
46
|
-
// });
|
|
47
|
-
|
|
48
|
-
this._initialize();
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// eslint-disable-next-line
|
|
52
|
-
_initialize(extend) {
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export default ValidateBaseBoot;
|
|
1
|
+
import BaseBoot from '@thzero/library_client/boot/base';
|
|
2
|
+
|
|
3
|
+
class ValidateBaseBoot extends BaseBoot {
|
|
4
|
+
// eslint-disable-next-line
|
|
5
|
+
async execute(framework, app, store) {
|
|
6
|
+
// extend('decimal', {
|
|
7
|
+
// validate: (value, { decimals = '*', separator = '.' } = {}) => {
|
|
8
|
+
// if (value === null || value === undefined || value === '') {
|
|
9
|
+
// return {
|
|
10
|
+
// valid: false
|
|
11
|
+
// };
|
|
12
|
+
// }
|
|
13
|
+
// if (Number(decimals) === 0) {
|
|
14
|
+
// return {
|
|
15
|
+
// valid: /^-?\d*$/.test(value)
|
|
16
|
+
// };
|
|
17
|
+
// }
|
|
18
|
+
// const regexPart = decimals === '*' ? '+' : `{1,${decimals}}`;
|
|
19
|
+
// const regex = new RegExp(`^[-+]?\\d*(\\${separator}\\d${regexPart})?([eE]{1}[-]?\\d+)?$`);
|
|
20
|
+
// return {
|
|
21
|
+
// valid: regex.test(value),
|
|
22
|
+
// data: {
|
|
23
|
+
// serverMessage: 'Only decimal values are available'
|
|
24
|
+
// }
|
|
25
|
+
// };
|
|
26
|
+
// },
|
|
27
|
+
// message: '{serverMessage}'
|
|
28
|
+
// });
|
|
29
|
+
|
|
30
|
+
// extend('name', {
|
|
31
|
+
// getMessage: field => 'The ' + field + ' field may only contain alphanumeric and space characters',
|
|
32
|
+
// // eslint-disable-next-line
|
|
33
|
+
// validate(value, args) {
|
|
34
|
+
// const regEx = /^[a-zA-Z0-9]+(['\-a-zA-Z0-9 ]*)*$/;
|
|
35
|
+
// return regEx.test(value);
|
|
36
|
+
// }
|
|
37
|
+
// });
|
|
38
|
+
|
|
39
|
+
// extend('tagLine', {
|
|
40
|
+
// getMessage: field => 'The ' + field + ' field may only contain alphanumeric, space, and punctuation characters',
|
|
41
|
+
// // eslint-disable-next-line
|
|
42
|
+
// validate(value, args) {
|
|
43
|
+
// const regEx = /^[a-zA-Z0-9]+([',.!& \-a-zA-Z0-9 ]*)*$/;
|
|
44
|
+
// return regEx.test(value);
|
|
45
|
+
// }
|
|
46
|
+
// });
|
|
47
|
+
|
|
48
|
+
this._initialize();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// eslint-disable-next-line
|
|
52
|
+
_initialize(extend) {
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export default ValidateBaseBoot;
|
package/boot/basei18n.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { init, getLocaleFromNavigator, register, format, addMessages, unwrapFunctionStore } from 'svelte-i18n';
|
|
2
|
-
|
|
3
|
-
import LibraryClientUtility from '@thzero/library_client/utility/index';
|
|
4
|
-
|
|
5
|
-
import i18nBaseBoot from '@thzero/library_client/boot/basei18n';
|
|
6
|
-
|
|
7
|
-
import NotImplementedError from '@thzero/library_common/errors/notImplemented';
|
|
8
|
-
|
|
9
|
-
class Sveltei18nBaseBoot extends i18nBaseBoot {
|
|
10
|
-
// eslint-disable-next-line
|
|
11
|
-
async execute(framework, app, store) {
|
|
12
|
-
this._initMessages(register, addMessages);
|
|
13
|
-
|
|
14
|
-
init({
|
|
15
|
-
fallbackLocale: 'en',
|
|
16
|
-
initialLocale: getLocaleFromNavigator()
|
|
17
|
-
});
|
|
18
|
-
LibraryClientUtility.$trans = { t: unwrapFunctionStore(format) };
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
_initMessages(register) {
|
|
22
|
-
throw new NotImplementedError();
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export default Sveltei18nBaseBoot;
|
|
1
|
+
import { init, getLocaleFromNavigator, register, format, addMessages, unwrapFunctionStore } from 'svelte-i18n';
|
|
2
|
+
|
|
3
|
+
import LibraryClientUtility from '@thzero/library_client/utility/index';
|
|
4
|
+
|
|
5
|
+
import i18nBaseBoot from '@thzero/library_client/boot/basei18n';
|
|
6
|
+
|
|
7
|
+
import NotImplementedError from '@thzero/library_common/errors/notImplemented';
|
|
8
|
+
|
|
9
|
+
class Sveltei18nBaseBoot extends i18nBaseBoot {
|
|
10
|
+
// eslint-disable-next-line
|
|
11
|
+
async execute(framework, app, store) {
|
|
12
|
+
this._initMessages(register, addMessages);
|
|
13
|
+
|
|
14
|
+
init({
|
|
15
|
+
fallbackLocale: 'en',
|
|
16
|
+
initialLocale: getLocaleFromNavigator()
|
|
17
|
+
});
|
|
18
|
+
LibraryClientUtility.$trans = { t: unwrapFunctionStore(format) };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
_initMessages(register) {
|
|
22
|
+
throw new NotImplementedError();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default Sveltei18nBaseBoot;
|
package/boot/eventBus.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import mitt from 'mitt';
|
|
2
|
-
|
|
3
|
-
import LibraryClientUtility from '@thzero/library_client/utility/index';
|
|
4
|
-
|
|
5
|
-
const EventBus = mitt();
|
|
6
|
-
|
|
7
|
-
export default async () => {
|
|
8
|
-
LibraryClientUtility.$EventBus = EventBus;
|
|
9
|
-
};
|
|
1
|
+
import mitt from 'mitt';
|
|
2
|
+
|
|
3
|
+
import LibraryClientUtility from '@thzero/library_client/utility/index';
|
|
4
|
+
|
|
5
|
+
const EventBus = mitt();
|
|
6
|
+
|
|
7
|
+
export default async () => {
|
|
8
|
+
LibraryClientUtility.$EventBus = EventBus;
|
|
9
|
+
};
|
package/boot/main.js
CHANGED
|
@@ -1,90 +1,104 @@
|
|
|
1
|
-
import LibraryClientUtility from '@thzero/library_client/utility/index';
|
|
2
|
-
|
|
3
|
-
// @ts-ignore
|
|
4
|
-
import {} from '@thzero/library_common/utility/string';
|
|
5
|
-
|
|
6
|
-
// eslint-disable-next-line
|
|
7
|
-
async function start(app, storeRequest, bootFiles, starter) {
|
|
8
|
-
let store = null;
|
|
9
|
-
if (storeRequest) {
|
|
10
|
-
try {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
1
|
+
import LibraryClientUtility from '@thzero/library_client/utility/index';
|
|
2
|
+
|
|
3
|
+
// @ts-ignore
|
|
4
|
+
import {} from '@thzero/library_common/utility/string';
|
|
5
|
+
|
|
6
|
+
// eslint-disable-next-line
|
|
7
|
+
async function start(app, storeRequest, bootFiles, starter, options) {
|
|
8
|
+
let store = null;
|
|
9
|
+
if (storeRequest) {
|
|
10
|
+
try {
|
|
11
|
+
const temp = new storeRequest();
|
|
12
|
+
store = temp.initialize();
|
|
13
|
+
}
|
|
14
|
+
catch (err) {
|
|
15
|
+
console.log(err);
|
|
16
|
+
throw Error('Unable to create store.');
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (!store)
|
|
21
|
+
throw Error('Unable to create store.');
|
|
22
|
+
LibraryClientUtility.$store = store;
|
|
23
|
+
|
|
24
|
+
if (options) {
|
|
25
|
+
if (options.idGenerator) {
|
|
26
|
+
if (options.idGenerator.override)
|
|
27
|
+
LibraryCommonUtility.setIdGenerator(options.idGenerator.override);
|
|
28
|
+
if (options.idGenerator.alphabet)
|
|
29
|
+
LibraryCommonUtility.setIdGeneratorAlphabet(options.idGenerator.alphabet);
|
|
30
|
+
if (options.idGenerator.lengthLong)
|
|
31
|
+
LibraryCommonUtility.setIdGeneratorLengthLong(options.idGenerator.lengthLong);
|
|
32
|
+
if (options.idGenerator.lengthShort)
|
|
33
|
+
LibraryCommonUtility.setIdGeneratorLengthShort(options.idGenerator.lengthShort);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (bootFiles && (bootFiles.length > 0)) {
|
|
38
|
+
let obj;
|
|
39
|
+
for (const bootFile of bootFiles) {
|
|
40
|
+
if (typeof bootFile !== 'function')
|
|
41
|
+
continue;
|
|
42
|
+
|
|
43
|
+
try {
|
|
44
|
+
try {
|
|
45
|
+
await bootFile({
|
|
46
|
+
store
|
|
47
|
+
});
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
obj = new bootFile();
|
|
52
|
+
await obj.execute(
|
|
53
|
+
store
|
|
54
|
+
);
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
catch (err) {
|
|
59
|
+
if (err && err.url) {
|
|
60
|
+
window.location.href = err.url;
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// eslint-disable-next-line
|
|
65
|
+
console.error('boot error:', err);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (!starter) {
|
|
72
|
+
if (app)
|
|
73
|
+
new app({ target: document.getElementById('app') });
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
try {
|
|
78
|
+
const result = starter({
|
|
79
|
+
store
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
result
|
|
83
|
+
// eslint-disable-next-line
|
|
84
|
+
.then(values => {
|
|
85
|
+
if (app)
|
|
86
|
+
new app({ target: document.getElementById('app') });
|
|
87
|
+
})
|
|
88
|
+
.catch(err => {
|
|
89
|
+
// eslint-disable-next-line
|
|
90
|
+
console.error('boot error:', err);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
catch (err) {
|
|
94
|
+
if (err && err.url) {
|
|
95
|
+
window.location.href = err.url;
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// eslint-disable-next-line
|
|
100
|
+
console.error('boot error:', err);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export default start;
|
package/boot/webcomponent.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import startMain from './main';
|
|
2
|
-
|
|
3
|
-
async function start(storeRequest, bootFiles, starter) {
|
|
4
|
-
await startMain(null, null, storeRequest, bootFiles, starter);
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export default start;
|
|
1
|
+
import startMain from './main';
|
|
2
|
+
|
|
3
|
+
async function start(storeRequest, bootFiles, starter) {
|
|
4
|
+
await startMain(null, null, storeRequest, bootFiles, starter);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export default start;
|
package/constants.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
const Constants = {
|
|
2
|
-
ErrorCodes: {
|
|
3
|
-
Suffix: 'errors',
|
|
4
|
-
SuffixParams: 'errors.params',
|
|
5
|
-
Default: 'error'
|
|
6
|
-
}
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export default Constants;
|
|
1
|
+
const Constants = {
|
|
2
|
+
ErrorCodes: {
|
|
3
|
+
Suffix: 'errors',
|
|
4
|
+
SuffixParams: 'errors.params',
|
|
5
|
+
Default: 'error'
|
|
6
|
+
}
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export default Constants;
|
package/license.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2021-
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
-
|
|
7
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
-
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021-2024 thZero.com
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
9
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/openSource.js
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
export default () => {
|
|
2
|
-
return [
|
|
3
|
-
{
|
|
4
|
-
category: 'client',
|
|
5
|
-
name: '@thzero/library_client',
|
|
6
|
-
url: 'https://github.com/thzero/library_client',
|
|
7
|
-
licenseName: 'MIT',
|
|
8
|
-
licenseUrl: 'https://github.com/thzero/library_client/blob/master/license.md'
|
|
9
|
-
},
|
|
10
|
-
{
|
|
11
|
-
category: 'client',
|
|
12
|
-
name: '@thzero/library_client_svelte',
|
|
13
|
-
url: 'https://github.com/thzero/library_client_svelte',
|
|
14
|
-
licenseName: 'MIT',
|
|
15
|
-
licenseUrl: 'https://github.com/thzero/library_client_svelte/blob/master/license.md'
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
category: 'client',
|
|
19
|
-
name: '@thzero/library_common',
|
|
20
|
-
url: 'https://github.com/thzero/library_common',
|
|
21
|
-
licenseName: 'MIT',
|
|
22
|
-
licenseUrl: 'https://github.com/thzero/library_common/blob/master/license.md'
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
category: 'client',
|
|
26
|
-
name: 'svelte',
|
|
27
|
-
url: 'https://github.com/sveltejs',
|
|
28
|
-
licenseName: 'MIT',
|
|
29
|
-
licenseUrl: 'https://github.com/sveltejs/svelte/blob/main/LICENSE.md'
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
category: 'client',
|
|
33
|
-
name: 'svelte-i18n',
|
|
34
|
-
url: 'https://github.com/kaisermann/svelte-i18n',
|
|
35
|
-
licenseName: 'MIT',
|
|
36
|
-
licenseUrl: 'https://github.com/kaisermann/svelte-i18n/blob/main/LICENSE'
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
category: 'client',
|
|
40
|
-
name: 'svelte-spa-router',
|
|
41
|
-
url: 'https://github.com/ItalyPaleAle/svelte-spa-router',
|
|
42
|
-
licenseName: 'MIT',
|
|
43
|
-
licenseUrl: 'https://github.com/ItalyPaleAle/svelte-spa-router/blob/main/LICENSE.md'
|
|
44
|
-
}
|
|
45
|
-
];
|
|
1
|
+
export default () => {
|
|
2
|
+
return [
|
|
3
|
+
{
|
|
4
|
+
category: 'client',
|
|
5
|
+
name: '@thzero/library_client',
|
|
6
|
+
url: 'https://github.com/thzero/library_client',
|
|
7
|
+
licenseName: 'MIT',
|
|
8
|
+
licenseUrl: 'https://github.com/thzero/library_client/blob/master/license.md'
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
category: 'client',
|
|
12
|
+
name: '@thzero/library_client_svelte',
|
|
13
|
+
url: 'https://github.com/thzero/library_client_svelte',
|
|
14
|
+
licenseName: 'MIT',
|
|
15
|
+
licenseUrl: 'https://github.com/thzero/library_client_svelte/blob/master/license.md'
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
category: 'client',
|
|
19
|
+
name: '@thzero/library_common',
|
|
20
|
+
url: 'https://github.com/thzero/library_common',
|
|
21
|
+
licenseName: 'MIT',
|
|
22
|
+
licenseUrl: 'https://github.com/thzero/library_common/blob/master/license.md'
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
category: 'client',
|
|
26
|
+
name: 'svelte',
|
|
27
|
+
url: 'https://github.com/sveltejs',
|
|
28
|
+
licenseName: 'MIT',
|
|
29
|
+
licenseUrl: 'https://github.com/sveltejs/svelte/blob/main/LICENSE.md'
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
category: 'client',
|
|
33
|
+
name: 'svelte-i18n',
|
|
34
|
+
url: 'https://github.com/kaisermann/svelte-i18n',
|
|
35
|
+
licenseName: 'MIT',
|
|
36
|
+
licenseUrl: 'https://github.com/kaisermann/svelte-i18n/blob/main/LICENSE'
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
category: 'client',
|
|
40
|
+
name: 'svelte-spa-router',
|
|
41
|
+
url: 'https://github.com/ItalyPaleAle/svelte-spa-router',
|
|
42
|
+
licenseName: 'MIT',
|
|
43
|
+
licenseUrl: 'https://github.com/ItalyPaleAle/svelte-spa-router/blob/main/LICENSE.md'
|
|
44
|
+
}
|
|
45
|
+
];
|
|
46
46
|
}
|
package/package.json
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@thzero/library_client_svelte",
|
|
3
|
-
"version": "0.17.
|
|
4
|
-
"version_major": 0,
|
|
5
|
-
"version_minor": 17,
|
|
6
|
-
"version_patch":
|
|
7
|
-
"version_date": "
|
|
8
|
-
"description": "An opinionated library of common functionality to bootstrap a Svelte based SPA application.",
|
|
9
|
-
"author": "thZero",
|
|
10
|
-
"license": "MIT",
|
|
11
|
-
"repository": {
|
|
12
|
-
"type": "git",
|
|
13
|
-
"url": "git+https://github.com/thzero/library_client_svelte.git"
|
|
14
|
-
},
|
|
15
|
-
"bugs": {
|
|
16
|
-
"url": "https://github.com/thzero/library_client_svelte/issues"
|
|
17
|
-
},
|
|
18
|
-
"homepage": "https://github.com/thzero/library_client_svelte#readme",
|
|
19
|
-
"scripts": {
|
|
20
|
-
"cli-update": "library-cli --updateversion --pi",
|
|
21
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
22
|
-
},
|
|
23
|
-
"dependencies": {
|
|
24
|
-
"@thzero/library_client": "^0.17",
|
|
25
|
-
"@thzero/library_common": "^0.17",
|
|
26
|
-
"mitt": "^3.0.1",
|
|
27
|
-
"svelte-i18n": "^4.0.0",
|
|
28
|
-
"svelte-spa-router": "^4.0.0"
|
|
29
|
-
},
|
|
30
|
-
"peerDependencies": {
|
|
31
|
-
"svelte": "^
|
|
32
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@thzero/library_client_svelte",
|
|
3
|
+
"version": "0.17.9",
|
|
4
|
+
"version_major": 0,
|
|
5
|
+
"version_minor": 17,
|
|
6
|
+
"version_patch": 9,
|
|
7
|
+
"version_date": "01/01/2024",
|
|
8
|
+
"description": "An opinionated library of common functionality to bootstrap a Svelte based SPA application.",
|
|
9
|
+
"author": "thZero",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/thzero/library_client_svelte.git"
|
|
14
|
+
},
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/thzero/library_client_svelte/issues"
|
|
17
|
+
},
|
|
18
|
+
"homepage": "https://github.com/thzero/library_client_svelte#readme",
|
|
19
|
+
"scripts": {
|
|
20
|
+
"cli-update": "library-cli --updateversion --pi",
|
|
21
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@thzero/library_client": "^0.17",
|
|
25
|
+
"@thzero/library_common": "^0.17",
|
|
26
|
+
"mitt": "^3.0.1",
|
|
27
|
+
"svelte-i18n": "^4.0.0",
|
|
28
|
+
"svelte-spa-router": "^4.0.0"
|
|
29
|
+
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"svelte": "^4"
|
|
32
|
+
}
|
|
33
33
|
}
|
package/service/baseUser.js
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
import LibraryClientConstants from '@thzero/library_client/constants';
|
|
2
|
-
|
|
3
|
-
import BaseUserService from '@thzero/library_client/service/baseUser';
|
|
4
|
-
|
|
5
|
-
class
|
|
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(LibraryClientConstants.InjectorKeys.SERVICE_STORE);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
async resetUser(correlationId) {
|
|
19
|
-
await this._serviceStore.
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
async setAuthCompleted(correlationId) {
|
|
23
|
-
await this._serviceStore.
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
async setClaims(correlationId, claims) {
|
|
27
|
-
await this._serviceStore.
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
async setLoggedIn(correlationId, value) {
|
|
31
|
-
await this._serviceStore.
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
async setTokenResult(correlationId, tokenResult) {
|
|
35
|
-
await this._serviceStore.
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
async setUser(correlationId, user) {
|
|
39
|
-
await this._serviceStore.
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
get token() {
|
|
43
|
-
if (this._serviceStore.
|
|
44
|
-
return this._serviceStore.
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export default
|
|
1
|
+
import LibraryClientConstants from '@thzero/library_client/constants';
|
|
2
|
+
|
|
3
|
+
import BaseUserService from '@thzero/library_client/service/baseUser';
|
|
4
|
+
|
|
5
|
+
class SvelteBaseUserService 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(LibraryClientConstants.InjectorKeys.SERVICE_STORE);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async resetUser(correlationId) {
|
|
19
|
+
await this._serviceStore.store.user.dispatcher.resetUser(correlationId);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async setAuthCompleted(correlationId) {
|
|
23
|
+
await this._serviceStore.store.user.dispatcher.setAuthCompleted(correlationId, true);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async setClaims(correlationId, claims) {
|
|
27
|
+
await this._serviceStore.store.user.dispatcher.setClaims(correlationId, claims);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async setLoggedIn(correlationId, value) {
|
|
31
|
+
await this._serviceStore.store.user.dispatcher.setLoggedIn(correlationId, value);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async setTokenResult(correlationId, tokenResult) {
|
|
35
|
+
await this._serviceStore.store.user.dispatcher.setTokenResult(correlationId, tokenResult);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async setUser(correlationId, user) {
|
|
39
|
+
await this._serviceStore.store.user.dispatcher.setUser(correlationId, user);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
get token() {
|
|
43
|
+
if (this._serviceStore.store.user)
|
|
44
|
+
return this._serviceStore.store.user.token;
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export default SvelteBaseUserService;
|
package/service/event.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import LibraryClientUtility from '@thzero/library_client/utility/index';
|
|
2
|
-
|
|
3
|
-
import EventService from '@thzero/library_client/service/event';
|
|
4
|
-
|
|
5
|
-
class SvelteEventService extends EventService {
|
|
6
|
-
// eslint-disable-next-line
|
|
7
|
-
emit(channel, value) {
|
|
8
|
-
LibraryClientUtility.$EventBus.emit(channel, value);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export default SvelteEventService;
|
|
1
|
+
import LibraryClientUtility from '@thzero/library_client/utility/index';
|
|
2
|
+
|
|
3
|
+
import EventService from '@thzero/library_client/service/event';
|
|
4
|
+
|
|
5
|
+
class SvelteEventService extends EventService {
|
|
6
|
+
// eslint-disable-next-line
|
|
7
|
+
emit(channel, value) {
|
|
8
|
+
LibraryClientUtility.$EventBus.emit(channel, value);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default SvelteEventService;
|
package/service/router.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import RouterService from '@thzero/library_client/service/router';
|
|
4
|
-
|
|
5
|
-
class SvelteRouterService extends RouterService {
|
|
6
|
-
// eslint-disable-next-line
|
|
7
|
-
route(path, options) {
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export default SvelteRouterService;
|
|
1
|
+
import { push } from 'svelte-spa-router';
|
|
2
|
+
|
|
3
|
+
import RouterService from '@thzero/library_client/service/router';
|
|
4
|
+
|
|
5
|
+
class SvelteRouterService extends RouterService {
|
|
6
|
+
// eslint-disable-next-line
|
|
7
|
+
route(path, options) {
|
|
8
|
+
push(path);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default SvelteRouterService;
|
package/service/store.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import LibraryClientUtility from '@thzero/library_client/utility/index';
|
|
2
|
-
|
|
3
|
-
import Service from '@thzero/library_client/service/index';
|
|
4
|
-
|
|
5
|
-
class SvelteStoreService extends Service {
|
|
6
|
-
get store() {
|
|
7
|
-
return LibraryClientUtility.$store;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export default SvelteStoreService;
|
|
1
|
+
import LibraryClientUtility from '@thzero/library_client/utility/index';
|
|
2
|
+
|
|
3
|
+
import Service from '@thzero/library_client/service/index';
|
|
4
|
+
|
|
5
|
+
class SvelteStoreService extends Service {
|
|
6
|
+
get store() {
|
|
7
|
+
return LibraryClientUtility.$store;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default SvelteStoreService;
|
package/service/translate.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import LibraryClientUtility from '@thzero/library_client/utility/index';
|
|
2
|
-
|
|
3
|
-
import TranslateService from '@thzero/library_client/service/translate';
|
|
4
|
-
|
|
5
|
-
class SvelteTranslateService extends TranslateService {
|
|
6
|
-
// eslint-disable-next-line
|
|
7
|
-
translate(correlationId, id) {
|
|
8
|
-
return LibraryClientUtility.$trans.t(id);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export default SvelteTranslateService;
|
|
1
|
+
import LibraryClientUtility from '@thzero/library_client/utility/index';
|
|
2
|
+
|
|
3
|
+
import TranslateService from '@thzero/library_client/service/translate';
|
|
4
|
+
|
|
5
|
+
class SvelteTranslateService extends TranslateService {
|
|
6
|
+
// eslint-disable-next-line
|
|
7
|
+
translate(correlationId, id) {
|
|
8
|
+
return LibraryClientUtility.$trans.t(id);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default SvelteTranslateService;
|
package/utility/index.js
CHANGED
|
@@ -1,77 +1,77 @@
|
|
|
1
|
-
import Constants from '../constants';
|
|
2
|
-
import LibraryCommonConstants from '@thzero/library_common/constants';
|
|
3
|
-
|
|
4
|
-
import LibraryClientUtility from '@thzero/library_client/utility/index';
|
|
5
|
-
|
|
6
|
-
class Utility {
|
|
7
|
-
static applyError(error, messageParams) {
|
|
8
|
-
if (!error)
|
|
9
|
-
return null;
|
|
10
|
-
|
|
11
|
-
if (!error.code && !String.isNullOrEmpty(error.message)) {
|
|
12
|
-
return {
|
|
13
|
-
message: error.message,
|
|
14
|
-
field: (error.field ? error.field : LibraryCommonConstants.ErrorFields.Generic)
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
let messageCode = error.code;
|
|
19
|
-
if (error.type)
|
|
20
|
-
messageCode = `${messageCode}.${error.type}`;
|
|
21
|
-
if (error.prefix)
|
|
22
|
-
messageCode = `${error.prefix}.${messageCode}`;
|
|
23
|
-
messageParams = { ...messageParams, ...error.params };
|
|
24
|
-
|
|
25
|
-
let param;
|
|
26
|
-
for (const field in messageParams) {
|
|
27
|
-
param = messageParams[field];
|
|
28
|
-
if (param.il8n) {
|
|
29
|
-
let suffix = param.suffix;
|
|
30
|
-
if (String.isNullOrEmpty(suffix))
|
|
31
|
-
suffix = Constants.ErrorCodes.SuffixParams;
|
|
32
|
-
param.value = LibraryClientUtility.$trans.t(`${suffix}.${param.value}`);
|
|
33
|
-
}
|
|
34
|
-
messageParams[field] = param.value;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (String.isNullOrEmpty(messageCode))
|
|
38
|
-
messageCode = Constants.ErrorCodes.Default;
|
|
39
|
-
|
|
40
|
-
return {
|
|
41
|
-
message: LibraryClientUtility.$trans.t(`${Constants.ErrorCodes.Suffix}.${messageCode}`, messageParams),
|
|
42
|
-
field: (error.field ? error.field : LibraryCommonConstants.ErrorFields.Generic)
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
static handleError(object, serverErrors, response) {
|
|
47
|
-
if (!object || !serverErrors || !response)
|
|
48
|
-
return;
|
|
49
|
-
|
|
50
|
-
const errors = {};
|
|
51
|
-
let error;
|
|
52
|
-
for (const field in response.errors) {
|
|
53
|
-
error = Utility.applyError(response.errors[field]);
|
|
54
|
-
if (error.field === LibraryCommonConstants.ErrorFields.Generic) {
|
|
55
|
-
serverErrors.push(error.message);
|
|
56
|
-
continue;
|
|
57
|
-
}
|
|
58
|
-
// eslint-disable-next-line
|
|
59
|
-
if (!errors.hasOwnProperty(error.field))
|
|
60
|
-
errors[error.field] = [];
|
|
61
|
-
errors[error.field].push(error.message);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
object.setErrors(errors);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
static invalid(next) {
|
|
68
|
-
if (next) {
|
|
69
|
-
next('/');
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
LibraryClientUtility.$navRouter.push('/');
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export default Utility;
|
|
1
|
+
import Constants from '../constants';
|
|
2
|
+
import LibraryCommonConstants from '@thzero/library_common/constants';
|
|
3
|
+
|
|
4
|
+
import LibraryClientUtility from '@thzero/library_client/utility/index';
|
|
5
|
+
|
|
6
|
+
class Utility {
|
|
7
|
+
static applyError(error, messageParams) {
|
|
8
|
+
if (!error)
|
|
9
|
+
return null;
|
|
10
|
+
|
|
11
|
+
if (!error.code && !String.isNullOrEmpty(error.message)) {
|
|
12
|
+
return {
|
|
13
|
+
message: error.message,
|
|
14
|
+
field: (error.field ? error.field : LibraryCommonConstants.ErrorFields.Generic)
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
let messageCode = error.code;
|
|
19
|
+
if (error.type)
|
|
20
|
+
messageCode = `${messageCode}.${error.type}`;
|
|
21
|
+
if (error.prefix)
|
|
22
|
+
messageCode = `${error.prefix}.${messageCode}`;
|
|
23
|
+
messageParams = { ...messageParams, ...error.params };
|
|
24
|
+
|
|
25
|
+
let param;
|
|
26
|
+
for (const field in messageParams) {
|
|
27
|
+
param = messageParams[field];
|
|
28
|
+
if (param.il8n) {
|
|
29
|
+
let suffix = param.suffix;
|
|
30
|
+
if (String.isNullOrEmpty(suffix))
|
|
31
|
+
suffix = Constants.ErrorCodes.SuffixParams;
|
|
32
|
+
param.value = LibraryClientUtility.$trans.t(`${suffix}.${param.value}`);
|
|
33
|
+
}
|
|
34
|
+
messageParams[field] = param.value;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (String.isNullOrEmpty(messageCode))
|
|
38
|
+
messageCode = Constants.ErrorCodes.Default;
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
message: LibraryClientUtility.$trans.t(`${Constants.ErrorCodes.Suffix}.${messageCode}`, messageParams),
|
|
42
|
+
field: (error.field ? error.field : LibraryCommonConstants.ErrorFields.Generic)
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
static handleError(object, serverErrors, response) {
|
|
47
|
+
if (!object || !serverErrors || !response)
|
|
48
|
+
return;
|
|
49
|
+
|
|
50
|
+
const errors = {};
|
|
51
|
+
let error;
|
|
52
|
+
for (const field in response.errors) {
|
|
53
|
+
error = Utility.applyError(response.errors[field]);
|
|
54
|
+
if (error.field === LibraryCommonConstants.ErrorFields.Generic) {
|
|
55
|
+
serverErrors.push(error.message);
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
// eslint-disable-next-line
|
|
59
|
+
if (!errors.hasOwnProperty(error.field))
|
|
60
|
+
errors[error.field] = [];
|
|
61
|
+
errors[error.field].push(error.message);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
object.setErrors(errors);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
static invalid(next) {
|
|
68
|
+
if (next) {
|
|
69
|
+
next('/');
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
LibraryClientUtility.$navRouter.push('/');
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export default Utility;
|