@dr.pogodin/react-utils 1.47.0-alpha.2 → 1.47.0-alpha.4

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.
Files changed (223) hide show
  1. package/babel.config.js +1 -1
  2. package/babel.module.config.js +11 -0
  3. package/bin/build.js +8 -4
  4. package/bin/setup.js +2 -3
  5. package/build/development/client/getInj.js +47 -45
  6. package/build/development/client/getInj.js.map +1 -1
  7. package/build/development/client/index.js +15 -21
  8. package/build/development/client/index.js.map +1 -1
  9. package/build/development/client/init.js +2 -6
  10. package/build/development/client/init.js.map +1 -1
  11. package/build/development/index.js +10 -179
  12. package/build/development/index.js.map +1 -1
  13. package/build/development/server/Cache.js +1 -8
  14. package/build/development/server/Cache.js.map +1 -1
  15. package/build/development/server/index.js +25 -50
  16. package/build/development/server/index.js.map +1 -1
  17. package/build/development/server/renderer.js +63 -92
  18. package/build/development/server/renderer.js.map +1 -1
  19. package/build/development/server/server.js +47 -58
  20. package/build/development/server/server.js.map +1 -1
  21. package/build/development/server/utils/errors.js +8 -31
  22. package/build/development/server/utils/errors.js.map +1 -1
  23. package/build/development/server/utils/index.js +2 -9
  24. package/build/development/server/utils/index.js.map +1 -1
  25. package/build/development/shared/components/Button/index.js +9 -16
  26. package/build/development/shared/components/Button/index.js.map +1 -1
  27. package/build/development/shared/components/Checkbox/index.js +6 -13
  28. package/build/development/shared/components/Checkbox/index.js.map +1 -1
  29. package/build/development/shared/components/GenericLink/index.js +4 -10
  30. package/build/development/shared/components/GenericLink/index.js.map +1 -1
  31. package/build/development/shared/components/Input/index.js +11 -18
  32. package/build/development/shared/components/Input/index.js.map +1 -1
  33. package/build/development/shared/components/Link.js +6 -13
  34. package/build/development/shared/components/Link.js.map +1 -1
  35. package/build/development/shared/components/Modal/index.js +16 -22
  36. package/build/development/shared/components/Modal/index.js.map +1 -1
  37. package/build/development/shared/components/NavLink.js +6 -13
  38. package/build/development/shared/components/NavLink.js.map +1 -1
  39. package/build/development/shared/components/PageLayout/index.js +7 -14
  40. package/build/development/shared/components/PageLayout/index.js.map +1 -1
  41. package/build/development/shared/components/TextArea/index.js +15 -22
  42. package/build/development/shared/components/TextArea/index.js.map +1 -1
  43. package/build/development/shared/components/Throbber/index.js +7 -14
  44. package/build/development/shared/components/Throbber/index.js.map +1 -1
  45. package/build/development/shared/components/WithTooltip/Tooltip.js +12 -18
  46. package/build/development/shared/components/WithTooltip/Tooltip.js.map +1 -1
  47. package/build/development/shared/components/WithTooltip/index.js +16 -23
  48. package/build/development/shared/components/WithTooltip/index.js.map +1 -1
  49. package/build/development/shared/components/YouTubeVideo/index.js +10 -17
  50. package/build/development/shared/components/YouTubeVideo/index.js.map +1 -1
  51. package/build/development/shared/components/index.js +16 -130
  52. package/build/development/shared/components/index.js.map +1 -1
  53. package/build/development/shared/components/selectors/CustomDropdown/Options/index.js +12 -19
  54. package/build/development/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
  55. package/build/development/shared/components/selectors/CustomDropdown/index.js +20 -28
  56. package/build/development/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  57. package/build/development/shared/components/selectors/NativeDropdown/index.js +13 -19
  58. package/build/development/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  59. package/build/development/shared/components/selectors/Switch/index.js +10 -17
  60. package/build/development/shared/components/selectors/Switch/index.js.map +1 -1
  61. package/build/development/shared/components/selectors/common.js +1 -7
  62. package/build/development/shared/components/selectors/common.js.map +1 -1
  63. package/build/development/shared/components/selectors/index.js +3 -27
  64. package/build/development/shared/components/selectors/index.js.map +1 -1
  65. package/build/development/shared/utils/config.js +40 -20
  66. package/build/development/shared/utils/config.js.map +1 -1
  67. package/build/development/shared/utils/globalState.js +3 -8
  68. package/build/development/shared/utils/globalState.js.map +1 -1
  69. package/build/development/shared/utils/index.js +12 -89
  70. package/build/development/shared/utils/index.js.map +1 -1
  71. package/build/development/shared/utils/isomorphy/buildInfo.js +2 -9
  72. package/build/development/shared/utils/isomorphy/buildInfo.js.map +1 -1
  73. package/build/development/shared/utils/isomorphy/environment-check.js +2 -8
  74. package/build/development/shared/utils/isomorphy/environment-check.js.map +1 -1
  75. package/build/development/shared/utils/isomorphy/index.js +7 -32
  76. package/build/development/shared/utils/isomorphy/index.js.map +1 -1
  77. package/build/development/shared/utils/jest/E2eSsrEnv.js +20 -31
  78. package/build/development/shared/utils/jest/E2eSsrEnv.js.map +1 -1
  79. package/build/development/shared/utils/jest/global.js +1 -7
  80. package/build/development/shared/utils/jest/global.js.map +1 -1
  81. package/build/development/shared/utils/jest/index.js +20 -44
  82. package/build/development/shared/utils/jest/index.js.map +1 -1
  83. package/build/development/shared/utils/splitComponent.js +24 -30
  84. package/build/development/shared/utils/splitComponent.js.map +1 -1
  85. package/build/development/shared/utils/time.js +22 -31
  86. package/build/development/shared/utils/time.js.map +1 -1
  87. package/build/development/shared/utils/webpack.js +13 -16
  88. package/build/development/shared/utils/webpack.js.map +1 -1
  89. package/build/production/client/getInj.js +13 -11
  90. package/build/production/client/getInj.js.map +1 -1
  91. package/build/production/client/index.js +3 -3
  92. package/build/production/client/index.js.map +1 -1
  93. package/build/production/client/init.js +2 -2
  94. package/build/production/client/init.js.map +1 -1
  95. package/build/production/index.js +3 -2
  96. package/build/production/index.js.map +1 -1
  97. package/build/production/server/Cache.js +3 -3
  98. package/build/production/server/Cache.js.map +1 -1
  99. package/build/production/server/index.js +8 -8
  100. package/build/production/server/index.js.map +1 -1
  101. package/build/production/server/renderer.js +24 -25
  102. package/build/production/server/renderer.js.map +1 -1
  103. package/build/production/server/server.js +9 -9
  104. package/build/production/server/server.js.map +1 -1
  105. package/build/production/server/utils/errors.js +9 -9
  106. package/build/production/server/utils/errors.js.map +1 -1
  107. package/build/production/server/utils/index.js +2 -1
  108. package/build/production/server/utils/index.js.map +1 -1
  109. package/build/production/shared/components/Button/index.js +4 -4
  110. package/build/production/shared/components/Button/index.js.map +1 -1
  111. package/build/production/shared/components/Checkbox/index.js +1 -1
  112. package/build/production/shared/components/Checkbox/index.js.map +1 -1
  113. package/build/production/shared/components/GenericLink/index.js +4 -4
  114. package/build/production/shared/components/GenericLink/index.js.map +1 -1
  115. package/build/production/shared/components/Input/index.js +5 -5
  116. package/build/production/shared/components/Input/index.js.map +1 -1
  117. package/build/production/shared/components/Link.js +3 -3
  118. package/build/production/shared/components/Link.js.map +1 -1
  119. package/build/production/shared/components/Modal/index.js +7 -7
  120. package/build/production/shared/components/Modal/index.js.map +1 -1
  121. package/build/production/shared/components/NavLink.js +2 -2
  122. package/build/production/shared/components/NavLink.js.map +1 -1
  123. package/build/production/shared/components/PageLayout/index.js +2 -2
  124. package/build/production/shared/components/PageLayout/index.js.map +1 -1
  125. package/build/production/shared/components/TextArea/index.js +5 -5
  126. package/build/production/shared/components/TextArea/index.js.map +1 -1
  127. package/build/production/shared/components/Throbber/index.js +2 -2
  128. package/build/production/shared/components/Throbber/index.js.map +1 -1
  129. package/build/production/shared/components/WithTooltip/Tooltip.js +4 -4
  130. package/build/production/shared/components/WithTooltip/Tooltip.js.map +1 -1
  131. package/build/production/shared/components/WithTooltip/index.js +4 -4
  132. package/build/production/shared/components/WithTooltip/index.js.map +1 -1
  133. package/build/production/shared/components/YouTubeVideo/index.js +4 -4
  134. package/build/production/shared/components/YouTubeVideo/index.js.map +1 -1
  135. package/build/production/shared/components/index.js +3 -1
  136. package/build/production/shared/components/index.js.map +1 -1
  137. package/build/production/shared/components/selectors/CustomDropdown/Options/index.js +2 -2
  138. package/build/production/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
  139. package/build/production/shared/components/selectors/CustomDropdown/index.js +2 -2
  140. package/build/production/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  141. package/build/production/shared/components/selectors/NativeDropdown/index.js +4 -4
  142. package/build/production/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  143. package/build/production/shared/components/selectors/Switch/index.js +1 -1
  144. package/build/production/shared/components/selectors/Switch/index.js.map +1 -1
  145. package/build/production/shared/components/selectors/common.js +2 -2
  146. package/build/production/shared/components/selectors/common.js.map +1 -1
  147. package/build/production/shared/components/selectors/index.js +1 -1
  148. package/build/production/shared/components/selectors/index.js.map +1 -1
  149. package/build/production/shared/utils/config.js +8 -4
  150. package/build/production/shared/utils/config.js.map +1 -1
  151. package/build/production/shared/utils/globalState.js +2 -2
  152. package/build/production/shared/utils/globalState.js.map +1 -1
  153. package/build/production/shared/utils/index.js +1 -1
  154. package/build/production/shared/utils/index.js.map +1 -1
  155. package/build/production/shared/utils/isomorphy/buildInfo.js +3 -3
  156. package/build/production/shared/utils/isomorphy/buildInfo.js.map +1 -1
  157. package/build/production/shared/utils/isomorphy/environment-check.js +3 -3
  158. package/build/production/shared/utils/isomorphy/environment-check.js.map +1 -1
  159. package/build/production/shared/utils/isomorphy/index.js +4 -4
  160. package/build/production/shared/utils/isomorphy/index.js.map +1 -1
  161. package/build/production/shared/utils/jest/E2eSsrEnv.js +14 -14
  162. package/build/production/shared/utils/jest/E2eSsrEnv.js.map +1 -1
  163. package/build/production/shared/utils/jest/global.js +1 -1
  164. package/build/production/shared/utils/jest/global.js.map +1 -1
  165. package/build/production/shared/utils/jest/index.js +11 -11
  166. package/build/production/shared/utils/jest/index.js.map +1 -1
  167. package/build/production/shared/utils/splitComponent.js +11 -11
  168. package/build/production/shared/utils/splitComponent.js.map +1 -1
  169. package/build/production/shared/utils/time.js +3 -3
  170. package/build/production/shared/utils/time.js.map +1 -1
  171. package/build/production/shared/utils/webpack.js +6 -6
  172. package/build/production/shared/utils/webpack.js.map +1 -1
  173. package/build/types-code/client/getInj.d.ts +1 -2
  174. package/build/types-code/client/index.d.ts +1 -1
  175. package/build/types-code/index.d.ts +1 -1
  176. package/build/types-code/server/index.d.ts +2 -2
  177. package/build/types-code/shared/utils/config.d.ts +4 -2
  178. package/build/types-code/shared/utils/index.d.ts +2 -2
  179. package/build/types-code/shared/utils/splitComponent.d.ts +6 -4
  180. package/build/web/client/getInj.js +48 -37
  181. package/build/web/client/getInj.js.map +1 -1
  182. package/build/web/client/index.js +3 -2
  183. package/build/web/client/index.js.map +1 -1
  184. package/build/web/index.js +3 -3
  185. package/build/web/index.js.map +1 -1
  186. package/build/web/server/index.js +9 -15
  187. package/build/web/server/index.js.map +1 -1
  188. package/build/web/server/renderer.js +24 -40
  189. package/build/web/server/renderer.js.map +1 -1
  190. package/build/web/server/server.js +2 -4
  191. package/build/web/server/server.js.map +1 -1
  192. package/build/web/shared/components/Modal/index.js +2 -2
  193. package/build/web/shared/components/Modal/index.js.map +1 -1
  194. package/build/web/shared/utils/config.js +36 -10
  195. package/build/web/shared/utils/config.js.map +1 -1
  196. package/build/web/shared/utils/index.js +2 -2
  197. package/build/web/shared/utils/index.js.map +1 -1
  198. package/build/web/shared/utils/jest/E2eSsrEnv.js +1 -2
  199. package/build/web/shared/utils/jest/E2eSsrEnv.js.map +1 -1
  200. package/build/web/shared/utils/splitComponent.js +2 -1
  201. package/build/web/shared/utils/splitComponent.js.map +1 -1
  202. package/build/web/shared/utils/webpack.js +11 -7
  203. package/build/web/shared/utils/webpack.js.map +1 -1
  204. package/config/babel/node-ssr.js +5 -5
  205. package/config/jest/default.js +1 -0
  206. package/config/jest/setup.js +8 -1
  207. package/config/webpack/app-base.js +13 -12
  208. package/config/webpack/app-development.js +3 -3
  209. package/config/webpack/lib-base.js +1 -2
  210. package/package.json +9 -9
  211. package/src/client/getInj.ts +60 -40
  212. package/src/client/index.tsx +5 -3
  213. package/src/index.ts +3 -3
  214. package/src/server/index.ts +9 -15
  215. package/src/server/renderer.tsx +27 -45
  216. package/src/server/server.ts +2 -4
  217. package/src/shared/components/Modal/index.tsx +2 -2
  218. package/src/shared/utils/config.ts +48 -12
  219. package/src/shared/utils/index.ts +2 -2
  220. package/src/shared/utils/jest/E2eSsrEnv.ts +1 -2
  221. package/src/shared/utils/splitComponent.tsx +14 -2
  222. package/src/shared/utils/webpack.ts +14 -8
  223. package/types.d.ts +1 -6
package/babel.config.js CHANGED
@@ -2,7 +2,7 @@
2
2
  /* global module */
3
3
 
4
4
  module.exports = {
5
- plugins: ['babel-plugin-transform-import-meta'],
5
+ plugins: [['babel-plugin-transform-import-meta', { module: 'ES6' }]],
6
6
  presets: [
7
7
  ['./config/babel/node-ssr', {
8
8
  typescript: true,
@@ -0,0 +1,11 @@
1
+ /* eslint-disable import/no-commonjs */
2
+ /* global module */
3
+
4
+ module.exports = {
5
+ presets: [
6
+ ['./config/babel/node-ssr', {
7
+ modules: false,
8
+ typescript: true,
9
+ }],
10
+ ],
11
+ };
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 isFunction from 'lodash/isFunction.js';
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 (isFunction(webpackConfig)) webpackConfig = webpackConfig(buildType);
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 = clone(donorData.devDependencies) || {};
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 = path.dirname(import.meta.resolve(url).slice(5));
177
+ url = import.meta.resolve(url).slice(5);
179
178
 
180
179
  for (;;) {
181
180
  const files = fs.readdirSync(url);
@@ -1,54 +1,56 @@
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
-
13
2
  /* global document */
3
+ import { getBuildInfo } from "../shared/utils/isomorphy/buildInfo.js";
4
+ let inj;
5
+ export default function getInj() {
6
+ inj ??= (async () => {
7
+ const metaElement = typeof document === 'undefined' ? null : document.querySelector('meta[itemprop="drpruinj"]');
8
+ if (metaElement) {
9
+ metaElement.remove();
14
10
 
15
- // Note: this way, only required part of "node-forge": AES, and some utils,
16
- // is bundled into client-side code.
11
+ // NOTE: Since 2025 there is Uint8Array.fromBase64(), which should be
12
+ // preferred, but it is not supported by older environments yet.
13
+ const data = atob(metaElement.content);
17
14
 
18
- // eslint-disable-next-line import/no-unassigned-import
15
+ // TODO: Our current handling of this encryption / decryption follows
16
+ // a legacy approach, and can be enhanced by using Crypto features.
17
+ // Though, this is not strictly intended to be secure (it is more
18
+ // to obfurscate injected data, rather than really keeping them
19
+ // secure), thus it is fine like this for now.
20
+ const {
21
+ key
22
+ } = getBuildInfo();
23
+ const code = x => x.charCodeAt(0);
24
+ const dataBuffer = Uint8Array.from(data.slice(16), code);
25
+ const ivBuffer = Uint8Array.from(data.slice(0, 16), code);
26
+ const keyBuffer = Uint8Array.from(atob(key), code);
27
+ const cKey = await window.crypto.subtle.importKey('raw', keyBuffer, {
28
+ name: 'AES-CBC'
29
+ }, false, ['decrypt']);
30
+ const buffer = await window.crypto.subtle.decrypt({
31
+ iv: ivBuffer,
32
+ name: 'AES-CBC'
33
+ }, cKey, dataBuffer);
34
+ const decoder = new TextDecoder();
19
35
 
20
- // Safeguard is needed here, because the server-side version of Docusaurus docs
21
- // is compiled (at least now) with settings suggesting it is a client-side
22
- // environment, but there is no document.
23
- let inj = {};
24
- const metaElement = typeof document === 'undefined' ? null : document.querySelector('meta[itemprop="drpruinj"]');
25
- if (metaElement) {
26
- metaElement.remove();
27
- let data = _forge.default.util.decode64(metaElement.content);
28
- const {
29
- key
30
- } = (0, _buildInfo.getBuildInfo)();
31
- const d = _forge.default.cipher.createDecipher('AES-CBC', key);
32
- d.start({
33
- iv: data.slice(0, key.length)
34
- });
35
- d.update(_forge.default.util.createBuffer(data.slice(key.length)));
36
- d.finish();
37
- data = _forge.default.util.decodeUtf8(d.output.data);
36
+ // eslint-disable-next-line no-eval
37
+ const res = eval(`(${decoder.decode(buffer)})`);
38
38
 
39
- // TODO: Double-check, if there is a safer alternative to parse it?
40
- // eslint-disable-next-line no-eval
41
- inj = eval(`(${data})`);
42
- } else if (typeof window !== 'undefined' && window.REACT_UTILS_INJECTION) {
43
- inj = window.REACT_UTILS_INJECTION;
44
- delete window.REACT_UTILS_INJECTION;
45
- } else {
46
- // Otherwise, a bunch of dependent stuff will easily fail in non-standard
47
- // environments, where no client-side initialization is performed. Like tests,
48
- // Docusaurus examples, etc.
49
- inj = {};
50
- }
51
- function getInj() {
39
+ // NOTE: This is important, to be able to return the injection
40
+ // synchronously once it is initialized.
41
+ inj = res;
42
+ return res;
43
+ } else if (typeof window !== 'undefined' && window.REACT_UTILS_INJECTION) {
44
+ const res = window.REACT_UTILS_INJECTION;
45
+ delete window.REACT_UTILS_INJECTION;
46
+ return res;
47
+ }
48
+
49
+ // Otherwise, a bunch of dependent stuff will easily fail in non-standard
50
+ // environments, where no client-side initialization is performed. Like tests,
51
+ // Docusaurus examples, etc.
52
+ return {};
53
+ })();
52
54
  return inj;
53
55
  }
54
56
  //# sourceMappingURL=getInj.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"getInj.js","names":["_forge","_interopRequireDefault","require","_buildInfo","inj","metaElement","document","querySelector","remove","data","forge","util","decode64","content","key","getBuildInfo","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';\n\n// eslint-disable-next-line import/no-unassigned-import\nimport 'node-forge/lib/aes';\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":";;;;;;;AAMA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAGAA,OAAA;AAIA,IAAAC,UAAA,GAAAD,OAAA;AAbA;;AAEA;;AAEA;AACA;;AAGA;;AAOA;AACA;AACA;AACA,IAAIE,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,GAAGC,cAAK,CAACC,IAAI,CAACC,QAAQ,CAACP,WAAW,CAACQ,OAAO,CAAC;EAEnD,MAAM;IAAEC;EAAI,CAAC,GAAG,IAAAC,uBAAY,EAAC,CAAC;EAC9B,MAAMC,CAAC,GAAGN,cAAK,CAACO,MAAM,CAACC,cAAc,CAAC,SAAS,EAAEJ,GAAG,CAAC;EACrDE,CAAC,CAACG,KAAK,CAAC;IAAEC,EAAE,EAAEX,IAAI,CAACY,KAAK,CAAC,CAAC,EAAEP,GAAG,CAACQ,MAAM;EAAE,CAAC,CAAC;EAC1CN,CAAC,CAACO,MAAM,CAACb,cAAK,CAACC,IAAI,CAACa,YAAY,CAACf,IAAI,CAACY,KAAK,CAACP,GAAG,CAACQ,MAAM,CAAC,CAAC,CAAC;EACzDN,CAAC,CAACS,MAAM,CAAC,CAAC;EAEVhB,IAAI,GAAGC,cAAK,CAACC,IAAI,CAACe,UAAU,CAACV,CAAC,CAACW,MAAM,CAAClB,IAAI,CAAC;;EAE3C;EACA;EACAL,GAAG,GAAGwB,IAAI,CAAC,IAAInB,IAAI,GAAG,CAAS;AACjC,CAAC,MAAM,IAAI,OAAOoB,MAAM,KAAK,WAAW,IAAIA,MAAM,CAACC,qBAAqB,EAAE;EACxE1B,GAAG,GAAGyB,MAAM,CAACC,qBAAqB;EAClC,OAAOD,MAAM,CAACC,qBAAqB;AACrC,CAAC,MAAM;EACL;EACA;EACA;EACA1B,GAAG,GAAG,CAAC,CAAC;AACV;AAEe,SAAS2B,MAAMA,CAAA,EAAS;EACrC,OAAO3B,GAAG;AACZ","ignoreList":[]}
1
+ {"version":3,"file":"getInj.js","names":["getBuildInfo","inj","getInj","metaElement","document","querySelector","remove","data","atob","content","key","code","x","charCodeAt","dataBuffer","Uint8Array","from","slice","ivBuffer","keyBuffer","cKey","window","crypto","subtle","importKey","name","buffer","decrypt","iv","decoder","TextDecoder","res","eval","decode","REACT_UTILS_INJECTION"],"sources":["../../../src/client/getInj.ts"],"sourcesContent":["// Encapsulates retrieval of server-side data injection into HTML template.\n\n/* global document */\n\nimport type { InjT } from 'utils/globalState';\n\nimport { getBuildInfo } from 'utils/isomorphy/buildInfo';\n\nlet inj: InjT | Promise<InjT> | undefined;\n\nexport default function getInj(): InjT | Promise<InjT> {\n inj ??= (async () => {\n const metaElement: HTMLMetaElement | null = typeof document === 'undefined'\n ? null : document.querySelector('meta[itemprop=\"drpruinj\"]');\n\n if (metaElement) {\n metaElement.remove();\n\n // NOTE: Since 2025 there is Uint8Array.fromBase64(), which should be\n // preferred, but it is not supported by older environments yet.\n const data = atob(metaElement.content);\n\n // TODO: Our current handling of this encryption / decryption follows\n // a legacy approach, and can be enhanced by using Crypto features.\n // Though, this is not strictly intended to be secure (it is more\n // to obfurscate injected data, rather than really keeping them\n // secure), thus it is fine like this for now.\n const { key } = getBuildInfo();\n\n const code = (x: string) => x.charCodeAt(0);\n const dataBuffer = Uint8Array.from(data.slice(16), code);\n const ivBuffer = Uint8Array.from(data.slice(0, 16), code);\n const keyBuffer = Uint8Array.from(atob(key), code);\n\n const cKey = await window.crypto.subtle.importKey(\n 'raw',\n keyBuffer,\n { name: 'AES-CBC' },\n false,\n ['decrypt'],\n );\n\n const buffer = await window.crypto.subtle.decrypt({\n iv: ivBuffer,\n name: 'AES-CBC',\n }, cKey, dataBuffer);\n\n const decoder = new TextDecoder();\n\n // eslint-disable-next-line no-eval\n const res = eval(`(${decoder.decode(buffer)})`) as InjT;\n\n // NOTE: This is important, to be able to return the injection\n // synchronously once it is initialized.\n inj = res;\n\n return res;\n } else if (typeof window !== 'undefined' && window.REACT_UTILS_INJECTION) {\n const res = window.REACT_UTILS_INJECTION;\n delete window.REACT_UTILS_INJECTION;\n return res;\n }\n\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 return {};\n })();\n\n return inj;\n}\n"],"mappings":"AAAA;AAEA;AAAA,SAISA,YAAY;AAErB,IAAIC,GAAqC;AAEzC,eAAe,SAASC,MAAMA,CAAA,EAAyB;EACrDD,GAAG,KAAK,CAAC,YAAY;IACnB,MAAME,WAAmC,GAAG,OAAOC,QAAQ,KAAK,WAAW,GACvE,IAAI,GAAGA,QAAQ,CAACC,aAAa,CAAC,2BAA2B,CAAC;IAE9D,IAAIF,WAAW,EAAE;MACfA,WAAW,CAACG,MAAM,CAAC,CAAC;;MAEpB;MACA;MACA,MAAMC,IAAI,GAAGC,IAAI,CAACL,WAAW,CAACM,OAAO,CAAC;;MAEtC;MACA;MACA;MACA;MACA;MACA,MAAM;QAAEC;MAAI,CAAC,GAAGV,YAAY,CAAC,CAAC;MAE9B,MAAMW,IAAI,GAAIC,CAAS,IAAKA,CAAC,CAACC,UAAU,CAAC,CAAC,CAAC;MAC3C,MAAMC,UAAU,GAAGC,UAAU,CAACC,IAAI,CAACT,IAAI,CAACU,KAAK,CAAC,EAAE,CAAC,EAAEN,IAAI,CAAC;MACxD,MAAMO,QAAQ,GAAGH,UAAU,CAACC,IAAI,CAACT,IAAI,CAACU,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAEN,IAAI,CAAC;MACzD,MAAMQ,SAAS,GAAGJ,UAAU,CAACC,IAAI,CAACR,IAAI,CAACE,GAAG,CAAC,EAAEC,IAAI,CAAC;MAElD,MAAMS,IAAI,GAAG,MAAMC,MAAM,CAACC,MAAM,CAACC,MAAM,CAACC,SAAS,CAC/C,KAAK,EACLL,SAAS,EACT;QAAEM,IAAI,EAAE;MAAU,CAAC,EACnB,KAAK,EACL,CAAC,SAAS,CACZ,CAAC;MAED,MAAMC,MAAM,GAAG,MAAML,MAAM,CAACC,MAAM,CAACC,MAAM,CAACI,OAAO,CAAC;QAChDC,EAAE,EAAEV,QAAQ;QACZO,IAAI,EAAE;MACR,CAAC,EAAEL,IAAI,EAAEN,UAAU,CAAC;MAEpB,MAAMe,OAAO,GAAG,IAAIC,WAAW,CAAC,CAAC;;MAEjC;MACA,MAAMC,GAAG,GAAGC,IAAI,CAAC,IAAIH,OAAO,CAACI,MAAM,CAACP,MAAM,CAAC,GAAG,CAAS;;MAEvD;MACA;MACAzB,GAAG,GAAG8B,GAAG;MAET,OAAOA,GAAG;IACZ,CAAC,MAAM,IAAI,OAAOV,MAAM,KAAK,WAAW,IAAIA,MAAM,CAACa,qBAAqB,EAAE;MACxE,MAAMH,GAAG,GAAGV,MAAM,CAACa,qBAAqB;MACxC,OAAOb,MAAM,CAACa,qBAAqB;MACnC,OAAOH,GAAG;IACZ;;IAEA;IACA;IACA;IACA,OAAO,CAAC,CAAC;EACX,CAAC,EAAE,CAAC;EAEJ,OAAO9B,GAAG;AACZ","ignoreList":[]}
@@ -1,38 +1,32 @@
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 async function Launch(Application, options = {}) {
16
+ const inj = await getInj();
23
17
  const container = document.getElementById('react-view');
24
18
  if (!container) throw Error('Failed to find container for React app');
25
- const scene = /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactGlobalState.GlobalStateProvider, {
26
- initialState: (0, _getInj.default)().ISTATE ?? options.initialState,
27
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactRouter.BrowserRouter, {
28
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactHelmet.HelmetProvider, {
29
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Application, {})
19
+ const scene = /*#__PURE__*/_jsx(GlobalStateProvider, {
20
+ initialState: inj.ISTATE ?? options.initialState,
21
+ children: /*#__PURE__*/_jsx(BrowserRouter, {
22
+ children: /*#__PURE__*/_jsx(HelmetProvider, {
23
+ children: /*#__PURE__*/_jsx(Application, {})
30
24
  })
31
25
  })
32
26
  });
33
27
  if (options.dontHydrate) {
34
- const root = (0, _client.createRoot)(container);
28
+ const root = createRoot(container);
35
29
  root.render(scene);
36
- } else (0, _client.hydrateRoot)(container, scene);
30
+ } else hydrateRoot(container, scene);
37
31
  }
38
32
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["_client","require","_reactHelmet","_reactRouter","_reactGlobalState","_getInj","_interopRequireDefault","_jsxRuntime","Launch","Application","options","container","document","getElementById","Error","scene","_jsx","GlobalStateProvider","initialState","getInj","ISTATE","children","BrowserRouter","HelmetProvider","dontHydrate","root","createRoot","render","hydrateRoot"],"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":";;;;;;;AAIA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAF,OAAA;AAEA,IAAAG,iBAAA,GAAAH,OAAA;AAEA,IAAAI,OAAA,GAAAC,sBAAA,CAAAL,OAAA;AAA8B,IAAAM,WAAA,GAAAN,OAAA;AAV9B;AACA;;AAgBA;AACA;AACA;AACA;AACA;AACe,SAASO,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,gBACT,IAAAC,eAAA,EAACC,qCAAmB;IAACC,YAAY,EAAE,IAAAC,eAAM,EAAC,CAAC,CAACC,MAAM,IAAIV,OAAO,CAACQ,YAAa;IAAAG,QAAA,eACzE,IAAAL,eAAA,EAACM,0BAAa;MAAAD,QAAA,eACZ,IAAAL,eAAA,EAACO,2BAAc;QAAAF,QAAA,eACb,IAAAL,eAAA,EAACP,WAAW,IAAE;MAAC,CACD;IAAC,CACJ;EAAC,CACG,CACtB;EAED,IAAIC,OAAO,CAACc,WAAW,EAAE;IACvB,MAAMC,IAAI,GAAG,IAAAC,kBAAU,EAACf,SAAS,CAAC;IAClCc,IAAI,CAACE,MAAM,CAACZ,KAAK,CAAC;EACpB,CAAC,MAAM,IAAAa,mBAAW,EAACjB,SAAS,EAAEI,KAAK,CAAC;AACtC","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["createRoot","hydrateRoot","HelmetProvider","BrowserRouter","GlobalStateProvider","getInj","jsx","_jsx","Launch","Application","options","inj","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 async function Launch(\n Application: ComponentType,\n options: OptionsT = {},\n): Promise<void> {\n const inj = await getInj();\n\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={inj.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,eAAeC,MAAMA,CAClCC,WAA0B,EAC1BC,OAAiB,GAAG,CAAC,CAAC,EACP;EACf,MAAMC,GAAG,GAAG,MAAMN,MAAM,CAAC,CAAC;EAE1B,MAAMO,SAAS,GAAGC,QAAQ,CAACC,cAAc,CAAC,YAAY,CAAC;EACvD,IAAI,CAACF,SAAS,EAAE,MAAMG,KAAK,CAAC,wCAAwC,CAAC;EACrE,MAAMC,KAAK,gBACTT,IAAA,CAACH,mBAAmB;IAACa,YAAY,EAAEN,GAAG,CAACO,MAAM,IAAIR,OAAO,CAACO,YAAa;IAAAE,QAAA,eACpEZ,IAAA,CAACJ,aAAa;MAAAgB,QAAA,eACZZ,IAAA,CAACL,cAAc;QAAAiB,QAAA,eACbZ,IAAA,CAACE,WAAW,IAAE;MAAC,CACD;IAAC,CACJ;EAAC,CACG,CACtB;EAED,IAAIC,OAAO,CAACU,WAAW,EAAE;IACvB,MAAMC,IAAI,GAAGrB,UAAU,CAACY,SAAS,CAAC;IAClCS,IAAI,CAACC,MAAM,CAACN,KAAK,CAAC;EACpB,CAAC,MAAMf,WAAW,CAACW,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 = (0, _buildInfo.getBuildInfo)();
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":["_buildInfo","require","buildInfo","getBuildInfo","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":";;AAMA,IAAAA,UAAA,GAAAC,OAAA;AANA;AACA;AACA;;AAEA;;AAIA,MAAMC,SAAS,GAAG,IAAAC,uBAAY,EAAC,CAAC;;AAEhC;;AAUA,IAAIC,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,GAAGV,SAAS;AACtC,IAAIU,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
+ {"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
- "use strict";
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 = require('url').pathToFileURL(__filename).toString();
187
- dirname = dirname.slice(5, dirname.lastIndexOf('/'));
188
- const server = exports.server = _utils.webpack.requireWeak("./server", dirname);
189
- const client = exports.client = server ? undefined : _client.default;
13
+ // eslint-disable-next-line @typescript-eslint/prefer-destructuring
14
+ const dirname = import.meta.dirname;
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, Barrier, Cached, Emitter, getConfig, 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":["_client","_interopRequireDefault","require","_utils","_reactGlobalState","_components","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","global","REACT_UTILS_LIBRARY_LOADED","Error","dirname","pathToFileURL","__filename","toString","slice","lastIndexOf","server","webpack","requireWeak","client","undefined","clientModule"],"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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAsBA,IAAAE,iBAAA,GAAAF,OAAA;AAmBA,IAAAG,WAAA,GAAAH,OAAA;AAAAI,MAAA,CAAAC,IAAA,CAAAF,WAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,WAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,WAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AArCA;AACA;AACA;AACA;AACA,IAAIS,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,GAAAnB,OAAA,QAAAoB,aAAA,CAAAC,UAAA,EAAAC,QAAA,EAAkB;AAC7BH,OAAO,GAAGA,OAAO,CAACI,KAAK,CAAC,CAAC,EAAEJ,OAAO,CAACK,WAAW,CAAC,GAAG,CAAC,CAAC;AAEpD,MAAMC,MAAM,GAAAb,OAAA,CAAAa,MAAA,GAAGC,cAAO,CAACC,WAAW,aAAoCR,OAAO,CAAC;AAE9E,MAAMS,MAAM,GAAAhB,OAAA,CAAAgB,MAAA,GAAGH,MAAM,GAAGI,SAAS,GAAGC,eAAY","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["clientModule","webpack","global","REACT_UTILS_LIBRARY_LOADED","Error","dirname","import","meta","server","requireWeak","client","undefined","getGlobalState","GlobalStateProvider","newAsyncDataEnvelope","useAsyncCollection","useAsyncData","useGlobalState","withGlobalStateType","assertEmptyObject","Barrier","Cached","Emitter","getConfig","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.\n// eslint-disable-next-line @typescript-eslint/prefer-destructuring\nconst dirname = import.meta.dirname;\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 Barrier,\n Cached,\n Emitter,\n getConfig,\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;AACA,MAAME,OAAO,GAAGC,MAAM,CAACC,IAAI,CAACF,OAAO;AAEnC,MAAMG,MAAM,GAAGP,OAAO,CAACQ,WAAW,aAAoCJ,OAAO,CAAC;AAE9E,MAAMK,MAAM,GAAGF,MAAM,GAAGG,SAAS,GAAGX,YAAY;AAEhD,SAUEY,cAAc,EACdC,mBAAmB,EACnBC,oBAAoB,EACpBC,kBAAkB,EAClBC,YAAY,EACZC,cAAc,EACdC,mBAAmB,QACd,gCAAgC;AAAA;AAAA,SAarCC,iBAAiB,EACjBC,OAAO,EACPC,MAAM,EACNC,OAAO,EACPC,SAAS,EACTC,SAAS,EACTC,aAAa,EAGbC,SAAS,EACTC,cAAc,EAEdC,MAAM,EACNC,aAAa,EACbC,IAAI,EACJ7B,OAAO,EACP8B,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","exports","default"],"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;AACe,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;AAAAoB,OAAA,CAAAC,OAAA,GAAAzB,KAAA","ignoreList":[]}
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":[]}