@itwin/core-backend 5.4.0-dev.2 → 5.4.0-dev.4
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.
- package/lib/cjs/Element.d.ts +29 -1
- package/lib/cjs/Element.d.ts.map +1 -1
- package/lib/cjs/Element.js +53 -1
- package/lib/cjs/Element.js.map +1 -1
- package/lib/cjs/ElementAspect.d.ts +24 -1
- package/lib/cjs/ElementAspect.d.ts.map +1 -1
- package/lib/cjs/ElementAspect.js +102 -1
- package/lib/cjs/ElementAspect.js.map +1 -1
- package/lib/cjs/IModelDb.d.ts +11 -0
- package/lib/cjs/IModelDb.d.ts.map +1 -1
- package/lib/cjs/IModelDb.js +18 -0
- package/lib/cjs/IModelDb.js.map +1 -1
- package/lib/cjs/NavigationRelationship.d.ts +15 -0
- package/lib/cjs/NavigationRelationship.d.ts.map +1 -1
- package/lib/cjs/NavigationRelationship.js +22 -1
- package/lib/cjs/NavigationRelationship.js.map +1 -1
- package/lib/cjs/annotations/LeaderGeometry.d.ts +13 -1
- package/lib/cjs/annotations/LeaderGeometry.d.ts.map +1 -1
- package/lib/cjs/annotations/LeaderGeometry.js +88 -10
- package/lib/cjs/annotations/LeaderGeometry.js.map +1 -1
- package/lib/cjs/annotations/TextAnnotationElement.d.ts +1 -1
- package/lib/cjs/annotations/TextAnnotationElement.d.ts.map +1 -1
- package/lib/cjs/annotations/TextAnnotationElement.js +7 -3
- package/lib/cjs/annotations/TextAnnotationElement.js.map +1 -1
- package/lib/esm/Element.d.ts +29 -1
- package/lib/esm/Element.d.ts.map +1 -1
- package/lib/esm/Element.js +53 -2
- package/lib/esm/Element.js.map +1 -1
- package/lib/esm/ElementAspect.d.ts +24 -1
- package/lib/esm/ElementAspect.d.ts.map +1 -1
- package/lib/esm/ElementAspect.js +101 -1
- package/lib/esm/ElementAspect.js.map +1 -1
- package/lib/esm/IModelDb.d.ts +11 -0
- package/lib/esm/IModelDb.d.ts.map +1 -1
- package/lib/esm/IModelDb.js +18 -0
- package/lib/esm/IModelDb.js.map +1 -1
- package/lib/esm/NavigationRelationship.d.ts +15 -0
- package/lib/esm/NavigationRelationship.d.ts.map +1 -1
- package/lib/esm/NavigationRelationship.js +19 -0
- package/lib/esm/NavigationRelationship.js.map +1 -1
- package/lib/esm/annotations/LeaderGeometry.d.ts +13 -1
- package/lib/esm/annotations/LeaderGeometry.d.ts.map +1 -1
- package/lib/esm/annotations/LeaderGeometry.js +89 -12
- package/lib/esm/annotations/LeaderGeometry.js.map +1 -1
- package/lib/esm/annotations/TextAnnotationElement.d.ts +1 -1
- package/lib/esm/annotations/TextAnnotationElement.d.ts.map +1 -1
- package/lib/esm/annotations/TextAnnotationElement.js +7 -3
- package/lib/esm/annotations/TextAnnotationElement.js.map +1 -1
- package/lib/esm/test/annotations/LeaderGeometry.test.js +47 -2
- package/lib/esm/test/annotations/LeaderGeometry.test.js.map +1 -1
- package/lib/esm/test/annotations/TextAnnotation.test.js +46 -5
- package/lib/esm/test/annotations/TextAnnotation.test.js.map +1 -1
- package/lib/esm/test/element/ProjectInformationRecord.test.d.ts +2 -0
- package/lib/esm/test/element/ProjectInformationRecord.test.d.ts.map +1 -0
- package/lib/esm/test/element/ProjectInformationRecord.test.js +80 -0
- package/lib/esm/test/element/ProjectInformationRecord.test.js.map +1 -0
- package/lib/esm/test/element/SheetInformationAspect.test.d.ts +2 -0
- package/lib/esm/test/element/SheetInformationAspect.test.d.ts.map +1 -0
- package/lib/esm/test/element/SheetInformationAspect.test.js +182 -0
- package/lib/esm/test/element/SheetInformationAspect.test.js.map +1 -0
- package/lib/esm/test/imodel/IModel.test.js +32 -2
- package/lib/esm/test/imodel/IModel.test.js.map +1 -1
- package/lib/esm/test/standalone/ChangesetReader.test.js +8 -11
- package/lib/esm/test/standalone/ChangesetReader.test.js.map +1 -1
- package/package.json +14 -14
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProjectInformationRecord.test.js","sourceRoot":"","sources":["../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Q,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC;YAEjC,MAAM,GAAG,EAAE,CAAC,QAAQ,CAAC,UAAU,CAA2B,QAAQ,CAAC,CAAC;YACpE,MAAM,CAAC,MAAM,CAAC,CAAC,UAAU,CAAC,wBAAwB,CAAC,CAAC;YACpD,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;YAE9D,MAAM,CAAC,kBAAkB,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC3C,CAAC,CAAC,CAAA;QAEF,EAAE,CAAC,mCAAmC,EAAE,GAAG,EAAE;YAC3C,MAAM,YAAY,GAAuB;gBACvC,aAAa,EAAE,KAAK;gBACpB,WAAW,EAAE,MAAM;gBACnB,QAAQ,EAAE,OAAO;aAClB,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 @@
|
|
|
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,uBAAu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ACnI,CAAC,CAAC,CAAC;YAEH,EAAE,CAAC,uDAAuD,EAAE,KAAK,IAAI,EAAE;gBACrE,MAAM,OAAO,GAAG,MAAM,WAAW,CAAC,EAAE,CAAC,CAAC;gBAEtC,SAAS,kBAAkB;oBACzB,4DAA4D;oBAC5D,OAAO,EAAE,CAAC,qBAAqB,CAAC,wBAAwB,+BAA+B,CAAC,aAAa,6BAA6B,OAAO,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE;wBACpJ,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;wBACrD,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC;oBACvC,CAAC,CAAC,CAAC;gBACL,CAAC;gBAED,MAAM,CAAC,kBAAkB,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;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"]}
|
|
@@ -71,7 +71,7 @@ import { DisableNativeAssertions } from "../TestUtils";
|
|
|
71
71
|
import { samplePngTexture } from "../imageData";
|
|
72
72
|
import { performance } from "perf_hooks";
|
|
73
73
|
import { _hubAccess } from "../../internal/Symbols";
|
|
74
|
-
import { CustomAttributeClass, EntityClass, PropertyType, propertyTypeToString, SchemaItemType } from "@itwin/ecschema-metadata";
|
|
74
|
+
import { CustomAttributeClass, ECVersion, EntityClass, PropertyType, propertyTypeToString, SchemaItemType } from "@itwin/ecschema-metadata";
|
|
75
75
|
// spell-checker: disable
|
|
76
76
|
async function getIModelError(promise) {
|
|
77
77
|
try {
|
|
@@ -3062,7 +3062,7 @@ describe("iModel", () => {
|
|
|
3062
3062
|
// Create a subset of random relationship entries to delete
|
|
3063
3063
|
const relationshipsToDelete = [];
|
|
3064
3064
|
for (let i = 0; i < 250; ++i) {
|
|
3065
|
-
relationshipsToDelete.push(relationships[Math.floor(Math.random() *
|
|
3065
|
+
relationshipsToDelete.push(relationships[Math.floor(Math.random() * relationships.length)]);
|
|
3066
3066
|
}
|
|
3067
3067
|
testImodel.relationships.deleteInstances(relationshipsToDelete);
|
|
3068
3068
|
testImodel.saveChanges();
|
|
@@ -3074,4 +3074,34 @@ describe("iModel", () => {
|
|
|
3074
3074
|
});
|
|
3075
3075
|
});
|
|
3076
3076
|
});
|
|
3077
|
+
describe("IModelDb.requireMinimumSchemaVersion", () => {
|
|
3078
|
+
let imodel;
|
|
3079
|
+
before(() => imodel = SnapshotDb.createEmpty(IModelTestUtils.prepareOutputFile("IModel", "MinSchemaVer.bim"), { rootSubject: { name: "MinSchemaVer" } }));
|
|
3080
|
+
after(() => imodel.close());
|
|
3081
|
+
it("throws if the schema does not exist", () => {
|
|
3082
|
+
expect(() => imodel.requireMinimumSchemaVersion("FakeSchema", new ECVersion(1, 0, 0), "Scrobbles")).to.throw("Scrobbles requires FakeSchema v01.00.00 or newer");
|
|
3083
|
+
});
|
|
3084
|
+
it("throws IFF the schema version is older than the minimum", () => {
|
|
3085
|
+
function test(minVer, expectError) {
|
|
3086
|
+
expect(imodel.meetsMinimumSchemaVersion("BisCore", minVer)).to.equal(!expectError);
|
|
3087
|
+
const require = () => imodel.requireMinimumSchemaVersion("BisCore", minVer, "Scrobbles");
|
|
3088
|
+
if (expectError) {
|
|
3089
|
+
expect(require).to.throw(`Scrobbles requires BisCore v${minVer.toString()} or newer`);
|
|
3090
|
+
}
|
|
3091
|
+
else {
|
|
3092
|
+
require();
|
|
3093
|
+
}
|
|
3094
|
+
}
|
|
3095
|
+
const bisVer = imodel.querySchemaVersionNumbers("BisCore");
|
|
3096
|
+
expect(bisVer.read).to.equal(1);
|
|
3097
|
+
expect(bisVer.write).to.equal(0);
|
|
3098
|
+
expect(bisVer.minor).to.least(24);
|
|
3099
|
+
test(bisVer, false);
|
|
3100
|
+
test(new ECVersion(bisVer.read, bisVer.write, bisVer.minor - 1), false);
|
|
3101
|
+
test(new ECVersion(0, 0, 1), false);
|
|
3102
|
+
test(new ECVersion(bisVer.read, bisVer.write, bisVer.minor + 1), true);
|
|
3103
|
+
test(new ECVersion(bisVer.read, bisVer.write, bisVer.minor + 1), true);
|
|
3104
|
+
test(new ECVersion(bisVer.read + 1, bisVer.write + 1, bisVer.minor), true);
|
|
3105
|
+
});
|
|
3106
|
+
});
|
|
3077
3107
|
//# sourceMappingURL=IModel.test.js.map
|