Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"pg": "^8.8.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"remult": "^0.16.0"
"remult": "^0.16.3-exp.1"
},
"devDependencies": {
"@types/compression": "^1.7.2",
Expand Down
30 changes: 15 additions & 15 deletions src/shared/Task.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { Allow, Entity, Fields, Validators } from "remult";
import { Allow, describeClass, Entity, Fields, Validators } from "remult";
import { Roles } from "./Roles";

@Entity<Task>("tasks", {
allowApiRead: Allow.authenticated,
allowApiUpdate: Allow.authenticated,
allowApiInsert: Roles.admin,
allowApiDelete: Roles.admin
})
export class Task {
@Fields.uuid()
id!: string;

@Fields.string({
validate: Validators.required,
allowApiUpdate: Roles.admin
})
title = '';

@Fields.boolean()
completed = false;
}

describeClass(Task, Entity<Task>("tasks", {
allowApiRead: Allow.authenticated,
allowApiUpdate: Allow.authenticated,
allowApiInsert: Roles.admin,
allowApiDelete: Roles.admin
}), {
id: Fields.uuid(),
title: Fields.string({
validate: Validators.required,
allowApiUpdate: Roles.admin
}),
completed: Fields.boolean()
})
Comment on lines +10 to +22

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks equivalent to the decorators version. 2 questions:

  1. If I have a typo anywhere, does TS catch that and let me know? If no, then does at least the runtime catch it?
  2. Have you looked into the mobx way of decorating classes without decorators (in the ctor)? I'm assuming they carefully evaluated different approaches and that their chosen one was found superior.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks - Answers:

  1. Yes - typescript will let you know there is an error and search references work.
  2. Mobx needed something other than me - All I need is some metadata - mobx needed to alter the class instance itself - that's why they used the "makeAutoObservable" in the constructor and changed the members to properties.

7 changes: 5 additions & 2 deletions src/shared/TasksController.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Allow, BackendMethod, remult } from "remult";
import { Allow, BackendMethod, describeClass, remult } from "remult";
import { Task } from "./Task";
import { Roles } from "./Roles";

export class TasksController {
@BackendMethod({ allowed: Roles.admin })
static async setAll(completed: boolean) {
const taskRepo = remult.repo(Task);

Expand All @@ -12,3 +11,7 @@ export class TasksController {
}
}
}

describeClass(TasksController, undefined, undefined, {
setAll: BackendMethod({ allowed: Roles.admin })
})