From 794acbb569754353e63e327e29198289382d9a30 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 29 Jan 2025 18:04:27 +0100 Subject: [PATCH 01/13] Fix iife reference --- packages/server/src/jsRunner/bundles/snippets.ts | 3 +-- packages/string-templates/package.json | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/server/src/jsRunner/bundles/snippets.ts b/packages/server/src/jsRunner/bundles/snippets.ts index 8244b2eef8..343cccd36f 100644 --- a/packages/server/src/jsRunner/bundles/snippets.ts +++ b/packages/server/src/jsRunner/bundles/snippets.ts @@ -1,6 +1,5 @@ // @ts-ignore -// eslint-disable-next-line local-rules/no-budibase-imports -import { iifeWrapper } from "@budibase/string-templates/iife" +import { iifeWrapper } from "@budibase/string-templates" export default new Proxy( {}, diff --git a/packages/string-templates/package.json b/packages/string-templates/package.json index b1b4b9ef55..acd0ea4fa8 100644 --- a/packages/string-templates/package.json +++ b/packages/string-templates/package.json @@ -11,8 +11,7 @@ "require": "./dist/bundle.cjs", "import": "./dist/bundle.mjs" }, - "./package.json": "./package.json", - "./iife": "./dist/iife.mjs" + "./package.json": "./package.json" }, "scripts": { "build": "tsc --emitDeclarationOnly && rollup -c", From 52b504a607eae49e30dbe6e8900ccbb3da1dcf35 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 29 Jan 2025 18:11:39 +0100 Subject: [PATCH 02/13] Add objectId test --- .../api/routes/tests/queries/mongodb.spec.ts | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/packages/server/src/api/routes/tests/queries/mongodb.spec.ts b/packages/server/src/api/routes/tests/queries/mongodb.spec.ts index a37957fe7e..c42227b623 100644 --- a/packages/server/src/api/routes/tests/queries/mongodb.spec.ts +++ b/packages/server/src/api/routes/tests/queries/mongodb.spec.ts @@ -634,6 +634,28 @@ if (descriptions.length) { } }) }) + + it("should be able to select a ObjectId in a transformer", async () => { + const query = await createQuery({ + fields: { + json: {}, + extra: { + actionType: "find", + }, + }, + transformer: "return data.map(x => ({ id: x._id }))", + }) + + const result = await config.api.query.execute(query._id!) + + expect(result.data).toEqual([ + { id: expectValidId }, + { id: expectValidId }, + { id: expectValidId }, + { id: expectValidId }, + { id: expectValidId }, + ]) + }) }) it("should throw an error if the incorrect actionType is specified", async () => { From 11b6547c21de504d1d914f340123b41f10929027 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 29 Jan 2025 20:50:09 +0100 Subject: [PATCH 03/13] Inject polyfills --- .../bundles/bson-polyfills.ivm.bundle.js | 6 ++++ packages/server/src/jsRunner/bundles/index.ts | 2 ++ .../server/src/jsRunner/vm/isolated-vm.ts | 31 +++++++------------ 3 files changed, 19 insertions(+), 20 deletions(-) create mode 100644 packages/server/src/jsRunner/bundles/bson-polyfills.ivm.bundle.js diff --git a/packages/server/src/jsRunner/bundles/bson-polyfills.ivm.bundle.js b/packages/server/src/jsRunner/bundles/bson-polyfills.ivm.bundle.js new file mode 100644 index 0000000000..e8147c63da --- /dev/null +++ b/packages/server/src/jsRunner/bundles/bson-polyfills.ivm.bundle.js @@ -0,0 +1,6 @@ +function atob(...args){ + return atobCB(...args) +} +function btoa(...args){ + return btoaCB(...args) +} diff --git a/packages/server/src/jsRunner/bundles/index.ts b/packages/server/src/jsRunner/bundles/index.ts index b62adac1cc..3a00ee96cc 100644 --- a/packages/server/src/jsRunner/bundles/index.ts +++ b/packages/server/src/jsRunner/bundles/index.ts @@ -5,6 +5,7 @@ export const enum BundleType { BSON = "bson", SNIPPETS = "snippets", BUFFER = "buffer", + BSON_POLYFILLS = "bson_polyfills", } const bundleSourceFile: Record = { @@ -12,6 +13,7 @@ const bundleSourceFile: Record = { [BundleType.BSON]: "./bson.ivm.bundle.js", [BundleType.SNIPPETS]: "./snippets.ivm.bundle.js", [BundleType.BUFFER]: "./buffer.ivm.bundle.js", + [BundleType.BSON_POLYFILLS]: "./bson-polyfills.ivm.bundle.js", } const bundleSourceCode: Partial> = {} diff --git a/packages/server/src/jsRunner/vm/isolated-vm.ts b/packages/server/src/jsRunner/vm/isolated-vm.ts index 3863be742d..65a2615ed7 100644 --- a/packages/server/src/jsRunner/vm/isolated-vm.ts +++ b/packages/server/src/jsRunner/vm/isolated-vm.ts @@ -173,30 +173,21 @@ export class IsolatedVM implements VM { return result } ), + atobCB: new ivm.Callback((...args: Parameters) => { + const result = atob(...args) + return result + }), + btoaCB: new ivm.Callback((...args: Parameters) => { + const result = btoa(...args) + return result + }), }) - // "Polyfilling" text decoder. `bson.deserialize` requires decoding. We are creating a bridge function so we don't need to inject the full library - const textDecoderPolyfill = class TextDecoderMock { - constructorArgs - - constructor(...constructorArgs: any) { - this.constructorArgs = constructorArgs - } - - decode(...input: any) { - // @ts-expect-error - this is going to run in the isolate, where this function will be available - // eslint-disable-next-line no-undef - return textDecoderCb({ - constructorArgs: this.constructorArgs, - functionArgs: input, - }) - } - } - .toString() - .replace(/TextDecoderMock/, "TextDecoder") + // "Polyfilling" text decoder and other utils. `bson.deserialize` requires decoding. We are creating a bridge function so we don't need to inject the full library + const bsonPolyfills = loadBundle(BundleType.BSON_POLYFILLS) const script = this.isolate.compileScriptSync( - `${textDecoderPolyfill};${bsonSource}` + `${bsonPolyfills};${bsonSource}` ) script.runSync(this.vm, { timeout: this.invocationTimeout, release: false }) new Promise(() => { From 9ff29c794e906202550dbce0e4621c02810bfa2c Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 29 Jan 2025 21:01:19 +0100 Subject: [PATCH 04/13] Add TextDecoder polyfill --- .prettierignore | 3 ++- .../bundles/bson-polyfills.ivm.bundle.js | 23 +++++++++++++++---- .../server/src/jsRunner/vm/isolated-vm.ts | 5 ++-- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/.prettierignore b/.prettierignore index b1ee287391..b0f9f8cdbf 100644 --- a/.prettierignore +++ b/.prettierignore @@ -9,4 +9,5 @@ packages/backend-core/coverage packages/builder/.routify packages/sdk/sdk packages/pro/coverage -**/*.ivm.bundle.js \ No newline at end of file +**/*.ivm.bundle.js +!**/bson-polyfills.ivm.bundle.js \ No newline at end of file diff --git a/packages/server/src/jsRunner/bundles/bson-polyfills.ivm.bundle.js b/packages/server/src/jsRunner/bundles/bson-polyfills.ivm.bundle.js index e8147c63da..33a3e9deaa 100644 --- a/packages/server/src/jsRunner/bundles/bson-polyfills.ivm.bundle.js +++ b/packages/server/src/jsRunner/bundles/bson-polyfills.ivm.bundle.js @@ -1,6 +1,21 @@ -function atob(...args){ - return atobCB(...args) +function atob(...args) { + return atobCB(...args) } -function btoa(...args){ - return btoaCB(...args) +function btoa(...args) { + return btoaCB(...args) +} + +class TextDecoder { + constructorArgs + + constructor(...constructorArgs) { + this.constructorArgs = constructorArgs + } + + decode(...input) { + return textDecoderCb({ + constructorArgs: this.constructorArgs, + functionArgs: input, + }) + } } diff --git a/packages/server/src/jsRunner/vm/isolated-vm.ts b/packages/server/src/jsRunner/vm/isolated-vm.ts index 65a2615ed7..4b17d52dba 100644 --- a/packages/server/src/jsRunner/vm/isolated-vm.ts +++ b/packages/server/src/jsRunner/vm/isolated-vm.ts @@ -161,6 +161,8 @@ export class IsolatedVM implements VM { const bsonSource = loadBundle(BundleType.BSON) + // "Polyfilling" text decoder and other utils. `bson.deserialize` requires decoding. We are creating a bridge function so we don't need to inject the full library + const bsonPolyfills = loadBundle(BundleType.BSON_POLYFILLS) this.addToContext({ textDecoderCb: new ivm.Callback( (args: { @@ -183,9 +185,6 @@ export class IsolatedVM implements VM { }), }) - // "Polyfilling" text decoder and other utils. `bson.deserialize` requires decoding. We are creating a bridge function so we don't need to inject the full library - const bsonPolyfills = loadBundle(BundleType.BSON_POLYFILLS) - const script = this.isolate.compileScriptSync( `${bsonPolyfills};${bsonSource}` ) From 148924f82123b9a20fe28dde1327124b3eb1e5b3 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 30 Jan 2025 08:47:18 +0100 Subject: [PATCH 05/13] Use polyfills directly --- .../bundles/bson-polyfills.ivm.bundle.js | 83 +++++++++++++++++-- 1 file changed, 78 insertions(+), 5 deletions(-) diff --git a/packages/server/src/jsRunner/bundles/bson-polyfills.ivm.bundle.js b/packages/server/src/jsRunner/bundles/bson-polyfills.ivm.bundle.js index 33a3e9deaa..e7949042c8 100644 --- a/packages/server/src/jsRunner/bundles/bson-polyfills.ivm.bundle.js +++ b/packages/server/src/jsRunner/bundles/bson-polyfills.ivm.bundle.js @@ -1,8 +1,81 @@ -function atob(...args) { - return atobCB(...args) -} -function btoa(...args) { - return btoaCB(...args) +if (typeof btoa !== "function") { + var chars = { + ascii: function () { + return "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=" + }, + indices: function () { + if (!this.cache) { + this.cache = {} + var ascii = chars.ascii() + + for (var c = 0; c < ascii.length; c++) { + var chr = ascii[c] + this.cache[chr] = c + } + } + return this.cache + }, + } + + function atob(b64) { + var indices = chars.indices(), + pos = b64.indexOf("="), + padded = pos > -1, + len = padded ? pos : b64.length, + i = -1, + data = "" + + while (i < len) { + var code = + (indices[b64[++i]] << 18) | + (indices[b64[++i]] << 12) | + (indices[b64[++i]] << 6) | + indices[b64[++i]] + if (code !== 0) { + data += String.fromCharCode( + (code >>> 16) & 255, + (code >>> 8) & 255, + code & 255 + ) + } + } + + if (padded) { + data = data.slice(0, pos - b64.length) + } + + return data + } + + function btoa(data) { + var ascii = chars.ascii(), + len = data.length - 1, + i = -1, + b64 = "" + + while (i < len) { + var code = + (data.charCodeAt(++i) << 16) | + (data.charCodeAt(++i) << 8) | + data.charCodeAt(++i) + b64 += + ascii[(code >>> 18) & 63] + + ascii[(code >>> 12) & 63] + + ascii[(code >>> 6) & 63] + + ascii[code & 63] + } + + var pads = data.length % 3 + if (pads > 0) { + b64 = b64.slice(0, pads - 3) + + while (b64.length % 4 !== 0) { + b64 += "=" + } + } + + return b64 + } } class TextDecoder { From 7fdb22459ae9b2b015e35ecbbf2d341ea795e571 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 30 Jan 2025 08:47:24 +0100 Subject: [PATCH 06/13] Use polyfills directly --- packages/server/src/jsRunner/vm/isolated-vm.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/packages/server/src/jsRunner/vm/isolated-vm.ts b/packages/server/src/jsRunner/vm/isolated-vm.ts index 4b17d52dba..3123bcaa44 100644 --- a/packages/server/src/jsRunner/vm/isolated-vm.ts +++ b/packages/server/src/jsRunner/vm/isolated-vm.ts @@ -175,14 +175,6 @@ export class IsolatedVM implements VM { return result } ), - atobCB: new ivm.Callback((...args: Parameters) => { - const result = atob(...args) - return result - }), - btoaCB: new ivm.Callback((...args: Parameters) => { - const result = btoa(...args) - return result - }), }) const script = this.isolate.compileScriptSync( From cfe296bcc904c589a28a8bd918279ef60ab5357c Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 30 Jan 2025 10:55:57 +0100 Subject: [PATCH 07/13] Add polyfills --- .../bundles/bson-polyfills.ivm.bundle.js | 52 ++++++++++++++----- .../server/src/jsRunner/vm/isolated-vm.ts | 14 ----- 2 files changed, 40 insertions(+), 26 deletions(-) diff --git a/packages/server/src/jsRunner/bundles/bson-polyfills.ivm.bundle.js b/packages/server/src/jsRunner/bundles/bson-polyfills.ivm.bundle.js index e7949042c8..94d08b84ed 100644 --- a/packages/server/src/jsRunner/bundles/bson-polyfills.ivm.bundle.js +++ b/packages/server/src/jsRunner/bundles/bson-polyfills.ivm.bundle.js @@ -78,17 +78,45 @@ if (typeof btoa !== "function") { } } -class TextDecoder { - constructorArgs - - constructor(...constructorArgs) { - this.constructorArgs = constructorArgs - } - - decode(...input) { - return textDecoderCb({ - constructorArgs: this.constructorArgs, - functionArgs: input, - }) +if (typeof TextDecoder === "undefined") { + globalThis.TextDecoder = class { + constructor(encoding = "utf8") { + if (encoding !== "utf8") { + throw new Error( + `Only UTF-8 is supported in this polyfill. Recieved: ${encoding}` + ) + } + } + decode(buffer) { + return String.fromCharCode(...buffer) + } + } +} + +if (typeof TextEncoder === "undefined") { + globalThis.TextEncoder = class { + encode(str) { + const utf8 = [] + for (const i = 0; i < str.length; i++) { + const codePoint = str.charCodeAt(i) + + if (codePoint < 0x80) { + utf8.push(codePoint) + } else if (codePoint < 0x800) { + utf8.push(0xc0 | (codePoint >> 6)) + utf8.push(0x80 | (codePoint & 0x3f)) + } else if (codePoint < 0x10000) { + utf8.push(0xe0 | (codePoint >> 12)) + utf8.push(0x80 | ((codePoint >> 6) & 0x3f)) + utf8.push(0x80 | (codePoint & 0x3f)) + } else { + utf8.push(0xf0 | (codePoint >> 18)) + utf8.push(0x80 | ((codePoint >> 12) & 0x3f)) + utf8.push(0x80 | ((codePoint >> 6) & 0x3f)) + utf8.push(0x80 | (codePoint & 0x3f)) + } + } + return new Uint8Array(utf8) + } } } diff --git a/packages/server/src/jsRunner/vm/isolated-vm.ts b/packages/server/src/jsRunner/vm/isolated-vm.ts index 3123bcaa44..37ee048dc2 100644 --- a/packages/server/src/jsRunner/vm/isolated-vm.ts +++ b/packages/server/src/jsRunner/vm/isolated-vm.ts @@ -161,21 +161,7 @@ export class IsolatedVM implements VM { const bsonSource = loadBundle(BundleType.BSON) - // "Polyfilling" text decoder and other utils. `bson.deserialize` requires decoding. We are creating a bridge function so we don't need to inject the full library const bsonPolyfills = loadBundle(BundleType.BSON_POLYFILLS) - this.addToContext({ - textDecoderCb: new ivm.Callback( - (args: { - constructorArgs: any - functionArgs: Parameters["decode"]> - }) => { - const result = new TextDecoder(...args.constructorArgs).decode( - ...args.functionArgs - ) - return result - } - ), - }) const script = this.isolate.compileScriptSync( `${bsonPolyfills};${bsonSource}` From 42eefddd5cc6b3a877368f59556cf24070c3478f Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 30 Jan 2025 11:26:05 +0100 Subject: [PATCH 08/13] Add tests --- .../api/routes/tests/queries/mongodb.spec.ts | 116 ++++++++++++++++++ 1 file changed, 116 insertions(+) diff --git a/packages/server/src/api/routes/tests/queries/mongodb.spec.ts b/packages/server/src/api/routes/tests/queries/mongodb.spec.ts index c42227b623..065efc95ae 100644 --- a/packages/server/src/api/routes/tests/queries/mongodb.spec.ts +++ b/packages/server/src/api/routes/tests/queries/mongodb.spec.ts @@ -656,6 +656,122 @@ if (descriptions.length) { { id: expectValidId }, ]) }) + + it("can handle all bson field types", async () => { + collection = generator.guid() + await withCollection(async collection => { + await collection.insertOne({ + _id: new BSON.ObjectId("65b0123456789abcdef01234"), + stringField: "This is a string", + numberField: 42, + doubleField: new BSON.Double(42.42), + integerField: new BSON.Int32(123), + longField: new BSON.Long("9223372036854775807"), + booleanField: true, + nullField: null, + arrayField: [1, 2, 3, "four", { nested: true }], + objectField: { + nestedString: "nested", + nestedNumber: 99, + }, + dateField: { $date: "2025-01-30T12:00:00Z" }, + // timestampField: new BSON.Timestamp({ t: 1706616000, i: 1 }), + binaryField: new BSON.Binary( + new TextEncoder().encode("bufferValue") + ), + objectIdField: new BSON.ObjectId("65b0123456789abcdef01235"), + regexField: new BSON.BSONRegExp("^Hello.*", "i"), + minKeyField: new BSON.MinKey(), + maxKeyField: new BSON.MaxKey(), + decimalField: new BSON.Decimal128("12345.6789"), + codeField: new BSON.Code( + "function() { return 'Hello, World!'; }" + ), + codeWithScopeField: new BSON.Code( + "function(x) { return x * 2; }", + { x: 10 } + ), + }) + }) + + const query = await createQuery({ + fields: { + json: {}, + extra: { + actionType: "find", + collection, + }, + }, + transformer: "return data.map(x => ({ ...x }))", + }) + + const result = await config.api.query.execute(query._id!) + + expect(result.data).toEqual([ + { + _id: "65b0123456789abcdef01234", + arrayField: [ + 1, + 2, + 3, + "four", + { + nested: true, + }, + ], + binaryField: "YnVmZmVyVmFsdWU=", + booleanField: true, + codeField: { + code: "function() { return 'Hello, World!'; }", + }, + codeWithScopeField: { + code: "function(x) { return x * 2; }", + scope: { + x: 10, + }, + }, + dateField: "2025-01-30T12:00:00.000Z", + decimalField: { + bytes: { + "0": 21, + "1": 205, + "10": 0, + "11": 0, + "12": 0, + "13": 0, + "14": 56, + "15": 48, + "2": 91, + "3": 7, + "4": 0, + "5": 0, + "6": 0, + "7": 0, + "8": 0, + "9": 0, + }, + }, + doubleField: 42.42, + integerField: 123, + longField: { + high: 2147483647, + low: -1, + unsigned: false, + }, + maxKeyField: {}, + minKeyField: {}, + nullField: null, + numberField: 42, + objectField: { + nestedNumber: 99, + nestedString: "nested", + }, + objectIdField: "65b0123456789abcdef01235", + regexField: {}, + stringField: "This is a string", + }, + ]) + }) }) it("should throw an error if the incorrect actionType is specified", async () => { From cfba775636be13d97f8c2e7676e0dcc29e85a325 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 30 Jan 2025 11:33:58 +0100 Subject: [PATCH 09/13] Check types --- .../api/routes/tests/queries/mongodb.spec.ts | 40 +++++-------------- 1 file changed, 11 insertions(+), 29 deletions(-) diff --git a/packages/server/src/api/routes/tests/queries/mongodb.spec.ts b/packages/server/src/api/routes/tests/queries/mongodb.spec.ts index 065efc95ae..c8c12acbf9 100644 --- a/packages/server/src/api/routes/tests/queries/mongodb.spec.ts +++ b/packages/server/src/api/routes/tests/queries/mongodb.spec.ts @@ -674,7 +674,7 @@ if (descriptions.length) { nestedString: "nested", nestedNumber: 99, }, - dateField: { $date: "2025-01-30T12:00:00Z" }, + dateField: new Date(Date.UTC(2025, 0, 30, 12, 30, 20)), // timestampField: new BSON.Timestamp({ t: 1706616000, i: 1 }), binaryField: new BSON.Binary( new TextEncoder().encode("bufferValue") @@ -702,7 +702,12 @@ if (descriptions.length) { collection, }, }, - transformer: "return data.map(x => ({ ...x }))", + transformer: `return data.map(x => ({ + ...x, + binaryField: x.binaryField?.toString('utf8'), + decimalField: x.decimalField.toString(), + longField: x.longField.toString() + }))`, }) const result = await config.api.query.execute(query._id!) @@ -719,7 +724,7 @@ if (descriptions.length) { nested: true, }, ], - binaryField: "YnVmZmVyVmFsdWU=", + binaryField: "bufferValue", booleanField: true, codeField: { code: "function() { return 'Hello, World!'; }", @@ -730,34 +735,11 @@ if (descriptions.length) { x: 10, }, }, - dateField: "2025-01-30T12:00:00.000Z", - decimalField: { - bytes: { - "0": 21, - "1": 205, - "10": 0, - "11": 0, - "12": 0, - "13": 0, - "14": 56, - "15": 48, - "2": 91, - "3": 7, - "4": 0, - "5": 0, - "6": 0, - "7": 0, - "8": 0, - "9": 0, - }, - }, + dateField: "2025-01-30T12:30:20.000Z", + decimalField: "12345.6789", doubleField: 42.42, integerField: 123, - longField: { - high: 2147483647, - low: -1, - unsigned: false, - }, + longField: "9223372036854775807", maxKeyField: {}, minKeyField: {}, nullField: null, From 49d50e053fdc8994cddbced63c192c39bb646c40 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 30 Jan 2025 11:38:04 +0100 Subject: [PATCH 10/13] Check types --- packages/server/src/api/routes/tests/queries/mongodb.spec.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/server/src/api/routes/tests/queries/mongodb.spec.ts b/packages/server/src/api/routes/tests/queries/mongodb.spec.ts index c8c12acbf9..63280f85c1 100644 --- a/packages/server/src/api/routes/tests/queries/mongodb.spec.ts +++ b/packages/server/src/api/routes/tests/queries/mongodb.spec.ts @@ -706,7 +706,8 @@ if (descriptions.length) { ...x, binaryField: x.binaryField?.toString('utf8'), decimalField: x.decimalField.toString(), - longField: x.longField.toString() + longField: x.longField.toString(), + regexField: x.regexField.toString() }))`, }) @@ -749,7 +750,7 @@ if (descriptions.length) { nestedString: "nested", }, objectIdField: "65b0123456789abcdef01235", - regexField: {}, + regexField: "/^Hello.*/i", stringField: "This is a string", }, ]) From 5d6088104d71570e58fdd299bbaa50b8de602d8b Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 30 Jan 2025 12:06:01 +0100 Subject: [PATCH 11/13] Improve tests --- .../server/src/api/routes/tests/queries/mongodb.spec.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/server/src/api/routes/tests/queries/mongodb.spec.ts b/packages/server/src/api/routes/tests/queries/mongodb.spec.ts index 63280f85c1..d74db5a7d3 100644 --- a/packages/server/src/api/routes/tests/queries/mongodb.spec.ts +++ b/packages/server/src/api/routes/tests/queries/mongodb.spec.ts @@ -675,7 +675,7 @@ if (descriptions.length) { nestedNumber: 99, }, dateField: new Date(Date.UTC(2025, 0, 30, 12, 30, 20)), - // timestampField: new BSON.Timestamp({ t: 1706616000, i: 1 }), + timestampField: new BSON.Timestamp({ t: 1706616000, i: 1 }), binaryField: new BSON.Binary( new TextEncoder().encode("bufferValue") ), @@ -707,7 +707,9 @@ if (descriptions.length) { binaryField: x.binaryField?.toString('utf8'), decimalField: x.decimalField.toString(), longField: x.longField.toString(), - regexField: x.regexField.toString() + regexField: x.regexField.toString(), + // TODO: currenlty not supported, it looks like there is bug in the library. Getting: Timestamp constructed from { t, i } must provide t as a number + timestampField: null }))`, }) From 79405dd3429f2368fedc745de142fd551e96d542 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 30 Jan 2025 12:06:17 +0100 Subject: [PATCH 12/13] Fix test --- packages/server/src/api/routes/tests/queries/mongodb.spec.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/server/src/api/routes/tests/queries/mongodb.spec.ts b/packages/server/src/api/routes/tests/queries/mongodb.spec.ts index d74db5a7d3..9c4502d192 100644 --- a/packages/server/src/api/routes/tests/queries/mongodb.spec.ts +++ b/packages/server/src/api/routes/tests/queries/mongodb.spec.ts @@ -754,6 +754,7 @@ if (descriptions.length) { objectIdField: "65b0123456789abcdef01235", regexField: "/^Hello.*/i", stringField: "This is a string", + timestampField: null, }, ]) }) From 768522b41055a87fb1abf2b0d36c48f142a73dcf Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 30 Jan 2025 12:12:28 +0100 Subject: [PATCH 13/13] Rename --- packages/server/src/api/routes/tests/queries/mongodb.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/server/src/api/routes/tests/queries/mongodb.spec.ts b/packages/server/src/api/routes/tests/queries/mongodb.spec.ts index 9c4502d192..37af4e74e1 100644 --- a/packages/server/src/api/routes/tests/queries/mongodb.spec.ts +++ b/packages/server/src/api/routes/tests/queries/mongodb.spec.ts @@ -657,7 +657,7 @@ if (descriptions.length) { ]) }) - it("can handle all bson field types", async () => { + it("can handle all bson field types with transformers", async () => { collection = generator.guid() await withCollection(async collection => { await collection.insertOne({