Skip to content

Commit

Permalink
fixed sorting to use value instead of key
Browse files Browse the repository at this point in the history
  • Loading branch information
USERSATOSHI committed Apr 15, 2024
1 parent 283e02a commit f7f5a6a
Show file tree
Hide file tree
Showing 16 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion dist/cjs/KeyValue/src/FileManager.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default class FileManager {
clear(): Promise<unknown> | undefined;
has(key: KeyValueData["key"]): Promise<unknown>;
all(query: (d: KeyValueData) => boolean, limit: number, order: "firstN" | "asc" | "desc"): Promise<unknown>;
findOne(query: (d: KeyValueData) => boolean): Promise<unknown>;
findOne(query: (d: KeyValueData) => boolean): Promise<KeyValueData | undefined>;
findMany(query: (d: KeyValueData) => boolean): Promise<unknown>;
getFirstN(query: (d: KeyValueData) => boolean, limit: number): Promise<unknown>;
removeMany(query: (d: KeyValueData) => boolean): Promise<unknown>;
Expand Down
4 changes: 2 additions & 2 deletions dist/cjs/KeyValue/src/FileManager.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/cjs/KeyValue/src/FileManager.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/cjs/KeyValue/src/Table.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default class Table extends EventEmitter {
clear(): Promise<void>;
has(key: string): Promise<unknown>;
all(query: (d: Data) => boolean, limit: number, order: "firstN" | "asc" | "desc"): Promise<unknown>;
findOne(query: (d: Data) => boolean): Promise<unknown>;
findOne(query: (d: Data) => boolean): Promise<Data | undefined>;
findMany(query: (d: Data) => boolean): Promise<unknown>;
removeMany(query: (d: Data) => boolean): Promise<unknown>;
ping(): Promise<unknown>;
Expand Down
2 changes: 1 addition & 1 deletion dist/cjs/KeyValue/src/database.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export default class KeyValue extends EventEmitter {
* })
* ```
*/
findOne(table: string, query: (value: Data) => boolean): Promise<unknown>;
findOne(table: string, query: (value: Data) => boolean): Promise<Data | undefined>;
/**
* @description find all data that matches the query
* @param table table to find
Expand Down
2 changes: 1 addition & 1 deletion dist/cjs/KeyValue/src/database.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/cjs/KeyValue/src/database.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/esm/KeyValue/src/FileManager.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default class FileManager {
clear(): Promise<unknown> | undefined;
has(key: KeyValueData["key"]): Promise<unknown>;
all(query: (d: KeyValueData) => boolean, limit: number, order: "firstN" | "asc" | "desc"): Promise<unknown>;
findOne(query: (d: KeyValueData) => boolean): Promise<unknown>;
findOne(query: (d: KeyValueData) => boolean): Promise<KeyValueData | undefined>;
findMany(query: (d: KeyValueData) => boolean): Promise<unknown>;
getFirstN(query: (d: KeyValueData) => boolean, limit: number): Promise<unknown>;
removeMany(query: (d: KeyValueData) => boolean): Promise<unknown>;
Expand Down
4 changes: 2 additions & 2 deletions dist/esm/KeyValue/src/FileManager.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/esm/KeyValue/src/FileManager.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/esm/KeyValue/src/Table.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default class Table extends EventEmitter {
clear(): Promise<void>;
has(key: string): Promise<unknown>;
all(query: (d: Data) => boolean, limit: number, order: "firstN" | "asc" | "desc"): Promise<unknown>;
findOne(query: (d: Data) => boolean): Promise<unknown>;
findOne(query: (d: Data) => boolean): Promise<Data | undefined>;
findMany(query: (d: Data) => boolean): Promise<unknown>;
removeMany(query: (d: Data) => boolean): Promise<unknown>;
ping(): Promise<unknown>;
Expand Down
2 changes: 1 addition & 1 deletion dist/esm/KeyValue/src/database.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export default class KeyValue extends EventEmitter {
* })
* ```
*/
findOne(table: string, query: (value: Data) => boolean): Promise<unknown>;
findOne(table: string, query: (value: Data) => boolean): Promise<Data | undefined>;
/**
* @description find all data that matches the query
* @param table table to find
Expand Down
2 changes: 1 addition & 1 deletion dist/esm/KeyValue/src/database.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/esm/KeyValue/src/database.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions lib/KeyValue/src/FileManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,9 @@ export default class FileManager {
}
}
if (order === "asc") {
data.sort((a, b) => a.key.localeCompare(b.key));
data.sort((a,b) => this.#table.db.options.cacheConfig.sortFunction(a,b));
} else {
data.sort((a, b) => b.key.localeCompare(a.key));
data.sort((a,b) => this.#table.db.options.cacheConfig.sortFunction(a,b)).reverse();
}
return data.slice(0, limit);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/KeyValue/src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default class KeyValue extends EventEmitter {
limit: 1000,
sorted: false,
sortFunction: (a, b) => {
return 0;
return a.value - b.value;
},
},
debug: false,
Expand Down

0 comments on commit f7f5a6a

Please sign in to comment.