index.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
  2. const logger = require('./logger')
  3. const client = require('./client')
  4. const Attribute = require('@ldapjs/attribute')
  5. const Change = require('@ldapjs/change')
  6. const Protocol = require('@ldapjs/protocol')
  7. const Server = require('./server')
  8. const controls = require('./controls')
  9. const persistentSearch = require('./persistent_search')
  10. const dn = require('@ldapjs/dn')
  11. const errors = require('./errors')
  12. const filters = require('@ldapjs/filter')
  13. const messages = require('./messages')
  14. const url = require('./url')
  15. const hasOwnProperty = (target, val) => Object.prototype.hasOwnProperty.call(target, val)
  16. /// --- API
  17. module.exports = {
  18. Client: client.Client,
  19. createClient: client.createClient,
  20. Server,
  21. createServer: function (options) {
  22. if (options === undefined) { options = {} }
  23. if (typeof (options) !== 'object') { throw new TypeError('options (object) required') }
  24. if (!options.log) {
  25. options.log = logger
  26. }
  27. return new Server(options)
  28. },
  29. Attribute,
  30. Change,
  31. dn,
  32. DN: dn.DN,
  33. RDN: dn.RDN,
  34. parseDN: dn.DN.fromString,
  35. persistentSearch,
  36. PersistentSearchCache: persistentSearch.PersistentSearchCache,
  37. filters,
  38. parseFilter: filters.parseString,
  39. url,
  40. parseURL: url.parse
  41. }
  42. /// --- Export all the childrenz
  43. let k
  44. for (k in Protocol) {
  45. if (hasOwnProperty(Protocol, k)) { module.exports[k] = Protocol[k] }
  46. }
  47. for (k in messages) {
  48. if (hasOwnProperty(messages, k)) { module.exports[k] = messages[k] }
  49. }
  50. for (k in controls) {
  51. if (hasOwnProperty(controls, k)) { module.exports[k] = controls[k] }
  52. }
  53. for (k in filters) {
  54. if (hasOwnProperty(filters, k)) {
  55. if (k !== 'parse' && k !== 'parseString') { module.exports[k] = filters[k] }
  56. }
  57. }
  58. for (k in errors) {
  59. if (hasOwnProperty(errors, k)) {
  60. module.exports[k] = errors[k]
  61. }
  62. }