Renamed _props to a symbol-property

This commit is contained in:
Alexander Cerutti
2019-06-29 23:51:38 +02:00
parent e4c39d837a
commit dba3a7a02a

View File

@@ -16,6 +16,7 @@ const barcodeDebug = debug("passkit:barcode");
const genericDebug = debug("passkit:generic"); const genericDebug = debug("passkit:generic");
const transitType = Symbol("transitType"); const transitType = Symbol("transitType");
const passProps = Symbol("_props");
interface PassIndexSignature { interface PassIndexSignature {
[key: string]: any; [key: string]: any;
@@ -34,7 +35,7 @@ export class Pass implements PassIndexSignature {
private bundle: schema.BundleUnit; private bundle: schema.BundleUnit;
private l10nBundles: schema.PartitionedBundle["l10nBundle"]; private l10nBundles: schema.PartitionedBundle["l10nBundle"];
private _fields: (keyof schema.PassFields)[]; private _fields: (keyof schema.PassFields)[];
private _props: schema.ValidPass = {}; private [passProps]: schema.ValidPass = {};
private type: keyof schema.ValidPassType; private type: keyof schema.ValidPassType;
private fieldsKeys: Set<string> = new Set<string>(); private fieldsKeys: Set<string> = new Set<string>();
private passCore: schema.ValidPass = {}; private passCore: schema.ValidPass = {};
@@ -229,14 +230,14 @@ export class Pass implements PassIndexSignature {
expiration(date?: Date): this | string { expiration(date?: Date): this | string {
if (date === null) { if (date === null) {
delete this._props["expirationDate"]; delete this[passProps]["expirationDate"];
return this; return this;
} }
const parsedDate = processDate("expirationDate", date); const parsedDate = processDate("expirationDate", date);
if (parsedDate) { if (parsedDate) {
this._props["expirationDate"] = parsedDate; this[passProps]["expirationDate"] = parsedDate;
} }
return this; return this;
@@ -250,7 +251,7 @@ export class Pass implements PassIndexSignature {
*/ */
void(): this { void(): this {
this._props["voided"] = true; this[passProps]["voided"] = true;
return this; return this;
} }
@@ -262,14 +263,14 @@ export class Pass implements PassIndexSignature {
beacons(...data: schema.Beacon[] | null): this { beacons(...data: schema.Beacon[] | null): this {
if (data === null) { if (data === null) {
delete this._props["beacons"]; delete this[passProps]["beacons"];
return this; return this;
} }
const valid = processRelevancySet("beacons", data); const valid = processRelevancySet("beacons", data);
if (valid.length) { if (valid.length) {
this._props["beacons"] = valid; this[passProps]["beacons"] = valid;
} }
return this; return this;
@@ -283,14 +284,14 @@ export class Pass implements PassIndexSignature {
locations(...data: schema.Location[]): this { locations(...data: schema.Location[]): this {
if (data === null) { if (data === null) {
delete this._props["locations"]; delete this[passProps]["locations"];
return this; return this;
} }
const valid = processRelevancySet("locations", data); const valid = processRelevancySet("locations", data);
if (valid.length) { if (valid.length) {
this._props["locations"] = valid; this[passProps]["locations"] = valid;
} }
return this; return this;
@@ -304,14 +305,14 @@ export class Pass implements PassIndexSignature {
relevantDate(date?: Date): this | string { relevantDate(date?: Date): this | string {
if (date === null) { if (date === null) {
delete this._props["relevantDate"]; delete this[passProps]["relevantDate"];
return this; return this;
} }
const parsedDate = processDate("relevandDate", date); const parsedDate = processDate("relevandDate", date);
if (parsedDate) { if (parsedDate) {
this._props["relevantDate"] = parsedDate; this[passProps]["relevantDate"] = parsedDate;
} }
return this; return this;
@@ -328,7 +329,7 @@ export class Pass implements PassIndexSignature {
barcodes(first?: string | schema.Barcode, ...data: schema.Barcode[]): this { barcodes(first?: string | schema.Barcode, ...data: schema.Barcode[]): this {
if (first === null) { if (first === null) {
delete this._props["barcodes"]; delete this[passProps]["barcodes"];
return this; return this;
} }
@@ -353,7 +354,7 @@ export class Pass implements PassIndexSignature {
return this; return this;
} }
this._props["barcodes"] = autogen; this[passProps]["barcodes"] = autogen;
return this; return this;
} else { } else {
@@ -380,7 +381,7 @@ export class Pass implements PassIndexSignature {
}, []); }, []);
if (valid.length) { if (valid.length) {
this._props["barcodes"] = valid; this[passProps]["barcodes"] = valid;
} }
return this; return this;
@@ -398,10 +399,10 @@ export class Pass implements PassIndexSignature {
*/ */
barcode(chosenFormat: schema.BarcodeFormat | null): this { barcode(chosenFormat: schema.BarcodeFormat | null): this {
let { barcodes } = this._props; let { barcodes } = this[passProps];
if (chosenFormat === null) { if (chosenFormat === null) {
delete this._props["barcode"]; delete this[passProps]["barcode"];
return this; return this;
} }
@@ -423,7 +424,7 @@ export class Pass implements PassIndexSignature {
return this; return this;
} }
this._props["barcode"] = barcodes[index]; this[passProps]["barcode"] = barcodes[index];
return this; return this;
} }
@@ -437,7 +438,7 @@ export class Pass implements PassIndexSignature {
nfc(data?: schema.NFC): this | schema.NFC { nfc(data?: schema.NFC): this | schema.NFC {
if (data === undefined) { if (data === undefined) {
return this._props["nfc"]; return this[passProps]["nfc"];
} }
if (!(typeof data === "object" && !Array.isArray(data) && schema.isValid(data, "nfcDict"))) { if (!(typeof data === "object" && !Array.isArray(data) && schema.isValid(data, "nfcDict"))) {
@@ -445,7 +446,7 @@ export class Pass implements PassIndexSignature {
return this; return this;
} }
this._props["nfc"] = data; this[passProps]["nfc"] = data;
return this; return this;
} }
@@ -524,7 +525,7 @@ export class Pass implements PassIndexSignature {
private _patch(passCoreBuffer: Buffer): Buffer { private _patch(passCoreBuffer: Buffer): Buffer {
let passFile = JSON.parse(passCoreBuffer.toString()); let passFile = JSON.parse(passCoreBuffer.toString());
if (Object.keys(this._props).length) { if (Object.keys(this[passProps]).length) {
/* /*
* We filter the existing (in passFile) and non-valid keys from * We filter the existing (in passFile) and non-valid keys from
* the below array keys that accept rgb values * the below array keys that accept rgb values
@@ -532,10 +533,10 @@ export class Pass implements PassIndexSignature {
*/ */
["backgroundColor", "foregroundColor", "labelColor"] ["backgroundColor", "foregroundColor", "labelColor"]
.filter(v => this._props[v] && !isValidRGB(this._props[v])) .filter(v => this[passProps][v] && !isValidRGB(this[passProps][v]))
.forEach(v => delete this._props[v]); .forEach(v => delete this[passProps][v]);
passFile = { ...passFile, ...this._props }; passFile = { ...passFile, ...this[passProps] };
} }
this._fields.forEach(field => { this._fields.forEach(field => {