[Node mongo] - Add omitting private fields feature#399
[Node mongo] - Add omitting private fields feature#399jskiller1404 wants to merge 6 commits intomainfrom
Conversation
fruneen
left a comment
There was a problem hiding this comment.
@jskiller1404 oh, we thought about different implantations.
I see this feature as saving current method 'getPublic', details are in this ticket: https://github.com/orgs/paralect/projects/1?pane=issue&itemId=62396152
f39e87e to
755b8ea
Compare
There was a problem hiding this comment.
that features will be on node-mongo beta right now, could you please rollback it?
When I publish changes, I will add these changes to the doc
packages/node-mongo/src/service.ts
Outdated
| getPublic = <U extends T = T>(doc: U | null): Partial<U> | null => { | ||
| return omitPrivateFields<U>(doc, this.options.privateFields || []); | ||
| }; |
There was a problem hiding this comment.
could you please play with return type?
Ideally, If you pass a user with type { _id: string, password: string } and private fields ['password'] return type should be { _id: string } (accessing 'password' field should cause error)
also try to implement types overloading when you pass null, here is high-level example:
interface MyObject {
foo: string;
bar: number;
}
// Modified type example
interface ModifiedObject {
foo: string;
bar: number;
baz: boolean;
}
// Overloads
function processObj(obj: null): null;
function processObj(obj: MyObject): ModifiedObject;
// Implementation (single signature)
function processObj(obj: MyObject | null): ModifiedObject | null {
if (obj === null) return null;
// Modify object as needed
return { ...obj, baz: true };
}
a1cd5dd to
0e0c6f6
Compare
0e0c6f6 to
bf6db6d
Compare
fruneen
left a comment
There was a problem hiding this comment.
Great job!
I'll merge it after testing on my side with new release version of node-mongo
No description provided.