mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-12 15:04:52 +09:00
Revert strict ModInfo.jsonSchema and cover the factorio_version error
The strict major.minor jsonSchema did not improve any consuming type (the factorioVersion field is already typed) and only complicated the fromJSON signature, so revert it (and drop the now-unused MajorMinorVersionSchema). Add a test for the unparseable factorio_version branch in fromJSON. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
e27ad5fdf9
commit
5d20f8fc84
3 files changed
+8
-13
No files matched your search
@@ -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<typeof ModInfo.infoJsonSchema>
|
||||
& Pick<Static<typeof ModInfo.jsonSchema>, "size" | "mtime_ms" | "sha1" | "updated_at_ms" | "is_deleted">
|
||||
) {
|
||||
static fromJSON(json: Static<typeof ModInfo.jsonSchema>) {
|
||||
const modInfo = new this();
|
||||
|
||||
// info.json fields
|
||||
|
||||
@@ -103,9 +103,6 @@ export function integerPartialVersion(version: PartialVersion) {
|
||||
*/
|
||||
const majorMinorVersionRegExp = /^\d+\.\d+$/;
|
||||
export type MajorMinorVersion = `${number}.${number}`;
|
||||
export const MajorMinorVersionSchema = Type.Unsafe<MajorMinorVersion>(
|
||||
Type.String({ pattern: majorMinorVersionRegExp.source })
|
||||
);
|
||||
|
||||
export function isMajorMinorVersion(input: string): input is MajorMinorVersion {
|
||||
return majorMinorVersionRegExp.test(input);
|
||||
|
||||
@@ -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"];
|
||||
|
||||
Reference in new issue
Block a user