diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index eee68b7..bdb613b 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,14 +1 @@ - -# These are supported funding model platforms - -github: [erfanium] -patreon: # Replace with a single Patreon username -open_collective: # Replace with a single Open Collective username -ko_fi: # Replace with a single Ko-fi username -tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel -community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry -liberapay: # Replace with a single Liberapay username -issuehunt: # Replace with a single IssueHunt username -otechie: # Replace with a single Otechie username -custom: - - https://github.com/denodrivers/deno_mongo/discussions/358 \ No newline at end of file +github: [lucsoft] diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dcc8e2d..d29829e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,7 +32,7 @@ jobs: # Lint & Format - name: Lint & Format TS run: | - deno lint --ignore=./bson/bson.d.ts + deno lint deno fmt --check # Start MongoDB diff --git a/.github/workflows/jsr.yml b/.github/workflows/jsr.yml new file mode 100644 index 0000000..6e91d51 --- /dev/null +++ b/.github/workflows/jsr.yml @@ -0,0 +1,36 @@ +name: jsr + +on: + release: + types: [published] + +jobs: + publish: + name: ubuntu-latest + runs-on: ubuntu-latest + timeout-minutes: 60 + permissions: + contents: read + id-token: write + + steps: + - name: Setup Environment + run: | + git config --global core.autocrlf false + git config --global core.eol lf + + - name: Clone repository + uses: actions/checkout@v2 + + - name: Install Deno + uses: denolib/setup-deno@master + with: + deno-version: 1.x.x + + - name: Log versions + run: | + deno --version + + - name: Publish to JSR + run: | + deno publish \ No newline at end of file diff --git a/deno.json b/deno.json index 9863f3c..fb831e4 100644 --- a/deno.json +++ b/deno.json @@ -1,6 +1,6 @@ { "name": "@db/mongo", - "version": "0.33.0", + "version": "0.34.0", "exports": { ".": "./mod.ts", "./client": "./src/client.ts", diff --git a/deps.ts b/deps.ts index ba33cc6..a70a811 100644 --- a/deps.ts +++ b/deps.ts @@ -16,6 +16,6 @@ export { Timestamp, UUID, } from "jsr:@lucsoft/web-bson@^0.3.1"; -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 { crypto as stdCrypto } from "jsr:@std/crypto@^0.224.0/crypto"; +export { decodeBase64, encodeBase64 } from "jsr:@std/encoding@^0.224.0/base64"; +export { encodeHex } from "jsr:@std/encoding@^0.224.0/hex"; diff --git a/mod.ts b/mod.ts index 3bf7a1a..32bf828 100644 --- a/mod.ts +++ b/mod.ts @@ -1,3 +1,34 @@ +/** + * @module + * + * # deno_mongo + * + * **deno_mongo** is a **MongoDB** driver for Deno which also supports Deno Deploy. + * + * ## ATTENTION + * + * Deno has support for npm modules now, so you can also use `npm:mongodb`. + * See [this](https://github.com/denodrivers/mongo/issues/380) for more details. + * + * ## Usage + * + * Replace `version` with the latest version of the driver. + * + * ```ts + * import { MongoClient } from 'jsr:@db/mongo@version'; + * ``` + * + * See [the README](https://github.com/denodrivers/mongo) for more examples. + * + * ## Other community resources and examples + * + * - [atlas_sdk](https://deno.land/x/atlas_sdk) - TypeSafe MongoDB Atlas SDK + * - [dangoDB](https://github.com/oslabs-beta/dangoDB) - MongoDB ORM for Deno + * - [deno-deploy-mongo](https://github.com/erfanium/deno-deploy-mongo) - A simple app with Deno, MongoDB, and Oak using MongoDB Atlas + * - [deno_rest](https://github.com/vicky-gonsalves/deno_rest) - An Oak-based template for RESTful APIs using this driver + * - [denomongo-unittest-utils](https://github.com/Gang-of-Fork/denomongo-unittest-utils) - Mock collection for unit tests + */ + export { Binary, BSONRegExp, diff --git a/src/auth/base.ts b/src/auth/base.ts index 2a8117e..8d79c34 100644 --- a/src/auth/base.ts +++ b/src/auth/base.ts @@ -1,5 +1,5 @@ -import { WireProtocol } from "../protocol/mod.ts"; -import { ConnectOptions, Credential, Document } from "../types.ts"; +import type { WireProtocol } from "../protocol/mod.ts"; +import type { ConnectOptions, Credential, Document } from "../types.ts"; export abstract class AuthPlugin { abstract auth(authContext: AuthContext): Document; diff --git a/src/auth/scram.ts b/src/auth/scram.ts index 09383c1..22a84d2 100644 --- a/src/auth/scram.ts +++ b/src/auth/scram.ts @@ -6,11 +6,11 @@ import { stdCrypto, } from "../../deps.ts"; import { MongoDriverError } from "../error.ts"; -import { HandshakeDocument } from "../protocol/handshake.ts"; +import type { HandshakeDocument } from "../protocol/handshake.ts"; import { driverMetadata } from "../protocol/mod.ts"; -import { Credential, Document } from "../types.ts"; +import type { Credential, Document } from "../types.ts"; import { saslprep } from "../utils/saslprep/mod.ts"; -import { AuthContext, AuthPlugin } from "./base.ts"; +import { type AuthContext, AuthPlugin } from "./base.ts"; import { pbkdf2 } from "./pbkdf2.ts"; type CryptoMethod = "sha1" | "sha256"; diff --git a/src/auth/x509.ts b/src/auth/x509.ts index 4a23666..c246e48 100644 --- a/src/auth/x509.ts +++ b/src/auth/x509.ts @@ -1,7 +1,7 @@ -import { HandshakeDocument } from "../protocol/handshake.ts"; +import type { HandshakeDocument } from "../protocol/handshake.ts"; import { driverMetadata } from "../protocol/mod.ts"; -import { Credential, Document } from "../types.ts"; -import { AuthContext, AuthPlugin } from "./base.ts"; +import type { Credential, Document } from "../types.ts"; +import { type AuthContext, AuthPlugin } from "./base.ts"; export interface X509Command extends Document { authenticate: number; diff --git a/src/client.ts b/src/client.ts index 3ba94bb..7090500 100644 --- a/src/client.ts +++ b/src/client.ts @@ -1,7 +1,7 @@ import { Cluster } from "./cluster.ts"; import { Database } from "./database.ts"; import { MongoDriverError } from "./error.ts"; -import { +import type { BuildInfo, ConnectOptions, Document, diff --git a/src/cluster.ts b/src/cluster.ts index 29996a0..49b9f54 100644 --- a/src/cluster.ts +++ b/src/cluster.ts @@ -1,7 +1,7 @@ import { AuthContext, ScramAuthPlugin, X509AuthPlugin } from "./auth/mod.ts"; import { MongoDriverError } from "./error.ts"; import { WireProtocol } from "./protocol/mod.ts"; -import { ConnectOptions, Server } from "./types.ts"; +import type { ConnectOptions, Server } from "./types.ts"; export class Cluster { #options: ConnectOptions; diff --git a/src/collection/collection.ts b/src/collection/collection.ts index 25c3e1d..9770e59 100644 --- a/src/collection/collection.ts +++ b/src/collection/collection.ts @@ -4,8 +4,8 @@ import { MongoInvalidArgumentError, MongoServerError, } from "../error.ts"; -import { WireProtocol } from "../protocol/mod.ts"; -import { +import type { WireProtocol } from "../protocol/mod.ts"; +import type { AggregateOptions, AggregatePipeline, CountOptions, diff --git a/src/collection/commands/aggregate.ts b/src/collection/commands/aggregate.ts index 9e5325c..a50dfa4 100644 --- a/src/collection/commands/aggregate.ts +++ b/src/collection/commands/aggregate.ts @@ -1,6 +1,6 @@ import { CommandCursor } from "../../protocol/cursor.ts"; -import { WireProtocol } from "../../protocol/protocol.ts"; -import { AggregateOptions, Document } from "../../types.ts"; +import type { WireProtocol } from "../../protocol/protocol.ts"; +import type { AggregateOptions, Document } from "../../types.ts"; interface AggregateCursorContext { dbName: string; diff --git a/src/collection/commands/find.ts b/src/collection/commands/find.ts index c9df5bb..ea2fac4 100644 --- a/src/collection/commands/find.ts +++ b/src/collection/commands/find.ts @@ -1,5 +1,5 @@ -import { CommandCursor, WireProtocol } from "../../protocol/mod.ts"; -import { Document, FindOptions } from "../../types.ts"; +import { CommandCursor, type WireProtocol } from "../../protocol/mod.ts"; +import type { Document, FindOptions } from "../../types.ts"; interface FindCursorContext { dbName: string; diff --git a/src/collection/commands/list_indexes.ts b/src/collection/commands/list_indexes.ts index 3825339..17c244b 100644 --- a/src/collection/commands/list_indexes.ts +++ b/src/collection/commands/list_indexes.ts @@ -1,4 +1,4 @@ -import { CommandCursor, WireProtocol } from "../../protocol/mod.ts"; +import { CommandCursor, type WireProtocol } from "../../protocol/mod.ts"; interface ListIndexesCursorContext { dbName: string; diff --git a/src/collection/commands/update.ts b/src/collection/commands/update.ts index 0b09a28..35bea5a 100644 --- a/src/collection/commands/update.ts +++ b/src/collection/commands/update.ts @@ -1,6 +1,6 @@ -import { ObjectId } from "../../../deps.ts"; -import { WireProtocol } from "../../protocol/mod.ts"; -import { Document, UpdateOptions } from "../../types.ts"; +import type { ObjectId } from "../../../deps.ts"; +import type { WireProtocol } from "../../protocol/mod.ts"; +import type { Document, UpdateOptions } from "../../types.ts"; interface UpdateResponse { ok: number; diff --git a/src/database.ts b/src/database.ts index 941533d..8081ef2 100644 --- a/src/database.ts +++ b/src/database.ts @@ -1,12 +1,12 @@ -import { Cluster } from "./cluster.ts"; +import type { Cluster } from "./cluster.ts"; import { Collection } from "./collection/mod.ts"; import { CommandCursor } from "./protocol/mod.ts"; -import { +import type { CreateCollectionOptions, CreateUserOptions, Document, } from "./types.ts"; -import { WriteConcern } from "./types/read_write_concern.ts"; +import type { WriteConcern } from "./types/read_write_concern.ts"; interface ListCollectionsReponse { cursor: { diff --git a/src/gridfs/bucket.ts b/src/gridfs/bucket.ts index e8d8f30..0cd6dce 100644 --- a/src/gridfs/bucket.ts +++ b/src/gridfs/bucket.ts @@ -1,10 +1,10 @@ import { ObjectId } from "../../deps.ts"; -import { Collection } from "../collection/collection.ts"; -import { FindCursor } from "../collection/commands/find.ts"; -import { Database } from "../database.ts"; +import type { Collection } from "../collection/collection.ts"; +import type { FindCursor } from "../collection/commands/find.ts"; +import type { Database } from "../database.ts"; import { MongoRuntimeError } from "../error.ts"; -import { Filter } from "../types.ts"; -import { +import type { Filter } from "../types.ts"; +import type { Chunk, File, FileId, diff --git a/src/gridfs/indexes.ts b/src/gridfs/indexes.ts index a93b376..2638d3a 100644 --- a/src/gridfs/indexes.ts +++ b/src/gridfs/indexes.ts @@ -1,6 +1,6 @@ -import { Collection } from "../collection/collection.ts"; -import { Document, IndexOptions } from "../types.ts"; -import { Chunk, File } from "../types/gridfs.ts"; +import type { Collection } from "../collection/collection.ts"; +import type { Document, IndexOptions } from "../types.ts"; +import type { Chunk, File } from "../types/gridfs.ts"; async function ensureIndex( index: IndexOptions, diff --git a/src/gridfs/upload.ts b/src/gridfs/upload.ts index 708b048..a0600e9 100644 --- a/src/gridfs/upload.ts +++ b/src/gridfs/upload.ts @@ -1,6 +1,6 @@ -import { Binary, ObjectId } from "../../deps.ts"; -import { Collection } from "../collection/mod.ts"; -import { Chunk, File, GridFSUploadOptions } from "../types/gridfs.ts"; +import { Binary, type ObjectId } from "../../deps.ts"; +import type { Collection } from "../collection/mod.ts"; +import type { Chunk, File, GridFSUploadOptions } from "../types/gridfs.ts"; export interface BucketInfo { filesCollection: Collection; diff --git a/src/protocol/cursor.ts b/src/protocol/cursor.ts index 301f9ff..416cbd4 100644 --- a/src/protocol/cursor.ts +++ b/src/protocol/cursor.ts @@ -1,7 +1,7 @@ import { Long } from "../../deps.ts"; -import { Document } from "../types.ts"; +import type { Document } from "../types.ts"; import { parseNamespace } from "../utils/ns.ts"; -import { WireProtocol } from "./protocol.ts"; +import type { WireProtocol } from "./protocol.ts"; export interface CommandCursorOptions { id: bigint | number | string; diff --git a/src/protocol/handshake.ts b/src/protocol/handshake.ts index 38c13f8..4120e01 100644 --- a/src/protocol/handshake.ts +++ b/src/protocol/handshake.ts @@ -1,5 +1,5 @@ -import { Document } from "../types.ts"; -import { WireProtocol } from "./protocol.ts"; +import type { Document } from "../types.ts"; +import type { WireProtocol } from "./protocol.ts"; export const driverMetadata = { driver: { diff --git a/src/protocol/message.ts b/src/protocol/message.ts index 296ec53..38ec721 100644 --- a/src/protocol/message.ts +++ b/src/protocol/message.ts @@ -1,6 +1,6 @@ import { deserialize, serialize } from "../../deps.ts"; -import { Document } from "../types.ts"; -import { MessageHeader, OpCode, setHeader } from "./header.ts"; +import type { Document } from "../types.ts"; +import { type MessageHeader, OpCode, setHeader } from "./header.ts"; type MessageFlags = number; diff --git a/src/protocol/protocol.ts b/src/protocol/protocol.ts index e83ca42..fcf039b 100644 --- a/src/protocol/protocol.ts +++ b/src/protocol/protocol.ts @@ -1,12 +1,16 @@ import { MongoDriverError, - MongoErrorInfo, + type MongoErrorInfo, MongoServerError, } from "../error.ts"; -import { Document } from "../types.ts"; +import type { Document } from "../types.ts"; import { handshake } from "./handshake.ts"; import { parseHeader } from "./header.ts"; -import { deserializeMessage, Message, serializeMessage } from "./message.ts"; +import { + deserializeMessage, + type Message, + serializeMessage, +} from "./message.ts"; interface CommandTask { requestId: number; diff --git a/src/types.ts b/src/types.ts index ebc0413..a54c3a4 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,4 +1,4 @@ -import { +import type { Binary, BSONRegExp, Decimal128, @@ -8,14 +8,14 @@ import { ObjectId, Timestamp, } from "../deps.ts"; -import { +import type { $geoAny, $geoMultiPolygon, $geoPolygon, CenterSpecifier, ShapeOperator, } from "./types/geospatial.ts"; -import { WriteConcern } from "./types/read_write_concern.ts"; +import type { WriteConcern } from "./types/read_write_concern.ts"; /** * The types used by the MongoDB driver. diff --git a/src/types/geospatial.ts b/src/types/geospatial.ts index baf4e2a..6a1c578 100644 --- a/src/types/geospatial.ts +++ b/src/types/geospatial.ts @@ -1,5 +1,5 @@ -import { Document } from "../types.ts"; -import { +import type { Document } from "../types.ts"; +import type { GeoJsonObject, GeometryCollection, GeometryObject, diff --git a/src/types/gridfs.ts b/src/types/gridfs.ts index 17b72d3..b398260 100644 --- a/src/types/gridfs.ts +++ b/src/types/gridfs.ts @@ -1,6 +1,6 @@ -import { Binary, ObjectId } from "../../deps.ts"; -import { Document, ReadPreference } from "../types.ts"; -import { ReadConcern, WriteConcern } from "../types/read_write_concern.ts"; +import type { Binary, ObjectId } from "../../deps.ts"; +import type { Document, ReadPreference } from "../types.ts"; +import type { ReadConcern, WriteConcern } from "../types/read_write_concern.ts"; export type FileId = ObjectId; diff --git a/src/utils/saslprep/mod.ts b/src/utils/saslprep/mod.ts index 7489f45..d3deecb 100644 --- a/src/utils/saslprep/mod.ts +++ b/src/utils/saslprep/mod.ts @@ -3,7 +3,7 @@ //ORIGINAL PROJECT AND LICENSE IN: https://github.com/chiefbiiko/sparse-bitfield //ORIGINAL PROJECT AND LICENSE IN: https://github.com/chiefbiiko/memory-pager import { loadCodePoints } from "./load_code_points.ts"; -import { Bitfield } from "./sparse_bitfield.ts"; +import type { Bitfield } from "./sparse_bitfield.ts"; const { unassigned_code_points, diff --git a/src/utils/saslprep/sparse_bitfield.ts b/src/utils/saslprep/sparse_bitfield.ts index d4787b6..af0e75f 100644 --- a/src/utils/saslprep/sparse_bitfield.ts +++ b/src/utils/saslprep/sparse_bitfield.ts @@ -1,4 +1,4 @@ -import { Page, Pager } from "./memory_pager.ts"; +import { type Page, Pager } from "./memory_pager.ts"; /** Is the given number a power of two? */ function powerOfTwo(x: number): boolean { diff --git a/src/utils/srv.ts b/src/utils/srv.ts index b97fd70..6b6f54f 100644 --- a/src/utils/srv.ts +++ b/src/utils/srv.ts @@ -1,4 +1,4 @@ -import { ConnectOptions } from "../types.ts"; +import type { ConnectOptions } from "../types.ts"; import { parseSrvUrl } from "./uri.ts"; enum AllowedOption { diff --git a/src/utils/uri.ts b/src/utils/uri.ts index 1907acd..2dbf556 100644 --- a/src/utils/uri.ts +++ b/src/utils/uri.ts @@ -1,5 +1,5 @@ // mongodb://username:password@example.com:27017,example2.com:27017,...,example.comN:27017/database?key=value&keyN=valueN -import { ConnectOptions, Credential, Server } from "../types.ts"; +import type { ConnectOptions, Credential, Server } from "../types.ts"; import { Srv } from "./srv.ts"; interface Parts { diff --git a/tests/cases/01_auth.ts b/tests/cases/01_auth.ts index 74d2a7a..12fb4e3 100644 --- a/tests/cases/01_auth.ts +++ b/tests/cases/01_auth.ts @@ -1,4 +1,4 @@ -import { Database } from "../../mod.ts"; +import type { Database } from "../../mod.ts"; import { cleanUsername, clientFirstMessageBare, diff --git a/tests/cases/03_crud.ts b/tests/cases/03_crud.ts index ff20b5a..7beb539 100644 --- a/tests/cases/03_crud.ts +++ b/tests/cases/03_crud.ts @@ -1,9 +1,9 @@ -import { Database, MongoClient, ObjectId } from "../../mod.ts"; +import type { Database, MongoClient, ObjectId } from "../../mod.ts"; import { MongoInvalidArgumentError, MongoServerError, } from "../../src/error.ts"; -import { CreateCollectionOptions } from "../../src/types.ts"; +import type { CreateCollectionOptions } from "../../src/types.ts"; import { cleanTestDb, getTestDb } from "../common.ts"; import { afterEach, diff --git a/tests/cases/04_indexes.ts b/tests/cases/04_indexes.ts index 1bf5350..38a1660 100644 --- a/tests/cases/04_indexes.ts +++ b/tests/cases/04_indexes.ts @@ -1,4 +1,4 @@ -import { Collection, Database, Document, MongoClient } from "../../mod.ts"; +import type { Collection, Database, Document, MongoClient } from "../../mod.ts"; import { cleanTestDb, getTestDb } from "../common.ts"; import { afterEach, diff --git a/tests/cases/06_gridfs.ts b/tests/cases/06_gridfs.ts index df53e8d..97632ce 100644 --- a/tests/cases/06_gridfs.ts +++ b/tests/cases/06_gridfs.ts @@ -1,4 +1,4 @@ -import { GridFSBucket, MongoClient } from "../../mod.ts"; +import { GridFSBucket, type MongoClient } from "../../mod.ts"; import { getClient } from "../common.ts"; import { afterAll, diff --git a/tests/cases/08_find_cursor.ts b/tests/cases/08_find_cursor.ts index 787ed79..cf6bb03 100644 --- a/tests/cases/08_find_cursor.ts +++ b/tests/cases/08_find_cursor.ts @@ -1,5 +1,5 @@ import { FindCursor } from "../../src/collection/commands/find.ts"; -import { WireProtocol } from "../../src/protocol/protocol.ts"; +import type { WireProtocol } from "../../src/protocol/protocol.ts"; import { assertEquals, describe, it } from "../deps.ts"; describe("find cursor", () => { diff --git a/tests/cases/09_geospatial_types.ts b/tests/cases/09_geospatial_types.ts index a59abf5..7bfb8fb 100644 --- a/tests/cases/09_geospatial_types.ts +++ b/tests/cases/09_geospatial_types.ts @@ -1,7 +1,11 @@ -import { type Database } from "../../mod.ts"; -import { type Collection } from "../../src/collection/collection.ts"; -import { Geometry, GeometryObject, Point } from "../../src/types/geojson.ts"; -import { +import type { Database } from "../../mod.ts"; +import type { Collection } from "../../src/collection/collection.ts"; +import type { + Geometry, + GeometryObject, + Point, +} from "../../src/types/geojson.ts"; +import type { $box, $center, $centerSphere, diff --git a/tests/common.ts b/tests/common.ts index 33a6737..bb37852 100644 --- a/tests/common.ts +++ b/tests/common.ts @@ -1,4 +1,4 @@ -import { Database, MongoClient } from "../mod.ts"; +import { type Database, MongoClient } from "../mod.ts"; const hostname = "127.0.0.1";