@itwin/core-backend 5.3.0-dev.8 → 5.3.0

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 (191) hide show
  1. package/CHANGELOG.md +52 -1
  2. package/lib/cjs/BriefcaseManager.d.ts.map +1 -1
  3. package/lib/cjs/BriefcaseManager.js +14 -0
  4. package/lib/cjs/BriefcaseManager.js.map +1 -1
  5. package/lib/cjs/CloudSqlite.d.ts +2 -0
  6. package/lib/cjs/CloudSqlite.d.ts.map +1 -1
  7. package/lib/cjs/CloudSqlite.js.map +1 -1
  8. package/lib/cjs/DisplayStyle.d.ts +2 -2
  9. package/lib/cjs/DisplayStyle.d.ts.map +1 -1
  10. package/lib/cjs/DisplayStyle.js +4 -4
  11. package/lib/cjs/DisplayStyle.js.map +1 -1
  12. package/lib/cjs/ECDb.js +1 -1
  13. package/lib/cjs/ECDb.js.map +1 -1
  14. package/lib/cjs/Element.d.ts +31 -3
  15. package/lib/cjs/Element.d.ts.map +1 -1
  16. package/lib/cjs/Element.js +55 -3
  17. package/lib/cjs/Element.js.map +1 -1
  18. package/lib/cjs/ElementAspect.d.ts +24 -1
  19. package/lib/cjs/ElementAspect.d.ts.map +1 -1
  20. package/lib/cjs/ElementAspect.js +102 -1
  21. package/lib/cjs/ElementAspect.js.map +1 -1
  22. package/lib/cjs/IModelDb.d.ts +26 -3
  23. package/lib/cjs/IModelDb.d.ts.map +1 -1
  24. package/lib/cjs/IModelDb.js +60 -5
  25. package/lib/cjs/IModelDb.js.map +1 -1
  26. package/lib/cjs/IModelElementCloneContext.d.ts +1 -1
  27. package/lib/cjs/IModelElementCloneContext.d.ts.map +1 -1
  28. package/lib/cjs/IModelElementCloneContext.js +2 -2
  29. package/lib/cjs/IModelElementCloneContext.js.map +1 -1
  30. package/lib/cjs/IModelHost.d.ts +1 -2
  31. package/lib/cjs/IModelHost.d.ts.map +1 -1
  32. package/lib/cjs/IModelHost.js +9 -17
  33. package/lib/cjs/IModelHost.js.map +1 -1
  34. package/lib/cjs/Material.d.ts +1 -1
  35. package/lib/cjs/Material.d.ts.map +1 -1
  36. package/lib/cjs/Material.js +2 -2
  37. package/lib/cjs/Material.js.map +1 -1
  38. package/lib/cjs/NavigationRelationship.d.ts +15 -0
  39. package/lib/cjs/NavigationRelationship.d.ts.map +1 -1
  40. package/lib/cjs/NavigationRelationship.js +22 -1
  41. package/lib/cjs/NavigationRelationship.js.map +1 -1
  42. package/lib/cjs/Relationship.d.ts +5 -0
  43. package/lib/cjs/Relationship.d.ts.map +1 -1
  44. package/lib/cjs/Relationship.js +7 -0
  45. package/lib/cjs/Relationship.js.map +1 -1
  46. package/lib/cjs/TileStorage.d.ts +1 -1
  47. package/lib/cjs/TileStorage.d.ts.map +1 -1
  48. package/lib/cjs/TileStorage.js.map +1 -1
  49. package/lib/cjs/TxnManager.d.ts +8 -0
  50. package/lib/cjs/TxnManager.d.ts.map +1 -1
  51. package/lib/cjs/TxnManager.js +30 -2
  52. package/lib/cjs/TxnManager.js.map +1 -1
  53. package/lib/cjs/ViewDefinition.d.ts +1 -1
  54. package/lib/cjs/ViewDefinition.d.ts.map +1 -1
  55. package/lib/cjs/ViewDefinition.js +2 -2
  56. package/lib/cjs/ViewDefinition.js.map +1 -1
  57. package/lib/cjs/annotations/ElementDrivesTextAnnotation.d.ts +15 -1
  58. package/lib/cjs/annotations/ElementDrivesTextAnnotation.d.ts.map +1 -1
  59. package/lib/cjs/annotations/ElementDrivesTextAnnotation.js +36 -23
  60. package/lib/cjs/annotations/ElementDrivesTextAnnotation.js.map +1 -1
  61. package/lib/cjs/annotations/LeaderGeometry.d.ts +13 -1
  62. package/lib/cjs/annotations/LeaderGeometry.d.ts.map +1 -1
  63. package/lib/cjs/annotations/LeaderGeometry.js +88 -10
  64. package/lib/cjs/annotations/LeaderGeometry.js.map +1 -1
  65. package/lib/cjs/annotations/TextAnnotationElement.d.ts +6 -5
  66. package/lib/cjs/annotations/TextAnnotationElement.d.ts.map +1 -1
  67. package/lib/cjs/annotations/TextAnnotationElement.js +33 -14
  68. package/lib/cjs/annotations/TextAnnotationElement.js.map +1 -1
  69. package/lib/cjs/annotations/TextBlockLayout.d.ts.map +1 -1
  70. package/lib/cjs/annotations/TextBlockLayout.js +2 -1
  71. package/lib/cjs/annotations/TextBlockLayout.js.map +1 -1
  72. package/lib/cjs/internal/annotations/fields.d.ts +3 -2
  73. package/lib/cjs/internal/annotations/fields.d.ts.map +1 -1
  74. package/lib/cjs/internal/annotations/fields.js +12 -5
  75. package/lib/cjs/internal/annotations/fields.js.map +1 -1
  76. package/lib/esm/BriefcaseManager.d.ts.map +1 -1
  77. package/lib/esm/BriefcaseManager.js +14 -0
  78. package/lib/esm/BriefcaseManager.js.map +1 -1
  79. package/lib/esm/CloudSqlite.d.ts +2 -0
  80. package/lib/esm/CloudSqlite.d.ts.map +1 -1
  81. package/lib/esm/CloudSqlite.js.map +1 -1
  82. package/lib/esm/DisplayStyle.d.ts +2 -2
  83. package/lib/esm/DisplayStyle.d.ts.map +1 -1
  84. package/lib/esm/DisplayStyle.js +4 -4
  85. package/lib/esm/DisplayStyle.js.map +1 -1
  86. package/lib/esm/ECDb.js +1 -1
  87. package/lib/esm/ECDb.js.map +1 -1
  88. package/lib/esm/Element.d.ts +31 -3
  89. package/lib/esm/Element.d.ts.map +1 -1
  90. package/lib/esm/Element.js +55 -4
  91. package/lib/esm/Element.js.map +1 -1
  92. package/lib/esm/ElementAspect.d.ts +24 -1
  93. package/lib/esm/ElementAspect.d.ts.map +1 -1
  94. package/lib/esm/ElementAspect.js +101 -1
  95. package/lib/esm/ElementAspect.js.map +1 -1
  96. package/lib/esm/IModelDb.d.ts +26 -3
  97. package/lib/esm/IModelDb.d.ts.map +1 -1
  98. package/lib/esm/IModelDb.js +60 -5
  99. package/lib/esm/IModelDb.js.map +1 -1
  100. package/lib/esm/IModelElementCloneContext.d.ts +1 -1
  101. package/lib/esm/IModelElementCloneContext.d.ts.map +1 -1
  102. package/lib/esm/IModelElementCloneContext.js +2 -2
  103. package/lib/esm/IModelElementCloneContext.js.map +1 -1
  104. package/lib/esm/IModelHost.d.ts +1 -2
  105. package/lib/esm/IModelHost.d.ts.map +1 -1
  106. package/lib/esm/IModelHost.js +10 -18
  107. package/lib/esm/IModelHost.js.map +1 -1
  108. package/lib/esm/Material.d.ts +1 -1
  109. package/lib/esm/Material.d.ts.map +1 -1
  110. package/lib/esm/Material.js +2 -2
  111. package/lib/esm/Material.js.map +1 -1
  112. package/lib/esm/NavigationRelationship.d.ts +15 -0
  113. package/lib/esm/NavigationRelationship.d.ts.map +1 -1
  114. package/lib/esm/NavigationRelationship.js +19 -0
  115. package/lib/esm/NavigationRelationship.js.map +1 -1
  116. package/lib/esm/Relationship.d.ts +5 -0
  117. package/lib/esm/Relationship.d.ts.map +1 -1
  118. package/lib/esm/Relationship.js +7 -0
  119. package/lib/esm/Relationship.js.map +1 -1
  120. package/lib/esm/TileStorage.d.ts +1 -1
  121. package/lib/esm/TileStorage.d.ts.map +1 -1
  122. package/lib/esm/TileStorage.js.map +1 -1
  123. package/lib/esm/TxnManager.d.ts +8 -0
  124. package/lib/esm/TxnManager.d.ts.map +1 -1
  125. package/lib/esm/TxnManager.js +30 -2
  126. package/lib/esm/TxnManager.js.map +1 -1
  127. package/lib/esm/ViewDefinition.d.ts +1 -1
  128. package/lib/esm/ViewDefinition.d.ts.map +1 -1
  129. package/lib/esm/ViewDefinition.js +2 -2
  130. package/lib/esm/ViewDefinition.js.map +1 -1
  131. package/lib/esm/annotations/ElementDrivesTextAnnotation.d.ts +15 -1
  132. package/lib/esm/annotations/ElementDrivesTextAnnotation.d.ts.map +1 -1
  133. package/lib/esm/annotations/ElementDrivesTextAnnotation.js +37 -24
  134. package/lib/esm/annotations/ElementDrivesTextAnnotation.js.map +1 -1
  135. package/lib/esm/annotations/LeaderGeometry.d.ts +13 -1
  136. package/lib/esm/annotations/LeaderGeometry.d.ts.map +1 -1
  137. package/lib/esm/annotations/LeaderGeometry.js +89 -12
  138. package/lib/esm/annotations/LeaderGeometry.js.map +1 -1
  139. package/lib/esm/annotations/TextAnnotationElement.d.ts +6 -5
  140. package/lib/esm/annotations/TextAnnotationElement.d.ts.map +1 -1
  141. package/lib/esm/annotations/TextAnnotationElement.js +33 -14
  142. package/lib/esm/annotations/TextAnnotationElement.js.map +1 -1
  143. package/lib/esm/annotations/TextBlockLayout.d.ts.map +1 -1
  144. package/lib/esm/annotations/TextBlockLayout.js +2 -1
  145. package/lib/esm/annotations/TextBlockLayout.js.map +1 -1
  146. package/lib/esm/internal/annotations/fields.d.ts +3 -2
  147. package/lib/esm/internal/annotations/fields.d.ts.map +1 -1
  148. package/lib/esm/internal/annotations/fields.js +11 -5
  149. package/lib/esm/internal/annotations/fields.js.map +1 -1
  150. package/lib/esm/test/ElementDrivesElement.test.d.ts +93 -0
  151. package/lib/esm/test/ElementDrivesElement.test.d.ts.map +1 -0
  152. package/lib/esm/test/ElementDrivesElement.test.js +862 -0
  153. package/lib/esm/test/ElementDrivesElement.test.js.map +1 -0
  154. package/lib/esm/test/ElementLRUCache.test.js +13 -0
  155. package/lib/esm/test/ElementLRUCache.test.js.map +1 -1
  156. package/lib/esm/test/IModelHost.test.js +17 -11
  157. package/lib/esm/test/IModelHost.test.js.map +1 -1
  158. package/lib/esm/test/annotations/Fields.test.js +44 -0
  159. package/lib/esm/test/annotations/Fields.test.js.map +1 -1
  160. package/lib/esm/test/annotations/LeaderGeometry.test.js +47 -2
  161. package/lib/esm/test/annotations/LeaderGeometry.test.js.map +1 -1
  162. package/lib/esm/test/annotations/TextAnnotation.test.js +120 -31
  163. package/lib/esm/test/annotations/TextAnnotation.test.js.map +1 -1
  164. package/lib/esm/test/ecdb/ConcurrentQuery.test.js +2 -2
  165. package/lib/esm/test/ecdb/ConcurrentQuery.test.js.map +1 -1
  166. package/lib/esm/test/ecdb/ECSqlStatement.test.js +33 -2
  167. package/lib/esm/test/ecdb/ECSqlStatement.test.js.map +1 -1
  168. package/lib/esm/test/element/ProjectInformationRecord.test.d.ts +2 -0
  169. package/lib/esm/test/element/ProjectInformationRecord.test.d.ts.map +1 -0
  170. package/lib/esm/test/element/ProjectInformationRecord.test.js +80 -0
  171. package/lib/esm/test/element/ProjectInformationRecord.test.js.map +1 -0
  172. package/lib/esm/test/element/SheetInformationAspect.test.d.ts +2 -0
  173. package/lib/esm/test/element/SheetInformationAspect.test.d.ts.map +1 -0
  174. package/lib/esm/test/element/SheetInformationAspect.test.js +182 -0
  175. package/lib/esm/test/element/SheetInformationAspect.test.js.map +1 -0
  176. package/lib/esm/test/hubaccess/Rebase.test.js +169 -2
  177. package/lib/esm/test/hubaccess/Rebase.test.js.map +1 -1
  178. package/lib/esm/test/imodel/IModel.test.js +175 -2
  179. package/lib/esm/test/imodel/IModel.test.js.map +1 -1
  180. package/lib/esm/test/incrementalSchemaLocater/ECSqlQueries.test.js.map +1 -1
  181. package/lib/esm/test/standalone/ChangesetReader.test.js +63 -60
  182. package/lib/esm/test/standalone/ChangesetReader.test.js.map +1 -1
  183. package/lib/esm/test/standalone/DisplayStyle.test.js +6 -6
  184. package/lib/esm/test/standalone/DisplayStyle.test.js.map +1 -1
  185. package/lib/esm/test/standalone/ElementGraphics.test.js +75 -6
  186. package/lib/esm/test/standalone/ElementGraphics.test.js.map +1 -1
  187. package/lib/esm/test/standalone/RenderMaterialElement.test.js +4 -4
  188. package/lib/esm/test/standalone/RenderMaterialElement.test.js.map +1 -1
  189. package/lib/esm/test/standalone/TxnManager.test.js +33 -5
  190. package/lib/esm/test/standalone/TxnManager.test.js.map +1 -1
  191. package/package.json +16 -18
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ProjectInformationRecord.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ProjectInformationRecord.test.d.ts","sourceRoot":"","sources":["../../../../src/test/element/ProjectInformationRecord.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,80 @@
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
+ * See LICENSE.md in the project root for license terms and full copyright notice.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ import { expect } from "chai";
6
+ import { IModelTestUtils } from "../IModelTestUtils";
7
+ import { SnapshotDb } from "../../IModelDb";
8
+ import { IModel } from "@itwin/core-common";
9
+ import { ProjectInformationRecord } from "../../Element";
10
+ import { SubjectOwnsProjectInformationRecord } from "../../NavigationRelationship";
11
+ import { DbResult } from "@itwin/core-bentley";
12
+ describe("ProjectInformationRecord", () => {
13
+ describe("with BisCore < 00.01.25", () => {
14
+ let db;
15
+ before(() => {
16
+ const seedFileName = IModelTestUtils.resolveAssetFile("mirukuru.ibim");
17
+ const testFileName = IModelTestUtils.prepareOutputFile("ProjectInformationRecord", "OldBisCore.bim");
18
+ db = IModelTestUtils.createSnapshotFromSeed(testFileName, seedFileName);
19
+ });
20
+ after(() => db.close());
21
+ it("throws", () => {
22
+ const projectProps = {
23
+ projectNumber: "num",
24
+ projectName: "name",
25
+ location: "place",
26
+ };
27
+ expect(() => ProjectInformationRecord.create({
28
+ iModel: db,
29
+ parentSubjectId: IModel.rootSubjectId,
30
+ ...projectProps,
31
+ })).to.throw("ProjectInformationRecord requires BisCore v01.00.25 or newer");
32
+ });
33
+ });
34
+ describe("with BisCore >= 00.01.25", () => {
35
+ let db;
36
+ before(async () => {
37
+ db = SnapshotDb.createEmpty(IModelTestUtils.prepareOutputFile("ProjectInformationRecord", "NewBisCore.bim"), { rootSubject: { name: "ProjectInformationRecord" } });
38
+ });
39
+ after(() => db.close());
40
+ it("inserts element and creates relationship", () => {
41
+ function countRelationships() {
42
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
43
+ return db.withPreparedStatement(`SELECT COUNT(*) FROM ${SubjectOwnsProjectInformationRecord.classFullName}`, (stmt) => {
44
+ expect(stmt.step()).to.equal(DbResult.BE_SQLITE_ROW);
45
+ return stmt.getValue(0).getInteger();
46
+ });
47
+ }
48
+ expect(countRelationships()).to.equal(0);
49
+ const projectProps = {
50
+ projectNumber: "num",
51
+ projectName: "name",
52
+ location: "place",
53
+ };
54
+ let record = ProjectInformationRecord.create({
55
+ iModel: db,
56
+ parentSubjectId: IModel.rootSubjectId,
57
+ ...projectProps,
58
+ });
59
+ const recordId = record.insert();
60
+ record = db.elements.getElement(recordId);
61
+ expect(record).instanceof(ProjectInformationRecord);
62
+ expect(record.projectInformation).to.deep.equal(projectProps);
63
+ expect(countRelationships()).to.equal(1);
64
+ });
65
+ it("throws if parent is not a Subject", () => {
66
+ const projectProps = {
67
+ projectNumber: "num",
68
+ projectName: "name",
69
+ location: "place",
70
+ };
71
+ const record = ProjectInformationRecord.create({
72
+ iModel: db,
73
+ parentSubjectId: IModel.dictionaryId,
74
+ ...projectProps,
75
+ });
76
+ expect(() => record.insert()).to.throw("ProjectInformationRecord must be a child of a Subject");
77
+ });
78
+ });
79
+ });
80
+ //# sourceMappingURL=ProjectInformationRecord.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ProjectInformationRecord.test.js","sourceRoot":"","sources":["../../../../src/test/element/ProjectInformationRecord.test.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAsB,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,mCAAmC,EAAE,MAAM,8BAA8B,CAAC;AACnF,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAE/C,QAAQ,CAAC,0BAA0B,EAAE,GAAG,EAAE;IACxC,QAAQ,CAAC,yBAAyB,EAAE,GAAG,EAAE;QACvC,IAAI,EAAc,CAAC;QAEnB,MAAM,CAA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B,CAAC;YAEF,MAAM,MAAM,GAAG,wBAAwB,CAAC,MAAM,CAAC;gBAC7C,MAAM,EAAE,EAAE;gBACV,eAAe,EAAE,MAAM,CAAC,YAAY;gBACpC,GAAG,YAAY;aAChB,CAAC,CAAC;YAEH,MAAM,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,uDAAuD,CAAC,CAAC;QAClG,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\nimport { expect } from \"chai\";\nimport { IModelTestUtils } from \"../IModelTestUtils\";\nimport { SnapshotDb } from \"../../IModelDb\";\nimport { IModel, ProjectInformation } from \"@itwin/core-common\";\nimport { ProjectInformationRecord } from \"../../Element\";\nimport { SubjectOwnsProjectInformationRecord } from \"../../NavigationRelationship\";\nimport { DbResult } from \"@itwin/core-bentley\";\n\ndescribe(\"ProjectInformationRecord\", () => {\n describe(\"with BisCore < 00.01.25\", () => {\n let db: SnapshotDb;\n\n before(() => {\n const seedFileName = IModelTestUtils.resolveAssetFile(\"mirukuru.ibim\");\n const testFileName = IModelTestUtils.prepareOutputFile(\"ProjectInformationRecord\", \"OldBisCore.bim\");\n db = IModelTestUtils.createSnapshotFromSeed(testFileName, seedFileName);\n });\n\n after(() => db.close());\n\n it(\"throws\", () => {\n const projectProps: ProjectInformation = {\n projectNumber: \"num\",\n projectName: \"name\",\n location: \"place\",\n };\n\n expect(() => ProjectInformationRecord.create({\n iModel: db,\n parentSubjectId: IModel.rootSubjectId,\n ...projectProps,\n })).to.throw(\"ProjectInformationRecord requires BisCore v01.00.25 or newer\");\n });\n });\n\n describe(\"with BisCore >= 00.01.25\", () => {\n let db: SnapshotDb;\n\n before(async () => {\n db = SnapshotDb.createEmpty(\n IModelTestUtils.prepareOutputFile(\"ProjectInformationRecord\", \"NewBisCore.bim\"),\n { rootSubject: { name: \"ProjectInformationRecord\" } }\n );\n });\n\n after(() => db.close());\n\n it(\"inserts element and creates relationship\", () => {\n function countRelationships(): number {\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n return db.withPreparedStatement(`SELECT COUNT(*) FROM ${SubjectOwnsProjectInformationRecord.classFullName}`, (stmt) => {\n expect(stmt.step()).to.equal(DbResult.BE_SQLITE_ROW);\n return stmt.getValue(0).getInteger();\n });\n }\n\n expect(countRelationships()).to.equal(0);\n\n const projectProps: ProjectInformation = {\n projectNumber: \"num\",\n projectName: \"name\",\n location: \"place\",\n };\n\n let record = ProjectInformationRecord.create({\n iModel: db,\n parentSubjectId: IModel.rootSubjectId,\n ...projectProps,\n });\n\n const recordId = record.insert();\n\n record = db.elements.getElement<ProjectInformationRecord>(recordId);\n expect(record).instanceof(ProjectInformationRecord);\n expect(record.projectInformation).to.deep.equal(projectProps);\n\n expect(countRelationships()).to.equal(1);\n })\n\n it(\"throws if parent is not a Subject\", () => {\n const projectProps: ProjectInformation = {\n projectNumber: \"num\",\n projectName: \"name\",\n location: \"place\",\n };\n\n const record = ProjectInformationRecord.create({\n iModel: db,\n parentSubjectId: IModel.dictionaryId,\n ...projectProps,\n });\n\n expect(() => record.insert()).to.throw(\"ProjectInformationRecord must be a child of a Subject\");\n });\n });\n});\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=SheetInformationAspect.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SheetInformationAspect.test.d.ts","sourceRoot":"","sources":["../../../../src/test/element/SheetInformationAspect.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,182 @@
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
+ * See LICENSE.md in the project root for license terms and full copyright notice.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ import { expect } from "chai";
6
+ import { SnapshotDb } from "../../IModelDb";
7
+ import { IModelTestUtils } from "../IModelTestUtils";
8
+ import { DbResult, Guid } from "@itwin/core-bentley";
9
+ import { DocumentPartition, Sheet } from "../../Element";
10
+ import { DocumentListModel, SheetModel } from "../../Model";
11
+ import { IModel } from "@itwin/core-common";
12
+ import { SheetInformationAspect } from "../../ElementAspect";
13
+ import { SheetOwnsSheetInformationAspect } from "../../NavigationRelationship";
14
+ async function getOrCreateDocumentList(iModel) {
15
+ const documentListName = "SheetList";
16
+ let documentListModelId;
17
+ // Attempt to find an existing document partition and document list model
18
+ const ids = iModel.queryEntityIds({ from: DocumentPartition.classFullName, where: `CodeValue = '${documentListName}'` });
19
+ if (ids.size === 1) {
20
+ documentListModelId = ids.values().next().value;
21
+ }
22
+ // If they do not exist, create the document partition and document list model
23
+ if (documentListModelId === undefined) {
24
+ const subjectId = iModel.elements.getRootSubject().id;
25
+ await iModel.locks.acquireLocks({
26
+ shared: subjectId,
27
+ });
28
+ documentListModelId = DocumentListModel.insert(iModel, subjectId, documentListName);
29
+ }
30
+ return documentListModelId;
31
+ }
32
+ ;
33
+ async function insertSheet(iModel) {
34
+ const sheetName = Guid.createValue();
35
+ const createSheetProps = {
36
+ height: 42,
37
+ width: 42,
38
+ scale: 42,
39
+ };
40
+ // Get or make documentListModelId
41
+ const modelId = await getOrCreateDocumentList(iModel);
42
+ // Acquire locks and create sheet
43
+ await iModel.locks.acquireLocks({ shared: modelId });
44
+ const sheetElementProps = {
45
+ ...createSheetProps,
46
+ classFullName: Sheet.classFullName,
47
+ code: Sheet.createCode(iModel, modelId, sheetName),
48
+ model: modelId,
49
+ };
50
+ const sheetElementId = iModel.elements.insertElement(sheetElementProps);
51
+ const sheetModelProps = {
52
+ classFullName: SheetModel.classFullName,
53
+ modeledElement: { id: sheetElementId, relClassName: "BisCore:ModelModelsElement" },
54
+ };
55
+ const sheetModelId = iModel.models.insertModel(sheetModelProps);
56
+ return sheetModelId;
57
+ }
58
+ ;
59
+ describe("SheetInformationAspect", () => {
60
+ describe("with BisCore < 00.01.25", () => {
61
+ let db;
62
+ let sheetId;
63
+ before(async () => {
64
+ const seedFileName = IModelTestUtils.resolveAssetFile("mirukuru.ibim");
65
+ const testFileName = IModelTestUtils.prepareOutputFile("SheetInformationAspect", "OldBisCore.bim");
66
+ db = IModelTestUtils.createSnapshotFromSeed(testFileName, seedFileName);
67
+ sheetId = await insertSheet(db);
68
+ });
69
+ after(() => db.close());
70
+ describe("getSheetInformation", () => {
71
+ it("returns undefined", () => {
72
+ expect(SheetInformationAspect.getSheetInformation(sheetId, db)).to.be.undefined;
73
+ });
74
+ });
75
+ describe("setSheetInformation", () => {
76
+ it("throws", () => {
77
+ expect(() => SheetInformationAspect.setSheetInformation({ designedBy: "me" }, sheetId, db)).to.throw("SheetInformationAspect requires BisCore v01.00.25 or newer");
78
+ });
79
+ });
80
+ });
81
+ describe("with BisCore >= 00.01.25", () => {
82
+ let db;
83
+ const designedDate = new Date("2011-10-05T14:48:00.000Z");
84
+ expect(designedDate.toISOString()).to.equal("2011-10-05T14:48:00.000Z");
85
+ before(async () => {
86
+ db = SnapshotDb.createEmpty(IModelTestUtils.prepareOutputFile("SheetInformationAspect", "NewBisCore.bim"), { rootSubject: { name: "SheetInformationAspect" } });
87
+ });
88
+ after(() => db.close());
89
+ function getSheetInfo(elemId) {
90
+ return SheetInformationAspect.getSheetInformation(elemId, db);
91
+ }
92
+ function setSheetInfo(elemId, info) {
93
+ SheetInformationAspect.setSheetInformation(info, elemId, db);
94
+ }
95
+ describe("getSheetInformation", () => {
96
+ it("returns undefined if no aspect exists", async () => {
97
+ const sheetId = await insertSheet(db);
98
+ expect(getSheetInfo(sheetId)).to.be.undefined;
99
+ });
100
+ it("returns undefined if element is not a valid Sheet", () => {
101
+ expect(getSheetInfo(IModel.rootSubjectId)).to.be.undefined;
102
+ });
103
+ it("returns information if aspect exists", async () => {
104
+ const sheetId = await insertSheet(db);
105
+ const info = { designedBy: "me", checkedBy: "you", designedDate, drawnBy: "Bob Ross" };
106
+ setSheetInfo(sheetId, info);
107
+ expect(getSheetInfo(sheetId)).to.deep.equal(info);
108
+ });
109
+ });
110
+ describe("setSheetInformation", () => {
111
+ it("inserts aspect if it doesn't already exist", async () => {
112
+ const sheetId = await insertSheet(db);
113
+ expect(getSheetInfo(sheetId)).to.be.undefined;
114
+ const info = { designedBy: "me", checkedBy: "you", designedDate, drawnBy: "Bob Ross" };
115
+ setSheetInfo(sheetId, info);
116
+ expect(getSheetInfo(sheetId)).to.deep.equal(info);
117
+ });
118
+ it("omits undefined fields", async () => {
119
+ const info = { designedBy: "me" };
120
+ const sheetId = await insertSheet(db);
121
+ setSheetInfo(sheetId, info);
122
+ expect(getSheetInfo(sheetId)).to.deep.equal({ designedBy: "me", checkedBy: undefined, designedDate: undefined, drawnBy: undefined });
123
+ });
124
+ it("includes fields set to empty strings", async () => {
125
+ const info = { designedBy: "", checkedBy: "", designedDate, drawnBy: "" };
126
+ const sheetId = await insertSheet(db);
127
+ setSheetInfo(sheetId, info);
128
+ expect(getSheetInfo(sheetId)).to.deep.equal(info);
129
+ });
130
+ it("updates existing aspect", async () => {
131
+ const sheetId = await insertSheet(db);
132
+ const initialInfo = { designedBy: "me", checkedBy: "you", designedDate, drawnBy: "Bob Ross" };
133
+ setSheetInfo(sheetId, initialInfo);
134
+ expect(getSheetInfo(sheetId)).to.deep.equal(initialInfo);
135
+ const updatedInfo = { designedBy: "you", checkedBy: "me", designedDate, drawnBy: "Pablo Picasso" };
136
+ setSheetInfo(sheetId, updatedInfo);
137
+ expect(getSheetInfo(sheetId)).to.deep.equal(updatedInfo);
138
+ });
139
+ it("selectively updates existing aspect", async () => {
140
+ const sheetId = await insertSheet(db);
141
+ const initialInfo = { designedBy: "me", checkedBy: "you", designedDate, drawnBy: "Bob Ross" };
142
+ setSheetInfo(sheetId, initialInfo);
143
+ expect(getSheetInfo(sheetId)).to.deep.equal(initialInfo);
144
+ const updatedInfo = { designedBy: "my buddy Gary" };
145
+ setSheetInfo(sheetId, updatedInfo);
146
+ expect(getSheetInfo(sheetId)).to.deep.equal({ designedDate, designedBy: "my buddy Gary", checkedBy: "you", drawnBy: "Bob Ross" });
147
+ });
148
+ it("deletes existing aspect if information is undefined", async () => {
149
+ const sheetId = await insertSheet(db);
150
+ const info = { designedBy: "me", checkedBy: "you", designedDate, drawnBy: "Bob Ross" };
151
+ setSheetInfo(sheetId, info);
152
+ expect(getSheetInfo(sheetId)).to.deep.equal(info);
153
+ setSheetInfo(sheetId, undefined);
154
+ expect(getSheetInfo(sheetId)).to.be.undefined;
155
+ });
156
+ it("is a no-op if information is undefined and no aspect exists", async () => {
157
+ const sheetId = await insertSheet(db);
158
+ expect(getSheetInfo(sheetId)).to.be.undefined;
159
+ setSheetInfo(sheetId, undefined);
160
+ expect(getSheetInfo(sheetId)).to.be.undefined;
161
+ });
162
+ it("throws if element is not a Sheet", () => {
163
+ const info = { designedBy: "me", checkedBy: "you", designedDate, drawnBy: "Bob Ross" };
164
+ expect(() => setSheetInfo(IModel.rootSubjectId, info)).to.throw("SheetInformationAspect can only be applied to a Sheet element");
165
+ });
166
+ it("creates SheetOwnsSheetInformationAspect relationships", async () => {
167
+ const sheetId = await insertSheet(db);
168
+ function countRelationships() {
169
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
170
+ return db.withPreparedStatement(`SELECT COUNT(*) FROM ${SheetOwnsSheetInformationAspect.classFullName} WHERE SourceECInstanceId=${sheetId}`, (stmt) => {
171
+ expect(stmt.step()).to.equal(DbResult.BE_SQLITE_ROW);
172
+ return stmt.getValue(0).getInteger();
173
+ });
174
+ }
175
+ expect(countRelationships()).to.equal(0);
176
+ setSheetInfo(sheetId, { designedBy: "me", checkedBy: "you", designedDate, drawnBy: "Bob Ross" });
177
+ expect(countRelationships()).to.equal(1);
178
+ });
179
+ });
180
+ });
181
+ });
182
+ //# sourceMappingURL=SheetInformationAspect.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SheetInformationAspect.test.js","sourceRoot":"","sources":["../../../../src/test/element/SheetInformationAspect.test.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,EAAY,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAc,MAAM,qBAAqB,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAyB,MAAM,EAAgD,MAAM,oBAAoB,CAAC;AACjH,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,+BAA+B,EAAE,MAAM,8BAA8B,CAAC;AAE/E,KAAK,UAAU,uBAAuB,CAAC,MAAgB;IACrD,MAAM,gBAAgB,GAAG,WAAW,CAAC;IACrC,IAAI,mBAAuC,CAAC;IAE5C,yEAAyE;IACzE,MAAM,GAAG,GAAG,MAAM,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,iBAAiB,CAAC,aAAa,EAAE,KAAK,EAAE,gBAAgB,gBAAgB,GAAG,EAAC,CAAC,CAAC;IACxH,IAAI,GAAG,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;QACnB,mBAAmB,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC;IAClD,CAAC;IAED,8EAA8E;IAC9E,IAAI,mBAAmB,KAAK,SAAS,EAAE,CAAC;QACtC,MAAM,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,cAAc,EAAE,CAAC,EAAE,CAAC;QACtD,MAAM,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC;YAC9B,MAAM,EAAE,SAAS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AAC;gBACzC,YAAY,CAAC,OAAO,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,CAAC;gBACjG,MAAM,CAAC,kBAAkB,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YAC3C,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\nimport { expect } from \"chai\";\nimport { IModelDb, SnapshotDb } from \"../../IModelDb\";\nimport { IModelTestUtils } from \"../IModelTestUtils\";\nimport { DbResult, Guid, Id64String } from \"@itwin/core-bentley\";\nimport { DocumentPartition, Sheet } from \"../../Element\";\nimport { DocumentListModel, SheetModel } from \"../../Model\";\nimport { GeometricModel2dProps, IModel, RelatedElement, SheetInformation, SheetProps } from \"@itwin/core-common\";\nimport { SheetInformationAspect } from \"../../ElementAspect\";\nimport { SheetOwnsSheetInformationAspect } from \"../../NavigationRelationship\";\n\nasync function getOrCreateDocumentList(iModel: IModelDb): Promise<Id64String> {\n const documentListName = \"SheetList\";\n let documentListModelId: string | undefined;\n\n // Attempt to find an existing document partition and document list model\n const ids = iModel.queryEntityIds({ from: DocumentPartition.classFullName, where: `CodeValue = '${documentListName}'`});\n if (ids.size === 1) {\n documentListModelId = ids.values().next().value;\n }\n\n // If they do not exist, create the document partition and document list model\n if (documentListModelId === undefined) {\n const subjectId = iModel.elements.getRootSubject().id;\n await iModel.locks.acquireLocks({\n shared: subjectId,\n });\n documentListModelId = DocumentListModel.insert(iModel, subjectId, documentListName);\n }\n\n return documentListModelId;\n};\n\nasync function insertSheet(iModel: IModelDb): Promise<Id64String> {\n const sheetName = Guid.createValue();\n\n const createSheetProps = {\n height: 42,\n width: 42,\n scale: 42,\n };\n // Get or make documentListModelId\n const modelId = await getOrCreateDocumentList(iModel);\n\n // Acquire locks and create sheet\n await iModel.locks.acquireLocks({ shared: modelId });\n const sheetElementProps: SheetProps = {\n ...createSheetProps,\n classFullName: Sheet.classFullName,\n code: Sheet.createCode(iModel, modelId, sheetName),\n model: modelId,\n };\n const sheetElementId = iModel.elements.insertElement(sheetElementProps);\n\n const sheetModelProps: GeometricModel2dProps = {\n classFullName: SheetModel.classFullName,\n modeledElement: { id: sheetElementId, relClassName: \"BisCore:ModelModelsElement\" } as RelatedElement,\n };\n const sheetModelId = iModel.models.insertModel(sheetModelProps);\n\n return sheetModelId;\n};\n\ndescribe(\"SheetInformationAspect\", () => {\n describe(\"with BisCore < 00.01.25\", () => {\n let db: SnapshotDb;\n let sheetId: Id64String;\n\n before(async () => {\n const seedFileName = IModelTestUtils.resolveAssetFile(\"mirukuru.ibim\");\n const testFileName = IModelTestUtils.prepareOutputFile(\"SheetInformationAspect\", \"OldBisCore.bim\");\n db = IModelTestUtils.createSnapshotFromSeed(testFileName, seedFileName);\n sheetId = await insertSheet(db);\n });\n\n after(() => db.close());\n\n describe(\"getSheetInformation\", () => {\n it(\"returns undefined\", () => {\n expect(SheetInformationAspect.getSheetInformation(sheetId, db)).to.be.undefined;\n });\n });\n\n describe(\"setSheetInformation\", () => {\n it(\"throws\", () => {\n expect(\n () => SheetInformationAspect.setSheetInformation({ designedBy: \"me\" }, sheetId, db)\n ).to.throw(\"SheetInformationAspect requires BisCore v01.00.25 or newer\");\n });\n });\n });\n\n describe(\"with BisCore >= 00.01.25\", () => {\n let db: SnapshotDb;\n const designedDate = new Date(\"2011-10-05T14:48:00.000Z\");\n expect(designedDate.toISOString()).to.equal(\"2011-10-05T14:48:00.000Z\");\n\n before(async () => {\n db = SnapshotDb.createEmpty(\n IModelTestUtils.prepareOutputFile(\"SheetInformationAspect\", \"NewBisCore.bim\"),\n { rootSubject: { name: \"SheetInformationAspect\" } }\n );\n });\n\n after(() => db.close());\n\n function getSheetInfo(elemId: string): SheetInformation | undefined {\n return SheetInformationAspect.getSheetInformation(elemId, db);\n }\n\n function setSheetInfo(elemId: string, info: SheetInformation | undefined): void {\n SheetInformationAspect.setSheetInformation(info, elemId, db);\n }\n\n describe(\"getSheetInformation\", () => {\n it(\"returns undefined if no aspect exists\", async () => {\n const sheetId = await insertSheet(db);\n expect(getSheetInfo(sheetId)).to.be.undefined;\n });\n\n it(\"returns undefined if element is not a valid Sheet\", () => {\n expect(getSheetInfo(IModel.rootSubjectId)).to.be.undefined;\n });\n\n it(\"returns information if aspect exists\", async () => {\n const sheetId = await insertSheet(db);\n const info = { designedBy: \"me\", checkedBy: \"you\", designedDate, drawnBy: \"Bob Ross\" };\n setSheetInfo(sheetId, info);\n expect(getSheetInfo(sheetId)).to.deep.equal(info);\n });\n });\n\n describe(\"setSheetInformation\", () => {\n it(\"inserts aspect if it doesn't already exist\", async () => {\n const sheetId = await insertSheet(db);\n expect(getSheetInfo(sheetId)).to.be.undefined;\n\n const info = { designedBy: \"me\", checkedBy: \"you\", designedDate, drawnBy: \"Bob Ross\" };\n setSheetInfo(sheetId, info);\n expect(getSheetInfo(sheetId)).to.deep.equal(info);\n });\n\n it(\"omits undefined fields\", async () => {\n const info = { designedBy: \"me\" };\n const sheetId = await insertSheet(db);\n setSheetInfo(sheetId, info);\n expect(getSheetInfo(sheetId)).to.deep.equal({ designedBy: \"me\", checkedBy: undefined, designedDate: undefined, drawnBy: undefined });\n });\n\n it(\"includes fields set to empty strings\", async () => {\n const info = { designedBy: \"\", checkedBy: \"\", designedDate, drawnBy: \"\" };\n const sheetId = await insertSheet(db);\n setSheetInfo(sheetId, info);\n expect(getSheetInfo(sheetId)).to.deep.equal(info);\n });\n\n it(\"updates existing aspect\", async () => {\n const sheetId = await insertSheet(db);\n const initialInfo = { designedBy: \"me\", checkedBy: \"you\", designedDate, drawnBy: \"Bob Ross\" };\n setSheetInfo(sheetId, initialInfo);\n expect(getSheetInfo(sheetId)).to.deep.equal(initialInfo);\n\n const updatedInfo = { designedBy: \"you\", checkedBy: \"me\", designedDate, drawnBy: \"Pablo Picasso\" };\n setSheetInfo(sheetId, updatedInfo);\n expect(getSheetInfo(sheetId)).to.deep.equal(updatedInfo);\n });\n\n it(\"selectively updates existing aspect\", async () => {\n const sheetId = await insertSheet(db);\n const initialInfo = { designedBy: \"me\", checkedBy: \"you\", designedDate, drawnBy: \"Bob Ross\" };\n setSheetInfo(sheetId, initialInfo);\n expect(getSheetInfo(sheetId)).to.deep.equal(initialInfo);\n\n const updatedInfo = { designedBy: \"my buddy Gary\" };\n setSheetInfo(sheetId, updatedInfo);\n expect(getSheetInfo(sheetId)).to.deep.equal({ designedDate, designedBy: \"my buddy Gary\", checkedBy: \"you\", drawnBy: \"Bob Ross\" });\n });\n\n it(\"deletes existing aspect if information is undefined\", async () => {\n const sheetId = await insertSheet(db);\n const info = { designedBy: \"me\", checkedBy: \"you\", designedDate, drawnBy: \"Bob Ross\" };\n setSheetInfo(sheetId, info);\n expect(getSheetInfo(sheetId)).to.deep.equal(info);\n setSheetInfo(sheetId, undefined);\n expect(getSheetInfo(sheetId)).to.be.undefined;\n });\n\n it(\"is a no-op if information is undefined and no aspect exists\", async () => {\n const sheetId = await insertSheet(db);\n expect(getSheetInfo(sheetId)).to.be.undefined;\n setSheetInfo(sheetId, undefined);\n expect(getSheetInfo(sheetId)).to.be.undefined;\n });\n\n it(\"throws if element is not a Sheet\", () => {\n const info = { designedBy: \"me\", checkedBy: \"you\", designedDate, drawnBy: \"Bob Ross\" };\n expect(() => setSheetInfo(IModel.rootSubjectId, info)).to.throw(\"SheetInformationAspect can only be applied to a Sheet element\");\n });\n\n it(\"creates SheetOwnsSheetInformationAspect relationships\", async () => {\n const sheetId = await insertSheet(db);\n\n function countRelationships(): number {\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n return db.withPreparedStatement(`SELECT COUNT(*) FROM ${SheetOwnsSheetInformationAspect.classFullName} WHERE SourceECInstanceId=${sheetId}`, (stmt) => {\n expect(stmt.step()).to.equal(DbResult.BE_SQLITE_ROW);\n return stmt.getValue(0).getInteger();\n });\n }\n\n expect(countRelationships()).to.equal(0);\n setSheetInfo(sheetId, { designedBy: \"me\", checkedBy: \"you\", designedDate, drawnBy: \"Bob Ross\" });\n expect(countRelationships()).to.equal(1);\n });\n })\n });\n});\n"]}
@@ -2,14 +2,16 @@
2
2
  * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
3
  * See LICENSE.md in the project root for license terms and full copyright notice.
4
4
  *--------------------------------------------------------------------------------------------*/
5
+ import { Guid } from "@itwin/core-bentley";
6
+ import { Code, IModel, QueryBinder, SubCategoryAppearance } from "@itwin/core-common";
5
7
  import * as chai from "chai";
6
8
  import * as chaiAsPromised from "chai-as-promised";
7
9
  import { HubWrappers, IModelTestUtils, KnownTestLocations } from "..";
8
10
  import { BriefcaseManager, ChannelControl, DrawingCategory, IModelHost, SqliteChangesetReader } from "../../core-backend";
9
11
  import { HubMock } from "../../internal/HubMock";
10
- import { Code, IModel, SubCategoryAppearance } from "@itwin/core-common";
11
- import { Guid } from "@itwin/core-bentley";
12
12
  import { StashManager } from "../../StashManager";
13
+ import { existsSync, unlinkSync, writeFileSync } from "fs";
14
+ import * as path from "path";
13
15
  chai.use(chaiAsPromised);
14
16
  class TestIModel {
15
17
  iModelId = "";
@@ -359,6 +361,131 @@ describe("rebase changes & stashing api", function () {
359
361
  StashManager.dropAllStashes(b1);
360
362
  chai.expect(StashManager.getStashes(b1)).to.have.lengthOf(0);
361
363
  });
364
+ it("recursively calling withIndirectTxnMode()", async () => {
365
+ const b1 = await testIModel.openBriefcase();
366
+ chai.expect(b1.txns.getMode()).to.equal("direct");
367
+ b1.txns.withIndirectTxnMode(() => {
368
+ chai.expect(b1.txns.getMode()).to.equal("indirect");
369
+ });
370
+ chai.expect(b1.txns.getMode()).to.equal("direct");
371
+ b1.txns.withIndirectTxnMode(() => {
372
+ chai.expect(b1.txns.getMode()).to.equal("indirect");
373
+ b1.txns.withIndirectTxnMode(() => {
374
+ chai.expect(b1.txns.getMode()).to.equal("indirect");
375
+ b1.txns.withIndirectTxnMode(() => {
376
+ chai.expect(b1.txns.getMode()).to.equal("indirect");
377
+ b1.txns.withIndirectTxnMode(() => {
378
+ chai.expect(b1.txns.getMode()).to.equal("indirect");
379
+ });
380
+ chai.expect(b1.txns.getMode()).to.equal("indirect");
381
+ });
382
+ chai.expect(b1.txns.getMode()).to.equal("indirect");
383
+ });
384
+ });
385
+ chai.expect(b1.txns.getMode()).to.equal("direct");
386
+ chai.expect(() => b1.txns.withIndirectTxnMode(() => {
387
+ chai.expect(b1.txns.getMode()).to.equal("indirect");
388
+ throw new Error("Test error");
389
+ })).to.throw();
390
+ chai.expect(b1.txns.getMode()).to.equal("direct");
391
+ });
392
+ it("should fail to importSchemas() & importSchemaStrings() in indirect scope", async () => {
393
+ const b1 = await testIModel.openBriefcase();
394
+ const schema = `<?xml version="1.0" encoding="UTF-8"?>
395
+ <ECSchema schemaName="MySchema" alias="ms1" version="01.00.00" xmlns="http://www.bentley.com/schemas/Bentley.ECXML.3.2">
396
+ <ECSchemaReference name="BisCore" version="01.00.00" alias="bis"/>
397
+ <ECEntityClass typeName="my_class">
398
+ <BaseClass>bis:GraphicalElement2d</BaseClass>
399
+ <ECProperty propertyName="prop1" typeName="string" />
400
+ </ECEntityClass>
401
+ </ECSchema>`;
402
+ const schemaFile = path.join(KnownTestLocations.outputDir, "MySchema.01.00.00.ecschema.xml");
403
+ if (existsSync(schemaFile)) {
404
+ unlinkSync(schemaFile);
405
+ }
406
+ writeFileSync(schemaFile, schema, { encoding: "utf8" });
407
+ await chai.expect(b1.txns.withIndirectTxnModeAsync(async () => {
408
+ await b1.importSchemas([schema]);
409
+ })).to.be.rejectedWith("Cannot import schemas while in an indirect change scope");
410
+ b1.abandonChanges();
411
+ await chai.expect(b1.txns.withIndirectTxnModeAsync(async () => {
412
+ await b1.importSchemaStrings([schema]);
413
+ })).to.be.rejectedWith("Cannot import schemas while in an indirect change scope");
414
+ b1.abandonChanges();
415
+ await b1.importSchemaStrings([schema]);
416
+ b1.saveChanges();
417
+ await b1.pushChanges({ description: "import schema" });
418
+ });
419
+ it("should fail to saveChanges() & pushChanges() in indirect scope", async () => {
420
+ const b1 = await testIModel.openBriefcase();
421
+ await testIModel.insertElement(b1);
422
+ await chai.expect(b1.txns.withIndirectTxnModeAsync(async () => {
423
+ b1.saveChanges();
424
+ })).to.be.rejectedWith("Cannot save changes while in an indirect change scope");
425
+ chai.expect(() => b1.txns.withIndirectTxnMode(() => {
426
+ b1.saveChanges();
427
+ })).to.be.throws("Cannot save changes while in an indirect change scope");
428
+ b1.saveChanges();
429
+ await chai.expect(b1.txns.withIndirectTxnModeAsync(async () => {
430
+ await b1.pushChanges({ description: "test" });
431
+ })).to.be.rejectedWith("Cannot push changeset while in an indirect change scope");
432
+ await b1.pushChanges({ description: "test" });
433
+ });
434
+ it("should fail to saveFileProperty/deleteFileProperty in indirect scope", async () => {
435
+ // pull/push/saveFileProperty/deleteFileProperty should be called inside indirect change scope.
436
+ const b1 = await testIModel.openBriefcase();
437
+ b1.saveFileProperty({ namespace: "test", name: "test" }, "Hello, World");
438
+ await chai.expect(b1.txns.withIndirectTxnModeAsync(async () => {
439
+ b1.saveFileProperty({ namespace: "test", name: "test" }, "This should fail 1");
440
+ })).to.be.rejectedWith("Cannot save file property while in an indirect change scope");
441
+ chai.expect(b1.queryFilePropertyString({ namespace: "test", name: "test" })).to.equal("Hello, World");
442
+ await chai.expect(b1.txns.withIndirectTxnModeAsync(async () => {
443
+ b1.deleteFileProperty({ namespace: "test", name: "test" });
444
+ })).to.be.rejectedWith("Cannot delete file property while in an indirect change scope");
445
+ chai.expect(b1.queryFilePropertyString({ namespace: "test", name: "test" })).to.equal("Hello, World");
446
+ chai.expect(() => b1.txns.withIndirectTxnMode(() => {
447
+ b1.saveFileProperty({ namespace: "test", name: "test" }, "This should fail 2");
448
+ })).to.be.throws("Cannot save file property while in an indirect change scope");
449
+ chai.expect(b1.queryFilePropertyString({ namespace: "test", name: "test" })).to.equal("Hello, World");
450
+ chai.expect(() => b1.txns.withIndirectTxnMode(() => {
451
+ b1.deleteFileProperty({ namespace: "test", name: "test" });
452
+ })).to.be.throws("Cannot delete file property while in an indirect change scope");
453
+ b1.saveChanges();
454
+ });
455
+ it("recursively calling withIndirectTxnModeAsync()", async () => {
456
+ const b1 = await testIModel.openBriefcase();
457
+ chai.expect(b1.txns.getMode()).to.equal("direct");
458
+ await b1.txns.withIndirectTxnModeAsync(async () => {
459
+ chai.expect(b1.txns.getMode()).to.equal("indirect");
460
+ });
461
+ chai.expect(b1.txns.getMode()).to.equal("direct");
462
+ await b1.txns.withIndirectTxnModeAsync(async () => {
463
+ chai.expect(b1.txns.getMode()).to.equal("indirect");
464
+ await b1.txns.withIndirectTxnModeAsync(async () => {
465
+ chai.expect(b1.txns.getMode()).to.equal("indirect");
466
+ await b1.txns.withIndirectTxnModeAsync(async () => {
467
+ chai.expect(b1.txns.getMode()).to.equal("indirect");
468
+ await b1.txns.withIndirectTxnModeAsync(async () => {
469
+ chai.expect(b1.txns.getMode()).to.equal("indirect");
470
+ await b1.txns.withIndirectTxnModeAsync(async () => {
471
+ chai.expect(b1.txns.getMode()).to.equal("indirect");
472
+ });
473
+ chai.expect(b1.txns.getMode()).to.equal("indirect");
474
+ });
475
+ chai.expect(b1.txns.getMode()).to.equal("indirect");
476
+ });
477
+ });
478
+ b1.txns.withIndirectTxnMode(() => {
479
+ chai.expect(b1.txns.getMode()).to.equal("indirect");
480
+ });
481
+ });
482
+ chai.expect(b1.txns.getMode()).to.equal("direct");
483
+ await chai.expect(b1.txns.withIndirectTxnModeAsync(async () => {
484
+ chai.expect(b1.txns.getMode()).to.equal("indirect");
485
+ throw new Error("Test error");
486
+ })).rejectedWith(Error);
487
+ chai.expect(b1.txns.getMode()).to.equal("direct");
488
+ });
362
489
  it("should restore mutually exclusive stashes", async () => {
363
490
  const b1 = await testIModel.openBriefcase();
364
491
  // stash 1
@@ -636,5 +763,45 @@ describe("rebase changes & stashing api", function () {
636
763
  await chai.expect(b2.pushChanges({ description: `deleted child ${childId} and inserted grandchild ${grandChildId}` }))
637
764
  .to.be.rejectedWith("Foreign key conflicts in ChangeSet. Aborting rebase.");
638
765
  });
766
+ it("ECSqlReader unable to read updates after saveChanges()", async () => {
767
+ const b1 = await testIModel.openBriefcase();
768
+ const findElement = async (id) => {
769
+ const reader = b1.createQueryReader(`SELECT ECInstanceId, ec_className(ECClassId), Prop1 FROM ts.A1 WHERE ECInstanceId = ${id}`, QueryBinder.from([id]));
770
+ if (await reader.step())
771
+ return { id: reader.current[0], className: reader.current[1], prop1: reader.current[2] };
772
+ return undefined;
773
+ };
774
+ const runQuery = async (query) => {
775
+ const reader = b1.createQueryReader(query);
776
+ let rows = 0;
777
+ while (await reader.step()) {
778
+ rows++;
779
+ }
780
+ return rows;
781
+ };
782
+ const runQueryParallel = async (query, times = 1) => {
783
+ return Promise.all(new Array(times).fill(query).map(runQuery));
784
+ };
785
+ // Following query have open cached statement against BisCore.Element that will prevent
786
+ // updates from being visible until the statement is finalized.
787
+ await runQueryParallel(`SELECT $ FROM BisCore.Element`, 10);
788
+ const e1 = await testIModel.insertElement(b1);
789
+ chai.expect(await findElement(e1)).to.be.undefined;
790
+ b1.saveChanges("insert element");
791
+ const e1Props = await findElement(e1);
792
+ chai.expect(e1Props).to.exist;
793
+ await runQueryParallel(`SELECT $ FROM BisCore.Element`, 10);
794
+ const e2 = await testIModel.insertElement(b1);
795
+ chai.expect(await findElement(e2)).to.be.undefined;
796
+ b1.saveChanges("insert second element");
797
+ const e2Props = await findElement(e2);
798
+ chai.expect(e2Props).to.exist;
799
+ await runQueryParallel(`SELECT $ FROM BisCore.Element`, 10);
800
+ const e3 = await testIModel.insertElement(b1);
801
+ chai.expect(await findElement(e3)).to.be.undefined;
802
+ b1.saveChanges("insert third element");
803
+ const e3Props = await findElement(e3);
804
+ chai.expect(e3Props).to.exist;
805
+ });
639
806
  });
640
807
  //# sourceMappingURL=Rebase.test.js.map