This commit is contained in:
Ben Galin 2020-11-18 17:03:31 -08:00
parent f0424abe81
commit fe4e5d40f9
19 changed files with 2012 additions and 3178 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "@google/earthengine",
"version": "0.1.242",
"version": "0.1.243",
"description": "JavaScript client for Google Earth Engine API.",
"author": "Google LLC",
"license": "Apache-2.0",

View File

@ -26,8 +26,7 @@ const {PromiseRequestService} = goog.require('eeapiclient.promise_request_servic
const apiclient = {};
const API_CLIENT_VERSION = '0.1.242';
const LEGACY_DOWNLOAD_REGEX = /^\/(table).*/;
const API_CLIENT_VERSION = '0.1.243';
exports.VERSION = apiVersion.VERSION;
exports.API_CLIENT_VERSION = API_CLIENT_VERSION;
@ -402,21 +401,6 @@ apiclient.getProject = function() {
return apiclient.project_;
};
/**
* Enables use of the Cloud API when making requests.
* @param {boolean} enable
*/
apiclient.setCloudApiEnabled = function(enable) {
apiclient.cloudApiEnabled_ = enable;
};
/**
* @return {boolean} True if the Cloud API is enabled.
*/
apiclient.getCloudApiEnabled = function() {
return apiclient.cloudApiEnabled_;
};
/**
* Constructs a URL for API requests that is safe to use in both browser and
@ -452,10 +436,7 @@ apiclient.getSafeApiUrl = function() {
apiclient.setAuthToken = function(
clientId, tokenType, accessToken, expiresIn, extraScopes, callback,
updateAuthLibrary) {
const scopes = [apiclient.AUTH_SCOPE_];
if (apiclient.cloudApiEnabled_) {
scopes.push(apiclient.CLOUD_PLATFORM_SCOPE_);
}
const scopes = [apiclient.AUTH_SCOPE_, apiclient.CLOUD_PLATFORM_SCOPE_];
if (extraScopes) {
array.extend(scopes, extraScopes);
array.removeDuplicates(scopes);
@ -514,7 +495,7 @@ apiclient.refreshAuthToken = function(success, error, onImmediateFailed) {
if (result.error == 'immediate_failed' && onImmediateFailed) {
onImmediateFailed();
} else {
if (apiclient.cloudApiEnabled_ && 'window' in goog.global) {
if ('window' in goog.global) {
try {
// Refresh the library auth token and handle error propagation.
apiclient.ensureAuthLibLoaded_(function() {
@ -650,9 +631,7 @@ apiclient.initialize = function(apiBaseUrl, tileBaseUrl, xsrfToken) {
if (xsrfToken !== undefined) { // Passing an explicit null clears it.
apiclient.xsrfToken_ = xsrfToken;
}
if (apiclient.cloudApiEnabled_) {
apiclient.setProject(apiclient.getProject() || apiclient.DEFAULT_PROJECT_);
}
apiclient.setProject(apiclient.getProject() || apiclient.DEFAULT_PROJECT_);
apiclient.initialized_ = true;
};
@ -773,9 +752,7 @@ apiclient.send = function(
const headers = {
'Content-Type': contentType,
};
const forceLegacyApi = LEGACY_DOWNLOAD_REGEX.test(path);
if (API_CLIENT_VERSION && apiclient.getCloudApiEnabled() &&
!forceLegacyApi) {
if (API_CLIENT_VERSION) {
let version = API_CLIENT_VERSION;
headers[apiclient.API_CLIENT_VERSION_HEADER] = 'ee-js/' + version;
}
@ -801,18 +778,12 @@ apiclient.send = function(
params.add('key', apiclient.cloudApiKey_);
}
if (apiclient.cloudApiEnabled_) {
if (profileHookAtCallTime) {
headers[apiclient.PROFILE_REQUEST_HEADER] = '1';
}
if (apiclient.getProject() &&
apiclient.getProject() !== apiclient.DEFAULT_PROJECT_ &&
!forceLegacyApi) {
headers[apiclient.USER_PROJECT_OVERRIDE_HEADER_] = apiclient.getProject();
}
} else
if (profileHookAtCallTime) {
params.add('profiling', '1'); // Request profiling results.
headers[apiclient.PROFILE_REQUEST_HEADER] = '1';
}
if (apiclient.getProject() &&
apiclient.getProject() !== apiclient.DEFAULT_PROJECT_) {
headers[apiclient.USER_PROJECT_OVERRIDE_HEADER_] = apiclient.getProject();
}
params = apiclient.paramAugmenter_(params, path);
@ -989,12 +960,6 @@ apiclient.handleResponse_ = function(
if (profileId && profileHook) {
profileHook(profileId);
}
const getData = (response) => {
if (apiclient.cloudApiEnabled_) {
return response;
}
return response['data'];
};
const parseJson = (body) => {
try {
const response = JSON.parse(body);
@ -1024,7 +989,7 @@ apiclient.handleResponse_ = function(
if (contentType === 'application/json' || contentType === 'text/json') {
const response = parseJson(responseText);
if (response.parsed) {
data = getData(response.parsed);
data = response.parsed;
if (data === undefined) {
errorMessage = 'Malformed response: ' + responseText;
}
@ -1037,7 +1002,7 @@ apiclient.handleResponse_ = function(
apiclient.parseBatchReply(typeHeader, responseText, (id, status, text) => {
const response = parseJson(text);
if (response.parsed) {
data[id] = getData(response.parsed);
data[id] = response.parsed;
}
const error = (response.parsed ? '' : response) || statusError(status);
if (error) {
@ -1503,12 +1468,6 @@ apiclient.STORAGE_SCOPE_ =
*/
apiclient.cloudApiKey_ = null;
/**
* Enables the Cloud API library.
* @private {boolean}
*/
apiclient.cloudApiEnabled_ = true;
/**
* Whether the library has been initialized.
@ -1668,8 +1627,6 @@ exports.setApiKey = apiclient.setApiKey;
exports.getApiKey = apiclient.getApiKey;
exports.setProject = apiclient.setProject;
exports.getProject = apiclient.getProject;
exports.setCloudApiEnabled = apiclient.setCloudApiEnabled;
exports.getCloudApiEnabled = apiclient.getCloudApiEnabled;
exports.DEFAULT_PROJECT = apiclient.DEFAULT_PROJECT_;
exports.PROFILE_HEADER = apiclient.PROFILE_HEADER;
exports.PROFILE_REQUEST_HEADER = apiclient.PROFILE_REQUEST_HEADER;

View File

@ -12,7 +12,6 @@ const Geometry = goog.require('ee.Geometry');
const GoogPromise = goog.require('goog.Promise');
const Image = goog.require('ee.Image');
const ImageCollection = goog.require('ee.ImageCollection');
const apiclient = goog.require('ee.apiclient');
const data = goog.require('ee.data');
const eeArguments = goog.require('ee.arguments');
const googArray = goog.require('goog.array');
@ -445,8 +444,7 @@ Export.resolveRegionParam = function(params) {
if (error) {
reject(error);
} else {
if (apiclient.getCloudApiEnabled() &&
params['type'] === ExportType.IMAGE) {
if (params['type'] === ExportType.IMAGE) {
params['region'] = new Geometry(regionInfo);
} else {
params['region'] = Export.serializeRegion(regionInfo);
@ -456,8 +454,7 @@ Export.resolveRegionParam = function(params) {
});
});
}
if (apiclient.getCloudApiEnabled() &&
params['type'] === ExportType.IMAGE) {
if (params['type'] === ExportType.IMAGE) {
params['region'] = new Geometry(region);
} else {
params['region'] = Export.serializeRegion(region);

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
import * as httpCors from 'goog:goog.net.rpc.HttpCors'; // from //javascript/closure/net/rpc:httpcors
import * as httpCors from 'goog:goog.net.rpc.HttpCors'; // from //third_party/javascript/closure/net/rpc:httpcors
import {GeneratedQueryParams} from './generated_types';

View File

@ -24,7 +24,7 @@ ee.rpc_convert_batch.ExportDestination = {
/**
* Converts a legacy ExportParameters into an Cloud API ExportImageRequest.
* Converts a legacy ExportParameters into a Cloud API ExportImageRequest.
*
* @param {!Object} params A parameter list representing a ExportParameters
* taken from an export TaskConfig.
@ -65,7 +65,7 @@ ee.rpc_convert_batch.taskToExportImageRequest = function(params) {
/**
* Converts a legacy ExportParameters into an Cloud API ExportTableRequest.
* Converts a legacy ExportParameters into a Cloud API ExportTableRequest.
*
* @param {!Object} params A parameter list representing a ExportParameters
* taken from an export TaskConfig.
@ -111,7 +111,7 @@ ee.rpc_convert_batch.taskToExportTableRequest = function(params) {
/**
* Converts a legacy ExportParameters into an Cloud API ExportVideoRequest.
* Converts a legacy ExportParameters into a Cloud API ExportVideoRequest.
*
* @param {!Object} params A parameter list representing a ExportParameters
* taken from an export TaskConfig.
@ -137,7 +137,7 @@ ee.rpc_convert_batch.taskToExportVideoRequest = function(params) {
/**
* Converts a legacy ExportParameters into an Cloud API ExportMapRequest.
* Converts a legacy ExportParameters into a Cloud API ExportMapRequest.
*
* @param {!Object} params A parameter list representing a ExportParameters
* taken from an export TaskConfig.
@ -160,7 +160,7 @@ ee.rpc_convert_batch.taskToExportMapRequest = function(params) {
/**
* Converts a legacy ExportParameters into an Cloud API ExportVideoMapRequest.
* Converts a legacy ExportParameters into a Cloud API ExportVideoMapRequest.
*
* @param {!Object} params A parameter list representing a ExportParameters
* taken from an export TaskConfig.

View File

@ -195,14 +195,10 @@ ee.FeatureCollection.prototype.getInfo = function(opt_callback) {
*/
ee.FeatureCollection.prototype.getDownloadURL = function(
opt_format, opt_selectors, opt_filename, opt_callback) {
var args = ee.arguments.extractFromFunction(
const args = ee.arguments.extractFromFunction(
ee.FeatureCollection.prototype.getDownloadURL, arguments);
var request = {};
if (ee.data.getCloudApiEnabled()) {
request['table'] = this;
} else {
request['table'] = this.serialize();
}
const request = {};
request['table'] = this;
if (args['format']) {
request['format'] = args['format'].toUpperCase();
}

View File

@ -17,7 +17,6 @@ goog.require('ee.data');
goog.require('ee.data.images');
goog.require('ee.rpc_node');
goog.require('goog.array');
goog.require('goog.json');
goog.require('goog.object');
@ -233,8 +232,7 @@ ee.Image.prototype.getDownloadURL = function(params, opt_callback) {
const args = ee.arguments.extractFromFunction(
ee.Image.prototype.getDownloadURL, arguments);
const request = args['params'] ? goog.object.clone(args['params']) : {};
request['image'] =
ee.data.getCloudApiEnabled() ? this : this.serialize(/* legacy = */ true);
request['image'] = this;
if (args['callback']) {
const callback = args['callback'];
ee.data.getDownloadId(request, (downloadId, error) => {
@ -272,27 +270,10 @@ ee.Image.prototype.getThumbId = function(params, opt_callback) {
const args = ee.arguments.extractFromFunction(
ee.Image.prototype.getDownloadURL, arguments);
let request = args['params'] ? goog.object.clone(args['params']) : {};
if (ee.data.getCloudApiEnabled()) {
const extra = {};
let image = ee.data.images.applyCrsAndTransform(this, request);
image =
ee.data.images.applySelectionAndScale(image, request, extra);
request = ee.data.images.applyVisualization(image, extra);
} else {
request = ee.data.images.applyVisualization(this, request);
if (request['region']) {
if (request['region'] instanceof ee.Geometry) {
request['region'] = request['region'].toGeoJSON();
}
if (Array.isArray(request['region']) ||
ee.Types.isRegularObject(request['region'])) {
request['region'] = goog.json.serialize(request['region']);
} else if (typeof request['region'] !== 'string') {
throw Error(
'The region parameter must be an array or a GeoJSON object.');
}
}
}
const extra = {};
let image = ee.data.images.applyCrsAndTransform(this, request);
image = ee.data.images.applySelectionAndScale(image, request, extra);
request = ee.data.images.applyVisualization(image, extra);
if (args['callback']) {
ee.data.getThumbId(request, args['callback']);
return null;
@ -323,8 +304,6 @@ ee.Image.prototype.getThumbId = function(params, opt_callback) {
ee.Image.prototype.getThumbURL = function(params, opt_callback) {
const args = ee.arguments.extractFromFunction(
ee.Image.prototype.getThumbURL, arguments);
// If the Cloud API is enabled, we can do cleaner handling of the parameters.
// If it isn't, we have to be bug-for-bug compatible with current behaviour.
if (args['callback']) {
const callbackWrapper = (thumbId, opt_error) => {
let thumbUrl = '';

View File

@ -10,7 +10,6 @@ goog.require('ee.ComputedObject');
goog.require('ee.Image');
goog.require('ee.List');
goog.require('ee.Types');
goog.require('ee.apiclient');
goog.require('ee.arguments');
goog.require('ee.data');
goog.require('ee.data.images');
@ -226,15 +225,13 @@ ee.ImageCollection.prototype.getThumbURL_ = function(
}
let getThumbId = ee.data.getThumbId;
if (ee.apiclient.getCloudApiEnabled()) {
switch (opt_thumbType) {
case ee.ImageCollection.ThumbTypes.VIDEO:
getThumbId = ee.data.getVideoThumbId;
break;
case ee.ImageCollection.ThumbTypes.FILMSTRIP:
getThumbId = ee.data.getFilmstripThumbId;
break;
}
switch (opt_thumbType) {
case ee.ImageCollection.ThumbTypes.VIDEO:
getThumbId = ee.data.getVideoThumbId;
break;
case ee.ImageCollection.ThumbTypes.FILMSTRIP:
getThumbId = ee.data.getFilmstripThumbId;
break;
}
if (args['callback']) {

View File

@ -7,7 +7,6 @@ goog.provide('ee.layers.TileStartEvent');
goog.provide('ee.layers.TileThrottleEvent');
goog.forwardDeclare('ee.data.PROFILE_REQUEST_HEADER');
goog.forwardDeclare('ee.data.getCloudApiEnabled');
goog.require('ee.data');
goog.require('ee.layers.AbstractOverlayStats');
goog.require('goog.array');
@ -522,10 +521,10 @@ ee.layers.AbstractTile = class extends goog.events.EventTarget {
this.xhrIo_ = new goog.net.XhrIo();
this.xhrIo_.setResponseType(goog.net.XhrIo.ResponseType.BLOB);
this.xhrIo_.listen(goog.net.EventType.COMPLETE, function(event) {
var blob = /** @type {!Blob} */ (this.xhrIo_.getResponse());
var status = this.xhrIo_.getStatus();
var HttpStatus = goog.net.HttpStatus;
this.xhrIo_.listen(goog.net.EventType.COMPLETE, (event) => {
const blob = /** @type {!Blob} */ (this.xhrIo_.getResponse());
const status = this.xhrIo_.getStatus();
const HttpStatus = goog.net.HttpStatus;
if (status == HttpStatus.TOO_MANY_REQUESTS) {
this.setStatus(ee.layers.AbstractTile.Status.THROTTLED);
}
@ -533,29 +532,27 @@ ee.layers.AbstractTile = class extends goog.events.EventTarget {
if (HttpStatus.isSuccess(status)) {
// Normalize case in headers so lookups can be naïve — XhrIo does not.
const sourceResponseHeaders = {};
goog.object.forEach(
this.xhrIo_.getResponseHeaders(), function(value, name) {
sourceResponseHeaders[name.toLowerCase()] = value;
});
goog.object.forEach(this.xhrIo_.getResponseHeaders(), (value, name) => {
sourceResponseHeaders[name.toLowerCase()] = value;
});
this.sourceResponseHeaders = sourceResponseHeaders;
this.sourceData = blob;
this.finishLoad();
} else if (blob) {
var reader = new goog.fs.FileReader();
reader.listen(goog.fs.FileReader.EventType.LOAD_END, function() {
const reader = new goog.fs.FileReader();
reader.listen(goog.fs.FileReader.EventType.LOAD_END, () => {
this.retryLoad(/** @type {string} */ (reader.getResult()));
}, undefined, this);
}, undefined);
reader.readAsText(blob);
} else {
this.retryLoad('Failed to load tile.');
}
}, false, this);
}, false);
this.xhrIo_.listenOnce(
goog.net.EventType.READY, goog.partial(goog.dispose, this.xhrIo_));
if (this.sourceUrl && this.sourceUrl.endsWith('&profiling=1') &&
ee.data.getCloudApiEnabled()) {
if (this.sourceUrl && this.sourceUrl.endsWith('&profiling=1')) {
this.sourceUrl = this.sourceUrl.replace('&profiling=1', '');
this.xhrIo_.headers.set(ee.data.PROFILE_REQUEST_HEADER, '1');
}

View File

@ -1,338 +0,0 @@
/**
* Packages are a set of saved algorithms.
*
* The contents of a package are stored as individual assets in a folder.
* A package is intialized by synchronously retrieving the folder's contents.
* The folder will contain 1 signature for each saved algorithm. A
* SavedFunction object is created for each saved algoirhtm and is wrapped
* with a real JavaScript function to make it callable. SavedFunction
* is just a proxy for a call to LoadAlgorithmById().
*
* Adding an algorithm to a package requires specifying signature information
* identifying types for the arguments and return value. It's also recommended
* that the algorithm and arguments be documented using 'description' and
* 'docs' fields when building the signature.
*
* When the package is being saved, each of the user's functions is replaced
* with a SavedFunction object, and only then are the user's original functions
* evaluated, to allow the user's functions to call each other.
*
* Packages are cached so they don't have to be retrieved from the server
* multiple times.
*
* WARNING: In the current playground implementation, ee.Package is injected
* into the user's VM as JavaScript to get around limitations in Caja related
* to a bunch of functions being generated at runtime. This means:
* 1) no closure functions are available. The lines in this file beginning
* with "^goog" are automatically stripped.
* 2) The package cache is only retained for the duration of 1 script execution.
*
*/
goog.provide('ee.Package');
goog.require('ee.ApiFunction');
goog.require('ee.CustomFunction');
goog.require('ee.SavedFunction');
goog.require('ee.arguments');
goog.require('ee.data');
goog.requireType('ee.Function.Signature');
/**
* Create a package.
*
* If opt_path is specified, and this package isn't cached, it is
* synchronously loaded from the asset store. If no path is specified,
* a new, empty package is created.
*
* @param {string=} opt_path The asset ID of an existing package.
*
* @constructor
* TODO(user): Add an at-export annotations once packages are ready.
*/
ee.Package = function(opt_path) {
// If this package has already been loaded, return it.
if (opt_path && ee.Package.importedPackages_[opt_path]) {
return ee.Package.importedPackages_[opt_path];
}
// Constructor safety.
if (!(this instanceof ee.Package)) {
return new ee.Package(opt_path);
}
if (opt_path) {
// Initialize this package with the contents from the asset store.
//
// We currently have to block on initialization because there's nothing to
// intercept if a user tries to use a member of this package immediately.
//
// TODO(user): Handle loading constants in the folder.
var contents = ee.Package.getFolder(opt_path);
for (var i = 0; i < contents.length; i++) {
var parts = contents[i]['id'].split('/');
var name = parts[parts.length - 1];
var signature = /** @type {ee.Function.Signature} */ (contents[i]);
this[name] = ee.Package.makeInvocation_(opt_path, name, signature);
}
// Add this to the list of packages so all calls get the same instance.
ee.Package.importedPackages_[opt_path] = this;
}
};
/**
* A cache of the packages that have already been loaded.
* @type {Object.<ee.Package>}
* @private
*/
ee.Package.importedPackages_ = {};
/**
* Add a user's function to a package. The function will not be callable
* until the package has been saved.
*
* @param {string|ee.Function.Signature} signature The function's signature,
* or a C-style function declaration string, to construct a signature from.
* @param {Function} body The function's body.
* @return {!Function} The newly added function.
*/
ee.Package.makeFunction = function(signature, body) {
if (typeof(signature) == 'string') {
signature = ee.Package.decodeDecl(/** @type {string} */ (signature));
}
// We can't run the function yet as it may use other functions in the package.
var func = function() { throw Error('Package not saved.'); };
func['body'] = body;
func['signature'] = signature;
return func;
};
/**
* Save a package.
*
* Serialize the contents of a package to the asset store. This is a bit
* tricky, because we need functions in a package to be able to refer to
* each other. To enable this, we do the following:
*
* 1) Swap out all the user's functions with SavedFunctions (so there's
* something in the package for each of the user's function to call.)
* 2) Convert the original functions to CustomFunctions, (which evaluates
* them with placeholder variables).
* 3) Serialize the CustomFunctions into the asset store.
*
* @param {ee.Package} pkg The package to save.
* @param {string} path The path to save the package under.
*/
ee.Package.save = function(pkg, path) {
var args = ee.arguments.extractFromFunction(ee.Package.save, arguments);
pkg = args['pkg'];
path = args['path'];
if (!path) {
throw Error('No path specified.');
}
// Replace all the user's functions with SavedFunctions before we run them.
// This allows one function in the package to reference another.
var original = {};
for (var name in pkg) {
if (pkg.hasOwnProperty(name)) {
var member = pkg[name];
if (member instanceof Function) {
if (member['isSaved']) {
var expected = path + '/' + name;
// Skip functions that have already been converted in the
// case of adding functions to an existing package.
if (member['path'] != expected) {
// Something funny has happened. Someone might have copied
// a savedfunction from another package. Throw an error.
throw Error('Function name mismatch. Expected path: ' +
expected + ' but found: ' + member['path']);
}
} else {
if ('signature' in member) {
// Save the existing function and replace it with a SavedFunction.
original[name] = member;
pkg[name] =
ee.Package.makeInvocation_(path, name, member['signature']);
} else {
throw Error('No signature for function: ' + name);
}
}
} else {
// TODO(user): Handle saving constants in the package.
throw Error('Can\'t save constants: ' + name);
}
}
}
// Create a CustomFunction for each converted function. This will run
// the user's function.
var custom = [];
for (var name in original) {
var body = original[name]['body'];
var signature = original[name]['signature'];
var func = new ee.CustomFunction(signature, body);
var properties = {'text': body.toString()};
custom.push({
'name': name,
'algorithm': ee.ApiFunction._call(
'SavedAlgorithm', func, signature, properties)
});
}
if (custom.length) {
// Make sure the destination folder exists.
// Catching the text in the error message is a little brittle.
// TODO(user): The server should probably throw error codes instead.
try {
ee.data.createFolder(path);
} catch (e) {
if (!e.message.match(/exists/)) {
// Rethrow the error if it's not an existence error.
throw (e);
}
}
// Save everything that needs saving.
for (var index = 0; index < custom.length; index++) {
var name = custom[index]['name'];
var algorithm = custom[index]['algorithm'].serialize(/* legacy = */ true);
ee.data.createAsset(algorithm, path + '/' + name);
}
}
};
/**
* Return the contents of an Earth Engine folder.
*
* @param {string} path The folder's path.
* @return {Array.<Object>} A list of the folder's contents.
*/
ee.Package.getFolder = function(path) {
return /** @type {Array.<Object>} */(
ee.ApiFunction.lookup('LoadFolder').call(path).getInfo());
};
/**
* A helper function that attempts to decode a C-style function declaration
* string into a signature object. This doesn't do robust checking.
*
* @param {string} decl A string containing the function's declaration.
* @return {ee.Function.Signature} The newly constructed signature or null.
*/
ee.Package.decodeDecl = function(decl) {
// This is implemented as a simple parser with peek() and expect().
var parts = decl.match(/\w+|\S/g); // The tokenized input.
var cur = 0; // Tracks the current token.
// Return the next token.
var peek = function() {
return parts[cur];
};
// Expect the input specified by regex. Returns the matching text.
var expect = function(regex) {
var match = peek() && peek().match(regex);
if (match) {
cur++;
return match[0];
}
throw Error('Unable to decode declaration.');
};
// Match a function declaration of the form: TYPE NAME '(' ARGS ') ;?
var type = expect(/\w+/); // The function type
expect(/\w+/); // The function name
expect(/\(/);
var collected = [];
// Match arguments of the form: {TYPE NAME {, TYPE NAME}}
while (peek() && !peek().match('\\)')) {
if (collected.length) {
expect(',');
}
collected.push({
'type': expect(/\w+/),
'name': expect(/\w+/)
});
}
expect(/\)/);
if (peek() == ';') {
expect(';'); // Skip an optional trailing ';'
}
// If there is anything left, it is an error.
if (peek()) {
throw Error('Unable to decode declaration. Found extra trailing input.');
}
return /** @type {ee.Function.Signature} */({
'returns': type,
'args': collected
});
};
/**
* Encode a signature into a C-style string declaration. This is used
* in functions descriptions.
*
* @param {ee.Function.Signature} signature The function's signature.
* @param {string} name The function's name.
* @return {string} The string representation of this function's declaration.
*
* @private
*/
ee.Package.encodeDecl_ = function(signature, name) {
var out = [
signature['returns'],
' ',
name,
'('
];
if (signature.args) {
for (var i = 0; i < signature.args.length; i++) {
if (i > 0) {
out.push(', ');
}
out.push(signature.args[i].type + ' ' + signature.args[i].name);
}
}
out.push(')');
return out.join('');
};
/**
* Initialize a callable SavedFunction for the given signature.
* @param {string} path The path to the saved function's folder.
* @param {string} name The name of the saved function.
* @param {ee.Function.Signature} signature The function's signature,
* @return {!Function} A function making the SavedFunction callable.
* @private
*/
ee.Package.makeInvocation_ = function(path, name, signature) {
var savedFunction = new ee.SavedFunction(path + '/' + name, signature);
// A function wrapper so the savedFunction is callable.
var fn = function(var_args) {
var args = Array.prototype.slice.call(arguments);
return savedFunction.call.apply(savedFunction, args);
};
// Decorate the wrapper function with the signature and docs.
fn.toString = function() {
return signature['returns'] + ' ' + savedFunction.toString(name);
};
fn['isSaved'] = true;
return fn;
};

View File

@ -2,7 +2,6 @@ window.ee = require('../build/browser');
const [token] = __karma__.config.args;
if (token) {
ee.apiclient.setAuthToken('', 'Bearer', token, 3600, [], undefined, false);
ee.apiclient.setCloudApiEnabled(true);
} else {
throw new Error(
'Must supply a user access token in the environment ' +

View File

@ -2,7 +2,6 @@ global.ee = require('../build/main');
const token = process.env['EE_ACCESS_TOKEN'];
if (token) {
ee.apiclient.setAuthToken('', 'Bearer', token, 3600, [], undefined, false);
ee.apiclient.setCloudApiEnabled(true);
} else {
throw new Error(
'Must supply a user access token in the environment ' +

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python
"""The EE Python library."""
__version__ = '0.1.242'
__version__ = '0.1.243'
# Using lowercase function naming to match the JavaScript names.
# pylint: disable=g-bad-name

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long