From 2a7f5f818c0011bb8278a1da55a2f112b5f11424 Mon Sep 17 00:00:00 2001 From: Alexander Cerutti Date: Sat, 16 Oct 2021 12:44:01 +0200 Subject: [PATCH] Unified props passing to PKPass.from between template and PKPass --- spec/PKPass.ts | 20 +++++++++++--------- src/PKPass.ts | 22 ++++++---------------- src/schemas/index.ts | 2 -- 3 files changed, 17 insertions(+), 27 deletions(-) diff --git a/spec/PKPass.ts b/spec/PKPass.ts index 076248e..8d4d300 100644 --- a/spec/PKPass.ts +++ b/spec/PKPass.ts @@ -1052,18 +1052,20 @@ describe("PKPass", () => { ), ); - const newPass = await PKPass.from({ - model: path.resolve( - __dirname, - "../examples/models/exampleBooking.pass", - ), - certificates: { - ...baseCerts, + const newPass = await PKPass.from( + { + model: path.resolve( + __dirname, + "../examples/models/exampleBooking.pass", + ), + certificates: { + ...baseCerts, + }, }, - props: { + { voided: true, }, - }); + ); expect(Object.keys(newPass[filesSymbol]).length).toBe(7); diff --git a/src/PKPass.ts b/src/PKPass.ts index 6bbb328..324fca2 100644 --- a/src/PKPass.ts +++ b/src/PKPass.ts @@ -39,13 +39,10 @@ export default class PKPass extends Bundle { static async from( source: S, - additionalProps?: S extends PKPass - ? Schemas.OverridablePassProps - : never, + props?: Schemas.OverridablePassProps, ): Promise { let certificates: Schemas.CertificatesSchema = undefined; let buffers: Schemas.FileBuffers = undefined; - let props: Schemas.OverridablePassProps = {}; if (!source) { throw new TypeError( @@ -86,20 +83,13 @@ export default class PKPass extends Bundle { buffers = await getModelFolderContents(source.model); certificates = source.certificates; - props = Schemas.validate( - Schemas.OverridablePassProps, - source.props, - ); } - if (additionalProps && Object.keys(additionalProps).length) { - Object.assign( - props, - Schemas.validate(Schemas.OverridablePassProps, additionalProps), - ); - } - - return new PKPass(buffers, certificates, props); + return new PKPass( + buffers, + certificates, + Schemas.validate(Schemas.OverridablePassProps, props), + ); } /** diff --git a/src/schemas/index.ts b/src/schemas/index.ts index 8782383..aaa282b 100644 --- a/src/schemas/index.ts +++ b/src/schemas/index.ts @@ -154,13 +154,11 @@ export const PassProps = Joi.object< export interface Template { model: string; certificates: CertificatesSchema; - props?: OverridablePassProps; } export const Template = Joi.object