Skip to content

Commit

Permalink
Add types for /v2/recipes
Browse files Browse the repository at this point in the history
  • Loading branch information
darthmaim committed Jul 26, 2024
1 parent 76bd812 commit 8e7ac8f
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/slow-hairs-pull.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@gw2api/types": patch
---

Add types for `/v2/recipes`
124 changes: 123 additions & 1 deletion packages/types/data/recipe.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,124 @@
import type { SchemaAfter, SchemaVersion } from "../schema";

export type CraftingDiscipline = 'Armorsmith'| 'Artificer'| 'Chef'| 'Huntsman'| 'Jeweler'| 'Leatherworker'| 'Scribe'| 'Tailor'| 'Weaponsmith';
/**
* Recipe as returned from /v2/recipes
* @see https://wiki.guildwars2.com/wiki/API:2/recipes
*/
export type Recipe<Schema extends SchemaVersion = undefined> =
Schema extends undefined ? Recipe_Base :
Schema extends SchemaAfter<'2022-03-09T02:00:00.000Z'> | 'latest' ? Recipe_2022_03_09 :
Recipe_Base;

type Recipe_Base = {
/** The recipe id */
id: number;

/** The id formatted as a chatlink */
chat_link: string;

/** Crafting Disciplines that can use the recipe */
disciplines: CraftingDiscipline[];

/** Recipe flags */
flags: RecipeFlag[];

/** List of recipe ingredients */
ingredients: {
/** The item id used as ingredient */
item_id: number;

/** The quantity of this ingredient */
count: number;
}[];

/** The required rating to craft the recipe */
min_rating: number;

/** The amount of items produced */
output_item_count: number;

/** The item id of the produced item */
output_item_id: number;

/** The id of the produced guild upgrade (/v2/guild/upgrades) */
output_upgrade_id?: number;

/** The time it takes to craft in milliseconds */
time_to_craft_ms: number;

/** The type of the recipe */
type: RecipeType;
};

type Recipe_2022_03_09 = Omit<Recipe_Base, 'ingredients'> & {
/** List of recipe ingredients */
ingredients: {
/** The type of ingredient required */
type: 'Item' | 'GuildUpgrade' | 'Currency';

/** The id of the ingredient */
id: number;

/** The quantity of this ingredient */
count: number;
}[];
}

export type CraftingDiscipline = 'Armorsmith' | 'Artificer' | 'Chef' | 'Huntsman' | 'Jeweler' | 'Leatherworker' | 'Scribe' | 'Tailor' | 'Weaponsmith';

// TODO: extend item type?
export type RecipeType =
| 'Refinement'
| 'Insignia'
| 'Inscription'
| 'Shoulders'
| 'Boots'
| 'Gloves'
| 'Coat'
| 'Helm'
| 'Leggings'
| 'Component'
| 'UpgradeComponent'
| 'Bag'
| 'Bulk'
| 'Snack'
| 'Seasoning'
| 'IngredientCooking'
| 'Soup'
| 'Meal'
| 'Dessert'
| 'Feast'
| 'Dye'
| 'Amulet'
| 'Ring'
| 'Earring'
| 'Staff'
| 'Trident'
| 'Scepter'
| 'Focus'
| 'Potion'
| 'Consumable'
| 'Rifle'
| 'Warhorn'
| 'LongBow'
| 'ShortBow'
| 'Torch'
| 'Speargun'
| 'Pistol'
| 'Shield'
| 'Harpoon'
| 'Sword'
| 'Axe'
| 'Dagger'
| 'Greatsword'
| 'Hammer'
| 'Mace'
| 'RefinementObsidian'
| 'RefinementEctoplasm'
| 'Backpack'
| 'GuildDecoration'
| 'LegendaryComponent'
| 'GuildConsumableWvw'
| 'GuildConsumable';

export type RecipeFlag = 'AutoLearned' | 'LearnedFromItem';
2 changes: 2 additions & 0 deletions packages/types/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type { Currency } from './data/currency';
import type { Item } from './data/item';
import type { MaterialCategory } from './data/material';
import type { Quaggan } from './data/quaggan';
import type { Recipe } from './data/recipe';
import type { Tokeninfo } from './data/tokeninfo';
import type { WizardsVault, WizardsVaultListing, WizardsVaultObjective } from './data/wizardsvault';
import type { SchemaVersion } from './schema';
Expand Down Expand Up @@ -416,6 +417,7 @@ export type EndpointType<Url extends KnownEndpoint | (string & {}), Schema exten
Url extends BulkExpandedEndpointUrl<'/v2/items', number> ? BulkExpandedResponseType<'/v2/items', Url, number, Item<Schema>> :
Url extends BulkExpandedEndpointUrl<'/v2/materials', number> ? BulkExpandedResponseType<'/v2/materials', Url, number, MaterialCategory> :
Url extends BulkExpandedEndpointUrl<'/v2/quaggans', string> ? BulkExpandedResponseType<'/v2/quaggans', Url, string, Quaggan> :
Url extends BulkExpandedEndpointUrl<'/v2/recipes', number> ? BulkExpandedResponseType<'/v2/recipes', Url, number, Recipe<Schema>> :
Url extends BulkExpandedEndpointUrl<'/v2/commerce/listings', number> ? BulkExpandedResponseType<'/v2/commerce/listings', Url, number, Listing> :
Url extends BulkExpandedEndpointUrl<'/v2/commerce/prices', number> ? BulkExpandedResponseType<'/v2/commerce/prices', Url, number, Price> :
Url extends PaginatedEndpointUrl<'/v2/commerce/transactions/current/buys'> ? TransactionCurrent[] :
Expand Down

0 comments on commit 8e7ac8f

Please sign in to comment.