From 598128bef88f87f4ea0fe68b79f15de90b3450dd Mon Sep 17 00:00:00 2001 From: Florian Wendelborn <1133858+FlorianWendelborn@users.noreply.github.com> Date: Sat, 15 Jun 2024 04:11:34 +0200 Subject: [PATCH] feature(actions): Add Gems and Improved Currencies --- packages/actions/data/$schema.json | 48 ++++++---- packages/actions/data/bits-crafts.json | 2 +- packages/actions/data/bits.json | 110 +++++++++++----------- packages/actions/data/gems.json | 90 ++++++++++++++++++ packages/actions/source/data.test.ts | 123 ++++++++++++------------- packages/actions/source/data.ts | 7 +- packages/actions/source/index.ts | 14 ++- packages/actions/source/schema.ts | 33 +++---- packages/actions/source/types.ts | 13 +++ 9 files changed, 284 insertions(+), 156 deletions(-) create mode 100644 packages/actions/data/gems.json create mode 100644 packages/actions/source/types.ts diff --git a/packages/actions/data/$schema.json b/packages/actions/data/$schema.json index 8f5ed34..7551b70 100644 --- a/packages/actions/data/$schema.json +++ b/packages/actions/data/$schema.json @@ -8,12 +8,15 @@ "amount": { "type": "number" }, - "type": { - "enum": ["bit", "coin", "mote", "north-star"], + "id": { + "enum": ["bit", "coin", "gem", "mote", "north-star", "usd"], "type": "string" + }, + "type": { + "const": "currency" } }, - "required": ["amount", "type"] + "required": ["amount", "id", "type"] }, "itemAction": { "additionalProperties": false, @@ -76,6 +79,32 @@ "required": ["id", "type"], "type": "object" }, + { + "additionalProperties": false, + "properties": { + "id": { + "type": "string" + }, + "type": { + "const": "npc" + } + }, + "required": ["id", "type"], + "type": "object" + }, + { + "additionalProperties": false, + "properties": { + "type": { + "const": "website" + }, + "url": { + "type": "string" + } + }, + "required": ["type", "url"], + "type": "object" + }, { "additionalProperties": false, "properties": { @@ -96,19 +125,6 @@ }, "required": ["type"], "type": "object" - }, - { - "additionalProperties": false, - "properties": { - "id": { - "type": "string" - }, - "type": { - "const": "npc" - } - }, - "required": ["id", "type"], - "type": "object" } ], "type": "object" diff --git a/packages/actions/data/bits-crafts.json b/packages/actions/data/bits-crafts.json index 0164da6..77ea747 100644 --- a/packages/actions/data/bits-crafts.json +++ b/packages/actions/data/bits-crafts.json @@ -320,7 +320,7 @@ ] }, { - "inputs": [{ "amount": 15, "type": "coin" }], + "inputs": [{ "amount": 15, "id": "coin", "type": "currency" }], "outputs": [{ "amount": 1, "id": "GOLDEN_CARROT", "type": "item" }], "place": [{ "id": "ALCHEMIST", "type": "npc" }] }, diff --git a/packages/actions/data/bits.json b/packages/actions/data/bits.json index 6f74765..1e12c06 100644 --- a/packages/actions/data/bits.json +++ b/packages/actions/data/bits.json @@ -2,248 +2,248 @@ "$schema": "./$schema.json", "actions": [ { - "inputs": [{ "amount": 1500, "type": "bit" }], + "inputs": [{ "amount": 1500, "id": "bit", "type": "currency" }], "outputs": [{ "amount": 1, "id": "GOD_POTION_2", "type": "item" }], "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 1350, "type": "bit" }], + "inputs": [{ "amount": 1350, "id": "bit", "type": "currency" }], "outputs": [{ "amount": 1, "id": "KISMET_FEATHER", "type": "item" }], "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 500, "type": "bit" }], + "inputs": [{ "amount": 500, "id": "bit", "type": "currency" }], "outputs": [{ "amount": 1, "id": "KAT_FLOWER", "type": "item" }], "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 2500, "type": "bit" }], + "inputs": [{ "amount": 2500, "id": "bit", "type": "currency" }], "outputs": [{ "amount": 1, "id": "KAT_BOUQUET", "type": "item" }], "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 3000, "type": "bit" }], + "inputs": [{ "amount": 3000, "id": "bit", "type": "currency" }], "outputs": [{ "amount": 1, "id": "HEAT_CORE", "type": "item" }], "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 300, "type": "bit" }], + "inputs": [{ "amount": 300, "id": "bit", "type": "currency" }], "outputs": [ { "amount": 1, "id": "HYPER_CATALYST_UPGRADE", "type": "item" } ], "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 8000, "type": "bit" }], + "inputs": [{ "amount": 8000, "id": "bit", "type": "currency" }], "outputs": [ { "amount": 1, "id": "ULTIMATE_CARROT_CANDY_UPGRADE", "type": "item" } ], "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 1200, "type": "bit" }], + "inputs": [{ "amount": 1200, "id": "bit", "type": "currency" }], "outputs": [ { "amount": 1, "id": "COLOSSAL_EXP_BOTTLE_UPGRADE", "type": "item" } ], "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 4000, "type": "bit" }], + "inputs": [{ "amount": 4000, "id": "bit", "type": "currency" }], "outputs": [ { "amount": 1, "id": "JUMBO_BACKPACK_UPGRADE", "type": "item" } ], "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 1500, "type": "bit" }], + "inputs": [{ "amount": 1500, "id": "bit", "type": "currency" }], "outputs": [ { "amount": 1, "id": "MINION_STORAGE_EXPANDER", "type": "item" } ], "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 1200, "type": "bit" }], + "inputs": [{ "amount": 1200, "id": "bit", "type": "currency" }], "outputs": [{ "amount": 1, "id": "MATRIARCH_PARFUM", "type": "item" }], "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 2000, "type": "bit" }], + "inputs": [{ "amount": 2000, "id": "bit", "type": "currency" }], "outputs": [{ "amount": 1, "id": "HOLOGRAM", "type": "item" }], "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 2000, "type": "bit" }], + "inputs": [{ "amount": 2000, "id": "bit", "type": "currency" }], "outputs": [{ "amount": 1, "id": "DITTO_BLOB", "type": "item" }], "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 12000, "type": "bit" }], + "inputs": [{ "amount": 12000, "id": "bit", "type": "currency" }], "outputs": [{ "amount": 1, "id": "BUILDERS_WAND", "type": "item" }], "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 5000, "type": "bit" }], + "inputs": [{ "amount": 5000, "id": "bit", "type": "currency" }], "outputs": [{ "amount": 1, "id": "BLOCK_ZAPPER", "type": "item" }], "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 15000, "type": "bit" }], + "inputs": [{ "amount": 15000, "id": "bit", "type": "currency" }], "outputs": [{ "amount": 1, "id": "BITS_TALISMAN", "type": "item" }], "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 8000, "type": "bit" }], + "inputs": [{ "amount": 8000, "id": "bit", "type": "currency" }], "outputs": [ { "amount": 1, "id": "POCKET_SACK_IN_A_SACK", "type": "item" } ], "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 14000, "type": "bit" }], + "inputs": [{ "amount": 14000, "id": "bit", "type": "currency" }], "outputs": [{ "amount": 1, "id": "LARGE_DUNGEON_SACK", "type": "item" }], "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 14000, "type": "bit" }], + "inputs": [{ "amount": 14000, "id": "bit", "type": "currency" }], "outputs": [{ "amount": 1, "id": "RUNE_SACK", "type": "item" }], "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 14000, "type": "bit" }], + "inputs": [{ "amount": 14000, "id": "bit", "type": "currency" }], "outputs": [{ "amount": 1, "id": "FLOWER_SACK", "type": "item" }], "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 14000, "type": "bit" }], + "inputs": [{ "amount": 14000, "id": "bit", "type": "currency" }], "outputs": [{ "amount": 1, "id": "DWARVEN_MINES_SACK", "type": "item" }], "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 14000, "type": "bit" }], + "inputs": [{ "amount": 14000, "id": "bit", "type": "currency" }], "outputs": [ { "amount": 1, "id": "CRYSTAL_HOLLOWS_SACK", "type": "item" } ], "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 4800, "type": "bit" }], + "inputs": [{ "amount": 4800, "id": "bit", "type": "currency" }], "outputs": [{ "amount": 1, "id": "PORTALIZER", "type": "item" }], "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 6450, "type": "bit" }], + "inputs": [{ "amount": 6450, "id": "bit", "type": "currency" }], "outputs": [{ "amount": 1, "id": "TRIO_CONTACTS_ADDON", "type": "item" }], "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 15000, "type": "bit" }], + "inputs": [{ "amount": 15000, "id": "bit", "type": "currency" }], "outputs": [{ "amount": 1, "id": "ABICASE", "type": "item" }], "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 25000, "type": "bit" }], + "inputs": [{ "amount": 25000, "id": "bit", "type": "currency" }], "outputs": [{ "amount": 1, "id": "ABICASE", "type": "item" }], "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 26000, "type": "bit" }], + "inputs": [{ "amount": 26000, "id": "bit", "type": "currency" }], "outputs": [{ "amount": 1, "id": "ABICASE", "type": "item" }], "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 17000, "type": "bit" }], + "inputs": [{ "amount": 17000, "id": "bit", "type": "currency" }], "outputs": [{ "amount": 1, "id": "ABICASE", "type": "item" }], "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 17000, "type": "bit" }], + "inputs": [{ "amount": 17000, "id": "bit", "type": "currency" }], "outputs": [{ "amount": 1, "id": "ABICASE", "type": "item" }], "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 17000, "type": "bit" }], + "inputs": [{ "amount": 17000, "id": "bit", "type": "currency" }], "outputs": [{ "amount": 1, "id": "ABICASE", "type": "item" }], "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 17000, "type": "bit" }], + "inputs": [{ "amount": 17000, "id": "bit", "type": "currency" }], "outputs": [{ "amount": 1, "id": "ABICASE", "type": "item" }], "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 17000, "type": "bit" }], + "inputs": [{ "amount": 17000, "id": "bit", "type": "currency" }], "outputs": [{ "amount": 1, "id": "ABICASE", "type": "item" }], "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 21000, "type": "bit" }], + "inputs": [{ "amount": 21000, "id": "bit", "type": "currency" }], "outputs": [{ "amount": 1, "id": "AUTOPET_RULES_2", "type": "item" }], "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 250000, "type": "bit" }], + "inputs": [{ "amount": 250000, "id": "bit", "type": "currency" }], "outputs": [{ "amount": 1, "id": "DYE_PURE_WHITE", "type": "item" }], "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 250000, "type": "bit" }], + "inputs": [{ "amount": 250000, "id": "bit", "type": "currency" }], "outputs": [{ "amount": 1, "id": "DYE_PURE_BLACK", "type": "item" }], "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 75, "type": "bit" }], + "inputs": [{ "amount": 75, "id": "bit", "type": "currency" }], "outputs": [{ "amount": 1, "id": "INFERNO_FUEL_BLOCK", "type": "item" }], "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 3600, "type": "bit" }], + "inputs": [{ "amount": 3600, "id": "bit", "type": "currency" }], "outputs": [{ "amount": 64, "id": "INFERNO_FUEL_BLOCK", "type": "item" }], "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 4000, "type": "bit" }], + "inputs": [{ "amount": 4000, "id": "bit", "type": "currency" }], "outputs": [ { "amount": 1, "id": "ENCHANTMENT_EXPERTISE_1", "type": "item" } ], "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 4000, "type": "bit" }], + "inputs": [{ "amount": 4000, "id": "bit", "type": "currency" }], "outputs": [ { "amount": 1, "id": "ENCHANTMENT_COMPACT_1", "type": "item" } ], "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 4000, "type": "bit" }], + "inputs": [{ "amount": 4000, "id": "bit", "type": "currency" }], "outputs": [ { "amount": 1, "id": "ENCHANTMENT_CULTIVATING_1", "type": "item" } ], "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 4000, "type": "bit" }], + "inputs": [{ "amount": 4000, "id": "bit", "type": "currency" }], "outputs": [ { "amount": 1, "id": "ENCHANTMENT_CHAMPION_1", "type": "item" } ], "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 6000, "type": "bit" }], + "inputs": [{ "amount": 6000, "id": "bit", "type": "currency" }], "outputs": [ { "amount": 1, "id": "ENCHANTMENT_HECATOMB_1", "type": "item" } ], "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 4000, "type": "bit" }], + "inputs": [{ "amount": 4000, "id": "bit", "type": "currency" }], "outputs": [ { "amount": 1, "id": "ENCHANTMENT_TOXOPHILITE_1", "type": "item" } ], "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 5000, "type": "bit" }], + "inputs": [{ "amount": 5000, "id": "bit", "type": "currency" }], "outputs": [ { "amount": 1, @@ -254,7 +254,7 @@ "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 5000, "type": "bit" }], + "inputs": [{ "amount": 5000, "id": "bit", "type": "currency" }], "outputs": [ { "amount": 1, @@ -265,7 +265,7 @@ "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 5000, "type": "bit" }], + "inputs": [{ "amount": 5000, "id": "bit", "type": "currency" }], "outputs": [ { "amount": 1, @@ -276,28 +276,28 @@ "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 5000, "type": "bit" }], + "inputs": [{ "amount": 5000, "id": "bit", "type": "currency" }], "outputs": [ { "amount": 1, "id": "TALISMAN_ENRICHMENT_DEFENSE", "type": "item" } ], "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 5000, "type": "bit" }], + "inputs": [{ "amount": 5000, "id": "bit", "type": "currency" }], "outputs": [ { "amount": 1, "id": "TALISMAN_ENRICHMENT_FEROCITY", "type": "item" } ], "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 5000, "type": "bit" }], + "inputs": [{ "amount": 5000, "id": "bit", "type": "currency" }], "outputs": [ { "amount": 1, "id": "TALISMAN_ENRICHMENT_HEALTH", "type": "item" } ], "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 5000, "type": "bit" }], + "inputs": [{ "amount": 5000, "id": "bit", "type": "currency" }], "outputs": [ { "amount": 1, @@ -308,14 +308,14 @@ "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 5000, "type": "bit" }], + "inputs": [{ "amount": 5000, "id": "bit", "type": "currency" }], "outputs": [ { "amount": 1, "id": "TALISMAN_ENRICHMENT_MAGIC_FIND", "type": "item" } ], "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 5000, "type": "bit" }], + "inputs": [{ "amount": 5000, "id": "bit", "type": "currency" }], "outputs": [ { "amount": 1, @@ -326,21 +326,21 @@ "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 5000, "type": "bit" }], + "inputs": [{ "amount": 5000, "id": "bit", "type": "currency" }], "outputs": [ { "amount": 1, "id": "TALISMAN_ENRICHMENT_STRENGTH", "type": "item" } ], "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 5000, "type": "bit" }], + "inputs": [{ "amount": 5000, "id": "bit", "type": "currency" }], "outputs": [ { "amount": 1, "id": "TALISMAN_ENRICHMENT_WALK_SPEED", "type": "item" } ], "place": [{ "id": "ELIZABETH", "type": "npc" }] }, { - "inputs": [{ "amount": 200, "type": "bit" }], + "inputs": [{ "amount": 200, "id": "bit", "type": "currency" }], "outputs": [ { "amount": 1, "id": "TALISMAN_ENRICHMENT_SWAPPER", "type": "item" } ], diff --git a/packages/actions/data/gems.json b/packages/actions/data/gems.json new file mode 100644 index 0000000..0f93200 --- /dev/null +++ b/packages/actions/data/gems.json @@ -0,0 +1,90 @@ +{ + "$schema": "./$schema.json", + "actions": [ + { + "inputs": [{ "amount": 4.99, "id": "usd", "type": "currency" }], + "outputs": [{ "amount": 675, "id": "gem", "type": "currency" }], + "place": [ + { + "id": "ELIZABETH", + "type": "npc" + }, + { + "type": "website", + "url": "https://store.hypixel.net/category/skyblock-gems" + } + ] + }, + { + "inputs": [{ "amount": 9.99, "id": "usd", "type": "currency" }], + "outputs": [{ "amount": 1390, "id": "gem", "type": "currency" }], + "place": [ + { + "id": "ELIZABETH", + "type": "npc" + }, + { + "type": "website", + "url": "https://store.hypixel.net/category/skyblock-gems" + } + ] + }, + { + "inputs": [{ "amount": 24.99, "id": "usd", "type": "currency" }], + "outputs": [{ "amount": 3600, "id": "gem", "type": "currency" }], + "place": [ + { + "id": "ELIZABETH", + "type": "npc" + }, + { + "type": "website", + "url": "https://store.hypixel.net/category/skyblock-gems" + } + ] + }, + { + "inputs": [{ "amount": 49.99, "id": "usd", "type": "currency" }], + "outputs": [{ "amount": 7300, "id": "gem", "type": "currency" }], + "place": [ + { + "id": "ELIZABETH", + "type": "npc" + }, + { + "type": "website", + "url": "https://store.hypixel.net/category/skyblock-gems" + } + ] + }, + { + "inputs": [{ "amount": 99.99, "id": "usd", "type": "currency" }], + "outputs": [{ "amount": 16400, "id": "gem", "type": "currency" }], + "place": [ + { + "id": "ELIZABETH", + "type": "npc" + }, + { + "type": "website", + "url": "https://store.hypixel.net/category/skyblock-gems" + } + ] + }, + { + "inputs": [{ "amount": 325, "id": "gem", "type": "currency" }], + "outputs": [{ "amount": 1, "id": "BOOSTER_COOKIE", "type": "item" }], + "place": [{ "id": "ELIZABETH", "type": "npc" }] + }, + { + "inputs": [{ "amount": 1950, "id": "gem", "type": "currency" }], + "outputs": [{ "amount": 6, "id": "BOOSTER_COOKIE", "type": "item" }], + "place": [{ "id": "ELIZABETH", "type": "npc" }] + }, + { + "inputs": [{ "amount": 3900, "id": "gem", "type": "currency" }], + "outputs": [{ "amount": 12, "id": "BOOSTER_COOKIE", "type": "item" }], + "place": [{ "id": "ELIZABETH", "type": "npc" }] + } + ] +} diff --git a/packages/actions/source/data.test.ts b/packages/actions/source/data.test.ts index 1255bcd..05addec 100644 --- a/packages/actions/source/data.test.ts +++ b/packages/actions/source/data.test.ts @@ -1,85 +1,82 @@ -import { ActionIoItem, actionSchema } from './schema' +import { actionSchema } from './schema' import { allActions } from './data' import { z } from 'zod' import { describe, expect, test } from 'bun:test' import assert from 'node:assert' +import { ActionIoItem } from './types' test('all actions follow the schema', () => { expect(() => z.array(actionSchema).parse(allActions)).not.toThrow() }) -describe('every action’s inputs match its outputs', () => { - /** - * Simplifies and "sorts" action input/output items - */ - const sumUp = (ios: ActionIoItem[]): Map => { - const result = new Map() +/** + * Simplifies and "sorts" action input/output items + */ +const sumUp = (ios: ActionIoItem[]): Map => { + const result = new Map() - for (const io of ios) { - const previousValue = result.get(io.id) ?? 0 - result.set(io.id, previousValue + io.amount) - } - - return result + for (const io of ios) { + const previousValue = result.get(io.id) ?? 0 + result.set(io.id, previousValue + io.amount) } - test('sumUp works', () => { - expect( - sumUp([ - { - amount: 1, - id: 'FOO', - type: 'item', - }, - { - amount: 2, - id: 'BAR', - type: 'item', - }, - { - amount: 1, - id: 'BAZ', - type: 'item', - }, - ]), - ).toEqual( - sumUp([ - { - amount: 1, - id: 'BAR', - type: 'item', - }, - { - amount: 1, - id: 'FOO', - type: 'item', - }, - { - amount: 1, - id: 'BAZ', - type: 'item', - }, - { - amount: 1, - id: 'BAR', - type: 'item', - }, - ]), - ) - }) + return result +} + +test('sumUp works', () => { + expect( + sumUp([ + { + amount: 1, + id: 'FOO', + type: 'item', + }, + { + amount: 2, + id: 'BAR', + type: 'item', + }, + { + amount: 1, + id: 'BAZ', + type: 'item', + }, + ]), + ).toEqual( + sumUp([ + { + amount: 1, + id: 'BAR', + type: 'item', + }, + { + amount: 1, + id: 'FOO', + type: 'item', + }, + { + amount: 1, + id: 'BAZ', + type: 'item', + }, + { + amount: 1, + id: 'BAR', + type: 'item', + }, + ]), + ) +}) +describe('every action’s inputs match its crafing grid', () => { for (const action of allActions) { for (const grid of action.place.filter((x) => x.type === 'workbench')) { test(`${JSON.stringify(action.outputs)} is valid`, () => { assert(grid.type === 'workbench') - const actual = sumUp( - action.inputs.filter((x) => x.type === 'item') as ActionIoItem[], - ) + const actual = sumUp(action.inputs.filter((x) => x.type === 'item')) - const expected = sumUp( - grid.grid.filter((x) => x !== null) as ActionIoItem[], - ) + const expected = sumUp(grid.grid.filter((x) => x !== null)) expect(actual).toEqual(expected) }) diff --git a/packages/actions/source/data.ts b/packages/actions/source/data.ts index d345585..a5a858b 100644 --- a/packages/actions/source/data.ts +++ b/packages/actions/source/data.ts @@ -1,8 +1,11 @@ import { actions as _bits } from '../data/bits.json' import { actions as _bitsCrafts } from '../data/bits-crafts.json' -import { Action } from './schema' +import { actions as _gems } from '../data/gems.json' +import { Action } from './types' export const bits = _bits as Action[] export const bitsCrafts = _bitsCrafts as Action[] -export const allActions = [...bits, ...bitsCrafts] +export const gems = _gems as Action[] + +export const allActions = [...bits, ...bitsCrafts, ...gems] diff --git a/packages/actions/source/index.ts b/packages/actions/source/index.ts index a4c57a6..1c2862d 100644 --- a/packages/actions/source/index.ts +++ b/packages/actions/source/index.ts @@ -1,2 +1,14 @@ export * from './data' -export * from './schema' +export { + Action, + ActionCurrency, + ActionIo, + ActionIoCurrency, + ActionIoItem, +} from './types' +export { + actionIoItemSchema, + actionIoSchema, + actionPlaceSchema, + actionSchema, +} from './schema' diff --git a/packages/actions/source/schema.ts b/packages/actions/source/schema.ts index f34d24f..afd12e3 100644 --- a/packages/actions/source/schema.ts +++ b/packages/actions/source/schema.ts @@ -2,32 +2,25 @@ import { z } from 'zod' export const actionIoItemSchema = z .object({ - amount: z.number().int().finite(), + amount: z.number().finite(), id: z.string(), type: z.literal('item'), }) .strict() -export type ActionIoItem = z.output +export const actionIoCurrencySchema = z + .object({ + amount: z.number().finite(), + id: z.enum(['bit', 'coin', 'gem', 'northStar', 'second', 'usd']), + type: z.literal('currency'), + }) + .strict() export const actionIoSchema = z.discriminatedUnion('type', [ - z - .object({ - amount: z.number().int().finite(), - type: z.literal('bit'), - }) - .strict(), - z - .object({ - amount: z.number().int().finite(), - type: z.literal('coin'), - }) - .strict(), + actionIoCurrencySchema, actionIoItemSchema, ]) -export type ActionIo = z.output - export const actionPlaceSchema = z.discriminatedUnion('type', [ z .object({ @@ -35,6 +28,12 @@ export const actionPlaceSchema = z.discriminatedUnion('type', [ type: z.literal('npc'), }) .strict(), + z + .object({ + type: z.literal('website'), + url: z.string().url(), + }) + .strict(), z .object({ grid: z.array(actionIoItemSchema.nullable()).length(9), @@ -50,5 +49,3 @@ export const actionSchema = z place: z.array(actionPlaceSchema), }) .strict() - -export type Action = z.output diff --git a/packages/actions/source/types.ts b/packages/actions/source/types.ts new file mode 100644 index 0000000..2638308 --- /dev/null +++ b/packages/actions/source/types.ts @@ -0,0 +1,13 @@ +import { z } from 'zod' +import { + actionIoCurrencySchema, + actionIoItemSchema, + actionIoSchema, + actionSchema, +} from './schema' + +export type Action = z.output +export type ActionCurrency = z.output +export type ActionIo = z.output +export type ActionIoCurrency = z.output +export type ActionIoItem = z.output