Skip to content

Commit

Permalink
refactor: add types to data models
Browse files Browse the repository at this point in the history
  • Loading branch information
becem-gharbi committed May 17, 2023
1 parent 83473f4 commit f4b0de6
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 42 deletions.
14 changes: 6 additions & 8 deletions src/models/credentials.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
// var Credentials = new Schema({
// appname: String,
// credentials: String,
// });

import { storage } from "../storage.js";
interface ICredentials {
appname: string;
credentials: string;
}

export default {
findOne: (
where: { appname: string },
cb: (err: Error, credentials: any) => void
cb: (err: Error, credentials: ICredentials) => void
) => {},

findOneAndUpdate: (
where: { appname: string },
data: { credentials: any },
cb: (err: Error, credentials: any) => {}
cb: (err: Error, credentials: ICredentials) => {}
) => {},
};
13 changes: 6 additions & 7 deletions src/models/flows.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
// var Flows = new Schema({
// appname: String,
// flow: Schema.Types.Mixed,
// });
import { storage } from "../storage.js";
interface IFlows {
appname: string;
flow: any;
}

export default {
findOne: (
where: { appname: string },
cb: (err: Error, flows: any) => void
cb: (err: Error, flows: IFlows) => void
) => {},

findOneAndUpdate: (
where: { appname: string },
data: { flow: any },
cb: (err: Error, flows: any) => {}
cb: (err: Error, flows: IFlows) => {}
) => {},
};
21 changes: 10 additions & 11 deletions src/models/library.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
// var Library = new Schema({
// appname: String,
// type: String,
// name: String,
// meta: Schema.Types.Mixed,
// body: Schema.Types.Mixed,
// });
import { storage } from "../storage.js";
interface ILibrary {
appname: string;
type: string;
name: string;
meta: any;
body: any;
}

export default {
findOne: (
where: { appname: string; type: string; name: string },
cb: (err: Error, library: any) => void
cb: (err: Error, library: ILibrary) => void
) => {},

findOneAndUpdate: (
where: { appname: string; name: string },
data: { name: string; meta: string; body: string; type: string },
cb: (err: Error, library: any) => {}
data: { name: string; meta: any; body: any; type: string },
cb: (err: Error, library: ILibrary) => {}
) => {},
};
13 changes: 6 additions & 7 deletions src/models/sessions.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
// var Sessions = new Schema({
// appname: String,
// sessions: Schema.Types.Mixed,
// });
import { storage } from "../storage.js";
interface ISessions {
appname: string;
sessions: any;
}

export default {
findOne: (
where: { appname: string },
cb: (err: Error, sessions: any) => void
cb: (err: Error, sessions: ISessions) => void
) => {},

findOneAndUpdate: (
where: { appname: string },
data: { sessions: any },
cb: (err: Error, sessions: any) => {}
cb: (err: Error, sessions: ISessions) => {}
) => {},
};
13 changes: 6 additions & 7 deletions src/models/settings.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
// var Settings = new Schema({
// appname: String,
// settings: Schema.Types.Mixed,
// });
import { storage } from "../storage.js";
interface ISettings {
appname: string;
settings: any;
}

export default {
findOne: (
whrere: { appname: string },
cb: (err: Error, settings: any) => void
cb: (err: Error, settings: ISettings) => void
) => {},

findOneAndUpdate: (
where: { appname: string },
data: { settings: any },
cb: (err: Error, settings: any) => {}
cb: (err: Error, settings: ISettings) => {}
) => {},
};
4 changes: 2 additions & 2 deletions src/storage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@ts-nocheck
import type { Storage } from "unstorage";
import type { StorageModule } from "@node-red/runtime";
import { createStorage } from "unstorage";
import Flows from "./models/flows.js";
import Credentials from "./models/credentials.js";
Expand All @@ -11,7 +11,7 @@ var appname: string;

export const storage = createStorage();

export const storageModule = {
export const storageModule: StorageModule = {
init: async () => {
appname = "app0";
},
Expand Down

0 comments on commit f4b0de6

Please sign in to comment.