Skip to content

Commit 0ea6716

Browse files
chore: add changeset and format
1 parent 97db041 commit 0ea6716

3 files changed

Lines changed: 8 additions & 7 deletions

File tree

.changeset/dull-eels-dance.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"monarch-orm": patch
3+
---
4+
5+
Fix update operators `$addToSet` and `$setOnInsert` failing schema validation when parsing data.

src/schema/update.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
MonarchNullable,
1212
MonarchNumber,
1313
MonarchOptional,
14-
MonarchObject,
1514
MonarchType,
1615
type AnyMonarchType,
1716
} from "../types";
@@ -93,10 +92,7 @@ export function updateParser<T extends AnyMonarchType>(
9392
return input;
9493
}
9594

96-
function unwrapTo<T extends new (...args: any) => AnyMonarchType>(
97-
type: AnyMonarchType,
98-
target: T
99-
): InstanceType<T> {
95+
function unwrapTo<T extends new (...args: any) => AnyMonarchType>(type: AnyMonarchType, target: T): InstanceType<T> {
10096
let unwrapped: any = type;
10197
while (!(unwrapped instanceof target)) {
10298
if (unwrapped instanceof MonarchDefaulted) unwrapped = MonarchDefaulted.type(unwrapped);
@@ -151,7 +147,7 @@ function parseArrayOperator(
151147
const elementType = MonarchArray.type(arrayType);
152148
const parser = MonarchType.parser(elementType, path);
153149
if (typeof value === "object" && value !== null && "$each" in value) {
154-
const ops = value as { $each: unknown[];[k: string]: unknown };
150+
const ops = value as { $each: unknown[]; [k: string]: unknown };
155151
parsed[path] = { ...ops, $each: ops.$each.map(parser) };
156152
} else {
157153
parsed[path] = parser(value);

tests/query/update.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { afterAll, afterEach, beforeAll, describe, expect, it, vi } from "vitest";
22
import { createDatabase, createSchema, defineSchemas } from "../../src";
3-
import { array, boolean, date, literal, mixed, number, object, string, tuple } from "../../src/types";
3+
import { array, boolean, date, mixed, number, string, tuple } from "../../src/types";
44
import { createMockDatabase, mockUsers } from "../mock";
55

66
describe("Update Operations", async () => {

0 commit comments

Comments
 (0)