@dr.pogodin/react-utils 1.17.8 → 1.17.9
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/build/development/server/renderer.js +4 -4
- package/build/development/server/renderer.js.map +1 -1
- package/build/development/shared/utils/Semaphore.js +2 -2
- package/build/development/shared/utils/Semaphore.js.map +1 -1
- package/build/development/shared/utils/index.js +2 -2
- package/build/development/shared/utils/index.js.map +1 -1
- package/build/development/shared/utils/time.js +4 -2
- package/build/development/shared/utils/time.js.map +1 -1
- package/build/development/web.bundle.js +3 -3
- package/build/production/server/renderer.js +4 -4
- package/build/production/server/renderer.js.map +1 -1
- package/build/production/shared/utils/Semaphore.js +2 -2
- package/build/production/shared/utils/Semaphore.js.map +1 -1
- package/build/production/shared/utils/index.js +2 -2
- package/build/production/shared/utils/index.js.map +1 -1
- package/build/production/shared/utils/time.js +2 -2
- package/build/production/shared/utils/time.js.map +1 -1
- package/build/production/web.bundle.js +1 -1
- package/build/production/web.bundle.js.map +1 -1
- package/package.json +12 -12
|
@@ -34,7 +34,7 @@ var _server2 = require("react-router-dom/server");
|
|
|
34
34
|
|
|
35
35
|
var _serializeJavascript = _interopRequireDefault(require("serialize-javascript"));
|
|
36
36
|
|
|
37
|
-
var _time =
|
|
37
|
+
var _time = require("../shared/utils/time");
|
|
38
38
|
|
|
39
39
|
var _winston = _interopRequireDefault(require("winston"));
|
|
40
40
|
|
|
@@ -379,7 +379,7 @@ function factory(webpackConfig, options) {
|
|
|
379
379
|
/* eslint-disable no-await-in-loop */
|
|
380
380
|
|
|
381
381
|
const timeout = ops.ssrTimeout + ssrStart - Date.now();
|
|
382
|
-
bailed = timeout <= 0 || !(await Promise.race([Promise.allSettled(ssrContext.pending), _time.
|
|
382
|
+
bailed = timeout <= 0 || !(await Promise.race([Promise.allSettled(ssrContext.pending), (0, _time.timer)(timeout).then(() => false)]));
|
|
383
383
|
if (bailed) break;
|
|
384
384
|
/* eslint-enable no-await-in-loop */
|
|
385
385
|
}
|
|
@@ -440,8 +440,6 @@ function factory(webpackConfig, options) {
|
|
|
440
440
|
|
|
441
441
|
const INJ = _nodeForge.default.util.encode64(`${iv}${cipher.output.data}`);
|
|
442
442
|
|
|
443
|
-
const status = ssrContext.status || 200;
|
|
444
|
-
if (status !== 200) res.status(status);
|
|
445
443
|
const chunkSet = new Set(); // TODO: "main" chunk has to be added explicitly,
|
|
446
444
|
// because unlike all other chunks they are not managed by <CodeSplit>
|
|
447
445
|
// component, thus they are not added to the ssrContext.chunks
|
|
@@ -498,6 +496,8 @@ function factory(webpackConfig, options) {
|
|
|
498
496
|
${grouppedExtraScripts[SCRIPT_LOCATIONS.DEFAULT]}
|
|
499
497
|
</body>
|
|
500
498
|
</html>`;
|
|
499
|
+
const status = ssrContext.status || 200;
|
|
500
|
+
if (status !== 200) res.status(status);
|
|
501
501
|
res.send(html);
|
|
502
502
|
|
|
503
503
|
if (cacheRef && status < 500) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderer.js","names":["sanitizedConfig","omit","config","SCRIPT_LOCATIONS","BODY_OPEN","DEFAULT","HEAD_OPEN","getBuildInfo","context","url","path","resolve","JSON","parse","fs","readFileSync","readChunkGroupsJson","buildDir","res","err","prepareCipher","key","Promise","reject","forge","random","getBytes","iv","cipher","createCipher","start","isBrotliAcceptable","req","acceptable","get","ops","split","i","length","type","priority","trim","parseFloat","groupExtraScripts","scripts","script","isString","code","location","undefined","Error","newDefaultLogger","defaultLogLevel","format","transports","winston","createLogger","level","combine","splat","timestamp","colorize","printf","message","stack","rest","Object","keys","stringify","Console","factory","webpackConfig","options","defaults","clone","beforeRender","maxSsrRounds","ssrTimeout","staticCacheSize","logger","defaultLoggerLogLevel","buildInfo","global","TRU_BUILD_INFO","publicPath","outputPath","output","manifestLink","existsSync","cache","staticCacheController","Cache","CHUNK_GROUPS","next","set","cacheRef","data","buffer","status","noCsp","send","done","failed","brotliDecompress","error","html","h","toString","regex","RegExp","nonce","replace","configToInject","extraScripts","initialState","all","helmet","App","Application","ssrContext","state","cloneDeep","chunks","stream","ssrStart","Date","now","renderPass","pipeableStream","renderToPipeableStream","onAllReady","onError","ssrRound","bailed","dirty","timeout","race","allSettled","pending","time","timer","then","logMsg","log","pipe","Writable","write","chunk","_","Helmet","renderStatic","chunkGroups","webpackStats","locals","mapValues","toJson","namedChunkGroups","item","assets","map","name","dr_pogodin_react_utils___split_components","payload","serializeJs","CONFIG","ISTATE","ignoreFunction","unsafe","update","util","createBuffer","finish","INJ","encode64","chunkSet","Set","forEach","asset","add","styleChunkString","scriptChunkString","endsWith","grouppedExtraScripts","faviconLink","favicon","title","meta","brotliCompress"],"sources":["../../../src/server/renderer.jsx"],"sourcesContent":["/**\n * ExpressJS middleware for server-side rendering of a ReactJS app.\n */\n\nimport { Writable } from 'stream';\n\nimport { GlobalStateProvider } from '@dr.pogodin/react-global-state';\n\nimport {\n clone,\n cloneDeep,\n defaults,\n isString,\n get,\n mapValues,\n omit,\n} from 'lodash';\n\nimport config from 'config';\nimport forge from 'node-forge';\nimport fs from 'fs';\nimport path from 'path';\nimport { brotliCompress, brotliDecompress } from 'zlib';\n\nimport { renderToPipeableStream } from 'react-dom/server';\nimport { Helmet } from 'react-helmet';\nimport { StaticRouter } from 'react-router-dom/server';\nimport serializeJs from 'serialize-javascript';\nimport time from 'utils/time';\nimport winston from 'winston';\n\nimport Cache from './Cache';\n\nconst sanitizedConfig = omit(config, 'SECRET');\n\nexport const SCRIPT_LOCATIONS = {\n BODY_OPEN: 'BODY_OPEN',\n DEFAULT: 'DEFAULT',\n HEAD_OPEN: 'HEAD_OPEN',\n};\n\n/**\n * Reads build-time information about the app. This information is generated\n * by our standard Webpack config for apps, and it is written into\n * \".build-info\" file in the context folder specified in Webpack config.\n * At the moment, that file contains build timestamp and a random 32-bit key,\n * suitable for cryptographical use.\n * @ignore\n * @param {String} context Webpack context path used during the build.\n * @return {Object} Resolves to the build-time information.\n */\nfunction getBuildInfo(context) {\n const url = path.resolve(context, '.build-info');\n return JSON.parse(fs.readFileSync(url));\n}\n\n/**\n * Attempts to read from disk the named chunk groups mapping generated\n * by Webpack during the compilation.\n * It will not work for development builds, where these stats should be captured\n * via compilator callback.\n * @ignore\n * @param {string} buildDir\n * @return {object}\n */\nfunction readChunkGroupsJson(buildDir) {\n const url = path.resolve(buildDir, '__chunk_groups__.json');\n let res;\n try {\n res = JSON.parse(fs.readFileSync(url));\n } catch (err) {\n res = null;\n }\n return res;\n}\n\n/**\n * Prepares a new Cipher for data encryption.\n * @ignore\n * @param {String} key Encryption key (32-bit random key is expected, see\n * node-forge documentation, in case of doubts).\n * @return {Promise} Resolves to the object with two fields:\n * 1. cipher - a new Cipher, ready for encryption;\n * 2. iv - initial vector used by the cipher.\n */\nfunction prepareCipher(key) {\n return new Promise((resolve, reject) => {\n forge.random.getBytes(32, (err, iv) => {\n if (err) reject(err);\n else {\n const cipher = forge.cipher.createCipher('AES-CBC', key);\n cipher.start({ iv });\n resolve({ cipher, iv });\n }\n });\n });\n}\n\n/**\n * Given an incoming HTTP requests, it deduces whether Brotli-encoded responses\n * are acceptable to the caller.\n * @param {object} req\n * @return {boolean}\n * @ignore\n */\nexport function isBrotliAcceptable(req) {\n const acceptable = req.get('accept-encoding');\n if (acceptable) {\n const ops = acceptable.split(',');\n for (let i = 0; i < ops.length; ++i) {\n const [type, priority] = ops[i].trim().split(';q=');\n if ((type === '*' || type === 'br')\n && (!priority || parseFloat(priority) > 0)) {\n return true;\n }\n }\n }\n return false;\n}\n\n/**\n * Given an array of extra script strings / objects, it returns an object with\n * arrays of scripts to inject in different HTML template locations. During\n * the script groupping it also filters out any empty scripts.\n * @param {({\n * code: string;\n * location: string;\n * }|string)[]} [scripts=[]]\n * @return {{\n * BODY_OPEN: string[];\n * DEFAULT: string[];\n * HEAD_OPEN: string[];\n * }}\n */\nfunction groupExtraScripts(scripts = []) {\n const res = {\n [SCRIPT_LOCATIONS.BODY_OPEN]: '',\n [SCRIPT_LOCATIONS.DEFAULT]: '',\n [SCRIPT_LOCATIONS.HEAD_OPEN]: '',\n };\n for (let i = 0; i < scripts.length; ++i) {\n const script = scripts[i];\n if (isString(script)) {\n if (script) res[SCRIPT_LOCATIONS.DEFAULT] += script;\n } else if (script.code) {\n if (res[script.location] !== undefined) {\n res[script.location] += script.code;\n } else throw Error(`Invalid location \"${script.location}\"`);\n }\n }\n return res;\n}\n\n/**\n * Creates a new default (Winston) logger.\n * @param {object} [options={}]\n * @param {string} [options.defaultLogLevel='info']\n * @return {object}\n */\nexport function newDefaultLogger({\n defaultLogLevel = 'info',\n} = {}) {\n const { format, transports } = winston;\n return winston.createLogger({\n level: defaultLogLevel,\n format: format.combine(\n format.splat(),\n format.timestamp(),\n format.colorize(),\n format.printf(\n ({\n level,\n message,\n timestamp,\n stack,\n ...rest\n }) => {\n let res = `${level}\\t(at ${timestamp}):\\t${message}`;\n if (Object.keys(rest).length) {\n res += `\\n${JSON.stringify(rest, null, 2)}`;\n }\n if (stack) res += `\\n${stack}`;\n return res;\n },\n ),\n ),\n transports: [new transports.Console()],\n });\n}\n\n/**\n * Creates the middleware.\n * @param {object} webpackConfig\n * @param {object} options Additional options:\n * @param {Component} [options.Application] The root ReactJS component of\n * the app to use for the server-side rendering. When not provided\n * the server-side rendering is disabled.\n * @param {object} [options.buildInfo] \"Build info\" object to use. If provided,\n * it will be used, instead of trying to load from the filesystem the one\n * generated by the Webpack build. It is intended for test environments,\n * where passing this stuff via file system is no bueno.\n * @param {boolean} [options.favicon] `true` will include favicon\n * link into the rendered HTML templates.\n * @param {boolean} [options.noCsp] `true` means that no\n * Content-Security-Policy (CSP) is used by server, thus the renderer\n * may cut a few corners.\n * @param {number} [options.maxSsrRounds=10] Maximum number of SSR rounds.\n * @param {number} [options.ssrTimeout=1000] SSR timeout in milliseconds,\n * defaults to 1 second.\n * @param {number} [options.staticCacheSize=1.e7] The maximum\n * static cache size in bytes. Defaults to ~10 MB.\n * @param {function} [options.staticCacheController] When given, it activates,\n * and controls the static caching of generated HTML markup. When this function\n * is provided, on each incoming request it is triggered with the request\n * passed in as the argument. To attempt to serve the response from the cache\n * it should return the object with the following fields:\n * - `key: string` – the cache key for the response;\n * - `maxage?: number` – the maximum age of cached result in ms.\n * If undefined - infinite age is assumed.\n * @return {function} Created middleware.\n */\nexport default function factory(webpackConfig, options) {\n const ops = defaults(clone(options), {\n beforeRender: () => Promise.resolve({}),\n maxSsrRounds: 10,\n ssrTimeout: 1000,\n staticCacheSize: 1.e7,\n });\n\n // Note: in normal use the default logger is created and set in the root\n // server function, and this initialization is for testing uses, where\n // renderer is imported directly.\n if (ops.logger === undefined) {\n ops.logger = newDefaultLogger({\n defaultLogLevel: ops.defaultLoggerLogLevel,\n });\n }\n\n const buildInfo = ops.buildInfo || getBuildInfo(webpackConfig.context);\n global.TRU_BUILD_INFO = buildInfo;\n\n // publicPath from webpack.output has a trailing slash at the end.\n const { publicPath, path: outputPath } = webpackConfig.output;\n\n const manifestLink = fs.existsSync(`${outputPath}/manifest.json`)\n ? `<link rel=\"manifest\" href=\"${publicPath}manifest.json\">` : '';\n\n const cache = ops.staticCacheController\n ? new Cache(ops.staticCacheSize) : null;\n\n const CHUNK_GROUPS = readChunkGroupsJson(outputPath);\n\n return async (req, res, next) => {\n try {\n // Ensures any caches always revalidate HTML markup before reuse.\n res.set('Cache-Control', 'no-cache');\n\n let cacheRef;\n if (cache) {\n cacheRef = ops.staticCacheController(req);\n if (cacheRef) {\n const data = cache.get(cacheRef);\n if (data !== null) {\n const { buffer, status } = data;\n if (ops.noCsp && isBrotliAcceptable(req)) {\n res.set('Content-Type', 'text/html');\n res.set('Content-Encoding', 'br');\n if (status !== 200) res.status(status);\n res.send(buffer);\n } else {\n await new Promise((done, failed) => {\n brotliDecompress(buffer, (error, html) => {\n if (error) failed(error);\n else {\n let h = html.toString();\n if (!ops.noCsp) {\n // TODO: Starting from Node v15 we'll be able to use string's\n // .replaceAll() method instead relying on reg. expression for\n // global matching.\n const regex = new RegExp(buffer.nonce, 'g');\n h = h.replace(regex, req.nonce);\n }\n if (status !== 200) res.status(status);\n res.send(h);\n done();\n }\n });\n });\n }\n return;\n }\n }\n }\n\n const [{\n configToInject,\n extraScripts,\n initialState,\n }, {\n cipher,\n iv,\n }] = await Promise.all([\n ops.beforeRender(req, sanitizedConfig),\n prepareCipher(buildInfo.key),\n ]);\n\n let helmet;\n\n /* Optional server-side rendering. */\n let App = ops.Application;\n const ssrContext = {\n req,\n state: cloneDeep(initialState || {}),\n\n // Array of chunk names encountered during the rendering.\n chunks: [],\n };\n let stream;\n if (App) {\n const ssrStart = Date.now();\n\n const renderPass = async () => {\n ssrContext.chunks = [];\n return new Promise((resolve, reject) => {\n const pipeableStream = renderToPipeableStream(\n <GlobalStateProvider\n initialState={ssrContext.state}\n ssrContext={ssrContext}\n >\n <StaticRouter location={req.url}>\n <App />\n </StaticRouter>\n </GlobalStateProvider>,\n {\n onAllReady: () => resolve(pipeableStream),\n onError: reject,\n },\n );\n });\n };\n\n let ssrRound = 0;\n let bailed = false;\n for (; ssrRound < ops.maxSsrRounds; ++ssrRound) {\n stream = await renderPass(); // eslint-disable-line no-await-in-loop\n\n if (!ssrContext.dirty) break;\n\n /* eslint-disable no-await-in-loop */\n const timeout = ops.ssrTimeout + ssrStart - Date.now();\n bailed = timeout <= 0 || !await Promise.race([\n Promise.allSettled(ssrContext.pending),\n time.timer(timeout).then(() => false),\n ]);\n if (bailed) break;\n /* eslint-enable no-await-in-loop */\n }\n\n let logMsg;\n if (ssrContext.dirty) {\n // NOTE: In the case of incomplete SSR one more round is necessary\n // to ensure the correct hydration when some pending promises have\n // resolved and placed their data into the initial global state.\n stream = await renderPass();\n\n logMsg = bailed ? `SSR timed out after ${ops.ssrTimeout} second(s)`\n : `SSR bailed out after ${ops.maxSsrRounds} round(s)`;\n } else logMsg = `SSR completed in ${ssrRound + 1} round(s)`;\n\n ops.logger.log(ssrContext.dirty ? 'warn' : 'info', logMsg);\n\n App = '';\n stream.pipe(new Writable({\n write: (chunk, _, done) => {\n App += chunk.toString();\n done();\n },\n }));\n\n /* This takes care about server-side rendering of page title and meta tags\n * (still demands injection into HTML template, which happens below). */\n helmet = Helmet.renderStatic();\n }\n\n let chunkGroups;\n const webpackStats = get(res.locals, 'webpack.devMiddleware.stats');\n if (webpackStats) {\n chunkGroups = mapValues(\n webpackStats.toJson({\n all: false,\n chunkGroups: true,\n }).namedChunkGroups,\n (item) => item.assets.map(({ name }) => name),\n );\n } else if (CHUNK_GROUPS) chunkGroups = CHUNK_GROUPS;\n else chunkGroups = {};\n\n /* Encrypts data to be injected into HTML.\n * Keep in mind, that this encryption is no way secure: as the JS bundle\n * contains decryption key and is able to decode it at the client side.\n * Hovewer, for a number of reasons, encryption of injected data is still\n * better than injection of a plain text. */\n delete ssrContext.state.dr_pogodin_react_utils___split_components;\n\n const payload = serializeJs({\n CHUNK_GROUPS: chunkGroups,\n CONFIG: configToInject || sanitizedConfig,\n ISTATE: ssrContext.state,\n }, {\n ignoreFunction: true,\n unsafe: true,\n });\n cipher.update(forge.util.createBuffer(payload, 'utf8'));\n cipher.finish();\n const INJ = forge.util.encode64(`${iv}${cipher.output.data}`);\n\n const status = ssrContext.status || 200;\n if (status !== 200) res.status(status);\n\n const chunkSet = new Set();\n\n // TODO: \"main\" chunk has to be added explicitly,\n // because unlike all other chunks they are not managed by <CodeSplit>\n // component, thus they are not added to the ssrContext.chunks\n // automatically. Actually, names of these entry chunks should be\n // read from Wepback config, as the end user may customize them,\n // remove or add other entry points, but it requires additional\n // efforts to figure out how to automatically order them right,\n // thus for now this handles the default config.\n [\n 'main',\n ...ssrContext.chunks,\n ].forEach((chunk) => {\n const assets = chunkGroups[chunk];\n if (assets) assets.forEach((asset) => chunkSet.add(asset));\n });\n\n let styleChunkString = '';\n let scriptChunkString = '';\n chunkSet.forEach((chunk) => {\n if (chunk.endsWith('.css')) {\n styleChunkString += `<link href=\"${publicPath}${chunk}\" rel=\"stylesheet\">`;\n } else if (\n chunk.endsWith('.js')\n // In dev mode HMR adds JS updates into asset arrays,\n // and they (updates) should be ignored.\n && !chunk.endsWith('.hot-update.js')\n ) {\n scriptChunkString += `<script src=\"${publicPath}${chunk}\" type=\"application/javascript\"></script>`;\n }\n });\n\n const grouppedExtraScripts = groupExtraScripts(extraScripts);\n\n const faviconLink = ops.favicon ? (\n '<link rel=\"shortcut icon\" href=\"/favicon.ico\">'\n ) : '';\n\n const html = `<!DOCTYPE html>\n <html lang=\"en\">\n <head>\n ${grouppedExtraScripts[SCRIPT_LOCATIONS.HEAD_OPEN]}\n ${helmet ? helmet.title.toString() : ''}\n ${helmet ? helmet.meta.toString() : ''}\n <meta name=\"theme-color\" content=\"#FFFFFF\">\n ${manifestLink}\n ${styleChunkString}\n ${faviconLink}\n <meta charset=\"utf-8\">\n <meta\n content=\"width=device-width,initial-scale=1.0\"\n name=\"viewport\"\n >\n </head>\n <body>\n ${grouppedExtraScripts[SCRIPT_LOCATIONS.BODY_OPEN]}\n <div id=\"react-view\">${App || ''}</div>\n <script\n id=\"inj\"\n type=\"application/javascript\"\n ${ops.noCsp ? '' : `nonce=\"${req.nonce}\"`}\n >\n window.INJ=\"${INJ}\"\n </script>\n ${scriptChunkString}\n ${grouppedExtraScripts[SCRIPT_LOCATIONS.DEFAULT]}\n </body>\n </html>`;\n\n res.send(html);\n\n if (cacheRef && status < 500) {\n // Note: waiting for the caching to complete is not strictly necessary,\n // but it greately simplifies testing, and error reporting.\n await new Promise((done, failed) => {\n brotliCompress(html, (error, buffer) => {\n if (error) failed(error);\n else {\n buffer.nonce = req.nonce; // eslint-disable-line no-param-reassign\n cache.add({ buffer, status }, cacheRef.key);\n done();\n }\n });\n });\n }\n } catch (error) {\n next(error);\n }\n };\n}\n"],"mappings":";;;;;;;;;;;;AAIA;;AAEA;;AAEA;;AAUA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;;;AA/BA;AACA;AACA;AA+BA,MAAMA,eAAe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OG,KAAP,EAAc;MACdX,IAAI,CAACW,KAAD,CAAJ;IACD;EACF,CAhQD;AAiQD"}
|
|
1
|
+
{"version":3,"file":"renderer.js","names":["sanitizedConfig","omit","config","SCRIPT_LOCATIONS","BODY_OPEN","DEFAULT","HEAD_OPEN","getBuildInfo","context","url","path","resolve","JSON","parse","fs","readFileSync","readChunkGroupsJson","buildDir","res","err","prepareCipher","key","Promise","reject","forge","random","getBytes","iv","cipher","createCipher","start","isBrotliAcceptable","req","acceptable","get","ops","split","i","length","type","priority","trim","parseFloat","groupExtraScripts","scripts","script","isString","code","location","undefined","Error","newDefaultLogger","defaultLogLevel","format","transports","winston","createLogger","level","combine","splat","timestamp","colorize","printf","message","stack","rest","Object","keys","stringify","Console","factory","webpackConfig","options","defaults","clone","beforeRender","maxSsrRounds","ssrTimeout","staticCacheSize","logger","defaultLoggerLogLevel","buildInfo","global","TRU_BUILD_INFO","publicPath","outputPath","output","manifestLink","existsSync","cache","staticCacheController","Cache","CHUNK_GROUPS","next","set","cacheRef","data","buffer","status","noCsp","send","done","failed","brotliDecompress","error","html","h","toString","regex","RegExp","nonce","replace","configToInject","extraScripts","initialState","all","helmet","App","Application","ssrContext","state","cloneDeep","chunks","stream","ssrStart","Date","now","renderPass","pipeableStream","renderToPipeableStream","onAllReady","onError","ssrRound","bailed","dirty","timeout","race","allSettled","pending","timer","then","logMsg","log","pipe","Writable","write","chunk","_","Helmet","renderStatic","chunkGroups","webpackStats","locals","mapValues","toJson","namedChunkGroups","item","assets","map","name","dr_pogodin_react_utils___split_components","payload","serializeJs","CONFIG","ISTATE","ignoreFunction","unsafe","update","util","createBuffer","finish","INJ","encode64","chunkSet","Set","forEach","asset","add","styleChunkString","scriptChunkString","endsWith","grouppedExtraScripts","faviconLink","favicon","title","meta","brotliCompress"],"sources":["../../../src/server/renderer.jsx"],"sourcesContent":["/**\n * ExpressJS middleware for server-side rendering of a ReactJS app.\n */\n\nimport { Writable } from 'stream';\n\nimport { GlobalStateProvider } from '@dr.pogodin/react-global-state';\n\nimport {\n clone,\n cloneDeep,\n defaults,\n isString,\n get,\n mapValues,\n omit,\n} from 'lodash';\n\nimport config from 'config';\nimport forge from 'node-forge';\nimport fs from 'fs';\nimport path from 'path';\nimport { brotliCompress, brotliDecompress } from 'zlib';\n\nimport { renderToPipeableStream } from 'react-dom/server';\nimport { Helmet } from 'react-helmet';\nimport { StaticRouter } from 'react-router-dom/server';\nimport serializeJs from 'serialize-javascript';\nimport { timer } from 'utils/time';\nimport winston from 'winston';\n\nimport Cache from './Cache';\n\nconst sanitizedConfig = omit(config, 'SECRET');\n\nexport const SCRIPT_LOCATIONS = {\n BODY_OPEN: 'BODY_OPEN',\n DEFAULT: 'DEFAULT',\n HEAD_OPEN: 'HEAD_OPEN',\n};\n\n/**\n * Reads build-time information about the app. This information is generated\n * by our standard Webpack config for apps, and it is written into\n * \".build-info\" file in the context folder specified in Webpack config.\n * At the moment, that file contains build timestamp and a random 32-bit key,\n * suitable for cryptographical use.\n * @ignore\n * @param {String} context Webpack context path used during the build.\n * @return {Object} Resolves to the build-time information.\n */\nfunction getBuildInfo(context) {\n const url = path.resolve(context, '.build-info');\n return JSON.parse(fs.readFileSync(url));\n}\n\n/**\n * Attempts to read from disk the named chunk groups mapping generated\n * by Webpack during the compilation.\n * It will not work for development builds, where these stats should be captured\n * via compilator callback.\n * @ignore\n * @param {string} buildDir\n * @return {object}\n */\nfunction readChunkGroupsJson(buildDir) {\n const url = path.resolve(buildDir, '__chunk_groups__.json');\n let res;\n try {\n res = JSON.parse(fs.readFileSync(url));\n } catch (err) {\n res = null;\n }\n return res;\n}\n\n/**\n * Prepares a new Cipher for data encryption.\n * @ignore\n * @param {String} key Encryption key (32-bit random key is expected, see\n * node-forge documentation, in case of doubts).\n * @return {Promise} Resolves to the object with two fields:\n * 1. cipher - a new Cipher, ready for encryption;\n * 2. iv - initial vector used by the cipher.\n */\nfunction prepareCipher(key) {\n return new Promise((resolve, reject) => {\n forge.random.getBytes(32, (err, iv) => {\n if (err) reject(err);\n else {\n const cipher = forge.cipher.createCipher('AES-CBC', key);\n cipher.start({ iv });\n resolve({ cipher, iv });\n }\n });\n });\n}\n\n/**\n * Given an incoming HTTP requests, it deduces whether Brotli-encoded responses\n * are acceptable to the caller.\n * @param {object} req\n * @return {boolean}\n * @ignore\n */\nexport function isBrotliAcceptable(req) {\n const acceptable = req.get('accept-encoding');\n if (acceptable) {\n const ops = acceptable.split(',');\n for (let i = 0; i < ops.length; ++i) {\n const [type, priority] = ops[i].trim().split(';q=');\n if ((type === '*' || type === 'br')\n && (!priority || parseFloat(priority) > 0)) {\n return true;\n }\n }\n }\n return false;\n}\n\n/**\n * Given an array of extra script strings / objects, it returns an object with\n * arrays of scripts to inject in different HTML template locations. During\n * the script groupping it also filters out any empty scripts.\n * @param {({\n * code: string;\n * location: string;\n * }|string)[]} [scripts=[]]\n * @return {{\n * BODY_OPEN: string[];\n * DEFAULT: string[];\n * HEAD_OPEN: string[];\n * }}\n */\nfunction groupExtraScripts(scripts = []) {\n const res = {\n [SCRIPT_LOCATIONS.BODY_OPEN]: '',\n [SCRIPT_LOCATIONS.DEFAULT]: '',\n [SCRIPT_LOCATIONS.HEAD_OPEN]: '',\n };\n for (let i = 0; i < scripts.length; ++i) {\n const script = scripts[i];\n if (isString(script)) {\n if (script) res[SCRIPT_LOCATIONS.DEFAULT] += script;\n } else if (script.code) {\n if (res[script.location] !== undefined) {\n res[script.location] += script.code;\n } else throw Error(`Invalid location \"${script.location}\"`);\n }\n }\n return res;\n}\n\n/**\n * Creates a new default (Winston) logger.\n * @param {object} [options={}]\n * @param {string} [options.defaultLogLevel='info']\n * @return {object}\n */\nexport function newDefaultLogger({\n defaultLogLevel = 'info',\n} = {}) {\n const { format, transports } = winston;\n return winston.createLogger({\n level: defaultLogLevel,\n format: format.combine(\n format.splat(),\n format.timestamp(),\n format.colorize(),\n format.printf(\n ({\n level,\n message,\n timestamp,\n stack,\n ...rest\n }) => {\n let res = `${level}\\t(at ${timestamp}):\\t${message}`;\n if (Object.keys(rest).length) {\n res += `\\n${JSON.stringify(rest, null, 2)}`;\n }\n if (stack) res += `\\n${stack}`;\n return res;\n },\n ),\n ),\n transports: [new transports.Console()],\n });\n}\n\n/**\n * Creates the middleware.\n * @param {object} webpackConfig\n * @param {object} options Additional options:\n * @param {Component} [options.Application] The root ReactJS component of\n * the app to use for the server-side rendering. When not provided\n * the server-side rendering is disabled.\n * @param {object} [options.buildInfo] \"Build info\" object to use. If provided,\n * it will be used, instead of trying to load from the filesystem the one\n * generated by the Webpack build. It is intended for test environments,\n * where passing this stuff via file system is no bueno.\n * @param {boolean} [options.favicon] `true` will include favicon\n * link into the rendered HTML templates.\n * @param {boolean} [options.noCsp] `true` means that no\n * Content-Security-Policy (CSP) is used by server, thus the renderer\n * may cut a few corners.\n * @param {number} [options.maxSsrRounds=10] Maximum number of SSR rounds.\n * @param {number} [options.ssrTimeout=1000] SSR timeout in milliseconds,\n * defaults to 1 second.\n * @param {number} [options.staticCacheSize=1.e7] The maximum\n * static cache size in bytes. Defaults to ~10 MB.\n * @param {function} [options.staticCacheController] When given, it activates,\n * and controls the static caching of generated HTML markup. When this function\n * is provided, on each incoming request it is triggered with the request\n * passed in as the argument. To attempt to serve the response from the cache\n * it should return the object with the following fields:\n * - `key: string` – the cache key for the response;\n * - `maxage?: number` – the maximum age of cached result in ms.\n * If undefined - infinite age is assumed.\n * @return {function} Created middleware.\n */\nexport default function factory(webpackConfig, options) {\n const ops = defaults(clone(options), {\n beforeRender: () => Promise.resolve({}),\n maxSsrRounds: 10,\n ssrTimeout: 1000,\n staticCacheSize: 1.e7,\n });\n\n // Note: in normal use the default logger is created and set in the root\n // server function, and this initialization is for testing uses, where\n // renderer is imported directly.\n if (ops.logger === undefined) {\n ops.logger = newDefaultLogger({\n defaultLogLevel: ops.defaultLoggerLogLevel,\n });\n }\n\n const buildInfo = ops.buildInfo || getBuildInfo(webpackConfig.context);\n global.TRU_BUILD_INFO = buildInfo;\n\n // publicPath from webpack.output has a trailing slash at the end.\n const { publicPath, path: outputPath } = webpackConfig.output;\n\n const manifestLink = fs.existsSync(`${outputPath}/manifest.json`)\n ? `<link rel=\"manifest\" href=\"${publicPath}manifest.json\">` : '';\n\n const cache = ops.staticCacheController\n ? new Cache(ops.staticCacheSize) : null;\n\n const CHUNK_GROUPS = readChunkGroupsJson(outputPath);\n\n return async (req, res, next) => {\n try {\n // Ensures any caches always revalidate HTML markup before reuse.\n res.set('Cache-Control', 'no-cache');\n\n let cacheRef;\n if (cache) {\n cacheRef = ops.staticCacheController(req);\n if (cacheRef) {\n const data = cache.get(cacheRef);\n if (data !== null) {\n const { buffer, status } = data;\n if (ops.noCsp && isBrotliAcceptable(req)) {\n res.set('Content-Type', 'text/html');\n res.set('Content-Encoding', 'br');\n if (status !== 200) res.status(status);\n res.send(buffer);\n } else {\n await new Promise((done, failed) => {\n brotliDecompress(buffer, (error, html) => {\n if (error) failed(error);\n else {\n let h = html.toString();\n if (!ops.noCsp) {\n // TODO: Starting from Node v15 we'll be able to use string's\n // .replaceAll() method instead relying on reg. expression for\n // global matching.\n const regex = new RegExp(buffer.nonce, 'g');\n h = h.replace(regex, req.nonce);\n }\n if (status !== 200) res.status(status);\n res.send(h);\n done();\n }\n });\n });\n }\n return;\n }\n }\n }\n\n const [{\n configToInject,\n extraScripts,\n initialState,\n }, {\n cipher,\n iv,\n }] = await Promise.all([\n ops.beforeRender(req, sanitizedConfig),\n prepareCipher(buildInfo.key),\n ]);\n\n let helmet;\n\n /* Optional server-side rendering. */\n let App = ops.Application;\n const ssrContext = {\n req,\n state: cloneDeep(initialState || {}),\n\n // Array of chunk names encountered during the rendering.\n chunks: [],\n };\n let stream;\n if (App) {\n const ssrStart = Date.now();\n\n const renderPass = async () => {\n ssrContext.chunks = [];\n return new Promise((resolve, reject) => {\n const pipeableStream = renderToPipeableStream(\n <GlobalStateProvider\n initialState={ssrContext.state}\n ssrContext={ssrContext}\n >\n <StaticRouter location={req.url}>\n <App />\n </StaticRouter>\n </GlobalStateProvider>,\n {\n onAllReady: () => resolve(pipeableStream),\n onError: reject,\n },\n );\n });\n };\n\n let ssrRound = 0;\n let bailed = false;\n for (; ssrRound < ops.maxSsrRounds; ++ssrRound) {\n stream = await renderPass(); // eslint-disable-line no-await-in-loop\n\n if (!ssrContext.dirty) break;\n\n /* eslint-disable no-await-in-loop */\n const timeout = ops.ssrTimeout + ssrStart - Date.now();\n bailed = timeout <= 0 || !await Promise.race([\n Promise.allSettled(ssrContext.pending),\n timer(timeout).then(() => false),\n ]);\n if (bailed) break;\n /* eslint-enable no-await-in-loop */\n }\n\n let logMsg;\n if (ssrContext.dirty) {\n // NOTE: In the case of incomplete SSR one more round is necessary\n // to ensure the correct hydration when some pending promises have\n // resolved and placed their data into the initial global state.\n stream = await renderPass();\n\n logMsg = bailed ? `SSR timed out after ${ops.ssrTimeout} second(s)`\n : `SSR bailed out after ${ops.maxSsrRounds} round(s)`;\n } else logMsg = `SSR completed in ${ssrRound + 1} round(s)`;\n\n ops.logger.log(ssrContext.dirty ? 'warn' : 'info', logMsg);\n\n App = '';\n stream.pipe(new Writable({\n write: (chunk, _, done) => {\n App += chunk.toString();\n done();\n },\n }));\n\n /* This takes care about server-side rendering of page title and meta tags\n * (still demands injection into HTML template, which happens below). */\n helmet = Helmet.renderStatic();\n }\n\n let chunkGroups;\n const webpackStats = get(res.locals, 'webpack.devMiddleware.stats');\n if (webpackStats) {\n chunkGroups = mapValues(\n webpackStats.toJson({\n all: false,\n chunkGroups: true,\n }).namedChunkGroups,\n (item) => item.assets.map(({ name }) => name),\n );\n } else if (CHUNK_GROUPS) chunkGroups = CHUNK_GROUPS;\n else chunkGroups = {};\n\n /* Encrypts data to be injected into HTML.\n * Keep in mind, that this encryption is no way secure: as the JS bundle\n * contains decryption key and is able to decode it at the client side.\n * Hovewer, for a number of reasons, encryption of injected data is still\n * better than injection of a plain text. */\n delete ssrContext.state.dr_pogodin_react_utils___split_components;\n\n const payload = serializeJs({\n CHUNK_GROUPS: chunkGroups,\n CONFIG: configToInject || sanitizedConfig,\n ISTATE: ssrContext.state,\n }, {\n ignoreFunction: true,\n unsafe: true,\n });\n cipher.update(forge.util.createBuffer(payload, 'utf8'));\n cipher.finish();\n const INJ = forge.util.encode64(`${iv}${cipher.output.data}`);\n\n const chunkSet = new Set();\n\n // TODO: \"main\" chunk has to be added explicitly,\n // because unlike all other chunks they are not managed by <CodeSplit>\n // component, thus they are not added to the ssrContext.chunks\n // automatically. Actually, names of these entry chunks should be\n // read from Wepback config, as the end user may customize them,\n // remove or add other entry points, but it requires additional\n // efforts to figure out how to automatically order them right,\n // thus for now this handles the default config.\n [\n 'main',\n ...ssrContext.chunks,\n ].forEach((chunk) => {\n const assets = chunkGroups[chunk];\n if (assets) assets.forEach((asset) => chunkSet.add(asset));\n });\n\n let styleChunkString = '';\n let scriptChunkString = '';\n chunkSet.forEach((chunk) => {\n if (chunk.endsWith('.css')) {\n styleChunkString += `<link href=\"${publicPath}${chunk}\" rel=\"stylesheet\">`;\n } else if (\n chunk.endsWith('.js')\n // In dev mode HMR adds JS updates into asset arrays,\n // and they (updates) should be ignored.\n && !chunk.endsWith('.hot-update.js')\n ) {\n scriptChunkString += `<script src=\"${publicPath}${chunk}\" type=\"application/javascript\"></script>`;\n }\n });\n\n const grouppedExtraScripts = groupExtraScripts(extraScripts);\n\n const faviconLink = ops.favicon ? (\n '<link rel=\"shortcut icon\" href=\"/favicon.ico\">'\n ) : '';\n\n const html = `<!DOCTYPE html>\n <html lang=\"en\">\n <head>\n ${grouppedExtraScripts[SCRIPT_LOCATIONS.HEAD_OPEN]}\n ${helmet ? helmet.title.toString() : ''}\n ${helmet ? helmet.meta.toString() : ''}\n <meta name=\"theme-color\" content=\"#FFFFFF\">\n ${manifestLink}\n ${styleChunkString}\n ${faviconLink}\n <meta charset=\"utf-8\">\n <meta\n content=\"width=device-width,initial-scale=1.0\"\n name=\"viewport\"\n >\n </head>\n <body>\n ${grouppedExtraScripts[SCRIPT_LOCATIONS.BODY_OPEN]}\n <div id=\"react-view\">${App || ''}</div>\n <script\n id=\"inj\"\n type=\"application/javascript\"\n ${ops.noCsp ? '' : `nonce=\"${req.nonce}\"`}\n >\n window.INJ=\"${INJ}\"\n </script>\n ${scriptChunkString}\n ${grouppedExtraScripts[SCRIPT_LOCATIONS.DEFAULT]}\n </body>\n </html>`;\n\n const status = ssrContext.status || 200;\n if (status !== 200) res.status(status);\n res.send(html);\n\n if (cacheRef && status < 500) {\n // Note: waiting for the caching to complete is not strictly necessary,\n // but it greately simplifies testing, and error reporting.\n await new Promise((done, failed) => {\n brotliCompress(html, (error, buffer) => {\n if (error) failed(error);\n else {\n buffer.nonce = req.nonce; // eslint-disable-line no-param-reassign\n cache.add({ buffer, status }, cacheRef.key);\n done();\n }\n });\n });\n }\n } catch (error) {\n next(error);\n }\n };\n}\n"],"mappings":";;;;;;;;;;;;AAIA;;AAEA;;AAEA;;AAUA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;;;AA/BA;AACA;AACA;AA+BA,MAAMA,eAAe,GAAG,IAAAC,YAAA,EAAKC,eAAL,EAAa,QAAb,CAAxB;AAEO,MAAMC,gBAAgB,GAAG;EAC9BC,SAAS,EAAE,WADmB;EAE9BC,OAAO,EAAE,SAFqB;EAG9BC,SAAS,EAAE;AAHmB,CAAzB;AAMP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;AACA,SAASC,YAAT,CAAsBC,OAAtB,EAA+B;EAC7B,MAAMC,GAAG,GAAGC,aAAA,CAAKC,OAAL,CAAaH,OAAb,EAAsB,aAAtB,CAAZ;;EACA,OAAOI,IAAI,CAACC,KAAL,CAAWC,WAAA,CAAGC,YAAH,CAAgBN,GAAhB,CAAX,CAAP;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASO,mBAAT,CAA6BC,QAA7B,EAAuC;EACrC,MAAMR,GAAG,GAAG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M6F,MAAM,GAAGqB,UAAU,CAACrB,MAAX,IAAqB,GAApC;MACA,IAAIA,MAAM,KAAK,GAAf,EAAoBhF,GAAG,CAACgF,MAAJ,CAAWA,MAAX;MACpBhF,GAAG,CAACkF,IAAJ,CAASK,IAAT;;MAEA,IAAIV,QAAQ,IAAIG,MAAM,GAAG,GAAzB,EAA8B;QAC5B;QACA;QACA,MAAM,IAAI5E,OAAJ,CAAY,CAAC+E,IAAD,EAAOC,MAAP,KAAkB;UAClC,IAAAoF,oBAAA,EAAejF,IAAf,EAAqB,CAACD,KAAD,EAAQP,MAAR,KAAmB;YACtC,IAAIO,KAAJ,EAAWF,MAAM,CAACE,KAAD,CAAN,CAAX,KACK;cACHP,MAAM,CAACa,KAAP,GAAe9E,GAAG,CAAC8E,KAAnB,CADG,CACuB;;cAC1BrB,KAAK,CAACwF,GAAN,CAAU;gBAAEhF,MAAF;gBAAUC;cAAV,CAAV,EAA8BH,QAAQ,CAAC1E,GAAvC;cACAgF,IAAI;YACL;UACF,CAPD;QAQD,CATK,CAAN;MAUD;IACF,CA3PD,CA2PE,OAAOG,KAAP,EAAc;MACdX,IAAI,CAACW,KAAD,CAAJ;IACD;EACF,CA/PD;AAgQD"}
|
|
@@ -43,6 +43,7 @@ class Semaphore {
|
|
|
43
43
|
const barrier = (0, _Barrier.newBarrier)();
|
|
44
44
|
this.#queue.push(barrier);
|
|
45
45
|
await barrier;
|
|
46
|
+
this.#queue.shift();
|
|
46
47
|
}
|
|
47
48
|
} // Private members below this point.
|
|
48
49
|
|
|
@@ -56,8 +57,7 @@ class Semaphore {
|
|
|
56
57
|
|
|
57
58
|
#drainQueue() {
|
|
58
59
|
if (this.#ready && this.#queue.length) {
|
|
59
|
-
|
|
60
|
-
next.resolve(); // Re-schedules itself for the next event loop iteration.
|
|
60
|
+
this.#queue[0].resolve(); // Re-schedules itself for the next event loop iteration.
|
|
61
61
|
|
|
62
62
|
if (this.#queue.length) {
|
|
63
63
|
setTimeout(this.#drainQueue.bind(this));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Semaphore.js","names":["Semaphore","constructor","ready","setReady","bool","draining","drainQueue","seize","waitReady","queue","length","barrier","newBarrier","push","
|
|
1
|
+
{"version":3,"file":"Semaphore.js","names":["Semaphore","constructor","ready","setReady","bool","draining","drainQueue","seize","waitReady","queue","length","barrier","newBarrier","push","shift","resolve","setTimeout","bind"],"sources":["../../../../src/shared/utils/Semaphore.js"],"sourcesContent":["import { newBarrier } from './Barrier';\n\n/**\n * Implements a simple semaphore for async code logic.\n */\nexport default class Semaphore {\n constructor(ready) {\n this.#ready = !!ready;\n }\n\n get ready() { return this.#ready; }\n\n setReady(ready) {\n const bool = !!ready;\n if (this.#ready !== bool) {\n this.#ready = bool;\n if (bool && !this.#draining) this.#drainQueue();\n }\n }\n\n /**\n * Waits until the semaphore is ready, and marks it as non-ready (seizes it).\n * @return {Promise}\n */\n async seize() {\n await this.waitReady();\n this.setReady(false);\n }\n\n async waitReady() {\n if (!this.#ready || this.#queue.length) {\n const barrier = newBarrier();\n this.#queue.push(barrier);\n await barrier;\n this.#queue.shift();\n }\n }\n\n // Private members below this point.\n\n /**\n * If semaphore is ready, it releases the next barrier in the queue, if any,\n * and reschedules itself for a call in the next event loop iteration.\n * Otherwise, it breaks the queue draining loop, which will be restarted\n * the next time the semaphore is set ready.\n */\n #drainQueue() {\n if (this.#ready && this.#queue.length) {\n this.#queue[0].resolve();\n\n // Re-schedules itself for the next event loop iteration.\n if (this.#queue.length) {\n setTimeout(this.#drainQueue.bind(this));\n this.#draining = true;\n return; // Exit here to avoid the drain loop termination below.\n }\n }\n\n // Cleans up for the drain loop termination.\n this.#draining = false;\n }\n\n // \"true\" when the drain queue process is running (and thus no need to start\n // a new one).\n #draining = false;\n\n // The array of barriers set for each async code flow awaiting for\n // the Semaphore to become ready.\n #queue = [];\n\n #ready;\n}\n"],"mappings":";;;;;;;AAAA;;AAEA;AACA;AACA;AACe,MAAMA,SAAN,CAAgB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,QAAN,GAAiB,KAAjB;EACD,CAvD4B,CAyD7B;EACA;;;EACA,CAACA,QAAD,GAAY,KAAZ,CA3D6B,CA6D7B;EACA;;EACA,CAACI,KAAD,GAAS,EAAT;EAEA,CAACP,KAAD;AAjE6B"}
|
|
@@ -73,7 +73,7 @@ var isomorphy = _interopRequireWildcard(require("./isomorphy"));
|
|
|
73
73
|
|
|
74
74
|
exports.isomorphy = isomorphy;
|
|
75
75
|
|
|
76
|
-
var _time =
|
|
76
|
+
var _time = _interopRequireWildcard(require("./time"));
|
|
77
77
|
|
|
78
78
|
var webpack = _interopRequireWildcard(require("./webpack"));
|
|
79
79
|
|
|
@@ -162,7 +162,7 @@ async function withRetries(action, maxRetries = 5, interval = 1000) {
|
|
|
162
162
|
try {
|
|
163
163
|
return await action();
|
|
164
164
|
} catch (error) {
|
|
165
|
-
if (n < maxRetries) await _time.
|
|
165
|
+
if (n < maxRetries) await (0, _time.timer)(interval);else throw error;
|
|
166
166
|
}
|
|
167
167
|
}
|
|
168
168
|
/* eslint-enable no-await-in-loop */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["themed","COMPOSE","PRIORITY","NODE_CONFIG_ENV","process","env","NODE_ENV","JU","webpack","requireWeak","__dirname","withRetries","action","maxRetries","interval","n","error","
|
|
1
|
+
{"version":3,"file":"index.js","names":["themed","COMPOSE","PRIORITY","NODE_CONFIG_ENV","process","env","NODE_ENV","JU","webpack","requireWeak","__dirname","withRetries","action","maxRetries","interval","n","error","timer"],"sources":["../../../../src/shared/utils/index.js"],"sourcesContent":["import themed, {\n COMPOSE,\n PRIORITY,\n ThemeProvider,\n} from '@dr.pogodin/react-themes';\n\nimport config from './config';\nimport * as isomorphy from './isomorphy';\nimport time, { timer } from './time';\nimport * as webpack from './webpack';\n\nexport * from './Barrier';\nexport { default as Emitter } from './Emitter';\nexport { default as Semaphore } from './Semaphore';\nexport { default as splitComponent } from './splitComponent';\n\nthemed.COMPOSE = COMPOSE;\nthemed.PRIORITY = PRIORITY;\n\n// Note: it should be done this way, as in some environments\n// \"process\" might not exist, and process.env.NODE_CONFIG_ENV\n// not injected by Webpack.\nlet NODE_CONFIG_ENV;\ntry {\n NODE_CONFIG_ENV = process.env.NODE_CONFIG_ENV;\n} catch { /* noop */ }\n\nconst env = NODE_CONFIG_ENV || process.env.NODE_ENV;\nconst JU = env !== 'production' && webpack.requireWeak('./jest', __dirname);\n\n/**\n * @category Utilities\n * @global\n * @func withRetries\n * @desc\n * ```js\n * import { withRetries } from '@dr.pogodin/react-utils';\n * ```\n * Attempts to perform given asynchronous `action` up to `maxRetries` times,\n * with the given `interval` between attempts. If any attempt is successful,\n * the result is returned immediately, with no further attempts done;\n * otherwise, if all attempts fail, the result Promise rejects after the last\n * attempt.\n * @param {function} action\n * @param {number} [maxRetries=5] Optional. Maximum number of retries. Defaults\n * to 5 attempts.\n * @param {number} [interval=1000] Optional. Interval between retries [ms].\n * Defaults to 1 second.\n * @return {Promise} Resolves to the result of successful operation, or\n * rejects with the error from the latst failed attempt.\n * @example\n * import { withRetries } from '@dr.pogodin/react-utils';\n *\n * let firstCall = true;\n *\n * function sampleAction() {\n * if (!firstCall) return 'success';\n * firstCall = false;\n * throw Error('The first call to this method fails');\n * }\n *\n * withRetries(sampleAction).then(console.log);\n * // It will print 'success' after one second, once the second attempt\n * // is performed.\n */\nexport async function withRetries(action, maxRetries = 5, interval = 1000) {\n /* eslint-disable no-await-in-loop */\n for (let n = 1; ; ++n) {\n try {\n return await action();\n } catch (error) {\n if (n < maxRetries) await timer(interval);\n else throw error;\n }\n }\n /* eslint-enable no-await-in-loop */\n}\n\nexport {\n config,\n isomorphy,\n JU,\n themed,\n ThemeProvider,\n time,\n webpack,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAMA;;AACA;;;;AACA;;AACA;;;;AAEA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AACA;;AACA;;;;;;AAEAA,oBAAA,CAAOC,OAAP,GAAiBA,oBAAjB;AACAD,oBAAA,CAAOE,QAAP,GAAkBA,qBAAlB,C,CAEA;AACA;AACA;;AACA,IAAIC,eAAJ;;AACA,IAAI;EACFA,eAAe,GAAGC,OAAO,CAACC,GAAR,CAAYF,eAA9B;AACD,CAFD,CAEE,MAAM;EAAE;AAAY;;AAEtB,MAAME,GAAG,GAAGF,eAAe,IAAIC,OAAO,CAACC,GAAR,CAAYC,QAA3C;AACA,MAAMC,EAAE,GAAGF,GAAG,KAAK,YAAR,IAAwBG,OAAO,CAACC,WAAR,WAA8BC,SAA9B,CAAnC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;AACO,eAAeC,WAAf,CAA2BC,MAA3B,EAAmCC,UAAU,GAAG,CAAhD,EAAmDC,QAAQ,GAAG,IAA9D,EAAoE;EACzE;EACA,KAAK,IAAIC,CAAC,GAAG,CAAb,GAAkB,EAAEA,CAApB,EAAuB;IACrB,IAAI;MACF,OAAO,MAAMH,MAAM,EAAnB;IACD,CAFD,CAEE,OAAOI,KAAP,EAAc;MACd,IAAID,CAAC,GAAGF,UAAR,EAAoB,MAAM,IAAAI,WAAA,EAAMH,QAAN,CAAN,CAApB,KACK,MAAME,KAAN;IACN;EACF;EACD;;AACD"}
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.default = void 0;
|
|
9
|
+
exports.timer = timer;
|
|
9
10
|
|
|
10
11
|
var _dayjs = _interopRequireDefault(require("dayjs"));
|
|
11
12
|
|
|
@@ -80,15 +81,16 @@ _dayjs.default.now = Date.now;
|
|
|
80
81
|
* (without resolving or rejecting the barrier).
|
|
81
82
|
*/
|
|
82
83
|
|
|
83
|
-
|
|
84
|
+
async function timer(timeout) {
|
|
84
85
|
const res = new _Barrier.Barrier();
|
|
85
86
|
const id = setTimeout(res.resolve.bind(res), timeout);
|
|
86
87
|
|
|
87
88
|
res.abort = () => clearTimeout(id);
|
|
88
89
|
|
|
89
90
|
return res;
|
|
90
|
-
}
|
|
91
|
+
}
|
|
91
92
|
|
|
93
|
+
_dayjs.default.timer = timer;
|
|
92
94
|
var _default = _dayjs.default;
|
|
93
95
|
exports.default = _default;
|
|
94
96
|
//# sourceMappingURL=time.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time.js","names":["dayjs","SEC_MS","MIN_MS","HOUR_MS","DAY_MS","YEAR_MS","now","Date","timer","timeout","res","Barrier","id","setTimeout","resolve","bind","abort","clearTimeout"],"sources":["../../../../src/shared/utils/time.js"],"sourcesContent":["import dayjs from 'dayjs';\nimport { Barrier } from './Barrier';\n\n/**\n * @static\n * @const SEC_MS\n * @desc One second, expressed in milliseconds (equals 1000 ms).\n * @example\n * import { time } from '@dr.pogodin/react-utils';\n * console.log(time.SEC_MS); // Prints: 1000\n */\ndayjs.SEC_MS = 1000;\n\n/**\n * @static\n * @const MIN_MS\n * @desc One minute, expressed in milliseconds (equals 60 × `SEC_MS`).\n * @example\n * import { time } from '@dr.pogodin/react-utils';\n * console.log(time.MIN_MS); // Prints: 60000\n */\ndayjs.MIN_MS = 60 * dayjs.SEC_MS;\n\n/**\n * @static\n * @const HOUR_MS\n * @desc One hour, expressed in milliseconds (equals 60 × `MIN_MS`).\n * @example\n * import { time } from '@dr.pogodin/react-utils';\n * console.log(time.HOUR_MS); // Prints: 3600000\n */\ndayjs.HOUR_MS = 60 * dayjs.MIN_MS;\n\n/**\n * @static\n * @const DAY_MS\n * @desc One day, expressed in milliseconds (equals 24 × `HOUR_MS`).\n * @example\n * import { time } from '@dr.pogodin/react-utils';\n * console.log(time.DAY_MS); // Prints: 86400000\n */\ndayjs.DAY_MS = 24 * dayjs.HOUR_MS;\n\n/**\n * @static\n * @const YEAR_MS\n * @desc One year, expressed in milliseconds (equals 365 × `DAY_MS`,\n * thus a normal, non-leap year).\n * @example\n * import { time } from '@dr.pogodin/react-utils';\n * console.log(time.YEAR_MS); // Prints: 31536000000\n */\ndayjs.YEAR_MS = 365 * dayjs.DAY_MS;\n\n/**\n * @static\n * @func now\n * @desc Returns Unix timestamp [ms] (thus, it is just an alias for `Date.now`).\n * @return {number}\n * @example\n * import { time } from '@dr.pogodin/react-utils';\n * console.log(time.now()); // Prints the current timestamp, e.g. 1618608761000.\n */\ndayjs.now = Date.now;\n\n/**\n * Creates a Promise, which resolves after the given timeout.\n * @param {number} timeout Timeout [ms].\n * @return {Barrier} Resolves after the timeout. It has additional\n * .abort() method attached, which cancels the pending timer resolution\n * (without resolving or rejecting the barrier).\n */\
|
|
1
|
+
{"version":3,"file":"time.js","names":["dayjs","SEC_MS","MIN_MS","HOUR_MS","DAY_MS","YEAR_MS","now","Date","timer","timeout","res","Barrier","id","setTimeout","resolve","bind","abort","clearTimeout"],"sources":["../../../../src/shared/utils/time.js"],"sourcesContent":["import dayjs from 'dayjs';\nimport { Barrier } from './Barrier';\n\n/**\n * @static\n * @const SEC_MS\n * @desc One second, expressed in milliseconds (equals 1000 ms).\n * @example\n * import { time } from '@dr.pogodin/react-utils';\n * console.log(time.SEC_MS); // Prints: 1000\n */\ndayjs.SEC_MS = 1000;\n\n/**\n * @static\n * @const MIN_MS\n * @desc One minute, expressed in milliseconds (equals 60 × `SEC_MS`).\n * @example\n * import { time } from '@dr.pogodin/react-utils';\n * console.log(time.MIN_MS); // Prints: 60000\n */\ndayjs.MIN_MS = 60 * dayjs.SEC_MS;\n\n/**\n * @static\n * @const HOUR_MS\n * @desc One hour, expressed in milliseconds (equals 60 × `MIN_MS`).\n * @example\n * import { time } from '@dr.pogodin/react-utils';\n * console.log(time.HOUR_MS); // Prints: 3600000\n */\ndayjs.HOUR_MS = 60 * dayjs.MIN_MS;\n\n/**\n * @static\n * @const DAY_MS\n * @desc One day, expressed in milliseconds (equals 24 × `HOUR_MS`).\n * @example\n * import { time } from '@dr.pogodin/react-utils';\n * console.log(time.DAY_MS); // Prints: 86400000\n */\ndayjs.DAY_MS = 24 * dayjs.HOUR_MS;\n\n/**\n * @static\n * @const YEAR_MS\n * @desc One year, expressed in milliseconds (equals 365 × `DAY_MS`,\n * thus a normal, non-leap year).\n * @example\n * import { time } from '@dr.pogodin/react-utils';\n * console.log(time.YEAR_MS); // Prints: 31536000000\n */\ndayjs.YEAR_MS = 365 * dayjs.DAY_MS;\n\n/**\n * @static\n * @func now\n * @desc Returns Unix timestamp [ms] (thus, it is just an alias for `Date.now`).\n * @return {number}\n * @example\n * import { time } from '@dr.pogodin/react-utils';\n * console.log(time.now()); // Prints the current timestamp, e.g. 1618608761000.\n */\ndayjs.now = Date.now;\n\n/**\n * Creates a Promise, which resolves after the given timeout.\n * @param {number} timeout Timeout [ms].\n * @return {Barrier} Resolves after the timeout. It has additional\n * .abort() method attached, which cancels the pending timer resolution\n * (without resolving or rejecting the barrier).\n */\nexport async function timer(timeout) {\n const res = new Barrier();\n const id = setTimeout(res.resolve.bind(res), timeout);\n res.abort = () => clearTimeout(id);\n return res;\n}\n\ndayjs.timer = timer;\n\nexport default dayjs;\n"],"mappings":";;;;;;;;;;AAAA;;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACAA,cAAA,CAAMC,MAAN,GAAe,IAAf;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACAD,cAAA,CAAME,MAAN,GAAe,KAAKF,cAAA,CAAMC,MAA1B;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACAD,cAAA,CAAMG,OAAN,GAAgB,KAAKH,cAAA,CAAME,MAA3B;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACAF,cAAA,CAAMI,MAAN,GAAe,KAAKJ,cAAA,CAAMG,OAA1B;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACAH,cAAA,CAAMK,OAAN,GAAgB,MAAML,cAAA,CAAMI,MAA5B;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACAJ,cAAA,CAAMM,GAAN,GAAYC,IAAI,CAACD,GAAjB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACO,eAAeE,KAAf,CAAqBC,OAArB,EAA8B;EACnC,MAAMC,GAAG,GAAG,IAAIC,gBAAJ,EAAZ;EACA,MAAMC,EAAE,GAAGC,UAAU,CAACH,GAAG,CAACI,OAAJ,CAAYC,IAAZ,CAAiBL,GAAjB,CAAD,EAAwBD,OAAxB,CAArB;;EACAC,GAAG,CAACM,KAAJ,GAAY,MAAMC,YAAY,CAACL,EAAD,CAA9B;;EACA,OAAOF,GAAP;AACD;;AAEDV,cAAA,CAAMQ,KAAN,GAAcA,KAAd;eAEeR,c"}
|
|
@@ -236,7 +236,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac
|
|
|
236
236
|
\***************************************/
|
|
237
237
|
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
238
238
|
|
|
239
|
-
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": function() { return /* binding */ Semaphore; }\n/* harmony export */ });\n/* harmony import */ var _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/asyncToGenerator */ \"@babel/runtime/helpers/asyncToGenerator\");\n/* harmony import */ var _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ \"@babel/runtime/helpers/classCallCheck\");\n/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_1__);\n/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @babel/runtime/helpers/createClass */ \"@babel/runtime/helpers/createClass\");\n/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_2__);\n/* harmony import */ var _babel_runtime_helpers_classPrivateFieldGet__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @babel/runtime/helpers/classPrivateFieldGet */ \"@babel/runtime/helpers/classPrivateFieldGet\");\n/* harmony import */ var _babel_runtime_helpers_classPrivateFieldGet__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classPrivateFieldGet__WEBPACK_IMPORTED_MODULE_3__);\n/* harmony import */ var _babel_runtime_helpers_classPrivateFieldSet__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @babel/runtime/helpers/classPrivateFieldSet */ \"@babel/runtime/helpers/classPrivateFieldSet\");\n/* harmony import */ var _babel_runtime_helpers_classPrivateFieldSet__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classPrivateFieldSet__WEBPACK_IMPORTED_MODULE_4__);\n/* harmony import */ var _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @babel/runtime/regenerator */ \"@babel/runtime/regenerator\");\n/* harmony import */ var _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_5__);\n/* harmony import */ var _Barrier__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./Barrier */ \"./src/shared/utils/Barrier.js\");\n\n\n\n\n\n\n\nfunction _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }\n\nfunction _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }\n\nfunction _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError(\"Cannot initialize the same private elements twice on an object\"); } }\n\nfunction _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError(\"attempted to get private field on non-instance\"); } return fn; }\n\n\n/**\n * Implements a simple semaphore for async code logic.\n */\n\nvar _drainQueue = /*#__PURE__*/new WeakSet();\n\nvar _draining = /*#__PURE__*/new WeakMap();\n\nvar _queue = /*#__PURE__*/new WeakMap();\n\nvar _ready = /*#__PURE__*/new WeakMap();\n\nvar Semaphore = /*#__PURE__*/function () {\n function Semaphore(ready) {\n _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_1___default()(this, Semaphore);\n\n _classPrivateMethodInitSpec(this, _drainQueue);\n\n _classPrivateFieldInitSpec(this, _draining, {\n writable: true,\n value: false\n });\n\n _classPrivateFieldInitSpec(this, _queue, {\n writable: true,\n value: []\n });\n\n _classPrivateFieldInitSpec(this, _ready, {\n writable: true,\n value: void 0\n });\n\n _babel_runtime_helpers_classPrivateFieldSet__WEBPACK_IMPORTED_MODULE_4___default()(this, _ready, !!ready);\n }\n\n _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_2___default()(Semaphore, [{\n key: \"ready\",\n get: function get() {\n return _babel_runtime_helpers_classPrivateFieldGet__WEBPACK_IMPORTED_MODULE_3___default()(this, _ready);\n }\n }, {\n key: \"setReady\",\n value: function setReady(ready) {\n var bool = !!ready;\n\n if (_babel_runtime_helpers_classPrivateFieldGet__WEBPACK_IMPORTED_MODULE_3___default()(this, _ready) !== bool) {\n _babel_runtime_helpers_classPrivateFieldSet__WEBPACK_IMPORTED_MODULE_4___default()(this, _ready, bool);\n\n if (bool && !_babel_runtime_helpers_classPrivateFieldGet__WEBPACK_IMPORTED_MODULE_3___default()(this, _draining)) _classPrivateMethodGet(this, _drainQueue, _drainQueue2).call(this);\n }\n }\n /**\n * Waits until the semaphore is ready, and marks it as non-ready (seizes it).\n * @return {Promise}\n */\n\n }, {\n key: \"seize\",\n value: function () {\n var _seize = _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0___default()( /*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_5___default().mark(function _callee() {\n return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_5___default().wrap(function _callee$(_context) {\n while (1) {\n switch (_context.prev = _context.next) {\n case 0:\n _context.next = 2;\n return this.waitReady();\n\n case 2:\n this.setReady(false);\n\n case 3:\n case \"end\":\n return _context.stop();\n }\n }\n }, _callee, this);\n }));\n\n function seize() {\n return _seize.apply(this, arguments);\n }\n\n return seize;\n }()\n }, {\n key: \"waitReady\",\n value: function () {\n var _waitReady = _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0___default()( /*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_5___default().mark(function _callee2() {\n var barrier;\n return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_5___default().wrap(function _callee2$(_context2) {\n while (1) {\n switch (_context2.prev = _context2.next) {\n case 0:\n if (!(!_babel_runtime_helpers_classPrivateFieldGet__WEBPACK_IMPORTED_MODULE_3___default()(this, _ready) || _babel_runtime_helpers_classPrivateFieldGet__WEBPACK_IMPORTED_MODULE_3___default()(this, _queue).length)) {\n _context2.next =
|
|
239
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": function() { return /* binding */ Semaphore; }\n/* harmony export */ });\n/* harmony import */ var _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/asyncToGenerator */ \"@babel/runtime/helpers/asyncToGenerator\");\n/* harmony import */ var _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ \"@babel/runtime/helpers/classCallCheck\");\n/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_1__);\n/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @babel/runtime/helpers/createClass */ \"@babel/runtime/helpers/createClass\");\n/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_2__);\n/* harmony import */ var _babel_runtime_helpers_classPrivateFieldGet__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @babel/runtime/helpers/classPrivateFieldGet */ \"@babel/runtime/helpers/classPrivateFieldGet\");\n/* harmony import */ var _babel_runtime_helpers_classPrivateFieldGet__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classPrivateFieldGet__WEBPACK_IMPORTED_MODULE_3__);\n/* harmony import */ var _babel_runtime_helpers_classPrivateFieldSet__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @babel/runtime/helpers/classPrivateFieldSet */ \"@babel/runtime/helpers/classPrivateFieldSet\");\n/* harmony import */ var _babel_runtime_helpers_classPrivateFieldSet__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classPrivateFieldSet__WEBPACK_IMPORTED_MODULE_4__);\n/* harmony import */ var _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @babel/runtime/regenerator */ \"@babel/runtime/regenerator\");\n/* harmony import */ var _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_5__);\n/* harmony import */ var _Barrier__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./Barrier */ \"./src/shared/utils/Barrier.js\");\n\n\n\n\n\n\n\nfunction _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }\n\nfunction _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }\n\nfunction _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError(\"Cannot initialize the same private elements twice on an object\"); } }\n\nfunction _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError(\"attempted to get private field on non-instance\"); } return fn; }\n\n\n/**\n * Implements a simple semaphore for async code logic.\n */\n\nvar _drainQueue = /*#__PURE__*/new WeakSet();\n\nvar _draining = /*#__PURE__*/new WeakMap();\n\nvar _queue = /*#__PURE__*/new WeakMap();\n\nvar _ready = /*#__PURE__*/new WeakMap();\n\nvar Semaphore = /*#__PURE__*/function () {\n function Semaphore(ready) {\n _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_1___default()(this, Semaphore);\n\n _classPrivateMethodInitSpec(this, _drainQueue);\n\n _classPrivateFieldInitSpec(this, _draining, {\n writable: true,\n value: false\n });\n\n _classPrivateFieldInitSpec(this, _queue, {\n writable: true,\n value: []\n });\n\n _classPrivateFieldInitSpec(this, _ready, {\n writable: true,\n value: void 0\n });\n\n _babel_runtime_helpers_classPrivateFieldSet__WEBPACK_IMPORTED_MODULE_4___default()(this, _ready, !!ready);\n }\n\n _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_2___default()(Semaphore, [{\n key: \"ready\",\n get: function get() {\n return _babel_runtime_helpers_classPrivateFieldGet__WEBPACK_IMPORTED_MODULE_3___default()(this, _ready);\n }\n }, {\n key: \"setReady\",\n value: function setReady(ready) {\n var bool = !!ready;\n\n if (_babel_runtime_helpers_classPrivateFieldGet__WEBPACK_IMPORTED_MODULE_3___default()(this, _ready) !== bool) {\n _babel_runtime_helpers_classPrivateFieldSet__WEBPACK_IMPORTED_MODULE_4___default()(this, _ready, bool);\n\n if (bool && !_babel_runtime_helpers_classPrivateFieldGet__WEBPACK_IMPORTED_MODULE_3___default()(this, _draining)) _classPrivateMethodGet(this, _drainQueue, _drainQueue2).call(this);\n }\n }\n /**\n * Waits until the semaphore is ready, and marks it as non-ready (seizes it).\n * @return {Promise}\n */\n\n }, {\n key: \"seize\",\n value: function () {\n var _seize = _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0___default()( /*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_5___default().mark(function _callee() {\n return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_5___default().wrap(function _callee$(_context) {\n while (1) {\n switch (_context.prev = _context.next) {\n case 0:\n _context.next = 2;\n return this.waitReady();\n\n case 2:\n this.setReady(false);\n\n case 3:\n case \"end\":\n return _context.stop();\n }\n }\n }, _callee, this);\n }));\n\n function seize() {\n return _seize.apply(this, arguments);\n }\n\n return seize;\n }()\n }, {\n key: \"waitReady\",\n value: function () {\n var _waitReady = _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0___default()( /*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_5___default().mark(function _callee2() {\n var barrier;\n return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_5___default().wrap(function _callee2$(_context2) {\n while (1) {\n switch (_context2.prev = _context2.next) {\n case 0:\n if (!(!_babel_runtime_helpers_classPrivateFieldGet__WEBPACK_IMPORTED_MODULE_3___default()(this, _ready) || _babel_runtime_helpers_classPrivateFieldGet__WEBPACK_IMPORTED_MODULE_3___default()(this, _queue).length)) {\n _context2.next = 6;\n break;\n }\n\n barrier = (0,_Barrier__WEBPACK_IMPORTED_MODULE_6__.newBarrier)();\n\n _babel_runtime_helpers_classPrivateFieldGet__WEBPACK_IMPORTED_MODULE_3___default()(this, _queue).push(barrier);\n\n _context2.next = 5;\n return barrier;\n\n case 5:\n _babel_runtime_helpers_classPrivateFieldGet__WEBPACK_IMPORTED_MODULE_3___default()(this, _queue).shift();\n\n case 6:\n case \"end\":\n return _context2.stop();\n }\n }\n }, _callee2, this);\n }));\n\n function waitReady() {\n return _waitReady.apply(this, arguments);\n }\n\n return waitReady;\n }() // Private members below this point.\n\n /**\n * If semaphore is ready, it releases the next barrier in the queue, if any,\n * and reschedules itself for a call in the next event loop iteration.\n * Otherwise, it breaks the queue draining loop, which will be restarted\n * the next time the semaphore is set ready.\n */\n\n }]);\n\n return Semaphore;\n}();\n\nfunction _drainQueue2() {\n if (_babel_runtime_helpers_classPrivateFieldGet__WEBPACK_IMPORTED_MODULE_3___default()(this, _ready) && _babel_runtime_helpers_classPrivateFieldGet__WEBPACK_IMPORTED_MODULE_3___default()(this, _queue).length) {\n _babel_runtime_helpers_classPrivateFieldGet__WEBPACK_IMPORTED_MODULE_3___default()(this, _queue)[0].resolve(); // Re-schedules itself for the next event loop iteration.\n\n\n if (_babel_runtime_helpers_classPrivateFieldGet__WEBPACK_IMPORTED_MODULE_3___default()(this, _queue).length) {\n setTimeout(_classPrivateMethodGet(this, _drainQueue, _drainQueue2).bind(this));\n\n _babel_runtime_helpers_classPrivateFieldSet__WEBPACK_IMPORTED_MODULE_4___default()(this, _draining, true);\n\n return; // Exit here to avoid the drain loop termination below.\n }\n } // Cleans up for the drain loop termination.\n\n\n _babel_runtime_helpers_classPrivateFieldSet__WEBPACK_IMPORTED_MODULE_4___default()(this, _draining, false);\n}\n\n\n\n//# sourceURL=webpack://@dr.pogodin/react-utils/./src/shared/utils/Semaphore.js?");
|
|
240
240
|
|
|
241
241
|
/***/ }),
|
|
242
242
|
|
|
@@ -256,7 +256,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _web
|
|
|
256
256
|
\***********************************/
|
|
257
257
|
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
258
258
|
|
|
259
|
-
eval("var __dirname = \"/\";\n__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"Barrier\": function() { return /* reexport safe */ _Barrier__WEBPACK_IMPORTED_MODULE_7__.Barrier; },\n/* harmony export */ \"Emitter\": function() { return /* reexport safe */ _Emitter__WEBPACK_IMPORTED_MODULE_8__[\"default\"]; },\n/* harmony export */ \"JU\": function() { return /* binding */ JU; },\n/* harmony export */ \"Semaphore\": function() { return /* reexport safe */ _Semaphore__WEBPACK_IMPORTED_MODULE_9__[\"default\"]; },\n/* harmony export */ \"ThemeProvider\": function() { return /* reexport safe */ _dr_pogodin_react_themes__WEBPACK_IMPORTED_MODULE_2__.ThemeProvider; },\n/* harmony export */ \"config\": function() { return /* reexport safe */ _config__WEBPACK_IMPORTED_MODULE_3__[\"default\"]; },\n/* harmony export */ \"isomorphy\": function() { return /* reexport module object */ _isomorphy__WEBPACK_IMPORTED_MODULE_4__; },\n/* harmony export */ \"newBarrier\": function() { return /* reexport safe */ _Barrier__WEBPACK_IMPORTED_MODULE_7__.newBarrier; },\n/* harmony export */ \"splitComponent\": function() { return /* reexport safe */ _splitComponent__WEBPACK_IMPORTED_MODULE_10__[\"default\"]; },\n/* harmony export */ \"themed\": function() { return /* reexport default from dynamic */ _dr_pogodin_react_themes__WEBPACK_IMPORTED_MODULE_2___default.a; },\n/* harmony export */ \"time\": function() { return /* reexport safe */ _time__WEBPACK_IMPORTED_MODULE_5__[\"default\"]; },\n/* harmony export */ \"webpack\": function() { return /* reexport module object */ _webpack__WEBPACK_IMPORTED_MODULE_6__; },\n/* harmony export */ \"withRetries\": function() { return /* binding */ withRetries; }\n/* harmony export */ });\n/* harmony import */ var _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/asyncToGenerator */ \"@babel/runtime/helpers/asyncToGenerator\");\n/* harmony import */ var _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/regenerator */ \"@babel/runtime/regenerator\");\n/* harmony import */ var _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_1__);\n/* harmony import */ var _dr_pogodin_react_themes__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @dr.pogodin/react-themes */ \"@dr.pogodin/react-themes\");\n/* harmony import */ var _dr_pogodin_react_themes__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_dr_pogodin_react_themes__WEBPACK_IMPORTED_MODULE_2__);\n/* harmony import */ var _config__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./config */ \"./src/shared/utils/config.js\");\n/* harmony import */ var _isomorphy__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./isomorphy */ \"./src/shared/utils/isomorphy.js\");\n/* harmony import */ var _time__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./time */ \"./src/shared/utils/time.js\");\n/* harmony import */ var _webpack__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./webpack */ \"./src/shared/utils/webpack.js\");\n/* harmony import */ var _Barrier__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./Barrier */ \"./src/shared/utils/Barrier.js\");\n/* harmony import */ var _Emitter__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./Emitter */ \"./src/shared/utils/Emitter.js\");\n/* harmony import */ var _Semaphore__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./Semaphore */ \"./src/shared/utils/Semaphore.js\");\n/* harmony import */ var _splitComponent__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./splitComponent */ \"./src/shared/utils/splitComponent.js\");\n\n\n\n\n\n\n\n\n\n\n\n(_dr_pogodin_react_themes__WEBPACK_IMPORTED_MODULE_2___default().COMPOSE) = _dr_pogodin_react_themes__WEBPACK_IMPORTED_MODULE_2__.COMPOSE;\n(_dr_pogodin_react_themes__WEBPACK_IMPORTED_MODULE_2___default().PRIORITY) = _dr_pogodin_react_themes__WEBPACK_IMPORTED_MODULE_2__.PRIORITY; // Note: it should be done this way, as in some environments\n// \"process\" might not exist, and process.env.NODE_CONFIG_ENV\n// not injected by Webpack.\n\nvar NODE_CONFIG_ENV;\n\ntry {\n NODE_CONFIG_ENV = process.env.NODE_CONFIG_ENV;\n} catch (_unused) {\n /* noop */\n}\n\nvar env = NODE_CONFIG_ENV || \"development\";\nvar JU = env !== 'production' && _webpack__WEBPACK_IMPORTED_MODULE_6__.requireWeak('./jest', __dirname);\n/**\n * @category Utilities\n * @global\n * @func withRetries\n * @desc\n * ```js\n * import { withRetries } from '@dr.pogodin/react-utils';\n * ```\n * Attempts to perform given asynchronous `action` up to `maxRetries` times,\n * with the given `interval` between attempts. If any attempt is successful,\n * the result is returned immediately, with no further attempts done;\n * otherwise, if all attempts fail, the result Promise rejects after the last\n * attempt.\n * @param {function} action\n * @param {number} [maxRetries=5] Optional. Maximum number of retries. Defaults\n * to 5 attempts.\n * @param {number} [interval=1000] Optional. Interval between retries [ms].\n * Defaults to 1 second.\n * @return {Promise} Resolves to the result of successful operation, or\n * rejects with the error from the latst failed attempt.\n * @example\n * import { withRetries } from '@dr.pogodin/react-utils';\n *\n * let firstCall = true;\n *\n * function sampleAction() {\n * if (!firstCall) return 'success';\n * firstCall = false;\n * throw Error('The first call to this method fails');\n * }\n *\n * withRetries(sampleAction).then(console.log);\n * // It will print 'success' after one second, once the second attempt\n * // is performed.\n */\n\nfunction withRetries(_x) {\n return _withRetries.apply(this, arguments);\n}\n\nfunction _withRetries() {\n _withRetries = _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0___default()( /*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_1___default().mark(function _callee(action) {\n var maxRetries,\n interval,\n n,\n _args = arguments;\n return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_1___default().wrap(function _callee$(_context) {\n while (1) {\n switch (_context.prev = _context.next) {\n case 0:\n maxRetries = _args.length > 1 && _args[1] !== undefined ? _args[1] : 5;\n interval = _args.length > 2 && _args[2] !== undefined ? _args[2] : 1000;\n n = 1;\n\n case 3:\n _context.prev = 3;\n _context.next = 6;\n return action();\n\n case 6:\n return _context.abrupt(\"return\", _context.sent);\n\n case 9:\n _context.prev = 9;\n _context.t0 = _context[\"catch\"](3);\n\n if (!(n < maxRetries)) {\n _context.next = 16;\n break;\n }\n\n _context.next = 14;\n return _time__WEBPACK_IMPORTED_MODULE_5__
|
|
259
|
+
eval("var __dirname = \"/\";\n__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"Barrier\": function() { return /* reexport safe */ _Barrier__WEBPACK_IMPORTED_MODULE_7__.Barrier; },\n/* harmony export */ \"Emitter\": function() { return /* reexport safe */ _Emitter__WEBPACK_IMPORTED_MODULE_8__[\"default\"]; },\n/* harmony export */ \"JU\": function() { return /* binding */ JU; },\n/* harmony export */ \"Semaphore\": function() { return /* reexport safe */ _Semaphore__WEBPACK_IMPORTED_MODULE_9__[\"default\"]; },\n/* harmony export */ \"ThemeProvider\": function() { return /* reexport safe */ _dr_pogodin_react_themes__WEBPACK_IMPORTED_MODULE_2__.ThemeProvider; },\n/* harmony export */ \"config\": function() { return /* reexport safe */ _config__WEBPACK_IMPORTED_MODULE_3__[\"default\"]; },\n/* harmony export */ \"isomorphy\": function() { return /* reexport module object */ _isomorphy__WEBPACK_IMPORTED_MODULE_4__; },\n/* harmony export */ \"newBarrier\": function() { return /* reexport safe */ _Barrier__WEBPACK_IMPORTED_MODULE_7__.newBarrier; },\n/* harmony export */ \"splitComponent\": function() { return /* reexport safe */ _splitComponent__WEBPACK_IMPORTED_MODULE_10__[\"default\"]; },\n/* harmony export */ \"themed\": function() { return /* reexport default from dynamic */ _dr_pogodin_react_themes__WEBPACK_IMPORTED_MODULE_2___default.a; },\n/* harmony export */ \"time\": function() { return /* reexport safe */ _time__WEBPACK_IMPORTED_MODULE_5__[\"default\"]; },\n/* harmony export */ \"webpack\": function() { return /* reexport module object */ _webpack__WEBPACK_IMPORTED_MODULE_6__; },\n/* harmony export */ \"withRetries\": function() { return /* binding */ withRetries; }\n/* harmony export */ });\n/* harmony import */ var _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/asyncToGenerator */ \"@babel/runtime/helpers/asyncToGenerator\");\n/* harmony import */ var _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/regenerator */ \"@babel/runtime/regenerator\");\n/* harmony import */ var _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_1__);\n/* harmony import */ var _dr_pogodin_react_themes__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @dr.pogodin/react-themes */ \"@dr.pogodin/react-themes\");\n/* harmony import */ var _dr_pogodin_react_themes__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_dr_pogodin_react_themes__WEBPACK_IMPORTED_MODULE_2__);\n/* harmony import */ var _config__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./config */ \"./src/shared/utils/config.js\");\n/* harmony import */ var _isomorphy__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./isomorphy */ \"./src/shared/utils/isomorphy.js\");\n/* harmony import */ var _time__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./time */ \"./src/shared/utils/time.js\");\n/* harmony import */ var _webpack__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./webpack */ \"./src/shared/utils/webpack.js\");\n/* harmony import */ var _Barrier__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./Barrier */ \"./src/shared/utils/Barrier.js\");\n/* harmony import */ var _Emitter__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./Emitter */ \"./src/shared/utils/Emitter.js\");\n/* harmony import */ var _Semaphore__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./Semaphore */ \"./src/shared/utils/Semaphore.js\");\n/* harmony import */ var _splitComponent__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./splitComponent */ \"./src/shared/utils/splitComponent.js\");\n\n\n\n\n\n\n\n\n\n\n\n(_dr_pogodin_react_themes__WEBPACK_IMPORTED_MODULE_2___default().COMPOSE) = _dr_pogodin_react_themes__WEBPACK_IMPORTED_MODULE_2__.COMPOSE;\n(_dr_pogodin_react_themes__WEBPACK_IMPORTED_MODULE_2___default().PRIORITY) = _dr_pogodin_react_themes__WEBPACK_IMPORTED_MODULE_2__.PRIORITY; // Note: it should be done this way, as in some environments\n// \"process\" might not exist, and process.env.NODE_CONFIG_ENV\n// not injected by Webpack.\n\nvar NODE_CONFIG_ENV;\n\ntry {\n NODE_CONFIG_ENV = process.env.NODE_CONFIG_ENV;\n} catch (_unused) {\n /* noop */\n}\n\nvar env = NODE_CONFIG_ENV || \"development\";\nvar JU = env !== 'production' && _webpack__WEBPACK_IMPORTED_MODULE_6__.requireWeak('./jest', __dirname);\n/**\n * @category Utilities\n * @global\n * @func withRetries\n * @desc\n * ```js\n * import { withRetries } from '@dr.pogodin/react-utils';\n * ```\n * Attempts to perform given asynchronous `action` up to `maxRetries` times,\n * with the given `interval` between attempts. If any attempt is successful,\n * the result is returned immediately, with no further attempts done;\n * otherwise, if all attempts fail, the result Promise rejects after the last\n * attempt.\n * @param {function} action\n * @param {number} [maxRetries=5] Optional. Maximum number of retries. Defaults\n * to 5 attempts.\n * @param {number} [interval=1000] Optional. Interval between retries [ms].\n * Defaults to 1 second.\n * @return {Promise} Resolves to the result of successful operation, or\n * rejects with the error from the latst failed attempt.\n * @example\n * import { withRetries } from '@dr.pogodin/react-utils';\n *\n * let firstCall = true;\n *\n * function sampleAction() {\n * if (!firstCall) return 'success';\n * firstCall = false;\n * throw Error('The first call to this method fails');\n * }\n *\n * withRetries(sampleAction).then(console.log);\n * // It will print 'success' after one second, once the second attempt\n * // is performed.\n */\n\nfunction withRetries(_x) {\n return _withRetries.apply(this, arguments);\n}\n\nfunction _withRetries() {\n _withRetries = _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0___default()( /*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_1___default().mark(function _callee(action) {\n var maxRetries,\n interval,\n n,\n _args = arguments;\n return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_1___default().wrap(function _callee$(_context) {\n while (1) {\n switch (_context.prev = _context.next) {\n case 0:\n maxRetries = _args.length > 1 && _args[1] !== undefined ? _args[1] : 5;\n interval = _args.length > 2 && _args[2] !== undefined ? _args[2] : 1000;\n n = 1;\n\n case 3:\n _context.prev = 3;\n _context.next = 6;\n return action();\n\n case 6:\n return _context.abrupt(\"return\", _context.sent);\n\n case 9:\n _context.prev = 9;\n _context.t0 = _context[\"catch\"](3);\n\n if (!(n < maxRetries)) {\n _context.next = 16;\n break;\n }\n\n _context.next = 14;\n return (0,_time__WEBPACK_IMPORTED_MODULE_5__.timer)(interval);\n\n case 14:\n _context.next = 17;\n break;\n\n case 16:\n throw _context.t0;\n\n case 17:\n ++n;\n _context.next = 3;\n break;\n\n case 20:\n case \"end\":\n return _context.stop();\n }\n }\n }, _callee, null, [[3, 9]]);\n }));\n return _withRetries.apply(this, arguments);\n}\n\n\n\n//# sourceURL=webpack://@dr.pogodin/react-utils/./src/shared/utils/index.js?");
|
|
260
260
|
|
|
261
261
|
/***/ }),
|
|
262
262
|
|
|
@@ -286,7 +286,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac
|
|
|
286
286
|
\**********************************/
|
|
287
287
|
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
288
288
|
|
|
289
|
-
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/asyncToGenerator */ \"@babel/runtime/helpers/asyncToGenerator\");\n/* harmony import */ var _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/regenerator */ \"@babel/runtime/regenerator\");\n/* harmony import */ var _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_1__);\n/* harmony import */ var dayjs__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! dayjs */ \"dayjs\");\n/* harmony import */ var dayjs__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(dayjs__WEBPACK_IMPORTED_MODULE_2__);\n/* harmony import */ var _Barrier__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./Barrier */ \"./src/shared/utils/Barrier.js\");\n\n\n\n\n/**\n * @static\n * @const SEC_MS\n * @desc One second, expressed in milliseconds (equals 1000 ms).\n * @example\n * import { time } from '@dr.pogodin/react-utils';\n * console.log(time.SEC_MS); // Prints: 1000\n */\n\n(dayjs__WEBPACK_IMPORTED_MODULE_2___default().SEC_MS) = 1000;\n/**\n * @static\n * @const MIN_MS\n * @desc One minute, expressed in milliseconds (equals 60 × `SEC_MS`).\n * @example\n * import { time } from '@dr.pogodin/react-utils';\n * console.log(time.MIN_MS); // Prints: 60000\n */\n\n(dayjs__WEBPACK_IMPORTED_MODULE_2___default().MIN_MS) = 60 * (dayjs__WEBPACK_IMPORTED_MODULE_2___default().SEC_MS);\n/**\n * @static\n * @const HOUR_MS\n * @desc One hour, expressed in milliseconds (equals 60 × `MIN_MS`).\n * @example\n * import { time } from '@dr.pogodin/react-utils';\n * console.log(time.HOUR_MS); // Prints: 3600000\n */\n\n(dayjs__WEBPACK_IMPORTED_MODULE_2___default().HOUR_MS) = 60 * (dayjs__WEBPACK_IMPORTED_MODULE_2___default().MIN_MS);\n/**\n * @static\n * @const DAY_MS\n * @desc One day, expressed in milliseconds (equals 24 × `HOUR_MS`).\n * @example\n * import { time } from '@dr.pogodin/react-utils';\n * console.log(time.DAY_MS); // Prints: 86400000\n */\n\n(dayjs__WEBPACK_IMPORTED_MODULE_2___default().DAY_MS) = 24 * (dayjs__WEBPACK_IMPORTED_MODULE_2___default().HOUR_MS);\n/**\n * @static\n * @const YEAR_MS\n * @desc One year, expressed in milliseconds (equals 365 × `DAY_MS`,\n * thus a normal, non-leap year).\n * @example\n * import { time } from '@dr.pogodin/react-utils';\n * console.log(time.YEAR_MS); // Prints: 31536000000\n */\n\n(dayjs__WEBPACK_IMPORTED_MODULE_2___default().YEAR_MS) = 365 * (dayjs__WEBPACK_IMPORTED_MODULE_2___default().DAY_MS);\n/**\n * @static\n * @func now\n * @desc Returns Unix timestamp [ms] (thus, it is just an alias for `Date.now`).\n * @return {number}\n * @example\n * import { time } from '@dr.pogodin/react-utils';\n * console.log(time.now()); // Prints the current timestamp, e.g. 1618608761000.\n */\n\n(dayjs__WEBPACK_IMPORTED_MODULE_2___default().now) = Date.now;\n/**\n * Creates a Promise, which resolves after the given timeout.\n * @param {number} timeout Timeout [ms].\n * @return {Barrier} Resolves after the timeout. It has additional\n * .abort() method attached, which cancels the pending timer resolution\n * (without resolving or rejecting the barrier).\n */\n\
|
|
289
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"timer\": function() { return /* binding */ timer; }\n/* harmony export */ });\n/* harmony import */ var _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/asyncToGenerator */ \"@babel/runtime/helpers/asyncToGenerator\");\n/* harmony import */ var _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/regenerator */ \"@babel/runtime/regenerator\");\n/* harmony import */ var _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_1__);\n/* harmony import */ var dayjs__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! dayjs */ \"dayjs\");\n/* harmony import */ var dayjs__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(dayjs__WEBPACK_IMPORTED_MODULE_2__);\n/* harmony import */ var _Barrier__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./Barrier */ \"./src/shared/utils/Barrier.js\");\n\n\n\n\n/**\n * @static\n * @const SEC_MS\n * @desc One second, expressed in milliseconds (equals 1000 ms).\n * @example\n * import { time } from '@dr.pogodin/react-utils';\n * console.log(time.SEC_MS); // Prints: 1000\n */\n\n(dayjs__WEBPACK_IMPORTED_MODULE_2___default().SEC_MS) = 1000;\n/**\n * @static\n * @const MIN_MS\n * @desc One minute, expressed in milliseconds (equals 60 × `SEC_MS`).\n * @example\n * import { time } from '@dr.pogodin/react-utils';\n * console.log(time.MIN_MS); // Prints: 60000\n */\n\n(dayjs__WEBPACK_IMPORTED_MODULE_2___default().MIN_MS) = 60 * (dayjs__WEBPACK_IMPORTED_MODULE_2___default().SEC_MS);\n/**\n * @static\n * @const HOUR_MS\n * @desc One hour, expressed in milliseconds (equals 60 × `MIN_MS`).\n * @example\n * import { time } from '@dr.pogodin/react-utils';\n * console.log(time.HOUR_MS); // Prints: 3600000\n */\n\n(dayjs__WEBPACK_IMPORTED_MODULE_2___default().HOUR_MS) = 60 * (dayjs__WEBPACK_IMPORTED_MODULE_2___default().MIN_MS);\n/**\n * @static\n * @const DAY_MS\n * @desc One day, expressed in milliseconds (equals 24 × `HOUR_MS`).\n * @example\n * import { time } from '@dr.pogodin/react-utils';\n * console.log(time.DAY_MS); // Prints: 86400000\n */\n\n(dayjs__WEBPACK_IMPORTED_MODULE_2___default().DAY_MS) = 24 * (dayjs__WEBPACK_IMPORTED_MODULE_2___default().HOUR_MS);\n/**\n * @static\n * @const YEAR_MS\n * @desc One year, expressed in milliseconds (equals 365 × `DAY_MS`,\n * thus a normal, non-leap year).\n * @example\n * import { time } from '@dr.pogodin/react-utils';\n * console.log(time.YEAR_MS); // Prints: 31536000000\n */\n\n(dayjs__WEBPACK_IMPORTED_MODULE_2___default().YEAR_MS) = 365 * (dayjs__WEBPACK_IMPORTED_MODULE_2___default().DAY_MS);\n/**\n * @static\n * @func now\n * @desc Returns Unix timestamp [ms] (thus, it is just an alias for `Date.now`).\n * @return {number}\n * @example\n * import { time } from '@dr.pogodin/react-utils';\n * console.log(time.now()); // Prints the current timestamp, e.g. 1618608761000.\n */\n\n(dayjs__WEBPACK_IMPORTED_MODULE_2___default().now) = Date.now;\n/**\n * Creates a Promise, which resolves after the given timeout.\n * @param {number} timeout Timeout [ms].\n * @return {Barrier} Resolves after the timeout. It has additional\n * .abort() method attached, which cancels the pending timer resolution\n * (without resolving or rejecting the barrier).\n */\n\nfunction timer(_x) {\n return _timer.apply(this, arguments);\n}\n\nfunction _timer() {\n _timer = _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0___default()( /*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_1___default().mark(function _callee(timeout) {\n var res, id;\n return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_1___default().wrap(function _callee$(_context) {\n while (1) {\n switch (_context.prev = _context.next) {\n case 0:\n res = new _Barrier__WEBPACK_IMPORTED_MODULE_3__.Barrier();\n id = setTimeout(res.resolve.bind(res), timeout);\n\n res.abort = function () {\n return clearTimeout(id);\n };\n\n return _context.abrupt(\"return\", res);\n\n case 4:\n case \"end\":\n return _context.stop();\n }\n }\n }, _callee);\n }));\n return _timer.apply(this, arguments);\n}\n\n(dayjs__WEBPACK_IMPORTED_MODULE_2___default().timer) = timer;\n/* harmony default export */ __webpack_exports__[\"default\"] = ((dayjs__WEBPACK_IMPORTED_MODULE_2___default()));\n\n//# sourceURL=webpack://@dr.pogodin/react-utils/./src/shared/utils/time.js?");
|
|
290
290
|
|
|
291
291
|
/***/ }),
|
|
292
292
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.SCRIPT_LOCATIONS=void 0;exports.default=factory;exports.isBrotliAcceptable=isBrotliAcceptable;exports.newDefaultLogger=newDefaultLogger;var _stream=require("stream");var _reactGlobalState=require("@dr.pogodin/react-global-state");var _lodash=require("lodash");var _config=_interopRequireDefault(require("config"));var _nodeForge=_interopRequireDefault(require("node-forge"));var _fs=_interopRequireDefault(require("fs"));var _path=_interopRequireDefault(require("path"));var _zlib=require("zlib");var _server=require("react-dom/server");var _reactHelmet=require("react-helmet");var _server2=require("react-router-dom/server");var _serializeJavascript=_interopRequireDefault(require("serialize-javascript"));var _time=
|
|
1
|
+
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.SCRIPT_LOCATIONS=void 0;exports.default=factory;exports.isBrotliAcceptable=isBrotliAcceptable;exports.newDefaultLogger=newDefaultLogger;var _stream=require("stream");var _reactGlobalState=require("@dr.pogodin/react-global-state");var _lodash=require("lodash");var _config=_interopRequireDefault(require("config"));var _nodeForge=_interopRequireDefault(require("node-forge"));var _fs=_interopRequireDefault(require("fs"));var _path=_interopRequireDefault(require("path"));var _zlib=require("zlib");var _server=require("react-dom/server");var _reactHelmet=require("react-helmet");var _server2=require("react-router-dom/server");var _serializeJavascript=_interopRequireDefault(require("serialize-javascript"));var _time=require("../shared/utils/time");var _winston=_interopRequireDefault(require("winston"));var _Cache=_interopRequireDefault(require("./Cache"));var _jsxRuntime=require("react/jsx-runtime");/**
|
|
2
2
|
* ExpressJS middleware for server-side rendering of a ReactJS app.
|
|
3
3
|
*/const sanitizedConfig=(0,_lodash.omit)(_config.default,"SECRET");const SCRIPT_LOCATIONS={BODY_OPEN:"BODY_OPEN",DEFAULT:"DEFAULT",HEAD_OPEN:"HEAD_OPEN"};/**
|
|
4
4
|
* Reads build-time information about the app. This information is generated
|
|
@@ -89,7 +89,7 @@ res.set("Cache-Control","no-cache");let cacheRef;if(cache){cacheRef=ops.staticCa
|
|
|
89
89
|
// global matching.
|
|
90
90
|
const regex=new RegExp(buffer.nonce,"g");h=h.replace(regex,req.nonce)}if(status!==200)res.status(status);res.send(h);done()}})})}return}}}const[{configToInject,extraScripts,initialState},{cipher,iv}]=await Promise.all([ops.beforeRender(req,sanitizedConfig),prepareCipher(buildInfo.key)]);let helmet;/* Optional server-side rendering. */let App=ops.Application;const ssrContext={req,state:(0,_lodash.cloneDeep)(initialState||{}),// Array of chunk names encountered during the rendering.
|
|
91
91
|
chunks:[]};let stream;if(App){const ssrStart=Date.now();const renderPass=async()=>{ssrContext.chunks=[];return new Promise((resolve,reject)=>{const pipeableStream=(0,_server.renderToPipeableStream)(/*#__PURE__*/(0,_jsxRuntime.jsx)(_reactGlobalState.GlobalStateProvider,{initialState:ssrContext.state,ssrContext:ssrContext,children:/*#__PURE__*/(0,_jsxRuntime.jsx)(_server2.StaticRouter,{location:req.url,children:/*#__PURE__*/(0,_jsxRuntime.jsx)(App,{})})}),{onAllReady:()=>resolve(pipeableStream),onError:reject})})};let ssrRound=0;let bailed=false;for(;ssrRound<ops.maxSsrRounds;++ssrRound){stream=await renderPass();// eslint-disable-line no-await-in-loop
|
|
92
|
-
if(!ssrContext.dirty)break;/* eslint-disable no-await-in-loop */const timeout=ops.ssrTimeout+ssrStart-Date.now();bailed=timeout<=0||!(await Promise.race([Promise.allSettled(ssrContext.pending),_time.
|
|
92
|
+
if(!ssrContext.dirty)break;/* eslint-disable no-await-in-loop */const timeout=ops.ssrTimeout+ssrStart-Date.now();bailed=timeout<=0||!(await Promise.race([Promise.allSettled(ssrContext.pending),(0,_time.timer)(timeout).then(()=>false)]));if(bailed)break;/* eslint-enable no-await-in-loop */}let logMsg;if(ssrContext.dirty){// NOTE: In the case of incomplete SSR one more round is necessary
|
|
93
93
|
// to ensure the correct hydration when some pending promises have
|
|
94
94
|
// resolved and placed their data into the initial global state.
|
|
95
95
|
stream=await renderPass();logMsg=bailed?`SSR timed out after ${ops.ssrTimeout} second(s)`:`SSR bailed out after ${ops.maxSsrRounds} round(s)`}else logMsg=`SSR completed in ${ssrRound+1} round(s)`;ops.logger.log(ssrContext.dirty?"warn":"info",logMsg);App="";stream.pipe(new _stream.Writable({write:(chunk,_,done)=>{App+=chunk.toString();done()}}));/* This takes care about server-side rendering of page title and meta tags
|
|
@@ -97,7 +97,7 @@ stream=await renderPass();logMsg=bailed?`SSR timed out after ${ops.ssrTimeout} s
|
|
|
97
97
|
* Keep in mind, that this encryption is no way secure: as the JS bundle
|
|
98
98
|
* contains decryption key and is able to decode it at the client side.
|
|
99
99
|
* Hovewer, for a number of reasons, encryption of injected data is still
|
|
100
|
-
* better than injection of a plain text. */delete ssrContext.state.dr_pogodin_react_utils___split_components;const payload=(0,_serializeJavascript.default)({CHUNK_GROUPS:chunkGroups,CONFIG:configToInject||sanitizedConfig,ISTATE:ssrContext.state},{ignoreFunction:true,unsafe:true});cipher.update(_nodeForge.default.util.createBuffer(payload,"utf8"));cipher.finish();const INJ=_nodeForge.default.util.encode64(`${iv}${cipher.output.data}`);const
|
|
100
|
+
* better than injection of a plain text. */delete ssrContext.state.dr_pogodin_react_utils___split_components;const payload=(0,_serializeJavascript.default)({CHUNK_GROUPS:chunkGroups,CONFIG:configToInject||sanitizedConfig,ISTATE:ssrContext.state},{ignoreFunction:true,unsafe:true});cipher.update(_nodeForge.default.util.createBuffer(payload,"utf8"));cipher.finish();const INJ=_nodeForge.default.util.encode64(`${iv}${cipher.output.data}`);const chunkSet=new Set;// TODO: "main" chunk has to be added explicitly,
|
|
101
101
|
// because unlike all other chunks they are not managed by <CodeSplit>
|
|
102
102
|
// component, thus they are not added to the ssrContext.chunks
|
|
103
103
|
// automatically. Actually, names of these entry chunks should be
|
|
@@ -136,7 +136,7 @@ stream=await renderPass();logMsg=bailed?`SSR timed out after ${ops.ssrTimeout} s
|
|
|
136
136
|
${scriptChunkString}
|
|
137
137
|
${grouppedExtraScripts[SCRIPT_LOCATIONS.DEFAULT]}
|
|
138
138
|
</body>
|
|
139
|
-
</html>`;res.send(html);if(cacheRef&&status<500){// Note: waiting for the caching to complete is not strictly necessary,
|
|
139
|
+
</html>`;const status=ssrContext.status||200;if(status!==200)res.status(status);res.send(html);if(cacheRef&&status<500){// Note: waiting for the caching to complete is not strictly necessary,
|
|
140
140
|
// but it greately simplifies testing, and error reporting.
|
|
141
141
|
await new Promise((done,failed)=>{(0,_zlib.brotliCompress)(html,(error,buffer)=>{if(error)failed(error);else{buffer.nonce=req.nonce;// eslint-disable-line no-param-reassign
|
|
142
142
|
cache.add({buffer,status},cacheRef.key);done()}})})}}catch(error){next(error)}}}
|