@rokkit/data 1.0.0-next.104 → 1.0.0-next.106
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/package.json +2 -2
- package/src/infer.js +4 -3
- package/src/metadata.js +3 -3
- package/src/model.js +2 -2
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.106",
|
|
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",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@lukeed/uuid": "^2.0.1",
|
|
34
|
-
"@rokkit/core": "1.0.0-next.
|
|
34
|
+
"@rokkit/core": "1.0.0-next.105",
|
|
35
35
|
"d3-array": "^3.2.4",
|
|
36
36
|
"d3-collection": "^1.0.7",
|
|
37
37
|
"ramda": "^0.30.1",
|
package/src/infer.js
CHANGED
|
@@ -95,8 +95,9 @@ export function deriveSortableColumn(value) {
|
|
|
95
95
|
* @param {Array<Object>} data - An array of objects to deep scan and collect sample values.
|
|
96
96
|
* @returns {Object} A sample object consolidating all unique keys with their latest non-null values.
|
|
97
97
|
*/
|
|
98
|
-
export function
|
|
99
|
-
if (
|
|
98
|
+
export function getSample(data, deepScan = true) {
|
|
99
|
+
if (data.length === 0) return {}
|
|
100
|
+
if (!deepScan) return data[0]
|
|
100
101
|
return data.reduce(
|
|
101
102
|
(acc, cur) => ({
|
|
102
103
|
...acc,
|
|
@@ -117,7 +118,7 @@ export function deriveColumns(data, options) {
|
|
|
117
118
|
if (data.length === 0) return []
|
|
118
119
|
|
|
119
120
|
const { scanMode } = { ...defaultViewOptions, ...options }
|
|
120
|
-
const sample = scanMode === 'fast' ? data[0] :
|
|
121
|
+
const sample = scanMode === 'fast' ? data[0] : getSample(data)
|
|
121
122
|
|
|
122
123
|
return deriveColumnProperties(sample, options)
|
|
123
124
|
}
|
package/src/metadata.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defaultPathOptions } from './constants'
|
|
2
|
-
import {
|
|
2
|
+
import { getSample } from './infer'
|
|
3
3
|
import { typeOf } from './utils'
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -88,8 +88,8 @@ export function deriveColumnProperties(sample, options) {
|
|
|
88
88
|
export function deriveColumnMetadata(data, options = {}) {
|
|
89
89
|
const { metadata, deepScan = false } = options
|
|
90
90
|
if (Array.isArray(metadata) && metadata.length > 0) return metadata
|
|
91
|
-
if (data.length === 0) return []
|
|
92
|
-
const sample =
|
|
91
|
+
// if (data.length === 0) return []
|
|
92
|
+
const sample = getSample(data, deepScan)
|
|
93
93
|
return Object.entries(sample).map(([name, value]) => ({ name, type: typeOf(value) }))
|
|
94
94
|
}
|
|
95
95
|
|
package/src/model.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { identity, clone as copy } from 'ramda'
|
|
2
|
-
import {
|
|
2
|
+
import { getSample } from './infer'
|
|
3
3
|
import { typeOf } from './utils'
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -13,7 +13,7 @@ function deriveModel(data, sparse = false) {
|
|
|
13
13
|
const result = []
|
|
14
14
|
let item = data
|
|
15
15
|
|
|
16
|
-
if (Array.isArray(data)) item = sparse ?
|
|
16
|
+
if (Array.isArray(data)) item = sparse ? getSample(data) : data[0]
|
|
17
17
|
|
|
18
18
|
const kv = Object.entries(item)
|
|
19
19
|
kv.forEach(([key, value]) => {
|