@google/earthengine 1.6.0 → 1.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@google/earthengine",
3
- "version": "1.6.0",
3
+ "version": "1.6.2",
4
4
  "description": "JavaScript client for Google Earth Engine API.",
5
5
  "author": "Google LLC",
6
6
  "license": "Apache-2.0",
package/src/apiclient.js CHANGED
@@ -24,7 +24,7 @@ const {trustedResourceUrl} = goog.require('safevalues.index');
24
24
  /** @namespace */
25
25
  const apiclient = {};
26
26
 
27
- const API_CLIENT_VERSION = '1.6.0';
27
+ const API_CLIENT_VERSION = '1.6.2';
28
28
 
29
29
  exports.VERSION = apiVersion.VERSION;
30
30
  exports.API_CLIENT_VERSION = API_CLIENT_VERSION;
@@ -1,25 +1,54 @@
1
1
  import {GeneratedRequestParams} from './generated_types';
2
2
 
3
+ /**
4
+ * Interface for a hook that can be used to intercept and modify API requests
5
+ * and responses.
6
+ */
3
7
  export interface ApiClientRequestHook {
4
- /** Called once before each API send. */
8
+ /**
9
+ * Called once before each API send.
10
+ */
5
11
  onBeforeSend(): void;
6
- /** Called after each successful API response. */
12
+ /**
13
+ * Called after each successful API response.
14
+ */
7
15
  onSuccess<T>(response: T): void;
8
- /** Called after each unsuccessful API response. */
16
+ /**
17
+ * Called after each unsuccessful API response.
18
+ */
9
19
  onError(error: {}): void;
20
+ /**
21
+ * Called after each API request is finalized.
22
+ * In some cases, the caller may cancel the API call which will not trigger
23
+ * any of the success or error callbacks. To handle such cases, the onFinalize
24
+ * callback can be used.
25
+ * OnFinalize will have equal number of calls as onBeforeSend.
26
+ */
27
+ onFinalize?: () => void;
10
28
  }
11
29
 
30
+ /**
31
+ * Interface for a factory that can be used to create {@link
32
+ * ApiClientRequestHook} instances.
33
+ */
12
34
  export abstract class ApiClientHookFactory {
13
35
  abstract getRequestHook(
14
36
  requestParams: GeneratedRequestParams,
15
37
  ): ApiClientRequestHook;
16
38
  }
17
39
 
40
+ /**
41
+ * Interface for a constructor that can be used to create {@link
42
+ * ApiClientHookFactory} instances.
43
+ */
18
44
  export interface ApiClientHookFactoryCtor {
19
45
  // tslint:disable-next-line:no-any ctor args are of any type
20
46
  new (...args: any[]): ApiClientHookFactory;
21
47
  }
22
48
 
49
+ /**
50
+ * Default implementation of {@link ApiClientHookFactory} that does nothing.
51
+ */
23
52
  export class DefaultApiClientHookFactory implements ApiClientHookFactory {
24
53
  getRequestHook(requestParams: GeneratedRequestParams): ApiClientRequestHook {
25
54
  return {
@@ -426,9 +426,7 @@ function deepCopyValue<T extends {}>(
426
426
  } else if (value instanceof NullClass) {
427
427
  deserialized = null as unknown as {};
428
428
  } else if (typeof value === 'object') {
429
- // TODO(user): Assert as a type, declared interface, or `unknown`.
430
- // tslint:disable-next-line:ban-types no-unnecessary-type-assertion
431
- deserialized = JSON.parse(JSON.stringify(value)) as AnyDuringMigration;
429
+ deserialized = JSON.parse(JSON.stringify(value)) as object;
432
430
  } else {
433
431
  deserialized = value;
434
432
  }
@@ -33,16 +33,20 @@ export class PromiseApiClient extends ApiClient {
33
33
  }
34
34
 
35
35
  hook.onBeforeSend();
36
- return promise.then(
37
- (response) => {
38
- hook.onSuccess(response);
39
- return response;
40
- },
41
- (error) => {
42
- hook.onError(error);
43
- throw error;
44
- },
45
- );
36
+ return promise
37
+ .then(
38
+ (response) => {
39
+ hook.onSuccess(response);
40
+ return response;
41
+ },
42
+ (error) => {
43
+ hook.onError(error);
44
+ throw error;
45
+ },
46
+ )
47
+ .finally(() => {
48
+ hook.onFinalize?.();
49
+ });
46
50
  }
47
51
 
48
52
  /** Converts a gapi.client.Request to an Promise<T>. */