From c1a582c054a04553ed9c32e974502b8ac4ee56f9 Mon Sep 17 00:00:00 2001 From: Taylor Cannon Date: Wed, 12 Nov 2025 11:00:09 -0600 Subject: [PATCH 1/5] STREAMS-1982: Add singleton compat for MinKey --- snippets/mongocompat/mongotypes.js | 35 ++++++++++++++++++++++++++++++ snippets/mongocompat/test.js | 14 +++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/snippets/mongocompat/mongotypes.js b/snippets/mongocompat/mongotypes.js index 76c84f4..e9426c3 100644 --- a/snippets/mongocompat/mongotypes.js +++ b/snippets/mongocompat/mongotypes.js @@ -714,6 +714,41 @@ if (typeof (gc) == "undefined") { }; } +// MinKey +if (typeof (MinKey) != "undefined") { + const OriginalMinKey = MinKey; + MinKey = function () { + if (MinKey.prototype.__instance__ === undefined) { + MinKey.prototype.__instance__ = new OriginalMinKey(); + } + + return MinKey.prototype.__instance__; + }; + + MinKey.prototype = OriginalMinKey.prototype; + + for (const key of Object.getOwnPropertyNames(OriginalMinKey)) { + // Skip prototype, length, name(function internals) + if (key !== 'prototype' && key !== 'length' && key !== 'name') { + MinKey[key] = OriginalMinKey[key]; + } + } + + MinKey.prototype.toJSON = function () { + return this.tojson(); + }; + + MinKey.prototype.tojson = function () { + return "{ \"$minKey\" : 1 }"; + }; + + MinKey.prototype.toString = function () { + return "[object Function]"; + }; +} else { + print("warning: no MinKey class"); +} + // Free Functions tojsononeline = function(x) { return tojson(x, " ", true); diff --git a/snippets/mongocompat/test.js b/snippets/mongocompat/test.js index 5710255..45a8d77 100644 --- a/snippets/mongocompat/test.js +++ b/snippets/mongocompat/test.js @@ -87,7 +87,7 @@ const tsFromStr = Timestamp.fromString('ff', 16); assert.strictEqual(tsFromStr.i, 255); assert.strictEqual(tsFromStr.t, 0); assert.strictEqual(Timestamp.MAX_VALUE._bsontype, 'Long'); -assert.strictEqual(Timestamp.MAX_VALUE, Long.MAX_UNSIGNED_VALUE); +assert.strictEqual(Timestamp.MAX_VALUE, Long.MAX_UNSIGNED_VALUE); const id = ObjectId('68ffa28b77bba38c9ddcf376'); const dbRef = DBRef('testColl', id, 'testDb'); @@ -161,3 +161,15 @@ assert(sortedArrayJson.indexOf('"a"') < sortedArrayJson.indexOf('"z"'), 'Array.t assert(sortedArrayJson.indexOf('"b"') < sortedArrayJson.indexOf('"y"'), 'Array.tojson with sortedKeys=true should sort object keys in array elements'); assert(unsortedArrayJson.indexOf('"z"') < unsortedArrayJson.indexOf('"a"'), 'Array.tojson with sortedKeys=false should not sort keys'); assert(defaultArrayJson.indexOf('"z"') < defaultArrayJson.indexOf('"a"'), 'Array.tojson without sortedKeys should not sort keys'); + +// Test MinKey +const minKey = new MinKey(); +assert(minKey instanceof MinKey, "minKey should be an instance of MinKey"); +assert.strictEqual(minKey.tojson(), '{ "$minKey" : 1 }', "minKey should serialize correctly"); +assert.strictEqual(minKey.toString(), "[object Function]", "minKey toString should work"); +assert.strictEqual(minKey.toJSON(), '{ "$minKey" : 1 }', "minKey toJSON should work"); + +// Test that multiple references return the same instance +const anotherMinKeyRef = new MinKey(); +assert.strictEqual(minKey, anotherMinKeyRef, "minKey should be a singleton - v1"); +assert.strictEqual(MinKey(), MinKey(), "minKey should be a singleton - v2"); From 1c01dab6356455d79c0e31657f71b52cdd9c9e7a Mon Sep 17 00:00:00 2001 From: Taylor Aron Cannon Date: Tue, 18 Nov 2025 11:09:35 -0600 Subject: [PATCH 2/5] add zed editor to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index c59e017..713b764 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ .lock-wscript .idea/ .vscode/ +.zed/ *.iml .npmrc .nvmrc From b9e5a855a64323317a410053882a08a7679b6340 Mon Sep 17 00:00:00 2001 From: Taylor Aron Cannon Date: Tue, 18 Nov 2025 11:57:11 -0600 Subject: [PATCH 3/5] remove zed from gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 713b764..c59e017 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,6 @@ .lock-wscript .idea/ .vscode/ -.zed/ *.iml .npmrc .nvmrc From df43365b23394c556aee2ca1f37446aa361fed8e Mon Sep 17 00:00:00 2001 From: Taylor Aron Cannon Date: Tue, 18 Nov 2025 15:17:00 -0600 Subject: [PATCH 4/5] Add test serializing as bson --- snippets/mongocompat/test.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/snippets/mongocompat/test.js b/snippets/mongocompat/test.js index 45a8d77..64d5898 100644 --- a/snippets/mongocompat/test.js +++ b/snippets/mongocompat/test.js @@ -1,5 +1,7 @@ load(__dirname + '/index.js'); +const bson = require('bson'); + assert.strictEqual(ObjectId('0123456789abcdef01234567').tojson(), 'ObjectId("0123456789abcdef01234567")'); assert.strictEqual(BinData(4, 'abcdefgh').toString(), 'BinData(4,"abcdefgh")'); @@ -173,3 +175,7 @@ assert.strictEqual(minKey.toJSON(), '{ "$minKey" : 1 }', "minKey toJSON should w const anotherMinKeyRef = new MinKey(); assert.strictEqual(minKey, anotherMinKeyRef, "minKey should be a singleton - v1"); assert.strictEqual(MinKey(), MinKey(), "minKey should be a singleton - v2"); + +const serializedBsonMinKey = bson.serialize({ key1: MinKey, key2: MinKey() }); +const deserializedBsonMinKey = bson.deserialize(serializedBsonMinKey); +assert.deepStrictEqual(deserializedBsonMinKey.key1, deserializedBsonMinKey.key2, "should be equal after bson serialization"); From fb055b8dcadce3f6e634e1427f02a15bca1a14ca Mon Sep 17 00:00:00 2001 From: Taylor Cannon Date: Tue, 25 Nov 2025 12:47:08 -0600 Subject: [PATCH 5/5] Remove assertion message --- snippets/mongocompat/test.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/snippets/mongocompat/test.js b/snippets/mongocompat/test.js index 64d5898..512ec8a 100644 --- a/snippets/mongocompat/test.js +++ b/snippets/mongocompat/test.js @@ -167,15 +167,15 @@ assert(defaultArrayJson.indexOf('"z"') < defaultArrayJson.indexOf('"a"'), 'Array // Test MinKey const minKey = new MinKey(); assert(minKey instanceof MinKey, "minKey should be an instance of MinKey"); -assert.strictEqual(minKey.tojson(), '{ "$minKey" : 1 }', "minKey should serialize correctly"); -assert.strictEqual(minKey.toString(), "[object Function]", "minKey toString should work"); -assert.strictEqual(minKey.toJSON(), '{ "$minKey" : 1 }', "minKey toJSON should work"); +assert.strictEqual(minKey.tojson(), '{ "$minKey" : 1 }'); +assert.strictEqual(minKey.toString(), "[object Function]"); +assert.strictEqual(minKey.toJSON(), '{ "$minKey" : 1 }'); // Test that multiple references return the same instance const anotherMinKeyRef = new MinKey(); -assert.strictEqual(minKey, anotherMinKeyRef, "minKey should be a singleton - v1"); -assert.strictEqual(MinKey(), MinKey(), "minKey should be a singleton - v2"); +assert.strictEqual(minKey, anotherMinKeyRef); +assert.strictEqual(MinKey(), MinKey()); const serializedBsonMinKey = bson.serialize({ key1: MinKey, key2: MinKey() }); const deserializedBsonMinKey = bson.deserialize(serializedBsonMinKey); -assert.deepStrictEqual(deserializedBsonMinKey.key1, deserializedBsonMinKey.key2, "should be equal after bson serialization"); +assert.deepStrictEqual(deserializedBsonMinKey.key1, deserializedBsonMinKey.key2);