Skip to content

Commit 65fbf2f

Browse files
author
DylanBulmer
committed
document project domain entities
1 parent 07ab24f commit 65fbf2f

14 files changed

Lines changed: 239 additions & 92 deletions

File tree

deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@codr/models",
3-
"version": "0.1.6",
3+
"version": "0.1.7",
44
"exports": "./mod.ts",
55
"fmt": {
66
"lineWidth": 80,

src/mod.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// export * as Types from "./types/mod.ts";
22
export * from "./models/mod.ts";
3-
export { type JwtPayload, UserTypeCode } from "./types/mod.ts";
3+
export { type JwtPayload } from "./types/mod.ts";

src/models/Annotation.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,30 @@ import type { ObjectId } from "bson";
22
import { Base, type BaseParameters } from "./Base.ts";
33
import type { AtLeast } from "../types/mod.ts";
44

5+
/**
6+
* Parameters for creating an {@link Annotation} entity.
7+
*/
58
export interface AnnotationParameters extends BaseParameters<"Annotation"> {
6-
projectId: ObjectId;
9+
/** The dataset this annotation comes from. */
710
datasetId: ObjectId;
11+
/** The sample this annotation is for. */
812
sampleId: ObjectId;
13+
/** What user annotated the annotation. */
914
annotatedBy: ObjectId;
15+
/** The annotated value/output */
1016
value: object;
1117
}
1218

19+
/**
20+
* Annotation entity class for representing a dataset sample annotation.
21+
*/
1322
export class Annotation extends Base<"Annotation"> {
14-
projectId: ObjectId;
1523
datasetId: ObjectId;
1624
sampleId: ObjectId;
1725
annotatedBy: ObjectId;
1826
value: object;
1927

2028
constructor({
21-
projectId,
2229
datasetId,
2330
sampleId,
2431
value,
@@ -31,29 +38,27 @@ export class Annotation extends Base<"Annotation"> {
3138
updatedBy,
3239
}: AtLeast<
3340
AnnotationParameters,
34-
| "createdBy"
35-
| "projectId"
36-
| "datasetId"
37-
| "annotatedBy"
38-
| "sampleId"
39-
| "value"
41+
"createdBy" | "datasetId" | "annotatedBy" | "sampleId" | "value"
4042
>) {
4143
super({ _id, _version, createdAt, updatedAt, createdBy, updatedBy });
42-
this.projectId = projectId;
4344
this.datasetId = datasetId;
44-
this.value = value;
4545
this.sampleId = sampleId;
4646
this.annotatedBy = annotatedBy;
47+
this.value = value;
4748
}
4849

50+
/**
51+
* Transforms the {@link Annotation} class object into a {@link AnnotationParameters}-like
52+
* json object. Useful for saving the entity to the database.
53+
* @returns a json representation of the annotation entity.
54+
*/
4955
toJSON(): Omit<AnnotationParameters, "kind"> {
5056
const json = super.toJSON();
5157
return {
5258
...json,
53-
projectId: this.projectId,
54-
annotatedBy: this.annotatedBy,
55-
sampleId: this.sampleId,
5659
datasetId: this.datasetId,
60+
sampleId: this.sampleId,
61+
annotatedBy: this.annotatedBy,
5762
value: this.value,
5863
};
5964
}

src/models/Dataset.ts

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,57 @@
11
import type { ObjectId } from "bson";
2-
import type { AtLeast, Flags } from "../types/mod.ts";
2+
import type { AtLeast } from "../types/mod.ts";
33
import { Base, type BaseParameters } from "./Base.ts";
44

5+
/**
6+
* Parameters for creating a {@link Dataset} entity.
7+
*/
58
export interface DatasetParameters extends BaseParameters<"Dataset"> {
9+
/** The project id that this dataset is for. */
610
projectId: ObjectId;
7-
flags: Flags;
8-
name: string;
11+
/** The task id(s) that this dataset is for. */
12+
taskId: ObjectId[];
13+
/**
14+
* The sub-dataset id(s) that for this dataset. This is for dividing out
15+
* samples for annotation.
16+
*/
17+
subDatasetId: ObjectId[];
18+
/** The title/name of the dataset */
19+
title: string;
20+
/** The dataset flags. */
21+
flags: {
22+
/** Is the dataset active/archived? */
23+
isActive: boolean;
24+
/** Is the dateset soft deleted? */
25+
isDeleted: boolean;
26+
};
927
}
1028

29+
/**
30+
* Dataset entity class for representing a set of samples for a project and task.
31+
*/
1132
export class Dataset extends Base<"Dataset"> {
12-
projectId: ObjectId;
13-
flags: Flags;
14-
name: string;
33+
projectId: DatasetParameters["projectId"];
34+
taskId: DatasetParameters["taskId"];
35+
subDatasetId: DatasetParameters["subDatasetId"];
36+
title: DatasetParameters["title"];
37+
flags: DatasetParameters["flags"];
1538

1639
constructor({
17-
flags,
1840
projectId,
41+
taskId,
42+
subDatasetId,
43+
title,
44+
flags,
1945
_id,
2046
_version,
2147
createdAt,
2248
updatedAt,
23-
name,
2449
createdBy,
2550
updatedBy,
26-
}: AtLeast<DatasetParameters, "createdBy" | "name" | "flags" | "projectId">) {
51+
}: AtLeast<
52+
DatasetParameters,
53+
"createdBy" | "title" | "flags" | "projectId" | "taskId" | "subDatasetId"
54+
>) {
2755
super({
2856
_id,
2957
_version,
@@ -33,16 +61,25 @@ export class Dataset extends Base<"Dataset"> {
3361
updatedBy,
3462
});
3563
this.projectId = projectId;
64+
this.taskId = taskId;
65+
this.subDatasetId = subDatasetId;
66+
this.title = title;
3667
this.flags = flags;
37-
this.name = name;
3868
}
3969

70+
/**
71+
* Transforms the {@link Dataset} class object into a {@link DatasetParameters}-like
72+
* json object. Useful for saving the entity to the database.
73+
* @returns a json representation of the dataset entity.
74+
*/
4075
toJSON(): Omit<DatasetParameters, "kind"> {
4176
const json = super.toJSON();
4277
return {
4378
...json,
4479
projectId: this.projectId,
45-
name: this.name,
80+
taskId: this.taskId,
81+
subDatasetId: this.subDatasetId,
82+
title: this.title,
4683
flags: this.flags,
4784
};
4885
}

src/models/Permission.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type { AtLeast } from "../types/mod.ts";
66
* Parameters for creating a {@link Permission} entity.
77
*/
88
export interface PermissionParameters extends BaseParameters<"Permission"> {
9+
/** The title/name of the role. */
910
title: string;
1011
/**
1112
* Permission code.

src/models/Project.ts

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,44 @@
11
import type { ObjectId } from "bson";
2-
import type { AtLeast, Flags, TaskType } from "../types/mod.ts";
2+
import type { AtLeast } from "../types/mod.ts";
33
import { Base, type BaseParameters } from "./Base.ts";
44

5+
/**
6+
* Parameters for creating a {@link Project} entity.
7+
*/
58
export interface ProjectParameters extends BaseParameters<"Project"> {
6-
name: string;
7-
type: TaskType;
9+
/** The organization id the project belongs to. */
10+
readonly organizationId: ObjectId;
11+
/** The title of the project. */
12+
title: string;
13+
/** The URL slug of the project (unique to the organization) */
814
slug: string;
9-
guidelines?: string;
15+
/** The color of the project shown in the UI. */
1016
bgColorClass: string;
11-
config: ObjectId;
12-
flags: Flags & {
13-
isAnonymized: boolean;
17+
/** Project flags. */
18+
flags: {
19+
/** Is the project active/archived? */
20+
isActive: boolean;
21+
/** Is the project soft deleted? */
22+
isDeleted: boolean;
1423
};
1524
}
1625

26+
/**
27+
* Poject entity class for representing a reseach project.
28+
*/
1729
export class Project extends Base<"Project"> {
18-
name: string;
19-
slug: string;
20-
type: TaskType;
21-
guidelines?: string;
22-
bgColorClass: string;
23-
config: ObjectId;
24-
flags: Flags & {
25-
isAnonymized: boolean;
26-
};
30+
readonly organizationId: ProjectParameters["organizationId"];
31+
title: ProjectParameters["title"];
32+
slug: ProjectParameters["slug"];
33+
bgColorClass: ProjectParameters["bgColorClass"];
34+
flags: ProjectParameters["flags"];
2735

2836
constructor({
37+
organizationId,
2938
bgColorClass,
30-
config,
3139
flags,
32-
guidelines,
3340
slug,
34-
name,
35-
type,
41+
title,
3642
_id,
3743
_version,
3844
createdAt,
@@ -41,31 +47,32 @@ export class Project extends Base<"Project"> {
4147
updatedBy,
4248
}: AtLeast<
4349
ProjectParameters,
44-
"createdBy" | "bgColorClass" | "config" | "flags" | "slug" | "name" | "type"
50+
"createdBy" | "bgColorClass" | "flags" | "slug" | "title" | "organizationId"
4551
>) {
4652
super({ _id, _version, createdAt, updatedAt, createdBy, updatedBy });
4753

4854
this.bgColorClass = bgColorClass;
49-
this.config = config;
5055
this.flags = flags;
51-
this.guidelines = guidelines;
5256
this.slug = slug;
53-
this.name = name;
54-
this.type = type;
57+
this.title = title;
58+
this.organizationId = organizationId;
5559
}
5660

61+
/**
62+
* Transforms the {@link Project} class object into a {@link ProjectParameters}-like
63+
* json object. Useful for saving the entity to the database.
64+
* @returns a json representation of the project entity.
65+
*/
5766
toJSON(): Omit<ProjectParameters, "kind"> {
5867
const json = super.toJSON();
5968
return {
6069
...json,
6170
bgColorClass: this.bgColorClass,
62-
config: this.config,
6371
flags: this.flags,
64-
guidelines: this.guidelines,
6572
slug: this.slug,
66-
name: this.name,
67-
type: this.type,
73+
title: this.title,
6874
createdBy: this.createdBy,
75+
organizationId: this.organizationId,
6976
};
7077
}
7178
}

src/models/Sample.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,24 @@ import { Base, type BaseParameters } from "./Base.ts";
33
import type { AtLeast } from "../types/mod.ts";
44

55
export interface SampleParameters extends BaseParameters<"Sample"> {
6-
projectId: ObjectId;
6+
/** Dataset this sample is a part of */
77
datasetId: ObjectId;
8+
/** What sub-dataset/partition this sample belongs to. */
9+
subDatasetId: ObjectId;
10+
/** The payload of the sample. */
811
payload: object;
912
}
1013

14+
/**
15+
* Parameters for creating a {@link Sample} entity.
16+
*/
1117
export class Sample extends Base<"Smaple"> {
12-
projectId: ObjectId;
13-
datasetId: ObjectId;
14-
payload: object;
18+
datasetId: SampleParameters["datasetId"];
19+
subDatasetId: SampleParameters["subDatasetId"];
20+
payload: SampleParameters["payload"];
1521

1622
constructor({
17-
projectId,
23+
subDatasetId,
1824
datasetId,
1925
payload,
2026
_id,
@@ -25,20 +31,25 @@ export class Sample extends Base<"Smaple"> {
2531
updatedBy,
2632
}: AtLeast<
2733
SampleParameters,
28-
"createdBy" | "datasetId" | "projectId" | "payload"
34+
"createdBy" | "datasetId" | "subDatasetId" | "payload"
2935
>) {
3036
super({ _id, _version, createdAt, updatedAt, createdBy, updatedBy });
31-
this.projectId = projectId;
3237
this.datasetId = datasetId;
38+
this.subDatasetId = subDatasetId;
3339
this.payload = payload;
3440
}
3541

42+
/**
43+
* Transforms the {@link Sample} class object into a {@link SampleParameters}-like
44+
* json object. Useful for saving the entity to the database.
45+
* @returns a json representation of a dataset sample entity.
46+
*/
3647
toJSON(): Omit<SampleParameters, "kind"> {
3748
const json = super.toJSON();
3849
return {
3950
...json,
40-
projectId: this.projectId,
4151
datasetId: this.datasetId,
52+
subDatasetId: this.subDatasetId,
4253
payload: this.payload,
4354
};
4455
}

0 commit comments

Comments
 (0)