Removed Abstract Model implementation and added PKPass as esport

This commit is contained in:
Alexander Cerutti
2021-10-03 22:14:33 +02:00
parent 8bb76d6942
commit 3d22cef805
2 changed files with 1 additions and 74 deletions

View File

@@ -1,69 +0,0 @@
import * as Schemas from "./schemas";
import { getModelContents, readCertificatesFromOptions } from "./parser";
import formatMessage, { ERROR } from "./messages";
const abmCertificates = Symbol("certificates");
const abmModel = Symbol("model");
const abmOverrides = Symbol("overrides");
export interface AbstractFactoryOptions
extends Omit<Schemas.FactoryOptions, "certificates"> {
certificates?: Schemas.Certificates;
}
interface AbstractModelOptions {
bundle: Schemas.PartitionedBundle;
certificates: Schemas.CertificatesSchema;
overrides?: Schemas.OverridesSupportedOptions;
}
/**
* Creates an abstract model to keep data
* in memory for future passes creation
* @param options
*/
export async function createAbstractModel(options: AbstractFactoryOptions) {
if (!(options && Object.keys(options).length)) {
throw new Error(formatMessage(ERROR.CP_NO_OPTS));
}
try {
const [bundle, certificates] = await Promise.all([
getModelContents(options.model),
readCertificatesFromOptions(options.certificates),
]);
return new AbstractModel({
bundle,
certificates,
overrides: options.overrides,
});
} catch (err) {
throw new Error(formatMessage(ERROR.CP_INIT, "abstract model", err));
}
}
export class AbstractModel {
private [abmCertificates]: Schemas.CertificatesSchema;
private [abmModel]: Schemas.PartitionedBundle;
private [abmOverrides]: Schemas.OverridesSupportedOptions;
constructor(options: AbstractModelOptions) {
this[abmModel] = options.bundle;
this[abmCertificates] = options.certificates;
this[abmOverrides] = options.overrides;
}
get certificates(): Schemas.CertificatesSchema {
return this[abmCertificates];
}
get bundle(): Schemas.PartitionedBundle {
return this[abmModel];
}
get overrides(): Schemas.OverridesSupportedOptions {
return this[abmOverrides];
}
}

View File

@@ -1,6 +1,2 @@
export type { Pass } from "./pass";
export type { AbstractModel } from "./abstract";
export { createAbstractModel } from "./abstract";
export { default as Bundle } from "./Bundle"; export { default as Bundle } from "./Bundle";
export { default as PKPass } from "./PKPass";