Skip to content

Instantly share code, notes, and snippets.

@doga
Last active December 11, 2022 18:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save doga/f130bb6c678b109b16bbf2db25dbb853 to your computer and use it in GitHub Desktop.
Save doga/f130bb6c678b109b16bbf2db25dbb853 to your computer and use it in GitHub Desktop.
// TypeScript pseudocode for an e-commerce use case.
// Placeholder for the Json datatype. See https://qworum.net/en/specification/v1/#json
type Json = string | number | boolean | Array<any> | {} | null;
/*
* Interface for a payment processing Qworum service.
*/
interface IPaymentProcessor {
lastPayment: Json; // Details of the lastly processed payment.
/*
* Interactive end-point that adds items to the shopping cart.
* Absolute path within web origin: /pay/
* @param {Json} total - Total amount to pay
* @return {Json} Details of the processed payment.
* @throws
*/
pay: (total: Json) => Json;
}
/*
* Interface for a shopping cart Qworum service.
*/
interface IShoppingCart {
lineItems : Json; // All articles in the shopping cart.
total : Json; // Total in EUR of all articles in the shopping cart.
paymentProcessor: IPaymentProcessor; // Remote service.
/*
* Interactive end-point that adds items to the shopping cart.
* Absolute path within web origin: /add-items/
*/
addItems: (lineItemsToAdd: Json) => Json;
/*
* Interactive end-point that shows the cart contents to the end-user,
* who can then check out.
* Absolute path within web origin: /show-cart/
*/
showCart: () => Json;
}
/*
* Interface for an e-shop Qworum service. Application available at the `home` end-point.
*/
interface IShop {
shoppingCart: IShoppingCart; // Remote service.
/*
* Main interactive end-point. Never returns.
* Absolute path within web origin: /home/
*/
home: () => Json;
/*
* Interactive end-point that shows an article to the end-user,
* who can then add the article to the shopping cart.
* This end-point is called internally by the home end-point.
* Absolute path within web origin: /view-article/
*/
viewArticle(articleId: Json): Json;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment