Skip to content

Commit

Permalink
v0.1.0-api/v1/chainlist
Browse files Browse the repository at this point in the history
  • Loading branch information
mingder78 committed Dec 12, 2023
1 parent 7fb7caf commit 1844a6c
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 36 deletions.
Binary file modified example/bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
"typescript": "^5.0.0"
},
"dependencies": {
"@muzamint/erica-items-db": "^0.0.0"
"@muzamint/erica-items-db": "latest"
}
}
1 change: 0 additions & 1 deletion example/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
console.log("Hello via Bun!");
import { router } from '@muzamint/erica-items-db'

export default {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": "",
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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',
),
Expand Down
6 changes: 2 additions & 4 deletions src/items/interface/item.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/items/router/items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down
32 changes: 7 additions & 25 deletions src/items/service/items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Item[]> => Object.values(items);
Expand Down

0 comments on commit 1844a6c

Please sign in to comment.