@rokkit/data 1.0.0-next.148 → 1.0.0-next.150

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.
Files changed (37) hide show
  1. package/dist/benchmark/fixtures.d.ts +33 -0
  2. package/dist/benchmark/index.d.ts +2 -0
  3. package/dist/benchmark/runner.d.ts +10 -0
  4. package/dist/{constants.d.ts → src/constants.d.ts} +6 -7
  5. package/dist/{dataset.d.ts → src/dataset.d.ts} +33 -15
  6. package/dist/src/dataset.svelte.d.ts +79 -0
  7. package/dist/{index.d.ts → src/index.d.ts} +1 -1
  8. package/dist/{infer.d.ts → src/infer.d.ts} +39 -0
  9. package/dist/{model.d.ts → src/model.d.ts} +1 -1
  10. package/dist/src/pipeline.d.ts +8 -0
  11. package/dist/{rollup.d.ts → src/rollup.d.ts} +2 -12
  12. package/package.json +1 -1
  13. package/src/constants.js +9 -4
  14. package/src/dataset.js +148 -119
  15. package/src/dataset.svelte.js +181 -0
  16. package/src/formatter.js +1 -1
  17. package/src/index.js +9 -1
  18. package/src/infer.js +103 -2
  19. package/src/join.js +11 -6
  20. package/src/model.js +3 -3
  21. package/src/pipeline.js +97 -0
  22. package/src/renamer.js +8 -1
  23. package/src/rollup.js +59 -62
  24. package/src/view.js +1 -2
  25. /package/dist/{aggregators.d.ts → src/aggregators.d.ts} +0 -0
  26. /package/dist/{convert.d.ts → src/convert.d.ts} +0 -0
  27. /package/dist/{filter.d.ts → src/filter.d.ts} +0 -0
  28. /package/dist/{formatter.d.ts → src/formatter.d.ts} +0 -0
  29. /package/dist/{hierarchy.d.ts → src/hierarchy.d.ts} +0 -0
  30. /package/dist/{join.d.ts → src/join.d.ts} +0 -0
  31. /package/dist/{list.d.ts → src/list.d.ts} +0 -0
  32. /package/dist/{metadata.d.ts → src/metadata.d.ts} +0 -0
  33. /package/dist/{parser.d.ts → src/parser.d.ts} +0 -0
  34. /package/dist/{renamer.d.ts → src/renamer.d.ts} +0 -0
  35. /package/dist/{types.d.ts → src/types.d.ts} +0 -0
  36. /package/dist/{utils.d.ts → src/utils.d.ts} +0 -0
  37. /package/dist/{view.d.ts → src/view.d.ts} +0 -0
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Generate sales rows: { region, product, year, revenue, units, status }
3
+ */
4
+ export function generateSalesData(n: any): {
5
+ region: string;
6
+ product: string;
7
+ year: number;
8
+ revenue: number;
9
+ units: number;
10
+ status: string;
11
+ }[];
12
+ /**
13
+ * Generate orders/customers pair for join benchmarks.
14
+ */
15
+ export function generateJoinData(n: any): {
16
+ customers: {
17
+ id: number;
18
+ name: string;
19
+ tier: string;
20
+ }[];
21
+ orders: {
22
+ orderId: number;
23
+ customerId: number;
24
+ amount: number;
25
+ year: number;
26
+ }[];
27
+ };
28
+ export function generateAlignData(n: any): {
29
+ revenue: number;
30
+ region: string;
31
+ product: string;
32
+ year: number;
33
+ }[];
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env bun
2
+ export {};
@@ -0,0 +1,10 @@
1
+ export function runBenchmarks(phase?: string): {
2
+ phase: string;
3
+ timestamp: string;
4
+ environment: {
5
+ runtime: string;
6
+ platform: NodeJS.Platform;
7
+ arch: NodeJS.Architecture;
8
+ };
9
+ results: never[];
10
+ };
@@ -1,4 +1,4 @@
1
- export const pickAllowedConfig: <U extends Partial<Record<"children" | "actual_flag", any>>>(obj: "children" | "actual_flag" extends keyof U ? U : never) => "children" | "actual_flag" extends keyof U ? Pick<U, keyof U & ("children" | "actual_flag")> : never;
1
+ export function pickAllowedConfig(obj: any): {};
2
2
  /** @type {import('./types').DataFrameConfig */
3
3
  export const defaultConfig: import("./types").DataFrameConfig;
4
4
  export namespace defaultPathOptions {
@@ -36,11 +36,10 @@ export const filterOperations: {
36
36
  '!~': (value: any, pattern: any) => boolean;
37
37
  };
38
38
  export namespace typeConverters {
39
- export function string(value: any): string;
40
- export function number(value: any): number;
41
- export function boolean(value: any): boolean;
42
- export function date(value: any): Date;
43
- export { identity as mixed };
39
+ function string(value: any): string;
40
+ function number(value: any): number;
41
+ function boolean(value: any): boolean;
42
+ function date(value: any): Date;
43
+ function mixed(x: any): any;
44
44
  }
45
45
  export function includeAll(): boolean;
46
- import { identity } from 'ramda';
@@ -1,12 +1,13 @@
1
1
  /**
2
- * Returns the default aggregator which rolls up the columns other than the group_by columns into a single object.
3
- *
4
- * @param {import('./types').Metadata} metadata - The metadata for the columns to be aggregated.
5
- * @param {Object} config - The configuration used to build the aggregator.
6
- *
7
- * @returns {Object} An object containing the default aggregator for the specified metadata and configuration.
2
+ * Returns the default aggregator which rolls up non-group_by columns into a children array.
8
3
  */
9
- export function defaultAggregator(config: Object): Object;
4
+ export function defaultAggregator(config: any): {
5
+ mapper: (row: any) => {};
6
+ reducers: {
7
+ field: any;
8
+ formula: (x: any) => any;
9
+ }[];
10
+ };
10
11
  export function dataset(data: any, options?: {}): DataSet;
11
12
  export class DataSet {
12
13
  constructor(data: any);
@@ -15,19 +16,36 @@ export class DataSet {
15
16
  set config(props: any);
16
17
  override(props: any): this;
17
18
  where(condition: any): this;
18
- groupBy(...fields: any[]): this;
19
- alignBy(...fields: any[]): this;
20
- usingTemplate(template: any): this;
21
- summarize(from: any, fields: any): this;
19
+ apply(callback: any): this;
20
+ sortBy(...fields: any[]): this;
22
21
  rename(how: any): this;
23
22
  drop(...fields: any[]): DataSet;
24
- sortBy(...fields: any[]): this;
23
+ fillNA(value: any): this;
25
24
  remove(): this;
26
25
  update(value: any): this;
27
- fillNA(value: any): this;
28
- apply(callback: any): this;
26
+ groupBy(...fields: any[]): this;
27
+ alignBy(...fields: any[]): this;
28
+ usingTemplate(template: any): this;
29
+ summarize(from: any, fields: any): this;
29
30
  rollup(): DataSet;
30
- select(...cols: any[]): any[];
31
+ select(...cols: any[]): any;
32
+ /**
33
+ * Derive column definitions from the current data.
34
+ *
35
+ * Returns `{ name, type, scale, sortable, filterable, fields, formatter }` for each
36
+ * column, plus any user-supplied properties from `options.enhancements`.
37
+ *
38
+ * @param {Object} [options]
39
+ * @param {Array<Object>} [options.enhancements=[]] - Per-column overrides keyed by name.
40
+ * @param {string} [options.language='en-US'] - Locale for formatters.
41
+ * @param {string} [options.scanMode='fast'] - 'fast' or 'deep'.
42
+ * @returns {Array<Object>}
43
+ */
44
+ columnDefs(options?: {
45
+ enhancements?: Object[] | undefined;
46
+ language?: string | undefined;
47
+ scanMode?: string | undefined;
48
+ }): Array<Object>;
31
49
  union(other: any): DataSet;
32
50
  minus(other: any): DataSet;
33
51
  intersect(other: any): DataSet;
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Factory function for `ReactiveDataSet`.
3
+ *
4
+ * @param {any[]} [data=[]] - Initial source rows.
5
+ * @returns {ReactiveDataSet}
6
+ */
7
+ export function reactiveDataset(data?: any[]): ReactiveDataSet;
8
+ export class ReactiveDataSet {
9
+ /**
10
+ * @param {any[]} data - Initial source rows.
11
+ */
12
+ constructor(data?: any[]);
13
+ /**
14
+ * Reactive computed result of filter + transforms + sort.
15
+ * Bind to this in templates instead of calling `.select()`.
16
+ */
17
+ get rows(): any;
18
+ /**
19
+ * Reactive derived column definitions: name, type, scale (discrete|continuous),
20
+ * sortable, filterable, fields, formatter — merged with any `withColumns` overrides.
21
+ *
22
+ * Re-computes when source data or column enhancements change.
23
+ * Bind to this in templates for Table / TreeTable column specs.
24
+ */
25
+ get columns(): Object[];
26
+ /**
27
+ * Set the filter predicate. Replaces any previous filter.
28
+ * @param {Function|null} fn
29
+ */
30
+ where(fn: Function | null): this;
31
+ /**
32
+ * Append a row transform. Each call to `apply` adds a new stage.
33
+ * @param {Function} fn
34
+ */
35
+ apply(fn: Function): this;
36
+ /**
37
+ * Set sort fields. Replaces any previous sort.
38
+ * @param {...string} fields
39
+ */
40
+ sortBy(...fields: string[]): this;
41
+ /**
42
+ * Set per-column enhancements / overrides for the reactive `columns` property.
43
+ *
44
+ * Each entry is matched by `name` and merged into the auto-derived column def.
45
+ * Unknown names are appended as synthetic columns (useful for action columns).
46
+ *
47
+ * @param {Array<Object>} enhancements - e.g. [{ name: 'revenue', label: 'Revenue ($)', scale: 'continuous' }]
48
+ * @param {Object} [options] - Options forwarded to deriveColumnDefs (language, scanMode).
49
+ */
50
+ withColumns(enhancements: Array<Object>, options?: Object): this;
51
+ /** Clear the current filter. */
52
+ clearFilter(): this;
53
+ /** Clear all transforms. */
54
+ clearTransforms(): this;
55
+ /**
56
+ * Replace the entire source dataset.
57
+ * @param {any[]} rows
58
+ */
59
+ setData(rows: any[]): this;
60
+ /**
61
+ * Append a single row to the source.
62
+ * @param {any} row
63
+ */
64
+ push(row: any): this;
65
+ /**
66
+ * Remove rows matching the predicate from the source.
67
+ * @param {Function} predicate
68
+ */
69
+ remove(predicate: Function): this;
70
+ /**
71
+ * Update rows matching the predicate with patch (object or function).
72
+ * @param {Function} predicate
73
+ * @param {Object|Function} patch
74
+ */
75
+ update(predicate: Function, patch: Object | Function): this;
76
+ /** Return a plain snapshot of the current reactive result (non-reactive copy). */
77
+ snapshot(): any[];
78
+ #private;
79
+ }
@@ -6,5 +6,5 @@ export { dataset } from "./dataset";
6
6
  export { dataview } from "./view";
7
7
  export { parseFilters } from "./parser";
8
8
  export { innerJoin, leftJoin, rightJoin, fullJoin, crossJoin, antiJoin, semiJoin } from "./join";
9
- export { deriveColumns, deriveMetadata, deriveSortableColumn } from "./infer";
9
+ export { deriveColumns, deriveMetadata, deriveSortableColumn, inferScale, addScales, deriveColumnDefs, mergeColumnEnhancements } from "./infer";
10
10
  export { filterData, filterObjectArray } from "./filter";
@@ -78,3 +78,42 @@ export function deriveActions(columns: Array<import("./types").ColumnMetadata>,
78
78
  * @returns {Array<import('./types').ColumnMetadata>} - The derived column metadata.
79
79
  */
80
80
  export function deriveMetadata(dataArray: any, options?: Object): Array<import("./types").ColumnMetadata>;
81
+ export function inferScale(values: any): any;
82
+ /**
83
+ * Adds a `scale` property to each column definition.
84
+ *
85
+ * @param {Array<Object>} columns - Column definitions (from deriveColumns / deriveMetadata).
86
+ * @param {any[]} data - Source rows.
87
+ * @returns {Array<Object>} Column definitions with `scale` added.
88
+ */
89
+ export function addScales(columns: Array<Object>, data: any[]): Array<Object>;
90
+ /**
91
+ * Merges user-provided enhancements into auto-derived column definitions.
92
+ * Enhancements are matched by `name` and merged (user values win).
93
+ * Enhancements for unknown column names are appended as synthetic columns.
94
+ *
95
+ * @param {Array<Object>} derived - Auto-derived column definitions.
96
+ * @param {Array<Object>} enhancements - User-provided overrides/additions.
97
+ * @returns {Array<Object>} Merged column definitions.
98
+ */
99
+ export function mergeColumnEnhancements(derived: Array<Object>, enhancements: Array<Object>): Array<Object>;
100
+ /**
101
+ * Full column definition pipeline: derive → format → scale → merge enhancements.
102
+ *
103
+ * Produces column descriptors suitable for use in Table, TreeTable, and chart
104
+ * components. Each column gets: name, type, scale, sortable, filterable, fields,
105
+ * formatter — plus any user-supplied properties from `enhancements`.
106
+ *
107
+ * @param {any[]} data - Source rows.
108
+ * @param {Object} [options] - Options forwarded to deriveColumns / addFormatters.
109
+ * @param {Array<Object>} [options.enhancements=[]] - Per-column overrides keyed by name.
110
+ * Use to override scale, add a label, attach a custom formatter, etc.
111
+ * @param {string} [options.language='en-US'] - Locale for formatters.
112
+ * @param {string} [options.scanMode='fast'] - 'fast' (first row) or 'deep' (all rows).
113
+ * @returns {Array<Object>} Column definitions with scale and formatters.
114
+ */
115
+ export function deriveColumnDefs(data: any[], options?: {
116
+ enhancements?: Object[] | undefined;
117
+ language?: string | undefined;
118
+ scanMode?: string | undefined;
119
+ }): Array<Object>;
@@ -9,7 +9,7 @@ export function model(): {
9
9
  * Renames the reference names using a renamer
10
10
  * @param {Function} rename - the renamer function
11
11
  */
12
- renameUsing: (rename?: Function) => /*elided*/ any;
12
+ renameUsing: (rename: Function) => /*elided*/ any;
13
13
  /**
14
14
  * Analyzes the input data and derives a model from it
15
15
  *
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Sort an array in-place by one or more field specs.
3
+ * @param {any[]} data - Array to sort (mutated in place).
4
+ * @param {...string|Object|Array} fields - Sort field specs (same as DataSet.sortBy).
5
+ * @returns {any[]}
6
+ */
7
+ export function sortDataByFields(data: any[], ...fields: (string | Object | any[])[]): any[];
8
+ export function executeFused(data: any, ops: any): any;
@@ -14,7 +14,7 @@ export function initialValues(summaries: any[]): Object;
14
14
  */
15
15
  export function addToSummaries(group: Object, row: Object, summaries: any[]): void;
16
16
  /**
17
- * Groups data by specified keys.
17
+ * Groups data by specified keys using a composite string key (Phase 3: replaces JSON.stringify).
18
18
  *
19
19
  * @param {Array} data - An array of data points.
20
20
  * @param {Array} groupByKeys - Keys to group the data by.
@@ -30,6 +30,7 @@ export function groupDataByKeys(data: any[], groupByKeys: any[], summaries: any[
30
30
  * @returns {Array} Aligned data array.
31
31
  */
32
32
  export function fillAlignedData(groupedData: Object, config: Object, fillRowsFunc: any): any[];
33
+ export function getAlignGenerator(data: any, config: any): (children: any) => any[];
33
34
  /**
34
35
  * Performs aggregation operations on grouped data.
35
36
  *
@@ -38,14 +39,3 @@ export function fillAlignedData(groupedData: Object, config: Object, fillRowsFun
38
39
  * @returns {Array} Aggregated data array with computed summary values.
39
40
  */
40
41
  export function aggregateData(dataArray: any[], summaries: any[]): any[];
41
- /**
42
- * Creates a generator that produces missing rows in a dataset based on specified columns.
43
- * The function determines all unique combinations of the specified columns in config.align_by
44
- * and returns a generator function to create the missing combinations, potentially with default
45
- * values for other columns.
46
- * @param {Array<Object>} data - The array of objects representing the dataset.
47
- * @param {Object} config - The configuration object.
48
- *
49
- * @returns {Function} A generator function that when called, produces the missing rows.
50
- */
51
- export function getAlignGenerator(data: Array<Object>, config: Object): Function;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rokkit/data",
3
- "version": "1.0.0-next.148",
3
+ "version": "1.0.0-next.150",
4
4
  "description": "Contains generic data manipulation functions that can be used in various components.",
5
5
  "repository": {
6
6
  "type": "git",
package/src/constants.js CHANGED
@@ -1,6 +1,11 @@
1
- import { identity, pick } from 'ramda'
2
-
3
- export const pickAllowedConfig = pick(['children', 'actual_flag'])
1
+ const ALLOWED_CONFIG_KEYS = new Set(['children', 'actual_flag'])
2
+ export const pickAllowedConfig = (obj) => {
3
+ const result = {}
4
+ for (const k of ALLOWED_CONFIG_KEYS) {
5
+ if (k in obj) result[k] = obj[k]
6
+ }
7
+ return result
8
+ }
4
9
 
5
10
  /** @type {import('./types').DataFrameConfig */
6
11
  export const defaultConfig = {
@@ -63,7 +68,7 @@ export const typeConverters = {
63
68
  number: (value) => Number(value),
64
69
  boolean: (value) => value === 'true' || value === true,
65
70
  date: (value) => new Date(value),
66
- mixed: identity
71
+ mixed: (x) => x
67
72
  }
68
73
 
69
74
  /**