@dr.pogodin/react-utils 1.47.0-alpha.2 → 1.47.0-alpha.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/babel.config.js +1 -1
- package/babel.module.config.js +11 -0
- package/bin/build.js +8 -4
- package/bin/setup.js +2 -3
- package/build/development/client/getInj.js +9 -18
- package/build/development/client/getInj.js.map +1 -1
- package/build/development/client/index.js +14 -21
- package/build/development/client/index.js.map +1 -1
- package/build/development/client/init.js +2 -6
- package/build/development/client/init.js.map +1 -1
- package/build/development/index.js +9 -178
- package/build/development/index.js.map +1 -1
- package/build/development/server/Cache.js +1 -8
- package/build/development/server/Cache.js.map +1 -1
- package/build/development/server/index.js +25 -50
- package/build/development/server/index.js.map +1 -1
- package/build/development/server/renderer.js +56 -67
- package/build/development/server/renderer.js.map +1 -1
- package/build/development/server/server.js +47 -58
- package/build/development/server/server.js.map +1 -1
- package/build/development/server/utils/errors.js +8 -31
- package/build/development/server/utils/errors.js.map +1 -1
- package/build/development/server/utils/index.js +2 -9
- package/build/development/server/utils/index.js.map +1 -1
- package/build/development/shared/components/Button/index.js +9 -16
- package/build/development/shared/components/Button/index.js.map +1 -1
- package/build/development/shared/components/Checkbox/index.js +6 -13
- package/build/development/shared/components/Checkbox/index.js.map +1 -1
- package/build/development/shared/components/GenericLink/index.js +4 -10
- package/build/development/shared/components/GenericLink/index.js.map +1 -1
- package/build/development/shared/components/Input/index.js +11 -18
- package/build/development/shared/components/Input/index.js.map +1 -1
- package/build/development/shared/components/Link.js +6 -13
- package/build/development/shared/components/Link.js.map +1 -1
- package/build/development/shared/components/Modal/index.js +16 -22
- package/build/development/shared/components/Modal/index.js.map +1 -1
- package/build/development/shared/components/NavLink.js +6 -13
- package/build/development/shared/components/NavLink.js.map +1 -1
- package/build/development/shared/components/PageLayout/index.js +7 -14
- package/build/development/shared/components/PageLayout/index.js.map +1 -1
- package/build/development/shared/components/TextArea/index.js +15 -22
- package/build/development/shared/components/TextArea/index.js.map +1 -1
- package/build/development/shared/components/Throbber/index.js +7 -14
- package/build/development/shared/components/Throbber/index.js.map +1 -1
- package/build/development/shared/components/WithTooltip/Tooltip.js +12 -18
- package/build/development/shared/components/WithTooltip/Tooltip.js.map +1 -1
- package/build/development/shared/components/WithTooltip/index.js +16 -23
- package/build/development/shared/components/WithTooltip/index.js.map +1 -1
- package/build/development/shared/components/YouTubeVideo/index.js +10 -17
- package/build/development/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/development/shared/components/index.js +16 -130
- package/build/development/shared/components/index.js.map +1 -1
- package/build/development/shared/components/selectors/CustomDropdown/Options/index.js +12 -19
- package/build/development/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
- package/build/development/shared/components/selectors/CustomDropdown/index.js +20 -28
- package/build/development/shared/components/selectors/CustomDropdown/index.js.map +1 -1
- package/build/development/shared/components/selectors/NativeDropdown/index.js +13 -19
- package/build/development/shared/components/selectors/NativeDropdown/index.js.map +1 -1
- package/build/development/shared/components/selectors/Switch/index.js +10 -17
- package/build/development/shared/components/selectors/Switch/index.js.map +1 -1
- package/build/development/shared/components/selectors/common.js +1 -7
- package/build/development/shared/components/selectors/common.js.map +1 -1
- package/build/development/shared/components/selectors/index.js +3 -27
- package/build/development/shared/components/selectors/index.js.map +1 -1
- package/build/development/shared/utils/config.js +8 -16
- package/build/development/shared/utils/config.js.map +1 -1
- package/build/development/shared/utils/globalState.js +3 -8
- package/build/development/shared/utils/globalState.js.map +1 -1
- package/build/development/shared/utils/index.js +12 -89
- package/build/development/shared/utils/index.js.map +1 -1
- package/build/development/shared/utils/isomorphy/buildInfo.js +2 -9
- package/build/development/shared/utils/isomorphy/buildInfo.js.map +1 -1
- package/build/development/shared/utils/isomorphy/environment-check.js +2 -8
- package/build/development/shared/utils/isomorphy/environment-check.js.map +1 -1
- package/build/development/shared/utils/isomorphy/index.js +7 -32
- package/build/development/shared/utils/isomorphy/index.js.map +1 -1
- package/build/development/shared/utils/jest/E2eSsrEnv.js +20 -31
- package/build/development/shared/utils/jest/E2eSsrEnv.js.map +1 -1
- package/build/development/shared/utils/jest/global.js +1 -7
- package/build/development/shared/utils/jest/global.js.map +1 -1
- package/build/development/shared/utils/jest/index.js +20 -44
- package/build/development/shared/utils/jest/index.js.map +1 -1
- package/build/development/shared/utils/splitComponent.js +22 -29
- package/build/development/shared/utils/splitComponent.js.map +1 -1
- package/build/development/shared/utils/time.js +22 -31
- package/build/development/shared/utils/time.js.map +1 -1
- package/build/development/shared/utils/webpack.js +13 -16
- package/build/development/shared/utils/webpack.js.map +1 -1
- package/build/production/client/getInj.js +5 -5
- package/build/production/client/getInj.js.map +1 -1
- package/build/production/client/index.js +3 -3
- package/build/production/client/index.js.map +1 -1
- package/build/production/client/init.js +2 -2
- package/build/production/client/init.js.map +1 -1
- package/build/production/index.js +2 -2
- package/build/production/index.js.map +1 -1
- package/build/production/server/Cache.js +3 -3
- package/build/production/server/Cache.js.map +1 -1
- package/build/production/server/index.js +8 -8
- package/build/production/server/index.js.map +1 -1
- package/build/production/server/renderer.js +21 -19
- package/build/production/server/renderer.js.map +1 -1
- package/build/production/server/server.js +9 -9
- package/build/production/server/server.js.map +1 -1
- package/build/production/server/utils/errors.js +9 -9
- package/build/production/server/utils/errors.js.map +1 -1
- package/build/production/server/utils/index.js +2 -1
- package/build/production/server/utils/index.js.map +1 -1
- package/build/production/shared/components/Button/index.js +4 -4
- package/build/production/shared/components/Button/index.js.map +1 -1
- package/build/production/shared/components/Checkbox/index.js +1 -1
- package/build/production/shared/components/Checkbox/index.js.map +1 -1
- package/build/production/shared/components/GenericLink/index.js +4 -4
- package/build/production/shared/components/GenericLink/index.js.map +1 -1
- package/build/production/shared/components/Input/index.js +5 -5
- package/build/production/shared/components/Input/index.js.map +1 -1
- package/build/production/shared/components/Link.js +3 -3
- package/build/production/shared/components/Link.js.map +1 -1
- package/build/production/shared/components/Modal/index.js +7 -7
- package/build/production/shared/components/Modal/index.js.map +1 -1
- package/build/production/shared/components/NavLink.js +2 -2
- package/build/production/shared/components/NavLink.js.map +1 -1
- package/build/production/shared/components/PageLayout/index.js +2 -2
- package/build/production/shared/components/PageLayout/index.js.map +1 -1
- package/build/production/shared/components/TextArea/index.js +5 -5
- package/build/production/shared/components/TextArea/index.js.map +1 -1
- package/build/production/shared/components/Throbber/index.js +2 -2
- package/build/production/shared/components/Throbber/index.js.map +1 -1
- package/build/production/shared/components/WithTooltip/Tooltip.js +4 -4
- package/build/production/shared/components/WithTooltip/Tooltip.js.map +1 -1
- package/build/production/shared/components/WithTooltip/index.js +4 -4
- package/build/production/shared/components/WithTooltip/index.js.map +1 -1
- package/build/production/shared/components/YouTubeVideo/index.js +4 -4
- package/build/production/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/production/shared/components/index.js +3 -1
- package/build/production/shared/components/index.js.map +1 -1
- package/build/production/shared/components/selectors/CustomDropdown/Options/index.js +2 -2
- package/build/production/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
- package/build/production/shared/components/selectors/CustomDropdown/index.js +2 -2
- package/build/production/shared/components/selectors/CustomDropdown/index.js.map +1 -1
- package/build/production/shared/components/selectors/NativeDropdown/index.js +4 -4
- package/build/production/shared/components/selectors/NativeDropdown/index.js.map +1 -1
- package/build/production/shared/components/selectors/Switch/index.js +1 -1
- package/build/production/shared/components/selectors/Switch/index.js.map +1 -1
- package/build/production/shared/components/selectors/common.js +2 -2
- package/build/production/shared/components/selectors/common.js.map +1 -1
- package/build/production/shared/components/selectors/index.js +1 -1
- package/build/production/shared/components/selectors/index.js.map +1 -1
- package/build/production/shared/utils/config.js +3 -3
- package/build/production/shared/utils/config.js.map +1 -1
- package/build/production/shared/utils/globalState.js +2 -2
- package/build/production/shared/utils/globalState.js.map +1 -1
- package/build/production/shared/utils/index.js +1 -1
- package/build/production/shared/utils/index.js.map +1 -1
- package/build/production/shared/utils/isomorphy/buildInfo.js +3 -3
- package/build/production/shared/utils/isomorphy/buildInfo.js.map +1 -1
- package/build/production/shared/utils/isomorphy/environment-check.js +3 -3
- package/build/production/shared/utils/isomorphy/environment-check.js.map +1 -1
- package/build/production/shared/utils/isomorphy/index.js +4 -4
- package/build/production/shared/utils/isomorphy/index.js.map +1 -1
- package/build/production/shared/utils/jest/E2eSsrEnv.js +14 -14
- package/build/production/shared/utils/jest/E2eSsrEnv.js.map +1 -1
- package/build/production/shared/utils/jest/global.js +1 -1
- package/build/production/shared/utils/jest/global.js.map +1 -1
- package/build/production/shared/utils/jest/index.js +11 -11
- package/build/production/shared/utils/jest/index.js.map +1 -1
- package/build/production/shared/utils/splitComponent.js +11 -11
- package/build/production/shared/utils/splitComponent.js.map +1 -1
- package/build/production/shared/utils/time.js +3 -3
- package/build/production/shared/utils/time.js.map +1 -1
- package/build/production/shared/utils/webpack.js +6 -6
- package/build/production/shared/utils/webpack.js.map +1 -1
- package/build/types-code/client/getInj.d.ts +1 -1
- package/build/types-code/server/index.d.ts +2 -2
- package/build/web/client/getInj.js +2 -2
- package/build/web/client/getInj.js.map +1 -1
- package/build/web/server/index.js +9 -15
- package/build/web/server/index.js.map +1 -1
- package/build/web/server/renderer.js +12 -10
- package/build/web/server/renderer.js.map +1 -1
- package/build/web/server/server.js +2 -4
- package/build/web/server/server.js.map +1 -1
- package/build/web/shared/utils/jest/E2eSsrEnv.js +1 -2
- package/build/web/shared/utils/jest/E2eSsrEnv.js.map +1 -1
- package/build/web/shared/utils/webpack.js +11 -7
- package/build/web/shared/utils/webpack.js.map +1 -1
- package/config/babel/node-ssr.js +5 -5
- package/config/jest/default.js +1 -0
- package/config/webpack/app-base.js +11 -10
- package/config/webpack/app-development.js +3 -3
- package/config/webpack/lib-base.js +1 -1
- package/package.json +8 -6
- package/src/client/getInj.ts +2 -2
- package/src/server/index.ts +9 -15
- package/src/server/renderer.tsx +11 -10
- package/src/server/server.ts +2 -4
- package/src/shared/utils/jest/E2eSsrEnv.ts +1 -2
- package/src/shared/utils/webpack.ts +14 -8
- package/types.d.ts +1 -1
package/babel.config.js
CHANGED
package/bin/build.js
CHANGED
|
@@ -8,9 +8,7 @@ import fs from 'node:fs';
|
|
|
8
8
|
import { createRequire } from 'node:module';
|
|
9
9
|
import path from 'node:path';
|
|
10
10
|
|
|
11
|
-
import
|
|
12
|
-
import mapValues from 'lodash/mapValues.js';
|
|
13
|
-
import merge from 'lodash/merge.js';
|
|
11
|
+
import { mapValues, merge } from 'lodash-es';
|
|
14
12
|
|
|
15
13
|
import { program } from 'commander';
|
|
16
14
|
|
|
@@ -70,6 +68,7 @@ program
|
|
|
70
68
|
.option('--no-webpack', 'opts out the Webpack (client-side code) build')
|
|
71
69
|
.option('-o, --out-dir <path>', 'output folder for the build', 'build')
|
|
72
70
|
.option('-w, --watch', 'build, watch, and rebuild on source changes')
|
|
71
|
+
.option('--babel-config <path>', 'path to the Babel config')
|
|
73
72
|
.option(
|
|
74
73
|
'--webpack-config <path>',
|
|
75
74
|
'path to the webpack config',
|
|
@@ -116,7 +115,7 @@ const require = createRequire(import.meta.url);
|
|
|
116
115
|
// eslint-disable-next-line import/no-dynamic-require
|
|
117
116
|
let webpackConfig = require(path.resolve(cwd, cmdLineArgs.webpackConfig));
|
|
118
117
|
if ('default' in webpackConfig) webpackConfig = webpackConfig.default;
|
|
119
|
-
if (
|
|
118
|
+
if (typeof webpackConfig === 'function') webpackConfig = webpackConfig(buildType);
|
|
120
119
|
|
|
121
120
|
let webpackOutDir = outDir;
|
|
122
121
|
if (!cmdLineArgs.lib) webpackOutDir += '/web-public';
|
|
@@ -195,6 +194,11 @@ let BABEL_CMD_BASE = `${cwd}/node_modules/.bin/babel`;
|
|
|
195
194
|
BABEL_CMD_BASE += ` ${inDir} --out-dir ${outDir} --source-maps`;
|
|
196
195
|
if (buildType === BUILD_TYPES.PRODUCTION) BABEL_CMD_BASE += ' --minified';
|
|
197
196
|
|
|
197
|
+
if (cmdLineArgs.babelConfig) {
|
|
198
|
+
const url = path.resolve(cwd, cmdLineArgs.babelConfig);
|
|
199
|
+
BABEL_CMD_BASE += ` --config-file ${url}`;
|
|
200
|
+
}
|
|
201
|
+
|
|
198
202
|
/* TODO: The watch is deactivated for Babel compilation because of SVG files:
|
|
199
203
|
* currently there is no way to tell Babel that SVG files should be compiled
|
|
200
204
|
* keeping their SVG extensions, while JS and JSX are compiled with extensions
|
package/bin/setup.js
CHANGED
|
@@ -7,7 +7,6 @@ import { spawnSync } from 'node:child_process';
|
|
|
7
7
|
import fs from 'node:fs';
|
|
8
8
|
import path from 'node:path';
|
|
9
9
|
|
|
10
|
-
import clone from 'lodash/clone.js';
|
|
11
10
|
import { program } from 'commander';
|
|
12
11
|
|
|
13
12
|
const NPM_COMMAND = process.platform === 'win32' ? 'npm.cmd' : 'npm';
|
|
@@ -110,7 +109,7 @@ function adoptDevDependencies(donorData, hostData) {
|
|
|
110
109
|
if (verbose) console.log('Adopting dev dependencies...');
|
|
111
110
|
|
|
112
111
|
/* Inits deps as a map of all donor's dev dependencies. */
|
|
113
|
-
const deps =
|
|
112
|
+
const deps = { ...donorData.devDependencies };
|
|
114
113
|
|
|
115
114
|
/* Removes from the map any prod dependencies of host. */
|
|
116
115
|
Object.entries(hostData.dependencies || {})
|
|
@@ -175,7 +174,7 @@ function getPackageJson(packageName = '@dr.pogodin/react-utils') {
|
|
|
175
174
|
let url = packageName === '@dr.pogodin/react-utils' ? '..' : packageName;
|
|
176
175
|
|
|
177
176
|
// TODO: .slice(5) cuts out file:// schema in front of the URL.
|
|
178
|
-
url =
|
|
177
|
+
url = import.meta.resolve(url).slice(5);
|
|
179
178
|
|
|
180
179
|
for (;;) {
|
|
181
180
|
const files = fs.readdirSync(url);
|
|
@@ -1,40 +1,31 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.default = getInj;
|
|
8
|
-
var _forge = _interopRequireDefault(require("node-forge/lib/forge"));
|
|
9
|
-
require("node-forge/lib/aes");
|
|
10
|
-
var _buildInfo = require("../shared/utils/isomorphy/buildInfo");
|
|
11
1
|
// Encapsulates retrieval of server-side data injection into HTML template.
|
|
12
2
|
|
|
13
3
|
/* global document */
|
|
14
4
|
|
|
15
5
|
// Note: this way, only required part of "node-forge": AES, and some utils,
|
|
16
6
|
// is bundled into client-side code.
|
|
7
|
+
import forge from 'node-forge/lib/forge.js';
|
|
17
8
|
|
|
18
9
|
// eslint-disable-next-line import/no-unassigned-import
|
|
19
|
-
|
|
20
|
-
// Safeguard is needed here, because the server-side version of Docusaurus docs
|
|
10
|
+
import 'node-forge/lib/aes.js';
|
|
11
|
+
import { getBuildInfo } from "../shared/utils/isomorphy/buildInfo.js"; // Safeguard is needed here, because the server-side version of Docusaurus docs
|
|
21
12
|
// is compiled (at least now) with settings suggesting it is a client-side
|
|
22
13
|
// environment, but there is no document.
|
|
23
14
|
let inj = {};
|
|
24
15
|
const metaElement = typeof document === 'undefined' ? null : document.querySelector('meta[itemprop="drpruinj"]');
|
|
25
16
|
if (metaElement) {
|
|
26
17
|
metaElement.remove();
|
|
27
|
-
let data =
|
|
18
|
+
let data = forge.util.decode64(metaElement.content);
|
|
28
19
|
const {
|
|
29
20
|
key
|
|
30
|
-
} =
|
|
31
|
-
const d =
|
|
21
|
+
} = getBuildInfo();
|
|
22
|
+
const d = forge.cipher.createDecipher('AES-CBC', key);
|
|
32
23
|
d.start({
|
|
33
24
|
iv: data.slice(0, key.length)
|
|
34
25
|
});
|
|
35
|
-
d.update(
|
|
26
|
+
d.update(forge.util.createBuffer(data.slice(key.length)));
|
|
36
27
|
d.finish();
|
|
37
|
-
data =
|
|
28
|
+
data = forge.util.decodeUtf8(d.output.data);
|
|
38
29
|
|
|
39
30
|
// TODO: Double-check, if there is a safer alternative to parse it?
|
|
40
31
|
// eslint-disable-next-line no-eval
|
|
@@ -48,7 +39,7 @@ if (metaElement) {
|
|
|
48
39
|
// Docusaurus examples, etc.
|
|
49
40
|
inj = {};
|
|
50
41
|
}
|
|
51
|
-
function getInj() {
|
|
42
|
+
export default function getInj() {
|
|
52
43
|
return inj;
|
|
53
44
|
}
|
|
54
45
|
//# sourceMappingURL=getInj.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getInj.js","names":["
|
|
1
|
+
{"version":3,"file":"getInj.js","names":["forge","getBuildInfo","inj","metaElement","document","querySelector","remove","data","util","decode64","content","key","d","cipher","createDecipher","start","iv","slice","length","update","createBuffer","finish","decodeUtf8","output","eval","window","REACT_UTILS_INJECTION","getInj"],"sources":["../../../src/client/getInj.ts"],"sourcesContent":["// Encapsulates retrieval of server-side data injection into HTML template.\n\n/* global document */\n\n// Note: this way, only required part of \"node-forge\": AES, and some utils,\n// is bundled into client-side code.\nimport forge from 'node-forge/lib/forge.js';\n\n// eslint-disable-next-line import/no-unassigned-import\nimport 'node-forge/lib/aes.js';\n\nimport type { InjT } from 'utils/globalState';\n\nimport { getBuildInfo } from 'utils/isomorphy/buildInfo';\n\n// Safeguard is needed here, because the server-side version of Docusaurus docs\n// is compiled (at least now) with settings suggesting it is a client-side\n// environment, but there is no document.\nlet inj: InjT = {};\n\nconst metaElement: HTMLMetaElement | null = typeof document === 'undefined'\n ? null : document.querySelector('meta[itemprop=\"drpruinj\"]');\n\nif (metaElement) {\n metaElement.remove();\n let data = forge.util.decode64(metaElement.content);\n\n const { key } = getBuildInfo();\n const d = forge.cipher.createDecipher('AES-CBC', key);\n d.start({ iv: data.slice(0, key.length) });\n d.update(forge.util.createBuffer(data.slice(key.length)));\n d.finish();\n\n data = forge.util.decodeUtf8(d.output.data);\n\n // TODO: Double-check, if there is a safer alternative to parse it?\n // eslint-disable-next-line no-eval\n inj = eval(`(${data})`) as InjT;\n} else if (typeof window !== 'undefined' && window.REACT_UTILS_INJECTION) {\n inj = window.REACT_UTILS_INJECTION;\n delete window.REACT_UTILS_INJECTION;\n} else {\n // Otherwise, a bunch of dependent stuff will easily fail in non-standard\n // environments, where no client-side initialization is performed. Like tests,\n // Docusaurus examples, etc.\n inj = {};\n}\n\nexport default function getInj(): InjT {\n return inj;\n}\n"],"mappings":"AAAA;;AAEA;;AAEA;AACA;AACA,OAAOA,KAAK,MAAM,yBAAyB;;AAE3C;AACA,OAAO,uBAAuB;AAAA,SAIrBC,YAAY,kDAErB;AACA;AACA;AACA,IAAIC,GAAS,GAAG,CAAC,CAAC;AAElB,MAAMC,WAAmC,GAAG,OAAOC,QAAQ,KAAK,WAAW,GACvE,IAAI,GAAGA,QAAQ,CAACC,aAAa,CAAC,2BAA2B,CAAC;AAE9D,IAAIF,WAAW,EAAE;EACfA,WAAW,CAACG,MAAM,CAAC,CAAC;EACpB,IAAIC,IAAI,GAAGP,KAAK,CAACQ,IAAI,CAACC,QAAQ,CAACN,WAAW,CAACO,OAAO,CAAC;EAEnD,MAAM;IAAEC;EAAI,CAAC,GAAGV,YAAY,CAAC,CAAC;EAC9B,MAAMW,CAAC,GAAGZ,KAAK,CAACa,MAAM,CAACC,cAAc,CAAC,SAAS,EAAEH,GAAG,CAAC;EACrDC,CAAC,CAACG,KAAK,CAAC;IAAEC,EAAE,EAAET,IAAI,CAACU,KAAK,CAAC,CAAC,EAAEN,GAAG,CAACO,MAAM;EAAE,CAAC,CAAC;EAC1CN,CAAC,CAACO,MAAM,CAACnB,KAAK,CAACQ,IAAI,CAACY,YAAY,CAACb,IAAI,CAACU,KAAK,CAACN,GAAG,CAACO,MAAM,CAAC,CAAC,CAAC;EACzDN,CAAC,CAACS,MAAM,CAAC,CAAC;EAEVd,IAAI,GAAGP,KAAK,CAACQ,IAAI,CAACc,UAAU,CAACV,CAAC,CAACW,MAAM,CAAChB,IAAI,CAAC;;EAE3C;EACA;EACAL,GAAG,GAAGsB,IAAI,CAAC,IAAIjB,IAAI,GAAG,CAAS;AACjC,CAAC,MAAM,IAAI,OAAOkB,MAAM,KAAK,WAAW,IAAIA,MAAM,CAACC,qBAAqB,EAAE;EACxExB,GAAG,GAAGuB,MAAM,CAACC,qBAAqB;EAClC,OAAOD,MAAM,CAACC,qBAAqB;AACrC,CAAC,MAAM;EACL;EACA;EACA;EACAxB,GAAG,GAAG,CAAC,CAAC;AACV;AAEA,eAAe,SAASyB,MAAMA,CAAA,EAAS;EACrC,OAAOzB,GAAG;AACZ","ignoreList":[]}
|
|
@@ -1,38 +1,31 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.default = Launch;
|
|
8
|
-
var _client = require("react-dom/client");
|
|
9
|
-
var _reactHelmet = require("@dr.pogodin/react-helmet");
|
|
10
|
-
var _reactRouter = require("react-router");
|
|
11
|
-
var _reactGlobalState = require("@dr.pogodin/react-global-state");
|
|
12
|
-
var _getInj = _interopRequireDefault(require("./getInj"));
|
|
13
|
-
var _jsxRuntime = require("react/jsx-runtime");
|
|
14
1
|
// Initialization of client-side code.
|
|
15
2
|
/* global document */
|
|
16
3
|
|
|
4
|
+
import { createRoot, hydrateRoot } from 'react-dom/client';
|
|
5
|
+
import { HelmetProvider } from '@dr.pogodin/react-helmet';
|
|
6
|
+
import { BrowserRouter } from 'react-router';
|
|
7
|
+
import { GlobalStateProvider } from '@dr.pogodin/react-global-state';
|
|
8
|
+
import getInj from "./getInj.js";
|
|
9
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
17
10
|
/**
|
|
18
11
|
* Prepares and launches the app at client side.
|
|
19
12
|
* @param Application Root application component
|
|
20
13
|
* @param [options={}] Optional. Additional settings.
|
|
21
14
|
*/
|
|
22
|
-
function Launch(Application, options = {}) {
|
|
15
|
+
export default function Launch(Application, options = {}) {
|
|
23
16
|
const container = document.getElementById('react-view');
|
|
24
17
|
if (!container) throw Error('Failed to find container for React app');
|
|
25
|
-
const scene = /*#__PURE__*/(
|
|
26
|
-
initialState: (
|
|
27
|
-
children: /*#__PURE__*/(
|
|
28
|
-
children: /*#__PURE__*/(
|
|
29
|
-
children: /*#__PURE__*/(
|
|
18
|
+
const scene = /*#__PURE__*/_jsx(GlobalStateProvider, {
|
|
19
|
+
initialState: getInj().ISTATE ?? options.initialState,
|
|
20
|
+
children: /*#__PURE__*/_jsx(BrowserRouter, {
|
|
21
|
+
children: /*#__PURE__*/_jsx(HelmetProvider, {
|
|
22
|
+
children: /*#__PURE__*/_jsx(Application, {})
|
|
30
23
|
})
|
|
31
24
|
})
|
|
32
25
|
});
|
|
33
26
|
if (options.dontHydrate) {
|
|
34
|
-
const root =
|
|
27
|
+
const root = createRoot(container);
|
|
35
28
|
root.render(scene);
|
|
36
|
-
} else
|
|
29
|
+
} else hydrateRoot(container, scene);
|
|
37
30
|
}
|
|
38
31
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["
|
|
1
|
+
{"version":3,"file":"index.js","names":["createRoot","hydrateRoot","HelmetProvider","BrowserRouter","GlobalStateProvider","getInj","jsx","_jsx","Launch","Application","options","container","document","getElementById","Error","scene","initialState","ISTATE","children","dontHydrate","root","render"],"sources":["../../../src/client/index.tsx"],"sourcesContent":["// Initialization of client-side code.\n/* global document */\n\nimport type { ComponentType } from 'react';\nimport { createRoot, hydrateRoot } from 'react-dom/client';\nimport { HelmetProvider } from '@dr.pogodin/react-helmet';\nimport { BrowserRouter } from 'react-router';\n\nimport { GlobalStateProvider } from '@dr.pogodin/react-global-state';\n\nimport getInj from './getInj';\n\ntype OptionsT = {\n dontHydrate?: boolean;\n initialState?: unknown;\n};\n\n/**\n * Prepares and launches the app at client side.\n * @param Application Root application component\n * @param [options={}] Optional. Additional settings.\n */\nexport default function Launch(\n Application: ComponentType,\n options: OptionsT = {},\n): void {\n const container = document.getElementById('react-view');\n if (!container) throw Error('Failed to find container for React app');\n const scene = (\n <GlobalStateProvider initialState={getInj().ISTATE ?? options.initialState}>\n <BrowserRouter>\n <HelmetProvider>\n <Application />\n </HelmetProvider>\n </BrowserRouter>\n </GlobalStateProvider>\n );\n\n if (options.dontHydrate) {\n const root = createRoot(container);\n root.render(scene);\n } else hydrateRoot(container, scene);\n}\n"],"mappings":"AAAA;AACA;;AAGA,SAASA,UAAU,EAAEC,WAAW,QAAQ,kBAAkB;AAC1D,SAASC,cAAc,QAAQ,0BAA0B;AACzD,SAASC,aAAa,QAAQ,cAAc;AAE5C,SAASC,mBAAmB,QAAQ,gCAAgC;AAAA,OAE7DC,MAAM;AAAiB,SAAAC,GAAA,IAAAC,IAAA;AAO9B;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,MAAMA,CAC5BC,WAA0B,EAC1BC,OAAiB,GAAG,CAAC,CAAC,EAChB;EACN,MAAMC,SAAS,GAAGC,QAAQ,CAACC,cAAc,CAAC,YAAY,CAAC;EACvD,IAAI,CAACF,SAAS,EAAE,MAAMG,KAAK,CAAC,wCAAwC,CAAC;EACrE,MAAMC,KAAK,gBACTR,IAAA,CAACH,mBAAmB;IAACY,YAAY,EAAEX,MAAM,CAAC,CAAC,CAACY,MAAM,IAAIP,OAAO,CAACM,YAAa;IAAAE,QAAA,eACzEX,IAAA,CAACJ,aAAa;MAAAe,QAAA,eACZX,IAAA,CAACL,cAAc;QAAAgB,QAAA,eACbX,IAAA,CAACE,WAAW,IAAE;MAAC,CACD;IAAC,CACJ;EAAC,CACG,CACtB;EAED,IAAIC,OAAO,CAACS,WAAW,EAAE;IACvB,MAAMC,IAAI,GAAGpB,UAAU,CAACW,SAAS,CAAC;IAClCS,IAAI,CAACC,MAAM,CAACN,KAAK,CAAC;EACpB,CAAC,MAAMd,WAAW,CAACU,SAAS,EAAEI,KAAK,CAAC;AACtC","ignoreList":[]}
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _buildInfo = require("../shared/utils/isomorphy/buildInfo");
|
|
4
1
|
/**
|
|
5
2
|
* Initialization of client-side environment.
|
|
6
3
|
*/
|
|
7
|
-
|
|
8
4
|
/* global window */
|
|
9
|
-
|
|
10
|
-
const buildInfo =
|
|
5
|
+
import { getBuildInfo } from "../shared/utils/isomorphy/buildInfo.js";
|
|
6
|
+
const buildInfo = getBuildInfo();
|
|
11
7
|
|
|
12
8
|
// TODO: Should be moved into buildInfo module?
|
|
13
9
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.js","names":["
|
|
1
|
+
{"version":3,"file":"init.js","names":["getBuildInfo","buildInfo","process","env","NODE_ENV","console","warn","window","__DEV_BUILD_INFO__","BUILD_INFO","useServiceWorker","navigator","addEventListener","reg","serviceWorker","register","log","err"],"sources":["../../../src/client/init.ts"],"sourcesContent":["/**\n * Initialization of client-side environment.\n */\n\n/* global window */\n\nimport { type BuildInfoT, getBuildInfo } from 'utils/isomorphy/buildInfo';\n\nconst buildInfo = getBuildInfo();\n\n// TODO: Should be moved into buildInfo module?\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/consistent-type-definitions\n interface Window {\n __DEV_BUILD_INFO__: BuildInfoT | undefined;\n }\n}\n\ndeclare const BUILD_INFO: BuildInfoT | undefined;\n\nif (process.env.NODE_ENV !== 'production') {\n // eslint-disable-next-line no-console\n console.warn('Dev mode: \"BUILD_INFO\" attached to the global \"window\"');\n\n // eslint-disable-next-line no-underscore-dangle\n window.__DEV_BUILD_INFO__ = BUILD_INFO;\n}\n\n/* TODO: A proper logger should be moved to `@dr.pogodin/react-utils`. */\nconst { useServiceWorker } = buildInfo;\nif (useServiceWorker) {\n const { navigator } = window;\n if ('serviceWorker' in navigator) {\n window.addEventListener('load', () => {\n void (async () => {\n try {\n // Note: no matter the \"publicPath\", we want to serve the service worker\n // from the web app root, to allow it control any and all pages of the\n // web app (otherwise, it will be restricted to the scope of its path).\n // The server takes it into account.\n const reg = await navigator\n .serviceWorker.register('/__service-worker.js');\n // eslint-disable-next-line no-console\n console.log('SW registered:', reg);\n } catch (err) {\n // eslint-disable-next-line no-console\n console.log('SW registration failed:', err);\n }\n })();\n });\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AAEA;AAAA,SAE0BA,YAAY;AAEtC,MAAMC,SAAS,GAAGD,YAAY,CAAC,CAAC;;AAEhC;;AAUA,IAAIE,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,EAAE;EACzC;EACAC,OAAO,CAACC,IAAI,CAAC,wDAAwD,CAAC;;EAEtE;EACAC,MAAM,CAACC,kBAAkB,GAAGC,UAAU;AACxC;;AAEA;AACA,MAAM;EAAEC;AAAiB,CAAC,GAAGT,SAAS;AACtC,IAAIS,gBAAgB,EAAE;EACpB,MAAM;IAAEC;EAAU,CAAC,GAAGJ,MAAM;EAC5B,IAAI,eAAe,IAAII,SAAS,EAAE;IAChCJ,MAAM,CAACK,gBAAgB,CAAC,MAAM,EAAE,MAAM;MACpC,KAAK,CAAC,YAAY;QAChB,IAAI;UACF;UACA;UACA;UACA;UACA,MAAMC,GAAG,GAAG,MAAMF,SAAS,CACxBG,aAAa,CAACC,QAAQ,CAAC,sBAAsB,CAAC;UACjD;UACAV,OAAO,CAACW,GAAG,CAAC,gBAAgB,EAAEH,GAAG,CAAC;QACpC,CAAC,CAAC,OAAOI,GAAG,EAAE;UACZ;UACAZ,OAAO,CAACW,GAAG,CAAC,yBAAyB,EAAEC,GAAG,CAAC;QAC7C;MACF,CAAC,EAAE,CAAC;IACN,CAAC,CAAC;EACJ;AACF","ignoreList":[]}
|
|
@@ -1,178 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
var _exportNames = {
|
|
8
|
-
client: true,
|
|
9
|
-
server: true,
|
|
10
|
-
assertEmptyObject: true,
|
|
11
|
-
config: true,
|
|
12
|
-
Barrier: true,
|
|
13
|
-
Cached: true,
|
|
14
|
-
Emitter: true,
|
|
15
|
-
isomorphy: true,
|
|
16
|
-
getSsrContext: true,
|
|
17
|
-
Semaphore: true,
|
|
18
|
-
splitComponent: true,
|
|
19
|
-
themed: true,
|
|
20
|
-
ThemeProvider: true,
|
|
21
|
-
time: true,
|
|
22
|
-
webpack: true,
|
|
23
|
-
withRetries: true,
|
|
24
|
-
getGlobalState: true,
|
|
25
|
-
GlobalStateProvider: true,
|
|
26
|
-
newAsyncDataEnvelope: true,
|
|
27
|
-
useAsyncCollection: true,
|
|
28
|
-
useAsyncData: true,
|
|
29
|
-
useGlobalState: true,
|
|
30
|
-
withGlobalStateType: true
|
|
31
|
-
};
|
|
32
|
-
Object.defineProperty(exports, "Barrier", {
|
|
33
|
-
enumerable: true,
|
|
34
|
-
get: function () {
|
|
35
|
-
return _utils.Barrier;
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
Object.defineProperty(exports, "Cached", {
|
|
39
|
-
enumerable: true,
|
|
40
|
-
get: function () {
|
|
41
|
-
return _utils.Cached;
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
Object.defineProperty(exports, "Emitter", {
|
|
45
|
-
enumerable: true,
|
|
46
|
-
get: function () {
|
|
47
|
-
return _utils.Emitter;
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
Object.defineProperty(exports, "GlobalStateProvider", {
|
|
51
|
-
enumerable: true,
|
|
52
|
-
get: function () {
|
|
53
|
-
return _reactGlobalState.GlobalStateProvider;
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
Object.defineProperty(exports, "Semaphore", {
|
|
57
|
-
enumerable: true,
|
|
58
|
-
get: function () {
|
|
59
|
-
return _utils.Semaphore;
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
Object.defineProperty(exports, "ThemeProvider", {
|
|
63
|
-
enumerable: true,
|
|
64
|
-
get: function () {
|
|
65
|
-
return _utils.ThemeProvider;
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
Object.defineProperty(exports, "assertEmptyObject", {
|
|
69
|
-
enumerable: true,
|
|
70
|
-
get: function () {
|
|
71
|
-
return _utils.assertEmptyObject;
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
exports.client = void 0;
|
|
75
|
-
Object.defineProperty(exports, "config", {
|
|
76
|
-
enumerable: true,
|
|
77
|
-
get: function () {
|
|
78
|
-
return _utils.config;
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
Object.defineProperty(exports, "getGlobalState", {
|
|
82
|
-
enumerable: true,
|
|
83
|
-
get: function () {
|
|
84
|
-
return _reactGlobalState.getGlobalState;
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
Object.defineProperty(exports, "getSsrContext", {
|
|
88
|
-
enumerable: true,
|
|
89
|
-
get: function () {
|
|
90
|
-
return _utils.getSsrContext;
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
Object.defineProperty(exports, "isomorphy", {
|
|
94
|
-
enumerable: true,
|
|
95
|
-
get: function () {
|
|
96
|
-
return _utils.isomorphy;
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
Object.defineProperty(exports, "newAsyncDataEnvelope", {
|
|
100
|
-
enumerable: true,
|
|
101
|
-
get: function () {
|
|
102
|
-
return _reactGlobalState.newAsyncDataEnvelope;
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
exports.server = void 0;
|
|
106
|
-
Object.defineProperty(exports, "splitComponent", {
|
|
107
|
-
enumerable: true,
|
|
108
|
-
get: function () {
|
|
109
|
-
return _utils.splitComponent;
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
Object.defineProperty(exports, "themed", {
|
|
113
|
-
enumerable: true,
|
|
114
|
-
get: function () {
|
|
115
|
-
return _utils.themed;
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
Object.defineProperty(exports, "time", {
|
|
119
|
-
enumerable: true,
|
|
120
|
-
get: function () {
|
|
121
|
-
return _utils.time;
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
Object.defineProperty(exports, "useAsyncCollection", {
|
|
125
|
-
enumerable: true,
|
|
126
|
-
get: function () {
|
|
127
|
-
return _reactGlobalState.useAsyncCollection;
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
Object.defineProperty(exports, "useAsyncData", {
|
|
131
|
-
enumerable: true,
|
|
132
|
-
get: function () {
|
|
133
|
-
return _reactGlobalState.useAsyncData;
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
Object.defineProperty(exports, "useGlobalState", {
|
|
137
|
-
enumerable: true,
|
|
138
|
-
get: function () {
|
|
139
|
-
return _reactGlobalState.useGlobalState;
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
Object.defineProperty(exports, "webpack", {
|
|
143
|
-
enumerable: true,
|
|
144
|
-
get: function () {
|
|
145
|
-
return _utils.webpack;
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
Object.defineProperty(exports, "withGlobalStateType", {
|
|
149
|
-
enumerable: true,
|
|
150
|
-
get: function () {
|
|
151
|
-
return _reactGlobalState.withGlobalStateType;
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
Object.defineProperty(exports, "withRetries", {
|
|
155
|
-
enumerable: true,
|
|
156
|
-
get: function () {
|
|
157
|
-
return _utils.withRetries;
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
var _client = _interopRequireDefault(require("./client"));
|
|
161
|
-
var _utils = require("./shared/utils");
|
|
162
|
-
var _reactGlobalState = require("@dr.pogodin/react-global-state");
|
|
163
|
-
var _components = require("./shared/components");
|
|
164
|
-
Object.keys(_components).forEach(function (key) {
|
|
165
|
-
if (key === "default" || key === "__esModule") return;
|
|
166
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
167
|
-
if (key in exports && exports[key] === _components[key]) return;
|
|
168
|
-
Object.defineProperty(exports, key, {
|
|
169
|
-
enumerable: true,
|
|
170
|
-
get: function () {
|
|
171
|
-
return _components[key];
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
});
|
|
175
|
-
// It is a safeguard against multiple instances / versions of the library
|
|
1
|
+
import clientModule from "./client/index.js";
|
|
2
|
+
import { webpack } from "./shared/utils/index.js"; // It is a safeguard against multiple instances / versions of the library
|
|
176
3
|
// being loaded into environment by mistake (e.g. because of different
|
|
177
4
|
// packages pinning down different exact versions of the lib, thus preventing
|
|
178
5
|
// a proper dedupe and using a single common library version).
|
|
@@ -183,8 +10,12 @@ if (global.REACT_UTILS_LIBRARY_LOADED) {
|
|
|
183
10
|
// TODO: This is a rapid workaround to get rid of __dirname. I guess, later
|
|
184
11
|
// we'll re-implement requireWeak() to accept import.meta.url directly, and
|
|
185
12
|
// this workaround won't be needed.
|
|
186
|
-
let dirname =
|
|
13
|
+
let dirname = import.meta.url;
|
|
187
14
|
dirname = dirname.slice(5, dirname.lastIndexOf('/'));
|
|
188
|
-
const server =
|
|
189
|
-
const client =
|
|
15
|
+
const server = webpack.requireWeak("./server", dirname);
|
|
16
|
+
const client = server ? undefined : clientModule;
|
|
17
|
+
export { getGlobalState, GlobalStateProvider, newAsyncDataEnvelope, useAsyncCollection, useAsyncData, useGlobalState, withGlobalStateType } from '@dr.pogodin/react-global-state';
|
|
18
|
+
export * from "./shared/components/index.js";
|
|
19
|
+
export { assertEmptyObject, config, Barrier, Cached, Emitter, isomorphy, getSsrContext, Semaphore, splitComponent, themed, ThemeProvider, time, webpack, withRetries } from "./shared/utils/index.js";
|
|
20
|
+
export { client, server };
|
|
190
21
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["
|
|
1
|
+
{"version":3,"file":"index.js","names":["clientModule","webpack","global","REACT_UTILS_LIBRARY_LOADED","Error","dirname","import","meta","url","slice","lastIndexOf","server","requireWeak","client","undefined","getGlobalState","GlobalStateProvider","newAsyncDataEnvelope","useAsyncCollection","useAsyncData","useGlobalState","withGlobalStateType","assertEmptyObject","config","Barrier","Cached","Emitter","isomorphy","getSsrContext","Semaphore","splitComponent","themed","ThemeProvider","time","withRetries"],"sources":["../../src/index.ts"],"sourcesContent":["import 'styles/global.scss';\n\nimport clientModule from './client';\nimport { webpack } from './shared/utils';\n\nimport type * as ServerFactoryM from './server';\n\n// It is a safeguard against multiple instances / versions of the library\n// being loaded into environment by mistake (e.g. because of different\n// packages pinning down different exact versions of the lib, thus preventing\n// a proper dedupe and using a single common library version).\nif (global.REACT_UTILS_LIBRARY_LOADED) {\n throw Error('React utils library is already loaded');\n} else global.REACT_UTILS_LIBRARY_LOADED = true;\n\n// TODO: This is a rapid workaround to get rid of __dirname. I guess, later\n// we'll re-implement requireWeak() to accept import.meta.url directly, and\n// this workaround won't be needed.\nlet dirname = import.meta.url;\ndirname = dirname.slice(5, dirname.lastIndexOf('/'));\n\nconst server = webpack.requireWeak<typeof ServerFactoryM>('./server', dirname);\n\nconst client = server ? undefined : clientModule;\n\nexport {\n type AsyncCollectionT,\n type AsyncCollectionLoaderT,\n type AsyncDataEnvelopeT,\n type AsyncDataLoaderT,\n type ForceT,\n type UseAsyncDataOptionsT,\n type UseAsyncDataResT,\n type UseGlobalStateResT,\n type ValueOrInitializerT,\n getGlobalState,\n GlobalStateProvider,\n newAsyncDataEnvelope,\n useAsyncCollection,\n useAsyncData,\n useGlobalState,\n withGlobalStateType,\n} from '@dr.pogodin/react-global-state';\n\nexport * from 'components';\n\nexport {\n type BeforeRenderResT,\n type BeforeRenderT,\n type ConfigT,\n type ServerSsrContext,\n type ServerT,\n} from './server';\n\nexport {\n assertEmptyObject,\n config,\n Barrier,\n Cached,\n Emitter,\n isomorphy,\n getSsrContext,\n type Listener,\n type ObjectKey,\n Semaphore,\n splitComponent,\n type Theme,\n themed,\n ThemeProvider,\n time,\n webpack,\n withRetries,\n} from 'utils';\n\nexport { client, server };\n"],"mappings":"OAEOA,YAAY;AAAA,SACVC,OAAO,mCAIhB;AACA;AACA;AACA;AACA,IAAIC,MAAM,CAACC,0BAA0B,EAAE;EACrC,MAAMC,KAAK,CAAC,uCAAuC,CAAC;AACtD,CAAC,MAAMF,MAAM,CAACC,0BAA0B,GAAG,IAAI;;AAE/C;AACA;AACA;AACA,IAAIE,OAAO,GAAGC,MAAM,CAACC,IAAI,CAACC,GAAG;AAC7BH,OAAO,GAAGA,OAAO,CAACI,KAAK,CAAC,CAAC,EAAEJ,OAAO,CAACK,WAAW,CAAC,GAAG,CAAC,CAAC;AAEpD,MAAMC,MAAM,GAAGV,OAAO,CAACW,WAAW,aAAoCP,OAAO,CAAC;AAE9E,MAAMQ,MAAM,GAAGF,MAAM,GAAGG,SAAS,GAAGd,YAAY;AAEhD,SAUEe,cAAc,EACdC,mBAAmB,EACnBC,oBAAoB,EACpBC,kBAAkB,EAClBC,YAAY,EACZC,cAAc,EACdC,mBAAmB,QACd,gCAAgC;AAAA;AAAA,SAarCC,iBAAiB,EACjBC,MAAM,EACNC,OAAO,EACPC,MAAM,EACNC,OAAO,EACPC,SAAS,EACTC,aAAa,EAGbC,SAAS,EACTC,cAAc,EAEdC,MAAM,EACNC,aAAa,EACbC,IAAI,EACJhC,OAAO,EACPiC,WAAW;AAGb,SAASrB,MAAM,EAAEF,MAAM","ignoreList":[]}
|
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
1
|
/**
|
|
8
2
|
* Implements the static cache.
|
|
9
3
|
*/
|
|
10
|
-
class Cache {
|
|
4
|
+
export default class Cache {
|
|
11
5
|
items = {};
|
|
12
6
|
size = 0;
|
|
13
7
|
constructor(maxSize) {
|
|
@@ -57,5 +51,4 @@ class Cache {
|
|
|
57
51
|
}
|
|
58
52
|
}
|
|
59
53
|
}
|
|
60
|
-
exports.default = Cache;
|
|
61
54
|
//# sourceMappingURL=Cache.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Cache.js","names":["Cache","items","size","constructor","maxSize","get","key","maxage","Number","MAX_VALUE","item","Date","now","timestamp","data","add","cached","entries","Object","sort","a","b","entry","itemKey"
|
|
1
|
+
{"version":3,"file":"Cache.js","names":["Cache","items","size","constructor","maxSize","get","key","maxage","Number","MAX_VALUE","item","Date","now","timestamp","data","add","cached","entries","Object","sort","a","b","entry","itemKey"],"sources":["../../../src/server/Cache.ts"],"sourcesContent":["type CachedItemT<DatumT> = {\n data: DatumT;\n size: number;\n timestamp: number;\n};\n\n/**\n * Implements the static cache.\n */\nexport default class Cache<DatumT> {\n private items: Record<string, CachedItemT<DatumT>> = {};\n\n private size = 0;\n\n constructor(private maxSize: number) { }\n\n /**\n * Cache lookup.\n * @param key Item key to look for.\n * @param [maxage=Number.MAX_VALUE] Optional. The maximum age of\n * cached item to serve. Default to infinite.\n * @returns Cached item, or null if the item is absent in cache,\n * or stale.\n */\n get({\n key,\n maxage = Number.MAX_VALUE,\n }: {\n key: string;\n maxage?: number;\n }): DatumT | null {\n const item = this.items[key];\n return item && Date.now() - item.timestamp < maxage ? item.data : null;\n }\n\n /**\n * Adds item to cache.\n * @param data Item to add.\n * @param key Key to store the item at.\n * @param size Byte size of the item.\n */\n add(data: DatumT, key: string, size: number): void {\n const cached = this.items[key];\n if (cached) this.size -= cached.size;\n\n this.items[key] = { data, size, timestamp: Date.now() };\n this.size += size;\n\n if (this.size > this.maxSize) {\n const entries = Object.entries(this.items);\n entries.sort((a, b) => a[1].timestamp - b[1].timestamp);\n\n for (const entry of entries) {\n const [itemKey, item] = entry;\n delete this.items[itemKey];\n this.size -= item.size;\n if (this.size < this.maxSize / 2) break;\n }\n }\n }\n}\n"],"mappings":"AAMA;AACA;AACA;AACA,eAAe,MAAMA,KAAK,CAAS;EACzBC,KAAK,GAAwC,CAAC,CAAC;EAE/CC,IAAI,GAAG,CAAC;EAEhBC,WAAWA,CAASC,OAAe,EAAE;IAAA,KAAjBA,OAAe,GAAfA,OAAe;EAAI;;EAEvC;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACEC,GAAGA,CAAC;IACFC,GAAG;IACHC,MAAM,GAAGC,MAAM,CAACC;EAIlB,CAAC,EAAiB;IAChB,MAAMC,IAAI,GAAG,IAAI,CAACT,KAAK,CAACK,GAAG,CAAC;IAC5B,OAAOI,IAAI,IAAIC,IAAI,CAACC,GAAG,CAAC,CAAC,GAAGF,IAAI,CAACG,SAAS,GAAGN,MAAM,GAAGG,IAAI,CAACI,IAAI,GAAG,IAAI;EACxE;;EAEA;AACF;AACA;AACA;AACA;AACA;EACEC,GAAGA,CAACD,IAAY,EAAER,GAAW,EAAEJ,IAAY,EAAQ;IACjD,MAAMc,MAAM,GAAG,IAAI,CAACf,KAAK,CAACK,GAAG,CAAC;IAC9B,IAAIU,MAAM,EAAE,IAAI,CAACd,IAAI,IAAIc,MAAM,CAACd,IAAI;IAEpC,IAAI,CAACD,KAAK,CAACK,GAAG,CAAC,GAAG;MAAEQ,IAAI;MAAEZ,IAAI;MAAEW,SAAS,EAAEF,IAAI,CAACC,GAAG,CAAC;IAAE,CAAC;IACvD,IAAI,CAACV,IAAI,IAAIA,IAAI;IAEjB,IAAI,IAAI,CAACA,IAAI,GAAG,IAAI,CAACE,OAAO,EAAE;MAC5B,MAAMa,OAAO,GAAGC,MAAM,CAACD,OAAO,CAAC,IAAI,CAAChB,KAAK,CAAC;MAC1CgB,OAAO,CAACE,IAAI,CAAC,CAACC,CAAC,EAAEC,CAAC,KAAKD,CAAC,CAAC,CAAC,CAAC,CAACP,SAAS,GAAGQ,CAAC,CAAC,CAAC,CAAC,CAACR,SAAS,CAAC;MAEvD,KAAK,MAAMS,KAAK,IAAIL,OAAO,EAAE;QAC3B,MAAM,CAACM,OAAO,EAAEb,IAAI,CAAC,GAAGY,KAAK;QAC7B,OAAO,IAAI,CAACrB,KAAK,CAACsB,OAAO,CAAC;QAC1B,IAAI,CAACrB,IAAI,IAAIQ,IAAI,CAACR,IAAI;QACtB,IAAI,IAAI,CAACA,IAAI,GAAG,IAAI,CAACE,OAAO,GAAG,CAAC,EAAE;MACpC;IACF;EACF;AACF","ignoreList":[]}
|