-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from antongolub/add-ts-libdefs
feat: add TS libdefs
- Loading branch information
Showing
4 changed files
with
4,613 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/// <reference types="node" /> | ||
|
||
import { | ||
Change, | ||
Control, | ||
createClient as _createClient, | ||
SearchCallbackResponse, | ||
SearchEntryObject, | ||
SearchOptions, | ||
SearchReference | ||
} from 'ldapjs' | ||
|
||
import {EventEmitter} from 'events' | ||
|
||
export * from 'ldapjs' | ||
|
||
export interface Client extends EventEmitter { | ||
// connected: boolean | ||
|
||
bind(dn: string, password: string, controls?: Control | Array<Control>): Promise<void> | ||
|
||
add(name: string, entry: Object, controls?: Control | Array<Control>): Promise<void> | ||
|
||
compare(name: string, attr: string, value: string, controls?: Control | Array<Control>): Promise<boolean | undefined> | ||
|
||
del(name: string, controls?: Control | Array<Control>): Promise<void> | ||
|
||
exop(name: string, value: string, controls?: Control | Array<Control>): Promise<{ | ||
value: string, | ||
response: any | ||
}> | ||
|
||
modify(name: string, change: Change | Array<Change>, controls?: Control | Array<Control>): Promise<void> | ||
|
||
modifyDN(name: string, newName: string, controls?: Control | Array<Control>): Promise<void> | ||
|
||
search(base: string, options?: SearchOptions, controls?: Control | Array<Control>): Promise<SearchCallbackResponse> | ||
|
||
starttls(options: Object, controls?: Control | Array<Control>): Promise<void> | ||
|
||
unbind(): Promise<void> | ||
|
||
destroy(err?: any): Promise<void> | ||
|
||
// Additional methods | ||
searchReturnAll(base: string, options?: SearchOptions, controls?: Control | Array<Control>): Promise<{ | ||
entries: Array<SearchEntryObject>, | ||
referrals: Array<SearchReference> | ||
}> | ||
|
||
findUser(base: string, username: string, options?: SearchOptions): Promise<any> | ||
|
||
userInGroup(base: string, username: string, groupName: string): Promise<boolean> | ||
} | ||
|
||
export declare const createClient: { | ||
(...args: Parameters<typeof _createClient>): Promise<Client> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import {expectType} from 'tsd' | ||
import { | ||
createClient, | ||
Client, | ||
Change, | ||
SearchCallbackResponse, | ||
SearchEntryObject, | ||
SearchReference | ||
} from '.' | ||
|
||
expectType<Promise<Client>>(createClient()) | ||
|
||
const client = await createClient() | ||
|
||
expectType<Promise<void>>(client.bind('cn=foo', 'bar')) | ||
expectType<Promise<void>>(client.bind('cn=foo', 'bar', {})) | ||
expectType<Promise<void>>(client.bind('cn=foo', 'bar', [])) | ||
expectType<Promise<void>>(client.bind('cn=foo', 'bar', [{}])) | ||
|
||
expectType<Promise<void>>(client.add('cn=foo', {})) | ||
expectType<Promise<void>>(client.add('cn=foo', {}, [])) | ||
expectType<Promise<void>>(client.add('cn=foo', {}, {})) | ||
|
||
expectType<Promise<boolean | undefined>>(client.compare('cn=foo', 'bar', 'baz')) | ||
expectType<Promise<boolean | undefined>>(client.compare('cn=foo', 'bar', 'baz', {})) | ||
expectType<Promise<boolean | undefined>>(client.compare('cn=foo', 'bar', 'baz', [])) | ||
|
||
expectType<Promise<void>>(client.del('cn=foo')) | ||
expectType<Promise<void>>(client.del('cn=foo', {})) | ||
|
||
expectType<Promise<{ value: string, response: any }>>(client.exop('cn=foo', 'bar')) | ||
expectType<Promise<{ value: string, response: any }>>(client.exop('cn=foo', 'bar', {})) | ||
|
||
const change: Change = { | ||
operation: 'op', | ||
modification: {} | ||
} | ||
expectType<Promise<void>>(client.modify('cn=foo', change)) | ||
expectType<Promise<void>>(client.modify('cn=foo', [change])) | ||
expectType<Promise<void>>(client.modify('cn=foo', [change], [])) | ||
|
||
expectType<Promise<void>>(client.modifyDN('cn=foo', 'bar')) | ||
expectType<Promise<void>>(client.modifyDN('cn=foo', 'bar', [])) | ||
|
||
expectType<Promise<SearchCallbackResponse>>(client.search('cn=foo')) | ||
expectType<Promise<SearchCallbackResponse>>(client.search('cn=foo', {scope: 'sub'})) | ||
expectType<Promise<SearchCallbackResponse>>(client.search('cn=foo', {filter: '(objectclass=*)'})) | ||
expectType<Promise<SearchCallbackResponse>>(client.search('cn=foo', {filter: '(objectclass=*)'}, {})) | ||
|
||
expectType<Promise<void>>(client.starttls('cn=foo')) | ||
expectType<Promise<void>>(client.starttls('cn=foo', {})) | ||
|
||
expectType<Promise<void>>(client.unbind()) | ||
|
||
expectType<Promise<void>>(client.destroy()) | ||
expectType<Promise<void>>(client.destroy(new Error())) | ||
|
||
type SearchResult = { | ||
entries: SearchEntryObject[], | ||
referrals: SearchReference[] | ||
} | ||
expectType<Promise<SearchResult>>(client.searchReturnAll('cn=foo')) | ||
expectType<Promise<SearchResult>>(client.searchReturnAll('cn=foo', {scope: 'base'})) | ||
expectType<Promise<SearchResult>>(client.searchReturnAll('cn=foo', {scope: 'base'}, [])) | ||
|
||
expectType<Promise<any>>(client.findUser('cn=foo', 'bar')) | ||
expectType<Promise<any>>(client.findUser('cn=foo', 'bar', {scope: 'sub'})) | ||
|
||
expectType<Promise<boolean>>(client.userInGroup('cn=foo', 'bar', 'baz')) |
Oops, something went wrong.