Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reconcile string enums with generated union types #808

Closed
wilsonianb opened this issue Dec 2, 2022 · 0 comments · Fixed by #956
Closed

Reconcile string enums with generated union types #808

wilsonianb opened this issue Dec 2, 2022 · 0 comments · Fixed by #956
Labels
pkg: auth Changes in the GNAP auth package. pkg: backend Changes in the backend package.

Comments

@wilsonianb
Copy link
Contributor

auth and backend have been handling grant access types and actions as string enums:

export enum AccessType {
Account = 'account',
IncomingPayment = 'incoming-payment',
OutgoingPayment = 'outgoing-payment',
Quote = 'quote'
}
export enum Action {
Create = 'create',
Read = 'read',
List = 'list',
Complete = 'complete'
}

export enum AccessType {
IncomingPayment = 'incoming-payment',
OutgoingPayment = 'outgoing-payment',
Quote = 'quote'
}
export enum AccessAction {
Create = 'create',
Read = 'read',
ReadAll = 'read-all',
Complete = 'complete',
List = 'list',
ListAll = 'list-all'
}

open-payments's generated types define distinct access typescript types for individual access types (incoming/outgoing payment, quote):

"access-item":
| external["https://raw.githubusercontent.com/interledger/open-payments/b363d33038fe789e5388f04f80ddd06a4fa97093/openapi/schemas.yaml"]["components"]["schemas"]["access-incoming"]
| external["https://raw.githubusercontent.com/interledger/open-payments/b363d33038fe789e5388f04f80ddd06a4fa97093/openapi/schemas.yaml"]["components"]["schemas"]["access-outgoing"]
| external["https://raw.githubusercontent.com/interledger/open-payments/b363d33038fe789e5388f04f80ddd06a4fa97093/openapi/schemas.yaml"]["components"]["schemas"]["access-quote"];
/** access-incoming */
"access-incoming": {
/** @description The type of resource request as a string. This field defines which other fields are allowed in the request object. */
type: "incoming-payment";
/** @description The types of actions the client instance will take at the RS as an array of strings. */
actions: (
| "create"
| "complete"
| "read"
| "read-all"
| "list"
| "list-all"
)[];
/**
* Format: uri
* @description A string identifier indicating a specific resource at the RS.
*/
identifier?: string;
};
/** access-outgoing */
"access-outgoing": {
/** @description The type of resource request as a string. This field defines which other fields are allowed in the request object. */
type: "outgoing-payment";
/** @description The types of actions the client instance will take at the RS as an array of strings. */
actions: ("create" | "read" | "read-all" | "list" | "list-all")[];
/**
* Format: uri
* @description A string identifier indicating a specific resource at the RS.
*/
identifier: string;
limits?: external["https://raw.githubusercontent.com/interledger/open-payments/b363d33038fe789e5388f04f80ddd06a4fa97093/openapi/schemas.yaml"]["components"]["schemas"]["limits-outgoing"];
};
/** access-quote */
"access-quote": {
/** @description The type of resource request as a string. This field defines which other fields are allowed in the request object. */
type: "quote";
/** @description The types of actions the client instance will take at the RS as an array of strings. */
actions: ("create" | "read" | "read-all")[];
};

As is they do not play nicely with each other.
One possible solution is to ditch the string enums in favor of the generated types.
In the future it may be possible to at least generate the actions as enums:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: auth Changes in the GNAP auth package. pkg: backend Changes in the backend package.
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant