mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 22:25:24 +00:00
Merge pull request #118 from alexandercerutti/fix/fields-row
Fix to unsupported fields rows
This commit is contained in:
@@ -41,6 +41,20 @@
|
|||||||
"label": "LOCATION",
|
"label": "LOCATION",
|
||||||
"value": "Moscone West"
|
"value": "Moscone West"
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
"auxiliaryFields": [
|
||||||
|
{
|
||||||
|
"key": "Foo",
|
||||||
|
"value": "foo2",
|
||||||
|
"label": "Foo(l)",
|
||||||
|
"row": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "Foo2",
|
||||||
|
"value": "foo3",
|
||||||
|
"label": "Foo(l)2",
|
||||||
|
"row": 1
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import * as Messages from "./messages";
|
|||||||
|
|
||||||
const passInstanceSymbol = Symbol("passInstance");
|
const passInstanceSymbol = Symbol("passInstance");
|
||||||
const sharedKeysPoolSymbol = Symbol("keysPool");
|
const sharedKeysPoolSymbol = Symbol("keysPool");
|
||||||
|
const fieldSchemaSymbol = Symbol("fieldSchema");
|
||||||
|
|
||||||
export default class FieldsArray extends Array<Schemas.Field> {
|
export default class FieldsArray extends Array<Schemas.Field> {
|
||||||
private [passInstanceSymbol]: InstanceType<typeof PKPass>;
|
private [passInstanceSymbol]: InstanceType<typeof PKPass>;
|
||||||
@@ -18,9 +19,11 @@ export default class FieldsArray extends Array<Schemas.Field> {
|
|||||||
constructor(
|
constructor(
|
||||||
passInstance: InstanceType<typeof PKPass>,
|
passInstance: InstanceType<typeof PKPass>,
|
||||||
keysPool: Set<string>,
|
keysPool: Set<string>,
|
||||||
|
fieldSchema: typeof Schemas.Field | typeof Schemas.FieldWithRow,
|
||||||
...args: Schemas.Field[]
|
...args: Schemas.Field[]
|
||||||
) {
|
) {
|
||||||
super(...args);
|
super(...args);
|
||||||
|
this[fieldSchemaSymbol] = fieldSchema;
|
||||||
this[passInstanceSymbol] = passInstance;
|
this[passInstanceSymbol] = passInstance;
|
||||||
this[sharedKeysPoolSymbol] = keysPool;
|
this[sharedKeysPoolSymbol] = keysPool;
|
||||||
}
|
}
|
||||||
@@ -75,7 +78,7 @@ function registerWithValidation(
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
Schemas.assertValidity(
|
Schemas.assertValidity(
|
||||||
Schemas.Field,
|
instance[fieldSchemaSymbol],
|
||||||
field,
|
field,
|
||||||
Messages.FIELDS.INVALID,
|
Messages.FIELDS.INVALID,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -287,9 +287,14 @@ export default class PKPass extends Bundle {
|
|||||||
* if no valid pass.json has been parsed yet
|
* if no valid pass.json has been parsed yet
|
||||||
* or, anyway, if a valid type has not been
|
* or, anyway, if a valid type has not been
|
||||||
* set yet.
|
* set yet.
|
||||||
|
*
|
||||||
|
* For Typescript users: this signature allows
|
||||||
|
* in any case to add the 'row' field, but on
|
||||||
|
* runtime they are only allowed on "eventTicket"
|
||||||
|
* passes.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public get auxiliaryFields(): Schemas.Field[] {
|
public get auxiliaryFields(): Schemas.FieldWithRow[] {
|
||||||
return this[propsSymbol][this.type].auxiliaryFields;
|
return this[propsSymbol][this.type].auxiliaryFields;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -353,12 +358,32 @@ export default class PKPass extends Bundle {
|
|||||||
const sharedKeysPool = new Set<string>();
|
const sharedKeysPool = new Set<string>();
|
||||||
|
|
||||||
this[passTypeSymbol] = type;
|
this[passTypeSymbol] = type;
|
||||||
this[propsSymbol][this[passTypeSymbol]] = {
|
this[propsSymbol][type] = {
|
||||||
headerFields /******/: new FieldsArray(this, sharedKeysPool),
|
headerFields /******/: new FieldsArray(
|
||||||
primaryFields /*****/: new FieldsArray(this, sharedKeysPool),
|
this,
|
||||||
secondaryFields /***/: new FieldsArray(this, sharedKeysPool),
|
sharedKeysPool,
|
||||||
auxiliaryFields /***/: new FieldsArray(this, sharedKeysPool),
|
Schemas.Field,
|
||||||
backFields /********/: new FieldsArray(this, sharedKeysPool),
|
),
|
||||||
|
primaryFields /*****/: new FieldsArray(
|
||||||
|
this,
|
||||||
|
sharedKeysPool,
|
||||||
|
Schemas.Field,
|
||||||
|
),
|
||||||
|
secondaryFields /***/: new FieldsArray(
|
||||||
|
this,
|
||||||
|
sharedKeysPool,
|
||||||
|
Schemas.Field,
|
||||||
|
),
|
||||||
|
auxiliaryFields /***/: new FieldsArray(
|
||||||
|
this,
|
||||||
|
sharedKeysPool,
|
||||||
|
type === "eventTicket" ? Schemas.FieldWithRow : Schemas.Field,
|
||||||
|
),
|
||||||
|
backFields /********/: new FieldsArray(
|
||||||
|
this,
|
||||||
|
sharedKeysPool,
|
||||||
|
Schemas.Field,
|
||||||
|
),
|
||||||
transitType: undefined,
|
transitType: undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,10 @@ export interface Field {
|
|||||||
numberStyle?: string;
|
numberStyle?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface FieldWithRow extends Field {
|
||||||
|
row?: 0 | 1;
|
||||||
|
}
|
||||||
|
|
||||||
export const Field = Joi.object<Field>().keys({
|
export const Field = Joi.object<Field>().keys({
|
||||||
attributedValue: Joi.alternatives(
|
attributedValue: Joi.alternatives(
|
||||||
Joi.string().allow(""),
|
Joi.string().allow(""),
|
||||||
@@ -72,3 +76,9 @@ export const Field = Joi.object<Field>().keys({
|
|||||||
otherwise: Joi.string().forbidden(),
|
otherwise: Joi.string().forbidden(),
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const FieldWithRow = Field.concat(
|
||||||
|
Joi.object<FieldWithRow>().keys({
|
||||||
|
row: Joi.number().min(0).max(1),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import Joi from "joi";
|
import Joi from "joi";
|
||||||
import { Field } from "./Field";
|
import { Field, FieldWithRow } from "./Field";
|
||||||
|
|
||||||
export type TransitType =
|
export type TransitType =
|
||||||
| "PKTransitTypeAir"
|
| "PKTransitTypeAir"
|
||||||
@@ -13,7 +13,7 @@ export const TransitType = Joi.string().regex(
|
|||||||
);
|
);
|
||||||
|
|
||||||
export interface PassFields {
|
export interface PassFields {
|
||||||
auxiliaryFields: (Field & { row?: number })[];
|
auxiliaryFields: FieldWithRow[];
|
||||||
backFields: Field[];
|
backFields: Field[];
|
||||||
headerFields: Field[];
|
headerFields: Field[];
|
||||||
primaryFields: Field[];
|
primaryFields: Field[];
|
||||||
@@ -22,13 +22,7 @@ export interface PassFields {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const PassFields = Joi.object<PassFields>().keys({
|
export const PassFields = Joi.object<PassFields>().keys({
|
||||||
auxiliaryFields: Joi.array().items(
|
auxiliaryFields: Joi.array().items(FieldWithRow),
|
||||||
Joi.object()
|
|
||||||
.keys({
|
|
||||||
row: Joi.number().max(1).min(0),
|
|
||||||
})
|
|
||||||
.concat(Field),
|
|
||||||
),
|
|
||||||
backFields: Joi.array().items(Field),
|
backFields: Joi.array().items(Field),
|
||||||
headerFields: Joi.array().items(Field),
|
headerFields: Joi.array().items(Field),
|
||||||
primaryFields: Joi.array().items(Field),
|
primaryFields: Joi.array().items(Field),
|
||||||
|
|||||||
Reference in New Issue
Block a user