-
Notifications
You must be signed in to change notification settings - Fork 76
[Node mongo] - Add omitting private fields feature #399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[Node mongo] - Add omitting private fields feature #399
Conversation
fruneen
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job!
I'll merge it after testing on my side with new release version of node-mongo
No description provided.