mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 23:25:26 +00:00
Improved PKPass.from signature and made additionalProps to be never if source is not a PKPass instance
This commit is contained in:
@@ -38,13 +38,15 @@ export default class PKPass extends Bundle {
|
|||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static async from(
|
static async from<S extends PKPass | Schemas.Template>(
|
||||||
source: PKPass | Schemas.Template,
|
source: S,
|
||||||
additionalProps: Schemas.OverridablePassProps = {},
|
additionalProps: S extends PKPass
|
||||||
|
? Schemas.OverridablePassProps
|
||||||
|
: never,
|
||||||
): Promise<PKPass> {
|
): Promise<PKPass> {
|
||||||
let certificates: Schemas.CertificatesSchema = undefined;
|
let certificates: Schemas.CertificatesSchema = undefined;
|
||||||
let buffers: Schemas.FileBuffers = undefined;
|
let buffers: Schemas.FileBuffers = undefined;
|
||||||
let overrides: Schemas.OverridablePassProps = {};
|
let props: Schemas.OverridablePassProps = {};
|
||||||
|
|
||||||
if (!source) {
|
if (!source) {
|
||||||
throw new TypeError(
|
throw new TypeError(
|
||||||
@@ -85,7 +87,7 @@ export default class PKPass extends Bundle {
|
|||||||
|
|
||||||
buffers = await getModelFolderContents(source.model);
|
buffers = await getModelFolderContents(source.model);
|
||||||
certificates = source.certificates;
|
certificates = source.certificates;
|
||||||
overrides = source.overrides || {};
|
props = source.props ?? {};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (additionalProps && Object.keys(additionalProps).length) {
|
if (additionalProps && Object.keys(additionalProps).length) {
|
||||||
@@ -95,14 +97,11 @@ export default class PKPass extends Bundle {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (validation) {
|
if (validation) {
|
||||||
Object.assign(overrides, validation);
|
Object.assign(props, validation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new PKPass(buffers, certificates, {
|
return new PKPass(buffers, certificates, props);
|
||||||
...overrides,
|
|
||||||
...additionalProps,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user