From aaea9c1304245bee36496cf33763b39a2b2858bd Mon Sep 17 00:00:00 2001 From: Alexander Cerutti Date: Sun, 26 Sep 2021 23:32:21 +0200 Subject: [PATCH] Revert "Added Bundle.prototype.files getter to prevent exposing filesSymbol" This reverts commit 6f7a597cbe62d441a590a613d8484dba5205ed84. --- spec/Bundle.ts | 4 ++-- src/Bundle.ts | 10 +--------- src/PKPass.ts | 8 ++++---- 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/spec/Bundle.ts b/spec/Bundle.ts index 2873b1d..f77d645 100644 --- a/spec/Bundle.ts +++ b/spec/Bundle.ts @@ -1,5 +1,5 @@ import { Stream } from "stream"; -import { default as Bundle } from "../lib/Bundle"; +import { default as Bundle, filesSymbol } from "../lib/Bundle"; describe("Bundle", () => { let bundle: InstanceType; @@ -24,7 +24,7 @@ describe("Bundle", () => { const buffer = Buffer.alloc(0); bundle.addBuffer("pass.json", buffer); - expect(bundle.files).toEqual({ "pass.json": buffer }); + expect(bundle[filesSymbol]).toEqual({ "pass.json": buffer }); }); it("should throw error if freezed", async () => { diff --git a/src/Bundle.ts b/src/Bundle.ts index 935c877..6727046 100644 --- a/src/Bundle.ts +++ b/src/Bundle.ts @@ -1,7 +1,7 @@ import { Stream } from "stream"; import { ZipFile } from "yazl"; -const filesSymbol = Symbol("bundleFiles"); +export const filesSymbol = Symbol("bundleFiles"); const bundleStateSymbol = Symbol("state"); const archiveSymbol = Symbol("zip"); @@ -78,14 +78,6 @@ export default class Bundle { return this[bundleStateSymbol] === BundleState.CLOSED; } - /** - * Returns the list of files added to the bundle - */ - - public get files() { - return this[filesSymbol]; - } - /** * Allows files to be added to the bundle. * If the bundle is closed, it will throw an error. diff --git a/src/PKPass.ts b/src/PKPass.ts index f18c70f..ec9e26e 100644 --- a/src/PKPass.ts +++ b/src/PKPass.ts @@ -1,5 +1,5 @@ import FieldsArray from "./fieldsArray"; -import { default as Bundle } from "./Bundle"; +import { default as Bundle, filesSymbol } from "./Bundle"; import { getModelFolderContents } from "./parser"; import * as Schemas from "./schemas"; import { Stream } from "stream"; @@ -73,7 +73,7 @@ export default class PKPass extends Bundle { certificates = source.certificates; buffers = {}; - const buffersEntries = Object.entries(source.files); + const buffersEntries = Object.entries(source[filesSymbol]); /** Cloning all the buffers to prevent unwanted edits */ for (let i = 0; i < buffersEntries.length; i++) { @@ -285,7 +285,7 @@ export default class PKPass extends Bundle { } if (/pass\.json/.test(pathName)) { - if (this.files["pass.json"]) { + if (this[filesSymbol]["pass.json"]) { /** * Ignoring any further addition. In a * future we might consider merging instead @@ -374,7 +374,7 @@ export default class PKPass extends Bundle { } private [createManifestSymbol]() { - return Object.entries(this.files).reduce( + return Object.entries(this[filesSymbol]).reduce( (acc, [fileName, buffer]) => { const hashFlow = forge.md.sha1.create();