@thzero/library_client_svelte 0.15.6 → 0.15.8
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 +53 -0
- package/boot/baseValidation.js +54 -0
- package/boot/main.js +2 -2
- package/package.json +6 -10
- package/service/baseUser.js +49 -0
package/README.md
CHANGED
|
@@ -1,12 +1,65 @@
|
|
|
1
1
|
[](https://opensource.org/licenses/MIT)
|
|
2
2
|
|
|
3
3
|
# library_client_svelte
|
|
4
|
+
|
|
4
5
|
## Requirements
|
|
5
6
|
|
|
6
7
|
### NodeJs
|
|
7
8
|
|
|
8
9
|
[NodeJs](https://nodejs.org) version 18+
|
|
9
10
|
|
|
11
|
+
### Svelte Application
|
|
12
|
+
|
|
13
|
+
npm create vite@latest myapp -- --template svelte
|
|
14
|
+
cd myapp
|
|
15
|
+
npm install
|
|
16
|
+
npm run dev
|
|
17
|
+
|
|
10
18
|
### Installation
|
|
11
19
|
|
|
12
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
|
+
```
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
class BaseValidate {
|
|
2
|
+
// eslint-disable-next-line
|
|
3
|
+
async execute(Vue, app, router) {
|
|
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/main.js
CHANGED
|
@@ -59,7 +59,7 @@ async function start(app, router, storeRequest, bootFiles, starter) {
|
|
|
59
59
|
|
|
60
60
|
if (!starter) {
|
|
61
61
|
if (app)
|
|
62
|
-
new app({ target: document.
|
|
62
|
+
new app({ target: document.getElementById('app') });
|
|
63
63
|
return;
|
|
64
64
|
}
|
|
65
65
|
|
|
@@ -73,7 +73,7 @@ async function start(app, router, storeRequest, bootFiles, starter) {
|
|
|
73
73
|
// eslint-disable-next-line
|
|
74
74
|
.then(values => {
|
|
75
75
|
if (app)
|
|
76
|
-
new app({ target: document.
|
|
76
|
+
new app({ target: document.getElementById('app') });
|
|
77
77
|
})
|
|
78
78
|
.catch(err => {
|
|
79
79
|
// eslint-disable-next-line
|
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.8",
|
|
4
4
|
"version_major": 0,
|
|
5
5
|
"version_minor": 15,
|
|
6
|
-
"version_patch":
|
|
7
|
-
"version_date": "
|
|
6
|
+
"version_patch": 8,
|
|
7
|
+
"version_date": "12/06/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",
|
|
@@ -21,16 +21,12 @@
|
|
|
21
21
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@thzero/library_client": "^0.
|
|
25
|
-
"@thzero/library_common": "^0.
|
|
26
|
-
"async-mutex": "^0.3.2",
|
|
24
|
+
"@thzero/library_client": "^0.16",
|
|
25
|
+
"@thzero/library_common": "^0.16",
|
|
27
26
|
"mitt": "^3.0.0",
|
|
28
|
-
"svelte-i18n": "^3.
|
|
27
|
+
"svelte-i18n": "^3.6.0"
|
|
29
28
|
},
|
|
30
29
|
"peerDependencies": {
|
|
31
|
-
"@alienfast/i18next-loader": "^1",
|
|
32
|
-
"@mdi/font": "^6",
|
|
33
|
-
"material-design-icons-iconfont": "^6",
|
|
34
30
|
"svelte": "^3"
|
|
35
31
|
}
|
|
36
32
|
}
|
|
@@ -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;
|