@mdgs/pivotjet 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +628 -3
- package/bin/pivotjet.mjs +122 -0
- package/dist/core.cjs +4926 -0
- package/dist/core.cjs.map +7 -0
- package/dist/index.cjs +7277 -0
- package/dist/index.cjs.map +7 -0
- package/dist/pivotjet.min.js +334 -0
- package/dist/pivotjet.min.js.map +7 -0
- package/docs/images/cell-formats.png +0 -0
- package/docs/images/chart.png +0 -0
- package/docs/images/configure-fields.png +0 -0
- package/docs/images/designer.png +0 -0
- package/docs/images/large-dataset.png +0 -0
- package/package.json +108 -4
- package/src/cellfmt.js +218 -0
- package/src/chart.js +595 -0
- package/src/core.d.ts +424 -0
- package/src/core.js +18 -0
- package/src/csv.js +198 -0
- package/src/dataset.js +404 -0
- package/src/designer.js +995 -0
- package/src/elements.js +50 -0
- package/src/engine.js +778 -0
- package/src/errors.js +2 -0
- package/src/export.js +775 -0
- package/src/expr.js +180 -0
- package/src/format.js +42 -0
- package/src/holistic.js +237 -0
- package/src/index.d.ts +155 -0
- package/src/index.js +6 -0
- package/src/layouts.js +105 -0
- package/src/node.d.ts +10 -0
- package/src/node.js +29 -0
- package/src/pdffont.js +361 -0
- package/src/remote.js +164 -0
- package/src/report-render.js +31 -0
- package/src/report.js +103 -0
- package/src/reportstore.js +135 -0
- package/src/server.d.ts +20 -0
- package/src/server.js +272 -0
- package/src/stream.js +285 -0
- package/src/styles.js +162 -0
- package/src/util.js +73 -0
- package/src/viewer.js +632 -0
package/src/core.d.ts
ADDED
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
// Type definitions for pivotjet (DOM-free core).
|
|
2
|
+
|
|
3
|
+
export type FieldType = 'auto' | 'string' | 'number' | 'date' | 'boolean';
|
|
4
|
+
export type FieldRole = 'auto' | 'dimension' | 'measure' | 'both' | 'skip';
|
|
5
|
+
|
|
6
|
+
export interface FieldDef {
|
|
7
|
+
name: string;
|
|
8
|
+
label?: string;
|
|
9
|
+
type?: FieldType;
|
|
10
|
+
/** auto: numbers become measures, everything else dimensions. 'both' keeps a dictionary AND numeric values. 'skip' ignores the column. */
|
|
11
|
+
role?: FieldRole;
|
|
12
|
+
/** 'single' stores a measure as Float32 (half the memory, ~7 digits). Default 'double'. */
|
|
13
|
+
precision?: 'single' | 'double';
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface FieldInfo {
|
|
17
|
+
name: string;
|
|
18
|
+
label: string;
|
|
19
|
+
type: Exclude<FieldType, 'auto'>;
|
|
20
|
+
role: Exclude<FieldRole, 'auto'>;
|
|
21
|
+
isDimension: boolean;
|
|
22
|
+
isMeasure: boolean;
|
|
23
|
+
/** true when a dimension exceeded `maxCardinality` and was disabled */
|
|
24
|
+
overflow: boolean;
|
|
25
|
+
cardinality: number | null;
|
|
26
|
+
/** present for calculated fields */
|
|
27
|
+
formula?: string;
|
|
28
|
+
precision?: 'single' | 'double';
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface DatasetOptions {
|
|
32
|
+
/** Max distinct values per dimension (default 2,000,000). */
|
|
33
|
+
maxCardinality?: number;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface CalculatedFieldDef {
|
|
37
|
+
name: string;
|
|
38
|
+
label?: string;
|
|
39
|
+
/** row-level formula over other fields, e.g. "[Revenue] / [Qty]" */
|
|
40
|
+
formula: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export class Dataset {
|
|
44
|
+
constructor(fields?: Array<string | FieldDef> | null, opts?: DatasetOptions);
|
|
45
|
+
static fromRows(rows: Record<string, any>[], fields?: Array<string | FieldDef> | null, opts?: DatasetOptions): Dataset;
|
|
46
|
+
static fromColumns(columns: Record<string, ArrayLike<any>>, fields?: Array<string | FieldDef> | null, opts?: DatasetOptions): Dataset;
|
|
47
|
+
readonly rowCount: number;
|
|
48
|
+
readonly fields: Array<FieldDef & { index: number }>;
|
|
49
|
+
readonly warnings: string[];
|
|
50
|
+
/** Append row objects. */
|
|
51
|
+
addRows(rows: Record<string, any>[]): this;
|
|
52
|
+
/** Append positional rows (values in field order). Fastest ingestion path. */
|
|
53
|
+
addRowArrays(rows: any[][]): this;
|
|
54
|
+
addRow(row: any[]): this;
|
|
55
|
+
addColumns(columns: Record<string, ArrayLike<any>>): this;
|
|
56
|
+
/** Stream batches from an (async) iterable of row-object arrays (or positional arrays). */
|
|
57
|
+
loadAsync(source: AsyncIterable<any[]> | Iterable<any[]>, opts?: { positional?: boolean; onProgress?: (p: { rows: number; done?: boolean }) => void; signal?: AbortSignal; sliceMs?: number }): Promise<this>;
|
|
58
|
+
/** Add a row-level calculated field (computed once, stored as a measure column). */
|
|
59
|
+
addCalculatedField(def: CalculatedFieldDef): this;
|
|
60
|
+
fieldInfo(): FieldInfo[];
|
|
61
|
+
hasField(name: string): boolean;
|
|
62
|
+
compute(spec: PivotSpec, opts?: ComputeOptions): Promise<PivotResult>;
|
|
63
|
+
drill(result: PivotResult, row: AxisNode, col: AxisNode, opts?: { limit?: number; signal?: AbortSignal }): Promise<DrillResult>;
|
|
64
|
+
distinct(name: string, opts?: { search?: string; limit?: number }): { total: number; items: Array<{ code: number; value: any; label: string }> };
|
|
65
|
+
memoryUsage(): number;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface CsvLoadOptions {
|
|
69
|
+
dataset?: Dataset;
|
|
70
|
+
delimiter?: string;
|
|
71
|
+
header?: boolean;
|
|
72
|
+
columns?: string[];
|
|
73
|
+
fields?: Array<FieldDef>;
|
|
74
|
+
sampleRows?: number;
|
|
75
|
+
maxCardinality?: number;
|
|
76
|
+
onProgress?: (p: { rows: number; bytes: number; done?: boolean }) => void;
|
|
77
|
+
signal?: AbortSignal;
|
|
78
|
+
}
|
|
79
|
+
/** Stream a CSV (string, Blob/File, fetch Response, ReadableStream or (async) iterable) into a Dataset. */
|
|
80
|
+
export function loadCSV(source: any, opts?: CsvLoadOptions): Promise<Dataset>;
|
|
81
|
+
|
|
82
|
+
export class CsvParser {
|
|
83
|
+
constructor(opts: { delimiter?: string; onRow: (row: string[]) => void });
|
|
84
|
+
write(chunk: string): void;
|
|
85
|
+
end(): void;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** distinct is exact; median is a sketch accurate to about 0.1%. */
|
|
89
|
+
export type Aggregate = 'sum' | 'count' | 'avg' | 'min' | 'max' | 'distinct' | 'median';
|
|
90
|
+
export type DateBucket = 'year' | 'quarter' | 'month' | 'day';
|
|
91
|
+
export type ShowAs = 'value' | 'pctRow' | 'pctCol' | 'pctGrand';
|
|
92
|
+
export type NumberFormat = 'number' | 'integer' | 'currency' | 'percent' | 'compact' | Intl.NumberFormatOptions & { preset?: string; prefix?: string; suffix?: string } | ((v: number) => string);
|
|
93
|
+
|
|
94
|
+
export interface DimSpec {
|
|
95
|
+
field: string;
|
|
96
|
+
/** group dates (UTC) */
|
|
97
|
+
bucket?: DateBucket;
|
|
98
|
+
sort?: 'asc' | 'desc' | 'natural';
|
|
99
|
+
label?: string;
|
|
100
|
+
}
|
|
101
|
+
export interface ValueSpec {
|
|
102
|
+
/** field name, or '*' / omitted for a row count */
|
|
103
|
+
field?: string;
|
|
104
|
+
agg?: Aggregate;
|
|
105
|
+
/** result-level formula over other values, e.g. "[Revenue] / [Orders]" or "sum(Revenue) / distinct(Customer)" */
|
|
106
|
+
calc?: string;
|
|
107
|
+
label?: string;
|
|
108
|
+
format?: NumberFormat;
|
|
109
|
+
showAs?: ShowAs;
|
|
110
|
+
}
|
|
111
|
+
export interface FilterSpec {
|
|
112
|
+
field: string;
|
|
113
|
+
include?: any[];
|
|
114
|
+
exclude?: any[];
|
|
115
|
+
}
|
|
116
|
+
export interface PivotOptions {
|
|
117
|
+
grandTotals?: boolean;
|
|
118
|
+
colSubtotals?: boolean;
|
|
119
|
+
/** true | false | number of levels | 'auto' */
|
|
120
|
+
expandRows?: boolean | number | 'auto';
|
|
121
|
+
expandCols?: boolean | number | 'auto';
|
|
122
|
+
maxCells?: number;
|
|
123
|
+
/** presentation used by the viewer/designer */
|
|
124
|
+
view?: 'table' | 'chart';
|
|
125
|
+
chart?: ChartOptions;
|
|
126
|
+
/** conditional / per-cell formatting; applies in the viewer, print, Excel and PDF */
|
|
127
|
+
cellRules?: CellRule[];
|
|
128
|
+
/** print + PDF defaults */
|
|
129
|
+
print?: PrintOptions;
|
|
130
|
+
}
|
|
131
|
+
export interface PrintOptions { font?: string; title?: string; subtitle?: string; footer?: string; pageSize?: 'a4' | 'letter' | 'a3' | 'legal'; orientation?: 'landscape' | 'portrait'; subtotals?: boolean; maxRows?: number }
|
|
132
|
+
export interface PivotSpec {
|
|
133
|
+
rows?: Array<string | DimSpec>;
|
|
134
|
+
cols?: Array<string | DimSpec>;
|
|
135
|
+
values?: Array<string | ValueSpec>;
|
|
136
|
+
filters?: FilterSpec[];
|
|
137
|
+
options?: PivotOptions;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export class AxisNode {
|
|
141
|
+
readonly id: number;
|
|
142
|
+
/** -1 for the grand-total root */
|
|
143
|
+
readonly level: number;
|
|
144
|
+
readonly parent: AxisNode | null;
|
|
145
|
+
children: AxisNode[];
|
|
146
|
+
readonly label: string;
|
|
147
|
+
readonly key: string;
|
|
148
|
+
readonly isLeaf: boolean;
|
|
149
|
+
path(): string[];
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export interface PivotStats {
|
|
153
|
+
rows: number;
|
|
154
|
+
matchedRows: number;
|
|
155
|
+
leafCells: number;
|
|
156
|
+
cells: number;
|
|
157
|
+
ms: number;
|
|
158
|
+
dense: boolean;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export class PivotResult {
|
|
162
|
+
readonly rowRoot: AxisNode;
|
|
163
|
+
readonly colRoot: AxisNode;
|
|
164
|
+
readonly rowDims: Required<DimSpec>[];
|
|
165
|
+
readonly colDims: Required<DimSpec>[];
|
|
166
|
+
readonly values: Array<Required<Pick<ValueSpec, 'field' | 'agg' | 'label' | 'showAs'>> & ValueSpec>;
|
|
167
|
+
readonly stats: PivotStats;
|
|
168
|
+
/** Value for a (row, column) node pair (use rowRoot/colRoot for totals); honours showAs. null when empty. */
|
|
169
|
+
get(row: AxisNode, col: AxisNode, valueIndex?: number): number | null;
|
|
170
|
+
/** Value ignoring showAs. */
|
|
171
|
+
base(row: AxisNode, col: AxisNode, valueIndex?: number): number | null;
|
|
172
|
+
has(row: AxisNode, col: AxisNode): boolean;
|
|
173
|
+
sortBy(axis: 'rows' | 'cols', otherNode: AxisNode, valueIndex: number, dir?: 'asc' | 'desc'): void;
|
|
174
|
+
resetSort(axis?: 'rows' | 'cols'): void;
|
|
175
|
+
leaves(axis: 'rows' | 'cols'): AxisNode[];
|
|
176
|
+
csvLines(opts?: { subtotals?: boolean; grandTotals?: boolean; delimiter?: string }): Generator<string>;
|
|
177
|
+
toCSV(opts?: { subtotals?: boolean; grandTotals?: boolean; delimiter?: string }): string;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export interface ComputeOptions {
|
|
181
|
+
signal?: AbortSignal;
|
|
182
|
+
/** called with 0..1 while scanning */
|
|
183
|
+
onProgress?: (p: number) => void;
|
|
184
|
+
/** guard against runaway results (default 2,000,000) */
|
|
185
|
+
maxCells?: number;
|
|
186
|
+
/** time slice before yielding to the event loop (default 24 ms) */
|
|
187
|
+
sliceMs?: number;
|
|
188
|
+
/** guard for distinct/median state (default 20,000,000 entries) */
|
|
189
|
+
maxHolisticEntries?: number;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export function computePivot(dataset: Dataset, spec: PivotSpec, opts?: ComputeOptions): Promise<PivotResult>;
|
|
193
|
+
export function drillRows(dataset: Dataset, result: PivotResult, row: AxisNode, col: AxisNode, opts?: { limit?: number; signal?: AbortSignal }): Promise<{ rows: Array<Record<string, any>>; total: number }>;
|
|
194
|
+
export function normalizeSpec(dataset: Dataset, spec: PivotSpec): any;
|
|
195
|
+
export function makeFormatter(fmt?: NumberFormat, locale?: string): (v: number | null) => string;
|
|
196
|
+
export function compareValues(a: any, b: any): number;
|
|
197
|
+
|
|
198
|
+
export class PivotError extends Error {}
|
|
199
|
+
export class PivotLimitError extends PivotError {}
|
|
200
|
+
export class AbortError extends Error {}
|
|
201
|
+
|
|
202
|
+
export const AGGREGATES: Aggregate[];
|
|
203
|
+
export const DATE_BUCKETS: DateBucket[];
|
|
204
|
+
export const CHUNK_SIZE: number;
|
|
205
|
+
|
|
206
|
+
// ---------------------------------------------------------------- formulas
|
|
207
|
+
export class FormulaError extends PivotError {}
|
|
208
|
+
export const AGG_FUNCS: string[];
|
|
209
|
+
export function compileFormula(src: string, opts?: { aggregates?: boolean }): { refs: string[]; evaluate: (get: (name: string) => number | null) => number | null };
|
|
210
|
+
|
|
211
|
+
// ---------------------------------------------------------------- data sources
|
|
212
|
+
/** Anything a viewer/designer can pivot: Dataset, StreamSource, RemoteDataset. */
|
|
213
|
+
export interface PivotSource {
|
|
214
|
+
readonly rowCount: number | null;
|
|
215
|
+
fieldInfo(): FieldInfo[];
|
|
216
|
+
hasField(name: string): boolean;
|
|
217
|
+
compute(spec: PivotSpec, opts?: ComputeOptions): Promise<PivotResult>;
|
|
218
|
+
distinct(name: string, opts?: { search?: string; limit?: number }): Promise<DistinctResult> | DistinctResult;
|
|
219
|
+
drill?(result: PivotResult, row: AxisNode, col: AxisNode, opts?: { limit?: number; signal?: AbortSignal }): Promise<DrillResult>;
|
|
220
|
+
memoryUsage(): number;
|
|
221
|
+
}
|
|
222
|
+
export interface DistinctResult { total: number; items: Array<{ code?: number; value: any; label: string }> }
|
|
223
|
+
export interface DrillResult { rows: Array<Record<string, any>>; total: number }
|
|
224
|
+
|
|
225
|
+
export function csvHead(source: any, opts?: { delimiter?: string; header?: boolean; columns?: string[]; sampleRows?: number }): Promise<{ columns: string[]; sample: string[][] }>;
|
|
226
|
+
export function csvBatches(source: any, opts?: { delimiter?: string; header?: boolean; batchSize?: number }): AsyncGenerator<string[][]>;
|
|
227
|
+
|
|
228
|
+
/** Bounded-memory pivot over a re-readable source (never holds the rows). No drill, distinct-count or median. */
|
|
229
|
+
export class StreamSource implements PivotSource {
|
|
230
|
+
/** open: () => any CSV source accepted by loadCSV (e.g. () => fetch(url), or a file stream thunk) */
|
|
231
|
+
static fromCSV(open: () => any, opts?: { delimiter?: string; fields?: FieldDef[]; header?: boolean; columns?: string[]; sampleRows?: number }): Promise<StreamSource>;
|
|
232
|
+
constructor(opts: { open: () => AsyncIterable<any[]>; fields: Array<string | FieldDef>; positional?: boolean; totalRows?: number | null });
|
|
233
|
+
readonly rowCount: number | null;
|
|
234
|
+
fieldInfo(): FieldInfo[];
|
|
235
|
+
hasField(name: string): boolean;
|
|
236
|
+
compute(spec: PivotSpec, opts?: ComputeOptions): Promise<PivotResult>;
|
|
237
|
+
distinct(name: string, opts?: { search?: string; limit?: number }): Promise<DistinctResult>;
|
|
238
|
+
/** always rejects: drill-through is not available while streaming */
|
|
239
|
+
drill(): Promise<never>;
|
|
240
|
+
memoryUsage(): number;
|
|
241
|
+
}
|
|
242
|
+
export function computePivotStream(source: any, fields: any, spec: PivotSpec, opts?: ComputeOptions): Promise<PivotResult>;
|
|
243
|
+
export function drillByPath(dataset: Dataset, spec: PivotSpec, rowPath: string[], colPath: string[], opts?: { limit?: number; signal?: AbortSignal }): Promise<DrillResult>;
|
|
244
|
+
|
|
245
|
+
export interface RemoteOptions {
|
|
246
|
+
token?: string;
|
|
247
|
+
headers?: Record<string, string>;
|
|
248
|
+
fetch?: typeof fetch;
|
|
249
|
+
}
|
|
250
|
+
/** Client for `createPivotServer` / the `pivotjet serve` CLI. */
|
|
251
|
+
export class RemoteDataset implements PivotSource {
|
|
252
|
+
static connect(baseUrl: string, name: string, opts?: RemoteOptions): Promise<RemoteDataset>;
|
|
253
|
+
readonly rowCount: number | null;
|
|
254
|
+
readonly supportsDrill: boolean;
|
|
255
|
+
readonly supportsLayouts: boolean;
|
|
256
|
+
readonly supportsReports: boolean;
|
|
257
|
+
/** store for saved reports on the server (throws when the server has reports disabled) */
|
|
258
|
+
reportStore(): RestReportStore;
|
|
259
|
+
fieldInfo(): FieldInfo[];
|
|
260
|
+
hasField(name: string): boolean;
|
|
261
|
+
compute(spec: PivotSpec, opts?: ComputeOptions): Promise<PivotResult>;
|
|
262
|
+
distinct(name: string, opts?: { search?: string; limit?: number }): Promise<DistinctResult>;
|
|
263
|
+
drill(result: PivotResult, row: AxisNode, col: AxisNode, opts?: { limit?: number; signal?: AbortSignal }): Promise<DrillResult>;
|
|
264
|
+
/** adapter that stores layouts on the server */
|
|
265
|
+
layoutAdapter(): LayoutAdapter;
|
|
266
|
+
memoryUsage(): number;
|
|
267
|
+
}
|
|
268
|
+
export function serializeResult(result: PivotResult): any;
|
|
269
|
+
export function deserializeResult(payload: any): PivotResult;
|
|
270
|
+
|
|
271
|
+
// ---------------------------------------------------------------- saved layouts
|
|
272
|
+
export interface LayoutState { layouts: Array<{ id: string; name: string; spec: PivotSpec; updated: number }>; defaultId: string | null }
|
|
273
|
+
export interface LayoutAdapter { read(): Promise<LayoutState>; write(state: LayoutState): Promise<void> }
|
|
274
|
+
export class MemoryAdapter implements LayoutAdapter { constructor(state?: LayoutState); read(): Promise<LayoutState>; write(s: LayoutState): Promise<void> }
|
|
275
|
+
export class LocalStorageAdapter implements LayoutAdapter { constructor(namespace?: string, storage?: Pick<Storage, 'getItem' | 'setItem'>); read(): Promise<LayoutState>; write(s: LayoutState): Promise<void> }
|
|
276
|
+
export class RestAdapter implements LayoutAdapter { constructor(url: string, opts?: { headers?: Record<string, string>; token?: string; fetch?: typeof fetch }); read(): Promise<LayoutState>; write(s: LayoutState): Promise<void> }
|
|
277
|
+
export interface LayoutSummary { id: string; name: string; updated: number; isDefault: boolean }
|
|
278
|
+
export class LayoutStore {
|
|
279
|
+
constructor(adapter?: LayoutAdapter);
|
|
280
|
+
readonly adapter: LayoutAdapter;
|
|
281
|
+
list(): Promise<LayoutSummary[]>;
|
|
282
|
+
load(id: string): Promise<{ id: string; name: string; spec: PivotSpec } | null>;
|
|
283
|
+
/** saving an existing name overwrites it */
|
|
284
|
+
save(name: string, spec: PivotSpec, opts?: { id?: string }): Promise<LayoutSummary>;
|
|
285
|
+
remove(id: string): Promise<void>;
|
|
286
|
+
setDefault(id: string | null): Promise<void>;
|
|
287
|
+
getDefault(): Promise<{ id: string; name: string; spec: PivotSpec } | null>;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// ---------------------------------------------------------------- export
|
|
291
|
+
export const XLSX_MAX_ROWS: number;
|
|
292
|
+
export const XLSX_MAX_COLS: number;
|
|
293
|
+
export type PdfFontFiles = { regular?: Uint8Array; bold?: Uint8Array; italic?: Uint8Array; boldItalic?: Uint8Array };
|
|
294
|
+
export interface ExportOptions { subtotals?: boolean; grandTotals?: boolean; date?: Date; /** per-cell rules (array or compiled with compileCellRules) */ rules?: CellRule[] | CellRuleEvaluator; locale?: string }
|
|
295
|
+
/** Real .xlsx workbook (one sheet). Throws a clear error beyond Excel's 1,048,576 x 16,384 limit. */
|
|
296
|
+
export function toXLSX(result: PivotResult, opts?: ExportOptions & { sheetName?: string }): Uint8Array;
|
|
297
|
+
/** Paginated PDF table; wide pivots split into column bands. Pass `locale` for deterministic number formatting. */
|
|
298
|
+
export function toPDF(result: PivotResult, opts?: ExportOptions & { pageSize?: 'a4' | 'letter' | 'a3' | 'legal'; orientation?: 'landscape' | 'portrait'; fontSize?: number; margin?: number; title?: string; subtitle?: string; maxRows?: number; locale?: string; /** default font family */ font?: string; /** embedded TrueType/OpenType fonts by family name */ fonts?: Record<string, PdfFontFiles>; footer?: string }): Uint8Array;
|
|
299
|
+
/** Browser only. */
|
|
300
|
+
export function downloadBlob(bytes: Uint8Array | string, filename: string, mime?: string): void;
|
|
301
|
+
|
|
302
|
+
// ---------------------------------------------------------------- charts
|
|
303
|
+
export type ChartType = 'column' | 'bar' | 'stackedColumn' | 'stackedBar' | 'line' | 'area' | 'stackedArea' | 'pie' | 'donut';
|
|
304
|
+
export const CHART_TYPES: ChartType[];
|
|
305
|
+
export interface ChartOptions {
|
|
306
|
+
type?: ChartType;
|
|
307
|
+
/** row level used for categories (default 0) */
|
|
308
|
+
rowLevel?: number | 'leaf';
|
|
309
|
+
/** column level used for series (default 0) */
|
|
310
|
+
colLevel?: number | 'leaf';
|
|
311
|
+
valueIndex?: number;
|
|
312
|
+
maxCategories?: number;
|
|
313
|
+
maxSeries?: number;
|
|
314
|
+
hidden?: number[];
|
|
315
|
+
seriesIndex?: number;
|
|
316
|
+
}
|
|
317
|
+
export interface ChartModel {
|
|
318
|
+
categories: Array<{ label: string; node: AxisNode }>;
|
|
319
|
+
series: Array<{ label: string; node: AxisNode; values: Array<number | null> }>;
|
|
320
|
+
[k: string]: any;
|
|
321
|
+
}
|
|
322
|
+
export function buildChartModel(result: PivotResult, opts?: ChartOptions): ChartModel;
|
|
323
|
+
export function renderSVG(model: ChartModel, opts?: { type?: ChartType; width?: number; height?: number; hidden?: number[]; inline?: boolean; theme?: 'light' | 'dark'; colors?: object; seriesIndex?: number }): string;
|
|
324
|
+
|
|
325
|
+
// ---------------------------------------------------------------- reports
|
|
326
|
+
export const REPORT_FORMAT: 'pivotjet-report';
|
|
327
|
+
export const REPORT_VERSION: number;
|
|
328
|
+
export interface PivotReport {
|
|
329
|
+
format: 'pivotjet-report';
|
|
330
|
+
version: number;
|
|
331
|
+
title: string;
|
|
332
|
+
description: string;
|
|
333
|
+
author: string;
|
|
334
|
+
created: string;
|
|
335
|
+
source: { name?: string; url?: string } | null;
|
|
336
|
+
locale: string | null;
|
|
337
|
+
spec: PivotSpec;
|
|
338
|
+
/** calculated (formula) columns that live on the dataset */
|
|
339
|
+
fields: Array<{ name: string; label: string; formula: string }>;
|
|
340
|
+
/** documentation of the source columns at save time */
|
|
341
|
+
schema: Array<{ name: string; label: string; type: string; role: string }> | null;
|
|
342
|
+
/** expansion, sort and sizing */
|
|
343
|
+
state: ViewState | null;
|
|
344
|
+
/** frozen numbers; null for a live-only report */
|
|
345
|
+
snapshot: { at: string; result: any } | null;
|
|
346
|
+
}
|
|
347
|
+
export interface ReportMeta { title?: string; description?: string; author?: string; source?: { name?: string; url?: string } }
|
|
348
|
+
export interface ViewState { expRows?: number | 'all'; expCols?: number | 'all'; rowOpen?: Array<[string, boolean]>; colOpen?: Array<[string, boolean]>; sort?: { key: string; kind: string; j: number; dir: 'asc' | 'desc' } | null; colWidth?: number; rowHeight?: number; rowHeaderWidth?: number; view?: 'table' | 'chart' }
|
|
349
|
+
/** Build a portable report. With a `result` the numbers are embedded so it renders offline (snapshot: false to omit). */
|
|
350
|
+
export function createReport(o: ReportMeta & { spec: PivotSpec; result?: PivotResult; snapshot?: boolean; fields?: Array<{ name: string; label?: string; formula: string }>; schema?: any[]; state?: ViewState; locale?: string }): PivotReport;
|
|
351
|
+
/** Validate a report (JSON text or object); throws PivotError otherwise. */
|
|
352
|
+
export function parseReport(input: string | object): PivotReport;
|
|
353
|
+
/** Self-contained .html that renders the snapshot offline. `bundle` = source of dist/pivotjet.min.js. */
|
|
354
|
+
export function reportToHTML(report: PivotReport, opts: { bundle: string; theme?: 'light' | 'dark' | 'auto' }): string;
|
|
355
|
+
|
|
356
|
+
// ---------------------------------------------------------------- per-cell formatting
|
|
357
|
+
export interface CellStyle { color?: string; background?: string; bold?: boolean; italic?: boolean; underline?: boolean; align?: 'left' | 'center' | 'right'; /** font family */ font?: string; /** size 5-96 */ size?: number }
|
|
358
|
+
export interface CellRule {
|
|
359
|
+
name?: string;
|
|
360
|
+
scope?: {
|
|
361
|
+
/** value index (0-based) or its label / field name; omit for every value */
|
|
362
|
+
value?: number | string;
|
|
363
|
+
kind?: 'any' | 'leaf' | 'sub' | 'grand' | 'total';
|
|
364
|
+
/** label path of a row / column node; matches it and everything below (exact: only that node). [] = grand total */
|
|
365
|
+
row?: string[];
|
|
366
|
+
col?: string[];
|
|
367
|
+
exact?: boolean;
|
|
368
|
+
};
|
|
369
|
+
when?: { op: '>' | '>=' | '<' | '<=' | '=' | '!=' | 'between' | 'outside' | 'empty' | 'notempty'; a?: number; b?: number };
|
|
370
|
+
format?: NumberFormat;
|
|
371
|
+
/** literal text shown instead of the number */
|
|
372
|
+
text?: string;
|
|
373
|
+
style?: CellStyle;
|
|
374
|
+
}
|
|
375
|
+
export interface CellMatch { fmt?: NumberFormat; fmtFn?: (v: number | null) => string; text?: string; style?: CellStyle }
|
|
376
|
+
export type CellRuleEvaluator = (row: AxisNode, col: AxisNode, valueIndex: number, value: number | null) => CellMatch | null;
|
|
377
|
+
/** Validate rules; throws PivotError("Cell rule #n: ...") */
|
|
378
|
+
export function cleanRules(rules: CellRule[] | null | undefined): CellRule[];
|
|
379
|
+
export function compileCellRules(rules: CellRule[], result: PivotResult, opts?: { locale?: string }): CellRuleEvaluator | null;
|
|
380
|
+
export function styleCss(style?: CellStyle): string;
|
|
381
|
+
export function parseColor(css: string): [number, number, number] | null;
|
|
382
|
+
export function excelNumFmt(fmt?: NumberFormat, showAs?: ShowAs): string | null;
|
|
383
|
+
/** The pivot as an HTML <table> (inline styles, rules applied). */
|
|
384
|
+
export function toHTMLTable(result: PivotResult, opts?: { rules?: CellRule[] | CellRuleEvaluator; locale?: string; subtotals?: boolean; grandTotals?: boolean; maxRows?: number }): string;
|
|
385
|
+
/** A complete printable HTML document. */
|
|
386
|
+
export function toPrintHTML(result: PivotResult, opts?: PrintOptions & { rules?: CellRule[] | CellRuleEvaluator; locale?: string; grandTotals?: boolean; chartSVG?: string; fontSize?: number }): string;
|
|
387
|
+
export function applyReportFields(dataset: any, report: PivotReport | string): string[];
|
|
388
|
+
|
|
389
|
+
export interface ReportSummary { id: string; title: string; description: string; author: string; created: number; updated: number; version: number; hasSnapshot: boolean }
|
|
390
|
+
export interface ReportVersionInfo { version: number; updated: number; title: string; hasSnapshot: boolean }
|
|
391
|
+
export interface ReportSaveResult { id: string; version: number; updated: number }
|
|
392
|
+
export interface ReportStoreApi {
|
|
393
|
+
list(): Promise<ReportSummary[]>;
|
|
394
|
+
load(id: string, opts?: { version?: number }): Promise<PivotReport | null>;
|
|
395
|
+
save(report: PivotReport, opts?: { id?: string; baseVersion?: number }): Promise<ReportSaveResult>;
|
|
396
|
+
versions(id: string): Promise<ReportVersionInfo[]>;
|
|
397
|
+
remove(id: string): Promise<void>;
|
|
398
|
+
}
|
|
399
|
+
export interface ReportAdapter { get(id: string): Promise<any | null>; put(id: string, doc: any): Promise<void>; del(id: string): Promise<void>; all(): Promise<any[]> }
|
|
400
|
+
export class ConflictError extends Error { status: 409; current?: number }
|
|
401
|
+
export class NotFoundError extends Error { status: 404 }
|
|
402
|
+
export const REPORT_ID: RegExp;
|
|
403
|
+
export class ReportStore implements ReportStoreApi {
|
|
404
|
+
constructor(adapter: ReportAdapter, opts?: { keepVersions?: number; validate?: (report: any) => void });
|
|
405
|
+
list(): Promise<ReportSummary[]>;
|
|
406
|
+
load(id: string, opts?: { version?: number }): Promise<PivotReport | null>;
|
|
407
|
+
save(report: PivotReport, opts?: { id?: string; baseVersion?: number }): Promise<ReportSaveResult>;
|
|
408
|
+
versions(id: string): Promise<ReportVersionInfo[]>;
|
|
409
|
+
remove(id: string): Promise<void>;
|
|
410
|
+
}
|
|
411
|
+
export class MemoryReportAdapter implements ReportAdapter { get(id: string): Promise<any | null>; put(id: string, doc: any): Promise<void>; del(id: string): Promise<void>; all(): Promise<any[]> }
|
|
412
|
+
export class LocalStorageReportAdapter implements ReportAdapter { constructor(namespace?: string, storage?: any); get(id: string): Promise<any | null>; put(id: string, doc: any): Promise<void>; del(id: string): Promise<void>; all(): Promise<any[]> }
|
|
413
|
+
export class LocalStorageReportStore extends ReportStore { constructor(namespace?: string, opts?: { storage?: any; keepVersions?: number }) }
|
|
414
|
+
export class RestReportStore implements ReportStoreApi {
|
|
415
|
+
constructor(url: string, opts?: { headers?: Record<string, string>; token?: string; fetch?: typeof fetch });
|
|
416
|
+
list(): Promise<ReportSummary[]>;
|
|
417
|
+
load(id: string, opts?: { version?: number }): Promise<PivotReport | null>;
|
|
418
|
+
save(report: PivotReport, opts?: { id?: string; baseVersion?: number }): Promise<ReportSaveResult>;
|
|
419
|
+
versions(id: string): Promise<ReportVersionInfo[]>;
|
|
420
|
+
remove(id: string): Promise<void>;
|
|
421
|
+
/** server-rendered export, sent with the Authorization header */
|
|
422
|
+
exportBytes(id: string, format?: 'pdf' | 'xlsx' | 'html' | 'json', opts?: { live?: boolean }): Promise<Uint8Array>;
|
|
423
|
+
shareUrl(id: string): string;
|
|
424
|
+
}
|
package/src/core.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// DOM-free entry: safe for Node, workers, SSR.
|
|
2
|
+
export { Dataset, compareValues, CHUNK_SIZE } from './dataset.js';
|
|
3
|
+
export { loadCSV, CsvParser } from './csv.js';
|
|
4
|
+
export { computePivot, drillRows, normalizeSpec, PivotResult, AxisNode, PivotError, PivotLimitError, AGGREGATES, DATE_BUCKETS } from './engine.js';
|
|
5
|
+
export { makeFormatter } from './format.js';
|
|
6
|
+
export { AbortError } from './util.js';
|
|
7
|
+
export { compileFormula, FormulaError, AGG_FUNCS } from './expr.js';
|
|
8
|
+
export { computePivotStream, StreamSource } from './stream.js';
|
|
9
|
+
export { csvBatches, csvHead } from './csv.js';
|
|
10
|
+
export { drillByPath } from './engine.js';
|
|
11
|
+
export { RemoteDataset, serializeResult, deserializeResult } from './remote.js';
|
|
12
|
+
export { LayoutStore, MemoryAdapter, LocalStorageAdapter, RestAdapter } from './layouts.js';
|
|
13
|
+
export { toXLSX, toPDF, downloadBlob } from './export.js';
|
|
14
|
+
export { buildChartModel, renderSVG, CHART_TYPES } from './chart.js';
|
|
15
|
+
export { ReportStore, MemoryReportAdapter, LocalStorageReportAdapter, LocalStorageReportStore, RestReportStore, ConflictError, NotFoundError } from './reportstore.js';
|
|
16
|
+
export { createReport, parseReport, reportToHTML, applyReportFields, REPORT_FORMAT, REPORT_VERSION } from './report.js';
|
|
17
|
+
export { cleanRules, compileCellRules, styleCss, parseColor, cssFamily } from './cellfmt.js';
|
|
18
|
+
export { toHTMLTable, toPrintHTML, excelNumFmt } from './export.js';
|
package/src/csv.js
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
// Streaming CSV parser + Dataset loader. Works with strings, Blob/File, fetch Response,
|
|
2
|
+
// WHATWG ReadableStream, and Node streams / any (async) iterable of string|Uint8Array.
|
|
3
|
+
|
|
4
|
+
import { Dataset, ISO_DATE, NUM } from './dataset.js';
|
|
5
|
+
import { Slicer } from './util.js';
|
|
6
|
+
|
|
7
|
+
export class CsvParser {
|
|
8
|
+
constructor({ delimiter = ',', onRow }) {
|
|
9
|
+
this.d = delimiter.charCodeAt(0);
|
|
10
|
+
this.onRow = onRow;
|
|
11
|
+
this.buf = '';
|
|
12
|
+
this.row = [];
|
|
13
|
+
this.inQ = false;
|
|
14
|
+
this.fs = true; // at field start
|
|
15
|
+
this.carry = '';
|
|
16
|
+
}
|
|
17
|
+
write(chunk) { this._parse(this.carry + chunk, false); }
|
|
18
|
+
end() {
|
|
19
|
+
this._parse(this.carry, true);
|
|
20
|
+
this.carry = '';
|
|
21
|
+
if (this.buf !== '' || this.row.length || this.inQ) { this._endField(); this._endRow(); }
|
|
22
|
+
}
|
|
23
|
+
_endField() { this.row.push(this.buf); this.buf = ''; }
|
|
24
|
+
_endRow() {
|
|
25
|
+
const r = this.row;
|
|
26
|
+
this.row = [];
|
|
27
|
+
if (r.length === 1 && r[0] === '') return; // blank line
|
|
28
|
+
this.onRow(r);
|
|
29
|
+
}
|
|
30
|
+
_parse(s, final) {
|
|
31
|
+
this.carry = '';
|
|
32
|
+
const n = s.length, D = this.d;
|
|
33
|
+
let i = 0;
|
|
34
|
+
while (i < n) {
|
|
35
|
+
if (this.inQ) {
|
|
36
|
+
const q = s.indexOf('"', i);
|
|
37
|
+
if (q < 0) { this.buf += s.slice(i); i = n; break; }
|
|
38
|
+
this.buf += s.slice(i, q);
|
|
39
|
+
if (q === n - 1 && !final) { this.carry = '"'; i = n; break; }
|
|
40
|
+
if (s.charCodeAt(q + 1) === 34) { this.buf += '"'; i = q + 2; } else { this.inQ = false; i = q + 1; }
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (this.fs && s.charCodeAt(i) === 34) { this.inQ = true; this.fs = false; i++; continue; }
|
|
44
|
+
let j = i;
|
|
45
|
+
for (; j < n; j++) {
|
|
46
|
+
const c = s.charCodeAt(j);
|
|
47
|
+
if (c === D || c === 10 || c === 13) break;
|
|
48
|
+
}
|
|
49
|
+
if (j > i) { this.buf += s.slice(i, j); this.fs = false; }
|
|
50
|
+
i = j;
|
|
51
|
+
if (i >= n) break;
|
|
52
|
+
const c = s.charCodeAt(i);
|
|
53
|
+
if (c === 13 && i === n - 1 && !final) { this.carry = '\r'; i = n; break; }
|
|
54
|
+
if (c === D) { this._endField(); this.fs = true; i++; }
|
|
55
|
+
else {
|
|
56
|
+
this._endField(); this._endRow(); this.fs = true;
|
|
57
|
+
i += c === 13 && s.charCodeAt(i + 1) === 10 ? 2 : 1;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export async function* chunksOf(source) {
|
|
64
|
+
if (typeof source === 'string') { yield source; return; }
|
|
65
|
+
if (source && typeof source.stream === 'function') source = source.stream(); // Blob / File
|
|
66
|
+
else if (source && source.body && typeof source.arrayBuffer === 'function') source = source.body; // Response
|
|
67
|
+
if (source && typeof source.getReader === 'function') {
|
|
68
|
+
const reader = source.getReader();
|
|
69
|
+
try { for (;;) { const { done, value } = await reader.read(); if (done) return; yield value; } }
|
|
70
|
+
finally { reader.releaseLock && reader.releaseLock(); }
|
|
71
|
+
} else {
|
|
72
|
+
for await (const c of source) yield c;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function inferFields(header, sample, overrides) {
|
|
77
|
+
return header.map((name, ci) => {
|
|
78
|
+
const o = overrides[name] || {};
|
|
79
|
+
let type = o.type;
|
|
80
|
+
if (!type) {
|
|
81
|
+
let allNum = true, allDate = true, seen = 0;
|
|
82
|
+
for (const r of sample) {
|
|
83
|
+
const v = r[ci];
|
|
84
|
+
if (v === undefined || v === '') continue;
|
|
85
|
+
seen++;
|
|
86
|
+
if (allNum && !NUM.test(v)) allNum = false;
|
|
87
|
+
if (allDate && !ISO_DATE.test(v)) allDate = false;
|
|
88
|
+
if (!allNum && !allDate) break;
|
|
89
|
+
}
|
|
90
|
+
type = seen === 0 ? 'string' : allNum ? 'number' : allDate ? 'date' : 'string';
|
|
91
|
+
}
|
|
92
|
+
return { name, type, role: o.role, label: o.label };
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Stream a CSV into a Dataset.
|
|
98
|
+
* @param {*} source string | Blob | Response | ReadableStream | AsyncIterable
|
|
99
|
+
* @param {{dataset?:Dataset, delimiter?:string, header?:boolean, columns?:string[],
|
|
100
|
+
* fields?:Array<{name:string,type?:string,role?:string}>, sampleRows?:number,
|
|
101
|
+
* onProgress?:Function, signal?:AbortSignal, maxCardinality?:number}} [opts]
|
|
102
|
+
*/
|
|
103
|
+
export async function loadCSV(source, opts = {}) {
|
|
104
|
+
const { delimiter = ',', header = true, sampleRows = 2000, onProgress, signal } = opts;
|
|
105
|
+
const overrides = Object.fromEntries((opts.fields || []).map((f) => [f.name, f]));
|
|
106
|
+
const slicer = new Slicer({ signal, sliceMs: opts.sliceMs, onProgress: onProgress && (() => onProgress({ rows: ds ? ds.rowCount : 0, bytes })) });
|
|
107
|
+
let ds = opts.dataset || null;
|
|
108
|
+
let names = header ? null : opts.columns || null;
|
|
109
|
+
let pending = [];
|
|
110
|
+
let bytes = 0;
|
|
111
|
+
const sample = [];
|
|
112
|
+
|
|
113
|
+
const ensure = () => {
|
|
114
|
+
if (ds && ds.fields.length) return;
|
|
115
|
+
ds = ds || new Dataset(null, { maxCardinality: opts.maxCardinality });
|
|
116
|
+
ds._defineFields(inferFields(names, sample, overrides));
|
|
117
|
+
};
|
|
118
|
+
const flush = () => {
|
|
119
|
+
if (!pending.length) return;
|
|
120
|
+
ensure();
|
|
121
|
+
ds.addRowArrays(pending);
|
|
122
|
+
pending = [];
|
|
123
|
+
};
|
|
124
|
+
const parser = new CsvParser({
|
|
125
|
+
delimiter,
|
|
126
|
+
onRow(r) {
|
|
127
|
+
if (!names) { names = r.map((x, i) => (x || `Column ${i + 1}`).trim()); return; }
|
|
128
|
+
if (!ds || !ds.fields.length) {
|
|
129
|
+
sample.push(r);
|
|
130
|
+
pending.push(r);
|
|
131
|
+
if (sample.length >= sampleRows) flush();
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
pending.push(r);
|
|
135
|
+
if (pending.length >= 20000) flush();
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
const decoder = typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8') : null;
|
|
140
|
+
let first = true;
|
|
141
|
+
for await (const chunk of chunksOf(source)) {
|
|
142
|
+
let text;
|
|
143
|
+
if (typeof chunk === 'string') text = chunk;
|
|
144
|
+
else { bytes += chunk.byteLength; text = decoder ? decoder.decode(chunk, { stream: true }) : Buffer.from(chunk).toString('utf8'); }
|
|
145
|
+
if (first) { if (text.charCodeAt(0) === 0xfeff) text = text.slice(1); first = false; }
|
|
146
|
+
parser.write(text);
|
|
147
|
+
flush && pending.length >= 20000 && flush();
|
|
148
|
+
await slicer.tick();
|
|
149
|
+
}
|
|
150
|
+
parser.end();
|
|
151
|
+
if (!names) throw new Error('CSV is empty');
|
|
152
|
+
flush();
|
|
153
|
+
ensure();
|
|
154
|
+
if (onProgress) onProgress({ rows: ds.rowCount, bytes, done: true });
|
|
155
|
+
return ds;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function makeDecoder() {
|
|
159
|
+
const decoder = typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8') : null;
|
|
160
|
+
let first = true;
|
|
161
|
+
return (chunk) => {
|
|
162
|
+
let text;
|
|
163
|
+
if (typeof chunk === 'string') text = chunk;
|
|
164
|
+
else text = decoder ? decoder.decode(chunk, { stream: true }) : Buffer.from(chunk).toString('utf8');
|
|
165
|
+
if (first) { if (text.charCodeAt(0) === 0xfeff) text = text.slice(1); first = false; }
|
|
166
|
+
return text;
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** Read the header and a sample of rows, then stop (closes the underlying stream). */
|
|
171
|
+
export async function csvHead(source, { delimiter = ',', header = true, columns = null, sampleRows = 2000 } = {}) {
|
|
172
|
+
const rows = [];
|
|
173
|
+
const parser = new CsvParser({ delimiter, onRow: (r) => rows.push(r) });
|
|
174
|
+
const dec = makeDecoder();
|
|
175
|
+
const need = (header ? 1 : 0) + sampleRows;
|
|
176
|
+
for await (const chunk of chunksOf(source)) {
|
|
177
|
+
parser.write(dec(chunk));
|
|
178
|
+
if (rows.length >= need) break;
|
|
179
|
+
}
|
|
180
|
+
if (rows.length < need) parser.end();
|
|
181
|
+
const names = header ? (rows[0] || []).map((x, i) => (x || `Column ${i + 1}`).trim()) : columns;
|
|
182
|
+
if (!names) throw new Error('CSV is empty');
|
|
183
|
+
return { names, sample: rows.slice(header ? 1 : 0, need) };
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** Lazily yield batches of positional string rows (header skipped). Constant memory. */
|
|
187
|
+
export async function* csvBatches(source, { delimiter = ',', header = true, batchSize = 20000 } = {}) {
|
|
188
|
+
let pending = [];
|
|
189
|
+
let skip = header;
|
|
190
|
+
const parser = new CsvParser({ delimiter, onRow: (r) => { if (skip) { skip = false; return; } pending.push(r); } });
|
|
191
|
+
const dec = makeDecoder();
|
|
192
|
+
for await (const chunk of chunksOf(source)) {
|
|
193
|
+
parser.write(dec(chunk));
|
|
194
|
+
while (pending.length >= batchSize) { const out = pending; pending = []; yield out; }
|
|
195
|
+
}
|
|
196
|
+
parser.end();
|
|
197
|
+
if (pending.length) yield pending;
|
|
198
|
+
}
|