@dr.pogodin/react-utils 1.25.6 → 1.26.0
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 +3 -1
- package/bin/build.js +18 -4
- package/build/development/client/getInj.js +9 -8
- package/build/development/client/getInj.js.map +1 -1
- package/build/development/client/index.js +6 -3
- package/build/development/client/index.js.map +1 -1
- package/build/development/client/init.js +4 -0
- package/build/development/client/init.js.map +1 -1
- package/build/development/index.js +166 -38
- package/build/development/index.js.map +1 -1
- package/build/development/server/Cache.js +13 -13
- package/build/development/server/Cache.js.map +1 -1
- package/build/development/server/index.js +16 -23
- package/build/development/server/index.js.map +1 -1
- package/build/development/server/renderer.js +56 -43
- package/build/development/server/renderer.js.map +1 -1
- package/build/development/server/server.js +9 -5
- package/build/development/server/server.js.map +1 -1
- package/build/development/server/utils/errors.js +12 -9
- package/build/development/server/utils/errors.js.map +1 -1
- package/build/development/server/utils/index.js +2 -2
- package/build/development/server/utils/index.js.map +1 -1
- package/build/development/shared/components/Button/index.js +7 -5
- package/build/development/shared/components/Button/index.js.map +1 -1
- package/build/development/shared/components/Checkbox/index.js +24 -26
- package/build/development/shared/components/Checkbox/index.js.map +1 -1
- package/build/development/shared/components/Dropdown/index.js +24 -17
- package/build/development/shared/components/Dropdown/index.js.map +1 -1
- package/build/development/shared/components/GenericLink/index.js +44 -37
- package/build/development/shared/components/GenericLink/index.js.map +1 -1
- package/build/development/shared/components/Input/index.js +7 -7
- package/build/development/shared/components/Input/index.js.map +1 -1
- package/build/development/shared/components/Link.js +10 -9
- package/build/development/shared/components/Link.js.map +1 -1
- package/build/development/shared/components/MetaTags.js +22 -18
- package/build/development/shared/components/MetaTags.js.map +1 -1
- package/build/development/shared/components/Modal/index.js +16 -16
- package/build/development/shared/components/Modal/index.js.map +1 -1
- package/build/development/shared/components/NavLink.js +10 -9
- package/build/development/shared/components/NavLink.js.map +1 -1
- package/build/development/shared/components/PageLayout/index.js +16 -18
- package/build/development/shared/components/PageLayout/index.js.map +1 -1
- package/build/development/shared/components/ScalableRect/index.js +27 -7
- package/build/development/shared/components/ScalableRect/index.js.map +1 -1
- package/build/development/shared/components/Throbber/index.js +14 -22
- package/build/development/shared/components/Throbber/index.js.map +1 -1
- package/build/development/shared/components/WithTooltip/Tooltip.js +19 -21
- package/build/development/shared/components/WithTooltip/Tooltip.js.map +1 -1
- package/build/development/shared/components/WithTooltip/index.js +11 -10
- package/build/development/shared/components/WithTooltip/index.js.map +1 -1
- package/build/development/shared/components/YouTubeVideo/index.js +15 -13
- package/build/development/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/development/shared/components/index.js +2 -2
- package/build/development/shared/components/index.js.map +1 -1
- package/build/development/shared/utils/config.js.map +1 -1
- package/build/development/shared/utils/globalState.js +15 -0
- package/build/development/shared/utils/globalState.js.map +1 -0
- package/build/development/shared/utils/index.js +13 -10
- package/build/development/shared/utils/index.js.map +1 -1
- package/build/development/shared/utils/isomorphy/buildInfo.js +7 -3
- package/build/development/shared/utils/isomorphy/buildInfo.js.map +1 -1
- package/build/development/shared/utils/isomorphy/environment-check.js.map +1 -1
- package/build/development/shared/utils/isomorphy/index.js.map +1 -1
- package/build/development/shared/utils/jest/E2eSsrEnv.js +35 -28
- package/build/development/shared/utils/jest/E2eSsrEnv.js.map +1 -1
- package/build/development/shared/utils/jest/global.js +17 -0
- package/build/development/shared/utils/jest/global.js.map +1 -0
- package/build/development/shared/utils/jest/index.js +17 -9
- package/build/development/shared/utils/jest/index.js.map +1 -1
- package/build/development/shared/utils/splitComponent.js +25 -34
- package/build/development/shared/utils/splitComponent.js.map +1 -1
- package/build/development/shared/utils/time.js +16 -12
- package/build/development/shared/utils/time.js.map +1 -1
- package/build/development/shared/utils/webpack.js +3 -3
- package/build/development/shared/utils/webpack.js.map +1 -1
- package/build/development/web.bundle.js +92 -82
- package/build/production/client/getInj.js +1 -1
- package/build/production/client/getInj.js.map +1 -1
- package/build/production/client/index.js +4 -4
- package/build/production/client/index.js.map +1 -1
- package/build/production/client/init.js +3 -1
- package/build/production/client/init.js.map +1 -1
- package/build/production/index.js +1 -1
- package/build/production/index.js.map +1 -1
- package/build/production/server/Cache.js +7 -8
- package/build/production/server/Cache.js.map +1 -1
- package/build/production/server/index.js +5 -4
- package/build/production/server/index.js.map +1 -1
- package/build/production/server/renderer.js +32 -30
- package/build/production/server/renderer.js.map +1 -1
- package/build/production/server/server.js +7 -5
- package/build/production/server/server.js.map +1 -1
- package/build/production/server/utils/errors.js +9 -10
- package/build/production/server/utils/errors.js.map +1 -1
- package/build/production/server/utils/index.js +1 -1
- package/build/production/server/utils/index.js.map +1 -1
- package/build/production/shared/components/Button/index.js +3 -3
- package/build/production/shared/components/Button/index.js.map +1 -1
- package/build/production/shared/components/Checkbox/index.js +11 -11
- package/build/production/shared/components/Checkbox/index.js.map +1 -1
- package/build/production/shared/components/Dropdown/index.js +11 -11
- package/build/production/shared/components/Dropdown/index.js.map +1 -1
- package/build/production/shared/components/GenericLink/index.js +25 -20
- package/build/production/shared/components/GenericLink/index.js.map +1 -1
- package/build/production/shared/components/Input/index.js +7 -7
- package/build/production/shared/components/Input/index.js.map +1 -1
- package/build/production/shared/components/Link.js +2 -2
- package/build/production/shared/components/Link.js.map +1 -1
- package/build/production/shared/components/MetaTags.js +10 -10
- package/build/production/shared/components/MetaTags.js.map +1 -1
- package/build/production/shared/components/Modal/index.js +2 -2
- package/build/production/shared/components/Modal/index.js.map +1 -1
- package/build/production/shared/components/NavLink.js +1 -1
- 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/ScalableRect/index.js +7 -3
- package/build/production/shared/components/ScalableRect/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 +13 -13
- package/build/production/shared/components/WithTooltip/Tooltip.js.map +1 -1
- package/build/production/shared/components/WithTooltip/index.js +3 -3
- package/build/production/shared/components/WithTooltip/index.js.map +1 -1
- package/build/production/shared/components/YouTubeVideo/index.js +7 -7
- package/build/production/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/production/shared/components/index.js +1 -1
- package/build/production/shared/components/index.js.map +1 -1
- package/build/production/shared/utils/config.js.map +1 -1
- package/build/production/shared/utils/globalState.js +3 -0
- package/build/production/shared/utils/globalState.js.map +1 -0
- package/build/production/shared/utils/index.js +2 -2
- package/build/production/shared/utils/index.js.map +1 -1
- package/build/production/shared/utils/isomorphy/buildInfo.js +7 -4
- package/build/production/shared/utils/isomorphy/buildInfo.js.map +1 -1
- package/build/production/shared/utils/isomorphy/environment-check.js.map +1 -1
- package/build/production/shared/utils/isomorphy/index.js.map +1 -1
- package/build/production/shared/utils/jest/E2eSsrEnv.js +9 -9
- package/build/production/shared/utils/jest/E2eSsrEnv.js.map +1 -1
- package/build/production/shared/utils/jest/global.js +2 -0
- package/build/production/shared/utils/jest/global.js.map +1 -0
- package/build/production/shared/utils/jest/index.js +5 -5
- package/build/production/shared/utils/jest/index.js.map +1 -1
- package/build/production/shared/utils/splitComponent.js +16 -16
- package/build/production/shared/utils/splitComponent.js.map +1 -1
- package/build/production/shared/utils/time.js +12 -8
- package/build/production/shared/utils/time.js.map +1 -1
- package/build/production/shared/utils/webpack.js +3 -3
- package/build/production/shared/utils/webpack.js.map +1 -1
- package/build/production/web.bundle.js +1 -1
- package/build/production/web.bundle.js.map +1 -1
- package/build/types-code/client/getInj.d.ts +3 -0
- package/build/types-code/client/index.d.ts +11 -0
- package/build/types-code/client/init.d.ts +9 -0
- package/build/types-code/index.d.ts +10 -0
- package/build/types-code/server/Cache.d.ts +37 -0
- package/build/types-code/server/index.d.ts +145 -0
- package/build/types-code/server/renderer.d.ts +106 -0
- package/build/types-code/server/server.d.ts +41 -0
- package/build/types-code/server/utils/errors.d.ts +104 -0
- package/build/types-code/server/utils/index.d.ts +1 -0
- package/build/types-code/shared/components/Button/index.d.ts +27 -0
- package/build/types-code/shared/components/Checkbox/index.d.ts +21 -0
- package/build/types-code/shared/components/Dropdown/index.d.ts +23 -0
- package/build/types-code/shared/components/GenericLink/index.d.ts +61 -0
- package/build/types-code/shared/components/Input/index.d.ts +11 -0
- package/build/types-code/shared/components/Link.d.ts +12 -0
- package/build/types-code/shared/components/MetaTags.d.ts +68 -0
- package/build/types-code/shared/components/Modal/index.d.ts +26 -0
- package/build/types-code/shared/components/NavLink.d.ts +5 -0
- package/build/types-code/shared/components/PageLayout/index.d.ts +16 -0
- package/build/types-code/shared/components/ScalableRect/index.d.ts +19 -0
- package/build/types-code/shared/components/Throbber/index.d.ts +9 -0
- package/build/types-code/shared/components/WithTooltip/Tooltip.d.ts +23 -0
- package/build/types-code/shared/components/WithTooltip/index.d.ts +17 -0
- package/build/types-code/shared/components/YouTubeVideo/index.d.ts +13 -0
- package/build/types-code/shared/components/index.d.ts +16 -0
- package/build/types-code/shared/utils/config.d.ts +2 -0
- package/build/types-code/shared/utils/globalState.d.ts +20 -0
- package/build/types-code/shared/utils/index.d.ts +52 -0
- package/build/types-code/shared/utils/isomorphy/buildInfo.d.ts +23 -0
- package/build/types-code/shared/utils/isomorphy/environment-check.d.ts +11 -0
- package/build/types-code/shared/utils/isomorphy/index.d.ts +20 -0
- package/build/types-code/shared/utils/jest/E2eSsrEnv.d.ts +31 -0
- package/build/types-code/shared/utils/jest/global.d.ts +12 -0
- package/build/types-code/shared/utils/jest/index.d.ts +85 -0
- package/build/types-code/shared/utils/splitComponent.d.ts +41 -0
- package/build/types-code/shared/utils/time.d.ts +62 -0
- package/build/types-code/shared/utils/webpack.d.ts +18 -0
- package/build/types-scss/__tests__/js/config/publicPath support/__assets__/style.scss.d.ts +1 -0
- package/build/types-scss/__tests__/js/config/stylename-generation/__assets__/MockPackageA/TestComponent/style.scss.d.ts +1 -0
- package/build/types-scss/__tests__/js/config/stylename-generation/__assets__/MockPackageB/TestComponent/style.scss.d.ts +1 -0
- package/build/types-scss/__tests__/js/config/stylename-generation/__assets__/style.scss.d.ts +1 -0
- package/build/types-scss/__tests__/js/shared/components/NavLink/styles.scss.d.ts +1 -0
- package/build/types-scss/__tests__/js/shared/utils/splitComponent/__assets__/SampleScene/ComponentA/style.scss.d.ts +1 -0
- package/build/types-scss/__tests__/js/shared/utils/splitComponent/__assets__/SampleScene/ComponentB/style.scss.d.ts +1 -0
- package/build/types-scss/__tests__/js/shared/utils/splitComponent/__assets__/SampleScene/ComponentC/style.scss.d.ts +1 -0
- package/build/types-scss/__tests__/js/shared/utils/splitComponent/__assets__/SampleScene/style.scss.d.ts +1 -0
- package/build/types-scss/__tests__/ts/config/publicPath support/__assets__/style.scss.d.ts +1 -0
- package/build/types-scss/__tests__/ts/config/stylename-generation/__assets__/MockPackageA/TestComponent/style.scss.d.ts +1 -0
- package/build/types-scss/__tests__/ts/config/stylename-generation/__assets__/MockPackageB/TestComponent/style.scss.d.ts +1 -0
- package/build/types-scss/__tests__/ts/config/stylename-generation/__assets__/style.scss.d.ts +1 -0
- package/build/types-scss/__tests__/ts/shared/components/NavLink/styles.scss.d.ts +1 -0
- package/build/types-scss/__tests__/ts/shared/utils/splitComponent/__assets__/SampleScene/ComponentA/style.scss.d.ts +1 -0
- package/build/types-scss/__tests__/ts/shared/utils/splitComponent/__assets__/SampleScene/ComponentB/style.scss.d.ts +1 -0
- package/build/types-scss/__tests__/ts/shared/utils/splitComponent/__assets__/SampleScene/ComponentC/style.scss.d.ts +1 -0
- package/build/types-scss/__tests__/ts/shared/utils/splitComponent/__assets__/SampleScene/style.scss.d.ts +1 -0
- package/build/types-scss/src/shared/components/Button/style.scss.d.ts +6 -0
- package/build/types-scss/src/shared/components/Checkbox/theme.scss.d.ts +6 -0
- package/build/types-scss/src/shared/components/Dropdown/theme.scss.d.ts +9 -0
- package/build/types-scss/src/shared/components/GenericLink/style.scss.d.ts +1 -0
- package/build/types-scss/src/shared/components/Input/theme.scss.d.ts +6 -0
- package/build/types-scss/src/shared/components/Modal/base-theme.scss.d.ts +5 -0
- package/build/types-scss/src/shared/components/PageLayout/base-theme.scss.d.ts +6 -0
- package/build/types-scss/src/shared/components/ScalableRect/style.scss.d.ts +2 -0
- package/build/types-scss/src/shared/components/Throbber/theme.scss.d.ts +6 -0
- package/build/types-scss/src/shared/components/WithTooltip/default-theme.scss.d.ts +7 -0
- package/build/types-scss/src/shared/components/YouTubeVideo/base.scss.d.ts +5 -0
- package/build/types-scss/src/shared/components/YouTubeVideo/throbber.scss.d.ts +4 -0
- package/config/eslint/jest.json +3 -2
- package/config/eslint/typescript.js +34 -0
- package/config/jest/default.js +3 -3
- package/package.json +74 -32
- package/src/client/getInj.ts +43 -0
- package/src/client/index.tsx +40 -0
- package/src/client/init.ts +47 -0
- package/src/index.ts +58 -0
- package/src/server/Cache.ts +68 -0
- package/src/server/index.ts +230 -0
- package/src/server/renderer.tsx +604 -0
- package/src/server/server.ts +309 -0
- package/src/server/utils/errors.ts +135 -0
- package/src/server/utils/index.ts +3 -0
- package/src/shared/components/Button/index.tsx +146 -0
- package/src/shared/components/Button/style.scss +53 -0
- package/src/shared/components/Checkbox/index.tsx +71 -0
- package/src/shared/components/Checkbox/theme.scss +43 -0
- package/src/shared/components/Dropdown/index.tsx +144 -0
- package/src/shared/components/Dropdown/theme.scss +63 -0
- package/src/shared/components/GenericLink/index.tsx +157 -0
- package/src/shared/components/GenericLink/style.scss +3 -0
- package/src/shared/components/Input/index.tsx +59 -0
- package/src/shared/components/Input/theme.scss +27 -0
- package/src/shared/components/Link.tsx +21 -0
- package/src/shared/components/MetaTags.tsx +170 -0
- package/src/shared/components/Modal/base-theme.scss +38 -0
- package/src/shared/components/Modal/index.tsx +144 -0
- package/src/shared/components/Modal/styles.scss +5 -0
- package/src/shared/components/NavLink.tsx +13 -0
- package/src/shared/components/PageLayout/base-theme.scss +30 -0
- package/src/shared/components/PageLayout/index.tsx +76 -0
- package/src/shared/components/ScalableRect/index.tsx +84 -0
- package/src/shared/components/ScalableRect/style.scss +10 -0
- package/src/shared/components/Throbber/index.tsx +43 -0
- package/src/shared/components/Throbber/theme.scss +26 -0
- package/src/shared/components/WithTooltip/Tooltip.tsx +353 -0
- package/src/shared/components/WithTooltip/default-theme.scss +36 -0
- package/src/shared/components/WithTooltip/index.tsx +204 -0
- package/src/shared/components/YouTubeVideo/base.scss +13 -0
- package/src/shared/components/YouTubeVideo/index.tsx +96 -0
- package/src/shared/components/YouTubeVideo/throbber.scss +11 -0
- package/src/shared/components/index.ts +17 -0
- package/src/shared/utils/config.ts +21 -0
- package/src/shared/utils/globalState.ts +29 -0
- package/src/shared/utils/index.ts +105 -0
- package/src/shared/utils/isomorphy/buildInfo.ts +54 -0
- package/src/shared/utils/isomorphy/environment-check.ts +18 -0
- package/src/shared/utils/isomorphy/index.ts +38 -0
- package/src/shared/utils/jest/E2eSsrEnv.ts +250 -0
- package/src/shared/utils/jest/global.ts +19 -0
- package/src/shared/utils/jest/index.tsx +157 -0
- package/src/shared/utils/splitComponent.tsx +255 -0
- package/src/shared/utils/time.ts +118 -0
- package/src/shared/utils/webpack.ts +45 -0
- package/src/styles/_global/reset.css +52 -0
- package/src/styles/global.scss +11 -0
- package/tsconfig.configs.json +18 -0
- package/tsconfig.json +27 -0
- package/tsconfig.types.json +53 -0
- package/typed-scss-modules.config.ts +9 -0
- package/types.d.ts +37 -0
- package/{webpack.config.js → webpack.config.ts} +7 -3
- package/config/babel/node-ssr.js +0 -85
- package/config/babel/webpack.js +0 -123
- package/config/webpack/app-base.js +0 -330
- package/config/webpack/app-development.js +0 -80
- package/config/webpack/app-production.js +0 -60
- package/config/webpack/lib-base.js +0 -155
- package/config/webpack/lib-development.js +0 -45
- package/config/webpack/lib-production.js +0 -44
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const sampleClassName: string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const navLink: string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const container: string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const container: string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const container: string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const container: string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const ad: string;
|
|
2
|
+
export declare const arrow: string;
|
|
3
|
+
export declare const container: string;
|
|
4
|
+
export declare const context: string;
|
|
5
|
+
export declare const hiddenOption: string;
|
|
6
|
+
export declare const hoc: string;
|
|
7
|
+
export declare const label: string;
|
|
8
|
+
export declare const option: string;
|
|
9
|
+
export declare const select: string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const link: string;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const ad: string;
|
|
2
|
+
export declare const appearance: string;
|
|
3
|
+
export declare const arrow: string;
|
|
4
|
+
export declare const container: string;
|
|
5
|
+
export declare const context: string;
|
|
6
|
+
export declare const hoc: string;
|
|
7
|
+
export declare const wrapper: string;
|
package/config/eslint/jest.json
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
{
|
|
2
|
-
"extends": "./default.json",
|
|
3
2
|
"env": {
|
|
4
3
|
"browser": true,
|
|
5
4
|
"jest": true
|
|
@@ -8,9 +7,11 @@
|
|
|
8
7
|
"jest"
|
|
9
8
|
],
|
|
10
9
|
"rules": {
|
|
10
|
+
"@typescript-eslint/no-implied-eval": 0,
|
|
11
11
|
"global-require": 0,
|
|
12
12
|
"import/no-dynamic-require": 0,
|
|
13
13
|
"import/no-extraneous-dependencies": 0,
|
|
14
|
-
"no-console": 0
|
|
14
|
+
"no-console": 0,
|
|
15
|
+
"no-new-func": 0
|
|
15
16
|
}
|
|
16
17
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
extends: ['airbnb', 'airbnb/hooks', 'airbnb-typescript'],
|
|
3
|
+
parserOptions: {
|
|
4
|
+
project: './tsconfig.json',
|
|
5
|
+
},
|
|
6
|
+
rules: {
|
|
7
|
+
'jsx-a11y/anchor-is-valid': ['error', {
|
|
8
|
+
components: [],
|
|
9
|
+
specialLink: ['hrefLeft', 'hrefRight'],
|
|
10
|
+
aspects: ['invalidHref', 'noHref', 'preferButton'],
|
|
11
|
+
}],
|
|
12
|
+
'no-plusplus': 0,
|
|
13
|
+
|
|
14
|
+
// In TypeScript arrow-functions are better for component definitions as
|
|
15
|
+
// they allow typing like this, which helps to avoid many errors early:
|
|
16
|
+
// const Component: React.FunctionComponent<Props> = ({ ... }) => { ... };
|
|
17
|
+
'react/function-component-definition': ['error', {
|
|
18
|
+
namedComponents: 'arrow-function',
|
|
19
|
+
unnamedComponents: 'arrow-function',
|
|
20
|
+
}],
|
|
21
|
+
|
|
22
|
+
'react/jsx-one-expression-per-line': 0,
|
|
23
|
+
'react/jsx-uses-react': 0,
|
|
24
|
+
'react/no-unknown-property': ['error', {
|
|
25
|
+
ignore: ['styleName'],
|
|
26
|
+
}],
|
|
27
|
+
'react/react-in-jsx-scope': 0,
|
|
28
|
+
},
|
|
29
|
+
settings: {
|
|
30
|
+
'import/resolver': {
|
|
31
|
+
'babel-module': {},
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
};
|
package/config/jest/default.js
CHANGED
|
@@ -5,7 +5,7 @@ const globalLibDir = path.resolve(process.execPath, '../../lib/node_modules');
|
|
|
5
5
|
module.exports = {
|
|
6
6
|
collectCoverage: true,
|
|
7
7
|
collectCoverageFrom: [
|
|
8
|
-
'src/**/*.{js,jsx}',
|
|
8
|
+
'src/**/*.{js,jsx,ts,tsx}',
|
|
9
9
|
],
|
|
10
10
|
coverageDirectory: '__coverage__',
|
|
11
11
|
moduleDirectories: [
|
|
@@ -17,7 +17,7 @@ module.exports = {
|
|
|
17
17
|
},
|
|
18
18
|
modulePathIgnorePatterns: ['<rootDir>/build/'],
|
|
19
19
|
rootDir: '../..',
|
|
20
|
-
testMatch: ['**/__tests__/**/*.
|
|
20
|
+
testMatch: ['**/__tests__/**/*.(j|t)s?(x)'],
|
|
21
21
|
testPathIgnorePatterns: [
|
|
22
22
|
'/__assets__/',
|
|
23
23
|
'/node_modules/',
|
|
@@ -26,7 +26,7 @@ module.exports = {
|
|
|
26
26
|
url: 'http://localhost',
|
|
27
27
|
},
|
|
28
28
|
transform: {
|
|
29
|
-
'\\.(
|
|
29
|
+
'\\.((j|t)sx?|svg)$': 'babel-jest',
|
|
30
30
|
},
|
|
31
31
|
transformIgnorePatterns: [
|
|
32
32
|
'/node_modules/(?!@dr.pogodin/react-utils)',
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.
|
|
2
|
+
"version": "1.26.0",
|
|
3
3
|
"bin": {
|
|
4
4
|
"react-utils-build": "bin/build.js",
|
|
5
5
|
"react-utils-setup": "bin/setup.js"
|
|
@@ -8,14 +8,15 @@
|
|
|
8
8
|
"url": "https://github.com/birdofpreyru/react-utils/issues"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@babel/runtime": "^7.23.
|
|
12
|
-
"@dr.pogodin/babel-plugin-react-css-modules": "^6.
|
|
11
|
+
"@babel/runtime": "^7.23.2",
|
|
12
|
+
"@dr.pogodin/babel-plugin-react-css-modules": "^6.12.0",
|
|
13
13
|
"@dr.pogodin/csurf": "^1.13.0",
|
|
14
14
|
"@dr.pogodin/js-utils": "^0.0.6",
|
|
15
|
-
"@dr.pogodin/react-global-state": "^0.10.0-alpha.
|
|
16
|
-
"@dr.pogodin/react-themes": "^1.
|
|
17
|
-
"
|
|
18
|
-
"
|
|
15
|
+
"@dr.pogodin/react-global-state": "^0.10.0-alpha.4",
|
|
16
|
+
"@dr.pogodin/react-themes": "^1.5.1",
|
|
17
|
+
"@jest/environment": "^29.7.0",
|
|
18
|
+
"axios": "^1.5.1",
|
|
19
|
+
"commander": "^11.1.0",
|
|
19
20
|
"compression": "^1.7.4",
|
|
20
21
|
"config": "^3.3.9",
|
|
21
22
|
"cookie": "^0.5.0",
|
|
@@ -25,7 +26,7 @@
|
|
|
25
26
|
"express": "^4.18.2",
|
|
26
27
|
"helmet": "^7.0.0",
|
|
27
28
|
"http-status-codes": "^2.3.0",
|
|
28
|
-
"joi": "^17.
|
|
29
|
+
"joi": "^17.11.0",
|
|
29
30
|
"lodash": "^4.17.21",
|
|
30
31
|
"morgan": "^1.10.0",
|
|
31
32
|
"node-forge": "^1.3.1",
|
|
@@ -35,69 +36,99 @@
|
|
|
35
36
|
"react": "^18.2.0",
|
|
36
37
|
"react-dom": "^18.2.0",
|
|
37
38
|
"react-helmet": "^6.1.0",
|
|
38
|
-
"react-router-dom": "^6.
|
|
39
|
+
"react-router-dom": "^6.17.0",
|
|
39
40
|
"request-ip": "^3.3.0",
|
|
40
|
-
"rimraf": "^5.0.
|
|
41
|
+
"rimraf": "^5.0.5",
|
|
41
42
|
"serialize-javascript": "^6.0.1",
|
|
42
43
|
"serve-favicon": "^2.5.0",
|
|
43
44
|
"source-map-support": "^0.5.21",
|
|
44
45
|
"uuid": "^9.0.1",
|
|
45
|
-
"winston": "^3.
|
|
46
|
+
"winston": "^3.11.0"
|
|
46
47
|
},
|
|
47
48
|
"description": "Collection of generic ReactJS components and utils",
|
|
48
49
|
"devDependencies": {
|
|
49
50
|
"@babel/cli": "^7.23.0",
|
|
50
|
-
"@babel/core": "^7.23.
|
|
51
|
+
"@babel/core": "^7.23.2",
|
|
51
52
|
"@babel/eslint-parser": "^7.22.15",
|
|
52
53
|
"@babel/eslint-plugin": "^7.22.10",
|
|
53
54
|
"@babel/node": "^7.22.19",
|
|
54
|
-
"@babel/plugin-transform-runtime": "^7.
|
|
55
|
-
"@babel/preset-env": "^7.
|
|
55
|
+
"@babel/plugin-transform-runtime": "^7.23.2",
|
|
56
|
+
"@babel/preset-env": "^7.23.2",
|
|
56
57
|
"@babel/preset-react": "^7.22.15",
|
|
58
|
+
"@babel/preset-typescript": "^7.23.2",
|
|
57
59
|
"@babel/register": "^7.22.15",
|
|
58
60
|
"@dr.pogodin/babel-plugin-transform-assets": "^1.2.2",
|
|
59
61
|
"@dr.pogodin/babel-preset-svgr": "^1.8.0",
|
|
60
62
|
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.11",
|
|
63
|
+
"@tsconfig/recommended": "^1.0.2",
|
|
64
|
+
"@tsd/typescript": "^5.1.6",
|
|
65
|
+
"@types/compression": "^1.7.4",
|
|
66
|
+
"@types/config": "^3.3.2",
|
|
67
|
+
"@types/cookie": "^0.5.3",
|
|
68
|
+
"@types/cookie-parser": "^1.4.5",
|
|
69
|
+
"@types/csurf": "^1.11.4",
|
|
70
|
+
"@types/express": "^4.17.20",
|
|
71
|
+
"@types/jest": "^29.5.6",
|
|
72
|
+
"@types/lodash": "^4.14.200",
|
|
73
|
+
"@types/morgan": "^1.9.7",
|
|
74
|
+
"@types/node-forge": "^1.3.8",
|
|
75
|
+
"@types/pretty": "^2.0.2",
|
|
76
|
+
"@types/react": "^18.2.31",
|
|
77
|
+
"@types/react-dom": "^18.2.14",
|
|
78
|
+
"@types/react-helmet": "^6.1.8",
|
|
79
|
+
"@types/react-test-renderer": "^18.0.5",
|
|
80
|
+
"@types/request-ip": "^0.0.40",
|
|
81
|
+
"@types/serialize-javascript": "^5.0.3",
|
|
82
|
+
"@types/serve-favicon": "^2.5.6",
|
|
83
|
+
"@types/supertest": "^2.0.15",
|
|
84
|
+
"@types/uuid": "^9.0.6",
|
|
85
|
+
"@types/webpack": "^5.28.4",
|
|
86
|
+
"@typescript-eslint/eslint-plugin": "^6.8.0",
|
|
87
|
+
"@typescript-eslint/parser": "^6.8.0",
|
|
61
88
|
"autoprefixer": "^10.4.16",
|
|
62
89
|
"babel-jest": "^29.7.0",
|
|
63
90
|
"babel-loader": "^9.1.3",
|
|
64
91
|
"babel-plugin-module-resolver": "^5.0.0",
|
|
65
|
-
"core-js": "^3.
|
|
92
|
+
"core-js": "^3.33.1",
|
|
66
93
|
"css-loader": "^6.8.1",
|
|
67
94
|
"css-minimizer-webpack-plugin": "^5.0.1",
|
|
68
|
-
"eslint": "^8.
|
|
95
|
+
"eslint": "^8.52.0",
|
|
69
96
|
"eslint-config-airbnb": "^19.0.4",
|
|
97
|
+
"eslint-config-airbnb-typescript": "^17.0.0",
|
|
70
98
|
"eslint-import-resolver-babel-module": "^5.3.2",
|
|
71
|
-
"eslint-plugin-import": "^2.
|
|
72
|
-
"eslint-plugin-jest": "^27.4.
|
|
99
|
+
"eslint-plugin-import": "^2.29.0",
|
|
100
|
+
"eslint-plugin-jest": "^27.4.3",
|
|
73
101
|
"eslint-plugin-jsx-a11y": "^6.7.1",
|
|
74
102
|
"eslint-plugin-react": "^7.33.2",
|
|
75
103
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
76
104
|
"identity-obj-proxy": "^3.0.0",
|
|
77
105
|
"jest": "^29.7.0",
|
|
78
106
|
"jest-environment-jsdom": "^29.7.0",
|
|
79
|
-
"memfs": "^4.
|
|
107
|
+
"memfs": "^4.6.0",
|
|
80
108
|
"mini-css-extract-plugin": "^2.7.6",
|
|
81
109
|
"mockdate": "^3.0.5",
|
|
82
110
|
"nodelist-foreach-polyfill": "^1.2.0",
|
|
83
|
-
"postcss": "^8.4.
|
|
111
|
+
"postcss": "^8.4.31",
|
|
84
112
|
"postcss-loader": "^7.3.3",
|
|
85
|
-
"postcss-scss": "^4.0.
|
|
113
|
+
"postcss-scss": "^4.0.9",
|
|
86
114
|
"pretty": "^2.0.0",
|
|
87
115
|
"react-refresh": "^0.14.0",
|
|
88
116
|
"react-test-renderer": "^18.2.0",
|
|
89
117
|
"regenerator-runtime": "^0.14.0",
|
|
90
118
|
"resolve-url-loader": "^5.0.0",
|
|
91
|
-
"sass": "^1.
|
|
119
|
+
"sass": "^1.69.4",
|
|
92
120
|
"sass-loader": "^13.3.2",
|
|
93
121
|
"sitemap": "^7.1.1",
|
|
94
|
-
"stylelint": "^15.
|
|
122
|
+
"stylelint": "^15.11.0",
|
|
95
123
|
"stylelint-config-standard-scss": "^11.0.0",
|
|
96
124
|
"supertest": "^6.3.3",
|
|
97
|
-
"
|
|
125
|
+
"tsc-alias": "^1.8.8",
|
|
126
|
+
"typed-scss-modules": "^7.1.4",
|
|
127
|
+
"typescript": "^5.2.2",
|
|
128
|
+
"webpack": "^5.89.0",
|
|
98
129
|
"webpack-dev-middleware": "^6.1.1",
|
|
99
130
|
"webpack-hot-middleware": "^2.25.4",
|
|
100
|
-
"webpack-merge": "^5.
|
|
131
|
+
"webpack-merge": "^5.10.0",
|
|
101
132
|
"workbox-core": "^7.0.0",
|
|
102
133
|
"workbox-precaching": "^7.0.0",
|
|
103
134
|
"workbox-webpack-plugin": "^7.0.0"
|
|
@@ -107,6 +138,8 @@
|
|
|
107
138
|
"npm": ">=9"
|
|
108
139
|
},
|
|
109
140
|
"main": "./node-entry.js",
|
|
141
|
+
"source": "./src/index.ts",
|
|
142
|
+
"types": "./build/types-code/index.d.ts",
|
|
110
143
|
"exports": {
|
|
111
144
|
".": {
|
|
112
145
|
"browser": {
|
|
@@ -148,6 +181,7 @@
|
|
|
148
181
|
"ReactJS",
|
|
149
182
|
"Starting Pack",
|
|
150
183
|
"Tools",
|
|
184
|
+
"TypeScript",
|
|
151
185
|
"Utils",
|
|
152
186
|
"Web"
|
|
153
187
|
],
|
|
@@ -155,13 +189,21 @@
|
|
|
155
189
|
"name": "@dr.pogodin/react-utils",
|
|
156
190
|
"repository": "github:birdofpreyru/react-utils",
|
|
157
191
|
"scripts": {
|
|
158
|
-
"build": "rimraf build &&
|
|
159
|
-
"
|
|
160
|
-
"
|
|
161
|
-
"
|
|
162
|
-
"
|
|
163
|
-
"
|
|
192
|
+
"build": "rimraf build && npm run build:configs && npm run build:types-scss && npm run build:types-code && npm run build:dev && npm run build:prod",
|
|
193
|
+
"build:configs": "tsc --project tsconfig.configs.json",
|
|
194
|
+
"build:dev": "node bin/build -t development --lib --webpack-config webpack.config.ts",
|
|
195
|
+
"build:prod": "node bin/build -t production --lib --webpack-config webpack.config.ts",
|
|
196
|
+
"build:types-code": "rimraf build/types-code && tsc --project tsconfig.types.json && tsc-alias -p tsconfig.types.json",
|
|
197
|
+
"build:types-scss": "rimraf build/types-scss && typed-scss-modules .",
|
|
198
|
+
"jest:1": "NODE_CONFIG_ENV=test jest --no-cache -w 1 --config config/jest/default.js --shard=1/4",
|
|
199
|
+
"jest:2": "NODE_CONFIG_ENV=test jest --no-cache -w 1 --config config/jest/default.js --shard=2/4",
|
|
200
|
+
"jest:3": "NODE_CONFIG_ENV=test jest --no-cache -w 1 --config config/jest/default.js --shard=3/4",
|
|
201
|
+
"jest:4": "NODE_CONFIG_ENV=test jest --no-cache -w 1 --config config/jest/default.js --shard=4/4",
|
|
202
|
+
"jest": "npm run jest:1 && npm run jest:2 && npm run jest:3 && npm run jest:4",
|
|
203
|
+
"lint": "npm run lint:code && npm run lint:scss",
|
|
204
|
+
"lint:code": "eslint --ext .js,.jsx,.ts,.tsx .",
|
|
164
205
|
"lint:scss": "stylelint -- **/*.{css,scss}",
|
|
165
|
-
"test": "npm run lint && npm run jest"
|
|
206
|
+
"test": "npm run lint && npm run typecheck && npm run jest",
|
|
207
|
+
"typecheck": "tsc --project __tests__/tsconfig.json"
|
|
166
208
|
}
|
|
167
209
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Encapsulates retrieval of server-side data injection into HTML template.
|
|
2
|
+
|
|
3
|
+
/* global document */
|
|
4
|
+
|
|
5
|
+
// Note: this way, only required part of "node-forge": AES, and some utils,
|
|
6
|
+
// is bundled into client-side code.
|
|
7
|
+
import forge from 'node-forge/lib/forge';
|
|
8
|
+
import 'node-forge/lib/aes';
|
|
9
|
+
|
|
10
|
+
import type { InjT } from 'utils/globalState';
|
|
11
|
+
|
|
12
|
+
import { getBuildInfo } from 'utils/isomorphy/buildInfo';
|
|
13
|
+
|
|
14
|
+
// Safeguard is needed here, because the server-side version of Docusaurus docs
|
|
15
|
+
// is compiled (at least now) with settings suggesting it is a client-side
|
|
16
|
+
// environment, but there is no document.
|
|
17
|
+
let inj: InjT = {};
|
|
18
|
+
|
|
19
|
+
const metaElement: HTMLMetaElement | null = typeof document !== 'undefined'
|
|
20
|
+
? document.querySelector('meta[itemprop="drpruinj"]') : null;
|
|
21
|
+
|
|
22
|
+
if (metaElement) {
|
|
23
|
+
metaElement.remove();
|
|
24
|
+
let data = forge.util.decode64(metaElement.content);
|
|
25
|
+
|
|
26
|
+
const { key } = getBuildInfo();
|
|
27
|
+
const d = forge.cipher.createDecipher('AES-CBC', key);
|
|
28
|
+
d.start({ iv: data.slice(0, key.length) });
|
|
29
|
+
d.update(forge.util.createBuffer(data.slice(key.length)));
|
|
30
|
+
d.finish();
|
|
31
|
+
|
|
32
|
+
data = forge.util.decodeUtf8(d.output.data);
|
|
33
|
+
inj = eval(`(${data})`); // eslint-disable-line no-eval
|
|
34
|
+
} else {
|
|
35
|
+
// Otherwise, a bunch of dependent stuff will easily fail in non-standard
|
|
36
|
+
// environments, where no client-side initialization is performed. Like tests,
|
|
37
|
+
// Docusaurus examples, etc.
|
|
38
|
+
inj = {};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export default function getInj(): InjT {
|
|
42
|
+
return inj;
|
|
43
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Initialization of client-side code.
|
|
2
|
+
/* global document */
|
|
3
|
+
|
|
4
|
+
import { type ComponentType } from 'react';
|
|
5
|
+
|
|
6
|
+
import { GlobalStateProvider } from '@dr.pogodin/react-global-state';
|
|
7
|
+
|
|
8
|
+
import { createRoot, hydrateRoot } from 'react-dom/client';
|
|
9
|
+
import { BrowserRouter } from 'react-router-dom';
|
|
10
|
+
|
|
11
|
+
import getInj from './getInj';
|
|
12
|
+
|
|
13
|
+
type OptionsT = {
|
|
14
|
+
dontHydrate?: boolean;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Prepares and launches the app at client side.
|
|
19
|
+
* @param Application Root application component
|
|
20
|
+
* @param [options={}] Optional. Additional settings.
|
|
21
|
+
*/
|
|
22
|
+
export default function Launch(
|
|
23
|
+
Application: ComponentType,
|
|
24
|
+
options: OptionsT = {},
|
|
25
|
+
) {
|
|
26
|
+
const container = document.getElementById('react-view');
|
|
27
|
+
if (!container) throw Error('Failed to find container for React app');
|
|
28
|
+
const scene = (
|
|
29
|
+
<GlobalStateProvider initialState={getInj().ISTATE}>
|
|
30
|
+
<BrowserRouter>
|
|
31
|
+
<Application />
|
|
32
|
+
</BrowserRouter>
|
|
33
|
+
</GlobalStateProvider>
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
if (options.dontHydrate) {
|
|
37
|
+
const root = createRoot(container);
|
|
38
|
+
root.render(scene);
|
|
39
|
+
} else hydrateRoot(container, scene);
|
|
40
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Initialization of client-side environment.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/* global BUILD_INFO, window */
|
|
6
|
+
|
|
7
|
+
import { type BuildInfoT, getBuildInfo } from 'utils/isomorphy/buildInfo';
|
|
8
|
+
|
|
9
|
+
const buildInfo = getBuildInfo();
|
|
10
|
+
|
|
11
|
+
// TODO: Should be moved into buildInfo module?
|
|
12
|
+
declare global {
|
|
13
|
+
interface Window {
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention, no-underscore-dangle
|
|
15
|
+
__DEV_BUILD_INFO__: BuildInfoT | undefined;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
20
|
+
// eslint-disable-next-line no-console
|
|
21
|
+
console.warn('Dev mode: "BUILD_INFO" attached to the global "window"');
|
|
22
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
23
|
+
window.__DEV_BUILD_INFO__ = BUILD_INFO;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/* TODO: A proper logger should be moved to `@dr.pogodin/react-utils`. */
|
|
27
|
+
/* eslint-disable no-console */
|
|
28
|
+
const { useServiceWorker } = buildInfo;
|
|
29
|
+
if (useServiceWorker) {
|
|
30
|
+
const { navigator } = window;
|
|
31
|
+
if ('serviceWorker' in navigator) {
|
|
32
|
+
window.addEventListener('load', async () => {
|
|
33
|
+
try {
|
|
34
|
+
// Note: no matter the "publicPath", we want to serve the service worker
|
|
35
|
+
// from the web app root, to allow it control any and all pages of the
|
|
36
|
+
// web app (otherwise, it will be restricted to the scope of its path).
|
|
37
|
+
// The server takes it into account.
|
|
38
|
+
const reg = await navigator
|
|
39
|
+
.serviceWorker.register('/__service-worker.js');
|
|
40
|
+
console.log('SW registered:', reg);
|
|
41
|
+
} catch (err) {
|
|
42
|
+
console.log('SW registration failed:', err);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/* eslint-enable no-console */
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import 'styles/global.scss';
|
|
2
|
+
|
|
3
|
+
import { webpack } from 'utils';
|
|
4
|
+
|
|
5
|
+
import type ServerT from './server';
|
|
6
|
+
|
|
7
|
+
const server = webpack.requireWeak('./server', __dirname) as (typeof ServerT) | null;
|
|
8
|
+
|
|
9
|
+
const client = server ? undefined : require('./client').default;
|
|
10
|
+
|
|
11
|
+
export { default as api } from 'axios';
|
|
12
|
+
export * as PT from 'prop-types';
|
|
13
|
+
|
|
14
|
+
export {
|
|
15
|
+
default as Rgs,
|
|
16
|
+
type API as RgsApi,
|
|
17
|
+
getGlobalState,
|
|
18
|
+
GlobalStateProvider,
|
|
19
|
+
useAsyncCollection,
|
|
20
|
+
useAsyncData,
|
|
21
|
+
useGlobalState,
|
|
22
|
+
} from '@dr.pogodin/react-global-state';
|
|
23
|
+
|
|
24
|
+
export {
|
|
25
|
+
BaseModal,
|
|
26
|
+
Button,
|
|
27
|
+
Checkbox,
|
|
28
|
+
Dropdown,
|
|
29
|
+
Input,
|
|
30
|
+
Link,
|
|
31
|
+
PageLayout,
|
|
32
|
+
MetaTags,
|
|
33
|
+
Modal,
|
|
34
|
+
NavLink,
|
|
35
|
+
ScalableRect,
|
|
36
|
+
Throbber,
|
|
37
|
+
WithTooltip,
|
|
38
|
+
YouTubeVideo,
|
|
39
|
+
} from 'components';
|
|
40
|
+
|
|
41
|
+
export {
|
|
42
|
+
type Theme,
|
|
43
|
+
config,
|
|
44
|
+
Barrier,
|
|
45
|
+
Emitter,
|
|
46
|
+
isomorphy,
|
|
47
|
+
getSsrContext,
|
|
48
|
+
JU,
|
|
49
|
+
Semaphore,
|
|
50
|
+
splitComponent,
|
|
51
|
+
themed,
|
|
52
|
+
ThemeProvider,
|
|
53
|
+
time,
|
|
54
|
+
webpack,
|
|
55
|
+
withRetries,
|
|
56
|
+
} from 'utils';
|
|
57
|
+
|
|
58
|
+
export { client, server };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Implements the static cache.
|
|
3
|
+
*/
|
|
4
|
+
export default class Cache<DatumT> {
|
|
5
|
+
private: {
|
|
6
|
+
items: {
|
|
7
|
+
[key: string]: {
|
|
8
|
+
data: DatumT;
|
|
9
|
+
size: number;
|
|
10
|
+
timestamp: number;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
maxSize: number;
|
|
14
|
+
size: number;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
constructor(maxSize: number) {
|
|
18
|
+
this.private = {
|
|
19
|
+
items: {},
|
|
20
|
+
maxSize,
|
|
21
|
+
size: 0,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Cache lookup.
|
|
27
|
+
* @param key Item key to look for.
|
|
28
|
+
* @param [maxage=Number.MAX_VALUE] Optional. The maximum age of
|
|
29
|
+
* cached item to serve. Default to infinite.
|
|
30
|
+
* @returns Cached item, or null if the item is absent in cache,
|
|
31
|
+
* or stale.
|
|
32
|
+
*/
|
|
33
|
+
get({
|
|
34
|
+
key,
|
|
35
|
+
maxage = Number.MAX_VALUE,
|
|
36
|
+
}: {
|
|
37
|
+
key: string;
|
|
38
|
+
maxage?: number;
|
|
39
|
+
}): DatumT | null {
|
|
40
|
+
const item = this.private.items[key];
|
|
41
|
+
return item && Date.now() - item.timestamp < maxage ? item.data : null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Adds item to cache.
|
|
46
|
+
* @ignore
|
|
47
|
+
* @param data Item to add.
|
|
48
|
+
* @param key Key to store the item at.
|
|
49
|
+
* @param size Byte size of the item.
|
|
50
|
+
*/
|
|
51
|
+
add(data: DatumT, key: string, size: number) {
|
|
52
|
+
const p = this.private;
|
|
53
|
+
const old = p.items[key];
|
|
54
|
+
if (old) p.size -= old.size;
|
|
55
|
+
p.items[key] = { data, size, timestamp: Date.now() };
|
|
56
|
+
p.size += size;
|
|
57
|
+
if (p.size > p.maxSize) {
|
|
58
|
+
const items = Object.entries(p.items);
|
|
59
|
+
items.sort((a, b) => a[1].timestamp - b[1].timestamp);
|
|
60
|
+
for (let i = 0; i < items.length; ++i) {
|
|
61
|
+
const [itemKey, item] = items[i];
|
|
62
|
+
delete p.items[itemKey];
|
|
63
|
+
p.size -= item.size;
|
|
64
|
+
if (p.size < p.maxSize / 2) break;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|