From 1ab998865454c942f6c8f5443a8350f520a64858 Mon Sep 17 00:00:00 2001 From: Scott Davey Date: Thu, 26 Oct 2023 13:36:37 +1100 Subject: [PATCH] Renamed map and mapper properties to __map and __mapper, to avoid the problem with Graphql schemas having those properties breaking the simulator. --- .../src/velocity/value-mapper/map.ts | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/packages/amplify-appsync-simulator/src/velocity/value-mapper/map.ts b/packages/amplify-appsync-simulator/src/velocity/value-mapper/map.ts index 2362e72d8ad..cd7ebe778b7 100644 --- a/packages/amplify-appsync-simulator/src/velocity/value-mapper/map.ts +++ b/packages/amplify-appsync-simulator/src/velocity/value-mapper/map.ts @@ -3,67 +3,67 @@ import { JavaInteger } from './integer'; import { toJSON } from './to-json'; export class JavaMap { - private map: Map; + private __map: Map; // eslint-disable-next-line @typescript-eslint/ban-types - private mapper: Function; + private __mapper: Function; constructor(obj, mapper) { - this.mapper = mapper; - this.map = new Map(); + this.__mapper = mapper; + this.__map = new Map(); Object.entries(obj).forEach(([key, value]) => { - this.map.set(key, value); + this.__map.set(key, value); }); } clear() { - this.map.clear(); + this.__map.clear(); } containsKey(key) { - return this.map.has(key); + return this.__map.has(key); } containsValue(value) { - return Array.from(this.map.values()).indexOf(value) !== -1; + return Array.from(this.__map.values()).indexOf(value) !== -1; } entrySet() { - const entries = Array.from(this.map.entries()).map(([key, value]) => + const entries = Array.from(this.__map.entries()).map(([key, value]) => createMapProxy( new JavaMap( { key, value, }, - this.mapper, + this.__mapper, ), ), ); - return new JavaArray(entries, this.mapper); + return new JavaArray(entries, this.__mapper); } equals(value) { - return Array.from(this.map.entries()).every(([key, v]) => value.get(key) === v); + return Array.from(this.__map.entries()).every(([key, v]) => value.get(key) === v); } get(key) { - if (this.map.has(key.toString())) { - return this.map.get(key.toString()); + if (this.__map.has(key.toString())) { + return this.__map.get(key.toString()); } return null; } isEmpty() { - return this.map.size === 0; + return this.__map.size === 0; } keySet() { - return new JavaArray(Array.from(this.map.keys()).map(this.mapper as any), this.mapper); + return new JavaArray(Array.from(this.__map.keys()).map(this.__mapper as any), this.__mapper); } put(key, value) { - const saveValue = this.mapper(value); - this.map.set(key, saveValue); + const saveValue = this.__mapper(value); + this.__map.set(key, saveValue); return saveValue; } @@ -75,24 +75,24 @@ export class JavaMap { } remove(key) { - if (!this.map.has(key)) { + if (!this.__map.has(key)) { return null; } - const value = this.map.get(key); - this.map.delete(key); + const value = this.__map.get(key); + this.__map.delete(key); return value; } size() { - return new JavaInteger(this.map.size); + return new JavaInteger(this.__map.size); } values() { - return new JavaArray(Array.from(this.map.values()), this.mapper); + return new JavaArray(Array.from(this.__map.values()), this.__mapper); } toJSON() { - return Array.from(this.map.entries()).reduce( + return Array.from(this.__map.entries()).reduce( (sum, [key, value]) => ({ ...sum, [key]: toJSON(value), @@ -105,14 +105,14 @@ export class JavaMap { export function createMapProxy(map) { return new Proxy(map, { get(obj, prop) { - if (map.map.has(prop)) { + if (map.__map.has(prop)) { return map.get(prop); } return map[prop]; }, set(obj, prop, val) { if (typeof val !== 'function') { - map.map.set(prop, val); + map.__map.set(prop, val); } return true; },