@thzero/library_client_svelte 0.18.1 → 0.18.2

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 CHANGED
@@ -1,65 +1,65 @@
1
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](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
- [![NPM](https://nodei.co/npm/@thzero/library_client_svelte.png?compact=true)](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
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](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
+ [![NPM](https://nodei.co/npm/@thzero/library_client_svelte.png?compact=true)](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,32 +1,32 @@
1
- import LibraryClientUtility from '@thzero/library_client/utility/index.js';
2
-
3
- import RootServicesBaseBoot from '@thzero/library_client/boot/rootServices.js';
4
-
5
- import eventService from '../service/event.js';
6
- import routerService from '../service/router.js';
7
- import storeService from '../service/store.js';
8
- import translateService from '../service/translate.js';
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;
1
+ import LibraryClientUtility from '@thzero/library_client/utility/index.js';
2
+
3
+ import RootServicesBaseBoot from '@thzero/library_client/boot/rootServices.js';
4
+
5
+ import eventService from '../service/event.js';
6
+ import routerService from '../service/router.js';
7
+ import storeService from '../service/store.js';
8
+ import translateService from '../service/translate.js';
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;
@@ -1,56 +1,56 @@
1
- import BaseBoot from '@thzero/library_client/boot/base.js';
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.js';
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,27 +1,27 @@
1
- import { init, getLocaleFromNavigator, register, format, addMessages, unwrapFunctionStore } from 'svelte-i18n';
2
-
3
- import LibraryClientUtility from '@thzero/library_client/utility/index.js';
4
-
5
- import i18nBaseBoot from '@thzero/library_client/boot/basei18n.js';
6
-
7
- import NotImplementedError from '@thzero/library_common/errors/notImplemented.js';
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
- LibraryClientUtility.$trans = { t: format };
20
- }
21
-
22
- _initMessages(register) {
23
- throw new NotImplementedError();
24
- }
25
- }
26
-
27
- export default Sveltei18nBaseBoot;
1
+ import { init, getLocaleFromNavigator, register, format, addMessages, unwrapFunctionStore } from 'svelte-i18n';
2
+
3
+ import LibraryClientUtility from '@thzero/library_client/utility/index.js';
4
+
5
+ import i18nBaseBoot from '@thzero/library_client/boot/basei18n.js';
6
+
7
+ import NotImplementedError from '@thzero/library_common/errors/notImplemented.js';
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
+ LibraryClientUtility.$trans = { t: format };
20
+ }
21
+
22
+ _initMessages(register) {
23
+ throw new NotImplementedError();
24
+ }
25
+ }
26
+
27
+ 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.js';
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.js';
4
+
5
+ const EventBus = mitt();
6
+
7
+ export default async () => {
8
+ LibraryClientUtility.$EventBus = EventBus;
9
+ };
package/boot/main.js CHANGED
@@ -1,106 +1,106 @@
1
- import LibraryClientUtility from '@thzero/library_client/utility/index.js';
2
-
3
- // @ts-ignore
4
- import {} from '@thzero/library_common/utility/string.js';
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
- store = new storeRequest();
12
- }
13
- catch (err) {
14
- console.log(err);
15
- throw Error('Unable to create store.');
16
- }
17
- }
18
-
19
- if (!store)
20
- throw Error('Unable to create store.');
21
- LibraryClientUtility.$store = store;
22
-
23
- if (options) {
24
- if (options.idGenerator) {
25
- if (options.idGenerator.override)
26
- LibraryCommonUtility.setIdGenerator(options.idGenerator.override);
27
- if (options.idGenerator.alphabet)
28
- LibraryCommonUtility.setIdGeneratorAlphabet(options.idGenerator.alphabet);
29
- if (options.idGenerator.lengthLong)
30
- LibraryCommonUtility.setIdGeneratorLengthLong(options.idGenerator.lengthLong);
31
- if (options.idGenerator.lengthShort)
32
- LibraryCommonUtility.setIdGeneratorLengthShort(options.idGenerator.lengthShort);
33
- }
34
- }
35
-
36
- if (bootFiles && (bootFiles.length > 0)) {
37
- let obj;
38
- for (const bootFile of bootFiles) {
39
- if (typeof bootFile !== 'function')
40
- continue;
41
-
42
- try {
43
- try {
44
- await bootFile({
45
- store
46
- });
47
- continue;
48
- }
49
- catch (err) {
50
- obj = new bootFile();
51
- await obj.execute(
52
- store
53
- );
54
- continue;
55
- }
56
- }
57
- catch (err) {
58
- if (err && err.url) {
59
- window.location.href = err.url;
60
- return;
61
- }
62
-
63
- // eslint-disable-next-line
64
- console.error('boot error:', err);
65
- return;
66
- }
67
- }
68
- }
69
-
70
- if (!app)
71
- return;
72
-
73
- if (!starter) {
74
- if (app)
75
- new app({ target: document.getElementById('app') });
76
- return;
77
- }
78
-
79
- try {
80
- const result = starter({
81
- store
82
- });
83
-
84
- result
85
- // eslint-disable-next-line
86
- .then(values => {
87
- if (app)
88
- new app({ target: document.getElementById('app') });
89
- })
90
- .catch(err => {
91
- // eslint-disable-next-line
92
- console.error('boot error:', err);
93
- });
94
- }
95
- catch (err) {
96
- if (err && err.url) {
97
- window.location.href = err.url;
98
- return;
99
- }
100
-
101
- // eslint-disable-next-line
102
- console.error('boot error:', err);
103
- }
104
- }
105
-
106
- export default start;
1
+ import LibraryClientUtility from '@thzero/library_client/utility/index.js';
2
+
3
+ // @ts-ignore
4
+ import {} from '@thzero/library_common/utility/string.js';
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
+ store = new storeRequest();
12
+ }
13
+ catch (err) {
14
+ console.log(err);
15
+ throw Error('Unable to create store.');
16
+ }
17
+ }
18
+
19
+ if (!store)
20
+ throw Error('Unable to create store.');
21
+ LibraryClientUtility.$store = store;
22
+
23
+ if (options) {
24
+ if (options.idGenerator) {
25
+ if (options.idGenerator.override)
26
+ LibraryCommonUtility.setIdGenerator(options.idGenerator.override);
27
+ if (options.idGenerator.alphabet)
28
+ LibraryCommonUtility.setIdGeneratorAlphabet(options.idGenerator.alphabet);
29
+ if (options.idGenerator.lengthLong)
30
+ LibraryCommonUtility.setIdGeneratorLengthLong(options.idGenerator.lengthLong);
31
+ if (options.idGenerator.lengthShort)
32
+ LibraryCommonUtility.setIdGeneratorLengthShort(options.idGenerator.lengthShort);
33
+ }
34
+ }
35
+
36
+ if (bootFiles && (bootFiles.length > 0)) {
37
+ let obj;
38
+ for (const bootFile of bootFiles) {
39
+ if (typeof bootFile !== 'function')
40
+ continue;
41
+
42
+ try {
43
+ try {
44
+ await bootFile({
45
+ store
46
+ });
47
+ continue;
48
+ }
49
+ catch (err) {
50
+ obj = new bootFile();
51
+ await obj.execute(
52
+ store
53
+ );
54
+ continue;
55
+ }
56
+ }
57
+ catch (err) {
58
+ if (err && err.url) {
59
+ window.location.href = err.url;
60
+ return;
61
+ }
62
+
63
+ // eslint-disable-next-line
64
+ console.error('boot error:', err);
65
+ return;
66
+ }
67
+ }
68
+ }
69
+
70
+ if (!app)
71
+ return;
72
+
73
+ if (!starter) {
74
+ if (app)
75
+ new app({ target: document.getElementById('app') });
76
+ return;
77
+ }
78
+
79
+ try {
80
+ const result = starter({
81
+ store
82
+ });
83
+
84
+ result
85
+ // eslint-disable-next-line
86
+ .then(values => {
87
+ if (app)
88
+ new app({ target: document.getElementById('app') });
89
+ })
90
+ .catch(err => {
91
+ // eslint-disable-next-line
92
+ console.error('boot error:', err);
93
+ });
94
+ }
95
+ catch (err) {
96
+ if (err && err.url) {
97
+ window.location.href = err.url;
98
+ return;
99
+ }
100
+
101
+ // eslint-disable-next-line
102
+ console.error('boot error:', err);
103
+ }
104
+ }
105
+
106
+ export default start;
@@ -1,7 +1,7 @@
1
- import startMain from './main.js';
2
-
3
- async function start(storeRequest, bootFiles, starter) {
4
- await startMain(null, storeRequest, bootFiles, starter);
5
- }
6
-
7
- export default start;
1
+ import startMain from './main.js';
2
+
3
+ async function start(storeRequest, bootFiles, starter) {
4
+ await startMain(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-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
-
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.18.1",
4
- "version_major": 0,
5
- "version_minor": 18,
6
- "version_patch": 1,
7
- "version_date": "02/25/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.18",
25
- "@thzero/library_common": "^0.18",
26
- "mitt": "^3.0.1",
27
- "svelte-i18n": "^4.0.0",
28
- "svelte-spa-router": "^4.0.1"
29
- },
30
- "peerDependencies": {
31
- "svelte": "^4"
32
- }
1
+ {
2
+ "name": "@thzero/library_client_svelte",
3
+ "version": "0.18.2",
4
+ "version_major": 0,
5
+ "version_minor": 18,
6
+ "version_patch": 2,
7
+ "version_date": "03/26/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.18",
25
+ "@thzero/library_common": "^0.18",
26
+ "mitt": "^3.0.1",
27
+ "svelte-i18n": "^4.0.0",
28
+ "svelte-spa-router": "^4.0.1"
29
+ },
30
+ "peerDependencies": {
31
+ "svelte": "^4"
32
+ }
33
33
  }
@@ -1,49 +1,49 @@
1
- import LibraryClientConstants from '@thzero/library_client/constants.js';
2
-
3
- import BaseUserService from '@thzero/library_client/service/baseUser.js';
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;
1
+ import LibraryClientConstants from '@thzero/library_client/constants.js';
2
+
3
+ import BaseUserService from '@thzero/library_client/service/baseUser.js';
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.js';
2
-
3
- import EventService from '@thzero/library_client/service/event.js';
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.js';
2
+
3
+ import EventService from '@thzero/library_client/service/event.js';
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 { push } from 'svelte-spa-router';
2
-
3
- import RouterService from '@thzero/library_client/service/router.js';
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;
1
+ import { push } from 'svelte-spa-router';
2
+
3
+ import RouterService from '@thzero/library_client/service/router.js';
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.js';
2
-
3
- import Service from '@thzero/library_client/service/index.js';
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.js';
2
+
3
+ import Service from '@thzero/library_client/service/index.js';
4
+
5
+ class SvelteStoreService extends Service {
6
+ get store() {
7
+ return LibraryClientUtility.$store;
8
+ }
9
+ }
10
+
11
+ export default SvelteStoreService;
@@ -1,12 +1,12 @@
1
- import LibraryClientUtility from '@thzero/library_client/utility/index.js';
2
-
3
- import TranslateService from '@thzero/library_client/service/translate.js';
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.js';
2
+
3
+ import TranslateService from '@thzero/library_client/service/translate.js';
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.js';
2
- import LibraryCommonConstants from '@thzero/library_common/constants.js';
3
-
4
- import LibraryClientUtility from '@thzero/library_client/utility/index.js';
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.js';
2
+ import LibraryCommonConstants from '@thzero/library_common/constants.js';
3
+
4
+ import LibraryClientUtility from '@thzero/library_client/utility/index.js';
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;