diff --git a/CHANGELOG.md b/CHANGELOG.md index cb626bd..12e0a81 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +##### 3.0.0-rc.2 - 13 August 2016 + +###### Backwards compatible changes +- Upgraded dependencies +- Finish JSDoc comments + +###### Bug fixes +- #55 - dist/js-data-http.d.ts is not complete + ##### 3.0.0-rc.1 - 10 August 2016 ###### Breaking changes diff --git a/dist/js-data-http.d.ts b/dist/js-data-http.d.ts index 36186ca..11c0609 100644 --- a/dist/js-data-http.d.ts +++ b/dist/js-data-http.d.ts @@ -35,4 +35,52 @@ export class HttpAdapter extends Adapter { } static extend(instanceProps?: IDict, classProps?: IDict): typeof HttpAdapter constructor(opts?: IBaseHttpAdapter) + afterDEL(url: string, config: any, opts: any, response: any): any + afterGET(url: string, config: any, opts: any, response: any): any + afterHTTP(config: any, opts: any, response: any): any + afterPOST(url: string, data: any, config: any, opts: any, response: any): any + afterPUT(url: string, data: any, config: any, opts: any, response: any): any + beforeDEL(url: string, config: any, opts: any): any + beforeGET(url: string, config: any, opts: any): any + beforeHTTP(config: any, opts: any): any + beforePOST(url: string, data: any, config: any, opts: any): any + beforePUT(url: string, data: any, config: any, opts: any): any + _count(mapper: any, query: any, opts?: any): Promise + _create(mapper: any, props: any, opts?: any): Promise + _createMany(mapper: any, props: any, opts?: any): Promise + _destroy(mapper: any, id: string | number, opts?: any): Promise + _destroyAll(mapper: any, query: any, opts?: any): Promise + _end(mapper: any, opts: any, response: any): any + _find(mapper: any, id: string | number, opts?: any): Promise + _findAll(mapper: any, query: any, opts?: any): Promise + _sum(mapper: any, field: any, query: any, opts?: any): Promise + _update(mapper: any, id: any, props: any, opts?: any): Promise + _updateAll(mapper: any, props: any, query: any, opts?: any): Promise + _updateMany(mapper: any, records: any, opts?: any): Promise + count(mapper: any, query: any, opts?: any): Promise + create(mapper: any, props: any, opts?: any): Promise + createMany(mapper: any, props: any, opts?: any): Promise + DEL(url: string, config?: any, opts?: any): Promise + deserialize(mapper: any, response: any, opts?: any): any + destroy(mapper: any, id: string | number, opts?: any): Promise + destroyAll(mapper: any, query: any, opts?: any): Promise + error(...args: any[]): void + fetch(config: any, opts?: any): Promise + find(mapper: any, id: string | number, opts?: any): Promise + findAll(mapper: any, query: any, opts?: any): Promise + GET(url: string, config?: any, opts?: any): Promise + getEndpoint(mapper: any, id: string | number, opts?: any): any + getPath(method: string, mapper: any, id: any, opts?: any): any + getParams(opts?: any): any + getSuffix(mapper: any, opts?: any): any + HTTP(config: any, opts?: any): Promise + POST(url: string, data: any, config?: any, opts?: any): Promise + PUT(url: string, data: any, config?: any, opts?: any): Promise + queryTransform(mapper: any, params: any, opts?: any): any + responseError(err: any, config?: any, opts?: any): any + serialize(mapper: any, data: any, opts?: any): Promise + sum(mapper: any, field: any, query: any, opts?: any): Promise + update(mapper: any, id: any, props: any, opts?: any): Promise + updateAll(mapper: any, props: any, query: any, opts?: any): Promise + updateMany(mapper: any, records: any, opts?: any): Promise } diff --git a/fetch/package.json b/fetch/package.json index 854d87f..ca72193 100644 --- a/fetch/package.json +++ b/fetch/package.json @@ -1,7 +1,7 @@ { "name": "js-data-fetch", "description": "HTTP adapter for js-data that uses the fetch API.", - "version": "3.0.0-rc.1", + "version": "3.0.0-rc.2", "homepage": "https://github.com/js-data/js-data-http", "repository": { "type": "git", @@ -22,7 +22,7 @@ "fetch" ], "dependencies": { - "js-data-adapter": "~0.8.0" + "js-data-adapter": "~0.8.1" }, "peerDependencies": { "js-data": "^3.0.0-rc.4" diff --git a/node/package.json b/node/package.json index 8b02a62..9ee98ce 100644 --- a/node/package.json +++ b/node/package.json @@ -1,7 +1,7 @@ { "name": "js-data-http-node", "description": "Node.js HTTP adapter for js-data.", - "version": "3.0.0-rc.1", + "version": "3.0.0-rc.2", "homepage": "https://github.com/js-data/js-data-http", "repository": { "type": "git", @@ -22,7 +22,7 @@ "node.js" ], "dependencies": { - "js-data-adapter": "~0.8.0" + "js-data-adapter": "~0.8.1" }, "peerDependencies": { "axios": "^0.13.1", diff --git a/package.json b/package.json index 1bfec37..815dc97 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "js-data-http", "description": "HTTP (XHR) adapter for js-data in the browser.", - "version": "3.0.0-rc.1", + "version": "3.0.0-rc.2", "homepage": "https://github.com/js-data/js-data-http", "repository": { "type": "git", @@ -74,7 +74,7 @@ "release": "npm test && npm run doc && repo-tools updates && repo-tools changelog && repo-tools authors" }, "dependencies": { - "js-data-adapter": "~0.8.0" + "js-data-adapter": "~0.8.1" }, "peerDependencies": { "js-data": "^3.0.0-rc.4" @@ -86,13 +86,13 @@ "babel-preset-stage-0": "6.5.0", "istanbul": "0.4.4", "js-data-repo-tools": "0.5.6", - "karma": "1.1.2", + "karma": "1.2.0", "karma-browserstack-launcher": "1.0.1", "karma-chai": "0.1.0", "karma-mocha": "1.1.1", "karma-phantomjs-launcher": "1.0.1", "karma-sinon": "1.0.5", - "phantomjs-prebuilt": "2.1.11", + "phantomjs-prebuilt": "2.1.12", "rollup-plugin-commonjs": "3.3.1", "rollup-plugin-replace": "1.1.1", "uglify-js": "2.7.0" diff --git a/src/index.js b/src/index.js index 6c6fb51..4ca18a7 100644 --- a/src/index.js +++ b/src/index.js @@ -70,42 +70,68 @@ function buildUrl (url, params) { } const DEFAULTS = { - // Default and user-defined settings /** + * Set a base path in order to use absolute URLs instead of relative URLs. + * + * @example + * const httpAdapter = new HttpAdapter({ + * basePath: 'https://mydomain.com' + * }) + * * @name HttpAdapter#basePath * @type {string} + * @since 3.0.0 */ basePath: '', /** + * Ensure that the request url has a trailing forward slash. + * * @name HttpAdapter#forceTrailingSlash * @type {boolean} * @default false + * @since 3.0.0 */ forceTrailingSlash: false, /** + * The HTTP function that actually makes the HTTP request. By default this is + * `axios`. + * * @name HttpAdapter#http * @type {Function} + * @since 3.0.0 + * @see http://www.js-data.io/docs/js-data-http#using-a-custom-http-library */ http: axios, /** + * Default configuration options to be mixed into the `config` argument passed + * to {@link HttpAdapter#http}. + * * @name HttpAdapter#httpConfig * @type {Object} + * @since 3.0.0 */ httpConfig: {}, /** + * Add a suffix to the request url, e.g. ".json". + * * @name HttpAdapter#suffix * @type {string} + * @since 3.0.0 */ suffix: '', /** + * Use `window.fetch` if available. + * * @name HttpAdapter#useFetch * @type {boolean} * @default false + * @since 3.0.0 + * @see http://www.js-data.io/docs/js-data-http#using-windowfetch */ useFetch: false } @@ -113,16 +139,34 @@ const DEFAULTS = { /** * HttpAdapter class. * + * @example + * import { DataStore } from 'js-data'; + * import { HttpAdapter } from 'js-data-http'; + * + * const httpAdapter = new HttpAdapter(); + * const store = new DataStore(); + * + * store.registerAdapter('http', httpAdapter, { 'default': true }); + * + * store.defineMapper('school'); + * store.defineMapper('student'); + * + * // GET /school/1 + * store.find('school', 1).then((school) => { + * console.log('school'); + * }); + * * @class HttpAdapter * @extends Adapter * @param {Object} [opts] Configuration options. - * @param {string} [opts.basePath=''] TODO - * @param {boolean} [opts.debug=false] TODO - * @param {boolean} [opts.forceTrailingSlash=false] TODO - * @param {Object} [opts.http=axios] TODO - * @param {Object} [opts.httpConfig={}] TODO - * @param {string} [opts.suffix=''] TODO - * @param {boolean} [opts.useFetch=false] TODO + * @param {string} [opts.basePath=''] See {@link HttpAdapter#basePath}. + * @param {boolean} [opts.debug=false] See {@link HttpAdapter#debug}. + * @param {boolean} [opts.forceTrailingSlash=false] See {@link HttpAdapter#forceTrailingSlash}. + * @param {Object} [opts.http=axios] See {@link HttpAdapter#http}. + * @param {Object} [opts.httpConfig={}] See {@link HttpAdapter#httpConfig}. + * @param {string} [opts.suffix=''] See {@link HttpAdapter#suffix}. + * @param {boolean} [opts.useFetch=false] See {@link HttpAdapter#useFetch}. + * @see http://www.js-data.io/docs/js-data-http */ export function HttpAdapter (opts) { utils.classCallCheck(this, HttpAdapter) @@ -332,8 +376,8 @@ Adapter.extend({ * @param {Object} mapper The mapper. * @param {Object} query Selection query. * @param {Object} [opts] Configuration options. - * @param {string} [opts.params] TODO - * @param {string} [opts.suffix={@link HttpAdapter#suffix}] TODO + * @param {string} [opts.params] Querystring parameters. + * @param {string} [opts.suffix={@link HttpAdapter#suffix}] See {@link HttpAdapter#suffix}. * @return {Promise} */ count (mapper, query, opts) { @@ -355,8 +399,8 @@ Adapter.extend({ * @param {Object} mapper The mapper. * @param {Object} props Properties to send as the payload. * @param {Object} [opts] Configuration options. - * @param {string} [opts.params] TODO - * @param {string} [opts.suffix={@link HttpAdapter#suffix}] TODO + * @param {string} [opts.params] Querystring parameters. + * @param {string} [opts.suffix={@link HttpAdapter#suffix}] See {@link HttpAdapter#suffix}. * @return {Promise} */ create (mapper, props, opts) { @@ -375,8 +419,8 @@ Adapter.extend({ * @param {Object} mapper The mapper. * @param {Array} props Array of property objects to send as the payload. * @param {Object} [opts] Configuration options. - * @param {string} [opts.params] TODO - * @param {string} [opts.suffix={@link HttpAdapter#suffix}] TODO + * @param {string} [opts.params] Querystring parameters. + * @param {string} [opts.suffix={@link HttpAdapter#suffix}] See {@link HttpAdapter#suffix}. * @return {Promise} */ createMany (mapper, props, opts) { @@ -456,8 +500,8 @@ Adapter.extend({ * @param {Object} mapper The mapper. * @param {(string|number)} id Primary key of the record to destroy. * @param {Object} [opts] Configuration options. - * @param {string} [opts.params] TODO - * @param {string} [opts.suffix={@link HttpAdapter#suffix}] TODO + * @param {string} [opts.params] Querystring parameters. + * @param {string} [opts.suffix={@link HttpAdapter#suffix}] See {@link HttpAdapter#suffix}. * @return {Promise} */ destroy (mapper, id, opts) { @@ -476,8 +520,8 @@ Adapter.extend({ * @param {Object} mapper The mapper. * @param {Object} query Selection query. * @param {Object} [opts] Configuration options. - * @param {string} [opts.params] TODO - * @param {string} [opts.suffix={@link HttpAdapter#suffix}] TODO + * @param {string} [opts.params] Querystring parameters. + * @param {string} [opts.suffix={@link HttpAdapter#suffix}] See {@link HttpAdapter#suffix}. * @return {Promise} */ destroyAll (mapper, query, opts) { @@ -549,8 +593,8 @@ Adapter.extend({ * @param {Object} mapper The mapper. * @param {(string|number)} id Primary key of the record to retrieve. * @param {Object} [opts] Configuration options. - * @param {string} [opts.params] TODO - * @param {string} [opts.suffix={@link HttpAdapter#suffix}] TODO + * @param {string} [opts.params] Querystring parameters. + * @param {string} [opts.suffix={@link HttpAdapter#suffix}] See {@link HttpAdapter#suffix}. * @return {Promise} */ find (mapper, id, opts) { @@ -569,8 +613,8 @@ Adapter.extend({ * @param {Object} mapper The mapper. * @param {Object} query Selection query. * @param {Object} [opts] Configuration options. - * @param {string} [opts.params] TODO - * @param {string} [opts.suffix={@link HttpAdapter#suffix}] TODO + * @param {string} [opts.params] Querystring parameters. + * @param {string} [opts.suffix={@link HttpAdapter#suffix}] See {@link HttpAdapter#suffix}. * @return {Promise} */ findAll (mapper, query, opts) { @@ -584,7 +628,7 @@ Adapter.extend({ }, /** - * TODO + * Make a GET request. * * @name HttpAdapter#GET * @method @@ -621,9 +665,9 @@ Adapter.extend({ /** * @name HttpAdapter#getEndpoint * @method - * @param {Object} mapper TODO - * @param {*} id TODO - * @param {boolean} opts TODO + * @param {Object} mapper The Mapper. + * @param {*} id The primary key, if any. + * @param {boolean} opts Configuration options. * @return {string} Full path. */ getEndpoint (mapper, id, opts) { @@ -676,9 +720,9 @@ Adapter.extend({ /** * @name HttpAdapter#getPath * @method - * @param {string} method TODO - * @param {Object} mapper TODO - * @param {(string|number)?} id TODO + * @param {string} method The method being executed. + * @param {Object} mapper The Mapper. + * @param {(string|number)?} id The primary key, if any. * @param {Object} opts Configuration options. */ getPath (method, mapper, id, opts) { @@ -745,7 +789,7 @@ Adapter.extend({ const str = `${start.toUTCString()} - ${config.method.toUpperCase()} ${config.url} - ${data.status} ${(new Date().getTime() - start.getTime())}ms` if (data.status >= 200 && data.status < 300) { if (this.log) { - this.dbg('debug', str, data) + this.dbg(str, data) } return data } else { @@ -776,13 +820,13 @@ Adapter.extend({ }, /** - * TODO + * Make a POST request. * * @name HttpAdapter#POST * @method - * @param {*} url TODO - * @param {Object} data TODO - * @param {Object} config TODO + * @param {*} url The url for the request. + * @param {Object} data Payload for the request. + * @param {Object} config Request configuration options. * @param {Object} [opts] Configuration options. * @return {Promise} */ @@ -813,13 +857,13 @@ Adapter.extend({ }, /** - * TODO + * Make a PUT request. * * @name HttpAdapter#PUT * @method - * @param {*} url TODO - * @param {Object} data TODO - * @param {Object} config TODO + * @param {*} url The url for the request. + * @param {Object} data Payload for the request. + * @param {Object} config Request configuration options. * @param {Object} [opts] Configuration options. * @return {Promise} */ @@ -850,13 +894,14 @@ Adapter.extend({ }, /** - * TODO + * Transform the querystring object before it is serialized. This doesn't do + * anything by default. * * @name HttpAdapter#queryTransform * @method - * @param {Object} mapper TODO - * @param {*} params TODO - * @param {*} opts TODO + * @param {Object} mapper The Mapper that triggered the request. + * @param {*} params The querystring object. + * @param {*} opts Configuration options * @return {*} Transformed params. */ queryTransform (mapper, params, opts) { @@ -888,13 +933,13 @@ Adapter.extend({ }, /** - * TODO + * Serialize request data. This doesn't do anything by default. * * @name HttpAdapter#serialize * @method - * @param {Object} mapper TODO - * @param {Object} data TODO - * @param {*} opts TODO + * @param {Object} mapper The Mapper that triggered the request. + * @param {Object} data The request payload. + * @param {*} opts Configuration options. * @return {*} Serialized data. */ serialize (mapper, data, opts) { @@ -917,8 +962,8 @@ Adapter.extend({ * @param {string} field The field to sum. * @param {Object} query Selection query. * @param {Object} [opts] Configuration options. - * @param {string} [opts.params] TODO - * @param {string} [opts.suffix={@link HttpAdapter#suffix}] TODO + * @param {string} [opts.params] Querystring parameters. + * @param {string} [opts.suffix={@link HttpAdapter#suffix}] See {@link HttpAdapter#suffix}. * @return {Promise} */ sum (mapper, field, query, opts) { @@ -936,13 +981,13 @@ Adapter.extend({ }, /** - * TODO + * Perform an update. Makes a PUT request by default. * * @name HttpAdapter#update * @method - * @param {Object} mapper TODO - * @param {*} id TODO - * @param {*} props TODO + * @param {Object} mapper The Mapper for the request. + * @param {*} id The primary key of the record being updated. + * @param {*} props The update payload. * @param {Object} [opts] Configuration options. * @return {Promise} */ @@ -955,13 +1000,14 @@ Adapter.extend({ }, /** - * TODO + * Perform an update against records that match the selection query. Makes a + * PUT request by default. * * @name HttpAdapter#updateAll * @method - * @param {Object} mapper TODO - * @param {Object} props TODO - * @param {Object} query TODO + * @param {Object} mapper The Mapper for the request. + * @param {Object} props The update payload. + * @param {Object} query The selection query. See {@link http://www.js-data.io/docs/query-syntax}. * @param {Object} [opts] Configuration options. * @return {Promise} */ @@ -976,20 +1022,16 @@ Adapter.extend({ }, /** - * Update multiple records in batch. - * - * {@link HttpAdapter#beforeUpdateMany} will be called before calling - * {@link HttpAdapter#PUT}. - * {@link HttpAdapter#afterUpdateMany} will be called after calling - * {@link HttpAdapter#PUT}. + * Update multiple individual records in a batch. * * @name HttpAdapter#updateMany * @method - * @param {Object} mapper The mapper. + * @param {Object} mapper The Mapper for the request. * @param {Array} records Array of property objects to send as the payload. + * Each must contain the primary key of the record to be updated. * @param {Object} [opts] Configuration options. - * @param {string} [opts.params] TODO - * @param {string} [opts.suffix={@link HttpAdapter#suffix}] TODO + * @param {string} [opts.params] Querystring parameters. + * @param {string} [opts.suffix={@link HttpAdapter#suffix}] See {@link HttpAdapter#suffix}. * @return {Promise} */ updateMany (mapper, records, opts) { diff --git a/typings.json b/typings.json index 2f71f35..bd7eb2d 100644 --- a/typings.json +++ b/typings.json @@ -5,6 +5,6 @@ "ambientDependencies": { "js-data": "npm:js-data", "js-data-adapter": "npm:js-data-adapter", - "es6-shim": "registry:dt/es6-shim#0.31.2+20160317120654" + "es6-shim": "registry:dt/es6-shim" } }