@rokkit/data 1.0.0-next.133 → 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.
- package/README.md +123 -35
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -1,50 +1,138 @@
|
|
|
1
1
|
# @rokkit/data
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Data manipulation utilities for the Rokkit design system — filtering, joining, schema inference, and dataset views.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Install
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
26
|
+
### Type inference
|
|
16
27
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
39
|
+
### Filtering
|
|
25
40
|
|
|
26
41
|
```js
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
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
|
-
##
|
|
113
|
+
## API
|
|
41
114
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
136
|
+
---
|
|
49
137
|
|
|
50
|
-
|
|
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.
|
|
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",
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
},
|
|
11
11
|
"scripts": {
|
|
12
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
|
},
|
|
@@ -31,7 +32,7 @@
|
|
|
31
32
|
},
|
|
32
33
|
"dependencies": {
|
|
33
34
|
"@lukeed/uuid": "^2.0.1",
|
|
34
|
-
"@rokkit/core": "1.0.0-next.
|
|
35
|
+
"@rokkit/core": "1.0.0-next.134",
|
|
35
36
|
"d3-array": "^3.2.4",
|
|
36
37
|
"d3-collection": "^1.0.7",
|
|
37
38
|
"ramda": "^0.32.0",
|