@google/earthengine 0.1.384 → 0.1.385
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/.tmp/BUILD +2 -2
- package/.tmp/METADATA +4 -4
- package/.tmp/VERSION_BUILD +2 -2
- package/build/browser.js +159 -161
- package/build/ee_api_js.js +215 -215
- package/build/ee_api_js_debug.js +137 -138
- package/build/ee_api_js_npm.js +159 -161
- package/build/main.js +159 -161
- package/package.json +1 -1
- package/src/apiclient.js +1 -1
- package/src/eeapiclient/api_client.ts +17 -14
- package/src/eeapiclient/api_request_hook.ts +7 -6
- package/src/eeapiclient/domain_object.ts +171 -96
- package/src/eeapiclient/generated_types.ts +9 -4
- package/src/eeapiclient/multipart_request.ts +23 -18
- package/src/eeapiclient/promise_api_client.ts +46 -27
- package/src/eeapiclient/promise_request_service.ts +15 -8
- package/src/eeapiclient/request_params.ts +26 -13
- package/src/eeapiclient/request_params_test.ts +77 -76
package/package.json
CHANGED
package/src/apiclient.js
CHANGED
|
@@ -25,7 +25,7 @@ const {trustedResourceUrl} = goog.require('safevalues');
|
|
|
25
25
|
/** @namespace */
|
|
26
26
|
const apiclient = {};
|
|
27
27
|
|
|
28
|
-
const API_CLIENT_VERSION = '0.1.
|
|
28
|
+
const API_CLIENT_VERSION = '0.1.385';
|
|
29
29
|
|
|
30
30
|
exports.VERSION = apiVersion.VERSION;
|
|
31
31
|
exports.API_CLIENT_VERSION = API_CLIENT_VERSION;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// g3-format-clang
|
|
2
1
|
import {Serializable, serialize} from './domain_object';
|
|
3
2
|
import {GeneratedRequestParams} from './generated_types';
|
|
4
3
|
import {MultipartRequest} from './multipart_request';
|
|
@@ -13,36 +12,41 @@ export abstract class ApiClient {
|
|
|
13
12
|
$validateParameter(param: any, pattern: RegExp): void {
|
|
14
13
|
const paramStr = String(param);
|
|
15
14
|
if (!pattern.test(paramStr)) {
|
|
16
|
-
throw new Error(
|
|
17
|
-
|
|
15
|
+
throw new Error(
|
|
16
|
+
`parameter [${paramStr}] does not match pattern [${pattern.toString()}]`,
|
|
17
|
+
);
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
export function toMakeRequestParams(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
export function toMakeRequestParams(
|
|
23
|
+
requestParams: GeneratedRequestParams,
|
|
24
|
+
): MakeRequestParams {
|
|
25
|
+
const body =
|
|
26
|
+
requestParams.body instanceof Serializable
|
|
27
|
+
? serialize(requestParams.body)
|
|
28
|
+
: requestParams.body;
|
|
27
29
|
return {
|
|
28
30
|
path: requestParams.path,
|
|
29
31
|
httpMethod: requestParams.httpMethod,
|
|
30
32
|
methodId: requestParams.methodId,
|
|
31
33
|
body: body as Serializable,
|
|
32
34
|
queryParams: requestParams.queryParams,
|
|
33
|
-
streamingType:
|
|
34
|
-
|
|
35
|
+
streamingType:
|
|
36
|
+
requestParams.streamingType &&
|
|
37
|
+
(requestParams.streamingType as StreamingType),
|
|
35
38
|
} as MakeRequestParams;
|
|
36
39
|
}
|
|
37
40
|
|
|
38
41
|
export function toMultipartMakeRequestParams(
|
|
39
|
-
|
|
42
|
+
requestParams: GeneratedRequestParams,
|
|
43
|
+
): Promise<MakeRequestParams> {
|
|
40
44
|
if (!(requestParams.body instanceof MultipartRequest)) {
|
|
41
45
|
throw new Error(`${requestParams.path} request must be a MultipartRequest`);
|
|
42
46
|
}
|
|
43
47
|
|
|
44
48
|
const multipartRequest = requestParams.body;
|
|
45
|
-
return multipartRequest.payloadPromise().then(body => {
|
|
49
|
+
return multipartRequest.payloadPromise().then((body) => {
|
|
46
50
|
const queryParams = requestParams.queryParams ?? {};
|
|
47
51
|
return {
|
|
48
52
|
path: requestParams.path,
|
|
@@ -51,8 +55,7 @@ export function toMultipartMakeRequestParams(
|
|
|
51
55
|
queryParams: {...queryParams, 'uploadType': 'multipart'},
|
|
52
56
|
headers: {
|
|
53
57
|
'X-Goog-Upload-Protocol': 'multipart',
|
|
54
|
-
'Content-Type':
|
|
55
|
-
`multipart/related; boundary=${multipartRequest.boundary()}`
|
|
58
|
+
'Content-Type': `multipart/related; boundary=${multipartRequest.boundary()}`,
|
|
56
59
|
},
|
|
57
60
|
body,
|
|
58
61
|
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// g3-format-clang
|
|
2
1
|
import {GeneratedRequestParams} from './generated_types';
|
|
3
2
|
|
|
4
3
|
export interface ApiClientRequestHook {
|
|
@@ -11,13 +10,14 @@ export interface ApiClientRequestHook {
|
|
|
11
10
|
}
|
|
12
11
|
|
|
13
12
|
export abstract class ApiClientHookFactory {
|
|
14
|
-
abstract getRequestHook(
|
|
15
|
-
|
|
13
|
+
abstract getRequestHook(
|
|
14
|
+
requestParams: GeneratedRequestParams,
|
|
15
|
+
): ApiClientRequestHook;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export interface ApiClientHookFactoryCtor {
|
|
19
19
|
// tslint:disable-next-line:no-any ctor args are of any type
|
|
20
|
-
new(...args: any[]): ApiClientHookFactory;
|
|
20
|
+
new (...args: any[]): ApiClientHookFactory;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export class DefaultApiClientHookFactory implements ApiClientHookFactory {
|
|
@@ -35,8 +35,9 @@ export class DefaultApiClientHookFactory implements ApiClientHookFactory {
|
|
|
35
35
|
* from a {@link ApiClientHookFactory}.
|
|
36
36
|
*/
|
|
37
37
|
export function getRequestHook(
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
factory: ApiClientHookFactory | null | undefined,
|
|
39
|
+
requestParams: GeneratedRequestParams,
|
|
40
|
+
): ApiClientRequestHook | null {
|
|
40
41
|
if (factory == null) {
|
|
41
42
|
return null;
|
|
42
43
|
}
|
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* g3-format-clang
|
|
3
2
|
* Utility map for ClassMetadata to describe how to create instances of child
|
|
4
3
|
* properties.
|
|
5
4
|
*/
|
|
6
5
|
|
|
7
6
|
export type ObjectMap<T> = {
|
|
8
|
-
[key: string]: T
|
|
7
|
+
[key: string]: T;
|
|
9
8
|
};
|
|
10
9
|
|
|
11
10
|
export interface ObjectMapMetadata {
|
|
12
11
|
isPropertyArray: boolean;
|
|
13
12
|
isValueArray: boolean;
|
|
14
13
|
isSerializable: boolean;
|
|
15
|
-
ctor: SerializableCtor<ISerializable
|
|
14
|
+
ctor: SerializableCtor<ISerializable> | null;
|
|
16
15
|
}
|
|
17
16
|
|
|
18
17
|
/** Primitive types used in ISerializable fields. */
|
|
19
|
-
type Primitive = string|number|boolean|null|undefined;
|
|
18
|
+
type Primitive = string | number | boolean | null | undefined;
|
|
20
19
|
|
|
21
20
|
/**
|
|
22
21
|
* Mapped type that annotates all nested fields on an object as optional,
|
|
@@ -24,13 +23,16 @@ type Primitive = string|number|boolean|null|undefined;
|
|
|
24
23
|
*
|
|
25
24
|
* i.e., {a: {b: {c: boolean}}} gets transformed into {a?: {b?: {c?: boolean}}}
|
|
26
25
|
*/
|
|
27
|
-
export type DeepPartialISerializable<T> =
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
26
|
+
export type DeepPartialISerializable<T> = T extends Primitive
|
|
27
|
+
? Partial<T>
|
|
28
|
+
: T extends ISerializable
|
|
29
|
+
? Omit<
|
|
30
|
+
{[K in keyof T]?: DeepPartialISerializable<T[K]>},
|
|
31
|
+
keyof ISerializable | 'getPartialClassMetadata'
|
|
32
|
+
>
|
|
33
|
+
: T extends object
|
|
34
|
+
? {[K in keyof T]?: DeepPartialISerializable<T[K]>}
|
|
35
|
+
: unknown;
|
|
34
36
|
|
|
35
37
|
/**
|
|
36
38
|
* Description of the properties in a Serializable class.
|
|
@@ -85,7 +87,8 @@ export interface ISerializable {
|
|
|
85
87
|
* this, then we can add new fields to ClassMetadata without updating all users.
|
|
86
88
|
*/
|
|
87
89
|
export function buildClassMetadataFromPartial(
|
|
88
|
-
|
|
90
|
+
partialClassMetadata: Partial<ClassMetadata>,
|
|
91
|
+
): ClassMetadata {
|
|
89
92
|
return {
|
|
90
93
|
arrays: {},
|
|
91
94
|
descriptions: {},
|
|
@@ -126,9 +129,9 @@ export abstract class Serializable implements ISerializable {
|
|
|
126
129
|
*/
|
|
127
130
|
// tslint:disable-next-line:no-any Serializables work with arbitrary data
|
|
128
131
|
Serializable$get(key: string): any {
|
|
129
|
-
return this.Serializable$values.hasOwnProperty(key)
|
|
130
|
-
|
|
131
|
-
|
|
132
|
+
return this.Serializable$values.hasOwnProperty(key)
|
|
133
|
+
? this.Serializable$values[key]
|
|
134
|
+
: null;
|
|
132
135
|
}
|
|
133
136
|
|
|
134
137
|
/**
|
|
@@ -153,7 +156,7 @@ export abstract class Serializable implements ISerializable {
|
|
|
153
156
|
|
|
154
157
|
/** Constructs an ISerializable instance. */
|
|
155
158
|
export interface SerializableCtor<T extends ISerializable> {
|
|
156
|
-
new(): T;
|
|
159
|
+
new (): T;
|
|
157
160
|
}
|
|
158
161
|
|
|
159
162
|
/**
|
|
@@ -161,8 +164,9 @@ export interface SerializableCtor<T extends ISerializable> {
|
|
|
161
164
|
*/
|
|
162
165
|
export function clone<T extends ISerializable>(serializable: T): T {
|
|
163
166
|
return deserialize(
|
|
164
|
-
|
|
165
|
-
|
|
167
|
+
serializable.getConstructor() as SerializableCtor<T>,
|
|
168
|
+
serialize(serializable),
|
|
169
|
+
);
|
|
166
170
|
}
|
|
167
171
|
|
|
168
172
|
/**
|
|
@@ -187,7 +191,11 @@ export function isEmpty(serializable: ISerializable): boolean {
|
|
|
187
191
|
// tslint:disable-next-line:no-any
|
|
188
192
|
export function serialize(serializable: ISerializable): ObjectMap<any> {
|
|
189
193
|
return deepCopy(
|
|
190
|
-
|
|
194
|
+
serializable,
|
|
195
|
+
serializeGetter,
|
|
196
|
+
serializeSetter,
|
|
197
|
+
serializeInstanciator,
|
|
198
|
+
);
|
|
191
199
|
}
|
|
192
200
|
|
|
193
201
|
function serializeGetter(key: string, obj: unknown) {
|
|
@@ -199,7 +207,7 @@ function serializeSetter(key: string, obj: {}, value: {}) {
|
|
|
199
207
|
}
|
|
200
208
|
|
|
201
209
|
function serializeInstanciator(ctor: CopyConstructor) {
|
|
202
|
-
return
|
|
210
|
+
return {} as ObjectMap<{}>;
|
|
203
211
|
}
|
|
204
212
|
|
|
205
213
|
/**
|
|
@@ -207,14 +215,20 @@ function serializeInstanciator(ctor: CopyConstructor) {
|
|
|
207
215
|
* the data from the raw input to the new class instances.
|
|
208
216
|
*/
|
|
209
217
|
export function deserialize<T extends ISerializable>(
|
|
210
|
-
|
|
218
|
+
type: SerializableCtor<T>,
|
|
219
|
+
raw?: unknown,
|
|
220
|
+
): T {
|
|
211
221
|
const result = new type();
|
|
212
222
|
if (raw == null) {
|
|
213
223
|
return result;
|
|
214
224
|
}
|
|
215
225
|
return deepCopy(
|
|
216
|
-
|
|
217
|
-
|
|
226
|
+
raw,
|
|
227
|
+
deserializeGetter,
|
|
228
|
+
deserializeSetter,
|
|
229
|
+
deserializeInstanciator,
|
|
230
|
+
type,
|
|
231
|
+
) as T;
|
|
218
232
|
}
|
|
219
233
|
|
|
220
234
|
function deserializeGetter(key: string, obj: unknown) {
|
|
@@ -238,13 +252,15 @@ function deserializeInstanciator(ctor: CopyConstructor) {
|
|
|
238
252
|
* class.
|
|
239
253
|
*/
|
|
240
254
|
export function strictDeserialize<T extends ISerializable>(
|
|
241
|
-
|
|
255
|
+
type: SerializableCtor<T>,
|
|
256
|
+
raw: DeepPartialISerializable<T>,
|
|
257
|
+
) {
|
|
242
258
|
return deserialize(type, raw);
|
|
243
259
|
}
|
|
244
260
|
|
|
245
261
|
type CopyValueGetter = (key: string, obj: unknown) => {};
|
|
246
262
|
type CopyValueSetter = (key: string, obj: {}, value: {}) => void;
|
|
247
|
-
type CopyConstructor = SerializableCtor<ISerializable
|
|
263
|
+
type CopyConstructor = SerializableCtor<ISerializable> | null | undefined;
|
|
248
264
|
type CopyInstanciator<T> = (ctor: CopyConstructor) => T;
|
|
249
265
|
|
|
250
266
|
/**
|
|
@@ -260,9 +276,12 @@ type CopyInstanciator<T> = (ctor: CopyConstructor) => T;
|
|
|
260
276
|
* @param targetConstructor Optional. The target's constructor function.
|
|
261
277
|
*/
|
|
262
278
|
function deepCopy<T extends {}>(
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
279
|
+
source: unknown,
|
|
280
|
+
valueGetter: CopyValueGetter,
|
|
281
|
+
valueSetter: CopyValueSetter,
|
|
282
|
+
copyInstanciator: CopyInstanciator<T>,
|
|
283
|
+
targetConstructor?: CopyConstructor,
|
|
284
|
+
): T {
|
|
266
285
|
const target = copyInstanciator(targetConstructor);
|
|
267
286
|
const metadata = deepCopyMetadata(source, target);
|
|
268
287
|
|
|
@@ -282,38 +301,61 @@ function deepCopy<T extends {}>(
|
|
|
282
301
|
continue;
|
|
283
302
|
}
|
|
284
303
|
copy = deepCopyValue(
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
304
|
+
value,
|
|
305
|
+
valueGetter,
|
|
306
|
+
valueSetter,
|
|
307
|
+
copyInstanciator,
|
|
308
|
+
true,
|
|
309
|
+
true,
|
|
310
|
+
arrays[key],
|
|
311
|
+
);
|
|
288
312
|
} else if (objects.hasOwnProperty(key)) {
|
|
289
313
|
// Explicitly a serializable object
|
|
290
314
|
copy = deepCopyValue(
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
315
|
+
value,
|
|
316
|
+
valueGetter,
|
|
317
|
+
valueSetter,
|
|
318
|
+
copyInstanciator,
|
|
319
|
+
false,
|
|
320
|
+
true,
|
|
321
|
+
objects[key],
|
|
322
|
+
);
|
|
294
323
|
} else if (objectMaps.hasOwnProperty(key)) {
|
|
295
324
|
// Serialize all the values in an object map.
|
|
296
325
|
const mapMetadata = objectMaps[key];
|
|
297
|
-
copy = mapMetadata.isPropertyArray
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
326
|
+
copy = mapMetadata.isPropertyArray
|
|
327
|
+
? (value as Array<ObjectMap<{}>>).map((v) =>
|
|
328
|
+
deepCopyObjectMap(
|
|
329
|
+
v,
|
|
330
|
+
mapMetadata,
|
|
331
|
+
valueGetter,
|
|
332
|
+
valueSetter,
|
|
333
|
+
copyInstanciator,
|
|
334
|
+
),
|
|
335
|
+
)
|
|
336
|
+
: deepCopyObjectMap(
|
|
337
|
+
value,
|
|
338
|
+
mapMetadata,
|
|
339
|
+
valueGetter,
|
|
340
|
+
valueSetter,
|
|
341
|
+
copyInstanciator,
|
|
342
|
+
);
|
|
343
|
+
} else if (Array.isArray(value)) {
|
|
344
|
+
// This needs to be second to last!
|
|
307
345
|
// Implicitly an array, treat as primitives
|
|
308
346
|
if (metadata.emptyArrayIsUnset && value.length === 0) {
|
|
309
347
|
continue;
|
|
310
348
|
}
|
|
311
349
|
copy = deepCopyValue(
|
|
312
|
-
|
|
313
|
-
|
|
350
|
+
value,
|
|
351
|
+
valueGetter,
|
|
352
|
+
valueSetter,
|
|
353
|
+
copyInstanciator,
|
|
354
|
+
true,
|
|
355
|
+
false,
|
|
356
|
+
);
|
|
314
357
|
} else if (value instanceof NullClass) {
|
|
315
358
|
copy = null as unknown as {};
|
|
316
|
-
|
|
317
359
|
} else {
|
|
318
360
|
copy = value;
|
|
319
361
|
}
|
|
@@ -324,27 +366,42 @@ function deepCopy<T extends {}>(
|
|
|
324
366
|
}
|
|
325
367
|
|
|
326
368
|
function deepCopyObjectMap<T extends {}>(
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
369
|
+
value: ObjectMap<{}>,
|
|
370
|
+
mapMetadata: ObjectMapMetadata,
|
|
371
|
+
valueGetter: CopyValueGetter,
|
|
372
|
+
valueSetter: CopyValueSetter,
|
|
373
|
+
copyInstanciator: CopyInstanciator<T>,
|
|
374
|
+
) {
|
|
330
375
|
const objMap: ObjectMap<{}> = {};
|
|
331
376
|
for (const mapKey of Object.keys(value)) {
|
|
332
377
|
const mapValue = value[mapKey];
|
|
333
378
|
if (mapValue == null) continue;
|
|
334
379
|
objMap[mapKey] = deepCopyValue(
|
|
335
|
-
|
|
336
|
-
|
|
380
|
+
mapValue,
|
|
381
|
+
valueGetter,
|
|
382
|
+
valueSetter,
|
|
383
|
+
copyInstanciator,
|
|
384
|
+
mapMetadata.isValueArray,
|
|
385
|
+
mapMetadata.isSerializable,
|
|
386
|
+
mapMetadata.ctor,
|
|
387
|
+
);
|
|
337
388
|
}
|
|
338
389
|
return objMap;
|
|
339
390
|
}
|
|
340
391
|
|
|
341
392
|
function deepCopyValue<T extends {}>(
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
393
|
+
value: {},
|
|
394
|
+
valueGetter: CopyValueGetter,
|
|
395
|
+
valueSetter: CopyValueSetter,
|
|
396
|
+
copyInstanciator: CopyInstanciator<T>,
|
|
397
|
+
isArray: boolean,
|
|
398
|
+
isRef: boolean,
|
|
399
|
+
ctor?: CopyConstructor,
|
|
400
|
+
) {
|
|
345
401
|
if (isRef && ctor == null) {
|
|
346
402
|
throw new Error(
|
|
347
|
-
|
|
403
|
+
'Cannot deserialize a reference object without a constructor.',
|
|
404
|
+
);
|
|
348
405
|
}
|
|
349
406
|
|
|
350
407
|
if (value == null) {
|
|
@@ -353,27 +410,25 @@ function deepCopyValue<T extends {}>(
|
|
|
353
410
|
|
|
354
411
|
let deserialized: {};
|
|
355
412
|
if (isArray && isRef) {
|
|
356
|
-
deserialized =
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
v => deepCopy(
|
|
360
|
-
v, valueGetter, valueSetter, copyInstanciator, ctor));
|
|
361
|
-
|
|
413
|
+
deserialized = (value as ISerializable[]).map((v) =>
|
|
414
|
+
deepCopy(v, valueGetter, valueSetter, copyInstanciator, ctor),
|
|
415
|
+
);
|
|
362
416
|
} else if (isArray && !isRef) {
|
|
363
417
|
deserialized = (value as Array<{}>).map((v) => v);
|
|
364
|
-
|
|
365
418
|
} else if (!isArray && isRef) {
|
|
366
|
-
deserialized =
|
|
367
|
-
|
|
368
|
-
|
|
419
|
+
deserialized = deepCopy(
|
|
420
|
+
value,
|
|
421
|
+
valueGetter,
|
|
422
|
+
valueSetter,
|
|
423
|
+
copyInstanciator,
|
|
424
|
+
ctor,
|
|
425
|
+
);
|
|
369
426
|
} else if (value instanceof NullClass) {
|
|
370
427
|
deserialized = null as unknown as {};
|
|
371
|
-
|
|
372
428
|
} else if (typeof value === 'object') {
|
|
373
429
|
// TODO(user): Assert as a type, declared interface, or `unknown`.
|
|
374
430
|
// tslint:disable-next-line:ban-types no-unnecessary-type-assertion
|
|
375
431
|
deserialized = JSON.parse(JSON.stringify(value)) as AnyDuringMigration;
|
|
376
|
-
|
|
377
432
|
} else {
|
|
378
433
|
deserialized = value;
|
|
379
434
|
}
|
|
@@ -392,13 +447,14 @@ function deepCopyMetadata(source: unknown, target: {}) {
|
|
|
392
447
|
return metadata;
|
|
393
448
|
}
|
|
394
449
|
|
|
395
|
-
|
|
396
450
|
/**
|
|
397
451
|
* Returns whether or not the two serializable objects are deeply equal. The
|
|
398
452
|
* traversal logic should be identical to that of serialize.
|
|
399
453
|
*/
|
|
400
454
|
export function deepEquals(
|
|
401
|
-
|
|
455
|
+
serializable1: ISerializable,
|
|
456
|
+
serializable2: ISerializable,
|
|
457
|
+
): boolean {
|
|
402
458
|
const metadata1 = serializable1.getClassMetadata();
|
|
403
459
|
const keys1 = metadata1.keys || [];
|
|
404
460
|
const arrays1 = metadata1.arrays || {};
|
|
@@ -411,8 +467,14 @@ export function deepEquals(
|
|
|
411
467
|
const objects2 = metadata2.objects || {};
|
|
412
468
|
const objectMaps2 = metadata2.objectMaps || {};
|
|
413
469
|
|
|
414
|
-
if (
|
|
415
|
-
|
|
470
|
+
if (
|
|
471
|
+
!(
|
|
472
|
+
sameKeys(keys1, keys2) &&
|
|
473
|
+
sameKeys(arrays1, arrays2) &&
|
|
474
|
+
sameKeys(objects1, objects2) &&
|
|
475
|
+
sameKeys(objectMaps1, objectMaps2)
|
|
476
|
+
)
|
|
477
|
+
) {
|
|
416
478
|
return false;
|
|
417
479
|
}
|
|
418
480
|
|
|
@@ -457,12 +519,10 @@ export function deepEquals(
|
|
|
457
519
|
if (!deepEqualsValue(value1, value2, true, true)) {
|
|
458
520
|
return false;
|
|
459
521
|
}
|
|
460
|
-
|
|
461
522
|
} else if (objects1.hasOwnProperty(key)) {
|
|
462
523
|
if (!deepEqualsValue(value1, value2, false, true)) {
|
|
463
524
|
return false;
|
|
464
525
|
}
|
|
465
|
-
|
|
466
526
|
} else if (objectMaps1.hasOwnProperty(key)) {
|
|
467
527
|
const mapMetadata = objectMaps1[key];
|
|
468
528
|
if (mapMetadata.isPropertyArray) {
|
|
@@ -470,19 +530,21 @@ export function deepEquals(
|
|
|
470
530
|
return false;
|
|
471
531
|
}
|
|
472
532
|
const value1Arr = value1 as Array<ObjectMap<{}>>;
|
|
473
|
-
if (
|
|
474
|
-
|
|
533
|
+
if (
|
|
534
|
+
value1Arr.some(
|
|
535
|
+
(v1, i) => !deepEqualsObjectMap(v1, value2[i], mapMetadata),
|
|
536
|
+
)
|
|
537
|
+
) {
|
|
475
538
|
return false;
|
|
476
539
|
}
|
|
477
540
|
} else if (!deepEqualsObjectMap(value1, value2, mapMetadata)) {
|
|
478
541
|
return false;
|
|
479
542
|
}
|
|
480
|
-
|
|
481
|
-
|
|
543
|
+
} else if (Array.isArray(value1)) {
|
|
544
|
+
// This needs to be second to last!
|
|
482
545
|
if (!deepEqualsValue(value1, value2, true, false)) {
|
|
483
546
|
return false;
|
|
484
547
|
}
|
|
485
|
-
|
|
486
548
|
} else if (!deepEqualsValue(value1, value2, false, false)) {
|
|
487
549
|
return false;
|
|
488
550
|
}
|
|
@@ -491,8 +553,10 @@ export function deepEquals(
|
|
|
491
553
|
}
|
|
492
554
|
|
|
493
555
|
function hasAndIsNotEmptyArray(
|
|
494
|
-
|
|
495
|
-
|
|
556
|
+
serializable: ISerializable,
|
|
557
|
+
key: string,
|
|
558
|
+
metadata: ClassMetadata,
|
|
559
|
+
): boolean {
|
|
496
560
|
if (!serializable.Serializable$has(key)) return false;
|
|
497
561
|
if (!metadata.emptyArrayIsUnset) return true;
|
|
498
562
|
const value = serializable.Serializable$get(key);
|
|
@@ -501,8 +565,10 @@ function hasAndIsNotEmptyArray(
|
|
|
501
565
|
}
|
|
502
566
|
|
|
503
567
|
function deepEqualsObjectMap(
|
|
504
|
-
|
|
505
|
-
|
|
568
|
+
value1: ObjectMap<{}>,
|
|
569
|
+
value2: ObjectMap<{}>,
|
|
570
|
+
mapMetadata: ObjectMapMetadata,
|
|
571
|
+
) {
|
|
506
572
|
if (!sameKeys(value1, value2)) {
|
|
507
573
|
return false;
|
|
508
574
|
}
|
|
@@ -511,9 +577,14 @@ function deepEqualsObjectMap(
|
|
|
511
577
|
const mapValue1 = value1[mapKey];
|
|
512
578
|
const mapValue2 = value2[mapKey];
|
|
513
579
|
|
|
514
|
-
if (
|
|
515
|
-
|
|
516
|
-
|
|
580
|
+
if (
|
|
581
|
+
!deepEqualsValue(
|
|
582
|
+
mapValue1,
|
|
583
|
+
mapValue2,
|
|
584
|
+
mapMetadata.isValueArray,
|
|
585
|
+
mapMetadata.isSerializable,
|
|
586
|
+
)
|
|
587
|
+
) {
|
|
517
588
|
return false;
|
|
518
589
|
}
|
|
519
590
|
}
|
|
@@ -522,7 +593,11 @@ function deepEqualsObjectMap(
|
|
|
522
593
|
}
|
|
523
594
|
|
|
524
595
|
function deepEqualsValue(
|
|
525
|
-
|
|
596
|
+
value1: {},
|
|
597
|
+
value2: {},
|
|
598
|
+
isArray: boolean,
|
|
599
|
+
isSerializable: boolean,
|
|
600
|
+
) {
|
|
526
601
|
if (value1 == null && value2 == null) {
|
|
527
602
|
return true;
|
|
528
603
|
}
|
|
@@ -531,13 +606,13 @@ function deepEqualsValue(
|
|
|
531
606
|
if (!sameKeys(value1, value2)) {
|
|
532
607
|
return false;
|
|
533
608
|
}
|
|
534
|
-
const serializableArr1 =
|
|
535
|
-
const serializableArr2 =
|
|
536
|
-
if (
|
|
537
|
-
|
|
609
|
+
const serializableArr1 = value1 as ISerializable[];
|
|
610
|
+
const serializableArr2 = value2 as ISerializable[];
|
|
611
|
+
if (
|
|
612
|
+
serializableArr1.some((v1, i) => !deepEquals(v1, serializableArr2[i]))
|
|
613
|
+
) {
|
|
538
614
|
return false;
|
|
539
615
|
}
|
|
540
|
-
|
|
541
616
|
} else if (isArray && !isSerializable) {
|
|
542
617
|
if (!sameKeys(value1, value2)) {
|
|
543
618
|
return false;
|
|
@@ -547,10 +622,8 @@ function deepEqualsValue(
|
|
|
547
622
|
if (arr1.some((v, i) => v !== arr2[i])) {
|
|
548
623
|
return false;
|
|
549
624
|
}
|
|
550
|
-
|
|
551
625
|
} else if (isSerializable) {
|
|
552
626
|
return deepEquals(value1 as ISerializable, value2 as ISerializable);
|
|
553
|
-
|
|
554
627
|
} else if (typeof value1 === 'object') {
|
|
555
628
|
if (JSON.stringify(value1) !== JSON.stringify(value2)) {
|
|
556
629
|
return false;
|
|
@@ -593,9 +666,11 @@ function sameKeys<T extends {}>(a: T, b: T) {
|
|
|
593
666
|
* implementation details in the future.
|
|
594
667
|
*/
|
|
595
668
|
export function serializableEqualityTester(
|
|
596
|
-
|
|
669
|
+
left: unknown,
|
|
670
|
+
right: unknown,
|
|
671
|
+
): boolean | undefined {
|
|
597
672
|
if (left instanceof Serializable && right instanceof Serializable) {
|
|
598
673
|
return deepEquals(left, right);
|
|
599
674
|
}
|
|
600
|
-
return undefined;
|
|
675
|
+
return undefined; // Do not change behavior for other types.
|
|
601
676
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// g3-format-clang
|
|
2
1
|
import {Serializable, SerializableCtor} from './domain_object';
|
|
3
2
|
import {MultipartRequest} from './multipart_request';
|
|
4
3
|
|
|
@@ -15,8 +14,14 @@ export interface GeneratedInterface {}
|
|
|
15
14
|
|
|
16
15
|
/** Type for the optional queryParams map: string-indexed primitive values. */
|
|
17
16
|
export interface GeneratedQueryParams {
|
|
18
|
-
[key: string]:
|
|
19
|
-
|
|
17
|
+
[key: string]:
|
|
18
|
+
| number
|
|
19
|
+
| ReadonlyArray<number>
|
|
20
|
+
| string
|
|
21
|
+
| ReadonlyArray<string>
|
|
22
|
+
| boolean
|
|
23
|
+
| ReadonlyArray<boolean>
|
|
24
|
+
| undefined;
|
|
20
25
|
}
|
|
21
26
|
|
|
22
27
|
export interface GeneratedRequestParams {
|
|
@@ -25,7 +30,7 @@ export interface GeneratedRequestParams {
|
|
|
25
30
|
/** The id of the called method, from discovery. */
|
|
26
31
|
methodId?: string;
|
|
27
32
|
queryParams?: GeneratedQueryParams;
|
|
28
|
-
body?: Serializable|GeneratedInterface|MultipartRequest|null;
|
|
33
|
+
body?: Serializable | GeneratedInterface | MultipartRequest | null;
|
|
29
34
|
responseCtor?: SerializableCtor<Serializable>;
|
|
30
35
|
/**
|
|
31
36
|
* Whether the end-point is a streaming end-point and its type e.g.
|