-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: converted src/APIs to TS #677
Open
shaikahmadnawaz
wants to merge
5
commits into
nkowaokwu:master
Choose a base branch
from
shaikahmadnawaz:api/js-ts
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
585d1ea
feat: converted src/APIs to TS
shaikahmadnawaz 4b43f95
Merge branch 'master' into api/js-ts
ijemmao 2cda28b
feat: fixed type mismatch
shaikahmadnawaz cb9a654
Merge branch 'api/js-ts' of https://github.com/shaikahmadnawaz/igbo_a…
shaikahmadnawaz 3e4bafa
Update RedisAPI.ts
shaikahmadnawaz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import compact from 'lodash/compact'; | ||
import assign from 'lodash/assign'; | ||
import omit from 'lodash/omit'; | ||
|
||
interface Word { | ||
id?: string; | ||
stems?: Array<string | { id?: string }>; | ||
relatedTerms?: Array<string | { id?: string }>; | ||
examples?: any; // Update the type of `examples` accordingly | ||
dialects?: any; // Update the type of `dialects` accordingly | ||
} | ||
|
||
interface Data { | ||
words: Word[]; | ||
contentLength: number; | ||
} | ||
|
||
interface Flags { | ||
examples?: boolean; | ||
dialects?: boolean; | ||
resolve?: boolean; | ||
} | ||
|
||
interface HandleWordFlagsParams { | ||
data: Data; | ||
flags: Flags; | ||
} | ||
|
||
export const handleWordFlags = ({ | ||
data: { words, contentLength }, | ||
flags: { examples, dialects, resolve }, | ||
}: HandleWordFlagsParams) => { | ||
const updatedWords = compact( | ||
words.map((word) => { | ||
let updatedWord = assign({}, word); | ||
if (!examples) { | ||
updatedWord = omit(updatedWord, ['examples']); | ||
} | ||
if (!dialects) { | ||
updatedWord = omit(updatedWord, ['dialects']); | ||
} | ||
if (!resolve) { | ||
if (updatedWord.stems) { | ||
updatedWord.stems = updatedWord.stems.map((stem) => (typeof stem === 'string' ? stem : stem.id)); | ||
} | ||
if (updatedWord.relatedTerms) { | ||
updatedWord.relatedTerms = updatedWord.relatedTerms.map((relatedTerm) => | ||
typeof relatedTerm === 'string' ? relatedTerm : relatedTerm.id | ||
); | ||
} | ||
} | ||
return updatedWord; | ||
}) | ||
); | ||
return { words: updatedWords, contentLength }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,12 @@ import assign from 'lodash/assign'; | |
import { REDIS_CACHE_EXPIRATION } from '../config'; | ||
import minimizeWords from '../controllers/utils/minimizeWords'; | ||
|
||
export const getCachedWords = async ({ key, redisClient }) => { | ||
interface GetCachedWordsParams { | ||
key: string; | ||
redisClient: RedisClient; | ||
} | ||
|
||
export const getCachedWords = async ({ key, redisClient }: GetCachedWordsParams) => { | ||
console.time('Getting cached words'); | ||
const rawCachedWords = await redisClient.get(key); | ||
const cachedWords = typeof rawCachedWords === 'string' ? JSON.parse(rawCachedWords) : rawCachedWords; | ||
|
@@ -11,49 +16,75 @@ export const getCachedWords = async ({ key, redisClient }) => { | |
return cachedWords; | ||
}; | ||
|
||
export const setCachedWords = async ({ | ||
key, | ||
data, | ||
redisClient, | ||
version, | ||
}) => { | ||
const updatedData = assign(data); | ||
interface SetCachedWordsParams { | ||
key: string; | ||
data: any; // Update the type of `data` accordingly | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or better still use the |
||
redisClient: RedisClient; | ||
version: string; // Update the type of `version` accordingly | ||
} | ||
|
||
export const setCachedWords = async ({ key, data, redisClient, version }: SetCachedWordsParams) => { | ||
const updatedData = assign({}, data); | ||
updatedData.words = minimizeWords(data.words, version); | ||
if (!redisClient.isFake) { | ||
await redisClient.set(key, JSON.stringify(updatedData), { EX: REDIS_CACHE_EXPIRATION }); | ||
} | ||
return updatedData; | ||
}; | ||
shaikahmadnawaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
export const getCachedExamples = async ({ key, redisClient }) => { | ||
interface GetCachedExamplesParams { | ||
key: string; | ||
redisClient: RedisClient; | ||
} | ||
|
||
export const getCachedExamples = async ({ key, redisClient }: GetCachedExamplesParams) => { | ||
const rawCachedExamples = await redisClient.get(key); | ||
const cachedExamples = typeof rawCachedExamples === 'string' ? JSON.parse(rawCachedExamples) : rawCachedExamples; | ||
console.log(`Retrieved cached data for examples ${key}:`, !!cachedExamples); | ||
return cachedExamples; | ||
}; | ||
|
||
export const setCachedExamples = async ({ key, data, redisClient }) => { | ||
interface SetCachedExamplesParams { | ||
key: string; | ||
data: any; // Update the type of `data` accordingly | ||
redisClient: RedisClient; | ||
} | ||
|
||
export const setCachedExamples = async ({ key, data, redisClient }: SetCachedExamplesParams) => { | ||
if (!redisClient.isFake) { | ||
await redisClient.set(key, JSON.stringify(data), { EX: REDIS_CACHE_EXPIRATION }); | ||
} | ||
return data; | ||
}; | ||
shaikahmadnawaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
export const getAllCachedVerbsAndSuffixes = async ({ key, redisClient }) => { | ||
interface GetAllCachedVerbsAndSuffixesParams { | ||
key: string; | ||
redisClient: RedisClient; | ||
} | ||
|
||
export const getAllCachedVerbsAndSuffixes = async ({ key, redisClient }: GetAllCachedVerbsAndSuffixesParams) => { | ||
const redisAllVerbsAndSuffixesKey = `verbs-and-suffixes-${key}`; | ||
const rawCachedAllVerbsAndSuffixes = await redisClient.get(redisAllVerbsAndSuffixesKey); | ||
const cachedAllVerbsAndSuffixes = typeof rawCachedAllVerbsAndSuffixes === 'string' | ||
? JSON.parse(rawCachedAllVerbsAndSuffixes) | ||
: rawCachedAllVerbsAndSuffixes; | ||
const cachedAllVerbsAndSuffixes = | ||
typeof rawCachedAllVerbsAndSuffixes === 'string' | ||
? JSON.parse(rawCachedAllVerbsAndSuffixes) | ||
: rawCachedAllVerbsAndSuffixes; | ||
return cachedAllVerbsAndSuffixes; | ||
}; | ||
shaikahmadnawaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
interface SetAllCachedVerbsAndSuffixesParams { | ||
key: string; | ||
data: any; // Update the type of `data` accordingly | ||
redisClient: RedisClient; | ||
version: string; // Update the type of `version` accordingly | ||
} | ||
|
||
export const setAllCachedVerbsAndSuffixes = async ({ | ||
key, | ||
data, | ||
redisClient, | ||
version, | ||
}) => { | ||
}: SetAllCachedVerbsAndSuffixesParams) => { | ||
const redisAllVerbsAndSuffixesKey = `verbs-and-suffixes-${key}`; | ||
const updatedData = minimizeWords(data, version); | ||
if (!redisClient.isFake) { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason why the Loadash is used instead of the native
Object.assign
method?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nope, just a decision that was made in the past!