-
Notifications
You must be signed in to change notification settings - Fork 23
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
No strong types on filters #407
Comments
Hi there! We would also like to have strong types. We were researching some months ago and the permissive type is coming from MongoDB NodeJS driver. You can find more info there:
Basically, they prefer to avoid narrowing the type and prevent issues when evolving MongoDB operators. Is there anything we could do from Papr? Maybe overwrite Filter?. |
@CarlosLozanoHealthCaters I did actually try to overwrite I didn't know about the PR you linked from the |
The main issue is that RootFilterOperators extends from Document. If we are able to overwrite that interface without that extension, everything will work correctly. export declare interface RootFilterOperators<TSchema> extends Document {
$and?: Filter<TSchema>[];
$nor?: Filter<TSchema>[];
$or?: Filter<TSchema>[];
$text?: {
$search: string;
$language?: string;
$caseSensitive?: boolean;
$diacriticSensitive?: boolean;
};
$where?: string | ((this: TSchema) => boolean);
$comment?: string | Document;
}
export declare interface Document {
[key: string]: any;
} |
I did exactly this: I copied the types from |
It would be something like: export declare type PaprFilter<TSchema> = Partial<TSchema> | ({
[Property in Join<NestedPaths<WithId<TSchema>, []>, '.'>]?: Condition<PropertyType<WithId<TSchema>, Property>>;
} & PaprRootFilterOperators<WithId<TSchema>>);
export declare interface PaprRootFilterOperators<TSchema> {
$and?: PaprFilter<TSchema>[];
$nor?: PaprFilter<TSchema>[];
$or?: PaprFilter<TSchema>[];
$text?: {
$search: string;
$language?: string;
$caseSensitive?: boolean;
$diacriticSensitive?: boolean;
};
$where?: string | ((this: TSchema) => boolean);
$comment?: string | Document;
} And then change all reference of Filter by PaprFilter in all internal types in papr and your private repo. Did you have time to check if the errors were due to wrong naming in the filter? |
Here's the branch in question: https://github.com/plexinc/papr/tree/feature/papr-filter-inexistent-fields I'll try to dig up some of those new errors. |
An example of the errors that show up with this branch in our private repo:
The code: await Credit.deleteMany({ 'person._id': person._id }); Part of the schema: const creditSchema = schema({
// ...
person: Types.object(
{
_id: Types.objectId({ required: true }),
name: Types.string(),
slug: Types.string()
},
{ required: true }
),
}); This may be caused by the recursive protections built in the |
I will try to work with that piece of code and check if I can find a solution! |
Related: #410 We just found out about mongodb's plan to remove these default |
Closed in #430 |
Hello!
When using a model function, typescript does not error when using non-existing attributes on the schema.
The text was updated successfully, but these errors were encountered: