mlform 0.1.2 → 0.1.3
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 +166 -85
- package/dist/FieldStrategy-CW2h8YyB.js +2427 -0
- package/dist/{ReportStrategy-DY3GC_mJ.js → ReportStrategy-CxPzs4b2.js} +1 -1
- package/dist/{boolean-field-Cd3uhIPj.js → boolean-field-Dwz0ejWl.js} +2 -2
- package/dist/{category-field-D_Ms1x9u.js → category-field-DIgX--Px.js} +2 -2
- package/dist/{classifier-prediction-C5QzorTo.js → classifier-prediction-DgiEREf_.js} +2 -2
- package/dist/{custom-element-ttkHUa8w.js → custom-element-DFxkZ1wU.js} +0 -5
- package/dist/{date-field-Cg_ja679.js → date-field-91U2Xe46.js} +2 -2
- package/dist/{error-card-BwjPChwf.js → error-card-DHdkE18B.js} +2 -2
- package/dist/{field-wrapper-DqIQl76d.js → field-wrapper-CBmpN5T_.js} +3 -3
- package/dist/{ml-layout-Dx63KKf7.js → ml-layout-BJax9HVW.js} +3 -3
- package/dist/mlform/extensions.mjs +4 -4
- package/dist/mlform/strategies.mjs +9 -9
- package/dist/mlform.mjs +210 -202
- package/dist/{number-field-CC2DrVEb.js → number-field-Bcp45dJb.js} +31 -32
- package/dist/{property-jKFNMQpR.js → property-B2UZ3Oii.js} +0 -25
- package/dist/{range-field-Cr7LEtsJ.js → range-field-CD0kkCt0.js} +2 -2
- package/dist/{regressor-prediction-C18dHlfK.js → regressor-prediction-CPzZXlmA.js} +2 -2
- package/dist/src/core/domain/index.d.ts +2 -1
- package/dist/state-Ba1Gr1cr.js +7 -0
- package/dist/test/integration/lifecycle.integration.test.d.ts +1 -0
- package/dist/test/integration/registration.integration.test.d.ts +1 -0
- package/dist/test/integration/state.integration.test.d.ts +1 -0
- package/dist/test/integration/validation.integration.test.d.ts +1 -0
- package/dist/test/unit/Strategies.extensions.test.d.ts +1 -0
- package/dist/test/unit/Strategies.test.d.ts +1 -0
- package/dist/{text-field-DwP-Fa1w.js → text-field-CSBBr4gN.js} +2 -2
- package/package.json +59 -15
- package/dist/FieldStrategy-pPekBtH-.js +0 -2318
- package/dist/state-CLlTRyl1.js +0 -12
package/README.md
CHANGED
|
@@ -2,131 +2,212 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://github.com/UlloaSP/mlform/actions/workflows/ci.yml)
|
|
4
4
|
[](https://github.com/UlloaSP/mlform/actions/workflows/release.yml)
|
|
5
|
+
[](https://www.npmjs.com/package/mlform)
|
|
6
|
+
[](LICENSE)
|
|
5
7
|
|
|
6
|
-
|
|
8
|
+
Composable form generation for machine learning workflows. MLForm turns JSON schemas into responsive web components, validates user input with Zod, and connects submissions to your predictive backend.
|
|
7
9
|
|
|
8
|
-
##
|
|
10
|
+
## Table of contents
|
|
9
11
|
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
12
|
+
- [Overview](#overview)
|
|
13
|
+
- [Features](#features)
|
|
14
|
+
- [Installation](#installation)
|
|
15
|
+
- [Quick start](#quick-start)
|
|
16
|
+
- [Schema essentials](#schema-essentials)
|
|
17
|
+
- [Machine learning responses](#machine-learning-responses)
|
|
18
|
+
- [Extensibility](#extensibility)
|
|
19
|
+
- [Runtime utilities](#runtime-utilities)
|
|
20
|
+
- [Tooling & scripts](#tooling--scripts)
|
|
21
|
+
- [Documentation & resources](#documentation--resources)
|
|
22
|
+
- [Contributing](#contributing)
|
|
23
|
+
- [License](#license)
|
|
15
24
|
|
|
16
|
-
##
|
|
25
|
+
## Overview
|
|
26
|
+
|
|
27
|
+
MLForm is a TypeScript-first library that renders adaptive forms as standards-based Web Components built with Lit. Provide a predictable JSON schema, plug in your ML inference endpoint, and receive validated input alongside structured model responses. The library ships with batteries included for common field types and ML output strategies, while remaining extensible for custom domains.
|
|
28
|
+
|
|
29
|
+
## Features
|
|
30
|
+
|
|
31
|
+
- Dynamic rendering of form layouts driven by strongly typed JSON signatures
|
|
32
|
+
- Built-in integration with regression and classification endpoints via fetch
|
|
33
|
+
- Prepackaged strategies for text, number, boolean, category, and date inputs
|
|
34
|
+
- Subscription API (`onSubmit`) and accessors (`lastInputs`, `lastResponse`) for reactive UIs
|
|
35
|
+
- Lazy-loaded Web Components that stay framework-agnostic and usable in any SPA or vanilla app
|
|
36
|
+
- Zod-powered validation, JSON Schema generation, and type definitions out of the box
|
|
37
|
+
|
|
38
|
+
## Installation
|
|
17
39
|
|
|
18
40
|
```bash
|
|
19
41
|
npm install mlform
|
|
20
42
|
```
|
|
21
43
|
|
|
22
|
-
|
|
44
|
+
> Requirements: Node.js >= 22.14 and npm >= 9.
|
|
23
45
|
|
|
24
|
-
|
|
46
|
+
The package exposes ESM builds and bundled type declarations. Consumers can tree-shake imports such as `mlform`, `mlform/extensions`, and `mlform/strategies` with modern bundlers (Vite, Webpack, Rollup, etc.).
|
|
25
47
|
|
|
26
|
-
|
|
27
|
-
- npm >= 9
|
|
48
|
+
## Quick start
|
|
28
49
|
|
|
29
|
-
|
|
50
|
+
```typescript
|
|
51
|
+
import { MLForm } from "mlform";
|
|
30
52
|
|
|
31
|
-
|
|
32
|
-
# Clonar el repositorio
|
|
33
|
-
git clone https://github.com/UlloaSP/mlform.git
|
|
34
|
-
cd mlform
|
|
53
|
+
const mlForm = new MLForm("https://api.example.com/predict");
|
|
35
54
|
|
|
36
|
-
|
|
37
|
-
|
|
55
|
+
const schema = {
|
|
56
|
+
inputs: [
|
|
57
|
+
{ type: "text", title: "Full Name", required: true },
|
|
58
|
+
{ type: "number", title: "Age", min: 0, max: 120, required: true },
|
|
59
|
+
{
|
|
60
|
+
type: "category",
|
|
61
|
+
title: "Department",
|
|
62
|
+
options: ["Engineering", "Sales", "Marketing"],
|
|
63
|
+
required: true,
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
outputs: [{ type: "classifier", title: "Access Level" }],
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
mlForm.onSubmit((inputs, response) => {
|
|
70
|
+
console.log("User inputs", inputs);
|
|
71
|
+
console.log("Prediction", response);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const container = document.getElementById("form-container")!;
|
|
75
|
+
await mlForm.toHTMLElement(schema, container);
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
```html
|
|
79
|
+
<div id="form-container"></div>
|
|
80
|
+
<script type="module" src="./main.ts"></script>
|
|
81
|
+
```
|
|
38
82
|
|
|
39
|
-
|
|
40
|
-
npm test
|
|
83
|
+
MLForm mounts a custom `<ml-layout>` shell, injects the appropriate field components, and dispatches an `ml-submit` event internally when the user submits the form. Responses from your backend are automatically forwarded to registered listeners and mirrored in the report slot.
|
|
41
84
|
|
|
42
|
-
|
|
43
|
-
npm run lint
|
|
85
|
+
## Schema essentials
|
|
44
86
|
|
|
45
|
-
|
|
46
|
-
npm run format
|
|
87
|
+
Schemas follow the `Signature` type exported from `mlform/core` (re-exported as `Signature` in the root package). Each entry is validated with Zod before rendering.
|
|
47
88
|
|
|
48
|
-
|
|
49
|
-
npm run type
|
|
89
|
+
### Input field types
|
|
50
90
|
|
|
51
|
-
|
|
52
|
-
|
|
91
|
+
| Type | Description | Key options |
|
|
92
|
+
| --- | --- | --- |
|
|
93
|
+
| `text` | Single-line text input | `minLength`, `maxLength`, `pattern`, `placeholder`, `value` |
|
|
94
|
+
| `number` | Numeric input with constraints | `min`, `max`, `step`, `value` |
|
|
95
|
+
| `boolean` | Checkbox or toggle | `required` |
|
|
96
|
+
| `category` | Select or radio options | `options`, `multiple` |
|
|
97
|
+
| `date` | Date picker | `min`, `max`, `format`, `value` |
|
|
53
98
|
|
|
54
|
-
|
|
55
|
-
|
|
99
|
+
Every field shares a base structure of `title`, optional `description`, and an explicit `required` flag (defaulting to `true`).
|
|
100
|
+
|
|
101
|
+
### Model output types
|
|
102
|
+
|
|
103
|
+
| Type | Use case | Typical payload |
|
|
104
|
+
| --- | --- | --- |
|
|
105
|
+
| `classifier` | Discrete predictions | `prediction`, `confidence`, `probabilities`, `execution_time` |
|
|
106
|
+
| `regressor` | Continuous predictions | `prediction`, `confidence_interval`, `std_deviation`, `execution_time` |
|
|
107
|
+
|
|
108
|
+
You can combine multiple outputs within the same schema to present downstream analytics alongside user inputs.
|
|
109
|
+
|
|
110
|
+
## Machine learning responses
|
|
111
|
+
|
|
112
|
+
During submission MLForm issues a POST request to the backend URL configured in the constructor. The body contains the normalized user inputs and the requested model metadata. Responses are projected into the report slot and emitted to listeners.
|
|
113
|
+
|
|
114
|
+
```json
|
|
115
|
+
// Request payload
|
|
116
|
+
{
|
|
117
|
+
"inputs": {
|
|
118
|
+
"Full Name": "Jane Doe",
|
|
119
|
+
"Age": 34,
|
|
120
|
+
"Department": "Engineering"
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
```json
|
|
126
|
+
// Expected response
|
|
127
|
+
{
|
|
128
|
+
"outputs": [
|
|
129
|
+
{
|
|
130
|
+
"type": "classifier",
|
|
131
|
+
"prediction": "admin",
|
|
132
|
+
"confidence": 0.92,
|
|
133
|
+
"probabilities": {
|
|
134
|
+
"viewer": 0.05,
|
|
135
|
+
"editor": 0.03,
|
|
136
|
+
"admin": 0.92
|
|
137
|
+
},
|
|
138
|
+
"execution_time": 37
|
|
139
|
+
}
|
|
140
|
+
]
|
|
141
|
+
}
|
|
56
142
|
```
|
|
57
143
|
|
|
58
|
-
|
|
144
|
+
Runtime helpers:
|
|
59
145
|
|
|
60
|
-
- `
|
|
61
|
-
- `
|
|
62
|
-
- `
|
|
63
|
-
- `npm run format:check` - Verifica el formato del código
|
|
64
|
-
- `npm run type` - Verifica tipos con TypeScript
|
|
65
|
-
- `npm run test` - Ejecuta tests con Vitest
|
|
66
|
-
- `npm run test:watch` - Ejecuta tests en modo watch
|
|
67
|
-
- `npm run coverage` - Genera reporte de cobertura
|
|
68
|
-
- `npm run build` - Construye el proyecto para producción
|
|
69
|
-
- `npm run docs` - Genera documentación con TypeDoc
|
|
70
|
-
- `npm run ci` - Ejecuta todo el pipeline de CI localmente
|
|
146
|
+
- `mlForm.onSubmit(callback)` returns an unsubscribe function and delivers both the parsed inputs and the transformed backend response.
|
|
147
|
+
- `mlForm.lastInputs` and `mlForm.lastResponse` expose the latest submission synchronously.
|
|
148
|
+
- `DescriptorService` handles lazy loading and rendering of ML report components so predictions are shown without additional wiring.
|
|
71
149
|
|
|
72
|
-
##
|
|
150
|
+
## Extensibility
|
|
73
151
|
|
|
74
|
-
|
|
152
|
+
MLForm is built around strategy classes that map schema entries to UI components. You can add or replace strategies for bespoke controls or ML result renderers.
|
|
75
153
|
|
|
76
|
-
|
|
154
|
+
```typescript
|
|
155
|
+
import { MLForm } from "mlform";
|
|
156
|
+
import { FieldStrategy } from "mlform/extensions";
|
|
77
157
|
|
|
78
|
-
|
|
158
|
+
class ColorPickerStrategy extends FieldStrategy {
|
|
159
|
+
constructor() {
|
|
160
|
+
super("color", ColorSchema, () => import("./color-field"));
|
|
161
|
+
}
|
|
79
162
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
163
|
+
buildControl(field) {
|
|
164
|
+
return {
|
|
165
|
+
tag: "color-field",
|
|
166
|
+
props: { value: field.value, label: field.title },
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
}
|
|
86
170
|
|
|
87
|
-
|
|
171
|
+
const mlForm = new MLForm("https://api.example.com/predict");
|
|
172
|
+
mlForm.register(new ColorPickerStrategy());
|
|
173
|
+
```
|
|
88
174
|
|
|
89
|
-
|
|
175
|
+
Use the default strategies exported from `mlform/strategies` as references when crafting new descriptors. Updates and removals follow the same pattern via `mlForm.update()` and `mlForm.unregister()`.
|
|
90
176
|
|
|
91
|
-
|
|
92
|
-
2. **📦 NPM Publish** - Publicación automática en NPM
|
|
177
|
+
## Runtime utilities
|
|
93
178
|
|
|
94
|
-
|
|
179
|
+
- `mlForm.validateSchema(signature)` returns a Zod safe-parse result, useful for testing incoming schemas before rendering.
|
|
180
|
+
- `mlForm.schema()` produces a JSON Schema (draft 2020-12) for your current registry configuration, enabling schema introspection or documentation workflows.
|
|
95
181
|
|
|
96
|
-
|
|
97
|
-
- **Linting**: Sin errores
|
|
98
|
-
- **Formato**: Código debe seguir las reglas de Prettier
|
|
99
|
-
- **Tipos**: Sin errores de TypeScript
|
|
100
|
-
- **Build**: Debe compilar sin errores
|
|
182
|
+
## Tooling & scripts
|
|
101
183
|
|
|
102
|
-
|
|
184
|
+
The repository uses npm as the package manager and Vite for bundling.
|
|
103
185
|
|
|
104
|
-
-
|
|
105
|
-
-
|
|
106
|
-
-
|
|
186
|
+
- `npm run lint` – format-aware linting powered by Biome.
|
|
187
|
+
- `npm run type` – TypeScript project checks with `tsc --noEmit`.
|
|
188
|
+
- `npm run test` / `npm run coverage` – unit tests and coverage via Vitest and V8 instrumentation.
|
|
189
|
+
- `npm run build` – generates the production-ready `dist/` bundle and declaration files.
|
|
190
|
+
- `npm run ci` – convenience task combining lint, type checks, tests, and build.
|
|
107
191
|
|
|
108
|
-
|
|
192
|
+
CI/CD pipelines verify linting, type safety, tests across Node 18/20/22, build integrity, documentation, and dependency audits. Releases are published to both GitHub and npm through GitHub Actions.
|
|
109
193
|
|
|
110
|
-
|
|
111
|
-
2. Crea una rama para tu feature (`git checkout -b feature/AmazingFeature`)
|
|
112
|
-
3. Commit tus cambios (`git commit -m 'Add some AmazingFeature'`)
|
|
113
|
-
4. Push a la rama (`git push origin feature/AmazingFeature`)
|
|
114
|
-
5. Abre un Pull Request
|
|
194
|
+
## Documentation & resources
|
|
115
195
|
|
|
116
|
-
|
|
196
|
+
- Product documentation: https://ulloasp.github.io/mlform/
|
|
197
|
+
- Examples and guides: `docs/`
|
|
198
|
+
- Bundle visualizations: `stats/bundle_size_treemap.html`
|
|
199
|
+
- Issue tracker: https://github.com/UlloaSP/mlform/issues
|
|
117
200
|
|
|
118
|
-
|
|
119
|
-
- Escribe tests para nuevas funcionalidades
|
|
120
|
-
- Mantén la cobertura de tests >= 80%
|
|
121
|
-
- Documenta el código con JSDoc
|
|
122
|
-
- Usa Conventional Commits para mensajes de commit
|
|
201
|
+
## Contributing
|
|
123
202
|
|
|
124
|
-
|
|
203
|
+
We welcome issues, feature requests, and pull requests.
|
|
125
204
|
|
|
126
|
-
|
|
205
|
+
1. Fork the repository and create a feature branch.
|
|
206
|
+
2. Run `npm install` followed by `npm run lint`, `npm run type`, and `npm run test` before committing.
|
|
207
|
+
3. Add or update tests and documentation alongside code changes (target 80%+ coverage).
|
|
208
|
+
4. Use Conventional Commit messages when possible.
|
|
209
|
+
5. Open a pull request describing your change and expected impact.
|
|
127
210
|
|
|
128
|
-
##
|
|
211
|
+
## License
|
|
129
212
|
|
|
130
|
-
|
|
131
|
-
- [Issues](https://github.com/UlloaSP/mlform/issues)
|
|
132
|
-
- [NPM Package](https://www.npmjs.com/package/mlform)
|
|
213
|
+
MLForm is released under the MIT License. See `LICENSE` for details.
|