@rokkit/data 1.0.0-next.132 → 1.0.0-next.134

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 (3) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +123 -35
  3. package/package.json +6 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Jerry Thomas
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,50 +1,138 @@
1
1
  # @rokkit/data
2
2
 
3
- This package provides a set of tools for managing and manipulating data in user interfaces. It is framework agnostic and can be used with any ui framework.
3
+ Data manipulation utilities for the Rokkit design system — filtering, joining, schema inference, and dataset views.
4
4
 
5
- ## Features
5
+ ## Install
6
6
 
7
- - **Datasets:** Manage and manipulate datasets with ease
8
- - filtering, sorting, and aggregation.
9
- - **Joins:** Combine datasets effortlessly with support for inner, outer, left, and right joins.
10
- - **Rollup:** Summarize data across multiple dimensions, calculating aggregate statistics like sum, average, min, and max.
11
- - **Modeling:** Create and manage data models, including merging, renaming, and resolving conflicts.
12
- - **Renaming:** Simplify key renaming in JavaScript objects, with options for prefixes, suffixes, and custom separators.
13
- - **Dataviews:** Create interactive views for exploring and analyzing datasets, including sortable and filterable columns.
7
+ ```sh
8
+ npm install @rokkit/data
9
+ # or
10
+ bun add @rokkit/data
11
+ ```
12
+
13
+ ## Overview
14
+
15
+ `@rokkit/data` provides general-purpose data utilities for working with arrays of objects. It is used internally by `@rokkit/ui` table and grid components and can also be used standalone.
16
+
17
+ - **Type inference** — detect column types from data samples
18
+ - **Filtering** — apply single or multiple filters with standard operators
19
+ - **Joins** — relational join operations across two datasets
20
+ - **Dataset / Dataview** — composable dataset abstraction with filter, sort, and pagination
21
+ - **Metadata** — derive column definitions and types from raw data
22
+ - **Renaming** — remap object keys with a rename spec
23
+
24
+ ## Usage
14
25
 
15
- ## Dataset
26
+ ### Type inference
16
27
 
17
- - The `dataset` function initializes a dataset from an array of objects.
18
- - This dataset comprises data rows that are sortable, filterable, and groupable.
19
- - Leverage dataset for SQL-like operations such as selecting, updating, and deleting rows.
20
- - Employ aggregate functions like sum, average, and count for summarizing multiple attributes of the data.
21
- - Utilize the dataset for various data operations like joining and merging data from disparate sources.
22
- - Establish connected data views with joins to visualize data relationships, particularly for tracking parent-child connections.
28
+ ```js
29
+ import { typeOf } from '@rokkit/data'
30
+
31
+ typeOf('hello') // 'string'
32
+ typeOf(42) // 'number'
33
+ typeOf(new Date()) // 'date'
34
+ typeOf([1, 2]) // 'array'
35
+ typeOf({ a: 1 }) // 'object'
36
+ typeOf(true) // 'boolean'
37
+ ```
23
38
 
24
- This makes it easier to build a tweenable data structure for animations. Here is an example of how to use the `dataset` to generate a tweenable data:
39
+ ### Filtering
25
40
 
26
41
  ```js
27
- function tweenable(data, by, group, template) {
28
- return dataset(data)
29
- .groupBy(by)
30
- .using(template)
31
- .alignBy(...group)
32
- .rollup()
33
- .sortBy(by)
34
- .select()
35
- }
42
+ import { filterObjectArray, filterData } from '@rokkit/data'
43
+
44
+ // Single filter
45
+ const adults = filterObjectArray(users, {
46
+ column: 'age',
47
+ value: 18,
48
+ operator: 'gte'
49
+ })
50
+
51
+ // Multiple filters combined
52
+ const results = filterData(users, [
53
+ { column: 'status', value: 'active', operator: 'eq' },
54
+ { column: 'age', value: 18, operator: 'gte' }
55
+ ])
36
56
  ```
37
57
 
38
- Refer to [dataset](docs/dataset.md) documentation for more details.
58
+ Supported operators: `eq`, `ne`, `gt`, `gte`, `lt`, `lte`, `contains`, `startsWith`, `endsWith`, `in`, `notIn`.
59
+
60
+ ### Joins
61
+
62
+ ```js
63
+ import { leftJoin, innerJoin } from '@rokkit/data'
64
+
65
+ const result = leftJoin(orders, customers, 'customerId', 'id')
66
+ // Each order row merged with its matching customer row (nulls if unmatched)
67
+ ```
68
+
69
+ Available joins: `innerJoin`, `leftJoin`, `rightJoin`, `fullJoin`, `crossJoin`, `antiJoin`, `semiJoin`.
70
+
71
+ ### Schema inference
72
+
73
+ ```js
74
+ import { deriveMetadata, deriveColumns } from '@rokkit/data'
75
+
76
+ const metadata = deriveMetadata(data)
77
+ // [{ column: 'name', type: 'string' }, { column: 'age', type: 'number' }, ...]
78
+
79
+ const columns = deriveColumns(data)
80
+ // Column definitions ready for use in a table component
81
+ ```
82
+
83
+ ### Dataset and dataview
84
+
85
+ ```js
86
+ import { dataset, dataview } from '@rokkit/data'
87
+
88
+ const ds = dataset(rawData)
89
+ const view = dataview(ds, {
90
+ filters: [{ column: 'active', value: true, operator: 'eq' }],
91
+ sort: [{ column: 'name', direction: 'asc' }],
92
+ page: { size: 20, index: 0 }
93
+ })
94
+ ```
95
+
96
+ ### Key renaming
97
+
98
+ ```js
99
+ import { renamer } from '@rokkit/data'
100
+
101
+ const rename = renamer({ firstName: 'first_name', lastName: 'last_name' })
102
+ const remapped = data.map(rename)
103
+ ```
104
+
105
+ ### Filter string parsing
106
+
107
+ ```js
108
+ import { parseFilters } from '@rokkit/data'
109
+
110
+ const filters = parseFilters('age >= 18 AND status = "active"')
111
+ ```
39
112
 
40
- ## DataView
113
+ ## API
41
114
 
42
- - Utilize the `dataview` function to create a data view, enabling dynamic data manipulation and observation.
43
- - This view facilitates sorting, filtering, and grouping data while providing insight into selected or hidden rows.
44
- - The original dataset remains untouched while the view offers flexible data presentation options.
45
- - Associate actions such as select, edit, and delete with data rows using action columns within the view.
46
- - Manage data effectively, including parent-child links, even within a flat array structure.
115
+ | Export | Description |
116
+ | --------------------------------- | ----------------------------------------------------- |
117
+ | `typeOf(value)` | Infer type string from a value |
118
+ | `filterObjectArray(data, filter)` | Apply a single filter object to an array |
119
+ | `filterData(data, filters)` | Apply an array of filters to a dataset |
120
+ | `parseFilters(string)` | Parse a filter expression string into filter objects |
121
+ | `innerJoin(a, b, keyA, keyB)` | Inner join two arrays on matching keys |
122
+ | `leftJoin(a, b, keyA, keyB)` | Left join — all rows from `a`, matched rows from `b` |
123
+ | `rightJoin(a, b, keyA, keyB)` | Right join — all rows from `b`, matched rows from `a` |
124
+ | `fullJoin(a, b, keyA, keyB)` | Full outer join |
125
+ | `crossJoin(a, b)` | Cartesian product of two arrays |
126
+ | `antiJoin(a, b, keyA, keyB)` | Rows in `a` with no match in `b` |
127
+ | `semiJoin(a, b, keyA, keyB)` | Rows in `a` that have a match in `b` |
128
+ | `deriveMetadata(data)` | Infer column names and types from a data sample |
129
+ | `deriveColumns(data)` | Derive column definitions from data |
130
+ | `deriveSortableColumn(col)` | Mark a column as sortable |
131
+ | `dataset(data, options?)` | Create a dataset abstraction |
132
+ | `dataview(dataset, options?)` | Create a filtered/sorted/paged view over a dataset |
133
+ | `renamer(mapping)` | Create a function that renames object keys |
134
+ | `model(data)` | Create a reactive data model |
47
135
 
48
- Refer to [dataview](docs/dataview.md) documentation for more details.
136
+ ---
49
137
 
50
- The `dataview` function initializes a manageable data state with methods that allow for manipulation and observation of data changes, integrating smoothly with UI updates.
138
+ Part of [Rokkit](https://github.com/jerrythomas/rokkit) — a Svelte 5 component library and design system.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rokkit/data",
3
- "version": "1.0.0-next.132",
3
+ "version": "1.0.0-next.134",
4
4
  "description": "Contains generic data manipulation functions that can be used in various components.",
5
5
  "author": "Jerry Thomas <me@jerrythomas.name>",
6
6
  "license": "MIT",
@@ -9,7 +9,8 @@
9
9
  "access": "public"
10
10
  },
11
11
  "scripts": {
12
- "prepublishOnly": "tsc --project tsconfig.build.json",
12
+ "prepublishOnly": "cp ../../LICENSE . && tsc --project tsconfig.build.json",
13
+ "postpublish": "rm -f LICENSE",
13
14
  "clean": "rm -rf dist",
14
15
  "build": "bun clean && bun prepublishOnly"
15
16
  },
@@ -17,7 +18,8 @@
17
18
  "src/**/*.js",
18
19
  "dist/**/*.d.ts",
19
20
  "README.md",
20
- "package.json"
21
+ "package.json",
22
+ "LICENSE"
21
23
  ],
22
24
  "exports": {
23
25
  "./src": "./src",
@@ -30,7 +32,7 @@
30
32
  },
31
33
  "dependencies": {
32
34
  "@lukeed/uuid": "^2.0.1",
33
- "@rokkit/core": "1.0.0-next.132",
35
+ "@rokkit/core": "1.0.0-next.134",
34
36
  "d3-array": "^3.2.4",
35
37
  "d3-collection": "^1.0.7",
36
38
  "ramda": "^0.32.0",