8000 Added typescript generic to JBDOC in node binding by jeremyben · Pull Request #311 · Softmotions/ejdb · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Added typescript generic to JBDOC in node binding #311

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

Merged
merged 1 commit into from
Apr 17, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/bindings/ejdb2_node/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ declare namespace ejdb2_node {
/**
* EJDB document.
*/
interface JBDOC {
interface JBDOC<T extends object = { [key: string]: any }> {
/**
* Document identifier
*/
Expand All @@ -59,16 +59,16 @@ declare namespace ejdb2_node {
/**
* Document JSON object
*/
json: any;
json: T;

/**
* String represen
*/
toString(): string;
}

interface JBDOCStream {
[Symbol.asyncIterator](): AsyncIterableIterator<JBDOC>;
interface JBDOCStream<T extends object = { [key: string]: any }> {
[Symbol.asyncIterator](): AsyncIterableIterator<JBDOC<T>>;
}

/**
Expand Down Expand Up @@ -105,7 +105,7 @@ declare namespace ejdb2_node {
* readable stream of matched documents.
*
*/
stream(opts?: QueryOptions): JBDOCStream;
stream<T extends object = { [key: string]: any }>(opts?: QueryOptions): JBDOCStream<T>;

/**
* Executes this query and waits its completion.
Expand All @@ -122,18 +122,18 @@ declare namespace ejdb2_node {
* Returns result set as a list.
* Use it with caution on large data sets.
*/
list(opts?: QueryOptions): Promise<Array<JBDOC>>;
list<T extends object = { [key: string]: any }>(opts?: QueryOptions): Promise<Array<JBDOC<T>>>;

/**
* Collects up to [n] documents from result set into array.
*/
firstN(n: number, opts?: QueryOptions): Promise<Array<JBDOC>>;
firstN<T extends object = { [key: string]: any }>(n: number, opts?: QueryOptions): Promise<Array<JBDOC<T>>>;

/**
* Returns a first record in result set.
* If record is not found promise with `undefined` will be returned.
*/
first(opts?: QueryOptions): Promise<JBDOC | undefined>;
first<T extends object = { [key: string]: any }>(opts?: QueryOptions): Promise<JBDOC<T> | undefined>;

/**
* Set [json] at the specified [placeholder].
Expand Down Expand Up @@ -380,14 +380,14 @@ declare namespace ejdb2_node {
* If document with given `id` is not found then `Error` will be thrown.
* Not found error can be detected by {@link JBE.isNotFound}
*/
get(collection: string, id: number): Promise<object>;
get<T extends object = { [key: string]: any }>(collection: string, id: number): Promise<T>;

/**
* Get json body of document identified by [id] and stored in [collection].
*
* If document with given `id` is not found then `null` will be resoved.
*/
getOrNull(collection: string, id: number): Promise<object|null>;
getOrNull<T extends object = { [key: string]: any }>(collection: string, id: number): Promise<T|null>;

/**
* Get json body with database metadata.
Expand Down
0