mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 19:25:23 +00:00
Added propsSymbol and prop getter implementation
This commit is contained in:
@@ -6,6 +6,7 @@ import * as Schemas from "./schemas";
|
|||||||
import { Stream } from "stream";
|
import { Stream } from "stream";
|
||||||
|
|
||||||
const fieldKeysPoolSymbol = Symbol("fieldKeysPoolSymbol");
|
const fieldKeysPoolSymbol = Symbol("fieldKeysPoolSymbol");
|
||||||
|
const propsSymbol = Symbol("props");
|
||||||
|
|
||||||
interface NamedBuffers {
|
interface NamedBuffers {
|
||||||
[key: string]: Buffer;
|
[key: string]: Buffer;
|
||||||
@@ -21,6 +22,7 @@ type TransitTypes = `PKTransitType${
|
|||||||
export class PKPass extends Bundle {
|
export class PKPass extends Bundle {
|
||||||
private certificates: Certificates;
|
private certificates: Certificates;
|
||||||
private [fieldKeysPoolSymbol] = new Set<string>();
|
private [fieldKeysPoolSymbol] = new Set<string>();
|
||||||
|
private [propsSymbol]: Schemas.ValidPass = {};
|
||||||
public primaryFields /*****/ = new FieldsArray(this[fieldKeysPoolSymbol]);
|
public primaryFields /*****/ = new FieldsArray(this[fieldKeysPoolSymbol]);
|
||||||
public secondaryFields /***/ = new FieldsArray(this[fieldKeysPoolSymbol]);
|
public secondaryFields /***/ = new FieldsArray(this[fieldKeysPoolSymbol]);
|
||||||
public auxiliaryFields /***/ = new FieldsArray(this[fieldKeysPoolSymbol]);
|
public auxiliaryFields /***/ = new FieldsArray(this[fieldKeysPoolSymbol]);
|
||||||
@@ -128,11 +130,7 @@ export class PKPass extends Bundle {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
get props(): Readonly<Schemas.ValidPass> {
|
get props(): Readonly<Schemas.ValidPass> {
|
||||||
/**
|
return freezeRecusive(this[propsSymbol]);
|
||||||
* @TODO implement
|
|
||||||
*/
|
|
||||||
|
|
||||||
return undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -369,3 +367,28 @@ export class PKPass extends Bundle {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function freezeRecusive(object: Object) {
|
||||||
|
const objectCopy = {};
|
||||||
|
const objectEntries = Object.entries(object);
|
||||||
|
|
||||||
|
for (let i = 0; i < objectEntries.length; i++) {
|
||||||
|
const [key, value] = objectEntries[i];
|
||||||
|
|
||||||
|
if (value && typeof value === "object") {
|
||||||
|
if (Array.isArray(value)) {
|
||||||
|
objectCopy[key] = value.slice();
|
||||||
|
|
||||||
|
for (let j = 0; j < value.length; j++) {
|
||||||
|
objectCopy[key][j] = freezeRecusive(value[j]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
objectCopy[key] = freezeRecusive(value);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
objectCopy[key] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Object.freeze(objectCopy);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user