Skip to content

Commit

Permalink
v0.1.369
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 563532158
  • Loading branch information
Google Earth Engine Authors authored and sufyanAbbasi committed Sep 14, 2023
1 parent cada813 commit 1baca88
Show file tree
Hide file tree
Showing 43 changed files with 1,198 additions and 1,155 deletions.
27 changes: 1 addition & 26 deletions CONTRIBUTING
Original file line number Diff line number Diff line change
@@ -1,26 +1 @@
All contributors to the Earth Engine API libraries must sign a CLA.

What is a CLA?
----------------------------------------

A CLA (Contributor License Agreement) basically says that you own the
rights to any code you contribute, and that you give us permission to
use that code in the Earth Engine API libraries. You maintain the
copyright on that code.

Where do I sign up?
----------------------------------------

If you own all the rights to your code, you can fill out an individual CLA.
http://code.google.com/legal/individual-cla-v1.0.html

If your employer has any rights to your code, then they also need to fill
out a corporate CLA. If you don't know if your employer has any rights
to your code, you should ask before signing anything.
http://code.google.com/legal/corporate-cla-v1.0.html

CLA Signers
----------------------------------------

By default, anyone with an @google.com email address already has a CLA
signed for them. Congratulations!
The Earth Engine API clients are not currently accepting pull requests.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Google Earth Engine API
=======================
# Google Earth Engine API

Python and JavaScript client libraries for calling the Google Earth Engine API.

Expand Down Expand Up @@ -39,3 +38,11 @@ Map.addLayer(
{min: 0, max: [0.18, 20, -0.18], bands: ['scale', 'offset', 'scale']},
'stable lights trend');
```

## NOTICE

In order to be more responsive to bug reports and feature requests, we are
currently using the Google Issue Tracker rather than the GitHub Issue tracker.
Please see the [Get Help](https://developers.google.com/earth-engine/help) page
of the Earth Engine documentation for details on how to browse and submit issues
to Issue Tracker.
1,354 changes: 678 additions & 676 deletions javascript/build/ee_api_js.js

Large diffs are not rendered by default.

156 changes: 97 additions & 59 deletions javascript/build/ee_api_js_debug.js

Large diffs are not rendered by default.

196 changes: 117 additions & 79 deletions javascript/build/ee_api_js_npm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion javascript/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@google/earthengine",
"version": "0.1.368",
"version": "0.1.369",
"description": "JavaScript client for Google Earth Engine API.",
"author": "Google LLC",
"license": "Apache-2.0",
Expand Down
75 changes: 59 additions & 16 deletions javascript/src/apiclient.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const {PromiseRequestService} = goog.require('eeapiclient.promise_request_servic
/** @namespace */
const apiclient = {};

const API_CLIENT_VERSION = '0.1.368';
const API_CLIENT_VERSION = '0.1.369';

exports.VERSION = apiVersion.VERSION;
exports.API_CLIENT_VERSION = API_CLIENT_VERSION;
Expand Down Expand Up @@ -60,6 +60,19 @@ class Call {
this.requestService = new EERequestService(!callback, retries);
}

/**
* Configures partial error detection for this Call.
*
* @param {function(!Object):boolean=} detectPartialError Checks if response
* JSON should be returned directly instead of throwing an error.
* Needed for Operations. See https://google.aip.dev/193#partial-errors
* @return {!Call}
*/
withDetectPartialError(detectPartialError) {
this.requestService.detectPartialError = detectPartialError;
return this;
}

/**
* Wraps a promise returned by an API call, to call the configured callback.
* Also handles the "fake promise" returned in synchronous mode.
Expand Down Expand Up @@ -196,6 +209,8 @@ class EERequestService extends PromiseRequestService {
constructor(sync = false, retries = undefined) {
super();
this.sync = sync;
/** @type {function(!Object):boolean|undefined} */
this.detectPartialError = undefined;

if (retries != null) {
this.retries = retries;
Expand Down Expand Up @@ -229,7 +244,8 @@ class EERequestService extends PromiseRequestService {
const body = params.body ? JSON.stringify(params.body) : undefined;
if (this.sync) {
const raw = apiclient.send(
url, args, undefined, params.httpMethod, body, this.retries);
url, args, undefined, params.httpMethod, body, this.retries,
this.detectPartialError);
const value = responseCtor ? deserialize(responseCtor, raw) : raw;
// Converts a value into an "instant" promise, with a then method that
// immediately applies a function and builds a new thenable of the result.
Expand All @@ -246,7 +262,8 @@ class EERequestService extends PromiseRequestService {
}
};
apiclient.send(
url, args, resolveOrReject, params.httpMethod, body, this.retries);
url, args, resolveOrReject, params.httpMethod, body, this.retries,
this.detectPartialError);
});
return value.then(r => responseCtor ? deserialize(responseCtor, r) : r);
}
Expand All @@ -272,6 +289,22 @@ class BatchCall extends Call {
constructor(callback) {
super(callback);
this.requestService = new BatchRequestService();
/** @type {function(!Object):boolean|undefined} */
this.detectPartialError = undefined;
}

/**
* Configures partial error detection for this BatchCall.
*
* @param {function(!Object):boolean=} detectPartialError Checks if response
* JSON should be returned directly instead of throwing an error.
* Needed for Operations. See https://google.aip.dev/193#partial-errors
* @return {!BatchCall}
* @override
*/
withDetectPartialError(detectPartialError) {
this.detectPartialError = detectPartialError;
return this;
}

/**
Expand Down Expand Up @@ -315,11 +348,14 @@ class BatchCall extends Call {
if (this.callback) {
const callback = (result, err = undefined) =>
this.callback(err ? result : deserializeResponses(result), err);
apiclient.send(batchUrl, null, callback, multipart, body);
apiclient.send(
batchUrl, null, callback, multipart, body, undefined,
this.detectPartialError);
return null;
}
return deserializeResponses(
apiclient.send(batchUrl, null, undefined, multipart, body));
return deserializeResponses(apiclient.send(
batchUrl, null, undefined, multipart, body, undefined,
this.detectPartialError));
}
}

Expand Down Expand Up @@ -769,11 +805,13 @@ apiclient.isInitialized = function() {
* is POST. If this starts with 'multipart', used as content type instead.
* @param {string=} body The payload for POST or multipart requests.
* @param {number=} retries Overrides the default max retries value.
* @param {function(!Object):boolean=} detectPartialError Checks if response
* JSON should be returned directly instead of throwing an error.
* @return {?Object} The data object returned by the API call, or null if a
* callback was specified.
*/
apiclient.send = function(
path, params, callback, method, body, retries) {
path, params, callback, method, body, retries, detectPartialError) {
// Make sure we never perform API calls before initialization.
apiclient.initialize();

Expand Down Expand Up @@ -859,7 +897,8 @@ apiclient.send = function(
// Send an asynchronous request.
const request =
apiclient.buildAsyncRequest_(
url, callback, method, requestData, headers, retries);
url, callback, method, requestData, headers, retries,
detectPartialError);

apiclient.requestQueue_.push(request);
apiclient.RequestThrottle_.fire();
Expand Down Expand Up @@ -904,7 +943,8 @@ apiclient.send = function(
// implement getResponseHeader when synchronous.
return null;
}
}, xmlHttp.responseText, profileHookAtCallTime, undefined, url, method);
}, xmlHttp.responseText, profileHookAtCallTime, undefined, url, method,
detectPartialError);
}
};

Expand All @@ -920,11 +960,13 @@ apiclient.send = function(
* @param {?string} content The content of the request.
* @param {!Object<string,string>} headers The headers to send with the request.
* @param {number=} retries Overrides the default max retries value.
* @param {function(!Object):boolean=} detectPartialError Checks if response
* JSON should be returned directly instead of throwing an error.
* @return {!apiclient.NetworkRequest_} The async request.
* @private
*/
apiclient.buildAsyncRequest_ = function(
url, callback, method, content, headers, retries) {
url, callback, method, content, headers, retries, detectPartialError) {
let retryCount = 0;
const request = {
url: url,
Expand All @@ -948,7 +990,8 @@ apiclient.buildAsyncRequest_ = function(

return apiclient.handleResponse_(
xhrIo.getStatus(), goog.bind(xhrIo.getResponseHeader, xhrIo),
xhrIo.getResponseText(), profileHookAtCallTime, callback, url, method);
xhrIo.getResponseText(), profileHookAtCallTime, callback, url, method,
detectPartialError);
};
request.callback = wrappedCallback;

Expand Down Expand Up @@ -992,13 +1035,15 @@ apiclient.withProfiling = function(hook, body, thisObject) {
* execute if the request is asynchronous.
* @param {string=} url The request's URL.
* @param {string=} method The request's HTTP method.
* @param {function(!Object):boolean=} detectPartialError Checks if response
* JSON should be returned directly instead of throwing an error.
* @return {?Object} The response data, if the request is synchronous,
* otherwise null, if the request is asynchronous.
* @private
*/
apiclient.handleResponse_ = function(
status, getResponseHeader, responseText, profileHook, callback, url,
method) {
method, detectPartialError) {
// Only attempt to get the profile response header if we have a hook.
const profileId =
profileHook ? getResponseHeader(apiclient.PROFILE_HEADER) : '';
Expand All @@ -1009,7 +1054,8 @@ apiclient.handleResponse_ = function(
try {
const response = JSON.parse(body);
if (goog.isObject(response)) {
if ('error' in response && 'message' in response['error']) {
if ('error' in response && 'message' in response['error'] &&
!(detectPartialError && detectPartialError(response))) {
return response['error']['message'];
}
}
Expand All @@ -1035,9 +1081,6 @@ apiclient.handleResponse_ = function(
const response = parseJson(responseText);
if (response.parsed) {
data = response.parsed;
if (data === undefined) {
errorMessage = 'Malformed response: ' + responseText;
}
} else {
errorMessage = response;
}
Expand Down
1 change: 1 addition & 0 deletions javascript/src/apifunction.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* This class manages the algorithm dictionary and creates JavaScript functions
* to apply each EE algorithm.
*
* @author [email protected] (Max Shawabkeh)
*/

goog.provide('ee.ApiFunction');
Expand Down
1 change: 1 addition & 0 deletions javascript/src/collection.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* @fileoverview Base class for ImageCollection and FeatureCollection.
* This class is never intended to be instantiated by the user.
* @author [email protected] (Noel Gorelick)
*/

goog.provide('ee.Collection');
Expand Down
1 change: 1 addition & 0 deletions javascript/src/computedobject.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* @fileoverview A representation of a computed earthengine object.
*
* @author [email protected] (Noel Gorelick)
*/

goog.provide('ee.ComputedObject');
Expand Down
1 change: 1 addition & 0 deletions javascript/src/customfunction.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* @fileoverview An object representing a custom EE Function.
* @author [email protected] (Max Shawabkeh)
*/

goog.provide('ee.CustomFunction');
Expand Down
38 changes: 29 additions & 9 deletions javascript/src/data.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* @fileoverview Singleton for all of the library's communication
* with the Earth Engine API.
* @author [email protected] (Noel Gorelick)
* @suppress {missingRequire} TODO(user): this shouldn't be needed
* @suppress {useOfGoogProvide} TODO(user): Convert to goog.module.
*/
Expand Down Expand Up @@ -75,6 +76,7 @@ goog.require('goog.singleton');
goog.requireType('ee.Collection');
goog.requireType('ee.ComputedObject');
goog.requireType('ee.Element');
goog.requireType('ee.Encodable');
goog.requireType('ee.Image');
goog.requireType('ee.data.images');
goog.requireType('proto.google.protobuf.Value');
Expand Down Expand Up @@ -556,10 +558,12 @@ ee.data.listFeatures = function(asset, params, opt_callback) {
*/
ee.data.computeValue = function(obj, opt_callback) {
const serializer = new ee.Serializer(true);
const expression = ee.data.expressionAugmenter_(
ee.Serializer.encodeCloudApiExpressionWithSerializer(
serializer, obj, /* unboundName= */ undefined));
const request = {expression};
const expression = ee.Serializer.encodeCloudApiExpressionWithSerializer(
serializer, obj, /* unboundName= */ undefined);
let extraMetadata = {};
const request = {
expression: ee.data.expressionAugmenter_(expression, extraMetadata)
};
const workloadTag = ee.data.getWorkloadTag();
if (workloadTag) {
request.workloadTag = workloadTag;
Expand Down Expand Up @@ -961,7 +965,7 @@ ee.data.makeTableDownloadUrl = function(id) {
* returned by ee.data.startProcessing and other batch methods.
*
* @param {number=} opt_count The number of IDs to generate, one by default.
* @param {function(!Array.<string>, string=)=} opt_callback An optional
* @param {function(?Array.<string>, string=)=} opt_callback An optional
* callback. If not supplied, the call is made synchronously.
* @return {?Array.<string>} An array containing generated ID strings, or null
* if a callback is specified.
Expand All @@ -979,6 +983,16 @@ ee.data.newTaskId = function(opt_count, opt_callback) {
};


/**
* Indicator function to determine if a response is an operation error.
* @param {!Object} response Response from a JSON API call.
* @return {boolean}
*/
ee.data.isOperationError_ = function(response) {
return response['name'] && response['done'] && response['error'];
};


/**
* Retrieve status of one or more long-running tasks.
*
Expand All @@ -997,13 +1011,16 @@ ee.data.getTaskStatus = function(taskId, opt_callback) {
ee.rpc_convert.taskIdToOperationName);
if (opNames.length === 1) {
const getResponse = (op) => [ee.rpc_convert.operationToTask(op)];
const call = new ee.apiclient.Call(opt_callback);
// Return operation and don't throw error if operation itself had an error.
const call = new ee.apiclient.Call(opt_callback)
.withDetectPartialError(ee.data.isOperationError_);
return call.handle(call.operations().get(opNames[0]).then(getResponse));
}
const getResponse = (data) =>
opNames.map(id => ee.rpc_convert.operationToTask(data[id]));

const call = new ee.apiclient.BatchCall(opt_callback);
const call = new ee.apiclient.BatchCall(opt_callback)
.withDetectPartialError(ee.data.isOperationError_);
const operations = call.operations();
return call.send(opNames.map(op => [op, operations.get(op)]), getResponse);
};
Expand Down Expand Up @@ -1171,10 +1188,13 @@ ee.data.getOperation = function(operationName, opt_callback) {
const opNames = ee.data.makeStringArray_(operationName)
.map(ee.rpc_convert.taskIdToOperationName);
if (!Array.isArray(operationName)) {
const call = new ee.apiclient.Call(opt_callback);
// Return operation and don't throw error if operation itself had an error.
const call = new ee.apiclient.Call(opt_callback)
.withDetectPartialError(ee.data.isOperationError_);
return call.handle(call.operations().get(opNames[0]));
}
const call = new ee.apiclient.BatchCall(opt_callback);
const call = new ee.apiclient.BatchCall(opt_callback)
.withDetectPartialError(ee.data.isOperationError_);
const operations = call.operations();
return call.send(opNames.map(op => [op, operations.get(op)]));
};
Expand Down
1 change: 1 addition & 0 deletions javascript/src/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* We don't autogenerate this class because we want the constructor
* to promote by pushing things through the server-side Date() function.
*
* @author [email protected] (Noel Gorelick)
*/

goog.provide('ee.Date');
Expand Down
1 change: 1 addition & 0 deletions javascript/src/deserializer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* @fileoverview A deserializer that decodes EE object trees from JSON DAGs.
*
* @author [email protected] (Max Shawabkeh)
*/

goog.provide('ee.Deserializer');
Expand Down
1 change: 1 addition & 0 deletions javascript/src/dictionary.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* @fileoverview A wrapper for dicts.
* @author [email protected] (Noel Gorelick)
*/

goog.provide('ee.Dictionary');
Expand Down
Loading

0 comments on commit 1baca88

Please sign in to comment.