@itwin/core-backend 5.14.0-dev.11 → 5.14.0-dev.14

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.
@@ -0,0 +1,186 @@
1
+ var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
2
+ if (value !== null && value !== void 0) {
3
+ if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
4
+ var dispose, inner;
5
+ if (async) {
6
+ if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
7
+ dispose = value[Symbol.asyncDispose];
8
+ }
9
+ if (dispose === void 0) {
10
+ if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
11
+ dispose = value[Symbol.dispose];
12
+ if (async) inner = dispose;
13
+ }
14
+ if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
15
+ if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
16
+ env.stack.push({ value: value, dispose: dispose, async: async });
17
+ }
18
+ else if (async) {
19
+ env.stack.push({ async: true });
20
+ }
21
+ return value;
22
+ };
23
+ var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
24
+ return function (env) {
25
+ function fail(e) {
26
+ env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
27
+ env.hasError = true;
28
+ }
29
+ var r, s = 0;
30
+ function next() {
31
+ while (r = env.stack.pop()) {
32
+ try {
33
+ if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
34
+ if (r.dispose) {
35
+ var result = r.dispose.call(r.value);
36
+ if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
37
+ }
38
+ else s |= 1;
39
+ }
40
+ catch (e) {
41
+ fail(e);
42
+ }
43
+ }
44
+ if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
45
+ if (env.hasError) throw env.error;
46
+ }
47
+ return next();
48
+ };
49
+ })(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
50
+ var e = new Error(message);
51
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
52
+ });
53
+ /*---------------------------------------------------------------------------------------------
54
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
55
+ * See LICENSE.md in the project root for license terms and full copyright notice.
56
+ *--------------------------------------------------------------------------------------------*/
57
+ import { expect } from "chai";
58
+ import * as fs from "fs";
59
+ import * as path from "path";
60
+ import { DbResult } from "@itwin/core-bentley";
61
+ import { KnownTestLocations } from "../KnownTestLocations";
62
+ import { ECDbTestHelper } from "./ECDbTestHelper";
63
+ const testSchema = `<ECSchema schemaName="Test" alias="test" version="01.00.00" xmlns="http://www.bentley.com/schemas/Bentley.ECXML.3.2">
64
+ <ECStructClass typeName="Details">
65
+ <ECProperty propertyName="Nickname" typeName="string"/>
66
+ </ECStructClass>
67
+ <ECEntityClass typeName="Person" modifier="Sealed">
68
+ <ECProperty propertyName="Name" typeName="string"/>
69
+ <ECProperty propertyName="Age" typeName="int"/>
70
+ <ECProperty propertyName="Salary" typeName="double"/>
71
+ <ECStructProperty propertyName="Details" typeName="Details"/>
72
+ </ECEntityClass>
73
+ </ECSchema>`;
74
+ const mapping = [
75
+ { columnIndex: 0, propertyName: "Name" },
76
+ { columnIndex: 1, propertyName: "Age" },
77
+ { columnIndex: 2, propertyName: "Salary" },
78
+ { columnIndex: 3, propertyName: "Details.Nickname" },
79
+ ];
80
+ function readPeople(ecdb) {
81
+ const rows = [];
82
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
83
+ ecdb.withPreparedStatement("SELECT Name, Age, Salary, Details.Nickname FROM test.Person ORDER BY Name", (stmt) => {
84
+ while (stmt.step() === DbResult.BE_SQLITE_ROW) {
85
+ const nickname = stmt.getValue(3);
86
+ rows.push({
87
+ name: stmt.getValue(0).getString(),
88
+ age: stmt.getValue(1).getInteger(),
89
+ salary: stmt.getValue(2).getDouble(),
90
+ nickname: nickname.isNull ? undefined : nickname.getString(),
91
+ });
92
+ }
93
+ });
94
+ return rows;
95
+ }
96
+ describe("ECDb CSV import", () => {
97
+ const outDir = KnownTestLocations.outputDir;
98
+ it("imports in-memory CSV data atomically", () => {
99
+ const env_1 = { stack: [], error: void 0, hasError: false };
100
+ try {
101
+ const ecdb = __addDisposableResource(env_1, ECDbTestHelper.createECDb(outDir, "csv-import-data.ecdb", testSchema), false);
102
+ expect(ecdb.importCSVData([
103
+ ["Alice", "42", "1234.5", "Résumé"],
104
+ ["用户", "31", "2500.25", "昵称"],
105
+ ], { className: "Test.Person", mapping })).to.equal(2);
106
+ expect(() => ecdb.importCSVData([
107
+ ["Valid", "20", "1000", "valid"],
108
+ ["Invalid", "not-an-integer", "1001", "invalid"],
109
+ ], { className: "Test.Person", mapping })).to.throw(/CSV data row 2 column 1/);
110
+ expect(readPeople(ecdb)).to.deep.equal([
111
+ { name: "Alice", age: 42, salary: 1234.5, nickname: "Résumé" },
112
+ { name: "用户", age: 31, salary: 2500.25, nickname: "昵称" },
113
+ ]);
114
+ }
115
+ catch (e_1) {
116
+ env_1.error = e_1;
117
+ env_1.hasError = true;
118
+ }
119
+ finally {
120
+ __disposeResources(env_1);
121
+ }
122
+ });
123
+ it("streams a CSV file and rolls back malformed input", () => {
124
+ const env_2 = { stack: [], error: void 0, hasError: false };
125
+ try {
126
+ const csvPath = path.join(outDir, "csv-import.csv");
127
+ fs.writeFileSync(csvPath, [
128
+ "Ignored,Age,Name,Salary,Nickname",
129
+ 'skip,42,"Doe, Jane",1234.5,"said ""hello""\nnext"',
130
+ String.raw `skip,31,用户,2500.25,\N`,
131
+ ].join("\r\n"));
132
+ const ecdb = __addDisposableResource(env_2, ECDbTestHelper.createECDb(outDir, "csv-import-file.ecdb", testSchema), false);
133
+ const fileMapping = [
134
+ { columnIndex: 1, propertyName: "Age" },
135
+ { columnIndex: 2, propertyName: "Name" },
136
+ { columnIndex: 3, propertyName: "Salary" },
137
+ { columnIndex: 4, propertyName: "Details.Nickname" },
138
+ ];
139
+ expect(ecdb.importCSVFile(csvPath, {
140
+ className: "Test.Person",
141
+ mapping: fileMapping,
142
+ hasHeader: true,
143
+ nullValue: String.raw `\N`,
144
+ })).to.equal(2);
145
+ fs.writeFileSync(csvPath, [
146
+ "skip,20,Valid,1000,valid",
147
+ 'skip,21,"unterminated,1001,invalid',
148
+ ].join("\n"));
149
+ expect(() => ecdb.importCSVFile(csvPath, { className: "Test.Person", mapping: fileMapping }))
150
+ .to.throw(/unterminated quoted field/);
151
+ expect(readPeople(ecdb)).to.deep.equal([
152
+ { name: "Doe, Jane", age: 42, salary: 1234.5, nickname: 'said "hello"\nnext' },
153
+ { name: "用户", age: 31, salary: 2500.25, nickname: undefined },
154
+ ]);
155
+ }
156
+ catch (e_2) {
157
+ env_2.error = e_2;
158
+ env_2.hasError = true;
159
+ }
160
+ finally {
161
+ __disposeResources(env_2);
162
+ }
163
+ });
164
+ it("rejects invalid column mappings before calling native code", () => {
165
+ const env_3 = { stack: [], error: void 0, hasError: false };
166
+ try {
167
+ const ecdb = __addDisposableResource(env_3, ECDbTestHelper.createECDb(outDir, "csv-import-mapping.ecdb", testSchema), false);
168
+ expect(() => ecdb.importCSVData([], { className: "Test.Person", mapping: [] })).to.throw(/must not be empty/);
169
+ expect(() => ecdb.importCSVData([], {
170
+ className: "Test.Person",
171
+ mapping: [
172
+ { columnIndex: 0, propertyName: "Name" },
173
+ { columnIndex: 0, propertyName: "Age" },
174
+ ],
175
+ })).to.throw(/duplicate columnIndex/);
176
+ }
177
+ catch (e_3) {
178
+ env_3.error = e_3;
179
+ env_3.hasError = true;
180
+ }
181
+ finally {
182
+ __disposeResources(env_3);
183
+ }
184
+ });
185
+ });
186
+ //# sourceMappingURL=CSVImport.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CSVImport.test.js","sourceRoot":"","sources":["../../../../src/test/ecdb/CSVImport.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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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 { expect } from \"chai\";\r\nimport * as fs from \"fs\";\r\nimport * as path from \"path\";\r\nimport { DbResult } from \"@itwin/core-bentley\";\r\nimport { ECDb, ECSqlStatement } from \"../../core-backend\";\r\nimport { KnownTestLocations } from \"../KnownTestLocations\";\r\nimport { ECDbTestHelper } from \"./ECDbTestHelper\";\r\n\r\nconst testSchema = `<ECSchema schemaName=\"Test\" alias=\"test\" version=\"01.00.00\" xmlns=\"http://www.bentley.com/schemas/Bentley.ECXML.3.2\">\r\n <ECStructClass typeName=\"Details\">\r\n <ECProperty propertyName=\"Nickname\" typeName=\"string\"/>\r\n </ECStructClass>\r\n <ECEntityClass typeName=\"Person\" modifier=\"Sealed\">\r\n <ECProperty propertyName=\"Name\" typeName=\"string\"/>\r\n <ECProperty propertyName=\"Age\" typeName=\"int\"/>\r\n <ECProperty propertyName=\"Salary\" typeName=\"double\"/>\r\n <ECStructProperty propertyName=\"Details\" typeName=\"Details\"/>\r\n </ECEntityClass>\r\n</ECSchema>`;\r\n\r\nconst mapping = [\r\n { columnIndex: 0, propertyName: \"Name\" },\r\n { columnIndex: 1, propertyName: \"Age\" },\r\n { columnIndex: 2, propertyName: \"Salary\" },\r\n { columnIndex: 3, propertyName: \"Details.Nickname\" },\r\n];\r\n\r\nfunction readPeople(ecdb: ECDb): Array<{ name: string, age: number, salary: number, nickname?: string }> {\r\n const rows: Array<{ name: string, age: number, salary: number, nickname?: string }> = [];\r\n // eslint-disable-next-line @typescript-eslint/no-deprecated\r\n ecdb.withPreparedStatement(\"SELECT Name, Age, Salary, Details.Nickname FROM test.Person ORDER BY Name\", (stmt: ECSqlStatement) => {\r\n while (stmt.step() === DbResult.BE_SQLITE_ROW) {\r\n const nickname = stmt.getValue(3);\r\n rows.push({\r\n name: stmt.getValue(0).getString(),\r\n age: stmt.getValue(1).getInteger(),\r\n salary: stmt.getValue(2).getDouble(),\r\n nickname: nickname.isNull ? undefined : nickname.getString(),\r\n });\r\n }\r\n });\r\n return rows;\r\n}\r\n\r\ndescribe(\"ECDb CSV import\", () => {\r\n const outDir = KnownTestLocations.outputDir;\r\n\r\n it(\"imports in-memory CSV data atomically\", () => {\r\n using ecdb = ECDbTestHelper.createECDb(outDir, \"csv-import-data.ecdb\", testSchema);\r\n expect(ecdb.importCSVData([\r\n [\"Alice\", \"42\", \"1234.5\", \"Résumé\"],\r\n [\"用户\", \"31\", \"2500.25\", \"昵称\"],\r\n ], { className: \"Test.Person\", mapping })).to.equal(2);\r\n\r\n expect(() => ecdb.importCSVData([\r\n [\"Valid\", \"20\", \"1000\", \"valid\"],\r\n [\"Invalid\", \"not-an-integer\", \"1001\", \"invalid\"],\r\n ], { className: \"Test.Person\", mapping })).to.throw(/CSV data row 2 column 1/);\r\n\r\n expect(readPeople(ecdb)).to.deep.equal([\r\n { name: \"Alice\", age: 42, salary: 1234.5, nickname: \"Résumé\" },\r\n { name: \"用户\", age: 31, salary: 2500.25, nickname: \"昵称\" },\r\n ]);\r\n });\r\n\r\n it(\"streams a CSV file and rolls back malformed input\", () => {\r\n const csvPath = path.join(outDir, \"csv-import.csv\");\r\n fs.writeFileSync(csvPath, [\r\n \"Ignored,Age,Name,Salary,Nickname\",\r\n 'skip,42,\"Doe, Jane\",1234.5,\"said \"\"hello\"\"\\nnext\"',\r\n String.raw`skip,31,用户,2500.25,\\N`,\r\n ].join(\"\\r\\n\"));\r\n\r\n using ecdb = ECDbTestHelper.createECDb(outDir, \"csv-import-file.ecdb\", testSchema);\r\n const fileMapping = [\r\n { columnIndex: 1, propertyName: \"Age\" },\r\n { columnIndex: 2, propertyName: \"Name\" },\r\n { columnIndex: 3, propertyName: \"Salary\" },\r\n { columnIndex: 4, propertyName: \"Details.Nickname\" },\r\n ];\r\n expect(ecdb.importCSVFile(csvPath, {\r\n className: \"Test.Person\",\r\n mapping: fileMapping,\r\n hasHeader: true,\r\n nullValue: String.raw`\\N`,\r\n })).to.equal(2);\r\n\r\n fs.writeFileSync(csvPath, [\r\n \"skip,20,Valid,1000,valid\",\r\n 'skip,21,\"unterminated,1001,invalid',\r\n ].join(\"\\n\"));\r\n expect(() => ecdb.importCSVFile(csvPath, { className: \"Test.Person\", mapping: fileMapping }))\r\n .to.throw(/unterminated quoted field/);\r\n\r\n expect(readPeople(ecdb)).to.deep.equal([\r\n { name: \"Doe, Jane\", age: 42, salary: 1234.5, nickname: 'said \"hello\"\\nnext' },\r\n { name: \"用户\", age: 31, salary: 2500.25, nickname: undefined },\r\n ]);\r\n });\r\n\r\n it(\"rejects invalid column mappings before calling native code\", () => {\r\n using ecdb = ECDbTestHelper.createECDb(outDir, \"csv-import-mapping.ecdb\", testSchema);\r\n expect(() => ecdb.importCSVData([], { className: \"Test.Person\", mapping: [] })).to.throw(/must not be empty/);\r\n expect(() => ecdb.importCSVData([], {\r\n className: \"Test.Person\",\r\n mapping: [\r\n { columnIndex: 0, propertyName: \"Name\" },\r\n { columnIndex: 0, propertyName: \"Age\" },\r\n ],\r\n })).to.throw(/duplicate columnIndex/);\r\n });\r\n});\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"ECSqlDatasets.d.ts","sourceRoot":"","sources":["../../../../../src/test/ecsql/dataset/ECSqlDatasets.ts"],"names":[],"mappings":"AA2KA,qBAAa,aAAa;WACJ,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;CA4CnD"}
1
+ {"version":3,"file":"ECSqlDatasets.d.ts","sourceRoot":"","sources":["../../../../../src/test/ecsql/dataset/ECSqlDatasets.ts"],"names":[],"mappings":"AA2KA,qBAAa,aAAa;WACJ,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;CAoDnD"}
@@ -131,6 +131,13 @@ export class ECSqlDatasets {
131
131
  assert.fail("Expected another element id");
132
132
  const anotherElementWithNavProp = iModel.elements.createElement(createElemWithNavProp("TestFeature", iModel, newModelId, spatialCategoryId, ++index, poppedId2));
133
133
  assert.isTrue(Id64.isValidId64(txn.insertElement(anotherElementWithNavProp.toJSON())), "element with nav props insert failed");
134
+ // Add a single link table relationship instance. Inserted last so that it does not shift
135
+ // the ids of any of the elements or aspects above.
136
+ assert.isTrue(Id64.isValidId64(txn.insertRelationship({
137
+ classFullName: "AllProperties:TestElementRefersToElements",
138
+ sourceId: elementIds[0],
139
+ targetId: elementIds[1],
140
+ })), "link table relationship insert failed");
134
141
  });
135
142
  iModel.close();
136
143
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ECSqlDatasets.js","sourceRoot":"","sources":["../../../../../src/test/ecsql/dataset/ECSqlDatasets.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,IAAI,EAAc,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAuB,UAAU,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACrG,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAA2C,MAAM,EAA6C,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AACvK,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AACpF,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAgE/C,SAAS,eAAe,CAAC,SAAiB,EAAE,WAAqB,EAAE,KAAiB,EAAE,KAAiB,EAAE,KAAa;IACpH,eAAe;IACf,MAAM,SAAS,GAAY;QACzB,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;QACvC,KAAK,C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CAAC;IACjB,CAAC;CACF","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 } from \"chai\";\r\nimport * as path from \"path\";\r\nimport { Id64, Id64String } from \"@itwin/core-bentley\";\r\nimport { _nativeDb, IModelDb, IModelHost, SnapshotDb, SpatialCategory } from \"../../../core-backend\";\r\nimport { IModelTestUtils } from \"../../IModelTestUtils\";\r\nimport { Code, ColorDef, ElementAspectProps, GeometryStreamProps, IModel, PhysicalElementProps, RelatedElementProps, SubCategoryAppearance } from \"@itwin/core-common\";\r\nimport { Arc3d, IModelJson, Point2d, Point3d, Range3d } from \"@itwin/core-geometry\";\r\nimport { KnownTestLocations } from \"../../KnownTestLocations\";\r\nimport { withEditTxn } from \"../../../EditTxn\";\r\n\r\n\r\ninterface IPrimitiveBase {\r\n i?: number;\r\n l?: number;\r\n d?: number;\r\n b?: boolean;\r\n dt?: string;\r\n s?: string;\r\n j?: string;\r\n bin?: Uint8Array;\r\n p2d?: Point2d;\r\n p3d?: Point3d;\r\n g?: GeometryStreamProps;\r\n range3d?: Uint8Array;\r\n}\r\n\r\ninterface IPrimitive extends IPrimitiveBase {\r\n st?: ComplexStruct;\r\n}\r\n\r\ninterface IPrimitiveArrayBase {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n array_i?: number[];\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n array_l?: number[];\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n array_d?: number[];\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n array_b?: boolean[];\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n array_dt?: string[];\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n array_s?: string[];\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n array_bin?: Uint8Array[];\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n array_p2d?: Point2d[];\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n array_p3d?: Point3d[];\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n array_g?: GeometryStreamProps[];\r\n}\r\n\r\ninterface IPrimitiveArray extends IPrimitiveArrayBase {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n array_st?: ComplexStruct[];\r\n}\r\n\r\ninterface ComplexStruct extends IPrimitiveArrayBase, IPrimitiveBase { }\r\n\r\ninterface TestElementProps extends PhysicalElementProps, IPrimitive, IPrimitiveArray {\r\n directStr?: string;\r\n directLong?: number;\r\n directDouble?: number;\r\n nullProp?: string;\r\n enumIntProp?: number;\r\n enumIntPropArr?: number[];\r\n enumStringProp?: string;\r\n enumStringPropArr?: string[];\r\n noCaseString?: string;\r\n}\r\n\r\nfunction createElemProps(className: string, _iModelName: IModelDb, modId: Id64String, catId: Id64String, index: number): TestElementProps {\r\n // add Geometry\r\n const geomArray: Arc3d[] = [\r\n Arc3d.createXY(Point3d.create(0, 0), 5),\r\n Arc3d.createXY(Point3d.create(5, 5), 2),\r\n Arc3d.createXY(Point3d.create(-5, -5), 20),\r\n ];\r\n const geometryStream: GeometryStreamProps = [];\r\n for (const geom of geomArray) {\r\n const arcData = IModelJson.Writer.toIModelJson(geom);\r\n geometryStream.push(arcData);\r\n }\r\n // Create props\r\n const elementProps: TestElementProps = {\r\n classFullName: `AllProperties:${className}`,\r\n model: modId,\r\n category: catId,\r\n code: Code.createEmpty(),\r\n geom: geometryStream,\r\n i: 100 + index,\r\n l: 1000 + index,\r\n d: 0.1 + index,\r\n s: `str${index}`,\r\n j: `{\"${String.fromCharCode(65 + index)}\": ${index}}`,\r\n dt: index % 2 === 0 ? \"2017-01-01T00:00:00.000\" : \"2010-01-01T11:11:11.000\",\r\n bin: index % 2 === 0 ? new Uint8Array([1, 2, 3]) : new Uint8Array([11, 21, 31, 34, 53, 21, 14, 14, 55, 22]),\r\n p2d: index % 2 === 0 ? new Point2d(1.034, 2.034) : new Point2d(1111.11, 2222.22),\r\n p3d: index % 2 === 0 ? new Point3d(-1.0, 2.3, 3.0001) : new Point3d(-111.11, -222.22, -333.33),\r\n b: true,\r\n range3d: index === 0\r\n ? new Uint8Array(new Range3d(1.2, 2.3, 3.4, 4.5, 5.6, 6.7).toFloat64Array().buffer)\r\n : new Uint8Array(new Range3d(2.2, 3.3, 4.4, 5.5, 6.6, 7.7).toFloat64Array().buffer),\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n array_b: [true, false, true],\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n array_i: [0, 1, 2],\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n array_d: [0.0, 1.1, 2.2],\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n array_l: [10000, 20000, 30000],\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n array_s: [\"s0\", \"s1\", \"s2\"],\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n array_dt: [\"2017-01-01T00:00:00.000\", \"2010-01-01T11:11:11.000\"],\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n array_p2d: [new Point2d(1.034, 2.034), new Point2d(1111.11, 2222.22)],\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n array_p3d: [new Point3d(-1.0, 2.3, 3.0001), new Point3d(-111.11, -222.22, -333.33)],\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n array_bin: [new Uint8Array([1, 2, 3]), new Uint8Array([11, 21, 31, 34, 53, 21, 14, 14, 55, 22])],\r\n directStr: `str${index}`,\r\n directLong: 1000 + index,\r\n directDouble: 0.1 + index,\r\n nullProp: (index % 2 === 0) ? undefined : \"NotNull\",\r\n noCaseString: (index % 2 === 0) ? \"abc\" : \"ABC\",\r\n enumIntProp: index % 2 === 0 ? 1 : 2,\r\n enumStringProp: index % 2 === 0 ? \"1\" : \"2\",\r\n enumIntPropArr: [1, 2, 3],\r\n enumStringPropArr: [\"1\", \"2\", \"3\"]\r\n };\r\n return elementProps;\r\n}\r\n\r\ninterface TestElementAspectProps extends ElementAspectProps, IPrimitive, IPrimitiveArray { }\r\n\r\nfunction createElemAspect(className: string, _iModelName: IModelDb, elementId: Id64String, autoHandledProp: any): TestElementAspectProps {\r\n // Create props\r\n const elementProps: ElementAspectProps = {\r\n classFullName: `AllProperties:${className}`,\r\n element: { id: elementId },\r\n };\r\n\r\n if (autoHandledProp)\r\n Object.assign(elementProps, autoHandledProp);\r\n\r\n return elementProps;\r\n}\r\n\r\ninterface TestElementWithNavProps extends TestElementProps {\r\n name: string;\r\n featureUsesElement: RelatedElementProps;\r\n}\r\n\r\nfunction createElemWithNavProp(className: string, _iModelName: IModelDb, modId: Id64String, catId: Id64String, index: number, elementId: Id64String): TestElementWithNavProps {\r\n const eProps = createElemProps(className, _iModelName, modId, catId, index);\r\n return {\r\n ...eProps,\r\n name: `Feature${elementId.toString()}`,\r\n featureUsesElement: {\r\n id: elementId,\r\n relClassName: \"AllProperties:TestFeatureUsesElement\",\r\n }\r\n };\r\n}\r\n\r\nexport class ECSqlDatasets {\r\n public static async generateFiles(): Promise<void> {\r\n const fileName = \"AllProperties.bim\";\r\n\r\n await IModelHost.startup();\r\n const filePath = IModelTestUtils.prepareOutputFile(\"ECSqlTests\", fileName);\r\n const iModel = SnapshotDb.createEmpty(filePath, { rootSubject: { name: \"AllPropertiesTest\" } });\r\n const testSchemaPath = path.join(KnownTestLocations.assetsDir, \"ECSqlTests\", \"AllProperties.ecschema.xml\");\r\n await iModel.importSchemas([testSchemaPath]);\r\n await withEditTxn(iModel, async (txn) => {\r\n const [, newModelId] = IModelTestUtils.createAndInsertPhysicalPartitionAndModel(txn, Code.createEmpty(), true);\r\n let spatialCategoryId = SpatialCategory.queryCategoryIdByName(iModel, IModel.dictionaryId, \"MySpatialCategory\");\r\n if (undefined === spatialCategoryId)\r\n spatialCategoryId = SpatialCategory.insert(txn, IModel.dictionaryId, \"MySpatialCategory\", new SubCategoryAppearance({ color: ColorDef.fromString(\"rgb(255,0,0)\").toJSON() }));\r\n\r\n let index = 0;\r\n const elementIds: Id64String[] = [];\r\n for (index = 0; index < 10; ++index) {\r\n const elementProps = createElemProps(\"TestElement\", iModel, newModelId, spatialCategoryId, index);\r\n const testElement = iModel.elements.createElement(elementProps);\r\n const elementId = txn.insertElement(testElement.toJSON());\r\n assert.isTrue(Id64.isValidId64(elementId), \"element insert failed\");\r\n\r\n if (index % 2 === 0) {\r\n const aspectId = txn.insertAspect(createElemAspect(\"TestElementAspect\", iModel, elementId, undefined));\r\n assert.isTrue(Id64.isValidId64(aspectId), \"element aspect insert failed\");\r\n }\r\n elementIds.push(elementId);\r\n }\r\n\r\n // Add two instances of feature class instance with a navigation property\r\n const poppedId1 = elementIds.pop();\r\n if (poppedId1 === undefined)\r\n assert.fail(\"Expected at least 1 element id\");\r\n const elementWithNavProp = iModel.elements.createElement(createElemWithNavProp(\"TestFeature\", iModel, newModelId, spatialCategoryId, ++index, poppedId1));\r\n assert.isTrue(Id64.isValidId64(txn.insertElement(elementWithNavProp.toJSON())), \"element with nav props insert failed\");\r\n\r\n const poppedId2 = elementIds.pop();\r\n if (poppedId2 === undefined)\r\n assert.fail(\"Expected another element id\");\r\n const anotherElementWithNavProp = iModel.elements.createElement(createElemWithNavProp(\"TestFeature\", iModel, newModelId, spatialCategoryId, ++index, poppedId2));\r\n assert.isTrue(Id64.isValidId64(txn.insertElement(anotherElementWithNavProp.toJSON())), \"element with nav props insert failed\");\r\n });\r\n iModel.close();\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"ECSqlDatasets.js","sourceRoot":"","sources":["../../../../../src/test/ecsql/dataset/ECSqlDatasets.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,IAAI,EAAc,MAAM,qB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AAC,CAAC,CAAC;YAC1J,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,aAAa,CAAC,kBAAkB,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,sCAAsC,CAAC,CAAC;YAExH,MAAM,SAAS,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC;YACnC,IAAI,SAAS,KAAK,SAAS;gBACzB,MAAM,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAC;YAC7C,MAAM,yBAAyB,GAAG,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,qBAAqB,CAAC,aAAa,EAAE,MAAM,EAAE,UAAU,EAAE,iBAAiB,EAAE,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC;YACjK,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,aAAa,CAAC,yBAAyB,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,sCAAsC,CAAC,CAAC;YAE/H,yFAAyF;YACzF,mDAAmD;YACnD,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,kBAAkB,CAAC;gBACpD,aAAa,EAAE,2CAA2C;gBAC1D,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC;gBACvB,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC;aACxB,CAAC,CAAC,EAAE,uCAAuC,CAAC,CAAC;QAChD,CAAC,CAAC,CAAC;QACH,MAAM,CAAC,KAAK,EAAE,CAAC;IACjB,CAAC;CACF","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 } from \"chai\";\r\nimport * as path from \"path\";\r\nimport { Id64, Id64String } from \"@itwin/core-bentley\";\r\nimport { _nativeDb, IModelDb, IModelHost, SnapshotDb, SpatialCategory } from \"../../../core-backend\";\r\nimport { IModelTestUtils } from \"../../IModelTestUtils\";\r\nimport { Code, ColorDef, ElementAspectProps, GeometryStreamProps, IModel, PhysicalElementProps, RelatedElementProps, SubCategoryAppearance } from \"@itwin/core-common\";\r\nimport { Arc3d, IModelJson, Point2d, Point3d, Range3d } from \"@itwin/core-geometry\";\r\nimport { KnownTestLocations } from \"../../KnownTestLocations\";\r\nimport { withEditTxn } from \"../../../EditTxn\";\r\n\r\n\r\ninterface IPrimitiveBase {\r\n i?: number;\r\n l?: number;\r\n d?: number;\r\n b?: boolean;\r\n dt?: string;\r\n s?: string;\r\n j?: string;\r\n bin?: Uint8Array;\r\n p2d?: Point2d;\r\n p3d?: Point3d;\r\n g?: GeometryStreamProps;\r\n range3d?: Uint8Array;\r\n}\r\n\r\ninterface IPrimitive extends IPrimitiveBase {\r\n st?: ComplexStruct;\r\n}\r\n\r\ninterface IPrimitiveArrayBase {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n array_i?: number[];\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n array_l?: number[];\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n array_d?: number[];\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n array_b?: boolean[];\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n array_dt?: string[];\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n array_s?: string[];\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n array_bin?: Uint8Array[];\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n array_p2d?: Point2d[];\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n array_p3d?: Point3d[];\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n array_g?: GeometryStreamProps[];\r\n}\r\n\r\ninterface IPrimitiveArray extends IPrimitiveArrayBase {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n array_st?: ComplexStruct[];\r\n}\r\n\r\ninterface ComplexStruct extends IPrimitiveArrayBase, IPrimitiveBase { }\r\n\r\ninterface TestElementProps extends PhysicalElementProps, IPrimitive, IPrimitiveArray {\r\n directStr?: string;\r\n directLong?: number;\r\n directDouble?: number;\r\n nullProp?: string;\r\n enumIntProp?: number;\r\n enumIntPropArr?: number[];\r\n enumStringProp?: string;\r\n enumStringPropArr?: string[];\r\n noCaseString?: string;\r\n}\r\n\r\nfunction createElemProps(className: string, _iModelName: IModelDb, modId: Id64String, catId: Id64String, index: number): TestElementProps {\r\n // add Geometry\r\n const geomArray: Arc3d[] = [\r\n Arc3d.createXY(Point3d.create(0, 0), 5),\r\n Arc3d.createXY(Point3d.create(5, 5), 2),\r\n Arc3d.createXY(Point3d.create(-5, -5), 20),\r\n ];\r\n const geometryStream: GeometryStreamProps = [];\r\n for (const geom of geomArray) {\r\n const arcData = IModelJson.Writer.toIModelJson(geom);\r\n geometryStream.push(arcData);\r\n }\r\n // Create props\r\n const elementProps: TestElementProps = {\r\n classFullName: `AllProperties:${className}`,\r\n model: modId,\r\n category: catId,\r\n code: Code.createEmpty(),\r\n geom: geometryStream,\r\n i: 100 + index,\r\n l: 1000 + index,\r\n d: 0.1 + index,\r\n s: `str${index}`,\r\n j: `{\"${String.fromCharCode(65 + index)}\": ${index}}`,\r\n dt: index % 2 === 0 ? \"2017-01-01T00:00:00.000\" : \"2010-01-01T11:11:11.000\",\r\n bin: index % 2 === 0 ? new Uint8Array([1, 2, 3]) : new Uint8Array([11, 21, 31, 34, 53, 21, 14, 14, 55, 22]),\r\n p2d: index % 2 === 0 ? new Point2d(1.034, 2.034) : new Point2d(1111.11, 2222.22),\r\n p3d: index % 2 === 0 ? new Point3d(-1.0, 2.3, 3.0001) : new Point3d(-111.11, -222.22, -333.33),\r\n b: true,\r\n range3d: index === 0\r\n ? new Uint8Array(new Range3d(1.2, 2.3, 3.4, 4.5, 5.6, 6.7).toFloat64Array().buffer)\r\n : new Uint8Array(new Range3d(2.2, 3.3, 4.4, 5.5, 6.6, 7.7).toFloat64Array().buffer),\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n array_b: [true, false, true],\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n array_i: [0, 1, 2],\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n array_d: [0.0, 1.1, 2.2],\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n array_l: [10000, 20000, 30000],\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n array_s: [\"s0\", \"s1\", \"s2\"],\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n array_dt: [\"2017-01-01T00:00:00.000\", \"2010-01-01T11:11:11.000\"],\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n array_p2d: [new Point2d(1.034, 2.034), new Point2d(1111.11, 2222.22)],\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n array_p3d: [new Point3d(-1.0, 2.3, 3.0001), new Point3d(-111.11, -222.22, -333.33)],\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n array_bin: [new Uint8Array([1, 2, 3]), new Uint8Array([11, 21, 31, 34, 53, 21, 14, 14, 55, 22])],\r\n directStr: `str${index}`,\r\n directLong: 1000 + index,\r\n directDouble: 0.1 + index,\r\n nullProp: (index % 2 === 0) ? undefined : \"NotNull\",\r\n noCaseString: (index % 2 === 0) ? \"abc\" : \"ABC\",\r\n enumIntProp: index % 2 === 0 ? 1 : 2,\r\n enumStringProp: index % 2 === 0 ? \"1\" : \"2\",\r\n enumIntPropArr: [1, 2, 3],\r\n enumStringPropArr: [\"1\", \"2\", \"3\"]\r\n };\r\n return elementProps;\r\n}\r\n\r\ninterface TestElementAspectProps extends ElementAspectProps, IPrimitive, IPrimitiveArray { }\r\n\r\nfunction createElemAspect(className: string, _iModelName: IModelDb, elementId: Id64String, autoHandledProp: any): TestElementAspectProps {\r\n // Create props\r\n const elementProps: ElementAspectProps = {\r\n classFullName: `AllProperties:${className}`,\r\n element: { id: elementId },\r\n };\r\n\r\n if (autoHandledProp)\r\n Object.assign(elementProps, autoHandledProp);\r\n\r\n return elementProps;\r\n}\r\n\r\ninterface TestElementWithNavProps extends TestElementProps {\r\n name: string;\r\n featureUsesElement: RelatedElementProps;\r\n}\r\n\r\nfunction createElemWithNavProp(className: string, _iModelName: IModelDb, modId: Id64String, catId: Id64String, index: number, elementId: Id64String): TestElementWithNavProps {\r\n const eProps = createElemProps(className, _iModelName, modId, catId, index);\r\n return {\r\n ...eProps,\r\n name: `Feature${elementId.toString()}`,\r\n featureUsesElement: {\r\n id: elementId,\r\n relClassName: \"AllProperties:TestFeatureUsesElement\",\r\n }\r\n };\r\n}\r\n\r\nexport class ECSqlDatasets {\r\n public static async generateFiles(): Promise<void> {\r\n const fileName = \"AllProperties.bim\";\r\n\r\n await IModelHost.startup();\r\n const filePath = IModelTestUtils.prepareOutputFile(\"ECSqlTests\", fileName);\r\n const iModel = SnapshotDb.createEmpty(filePath, { rootSubject: { name: \"AllPropertiesTest\" } });\r\n const testSchemaPath = path.join(KnownTestLocations.assetsDir, \"ECSqlTests\", \"AllProperties.ecschema.xml\");\r\n await iModel.importSchemas([testSchemaPath]);\r\n await withEditTxn(iModel, async (txn) => {\r\n const [, newModelId] = IModelTestUtils.createAndInsertPhysicalPartitionAndModel(txn, Code.createEmpty(), true);\r\n let spatialCategoryId = SpatialCategory.queryCategoryIdByName(iModel, IModel.dictionaryId, \"MySpatialCategory\");\r\n if (undefined === spatialCategoryId)\r\n spatialCategoryId = SpatialCategory.insert(txn, IModel.dictionaryId, \"MySpatialCategory\", new SubCategoryAppearance({ color: ColorDef.fromString(\"rgb(255,0,0)\").toJSON() }));\r\n\r\n let index = 0;\r\n const elementIds: Id64String[] = [];\r\n for (index = 0; index < 10; ++index) {\r\n const elementProps = createElemProps(\"TestElement\", iModel, newModelId, spatialCategoryId, index);\r\n const testElement = iModel.elements.createElement(elementProps);\r\n const elementId = txn.insertElement(testElement.toJSON());\r\n assert.isTrue(Id64.isValidId64(elementId), \"element insert failed\");\r\n\r\n if (index % 2 === 0) {\r\n const aspectId = txn.insertAspect(createElemAspect(\"TestElementAspect\", iModel, elementId, undefined));\r\n assert.isTrue(Id64.isValidId64(aspectId), \"element aspect insert failed\");\r\n }\r\n elementIds.push(elementId);\r\n }\r\n\r\n // Add two instances of feature class instance with a navigation property\r\n const poppedId1 = elementIds.pop();\r\n if (poppedId1 === undefined)\r\n assert.fail(\"Expected at least 1 element id\");\r\n const elementWithNavProp = iModel.elements.createElement(createElemWithNavProp(\"TestFeature\", iModel, newModelId, spatialCategoryId, ++index, poppedId1));\r\n assert.isTrue(Id64.isValidId64(txn.insertElement(elementWithNavProp.toJSON())), \"element with nav props insert failed\");\r\n\r\n const poppedId2 = elementIds.pop();\r\n if (poppedId2 === undefined)\r\n assert.fail(\"Expected another element id\");\r\n const anotherElementWithNavProp = iModel.elements.createElement(createElemWithNavProp(\"TestFeature\", iModel, newModelId, spatialCategoryId, ++index, poppedId2));\r\n assert.isTrue(Id64.isValidId64(txn.insertElement(anotherElementWithNavProp.toJSON())), \"element with nav props insert failed\");\r\n\r\n // Add a single link table relationship instance. Inserted last so that it does not shift\r\n // the ids of any of the elements or aspects above.\r\n assert.isTrue(Id64.isValidId64(txn.insertRelationship({\r\n classFullName: \"AllProperties:TestElementRefersToElements\",\r\n sourceId: elementIds[0],\r\n targetId: elementIds[1],\r\n })), \"link table relationship insert failed\");\r\n });\r\n iModel.close();\r\n }\r\n}\r\n"]}
@@ -1,3 +1,55 @@
1
+ var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
2
+ if (value !== null && value !== void 0) {
3
+ if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
4
+ var dispose, inner;
5
+ if (async) {
6
+ if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
7
+ dispose = value[Symbol.asyncDispose];
8
+ }
9
+ if (dispose === void 0) {
10
+ if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
11
+ dispose = value[Symbol.dispose];
12
+ if (async) inner = dispose;
13
+ }
14
+ if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
15
+ if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
16
+ env.stack.push({ value: value, dispose: dispose, async: async });
17
+ }
18
+ else if (async) {
19
+ env.stack.push({ async: true });
20
+ }
21
+ return value;
22
+ };
23
+ var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
24
+ return function (env) {
25
+ function fail(e) {
26
+ env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
27
+ env.hasError = true;
28
+ }
29
+ var r, s = 0;
30
+ function next() {
31
+ while (r = env.stack.pop()) {
32
+ try {
33
+ if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
34
+ if (r.dispose) {
35
+ var result = r.dispose.call(r.value);
36
+ if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
37
+ }
38
+ else s |= 1;
39
+ }
40
+ catch (e) {
41
+ fail(e);
42
+ }
43
+ }
44
+ if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
45
+ if (env.hasError) throw env.error;
46
+ }
47
+ return next();
48
+ };
49
+ })(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
50
+ var e = new Error(message);
51
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
52
+ });
1
53
  /*---------------------------------------------------------------------------------------------
2
54
  * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
55
  * See LICENSE.md in the project root for license terms and full copyright notice.
@@ -17,6 +69,7 @@ var TestDataset;
17
69
  TestDataset["AllProperties"] = "AllProperties.bim";
18
70
  })(TestDataset || (TestDataset = {}));
19
71
  const snapshotDbs = {};
72
+ let supportsRelations = false;
20
73
  describe("Markdown based ECDb test runner", async () => {
21
74
  before(async () => {
22
75
  await ECSqlDatasets.generateFiles();
@@ -24,7 +77,23 @@ describe("Markdown based ECDb test runner", async () => {
24
77
  if (!fs.existsSync(datasetFilePath)) {
25
78
  throw new Error(`Dataset file ${datasetFilePath} does not exist`);
26
79
  }
27
- snapshotDbs[TestDataset.AllProperties] = SnapshotDb.openFile(datasetFilePath);
80
+ const snapshotDb = SnapshotDb.openFile(datasetFilePath);
81
+ snapshotDbs[TestDataset.AllProperties] = snapshotDb;
82
+ supportsRelations = snapshotDb.withSqliteStatement("SELECT 1 FROM pragma_module_list WHERE name='relations'", (statement) => statement.step() === DbResult.BE_SQLITE_ROW);
83
+ if (supportsRelations) {
84
+ const env_1 = { stack: [], error: void 0, hasError: false };
85
+ try {
86
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
87
+ const _statement = __addDisposableResource(env_1, snapshotDb.prepareStatement("SELECT RelatedECInstanceId FROM ECVLib.Relations(1, 1) ECSQLOPTIONS ENABLE_EXPERIMENTAL_FEATURES", false), false);
88
+ }
89
+ catch (e_1) {
90
+ env_1.error = e_1;
91
+ env_1.hasError = true;
92
+ }
93
+ finally {
94
+ __disposeResources(env_1);
95
+ }
96
+ }
28
97
  });
29
98
  after(() => {
30
99
  for (const key in snapshotDbs) {
@@ -45,15 +114,21 @@ describe("Markdown based ECDb test runner", async () => {
45
114
  continue;
46
115
  }
47
116
  const dataset = TestDataset.AllProperties;
117
+ const skipIfUnsupported = function () {
118
+ if ("RelationsVTTests.ecsql.md" === test.fileName && !supportsRelations)
119
+ this.skip();
120
+ };
48
121
  if (test.mode === ECDbTestMode.Both || test.mode === ECDbTestMode.Statement) {
49
122
  if (test.skip)
50
123
  it(`${test.fileName}: ${test.title} (Statement) skipped. Reason: ${test.skip}`);
51
124
  else if (test.only)
52
- it.only(`${test.fileName}: ${test.title} (Statement)`, () => {
125
+ it.only(`${test.fileName}: ${test.title} (Statement)`, function () {
126
+ skipIfUnsupported.call(this);
53
127
  runECSqlStatementTest(test, dataset);
54
128
  });
55
129
  else
56
- it(`${test.fileName}: ${test.title} (Statement)`, () => {
130
+ it(`${test.fileName}: ${test.title} (Statement)`, function () {
131
+ skipIfUnsupported.call(this);
57
132
  runECSqlStatementTest(test, dataset);
58
133
  });
59
134
  }
@@ -63,18 +138,22 @@ describe("Markdown based ECDb test runner", async () => {
63
138
  it(`${test.fileName}: ${test.title} (ECSqlSyncReader) skipped. Reason: ${test.skip}`);
64
139
  }
65
140
  else if (test.only) {
66
- it.only(`${test.fileName}: ${test.title} (ECSqlReader)`, async () => {
141
+ it.only(`${test.fileName}: ${test.title} (ECSqlReader)`, async function () {
142
+ skipIfUnsupported.call(this);
67
143
  await runECSqlReaderTest(test, dataset);
68
144
  });
69
- it.only(`${test.fileName}: ${test.title} (ECSqlSyncReader)`, async () => {
145
+ it.only(`${test.fileName}: ${test.title} (ECSqlSyncReader)`, async function () {
146
+ skipIfUnsupported.call(this);
70
147
  await runECSqlSyncReaderTest(test, dataset);
71
148
  });
72
149
  }
73
150
  else {
74
- it(`${test.fileName}: ${test.title} (ECSqlReader)`, async () => {
151
+ it(`${test.fileName}: ${test.title} (ECSqlReader)`, async function () {
152
+ skipIfUnsupported.call(this);
75
153
  await runECSqlReaderTest(test, dataset);
76
154
  });
77
- it(`${test.fileName}: ${test.title} (ECSqlSyncReader)`, async () => {
155
+ it(`${test.fileName}: ${test.title} (ECSqlSyncReader)`, async function () {
156
+ skipIfUnsupported.call(this);
78
157
  await runECSqlSyncReaderTest(test, dataset);
79
158
  });
80
159
  }