@quanticdigit/web-model 1.0.1 → 1.0.2

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.
Files changed (2) hide show
  1. package/README.md +53 -39
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,64 +1,78 @@
1
- # WebModel
1
+ # @quanticdigit/web-model
2
2
 
3
- This project was generated using [Angular CLI](https://github.com/angular/angular-cli) version 21.2.0.
3
+ Typed model reconstruction from JSON: `BaseModel` and the expose decorators for dates and nested
4
+ models.
4
5
 
5
- ## Code scaffolding
6
+ This package holds the **machinery**, not the models. Your own model hierarchy lives in your product,
7
+ where your generator writes it from your DTOs — those are your entity conventions, and a shared
8
+ package that contained them would force the second consumer to adopt the first one's.
6
9
 
7
- Angular CLI includes powerful code scaffolding tools. To generate a new component, run:
10
+ ## Install
8
11
 
9
12
  ```bash
10
- ng generate component component-name
13
+ npm install @quanticdigit/web-model class-transformer reflect-metadata
11
14
  ```
12
15
 
13
- For a complete list of available schematics (such as `components`, `directives`, or `pipes`), run:
16
+ `class-transformer` and `reflect-metadata` are peer dependencies.
14
17
 
15
- ```bash
16
- ng generate --help
17
- ```
18
-
19
- ## Building
18
+ ## Import reflect-metadata once
20
19
 
21
- To build the library, run:
20
+ The decorators read type metadata. Without this import they silently find nothing:
22
21
 
23
- ```bash
24
- ng build web-model
22
+ ```ts
23
+ // main.ts, before anything else
24
+ import 'reflect-metadata';
25
25
  ```
26
26
 
27
- This command will compile your project, and the build artifacts will be placed in the `dist/` directory.
28
-
29
- ### Publishing the Library
30
-
31
- Once the project is built, you can publish your library by following these steps:
27
+ ## Writing a model
32
28
 
33
- 1. Navigate to the `dist` directory:
29
+ ```ts
30
+ import { Exclude } from 'class-transformer';
31
+ import { BaseModel, ExposeDateOnly, ExposeDateTimeOffset, ExposeModel } from '@quanticdigit/web-model';
34
32
 
35
- ```bash
36
- cd dist/web-model
37
- ```
33
+ @Exclude()
34
+ export class Observation extends BaseModel {
35
+ @ExposeDateOnly() declare takenOn: Date;
36
+ @ExposeDateTimeOffset() declare createdAt: Date;
37
+ @ExposeModel(() => Species) declare species: Species;
38
38
 
39
- 2. Run the `npm publish` command to publish your library to the npm registry:
40
- ```bash
41
- npm publish
42
- ```
39
+ public override init(): void {
40
+ this.takenOn = new Date();
41
+ this.createdAt = new Date();
42
+ this.species = new Species();
43
+ }
44
+ }
45
+ ```
43
46
 
44
- ## Running unit tests
47
+ Then a plain object from the wire becomes a typed instance, and back:
45
48
 
46
- To execute unit tests with the [Karma](https://karma-runner.github.io) test runner, use the following command:
49
+ ```ts
50
+ const model = new Observation({ takenOn: '2026-08-29', species: { code: 'ABI' } });
47
51
 
48
- ```bash
49
- ng test
52
+ model.takenOn; // a Date
53
+ model.species; // a Species instance, not a plain object
54
+ model.toPlainObject(); // { takenOn: '2026-08-29', species: { code: 'ABI' } }
50
55
  ```
51
56
 
52
- ## Running end-to-end tests
57
+ ## The decorators
53
58
 
54
- For end-to-end (e2e) testing, run:
59
+ | Decorator | Wire format |
60
+ |---|---|
61
+ | `ExposeDateOnly` | `2026-08-29` |
62
+ | `ExposeTimeOnly` | `09:30:15` or `09:30:15.250` |
63
+ | `ExposeDateTimeOnly` | `2026-08-29T14:05:30.123`, no zone |
64
+ | `ExposeDateTimeOffset` | a full instant with zone |
65
+ | `ExposeTimeOffset` | a time of day carrying a zone |
66
+ | `ExposeModel` | a nested model, reconstructed as an instance |
55
67
 
56
- ```bash
57
- ng e2e
58
- ```
68
+ Round trips are stable across time zones: a date-only value read east of Greenwich is written back as
69
+ the same day.
70
+
71
+ ## The family
59
72
 
60
- Angular CLI does not come with an end-to-end testing framework by default. You can choose one that suits your needs.
73
+ `web-utils`, `web-model`, `web-services`, `web-component` and `web-errors` are released together and
74
+ always share the same version. Install them at the same version.
61
75
 
62
- ## Additional Resources
76
+ ## License
63
77
 
64
- For more information on using the Angular CLI, including detailed command references, visit the [Angular CLI Overview and Command Reference](https://angular.dev/tools/cli) page.
78
+ Commercial. See `LICENSE.txt` in the package.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@quanticdigit/web-model",
3
- "version": "1.0.1",
4
- "description": "Ricostruzione dei modelli tipizzati dal JSON: BaseModel e i decoratori di esposizione.",
3
+ "version": "1.0.2",
4
+ "description": "Typed model reconstruction from JSON: BaseModel and the expose decorators for dates and nested models.",
5
5
  "author": "Quantic Digit S.R.L.",
6
6
  "license": "SEE LICENSE IN LICENSE.txt",
7
7
  "homepage": "https://www.quanticdigit.it/",