diff --git a/package.json b/package.json index 5b1d359..9c28e1f 100644 --- a/package.json +++ b/package.json @@ -76,7 +76,8 @@ "form-data": "https://github.com/spark/form-data/archive/v1.0.0-relative-path.tar.gz", "stream-http": "https://github.com/spark/stream-http/archive/v2.2.1.tar.gz", "superagent": "^2.2.0", - "superagent-prefix": "0.0.2" + "superagent-prefix": "0.0.2", + "verror": "^1.9.0" }, "browser": { "http": "stream-http", diff --git a/src/collections/Base.js b/src/collections/Base.js new file mode 100644 index 0000000..ff1208f --- /dev/null +++ b/src/collections/Base.js @@ -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(); + } +} diff --git a/src/errors/CustomError.js b/src/errors/CustomError.js new file mode 100644 index 0000000..571694e --- /dev/null +++ b/src/errors/CustomError.js @@ -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; diff --git a/src/errors/NotImplementedError.js b/src/errors/NotImplementedError.js new file mode 100644 index 0000000..f28b624 --- /dev/null +++ b/src/errors/NotImplementedError.js @@ -0,0 +1,3 @@ +import CustomError from './CustomError'; + +export default class NotImplementedError extends CustomError {} diff --git a/src/models/Base.js b/src/models/Base.js new file mode 100644 index 0000000..1d3131d --- /dev/null +++ b/src/models/Base.js @@ -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); + } +} diff --git a/src/models/BuildTarget.js b/src/models/BuildTarget.js new file mode 100644 index 0000000..4a00882 --- /dev/null +++ b/src/models/BuildTarget.js @@ -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 { + +} diff --git a/test/errors/NotImplementedError.js b/test/errors/NotImplementedError.js new file mode 100644 index 0000000..065c324 --- /dev/null +++ b/test/errors/NotImplementedError.js @@ -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; + }) +});