1 | /*
|
2 | * Copyright 2014 the original author or authors
|
3 | * @license MIT, see LICENSE.txt for details
|
4 | *
|
5 | * @author Scott Andrews
|
6 | */
|
7 |
|
8 | (function (define) {
|
9 | ;
|
10 |
|
11 | define(function (/* require */) {
|
12 |
|
13 | /**
|
14 | * Add common helper methods to a client impl
|
15 | *
|
16 | * @param {function} impl the client implementation
|
17 | * @param {Client} [target] target of this client, used when wrapping other clients
|
18 | * @returns {Client} the client impl with additional methods
|
19 | */
|
20 | return function client(impl, target) {
|
21 |
|
22 | if (target) {
|
23 |
|
24 | /**
|
25 | * @returns {Client} the target client
|
26 | */
|
27 | impl.skip = function skip() {
|
28 | return target;
|
29 | };
|
30 |
|
31 | }
|
32 |
|
33 | /**
|
34 | * Allow a client to easily be wrapped by an interceptor
|
35 | *
|
36 | * @param {Interceptor} interceptor the interceptor to wrap this client with
|
37 | * @param [config] configuration for the interceptor
|
38 | * @returns {Client} the newly wrapped client
|
39 | */
|
40 | impl.wrap = function wrap(interceptor, config) {
|
41 | return interceptor(impl, config);
|
42 | };
|
43 |
|
44 | /**
|
45 | * @deprecated
|
46 | */
|
47 | impl.chain = function chain() {
|
48 | if (typeof console !== 'undefined') {
|
49 | console.log('rest.js: client.chain() is deprecated, use client.wrap() instead');
|
50 | }
|
51 |
|
52 | return impl.wrap.apply(this, arguments);
|
53 | };
|
54 |
|
55 | return impl;
|
56 |
|
57 | };
|
58 |
|
59 | });
|
60 |
|
61 | }(
|
62 | typeof define === 'function' && define.amd ? define : function (factory) { module.exports = factory(require); }
|
63 | // Boilerplate for AMD and Node
|
64 | ));
|