@rebasepro/schema-inference 0.4.0 → 0.6.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/README.md CHANGED
@@ -1 +1,76 @@
1
- # schema_inference
1
+ # @rebasepro/schema-inference
2
+
3
+ Automatically infer Rebase collection property schemas from sample data — analyzes field types, detects enums, references, validation rules, and nested structures.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm add @rebasepro/schema-inference
9
+ ```
10
+
11
+ ## What This Package Does
12
+
13
+ `@rebasepro/schema-inference` examines arrays of data objects and produces `Properties` definitions compatible with the Rebase collection schema. It uses statistical analysis to determine the most probable type for each field, detect enum values, identify reference patterns, and build nested map/array structures. Used by the Rebase introspection pipeline and data import tools.
14
+
15
+ ## Key Exports
16
+
17
+ ### Collection Builder
18
+
19
+ | Export | Type | Description |
20
+ |---|---|---|
21
+ | `buildEntityPropertiesFromData` | `(data: object[], getType: InferenceTypeBuilder) => Promise<Properties>` | Main entry — infer full property schema from data |
22
+ | `buildPropertyFromData` | `(data: unknown[], property: Property, getType: InferenceTypeBuilder) => Property` | Refine an existing property with new sample data |
23
+ | `buildPropertiesOrder` | `(properties: Properties, propertiesOrder?: string[], priorityKeys?: string[]) => string[]` | Sort property keys (title/name first, then images, then alphabetical) |
24
+ | `inferTypeFromValue` | `(value: unknown) => DataType` | Default type inference: string, number, boolean, array, map, vector |
25
+ | `InferenceTypeBuilder` | Type | `(value: unknown) => DataType` — pluggable type detector |
26
+
27
+ ### String Utilities
28
+
29
+ | Export | Description |
30
+ |---|---|
31
+ | `parseReferenceString` | Parse `"path/entityId"` or `"db:::path/entityId"` format |
32
+ | `looksLikeReference` | Check if a string looks like a document reference |
33
+ | `findCommonInitialStringInPath` | Find shared collection path prefix in sample values |
34
+ | `removeInitialAndTrailingSlashes` | Path cleanup |
35
+ | `removeInitialSlash` / `removeTrailingSlash` | Path cleanup |
36
+
37
+ ### General Utilities (re-exported from `@rebasepro/utils`)
38
+
39
+ | Export | Description |
40
+ |---|---|
41
+ | `extractEnumFromValues` | Extract enum entries from sample string values |
42
+ | `resolveEnumValues` | Normalize `EnumValues` to `EnumValueConfig[]` |
43
+ | `prettifyIdentifier` | `"snake_case"` → `"Snake Case"` |
44
+ | `unslugify` | `"my-slug"` → `"My Slug"` |
45
+ | `mergeDeep` | Deep merge objects |
46
+
47
+ ## Quick Start
48
+
49
+ ```typescript
50
+ import {
51
+ buildEntityPropertiesFromData,
52
+ inferTypeFromValue
53
+ } from "@rebasepro/schema-inference";
54
+
55
+ const sampleData = [
56
+ { name: "Alice", age: 30, active: true, role: "admin" },
57
+ { name: "Bob", age: 25, active: false, role: "editor" },
58
+ { name: "Carol", age: 28, active: true, role: "admin" },
59
+ ];
60
+
61
+ const properties = await buildEntityPropertiesFromData(
62
+ sampleData,
63
+ inferTypeFromValue
64
+ );
65
+ // properties = {
66
+ // name: { type: "string", name: "Name", ... },
67
+ // age: { type: "number", name: "Age", ... },
68
+ // active: { type: "boolean", name: "Active", ... },
69
+ // role: { type: "string", name: "Role", enum: [...], ... }
70
+ // }
71
+ ```
72
+
73
+ ## Related Packages
74
+
75
+ - `@rebasepro/types` — Provides `Property`, `DataType`, `Properties`, and related types
76
+ - `@rebasepro/utils` — General utilities re-exported by this package