Repository navigation
fix(api): type the documented verse, word and translation fields - #111
Open
marouanebatrone wants to merge 1 commit into
Open
marouanebatrone wants to merge 1 commit into
marouanebatrone wants to merge 1 commit into
Conversation
The field selection unions were missing names that the API's field
reference documents, so typed calls could not request them without a
cast. `wordFields: { textIndopakNastaleeq: true }`, which the spec gives
as the way to get IndoPak Nastaleeq word text, failed with TS2353. The
response types did not declare what those fields return either.
`TranslationField` also offered `rubNumber`, which is sent as
`rub_number`. The API does not know that field and returns the number
as `rub_el_hizb_number`, so `Translation.rubNumber` was never set.
- add the missing `VerseField`, `WordField` and `TranslationField` names
- declare the matching optional properties on `Verse`, `Word` and
`Translation`
- keep `rubNumber` for compatibility, noted as unknown to the API, and
deprecate `Translation.rubNumber` in favor of `rubElHizbNumber`
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
The verse field-selection types are missing names that the field reference documents, so typed calls can't request them without a cast:
The word schema in
openAPI/content/v4.jsonsays to request IndoPak Nastaleeq word text withword_fields=text_indopak_nastaleeq, and it deprecatestextIndopakin its favor. The response types don't declare what these fields return either, soverse.words?.[0]?.textIndopakNastaleeqdoesn't compile.TranslationFieldalso offers"rubNumber", which is sent astranslation_fields=rub_number. The API doesn't define that field: it returns the number asrub_el_hizb_number, soTranslation.rubNumberis never set. Meanwhile TypeScript rejects the correct name,rubElHizbNumber, with "Did you mean 'hizbNumber'?".These names from the field reference are missing:
VerseFieldtextQpcHafs,textQpcNastaleeqHafs,textQpcNastaleeq,pageNumberWordFieldtextIndopakNastaleeq,textUthmaniTajweed,textQpcHafs,textImlaeiSimple,textUthmaniSimple,verseId,chapterId,lineNumber,lineV1,lineV2TranslationFieldrubElHizbNumber,rukuNumber,manzilNumber,idI left out the deprecated
qpc_uthmani_hafsalias.Change
VerseField,WordFieldandTranslationField, and each is sent under its documented wire name.Verse:textQpcHafs,textQpcNastaleeqHafs,textQpcNastaleeq.Word:textIndopakNastaleeq(string | null, as in the spec),textUthmaniTajweed,textQpcHafs,textImlaeiSimple,textUthmaniSimple,verseId,chapterId,v1Page,v2Page,lineV1,lineV2.Translation:rubElHizbNumber,rukuNumber,manzilNumber."rubNumber"stays inTranslationFieldso existing code still compiles, with a comment that the API doesn't know it.Translation.rubNumberis marked@deprecatedin favor ofrubElHizbNumber.Tests
A new test in
test/verse-fields.test.tsrequests every added field throughclient.verses.findByKey()and checks two things:fields=page_number,text_qpc_hafs,…,word_fields=chapter_id,line_number,line_v1,line_v2,text_imlaei_simple,text_indopak_nastaleeq,…andtranslation_fields=id,manzil_number,rub_el_hizb_number,ruku_number.On
main,pnpm typecheckreports 16 errors in this test: TS2353 on the field maps, and TS2339 or TS2551 on the response properties. With the change it passes.The public v4 endpoint also returns these documented fields:
text_qpc_hafsandtext_qpc_nastaleeq(_hafs);verse_id,chapter_id,text_uthmani_tajweed,text_qpc_hafs,line_v1andline_v2;rub_el_hizb_number.Checks run locally on current
main(Node 26.8.1, pnpm 9.15.4)pnpm test(vitest, build and package smoke test): 30 files, 357 tests passed.pnpm lint --quiet,pnpm typecheckandpnpm build --filter=./packages/*: passed.pnpm --filter @quranjs/api size: unchanged.