diff --git a/README.md b/README.md index 501a5b5..fc4c184 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ import { User } from "jsr:@codr/models@^1"; git clone git@github.com:CodrJS/models.git # Cache deno dependencies -deno cache +deno cache ./mod.ts # Format, lint, and test the code deno fmt diff --git a/deno.lock b/deno.lock index e56fe9e..29d8b33 100644 --- a/deno.lock +++ b/deno.lock @@ -4,6 +4,7 @@ "specifiers": { "jsr:@std/assert": "jsr:@std/assert@1.0.0", "jsr:@std/internal@^1.0.1": "jsr:@std/internal@1.0.1", + "npm:bson": "npm:bson@6.8.0", "npm:jsonwebtoken": "npm:jsonwebtoken@9.0.2" }, "jsr": { @@ -18,6 +19,10 @@ } }, "npm": { + "bson@6.8.0": { + "integrity": "sha512-iOJg8pr7wq2tg/zSlCCHMi3hMm5JTOxLTagf3zxhcenHsFp+c6uOs6K7W5UE7A4QIJGtqh/ZovFNMP4mOPJynQ==", + "dependencies": {} + }, "buffer-equal-constant-time@1.0.1": { "integrity": "sha512-zRpUiDwd/xk6ADqPMATG8vc9VPrkck7T07OIx0gnjmJAnHnTVXNQG3vfvWNuiZIkwu9KrKdA1iJKfsfTVxE6NA==", "dependencies": {} diff --git a/src/models/Annotation.ts b/src/models/Annotation.ts index ac8a6c2..be3c4fb 100644 --- a/src/models/Annotation.ts +++ b/src/models/Annotation.ts @@ -1,4 +1,4 @@ -import type { ObjectId } from "npm:mongodb"; +import type { ObjectId } from "npm:bson"; import { Base, type IBase } from "./Base.ts"; import type { AtLeast } from "../types/mod.ts"; diff --git a/src/models/Audit.ts b/src/models/Audit.ts index 5e081c7..6919be7 100644 --- a/src/models/Audit.ts +++ b/src/models/Audit.ts @@ -1,4 +1,4 @@ -import type { ObjectId } from "npm:mongodb"; +import type { ObjectId } from "npm:bson"; import type { IBase } from "./Base.ts"; import type { ActionCode, ResourceCode } from "../types/mod.ts"; diff --git a/src/models/Authorization.ts b/src/models/Authorization.ts index aa3f7c6..ed29c30 100644 --- a/src/models/Authorization.ts +++ b/src/models/Authorization.ts @@ -1,4 +1,4 @@ -import type { ObjectId } from "npm:mongodb"; +import type { ObjectId } from "npm:bson"; import { Base, type IBase } from "./Base.ts"; import type { ActionCode, AtLeast, ResourceCode } from "../types/mod.ts"; diff --git a/src/models/Base.ts b/src/models/Base.ts index 5c03b2d..5bf135b 100644 --- a/src/models/Base.ts +++ b/src/models/Base.ts @@ -1,4 +1,4 @@ -import { ObjectId } from "npm:mongodb"; +import { ObjectId } from "npm:bson"; import type { AtLeast } from "../types/mod.ts"; export interface IBase { diff --git a/src/models/Dataset.ts b/src/models/Dataset.ts index 010e3cd..86e92ee 100644 --- a/src/models/Dataset.ts +++ b/src/models/Dataset.ts @@ -1,4 +1,4 @@ -import type { ObjectId } from "npm:mongodb"; +import type { ObjectId } from "npm:bson"; import type { AtLeast, Flags } from "../types/mod.ts"; import { Base, type IBase } from "./Base.ts"; diff --git a/src/models/Group.ts b/src/models/Group.ts index 00d8b2d..94e7d3f 100644 --- a/src/models/Group.ts +++ b/src/models/Group.ts @@ -1,4 +1,4 @@ -import type { ObjectId } from "npm:mongodb"; +import type { ObjectId } from "npm:bson"; import { Base, type IBase } from "./Base.ts"; import type { AtLeast, Flags } from "../types/mod.ts"; diff --git a/src/models/Message.ts b/src/models/Message.ts index a741c6d..c6e3873 100644 --- a/src/models/Message.ts +++ b/src/models/Message.ts @@ -1,4 +1,4 @@ -import type { ObjectId } from "npm:mongodb"; +import type { ObjectId } from "npm:bson"; import type { AtLeast, MessageType } from "../types/mod.ts"; import { Base, type IBase } from "./Base.ts"; diff --git a/src/models/Organization.ts b/src/models/Organization.ts index 7477c56..9bf0c6f 100644 --- a/src/models/Organization.ts +++ b/src/models/Organization.ts @@ -1,3 +1,4 @@ +import type { AtLeast } from "../types/mod.ts"; import { Base, type IBase } from "./Base.ts"; interface OrganizationFlags { @@ -34,7 +35,7 @@ export class Organization extends Base<"Organization"> { name, slug, domains, - }: IOrganization) { + }: AtLeast) { super({ _id, __v, diff --git a/src/models/Profile.ts b/src/models/Profile.ts index 5ae2fa2..f9b9db0 100644 --- a/src/models/Profile.ts +++ b/src/models/Profile.ts @@ -1,4 +1,4 @@ -import type { ObjectId } from "npm:mongodb"; +import type { ObjectId } from "npm:bson"; import { Base, type IBase } from "./Base.ts"; import type { User } from "./User.ts"; import type { AtLeast } from "../types/mod.ts"; diff --git a/src/models/Project.ts b/src/models/Project.ts index 0d1aed5..cfdbeed 100644 --- a/src/models/Project.ts +++ b/src/models/Project.ts @@ -1,4 +1,4 @@ -import type { ObjectId } from "npm:mongodb"; +import type { ObjectId } from "npm:bson"; import type { AtLeast, Flags, TaskType } from "../types/mod.ts"; import { Base, type IBase } from "./Base.ts"; diff --git a/src/models/Sample.ts b/src/models/Sample.ts index 514bf10..a9e73ec 100644 --- a/src/models/Sample.ts +++ b/src/models/Sample.ts @@ -1,4 +1,4 @@ -import type { ObjectId } from "npm:mongodb"; +import type { ObjectId } from "npm:bson"; import { Base, type IBase } from "./Base.ts"; import type { AtLeast } from "../types/mod.ts"; diff --git a/src/models/User.ts b/src/models/User.ts index 24544bd..6ed3c43 100644 --- a/src/models/User.ts +++ b/src/models/User.ts @@ -1,6 +1,6 @@ import { Base, type IBase } from "./Base.ts"; import type { AtLeast, UserEnum } from "../types/mod.ts"; -import type { ObjectId } from "npm:mongodb"; +import type { ObjectId } from "npm:bson"; export interface IUser extends IBase<"User"> { organizationId: ObjectId; diff --git a/tests/add.test.ts b/tests/add.test.ts deleted file mode 100644 index 0e0df17..0000000 --- a/tests/add.test.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { assertEquals } from "jsr:@std/assert"; -import { add } from "../mod.ts"; - -Deno.test("Adding numbers", function addTest() { - assertEquals(add(2, 3), 5); -}); diff --git a/tests/organization.test.ts b/tests/organization.test.ts new file mode 100644 index 0000000..bea5c89 --- /dev/null +++ b/tests/organization.test.ts @@ -0,0 +1,26 @@ +import { assert, assertEquals } from "jsr:@std/assert"; +import { Organization } from "../mod.ts"; +import { ObjectId } from "npm:bson"; + +Deno.test("Create organziation", function createOrganization() { + const createdBy: ObjectId = new ObjectId(); + const org = new Organization({ + domains: ["localhost:3000"], + name: "Demo Account", + flags: { + isActive: true, + isDeleted: false, + isDemo: true, + }, + slug: "demo", + createdBy, + }); + + assertEquals(org.toJSON().name, "Demo Account"); + assertEquals(org.toJSON().slug, "demo"); + assertEquals(org.toJSON().createdBy.toString(), createdBy.toString()); + assertEquals(org.toJSON().flags.isActive, true); + assertEquals(org.toJSON().flags.isDeleted, false); + assertEquals(org.toJSON().flags.isDemo, true); + assert(org.toJSON().domains.includes("localhost:3000")); +});