added format command and added trailing commas to reduce conflicts

This commit is contained in:
dswbx
2025-02-26 20:06:03 +01:00
parent 88b5359f1c
commit 7743f71a11
414 changed files with 3622 additions and 3610 deletions

View File

@@ -8,8 +8,8 @@ describe("SchemaObject", async () => {
Type.Object({ a: Type.String({ default: "b" }) }),
{ a: "test" },
{
forceParse: true
}
forceParse: true,
},
);
expect(m.get()).toEqual({ a: "test" });
@@ -30,14 +30,14 @@ describe("SchemaObject", async () => {
b: Type.Object(
{
c: Type.String({ default: "d" }),
e: Type.String({ default: "f" })
e: Type.String({ default: "f" }),
},
{ default: {} }
)
{ default: {} },
),
},
{ default: {}, additionalProperties: false }
)
})
{ default: {}, additionalProperties: false },
),
}),
);
expect(m.get()).toEqual({ s: { a: "b", b: { c: "d", e: "f" } } });
@@ -59,8 +59,8 @@ describe("SchemaObject", async () => {
test("patch array", async () => {
const m = new SchemaObject(
Type.Object({
methods: Type.Array(Type.String(), { default: ["GET", "PATCH"] })
})
methods: Type.Array(Type.String(), { default: ["GET", "PATCH"] }),
}),
);
expect(m.get()).toEqual({ methods: ["GET", "PATCH"] });
@@ -81,14 +81,14 @@ describe("SchemaObject", async () => {
a: Type.String({ default: "b" }),
b: Type.Object(
{
c: Type.String({ default: "d" })
c: Type.String({ default: "d" }),
},
{ default: {} }
)
{ default: {} },
),
},
{ default: {} }
)
})
{ default: {} },
),
}),
);
expect(m.get()).toEqual({ s: { a: "b", b: { c: "d" } } });
@@ -108,8 +108,8 @@ describe("SchemaObject", async () => {
test("set", async () => {
const m = new SchemaObject(
Type.Object({
methods: Type.Array(Type.String(), { default: ["GET", "PATCH"] })
})
methods: Type.Array(Type.String(), { default: ["GET", "PATCH"] }),
}),
);
expect(m.get()).toEqual({ methods: ["GET", "PATCH"] });
@@ -125,7 +125,7 @@ describe("SchemaObject", async () => {
let result: any;
const m = new SchemaObject(
Type.Object({
methods: Type.Array(Type.String(), { default: ["GET", "PATCH"] })
methods: Type.Array(Type.String(), { default: ["GET", "PATCH"] }),
}),
undefined,
{
@@ -133,8 +133,8 @@ describe("SchemaObject", async () => {
await new Promise((r) => setTimeout(r, 10));
called = true;
result = config;
}
}
},
},
);
await m.set({ methods: ["GET", "POST"] });
@@ -146,7 +146,7 @@ describe("SchemaObject", async () => {
let called = false;
const m = new SchemaObject(
Type.Object({
methods: Type.Array(Type.String(), { default: ["GET", "PATCH"] })
methods: Type.Array(Type.String(), { default: ["GET", "PATCH"] }),
}),
undefined,
{
@@ -155,8 +155,8 @@ describe("SchemaObject", async () => {
called = true;
to.methods.push("OPTIONS");
return to;
}
}
},
},
);
const result = await m.set({ methods: ["GET", "POST"] });
@@ -168,7 +168,7 @@ describe("SchemaObject", async () => {
test("throwIfRestricted", async () => {
const m = new SchemaObject(Type.Object({}), undefined, {
restrictPaths: ["a.b"]
restrictPaths: ["a.b"],
});
expect(() => m.throwIfRestricted("a.b")).toThrow();
@@ -185,18 +185,18 @@ describe("SchemaObject", async () => {
a: Type.String({ default: "b" }),
b: Type.Object(
{
c: Type.String({ default: "d" })
c: Type.String({ default: "d" }),
},
{ default: {} }
)
{ default: {} },
),
},
{ default: {} }
)
{ default: {} },
),
}),
undefined,
{
restrictPaths: ["s.b"]
}
restrictPaths: ["s.b"],
},
);
expect(m.patch("s.b.c", "e")).rejects.toThrow();
@@ -217,33 +217,33 @@ describe("SchemaObject", async () => {
additionalProperties: Type.Object({
type: Type.String(),
config: Type.Optional(
Type.Object({}, { additionalProperties: Type.String() })
)
})
}
Type.Object({}, { additionalProperties: Type.String() }),
),
}),
},
),
config: Type.Optional(Type.Object({}, { additionalProperties: Type.String() }))
})
}
)
config: Type.Optional(Type.Object({}, { additionalProperties: Type.String() })),
}),
},
),
},
{
additionalProperties: false
}
additionalProperties: false,
},
);
test("patch safe object, overwrite", async () => {
const data = {
entities: {
some: {
fields: {
a: { type: "string", config: { some: "thing" } }
}
}
}
a: { type: "string", config: { some: "thing" } },
},
},
},
};
const m = new SchemaObject(dataEntitiesSchema, data, {
forceParse: true,
overwritePaths: [/^entities\..*\.fields\..*\.config/]
overwritePaths: [/^entities\..*\.fields\..*\.config/],
});
await m.patch("entities.some.fields.a", { type: "string", config: { another: "one" } });
@@ -252,10 +252,10 @@ describe("SchemaObject", async () => {
entities: {
some: {
fields: {
a: { type: "string", config: { another: "one" } }
}
}
}
a: { type: "string", config: { another: "one" } },
},
},
},
});
});
@@ -265,22 +265,22 @@ describe("SchemaObject", async () => {
users: {
fields: {
email: { type: "string" },
password: { type: "string" }
}
}
}
password: { type: "string" },
},
},
},
};
const m = new SchemaObject(dataEntitiesSchema, data, {
forceParse: true,
overwritePaths: [/^entities\..*\.fields\..*\.config\.html_config$/]
overwritePaths: [/^entities\..*\.fields\..*\.config\.html_config$/],
});
await m.patch("entities.test", {
fields: {
content: {
type: "text"
}
}
type: "text",
},
},
});
expect(m.get()).toEqual({
@@ -288,17 +288,17 @@ describe("SchemaObject", async () => {
users: {
fields: {
email: { type: "string" },
password: { type: "string" }
}
password: { type: "string" },
},
},
test: {
fields: {
content: {
type: "text"
}
}
}
}
type: "text",
},
},
},
},
});
});
@@ -308,14 +308,14 @@ describe("SchemaObject", async () => {
users: {
fields: {
email: { type: "string" },
password: { type: "string" }
}
}
}
password: { type: "string" },
},
},
},
};
const m = new SchemaObject(dataEntitiesSchema, data, {
forceParse: true,
overwritePaths: [/^entities\..*\.fields\..*\.config\.html_config$/]
overwritePaths: [/^entities\..*\.fields\..*\.config\.html_config$/],
});
expect(m.patch("desc", "entities.users.config.sort_dir")).rejects.toThrow();
@@ -323,13 +323,13 @@ describe("SchemaObject", async () => {
await m.patch("entities.test", {
fields: {
content: {
type: "text"
}
}
type: "text",
},
},
});
await m.patch("entities.users.config", {
sort_dir: "desc"
sort_dir: "desc",
});
expect(m.get()).toEqual({
@@ -337,20 +337,20 @@ describe("SchemaObject", async () => {
users: {
fields: {
email: { type: "string" },
password: { type: "string" }
password: { type: "string" },
},
config: {
sort_dir: "desc"
}
sort_dir: "desc",
},
},
test: {
fields: {
content: {
type: "text"
}
}
}
}
type: "text",
},
},
},
},
});
});
});

View File

@@ -13,8 +13,8 @@ describe("diff", () => {
t: "a",
p: ["b"],
o: undefined,
n: 2
}
n: 2,
},
]);
const appliedObj = apply(oldObj, diffs);
@@ -35,8 +35,8 @@ describe("diff", () => {
t: "r",
p: ["b"],
o: 2,
n: undefined
}
n: undefined,
},
]);
const appliedObj = apply(oldObj, diffs);
@@ -57,8 +57,8 @@ describe("diff", () => {
t: "e",
p: ["a"],
o: 1,
n: 2
}
n: 2,
},
]);
const appliedObj = apply(oldObj, diffs);
@@ -79,8 +79,8 @@ describe("diff", () => {
t: "e",
p: ["a", "b"],
o: 1,
n: 2
}
n: 2,
},
]);
const appliedObj = apply(oldObj, diffs);
@@ -101,14 +101,14 @@ describe("diff", () => {
t: "e",
p: ["a", 1],
o: 2,
n: 4
n: 4,
},
{
t: "a",
p: ["a", 3],
o: undefined,
n: 5
}
n: 5,
},
]);
const appliedObj = apply(oldObj, diffs);
@@ -129,20 +129,20 @@ describe("diff", () => {
t: "a",
p: ["a", 0],
o: undefined,
n: 1
n: 1,
},
{
t: "a",
p: ["a", 1],
o: undefined,
n: 2
n: 2,
},
{
t: "a",
p: ["a", 2],
o: undefined,
n: 3
}
n: 3,
},
]);
const appliedObj = apply(oldObj, diffs);
@@ -163,14 +163,14 @@ describe("diff", () => {
t: "e",
p: ["a", 1],
o: 2,
n: 3
n: 3,
},
{
t: "r",
p: ["a", 2],
o: 3,
n: undefined
}
n: undefined,
},
]);
const appliedObj = apply(oldObj, diffs);
@@ -183,14 +183,14 @@ describe("diff", () => {
it("should handle complex nested changes", () => {
const oldObj = {
a: {
b: [1, 2, { c: 3 }]
}
b: [1, 2, { c: 3 }],
},
};
const newObj = {
a: {
b: [1, 2, { c: 4 }, 5]
}
b: [1, 2, { c: 4 }, 5],
},
};
const diffs = diff(oldObj, newObj);
@@ -200,14 +200,14 @@ describe("diff", () => {
t: "e",
p: ["a", "b", 2, "c"],
o: 3,
n: 4
n: 4,
},
{
t: "a",
p: ["a", "b", 3],
o: undefined,
n: 5
}
n: 5,
},
]);
const appliedObj = apply(oldObj, diffs);
@@ -228,14 +228,14 @@ describe("diff", () => {
t: "e",
p: ["a"],
o: undefined,
n: null
n: null,
},
{
t: "e",
p: ["b"],
o: null,
n: undefined
}
n: undefined,
},
]);
const appliedObj = apply(oldObj, diffs);
@@ -256,8 +256,8 @@ describe("diff", () => {
t: "e",
p: ["a"],
o: 1,
n: "1"
}
n: "1",
},
]);
const appliedObj = apply(oldObj, diffs);
@@ -278,14 +278,14 @@ describe("diff", () => {
t: "r",
p: ["b"],
o: 2,
n: undefined
n: undefined,
},
{
t: "a",
p: ["c"],
o: undefined,
n: 3
}
n: 3,
},
]);
const appliedObj = apply(oldObj, diffs);
@@ -306,8 +306,8 @@ describe("diff", () => {
t: "e",
p: ["a"],
o: [1, 2, 3],
n: { b: 4 }
}
n: { b: 4 },
},
]);
const appliedObj = apply(oldObj, diffs);
@@ -328,8 +328,8 @@ describe("diff", () => {
t: "e",
p: ["a"],
o: { b: 1 },
n: 2
}
n: 2,
},
]);
const appliedObj = apply(oldObj, diffs);
@@ -350,14 +350,14 @@ describe("diff", () => {
t: "r",
p: ["a"],
o: 1,
n: undefined
n: undefined,
},
{
t: "a",
p: ["b"],
o: undefined,
n: 2
}
n: 2,
},
]);
const appliedObj = apply(oldObj, diffs);
@@ -408,8 +408,8 @@ describe("diff", () => {
t: "a",
p: ["a"],
o: undefined,
n: 1
}
n: 1,
},
]);
const appliedObj = apply(oldObj, diffs);
@@ -430,8 +430,8 @@ describe("diff", () => {
t: "r",
p: ["a"],
o: 1,
n: undefined
}
n: undefined,
},
]);
const appliedObj = apply(oldObj, diffs);

View File

@@ -9,7 +9,7 @@ describe("object-query", () => {
test("validates", async () => {
const converted = convert({
name: { $eq: "ch" }
name: { $eq: "ch" },
});
validate(converted, { name: "Michael" });
});
@@ -31,7 +31,7 @@ describe("object-query", () => {
[{ val: { $notnull: 1 } }, { val: null }, false],
[{ val: { $regex: ".*" } }, { val: "test" }, true],
[{ val: { $regex: /^t.*/ } }, { val: "test" }, true],
[{ val: { $regex: /^b.*/ } }, { val: "test" }, false]
[{ val: { $regex: /^b.*/ } }, { val: "test" }, false],
];
for (const [query, object, expected] of tests) {
@@ -55,10 +55,10 @@ describe("object-query", () => {
[
{ $or: { val1: { $eq: "foo" }, val2: { $eq: "bar" } } },
{ val1: "foo", val2: "bar" },
true
true,
],
[{ val1: { $eq: 1 }, $or: { val1: { $eq: 2 } } }, { val1: 1 }, true],
[{ val1: { $eq: 1 }, $or: { val1: { $eq: 2 } } }, { val1: 3 }, false]
[{ val1: { $eq: 1 }, $or: { val1: { $eq: 2 } } }, { val1: 3 }, false],
];
for (const [query, object, expected] of tests) {