@itwin/core-backend 5.1.0-dev.37 → 5.1.0-dev.39

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 (67) hide show
  1. package/lib/cjs/BackendHubAccess.d.ts +1 -1
  2. package/lib/cjs/BackendHubAccess.js +1 -1
  3. package/lib/cjs/BackendHubAccess.js.map +1 -1
  4. package/lib/cjs/ECDb.d.ts +3 -3
  5. package/lib/cjs/ECDb.js +3 -3
  6. package/lib/cjs/ECDb.js.map +1 -1
  7. package/lib/cjs/ECSqlStatement.d.ts +14 -5
  8. package/lib/cjs/ECSqlStatement.d.ts.map +1 -1
  9. package/lib/cjs/ECSqlStatement.js +17 -3
  10. package/lib/cjs/ECSqlStatement.js.map +1 -1
  11. package/lib/cjs/ElementAspect.d.ts +1 -1
  12. package/lib/cjs/ElementAspect.js +1 -1
  13. package/lib/cjs/ElementAspect.js.map +1 -1
  14. package/lib/cjs/IModelDb.d.ts +6 -6
  15. package/lib/cjs/IModelDb.js +6 -6
  16. package/lib/cjs/IModelDb.js.map +1 -1
  17. package/lib/cjs/IModelHost.d.ts +2 -2
  18. package/lib/cjs/IModelHost.js +2 -2
  19. package/lib/cjs/IModelHost.js.map +1 -1
  20. package/lib/cjs/Material.d.ts +1 -1
  21. package/lib/cjs/Material.js +1 -1
  22. package/lib/cjs/Material.js.map +1 -1
  23. package/lib/cjs/SQLiteDb.d.ts +1 -1
  24. package/lib/cjs/SQLiteDb.js +1 -1
  25. package/lib/cjs/SQLiteDb.js.map +1 -1
  26. package/lib/cjs/rpc-impl/IModelReadRpcImpl.d.ts +1 -1
  27. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js +1 -1
  28. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js.map +1 -1
  29. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.d.ts +2 -2
  30. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js.map +1 -1
  31. package/lib/esm/BackendHubAccess.d.ts +1 -1
  32. package/lib/esm/BackendHubAccess.js +1 -1
  33. package/lib/esm/BackendHubAccess.js.map +1 -1
  34. package/lib/esm/ECDb.d.ts +3 -3
  35. package/lib/esm/ECDb.js +3 -3
  36. package/lib/esm/ECDb.js.map +1 -1
  37. package/lib/esm/ECSqlStatement.d.ts +14 -5
  38. package/lib/esm/ECSqlStatement.d.ts.map +1 -1
  39. package/lib/esm/ECSqlStatement.js +17 -3
  40. package/lib/esm/ECSqlStatement.js.map +1 -1
  41. package/lib/esm/ElementAspect.d.ts +1 -1
  42. package/lib/esm/ElementAspect.js +1 -1
  43. package/lib/esm/ElementAspect.js.map +1 -1
  44. package/lib/esm/IModelDb.d.ts +6 -6
  45. package/lib/esm/IModelDb.js +6 -6
  46. package/lib/esm/IModelDb.js.map +1 -1
  47. package/lib/esm/IModelHost.d.ts +2 -2
  48. package/lib/esm/IModelHost.js +2 -2
  49. package/lib/esm/IModelHost.js.map +1 -1
  50. package/lib/esm/Material.d.ts +1 -1
  51. package/lib/esm/Material.js +1 -1
  52. package/lib/esm/Material.js.map +1 -1
  53. package/lib/esm/SQLiteDb.d.ts +1 -1
  54. package/lib/esm/SQLiteDb.js +1 -1
  55. package/lib/esm/SQLiteDb.js.map +1 -1
  56. package/lib/esm/rpc-impl/IModelReadRpcImpl.d.ts +1 -1
  57. package/lib/esm/rpc-impl/IModelReadRpcImpl.js +1 -1
  58. package/lib/esm/rpc-impl/IModelReadRpcImpl.js.map +1 -1
  59. package/lib/esm/rpc-impl/RpcBriefcaseUtility.d.ts +2 -2
  60. package/lib/esm/rpc-impl/RpcBriefcaseUtility.js.map +1 -1
  61. package/lib/esm/test/ecdb/ECSqlStatement.test.js +192 -0
  62. package/lib/esm/test/ecdb/ECSqlStatement.test.js.map +1 -1
  63. package/lib/esm/test/imodel/IModel.test.js +155 -0
  64. package/lib/esm/test/imodel/IModel.test.js.map +1 -1
  65. package/lib/esm/test/standalone/GeometryStream.test.js +49 -1
  66. package/lib/esm/test/standalone/GeometryStream.test.js.map +1 -1
  67. package/package.json +13 -13
@@ -2690,5 +2690,160 @@ describe("iModel", () => {
2690
2690
  expect(() => imodel.relationships.insertInstance(props)).to.throw(`Failed to insert relationship [${imodelPath}]: rc=2067, constraint failed (BE_SQLITE_CONSTRAINT_UNIQUE)`);
2691
2691
  imodel.close();
2692
2692
  });
2693
+ function createElemProps(_imodel, modId, catId, className) {
2694
+ // Create props
2695
+ const elementProps = {
2696
+ classFullName: className,
2697
+ model: modId,
2698
+ category: catId,
2699
+ code: Code.createEmpty(),
2700
+ };
2701
+ return elementProps;
2702
+ }
2703
+ function insertElement(imodel, mId, cId, cName, propName) {
2704
+ const elementProps = createElemProps(imodel, mId, cId, cName);
2705
+ const geomElement = imodel.elements.createElement(elementProps);
2706
+ geomElement.name = propName; // Add a custom property to the element
2707
+ const id = imodel.elements.insertElement(geomElement.toJSON());
2708
+ assert.isTrue(Id64.isValidId64(id), "insert failed");
2709
+ return id;
2710
+ }
2711
+ function validateADrivesBRowCount(imodel, expectedRows) {
2712
+ const reader = IModelTestUtils.executeQuery(imodel, `select * from trs.ADrivesB`);
2713
+ assert.strictEqual(reader.length, expectedRows, `Expected ${expectedRows} rows in trs.ADrivesB table`);
2714
+ }
2715
+ function validateNavProp(imodel, expectedNavPropValue) {
2716
+ const reader = IModelTestUtils.executeQuery(imodel, `select NavPropChildB from trs.ChildA`);
2717
+ assert.strictEqual(reader.length, 1);
2718
+ assert.deepEqual(reader[0].navPropChildB, expectedNavPropValue, `Expected NavPropChildB to be "${expectedNavPropValue}"`);
2719
+ }
2720
+ it("Validate invalid relationship classes being inserted/updated", async () => {
2721
+ const imodelPath = IModelTestUtils.prepareOutputFile("IModel", "invalidRelationshipClass.bim");
2722
+ if (IModelJsFs.existsSync(imodelPath))
2723
+ IModelJsFs.unlinkSync(imodelPath);
2724
+ const testImodel = SnapshotDb.createEmpty(imodelPath, { rootSubject: { name: "invalidRelationshipClass" } });
2725
+ await testImodel.importSchemaStrings([
2726
+ `<?xml version="1.0" encoding="UTF-8"?>
2727
+ <ECSchema schemaName="TestRelationSchema" alias="trs" version="01.00" xmlns="http://www.bentley.com/schemas/Bentley.ECXML.3.1">
2728
+ <ECSchemaReference name="BisCore" version="01.00" alias="bis"/>
2729
+ <ECEntityClass typeName="TestElement">
2730
+ <BaseClass>bis:PhysicalElement</BaseClass>
2731
+ <ECProperty propertyName="Name" typeName="string" />
2732
+ </ECEntityClass>
2733
+
2734
+ <ECEntityClass typeName="ChildA" >
2735
+ <BaseClass>TestElement</BaseClass>
2736
+ <ECNavigationProperty propertyName="NavPropChildB" relationshipName="ADrivesB" direction="Forward" readOnly="True">
2737
+ </ECNavigationProperty>
2738
+ </ECEntityClass>
2739
+
2740
+ <ECEntityClass typeName="ChildB" >
2741
+ <BaseClass>TestElement</BaseClass>
2742
+ </ECEntityClass>
2743
+
2744
+ <ECRelationshipClass typeName="ADrivesB" strengthDirection="Backward" strength="referencing" modifier="Sealed">
2745
+ <Source multiplicity="(0..*)" polymorphic="true" roleLabel="drives">
2746
+ <Class class="ChildA"/>
2747
+ </Source>
2748
+ <Target multiplicity="(0..1)" polymorphic="true" roleLabel="is driven by">
2749
+ <Class class="ChildB"/>
2750
+ </Target>
2751
+ </ECRelationshipClass>
2752
+
2753
+ <ECEntityClass typeName="ChildC">
2754
+ <BaseClass>TestElement</BaseClass>
2755
+ </ECEntityClass>
2756
+
2757
+ <ECEntityClass typeName="ChildD">
2758
+ <BaseClass>TestElement</BaseClass>
2759
+ </ECEntityClass>
2760
+
2761
+ <ECRelationshipClass typeName="CIsRelatedToD" strength="referencing" modifier="Sealed">
2762
+ <BaseClass>bis:ElementRefersToElements</BaseClass>
2763
+ <Source multiplicity="(0..*)" roleLabel="IsRelatedTo" polymorphic="true">
2764
+ <Class class="ChildC"/>
2765
+ </Source>
2766
+ <Target multiplicity="(0..*)" roleLabel="IsRelatedTo (Reversed)" polymorphic="true">
2767
+ <Class class="ChildD"/>
2768
+ </Target>
2769
+ </ECRelationshipClass>
2770
+ </ECSchema>`
2771
+ ]);
2772
+ // Enable ECSQL write validation and verify it's set
2773
+ const pragmaRows = IModelTestUtils.executeQuery(testImodel, `PRAGMA validate_ecsql_writes=true`);
2774
+ assert.exists(pragmaRows);
2775
+ assert.strictEqual(pragmaRows[0].validate_ecsql_writes, true);
2776
+ // Ensure ADrivesB table is empty before test
2777
+ validateADrivesBRowCount(testImodel, 0);
2778
+ // Create a physical model and spatial category if needed
2779
+ const [, newModelId] = IModelTestUtils.createAndInsertPhysicalPartitionAndModel(testImodel, Code.createEmpty(), true);
2780
+ let spatialCategoryId = SpatialCategory.queryCategoryIdByName(testImodel, IModel.dictionaryId, "MySpatialCategory");
2781
+ if (!spatialCategoryId) {
2782
+ spatialCategoryId = SpatialCategory.insert(testImodel, IModel.dictionaryId, "MySpatialCategory", new SubCategoryAppearance({ color: ColorDef.fromString("rgb(255,0,0)").toJSON() }));
2783
+ }
2784
+ // Insert a ChildB element to be referenced by ChildA
2785
+ const idB = insertElement(testImodel, newModelId, spatialCategoryId, "TestRelationSchema:ChildB", "ChildBElement");
2786
+ assert.isTrue(Id64.isValidId64(idB), "Insert ChildBElement failed");
2787
+ testImodel.saveChanges();
2788
+ // Prepare base props for ChildA
2789
+ const elementProps = createElemProps(testImodel, newModelId, spatialCategoryId, "TestRelationSchema:ChildA");
2790
+ // Test various relationship class names for navigation property
2791
+ const testCases = [
2792
+ { name: "trs:ADrivesB", shouldSucceed: true, expectedRows: 1 },
2793
+ { name: "trs.FakeClass", shouldSucceed: true, expectedRows: 0 },
2794
+ { name: "trs:ChildA", shouldSucceed: false, expectedRows: 0 },
2795
+ { name: "trs:ChildB", shouldSucceed: false, expectedRows: 0 },
2796
+ { name: "trs:CIsRelatedToD", shouldSucceed: false, expectedRows: 0 },
2797
+ ];
2798
+ for (const { name, shouldSucceed, expectedRows } of testCases) {
2799
+ const elemRef = new RelatedElement({ id: idB, relClassName: name });
2800
+ elementProps.navPropChildB = elemRef;
2801
+ elementProps.name = "ChildAElement";
2802
+ const geomElement = testImodel.elements.createElement(elementProps);
2803
+ let idA;
2804
+ try {
2805
+ idA = testImodel.elements.insertElement(geomElement.toJSON());
2806
+ if (shouldSucceed)
2807
+ assert.isTrue(Id64.isValidId64(idA), `Insert should have succeeded for ${name}.`);
2808
+ else
2809
+ assert.fail(`Insert should have failed for ${name}.`);
2810
+ }
2811
+ catch (err) {
2812
+ if (shouldSucceed)
2813
+ assert.fail(`Insert should have succeeded for ${name}. Error: ${err.message}`);
2814
+ // If should not succeed, error is expected
2815
+ }
2816
+ // Validate row count in ADrivesB table
2817
+ validateADrivesBRowCount(testImodel, expectedRows);
2818
+ // If insert succeeded, test update and delete scenarios
2819
+ if (expectedRows === 1 && idA !== undefined) {
2820
+ validateNavProp(testImodel, { id: idB, relClassName: "TestRelationSchema.ADrivesB" });
2821
+ const editElem = testImodel.elements.getElement(idA);
2822
+ editElem.navPropChildB = new RelatedElement({ id: idB, relClassName: "trs.FakeClass" });
2823
+ editElem.name = "ChildAElementUpdated";
2824
+ testImodel.elements.updateElement(editElem);
2825
+ validateADrivesBRowCount(testImodel, 1);
2826
+ validateNavProp(testImodel, { id: idB, relClassName: "TestRelationSchema.ADrivesB" });
2827
+ const editedElem = testImodel.elements.getElement(idA);
2828
+ assert.equal(editedElem.name, "ChildAElementUpdated", `Expected name to be "ChildAElementUpdated" after update, but got "${editedElem.name}"`);
2829
+ assert.strictEqual(editedElem.navPropChildB.relClassName, "TestRelationSchema.ADrivesB", `Expected navPropChildB to be "TestRelationSchema.ADrivesB" after update, but got "${editedElem.navPropChildB}"`);
2830
+ // Set the nav prop value to null
2831
+ editElem.name = "ChildAElementNulled";
2832
+ editElem.navPropChildB = null;
2833
+ testImodel.elements.updateElement(editElem);
2834
+ validateADrivesBRowCount(testImodel, 0);
2835
+ const nulledElem = testImodel.elements.getElement(idA);
2836
+ assert.equal(nulledElem.name, "ChildAElementNulled", `Expected name to be "ChildAElementNulled" after nulling, but got "${nulledElem.name}"`);
2837
+ assert.isUndefined(nulledElem.navPropChildB, `Expected navPropChildB to be undefined after nulling, but got "${nulledElem.navPropChildB}"`);
2838
+ if (shouldSucceed) {
2839
+ // Delete the element
2840
+ testImodel.elements.deleteElement(idA);
2841
+ assert.isUndefined(testImodel.elements.tryGetElement(idA), `Expected element with id ${idA} to be deleted, but it still exists.`);
2842
+ }
2843
+ }
2844
+ testImodel.abandonChanges();
2845
+ }
2846
+ testImodel.close();
2847
+ });
2693
2848
  });
2694
2849
  //# sourceMappingURL=IModel.test.js.map