Skip to content

Commit be2b875

Browse files
authoredFeb 25, 2021
Merge branch 'master' into bugfix_typos
2 parents 9fb353c + 6719469 commit be2b875

13 files changed

+1314
-1114
lines changed
 

‎docs/branding/footer.html.in

+2-46
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,7 @@
11
</div><!-- end #content -->
22

3-
<script type="text/javascript" charset="utf-8">
4-
$(function() {
5-
var headerHeight = $("#header").height();
6-
var offsets = [];
7-
var current = -1;
8-
9-
function endpoint(scrollDistance) {
10-
if (scrollDistance < offsets[0]) {
11-
return -1;
12-
} else {
13-
for (var id = offsets.length; id > 0; id--) {
14-
if (scrollDistance > offsets[id - 1]) {
15-
return id - 1;
16-
break;
17-
}
18-
}
19-
}
20-
}
21-
22-
$("h2").each(function(i) {
23-
offsets.push($(this).offset().top - headerHeight)
24-
});
25-
26-
$("#content").append('<h2 class="fixed" style="display: none"><span>&nbsp;</span></h2>');
27-
var fixed_h2 = $("h2.fixed");
28-
var fixed_span = $("h2.fixed span");
29-
30-
$("#content").scroll(function() {
31-
var scrollDistance = $("#content").attr('scrollTop');
32-
var now = endpoint(scrollDistance);
33-
34-
if (now !== current) {
35-
$("#sidebar li").removeClass("current");
36-
current = now;
37-
if (current < 0) {
38-
fixed_h2.hide();
39-
} else if (current >= 0) {
40-
var heading = $($("h2 span")[current]).text();
41-
$("#sidebar a[href|=#" + heading.replace(' ', '-') + "]").parent().addClass("current");
42-
fixed_span.text(heading);
43-
fixed_h2.show();
44-
}
45-
}
46-
});
47-
});
48-
</script>
3+
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
4+
<script type="text/javascript" src="media/js/script.js"></script>
495

506
</body>
517
</html>

‎docs/branding/header.html.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<title>%(title)s</title>
55
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
66
<link rel="stylesheet" type="text/css" href="media/css/style.css">
7-
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
7+
<link rel="stylesheet" type="text/css" href="media/css/highlight.css">
88
</head>
99
<body>
1010
<div id="header">

‎docs/branding/media/js/script.js

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
2+
/* eslint-disable */
3+
4+
$(function() {
5+
var headerHeight = $("#header").height();
6+
var offsets = [];
7+
var current = -1;
8+
9+
function endpoint(scrollDistance) {
10+
if (scrollDistance < offsets[0]) {
11+
return -1;
12+
} else {
13+
for (var id = offsets.length; id > 0; id--) {
14+
if (scrollDistance > offsets[id - 1]) {
15+
return id - 1;
16+
break;
17+
}
18+
}
19+
}
20+
}
21+
22+
$("h2").each(function(i) {
23+
offsets.push($(this).offset().top - headerHeight)
24+
});
25+
26+
$("#content").append('<h2 class="fixed" style="display: none"><span>&nbsp;</span></h2>');
27+
var fixed_h2 = $("h2.fixed");
28+
var fixed_span = $("h2.fixed span");
29+
30+
$("#content").scroll(function() {
31+
var scrollDistance = $("#content").attr('scrollTop');
32+
var now = endpoint(scrollDistance);
33+
34+
if (now !== current) {
35+
$("#sidebar li").removeClass("current");
36+
current = now;
37+
if (current < 0) {
38+
fixed_h2.hide();
39+
} else if (current >= 0) {
40+
var heading = $($("h2 span")[current]).text();
41+
$("#sidebar a[href|=#" + heading.replace(' ', '-') + "]").parent().addClass("current");
42+
fixed_span.text(heading);
43+
fixed_h2.show();
44+
}
45+
}
46+
});
47+
});

‎docs/client.md

+157-127
Large diffs are not rendered by default.

‎docs/dn.md

+38-28
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ The `parseDN` API converts a string representation of a DN into an ldapjs DN
2626
object; in most cases this will be handled for you under the covers of the
2727
ldapjs framework, but if you need it, it's there.
2828

29-
var parseDN = require('ldapjs').parseDN;
29+
```js
30+
const parseDN = require('ldapjs').parseDN;
3031

31-
var dn = parseDN('cn=foo+sn=bar, ou=people, o=example');
32-
console.log(dn.toString());
32+
const dn = parseDN('cn=foo+sn=bar, ou=people, o=example');
33+
console.log(dn.toString());
34+
```
3335

3436
# DN
3537

@@ -41,40 +43,46 @@ APIs are setup to give you a DN object.
4143
Returns a boolean indicating whether 'this' is a child of the passed in dn. The
4244
`dn` argument can be either a string or a DN.
4345

44-
server.add('o=example', function(req, res, next) {
45-
if (req.dn.childOf('ou=people, o=example')) {
46-
...
47-
} else {
48-
...
49-
}
50-
});
46+
```js
47+
server.add('o=example', (req, res, next) => {
48+
if (req.dn.childOf('ou=people, o=example')) {
49+
...
50+
} else {
51+
...
52+
}
53+
});
54+
```
5155

5256
## parentOf(dn)
5357

5458
The inverse of `childOf`; returns a boolean on whether or not `this` is a parent
5559
of the passed in dn. Like `childOf`, can take either a string or a DN.
5660

57-
server.add('o=example', function(req, res, next) {
58-
var dn = parseDN('ou=people, o=example');
59-
if (dn.parentOf(req.dn)) {
60-
...
61-
} else {
62-
...
63-
}
64-
});
61+
```js
62+
server.add('o=example', (req, res, next) => {
63+
const dn = parseDN('ou=people, o=example');
64+
if (dn.parentOf(req.dn)) {
65+
...
66+
} else {
67+
...
68+
}
69+
});
70+
```
6571

6672
## equals(dn)
6773

6874
Returns a boolean indicating whether `this` is equivalent to the passed in `dn`
6975
argument. `dn` can be a string or a DN.
7076

71-
server.add('o=example', function(req, res, next) {
72-
if (req.dn.equals('cn=foo, ou=people, o=example')) {
73-
...
74-
} else {
75-
...
76-
}
77-
});
77+
```js
78+
server.add('o=example', (req, res, next) => {
79+
if (req.dn.equals('cn=foo, ou=people, o=example')) {
80+
...
81+
} else {
82+
...
83+
}
84+
});
85+
```
7886

7987
## parent()
8088

@@ -112,6 +120,8 @@ It accepts the same parameters as `format`.
112120

113121
Returns the string representation of `this`.
114122

115-
server.add('o=example', function(req, res, next) {
116-
console.log(req.dn.toString());
117-
});
123+
```js
124+
server.add('o=example', (req, res, next) => {
125+
console.log(req.dn.toString());
126+
});
127+
```

‎docs/errors.md

+17-15
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,23 @@ a `stack` property correctly set.
1717

1818
In general, you'll be using the errors in ldapjs like:
1919

20-
var ldap = require('ldapjs');
21-
22-
var db = {};
23-
24-
server.add('o=example', function(req, res, next) {
25-
var parent = req.dn.parent();
26-
if (parent) {
27-
if (!db[parent.toString()])
28-
return next(new ldap.NoSuchObjectError(parent.toString()));
29-
}
30-
if (db[req.dn.toString()])
31-
return next(new ldap.EntryAlreadyExistsError(req.dn.toString()));
32-
33-
...
34-
});
20+
```js
21+
const ldap = require('ldapjs');
22+
23+
const db = {};
24+
25+
server.add('o=example', (req, res, next) => {
26+
const parent = req.dn.parent();
27+
if (parent) {
28+
if (!db[parent.toString()])
29+
return next(new ldap.NoSuchObjectError(parent.toString()));
30+
}
31+
if (db[req.dn.toString()])
32+
return next(new ldap.EntryAlreadyExistsError(req.dn.toString()));
33+
34+
...
35+
});
36+
```
3537

3638
I.e., if you just pass them into the `next()` handler, ldapjs will automatically
3739
return the appropriate LDAP error message, and stop the handler chain.

‎docs/examples.md

+427-416
Large diffs are not rendered by default.

‎docs/filters.md

+122-88
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,17 @@ Parses an [RFC2254](http://www.ietf.org/rfc/rfc2254.txt) filter string into an
3434
ldapjs object(s). If the filter is "complex", it will be a "tree" of objects.
3535
For example:
3636

37-
var parseFilter = require('ldapjs').parseFilter;
37+
```js
38+
const parseFilter = require('ldapjs').parseFilter;
3839

39-
var f = parseFilter('(objectclass=*)');
40+
const f = parseFilter('(objectclass=*)');
41+
```
4042

4143
Is a "simple" filter, and would just return a `PresenceFilter` object. However,
4244

43-
var f = parseFilter('(&(employeeType=manager)(l=Seattle))');
45+
```js
46+
const f = parseFilter('(&(employeeType=manager)(l=Seattle))');
47+
```
4448

4549
Would return an `AndFilter`, which would have a `filters` array of two
4650
`EqualityFilter` objects.
@@ -59,13 +63,15 @@ The string syntax for an equality filter is `(attr=value)`.
5963
The `matches()` method will return true IFF the passed in object has a
6064
key matching `attribute` and a value matching `value`.
6165

62-
var f = new EqualityFilter({
63-
attribute: 'cn',
64-
value: 'foo'
65-
});
66+
```js
67+
const f = new EqualityFilter({
68+
attribute: 'cn',
69+
value: 'foo'
70+
});
6671

67-
f.matches({cn: 'foo'}); => true
68-
f.matches({cn: 'bar'}); => false
72+
f.matches({cn: 'foo'}); => true
73+
f.matches({cn: 'bar'}); => false
74+
```
6975

7076
Equality matching uses "strict" type JavaScript comparison, and by default
7177
everything in ldapjs (and LDAP) is a UTF-8 string. If you want comparison
@@ -83,12 +89,14 @@ The string syntax for a presence filter is `(attr=*)`.
8389
The `matches()` method will return true IFF the passed in object has a
8490
key matching `attribute`.
8591

86-
var f = new PresenceFilter({
87-
attribute: 'cn'
88-
});
92+
```js
93+
const f = new PresenceFilter({
94+
attribute: 'cn'
95+
});
8996

90-
f.matches({cn: 'foo'}); => true
91-
f.matches({sn: 'foo'}); => false
97+
f.matches({cn: 'foo'}); => true
98+
f.matches({sn: 'foo'}); => false
99+
```
92100

93101
# SubstringFilter
94102

@@ -102,24 +110,28 @@ optional. The `name` property will be `substring`.
102110
The string syntax for a presence filter is `(attr=foo*bar*cat*dog)`, which would
103111
map to:
104112

105-
{
106-
initial: 'foo',
107-
any: ['bar', 'cat'],
108-
final: 'dog'
109-
}
113+
```js
114+
{
115+
initial: 'foo',
116+
any: ['bar', 'cat'],
117+
final: 'dog'
118+
}
119+
```
110120

111121
The `matches()` method will return true IFF the passed in object has a
112122
key matching `attribute` and the "regex" matches the value
113123

114-
var f = new SubstringFilter({
115-
attribute: 'cn',
116-
initial: 'foo',
117-
any: ['bar'],
118-
final: 'baz'
119-
});
124+
```js
125+
const f = new SubstringFilter({
126+
attribute: 'cn',
127+
initial: 'foo',
128+
any: ['bar'],
129+
final: 'baz'
130+
});
120131

121-
f.matches({cn: 'foobigbardogbaz'}); => true
122-
f.matches({sn: 'fobigbardogbaz'}); => false
132+
f.matches({cn: 'foobigbardogbaz'}); => true
133+
f.matches({sn: 'fobigbardogbaz'}); => false
134+
```
123135

124136
# GreaterThanEqualsFilter
125137

@@ -135,18 +147,22 @@ property and the `name` property will be `ge`.
135147

136148
The string syntax for a ge filter is:
137149

138-
(cn>=foo)
150+
```
151+
(cn>=foo)
152+
```
139153

140154
The `matches()` method will return true IFF the passed in object has a
141155
key matching `attribute` and the value is `>=` this filter's `value`.
142156

143-
var f = new GreaterThanEqualsFilter({
144-
attribute: 'cn',
145-
value: 'foo',
146-
});
157+
```js
158+
const f = new GreaterThanEqualsFilter({
159+
attribute: 'cn',
160+
value: 'foo',
161+
});
147162

148-
f.matches({cn: 'foobar'}); => true
149-
f.matches({cn: 'abc'}); => false
163+
f.matches({cn: 'foobar'}); => true
164+
f.matches({cn: 'abc'}); => false
165+
```
150166

151167
# LessThanEqualsFilter
152168

@@ -159,21 +175,25 @@ Note that the ldapjs schema middleware will do this.
159175

160176
The string syntax for a le filter is:
161177

162-
(cn<=foo)
178+
```
179+
(cn<=foo)
180+
```
163181

164182
The LessThanEqualsFilter will have an `attribute` property, a `value`
165183
property and the `name` property will be `le`.
166184

167185
The `matches()` method will return true IFF the passed in object has a
168186
key matching `attribute` and the value is `<=` this filter's `value`.
169187

170-
var f = new LessThanEqualsFilter({
171-
attribute: 'cn',
172-
value: 'foo',
173-
});
188+
```js
189+
const f = new LessThanEqualsFilter({
190+
attribute: 'cn',
191+
value: 'foo',
192+
});
174193

175-
f.matches({cn: 'abc'}); => true
176-
f.matches({cn: 'foobar'}); => false
194+
f.matches({cn: 'abc'}); => true
195+
f.matches({cn: 'foobar'}); => false
196+
```
177197

178198
# AndFilter
179199

@@ -184,26 +204,30 @@ object will have a `filters` property which is an array of `Filter` objects. The
184204
The string syntax for an and filter is (assuming below we're and'ing two
185205
equality filters):
186206

187-
(&(cn=foo)(sn=bar))
207+
```
208+
(&(cn=foo)(sn=bar))
209+
```
188210

189211
The `matches()` method will return true IFF the passed in object matches all
190212
the filters in the `filters` array.
191213

192-
var f = new AndFilter({
193-
filters: [
194-
new EqualityFilter({
195-
attribute: 'cn',
196-
value: 'foo'
197-
}),
198-
new EqualityFilter({
199-
attribute: 'sn',
200-
value: 'bar'
201-
})
202-
]
203-
});
204-
205-
f.matches({cn: 'foo', sn: 'bar'}); => true
206-
f.matches({cn: 'foo', sn: 'baz'}); => false
214+
```js
215+
const f = new AndFilter({
216+
filters: [
217+
new EqualityFilter({
218+
attribute: 'cn',
219+
value: 'foo'
220+
}),
221+
new EqualityFilter({
222+
attribute: 'sn',
223+
value: 'bar'
224+
})
225+
]
226+
});
227+
228+
f.matches({cn: 'foo', sn: 'bar'}); => true
229+
f.matches({cn: 'foo', sn: 'baz'}); => false
230+
```
207231

208232
# OrFilter
209233

@@ -214,26 +238,30 @@ object will have a `filters` property which is an array of `Filter` objects. The
214238
The string syntax for an or filter is (assuming below we're or'ing two
215239
equality filters):
216240

217-
(|(cn=foo)(sn=bar))
241+
```
242+
(|(cn=foo)(sn=bar))
243+
```
218244

219245
The `matches()` method will return true IFF the passed in object matches *any*
220246
of the filters in the `filters` array.
221247

222-
var f = new OrFilter({
223-
filters: [
224-
new EqualityFilter({
225-
attribute: 'cn',
226-
value: 'foo'
227-
}),
228-
new EqualityFilter({
229-
attribute: 'sn',
230-
value: 'bar'
231-
})
232-
]
233-
});
234-
235-
f.matches({cn: 'foo', sn: 'baz'}); => true
236-
f.matches({cn: 'bar', sn: 'baz'}); => false
248+
```js
249+
const f = new OrFilter({
250+
filters: [
251+
new EqualityFilter({
252+
attribute: 'cn',
253+
value: 'foo'
254+
}),
255+
new EqualityFilter({
256+
attribute: 'sn',
257+
value: 'bar'
258+
})
259+
]
260+
});
261+
262+
f.matches({cn: 'foo', sn: 'baz'}); => true
263+
f.matches({cn: 'bar', sn: 'baz'}); => false
264+
```
237265

238266
# NotFilter
239267

@@ -244,20 +272,24 @@ The `name` property will be `not`.
244272
The string syntax for a not filter is (assuming below we're not'ing an
245273
equality filter):
246274

247-
(!(cn=foo))
275+
```
276+
(!(cn=foo))
277+
```
248278

249279
The `matches()` method will return true IFF the passed in object does not match
250280
the filter in the `filter` property.
251281

252-
var f = new NotFilter({
253-
filter: new EqualityFilter({
254-
attribute: 'cn',
255-
value: 'foo'
256-
})
257-
});
282+
```js
283+
const f = new NotFilter({
284+
filter: new EqualityFilter({
285+
attribute: 'cn',
286+
value: 'foo'
287+
})
288+
});
258289

259-
f.matches({cn: 'bar'}); => true
260-
f.matches({cn: 'foo'}); => false
290+
f.matches({cn: 'bar'}); => true
291+
f.matches({cn: 'foo'}); => false
292+
```
261293

262294
# ApproximateFilter
263295

@@ -274,10 +306,12 @@ The string syntax for an equality filter is `(attr~=value)`.
274306
The `matches()` method will return true IFF the passed in object has a
275307
key matching `attribute` and a value exactly matching `value`.
276308

277-
var f = new ApproximateFilter({
278-
attribute: 'cn',
279-
value: 'foo'
280-
});
309+
```js
310+
const f = new ApproximateFilter({
311+
attribute: 'cn',
312+
value: 'foo'
313+
});
281314

282-
f.matches({cn: 'foo'}); => true
283-
f.matches({cn: 'bar'}); => false
315+
f.matches({cn: 'foo'}); => true
316+
f.matches({cn: 'bar'}); => false
317+
```

‎docs/guide.md

+316-261
Large diffs are not rendered by default.

‎docs/index.md

+25-19
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,36 @@ with HTTP services in node and [restify](http://restify.com).
1717

1818
</div>
1919

20-
var ldap = require('ldapjs');
20+
```js
21+
const ldap = require('ldapjs');
2122

22-
var server = ldap.createServer();
23+
const server = ldap.createServer();
2324

24-
server.search('o=example', function(req, res, next) {
25-
var obj = {
26-
dn: req.dn.toString(),
27-
attributes: {
28-
objectclass: ['organization', 'top'],
29-
o: 'example'
30-
}
31-
};
25+
server.search('o=example', (req, res, next) => {
26+
const obj = {
27+
dn: req.dn.toString(),
28+
attributes: {
29+
objectclass: ['organization', 'top'],
30+
o: 'example'
31+
}
32+
};
3233

33-
if (req.filter.matches(obj.attributes))
34-
res.send(obj);
34+
if (req.filter.matches(obj.attributes))
35+
res.send(obj);
3536

36-
res.end();
37-
});
37+
res.end();
38+
});
3839

39-
server.listen(1389, function() {
40-
console.log('LDAP server listening at %s', server.url);
41-
});
40+
server.listen(1389, () => {
41+
console.log('LDAP server listening at %s', server.url);
42+
});
43+
```
4244

4345
Try hitting that with:
4446

45-
$ ldapsearch -H ldap://localhost:1389 -x -b o=example objectclass=*
47+
```shell
48+
$ ldapsearch -H ldap://localhost:1389 -x -b o=example objectclass=*
49+
```
4650

4751
# Features
4852

@@ -55,7 +59,9 @@ that you can build LDAP over anything you want, not just traditional databases.
5559

5660
# Getting started
5761

58-
$ npm install ldapjs
62+
```shell
63+
$ npm install ldapjs
64+
```
5965

6066
If you're new to LDAP, check out the [guide](guide.html). Otherwise, the
6167
API documentation is:

‎docs/server.md

+144-111
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ with LDAP. If you're not, read the [guide](guide.html) first.
1515

1616
The code to create a new server looks like:
1717

18-
var server = ldap.createServer();
18+
```js
19+
const server = ldap.createServer();
20+
```
1921

2022
The full list of options is:
2123

@@ -68,10 +70,11 @@ available.
6870

6971
Example:
7072

71-
server.listen(389, '127.0.0.1', function() {
72-
console.log('LDAP server listening at: ' + server.url);
73-
});
74-
73+
```js
74+
server.listen(389, '127.0.0.1', function() {
75+
console.log('LDAP server listening at: ' + server.url);
76+
});
77+
```
7578

7679
### Port and Host
7780
`listen(port, [host], [callback])`
@@ -115,14 +118,16 @@ paradigm of programming. Essentially every method is of the form
115118
handlers together by calling `next()` and ordering your functions in the
116119
definition of the route. For example:
117120

118-
function authorize(req, res, next) {
119-
if (!req.connection.ldap.bindDN.equals('cn=root'))
120-
return next(new ldap.InsufficientAccessRightsError());
121+
```js
122+
function authorize(req, res, next) {
123+
if (!req.connection.ldap.bindDN.equals('cn=root'))
124+
return next(new ldap.InsufficientAccessRightsError());
121125

122-
return next();
123-
}
126+
return next();
127+
}
124128

125-
server.search('o=example', authorize, function(req, res, next) { ... });
129+
server.search('o=example', authorize, function(req, res, next) { ... });
130+
```
126131

127132
Note that ldapjs is also slightly different, since it's often going to be backed
128133
to a DB-like entity, in that it also has an API where you can pass in a
@@ -134,23 +139,25 @@ complete implementation of the LDAP protocol over
134139
[Riak](https://github.com/basho/riak). Getting an LDAP server up with riak
135140
looks like:
136141

137-
var ldap = require('ldapjs');
138-
var ldapRiak = require('ldapjs-riak');
139-
140-
var server = ldap.createServer();
141-
var backend = ldapRiak.createBackend({
142-
"host": "localhost",
143-
"port": 8098,
144-
"bucket": "example",
145-
"indexes": ["l", "cn"],
146-
"uniqueIndexes": ["uid"],
147-
"numConnections": 5
148-
});
149-
150-
server.add("o=example",
151-
backend,
152-
backend.add());
153-
...
142+
```js
143+
const ldap = require('ldapjs');
144+
const ldapRiak = require('ldapjs-riak');
145+
146+
const server = ldap.createServer();
147+
const backend = ldapRiak.createBackend({
148+
"host": "localhost",
149+
"port": 8098,
150+
"bucket": "example",
151+
"indexes": ["l", "cn"],
152+
"uniqueIndexes": ["uid"],
153+
"numConnections": 5
154+
});
155+
156+
server.add("o=example",
157+
backend,
158+
backend.add());
159+
...
160+
```
154161

155162
The first parameter to an ldapjs route is always the point in the
156163
tree to mount the handler chain at. The second argument is _optionally_ a
@@ -163,10 +170,12 @@ operation requires specific methods/fields on the request/response
163170
objects. However, there is a `.use()` method availabe, similar to
164171
that on express/connect, allowing you to chain up "middleware":
165172

166-
server.use(function(req, res, next) {
167-
console.log('hello world');
168-
return next();
169-
});
173+
```js
174+
server.use(function(req, res, next) {
175+
console.log('hello world');
176+
return next();
177+
});
178+
```
170179

171180
## Common Request Elements
172181

@@ -210,23 +219,27 @@ the paradigm is something defined like CONSTRAINT\_VIOLATION in the RFC would be
210219
`ConstraintViolationError` in ldapjs. Upon calling `next(new LDAPError())`,
211220
ldapjs will _stop_ calling your handler chain. For example:
212221

213-
server.search('o=example',
214-
function(req, res, next) { return next(); },
215-
function(req, res, next) { return next(new ldap.OperationsError()); },
216-
function(req, res, next) { res.end(); }
217-
);
222+
```js
223+
server.search('o=example',
224+
(req, res, next) => { return next(); },
225+
(req, res, next) => { return next(new ldap.OperationsError()); },
226+
(req, res, next) => { res.end(); }
227+
);
228+
```
218229

219230
In the code snipped above, the third handler would never get invoked.
220231

221232
# Bind
222233

223234
Adds a mount in the tree to perform LDAP binds with. Example:
224235

225-
server.bind('ou=people, o=example', function(req, res, next) {
226-
console.log('bind DN: ' + req.dn.toString());
227-
console.log('bind PW: ' + req.credentials);
228-
res.end();
229-
});
236+
```js
237+
server.bind('ou=people, o=example', (req, res, next) => {
238+
console.log('bind DN: ' + req.dn.toString());
239+
console.log('bind PW: ' + req.credentials);
240+
res.end();
241+
});
242+
```
230243

231244
## BindRequest
232245

@@ -259,11 +272,13 @@ No extra methods above an `LDAPResult` API call.
259272

260273
Adds a mount in the tree to perform LDAP adds with.
261274

262-
server.add('ou=people, o=example', function(req, res, next) {
263-
console.log('DN: ' + req.dn.toString());
264-
console.log('Entry attributes: ' + req.toObject().attributes);
265-
res.end();
266-
});
275+
```js
276+
server.add('ou=people, o=example', (req, res, next) => {
277+
console.log('DN: ' + req.dn.toString());
278+
console.log('Entry attributes: ' + req.toObject().attributes);
279+
res.end();
280+
});
281+
```
267282

268283
## AddRequest
269284

@@ -287,14 +302,16 @@ a standard JavaScript object.
287302
This operation will return a plain JavaScript object from the request that looks
288303
like:
289304

290-
{
291-
dn: 'cn=foo, o=example', // string, not DN object
292-
attributes: {
293-
cn: ['foo'],
294-
sn: ['bar'],
295-
objectclass: ['person', 'top']
296-
}
297-
}
305+
```js
306+
{
307+
dn: 'cn=foo, o=example', // string, not DN object
308+
attributes: {
309+
cn: ['foo'],
310+
sn: ['bar'],
311+
objectclass: ['person', 'top']
312+
}
313+
}
314+
```
298315

299316
## AddResponse
300317

@@ -304,12 +321,14 @@ No extra methods above an `LDAPResult` API call.
304321

305322
Adds a handler for the LDAP search operation.
306323

307-
server.search('o=example', function(req, res, next) {
308-
console.log('base object: ' + req.dn.toString());
309-
console.log('scope: ' + req.scope);
310-
console.log('filter: ' + req.filter.toString());
311-
res.end();
312-
});
324+
```js
325+
server.search('o=example', (req, res, next) => {
326+
console.log('base object: ' + req.dn.toString());
327+
console.log('scope: ' + req.scope);
328+
console.log('filter: ' + req.filter.toString());
329+
res.end();
330+
});
331+
```
313332

314333
## SearchRequest
315334

@@ -367,34 +386,38 @@ explicitly pass in a `SearchEntry` object, and can instead just send a plain
367386
JavaScript object that matches the format used from `AddRequest.toObject()`.
368387

369388

370-
server.search('o=example', function(req, res, next) {
371-
var obj = {
372-
dn: 'o=example',
373-
attributes: {
374-
objectclass: ['top', 'organization'],
375-
o: ['example']
376-
}
377-
};
389+
```js
390+
server.search('o=example', (req, res, next) => {
391+
const obj = {
392+
dn: 'o=example',
393+
attributes: {
394+
objectclass: ['top', 'organization'],
395+
o: ['example']
396+
}
397+
};
378398

379-
if (req.filter.matches(obj))
380-
res.send(obj)
399+
if (req.filter.matches(obj))
400+
res.send(obj)
381401

382-
res.end();
383-
});
402+
res.end();
403+
});
404+
```
384405

385406
# modify
386407

387408
Allows you to handle an LDAP modify operation.
388409

389-
server.modify('o=example', function(req, res, next) {
390-
console.log('DN: ' + req.dn.toString());
391-
console.log('changes:');
392-
req.changes.forEach(function(c) {
393-
console.log(' operation: ' + c.operation);
394-
console.log(' modification: ' + c.modification.toString());
395-
});
396-
res.end();
397-
});
410+
```js
411+
server.modify('o=example', (req, res, next) => {
412+
console.log('DN: ' + req.dn.toString());
413+
console.log('changes:');
414+
for (const c of req.changes) {
415+
console.log(' operation: ' + c.operation);
416+
console.log(' modification: ' + c.modification.toString());
417+
}
418+
res.end();
419+
});
420+
```
398421

399422
## ModifyRequest
400423

@@ -431,10 +454,12 @@ No extra methods above an `LDAPResult` API call.
431454

432455
Allows you to handle an LDAP delete operation.
433456

434-
server.del('o=example', function(req, res, next) {
435-
console.log('DN: ' + req.dn.toString());
436-
res.end();
437-
});
457+
```js
458+
server.del('o=example', (req, res, next) => {
459+
console.log('DN: ' + req.dn.toString());
460+
res.end();
461+
});
462+
```
438463

439464
## DeleteRequest
440465

@@ -451,12 +476,14 @@ No extra methods above an `LDAPResult` API call.
451476

452477
Allows you to handle an LDAP compare operation.
453478

454-
server.compare('o=example', function(req, res, next) {
455-
console.log('DN: ' + req.dn.toString());
456-
console.log('attribute name: ' + req.attribute);
457-
console.log('attribute value: ' + req.value);
458-
res.end(req.value === 'foo');
459-
});
479+
```js
480+
server.compare('o=example', (req, res, next) => {
481+
console.log('DN: ' + req.dn.toString());
482+
console.log('attribute name: ' + req.attribute);
483+
console.log('attribute value: ' + req.value);
484+
res.end(req.value === 'foo');
485+
});
486+
```
460487

461488
## CompareRequest
462489

@@ -483,15 +510,17 @@ that, there are no extra methods above an `LDAPResult` API call.
483510

484511
Allows you to handle an LDAP modifyDN operation.
485512

486-
server.modifyDN('o=example', function(req, res, next) {
487-
console.log('DN: ' + req.dn.toString());
488-
console.log('new RDN: ' + req.newRdn.toString());
489-
console.log('deleteOldRDN: ' + req.deleteOldRdn);
490-
console.log('new superior: ' +
491-
(req.newSuperior ? req.newSuperior.toString() : ''));
513+
```js
514+
server.modifyDN('o=example', (req, res, next) => {
515+
console.log('DN: ' + req.dn.toString());
516+
console.log('new RDN: ' + req.newRdn.toString());
517+
console.log('deleteOldRDN: ' + req.deleteOldRdn);
518+
console.log('new superior: ' +
519+
(req.newSuperior ? req.newSuperior.toString() : ''));
492520

493-
res.end();
494-
});
521+
res.end();
522+
});
523+
```
495524

496525
## ModifyDNRequest
497526

@@ -525,14 +554,16 @@ OID, but ldapjs makes no such restrictions; it just needs to be a string.
525554
Unlike the other operations, extended operations don't map to any location in
526555
the tree, so routing here will be exact match, as opposed to subtree.
527556

528-
// LDAP whoami
529-
server.exop('1.3.6.1.4.1.4203.1.11.3', function(req, res, next) {
530-
console.log('name: ' + req.name);
531-
console.log('value: ' + req.value);
532-
res.value = 'u:xxyyz@EXAMPLE.NET';
533-
res.end();
534-
return next();
535-
});
557+
```js
558+
// LDAP whoami
559+
server.exop('1.3.6.1.4.1.4203.1.11.3', (req, res, next) => {
560+
console.log('name: ' + req.name);
561+
console.log('value: ' + req.value);
562+
res.value = 'u:xxyyz@EXAMPLE.NET';
563+
res.end();
564+
return next();
565+
});
566+
```
536567

537568
## ExtendedRequest
538569

@@ -563,9 +594,11 @@ and cleans up any internals (in ldapjs core). You can override this handler
563594
if you need to clean up any items in your backend, or perform any other cleanup
564595
tasks you need to.
565596

566-
server.unbind(function(req, res, next) {
567-
res.end();
568-
});
597+
```js
598+
server.unbind((req, res, next) => {
599+
res.end();
600+
});
601+
```
569602

570603
Note that the LDAP unbind operation actually doesn't send any response (by
571604
definition in the RFC), so the UnbindResponse is really just a stub that

‎package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@
2727
"verror": "^1.8.1"
2828
},
2929
"devDependencies": {
30-
"eslint": "^7.14.0",
30+
"eslint": "^7.20.0",
3131
"eslint-config-standard": "^16.0.2",
3232
"eslint-plugin-import": "^2.22.1",
3333
"eslint-plugin-node": "^11.1.0",
34-
"eslint-plugin-promise": "^4.2.1",
34+
"eslint-plugin-promise": "^4.3.1",
3535
"front-matter": "^4.0.2",
3636
"get-port": "^5.1.1",
37+
"highlight.js": "^10.6.0",
3738
"husky": "^4.2.5",
3839
"marked": "^2.0.0",
3940
"tap": "14.11.0"

‎scripts/build-docs.js

+15
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@ const fs = require('fs/promises')
22
const path = require('path')
33
const marked = require('marked')
44
const fm = require('front-matter')
5+
const { highlight } = require('highlight.js')
6+
7+
marked.use({
8+
highlight: (code, lang) => {
9+
if (lang) {
10+
return highlight(lang, code).value
11+
}
12+
13+
return code
14+
}
15+
})
516

617
function tocHTML (toc) {
718
let html = '<ul>\n'
@@ -92,10 +103,14 @@ async function createDocs () {
92103

93104
const dest = path.join(dist, 'media')
94105
const src = path.join(branding, 'media')
106+
const highlightjsStyles = path.resolve(__dirname, '..', 'node_modules', 'highlight.js', 'styles')
95107
await fs.mkdir(dest)
96108
await fs.mkdir(path.join(dest, 'css'))
109+
await fs.mkdir(path.join(dest, 'js'))
97110
await fs.mkdir(path.join(dest, 'img'))
98111
await fs.copyFile(path.join(src, 'css', 'style.css'), path.join(dest, 'css', 'style.css'))
112+
await fs.copyFile(path.join(highlightjsStyles, 'default.css'), path.join(dest, 'css', 'highlight.css'))
113+
await fs.copyFile(path.join(src, 'js', 'script.js'), path.join(dest, 'js', 'script.js'))
99114
await fs.copyFile(path.join(src, 'img', 'logo.svg'), path.join(dest, 'img', 'logo.svg'))
100115
await fs.copyFile(path.join(branding, 'CNAME'), path.join(dist, 'CNAME'))
101116
}

0 commit comments

Comments
 (0)
Please sign in to comment.