@itwin/core-backend 5.12.0-dev.13 → 5.12.0-dev.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/lib/cjs/ClassRegistry.d.ts.map +1 -1
  2. package/lib/cjs/ClassRegistry.js +1 -2
  3. package/lib/cjs/ClassRegistry.js.map +1 -1
  4. package/lib/cjs/IModelDb.js +1 -1
  5. package/lib/cjs/IModelDb.js.map +1 -1
  6. package/lib/cjs/IpcHost.d.ts +26 -0
  7. package/lib/cjs/IpcHost.d.ts.map +1 -1
  8. package/lib/cjs/IpcHost.js +68 -61
  9. package/lib/cjs/IpcHost.js.map +1 -1
  10. package/lib/cjs/SQLiteDb.d.ts +19 -10
  11. package/lib/cjs/SQLiteDb.d.ts.map +1 -1
  12. package/lib/cjs/SQLiteDb.js +19 -10
  13. package/lib/cjs/SQLiteDb.js.map +1 -1
  14. package/lib/cjs/ViewStore.js +1 -1
  15. package/lib/cjs/ViewStore.js.map +1 -1
  16. package/lib/esm/ClassRegistry.d.ts.map +1 -1
  17. package/lib/esm/ClassRegistry.js +1 -2
  18. package/lib/esm/ClassRegistry.js.map +1 -1
  19. package/lib/esm/IModelDb.js +1 -1
  20. package/lib/esm/IModelDb.js.map +1 -1
  21. package/lib/esm/IpcHost.d.ts +26 -0
  22. package/lib/esm/IpcHost.d.ts.map +1 -1
  23. package/lib/esm/IpcHost.js +70 -63
  24. package/lib/esm/IpcHost.js.map +1 -1
  25. package/lib/esm/SQLiteDb.d.ts +19 -10
  26. package/lib/esm/SQLiteDb.d.ts.map +1 -1
  27. package/lib/esm/SQLiteDb.js +19 -10
  28. package/lib/esm/SQLiteDb.js.map +1 -1
  29. package/lib/esm/ViewStore.js +1 -1
  30. package/lib/esm/ViewStore.js.map +1 -1
  31. package/lib/esm/test/IpcHost.test.js +232 -1
  32. package/lib/esm/test/IpcHost.test.js.map +1 -1
  33. package/lib/esm/test/imodel/IModel.test.js +20 -0
  34. package/lib/esm/test/imodel/IModel.test.js.map +1 -1
  35. package/lib/esm/test/schema/ClassRegistry.test.js +2 -2
  36. package/lib/esm/test/schema/ClassRegistry.test.js.map +1 -1
  37. package/lib/esm/test/standalone/SQLiteDb.test.d.ts.map +1 -1
  38. package/lib/esm/test/standalone/SQLiteDb.test.js +37 -90
  39. package/lib/esm/test/standalone/SQLiteDb.test.js.map +1 -1
  40. package/lib/esm/test/standalone/ViewStoreDb.test.js +30 -0
  41. package/lib/esm/test/standalone/ViewStoreDb.test.js.map +1 -1
  42. package/package.json +14 -14
@@ -1,6 +1,7 @@
1
1
  import * as sinon from "sinon";
2
2
  import { expect } from "chai";
3
- import { BentleyError, IModelStatus } from "@itwin/core-bentley";
3
+ import { BentleyError, IModelStatus, ITwinError } from "@itwin/core-bentley";
4
+ import { serializeIpcError } from "@itwin/core-common";
4
5
  import { IpcHandler, IpcHost } from "../IpcHost";
5
6
  class OuterError extends Error {
6
7
  originalError;
@@ -42,6 +43,10 @@ class MockIpcHandler extends IpcHandler {
42
43
  outer.cause = inner;
43
44
  throw outer;
44
45
  }
46
+ throwBentleyErrorWithNestedBentleyErrorMetaData() {
47
+ const inner = new BentleyError(IModelStatus.BadArg, "inner-bentley-in-metadata", { detail: "inner-value" });
48
+ throw new BentleyError(IModelStatus.BadArg, "bentley-nested-bentley-meta", { nested: inner });
49
+ }
45
50
  throwErrorWithFunctionProperty() {
46
51
  const err = new Error("fn-prop");
47
52
  err.retry = () => { };
@@ -67,6 +72,28 @@ class MockIpcHandler extends IpcHandler {
67
72
  err.items = ["string-value", 42, new Date("2024-01-01"), new URL("https://example.com"), new Error("array-error")];
68
73
  throw err;
69
74
  }
75
+ throwErrorWithNestedArrayProperty() {
76
+ const err = new Error("nested-array");
77
+ err.matrix = [[1, 2], [3, 4]];
78
+ throw err;
79
+ }
80
+ throwBentleyErrorWithMapMetaData() {
81
+ throw new BentleyError(IModelStatus.BadArg, "bentley-map-meta", new Map([["detail", "map-value"]]));
82
+ }
83
+ throwBentleyErrorWithCollidingMapMetaData() {
84
+ // Numeric key `1` and string key `"1"` stringify to the same "1", so they'd collide without disambiguation.
85
+ throw new BentleyError(IModelStatus.BadArg, "bentley-colliding-map-meta", new Map([[1, "num-one"], ["1", "str-one"]]));
86
+ }
87
+ throwBentleyErrorWithSetMetaData() {
88
+ throw new BentleyError(IModelStatus.BadArg, "bentley-set-meta", new Set(["tag1", "tag2"]));
89
+ }
90
+ throwErrorWithSelfReferencingArray() {
91
+ const err = new Error("self-referencing-array");
92
+ const arr = [];
93
+ arr.push(arr); // array that contains itself
94
+ err.items = arr;
95
+ throw err;
96
+ }
70
97
  #privateFunction() { }
71
98
  }
72
99
  describe("IpcHost", () => {
@@ -80,6 +107,10 @@ describe("IpcHost", () => {
80
107
  };
81
108
  await IpcHost.startup({ ipcHost: { socket } });
82
109
  });
110
+ afterEach(() => {
111
+ IpcHost._nextInvokeId = 0;
112
+ IpcHost._pendingInvokes.clear();
113
+ });
83
114
  describe("IpcHandler", () => {
84
115
  let handler;
85
116
  beforeEach(() => {
@@ -213,6 +244,206 @@ describe("IpcHost", () => {
213
244
  expect(error.items[3]).to.be.undefined; // class instance: dropped (→ undefined)
214
245
  expect(error.items[4].message).to.equal("array-error"); // Error: recursed
215
246
  });
247
+ it("should preserve nested arrays (array-of-arrays)", async () => {
248
+ const ipcReturn = await handler(undefined, "throwErrorWithNestedArrayProperty");
249
+ const error = ipcReturn.error;
250
+ expect(error.message).to.equal("nested-array");
251
+ expect(error.matrix).to.deep.equal([[1, 2], [3, 4]]);
252
+ });
253
+ it("should not infinitely recurse on a self-referencing array", async () => {
254
+ const ipcReturn = await handler(undefined, "throwErrorWithSelfReferencingArray");
255
+ const error = ipcReturn.error;
256
+ expect(error.message).to.equal("self-referencing-array");
257
+ expect(error.items[0]).to.be.undefined; // cycle detected: dropped rather than recursing forever
258
+ });
259
+ it("should normalize Map-valued loggingMetadata to a JSON-safe plain object (survives every transport)", async () => {
260
+ const ipcReturn = await handler(undefined, "throwBentleyErrorWithMapMetaData");
261
+ const error = ipcReturn.error;
262
+ expect(error.message).to.equal("bentley-map-meta");
263
+ expect(error.loggingMetadata).to.deep.equal({ detail: "map-value" });
264
+ });
265
+ it("should disambiguate Map-valued loggingMetadata keys that stringify to the same value", async () => {
266
+ const ipcReturn = await handler(undefined, "throwBentleyErrorWithCollidingMapMetaData");
267
+ const error = ipcReturn.error;
268
+ expect(error.message).to.equal("bentley-colliding-map-meta");
269
+ expect(error.loggingMetadata).to.deep.equal({ "1": "num-one", "1#1": "str-one" });
270
+ });
271
+ it("should preserve iTwinErrorId/loggingMetadata of a BentleyError nested inside loggingMetadata", async () => {
272
+ const ipcReturn = await handler(undefined, "throwBentleyErrorWithNestedBentleyErrorMetaData");
273
+ const error = ipcReturn.error;
274
+ expect(error.message).to.equal("bentley-nested-bentley-meta");
275
+ const nested = error.loggingMetadata.nested;
276
+ expect(nested.message).to.equal("inner-bentley-in-metadata");
277
+ expect(nested.iTwinErrorId).to.deep.equal({ scope: BentleyError.iTwinErrorScope, key: nested.iTwinErrorId.key });
278
+ expect(nested.loggingMetadata).to.deep.equal({ detail: "inner-value" });
279
+ });
280
+ it("should normalize Set-valued loggingMetadata to a JSON-safe array (survives every transport)", async () => {
281
+ const ipcReturn = await handler(undefined, "throwBentleyErrorWithSetMetaData");
282
+ const error = ipcReturn.error;
283
+ expect(error.message).to.equal("bentley-set-meta");
284
+ expect(error.loggingMetadata).to.deep.equal(["tag1", "tag2"]);
285
+ });
286
+ });
287
+ describe("IpcHost.invoke", () => {
288
+ /** Simulates the frontend: captures per-request listeners and provides a `respond` helper by call index. */
289
+ function mockFrontend() {
290
+ const listeners = new Map();
291
+ socket.addListener.callsFake((ch, fn) => {
292
+ listeners.set(ch, fn);
293
+ return () => listeners.delete(ch);
294
+ });
295
+ return {
296
+ listeners,
297
+ responseChannel: (callIndex) => socket.send.getCall(callIndex).args[1],
298
+ respond: (callIndex, result) => {
299
+ const responseChannel = socket.send.getCall(callIndex).args[1];
300
+ const listener = listeners.get(responseChannel);
301
+ if (!listener)
302
+ throw new Error(`No listener found for response channel ${responseChannel}`);
303
+ listener(undefined, result);
304
+ },
305
+ };
306
+ }
307
+ it("should resolve with the frontend's response", async () => {
308
+ const frontend = mockFrontend();
309
+ const promise = IpcHost.invoke("ch", "a", "b");
310
+ frontend.respond(0, "hello");
311
+ expect(await promise).to.equal("hello");
312
+ // the pending-invoke entry must be removed so the map does not grow unboundedly
313
+ expect(IpcHost._pendingInvokes.size).to.equal(0);
314
+ });
315
+ it("should route concurrent invokes to the correct caller", async () => {
316
+ const frontend = mockFrontend();
317
+ const p1 = IpcHost.invoke("ch");
318
+ const p2 = IpcHost.invoke("ch");
319
+ // respond out of order
320
+ frontend.respond(1, "second");
321
+ frontend.respond(0, "first");
322
+ expect(await p1).to.equal("first");
323
+ expect(await p2).to.equal("second");
324
+ });
325
+ it("should remove the response listener after a response", async () => {
326
+ const frontend = mockFrontend();
327
+ const promise = IpcHost.invoke("ch");
328
+ const responseChannel = frontend.responseChannel(0);
329
+ expect(frontend.listeners.has(responseChannel)).to.be.true;
330
+ frontend.respond(0, "done");
331
+ await promise;
332
+ expect(frontend.listeners.has(responseChannel)).to.be.false;
333
+ });
334
+ it("should reject pending invokes when IpcHost is shut down", async () => {
335
+ const frontend = mockFrontend();
336
+ const promise = IpcHost.invoke("ch");
337
+ const responseChannel = frontend.responseChannel(0);
338
+ // attach handler immediately so the rejection is observed (and not "unhandled")
339
+ const caught = promise.then(() => undefined, (e) => e);
340
+ await IpcHost.shutdown();
341
+ const err = await caught;
342
+ expect(err).to.be.instanceOf(Error);
343
+ expect(err.message).to.contain("shut down");
344
+ // the listener must be cleaned up so it does not leak past shutdown
345
+ expect(frontend.listeners.has(responseChannel)).to.be.false;
346
+ });
347
+ it("should reject all pending invokes when IpcHost is shut down with 2+ concurrent invokes, removing all listeners", async () => {
348
+ const frontend = mockFrontend();
349
+ const p1 = IpcHost.invoke("ch1");
350
+ const p2 = IpcHost.invoke("ch2");
351
+ const responseChannel1 = frontend.responseChannel(0);
352
+ const responseChannel2 = frontend.responseChannel(1);
353
+ // attach handlers immediately so the rejections are observed (and not "unhandled")
354
+ const caught1 = p1.then(() => undefined, (e) => e);
355
+ const caught2 = p2.then(() => undefined, (e) => e);
356
+ expect(IpcHost._pendingInvokes.size).to.equal(2);
357
+ await IpcHost.shutdown();
358
+ const err1 = await caught1;
359
+ const err2 = await caught2;
360
+ expect(err1).to.be.instanceOf(Error);
361
+ expect(err1.message).to.contain("shut down");
362
+ expect(err2).to.be.instanceOf(Error);
363
+ expect(err2.message).to.contain("shut down");
364
+ expect(frontend.listeners.has(responseChannel1)).to.be.false;
365
+ expect(frontend.listeners.has(responseChannel2)).to.be.false;
366
+ expect(IpcHost._pendingInvokes.size).to.equal(0);
367
+ });
368
+ it("should reject and clean up the listener/pending-invoke entry when `send` throws synchronously", async () => {
369
+ const frontend = mockFrontend();
370
+ socket.send.throws(new Error("send failed"));
371
+ const promise = IpcHost.invoke("ch");
372
+ let caught;
373
+ try {
374
+ await promise;
375
+ expect.fail("invoke should have rejected");
376
+ }
377
+ catch (err) {
378
+ caught = err;
379
+ }
380
+ expect(caught).to.be.instanceOf(Error);
381
+ expect(caught.message).to.equal("send failed");
382
+ // the listener and _pendingInvokes entry must not leak when `send` throws synchronously
383
+ expect(frontend.listeners.size).to.equal(0);
384
+ expect(IpcHost._pendingInvokes.size).to.equal(0);
385
+ });
386
+ it("should rethrow a frontend-thrown BentleyError from makeIpcProxy preserving ITwinError identity and metadata", async () => {
387
+ const frontend = mockFrontend();
388
+ const proxy = IpcHost.makeIpcProxy("ch");
389
+ const promise = proxy.doIt();
390
+ // simulate the frontend handler serializing a thrown BentleyError into the invoke-response envelope
391
+ const thrown = new BentleyError(IModelStatus.NotFound, "boom", () => ({ detail: 42 }));
392
+ thrown.name = "MyFrontendError";
393
+ const serialized = serializeIpcError(thrown, true);
394
+ frontend.respond(0, serialized);
395
+ let caught;
396
+ try {
397
+ await promise;
398
+ expect.fail("proxy call should have rejected");
399
+ }
400
+ catch (err) {
401
+ caught = err;
402
+ }
403
+ // Following the ITwinError paradigm, the backend rebuilds a plain Error (no cross-process class identity)
404
+ // that callers identify via ITwinError.isError / BentleyError.isError rather than instanceof.
405
+ expect(ITwinError.isError(caught, BentleyError.iTwinErrorScope, "MyFrontendError")).to.be.true;
406
+ expect(caught.name).to.equal("MyFrontendError");
407
+ expect(BentleyError.isError(caught, IModelStatus.NotFound)).to.be.true;
408
+ expect(caught.message).to.equal("boom");
409
+ expect(caught.loggingMetadata).to.deep.equal({ detail: 42 });
410
+ });
411
+ it("should not let a non-string thrown `message` field overwrite the 'unknown error' guard in rebuildIpcError", async () => {
412
+ const frontend = mockFrontend();
413
+ const proxy = IpcHost.makeIpcProxy("ch");
414
+ const promise = proxy.doIt();
415
+ // simulate a thrown non-Error value with a non-string `message` field (e.g. `throw { message: 123 }`)
416
+ const serialized = serializeIpcError({ message: 123 }, true);
417
+ frontend.respond(0, serialized);
418
+ let caught;
419
+ try {
420
+ await promise;
421
+ expect.fail("proxy call should have rejected");
422
+ }
423
+ catch (err) {
424
+ caught = err;
425
+ }
426
+ expect(caught).to.be.instanceOf(Error);
427
+ expect(caught.message).to.equal("unknown error");
428
+ });
429
+ it("should rethrow a plain Error from makeIpcProxy when the frontend threw a non-BentleyError", async () => {
430
+ const frontend = mockFrontend();
431
+ const proxy = IpcHost.makeIpcProxy("ch");
432
+ const promise = proxy.doIt();
433
+ const serialized = serializeIpcError(new Error("plain failure"), true);
434
+ frontend.respond(0, serialized);
435
+ let caught;
436
+ try {
437
+ await promise;
438
+ expect.fail("proxy call should have rejected");
439
+ }
440
+ catch (err) {
441
+ caught = err;
442
+ }
443
+ expect(caught).to.be.instanceOf(Error);
444
+ expect(BentleyError.isError(caught)).to.be.false;
445
+ expect(caught.message).to.equal("plain failure");
446
+ });
216
447
  });
217
448
  });
218
449
  //# sourceMappingURL=IpcHost.test.js.map
@@ -1 +1 @@
1
- {"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C,EAAE,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,kBAAkB;QAC5E,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import * as sinon from \"sinon\";\nimport { expect } from \"chai\";\nimport { BentleyError, IModelStatus } from \"@itwin/core-bentley\";\nimport { IpcInvokeReturn, IpcSocketBackend } from \"@itwin/core-common\";\nimport { IpcHandler, IpcHost } from \"../IpcHost\";\n\ninterface MockIpcInterface {\n mockMethod: () => string;\n throwNestedError: () => never;\n throwCircularError: () => never;\n throwErrorWithNativeCause: () => never;\n throwBentleyErrorWithFunctionMetaData: () => never;\n throwBentleyErrorWithObjectMetaData: () => never;\n throwNestedBentleyErrorWithFunctionMetaData: () => never;\n throwErrorWithFunctionProperty: () => never;\n throwErrorWithSymbolProperty: () => never;\n throwErrorWithDateProperty: () => never;\n throwErrorWithClassInstanceProperty: () => never;\n throwErrorWithMixedArray: () => never;\n}\n\nclass OuterError extends Error {\n public readonly context: { cause: Error };\n public readonly errors: Error[];\n constructor(public readonly originalError: Error) {\n super(\"outer\");\n this.context = { cause: originalError };\n this.errors = [new Error(\"array-child-1\"), new Error(\"array-child-2\")];\n }\n}\n\nclass MockIpcHandler extends IpcHandler implements MockIpcInterface {\n public override get channelName() { return \"mock-channel\"; }\n\n public mockMethod(): string {\n return \"mock-value\";\n }\n\n public throwNestedError(): never {\n const inner = new Error(\"inner-message\");\n throw new OuterError(inner);\n }\n\n public throwCircularError(): never {\n const err = new Error(\"circular\") as any;\n err.cause = err; // circular reference\n throw err;\n }\n\n public throwErrorWithNativeCause(): never {\n throw new Error(\"native-cause-outer\", { cause: new Error(\"native-cause-inner\") });\n }\n\n public throwBentleyErrorWithFunctionMetaData(): never {\n throw new BentleyError(IModelStatus.BadArg, \"bentley-fn-meta\", () => ({ detail: \"computed\" }));\n }\n\n public throwBentleyErrorWithObjectMetaData(): never {\n throw new BentleyError(IModelStatus.BadArg, \"bentley-obj-meta\", { detail: \"static\" });\n }\n\n public throwNestedBentleyErrorWithFunctionMetaData(): never {\n const inner = new BentleyError(IModelStatus.BadArg, \"inner-bentley\", () => ({ detail: \"nested-computed\" }));\n const outer = new Error(\"outer\") as any;\n outer.cause = inner;\n throw outer;\n }\n\n public throwErrorWithFunctionProperty(): never {\n const err = new Error(\"fn-prop\") as any;\n err.retry = () => {};\n throw err;\n }\n\n public throwErrorWithSymbolProperty(): never {\n const err = new Error(\"sym-prop\") as any;\n err[Symbol(\"tag\")] = \"should-be-dropped\";\n throw err;\n }\n\n public throwErrorWithDateProperty(): never {\n const err = new Error(\"date-prop\") as any;\n err.timestamp = new Date(\"2024-01-01\");\n throw err;\n }\n\n public throwErrorWithClassInstanceProperty(): never {\n const err = new Error(\"class-instance-prop\") as any;\n err.request = new URL(\"https://example.com\"); // arbitrary non-plain class instance\n throw err;\n }\n\n public throwErrorWithMixedArray(): never {\n const err = new Error(\"mixed-array\") as any;\n err.items = [\"string-value\", 42, new Date(\"2024-01-01\"), new URL(\"https://example.com\"), new Error(\"array-error\")];\n throw err;\n }\n\n #privateFunction(): void { }\n}\n\ndescribe(\"IpcHost\", () => {\n let socket: sinon.SinonStubbedInstance<IpcSocketBackend>;\n\n beforeEach(async () => {\n socket = {\n send: sinon.stub(),\n addListener: sinon.stub(),\n removeListener: sinon.stub(),\n handle: sinon.stub(),\n };\n\n await IpcHost.startup({ ipcHost: { socket } });\n });\n\n describe(\"IpcHandler\", () => {\n let handler: (...args: any[]) => Promise<IpcInvokeReturn>;\n\n beforeEach(() => {\n MockIpcHandler.register();\n const handleCall = socket.handle.getCalls().find((call) => call.args[0] === \"itwin.mock-channel\")!;\n expect(handleCall).to.not.be.undefined;\n handler = handleCall.args[1];\n });\n\n it(\"should call public methods\", async () => {\n const ipcReturn = await handler(undefined, \"mockMethod\");\n expect(ipcReturn.result).to.equal(\"mock-value\");\n expect(ipcReturn.error).to.be.undefined;\n });\n\n it(\"should not call private methods\", async () => {\n const ipcReturn = await handler(undefined, \"#privateFunction\");\n expect(ipcReturn.result).to.be.undefined;\n expect(ipcReturn.error).to.not.be.undefined;\n });\n\n it(\"should not call methods inherited from Object\", async () => {\n const ipcReturn = await handler(undefined, \"toString\");\n expect(ipcReturn.result).to.be.undefined;\n expect(ipcReturn.error).to.not.be.undefined;\n });\n\n it(\"should serialize nested Error properties preserving message and stack\", async () => {\n const ipcReturn = await handler(undefined, \"throwNestedError\");\n const error = ipcReturn.error as any;\n // Top-level error\n expect(error.message).to.equal(\"outer\");\n expect(error.stack).to.be.a(\"string\");\n // Direct Error property\n expect(error.originalError.message).to.equal(\"inner-message\");\n expect(error.originalError.stack).to.be.a(\"string\");\n // Error nested inside a plain-object property\n expect(error.context.cause.message).to.equal(\"inner-message\");\n expect(error.context.cause.stack).to.be.a(\"string\");\n // Array of Errors stays an array\n expect(Array.isArray(error.errors)).to.be.true;\n expect(error.errors[0].message).to.equal(\"array-child-1\");\n expect(error.errors[1].message).to.equal(\"array-child-2\");\n });\n\n it(\"should omit stack on nested Errors when IpcHost.noStack is set\", async () => {\n const originalNoStack = IpcHost.noStack;\n IpcHost.noStack = true;\n try {\n const ipcReturn = await handler(undefined, \"throwNestedError\");\n const error = ipcReturn.error as any;\n expect(error.stack).to.be.undefined;\n expect(error.originalError.stack).to.be.undefined;\n expect(error.context.cause.stack).to.be.undefined;\n expect(error.errors[0].stack).to.be.undefined;\n expect(error.errors[1].stack).to.be.undefined;\n } finally {\n IpcHost.noStack = originalNoStack;\n }\n });\n\n it(\"should not infinitely recurse on circular Error references\", async () => {\n const ipcReturn = await handler(undefined, \"throwCircularError\");\n const error = ipcReturn.error as any;\n expect(error.message).to.equal(\"circular\");\n expect(error.cause).to.be.undefined;\n });\n\n it(\"should serialize native Error.cause even though it is non-enumerable\", async () => {\n const ipcReturn = await handler(undefined, \"throwErrorWithNativeCause\");\n const error = ipcReturn.error as any;\n expect(error.message).to.equal(\"native-cause-outer\");\n expect(error.cause).to.not.be.undefined;\n expect(error.cause.message).to.equal(\"native-cause-inner\");\n expect(error.cause.stack).to.be.a(\"string\");\n });\n\n it(\"should drop _metaData and expose loggingMetadata when BentleyError has a GetMetaDataFunction\", async () => {\n const ipcReturn = await handler(undefined, \"throwBentleyErrorWithFunctionMetaData\");\n const error = ipcReturn.error as any;\n expect(error.message).to.equal(\"bentley-fn-meta\");\n // _metaData is a function — must not survive serialization\n expect(error._metaData).to.be.undefined;\n // loggingMetadata should be the resolved object\n expect(error.loggingMetadata).to.deep.equal({ detail: \"computed\" });\n });\n\n it(\"should drop _metaData and expose loggingMetadata when BentleyError has an object metaData\", async () => {\n const ipcReturn = await handler(undefined, \"throwBentleyErrorWithObjectMetaData\");\n const error = ipcReturn.error as any;\n expect(error.message).to.equal(\"bentley-obj-meta\");\n expect(error._metaData).to.be.undefined;\n expect(error.loggingMetadata).to.deep.equal({ detail: \"static\" });\n });\n\n it(\"should drop function-valued _metaData on a nested BentleyError and still expose loggingMetadata\", async () => {\n const ipcReturn = await handler(undefined, \"throwNestedBentleyErrorWithFunctionMetaData\");\n const error = ipcReturn.error as any;\n expect(error.message).to.equal(\"outer\");\n // The nested BentleyError inside .cause must also have _metaData stripped and loggingMetadata populated\n expect(error.cause).to.not.be.undefined;\n expect(error.cause.message).to.equal(\"inner-bentley\");\n expect(error.cause._metaData).to.be.undefined;\n expect(error.cause.loggingMetadata).to.deep.equal({ detail: \"nested-computed\" });\n });\n\n it(\"should drop arbitrary function-valued properties from a thrown Error\", async () => {\n const ipcReturn = await handler(undefined, \"throwErrorWithFunctionProperty\");\n const error = ipcReturn.error as any;\n expect(error.message).to.equal(\"fn-prop\");\n expect(error.retry).to.be.undefined;\n });\n\n it(\"should not include symbol-keyed properties from a thrown Error\", async () => {\n const ipcReturn = await handler(undefined, \"throwErrorWithSymbolProperty\");\n const error = ipcReturn.error as any;\n expect(error.message).to.equal(\"sym-prop\");\n // { ...e } copies enumerable own symbol-keyed properties too.\n // The serializer explicitly strips them (they cannot be structured-cloned).\n expect(Object.getOwnPropertySymbols(error)).to.have.length(0);\n });\n\n it(\"should preserve Date properties\", async () => {\n const ipcReturn = await handler(undefined, \"throwErrorWithDateProperty\");\n const error = ipcReturn.error as any;\n expect(error.message).to.equal(\"date-prop\");\n expect(error.timestamp).to.deep.equal(new Date(\"2024-01-01\"));\n });\n\n it(\"should drop non-plain class instance properties\", async () => {\n const ipcReturn = await handler(undefined, \"throwErrorWithClassInstanceProperty\");\n const error = ipcReturn.error as any;\n expect(error.message).to.equal(\"class-instance-prop\");\n expect(error.request).to.be.undefined;\n });\n\n it(\"should sanitize mixed arrays: preserve primitives and Dates, drop non-plain class instances, recurse into Errors\", async () => {\n const ipcReturn = await handler(undefined, \"throwErrorWithMixedArray\");\n const error = ipcReturn.error as any;\n expect(error.message).to.equal(\"mixed-array\");\n expect(Array.isArray(error.items)).to.be.true;\n expect(error.items[0]).to.equal(\"string-value\"); // primitive: preserved\n expect(error.items[1]).to.equal(42); // primitive: preserved\n expect(error.items[2]).to.deep.equal(new Date(\"2024-01-01\")); // Date: preserved\n expect(error.items[3]).to.be.undefined; // class instance: dropped (→ undefined)\n expect(error.items[4].message).to.equal(\"array-error\"); // Error: recursed\n });\n });\n});\n"]}
1
+ {"version":3,"file":"IpcHost.test.js","sourceRoot":"","sources":["../../../src/test/IpcHost.test.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAC7E,OAAO,EAAqC,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC1F,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAuBjD,MAAM,UAAW,SAAQ,KAAK;IAGA;IAFZ,OAAO,CAAmB;IAC1B,MAAM,CAAU;IAChC,YAA4B,aAAoB;QAC9C,KAAK,CAAC,OAA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,CAAC,eAAe,CAAC,EAAE,IAAI,CAAC,CAAC;YACvE,QAAQ,CAAC,OAAO,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC;YAEhC,IAAI,MAAW,CAAC;YAChB,IAAI,CAAC;gBACH,MAAM,OAAO,CAAC;gBACd,MAAM,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;YACjD,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,MAAM,GAAG,GAAG,CAAC;YACf,CAAC;YACD,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;YACvC,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC;YACjD,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;QACnD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import * as sinon from \"sinon\";\nimport { expect } from \"chai\";\nimport { BentleyError, IModelStatus, ITwinError } from \"@itwin/core-bentley\";\nimport { IpcInvokeReturn, IpcSocketBackend, serializeIpcError } from \"@itwin/core-common\";\nimport { IpcHandler, IpcHost } from \"../IpcHost\";\n\ninterface MockIpcInterface {\n mockMethod: () => string;\n throwNestedError: () => never;\n throwCircularError: () => never;\n throwErrorWithNativeCause: () => never;\n throwBentleyErrorWithFunctionMetaData: () => never;\n throwBentleyErrorWithObjectMetaData: () => never;\n throwNestedBentleyErrorWithFunctionMetaData: () => never;\n throwBentleyErrorWithNestedBentleyErrorMetaData: () => never;\n throwErrorWithFunctionProperty: () => never;\n throwErrorWithSymbolProperty: () => never;\n throwErrorWithDateProperty: () => never;\n throwErrorWithClassInstanceProperty: () => never;\n throwErrorWithMixedArray: () => never;\n throwErrorWithNestedArrayProperty: () => never;\n throwBentleyErrorWithMapMetaData: () => never;\n throwBentleyErrorWithCollidingMapMetaData: () => never;\n throwBentleyErrorWithSetMetaData: () => never;\n throwErrorWithSelfReferencingArray: () => never;\n}\n\nclass OuterError extends Error {\n public readonly context: { cause: Error };\n public readonly errors: Error[];\n constructor(public readonly originalError: Error) {\n super(\"outer\");\n this.context = { cause: originalError };\n this.errors = [new Error(\"array-child-1\"), new Error(\"array-child-2\")];\n }\n}\n\nclass MockIpcHandler extends IpcHandler implements MockIpcInterface {\n public override get channelName() { return \"mock-channel\"; }\n\n public mockMethod(): string {\n return \"mock-value\";\n }\n\n public throwNestedError(): never {\n const inner = new Error(\"inner-message\");\n throw new OuterError(inner);\n }\n\n public throwCircularError(): never {\n const err = new Error(\"circular\") as any;\n err.cause = err; // circular reference\n throw err;\n }\n\n public throwErrorWithNativeCause(): never {\n throw new Error(\"native-cause-outer\", { cause: new Error(\"native-cause-inner\") });\n }\n\n public throwBentleyErrorWithFunctionMetaData(): never {\n throw new BentleyError(IModelStatus.BadArg, \"bentley-fn-meta\", () => ({ detail: \"computed\" }));\n }\n\n public throwBentleyErrorWithObjectMetaData(): never {\n throw new BentleyError(IModelStatus.BadArg, \"bentley-obj-meta\", { detail: \"static\" });\n }\n\n public throwNestedBentleyErrorWithFunctionMetaData(): never {\n const inner = new BentleyError(IModelStatus.BadArg, \"inner-bentley\", () => ({ detail: \"nested-computed\" }));\n const outer = new Error(\"outer\") as any;\n outer.cause = inner;\n throw outer;\n }\n\n public throwBentleyErrorWithNestedBentleyErrorMetaData(): never {\n const inner = new BentleyError(IModelStatus.BadArg, \"inner-bentley-in-metadata\", { detail: \"inner-value\" });\n throw new BentleyError(IModelStatus.BadArg, \"bentley-nested-bentley-meta\", { nested: inner });\n }\n\n public throwErrorWithFunctionProperty(): never {\n const err = new Error(\"fn-prop\") as any;\n err.retry = () => {};\n throw err;\n }\n\n public throwErrorWithSymbolProperty(): never {\n const err = new Error(\"sym-prop\") as any;\n err[Symbol(\"tag\")] = \"should-be-dropped\";\n throw err;\n }\n\n public throwErrorWithDateProperty(): never {\n const err = new Error(\"date-prop\") as any;\n err.timestamp = new Date(\"2024-01-01\");\n throw err;\n }\n\n public throwErrorWithClassInstanceProperty(): never {\n const err = new Error(\"class-instance-prop\") as any;\n err.request = new URL(\"https://example.com\"); // arbitrary non-plain class instance\n throw err;\n }\n\n public throwErrorWithMixedArray(): never {\n const err = new Error(\"mixed-array\") as any;\n err.items = [\"string-value\", 42, new Date(\"2024-01-01\"), new URL(\"https://example.com\"), new Error(\"array-error\")];\n throw err;\n }\n\n public throwErrorWithNestedArrayProperty(): never {\n const err = new Error(\"nested-array\") as any;\n err.matrix = [[1, 2], [3, 4]];\n throw err;\n }\n\n public throwBentleyErrorWithMapMetaData(): never {\n throw new BentleyError(IModelStatus.BadArg, \"bentley-map-meta\", new Map([[\"detail\", \"map-value\"]]));\n }\n\n public throwBentleyErrorWithCollidingMapMetaData(): never {\n // Numeric key `1` and string key `\"1\"` stringify to the same \"1\", so they'd collide without disambiguation.\n throw new BentleyError(IModelStatus.BadArg, \"bentley-colliding-map-meta\", new Map<number | string, string>([[1, \"num-one\"], [\"1\", \"str-one\"]]));\n }\n\n public throwBentleyErrorWithSetMetaData(): never {\n throw new BentleyError(IModelStatus.BadArg, \"bentley-set-meta\", new Set([\"tag1\", \"tag2\"]));\n }\n\n public throwErrorWithSelfReferencingArray(): never {\n const err = new Error(\"self-referencing-array\") as any;\n const arr: any[] = [];\n arr.push(arr); // array that contains itself\n err.items = arr;\n throw err;\n }\n\n #privateFunction(): void { }\n}\n\ndescribe(\"IpcHost\", () => {\n let socket: sinon.SinonStubbedInstance<IpcSocketBackend>;\n\n beforeEach(async () => {\n socket = {\n send: sinon.stub(),\n addListener: sinon.stub(),\n removeListener: sinon.stub(),\n handle: sinon.stub(),\n };\n\n await IpcHost.startup({ ipcHost: { socket } });\n });\n\n afterEach(() => {\n (IpcHost as any)._nextInvokeId = 0;\n (IpcHost as any)._pendingInvokes.clear();\n });\n\n describe(\"IpcHandler\", () => {\n let handler: (...args: any[]) => Promise<IpcInvokeReturn>;\n\n beforeEach(() => {\n MockIpcHandler.register();\n const handleCall = socket.handle.getCalls().find((call) => call.args[0] === \"itwin.mock-channel\")!;\n expect(handleCall).to.not.be.undefined;\n handler = handleCall.args[1];\n });\n\n it(\"should call public methods\", async () => {\n const ipcReturn = await handler(undefined, \"mockMethod\");\n expect(ipcReturn.result).to.equal(\"mock-value\");\n expect(ipcReturn.error).to.be.undefined;\n });\n\n it(\"should not call private methods\", async () => {\n const ipcReturn = await handler(undefined, \"#privateFunction\");\n expect(ipcReturn.result).to.be.undefined;\n expect(ipcReturn.error).to.not.be.undefined;\n });\n\n it(\"should not call methods inherited from Object\", async () => {\n const ipcReturn = await handler(undefined, \"toString\");\n expect(ipcReturn.result).to.be.undefined;\n expect(ipcReturn.error).to.not.be.undefined;\n });\n\n it(\"should serialize nested Error properties preserving message and stack\", async () => {\n const ipcReturn = await handler(undefined, \"throwNestedError\");\n const error = ipcReturn.error as any;\n // Top-level error\n expect(error.message).to.equal(\"outer\");\n expect(error.stack).to.be.a(\"string\");\n // Direct Error property\n expect(error.originalError.message).to.equal(\"inner-message\");\n expect(error.originalError.stack).to.be.a(\"string\");\n // Error nested inside a plain-object property\n expect(error.context.cause.message).to.equal(\"inner-message\");\n expect(error.context.cause.stack).to.be.a(\"string\");\n // Array of Errors stays an array\n expect(Array.isArray(error.errors)).to.be.true;\n expect(error.errors[0].message).to.equal(\"array-child-1\");\n expect(error.errors[1].message).to.equal(\"array-child-2\");\n });\n\n it(\"should omit stack on nested Errors when IpcHost.noStack is set\", async () => {\n const originalNoStack = IpcHost.noStack;\n IpcHost.noStack = true;\n try {\n const ipcReturn = await handler(undefined, \"throwNestedError\");\n const error = ipcReturn.error as any;\n expect(error.stack).to.be.undefined;\n expect(error.originalError.stack).to.be.undefined;\n expect(error.context.cause.stack).to.be.undefined;\n expect(error.errors[0].stack).to.be.undefined;\n expect(error.errors[1].stack).to.be.undefined;\n } finally {\n IpcHost.noStack = originalNoStack;\n }\n });\n\n it(\"should not infinitely recurse on circular Error references\", async () => {\n const ipcReturn = await handler(undefined, \"throwCircularError\");\n const error = ipcReturn.error as any;\n expect(error.message).to.equal(\"circular\");\n expect(error.cause).to.be.undefined;\n });\n\n it(\"should serialize native Error.cause even though it is non-enumerable\", async () => {\n const ipcReturn = await handler(undefined, \"throwErrorWithNativeCause\");\n const error = ipcReturn.error as any;\n expect(error.message).to.equal(\"native-cause-outer\");\n expect(error.cause).to.not.be.undefined;\n expect(error.cause.message).to.equal(\"native-cause-inner\");\n expect(error.cause.stack).to.be.a(\"string\");\n });\n\n it(\"should drop _metaData and expose loggingMetadata when BentleyError has a GetMetaDataFunction\", async () => {\n const ipcReturn = await handler(undefined, \"throwBentleyErrorWithFunctionMetaData\");\n const error = ipcReturn.error as any;\n expect(error.message).to.equal(\"bentley-fn-meta\");\n // _metaData is a function — must not survive serialization\n expect(error._metaData).to.be.undefined;\n // loggingMetadata should be the resolved object\n expect(error.loggingMetadata).to.deep.equal({ detail: \"computed\" });\n });\n\n it(\"should drop _metaData and expose loggingMetadata when BentleyError has an object metaData\", async () => {\n const ipcReturn = await handler(undefined, \"throwBentleyErrorWithObjectMetaData\");\n const error = ipcReturn.error as any;\n expect(error.message).to.equal(\"bentley-obj-meta\");\n expect(error._metaData).to.be.undefined;\n expect(error.loggingMetadata).to.deep.equal({ detail: \"static\" });\n });\n\n it(\"should drop function-valued _metaData on a nested BentleyError and still expose loggingMetadata\", async () => {\n const ipcReturn = await handler(undefined, \"throwNestedBentleyErrorWithFunctionMetaData\");\n const error = ipcReturn.error as any;\n expect(error.message).to.equal(\"outer\");\n // The nested BentleyError inside .cause must also have _metaData stripped and loggingMetadata populated\n expect(error.cause).to.not.be.undefined;\n expect(error.cause.message).to.equal(\"inner-bentley\");\n expect(error.cause._metaData).to.be.undefined;\n expect(error.cause.loggingMetadata).to.deep.equal({ detail: \"nested-computed\" });\n });\n\n it(\"should drop arbitrary function-valued properties from a thrown Error\", async () => {\n const ipcReturn = await handler(undefined, \"throwErrorWithFunctionProperty\");\n const error = ipcReturn.error as any;\n expect(error.message).to.equal(\"fn-prop\");\n expect(error.retry).to.be.undefined;\n });\n\n it(\"should not include symbol-keyed properties from a thrown Error\", async () => {\n const ipcReturn = await handler(undefined, \"throwErrorWithSymbolProperty\");\n const error = ipcReturn.error as any;\n expect(error.message).to.equal(\"sym-prop\");\n // { ...e } copies enumerable own symbol-keyed properties too.\n // The serializer explicitly strips them (they cannot be structured-cloned).\n expect(Object.getOwnPropertySymbols(error)).to.have.length(0);\n });\n\n it(\"should preserve Date properties\", async () => {\n const ipcReturn = await handler(undefined, \"throwErrorWithDateProperty\");\n const error = ipcReturn.error as any;\n expect(error.message).to.equal(\"date-prop\");\n expect(error.timestamp).to.deep.equal(new Date(\"2024-01-01\"));\n });\n\n it(\"should drop non-plain class instance properties\", async () => {\n const ipcReturn = await handler(undefined, \"throwErrorWithClassInstanceProperty\");\n const error = ipcReturn.error as any;\n expect(error.message).to.equal(\"class-instance-prop\");\n expect(error.request).to.be.undefined;\n });\n\n it(\"should sanitize mixed arrays: preserve primitives and Dates, drop non-plain class instances, recurse into Errors\", async () => {\n const ipcReturn = await handler(undefined, \"throwErrorWithMixedArray\");\n const error = ipcReturn.error as any;\n expect(error.message).to.equal(\"mixed-array\");\n expect(Array.isArray(error.items)).to.be.true;\n expect(error.items[0]).to.equal(\"string-value\"); // primitive: preserved\n expect(error.items[1]).to.equal(42); // primitive: preserved\n expect(error.items[2]).to.deep.equal(new Date(\"2024-01-01\")); // Date: preserved\n expect(error.items[3]).to.be.undefined; // class instance: dropped (→ undefined)\n expect(error.items[4].message).to.equal(\"array-error\"); // Error: recursed\n });\n\n it(\"should preserve nested arrays (array-of-arrays)\", async () => {\n const ipcReturn = await handler(undefined, \"throwErrorWithNestedArrayProperty\");\n const error = ipcReturn.error as any;\n expect(error.message).to.equal(\"nested-array\");\n expect(error.matrix).to.deep.equal([[1, 2], [3, 4]]);\n });\n\n it(\"should not infinitely recurse on a self-referencing array\", async () => {\n const ipcReturn = await handler(undefined, \"throwErrorWithSelfReferencingArray\");\n const error = ipcReturn.error as any;\n expect(error.message).to.equal(\"self-referencing-array\");\n expect(error.items[0]).to.be.undefined; // cycle detected: dropped rather than recursing forever\n });\n\n it(\"should normalize Map-valued loggingMetadata to a JSON-safe plain object (survives every transport)\", async () => {\n const ipcReturn = await handler(undefined, \"throwBentleyErrorWithMapMetaData\");\n const error = ipcReturn.error as any;\n expect(error.message).to.equal(\"bentley-map-meta\");\n expect(error.loggingMetadata).to.deep.equal({ detail: \"map-value\" });\n });\n\n it(\"should disambiguate Map-valued loggingMetadata keys that stringify to the same value\", async () => {\n const ipcReturn = await handler(undefined, \"throwBentleyErrorWithCollidingMapMetaData\");\n const error = ipcReturn.error as any;\n expect(error.message).to.equal(\"bentley-colliding-map-meta\");\n expect(error.loggingMetadata).to.deep.equal({ \"1\": \"num-one\", \"1#1\": \"str-one\" });\n });\n\n it(\"should preserve iTwinErrorId/loggingMetadata of a BentleyError nested inside loggingMetadata\", async () => {\n const ipcReturn = await handler(undefined, \"throwBentleyErrorWithNestedBentleyErrorMetaData\");\n const error = ipcReturn.error as any;\n expect(error.message).to.equal(\"bentley-nested-bentley-meta\");\n const nested = error.loggingMetadata.nested;\n expect(nested.message).to.equal(\"inner-bentley-in-metadata\");\n expect(nested.iTwinErrorId).to.deep.equal({ scope: BentleyError.iTwinErrorScope, key: nested.iTwinErrorId.key });\n expect(nested.loggingMetadata).to.deep.equal({ detail: \"inner-value\" });\n });\n\n it(\"should normalize Set-valued loggingMetadata to a JSON-safe array (survives every transport)\", async () => {\n const ipcReturn = await handler(undefined, \"throwBentleyErrorWithSetMetaData\");\n const error = ipcReturn.error as any;\n expect(error.message).to.equal(\"bentley-set-meta\");\n expect(error.loggingMetadata).to.deep.equal([\"tag1\", \"tag2\"]);\n });\n });\n\n describe(\"IpcHost.invoke\", () => {\n /** Simulates the frontend: captures per-request listeners and provides a `respond` helper by call index. */\n function mockFrontend() {\n const listeners = new Map<string, (event: any, result: any) => void>();\n socket.addListener.callsFake((ch: string, fn: (event: any, result: any) => void) => {\n listeners.set(ch, fn);\n return () => listeners.delete(ch);\n });\n\n return {\n listeners,\n responseChannel: (callIndex: number) => socket.send.getCall(callIndex).args[1] as string,\n respond: (callIndex: number, result: unknown) => {\n const responseChannel = socket.send.getCall(callIndex).args[1] as string;\n const listener = listeners.get(responseChannel);\n if (!listener)\n throw new Error(`No listener found for response channel ${responseChannel}`);\n listener(undefined, result);\n },\n };\n }\n\n it(\"should resolve with the frontend's response\", async () => {\n const frontend = mockFrontend();\n const promise = IpcHost.invoke(\"ch\", \"a\", \"b\");\n frontend.respond(0, \"hello\");\n expect(await promise).to.equal(\"hello\");\n // the pending-invoke entry must be removed so the map does not grow unboundedly\n expect((IpcHost as any)._pendingInvokes.size).to.equal(0);\n });\n\n it(\"should route concurrent invokes to the correct caller\", async () => {\n const frontend = mockFrontend();\n const p1 = IpcHost.invoke(\"ch\");\n const p2 = IpcHost.invoke(\"ch\");\n\n // respond out of order\n frontend.respond(1, \"second\");\n frontend.respond(0, \"first\");\n\n expect(await p1).to.equal(\"first\");\n expect(await p2).to.equal(\"second\");\n });\n\n it(\"should remove the response listener after a response\", async () => {\n const frontend = mockFrontend();\n const promise = IpcHost.invoke(\"ch\");\n const responseChannel = frontend.responseChannel(0);\n expect(frontend.listeners.has(responseChannel)).to.be.true;\n\n frontend.respond(0, \"done\");\n await promise;\n expect(frontend.listeners.has(responseChannel)).to.be.false;\n });\n\n it(\"should reject pending invokes when IpcHost is shut down\", async () => {\n const frontend = mockFrontend();\n const promise = IpcHost.invoke(\"ch\");\n const responseChannel = frontend.responseChannel(0);\n // attach handler immediately so the rejection is observed (and not \"unhandled\")\n const caught = promise.then(() => undefined, (e: Error) => e);\n\n await IpcHost.shutdown();\n\n const err = await caught;\n expect(err).to.be.instanceOf(Error);\n expect((err as Error).message).to.contain(\"shut down\");\n // the listener must be cleaned up so it does not leak past shutdown\n expect(frontend.listeners.has(responseChannel)).to.be.false;\n });\n\n it(\"should reject all pending invokes when IpcHost is shut down with 2+ concurrent invokes, removing all listeners\", async () => {\n const frontend = mockFrontend();\n const p1 = IpcHost.invoke(\"ch1\");\n const p2 = IpcHost.invoke(\"ch2\");\n const responseChannel1 = frontend.responseChannel(0);\n const responseChannel2 = frontend.responseChannel(1);\n // attach handlers immediately so the rejections are observed (and not \"unhandled\")\n const caught1 = p1.then(() => undefined, (e: Error) => e);\n const caught2 = p2.then(() => undefined, (e: Error) => e);\n expect((IpcHost as any)._pendingInvokes.size).to.equal(2);\n\n await IpcHost.shutdown();\n\n const err1 = await caught1;\n const err2 = await caught2;\n expect(err1).to.be.instanceOf(Error);\n expect((err1 as Error).message).to.contain(\"shut down\");\n expect(err2).to.be.instanceOf(Error);\n expect((err2 as Error).message).to.contain(\"shut down\");\n expect(frontend.listeners.has(responseChannel1)).to.be.false;\n expect(frontend.listeners.has(responseChannel2)).to.be.false;\n expect((IpcHost as any)._pendingInvokes.size).to.equal(0);\n });\n\n it(\"should reject and clean up the listener/pending-invoke entry when `send` throws synchronously\", async () => {\n const frontend = mockFrontend();\n socket.send.throws(new Error(\"send failed\"));\n const promise = IpcHost.invoke(\"ch\");\n\n let caught: any;\n try {\n await promise;\n expect.fail(\"invoke should have rejected\");\n } catch (err) {\n caught = err;\n }\n expect(caught).to.be.instanceOf(Error);\n expect(caught.message).to.equal(\"send failed\");\n // the listener and _pendingInvokes entry must not leak when `send` throws synchronously\n expect(frontend.listeners.size).to.equal(0);\n expect((IpcHost as any)._pendingInvokes.size).to.equal(0);\n });\n\n it(\"should rethrow a frontend-thrown BentleyError from makeIpcProxy preserving ITwinError identity and metadata\", async () => {\n const frontend = mockFrontend();\n const proxy = IpcHost.makeIpcProxy<{ doIt: () => Promise<void> }>(\"ch\");\n const promise = proxy.doIt();\n\n // simulate the frontend handler serializing a thrown BentleyError into the invoke-response envelope\n const thrown = new BentleyError(IModelStatus.NotFound, \"boom\", () => ({ detail: 42 }));\n thrown.name = \"MyFrontendError\";\n const serialized = serializeIpcError(thrown, true);\n frontend.respond(0, serialized);\n\n let caught: any;\n try {\n await promise;\n expect.fail(\"proxy call should have rejected\");\n } catch (err) {\n caught = err;\n }\n // Following the ITwinError paradigm, the backend rebuilds a plain Error (no cross-process class identity)\n // that callers identify via ITwinError.isError / BentleyError.isError rather than instanceof.\n expect(ITwinError.isError(caught, BentleyError.iTwinErrorScope, \"MyFrontendError\")).to.be.true;\n expect(caught.name).to.equal(\"MyFrontendError\");\n expect(BentleyError.isError(caught, IModelStatus.NotFound)).to.be.true;\n expect(caught.message).to.equal(\"boom\");\n expect(caught.loggingMetadata).to.deep.equal({ detail: 42 });\n });\n\n it(\"should not let a non-string thrown `message` field overwrite the 'unknown error' guard in rebuildIpcError\", async () => {\n const frontend = mockFrontend();\n const proxy = IpcHost.makeIpcProxy<{ doIt: () => Promise<void> }>(\"ch\");\n const promise = proxy.doIt();\n\n // simulate a thrown non-Error value with a non-string `message` field (e.g. `throw { message: 123 }`)\n const serialized = serializeIpcError({ message: 123 }, true);\n frontend.respond(0, serialized);\n\n let caught: any;\n try {\n await promise;\n expect.fail(\"proxy call should have rejected\");\n } catch (err) {\n caught = err;\n }\n expect(caught).to.be.instanceOf(Error);\n expect(caught.message).to.equal(\"unknown error\");\n });\n\n it(\"should rethrow a plain Error from makeIpcProxy when the frontend threw a non-BentleyError\", async () => {\n const frontend = mockFrontend();\n const proxy = IpcHost.makeIpcProxy<{ doIt: () => Promise<void> }>(\"ch\");\n const promise = proxy.doIt();\n\n const serialized = serializeIpcError(new Error(\"plain failure\"), true);\n frontend.respond(0, serialized);\n\n let caught: any;\n try {\n await promise;\n expect.fail(\"proxy call should have rejected\");\n } catch (err) {\n caught = err;\n }\n expect(caught).to.be.instanceOf(Error);\n expect(BentleyError.isError(caught)).to.be.false;\n expect(caught.message).to.equal(\"plain failure\");\n });\n });\n});\n"]}
@@ -1288,6 +1288,26 @@ describe("iModel", () => {
1288
1288
  const physicalObjectIds = imodel2.queryEntityIds({ from: "generic.PhysicalObject", where: "codevalue is null", limit: 1, offset: 1, only: true, orderBy: "ecinstanceid desc" });
1289
1289
  assert.equal(physicalObjectIds.size, 1);
1290
1290
  });
1291
+ it("queryEntityIds should skip undefined and null bindings", () => {
1292
+ // Callers commonly build the WHERE clause conditionally but pass the bindings object
1293
+ // unconditionally, relying on undefined entries being skipped (legacy bindValues semantics).
1294
+ const baseline = imodel2.queryEntityIds({ from: "generic.PhysicalObject", where: "codevalue is null" });
1295
+ assert.isAtLeast(baseline.size, 1);
1296
+ const parent = undefined;
1297
+ const where = "codevalue is null";
1298
+ const withUnusedUndefined = imodel2.queryEntityIds({ from: "generic.PhysicalObject", where, bindings: { parent } });
1299
+ assert.deepEqual(withUnusedUndefined, baseline);
1300
+ const withUnusedNull = imodel2.queryEntityIds({ from: "generic.PhysicalObject", where: "codevalue is null", bindings: { parent: null } });
1301
+ assert.deepEqual(withUnusedNull, baseline);
1302
+ const someId = imodel2.queryEntityIds({ from: "bis.element", where: "CodeValue IS NOT NULL", limit: 1 }).values().next().value;
1303
+ assert.isDefined(someId);
1304
+ const codeValue = imodel2.elements.getElement(someId).code.value;
1305
+ const mixed = imodel2.queryEntityIds({ from: "bis.element", where: "CodeValue=:cv", bindings: { cv: codeValue, parent: undefined } });
1306
+ assert.isTrue(mixed.has(someId));
1307
+ // positional form: trailing undefined beyond the parameter count must be skipped, not bound
1308
+ const positional = imodel2.queryEntityIds({ from: "bis.element", where: "CodeValue=?", bindings: [codeValue, undefined] });
1309
+ assert.isTrue(positional.has(someId));
1310
+ });
1291
1311
  it("validate BisCodeSpecs", async () => {
1292
1312
  assert.equal(imodel2.codeSpecs.getByName(BisCodeSpec.nullCodeSpec).scopeType, CodeScopeSpec.Type.Repository);
1293
1313
  assert.equal(imodel2.codeSpecs.getByName(BisCodeSpec.subCategory).scopeType, CodeScopeSpec.Type.ParentElement);