mirror of
https://github.com/zkitter/groups.git
synced 2026-01-09 13:08:01 -05:00
feat: define serverless functions (#10)
This commit is contained in:
13
functions/get-gh-group.ts
Normal file
13
functions/get-gh-group.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import 'cross-fetch/polyfill'
|
||||
import { Request, Response } from 'express'
|
||||
|
||||
import { getGhGroup } from '../src'
|
||||
|
||||
export default async (_: Request, res: Response) => {
|
||||
try {
|
||||
const group = await getGhGroup()
|
||||
res.status(200).json(group)
|
||||
} catch (err) {
|
||||
res.status(500).json(err)
|
||||
}
|
||||
}
|
||||
13
functions/get-gh-orgs.ts
Normal file
13
functions/get-gh-orgs.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import 'cross-fetch/polyfill'
|
||||
import { Request, Response } from 'express'
|
||||
|
||||
import { getGhOrgs } from '../src/get-gh-orgs'
|
||||
|
||||
export default async (_: Request, res: Response) => {
|
||||
try {
|
||||
const orgs = await getGhOrgs()
|
||||
res.status(200).json(orgs)
|
||||
} catch (err) {
|
||||
res.status(500).json(err)
|
||||
}
|
||||
}
|
||||
13
functions/get-gh-spaces.ts
Normal file
13
functions/get-gh-spaces.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import 'cross-fetch/polyfill'
|
||||
import { Request, Response } from 'express'
|
||||
|
||||
import { get100TopDaosWithMin10kFollowers } from '../src/get-spaces'
|
||||
|
||||
export default async (_: Request, res: Response) => {
|
||||
try {
|
||||
const spaces = await get100TopDaosWithMin10kFollowers()
|
||||
res.json(spaces)
|
||||
} catch (err) {
|
||||
res.status(500).json(err)
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@
|
||||
"devDependencies": {
|
||||
"@r1oga/eslint-config": "^1.1.6",
|
||||
"@r1oga/prettier-config": "^1.1.8",
|
||||
"@types/express": "^4.17.15",
|
||||
"@types/jest": "^29.2.3",
|
||||
"@types/node": "^18.11.18",
|
||||
"@types/yargs": "^17.0.19",
|
||||
@@ -48,5 +49,8 @@
|
||||
},
|
||||
"jest-runner-tsc": {
|
||||
"tsconfigPath": "./tsconfig.json"
|
||||
},
|
||||
"dependencies": {
|
||||
"cross-fetch": "^3.1.5"
|
||||
}
|
||||
}
|
||||
|
||||
90
pnpm-lock.yaml
generated
90
pnpm-lock.yaml
generated
@@ -3,10 +3,12 @@ lockfileVersion: 5.4
|
||||
specifiers:
|
||||
'@r1oga/eslint-config': ^1.1.6
|
||||
'@r1oga/prettier-config': ^1.1.8
|
||||
'@types/express': ^4.17.15
|
||||
'@types/jest': ^29.2.3
|
||||
'@types/node': ^18.11.18
|
||||
'@types/yargs': ^17.0.19
|
||||
concurrently: ^7.6.0
|
||||
cross-fetch: ^3.1.5
|
||||
husky: ^8.0.2
|
||||
is-ci: ^3.0.1
|
||||
jest: ^29.3.1
|
||||
@@ -28,9 +30,13 @@ specifiers:
|
||||
typescript: ^4.9.4
|
||||
yargs: ^17.6.2
|
||||
|
||||
dependencies:
|
||||
cross-fetch: 3.1.5
|
||||
|
||||
devDependencies:
|
||||
'@r1oga/eslint-config': 1.1.6_bh7fyjwf3qvjuxqkkpsm2qjvfa
|
||||
'@r1oga/prettier-config': 1.1.8_prettier@2.8.1
|
||||
'@types/express': 4.17.15
|
||||
'@types/jest': 29.2.3
|
||||
'@types/node': 18.11.18
|
||||
'@types/yargs': 17.0.19
|
||||
@@ -951,6 +957,36 @@ packages:
|
||||
'@babel/types': 7.20.2
|
||||
dev: true
|
||||
|
||||
/@types/body-parser/1.19.2:
|
||||
resolution: {integrity: sha512-ALYone6pm6QmwZoAgeyNksccT9Q4AWZQ6PvfwR37GT6r6FWUPguq6sUmNGSMV2Wr761oQoBxwGGa6DR5o1DC9g==}
|
||||
dependencies:
|
||||
'@types/connect': 3.4.35
|
||||
'@types/node': 18.11.18
|
||||
dev: true
|
||||
|
||||
/@types/connect/3.4.35:
|
||||
resolution: {integrity: sha512-cdeYyv4KWoEgpBISTxWvqYsVy444DOqehiF3fM3ne10AmJ62RSyNkUnxMJXHQWRQQX2eR94m5y1IZyDwBjV9FQ==}
|
||||
dependencies:
|
||||
'@types/node': 18.11.18
|
||||
dev: true
|
||||
|
||||
/@types/express-serve-static-core/4.17.32:
|
||||
resolution: {integrity: sha512-aI5h/VOkxOF2Z1saPy0Zsxs5avets/iaiAJYznQFm5By/pamU31xWKL//epiF4OfUA2qTOc9PV6tCUjhO8wlZA==}
|
||||
dependencies:
|
||||
'@types/node': 18.11.18
|
||||
'@types/qs': 6.9.7
|
||||
'@types/range-parser': 1.2.4
|
||||
dev: true
|
||||
|
||||
/@types/express/4.17.15:
|
||||
resolution: {integrity: sha512-Yv0k4bXGOH+8a+7bELd2PqHQsuiANB+A8a4gnQrkRWzrkKlb6KHaVvyXhqs04sVW/OWlbPyYxRgYlIXLfrufMQ==}
|
||||
dependencies:
|
||||
'@types/body-parser': 1.19.2
|
||||
'@types/express-serve-static-core': 4.17.32
|
||||
'@types/qs': 6.9.7
|
||||
'@types/serve-static': 1.15.0
|
||||
dev: true
|
||||
|
||||
/@types/graceful-fs/4.1.5:
|
||||
resolution: {integrity: sha512-anKkLmZZ+xm4p8JWBf4hElkM4XR+EZeA2M9BAkkTldmcyDY4mbdIJnRghDJH3Ov5ooY7/UAoENtmdMSkaAd7Cw==}
|
||||
dependencies:
|
||||
@@ -994,6 +1030,10 @@ packages:
|
||||
resolution: {integrity: sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==}
|
||||
dev: true
|
||||
|
||||
/@types/mime/3.0.1:
|
||||
resolution: {integrity: sha512-Y4XFY5VJAuw0FgAqPNd6NNoV44jbq9Bz2L7Rh/J6jLTiHBSBJa9fxqQIvkIld4GsoDOcCbvzOUAbLPsSKKg+uA==}
|
||||
dev: true
|
||||
|
||||
/@types/node/18.11.18:
|
||||
resolution: {integrity: sha512-DHQpWGjyQKSHj3ebjFI/wRKcqQcdR+MoFBygntYOZytCqNfkd2ZC4ARDJ2DQqhjH5p85Nnd3jhUJIXrszFX/JA==}
|
||||
dev: true
|
||||
@@ -1006,10 +1046,25 @@ packages:
|
||||
resolution: {integrity: sha512-ri0UmynRRvZiiUJdiz38MmIblKK+oH30MztdBVR95dv/Ubw6neWSb8u1XpRb72L4qsZOhz+L+z9JD40SJmfWow==}
|
||||
dev: true
|
||||
|
||||
/@types/qs/6.9.7:
|
||||
resolution: {integrity: sha512-FGa1F62FT09qcrueBA6qYTrJPVDzah9a+493+o2PCXsesWHIn27G98TsSMs3WPNbZIEj4+VJf6saSFpvD+3Zsw==}
|
||||
dev: true
|
||||
|
||||
/@types/range-parser/1.2.4:
|
||||
resolution: {integrity: sha512-EEhsLsD6UsDM1yFhAvy0Cjr6VwmpMWqFBCb9w07wVugF7w9nfajxLuVmngTIpgS6svCnm6Vaw+MZhoDCKnOfsw==}
|
||||
dev: true
|
||||
|
||||
/@types/semver/7.3.13:
|
||||
resolution: {integrity: sha512-21cFJr9z3g5dW8B0CVI9g2O9beqaThGQ6ZFBqHfwhzLDKUxaqTIy3vnfah/UPkfOiF2pLq+tGz+W8RyCskuslw==}
|
||||
dev: true
|
||||
|
||||
/@types/serve-static/1.15.0:
|
||||
resolution: {integrity: sha512-z5xyF6uh8CbjAu9760KDKsH2FcDxZ2tFCsA4HIMWE6IkiYMXfVoa+4f9KX+FN0ZLsaMw1WNG2ETLA6N+/YA+cg==}
|
||||
dependencies:
|
||||
'@types/mime': 3.0.1
|
||||
'@types/node': 18.11.18
|
||||
dev: true
|
||||
|
||||
/@types/stack-utils/2.0.1:
|
||||
resolution: {integrity: sha512-Hl219/BT5fLAaz6NDkSuhzasy49dwQS/DSdu4MdggFB8zcXv7vflBI3xp7FEmkmdDkBUI2bPUNeMttp2knYdxw==}
|
||||
dev: true
|
||||
@@ -1813,6 +1868,14 @@ packages:
|
||||
resolution: {integrity: sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==}
|
||||
dev: true
|
||||
|
||||
/cross-fetch/3.1.5:
|
||||
resolution: {integrity: sha512-lvb1SBsI0Z7GDwmuid+mU3kWVBwTVUbe7S0H52yaaAdQOXq2YktTCZdlAcNKFzE6QtRz0snpw9bNiPeOIkkQvw==}
|
||||
dependencies:
|
||||
node-fetch: 2.6.7
|
||||
transitivePeerDependencies:
|
||||
- encoding
|
||||
dev: false
|
||||
|
||||
/cross-spawn/7.0.3:
|
||||
resolution: {integrity: sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==}
|
||||
engines: {node: '>= 8'}
|
||||
@@ -4240,6 +4303,18 @@ packages:
|
||||
resolution: {integrity: sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==}
|
||||
dev: true
|
||||
|
||||
/node-fetch/2.6.7:
|
||||
resolution: {integrity: sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==}
|
||||
engines: {node: 4.x || >=6.0.0}
|
||||
peerDependencies:
|
||||
encoding: ^0.1.0
|
||||
peerDependenciesMeta:
|
||||
encoding:
|
||||
optional: true
|
||||
dependencies:
|
||||
whatwg-url: 5.0.0
|
||||
dev: false
|
||||
|
||||
/node-int64/0.4.0:
|
||||
resolution: {integrity: sha512-O5lz91xSOeoXP6DulyHfllpq+Eg00MWitZIbtPfoSEvqIHdl5gfcY6hYzDWnj0qD5tz52PI08u9qUvSVeUBeHw==}
|
||||
dev: true
|
||||
@@ -5078,6 +5153,10 @@ packages:
|
||||
url-parse: 1.5.10
|
||||
dev: true
|
||||
|
||||
/tr46/0.0.3:
|
||||
resolution: {integrity: sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==}
|
||||
dev: false
|
||||
|
||||
/tr46/2.1.0:
|
||||
resolution: {integrity: sha512-15Ih7phfcdP5YxqiB+iDtLoaTz4Nd35+IiAv0kQ5FNKHzXgdWqPoTIqEDDJmXceQt4JZk6lVPT8lnDlPpGDppw==}
|
||||
engines: {node: '>=8'}
|
||||
@@ -5353,6 +5432,10 @@ packages:
|
||||
makeerror: 1.0.12
|
||||
dev: true
|
||||
|
||||
/webidl-conversions/3.0.1:
|
||||
resolution: {integrity: sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==}
|
||||
dev: false
|
||||
|
||||
/webidl-conversions/5.0.0:
|
||||
resolution: {integrity: sha512-VlZwKPCkYKxQgeSbH5EyngOmRp7Ww7I9rQLERETtf5ofd9pGeswWiOtogpEO850jziPRarreGxn5QIiTqpb2wA==}
|
||||
engines: {node: '>=8'}
|
||||
@@ -5373,6 +5456,13 @@ packages:
|
||||
resolution: {integrity: sha512-M4yMwr6mAnQz76TbJm914+gPpB/nCwvZbJU28cUD6dR004SAxDLOOSUaB1JDRqLtaOV/vi0IC5lEAGFgrjGv/g==}
|
||||
dev: true
|
||||
|
||||
/whatwg-url/5.0.0:
|
||||
resolution: {integrity: sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==}
|
||||
dependencies:
|
||||
tr46: 0.0.3
|
||||
webidl-conversions: 3.0.1
|
||||
dev: false
|
||||
|
||||
/whatwg-url/8.7.0:
|
||||
resolution: {integrity: sha512-gAojqb/m9Q8a5IV96E3fHJM70AzCkgt4uXYX2O7EmuyOnLrViCQlsEBmF9UQIu3/aeAIp2U17rtbpZWNntQqdg==}
|
||||
engines: {node: '>=10'}
|
||||
|
||||
@@ -16,24 +16,24 @@ export const getSpaces =
|
||||
minFollowers: 10_000,
|
||||
},
|
||||
) =>
|
||||
async () =>
|
||||
fetch(URLS.SNAPSHOT_EXPLORE).then(async (res) =>
|
||||
res.json().then((res) =>
|
||||
Object.entries(res.spaces as Space[])
|
||||
.reduce<Array<{ id: string; followers: number }>>(
|
||||
(spaces, [id, space]) => {
|
||||
if (filterSpaces(minFollowers)(space)) {
|
||||
// @ts-expect-error - filterSpaces already ensures that props are defined
|
||||
spaces.push({ followers: space.followers, id })
|
||||
}
|
||||
async () => {
|
||||
const res = await fetch(URLS.SNAPSHOT_EXPLORE)
|
||||
const { spaces } = await res.json()
|
||||
|
||||
return spaces
|
||||
},
|
||||
[],
|
||||
)
|
||||
.sort((a, b) => b.followers - a.followers)
|
||||
.slice(0, maxOrgs),
|
||||
),
|
||||
)
|
||||
return Object.entries(spaces as Space[])
|
||||
.reduce<Array<{ id: string; followers: number }>>(
|
||||
(spaces, [id, space]) => {
|
||||
if (filterSpaces(minFollowers)(space)) {
|
||||
// @ts-expect-error - filterSpaces already ensures that props are defined
|
||||
spaces.push({ followers: space.followers, id })
|
||||
}
|
||||
|
||||
return spaces
|
||||
},
|
||||
[],
|
||||
)
|
||||
.sort((a, b) => b.followers - a.followers)
|
||||
.slice(0, maxOrgs)
|
||||
}
|
||||
|
||||
export const get100TopDaosWithMin10kFollowers = getSpaces()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"include": ["src", "scripts", "test"],
|
||||
"include": ["src", "scripts", "test", "functions"],
|
||||
"exclude": ["test/coverage"],
|
||||
"files": ["node_modules/jest-chain/types/index.d.ts"],
|
||||
"compilerOptions": {
|
||||
|
||||
Reference in New Issue
Block a user