2 files changed
+21
No files matched your search
@@ -74,6 +74,7 @@ export function parseMongoDocumentInputValue(raw: MongoInputValue): unknown {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function mongoDocumentDisplayValue(value: unknown): unknown {
|
export function mongoDocumentDisplayValue(value: unknown): unknown {
|
||||||
|
if (value === null) return "NULL";
|
||||||
if (value && typeof value === "object" && !Array.isArray(value)) {
|
if (value && typeof value === "object" && !Array.isArray(value)) {
|
||||||
const object = value as Record<string, unknown>;
|
const object = value as Record<string, unknown>;
|
||||||
if (Object.keys(object).length === 1 && typeof object.$numberLong === "string") return `NumberLong(${JSON.stringify(object.$numberLong)})`;
|
if (Object.keys(object).length === 1 && typeof object.$numberLong === "string") return `NumberLong(${JSON.stringify(object.$numberLong)})`;
|
||||||
|
|||||||
+20
@@ -322,6 +322,8 @@ test("formats other extended JSON values through EJSON.deserialize", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("keeps normal Mongo values readable and unsafe Int64 editable", () => {
|
test("keeps normal Mongo values readable and unsafe Int64 editable", () => {
|
||||||
|
assert.equal(mongoDocumentDisplayValue(null), "NULL");
|
||||||
|
assert.equal(mongoDocumentDisplayValue(undefined), undefined);
|
||||||
assert.equal(mongoDocumentDisplayValue(42), 42);
|
assert.equal(mongoDocumentDisplayValue(42), 42);
|
||||||
assert.equal(mongoDocumentDisplayValue(3.5), 3.5);
|
assert.equal(mongoDocumentDisplayValue(3.5), 3.5);
|
||||||
assert.equal(mongoDocumentDisplayValue('ISODate("2026-07-14T00:00:00Z")'), 'ISODate("2026-07-14T00:00:00Z")');
|
assert.equal(mongoDocumentDisplayValue('ISODate("2026-07-14T00:00:00Z")'), 'ISODate("2026-07-14T00:00:00Z")');
|
||||||
@@ -340,3 +342,21 @@ test("builds edits for Int32, Double, Date, and unsafe Int64", () => {
|
|||||||
$set: { int32: 42, double: 3.5, createdAt: { $date: "2026-07-14T00:00:00Z" }, unsafe: { $numberLong: "9007199254740993" } },
|
$set: { int32: 42, double: 3.5, createdAt: { $date: "2026-07-14T00:00:00Z" }, unsafe: { $numberLong: "9007199254740993" } },
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("keeps explicit Mongo null fields distinct from missing fields during grid edits", () => {
|
||||||
|
const columns = ["_id", "nullable", "missing"];
|
||||||
|
|
||||||
|
assert.deepEqual(buildMongoUpdateDocument(new Map([[1, "NULL"]]), columns, { _id: "1", nullable: null }), {
|
||||||
|
$set: { nullable: null },
|
||||||
|
});
|
||||||
|
assert.deepEqual(buildMongoUpdateDocument(new Map([[1, "NULL"]]), columns, { _id: "1", nullable: "NULL" }), {
|
||||||
|
$set: { nullable: "NULL" },
|
||||||
|
});
|
||||||
|
assert.deepEqual(buildMongoUpdateDocument(new Map([[2, null]]), columns, { _id: "1", nullable: null }), {
|
||||||
|
$unset: { missing: "" },
|
||||||
|
});
|
||||||
|
assert.deepEqual(applyMongoGridChangesToDocument({ _id: "1", nullable: null }, new Map([[1, "NULL"]]), columns), {
|
||||||
|
_id: "1",
|
||||||
|
nullable: null,
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in new issue
Block a user