Add time unit suffixes to variables (#561)

Add suffixes like Ms and Ns to variables whos time unit is not in
seconds.  This is aligning with a new code style of putting units
on variables that are not in SI base units.
This commit is contained in:
Hornwitser authored and GitHub committed 2024-01-20 13:26:55 +01:00
1 parent 9842705eb9
commit c53781d16c
38 files changed
+221 -201

No files matched your search

+5 -5
View File
@@ -122,7 +122,7 @@ export default class ModInfo {
sha1?: string;
/** Millisecond Unix timestamp this entry was last updated at */
updatedAt = 0;
updatedAtMs = 0;
/**
* True if this mod has been deleted
@@ -148,7 +148,7 @@ export default class ModInfo {
...this.infoJsonSchema.properties,
"size": Type.Optional(Type.Integer()),
"sha1": Type.Optional(Type.String()),
"updated_at": Type.Optional(Type.Number()),
"updated_at_ms": Type.Optional(Type.Number()),
"is_deleted": Type.Optional(Type.Boolean()),
});
@@ -171,7 +171,7 @@ export default class ModInfo {
// Additional data
if (json.size) { modInfo.size = json.size; }
if (json.sha1) { modInfo.sha1 = json.sha1; }
if (json.updated_at) { modInfo.updatedAt = json.updated_at; }
if (json.updated_at_ms) { modInfo.updatedAtMs = json.updated_at_ms; }
if (json.is_deleted) { modInfo.isDeleted = json.is_deleted; }
return modInfo;
@@ -193,7 +193,7 @@ export default class ModInfo {
}
if (this.size) { json.size = this.size; }
if (this.sha1) { json.sha1 = this.sha1; }
if (this.updatedAt) { json.updated_at = this.updatedAt; }
if (this.updatedAtMs) { json.updated_at_ms = this.updatedAtMs; }
if (this.isDeleted) { json.is_deleted = this.isDeleted; }
return json;
}
@@ -229,7 +229,7 @@ export default class ModInfo {
size: stat.size,
sha1: await libHash.hashFile(modPath),
updated_at: stat.mtimeMs,
updated_at_ms: stat.mtimeMs,
is_deleted: false,
});
}
+6 -6
View File
@@ -102,7 +102,7 @@ export default class ModPack {
exportManifest?: ExportManifest;
/** Millisecond Unix timestamp this entry was last updated at */
updatedAt = 0;
updatedAtMs = 0;
/**
* True if this mod pack has been deleted from the list of mod packs.
@@ -118,7 +118,7 @@ export default class ModPack {
clone.mods = this.mods;
clone.settings = this.settings;
clone.exportManifest = this.exportManifest;
clone.updatedAt = this.updatedAt;
clone.updatedAtMs = this.updatedAtMs;
clone.isDeleted = this.isDeleted;
return clone;
}
@@ -135,7 +135,7 @@ export default class ModPack {
"runtime-per-user": ModSettingsJsonSchema,
}),
"export_manifest": Type.Optional(ExportManifest.jsonSchema),
"updated_at": Type.Optional(Type.Number()),
"updated_at_ms": Type.Optional(Type.Number()),
"is_deleted": Type.Optional(Type.Boolean()),
});
@@ -161,7 +161,7 @@ export default class ModPack {
};
}
if (json.export_manifest) { modPack.exportManifest = ExportManifest.fromJSON(json.export_manifest); }
if (json.updated_at) { modPack.updatedAt = json.updated_at; }
if (json.updated_at_ms) { modPack.updatedAtMs = json.updated_at_ms; }
if (json.is_deleted) { modPack.isDeleted = json.is_deleted; }
if (!modPack.mods.has("base")) {
@@ -185,7 +185,7 @@ export default class ModPack {
},
};
if (this.exportManifest) { json.export_manifest = this.exportManifest; }
if (this.updatedAt) { json.updated_at = this.updatedAt; }
if (this.updatedAtMs) { json.updated_at_ms = this.updatedAtMs; }
if (this.isDeleted) { json.is_deleted = this.isDeleted; }
return json;
}
@@ -194,7 +194,7 @@ export default class ModPack {
const json = this.toJSON();
delete json.id;
delete json.export_manifest;
delete json.updated_at;
delete json.updated_at_ms;
delete json.is_deleted;
// eslint-disable-next-line node/no-sync
+14 -11
View File
@@ -37,30 +37,33 @@ export default class PlayerStats {
static jsonSchema = Type.Object({
"join_count": Type.Optional(Type.Integer()),
"online_time_ms": Type.Optional(Type.Number()),
"first_join_at": Type.Optional(Type.Number()),
"first_join_at_ms": Type.Optional(Type.Number()),
"last_join_at_ms": Type.Optional(Type.Number()),
"last_leave_at_ms": Type.Optional(Type.Number()),
"last_leave_reason": Type.Optional(Type.String()),
// migrate: renamed fields from alpha 13
"last_join_at": Type.Optional(Type.Number()),
"last_leave_at": Type.Optional(Type.Number()),
"last_leave_reason": Type.Optional(Type.String()),
});
constructor(json: Static<typeof PlayerStats.jsonSchema> = {}) {
if (json["join_count"]) {
this.joinCount = json["join_count"];
}
if (json["first_join_at"]) {
this.firstJoinAt = new Date(json["first_join_at"]);
if (json["first_join_at_ms"]) {
this.firstJoinAt = new Date(json["first_join_at_ms"]);
}
if (json["online_time_ms"]) {
this.onlineTimeMs = json["online_time_ms"];
}
if (json["last_join_at"]) {
this.lastJoinAt = new Date(json["last_join_at"]);
if (json["last_join_at_ms"] ?? json["last_join_at"]) {
this.lastJoinAt = new Date(json["last_join_at_ms"] ?? json["last_join_at"]!);
if (!this.firstJoinAt) { // migrate: pre-alpha 14 did not have this field.
this.firstJoinAt = this.lastJoinAt;
}
}
if (json["last_leave_at"]) {
this.lastLeaveAt = new Date(json["last_leave_at"]);
if (json["last_leave_at_ms"] ?? json["last_leave_at"]) {
this.lastLeaveAt = new Date(json["last_leave_at_ms"] ?? json["last_leave_at"]!);
this.lastLeaveReason = json["last_leave_reason"] || "quit";
}
}
@@ -78,13 +81,13 @@ export default class PlayerStats {
json["online_time_ms"] = this.onlineTimeMs;
}
if (this.firstJoinAt) {
json["first_join_at"] = this.firstJoinAt.getTime();
json["first_join_at_ms"] = this.firstJoinAt.getTime();
}
if (this.lastJoinAt) {
json["last_join_at"] = this.lastJoinAt.getTime();
json["last_join_at_ms"] = this.lastJoinAt.getTime();
}
if (this.lastLeaveAt) {
json["last_leave_at"] = this.lastLeaveAt.getTime();
json["last_leave_at_ms"] = this.lastLeaveAt.getTime();
json["last_leave_reason"] = this.lastLeaveReason;
}
return json;
+5 -5
View File
@@ -24,7 +24,7 @@ export default class User {
/** Reason for being banned. Ignored if isBanned is false. */
public banReason = "",
/** Millisecond Unix timestamp this entry was last updated at */
public updatedAt = 0,
public updatedAtMs = 0,
/** True if this user object has been removed from the cluster. */
public isDeleted = false,
/** Combined statistics for the player this user account is tied to. */
@@ -42,7 +42,7 @@ export default class User {
is_banned: Type.Optional(Type.Boolean()),
is_whitelisted: Type.Optional(Type.Boolean()),
ban_reason: Type.Optional(Type.String()),
updated_at: Type.Optional(Type.Number()),
updated_at_ms: Type.Optional(Type.Number()),
is_deleted: Type.Optional(Type.Boolean()),
instance_stats: Type.Optional(
Type.Array(
@@ -67,7 +67,7 @@ export default class User {
json.is_banned,
json.is_whitelisted,
json.ban_reason,
json.updated_at,
json.updated_at_ms,
json.is_deleted,
playerStats,
instanceStats,
@@ -103,8 +103,8 @@ export default class User {
json.ban_reason = this.banReason;
}
if (this.updatedAt) {
json.updated_at = this.updatedAt;
if (this.updatedAtMs) {
json.updated_at_ms = this.updatedAtMs;
}
if (this.isDeleted) {
+3 -3
View File
@@ -239,7 +239,7 @@ export class SystemInfo {
public diskAvailable: number,
public canRestart: boolean,
/** Millisecond Unix timestamp this entry was last updated at */
public updatedAt: number,
public updatedAtMs: number,
public isDeleted: boolean,
) { }
@@ -256,7 +256,7 @@ export class SystemInfo {
"diskCapacity": Type.Number(),
"diskAvailable": Type.Number(),
"canRestart": Type.Boolean(),
"updatedAt": Type.Number(),
"updatedAtMs": Type.Number(),
"isDeleted": Type.Boolean(),
});
@@ -274,7 +274,7 @@ export class SystemInfo {
json.diskCapacity,
json.diskAvailable,
json.canRestart,
json.updatedAt,
json.updatedAtMs,
json.isDeleted,
);
}
+3 -3
View File
@@ -84,7 +84,7 @@ export class HostDetails {
public publicAddress: string = "",
public tokenValidAfter: number = 0,
/** Millisecond Unix timestamp this entry was last updated at */
public updatedAt = 0,
public updatedAtMs = 0,
public isDeleted = false,
) { }
@@ -96,7 +96,7 @@ export class HostDetails {
"remoteAddress": Type.Optional(Type.String()),
"publicAddress": Type.Optional(Type.String()),
"tokenValidAfter": Type.Optional(Type.Number()),
"updatedAt": Type.Optional(Type.Number()),
"updatedAtMs": Type.Optional(Type.Number()),
"isDeleted": Type.Optional(Type.Boolean()),
});
@@ -109,7 +109,7 @@ export class HostDetails {
json.remoteAddress,
json.publicAddress,
json.tokenValidAfter,
json.updatedAt,
json.updatedAtMs,
json.isDeleted,
);
}
+8 -8
View File
@@ -43,7 +43,7 @@ export class InstanceDetails {
public gamePort: number | undefined,
public status: InstanceStatus,
/** Millisecond Unix timestamp this entry was last updated at */
public updatedAt = 0,
public updatedAtMs = 0,
) { }
static jsonSchema = Type.Object({
@@ -55,7 +55,7 @@ export class InstanceDetails {
"unknown", "unassigned", "stopped", "starting", "running", "stopping",
"creating_save", "exporting_data", "deleted",
]),
"updatedAt": Type.Optional(Type.Number()),
"updatedAtMs": Type.Optional(Type.Number()),
});
static fromJSON(json: Static<typeof this.jsonSchema>) {
@@ -65,7 +65,7 @@ export class InstanceDetails {
json.assignedHost,
json.gamePort,
json.status,
json.updatedAt,
json.updatedAtMs,
);
}
@@ -289,7 +289,7 @@ export class SaveDetails {
public loaded: boolean,
public loadByDefault: boolean,
/** Millisecond Unix timestamp this entry was last updated at */
public updatedAt: number,
public updatedAtMs: number,
public isDeleted: boolean,
) { }
@@ -301,7 +301,7 @@ export class SaveDetails {
"mtimeMs": Type.Number(),
"loaded": Type.Boolean(),
"loadByDefault": Type.Boolean(),
"updatedAt": Type.Number(),
"updatedAtMs": Type.Number(),
"isDeleted": Type.Boolean(),
});
@@ -314,7 +314,7 @@ export class SaveDetails {
json.mtimeMs,
json.loaded,
json.loadByDefault,
json.updatedAt,
json.updatedAtMs,
json.isDeleted,
);
}
@@ -330,8 +330,8 @@ export class SaveDetails {
* @returns true if this save is identical to the provided save
*/
equals(other: SaveDetails) {
// Note that updatedAt is not included in the equality check because
// instances send the whole list of saves with updatedAt set to zero
// Note that updatedAtMs is not included in the equality check because
// instances send the whole list of saves with updatedAtMs set to zero
// to the controller whenever any save changes and this equals check
// is used to filter whether a save was updated.
return (