Skip to content
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: Add lang option to DataType read operations #473

Merged
merged 46 commits into from
May 7, 2024

Conversation

gmaclennan
Copy link
Member

@gmaclennan gmaclennan commented Feb 12, 2024

Fixes #472

Depends on:

TODO:

  • Add tests once dependencies are ready

The implementation in this draft PR tries to minimize the overhead for looking up translations.

Ready for an initial review.

@gmaclennan gmaclennan self-assigned this Feb 12, 2024
@gmaclennan
Copy link
Member Author

@EvanHahn non-urgent, but it would be great to have your eyes on this this week to check this approach makes sense. A full review can maybe wait until we get the dependencies in place, but the approach here might affect how we design the translation API.

@gmaclennan gmaclennan linked an issue Feb 12, 2024 that may be closed by this pull request
Tomás Ciccola added 19 commits March 11, 2024 13:42
* start writing unit tests
* error handling for missing translation
* fix error in sql query
* fix logic error when `put`
* handle unexisting key in the indexing (by creating a new Set)
* make `fieldRef` and `regionCode` optional when `get`
* expose cache map through symbol and getter
* improve `get` signature (by making `fieldRef` and `regionCode`
  optional)
* add more unit tests
* add translationDoc to entries for batching indexer
* move decoding of translationDoc into `.index` function in
  translationApi
…ranslationApi

Also, have a fallback when no matching `regionCode` (can be reverted is
it not desired)
@tomasciccola
Copy link
Contributor

TranslationApi need dataType in its constructor, but DataType needs translationApi in its constructor. This means that we usually need to do:

let translationApi;
const dataType = new DataType({
  dataStore,
  table,
  db,
  translation: translationApi
})
translationApi = new TranslationApi({
  dataType, 
 table
})

This kinda feels weird but it seems to work. Could there be edge cases where this wouldn't work? Is there a pattern that we could have were we avoid this?
A possibility would be to have an init function in, lets say, DataType so that we pass translationApi there, after instancing it...

src/datatype/index.js Outdated Show resolved Hide resolved
@tomasciccola tomasciccola marked this pull request as ready for review May 2, 2024 15:04
@tomasciccola tomasciccola requested a review from EvanHahn May 2, 2024 15:04
Copy link
Contributor

@EvanHahn EvanHahn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add an e2e test too?

src/datatype/index.js Outdated Show resolved Hide resolved
src/datatype/index.js Outdated Show resolved Hide resolved
src/mapeo-project.js Outdated Show resolved Hide resolved
src/mapeo-project.js Outdated Show resolved Hide resolved
src/datatype/index.js Outdated Show resolved Hide resolved
tests/data-type.js Show resolved Hide resolved
src/datatype/index.js Outdated Show resolved Hide resolved
* Have better typing on `getByDocId` result
* Avoid extra translation lookup
* remove ts-ignore

Co-authored-by: Evan Hahn <me@evanhahn.com>
Tomás Ciccola and others added 7 commits May 7, 2024 11:51
`DataType` needs access to `TranslationApi.prototype.get`, but
`TranslationApi` needs access to `DataType`. To avoid this circular
reference, pass a `getTranslations` function into `DataType`.
…em/mapeo-core-next into feat/record-translations-opts-lang
@tomasciccola
Copy link
Contributor

@EvanHahn do you feel there are e2e-tests that we can add? The ones I added are pretty similar to the translationApi tests with the added layer of going through dataType.getByDocId(docId, {lang}) instead of using translationApi.get()

@tomasciccola tomasciccola requested a review from EvanHahn May 7, 2024 18:22
@EvanHahn
Copy link
Contributor

EvanHahn commented May 7, 2024

Nah, I think those are good enough!

I'll review the rest now.

Copy link
Contributor

@EvanHahn EvanHahn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Feel free to merge when CI passes.

Thanks for all the back-and-forth here.

src/mapeo-project.js Outdated Show resolved Hide resolved
test-e2e/translation-api.js Show resolved Hide resolved
@tomasciccola tomasciccola merged commit 7f8fcdd into main May 7, 2024
4 checks passed
@tomasciccola tomasciccola deleted the feat/record-translations-opts-lang branch May 7, 2024 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add lang option to DataType read operations
3 participants