datainout
Version:
Import and reports data
107 lines (105 loc) • 3.38 kB
JavaScript
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/reporters/SheetMeta.ts
var SheetMeta_exports = {};
__export(SheetMeta_exports, {
SheetMeta: () => SheetMeta
});
module.exports = __toCommonJS(SheetMeta_exports);
var SheetMeta = class {
constructor(opts) {
this.byJobIndex = true;
this.sheetMetas = {};
this.mapSheetByJobIndex = {};
this.currentSheetName = 0;
this.rowCount = 0;
this.sheetNames = [];
this.isCompleted = false;
this.jobCount = 0;
var _a;
for (let i = 0; i < opts.length; i++)
if (opts[i].jobs || opts[i].maxRow) this.addSheetMeta(opts[i].name, (_a = opts[i].jobs) != null ? _a : opts[i].maxRow);
}
// private addSheetMeta(name: string, jobIndexes: number[]): this;
// private addSheetMeta(name: string, rowCount: number): this;
addSheetMeta(name, data) {
if (typeof data === "number") {
this.byJobIndex = false;
this.sheetMetas[name] = {
isCompleted: false,
rowCount: 0,
maxRow: data
};
} else if (Array.isArray(data)) {
this.byJobIndex = true;
this.sheetMetas[name] = {
isCompleted: false,
rowCount: 0,
jobCount: data.length,
maxRow: 0
};
this.jobCount += data.length;
data.forEach((e) => {
this.mapSheetByJobIndex[e] = name;
});
}
this.sheetNames.push(name);
return this;
}
completeJob(index) {
const name = this.mapSheetByJobIndex[index];
if (this.sheetMetas[name].jobCount) {
this.sheetMetas[name].jobCount -= 1;
this.sheetMetas[name].isCompleted = this.sheetMetas[name].jobCount <= 0;
this.jobCount--;
this.isCompleted = this.jobCount <= 0;
}
}
get IsCompleted() {
return this.isCompleted;
}
get RowCount() {
return this.rowCount;
}
updateRowCount(isCompleted, rowCount) {
var _a;
const name = this.sheetNames[this.currentSheetName];
const sheetMeta = this.sheetMetas[name];
if (isCompleted) sheetMeta.isCompleted = isCompleted;
else if (!this.byJobIndex) {
this.rowCount += rowCount;
if (((_a = sheetMeta.maxRow) != null ? _a : 0) < sheetMeta.rowCount) {
this.currentSheetName++;
sheetMeta.isCompleted = true;
}
sheetMeta.rowCount += rowCount;
}
}
getSheetName(index) {
if (this.byJobIndex && index) return this.mapSheetByJobIndex[index];
return this.sheetNames[this.currentSheetName];
}
getSheetStatus(name) {
return this.sheetMetas[name].isCompleted;
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
SheetMeta
});