-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
adding types #15
Open
AntanasGa
wants to merge
7
commits into
instafluff:master
Choose a base branch
from
AntanasGa:ts-rewrite
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
adding types #15
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
cb1296b
adding types
c9fd3b1
cleanup
5f97477
reordering and cleanup
3794433
updating `package.json`
6f8c17d
updating test case
bf32dde
updating `example.js` and ts requirements
997a871
excluding files from built version
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 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 |
---|---|---|
|
@@ -60,4 +60,6 @@ typings/ | |
# next.js build output | ||
.next | ||
|
||
lib/ | ||
|
||
data/ |
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,3 @@ | ||
index.test.js | ||
tsconfig.json | ||
src/ |
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
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 | ||
---|---|---|---|---|
@@ -1,4 +1,5 @@ | ||||
const ComfyDB = require( "./index" ); | ||||
//@ts-check | ||||
const ComfyDB = require( "./lib/index" ); | ||||
|
||||
test( "connects to MongoDB", async () => { | ||||
await ComfyDB.Connect(); | ||||
|
@@ -11,7 +12,7 @@ test( "gets undefined for non-existent values", async () => { | |||
|
||||
test( "saves and gets values", async () => { | ||||
await ComfyDB.Store( "test", { name: "Instafluff" } ); | ||||
expect( ( await ComfyDB.Get( "test" ) ).name ).toBe( "Instafluff" ); | ||||
expect( ( await ComfyDB.Get( "test" ) )?.name ).toBe( "Instafluff" ); | ||||
}); | ||||
|
||||
test( "deletes value", async () => { | ||||
|
@@ -21,17 +22,17 @@ test( "deletes value", async () => { | |||
|
||||
test( "sets _id", async () => { | ||||
await ComfyDB.Store( "identifier", { name: "Instafluff" } ); | ||||
expect( ( await ComfyDB.Get( "identifier" ) )._id ).toBeDefined(); | ||||
expect( ( await ComfyDB.Get( "identifier" ) )?._id ).toBeDefined(); | ||||
}); | ||||
|
||||
test( "adds createdAt", async () => { | ||||
await ComfyDB.Store( "created", { name: "Instafluff" } ); | ||||
expect( ( await ComfyDB.Get( "created" ) ).createdAt ).toBeDefined(); | ||||
expect( ( await ComfyDB.Get( "created" ) )?.createdAt ).toBeDefined(); | ||||
}); | ||||
|
||||
test( "adds updatedAt", async () => { | ||||
await ComfyDB.Store( "updated", { name: "Instafluff" } ); | ||||
expect( ( await ComfyDB.Get( "updated" ) ).updatedAt ).toBeDefined(); | ||||
expect( ( await ComfyDB.Get( "updated" ) )?.updatedAt ).toBeDefined(); | ||||
}); | ||||
|
||||
test( "search returns all results", async () => { | ||||
|
@@ -40,7 +41,7 @@ test( "search returns all results", async () => { | |||
} | ||||
let results = await ComfyDB.Search(); | ||||
for( let i = 0; i < 5; i++ ) { | ||||
expect( ( await ComfyDB.Get( `test${i}` ) ).value ).toBe( `test${i}` ); | ||||
expect( ( await ComfyDB.Get( `test${i}` ) )?.value ).toBe( `test${i}` ); | ||||
} | ||||
}); | ||||
|
||||
|
@@ -110,15 +111,22 @@ test( "count is accurate", async () => { | |||
expect( result ).toBe( 10 ); | ||||
}); | ||||
|
||||
/** | ||||
* @typedef TestValue | ||||
* @property {string} key | ||||
* @property {number} value | ||||
*/ | ||||
|
||||
Comment on lines
+114
to
+119
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. not sure if this is the best option, but its the one i found for jsdoc, it comes along with: Line 129 in 997a871
|
||||
test( "increment adds amount", async () => { | ||||
for( let i = 0; i < 10; i++ ) { | ||||
await ComfyDB.Store( `skipincrement${i}`, { value: 5 } ); | ||||
} | ||||
for( let i = 0; i < 5; i++ ) { | ||||
await ComfyDB.Store( `increment${i}`, { value: 5 } ); | ||||
} | ||||
await ComfyDB.Increment( "value", { by: 5, where: { key: { startsWith: "increment" } } } ); | ||||
let results = await ComfyDB.Search( { where: { key: { contains: "increment" } } } ); | ||||
await ComfyDB.Increment( "value", { where: { key: { startsWith: "increment" } }, by: 5, } ); | ||||
|
||||
let results = /** @type {TestValue[]} */ ( await ComfyDB.Search( { where: { key: { contains: "increment" } } } ) ); | ||||
expect( results.length ).toBe( 15 ); | ||||
for( let i = 0; i < 15; i++ ) { | ||||
if( results[ i ].key.startsWith( "skip" ) ) { | ||||
|
@@ -138,7 +146,7 @@ test( "decrement subtracts amount", async () => { | |||
await ComfyDB.Store( `decrement${i}`, { value: 5 } ); | ||||
} | ||||
await ComfyDB.Decrement( "value", { by: 5, where: { key: { startsWith: "decrement" } } } ); | ||||
let results = await ComfyDB.Search( { where: { key: { contains: "decrement" } } } ); | ||||
let results = /** @type {TestValue[]} */ ( await ComfyDB.Search({ where: { key: { contains: "decrement" } } } )); | ||||
expect( results.length ).toBe( 15 ); | ||||
for( let i = 0; i < 15; i++ ) { | ||||
if( results[ i ].key.startsWith( "skip" ) ) { | ||||
|
@@ -163,7 +171,7 @@ beforeAll( () => { | |||
}); | ||||
ComfyMongo.on( "ready", async () => { | ||||
console.log( "[ComfyDB] Ready..." ); | ||||
resolve(); | ||||
resolve(void 0); | ||||
}); | ||||
ComfyMongo.on( "exit", ( code ) => { | ||||
console.log( "[ComfyDB] Exit:", code ); | ||||
|
Oops, something went wrong.
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.
depending on how it's deployed this might have to be removed