Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: CodrJS/jsr-models
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.1.2
Choose a base ref
...
head repository: CodrJS/jsr-models
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
  • 7 commits
  • 29 files changed
  • 1 contributor

Commits on Jul 20, 2024

  1. fix package name

    DylanBulmer committed Jul 20, 2024
    Copy the full SHA
    c6f99f7 View commit details
  2. start documenting the organization model

    DylanBulmer committed Jul 20, 2024
    Copy the full SHA
    7e745cf View commit details

Commits on Jul 21, 2024

  1. document Base and User entities

    DylanBulmer committed Jul 21, 2024
    Copy the full SHA
    85f512f View commit details
  2. bump version

    DylanBulmer committed Jul 21, 2024
    Copy the full SHA
    e236740 View commit details

Commits on Jul 26, 2024

  1. Document User, Profile, Role, and Permission; update naming conventio…

    …n from IEntity to EntityParamaters; update JWT token type
    DylanBulmer committed Jul 26, 2024
    Copy the full SHA
    861bb98 View commit details
  2. document Group, update Base, add tests

    DylanBulmer committed Jul 26, 2024
    Copy the full SHA
    07ab24f View commit details
  3. document project domain entities

    DylanBulmer committed Jul 26, 2024
    Copy the full SHA
    65fbf2f View commit details
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -49,7 +49,7 @@ import { User } from "jsr:@codr/models@^1";

```bash
# Clone the repo
git clone git@github.com:CodrJS/models.git
git clone git@github.com:CodrJS/jsr-models.git

# Cache deno dependencies
deno cache ./mod.ts
9 changes: 5 additions & 4 deletions deno.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
{
"name": "@codr/ts-template",
"version": "0.1.2",
"name": "@codr/models",
"version": "0.1.7",
"exports": "./mod.ts",
"fmt": {
"lineWidth": 80,
"indentWidth": 2,
"useTabs": false,
"semiColons": true,
"singleQuote": false
"singleQuote": false,
"proseWrap": "always"
},
"publish": {
"exclude": [".github/*", "*.test.ts", ".gitignore"]
"exclude": [".github/*", "tests/*.test.ts", ".gitignore", "coverage/*"]
},
"imports": {
"@std/assert": "jsr:@std/assert@^1.0.0",
15 changes: 11 additions & 4 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions mod.ts
Original file line number Diff line number Diff line change
@@ -1 +1,26 @@
/**
* @module
*
* This module consists of class entities used to collect, transform, and
* process data in Codr.
*
* @example
* ```ts
* import { Organization } from "@codr/models";
* import { ObjectId } from "bson";
*
* const org = new Organization ({
* name: "Demo Organization",
* domains: ["localhost:3000"],
* flags: {
* isActive: true,
* isDeleted: false,
* isDemo: true,
* },
* slug: "demo",
* createdBy: new ObjectId(),
* })
* ```
*/

export * from "./src/mod.ts";
3 changes: 1 addition & 2 deletions src/mod.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// export files from here.

// export * as Types from "./types/mod.ts";
export * from "./models/mod.ts";
export { type JwtPayload } from "./types/mod.ts";
45 changes: 25 additions & 20 deletions src/models/Annotation.ts
Original file line number Diff line number Diff line change
@@ -1,59 +1,64 @@
import type { ObjectId } from "bson";
import { Base, type IBase } from "./Base.ts";
import { Base, type BaseParameters } from "./Base.ts";
import type { AtLeast } from "../types/mod.ts";

export interface IAnnotation extends IBase<"Annotation"> {
projectId: ObjectId;
/**
* Parameters for creating an {@link Annotation} entity.
*/
export interface AnnotationParameters extends BaseParameters<"Annotation"> {
/** The dataset this annotation comes from. */
datasetId: ObjectId;
/** The sample this annotation is for. */
sampleId: ObjectId;
/** What user annotated the annotation. */
annotatedBy: ObjectId;
/** The annotated value/output */
value: object;
}

/**
* Annotation entity class for representing a dataset sample annotation.
*/
export class Annotation extends Base<"Annotation"> {
projectId: ObjectId;
datasetId: ObjectId;
sampleId: ObjectId;
annotatedBy: ObjectId;
value: object;

constructor({
projectId,
datasetId,
sampleId,
value,
annotatedBy,
_id,
__v,
_version,
createdAt,
updatedAt,
createdBy,
updatedBy,
}: AtLeast<
IAnnotation,
| "createdBy"
| "projectId"
| "datasetId"
| "annotatedBy"
| "sampleId"
| "value"
AnnotationParameters,
"createdBy" | "datasetId" | "annotatedBy" | "sampleId" | "value"
>) {
super({ _id, __v, createdAt, updatedAt, createdBy, updatedBy });
this.projectId = projectId;
super({ _id, _version, createdAt, updatedAt, createdBy, updatedBy });
this.datasetId = datasetId;
this.value = value;
this.sampleId = sampleId;
this.annotatedBy = annotatedBy;
this.value = value;
}

toJSON(): Omit<IAnnotation, "kind"> {
/**
* Transforms the {@link Annotation} class object into a {@link AnnotationParameters}-like
* json object. Useful for saving the entity to the database.
* @returns a json representation of the annotation entity.
*/
toJSON(): Omit<AnnotationParameters, "kind"> {
const json = super.toJSON();
return {
...json,
projectId: this.projectId,
annotatedBy: this.annotatedBy,
sampleId: this.sampleId,
datasetId: this.datasetId,
sampleId: this.sampleId,
annotatedBy: this.annotatedBy,
value: this.value,
};
}
5 changes: 3 additions & 2 deletions src/models/Audit.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { ObjectId } from "bson";
import type { IBase } from "./Base.ts";
import type { BaseParameters } from "./Base.ts";
import type { ActionCode, ResourceCode } from "../types/mod.ts";

export interface IAudit<T> extends Omit<IBase<"Audit">, "createdBy"> {
export interface AuditParameters<T>
extends Omit<BaseParameters<"Audit">, "createdBy"> {
type: ResourceCode; // Where: what system processed this event.
action: ActionCode; // How: what action was taken.
userId: ObjectId; // Who: which user made the change.
43 changes: 0 additions & 43 deletions src/models/Authorization.ts

This file was deleted.

42 changes: 28 additions & 14 deletions src/models/Base.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,60 @@
import { ObjectId } from "bson";
import type { AtLeast } from "../types/mod.ts";

export interface IBase<Kind extends string> {
/**
* Base entity parameters for all database entities.
*/
export interface BaseParameters<Kind extends string> {
/** Typescript annotation for permissioning/authorization purposes. */
readonly kind: Kind;
__v?: number;
/** Entity version stored in the database. */
_version?: number;
/** Entity identifier stored in the database. */
_id: ObjectId;
/** Entity created date. */
createdAt: Date;
/** Entity unpdated date. */
updatedAt: Date;
/** Entity created by {@link User} id. */
createdBy: ObjectId;
/** Entity updated by {@link User} id. */
updatedBy: ObjectId;
}

export class Base<K extends string> {
readonly __v: IBase<K>["__v"];
readonly _id: IBase<K>["_id"];
readonly createdAt: Date;
readonly updatedAt: Date;
readonly createdBy: ObjectId;
readonly updatedBy: ObjectId;
readonly _version: BaseParameters<K>["_version"];
readonly _id: BaseParameters<K>["_id"];
readonly createdAt: BaseParameters<K>["createdAt"];
updatedAt: BaseParameters<K>["updatedAt"];
readonly createdBy: BaseParameters<K>["createdBy"];
updatedBy: BaseParameters<K>["updatedBy"];

constructor({
createdAt,
updatedAt,
createdBy,
updatedBy,
_id,
__v,
}: AtLeast<IBase<K>, "createdBy">) {
this.__v = __v;
_version = 0,
}: AtLeast<BaseParameters<K>, "createdBy">) {
this._version = _version;
this._id = _id || new ObjectId();

const now = new Date(Date.now());
const now = new Date();
this.createdAt = createdAt || now;
this.updatedAt = updatedAt || now;

this.createdBy = createdBy;
this.updatedBy = updatedBy || createdBy;
}

toJSON(): Omit<IBase<K>, "kind"> {
/**
* Transforms the base class object into a json object. Useful for saving the entity to the database.
* @returns a json representation of the base entity.
*/
toJSON(): Omit<BaseParameters<K>, "kind"> {
return {
__v: this.__v,
_version: this._version,
_id: this._id,
createdAt: this.createdAt,
updatedAt: this.updatedAt,
Loading