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