Skip to content

Commit

Permalink
fix mentioned issues
Browse files Browse the repository at this point in the history
Signed-off-by: Jersey <[email protected]>
  • Loading branch information
williamhorning committed Mar 23, 2024
1 parent 1f02481 commit 2d35550
Show file tree
Hide file tree
Showing 28 changed files with 116 additions and 60 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@
.idea/
.DS_Store
.vscode/
deno.lock
14 changes: 2 additions & 12 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,10 @@
"publish": {
"exclude": [".github", "tests", ".gitattributes", ".gitignore", "deno.lock"]
},
"imports": {
"assert": "jsr:@std/assert@^0.220.1",
"b64": "jsr:@std/encoding@^0.220.1/base64",
"bdd": "jsr:@std/testing@^0.220.1/bdd",
"bytes_eq": "jsr:@std/bytes@^0.220.1/equals",
"hex": "jsr:@std/encoding@^0.220.1/hex",
"io": "jsr:@std/io@^0.220.1",
"semver": "jsr:@std/semver@^0.220.1",
"std_crypto": "jsr:@std/crypto@^0.220.1/crypto",
"web-bson": "jsr:@lucsoft/web-bson@^0.3.1"
},
"test": {
"include": [
"tests/cases/*.ts"
]
}
},
"lock": false
}
18 changes: 18 additions & 0 deletions deps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export {
Binary,
BSONRegExp,
Decimal128,
deserialize,
Double,
Int32,
Long,
ObjectId,
serialize,
Timestamp,
UUID,
} from "jsr:@lucsoft/web-bson@^0.3.1";
export {} from "jsr:@std/bytes@^0.220.1/equals";
export { crypto as stdCrypto } from "jsr:@std/crypto@^0.220.1/crypto";
export { decodeBase64, encodeBase64 } from "jsr:@std/encoding@^0.220.1/base64";
export { encodeHex } from "jsr:@std/encoding@^0.220.1/hex";
export { BufReader, writeAll } from "jsr:@std/io@^0.220.1";
11 changes: 6 additions & 5 deletions mod.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
export { MongoClient } from "./src/client.ts";
export { Database } from "./src/database.ts";
export { Collection } from "./src/collection/mod.ts";
export * from "./src/types.ts";
export {
Binary,
BSONRegExp,
Expand All @@ -11,5 +7,10 @@ export {
Long,
ObjectId,
Timestamp,
} from "web-bson";
UUID,
} from "./deps.ts";
export { MongoClient } from "./src/client.ts";
export { Collection } from "./src/collection/mod.ts";
export { Database } from "./src/database.ts";
export { GridFSBucket } from "./src/gridfs/bucket.ts";
export * from "./src/types.ts";
2 changes: 1 addition & 1 deletion src/auth/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { WireProtocol } from "../protocol/mod.ts";
import { ConnectOptions, Credential, Document } from "../types.ts";

export abstract class AuthPlugin {
abstract prepare(authContext: AuthContext): Document;
abstract auth(authContext: AuthContext): Document;
abstract prepare(authContext: AuthContext): Document;
}

/** Context used during authentication */
Expand Down
11 changes: 7 additions & 4 deletions src/auth/scram.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { decodeBase64, encodeBase64 } from "b64";
import { encodeHex } from "hex";
import { crypto as stdCrypto } from "std_crypto";
import { Binary } from "web-bson";
import {
Binary,
decodeBase64,
encodeBase64,
encodeHex,
stdCrypto,
} from "../../deps.ts";
import { MongoDriverError } from "../error.ts";
import { HandshakeDocument } from "../protocol/handshake.ts";
import { driverMetadata } from "../protocol/mod.ts";
Expand Down
3 changes: 1 addition & 2 deletions src/collection/collection.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ObjectId } from "web-bson";
import { ObjectId } from "../../deps.ts";
import {
MongoDriverError,
MongoInvalidArgumentError,
Expand Down Expand Up @@ -382,7 +382,6 @@ export class Collection<T extends Document> {
});
}

// TODO: add docs for this
async distinct(
key: string,
query?: Filter<T>,
Expand Down
2 changes: 1 addition & 1 deletion src/collection/commands/update.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ObjectId } from "web-bson";
import { ObjectId } from "../../../deps.ts";
import { WireProtocol } from "../../protocol/mod.ts";
import { Document, UpdateOptions } from "../../types.ts";

Expand Down
2 changes: 1 addition & 1 deletion src/gridfs/bucket.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ObjectId } from "web-bson";
import { ObjectId } from "../../deps.ts";
import { Collection } from "../collection/collection.ts";
import { FindCursor } from "../collection/commands/find.ts";
import { Database } from "../database.ts";
Expand Down
2 changes: 1 addition & 1 deletion src/gridfs/upload.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Binary, ObjectId } from "web-bson";
import { Binary, ObjectId } from "../../deps.ts";
import { Collection } from "../collection/mod.ts";
import { Chunk, File, GridFSUploadOptions } from "../types/gridfs.ts";

Expand Down
2 changes: 1 addition & 1 deletion src/protocol/cursor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Long } from "web-bson";
import { Long } from "../../deps.ts";
import { Document } from "../types.ts";
import { parseNamespace } from "../utils/ns.ts";
import { WireProtocol } from "./protocol.ts";
Expand Down
2 changes: 1 addition & 1 deletion src/protocol/message.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { deserialize, serialize } from "web-bson";
import { deserialize, serialize } from "../../deps.ts";
import { Document } from "../types.ts";
import { MessageHeader, OpCode, setHeader } from "./header.ts";

Expand Down
2 changes: 1 addition & 1 deletion src/protocol/protocol.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BufReader, writeAll } from "io";
import { BufReader, writeAll } from "../../deps.ts";
import {
MongoDriverError,
MongoErrorInfo,
Expand Down
8 changes: 5 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
Long,
ObjectId,
Timestamp,
} from "web-bson";
} from "../deps.ts";
import {
$geoAny,
$geoMultiPolygon,
Expand Down Expand Up @@ -303,7 +303,6 @@ export interface DropOptions {
comment?: any;
}

// TODO: figure out what this is
export interface DistinctOptions {
/**
* The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
Expand Down Expand Up @@ -812,7 +811,10 @@ export type UpdateFilter<T> =
& UpdateOperators<T>
& Partial<T>;

// TODO: what
/**
* Aggregation pipelines are used to process many documents
* @see https://www.mongodb.com/docs/manual/core/aggregation-pipeline/
*/
export type AggregatePipeline<T> =
& NotImplementedOperators<AggregateOperators>
& Document
Expand Down
2 changes: 1 addition & 1 deletion src/types/gridfs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Binary, ObjectId } from "web-bson";
import { Binary, ObjectId } from "../../deps.ts";
import { Document, ReadPreference } from "../types.ts";
import { ReadConcern, WriteConcern } from "../types/read_write_concern.ts";

Expand Down
2 changes: 1 addition & 1 deletion src/utils/saslprep/load_code_points.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { decodeBase64 } from "b64";
import { decodeBase64 } from "../../../deps.ts";
import { Bitfield } from "./sparse_bitfield.ts";

/** Reads an uint32 from the specified buffer offset. */
Expand Down
3 changes: 1 addition & 2 deletions tests/cases/00_uri.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { assertEquals } from "assert";
import { describe, it } from "bdd";
import { parse, parseSrvUrl } from "../../src/utils/uri.ts";
import { assertEquals, describe, it } from "../deps.ts";

describe("uri", () => {
it({
Expand Down
10 changes: 8 additions & 2 deletions tests/cases/01_auth.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { assert, assertEquals } from "assert";
import { afterAll, beforeAll, describe, it } from "bdd";
import { Database } from "../../mod.ts";
import {
cleanUsername,
Expand All @@ -9,6 +7,14 @@ import {
} from "../../src/auth/mod.ts";
import { MongoClient } from "../../src/client.ts";
import { cleanTestDb, getTestDb } from "../common.ts";
import {
afterAll,
assert,
assertEquals,
beforeAll,
describe,
it,
} from "../deps.ts";

describe("auth", () => {
describe("prerequisites", () => {
Expand Down
10 changes: 8 additions & 2 deletions tests/cases/02_connect.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { assert, assertEquals } from "assert";
import { afterEach, beforeEach, describe, it } from "bdd";
import { MongoClient } from "../../src/client.ts";
import {
afterEach,
assert,
assertEquals,
beforeEach,
describe,
it,
} from "../deps.ts";

const hostname = "127.0.0.1";

Expand Down
14 changes: 11 additions & 3 deletions tests/cases/03_crud.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import { assert, assertEquals, assertRejects } from "assert";
import { afterEach, beforeEach, describe, it } from "bdd";
import { greaterOrEqual, parse } from "semver";
import { Database, MongoClient, ObjectId } from "../../mod.ts";
import {
MongoInvalidArgumentError,
MongoServerError,
} from "../../src/error.ts";
import { CreateCollectionOptions } from "../../src/types.ts";
import { cleanTestDb, getTestDb } from "../common.ts";
import {
afterEach,
assert,
assertEquals,
assertRejects,
beforeEach,
describe,
greaterOrEqual,
it,
parse,
} from "../deps.ts";

interface User {
_id: string | ObjectId;
Expand Down
12 changes: 9 additions & 3 deletions tests/cases/04_indexes.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { assertEquals } from "assert";
import { afterEach, beforeEach, describe, it } from "bdd";
import { greaterOrEqual, parse } from "semver";
import { Collection, Database, Document, MongoClient } from "../../mod.ts";
import { cleanTestDb, getTestDb } from "../common.ts";
import {
afterEach,
assertEquals,
beforeEach,
describe,
greaterOrEqual,
it,
parse,
} from "../deps.ts";

describe(
"indexes",
Expand Down
3 changes: 1 addition & 2 deletions tests/cases/05_srv.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { assertEquals, assertRejects } from "assert";
import { describe, it } from "bdd";
import { Srv } from "../../src/utils/srv.ts";
import { assertEquals, assertRejects, describe, it } from "../deps.ts";

function mockResolver(
srvRecords: Partial<Deno.SRVRecord>[] = [],
Expand Down
12 changes: 10 additions & 2 deletions tests/cases/06_gridfs.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import { assert, assertEquals, assertNotEquals } from "assert";
import { afterAll, afterEach, beforeEach, describe, it } from "bdd";
import { GridFSBucket, MongoClient } from "../../mod.ts";
import { getClient } from "../common.ts";
import {
afterAll,
afterEach,
assert,
assertEquals,
assertNotEquals,
beforeEach,
describe,
it,
} from "../deps.ts";

async function streamReadAll(readable: ReadableStream): Promise<Uint8Array> {
return new Uint8Array(await new Response(readable).arrayBuffer());
Expand Down
3 changes: 1 addition & 2 deletions tests/cases/07_worker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { assertEquals } from "assert";
import { describe, it } from "bdd";
import { assertEquals, describe, it } from "../deps.ts";

describe("worker", () => {
it({
Expand Down
3 changes: 1 addition & 2 deletions tests/cases/08_find_cursor.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { assertEquals } from "assert";
import { describe, it } from "bdd";
import { FindCursor } from "../../src/collection/commands/find.ts";
import { WireProtocol } from "../../src/protocol/protocol.ts";
import { assertEquals, describe, it } from "../deps.ts";

describe("find cursor", () => {
it({
Expand Down
3 changes: 1 addition & 2 deletions tests/cases/09_geospatial_types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { assert, assertEquals } from "assert";
import { afterAll, describe, it } from "bdd";
import { type Database } from "../../mod.ts";
import { type Collection } from "../../src/collection/collection.ts";
import { Geometry, GeometryObject, Point } from "../../src/types/geojson.ts";
Expand All @@ -21,6 +19,7 @@ import {
ShapeOperator,
} from "../../src/types/geospatial.ts";
import { getClient } from "../common.ts";
import { afterAll, assert, assertEquals, describe, it } from "../deps.ts";

interface IPlace {
_id: string;
Expand Down
3 changes: 1 addition & 2 deletions tests/cases/10_command_helpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { assert, assertEquals } from "assert";
import { describe, it } from "bdd";
import { MongoClient } from "../../mod.ts";
import { assert, assertEquals, describe, it } from "../deps.ts";

describe("command helpers", () => {
it({
Expand Down
16 changes: 16 additions & 0 deletions tests/deps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export {
assert,
assertEquals,
assertNotEquals,
assertRejects,
assertThrows,
} from "jsr:@std/assert@^0.220.1";
export {
afterAll,
afterEach,
beforeAll,
beforeEach,
describe,
it,
} from "jsr:@std/testing@^0.220.1/bdd";
export { greaterOrEqual, parse } from "jsr:@std/semver@^0.220.1";

0 comments on commit 2d35550

Please sign in to comment.