Skip to content

Commit f6a65ec

Browse files
committed
Writing cat transformation via models examples
1 parent 0afbc84 commit f6a65ec

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

README.md

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
1-
# Nitro starter
1+
# Working with models and named constructors
22

3-
Look at the [nitro quick start](https://nitro.build/guide#quick-start) to learn more how to get started.
4-
# nitro-models-validation-and-transformation-Public
3+
## Example of Cat transformation
4+
5+
Cat Models:
6+
- [CatRemote](cat/models/cat.remote.ts)
7+
- [Cat](cat/models/cat.ts)
8+
9+
```typescript
10+
const remoteResponse = { id: 1, name: 'Whiskers', age: 18, breed: 'Siamese' }
11+
12+
// Create CatRemote
13+
const verifiedAndTypesafeRemoteCat = CatRemote.create(remoteResponse);
14+
console.log(verifiedAndTypesafeRemoteCat);
15+
// Output:
16+
// CatRemote { id: 1, name: 'Whiskers', age: 18, breed: 'Siamese' }
17+
18+
// Create Cat
19+
const verifiedAndTypesafeCatSentToClient = Cat.create(verifiedAndTypesafeRemoteCat);
20+
console.log(verifiedAndTypesafeCatSentToClient);
21+
// Output:
22+
// Cat { name: 'Whiskers', ageCategory: 'Senior', breed: 'Siamese' }
23+
```

0 commit comments

Comments
 (0)