mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-18 12:08:59 +08:00
Merge pull request #23297 from jefff/add-ldapjs-filters
[ldapjs] Add definitions for Filters
This commit is contained in:
45
types/ldapjs/index.d.ts
vendored
45
types/ldapjs/index.d.ts
vendored
@@ -52,7 +52,7 @@ export interface ClientOptions {
|
||||
|
||||
export interface SearchOptions {
|
||||
scope?: string;
|
||||
filter?: string;
|
||||
filter?: string | Filter;
|
||||
attributes?: string[];
|
||||
sizeLimit?: number;
|
||||
timeLimit?: number;
|
||||
@@ -238,3 +238,46 @@ export interface Client extends EventEmitter {
|
||||
}
|
||||
|
||||
export function createClient(options?: ClientOptions): Client;
|
||||
|
||||
declare class Filter {
|
||||
matches(obj: any): boolean;
|
||||
type: string;
|
||||
}
|
||||
|
||||
export function parseFilter(filterString: string): Filter;
|
||||
|
||||
export class EqualityFilter extends Filter {
|
||||
constructor(options: { attribute: string, value: string })
|
||||
}
|
||||
|
||||
export class PresenceFilter extends Filter {
|
||||
constructor(options: { attribute: string })
|
||||
}
|
||||
|
||||
export class SubstringFilter extends Filter {
|
||||
constructor(options: { attribute: string, initial: string, any?: string[], final?: string })
|
||||
}
|
||||
|
||||
export class GreaterThanEqualsFilter extends Filter {
|
||||
constructor(options: { attribute: string, value: string })
|
||||
}
|
||||
|
||||
export class LessThanEqualsFilter extends Filter {
|
||||
constructor(options: { attribute: string, value: string })
|
||||
}
|
||||
|
||||
export class AndFilter extends Filter {
|
||||
constructor(options: { filters: Filter[] })
|
||||
}
|
||||
|
||||
export class OrFilter extends Filter {
|
||||
constructor(options: { filters: Filter[] })
|
||||
}
|
||||
|
||||
export class NotFilter extends Filter {
|
||||
constructor(options: { filter: Filter })
|
||||
}
|
||||
|
||||
export class ApproximateFilter extends Filter {
|
||||
constructor(options: { attribute: string, value: string })
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import ldap = require("ldapjs");
|
||||
|
||||
let client = ldap.createClient({
|
||||
url: 'ldap://127.0.0.1:1389'
|
||||
url: 'ldap://127.0.0.1:1389'
|
||||
});
|
||||
|
||||
client.bind('cn=root', 'secret', (err: Error): void => {
|
||||
@@ -10,9 +10,9 @@ client.bind('cn=root', 'secret', (err: Error): void => {
|
||||
});
|
||||
|
||||
let opts: ldap.SearchOptions = {
|
||||
filter: '(&(l=Seattle)(email=*@foo.com))',
|
||||
scope: 'sub',
|
||||
attributes: ['dn', 'sn', 'cn']
|
||||
filter: '(&(l=Seattle)(email=*@foo.com))',
|
||||
scope: 'sub',
|
||||
attributes: ['dn', 'sn', 'cn']
|
||||
};
|
||||
|
||||
client.search('o=example', opts, (err: Error, res: NodeJS.EventEmitter): void => {
|
||||
@@ -20,12 +20,89 @@ client.search('o=example', opts, (err: Error, res: NodeJS.EventEmitter): void =>
|
||||
});
|
||||
|
||||
let change = new ldap.Change({
|
||||
operation: 'add',
|
||||
modification: {
|
||||
pets: ['cat', 'dog']
|
||||
}
|
||||
operation: 'add',
|
||||
modification: {
|
||||
pets: ['cat', 'dog']
|
||||
}
|
||||
});
|
||||
|
||||
client.modify('cn=foo, o=example', change, function(err) {
|
||||
// nothing
|
||||
client.modify('cn=foo, o=example', change, function (err) {
|
||||
// nothing
|
||||
});
|
||||
|
||||
|
||||
let f = ldap.parseFilter('(objectclass=*)');
|
||||
f.matches({});
|
||||
|
||||
let equalityFilter = new ldap.EqualityFilter({
|
||||
attribute: 'cn',
|
||||
value: 'foo'
|
||||
});
|
||||
equalityFilter.matches({ cn: 'foo' });
|
||||
|
||||
let presenceFilter = new ldap.PresenceFilter({
|
||||
attribute: 'cn'
|
||||
});
|
||||
presenceFilter.matches({ cn: 'foo' });
|
||||
|
||||
let substringFilter = new ldap.SubstringFilter({
|
||||
attribute: 'cn',
|
||||
initial: 'foo',
|
||||
any: ['bar'],
|
||||
final: 'baz'
|
||||
});
|
||||
substringFilter.matches({ cn: 'foobigbardogbaz' });
|
||||
|
||||
let greaterThanEqualsFilter = new ldap.GreaterThanEqualsFilter({
|
||||
attribute: 'cn',
|
||||
value: 'foo',
|
||||
});
|
||||
greaterThanEqualsFilter.matches({ cn: 'foobar' });
|
||||
|
||||
let lessThanEqualsFilter = new ldap.LessThanEqualsFilter({
|
||||
attribute: 'cn',
|
||||
value: 'foo',
|
||||
});
|
||||
lessThanEqualsFilter.matches({ cn: 'abc' });
|
||||
|
||||
let andFilter = new ldap.AndFilter({
|
||||
filters: [
|
||||
new ldap.EqualityFilter({
|
||||
attribute: 'cn',
|
||||
value: 'foo'
|
||||
}),
|
||||
new ldap.EqualityFilter({
|
||||
attribute: 'sn',
|
||||
value: 'bar'
|
||||
})
|
||||
]
|
||||
});
|
||||
andFilter.matches({ cn: 'foo', sn: 'bar' });
|
||||
|
||||
let orFilter = new ldap.OrFilter({
|
||||
filters: [
|
||||
new ldap.EqualityFilter({
|
||||
attribute: 'cn',
|
||||
value: 'foo'
|
||||
}),
|
||||
new ldap.EqualityFilter({
|
||||
attribute: 'sn',
|
||||
value: 'bar'
|
||||
})
|
||||
]
|
||||
});
|
||||
orFilter.matches({ cn: 'foo', sn: 'baz' });
|
||||
|
||||
let notFilter = new ldap.NotFilter({
|
||||
filter: new ldap.EqualityFilter({
|
||||
attribute: 'cn',
|
||||
value: 'foo'
|
||||
})
|
||||
});
|
||||
notFilter.matches({ cn: 'bar' });
|
||||
|
||||
let approximateFilter = new ldap.ApproximateFilter({
|
||||
attribute: 'cn',
|
||||
value: 'foo'
|
||||
});
|
||||
approximateFilter.matches({ cn: 'foo' });
|
||||
|
||||
Reference in New Issue
Block a user