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

Upgrade to TypeScript #43

Draft
wants to merge 50 commits into
base: develop
Choose a base branch
from
Draft

Upgrade to TypeScript #43

wants to merge 50 commits into from

Conversation

kennyek
Copy link
Contributor

@kennyek kennyek commented Aug 6, 2022

Upgrade to use TypeScript and modern tools.

  • Rewrite in TypeScript with class based syntax
  • Replace Mocha+Should+Istanbul with Jest for testing
  • Replace jscs & jshint with eslint & prettier
  • Use SWC for transpilation and running the unit tests
  • Upgraded dependencies and removed dependencies no longer needed
  • Add documentation to the README

Remaining Work

  • Look through all the types. Some of them are naive and need to be updated with proper values.
  • See if tests should be updated. A lot has been typed with general types such as Record<string, any> to silence the warnings.
  • Must be tested thoroughly with different stores.

Identified Issues

  • Tests for the Observer fail in the HybridCursor in the remote persistent store.
  • Test for the Observer fail in the MongoDB peristence store. However, they failed when I run them without the bump. Now, it seems like an observer keeps reconnecting.

Pretty format using prettier
Replace node-uuid with uuid

Upgrade lodash to exact version. Upgrading to newer version breaks tests for timestamp plugin. Seems like changes have been made to cloneDeep causing this.
Move source code from lib to src. lib will be git ignored in next commit.

Replace root index.js with specified main in package.json
Organize methods as public before privates, alphabetically

Replace var with const/let

Replace this binding with class properties

Insert new lines around selections for readability
Organize methods as public before privates, alphabetically

Replace var with const/let

Insert new lines around selections for readability
Replace var with const/let

Insert new lines around selections for readability

Since no logic needed to be inside of the class, smaller functions were extracted for cleaner code.
Replace var with const/let

Insert new lines around selections for readability

Since no logic needed to be inside of the class, smaller functions were extracted for cleaner code.

Refactored duplicated code for save/insert to own function.
Extract mergeOptions so that it won't have to be recreated on each refresh.
Replace bluebird Promise with native Promise.

Add Babel plugin transform-runtime to support async await.
Add interface for Store and Collection.
Add change to not refresh observer if there are no results, since that would throw in the merger.
We don't use a test directory anymore.

Add "Surikat" as author of the library.
# Conflicts:
#	package-lock.json
#	package.json
Export more interfaces and classes.

Add prepare script to test and build before pack/publish.
Don't prevent init call from Observer.refresh if documents is `undefined`.

Needed for the HybridCursor. _ prefix should be removed, and the call in the HybridCursor updated.
Replace `this` with the object meant as `thisArg`.

Remove remaining global imports of Lodash with function imports.
To be more readable by extracting boilerplate to test hooks.

To not default to empty arrays as results. Would be misleading if they were `undefined`.

Nest callbacks properly to avoid flaky tests.

Remove unnecessary timeouts.
Can use either the callback form as before or wait for the Promise to resolve.

Update test cases to use Promise syntax to add brevity.
Can use either the callback form as before or wait for the Promise to resolve.

Update test cases to use Promise syntax to increase brevity.
insert, save & remove will return a Promise if a callback is not provided.

remove will now return a "RemoveResult" object.

Change in drop API. To reflect the MongoDB API, drop no longer takes any arguments, and will return a boolean indicating that te drop was successful.
Update API for createIndex, ensureIndex & findAndModify, even though they are unsupported in the InMemoryCollection, since the custom stores should implement that API.

Add more API documentation to README.
@kennyek
Copy link
Contributor Author

kennyek commented Aug 10, 2022

The current API update of the ViewDB interfaces are that the methods (e.g. Cursor.toArray) returns a Promise IF no callback is provided. If a callback is provided, the methods return void and the values are passed in the callback instead.

This was to follow the MongoDB API as a standard, and to prevent cases of e.g. unhandled rejections of promises if only the callback version is used.

I did get the suggestion to always return a Promise, regardless of whether a callback is provided or not. I'm however concerned about the beforementioned unhandled rejection case. Any thoughts? 🙂

@tbruun @heartmon @spralle

kennyek and others added 4 commits August 14, 2022 13:14
Since `IndexedDBStore` will implement `Store` and `IndexedDBCollection` will implement `Collection` from `viewdb`
# Conflicts:
#	package-lock.json
#	package.json
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.

None yet

1 participant