@itwin/presentation-core-interop 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/lib/cjs/core-interop/QueryExecutor.d.ts.map +1 -1
- package/lib/cjs/core-interop/QueryExecutor.js +5 -1
- package/lib/cjs/core-interop/QueryExecutor.js.map +1 -1
- package/lib/esm/core-interop/QueryExecutor.d.ts.map +1 -1
- package/lib/esm/core-interop/QueryExecutor.js +5 -1
- package/lib/esm/core-interop/QueryExecutor.js.map +1 -1
- package/package.json +12 -12
- package/.mocharc.json +0 -8
- package/.nycrc +0 -14
- package/api/presentation-core-interop.api.md +0 -38
- package/api/presentation-core-interop.exports.csv +0 -7
- package/eslint.config.js +0 -14
- package/lib/cjs/test/Formatting.test.d.ts +0 -2
- package/lib/cjs/test/Formatting.test.d.ts.map +0 -1
- package/lib/cjs/test/Formatting.test.js +0 -282
- package/lib/cjs/test/Formatting.test.js.map +0 -1
- package/lib/cjs/test/Logging.test.d.ts +0 -2
- package/lib/cjs/test/Logging.test.d.ts.map +0 -1
- package/lib/cjs/test/Logging.test.js +0 -57
- package/lib/cjs/test/Logging.test.js.map +0 -1
- package/lib/cjs/test/Metadata.test.d.ts +0 -2
- package/lib/cjs/test/Metadata.test.d.ts.map +0 -1
- package/lib/cjs/test/Metadata.test.js +0 -684
- package/lib/cjs/test/Metadata.test.js.map +0 -1
- package/lib/cjs/test/QueryExecutor.test.d.ts +0 -2
- package/lib/cjs/test/QueryExecutor.test.d.ts.map +0 -1
- package/lib/cjs/test/QueryExecutor.test.js +0 -178
- package/lib/cjs/test/QueryExecutor.test.js.map +0 -1
- package/lib/cjs/test/Transactions.test.d.ts +0 -2
- package/lib/cjs/test/Transactions.test.d.ts.map +0 -1
- package/lib/cjs/test/Transactions.test.js +0 -73
- package/lib/cjs/test/Transactions.test.js.map +0 -1
- package/lib/cjs/test/index.d.ts +0 -2
- package/lib/cjs/test/index.d.ts.map +0 -1
- package/lib/cjs/test/index.js +0 -43
- package/lib/cjs/test/index.js.map +0 -1
- package/lib/esm/test/Formatting.test.d.ts +0 -2
- package/lib/esm/test/Formatting.test.d.ts.map +0 -1
- package/lib/esm/test/Formatting.test.js +0 -277
- package/lib/esm/test/Formatting.test.js.map +0 -1
- package/lib/esm/test/Logging.test.d.ts +0 -2
- package/lib/esm/test/Logging.test.d.ts.map +0 -1
- package/lib/esm/test/Logging.test.js +0 -52
- package/lib/esm/test/Logging.test.js.map +0 -1
- package/lib/esm/test/Metadata.test.d.ts +0 -2
- package/lib/esm/test/Metadata.test.d.ts.map +0 -1
- package/lib/esm/test/Metadata.test.js +0 -679
- package/lib/esm/test/Metadata.test.js.map +0 -1
- package/lib/esm/test/QueryExecutor.test.d.ts +0 -2
- package/lib/esm/test/QueryExecutor.test.d.ts.map +0 -1
- package/lib/esm/test/QueryExecutor.test.js +0 -173
- package/lib/esm/test/QueryExecutor.test.js.map +0 -1
- package/lib/esm/test/Transactions.test.d.ts +0 -2
- package/lib/esm/test/Transactions.test.d.ts.map +0 -1
- package/lib/esm/test/Transactions.test.js +0 -68
- package/lib/esm/test/Transactions.test.js.map +0 -1
- package/lib/esm/test/index.d.ts +0 -2
- package/lib/esm/test/index.d.ts.map +0 -1
- package/lib/esm/test/index.js +0 -15
- package/lib/esm/test/index.js.map +0 -1
- package/src/core-interop/Formatting.ts +0 -194
- package/src/core-interop/Logging.ts +0 -58
- package/src/core-interop/Metadata.ts +0 -62
- package/src/core-interop/MetadataInternal.ts +0 -413
- package/src/core-interop/QueryExecutor.ts +0 -122
- package/src/core-interop/Transactions.ts +0 -92
- package/src/presentation-core-interop.ts +0 -10
- package/src/test/Formatting.test.ts +0 -358
- package/src/test/Logging.test.ts +0 -59
- package/src/test/Metadata.test.ts +0 -786
- package/src/test/QueryExecutor.test.ts +0 -217
- package/src/test/Transactions.test.ts +0 -74
- package/src/test/index.ts +0 -17
- package/tsconfig.cjs.json +0 -7
- package/tsconfig.esm.json +0 -7
- package/tsconfig.json +0 -14
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @itwin/presentation-core-interop
|
|
2
2
|
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#582](https://github.com/iTwin/presentation/pull/582): Updated `ECSqlQueryExecutor` to pass `restartToken` options to the underlying ECSql reader.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- [#585](https://github.com/iTwin/presentation/pull/585): `createQueryReader`: Remove extra whitespace from executed queries
|
|
12
|
+
- [#592](https://github.com/iTwin/presentation/pull/592): Do not publish source files to the npm
|
|
13
|
+
- Updated dependencies:
|
|
14
|
+
- @itwin/presentation-shared@0.2.0
|
|
15
|
+
|
|
16
|
+
## 0.1.2
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- Updated dependencies:
|
|
21
|
+
- @itwin/presentation-shared@0.1.1
|
|
22
|
+
|
|
3
23
|
## 0.1.1
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryExecutor.d.ts","sourceRoot":"","sources":["../../../src/core-interop/QueryExecutor.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,YAAY,EAAuC,MAAM,oBAAoB,CAAC;AAEjH,OAAO,EAA+B,kBAAkB,
|
|
1
|
+
{"version":3,"file":"QueryExecutor.d.ts","sourceRoot":"","sources":["../../../src/core-interop/QueryExecutor.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,YAAY,EAAuC,MAAM,oBAAoB,CAAC;AAEjH,OAAO,EAA+B,kBAAkB,EAA0D,MAAM,4BAA4B,CAAC;AAErJ;;;GAGG;AACH,UAAU,sBAAsB;IAC9B,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,WAAW,CAAC;CAC7F;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,sBAAsB,GAAG,kBAAkB,CAsB3F"}
|
|
@@ -8,6 +8,7 @@ exports.createECSqlQueryExecutor = void 0;
|
|
|
8
8
|
const core_bentley_1 = require("@itwin/core-bentley");
|
|
9
9
|
const core_common_1 = require("@itwin/core-common");
|
|
10
10
|
const core_geometry_1 = require("@itwin/core-geometry");
|
|
11
|
+
const presentation_shared_1 = require("@itwin/presentation-shared");
|
|
11
12
|
/**
|
|
12
13
|
* Creates an `ECSqlQueryExecutor` from either [IModelDb](https://www.itwinjs.org/reference/core-backend/imodels/imodeldb/) or
|
|
13
14
|
* [IModelConnection](https://www.itwinjs.org/reference/core-frontend/imodelconnection/imodelconnection/).
|
|
@@ -40,7 +41,10 @@ function createECSqlQueryExecutor(imodel) {
|
|
|
40
41
|
opts.setRowFormat(core_common_1.QueryRowFormat.UseECSqlPropertyIndexes);
|
|
41
42
|
break;
|
|
42
43
|
}
|
|
43
|
-
|
|
44
|
+
if (config?.restartToken) {
|
|
45
|
+
opts.setRestartToken(config?.restartToken);
|
|
46
|
+
}
|
|
47
|
+
return new ECSqlQueryReaderImpl(imodel.createQueryReader((0, presentation_shared_1.trimWhitespace)(addCTEs(ecsql, ctes)), bind(bindings ?? []), opts.getOptions()), config?.rowFormat === "Indexes" ? "array" : "object");
|
|
44
48
|
},
|
|
45
49
|
};
|
|
46
50
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryExecutor.js","sourceRoot":"","sources":["../../../src/core-interop/QueryExecutor.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;AAEhG,sDAA0D;AAC1D,oDAAiH;AACjH,wDAAwD;
|
|
1
|
+
{"version":3,"file":"QueryExecutor.js","sourceRoot":"","s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AG,CAAC,EAAE,kCAAmB,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;gBAChE,MAAM;YACR,KAAK,KAAK;gBACR,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC;gBAC/B,MAAM;YACR,KAAK,MAAM;gBACT,MAAM,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC;gBAChC,MAAM;YACR,KAAK,SAAS;gBACZ,MAAM,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,EAAE,uBAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;gBACrD,MAAM;YACR,KAAK,SAAS;gBACZ,MAAM,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,EAAE,uBAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;gBACrD,MAAM;YACR,KAAK,QAAQ;gBACX,MAAM,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC;gBAClC,MAAM;QACV,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,OAAO,CAAC,KAAa,EAAE,IAA0B;IACxD,MAAM,UAAU,GAAG,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,kBAAkB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IAC5E,OAAO,GAAG,UAAU,GAAG,KAAK,EAAE,CAAC;AACjC,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 { OrderedId64Iterable } from \"@itwin/core-bentley\";\nimport { ECSqlReader, QueryBinder, QueryOptions, QueryOptionsBuilder, QueryRowFormat } from \"@itwin/core-common\";\nimport { Point2d, Point3d } from \"@itwin/core-geometry\";\nimport { ECSqlBinding, ECSqlQueryDef, ECSqlQueryExecutor, ECSqlQueryReaderOptions, ECSqlQueryRow, trimWhitespace } from \"@itwin/presentation-shared\";\n\n/**\n * Defines input for `createECSqlQueryExecutor`. Generally, this is an instance of either [IModelDb](https://www.itwinjs.org/reference/core-backend/imodels/imodeldb/)\n * or [IModelConnection](https://www.itwinjs.org/reference/core-frontend/imodelconnection/imodelconnection/).\n */\ninterface CoreECSqlReaderFactory {\n createQueryReader(ecsql: string, binder?: QueryBinder, options?: QueryOptions): ECSqlReader;\n}\n\n/**\n * Creates an `ECSqlQueryExecutor` from either [IModelDb](https://www.itwinjs.org/reference/core-backend/imodels/imodeldb/) or\n * [IModelConnection](https://www.itwinjs.org/reference/core-frontend/imodelconnection/imodelconnection/).\n *\n * Usage example:\n *\n * ```ts\n * import { IModelDb } from \"@itwin/core-backend\";\n * import { createECSqlQueryExecutor } from \"@itwin/presentation-core-interop\";\n *\n * const imodel: IModelDb = getIModelDb();\n * const executor = createECSqlQueryExecutor(imodel);\n * for await (const row of executor.createQueryReader(MY_QUERY)) {\n * // TODO: do something with `row`\n * }\n * ```\n *\n * @beta\n */\nexport function createECSqlQueryExecutor(imodel: CoreECSqlReaderFactory): ECSqlQueryExecutor {\n return {\n createQueryReader(query: ECSqlQueryDef, config?: ECSqlQueryReaderOptions) {\n const { ctes, ecsql, bindings } = query;\n const opts = new QueryOptionsBuilder();\n switch (config?.rowFormat) {\n case \"ECSqlPropertyNames\":\n opts.setRowFormat(QueryRowFormat.UseECSqlPropertyNames);\n break;\n case \"Indexes\":\n opts.setRowFormat(QueryRowFormat.UseECSqlPropertyIndexes);\n break;\n }\n if (config?.restartToken) {\n opts.setRestartToken(config?.restartToken);\n }\n return new ECSqlQueryReaderImpl(\n imodel.createQueryReader(trimWhitespace(addCTEs(ecsql, ctes)), bind(bindings ?? []), opts.getOptions()),\n config?.rowFormat === \"Indexes\" ? \"array\" : \"object\",\n );\n },\n };\n}\n\nclass ECSqlQueryReaderImpl implements ReturnType<ECSqlQueryExecutor[\"createQueryReader\"]> {\n public constructor(\n private _coreReader: ECSqlReader,\n private _format: \"array\" | \"object\",\n ) {}\n public [Symbol.asyncIterator](): AsyncIterableIterator<ECSqlQueryRow> {\n return this;\n }\n public async next(): Promise<IteratorResult<ECSqlQueryRow>> {\n const res = await this._coreReader.next();\n if (res.done) {\n return { done: true, value: undefined };\n }\n return {\n done: false,\n value: this._format === \"array\" ? res.value.toArray() : res.value.toRow(),\n };\n }\n}\n\nfunction bind(bindings: ECSqlBinding[]): QueryBinder {\n const binder = new QueryBinder();\n bindings.forEach((b, i) => {\n if (b.value === undefined) {\n binder.bindNull(i + 1);\n return;\n }\n switch (b.type) {\n case \"boolean\":\n binder.bindBoolean(i + 1, b.value);\n break;\n case \"double\":\n binder.bindDouble(i + 1, b.value);\n break;\n case \"id\":\n binder.bindId(i + 1, b.value);\n break;\n case \"idset\":\n binder.bindIdSet(i + 1, OrderedId64Iterable.sortArray(b.value));\n break;\n case \"int\":\n binder.bindInt(i + 1, b.value);\n break;\n case \"long\":\n binder.bindLong(i + 1, b.value);\n break;\n case \"point2d\":\n binder.bindPoint2d(i + 1, Point2d.fromJSON(b.value));\n break;\n case \"point3d\":\n binder.bindPoint3d(i + 1, Point3d.fromJSON(b.value));\n break;\n case \"string\":\n binder.bindString(i + 1, b.value);\n break;\n }\n });\n return binder;\n}\n\nfunction addCTEs(ecsql: string, ctes: string[] | undefined) {\n const ctesPrefix = ctes?.length ? `WITH RECURSIVE ${ctes.join(\", \")} ` : \"\";\n return `${ctesPrefix}${ecsql}`;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryExecutor.d.ts","sourceRoot":"","sources":["../../../src/core-interop/QueryExecutor.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,YAAY,EAAuC,MAAM,oBAAoB,CAAC;AAEjH,OAAO,EAA+B,kBAAkB,
|
|
1
|
+
{"version":3,"file":"QueryExecutor.d.ts","sourceRoot":"","sources":["../../../src/core-interop/QueryExecutor.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,YAAY,EAAuC,MAAM,oBAAoB,CAAC;AAEjH,OAAO,EAA+B,kBAAkB,EAA0D,MAAM,4BAA4B,CAAC;AAErJ;;;GAGG;AACH,UAAU,sBAAsB;IAC9B,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,WAAW,CAAC;CAC7F;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,sBAAsB,GAAG,kBAAkB,CAsB3F"}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import { OrderedId64Iterable } from "@itwin/core-bentley";
|
|
6
6
|
import { QueryBinder, QueryOptionsBuilder, QueryRowFormat } from "@itwin/core-common";
|
|
7
7
|
import { Point2d, Point3d } from "@itwin/core-geometry";
|
|
8
|
+
import { trimWhitespace } from "@itwin/presentation-shared";
|
|
8
9
|
/**
|
|
9
10
|
* Creates an `ECSqlQueryExecutor` from either [IModelDb](https://www.itwinjs.org/reference/core-backend/imodels/imodeldb/) or
|
|
10
11
|
* [IModelConnection](https://www.itwinjs.org/reference/core-frontend/imodelconnection/imodelconnection/).
|
|
@@ -37,7 +38,10 @@ export function createECSqlQueryExecutor(imodel) {
|
|
|
37
38
|
opts.setRowFormat(QueryRowFormat.UseECSqlPropertyIndexes);
|
|
38
39
|
break;
|
|
39
40
|
}
|
|
40
|
-
|
|
41
|
+
if (config?.restartToken) {
|
|
42
|
+
opts.setRestartToken(config?.restartToken);
|
|
43
|
+
}
|
|
44
|
+
return new ECSqlQueryReaderImpl(imodel.createQueryReader(trimWhitespace(addCTEs(ecsql, ctes)), bind(bindings ?? []), opts.getOptions()), config?.rowFormat === "Indexes" ? "array" : "object");
|
|
41
45
|
},
|
|
42
46
|
};
|
|
43
47
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryExecutor.js","sourceRoot":"","sources":["../../../src/core-interop/QueryExecutor.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAe,WAAW,EAAgB,mBAAmB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACjH,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"QueryExecutor.js","sourceRoot":"","sources":["../../../src/core-interop/QueryExecutor.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAe,WAAW,EAAgB,mBAAmB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACjH,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAA2F,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAUrJ;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,wBAAwB,CAAC,MAA8B;IACrE,OAAO;QACL,iBAAiB,CAAC,KAAoB,EAAE,MAAgC;YACtE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;YACxC,MAAM,IAAI,GAAG,IAAI,mBAAmB,EAAE,CAAC;YACvC,QAAQ,MAAM,EAAE,SAAS,EAAE,CAAC;gBAC1B,KAAK,oBAAoB;oBACvB,IAAI,CAAC,YAAY,CAAC,cAAc,CAAC,qBAAqB,CAAC,CAAC;oBACxD,MAAM;gBACR,KAAK,SAAS;oBACZ,IAAI,CAAC,Y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,KAAK,CAAC,CAAC,CAAC;gBACrD,MAAM;YACR,KAAK,QAAQ;gBACX,MAAM,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC;gBAClC,MAAM;QACV,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,OAAO,CAAC,KAAa,EAAE,IAA0B;IACxD,MAAM,UAAU,GAAG,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,kBAAkB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IAC5E,OAAO,GAAG,UAAU,GAAG,KAAK,EAAE,CAAC;AACjC,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 { OrderedId64Iterable } from \"@itwin/core-bentley\";\nimport { ECSqlReader, QueryBinder, QueryOptions, QueryOptionsBuilder, QueryRowFormat } from \"@itwin/core-common\";\nimport { Point2d, Point3d } from \"@itwin/core-geometry\";\nimport { ECSqlBinding, ECSqlQueryDef, ECSqlQueryExecutor, ECSqlQueryReaderOptions, ECSqlQueryRow, trimWhitespace } from \"@itwin/presentation-shared\";\n\n/**\n * Defines input for `createECSqlQueryExecutor`. Generally, this is an instance of either [IModelDb](https://www.itwinjs.org/reference/core-backend/imodels/imodeldb/)\n * or [IModelConnection](https://www.itwinjs.org/reference/core-frontend/imodelconnection/imodelconnection/).\n */\ninterface CoreECSqlReaderFactory {\n createQueryReader(ecsql: string, binder?: QueryBinder, options?: QueryOptions): ECSqlReader;\n}\n\n/**\n * Creates an `ECSqlQueryExecutor` from either [IModelDb](https://www.itwinjs.org/reference/core-backend/imodels/imodeldb/) or\n * [IModelConnection](https://www.itwinjs.org/reference/core-frontend/imodelconnection/imodelconnection/).\n *\n * Usage example:\n *\n * ```ts\n * import { IModelDb } from \"@itwin/core-backend\";\n * import { createECSqlQueryExecutor } from \"@itwin/presentation-core-interop\";\n *\n * const imodel: IModelDb = getIModelDb();\n * const executor = createECSqlQueryExecutor(imodel);\n * for await (const row of executor.createQueryReader(MY_QUERY)) {\n * // TODO: do something with `row`\n * }\n * ```\n *\n * @beta\n */\nexport function createECSqlQueryExecutor(imodel: CoreECSqlReaderFactory): ECSqlQueryExecutor {\n return {\n createQueryReader(query: ECSqlQueryDef, config?: ECSqlQueryReaderOptions) {\n const { ctes, ecsql, bindings } = query;\n const opts = new QueryOptionsBuilder();\n switch (config?.rowFormat) {\n case \"ECSqlPropertyNames\":\n opts.setRowFormat(QueryRowFormat.UseECSqlPropertyNames);\n break;\n case \"Indexes\":\n opts.setRowFormat(QueryRowFormat.UseECSqlPropertyIndexes);\n break;\n }\n if (config?.restartToken) {\n opts.setRestartToken(config?.restartToken);\n }\n return new ECSqlQueryReaderImpl(\n imodel.createQueryReader(trimWhitespace(addCTEs(ecsql, ctes)), bind(bindings ?? []), opts.getOptions()),\n config?.rowFormat === \"Indexes\" ? \"array\" : \"object\",\n );\n },\n };\n}\n\nclass ECSqlQueryReaderImpl implements ReturnType<ECSqlQueryExecutor[\"createQueryReader\"]> {\n public constructor(\n private _coreReader: ECSqlReader,\n private _format: \"array\" | \"object\",\n ) {}\n public [Symbol.asyncIterator](): AsyncIterableIterator<ECSqlQueryRow> {\n return this;\n }\n public async next(): Promise<IteratorResult<ECSqlQueryRow>> {\n const res = await this._coreReader.next();\n if (res.done) {\n return { done: true, value: undefined };\n }\n return {\n done: false,\n value: this._format === \"array\" ? res.value.toArray() : res.value.toRow(),\n };\n }\n}\n\nfunction bind(bindings: ECSqlBinding[]): QueryBinder {\n const binder = new QueryBinder();\n bindings.forEach((b, i) => {\n if (b.value === undefined) {\n binder.bindNull(i + 1);\n return;\n }\n switch (b.type) {\n case \"boolean\":\n binder.bindBoolean(i + 1, b.value);\n break;\n case \"double\":\n binder.bindDouble(i + 1, b.value);\n break;\n case \"id\":\n binder.bindId(i + 1, b.value);\n break;\n case \"idset\":\n binder.bindIdSet(i + 1, OrderedId64Iterable.sortArray(b.value));\n break;\n case \"int\":\n binder.bindInt(i + 1, b.value);\n break;\n case \"long\":\n binder.bindLong(i + 1, b.value);\n break;\n case \"point2d\":\n binder.bindPoint2d(i + 1, Point2d.fromJSON(b.value));\n break;\n case \"point3d\":\n binder.bindPoint3d(i + 1, Point3d.fromJSON(b.value));\n break;\n case \"string\":\n binder.bindString(i + 1, b.value);\n break;\n }\n });\n return binder;\n}\n\nfunction addCTEs(ecsql: string, ctes: string[] | undefined) {\n const ctesPrefix = ctes?.length ? `WITH RECURSIVE ${ctes.join(\", \")} ` : \"\";\n return `${ctesPrefix}${ecsql}`;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/presentation-core-interop",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "The package acts as a layer between iTwin.js Core and Presentation packages.",
|
|
5
5
|
"license": "MIT",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "Bentley Systems, Inc.",
|
|
8
|
+
"url": "http://www.bentley.com"
|
|
9
|
+
},
|
|
6
10
|
"repository": {
|
|
7
11
|
"type": "git",
|
|
8
12
|
"url": "https://github.com/iTwin/presentation.git",
|
|
@@ -14,16 +18,12 @@
|
|
|
14
18
|
"iTwin.js",
|
|
15
19
|
"Presentation"
|
|
16
20
|
],
|
|
17
|
-
"author": {
|
|
18
|
-
"name": "Bentley Systems, Inc.",
|
|
19
|
-
"url": "http://www.bentley.com"
|
|
20
|
-
},
|
|
21
21
|
"main": "lib/cjs/presentation-core-interop.js",
|
|
22
22
|
"module": "lib/esm/presentation-core-interop.js",
|
|
23
23
|
"types": "lib/cjs/presentation-core-interop.d.ts",
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"rxjs": "^7.8.1",
|
|
26
|
-
"@itwin/presentation-shared": "~0.
|
|
26
|
+
"@itwin/presentation-shared": "~0.2.0"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"@itwin/core-bentley": "^4.1.0",
|
|
@@ -33,12 +33,12 @@
|
|
|
33
33
|
"@itwin/ecschema-metadata": "^4.1.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@itwin/build-tools": "^4.
|
|
37
|
-
"@itwin/core-bentley": "^4.
|
|
38
|
-
"@itwin/core-common": "^4.
|
|
39
|
-
"@itwin/core-geometry": "^4.
|
|
40
|
-
"@itwin/core-quantity": "^4.
|
|
41
|
-
"@itwin/ecschema-metadata": "^4.
|
|
36
|
+
"@itwin/build-tools": "^4.6.0",
|
|
37
|
+
"@itwin/core-bentley": "^4.6.0",
|
|
38
|
+
"@itwin/core-common": "^4.6.0",
|
|
39
|
+
"@itwin/core-geometry": "^4.6.0",
|
|
40
|
+
"@itwin/core-quantity": "^4.6.0",
|
|
41
|
+
"@itwin/ecschema-metadata": "^4.6.0",
|
|
42
42
|
"@itwin/eslint-plugin": "^4.0.0",
|
|
43
43
|
"@types/chai": "^4.3.14",
|
|
44
44
|
"@types/chai-as-promised": "^7.1.8",
|
package/.mocharc.json
DELETED
package/.nycrc
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"check-coverage": true,
|
|
3
|
-
"statements": 100,
|
|
4
|
-
"functions": 100,
|
|
5
|
-
"branches": 100,
|
|
6
|
-
"lines": 100,
|
|
7
|
-
"all": true,
|
|
8
|
-
"include": ["src/**/*", "lib/cjs/**/*"],
|
|
9
|
-
"exclude": ["src/presentation-core-interop.ts", "src/test/**", "lib/cjs/test/**"],
|
|
10
|
-
"extension": [".ts"],
|
|
11
|
-
"temp-dir": "./lib/test/coverage/.nyc_output",
|
|
12
|
-
"report-dir": "./lib/test/coverage",
|
|
13
|
-
"reporter": ["text-summary", "lcov", "cobertura"]
|
|
14
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
## API Report File for "@itwin/presentation-core-interop"
|
|
2
|
-
|
|
3
|
-
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
|
|
4
|
-
|
|
5
|
-
```ts
|
|
6
|
-
|
|
7
|
-
import { ECSchemaProvider } from '@itwin/presentation-shared';
|
|
8
|
-
import { ECSqlQueryExecutor } from '@itwin/presentation-shared';
|
|
9
|
-
import { ECSqlReader } from '@itwin/core-common';
|
|
10
|
-
import { Event } from '@itwin/presentation-shared';
|
|
11
|
-
import { ILogger } from '@itwin/presentation-shared';
|
|
12
|
-
import { IPrimitiveValueFormatter } from '@itwin/presentation-shared';
|
|
13
|
-
import { LogLevel } from '@itwin/core-bentley';
|
|
14
|
-
import { QueryBinder } from '@itwin/core-common';
|
|
15
|
-
import { QueryOptions } from '@itwin/core-common';
|
|
16
|
-
import { Schema } from '@itwin/ecschema-metadata';
|
|
17
|
-
import { SchemaContext } from '@itwin/ecschema-metadata';
|
|
18
|
-
import { SchemaKey } from '@itwin/ecschema-metadata';
|
|
19
|
-
import { UnitSystemKey } from '@itwin/core-quantity';
|
|
20
|
-
|
|
21
|
-
// @beta
|
|
22
|
-
export function createECSchemaProvider(schemaContext: CoreSchemaContext): ECSchemaProvider;
|
|
23
|
-
|
|
24
|
-
// @beta
|
|
25
|
-
export function createECSqlQueryExecutor(imodel: CoreECSqlReaderFactory): ECSqlQueryExecutor;
|
|
26
|
-
|
|
27
|
-
// @beta
|
|
28
|
-
export function createLogger(coreLogger: ICoreLogger): ILogger;
|
|
29
|
-
|
|
30
|
-
// @beta
|
|
31
|
-
export function createValueFormatter(props: CreateValueFormatterProps): IPrimitiveValueFormatter;
|
|
32
|
-
|
|
33
|
-
// @beta
|
|
34
|
-
export function registerTxnListeners(txns: ICoreTxnManager, onChanged: () => void): () => void;
|
|
35
|
-
|
|
36
|
-
// (No @packageDocumentation comment for this package)
|
|
37
|
-
|
|
38
|
-
```
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
sep=;
|
|
2
|
-
Release Tag;API Item
|
|
3
|
-
beta;createECSchemaProvider(schemaContext: CoreSchemaContext): ECSchemaProvider
|
|
4
|
-
beta;createECSqlQueryExecutor(imodel: CoreECSqlReaderFactory): ECSqlQueryExecutor
|
|
5
|
-
beta;createLogger(coreLogger: ICoreLogger): ILogger
|
|
6
|
-
beta;createValueFormatter(props: CreateValueFormatterProps): IPrimitiveValueFormatter
|
|
7
|
-
beta;registerTxnListeners(txns: ICoreTxnManager, onChanged: () => void): () => void
|
package/eslint.config.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
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
|
-
const iTwinPlugin = require("@itwin/eslint-plugin");
|
|
6
|
-
const eslintBaseConfig = require("../../eslint.base.config");
|
|
7
|
-
|
|
8
|
-
module.exports = [
|
|
9
|
-
{
|
|
10
|
-
files: ["**/*.ts"],
|
|
11
|
-
...iTwinPlugin.configs.iTwinjsRecommendedConfig,
|
|
12
|
-
},
|
|
13
|
-
...eslintBaseConfig,
|
|
14
|
-
];
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Formatting.test.d.ts","sourceRoot":"","sources":["../../../src/test/Formatting.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,282 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*---------------------------------------------------------------------------------------------
|
|
3
|
-
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
-
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
-
*--------------------------------------------------------------------------------------------*/
|
|
6
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
-
};
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
const chai_1 = require("chai");
|
|
11
|
-
const sinon_1 = __importDefault(require("sinon"));
|
|
12
|
-
const core_quantity_1 = require("@itwin/core-quantity");
|
|
13
|
-
const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
|
|
14
|
-
const Formatting_1 = require("../core-interop/Formatting");
|
|
15
|
-
describe("createValueFormatter", () => {
|
|
16
|
-
const schemaContext = {
|
|
17
|
-
getSchema: sinon_1.default.stub(),
|
|
18
|
-
};
|
|
19
|
-
const defaultFormatter = sinon_1.default.fake(async () => Promise.resolve("DEFAULT"));
|
|
20
|
-
let formatter;
|
|
21
|
-
function initFormatter(unitSystem) {
|
|
22
|
-
formatter = (0, Formatting_1.createValueFormatter)({
|
|
23
|
-
schemaContext: schemaContext,
|
|
24
|
-
unitSystem,
|
|
25
|
-
baseFormatter: defaultFormatter,
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
beforeEach(() => {
|
|
29
|
-
defaultFormatter.resetHistory();
|
|
30
|
-
initFormatter();
|
|
31
|
-
});
|
|
32
|
-
it("returns default formatter result when property doesn't have a KoQ", async () => {
|
|
33
|
-
const prop = {
|
|
34
|
-
type: "Double",
|
|
35
|
-
value: 1.23,
|
|
36
|
-
};
|
|
37
|
-
(0, chai_1.expect)(await formatter(prop)).to.eq("DEFAULT");
|
|
38
|
-
(0, chai_1.expect)(defaultFormatter).to.be.calledOnceWith(prop);
|
|
39
|
-
});
|
|
40
|
-
it("throws when property references non-existing schema in KoQ", async () => {
|
|
41
|
-
schemaContext.getSchema.resolves(undefined);
|
|
42
|
-
const prop = {
|
|
43
|
-
type: "Double",
|
|
44
|
-
value: 1.23,
|
|
45
|
-
koqName: "X.Y",
|
|
46
|
-
};
|
|
47
|
-
await (0, chai_1.expect)(formatter(prop)).to.eventually.be.rejectedWith("Invalid schema");
|
|
48
|
-
});
|
|
49
|
-
it("throws when property references non-existing KoQ", async () => {
|
|
50
|
-
schemaContext.getSchema.resolves({
|
|
51
|
-
name: "X",
|
|
52
|
-
getItem: async () => undefined,
|
|
53
|
-
});
|
|
54
|
-
const prop = {
|
|
55
|
-
type: "Double",
|
|
56
|
-
value: 1.23,
|
|
57
|
-
koqName: "X.Y",
|
|
58
|
-
};
|
|
59
|
-
await (0, chai_1.expect)(formatter(prop)).to.eventually.be.rejectedWith("Invalid kind of quantity");
|
|
60
|
-
});
|
|
61
|
-
it("returns default formatter result when KoQ doesn't specify persistence unit", async () => {
|
|
62
|
-
schemaContext.getSchema.resolves({
|
|
63
|
-
name: "X",
|
|
64
|
-
getItem: async (name) => {
|
|
65
|
-
if (name === "Y") {
|
|
66
|
-
return {
|
|
67
|
-
persistenceUnit: Promise.resolve(undefined),
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
return undefined;
|
|
71
|
-
},
|
|
72
|
-
});
|
|
73
|
-
const prop = {
|
|
74
|
-
type: "Double",
|
|
75
|
-
value: 1.23,
|
|
76
|
-
koqName: "X.Y",
|
|
77
|
-
};
|
|
78
|
-
(0, chai_1.expect)(await formatter(prop)).to.eq("DEFAULT");
|
|
79
|
-
(0, chai_1.expect)(defaultFormatter).to.be.calledOnceWith(prop);
|
|
80
|
-
});
|
|
81
|
-
it("returns default formatter result when KoQ doesn't specify presentation format", async () => {
|
|
82
|
-
schemaContext.getSchema.resolves({
|
|
83
|
-
name: "X",
|
|
84
|
-
getItem: async (name) => {
|
|
85
|
-
if (name === "Y") {
|
|
86
|
-
return {
|
|
87
|
-
persistenceUnit: Promise.resolve({
|
|
88
|
-
unitSystem: Promise.resolve({
|
|
89
|
-
name: "metric",
|
|
90
|
-
}),
|
|
91
|
-
}),
|
|
92
|
-
presentationFormats: [],
|
|
93
|
-
defaultPresentationFormat: undefined,
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
return undefined;
|
|
97
|
-
},
|
|
98
|
-
});
|
|
99
|
-
const prop = {
|
|
100
|
-
type: "Double",
|
|
101
|
-
value: 1.23,
|
|
102
|
-
koqName: "X.Y",
|
|
103
|
-
};
|
|
104
|
-
(0, chai_1.expect)(await formatter(prop)).to.eq("DEFAULT");
|
|
105
|
-
(0, chai_1.expect)(defaultFormatter).to.be.calledOnceWith(prop);
|
|
106
|
-
});
|
|
107
|
-
it("returns koq formatter result when presentation format is found in koq formats list", async () => {
|
|
108
|
-
initFormatter("metric");
|
|
109
|
-
const persistenceUnit = createUnit("schema.persistence_unit", "metric");
|
|
110
|
-
const presentationUnit = createUnit("schema.presentation_unit", "metric");
|
|
111
|
-
const presentationFormatProps = {};
|
|
112
|
-
schemaContext.getSchema.resolves({
|
|
113
|
-
name: "schema",
|
|
114
|
-
getItem: async (name) => {
|
|
115
|
-
if (name === "koq") {
|
|
116
|
-
return {
|
|
117
|
-
schemaItemType: ecschema_metadata_1.SchemaItemType.KindOfQuantity,
|
|
118
|
-
persistenceUnit: Promise.resolve(persistenceUnit),
|
|
119
|
-
presentationFormats: [
|
|
120
|
-
{
|
|
121
|
-
units: [[presentationUnit, "presentation unit"]],
|
|
122
|
-
toJSON: () => presentationFormatProps,
|
|
123
|
-
},
|
|
124
|
-
],
|
|
125
|
-
defaultPresentationFormat: undefined,
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
if (name === "persistence_unit") {
|
|
129
|
-
return persistenceUnit;
|
|
130
|
-
}
|
|
131
|
-
if (name === "presentation_unit") {
|
|
132
|
-
return presentationUnit;
|
|
133
|
-
}
|
|
134
|
-
return undefined;
|
|
135
|
-
},
|
|
136
|
-
});
|
|
137
|
-
const koqFormatterStub = sinon_1.default.stub().returns("KOQ FORMAT");
|
|
138
|
-
const quantityFormat = {};
|
|
139
|
-
const createQuantityFormatStub = sinon_1.default.stub(core_quantity_1.Format, "createFromJSON").resolves(quantityFormat);
|
|
140
|
-
const createFormatSpecStub = sinon_1.default.stub(core_quantity_1.FormatterSpec, "create").resolves({
|
|
141
|
-
applyFormatting: koqFormatterStub,
|
|
142
|
-
});
|
|
143
|
-
(0, chai_1.expect)(await formatter({
|
|
144
|
-
type: "Double",
|
|
145
|
-
value: 1.23,
|
|
146
|
-
koqName: "schema.koq",
|
|
147
|
-
})).to.eq("KOQ FORMAT");
|
|
148
|
-
(0, chai_1.expect)(createQuantityFormatStub).to.be.calledOnceWithExactly("", sinon_1.default.match((arg) => arg instanceof ecschema_metadata_1.SchemaUnitProvider), presentationFormatProps);
|
|
149
|
-
(0, chai_1.expect)(createFormatSpecStub).to.be.calledOnceWithExactly("", quantityFormat, sinon_1.default.match((arg) => arg instanceof ecschema_metadata_1.SchemaUnitProvider), sinon_1.default.match((arg) => arg.name === persistenceUnit.fullName));
|
|
150
|
-
(0, chai_1.expect)(koqFormatterStub).to.be.calledOnceWithExactly(1.23);
|
|
151
|
-
});
|
|
152
|
-
it("returns koq formatter result when persistence unit system matches requested unit system", async () => {
|
|
153
|
-
initFormatter("imperial");
|
|
154
|
-
const persistenceUnit = createUnit("schema.persistence_unit", "imperial");
|
|
155
|
-
schemaContext.getSchema.resolves({
|
|
156
|
-
name: "schema",
|
|
157
|
-
getItem: async (name) => {
|
|
158
|
-
if (name === "koq") {
|
|
159
|
-
return {
|
|
160
|
-
schemaItemType: ecschema_metadata_1.SchemaItemType.KindOfQuantity,
|
|
161
|
-
persistenceUnit: Promise.resolve(persistenceUnit),
|
|
162
|
-
presentationFormats: [],
|
|
163
|
-
defaultPresentationFormat: undefined,
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
if (name === "persistence_unit") {
|
|
167
|
-
return persistenceUnit;
|
|
168
|
-
}
|
|
169
|
-
return undefined;
|
|
170
|
-
},
|
|
171
|
-
});
|
|
172
|
-
const koqFormatterStub = sinon_1.default.stub().returns("KOQ FORMAT");
|
|
173
|
-
const quantityFormat = {};
|
|
174
|
-
const createQuantityFormatStub = sinon_1.default.stub(core_quantity_1.Format, "createFromJSON").resolves(quantityFormat);
|
|
175
|
-
const createFormatSpecStub = sinon_1.default.stub(core_quantity_1.FormatterSpec, "create").resolves({
|
|
176
|
-
applyFormatting: koqFormatterStub,
|
|
177
|
-
});
|
|
178
|
-
(0, chai_1.expect)(await formatter({
|
|
179
|
-
type: "Double",
|
|
180
|
-
value: 1.23,
|
|
181
|
-
koqName: "schema.koq",
|
|
182
|
-
})).to.eq("KOQ FORMAT");
|
|
183
|
-
(0, chai_1.expect)(createQuantityFormatStub).to.be.calledOnceWithExactly("", sinon_1.default.match((arg) => arg instanceof ecschema_metadata_1.SchemaUnitProvider), sinon_1.default.match((arg) => arg.composite.units[0].name === persistenceUnit.fullName));
|
|
184
|
-
(0, chai_1.expect)(createFormatSpecStub).to.be.calledOnceWithExactly("", quantityFormat, sinon_1.default.match((arg) => arg instanceof ecschema_metadata_1.SchemaUnitProvider), sinon_1.default.match((arg) => arg.name === persistenceUnit.fullName));
|
|
185
|
-
(0, chai_1.expect)(koqFormatterStub).to.be.calledOnceWithExactly(1.23);
|
|
186
|
-
});
|
|
187
|
-
it("returns koq formatter result when default presentation unit is of requested unit system", async () => {
|
|
188
|
-
initFormatter("usCustomary");
|
|
189
|
-
const persistenceUnit = createUnit("schema.persistence_unit", "imperial");
|
|
190
|
-
const defaultPresentationUnit = createUnit("schema.presentation_unit", "usCustomary");
|
|
191
|
-
const defaultPresentationFormatProps = {};
|
|
192
|
-
schemaContext.getSchema.resolves({
|
|
193
|
-
name: "schema",
|
|
194
|
-
getItem: async (name) => {
|
|
195
|
-
if (name === "koq") {
|
|
196
|
-
return {
|
|
197
|
-
schemaItemType: ecschema_metadata_1.SchemaItemType.KindOfQuantity,
|
|
198
|
-
persistenceUnit: Promise.resolve(persistenceUnit),
|
|
199
|
-
presentationFormats: [],
|
|
200
|
-
defaultPresentationFormat: {
|
|
201
|
-
units: [[defaultPresentationUnit, "presentation unit"]],
|
|
202
|
-
toJSON: () => defaultPresentationFormatProps,
|
|
203
|
-
},
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
if (name === "persistence_unit") {
|
|
207
|
-
return persistenceUnit;
|
|
208
|
-
}
|
|
209
|
-
if (name === "presentation_unit") {
|
|
210
|
-
return defaultPresentationUnit;
|
|
211
|
-
}
|
|
212
|
-
return undefined;
|
|
213
|
-
},
|
|
214
|
-
});
|
|
215
|
-
const koqFormatterStub = sinon_1.default.stub().returns("KOQ FORMAT");
|
|
216
|
-
const quantityFormat = {};
|
|
217
|
-
const createQuantityFormatStub = sinon_1.default.stub(core_quantity_1.Format, "createFromJSON").resolves(quantityFormat);
|
|
218
|
-
const createFormatSpecStub = sinon_1.default.stub(core_quantity_1.FormatterSpec, "create").resolves({
|
|
219
|
-
applyFormatting: koqFormatterStub,
|
|
220
|
-
});
|
|
221
|
-
(0, chai_1.expect)(await formatter({
|
|
222
|
-
type: "Double",
|
|
223
|
-
value: 1.23,
|
|
224
|
-
koqName: "schema.koq",
|
|
225
|
-
})).to.eq("KOQ FORMAT");
|
|
226
|
-
(0, chai_1.expect)(createQuantityFormatStub).to.be.calledOnceWithExactly("", sinon_1.default.match((arg) => arg instanceof ecschema_metadata_1.SchemaUnitProvider), defaultPresentationFormatProps);
|
|
227
|
-
(0, chai_1.expect)(createFormatSpecStub).to.be.calledOnceWithExactly("", quantityFormat, sinon_1.default.match((arg) => arg instanceof ecschema_metadata_1.SchemaUnitProvider), sinon_1.default.match((arg) => arg.name === persistenceUnit.fullName));
|
|
228
|
-
(0, chai_1.expect)(koqFormatterStub).to.be.calledOnceWithExactly(1.23);
|
|
229
|
-
});
|
|
230
|
-
it("returns koq formatter result when koq uses override format", async () => {
|
|
231
|
-
initFormatter("usSurvey");
|
|
232
|
-
const persistenceUnit = createUnit("schema.persistence_unit", "metric");
|
|
233
|
-
const presentationUnit = createUnit("schema.presentation_unit", "usSurvey");
|
|
234
|
-
const overrideFormat = new ecschema_metadata_1.OverrideFormat({ fullName: "schema.base_format", toJSON: () => ({}) }, undefined, [
|
|
235
|
-
[presentationUnit, "presentation unit"],
|
|
236
|
-
]);
|
|
237
|
-
schemaContext.getSchema.resolves({
|
|
238
|
-
name: "schema",
|
|
239
|
-
getItem: async (name) => {
|
|
240
|
-
if (name === "koq") {
|
|
241
|
-
return {
|
|
242
|
-
schemaItemType: ecschema_metadata_1.SchemaItemType.KindOfQuantity,
|
|
243
|
-
persistenceUnit: Promise.resolve(persistenceUnit),
|
|
244
|
-
presentationFormats: [],
|
|
245
|
-
defaultPresentationFormat: overrideFormat,
|
|
246
|
-
};
|
|
247
|
-
}
|
|
248
|
-
if (name === "persistence_unit") {
|
|
249
|
-
return persistenceUnit;
|
|
250
|
-
}
|
|
251
|
-
if (name === "presentation_unit") {
|
|
252
|
-
return presentationUnit;
|
|
253
|
-
}
|
|
254
|
-
return undefined;
|
|
255
|
-
},
|
|
256
|
-
});
|
|
257
|
-
const koqFormatterStub = sinon_1.default.stub().returns("KOQ FORMAT");
|
|
258
|
-
const quantityFormat = {};
|
|
259
|
-
const createQuantityFormatStub = sinon_1.default.stub(core_quantity_1.Format, "createFromJSON").resolves(quantityFormat);
|
|
260
|
-
const createFormatSpecStub = sinon_1.default.stub(core_quantity_1.FormatterSpec, "create").resolves({
|
|
261
|
-
applyFormatting: koqFormatterStub,
|
|
262
|
-
});
|
|
263
|
-
(0, chai_1.expect)(await formatter({
|
|
264
|
-
type: "Double",
|
|
265
|
-
value: 1.23,
|
|
266
|
-
koqName: "schema.koq",
|
|
267
|
-
})).to.eq("KOQ FORMAT");
|
|
268
|
-
(0, chai_1.expect)(createQuantityFormatStub).to.be.calledOnceWithExactly("", sinon_1.default.match((arg) => arg instanceof ecschema_metadata_1.SchemaUnitProvider), sinon_1.default.match((arg) => arg.composite?.units[0].name === presentationUnit.fullName));
|
|
269
|
-
(0, chai_1.expect)(createFormatSpecStub).to.be.calledOnceWithExactly("", quantityFormat, sinon_1.default.match((arg) => arg instanceof ecschema_metadata_1.SchemaUnitProvider), sinon_1.default.match((arg) => arg.name === persistenceUnit.fullName));
|
|
270
|
-
(0, chai_1.expect)(koqFormatterStub).to.be.calledOnceWithExactly(1.23);
|
|
271
|
-
});
|
|
272
|
-
});
|
|
273
|
-
function createUnit(fullName, unitSystem) {
|
|
274
|
-
return {
|
|
275
|
-
schemaItemType: ecschema_metadata_1.SchemaItemType.Unit,
|
|
276
|
-
fullName,
|
|
277
|
-
unitSystem: Promise.resolve({
|
|
278
|
-
name: unitSystem,
|
|
279
|
-
}),
|
|
280
|
-
};
|
|
281
|
-
}
|
|
282
|
-
//# sourceMappingURL=Formatting.test.js.map
|