mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 13:25:19 +00:00
Updated signatures using Field instead of PassFieldContent
This commit is contained in:
@@ -12,15 +12,17 @@ const passInstanceSymbol = Symbol("passInstance");
|
||||
const sharedKeysPoolSymbol = Symbol("keysPool");
|
||||
const fieldSchemaSymbol = Symbol("fieldSchema");
|
||||
|
||||
export default class FieldsArray extends Array<Schemas.Field> {
|
||||
export default class FieldsArray extends Array<Schemas.PassFieldContent> {
|
||||
private [passInstanceSymbol]: InstanceType<typeof PKPass>;
|
||||
private [sharedKeysPoolSymbol]: Set<string>;
|
||||
|
||||
constructor(
|
||||
passInstance: InstanceType<typeof PKPass>,
|
||||
keysPool: Set<string>,
|
||||
fieldSchema: typeof Schemas.Field | typeof Schemas.FieldWithRow,
|
||||
...args: Schemas.Field[]
|
||||
fieldSchema:
|
||||
| typeof Schemas.PassFieldContent
|
||||
| typeof Schemas.PassFieldContentWithRow,
|
||||
...args: Schemas.PassFieldContent[]
|
||||
) {
|
||||
super(...args);
|
||||
this[fieldSchemaSymbol] = fieldSchema;
|
||||
@@ -28,20 +30,20 @@ export default class FieldsArray extends Array<Schemas.Field> {
|
||||
this[sharedKeysPoolSymbol] = keysPool;
|
||||
}
|
||||
|
||||
push(...items: Schemas.Field[]): number {
|
||||
push(...items: Schemas.PassFieldContent[]): number {
|
||||
const validItems = registerWithValidation(this, ...items);
|
||||
return super.push(...validItems);
|
||||
}
|
||||
|
||||
pop(): Schemas.Field {
|
||||
pop(): Schemas.PassFieldContent {
|
||||
return unregisterItems(this, () => super.pop());
|
||||
}
|
||||
|
||||
splice(
|
||||
start: number,
|
||||
deleteCount: number,
|
||||
...items: Schemas.Field[]
|
||||
): Schemas.Field[] {
|
||||
...items: Schemas.PassFieldContent[]
|
||||
): Schemas.PassFieldContent[] {
|
||||
// Perfoming frozen check, validation and getting valid items
|
||||
const validItems = registerWithValidation(this, ...items);
|
||||
|
||||
@@ -56,7 +58,7 @@ export default class FieldsArray extends Array<Schemas.Field> {
|
||||
return unregisterItems(this, () => super.shift());
|
||||
}
|
||||
|
||||
unshift(...items: Schemas.Field[]) {
|
||||
unshift(...items: Schemas.PassFieldContent[]) {
|
||||
const validItems = registerWithValidation(this, ...items);
|
||||
return super.unshift(...validItems);
|
||||
}
|
||||
@@ -64,11 +66,11 @@ export default class FieldsArray extends Array<Schemas.Field> {
|
||||
|
||||
function registerWithValidation(
|
||||
instance: InstanceType<typeof FieldsArray>,
|
||||
...items: Schemas.Field[]
|
||||
...items: Schemas.PassFieldContent[]
|
||||
) {
|
||||
Utils.assertUnfrozen(instance[passInstanceSymbol]);
|
||||
|
||||
let validItems: Schemas.Field[] = [];
|
||||
let validItems: Schemas.PassFieldContent[] = [];
|
||||
|
||||
for (const field of items) {
|
||||
if (!field) {
|
||||
@@ -109,7 +111,7 @@ function unregisterItems(
|
||||
) {
|
||||
Utils.assertUnfrozen(instance[passInstanceSymbol]);
|
||||
|
||||
const element: Schemas.Field = removeFn();
|
||||
const element: Schemas.PassFieldContent = removeFn();
|
||||
instance[sharedKeysPoolSymbol].delete(element.key);
|
||||
return element;
|
||||
}
|
||||
|
||||
@@ -302,7 +302,7 @@ export default class PKPass extends Bundle {
|
||||
* instance has not a valid type set yet.
|
||||
*/
|
||||
|
||||
public get primaryFields(): Schemas.Field[] {
|
||||
public get primaryFields(): Schemas.PassFieldContent[] {
|
||||
return this[propsSymbol][this.type].primaryFields;
|
||||
}
|
||||
|
||||
@@ -314,7 +314,7 @@ export default class PKPass extends Bundle {
|
||||
* instance has not a valid type set yet.
|
||||
*/
|
||||
|
||||
public get secondaryFields(): Schemas.Field[] {
|
||||
public get secondaryFields(): Schemas.PassFieldContent[] {
|
||||
return this[propsSymbol][this.type].secondaryFields;
|
||||
}
|
||||
|
||||
@@ -331,7 +331,7 @@ export default class PKPass extends Bundle {
|
||||
* instance has not a valid type set yet.
|
||||
*/
|
||||
|
||||
public get auxiliaryFields(): Schemas.FieldWithRow[] {
|
||||
public get auxiliaryFields(): Schemas.PassFieldContentWithRow[] {
|
||||
return this[propsSymbol][this.type].auxiliaryFields;
|
||||
}
|
||||
|
||||
@@ -343,7 +343,7 @@ export default class PKPass extends Bundle {
|
||||
* instance has not a valid type set yet.
|
||||
*/
|
||||
|
||||
public get headerFields(): Schemas.Field[] {
|
||||
public get headerFields(): Schemas.PassFieldContent[] {
|
||||
return this[propsSymbol][this.type].headerFields;
|
||||
}
|
||||
|
||||
@@ -355,7 +355,7 @@ export default class PKPass extends Bundle {
|
||||
* instance has not a valid type set yet.
|
||||
*/
|
||||
|
||||
public get backFields(): Schemas.Field[] {
|
||||
public get backFields(): Schemas.PassFieldContent[] {
|
||||
return this[propsSymbol][this.type].backFields;
|
||||
}
|
||||
|
||||
@@ -368,7 +368,7 @@ export default class PKPass extends Bundle {
|
||||
* type is not "eventTicket".
|
||||
*/
|
||||
|
||||
public get additionalInfoFields(): Schemas.Field[] {
|
||||
public get additionalInfoFields(): Schemas.PassFieldContent[] {
|
||||
return this[propsSymbol]["eventTicket"].additionalInfoFields;
|
||||
}
|
||||
|
||||
@@ -411,32 +411,34 @@ export default class PKPass extends Bundle {
|
||||
headerFields /******/: new FieldsArray(
|
||||
this,
|
||||
sharedKeysPool,
|
||||
Schemas.Field,
|
||||
Schemas.PassFieldContent,
|
||||
),
|
||||
primaryFields /*****/: new FieldsArray(
|
||||
this,
|
||||
sharedKeysPool,
|
||||
Schemas.Field,
|
||||
Schemas.PassFieldContent,
|
||||
),
|
||||
secondaryFields /***/: new FieldsArray(
|
||||
this,
|
||||
sharedKeysPool,
|
||||
Schemas.Field,
|
||||
Schemas.PassFieldContent,
|
||||
),
|
||||
auxiliaryFields /***/: new FieldsArray(
|
||||
this,
|
||||
sharedKeysPool,
|
||||
type === "eventTicket" ? Schemas.FieldWithRow : Schemas.Field,
|
||||
type === "eventTicket"
|
||||
? Schemas.PassFieldContentWithRow
|
||||
: Schemas.PassFieldContent,
|
||||
),
|
||||
backFields /********/: new FieldsArray(
|
||||
this,
|
||||
sharedKeysPool,
|
||||
Schemas.Field,
|
||||
Schemas.PassFieldContent,
|
||||
),
|
||||
additionalInfoFields: new FieldsArray(
|
||||
this,
|
||||
sharedKeysPool,
|
||||
Schemas.Field,
|
||||
Schemas.PassFieldContent,
|
||||
),
|
||||
transitType: undefined,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user