@statoscope/report-writer
Advanced tools
Comparing version 5.22.0 to 5.25.0-alpha.0
/// <reference types="node" /> | ||
import { PassThrough, Readable } from 'stream'; | ||
export { encode as encodeBinaryJSON } from './binary-json'; | ||
export declare type InitArg = { | ||
@@ -11,2 +12,6 @@ id: string; | ||
} | { | ||
type: 'cjs'; | ||
path: string; | ||
name: string; | ||
} | { | ||
type: 'raw'; | ||
@@ -21,2 +26,3 @@ content: string; | ||
jsonExtAPIName?: string; | ||
dataCompression?: boolean; | ||
}; | ||
@@ -23,0 +29,0 @@ export default class HTMLWriter { |
@@ -6,5 +6,24 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.encodeBinaryJSON = void 0; | ||
const fs_1 = __importDefault(require("fs")); | ||
const stream_1 = require("stream"); | ||
const chunkToScriptWriter_1 = __importDefault(require("./chunkToScriptWriter")); | ||
var binary_json_1 = require("./binary-json"); | ||
Object.defineProperty(exports, "encodeBinaryJSON", { enumerable: true, get: function () { return binary_json_1.encode; } }); | ||
const scriptsToInject = [ | ||
{ | ||
type: 'path', | ||
path: require.resolve('@discoveryjs/json-ext/dist/json-ext.min.js'), | ||
}, | ||
{ | ||
type: 'cjs', | ||
path: require.resolve('pako/dist/pako.es5.min.js'), | ||
name: 'Pako', | ||
}, | ||
{ | ||
type: 'cjs', | ||
path: require.resolve('./binary-json'), | ||
name: 'BinaryJSON', | ||
}, | ||
]; | ||
class HTMLWriter { | ||
@@ -44,9 +63,29 @@ constructor(options) { | ||
} | ||
const content = asset.type === 'path' | ||
? fs_1.default.readFileSync(require.resolve(asset.path), 'utf8') | ||
: asset.content; | ||
let content; | ||
if (asset.type === 'path') { | ||
content = fs_1.default.readFileSync(require.resolve(asset.path), 'utf8'); | ||
} | ||
else if (asset.type === 'raw') { | ||
content = asset.content; | ||
} | ||
else if (asset.type === 'cjs') { | ||
content = fs_1.default.readFileSync(require.resolve(asset.path), 'utf8'); | ||
content = ` | ||
window['${asset.name}'] = (() => { | ||
const exports = {}; | ||
const module = { exports }; | ||
((module, exports) => { | ||
${content} | ||
})(module, exports); | ||
return module.exports; | ||
})(); | ||
`; | ||
} | ||
else { | ||
throw new Error('Unknown type'); | ||
} | ||
return `<${type}>${content}</${type}>`; | ||
} | ||
function writeHeader(stream, options) { | ||
var _a, _b; | ||
var _a, _b, _c, _d; | ||
stream.write(`<!doctype html> | ||
@@ -63,2 +102,3 @@ <html lang="en"> | ||
-webkit-text-size-adjust: 100%; | ||
font-family: Helvetica, sans-serif; | ||
} | ||
@@ -71,3 +111,2 @@ | ||
right: 0; | ||
left: 0; | ||
width: 100%; | ||
@@ -79,7 +118,7 @@ height: 100%; | ||
-webkit-box-pack: center; | ||
-ms-flex-pack: center; | ||
justify-content: center; | ||
-ms-flex-pack: center; | ||
justify-content: center; | ||
} | ||
.logo { | ||
.wrapper { | ||
position: relative; | ||
@@ -89,7 +128,15 @@ top: 20%; | ||
height: 10vw; | ||
display: -webkit-box; | ||
display: -ms-flexbox; | ||
display: flex; | ||
-webkit-box-orient: vertical; | ||
-webkit-box-direction: normal; | ||
-ms-flex-direction: column; | ||
flex-direction: column; | ||
-webkit-box-align: center; | ||
-ms-flex-align: center; | ||
align-items: center; | ||
} | ||
.logo > svg { | ||
-webkit-animation: rotate 3s ease infinite; | ||
animation: rotate 3s ease infinite; | ||
width: 100%; | ||
@@ -99,19 +146,5 @@ height: 100%; | ||
@-webkit-keyframes rotate { | ||
0% { | ||
-webkit-transform: rotate(0deg); | ||
transform: rotate(0deg); | ||
} | ||
25% { | ||
} | ||
50% { | ||
-webkit-transform: rotate(1440deg); | ||
transform: rotate(1440deg); | ||
} | ||
75% { | ||
} | ||
100% { | ||
-webkit-transform: rotate(0deg); | ||
transform: rotate(0deg); | ||
} | ||
#stage { | ||
font-size: 16px; | ||
margin-top: 20px; | ||
} | ||
@@ -122,14 +155,63 @@ </style> | ||
<div id="loading"> | ||
<div class="logo"> | ||
<svg width="144" height="144" viewBox="0 0 144 144" fill="none" xmlns="http://www.w3.org/2000/svg"><mask id="a" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="0" y="0" width="144" height="144"><circle cx="72" cy="72" r="72" fill="#fff"/></mask><g mask="url(#a)"><path d="M144 0H0v144h144V0Z" fill="#10255F"/><rect x="-67.999" y="-92" width="232" height="48" rx="24" transform="rotate(30 -68 -92)" fill="#4581B7"/><rect x="-22.718" y="-10.43" width="232" height="48" rx="24" transform="rotate(30 -22.718 -10.43)" fill="#5491C7"/><rect x="39.885" y="81.139" width="232" height="48" rx="24" transform="rotate(30 39.885 81.14)" fill="#4581B7"/></g></svg> | ||
<div class="wrapper"> | ||
<div class="logo"> | ||
<svg width="144" height="144" viewBox="0 0 144 144" fill="none" xmlns="http://www.w3.org/2000/svg"><mask id="a" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="0" y="0" width="144" height="144"><circle cx="72" cy="72" r="72" fill="#fff"/></mask><g mask="url(#a)"><path d="M144 0H0v144h144V0Z" fill="#10255F"/><rect x="-67.999" y="-92" width="232" height="48" rx="24" transform="rotate(30 -68 -92)" fill="#4581B7"/><rect x="-22.718" y="-10.43" width="232" height="48" rx="24" transform="rotate(30 -22.718 -10.43)" fill="#5491C7"/><rect x="39.885" y="81.139" width="232" height="48" rx="24" transform="rotate(30 39.885 81.14)" fill="#4581B7"/></g></svg> | ||
</div> | ||
<div id="stage">Loading...</div> | ||
</div> | ||
</div> | ||
${(_c = (_b = [...((_a = options.scripts) !== null && _a !== void 0 ? _a : []), ...scriptsToInject]) === null || _b === void 0 ? void 0 : _b.map((item) => handleAsset('script', item)).join('\n')) !== null && _c !== void 0 ? _c : ''} | ||
<script> | ||
${fs_1.default.readFileSync(require.resolve('@discoveryjs/json-ext/dist/json-ext.min.js'), 'utf8')} | ||
</script> | ||
${(_b = (_a = options.scripts) === null || _a === void 0 ? void 0 : _a.map((item) => handleAsset('script', item)).join('\n')) !== null && _b !== void 0 ? _b : ''} | ||
<script> | ||
const stage = document.querySelector('#stage'); | ||
function setStage(name, fn) { | ||
stage.textContent = \`\${name}...\`; | ||
requestAnimationFrame(() => { | ||
setTimeout(fn); | ||
}); | ||
} | ||
function _makeJsonExtAPI() { | ||
const jsonExtData = new Object(null); | ||
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='.split(''); | ||
const charIndex = chars.reduce(function(res, item, index){ | ||
res[item] = index; | ||
return res; | ||
}, {}); | ||
function decodeFromBase64(input) { | ||
input = input.replace(/[^a-zA-Z0-9\\+\\/]/g, ''); | ||
const output = []; | ||
let len = input.length; | ||
let i = 0; | ||
let chr1; | ||
let chr2; | ||
let chr3; | ||
let enc1; | ||
let enc2; | ||
let enc3; | ||
let enc4; | ||
// decode | ||
while (i < len) | ||
{ | ||
enc1 = charIndex[input.charAt(i++)]; | ||
enc2 = charIndex[input.charAt(i++)]; | ||
enc3 = charIndex[input.charAt(i++)]; | ||
enc4 = charIndex[input.charAt(i++)]; | ||
chr1 = (enc1 << 2) | (enc2 >> 4); | ||
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); | ||
chr3 = ((enc3 & 3) << 6) | enc4; | ||
output.push(chr1, chr2, chr3); | ||
} | ||
if (enc3 == null || enc3 == 64) output.pop(); | ||
if (enc4 == null || enc4 == 64) output.pop(); | ||
return output; | ||
} | ||
return { | ||
@@ -146,3 +228,15 @@ getData() { | ||
Object.entries(jsonExtData).map(([id, chunks]) => { | ||
return jsonExt.parseChunked(() => chunks).then((data) => ({ id, data })); | ||
if (${JSON.stringify((_d = options.dataCompression) !== null && _d !== void 0 ? _d : true)} === false) { | ||
return jsonExt.parseChunked(() => chunks).then((data) => ({ id, data })); | ||
} | ||
const inflator = new Pako.Inflate(); | ||
for(const chunk of chunks) { | ||
const decoded = decodeFromBase64(chunk); | ||
inflator.push(decoded); | ||
} | ||
const data = BinaryJSON.decode(inflator.result); | ||
return { id, data }; | ||
}) | ||
@@ -161,2 +255,3 @@ ); | ||
<script> | ||
setStage('Parsing', () => { | ||
for (const element of document.querySelectorAll('script')) { | ||
@@ -174,5 +269,8 @@ if(element.dataset.id) { | ||
.then(items => { | ||
initFunction(items); | ||
document.querySelector('#loading').remove(); | ||
setStage('Initialization', () => { | ||
initFunction(items); | ||
document.querySelector('#loading').remove(); | ||
}); | ||
}); | ||
}) | ||
</script> | ||
@@ -179,0 +277,0 @@ </body> |
@@ -15,2 +15,6 @@ /// <reference types="node" /> | ||
replacer?: TReplacer; | ||
} | { | ||
type: 'stream'; | ||
filename: string; | ||
stream: Readable; | ||
}; | ||
@@ -17,0 +21,0 @@ export declare function transform(options: { |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -9,4 +32,6 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
const path_1 = __importDefault(require("path")); | ||
const stream_1 = require("stream"); | ||
const pako_1 = __importDefault(require("pako")); | ||
const json_ext_1 = require("@discoveryjs/json-ext"); | ||
const _1 = __importDefault(require("./")); | ||
const _1 = __importStar(require("./")); | ||
function waitFinished(stream) { | ||
@@ -34,6 +59,28 @@ return new Promise((resolve, reject) => { | ||
} | ||
else { | ||
else if (fromItem.type === 'data') { | ||
stream = (0, json_ext_1.stringifyStream)(fromItem.data, fromItem.replacer); | ||
} | ||
htmlWriter.addChunkWriter(stream, id); | ||
else { | ||
stream = fromItem.stream; | ||
} | ||
if (options.writer.dataCompression === false) { | ||
htmlWriter.addChunkWriter(stream, id); | ||
} | ||
else { | ||
const htmlStats = await (0, json_ext_1.parseChunked)(stream); | ||
const binaryJSONArray = (0, _1.encodeBinaryJSON)(htmlStats); | ||
const binaryJSONCompressedArray = pako_1.default.deflate(binaryJSONArray); | ||
let readIndex = 0; | ||
const htmlStatsStream = new stream_1.Readable({ | ||
read(size) { | ||
const chunk = binaryJSONCompressedArray.subarray(readIndex, readIndex + size); | ||
readIndex += size; | ||
this.push(Buffer.from(chunk).toString('base64')); | ||
if (readIndex >= binaryJSONCompressedArray.length) { | ||
this.push(null); | ||
} | ||
}, | ||
}); | ||
htmlWriter.addChunkWriter(htmlStatsStream, id); | ||
} | ||
} | ||
@@ -40,0 +87,0 @@ htmlWriter.getStream().pipe(outputStream); |
{ | ||
"name": "@statoscope/report-writer", | ||
"version": "5.22.0", | ||
"version": "5.25.0-alpha.0", | ||
"description": "Statoscope report writer", | ||
@@ -21,3 +21,5 @@ "main": "./dist/index.js", | ||
"dependencies": { | ||
"@discoveryjs/json-ext": "^0.5.7" | ||
"@discoveryjs/json-ext": "^0.5.7", | ||
"@types/pako": "^2.0.0", | ||
"pako": "^2.0.4" | ||
}, | ||
@@ -27,3 +29,3 @@ "devDependencies": { | ||
}, | ||
"gitHead": "0d2e09d892c1bb6e019778e270079f99cb80d332" | ||
"gitHead": "e75d2467531bd7df1d82a13498a8a608e75ea567" | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
32589
11
908
3
1
5
1
+ Added@types/pako@^2.0.0
+ Addedpako@^2.0.4
+ Added@types/pako@2.0.3(transitive)
+ Addedpako@2.1.0(transitive)