How to use @google-cloud/promisify - 10 common examples

To help you get started, we’ve selected a few @google-cloud/promisify examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github googleapis / nodejs-vision / src / helpers.js View on Github external
* const request = {
   *   image: {
   *     source: {imageUri: 'gs://path/to/image.jpg'}
   *   }
   * };
   *
   * client
   *   .documentTextDetection(request)
   *   .then(response => {
   *     // doThingsWith(response);
   *   })
   *   .catch(err => {
   *     console.error(err);
   *   });
   */
  methods.documentTextDetection = promisify(
    _createSingleFeatureMethod(features.DOCUMENT_TEXT_DETECTION)
  );

  /**
   * Annotate a single image with safe search detection.
   *
   * @see v1.ImageAnnotatorClient#batchAnnotateImages
   * @see google.cloud.vision.v1.AnnotateImageRequest
   *
   * @method v1.ImageAnnotatorClient#safeSearchDetection
   * @param {object|string|Buffer} request A representation of the request
   *     being sent to the Vision API. This is an
   *     {@link google.cloud.vision.v1.AnnotateImageRequest AnnotateImageRequest}.
   *     For simple cases, you may also send a string (the URL or filename of
   *     the image) or a buffer (the image itself).
   * @param {object} request.image A dictionary-like object representing the
github googleapis / nodejs-vision / src / helpers.js View on Github external
* const request = {
   *   image: {
   *     source: {imageUri: 'gs://path/to/image.jpg'}
   *   }
   * };
   *
   * client
   *   .faceDetection(request)
   *   .then(response => {
   *     // doThingsWith(response);
   *   })
   *   .catch(err => {
   *     console.error(err);
   *   });
   */
  methods.faceDetection = promisify(
    _createSingleFeatureMethod(features.FACE_DETECTION)
  );

  /**
   * Annotate a single image with landmark detection.
   *
   * @see v1.ImageAnnotatorClient#batchAnnotateImages
   * @see google.cloud.vision.v1.AnnotateImageRequest
   *
   * @method v1.ImageAnnotatorClient#landmarkDetection
   * @param {object|string|Buffer} request A representation of the request
   *     being sent to the Vision API. This is an
   *     {@link google.cloud.vision.v1.AnnotateImageRequest AnnotateImageRequest}.
   *     For simple cases, you may also send a string (the URL or filename of
   *     the image) or a buffer (the image itself).
   * @param {object} request.image A dictionary-like object representing the
github googleapis / nodejs-vision / src / helpers.js View on Github external
* const request = {
   *   image: {
   *     source: {imageUri: 'gs://path/to/image.jpg'}
   *   }
   * };
   *
   * client
   *   .cropHints(request)
   *   .then(response => {
   *     // doThingsWith(response);
   *   })
   *   .catch(err => {
   *     console.error(err);
   *   });
   */
  methods.cropHints = promisify(
    _createSingleFeatureMethod(features.CROP_HINTS)
  );

  /**
   * Annotate a single image with web detection.
   *
   * @see v1.ImageAnnotatorClient#batchAnnotateImages
   * @see google.cloud.vision.v1.AnnotateImageRequest
   *
   * @method v1.ImageAnnotatorClient#webDetection
   * @param {object|string|Buffer} request A representation of the request
   *     being sent to the Vision API. This is an
   *     {@link google.cloud.vision.v1.AnnotateImageRequest AnnotateImageRequest}.
   *     For simple cases, you may also send a string (the URL or filename of
   *     the image) or a buffer (the image itself).
   * @param {object} request.image A dictionary-like object representing the
github googleapis / nodejs-common / test / service-object.ts View on Github external
it('should execute callback with instance & metadata', done => {
      const metadata = {} as SO.Metadata;

      serviceObject.getMetadata = promisify(
        (options: SO.GetMetadataOptions, callback: SO.MetadataCallback) => {
          callback(null, metadata);
        }
      );

      serviceObject.get((err, instance, metadata_) => {
        assert.ifError(err);

        assert.strictEqual(instance, serviceObject);
        assert.strictEqual(metadata_, metadata);

        done();
      });
    });
github googleapis / nodejs-common / test / service-object.ts View on Github external
it('handles not getting a config', (done) => {
      serviceObject.getMetadata =
          promisify((_callback: SO.MetadataCallback): void => {
            done();
          });
      (serviceObject as FakeServiceObject).get(undefined, assert.ifError);
    });
github googleapis / nodejs-compute / src / snapshot.js View on Github external
callback(err, null, resp);
        return;
      }
      const operation = compute.operation(resp.name);
      operation.metadata = resp;
      callback(null, operation, resp);
    });
  }
}

/*! Developer Documentation
 *
 * All async methods (except for streams) will return a Promise in the event
 * that a callback is omitted.
 */
promisifyAll(Snapshot);

/**
 * Reference to the {@link Snapshot} class.
 * @name module:@google-cloud/compute.Snapshot
 * @see Snapshot
 */
module.exports = Snapshot;
github googleapis / nodejs-logging / src / sink.js View on Github external
if (arguments[1]) {
            self.metadata = arguments[1];
          }
          callback.apply(null, arguments);
        }
      );
    });
  }
}

/*! Developer Documentation
 *
 * All async methods (except for streams) will return a Promise in the event
 * that a callback is omitted.
 */
promisifyAll(Sink);

/**
 * Reference to the {@link Sink} class.
 * @name module:@google-cloud/logging.Sink
 * @see Sink
 */
module.exports.Sink = Sink;
github googleapis / nodejs-bigtable / src / cluster.ts View on Github external
{
          client: 'BigtableInstanceAdminClient',
          method: 'updateCluster',
          reqOpts,
          gaxOpts: gaxOptions,
        },
        callback);
  }
}

/*! Developer Documentation
 *
 * All async methods (except for streams) will return a Promise in the event
 * that a callback is omitted.
 */
promisifyAll(Cluster);

/**
 * Reference to the {@link Cluster} class.
 * @name module:@google-cloud/bigtable.Cluster
 * @see Cluster
 */
github googleapis / nodejs-storage / src / iam.ts View on Github external
const permissionsHash = permissions.reduce((acc, permission) => {
            acc[permission] = availablePermissions.indexOf(permission) > -1;
            return acc;
          }, {});

          callback(null, permissionsHash, resp);
        });
  }
}

/*! Developer Documentation
 *
 * All async methods (except for streams) will return a Promise in the event
 * that a callback is omitted.
 */
promisifyAll(Iam);

export {Iam};
github googleapis / nodejs-datastore / src / transaction.ts View on Github external
entity: {
          key: ent.key,
        },
        method: 'save',
        args: [ent],
      });
    });
  }
}

/*! Developer Documentation
 *
 * All async methods (except for streams) will return a Promise in the event
 * that a callback is omitted.
 */
promisifyAll(Transaction, {
  exclude: ['createQuery', 'delete', 'save'],
});

/**
 * Reference to the {@link Transaction} class.
 * @name module:@google-cloud/datastore.Transaction
 * @see Transaction
 */
export {Transaction};

@google-cloud/promisify

A simple utility for promisifying functions and classes.

Apache-2.0
Latest version published 1 year ago

Package Health Score

81 / 100
Full package analysis

Similar packages