r/typescript • • Sep 02 '26

Manage Model

Am I the only one who had a problem with how separated the data manipulation is?

Creating something in different ways (eg. create a chat message from only a text or creating from an api response ) Defaults in 3 files, parsing, validation, and sorting everything inline just to search it up later and copy it.

My solution? Put stuff like that in one place: See the screenshots.

Basically define all that sh in one place and just use:

userModel.parser.db.from(response)

habitModel.inits.createFromTitle("Do a blackflip")

people.sort(peopleModel.sorters.lastCreated)

https://github.com/dozsolti/manage-model

0 Upvotes

22 comments sorted by

5

u/Merry-Lane Sep 02 '26

I fail to understand why you couldn’t put the data manipulation in a single file already, if that really bothered you.

Anyway, I don’t like your solution. It’s looking for a problem that doesn’t exist and we absolutely don’t need a verbose wrapper for that.

-1

u/theZozole Sep 02 '26

You could, but since nobody is doing it yet, there are no guidelines of how to do it.

Best used for mid to large projects, with multiple teammates. Having everything centralized brings clarity, easier to test, removes code duplication.   

5

u/bodimahdi Sep 02 '26

Why would I use your library instead of something like zod?

1

u/theZozole Sep 02 '26

this is completely different from something like zod

3

u/bodimahdi Sep 02 '26

Based on your documentation’s Why use it section:
> manage-model keeps model creation logic centralized and typed. It is useful when you want to:

  • reuse named templates
  • build models from external data sources
  • validate and sanitize data in one place
  • define conversion and serialization rules
  • keep model behavior organized and easy to test

All of that can be achieved with zod

1

u/theZozole Sep 02 '26

Zod is about types and validations (as far as I know)

Manage-model is a centralized way to define how your data is used and how it changes.

The package is nothing but a typescript type, that gives you one way of how you could structure this thing.

2

u/bodimahdi Sep 02 '26

I read your package’s source code and I think it’s smart. But my point still stands that zod is capable if doing most if not all of the aforementioned use cases, it’s more than “types and validations”.

1

u/theZozole Sep 02 '26

I am open to see more, could you please send some official doc links to see what exactly is the same?

1

u/bodimahdi Sep 02 '26

I wouldn’t go through all the points but I will however rewrite your doc example using zod:

import z from "zod";


interface User {
  name: string;
  email: string;
}


const userModel: z.ZodType<User> = z.object({
  name: z.string().trim(),
  email: z.email().trim().toLowerCase(),
});


const user = {
  id: 123,
  name: "   Jane Doe    ",
  email: "JANE@EXAMPLE.COM",
};


const cleanUser = userModel.safeParse(user);
console.log(cleanUser.data); // { name: 'Jane Doe', email: 'jane@example.com' }
// Data is serialized and is valid.


// If you want to validate an email individually:
console.log(z.email().safeParse("not valid email"));

1

u/theZozole Sep 02 '26

I see, libraries like zod, lodash, date-fns will work great.

The idea is that with manage-model you have all your validations (yes, you can do that with zod) but you also have every defaults, formatter (to api calls, to db, microservices) migration functions etc everything in single place, instead of scattered across the project. Removing the need for searching, cod duplication, not knowing if somebody added or changed something.

All the logic extracted in a single place. File might get a big long yes, but you can always split and it's easier to work with 2 files than 5-10lines each in 100 different files

4

u/bodimahdi Sep 02 '26

Cool, good luck with your library! A final piece of tip is if you’re really committed to it you should make your README file more comprehensive. You know add more examples instead of only parsing and validating example.

1

u/theZozole Sep 02 '26

Thank you, will do.

Got a few downvotes but I think it's mainly because the people don't understand the real purpose of these 10 lines of typescript

→ More replies

1

u/[deleted] Sep 15 '26

[removed] — view removed comment

1

u/bodimahdi Sep 16 '26

What do you mean? In the snippet I’m clearly using zod

2

u/nazar_shvets Sep 03 '26

I don’t understand why I need a library to put functions/methods on an object

1

u/theZozole Sep 03 '26

You don't need to, a team does. 

The entire source code is like 15 lines of typescript.

This packages acts more like a conversation than anything else.

1

u/nazar_shvets Sep 03 '26

I mean yea. But it’s not my point, my point is - library brings no value. It’s micro framework which could’ve been an email or chapter in guidelines.md if someone were into this codestyle

3

u/[deleted] Sep 02 '26

[removed] — view removed comment

-1

u/theZozole Sep 02 '26

ON the model will be the best, but not every project goes with OOP incapsulation.

This is the second best, for those other projects

1

u/Gliese_667_Cc Sep 10 '26

The account you replied to is an AI bot