Skip to content

Commit

Permalink
feat: beside the 'with' methods in the builder which will replace exi…
Browse files Browse the repository at this point in the history
…sting configuration for that field, I've added 'add' methods to add to existing configuration
  • Loading branch information
sksadjad committed Apr 3, 2023
1 parent 38849af commit 9d42152
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
29 changes: 25 additions & 4 deletions packages/issuer/lib/builder/CredentialSupportedV1_11Builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class CredentialSupportedV1_11Builder {
return this
}

withTypes(type: string | string[]): CredentialSupportedV1_11Builder {
addTypes(type: string | string[]): CredentialSupportedV1_11Builder {
if (!Array.isArray(type)) {
this.types = this.types ? [...this.types, type] : [type]
} else {
Expand All @@ -38,7 +38,13 @@ export class CredentialSupportedV1_11Builder {
}
return this
}
withCryptographicBindingMethod(method: string | string[]): CredentialSupportedV1_11Builder {

withTypes(type: string | string[]): CredentialSupportedV1_11Builder {
this.types = Array.isArray(type) ? type : [type]
return this
}

addCryptographicBindingMethod(method: string | string[]): CredentialSupportedV1_11Builder {
if (!Array.isArray(method)) {
this.cryptographicBindingMethodsSupported = this.cryptographicBindingMethodsSupported
? [...this.cryptographicBindingMethodsSupported, method]
Expand All @@ -51,7 +57,12 @@ export class CredentialSupportedV1_11Builder {
return this
}

withCryptographicSuitesSupported(suit: string | string[]): CredentialSupportedV1_11Builder {
withCryptographicBindingMethod(method: string | string[]): CredentialSupportedV1_11Builder {
this.cryptographicBindingMethodsSupported = Array.isArray(method) ? method : [method]
return this
}

addCryptographicSuitesSupported(suit: string | string[]): CredentialSupportedV1_11Builder {
if (!Array.isArray(suit)) {
this.cryptographicSuitesSupported = this.cryptographicSuitesSupported ? [...this.cryptographicSuitesSupported, suit] : [suit]
} else {
Expand All @@ -60,7 +71,12 @@ export class CredentialSupportedV1_11Builder {
return this
}

withCredentialDisplay(credentialDisplay: Display | Display[]): CredentialSupportedV1_11Builder {
withCryptographicSuitesSupported(suit: string | string[]): CredentialSupportedV1_11Builder {
this.cryptographicSuitesSupported = Array.isArray(suit) ? suit : [suit]
return this
}

addCredentialDisplay(credentialDisplay: Display | Display[]): CredentialSupportedV1_11Builder {
if (!Array.isArray(credentialDisplay)) {
this.display = this.display ? [...this.display, credentialDisplay] : [credentialDisplay]
} else {
Expand All @@ -69,6 +85,11 @@ export class CredentialSupportedV1_11Builder {
return this
}

withCredentialDisplay(credentialDisplay: Display | Display[]): CredentialSupportedV1_11Builder {
this.display = Array.isArray(credentialDisplay) ? credentialDisplay : [credentialDisplay]
return this
}

withIssuerCredentialSubjectDisplay(
subjectProperty: string,
issuerCredentialSubjectDisplay: IssuerCredentialSubjectDisplay
Expand Down
12 changes: 12 additions & 0 deletions packages/issuer/lib/builder/VcIssuerBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ export class VcIssuerBuilder {
}

public withIssuerDisplay(issuerDisplay: Display[] | Display): VcIssuerBuilder {
this.issuerDisplay = Array.isArray(issuerDisplay) ? issuerDisplay : [issuerDisplay]
return this
}

public addIssuerDisplay(issuerDisplay: Display[] | Display): VcIssuerBuilder {
if (!Array.isArray(issuerDisplay)) this.issuerDisplay = this.issuerDisplay ? [...this.issuerDisplay, issuerDisplay] : [issuerDisplay]
else {
this.issuerDisplay = this.issuerDisplay ? [...this.issuerDisplay, ...issuerDisplay] : issuerDisplay
Expand All @@ -46,6 +51,13 @@ export class VcIssuerBuilder {

public withCredentialsSupported(
credentialSupported: CredentialIssuerMetadataSupportedCredentials | CredentialIssuerMetadataSupportedCredentials[]
): VcIssuerBuilder {
this.credentialsSupported = Array.isArray(credentialSupported) ? credentialSupported : [credentialSupported]
return this
}

public addCredentialsSupported(
credentialSupported: CredentialIssuerMetadataSupportedCredentials | CredentialIssuerMetadataSupportedCredentials[]
): VcIssuerBuilder {
if (!Array.isArray(credentialSupported))
this.credentialsSupported = this.credentialsSupported ? [...this.credentialsSupported, credentialSupported] : [credentialSupported]
Expand Down

0 comments on commit 9d42152

Please sign in to comment.