swc/crates/swc_bundler/tests/.cache/deno/fe1fb10b588091a929436de10f3fc075e55f88d4.ts
2021-11-09 20:42:49 +09:00

48 lines
1.1 KiB
TypeScript

// Loaded from https://deno.land/x/mongo@v0.20.0/src/collection/commands/find.ts
import { CommandCursor, WireProtocol } from "../../protocol/mod.ts";
import { Document, FindOptions } from "../../types.ts";
interface FindCursorContext {
dbName: string;
collectionName: string;
protocol: WireProtocol;
options: FindOptions;
filter?: Document;
}
export class FindCursor<T> extends CommandCursor<T> {
#context: FindCursorContext;
private async executor() {
const { protocol, filter, dbName, collectionName, options } = this.#context;
const { cursor } = await protocol.commandSingle(dbName, {
find: collectionName,
filter,
batchSize: 1,
noCursorTimeout: true,
...options,
});
return {
...cursor,
id: cursor.id.toString(),
};
}
constructor(context: FindCursorContext) {
super(context.protocol, () => this.executor());
this.#context = context;
}
limit(limit: number): this {
this.#context.options.limit = limit;
return this;
}
skip(skip: number): this {
this.#context.options.skip = skip;
return this;
}
}