Skip to content

Commit 4f1d49a

Browse files
authored
Merge pull request #76 from ifwe/update-monocle-api
monocle api 2.0.0: Update dependencies, add typescript checks
2 parents 39770e5 + 56025e8 commit 4f1d49a

18 files changed

+1090
-731
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ test/coverage.html
44
coverage/
55
npm-debug.log
66
.idea
7+
.*.swp
8+
.*.swo

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
language: node_js
22
node_js:
3-
- "5.11"
3+
- "6"
4+
- "8"
5+
- "10"
46
before_script:
57
- npm install -g grunt-cli

Gruntfile.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ module.exports = function(grunt) {
1818
coverage: ['test/coverage.html']
1919
},
2020

21+
// https://www.npmjs.com/package/grunt-mocha-test
22+
mochaTest: {
23+
test: {
24+
options: {
25+
reporter: 'spec',
26+
require: './test/test_runner',
27+
ui: 'bdd',
28+
timeout: 200
29+
},
30+
src: ['test/**/*_test.js']
31+
}
32+
},
2133
//Bump up version
2234
bump: {
2335
options: {
@@ -61,8 +73,10 @@ module.exports = function(grunt) {
6173
// Runs all unit tests
6274
grunt.registerTask('test', 'All unit tests', ['mochaTest:test']);
6375

76+
// TODO: Migrate this to https://www.npmjs.com/package/grunt-mocha-test#instrumenting-source-files-with-coverage-data-before-running-tests
6477
// Generates test coverage report
65-
grunt.registerTask('coverage', 'Unit test code coverage', ['clean:coverage', 'mochaTest:instrument', 'mochaTest:coverage']);
78+
// As a substitute, just use `npm test` instead
79+
// grunt.registerTask('coverage', 'Unit test code coverage', ['clean:coverage', 'mochaTest:instrument', 'mochaTest:coverage']);
6680

6781
// Generates documentation
6882
grunt.registerTask('docs', 'Generate documentation', ['clean:docs', 'docco:main']);

lib/CollectionCache.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ CollectionCache.prototype.id = function() {
5050
var props = [].concat(this.request.getProps()).sort();
5151

5252
// 3. Gather all other query string parameters
53-
var query = this.request.getUrl().search
53+
// Note: In node 10, getUrl().search seems like it became optional?
54+
var query = (this.request.getUrl().search || '')
5455
.replace(/^\?/, '') // remove "?" from beginning of string
5556
.split('&') // create array of keyvalue parts
5657
.filter(function(keyvalue) { // filter out "props" query string param
@@ -78,8 +79,8 @@ CollectionCache.prototype.id = function() {
7879
/**
7980
* Verifies an etag. Returns `true` if it matches.
8081
*
81-
* @param string etag - The etag to check.
82-
* @return boolean - True if passes validation.
82+
* @param {string} etag - The etag to check.
83+
* @returns {boolean} - True if passes validation.
8384
*/
8485
CollectionCache.prototype.isValid = function(etag) {
8586
if (!etag) {

lib/Connection.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function Connection(router, req, res) {
2727
].forEach(function(method) {
2828
Connection.prototype[method.toLowerCase()] = function (resourceId, options) {
2929
debug('Incoming request', method, resourceId, options)
30-
var request = new Request(resourceId, this.router, this);
30+
var request = new Request(resourceId);
3131
request.setResourceId(resourceId);
3232
request.setMethod(method);
3333

lib/CursorPaginator.js

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* A CursorPaginator represents an array of items
33
* that can be paginated via offset/limit parameters.
4-
* The items may be Resources, Symlinks, primatives, or any combination.
4+
* The items may be Resources, Symlinks, primitives, or any combination.
55
* CursorPaginator provides a fluent interface to simplify their creation.
66
*
77
* ```js
@@ -45,9 +45,9 @@ var CursorPaginator = function(id, items, expires) {
4545
/**
4646
* Sets the resource ID for this collection.
4747
*
48-
* @param string|undefined - The new resource ID or `undefined` to remove it.
48+
* @param {string|undefined} id - The new resource ID or `undefined` to remove it.
4949
* @throws Error - Provided resource ID is invalid.
50-
* @return this - Fluent interface.
50+
* @returns this - Fluent interface.
5151
*/
5252
CursorPaginator.prototype.setId = function(id) {
5353
var type = typeof id;
@@ -61,7 +61,7 @@ CursorPaginator.prototype.setId = function(id) {
6161
/**
6262
* Gets the resource ID, or undefined if not set.
6363
*
64-
* @return string|undefined - The resource ID for this collection
64+
* @returns string|undefined - The resource ID for this collection
6565
*/
6666
CursorPaginator.prototype.getId = function() {
6767
return this.$id;
@@ -70,10 +70,10 @@ CursorPaginator.prototype.getId = function() {
7070
/**
7171
* Sets the items in the collection.
7272
*
73-
* @param array items - Array of items that are in this collection.
74-
* May be an array of Resources, Symlinks, primatives, or any combination.
73+
* @param {Array} items - Array of items that are in this collection.
74+
* May be an array of Resources, Symlinks, primitives, or any combination.
7575
* @throws Error - When non-array is passed in.
76-
* @return this - Fluent interface.
76+
* @returns this - Fluent interface.
7777
*/
7878
CursorPaginator.prototype.setItems = function(items) {
7979
if (!Array.isArray(items)) {
@@ -86,7 +86,7 @@ CursorPaginator.prototype.setItems = function(items) {
8686
/**
8787
* Gets the items in the collection.
8888
*
89-
* @return array - All items in the collection.
89+
* @returns array - All items in the collection.
9090
*/
9191
CursorPaginator.prototype.getItems = function() {
9292
return this.items;
@@ -95,10 +95,10 @@ CursorPaginator.prototype.getItems = function() {
9595
/**
9696
* Sets the value for an item in the collection.
9797
*
98-
* @param integer position - The array position.
99-
* @param array item - Item to be placed into specified position.
98+
* @param {Number} position - The integer array position.
99+
* @param {Array} item - Item to be placed into specified position.
100100
* @throws Error - Invalid position.
101-
* @return this - Fluent interface.
101+
* @returns this - Fluent interface.
102102
*/
103103
CursorPaginator.prototype.setItem = function(position, item) {
104104
if (typeof position !== 'number') {
@@ -116,8 +116,8 @@ CursorPaginator.prototype.setItem = function(position, item) {
116116
/**
117117
* Returns the value for an item in the collection, or undefined if not set.
118118
*
119-
* @param integer position - The array position.
120-
* @return mixed - The item at the position in the collection or undefined.
119+
* @param {Number} position - The integer array position.
120+
* @returns mixed - The item at the position in the collection or undefined.
121121
*/
122122
CursorPaginator.prototype.getItem = function(position) {
123123
return this.items[position];
@@ -126,9 +126,9 @@ CursorPaginator.prototype.getItem = function(position) {
126126
/**
127127
* Sets the expiration for the collection in milliseconds.
128128
*
129-
* @param integer|undefined - Maximum number of milliseconds this collection may be cached for.
129+
* @param {Number|undefined} expires - Maximum number of milliseconds this collection may be cached for.
130130
* @throws Error - Expiration is invalid.
131-
* @return this - Fluent interface.
131+
* @returns this - Fluent interface.
132132
*/
133133
CursorPaginator.prototype.setExpires = function(expires) {
134134
var type = typeof expires;
@@ -148,7 +148,7 @@ CursorPaginator.prototype.setExpires = function(expires) {
148148
/**
149149
* Returns the expiration for the collection in milliseconds, or undefined if not set.
150150
*
151-
* @return integer|undefined - Maximum number of milliseconds this collection may be cached for.
151+
* @returns integer|undefined - Maximum number of milliseconds this collection may be cached for.
152152
*/
153153
CursorPaginator.prototype.getExpires = function() {
154154
return this.$expires;
@@ -158,9 +158,9 @@ CursorPaginator.prototype.getExpires = function() {
158158
* Sets the total number of items in the collection.
159159
* May be more than the number of items represented.
160160
*
161-
* @param integer total - Number of items in the collection.
161+
* @param {Number} total - Number of items in the collection.
162162
* @throws Error - Total is invalid.
163-
* @return mixed - Total number of items in collection if no argument provided,
163+
* @returns mixed - Total number of items in collection if no argument provided,
164164
* otherwise returns `this` for fluent interface
165165
*/
166166
CursorPaginator.prototype.setTotal = function(total) {
@@ -181,7 +181,7 @@ CursorPaginator.prototype.setTotal = function(total) {
181181
/**
182182
* Returns the total number of items in the collection, or undefined if not set.
183183
*
184-
* @return integer|undefined - Total number of items in the collection
184+
* @returns integer|undefined - Total number of items in the collection
185185
*/
186186
CursorPaginator.prototype.getTotal = function() {
187187
return this.total;
@@ -190,9 +190,9 @@ CursorPaginator.prototype.getTotal = function() {
190190
/**
191191
* Sets the limit of items in the collection, or undefined if no limit is set.
192192
*
193-
* @param integer|undefined limit - Limit of items in the collection.
193+
* @param {Number|undefined} limit - Limit of items in the collection.
194194
* @throws Error - Limit is invalid.
195-
* @return this - Fluent interface.
195+
* @returns this - Fluent interface.
196196
*/
197197
CursorPaginator.prototype.setLimit = function(limit) {
198198
var type = typeof limit;
@@ -212,7 +212,7 @@ CursorPaginator.prototype.setLimit = function(limit) {
212212
/**
213213
* Returns the limit of items in the collection, or undefined if not set.
214214
*
215-
* @return integer|undefined - Limit of items in the collection.
215+
* @returns integer|undefined - Limit of items in the collection.
216216
*/
217217
CursorPaginator.prototype.getLimit = function() {
218218
return this.limit;
@@ -221,8 +221,8 @@ CursorPaginator.prototype.getLimit = function() {
221221
/**
222222
* Sets the current cursor for the items in the collection, or undefined if no cursor exists.
223223
*
224-
* @param string|undefined cursor - Current cursor for items in the collection.
225-
* @return this - Fluent interface.
224+
* @param {String|undefined} cursor - Current cursor for items in the collection.
225+
* @returns this - Fluent interface.
226226
*/
227227
CursorPaginator.prototype.setCursor = function(cursor) {
228228
this.cursor = cursor;
@@ -232,7 +232,7 @@ CursorPaginator.prototype.setCursor = function(cursor) {
232232
/**
233233
* Returns the current cursor for the items in the collection, or undefined if no cursor exists.
234234
*
235-
* @return string|undefined - Current cursor for items in the collection.
235+
* @returns string|undefined - Current cursor for items in the collection.
236236
*/
237237
CursorPaginator.prototype.getCursor = function() {
238238
return this.cursor;
@@ -242,8 +242,8 @@ CursorPaginator.prototype.getCursor = function() {
242242
/**
243243
* Sets the cursor for the next page of items in the collection, or undefined if no next cursor exists.
244244
*
245-
* @param string|undefined nextCursor - Cursor for the next page of items in the collection.
246-
* @return this - Fluent interface.
245+
* @param {String|undefined} nextCursor - Cursor for the next page of items in the collection.
246+
* @returns this - Fluent interface.
247247
*/
248248
CursorPaginator.prototype.setNextCursor = function(nextCursor) {
249249
this.nextCursor = nextCursor;
@@ -253,7 +253,7 @@ CursorPaginator.prototype.setNextCursor = function(nextCursor) {
253253
/**
254254
* Returns the cursor for the next page of items in the collection, or undefined if not set.
255255
*
256-
* @return string|undefined - Cursor for next page of items in the collection.
256+
* @returns string|undefined - Cursor for next page of items in the collection.
257257
*/
258258
CursorPaginator.prototype.getNextCursor = function() {
259259
return this.nextCursor;
@@ -262,7 +262,7 @@ CursorPaginator.prototype.getNextCursor = function() {
262262
/**
263263
* Removes the last item from the collection and returns it.
264264
*
265-
* @return mixed
265+
* @returns any
266266
*/
267267
CursorPaginator.prototype.pop = function() {
268268
return this.items.pop();
@@ -271,8 +271,8 @@ CursorPaginator.prototype.pop = function() {
271271
/**
272272
* Adds the item to the end of the collection.
273273
*
274-
* @param mixed item - The item to add
275-
* @return this - fluent interface
274+
* @param {any} item - The item to add
275+
* @returns {CursorPaginator} - fluent interface
276276
*/
277277
CursorPaginator.prototype.push = function(item) {
278278
this.items.push(item);
@@ -282,7 +282,7 @@ CursorPaginator.prototype.push = function(item) {
282282
/**
283283
* Removes the first item from the collection and returns it.
284284
*
285-
* @return mixed
285+
* @returns mixed
286286
*/
287287
CursorPaginator.prototype.shift = function() {
288288
return this.items.shift();
@@ -291,8 +291,8 @@ CursorPaginator.prototype.shift = function() {
291291
/**
292292
* Adds the item to the beginning of the collection.
293293
*
294-
* @param mixed item - The item to add
295-
* @return this - fluent interface
294+
* @param {any} item - The item to add
295+
* @returns this - fluent interface
296296
*/
297297
CursorPaginator.prototype.unshift = function(item) {
298298
this.items.unshift(item);

lib/OffsetPaginator.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* An OffsetPaginator represents an array of items
33
* that can be paginated via offset/limit parameters.
4-
* The items may be Resources, Symlinks, primatives, or any combination.
4+
* The items may be Resources, Symlinks, primitives, or any combination.
55
* OffsetPaginator provides a fluent interface to simplify their creation.
66
*
77
* ```js
@@ -44,7 +44,7 @@ var OffsetPaginator = function(id, items, expires) {
4444
/**
4545
* Sets the resource ID for this collection.
4646
*
47-
* @param string|undefined - The new resource ID or `undefined` to remove it.
47+
* @param {String|undefined} id - The new resource ID or `undefined` to remove it.
4848
* @throws Error - Provided resource ID is invalid.
4949
* @return this - Fluent interface.
5050
*/
@@ -69,8 +69,8 @@ OffsetPaginator.prototype.getId = function() {
6969
/**
7070
* Sets the items in the collection.
7171
*
72-
* @param array items - Array of items that are in this collection.
73-
* May be an array of Resources, Symlinks, primatives, or any combination.
72+
* @param {Array} items - Array of items that are in this collection.
73+
* May be an array of Resources, Symlinks, primitives, or any combination.
7474
* @throws Error - When non-array is passed in.
7575
* @return this - Fluent interface.
7676
*/
@@ -94,8 +94,8 @@ OffsetPaginator.prototype.getItems = function() {
9494
/**
9595
* Sets the value for an item in the collection.
9696
*
97-
* @param integer position - The array position.
98-
* @param array item - Item to be placed into specified position.
97+
* @param {Number} position - The array position.
98+
* @param {Array} item - Item to be placed into specified position.
9999
* @throws Error - Invalid position.
100100
* @return this - Fluent interface.
101101
*/
@@ -115,7 +115,7 @@ OffsetPaginator.prototype.setItem = function(position, item) {
115115
/**
116116
* Returns the value for an item in the collection, or undefined if not set.
117117
*
118-
* @param integer position - The array position.
118+
* @param {Number} position - The array position.
119119
* @return mixed - The item at the position in the collection or undefined.
120120
*/
121121
OffsetPaginator.prototype.getItem = function(position) {
@@ -125,7 +125,7 @@ OffsetPaginator.prototype.getItem = function(position) {
125125
/**
126126
* Sets the expiration for the collection in milliseconds.
127127
*
128-
* @param integer|undefined - Maximum number of milliseconds this collection may be cached for.
128+
* @param {Number|undefined} expires - Maximum number of milliseconds this collection may be cached for.
129129
* @throws Error - Expiration is invalid.
130130
* @return this - Fluent interface.
131131
*/
@@ -157,7 +157,7 @@ OffsetPaginator.prototype.getExpires = function() {
157157
* Sets the total number of items in the collection.
158158
* May be more than the number of items represented.
159159
*
160-
* @param integer total - Number of items in the collection.
160+
* @param {Number} total - Number of items in the collection.
161161
* @throws Error - Total is invalid.
162162
* @return mixed - Total number of items in collection if no argument provided,
163163
* otherwise returns `this` for fluent interface
@@ -189,7 +189,7 @@ OffsetPaginator.prototype.getTotal = function() {
189189
/**
190190
* Sets the limit of items in the collection, or undefined if no limit is set.
191191
*
192-
* @param integer|undefined limit - Limit of items in the collection.
192+
* @param {Number|undefined} limit - Limit of items in the collection.
193193
* @throws Error - Limit is invalid.
194194
* @return this - Fluent interface.
195195
*/
@@ -220,7 +220,7 @@ OffsetPaginator.prototype.getLimit = function() {
220220
/**
221221
* Sets the offset of items in the collection, or undefined if no offset is set.
222222
*
223-
* @param integer|undefined offset - Offset of items in the collection.
223+
* @param {Number|undefined} offset - Offset of items in the collection.
224224
* @throws Error - Offset is invalid.
225225
* @return this - Fluent interface.
226226
*/
@@ -260,7 +260,7 @@ OffsetPaginator.prototype.pop = function() {
260260
/**
261261
* Adds the item to the end of the collection.
262262
*
263-
* @param mixed item - The item to add
263+
* @param {any} item - The item to add
264264
* @return this - fluent interface
265265
*/
266266
OffsetPaginator.prototype.push = function(item) {
@@ -280,7 +280,7 @@ OffsetPaginator.prototype.shift = function() {
280280
/**
281281
* Adds the item to the beginning of the collection.
282282
*
283-
* @param mixed item - The item to add
283+
* @param {any} item - The item to add
284284
* @return this - fluent interface
285285
*/
286286
OffsetPaginator.prototype.unshift = function(item) {

0 commit comments

Comments
 (0)