Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default class FileSystemGoToFileDialog extends Mixins(StateMixin) {
search = ''
loaded = false

get rootFiles (): Moonraker.Files.RootFile[] | undefined {
get rootFiles (): readonly Moonraker.Files.RootFile[] | undefined {
return this.$typedGetters['files/getRootFiles'](this.root)
}

Expand Down
2 changes: 1 addition & 1 deletion src/store/console/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const mutations = {
* Defines the list of available commands
*/
setGcodeHelp (state, payload: Moonraker.KlippyApis.GcodeHelpResponse) {
state.gcodeHelp = payload
state.gcodeHelp = Object.freeze(payload)
},

/**
Expand Down
5 changes: 2 additions & 3 deletions src/store/console/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
export interface ConsoleState {
// [key: string]: string;
consoleCommand: string;
consoleSearch: string;
console: ConsoleEntry[]; // console stream
gcodeHelp: Moonraker.KlippyApis.GcodeHelpResponse; // known commands
console: Readonly<ConsoleEntry>[]; // console stream
gcodeHelp: Readonly<Moonraker.KlippyApis.GcodeHelpResponse>; // known commands
consoleEntryCount: number; // give each console entry a unique id.
commandHistory: string[];
autoScroll: boolean;
Expand Down
26 changes: 17 additions & 9 deletions src/store/files/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,25 @@ export const mutations = {
setServerFilesGetDirectory (state, payload: { path: string, content: MoonrakerPathContent }) {
const { path, content } = payload

Vue.set(state.pathContent, path, content)
const pathContent: MoonrakerPathContent = {
...content,
files: content.files
.map(file => Object.freeze(file)),
dirs: content.dirs
.map(dir => Object.freeze(dir))
}

Vue.set(state.pathContent, path, pathContent)
},

setServerFilesRoots (state, payload: Moonraker.Files.RootInfoWithPath[]) {
state.roots = payload
state.roots = Object.freeze(payload)
},

setServerFilesListRoot (state, payload: { root: string, files: Moonraker.Files.RootFile[] }) {
const { root, files } = payload

Vue.set(state.rootFiles, root, files)
Vue.set(state.rootFiles, root, Object.freeze(files))
},

setFileUpdate (state, payload: { paths: FilePaths, file: Moonraker.Files.File | Moonraker.Files.FileWithMeta }) {
Expand All @@ -57,14 +65,14 @@ export const mutations = {
const fileIndex = directory.files.findIndex(file => file.filename === paths.filename)

if (fileIndex >= 0) {
Vue.set(directory.files, fileIndex, file)
Vue.set(directory.files, fileIndex, Object.freeze(file))
} else {
directory.files.push(file)
directory.files.push(Object.freeze(file))
}
} else {
const directory: MoonrakerPathContent = {
partial: true,
files: [file],
files: [Object.freeze(file)],
dirs: []
}

Expand All @@ -89,9 +97,9 @@ export const mutations = {
const dirIndex = directory.dirs.findIndex(dir => dir.dirname === paths.filename)

if (dirIndex >= 0) {
Vue.set(directory.dirs, dirIndex, dir)
Vue.set(directory.dirs, dirIndex, Object.freeze(dir))
} else {
directory.dirs.push(dir)
directory.dirs.push(Object.freeze(dir))
}
}
}
Expand Down Expand Up @@ -179,6 +187,6 @@ export const mutations = {
},

setDiskUsage (state, payload: { root: string, disk_usage: Moonraker.Files.DiskUsage }) {
Vue.set(state.diskUsage, payload.root, payload.disk_usage)
Vue.set(state.diskUsage, payload.root, Object.freeze(payload.disk_usage))
}
} satisfies MutationTree<FilesState>
10 changes: 5 additions & 5 deletions src/store/files/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ export type { AppFileMeta }
export interface FilesState {
uploads: FileUpload[];
download: FileDownload | null;
roots: Moonraker.Files.RootInfoWithPath[] | null;
roots: readonly Moonraker.Files.RootInfoWithPath[] | null;
currentPaths: Record<string, string | undefined>;
diskUsage: Record<string, Moonraker.Files.DiskUsage | undefined>;
rootFiles: Record<string, Moonraker.Files.RootFile[] | undefined>;
diskUsage: Record<string, Readonly<Moonraker.Files.DiskUsage> | undefined>;
rootFiles: Record<string, readonly Moonraker.Files.RootFile[] | undefined>;
pathContent: Record<string, MoonrakerPathContent | undefined>;
}

Expand All @@ -20,8 +20,8 @@ export interface AppDiskUsage extends Moonraker.Files.DiskUsage {

export interface MoonrakerPathContent {
partial?: boolean;
files: (Moonraker.Files.File | Moonraker.Files.FileWithMeta)[];
dirs: Moonraker.Files.Dir[];
files: (Readonly<Moonraker.Files.File> | Readonly<Moonraker.Files.FileWithMeta>)[];
dirs: Readonly<Moonraker.Files.Dir>[];
}

export interface AppFile extends Moonraker.Files.File, Pick<Moonraker.Files.Metadata, 'thumbnails'> {
Expand Down
9 changes: 5 additions & 4 deletions src/store/history/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const mutations = {
setHistoryList (state, payload: Moonraker.History.ListResponse) {
if (payload.jobs != null) {
state.jobs = payload.jobs
.map(job => Object.freeze(job))
}
if (payload.count != null) {
state.count = payload.count
Expand All @@ -35,7 +36,7 @@ export const mutations = {
*/
setAddHistory (state, payload: Moonraker.History.Job) {
if (payload) {
state.jobs.push(payload)
state.jobs.push(Object.freeze(payload))
state.count++
}
},
Expand All @@ -47,7 +48,7 @@ export const mutations = {
if (payload) {
const i = state.jobs.findIndex(job => job.job_id === payload.job_id)
if (i >= 0) {
Vue.set(state.jobs, i, payload)
Vue.set(state.jobs, i, Object.freeze(payload))
}
}
},
Expand All @@ -57,13 +58,13 @@ export const mutations = {
const i = state.jobs.findIndex(job => job.job_id === payload)
if (i >= 0) {
const job = state.jobs[i]
Vue.set(state.jobs, i, {
Vue.set(state.jobs, i, Object.freeze({
...job,
metadata: {
...job.metadata,
thumbnails: []
}
})
}))
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/store/history/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { AppFileMeta } from '@/store/files/types.metadata'

export interface HistoryState {
count: number;
jobs: Moonraker.History.Job[];
jobs: Readonly<Moonraker.History.Job>[];
job_totals: Moonraker.History.JobTotals;
}

Expand Down
2 changes: 1 addition & 1 deletion src/store/jobQueue/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ export const mutations = {
},

setQueuedJobs (state, payload: Moonraker.JobQueue.QueuedJob[]) {
state.queuedJobs = payload || []
state.queuedJobs = Object.freeze(payload || [])
}
Comment thread
pedrolamas marked this conversation as resolved.
} satisfies MutationTree<JobQueueState>
2 changes: 1 addition & 1 deletion src/store/jobQueue/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { AppFile, AppFileWithMeta } from '@/store/files/types'

export interface JobQueueState {
queueState: Moonraker.JobQueue.QueueState;
queuedJobs: Moonraker.JobQueue.QueuedJob[];
queuedJobs: readonly Moonraker.JobQueue.QueuedJob[];
}

export interface QueuedJobWithAppFile extends Moonraker.JobQueue.QueuedJob {
Expand Down
4 changes: 2 additions & 2 deletions src/store/spoolman/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ export const mutations = {
},

setSpools (state, payload: Moonraker.Spoolman.Spool[]) {
state.spools = payload
state.spools = Object.freeze(payload)
},

setDialogState (state, payload: SpoolSelectionDialogState) {
state.dialog = payload
},

setInfo (state, payload: Moonraker.Spoolman.Info) {
state.info = payload
state.info = Object.freeze(payload)
},

setCurrency (state, payload: Moonraker.Spoolman.Currency) {
Expand Down
4 changes: 2 additions & 2 deletions src/store/spoolman/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export interface SpoolmanState {
info: Moonraker.Spoolman.Info | null;
spools: Moonraker.Spoolman.Spool[];
info: Readonly<Moonraker.Spoolman.Info> | null;
spools: readonly Moonraker.Spoolman.Spool[];
activeSpool: number | null;
currency: string | null;
connected: boolean;
Expand Down
6 changes: 5 additions & 1 deletion src/typings/moonraker.spoolman.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ declare namespace Moonraker.Spoolman {
extra?: Record<string, unknown>;
}

export type FilamentMultiColorDirection =
| 'coaxial'
| 'longitudinal'

export interface Filament {
id: number;
registered: string;
Expand All @@ -75,7 +79,7 @@ declare namespace Moonraker.Spoolman {
settings_bed_temp?: number;
color_hex?: string;
multi_color_hexes?: string;
multi_color_direction?: string;
multi_color_direction?: FilamentMultiColorDirection;
external_id?: string;
extra?: Record<string, unknown>;
}
Expand Down