@@ -29,15 +29,28 @@ function deprecate(fn, msg) {
2929 * API for calling helper methods (single-stage pipelines) and
3030 * pipeline building.
3131 *
32- * @param {Object } client the client to execute the stages on
32+ * @param {Object } service the service to execute the stages on
3333 * @param {Array } stages the pipeline stages to execute
3434 * @param {Function } [finalizer] optional function to call on the result of the response
3535 */
36- function serviceResponse ( client , stages , finalizer ) {
36+ function serviceResponse ( service , stages , finalizer ) {
37+ if ( service && ! service . client ) {
38+ throw new Error ( 'Service has no client' ) ;
39+ }
40+
3741 if ( finalizer && typeof finalizer !== 'function' ) {
3842 throw new Error ( 'Service response finalizer must be a function' ) ;
3943 }
4044
45+ if ( service . hasOwnProperty ( '__let__' ) ) {
46+ if ( Array . isArray ( stages ) ) {
47+ // what do we do here?
48+ } else {
49+ stages . let = service . __let__ ;
50+ }
51+ }
52+
53+ const client = service . client ;
4154 Object . defineProperties ( stages , {
4255 then : {
4356 enumerable : false ,
@@ -64,4 +77,22 @@ function serviceResponse(client, stages, finalizer) {
6477 return stages ;
6578}
6679
67- export { deprecate , serviceResponse } ;
80+ /**
81+ * Mixin that allows a definition of an optional `let` stage for
82+ * services is mixes in with.
83+ *
84+ * @param {* } Type the service to mixin
85+ */
86+ function letMixin ( Type ) {
87+ Type . prototype . let = function ( options ) {
88+ Object . defineProperty ( this , '__let__' , {
89+ enumerable : false , configurable : false , writable : false , value : options
90+ } ) ;
91+
92+ return this ;
93+ } ;
94+
95+ return Type ;
96+ }
97+
98+ export { deprecate , serviceResponse , letMixin } ;
0 commit comments