@itwin/core-backend 5.13.0-dev.10 → 5.13.0-dev.12

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 (53) hide show
  1. package/lib/cjs/Element.d.ts +25 -1
  2. package/lib/cjs/Element.d.ts.map +1 -1
  3. package/lib/cjs/Element.js +45 -0
  4. package/lib/cjs/Element.js.map +1 -1
  5. package/lib/esm/Element.d.ts +25 -1
  6. package/lib/esm/Element.d.ts.map +1 -1
  7. package/lib/esm/Element.js +45 -0
  8. package/lib/esm/Element.js.map +1 -1
  9. package/lib/esm/test/ecdb/QueryReaders.test.js +2 -16
  10. package/lib/esm/test/ecdb/QueryReaders.test.js.map +1 -1
  11. package/lib/esm/test/ecsql/src/ECSqlTestRunner.test.js +2 -2
  12. package/lib/esm/test/ecsql/src/ECSqlTestRunner.test.js.map +1 -1
  13. package/lib/esm/test/imodel/IModelECSql.test.d.ts +2 -0
  14. package/lib/esm/test/imodel/IModelECSql.test.d.ts.map +1 -0
  15. package/lib/esm/test/imodel/IModelECSql.test.js +367 -0
  16. package/lib/esm/test/imodel/IModelECSql.test.js.map +1 -0
  17. package/lib/esm/test/imodel/IModelElements.test.d.ts +2 -0
  18. package/lib/esm/test/imodel/IModelElements.test.d.ts.map +1 -0
  19. package/lib/esm/test/imodel/IModelElements.test.js +969 -0
  20. package/lib/esm/test/imodel/IModelElements.test.js.map +1 -0
  21. package/lib/esm/test/imodel/IModelGeolocation.test.d.ts +2 -0
  22. package/lib/esm/test/imodel/IModelGeolocation.test.d.ts.map +1 -0
  23. package/lib/esm/test/imodel/IModelGeolocation.test.js +539 -0
  24. package/lib/esm/test/imodel/IModelGeolocation.test.js.map +1 -0
  25. package/lib/esm/test/imodel/IModelLifecycle.test.d.ts +2 -0
  26. package/lib/esm/test/imodel/IModelLifecycle.test.d.ts.map +1 -0
  27. package/lib/esm/test/imodel/IModelLifecycle.test.js +498 -0
  28. package/lib/esm/test/imodel/IModelLifecycle.test.js.map +1 -0
  29. package/lib/esm/test/imodel/IModelMetadata.test.d.ts +2 -0
  30. package/lib/esm/test/imodel/IModelMetadata.test.d.ts.map +1 -0
  31. package/lib/esm/test/imodel/IModelMetadata.test.js +274 -0
  32. package/lib/esm/test/imodel/IModelMetadata.test.js.map +1 -0
  33. package/lib/esm/test/imodel/IModelModels.test.d.ts +2 -0
  34. package/lib/esm/test/imodel/IModelModels.test.d.ts.map +1 -0
  35. package/lib/esm/test/imodel/IModelModels.test.js +357 -0
  36. package/lib/esm/test/imodel/IModelModels.test.js.map +1 -0
  37. package/lib/esm/test/imodel/IModelRelationships.test.d.ts +2 -0
  38. package/lib/esm/test/imodel/IModelRelationships.test.d.ts.map +1 -0
  39. package/lib/esm/test/imodel/IModelRelationships.test.js +407 -0
  40. package/lib/esm/test/imodel/IModelRelationships.test.js.map +1 -0
  41. package/lib/esm/test/imodel/IModelTestFixtures.d.ts +53 -0
  42. package/lib/esm/test/imodel/IModelTestFixtures.d.ts.map +1 -0
  43. package/lib/esm/test/imodel/IModelTestFixtures.js +107 -0
  44. package/lib/esm/test/imodel/IModelTestFixtures.js.map +1 -0
  45. package/lib/esm/test/imodel/IModelViews.test.d.ts +2 -0
  46. package/lib/esm/test/imodel/IModelViews.test.d.ts.map +1 -0
  47. package/lib/esm/test/imodel/IModelViews.test.js +199 -0
  48. package/lib/esm/test/imodel/IModelViews.test.js.map +1 -0
  49. package/package.json +13 -13
  50. package/lib/esm/test/imodel/IModel.test.d.ts +0 -2
  51. package/lib/esm/test/imodel/IModel.test.d.ts.map +0 -1
  52. package/lib/esm/test/imodel/IModel.test.js +0 -3277
  53. package/lib/esm/test/imodel/IModel.test.js.map +0 -1
@@ -0,0 +1,107 @@
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 { assert, expect } from "chai";
6
+ import * as path from "node:path";
7
+ import { IModelError } from "@itwin/core-common";
8
+ import { SnapshotDb } from "../../core-backend";
9
+ import { KnownTestLocations } from "../KnownTestLocations";
10
+ import { IModelTestUtils } from "../IModelTestUtils";
11
+ /**
12
+ * Awaits `promise` and returns the {@link IModelError} it rejected with, or `undefined` if it resolved.
13
+ *
14
+ * A rejection that is not an {@link IModelError} is rethrown rather than swallowed, so an unexpected
15
+ * failure surfaces with its original message and stack trace instead of being misreported as
16
+ * "no error was thrown". This means `undefined` unambiguously means the promise resolved.
17
+ */
18
+ export async function getIModelError(promise) {
19
+ try {
20
+ await promise;
21
+ return undefined;
22
+ }
23
+ catch (err) {
24
+ if (err instanceof IModelError)
25
+ return err;
26
+ throw err;
27
+ }
28
+ }
29
+ /** Asserts that `error` is an {@link IModelError} carrying the expected error number. */
30
+ export function expectIModelError(expectedErrorNumber, error) {
31
+ if (error === undefined)
32
+ expect.fail(`Expected an IModelError with errorNumber ${expectedErrorNumber}, but the call resolved without throwing.`);
33
+ expect(error.errorNumber).to.equal(expectedErrorNumber);
34
+ }
35
+ /** Roundtrip an entity through a JSON string and back to a new entity, asserting the serialization is stable. */
36
+ export function roundtripThroughJson(entity1) {
37
+ const string1 = JSON.stringify(entity1);
38
+ const props1 = JSON.parse(string1);
39
+ const entity2 = new entity1.constructor(props1, entity1.iModel); // create a new entity from the EntityProps
40
+ const string2 = JSON.stringify(entity2);
41
+ assert.equal(string1, string2);
42
+ return entity2;
43
+ }
44
+ /**
45
+ * Create a fresh writable snapshot copied from a seed asset. This is the single creation path for
46
+ * mutating tests (hybrid isolation) so state never leaks between tests. Compose with
47
+ * {@link importTestBim} when the test also needs the `TestBim` schema.
48
+ */
49
+ export function createIModelFromSeed(targetFileName, seedAssetName) {
50
+ const seedFile = IModelTestUtils.resolveAssetFile(seedAssetName);
51
+ const snapshotFile = IModelTestUtils.prepareOutputFile("IModel", targetFileName);
52
+ return IModelTestUtils.createSnapshotFromSeed(snapshotFile, seedFile);
53
+ }
54
+ /**
55
+ * Import the `TestBim` schema into `imodel` and return it, so this can wrap a creation call:
56
+ * `await importTestBim(createIModelFromSeed(target, seed))`.
57
+ */
58
+ export async function importTestBim(imodel) {
59
+ const schemaPathname = path.join(KnownTestLocations.assetsDir, "TestBim.ecschema.xml");
60
+ await imodel.importSchemas([schemaPathname]);
61
+ return imodel;
62
+ }
63
+ /**
64
+ * Create a fresh writable copy from a seed asset, close it, and reopen it read-only.
65
+ *
66
+ * This is the canonical way to build a shared, per-file read-only fixture under the hybrid
67
+ * isolation policy: the read-only handle can be shared safely across tests in a file because
68
+ * nothing can mutate it, while each mutating test still gets its own writable copy elsewhere.
69
+ * When `importTestBim` is set, the `TestBim` schema is imported into the writable copy before
70
+ * it is reopened read-only.
71
+ */
72
+ export async function openReadonlySeedCopy(targetFileName, seedAssetName, opts) {
73
+ const writable = createIModelFromSeed(targetFileName, seedAssetName);
74
+ if (opts?.importTestBim)
75
+ await importTestBim(writable);
76
+ const pathName = writable.pathName;
77
+ writable.close();
78
+ return SnapshotDb.openFile(pathName);
79
+ }
80
+ /** Close each provided database that is still open. Guards against `undefined` and already-closed handles. */
81
+ export function closeIfOpen(...dbs) {
82
+ for (const db of dbs) {
83
+ if (db !== undefined && db.isOpen)
84
+ db.close();
85
+ }
86
+ }
87
+ /**
88
+ * Create a tracker for the writable iModels a test file opens, so they are all closed during teardown.
89
+ *
90
+ * This is the mechanism that enforces the hybrid isolation policy for mutating tests: each test wraps
91
+ * its freshly-created writable copy in `trackMutableIModel(...)`, and the file's `afterEach`/`after`
92
+ * calls `closeTrackedIModels()` to close and forget them. `closeTrackedIModels` is idempotent, so it is
93
+ * safe to call from both hooks.
94
+ */
95
+ export function createMutableIModelTracker() {
96
+ const tracked = [];
97
+ return {
98
+ trackMutableIModel: (imodel) => {
99
+ tracked.push(imodel);
100
+ return imodel;
101
+ },
102
+ closeTrackedIModels: () => {
103
+ closeIfOpen(...tracked.splice(0));
104
+ },
105
+ };
106
+ }
107
+ //# sourceMappingURL=IModelTestFixtures.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IModelTestFixtures.js","sourceRoot":"","sources":["../../../../src/test/imodel/IModelTestFixtures.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACtC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,OAAO,EAAe,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAoB,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAI,OAAmB;IACzD,IAAI,CAAC;QACH,MAAM,OAAO,CAAC;QACd,OAAO,SAAS,CAAC;IACnB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,GAAG,YAAY,WAAW;YAC5B,OAAO,GAAG,CAAC;QACb,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC;AAED,yFAAyF;AACzF,MAAM,UAAU,iBAAiB,CAAC,mBAA4C,EAAE,KAA8B;IAC5G,IAAI,KAAK,KAAK,SAAS;QACrB,MAAM,CAAC,IAAI,CAAC,4CAA4C,mBAAmB,2CAA2C,CAAC,CAAC;IAC1H,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC;AAC1D,CAAC;AAED,iHAAiH;AACjH,MAAM,UAAU,oBAAoB,CAAC,OAAe;IAClD,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IACxC,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAgB,CAAC;IAClD,MAAM,OAAO,GAAG,IAAK,OAAO,CAAC,WAA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GAAG,GAAgC;IAC7D,KAAK,MAAM,EAAE,IAAI,GAAG,EAAE,CAAC;QACrB,IAAI,EAAE,KAAK,SAAS,IAAI,EAAE,CAAC,MAAM;YAC/B,EAAE,CAAC,KAAK,EAAE,CAAC;IACf,CAAC;AACH,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,0BAA0B;IAIxC,MAAM,OAAO,GAAe,EAAE,CAAC;IAC/B,OAAO;QACL,kBAAkB,EAAE,CAAC,MAAM,EAAE,EAAE;YAC7B,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACrB,OAAO,MAAM,CAAC;QAChB,CAAC;QACD,mBAAmB,EAAE,GAAG,EAAE;YACxB,WAAW,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;QACpC,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\nimport { assert, expect } from \"chai\";\r\nimport * as path from \"node:path\";\r\nimport { DbResult, IModelStatus } from \"@itwin/core-bentley\";\r\nimport { EntityProps, IModelError } from \"@itwin/core-common\";\r\nimport { Entity, IModelDb, SnapshotDb } from \"../../core-backend\";\r\nimport { KnownTestLocations } from \"../KnownTestLocations\";\r\nimport { IModelTestUtils } from \"../IModelTestUtils\";\r\n\r\n/**\r\n * Awaits `promise` and returns the {@link IModelError} it rejected with, or `undefined` if it resolved.\r\n *\r\n * A rejection that is not an {@link IModelError} is rethrown rather than swallowed, so an unexpected\r\n * failure surfaces with its original message and stack trace instead of being misreported as\r\n * \"no error was thrown\". This means `undefined` unambiguously means the promise resolved.\r\n */\r\nexport async function getIModelError<T>(promise: Promise<T>): Promise<IModelError | undefined> {\r\n try {\r\n await promise;\r\n return undefined;\r\n } catch (err) {\r\n if (err instanceof IModelError)\r\n return err;\r\n throw err;\r\n }\r\n}\r\n\r\n/** Asserts that `error` is an {@link IModelError} carrying the expected error number. */\r\nexport function expectIModelError(expectedErrorNumber: IModelStatus | DbResult, error: IModelError | undefined): void {\r\n if (error === undefined)\r\n expect.fail(`Expected an IModelError with errorNumber ${expectedErrorNumber}, but the call resolved without throwing.`);\r\n expect(error.errorNumber).to.equal(expectedErrorNumber);\r\n}\r\n\r\n/** Roundtrip an entity through a JSON string and back to a new entity, asserting the serialization is stable. */\r\nexport function roundtripThroughJson(entity1: Entity): Entity {\r\n const string1 = JSON.stringify(entity1);\r\n const props1 = JSON.parse(string1) as EntityProps;\r\n const entity2 = new (entity1.constructor as any)(props1, entity1.iModel); // create a new entity from the EntityProps\r\n const string2 = JSON.stringify(entity2);\r\n assert.equal(string1, string2);\r\n return entity2;\r\n}\r\n\r\n/**\r\n * Create a fresh writable snapshot copied from a seed asset. This is the single creation path for\r\n * mutating tests (hybrid isolation) so state never leaks between tests. Compose with\r\n * {@link importTestBim} when the test also needs the `TestBim` schema.\r\n */\r\nexport function createIModelFromSeed(targetFileName: string, seedAssetName: string): SnapshotDb {\r\n const seedFile = IModelTestUtils.resolveAssetFile(seedAssetName);\r\n const snapshotFile = IModelTestUtils.prepareOutputFile(\"IModel\", targetFileName);\r\n return IModelTestUtils.createSnapshotFromSeed(snapshotFile, seedFile);\r\n}\r\n\r\n/**\r\n * Import the `TestBim` schema into `imodel` and return it, so this can wrap a creation call:\r\n * `await importTestBim(createIModelFromSeed(target, seed))`.\r\n */\r\nexport async function importTestBim<T extends SnapshotDb>(imodel: T): Promise<T> {\r\n const schemaPathname = path.join(KnownTestLocations.assetsDir, \"TestBim.ecschema.xml\");\r\n await imodel.importSchemas([schemaPathname]);\r\n return imodel;\r\n}\r\n\r\n/**\r\n * Create a fresh writable copy from a seed asset, close it, and reopen it read-only.\r\n *\r\n * This is the canonical way to build a shared, per-file read-only fixture under the hybrid\r\n * isolation policy: the read-only handle can be shared safely across tests in a file because\r\n * nothing can mutate it, while each mutating test still gets its own writable copy elsewhere.\r\n * When `importTestBim` is set, the `TestBim` schema is imported into the writable copy before\r\n * it is reopened read-only.\r\n */\r\nexport async function openReadonlySeedCopy(targetFileName: string, seedAssetName: string, opts?: { importTestBim?: boolean }): Promise<SnapshotDb> {\r\n const writable = createIModelFromSeed(targetFileName, seedAssetName);\r\n if (opts?.importTestBim)\r\n await importTestBim(writable);\r\n const pathName = writable.pathName;\r\n writable.close();\r\n return SnapshotDb.openFile(pathName);\r\n}\r\n\r\n/** Close each provided database that is still open. Guards against `undefined` and already-closed handles. */\r\nexport function closeIfOpen(...dbs: Array<IModelDb | undefined>): void {\r\n for (const db of dbs) {\r\n if (db !== undefined && db.isOpen)\r\n db.close();\r\n }\r\n}\r\n\r\n/**\r\n * Create a tracker for the writable iModels a test file opens, so they are all closed during teardown.\r\n *\r\n * This is the mechanism that enforces the hybrid isolation policy for mutating tests: each test wraps\r\n * its freshly-created writable copy in `trackMutableIModel(...)`, and the file's `afterEach`/`after`\r\n * calls `closeTrackedIModels()` to close and forget them. `closeTrackedIModels` is idempotent, so it is\r\n * safe to call from both hooks.\r\n */\r\nexport function createMutableIModelTracker(): {\r\n trackMutableIModel: <T extends IModelDb>(imodel: T) => T;\r\n closeTrackedIModels: () => void;\r\n} {\r\n const tracked: IModelDb[] = [];\r\n return {\r\n trackMutableIModel: (imodel) => {\r\n tracked.push(imodel);\r\n return imodel;\r\n },\r\n closeTrackedIModels: () => {\r\n closeIfOpen(...tracked.splice(0));\r\n },\r\n };\r\n}\r\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=IModelViews.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IModelViews.test.d.ts","sourceRoot":"","sources":["../../../../src/test/imodel/IModelViews.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,199 @@
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 { assert, expect } from "chai";
6
+ import { BisCodeSpec, ColorDef, DisplayStyleSettings, IModel, RenderMode, ViewFlags, } from "@itwin/core-common";
7
+ import { EditTxn, withEditTxn } from "../../EditTxn";
8
+ import { DisplayStyle3d, IModelDb } from "../../core-backend";
9
+ import { IModelTestUtils } from "../IModelTestUtils";
10
+ import { TestUtils } from "../TestUtils";
11
+ import { closeIfOpen, createIModelFromSeed, createMutableIModelTracker, openReadonlySeedCopy } from "./IModelTestFixtures";
12
+ describe("iModel views", () => {
13
+ let compatibilityReadonly;
14
+ const { trackMutableIModel, closeTrackedIModels } = createMutableIModelTracker();
15
+ before(async () => {
16
+ await TestUtils.startBackend();
17
+ IModelTestUtils.registerTestBimSchema();
18
+ compatibilityReadonly = await openReadonlySeedCopy("views-CompatibilityTestSeed.bim", "CompatibilityTestSeed.bim");
19
+ });
20
+ after(() => {
21
+ closeIfOpen(compatibilityReadonly);
22
+ closeTrackedIModels();
23
+ });
24
+ afterEach(() => {
25
+ closeTrackedIModels();
26
+ });
27
+ it("should insert a DisplayStyle", () => {
28
+ const imodel2 = trackMutableIModel(createIModelFromSeed("views-insert-display-style.bim", "CompatibilityTestSeed.bim"));
29
+ const model = imodel2.models.getModel(IModel.dictionaryId);
30
+ expect(model).not.to.be.undefined;
31
+ const settings = {
32
+ backgroundColor: ColorDef.blue.toJSON(),
33
+ viewflags: ViewFlags.fromJSON({
34
+ renderMode: RenderMode.SolidFill,
35
+ }),
36
+ };
37
+ const props = {
38
+ classFullName: DisplayStyle3d.classFullName,
39
+ model: IModel.dictionaryId,
40
+ code: { spec: BisCodeSpec.displayStyle, scope: IModel.dictionaryId, value: "test style" },
41
+ isPrivate: false,
42
+ jsonProperties: {
43
+ styles: settings,
44
+ },
45
+ };
46
+ const txn = new EditTxn(imodel2, "insert and update DisplayStyle");
47
+ txn.start();
48
+ const styleId = txn.insertElement(props);
49
+ let style = imodel2.elements.getElement(styleId);
50
+ expect(style instanceof DisplayStyle3d).to.be.true;
51
+ expect(style.code.spec).equal(imodel2.codeSpecs.getByName(BisCodeSpec.displayStyle).id);
52
+ expect(style.settings.viewFlags.renderMode).to.equal(RenderMode.SolidFill);
53
+ expect(style.settings.backgroundColor.equals(ColorDef.blue)).to.be.true;
54
+ const newFlags = style.settings.viewFlags.copy({ renderMode: RenderMode.SmoothShade });
55
+ style.settings.viewFlags = newFlags;
56
+ style.settings.backgroundColor = ColorDef.red;
57
+ style.settings.monochromeColor = ColorDef.green;
58
+ expect(style.jsonProperties.styles.viewflags.renderMode).to.equal(RenderMode.SmoothShade);
59
+ txn.updateElement(style.toJSON());
60
+ txn.end();
61
+ style = imodel2.elements.getElement(styleId);
62
+ expect(style instanceof DisplayStyle3d).to.be.true;
63
+ expect(style.settings.viewFlags.renderMode).to.equal(RenderMode.SmoothShade);
64
+ expect(style.settings.backgroundColor.equals(ColorDef.red)).to.be.true;
65
+ expect(style.settings.monochromeColor.equals(ColorDef.green)).to.be.true;
66
+ });
67
+ it("should create display styles", () => {
68
+ const imodel2 = trackMutableIModel(createIModelFromSeed("views-create-display-styles.bim", "CompatibilityTestSeed.bim"));
69
+ const defaultViewFlags = new ViewFlags().toJSON();
70
+ const defaultMapImagery = new DisplayStyleSettings({}).toJSON().mapImagery;
71
+ const viewFlags = new ViewFlags({ patterns: false, visibleEdges: true });
72
+ const viewflags = { noWhiteOnWhiteReversal: true, shadows: true, noTransp: true };
73
+ const mapImagery = {
74
+ backgroundBase: ColorDef.red.tbgr,
75
+ backgroundLayers: [{
76
+ name: "x",
77
+ url: "y",
78
+ transparency: 0.5,
79
+ formatId: "WMS",
80
+ visible: true,
81
+ }],
82
+ };
83
+ const props = {
84
+ mapImagery,
85
+ excludedElements: ["0x123", "0xfed"],
86
+ timePoint: 42,
87
+ backgroundColor: ColorDef.green.tbgr,
88
+ };
89
+ const testCases = [
90
+ [undefined, defaultViewFlags, false],
91
+ [{ viewFlags }, viewFlags.toJSON(), false],
92
+ [{ viewflags }, viewflags, false],
93
+ [{ viewflags, viewFlags }, viewFlags.toJSON(), false],
94
+ [props, defaultViewFlags, false],
95
+ [{ ...props, viewflags }, viewflags, false],
96
+ [{ backgroundColor: ColorDef.blue }, defaultViewFlags, false],
97
+ [{ backgroundColor: ColorDef.from(1, 2, 3, 4) }, defaultViewFlags, false],
98
+ [{ backgroundColor: ColorDef.blue.tbgr }, defaultViewFlags, false],
99
+ [{ backgroundColor: ColorDef.from(1, 2, 3, 4).tbgr }, defaultViewFlags, false],
100
+ ];
101
+ let suffix = 123;
102
+ withEditTxn(imodel2, (txn) => {
103
+ for (const test of testCases) {
104
+ const expected = test[0] ?? {};
105
+ const styleId = DisplayStyle3d.insert(txn, IModel.dictionaryId, `TestStyle${suffix++}`, expected);
106
+ const style = imodel2.elements.getElement(styleId).toJSON();
107
+ expect(style.jsonProperties.styles).not.to.be.undefined;
108
+ expect(style.jsonProperties).not.to.be.undefined;
109
+ expect(style.jsonProperties.styles).not.to.be.undefined;
110
+ const actual = style.jsonProperties.styles;
111
+ expect(actual.viewflags).not.to.be.undefined;
112
+ const expectedVf = ViewFlags.fromJSON(test[1]);
113
+ const actualVf = ViewFlags.fromJSON(actual.viewflags);
114
+ expect(actualVf.toJSON()).to.deep.equal(expectedVf.toJSON());
115
+ const expectedBGColor = expected.backgroundColor instanceof ColorDef ? expected.backgroundColor.toJSON() : expected.backgroundColor;
116
+ expect(actual.backgroundColor).to.equal(expectedBGColor);
117
+ // DisplayStyleSettings constructor always initializes json.mapImagery.
118
+ expect(actual.mapImagery).to.deep.equal(expected.mapImagery ?? defaultMapImagery);
119
+ expect(actual.excludedElements).to.deep.equal(expected.excludedElements);
120
+ expect(actual.timePoint).to.deep.equal(expected.timePoint);
121
+ }
122
+ });
123
+ });
124
+ it("should be able to query for ViewDefinitionProps", () => {
125
+ const imodel2 = compatibilityReadonly;
126
+ const viewDefinitionProps = imodel2.views.queryViewDefinitionProps(); // query for all ViewDefinitions
127
+ assert.isAtLeast(viewDefinitionProps.length, 3);
128
+ assert.isTrue(viewDefinitionProps[0].classFullName.includes("ViewDefinition"));
129
+ assert.isFalse(viewDefinitionProps[1].isPrivate);
130
+ const spatialViewDefinitionProps = imodel2.views.queryViewDefinitionProps("BisCore.SpatialViewDefinition"); // limit query to SpatialViewDefinitions
131
+ assert.isAtLeast(spatialViewDefinitionProps.length, 3);
132
+ assert.exists(spatialViewDefinitionProps[2].modelSelector?.id);
133
+ });
134
+ it("should iterate ViewDefinitions", () => {
135
+ const imodel2 = compatibilityReadonly;
136
+ // imodel2 contains 3 SpatialViewDefinitions and no other views.
137
+ let numViews = 0;
138
+ let result = imodel2.views.iterateViews(IModelDb.Views.defaultQueryParams, (_view) => {
139
+ ++numViews;
140
+ return true;
141
+ });
142
+ expect(result).to.be.true;
143
+ expect(numViews).to.equal(3);
144
+ // Query specifically for spatial views
145
+ numViews = 0;
146
+ result = imodel2.views.iterateViews({ from: "BisCore.SpatialViewDefinition" }, (view) => {
147
+ if (view.isSpatialView())
148
+ ++numViews;
149
+ return view.isSpatialView();
150
+ });
151
+ expect(result).to.be.true;
152
+ expect(numViews).to.equal(3);
153
+ // Query specifically for 2d views
154
+ numViews = 0;
155
+ result = imodel2.views.iterateViews({ from: "BisCore.ViewDefinition2d" }, (_view) => {
156
+ ++numViews;
157
+ return true;
158
+ });
159
+ expect(result).to.be.true;
160
+ expect(numViews).to.equal(0);
161
+ // Terminate iteration on first view
162
+ numViews = 0;
163
+ result = imodel2.views.iterateViews(IModelDb.Views.defaultQueryParams, (_view) => {
164
+ ++numViews;
165
+ return false;
166
+ });
167
+ expect(result).to.be.false;
168
+ expect(numViews).to.equal(1);
169
+ });
170
+ it("read view thumbnail", () => {
171
+ const imodel5 = trackMutableIModel(createIModelFromSeed("views-mirukuru-thumbnail.bim", "mirukuru.ibim"));
172
+ const viewId = "0x24";
173
+ const thumbnail = imodel5.views.getThumbnail(viewId);
174
+ assert.exists(thumbnail);
175
+ if (!thumbnail)
176
+ return;
177
+ assert.equal(thumbnail.format, "jpeg");
178
+ assert.equal(thumbnail.height, 768);
179
+ assert.equal(thumbnail.width, 768);
180
+ assert.equal(thumbnail.image.length, 18062);
181
+ thumbnail.width = 100;
182
+ thumbnail.height = 200;
183
+ thumbnail.format = "png";
184
+ thumbnail.image = new Uint8Array(200);
185
+ thumbnail.image.fill(12);
186
+ const stat = imodel5.views.saveThumbnail(viewId, thumbnail);
187
+ assert.equal(stat, 0, "save thumbnail");
188
+ const thumbnail2 = imodel5.views.getThumbnail(viewId);
189
+ assert.exists(thumbnail2);
190
+ if (!thumbnail2)
191
+ return;
192
+ assert.equal(thumbnail2.format, "png");
193
+ assert.equal(thumbnail2.height, 200);
194
+ assert.equal(thumbnail2.width, 100);
195
+ assert.equal(thumbnail2.image.length, 200);
196
+ assert.equal(thumbnail2.image[0], 12);
197
+ });
198
+ });
199
+ //# sourceMappingURL=IModelViews.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IModelViews.test.js","sourceRoot":"","sources":["../../../../src/test/imodel/IModelViews.test.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACtC,OAAO,EACL,WAAW,EAAE,QAAQ,EAAqB,oBAAoB,EAA6B,MAAM,EACjG,UAAU,EAAkE,SAAS,GACtF,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAmB,cAAc,EAA+B,QAAQ,EAA8B,MAAM,oBAAoB,CAAC;AACxI,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,0BAA0B,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAG3H,QAAQ,CAAC,cAAc,EAAE,G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C,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\nimport { assert, expect } from \"chai\";\r\nimport {\r\n BisCodeSpec, ColorDef, DisplayStyleProps, DisplayStyleSettings, DisplayStyleSettingsProps, IModel, MapImageryProps,\r\n RenderMode, SpatialViewDefinitionProps, ViewDefinitionProps, ViewFlagProps, ViewFlags,\r\n} from \"@itwin/core-common\";\r\nimport { EditTxn, withEditTxn } from \"../../EditTxn\";\r\nimport { DictionaryModel, DisplayStyle3d, DisplayStyleCreationOptions, IModelDb, SnapshotDb, ViewDefinition } from \"../../core-backend\";\r\nimport { IModelTestUtils } from \"../IModelTestUtils\";\r\nimport { TestUtils } from \"../TestUtils\";\r\nimport { closeIfOpen, createIModelFromSeed, createMutableIModelTracker, openReadonlySeedCopy } from \"./IModelTestFixtures\";\r\n\r\n\r\ndescribe(\"iModel views\", () => {\r\n let compatibilityReadonly: SnapshotDb;\r\n const { trackMutableIModel, closeTrackedIModels } = createMutableIModelTracker();\r\n\r\n before(async () => {\r\n await TestUtils.startBackend();\r\n IModelTestUtils.registerTestBimSchema();\r\n\r\n compatibilityReadonly = await openReadonlySeedCopy(\"views-CompatibilityTestSeed.bim\", \"CompatibilityTestSeed.bim\");\r\n });\r\n\r\n after(() => {\r\n closeIfOpen(compatibilityReadonly);\r\n closeTrackedIModels();\r\n });\r\n\r\n afterEach(() => {\r\n closeTrackedIModels();\r\n });\r\n\r\n it(\"should insert a DisplayStyle\", () => {\r\n const imodel2 = trackMutableIModel(createIModelFromSeed(\"views-insert-display-style.bim\", \"CompatibilityTestSeed.bim\"));\r\n const model = imodel2.models.getModel<DictionaryModel>(IModel.dictionaryId);\r\n expect(model).not.to.be.undefined;\r\n\r\n const settings: DisplayStyleSettingsProps = {\r\n backgroundColor: ColorDef.blue.toJSON(),\r\n viewflags: ViewFlags.fromJSON({\r\n renderMode: RenderMode.SolidFill,\r\n }),\r\n };\r\n\r\n const props: DisplayStyleProps = {\r\n classFullName: DisplayStyle3d.classFullName,\r\n model: IModel.dictionaryId,\r\n code: { spec: BisCodeSpec.displayStyle, scope: IModel.dictionaryId, value: \"test style\" },\r\n isPrivate: false,\r\n jsonProperties: {\r\n styles: settings,\r\n },\r\n };\r\n\r\n const txn = new EditTxn(imodel2, \"insert and update DisplayStyle\");\r\n txn.start();\r\n const styleId = txn.insertElement(props);\r\n let style = imodel2.elements.getElement<DisplayStyle3d>(styleId);\r\n expect(style instanceof DisplayStyle3d).to.be.true;\r\n expect(style.code.spec).equal(imodel2.codeSpecs.getByName(BisCodeSpec.displayStyle).id);\r\n\r\n expect(style.settings.viewFlags.renderMode).to.equal(RenderMode.SolidFill);\r\n expect(style.settings.backgroundColor.equals(ColorDef.blue)).to.be.true;\r\n\r\n const newFlags = style.settings.viewFlags.copy({ renderMode: RenderMode.SmoothShade });\r\n style.settings.viewFlags = newFlags;\r\n style.settings.backgroundColor = ColorDef.red;\r\n style.settings.monochromeColor = ColorDef.green;\r\n expect(style.jsonProperties.styles.viewflags.renderMode).to.equal(RenderMode.SmoothShade);\r\n\r\n txn.updateElement(style.toJSON());\r\n txn.end();\r\n style = imodel2.elements.getElement<DisplayStyle3d>(styleId);\r\n expect(style instanceof DisplayStyle3d).to.be.true;\r\n\r\n expect(style.settings.viewFlags.renderMode).to.equal(RenderMode.SmoothShade);\r\n expect(style.settings.backgroundColor.equals(ColorDef.red)).to.be.true;\r\n expect(style.settings.monochromeColor.equals(ColorDef.green)).to.be.true;\r\n });\r\n\r\n it(\"should create display styles\", () => {\r\n const imodel2 = trackMutableIModel(createIModelFromSeed(\"views-create-display-styles.bim\", \"CompatibilityTestSeed.bim\"));\r\n const defaultViewFlags = new ViewFlags().toJSON();\r\n const defaultMapImagery = new DisplayStyleSettings({}).toJSON().mapImagery;\r\n\r\n const viewFlags = new ViewFlags({ patterns: false, visibleEdges: true });\r\n const viewflags: ViewFlagProps = { noWhiteOnWhiteReversal: true, shadows: true, noTransp: true };\r\n\r\n const mapImagery: MapImageryProps = {\r\n backgroundBase: ColorDef.red.tbgr,\r\n backgroundLayers: [{\r\n name: \"x\",\r\n url: \"y\",\r\n transparency: 0.5,\r\n formatId: \"WMS\",\r\n visible: true,\r\n }],\r\n };\r\n\r\n const props: DisplayStyleSettingsProps = {\r\n mapImagery,\r\n excludedElements: [\"0x123\", \"0xfed\"],\r\n timePoint: 42,\r\n backgroundColor: ColorDef.green.tbgr,\r\n };\r\n\r\n type TestCase = [DisplayStyleCreationOptions | undefined, ViewFlagProps, boolean];\r\n const testCases: TestCase[] = [\r\n [undefined, defaultViewFlags, false],\r\n [{ viewFlags }, viewFlags.toJSON(), false],\r\n [{ viewflags }, viewflags, false],\r\n [{ viewflags, viewFlags }, viewFlags.toJSON(), false],\r\n [props, defaultViewFlags, false],\r\n [{ ...props, viewflags }, viewflags, false],\r\n [{ backgroundColor: ColorDef.blue }, defaultViewFlags, false],\r\n [{ backgroundColor: ColorDef.from(1, 2, 3, 4) }, defaultViewFlags, false],\r\n [{ backgroundColor: ColorDef.blue.tbgr }, defaultViewFlags, false],\r\n [{ backgroundColor: ColorDef.from(1, 2, 3, 4).tbgr }, defaultViewFlags, false],\r\n ];\r\n\r\n let suffix = 123;\r\n withEditTxn(imodel2, (txn) => {\r\n for (const test of testCases) {\r\n const expected = test[0] ?? {};\r\n const styleId = DisplayStyle3d.insert(txn, IModel.dictionaryId, `TestStyle${suffix++}`, expected);\r\n const style = imodel2.elements.getElement<DisplayStyle3d>(styleId).toJSON();\r\n expect(style.jsonProperties.styles).not.to.be.undefined;\r\n\r\n expect(style.jsonProperties).not.to.be.undefined;\r\n expect(style.jsonProperties.styles).not.to.be.undefined;\r\n const actual = style.jsonProperties.styles!;\r\n\r\n expect(actual.viewflags).not.to.be.undefined;\r\n const expectedVf = ViewFlags.fromJSON(test[1]);\r\n const actualVf = ViewFlags.fromJSON(actual.viewflags);\r\n expect(actualVf.toJSON()).to.deep.equal(expectedVf.toJSON());\r\n\r\n const expectedBGColor = expected.backgroundColor instanceof ColorDef ? expected.backgroundColor.toJSON() : expected.backgroundColor;\r\n expect(actual.backgroundColor).to.equal(expectedBGColor);\r\n\r\n // DisplayStyleSettings constructor always initializes json.mapImagery.\r\n expect(actual.mapImagery).to.deep.equal(expected.mapImagery ?? defaultMapImagery);\r\n expect(actual.excludedElements).to.deep.equal(expected.excludedElements);\r\n expect(actual.timePoint).to.deep.equal(expected.timePoint);\r\n }\r\n });\r\n });\r\n\r\n it(\"should be able to query for ViewDefinitionProps\", () => {\r\n const imodel2 = compatibilityReadonly;\r\n const viewDefinitionProps: ViewDefinitionProps[] = imodel2.views.queryViewDefinitionProps(); // query for all ViewDefinitions\r\n assert.isAtLeast(viewDefinitionProps.length, 3);\r\n assert.isTrue(viewDefinitionProps[0].classFullName.includes(\"ViewDefinition\"));\r\n assert.isFalse(viewDefinitionProps[1].isPrivate);\r\n\r\n const spatialViewDefinitionProps = imodel2.views.queryViewDefinitionProps(\"BisCore.SpatialViewDefinition\") as SpatialViewDefinitionProps[]; // limit query to SpatialViewDefinitions\r\n assert.isAtLeast(spatialViewDefinitionProps.length, 3);\r\n assert.exists(spatialViewDefinitionProps[2].modelSelector?.id);\r\n });\r\n\r\n it(\"should iterate ViewDefinitions\", () => {\r\n const imodel2 = compatibilityReadonly;\r\n // imodel2 contains 3 SpatialViewDefinitions and no other views.\r\n let numViews = 0;\r\n let result = imodel2.views.iterateViews(IModelDb.Views.defaultQueryParams, (_view: ViewDefinition) => {\r\n ++numViews;\r\n return true;\r\n });\r\n\r\n expect(result).to.be.true;\r\n expect(numViews).to.equal(3);\r\n\r\n // Query specifically for spatial views\r\n numViews = 0;\r\n result = imodel2.views.iterateViews({ from: \"BisCore.SpatialViewDefinition\" }, (view: ViewDefinition) => {\r\n if (view.isSpatialView())\r\n ++numViews;\r\n\r\n return view.isSpatialView();\r\n });\r\n expect(result).to.be.true;\r\n expect(numViews).to.equal(3);\r\n\r\n // Query specifically for 2d views\r\n numViews = 0;\r\n result = imodel2.views.iterateViews({ from: \"BisCore.ViewDefinition2d\" }, (_view: ViewDefinition) => {\r\n ++numViews;\r\n return true;\r\n });\r\n\r\n expect(result).to.be.true;\r\n expect(numViews).to.equal(0);\r\n\r\n // Terminate iteration on first view\r\n numViews = 0;\r\n result = imodel2.views.iterateViews(IModelDb.Views.defaultQueryParams, (_view: ViewDefinition) => {\r\n ++numViews;\r\n return false;\r\n });\r\n\r\n expect(result).to.be.false;\r\n expect(numViews).to.equal(1);\r\n });\r\n\r\n it(\"read view thumbnail\", () => {\r\n const imodel5 = trackMutableIModel(createIModelFromSeed(\"views-mirukuru-thumbnail.bim\", \"mirukuru.ibim\"));\r\n const viewId = \"0x24\";\r\n const thumbnail = imodel5.views.getThumbnail(viewId);\r\n assert.exists(thumbnail);\r\n if (!thumbnail)\r\n return;\r\n assert.equal(thumbnail.format, \"jpeg\");\r\n assert.equal(thumbnail.height, 768);\r\n assert.equal(thumbnail.width, 768);\r\n assert.equal(thumbnail.image.length, 18062);\r\n\r\n thumbnail.width = 100;\r\n thumbnail.height = 200;\r\n thumbnail.format = \"png\";\r\n thumbnail.image = new Uint8Array(200);\r\n thumbnail.image.fill(12);\r\n const stat = imodel5.views.saveThumbnail(viewId, thumbnail);\r\n assert.equal(stat, 0, \"save thumbnail\");\r\n\r\n const thumbnail2 = imodel5.views.getThumbnail(viewId);\r\n assert.exists(thumbnail2);\r\n if (!thumbnail2)\r\n return;\r\n assert.equal(thumbnail2.format, \"png\");\r\n assert.equal(thumbnail2.height, 200);\r\n assert.equal(thumbnail2.width, 100);\r\n assert.equal(thumbnail2.image.length, 200);\r\n assert.equal(thumbnail2.image[0], 12);\r\n });\r\n});\r\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itwin/core-backend",
3
- "version": "5.13.0-dev.10",
3
+ "version": "5.13.0-dev.12",
4
4
  "description": "iTwin.js backend components",
5
5
  "main": "lib/cjs/core-backend.js",
6
6
  "module": "lib/esm/core-backend.js",
@@ -27,10 +27,10 @@
27
27
  },
28
28
  "peerDependencies": {
29
29
  "@opentelemetry/api": "^1.0.4",
30
- "@itwin/core-geometry": "5.13.0-dev.10",
31
- "@itwin/core-common": "5.13.0-dev.10",
32
- "@itwin/ecschema-metadata": "5.13.0-dev.10",
33
- "@itwin/core-bentley": "5.13.0-dev.10"
30
+ "@itwin/core-bentley": "5.13.0-dev.12",
31
+ "@itwin/core-geometry": "5.13.0-dev.12",
32
+ "@itwin/core-common": "5.13.0-dev.12",
33
+ "@itwin/ecschema-metadata": "5.13.0-dev.12"
34
34
  },
35
35
  "peerDependenciesMeta": {
36
36
  "@opentelemetry/api": {
@@ -74,17 +74,17 @@
74
74
  "marked": "^14.1.3",
75
75
  "sql-formatter": "^15.4.6",
76
76
  "vite": "^6.4.3",
77
- "@itwin/build-tools": "5.13.0-dev.10",
78
- "@itwin/core-bentley": "5.13.0-dev.10",
79
- "@itwin/ecschema-locaters": "5.13.0-dev.10",
80
- "@itwin/core-common": "5.13.0-dev.10",
81
- "@itwin/core-geometry": "5.13.0-dev.10",
82
- "@itwin/ecschema-metadata": "5.13.0-dev.10",
77
+ "@itwin/core-bentley": "5.13.0-dev.12",
78
+ "@itwin/core-geometry": "5.13.0-dev.12",
79
+ "@itwin/build-tools": "5.13.0-dev.12",
80
+ "@itwin/core-common": "5.13.0-dev.12",
81
+ "@itwin/ecschema-locaters": "5.13.0-dev.12",
82
+ "@itwin/ecsql-common": "5.13.0-dev.12",
83
83
  "internal-tools": "3.0.0-dev.69",
84
- "@itwin/ecsql-common": "5.13.0-dev.10"
84
+ "@itwin/ecschema-metadata": "5.13.0-dev.12"
85
85
  },
86
86
  "dependencies": {
87
- "@bentley/imodeljs-native": "5.13.7",
87
+ "@bentley/imodeljs-native": "5.13.9",
88
88
  "@itwin/object-storage-azure": "^3.0.4",
89
89
  "@azure/storage-blob": "^12.28.0",
90
90
  "form-data": "^4.0.6",
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=IModel.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"IModel.test.d.ts","sourceRoot":"","sources":["../../../../src/test/imodel/IModel.test.ts"],"names":[],"mappings":""}