You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit a686dba
Browse filesBrowse the repository at this point in the historyBrowse files
feat: Enhance error handling with custom error classes and improve validation logic
- Added rich error handling with descriptive error classes for better semantics.
- Improved validation logic in the Base class to throw specific errors for various validation failures.
- Updated the README and CHANGELOG to reflect new features and improvements.
- Added benchmarking capabilities to measure performance of model creation and updates.
- Refactored CI workflow to streamline testing and coverage reporting.
Copy file name to clipboardExpand all lines: CHANGELOG.md
+12Lines changed: 12 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,18 @@
2
2
3
3
All notable changes to this project will be documented in this file.
4
4
5
+
## [1.1.0] - 2026-06-02
6
+
7
+
### Added
8
+
- Rich and detailed error handling with descriptive error classes to enable programmatic error handling and clearer error semantics.
9
+
10
+
### Changed
11
+
- Removed redundant checks
12
+
- Fixed loop on error thrown during construction to properly set all properties to the error object instead of just the enumerable ones.
13
+
14
+
### Notes
15
+
- These changes improve runtime safety and the test coverage baseline; see tests in `test/base.test.js` for usage patterns.
16
+
5
17
## [1.0.0] - 2024-06-30
6
18
- Project renamed from `@bufferpunk/schema` to `@bufferpunk/modelcore` to better reflect its focus on runtime entities and validation rather than just schema definition.
7
19
- Improve TypeScript ergonomics: recommend `as const` schemas and provide `createFrom` factory for single-source-of-truth typed instantiation.
Copy file name to clipboardExpand all lines: README.md
+60-5Lines changed: 60 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,17 @@
1
1
# ModelCore - Runtime Entity Integrity for JavaScript and TypeScript
2
2
3
-
A lightweight runtime schema validator for JavaScript and TypeScript models with support for immutability, field-level validation hooks, and TypeScript-friendly ergonomics.
`@bufferpunk/modelcore` is built around a `Base` class that validates plain objects using a static `schema` definition. It is useful when working with NoSQL data, API payloads, and nested objects that need runtime guarantees and constraints.
A blazing fast, lightweight and Reactive Class-Based Object Modeling framework.
11
+
12
+
Build clean, safe, and delightful domain entities for TypeScript and JavaScript.
13
+
14
+
`@bufferpunk/modelcore` is built around a `Base` class that validates plain objects using a static `schema` definition. It is useful when working with NoSQL data, API payloads, and nested objects that need runtime and compile-time guarantees and constraints.
6
15
7
16
## What It Does
8
17
@@ -19,6 +28,27 @@ When a model extends `Base` and defines a static `schema`, instance creation and
19
28
20
29
This package now also provides a typed factory pattern (`createFrom`) and improved TypeScript mappings so editors receive useful type information and inferred instance types when schemas are declared with `as const`.
21
30
31
+
## Comparison to Other Libraries
32
+
33
+
-**Zod / Joi / Yup**: These are schema validation libraries that focus on validating plain objects. They do not provide a class-based model with runtime immutability or automatic coercion. You would need to manually validate and then assign values to a class instance.
34
+
-**TypeORM / Sequelize**: These are ORM libraries that provide class-based models but are tightly coupled to databases and do not focus on runtime validation or immutability outside of the context of database operations.
35
+
-**MobX / Vue Reactivity**: These libraries provide reactivity and state management but do not enforce validation rules or immutability at the runtime level. They track changes but do not govern them.
36
+
37
+
**ModelCore** fills the gap by providing a class-based modeling system that enforces validation and immutability rules at runtime and compile-time, making it suitable for both frontend and backend applications where data integrity is crucial.
38
+
39
+
**Here is a simple comparison with other libraries**
@@ -162,13 +192,13 @@ class ImmutableUser extends Base {
162
192
163
193
## Updating Instances
164
194
165
-
Use the `update()` method or regular property assignment to modify instance properties.
195
+
Use regular property access (recommended) to modify instance properties or the `update()` method (best if you want to update the whole object).
166
196
The constructor automatically includes the `version` if defined on the class.
167
197
168
198
```ts
169
199
const user =newUser({ name: 'John', role: 'user' });
170
-
user.update({ role: 'admin' });
171
-
user.name='Jane'; // also works, with validation (eassiest for simple updates)
200
+
user.name='Jane'; // (easiest and recommended for simple property changes)
201
+
user.update({ name: 'Jane', role: 'admin' });
172
202
```
173
203
174
204
## Factory and TypeScript ergonomics
@@ -213,6 +243,31 @@ npm test
213
243
214
244
The repository includes a GitHub Actions workflow to run build and test on Node LTS.
215
245
246
+
## Benchmarking
247
+
248
+
Use the included micro-benchmark to compare construction, factory creation, updates, and mutation paths:
249
+
250
+
```bash
251
+
npm run bench
252
+
```
253
+
254
+
You can adjust iteration count with `BENCH_ITERATIONS`:
255
+
256
+
```bash
257
+
BENCH_ITERATIONS=100000 npm run bench
258
+
```
259
+
260
+
Example result on this repository, run with `BENCH_ITERATIONS=100000`:
261
+
262
+
```text
263
+
construct + validate 1512.23 ms 66128 ops/sec
264
+
createFrom factory 1452.82 ms 68832 ops/sec
265
+
update validated fields 2831.84 ms 35313 ops/sec
266
+
array mutations 2747.17 ms 36401 ops/sec
267
+
```
268
+
269
+
The benchmark is intentionally small and repeatable. It is useful for comparing changes between commits, not for replacing a full profiler or load test.
270
+
216
271
## Why Runtime Entities Matter
217
272
218
273
See the manifesto for the project's goals and positioning: [manifesto.md](manifesto.md)
0 commit comments