@google/earthengine 0.1.384 → 0.1.386

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.
@@ -1,4 +1,3 @@
1
- // g3-format-clang
2
1
  import {Serializable, serialize} from './domain_object';
3
2
 
4
3
  export class MultipartRequest {
@@ -6,7 +5,7 @@ export class MultipartRequest {
6
5
  private _metadataPayload = '';
7
6
  private _payloadPromise: Promise<string>;
8
7
 
9
- constructor(private files: File[], private _metadata?: {}|null) {
8
+ constructor(private files: File[], private _metadata?: {} | null) {
10
9
  this._boundary = Date.now().toString();
11
10
  if (_metadata) {
12
11
  this.addMetadata(_metadata);
@@ -18,7 +17,7 @@ export class MultipartRequest {
18
17
  return this._boundary;
19
18
  }
20
19
 
21
- metadata(): {}|undefined|null {
20
+ metadata(): {} | undefined | null {
22
21
  return this._metadata;
23
22
  }
24
23
 
@@ -28,31 +27,37 @@ export class MultipartRequest {
28
27
 
29
28
  private addMetadata(metadata: {}): void {
30
29
  const json =
31
- (metadata instanceof Serializable) ? serialize(metadata) : metadata;
30
+ metadata instanceof Serializable ? serialize(metadata) : metadata;
32
31
  this._metadataPayload +=
33
- 'Content-Type: application/json; charset=utf-8\r\n\r\n' +
34
- JSON.stringify(json) + `\r\n--${this._boundary}\r\n`;
32
+ 'Content-Type: application/json; charset=utf-8\r\n\r\n' +
33
+ JSON.stringify(json) +
34
+ `\r\n--${this._boundary}\r\n`;
35
35
  }
36
36
 
37
37
  private build(): Promise<string> {
38
38
  let payload = `--${this._boundary}\r\n`;
39
39
  payload += this._metadataPayload;
40
- return Promise.all(this.files.map(f => this.encodeFile(f)))
41
- .then(filePayloads => {
42
- for (const filePayload of filePayloads) {
43
- payload += filePayload;
44
- }
45
- payload += `\r\n--${this._boundary}--`;
46
- return payload;
47
- });
40
+ return Promise.all(this.files.map((f) => this.encodeFile(f))).then(
41
+ (filePayloads) => {
42
+ for (const filePayload of filePayloads) {
43
+ payload += filePayload;
44
+ }
45
+ payload += `\r\n--${this._boundary}--`;
46
+ return payload;
47
+ },
48
+ );
48
49
  }
49
50
 
50
51
  private encodeFile(file: File): Promise<string> {
51
52
  return this.base64EncodeFile(file).then(
52
- base64Str => `Content-Type: ${file.type}\r\n` +
53
- `Content-Disposition: form-data; name="file"; filename="${
54
- encodeURIComponent(file.name)}"\r\n` +
55
- 'Content-Transfer-Encoding: base64\r\n\r\n' + base64Str);
53
+ (base64Str) =>
54
+ `Content-Type: ${file.type}\r\n` +
55
+ `Content-Disposition: form-data; name="file"; filename="${encodeURIComponent(
56
+ file.name,
57
+ )}"\r\n` +
58
+ 'Content-Transfer-Encoding: base64\r\n\r\n' +
59
+ base64Str,
60
+ );
56
61
  }
57
62
 
58
63
  private base64EncodeFile(file: File): Promise<string> {
@@ -1,20 +1,32 @@
1
- // g3-format-clang
2
- import {ApiClient, toMakeRequestParams, toMultipartMakeRequestParams} from './api_client';
3
- import {ApiClientHookFactory, getRequestHook} from './api_request_hook';
1
+ import {
2
+ ApiClient,
3
+ toMakeRequestParams,
4
+ toMultipartMakeRequestParams,
5
+ } from './api_client';
6
+ import {
7
+ ApiClientHookFactory,
8
+ getRequestHook,
9
+ } from './api_request_hook';
4
10
  import {Serializable} from './domain_object';
5
- import {GeneratedInterface, GeneratedRequestParams} from './generated_types';
11
+ import {
12
+ GeneratedInterface,
13
+ GeneratedRequestParams,
14
+ } from './generated_types';
6
15
 
7
16
  import {PromiseRequestService} from './promise_request_service';
8
17
 
9
18
  export class PromiseApiClient extends ApiClient {
10
19
  constructor(
11
- protected requestService: PromiseRequestService,
12
- protected hookFactory: ApiClientHookFactory|null = null) {
20
+ protected requestService: PromiseRequestService,
21
+ protected hookFactory: ApiClientHookFactory | null = null,
22
+ ) {
13
23
  super();
14
24
  }
15
25
 
16
26
  protected $addHooksToRequest<T>(
17
- requestParams: GeneratedRequestParams, promise: Promise<T>): Promise<T> {
27
+ requestParams: GeneratedRequestParams,
28
+ promise: Promise<T>,
29
+ ): Promise<T> {
18
30
  const hook = getRequestHook(this.hookFactory, requestParams);
19
31
  if (hook == null) {
20
32
  return promise;
@@ -22,34 +34,41 @@ export class PromiseApiClient extends ApiClient {
22
34
 
23
35
  hook.onBeforeSend();
24
36
  return promise.then(
25
- (response) => {
26
- hook.onSuccess(response);
27
- return response;
28
- },
29
- (error) => {
30
- hook.onError(error);
31
- throw error;
32
- });
37
+ (response) => {
38
+ hook.onSuccess(response);
39
+ return response;
40
+ },
41
+ (error) => {
42
+ hook.onError(error);
43
+ throw error;
44
+ },
45
+ );
33
46
  }
34
47
 
35
48
  /** Converts a gapi.client.Request to an Promise<T>. */
36
- $request<T extends Serializable|GeneratedInterface>(
37
- requestParams: GeneratedRequestParams): Promise<T> {
49
+ $request<T extends Serializable | GeneratedInterface>(
50
+ requestParams: GeneratedRequestParams,
51
+ ): Promise<T> {
38
52
  const responseCtor = requestParams.responseCtor || void 0;
39
53
  return this.$addHooksToRequest<T>(
40
- requestParams,
41
- this.requestService.send(
42
- toMakeRequestParams(requestParams), responseCtor) as Promise<T>);
54
+ requestParams,
55
+ this.requestService.send(
56
+ toMakeRequestParams(requestParams),
57
+ responseCtor,
58
+ ) as Promise<T>,
59
+ );
43
60
  }
44
61
 
45
- $uploadRequest<T extends Serializable|GeneratedInterface>(
46
- requestParams: GeneratedRequestParams): Promise<T> {
62
+ $uploadRequest<T extends Serializable | GeneratedInterface>(
63
+ requestParams: GeneratedRequestParams,
64
+ ): Promise<T> {
47
65
  const responseCtor = requestParams.responseCtor || void 0;
48
66
  return this.$addHooksToRequest<T>(
49
- requestParams,
50
- toMultipartMakeRequestParams(requestParams)
51
- .then(
52
- params => this.requestService.send(params, responseCtor) as
53
- Promise<T>));
67
+ requestParams,
68
+ toMultipartMakeRequestParams(requestParams).then(
69
+ (params) =>
70
+ this.requestService.send(params, responseCtor) as Promise<T>,
71
+ ),
72
+ );
54
73
  }
55
74
  }
@@ -1,15 +1,22 @@
1
- // g3-format-clang
2
- import {deserialize, Serializable, SerializableCtor} from './domain_object';
3
- import {MakeRequestParams, processParams} from './request_params';
1
+ import {
2
+ deserialize,
3
+ Serializable,
4
+ SerializableCtor,
5
+ } from './domain_object';
6
+ import {
7
+ MakeRequestParams,
8
+ processParams,
9
+ } from './request_params';
4
10
 
5
11
  export abstract class PromiseRequestService {
6
12
  send<T extends Serializable>(
7
- params: MakeRequestParams,
8
- responseCtor?: SerializableCtor<T>): Promise<T> {
13
+ params: MakeRequestParams,
14
+ responseCtor?: SerializableCtor<T>,
15
+ ): Promise<T> {
9
16
  processParams(params);
10
- return this.makeRequest(params).then(
11
- (response) =>
12
- responseCtor ? deserialize(responseCtor, response) : response as T);
17
+ return this.makeRequest(params).then((response) =>
18
+ responseCtor ? deserialize(responseCtor, response) : (response as T),
19
+ );
13
20
  }
14
21
 
15
22
  abstract makeRequest(params: MakeRequestParams): Promise<{}>;
@@ -1,10 +1,9 @@
1
- // g3-format-clang
2
1
  import * as httpCors from 'goog:goog.net.rpc.HttpCors';
3
2
 
4
3
  import {GeneratedQueryParams} from './generated_types';
5
4
 
6
5
  /** Available HTTP methods supported by Google APIs */
7
- export type HttpMethod = 'GET'|'POST'|'PUT'|'PATCH'|'DELETE';
6
+ export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
8
7
 
9
8
  /**
10
9
  * {@link HttpMethod} come directly from the discovery file as strings. The code
@@ -44,7 +43,7 @@ export enum StreamingType {
44
43
  NONE = 'NONE',
45
44
  CLIENT_SIDE = 'CLIENT_SIDE',
46
45
  SERVER_SIDE = 'SERVER_SIDE',
47
- BIDIRECTONAL = 'BIDIRECTONAL'
46
+ BIDIRECTONAL = 'BIDIRECTONAL',
48
47
  }
49
48
 
50
49
  /**
@@ -58,7 +57,7 @@ export interface MakeRequestParams {
58
57
  * custom HTTP methods. You can use {@link HttpMethodEnum#isHttpMethod}
59
58
  * to check if the httpMethod is of type {@link HttpMethod}.
60
59
  */
61
- httpMethod: HttpMethod|string;
60
+ httpMethod: HttpMethod | string;
62
61
  /** The id of the called method, from discovery. */
63
62
  methodId?: string;
64
63
  // tslint:disable-next-line:no-any
@@ -97,8 +96,10 @@ export function processParams(params: MakeRequestParams) {
97
96
  * therefore this function can be loose about type-checking the fields.
98
97
  */
99
98
  export function buildQueryParams(
100
- params: {}, mapping: Record<string, string>,
101
- passthroughParams: Record<string, string> = {}): GeneratedQueryParams {
99
+ params: {},
100
+ mapping: Record<string, string>,
101
+ passthroughParams: Record<string, string> = {},
102
+ ): GeneratedQueryParams {
102
103
  const paramsMap = params as unknown as GeneratedQueryParams;
103
104
 
104
105
  const urlQueryParams: GeneratedQueryParams = passthroughParams;
@@ -110,8 +111,11 @@ export function buildQueryParams(
110
111
  return urlQueryParams;
111
112
  }
112
113
 
113
- const simpleCorsAllowedHeaders: string[] =
114
- ['accept', 'accept-language', 'content-language'];
114
+ const simpleCorsAllowedHeaders: string[] = [
115
+ 'accept',
116
+ 'accept-language',
117
+ 'content-language',
118
+ ];
115
119
 
116
120
  const simpleCorsAllowedMethods: string[] = ['GET', 'HEAD', 'POST'];
117
121
 
@@ -158,8 +162,11 @@ export function bypassCorsPreflight(params: MakeRequestParams) {
158
162
  }
159
163
  }
160
164
 
161
- if (params.body != null || params.httpMethod === 'PUT' ||
162
- params.httpMethod === 'POST') {
165
+ if (
166
+ params.body != null ||
167
+ params.httpMethod === 'PUT' ||
168
+ params.httpMethod === 'POST'
169
+ ) {
163
170
  // Normally, HttpClient detects the application/json Content-Type based on
164
171
  // the body of the request. We need to explicitly set it in the
165
172
  // pre-generateEncodedHttpHeadersOverwriteParam so that the header
@@ -175,20 +182,26 @@ export function bypassCorsPreflight(params: MakeRequestParams) {
175
182
 
176
183
  if (hasUnsafeHeaders) {
177
184
  const finalParam =
178
- httpCors.generateEncodedHttpHeadersOverwriteParam(unsafeHeaders);
185
+ httpCors.generateEncodedHttpHeadersOverwriteParam(unsafeHeaders);
179
186
  addQueryParameter(params, httpCors.HTTP_HEADERS_PARAM_NAME, finalParam);
180
187
  }
181
188
  params.headers = safeHeaders;
182
189
 
183
190
  if (!simpleCorsAllowedMethods.includes(params.httpMethod)) {
184
191
  addQueryParameter(
185
- params, httpCors.HTTP_METHOD_PARAM_NAME, params.httpMethod);
192
+ params,
193
+ httpCors.HTTP_METHOD_PARAM_NAME,
194
+ params.httpMethod,
195
+ );
186
196
  params.httpMethod = 'POST';
187
197
  }
188
198
  }
189
199
 
190
200
  function addQueryParameter(
191
- params: MakeRequestParams, key: string, value: string) {
201
+ params: MakeRequestParams,
202
+ key: string,
203
+ value: string,
204
+ ) {
192
205
  if (params.queryParams) {
193
206
  params.queryParams[key] = value;
194
207
  } else {
@@ -1,7 +1,10 @@
1
- // g3-format-clang
2
1
  import 'jasmine';
3
2
 
4
- import {buildQueryParams, bypassCorsPreflight, MakeRequestParams} from './request_params';
3
+ import {
4
+ buildQueryParams,
5
+ bypassCorsPreflight,
6
+ MakeRequestParams,
7
+ } from './request_params';
5
8
 
6
9
  describe('buildQueryParams', () => {
7
10
  const PARAMS_MAP = {
@@ -100,7 +103,7 @@ describe('bypassCorsPreflight', () => {
100
103
  expect(params.headers).toEqual({'Content-Type': 'text/plain'});
101
104
  expect(params.httpMethod).toEqual('POST');
102
105
  expect(params.queryParams).toEqual({
103
- '$httpHeaders': 'Content-Type%3Aapplication%2Fjson%0D%0A'
106
+ '$httpHeaders': 'Content-Type%3Aapplication%2Fjson%0D%0A',
104
107
  });
105
108
  });
106
109
 
@@ -109,15 +112,16 @@ describe('bypassCorsPreflight', () => {
109
112
  path: 'v1/whatever',
110
113
  httpMethod: 'POST',
111
114
  methodId: 'someservice.whatever.post',
112
- headers:
113
- {'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'},
115
+ headers: {
116
+ 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
117
+ },
114
118
  };
115
119
  bypassCorsPreflight(params);
116
120
  expect(params.headers).toEqual({'Content-Type': 'text/plain'});
117
121
  expect(params.httpMethod).toEqual('POST');
118
122
  expect(params.queryParams).toEqual({
119
123
  '$httpHeaders':
120
- 'Content-Type%3Aapplication%2Fx-www-form-urlencoded%3Bcharset%3DUTF-8%0D%0A',
124
+ 'Content-Type%3Aapplication%2Fx-www-form-urlencoded%3Bcharset%3DUTF-8%0D%0A',
121
125
  });
122
126
  });
123
127
 
@@ -134,26 +138,25 @@ describe('bypassCorsPreflight', () => {
134
138
  expect(params.httpMethod).toEqual('POST');
135
139
  expect(params.queryParams).toEqual({
136
140
  '$httpMethod': 'PUT',
137
- '$httpHeaders': 'Content-Type%3Aapplication%2Fjson%0D%0A'
141
+ '$httpHeaders': 'Content-Type%3Aapplication%2Fjson%0D%0A',
138
142
  });
139
143
  });
140
144
 
141
- it('handles would-trigger-preflight cors method with optional query params',
142
- () => {
143
- const params: MakeRequestParams = {
144
- path: 'v1/whatever',
145
- httpMethod: 'PUT',
146
- methodId: 'someservice.whatever.put',
147
- headers: {},
148
- };
149
- bypassCorsPreflight(params);
150
- expect(params.headers).toEqual({'Content-Type': 'text/plain'});
151
- expect(params.httpMethod).toEqual('POST');
152
- expect(params.queryParams).toEqual({
153
- '$httpMethod': 'PUT',
154
- '$httpHeaders': 'Content-Type%3Aapplication%2Fjson%0D%0A'
155
- });
156
- });
145
+ it('handles would-trigger-preflight cors method with optional query params', () => {
146
+ const params: MakeRequestParams = {
147
+ path: 'v1/whatever',
148
+ httpMethod: 'PUT',
149
+ methodId: 'someservice.whatever.put',
150
+ headers: {},
151
+ };
152
+ bypassCorsPreflight(params);
153
+ expect(params.headers).toEqual({'Content-Type': 'text/plain'});
154
+ expect(params.httpMethod).toEqual('POST');
155
+ expect(params.queryParams).toEqual({
156
+ '$httpMethod': 'PUT',
157
+ '$httpHeaders': 'Content-Type%3Aapplication%2Fjson%0D%0A',
158
+ });
159
+ });
157
160
 
158
161
  it('handles simple cors headers', () => {
159
162
  const params: MakeRequestParams = {
@@ -183,57 +186,55 @@ describe('bypassCorsPreflight', () => {
183
186
  expect(params.queryParams).toEqual({'$httpHeaders': 'foo%3Abar%0D%0A'});
184
187
  });
185
188
 
186
- it('handles would-trigger-preflight cors headers without safe headers',
187
- () => {
188
- const params: MakeRequestParams = {
189
- path: 'v1/whatever',
190
- httpMethod: 'GET',
191
- methodId: 'someservice.whatever.get',
192
- headers: {'foo': 'bar'},
193
- queryParams: {},
194
- };
195
- bypassCorsPreflight(params);
196
- expect(params.headers).toEqual({});
197
- expect(params.httpMethod).toEqual('GET');
198
- expect(params.queryParams).toEqual({'$httpHeaders': 'foo%3Abar%0D%0A'});
199
- });
200
-
201
- it('handles would-trigger-preflight cors headers with existing query params',
202
- () => {
203
- const params: MakeRequestParams = {
204
- path: 'v1/whatever',
205
- httpMethod: 'GET',
206
- methodId: 'someservice.whatever.get',
207
- headers: {'accept-language': 'de', 'foo': 'bar', 'a': 'b'},
208
- queryParams: {'hello': 'world'},
209
- };
210
- bypassCorsPreflight(params);
211
- expect(params.headers).toEqual({'accept-language': 'de'});
212
- expect(params.httpMethod).toEqual('GET');
213
- expect(params.queryParams).toEqual({
214
- 'hello': 'world',
215
- '$httpHeaders': 'foo%3Abar%0D%0Aa%3Ab%0D%0A'
216
- });
217
- });
218
-
219
- it('handles would-trigger-preflight cors headers and method with existing query params',
220
- () => {
221
- const params: MakeRequestParams = {
222
- path: 'v1/whatever',
223
- httpMethod: 'PUT',
224
- methodId: 'someservice.whatever.put',
225
- headers: {'accept-language': 'de', 'foo': 'bar'},
226
- queryParams: {'hello': 'world'},
227
- };
228
- bypassCorsPreflight(params);
229
- expect(params.headers)
230
- .toEqual({'accept-language': 'de', 'Content-Type': 'text/plain'});
231
- expect(params.httpMethod).toEqual('POST');
232
- expect(params.queryParams).toEqual({
233
- 'hello': 'world',
234
- '$httpHeaders':
235
- 'foo%3Abar%0D%0AContent-Type%3Aapplication%2Fjson%0D%0A',
236
- '$httpMethod': 'PUT'
237
- });
238
- });
189
+ it('handles would-trigger-preflight cors headers without safe headers', () => {
190
+ const params: MakeRequestParams = {
191
+ path: 'v1/whatever',
192
+ httpMethod: 'GET',
193
+ methodId: 'someservice.whatever.get',
194
+ headers: {'foo': 'bar'},
195
+ queryParams: {},
196
+ };
197
+ bypassCorsPreflight(params);
198
+ expect(params.headers).toEqual({});
199
+ expect(params.httpMethod).toEqual('GET');
200
+ expect(params.queryParams).toEqual({'$httpHeaders': 'foo%3Abar%0D%0A'});
201
+ });
202
+
203
+ it('handles would-trigger-preflight cors headers with existing query params', () => {
204
+ const params: MakeRequestParams = {
205
+ path: 'v1/whatever',
206
+ httpMethod: 'GET',
207
+ methodId: 'someservice.whatever.get',
208
+ headers: {'accept-language': 'de', 'foo': 'bar', 'a': 'b'},
209
+ queryParams: {'hello': 'world'},
210
+ };
211
+ bypassCorsPreflight(params);
212
+ expect(params.headers).toEqual({'accept-language': 'de'});
213
+ expect(params.httpMethod).toEqual('GET');
214
+ expect(params.queryParams).toEqual({
215
+ 'hello': 'world',
216
+ '$httpHeaders': 'foo%3Abar%0D%0Aa%3Ab%0D%0A',
217
+ });
218
+ });
219
+
220
+ it('handles would-trigger-preflight cors headers and method with existing query params', () => {
221
+ const params: MakeRequestParams = {
222
+ path: 'v1/whatever',
223
+ httpMethod: 'PUT',
224
+ methodId: 'someservice.whatever.put',
225
+ headers: {'accept-language': 'de', 'foo': 'bar'},
226
+ queryParams: {'hello': 'world'},
227
+ };
228
+ bypassCorsPreflight(params);
229
+ expect(params.headers).toEqual({
230
+ 'accept-language': 'de',
231
+ 'Content-Type': 'text/plain',
232
+ });
233
+ expect(params.httpMethod).toEqual('POST');
234
+ expect(params.queryParams).toEqual({
235
+ 'hello': 'world',
236
+ '$httpHeaders': 'foo%3Abar%0D%0AContent-Type%3Aapplication%2Fjson%0D%0A',
237
+ '$httpMethod': 'PUT',
238
+ });
239
+ });
239
240
  });