Releases: payw-org/eodiro-server
v2.3.0
Feature
- api:
getLecturesYears
- cnw: dormitory blue mir notice now redirect to the notice page
Dev
- snippet:
oneres
auto completesoneApiResponse<Action>($0)
- script: watch One API schemes and auto-refresh on change (included in
dev
script)
Refactor
- api: tip apis are updated with the latest one api types
Fix
- lectures: now search with current year and semester - 7210a5c
- lectures: fix table attribute name - 834daf1
Chore
- deps: remove graphql, dts-gen
- seed: quit timetable seeder after finished the process - b851a35
v2.2.1
Time.getPrismaCurrent()
Returns the current time for using with Prisma.
const currentTime = Time.getPrismaCurrent()
await prisma.tip.create({
data: {
user: {
connect: {
id: userId,
},
},
title,
topic,
body,
randomNickname: randomNick,
createdAt: currentTime,
editedAt: currentTime,
},
})
⚠️ Time.getIsoString()
is deprecated
prismaTimeMod()
We assume that prisma treats the time in database as UTC time. Wrapping the result of Prisma client with this function resolves the issue by merely subtracting 9 hours from the UTC time (UTC+9:00 is KST).
First argument could be any variable which includes Date
.
v2.2.0
Features
- CAU Notice Watcher
- Tips API
- eodiro LIVE
Dev
- Expose a lot of changes to One API (types, code snippets)
- Integrate repository pattern (#55)
Contributors
- @97e57e
v2.2.0 Beta 2
New VSCode code snippets
Action Types
onetype
It replaces the previous oneint
(One Interface) snippet and constructs Action
type boilerplate.
onetypeauth
It replaces the previous oneintauth
(One Interface Auth Required) snippet and constructs Action
type boilerplate with AuthRequired
injected.
onetypeauthonly
Constructs Action
type boilerplate with AuthOnly
type injected where the API only accepts the accessToken
.
onetypeauthoptional
Constructs Action
type boilerplate with AuthOptional
type injected where the API optionally requires the authentication.
onetypenodata
Constructs Action
type boilerplate without the request data.
Function Types
onefunc
It slightly updates the previous onefunc
snippet with the new type declarations.
onefuncnodata
The resolvers(functions) for the Actions that don't require any request data.
v2.2.0 Beta 1
This version introduces some new ways to build One APIs.
Removed deprecated utility types
OneAPIData
: Replaced with using direct access to the property,T['data']
OneAPIPayload
: Replaced with using direct access to the property,T['payload']
OneAPIError<T>
: Replaced withOneApiError
combined with union types,OneApiError | 'Other Error' | ...
Removed the universal OneApiAction
type
At the beginning of its creation, we standardized the One APIs' interface and they could be expressed in the same, single interface called OneApiAction
which is an union of all the One APIs. However, the number of APIs are increasing and we found they can be differed in four different structures.
Request Data | Response Data | Response Error |
---|---|---|
✅ | ✅ | ✅ |
❌ | ✅ | ✅ |
✅ | ❌ | ✅ |
❌ | ❌ | ✅ |
For the APIs which provide no response data, the payload data is
null
.
AuthOptional
(#48)
Added this type alongside AuthRequired
and AuthOnly
. It makes the accessToken
field optional in request data and oneApiClient
can call them with or without the token. This type is suitable for the APIs that act differently in unauthorized session.
One API Templates
Now you can define actions interface with two types of One API templates.
OneApiActionTemplate<D, P>
This type accepts data and payload types.
Here is an example, suppose there is an action interface like below,
// bookmark-tip.action/interface.ts
export interface Action {
data: AuthRequired<{
tipId: number
}>
payload: {
err: OneApiError
data: {
isBookmarked: boolean
}
}
}
You can rewrite the interface with the new types
export type Action = OneApiActionTemplate<
AuthRequired<
tipId: number
>
OneApiActionTemplatePayload<
OneApiError,
{
isBookmarked: boolean
}
>
>
OneApiActionTemplateWithoutRequestData<P>
(#48)
This type accepts only the payload type.
get-notice-catalog.action
for example, doesn't require any reqeust data. Currently it is defined by filling the data with undefined
. It doesn't make sense and oneApiClient
always infers the data
as required(or optional) property.
// get-notice-catalog.action/interface.ts
export interface Action {
data: undefined
payload: {
err: OneApiError
data: {
noticeCatalog: NoticeItem[]
}
}
}
But now it can be defined in a much explicit way.
export type Action = OneApiActionTemplateWithoutRequestData<
OneApiActionTemplatePayload<
OneApiError,
{
noticeCatalog: NoticeItem[]
}
>
>
If there is no response data(payload data), pass null
to OneApiActionTemplatePayload
as the second template type.
export type Action = OneApiActionTemplateWithoutRequestData<
OneApiActionTemplatePayload<OneApiError, null>
>
In default, you should pass
OneApiError
as the first template type ofOneApiActionTemplatePayload
. Use union types if you need additional error types.
Return the response with oneApiResponse
(#49)
Previously you're returning the response inside the One API functions like this.
return {
err: OneApiError.UNAUTHORIZED,
data: {
some: 'data'
}
}
By using the oneApiResponse<Action>()
, you can return the response in a much simpler and intuitive way.
Response with only an error
return oneApiResponse<Action>(OneApiError.UNAUTHORIZED)
data
will be automatically filled withnull
Response with only the data
return oneApiResponse<Action>({
some: 'data'
})
err
will be automatically filled withnull
Response with both an error and the data
return oneApiResponse<Action>('Some Error', null)
Don't forget to pass the template type
Action
. Without doing this, type inferences will be broken.
One API function declaration
Define the One API function with one of these types.
OneApiFunc
OneApiFuncWithoutRequestData
They accept a template type that extends OneApiActionTemplate
and OneApiActionTemplateWithoutRequestData
each.
const func: OneApiFunc<Action> = async (data) => {
const response = oneApiResponse<Action>(OneApiError.UNAUTHORIZED)
return response
}
OneApiFunction
is now deprecated
oneAPIClient
is now oneApiClient
In JavaScript, variable naming convention is often using camelCase
. And we are trying to keep consistent variable names even if a name is using an abbreviation like API
. So we changed oneAPIClient
to oneApiClient
.
v2.1.0
Cron
We have multiple periodic jobs. Those are including clearing pending users, garbage collecting dangling user-uploaded files, scraping data from websites and much more. Previously these jobs were running inside the main process through so called node-cron. Unfortunately we faced the issue(#41) where the headless browsers(Zombie.js and Puppeteer) leak memories on every browser instance creation. So, from v2.1.0
, they are separated from the main process and moved to cron. This approach additionally provides few improvements as well as resolving the memory leak problem which is critical. They are now isolated and run in background even when the main server process got blocked or updating. It means that periodic jobs never halt and always achieve what they have to.