From 1844a6c8f303ed449fb165b959fe9098765e3781 Mon Sep 17 00:00:00 2001 From: Ming-der Wang Date: Wed, 13 Dec 2023 00:57:45 +0800 Subject: [PATCH] v0.1.0-api/v1/chainlist --- example/bun.lockb | Bin 8885 -> 11196 bytes example/package.json | 2 +- example/src/index.ts | 1 - package.json | 2 +- src/index.ts | 6 +++--- src/items/interface/item.ts | 6 ++---- src/items/router/items.ts | 2 +- src/items/service/items.ts | 32 +++++++------------------------- 8 files changed, 15 insertions(+), 36 deletions(-) diff --git a/example/bun.lockb b/example/bun.lockb index 0ce0331d501e49030ba06d803fed58a13a90d025..1d27f46a1ec37f3134a409f281a2f6c24090a0b9 100755 GIT binary patch delta 2757 zcmcImdr*{B6ua z-U`z(EiJ`Y8Zr$agFSrArlw^zVF8Y1qG4!iiin-F`+bBs^h8+I-!=lwS(Pn{HHQsMqYBIdhAdouT=xgX)=< zbEg}bg)?!(DBI1Y&@9%;nds{*Ok|=CW)YbykujWEQE37O+~W z$+s2~OT{%X++d2?1v;8_h&{X@({xb4N+JPa1P1JD0qNr)1y3ZdAC8)RpqVD%LF3^x zgc=X9o5E|nLE{iKL!SVRGhmRqu@bS<2ltX2yCO~DPPnmfw~2Q2kAcB9;uaF90vQGq zz6>&)=lysJJLDV#DMqS!N5=$MXXz;zsdupmyi$06{+wg(G8l;6RE7!gx7S zXPpp-PaUD60`sM>-2lNnmqTKAwg*yJ~3WMoGJNr^}VzW5xH$!S4kHYrtL^Ndg_j& zbxM2PB9C;by)0pA!}0sY@-a0>dzVjcDw|PJ=oP=X+ol~Amelv_>VOlXFWY|JBKgpI zO*vV6zVWRw>kjL4OQHg#M>ePWhvZI%&?)Kj>4SK&e!>t3y_4rYyJ7#x*|$5&Gs67B ztLrzHwj6yo{`gvQHQXLmnr8aQZY#NEcjT+(jme`+){eh>D68+%_pLWH7v4U$X(bj$ zFbua&{}BKFUB#Xwa~d~onWVgZxzp>Lp>kPwWkb0`72mqlO;gx(;--Vs{CxBe%e1ML z?d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nTK&px>eW z@iQXK#4cni>Q<$|HGP4B-GLUNL+B9(gb~5+S^>*?-Fh?5QV=C;3FlQQqjF(OL@Q)?Do) nJX!Xmx$MlJrM{#eN_Off1}m&uZ_ymMlw}D#OH1YlCvEf>G$QIm diff --git a/example/package.json b/example/package.json index 633de7b..bef8b2f 100644 --- a/example/package.json +++ b/example/package.json @@ -13,6 +13,6 @@ "typescript": "^5.0.0" }, "dependencies": { - "@muzamint/erica-items-db": "^0.0.0" + "@muzamint/erica-items-db": "latest" } } diff --git a/example/src/index.ts b/example/src/index.ts index be7cce6..15a13cc 100644 --- a/example/src/index.ts +++ b/example/src/index.ts @@ -1,4 +1,3 @@ -console.log("Hello via Bun!"); import { router } from '@muzamint/erica-items-db' export default { diff --git a/package.json b/package.json index 6bb42f5..380630a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@muzamint/erica-items-db", - "version": "0.0.1", + "version": "0.1.0", "main": "dist/index.js", "types": "dist/index.d.ts", "description": "", diff --git a/src/index.ts b/src/index.ts index efdc451..4a6809e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,16 +1,16 @@ export const one = 1 export const two = 2 import { http, createPublicClient, webSocket } from 'viem' -import { mainnet } from 'viem/chains' +import * as ChainList from 'viem/chains' export * from './items' const client = createPublicClient({ - chain: mainnet, + chain: ChainList.mainnet, transport: http(), }) const webSocketClient = createPublicClient({ - chain: mainnet, + chain: ChainList.mainnet, transport: webSocket( 'wss://eth-mainnet.g.alchemy.com/v2/4iIl6mDHqX3GFrpzmfj2Soirf3MPoAcH', ), diff --git a/src/items/interface/item.ts b/src/items/interface/item.ts index 5cfda58..3a257f7 100644 --- a/src/items/interface/item.ts +++ b/src/items/interface/item.ts @@ -1,10 +1,8 @@ // src/items/item.interface.ts +import type { Chain } from 'viem/chains' export interface BaseItem { - name: string; - price: number; - description: string; - image: string; + meta: Chain; } export interface Item extends BaseItem { diff --git a/src/items/router/items.ts b/src/items/router/items.ts index da7f04b..9ca9dae 100644 --- a/src/items/router/items.ts +++ b/src/items/router/items.ts @@ -22,7 +22,7 @@ export const router = new Elysia() return new Response(error.toString()) }) .get('/ping', () => 'pong') - .group("/items", app => { + .group("api/v1/chainlist", app => { return app .get('/', async () => await ItemService.findAll() ) .post('/', async ({ body, set }) => { diff --git a/src/items/service/items.ts b/src/items/service/items.ts index 2c604f5..79f4adb 100644 --- a/src/items/service/items.ts +++ b/src/items/service/items.ts @@ -4,33 +4,15 @@ import { BaseItem, Item } from "../interface/item"; import { Items } from "../interface/items"; +import * as ChainList from 'viem/chains'; -// in memory store - -let items: Items = { - 1: { - id: 1, - name: "Burger", - price: 599, - description: "Tasty", - image: "https://cdn.auth0.com/blog/whatabyte/burger-sm.png" - }, - 2: { - id: 2, - name: "Pizza", - price: 299, - description: "Cheesy", - image: "https://cdn.auth0.com/blog/whatabyte/pizza-sm.png" - }, - 3: { - id: 3, - name: "Tea", - price: 199, - description: "Informative", - image: "https://cdn.auth0.com/blog/whatabyte/tea-sm.png" - } -}; +var chainlist = [] +var id_counter = 0; +for(var i in Object.keys(ChainList)) + chainlist.push({id: id_counter++, meta: Object.values(ChainList)[i]}); +// in memory store +let items: Items = chainlist as any[] // services export const findAll = async (): Promise => Object.values(items);