-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce basic model, collection and error patterns
- Loading branch information
Showing
7 changed files
with
100 additions
and
1 deletion.
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
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,49 @@ | ||
import NotImplementedError from '../errors/NotImplementedError'; | ||
|
||
/** | ||
* @interface | ||
*/ | ||
export default class Base { | ||
/** | ||
* @param {Object} [filter] Predicate used when fetching | ||
* @return {Promise} | ||
*/ | ||
fetch(filter={}) { | ||
throw new NotImplementedError(); | ||
} | ||
|
||
/** | ||
* @property {boolean} hasNextPage Indicates if collection has a next page | ||
*/ | ||
get hasNextPage() { | ||
throw new NotImplementedError(); | ||
} | ||
|
||
/** | ||
* @return {Promise} | ||
*/ | ||
nextPage() { | ||
throw new NotImplementedError(); | ||
} | ||
|
||
/** | ||
* @property {boolean} hasPrevPage Indicates if collection has a previous page | ||
*/ | ||
get hasPrevPage() { | ||
throw new NotImplementedError(); | ||
} | ||
|
||
/** | ||
* @return {Promise} | ||
*/ | ||
prevPage() { | ||
throw new NotImplementedError(); | ||
} | ||
|
||
/** | ||
* @property {number} page Indicates current page number | ||
*/ | ||
get page() { | ||
throw new NotImplementedError(); | ||
} | ||
} |
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,14 @@ | ||
import VError from 'VError'; | ||
|
||
class CustomError extends VError { | ||
constructor() { | ||
super(...arguments); | ||
this.name = this.constructor.name; | ||
} | ||
|
||
static matches(error) { | ||
return error.name === this.name; | ||
} | ||
} | ||
|
||
export default CustomError; |
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,3 @@ | ||
import CustomError from './CustomError'; | ||
|
||
export default class NotImplementedError extends CustomError {} |
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,11 @@ | ||
export default class Base { | ||
constructor(client, data) { | ||
// Make client non-enumerable so it doesn't show up in Object.keys, JSON.stringify, etc | ||
Object.defineProperty(this, 'client', { value: client }); | ||
this._assignAttributes(data); | ||
} | ||
|
||
_assignAttributes(data) { | ||
Object.assign(this, data); | ||
} | ||
} |
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,12 @@ | ||
import Base from './Base'; | ||
|
||
/** | ||
* @property {string} version | ||
* @property {number} platformId | ||
* @property {boolean} featured | ||
* @property {boolean} prerelease | ||
* @property {string} vendor | ||
*/ | ||
export default class BuildTarget extends Base { | ||
|
||
} |
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,9 @@ | ||
import {expect} from '../test-setup'; | ||
import NotImplementedError from '../../src/errors/NotImplementedError'; | ||
|
||
describe('NotImplementedError', () => { | ||
it('matches the error', () => { | ||
let exception = new NotImplementedError(); | ||
expect(NotImplementedError.matches(exception)).to.be.true; | ||
}) | ||
}); |