@rws-framework/client 2.20.1 → 2.20.3
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/.bin/emerge.sh +15 -15
- package/builder/vite/index.ts +4 -4
- package/builder/vite/rws.vite.config.ts +132 -132
- package/builder/vite/rws_scss_plugin.ts +61 -61
- package/builder/webpack/index.js +10 -10
- package/builder/webpack/rws.webpack.config.js +161 -161
- package/builder/webpack/rws_scss_plugin.js +90 -90
- package/builder/webpack/rws_webpack_plugin.js +137 -137
- package/cfg/_default.cfg.js +26 -26
- package/cfg/_storage.d.ts +22 -22
- package/cfg/_storage.js +42 -42
- package/cfg/tsconfigSetup.js +146 -146
- package/docs/assets/26e93147f10415a0ed4a.svg +6 -6
- package/docs/assets/75c9471662e97ee24f29.svg +7 -7
- package/docs/assets/db90e4df2373980c497d.svg +9 -9
- package/docs/assets/highlight.css +127 -127
- package/docs/assets/main.js +59 -59
- package/docs/assets/style.css +1414 -1414
- package/docs/classes/ApiServiceInstance.html +25 -25
- package/docs/classes/ConfigServiceInstance.html +21 -21
- package/docs/classes/DOMServiceInstance.html +17 -17
- package/docs/classes/NotifyServiceInstance.html +15 -15
- package/docs/classes/RWSClientInstance.html +45 -45
- package/docs/classes/RWSPlugin.html +13 -13
- package/docs/classes/RWSService.html +10 -10
- package/docs/classes/RWSViewComponent.html +1022 -1022
- package/docs/classes/ServiceWorkerServiceInstance.html +13 -13
- package/docs/classes/UtilsServiceInstance.html +13 -13
- package/docs/functions/attr.html +5 -5
- package/docs/functions/observable.html +3 -3
- package/docs/index.html +179 -179
- package/docs/interfaces/HTMLTag.html +3 -3
- package/docs/interfaces/IRWSConfig.html +20 -20
- package/docs/interfaces/IRWSDecoratorOptions.html +5 -5
- package/docs/interfaces/IRWSHttpRoute.html +2 -2
- package/docs/interfaces/IRWSPrefixedHTTProutes.html +2 -2
- package/docs/interfaces/IRWSUser.html +5 -5
- package/docs/modules.html +45 -45
- package/foundation/index.js +1 -1
- package/foundation/rws-foundation.d.ts +7 -7
- package/foundation/rws-foundation.js +7 -7
- package/package.json +1 -1
- package/service_worker/src/_service_worker.ts +83 -83
- package/service_worker/tsconfig.json +20 -20
- package/service_worker/webpack.config.js +66 -66
- package/src/client/components.ts +67 -67
- package/src/client/config.ts +175 -175
- package/src/client/hotReload.ts +22 -22
- package/src/client/services.ts +27 -27
- package/src/client.ts +208 -208
- package/src/components/_component.ts +247 -247
- package/src/components/_container.ts +15 -15
- package/src/components/_decorator.ts +122 -122
- package/src/components/_definitions.ts +64 -64
- package/src/components/_event_handling.ts +40 -40
- package/src/components/index.ts +25 -25
- package/src/index.ts +86 -86
- package/src/plugins/_builder.js +31 -31
- package/src/plugins/_plugin.ts +60 -60
- package/src/services/ApiService.ts +105 -105
- package/src/services/ConfigService.ts +125 -125
- package/src/services/DOMService.ts +93 -93
- package/src/services/NotifyService.ts +47 -47
- package/src/services/ServiceWorkerService.ts +60 -60
- package/src/services/UtilsService.ts +60 -60
- package/src/services/_service.ts +64 -64
- package/src/styles/README.md +157 -157
- package/src/styles/_darkreader.scss +30 -30
- package/src/styles/_grid.scss +75 -75
- package/src/styles/_grid_legacy.scss +49 -49
- package/src/styles/_misc.scss +8 -8
- package/src/styles/_scrollbars.scss +40 -40
- package/src/styles/includes.scss +6 -6
- package/src/types/IBackendCore.ts +11 -11
- package/src/types/IRWSConfig.ts +29 -29
- package/src/types/IRWSPlugin.ts +23 -23
- package/src/types/IRWSResource.ts +4 -4
- package/src/types/IRWSUser.ts +6 -6
- package/src/types/IRWSViewComponent.ts +36 -36
- package/src/types/IReFormerField.ts +4 -4
- package/src/types/RWSNotify.ts +6 -6
- package/src/types/RWSWindow.ts +41 -41
- package/types/declarations.d.ts +8 -8
- package/types/docs-typings.d.ts +15 -15
|
@@ -1,138 +1,138 @@
|
|
|
1
|
-
const rwsAfterCopy = require('./after/copy');
|
|
2
|
-
const rwsAfterSW = require('./after/sw');
|
|
3
|
-
const deepmerge = require('deepmerge');
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const _DEFAULT_CONFIG = { actions: [], executionDir: null, packageDir: null, dev: false, devDebug: null }
|
|
7
|
-
|
|
8
|
-
const _DEFAULT_ACTION = {
|
|
9
|
-
type: 'copy',
|
|
10
|
-
actionHandler: {
|
|
11
|
-
'targetDir': [
|
|
12
|
-
'filePath0',
|
|
13
|
-
'filePath1'
|
|
14
|
-
]
|
|
15
|
-
},
|
|
16
|
-
event: 'done'
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
class RWSWebpackPlugin {
|
|
20
|
-
config = _DEFAULT_CONFIG;
|
|
21
|
-
_allowedActionTypes = ['copy', 'custom', 'service_worker'];
|
|
22
|
-
|
|
23
|
-
constructor(config = {}) {
|
|
24
|
-
this.config = deepmerge(this.config, config);
|
|
25
|
-
this.customOptions = {
|
|
26
|
-
devDebug: this.config.devDebug
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
apply(compiler) {
|
|
31
|
-
const actionsEvents = this.config.actions.map(item => item.event ? item.event : 'done');
|
|
32
|
-
const errorActionsEvents = this.config.error_actions.map(item => item.event ? item.event : null).filter(item => !!item);
|
|
33
|
-
|
|
34
|
-
compiler.hooks.compilation.tap('RWSWebpackPlugin', (compilation) => {
|
|
35
|
-
compilation['customOptions'] = this.customOptions;
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
Array.from(new Set(actionsEvents)).forEach((eventName) => {
|
|
39
|
-
compiler.hooks[eventName].tapPromise('RWSWebpackPlugin', async (buildInfo) => {
|
|
40
|
-
const proms = this.config.actions.filter(item => item.event === _DEFAULT_ACTION.event || !item.event).map(async (rwsAfterAction) => {
|
|
41
|
-
return await this._runActionType(rwsAfterAction.type, rwsAfterAction.actionHandler);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
return await Promise.all(proms);
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
if (!this.config.dev) {
|
|
49
|
-
compiler.hooks.emit.tapAsync('RWSWebpackPlugin', (compilation, callback) => {
|
|
50
|
-
Object.keys(compilation.assets).forEach((filename) => {
|
|
51
|
-
|
|
52
|
-
if (filename.endsWith('.js')) {
|
|
53
|
-
const asset = compilation.assets[filename];
|
|
54
|
-
let source = asset.source();
|
|
55
|
-
|
|
56
|
-
if ((source.indexOf('css`') > -1 || source.indexOf('html`') > -1)) {
|
|
57
|
-
const updatedSource = source.replace(/\n/g, '');
|
|
58
|
-
|
|
59
|
-
// Update the asset with the new content
|
|
60
|
-
compilation.assets[filename] = {
|
|
61
|
-
source: () => updatedSource,
|
|
62
|
-
size: () => updatedSource.length
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
callback();
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// compiler.hooks.done.tap('RWSWebpackPlugin', (stats) => {
|
|
73
|
-
// // Check if there were any errors
|
|
74
|
-
// if (stats.hasErrors()) {
|
|
75
|
-
// console.error('Build failed with errors:');
|
|
76
|
-
|
|
77
|
-
// // Log the errors
|
|
78
|
-
// const info = stats.toJson();
|
|
79
|
-
// console.error(info.errors);
|
|
80
|
-
|
|
81
|
-
// Array.from(new Set(actionsEvents)).forEach((eventName) => {
|
|
82
|
-
// compiler.hooks[eventName].tapPromise('RWSWebpackPlugin', async (buildInfo) => {
|
|
83
|
-
// const proms = this.config.actions.filter(item => item.event === _DEFAULT_ACTION.event || !item.event).map(async (rwsAfterAction) => {
|
|
84
|
-
// return await this._runActionType(rwsAfterAction.type, rwsAfterAction.actionHandler);
|
|
85
|
-
// });
|
|
86
|
-
|
|
87
|
-
// return await Promise.all(proms);
|
|
88
|
-
// });
|
|
89
|
-
// });
|
|
90
|
-
|
|
91
|
-
// // Optionally exit the process with a non-zero status
|
|
92
|
-
// process.exit(1);
|
|
93
|
-
// } else {
|
|
94
|
-
// console.log('Build completed successfully.');
|
|
95
|
-
// }
|
|
96
|
-
// });
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
async _runActionType(actionType, action) {
|
|
100
|
-
if (!this._allowedActionTypes.includes(actionType)) {
|
|
101
|
-
throw new Error(`[RWSAfter webpack plugin] Action type ${actionType} is not allowed`);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
switch (actionType) {
|
|
105
|
-
case 'copy': {
|
|
106
|
-
const copyFiles = typeof action === 'function' ? await action() : action;
|
|
107
|
-
|
|
108
|
-
await rwsAfterCopy(copyFiles, this.config);
|
|
109
|
-
return;
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
//@TODO
|
|
113
|
-
case 'service_worker': {
|
|
114
|
-
|
|
115
|
-
const serviceWorkerPath = typeof action === 'function' ? await action() : action;
|
|
116
|
-
await rwsAfterSW(this.config.appRoot, serviceWorkerPath);
|
|
117
|
-
return;
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
case 'custom': {
|
|
121
|
-
|
|
122
|
-
if (typeof action !== 'function') {
|
|
123
|
-
console.error('Custom RWS action must be a function.')
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
await action();
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
default:
|
|
132
|
-
console.warn('RWSWebpackPlugin::_runActionType could not act upon input. Please resolve.');
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
1
|
+
const rwsAfterCopy = require('./after/copy');
|
|
2
|
+
const rwsAfterSW = require('./after/sw');
|
|
3
|
+
const deepmerge = require('deepmerge');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
const _DEFAULT_CONFIG = { actions: [], executionDir: null, packageDir: null, dev: false, devDebug: null }
|
|
7
|
+
|
|
8
|
+
const _DEFAULT_ACTION = {
|
|
9
|
+
type: 'copy',
|
|
10
|
+
actionHandler: {
|
|
11
|
+
'targetDir': [
|
|
12
|
+
'filePath0',
|
|
13
|
+
'filePath1'
|
|
14
|
+
]
|
|
15
|
+
},
|
|
16
|
+
event: 'done'
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
class RWSWebpackPlugin {
|
|
20
|
+
config = _DEFAULT_CONFIG;
|
|
21
|
+
_allowedActionTypes = ['copy', 'custom', 'service_worker'];
|
|
22
|
+
|
|
23
|
+
constructor(config = {}) {
|
|
24
|
+
this.config = deepmerge(this.config, config);
|
|
25
|
+
this.customOptions = {
|
|
26
|
+
devDebug: this.config.devDebug
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
apply(compiler) {
|
|
31
|
+
const actionsEvents = this.config.actions.map(item => item.event ? item.event : 'done');
|
|
32
|
+
const errorActionsEvents = this.config.error_actions.map(item => item.event ? item.event : null).filter(item => !!item);
|
|
33
|
+
|
|
34
|
+
compiler.hooks.compilation.tap('RWSWebpackPlugin', (compilation) => {
|
|
35
|
+
compilation['customOptions'] = this.customOptions;
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
Array.from(new Set(actionsEvents)).forEach((eventName) => {
|
|
39
|
+
compiler.hooks[eventName].tapPromise('RWSWebpackPlugin', async (buildInfo) => {
|
|
40
|
+
const proms = this.config.actions.filter(item => item.event === _DEFAULT_ACTION.event || !item.event).map(async (rwsAfterAction) => {
|
|
41
|
+
return await this._runActionType(rwsAfterAction.type, rwsAfterAction.actionHandler);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
return await Promise.all(proms);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
if (!this.config.dev) {
|
|
49
|
+
compiler.hooks.emit.tapAsync('RWSWebpackPlugin', (compilation, callback) => {
|
|
50
|
+
Object.keys(compilation.assets).forEach((filename) => {
|
|
51
|
+
|
|
52
|
+
if (filename.endsWith('.js')) {
|
|
53
|
+
const asset = compilation.assets[filename];
|
|
54
|
+
let source = asset.source();
|
|
55
|
+
|
|
56
|
+
if ((source.indexOf('css`') > -1 || source.indexOf('html`') > -1)) {
|
|
57
|
+
const updatedSource = source.replace(/\n/g, '');
|
|
58
|
+
|
|
59
|
+
// Update the asset with the new content
|
|
60
|
+
compilation.assets[filename] = {
|
|
61
|
+
source: () => updatedSource,
|
|
62
|
+
size: () => updatedSource.length
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
callback();
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// compiler.hooks.done.tap('RWSWebpackPlugin', (stats) => {
|
|
73
|
+
// // Check if there were any errors
|
|
74
|
+
// if (stats.hasErrors()) {
|
|
75
|
+
// console.error('Build failed with errors:');
|
|
76
|
+
|
|
77
|
+
// // Log the errors
|
|
78
|
+
// const info = stats.toJson();
|
|
79
|
+
// console.error(info.errors);
|
|
80
|
+
|
|
81
|
+
// Array.from(new Set(actionsEvents)).forEach((eventName) => {
|
|
82
|
+
// compiler.hooks[eventName].tapPromise('RWSWebpackPlugin', async (buildInfo) => {
|
|
83
|
+
// const proms = this.config.actions.filter(item => item.event === _DEFAULT_ACTION.event || !item.event).map(async (rwsAfterAction) => {
|
|
84
|
+
// return await this._runActionType(rwsAfterAction.type, rwsAfterAction.actionHandler);
|
|
85
|
+
// });
|
|
86
|
+
|
|
87
|
+
// return await Promise.all(proms);
|
|
88
|
+
// });
|
|
89
|
+
// });
|
|
90
|
+
|
|
91
|
+
// // Optionally exit the process with a non-zero status
|
|
92
|
+
// process.exit(1);
|
|
93
|
+
// } else {
|
|
94
|
+
// console.log('Build completed successfully.');
|
|
95
|
+
// }
|
|
96
|
+
// });
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async _runActionType(actionType, action) {
|
|
100
|
+
if (!this._allowedActionTypes.includes(actionType)) {
|
|
101
|
+
throw new Error(`[RWSAfter webpack plugin] Action type ${actionType} is not allowed`);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
switch (actionType) {
|
|
105
|
+
case 'copy': {
|
|
106
|
+
const copyFiles = typeof action === 'function' ? await action() : action;
|
|
107
|
+
|
|
108
|
+
await rwsAfterCopy(copyFiles, this.config);
|
|
109
|
+
return;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
//@TODO
|
|
113
|
+
case 'service_worker': {
|
|
114
|
+
|
|
115
|
+
const serviceWorkerPath = typeof action === 'function' ? await action() : action;
|
|
116
|
+
await rwsAfterSW(this.config.appRoot, serviceWorkerPath);
|
|
117
|
+
return;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
case 'custom': {
|
|
121
|
+
|
|
122
|
+
if (typeof action !== 'function') {
|
|
123
|
+
console.error('Custom RWS action must be a function.')
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
await action();
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
default:
|
|
132
|
+
console.warn('RWSWebpackPlugin::_runActionType could not act upon input. Please resolve.');
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
138
|
module.exports = RWSWebpackPlugin;
|
package/cfg/_default.cfg.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
const _DEFAULT_CONFIG_VARS = {
|
|
2
|
-
//Build configs
|
|
3
|
-
dev: false,
|
|
4
|
-
hot: false,
|
|
5
|
-
report: false,
|
|
6
|
-
publicDir: './public',
|
|
7
|
-
publicIndex: 'index.html',
|
|
8
|
-
outputFileName: 'rws.client.js',
|
|
9
|
-
outputDir: './build',
|
|
10
|
-
tsConfigPath: './tsconfig.json',
|
|
11
|
-
//Frontend RWS client configs
|
|
12
|
-
backendUrl: null,
|
|
13
|
-
wsUrl: null,
|
|
14
|
-
partedDirUrlPrefix: '/',
|
|
15
|
-
partedPrefix: 'rws',
|
|
16
|
-
pubUrlFilePrefix: '/',
|
|
17
|
-
//Universal configs
|
|
18
|
-
transports: ['websocket'],
|
|
19
|
-
parted: false,
|
|
20
|
-
devRouteProxy: '/api',
|
|
21
|
-
devApiPort: 3002,
|
|
22
|
-
plugins: []
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const _DEFAULT_CONFIG = Object.freeze(_DEFAULT_CONFIG_VARS);
|
|
26
|
-
|
|
1
|
+
const _DEFAULT_CONFIG_VARS = {
|
|
2
|
+
//Build configs
|
|
3
|
+
dev: false,
|
|
4
|
+
hot: false,
|
|
5
|
+
report: false,
|
|
6
|
+
publicDir: './public',
|
|
7
|
+
publicIndex: 'index.html',
|
|
8
|
+
outputFileName: 'rws.client.js',
|
|
9
|
+
outputDir: './build',
|
|
10
|
+
tsConfigPath: './tsconfig.json',
|
|
11
|
+
//Frontend RWS client configs
|
|
12
|
+
backendUrl: null,
|
|
13
|
+
wsUrl: null,
|
|
14
|
+
partedDirUrlPrefix: '/',
|
|
15
|
+
partedPrefix: 'rws',
|
|
16
|
+
pubUrlFilePrefix: '/',
|
|
17
|
+
//Universal configs
|
|
18
|
+
transports: ['websocket'],
|
|
19
|
+
parted: false,
|
|
20
|
+
devRouteProxy: '/api',
|
|
21
|
+
devApiPort: 3002,
|
|
22
|
+
plugins: []
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const _DEFAULT_CONFIG = Object.freeze(_DEFAULT_CONFIG_VARS);
|
|
26
|
+
|
|
27
27
|
module.exports = {_DEFAULT_CONFIG};
|
package/cfg/_storage.d.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
interface Storage {
|
|
2
|
-
_loaded: boolean;
|
|
3
|
-
data: {
|
|
4
|
-
[key: string]: any;
|
|
5
|
-
};
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
declare const _STORAGE: Readonly<Storage>;
|
|
9
|
-
|
|
10
|
-
declare function get(key: string): any | null;
|
|
11
|
-
declare function getAll(): any;
|
|
12
|
-
declare function init(json: any): void;
|
|
13
|
-
declare function has(key: string): boolean;
|
|
14
|
-
declare function isLoaded(): boolean;
|
|
15
|
-
|
|
16
|
-
export {
|
|
17
|
-
get,
|
|
18
|
-
getAll,
|
|
19
|
-
has,
|
|
20
|
-
init,
|
|
21
|
-
isLoaded
|
|
22
|
-
};
|
|
1
|
+
interface Storage {
|
|
2
|
+
_loaded: boolean;
|
|
3
|
+
data: {
|
|
4
|
+
[key: string]: any;
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
declare const _STORAGE: Readonly<Storage>;
|
|
9
|
+
|
|
10
|
+
declare function get(key: string): any | null;
|
|
11
|
+
declare function getAll(): any;
|
|
12
|
+
declare function init(json: any): void;
|
|
13
|
+
declare function has(key: string): boolean;
|
|
14
|
+
declare function isLoaded(): boolean;
|
|
15
|
+
|
|
16
|
+
export {
|
|
17
|
+
get,
|
|
18
|
+
getAll,
|
|
19
|
+
has,
|
|
20
|
+
init,
|
|
21
|
+
isLoaded
|
|
22
|
+
};
|
package/cfg/_storage.js
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
class Storage {
|
|
2
|
-
static _instance;
|
|
3
|
-
|
|
4
|
-
_loaded = false;
|
|
5
|
-
data = {}
|
|
6
|
-
|
|
7
|
-
static create(){
|
|
8
|
-
if(!this._instance){
|
|
9
|
-
this._instance = new Storage();
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
return this._instance;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const _STORAGE = Storage.create();
|
|
17
|
-
|
|
18
|
-
function get(key){
|
|
19
|
-
if(!has(key)){
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return _STORAGE.data[key];
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function getAll(){
|
|
27
|
-
return _STORAGE.data;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function init(json){
|
|
31
|
-
_STORAGE.data = json;
|
|
32
|
-
_STORAGE._loaded = true;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function has(key){
|
|
36
|
-
return Object.keys(_STORAGE.data).includes(key);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function isLoaded(){
|
|
40
|
-
return _STORAGE._loaded;
|
|
41
|
-
}
|
|
42
|
-
|
|
1
|
+
class Storage {
|
|
2
|
+
static _instance;
|
|
3
|
+
|
|
4
|
+
_loaded = false;
|
|
5
|
+
data = {}
|
|
6
|
+
|
|
7
|
+
static create(){
|
|
8
|
+
if(!this._instance){
|
|
9
|
+
this._instance = new Storage();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return this._instance;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const _STORAGE = Storage.create();
|
|
17
|
+
|
|
18
|
+
function get(key){
|
|
19
|
+
if(!has(key)){
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return _STORAGE.data[key];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function getAll(){
|
|
27
|
+
return _STORAGE.data;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function init(json){
|
|
31
|
+
_STORAGE.data = json;
|
|
32
|
+
_STORAGE._loaded = true;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function has(key){
|
|
36
|
+
return Object.keys(_STORAGE.data).includes(key);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function isLoaded(){
|
|
40
|
+
return _STORAGE._loaded;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
43
|
module.exports = {get, getAll, has, init, isLoaded}
|