Feat/#203 support nullable nested objects
This is regarding issue #203
I have extended the existing ModelValueType and the function isModelValueType to allow for object type.
I also added a new test case covering the scenario described in #203 .
It was indeed failing at the beginning, the object would be null no matter whether or not you passed to create an existing object.
This was caused by isModelValueType that would return false if the object was not a Primitive or an Array of Primitives.
The test is now passing, and I've also tested it manually.
Note that this is my PR for this project and unfortunately the tests were not all green out of the box. So I manually checked where these functions/types were used to ensure I didn't break existing functionalities.
Please don't hesitate to let me know if anything needs to be changed.
Nice one, can we get it merged?
Hi there! 👋 I've also tried to tackle that one. I think that there may be some parts missing, when for example we'd like to have some default value for nullable object property
const db = factory({
user: {
id: primaryKey(faker.datatype.uuid),
address: nullable(() => ({
street: () => "Wall Street",
number: nullable<number>(() => null),
})),
},
});
const user = db.user.create();
we may want to have something like
{
"id": "...",
"address": {
"street": "Wall Street",
"number": null
}
}
for user, right?
Also, if you run all tests, you may see that there are some issues with types in test/query/pagination.test.ts.
I created https://github.com/mswjs/data/pull/231 with some investigation I've made some time ago and finished today. Maybe you could take a look there, because you're familiar with the problem and we could figure out some working solution together?
Hi @roertbb, sorry I was quite busy, I'll have a look at your code and get back to you ASAP :+1:
Hi, Any progress on this one? It would really upgrade this already amazing package :) Thanks !!