Conversation
thanks to DefinitelyTyped/DefinitelyTyped#65416 for the initial version
| STANDARD: string; | ||
| }; | ||
|
|
||
| export const RuleTypes: { |
There was a problem hiding this comment.
I guess it should be an enum or union type. I do not know which will be compatible with the Rust library. At least it is enum here: https://docs.rs/adblock/latest/adblock/lists/enum.RuleTypes.html
For now, it is an object with all required fields and it can not be used to parse only some types of rules
Line 103 in dc2a4fa
There was a problem hiding this comment.
hmm, after some reading (1, 2), my understanding is that enums shouldn't be declared in a .d.ts file.
This seems correct to me because it's describing the shape of (await import('adblock-rs')).RuleTypes, which basically behaves like a struct with those 3 fields.
Perhaps there is an issue with using rule_types: typeof RuleTypes in ParseOptions instead? I think it needs to be "field of" rather than typeof, but I don't know how to express that.
There was a problem hiding this comment.
Maybe you can use keyof typeof RyleTypes or union type like here:
#343 (comment)
| export class Engine { | ||
| constructor(rules: FilterSet, debug: boolean); | ||
| addResource(resource: Resource): boolean; | ||
| check(url: string, source_url: string, request_type: string, debug?: false): boolean; |
There was a problem hiding this comment.
Also, request_type is enum in Rust. So, I think it should be enum here too.
https://docs.rs/adblock/latest/adblock/request/enum.RequestType.html
There was a problem hiding this comment.
technically, although the enum isn't currently used in any public-facing Rust API. Those functions just accept string arguments. I do want to change that but it'll have to be left to a breaking change in the future.
There was a problem hiding this comment.
Maybe we can deal with union type here:
type RequestType =
| 'beacon'
| 'csp'
| 'document'
| 'dtd'
| 'fetch'
| 'font'
| 'image'
| 'media'
| 'object'
| 'other'
| 'ping'
| 'script'
| 'stylesheet'
| 'subdocument'
| 'websocket'
| 'xlst'
| 'xmlhttprequest';For reference see different implementations from other adblockers:
| constructor(rules: FilterSet, debug: boolean); | ||
| addResource(resource: Resource): boolean; | ||
| check(url: string, source_url: string, request_type: string, debug?: false): boolean; | ||
| check(url: string, source_url: string, request_type: string, debug: true): BlockerResult; |
There was a problem hiding this comment.
Nit: we can pass an object (aka named parameters) instead of passing 4 parameters separately, and then we will have a better user experience.
There was a problem hiding this comment.
sounds like that's a breaking change as well, so I'll leave it as-is for now
|
@antonok-edm If you need some help to finish this PR you can ping me here |
closes #340
@darahe does this look good to you?