diff --git a/packages/lib/src/data/ModInfo.ts b/packages/lib/src/data/ModInfo.ts index dc164d65..458459c7 100644 --- a/packages/lib/src/data/ModInfo.ts +++ b/packages/lib/src/data/ModInfo.ts @@ -11,7 +11,7 @@ import { FullVersion, integerFullVersion, integerPartialVersion, GameVersionSchema, normaliseGameVersion, normaliseMajorMinorVersion, - MajorMinorVersion, MajorMinorVersionSchema, + MajorMinorVersion, ModVersionEquality, } from "./version"; @@ -266,9 +266,6 @@ export default class ModInfo { static jsonSchema = Type.Object({ ...this.infoJsonSchema.properties, - // The stored value is always normalised to a strict major.minor (see fromJSON), - // unlike the lenient info.json schema above. - "factorio_version": Type.Optional(MajorMinorVersionSchema), "size": Type.Optional(Type.Integer()), "mtime_ms": Type.Optional(Type.Number()), "sha1": Type.Optional(Type.String()), @@ -278,12 +275,7 @@ export default class ModInfo { static validate = libSchema.compile(this.jsonSchema as any); - // Accepts the lenient info.json version fields (normalised below) plus the stored - // extras; the strict jsonSchema describes the serialised form produced by toJSON. - static fromJSON(json: - Static - & Pick, "size" | "mtime_ms" | "sha1" | "updated_at_ms" | "is_deleted"> - ) { + static fromJSON(json: Static) { const modInfo = new this(); // info.json fields diff --git a/packages/lib/src/data/version.ts b/packages/lib/src/data/version.ts index 9b04f8b2..cdd575d9 100644 --- a/packages/lib/src/data/version.ts +++ b/packages/lib/src/data/version.ts @@ -103,9 +103,6 @@ export function integerPartialVersion(version: PartialVersion) { */ const majorMinorVersionRegExp = /^\d+\.\d+$/; export type MajorMinorVersion = `${number}.${number}`; -export const MajorMinorVersionSchema = Type.Unsafe( - Type.String({ pattern: majorMinorVersionRegExp.source }) -); export function isMajorMinorVersion(input: string): input is MajorMinorVersion { return majorMinorVersionRegExp.test(input); diff --git a/test/lib/data/ModInfo.js b/test/lib/data/ModInfo.js index 1d9531d8..1a31bb75 100644 --- a/test/lib/data/ModInfo.js +++ b/test/lib/data/ModInfo.js @@ -356,6 +356,12 @@ describe("lib/data/ModInfo", function() { /Invalid mod version/ ); }); + it("should throw for an unparseable factorio_version", function() { + assert.throws( + () => ModInfo.fromJSON({ name: "my-mod", factorio_version: "not-a-version" }), + /Invalid factorio_version/ + ); + }); it("should sort integer mod versions lexicographically", function() { let unsortedVersions = ["1.0.0", "1.1.0", "0.1.0", "3.0.0", "1.2.0", "0.3.1", "0.3.3", "2.1.1", "0.0.1"]; let sortedVersions = ["0.0.1", "0.1.0", "0.3.1", "0.3.3", "1.0.0", "1.1.0", "1.2.0", "2.1.1", "3.0.0"];